Skip to content

Commit

Permalink
psync: FullSync encode cumulative number of elements in sync Interest
Browse files Browse the repository at this point in the history
  • Loading branch information
yoursunny committed May 18, 2024
1 parent 337b871 commit 2a2cfa0
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
8 changes: 4 additions & 4 deletions integ/sync-interop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
Test environment:

* Ubuntu 22.04
* ndn-cxx 0.8.1-55-gc5003938
* NFD 22.12-41-g91c15c8c
* Node.js 20.11.0
* ndn-cxx 0.8.1-88-g5eb7a075
* NFD 22.12-69-gec352f2b
* Node.js 20.12.2

Reference implementation:

* PSync 0.4.0-15-gac63e32
* PSync 0.4.0-24-gdcb0bb86

Build reference program:

Expand Down
2 changes: 1 addition & 1 deletion pkg/psync/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ In the future, there would be alternative parameter sets optimized for the moder

NOTICE:
PSync commit d83af5255db9c4a557264542647f7ccb281e6840 (2024-04-09) introduces breaking changes to the FullSync algorithm and codec.
This library is currently incompatible with PSync revision since this commit.
This library has been adjusted to support the changed encoding, but does not yet implement the improved algorithm.
5 changes: 4 additions & 1 deletion pkg/psync/src/psync/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class PSyncCore {
public readonly nodes = new NameMap<PSyncNode>();
public readonly keys = new Map<number, PSyncNode>(); // key => node
public readonly iblt: IBLT;
public sumSeqNum = 0;

public get(prefix: Name): PSyncNode | undefined {
return this.nodes.get(prefix);
Expand Down Expand Up @@ -126,13 +127,14 @@ export class PSyncNode implements SyncNode<Name>, PSyncCore.PrefixSeqNum {
assert(!this.c.keys.has(this.k)); // algorithm cannot handle hash collision
this.c.keys.set(this.k, this);
this.c.iblt.insert(this.k);
this.c.sumSeqNum += this.seq;

if (triggerEvent) {
this.c.onIncreaseSeqNum?.(this, prevSeqNum, prevKey);
}
}

public remove() {
public remove(): void {
this.detachKey();
this.c.nodes.delete(this.prefix);
}
Expand All @@ -146,6 +148,7 @@ export class PSyncNode implements SyncNode<Name>, PSyncCore.PrefixSeqNum {
if (this.seq > 0 && this.c.keys.get(this.k) === this) {
this.c.keys.delete(this.k);
this.c.iblt.erase(this.k);
this.c.sumSeqNum -= this.seq;
}
}
}
24 changes: 22 additions & 2 deletions pkg/psync/src/psync/full.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ConsumerOptions, type Endpoint, produce, type Producer, type ProducerHandler, ProducerOptions } from "@ndn/endpoint";
import { GenericNumber } from "@ndn/naming-convention2";
import type { Component, Data, Interest, Name, Signer, Verifier } from "@ndn/packet";
import { type SyncNode, type SyncProtocol, SyncUpdate } from "@ndn/sync-api";
import { KeyMap, toHex, trackEventListener } from "@ndn/util";
Expand Down Expand Up @@ -51,6 +52,7 @@ export class FullSync extends TypedEventTarget<EventMap> implements SyncProtocol
this.c = new PSyncCore(p);
this.c.onIncreaseSeqNum = this.handleIncreaseSeqNum;
this.codec = new PSyncCodec(p, this.c.ibltParams);
this.syncInterestNameCumulativeNElements = p.syncInterestNameCumulativeNElements ?? true;

this.pFreshness = syncReplyFreshness;
this.pBuffer = new StateProducerBuffer(this.describe, this.codec, producerBufferLimit, {
Expand Down Expand Up @@ -81,6 +83,7 @@ export class FullSync extends TypedEventTarget<EventMap> implements SyncProtocol
private readonly syncPrefix: Name;
private readonly c: PSyncCore;
private readonly codec: PSyncCodec;
private readonly syncInterestNameCumulativeNElements: boolean;
private closed = false;

private readonly pFreshness: number;
Expand Down Expand Up @@ -136,7 +139,8 @@ export class FullSync extends TypedEventTarget<EventMap> implements SyncProtocol
}

private handleSyncInterest: ProducerHandler = async (interest) => {
if (interest.name.length !== this.syncPrefix.length + 1) {
if (interest.name.length !== this.syncPrefix.length +
(this.syncInterestNameCumulativeNElements ? 2 : 1)) {
// segment Interest should be satisfied by StateProducerBuffer
return undefined;
}
Expand Down Expand Up @@ -225,7 +229,10 @@ export class FullSync extends TypedEventTarget<EventMap> implements SyncProtocol
const abort = new AbortController();
this.cAbort = abort;
const ibltComp = this.codec.iblt2comp(this.c.iblt);
const name = this.syncPrefix.append(ibltComp);
let name = this.syncPrefix.append(ibltComp);
if (this.syncInterestNameCumulativeNElements) {
name = name.append(GenericNumber.create(this.c.sumSeqNum));
}
this.cCurrentInterestName = name;
this.debug("c-request");

Expand Down Expand Up @@ -268,6 +275,19 @@ export class FullSync extends TypedEventTarget<EventMap> implements SyncProtocol

export namespace FullSync {
export interface Parameters extends PSyncCore.Parameters, PSyncCodec.Parameters {
/**
* If true, sync Interest name contains cumulative number of elements in IBLT.
* @defaultValue true
*
* @remarks
* PSync C++ library commit d83af5255db9c4a557264542647f7ccb281e6840 (2024-04-09) introduced an
* algorithm change that involves a breaking change in sync Interest encoding.
* To interact with PSync since this commit, set to true.
* To interact with PSync before this commit, set to false.
*
* @experimental
*/
syncInterestNameCumulativeNElements?: boolean;
}

export interface Options {
Expand Down

0 comments on commit 2a2cfa0

Please sign in to comment.