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:
Vasco Santos
2019-11-26 16:40:04 +01:00
committed by Jacob Heun
parent f28b09fc0d
commit c563e06a60
10 changed files with 380 additions and 43 deletions

View File

@ -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()
}
}
/**