Skip to content

Commit

Permalink
fix: look for final peer event instead of peer response (#1092)
Browse files Browse the repository at this point in the history
`FINAL_PEER` means we found the peer, `PEER_RESPONSE` means a peer
responded to our query.
  • Loading branch information
achingbrain committed Dec 29, 2021
1 parent 79b3cfc commit d2b7ec0
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/dht/dht-peer-routing.js
Expand Up @@ -27,12 +27,8 @@ class DHTPeerRouting {
*/
async findPeer (peerId, options = {}) {
for await (const event of this._dht.findPeer(peerId, options)) {
if (event.name === 'PEER_RESPONSE') {
const peer = event.closer.find(peerData => peerData.id.equals(peerId))

if (peer) {
return peer
}
if (event.name === 'FINAL_PEER') {
return event.peer
}
}

Expand Down

0 comments on commit d2b7ec0

Please sign in to comment.