Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

feat: allow passing ProvidersInit in KadDHT constructor #404

Merged
merged 6 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions src/kad-dht.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ export class KadDHT extends EventEmitter<PeerDiscoveryEvents> implements DHT {
pingTimeout,
pingConcurrency,
maxInboundStreams,
maxOutboundStreams
maxOutboundStreams,
providers: providersInit,
achingbrain marked this conversation as resolved.
Show resolved Hide resolved
} = init

this.running = false
Expand All @@ -102,7 +103,7 @@ export class KadDHT extends EventEmitter<PeerDiscoveryEvents> implements DHT {
protocol: this.protocol
})

this.providers = new Providers(components)
this.providers = new Providers(components, providersInit ?? {})

this.validators = {
...recordValidators,
Expand Down
15 changes: 15 additions & 0 deletions test/kad-dht.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
achingbrain marked this conversation as resolved.
Show resolved Hide resolved
}
})

achingbrain marked this conversation as resolved.
Show resolved Hide resolved
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', () => {
Expand Down