Skip to content

Commit 3bc94b4

Browse files
authored
fix: begin routing table refresh after routing table has started (#2511)
Fixes an error in the logs where we try to refresh the routing table before it's started. Switch to doing it in `afterStart` so the routing table is available.
1 parent 9e9a32b commit 3bc94b4

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

packages/kad-dht/src/kad-dht.ts

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CodeError, CustomEvent, TypedEventEmitter, contentRoutingSymbol, peerDiscoverySymbol, peerRoutingSymbol } from '@libp2p/interface'
1+
import { CodeError, CustomEvent, TypedEventEmitter, contentRoutingSymbol, peerDiscoverySymbol, peerRoutingSymbol, start, stop } from '@libp2p/interface'
22
import drain from 'it-drain'
33
import pDefer from 'p-defer'
44
import { PROTOCOL } from './constants.js'
@@ -379,16 +379,15 @@ export class KadDHT extends TypedEventEmitter<PeerDiscoveryEvents> implements Ka
379379
// Only respond to queries when not in client mode
380380
await this.setMode(this.clientMode ? 'client' : 'server')
381381

382-
this.querySelf.start()
383-
384-
await Promise.all([
385-
this.providers.start(),
386-
this.queryManager.start(),
387-
this.network.start(),
388-
this.routingTable.start(),
389-
this.topologyListener.start(),
390-
this.routingTableRefresh.start()
391-
])
382+
await start(
383+
this.querySelf,
384+
this.providers,
385+
this.queryManager,
386+
this.network,
387+
this.routingTable,
388+
this.topologyListener,
389+
this.routingTableRefresh
390+
)
392391
}
393392

394393
/**
@@ -398,16 +397,15 @@ export class KadDHT extends TypedEventEmitter<PeerDiscoveryEvents> implements Ka
398397
async stop (): Promise<void> {
399398
this.running = false
400399

401-
this.querySelf.stop()
402-
403-
await Promise.all([
404-
this.providers.stop(),
405-
this.queryManager.stop(),
406-
this.network.stop(),
407-
this.routingTable.stop(),
408-
this.routingTableRefresh.stop(),
409-
this.topologyListener.stop()
410-
])
400+
await stop(
401+
this.querySelf,
402+
this.providers,
403+
this.queryManager,
404+
this.network,
405+
this.routingTable,
406+
this.routingTableRefresh,
407+
this.topologyListener
408+
)
411409
}
412410

413411
/**

packages/kad-dht/src/routing-table/refresh.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class RoutingTableRefresh {
5151
this.refreshTable = this.refreshTable.bind(this)
5252
}
5353

54-
async start (): Promise<void> {
54+
async afterStart (): Promise<void> {
5555
this.log(`refreshing routing table every ${this.refreshInterval}ms`)
5656
this.refreshTable(true)
5757
}

0 commit comments

Comments
 (0)