Skip to content

Commit

Permalink
feat: Report cause of connection closing to behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
dariusc93 committed Jun 5, 2024
1 parent 3da7d91 commit 7e66fee
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions protocols/gossipsub/src/behaviour/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ where
connection_id,
endpoint: &fake_endpoint,
remaining_established: active_connections,
cause: None,
}));
}
}
Expand Down
1 change: 1 addition & 0 deletions protocols/perf/src/client/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ impl NetworkBehaviour for Behaviour {
connection_id: _,
endpoint: _,
remaining_established,
..
}) => {
if remaining_established == 0 {
assert!(self.connected.remove(&peer_id));
Expand Down
5 changes: 3 additions & 2 deletions swarm/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ use crate::connection::ConnectionId;
use crate::dial_opts::DialOpts;
use crate::listen_opts::ListenOpts;
use crate::{
ConnectionDenied, ConnectionHandler, DialError, ListenError, THandler, THandlerInEvent,
THandlerOutEvent,
ConnectionDenied, ConnectionError, ConnectionHandler, DialError, ListenError, THandler,
THandlerInEvent, THandlerOutEvent,
};
use libp2p_core::{transport::ListenerId, ConnectedPoint, Endpoint, Multiaddr};
use libp2p_identity::PeerId;
Expand Down Expand Up @@ -475,6 +475,7 @@ pub struct ConnectionClosed<'a> {
pub peer_id: PeerId,
pub connection_id: ConnectionId,
pub endpoint: &'a ConnectedPoint,
pub cause: Option<&'a ConnectionError>,
pub remaining_established: usize,
}

Expand Down
1 change: 1 addition & 0 deletions swarm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@ where
peer_id,
connection_id: id,
endpoint: &endpoint,
cause: error.as_ref(),
remaining_established: num_established as usize,
}));
self.pending_swarm_events
Expand Down
2 changes: 2 additions & 0 deletions swarm/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ where
connection_id,
endpoint,
remaining_established,
cause,
}: ConnectionClosed,
) {
let mut other_closed_connections = self
Expand Down Expand Up @@ -350,6 +351,7 @@ where
connection_id,
endpoint,
remaining_established,
cause,
}));
}
}
Expand Down

0 comments on commit 7e66fee

Please sign in to comment.