Skip to main content

Relay

Struct Relay 

Source
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

Source

pub fn new(clock: Box<dyn Clock + Send + Sync>) -> Self

Create a new relay with the given clock.

Source

pub fn sender(&self) -> Arc<str>

Source

pub fn set_sender<S: AsRef<str>>(&self, sender: S)

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.

Source

pub fn add_side_packed<F>(&self, name: &'static str, tx: F) -> RelaySideId
where F: Fn(&[u8]) -> TelemetryResult<()> + Send + Sync + 'static,

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.

Source

pub fn add_side_packed_small_packets<F>( &self, name: &'static str, tx: F, max_frame_bytes: usize, ) -> RelaySideId
where F: Fn(&[u8]) -> TelemetryResult<()> + Send + Sync + 'static,

Register a packed side with bounded-frame transport enabled.

max_frame_bytes == 0 leaves frames unbounded.

Source

pub fn add_side_packed_with_options<F>( &self, name: &'static str, tx: F, opts: RelaySideOptions, ) -> RelaySideId
where F: Fn(&[u8]) -> TelemetryResult<()> + Send + Sync + 'static,

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.

Source

pub fn add_side_packet<F>(&self, name: &'static str, tx: F) -> RelaySideId
where F: Fn(&Packet) -> TelemetryResult<()> + Send + Sync + 'static,

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.

Source

pub fn add_side_packet_with_options<F>( &self, name: &'static str, tx: F, opts: RelaySideOptions, ) -> RelaySideId
where F: Fn(&Packet) -> TelemetryResult<()> + Send + Sync + 'static,

Register a packet-output side with explicit side options.

Source

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.

Source

pub fn set_side_ingress_enabled( &self, side: RelaySideId, enabled: bool, ) -> TelemetryResult<()>

Enable or disable ingress processing for a registered side.

Source

pub fn set_side_egress_enabled( &self, side: RelaySideId, enabled: bool, ) -> TelemetryResult<()>

Enable or disable egress toward a registered side.

Source

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.

Source

pub fn clear_source_route_mode( &self, src: Option<RelaySideId>, ) -> TelemetryResult<()>

Clear a source-specific route-selection override.

Source

pub fn set_route_weight( &self, src: Option<RelaySideId>, dst: RelaySideId, weight: u32, ) -> TelemetryResult<()>

Set the weighted-routing weight from src toward dst.

Source

pub fn clear_route_weight( &self, src: Option<RelaySideId>, dst: RelaySideId, ) -> TelemetryResult<()>

Clear a previously configured weighted-routing weight override.

Source

pub fn set_route_priority( &self, src: Option<RelaySideId>, dst: RelaySideId, priority: u32, ) -> TelemetryResult<()>

Set the failover priority from src toward dst.

Source

pub fn clear_route_priority( &self, src: Option<RelaySideId>, dst: RelaySideId, ) -> TelemetryResult<()>

Clear a previously configured failover priority override.

Source

pub fn set_route( &self, src: Option<RelaySideId>, dst: RelaySideId, enabled: bool, ) -> TelemetryResult<()>

Allow or block routing from src toward dst.

Source

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.

Source

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.

Source

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.

Source

pub fn announce_discovery(&self) -> TelemetryResult<()>

Queues an immediate discovery announcement for this relay.

Source

pub fn announce_leave(&self) -> TelemetryResult<()>

Broadcast that this relay is leaving so peers can prune topology immediately.

Source

pub fn poll_discovery(&self) -> TelemetryResult<bool>

Polls discovery state and queues an announce if the cadence says one is due.

Source

pub fn export_topology(&self) -> TopologySnapshot

Exports the relay’s current discovered topology snapshot.

Source

pub fn client_stats(&self, sender_id: &str) -> Option<ClientStatsSnapshot>

Source

pub fn export_runtime_stats(&self) -> RuntimeStatsSnapshot

Source

pub fn export_memory_layout_json(&self) -> String

Export current relay memory usage/layout as JSON for profiling.

Source

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.

Source

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.

Source

pub fn clear_queues(&self)

Clear both RX and TX queues.

Source

pub fn clear_rx_queue(&self)

Clear only RX queue.

Source

pub fn clear_tx_queue(&self)

Clear only TX queue.

Source

pub fn process_rx_queue(&self) -> TelemetryResult<()>

Drain the RX queue fully, expanding to TX items.

Source

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.

Source

pub fn process_all_queues(&self) -> TelemetryResult<()>

Drain RX then TX queues fully (one pass).

Source

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.

Source

pub fn process_rx_queue_with_timeout( &self, timeout_ms: u32, ) -> TelemetryResult<()>

Process RX queue with timeout.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl !Freeze for Relay

§

impl !RefUnwindSafe for Relay

§

impl !UnwindSafe for Relay

§

impl Send for Relay

§

impl Sync for Relay

§

impl Unpin for Relay

§

impl UnsafeUnpin for Relay

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.