Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
zjkmxy committed Feb 10, 2024
1 parent fa537cf commit 3499c52
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 108 deletions.
2 changes: 1 addition & 1 deletion deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"jose": "^5.2.1",
"tslib": "^2.6.2",
"y-protocols": "^1.0.6",
"yjs": "^13.6.11"
"yjs": "^13.6.12"
},
"devDependencies": {
"@ndn/endpoint": "https://ndnts-nightly.ndn.today/endpoint.tgz",
Expand All @@ -37,7 +37,7 @@
"@ndn/node-transport": "https://ndnts-nightly.ndn.today/node-transport.tgz",
"@ndn/packet": "https://ndnts-nightly.ndn.today/packet.tgz",
"@ndn/segmented-object": "https://ndnts-nightly.ndn.today/segmented-object.tgz",
"@ndn/sync": "https://ndnts-nightly.ndn.today/sync.tgz",
"@ndn/svs": "https://ndnts-nightly.ndn.today/svs.tgz",
"@ndn/tlv": "https://ndnts-nightly.ndn.today/tlv.tgz",
"@ndn/util": "https://ndnts-nightly.ndn.today/util.tgz",
"@ndn/ws-transport": "https://ndnts-nightly.ndn.today/ws-transport.tgz",
Expand All @@ -59,7 +59,7 @@
"@ndn/node-transport": ">=0.0.0",
"@ndn/packet": ">=0.0.0",
"@ndn/segmented-object": ">=0.0.0",
"@ndn/sync": ">=0.0.0",
"@ndn/svs": ">=0.0.0",
"@ndn/tlv": ">=0.0.0",
"@ndn/util": ">=0.0.0",
"@ndn/ws-transport": ">=0.0.0"
Expand Down
89 changes: 10 additions & 79 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 19 additions & 19 deletions src/sync-agent/deliveries.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Endpoint } from '@ndn/endpoint';
import { SvStateVector, SvSync, type SyncNode, type SyncUpdate } from '@ndn/sync';
import { StateVector, SvSync, type SyncNode, type SyncUpdate } from '@ndn/svs';
import { Data, digestSigning, Name, Signer, type Verifier } from '@ndn/packet';
import { SequenceNum } from '@ndn/naming-convention2';
import { Decoder, Encoder } from '@ndn/tlv';
Expand All @@ -8,17 +8,17 @@ import { getNamespace } from './namespace.ts';
import { Storage } from '../storage/mod.ts';
import { panic } from '../utils/panic.ts';

export function encodeSyncState(state: SvStateVector): Uint8Array {
export function encodeSyncState(state: StateVector): Uint8Array {
return Encoder.encode(state);
}

export function parseSyncState(vector: Uint8Array): SvStateVector {
export function parseSyncState(vector: Uint8Array): StateVector {
try {
const ret = Decoder.decode(vector, SvStateVector);
const ret = Decoder.decode(vector, StateVector);
return ret;
} catch (e) {
console.error(`Unable to parse SvStateVector: `, e);
return new SvStateVector();
console.error(`Unable to parse StateVector: `, e);
return new StateVector();
}
}

Expand All @@ -42,7 +42,7 @@ export abstract class SyncDelivery implements AsyncDisposable {
private _startPromiseResolve?: () => void;
protected _onReset?: () => void;
protected _abortController: AbortController;
protected _lastTillNow: SvStateVector;
protected _lastTillNow: StateVector;

// TODO: Use options to configure parameters
constructor(
Expand All @@ -52,7 +52,7 @@ export abstract class SyncDelivery implements AsyncDisposable {
readonly signer: Signer,
readonly verifier: Verifier,
onUpdatePromise: Promise<UpdateEvent>,
protected state?: SvStateVector,
protected state?: StateVector,
) {
// const nodeId = getNamespace().nodeIdFromSigner(this.signer.name)
this.baseName = getNamespace().baseName(nodeId, syncPrefix);
Expand All @@ -63,14 +63,14 @@ export abstract class SyncDelivery implements AsyncDisposable {
}
});
this._abortController = new AbortController();
this._lastTillNow = new SvStateVector(this.state);
this._lastTillNow = new StateVector(this.state);

SvSync.create({
endpoint: endpoint,
syncPrefix: syncPrefix,
signer: signer,
verifier: verifier,
initialStateVector: new SvStateVector(state),
initialStateVector: new StateVector(state),
initialize: async (svSync) => {
this._syncInst = svSync;
this._syncInst.addEventListener('update', (update) => this.handleSyncUpdate(update));
Expand Down Expand Up @@ -101,7 +101,7 @@ export abstract class SyncDelivery implements AsyncDisposable {
}

public get syncState() {
return new SvStateVector(this.state);
return new StateVector(this.state);
}

/**
Expand Down Expand Up @@ -155,15 +155,15 @@ export abstract class SyncDelivery implements AsyncDisposable {
console.warn('A Sync reset is scheduled.');
this._abortController.abort('Reset');
this._abortController = new AbortController();
this._lastTillNow = new SvStateVector(this.state);
this._lastTillNow = new StateVector(this.state);
this._syncInst.close();
this._syncNode = undefined;
const svSync = await SvSync.create({
endpoint: this.endpoint,
syncPrefix: this.syncPrefix,
signer: digestSigning,
// We can do so because the state has not been set
initialStateVector: new SvStateVector(this.state),
initialStateVector: new StateVector(this.state),
initialize: (svSync) => {
this._syncInst = svSync;
this._syncInst.addEventListener('update', (update) => this.handleSyncUpdate(update));
Expand Down Expand Up @@ -227,7 +227,7 @@ export class AtLeastOnceDelivery extends SyncDelivery {
readonly verifier: Verifier,
readonly storage: Storage,
onUpdatePromise: Promise<UpdateEvent>,
protected state?: SvStateVector,
protected state?: StateVector,
) {
super(nodeId, endpoint, syncPrefix, signer, verifier, onUpdatePromise, state);
}
Expand Down Expand Up @@ -263,7 +263,7 @@ export class AtLeastOnceDelivery extends SyncDelivery {

// Callback
// AtLeastOnce is required to have the callback acknowledged
// before writing the new SvStateVector into the storage
// before writing the new StateVector into the storage
await this._onUpdate!(data.content, update.id, this);
}
} catch (error) {
Expand Down Expand Up @@ -358,7 +358,7 @@ export class AtLeastOnceDelivery extends SyncDelivery {
// const nodeId = getNamespace().nodeIdFromSigner(signer.name)
const baseName = getNamespace().baseName(nodeId, syncPrefix);
const encoded = await storage.get(getNamespace().syncStateKey(baseName));
let syncState = new SvStateVector();
let syncState = new StateVector();
if (encoded) {
syncState = parseSyncState(encoded);
}
Expand All @@ -369,7 +369,7 @@ export class AtLeastOnceDelivery extends SyncDelivery {
return await super.destroy(this.storage);
}

async replay(startFrom: SvStateVector, callback: UpdateEvent) {
async replay(startFrom: StateVector, callback: UpdateEvent) {
for (const [key, last] of this.syncState) {
const first = startFrom.get(key);
const prefix = getNamespace().baseName(key, this.syncPrefix);
Expand Down Expand Up @@ -401,7 +401,7 @@ export class LatestOnlyDelivery extends SyncDelivery {
readonly pktStorage: Storage,
readonly stateStorage: Storage,
readonly onUpdatePromise: Promise<UpdateEvent>,
protected state?: SvStateVector,
protected state?: StateVector,
) {
super(nodeId, endpoint, syncPrefix, signer, verifier, onUpdatePromise, state);
}
Expand Down Expand Up @@ -467,7 +467,7 @@ export class LatestOnlyDelivery extends SyncDelivery {
// const nodeId = getNamespace().nodeIdFromSigner(signer.name)
const baseName = getNamespace().baseName(nodeId, syncPrefix);
const encoded = await stateStorage.get(getNamespace().syncStateKey(baseName));
let syncState = new SvStateVector();
let syncState = new StateVector();
if (encoded) {
syncState = parseSyncState(encoded);
}
Expand Down
12 changes: 6 additions & 6 deletions src/sync-agent/sync-agent.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Endpoint } from '@ndn/endpoint';
import { Data, type Interest, Name, Signer, type Verifier } from '@ndn/packet';
import { Decoder, Encoder } from '@ndn/tlv';
import { DataProducer, fetch, makeChunkSource } from '@ndn/segmented-object';
import { BufferChunkSource, DataProducer, fetch } from '@ndn/segmented-object';
import { concatBuffers } from '@ndn/util';
import { AtLeastOnceDelivery, LatestOnlyDelivery, UpdateEvent } from './deliveries.ts';
import { getNamespace } from './namespace.ts';
import { InMemoryStorage, Storage } from '../storage/mod.ts';
import { SvStateVector } from '@ndn/sync';
import { StateVector } from '@ndn/svs';
import { panic } from '../utils/panic.ts';

export type ChannelType = 'update' | 'blob' | 'status' | 'blobUpdate';
Expand Down Expand Up @@ -246,7 +246,7 @@ export class SyncAgent implements AsyncDisposable {
await this.persistStorage.set(name.toString(), blobContent);

// Put segmented packets
const producer = DataProducer.create(makeChunkSource(blobContent), name, { signer: this.signer });
const producer = DataProducer.create(new BufferChunkSource(blobContent), name, { signer: this.signer });
for await (const segment of producer.listData()) {
this.persistStorage.set(segment.name.toString(), Encoder.encode(segment));
}
Expand Down Expand Up @@ -329,13 +329,13 @@ export class SyncAgent implements AsyncDisposable {
/**
* Replay existing updates under specific topic
*/
async replayUpdates(topic: string, startFrom?: SvStateVector) {
async replayUpdates(topic: string, startFrom?: StateVector) {
const listener = this.listeners[`update.${topic}`];
if (!listener) {
throw new Error('You cannot call replayUpdates without a listener');
}

const start = startFrom ?? new SvStateVector();
const start = startFrom ?? new StateVector();
await this.atLeastOnce.replay(start, async (wire, id) => {
const inner = this.parseInnerData(wire);
if (!inner) {
Expand Down Expand Up @@ -363,7 +363,7 @@ export class SyncAgent implements AsyncDisposable {
}

public getUpdateSyncSV() {
return new SvStateVector(this.atLeastOnce.syncState);
return new StateVector(this.atLeastOnce.syncState);
}

static async create(
Expand Down

0 comments on commit 3499c52

Please sign in to comment.