Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(swarm): add #[non_exhaustive] to key enums #4581

Merged
merged 34 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
207c7ba
adding #[non_exhaustive] to key enums
dhuseby Oct 2, 2023
42a018f
fix swarm/CHANGELOG.md
dhuseby Oct 2, 2023
cd26395
Merge branch 'master' into add-non_exhaustive
dhuseby Oct 2, 2023
9a844b2
fix clippy CI error
dhuseby Oct 2, 2023
c7d8084
Merge branch 'master' into add-non_exhaustive
dhuseby Oct 2, 2023
8edbc27
Update swarm/CHANGELOG.md
dhuseby Oct 3, 2023
f0ecf33
Merge branch 'master' into add-non_exhaustive
dhuseby Oct 3, 2023
1e9561c
Merge branch 'add-non_exhaustive' of github:dhuseby/rust-libp2p into …
dhuseby Oct 3, 2023
2c8ec27
more cleanup
dhuseby Oct 3, 2023
32fbbfa
Merge branch 'master' into add-non_exhaustive
dhuseby Oct 3, 2023
607b6b5
Merge branch 'master' into add-non_exhaustive
dhuseby Oct 3, 2023
36c4ced
Merge branch 'master' into add-non_exhaustive
dhuseby Oct 30, 2023
b87bf96
fixing merge errors
dhuseby Oct 30, 2023
32ba7cd
pinning libp2p-swarm-derive for safety
dhuseby Oct 30, 2023
b8fd915
integrating review changes
dhuseby Oct 31, 2023
1797e27
Merge branch 'master' into add-non_exhaustive
dhuseby Oct 31, 2023
733e617
Update Cargo.toml
dhuseby Oct 31, 2023
eee905f
Merge branch 'master' into add-non_exhaustive
dhuseby Oct 31, 2023
30f1665
Simplify derive code
thomaseizinger Nov 1, 2023
717a577
Fix clippy warnings
thomaseizinger Nov 1, 2023
5e9bf98
Merge branch 'add-non_exhaustive' of github:dhuseby/rust-libp2p into …
dhuseby Nov 1, 2023
c750a58
move swarm-derive comment to the same line in Cargo.toml
dhuseby Nov 1, 2023
789e094
Merge branch 'master' into add-non_exhaustive
dhuseby Nov 1, 2023
344e012
updating CHANGELOGs
dhuseby Nov 1, 2023
21efd9e
fixing kad CHANGELOG
dhuseby Nov 1, 2023
e6aff9f
add libp2p-swarm-derive version pin test
dhuseby Nov 1, 2023
3277209
Revert "updating CHANGELOGs"
thomaseizinger Nov 2, 2023
c85bb0b
Revert "add libp2p-swarm-derive version pin test"
thomaseizinger Nov 2, 2023
3c3e7b5
Extend check to cover pinned version
thomaseizinger Nov 2, 2023
cdd21aa
Merge branch 'master' into add-non_exhaustive
dhuseby Nov 2, 2023
f796df0
update CHANGELOG for swarm-derive
dhuseby Nov 2, 2023
f0c4e0a
Merge branch 'add-non_exhaustive' of github:dhuseby/rust-libp2p into …
dhuseby Nov 2, 2023
e37cbc4
revert swarm-derive/CHANGELOG update
dhuseby Nov 2, 2023
81d7835
Merge branch 'master' into add-non_exhaustive
mergify[bot] Nov 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: >
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.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" }
Expand Down
18 changes: 1 addition & 17 deletions misc/allow-block-list/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,23 +231,7 @@ where
Ok(dummy::ConnectionHandler)
}

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(_) => {}
}
}
fn on_swarm_event(&mut self, _event: FromSwarm) {}

fn on_connection_handler_event(
&mut self,
Expand Down
10 changes: 1 addition & 9 deletions misc/connection-limits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_) => {}
_ => {}
}
}

Expand Down
51 changes: 22 additions & 29 deletions misc/metrics/src/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::sync::{Arc, Mutex};

use crate::protocol_stack;
use instant::Instant;
use libp2p_swarm::{ConnectionId, SwarmEvent};
use libp2p_swarm::{ConnectionId, DialError, SwarmEvent};
use prometheus_client::encoding::{EncodeLabelSet, EncodeLabelValue};
use prometheus_client::metrics::counter::Counter;
use prometheus_client::metrics::family::Family;
Expand Down Expand Up @@ -185,11 +185,11 @@ impl Metrics {
}
}

impl<TBvEv, THandleErr> super::Recorder<libp2p_swarm::SwarmEvent<TBvEv, THandleErr>> for Metrics {
fn record(&self, event: &libp2p_swarm::SwarmEvent<TBvEv, THandleErr>) {
impl<TBvEv, THandleErr> super::Recorder<SwarmEvent<TBvEv, THandleErr>> for Metrics {
fn record(&self, event: &SwarmEvent<TBvEv, THandleErr>) {
match event {
libp2p_swarm::SwarmEvent::Behaviour(_) => {}
libp2p_swarm::SwarmEvent::ConnectionEstablished {
SwarmEvent::Behaviour(_) => {}
SwarmEvent::ConnectionEstablished {
endpoint,
established_in: time_taken,
connection_id,
Expand All @@ -208,7 +208,7 @@ impl<TBvEv, THandleErr> super::Recorder<libp2p_swarm::SwarmEvent<TBvEv, THandleE
.expect("lock not to be poisoned")
.insert(*connection_id, Instant::now());
}
libp2p_swarm::SwarmEvent::ConnectionClosed {
SwarmEvent::ConnectionClosed {
endpoint,
connection_id,
cause,
Expand All @@ -231,14 +231,14 @@ impl<TBvEv, THandleErr> super::Recorder<libp2p_swarm::SwarmEvent<TBvEv, THandleE
.as_secs_f64(),
);
}
libp2p_swarm::SwarmEvent::IncomingConnection { send_back_addr, .. } => {
SwarmEvent::IncomingConnection { send_back_addr, .. } => {
self.connections_incoming
.get_or_create(&AddressLabels {
protocols: protocol_stack::as_string(send_back_addr),
})
.inc();
}
libp2p_swarm::SwarmEvent::IncomingConnectionError {
SwarmEvent::IncomingConnectionError {
error,
send_back_addr,
..
Expand All @@ -250,7 +250,7 @@ impl<TBvEv, THandleErr> super::Recorder<libp2p_swarm::SwarmEvent<TBvEv, THandleE
})
.inc();
}
libp2p_swarm::SwarmEvent::OutgoingConnectionError { error, peer_id, .. } => {
SwarmEvent::OutgoingConnectionError { error, peer_id, .. } => {
let peer = match peer_id {
Some(_) => PeerStatus::Known,
None => PeerStatus::Unknown,
Expand All @@ -263,7 +263,7 @@ impl<TBvEv, THandleErr> super::Recorder<libp2p_swarm::SwarmEvent<TBvEv, THandleE
};

match error {
libp2p_swarm::DialError::Transport(errors) => {
DialError::Transport(errors) => {
for (_multiaddr, error) in errors {
match error {
libp2p_core::transport::TransportError::MultiaddrNotSupported(
Expand All @@ -277,39 +277,31 @@ impl<TBvEv, THandleErr> super::Recorder<libp2p_swarm::SwarmEvent<TBvEv, THandleE
};
}
}
libp2p_swarm::DialError::LocalPeerId { .. } => {
record(OutgoingConnectionError::LocalPeerId)
}
libp2p_swarm::DialError::NoAddresses => {
record(OutgoingConnectionError::NoAddresses)
}
libp2p_swarm::DialError::DialPeerConditionFalse(_) => {
DialError::LocalPeerId { .. } => record(OutgoingConnectionError::LocalPeerId),
DialError::NoAddresses => record(OutgoingConnectionError::NoAddresses),
DialError::DialPeerConditionFalse(_) => {
record(OutgoingConnectionError::DialPeerConditionFalse)
}
libp2p_swarm::DialError::Aborted => record(OutgoingConnectionError::Aborted),
libp2p_swarm::DialError::WrongPeerId { .. } => {
record(OutgoingConnectionError::WrongPeerId)
}
libp2p_swarm::DialError::Denied { .. } => {
record(OutgoingConnectionError::Denied)
}
DialError::Aborted => record(OutgoingConnectionError::Aborted),
DialError::WrongPeerId { .. } => record(OutgoingConnectionError::WrongPeerId),
DialError::Denied { .. } => record(OutgoingConnectionError::Denied),
};
}
libp2p_swarm::SwarmEvent::NewListenAddr { address, .. } => {
SwarmEvent::NewListenAddr { address, .. } => {
self.new_listen_addr
.get_or_create(&AddressLabels {
protocols: protocol_stack::as_string(address),
})
.inc();
}
libp2p_swarm::SwarmEvent::ExpiredListenAddr { address, .. } => {
SwarmEvent::ExpiredListenAddr { address, .. } => {
self.expired_listen_addr
.get_or_create(&AddressLabels {
protocols: protocol_stack::as_string(address),
})
.inc();
}
libp2p_swarm::SwarmEvent::ListenerClosed { addresses, .. } => {
SwarmEvent::ListenerClosed { addresses, .. } => {
for address in addresses {
self.listener_closed
.get_or_create(&AddressLabels {
Expand All @@ -318,10 +310,10 @@ impl<TBvEv, THandleErr> super::Recorder<libp2p_swarm::SwarmEvent<TBvEv, THandleE
.inc();
}
}
libp2p_swarm::SwarmEvent::ListenerError { .. } => {
SwarmEvent::ListenerError { .. } => {
self.listener_error.inc();
}
libp2p_swarm::SwarmEvent::Dialing { .. } => {
SwarmEvent::Dialing { .. } => {
self.dial_attempt.inc();
}
SwarmEvent::NewExternalAddrCandidate { address } => {
Expand All @@ -345,6 +337,7 @@ impl<TBvEv, THandleErr> super::Recorder<libp2p_swarm::SwarmEvent<TBvEv, THandleE
})
.inc();
}
_ => {}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions protocols/autonat/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ impl NetworkBehaviour for Behaviour {
self.inner.on_swarm_event(listener_closed)
}
confirmed @ FromSwarm::ExternalAddrConfirmed(_) => self.inner.on_swarm_event(confirmed),
_ => {}
}
}

Expand Down
11 changes: 1 addition & 10 deletions protocols/dcutr/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,16 +339,7 @@ impl NetworkBehaviour for Behaviour {
FromSwarm::NewExternalAddrCandidate(NewExternalAddrCandidate { addr }) => {
self.address_candidates.add(addr.clone());
}
FromSwarm::AddressChange(_)
| FromSwarm::ConnectionEstablished(_)
| FromSwarm::ListenFailure(_)
| FromSwarm::NewListener(_)
| FromSwarm::NewListenAddr(_)
| FromSwarm::ExpiredListenAddr(_)
| FromSwarm::ListenerError(_)
| FromSwarm::ListenerClosed(_)
| FromSwarm::ExternalAddrExpired(_)
| FromSwarm::ExternalAddrConfirmed(_) => {}
_ => {}
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions protocols/dcutr/src/handler/relayed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,7 @@ impl ConnectionHandler for Handler {
ConnectionEvent::DialUpgradeError(dial_upgrade_error) => {
self.on_dial_upgrade_error(dial_upgrade_error)
}
ConnectionEvent::AddressChange(_)
| ConnectionEvent::LocalProtocolsChange(_)
| ConnectionEvent::RemoteProtocolsChange(_) => {}
_ => {}
}
}
}
12 changes: 1 addition & 11 deletions protocols/floodsub/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,17 +490,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(_) => {}
_ => {}
}
}
}
Expand Down
11 changes: 1 addition & 10 deletions protocols/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3458,16 +3458,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(_) => {}
_ => {}
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions protocols/gossipsub/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,10 +533,7 @@ impl ConnectionHandler for Handler {
}) => {
tracing::debug!("Protocol negotiation failed: {e}")
}
ConnectionEvent::AddressChange(_)
| ConnectionEvent::ListenUpgradeError(_)
| ConnectionEvent::LocalProtocolsChange(_)
| ConnectionEvent::RemoteProtocolsChange(_) => {}
_ => {}
}
}
Handler::Disabled(_) => {}
Expand Down
11 changes: 1 addition & 10 deletions protocols/identify/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_) => {}
_ => {}
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions protocols/identify/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,6 @@ impl ConnectionHandler for Handler {
));
self.trigger_next_identify.reset(self.interval);
}
ConnectionEvent::AddressChange(_)
| ConnectionEvent::ListenUpgradeError(_)
| ConnectionEvent::RemoteProtocolsChange(_) => {}
ConnectionEvent::LocalProtocolsChange(change) => {
let before = tracing::enabled!(Level::DEBUG)
.then(|| self.local_protocols_to_string())
Expand All @@ -436,6 +433,7 @@ impl ConnectionHandler for Handler {
});
}
}
_ => {}
}
}
}
Expand Down
10 changes: 1 addition & 9 deletions protocols/kad/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2554,15 +2554,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(_) => {}
_ => {}
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions protocols/kad/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,9 +777,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);

Expand All @@ -795,6 +792,7 @@ impl ConnectionHandler for Handler {
))
}
}
_ => {}
}
}
}
Expand Down
12 changes: 1 addition & 11 deletions protocols/perf/src/client/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,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(_) => {}
_ => {}
}
}

Expand Down
1 change: 1 addition & 0 deletions protocols/perf/src/client/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ impl ConnectionHandler for Handler {
ConnectionEvent::ListenUpgradeError(ListenUpgradeError { info: (), error }) => {
void::unreachable(error)
}
_ => {}
}
}

Expand Down
Loading