mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-03-16 15:40:49 +00:00
fix: bail when discovering self (#357)
This commit is contained in:
parent
c049074cb5
commit
f28dffb268
@ -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
|
||||
|
@ -259,6 +259,33 @@ describe('peer discovery', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('discovery scenarios', () => {
|
||||
setup({
|
||||
config: {
|
||||
dht: {
|
||||
enabled: false
|
||||
},
|
||||
peerDiscovery: {
|
||||
autoDial: false,
|
||||
bootstrap: {
|
||||
enabled: true,
|
||||
list: []
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
it('should ignore self on discovery', function () {
|
||||
const discoverySpy = sinon.spy()
|
||||
nodeA.on('peer:discovery', discoverySpy)
|
||||
nodeA._discovery[0].emit('peer', nodeA.peerInfo)
|
||||
|
||||
expect(discoverySpy.called).to.eql(false)
|
||||
expect(nodeA.peerBook.getAllArray()).to.have.length(0)
|
||||
expect()
|
||||
})
|
||||
})
|
||||
|
||||
describe('MulticastDNS', () => {
|
||||
setup({
|
||||
config: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user