Skip to main content

DaemonHost

Struct DaemonHost 

Source
pub struct DaemonHost { /* private fields */ }
Expand description

Runtime wrapper for a MeshDaemon.

Manages the daemon’s causal chain, observed horizon, and snapshot lifecycle. Each DaemonHost has its own EntityKeypair — its identity in the mesh.

Implementations§

Source§

impl DaemonHost

Source

pub fn new( daemon: Box<dyn MeshDaemon>, keypair: EntityKeypair, config: DaemonHostConfig, ) -> Self

Create a new host with a genesis chain.

Source

pub fn from_fork( daemon: Box<dyn MeshDaemon>, keypair: EntityKeypair, chain: CausalChainBuilder, config: DaemonHostConfig, ) -> Result<Self, DaemonError>

Create a host from a fork.

Uses a pre-built CausalChainBuilder from fork_entity() whose genesis link carries the fork sentinel as parent_hash. The daemon starts fresh (no state to restore) but its chain documents lineage.

Validates that the chain’s origin_hash matches the keypair to prevent identity/chain mismatches.

Source

pub fn from_snapshot( daemon: Box<dyn MeshDaemon>, keypair: EntityKeypair, snapshot: &StateSnapshot, config: DaemonHostConfig, ) -> Result<Self, DaemonError>

Restore from an L4 StateSnapshot.

Rebuilds the causal chain from the snapshot’s head link and calls daemon.restore() with the serialized state. Any subscriptions encoded in snapshot.bindings_bytes are parsed into the host’s ledger so the migration-target replay path can re-subscribe the daemon on the target node before cutover fires. A malformed bindings_bytes payload aborts the restore — attacker-controlled data must not slip past into the daemon’s operational state.

Source

pub fn deliver( &mut self, event: &CausalEvent, ) -> Result<Vec<CausalEvent>, DaemonError>

Deliver an inbound causal event to the daemon.

Updates the observed horizon, calls daemon.process(), and wraps any outputs in CausalLinks via the chain builder.

Returns the wrapped output events (ready to send on the mesh).

Source

pub fn take_snapshot(&self) -> Option<StateSnapshot>

Take a snapshot of the daemon’s current state.

Returns None if the daemon is stateless (snapshot() returns None). The returned snapshot carries a frozen view of the subscription ledger in its bindings_bytes field so the migration target can replay subscriptions during Restore. An empty ledger serializes to an empty byte slice — no wire overhead for daemons that never subscribed.

Source

pub fn restore_from_snapshot( &mut self, snapshot: &StateSnapshot, ) -> Result<(), DaemonError>

Restore this host’s daemon state and chain head from a snapshot taken on another daemon (typically the active in a standby group). Unlike from_snapshot, this mutates an existing host in place — the keypair stays put, only the daemon-state bytes and chain head are updated.

Used by StandbyGroup::sync_standbys to actually copy state from the active onto each standby; previously sync only updated bookkeeping and standbys stayed in their initial default-constructed state, so a promoted standby lost everything that had happened before the most recent sync.

Source

pub fn record_subscription( &self, publisher: u64, channel: ChannelName, token_bytes: Option<Vec<u8>>, )

Record a subscription in the daemon’s ledger.

Called by the SDK’s DaemonRuntime::subscribe_channel path after the membership-subscribe Ack returns successfully. The ledger is the authoritative view of what the daemon has subscribed to; migration reads from here, not from the mesh’s per-node subscriber roster.

Re-recording the same (publisher, channel) pair replaces the token (tokens refresh), but keeps the subscription single-entry — no duplicates in the ledger.

Source

pub fn forget_subscription(&self, publisher: u64, channel: &ChannelName)

Drop a subscription from the ledger. Idempotent.

Source

pub fn subscription_count(&self) -> usize

Number of subscriptions in the ledger.

Source

pub fn bindings_snapshot(&self) -> DaemonBindings

Snapshot of the subscription ledger — a cloned view for migration / diagnostic readers. Order is insertion-ish but DashMap doesn’t guarantee stable iteration, so the target replay path treats the list as a set.

Source

pub fn entity_id(&self) -> &EntityId

Get the daemon’s entity ID.

Source

pub fn origin_hash(&self) -> u64

Get the daemon’s origin hash.

Source

pub fn keypair(&self) -> &EntityKeypair

Read-only access to the daemon’s keypair.

Migration uses this to seal the daemon’s ed25519 seed into an IdentityEnvelope before shipping the snapshot. The keypair may be public-only (see EntityKeypair::is_read_only) — sealing a public-only keypair is a logic error handled by IdentityEnvelope::new, not here.

Source

pub fn requirements(&self) -> CapabilityFilter

Get the daemon’s capability requirements.

Source

pub fn name(&self) -> &str

Get the daemon’s name.

Source

pub fn sequence(&self) -> u64

Get the current chain sequence number.

Get the current causal-chain head link.

Returns the link of the most-recently-applied event: (origin_hash, horizon_encoded, sequence, parent_hash). The parent_hash is the forward hash of the event at sequence - 1, i.e. the cryptographic anchor that continuity proofs verify against.

Used by the migration orchestrator’s on_replay_complete to stamp the real parent_hash into the superposition’s target_head instead of a synthetic 0. A synthetic parent_hash: 0 produces a ContinuityProof that no downstream verifier holding the real chain can ever reconcile.

Source

pub fn stats(&self) -> &DaemonStats

Get runtime statistics.

Source

pub fn config(&self) -> &DaemonHostConfig

Get the daemon host configuration.

Trait Implementations§

Source§

impl Debug for DaemonHost

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more