pub struct PathSelector { /* private fields */ }Expand description
Path selector for optimal relay selection.
Implementations§
Source§impl PathSelector
impl PathSelector
Sourcepub fn with_config(config: PathConfig, relay_manager: RelayManager) -> Self
pub fn with_config(config: PathConfig, relay_manager: RelayManager) -> Self
Creates a new path selector with custom configuration.
Sourcepub fn set_local_device_id(&mut self, device_id: impl Into<String>)
pub fn set_local_device_id(&mut self, device_id: impl Into<String>)
Sets the local device ID for deterministic gossip decisions.
Sourcepub fn current_relay_role(&self) -> RelayRole
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).
Sourcepub fn evaluate_relay_transition(
&mut self,
connection_count: usize,
battery_level: u8,
is_charging: bool,
) -> Option<RelayTransition>
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.
Sourcepub fn compute_forwarding_probability(&self, visible_peer_count: usize) -> f32
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.
Sourcepub fn select_paths_with_gossip(
&self,
message: &Message,
neighbors: &[NeighborInfo],
total_visible_peers: usize,
) -> ForwardingDecision
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 routeneighbors- Available neighboring devicestotal_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.
Sourcepub fn select_paths(
&self,
message: &Message,
neighbors: &[NeighborInfo],
) -> Vec<String>
pub fn select_paths( &self, message: &Message, neighbors: &[NeighborInfo], ) -> Vec<String>
Selects the best path(s) for message delivery.
§Arguments
message- The message to routeneighbors- 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.
Sourcepub fn select_best_path(
&self,
message: &Message,
neighbors: &[NeighborInfo],
) -> Option<String>
pub fn select_best_path( &self, message: &Message, neighbors: &[NeighborInfo], ) -> Option<String>
Finds the best single path (for unicast).
Sourcepub fn should_route_around_congestion(&self, neighbor: &NeighborInfo) -> bool
pub fn should_route_around_congestion(&self, neighbor: &NeighborInfo) -> bool
Checks if routing around congestion is needed.
Sourcepub fn config(&self) -> &PathConfig
pub fn config(&self) -> &PathConfig
Gets the path configuration.
Sourcepub fn learn_route_from_message(
&mut self,
message: &Message,
from_neighbor: &str,
quality: f32,
)
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.
Sourcepub fn get_route_to(&self, destination: &str) -> Option<&RouteEntry>
pub fn get_route_to(&self, destination: &str) -> Option<&RouteEntry>
Gets the best route to a destination, if known.
Sourcepub fn has_route_to(&self, destination: &str) -> bool
pub fn has_route_to(&self, destination: &str) -> bool
Checks if we have a known route to a destination.
Sourcepub fn select_directed_path(
&self,
message: &Message,
neighbors: &[NeighborInfo],
) -> Option<String>
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.
Sourcepub fn remove_neighbor_routes(&mut self, neighbor: &str)
pub fn remove_neighbor_routes(&mut self, neighbor: &str)
Removes a neighbor from the routing table (e.g., on disconnect).
Sourcepub fn cleanup_routes(&mut self)
pub fn cleanup_routes(&mut self)
Cleans up expired routes.
Sourcepub fn routing_stats(&self) -> (usize, usize)
pub fn routing_stats(&self) -> (usize, usize)
Returns routing table statistics.
Sourcepub fn routing_table_mut(&mut self) -> &mut GradientRoutingTable
pub fn routing_table_mut(&mut self) -> &mut GradientRoutingTable
Gets a mutable reference to the routing table for advanced operations.