9#include "gnunet_signatures.h"
16#include <ngtcp2/ngtcp2.h>
17#include <ngtcp2/ngtcp2_crypto.h>
18#include <ngtcp2/ngtcp2_crypto_gnutls.h>
19#include <nghttp3/nghttp3.h>
20#include <gnutls/crypto.h>
21#include <gnutls/gnutls.h>
28#define COMMUNICATOR_CONFIG_SECTION "communicator-http3"
33#define COMMUNICATOR_ADDRESS_PREFIX "http3"
38#define PRIORITY "NORMAL:-VERS-ALL:+VERS-TLS1.3:" \
39 "-CIPHER-ALL:+AES-128-GCM:+AES-256-GCM:+CHACHA20-POLY1305:+AES-128-CCM:" \
40 "-GROUP-ALL:+GROUP-SECP256R1:+GROUP-X25519:+GROUP-SECP384R1:+GROUP-SECP521R1:" \
41 "%DISABLE_TLS13_COMPAT_MODE"
47#define ADDRESS_VALIDITY_PERIOD GNUNET_TIME_UNIT_HOURS
52#define NUM_LONG_POLL 16
139static gnutls_certificate_credentials_t
cred;
418 clock_gettime (CLOCK_MONOTONIC, &tp);
419 return (uint64_t) tp.tv_sec * NGTCP2_SECONDS + (uint64_t) tp.tv_nsec;
434 socklen_t address_len)
468static struct sockaddr *
477 if (1 == sscanf (bindto,
"%u%1s", &
port,
dummy))
480 if (
port > UINT16_MAX)
483 "BINDTO specification `%s' invalid: value too large for port\n",
489 struct sockaddr_in *i4;
492 i4->sin_family = AF_INET;
493 i4->sin_port = htons ((uint16_t)
port);
494 *sock_len =
sizeof(
struct sockaddr_in);
495 in = (
struct sockaddr *) i4;
499 struct sockaddr_in6 *i6;
502 i6->sin6_family = AF_INET6;
503 i6->sin6_port = htons ((uint16_t)
port);
504 *sock_len =
sizeof(
struct sockaddr_in6);
505 in = (
struct sockaddr *) i6;
510 colon = strrchr (cp,
':');
516 if (1 == sscanf (colon,
"%u%1s", &
port,
dummy))
519 if (
port > UINT16_MAX)
522 "BINDTO specification `%s' invalid: value too large for port\n",
532 "BINDTO specification `%s' invalid: last ':' not followed by number\n",
545 struct sockaddr_in v4;
547 memset (&v4, 0,
sizeof(v4));
548 if (1 == inet_pton (AF_INET, cp, &v4.sin_addr))
550 v4.sin_family = AF_INET;
551 v4.sin_port = htons ((uint16_t)
port);
552#if HAVE_SOCKADDR_IN_SIN_LEN
553 v4.sin_len =
sizeof(
struct sockaddr_in);
556 *sock_len =
sizeof(
struct sockaddr_in);
563 struct sockaddr_in6 v6;
566 memset (&v6, 0,
sizeof(v6));
568 if ((
'[' == *cp) && (
']' == cp[strlen (cp) - 1]))
571 cp[strlen (cp) - 1] =
'\0';
573 if (1 == inet_pton (AF_INET6,
start, &v6.sin6_addr))
575 v6.sin6_family = AF_INET6;
576 v6.sin6_port = htons ((uint16_t)
port);
577#if HAVE_SOCKADDR_IN_SIN_LEN
578 v6.sin6_len =
sizeof(
struct sockaddr_in6);
581 *sock_len =
sizeof(v6);
598 return ((
struct Connection*) (ref->user_data))->conn;
604 const struct sockaddr *addr,
609 "No connection reversal implemented!\n");
651 "send packet failed!\n");
670 struct Stream *new_stream;
674 memset (new_stream, 0,
sizeof (
struct Stream));
707 "can't remove non-exist pair in connection->streams, stream_id = %"PRIi64
"\n",
761 gnutls_datum_t alpn = { (
unsigned char *)
"h3",
sizeof(
"h3") - 1};
774 | GNUTLS_ENABLE_EARLY_DATA
775 | GNUTLS_NO_END_OF_EARLY_DATA);
779 "gnutls_init error: %s\n",
780 gnutls_strerror (rv));
787 "ngtcp2_crypto_gnutls_configure_client_session failed\n");
794 "gnutls_priority_set_direct: %s\n",
795 gnutls_strerror (rv));
804 "gnutls_credentials_set: %s\n",
805 gnutls_strerror (rv));
809 GNUTLS_ALPN_MANDATORY);
888 while (NULL != msg_curr)
890 msg_curr = msg_curr->
next;
896 while (NULL != msg_curr)
898 msg_curr = msg_curr->
next;
905 while (NULL != long_poll_curr)
907 long_poll_temp = long_poll_curr;
908 long_poll_curr = long_poll_curr->
next;
912 if (NULL != connection->
d_qh)
915 connection->
d_qh = NULL;
925 "tried to remove non-existent connection from addr_map\n");
929 "# connections active",
933 ngtcp2_conn_del (connection->
conn);
936 nghttp3_conn_del (connection->
h3_conn);
938 gnutls_deinit (connection->
session);
963 nv.name = (
const uint8_t *)
name;
964 nv.namelen = strlen (
name);
965 nv.value = (
const uint8_t *)
value;
966 nv.valuelen = strlen (
value);
977read_data (nghttp3_conn *conn, int64_t stream_id, nghttp3_vec *vec,
978 size_t veccnt, uint32_t *pflags,
void *user_data,
979 void *stream_user_data)
981 struct Stream *stream = stream_user_data;
983 vec[0].base = stream->
data;
985 *pflags |= NGHTTP3_DATA_FLAG_EOF;
1004 const uint8_t *
data,
1008 char contentlen[20];
1009 nghttp3_data_reader dr = {};
1016 nva[0] =
make_nv (
":method",
"POST",
1017 NGHTTP3_NV_FLAG_NO_COPY_NAME
1018 | NGHTTP3_NV_FLAG_NO_COPY_VALUE);
1019 nva[1] =
make_nv (
":scheme",
"https",
1020 NGHTTP3_NV_FLAG_NO_COPY_NAME
1021 | NGHTTP3_NV_FLAG_NO_COPY_VALUE);
1022 nva[2] =
make_nv (
":authority",
1024 NGHTTP3_NV_FLAG_NO_COPY_NAME);
1025 nva[3] =
make_nv (
":path",
"/",
1026 NGHTTP3_NV_FLAG_NO_COPY_NAME
1027 | NGHTTP3_NV_FLAG_NO_COPY_VALUE);
1028 nva[4] =
make_nv (
"user-agent",
"nghttp3/ngtcp2 client",
1029 NGHTTP3_NV_FLAG_NO_COPY_NAME
1030 | NGHTTP3_NV_FLAG_NO_COPY_VALUE);
1031 nva[5] =
make_nv (
"content-type",
"application/octet-stream",
1032 NGHTTP3_NV_FLAG_NO_COPY_NAME
1033 | NGHTTP3_NV_FLAG_NO_COPY_VALUE);
1034 nva[6] =
make_nv (
"content-length", contentlen,
1035 NGHTTP3_NV_FLAG_NO_COPY_NAME);
1040 nva, 7, &dr, stream);
1044 "nghttp3_conn_submit_request: %s\n",
1045 nghttp3_strerror (rv));
1067 "send get request\n");
1071 nva[0] =
make_nv (
":method",
"GET",
1072 NGHTTP3_NV_FLAG_NO_COPY_NAME
1073 | NGHTTP3_NV_FLAG_NO_COPY_VALUE);
1074 nva[1] =
make_nv (
":scheme",
"https",
1075 NGHTTP3_NV_FLAG_NO_COPY_NAME
1076 | NGHTTP3_NV_FLAG_NO_COPY_VALUE);
1077 nva[2] =
make_nv (
":authority",
1079 NGHTTP3_NV_FLAG_NO_COPY_NAME);
1080 nva[3] =
make_nv (
":path",
"/",
1081 NGHTTP3_NV_FLAG_NO_COPY_NAME
1082 | NGHTTP3_NV_FLAG_NO_COPY_VALUE);
1083 nva[4] =
make_nv (
"user-agent",
"nghttp3/ngtcp2 client",
1084 NGHTTP3_NV_FLAG_NO_COPY_NAME
1085 | NGHTTP3_NV_FLAG_NO_COPY_VALUE);
1089 nva, 5, NULL, stream);
1093 "nghttp3_conn_submit_request: %s\n",
1094 nghttp3_strerror (rv));
1111 "long_poll_timeoutcb called!\n");
1118 long_poll->
timer = NULL;
1120 stream = long_poll->
stream;
1122 if (NULL != long_poll->
prev)
1126 if (NULL != long_poll->
next)
1140 nva[0] =
make_nv (
":status",
"204",
1141 NGHTTP3_NV_FLAG_NO_COPY_NAME
1142 | NGHTTP3_NV_FLAG_NO_COPY_VALUE);
1143 nva[1] =
make_nv (
"server",
"nghttp3/ngtcp2 server",
1144 NGHTTP3_NV_FLAG_NO_COPY_NAME
1145 | NGHTTP3_NV_FLAG_NO_COPY_VALUE);
1146 rv = nghttp3_conn_submit_response (connection->
h3_conn,
1151 "nghttp3_conn_submit_response: %s\n",
1152 nghttp3_strerror (rv));
1155 ngtcp2_conn_shutdown_stream_read (connection->
conn, 0,
1157 NGHTTP3_H3_NO_ERROR);
1173 uint8_t *
data,
size_t datalen)
1176 nghttp3_data_reader dr = {};
1177 char content_length_str[20];
1182 nva[0] =
make_nv (
":status",
"200",
1183 NGHTTP3_NV_FLAG_NO_COPY_NAME
1184 | NGHTTP3_NV_FLAG_NO_COPY_VALUE);
1185 nva[1] =
make_nv (
"server",
"nghttp3/ngtcp2 server",
1186 NGHTTP3_NV_FLAG_NO_COPY_NAME
1187 | NGHTTP3_NV_FLAG_NO_COPY_VALUE);
1188 nva[2] =
make_nv (
"content-type",
"application/octet-stream",
1189 NGHTTP3_NV_FLAG_NO_COPY_NAME
1190 | NGHTTP3_NV_FLAG_NO_COPY_VALUE);
1191 nva[3] =
make_nv (
"content-length", content_length_str,
1192 NGHTTP3_NV_FLAG_NO_COPY_NAME);
1203 "nghttp3_conn_submit_response: %s\n",
1204 nghttp3_strerror (rv));
1228 nva[0] =
make_nv (
":status",
"200",
1229 NGHTTP3_NV_FLAG_NO_COPY_NAME
1230 | NGHTTP3_NV_FLAG_NO_COPY_VALUE);
1231 nva[1] =
make_nv (
"server",
"nghttp3/ngtcp2 server",
1232 NGHTTP3_NV_FLAG_NO_COPY_NAME
1233 | NGHTTP3_NV_FLAG_NO_COPY_VALUE);
1245 "nghttp3_conn_submit_response: %s\n",
1246 nghttp3_strerror (rv));
1254 "rm msg, len = %lu\n",
1267 "server recv GET request\n");
1273 (uint8_t *)
msg->buf,
1284 "add long_poll, len = %lu\n",
1287 long_poll->
stream = stream;
1288 long_poll->
next = NULL;
1310 while (NULL != long_poll &&
1314 if (NULL != long_poll->
next)
1324 (uint8_t *)
msg->buf,
1327 if (NULL != long_poll->
next)
1333 "rm long_poll, len = %lu\n",
1357 uint16_t msize = ntohs (
msg->
size);
1358 struct Stream *post_stream;
1363 "mq_send_d: init = %d, msg->size = %u, time: %llu\n",
1365 (
unsigned long long)
timestamp () / NGTCP2_SECONDS);
1366 if (NULL == connection->
conn)
1369 "No quic connection has been established yet\n");
1375 if (msize > connection->
d_mtu)
1378 "msize: %u, mtu: %lu\n",
1385 "connection destroy called, destroying connection\n");
1396 ngtcp2_conn_open_bidi_stream (connection->
conn,
1413 if (NULL != long_poll->
next)
1419 "rm long_poll, len = %lu\n",
1428 "add msg, len = %lu\n",
1431 send_buf->
size = msize;
1433 send_buf->
next = NULL;
1442 while (NULL != long_poll &&
1446 if (NULL != long_poll->
next)
1456 (uint8_t *) send_buf->
buf,
1459 if (NULL != long_poll->
next)
1465 "rm long_poll, len = %lu\n",
1488 "Default MQ destroyed\n");
1489 if (
mq == connection->
d_mq)
1491 connection->
d_mq = NULL;
1526 "MQ error in queue to %s: %d\n",
1544 "setup_connection_mq: init = %u\n",
1548 switch (connection->
address->sa_family)
1567 connection->
d_mtu = base_mtu;
1569 if (NULL == connection->
d_mq)
1596 ngtcp2_conn_extend_max_stream_offset (connection->
conn, stream_id, consumed);
1597 ngtcp2_conn_extend_max_offset (connection->
conn, consumed);
1606 uint64_t app_error_code,
void *conn_user_data,
1607 void *stream_user_data)
1609 struct Connection *connection = conn_user_data;
1613 "HTTP stream %lu closed\n",
1614 (
unsigned long) stream_id);
1616 ngtcp2_is_bidi_stream (stream_id))
1618 ngtcp2_conn_extend_max_streams_bidi (connection->
conn, 1);
1621 ! ngtcp2_is_bidi_stream (stream_id))
1623 ngtcp2_conn_extend_max_streams_uni (connection->
conn, 1);
1635 size_t datalen,
void *user_data,
void *stream_user_data)
1638 "http_recv_data_cb\n");
1652 "message recv len of %zd less than length of peer identity\n",
1654 return NGHTTP3_ERR_CALLBACK_FAILURE;
1674 "GNUNET_TRANSPORT_communicator_receive:%d, hdr->len = %u, datalen = %lu, init = %d\n",
1676 return NGHTTP3_ERR_CALLBACK_FAILURE;
1679 "GNUNET_TRANSPORT_communicator_receive:%d, hdr->len = %u, datalen = %lu, init = %d\n",
1690 size_t nconsumed,
void *user_data,
1691 void *stream_user_data)
1704 void *user_data,
void *stream_user_data)
1712 return NGHTTP3_ERR_CALLBACK_FAILURE;
1725 nghttp3_rcbuf *
name, nghttp3_rcbuf *
value, uint8_t flags,
1726 void *user_data,
void *stream_user_data)
1728 nghttp3_vec namebuf = nghttp3_rcbuf_get_buf (
name);
1729 nghttp3_vec valbuf = nghttp3_rcbuf_get_buf (
value);
1733 (
int) namebuf.len, namebuf.base,
1734 (
int) valbuf.len, valbuf.base);
1738 struct Stream *stream = stream_user_data;
1741 case NGHTTP3_QPACK_TOKEN__PATH:
1742 stream->
urilen = valbuf.len;
1743 stream->
uri = (uint8_t *) malloc (valbuf.len);
1744 memcpy (stream->
uri, valbuf.base, valbuf.len);
1746 case NGHTTP3_QPACK_TOKEN__METHOD:
1748 stream->
method = (uint8_t *) malloc (valbuf.len);
1749 memcpy (stream->
method, valbuf.base, valbuf.len);
1751 case NGHTTP3_QPACK_TOKEN__AUTHORITY:
1753 stream->
authority = (uint8_t *) malloc (valbuf.len);
1754 memcpy (stream->
authority, valbuf.base, valbuf.len);
1767 uint64_t app_error_code,
void *user_data,
1768 void *stream_user_data)
1773 rv = ngtcp2_conn_shutdown_stream_read (connection->
conn,
1780 "ngtcp2_conn_shutdown_stream_read: %s\n",
1781 ngtcp2_strerror (rv));
1782 return NGHTTP3_ERR_CALLBACK_FAILURE;
1793 void *stream_user_data)
1796 struct Stream *stream = stream_user_data;
1806 return NGHTTP3_ERR_CALLBACK_FAILURE;
1816 while (NULL != long_poll)
1821 "client side recv GET response\n");
1823 rv = ngtcp2_conn_open_bidi_stream (connection->
conn,
1828 "ngtcp2_conn_open_bidi_stream: %s\n",
1829 ngtcp2_strerror (rv));
1835 long_poll = long_poll->
next;
1847 uint64_t app_error_code,
void *user_data,
1848 void *stream_user_data)
1853 rv = ngtcp2_conn_shutdown_stream_write (connection->
conn,
1860 "ngtcp2_conn_shutdown_stream_write: %s\n",
1861 ngtcp2_strerror (rv));
1862 return NGHTTP3_ERR_CALLBACK_FAILURE;
1878 nghttp3_settings settings;
1879 const nghttp3_mem *mem = nghttp3_mem_default ();
1880 int64_t ctrl_stream_id;
1881 int64_t enc_stream_id;
1882 int64_t dec_stream_id;
1883 nghttp3_callbacks callbacks = {
1895 if (NULL != connection->
h3_conn)
1900 if (ngtcp2_conn_get_streams_uni_left (connection->
conn) < 3)
1903 "uni stream left less than 3\n");
1909 callbacks.begin_headers = NULL;
1913 nghttp3_settings_default (&settings);
1914 settings.qpack_blocked_streams = 100;
1915 settings.qpack_encoder_max_dtable_capacity = 4096;
1919 const ngtcp2_transport_params *params =
1920 ngtcp2_conn_get_local_transport_params (connection->
conn);
1922 rv = nghttp3_conn_server_new (&connection->
h3_conn,
1927 nghttp3_conn_set_max_client_streams_bidi (connection->
h3_conn,
1928 params->initial_max_streams_bidi);
1932 "nghttp3_conn_server_new: %s\n",
1933 nghttp3_strerror (rv));
1939 rv = nghttp3_conn_client_new (&connection->
h3_conn,
1947 "nghttp3_conn_client_new: %s\n",
1948 nghttp3_strerror (rv));
1953 rv = ngtcp2_conn_open_uni_stream (connection->
conn, &ctrl_stream_id, NULL);
1957 "ngtcp2_conn_open_uni_stream: %s\n",
1958 ngtcp2_strerror (rv));
1962 rv = nghttp3_conn_bind_control_stream (connection->
h3_conn, ctrl_stream_id);
1966 "nghttp3_conn_bind_control_stream: %s\n",
1967 nghttp3_strerror (rv));
1971 rv = ngtcp2_conn_open_uni_stream (connection->
conn, &enc_stream_id, NULL);
1975 "ngtcp2_conn_open_uni_stream: %s\n",
1976 ngtcp2_strerror (rv));
1980 rv = ngtcp2_conn_open_uni_stream (connection->
conn, &dec_stream_id, NULL);
1984 "ngtcp2_conn_open_uni_stream: %s\n",
1985 ngtcp2_strerror (rv));
1989 rv = nghttp3_conn_bind_qpack_streams (connection->
h3_conn,
1990 enc_stream_id, dec_stream_id);
1994 "nghttp3_conn_bind_qpack_streams: %s\n",
1995 nghttp3_strerror (rv));
2000 "Bind control stream: %"PRIi64
", enc stream: %"PRIi64
", dec stream: %"PRIi64
"\n",
2001 ctrl_stream_id, enc_stream_id, dec_stream_id);
2012 const ngtcp2_rand_ctx *rand_ctx)
2026 uint8_t *token,
size_t cidlen,
2035 cid->datalen = cidlen;
2038 NGTCP2_STATELESS_RESET_TOKENLEN);
2048 uint64_t offset,
const uint8_t *
data,
size_t datalen,
2050 void *stream_user_data)
2053 nghttp3_ssize nconsumed;
2055 if (NULL == connection->
h3_conn)
2059 nconsumed = nghttp3_conn_read_stream (connection->
h3_conn, stream_id,
2061 flags & NGTCP2_STREAM_DATA_FLAG_FIN);
2065 "nghttp3_conn_read_stream: %s, init = %d\n",
2066 nghttp3_strerror (nconsumed), connection->
is_initiator);
2067 ngtcp2_ccerr_set_application_error (
2069 nghttp3_err_infer_quic_app_error_code (nconsumed),
2071 return NGTCP2_ERR_CALLBACK_FAILURE;
2085 if (! ngtcp2_is_bidi_stream (stream_id))
2101 uint64_t app_error_code,
void *user_data,
2102 void *stream_user_data)
2105 "stream_close id = %"PRIi64
"\n",
2110 if (! (flags & NGTCP2_STREAM_CLOSE_FLAG_APP_ERROR_CODE_SET))
2112 app_error_code = NGHTTP3_H3_NO_ERROR;
2117 if (0 == app_error_code)
2119 app_error_code = NGHTTP3_H3_NO_ERROR;
2122 rv = nghttp3_conn_close_stream (connection->
h3_conn,
2129 case NGHTTP3_ERR_STREAM_NOT_FOUND:
2131 ngtcp2_is_bidi_stream (stream_id))
2133 ngtcp2_conn_extend_max_streams_bidi (connection->
conn, 1);
2136 ! ngtcp2_is_bidi_stream (stream_id))
2138 ngtcp2_conn_extend_max_streams_uni (connection->
conn, 1);
2143 "nghttp3_conn_close_stream: %s\n",
2144 nghttp3_strerror (rv));
2145 ngtcp2_ccerr_set_application_error (
2147 nghttp3_err_infer_quic_app_error_code (rv),
2149 return NGTCP2_ERR_CALLBACK_FAILURE;
2161 uint64_t offset, uint64_t datalen,
void *user_data,
2162 void *stream_user_data)
2167 if (NULL == connection->
h3_conn)
2172 rv = nghttp3_conn_add_ack_offset (connection->
h3_conn, stream_id, datalen);
2176 "nghttp3_conn_add_ack_offset: %s\n",
2177 nghttp3_strerror (rv));
2178 return NGTCP2_ERR_CALLBACK_FAILURE;
2189 uint64_t max_data,
void *user_data,
2190 void *stream_user_data)
2195 rv = nghttp3_conn_unblock_stream (connection->
h3_conn, stream_id);
2199 "nghttp3_conn_unblock_stream: %s\n",
2200 nghttp3_strerror (rv));
2201 return NGTCP2_ERR_CALLBACK_FAILURE;
2212 uint64_t app_error_code,
void *user_data,
2213 void *stream_user_data)
2220 rv = nghttp3_conn_shutdown_stream_read (connection->
h3_conn, stream_id);
2224 "nghttp3_conn_shutdown_stream_read: %s\n",
2225 nghttp3_strerror (rv));
2226 return NGTCP2_ERR_CALLBACK_FAILURE;
2241 if (NULL == connection->
h3_conn)
2245 nghttp3_conn_set_max_client_streams_bidi (connection->
h3_conn, max_streams);
2255 uint64_t app_error_code,
void *user_data,
2256 void *stream_user_data)
2263 rv = nghttp3_conn_shutdown_stream_read (connection->
h3_conn, stream_id);
2267 "nghttp3_conn_shutdown_stream_read: %s\n",
2268 nghttp3_strerror (rv));
2269 return NGTCP2_ERR_CALLBACK_FAILURE;
2283 if (NGTCP2_ENCRYPTION_LEVEL_1RTT != level)
2294 return NGTCP2_ERR_CALLBACK_FAILURE;
2307 if (NGTCP2_ENCRYPTION_LEVEL_1RTT != level)
2321 return NGTCP2_ERR_CALLBACK_FAILURE;
2344 long_poll->
next = NULL;
2346 long_poll->
timer = NULL;
2377 socklen_t local_addrlen,
2379 socklen_t remote_addrlen)
2384 ngtcp2_settings settings;
2385 ngtcp2_transport_params params;
2386 ngtcp2_path path = {
2391 ngtcp2_callbacks callbacks = {
2392 .client_initial = ngtcp2_crypto_client_initial_cb,
2393 .recv_crypto_data = ngtcp2_crypto_recv_crypto_data_cb,
2394 .encrypt = ngtcp2_crypto_encrypt_cb,
2395 .decrypt = ngtcp2_crypto_decrypt_cb,
2396 .hp_mask = ngtcp2_crypto_hp_mask_cb,
2397 .recv_retry = ngtcp2_crypto_recv_retry_cb,
2398 .update_key = ngtcp2_crypto_update_key_cb,
2399 .delete_crypto_aead_ctx = ngtcp2_crypto_delete_crypto_aead_ctx_cb,
2400 .delete_crypto_cipher_ctx = ngtcp2_crypto_delete_crypto_cipher_ctx_cb,
2401 .get_path_challenge_data = ngtcp2_crypto_get_path_challenge_data_cb,
2402 .version_negotiation = ngtcp2_crypto_version_negotiation_cb,
2415 scid.datalen = NGTCP2_MAX_CIDLEN;
2419 dcid.datalen = NGTCP2_MAX_CIDLEN;
2423 ngtcp2_settings_default (&settings);
2426 ngtcp2_transport_params_default (¶ms);
2427 params.initial_max_streams_uni = 100;
2428 params.initial_max_stream_data_bidi_local = 6291456;
2429 params.initial_max_data = 15728640;
2430 params.initial_max_stream_data_bidi_remote = 0;
2431 params.initial_max_stream_data_uni = 6291456;
2432 params.initial_max_streams_bidi = 0;
2433 params.max_idle_timeout = 30 * NGTCP2_SECONDS;
2434 params.active_connection_id_limit = 7;
2435 params.grease_quic_bit = 1;
2436 rv = ngtcp2_conn_client_new (&connection->
conn,
2440 NGTCP2_PROTO_VER_V1,
2449 "ngtcp2_conn_client_new: %s\n",
2450 ngtcp2_strerror (rv));
2453 ngtcp2_conn_set_tls_native_handle (connection->
conn, connection->
session);
2454 connection->
conn_ref.user_data = connection;
2469 connection->
timer = NULL;
2471 if (ngtcp2_conn_in_closing_period (connection->
conn))
2474 "Closing period over\n");
2478 if (ngtcp2_conn_in_draining_period (connection->
conn))
2481 "Draining period over\n");
2496 ngtcp2_duration pto;
2499 if (NULL != connection->
timer)
2502 connection->
timer = NULL;
2504 pto = ngtcp2_conn_get_pto (connection->
conn);
2511 "Start draining period\n");
2528 ngtcp2_path_storage
ps;
2530 ngtcp2_ssize nwrite;
2531 ngtcp2_duration pto;
2534 if (NULL == connection->
conn ||
2535 ngtcp2_conn_in_closing_period (connection->
conn) ||
2536 ngtcp2_conn_in_draining_period (connection->
conn))
2542 "Start closing period\n");
2546 if (NULL != connection->
timer)
2549 connection->
timer = NULL;
2551 pto = ngtcp2_conn_get_pto (connection->
conn);
2562 ngtcp2_path_storage_zero (&
ps);
2563 nwrite = ngtcp2_conn_write_connection_close (connection->
conn,
2567 NGTCP2_MAX_UDP_PAYLOAD_SIZE,
2573 "ngtcp2_conn_write_connection_close: %s\n",
2574 ngtcp2_strerror (nwrite));
2604 "Closing period, send CONNECTION_CLOSE\n");
2633 if (NGTCP2_CCERR_TYPE_IDLE_CLOSE == connection->
last_error.type)
2643 if (ngtcp2_conn_in_draining_period (connection->
conn))
2669 rv = ngtcp2_conn_handle_expiry (connection->
conn,
timestamp ());
2673 "ngtcp2_conn_handle_expiry: %s\n",
2674 ngtcp2_strerror (rv));
2675 ngtcp2_ccerr_set_liberr (&connection->
last_error, rv, NULL, 0);
2691 "timeoutcb func called!\n");
2693 connection->
timer = NULL;
2743 ngtcp2_tstamp expiry;
2747 expiry = ngtcp2_conn_get_expiry (connection->
conn);
2750 if (NULL != connection->
timer)
2753 connection->
timer = NULL;
2758 "Timer has expired\n");
2765 (
double) (expiry - now) / NGTCP2_SECONDS);
2768 (expiry - now) / 1000ULL + 1);
2786 ngtcp2_path_storage
ps;
2789 ngtcp2_ssize nwrite;
2790 ngtcp2_ssize wdatalen;
2791 nghttp3_vec vec[16];
2792 nghttp3_ssize sveccnt;
2797 ngtcp2_path_storage_zero (&
ps);
2806 ngtcp2_conn_get_max_data_left (connection->
conn))
2808 sveccnt = nghttp3_conn_writev_stream (connection->
h3_conn,
2816 "nghttp3_conn_writev_stream: %s\n",
2817 nghttp3_strerror (sveccnt));
2819 ngtcp2_ccerr_set_application_error (
2821 nghttp3_err_infer_quic_app_error_code (sveccnt),
2828 flags = NGTCP2_WRITE_STREAM_FLAG_MORE;
2830 flags |= NGTCP2_WRITE_STREAM_FLAG_FIN;
2832 nwrite = ngtcp2_conn_writev_stream (connection->
conn,
2847 case NGTCP2_ERR_STREAM_DATA_BLOCKED:
2848 nghttp3_conn_block_stream (connection->
h3_conn, stream_id);
2850 case NGTCP2_ERR_STREAM_SHUT_WR:
2851 nghttp3_conn_shutdown_stream_write (connection->
h3_conn, stream_id);
2853 case NGTCP2_ERR_WRITE_MORE:
2854 rv = nghttp3_conn_add_write_offset (connection->
h3_conn, stream_id,
2859 "nghttp3_conn_add_write_offset: %s\n",
2860 nghttp3_strerror (rv));
2861 ngtcp2_ccerr_set_application_error (
2863 nghttp3_err_infer_quic_app_error_code (rv),
2870 "ngtcp2_conn_writev_stream: %s\n",
2871 ngtcp2_strerror (nwrite));
2872 ngtcp2_ccerr_set_liberr (&connection->
last_error,
2880 ngtcp2_conn_update_pkt_tx_time (connection->
conn, ts);
2885 rv = nghttp3_conn_add_write_offset (connection->
h3_conn, stream_id,
2890 "nghttp3_conn_add_write_offset: %s\n",
2891 nghttp3_strerror (rv));
2892 ngtcp2_ccerr_set_application_error (
2894 nghttp3_err_infer_quic_app_error_code (rv),
2920 (ngtcp2_conn_in_closing_period (connection->
conn) ||
2921 ngtcp2_conn_in_draining_period (connection->
conn)))
2962 socklen_t local_addrlen;
2964 socklen_t remote_addrlen;
2994 if (NULL != connection)
2997 "receiver %s already exist or is being connected to\n",
3023 "# connections active",
3045 ngtcp2_conn_set_tls_native_handle (connection->
conn, connection->
session);
3051 "connection_write failed\n");
3077 const struct sockaddr *addr,
3140 "do_shutdown start\n");
3145 gnutls_certificate_free_credentials (
cred);
3184 "do_shutdown finished\n");
3204 struct sockaddr *
local_addr, socklen_t local_addrlen,
3205 struct sockaddr *
remote_addr, socklen_t remote_addrlen,
3206 const ngtcp2_pkt_info *pi,
3207 const uint8_t *
data,
size_t datalen)
3213 path.local.addrlen = local_addrlen;
3215 path.remote.addrlen = remote_addrlen;
3217 rv = ngtcp2_conn_read_pkt (connection->
conn, &path, pi,
data, datalen,
3222 "ngtcp2_conn_read_pkt: %s\n",
3223 ngtcp2_strerror (rv));
3226 case NGTCP2_ERR_DRAINING:
3234 ngtcp2_ccerr_set_liberr (&connection->
last_error, rv, NULL, 0);
3236 case NGTCP2_ERR_RETRY:
3239 case NGTCP2_ERR_DROP_CONN:
3242 case NGTCP2_ERR_CRYPTO:
3245 ngtcp2_ccerr_set_tls_alert (
3247 ngtcp2_conn_get_tls_alert (connection->
conn),
3254 ngtcp2_ccerr_set_liberr (&connection->
last_error, rv, NULL, 0);
3280 struct sockaddr *
local_addr, socklen_t local_addrlen,
3281 struct sockaddr *
remote_addr, socklen_t remote_addrlen,
3282 const ngtcp2_pkt_info *pi,
3283 const uint8_t *
data,
size_t datalen)
3287 remote_addrlen, pi,
data, datalen);
3313 socklen_t local_addrlen,
3315 socklen_t remote_addrlen,
3316 const ngtcp2_cid *dcid,
const ngtcp2_cid *scid,
3321 ngtcp2_transport_params params;
3323 ngtcp2_conn *
conn = NULL;
3324 ngtcp2_settings settings;
3325 ngtcp2_callbacks callbacks = {
3326 .recv_client_initial = ngtcp2_crypto_recv_client_initial_cb,
3327 .recv_crypto_data = ngtcp2_crypto_recv_crypto_data_cb,
3328 .encrypt = ngtcp2_crypto_encrypt_cb,
3329 .decrypt = ngtcp2_crypto_decrypt_cb,
3330 .hp_mask = ngtcp2_crypto_hp_mask_cb,
3331 .update_key = ngtcp2_crypto_update_key_cb,
3332 .delete_crypto_aead_ctx = ngtcp2_crypto_delete_crypto_aead_ctx_cb,
3333 .delete_crypto_cipher_ctx = ngtcp2_crypto_delete_crypto_cipher_ctx_cb,
3334 .get_path_challenge_data = ngtcp2_crypto_get_path_challenge_data_cb,
3335 .version_negotiation = ngtcp2_crypto_version_negotiation_cb,
3353 path.local.addrlen = local_addrlen;
3355 path.remote.addrlen = remote_addrlen;
3358 memset (new_connection, 0,
sizeof (
struct Connection));
3360 gnutls_init (&new_connection->
session,
3362 | GNUTLS_ENABLE_EARLY_DATA
3363 | GNUTLS_NO_END_OF_EARLY_DATA);
3365 gnutls_credentials_set (new_connection->
session,
3366 GNUTLS_CRD_CERTIFICATE,
cred);
3368 ngtcp2_transport_params_default (¶ms);
3369 params.initial_max_streams_uni = 3;
3370 params.initial_max_streams_bidi = 128;
3371 params.initial_max_stream_data_bidi_local = 128 * 1024;
3372 params.initial_max_stream_data_bidi_remote = 256 * 1024;
3373 params.initial_max_stream_data_uni = 256 * 1024;
3374 params.initial_max_data = 1024 * 1024;
3375 params.original_dcid_present = 1;
3376 params.max_idle_timeout = 30 * NGTCP2_SECONDS;
3377 params.original_dcid = *scid;
3379 ngtcp2_settings_default (&settings);
3381 scid_.datalen = NGTCP2_MAX_CIDLEN;
3383 &scid_.data, scid_.datalen);
3385 rv = ngtcp2_conn_server_new (&
conn,
3398 "ngtcp2_conn_server_new: %s\n",
3399 ngtcp2_strerror (rv));
3411 ngtcp2_crypto_gnutls_configure_server_session (new_connection->
session);
3412 ngtcp2_conn_set_tls_native_handle (new_connection->
conn,
3414 gnutls_session_set_ptr (new_connection->
session,
3418 new_connection->
conn_ref.user_data = new_connection;
3422 return new_connection;
3443 struct sockaddr *
local_addr, socklen_t local_addrlen,
3444 struct sockaddr *
remote_addr, socklen_t remote_addrlen,
3445 const ngtcp2_pkt_info *pi,
3446 const uint8_t *
data,
size_t datalen)
3448 ngtcp2_version_cid version_cid;
3451 rv = ngtcp2_pkt_decode_version_cid (&version_cid,
data, datalen,
3457 case NGTCP2_ERR_VERSION_NEGOTIATION:
3462 "Can't decode version and CID: %s\n",
3463 ngtcp2_strerror (rv));
3467 if (NULL == connection)
3469 ngtcp2_pkt_hd header;
3470 rv = ngtcp2_accept (&header,
data, datalen);
3474 "ngtcp2_accept: %s\n",
3475 ngtcp2_strerror (rv));
3484 remote_addrlen, &header.scid, &header.dcid,
3486 if (NULL == connection)
3489 "accept connection error!\n");
3498 remote_addrlen, pi,
data, datalen);
3520 if (ngtcp2_conn_in_closing_period (connection->
conn))
3530 if (ngtcp2_conn_in_draining_period (connection->
conn))
3536 remote_addrlen, pi,
data, datalen);
3559 struct sockaddr_storage sa;
3560 socklen_t salen =
sizeof (sa);
3562 uint8_t buf[UINT16_MAX];
3568 socklen_t local_addrlen;
3592 (
struct sockaddr *) &sa,
3596 struct sockaddr *addr = (
struct sockaddr*) &sa;
3598 if (EAGAIN == errno)
3601 "Failed to recv from %s family %d failed sock %p\n",
3610 "Read %llu bytes\n",
3611 (
unsigned long long) rcvd);
3616 "Read 0 bytes from UDP socket\n");
3628 ngtcp2_pkt_info pi = {0};
3632 (
struct sockaddr *) &sa,
3633 salen, &pi, buf, rcvd);
3642 "connection write error!\n");
3650 (
struct sockaddr *) &sa, salen,
3672 const char *cfgfile,
3676 struct sockaddr *in;
3678 struct sockaddr_storage in_sto;
3715 "Creating new certificate\n");
3721 "gnunet-transport-certificate-creation",
3722 "gnunet-transport-certificate-creation",
3726 if (NULL == cert_creation)
3729 "Can't create new key pair %s/%s\n",
3730 key_file, cert_file);
3755 "Failed to setup UDP socket address with path `%s'\n",
3768 "Failed to create socket for %s family %d\n",
3776 if (AF_INET6 == in->sa_family)
3787 "Failed to bind socket for %s family %d sock %p\n",
3798 sto_len =
sizeof(in_sto);
3800 (
struct sockaddr *) &in_sto,
3803 memcpy (&in_sto, in, in_len);
3808 in = (
struct sockaddr *) &in_sto;
3812 "Bound to `%s' sock %p\n",
3813 GNUNET_a2s ((
const struct sockaddr *) &in_sto,
3816 switch (in->sa_family)
3819 my_port = ntohs (((
struct sockaddr_in *) in)->sin_port);
3823 my_port = ntohs (((
struct sockaddr_in6 *) in)->sin6_port);
3836 rv = gnutls_certificate_allocate_credentials (&
cred);
3838 rv = gnutls_certificate_set_x509_system_trust (
cred);
3842 "cred init failed: %s\n",
3843 gnutls_strerror (rv));
3846 rv = gnutls_certificate_set_x509_key_file (
cred,
3849 GNUTLS_X509_FMT_PEM);
3851 "key_file: %s\ncert_file: %s\n",
3852 key_file, cert_file);
3858 "gnutls_certificate_set_x509_key_file: %s\n",
3859 gnutls_strerror (rv));
3871 "Transport service is lacking key configuration settings. Exiting.\n"));
3901 (
const struct sockaddr **) &in,
3926 "Starting http3 communicator\n");
3933 "gnunet-communicator-http3",
3934 _ (
"GNUnet HTTP3 communicator"),
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
struct GNUNET_GETOPT_CommandLineOption options[]
struct GNUNET_MQ_Handle * mq
struct GNUNET_MessageHeader * msg
static int start
Set if we are to start default services (including ARM).
static int ret
Final status code.
static uint16_t port
Port number.
static char * peer_id
Option –peer.
static int send_conn_close(struct Connection *connection)
Send the packet in the conn_closebuf.
static void start_draining_period(struct Connection *connection)
Start the draining period, called after receiving CONNECTION_CLOSE.
static int recv_stream_data_cb(ngtcp2_conn *conn, uint32_t flags, int64_t stream_id, uint64_t offset, const uint8_t *data, size_t datalen, void *user_data, void *stream_user_data)
The callback function for ngtcp2_callbacks.recv_stream_data.
static int client_quic_init(struct Connection *connection, struct sockaddr *local_addr, socklen_t local_addrlen, struct sockaddr *remote_addr, socklen_t remote_addrlen)
Create new ngtcp2_conn as client side.
static int connection_write(struct Connection *connection)
Write the data in the stream into the packet and handle timer.
static int get_connection_delete_it(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator over all connection to clean up.
static void mq_destroy_d(struct GNUNET_MQ_Handle *mq, void *impl_state)
Signature of functions implementing the destruction of a message queue.
static int get_stream_delete_it(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator over all streams to clean up.
static int stream_open_cb(ngtcp2_conn *conn, int64_t stream_id, void *user_data)
The callback function for ngtcp2_callbacks.stream_open.
static struct GNUNET_PeerIdentity my_identity
Our peer identity.
static int http_reset_stream_cb(nghttp3_conn *conn, int64_t stream_id, uint64_t app_error_code, void *user_data, void *stream_user_data)
The callback of nghttp3_callback.reset_stream.
static int http_stop_sending_cb(nghttp3_conn *conn, int64_t stream_id, uint64_t app_error_code, void *user_data, void *stream_user_data)
The callback of nghttp3_callback.stop_sending.
#define PRIORITY
the priorities to use on the ciphers, key exchange methods, and macs.
static int stream_start_response(struct Connection *connection, struct Stream *stream)
Make response to the request.
#define COMMUNICATOR_ADDRESS_PREFIX
Address prefix used by the communicator.
static void long_poll_timeoutcb(void *cls)
Timeout callback function in the long polling struct.
static void notify_cb(void *cls, const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *msg)
Function called when the transport service has received a backchannel message for this communicator (...
static int extend_max_stream_data_cb(ngtcp2_conn *conn, int64_t stream_id, uint64_t max_data, void *user_data, void *stream_user_data)
The callback function for ngtcp2_callbacks.extend_max_stream_data.
static int connection_write_streams(struct Connection *connection)
Write HTTP stream data and send the packets.
static int send_packet(struct Connection *connection, const uint8_t *data, size_t datalen)
Send the udp packet to remote.
static uint64_t timestamp(void)
Get current timestamp.
#define ADDRESS_VALIDITY_PERIOD
How long do we believe our addresses to remain up (before the other peer should revalidate).
static void rand_cb(uint8_t *dest, size_t destlen, const ngtcp2_rand_ctx *rand_ctx)
The callback function for ngtcp2_callbacks.rand.
static int stream_stop_sending_cb(ngtcp2_conn *conn, int64_t stream_id, uint64_t app_error_code, void *user_data, void *stream_user_data)
The callback function for ngtcp2_callbacks.stream_stop_sending.
static gnutls_certificate_credentials_t cred
The credential.
static int setup_httpconn(struct Connection *connection)
Setup the http3 connection.
network_error
Defines some error types related to network errors.
@ NETWORK_ERR_SEND_BLOCKED
static int client_gnutls_init(struct Connection *connection)
As the client, initialize the corresponding connection.
static int http_end_stream_cb(nghttp3_conn *conn, int64_t stream_id, void *user_data, void *stream_user_data)
The callback of nghttp3_callback.end_stream.
static void connection_destroy(struct Connection *connection)
Destroys a receiving state due to timeout or shutdown.
static void try_connection_reversal(void *cls, const struct sockaddr *addr, socklen_t addrlen)
static int connection_feed_data(struct Connection *connection, struct sockaddr *local_addr, socklen_t local_addrlen, struct sockaddr *remote_addr, socklen_t remote_addrlen, const ngtcp2_pkt_info *pi, const uint8_t *data, size_t datalen)
Decrypt QUIC packet.
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
static void connection_update_timer(struct Connection *connection)
Update the timer.
static int disable_v6
IPv6 disabled or not.
static struct Connection * connection_init(struct sockaddr *local_addr, socklen_t local_addrlen, struct sockaddr *remote_addr, socklen_t remote_addrlen, const ngtcp2_cid *dcid, const ngtcp2_cid *scid, uint32_t version)
Create a new connection.
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static int mq_init(void *cls, const struct GNUNET_PeerIdentity *peer_id, const char *address)
Function called by the transport service to initialize a message queue given address information abou...
static int recv_tx_key_cb(ngtcp2_conn *conn, ngtcp2_encryption_level level, void *user_data)
The callback function for ngtcp2_callbacks.recv_tx_key.
#define NUM_LONG_POLL
Long polling requests' number.
static void http_consume(struct Connection *connection, int64_t stream_id, size_t consumed)
Extend connection and stream offset.
static struct GNUNET_NETWORK_Handle * udp_sock
Our socket.
static nghttp3_ssize read_data(nghttp3_conn *conn, int64_t stream_id, nghttp3_vec *vec, size_t veccnt, uint32_t *pflags, void *user_data, void *stream_user_data)
The callback function to generate body.
static void mq_send_d(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *msg, void *impl_state)
Signature of functions implementing the sending functionality of a message queue.
static void sock_read(void *cls)
Socket read task.
static void do_shutdown(void *cls)
Shutdown the HTTP3 communicator.
#define COMMUNICATOR_CONFIG_SECTION
Configuration section used by the communicator.
static nghttp3_nv make_nv(const char *name, const char *value, uint8_t flag)
Make name/value pair for request headers.
static void nat_address_cb(void *cls, void **app_ctx, int add_remove, enum GNUNET_NAT_AddressClass ac, const struct sockaddr *addr, socklen_t addrlen)
Signature of the callback passed to GNUNET_NAT_register() for a function to call whenever our set of ...
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
static int get_new_connection_id_cb(ngtcp2_conn *conn, ngtcp2_cid *cid, uint8_t *token, size_t cidlen, void *user_data)
The callback function for ngtcp2_callbacks.get_new_connection_id.
static struct sockaddr * udp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
Convert UDP bind specification to a struct sockaddr *
static int extend_max_remote_streams_bidi_cb(ngtcp2_conn *conn, uint64_t max_streams, void *user_data)
The callback function for ngtcp2_callbacks.extend_max_remote_streams_bidi.
static int http_recv_data_cb(nghttp3_conn *conn, int64_t stream_id, const uint8_t *data, size_t datalen, void *user_data, void *stream_user_data)
The callback of nghttp3_callback.recv_data.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Setup communicator and launch network interactions.
static void reschedule_peer_timeout(struct Connection *connection)
Increment connection timeout due to activity.
static struct GNUNET_NAT_Handle * nat
Connection to NAT service.
static int acked_stream_data_offset_cb(ngtcp2_conn *conn, int64_t stream_id, uint64_t offset, uint64_t datalen, void *user_data, void *stream_user_data)
The callback function for ngtcp2_callbacks.acked_stream_data_offset.
static struct GNUNET_CONTAINER_MultiHashMap * addr_map
Map of sockaddr -> struct Connection.
static struct GNUNET_SCHEDULER_Task * read_task
ID of listen task.
static int http_begin_headers_cb(nghttp3_conn *conn, int64_t stream_id, void *user_data, void *stream_user_data)
The callback of nghttp3_callback.begin_headers.
static int handle_error(struct Connection *connection)
Handle errors.
static void setup_connection_mq(struct Connection *connection)
Setup the MQ for the connection.
static void mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state)
Implementation function that cancels the currently sent message.
static int have_v6_socket
GNUNET_YES if udp_sock supports IPv6.
static uint16_t my_port
Port number to which we are actually bound.
static int submit_post_request(struct Connection *connection, struct Stream *stream, const uint8_t *data, size_t datalen)
Submit the post request, send our data.
static void close_waitcb(void *cls)
The timeout callback function of closing/draining period.
static char * sockaddr_to_udpaddr_string(const struct sockaddr *address, socklen_t address_len)
Taken from: UDP communicator Converts address to the address string format used by this communicator ...
static int connection_on_read(struct Connection *connection, struct sockaddr *local_addr, socklen_t local_addrlen, struct sockaddr *remote_addr, socklen_t remote_addrlen, const ngtcp2_pkt_info *pi, const uint8_t *data, size_t datalen)
Connection read the packet data.
static struct Stream * create_stream(struct Connection *connection, int64_t stream_id)
Create a new stream of connection with stream_id.
static int stream_reset_cb(ngtcp2_conn *conn, int64_t stream_id, uint64_t final_size, uint64_t app_error_code, void *user_data, void *stream_user_data)
The callback function for ngtcp2_callbacks.stream_reset.
static ngtcp2_conn * get_conn(ngtcp2_crypto_conn_ref *ref)
The callback function for ngtcp2_crypto_conn_ref.
static int start_closing_period(struct Connection *connection)
Start the closing period and build the packet contains CONNECTION_CLOSE.
int main(int argc, char *const *argv)
The main function for the UNIX communicator.
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Our private key.
static void server_read_pkt(struct Connection *connection, const struct GNUNET_HashCode *addr_key, struct sockaddr *local_addr, socklen_t local_addrlen, struct sockaddr *remote_addr, socklen_t remote_addrlen, const ngtcp2_pkt_info *pi, const uint8_t *data, size_t datalen)
The server processes the newly received data packet.
static void timeoutcb(void *cls)
The timer callback function.
static int handle_expiry(struct Connection *connection)
Handles expired timer.
static int http_deferred_consume_cb(nghttp3_conn *conn, int64_t stream_id, size_t nconsumed, void *user_data, void *stream_user_data)
The callback of nghttp3_callback.deferred_consume.
static struct Stream * find_stream(struct Connection *connection, int64_t stream_id)
Find the stream specified with stream_id in connection and return the pointer of the stream,...
static int stream_close_cb(ngtcp2_conn *conn, uint32_t flags, int64_t stream_id, uint64_t app_error_code, void *user_data, void *stream_user_data)
The callback function for ngtcp2_callbacks.stream_close.
static int submit_get_request(struct Connection *connection, struct Stream *stream)
Client side submits the GET request, allow the server to send messages.
static int recv_rx_key_cb(ngtcp2_conn *conn, ngtcp2_encryption_level level, void *user_data)
The callback function for ngtcp2_callbacks.recv_rx_key.
static void remove_stream(struct Connection *connection, int64_t stream_id)
Remove the stream with the specified stream_id in connection.
static void mq_error(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
static int http_stream_close_cb(nghttp3_conn *conn, int64_t stream_id, uint64_t app_error_code, void *conn_user_data, void *stream_user_data)
The callback of nghttp3_callback.stream_close.
static int http_recv_header_cb(nghttp3_conn *conn, int64_t stream_id, int32_t token, nghttp3_rcbuf *name, nghttp3_rcbuf *value, uint8_t flags, void *user_data, void *stream_user_data)
The callback of nghttp3_callback.recv_header.
static int stream_send_data(struct Stream *stream, uint8_t *data, size_t datalen)
Send message through the specified stream.
static struct GNUNET_TRANSPORT_AddressIdentifier * ai
Handle to the operation that publishes our address.
static char * address
GNS address for this phone.
static struct GNUNET_PEERSTORE_Handle * ps
Handle to the PEERSTORE service.
static char * data
The data to insert into the dht.
struct GNUNET_HashCode key
The key used in the DHT.
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
static char * name
Name (label) of the records to list.
static char * value
Value of the record to add/remove.
static struct GNUNET_NAT_AUTO_Test * nt
Handle to a NAT test operation.
static char * remote_addr
Remote address to use for connection reversal request.
static char * local_addr
Local address to use for connection reversal request.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
Core service; the main API for encrypted P2P communications.
Constants for network protocols.
API to create, modify and access statistics.
Bandwidth allocation API for applications to interact with.
API of the transport service towards the communicator processes.
void GNUNET_TRANSPORT_communicator_address_remove(struct GNUNET_TRANSPORT_AddressIdentifier *ai)
Notify transport service about an address that this communicator no longer provides for this peer.
int GNUNET_TRANSPORT_communicator_receive(struct GNUNET_TRANSPORT_CommunicatorHandle *handle, const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *msg, struct GNUNET_TIME_Relative expected_addr_validity, GNUNET_TRANSPORT_MessageCompletedCallback cb, void *cb_cls)
Notify transport service that the communicator has received a message.
void GNUNET_TRANSPORT_communicator_mq_del(struct GNUNET_TRANSPORT_QueueHandle *qh)
Notify transport service that an MQ became unavailable due to a disconnect or timeout.
#define GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED
Queue length.
struct GNUNET_TRANSPORT_QueueHandle * GNUNET_TRANSPORT_communicator_mq_add(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const struct GNUNET_PeerIdentity *peer, const char *address, uint32_t mtu, uint64_t q_len, uint32_t priority, enum GNUNET_NetworkType nt, enum GNUNET_TRANSPORT_ConnectionStatus cs, struct GNUNET_MQ_Handle *mq)
Notify transport service that a MQ became available due to an "inbound" connection or because the com...
void GNUNET_TRANSPORT_communicator_disconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
Disconnect from the transport service.
struct GNUNET_TRANSPORT_CommunicatorHandle * GNUNET_TRANSPORT_communicator_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *config_section_name, const char *addr_prefix, enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, GNUNET_TRANSPORT_CommunicatorMqInit mq_init, void *mq_init_cls, GNUNET_TRANSPORT_CommunicatorNotify notify_cb, void *notify_cb_cls, GNUNET_TRANSPORT_StartBurstNotify sb)
Connect to the transport service.
struct GNUNET_TRANSPORT_AddressIdentifier * GNUNET_TRANSPORT_communicator_address_add(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const char *address, enum GNUNET_NetworkType nt, struct GNUNET_TIME_Relative expiration)
Notify transport service about an address that this communicator provides for this peer.
@ GNUNET_TRANSPORT_CC_RELIABLE
Transmission is reliabile (with ACKs), e.g.
@ GNUNET_TRANSPORT_CS_OUTBOUND
this is an outbound connection (transport initiated)
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don't receive messages from the peer?
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_CRYPTO_eddsa_key_create_from_configuration(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create a new private key by reading our peer's key from the file specified in the configuration.
@ GNUNET_CRYPTO_QUALITY_STRONG
High-quality operations are desired.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
unsigned int GNUNET_CONTAINER_multihashmap_size(const struct GNUNET_CONTAINER_MultiHashMap *map)
Get the number of key-value pairs in the map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
#define GNUNET_log(kind,...)
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages).
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
void GNUNET_log_from_nocheck(enum GNUNET_ErrorType kind, const char *comp, const char *message,...) __attribute__((format(printf
Log function that specifies an alternative component.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_free_nz(ptr)
Wrapper around free.
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
GNUNET_MQ_Error
Error codes for the queue.
struct GNUNET_MQ_Handle * GNUNET_MQ_queue_for_callbacks(GNUNET_MQ_SendImpl send, GNUNET_MQ_DestroyImpl destroy, GNUNET_MQ_CancelImpl cancel, void *impl_state, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *cls)
Create a message queue for the specified handlers.
void GNUNET_MQ_impl_send_continue(struct GNUNET_MQ_Handle *mq)
Call the send implementation for the next queued message, if any.
struct GNUNET_NAT_Handle * GNUNET_NAT_register(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *config_section, uint8_t proto, unsigned int num_addrs, const struct sockaddr **addrs, const socklen_t *addrlens, GNUNET_NAT_AddressCallback address_callback, GNUNET_NAT_ReversalCallback reversal_callback, void *callback_cls)
Attempt to enable port redirection and detect public IP address contacting UPnP or NAT-PMP routers on...
void GNUNET_NAT_unregister(struct GNUNET_NAT_Handle *nh)
Stop port redirection and public IP address detection for the given handle.
GNUNET_NAT_AddressClass
Some addresses contain sensitive information or are not suitable for global distribution.
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
int GNUNET_NETWORK_get_fd(const struct GNUNET_NETWORK_Handle *desc)
Return file descriptor for this network handle.
ssize_t GNUNET_NETWORK_socket_recvfrom(const struct GNUNET_NETWORK_Handle *desc, void *buffer, size_t length, struct sockaddr *src_addr, socklen_t *addrlen)
Read data from a socket (always non-blocking).
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
enum GNUNET_GenericReturnValue GNUNET_NETWORK_test_pf(int pf)
Test if the given protocol family is supported by this system.
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_bind(struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Bind a socket to a particular address.
ssize_t GNUNET_NETWORK_socket_sendto(const struct GNUNET_NETWORK_Handle *desc, const void *message, size_t length, const struct sockaddr *dest_addr, socklen_t dest_len)
Send data to a particular destination (always non-blocking).
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
void GNUNET_NT_scanner_done(struct GNUNET_NT_InterfaceScanner *is)
Terminate interface scanner.
struct GNUNET_NT_InterfaceScanner * GNUNET_NT_scanner_init(void)
Initialize the address characterization client handle.
enum GNUNET_NetworkType GNUNET_NT_scanner_get_type(struct GNUNET_NT_InterfaceScanner *is, const struct sockaddr *addr, socklen_t addrlen)
Returns where the address is located: loopback, LAN or WAN.
struct GNUNET_OS_Process * GNUNET_OS_start_process(enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, struct GNUNET_DISK_PipeHandle *pipe_stderr, const char *filename,...)
Start a process.
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
enum GNUNET_GenericReturnValue GNUNET_OS_process_wait(struct GNUNET_OS_Process *proc)
Wait for a process to terminate.
@ GNUNET_OS_INHERIT_STD_OUT_AND_ERR
When these flags are set, the child process will inherit stdout and stderr of the parent.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
#define GNUNET_TIME_UNIT_MICROSECONDS
One microsecond, our basic time unit.
Information of the connection with peer.
ngtcp2_conn * conn
The QUIC connection.
ngtcp2_ssize conn_closebuflen
The length of conn_closebuf;.
enum GNUNET_NetworkType nt
Which network type does this queue use?
gnutls_session_t session
The gnutls session.
struct Long_Poll_Request * long_poll_head
head pointer of long polling struct queue.
ngtcp2_crypto_conn_ref conn_ref
The structure to get a pointer to ngtcp2_conn.
struct sockaddr * address
Address of the other peer.
int is_initiator
Flag to indicate if we are the initiator of the connection.
nghttp3_conn * h3_conn
The HTTP/3 connection.
struct Long_Poll_Request * long_poll_rear
rear pointer of long polling struct queue.
struct GNUNET_TRANSPORT_QueueHandle * d_qh
handle for default queue with the ch.
size_t d_mtu
MTU we allowed transport for this receiver's default queue.
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct HTTP_Message * msg_queue_rear
rear pointer of message queue.
char * foreign_addr
Address of the receiver in the human-readable format with the COMMUNICATOR_ADDRESS_PREFIX.
struct GNUNET_CONTAINER_MultiHashMap * streams
Information of the stream.
int id_rcvd
Flag to indicate whether we know the PeerIdentity (target) yet.
struct GNUNET_TIME_Absolute timeout
Timeout for this connection.
struct GNUNET_MQ_Handle * d_mq
Default message queue we are providing for the ch.
ngtcp2_ccerr last_error
The connection error.
uint8_t * conn_closebuf
conn_closebuf contains a packet which contains CONNECTION_CLOSE.
size_t long_poll_len
length of long polling struct queue.
struct HTTP_Message * msg_queue_head
head pointer of message queue.
struct HTTP_Message * submitted_msg_queue_head
Messages that have been submitted will be put into this queue.
socklen_t address_len
Length of the address.
int connection_destroy_called
connection_destroy already called on connection.
struct GNUNET_SCHEDULER_Task * timer
The timer of this connection.
int id_sent
Flag to indicate whether we have sent OUR PeerIdentity to this peer.
size_t msg_queue_len
length of message queue.
Internal representation of the hash map.
Private ECC key encoded for transmission.
Definition of a command line option.
Handle to a message queue.
Handle for active NAT registrations.
Handle to the interface scanner.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Entry in list of pending tasks.
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.
Internal representation of an address a communicator is currently providing for the transport service...
Opaque handle to the transport service for communicators.
Handle returned to identify the internal data structure the transport API has created to manage a mes...
Message to send using http.
char * buf
buffer containing data to send
struct HTTP_Message * next
next pointer for double linked list
uint64_t delay_time
Timeout value.
struct Long_Poll_Request * prev
Previous structure.
struct Long_Poll_Request * next
Next structure.
struct Stream * stream
The long polling stream.
struct GNUNET_SCHEDULER_Task * timer
Timeout timer for long polling stream.
size_t urilen
The length of request uri.
struct Connection * connection
The connection that stream belongs to.
size_t authoritylen
The length of request authority.
uint8_t * uri
The request uri.
uint8_t * method
The request method.
uint8_t * data
The stream data.
uint64_t datalen
The length of stream data.
int64_t stream_id
ID of this stream.
size_t methodlen
The length of request method.
uint8_t * authority
The request authority.
struct Long_Poll_Request * long_poll_struct
The long polling request structure.