Kademlia inserts addresses even when requested not to
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 5.6k
- Forks
- 1.3k
- Avg merge
- 8h 47m
- Merged PRs (30d)
- 19
Description
There is BucketInserts enum in Kademlia that is supposed to control when to insert addresses of connected peers into k-buckets or not. If I'm reading it correctly, it only has effect if particular peer ID is not yet in k-buckets, however it if it already there, insertion configuration is ignored:
https://github.com/libp2p/rust-libp2p/blob/e151ecbbf5d2d8a663f6db4d88230469a0eab58f/protocols/kad/src/behaviour.rs#L1223-L1253
This looks like an oversight that will often result in observed ephemeral non-dialable (in the long run anyway) addresses from incoming connections being added to k-buckets and shared with other peers.
The solution here is to not insert an address in k-bucket unless BucketInserts::OnConnected is used (status should still be updated though).
P.S. I'm having a hard time putting such reports into pre-defined bug report template, hence writing it free-form instead.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read protocols/kad/src/behaviour.rs around the linked lines 1223-1253, focusing on how BucketInserts is applied when a peer ID is already in a k-bucket. Verify the behavior for each insertion mode and ensure the reported non-insertion case still updates status without adding the address; confirm the existing Kademlia tests, if present, cover this path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100