pub struct RelayManager { /* private fields */ }Expand description
Relay manager for promotion and demotion logic.
Implementations§
Source§impl RelayManager
impl RelayManager
Sourcepub fn with_config(config: RelayConfig) -> Self
pub fn with_config(config: RelayConfig) -> Self
Creates a new relay manager with custom configuration.
Sourcepub fn should_promote_to_relay(
&self,
connection_count: usize,
battery_level: u8,
is_charging: bool,
) -> bool
pub fn should_promote_to_relay( &self, connection_count: usize, battery_level: u8, is_charging: bool, ) -> bool
Sourcepub fn should_demote_from_relay(
&self,
connection_count: usize,
battery_level: u8,
is_charging: bool,
) -> bool
pub fn should_demote_from_relay( &self, connection_count: usize, battery_level: u8, is_charging: bool, ) -> bool
Sourcepub fn evaluate_transition(
&mut self,
connection_count: usize,
battery_level: u8,
is_charging: bool,
) -> Option<RelayTransition>
pub fn evaluate_transition( &mut self, connection_count: usize, battery_level: u8, is_charging: bool, ) -> Option<RelayTransition>
Evaluates whether the relay role should change and, if so, applies the change and returns the transition that occurred.
This is the single entry point that mutates RelayRole: it compares
the promote/demote decision against the current role and only returns
Some when the role actually flips, so callers can emit a role-change
event exactly once per transition. A stable role returns None.
Sourcepub fn calculate_relay_score(&self, relay: &RelayInfo) -> f32
pub fn calculate_relay_score(&self, relay: &RelayInfo) -> f32
Calculates a score for a potential relay.
Higher score = better relay candidate.
Sourcepub fn select_best_relays(
&self,
candidates: Vec<RelayInfo>,
count: usize,
max_congestion_level: f32,
) -> Vec<RelayInfo>
pub fn select_best_relays( &self, candidates: Vec<RelayInfo>, count: usize, max_congestion_level: f32, ) -> Vec<RelayInfo>
Selects the best relays from a list of candidates.
§Arguments
candidates- List of potential relayscount- Number of relays to selectmax_congestion_level- Congestion level (0.0-1.0) at or above which a candidate is considered overloaded and excluded; pass the caller’s path policy (e.g.PathConfig::max_congestion_level)
§Returns
Returns up to count relay candidates, sorted by score (best first).
Sourcepub fn current_role(&self) -> RelayRole
pub fn current_role(&self) -> RelayRole
Gets the current relay role.
Sourcepub fn config(&self) -> &RelayConfig
pub fn config(&self) -> &RelayConfig
Gets the relay configuration.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RelayManager
impl RefUnwindSafe for RelayManager
impl Send for RelayManager
impl Sync for RelayManager
impl Unpin for RelayManager
impl UnsafeUnpin for RelayManager
impl UnwindSafe for RelayManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more