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§
Sourcefn capabilities(&self, below: &Capabilities) -> Result<Capabilities, LayerError>
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.
Provided Methods§
Sourcefn lanes(&mut self, above: &[LaneKey]) -> Result<Vec<LaneKey>, LayerError>
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.
Sourcefn tick(
&mut self,
now: Instant,
down: &mut Frames,
up: &mut Frames,
) -> Option<Instant>
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.
Sourcefn security(
&self,
below: Option<&SecurityProperties>,
) -> Option<SecurityProperties>
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.
Sourcefn counters(&self) -> Vec<Counter>
fn counters(&self) -> Vec<Counter>
The layer’s counters, every one scoped by this layer’s kind.
Sourcefn actions(&self) -> Vec<ActionSpec>
fn actions(&self) -> Vec<ActionSpec>
The operator actions this layer offers (#129), if any: a key rotation, for one.
Sourcefn invoke(
&mut self,
name: &str,
arguments: &BTreeMap<String, ConfigValue>,
) -> Result<ActionOutcome, ActionError>
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".