![]() |
Nilorea Library
C utilities for networking, threading, graphics
|
#include "nilorea/n_common.h"#include "nilorea/n_http2_server.h"#include "nilorea/n_log.h"#include "nilorea/n_network.h"#include "nilorea/n_str.h"#include "nilorea/n_x509.h"#include <getopt.h>#include <pthread.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <openssl/ssl.h>Go to the source code of this file.
Data Structures | |
| struct | CA_CTX |
| CA used by the server to mint per-host leaves. More... | |
| struct | SRV |
| server worker context More... | |
Macros | |
| #define | ALPN_HOST "alpn.host.example" |
| the host name the client requests via SNI | |
| #define | H2_REPLY "served-over-h2" |
| the body the HTTP/2 handler answers with | |
| #define | ROUNDS 3 |
| how many connections the server accepts before it stops | |
Functions | |
| static NETWORK * | bind_free (char *port_out, size_t port_out_len) |
| static NETWORK * | client_connect (const char *port, const char *const *protos, size_t count, char *got, size_t got_len) |
| static int | h2_client_get (NETWORK *c, const char *path, int *status, char *body, size_t body_cap) |
| static int | h2_on_request (void *ud, N_H2_SERVER *srv, const N_H2_REQUEST *req) |
| int | main (int argc, char **argv) |
| static int | pick_cb (const char *sni, N_STR **cert_pem, N_STR **key_pem, void *user_data) |
| void | process_args (int argc, char **argv) |
| static void * | server_fn (void *p) |
| static ssize_t | tls_read (void *io, void *buf, size_t len) |
| static ssize_t | tls_write (void *io, const void *buf, size_t len) |
Variables | |
| static int | failures = 0 |
| struct CA_CTX |
CA used by the server to mint per-host leaves.
Definition at line 61 of file ex_network_alpn.c.
| Data Fields | ||
|---|---|---|
| N_STR * | cert | the CA certificate PEM |
| N_STR * | key | the CA private key PEM |
| struct SRV |
server worker context
Definition at line 67 of file ex_network_alpn.c.
| Data Fields | ||
|---|---|---|
| CA_CTX * | ca | the CA to mint leaves with |
| SSL_CTX * | ctx | shared server ctx (owned by main) |
| char | h2_path[128] | the :path of the last HTTP/2 request |
| int | h2_requests | requests served over HTTP/2 |
| NETWORK * | listen |
the listening socket listening NETWORK |
| int | ok | set to 1 once the server completed the exchange |
| int | rounds_done | how many connections it served |
| char | selected[3][32] | what ALPN the server answered per round |
| #define ALPN_HOST "alpn.host.example" |
the host name the client requests via SNI
Definition at line 52 of file ex_network_alpn.c.
Referenced by client_connect(), and h2_client_get().
| #define H2_REPLY "served-over-h2" |
the body the HTTP/2 handler answers with
Definition at line 56 of file ex_network_alpn.c.
Referenced by h2_on_request(), and main().
| #define ROUNDS 3 |
how many connections the server accepts before it stops
Definition at line 54 of file ex_network_alpn.c.
Referenced by main(), and server_fn().
|
static |
Definition at line 295 of file ex_network_alpn.c.
References netw_close(), netw_make_listening(), and NETWORK_IPALL.
Referenced by main().
|
static |
Definition at line 276 of file ex_network_alpn.c.
References ALPN_HOST, netw_close(), netw_ssl_connect_client_to(), netw_ssl_do_handshake(), netw_ssl_get_alpn(), netw_ssl_set_alpn(), netw_ssl_set_verify(), NETWORK_IPALL, and port.
Referenced by main().
|
static |
< SETTINGS
< HEADERS
< HEADERS/PUSH_PROMISE/CONTINUATION: header block complete
< DATA/HEADERS: last frame of the stream
< HEADERS
< DATA
< DATA/HEADERS: last frame of the stream
Definition at line 194 of file ex_network_alpn.c.
References ALPN_HOST, done, N_H2_FRAME::flags, N_H2_FRAME::length, N_H2_DATA, N_H2_FLAG_END_HEADERS, N_H2_FLAG_END_STREAM, N_H2_FRAME_HEADER_LEN, N_H2_HEADERS, N_H2_PREFACE, N_H2_SETTINGS, n_http2_frame_build_header(), n_http2_frame_parse(), n_http2_hpack_decode(), n_http2_hpack_encode(), n_http2_hpack_free(), n_http2_hpack_headers_free(), n_http2_hpack_new(), N_H2_HEADER::name, N_H2_FRAME::payload, N_H2_FRAME::stream_id, tls_read(), tls_write(), N_H2_FRAME::type, and N_H2_HEADER::value.
Referenced by main().
|
static |
Definition at line 138 of file ex_network_alpn.c.
References failures, SRV::h2_path, H2_REPLY, SRV::h2_requests, n_http2_server_respond(), N_H2_HEADER::name, N_H2_REQUEST::path, N_H2_REQUEST::stream_id, and N_H2_HEADER::value.
Referenced by server_fn().
| int main | ( | int | argc, |
| char ** | argv ) |
Definition at line 311 of file ex_network_alpn.c.
References bind_free(), SRV::ca, CA_CTX::cert, client_connect(), failures, free_nstr, h2_client_get(), SRV::h2_path, H2_REPLY, SRV::h2_requests, CA_CTX::key, SRV::listen, LOG_ERR, LOG_NOTICE, n_log, n_x509_generate_ca(), netw_close(), netw_init_openssl(), netw_ssl_get_alpn(), netw_ssl_server_handshake_ex(), netw_ssl_set_alpn(), netw_unload_openssl(), pick_cb(), port, process_args(), ROUNDS, SRV::rounds_done, SRV::selected, server_fn(), set_log_level(), NETWORK::ssl, and tls_write().
Definition at line 105 of file ex_network_alpn.c.
References CA_CTX::cert, CA_CTX::key, and n_x509_mint_host_cert().
Referenced by main(), server_fn(), and server_fn().
| void process_args | ( | int | argc, |
| char ** | argv ) |
Definition at line 77 of file ex_network_alpn.c.
References LOG_DEBUG, LOG_ERR, LOG_INFO, LOG_NOTICE, LOG_NULL, and set_log_level().
|
static |
Definition at line 153 of file ex_network_alpn.c.
References _str, SRV::ca, failures, h2_on_request(), SRV::listen, LOG_ERR, n_http2_server_error(), n_http2_server_free(), n_http2_server_handshake(), n_http2_server_new(), n_http2_server_run(), n_log, netw_accept_from(), netw_close(), netw_ssl_get_alpn(), netw_ssl_server_handshake_ex(), pick_cb(), ROUNDS, SRV::rounds_done, SRV::selected, NETWORK::ssl, tls_read(), and tls_write().
Referenced by main().
|
static |
Definition at line 115 of file ex_network_alpn.c.
References NETWORK::ssl.
Referenced by h2_client_get(), and server_fn().
|
static |
Definition at line 121 of file ex_network_alpn.c.
References NETWORK::ssl.
Referenced by h2_client_get(), main(), and server_fn().
|
static |
Definition at line 58 of file ex_network_alpn.c.