fix: look for final peer event instead of peer response (#1092)

`FINAL_PEER` means we found the peer, `PEER_RESPONSE` means a peer
responded to our query.
This commit is contained in:
Alex Potsides 2021-12-29 10:56:56 +01:00 committed by GitHub
parent 79b3cfc6ad
commit d2b7ec0f6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
}
}