Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 3 additions & 5 deletions neqo-transport/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,6 @@ impl Server {
}
}

assert!(
self.saved_datagrams.is_empty(),
"Otherwise, there would be more work to do."
);

OutputBatch::None
}

Expand Down Expand Up @@ -533,6 +528,7 @@ impl Server {
now: Instant,
max_datagrams: NonZeroUsize,
) -> OutputBatch {
// Process input datagrams from previous call.
while let Some(SavedDatagram { d, t }) = self.saved_datagrams.pop_front() {
if let OutputBatch::DatagramBatch(b) = self.process_input(std::iter::once(d), t) {
self.saved_datagrams
Expand All @@ -545,11 +541,13 @@ impl Server {
}
}

// Process input datagrams from this call.
if let o @ OutputBatch::DatagramBatch(_) = self.process_input(dgrams, now) {
// Return immediately. Do any maintenance on next call.
return o;
}

// Process output datagrams.
let maybe_callback = match self.process_next_output(now, max_datagrams) {
// Return immediately. Do any maintenance on next call.
o @ OutputBatch::DatagramBatch(_) => return o,
Expand Down
56 changes: 36 additions & 20 deletions neqo-transport/tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,40 +900,56 @@ fn has_active_connections() {
#[test]
fn saved_datagrams() {
let mut server = default_server();
let mut client = default_client();

// Any packet will do, but let's make something that looks real.
let damaged_dgram = {
let dgram = client.process_output(now()).dgram().expect("a datagram");
let mut input = dgram.to_vec();
input[1] ^= 0x12;
Datagram::new(
dgram.source(),
dgram.destination(),
dgram.tos(),
input.clone(),
)
let valid_dgram = {
let mut client = default_client();
client.process_output(now()).dgram().expect("a datagram")
};

// Server sends a version negotation immediately. Saves second input datagram for later.
// Any packet will do, but let's make something that looks real.
let mut invalid_dgrams: Vec<_> = [0x12, 0x13, 0x14]
.into_iter()
.map(|damage| {
let mut client = default_client();
let dgram = client.process_output(now()).dgram().expect("a datagram");
let mut input = dgram.to_vec();
input[1] ^= damage;
Datagram::new(
dgram.source(),
dgram.destination(),
dgram.tos(),
input.clone(),
)
})
.collect();

// Server sends a version negotation immediately. Saves second and third
// input datagram for later.
server
.process_multiple(
vec![damaged_dgram.clone(), damaged_dgram.clone()],
vec![
invalid_dgrams.pop().unwrap(),
Comment thread
mxinden marked this conversation as resolved.
Resolved
valid_dgram,
invalid_dgrams.pop().unwrap(),
],
now(),
1.try_into().expect("1>0"),
)
.dgram()
.expect("first vn");
.expect("first packet triggers first vn");

// Server processes the second datagram and saves the third.
// Server processes the second (valid) datagram which doesn't require an
// immediate response. Server then processes the third (invalid) datagram
// which does require an immediate response. It thereby has to save the
// fourth (new) datagram for the next call.
server
.process_multiple(vec![damaged_dgram], now(), 1.try_into().expect("1>0"))
.process_multiple(invalid_dgrams.pop(), now(), 1.try_into().expect("1>0"))
.dgram()
.expect("second vn");
.expect("third packet triggers second vn");

// Server processes the third datagram.
// Server processes the fourth datagram.
server
.process_multiple(Vec::<Datagram>::new(), now(), 1.try_into().expect("1>0"))
.dgram()
.expect("third vn");
.expect("fourth packet triggers third vn");
}