Skip to content

Commit c6c6aef

Browse files
author
Antoine Riard
committed
Add PeerManager::disconnect_node_id()
This public method allows a client to easily disconnect peers while only owning its node id. It will clean up peer state and disconnect properly its descriptor.
1 parent 74cd96f commit c6c6aef

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lightning/src/ln/peer_handler.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,18 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
11791179
};
11801180
}
11811181

1182+
/// Disconnect a peer given its node id.
1183+
pub fn disconnect_node_id(&self, node_id: PublicKey, no_connection_possible: bool) {
1184+
let mut peers_lock = self.peers.lock().unwrap();
1185+
if let Some(mut descriptor) = peers_lock.node_id_to_descriptor.remove(&node_id) {
1186+
log_trace!(self.logger, "Disconnecting peer with id {} due to client request", node_id);
1187+
peers_lock.peers.remove(&descriptor);
1188+
peers_lock.peers_needing_send.remove(&descriptor);
1189+
self.message_handler.chan_handler.peer_disconnected(&node_id, no_connection_possible);
1190+
descriptor.disconnect_socket();
1191+
}
1192+
}
1193+
11821194
/// This function should be called roughly once every 30 seconds.
11831195
/// It will send pings to each peer and disconnect those which did not respond to the last round of pings.
11841196

0 commit comments

Comments
 (0)