Skip to content

Commit a128bc5

Browse files
committed
respond to Jeff's comments and add node pubkeys to map
1 parent 100e5a9 commit a128bc5

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lightning/src/ln/peer_handler.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,19 @@ impl<Descriptor: SocketDescriptor, CM: Deref> PeerManager<Descriptor, CM> where
490490
if let Some(conduit) = conduit_option {
491491
// Rust 1.22 does not allow assignment in a borrowed context, even if mutable
492492
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+
};
493506
}
494507

495508
if let &mut PeerState::Connected(ref mut conduit) = &mut peer.encryptor {
@@ -531,7 +544,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref> PeerManager<Descriptor, CM> where
531544
}
532545
}
533546

534-
let mut next_message_result = conduit.decrypt(&peer.pending_read_buffer);
547+
let next_message_result = conduit.decrypt(&peer.pending_read_buffer);
535548

536549
let offset = next_message_result.1;
537550
if offset == 0 {

lightning/src/ln/peers/conduit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl Conduit {
3838
}
3939

4040
pub(super) fn read(&mut self, data: &[u8]) {
41-
let mut read_buffer = self.read_buffer.get_or_insert(Vec::new());
41+
let read_buffer = self.read_buffer.get_or_insert(Vec::new());
4242
read_buffer.extend_from_slice(data);
4343
}
4444

0 commit comments

Comments
 (0)