diff --git a/pkg/svs/README.md b/pkg/svs/README.md index 82495381..76178c19 100644 --- a/pkg/svs/README.md +++ b/pkg/svs/README.md @@ -9,3 +9,5 @@ This package contains **StateVectorSync** and related protocols, including: * core synchronization logic only, does not deal with Data fetching * [SVS-PS](https://named-data.github.io/StateVectorSync/PubSubSpec.html), revision 2023-05-19 * simple unit test + +[SVS v2](https://github.com/named-data/StateVectorSync/pull/14) is being implemented. diff --git a/pkg/svs/src/sync.ts b/pkg/svs/src/sync.ts index b18477de..89db7f05 100644 --- a/pkg/svs/src/sync.ts +++ b/pkg/svs/src/sync.ts @@ -34,10 +34,18 @@ export class SvSync extends TypedEventTarget implements SyncProtocol { + if (typeof periodicTimeout === "number") { + periodicTimeout = [periodicTimeout, 0.1]; + } + const sync = new SvSync( syncPrefix, describe, @@ -48,7 +56,8 @@ export class SvSync extends TypedEventTarget implements SyncProtocol implements SyncProtocol number; /** * Sync Interest signer. @@ -297,6 +352,21 @@ export namespace SvSync { */ verifier?: Verifier; } + + /** + * SVS v2 suppression timeout exponential decay function. + * @param c - Constant factor. + * @param f - Decay factor. + * @returns Function to generate suppression timeout values. + * @experimental + */ + export function suppressionExpDelay(c: number, f = 10): () => number { + const cf = c / f; + return () => { + const v = Math.random() * c; + return -c * Math.expm1((v - c) / cf); + }; + } } class SvSyncNode implements SyncNode { diff --git a/pkg/svs/tests/svs.t.ts b/pkg/svs/tests/svs.t.ts index 076562ce..dfb68831 100644 --- a/pkg/svs/tests/svs.t.ts +++ b/pkg/svs/tests/svs.t.ts @@ -55,7 +55,7 @@ const closers = new Closers(); afterEach(closers.close); // specification section 5.2 example -test("example", async () => { +test.each([false, true])("example %#", async (svs2suppression) => { const debugHandler = new DebugHandler(); let lossToC = false; using bridge = Bridge.create({ @@ -65,6 +65,7 @@ test("example", async () => { const opts: SvSync.Options = { ...baseOpts, + svs2suppression, fw: fwAB, };