mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-03-16 15:40:49 +00:00
feat: append peer id to multiaddr if not there
This commit is contained in:
parent
300936f2f3
commit
59ea9c388f
@ -42,6 +42,7 @@
|
||||
"dependencies": {
|
||||
"libp2p-ping": "~0.3.2",
|
||||
"libp2p-swarm": "~0.28.0",
|
||||
"mafmt": "^2.1.8",
|
||||
"multiaddr": "^2.3.0",
|
||||
"peer-book": "~0.3.2",
|
||||
"peer-id": "~0.8.5",
|
||||
@ -54,4 +55,4 @@
|
||||
"greenkeeperio-bot <support@greenkeeper.io>",
|
||||
"mayerwin <mayerwin@users.noreply.github.com>"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user