diff --git a/src/index.ts b/src/index.ts index 94394cbf..eb77c35e 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 + + /** + * Initialization options for the Providers component + */ + providers?: ProvidersInit } export interface KadDHTComponents { diff --git a/src/kad-dht.ts b/src/kad-dht.ts index 098144bb..3108bc80 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, diff --git a/test/kad-dht.spec.ts b/test/kad-dht.spec.ts index 6b4299af..13e89294 100644 --- a/test/kad-dht.spec.ts +++ b/test/kad-dht.spec.ts @@ -91,6 +91,20 @@ 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', () => {