From 51474c334a8daf4a5053a662e17530077f3e54bb Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Tue, 28 Apr 2020 16:21:25 +0200 Subject: [PATCH] chore: rename address functions and apply suggestions from code review Co-Authored-By: Jacob Heun --- doc/API.md | 32 ++++++++++----------- doc/CONFIGURATION.md | 4 +-- doc/GETTING_STARTED.md | 11 +++++-- src/address-manager/README.md | 12 ++++---- src/address-manager/index.js | 8 +++--- src/circuit/index.js | 2 +- src/identify/index.js | 16 +++++------ src/index.js | 26 ++--------------- src/transport-manager.js | 2 +- test/addresses/address-manager.spec.js | 6 ++-- test/addresses/addresses.node.js | 40 +++++--------------------- test/core/ping.node.js | 4 +-- test/dialing/direct.node.js | 6 ++-- test/dialing/relay.node.js | 4 +-- test/identify/index.spec.js | 12 ++++---- test/peer-discovery/index.node.js | 4 +-- test/pubsub/implementations.node.js | 2 +- test/pubsub/operation.node.js | 4 +-- test/utils/creators/peer.js | 2 +- 19 files changed, 78 insertions(+), 119 deletions(-) diff --git a/doc/API.md b/doc/API.md index 4890264c..df331fe3 100644 --- a/doc/API.md +++ b/doc/API.md @@ -11,10 +11,10 @@ * [`handle`](#handle) * [`unhandle`](#unhandle) * [`ping`](#ping) - * [`getAdvertisingMultiaddrs`](#getadvertisingmultiaddrs) - * [`addressManager.getListenMultiaddrs`](#addressmanagergetlistenmultiaddrs) - * [`addressmger.getAnnounceMultiaddrs`](#addressmanagergetannouncemultiaddrs) - * [`addressManager.getNoAnnounceMultiaddrs`](#addressmanagergetnoannouncemultiaddrs) + * [`multiaddrs`](#multiaddrs) + * [`addressManager.getListenAddrs`](#addressmanagergetlistenaddrs) + * [`addressmger.getAnnounceAddrs`](#addressmanagergetannounceaddrs) + * [`addressManager.getNoAnnounceAddrs`](#addressmanagergetnoannounceaddrs) * [`contentRouting.findProviders`](#contentroutingfindproviders) * [`contentRouting.provide`](#contentroutingprovide) * [`contentRouting.put`](#contentroutingput) @@ -364,14 +364,14 @@ Pings a given peer and get the operation's latency. const latency = await libp2p.ping(otherPeerId) ``` -## getAdvertisingMultiaddrs +## 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. -`libp2p.getAdvertisingMultiaddrs()` +`libp2p.multiaddrs` #### Returns @@ -383,15 +383,15 @@ using random ports in the provided multiaddrs. ```js // ... -const listenMa = libp2p.getAdvertisingMultiaddrs() +const listenMa = libp2p.multiaddrs // [ ] ``` -### addressManager.getListenMultiaddrs +### addressManager.getListenAddrs Get the multiaddrs that were provided for listening on libp2p transports. -`libp2p.addressManager.getListenMultiaddrs()` +`libp2p.addressManager.getListenAddrs()` #### Returns @@ -403,15 +403,15 @@ Get the multiaddrs that were provided for listening on libp2p transports. ```js // ... -const listenMa = libp2p.addressManager.getListenMultiaddrs() +const listenMa = libp2p.addressManager.getListenAddrs() // [ ] ``` -### addressManager.getAnnounceMultiaddrs +### addressManager.getAnnounceAddrs Get the multiaddrs that were provided to announce to the network. -`libp2p.addressManager.getAnnounceMultiaddrs()` +`libp2p.addressManager.getAnnounceAddrs()` #### Returns @@ -423,15 +423,15 @@ Get the multiaddrs that were provided to announce to the network. ```js // ... -const announceMa = libp2p.addressManager.getAnnounceMultiaddrs() +const announceMa = libp2p.addressManager.getAnnounceAddrs() // [ ] ``` -### addressManager.getNoAnnounceMultiaddrs +### addressManager.getNoAnnounceAddrs Get the multiaddrs that were provided to not announce to the network. -`libp2p.addressManager.getNoAnnounceMultiaddrs()` +`libp2p.addressManager.getNoAnnounceAddrs()` #### Returns @@ -443,7 +443,7 @@ Get the multiaddrs that were provided to not announce to the network. ```js // ... -const noAnnounceMa = libp2p.addressManager.getNoAnnounceMultiaddrs() +const noAnnounceMa = libp2p.addressManager.getNoAnnounceAddrs() // [ ] ``` diff --git a/doc/CONFIGURATION.md b/doc/CONFIGURATION.md index 64abf8af..7a458200 100644 --- a/doc/CONFIGURATION.md +++ b/doc/CONFIGURATION.md @@ -204,7 +204,7 @@ Moreover, the majority of the modules can be customized via option parameters. T Besides the `modules` and `config`, libp2p allows other internal options and configurations: - `datastore`: an instance of [ipfs/interface-datastore](https://github.com/ipfs/interface-datastore/) modules. - This is used in modules such as the DHT. If it is not provided, `js-libp2p` will use an in memory datastore. -- `peerId`: a previously computed instance of [libp2p/js-peer-id](https://github.com/libp2p/js-peer-id). +- `peerId`: the identity of the node, an instance of [libp2p/js-peer-id](https://github.com/libp2p/js-peer-id). - This is particularly useful if you want to reuse the same `peer-id`, as well as for modules like `libp2p-delegated-content-routing`, which need a `peer-id` in their instantiation. - `addresses`: an object containing `listen`, `announce` and `noAnnounce` properties with `Array`: - `listen` addresses will be provided to the libp2p underlying transports for listening on them. @@ -215,8 +215,6 @@ Besides the `modules` and `config`, libp2p allows other internal options and con #### Basic setup -TODO: should we add to the basic setup the configuration of listen addresses? we should probably make it a required option? - ```js // Creating a libp2p node with: // transport: websockets + tcp diff --git a/doc/GETTING_STARTED.md b/doc/GETTING_STARTED.md index 9c1ddbc0..c9a772de 100644 --- a/doc/GETTING_STARTED.md +++ b/doc/GETTING_STARTED.md @@ -136,8 +136,6 @@ If you want to know more about libp2p stream multiplexing, you should read the f Now that you have configured a [**Transport**][transport], [**Crypto**][crypto] and [**Stream Multiplexer**](streamMuxer) module, you can start your libp2p node. We can start and stop libp2p using the [`libp2p.start()`](./API.md#start) and [`libp2p.stop()`](./API.md#stop) methods. -TODO: add listen addresses here? - ```js const Libp2p = require('libp2p') const WebSockets = require('libp2p-websockets') @@ -145,6 +143,9 @@ const SECIO = require('libp2p-secio') const MPLEX = require('libp2p-mplex') const node = await Libp2p.create({ + addresses: { + listen: ['/ip4/127.0.0.1/tcp/8000/ws'] + }, modules: { transport: [WebSockets], connEncryption: [SECIO], @@ -156,6 +157,12 @@ const node = await Libp2p.create({ await node.start() console.log('libp2p has started') +const listenAddrs = node.transportManager.getAddrs() +console.log('libp2p is listening on the following addresses: ', listenAddrs) + +const advertiseAddrs = node.multiaddrs +console.log('libp2p is advertising the following addresses: ', advertiseAddrs) + // stop libp2p await node.stop() console.log('libp2p has stopped') diff --git a/src/address-manager/README.md b/src/address-manager/README.md index 6cceff6a..53f93248 100644 --- a/src/address-manager/README.md +++ b/src/address-manager/README.md @@ -8,9 +8,9 @@ These Addresses should be specified in your libp2p [configuration](../../doc/CON A libp2p node should have a set of listen addresses, which will be used by libp2p underlying transports to listen for dials from other nodes in the network. -Before a libp2p node starts, a set of listen addresses should be provided to the AddressManager, so that when the node is started, the libp2p transports can use them to listen for connections. Accordingly, listen addresses should be specified through the libp2p configuration, in order to have the `AddressManager` created with them. +Before a libp2p node starts, its configured listen addresses will be passed to the AddressManager, so that during startup the libp2p transports can use them to listen for connections. Accordingly, listen addresses should be specified through the libp2p configuration, in order to have the `AddressManager` created with them. -It is important pointing out that libp2p accepts to listen on addresses that intend to rely on any available local port. In this context, the provided listen addresses might not be exactly the same as the ones used by the transports. For example tcp may replace `/ip4/0.0.0.0/tcp/0` with something like `/ip4/0.0.0.0/tcp/8989`. As a consequence, libp2p should take into account this when advertising its addresses. +It is important pointing out that libp2p accepts ephemeral listening addresses. In this context, the provided listen addresses might not be exactly the same as the ones used by the transports. For example TCP may replace `/ip4/0.0.0.0/tcp/0` with something like `/ip4/127.0.0.1/tcp/8989`. As a consequence, libp2p should take into account this when determining its advertised addresses. ## Announce Addresses @@ -22,13 +22,13 @@ Scenarios for Announce Addresses include: ## No Announce Addresses -While we need to add Announce Addresses to enable peers' connectivity, we can also not announce addresses that will not be reachable. This way, No Announce Addresses should be specified so that they are not announced by the peer as addresses that other peers can use to dial it. +While we need to add Announce Addresses to enable peers' connectivity, we should also avoid announcing addresses that will not be reachable. No Announce Addresses should be specified so that they are filtered from the advertised multiaddrs. -As stated into the Listen Addresses section, Listen Addresses might get modified after libp2p transports get in action and use them to listen for new connections. This way, libp2p should also take into account these changes so that they can be matched when No Announce Addresses are being filtered out for advertising addresses. +As stated in the Listen Addresses section, Listen Addresses might be modified by libp2p transports after the successfully bind to those addresses. Libp2p should also take these changes into account so that they can be matched when No Announce Addresses are being filtered out of the advertised multiaddrs. ## Implementation -When a libp2p node is created, the Address Manager will be populated from the provided addresses through the libp2p configuration. Once the node is started, the Transport Manager component will gather the listen addresses from the Address Manager, so that the libp2p transports use them to listen on. +When a libp2p node is created, the Address Manager will be populated from the provided addresses through the libp2p configuration. Once the node is started, the Transport Manager component will gather the listen addresses from the Address Manager, so that the libp2p transports can attempt to bind to them. Libp2p will use the the Address Manager as the source of truth when advertising the peers addresses. After all transports are ready, other libp2p components/subsystems will kickoff, namely the Identify Service and the DHT. Both of them will announce the node addresses to the other peers in the network. The announce and noAnnounce addresses will have an important role here and will be gathered by libp2p to compute its current addresses to advertise everytime it is needed. @@ -40,7 +40,7 @@ In a future iteration, we can enable these addresses to be modified in runtime. #### Modify Listen Addresses -While adding new addresses to listen on runtime is a feasible operation, removing one listen address might have bad implications for the node, since all the connections using that listen address will be closed. With this in mind and taking also into consideration the lack of good use cases for removing listen addresses, the Address Manager API only allows libp2p users to add new Listen Addresses on runtime. +While adding new addresses to listen on runtime should be trivial, removing a listen address might have bad implications for the node, since all the connections using that listen address will be closed. However, libp2p should provide a mechanism for both adding and removing listen addresses in the future. Every time a new listen address is added, the Address Manager should emit an event with the new multiaddrs to listen. The Transport Manager should listen to this events and act accordingly. diff --git a/src/address-manager/index.js b/src/address-manager/index.js index 972f6fb2..e1527936 100644 --- a/src/address-manager/index.js +++ b/src/address-manager/index.js @@ -7,7 +7,7 @@ log.error = debug('libp2p:addresses:error') const multiaddr = require('multiaddr') /** - * Responsible for managing the peer addresses. + * Responsible for managing this peers addresses. * Peers can specify their listen, announce and noAnnounce addresses. * The listen addresses will be used by the libp2p transports to listen for new connections, * while the announce an noAnnounce addresses will be combined with the listen addresses for @@ -31,7 +31,7 @@ class AddressManager { * Get peer listen multiaddrs. * @return {Array} */ - getListenMultiaddrs () { + getListenAddrs () { return Array.from(this.listen).map((a) => multiaddr(a)) } @@ -39,7 +39,7 @@ class AddressManager { * Get peer announcing multiaddrs. * @return {Array} */ - getAnnounceMultiaddrs () { + getAnnounceAddrs () { return Array.from(this.announce).map((a) => multiaddr(a)) } @@ -47,7 +47,7 @@ class AddressManager { * Get peer noAnnouncing multiaddrs. * @return {Array} */ - getNoAnnounceMultiaddrs () { + getNoAnnounceAddrs () { return Array.from(this.noAnnounce).map((a) => multiaddr(a)) } } diff --git a/src/circuit/index.js b/src/circuit/index.js index 637f5f86..0e7c9fe3 100644 --- a/src/circuit/index.js +++ b/src/circuit/index.js @@ -122,7 +122,7 @@ class Circuit { type: CircuitPB.Type.HOP, srcPeer: { id: this.peerId.toBytes(), - addrs: this.addressManager.getListenMultiaddrs().map(addr => addr.buffer) + addrs: this.addressManager.getListenAddrs().map(addr => addr.buffer) }, dstPeer: { id: destinationPeer.toBytes(), diff --git a/src/identify/index.js b/src/identify/index.js index 701587a0..392f2c38 100644 --- a/src/identify/index.js +++ b/src/identify/index.js @@ -49,16 +49,16 @@ class IdentifyService { * @param {Libp2p} options.libp2p * @param {Map} options.protocols A reference to the protocols we support */ - constructor (options) { + constructor ({ libp2p, protocols }) { /** * @property {PeerStore} */ - this.peerStore = options.libp2p.peerStore + this.peerStore = libp2p.peerStore /** * @property {ConnectionManager} */ - this.connectionManager = options.libp2p.connectionManager + this.connectionManager = libp2p.connectionManager this.connectionManager.on('peer:connect', (connection) => { const peerId = connection.remotePeer @@ -69,14 +69,14 @@ class IdentifyService { /** * @property {PeerId} */ - this.peerId = options.libp2p.peerId + this.peerId = libp2p.peerId /** * @property {AddressManager} */ - this._libp2p = options.libp2p + this._libp2p = libp2p - this._protocols = options.protocols + this._protocols = protocols this.handleMessage = this.handleMessage.bind(this) } @@ -93,7 +93,7 @@ class IdentifyService { await pipe( [{ - listenAddrs: this._libp2p.getAdvertisingMultiaddrs().map((ma) => ma.buffer), + listenAddrs: this._libp2p.multiaddrs.map((ma) => ma.buffer), protocols: Array.from(this._protocols.keys()) }], pb.encode(Message), @@ -218,7 +218,7 @@ class IdentifyService { protocolVersion: PROTOCOL_VERSION, agentVersion: AGENT_VERSION, publicKey, - listenAddrs: this._libp2p.getAdvertisingMultiaddrs().map((ma) => ma.buffer), + listenAddrs: this._libp2p.multiaddrs.map((ma) => ma.buffer), observedAddr: connection.remoteAddr.buffer, protocols: Array.from(this._protocols.keys()) }) diff --git a/src/index.js b/src/index.js index d02e0d5b..19e383ca 100644 --- a/src/index.js +++ b/src/index.js @@ -300,25 +300,15 @@ class Libp2p extends EventEmitter { * Get peer advertising multiaddrs by concating the addresses used * by transports to listen with the announce addresses. * Duplicated addresses and noAnnounce addresses are filtered out. - * This takes into account random ports on matching noAnnounce addresses. * @return {Array} */ - getAdvertisingMultiaddrs () { + get multiaddrs () { // Filter noAnnounce multiaddrs - const filterMa = this.addressManager.getNoAnnounceMultiaddrs() - - // Special filter for noAnnounce addresses using a random port - // eg /ip4/0.0.0.0/tcp/0 => /ip4/192.168.1.0/tcp/58751 - const filterSpecial = filterMa - .map((ma) => ({ - protos: ma.protos(), - ...ma.toOptions() - })) - .filter((op) => op.port === 0) + const filterMa = this.addressManager.getNoAnnounceAddrs() // Create advertising list return this.transportManager.getAddrs() - .concat(this.addressManager.getAnnounceMultiaddrs()) + .concat(this.addressManager.getAnnounceAddrs()) .filter((ma, index, array) => { // Filter out if repeated if (array.findIndex((otherMa) => otherMa.equals(ma)) !== index) { @@ -330,16 +320,6 @@ class Libp2p extends EventEmitter { return false } - // Filter out if in the special filter - const options = ma.toOptions() - if (filterSpecial.find((op) => - op.family === options.family && - op.host === options.host && - op.transport === options.transport && - op.protos.length === ma.protos().length - )) { - return false - } return true }) } diff --git a/src/transport-manager.js b/src/transport-manager.js index 7bb751f6..b1994938 100644 --- a/src/transport-manager.js +++ b/src/transport-manager.js @@ -131,7 +131,7 @@ class TransportManager { * @async */ async listen () { - const addrs = this.libp2p.addressManager.getListenMultiaddrs() + const addrs = this.libp2p.addressManager.getListenAddrs() if (addrs.length === 0) { log('no addresses were provided for listening, this node is dial only') diff --git a/test/addresses/address-manager.spec.js b/test/addresses/address-manager.spec.js index 4ac35f79..3e0d0efd 100644 --- a/test/addresses/address-manager.spec.js +++ b/test/addresses/address-manager.spec.js @@ -32,7 +32,7 @@ describe('Address Manager', () => { expect(am.announce.size).to.equal(0) expect(am.noAnnounce.size).to.equal(0) - const listenMultiaddrs = am.getListenMultiaddrs() + const listenMultiaddrs = am.getListenAddrs() expect(listenMultiaddrs.length).to.equal(2) expect(listenMultiaddrs[0].equals(multiaddr(listenAddresses[0]))).to.equal(true) expect(listenMultiaddrs[1].equals(multiaddr(listenAddresses[1]))).to.equal(true) @@ -48,7 +48,7 @@ describe('Address Manager', () => { expect(am.announce.size).to.equal(announceAddreses.length) expect(am.noAnnounce.size).to.equal(0) - const announceMultiaddrs = am.getAnnounceMultiaddrs() + const announceMultiaddrs = am.getAnnounceAddrs() expect(announceMultiaddrs.length).to.equal(1) expect(announceMultiaddrs[0].equals(multiaddr(announceAddreses[0]))).to.equal(true) }) @@ -63,7 +63,7 @@ describe('Address Manager', () => { expect(am.announce.size).to.equal(0) expect(am.noAnnounce.size).to.equal(listenAddresses.length) - const noAnnounceMultiaddrs = am.getNoAnnounceMultiaddrs() + const noAnnounceMultiaddrs = am.getNoAnnounceAddrs() expect(noAnnounceMultiaddrs.length).to.equal(2) expect(noAnnounceMultiaddrs[0].equals(multiaddr(listenAddresses[0]))).to.equal(true) expect(noAnnounceMultiaddrs[1].equals(multiaddr(listenAddresses[1]))).to.equal(true) diff --git a/test/addresses/addresses.node.js b/test/addresses/addresses.node.js index 0526d388..8993fe1c 100644 --- a/test/addresses/addresses.node.js +++ b/test/addresses/addresses.node.js @@ -13,7 +13,7 @@ const peerUtils = require('../utils/creators/peer') const listenAddresses = ['/ip4/127.0.0.1/tcp/0', '/ip4/127.0.0.1/tcp/8000/ws'] const announceAddreses = ['/dns4/peer.io'] -describe('libp2p.getAdvertisingMultiaddrs', () => { +describe('libp2p.multiaddrs', () => { let libp2p afterEach(() => libp2p && libp2p.stop()) @@ -58,12 +58,12 @@ describe('libp2p.getAdvertisingMultiaddrs', () => { const tmListen = libp2p.transportManager.getAddrs().map((ma) => ma.toString()) - const spyAnnounce = sinon.spy(libp2p.addressManager, 'getAnnounceMultiaddrs') - const spyNoAnnounce = sinon.spy(libp2p.addressManager, 'getNoAnnounceMultiaddrs') - const spyListen = sinon.spy(libp2p.addressManager, 'getListenMultiaddrs') + const spyAnnounce = sinon.spy(libp2p.addressManager, 'getAnnounceAddrs') + const spyNoAnnounce = sinon.spy(libp2p.addressManager, 'getNoAnnounceAddrs') + const spyListen = sinon.spy(libp2p.addressManager, 'getListenAddrs') const spyTranspMgr = sinon.spy(libp2p.transportManager, 'getAddrs') - const advertiseMultiaddrs = libp2p.getAdvertisingMultiaddrs().map((ma) => ma.toString()) + const advertiseMultiaddrs = libp2p.multiaddrs.map((ma) => ma.toString()) expect(spyAnnounce).to.have.property('callCount', 1) expect(spyNoAnnounce).to.have.property('callCount', 1) @@ -92,7 +92,7 @@ describe('libp2p.getAdvertisingMultiaddrs', () => { } }) - const advertiseMultiaddrs = libp2p.getAdvertisingMultiaddrs().map((ma) => ma.toString()) + const advertiseMultiaddrs = libp2p.multiaddrs.map((ma) => ma.toString()) // Announce 2 listen (transport), ignoring duplicated in announce expect(advertiseMultiaddrs.length).to.equal(2) @@ -111,33 +111,7 @@ describe('libp2p.getAdvertisingMultiaddrs', () => { } }) - const advertiseMultiaddrs = libp2p.getAdvertisingMultiaddrs().map((ma) => ma.toString()) - - // Announce 1 listen (transport) not in the noAnnounce and the announce - expect(advertiseMultiaddrs.length).to.equal(2) - - announceAddreses.forEach((m) => { - expect(advertiseMultiaddrs).to.include(m) - }) - noAnnounce.forEach((m) => { - expect(advertiseMultiaddrs).to.not.include(m) - }) - }) - - it('should not advertise noAnnounce addresses with random port switch', async () => { - const noAnnounce = [listenAddresses[0]] - ;[libp2p] = await peerUtils.createPeer({ - config: { - ...AddressesOptions, - addresses: { - listen: listenAddresses, - announce: announceAddreses, - noAnnounce - } - } - }) - - const advertiseMultiaddrs = libp2p.getAdvertisingMultiaddrs().map((ma) => ma.toString()) + const advertiseMultiaddrs = libp2p.multiaddrs.map((ma) => ma.toString()) // Announce 1 listen (transport) not in the noAnnounce and the announce expect(advertiseMultiaddrs.length).to.equal(2) diff --git a/test/core/ping.node.js b/test/core/ping.node.js index 99e57d60..439fac74 100644 --- a/test/core/ping.node.js +++ b/test/core/ping.node.js @@ -21,8 +21,8 @@ describe('ping', () => { config: baseOptions }) - nodes[0].peerStore.addressBook.set(nodes[1].peerId, nodes[1].getAdvertisingMultiaddrs()) - nodes[1].peerStore.addressBook.set(nodes[0].peerId, nodes[0].getAdvertisingMultiaddrs()) + nodes[0].peerStore.addressBook.set(nodes[1].peerId, nodes[1].multiaddrs) + nodes[1].peerStore.addressBook.set(nodes[0].peerId, nodes[0].multiaddrs) }) it('ping once from peer0 to peer1', async () => { diff --git a/test/dialing/direct.node.js b/test/dialing/direct.node.js index 7b6cd9f6..bb93d94b 100644 --- a/test/dialing/direct.node.js +++ b/test/dialing/direct.node.js @@ -282,7 +282,7 @@ describe('Dialing (direct, TCP)', () => { }) sinon.spy(libp2p.dialer, 'connectToPeer') - libp2p.peerStore.addressBook.set(remotePeerId, remoteLibp2p.getAdvertisingMultiaddrs()) + libp2p.peerStore.addressBook.set(remotePeerId, remoteLibp2p.multiaddrs) const connection = await libp2p.dial(remotePeerId) expect(connection).to.exist() @@ -364,7 +364,7 @@ describe('Dialing (direct, TCP)', () => { const fullAddress = remoteAddr.encapsulate(`/p2p/${remoteLibp2p.peerId.toB58String()}`) - libp2p.peerStore.addressBook.set(remotePeerId, remoteLibp2p.getAdvertisingMultiaddrs()) + libp2p.peerStore.addressBook.set(remotePeerId, remoteLibp2p.multiaddrs) const dialResults = await Promise.all([...new Array(dials)].map((_, index) => { if (index % 2 === 0) return libp2p.dial(remoteLibp2p.peerId) return libp2p.dial(fullAddress) @@ -394,7 +394,7 @@ describe('Dialing (direct, TCP)', () => { const error = new Error('Boom') sinon.stub(libp2p.transportManager, 'dial').callsFake(() => Promise.reject(error)) - libp2p.peerStore.addressBook.set(remotePeerId, remoteLibp2p.getAdvertisingMultiaddrs()) + libp2p.peerStore.addressBook.set(remotePeerId, remoteLibp2p.multiaddrs) const dialResults = await pSettle([...new Array(dials)].map((_, index) => { if (index % 2 === 0) return libp2p.dial(remoteLibp2p.peerId) return libp2p.dial(remoteAddr) diff --git a/test/dialing/relay.node.js b/test/dialing/relay.node.js index 74e12c00..003bab4f 100644 --- a/test/dialing/relay.node.js +++ b/test/dialing/relay.node.js @@ -155,13 +155,13 @@ describe('Dialing (via relay, TCP)', () => { // Connect the destination peer and the relay const tcpAddrs = dstLibp2p.transportManager.getAddrs() - sinon.stub(dstLibp2p.addressManager, 'getListenMultiaddrs').returns([multiaddr(`${relayAddr}/p2p-circuit`)]) + sinon.stub(dstLibp2p.addressManager, 'getListenAddrs').returns([multiaddr(`${relayAddr}/p2p-circuit`)]) await dstLibp2p.transportManager.listen() 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, 'getListenMultiaddrs').returns([{ + sinon.stub(srcLibp2p.addressManager, 'getListenAddrs').returns([{ buffer: Buffer.from('an invalid multiaddr') }]) diff --git a/test/identify/index.spec.js b/test/identify/index.spec.js index b0db6675..9ca892ff 100644 --- a/test/identify/index.spec.js +++ b/test/identify/index.spec.js @@ -55,7 +55,7 @@ describe('Identify', () => { set: () => { } } }, - getAdvertisingMultiaddrs: () => [] + multiaddrs: [] }, protocols }) @@ -63,7 +63,7 @@ describe('Identify', () => { libp2p: { peerId: remotePeer, connectionManager: new EventEmitter(), - getAdvertisingMultiaddrs: () => [] + multiaddrs: [] }, protocols }) @@ -108,7 +108,7 @@ describe('Identify', () => { set: () => { } } }, - getAdvertisingMultiaddrs: () => [] + multiaddrs: [] }, protocols }) @@ -116,7 +116,7 @@ describe('Identify', () => { libp2p: { peerId: remotePeer, connectionManager: new EventEmitter(), - getAdvertisingMultiaddrs: () => [] + multiaddrs: [] }, protocols }) @@ -153,7 +153,7 @@ describe('Identify', () => { libp2p: { peerId: localPeer, connectionManager: new EventEmitter(), - getAdvertisingMultiaddrs: () => [listeningAddr] + multiaddrs: [listeningAddr] }, protocols: new Map([ [multicodecs.IDENTIFY], @@ -173,7 +173,7 @@ describe('Identify', () => { set: () => { } } }, - getAdvertisingMultiaddrs: () => [] + multiaddrs: [] } }) diff --git a/test/peer-discovery/index.node.js b/test/peer-discovery/index.node.js index 81d7309b..4d28e23c 100644 --- a/test/peer-discovery/index.node.js +++ b/test/peer-discovery/index.node.js @@ -193,8 +193,8 @@ describe('peer discovery scenarios', () => { remoteLibp2p2.start() ]) - libp2p.peerStore.addressBook.set(remotePeerId1, remoteLibp2p1.getAdvertisingMultiaddrs()) - remoteLibp2p2.peerStore.addressBook.set(remotePeerId1, remoteLibp2p1.getAdvertisingMultiaddrs()) + libp2p.peerStore.addressBook.set(remotePeerId1, remoteLibp2p1.multiaddrs) + remoteLibp2p2.peerStore.addressBook.set(remotePeerId1, remoteLibp2p1.multiaddrs) // Topology: // A -> B diff --git a/test/pubsub/implementations.node.js b/test/pubsub/implementations.node.js index 49310358..7ce32c0a 100644 --- a/test/pubsub/implementations.node.js +++ b/test/pubsub/implementations.node.js @@ -75,7 +75,7 @@ describe('Pubsub subsystem is able to use different implementations', () => { ]) const libp2pId = libp2p.peerId.toB58String() - libp2p.peerStore.addressBook.set(remotePeerId, remoteLibp2p.getAdvertisingMultiaddrs()) + libp2p.peerStore.addressBook.set(remotePeerId, remoteLibp2p.multiaddrs) const connection = await libp2p.dialProtocol(remotePeerId, multicodec) expect(connection).to.exist() diff --git a/test/pubsub/operation.node.js b/test/pubsub/operation.node.js index 02cf24ea..a29ac953 100644 --- a/test/pubsub/operation.node.js +++ b/test/pubsub/operation.node.js @@ -47,7 +47,7 @@ describe('Pubsub subsystem operates correctly', () => { remoteLibp2p.start() ]) - libp2p.peerStore.addressBook.set(remotePeerId, remoteLibp2p.getAdvertisingMultiaddrs()) + libp2p.peerStore.addressBook.set(remotePeerId, remoteLibp2p.multiaddrs) }) afterEach(() => Promise.all([ @@ -124,7 +124,7 @@ describe('Pubsub subsystem operates correctly', () => { await libp2p.start() await remoteLibp2p.start() - libp2p.peerStore.addressBook.set(remotePeerId, remoteLibp2p.getAdvertisingMultiaddrs()) + libp2p.peerStore.addressBook.set(remotePeerId, remoteLibp2p.multiaddrs) }) afterEach(() => Promise.all([ diff --git a/test/utils/creators/peer.js b/test/utils/creators/peer.js index db0026f4..6e4a5865 100644 --- a/test/utils/creators/peer.js +++ b/test/utils/creators/peer.js @@ -45,7 +45,7 @@ function _populateAddressBooks (peers) { for (let i = 0; i < peers.length; i++) { for (let j = 0; j < peers.length; j++) { if (i !== j) { - peers[i].peerStore.addressBook.set(peers[j].peerId, peers[j].getAdvertisingMultiaddrs()) + peers[i].peerStore.addressBook.set(peers[j].peerId, peers[j].multiaddrs) } } }