Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return closest peers from FIND_NODE #2499

Merged
merged 3 commits into from
Apr 24, 2024

Conversation

achingbrain
Copy link
Member

The FIND_NODE DHT operation should return the closest peers the node knows to the value.

It does not need to return itself in the list because the calling peer already knows about it.

Fixes #2450

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if necessary (this includes comments as well)
  • I have added tests that prove my fix is effective or that my feature works

The `FIND_NODE` DHT operation should return the closest peers the
node knows to the value.

It does not need to return itself in the list because the calling
peer already knows about it.

Fixes #2450
@achingbrain achingbrain requested a review from a team as a code owner April 23, 2024 11:56
@guillaumemichel
Copy link

Looks good, thanks @achingbrain !

Copy link
Member

@maschad maschad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, left some comments in line

packages/kad-dht/test/rpc/handlers/find-node.spec.ts Outdated Show resolved Hide resolved
@@ -799,6 +799,37 @@ describe('KadDHT', () => {

expect(res).to.not.be.empty()
})

it('should not include itself in getClosestPeers PEER_RESPONSE', async function () {
this.timeout(240 * 1000)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, why are we using a 240 second timeout?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No specific reason, it was copied from the preceding test.

@achingbrain achingbrain merged commit 0d55966 into main Apr 24, 2024
22 checks passed
@achingbrain achingbrain deleted the fix/return-multiple-peers-from-find-node branch April 24, 2024 08:09
@achingbrain achingbrain mentioned this pull request Apr 24, 2024
achingbrain added a commit that referenced this pull request Apr 29, 2024
Partial revert of #2499

If a node is queried for it's own peer id, return it's own peer
info.

This is necessary because since libp2p/go-libp2p-kad-dht#820
go-libp2p-kad-dht won't add a peer to it's routing tables that
doesn't have any DHT peers that are KAD-futher from it's own ID
already.
achingbrain added a commit that referenced this pull request Apr 29, 2024
Partial revert of #2499

If a node is queried for it's own peer id, return it's own peer
info.

This is necessary because since libp2p/go-libp2p-kad-dht#820
go-libp2p-kad-dht won't add a peer to it's routing tables that
doesn't have any DHT peers that are KAD-futher from it's own ID
already.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kad: FIND_NODE(self) should return multiple peers
3 participants