From 207c7baa67f1cef6dda9dd71365ea6b28c5acbe2 Mon Sep 17 00:00:00 2001 From: Dave Huseby Date: Sun, 1 Oct 2023 18:27:29 -0600 Subject: [PATCH 01/20] adding #[non_exhaustive] to key enums Signed-off-by: Dave Huseby --- misc/allow-block-list/src/lib.rs | 14 +------------- misc/connection-limits/src/lib.rs | 10 +--------- misc/metrics/src/swarm.rs | 1 + protocols/autonat/src/behaviour.rs | 1 + protocols/dcutr/src/behaviour_impl.rs | 12 +----------- protocols/dcutr/src/handler/relayed.rs | 4 +--- protocols/floodsub/src/layer.rs | 12 +----------- protocols/gossipsub/src/behaviour.rs | 11 +---------- protocols/gossipsub/src/handler.rs | 5 +---- protocols/identify/src/behaviour.rs | 11 +---------- protocols/identify/src/handler.rs | 4 +--- protocols/kad/src/behaviour.rs | 10 +--------- protocols/kad/src/handler.rs | 4 +--- protocols/mdns/src/behaviour.rs | 13 +------------ protocols/perf/src/client.rs | 12 +----------- protocols/ping/src/handler.rs | 5 +---- protocols/ping/src/lib.rs | 14 +------------- protocols/relay/src/behaviour.rs | 13 +------------ protocols/relay/src/behaviour/handler.rs | 5 +---- protocols/relay/src/priv_client.rs | 11 +---------- protocols/relay/src/priv_client/handler.rs | 4 +--- protocols/rendezvous/src/client.rs | 1 + protocols/rendezvous/src/server.rs | 1 + protocols/request-response/src/handler.rs | 4 +--- protocols/request-response/src/lib.rs | 10 +--------- protocols/upnp/src/behaviour.rs | 12 +----------- swarm-derive/src/lib.rs | 1 + swarm/CHANGELOG.md | 5 +++++ swarm/src/behaviour.rs | 2 ++ swarm/src/handler.rs | 2 ++ swarm/src/lib.rs | 1 + swarm/tests/swarm_derive.rs | 14 +------------- 32 files changed, 38 insertions(+), 191 deletions(-) diff --git a/misc/allow-block-list/src/lib.rs b/misc/allow-block-list/src/lib.rs index 1950c47f28b..6694671c4c8 100644 --- a/misc/allow-block-list/src/lib.rs +++ b/misc/allow-block-list/src/lib.rs @@ -233,19 +233,7 @@ where fn on_swarm_event(&mut self, event: FromSwarm) { match event { - FromSwarm::ConnectionClosed(_) => {} - FromSwarm::ConnectionEstablished(_) => {} - FromSwarm::AddressChange(_) => {} - FromSwarm::DialFailure(_) => {} - FromSwarm::ListenFailure(_) => {} - FromSwarm::NewListener(_) => {} - FromSwarm::NewListenAddr(_) => {} - FromSwarm::ExpiredListenAddr(_) => {} - FromSwarm::ListenerError(_) => {} - FromSwarm::ListenerClosed(_) => {} - FromSwarm::NewExternalAddrCandidate(_) => {} - FromSwarm::ExternalAddrExpired(_) => {} - FromSwarm::ExternalAddrConfirmed(_) => {} + _ => {} } } diff --git a/misc/connection-limits/src/lib.rs b/misc/connection-limits/src/lib.rs index 7de96cc1736..c0170bd1f00 100644 --- a/misc/connection-limits/src/lib.rs +++ b/misc/connection-limits/src/lib.rs @@ -340,18 +340,10 @@ impl NetworkBehaviour for Behaviour { FromSwarm::DialFailure(DialFailure { connection_id, .. }) => { self.pending_outbound_connections.remove(&connection_id); } - FromSwarm::AddressChange(_) => {} FromSwarm::ListenFailure(ListenFailure { connection_id, .. }) => { self.pending_inbound_connections.remove(&connection_id); } - FromSwarm::NewListener(_) => {} - FromSwarm::NewListenAddr(_) => {} - FromSwarm::ExpiredListenAddr(_) => {} - FromSwarm::ListenerError(_) => {} - FromSwarm::ListenerClosed(_) => {} - FromSwarm::NewExternalAddrCandidate(_) => {} - FromSwarm::ExternalAddrExpired(_) => {} - FromSwarm::ExternalAddrConfirmed(_) => {} + _ => {} } } diff --git a/misc/metrics/src/swarm.rs b/misc/metrics/src/swarm.rs index 8837457d36a..b4834acd89a 100644 --- a/misc/metrics/src/swarm.rs +++ b/misc/metrics/src/swarm.rs @@ -296,6 +296,7 @@ impl super::Recorder { self.dial_attempt.inc(); } + _ => {} } } } diff --git a/protocols/autonat/src/behaviour.rs b/protocols/autonat/src/behaviour.rs index 439543f8318..45efadbdfb7 100644 --- a/protocols/autonat/src/behaviour.rs +++ b/protocols/autonat/src/behaviour.rs @@ -589,6 +589,7 @@ impl NetworkBehaviour for Behaviour { self.inner.on_swarm_event(listener_closed) } confirmed @ FromSwarm::ExternalAddrConfirmed(_) => self.inner.on_swarm_event(confirmed), + _ => {} } } diff --git a/protocols/dcutr/src/behaviour_impl.rs b/protocols/dcutr/src/behaviour_impl.rs index 748e163429d..6e3553a2dd2 100644 --- a/protocols/dcutr/src/behaviour_impl.rs +++ b/protocols/dcutr/src/behaviour_impl.rs @@ -365,17 +365,7 @@ impl NetworkBehaviour for Behaviour { self.on_connection_closed(connection_closed) } FromSwarm::DialFailure(dial_failure) => self.on_dial_failure(dial_failure), - FromSwarm::AddressChange(_) - | FromSwarm::ConnectionEstablished(_) - | FromSwarm::ListenFailure(_) - | FromSwarm::NewListener(_) - | FromSwarm::NewListenAddr(_) - | FromSwarm::ExpiredListenAddr(_) - | FromSwarm::ListenerError(_) - | FromSwarm::ListenerClosed(_) - | FromSwarm::NewExternalAddrCandidate(_) - | FromSwarm::ExternalAddrExpired(_) - | FromSwarm::ExternalAddrConfirmed(_) => {} + _ => {} } } } diff --git a/protocols/dcutr/src/handler/relayed.rs b/protocols/dcutr/src/handler/relayed.rs index ff22f2b18e1..9f2b9fc3633 100644 --- a/protocols/dcutr/src/handler/relayed.rs +++ b/protocols/dcutr/src/handler/relayed.rs @@ -331,9 +331,7 @@ impl ConnectionHandler for Handler { ConnectionEvent::DialUpgradeError(dial_upgrade_error) => { self.on_dial_upgrade_error(dial_upgrade_error) } - ConnectionEvent::AddressChange(_) - | ConnectionEvent::LocalProtocolsChange(_) - | ConnectionEvent::RemoteProtocolsChange(_) => {} + _ => {} } } } diff --git a/protocols/floodsub/src/layer.rs b/protocols/floodsub/src/layer.rs index 29fe8ba250f..68cd7276a28 100644 --- a/protocols/floodsub/src/layer.rs +++ b/protocols/floodsub/src/layer.rs @@ -486,17 +486,7 @@ impl NetworkBehaviour for Floodsub { FromSwarm::ConnectionClosed(connection_closed) => { self.on_connection_closed(connection_closed) } - FromSwarm::AddressChange(_) - | FromSwarm::DialFailure(_) - | FromSwarm::ListenFailure(_) - | FromSwarm::NewListener(_) - | FromSwarm::NewListenAddr(_) - | FromSwarm::ExpiredListenAddr(_) - | FromSwarm::ListenerError(_) - | FromSwarm::ListenerClosed(_) - | FromSwarm::NewExternalAddrCandidate(_) - | FromSwarm::ExternalAddrExpired(_) - | FromSwarm::ExternalAddrConfirmed(_) => {} + _ => {} } } } diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index 402420f378e..09e553aaba1 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -3489,16 +3489,7 @@ where self.on_connection_closed(connection_closed) } FromSwarm::AddressChange(address_change) => self.on_address_change(address_change), - FromSwarm::DialFailure(_) - | FromSwarm::ListenFailure(_) - | FromSwarm::NewListener(_) - | FromSwarm::NewListenAddr(_) - | FromSwarm::ExpiredListenAddr(_) - | FromSwarm::ListenerError(_) - | FromSwarm::ListenerClosed(_) - | FromSwarm::NewExternalAddrCandidate(_) - | FromSwarm::ExternalAddrExpired(_) - | FromSwarm::ExternalAddrConfirmed(_) => {} + _ => {} } } } diff --git a/protocols/gossipsub/src/handler.rs b/protocols/gossipsub/src/handler.rs index 8508e026cee..62453d9181b 100644 --- a/protocols/gossipsub/src/handler.rs +++ b/protocols/gossipsub/src/handler.rs @@ -553,10 +553,7 @@ impl ConnectionHandler for Handler { }) => { log::debug!("Protocol negotiation failed: {e}") } - ConnectionEvent::AddressChange(_) - | ConnectionEvent::ListenUpgradeError(_) - | ConnectionEvent::LocalProtocolsChange(_) - | ConnectionEvent::RemoteProtocolsChange(_) => {} + _ => {} } } Handler::Disabled(_) => {} diff --git a/protocols/identify/src/behaviour.rs b/protocols/identify/src/behaviour.rs index f572b937d38..2e60bc5b5f4 100644 --- a/protocols/identify/src/behaviour.rs +++ b/protocols/identify/src/behaviour.rs @@ -395,16 +395,7 @@ impl NetworkBehaviour for Behaviour { } } } - FromSwarm::NewListenAddr(_) - | FromSwarm::ExpiredListenAddr(_) - | FromSwarm::AddressChange(_) - | FromSwarm::ListenFailure(_) - | FromSwarm::NewListener(_) - | FromSwarm::ListenerError(_) - | FromSwarm::ListenerClosed(_) - | FromSwarm::NewExternalAddrCandidate(_) - | FromSwarm::ExternalAddrExpired(_) => {} - FromSwarm::ExternalAddrConfirmed(_) => {} + _ => {} } } } diff --git a/protocols/identify/src/handler.rs b/protocols/identify/src/handler.rs index 50b9882f2c5..54a4ac14177 100644 --- a/protocols/identify/src/handler.rs +++ b/protocols/identify/src/handler.rs @@ -412,9 +412,6 @@ impl ConnectionHandler for Handler { )); self.trigger_next_identify.reset(self.interval); } - ConnectionEvent::AddressChange(_) - | ConnectionEvent::ListenUpgradeError(_) - | ConnectionEvent::RemoteProtocolsChange(_) => {} ConnectionEvent::LocalProtocolsChange(change) => { let before = log::log_enabled!(Level::Debug) .then(|| self.local_protocols_to_string()) @@ -439,6 +436,7 @@ impl ConnectionHandler for Handler { }); } } + _ => {} } } } diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs index 262962cbd1f..e75d93625c9 100644 --- a/protocols/kad/src/behaviour.rs +++ b/protocols/kad/src/behaviour.rs @@ -2543,15 +2543,7 @@ where } FromSwarm::DialFailure(dial_failure) => self.on_dial_failure(dial_failure), FromSwarm::AddressChange(address_change) => self.on_address_change(address_change), - FromSwarm::ExpiredListenAddr(_) - | FromSwarm::NewExternalAddrCandidate(_) - | FromSwarm::NewListenAddr(_) - | FromSwarm::ListenFailure(_) - | FromSwarm::NewListener(_) - | FromSwarm::ListenerClosed(_) - | FromSwarm::ListenerError(_) - | FromSwarm::ExternalAddrExpired(_) - | FromSwarm::ExternalAddrConfirmed(_) => {} + _ => {} } } } diff --git a/protocols/kad/src/handler.rs b/protocols/kad/src/handler.rs index 0df4da6bdc7..7a2569f1d5f 100644 --- a/protocols/kad/src/handler.rs +++ b/protocols/kad/src/handler.rs @@ -792,9 +792,6 @@ impl ConnectionHandler for Handler { ConnectionEvent::DialUpgradeError(dial_upgrade_error) => { self.on_dial_upgrade_error(dial_upgrade_error) } - ConnectionEvent::AddressChange(_) - | ConnectionEvent::ListenUpgradeError(_) - | ConnectionEvent::LocalProtocolsChange(_) => {} ConnectionEvent::RemoteProtocolsChange(change) => { let dirty = self.remote_supported_protocols.on_protocols_change(change); @@ -828,6 +825,7 @@ impl ConnectionHandler for Handler { } } } + _ => {} } } } diff --git a/protocols/mdns/src/behaviour.rs b/protocols/mdns/src/behaviour.rs index bc102f832df..da91a42c319 100644 --- a/protocols/mdns/src/behaviour.rs +++ b/protocols/mdns/src/behaviour.rs @@ -234,18 +234,7 @@ where iface.fire_timer(); } } - FromSwarm::ConnectionClosed(_) - | FromSwarm::ConnectionEstablished(_) - | FromSwarm::DialFailure(_) - | FromSwarm::AddressChange(_) - | FromSwarm::ListenFailure(_) - | FromSwarm::NewListenAddr(_) - | FromSwarm::ExpiredListenAddr(_) - | FromSwarm::ListenerError(_) - | FromSwarm::ListenerClosed(_) - | FromSwarm::NewExternalAddrCandidate(_) - | FromSwarm::ExternalAddrExpired(_) - | FromSwarm::ExternalAddrConfirmed(_) => {} + _ => {} } } diff --git a/protocols/perf/src/client.rs b/protocols/perf/src/client.rs index 93c2086a49e..e246fa246b4 100644 --- a/protocols/perf/src/client.rs +++ b/protocols/perf/src/client.rs @@ -171,17 +171,7 @@ impl NetworkBehaviour for Behaviour { assert!(self.connected.remove(&peer_id)); } } - FromSwarm::AddressChange(_) - | FromSwarm::DialFailure(_) - | FromSwarm::ListenFailure(_) - | FromSwarm::NewListener(_) - | FromSwarm::NewListenAddr(_) - | FromSwarm::ExpiredListenAddr(_) - | FromSwarm::ListenerError(_) - | FromSwarm::ListenerClosed(_) - | FromSwarm::NewExternalAddrCandidate(_) - | FromSwarm::ExternalAddrConfirmed(_) - | FromSwarm::ExternalAddrExpired(_) => {} + _ => {} }; self.request_response.on_swarm_event(event); diff --git a/protocols/ping/src/handler.rs b/protocols/ping/src/handler.rs index 522663196e6..19046776315 100644 --- a/protocols/ping/src/handler.rs +++ b/protocols/ping/src/handler.rs @@ -365,10 +365,7 @@ impl ConnectionHandler for Handler { ConnectionEvent::DialUpgradeError(dial_upgrade_error) => { self.on_dial_upgrade_error(dial_upgrade_error) } - ConnectionEvent::AddressChange(_) - | ConnectionEvent::ListenUpgradeError(_) - | ConnectionEvent::LocalProtocolsChange(_) - | ConnectionEvent::RemoteProtocolsChange(_) => {} + _ => {} } } } diff --git a/protocols/ping/src/lib.rs b/protocols/ping/src/lib.rs index d1c4a2facaf..78ae515c068 100644 --- a/protocols/ping/src/lib.rs +++ b/protocols/ping/src/lib.rs @@ -155,19 +155,7 @@ impl NetworkBehaviour for Behaviour { fn on_swarm_event(&mut self, event: FromSwarm) { match event { - FromSwarm::ConnectionEstablished(_) - | FromSwarm::ConnectionClosed(_) - | FromSwarm::AddressChange(_) - | FromSwarm::DialFailure(_) - | FromSwarm::ListenFailure(_) - | FromSwarm::NewListener(_) - | FromSwarm::NewListenAddr(_) - | FromSwarm::ExpiredListenAddr(_) - | FromSwarm::ListenerError(_) - | FromSwarm::ListenerClosed(_) - | FromSwarm::NewExternalAddrCandidate(_) - | FromSwarm::ExternalAddrExpired(_) - | FromSwarm::ExternalAddrConfirmed(_) => {} + _ => {} } } } diff --git a/protocols/relay/src/behaviour.rs b/protocols/relay/src/behaviour.rs index 9e49b9cea08..e94a94538e1 100644 --- a/protocols/relay/src/behaviour.rs +++ b/protocols/relay/src/behaviour.rs @@ -339,18 +339,7 @@ impl NetworkBehaviour for Behaviour { FromSwarm::ConnectionClosed(connection_closed) => { self.on_connection_closed(connection_closed) } - FromSwarm::ConnectionEstablished(_) - | FromSwarm::DialFailure(_) - | FromSwarm::AddressChange(_) - | FromSwarm::ListenFailure(_) - | FromSwarm::NewListener(_) - | FromSwarm::NewListenAddr(_) - | FromSwarm::ExpiredListenAddr(_) - | FromSwarm::ListenerError(_) - | FromSwarm::ListenerClosed(_) - | FromSwarm::NewExternalAddrCandidate(_) - | FromSwarm::ExternalAddrExpired(_) - | FromSwarm::ExternalAddrConfirmed(_) => {} + _ => {} } } diff --git a/protocols/relay/src/behaviour/handler.rs b/protocols/relay/src/behaviour/handler.rs index 895228e807b..0e695be0309 100644 --- a/protocols/relay/src/behaviour/handler.rs +++ b/protocols/relay/src/behaviour/handler.rs @@ -922,10 +922,7 @@ impl ConnectionHandler for Handler { ConnectionEvent::DialUpgradeError(dial_upgrade_error) => { self.on_dial_upgrade_error(dial_upgrade_error); } - ConnectionEvent::AddressChange(_) - | ConnectionEvent::ListenUpgradeError(_) - | ConnectionEvent::LocalProtocolsChange(_) - | ConnectionEvent::RemoteProtocolsChange(_) => {} + _ => {} } } } diff --git a/protocols/relay/src/priv_client.rs b/protocols/relay/src/priv_client.rs index d4f0c07cae3..aeb133eeaab 100644 --- a/protocols/relay/src/priv_client.rs +++ b/protocols/relay/src/priv_client.rs @@ -221,16 +221,7 @@ impl NetworkBehaviour for Behaviour { FromSwarm::DialFailure(DialFailure { connection_id, .. }) => { self.pending_handler_commands.remove(&connection_id); } - FromSwarm::AddressChange(_) - | FromSwarm::ListenFailure(_) - | FromSwarm::NewListener(_) - | FromSwarm::NewListenAddr(_) - | FromSwarm::ExpiredListenAddr(_) - | FromSwarm::ListenerError(_) - | FromSwarm::ListenerClosed(_) - | FromSwarm::NewExternalAddrCandidate(_) - | FromSwarm::ExternalAddrExpired(_) - | FromSwarm::ExternalAddrConfirmed(_) => {} + _ => {} } } diff --git a/protocols/relay/src/priv_client/handler.rs b/protocols/relay/src/priv_client/handler.rs index 25488ac3041..2b9b7cbb2fe 100644 --- a/protocols/relay/src/priv_client/handler.rs +++ b/protocols/relay/src/priv_client/handler.rs @@ -577,9 +577,7 @@ impl ConnectionHandler for Handler { ConnectionEvent::DialUpgradeError(dial_upgrade_error) => { self.on_dial_upgrade_error(dial_upgrade_error) } - ConnectionEvent::AddressChange(_) - | ConnectionEvent::LocalProtocolsChange(_) - | ConnectionEvent::RemoteProtocolsChange(_) => {} + _ => {} } } } diff --git a/protocols/rendezvous/src/client.rs b/protocols/rendezvous/src/client.rs index 505635efda8..010adae3500 100644 --- a/protocols/rendezvous/src/client.rs +++ b/protocols/rendezvous/src/client.rs @@ -281,6 +281,7 @@ impl NetworkBehaviour for Behaviour { return Poll::Ready(new_to_swarm); } + Poll::Ready(_) => {} Poll::Pending => {} } diff --git a/protocols/rendezvous/src/server.rs b/protocols/rendezvous/src/server.rs index 44f2f97a6a0..69b5bc09369 100644 --- a/protocols/rendezvous/src/server.rs +++ b/protocols/rendezvous/src/server.rs @@ -224,6 +224,7 @@ impl NetworkBehaviour for Behaviour { return Poll::Ready(new_to_swarm); } + _ => {} }; } diff --git a/protocols/request-response/src/handler.rs b/protocols/request-response/src/handler.rs index 35a2db98bdc..61a9229e6fa 100644 --- a/protocols/request-response/src/handler.rs +++ b/protocols/request-response/src/handler.rs @@ -375,9 +375,7 @@ where ConnectionEvent::ListenUpgradeError(listen_upgrade_error) => { self.on_listen_upgrade_error(listen_upgrade_error) } - ConnectionEvent::AddressChange(_) - | ConnectionEvent::LocalProtocolsChange(_) - | ConnectionEvent::RemoteProtocolsChange(_) => {} + _ => {} } } } diff --git a/protocols/request-response/src/lib.rs b/protocols/request-response/src/lib.rs index 7b1a8088443..19f74ceea46 100644 --- a/protocols/request-response/src/lib.rs +++ b/protocols/request-response/src/lib.rs @@ -775,15 +775,7 @@ where } FromSwarm::AddressChange(address_change) => self.on_address_change(address_change), FromSwarm::DialFailure(dial_failure) => self.on_dial_failure(dial_failure), - FromSwarm::ListenFailure(_) => {} - FromSwarm::NewListener(_) => {} - FromSwarm::NewListenAddr(_) => {} - FromSwarm::ExpiredListenAddr(_) => {} - FromSwarm::ListenerError(_) => {} - FromSwarm::ListenerClosed(_) => {} - FromSwarm::NewExternalAddrCandidate(_) => {} - FromSwarm::ExternalAddrExpired(_) => {} - FromSwarm::ExternalAddrConfirmed(_) => {} + _ => {} } } diff --git a/protocols/upnp/src/behaviour.rs b/protocols/upnp/src/behaviour.rs index 45b82edc562..897712618ed 100644 --- a/protocols/upnp/src/behaviour.rs +++ b/protocols/upnp/src/behaviour.rs @@ -344,17 +344,7 @@ impl NetworkBehaviour for Behaviour { } } } - FromSwarm::ConnectionEstablished(_) - | FromSwarm::ConnectionClosed(_) - | FromSwarm::AddressChange(_) - | FromSwarm::DialFailure(_) - | FromSwarm::ListenFailure(_) - | FromSwarm::NewListener(_) - | FromSwarm::ListenerError(_) - | FromSwarm::ListenerClosed(_) - | FromSwarm::NewExternalAddrCandidate(_) - | FromSwarm::ExternalAddrConfirmed(_) - | FromSwarm::ExternalAddrExpired(_) => {} + _ => {} } } diff --git a/swarm-derive/src/lib.rs b/swarm-derive/src/lib.rs index e54cd058daf..5ace9f3b4df 100644 --- a/swarm-derive/src/lib.rs +++ b/swarm-derive/src/lib.rs @@ -757,6 +757,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> syn::Result { return std::task::Poll::Ready(#network_behaviour_action::CloseConnection { peer_id, connection }); } + std::task::Poll::Ready(_) => {}, std::task::Poll::Pending => {}, } } diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index 230134862df..b1613e7164c 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.44.0 - unreleased + +- Added `#[non_exhaustive]` to `FromSwarm`, `ToSwarm`, `SwarmEvent`, `ConnectionHandlerEvent`, `ConnectionEevnt`. + See [PR XXXX](https://github.com/libp2p/rust-libp2p/pull/XXXX). + ## 0.43.5 - Fix overflow in `KeepAlive` computation that could occur if `SwarmBuilder::idle_connection_timeout` is configured with `u64::MAX`. diff --git a/swarm/src/behaviour.rs b/swarm/src/behaviour.rs index d80f5f0c9a4..d974590ee5f 100644 --- a/swarm/src/behaviour.rs +++ b/swarm/src/behaviour.rs @@ -237,6 +237,7 @@ pub trait PollParameters { /// /// [`Swarm`]: super::Swarm #[derive(Debug)] +#[non_exhaustive] pub enum ToSwarm { /// Instructs the `Swarm` to return an event when it is being polled. GenerateEvent(TOutEvent), @@ -409,6 +410,7 @@ pub enum CloseConnection { /// Enumeration with the list of the possible events /// to pass to [`on_swarm_event`](NetworkBehaviour::on_swarm_event). #[derive(Debug)] +#[non_exhaustive] pub enum FromSwarm<'a, Handler> { /// Informs the behaviour about a newly established connection to a peer. ConnectionEstablished(ConnectionEstablished<'a>), diff --git a/swarm/src/handler.rs b/swarm/src/handler.rs index 9374903f9b7..8f14da6e555 100644 --- a/swarm/src/handler.rs +++ b/swarm/src/handler.rs @@ -205,6 +205,7 @@ pub trait ConnectionHandler: Send + 'static { /// Enumeration with the list of the possible stream events /// to pass to [`on_connection_event`](ConnectionHandler::on_connection_event). +#[non_exhaustive] pub enum ConnectionEvent<'a, IP: InboundUpgradeSend, OP: OutboundUpgradeSend, IOI, OOI> { /// Informs the handler about the output of a successful upgrade on a new inbound substream. FullyNegotiatedInbound(FullyNegotiatedInbound), @@ -530,6 +531,7 @@ impl SubstreamProtocol { /// Event produced by a handler. #[derive(Debug, Clone, PartialEq, Eq)] +#[non_exhaustive] pub enum ConnectionHandlerEvent { /// Request a new outbound substream to be opened with the remote. OutboundSubstreamRequest { diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 22433d22c62..a8f2433b974 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -183,6 +183,7 @@ pub type THandlerErr = as ConnectionHandler>:: /// Event generated by the `Swarm`. #[derive(Debug)] +#[non_exhaustive] pub enum SwarmEvent { /// Event generated by the `NetworkBehaviour`. Behaviour(TBehaviourOutEvent), diff --git a/swarm/tests/swarm_derive.rs b/swarm/tests/swarm_derive.rs index d0680591621..97e69819349 100644 --- a/swarm/tests/swarm_derive.rs +++ b/swarm/tests/swarm_derive.rs @@ -508,19 +508,7 @@ fn custom_out_event_no_type_parameters() { fn on_swarm_event(&mut self, event: FromSwarm) { match event { - FromSwarm::ConnectionEstablished(_) - | FromSwarm::ConnectionClosed(_) - | FromSwarm::AddressChange(_) - | FromSwarm::DialFailure(_) - | FromSwarm::ListenFailure(_) - | FromSwarm::NewListener(_) - | FromSwarm::NewListenAddr(_) - | FromSwarm::ExpiredListenAddr(_) - | FromSwarm::ListenerError(_) - | FromSwarm::ListenerClosed(_) - | FromSwarm::NewExternalAddrCandidate(_) - | FromSwarm::ExternalAddrExpired(_) - | FromSwarm::ExternalAddrConfirmed(_) => {} + _ => {} } } } From 42a018f54ec1d46920e4aac1dcef266932fff0d1 Mon Sep 17 00:00:00 2001 From: Dave Huseby Date: Mon, 2 Oct 2023 14:47:04 -0600 Subject: [PATCH 02/20] fix swarm/CHANGELOG.md Signed-off-by: Dave Huseby --- swarm/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index b1613e7164c..387670d2f92 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -1,7 +1,7 @@ ## 0.44.0 - unreleased -- Added `#[non_exhaustive]` to `FromSwarm`, `ToSwarm`, `SwarmEvent`, `ConnectionHandlerEvent`, `ConnectionEevnt`. - See [PR XXXX](https://github.com/libp2p/rust-libp2p/pull/XXXX). +- Add `#[non_exhaustive]` to `FromSwarm`, `ToSwarm`, `SwarmEvent`, `ConnectionHandlerEvent`, `ConnectionEevnt`. + See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). ## 0.43.5 From 9a844b2ee58301c6c1bbda71ec32a2636332c742 Mon Sep 17 00:00:00 2001 From: Dave Huseby Date: Mon, 2 Oct 2023 17:10:40 -0600 Subject: [PATCH 03/20] fix clippy CI error Signed-off-by: Dave Huseby --- identity/src/keypair.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/identity/src/keypair.rs b/identity/src/keypair.rs index e55fcef21e5..4876659a29b 100644 --- a/identity/src/keypair.rs +++ b/identity/src/keypair.rs @@ -382,7 +382,7 @@ impl Keypair { #[cfg(feature = "ed25519")] KeyPairInner::Ed25519(ref inner) => Some(inner.secret().to_bytes()), #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] - KeyPairInner::Rsa(_) => return None, + KeyPairInner::Rsa(_) => None, #[cfg(feature = "secp256k1")] KeyPairInner::Secp256k1(ref inner) => Some(inner.secret().to_bytes()), #[cfg(feature = "ecdsa")] From 8edbc2710e8e07825a0aaadfd5981133fd428e08 Mon Sep 17 00:00:00 2001 From: Dave Huseby Date: Mon, 2 Oct 2023 18:21:27 -0600 Subject: [PATCH 04/20] Update swarm/CHANGELOG.md Co-authored-by: Thomas Eizinger --- swarm/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index 387670d2f92..f4ef1858d34 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -1,6 +1,6 @@ ## 0.44.0 - unreleased -- Add `#[non_exhaustive]` to `FromSwarm`, `ToSwarm`, `SwarmEvent`, `ConnectionHandlerEvent`, `ConnectionEevnt`. +- Add `#[non_exhaustive]` to `FromSwarm`, `ToSwarm`, `SwarmEvent`, `ConnectionHandlerEvent`, `ConnectionEvent`. See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). ## 0.43.5 From 2c8ec273a70c66d523f563328e9bf017b1979663 Mon Sep 17 00:00:00 2001 From: Dave Huseby Date: Mon, 2 Oct 2023 20:19:19 -0600 Subject: [PATCH 05/20] more cleanup Signed-off-by: Dave Huseby --- misc/allow-block-list/src/lib.rs | 6 +----- misc/connection-limits/src/lib.rs | 2 +- protocols/perf/src/client/behaviour.rs | 12 +----------- protocols/perf/src/server/behaviour.rs | 18 +----------------- protocols/ping/src/lib.rs | 6 +----- protocols/rendezvous/src/client.rs | 2 +- swarm/src/dummy.rs | 18 +----------------- swarm/src/keep_alive.rs | 18 +----------------- swarm/src/test.rs | 18 +----------------- swarm/tests/swarm_derive.rs | 6 +----- 10 files changed, 10 insertions(+), 96 deletions(-) diff --git a/misc/allow-block-list/src/lib.rs b/misc/allow-block-list/src/lib.rs index 6694671c4c8..922919df912 100644 --- a/misc/allow-block-list/src/lib.rs +++ b/misc/allow-block-list/src/lib.rs @@ -231,11 +231,7 @@ where Ok(dummy::ConnectionHandler) } - fn on_swarm_event(&mut self, event: FromSwarm) { - match event { - _ => {} - } - } + fn on_swarm_event(&mut self, _: FromSwarm) {} fn on_connection_handler_event( &mut self, diff --git a/misc/connection-limits/src/lib.rs b/misc/connection-limits/src/lib.rs index c0170bd1f00..eff7f087943 100644 --- a/misc/connection-limits/src/lib.rs +++ b/misc/connection-limits/src/lib.rs @@ -571,7 +571,7 @@ mod tests { ))) } - fn on_swarm_event(&mut self, _event: FromSwarm) {} + fn on_swarm_event(&mut self, _: FromSwarm) {} fn on_connection_handler_event( &mut self, diff --git a/protocols/perf/src/client/behaviour.rs b/protocols/perf/src/client/behaviour.rs index 912f6d5bb9e..1bf8d1a7a48 100644 --- a/protocols/perf/src/client/behaviour.rs +++ b/protocols/perf/src/client/behaviour.rs @@ -120,17 +120,7 @@ impl NetworkBehaviour for Behaviour { assert!(self.connected.remove(&peer_id)); } } - FromSwarm::AddressChange(_) - | FromSwarm::DialFailure(_) - | FromSwarm::ListenFailure(_) - | FromSwarm::NewListener(_) - | FromSwarm::NewListenAddr(_) - | FromSwarm::ExpiredListenAddr(_) - | FromSwarm::ListenerError(_) - | FromSwarm::ListenerClosed(_) - | FromSwarm::NewExternalAddrCandidate(_) - | FromSwarm::ExternalAddrExpired(_) - | FromSwarm::ExternalAddrConfirmed(_) => {} + _ => {} } } diff --git a/protocols/perf/src/server/behaviour.rs b/protocols/perf/src/server/behaviour.rs index b15cb70110d..25684764510 100644 --- a/protocols/perf/src/server/behaviour.rs +++ b/protocols/perf/src/server/behaviour.rs @@ -77,23 +77,7 @@ impl NetworkBehaviour for Behaviour { Ok(Handler::default()) } - fn on_swarm_event(&mut self, event: FromSwarm) { - match event { - FromSwarm::ConnectionEstablished(_) => {} - FromSwarm::ConnectionClosed(_) => {} - FromSwarm::AddressChange(_) => {} - FromSwarm::DialFailure(_) => {} - FromSwarm::ListenFailure(_) => {} - FromSwarm::NewListener(_) => {} - FromSwarm::NewListenAddr(_) => {} - FromSwarm::ExpiredListenAddr(_) => {} - FromSwarm::ListenerError(_) => {} - FromSwarm::ListenerClosed(_) => {} - FromSwarm::NewExternalAddrCandidate(_) => {} - FromSwarm::ExternalAddrExpired(_) => {} - FromSwarm::ExternalAddrConfirmed(_) => {} - } - } + fn on_swarm_event(&mut self, _: FromSwarm) {} fn on_connection_handler_event( &mut self, diff --git a/protocols/ping/src/lib.rs b/protocols/ping/src/lib.rs index 78ae515c068..5559500e46e 100644 --- a/protocols/ping/src/lib.rs +++ b/protocols/ping/src/lib.rs @@ -153,9 +153,5 @@ impl NetworkBehaviour for Behaviour { } } - fn on_swarm_event(&mut self, event: FromSwarm) { - match event { - _ => {} - } - } + fn on_swarm_event(&mut self, _: FromSwarm) {} } diff --git a/protocols/rendezvous/src/client.rs b/protocols/rendezvous/src/client.rs index 010adae3500..c30c7df5ac9 100644 --- a/protocols/rendezvous/src/client.rs +++ b/protocols/rendezvous/src/client.rs @@ -281,7 +281,7 @@ impl NetworkBehaviour for Behaviour { return Poll::Ready(new_to_swarm); } - Poll::Ready(_) => {} + Poll::Ready(_) => return Poll::Pending, Poll::Pending => {} } diff --git a/swarm/src/dummy.rs b/swarm/src/dummy.rs index 6810abec591..cde6096c39a 100644 --- a/swarm/src/dummy.rs +++ b/swarm/src/dummy.rs @@ -58,23 +58,7 @@ impl NetworkBehaviour for Behaviour { Poll::Pending } - fn on_swarm_event(&mut self, event: FromSwarm) { - match event { - FromSwarm::ConnectionEstablished(_) - | FromSwarm::ConnectionClosed(_) - | FromSwarm::AddressChange(_) - | FromSwarm::DialFailure(_) - | FromSwarm::ListenFailure(_) - | FromSwarm::NewListener(_) - | FromSwarm::NewListenAddr(_) - | FromSwarm::ExpiredListenAddr(_) - | FromSwarm::ListenerError(_) - | FromSwarm::ListenerClosed(_) - | FromSwarm::NewExternalAddrCandidate(_) - | FromSwarm::ExternalAddrExpired(_) - | FromSwarm::ExternalAddrConfirmed(_) => {} - } - } + fn on_swarm_event(&mut self, _: FromSwarm) {} } /// An implementation of [`ConnectionHandler`] that neither handles any protocols nor does it keep the connection alive. diff --git a/swarm/src/keep_alive.rs b/swarm/src/keep_alive.rs index 05cbcdf7b8c..41c3308d051 100644 --- a/swarm/src/keep_alive.rs +++ b/swarm/src/keep_alive.rs @@ -61,23 +61,7 @@ impl NetworkBehaviour for Behaviour { Poll::Pending } - fn on_swarm_event(&mut self, event: FromSwarm) { - match event { - FromSwarm::ConnectionEstablished(_) - | FromSwarm::ConnectionClosed(_) - | FromSwarm::AddressChange(_) - | FromSwarm::DialFailure(_) - | FromSwarm::ListenFailure(_) - | FromSwarm::NewListener(_) - | FromSwarm::NewListenAddr(_) - | FromSwarm::ExpiredListenAddr(_) - | FromSwarm::ListenerError(_) - | FromSwarm::ListenerClosed(_) - | FromSwarm::NewExternalAddrCandidate(_) - | FromSwarm::ExternalAddrExpired(_) - | FromSwarm::ExternalAddrConfirmed(_) => {} - } - } + fn on_swarm_event(&mut self, _: FromSwarm) {} } /// Implementation of [`ConnectionHandler`] that doesn't handle anything but keeps the connection alive. diff --git a/swarm/src/test.rs b/swarm/src/test.rs index 6f39d56da91..4f08c553fd0 100644 --- a/swarm/src/test.rs +++ b/swarm/src/test.rs @@ -118,23 +118,7 @@ where self.next_action.take().map_or(Poll::Pending, Poll::Ready) } - fn on_swarm_event(&mut self, event: FromSwarm) { - match event { - FromSwarm::ConnectionEstablished(_) - | FromSwarm::ConnectionClosed(_) - | FromSwarm::AddressChange(_) - | FromSwarm::DialFailure(_) - | FromSwarm::ListenFailure(_) - | FromSwarm::NewListener(_) - | FromSwarm::NewListenAddr(_) - | FromSwarm::ExpiredListenAddr(_) - | FromSwarm::ListenerError(_) - | FromSwarm::ListenerClosed(_) - | FromSwarm::NewExternalAddrCandidate(_) - | FromSwarm::ExternalAddrExpired(_) - | FromSwarm::ExternalAddrConfirmed(_) => {} - } - } + fn on_swarm_event(&mut self, _: FromSwarm) {} fn on_connection_handler_event( &mut self, diff --git a/swarm/tests/swarm_derive.rs b/swarm/tests/swarm_derive.rs index 97e69819349..83cf12db8da 100644 --- a/swarm/tests/swarm_derive.rs +++ b/swarm/tests/swarm_derive.rs @@ -506,11 +506,7 @@ fn custom_out_event_no_type_parameters() { Poll::Pending } - fn on_swarm_event(&mut self, event: FromSwarm) { - match event { - _ => {} - } - } + fn on_swarm_event(&mut self, _event: FromSwarm) {} } #[derive(NetworkBehaviour)] From b87bf967909219bb47c62a8175412af9f4cb5f1a Mon Sep 17 00:00:00 2001 From: Dave Huseby Date: Mon, 30 Oct 2023 17:05:06 -0600 Subject: [PATCH 06/20] fixing merge errors Signed-off-by: Dave Huseby --- protocols/perf/src/client/handler.rs | 1 + protocols/perf/src/server/handler.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/protocols/perf/src/client/handler.rs b/protocols/perf/src/client/handler.rs index a9bb0c7d483..a3c5cc39294 100644 --- a/protocols/perf/src/client/handler.rs +++ b/protocols/perf/src/client/handler.rs @@ -150,6 +150,7 @@ impl ConnectionHandler for Handler { ConnectionEvent::ListenUpgradeError(ListenUpgradeError { info: (), error }) => { void::unreachable(error) } + _ => {} } } diff --git a/protocols/perf/src/server/handler.rs b/protocols/perf/src/server/handler.rs index 4e739995b67..32a87fcb3c1 100644 --- a/protocols/perf/src/server/handler.rs +++ b/protocols/perf/src/server/handler.rs @@ -112,6 +112,7 @@ impl ConnectionHandler for Handler { ConnectionEvent::ListenUpgradeError(ListenUpgradeError { info: (), error }) => { void::unreachable(error) } + _ => {} } } From 32ba7cd0b63d1ae4c9ba6ce71a6d8be0e472980c Mon Sep 17 00:00:00 2001 From: Dave Huseby Date: Mon, 30 Oct 2023 17:17:36 -0600 Subject: [PATCH 07/20] pinning libp2p-swarm-derive for safety Signed-off-by: Dave Huseby --- Cargo.lock | 2 +- Cargo.toml | 2 +- swarm-derive/Cargo.toml | 2 +- swarm/Cargo.toml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0172af429ee..9d1dc01cb5b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3071,7 +3071,7 @@ dependencies = [ [[package]] name = "libp2p-swarm-derive" -version = "0.34.0" +version = "0.35.0" dependencies = [ "heck", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index 2c823756bbe..c5cafd53df7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -99,7 +99,7 @@ libp2p-rendezvous = { version = "0.14.0", path = "protocols/rendezvous" } libp2p-request-response = { version = "0.26.0", path = "protocols/request-response" } libp2p-server = { version = "0.12.3", path = "misc/server" } libp2p-swarm = { version = "0.44.0", path = "swarm" } -libp2p-swarm-derive = { version = "0.34.0", path = "swarm-derive" } +libp2p-swarm-derive = { version = "=0.35.0", path = "swarm-derive" } libp2p-swarm-test = { version = "0.3.0", path = "swarm-test" } libp2p-tcp = { version = "0.41.0", path = "transports/tcp" } libp2p-tls = { version = "0.3.0", path = "transports/tls" } diff --git a/swarm-derive/Cargo.toml b/swarm-derive/Cargo.toml index 61aac588a80..6a5afe1e0da 100644 --- a/swarm-derive/Cargo.toml +++ b/swarm-derive/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-swarm-derive" edition = "2021" rust-version = { workspace = true } description = "Procedural macros of libp2p-swarm" -version = "0.34.0" +version = "0.35.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index 116604987f8..cb76db9ec4c 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -48,7 +48,7 @@ libp2p-identity = { workspace = true, features = ["ed25519"] } libp2p-kad = { path = "../protocols/kad" } # Using `path` here because this is a cyclic dev-dependency which otherwise breaks releasing. libp2p-ping = { path = "../protocols/ping" } # Using `path` here because this is a cyclic dev-dependency which otherwise breaks releasing. libp2p-plaintext = { path = "../transports/plaintext" } # Using `path` here because this is a cyclic dev-dependency which otherwise breaks releasing. -libp2p-swarm-derive = { path = "../swarm-derive" } # Using `path` here because this is a cyclic dev-dependency which otherwise breaks releasing. +libp2p-swarm-derive = { version = "=0.35.0", path = "../swarm-derive" } # Using `path` here because this is a cyclic dev-dependency which otherwise breaks releasing. libp2p-swarm-test = { path = "../swarm-test" } # Using `path` here because this is a cyclic dev-dependency which otherwise breaks releasing. libp2p-yamux = { path = "../muxers/yamux" } # Using `path` here because this is a cyclic dev-dependency which otherwise breaks releasing. quickcheck = { workspace = true } From b8fd915bc013abdf6d13b1c12973edfb3f162f78 Mon Sep 17 00:00:00 2001 From: Dave Huseby Date: Mon, 30 Oct 2023 23:10:32 -0600 Subject: [PATCH 08/20] integrating review changes Signed-off-by: Dave Huseby --- Cargo.lock | 2 +- Cargo.toml | 2 +- protocols/rendezvous/src/client.rs | 12 +----------- swarm-derive/Cargo.toml | 2 +- swarm/Cargo.toml | 2 +- 5 files changed, 5 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9d1dc01cb5b..0172af429ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3071,7 +3071,7 @@ dependencies = [ [[package]] name = "libp2p-swarm-derive" -version = "0.35.0" +version = "0.34.0" dependencies = [ "heck", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index c5cafd53df7..a93880a1eee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -99,7 +99,7 @@ libp2p-rendezvous = { version = "0.14.0", path = "protocols/rendezvous" } libp2p-request-response = { version = "0.26.0", path = "protocols/request-response" } libp2p-server = { version = "0.12.3", path = "misc/server" } libp2p-swarm = { version = "0.44.0", path = "swarm" } -libp2p-swarm-derive = { version = "=0.35.0", path = "swarm-derive" } +libp2p-swarm-derive = { version = "=0.34.0", path = "swarm-derive" } libp2p-swarm-test = { version = "0.3.0", path = "swarm-test" } libp2p-tcp = { version = "0.41.0", path = "transports/tcp" } libp2p-tls = { version = "0.3.0", path = "transports/tls" } diff --git a/protocols/rendezvous/src/client.rs b/protocols/rendezvous/src/client.rs index 771b16c2134..cba48c890c5 100644 --- a/protocols/rendezvous/src/client.rs +++ b/protocols/rendezvous/src/client.rs @@ -280,22 +280,12 @@ impl NetworkBehaviour for Behaviour { )) => { unreachable!("rendezvous clients never receive requests") } - Poll::Ready( - other @ (ToSwarm::ExternalAddrConfirmed(_) - | ToSwarm::ExternalAddrExpired(_) - | ToSwarm::NewExternalAddrCandidate(_) - | ToSwarm::NotifyHandler { .. } - | ToSwarm::Dial { .. } - | ToSwarm::CloseConnection { .. } - | ToSwarm::ListenOn { .. } - | ToSwarm::RemoveListener { .. }), - ) => { + Poll::Ready(other @ _) => { let new_to_swarm = other.map_out(|_| unreachable!("we manually map `GenerateEvent` variants")); return Poll::Ready(new_to_swarm); } - Poll::Ready(_) => return Poll::Pending, Poll::Pending => {} } diff --git a/swarm-derive/Cargo.toml b/swarm-derive/Cargo.toml index 6a5afe1e0da..61aac588a80 100644 --- a/swarm-derive/Cargo.toml +++ b/swarm-derive/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-swarm-derive" edition = "2021" rust-version = { workspace = true } description = "Procedural macros of libp2p-swarm" -version = "0.35.0" +version = "0.34.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index cb76db9ec4c..116604987f8 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -48,7 +48,7 @@ libp2p-identity = { workspace = true, features = ["ed25519"] } libp2p-kad = { path = "../protocols/kad" } # Using `path` here because this is a cyclic dev-dependency which otherwise breaks releasing. libp2p-ping = { path = "../protocols/ping" } # Using `path` here because this is a cyclic dev-dependency which otherwise breaks releasing. libp2p-plaintext = { path = "../transports/plaintext" } # Using `path` here because this is a cyclic dev-dependency which otherwise breaks releasing. -libp2p-swarm-derive = { version = "=0.35.0", path = "../swarm-derive" } # Using `path` here because this is a cyclic dev-dependency which otherwise breaks releasing. +libp2p-swarm-derive = { path = "../swarm-derive" } # Using `path` here because this is a cyclic dev-dependency which otherwise breaks releasing. libp2p-swarm-test = { path = "../swarm-test" } # Using `path` here because this is a cyclic dev-dependency which otherwise breaks releasing. libp2p-yamux = { path = "../muxers/yamux" } # Using `path` here because this is a cyclic dev-dependency which otherwise breaks releasing. quickcheck = { workspace = true } From 733e61771e8cac205ea407c4a8d70594cb2930fc Mon Sep 17 00:00:00 2001 From: Dave Huseby Date: Tue, 31 Oct 2023 12:06:10 -0600 Subject: [PATCH 09/20] Update Cargo.toml add a warning to future developers about bumping the version. Co-authored-by: Max Inden --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index a93880a1eee..b7abe4c833d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -99,6 +99,7 @@ libp2p-rendezvous = { version = "0.14.0", path = "protocols/rendezvous" } libp2p-request-response = { version = "0.26.0", path = "protocols/request-response" } libp2p-server = { version = "0.12.3", path = "misc/server" } libp2p-swarm = { version = "0.44.0", path = "swarm" } +# `libp2p-swarm-derive` may not be compatible with different `libp2p-swarm` non-breaking releases. E.g. `libp2p-swarm` might introduce a new enum variant `FromSwarm` (which is `#[non-exhaustive]`) in a non-breaking release. Older versions of `libp2p-swarm-derive` would not forward this enum variant within the `NetworkBehaviour` hierarchy. Thus the version pinning is required. libp2p-swarm-derive = { version = "=0.34.0", path = "swarm-derive" } libp2p-swarm-test = { version = "0.3.0", path = "swarm-test" } libp2p-tcp = { version = "0.41.0", path = "transports/tcp" } From 30f1665f1553df97bd184e35ca543a3ddfe37c29 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 1 Nov 2023 21:13:13 +1100 Subject: [PATCH 10/20] Simplify derive code --- swarm-derive/src/lib.rs | 94 +++++++++++++---------------------------- 1 file changed, 30 insertions(+), 64 deletions(-) diff --git a/swarm-derive/src/lib.rs b/swarm-derive/src/lib.rs index e213c423e33..514975390b0 100644 --- a/swarm-derive/src/lib.rs +++ b/swarm-derive/src/lib.rs @@ -672,80 +672,47 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> syn::Result { - return std::task::Poll::Ready(#network_behaviour_action::GenerateEvent(#into_out_event)) - } - } - }; + let map_in_event = quote! { |event| #wrapped_event }; - quote!{ - match #trait_to_impl::poll(&mut self.#field, cx) { - #generate_event_match_arm - std::task::Poll::Ready(#network_behaviour_action::Dial { opts }) => { - return std::task::Poll::Ready(#network_behaviour_action::Dial { opts }); - } - std::task::Poll::Ready(#network_behaviour_action::ListenOn { opts }) => { - return std::task::Poll::Ready(#network_behaviour_action::ListenOn { opts }); - } - std::task::Poll::Ready(#network_behaviour_action::RemoveListener { id }) => { - return std::task::Poll::Ready(#network_behaviour_action::RemoveListener { id }); - } - std::task::Poll::Ready(#network_behaviour_action::NotifyHandler { peer_id, handler, event }) => { - return std::task::Poll::Ready(#network_behaviour_action::NotifyHandler { - peer_id, - handler, - event: #wrapped_event, - }); - } - std::task::Poll::Ready(#network_behaviour_action::NewExternalAddrCandidate(addr)) => { - return std::task::Poll::Ready(#network_behaviour_action::NewExternalAddrCandidate(addr)); - } - std::task::Poll::Ready(#network_behaviour_action::ExternalAddrConfirmed(addr)) => { - return std::task::Poll::Ready(#network_behaviour_action::ExternalAddrConfirmed(addr)); - } - std::task::Poll::Ready(#network_behaviour_action::ExternalAddrExpired(addr)) => { - return std::task::Poll::Ready(#network_behaviour_action::ExternalAddrExpired(addr)); - } - std::task::Poll::Ready(#network_behaviour_action::CloseConnection { peer_id, connection }) => { - return std::task::Poll::Ready(#network_behaviour_action::CloseConnection { peer_id, connection }); + quote! { + match #trait_to_impl::poll(&mut self.#field, cx) { + std::task::Poll::Ready(e) => return std::task::Poll::Ready(e.map_out(#map_out_event).map_in(#map_in_event)), + std::task::Poll::Pending => {}, } - std::task::Poll::Ready(_) => {}, - std::task::Poll::Pending => {}, } - } - }); + }); let out_event_reference = if out_event_definition.is_some() { quote! { #out_event_name #ty_generics } @@ -820,7 +787,6 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> syn::Result std::task::Poll<#network_behaviour_action>> { - use #prelude_path::futures::*; #(#poll_stmts)* std::task::Poll::Pending } From 717a577818c3ccfecb75e0c0ddafc66bac5ecec6 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 1 Nov 2023 21:13:54 +1100 Subject: [PATCH 11/20] Fix clippy warnings --- protocols/relay/src/behaviour.rs | 7 ++----- protocols/rendezvous/src/client.rs | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/protocols/relay/src/behaviour.rs b/protocols/relay/src/behaviour.rs index ecaf17f2b90..e5faa28e176 100644 --- a/protocols/relay/src/behaviour.rs +++ b/protocols/relay/src/behaviour.rs @@ -335,11 +335,8 @@ impl NetworkBehaviour for Behaviour { fn on_swarm_event(&mut self, event: FromSwarm) { self.external_addresses.on_swarm_event(&event); - match event { - FromSwarm::ConnectionClosed(connection_closed) => { - self.on_connection_closed(connection_closed) - } - _ => {} + if let FromSwarm::ConnectionClosed(connection_closed) = event { + self.on_connection_closed(connection_closed) } } diff --git a/protocols/rendezvous/src/client.rs b/protocols/rendezvous/src/client.rs index cba48c890c5..77483084b4a 100644 --- a/protocols/rendezvous/src/client.rs +++ b/protocols/rendezvous/src/client.rs @@ -280,7 +280,7 @@ impl NetworkBehaviour for Behaviour { )) => { unreachable!("rendezvous clients never receive requests") } - Poll::Ready(other @ _) => { + Poll::Ready(other) => { let new_to_swarm = other.map_out(|_| unreachable!("we manually map `GenerateEvent` variants")); From c750a58d089119ade7a4f4b8ec68ff3d389c5fa7 Mon Sep 17 00:00:00 2001 From: Dave Huseby Date: Wed, 1 Nov 2023 12:40:44 -0600 Subject: [PATCH 12/20] move swarm-derive comment to the same line in Cargo.toml Signed-off-by: Dave Huseby --- Cargo.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1b904533321..96b795e0726 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -99,8 +99,7 @@ libp2p-rendezvous = { version = "0.14.0", path = "protocols/rendezvous" } libp2p-request-response = { version = "0.26.0", path = "protocols/request-response" } libp2p-server = { version = "0.12.3", path = "misc/server" } libp2p-swarm = { version = "0.44.0", path = "swarm" } -# `libp2p-swarm-derive` may not be compatible with different `libp2p-swarm` non-breaking releases. E.g. `libp2p-swarm` might introduce a new enum variant `FromSwarm` (which is `#[non-exhaustive]`) in a non-breaking release. Older versions of `libp2p-swarm-derive` would not forward this enum variant within the `NetworkBehaviour` hierarchy. Thus the version pinning is required. -libp2p-swarm-derive = { version = "=0.34.0", path = "swarm-derive" } +libp2p-swarm-derive = { version = "=0.34.0", path = "swarm-derive" } # `libp2p-swarm-derive` may not be compatible with different `libp2p-swarm` non-breaking releases. E.g. `libp2p-swarm` might introduce a new enum variant `FromSwarm` (which is `#[non-exhaustive]`) in a non-breaking release. Older versions of `libp2p-swarm-derive` would not forward this enum variant within the `NetworkBehaviour` hierarchy. Thus the version pinning is required. libp2p-swarm-test = { version = "0.3.0", path = "swarm-test" } libp2p-tcp = { version = "0.41.0", path = "transports/tcp" } libp2p-tls = { version = "0.3.0", path = "transports/tls" } From 344e012d5ca260f37d11026dbe99697696c30e88 Mon Sep 17 00:00:00 2001 From: Dave Huseby Date: Wed, 1 Nov 2023 17:00:58 -0600 Subject: [PATCH 13/20] updating CHANGELOGs Signed-off-by: Dave Huseby --- misc/allow-block-list/CHANGELOG.md | 4 +++- misc/connection-limits/CHANGELOG.md | 2 ++ misc/metrics/CHANGELOG.md | 2 ++ protocols/autonat/CHANGELOG.md | 4 +++- protocols/dcutr/CHANGELOG.md | 4 +++- protocols/floodsub/CHANGELOG.md | 2 ++ protocols/gossipsub/CHANGELOG.md | 2 ++ protocols/identify/CHANGELOG.md | 4 +++- protocols/kad/CHANGELOG.md | 6 ++++-- protocols/perf/CHANGELOG.md | 2 ++ protocols/ping/CHANGELOG.md | 2 ++ protocols/relay/CHANGELOG.md | 6 ++++-- protocols/rendezvous/CHANGELOG.md | 2 ++ protocols/request-response/CHANGELOG.md | 2 ++ protocols/upnp/CHANGELOG.md | 2 ++ 15 files changed, 38 insertions(+), 8 deletions(-) diff --git a/misc/allow-block-list/CHANGELOG.md b/misc/allow-block-list/CHANGELOG.md index d9b8e0c6de1..1ff1349f6e1 100644 --- a/misc/allow-block-list/CHANGELOG.md +++ b/misc/allow-block-list/CHANGELOG.md @@ -1,7 +1,9 @@ ## 0.3.0 - unreleased +- Clean up on_swarm_event handler. + See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). -## 0.2.0 +## 0.2.0 - Raise MSRV to 1.65. See [PR 3715]. diff --git a/misc/connection-limits/CHANGELOG.md b/misc/connection-limits/CHANGELOG.md index 36884867b97..42ed9dab973 100644 --- a/misc/connection-limits/CHANGELOG.md +++ b/misc/connection-limits/CHANGELOG.md @@ -1,5 +1,7 @@ ## 0.3.0 - unreleased +- Add `_ => {}` arm to `#[non_exhaustive]` enum `match`es + See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). ## 0.2.1 diff --git a/misc/metrics/CHANGELOG.md b/misc/metrics/CHANGELOG.md index acad2043fc8..4901159342e 100644 --- a/misc/metrics/CHANGELOG.md +++ b/misc/metrics/CHANGELOG.md @@ -1,5 +1,7 @@ ## 0.14.0 - unreleased +- Add `_ => {}` arm to `#[non_exhaustive]` enum `match`es + See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). - Add metrics for `SwarmEvent::{NewExternalAddrCandidate,ExternalAddrConfirmed,ExternalAddrExpired}`. See [PR 4721](https://github.com/libp2p/rust-libp2p/pull/4721). diff --git a/protocols/autonat/CHANGELOG.md b/protocols/autonat/CHANGELOG.md index 2b14598bd3e..ee7d9ef58e7 100644 --- a/protocols/autonat/CHANGELOG.md +++ b/protocols/autonat/CHANGELOG.md @@ -1,10 +1,12 @@ ## 0.12.0 - unreleased +- Add `_ => {}` arm to `#[non_exhaustive]` enum `match`es + See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). - Remove `Clone`, `PartialEq` and `Eq` implementations on `Event` and its sub-structs. The `Event` also contains errors which are not clonable or comparable. See [PR 3914](https://github.com/libp2p/rust-libp2p/pull/3914). -## 0.11.0 +## 0.11.0 - Raise MSRV to 1.65. See [PR 3715]. diff --git a/protocols/dcutr/CHANGELOG.md b/protocols/dcutr/CHANGELOG.md index cb84020ec5f..781be8176ad 100644 --- a/protocols/dcutr/CHANGELOG.md +++ b/protocols/dcutr/CHANGELOG.md @@ -1,5 +1,7 @@ ## 0.11.0 - unreleased +- Add `_ => {}` arm to `#[non_exhaustive]` enum `match`es + See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). - Add `ConnectionId` to `Event::DirectConnectionUpgradeSucceeded` and `Event::DirectConnectionUpgradeFailed`. See [PR 4558](https://github.com/libp2p/rust-libp2p/pull/4558). - Exchange address _candidates_ instead of external addresses in `CONNECT`. @@ -9,7 +11,7 @@ We now only emit a single event: whether the hole-punch was successful or not. See [PR XXXX](https://github.com/libp2p/rust-libp2p/pull/XXXX). -## 0.10.0 +## 0.10.0 - Raise MSRV to 1.65. See [PR 3715]. diff --git a/protocols/floodsub/CHANGELOG.md b/protocols/floodsub/CHANGELOG.md index 3891a09f4d4..7bec5a26b88 100644 --- a/protocols/floodsub/CHANGELOG.md +++ b/protocols/floodsub/CHANGELOG.md @@ -1,5 +1,7 @@ ## 0.44.0 - unreleased +- Add `_ => {}` arm to `#[non_exhaustive]` enum `match`es + See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). - Change publish to require `data: impl Into` to internally avoid any costly cloning / allocation. See [PR 4754](https://github.com/libp2p/rust-libp2p/pull/4754). diff --git a/protocols/gossipsub/CHANGELOG.md b/protocols/gossipsub/CHANGELOG.md index b86ec4de6d4..ae46a396e4f 100644 --- a/protocols/gossipsub/CHANGELOG.md +++ b/protocols/gossipsub/CHANGELOG.md @@ -1,5 +1,7 @@ ## 0.46.0 - unreleased +- Add `_ => {}` arm to `#[non_exhaustive]` enum `match`es + See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). - Remove `fast_message_id_fn` mechanism from `Config`. See [PR 4285](https://github.com/libp2p/rust-libp2p/pull/4285). - Remove deprecated `gossipsub::Config::idle_timeout` in favor of `SwarmBuilder::idle_connection_timeout`. diff --git a/protocols/identify/CHANGELOG.md b/protocols/identify/CHANGELOG.md index 960ed530682..b9e790ef09f 100644 --- a/protocols/identify/CHANGELOG.md +++ b/protocols/identify/CHANGELOG.md @@ -1,5 +1,7 @@ ## 0.44.0 - unreleased +- Add `_ => {}` arm to `#[non_exhaustive]` enum `match`es + See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). - Add `Info` to the `libp2p-identify::Event::Pushed` to report pushed info. See [PR 4527](https://github.com/libp2p/rust-libp2p/pull/4527) - Remove deprecated `initial_delay`. @@ -7,7 +9,7 @@ See [PR 4735](https://github.com/libp2p/rust-libp2p/pull/4735) - Don't repeatedly report the same observed address as a `NewExternalAddrCandidate`. Instead, only report each observed address once per connection. - This allows users to probabilistically deem an address as external if it gets reported as a candidate repeatedly. + This allows users to probabilistically deem an address as external if it gets reported as a candidate repeatedly. See [PR 4721](https://github.com/libp2p/rust-libp2p/pull/4721). ## 0.43.1 diff --git a/protocols/kad/CHANGELOG.md b/protocols/kad/CHANGELOG.md index d2b92195ab3..b3899a2afd7 100644 --- a/protocols/kad/CHANGELOG.md +++ b/protocols/kad/CHANGELOG.md @@ -1,5 +1,7 @@ -## 0.45.0 - unreleased +## -1.45.0 - unreleased +- Add `_ => {}` arm to `#[non_exhaustive]` enum `match`es + See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). - Remove deprecated `kad::Config::set_connection_idle_timeout` in favor of `SwarmBuilder::idle_connection_timeout`. See [PR 4659](https://github.com/libp2p/rust-libp2p/pull/4659). - Emit `ModeChanged` event whenever we automatically reconfigure the mode. @@ -10,7 +12,7 @@ See [PR 4698](https://github.com/libp2p/rust-libp2p/pull/4698). - Remove previously deprecated type-aliases. Users should follow the convention of importing the `libp2p::kad` module and referring to symbols as `kad::Behaviour` etc. - See [PR 4733](https://github.com/libp2p/rust-libp2p/pull/4733). + See [PR 4733](https://github.com/libp2p/rust-libp2p/pull/4733). ## 0.44.6 diff --git a/protocols/perf/CHANGELOG.md b/protocols/perf/CHANGELOG.md index 6976a89887b..3cee1d96ea9 100644 --- a/protocols/perf/CHANGELOG.md +++ b/protocols/perf/CHANGELOG.md @@ -1,5 +1,7 @@ ## 0.3.0 - unreleased +- Add `_ => {}` arm to `#[non_exhaustive]` enum `match`es + See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). - Continuously measure on single connection (iperf-style). See https://github.com/libp2p/test-plans/issues/261 for high level overview. See [PR 4382](https://github.com/libp2p/rust-libp2p/pull/4382). diff --git a/protocols/ping/CHANGELOG.md b/protocols/ping/CHANGELOG.md index b94b4581a6a..63ce8ed7004 100644 --- a/protocols/ping/CHANGELOG.md +++ b/protocols/ping/CHANGELOG.md @@ -1,5 +1,7 @@ ## 0.44.0 - unreleased +- Add `_ => {}` arm to `#[non_exhaustive]` enum `match`es + See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). ## 0.43.1 diff --git a/protocols/relay/CHANGELOG.md b/protocols/relay/CHANGELOG.md index 200cc4bc18d..9c95fc3de92 100644 --- a/protocols/relay/CHANGELOG.md +++ b/protocols/relay/CHANGELOG.md @@ -1,5 +1,7 @@ ## 0.17.0 - unreleased +- Add `_ => {}` arm to `#[non_exhaustive]` enum `match`es + See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). - Don't close connections on protocol failures within the relay-server. To achieve this, error handling was restructured: - `libp2p::relay::outbound::stop::FatalUpgradeError` has been removed. @@ -10,7 +12,7 @@ - Fix a rare race condition when making a reservation on a relay that could lead to a failed reservation. See [PR 4747](https://github.com/libp2p/rust-lib2pp/pulls/4747). - Propagate errors of relay client to the listener / dialer. - A failed reservation will now appear as `SwarmEvent::ListenerClosed` with the `ListenerId` of the corresponding `Swarm::listen_on` call. + A failed reservation will now appear as `SwarmEvent::ListenerClosed` with the `ListenerId` of the corresponding `Swarm::listen_on` call. A failed circuit request will now appear as `SwarmEvent::OutgoingConnectionError` with the `ConnectionId` of the corresponding `Swarm::dial` call. Lastly, a failed reservation or circuit request will **no longer** close the underlying relay connection. As a result, we remove the following enum variants: @@ -18,7 +20,7 @@ - `relay::client::Event::OutboundCircuitReqFailed` - `relay::client::Event::InboundCircuitReqDenied` - `relay::client::Event::InboundCircuitReqDenyFailed` - + See [PR 4745](https://github.com/libp2p/rust-lib2pp/pulls/4745). ## 0.16.2 diff --git a/protocols/rendezvous/CHANGELOG.md b/protocols/rendezvous/CHANGELOG.md index 7b75b35ae9c..77223678077 100644 --- a/protocols/rendezvous/CHANGELOG.md +++ b/protocols/rendezvous/CHANGELOG.md @@ -1,5 +1,7 @@ ## 0.14.0 - unreleased +- Add `_ => {}` arm to `#[non_exhaustive]` enum `match`es + See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). ## 0.13.1 - Refresh registration upon a change in external addresses. diff --git a/protocols/request-response/CHANGELOG.md b/protocols/request-response/CHANGELOG.md index 138401c2f50..e0c9f62de7b 100644 --- a/protocols/request-response/CHANGELOG.md +++ b/protocols/request-response/CHANGELOG.md @@ -1,5 +1,7 @@ ## 0.26.0 - unreleased +- Add `_ => {}` arm to `#[non_exhaustive]` enum `match`es + See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). - Remove `request_response::Config::set_connection_keep_alive` in favor of `SwarmBuilder::idle_connection_timeout`. See [PR 4679](https://github.com/libp2p/rust-libp2p/pull/4679). - Allow at most 100 concurrent inbound + outbound streams per instance of `request_response::Behaviour`. diff --git a/protocols/upnp/CHANGELOG.md b/protocols/upnp/CHANGELOG.md index 75aeaf64d6e..39f47ffa265 100644 --- a/protocols/upnp/CHANGELOG.md +++ b/protocols/upnp/CHANGELOG.md @@ -1,5 +1,7 @@ ## 0.2.0 - unreleased +- Add `_ => {}` arm to `#[non_exhaustive]` enum `match`es + See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). ## 0.1.1 From 21efd9ebe9d3c7099167bea666281c0c6921f84e Mon Sep 17 00:00:00 2001 From: Dave Huseby Date: Wed, 1 Nov 2023 17:13:26 -0600 Subject: [PATCH 14/20] fixing kad CHANGELOG Signed-off-by: Dave Huseby --- protocols/kad/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protocols/kad/CHANGELOG.md b/protocols/kad/CHANGELOG.md index b3899a2afd7..3086256213c 100644 --- a/protocols/kad/CHANGELOG.md +++ b/protocols/kad/CHANGELOG.md @@ -1,4 +1,4 @@ -## -1.45.0 - unreleased +## 0.45.0 - unreleased - Add `_ => {}` arm to `#[non_exhaustive]` enum `match`es See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). From e6aff9fe8426be9f31f3f2e9917ee0a48b2cc75e Mon Sep 17 00:00:00 2001 From: Dave Huseby Date: Wed, 1 Nov 2023 17:35:07 -0600 Subject: [PATCH 15/20] add libp2p-swarm-derive version pin test Signed-off-by: Dave Huseby --- .github/workflows/ci.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2c69eb65276..8eaa469db26 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,8 +61,19 @@ jobs: with: tool: tomlq + - name: Enforce libp2p-swarm-derive version is pinned and matches latest version + if: env.CRATE == 'libp2p-swarm-derive' + run: | + PACKAGE_VERSION=$(cargo metadata --format-version=1 --no-deps | jq -e -r '.packages[] | select(.name == "'"$CRATE"'") | .version') + SPECIFIED_VERSION=$(tomlq "workspace.dependencies.$CRATE.version" --file ./Cargo.toml) + + echo "Package version: $PACKAGE_VERSION"; + echo "Specified version: $SPECIFIED_VERSION"; + + test "=$PACKAGE_VERSION" = "$SPECIFIED_VERSION" + - name: Enforce version in `workspace.dependencies` matches latest version - if: env.CRATE != 'libp2p' + if: env.CRATE != 'libp2p' && env.CRATE != 'libp2p-swarm-derive' run: | PACKAGE_VERSION=$(cargo metadata --format-version=1 --no-deps | jq -e -r '.packages[] | select(.name == "'"$CRATE"'") | .version') SPECIFIED_VERSION=$(tomlq "workspace.dependencies.$CRATE.version" --file ./Cargo.toml) From 3277209c0c5ba5eebdfa0310e776a2bbd9f3f23a Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 2 Nov 2023 17:16:35 +1100 Subject: [PATCH 16/20] Revert "updating CHANGELOGs" This reverts commit 344e012d5ca260f37d11026dbe99697696c30e88. --- misc/allow-block-list/CHANGELOG.md | 4 +--- misc/connection-limits/CHANGELOG.md | 2 -- misc/metrics/CHANGELOG.md | 2 -- protocols/autonat/CHANGELOG.md | 4 +--- protocols/dcutr/CHANGELOG.md | 4 +--- protocols/floodsub/CHANGELOG.md | 2 -- protocols/gossipsub/CHANGELOG.md | 2 -- protocols/identify/CHANGELOG.md | 4 +--- protocols/kad/CHANGELOG.md | 4 +--- protocols/perf/CHANGELOG.md | 2 -- protocols/ping/CHANGELOG.md | 2 -- protocols/relay/CHANGELOG.md | 6 ++---- protocols/rendezvous/CHANGELOG.md | 2 -- protocols/request-response/CHANGELOG.md | 2 -- protocols/upnp/CHANGELOG.md | 2 -- 15 files changed, 7 insertions(+), 37 deletions(-) diff --git a/misc/allow-block-list/CHANGELOG.md b/misc/allow-block-list/CHANGELOG.md index 1ff1349f6e1..d9b8e0c6de1 100644 --- a/misc/allow-block-list/CHANGELOG.md +++ b/misc/allow-block-list/CHANGELOG.md @@ -1,9 +1,7 @@ ## 0.3.0 - unreleased -- Clean up on_swarm_event handler. - See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). -## 0.2.0 +## 0.2.0 - Raise MSRV to 1.65. See [PR 3715]. diff --git a/misc/connection-limits/CHANGELOG.md b/misc/connection-limits/CHANGELOG.md index 42ed9dab973..36884867b97 100644 --- a/misc/connection-limits/CHANGELOG.md +++ b/misc/connection-limits/CHANGELOG.md @@ -1,7 +1,5 @@ ## 0.3.0 - unreleased -- Add `_ => {}` arm to `#[non_exhaustive]` enum `match`es - See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). ## 0.2.1 diff --git a/misc/metrics/CHANGELOG.md b/misc/metrics/CHANGELOG.md index 4901159342e..acad2043fc8 100644 --- a/misc/metrics/CHANGELOG.md +++ b/misc/metrics/CHANGELOG.md @@ -1,7 +1,5 @@ ## 0.14.0 - unreleased -- Add `_ => {}` arm to `#[non_exhaustive]` enum `match`es - See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). - Add metrics for `SwarmEvent::{NewExternalAddrCandidate,ExternalAddrConfirmed,ExternalAddrExpired}`. See [PR 4721](https://github.com/libp2p/rust-libp2p/pull/4721). diff --git a/protocols/autonat/CHANGELOG.md b/protocols/autonat/CHANGELOG.md index ee7d9ef58e7..2b14598bd3e 100644 --- a/protocols/autonat/CHANGELOG.md +++ b/protocols/autonat/CHANGELOG.md @@ -1,12 +1,10 @@ ## 0.12.0 - unreleased -- Add `_ => {}` arm to `#[non_exhaustive]` enum `match`es - See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). - Remove `Clone`, `PartialEq` and `Eq` implementations on `Event` and its sub-structs. The `Event` also contains errors which are not clonable or comparable. See [PR 3914](https://github.com/libp2p/rust-libp2p/pull/3914). -## 0.11.0 +## 0.11.0 - Raise MSRV to 1.65. See [PR 3715]. diff --git a/protocols/dcutr/CHANGELOG.md b/protocols/dcutr/CHANGELOG.md index 781be8176ad..cb84020ec5f 100644 --- a/protocols/dcutr/CHANGELOG.md +++ b/protocols/dcutr/CHANGELOG.md @@ -1,7 +1,5 @@ ## 0.11.0 - unreleased -- Add `_ => {}` arm to `#[non_exhaustive]` enum `match`es - See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). - Add `ConnectionId` to `Event::DirectConnectionUpgradeSucceeded` and `Event::DirectConnectionUpgradeFailed`. See [PR 4558](https://github.com/libp2p/rust-libp2p/pull/4558). - Exchange address _candidates_ instead of external addresses in `CONNECT`. @@ -11,7 +9,7 @@ We now only emit a single event: whether the hole-punch was successful or not. See [PR XXXX](https://github.com/libp2p/rust-libp2p/pull/XXXX). -## 0.10.0 +## 0.10.0 - Raise MSRV to 1.65. See [PR 3715]. diff --git a/protocols/floodsub/CHANGELOG.md b/protocols/floodsub/CHANGELOG.md index 7bec5a26b88..3891a09f4d4 100644 --- a/protocols/floodsub/CHANGELOG.md +++ b/protocols/floodsub/CHANGELOG.md @@ -1,7 +1,5 @@ ## 0.44.0 - unreleased -- Add `_ => {}` arm to `#[non_exhaustive]` enum `match`es - See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). - Change publish to require `data: impl Into` to internally avoid any costly cloning / allocation. See [PR 4754](https://github.com/libp2p/rust-libp2p/pull/4754). diff --git a/protocols/gossipsub/CHANGELOG.md b/protocols/gossipsub/CHANGELOG.md index ae46a396e4f..b86ec4de6d4 100644 --- a/protocols/gossipsub/CHANGELOG.md +++ b/protocols/gossipsub/CHANGELOG.md @@ -1,7 +1,5 @@ ## 0.46.0 - unreleased -- Add `_ => {}` arm to `#[non_exhaustive]` enum `match`es - See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). - Remove `fast_message_id_fn` mechanism from `Config`. See [PR 4285](https://github.com/libp2p/rust-libp2p/pull/4285). - Remove deprecated `gossipsub::Config::idle_timeout` in favor of `SwarmBuilder::idle_connection_timeout`. diff --git a/protocols/identify/CHANGELOG.md b/protocols/identify/CHANGELOG.md index b9e790ef09f..960ed530682 100644 --- a/protocols/identify/CHANGELOG.md +++ b/protocols/identify/CHANGELOG.md @@ -1,7 +1,5 @@ ## 0.44.0 - unreleased -- Add `_ => {}` arm to `#[non_exhaustive]` enum `match`es - See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). - Add `Info` to the `libp2p-identify::Event::Pushed` to report pushed info. See [PR 4527](https://github.com/libp2p/rust-libp2p/pull/4527) - Remove deprecated `initial_delay`. @@ -9,7 +7,7 @@ See [PR 4735](https://github.com/libp2p/rust-libp2p/pull/4735) - Don't repeatedly report the same observed address as a `NewExternalAddrCandidate`. Instead, only report each observed address once per connection. - This allows users to probabilistically deem an address as external if it gets reported as a candidate repeatedly. + This allows users to probabilistically deem an address as external if it gets reported as a candidate repeatedly. See [PR 4721](https://github.com/libp2p/rust-libp2p/pull/4721). ## 0.43.1 diff --git a/protocols/kad/CHANGELOG.md b/protocols/kad/CHANGELOG.md index 3086256213c..d2b92195ab3 100644 --- a/protocols/kad/CHANGELOG.md +++ b/protocols/kad/CHANGELOG.md @@ -1,7 +1,5 @@ ## 0.45.0 - unreleased -- Add `_ => {}` arm to `#[non_exhaustive]` enum `match`es - See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). - Remove deprecated `kad::Config::set_connection_idle_timeout` in favor of `SwarmBuilder::idle_connection_timeout`. See [PR 4659](https://github.com/libp2p/rust-libp2p/pull/4659). - Emit `ModeChanged` event whenever we automatically reconfigure the mode. @@ -12,7 +10,7 @@ See [PR 4698](https://github.com/libp2p/rust-libp2p/pull/4698). - Remove previously deprecated type-aliases. Users should follow the convention of importing the `libp2p::kad` module and referring to symbols as `kad::Behaviour` etc. - See [PR 4733](https://github.com/libp2p/rust-libp2p/pull/4733). + See [PR 4733](https://github.com/libp2p/rust-libp2p/pull/4733). ## 0.44.6 diff --git a/protocols/perf/CHANGELOG.md b/protocols/perf/CHANGELOG.md index 3cee1d96ea9..6976a89887b 100644 --- a/protocols/perf/CHANGELOG.md +++ b/protocols/perf/CHANGELOG.md @@ -1,7 +1,5 @@ ## 0.3.0 - unreleased -- Add `_ => {}` arm to `#[non_exhaustive]` enum `match`es - See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). - Continuously measure on single connection (iperf-style). See https://github.com/libp2p/test-plans/issues/261 for high level overview. See [PR 4382](https://github.com/libp2p/rust-libp2p/pull/4382). diff --git a/protocols/ping/CHANGELOG.md b/protocols/ping/CHANGELOG.md index 63ce8ed7004..b94b4581a6a 100644 --- a/protocols/ping/CHANGELOG.md +++ b/protocols/ping/CHANGELOG.md @@ -1,7 +1,5 @@ ## 0.44.0 - unreleased -- Add `_ => {}` arm to `#[non_exhaustive]` enum `match`es - See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). ## 0.43.1 diff --git a/protocols/relay/CHANGELOG.md b/protocols/relay/CHANGELOG.md index 9c95fc3de92..200cc4bc18d 100644 --- a/protocols/relay/CHANGELOG.md +++ b/protocols/relay/CHANGELOG.md @@ -1,7 +1,5 @@ ## 0.17.0 - unreleased -- Add `_ => {}` arm to `#[non_exhaustive]` enum `match`es - See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). - Don't close connections on protocol failures within the relay-server. To achieve this, error handling was restructured: - `libp2p::relay::outbound::stop::FatalUpgradeError` has been removed. @@ -12,7 +10,7 @@ - Fix a rare race condition when making a reservation on a relay that could lead to a failed reservation. See [PR 4747](https://github.com/libp2p/rust-lib2pp/pulls/4747). - Propagate errors of relay client to the listener / dialer. - A failed reservation will now appear as `SwarmEvent::ListenerClosed` with the `ListenerId` of the corresponding `Swarm::listen_on` call. + A failed reservation will now appear as `SwarmEvent::ListenerClosed` with the `ListenerId` of the corresponding `Swarm::listen_on` call. A failed circuit request will now appear as `SwarmEvent::OutgoingConnectionError` with the `ConnectionId` of the corresponding `Swarm::dial` call. Lastly, a failed reservation or circuit request will **no longer** close the underlying relay connection. As a result, we remove the following enum variants: @@ -20,7 +18,7 @@ - `relay::client::Event::OutboundCircuitReqFailed` - `relay::client::Event::InboundCircuitReqDenied` - `relay::client::Event::InboundCircuitReqDenyFailed` - + See [PR 4745](https://github.com/libp2p/rust-lib2pp/pulls/4745). ## 0.16.2 diff --git a/protocols/rendezvous/CHANGELOG.md b/protocols/rendezvous/CHANGELOG.md index 77223678077..7b75b35ae9c 100644 --- a/protocols/rendezvous/CHANGELOG.md +++ b/protocols/rendezvous/CHANGELOG.md @@ -1,7 +1,5 @@ ## 0.14.0 - unreleased -- Add `_ => {}` arm to `#[non_exhaustive]` enum `match`es - See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). ## 0.13.1 - Refresh registration upon a change in external addresses. diff --git a/protocols/request-response/CHANGELOG.md b/protocols/request-response/CHANGELOG.md index e0c9f62de7b..138401c2f50 100644 --- a/protocols/request-response/CHANGELOG.md +++ b/protocols/request-response/CHANGELOG.md @@ -1,7 +1,5 @@ ## 0.26.0 - unreleased -- Add `_ => {}` arm to `#[non_exhaustive]` enum `match`es - See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). - Remove `request_response::Config::set_connection_keep_alive` in favor of `SwarmBuilder::idle_connection_timeout`. See [PR 4679](https://github.com/libp2p/rust-libp2p/pull/4679). - Allow at most 100 concurrent inbound + outbound streams per instance of `request_response::Behaviour`. diff --git a/protocols/upnp/CHANGELOG.md b/protocols/upnp/CHANGELOG.md index 39f47ffa265..75aeaf64d6e 100644 --- a/protocols/upnp/CHANGELOG.md +++ b/protocols/upnp/CHANGELOG.md @@ -1,7 +1,5 @@ ## 0.2.0 - unreleased -- Add `_ => {}` arm to `#[non_exhaustive]` enum `match`es - See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). ## 0.1.1 From c85bb0bb45260ef89fb07676b4dcd212dfd8998e Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 2 Nov 2023 17:17:19 +1100 Subject: [PATCH 17/20] Revert "add libp2p-swarm-derive version pin test" This reverts commit e6aff9fe8426be9f31f3f2e9917ee0a48b2cc75e. --- .github/workflows/ci.yml | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8eaa469db26..2c69eb65276 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,19 +61,8 @@ jobs: with: tool: tomlq - - name: Enforce libp2p-swarm-derive version is pinned and matches latest version - if: env.CRATE == 'libp2p-swarm-derive' - run: | - PACKAGE_VERSION=$(cargo metadata --format-version=1 --no-deps | jq -e -r '.packages[] | select(.name == "'"$CRATE"'") | .version') - SPECIFIED_VERSION=$(tomlq "workspace.dependencies.$CRATE.version" --file ./Cargo.toml) - - echo "Package version: $PACKAGE_VERSION"; - echo "Specified version: $SPECIFIED_VERSION"; - - test "=$PACKAGE_VERSION" = "$SPECIFIED_VERSION" - - name: Enforce version in `workspace.dependencies` matches latest version - if: env.CRATE != 'libp2p' && env.CRATE != 'libp2p-swarm-derive' + if: env.CRATE != 'libp2p' run: | PACKAGE_VERSION=$(cargo metadata --format-version=1 --no-deps | jq -e -r '.packages[] | select(.name == "'"$CRATE"'") | .version') SPECIFIED_VERSION=$(tomlq "workspace.dependencies.$CRATE.version" --file ./Cargo.toml) From 3c3e7b5d6b426fc9bd77a12287728f669894e0d4 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 2 Nov 2023 17:17:48 +1100 Subject: [PATCH 18/20] Extend check to cover pinned version --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2c69eb65276..d469b8734b7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,7 +70,7 @@ jobs: echo "Package version: $PACKAGE_VERSION"; echo "Specified version: $SPECIFIED_VERSION"; - test "$PACKAGE_VERSION" = "$SPECIFIED_VERSION" + test "$PACKAGE_VERSION" = "$SPECIFIED_VERSION" || test "=$PACKAGE_VERSION" = "$SPECIFIED_VERSION" - name: Ensure manifest and CHANGELOG are properly updated if: > From f796df045680b46690e12289c99fa05755b8c77d Mon Sep 17 00:00:00 2001 From: Dave Huseby Date: Thu, 2 Nov 2023 09:32:56 -0600 Subject: [PATCH 19/20] update CHANGELOG for swarm-derive Signed-off-by: Dave Huseby --- swarm-derive/CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/swarm-derive/CHANGELOG.md b/swarm-derive/CHANGELOG.md index 269c2f1af7f..24db5e95c07 100644 --- a/swarm-derive/CHANGELOG.md +++ b/swarm-derive/CHANGELOG.md @@ -1,12 +1,14 @@ ## 0.34.0 - unreleased +- Add `#[non_exhaustive]` to `FromSwarm`, `ToSwarm`, `SwarmEvent`, `ConnectionHandlerEvent`, `ConnectionEvent`. + See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). - Adapt to interface changes in `libp2p-swarm`. See [PR 4706](https://github.com/libp2p/rust-libp2p/pull/4076). - Remove supported for deprecated `#[behaviour(out_event = "...")]`. To same functionality is available using `#[behaviour(to_swarm = "...")]` See [PR 4737](https://github.com/libp2p/rust-libp2p/pull/4737). -## 0.33.0 +## 0.33.0 - Raise MSRV to 1.65. See [PR 3715]. From e37cbc41057d6276091a174cae17f7fee9777964 Mon Sep 17 00:00:00 2001 From: Dave Huseby Date: Thu, 2 Nov 2023 09:35:20 -0600 Subject: [PATCH 20/20] revert swarm-derive/CHANGELOG update Signed-off-by: Dave Huseby --- swarm-derive/CHANGELOG.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/swarm-derive/CHANGELOG.md b/swarm-derive/CHANGELOG.md index 24db5e95c07..3ed7b9931df 100644 --- a/swarm-derive/CHANGELOG.md +++ b/swarm-derive/CHANGELOG.md @@ -1,7 +1,5 @@ ## 0.34.0 - unreleased -- Add `#[non_exhaustive]` to `FromSwarm`, `ToSwarm`, `SwarmEvent`, `ConnectionHandlerEvent`, `ConnectionEvent`. - See [PR 4581](https://github.com/libp2p/rust-libp2p/pull/4581). - Adapt to interface changes in `libp2p-swarm`. See [PR 4706](https://github.com/libp2p/rust-libp2p/pull/4076). - Remove supported for deprecated `#[behaviour(out_event = "...")]`.