Skip to content

Commit

Permalink
fix: create dial target for peer with no known addrs (#715)
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos authored Jul 20, 2020
1 parent 3896941 commit 7da9ad4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/dialer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions test/dialing/direct.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 7da9ad4

Please sign in to comment.