diff options
author | 2021-05-04 23:20:19 +0200 | |
---|---|---|
committer | 2021-05-06 12:09:31 +0100 | |
commit | 0a08fd78134dc35351ce773f143015ed12f53ae1 (patch) | |
tree | 0ab92c9430c32805e9d126c1b6d9f16b314cda43 | |
parent | 720cd94a0966c0d3ba3818b98ec94e5ea4e5d4d1 (diff) | |
download | quiche-0a08fd78134dc35351ce773f143015ed12f53ae1.tar.gz quiche-0a08fd78134dc35351ce773f143015ed12f53ae1.tar.zst quiche-0a08fd78134dc35351ce773f143015ed12f53ae1.zip |
ffi: expose client-side session resumption and 0-RTT API
Motivation:
Quiche added support for session resumption and 0-RTT lately but the API was not exposed via the C api.
This was done in https://github.com/cloudflare/quiche/pull/911 and https://github.com/cloudflare/quiche/pull/914.
Modifications:
Add C API to also be able to make use of the functionality via C.
Result:
Be able to use session resumption and 0-RTT via the C api
-rw-r--r-- | include/quiche.h | 6 | ||||
-rw-r--r-- | src/ffi.rs | 27 |
2 files changed, 33 insertions, 0 deletions
diff --git a/include/quiche.h b/include/quiche.h index a49f37a1..e8c46b58 100644 --- a/include/quiche.h +++ b/include/quiche.h @@ -256,6 +256,9 @@ bool quiche_conn_set_qlog_path(quiche_conn *conn, const char *path, void quiche_conn_set_qlog_fd(quiche_conn *conn, int fd, const char *log_title, const char *log_desc); +// Configures the given session for resumption. +int quiche_conn_set_session(quiche_conn *conn, const uint8_t *buf, size_t buf_len); + // Processes QUIC packets received from the peer. ssize_t quiche_conn_recv(quiche_conn *conn, uint8_t *buf, size_t buf_len); @@ -321,6 +324,9 @@ void quiche_conn_trace_id(quiche_conn *conn, const uint8_t **out, size_t *out_le void quiche_conn_application_proto(quiche_conn *conn, const uint8_t **out, size_t *out_len); +// Returns the serialized cryptographic session for the connection. +void quiche_conn_session(quiche_conn *conn, const uint8_t **out, size_t *out_len); + // Returns true if the connection handshake is complete. bool quiche_conn_is_established(quiche_conn *conn); @@ -540,6 +540,19 @@ pub extern fn quiche_conn_set_qlog_fd( } #[no_mangle] +pub extern fn quiche_conn_set_session( + conn: &mut Connection, buf: *const u8, buf_len: size_t, +) -> c_int { + let buf = unsafe { slice::from_raw_parts(buf, buf_len) }; + + match conn.set_session(buf) { + Ok(_) => 0, + + Err(e) => e.to_c() as c_int, + } +} + +#[no_mangle] pub extern fn quiche_conn_recv( conn: &mut Connection, buf: *mut u8, buf_len: size_t, ) -> ssize_t { @@ -764,6 +777,20 @@ pub extern fn quiche_conn_application_proto( } #[no_mangle] +pub extern fn quiche_conn_session( + conn: &mut Connection, out: &mut *const u8, out_len: &mut size_t, +) { + match conn.session() { + Some(session) => { + *out = session.as_ptr(); + *out_len = session.len(); + }, + + None => *out_len = 0, + } +} + +#[no_mangle] pub extern fn quiche_conn_is_established(conn: &mut Connection) -> bool { conn.is_established() } |