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§
Required Methods§
Sourcefn local_peer(&self) -> PeerId
fn local_peer(&self) -> PeerId
Get our local peer ID.
Sourcefn external_address(&self) -> Option<SocketAddr>
fn external_address(&self) -> Option<SocketAddr>
Get our observed external address (if known).
Sourcefn peer_table(&self) -> Vec<(PeerId, Capabilities)>
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.
Sourcefn peer_capabilities(&self, peer: &PeerId) -> Option<Capabilities>
fn peer_capabilities(&self, peer: &PeerId) -> Option<Capabilities>
Get capabilities for a specific peer.
Sourcefn accept(&self, proto: ProtocolId) -> Incoming<Self::Conn>
fn accept(&self, proto: ProtocolId) -> Incoming<Self::Conn>
Accept incoming connections for a specific protocol.
Sourcefn dial(
&self,
peer: PeerId,
proto: ProtocolId,
) -> BoxFuture<'_, LinkResult<Self::Conn>>
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.
Sourcefn dial_addr(
&self,
addr: SocketAddr,
proto: ProtocolId,
) -> BoxFuture<'_, LinkResult<Self::Conn>>
fn dial_addr( &self, addr: SocketAddr, proto: ProtocolId, ) -> BoxFuture<'_, LinkResult<Self::Conn>>
Dial a peer by address (for bootstrap).
Sourcefn supported_protocols(&self) -> Vec<ProtocolId>
fn supported_protocols(&self) -> Vec<ProtocolId>
Get the list of protocols we support.
Sourcefn register_protocol(&self, proto: ProtocolId)
fn register_protocol(&self, proto: ProtocolId)
Register a protocol as supported.
Sourcefn unregister_protocol(&self, proto: ProtocolId)
fn unregister_protocol(&self, proto: ProtocolId)
Unregister a protocol.
Sourcefn is_connected(&self, peer: &PeerId) -> bool
fn is_connected(&self, peer: &PeerId) -> bool
Check if we’re connected to a peer.
Sourcefn active_connections(&self) -> usize
fn active_connections(&self) -> usize
Get the number of active connections.