Customizable Communication Channels

The Channel trait in our MPC engine provides a flexible and extensible abstraction for message-passing between parties. It allows communication to be implemented in various ways, enabling users to choose between synchronous, asynchronous, and even platform-specific implementations. Polytune is deliberately communication-agnostic, while remaining quite flexible, offering the following features:

  • Customizable Transport: Implement the Channel trait using any transport mechanism — HTTP, WebSockets, in-memory queues, or custom networking protocols.
  • Sync & Async Support: Thanks to maybe_async, our trait seamlessly supports both synchronous and asynchronous implementations.
  • Serialization-Aware: The trait ensures that messages can be efficiently serialized and chunked when necessary, making it ideal for large payloads.

We provide example implementations for:

  • Rust sync channels using std::sync::mpsc
  • HTTP channels for distributed deployments for servers
  • WebAssembly-compatible HTTP channels for clients
  • Peer-to-Peer channels

How to Implement Your Own Channel

  1. Define a Struct: Implement your own channel struct, ensuring it manages communication between multiple parties.
  2. Implement the Channel Trait: Define the required methods (send_bytes_to, recv_bytes_from) based on your chosen communication mechanism.
  3. Handle Errors Gracefully: Ensure robust error handling for message sending and receiving.

That's it! You can create a custom Channel implementation that integrates seamlessly with Polytune, adapting it to different transport mechanisms such as network sockets or async channels.

Implementation Requirements

When implementing the Channel trait, you need to:

  1. Define the error types for sending and receiving operations
  2. Implement the sending mechanism through send_bytes_to
  3. Implement the receiving mechanism through recv_bytes_from
#![allow(unused)]
fn main() {
trait Channel {
    type SendError;
    type RecvError;

    async fn send_bytes_to(
        &mut self,
        p: usize,
        msg: Vec<u8>,
        info: SendInfo,
    ) -> Result<(), Self::SendError>;

    async fn recv_bytes_from(
        &mut self,
        p: usize,
        info: RecvInfo,
    ) -> Result<Vec<u8>, Self::RecvError>;
}
}

Tips for Custom Implementations

  1. Channel Parameters:

    • p: Index of the target party for send/receive
    • info: Various information useful for logging
    • msg: Message sent to the target party (only in send_bytes_to)
  2. Connection Management:

    • Consider connection setup/teardown if needed
    • Ensure proper resource cleanup
  3. Security Considerations:

    • Add encryption if transmitting over insecure channels
    • Implement authentication mechanisms if needed