From 7da9ad44ab0b946198452f24a4614d5785ee85a2 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Mon, 20 Jul 2020 14:54:03 +0200 Subject: [PATCH] fix: create dial target for peer with no known addrs (#715) --- src/dialer/index.js | 2 +- test/dialing/direct.node.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/dialer/index.js b/src/dialer/index.js index 5e460ab3..bd43bd71 100644 --- a/src/dialer/index.js +++ b/src/dialer/index.js @@ -112,7 +112,7 @@ class Dialer { this.peerStore.addressBook.add(id, multiaddrs) } - let addrs = this.peerStore.addressBook.getMultiaddrsForPeer(id) + let addrs = this.peerStore.addressBook.getMultiaddrsForPeer(id) || [] // If received a multiaddr to dial, it should be the first to use // But, if we know other multiaddrs for the peer, we should try them too. diff --git a/test/dialing/direct.node.js b/test/dialing/direct.node.js index 536cf5ec..0d65e8ab 100644 --- a/test/dialing/direct.node.js +++ b/test/dialing/direct.node.js @@ -96,6 +96,15 @@ describe('Dialing (direct, TCP)', () => { .and.to.have.nested.property('._errors[0].code', ErrorCodes.ERR_TRANSPORT_UNAVAILABLE) }) + it('should fail to connect if peer has no known addresses', async () => { + const dialer = new Dialer({ transportManager: localTM, peerStore }) + const peerId = await PeerId.createFromJSON(Peers[1]) + + await expect(dialer.connectToPeer(peerId)) + .to.eventually.be.rejectedWith(Error) + .and.to.have.nested.property('.code', ErrorCodes.ERR_NO_VALID_ADDRESSES) + }) + it('should be able to connect to a given peer id', async () => { const peerStore = new PeerStore() const dialer = new Dialer({