Skip to content

Commit

Permalink
feat(swarm): remove deprecated connection limits
Browse files Browse the repository at this point in the history
Users are encouraged to use `libp2p::connection_limit::Behaviour` which is a one-to-one replacement for this functionality but built as a `NetworkBehaviour`.

Related: #3647.

Pull-Request: #3885.
  • Loading branch information
thomaseizinger authored May 8, 2023
1 parent f08055e commit b8a7684
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 510 deletions.
10 changes: 0 additions & 10 deletions misc/metrics/src/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,6 @@ impl<TBvEv, THandleErr> super::Recorder<libp2p_swarm::SwarmEvent<TBvEv, THandleE
};
}
}
#[allow(deprecated)]
libp2p_swarm::DialError::ConnectionLimit(_) => {
record(OutgoingConnectionError::ConnectionLimit)
}
libp2p_swarm::DialError::LocalPeerId { .. } => {
record(OutgoingConnectionError::LocalPeerId)
}
Expand Down Expand Up @@ -320,7 +316,6 @@ enum PeerStatus {

#[derive(EncodeLabelValue, Hash, Clone, Eq, PartialEq, Debug)]
enum OutgoingConnectionError {
ConnectionLimit,
LocalPeerId,
NoAddresses,
DialPeerConditionFalse,
Expand All @@ -345,18 +340,13 @@ enum IncomingConnectionError {
TransportErrorMultiaddrNotSupported,
TransportErrorOther,
Aborted,
ConnectionLimit,
Denied,
}

impl From<&libp2p_swarm::ListenError> for IncomingConnectionError {
fn from(error: &libp2p_swarm::ListenError) -> Self {
match error {
libp2p_swarm::ListenError::WrongPeerId { .. } => IncomingConnectionError::WrongPeerId,
#[allow(deprecated)]
libp2p_swarm::ListenError::ConnectionLimit(_) => {
IncomingConnectionError::ConnectionLimit
}
libp2p_swarm::ListenError::LocalPeerId { .. } => IncomingConnectionError::LocalPeerId,
libp2p_swarm::ListenError::Transport(
libp2p_core::transport::TransportError::MultiaddrNotSupported(_),
Expand Down
2 changes: 0 additions & 2 deletions protocols/kad/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1931,8 +1931,6 @@ where
DialError::DialPeerConditionFalse(dial_opts::PeerCondition::Always) => {
unreachable!("DialPeerCondition::Always can not trigger DialPeerConditionFalse.");
}
#[allow(deprecated)]
DialError::ConnectionLimit(_) => {}
}
}

Expand Down
5 changes: 5 additions & 0 deletions swarm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,17 @@
- Flatten `ConnectionHandlerUpgrErr` and rename to `StreamUpgradeError`.
See [PR 3882].

- Remove deprecated `ConnectionLimits`.
Users should migrate to `libp2p::connection_limits::Behaviour`.
See [PR 3885].

[PR 3605]: https://github.com/libp2p/rust-libp2p/pull/3605
[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715
[PR 3746]: https://github.com/libp2p/rust-libp2p/pull/3746
[PR 3865]: https://github.com/libp2p/rust-libp2p/pull/3865
[PR 3882]: https://github.com/libp2p/rust-libp2p/pull/3882
[PR 3884]: https://github.com/libp2p/rust-libp2p/pull/3884
[PR 3885]: https://github.com/libp2p/rust-libp2p/pull/3885
[PR 3886]: https://github.com/libp2p/rust-libp2p/pull/3886

## 0.42.2
Expand Down
25 changes: 0 additions & 25 deletions swarm/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,31 +400,6 @@ impl<'a> IncomingInfo<'a> {
}
}

/// Information about a connection limit.
#[deprecated(note = "Use `libp2p::connection_limits` instead.", since = "0.42.1")]
#[derive(Debug, Clone, Copy)]
pub struct ConnectionLimit {
/// The maximum number of connections.
pub limit: u32,
/// The current number of connections.
pub current: u32,
}

#[allow(deprecated)]
impl fmt::Display for ConnectionLimit {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"connection limit exceeded ({}/{})",
self.current, self.limit
)
}
}

/// A `ConnectionLimit` can represent an error if it has been exceeded.
#[allow(deprecated)]
impl std::error::Error for ConnectionLimit {}

struct SubstreamUpgrade<UserData, Upgrade> {
user_data: Option<UserData>,
timeout: Delay,
Expand Down
21 changes: 0 additions & 21 deletions swarm/src/connection/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

#[allow(deprecated)]
use crate::connection::ConnectionLimit;
use crate::transport::TransportError;
use crate::Multiaddr;
use crate::{ConnectedPoint, PeerId};
Expand Down Expand Up @@ -90,15 +88,6 @@ pub enum PendingConnectionError<TTransErr> {
/// An error occurred while negotiating the transport protocol(s) on a connection.
Transport(TTransErr),

/// The connection was dropped because the connection limit
/// for a peer has been reached.
#[deprecated(
note = "Use `libp2p::connection_limits` instead and handle `{Dial,Listen}Error::Denied::cause`.",
since = "0.42.1"
)]
#[allow(deprecated)]
ConnectionLimit(ConnectionLimit),

/// Pending connection attempt has been aborted.
Aborted,

Expand All @@ -117,10 +106,6 @@ impl<T> PendingConnectionError<T> {
pub fn map<U>(self, f: impl FnOnce(T) -> U) -> PendingConnectionError<U> {
match self {
PendingConnectionError::Transport(t) => PendingConnectionError::Transport(f(t)),
#[allow(deprecated)]
PendingConnectionError::ConnectionLimit(l) => {
PendingConnectionError::ConnectionLimit(l)
}
PendingConnectionError::Aborted => PendingConnectionError::Aborted,
PendingConnectionError::WrongPeerId { obtained, endpoint } => {
PendingConnectionError::WrongPeerId { obtained, endpoint }
Expand All @@ -145,10 +130,6 @@ where
"Pending connection: Transport error on connection: {err}"
)
}
#[allow(deprecated)]
PendingConnectionError::ConnectionLimit(l) => {
write!(f, "Connection error: Connection limit: {l}.")
}
PendingConnectionError::WrongPeerId { obtained, endpoint } => {
write!(
f,
Expand All @@ -172,8 +153,6 @@ where
PendingConnectionError::WrongPeerId { .. } => None,
PendingConnectionError::LocalPeerId { .. } => None,
PendingConnectionError::Aborted => None,
#[allow(deprecated)]
PendingConnectionError::ConnectionLimit(..) => None,
}
}
}
Loading

0 comments on commit b8a7684

Please sign in to comment.