-
-
Notifications
You must be signed in to change notification settings - Fork 107
fix: add self-connection guard in should_accept() #2140
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
Conversation
Prevents a node from accepting a connection request from itself, which can occur when a joiner connects to a gateway with no other peers and the connect request gets forwarded back to the joiner. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Claude finished @sanity's task —— View job PR Review: Self-Connection GuardI've completed my review of PR #2140 and the original issue #2139. Here's my comprehensive analysis: ✅ Overall Assessment: Approved with Minor NotesThe fix is correct and complete for the reported issue. The implementation is clean, well-tested, and placed in the optimal location. 🔍 Implementation ReviewGuard Logic ✅The guard is implemented correctly in // Don't accept connections from ourselves
if let Some(own_id) = self.get_peer_key() {
if &own_id == peer_id {
tracing::warn!(%peer_id, "should_accept: rejecting self-connection attempt");
return false;
}
}Strengths:
Existing SafeguardsThe codebase already has defense-in-depth at debug_assert!(self.get_peer_key().expect("should be set") != peer);This
🧪 Test CoverageTests Added ✅Two unit tests provide solid coverage:
Test Quality:
Edge Cases Covered
🔗 Related Code AnalysisI checked whether similar guards are needed elsewhere:
Conclusion: No additional guards needed. The fix at 📝 Code QualityPositive:
Minor Suggestions (non-blocking):
🎯 Issue ResolutionThe fix addresses the exact scenario from issue #2139:
Root Cause Correctly Identified: 🚀 Recommendation: MergeThis PR is ready to merge. The fix is:
References:
| |
| /// # Panic | ||
| /// Will panic if the node checking for this condition has no location assigned. | ||
| pub fn should_accept(&self, location: Location, peer_id: &PeerId) -> bool { | ||
| // Don't accept connections from ourselves |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this fix is ok, but the main issue is that we are not adding self to the skip_list of connect so it wont be a possible target at all in the gateway, we should look into that
When selecting forwarding targets for connect requests, explicitly exclude ourselves from candidates using SkipListWithSelf. This ensures a node never selects itself as a forwarding target, even if self wasn't properly added to the visited list by upstream callers. This complements the defense-in-depth guard added in PR #2140 which rejects self-connections in should_accept(). Now we prevent self from being a candidate in the first place. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Problem
When a joiner connects to a gateway that has no other peers, the connect request can be forwarded back to the joiner itself. Without a guard, the joiner would accept this connection to itself, causing a self-connection.
This scenario occurs during early network bootstrap when:
should_accept()for its own connection requestSolution
Add an early guard in
should_accept()that checks if the incoming peer ID matches the node's own peer ID. If they match, the connection is rejected immediately with a warning log.Testing
Added two unit tests:
rejects_self_connection- verifies thatshould_accept()returnsfalsewhen the peer ID matches the node's own IDaccepts_connection_from_different_peer- verifies normal connections from other peers are still acceptedFixes
Closes #2139
[AI-assisted - Claude]