Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/earthstar/src/syncer/sync_agent.ts>SyncAgent

Earthstar is a tool for private, undiscoverable, offline-first networks.
Go to Latest
class SyncAgent
import { SyncAgent } from "https://deno.land/x/earthstar@v10.0.0-alpha.2/src/syncer/sync_agent.ts";

Mediates synchronisation on behalf of a Replica. Tells other SyncAgents what the Replica posseses, what it wants from them, and fulfils requests from other SyncAgents.

Constructors

new
SyncAgent(unnamed 0: SyncAgentOpts<F>)

Properties

private
fulfilledCount: number

An integer representing the number of requests were fulfilled. Quicker than calculating this every time from the fulfilledMap.

private
fulfilledMap: Map<string, boolean>

A map of all the HAVE ids we've WANTed and whether we received them or not.

private
initialHash

A promise of a hash of all documents we hold once existing documents have been processed.

private
isDoneMultiDeferred: MultiDeferred<void>

A multi deferred describing if th the SyncAgent has finished or not.

private
isFulfilled
private
isPartnerFulfilled

A promise for whether our partner SyncAgent has signalled its DONE or not.

private
outboundEventBus: BlockingBus<SyncAgentEvent | { kind: "CMD_FINISHED"; }>

A bus to send events to, and which our readable streams subcribe to.

private
rootIdsRequested: Set<string>

Here we keep track of all the root IDs of versions we've WANTed. Used to prevent offering things to another peer which they already have.

private
statusBus: BlockingBus<SyncAgentStatus>

A bus we can update the SyncAgent's status from, and which others can subscribe to.

gotAllPartnerHaves

A promise for when we have received all HAVEs our partner has on offer

A readable stream of outbound events intended for a SyncAgent partner.

replica: Replica

A writable stream which takes incoming messages from another SyncAgent.

Methods

private
fulfilWant(versionId: string)

Note down that a WANT was fulfilled by the other side.

private
registerWant(versionId: string)

Note down a HAVE ID we WANTed

cancel(reason?: string)

Signal the SyncAgent to wrap up syncing early.

The current status of this SyncAgent

onStatusUpdate(callback: (status: SyncAgentStatus) => void)

Subscribe to status updates with a callback.