Skip to content

Commit 7fbd155

Browse files
fix: use libp2p.multiaddrs instead of listen
Co-Authored-By: Jacob Heun <jacobheun@gmail.com>
1 parent 51474c3 commit 7fbd155

File tree

5 files changed

+9
-10
lines changed

5 files changed

+9
-10
lines changed

doc/API.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,9 @@ const latency = await libp2p.ping(otherPeerId)
366366

367367
## multiaddrs
368368

369-
Get peer advertising multiaddrs. This computes the advertising multiaddrs of the peer by
370-
joining the multiaddrs that libp2p transports are listening on with the announce multiaddrs
371-
provided in hte libp2p config. No announce multiaddrs will be filtered out, even when
372-
using random ports in the provided multiaddrs.
369+
Gets the multiaddrs the libp2p node announces to the network. This computes the advertising multiaddrs
370+
of the peer by joining the multiaddrs that libp2p transports are listening on with the announce multiaddrs
371+
provided in the libp2p config. Configured no announce multiaddrs will be filtered out of the advertised addresses.
373372

374373
`libp2p.multiaddrs`
375374

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

469469
### contentRouting.findProviders
470470

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
"libp2p-floodsub": "^0.21.0",
9797
"libp2p-gossipsub": "^0.4.0",
9898
"libp2p-kad-dht": "^0.19.1",
99-
"libp2p-mdns": "^0.14.0",
99+
"libp2p-mdns": "^0.14.1",
100100
"libp2p-mplex": "^0.9.5",
101101
"libp2p-secio": "^0.12.4",
102102
"libp2p-tcp": "^0.14.1",

src/circuit/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Circuit {
3232
this._connectionManager = libp2p.connectionManager
3333
this._upgrader = upgrader
3434
this._options = libp2p._config.relay
35-
this.addressManager = libp2p.addressManager
35+
this._libp2p = libp2p
3636
this.peerId = libp2p.peerId
3737
this._registrar.handle(multicodec, this._onProtocol.bind(this))
3838
}
@@ -122,7 +122,7 @@ class Circuit {
122122
type: CircuitPB.Type.HOP,
123123
srcPeer: {
124124
id: this.peerId.toBytes(),
125-
addrs: this.addressManager.getListenAddrs().map(addr => addr.buffer)
125+
addrs: this._libp2p.multiaddrs.map(addr => addr.buffer)
126126
},
127127
dstPeer: {
128128
id: destinationPeer.toBytes(),

src/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,7 @@ class Libp2p extends EventEmitter {
189189
*/
190190
async start () {
191191
log('libp2p is starting')
192-
// TODO: consider validate listen addresses on start?
193-
// depend on transports?
192+
194193
try {
195194
await this._onStarting()
196195
await this._onDidStart()

test/dialing/relay.node.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ describe('Dialing (via relay, TCP)', () => {
161161
expect(dstLibp2p.transportManager.getAddrs()).to.have.deep.members([...tcpAddrs, dialAddr.decapsulate('p2p')])
162162

163163
// Tamper with the our multiaddrs for the circuit message
164-
sinon.stub(srcLibp2p.addressManager, 'getListenAddrs').returns([{
164+
sinon.stub(srcLibp2p, 'multiaddrs').value([{
165165
buffer: Buffer.from('an invalid multiaddr')
166166
}])
167167

0 commit comments

Comments
 (0)