Skip to content

Commit

Permalink
core/: Fix ConectionClose and PendingAborted reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
mxinden committed Aug 20, 2021
1 parent 174693a commit a78de13
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 19 deletions.
12 changes: 0 additions & 12 deletions core/src/connection/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,32 +384,20 @@ impl<THandler: IntoConnectionHandler, TTransErr> Pool<THandler, TTransErr> {
/// > performing such an orderly close.
pub fn disconnect(&mut self, peer: &PeerId) {
if let Some(conns) = self.established.get(peer) {
// Count upwards because we push to / pop from the end. See also `Pool::poll`.
for (&id, endpoint) in conns.iter() {
if let Some(manager::Entry::Established(e)) = self.manager.entry(id) {
e.start_close(None);
// TODO: I removed the disconnected logic, thus depending on start_close to
// eventually trigger a ConnectionClosed event. Make sure that is the case.
}
self.counters.dec_established(endpoint);
}
}
self.established.remove(peer);

let mut aborted = Vec::new();
for (&id, (_endpoint, peer2)) in &self.pending {
if Some(peer) == peer2.as_ref() {
if let Some(manager::Entry::Pending(e)) = self.manager.entry(id) {
e.abort();
aborted.push(id);
}
}
}
for id in aborted {
if let Some((endpoint, _)) = self.pending.remove(&id) {
self.counters.dec_pending(&endpoint);
}
}
}

/// Counts the number of established connections to the given peer.
Expand Down
2 changes: 1 addition & 1 deletion protocols/relay/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ impl CombinedBehaviour {
&mut self,
_: &mut Context,
_: &mut impl PollParameters,
) -> Poll<NetworkBehaviourAction<CombinedEvent, <Self as NetworkBehaviour>::ProtocolsHandler> {
) -> Poll<NetworkBehaviourAction<CombinedEvent, <Self as NetworkBehaviour>::ProtocolsHandler>> {
if !self.events.is_empty() {
return Poll::Ready(NetworkBehaviourAction::GenerateEvent(self.events.remove(0)));
}
Expand Down
10 changes: 4 additions & 6 deletions swarm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1353,17 +1353,15 @@ mod tests {
<<TBehaviour::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::OutEvent: Clone
{
for s in &[swarm1, swarm2] {
if s.behaviour.inject_connection_closed.len() < num_connections {
assert_eq!(s.behaviour.inject_disconnected.len(), 0);
} else {
assert_eq!(s.behaviour.inject_disconnected.len(), 1);
}
assert_eq!(s.behaviour.inject_connection_established.len(), 0);
assert_eq!(s.behaviour.inject_connected.len(), 0);
}
[swarm1, swarm2]
.iter()
.all(|s| s.behaviour.inject_connection_closed.len() == num_connections)
.all(|s| s.behaviour.inject_connection_closed.len() == num_connections) &&
[swarm1, swarm2]
.iter()
.all(|s| s.behaviour.inject_disconnected.len() == 1)
}

/// Establishes multiple connections between two peers,
Expand Down

0 comments on commit a78de13

Please sign in to comment.