From 127f5379d3685ce1656aef1c37d6d0b90707d5f1 Mon Sep 17 00:00:00 2001 From: Joel Gustafson Date: Tue, 29 Nov 2022 11:20:06 -0500 Subject: [PATCH 1/5] expose ProvidersInit in KadDHT constructor --- src/index.ts | 6 ++++++ src/kad-dht.ts | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 94394cbf..60977adb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,6 @@ import { KadDHT as SingleKadDHT } from './kad-dht.js' import { DualKadDHT } from './dual-kad-dht.js' +import type { ProvidersInit } from './providers.js' import type { Selectors, Validators } from '@libp2p/interface-dht' import type { Registrar } from '@libp2p/interface-registrar' import type { AddressManager } from '@libp2p/interface-address-manager' @@ -62,6 +63,11 @@ export interface KadDHTInit { * How many parallel outgoing streams to allow on the DHT protocol per-connection */ maxOutboundStreams?: number + + /** + * Initalization options for the Providers component + */ + providers?: ProvidersInit } export interface KadDHTComponents { diff --git a/src/kad-dht.ts b/src/kad-dht.ts index 098144bb..f5c4ae72 100644 --- a/src/kad-dht.ts +++ b/src/kad-dht.ts @@ -82,7 +82,8 @@ export class KadDHT extends EventEmitter implements DHT { pingTimeout, pingConcurrency, maxInboundStreams, - maxOutboundStreams + maxOutboundStreams, + providers: providersInit, } = init this.running = false @@ -102,7 +103,7 @@ export class KadDHT extends EventEmitter implements DHT { protocol: this.protocol }) - this.providers = new Providers(components) + this.providers = new Providers(components, providersInit ?? {}) this.validators = { ...recordValidators, From 3752cdffda6a9adc029b1233fd7f1d2a9cbe8b39 Mon Sep 17 00:00:00 2001 From: Joel Gustafson Date: Tue, 29 Nov 2022 11:29:59 -0500 Subject: [PATCH 2/5] typo --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 60977adb..eb77c35e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -65,7 +65,7 @@ export interface KadDHTInit { maxOutboundStreams?: number /** - * Initalization options for the Providers component + * Initialization options for the Providers component */ providers?: ProvidersInit } From f380de28e62e9157c59c8dd3ade014753e0b6475 Mon Sep 17 00:00:00 2001 From: Joel Gustafson Date: Tue, 29 Nov 2022 12:07:32 -0500 Subject: [PATCH 3/5] add test that checks that the options are in fact passed successfully --- test/kad-dht.spec.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/kad-dht.spec.ts b/test/kad-dht.spec.ts index 1d33ba85..9c2e5a29 100644 --- a/test/kad-dht.spec.ts +++ b/test/kad-dht.spec.ts @@ -91,6 +91,21 @@ describe('KadDHT', () => { expect(dht).to.have.property('getMode') expect(dht).to.have.property('setMode') }) + + it('forward providers init options to providers component', async () => { + const dht = await tdht.spawn({ + kBucketSize: 5, + providers: { + cleanupInterval: 60, + provideValidity: 60 * 10, + } + }) + + expect(dht.lan.providers).to.have.property('cleanupInterval', 60) + expect(dht.lan.providers).to.have.property('provideValidity', 60 * 10) + expect(dht.wan.providers).to.have.property('cleanupInterval', 60) + expect(dht.wan.providers).to.have.property('provideValidity', 60 * 10) + }) }) describe('start and stop', () => { From d696cef2ab0efdb15f47224a618841746bc24581 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Wed, 7 Dec 2022 09:05:36 +0000 Subject: [PATCH 4/5] chore: linting --- src/kad-dht.ts | 2 +- test/kad-dht.spec.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/kad-dht.ts b/src/kad-dht.ts index f5c4ae72..3108bc80 100644 --- a/src/kad-dht.ts +++ b/src/kad-dht.ts @@ -83,7 +83,7 @@ export class KadDHT extends EventEmitter implements DHT { pingConcurrency, maxInboundStreams, maxOutboundStreams, - providers: providersInit, + providers: providersInit } = init this.running = false diff --git a/test/kad-dht.spec.ts b/test/kad-dht.spec.ts index d27bfd74..11435a90 100644 --- a/test/kad-dht.spec.ts +++ b/test/kad-dht.spec.ts @@ -97,7 +97,7 @@ describe('KadDHT', () => { kBucketSize: 5, providers: { cleanupInterval: 60, - provideValidity: 60 * 10, + provideValidity: 60 * 10 } }) From f59880dbe6b890578f51ce125fad9cd56b907446 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Wed, 7 Dec 2022 09:14:26 +0000 Subject: [PATCH 5/5] chore: linting again --- test/kad-dht.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/kad-dht.spec.ts b/test/kad-dht.spec.ts index 11435a90..13e89294 100644 --- a/test/kad-dht.spec.ts +++ b/test/kad-dht.spec.ts @@ -100,7 +100,6 @@ describe('KadDHT', () => { provideValidity: 60 * 10 } }) - expect(dht.lan.providers).to.have.property('cleanupInterval', 60) expect(dht.lan.providers).to.have.property('provideValidity', 60 * 10) expect(dht.wan.providers).to.have.property('cleanupInterval', 60)