diff --git a/Cargo.lock b/Cargo.lock index 5a345c62699..e04d951f1b1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2619,7 +2619,7 @@ dependencies = [ [[package]] name = "libp2p-core" -version = "0.40.0" +version = "0.40.1" dependencies = [ "async-std", "either", diff --git a/Cargo.toml b/Cargo.toml index 189114f6ede..734b2d14efb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -68,7 +68,7 @@ libp2p = { version = "0.52.3", path = "libp2p" } libp2p-allow-block-list = { version = "0.2.0", path = "misc/allow-block-list" } libp2p-autonat = { version = "0.11.0", path = "protocols/autonat" } libp2p-connection-limits = { version = "0.2.1", path = "misc/connection-limits" } -libp2p-core = { version = "0.40.0", path = "core" } +libp2p-core = { version = "0.40.1", path = "core" } libp2p-dcutr = { version = "0.10.0", path = "protocols/dcutr" } libp2p-deflate = { version = "0.40.0", path = "transports/deflate" } libp2p-dns = { version = "0.40.0", path = "transports/dns" } diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index ecc1eff2d7a..2d5c47a1633 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -1,4 +1,11 @@ -## 0.40.0 +## 0.40.1 - unreleased + +- Implement `Debug` for `StreamMuxerEvent`. + See [PR 4426]. + +[PR 4426]: https://github.com/libp2p/rust-libp2p/pull/4426 + +## 0.40.0 - Allow `ListenerId` to be user-controlled, i.e. to be provided on `Transport::listen_on`. See [PR 3567]. diff --git a/core/Cargo.toml b/core/Cargo.toml index e71c4d0f243..a3912f0f5e4 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-core" edition = "2021" rust-version = { workspace = true } description = "Core traits and structs of libp2p" -version = "0.40.0" +version = "0.40.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/core/src/muxing.rs b/core/src/muxing.rs index 13b826ba840..477e1608073 100644 --- a/core/src/muxing.rs +++ b/core/src/muxing.rs @@ -112,6 +112,7 @@ pub trait StreamMuxer { } /// An event produced by a [`StreamMuxer`]. +#[derive(Debug)] pub enum StreamMuxerEvent { /// The address of the remote has changed. AddressChange(Multiaddr), diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index bc035893bd4..77ddf3458d1 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -1,8 +1,12 @@ ## 0.43.4 - unreleased +- Implement `Debug` for event structs. + See [PR 4426]. + - Improve error message when `DialPeerCondition` prevents a dial. See [PR 4409]. +[PR 4426]: https://github.com/libp2p/rust-libp2p/pull/4426 [PR 4409]: https://github.com/libp2p/rust-libp2p/pull/4409 ## 0.43.3 diff --git a/swarm/src/behaviour.rs b/swarm/src/behaviour.rs index 0ecdf7b31f0..d80f5f0c9a4 100644 --- a/swarm/src/behaviour.rs +++ b/swarm/src/behaviour.rs @@ -408,6 +408,7 @@ pub enum CloseConnection { /// Enumeration with the list of the possible events /// to pass to [`on_swarm_event`](NetworkBehaviour::on_swarm_event). +#[derive(Debug)] pub enum FromSwarm<'a, Handler> { /// Informs the behaviour about a newly established connection to a peer. ConnectionEstablished(ConnectionEstablished<'a>), @@ -450,7 +451,7 @@ pub enum FromSwarm<'a, Handler> { } /// [`FromSwarm`] variant that informs the behaviour about a newly established connection to a peer. -#[derive(Clone, Copy)] +#[derive(Debug, Clone, Copy)] pub struct ConnectionEstablished<'a> { pub peer_id: PeerId, pub connection_id: ConnectionId, @@ -464,6 +465,7 @@ pub struct ConnectionEstablished<'a> { /// This event is always paired with an earlier /// [`FromSwarm::ConnectionEstablished`] with the same peer ID, connection ID /// and endpoint. +#[derive(Debug)] pub struct ConnectionClosed<'a, Handler> { pub peer_id: PeerId, pub connection_id: ConnectionId, @@ -474,7 +476,7 @@ pub struct ConnectionClosed<'a, Handler> { /// [`FromSwarm`] variant that informs the behaviour that the [`ConnectedPoint`] of an existing /// connection has changed. -#[derive(Clone, Copy)] +#[derive(Debug, Clone, Copy)] pub struct AddressChange<'a> { pub peer_id: PeerId, pub connection_id: ConnectionId, @@ -484,7 +486,7 @@ pub struct AddressChange<'a> { /// [`FromSwarm`] variant that informs the behaviour that the dial to a known /// or unknown node failed. -#[derive(Clone, Copy)] +#[derive(Debug, Clone, Copy)] pub struct DialFailure<'a> { pub peer_id: Option, pub error: &'a DialError, @@ -496,7 +498,7 @@ pub struct DialFailure<'a> { /// /// This can include, for example, an error during the handshake of the encryption layer, or the /// connection unexpectedly closed. -#[derive(Clone, Copy)] +#[derive(Debug, Clone, Copy)] pub struct ListenFailure<'a> { pub local_addr: &'a Multiaddr, pub send_back_addr: &'a Multiaddr, @@ -505,14 +507,14 @@ pub struct ListenFailure<'a> { } /// [`FromSwarm`] variant that informs the behaviour that a new listener was created. -#[derive(Clone, Copy)] +#[derive(Debug, Clone, Copy)] pub struct NewListener { pub listener_id: ListenerId, } /// [`FromSwarm`] variant that informs the behaviour /// that we have started listening on a new multiaddr. -#[derive(Clone, Copy)] +#[derive(Debug, Clone, Copy)] pub struct NewListenAddr<'a> { pub listener_id: ListenerId, pub addr: &'a Multiaddr, @@ -521,40 +523,40 @@ pub struct NewListenAddr<'a> { /// [`FromSwarm`] variant that informs the behaviour that a multiaddr /// we were listening on has expired, /// which means that we are no longer listening on it. -#[derive(Clone, Copy)] +#[derive(Debug, Clone, Copy)] pub struct ExpiredListenAddr<'a> { pub listener_id: ListenerId, pub addr: &'a Multiaddr, } /// [`FromSwarm`] variant that informs the behaviour that a listener experienced an error. -#[derive(Clone, Copy)] +#[derive(Debug, Clone, Copy)] pub struct ListenerError<'a> { pub listener_id: ListenerId, pub err: &'a (dyn std::error::Error + 'static), } /// [`FromSwarm`] variant that informs the behaviour that a listener closed. -#[derive(Clone, Copy)] +#[derive(Debug, Clone, Copy)] pub struct ListenerClosed<'a> { pub listener_id: ListenerId, pub reason: Result<(), &'a std::io::Error>, } /// [`FromSwarm`] variant that informs the behaviour about a new candidate for an external address for us. -#[derive(Clone, Copy)] +#[derive(Debug, Clone, Copy)] pub struct NewExternalAddrCandidate<'a> { pub addr: &'a Multiaddr, } /// [`FromSwarm`] variant that informs the behaviour that an external address was confirmed. -#[derive(Clone, Copy)] +#[derive(Debug, Clone, Copy)] pub struct ExternalAddrConfirmed<'a> { pub addr: &'a Multiaddr, } /// [`FromSwarm`] variant that informs the behaviour that an external address was removed. -#[derive(Clone, Copy)] +#[derive(Debug, Clone, Copy)] pub struct ExternalAddrExpired<'a> { pub addr: &'a Multiaddr, } diff --git a/swarm/src/handler.rs b/swarm/src/handler.rs index dcc7ab1c09d..9374903f9b7 100644 --- a/swarm/src/handler.rs +++ b/swarm/src/handler.rs @@ -222,6 +222,42 @@ pub enum ConnectionEvent<'a, IP: InboundUpgradeSend, OP: OutboundUpgradeSend, IO RemoteProtocolsChange(ProtocolsChange<'a>), } +impl<'a, IP, OP, IOI, OOI> fmt::Debug for ConnectionEvent<'a, IP, OP, IOI, OOI> +where + IP: InboundUpgradeSend + fmt::Debug, + IP::Output: fmt::Debug, + IP::Error: fmt::Debug, + OP: OutboundUpgradeSend + fmt::Debug, + OP::Output: fmt::Debug, + OP::Error: fmt::Debug, + IOI: fmt::Debug, + OOI: fmt::Debug, +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + ConnectionEvent::FullyNegotiatedInbound(v) => { + f.debug_tuple("FullyNegotiatedInbound").field(v).finish() + } + ConnectionEvent::FullyNegotiatedOutbound(v) => { + f.debug_tuple("FullyNegotiatedOutbound").field(v).finish() + } + ConnectionEvent::AddressChange(v) => f.debug_tuple("AddressChange").field(v).finish(), + ConnectionEvent::DialUpgradeError(v) => { + f.debug_tuple("DialUpgradeError").field(v).finish() + } + ConnectionEvent::ListenUpgradeError(v) => { + f.debug_tuple("ListenUpgradeError").field(v).finish() + } + ConnectionEvent::LocalProtocolsChange(v) => { + f.debug_tuple("LocalProtocolsChange").field(v).finish() + } + ConnectionEvent::RemoteProtocolsChange(v) => { + f.debug_tuple("RemoteProtocolsChange").field(v).finish() + } + } + } +} + impl<'a, IP: InboundUpgradeSend, OP: OutboundUpgradeSend, IOI, OOI> ConnectionEvent<'a, IP, OP, IOI, OOI> { @@ -262,6 +298,7 @@ impl<'a, IP: InboundUpgradeSend, OP: OutboundUpgradeSend, IOI, OOI> /// of simultaneously open negotiated inbound substreams. In other words it is up to the /// [`ConnectionHandler`] implementation to stop a malicious remote node to open and keep alive /// an excessive amount of inbound substreams. +#[derive(Debug)] pub struct FullyNegotiatedInbound { pub protocol: IP::Output, pub info: IOI, @@ -271,18 +308,20 @@ pub struct FullyNegotiatedInbound { /// /// The `protocol` field is the information that was previously passed to /// [`ConnectionHandlerEvent::OutboundSubstreamRequest`]. +#[derive(Debug)] pub struct FullyNegotiatedOutbound { pub protocol: OP::Output, pub info: OOI, } /// [`ConnectionEvent`] variant that informs the handler about a change in the address of the remote. +#[derive(Debug)] pub struct AddressChange<'a> { pub new_address: &'a Multiaddr, } /// [`ConnectionEvent`] variant that informs the handler about a change in the protocols supported on the connection. -#[derive(Clone)] +#[derive(Debug, Clone)] pub enum ProtocolsChange<'a> { Added(ProtocolsAdded<'a>), Removed(ProtocolsRemoved<'a>), @@ -352,7 +391,7 @@ impl<'a> ProtocolsChange<'a> { } /// An [`Iterator`] over all protocols that have been added. -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct ProtocolsAdded<'a> { protocols: Peekable>, } @@ -366,7 +405,7 @@ impl<'a> ProtocolsAdded<'a> { } /// An [`Iterator`] over all protocols that have been removed. -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct ProtocolsRemoved<'a> { protocols: Either< Peekable>, @@ -399,6 +438,7 @@ impl<'a> Iterator for ProtocolsRemoved<'a> { /// [`ConnectionEvent`] variant that informs the handler /// that upgrading an outbound substream to the given protocol has failed. +#[derive(Debug)] pub struct DialUpgradeError { pub info: OOI, pub error: StreamUpgradeError, @@ -406,6 +446,7 @@ pub struct DialUpgradeError { /// [`ConnectionEvent`] variant that informs the handler /// that upgrading an inbound substream to the given protocol has failed. +#[derive(Debug)] pub struct ListenUpgradeError { pub info: IOI, pub error: IP::Error, diff --git a/swarm/src/handler/map_in.rs b/swarm/src/handler/map_in.rs index af828999b03..82cb12a183d 100644 --- a/swarm/src/handler/map_in.rs +++ b/swarm/src/handler/map_in.rs @@ -24,6 +24,7 @@ use crate::handler::{ use std::{fmt::Debug, marker::PhantomData, task::Context, task::Poll}; /// Wrapper around a protocol handler that turns the input event into something else. +#[derive(Debug)] pub struct MapInEvent { inner: TConnectionHandler, map: TMap, diff --git a/swarm/src/handler/map_out.rs b/swarm/src/handler/map_out.rs index e92d1403ce6..8528b563ece 100644 --- a/swarm/src/handler/map_out.rs +++ b/swarm/src/handler/map_out.rs @@ -25,6 +25,7 @@ use std::fmt::Debug; use std::task::{Context, Poll}; /// Wrapper around a protocol handler that turns the output event into something else. +#[derive(Debug)] pub struct MapOutEvent { inner: TConnectionHandler, map: TMap,