mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-23 22:11:35 +00:00
refactor: dht async/await (#480)
* refactor: core async (#478) * refactor: cleanup core test: auto dial on startup * fix: make hangup work properly * chore: fix lint * chore: apply suggestions from code review Co-Authored-By: Vasco Santos <vasco.santos@moxy.studio> * fix: provide libp2p dialer to the dht * chore: use dht release
This commit is contained in:
18
src/index.js
18
src/index.js
@ -91,7 +91,8 @@ class Libp2p extends EventEmitter {
|
||||
}
|
||||
|
||||
this.dialer = new Dialer({
|
||||
transportManager: this.transportManager
|
||||
transportManager: this.transportManager,
|
||||
peerStore: this.peerStore
|
||||
})
|
||||
|
||||
// Attach stream multiplexers
|
||||
@ -118,13 +119,8 @@ class Libp2p extends EventEmitter {
|
||||
}
|
||||
|
||||
// dht provided components (peerRouting, contentRouting, dht)
|
||||
if (this._config.dht.enabled) {
|
||||
const DHT = this._modules.dht
|
||||
|
||||
this._dht = new DHT(this._switch, {
|
||||
datastore: this.datastore,
|
||||
...this._config.dht
|
||||
})
|
||||
if (this._modules.dht) {
|
||||
this._dht = dht(this, this._modules.dht, this._config.dht)
|
||||
}
|
||||
|
||||
// start pubsub
|
||||
@ -136,7 +132,6 @@ class Libp2p extends EventEmitter {
|
||||
// peer and content routing will automatically get modules from _modules and _dht
|
||||
this.peerRouting = peerRouting(this)
|
||||
this.contentRouting = contentRouting(this)
|
||||
this.dht = dht(this)
|
||||
|
||||
this._peerDiscovered = this._peerDiscovered.bind(this)
|
||||
}
|
||||
@ -186,6 +181,7 @@ class Libp2p extends EventEmitter {
|
||||
|
||||
try {
|
||||
this.pubsub && await this.pubsub.stop()
|
||||
this._dht && await this._dht.stop()
|
||||
await this.transportManager.close()
|
||||
} catch (err) {
|
||||
if (err) {
|
||||
@ -312,6 +308,10 @@ class Libp2p extends EventEmitter {
|
||||
if (this._config.pubsub.enabled) {
|
||||
this.pubsub && this.pubsub.start()
|
||||
}
|
||||
|
||||
if (this._config.dht.enabled) {
|
||||
this._dht && this._dht.start()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user