Communication

The communication/ directory abstracts how ORQ parties exchange messages and offers multiple back-ends.

Contents:

  • no_copy_communicator/ – Zero-copy communicator implementation.

  • communicator.h – Abstract communicator interface.

  • communicator_factory.h – Factory for constructing communicators.

  • mpi_communicator.h – MPI communicator back-end.

  • null_communicator.h – Null communicator for single-process or testing setups.

  • ring.h - definitions for Ring and RingEntry structs.

MPI Communicator

class MPICommunicator : public orq::Communicator

Public Functions

inline MPICommunicator(const int &_currentId, const int &_numParties, const int &_msg_tag = 7, const int &_parallelism_factor = 1)
inline ~MPICommunicator()
template<typename T>
inline void sendShare_impl(T share, PartyID _id)
inline virtual void sendShare(int8_t share, PartyID _id) override

Peer to Peer Communication //.

Send one data element to a chosen party.

Parameters:
  • element – The data element to be sent to the party.

  • id – The index of the recipient party relative to the current party.

inline virtual void sendShare(int16_t share, PartyID _id) override
inline virtual void sendShare(int32_t share, PartyID _id) override
inline virtual void sendShare(int64_t share, PartyID _id) override
template<typename T>
inline void sendShares_impl(const Vector<T> &_shares, PartyID _id, size_t _size)
inline virtual void sendShares(const Vector<int8_t> &shares, PartyID _id, size_t _size) override

Send a vector to a chosen party.

Parameters:
  • shares – The data elements to be sent to the party.

  • id – The index of the recipient party relative to the current party.

  • size – Number of data elements to be sent.

inline virtual void sendShares(const Vector<int16_t> &shares, PartyID _id, size_t _size) override
inline virtual void sendShares(const Vector<int32_t> &shares, PartyID _id, size_t _size) override
inline virtual void sendShares(const Vector<int64_t> &shares, PartyID _id, size_t _size) override
inline virtual void sendShares(const Vector<__int128_t> &shares, PartyID _id, size_t _size) override
template<typename T>
inline void receiveShare_impl(T &_share, PartyID _id)
inline virtual void receiveShare(int8_t &_share, PartyID _id) override

Receive an element from the chosen party. blocking call.

Parameters:
  • element – reference to variable to receive into

  • id – The index of the sending party relative to the current party.

inline virtual void receiveShare(int16_t &_share, PartyID _id) override
inline virtual void receiveShare(int32_t &_share, PartyID _id) override
inline virtual void receiveShare(int64_t &_share, PartyID _id) override
template<typename T>
inline void receiveShares_impl(Vector<T> &_shares, PartyID _id, size_t _size)
inline virtual void receiveShares(Vector<int8_t> &_shareVector, PartyID _id, size_t _size) override

Receive a vector from some chosen party. blocking call.

Parameters:
  • shares – reference to vector to receive into

  • id – The index of the sending party relative to the current party.

  • size – Number of data elements to be received.

inline virtual void receiveShares(Vector<int16_t> &_shareVector, PartyID _id, size_t _size) override
inline virtual void receiveShares(Vector<int32_t> &_shareVector, PartyID _id, size_t _size) override
inline virtual void receiveShares(Vector<int64_t> &_shareVector, PartyID _id, size_t _size) override
inline virtual void receiveShares(Vector<__int128_t> &_shareVector, PartyID _id, size_t _size) override
template<typename T>
inline void exchangeShares_impl(Vector<T> sent_shares, Vector<T> &received_shares, PartyID _id, size_t _size)

Single party version of exchange shares.

Template Parameters:

T

Parameters:
  • sent_shares

  • received_shares

  • _id

  • _size

inline virtual void exchangeShares(Vector<int8_t> sent_shares, Vector<int8_t> &received_shares, PartyID _id, size_t _size) override

Sends and Receives vectors to and from some same party. Subclasses may implement in an arbitrary order, but neither send nor receive should block each other. exchangeShares should block until both calls are completed. Implementations may choose to run send and receive concurrently, or queue the send while waiting on a blocking receive.

Parameters:
  • sent_shares – vector to send

  • received_shares – vector to receive into

  • id – The index of the other party relative to the current party.

  • size – Number of data elements to be sent and received.

inline virtual void exchangeShares(Vector<int16_t> sent_shares, Vector<int16_t> &received_shares, PartyID _id, size_t _size) override
inline virtual void exchangeShares(Vector<int32_t> sent_shares, Vector<int32_t> &received_shares, PartyID _id, size_t _size) override
inline virtual void exchangeShares(Vector<int64_t> sent_shares, Vector<int64_t> &received_shares, PartyID _id, size_t _size) override
inline virtual void exchangeShares(Vector<__int128_t> sent_shares, Vector<__int128_t> &received_shares, PartyID _id, size_t _size) override
template<typename T>
inline void exchangeShares_impl(Vector<T> _shares, Vector<T> &received_shares, PartyID to_id, PartyID from_id, size_t _size)
inline virtual void exchangeShares(Vector<int8_t> sent_shares, Vector<int8_t> &received_shares, PartyID to_id, PartyID from_id, size_t _size) override

Exchange shares with two different parties.

Parameters:
  • sent_shares

  • received_shares

  • to_id – relative ID of destination party

  • from_id – relative ID of source party

  • size

inline virtual void exchangeShares(Vector<int16_t> sent_shares, Vector<int16_t> &received_shares, PartyID to_id, PartyID from_id, size_t _size) override
inline virtual void exchangeShares(Vector<int32_t> sent_shares, Vector<int32_t> &received_shares, PartyID to_id, PartyID from_id, size_t _size) override
inline virtual void exchangeShares(Vector<int64_t> sent_shares, Vector<int64_t> &received_shares, PartyID to_id, PartyID from_id, size_t _size) override
inline virtual void exchangeShares(Vector<__int128_t> sent_shares, Vector<__int128_t> &received_shares, PartyID to_id, PartyID from_id, size_t _size) override
template<typename T>
inline void sendShares_impl(const std::vector<Vector<T>> &shares, std::vector<PartyID> partyID)
inline virtual void sendShares(const std::vector<Vector<int8_t>> &shares, std::vector<PartyID> partyID) override

Send multiple Vectors to multiple parties at the same time. Vector sizes must match.

Parameters:
  • shares – The std::vector of the vectors to be sent.

  • partyID – The std::vector of the parties to send to.

inline virtual void sendShares(const std::vector<Vector<int16_t>> &shares, std::vector<PartyID> partyID) override
inline virtual void sendShares(const std::vector<Vector<int32_t>> &shares, std::vector<PartyID> partyID) override
inline virtual void sendShares(const std::vector<Vector<int64_t>> &shares, std::vector<PartyID> partyID) override
inline virtual void sendShares(const std::vector<Vector<__int128_t>> &shares, std::vector<PartyID> partyID) override
template<typename T>
inline void receiveBroadcast_impl(std::vector<Vector<T>> &shares, std::vector<PartyID> partyID)
inline virtual void receiveBroadcast(std::vector<Vector<int8_t>> &shares, std::vector<PartyID> partyID) override

Receive from multiple parties. Vector sizes must match.

Parameters:
  • shares – vector of Vectors to be sent

  • partyID

inline virtual void receiveBroadcast(std::vector<Vector<int16_t>> &shares, std::vector<PartyID> partyID) override
inline virtual void receiveBroadcast(std::vector<Vector<int32_t>> &shares, std::vector<PartyID> partyID) override
inline virtual void receiveBroadcast(std::vector<Vector<int64_t>> &shares, std::vector<PartyID> partyID) override
inline virtual void receiveBroadcast(std::vector<Vector<__int128_t>> &shares, std::vector<PartyID> partyID) override
template<typename T>
inline void exchangeShares_impl(const std::vector<Vector<T>> &shares, std::vector<Vector<T>> &received_shares, std::vector<PartyID> to_id, std::vector<PartyID> from_id)
inline virtual void exchangeShares(const std::vector<Vector<int8_t>> &shares, std::vector<Vector<int8_t>> &received_shares, std::vector<PartyID> to_id, std::vector<PartyID> from_id) override

Send and receive multiple Vectors to and from multiple parties.

Parameters:
  • shares – The std::vector of the vectors to be sent.

  • received_shares – The std::vector of the vectors to be received.

  • to_id – The std::vector of the parties to send shares to.

  • from_id – The std::vector of the parties to receive received_shares from.

inline virtual void exchangeShares(const std::vector<Vector<int16_t>> &shares, std::vector<Vector<int16_t>> &received_shares, std::vector<PartyID> to_id, std::vector<PartyID> from_id) override
inline virtual void exchangeShares(const std::vector<Vector<int32_t>> &shares, std::vector<Vector<int32_t>> &received_shares, std::vector<PartyID> to_id, std::vector<PartyID> from_id) override
inline virtual void exchangeShares(const std::vector<Vector<int64_t>> &shares, std::vector<Vector<int64_t>> &received_shares, std::vector<PartyID> to_id, std::vector<PartyID> from_id) override
inline virtual void exchangeShares(const std::vector<Vector<__int128_t>> &shares, std::vector<Vector<__int128_t>> &received_shares, std::vector<PartyID> to_id, std::vector<PartyID> from_id) override

Private Members

int numParties
int msg_tag
int parallelism_factor

No-copy Communicator

class NoCopyCommunicator : public orq::Communicator

No-copy communicator layer. Builds a ring buffer of pointers to vectors, and sends out each vector sequentially, without introducing extra copies.

Public Functions

inline NoCopyCommunicator(const int &_currentId, const std::vector<int> &socket_map, const int &_numParties)

Construct a new No Copy Communicator.

Parameters:
  • _currentId – party ID of this node

  • socket_map – map (stored as a vector) of party IDs to socket file descriptors. The current party ID (i.e., _currentID) can contain any value in this map and should be ignored.

  • _numParties – The number of parties in this execution

inline ~NoCopyCommunicator()
template<typename T>
inline void printType(const std::string &name, const std::string &meta)

Generic function to print a string along with a type.

Template Parameters:

T – the type to output

Parameters:
  • name – name of the calling function

  • meta – additional information to output

template<typename T>
inline void sendShareGeneric(T share, PartyID _id)

Send a single generic share. Creates a singleton vector and pushes it to the send ring.

Template Parameters:

T – type of the share

Parameters:
  • share

  • _id – relative destination party

template<typename T>
inline void sendSharesGeneric(const Vector<T> &_shares, PartyID _id, size_t _size)

Send a shared vector. Pushes the vector to the send ring.

Template Parameters:

T – underlying type of the shared vector

Parameters:
  • _shares

  • _id – relative destination party. +1 is the next party, -1 is the previous.

  • _size – size of the vector (TODO: use size of _shares)

template<typename T>
inline void receiveShareGeneric(T &_share, PartyID _id)

Receive a single share. Directly calls the recv function.

Template Parameters:

T

Parameters:
  • _share

  • _id

template<typename T>
inline void receiveSharesGeneric(Vector<T> &_shareVector, PartyID _id, size_t _size)

Receive a shared vector. Directly calls the recv function, operating in chunks if the entire vector is not read in a single call.

Template Parameters:

T – underlying type of the shared vector

Parameters:
  • _shareVector

  • _id – relative source party. +1 is the next party, -1 is the previous.

  • _size – number of elements to receive

template<typename T>
inline void exchangeSharesGeneric(Vector<T> sent_shares, Vector<T> &received_shares, PartyID _to_id, PartyID _from_id, size_t _size)

Concurrently send and receive two vectors. Pushes the send vector to the send ring (which is sent out in the background), and then populate the receive vector by reading from the socket.

Template Parameters:

T

Parameters:
  • sent_shares

  • received_shares

  • _to_id – relative destination party. +1 is the next party, -1 is the previous.

  • _from_id – relative source party

  • _size – number of elements in each vector (TODO: remove)

template<typename T>
inline void sendSharesGeneric(const std::vector<Vector<T>> &shares, std::vector<PartyID> partyID)

Send shares to multiple parties. shares and partyID must be vectors of the same length.

Template Parameters:

T

Parameters:
  • shares – vector of Vectors; one for each party.

  • partyID – vector of relative party IDs to send to.

template<typename T>
inline void receiveBroadcastGeneric(std::vector<Vector<T>> &shares, std::vector<PartyID> partyID)

Receive shares from multiple parties. shares and partyID must be vectors of the same length.

Template Parameters:

T

Parameters:
  • shares – vector of Vectors to receive into

  • partyID – relative source party IDs

template<typename T>
inline void exchangeSharesGeneric(const std::vector<Vector<T>> &shares, std::vector<Vector<T>> &received_shares, std::vector<PartyID> to_id, std::vector<PartyID> from_id)

Exchange shares to and from multiple parties. shares and to_id must have the same length, as should received_shares and from_id.

Template Parameters:

T

Parameters:
  • shares – vector of Vectors to send

  • received_shares – vector of Vectors to receive into

  • to_id – relative destination IDs

  • from_id – relative source IDs

inline virtual void sendShare(int8_t share, PartyID _id)

Peer to Peer Communication //.

Send one data element to a chosen party.

Parameters:
  • element – The data element to be sent to the party.

  • id – The index of the recipient party relative to the current party.

inline virtual void sendShare(int16_t share, PartyID _id)
inline virtual void sendShare(int32_t share, PartyID _id)
inline virtual void sendShare(int64_t share, PartyID _id)
inline virtual void sendShares(const Vector<int8_t> &_shares, PartyID _id, size_t _size)

Send a vector to a chosen party.

Parameters:
  • shares – The data elements to be sent to the party.

  • id – The index of the recipient party relative to the current party.

  • size – Number of data elements to be sent.

inline virtual void sendShares(const Vector<int16_t> &_shares, PartyID _id, size_t _size)
inline virtual void sendShares(const Vector<int32_t> &_shares, PartyID _id, size_t _size)
inline virtual void sendShares(const Vector<int64_t> &_shares, PartyID _id, size_t _size)
inline virtual void sendShares(const Vector<__int128_t> &_shares, PartyID _id, size_t _size)
inline virtual void receiveShare(int8_t &_share, PartyID _id)

Receive an element from the chosen party. blocking call.

Parameters:
  • element – reference to variable to receive into

  • id – The index of the sending party relative to the current party.

inline virtual void receiveShare(int16_t &_share, PartyID _id)
inline virtual void receiveShare(int32_t &_share, PartyID _id)
inline virtual void receiveShare(int64_t &_share, PartyID _id)
inline virtual void receiveShares(Vector<int8_t> &_shareVector, PartyID _id, size_t _size)

Receive a vector from some chosen party. blocking call.

Parameters:
  • shares – reference to vector to receive into

  • id – The index of the sending party relative to the current party.

  • size – Number of data elements to be received.

inline virtual void receiveShares(Vector<int16_t> &_shareVector, PartyID _id, size_t _size)
inline virtual void receiveShares(Vector<int32_t> &_shareVector, PartyID _id, size_t _size)
inline virtual void receiveShares(Vector<int64_t> &_shareVector, PartyID _id, size_t _size)
inline virtual void receiveShares(Vector<__int128_t> &_shareVector, PartyID _id, size_t _size)
inline virtual void exchangeShares(Vector<int8_t> sent_shares, Vector<int8_t> &received_shares, PartyID _id, size_t _size)

Sends and Receives vectors to and from some same party. Subclasses may implement in an arbitrary order, but neither send nor receive should block each other. exchangeShares should block until both calls are completed. Implementations may choose to run send and receive concurrently, or queue the send while waiting on a blocking receive.

Parameters:
  • sent_shares – vector to send

  • received_shares – vector to receive into

  • id – The index of the other party relative to the current party.

  • size – Number of data elements to be sent and received.

inline virtual void exchangeShares(Vector<int16_t> sent_shares, Vector<int16_t> &received_shares, PartyID _id, size_t _size)
inline virtual void exchangeShares(Vector<int32_t> sent_shares, Vector<int32_t> &received_shares, PartyID _id, size_t _size)
inline virtual void exchangeShares(Vector<int64_t> sent_shares, Vector<int64_t> &received_shares, PartyID _id, size_t _size)
inline virtual void exchangeShares(Vector<__int128_t> sent_shares, Vector<__int128_t> &received_shares, PartyID _id, size_t _size)
inline virtual void exchangeShares(Vector<int8_t> sent_shares, Vector<int8_t> &received_shares, PartyID to_id, PartyID from_id, size_t _size)

Exchange shares with two different parties.

Parameters:
  • sent_shares

  • received_shares

  • to_id – relative ID of destination party

  • from_id – relative ID of source party

  • size

inline virtual void exchangeShares(Vector<int16_t> sent_shares, Vector<int16_t> &received_shares, PartyID to_id, PartyID from_id, size_t _size)
inline virtual void exchangeShares(Vector<int32_t> sent_shares, Vector<int32_t> &received_shares, PartyID to_id, PartyID from_id, size_t _size)
inline virtual void exchangeShares(Vector<int64_t> sent_shares, Vector<int64_t> &received_shares, PartyID to_id, PartyID from_id, size_t _size)
inline virtual void exchangeShares(Vector<__int128_t> sent_shares, Vector<__int128_t> &received_shares, PartyID to_id, PartyID from_id, size_t _size)
inline virtual void sendShares(const std::vector<Vector<int8_t>> &shares, std::vector<PartyID> partyID)

Send multiple Vectors to multiple parties at the same time. Vector sizes must match.

Parameters:
  • shares – The std::vector of the vectors to be sent.

  • partyID – The std::vector of the parties to send to.

inline virtual void sendShares(const std::vector<Vector<int16_t>> &shares, std::vector<PartyID> partyID)
inline virtual void sendShares(const std::vector<Vector<int32_t>> &shares, std::vector<PartyID> partyID)
inline virtual void sendShares(const std::vector<Vector<int64_t>> &shares, std::vector<PartyID> partyID)
inline virtual void sendShares(const std::vector<Vector<__int128_t>> &shares, std::vector<PartyID> partyID)
inline virtual void receiveBroadcast(std::vector<Vector<int8_t>> &shares, std::vector<PartyID> partyID)

Receive from multiple parties. Vector sizes must match.

Parameters:
  • shares – vector of Vectors to be sent

  • partyID

inline virtual void receiveBroadcast(std::vector<Vector<int16_t>> &shares, std::vector<PartyID> partyID)
inline virtual void receiveBroadcast(std::vector<Vector<int32_t>> &shares, std::vector<PartyID> partyID)
inline virtual void receiveBroadcast(std::vector<Vector<int64_t>> &shares, std::vector<PartyID> partyID)
inline virtual void receiveBroadcast(std::vector<Vector<__int128_t>> &shares, std::vector<PartyID> partyID)
inline virtual void exchangeShares(const std::vector<Vector<int8_t>> &shares, std::vector<Vector<int8_t>> &received_shares, std::vector<PartyID> to_id, std::vector<PartyID> from_id)

Send and receive multiple Vectors to and from multiple parties.

Parameters:
  • shares – The std::vector of the vectors to be sent.

  • received_shares – The std::vector of the vectors to be received.

  • to_id – The std::vector of the parties to send shares to.

  • from_id – The std::vector of the parties to receive received_shares from.

inline virtual void exchangeShares(const std::vector<Vector<int16_t>> &shares, std::vector<Vector<int16_t>> &received_shares, std::vector<PartyID> to_id, std::vector<PartyID> from_id)
inline virtual void exchangeShares(const std::vector<Vector<int32_t>> &shares, std::vector<Vector<int32_t>> &received_shares, std::vector<PartyID> to_id, std::vector<PartyID> from_id)
inline virtual void exchangeShares(const std::vector<Vector<int64_t>> &shares, std::vector<Vector<int64_t>> &received_shares, std::vector<PartyID> to_id, std::vector<PartyID> from_id)
inline virtual void exchangeShares(const std::vector<Vector<__int128_t>> &shares, std::vector<Vector<__int128_t>> &received_shares, std::vector<PartyID> to_id, std::vector<PartyID> from_id)
inline PartyInfoBasic &get_party(int id)

Get the party info object for the given (absolute) party. Performs a bounds check on the ID and asserts that the struct pointer is not null.

Parameters:

id

Returns:

PartyInfoBasic&

Private Members

int numParties
std::vector<std::unique_ptr<PartyInfoBasic>> _party_map
struct NoCopyRingEntry
#include <no_copy_ring.h>

A single entry in the NoCopy ring.

Public Members

const char *buffer
size_t buffer_size
class NoCopyRing
#include <no_copy_ring.h>

The NoCopy circular ring buffer. Contains a read and write index, both of which are updated atomically, and a dynamically-allocated array of ring entries.

As data is added to the ring buffer, the write index is incremented. As data is read and sent out on the socket, the read index is incremented. If the read index cannot be incremented, the buffer is empty. If the write index cannot be incremented, the buffer is full.

Public Functions

NoCopyRing(int)

Construct a new NoCopy Ring of the given size.

Parameters:

r_size

~NoCopyRing()
int getWriteIndex() const
int getReadIndex() const
int nextIndex(int) const

Returns the next index in the ring buffer (mod the ring size)

Parameters:

index

Returns:

int

bool isRingFull() const

Checks if the ring is full: that is, readIndex is the next index after writeIndex.

Returns:

true the ring is full

Returns:

false it is not

bool isRingEmpty() const

Checks if the ring is empty: that is, readIndex and writeIndex are the same.

Returns:

true the ring is empty

Returns:

false it is not

template<typename T>
int push(const orq::Vector<T>&)

Push a (pointer to a) Vector onto the buffer. Be careful about data lifetimes: if the passed vectorData goes out of scope in the caller, undefined data may be sent. This function expects vectorData to remain unmodified until it is sent.

Template Parameters:

T

Parameters:

vectorData – the const Vector to push onto the buffer.

Returns:

int

NoCopyRingEntry *currentEntry() const

Wait until the ring is not empty, then return a pointer to the current entry.

Returns:

NoCopyRingEntry*

void pop(NoCopyRingEntry*)

Remove the first element (at readIndex) from the ring buffer.

Parameters:

entry

void wait(int) const

Wait until the readIndex equals pushIndex.

Parameters:

pushIndex

Private Members

std::atomic<uint32_t> writeIndex = 0
std::atomic<uint32_t> readIndex = 0
int ring_size
NoCopyRingEntry *ring_array
struct RingEntry
#include <ring.h>

Public Functions

inline RingEntry()

Public Members

char buffer[SOCKET_COMMUNICATOR_BUFFER_SIZE]
size_t used
class Ring
#include <ring.h>

Public Functions

Ring(int)
~Ring()
int getWriteIndex()
int getReadIndex()
int nextIndex(int)
bool isRingFull()
bool isRingEmpty()
template<typename T>
int push(orq::Vector<T>)
void push(char*, int byte_count)
RingEntry pop()
void wait(int)

Private Members

int writeIndex
int readIndex
int ring_size
RingEntry *ring_array

Base Classes & Utilities

class Communicator

The base communicator class. All communicators must inherit from this class.

Subclassed by orq::MPICommunicator, orq::NoCopyCommunicator, orq::NullCommunicator

Public Functions

inline Communicator(PartyID _currentId)

Initializes the communicator base with the current party index.

Parameters:

_currentId – The absolute index of the party in the parties ring.

inline virtual ~Communicator()
inline size_t getBytesSent() const
virtual void sendShare(int8_t element, PartyID id) = 0

Peer to Peer Communication //.

Send one data element to a chosen party.

Parameters:
  • element – The data element to be sent to the party.

  • id – The index of the recipient party relative to the current party.

virtual void sendShare(int16_t element, PartyID id) = 0
virtual void sendShare(int32_t element, PartyID id) = 0
virtual void sendShare(int64_t element, PartyID id) = 0
virtual void sendShares(const Vector<int8_t> &shares, PartyID id, size_t size) = 0

Send a vector to a chosen party.

Parameters:
  • shares – The data elements to be sent to the party.

  • id – The index of the recipient party relative to the current party.

  • size – Number of data elements to be sent.

virtual void sendShares(const Vector<int16_t> &shares, PartyID id, size_t size) = 0
virtual void sendShares(const Vector<int32_t> &shares, PartyID id, size_t size) = 0
virtual void sendShares(const Vector<int64_t> &shares, PartyID id, size_t size) = 0
virtual void sendShares(const Vector<__int128_t> &shares, PartyID id, size_t size) = 0
virtual void receiveShare(int8_t &element, PartyID id) = 0

Receive an element from the chosen party. blocking call.

Parameters:
  • element – reference to variable to receive into

  • id – The index of the sending party relative to the current party.

virtual void receiveShare(int16_t &element, PartyID id) = 0
virtual void receiveShare(int32_t &element, PartyID id) = 0
virtual void receiveShare(int64_t &element, PartyID id) = 0
virtual void receiveShares(Vector<int8_t> &shares, PartyID id, size_t size) = 0

Receive a vector from some chosen party. blocking call.

Parameters:
  • shares – reference to vector to receive into

  • id – The index of the sending party relative to the current party.

  • size – Number of data elements to be received.

virtual void receiveShares(Vector<int16_t> &shares, PartyID id, size_t size) = 0
virtual void receiveShares(Vector<int32_t> &shares, PartyID id, size_t size) = 0
virtual void receiveShares(Vector<int64_t> &shares, PartyID id, size_t size) = 0
virtual void receiveShares(Vector<__int128_t> &shares, PartyID id, size_t size) = 0
virtual void exchangeShares(Vector<int8_t> sent_shares, Vector<int8_t> &received_shares, PartyID id, size_t size) = 0

Sends and Receives vectors to and from some same party. Subclasses may implement in an arbitrary order, but neither send nor receive should block each other. exchangeShares should block until both calls are completed. Implementations may choose to run send and receive concurrently, or queue the send while waiting on a blocking receive.

Parameters:
  • sent_shares – vector to send

  • received_shares – vector to receive into

  • id – The index of the other party relative to the current party.

  • size – Number of data elements to be sent and received.

virtual void exchangeShares(Vector<int16_t> sent_shares, Vector<int16_t> &received_shares, PartyID id, size_t size) = 0
virtual void exchangeShares(Vector<int32_t> sent_shares, Vector<int32_t> &received_shares, PartyID id, size_t size) = 0
virtual void exchangeShares(Vector<int64_t> sent_shares, Vector<int64_t> &received_shares, PartyID id, size_t size) = 0
virtual void exchangeShares(Vector<__int128_t> sent_shares, Vector<__int128_t> &received_shares, PartyID id, size_t size) = 0
virtual void exchangeShares(Vector<int8_t> sent_shares, Vector<int8_t> &received_shares, PartyID to_id, PartyID from_id, size_t size) = 0

Exchange shares with two different parties.

Parameters:
  • sent_shares

  • received_shares

  • to_id – relative ID of destination party

  • from_id – relative ID of source party

  • size

virtual void exchangeShares(Vector<int16_t> sent_shares, Vector<int16_t> &received_shares, PartyID to_id, PartyID from_id, size_t size) = 0
virtual void exchangeShares(Vector<int32_t> sent_shares, Vector<int32_t> &received_shares, PartyID to_id, PartyID from_id, size_t size) = 0
virtual void exchangeShares(Vector<int64_t> sent_shares, Vector<int64_t> &received_shares, PartyID to_id, PartyID from_id, size_t size) = 0
virtual void exchangeShares(Vector<__int128_t> sent_shares, Vector<__int128_t> &received_shares, PartyID to_id, PartyID from_id, size_t size) = 0
virtual void sendShares(const std::vector<Vector<int8_t>> &shares, std::vector<PartyID> partyID) = 0

Send multiple Vectors to multiple parties at the same time. Vector sizes must match.

Parameters:
  • shares – The std::vector of the vectors to be sent.

  • partyID – The std::vector of the parties to send to.

virtual void sendShares(const std::vector<Vector<int16_t>> &shares, std::vector<PartyID> partyID) = 0
virtual void sendShares(const std::vector<Vector<int32_t>> &shares, std::vector<PartyID> partyID) = 0
virtual void sendShares(const std::vector<Vector<int64_t>> &shares, std::vector<PartyID> partyID) = 0
virtual void sendShares(const std::vector<Vector<__int128_t>> &shares, std::vector<PartyID> partyID) = 0
virtual void receiveBroadcast(std::vector<Vector<int8_t>> &shares, std::vector<PartyID> partyID) = 0

Receive from multiple parties. Vector sizes must match.

Parameters:
  • shares – vector of Vectors to be sent

  • partyID

virtual void receiveBroadcast(std::vector<Vector<int16_t>> &shares, std::vector<PartyID> partyID) = 0
virtual void receiveBroadcast(std::vector<Vector<int32_t>> &shares, std::vector<PartyID> partyID) = 0
virtual void receiveBroadcast(std::vector<Vector<int64_t>> &shares, std::vector<PartyID> partyID) = 0
virtual void receiveBroadcast(std::vector<Vector<__int128_t>> &shares, std::vector<PartyID> partyID) = 0
virtual void exchangeShares(const std::vector<Vector<int8_t>> &shares, std::vector<Vector<int8_t>> &received_shares, std::vector<PartyID> to_id, std::vector<PartyID> from_id) = 0

Send and receive multiple Vectors to and from multiple parties.

Parameters:
  • shares – The std::vector of the vectors to be sent.

  • received_shares – The std::vector of the vectors to be received.

  • to_id – The std::vector of the parties to send shares to.

  • from_id – The std::vector of the parties to receive received_shares from.

virtual void exchangeShares(const std::vector<Vector<int16_t>> &shares, std::vector<Vector<int16_t>> &received_shares, std::vector<PartyID> to_id, std::vector<PartyID> from_id) = 0
virtual void exchangeShares(const std::vector<Vector<int32_t>> &shares, std::vector<Vector<int32_t>> &received_shares, std::vector<PartyID> to_id, std::vector<PartyID> from_id) = 0
virtual void exchangeShares(const std::vector<Vector<int64_t>> &shares, std::vector<Vector<int64_t>> &received_shares, std::vector<PartyID> to_id, std::vector<PartyID> from_id) = 0
virtual void exchangeShares(const std::vector<Vector<__int128_t>> &shares, std::vector<Vector<__int128_t>> &received_shares, std::vector<PartyID> to_id, std::vector<PartyID> from_id) = 0

Protected Attributes

PartyID currentId

The current party’s absolute index in the party ring.

size_t bytes_sent = 0
template<typename InnerFactory>
class CommunicatorFactory

A factory or a communicator object. Parameterized by the subclass type.

Template Parameters:

InnerFactory

Public Functions

virtual ~CommunicatorFactory() = default
inline std::unique_ptr<Communicator> create()

Create a unique pointer to a new communicator.

Returns:

std::unique_ptr<Communicator>

inline void start()

Start the communicator.

inline int getPartyId() const

Get the Party ID of this node.

Returns:

int

inline int getNumParties() const

Get the number of parties in this execution.

Returns:

int

inline void blockingReady()

If this communicator is blocking, wait until it is ready.

class NullCommunicator : public orq::Communicator

Public Functions

inline NullCommunicator()

Null Communicator that does nothing for the Plaintext 1PC test protocol.

inline ~NullCommunicator()
template<typename T>
inline void checkMapping(const Vector<T> &v)

Confirm that v does not have a mapping before sending it.

Template Parameters:

T

Parameters:

v

inline virtual void sendShare(int8_t share, PartyID _id)

Peer to Peer Communication //.

Send one data element to a chosen party.

Parameters:
  • element – The data element to be sent to the party.

  • id – The index of the recipient party relative to the current party.

inline virtual void sendShare(int16_t share, PartyID _id)
inline virtual void sendShare(int32_t share, PartyID _id)
inline virtual void sendShare(int64_t share, PartyID _id)
inline virtual void sendShares(const Vector<int8_t> &_shares, PartyID _id, size_t _size)

Send a vector to a chosen party.

Parameters:
  • shares – The data elements to be sent to the party.

  • id – The index of the recipient party relative to the current party.

  • size – Number of data elements to be sent.

inline virtual void sendShares(const Vector<int16_t> &_shares, PartyID _id, size_t _size)
inline virtual void sendShares(const Vector<int32_t> &_shares, PartyID _id, size_t _size)
inline virtual void sendShares(const Vector<int64_t> &_shares, PartyID _id, size_t _size)
inline virtual void sendShares(const Vector<__int128_t> &_shares, PartyID _id, size_t _size)
inline virtual void receiveShare(int8_t &_share, PartyID _id)

Receive an element from the chosen party. blocking call.

Parameters:
  • element – reference to variable to receive into

  • id – The index of the sending party relative to the current party.

inline virtual void receiveShare(int16_t &_share, PartyID _id)
inline virtual void receiveShare(int32_t &_share, PartyID _id)
inline virtual void receiveShare(int64_t &_share, PartyID _id)
inline virtual void receiveShares(Vector<int8_t> &_shares, PartyID _id, size_t _size)

Receive a vector from some chosen party. blocking call.

Parameters:
  • shares – reference to vector to receive into

  • id – The index of the sending party relative to the current party.

  • size – Number of data elements to be received.

inline virtual void receiveShares(Vector<int16_t> &_shares, PartyID _id, size_t _size)
inline virtual void receiveShares(Vector<int32_t> &_shares, PartyID _id, size_t _size)
inline virtual void receiveShares(Vector<int64_t> &_shares, PartyID _id, size_t _size)
inline virtual void receiveShares(Vector<__int128_t> &_shares, PartyID _id, size_t _size)
inline virtual void exchangeShares(Vector<int8_t> sent_shares, Vector<int8_t> &received_shares, PartyID to_id, PartyID from_id, size_t _size)

Copy sent_shares into received_shares

Parameters:
  • sent_shares

  • received_shares

  • to_id

  • from_id

  • _size

inline virtual void exchangeShares(Vector<int16_t> sent_shares, Vector<int16_t> &received_shares, PartyID to_id, PartyID from_id, size_t _size)
inline virtual void exchangeShares(Vector<int32_t> sent_shares, Vector<int32_t> &received_shares, PartyID to_id, PartyID from_id, size_t _size)
inline virtual void exchangeShares(Vector<int64_t> sent_shares, Vector<int64_t> &received_shares, PartyID to_id, PartyID from_id, size_t _size)
inline virtual void exchangeShares(Vector<__int128_t> sent_shares, Vector<__int128_t> &received_shares, PartyID to_id, PartyID from_id, size_t _size)
inline virtual void exchangeShares(Vector<int8_t> sent_shares, Vector<int8_t> &received_shares, PartyID id, size_t _size)

Sends and Receives vectors to and from some same party. Subclasses may implement in an arbitrary order, but neither send nor receive should block each other. exchangeShares should block until both calls are completed. Implementations may choose to run send and receive concurrently, or queue the send while waiting on a blocking receive.

Parameters:
  • sent_shares – vector to send

  • received_shares – vector to receive into

  • id – The index of the other party relative to the current party.

  • size – Number of data elements to be sent and received.

inline virtual void exchangeShares(Vector<int16_t> sent_shares, Vector<int16_t> &received_shares, PartyID id, size_t _size)
inline virtual void exchangeShares(Vector<int32_t> sent_shares, Vector<int32_t> &received_shares, PartyID id, size_t _size)
inline virtual void exchangeShares(Vector<int64_t> sent_shares, Vector<int64_t> &received_shares, PartyID id, size_t _size)
inline virtual void exchangeShares(Vector<__int128_t> sent_shares, Vector<__int128_t> &received_shares, PartyID id, size_t _size)
inline virtual void sendShares(const std::vector<Vector<int8_t>> &shares, std::vector<PartyID> partyID)

Send multiple Vectors to multiple parties at the same time. Vector sizes must match.

Parameters:
  • shares – The std::vector of the vectors to be sent.

  • partyID – The std::vector of the parties to send to.

inline virtual void sendShares(const std::vector<Vector<int16_t>> &shares, std::vector<PartyID> partyID)
inline virtual void sendShares(const std::vector<Vector<int32_t>> &shares, std::vector<PartyID> partyID)
inline virtual void sendShares(const std::vector<Vector<int64_t>> &shares, std::vector<PartyID> partyID)
inline virtual void sendShares(const std::vector<Vector<__int128_t>> &shares, std::vector<PartyID> partyID)
inline virtual void receiveBroadcast(std::vector<Vector<int8_t>> &shares, std::vector<PartyID> partyID)

Do nothing.

Parameters:
  • shares

  • partyID

inline virtual void receiveBroadcast(std::vector<Vector<int16_t>> &shares, std::vector<PartyID> partyID)
inline virtual void receiveBroadcast(std::vector<Vector<int32_t>> &shares, std::vector<PartyID> partyID)
inline virtual void receiveBroadcast(std::vector<Vector<int64_t>> &shares, std::vector<PartyID> partyID)
inline virtual void receiveBroadcast(std::vector<Vector<__int128_t>> &shares, std::vector<PartyID> partyID)
inline virtual void exchangeShares(const std::vector<Vector<int8_t>> &shares, std::vector<Vector<int8_t>> &received_shares, std::vector<PartyID> to_id, std::vector<PartyID> from_id)

Copy each element of shares into received_shares. Lengths must match.

Parameters:
  • shares

  • received_shares

  • to_id

  • from_id

inline virtual void exchangeShares(const std::vector<Vector<int16_t>> &shares, std::vector<Vector<int16_t>> &received_shares, std::vector<PartyID> to_id, std::vector<PartyID> from_id)
inline virtual void exchangeShares(const std::vector<Vector<int32_t>> &shares, std::vector<Vector<int32_t>> &received_shares, std::vector<PartyID> to_id, std::vector<PartyID> from_id)
inline virtual void exchangeShares(const std::vector<Vector<int64_t>> &shares, std::vector<Vector<int64_t>> &received_shares, std::vector<PartyID> to_id, std::vector<PartyID> from_id)
inline virtual void exchangeShares(const std::vector<Vector<__int128_t>> &shares, std::vector<Vector<__int128_t>> &received_shares, std::vector<PartyID> to_id, std::vector<PartyID> from_id)

Private Members

int numParties