fix: add self to connect skip_list when selecting forwarding targets #2146
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.
Problem
PR #2140 added a defense-in-depth guard in
should_accept()to reject self-connections. However, as Nacho pointed out in review feedback, the root fix should happen earlier: when a gateway picks candidates to forward a connect request, it should never even consider itself as a target.The issue was that
select_next_hop()used a skip list built only from thevisitedpeers in the incoming request. If for any reasonselfwasn't properly added tovisitedby upstream callers, the node could select itself as a forwarding target.This Solution
Introduce
SkipListWithSelf, a skip list that explicitly combines visited peers with the current node's own peer ID. This ensures:should_accept()guard from fix: add self-connection guard in should_accept() #2140 remains as defense-in-depthThe key insight is that excluding self should not depend on upstream callers correctly populating the visited list - it should be a hard guarantee at the point where we select candidates.
Changes
VisitedPeerIdswithSkipListWithSelfinselect_next_hop()SkipListWithSelfchecks both&target == self.self_peerAND the visited listTesting
skip_list_with_self_excludes_self_and_visitedtestAddresses
Feedback from @iduartgomez on https://github.com/freenet/freenet-core/pull/2140/files#r2559449449
[AI-assisted - Claude]