fix: use libp2p.multiaddrs instead of listen

Co-Authored-By: Jacob Heun <jacobheun@gmail.com>
This commit is contained in:
Vasco Santos 2020-04-29 16:08:52 +02:00 committed by Jacob Heun
parent 51474c334a
commit 7fbd1556e8
5 changed files with 9 additions and 10 deletions

View File

@ -366,10 +366,9 @@ const latency = await libp2p.ping(otherPeerId)
## multiaddrs ## multiaddrs
Get peer advertising multiaddrs. This computes the advertising multiaddrs of the peer by Gets the multiaddrs the libp2p node announces to the network. This computes the advertising multiaddrs
joining the multiaddrs that libp2p transports are listening on with the announce multiaddrs of the peer by joining the multiaddrs that libp2p transports are listening on with the announce multiaddrs
provided in hte libp2p config. No announce multiaddrs will be filtered out, even when provided in the libp2p config. Configured no announce multiaddrs will be filtered out of the advertised addresses.
using random ports in the provided multiaddrs.
`libp2p.multiaddrs` `libp2p.multiaddrs`
@ -465,6 +464,7 @@ Get the multiaddrs that libp2p transports are using to listen on.
// ... // ...
const listenMa = libp2p.transportManager.getAddrs() const listenMa = libp2p.transportManager.getAddrs()
// [ <Multiaddr 047f00000106f9ba - /ip4/127.0.0.1/tcp/63930> ] // [ <Multiaddr 047f00000106f9ba - /ip4/127.0.0.1/tcp/63930> ]
```
### contentRouting.findProviders ### contentRouting.findProviders

View File

@ -96,7 +96,7 @@
"libp2p-floodsub": "^0.21.0", "libp2p-floodsub": "^0.21.0",
"libp2p-gossipsub": "^0.4.0", "libp2p-gossipsub": "^0.4.0",
"libp2p-kad-dht": "^0.19.1", "libp2p-kad-dht": "^0.19.1",
"libp2p-mdns": "^0.14.0", "libp2p-mdns": "^0.14.1",
"libp2p-mplex": "^0.9.5", "libp2p-mplex": "^0.9.5",
"libp2p-secio": "^0.12.4", "libp2p-secio": "^0.12.4",
"libp2p-tcp": "^0.14.1", "libp2p-tcp": "^0.14.1",

View File

@ -32,7 +32,7 @@ class Circuit {
this._connectionManager = libp2p.connectionManager this._connectionManager = libp2p.connectionManager
this._upgrader = upgrader this._upgrader = upgrader
this._options = libp2p._config.relay this._options = libp2p._config.relay
this.addressManager = libp2p.addressManager this._libp2p = libp2p
this.peerId = libp2p.peerId this.peerId = libp2p.peerId
this._registrar.handle(multicodec, this._onProtocol.bind(this)) this._registrar.handle(multicodec, this._onProtocol.bind(this))
} }
@ -122,7 +122,7 @@ class Circuit {
type: CircuitPB.Type.HOP, type: CircuitPB.Type.HOP,
srcPeer: { srcPeer: {
id: this.peerId.toBytes(), id: this.peerId.toBytes(),
addrs: this.addressManager.getListenAddrs().map(addr => addr.buffer) addrs: this._libp2p.multiaddrs.map(addr => addr.buffer)
}, },
dstPeer: { dstPeer: {
id: destinationPeer.toBytes(), id: destinationPeer.toBytes(),

View File

@ -189,8 +189,7 @@ class Libp2p extends EventEmitter {
*/ */
async start () { async start () {
log('libp2p is starting') log('libp2p is starting')
// TODO: consider validate listen addresses on start?
// depend on transports?
try { try {
await this._onStarting() await this._onStarting()
await this._onDidStart() await this._onDidStart()

View File

@ -161,7 +161,7 @@ describe('Dialing (via relay, TCP)', () => {
expect(dstLibp2p.transportManager.getAddrs()).to.have.deep.members([...tcpAddrs, dialAddr.decapsulate('p2p')]) expect(dstLibp2p.transportManager.getAddrs()).to.have.deep.members([...tcpAddrs, dialAddr.decapsulate('p2p')])
// Tamper with the our multiaddrs for the circuit message // Tamper with the our multiaddrs for the circuit message
sinon.stub(srcLibp2p.addressManager, 'getListenAddrs').returns([{ sinon.stub(srcLibp2p, 'multiaddrs').value([{
buffer: Buffer.from('an invalid multiaddr') buffer: Buffer.from('an invalid multiaddr')
}]) }])