diff options
author | 2022-09-29 15:54:31 +0200 | |
---|---|---|
committer | 2022-09-29 14:54:31 +0100 | |
commit | 06632d78c92d0b6a585bca713a04ae2fb62cd23b (patch) | |
tree | d06f1363b8624b076491d13c463888a0f749cd60 | |
parent | f51a64e109a8c0055a3c7c5acf208f287a31b797 (diff) | |
download | quiche-06632d78c92d0b6a585bca713a04ae2fb62cd23b.tar.gz quiche-06632d78c92d0b6a585bca713a04ae2fb62cd23b.tar.zst quiche-06632d78c92d0b6a585bca713a04ae2fb62cd23b.zip |
refactor processing undecrypted 0-RTT packets
Motivation:
There was some code-duplication which can be removed by adding function.
Modifications:
Add process_undecrypted_0rtt_packets
Result:
Share code / cleanup
-rw-r--r-- | quiche/src/lib.rs | 43 |
1 files changed, 17 insertions, 26 deletions
diff --git a/quiche/src/lib.rs b/quiche/src/lib.rs index 1b290808..c438bcc1 100644 --- a/quiche/src/lib.rs +++ b/quiche/src/lib.rs @@ -2034,6 +2034,15 @@ impl Connection { left -= read; } + // Even though the packet was previously "accepted", it + // should be safe to forward the error, as it also comes + // from the `recv()` method. + self.process_undecrypted_0rtt_packets()?; + + Ok(done) + } + + fn process_undecrypted_0rtt_packets(&mut self) -> Result<()> { // Process previously undecryptable 0-RTT packets if the decryption key // is now available. if self.pkt_num_spaces[packet::EPOCH_APPLICATION] @@ -2045,15 +2054,11 @@ impl Connection { if let Err(e) = self.recv(&mut pkt, info) { self.undecryptable_pkts.clear(); - // Even though the packet was previously "accepted", it - // should be safe to forward the error, as it also comes - // from the `recv()` method. return Err(e); } } } - - Ok(done) + Ok(()) } /// Processes a single QUIC packet received from the peer. @@ -2878,27 +2883,13 @@ impl Connection { self.do_handshake()?; } - // Process previously undecryptable 0-RTT packets if the decryption key - // is now available. - if self.pkt_num_spaces[packet::EPOCH_APPLICATION] - .crypto_0rtt_open - .is_some() - { - while let Some((mut pkt, info)) = self.undecryptable_pkts.pop_front() - { - if self.recv(&mut pkt, info).is_err() { - self.undecryptable_pkts.clear(); - - // Forwarding the error value here could confuse - // applications, as they may not expect getting a `recv()` - // error when calling `send()`. - // - // We simply fall-through to sending packets, which should - // take care of terminating the connection as needed. - break; - } - } - } + // Forwarding the error value here could confuse + // applications, as they may not expect getting a `recv()` + // error when calling `send()`. + // + // We simply fall-through to sending packets, which should + // take care of terminating the connection as needed. + let _ = self.process_undecrypted_0rtt_packets(); // There's no point in trying to send a packet if the Initial secrets // have not been derived yet, so return early. |