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
- Define a Struct: Implement your own channel struct, ensuring it manages communication between multiple parties.
- Implement the
Channel
Trait: Define the required methods (send_bytes_to
,recv_bytes_from
) based on your chosen communication mechanism. - 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:
- Define the error types for sending and receiving operations
- Implement the sending mechanism through
send_bytes_to
- 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
-
Channel Parameters:
p
: Index of the target party for send/receiveinfo
: Various information useful for loggingmsg
: Message sent to the target party (only insend_bytes_to
)
-
Connection Management:
- Consider connection setup/teardown if needed
- Ensure proper resource cleanup
-
Security Considerations:
- Add encryption if transmitting over insecure channels
- Implement authentication mechanisms if needed