Skip to main content

FrameTransport

Trait FrameTransport 

Source
pub trait FrameTransport: Send + Sync {
    // Required methods
    fn key(&self) -> TransportKey;
    fn address(&self) -> WorkerAddress;
    fn bind(
        &self,
        anchor_id: u64,
        session_id: u64,
    ) -> BoxFuture<'_, Result<Receiver<Vec<u8>>>>;
    fn connect(
        &self,
        peer: WorkerId,
        anchor_id: u64,
        session_id: u64,
    ) -> BoxFuture<'_, Result<Sender<Vec<u8>>>>;

    // Provided method
    fn register(&self, _peer_info: &PeerInfo) -> Result<()> { ... }
}
Expand description

Transport abstraction for frame-level ordered delivery.

§Ordered-Delivery Contract

All frames – including data frames (Item, Heartbeat) and sentinel frames (Dropped, Detached, Finalized, TransportError) – MUST travel the same physical channel established by FrameTransport::bind / FrameTransport::connect. Sentinels MUST NOT be injected via a side channel; the FIFO ordering guarantee of the underlying channel is load-bearing for the correctness of the streaming protocol.

Implementations MUST preserve send order: a frame sent before another MUST be received before that other frame on the corresponding flume::Receiver.

§Usage

The transport operates at the raw byte level. Callers are responsible for serializing frame values to Vec<u8> before sending via flume::Sender::send_async, and for deserializing bytes received from flume::Receiver::recv_async.

§Async Design

Both bind and connect return BoxFuture to support async implementations (e.g., network setup). The heap allocation is acceptable because these are setup-path calls, not per-frame hot-path operations.

Required Methods§

Source

fn key(&self) -> TransportKey

Identifies this transport’s entry in WorkerAddress.

Mirrors crate::Transport::key. Used by the streaming attach handshake to tell the client which FrameTransport to call connect on, and by register to look up the peer’s matching endpoint entry.

Source

fn address(&self) -> WorkerAddress

This transport’s local listener endpoints, encoded for inclusion in the local WorkerAddress.

Mirrors crate::Transport::address. Returned at builder time so the Velo builder can merge it into the local PeerInfo’s WorkerAddress. Implementations that do not open their own listener (e.g., a transport that piggybacks on the messenger) should return [WorkerAddress::default].

Source

fn bind( &self, anchor_id: u64, session_id: u64, ) -> BoxFuture<'_, Result<Receiver<Vec<u8>>>>

Bind a receive endpoint for the given anchor.

  • anchor_id: identifies which anchor this binding is for.
  • session_id: unique session identifier for this attachment; used by the transport to discriminate between successive sessions on the same anchor so that stale frames from a prior session are not delivered.

Returns the receiver half of the per-session frame channel. Endpoint resolution is no longer string-based — the connecting peer resolves the listener address from the bound worker’s WorkerAddress entry for this transport’s Self::key.

The channel established by bind / connect MUST provide ordered, loss-free delivery of all frames including sentinels.

Source

fn connect( &self, peer: WorkerId, anchor_id: u64, session_id: u64, ) -> BoxFuture<'_, Result<Sender<Vec<u8>>>>

Connect a write endpoint to the given peer’s bound anchor.

  • peer: the WorkerId of the worker that called Self::bind. The transport looks up the peer’s cached endpoint (populated via Self::register) to determine the actual socket address.
  • anchor_id: identifies which anchor this writer is attached to.
  • session_id: unique session identifier for this attachment; used by the transport to route frames to the correct reader.

Returns a flume::Sender<Vec<u8>> for sending frames to the bound receiver.

Provided Methods§

Source

fn register(&self, _peer_info: &PeerInfo) -> Result<()>

Notify this transport that a peer’s PeerInfo is now known.

Mirrors crate::Transport::register. The transport extracts its own entry from peer_info.worker_address() (using Self::key), decodes the endpoint(s), and caches a resolved socket address keyed by the peer’s WorkerId for later use by Self::connect.

Default implementation is a no-op for transports that do not require per-peer state (e.g., a transport that piggybacks on the messenger which already tracks peers).

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§