mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-26 23:41:34 +00:00
chore: remove noAnnounce from address manager
This commit is contained in:
committed by
Vasco Santos
parent
ef9d3ca2c6
commit
5758db8ea9
@ -7,11 +7,10 @@ log.error = debug('libp2p:addresses:error')
|
||||
const multiaddr = require('multiaddr')
|
||||
|
||||
/**
|
||||
* Responsible for managing this peers addresses.
|
||||
* Peers can specify their listen, announce and noAnnounce addresses.
|
||||
* Responsible for managing the peer addresses.
|
||||
* Peers can specify their listen and announce 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
|
||||
* address adverstising to other peers in the network.
|
||||
* while the announce addresses will be used for the peer addresses' to other peers in the network.
|
||||
*/
|
||||
class AddressManager {
|
||||
/**
|
||||
@ -19,12 +18,10 @@ class AddressManager {
|
||||
* @param {object} [options]
|
||||
* @param {Array<string>} [options.listen = []] - list of multiaddrs string representation to listen.
|
||||
* @param {Array<string>} [options.announce = []] - list of multiaddrs string representation to announce.
|
||||
* @param {Array<string>} [options.noAnnounce = []] - list of multiaddrs string representation to not announce.
|
||||
*/
|
||||
constructor ({ listen = [], announce = [], noAnnounce = [] } = {}) {
|
||||
constructor ({ listen = [], announce = [] } = {}) {
|
||||
this.listen = new Set(listen)
|
||||
this.announce = new Set(announce)
|
||||
this.noAnnounce = new Set(noAnnounce)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -44,15 +41,6 @@ class AddressManager {
|
||||
getAnnounceAddrs () {
|
||||
return Array.from(this.announce).map((a) => multiaddr(a))
|
||||
}
|
||||
|
||||
/**
|
||||
* Get peer noAnnouncing multiaddrs.
|
||||
*
|
||||
* @returns {Array<Multiaddr>}
|
||||
*/
|
||||
getNoAnnounceAddrs () {
|
||||
return Array.from(this.noAnnounce).map((a) => multiaddr(a))
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AddressManager
|
||||
|
24
src/index.js
24
src/index.js
@ -367,27 +367,15 @@ class Libp2p extends EventEmitter {
|
||||
* @returns {Array<Multiaddr>}
|
||||
*/
|
||||
get multiaddrs () {
|
||||
const announceAddrs = this.addressManager.getAnnounceAddrs()
|
||||
if (announceAddrs.length) {
|
||||
return announceAddrs
|
||||
}
|
||||
|
||||
const announceFilter = this._options.addresses.announceFilter || ((multiaddrs) => multiaddrs)
|
||||
|
||||
// Filter noAnnounce multiaddrs
|
||||
const filterMa = this.addressManager.getNoAnnounceAddrs()
|
||||
|
||||
// Create advertising list
|
||||
return announceFilter(this.transportManager.getAddrs()
|
||||
.concat(this.addressManager.getAnnounceAddrs())
|
||||
.filter((ma, index, array) => {
|
||||
// Filter out if repeated
|
||||
if (array.findIndex((otherMa) => otherMa.equals(ma)) !== index) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Filter out if in noAnnounceMultiaddrs
|
||||
if (filterMa.find((fm) => fm.equals(ma))) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}))
|
||||
return announceFilter(this.transportManager.getAddrs())
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user