h3ssl
h3ssl->fileprefix = prior_fileprefix;
static void reuse_h3ssl(struct h3ssl *h3ssl)
struct h3ssl h3ssl;
h3ssl->end_headers_received = 0;
h3ssl->datadone = 0;
h3ssl->close_done = 0;
h3ssl->close_wait = 0;
init_ids(&h3ssl);
h3ssl.fileprefix = fileprefix;
add_ids_listener(listener, &h3ssl);
h3ssl->done = 0;
memset(h3ssl->url, '\0', sizeof(h3ssl->url));
while (!h3ssl.end_headers_received) {
if (h3ssl->ptr_data != NULL && h3ssl->ptr_data != nulldata)
handle_events_from_ids(&h3ssl);
hassomething = read_from_ssl_ids(&h3conn, &h3ssl);
free(h3ssl->ptr_data);
if (h3ssl.close_done) {
h3ssl->ptr_data = NULL;
h3ssl.restart = 0;
if (h3ssl.close_done) {
if (!h3ssl.has_uni) {
h3ssl->offset_data = 0;
if (quic_server_h3streams(h3conn, &h3ssl) == -1) {
h3ssl.has_uni = 1;
h3ssl->ldata = 0;
h3ssl.ldata = get_file_length(&h3ssl);
if (h3ssl.ldata == 0) {
h3ssl.ptr_data = nulldata;
h3ssl.ldata = nulldata_sz;
sprintf(slength, "%zu", h3ssl.ldata);
} else if (h3ssl.ldata == INT_MAX) {
sprintf(slength, "%zu", h3ssl.ldata);
h3ssl.ptr_data = (uint8_t *)malloc(4096);
memset(h3ssl.ptr_data, 'A', 4096);
sprintf(slength, "%zu", h3ssl.ldata);
h3ssl.ptr_data = (uint8_t *)get_file_data(&h3ssl);
if (h3ssl.ptr_data == NULL)
(unsigned long long)h3ssl.id_bidi, h3ssl.url);
if (strstr(h3ssl.url, ".png"))
else if (strstr(h3ssl.url, ".ico"))
else if (strstr(h3ssl.url, ".htm"))
static void add_id_status(uint64_t id, SSL *ssl, struct h3ssl *h3ssl, int status)
if (nghttp3_conn_submit_response(h3conn, h3ssl.id_bidi, resp, num_nv, &dr)) {
printf("nghttp3_conn_submit_response on %llu...\n", (unsigned long long)h3ssl.id_bidi);
if (!h3ssl.datadone)
if (!quic_server_write(&h3ssl, streamid, vec[i].base,
ssl_ids = h3ssl->ssl_ids;
if (h3ssl.datadone) {
if (!h3ssl.close_done) {
set_id_status(h3ssl.id_bidi, SERVERCLOSED, &h3ssl);
h3ssl.close_wait = 1;
SSL *newssl = get_ids_connection(&h3ssl);
printf("hasnothing nothing WAIT %d!!!\n", h3ssl.close_done);
handle_events_from_ids(&h3ssl);
hasnothing = read_from_ssl_ids(&h3conn, &h3ssl);
if (h3ssl.done) {
if (h3ssl.new_conn) {
h3ssl.new_conn = 0;
if (h3ssl.restart) {
h3ssl.restart = 0;
if (are_all_clientid_closed(&h3ssl)) {
close_all_ids(&h3ssl);
ssl = get_ids_connection(&h3ssl);
replace_ids_connection(&h3ssl, ssl, NULL);
static void add_id(uint64_t id, SSL *ssl, struct h3ssl *h3ssl)
add_id_status(id, ssl, h3ssl, 0);
static void add_ids_listener(SSL *ssl, struct h3ssl *h3ssl)
add_id_status(UINT64_MAX, ssl, h3ssl, ISLISTENER);
static void add_ids_connection(struct h3ssl *h3ssl, SSL *ssl)
add_id_status(UINT64_MAX, ssl, h3ssl, ISCONNECTION);
static SSL *get_ids_connection(struct h3ssl *h3ssl)
ssl_ids = h3ssl->ssl_ids;
static void replace_ids_connection(struct h3ssl *h3ssl, SSL *oldstream, SSL *newstream)
ssl_ids = h3ssl->ssl_ids;
static void remove_marked_ids(struct h3ssl *h3ssl)
ssl_ids = h3ssl->ssl_ids;
static void set_id_status(uint64_t id, int status, struct h3ssl *h3ssl)
ssl_ids = h3ssl->ssl_ids;
static int get_id_status(uint64_t id, struct h3ssl *h3ssl)
ssl_ids = h3ssl->ssl_ids;
static int are_all_clientid_closed(struct h3ssl *h3ssl)
ssl_ids = h3ssl->ssl_ids;
static void close_all_ids(struct h3ssl *h3ssl)
ssl_ids = h3ssl->ssl_ids;
struct h3ssl *h3ssl = (struct h3ssl *)user_data;
memset(h3ssl->url, 0, sizeof(h3ssl->url));
strncpy(h3ssl->url, "index.html", MAXURL);
memcpy(h3ssl->url, vvalue.base + 1, len - 1);
h3ssl->url[len - 1] = '\0';
memcpy(h3ssl->url, vvalue.base, len);
struct h3ssl *h3ssl = (struct h3ssl *)user_data;
h3ssl->end_headers_received = 1;
struct h3ssl *h3ssl = (struct h3ssl *)conn_user_data;
h3ssl->done = 1;
static int quic_server_read(nghttp3_conn *h3conn, SSL *stream, uint64_t id, struct h3ssl *h3ssl)
if (!h3ssl->received_from_two && id != 2) {
h3ssl->received_from_two = 1;
static int quic_server_h3streams(nghttp3_conn *h3conn, struct h3ssl *h3ssl)
conn = get_ids_connection(h3ssl);
add_id(SSL_get_stream_id(rstream), rstream, h3ssl);
add_id(SSL_get_stream_id(pstream), pstream, h3ssl);
add_id(SSL_get_stream_id(cstream), cstream, h3ssl);
static int read_from_ssl_ids(nghttp3_conn **curh3conn, struct h3ssl *h3ssl)
struct ssl_id *ssl_ids = h3ssl->ssl_ids;
h3ssl->new_conn = 0;
h3ssl->restart = 0;
h3ssl->done = 0;
oldconn = get_ids_connection(h3ssl);
replace_ids_connection(h3ssl, oldconn, conn);
reuse_h3ssl(h3ssl);
close_all_ids(h3ssl);
h3ssl->id_bidi = UINT64_MAX;
h3ssl->has_uni = 0;
add_ids_connection(h3ssl, conn);
h3ssl->new_conn = 1;
h3ssl)) {
add_id(new_id, stream, h3ssl);
if (h3ssl->close_wait) {
reuse_h3ssl(h3ssl);
h3ssl->restart = 1; /* Checked in wait_close loop */
if (h3ssl->id_bidi != UINT64_MAX) {
set_id_status(h3ssl->id_bidi, TOBEREMOVED, h3ssl);
h3ssl->id_bidi = new_id;
reuse_h3ssl(h3ssl);
h3ssl->restart = 1;
set_id_status(new_id, CLIENTUNIOPEN, h3ssl);
r = quic_server_read(h3conn, stream, new_id, h3ssl);
if (!h3ssl->has_uni) {
ret = quic_server_h3streams(h3conn, h3ssl);
h3ssl->has_uni = 1;
printf("Connection terminating restart %d\n", h3ssl->restart);
if (!h3ssl->close_done) {
h3ssl->close_done = 1;
h3ssl->done = 1;
h3ssl->done = 1;
r = quic_server_read(h3conn, s, id, h3ssl);
set_id_status(id, TOBEREMOVED, h3ssl);
status = get_id_status(id, h3ssl);
set_id_status(id, CLIENTCLOSED, h3ssl);
status = get_id_status(id, h3ssl);
set_id_status(id, TOBEREMOVED, h3ssl);
remove_marked_ids(h3ssl);
static void handle_events_from_ids(struct h3ssl *h3ssl)
struct ssl_id *ssl_ids = h3ssl->ssl_ids;
ssl_ids = h3ssl->ssl_ids;
static size_t get_file_length(struct h3ssl *h3ssl)
if (h3ssl->fileprefix != NULL)
strcat(filename, h3ssl->fileprefix);
strcat(filename, h3ssl->url);
if (strcmp(h3ssl->url, "big") == 0) {
static char *get_file_data(struct h3ssl *h3ssl)
size_t size = get_file_length(h3ssl);
if (h3ssl->fileprefix != NULL)
strcat(filename, h3ssl->fileprefix);
strcat(filename, h3ssl->url);
struct h3ssl *h3ssl = (struct h3ssl *)user_data;
if (h3ssl->datadone) {
printf("step_read_data for %s %zu\n", h3ssl->url, h3ssl->ldata);
if (h3ssl->ldata <= 4096) {
vec[0].base = &(h3ssl->ptr_data[h3ssl->offset_data]);
vec[0].len = h3ssl->ldata;
h3ssl->datadone++;
vec[0].base = &(h3ssl->ptr_data[h3ssl->offset_data]);
if (h3ssl->ldata == INT_MAX) {
static void init_ids(struct h3ssl *h3ssl)
h3ssl->offset_data = h3ssl->offset_data + 4096;
h3ssl->ldata = h3ssl->ldata - 4096;
static int quic_server_write(struct h3ssl *h3ssl, uint64_t streamid,
ssl_ids = h3ssl->ssl_ids;
char *prior_fileprefix = h3ssl->fileprefix;
if (h3ssl->ptr_data != NULL && h3ssl->ptr_data != nulldata)
free(h3ssl->ptr_data);
memset(h3ssl, 0, sizeof(struct h3ssl));
ssl_ids = h3ssl->ssl_ids;
h3ssl->id_bidi = UINT64_MAX;