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

Always accept incoming connections from trusted peers #7140

Merged
merged 6 commits into from Mar 15, 2024

Conversation

AbnerZheng
Copy link
Contributor

close #7001

@AbnerZheng AbnerZheng marked this pull request as ready for review March 14, 2024 12:44
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

nice, this looks great

Comment on lines 1244 to 1254
/// Maximum occupied slots for outbound connections.
pub fn with_max_pending_outbound(mut self, num_outbound: usize) -> Self {
self.connection_info.num_outbound = num_outbound;
self
}

/// Maximum occupied slots for inbound connections.
pub fn with_max_pending_inbound(mut self, num_inbound: usize) -> Self {
self.connection_info.num_inbound = num_inbound;
self
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

please add again

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment on lines +282 to +287
// if a peer is not trusted and we don't have capacity for more inbound connections,
// disconnecting the peer
if !value.is_trusted() && !self.connection_info.has_in_capacity() {
self.queued_actions.push_back(PeerAction::Disconnect {
peer_id,
reason: Some(DisconnectReason::TooManyPeers),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm wondering if we have actually have a bug here where we allow multiple incoming sessions from the same peerid.

could you please add a test case for this scenario, because I think we should check the peer's state here

similar setup as https://github.com/paradigmxyz/reth/blob/main/crates/net/network/src/peers/manager.rs#L1913-L1913

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is the test I can imagine:

  1. setup a peer with max_in_bound = 1.
  2. receive a incoming session from the another peer X and established the session.
  3. receive another incoming session from peer X again and should be rejected by AlreadyConnected, the connected peers should not be connected and removed.

The point is that a connected peer shouldn't be disconnected by another incoming session. Am I in the right direction?

Copy link
Collaborator

Choose a reason for hiding this comment

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

receive another incoming session from peer X again and should be rejected by AlreadyConnected

exactly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, there seems be a bug that num_inbound should have be decreased when on_already_connected, and I add a unit test and an integration test, PTAL.
Also, I think num_inbound should only be increased when session established which may simplify the code to maintain it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, I think num_inbound should only be increased when session established which may simplify the code to maintain it.

I believe this makes sense, I'd like to introduce a new state PendingIn, similar to PendingOut

we can do this separately

@mattsse mattsse added C-enhancement New feature or request A-networking Related to networking in general labels Mar 15, 2024
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

lgtm, will open a followup issue for pendingIn state mgmt

@mattsse mattsse added this pull request to the merge queue Mar 15, 2024
Merged via the queue into paradigmxyz:main with commit 9312424 Mar 15, 2024
27 checks passed
@AbnerZheng AbnerZheng deleted the issue-7001 branch March 15, 2024 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-networking Related to networking in general C-enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Always accept incoming connections from trusted peers
2 participants