Skip to main content

PeerChannel

Trait PeerChannel 

Source
pub trait PeerChannel: Send + Sync {
    // Required methods
    fn peer_id(&self) -> &str;
    fn send<'life0, 'async_trait>(
        &'life0 self,
        data: Vec<u8>,
    ) -> Pin<Box<dyn Future<Output = Result<(), ChannelError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn recv<'life0, 'async_trait>(
        &'life0 self,
        timeout: Duration,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, ChannelError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn is_connected(&self) -> bool;
    fn bytes_sent(&self) -> u64;
    fn bytes_received(&self) -> u64;
}
Expand description

A channel to a single peer for sending/receiving bytes

This is the core abstraction that allows the same P2P logic to work with:

  • Real WebRTC data channels (production)
  • Mock in-memory channels (simulation/testing)

Required Methods§

Source

fn peer_id(&self) -> &str

Remote peer ID (string to support both Nostr pubkeys and numeric IDs)

Source

fn send<'life0, 'async_trait>( &'life0 self, data: Vec<u8>, ) -> Pin<Box<dyn Future<Output = Result<(), ChannelError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Send bytes to peer

Source

fn recv<'life0, 'async_trait>( &'life0 self, timeout: Duration, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, ChannelError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Receive bytes from peer (with timeout)

Source

fn is_connected(&self) -> bool

Check if channel is still connected

Source

fn bytes_sent(&self) -> u64

Bytes sent through this channel

Source

fn bytes_received(&self) -> u64

Bytes received through this channel

Implementors§