Skip to content

Commit 462bc10

Browse files
committed
rename: s/is_ready_for_encryption/is_connected/g
1 parent 4e21958 commit 462bc10

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

lightning/src/ln/peers/handler.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub(super) trait ITransport {
5858
fn process_input(&mut self, input: &[u8], output_buffer: &mut impl PayloadQueuer) -> Result<(), String>;
5959

6060
/// Returns true if the connection is established and encrypted messages can be sent.
61-
fn is_ready_for_encryption(&self) -> bool;
61+
fn is_connected(&self) -> bool;
6262

6363
/// Encodes, encrypts, and enqueues a message to the outbound queue. Panics if the connection is
6464
/// not established yet.
@@ -333,7 +333,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
333333
pub fn get_peer_node_ids(&self) -> Vec<PublicKey> {
334334
let peers = self.peers.lock().unwrap();
335335
peers.peers.values().filter_map(|p| {
336-
if !p.transport.is_ready_for_encryption() || p.their_features.is_none() {
336+
if !p.transport.is_connected() || p.their_features.is_none() {
337337
return None;
338338
}
339339
p.their_node_id
@@ -416,7 +416,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
416416
($msg: expr) => {
417417
{
418418
log_trace!(self.logger, "Encoding and sending sync update message of type {} to {}", $msg.type_id(), log_pubkey!(peer.their_node_id.unwrap()));
419-
assert!(peer.transport.is_ready_for_encryption());
419+
assert!(peer.transport.is_connected());
420420
peer.transport.enqueue_message($msg, &mut peer.pending_outbound_buffer)
421421
}
422422
}
@@ -546,7 +546,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
546546
Ok(_) => {
547547

548548
// If the transport is newly connected, do the appropriate set up for the connection
549-
if peer.transport.is_ready_for_encryption() {
549+
if peer.transport.is_connected() {
550550
let their_node_id = peer.transport.their_node_id.unwrap();
551551

552552
match peers.node_id_to_descriptor.entry(their_node_id.clone()) {
@@ -915,7 +915,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
915915
let (mut descriptor, peer) = get_peer_for_forwarding!(node_id, {
916916
//TODO: Drop the pending channel? (or just let it timeout, but that sucks)
917917
});
918-
if peer.transport.is_ready_for_encryption() {
918+
if peer.transport.is_connected() {
919919
peer.transport.enqueue_message(msg, &mut peer.pending_outbound_buffer);
920920
}
921921
self.do_attempt_write_data(&mut descriptor, peer);
@@ -927,7 +927,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
927927
let (mut descriptor, peer) = get_peer_for_forwarding!(node_id, {
928928
//TODO: Drop the pending channel? (or just let it timeout, but that sucks)
929929
});
930-
if peer.transport.is_ready_for_encryption() {
930+
if peer.transport.is_connected() {
931931
peer.transport.enqueue_message(msg, &mut peer.pending_outbound_buffer);
932932
}
933933
self.do_attempt_write_data(&mut descriptor, peer);
@@ -941,7 +941,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
941941
//TODO: generate a DiscardFunding event indicating to the wallet that
942942
//they should just throw away this funding transaction
943943
});
944-
if peer.transport.is_ready_for_encryption() {
944+
if peer.transport.is_connected() {
945945
peer.transport.enqueue_message(msg, &mut peer.pending_outbound_buffer);
946946
}
947947
self.do_attempt_write_data(&mut descriptor, peer);
@@ -954,7 +954,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
954954
//TODO: generate a DiscardFunding event indicating to the wallet that
955955
//they should just throw away this funding transaction
956956
});
957-
if peer.transport.is_ready_for_encryption() {
957+
if peer.transport.is_connected() {
958958
peer.transport.enqueue_message(msg, &mut peer.pending_outbound_buffer);
959959
}
960960
self.do_attempt_write_data(&mut descriptor, peer);
@@ -966,7 +966,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
966966
let (mut descriptor, peer) = get_peer_for_forwarding!(node_id, {
967967
//TODO: Do whatever we're gonna do for handling dropped messages
968968
});
969-
if peer.transport.is_ready_for_encryption() {
969+
if peer.transport.is_connected() {
970970
peer.transport.enqueue_message(msg, &mut peer.pending_outbound_buffer);
971971
}
972972
self.do_attempt_write_data(&mut descriptor, peer);
@@ -979,7 +979,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
979979
//TODO: generate a DiscardFunding event indicating to the wallet that
980980
//they should just throw away this funding transaction
981981
});
982-
if peer.transport.is_ready_for_encryption() {
982+
if peer.transport.is_connected() {
983983
peer.transport.enqueue_message(msg, &mut peer.pending_outbound_buffer);
984984
}
985985
self.do_attempt_write_data(&mut descriptor, peer);
@@ -994,7 +994,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
994994
let (mut descriptor, peer) = get_peer_for_forwarding!(node_id, {
995995
//TODO: Do whatever we're gonna do for handling dropped messages
996996
});
997-
if peer.transport.is_ready_for_encryption() {
997+
if peer.transport.is_connected() {
998998
for msg in update_add_htlcs {
999999
peer.transport.enqueue_message(msg, &mut peer.pending_outbound_buffer);
10001000
}
@@ -1021,7 +1021,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
10211021
let (mut descriptor, peer) = get_peer_for_forwarding!(node_id, {
10221022
//TODO: Do whatever we're gonna do for handling dropped messages
10231023
});
1024-
if peer.transport.is_ready_for_encryption() {
1024+
if peer.transport.is_connected() {
10251025
peer.transport.enqueue_message(msg, &mut peer.pending_outbound_buffer);
10261026
}
10271027
self.do_attempt_write_data(&mut descriptor, peer);
@@ -1033,7 +1033,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
10331033
let (mut descriptor, peer) = get_peer_for_forwarding!(node_id, {
10341034
//TODO: Do whatever we're gonna do for handling dropped messages
10351035
});
1036-
if peer.transport.is_ready_for_encryption() {
1036+
if peer.transport.is_connected() {
10371037
peer.transport.enqueue_message(msg, &mut peer.pending_outbound_buffer);
10381038
}
10391039
self.do_attempt_write_data(&mut descriptor, peer);
@@ -1045,7 +1045,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
10451045
let (mut descriptor, peer) = get_peer_for_forwarding!(node_id, {
10461046
//TODO: Do whatever we're gonna do for handling dropped messages
10471047
});
1048-
if peer.transport.is_ready_for_encryption() {
1048+
if peer.transport.is_connected() {
10491049
peer.transport.enqueue_message(msg, &mut peer.pending_outbound_buffer);
10501050
}
10511051
self.do_attempt_write_data(&mut descriptor, peer);
@@ -1057,7 +1057,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
10571057
let (mut descriptor, peer) = get_peer_for_forwarding!(node_id, {
10581058
//TODO: Do whatever we're gonna do for handling dropped messages
10591059
});
1060-
if peer.transport.is_ready_for_encryption() {
1060+
if peer.transport.is_connected() {
10611061
peer.transport.enqueue_message(msg, &mut peer.pending_outbound_buffer);
10621062
}
10631063
self.do_attempt_write_data(&mut descriptor, peer);
@@ -1066,7 +1066,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
10661066
log_trace!(self.logger, "Handling BroadcastChannelAnnouncement event in peer_handler for short channel id {}", msg.contents.short_channel_id);
10671067
if self.message_handler.route_handler.handle_channel_announcement(msg).is_ok() && self.message_handler.route_handler.handle_channel_update(update_msg).is_ok() {
10681068
for (ref descriptor, ref mut peer) in peers.peers.iter_mut() {
1069-
if !peer.transport.is_ready_for_encryption() || peer.their_features.is_none() ||
1069+
if !peer.transport.is_connected() || peer.their_features.is_none() ||
10701070
!peer.should_forward_channel_announcement(msg.contents.short_channel_id) {
10711071
continue
10721072
}
@@ -1078,7 +1078,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
10781078
}
10791079
}
10801080
}
1081-
if peer.transport.is_ready_for_encryption() {
1081+
if peer.transport.is_connected() {
10821082
peer.transport.enqueue_message(msg, &mut peer.pending_outbound_buffer);
10831083
peer.transport.enqueue_message(update_msg, &mut peer.pending_outbound_buffer);
10841084
}
@@ -1090,11 +1090,11 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
10901090
log_trace!(self.logger, "Handling BroadcastNodeAnnouncement event in peer_handler");
10911091
if self.message_handler.route_handler.handle_node_announcement(msg).is_ok() {
10921092
for (ref descriptor, ref mut peer) in peers.peers.iter_mut() {
1093-
if !peer.transport.is_ready_for_encryption() || peer.their_features.is_none() ||
1093+
if !peer.transport.is_connected() || peer.their_features.is_none() ||
10941094
!peer.should_forward_node_announcement(msg.contents.node_id) {
10951095
continue
10961096
}
1097-
if peer.transport.is_ready_for_encryption() {
1097+
if peer.transport.is_connected() {
10981098
peer.transport.enqueue_message(msg, &mut peer.pending_outbound_buffer);
10991099
}
11001100
self.do_attempt_write_data(&mut (*descriptor).clone(), peer);
@@ -1105,11 +1105,11 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
11051105
log_trace!(self.logger, "Handling BroadcastChannelUpdate event in peer_handler for short channel id {}", msg.contents.short_channel_id);
11061106
if self.message_handler.route_handler.handle_channel_update(msg).is_ok() {
11071107
for (ref descriptor, ref mut peer) in peers.peers.iter_mut() {
1108-
if !peer.transport.is_ready_for_encryption() || peer.their_features.is_none() ||
1108+
if !peer.transport.is_connected() || peer.their_features.is_none() ||
11091109
!peer.should_forward_channel_announcement(msg.contents.short_channel_id) {
11101110
continue
11111111
}
1112-
if peer.transport.is_ready_for_encryption() {
1112+
if peer.transport.is_connected() {
11131113
peer.transport.enqueue_message(msg, &mut peer.pending_outbound_buffer);
11141114
}
11151115
self.do_attempt_write_data(&mut (*descriptor).clone(), peer);
@@ -1129,7 +1129,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
11291129
log_trace!(self.logger, "Handling DisconnectPeer HandleError event in peer_handler for node {} with message {}",
11301130
log_pubkey!(node_id),
11311131
msg.data);
1132-
if peer.transport.is_ready_for_encryption() {
1132+
if peer.transport.is_connected() {
11331133
peer.transport.enqueue_message(msg, &mut peer.pending_outbound_buffer);
11341134
}
11351135
// This isn't guaranteed to work, but if there is enough free
@@ -1151,7 +1151,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
11511151
let (mut descriptor, peer) = get_peer_for_forwarding!(node_id, {
11521152
//TODO: Do whatever we're gonna do for handling dropped messages
11531153
});
1154-
if peer.transport.is_ready_for_encryption() {
1154+
if peer.transport.is_connected() {
11551155
peer.transport.enqueue_message(msg, &mut peer.pending_outbound_buffer);
11561156
}
11571157
self.do_attempt_write_data(&mut descriptor, peer);
@@ -1225,15 +1225,15 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
12251225
}
12261226
None => {
12271227
// This can't actually happen as we should have hit
1228-
// is_ready_for_encryption() previously on this same peer.
1228+
// is_connected() previously on this same peer.
12291229
unreachable!();
12301230
},
12311231
}
12321232
return false;
12331233
}
12341234

12351235
let mut needs_to_write_data = false;
1236-
if peer.transport.is_ready_for_encryption() {
1236+
if peer.transport.is_connected() {
12371237
let ping = msgs::Ping {
12381238
ponglen: 0,
12391239
byteslen: 64,

lightning/src/ln/peers/transport.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl<PeerHandshakeImpl: IPeerHandshake> ITransport for Transport<PeerHandshakeIm
7878
Ok(())
7979
}
8080

81-
fn is_ready_for_encryption(&self) -> bool {
81+
fn is_connected(&self) -> bool {
8282
self.conduit.is_some()
8383
}
8484

@@ -125,15 +125,15 @@ mod tests {
125125
fn inbound_unconnected() {
126126
let transport = create_inbound_for_test::<PeerHandshakeTestStubFail>();
127127

128-
assert!(!transport.is_ready_for_encryption());
128+
assert!(!transport.is_connected());
129129
}
130130

131131
#[test]
132132
fn outbound_unconnected() {
133133
let mut transport = create_outbound_for_test::<PeerHandshakeTestStubFail>();
134134
transport.set_up_outbound();
135135

136-
assert!(!transport.is_ready_for_encryption());
136+
assert!(!transport.is_connected());
137137
}
138138

139139
// Test that errors in the handshake code are reraised through the transport
@@ -159,7 +159,7 @@ mod tests {
159159
let mut spy = Vec::new();
160160

161161
transport.process_input(&[], &mut spy).unwrap();
162-
assert!(!transport.is_ready_for_encryption());
162+
assert!(!transport.is_connected());
163163

164164
assert_matches!(&spy[..], [_]);
165165
}
@@ -171,7 +171,7 @@ mod tests {
171171
let mut spy = Vec::new();
172172

173173
transport.process_input(&[], &mut spy).unwrap();
174-
assert!(!transport.is_ready_for_encryption());
174+
assert!(!transport.is_connected());
175175

176176
assert_matches!(&spy[..], [_]);
177177
}
@@ -182,17 +182,17 @@ mod tests {
182182
let mut spy = Vec::new();
183183

184184
transport.process_input(&[], &mut spy).unwrap();
185-
assert!(transport.is_ready_for_encryption());
185+
assert!(transport.is_connected());
186186
}
187187

188-
// Test that when a handshake completes is_ready_for_encryption() is correct
188+
// Test that when a handshake completes is_connected() is correct
189189
#[test]
190190
fn outbound_handshake_complete_ready_for_encryption() {
191191
let mut transport = create_outbound_for_test::<PeerHandshakeTestStubComplete>();
192192
let mut spy = Vec::new();
193193

194194
transport.process_input(&[], &mut spy).unwrap();
195-
assert!(transport.is_ready_for_encryption());
195+
assert!(transport.is_connected());
196196
}
197197

198198
#[test]

0 commit comments

Comments
 (0)