mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-08-01 01:11:58 +00:00
[core/swarm] Refactor and extend configurable connection limits. (#1848)
* Refactor and extend configurable connection limits. To better track different connection counts, permit configurable limits for these counts and make these available for inspection efficiently, introduce dedicated connection counters via a `ConnectionCounters` structure that is exposed on the API via the `NetworkInfo`. All connection or connection states that are counted in this way can also have effective configurable limits. * Cleanup * Add missing file. * Refine naming and config API. * Update core/CHANGELOG.md Co-authored-by: Max Inden <mail@max-inden.de> * Update core/CHANGELOG.md Co-authored-by: Max Inden <mail@max-inden.de> Co-authored-by: Max Inden <mail@max-inden.de>
This commit is contained in:
@@ -310,7 +310,7 @@ where
|
||||
}
|
||||
|
||||
/// The number of established connections to the peer.
|
||||
pub fn num_connections(&self) -> usize {
|
||||
pub fn num_connections(&self) -> u32 {
|
||||
self.network.pool.num_peer_established(&self.peer_id)
|
||||
}
|
||||
|
||||
@@ -448,12 +448,6 @@ where
|
||||
None
|
||||
}
|
||||
|
||||
/// The number of ongoing dialing attempts, i.e. pending outgoing connections
|
||||
/// to this peer.
|
||||
pub fn num_attempts(&self) -> usize {
|
||||
self.network.pool.num_peer_outgoing(&self.peer_id)
|
||||
}
|
||||
|
||||
/// Gets an iterator over all dialing (i.e. pending outgoing) connections to the peer.
|
||||
pub fn attempts<'b>(&'b mut self)
|
||||
-> DialingAttemptIter<'b,
|
||||
@@ -672,6 +666,15 @@ impl<'a, TInEvent, TOutEvent, THandler, TTransErr, THandlerErr>
|
||||
|
||||
/// Obtains the next dialing connection, if any.
|
||||
pub fn next<'b>(&'b mut self) -> Option<DialingAttempt<'b, TInEvent>> {
|
||||
// If the number of elements reduced, the current `DialingAttempt` has been
|
||||
// aborted and iteration needs to continue from the previous position to
|
||||
// account for the removed element.
|
||||
let end = self.dialing.get(self.peer_id).map_or(0, |conns| conns.len());
|
||||
if self.end > end {
|
||||
self.end = end;
|
||||
self.pos -= 1;
|
||||
}
|
||||
|
||||
if self.pos == self.end {
|
||||
return None
|
||||
}
|
||||
|
Reference in New Issue
Block a user