Skip to content

Commit 54b7464

Browse files
committed
Restrict conduit borrow scope for compatibility with Rust 1.22.0.
1 parent 029bb66 commit 54b7464

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

lightning/src/ln/peers/handler.rs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ impl PeerState {
129129
}
130130

131131
fn process_peer_data(&mut self, data: &[u8], mutable_response_buffer: &mut LinkedList<Vec<u8>>) -> PeerDataProcessingDecision {
132+
let mut conduit_option = None;
133+
let mut decision_option = None;
134+
132135
match self {
133136
&mut PeerState::Authenticating(ref mut handshake) => {
134137
let (next_act, conduit) = match handshake.process_act(data) {
@@ -145,8 +148,8 @@ impl PeerState {
145148

146149
let remote_pubkey_option = handshake.get_remote_pubkey();
147150
if let Some(conduit) = conduit {
148-
*self = PeerState::Connected(conduit);
149-
return PeerDataProcessingDecision::CompleteHandshake(requires_response, remote_pubkey_option);
151+
conduit_option = Some(conduit);
152+
decision_option = Some(PeerDataProcessingDecision::CompleteHandshake(requires_response, remote_pubkey_option));
150153
}
151154
}
152155

@@ -155,6 +158,11 @@ impl PeerState {
155158
}
156159
};
157160

161+
if let (Some(conduit), Some(decision)) = (conduit_option, decision_option) {
162+
*self = PeerState::Connected(conduit);
163+
return decision;
164+
}
165+
158166
PeerDataProcessingDecision::Continue
159167
}
160168
}
@@ -169,8 +177,6 @@ struct Peer {
169177
pending_outbound_buffer_first_msg_offset: usize,
170178
awaiting_write_event: bool,
171179

172-
pending_read_buffer: Vec<u8>,
173-
174180
sync_status: InitSyncTracker,
175181

176182
awaiting_pong: bool,
@@ -338,8 +344,6 @@ impl<Descriptor: SocketDescriptor, CM: Deref> PeerManager<Descriptor, CM> where
338344
pending_outbound_buffer_first_msg_offset: 0,
339345
awaiting_write_event: false,
340346

341-
pending_read_buffer: Vec::new(),
342-
343347
sync_status: InitSyncTracker::NoSyncRequested,
344348

345349
awaiting_pong: false,
@@ -372,8 +376,6 @@ impl<Descriptor: SocketDescriptor, CM: Deref> PeerManager<Descriptor, CM> where
372376
pending_outbound_buffer_first_msg_offset: 0,
373377
awaiting_write_event: false,
374378

375-
pending_read_buffer: Vec::new(),
376-
377379
sync_status: InitSyncTracker::NoSyncRequested,
378380

379381
awaiting_pong: false,
@@ -516,7 +518,6 @@ impl<Descriptor: SocketDescriptor, CM: Deref> PeerManager<Descriptor, CM> where
516518
Some(peer) => {
517519

518520
let mut send_init_message = false;
519-
let mut conduit_option = None;
520521

521522
let data_processing_decision = peer.encryptor.process_peer_data(data, &mut peer.pending_outbound_buffer);
522523
match data_processing_decision {
@@ -543,19 +544,11 @@ impl<Descriptor: SocketDescriptor, CM: Deref> PeerManager<Descriptor, CM> where
543544
entry.insert(peer_descriptor.clone())
544545
}
545546
};
546-
547-
if let &mut PeerState::Connected(ref mut conduit) = &mut peer.encryptor {
548-
conduit_option = Some(conduit);
549-
}
550-
}
551-
PeerDataProcessingDecision::Continue => {
552-
if let &mut PeerState::Connected(ref mut conduit) = &mut peer.encryptor {
553-
conduit_option = Some(conduit);
554-
}
555547
}
548+
_ => {}
556549
};
557550

558-
if let Some(conduit) = conduit_option {
551+
if let &mut PeerState::Connected(ref mut conduit) = &mut peer.encryptor {
559552

560553
let encryptor = &mut conduit.encryptor;
561554
let decryptor = &mut conduit.decryptor;

0 commit comments

Comments
 (0)