Skip to content

Commit 7da9ad4

Browse files
authored
fix: create dial target for peer with no known addrs (#715)
1 parent 3896941 commit 7da9ad4

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/dialer/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class Dialer {
112112
this.peerStore.addressBook.add(id, multiaddrs)
113113
}
114114

115-
let addrs = this.peerStore.addressBook.getMultiaddrsForPeer(id)
115+
let addrs = this.peerStore.addressBook.getMultiaddrsForPeer(id) || []
116116

117117
// If received a multiaddr to dial, it should be the first to use
118118
// But, if we know other multiaddrs for the peer, we should try them too.

test/dialing/direct.node.js

+9
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ describe('Dialing (direct, TCP)', () => {
9696
.and.to.have.nested.property('._errors[0].code', ErrorCodes.ERR_TRANSPORT_UNAVAILABLE)
9797
})
9898

99+
it('should fail to connect if peer has no known addresses', async () => {
100+
const dialer = new Dialer({ transportManager: localTM, peerStore })
101+
const peerId = await PeerId.createFromJSON(Peers[1])
102+
103+
await expect(dialer.connectToPeer(peerId))
104+
.to.eventually.be.rejectedWith(Error)
105+
.and.to.have.nested.property('.code', ErrorCodes.ERR_NO_VALID_ADDRESSES)
106+
})
107+
99108
it('should be able to connect to a given peer id', async () => {
100109
const peerStore = new PeerStore()
101110
const dialer = new Dialer({

0 commit comments

Comments
 (0)