Skip to main content

Layer

Trait Layer 

Source
pub trait Layer: Send {
    // Required methods
    fn kind(&self) -> &'static str;
    fn capabilities(
        &self,
        below: &Capabilities,
    ) -> Result<Capabilities, LayerError>;
    fn encode(
        &mut self,
        lane: &LaneKey,
        sdu: Sdu,
        now: Instant,
        out: &mut Frames,
    ) -> Result<(), LayerError>;
    fn decode(
        &mut self,
        lane: &LaneKey,
        frame: Sdu,
        now: Instant,
        out: &mut Frames,
    ) -> Decoded;

    // Provided methods
    fn lanes(&mut self, above: &[LaneKey]) -> Result<Vec<LaneKey>, LayerError> { ... }
    fn tick(
        &mut self,
        now: Instant,
        down: &mut Frames,
        up: &mut Frames,
    ) -> Option<Instant> { ... }
    fn security(
        &self,
        below: Option<&SecurityProperties>,
    ) -> Option<SecurityProperties> { ... }
    fn counters(&self) -> Vec<Counter> { ... }
    fn actions(&self) -> Vec<ActionSpec> { ... }
    fn invoke(
        &mut self,
        name: &str,
        arguments: &BTreeMap<String, ConfigValue>,
    ) -> Result<ActionOutcome, ActionError> { ... }
}
Expand description

A synchronous transform over SDUs, composed by the driver’s Stack.

Every method is called under one lock and never across an .await, so a layer is a plain state machine: encode and decode are called in the order the SDUs and frames arrive, and tick whenever the Stack reaches a deadline this layer announced, and after every encode/decode pass (a tick with nothing due is a question, not an order). Time is the caller’s: a layer compares the now it is handed and never reads a clock, which is what lets a test drive it deterministically.

Required Methods§

Source

fn kind(&self) -> &'static str

The name the file and the counters use: "aead", "fragment".

Source

fn capabilities(&self, below: &Capabilities) -> Result<Capabilities, LayerError>

What this layer makes of the capabilities below it: the overhead taken off each direction, reliable as the layer’s rule says, the framing it adds or passes through. Refused when nothing would fit or the layer below cannot be layered over.

Source

fn encode( &mut self, lane: &LaneKey, sdu: Sdu, now: Instant, out: &mut Frames, ) -> Result<(), LayerError>

One SDU going down: the frames for the layer below, in order, pushed onto out.

Source

fn decode( &mut self, lane: &LaneKey, frame: Sdu, now: Instant, out: &mut Frames, ) -> Decoded

One frame coming up: the SDUs for the layer above pushed onto out, or a counted refusal.

Provided Methods§

Source

fn lanes(&mut self, above: &[LaneKey]) -> Result<Vec<LaneKey>, LayerError>

The lanes to ask of the layer below, given the lanes asked of this one. Identity for most layers; an addressing layer maps a lane per peer onto one channel. Called once, before anything moves.

Source

fn tick( &mut self, now: Instant, down: &mut Frames, up: &mut Frames, ) -> Option<Instant>

Time passing: what the layer’s timers owe downward (down, as frames for the layer below) and upward (up, as SDUs for the layer above), and when it next needs a tick. None when nothing is pending.

Source

fn security( &self, below: Option<&SecurityProperties>, ) -> Option<SecurityProperties>

What this layer guarantees about the bytes it carries, given what the layers below guarantee (I6). A layer that adds nothing passes below through.

Source

fn counters(&self) -> Vec<Counter>

The layer’s counters, every one scoped by this layer’s kind.

Source

fn actions(&self) -> Vec<ActionSpec>

The operator actions this layer offers (#129), if any: a key rotation, for one.

Source

fn invoke( &mut self, name: &str, arguments: &BTreeMap<String, ConfigValue>, ) -> Result<ActionOutcome, ActionError>

Run one of them, now. Synchronous, like everything here.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§