feat(kad): add Behaviour::get_record_from#6475
Draft
fully-autonomous wants to merge 1 commit into
Draft
Conversation
3c4cb34 to
1be9c70
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds
Behaviour::get_record_from(key, peers): a seededGETthat contacts only acaller-supplied peer set and never expands to peers discovered mid-walk. It is the
GETcounterpart of the existing
Behaviour::put_record_to— whereput_record_towrites to afixed peer set,
get_record_fromreads from one. The local store is consulted exactly as inget_record(a local hit is emitted immediately asGetRecordOk::FoundRecordwithpeer: None).Motivation: S/Kademlia §4.2 node-disjoint lookups require issuing
dindependent lookups, eachrestricted to a disjoint seed group, so the paths provably never converge on a shared
intermediate node.
get_recordalways seeds from the routing table and expands iteratively, sothis is not currently possible without forking the crate.
get_record_fromreuses the existingQueryPool::add_fixed/FixedPeersItermachinery that already backsput_record_to, whoseon_successnever folds in newly discovered peers — making theGETpinned by construction.Implementation mirrors
get_recordexactly, substitutingqueries.add_fixed(peers, info)foradd_iter_closest(...). The change is purely additive: no existing method, signature, or traitis changed, and
QueryPool::add_fixedremainspub(crate).AI Assistance Disclosure
Tools used (required — write
noneif no AI was used): Claude CodeAttestation (required):
Notes & open questions
Two integration tests were added in
protocols/kad/src/behaviour/test.rs, in the style of theexisting
get_record*tests:get_record_from_seeded_peer— seeding theGETwith a peer that holds the record returns it.get_record_from_does_not_expand_beyond_seeded_peers— the record lives on an un-seedednode that the querying node knows directly; seeding the
GETwith a different peer that lacksthe record yields
GetRecordError::NotFoundand never contacts the record-holder, proving thequery does not expand beyond the fixed set (the disjointness property the use case relies on).
Open question for maintainers: the changelog entry has been added under the unreleased
0.49.0section; happy to move it to a different version header if you prefer.
Change checklist