pub struct TransportSelector { /* private fields */ }Expand description
Transport selector for DORS.
This struct implements the intelligent transport selection algorithm that chooses between Internet, BLE, and Wi-Fi Direct based on network conditions.
Implementations§
Source§impl TransportSelector
impl TransportSelector
Sourcepub fn with_config(config: DorsConfig) -> Self
pub fn with_config(config: DorsConfig) -> Self
Creates a new transport selector with custom configuration.
Sourcepub fn select_transport(
&mut self,
message: &Message,
available_transports: &HashMap<TransportType, TransportMetrics>,
) -> Option<TransportType>
pub fn select_transport( &mut self, message: &Message, available_transports: &HashMap<TransportType, TransportMetrics>, ) -> Option<TransportType>
Sourcepub fn score_and_rank(
&self,
message: &Message,
available_transports: &HashMap<TransportType, TransportMetrics>,
) -> Vec<(TransportType, f32)>
pub fn score_and_rank( &self, message: &Message, available_transports: &HashMap<TransportType, TransportMetrics>, ) -> Vec<(TransportType, f32)>
Scores all available transports and returns them ranked by score (descending).
Unlike select_transport, this is read-only: it does not record metrics,
update history, or mutate selector state. It is used by
TransportManager::send() to build a fallback list when the primary
transport’s send fails — at that point select_transport has already
recorded the state for this scoring cycle.
Important: This method reads transport_history for reliability and
load scores but does not update it. If called independently of a prior
select_transport in the same cycle, the scores may reflect stale
history. Always call select_transport first in any given scoring
cycle.
Sourcepub fn score_and_rank_detailed(
&self,
message: &Message,
available_transports: &HashMap<TransportType, TransportMetrics>,
) -> Vec<(TransportType, TransportScore)>
pub fn score_and_rank_detailed( &self, message: &Message, available_transports: &HashMap<TransportType, TransportMetrics>, ) -> Vec<(TransportType, TransportScore)>
Diagnostic variant of Self::score_and_rank that returns the full
seven-factor TransportScore per transport rather than just the
total. Used by telemetry consumers that opted into routing_diagnostic.
Sorted descending by total; ties resolve via the same priority
(Internet > WiFiDirect > BLE) used by selection. Identical read-only
guarantees as score_and_rank.
Sourcepub fn record_retry_failure(&mut self, transport_type: TransportType)
pub fn record_retry_failure(&mut self, transport_type: TransportType)
Records a retry failure for a transport. Uses saturating addition to prevent overflow.
Sourcepub fn reset_retry_count(&mut self, transport_type: TransportType)
pub fn reset_retry_count(&mut self, transport_type: TransportType)
Resets retry count for a transport (e.g., after successful delivery).
Sourcepub fn escalation_trigger_reason(&self) -> Option<EscalationTriggerReason>
pub fn escalation_trigger_reason(&self) -> Option<EscalationTriggerReason>
Returns which condition triggered escalation, if any.
Returns None when battery is too low (escalation suppressed) or
when no escalation condition is active.
Sourcepub fn should_escalate_to_wifi(&self) -> bool
pub fn should_escalate_to_wifi(&self) -> bool
Checks if escalation from BLE to Wi-Fi Direct is needed.
Sourcepub fn should_escalate_to_wifi_for_priority(
&self,
priority: MessagePriority,
) -> bool
pub fn should_escalate_to_wifi_for_priority( &self, priority: MessagePriority, ) -> bool
Checks if WiFi escalation is appropriate for a message with given priority.
For Critical priority messages, battery constraints are bypassed since message delivery is more important than battery preservation.
Sourcepub fn update_config(&mut self, config: DorsConfig)
pub fn update_config(&mut self, config: DorsConfig)
Replaces the configuration while preserving accumulated state (history, retry counts, signal tracking, score history).
Sourcepub fn config(&self) -> &DorsConfig
pub fn config(&self) -> &DorsConfig
Returns the configuration scoring actually runs against.
This selector — not ProtocolConfig::dors, which is read once at
construction — is the live consumer, so this is the honest place to
confirm a runtime update landed.
Sourcepub fn current_transport(&self) -> Option<TransportType>
pub fn current_transport(&self) -> Option<TransportType>
Gets the current transport.
Sourcepub fn set_current_transport(&mut self, transport: TransportType)
pub fn set_current_transport(&mut self, transport: TransportType)
Updates the current transport tracked by the selector.
Used by TransportManager when a fallback transport succeeds so that
subsequent select_transport calls apply hysteresis against the
transport that actually carried the last message. Also resets the
switch cooldown timer so the next selection uses a full cooldown
window measured from this fallback, not from the original primary
selection.
The caller is responsible for ensuring transport is currently
available. Setting a transport that has since become unavailable is
safe — select_transport handles the !current_still_available
case — but may cause one wasted hysteresis evaluation.