pub struct Relay { /* private fields */ }Expand description
Relay that fans out packets from one side to all others.
- Supports both packed bytes and full Packet.
- Has RX & TX queues, like Router.
- Uses a Clock for the *_with_timeout APIs, same style as Router.
Implementations§
Source§impl Relay
impl Relay
Sourcepub fn new(clock: Box<dyn Clock + Send + Sync>) -> Self
pub fn new(clock: Box<dyn Clock + Send + Sync>) -> Self
Create a new relay with the given clock.
pub fn sender(&self) -> Arc<str>
pub fn set_sender<S: AsRef<str>>(&self, sender: S)
Sourcepub fn note_side_link_probe_sample(
&self,
side: RelaySideId,
bytes: usize,
duration_ms: u64,
) -> TelemetryResult<()>
pub fn note_side_link_probe_sample( &self, side: RelaySideId, bytes: usize, duration_ms: u64, ) -> TelemetryResult<()>
Seed adaptive route selection with a transport-measured link probe.
Call this after a side-specific bring-up probe, or whenever the transport already knows the duration for a frame. The relay does not emit synthetic probe frames by itself.
Sourcepub fn add_side_packed<F>(&self, name: &'static str, tx: F) -> RelaySideId
pub fn add_side_packed<F>(&self, name: &'static str, tx: F) -> RelaySideId
Register a side whose TX callback consumes packed packet bytes.
Returns the side id later used for ingress APIs such as rx_packed_from_side.
The default options disable the relay’s per-link reliable framing on this side.
Sourcepub fn add_side_packed_small_packets<F>(
&self,
name: &'static str,
tx: F,
max_frame_bytes: usize,
) -> RelaySideId
pub fn add_side_packed_small_packets<F>( &self, name: &'static str, tx: F, max_frame_bytes: usize, ) -> RelaySideId
Register a packed side with bounded-frame transport enabled.
max_frame_bytes == 0 leaves frames unbounded.
Sourcepub fn add_side_packed_with_options<F>(
&self,
name: &'static str,
tx: F,
opts: RelaySideOptions,
) -> RelaySideId
pub fn add_side_packed_with_options<F>( &self, name: &'static str, tx: F, opts: RelaySideOptions, ) -> RelaySideId
Register a packed-output side with explicit side options.
opts.reliable_enabled enables relay-managed per-hop ACK/retransmit behavior on this side.
opts.link_local_enabled gates link-local-only forwarding and discovery use of this side.
ingress_enabled and egress_enabled set the initial directional policy.
Sourcepub fn add_side_packet<F>(&self, name: &'static str, tx: F) -> RelaySideId
pub fn add_side_packet<F>(&self, name: &'static str, tx: F) -> RelaySideId
Register a side whose TX callback receives decoded Packet values.
Packet-output sides do not preserve the relay’s packed reliable hop framing, so use a packed side when this hop should participate in relay-managed per-link reliability.
Sourcepub fn add_side_packet_with_options<F>(
&self,
name: &'static str,
tx: F,
opts: RelaySideOptions,
) -> RelaySideId
pub fn add_side_packet_with_options<F>( &self, name: &'static str, tx: F, opts: RelaySideOptions, ) -> RelaySideId
Register a packet-output side with explicit side options.
Sourcepub fn remove_side(&self, side: RelaySideId) -> TelemetryResult<()>
pub fn remove_side(&self, side: RelaySideId) -> TelemetryResult<()>
Remove a side while keeping existing side IDs stable.
side must be an id returned by one of the add_side_* calls. Remaining side ids are not
renumbered.
Sourcepub fn set_side_ingress_enabled(
&self,
side: RelaySideId,
enabled: bool,
) -> TelemetryResult<()>
pub fn set_side_ingress_enabled( &self, side: RelaySideId, enabled: bool, ) -> TelemetryResult<()>
Enable or disable ingress processing for a registered side.
Sourcepub fn set_side_egress_enabled(
&self,
side: RelaySideId,
enabled: bool,
) -> TelemetryResult<()>
pub fn set_side_egress_enabled( &self, side: RelaySideId, enabled: bool, ) -> TelemetryResult<()>
Enable or disable egress toward a registered side.
Sourcepub fn set_source_route_mode(
&self,
src: Option<RelaySideId>,
mode: RouteSelectionMode,
) -> TelemetryResult<()>
pub fn set_source_route_mode( &self, src: Option<RelaySideId>, mode: RouteSelectionMode, ) -> TelemetryResult<()>
Set the route-selection policy for traffic originating from src.
src == None targets locally-originated relay traffic such as discovery output.
Sourcepub fn clear_source_route_mode(
&self,
src: Option<RelaySideId>,
) -> TelemetryResult<()>
pub fn clear_source_route_mode( &self, src: Option<RelaySideId>, ) -> TelemetryResult<()>
Clear a source-specific route-selection override.
Sourcepub fn set_route_weight(
&self,
src: Option<RelaySideId>,
dst: RelaySideId,
weight: u32,
) -> TelemetryResult<()>
pub fn set_route_weight( &self, src: Option<RelaySideId>, dst: RelaySideId, weight: u32, ) -> TelemetryResult<()>
Set the weighted-routing weight from src toward dst.
Sourcepub fn clear_route_weight(
&self,
src: Option<RelaySideId>,
dst: RelaySideId,
) -> TelemetryResult<()>
pub fn clear_route_weight( &self, src: Option<RelaySideId>, dst: RelaySideId, ) -> TelemetryResult<()>
Clear a previously configured weighted-routing weight override.
Sourcepub fn set_route_priority(
&self,
src: Option<RelaySideId>,
dst: RelaySideId,
priority: u32,
) -> TelemetryResult<()>
pub fn set_route_priority( &self, src: Option<RelaySideId>, dst: RelaySideId, priority: u32, ) -> TelemetryResult<()>
Set the failover priority from src toward dst.
Sourcepub fn clear_route_priority(
&self,
src: Option<RelaySideId>,
dst: RelaySideId,
) -> TelemetryResult<()>
pub fn clear_route_priority( &self, src: Option<RelaySideId>, dst: RelaySideId, ) -> TelemetryResult<()>
Clear a previously configured failover priority override.
Sourcepub fn set_route(
&self,
src: Option<RelaySideId>,
dst: RelaySideId,
enabled: bool,
) -> TelemetryResult<()>
pub fn set_route( &self, src: Option<RelaySideId>, dst: RelaySideId, enabled: bool, ) -> TelemetryResult<()>
Allow or block routing from src toward dst.
Sourcepub fn set_typed_route(
&self,
src: Option<RelaySideId>,
ty: DataType,
dst: RelaySideId,
enabled: bool,
) -> TelemetryResult<()>
pub fn set_typed_route( &self, src: Option<RelaySideId>, ty: DataType, dst: RelaySideId, enabled: bool, ) -> TelemetryResult<()>
Allow or block routing for a specific DataType from src toward dst.
Sourcepub fn clear_typed_route(
&self,
src: Option<RelaySideId>,
ty: DataType,
dst: RelaySideId,
) -> TelemetryResult<()>
pub fn clear_typed_route( &self, src: Option<RelaySideId>, ty: DataType, dst: RelaySideId, ) -> TelemetryResult<()>
Clear a typed route override for the (src, ty, dst) triple.
Sourcepub fn clear_route(
&self,
src: Option<RelaySideId>,
dst: RelaySideId,
) -> TelemetryResult<()>
pub fn clear_route( &self, src: Option<RelaySideId>, dst: RelaySideId, ) -> TelemetryResult<()>
Clear a non-typed route override so the relay falls back to default behavior.
Sourcepub fn announce_discovery(&self) -> TelemetryResult<()>
pub fn announce_discovery(&self) -> TelemetryResult<()>
Queues an immediate discovery announcement for this relay.
Sourcepub fn announce_leave(&self) -> TelemetryResult<()>
pub fn announce_leave(&self) -> TelemetryResult<()>
Broadcast that this relay is leaving so peers can prune topology immediately.
Sourcepub fn poll_discovery(&self) -> TelemetryResult<bool>
pub fn poll_discovery(&self) -> TelemetryResult<bool>
Polls discovery state and queues an announce if the cadence says one is due.
Sourcepub fn export_topology(&self) -> TopologySnapshot
pub fn export_topology(&self) -> TopologySnapshot
Exports the relay’s current discovered topology snapshot.
pub fn client_stats(&self, sender_id: &str) -> Option<ClientStatsSnapshot>
pub fn export_runtime_stats(&self) -> RuntimeStatsSnapshot
Sourcepub fn export_memory_layout_json(&self) -> String
pub fn export_memory_layout_json(&self) -> String
Export current relay memory usage/layout as JSON for profiling.
Sourcepub fn rx_packed_from_side(
&self,
src: RelaySideId,
bytes: &[u8],
) -> TelemetryResult<()>
pub fn rx_packed_from_side( &self, src: RelaySideId, bytes: &[u8], ) -> TelemetryResult<()>
Enqueue packed bytes that originated from src into the relay RX queue.
Note: Arc::from(bytes) allocates and copies len bytes into a new Arc<[u8]>.
This is still “fast enough” for many cases, but it is not allocation-free / ISR-safe.
Sourcepub fn rx_from_side(
&self,
src: RelaySideId,
packet: Packet,
) -> TelemetryResult<()>
pub fn rx_from_side( &self, src: RelaySideId, packet: Packet, ) -> TelemetryResult<()>
Enqueue a full packet that originated from src into the relay RX queue.
The packet is wrapped in Arc<Packet> so fanout can clone the pointer cheaply.
Sourcepub fn clear_queues(&self)
pub fn clear_queues(&self)
Clear both RX and TX queues.
Sourcepub fn clear_rx_queue(&self)
pub fn clear_rx_queue(&self)
Clear only RX queue.
Sourcepub fn clear_tx_queue(&self)
pub fn clear_tx_queue(&self)
Clear only TX queue.
Sourcepub fn process_rx_queue(&self) -> TelemetryResult<()>
pub fn process_rx_queue(&self) -> TelemetryResult<()>
Drain the RX queue fully, expanding to TX items.
Sourcepub fn process_tx_queue(&self) -> TelemetryResult<()>
pub fn process_tx_queue(&self) -> TelemetryResult<()>
Drain the TX queue fully, invoking per-side TX handlers.
If called from inside a side TX callback, this becomes a no-op so relay TX handlers cannot recurse into nested queue drains on the same stack.
Sourcepub fn process_all_queues(&self) -> TelemetryResult<()>
pub fn process_all_queues(&self) -> TelemetryResult<()>
Drain RX then TX queues fully (one pass).
Sourcepub fn process_tx_queue_with_timeout(
&self,
timeout_ms: u32,
) -> TelemetryResult<()>
pub fn process_tx_queue_with_timeout( &self, timeout_ms: u32, ) -> TelemetryResult<()>
Process the TX queue for up to timeout_ms milliseconds.
timeout_ms == 0 drains fully. If called from inside a side TX callback, this becomes a
no-op so relay TX handlers cannot recurse into nested queue drains on the same stack.
Sourcepub fn process_rx_queue_with_timeout(
&self,
timeout_ms: u32,
) -> TelemetryResult<()>
pub fn process_rx_queue_with_timeout( &self, timeout_ms: u32, ) -> TelemetryResult<()>
Process RX queue with timeout.
Sourcepub fn process_all_queues_with_timeout(
&self,
timeout_ms: u32,
) -> TelemetryResult<()>
pub fn process_all_queues_with_timeout( &self, timeout_ms: u32, ) -> TelemetryResult<()>
Process RX and TX queues interleaved for up to timeout_ms milliseconds.
timeout_ms == 0 drains fully. If called from inside a side TX callback, this becomes a
no-op so relay TX handlers cannot recurse into nested queue drains on the same stack.
Sourcepub fn periodic(&self, timeout_ms: u32) -> TelemetryResult<()>
pub fn periodic(&self, timeout_ms: u32) -> TelemetryResult<()>
Runs one application-loop maintenance cycle.
This polls built-in discovery when that feature is compiled in, then drains queued RX/TX
work for up to timeout_ms milliseconds.