LinkTransport

Trait LinkTransport 

Source
pub trait LinkTransport:
    Send
    + Sync
    + 'static {
    type Conn: LinkConn + 'static;

Show 14 methods // Required methods fn local_peer(&self) -> PeerId; fn external_address(&self) -> Option<SocketAddr>; fn peer_table(&self) -> Vec<(PeerId, Capabilities)>; fn peer_capabilities(&self, peer: &PeerId) -> Option<Capabilities>; fn subscribe(&self) -> Receiver<LinkEvent>; fn accept(&self, proto: ProtocolId) -> Incoming<Self::Conn>; fn dial( &self, peer: PeerId, proto: ProtocolId, ) -> BoxFuture<'_, LinkResult<Self::Conn>>; fn dial_addr( &self, addr: SocketAddr, proto: ProtocolId, ) -> BoxFuture<'_, LinkResult<Self::Conn>>; fn supported_protocols(&self) -> Vec<ProtocolId>; fn register_protocol(&self, proto: ProtocolId); fn unregister_protocol(&self, proto: ProtocolId); fn is_connected(&self, peer: &PeerId) -> bool; fn active_connections(&self) -> usize; fn shutdown(&self) -> BoxFuture<'_, ()>;
}
Expand description

The primary transport abstraction for overlay networks.

This trait provides everything an overlay needs to establish connections, send/receive data, and monitor the transport layer.

§Implementation Notes

Implementors should:

  • Handle NAT traversal transparently
  • Maintain a peer table with capabilities
  • Emit events for connection state changes
  • Support protocol multiplexing

§Example Implementation

The default implementation wraps [P2pEndpoint]:

let config = P2pConfig::builder()
    .bind_addr("0.0.0.0:0".parse()?)
    .build()?;
let endpoint = P2pEndpoint::new(config).await?;
let transport: Arc<dyn LinkTransport<Conn = P2pLinkConn>> = Arc::new(endpoint);

Required Associated Types§

Source

type Conn: LinkConn + 'static

The connection type returned by this transport.

Required Methods§

Source

fn local_peer(&self) -> PeerId

Get our local peer ID.

Source

fn external_address(&self) -> Option<SocketAddr>

Get our observed external address (if known).

Source

fn peer_table(&self) -> Vec<(PeerId, Capabilities)>

Get the current peer table with capabilities.

This returns all known peers, including disconnected ones that are still in the bootstrap cache.

Source

fn peer_capabilities(&self, peer: &PeerId) -> Option<Capabilities>

Get capabilities for a specific peer.

Source

fn subscribe(&self) -> Receiver<LinkEvent>

Subscribe to transport events.

Source

fn accept(&self, proto: ProtocolId) -> Incoming<Self::Conn>

Accept incoming connections for a specific protocol.

Source

fn dial( &self, peer: PeerId, proto: ProtocolId, ) -> BoxFuture<'_, LinkResult<Self::Conn>>

Dial a peer to establish a connection.

This may involve NAT traversal, which is handled transparently.

Source

fn dial_addr( &self, addr: SocketAddr, proto: ProtocolId, ) -> BoxFuture<'_, LinkResult<Self::Conn>>

Dial a peer by address (for bootstrap).

Source

fn supported_protocols(&self) -> Vec<ProtocolId>

Get the list of protocols we support.

Source

fn register_protocol(&self, proto: ProtocolId)

Register a protocol as supported.

Source

fn unregister_protocol(&self, proto: ProtocolId)

Unregister a protocol.

Source

fn is_connected(&self, peer: &PeerId) -> bool

Check if we’re connected to a peer.

Source

fn active_connections(&self) -> usize

Get the number of active connections.

Source

fn shutdown(&self) -> BoxFuture<'_, ()>

Gracefully shutdown the transport.

Implementors§