Skip to content

Commit

Permalink
fix: use libp2p.multiaddrs instead of listen
Browse files Browse the repository at this point in the history
Co-Authored-By: Jacob Heun <[email protected]>
  • Loading branch information
vasco-santos and jacobheun committed Apr 29, 2020
1 parent 4357148 commit e5592b0
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
8 changes: 4 additions & 4 deletions doc/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,9 @@ const latency = await libp2p.ping(otherPeerId)

## multiaddrs

Get peer advertising multiaddrs. This computes the advertising 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
using random ports in the provided multiaddrs.
Gets the multiaddrs the libp2p node announces to the network. This computes the advertising multiaddrs
of the peer by joining the multiaddrs that libp2p transports are listening on with the announce multiaddrs
provided in the libp2p config. Configured no announce multiaddrs will be filtered out of the advertised addresses.

`libp2p.multiaddrs`

Expand Down Expand Up @@ -465,6 +464,7 @@ Get the multiaddrs that libp2p transports are using to listen on.
// ...
const listenMa = libp2p.transportManager.getAddrs()
// [ <Multiaddr 047f00000106f9ba - /ip4/127.0.0.1/tcp/63930> ]
```

### contentRouting.findProviders

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"libp2p-floodsub": "^0.21.0",
"libp2p-gossipsub": "^0.4.0",
"libp2p-kad-dht": "^0.19.1",
"libp2p-mdns": "libp2p/js-libp2p-mdns#chore/use-address-manager",
"libp2p-mdns": "^0.14.1",
"libp2p-mplex": "^0.9.1",
"libp2p-secio": "^0.12.1",
"libp2p-tcp": "^0.14.1",
Expand Down
4 changes: 2 additions & 2 deletions src/circuit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Circuit {
this._connectionManager = libp2p.connectionManager
this._upgrader = upgrader
this._options = libp2p._config.relay
this.addressManager = libp2p.addressManager
this._libp2p = libp2p
this.peerId = libp2p.peerId
this._registrar.handle(multicodec, this._onProtocol.bind(this))
}
Expand Down Expand Up @@ -122,7 +122,7 @@ class Circuit {
type: CircuitPB.Type.HOP,
srcPeer: {
id: this.peerId.toBytes(),
addrs: this.addressManager.getListenAddrs().map(addr => addr.buffer)
addrs: this._libp2p.multiaddrs.map(addr => addr.buffer)
},
dstPeer: {
id: destinationPeer.toBytes(),
Expand Down
3 changes: 1 addition & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ class Libp2p extends EventEmitter {
*/
async start () {
log('libp2p is starting')
// TODO: consider validate listen addresses on start?
// depend on transports?

try {
await this._onStarting()
await this._onDidStart()
Expand Down
2 changes: 1 addition & 1 deletion test/dialing/relay.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ describe('Dialing (via relay, TCP)', () => {
expect(dstLibp2p.transportManager.getAddrs()).to.have.deep.members([...tcpAddrs, dialAddr.decapsulate('p2p')])

// 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')
}])

Expand Down

0 comments on commit e5592b0

Please sign in to comment.