Skip to content

Commit c1aa32f

Browse files
committed
f use util method
1 parent 83d28d8 commit c1aa32f

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lightning/src/ln/peer_handler.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,8 @@ struct Peer {
397397
///
398398
/// This is set only after we've processed the [`msgs::Init`] message and called relevant
399399
/// `peer_connected` handler methods. Thus, this field is set *iff* we've finished our
400-
/// handshake and can talk to this peer normally.
400+
/// handshake and can talk to this peer normally (though use [`Peer::handshake_complete`] to
401+
/// check this.
401402
their_features: Option<InitFeatures>,
402403
their_net_address: Option<NetAddress>,
403404

@@ -429,6 +430,13 @@ struct Peer {
429430
}
430431

431432
impl Peer {
433+
/// True after we've processed the [`msgs::Init`] message and called relevant `peer_connected`
434+
/// handler methods. Thus, this implies we've finished our handshake and can talk to this peer
435+
/// normally.
436+
fn handshake_complete(&self) -> bool {
437+
self.their_features.is_some()
438+
}
439+
432440
/// Returns true if the channel announcements/updates for the given channel should be
433441
/// forwarded to this peer.
434442
/// If we are sending our routing table to this peer and we have not yet sent channel
@@ -1908,7 +1916,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
19081916
}
19091917

19101918
fn do_disconnect(&self, mut descriptor: Descriptor, peer: &Peer, reason: &'static str) {
1911-
if peer.their_features.is_none() {
1919+
if !peer.handshake_complete() {
19121920
log_trace!(self.logger, "Disconnecting peer which hasn't completed handshake due to {}", reason);
19131921
descriptor.disconnect_socket();
19141922
return;
@@ -1934,7 +1942,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
19341942
},
19351943
Some(peer_lock) => {
19361944
let peer = peer_lock.lock().unwrap();
1937-
if peer.their_features.is_none() { return; }
1945+
if !peer.handshake_complete() { return; }
19381946
debug_assert!(peer.their_node_id.is_some());
19391947
if let Some((node_id, _)) = peer.their_node_id {
19401948
log_trace!(self.logger,
@@ -2066,7 +2074,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
20662074
if !descriptors_needing_disconnect.is_empty() {
20672075
{
20682076
let mut peers_lock = self.peers.write().unwrap();
2069-
for descriptor in descriptors_needing_disconnect.drain(..) {
2077+
for descriptor in descriptors_needing_disconnect {
20702078
if let Some(peer_mutex) = peers_lock.remove(&descriptor) {
20712079
let peer = peer_mutex.lock().unwrap();
20722080
if let Some((node_id, _)) = peer.their_node_id {

0 commit comments

Comments
 (0)