@@ -397,7 +397,8 @@ struct Peer {
397
397
///
398
398
/// This is set only after we've processed the [`msgs::Init`] message and called relevant
399
399
/// `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.
401
402
their_features : Option < InitFeatures > ,
402
403
their_net_address : Option < NetAddress > ,
403
404
@@ -429,6 +430,13 @@ struct Peer {
429
430
}
430
431
431
432
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
+
432
440
/// Returns true if the channel announcements/updates for the given channel should be
433
441
/// forwarded to this peer.
434
442
/// 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
1908
1916
}
1909
1917
1910
1918
fn do_disconnect ( & self , mut descriptor : Descriptor , peer : & Peer , reason : & ' static str ) {
1911
- if peer. their_features . is_none ( ) {
1919
+ if ! peer. handshake_complete ( ) {
1912
1920
log_trace ! ( self . logger, "Disconnecting peer which hasn't completed handshake due to {}" , reason) ;
1913
1921
descriptor. disconnect_socket ( ) ;
1914
1922
return ;
@@ -1934,7 +1942,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
1934
1942
} ,
1935
1943
Some ( peer_lock) => {
1936
1944
let peer = peer_lock. lock ( ) . unwrap ( ) ;
1937
- if peer. their_features . is_none ( ) { return ; }
1945
+ if ! peer. handshake_complete ( ) { return ; }
1938
1946
debug_assert ! ( peer. their_node_id. is_some( ) ) ;
1939
1947
if let Some ( ( node_id, _) ) = peer. their_node_id {
1940
1948
log_trace ! ( self . logger,
@@ -2066,7 +2074,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
2066
2074
if !descriptors_needing_disconnect. is_empty ( ) {
2067
2075
{
2068
2076
let mut peers_lock = self . peers . write ( ) . unwrap ( ) ;
2069
- for descriptor in descriptors_needing_disconnect. drain ( .. ) {
2077
+ for descriptor in descriptors_needing_disconnect {
2070
2078
if let Some ( peer_mutex) = peers_lock. remove ( & descriptor) {
2071
2079
let peer = peer_mutex. lock ( ) . unwrap ( ) ;
2072
2080
if let Some ( ( node_id, _) ) = peer. their_node_id {
0 commit comments