Skip to content

Commit 6f4e76a

Browse files
committed
Group peer handler's connected state checks instead of repeating them in each iteration.
1 parent 6cf5a07 commit 6f4e76a

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

lightning/src/ln/peer_handler.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -901,32 +901,22 @@ impl<Descriptor: SocketDescriptor, CM: Deref> PeerManager<Descriptor, CM> where
901901
let (mut descriptor, peer) = get_peer_for_forwarding!(node_id, {
902902
//TODO: Do whatever we're gonna do for handling dropped messages
903903
});
904-
for msg in update_add_htlcs {
905-
if let PeerState::Connected(ref mut conduit) = peer.encryptor {
904+
if let PeerState::Connected(ref mut conduit) = peer.encryptor {
905+
for msg in update_add_htlcs {
906906
peer.pending_outbound_buffer.push_back(conduit.encrypt(&encode_msg!(msg)));
907907
}
908-
}
909-
for msg in update_fulfill_htlcs {
910-
if let PeerState::Connected(ref mut conduit) = peer.encryptor {
908+
for msg in update_fulfill_htlcs {
911909
peer.pending_outbound_buffer.push_back(conduit.encrypt(&encode_msg!(msg)));
912910
}
913-
}
914-
for msg in update_fail_htlcs {
915-
if let PeerState::Connected(ref mut conduit) = peer.encryptor {
911+
for msg in update_fail_htlcs {
916912
peer.pending_outbound_buffer.push_back(conduit.encrypt(&encode_msg!(msg)));
917913
}
918-
}
919-
for msg in update_fail_malformed_htlcs {
920-
if let PeerState::Connected(ref mut conduit) = peer.encryptor {
914+
for msg in update_fail_malformed_htlcs {
921915
peer.pending_outbound_buffer.push_back(conduit.encrypt(&encode_msg!(msg)));
922916
}
923-
}
924-
if let &Some(ref msg) = update_fee {
925-
if let PeerState::Connected(ref mut conduit) = peer.encryptor {
917+
if let &Some(ref msg) = update_fee {
926918
peer.pending_outbound_buffer.push_back(conduit.encrypt(&encode_msg!(msg)));
927919
}
928-
}
929-
if let PeerState::Connected(ref mut conduit) = peer.encryptor {
930920
peer.pending_outbound_buffer.push_back(conduit.encrypt(&encode_msg!(commitment_signed)));
931921
}
932922
self.do_attempt_write_data(&mut descriptor, peer);
@@ -1012,11 +1002,13 @@ impl<Descriptor: SocketDescriptor, CM: Deref> PeerManager<Descriptor, CM> where
10121002
let encoded_msg = encode_msg!(msg);
10131003

10141004
for (ref descriptor, ref mut peer) in peers.peers.iter_mut() {
1015-
if !peer.channel_encryptor.is_ready_for_encryption() || peer.their_features.is_none() ||
1005+
if !peer.encryptor.is_ready_for_encryption() || peer.their_features.is_none() ||
10161006
!peer.should_forward_node_announcement(msg.contents.node_id) {
10171007
continue
10181008
}
1019-
peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encoded_msg[..]));
1009+
if let PeerState::Connected(ref mut conduit) = peer.encryptor {
1010+
peer.pending_outbound_buffer.push_back(conduit.encrypt(&encoded_msg[..]));
1011+
}
10201012
self.do_attempt_write_data(&mut (*descriptor).clone(), peer);
10211013
}
10221014
}

0 commit comments

Comments
 (0)