use super::codec::decode_event;
use super::codec::OnionCircuitInput;
use super::ONION_CIRCUIT_NAMESPACE;
use crate::extension::ext::Ctx;
use crate::extension::ext::LinkFact;
use crate::extension::ext::Protocol;
use crate::extension::ext::Reject;
use crate::extension::ext::Transition;
use crate::extension::ext::Wire;
#[derive(Clone, Copy, Debug, Default)]
pub(crate) struct OnionCircuitProtocol;
impl Protocol for OnionCircuitProtocol {
type State = ();
type Event = OnionCircuitInput;
type Effect = OnionCircuitInput;
fn namespace(&self) -> &str {
ONION_CIRCUIT_NAMESPACE
}
fn init(&self) -> Self::State {}
fn decode(&self, wire: Wire<'_>) -> std::result::Result<Self::Event, Reject> {
decode_event(wire)
}
fn step(
&self,
_ctx: Ctx<'_, Self::State>,
event: Self::Event,
) -> Transition<Self::State, Self::Effect> {
Transition::with((), vec![event])
}
fn delegates_admission(&self) -> bool {
true
}
fn delegates_replay(&self) -> bool {
true
}
fn link_fact(&self, fact: LinkFact) -> Option<Self::Event> {
Some(OnionCircuitInput::Link(fact.into()))
}
}