Skip to content

Commit

Permalink
swarm/src/connection: Extend log when exceeding streams limit (#2716)
Browse files Browse the repository at this point in the history
Log peer ID and stream limit as well as reference config option when limit is
exceeded. This should help folks running into this limit debug what is going on.
  • Loading branch information
mxinden authored Jun 22, 2022
1 parent e2bef93 commit 7eaa9c7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
6 changes: 6 additions & 0 deletions swarm/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 0.36.2 [unreleased]

- Extend log message when exceeding inbound negotiating streams with peer ID and limit. See [PR 2716].

[PR 2716]: https://github.com/libp2p/rust-libp2p/pull/2716/

# 0.36.1

- Limit negotiating inbound substreams per connection. See [PR 2697].
Expand Down
2 changes: 1 addition & 1 deletion swarm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p-swarm"
edition = "2021"
rust-version = "1.56.1"
description = "The libp2p swarm"
version = "0.36.1"
version = "0.36.2"
authors = ["Parity Technologies <[email protected]>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down
7 changes: 6 additions & 1 deletion swarm/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub use pool::{EstablishedConnection, PendingConnection};
pub use substream::{Close, Substream, SubstreamEndpoint};

use crate::handler::ConnectionHandler;
use crate::IntoConnectionHandler;
use handler_wrapper::HandlerWrapper;
use libp2p_core::connection::ConnectedPoint;
use libp2p_core::multiaddr::Multiaddr;
Expand Down Expand Up @@ -94,12 +95,16 @@ where
/// Builds a new `Connection` from the given substream multiplexer
/// and connection handler.
pub fn new(
peer_id: PeerId,
endpoint: ConnectedPoint,
muxer: StreamMuxerBox,
handler: THandler,
handler: impl IntoConnectionHandler<Handler = THandler>,
substream_upgrade_protocol_override: Option<upgrade::Version>,
max_negotiating_inbound_streams: usize,
) -> Self {
let wrapped_handler = HandlerWrapper::new(
peer_id,
endpoint,
handler,
substream_upgrade_protocol_override,
max_negotiating_inbound_streams,
Expand Down
17 changes: 13 additions & 4 deletions swarm/src/connection/handler_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::handler::{
ConnectionHandler, ConnectionHandlerEvent, ConnectionHandlerUpgrErr, KeepAlive,
};
use crate::upgrade::SendWrapper;
use crate::IntoConnectionHandler;

use futures::prelude::*;
use futures::stream::FuturesUnordered;
Expand All @@ -33,6 +34,7 @@ use libp2p_core::{
upgrade::{self, InboundUpgradeApply, OutboundUpgradeApply, UpgradeError},
Multiaddr,
};
use libp2p_core::{ConnectedPoint, PeerId};
use std::{error, fmt, pin::Pin, task::Context, task::Poll, time::Duration};

/// A wrapper for an underlying [`ConnectionHandler`].
Expand All @@ -46,6 +48,7 @@ pub struct HandlerWrapper<TConnectionHandler>
where
TConnectionHandler: ConnectionHandler,
{
remote_peer_id: PeerId,
/// The underlying handler.
handler: TConnectionHandler,
/// Futures that upgrade incoming substreams.
Expand Down Expand Up @@ -106,12 +109,15 @@ impl<TConnectionHandler: ConnectionHandler> std::fmt::Debug for HandlerWrapper<T

impl<TConnectionHandler: ConnectionHandler> HandlerWrapper<TConnectionHandler> {
pub(crate) fn new(
handler: TConnectionHandler,
remote_peer_id: PeerId,
endpoint: ConnectedPoint,
handler: impl IntoConnectionHandler<Handler = TConnectionHandler>,
substream_upgrade_protocol_override: Option<upgrade::Version>,
max_negotiating_inbound_streams: usize,
) -> Self {
Self {
handler,
remote_peer_id,
handler: handler.into_handler(&remote_peer_id, &endpoint),
negotiating_in: Default::default(),
negotiating_out: Default::default(),
queued_dial_upgrades: Vec::new(),
Expand Down Expand Up @@ -257,8 +263,11 @@ where
SubstreamEndpoint::Listener => {
if self.negotiating_in.len() == self.max_negotiating_inbound_streams {
log::warn!(
"Incoming substream exceeding maximum number of \
negotiating inbound streams. Dropping."
"Incoming substream from {} exceeding maximum number \
of negotiating inbound streams {} on connection. \
Dropping. See PoolConfig::with_max_negotiating_inbound_streams.",
self.remote_peer_id,
self.max_negotiating_inbound_streams,
);
return;
}
Expand Down
4 changes: 3 additions & 1 deletion swarm/src/connection/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,10 @@ where
);

let connection = super::Connection::new(
obtained_peer_id,
endpoint,
muxer,
handler.into_handler(&obtained_peer_id, &endpoint),
handler,
self.substream_upgrade_protocol_override,
self.max_negotiating_inbound_streams,
);
Expand Down

0 comments on commit 7eaa9c7

Please sign in to comment.