mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-04-25 10:32:14 +00:00
fix: peerRouting.findPeer() trying to find self (#941)
* throw error if node attempts to find itself Co-authored-by: Vasco Santos <vasco.santos@ua.pt>
This commit is contained in:
parent
d372a68692
commit
a79c6b50d7
@ -104,6 +104,10 @@ class PeerRouting {
|
||||
throw errCode(new Error('No peer routers available'), 'NO_ROUTERS_AVAILABLE')
|
||||
}
|
||||
|
||||
if (id.toB58String() === this._peerId.toB58String()) {
|
||||
throw errCode(new Error('Should not try to find self'), 'ERR_FIND_SELF')
|
||||
}
|
||||
|
||||
const output = await pipe(
|
||||
merge(
|
||||
...this._routers.map(router => [router.findPeer(id, options)])
|
||||
|
@ -100,6 +100,12 @@ describe('peer-routing', () => {
|
||||
|
||||
return deferred.promise
|
||||
})
|
||||
|
||||
it('should error when peer tries to find itself', async () => {
|
||||
await expect(nodes[0].peerRouting.findPeer(nodes[0].peerId))
|
||||
.to.eventually.be.rejected()
|
||||
.and.to.have.property('code', 'ERR_FIND_SELF')
|
||||
})
|
||||
})
|
||||
|
||||
describe('via delegate router', () => {
|
||||
@ -187,6 +193,12 @@ describe('peer-routing', () => {
|
||||
expect(mockApi.isDone()).to.equal(true)
|
||||
})
|
||||
|
||||
it('should error when peer tries to find itself', async () => {
|
||||
await expect(node.peerRouting.findPeer(node.peerId))
|
||||
.to.eventually.be.rejected()
|
||||
.and.to.have.property('code', 'ERR_FIND_SELF')
|
||||
})
|
||||
|
||||
it('should error when a peer cannot be found', async () => {
|
||||
const peerKey = 'key of a peer not on the network'
|
||||
const mockApi = nock('http://0.0.0.0:60197')
|
||||
|
Loading…
x
Reference in New Issue
Block a user