Strategy

Trait Strategy 

Source
pub trait Strategy:
    Send
    + Sync
    + 'static {
    // Required methods
    fn name(&self) -> &Name;
    fn after_receive_interest(
        &self,
        ctx: &StrategyContext<'_>,
    ) -> impl Future<Output = SmallVec<[ForwardingAction; 2]>> + Send;
    fn after_receive_data(
        &self,
        ctx: &StrategyContext<'_>,
    ) -> impl Future<Output = SmallVec<[ForwardingAction; 2]>> + Send;

    // Provided methods
    fn decide(
        &self,
        _ctx: &StrategyContext<'_>,
    ) -> Option<SmallVec<[ForwardingAction; 2]>> { ... }
    fn on_interest_timeout(
        &self,
        _ctx: &StrategyContext<'_>,
    ) -> impl Future<Output = ForwardingAction> + Send { ... }
    fn on_nack(
        &self,
        _ctx: &StrategyContext<'_>,
        _reason: NackReason,
    ) -> impl Future<Output = ForwardingAction> + Send { ... }
}
Expand description

The forwarding strategy trait.

A strategy is a pure decision function — it reads state through StrategyContext but cannot modify forwarding tables directly. Autonomous behaviour (probing, discovery) is done via the Probe channel on StrategyContext.

Required Methods§

Source

fn name(&self) -> &Name

Canonical name identifying this strategy.

Source

fn after_receive_interest( &self, ctx: &StrategyContext<'_>, ) -> impl Future<Output = SmallVec<[ForwardingAction; 2]>> + Send

Called when an Interest arrives and needs a forwarding decision.

Source

fn after_receive_data( &self, ctx: &StrategyContext<'_>, ) -> impl Future<Output = SmallVec<[ForwardingAction; 2]>> + Send

Called when Data arrives and needs to be forwarded to consumers.

Provided Methods§

Source

fn decide( &self, _ctx: &StrategyContext<'_>, ) -> Option<SmallVec<[ForwardingAction; 2]>>

Synchronous fast path for forwarding decisions.

Strategies whose after_receive_interest is fully synchronous should override this to return Some(actions), avoiding the Box::pin heap allocation in the ErasedStrategy wrapper.

Returns None (default) to fall through to the async path.

Source

fn on_interest_timeout( &self, _ctx: &StrategyContext<'_>, ) -> impl Future<Output = ForwardingAction> + Send

Called when a PIT entry times out. Default: suppress (let the entry die).

Source

fn on_nack( &self, _ctx: &StrategyContext<'_>, _reason: NackReason, ) -> impl Future<Output = ForwardingAction> + Send

Called when a Nack arrives on an out-record face.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§