mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-04-30 04:52:14 +00:00
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:
parent
79b3cfc6ad
commit
d2b7ec0f6b
@ -27,12 +27,8 @@ class DHTPeerRouting {
|
|||||||
*/
|
*/
|
||||||
async findPeer (peerId, options = {}) {
|
async findPeer (peerId, options = {}) {
|
||||||
for await (const event of this._dht.findPeer(peerId, options)) {
|
for await (const event of this._dht.findPeer(peerId, options)) {
|
||||||
if (event.name === 'PEER_RESPONSE') {
|
if (event.name === 'FINAL_PEER') {
|
||||||
const peer = event.closer.find(peerData => peerData.id.equals(peerId))
|
return event.peer
|
||||||
|
|
||||||
if (peer) {
|
|
||||||
return peer
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user