import { IbGib_V1 } from "@ibgib/ts-gib/dist/V1/types.mjs"; import { IbGibSpaceAny } from "../witness/space/space-base-v1.mjs"; import { MetaspaceService } from "../witness/space/metaspace/metaspace-types.mjs"; import { SyncConflictStrategy } from "./sync-constants.mjs"; import { GraftPreference } from "./graft-info/graft-info-types.mjs"; import { SyncData_V1, SyncIbGib_V1, SyncMode, SyncSenderIdentityInfo, SnapshotSyncManifest, SyncDomainAdapter } from "./sync-types.mjs"; import { SyncSagaInfo } from "./sync-types.mjs"; import { SyncPeerWitness } from "./sync-peer/sync-peer-types.mjs"; import { SyncSagaContextIbGib_V1 } from "./sync-saga-context/sync-saga-context-types.mjs"; import { KeystonePoolConfig } from "../keystone/keystone-types.mjs"; import { SyncPeer_V1 } from "./sync-peer/sync-peer-v1.mjs"; /** * Orchestrates the synchronization process between two spaces (Source and Destination). * * ## Execution Contexts * * The methods in this class are designed to be run on specific nodes in the sync topology: * * * **Sender/Local Node**: The node *initiating* the sync (calling `sync()`). * * **Receiver/Remote Node**: The node *accepting* the sync request (the Peer). * * Note that in a peer-to-peer architecture, "Sender" and "Receiver" are roles * relative to a specific Saga, not fixed node ids. */ export declare class SyncSagaCoordinator { private lc; private currentAccelerationHint?; private currentAdapter?; latestSagaFrame?: SyncIbGib_V1; constructor(); /** * Default pool config for the session keystone's `connect` pool. * Consumed exactly once per saga during `peer.connect()`. * Uses `deleteAll` replenish strategy — after the handshake, the pool is gone. * * Override in subclasses or pass custom config via opts to change security parameters. */ protected defaultSessionConnectPoolConfig(): KeystonePoolConfig; /** * Default pool config for the session keystone's per-turn `sync` pool. * Used on each outgoing context frame (Init, Delta, Commit). * Uses `topUp` replenish strategy to stay active throughout the saga. * * Override in subclasses or pass custom config via opts to change security parameters. */ protected defaultSessionSyncPoolConfig(): KeystonePoolConfig; /** * Executes a synchronization saga using the Symmetric Sync Protocol. * * @remarks * **Execution Context**: **Sender (Local)**. * This method is the entry point for starting a sync saga. */ sync({ peer, domainIbGibs, domainAddrs, mode, senderIdentityInfo, fnSenderSecret, conflictStrategy, graftPreference, metaspace, controlSpace, domainSpace, targetSpaceInfo, useInMemoryTempSpace, accelerationHint, adapter, }: { /** * The peer we are syncing with. */ peer: SyncPeerWitness; /** * The primary ibgibs we wish to sync. The dependency ibgibs will be * automatically included as needed for sync. * * These should all exist in {@link domainSpace} */ domainIbGibs?: IbGib_V1[]; domainAddrs?: string[]; mode?: SyncMode; /** * Optional structure containing both the sender's delegate identity (Alice's device key) * and the parent root Domain Identity address (senderDomainAddr). * * NOTE: {@link fnSenderSecret} must be truthy if this is truthy, and vice versa. */ senderIdentityInfo?: SyncSenderIdentityInfo; /** * secret corresponding to {@link senderIdentityInfo.senderIdentity}. * * NOTE: {@link senderIdentityInfo} must be truthy if this is truthy, and vice versa. */ fnSenderSecret?: () => Promise; /** * Durable control space containing sync saga control/audit stones (`SyncIbGib_V1`, * `SyncSagaMessageIbGib_V1`, `SyncSagaContextIbGib_V1`) and identity/session * keystones ($I_{primary}$, $I_{sync}$, $S$). */ controlSpace: IbGibSpaceAny; /** * Durable domain space containing the {@link domainIbGibs} we want to sync. If * sync is successful, any updates to domain timelines will be stored here. */ domainSpace: IbGibSpaceAny; /** * The metaspace context (for registering sync sagas locally). */ metaspace: MetaspaceService; /** * How to handle conflicts when both Source and Dest have diverged on the * same timeline. * * defaults to {@link SyncConflictStrategy.abort} */ conflictStrategy?: SyncConflictStrategy; /** * General endpoint preference for resolving graft conflicts (receiver, sender, or timestamp). */ graftPreference?: GraftPreference; /** * Optional destination space coordinates / transport info captured * on the root frame for permanent audit logging. */ targetSpaceInfo?: SyncData_V1['targetSpaceInfo']; /** * Whether to use an in-memory scratch space for staging sync payload ibgibs. * Defaults to true for maximal speed. If false and metaspace is available, * creates a disk-backed local space. */ useInMemoryTempSpace?: boolean; /** * Optional intermediate snapshot sync manifest to accelerate gap analysis * during VCS branch synchronization. */ accelerationHint?: SnapshotSyncManifest; /** * Optional domain adapter (e.g. B2tFSSnapshotSyncAdapter) to accelerate * domain analysis and fast-forward delta payload calculations. */ adapter?: SyncDomainAdapter; }): Promise; /** * Executes a strictly read-only clone / pull operation against a remote target domain. * * Invariants guaranteed: * 1. Zero writes to the target domain's space (Alice's space). * 2. Complete DoS isolation: SyncSaga audit logs are written exclusively to caller's controlSpace (Bob's local space). * 3. Target snapshot address is pinned at start. */ cloneReadOnly({ peer, targetAddrs, controlSpace, domainSpace, metaspace, senderIdentityInfo, fnSenderSecret, useInMemoryTempSpace, }: { peer: SyncPeerWitness; targetAddrs: string[]; controlSpace: IbGibSpaceAny; domainSpace: IbGibSpaceAny; metaspace: MetaspaceService; senderIdentityInfo?: SyncSenderIdentityInfo; fnSenderSecret?: () => Promise; useInMemoryTempSpace?: boolean; }): Promise; /** * This is what the receiving side of the sync calls to drive the FSM to the * next stage. * * So whereas the sender executes a saga loop and drives the entire process, * this is a reactive one-off that drives just the single step that the * receiver does in that saga. * * @returns next context result if another round, else if commit returns * null */ continueSync({ sagaContext, controlSpace, domainSpace, myTempSpace, metaspace, peer, }: { sagaContext: SyncSagaContextIbGib_V1; /** * Durable control space relative to the execution context's POV */ controlSpace: IbGibSpaceAny; /** * Durable domain space relative to the execution context's POV */ domainSpace: IbGibSpaceAny; /** * Local temp space relative to the execution context's POV */ myTempSpace: IbGibSpaceAny; metaspace: MetaspaceService; /** * the peer that is continuing the sync */ peer: SyncPeer_V1; }): Promise; /** * Drives the FSM loop of the Saga. * * @remarks * **Execution Context**: **Sender (Local)**. * * This method manages the "Ping Pong" request-response cycle on the Sender. * It sends frames via the Peer Witness and processes the responses using `handleSagaResponseContext`. * * **Data Transport Note**: * Actual ibGib data (payloads) are transported via `SyncSagaContext.rel8ns.payload`. * When `handleSagaResponseContext` returns a `nextPayloadIbGibs` (data to send), this loop injects it into * the NEXT request context. * When the Peer responds with data (in the response context), it is resolved and put into `tempSpace`. */ private executeSagaLoop; /** * Creates new SyncSagaContext stone. Puts/registers in {@link controlSpace} * immediately after creation. * * @returns The context ibGib. * * ## notes * * the other ibgibs that are related to this context stone should already be * put/registered in {@link controlSpace}. */ private createSyncSagaContext; /** * Helper to get Knowledge Map for specific domain ibGibs or TJPs. * Useful for testing and external validation. */ getKnowledgeMap({ space, metaspace, domainIbGibs, tjpAddrs, }: { space: IbGibSpaceAny; metaspace: MetaspaceService; domainIbGibs?: IbGib_V1[]; tjpAddrs?: string[]; }): Promise<{ [tjp: string]: string | null; }>; private analyzeDomainIbGibs; /** * Creates the Initial Saga Frame (Init Stage). * * @remarks * **Execution Context**: **Sender (Local)**. * * Generates the first frame containing the Knowledge Map of the Domain Space. * This is sent to the Receiver to begin Gap Analysis. */ private createInitFrame; /** * Validates that the return context received from a peer is a valid * continuation of the outbound context and that the session identity * is consistent. */ private validateReturnContext; /** * Helper to poll for streaming domain payloads and put them in the * local {@link tempSpace}. * * @returns when all {@link expectedAddrs} are done being transmitted. */ private pollForDomainPayloads; /** * This is the heart of the "ping pong" transaction, where we send a context * * and receive a context. IOW, this drives the FSM of the sync saga ibgib as * a whole. * * This is called in two places: * * ## 1. Sender * * On the sender, this is called repeatedly within the the sync saga * coordinator's {@link executeSagaLoop} which initiates and drives the * overall sync process. This loop continues until there are no more frames * to be exchanged between endpoints. * * ## 2. Receiver * * On the receiver, this is called directly from {@link continueSync}, which * itself is called either directly by the concrete sync peer or from within * the receiving node endpoint. That endpoint's job is basically to get * these things collocated and prepared to make this call. * * In contrast to the sender, this can be thought of as a one-off on the * receiver, since the sender's {@link executeSagaLoop} is what actually * drives the ping-pong process. */ private handleResponseSagaContext; /** * Handles the `Init` frame. * * @remarks * **Execution Context**: **Receiver (Remote)**. * * The Receiver performs Gap Analysis here: * 1. Compares Sender's Knowledge Map (in `sagaIbGib`) vs Receiver's Local Knowledge Map. * 2. Identifies what Sender needs (`pushOfferAddrs`). * 3. Identifies what Receiver needs (`deltaRequestAddrInfos`). * 4. Returns an `Ack` frame containing these lists. */ private handleInitFrame; /** * Handles the `Ack` frame. * * @remarks * **Execution Context**: **Sender (Local)**. * * The Sender reacts to the Receiver's requirements: * 1. `deltaRequestAddrInfos`: Receiver wants this data. Sender takes this * into account, plus gathers it from `initDomainGraph` and puts them in * `payloadIbGibs` (for next frame). * 2. `pushOfferAddrs`: Receiver has newer data. these should have been * included in the incoming context from the receiver.. * * Returns a `Delta` frame. */ private handleAckFrame; /** * Handles the `Delta` frame. * * @remarks * **Execution Context**: **Both** ?? * * At this time, I only conceive this as being executed by the receiver. * Initially, I was thinking that it would need to be a back and forth, * especially since we were going to resolve one conflict at a time. That * may still end up being the case, but right now (01/27/2026), I'm thinking * we just have the receiver do the merging, since they should have full * knowledge at that point for most (all?) cases AFAICT. */ private handleDeltaFrame; /** * should throw if fails */ private executeLocalCommit; private createCommitFrame; private handleCommitFrame; private createSyncMsgStone; private getPayloadsForRequestedInfos; /** * Evolves the saga timeline with a new frame in controlSpace. */ private evolveSyncSagaIbGib; private getStageAndPayloadFromFrame; private sortTimelinesTopologically; } //# sourceMappingURL=sync-saga-coordinator.d.mts.map