@@ -490,6 +490,19 @@ impl<Descriptor: SocketDescriptor, CM: Deref> PeerManager<Descriptor, CM> where
490
490
if let Some ( conduit) = conduit_option {
491
491
// Rust 1.22 does not allow assignment in a borrowed context, even if mutable
492
492
peer. encryptor = PeerState :: Connected ( conduit) ;
493
+
494
+ // the handshake has finished, so one way or another, we now have their node id
495
+ match peers. node_id_to_descriptor . entry ( peer. their_node_id . unwrap ( ) ) {
496
+ hash_map:: Entry :: Occupied ( _) => {
497
+ log_trace ! ( self , "Got second connection with {}, closing" , log_pubkey!( peer. their_node_id. unwrap( ) ) ) ;
498
+ peer. their_node_id = None ; // Unset so that we don't generate a peer_disconnected event
499
+ return Err ( PeerHandleError { no_connection_possible : false } )
500
+ } ,
501
+ hash_map:: Entry :: Vacant ( entry) => {
502
+ log_trace ! ( self , "Finished noise handshake for connection with {}" , log_pubkey!( peer. their_node_id. unwrap( ) ) ) ;
503
+ entry. insert ( peer_descriptor. clone ( ) )
504
+ } ,
505
+ } ;
493
506
}
494
507
495
508
if let & mut PeerState :: Connected ( ref mut conduit) = & mut peer. encryptor {
@@ -531,7 +544,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref> PeerManager<Descriptor, CM> where
531
544
}
532
545
}
533
546
534
- let mut next_message_result = conduit. decrypt ( & peer. pending_read_buffer ) ;
547
+ let next_message_result = conduit. decrypt ( & peer. pending_read_buffer ) ;
535
548
536
549
let offset = next_message_result. 1 ;
537
550
if offset == 0 {
0 commit comments