diff --git a/quinn-proto/src/connection/mod.rs b/quinn-proto/src/connection/mod.rs index 77b8c6e54..d3cfaeb21 100644 --- a/quinn-proto/src/connection/mod.rs +++ b/quinn-proto/src/connection/mod.rs @@ -682,12 +682,21 @@ where /// Returns `true` if a space has outgoing data to send fn space_can_send(&self, space_id: SpaceId) -> bool { - (self.spaces[space_id].crypto.is_some() && self.spaces[space_id].can_send()) - || (space_id == SpaceId::Data - && ((self.spaces[space_id].crypto.is_some() && self.can_send_1rtt()) - || (self.zero_rtt_crypto.is_some() - && self.side.is_client() - && (self.spaces[space_id].can_send() || self.can_send_1rtt())))) + if self.spaces[space_id].crypto.is_some() && self.spaces[space_id].can_send() { + return true; + } + + if space_id != SpaceId::Data { + return false; + } + + if self.spaces[space_id].crypto.is_some() && self.can_send_1rtt() { + return true; + } + + self.zero_rtt_crypto.is_some() + && self.side.is_client() + && (self.spaces[space_id].can_send() || self.can_send_1rtt()) } /// Write a new packet header to `buffer` and determine the packet's properties @@ -861,28 +870,39 @@ where let ack_eliciting = builder.ack_eliciting; let exact_number = builder.exact_number; let space_id = builder.space; - let (size, padded) = self.finish_packet(builder, buffer); + let (size, _) = self.finish_packet(builder, buffer); + let sent = match sent { + Some(sent) => sent, + None => return, + }; - if let Some(mut sent) = sent { - sent.padding = padded; + let size = match sent.padding || ack_eliciting { + true => size as u16, + false => 0, + }; - self.on_packet_sent( - now, - space_id, - exact_number, - SentPacket { - acks: sent.acks, - time_sent: now, - size: if sent.padding || ack_eliciting { - size as u16 - } else { - 0 - }, - ack_eliciting, - retransmits: sent.retransmits, - stream_frames: sent.stream_frames, - }, - ); + let packet = SentPacket { + acks: sent.acks, + time_sent: now, + size, + ack_eliciting, + retransmits: sent.retransmits, + stream_frames: sent.stream_frames, + }; + + self.in_flight.insert(&packet); + self.spaces[space_id].sent(exact_number, packet); + self.reset_keep_alive(now); + if size != 0 { + if ack_eliciting { + self.spaces[space_id].time_of_last_ack_eliciting_packet = Some(now); + if self.permit_idle_reset { + self.reset_idle_timeout(now); + } + self.permit_idle_reset = false; + } + self.set_loss_detection_timer(now); + self.path.pacing.on_transmit(size); } } @@ -1315,35 +1335,6 @@ where self.path.rtt.get() } - fn on_packet_sent( - &mut self, - now: Instant, - space: SpaceId, - packet_number: u64, - packet: SentPacket, - ) { - let SentPacket { - size, - ack_eliciting, - .. - } = packet; - - self.in_flight.insert(&packet); - self.spaces[space].sent(packet_number, packet); - self.reset_keep_alive(now); - if size != 0 { - if ack_eliciting { - self.spaces[space].time_of_last_ack_eliciting_packet = Some(now); - if self.permit_idle_reset { - self.reset_idle_timeout(now); - } - self.permit_idle_reset = false; - } - self.set_loss_detection_timer(now); - self.path.pacing.on_transmit(size); - } - } - fn on_ack_received( &mut self, now: Instant,