Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
ex_network_alpn.c File Reference
#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>
Include dependency graph for ex_network_alpn.c:

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

Data Structure Documentation

◆ CA_CTX

struct CA_CTX

CA used by the server to mint per-host leaves.

Examples
ex_network_alpn.c, and ex_network_sni.c.

Definition at line 61 of file ex_network_alpn.c.

Collaboration diagram for CA_CTX:
Data Fields
N_STR * cert the CA certificate PEM
N_STR * key the CA private key PEM

◆ SRV

struct SRV

server worker context

Examples
ex_network_alpn.c, ex_network_sni.c, and ex_network_ssl_nonblock.c.

Definition at line 67 of file ex_network_alpn.c.

Collaboration diagram for SRV:
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

Macro Definition Documentation

◆ ALPN_HOST

#define ALPN_HOST   "alpn.host.example"

the host name the client requests via SNI

Examples
ex_network_alpn.c.

Definition at line 52 of file ex_network_alpn.c.

Referenced by client_connect(), and h2_client_get().

◆ H2_REPLY

#define H2_REPLY   "served-over-h2"

the body the HTTP/2 handler answers with

Examples
ex_network_alpn.c.

Definition at line 56 of file ex_network_alpn.c.

Referenced by h2_on_request(), and main().

◆ ROUNDS

#define ROUNDS   3

how many connections the server accepts before it stops

Examples
ex_network_alpn.c.

Definition at line 54 of file ex_network_alpn.c.

Referenced by main(), and server_fn().

Function Documentation

◆ bind_free()

NETWORK * bind_free ( char * port_out,
size_t port_out_len )
static
Examples
ex_network_alpn.c, ex_network_sni.c, and ex_network_ssl_nonblock.c.

Definition at line 295 of file ex_network_alpn.c.

References netw_close(), netw_make_listening(), and NETWORK_IPALL.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ client_connect()

NETWORK * client_connect ( const char * port,
const char *const * protos,
size_t count,
char * got,
size_t got_len )
static
Examples
ex_network_alpn.c.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ h2_client_get()

int h2_client_get ( NETWORK * c,
const char * path,
int * status,
char * body,
size_t body_cap )
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

Examples
ex_network_alpn.c.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ h2_on_request()

int h2_on_request ( void * ud,
N_H2_SERVER * srv,
const N_H2_REQUEST * req )
static
Examples
ex_network_alpn.c.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

◆ pick_cb()

int pick_cb ( const char * sni,
N_STR ** cert_pem,
N_STR ** key_pem,
void * user_data )
static
Examples
ex_network_alpn.c, and ex_network_sni.c.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_args()

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().

Here is the call graph for this function:

◆ server_fn()

◆ tls_read()

ssize_t tls_read ( void * io,
void * buf,
size_t len )
static
Examples
ex_network_alpn.c.

Definition at line 115 of file ex_network_alpn.c.

References NETWORK::ssl.

Referenced by h2_client_get(), and server_fn().

Here is the caller graph for this function:

◆ tls_write()

ssize_t tls_write ( void * io,
const void * buf,
size_t len )
static
Examples
ex_network_alpn.c.

Definition at line 121 of file ex_network_alpn.c.

References NETWORK::ssl.

Referenced by h2_client_get(), main(), and server_fn().

Here is the caller graph for this function:

Variable Documentation

◆ failures

int failures = 0
static

Definition at line 58 of file ex_network_alpn.c.