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
impl DaemonHost
Sourcepub fn new(
daemon: Box<dyn MeshDaemon>,
keypair: EntityKeypair,
config: DaemonHostConfig,
) -> Self
pub fn new( daemon: Box<dyn MeshDaemon>, keypair: EntityKeypair, config: DaemonHostConfig, ) -> Self
Create a new host with a genesis chain.
Sourcepub fn from_fork(
daemon: Box<dyn MeshDaemon>,
keypair: EntityKeypair,
chain: CausalChainBuilder,
config: DaemonHostConfig,
) -> Result<Self, DaemonError>
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.
Sourcepub fn from_snapshot(
daemon: Box<dyn MeshDaemon>,
keypair: EntityKeypair,
snapshot: &StateSnapshot,
config: DaemonHostConfig,
) -> Result<Self, DaemonError>
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.
Sourcepub fn deliver(
&mut self,
event: &CausalEvent,
) -> Result<Vec<CausalEvent>, DaemonError>
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).
Sourcepub fn take_snapshot(&self) -> Option<StateSnapshot>
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.
Sourcepub fn restore_from_snapshot(
&mut self,
snapshot: &StateSnapshot,
) -> Result<(), DaemonError>
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.
Sourcepub fn record_subscription(
&self,
publisher: u64,
channel: ChannelName,
token_bytes: Option<Vec<u8>>,
)
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.
Sourcepub fn forget_subscription(&self, publisher: u64, channel: &ChannelName)
pub fn forget_subscription(&self, publisher: u64, channel: &ChannelName)
Drop a subscription from the ledger. Idempotent.
Sourcepub fn subscription_count(&self) -> usize
pub fn subscription_count(&self) -> usize
Number of subscriptions in the ledger.
Sourcepub fn bindings_snapshot(&self) -> DaemonBindings
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.
Sourcepub fn origin_hash(&self) -> u64
pub fn origin_hash(&self) -> u64
Get the daemon’s origin hash.
Sourcepub fn keypair(&self) -> &EntityKeypair
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.
Sourcepub fn requirements(&self) -> CapabilityFilter
pub fn requirements(&self) -> CapabilityFilter
Get the daemon’s capability requirements.
Sourcepub fn head_link(&self) -> CausalLink
pub fn head_link(&self) -> CausalLink
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.
Sourcepub fn stats(&self) -> &DaemonStats
pub fn stats(&self) -> &DaemonStats
Get runtime statistics.
Sourcepub fn config(&self) -> &DaemonHostConfig
pub fn config(&self) -> &DaemonHostConfig
Get the daemon host configuration.