Skip to content

Commit a2055bc

Browse files
committed
Added disconnect for all connections
1 parent 1564dfc commit a2055bc

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

p2p/src/disconnection/p2p_disconnection_reducer.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,30 @@ impl P2pDisconnectedState {
2424
P2pDisconnectionAction::Init { peer_id, reason } => {
2525
#[cfg(feature = "p2p-libp2p")]
2626
if p2p_state.is_libp2p_peer(&peer_id) {
27-
if let Some((&addr, _)) = p2p_state
27+
let connections = p2p_state
2828
.network
2929
.scheduler
3030
.connections
3131
.iter()
32-
.find(|(_, conn_state)| conn_state.peer_id() == Some(&peer_id))
33-
{
34-
let Some(peer) = p2p_state.peers.get_mut(&peer_id) else {
35-
bug_condition!("Invalid state for: `P2pDisconnectionAction::Finish`");
36-
return Ok(());
37-
};
38-
peer.status = P2pPeerStatus::Disconnecting { time: meta.time() };
32+
.filter(|(_, conn_state)| conn_state.peer_id() == Some(&peer_id))
33+
.map(|(addr, _)| *addr)
34+
.collect::<Vec<_>>();
3935

40-
let dispatcher = state_context.into_dispatcher();
41-
dispatcher.push(P2pNetworkSchedulerAction::Disconnect { addr, reason });
42-
dispatcher.push(P2pDisconnectionAction::Finish { peer_id });
36+
let Some(peer) = p2p_state.peers.get_mut(&peer_id) else {
37+
bug_condition!("Invalid state for: `P2pDisconnectionAction::Finish`");
38+
return Ok(());
39+
};
40+
peer.status = P2pPeerStatus::Disconnecting { time: meta.time() };
41+
42+
let dispatcher = state_context.into_dispatcher();
43+
for addr in connections {
44+
dispatcher.push(P2pNetworkSchedulerAction::Disconnect {
45+
addr,
46+
reason: reason.clone(),
47+
});
4348
}
49+
50+
dispatcher.push(P2pDisconnectionAction::Finish { peer_id });
4451
return Ok(());
4552
}
4653

0 commit comments

Comments
 (0)