Docs

sync

Source: crates/lvcs-net/src/sync/mod.rs.

/// The sync actor's events, generated by its sml table: its mailbox and
/// journal type (decision 286). Time enters only as event data. Owner:
/// `M3.sync`.
///
/// Its events, each the payload type its variant is named for: [`PeerOpened`],
/// [`PeerClosed`], [`DocKnown`], [`DocOutgoing`], [`DocSettled`], [`FrameIn`],
/// [`DocRejected`].
pub use machine::{
    DocKnown, DocOutgoing, DocRejected, DocSettled, FrameIn, PeerClosed, PeerOpened, SyncingEvents,
};

/// Outputs of the sync actor, which the daemon shell carries out.
/// Owner: `M3.sync`.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SyncOutput {
    /// Seal `frame` in an envelope of kind `sync` signed by this device's
    /// key and write it to the sync stream with `peer`
    /// (`TransportCommand::SyncFrame`).
    Send {
        /// The peer to send to.
        peer: Peer,
        /// The frame to seal and send.
        frame: SyncFrame,
    },
    /// Seal an `inventory` envelope ([`crate::wire::SyncInventory`]) counting `docs`,
    /// signed by this device's key, and write it to the sync stream with
    /// `peer`: sent each time the peer's caps round settles, after the
    /// round's held messages and joins, with every document then joined
    /// with the peer, `.lvcs/caps` among them.
    Inventory {
        /// The peer to send to.
        peer: Peer,
        /// How many documents sync with it.
        docs: u64,
    },
    /// `peer` sent its `inventory`: it syncs `docs` documents with this
    /// daemon (`lvcs join` waits for them), its daemon holds `holders`,
    /// whose signatures the shell checks, and it is named `host`
    /// (decision 314).
    Inventoried {
        /// The peer that sent it.
        peer: Peer,
        /// How many documents it syncs with this daemon.
        docs: u64,
        /// The participant keys its daemon holds, each signed.
        holders: Vec<crate::wire::Holder>,
        /// Its machine name.
        host: Option<String>,
    },
    /// Hand a received payload to the document at `doc`, spawning its actor
    /// if it isn't running (`DocEvent::SyncIn`, carrying `tag`). The shell
    /// refuses one whose address the path filter excludes (never-sync,
    /// decision 81) or that collides with an existing directory, before
    /// spawning any document (decision 110), and spawns no document for one
    /// while it holds `PROJECT_MAX_DOCUMENTS` documents, dropping it without
    /// penalty (decision 112).
    Deliver {
        /// The document's address.
        doc: String,
        /// The peer the payload came from.
        peer: Peer,
        /// The sync message, opaque here.
        payload: Vec<u8>,
        /// The input's tag.
        tag: u64,
    },
    /// Start syncing `doc` with `peer` (`DocEvent::PeerJoined`, carrying
    /// `tag`). Every `Join` and `Deliver` takes the next value of a counter
    /// rising through the daemon run (decision 110); tags are never
    /// telemetry values.
    Join {
        /// The document's address.
        doc: String,
        /// The peer to sync with.
        peer: Peer,
        /// The input's tag.
        tag: u64,
    },
    /// Stop syncing `doc` with `peer` (`DocEvent::PeerLeft`).
    Leave {
        /// The document's address.
        doc: String,
        /// The peer to stop syncing with.
        peer: Peer,
    },
    /// Close the stream and every connection to `peer` and lower its score
    /// (`TransportCommand::Disconnect` and `Penalize`): a faulty frame, a
    /// document's rejection, or `over_limit` (decisions 111 and 112).
    Disconnect {
        /// The faulty peer.
        peer: Peer,
        /// Why it is disconnected.
        reason: Rejection,
    },
}