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

refactor: deduplicate events #1818

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
35 changes: 14 additions & 21 deletions neqo-http3/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,28 +131,21 @@ impl Http3Server {
fn process_http3(&mut self, now: Instant) {
qtrace!([self], "Process http3 internal.");
let mut active_conns = self.server.active_connections();

// We need to find connections that needs to be process on http3 level.
let mut http3_active: Vec<ActiveConnectionRef> = self
.http3_handlers
.iter()
.filter_map(|(conn, handler)| {
if handler.borrow_mut().should_be_processed() && !active_conns.contains(conn) {
Some(conn)
} else {
None
}
})
.cloned()
.collect();
// For http_active connection we need to put them in neqo-transport's server
// waiting queue.
active_conns.append(&mut http3_active);
active_conns.dedup();
active_conns
.iter()
.for_each(|conn| self.server.add_to_waiting(conn));
active_conns.extend(
// We need to find connections that needs to be process on http3 level.
self.http3_handlers
.iter()
.filter_map(|(conn, handler)| {
if handler.borrow_mut().should_be_processed() {
Some(conn)
} else {
None
}
})
.cloned(),
);
for mut conn in active_conns {
self.server.add_to_waiting(&conn);
self.process_events(&mut conn, now);
}
}
Expand Down
4 changes: 2 additions & 2 deletions neqo-transport/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,8 @@ impl Server {

/// This lists the connections that have received new events
/// as a result of calling `process()`.
pub fn active_connections(&mut self) -> Vec<ActiveConnectionRef> {
mem::take(&mut self.active).into_iter().collect()
pub fn active_connections(&mut self) -> HashSet<ActiveConnectionRef> {
mem::take(&mut self.active)
}

pub fn add_to_waiting(&mut self, c: &ActiveConnectionRef) {
Expand Down
24 changes: 22 additions & 2 deletions neqo-transport/tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,17 @@ fn zero_rtt() {
// The server will have received two STREAM frames now if it processed both packets.
let active = server.active_connections();
assert_eq!(active.len(), 1);
assert_eq!(active[0].borrow().stats().frame_rx.stream, 2);
assert_eq!(
active
.iter()
.next()
.unwrap()
.borrow()
.stats()
.frame_rx
.stream,
2
);

// Complete the handshake. As the client was pacing 0-RTT packets, extend the time
// a little so that the pacer doesn't prevent the Finished from being sent.
Expand All @@ -321,7 +331,17 @@ fn zero_rtt() {
mem::drop(server.process(Some(&c4), now));
let active = server.active_connections();
assert_eq!(active.len(), 1);
assert_eq!(active[0].borrow().stats().frame_rx.stream, 2);
assert_eq!(
active
.iter()
.next()
.unwrap()
.borrow()
.stats()
.frame_rx
.stream,
2
);
}

#[test]
Expand Down