Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function isPeerMultiaddr (input) {
if (!isMultiaddr(input)) return false
if (input instanceof Buffer) {
// mafmt does not support Buffer input
input = new Multiaddr(input)
}
return mafmt.IPFS.matches(input)
}
addrs.forEach((addr) => {
const peerMa = `/p2p-circuit/ipfs/${swarm._peerInfo.id.toB58String()}`
if (addr.toString() === peerMa) {
listenAddrs.push(multiaddr(peerMa))
return
}
if (!mafmt.Circuit.matches(addr)) {
if (addr.getPeerId()) {
// by default we're reachable over any relay
listenAddrs.push(multiaddr('/p2p-circuit').encapsulate(addr))
} else {
const ma = `${addr}/ipfs/${swarm._peerInfo.id.toB58String()}`
listenAddrs.push(multiaddr('/p2p-circuit').encapsulate(ma))
}
} else {
listenAddrs.push(addr.encapsulate(`/ipfs/${swarm._peerInfo.id.toB58String()}`))
}
})
r.once('peer', (peer) => {
const peerList = peer.multiaddrs.toArray()
expect(peerList.length).to.eq(1)
expect(mafmt.IPFS.matches(peerList[0].toString())).equals(true)
resolve()
})
})
this._list.forEach(async (candidate) => {
if (!mafmt.P2P.matches(candidate)) {
return log.error('Invalid multiaddr')
}
const ma = multiaddr(candidate)
const peerId = PeerId.createFromB58String(ma.getPeerId())
try {
const peerInfo = await PeerInfo.create(peerId)
peerInfo.multiaddrs.add(ma)
this.emit('peer', peerInfo)
} catch (err) {
log.error('Invalid bootstrap peer id', err)
}
})
}
result.forEach((item) => {
let ma = multiaddr(item.addr.toString())
if (!mafmt.IPFS.matches(ma)) {
ma = ma.encapsulate('/ipfs/' + item.peer.toB58String())
}
const addr = ma.toString()
argv.print(addr)
})
})())
'use strict'
const defaultConfig = require('../runtime/config-nodejs.js')
const isMultiaddr = require('mafmt').IPFS.matches
const callbackify = require('callbackify')
function isValidMultiaddr (ma) {
try {
return isMultiaddr(ma)
} catch (err) {
return false
}
}
function invalidMultiaddrError (ma) {
return new Error(`${ma} is not a valid Multiaddr`)
}
module.exports = function bootstrap (self) {
return {
'multiaddr-ipfs': v => mafmt.IPFS.matches(v) ? true : 'multiaddr IPFS invalid'
}
return multiaddrs.filter((ma) => {
return mafmt.Circuit.matches(ma)
})
}
const p2pAddrs = addrs.filter((addr) => {
return mafmt.Circuit.matches(addr) &&
!addr.toString().includes(swarm._peerInfo.id.toB58String())
})
return multiaddrs.filter((ma) => {
return mafmt.WebRTCStar.matches(ma)
})
}