Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style tweaks #1026

Merged
merged 3 commits into from
Feb 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 46 additions & 55 deletions quinn-proto/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely a lot easier to follow than the previous and/or chain 👍

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
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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,
Expand Down