fix: replace peerInfo addresses with listen addresses (#485)

* feat: replace peer info addresses with listen addresses

* test: add listening test

* chore: fix linting
This commit is contained in:
dirkmc
2019-11-28 10:45:04 -05:00
committed by Jacob Heun
parent 472e14f2b4
commit 1999606ecc
2 changed files with 64 additions and 0 deletions

View File

@ -301,10 +301,18 @@ class Libp2p extends EventEmitter {
}
async _onStarting () {
// Listen on the addresses supplied in the peerInfo
const multiaddrs = this.peerInfo.multiaddrs.toArray()
await this.transportManager.listen(multiaddrs)
// The addresses may change once the listener starts
// eg /ip4/0.0.0.0/tcp/0 => /ip4/192.168.1.0/tcp/58751
this.peerInfo.multiaddrs.clear()
for (const ma of this.transportManager.getAddrs()) {
this.peerInfo.multiaddrs.add(ma)
}
if (this._config.pubsub.enabled) {
this.pubsub && this.pubsub.start()
}