Skip to content

Commit

Permalink
remove DialError & ListenError invariants
Browse files Browse the repository at this point in the history
also fix pending_events
  • Loading branch information
melekes committed Jun 23, 2023
1 parent 37e7408 commit d5b8198
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
6 changes: 4 additions & 2 deletions client/network/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -901,8 +901,10 @@ impl NetworkBehaviour for DiscoveryBehaviour {
continue
}

self.pending_events
.extend(list.map(|(peer_id, _)| DiscoveryOut::Discovered(peer_id)));
self.pending_events.extend(
list.into_iter()
.map(|(peer_id, _)| DiscoveryOut::Discovered(peer_id)),
);
if let Some(ev) = self.pending_events.pop_front() {
return Poll::Ready(ToSwarm::GenerateEvent(ev))
}
Expand Down
45 changes: 20 additions & 25 deletions client/network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,6 @@ where
SpawnImpl(params.executor),
)
};
#[allow(deprecated)]
let builder = builder
.connection_limits(
ConnectionLimits::default()
Expand Down Expand Up @@ -1555,7 +1554,7 @@ where
endpoint,
num_established,
} => {
debug!(target: "sub-libp2p", "Libp2p => Disconnected({:?} via {:?}, {:?})", peer_id, connection_id, cause);
debug!(target: "sub-libp2p", "Libp2p => Disconnected({:?} via {:?}: {:?})", peer_id, connection_id, cause);
if let Some(metrics) = self.metrics.as_ref() {
let direction = match endpoint {
ConnectedPoint::Dialer { .. } => "out",
Expand Down Expand Up @@ -1624,12 +1623,9 @@ where
} else {
None
},
DialError::ConnectionLimit(_) => Some("limit-reached"),
DialError::InvalidPeerId(_) |
DialError::WrongPeerId { .. } |
DialError::LocalPeerId { .. } => Some("invalid-peer-id"),
DialError::WrongPeerId { .. } | DialError::LocalPeerId { .. } =>
Some("invalid-peer-id"),
DialError::Transport(_) => Some("transport-error"),
DialError::Banned |
DialError::NoAddresses |
DialError::DialPeerConditionFalse(_) |
DialError::Aborted => None, // ignore them
Expand All @@ -1639,12 +1635,12 @@ where
}
}
},
SwarmEvent::Dialing(peer_id) => {
trace!(target: "sub-libp2p", "Libp2p => Dialing({:?})", peer_id)
SwarmEvent::Dialing { peer_id, connection_id } => {
trace!(target: "sub-libp2p", "Libp2p => Dialing({:?} via {:?})", peer_id, connection_id)
},
SwarmEvent::IncomingConnection { connection_id, local_addr, send_back_addr } => {
trace!(target: "sub-libp2p", "Libp2p => IncomingConnection({:?},{},{}))",
connection_id, local_addr, send_back_addr);
trace!(target: "sub-libp2p", "Libp2p => IncomingConnection({},{} via {:?}))",
local_addr, send_back_addr, connection_id);
if let Some(metrics) = self.metrics.as_ref() {
metrics.incoming_connections_total.inc();
}
Expand All @@ -1657,8 +1653,8 @@ where
} => {
debug!(
target: "sub-libp2p",
"Libp2p => IncomingConnectionError({:?},{},{}): {}",
connection_id, local_addr, send_back_addr, error,
"Libp2p => IncomingConnectionError({},{} via {:?}): {}",
local_addr, send_back_addr, connection_id, error,
);
if let Some(metrics) = self.metrics.as_ref() {
#[allow(deprecated)]
Expand All @@ -1669,7 +1665,6 @@ where
} else {
None
},
ListenError::ConnectionLimit(_) => Some("limit-reached"),
ListenError::WrongPeerId { .. } | ListenError::LocalPeerId { .. } =>
Some("invalid-peer-id"),
ListenError::Transport(_) => Some("transport-error"),
Expand All @@ -1684,17 +1679,17 @@ where
}
}
},
#[allow(deprecated)]
SwarmEvent::BannedPeer { peer_id, endpoint } => {
debug!(
target: "sub-libp2p",
"Libp2p => BannedPeer({}). Connected via {:?}.",
peer_id, endpoint,
);
if let Some(metrics) = self.metrics.as_ref() {
metrics.incoming_connections_errors_total.with_label_values(&["banned"]).inc();
}
},
// #[allow(deprecated)]
// SwarmEvent::BannedPeer { peer_id, endpoint } => {
// debug!(
// target: "sub-libp2p",
// "Libp2p => BannedPeer({}). Connected via {:?}.",
// peer_id, endpoint,
// );
// if let Some(metrics) = self.metrics.as_ref() {
// metrics.incoming_connections_errors_total.with_label_values(&["banned"]).inc();
// }
// },
SwarmEvent::ListenerClosed { reason, addresses, .. } => {
if let Some(metrics) = self.metrics.as_ref() {
metrics.listeners_local_addresses.sub(addresses.len() as u64);
Expand Down

0 comments on commit d5b8198

Please sign in to comment.