#define ARRAY_LEN(x) (sizeof(x)/sizeof((x)[0]))
enum {
- H3_STREAM_TYPE_CTRL_SEND,
- H3_STREAM_TYPE_QPACK_ENC_SEND,
- H3_STREAM_TYPE_QPACK_DEC_SEND,
- H3_STREAM_TYPE_REQ,
+ OSSL_DEMO_H3_STREAM_TYPE_CTRL_SEND,
+ OSSL_DEMO_H3_STREAM_TYPE_QPACK_ENC_SEND,
+ OSSL_DEMO_H3_STREAM_TYPE_QPACK_DEC_SEND,
+ OSSL_DEMO_H3_STREAM_TYPE_REQ,
};
#define BUF_SIZE 4096
-struct h3_stream_st {
+struct ossl_demo_h3_stream_st {
uint64_t id; /* QUIC stream ID */
SSL *s; /* QUIC stream SSL object */
int done_recv_fin; /* Received FIN */
size_t buf_cur, buf_total;
};
-DEFINE_LHASH_OF_EX(H3_STREAM);
+DEFINE_LHASH_OF_EX(OSSL_DEMO_H3_STREAM);
-static void h3_stream_free(H3_STREAM *s)
+static void h3_stream_free(OSSL_DEMO_H3_STREAM *s)
{
if (s == NULL)
return;
OPENSSL_free(s);
}
-static unsigned long h3_stream_hash(const H3_STREAM *s)
+static unsigned long h3_stream_hash(const OSSL_DEMO_H3_STREAM *s)
{
return (unsigned long)s->id;
}
-static int h3_stream_eq(const H3_STREAM *a, const H3_STREAM *b)
+static int h3_stream_eq(const OSSL_DEMO_H3_STREAM *a, const OSSL_DEMO_H3_STREAM *b)
{
if (a->id < b->id) return -1;
if (a->id > b->id) return 1;
return 0;
}
-void *H3_STREAM_get_user_data(const H3_STREAM *s)
+void *OSSL_DEMO_H3_STREAM_get_user_data(const OSSL_DEMO_H3_STREAM *s)
{
return s->user_data;
}
-struct h3_conn_st {
- SSL *qconn; /* QUIC connection SSL object */
- BIO *qconn_bio; /* BIO wrapping QCSO */
- nghttp3_conn *h3conn; /* HTTP/3 connection object */
- LHASH_OF(H3_STREAM) *streams; /* map of stream IDs to H3_STREAMs */
- void *user_data; /* opaque user data pointer */
-
- int pump_res;
- size_t consumed_app_data;
+struct ossl_demo_h3_conn_st {
+ /* QUIC connection SSL object */
+ SSL *qconn;
+ /* BIO wrapping QCSO */
+ BIO *qconn_bio;
+ /* HTTP/3 connection object */
+ nghttp3_conn *h3conn;
+ /* map of stream IDs to OSSL_DEMO_H3_STREAMs */
+ LHASH_OF(OSSL_DEMO_H3_STREAM) *streams;
+ /* opaque user data pointer */
+ void *user_data;
+
+ int pump_res;
+ size_t consumed_app_data;
/* Forwarding callbacks */
- nghttp3_recv_data recv_data_cb;
- nghttp3_stream_close stream_close_cb;
- nghttp3_stop_sending stop_sending_cb;
- nghttp3_reset_stream reset_stream_cb;
- nghttp3_deferred_consume deferred_consume_cb;
+ nghttp3_recv_data recv_data_cb;
+ nghttp3_stream_close stream_close_cb;
+ nghttp3_stop_sending stop_sending_cb;
+ nghttp3_reset_stream reset_stream_cb;
+ nghttp3_deferred_consume deferred_consume_cb;
};
-void H3_CONN_free(H3_CONN *conn)
+void OSSL_DEMO_H3_CONN_free(OSSL_DEMO_H3_CONN *conn)
{
if (conn == NULL)
return;
- lh_H3_STREAM_doall(conn->streams, h3_stream_free);
+ lh_OSSL_DEMO_H3_STREAM_doall(conn->streams, h3_stream_free);
nghttp3_conn_del(conn->h3conn);
BIO_free_all(conn->qconn_bio);
- lh_H3_STREAM_free(conn->streams);
+ lh_OSSL_DEMO_H3_STREAM_free(conn->streams);
OPENSSL_free(conn);
}
-static H3_STREAM *h3_conn_create_stream(H3_CONN *conn, int type)
+static OSSL_DEMO_H3_STREAM *h3_conn_create_stream(OSSL_DEMO_H3_CONN *conn, int type)
{
- H3_STREAM *s;
+ OSSL_DEMO_H3_STREAM *s;
uint64_t flags = SSL_STREAM_FLAG_ADVANCE;
- if ((s = OPENSSL_zalloc(sizeof(H3_STREAM))) == NULL)
+ if ((s = OPENSSL_zalloc(sizeof(OSSL_DEMO_H3_STREAM))) == NULL)
return NULL;
- if (type != H3_STREAM_TYPE_REQ)
+ if (type != OSSL_DEMO_H3_STREAM_TYPE_REQ)
flags |= SSL_STREAM_FLAG_UNI;
if ((s->s = SSL_new_stream(conn->qconn, flags)) == NULL) {
}
s->id = SSL_get_stream_id(s->s);
- lh_H3_STREAM_insert(conn->streams, s);
+ lh_OSSL_DEMO_H3_STREAM_insert(conn->streams, s);
return s;
err:
return NULL;
}
-static H3_STREAM *h3_conn_accept_stream(H3_CONN *conn, SSL *qstream)
+static OSSL_DEMO_H3_STREAM *h3_conn_accept_stream(OSSL_DEMO_H3_CONN *conn, SSL *qstream)
{
- H3_STREAM *s;
+ OSSL_DEMO_H3_STREAM *s;
- if ((s = OPENSSL_zalloc(sizeof(H3_STREAM))) == NULL)
+ if ((s = OPENSSL_zalloc(sizeof(OSSL_DEMO_H3_STREAM))) == NULL)
return NULL;
s->id = SSL_get_stream_id(qstream);
s->s = qstream;
- lh_H3_STREAM_insert(conn->streams, s);
+ lh_OSSL_DEMO_H3_STREAM_insert(conn->streams, s);
return s;
}
-static void h3_conn_remove_stream(H3_CONN *conn, H3_STREAM *s)
+static void h3_conn_remove_stream(OSSL_DEMO_H3_CONN *conn, OSSL_DEMO_H3_STREAM *s)
{
if (s == NULL)
return;
- lh_H3_STREAM_delete(conn->streams, s);
+ lh_OSSL_DEMO_H3_STREAM_delete(conn->streams, s);
h3_stream_free(s);
}
const uint8_t *data, size_t datalen,
void *conn_user_data, void *stream_user_data)
{
- H3_CONN *conn = conn_user_data;
+ OSSL_DEMO_H3_CONN *conn = conn_user_data;
conn->consumed_app_data += datalen;
if (conn->recv_data_cb == NULL)
void *conn_user_data, void *stream_user_data)
{
int ret = 0;
- H3_CONN *conn = conn_user_data;
- H3_STREAM *stream = stream_user_data;
+ OSSL_DEMO_H3_CONN *conn = conn_user_data;
+ OSSL_DEMO_H3_STREAM *stream = stream_user_data;
if (conn->stream_close_cb != NULL)
ret = conn->stream_close_cb(h3conn, stream_id, app_error_code,
void *conn_user_data, void *stream_user_data)
{
int ret = 0;
- H3_CONN *conn = conn_user_data;
- H3_STREAM *stream = stream_user_data;
+ OSSL_DEMO_H3_CONN *conn = conn_user_data;
+ OSSL_DEMO_H3_STREAM *stream = stream_user_data;
if (conn->stop_sending_cb != NULL)
ret = conn->stop_sending_cb(h3conn, stream_id, app_error_code,
void *conn_user_data, void *stream_user_data)
{
int ret = 0;
- H3_CONN *conn = conn_user_data;
- H3_STREAM *stream = stream_user_data;
+ OSSL_DEMO_H3_CONN *conn = conn_user_data;
+ OSSL_DEMO_H3_STREAM *stream = stream_user_data;
SSL_STREAM_RESET_ARGS args = {0};
if (conn->reset_stream_cb != NULL)
void *conn_user_data, void *stream_user_data)
{
int ret = 0;
- H3_CONN *conn = conn_user_data;
+ OSSL_DEMO_H3_CONN *conn = conn_user_data;
if (conn->deferred_consume_cb != NULL)
ret = conn->deferred_consume_cb(h3conn, stream_id, consumed,
return ret;
}
-H3_CONN *H3_CONN_new_for_conn(BIO *qconn_bio,
- const nghttp3_callbacks *callbacks,
- const nghttp3_settings *settings,
- void *user_data)
+OSSL_DEMO_H3_CONN *OSSL_DEMO_H3_CONN_new_for_conn(BIO *qconn_bio,
+ const nghttp3_callbacks *callbacks,
+ const nghttp3_settings *settings,
+ void *user_data)
{
int ec;
- H3_CONN *conn;
- H3_STREAM *s_ctl_send = NULL, *s_qpenc_send = NULL, *s_qpdec_send = NULL;
+ OSSL_DEMO_H3_CONN *conn;
+ OSSL_DEMO_H3_STREAM *s_ctl_send = NULL;
+ OSSL_DEMO_H3_STREAM *s_qpenc_send = NULL;
+ OSSL_DEMO_H3_STREAM *s_qpdec_send = NULL;
nghttp3_settings dsettings = {0};
nghttp3_callbacks intl_callbacks = {0};
static const unsigned char alpn[] = {2, 'h', '3'};
return NULL;
}
- if ((conn = OPENSSL_zalloc(sizeof(H3_CONN))) == NULL)
+ if ((conn = OPENSSL_zalloc(sizeof(OSSL_DEMO_H3_CONN))) == NULL)
return NULL;
conn->qconn_bio = qconn_bio;
goto err;
}
- /* Create the map of stream IDs to H3_STREAM structures. */
- if ((conn->streams = lh_H3_STREAM_new(h3_stream_hash, h3_stream_eq)) == NULL)
+ /* Create the map of stream IDs to OSSL_DEMO_H3_STREAM structures. */
+ if ((conn->streams = lh_OSSL_DEMO_H3_STREAM_new(h3_stream_hash, h3_stream_eq)) == NULL)
goto err;
/*
* side, which we handle subsequently as they come in (see SSL_accept_stream
* in the event handling code below).
*/
- if ((s_ctl_send = h3_conn_create_stream(conn, H3_STREAM_TYPE_CTRL_SEND)) == NULL)
+ if ((s_ctl_send
+ = h3_conn_create_stream(conn, OSSL_DEMO_H3_STREAM_TYPE_CTRL_SEND)) == NULL)
goto err;
- if ((s_qpenc_send = h3_conn_create_stream(conn, H3_STREAM_TYPE_QPACK_ENC_SEND)) == NULL)
+ if ((s_qpenc_send
+ = h3_conn_create_stream(conn, OSSL_DEMO_H3_STREAM_TYPE_QPACK_ENC_SEND)) == NULL)
goto err;
- if ((s_qpdec_send = h3_conn_create_stream(conn, H3_STREAM_TYPE_QPACK_DEC_SEND)) == NULL)
+ if ((s_qpdec_send
+ = h3_conn_create_stream(conn, OSSL_DEMO_H3_STREAM_TYPE_QPACK_DEC_SEND)) == NULL)
goto err;
if (settings == NULL) {
h3_stream_free(s_ctl_send);
h3_stream_free(s_qpenc_send);
h3_stream_free(s_qpdec_send);
- lh_H3_STREAM_free(conn->streams);
+ lh_OSSL_DEMO_H3_STREAM_free(conn->streams);
OPENSSL_free(conn);
return NULL;
}
-H3_CONN *H3_CONN_new_for_addr(SSL_CTX *ctx, const char *addr,
- const nghttp3_callbacks *callbacks,
- const nghttp3_settings *settings,
- void *user_data)
+OSSL_DEMO_H3_CONN *OSSL_DEMO_H3_CONN_new_for_addr(SSL_CTX *ctx, const char *addr,
+ const nghttp3_callbacks *callbacks,
+ const nghttp3_settings *settings,
+ void *user_data)
{
BIO *qconn_bio = NULL;
SSL *qconn = NULL;
- H3_CONN *conn = NULL;
+ OSSL_DEMO_H3_CONN *conn = NULL;
const char *bare_hostname;
/* QUIC connection setup */
if (SSL_set1_host(qconn, bare_hostname) <= 0)
goto err;
- conn = H3_CONN_new_for_conn(qconn_bio, callbacks, settings, user_data);
+ conn = OSSL_DEMO_H3_CONN_new_for_conn(qconn_bio, callbacks,
+ settings, user_data);
if (conn == NULL)
goto err;
return NULL;
}
-int H3_CONN_connect(H3_CONN *conn)
+int OSSL_DEMO_H3_CONN_connect(OSSL_DEMO_H3_CONN *conn)
{
- return SSL_connect(H3_CONN_get0_connection(conn));
+ return SSL_connect(OSSL_DEMO_H3_CONN_get0_connection(conn));
}
-void *H3_CONN_get_user_data(const H3_CONN *conn)
+void *OSSL_DEMO_H3_CONN_get_user_data(const OSSL_DEMO_H3_CONN *conn)
{
return conn->user_data;
}
-SSL *H3_CONN_get0_connection(const H3_CONN *conn)
+SSL *OSSL_DEMO_H3_CONN_get0_connection(const OSSL_DEMO_H3_CONN *conn)
{
return conn->qconn;
}
/* Pumps received data to the HTTP/3 stack for a single stream. */
-static void h3_conn_pump_stream(H3_STREAM *s, void *conn_)
+static void h3_conn_pump_stream(OSSL_DEMO_H3_STREAM *s, void *conn_)
{
int ec;
- H3_CONN *conn = conn_;
+ OSSL_DEMO_H3_CONN *conn = conn_;
size_t num_bytes, consumed;
uint64_t aec;
conn->pump_res = 0;
}
-int H3_CONN_handle_events(H3_CONN *conn)
+int OSSL_DEMO_H3_CONN_handle_events(OSSL_DEMO_H3_CONN *conn)
{
int ec, fin;
size_t i, num_vecs, written, total_written, total_len;
int64_t stream_id;
nghttp3_vec vecs[8] = {0};
- H3_STREAM key, *s;
+ OSSL_DEMO_H3_STREAM key, *s;
SSL *snew;
if (conn == NULL)
break;
/*
- * Each new incoming stream gets wrapped into an H3_STREAM object and
+ * Each new incoming stream gets wrapped into an OSSL_DEMO_H3_STREAM object and
* added into our stream ID map.
*/
if (h3_conn_accept_stream(conn, snew) == NULL) {
/* For each of the vectors returned, pass it to OpenSSL QUIC. */
key.id = stream_id;
- if ((s = lh_H3_STREAM_retrieve(conn->streams, &key)) == NULL) {
+ if ((s = lh_OSSL_DEMO_H3_STREAM_retrieve(conn->streams, &key)) == NULL) {
ERR_raise_data(ERR_LIB_USER, ERR_R_INTERNAL_ERROR,
"no stream for ID %zd", stream_id);
return 0;
/* 3. Pump incoming data from QUIC to HTTP/3 engine. */
conn->pump_res = 1; /* cleared in below call if an error occurs */
- lh_H3_STREAM_doall_arg(conn->streams, h3_conn_pump_stream, conn);
+ lh_OSSL_DEMO_H3_STREAM_doall_arg(conn->streams, h3_conn_pump_stream, conn);
if (!conn->pump_res)
return 0;
return 1;
}
-int H3_CONN_submit_request(H3_CONN *conn, const nghttp3_nv *nva, size_t nvlen,
- const nghttp3_data_reader *dr,
- void *user_data)
+int OSSL_DEMO_H3_CONN_submit_request(OSSL_DEMO_H3_CONN *conn,
+ const nghttp3_nv *nva, size_t nvlen,
+ const nghttp3_data_reader *dr,
+ void *user_data)
{
int ec;
- H3_STREAM *s_req = NULL;
+ OSSL_DEMO_H3_STREAM *s_req = NULL;
if (conn == NULL) {
ERR_raise_data(ERR_LIB_USER, ERR_R_PASSED_NULL_PARAMETER,
}
/* Each HTTP/3 request is represented by a stream. */
- if ((s_req = h3_conn_create_stream(conn, H3_STREAM_TYPE_REQ)) == NULL)
+ if ((s_req = h3_conn_create_stream(conn, OSSL_DEMO_H3_STREAM_TYPE_REQ)) == NULL)
goto err;
s_req->user_data = user_data;
*/
/* Represents an HTTP/3 connection to a server. */
-typedef struct h3_conn_st H3_CONN;
+typedef struct ossl_demo_h3_conn_st OSSL_DEMO_H3_CONN;
/* Represents an HTTP/3 request, control or QPACK stream. */
-typedef struct h3_stream_st H3_STREAM;
+typedef struct ossl_demo_h3_stream_st OSSL_DEMO_H3_STREAM;
/*
* Creates a HTTP/3 connection using the given QUIC client connection BIO. The
* this QUIC binding are ignored.
*
* user_data is an application-provided opaque value which can be retrieved
- * using H3_CONN_get_user_data. Note that the user data value passed to the
- * callback functions specified in callbacks is a pointer to the H3_CONN, not
- * user_data.
+ * using OSSL_DEMO_H3_CONN_get_user_data. Note that the user data value passed
+ * to the callback functions specified in callbacks is a pointer to the
+ * OSSL_DEMO_H3_CONN, not user_data.
*
* Returns NULL on failure.
*/
-H3_CONN *H3_CONN_new_for_conn(BIO *qconn_bio,
- const nghttp3_callbacks *callbacks,
- const nghttp3_settings *settings,
- void *user_data);
+OSSL_DEMO_H3_CONN *OSSL_DEMO_H3_CONN_new_for_conn(BIO *qconn_bio,
+ const nghttp3_callbacks *callbacks,
+ const nghttp3_settings *settings,
+ void *user_data);
/*
- * Works identically to H3_CONN_new_for_conn except that it manages the creation
- * of a QUIC connection SSL object automatically using an address string. addr
- * should be a string such as "www.example.com:443". The created underlying QUIC
- * connection SSL object is owned by the H3_CONN and can be subsequently
- * retrieved using H3_CONN_get0_connection.
+ * Works identically to OSSL_DEMO_H3_CONN_new_for_conn except that it manages
+ * the creation of a QUIC connection SSL object automatically using an address
+ * string. addr should be a string such as "www.example.com:443". The created
+ * underlying QUIC connection SSL object is owned by the OSSL_DEMO_H3_CONN and
+ * can be subsequently retrieved using OSSL_DEMO_H3_CONN_get0_connection.
*
* Returns NULL on failure. ctx must be a SSL_CTX using a QUIC client
* SSL_METHOD.
*/
-H3_CONN *H3_CONN_new_for_addr(SSL_CTX *ctx, const char *addr,
- const nghttp3_callbacks *callbacks,
- const nghttp3_settings *settings,
- void *user_data);
+OSSL_DEMO_H3_CONN *OSSL_DEMO_H3_CONN_new_for_addr(SSL_CTX *ctx,
+ const char *addr,
+ const nghttp3_callbacks *callbacks,
+ const nghttp3_settings *settings,
+ void *user_data);
-/* Equivalent to SSL_connect(H3_CONN_get0_connection(conn)). */
-int H3_CONN_connect(H3_CONN *conn);
+/* Equivalent to SSL_connect(OSSL_DEMO_H3_CONN_get0_connection(conn)). */
+int OSSL_DEMO_H3_CONN_connect(OSSL_DEMO_H3_CONN *conn);
/*
- * Free the H3_CONN and any underlying QUIC connection SSL object and associated
- * streams.
+ * Free the OSSL_DEMO_H3_CONN and any underlying QUIC connection SSL object and
+ * associated streams.
*/
-void H3_CONN_free(H3_CONN *conn);
+void OSSL_DEMO_H3_CONN_free(OSSL_DEMO_H3_CONN *conn);
-/* Returns the user data value which was specified in H3_CONN_new_for_conn. */
-void *H3_CONN_get_user_data(const H3_CONN *conn);
+/*
+ * Returns the user data value which was specified in
+ * OSSL_DEMO_H3_CONN_new_for_conn.
+ */
+void *OSSL_DEMO_H3_CONN_get_user_data(const OSSL_DEMO_H3_CONN *conn);
/* Returns the underlying QUIC connection SSL object. */
-SSL *H3_CONN_get0_connection(const H3_CONN *conn);
+SSL *OSSL_DEMO_H3_CONN_get0_connection(const OSSL_DEMO_H3_CONN *conn);
/*
* Handle any pending events on a given HTTP/3 connection. Returns 0 on error.
*/
-int H3_CONN_handle_events(H3_CONN *conn);
+int OSSL_DEMO_H3_CONN_handle_events(OSSL_DEMO_H3_CONN *conn);
/*
* Submits a new HTTP/3 request on the given connection. Returns 0 on error.
*
* This works analogously to nghttp3_conn_submit_request(). The stream user data
- * pointer passed to the callbacks is a H3_STREAM object pointer; to retrieve
- * the stream user data pointer passed to this function, use
- * H3_STREAM_get_user_data.
+ * pointer passed to the callbacks is a OSSL_DEMO_H3_STREAM object pointer; to
+ * retrieve the stream user data pointer passed to this function, use
+ * OSSL_DEMO_H3_STREAM_get_user_data.
*/
-int H3_CONN_submit_request(H3_CONN *conn,
+int OSSL_DEMO_H3_CONN_submit_request(OSSL_DEMO_H3_CONN *conn,
const nghttp3_nv *hdr, size_t hdrlen,
const nghttp3_data_reader *dr,
void *stream_user_data);
-/* Returns the user data value which was specified in H3_CONN_submit_request. */
-void *H3_STREAM_get_user_data(const H3_STREAM *stream);
+/*
+ * Returns the user data value which was specified in
+ * OSSL_DEMO_H3_CONN_submit_request.
+ */
+void *OSSL_DEMO_H3_STREAM_get_user_data(const OSSL_DEMO_H3_STREAM *stream);
#endif