Skip to content

Commit 19a80e0

Browse files
Add EventLoopIteration to Connection methods: send_on_path, recv and on_timeout
1 parent 00fc7d7 commit 19a80e0

23 files changed

Lines changed: 920 additions & 281 deletions

File tree

apps/src/bin/quiche-server.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ use std::cell::RefCell;
4343

4444
use ring::rand::*;
4545

46+
use quiche::EventLoopIteration;
47+
4648
use quiche_apps::args::*;
4749

4850
use quiche_apps::common::*;
@@ -198,6 +200,8 @@ fn main() {
198200
}
199201
}
200202

203+
let iteration = EventLoopIteration::new();
204+
201205
// Read incoming UDP packets from the socket and feed them to quiche,
202206
// until there are no more packets to read.
203207
'read: loop {
@@ -207,7 +211,9 @@ fn main() {
207211
if events.is_empty() && !continue_write {
208212
trace!("timed out");
209213

210-
clients.values_mut().for_each(|c| c.conn.on_timeout());
214+
clients
215+
.values_mut()
216+
.for_each(|c| c.conn.on_timeout(&iteration));
211217

212218
break 'read;
213219
}
@@ -425,7 +431,7 @@ fn main() {
425431
};
426432

427433
// Process potentially coalesced packets.
428-
let read = match client.conn.recv(pkt_buf, recv_info) {
434+
let read = match client.conn.recv(&iteration, pkt_buf, recv_info) {
429435
Ok(v) => v,
430436

431437
Err(e) => {
@@ -561,7 +567,7 @@ fn main() {
561567
while total_write < max_send_burst {
562568
let (write, send_info) = match client
563569
.conn
564-
.send(&mut out[total_write..max_send_burst])
570+
.send(&iteration, &mut out[total_write..max_send_burst])
565571
{
566572
Ok(v) => v,
567573

apps/src/client.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
use crate::args::*;
2828
use crate::common::*;
2929

30+
use quiche::EventLoopIteration;
31+
3032
use std::io::prelude::*;
3133

3234
use std::rc::Rc;
@@ -226,7 +228,9 @@ pub fn connect(
226228
scid,
227229
);
228230

229-
let (write, send_info) = conn.send(&mut out).expect("initial send failed");
231+
let (write, send_info) = conn
232+
.send(&EventLoopIteration::new(), &mut out)
233+
.expect("initial send failed");
230234

231235
while let Err(e) = socket.send_to(&out[..write], send_info.to) {
232236
if e.kind() == std::io::ErrorKind::WouldBlock {
@@ -256,13 +260,15 @@ pub fn connect(
256260
poll.poll(&mut events, conn.timeout()).unwrap();
257261
}
258262

263+
let iteration = EventLoopIteration::new();
264+
259265
// If the event loop reported no events, it means that the timeout
260266
// has expired, so handle it without attempting to read packets. We
261267
// will then proceed with the send loop.
262268
if events.is_empty() {
263269
trace!("timed out");
264270

265-
conn.on_timeout();
271+
conn.on_timeout(&iteration);
266272
}
267273

268274
// Read incoming UDP packets from the socket and feed them to quiche,
@@ -314,7 +320,8 @@ pub fn connect(
314320
};
315321

316322
// Process potentially coalesced packets.
317-
let read = match conn.recv(&mut buf[..len], recv_info) {
323+
let read = match conn.recv(&iteration, &mut buf[..len], recv_info)
324+
{
318325
Ok(v) => v,
319326

320327
Err(e) => {
@@ -498,6 +505,7 @@ pub fn connect(
498505
for peer_addr in conn.paths_iter(local_addr) {
499506
loop {
500507
let (write, send_info) = match conn.send_on_path(
508+
&iteration,
501509
&mut out,
502510
Some(local_addr),
503511
Some(peer_addr),

fuzz/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::path::Path;
22
use std::path::PathBuf;
33

44
use quiche::h3::NameValue;
5+
use quiche::EventLoopIteration;
56

67
pub struct PktsData<'a> {
78
pub data: &'a [u8],
@@ -92,7 +93,7 @@ pub fn server_process(
9293
h3_conn: &mut Option<quiche::h3::Connection>, info: quiche::RecvInfo,
9394
) {
9495
let mut buf = pkt.to_vec();
95-
conn.recv(&mut buf, info).ok();
96+
conn.recv(&EventLoopIteration::new(), &mut buf, info).ok();
9697

9798
if (conn.is_in_early_data() || conn.is_established()) && h3_conn.is_none() {
9899
let h3_config = quiche::h3::Config::new().unwrap();
@@ -168,5 +169,5 @@ pub fn server_process(
168169
}
169170

170171
let mut out_buf = [0; 1500];
171-
while conn.send(&mut out_buf).is_ok() {}
172+
while conn.send(&EventLoopIteration::new(), &mut out_buf).is_ok() {}
172173
}

fuzz/src/packet_recv_client.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ extern crate libfuzzer_sys;
66
use std::net::SocketAddr;
77

88
use std::sync::Mutex;
9+
10+
use quiche::EventLoopIteration;
911
use std::sync::Once;
1012
use std::sync::OnceLock;
1113

@@ -57,8 +59,8 @@ fuzz_target!(|data: &[u8]| {
5759

5860
let info = quiche::RecvInfo { from, to };
5961

60-
conn.recv(&mut buf, info).ok();
62+
conn.recv(&EventLoopIteration::new(), &mut buf, info).ok();
6163

6264
let mut out_buf = [0; 1500];
63-
while conn.send(&mut out_buf).is_ok() {}
65+
while conn.send(&EventLoopIteration::new(), &mut out_buf).is_ok() {}
6466
});

fuzz/src/packet_recv_server.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ extern crate libfuzzer_sys;
66
use std::net::SocketAddr;
77

88
use std::sync::Mutex;
9+
10+
use quiche::EventLoopIteration;
911
use std::sync::Once;
1012
use std::sync::OnceLock;
1113

@@ -55,8 +57,8 @@ fuzz_target!(|data: &[u8]| {
5557

5658
let info = quiche::RecvInfo { from, to };
5759

58-
conn.recv(&mut buf, info).ok();
60+
conn.recv(&EventLoopIteration::new(), &mut buf, info).ok();
5961

6062
let mut out_buf = [0; 1500];
61-
while conn.send(&mut out_buf).is_ok() {}
63+
while conn.send(&EventLoopIteration::new(), &mut out_buf).is_ok() {}
6264
});

h3i/src/client/sync_client.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use ring::rand::*;
3535
use crate::client::QUIC_VERSION;
3636
use crate::frame::H3iFrame;
3737
use crate::quiche;
38+
use crate::quiche::EventLoopIteration;
3839

3940
use crate::actions::h3::Action;
4041
use crate::actions::h3::StreamEventType;
@@ -216,7 +217,9 @@ pub fn connect_with_early_data(
216217
let mut app_proto_selected = false;
217218

218219
// Send ClientHello and initiate the handshake.
219-
let (write, send_info) = conn.send(&mut out).expect("initial send failed");
220+
let (write, send_info) = conn
221+
.send(&EventLoopIteration::new(), &mut out)
222+
.expect("initial send failed");
220223

221224
let mut client = SyncClient::new(close_trigger_frames);
222225
// Send early data if connection is_in_early_data (resumption with 0-RTT was
@@ -285,12 +288,14 @@ pub fn connect_with_early_data(
285288
log::debug!("actual sleep is {actual_sleep:?}");
286289
poll.poll(&mut events, actual_sleep).unwrap();
287290

291+
let iteration = EventLoopIteration::new();
292+
288293
// If the event loop reported no events, run a belt and braces check on
289294
// the quiche connection's timeouts.
290295
if events.is_empty() {
291296
log::debug!("timed out");
292297

293-
conn.on_timeout();
298+
conn.on_timeout(&iteration);
294299
}
295300

296301
// Read incoming UDP packets from the socket and feed them to quiche,
@@ -326,14 +331,15 @@ pub fn connect_with_early_data(
326331
};
327332

328333
// Process potentially coalesced packets.
329-
let _read = match conn.recv(&mut buf[..len], recv_info) {
330-
Ok(v) => v,
334+
let _read =
335+
match conn.recv(&iteration, &mut buf[..len], recv_info) {
336+
Ok(v) => v,
331337

332-
Err(e) => {
333-
log::debug!("{local_addr}: recv failed: {e:?}");
334-
continue 'read;
335-
},
336-
};
338+
Err(e) => {
339+
log::debug!("{local_addr}: recv failed: {e:?}");
340+
continue 'read;
341+
},
342+
};
337343
}
338344
}
339345

@@ -433,6 +439,7 @@ pub fn connect_with_early_data(
433439
for peer_addr in conn.paths_iter(local_addr) {
434440
loop {
435441
let (write, send_info) = match conn.send_on_path(
442+
&iteration,
436443
&mut out,
437444
Some(local_addr),
438445
Some(peer_addr),

quiche/examples/client.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#[macro_use]
2828
extern crate log;
2929

30+
use quiche::EventLoopIteration;
31+
3032
use ring::rand::*;
3133

3234
const MAX_DATAGRAM_SIZE: usize = 1350;
@@ -119,7 +121,9 @@ fn main() {
119121
hex_dump(&scid)
120122
);
121123

122-
let (write, send_info) = conn.send(&mut out).expect("initial send failed");
124+
let (write, send_info) = conn
125+
.send(&EventLoopIteration::new(), &mut out)
126+
.expect("initial send failed");
123127

124128
while let Err(e) = socket.send_to(&out[..write], send_info.to) {
125129
if e.kind() == std::io::ErrorKind::WouldBlock {
@@ -139,6 +143,8 @@ fn main() {
139143
loop {
140144
poll.poll(&mut events, conn.timeout()).unwrap();
141145

146+
let iteration = EventLoopIteration::new();
147+
142148
// Read incoming UDP packets from the socket and feed them to quiche,
143149
// until there are no more packets to read.
144150
'read: loop {
@@ -148,7 +154,7 @@ fn main() {
148154
if events.is_empty() {
149155
debug!("timed out");
150156

151-
conn.on_timeout();
157+
conn.on_timeout(&iteration);
152158
break 'read;
153159
}
154160

@@ -175,7 +181,7 @@ fn main() {
175181
};
176182

177183
// Process potentially coalesced packets.
178-
let read = match conn.recv(&mut buf[..len], recv_info) {
184+
let read = match conn.recv(&iteration, &mut buf[..len], recv_info) {
179185
Ok(v) => v,
180186

181187
Err(e) => {
@@ -239,7 +245,7 @@ fn main() {
239245
// Generate outgoing QUIC packets and send them on the UDP socket, until
240246
// quiche reports that there are no more packets to be sent.
241247
loop {
242-
let (write, send_info) = match conn.send(&mut out) {
248+
let (write, send_info) = match conn.send(&iteration, &mut out) {
243249
Ok(v) => v,
244250

245251
Err(quiche::Error::Done) => {

quiche/examples/http3-client.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
extern crate log;
2929

3030
use quiche::h3::NameValue;
31+
use quiche::EventLoopIteration;
3132

3233
use ring::rand::*;
3334

@@ -116,7 +117,9 @@ fn main() {
116117
hex_dump(&scid)
117118
);
118119

119-
let (write, send_info) = conn.send(&mut out).expect("initial send failed");
120+
let (write, send_info) = conn
121+
.send(&EventLoopIteration::new(), &mut out)
122+
.expect("initial send failed");
120123

121124
while let Err(e) = socket.send_to(&out[..write], send_info.to) {
122125
if e.kind() == std::io::ErrorKind::WouldBlock {
@@ -157,6 +160,8 @@ fn main() {
157160
loop {
158161
poll.poll(&mut events, conn.timeout()).unwrap();
159162

163+
let iteration = EventLoopIteration::new();
164+
160165
// Read incoming UDP packets from the socket and feed them to quiche,
161166
// until there are no more packets to read.
162167
'read: loop {
@@ -166,7 +171,7 @@ fn main() {
166171
if events.is_empty() {
167172
debug!("timed out");
168173

169-
conn.on_timeout();
174+
conn.on_timeout(&iteration);
170175

171176
break 'read;
172177
}
@@ -194,7 +199,7 @@ fn main() {
194199
};
195200

196201
// Process potentially coalesced packets.
197-
let read = match conn.recv(&mut buf[..len], recv_info) {
202+
let read = match conn.recv(&iteration, &mut buf[..len], recv_info) {
198203
Ok(v) => v,
199204

200205
Err(e) => {
@@ -296,7 +301,7 @@ fn main() {
296301
// Generate outgoing QUIC packets and send them on the UDP socket, until
297302
// quiche reports that there are no more packets to be sent.
298303
loop {
299-
let (write, send_info) = match conn.send(&mut out) {
304+
let (write, send_info) = match conn.send(&iteration, &mut out) {
300305
Ok(v) => v,
301306

302307
Err(quiche::Error::Done) => {

quiche/examples/http3-server.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ use std::net;
3131

3232
use std::collections::HashMap;
3333

34-
use ring::rand::*;
35-
3634
use quiche::h3::NameValue;
35+
use quiche::EventLoopIteration;
36+
37+
use ring::rand::*;
3738

3839
const MAX_DATAGRAM_SIZE: usize = 1350;
3940

@@ -124,6 +125,8 @@ fn main() {
124125

125126
poll.poll(&mut events, timeout).unwrap();
126127

128+
let iteration = EventLoopIteration::new();
129+
127130
// Read incoming UDP packets from the socket and feed them to quiche,
128131
// until there are no more packets to read.
129132
'read: loop {
@@ -133,7 +136,9 @@ fn main() {
133136
if events.is_empty() {
134137
debug!("timed out");
135138

136-
clients.values_mut().for_each(|c| c.conn.on_timeout());
139+
clients
140+
.values_mut()
141+
.for_each(|c| c.conn.on_timeout(&iteration));
137142

138143
break 'read;
139144
}
@@ -295,7 +300,7 @@ fn main() {
295300
};
296301

297302
// Process potentially coalesced packets.
298-
let read = match client.conn.recv(pkt_buf, recv_info) {
303+
let read = match client.conn.recv(&iteration, pkt_buf, recv_info) {
299304
Ok(v) => v,
300305

301306
Err(e) => {
@@ -399,7 +404,10 @@ fn main() {
399404
// packets to be sent.
400405
for client in clients.values_mut() {
401406
loop {
402-
let (write, send_info) = match client.conn.send(&mut out) {
407+
let (write, send_info) = match client
408+
.conn
409+
.send(&iteration, &mut out)
410+
{
403411
Ok(v) => v,
404412

405413
Err(quiche::Error::Done) => {

0 commit comments

Comments
 (0)