Skip to main content

TransportSelector

Struct TransportSelector 

Source
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

Source

pub fn new() -> Self

Creates a new transport selector with default configuration.

Source

pub fn with_config(config: DorsConfig) -> Self

Creates a new transport selector with custom configuration.

Source

pub fn select_transport( &mut self, message: &Message, available_transports: &HashMap<TransportType, TransportMetrics>, ) -> Option<TransportType>

Selects the best transport for sending a message.

§Arguments
  • message - The message to send
  • available_transports - Available transport types and their metrics
§Returns

Returns the recommended transport type.

Source

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.

Source

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.

Source

pub fn record_retry_failure(&mut self, transport_type: TransportType)

Records a retry failure for a transport. Uses saturating addition to prevent overflow.

Source

pub fn reset_retry_count(&mut self, transport_type: TransportType)

Resets retry count for a transport (e.g., after successful delivery).

Source

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.

Source

pub fn should_escalate_to_wifi(&self) -> bool

Checks if escalation from BLE to Wi-Fi Direct is needed.

Source

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.

Source

pub fn update_config(&mut self, config: DorsConfig)

Replaces the configuration while preserving accumulated state (history, retry counts, signal tracking, score history).

Source

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.

Source

pub fn current_transport(&self) -> Option<TransportType>

Gets the current transport.

Source

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.

Trait Implementations§

Source§

impl Default for TransportSelector

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 = !

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

fn try_from(value: U) -> Result<T, !>

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