Skip to main content
Module

x/earthstar/deps.ts>RangeMessenger

Storage for private, distributed, offline-first applications.
Go to Latest
class RangeMessenger
Re-export
import { RangeMessenger } from "https://deno.land/x/earthstar@v10.2.0/deps.ts";

Produces and responds to messages, enabling efficient reconciliation of two sets.

Constructors

new
RangeMessenger(opts: RangeMessengerOpts<EncodedMessageType, ValueType, LiftedType>)

Type Parameters

EncodedMessageType
ValueType
LiftedType

Properties

private
collatedPayload: { lowerBound: ValueType; type: "payload"; payload: ValueType[]; end: { canRespond: boolean; upperBound: ValueType; }; } | null

A collated payload object created from many previous payload messages.

private
collatePayloads: (decoded: DecodeStageResult<ValueType, LiftedType>) => CollateStageResult<ValueType, LiftedType> | undefined
private
fingerprintEquals: (a: LiftedType, b: LiftedType) => boolean
private
insertionCallbacks: Set<(v: ValueType) => void>
private
isDoneSoFar: boolean

Indicates if we are done judging from received messages from the current round of messages.

private
isDoneTee: TeeableDeferred
private
lastAdjacentDoneUpperBound: ValueType | null

The last upper bound of a series of adjacent 'done' messages, used to consolidate multiple done messages into a single one.

private
lowerBoundFromPrev: ValueType

The lower bound of the next message, derived from the upper bound of the previous call to respond.

private
payloadThreshold: number
private
rangeDivision: number
private
reusableTree: NodeType<ValueType, LiftedType> | undefined

A tree returned by the previous call of tree.getFingeprint, to be used by the next call to .respond.

Methods

private
checkIsDone(message: ProcessStageResult<ValueType, LiftedType>): void

Determine if reconciliation has been achieved by looking at messages.

private
consolidateAdjacentDones(result: ProcessStageResult<ValueType, LiftedType>): ProcessStageResult<ValueType, LiftedType>[] | undefined

Consolidate many adjacent done messages into a single done message, with the upper bound of the last one.

private
decode(message: EncodedMessageType): DecodeStageResult<ValueType, LiftedType>

Decodes an incoming message, and remembers its upper bound to use as a lower bound for the next message.

private
process(result: CollateStageResult<ValueType, LiftedType>): ProcessStageResult<ValueType, LiftedType>[]

Formulate the reply to a given message, as well as carry out any side effects such as inserting items into the tree.

private
setReusableTree(tree: NodeType<ValueType, LiftedType> | null)

A tiny convenience for casting the reusable tree to the right type.

encode(message: ProcessStageResult<ValueType, LiftedType>): EncodedMessageType
initialMessages(partitionItems?: (items: ValueType[]) => ValueType[][]): Iterable<EncodedMessageType>

Returns the opening messages for initiating an exchange between two peers.

onInsertion(callback: (value: ValueType) => void): () => void

Formulates and returns the appropriate response given a message from another peer. May insert values into the RangeMessenger's tree.

This method must be called with the messages from another peer, in the order they came.