@@ -740,9 +740,6 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref, TransportImpl
740
740
//
741
741
// For an inbound connection, this will respond with an INIT message.
742
742
//
743
- // In the event an INIT has already been seen from this node_id, the current peer connection
744
- // will be disconnected, but the first connection will remain available.
745
- //
746
743
// In the event this message is not an INIT the peer will be disconnected.
747
744
//
748
745
// On successful processing of the INIT message, the peer_connected() callback on the
@@ -753,10 +750,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref, TransportImpl
753
750
match message {
754
751
Message :: Init ( ref init_message) => {
755
752
log_trace ! ( self . logger, "Received Init message from {}" , log_pubkey!( & their_node_id) ) ;
756
- if node_id_to_descriptor. contains_key ( & their_node_id) {
757
- log_trace ! ( self . logger, "Got second connection with {}, closing" , log_pubkey!( & their_node_id) ) ;
758
- return Err ( PeerHandleError { no_connection_possible : false } ) ;
759
- }
753
+
760
754
761
755
let new_post_init_state = self . post_init_state_from_init_message ( init_message, & their_node_id) ?;
762
756
@@ -788,7 +782,14 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref, TransportImpl
788
782
} ,
789
783
Ok ( newly_connected) => {
790
784
if newly_connected {
791
- log_trace ! ( self . logger, "Finished noise handshake for connection with {}" , log_pubkey!( & peer. transport. get_their_node_id( ) ) ) ;
785
+ let their_node_id = peer. transport . get_their_node_id ( ) ;
786
+ log_trace ! ( self . logger, "Finished noise handshake for connection with {}" , log_pubkey!( & their_node_id) ) ;
787
+
788
+ // Check for a duplicate connection at the completion of the NOISE handshake
789
+ if node_id_to_descriptor. contains_key ( & their_node_id) {
790
+ log_trace ! ( self . logger, "Got second connection with {}, closing" , log_pubkey!( & their_node_id) ) ;
791
+ return Err ( PeerHandleError { no_connection_possible : false } ) ;
792
+ }
792
793
}
793
794
794
795
if newly_connected && peer. outbound {
0 commit comments