Skip to content

Commit

Permalink
svs: delete SVS v1
Browse files Browse the repository at this point in the history
  • Loading branch information
yoursunny committed Jan 7, 2025
1 parent a053240 commit da92a13
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 191 deletions.
47 changes: 15 additions & 32 deletions integ/sync-interop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,15 @@ corepack pnpm literate integ/sync-interop/syncps.ts
Test environment:

* Ubuntu 22.04
* ndn-cxx 0.9.0-1-g0311642a
* NFD 24.07-1-gee97f534
* ndn-cxx 0.9.0-3-ge913e3ab
* NFD 24.07-5-g401d1a48
* Node.js v22.11.0
* Go 1.23.4

Reference implementation:

* [StateVectorSync C++ library](https://github.com/named-data/ndn-svs) commit `e502c2aef95640d33b51c92c9659ec0bb7ee6386` (2024-12-15)
* [SVS v2](https://github.com/named-data/ndn-svs/pull/26) commit `1290954f8d0d5c1f61caab9ac1aeacde500c9990` (2024-03-08)
* [NDNd](https://github.com/named-data/ndnd) commit `e5c2033375770932ea049a5bde9a9c1db7b6dcce` (2024-12-25)
* [StateVectorSync C++ library](https://github.com/named-data/ndn-svs) commit `7fa0af007772c2e320bdc3996fd3bb57fbb21347` (2025-01-05)
* [NDNd](https://github.com/named-data/ndnd) commit `e8bf6feb24e006e3ff9737d8c5e49b976ed61604` (2025-01-07)

Build reference program:

Expand All @@ -120,63 +119,47 @@ Build reference program:
./waf

# in $HOME directory
go install -v github.com/named-data/ndnd/std/examples/low-level/svs@@v1.4.1-0.20241225025915-e5c203337577
```

Environment variables:

```bash
# if testing with C++, SVS v1
export NDNTS_INTEROP_SVS2=0
export NDNTS_INTEROP_B64HMAC=dGhpcyBpcyBhIHNlY3JldCBtZXNzYWdl
export NDNTS_INTEROP_HASMSG=1

# if testing with C++, SVS v2
export NDNTS_INTEROP_SVS2=1
export NDNTS_INTEROP_B64HMAC=dGhpcyBpcyBhIHNlY3JldCBtZXNzYWdl
export NDNTS_INTEROP_HASMSG=1

# if testing with NDNd
export NDNTS_INTEROP_SVS2=1
export NDNTS_INTEROP_B64HMAC=''
export NDNTS_INTEROP_HASMSG=0
go install -v github.com/named-data/ndnd/std/examples/low-level/svs@v1.4.3-0.20250107153723-e8bf6feb24e0
```

Test `SvSync`:

```bash
# set multicast strategy
nfdc strategy set /ndn/svs /localhost/nfd/strategy/multicast

# C++: in ndn-svs directory
LD_LIBRARY_PATH=build ./build/examples/chat /${RANDOM}
LD_LIBRARY_PATH=build ./build/examples/core /cpp-${RANDOM}

# NDNd: in $HOME directory
~/go/bin/svs ndnd-${RANDOM}

# in NDNts directory, after setting environment variables
# in NDNts directory
corepack pnpm literate integ/sync-interop/svsync.ts
```

Test `SvPublisher`:

```bash
# in NDNts directory, after setting environment variables
# in NDNts directory
corepack pnpm literate integ/sync-interop/svsps-publisher.ts

# C++: in ndn-svs directory
LD_LIBRARY_PATH=build ./build/examples/chat-pubsub /${RANDOM}
LD_LIBRARY_PATH=build ./build/examples/chat-pubsub /cpp-${RANDOM}
```

Test `SvSubscriber`:

```bash
# C++: in ndn-svs directory
LD_LIBRARY_PATH=build ./build/examples/chat-pubsub /${RANDOM}
LD_LIBRARY_PATH=build ./build/examples/chat-pubsub /cpp-${RANDOM}

# in NDNts directory, after setting environment variables
# in NDNts directory
corepack pnpm literate integ/sync-interop/svsps-subscriber.ts
```

What to do and what to observe:

* For C++ `chat` or `chat-pubsub` publisher: type a line on the console and press ENTER to publish an update.
* For C++ `chat-pubsub` publisher: type a line on the console and press ENTER to publish an update.
* NDNts and NDNd publisher do not need user interaction.
* Look at console logs: when one peer publishes an update, the other peer should see the update.
14 changes: 4 additions & 10 deletions integ/sync-interop/svs-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,22 @@ import { Name } from "@ndn/packet";
import { SvSync } from "@ndn/svs";

export const syncPrefix = new Name("/ndn/svs");
export const myID = new Name(`/${process.pid}-${Date.now()}`);
export const myID = new Name(`/NDNts-${process.pid}-${Date.now()}`);
export const myDataPrefix = myID.append(...syncPrefix.comps);

export async function openSvSync(): Promise<SvSync> {
export async function openSvSync(wantHMAC: boolean): Promise<SvSync> {
await openUplinks();

const opts: SvSync.Options = { syncPrefix };

const b64hmac = process.env.NDNTS_INTEROP_B64HMAC;
if (b64hmac) {
if (wantHMAC) {
const key = await HMAC.cryptoGenerate({
importRaw: Buffer.from(b64hmac, "base64"),
importRaw: Buffer.from("dGhpcyBpcyBhIHNlY3JldCBtZXNzYWdl", "base64"),
}, false);
opts.signer = createSigner(HMAC, key);
opts.verifier = createVerifier(HMAC, key);
}

if (process.env.NDNTS_INTEROP_SVS2 === "1") {
opts.svs2interest = true;
opts.svs2suppression = true;
}

const sync = await SvSync.create(opts);
exitClosers.push(sync);
return sync;
Expand Down
2 changes: 1 addition & 1 deletion integ/sync-interop/svsps-publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { console, crypto, toHex, toUtf8 } from "@ndn/util";

import { myID, openSvSync } from "./svs-common";

const sync = await openSvSync();
const sync = await openSvSync(true);
const pub = new SvPublisher({
sync,
id: myID,
Expand Down
2 changes: 1 addition & 1 deletion integ/sync-interop/svsps-subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { console, fromUtf8 } from "@ndn/util";

import { openSvSync } from "./svs-common";

const sync = await openSvSync();
const sync = await openSvSync(true);
const sub = new SvSubscriber({
sync,
innerVerifier: digestSigning,
Expand Down
30 changes: 3 additions & 27 deletions integ/sync-interop/svsync.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,13 @@
import { exitClosers } from "@ndn/cli-common";
import { consume, produce } from "@ndn/endpoint";
import { GenericNumber } from "@ndn/naming-convention2";
import { Data, Interest } from "@ndn/packet";
import { console, fromUtf8, toUtf8 } from "@ndn/util";
import { console } from "@ndn/util";

import { myDataPrefix, myID, openSvSync, syncPrefix } from "./svs-common";
import { myID, openSvSync } from "./svs-common";

const sync = await openSvSync();

const producer = produce(myDataPrefix, async (interest) => {
const n = interest.name.at(myDataPrefix.length).as(GenericNumber);
return new Data(interest.name, Data.FreshnessPeriod(1), toUtf8(`NDNts message ${n}`));
});
exitClosers.push(producer);
const sync = await openSvSync(false);

sync.addEventListener("update", (update) => {
const { id, loSeqNum, hiSeqNum } = update;
console.log(`UPDATE ${id} ${loSeqNum}..${hiSeqNum}`);
if (process.env.NDNTS_INTEROP_HASMSG === "0") {
return;
}
for (const seqNum of update.seqNums()) {
void (async () => {
try {
const name = id.append(...syncPrefix.comps, GenericNumber.create(seqNum));
const interest = new Interest(name, Interest.CanBePrefix, Interest.Lifetime(2000));
const data = await consume(interest, { retx: 2 });
console.log(`MSG ${id}:${seqNum} ${fromUtf8(data.content)}`);
} catch (err: unknown) {
console.warn(`FETCH-ERR ${id}:${seqNum} ${err}`);
}
})();
}
});

const node = sync.add(myID);
Expand Down
15 changes: 3 additions & 12 deletions pkg/svs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,12 @@ This package is part of [NDNts](https://yoursunny.com/p/NDNts/), Named Data Netw

This package contains **StateVectorSync** and related protocols, including:

* [StateVectorSync](https://named-data.github.io/StateVectorSync/Specification.html), revision 2021-12-15
* [StateVectorSync v2](https://named-data.github.io/StateVectorSync/Specification.html), revision 2025-01-04
* complete unit test
* core synchronization logic only, does not deal with Data fetching
* note: SVS v2 has been deleted
* [SVS-PS](https://named-data.github.io/StateVectorSync/PubSubSpec.html), revision 2023-05-19
* simple unit test
* piggyback MappingData feature is not supported

Compatibility with the reference implementation is validated in [sync-interop](../../integ/sync-interop).

[SVS v2](https://github.com/named-data/StateVectorSync/pull/14) is being implemented:

* [X] Encode StateVector in ApplicationParameters instead of Name.
Enable with `svs2interest: true` option.
* [X] Use exponential decay function for suppression timeout.
Enable with `svs2suppression: true` option.
* [X] Don't enter suppression state if every node was updated in last suppression period.
Enable with `svs2suppression: true` option.
* [ ] Piggyback SVS-PS MappingData.
* [ ] Accept piggybacked SVS-PS MappingData.
Loading

0 comments on commit da92a13

Please sign in to comment.