mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-23 05:51:37 +00:00
fix: bail when discovering self (#357)
This commit is contained in:
@ -7,5 +7,7 @@ exports.messages = {
|
||||
|
||||
exports.codes = {
|
||||
DHT_DISABLED: 'ERR_DHT_DISABLED',
|
||||
PUBSUB_NOT_STARTED: 'ERR_PUBSUB_NOT_STARTED'
|
||||
PUBSUB_NOT_STARTED: 'ERR_PUBSUB_NOT_STARTED',
|
||||
ERR_NODE_NOT_STARTED: 'ERR_NODE_NOT_STARTED',
|
||||
ERR_DISCOVERED_SELF: 'ERR_DISCOVERED_SELF'
|
||||
}
|
||||
|
@ -24,11 +24,12 @@ const dht = require('./dht')
|
||||
const pubsub = require('./pubsub')
|
||||
const getPeerInfo = require('./get-peer-info')
|
||||
const validateConfig = require('./config').validate
|
||||
const { codes } = require('./errors')
|
||||
|
||||
const notStarted = (action, state) => {
|
||||
return errCode(
|
||||
new Error(`libp2p cannot ${action} when not started; state is ${state}`),
|
||||
'ERR_NODE_NOT_STARTED'
|
||||
codes.ERR_NODE_NOT_STARTED
|
||||
)
|
||||
}
|
||||
|
||||
@ -476,6 +477,10 @@ class Node extends EventEmitter {
|
||||
* @param {PeerInfo} peerInfo
|
||||
*/
|
||||
_peerDiscovered (peerInfo) {
|
||||
if (peerInfo.id.toB58String() === this.peerInfo.id.toB58String()) {
|
||||
log.error(new Error(codes.ERR_DISCOVERED_SELF))
|
||||
return
|
||||
}
|
||||
peerInfo = this.peerBook.put(peerInfo)
|
||||
|
||||
if (!this.isStarted()) return
|
||||
|
Reference in New Issue
Block a user