diff --git a/misc/metrics/src/swarm.rs b/misc/metrics/src/swarm.rs index c4fa8712d142..9d89944b49d2 100644 --- a/misc/metrics/src/swarm.rs +++ b/misc/metrics/src/swarm.rs @@ -31,6 +31,8 @@ pub struct Metrics { connections_established: Family, connections_closed: Family, + connections_denied: Family, + new_listen_addr: Family, expired_listen_addr: Family, @@ -60,6 +62,13 @@ impl Metrics { Box::new(connections_incoming_error.clone()), ); + let connections_denied = Family::default(); + sub_registry.register( + "connections_denied", + "Number of denied connections", + Box::new(connections_denied.clone()), + ); + let new_listen_addr = Family::default(); sub_registry.register( "new_listen_addr", @@ -128,6 +137,7 @@ impl Metrics { connections_incoming_error, connections_established, connections_closed, + connections_denied, new_listen_addr, expired_listen_addr, listener_closed, @@ -269,6 +279,13 @@ impl super::Recorder { self.dial_attempt.inc(); } + libp2p_swarm::SwarmEvent::ConnectionDenied { endpoint, .. } => { + self.connections_denied + .get_or_create(&AddressLabels { + protocols: protocol_stack::as_string(endpoint.get_remote_address()), + }) + .inc(); + } } } } diff --git a/protocols/autonat/src/behaviour.rs b/protocols/autonat/src/behaviour.rs index 70cd4236e421..c8453661d77f 100644 --- a/protocols/autonat/src/behaviour.rs +++ b/protocols/autonat/src/behaviour.rs @@ -35,7 +35,7 @@ use libp2p_request_response::{ ProtocolSupport, RequestId, RequestResponse, RequestResponseConfig, RequestResponseEvent, RequestResponseMessage, ResponseChannel, }; -use libp2p_swarm::behaviour::{ConnectionDenied, THandlerInEvent}; +use libp2p_swarm::behaviour::THandlerInEvent; use libp2p_swarm::{ behaviour::{ AddressChange, ConnectionClosed, ConnectionEstablished, DialFailure, ExpiredExternalAddr, @@ -461,7 +461,7 @@ impl NetworkBehaviour for Behaviour { &mut self, peer: &PeerId, connected_point: &ConnectedPoint, - ) -> Result { + ) -> Result> { self.inner.new_handler(peer, connected_point) } diff --git a/protocols/dcutr/src/behaviour.rs b/protocols/dcutr/src/behaviour.rs index 7be0af12d34b..240b742804cd 100644 --- a/protocols/dcutr/src/behaviour.rs +++ b/protocols/dcutr/src/behaviour.rs @@ -27,8 +27,7 @@ use libp2p_core::connection::{ConnectedPoint, ConnectionId}; use libp2p_core::multiaddr::Protocol; use libp2p_core::{Multiaddr, PeerId}; use libp2p_swarm::behaviour::{ - ConnectionClosed, ConnectionDenied, ConnectionEstablished, DialFailure, FromSwarm, - THandlerInEvent, + ConnectionClosed, ConnectionEstablished, DialFailure, FromSwarm, THandlerInEvent, }; use libp2p_swarm::dial_opts::{self, DialOpts}; use libp2p_swarm::{ @@ -216,7 +215,7 @@ impl NetworkBehaviour for Behaviour { &mut self, peer: &PeerId, connected_point: &ConnectedPoint, - ) -> Result { + ) -> Result> { match ( self.awaiting_direct_inbound_connections.entry(*peer), self.awaiting_direct_outbound_connections.entry(*peer), diff --git a/protocols/floodsub/src/layer.rs b/protocols/floodsub/src/layer.rs index 7e8aa28aa7bd..58fc40a9f25d 100644 --- a/protocols/floodsub/src/layer.rs +++ b/protocols/floodsub/src/layer.rs @@ -27,8 +27,8 @@ use crate::FloodsubConfig; use cuckoofilter::{CuckooError, CuckooFilter}; use fnv::FnvHashSet; use libp2p_core::{connection::ConnectionId, ConnectedPoint, PeerId}; +use libp2p_swarm::behaviour::THandlerInEvent; use libp2p_swarm::behaviour::{ConnectionClosed, ConnectionEstablished, FromSwarm}; -use libp2p_swarm::behaviour::{ConnectionDenied, THandlerInEvent}; use libp2p_swarm::ConnectionHandler; use libp2p_swarm::{ dial_opts::DialOpts, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler, OneShotHandler, @@ -340,7 +340,7 @@ impl NetworkBehaviour for Floodsub { &mut self, _: &PeerId, _: &ConnectedPoint, - ) -> Result { + ) -> Result> { Ok(Default::default()) } diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index 3e79ff7d55a4..43dd133468c7 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -66,7 +66,6 @@ use crate::types::{ }; use crate::types::{GossipsubRpc, PeerConnections, PeerKind}; use crate::{rpc_proto, TopicScoreParams}; -use libp2p_swarm::behaviour::ConnectionDenied; use std::{cmp::Ordering::Equal, fmt::Debug}; use wasm_timer::Interval; @@ -3302,7 +3301,7 @@ where &mut self, _: &PeerId, _: &ConnectedPoint, - ) -> Result { + ) -> Result> { let protocol_config = ProtocolConfig::new( self.config.protocol_id().clone(), self.config.custom_id_version().clone(), diff --git a/protocols/identify/src/behaviour.rs b/protocols/identify/src/behaviour.rs index 46d1880f62a6..fa7c5e9e219b 100644 --- a/protocols/identify/src/behaviour.rs +++ b/protocols/identify/src/behaviour.rs @@ -25,8 +25,7 @@ use libp2p_core::{ connection::ConnectionId, multiaddr::Protocol, ConnectedPoint, Multiaddr, PeerId, PublicKey, }; use libp2p_swarm::behaviour::{ - ConnectionClosed, ConnectionDenied, ConnectionEstablished, DialFailure, FromSwarm, - THandlerInEvent, + ConnectionClosed, ConnectionEstablished, DialFailure, FromSwarm, THandlerInEvent, }; use libp2p_swarm::{ dial_opts::DialOpts, AddressScore, ConnectionHandler, ConnectionHandlerUpgrErr, DialError, @@ -243,7 +242,7 @@ impl NetworkBehaviour for Behaviour { &mut self, peer: &PeerId, _: &ConnectedPoint, - ) -> Result { + ) -> Result> { Ok(Handler::new( self.config.initial_delay, self.config.interval, diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs index bc5a69b23160..38bcf052d86d 100644 --- a/protocols/kad/src/behaviour.rs +++ b/protocols/kad/src/behaviour.rs @@ -41,8 +41,8 @@ use fnv::{FnvHashMap, FnvHashSet}; use instant::Instant; use libp2p_core::{connection::ConnectionId, ConnectedPoint, Multiaddr, PeerId}; use libp2p_swarm::behaviour::{ - AddressChange, ConnectionClosed, ConnectionDenied, ConnectionEstablished, DialFailure, - ExpiredListenAddr, FromSwarm, NewExternalAddr, NewListenAddr, THandlerInEvent, + AddressChange, ConnectionClosed, ConnectionEstablished, DialFailure, ExpiredListenAddr, + FromSwarm, NewExternalAddr, NewListenAddr, THandlerInEvent, }; use libp2p_swarm::{ dial_opts::{self, DialOpts}, @@ -1979,7 +1979,7 @@ where &mut self, remote_peer_id: &PeerId, endpoint: &ConnectedPoint, - ) -> Result { + ) -> Result> { Ok(KademliaHandler::new( KademliaHandlerConfig { protocol_config: self.protocol_config.clone(), diff --git a/protocols/mdns/src/behaviour.rs b/protocols/mdns/src/behaviour.rs index 9d8c471314a7..4fa105ec8e86 100644 --- a/protocols/mdns/src/behaviour.rs +++ b/protocols/mdns/src/behaviour.rs @@ -28,7 +28,7 @@ use crate::Config; use futures::Stream; use if_watch::IfEvent; use libp2p_core::{Multiaddr, PeerId}; -use libp2p_swarm::behaviour::{ConnectionClosed, ConnectionDenied, FromSwarm}; +use libp2p_swarm::behaviour::{ConnectionClosed, FromSwarm}; use libp2p_swarm::{ dummy, ConnectionHandler, NetworkBehaviour, NetworkBehaviourAction, PollParameters, }; @@ -172,7 +172,7 @@ where &mut self, _: &PeerId, _: &libp2p_core::ConnectedPoint, - ) -> Result { + ) -> Result> { Ok(dummy::ConnectionHandler) } diff --git a/protocols/ping/src/lib.rs b/protocols/ping/src/lib.rs index e1ba31143ebb..80b14e1dc448 100644 --- a/protocols/ping/src/lib.rs +++ b/protocols/ping/src/lib.rs @@ -48,7 +48,7 @@ mod protocol; use handler::Handler; pub use handler::{Config, Failure, Success}; use libp2p_core::{connection::ConnectionId, ConnectedPoint, PeerId}; -use libp2p_swarm::behaviour::{ConnectionDenied, THandlerInEvent}; +use libp2p_swarm::behaviour::THandlerInEvent; use libp2p_swarm::{ behaviour::FromSwarm, NetworkBehaviour, NetworkBehaviourAction, PollParameters, }; @@ -124,7 +124,8 @@ impl NetworkBehaviour for Behaviour { &mut self, _: &PeerId, _: &ConnectedPoint, - ) -> std::result::Result { + ) -> std::result::Result> + { Ok(Handler::new(self.config.clone())) } diff --git a/protocols/relay/src/v2/client.rs b/protocols/relay/src/v2/client.rs index f5aa268d380c..76527af3591e 100644 --- a/protocols/relay/src/v2/client.rs +++ b/protocols/relay/src/v2/client.rs @@ -35,8 +35,8 @@ use futures::ready; use futures::stream::StreamExt; use libp2p_core::connection::ConnectionId; use libp2p_core::{ConnectedPoint, PeerId}; +use libp2p_swarm::behaviour::THandlerInEvent; use libp2p_swarm::behaviour::{ConnectionClosed, ConnectionEstablished, FromSwarm}; -use libp2p_swarm::behaviour::{ConnectionDenied, THandlerInEvent}; use libp2p_swarm::dial_opts::DialOpts; use libp2p_swarm::{dummy, ConnectionHandler}; use libp2p_swarm::{ @@ -159,7 +159,7 @@ impl NetworkBehaviour for Client { &mut self, peer: &PeerId, connected_point: &ConnectedPoint, - ) -> Result { + ) -> Result> { if connected_point.is_relayed() { if let Some(event) = self.initial_events.remove(peer) { log::debug!( diff --git a/protocols/relay/src/v2/relay.rs b/protocols/relay/src/v2/relay.rs index 41bde8dfed41..b6be9d9197de 100644 --- a/protocols/relay/src/v2/relay.rs +++ b/protocols/relay/src/v2/relay.rs @@ -31,8 +31,8 @@ use instant::Instant; use libp2p_core::connection::ConnectionId; use libp2p_core::multiaddr::Protocol; use libp2p_core::{ConnectedPoint, PeerId}; +use libp2p_swarm::behaviour::THandlerInEvent; use libp2p_swarm::behaviour::{ConnectionClosed, FromSwarm}; -use libp2p_swarm::behaviour::{ConnectionDenied, THandlerInEvent}; use libp2p_swarm::{ dummy, ConnectionHandlerUpgrErr, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler, PollParameters, @@ -258,7 +258,7 @@ impl NetworkBehaviour for Relay { &mut self, _: &PeerId, endpoint: &ConnectedPoint, - ) -> Result { + ) -> Result> { if endpoint.is_relayed() { // Deny all substreams on relayed connection. Ok(Either::Right(dummy::ConnectionHandler)) diff --git a/protocols/rendezvous/src/client.rs b/protocols/rendezvous/src/client.rs index 4a92d6339ed0..9406ec827533 100644 --- a/protocols/rendezvous/src/client.rs +++ b/protocols/rendezvous/src/client.rs @@ -32,8 +32,8 @@ use libp2p_core::connection::ConnectionId; use libp2p_core::identity::error::SigningError; use libp2p_core::identity::Keypair; use libp2p_core::{ConnectedPoint, Multiaddr, PeerId, PeerRecord}; +use libp2p_swarm::behaviour::FromSwarm; use libp2p_swarm::behaviour::THandlerInEvent; -use libp2p_swarm::behaviour::{ConnectionDenied, FromSwarm}; use libp2p_swarm::{ CloseConnection, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler, PollParameters, }; @@ -170,7 +170,7 @@ impl NetworkBehaviour for Behaviour { &mut self, _: &PeerId, _: &ConnectedPoint, - ) -> Result { + ) -> Result> { let initial_keep_alive = Duration::from_secs(30); Ok(SubstreamConnectionHandler::new_outbound_only( diff --git a/protocols/rendezvous/src/server.rs b/protocols/rendezvous/src/server.rs index 22a72b1f6898..2c10f14253c7 100644 --- a/protocols/rendezvous/src/server.rs +++ b/protocols/rendezvous/src/server.rs @@ -29,8 +29,8 @@ use futures::stream::FuturesUnordered; use futures::{FutureExt, StreamExt}; use libp2p_core::connection::ConnectionId; use libp2p_core::{ConnectedPoint, PeerId}; +use libp2p_swarm::behaviour::FromSwarm; use libp2p_swarm::behaviour::THandlerInEvent; -use libp2p_swarm::behaviour::{ConnectionDenied, FromSwarm}; use libp2p_swarm::{ CloseConnection, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler, PollParameters, }; @@ -116,7 +116,7 @@ impl NetworkBehaviour for Behaviour { &mut self, _: &PeerId, _: &ConnectedPoint, - ) -> Result { + ) -> Result> { let initial_keep_alive = Duration::from_secs(30); Ok(SubstreamConnectionHandler::new_inbound_only( diff --git a/protocols/request-response/src/lib.rs b/protocols/request-response/src/lib.rs index 5c403429fbef..3cf0f94c0e2a 100644 --- a/protocols/request-response/src/lib.rs +++ b/protocols/request-response/src/lib.rs @@ -67,7 +67,7 @@ pub use handler::ProtocolSupport; use futures::channel::oneshot; use handler::{RequestProtocol, RequestResponseHandler, RequestResponseHandlerEvent}; use libp2p_core::{connection::ConnectionId, ConnectedPoint, Multiaddr, PeerId}; -use libp2p_swarm::behaviour::{ConnectionDenied, THandlerInEvent}; +use libp2p_swarm::behaviour::THandlerInEvent; use libp2p_swarm::{ behaviour::{AddressChange, ConnectionClosed, ConnectionEstablished, DialFailure, FromSwarm}, dial_opts::DialOpts, @@ -698,7 +698,7 @@ where &mut self, _: &PeerId, _: &ConnectedPoint, - ) -> Result { + ) -> Result> { Ok(RequestResponseHandler::new( self.inbound_protocols.clone(), self.codec.clone(), diff --git a/swarm-derive/src/lib.rs b/swarm-derive/src/lib.rs index f7f004347a8a..66ad8887a542 100644 --- a/swarm-derive/src/lib.rs +++ b/swarm-derive/src/lib.rs @@ -52,7 +52,6 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { .unwrap_or_else(|| syn::parse_quote! { ::libp2p::swarm::derive_prelude }); let multiaddr = quote! { #prelude_path::Multiaddr }; - let connection_denied = quote! { #prelude_path::ConnectionDenied }; let trait_to_impl = quote! { #prelude_path::NetworkBehaviour }; let either_ident = quote! { #prelude_path::EitherOutput }; let network_behaviour_action = quote! { #prelude_path::NetworkBehaviourAction }; @@ -560,7 +559,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { type OutEvent = #out_event_reference; #[allow(clippy::needless_question_mark)] - fn new_handler(&mut self, peer: &#peer_id, connected_point: &#connected_point) -> Result { + fn new_handler(&mut self, peer: &#peer_id, connected_point: &#connected_point) -> Result> { use #connection_handler; Ok(#new_handler) diff --git a/swarm/src/behaviour.rs b/swarm/src/behaviour.rs index c1eeba5c4090..07cb18f3e848 100644 --- a/swarm/src/behaviour.rs +++ b/swarm/src/behaviour.rs @@ -143,7 +143,7 @@ pub trait NetworkBehaviour: 'static { &mut self, peer: &PeerId, connected_point: &ConnectedPoint, - ) -> Result; + ) -> Result>; /// Addresses that this behaviour is aware of for this specific peer, and that may allow /// reaching the peer. @@ -370,10 +370,6 @@ pub trait NetworkBehaviour: 'static { ) -> Poll>>; } -#[derive(Debug)] -#[non_exhaustive] -pub enum ConnectionDenied {} - /// Parameters passed to `poll()`, that the `NetworkBehaviour` has access to. pub trait PollParameters { /// Iterator returned by [`supported_protocols`](PollParameters::supported_protocols). diff --git a/swarm/src/behaviour/either.rs b/swarm/src/behaviour/either.rs index f7ac2871dccf..f187392831f0 100644 --- a/swarm/src/behaviour/either.rs +++ b/swarm/src/behaviour/either.rs @@ -18,10 +18,10 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +use crate::behaviour::THandlerInEvent; use crate::behaviour::{ self, inject_from_swarm, NetworkBehaviour, NetworkBehaviourAction, PollParameters, }; -use crate::behaviour::{ConnectionDenied, THandlerInEvent}; use either::Either; use libp2p_core::{ConnectedPoint, Multiaddr, PeerId}; use std::{task::Context, task::Poll}; @@ -39,7 +39,7 @@ where &mut self, peer: &PeerId, connected_point: &ConnectedPoint, - ) -> Result { + ) -> Result> { Ok(match self { Either::Left(a) => Either::Left(a.new_handler(peer, connected_point)?), Either::Right(b) => Either::Right(b.new_handler(peer, connected_point)?), diff --git a/swarm/src/behaviour/toggle.rs b/swarm/src/behaviour/toggle.rs index c424a5e9a421..399058bfe322 100644 --- a/swarm/src/behaviour/toggle.rs +++ b/swarm/src/behaviour/toggle.rs @@ -18,8 +18,8 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +use crate::behaviour::THandlerInEvent; use crate::behaviour::{inject_from_swarm, FromSwarm}; -use crate::behaviour::{ConnectionDenied, THandlerInEvent}; use crate::handler::{ ConnectionEvent, ConnectionHandler, ConnectionHandlerEvent, ConnectionHandlerUpgrErr, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, KeepAlive, @@ -76,7 +76,7 @@ where &mut self, peer: &PeerId, connected_point: &ConnectedPoint, - ) -> Result { + ) -> Result> { Ok(ToggleConnectionHandler { inner: match self.inner.as_mut() { None => None, diff --git a/swarm/src/connection/pool.rs b/swarm/src/connection/pool.rs index 40bc4e62af87..65d842200d46 100644 --- a/swarm/src/connection/pool.rs +++ b/swarm/src/connection/pool.rs @@ -18,8 +18,6 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. - -use crate::behaviour::ConnectionDenied; use crate::connection::Connection; use crate::upgrade::UpgradeInfoSend; use crate::{ @@ -44,6 +42,7 @@ use libp2p_core::connection::{ConnectionId, Endpoint, PendingPoint}; use libp2p_core::muxing::{StreamMuxerBox, StreamMuxerExt}; use libp2p_core::ProtocolName; use smallvec::SmallVec; +use std::error::Error; use std::{ collections::{hash_map, HashMap}, convert::TryFrom as _, @@ -260,6 +259,17 @@ where handler: THandler, }, + /// A [NetworkBehaviour] denied a just established connection by not producing a [`ConnectionHandler`] from [`NetworkBehaviour::new_handler`]. + /// + /// [NetworkBehaviour]: crate::NetworkBehaviour + /// [NetworkBehaviour::new_handler]: crate::NetworkBehaviour::new_handler + ConnectionDenied { + id: ConnectionId, + peer_id: PeerId, + endpoint: ConnectedPoint, + cause: Box, + }, + /// An outbound connection attempt failed. PendingOutboundConnectionError { /// The ID of the failed connection. @@ -534,7 +544,10 @@ where /// Polls the connection pool for events. pub fn poll( &mut self, - mut new_handler_fn: impl FnMut(&PeerId, &ConnectedPoint) -> Result, + mut new_handler_fn: impl FnMut( + &PeerId, + &ConnectedPoint, + ) -> Result>, cx: &mut Context<'_>, ) -> Poll> where @@ -753,8 +766,17 @@ where }, ); - let handler = - new_handler_fn(&obtained_peer_id, &endpoint).expect("empty to empty"); + let handler = match new_handler_fn(&obtained_peer_id, &endpoint) { + Ok(handler) => handler, + Err(cause) => { + return Poll::Ready(PoolEvent::ConnectionDenied { + id, + peer_id: obtained_peer_id, + endpoint, + cause, + }) + } + }; let supported_protocols = handler .listen_protocol() .upgrade() diff --git a/swarm/src/dummy.rs b/swarm/src/dummy.rs index a1cfe910bd24..880605452a35 100644 --- a/swarm/src/dummy.rs +++ b/swarm/src/dummy.rs @@ -1,6 +1,5 @@ use crate::behaviour::{ - ConnectionDenied, FromSwarm, NetworkBehaviour, NetworkBehaviourAction, PollParameters, - THandlerInEvent, + FromSwarm, NetworkBehaviour, NetworkBehaviourAction, PollParameters, THandlerInEvent, }; use crate::handler::{ ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, @@ -24,7 +23,7 @@ impl NetworkBehaviour for Behaviour { &mut self, _: &PeerId, _: &ConnectedPoint, - ) -> Result { + ) -> Result> { Ok(ConnectionHandler) } diff --git a/swarm/src/keep_alive.rs b/swarm/src/keep_alive.rs index 651a75456f4a..a778a5f85db1 100644 --- a/swarm/src/keep_alive.rs +++ b/swarm/src/keep_alive.rs @@ -1,6 +1,5 @@ use crate::behaviour::{ - ConnectionDenied, FromSwarm, NetworkBehaviour, NetworkBehaviourAction, PollParameters, - THandlerInEvent, + FromSwarm, NetworkBehaviour, NetworkBehaviourAction, PollParameters, THandlerInEvent, }; use crate::handler::{ ConnectionEvent, ConnectionHandlerEvent, FullyNegotiatedInbound, FullyNegotiatedOutbound, @@ -29,7 +28,7 @@ impl NetworkBehaviour for Behaviour { &mut self, _: &PeerId, _: &ConnectedPoint, - ) -> Result { + ) -> Result> { Ok(ConnectionHandler) } diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index ce4354a0ab2c..9cc217a90a80 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -73,7 +73,6 @@ pub mod keep_alive; pub mod derive_prelude { pub use crate::behaviour::AddressChange; pub use crate::behaviour::ConnectionClosed; - pub use crate::behaviour::ConnectionDenied; pub use crate::behaviour::ConnectionEstablished; pub use crate::behaviour::DialFailure; pub use crate::behaviour::ExpiredExternalAddr; @@ -199,6 +198,13 @@ pub enum SwarmEvent { /// active close. cause: Option>, }, + ConnectionDenied { + /// Identity of the peer that we have connected to. + peer_id: PeerId, + /// Endpoint of the connection that has been closed. + endpoint: ConnectedPoint, + cause: Box, + }, /// A new connection arrived on a listener and is in the process of protocol negotiation. /// /// A corresponding [`ConnectionEstablished`](SwarmEvent::ConnectionEstablished), @@ -931,6 +937,18 @@ where num_established, }); } + PoolEvent::ConnectionDenied { + peer_id, + endpoint, + cause, + .. + } => { + return Some(SwarmEvent::ConnectionDenied { + peer_id, + endpoint, + cause, + }) + } PoolEvent::ConnectionEvent { peer_id, id, event } => { if self.banned_peer_connections.contains(&id) { log::debug!("Ignoring event from banned peer: {} {:?}.", peer_id, id); diff --git a/swarm/src/test.rs b/swarm/src/test.rs index 59ab424f8939..1d03eec55bb7 100644 --- a/swarm/src/test.rs +++ b/swarm/src/test.rs @@ -19,9 +19,8 @@ // DEALINGS IN THE SOFTWARE. use crate::behaviour::{ - ConnectionClosed, ConnectionDenied, ConnectionEstablished, DialFailure, ExpiredExternalAddr, - ExpiredListenAddr, FromSwarm, ListenerClosed, ListenerError, NewExternalAddr, NewListenAddr, - NewListener, + ConnectionClosed, ConnectionEstablished, DialFailure, ExpiredExternalAddr, ExpiredListenAddr, + FromSwarm, ListenerClosed, ListenerError, NewExternalAddr, NewListenAddr, NewListener, }; use crate::{ behaviour::THandlerInEvent, ConnectionHandler, NetworkBehaviour, NetworkBehaviourAction, @@ -77,7 +76,7 @@ where &mut self, _: &PeerId, _: &ConnectedPoint, - ) -> Result { + ) -> Result> { Ok(self.handler_proto.clone()) } @@ -379,7 +378,7 @@ where &mut self, peer: &PeerId, endpoint: &ConnectedPoint, - ) -> Result { + ) -> Result> { self.inner.new_handler(peer, endpoint) } diff --git a/swarm/tests/swarm_derive.rs b/swarm/tests/swarm_derive.rs index 8c1f2d7b2525..ce8417e19f79 100644 --- a/swarm/tests/swarm_derive.rs +++ b/swarm/tests/swarm_derive.rs @@ -21,7 +21,6 @@ use futures::StreamExt; use libp2p_identify as identify; use libp2p_ping as ping; -use libp2p_swarm::behaviour::ConnectionDenied; use libp2p_swarm::{behaviour::FromSwarm, dummy, NetworkBehaviour, SwarmEvent}; use std::fmt::Debug; @@ -391,7 +390,7 @@ fn custom_out_event_no_type_parameters() { &mut self, _: &PeerId, _: &ConnectedPoint, - ) -> Result { + ) -> Result> { Ok(dummy::ConnectionHandler) }