polytune 0.2.0-alpha.2

Maliciously-Secure Multi-Party Computation (MPC) Engine using Authenticated Garbling
Documentation
# 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 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.
- **Serialization-Aware**: The trait ensures that messages can be efficiently serialized.

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`

```rust
trait Channel {
    type SendError;
    type RecvError;

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

    async fn recv_bytes_from(
        &self,
        p: usize,
        phase: &str,
    ) -> Result<Vec<u8>, Self::RecvError>;
}
```

## Tips for Custom Implementations

1. **Channel Parameters**:

   - `p`: Index of the target party for send/receive
   - `phase`: Phase of the protocol where the message is sent
   - `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