Communication

The communication/ directory abstracts how cdough 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 cdough::Communicator

Public Functions

inline MPICommunicator(int _currentId, int _msg_tag = 7, const std::string host_prefix = "localhost", double latency = 0, double bandwidth = std::numeric_limits<double>::infinity(), cdough::service::Setting setting = cdough::service::Setting::SAME)
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)
inline virtual void sendShares(const Vector<int8_t> &shares, PartyID _id) 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) override
inline virtual void sendShares(const Vector<int32_t> &shares, PartyID _id) override
inline virtual void sendShares(const Vector<int64_t> &shares, PartyID _id) override
inline virtual void sendShares(const Vector<__int128_t> &shares, PartyID _id) 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)
inline virtual void receiveShares(Vector<int8_t> &_shareVector, PartyID _id) 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) override
inline virtual void receiveShares(Vector<int32_t> &_shareVector, PartyID _id) override
inline virtual void receiveShares(Vector<int64_t> &_shareVector, PartyID _id) override
inline virtual void receiveShares(Vector<__int128_t> &_shareVector, PartyID _id) override
template<typename T>
inline void exchangeShares_impl(Vector<T> sent_shares, Vector<T> &received_shares, PartyID _id)

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) 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) override
inline virtual void exchangeShares(Vector<int32_t> sent_shares, Vector<int32_t> &received_shares, PartyID _id) override
inline virtual void exchangeShares(Vector<int64_t> sent_shares, Vector<int64_t> &received_shares, PartyID _id) override
inline virtual void exchangeShares(Vector<__int128_t> sent_shares, Vector<__int128_t> &received_shares, PartyID _id) override
template<typename T>
inline void exchangeShares_impl(Vector<T> _shares, Vector<T> &received_shares, PartyID to_id, PartyID from_id)
inline virtual void exchangeShares(Vector<int8_t> sent_shares, Vector<int8_t> &received_shares, PartyID to_id, PartyID from_id) 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) override
inline virtual void exchangeShares(Vector<int32_t> sent_shares, Vector<int32_t> &received_shares, PartyID to_id, PartyID from_id) override
inline virtual void exchangeShares(Vector<int64_t> sent_shares, Vector<int64_t> &received_shares, PartyID to_id, PartyID from_id) override
inline virtual void exchangeShares(Vector<__int128_t> sent_shares, Vector<__int128_t> &received_shares, PartyID to_id, PartyID from_id) 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
const int parallelism_factor = 1

No-copy Communicator

class NoCopyCommunicator : public cdough::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(int _currentId, const std::vector<int> &socket_map, int _numParties, std::string host_prefix, double latency, double bandwidth, cdough::service::Setting setting = cdough::service::Setting::SAME)

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)

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)

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)

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)

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)
inline virtual void sendShares(const Vector<int32_t> &_shares, PartyID _id)
inline virtual void sendShares(const Vector<int64_t> &_shares, PartyID _id)
inline virtual void sendShares(const Vector<__int128_t> &_shares, PartyID _id)
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)

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)
inline virtual void receiveShares(Vector<int32_t> &_shareVector, PartyID _id)
inline virtual void receiveShares(Vector<int64_t> &_shareVector, PartyID _id)
inline virtual void receiveShares(Vector<__int128_t> &_shareVector, PartyID _id)
inline virtual void exchangeShares(Vector<int8_t> sent_shares, Vector<int8_t> &received_shares, PartyID _id)

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)
inline virtual void exchangeShares(Vector<int32_t> sent_shares, Vector<int32_t> &received_shares, PartyID _id)
inline virtual void exchangeShares(Vector<int64_t> sent_shares, Vector<int64_t> &received_shares, PartyID _id)
inline virtual void exchangeShares(Vector<__int128_t> sent_shares, Vector<__int128_t> &received_shares, PartyID _id)
inline virtual void exchangeShares(Vector<int8_t> sent_shares, Vector<int8_t> &received_shares, PartyID to_id, PartyID from_id)

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)
inline virtual void exchangeShares(Vector<int32_t> sent_shares, Vector<int32_t> &received_shares, PartyID to_id, PartyID from_id)
inline virtual void exchangeShares(Vector<int64_t> sent_shares, Vector<int64_t> &received_shares, PartyID to_id, PartyID from_id)
inline virtual void exchangeShares(Vector<__int128_t> sent_shares, Vector<__int128_t> &received_shares, PartyID to_id, PartyID from_id)
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
namespace cdough
template<typename Engine>
class NoCopyCommunicatorFactory : public cdough::CommunicatorFactory<NoCopyCommunicatorFactory<Engine>>
#include <no_copy_communicator_factory.h>

Factor for the nocopy communicator to interface with the CommunicatorFactory API.

Public Functions

inline NoCopyCommunicatorFactory(Engine &engine, CommFactoryArgs args)
inline std::unique_ptr<Communicator> create()
inline void start()
inline int getPartyId() const
inline int getNumParties() const
inline cdough::service::Setting getSetting() const
inline void blockingReady()

Private Members

int partyId
int numParties
const int threadsNum_
const std::string host_prefix
Engine &engine
const cdough::service::Setting setting_
std::vector<std::vector<int>> socketMaps_

Vector of socket maps for each cdough thread. Each element of the outer vector is assigned to a thread. The inner vector maps from party ID to socket file descriptor:

socket_maps[Thread #][Party ID] -> Socket file descriptor

NOTE: this used to be a vector<map<int, int>>, but this led to a concurrent write and thus an infrequent race condition.

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 cdough::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(cdough::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 cdough::MPICommunicator, cdough::NoCopyCommunicator, cdough::NullCommunicator

Public Functions

inline Communicator(PartyID _currentId, std::string host_prefix = "localhost", double latency = 0, double bandwidth = std::numeric_limits<double>::infinity(), service::Setting setting = service::Setting::SAME)

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
inline double getLatency()

Get the communicator’s latency in milliseconds. This implementation returns a static value, but future implementations may directly measure the value in the caller.

Returns:

double

inline double getBandwidth()

Get the communicator’s bandwdith in Gbps. This implementation returns a static value, but future implementations may directly measure the value in the caller.

Returns:

double

inline service::Setting getSetting() const

Get the network setting (same/lan/wan) for this execution.

Returns:

service::Setting

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
inline void sendShare(uint8_t element, PartyID id)
inline void sendShare(uint16_t element, PartyID id)
inline void sendShare(uint32_t element, PartyID id)
inline void sendShare(uint64_t element, PartyID id)
virtual void sendShares(const Vector<int8_t> &shares, PartyID id) = 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) = 0
virtual void sendShares(const Vector<int32_t> &shares, PartyID id) = 0
virtual void sendShares(const Vector<int64_t> &shares, PartyID id) = 0
virtual void sendShares(const Vector<__int128_t> &shares, PartyID id) = 0
inline void sendShares(const Vector<uint8_t> &shares, PartyID id)
inline void sendShares(const Vector<uint16_t> &shares, PartyID id)
inline void sendShares(const Vector<uint32_t> &shares, PartyID id)
inline void sendShares(const Vector<uint64_t> &shares, PartyID id)
inline void sendShares(const Vector<__uint128_t> &shares, PartyID id)
inline void sendShares(const Vector<NTL::GF2E> &shares, PartyID id)
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
inline void receiveShare(uint8_t &element, PartyID id)
inline void receiveShare(uint16_t &element, PartyID id)
inline void receiveShare(uint32_t &element, PartyID id)
inline void receiveShare(uint64_t &element, PartyID id)
virtual void receiveShares(Vector<int8_t> &shares, PartyID id) = 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) = 0
virtual void receiveShares(Vector<int32_t> &shares, PartyID id) = 0
virtual void receiveShares(Vector<int64_t> &shares, PartyID id) = 0
virtual void receiveShares(Vector<__int128_t> &shares, PartyID id) = 0
inline void receiveShares(Vector<uint8_t> &shares, PartyID id)
inline void receiveShares(Vector<uint16_t> &shares, PartyID id)
inline void receiveShares(Vector<uint32_t> &shares, PartyID id)
inline void receiveShares(Vector<uint64_t> &shares, PartyID id)
inline void receiveShares(Vector<__uint128_t> &shares, PartyID id)
inline void receiveShares(Vector<NTL::GF2E> &shares, PartyID id)
virtual void exchangeShares(Vector<int8_t> sent_shares, Vector<int8_t> &received_shares, PartyID id) = 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) = 0
virtual void exchangeShares(Vector<int32_t> sent_shares, Vector<int32_t> &received_shares, PartyID id) = 0
virtual void exchangeShares(Vector<int64_t> sent_shares, Vector<int64_t> &received_shares, PartyID id) = 0
virtual void exchangeShares(Vector<__int128_t> sent_shares, Vector<__int128_t> &received_shares, PartyID id) = 0
inline void exchangeShares(Vector<uint8_t> sent_shares, Vector<uint8_t> &received_shares, PartyID id)
inline void exchangeShares(Vector<uint16_t> sent_shares, Vector<uint16_t> &received_shares, PartyID id)
inline void exchangeShares(Vector<uint32_t> sent_shares, Vector<uint32_t> &received_shares, PartyID id)
inline void exchangeShares(Vector<uint64_t> sent_shares, Vector<uint64_t> &received_shares, PartyID id)
inline void exchangeShares(Vector<__uint128_t> sent_shares, Vector<__uint128_t> &received_shares, PartyID id)
inline void exchangeShares(Vector<NTL::GF2E> &send_shares, Vector<NTL::GF2E> &recv_shares, PartyID id)
virtual void exchangeShares(Vector<int8_t> sent_shares, Vector<int8_t> &received_shares, PartyID to_id, PartyID from_id) = 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) = 0
virtual void exchangeShares(Vector<int32_t> sent_shares, Vector<int32_t> &received_shares, PartyID to_id, PartyID from_id) = 0
virtual void exchangeShares(Vector<int64_t> sent_shares, Vector<int64_t> &received_shares, PartyID to_id, PartyID from_id) = 0
virtual void exchangeShares(Vector<__int128_t> sent_shares, Vector<__int128_t> &received_shares, PartyID to_id, PartyID from_id) = 0
inline void exchangeShares(Vector<uint8_t> sent_shares, Vector<uint8_t> &received_shares, PartyID to_id, PartyID from_id)
inline void exchangeShares(Vector<uint16_t> sent_shares, Vector<uint16_t> &received_shares, PartyID to_id, PartyID from_id)
inline void exchangeShares(Vector<uint32_t> sent_shares, Vector<uint32_t> &received_shares, PartyID to_id, PartyID from_id)
inline void exchangeShares(Vector<uint64_t> sent_shares, Vector<uint64_t> &received_shares, PartyID to_id, PartyID from_id)
inline void exchangeShares(Vector<__uint128_t> sent_shares, Vector<__uint128_t> &received_shares, PartyID to_id, PartyID from_id)
inline void exchangeShares(const Vector<NTL::GF2E> &send_shares, Vector<NTL::GF2E> &recv_shares, PartyID to_id, PartyID from_id)
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
inline void sendShares(const std::vector<Vector<uint8_t>> &shares, std::vector<PartyID> partyID)
inline void sendShares(const std::vector<Vector<uint16_t>> &shares, std::vector<PartyID> partyID)
inline void sendShares(const std::vector<Vector<uint32_t>> &shares, std::vector<PartyID> partyID)
inline void sendShares(const std::vector<Vector<uint64_t>> &shares, std::vector<PartyID> partyID)
inline void sendShares(const std::vector<Vector<__uint128_t>> &shares, std::vector<PartyID> partyID)
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
inline void receiveBroadcast(std::vector<Vector<uint8_t>> &shares, std::vector<PartyID> partyID)
inline void receiveBroadcast(std::vector<Vector<uint16_t>> &shares, std::vector<PartyID> partyID)
inline void receiveBroadcast(std::vector<Vector<uint32_t>> &shares, std::vector<PartyID> partyID)
inline void receiveBroadcast(std::vector<Vector<uint64_t>> &shares, std::vector<PartyID> partyID)
inline void receiveBroadcast(std::vector<Vector<__uint128_t>> &shares, std::vector<PartyID> partyID)
inline void receiveBroadcast(std::vector<Vector<NTL::GF2E>> &shares, std::vector<PartyID> id)
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
inline void exchangeShares(const std::vector<Vector<uint8_t>> &shares, std::vector<Vector<uint8_t>> &received_shares, std::vector<PartyID> to_id, std::vector<PartyID> from_id)
inline void exchangeShares(const std::vector<Vector<uint16_t>> &shares, std::vector<Vector<uint16_t>> &received_shares, std::vector<PartyID> to_id, std::vector<PartyID> from_id)
inline void exchangeShares(const std::vector<Vector<uint32_t>> &shares, std::vector<Vector<uint32_t>> &received_shares, std::vector<PartyID> to_id, std::vector<PartyID> from_id)
inline void exchangeShares(const std::vector<Vector<uint64_t>> &shares, std::vector<Vector<uint64_t>> &received_shares, std::vector<PartyID> to_id, std::vector<PartyID> from_id)
inline void exchangeShares(const std::vector<Vector<__uint128_t>> &shares, std::vector<Vector<__uint128_t>> &received_shares, std::vector<PartyID> to_id, std::vector<PartyID> from_id)

Public Members

std::string host_prefix

Protected Functions

inline const Vector<uint8_t> serializeGF2E(const Vector<NTL::GF2E> &vec)
inline const Vector<NTL::GF2E> deserializeGF2E(const uint8_t *buf, size_t elms)

Protected Attributes

double latency

pairwise latency of this communicator, milliseconds

double bandwidth

pairwise bandwidth of this communicator, Gbps

PartyID currentId

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

size_t bytes_sent = 0
service::Setting setting_
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 void blockingReady()

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

inline auto getSetting() const

Get the network setting (same/lan/wan) according to the runtime.

Returns:

The Setting enum value for this execution.

Protected Attributes

double latency

pairwise latency of this communicator, milliseconds. Passed into Communicator

double bandwidth

pairwise bandwidth of this communicator, Gbps. Passed into Communicator

class NullCommunicator : public cdough::Communicator

Public Functions

inline NullCommunicator(std::string host_prefix = "localhost")

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)

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)
inline virtual void sendShares(const Vector<int32_t> &_shares, PartyID _id)
inline virtual void sendShares(const Vector<int64_t> &_shares, PartyID _id)
inline virtual void sendShares(const Vector<__int128_t> &_shares, PartyID _id)
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)

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)
inline virtual void receiveShares(Vector<int32_t> &_shares, PartyID _id)
inline virtual void receiveShares(Vector<int64_t> &_shares, PartyID _id)
inline virtual void receiveShares(Vector<__int128_t> &_shares, PartyID _id)
inline virtual void exchangeShares(Vector<int8_t> sent_shares, Vector<int8_t> &received_shares, PartyID to_id, PartyID from_id)

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)
inline virtual void exchangeShares(Vector<int32_t> sent_shares, Vector<int32_t> &received_shares, PartyID to_id, PartyID from_id)
inline virtual void exchangeShares(Vector<int64_t> sent_shares, Vector<int64_t> &received_shares, PartyID to_id, PartyID from_id)
inline virtual void exchangeShares(Vector<__int128_t> sent_shares, Vector<__int128_t> &received_shares, PartyID to_id, PartyID from_id)
inline virtual void exchangeShares(Vector<int8_t> sent_shares, Vector<int8_t> &received_shares, PartyID id)

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)
inline virtual void exchangeShares(Vector<int32_t> sent_shares, Vector<int32_t> &received_shares, PartyID id)
inline virtual void exchangeShares(Vector<int64_t> sent_shares, Vector<int64_t> &received_shares, PartyID id)
inline virtual void exchangeShares(Vector<__int128_t> sent_shares, Vector<__int128_t> &received_shares, PartyID id)
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