forked from bmwill/anemo
-
Notifications
You must be signed in to change notification settings - Fork 22
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
introduce a mechanism for setting maximum number of connections #19
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7ce8272
connection-manager: refactor pending_connections tasks
bmwill 7639a11
connection-manager: introduce a connect timeout configuration
bmwill 8113f37
wire: introduce a lightweight handshake
bmwill 4a8c190
config: add a max_conncurrent_connections parameter
bmwill c1de2bf
connection-manager: respect max_concurrent_connections config
bmwill 6f0910a
network: add tests for max_concurrent_connections config
bmwill 03d9aaa
network: add test to verify server properly handles client rejection
bmwill 00b93c6
peer-affinity: introduce PeerAffinity::Never
bmwill File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,12 +45,39 @@ pub struct Config { | |
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub connection_backoff_ms: Option<u64>, | ||
|
||
/// Set a timeout, in milliseconds, for all inbound and outbound connects. | ||
/// | ||
/// In unspecified, this will default to `10,000` milliseconds. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub connect_timeout_ms: Option<u64>, | ||
|
||
/// Maximum number of concurrent connections to attempt to establish at a given point in time. | ||
/// | ||
/// If unspecified, this will default to `100`. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub max_concurrent_outstanding_connecting_connections: Option<usize>, | ||
|
||
/// Maximum number of concurrent connections to have established at a given point in time. | ||
/// | ||
/// This limit is applied in the following ways: | ||
/// - Inbound connections from [`KnownPeers`] with [`PeerAffinity::High`] bypass this limit. All | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. small request - Can you reword this to make it clearer whether the "limit bypass" cases count towards the limit, even if they bypass it? (I think yes but not 100% sure) |
||
/// other inbound connections are only accepted if the total number of inbound and outbound | ||
/// connections, irrespective of affinity, is less than this limit. | ||
/// - Outbound connections explicitly made by the application via [`Network::connect`] or | ||
/// [`Network::connect_with_peer_id`] bypass this limit. | ||
/// - Outbound connections made in the background, due to configured [`KnownPeers`], to peers with | ||
/// [`PeerAffinity::High`] bypass this limit and are always attempted, while peers with lower | ||
/// affinity respect this limit. | ||
/// | ||
/// If unspecified, there will be no limit on the number of concurrent connections. | ||
/// | ||
/// [`KnownPeers`]: crate::KnownPeers | ||
/// [`PeerAffinity::High`]: crate::types::PeerAffinity::High | ||
/// [`Network::connect`]: crate::Network::connect | ||
/// [`Network::connect_with_peer_id`]: crate::Network::connect_with_peer_id | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub max_concurrent_connections: Option<usize>, | ||
|
||
/// Size of the broadcast channel use for subscribing to | ||
/// [`PeerEvent`](crate::types::PeerEvent)s via | ||
/// [`Network::subscribe`](crate::Network::subscribe). | ||
|
@@ -161,13 +188,23 @@ impl Config { | |
Duration::from_millis(self.connection_backoff_ms.unwrap_or(CONNECTION_BACKOFF_MS)) | ||
} | ||
|
||
pub(crate) fn connect_timeout(&self) -> Duration { | ||
const CONNECTION_TIMEOUT_MS: u64 = 10_000; // 10 seconds | ||
|
||
Duration::from_millis(self.connect_timeout_ms.unwrap_or(CONNECTION_TIMEOUT_MS)) | ||
} | ||
|
||
pub(crate) fn max_concurrent_outstanding_connecting_connections(&self) -> usize { | ||
const MAX_CONCURRENT_OUTSTANDING_CONNECTING_CONNECTIONS: usize = 100; | ||
|
||
self.max_concurrent_outstanding_connecting_connections | ||
.unwrap_or(MAX_CONCURRENT_OUTSTANDING_CONNECTING_CONNECTIONS) | ||
} | ||
|
||
pub(crate) fn max_concurrent_connections(&self) -> Option<usize> { | ||
self.max_concurrent_connections | ||
} | ||
|
||
pub(crate) fn peer_event_broadcast_channel_capacity(&self) -> usize { | ||
const PEER_EVENT_BROADCAST_CHANNEL_CAPACITY: usize = 128; | ||
|
||
|
This file contains 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
Oops, something went wrong.
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.
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.
ty for the excellent docs