mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-24 14:31:35 +00:00
feat: append peer id to multiaddr if not there
This commit is contained in:
10
src/index.js
10
src/index.js
@ -3,6 +3,7 @@
|
||||
const Swarm = require('libp2p-swarm')
|
||||
const PeerId = require('peer-id')
|
||||
const PeerInfo = require('peer-info')
|
||||
const mafmt = require('mafmt')
|
||||
const PeerBook = require('peer-book')
|
||||
const multiaddr = require('multiaddr')
|
||||
const EventEmitter = require('events').EventEmitter
|
||||
@ -47,6 +48,8 @@ class Node extends EventEmitter {
|
||||
|
||||
this.swarm.on('peer-mux-closed', (peerInfo) => {
|
||||
this.emit('peer:disconnect', peerInfo)
|
||||
// TODO remove this line
|
||||
this.peerBook.removeByB58String(peerInfo.id.toB58String())
|
||||
})
|
||||
}
|
||||
|
||||
@ -104,6 +107,13 @@ class Node extends EventEmitter {
|
||||
}
|
||||
})
|
||||
|
||||
// so that we can have webrtc-star addrs without adding manually the id
|
||||
this.peerInfo.multiaddrs = this.peerInfo.multiaddrs.map((ma) => {
|
||||
if (!mafmt.IPFS.matches(ma)) {
|
||||
ma = ma.encapsulate('/ipfs/' + this.peerInfo.id.toB58String())
|
||||
}
|
||||
})
|
||||
|
||||
this.swarm.listen((err) => {
|
||||
if (err) {
|
||||
return callback(err)
|
||||
|
Reference in New Issue
Block a user