Skip to content

Commit 2bff132

Browse files
committed
lib: support idle timeout reconfiguration
1 parent b17904e commit 2bff132

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

quiche/include/quiche.h

+4
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,10 @@ void quiche_conn_set_qlog_fd(quiche_conn *conn, int fd, const char *log_title,
333333
// Configures the given session for resumption.
334334
int quiche_conn_set_session(quiche_conn *conn, const uint8_t *buf, size_t buf_len);
335335

336+
// Sets the `max_idle_timeout` transport parameter, in milliseconds, default is
337+
// no timeout.
338+
int quiche_conn_set_max_idle_timeout(quiche_conn *conn, uint64_t v);
339+
336340
typedef struct {
337341
// The remote address the packet was received from.
338342
struct sockaddr *from;

quiche/src/ffi.rs

+11
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,17 @@ pub extern fn quiche_conn_set_session(
725725
}
726726
}
727727

728+
#[no_mangle]
729+
pub extern fn quiche_conn_set_max_idle_timeout(
730+
conn: &mut Connection, v: u64,
731+
) -> c_int {
732+
match conn.set_max_idle_timeout(v) {
733+
Ok(()) => 0,
734+
735+
Err(e) => e.to_c() as c_int,
736+
}
737+
}
738+
728739
#[repr(C)]
729740
pub struct RecvInfo<'a> {
730741
from: &'a sockaddr,

quiche/src/lib.rs

+47
Original file line numberDiff line numberDiff line change
@@ -2198,6 +2198,19 @@ impl Connection {
21982198
Ok(())
21992199
}
22002200

2201+
/// Sets the `max_idle_timeout` transport parameter, in milliseconds.
2202+
///
2203+
/// This must only be called immediately after creating a connection, that
2204+
/// is, before any packet is sent or received.
2205+
///
2206+
/// The default value is infinite, that is, no timeout is used unless
2207+
/// already configured when creating the connection.
2208+
pub fn set_max_idle_timeout(&mut self, v: u64) -> Result<()> {
2209+
self.local_transport_params.max_idle_timeout = v;
2210+
2211+
self.encode_transport_params()
2212+
}
2213+
22012214
/// Processes QUIC packets received from the peer.
22022215
///
22032216
/// On success the number of bytes processed from the input buffer is
@@ -9228,6 +9241,40 @@ mod tests {
92289241
);
92299242
}
92309243

9244+
#[test]
9245+
fn change_idle_timeout() {
9246+
let mut config = Config::new(0x1).unwrap();
9247+
config
9248+
.set_application_protos(&[b"proto1", b"proto2"])
9249+
.unwrap();
9250+
config.set_max_idle_timeout(999999);
9251+
config.verify_peer(false);
9252+
9253+
let mut pipe = testing::Pipe::with_client_config(&mut config).unwrap();
9254+
assert_eq!(pipe.client.local_transport_params.max_idle_timeout, 999999);
9255+
assert_eq!(pipe.client.peer_transport_params.max_idle_timeout, 0);
9256+
assert_eq!(pipe.server.local_transport_params.max_idle_timeout, 0);
9257+
assert_eq!(pipe.server.peer_transport_params.max_idle_timeout, 0);
9258+
9259+
pipe.client.set_max_idle_timeout(456000).unwrap();
9260+
pipe.server.set_max_idle_timeout(234000).unwrap();
9261+
assert_eq!(pipe.client.local_transport_params.max_idle_timeout, 456000);
9262+
assert_eq!(pipe.client.peer_transport_params.max_idle_timeout, 0);
9263+
assert_eq!(pipe.server.local_transport_params.max_idle_timeout, 234000);
9264+
assert_eq!(pipe.server.peer_transport_params.max_idle_timeout, 0);
9265+
9266+
assert_eq!(pipe.handshake(), Ok(()));
9267+
9268+
assert_eq!(
9269+
pipe.client.idle_timeout(),
9270+
Some(time::Duration::from_millis(234000))
9271+
);
9272+
assert_eq!(
9273+
pipe.server.idle_timeout(),
9274+
Some(time::Duration::from_millis(234000))
9275+
);
9276+
}
9277+
92319278
#[test]
92329279
fn handshake() {
92339280
let mut pipe = testing::Pipe::new().unwrap();

0 commit comments

Comments
 (0)