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§
Sourcetype Event: MaybeSendSync
type Event: MaybeSendSync
The protocol’s typed input, produced by decode.
Required Methods§
Provided Methods§
Sourcefn delegates_admission(&self) -> bool
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.
Sourcefn delegates_replay(&self) -> bool
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.
Sourcefn link_fact(&self, _fact: LinkFact) -> Option<Self::Event>
fn link_fact(&self, _fact: LinkFact) -> Option<Self::Event>
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".