Skip to main content

Protocol

Trait Protocol 

Source
pub trait Protocol {
    type State;
    type Event: MaybeSendSync;
    type Effect;

    // Required methods
    fn namespace(&self) -> &str;
    fn init(&self) -> Self::State;
    fn decode(&self, wire: Wire<'_>) -> Result<Self::Event, Reject>;
    fn step(
        &self,
        ctx: Ctx<'_, Self::State>,
        event: Self::Event,
    ) -> Transition<Self::State, Self::Effect>;

    // Provided methods
    fn delegates_admission(&self) -> bool { ... }
    fn delegates_replay(&self) -> bool { ... }
    fn link_fact(&self, _fact: LinkFact) -> Option<Self::Event> { ... }
}
Expand description

A protocol: a namespace, an initial state, a decode boundary, and a state transition that is pure by contract.

  init   :              → S
  decode : Wire        ⇀ Event            (partial: may Reject)
  step   : (Ctx S, Event) → Transition (S, Effect)

decode is the single place raw bytes become a typed Event; a malformed/foreign message is an explicit Reject, not a silent no-op in step. step is then total over well-typed events and pure: no IO, no clocks, no globals. All side effects are described as values of the protocol’s own Effect type and performed by the extension’s Interpret shell.

Required Associated Types§

Source

type State

Protocol-private state, owned by the runtime and threaded through step.

Source

type Event: MaybeSendSync

The protocol’s typed input, produced by decode.

Source

type Effect

The protocol’s own effect algebra (the core defines no global effect enum).

Required Methods§

Source

fn namespace(&self) -> &str

The namespace this protocol is registered and routed under.

Source

fn init(&self) -> Self::State

Initial state. init : 1 → S.

Source

fn decode(&self, wire: Wire<'_>) -> Result<Self::Event, Reject>

Decode the boundary into a typed event, or Reject it. decode : Wire ⇀ Event.

Source

fn step( &self, ctx: Ctx<'_, Self::State>, event: Self::Event, ) -> Transition<Self::State, Self::Effect>

Pure transition. step : (Ctx S, Event) → Transition (S, Effect).

Provided Methods§

Source

fn delegates_admission(&self) -> bool

Whether this protocol delegates its admission: it admits its own direct-edge traffic, per sending neighbour, before its own processing and after core’s admission (#888).

Read once when the protocol is registered. For this namespace’s traffic from the authenticated neighbour that originated it, core then skips the per-origin message-count limit; the per-origin byte bucket and the record bound still apply, and relayed or foreign-origin traffic keeps the enforced limits. false, the default, delegates nothing.

Delegation is trusted local configuration: a protocol that returns true must enforce its own per-neighbour admission.

Source

fn delegates_replay(&self) -> bool

Whether this protocol delegates its replay (#1081): it acts on each of its payloads at most once, by its own replay key, across connections, link generations, envelopes and restarts of this node (Obligation R of durable-records).

Read once when the protocol is registered. For this namespace’s traffic from the authenticated neighbour that originated it, core then admits each transaction in a volatile replay window of the link it arrived on, instead of its durable window, and writes nothing; relayed or foreign-origin traffic keeps the durable window. false, the default, delegates nothing.

Delegation is trusted local configuration: a protocol that returns true must keep R.

The event this protocol makes of fact about a link, or None when the protocol keeps no state about links. link_fact : LinkFact ⇀ Event.

A fact reaches the protocol in its namespace’s queue, in order with the envelopes around it, and is never dropped (#963, #966).

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§