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§
Sourcefn peer_id(&self) -> &str
fn peer_id(&self) -> &str
Remote peer ID (string to support both Nostr pubkeys and numeric IDs)
Sourcefn 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 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
Sourcefn 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 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)
Sourcefn is_connected(&self) -> bool
fn is_connected(&self) -> bool
Check if channel is still connected
Sourcefn bytes_sent(&self) -> u64
fn bytes_sent(&self) -> u64
Bytes sent through this channel
Sourcefn bytes_received(&self) -> u64
fn bytes_received(&self) -> u64
Bytes received through this channel