Skip to main content

Transport

Trait Transport 

Source
pub trait Transport {
    // Required methods
    fn transport_id(&self) -> TransportId;
    fn transport_type(&self) -> &TransportType;
    fn state(&self) -> TransportState;
    fn mtu(&self) -> u16;
    fn start(&mut self) -> Result<(), TransportError>;
    fn stop(&mut self) -> Result<(), TransportError>;
    fn send(
        &self,
        addr: &TransportAddr,
        data: &[u8],
    ) -> Result<(), TransportError>;
    fn discover(&self) -> Result<Vec<DiscoveredPeer>, TransportError>;

    // Provided methods
    fn link_mtu(&self, addr: &TransportAddr) -> u16 { ... }
    fn auto_connect(&self) -> bool { ... }
    fn accept_connections(&self) -> bool { ... }
    fn close_connection(&self, _addr: &TransportAddr) { ... }
}
Expand description

Transport trait defining the interface for transport drivers.

This is a simplified synchronous trait. Actual implementations would be async and use channels for event delivery.

Required Methods§

Source

fn transport_id(&self) -> TransportId

Get the transport identifier.

Source

fn transport_type(&self) -> &TransportType

Get the transport type metadata.

Source

fn state(&self) -> TransportState

Get the current state.

Source

fn mtu(&self) -> u16

Get the MTU for this transport.

Source

fn start(&mut self) -> Result<(), TransportError>

Start the transport.

Source

fn stop(&mut self) -> Result<(), TransportError>

Stop the transport.

Source

fn send(&self, addr: &TransportAddr, data: &[u8]) -> Result<(), TransportError>

Send data to a transport address.

Source

fn discover(&self) -> Result<Vec<DiscoveredPeer>, TransportError>

Discover potential peers (if supported).

Provided Methods§

Get the MTU for a specific link.

Returns the MTU negotiated for the given transport address, or falls back to the transport-wide default if the address is unknown or the transport doesn’t support per-link MTU negotiation.

Source

fn auto_connect(&self) -> bool

Whether to auto-connect to peers returned by discover(). Default: false. Concrete transports read from their own config.

Source

fn accept_connections(&self) -> bool

Whether to accept inbound handshake initiations on this transport. Default: true (preserves UDP’s current implicit behavior).

Source

fn close_connection(&self, _addr: &TransportAddr)

Close a specific connection (connection-oriented transports only).

For connectionless transports (UDP, Ethernet), this is a no-op. Connection-oriented transports (TCP, Tor) remove the connection from their pool and drop the underlying stream.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§