Skip to main content

PathSelector

Struct PathSelector 

Source
pub struct PathSelector { /* private fields */ }
Expand description

Path selector for optimal relay selection.

Implementations§

Source§

impl PathSelector

Source

pub fn new() -> Self

Creates a new path selector with default configuration.

Source

pub fn with_config(config: PathConfig, relay_manager: RelayManager) -> Self

Creates a new path selector with custom configuration.

Source

pub fn set_local_device_id(&mut self, device_id: impl Into<String>)

Sets the local device ID for deterministic gossip decisions.

Source

pub fn current_relay_role(&self) -> RelayRole

Returns the current RelayRole from the internal RelayManager.

Exposed for read-only callers (e.g., the telemetry aggregator that needs to know the current relay role without widening the surface to the full RelayManager API).

Source

pub fn evaluate_relay_transition( &mut self, connection_count: usize, battery_level: u8, is_charging: bool, ) -> Option<RelayTransition>

Re-evaluates the local relay role against current connectivity and battery, applying any change to the internal RelayManager.

Returns Some(transition) only when the role actually changes, so the caller can emit a role-transition event exactly once per transition.

Source

pub fn compute_forwarding_probability(&self, visible_peer_count: usize) -> f32

Computes the forwarding probability based on visible peer count.

Uses the formula: min(1.0, max(min_probability, target_fanout / peer_count)) This ensures constant expected message overhead regardless of network size.

Source

pub fn select_paths_with_gossip( &self, message: &Message, neighbors: &[NeighborInfo], total_visible_peers: usize, ) -> ForwardingDecision

Selects the best path(s) for message delivery with gossip-based filtering.

§Arguments
  • message - The message to route
  • neighbors - Available neighboring devices
  • total_visible_peers - Total number of peers visible in the network (may be larger than neighbors if some peers are not connected)
§Returns

Returns a forwarding decision with selected peers and metadata.

Source

pub fn select_paths( &self, message: &Message, neighbors: &[NeighborInfo], ) -> Vec<String>

Selects the best path(s) for message delivery.

§Arguments
  • message - The message to route
  • neighbors - Available neighboring devices
§Returns

Returns a list of neighbors to forward the message to, ordered by preference.

Note: This method does not apply gossip filtering. Use select_paths_with_gossip for scalable routing in large networks.

Source

pub fn select_best_path( &self, message: &Message, neighbors: &[NeighborInfo], ) -> Option<String>

Finds the best single path (for unicast).

Source

pub fn should_route_around_congestion(&self, neighbor: &NeighborInfo) -> bool

Checks if routing around congestion is needed.

Source

pub fn config(&self) -> &PathConfig

Gets the path configuration.

Source

pub fn learn_route_from_message( &mut self, message: &Message, from_neighbor: &str, quality: f32, )

Learns a route from an incoming message. Call this when receiving a message from a neighbor to learn that the neighbor can reach the message’s sender.

Source

pub fn get_route_to(&self, destination: &str) -> Option<&RouteEntry>

Gets the best route to a destination, if known.

Source

pub fn has_route_to(&self, destination: &str) -> bool

Checks if we have a known route to a destination.

Source

pub fn select_directed_path( &self, message: &Message, neighbors: &[NeighborInfo], ) -> Option<String>

Selects the best path for a message using gradient routing when available. Falls back to flooding if no route is known.

Source

pub fn remove_neighbor_routes(&mut self, neighbor: &str)

Removes a neighbor from the routing table (e.g., on disconnect).

Source

pub fn cleanup_routes(&mut self)

Cleans up expired routes.

Source

pub fn routing_stats(&self) -> (usize, usize)

Returns routing table statistics.

Source

pub fn routing_table_mut(&mut self) -> &mut GradientRoutingTable

Gets a mutable reference to the routing table for advanced operations.

Trait Implementations§

Source§

impl Default for PathSelector

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more