GNUnet 0.22.2
gnunet-communicator-quic.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet
3 Copyright (C) 2010-2014, 2018, 2019 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
37#include "gnunet_common.h"
38#include "gnunet_util_lib.h"
39#include "quiche.h"
40#include "platform.h"
41#include "gnunet_constants.h"
45#include "gnunet_nat_service.h"
46#include "stdint.h"
47#include "inttypes.h"
48
49#define COMMUNICATOR_CONFIG_SECTION "communicator-quic"
50#define COMMUNICATOR_ADDRESS_PREFIX "quic"
51#define MAX_DATAGRAM_SIZE 1350
52
53
54/* FIXME: Review all static lengths/contents below. Maybe this can be done smarter */
55/* Currently equivalent to QUICHE_MAX_CONN_ID_LEN */
56#define LOCAL_CONN_ID_LEN 20
57#define MAX_TOKEN_LEN \
58 sizeof("quiche") - 1 \
59 + sizeof(struct sockaddr_storage) \
60 + QUICHE_MAX_CONN_ID_LEN
61#define CID_LEN sizeof(uint8_t) * QUICHE_MAX_CONN_ID_LEN
62#define TOKEN_LEN sizeof (uint8_t) * MAX_TOKEN_LEN
63
64
65/* FIXME: Why 4?
66 Generic, bidirectional, client-initiated quic stream id */
67#define STREAMID_BI 4
68
73#define ADDRESS_VALIDITY_PERIOD GNUNET_TIME_UNIT_HOURS
74
79
84
88static const struct GNUNET_CONFIGURATION_Handle *cfg;
89
94
99
104
109
113static int have_v6_socket;
114
118static uint16_t my_port;
119
123static quiche_config *config = NULL;
124
129
134
138static struct GNUNET_NAT_Handle *nat;
139
149{
154
159
164
169
175
179 struct sockaddr *address;
180
184 socklen_t address_len;
185
190
195
200
205
210 size_t d_mtu;
211
216
221
226 // struct GNUNET_CONTAINER_HeapNode *hn;
227};
228
229// /**
230// * FIXME: Implementation missing
231// * Expiration heap for peers (contains `struct PeerAddress`)
232// */
233// static struct GNUNET_CONTAINER_Heap *peers_heap;
234
239
244
249
256{
258
259 quiche_conn *conn;
260};
261
266{
267 uint8_t type;
268 uint32_t version;
269
270 uint8_t scid[QUICHE_MAX_CONN_ID_LEN];
271 size_t scid_len;
272
273 uint8_t dcid[QUICHE_MAX_CONN_ID_LEN];
274 size_t dcid_len;
275
276 uint8_t odcid[QUICHE_MAX_CONN_ID_LEN];
277 size_t odcid_len;
278
280 size_t token_len;
281};
282
283
288static void
290{
291 char stream_buf[UINT16_MAX];
292 size_t buf_size = UINT16_MAX;
293 char *buf_ptr = stream_buf;
294 struct GNUNET_MessageHeader *hdr;
295
296 uint64_t s = 0;
297 quiche_stream_iter *readable;
298 bool fin;
299 uint64_t err_code;
300 ssize_t recv_len;
301
302 readable = quiche_conn_readable (peer->conn->conn);
303 while (quiche_stream_iter_next (readable, &s))
304 {
305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "stream %" PRIu64 " is readable\n",
306 s);
307 fin = false;
308 recv_len = quiche_conn_stream_recv (peer->conn->conn, s,
309 (uint8_t *) stream_buf, buf_size,
310 &fin, &err_code);
311 if (recv_len < 0)
312 {
314 "error while receiving data from stream %" PRIu64
315 "; error_code %" PRIu64 "\n",
316 s, err_code);
317 break;
318 }
325 if (! peer->is_receiver && GNUNET_NO == peer->id_rcvd)
326 {
327 if (recv_len < sizeof(struct GNUNET_PeerIdentity))
328 {
330 "message recv len of %zd less than length of peer identity\n",
331 recv_len);
332 return;
333 }
335 "received peer identity\n");
336 struct GNUNET_PeerIdentity *pid = (struct
337 GNUNET_PeerIdentity *) stream_buf;
338 peer->target = *pid;
339 peer->id_rcvd = GNUNET_YES;
340 buf_ptr += sizeof(struct GNUNET_PeerIdentity);
341 recv_len -= sizeof(struct GNUNET_PeerIdentity);
342 }
346 while (recv_len >= sizeof(struct GNUNET_MessageHeader))
347 {
348 hdr = (struct GNUNET_MessageHeader *) buf_ptr;
349 if (ntohs (hdr->size) > recv_len)
350 {
352 "message size stated (%d) is greater than length of rcvd data (%zd)!\n",
353 ntohs (hdr->size), recv_len);
354 return;
355 }
356 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "passing %zd bytes to core\n",
357 recv_len);
360 NULL);
361 recv_len -= ntohs (hdr->size);
362 buf_ptr += ntohs (hdr->size);
363 }
367 if (0 != recv_len)
368 {
370 "message recv len of %zd less than length of message header\n",
371 recv_len);
372 }
377 if (fin)
378 {
380 "fin received, closing connection\n");
381 if (0 > quiche_conn_close (peer->conn->conn, true, 0, NULL, 0))
382 {
384 "quiche failed to close connection to peer\n");
385 }
386 }
387 }
388 quiche_stream_iter_free (readable);
389}
390
391
395static void
396mint_token (const uint8_t *dcid, size_t dcid_len,
397 struct sockaddr_storage *addr, socklen_t addr_len,
398 uint8_t *token, size_t *token_len)
399{
400 GNUNET_memcpy (token, "quiche", sizeof("quiche") - 1);
401 GNUNET_memcpy (token + sizeof("quiche") - 1, addr, addr_len);
402 GNUNET_memcpy (token + sizeof("quiche") - 1 + addr_len, dcid, dcid_len);
403
404 *token_len = sizeof("quiche") - 1 + addr_len + dcid_len;
405}
406
407
409validate_token (const uint8_t *token, size_t token_len,
410 struct sockaddr_storage *addr, socklen_t addr_len,
411 uint8_t *odcid, size_t *odcid_len)
412{
413 if ((token_len < sizeof("quiche") - 1) ||
414 memcmp (token, "quiche", sizeof("quiche") - 1))
415 {
416 return GNUNET_NO;
417 }
418
419 token += sizeof("quiche") - 1;
420 token_len -= sizeof("quiche") - 1;
421
422 if ((token_len < addr_len) || memcmp (token, addr, addr_len))
423 {
424 return GNUNET_NO;
425 }
426
427 token += addr_len;
428 token_len -= addr_len;
429
430 if (*odcid_len < token_len)
431 {
432 return GNUNET_NO;
433 }
434
435 memcpy (odcid, token, token_len);
436 *odcid_len = token_len;
437
438 return GNUNET_OK;
439}
440
441
442static struct quic_conn*
443create_conn (uint8_t *scid, size_t scid_len,
444 uint8_t *odcid, size_t odcid_len,
445 struct sockaddr *local_addr,
446 socklen_t local_addr_len,
447 struct sockaddr_storage *peer_addr,
448 socklen_t peer_addr_len)
449{
450 struct quic_conn *conn;
451 quiche_conn *q_conn;
452 conn = GNUNET_new (struct quic_conn);
453 if (scid_len != LOCAL_CONN_ID_LEN)
454 {
456 "error while creating connection, scid length too short: %zu\n",
457 scid_len);
458 return NULL;
459 }
460
462 q_conn = quiche_accept (conn->cid, LOCAL_CONN_ID_LEN,
463 odcid, odcid_len,
465 local_addr_len,
466 (struct sockaddr *) peer_addr,
467 peer_addr_len,
468 config);
469 if (NULL == q_conn)
470 {
472 "quiche failed to create connection after call to quiche_accept\n");
473 return NULL;
474 }
475 conn->conn = q_conn;
476 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "new quic connection created\n");
477 return conn;
478}
479
480
481static void
483{
484 static uint8_t out[MAX_DATAGRAM_SIZE];
485 quiche_send_info send_info;
486
487 ssize_t written;
488 ssize_t sent;
489
490 while (1)
491 {
492 written = quiche_conn_send (conn->conn, out, sizeof(out), &send_info);
493 if (QUICHE_ERR_DONE == written)
494 {
495 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "done writing quic packets\n");
496 break;
497 }
498 if (0 > written)
499 {
501 "quiche failed to create packet. quiche error: %zd\n",
502 written);
503 return;
504 }
505 sent = GNUNET_NETWORK_socket_sendto (udp_sock, out, written,
506 (struct sockaddr *) &send_info.to,
507 send_info.to_len);
508 if (sent != written)
509 {
511 "quiche failed to send data to peer\n");
512 return;
513 }
514 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sent %zd bytes\n", sent);
515 }
516}
517
518
524static void
526{
527 peer->timeout =
529 // GNUNET_CONTAINER_heap_update_cost (peer->hn,
530 // peer->timeout.abs_value_us);
531}
532
533
539static void
541{
542 struct GNUNET_HashCode addr_key;
543
546 "Disconnecting peer for peer `%s'\n",
547 GNUNET_i2s (&peer->target));
548 if (NULL != peer->d_qh)
549 {
551 peer->d_qh = NULL;
552 }
553 // GNUNET_assert (peer == GNUNET_CONTAINER_heap_remove_node (peer->hn));
557 GNUNET_CRYPTO_hash (peer->address, peer->address_len, &addr_key);
559 peer))
560 {
562 "tried to remove non-existent peer from addr map\n");
563 return;
564 }
566 "# peers active",
568 GNUNET_NO);
569 quiche_conn_free (peer->conn->conn);
570 GNUNET_free (peer->address);
572 GNUNET_free (peer->conn);
573 GNUNET_free (peer);
574}
575
576
585static int
587 const struct GNUNET_HashCode *key,
588 void *value)
589{
590 struct PeerAddress *peer = value;
591 (void) cls;
592 (void) key;
593 peer_destroy (peer);
594 return GNUNET_OK;
595}
596
597
606static void
608 const struct GNUNET_MessageHeader *msg,
609 void *impl_state)
610{
611 struct PeerAddress *peer = impl_state;
612 uint16_t msize = ntohs (msg->size);
613 ssize_t send_len;
614 uint64_t err_code;
615
616 if (NULL == peer->conn->conn)
617 {
619 "peer never established quic connection\n");
620 return;
621 }
622
623 GNUNET_assert (mq == peer->d_mq);
624 if (msize > peer->d_mtu)
625 {
627 "msize: %u, mtu: %lu\n",
628 msize,
629 peer->d_mtu);
630 GNUNET_break (0);
631 if (GNUNET_YES != peer->peer_destroy_called)
632 {
634 "peer destroy called, destroying peer\n");
635 peer_destroy (peer);
636 }
637 return;
638 }
640
641 send_len = quiche_conn_stream_send (peer->conn->conn, 4, (uint8_t *) msg,
642 msize, false, &err_code);
643 if (send_len != msize)
644 {
646 "tried to send message and quiche returned %zd; error_code %"
647 PRIu64,
648 send_len, err_code);
649 return;
650 }
651 flush_egress (peer->conn);
653 "sent a message of %zd bytes\n", send_len);
655}
656
657
666static void
667mq_destroy_d (struct GNUNET_MQ_Handle *mq, void *impl_state)
668{
669 struct PeerAddress *peer = impl_state;
671 "Default MQ destroyed\n");
672 if (mq == peer->d_mq)
673 {
674 peer->d_mq = NULL;
675 if (GNUNET_YES != peer->peer_destroy_called)
676 peer_destroy (peer);
677 }
678}
679
680
687static void
688mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
689{
690 /* Cancellation is impossible with QUIC; bail */
691 GNUNET_assert (0);
692}
693
694
704static void
705mq_error (void *cls, enum GNUNET_MQ_Error error)
706{
707 struct PeerAddress *peer = cls;
708
710 "MQ error in queue to %s: %d\n",
711 GNUNET_i2s (&peer->target),
712 (int) error);
713 peer_destroy (peer);
714}
715
716
724static struct sockaddr *
725udp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
726{
727 struct sockaddr *in;
728 unsigned int port;
729 char dummy[2];
730 char *colon;
731 char *cp;
732
733 if (1 == sscanf (bindto, "%u%1s", &port, dummy))
734 {
735 /* interpreting value as just a PORT number */
736 if (port > UINT16_MAX)
737 {
739 "BINDTO specification `%s' invalid: value too large for port\n",
740 bindto);
741 return NULL;
742 }
743 if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
744 (GNUNET_YES ==
747 "DISABLE_V6")))
748 {
749 struct sockaddr_in *i4;
750
751 i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
752 i4->sin_family = AF_INET;
753 i4->sin_port = htons ((uint16_t) port);
754 *sock_len = sizeof(struct sockaddr_in);
755 in = (struct sockaddr *) i4;
756 }
757 else
758 {
759 struct sockaddr_in6 *i6;
760
761 i6 = GNUNET_malloc (sizeof(struct sockaddr_in6));
762 i6->sin6_family = AF_INET6;
763 i6->sin6_port = htons ((uint16_t) port);
764 *sock_len = sizeof(struct sockaddr_in6);
765 in = (struct sockaddr *) i6;
766 }
767 return in;
768 }
769 cp = GNUNET_strdup (bindto);
770 colon = strrchr (cp, ':');
771 if (NULL != colon)
772 {
773 /* interpret value after colon as port */
774 *colon = '\0';
775 colon++;
776 if (1 == sscanf (colon, "%u%1s", &port, dummy))
777 {
778 /* interpreting value as just a PORT number */
779 if (port > UINT16_MAX)
780 {
782 "BINDTO specification `%s' invalid: value too large for port\n",
783 bindto);
784 GNUNET_free (cp);
785 return NULL;
786 }
787 }
788 else
789 {
790 GNUNET_log (
792 "BINDTO specification `%s' invalid: last ':' not followed by number\n",
793 bindto);
794 GNUNET_free (cp);
795 return NULL;
796 }
797 }
798 else
799 {
800 /* interpret missing port as 0, aka pick any free one */
801 port = 0;
802 }
803 {
804 /* try IPv4 */
805 struct sockaddr_in v4;
806
807 memset (&v4, 0, sizeof(v4));
808 if (1 == inet_pton (AF_INET, cp, &v4.sin_addr))
809 {
810 v4.sin_family = AF_INET;
811 v4.sin_port = htons ((uint16_t) port);
812#if HAVE_SOCKADDR_IN_SIN_LEN
813 v4.sin_len = sizeof(struct sockaddr_in);
814#endif
815 in = GNUNET_memdup (&v4, sizeof(struct sockaddr_in));
816 *sock_len = sizeof(struct sockaddr_in);
817 GNUNET_free (cp);
818 return in;
819 }
820 }
821 {
822 /* try IPv6 */
823 struct sockaddr_in6 v6;
824 const char *start;
825
826 memset (&v6, 0, sizeof(v6));
827 start = cp;
828 if (('[' == *cp) && (']' == cp[strlen (cp) - 1]))
829 {
830 start++; /* skip over '[' */
831 cp[strlen (cp) - 1] = '\0'; /* eat ']' */
832 }
833 if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
834 {
835 v6.sin6_family = AF_INET6;
836 v6.sin6_port = htons ((uint16_t) port);
837#if HAVE_SOCKADDR_IN_SIN_LEN
838 v6.sin6_len = sizeof(sizeof(struct sockaddr_in6));
839#endif
840 in = GNUNET_memdup (&v6, sizeof(v6));
841 *sock_len = sizeof(v6);
842 GNUNET_free (cp);
843 return in;
844 }
845 }
846 /* #5528 FIXME (feature!): maybe also try getnameinfo()? */
847 GNUNET_free (cp);
848 return NULL;
849}
850
851
859static void
861{
862 size_t base_mtu;
863
864 switch (peer->address->sa_family)
865 {
866 case AF_INET:
867 base_mtu = 1480 /* Ethernet MTU, 1500 - Ethernet header - VLAN tag */
868 - sizeof(struct GNUNET_TUN_IPv4Header) /* 20 */
869 - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */;
870 break;
871
872 case AF_INET6:
873 base_mtu = 1280 /* Minimum MTU required by IPv6 */
874 - sizeof(struct GNUNET_TUN_IPv6Header) /* 40 */
875 - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */;
876 break;
877
878 default:
879 GNUNET_assert (0);
880 break;
881 }
882 /* MTU == base_mtu */
883 peer->d_mtu = base_mtu;
884
886 "Setting up MQs and QHs\n");
887 /* => Effective MTU for CORE will range from 1080 (IPv6 + KX) to
888 1404 (IPv4 + Box) bytes, depending on circumstances... */
889
890 if (NULL == peer->d_mq)
893 &mq_cancel,
894 peer,
895 NULL,
896 &mq_error,
897 peer);
898 peer->d_qh =
900 &peer->target,
901 peer->foreign_addr,
902 1000,
904 0, /* Priority */
905 peer->nt,
907 peer->d_mq);
908}
909
910
920static char *
921sockaddr_to_udpaddr_string (const struct sockaddr *address,
922 socklen_t address_len)
923{
924 char *ret;
925
926 switch (address->sa_family)
927 {
928 case AF_INET:
930 "%s-%s",
932 GNUNET_a2s (address, address_len));
933 break;
934
935 case AF_INET6:
937 "%s-%s",
939 GNUNET_a2s (address, address_len));
940 break;
941
942 default:
943 GNUNET_assert (0);
944 }
945 return ret;
946}
947
948
958static void
959notify_cb (void *cls,
960 const struct GNUNET_PeerIdentity *sender,
961 const struct GNUNET_MessageHeader *msg)
962{
963 // const struct UDPAck *ack;
964
965 // (void) cls;
966 // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
967 // "Storing UDPAck received from backchannel from %s\n",
968 // GNUNET_i2s_full (sender));
969 // if ((ntohs (msg->type) != GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK) ||
970 // (ntohs (msg->size) != sizeof(struct UDPAck)))
971 // {
972 // GNUNET_break_op (0);
973 // return;
974 // }
975 // ack = (const struct UDPAck *) msg;
976 // GNUNET_CONTAINER_multipeermap_get_multiple (receivers,
977 // sender,
978 // &handle_ack,
979 // (void *) ack);
980}
981
982
1001static int
1002mq_init (void *cls, const struct GNUNET_PeerIdentity *peer_id, const
1003 char *address)
1004{
1005 struct PeerAddress *peer;
1006 const char *path;
1007 struct sockaddr *in;
1008 socklen_t in_len;
1009 struct GNUNET_HashCode addr_key;
1010 uint8_t scid[LOCAL_CONN_ID_LEN];
1011
1012 struct quic_conn *q_conn;
1013 char *bindto;
1014 socklen_t local_in_len;
1015 struct sockaddr *local_addr;
1016
1017 if (GNUNET_OK !=
1020 "BINDTO",
1021 &bindto))
1022 {
1025 "BINDTO");
1026 return GNUNET_SYSERR;
1027 }
1028 local_addr = udp_address_to_sockaddr (bindto, &local_in_len);
1029
1030 if (0 != strncmp (address,
1032 strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
1033 {
1034 GNUNET_break_op (0);
1035 return GNUNET_SYSERR;
1036 }
1037 path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
1038 in = udp_address_to_sockaddr (path, &in_len);
1039 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mq_init in_len length before: %d\n",
1040 in_len);
1044 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "address string in mq_init: %s\n",
1045 address);
1046 GNUNET_CRYPTO_hash (address, strlen (address), &addr_key);
1047 peer = GNUNET_CONTAINER_multihashmap_get (addr_map, &addr_key);
1048 if (NULL != peer)
1049 {
1051 "ignoring transport service mq request, we already have an mq with this peer (address)\n");
1052 return GNUNET_SYSERR;
1053 }
1054 peer = GNUNET_new (struct PeerAddress);
1055 peer->address = in;
1056 peer->address_len = in_len;
1057 peer->target = *peer_id;
1058 peer->id_rcvd = GNUNET_YES;
1059 peer->is_receiver = GNUNET_YES;
1060 peer->nt = GNUNET_NT_scanner_get_type (is, in, in_len);
1061 peer->timeout =
1064 "# peers active",
1066 GNUNET_NO);
1067 peer->foreign_addr =
1073 peer,
1076 "mq_init added new peer to the addr map\n");
1082 q_conn = GNUNET_new (struct quic_conn);
1083 GNUNET_memcpy (q_conn->cid, scid, LOCAL_CONN_ID_LEN);
1084 peer->conn = q_conn;
1086 "attempting to perform QUIC handshake with peer\n");
1087 q_conn->conn = quiche_connect (peer->foreign_addr, scid, LOCAL_CONN_ID_LEN,
1088 local_addr,
1089 local_in_len, peer->address, peer->address_len,
1090 config);
1091 flush_egress (peer->conn);
1093 return GNUNET_OK;
1097 // if (NULL == timeout_task)
1098 // timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts, NULL);
1099}
1100
1101
1102static void
1104 const struct sockaddr *addr,
1105 socklen_t addrlen)
1106{
1107 /* FIXME: support reversal: #5529 */
1109 "No connection reversal implemented!");
1110}
1111
1112
1126static void
1128 void **app_ctx,
1129 int add_remove,
1131 const struct sockaddr *addr,
1132 socklen_t addrlen)
1133{
1134 char *my_addr;
1136
1137 if (GNUNET_YES == add_remove)
1138 {
1140
1141 GNUNET_asprintf (&my_addr,
1142 "%s-%s",
1144 GNUNET_a2s (addr, addrlen));
1145 nt = GNUNET_NT_scanner_get_type (is, addr, addrlen);
1146 ai =
1148 my_addr,
1149 nt,
1151 GNUNET_free (my_addr);
1152 *app_ctx = ai;
1153 }
1154 else
1155 {
1156 ai = *app_ctx;
1158 *app_ctx = NULL;
1159 }
1160}
1161
1162
1168static void
1169do_shutdown (void *cls)
1170{
1172 "do_shutdown\n");
1175 quiche_config_free (config);
1176
1177 if (NULL != timeout_task)
1178 {
1180 timeout_task = NULL;
1181 }
1182 if (NULL != read_task)
1183 {
1185 read_task = NULL;
1186 }
1187 if (NULL != udp_sock)
1188 {
1191 udp_sock = NULL;
1192 }
1193 if (NULL != ch)
1194 {
1196 ch = NULL;
1197 }
1198 if (NULL != ah)
1199 {
1201 ah = NULL;
1202 }
1203 if (NULL != my_private_key)
1204 {
1206 my_private_key = NULL;
1207 }
1209 "do_shutdown finished\n");
1210}
1211
1212
1213static void
1214sock_read (void *cls)
1215{
1216 struct sockaddr_storage sa;
1217 socklen_t salen = sizeof(sa);
1218 uint8_t buf[UINT16_MAX];
1219 uint8_t out[MAX_DATAGRAM_SIZE];
1220 ssize_t rcvd;
1221
1222 ssize_t process_pkt;
1223 struct QUIC_header quic_header;
1224
1225 struct PeerAddress *peer;
1226 struct GNUNET_HashCode addr_key;
1227
1228 (void) cls;
1229 quic_header.scid_len = sizeof(quic_header.scid);
1230 quic_header.dcid_len = sizeof(quic_header.dcid);
1231 quic_header.odcid_len = sizeof(quic_header.odcid);
1232 quic_header.token_len = sizeof(quic_header.token);
1236 char *bindto;
1237 socklen_t in_len;
1238 if (GNUNET_OK !=
1241 "BINDTO",
1242 &bindto))
1243 {
1246 "BINDTO");
1247 return;
1248 }
1249 struct sockaddr *local_addr = udp_address_to_sockaddr (bindto, &in_len);
1250
1252 udp_sock,
1253 &sock_read,
1254 NULL);
1255 while (1)
1256 {
1258 buf,
1259 sizeof(buf),
1260 (struct sockaddr *) &sa,
1261 &salen);
1262 if (-1 == rcvd)
1263 {
1264 if (EAGAIN == errno)
1265 break; // We are done reading data
1267 return;
1268 }
1269
1271 "Read %lu bytes\n", rcvd);
1272
1273 if (-1 == rcvd)
1274 {
1276 return;
1277 }
1285 char *addr_string = sockaddr_to_udpaddr_string ((const struct
1286 sockaddr *) &sa,
1287 salen);
1288 GNUNET_CRYPTO_hash (addr_string, strlen (addr_string),
1289 &addr_key);
1290 GNUNET_free (addr_string);
1291 peer = GNUNET_CONTAINER_multihashmap_get (addr_map, &addr_key);
1292
1293 if (NULL == peer)
1294 {
1298 peer = GNUNET_new (struct PeerAddress);
1299 peer->address = GNUNET_memdup (&sa, salen);
1300 peer->address_len = salen;
1301 peer->id_rcvd = GNUNET_NO;
1302 peer->id_sent = GNUNET_NO;
1303 peer->is_receiver = GNUNET_NO;
1304 peer->conn = NULL;
1306 peer->address_len);
1310 // setup_peer_mq (peer);
1312 &addr_key,
1313 peer,
1315 {
1317 "tried to add duplicate address into address map\n");
1318 return;
1319 }
1321 "sock_read added new peer to address map\n");
1322 }
1323
1327 int rc = quiche_header_info (buf, rcvd, LOCAL_CONN_ID_LEN,
1328 &quic_header.version,
1329 &quic_header.type, quic_header.scid,
1330 &quic_header.scid_len, quic_header.dcid,
1331 &quic_header.dcid_len,
1332 quic_header.token, &quic_header.token_len);
1333 if (0 > rc)
1334 {
1336 "failed to parse quic header: %d\n",
1337 rc);
1338 return;
1339 }
1340
1344 if (NULL == peer->conn)
1345 {
1347 "attempting to create new connection\n");
1348 if (0 == quiche_version_is_supported (quic_header.version))
1349 {
1351 "quic version negotiation initiated\n");
1359 ssize_t written = quiche_negotiate_version (quic_header.scid,
1360 quic_header.scid_len,
1361 quic_header.dcid,
1362 quic_header.dcid_len,
1363 out, sizeof(out));
1364 if (0 > written)
1365 {
1367 "quiche failed to generate version negotiation packet\n");
1368 return;
1369 }
1370 ssize_t sent = GNUNET_NETWORK_socket_sendto (udp_sock,
1371 out,
1372 written,
1373 (struct sockaddr*) &sa,
1374 salen);
1375 if (sent != written)
1376 {
1378 "failed to send version negotiation packet to peer\n");
1379 return;
1380 }
1382 "sent %zd bytes to peer during version negotiation\n",
1383 sent);
1384 return;
1385 }
1386
1387 if (0 == quic_header.token_len)
1388 {
1389 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "quic stateless retry\n");
1390 mint_token (quic_header.dcid, quic_header.dcid_len, &sa, salen,
1391 quic_header.token, &quic_header.token_len);
1392
1393 uint8_t new_cid[LOCAL_CONN_ID_LEN];
1396
1397 ssize_t written = quiche_retry (quic_header.scid, quic_header.scid_len,
1398 quic_header.dcid, quic_header.dcid_len,
1399 new_cid, LOCAL_CONN_ID_LEN,
1400 quic_header.token,
1401 quic_header.token_len,
1402 quic_header.version, out, sizeof(out));
1403 if (0 > written)
1404 {
1406 "quiche failed to write retry packet\n");
1407 return;
1408 }
1409 ssize_t sent = GNUNET_NETWORK_socket_sendto (udp_sock,
1410 out,
1411 written,
1412 (struct sockaddr*) &sa,
1413 salen);
1414 if (written != sent)
1415 {
1416 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "failed to send retry packet\n");
1417 return;
1418 }
1419
1420 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sent %zd bytes\n", sent);
1421 continue;
1422 }
1423
1424 if (GNUNET_OK != validate_token (quic_header.token, quic_header.token_len,
1425 &sa, salen,
1426 quic_header.odcid,
1427 &quic_header.odcid_len))
1428 {
1430 "invalid address validation token created\n");
1431 return;
1432 }
1433 peer->conn = create_conn (quic_header.dcid, quic_header.dcid_len,
1434 quic_header.odcid, quic_header.odcid_len,
1435 local_addr, in_len,
1436 &sa, salen);
1437 if (NULL == peer->conn)
1438 {
1440 "failed to create quic connection with peer\n");
1441 return;
1442 }
1443 } // null connection
1444
1445 quiche_recv_info recv_info = {
1446 (struct sockaddr *) &sa,
1447 salen,
1448
1449 local_addr,
1450 in_len,
1451 };
1455 if (quiche_conn_is_established (peer->conn->conn) && ! peer->id_sent &&
1456 peer->is_receiver)
1457 {
1458 ssize_t send_len;
1459 uint64_t err_code;
1460
1462 "handshake established with peer, sending our peer id\n");
1463 send_len = quiche_conn_stream_send (peer->conn->conn, STREAMID_BI,
1464 (const uint8_t *) &my_identity,
1465 sizeof(my_identity),
1466 false, &err_code);
1467 if (0 > send_len)
1468 {
1470 "failed to write peer identity packet. quiche error: %"
1471 PRIu64 "; len=%zd\n",
1472 err_code,
1473 send_len);
1474 return;
1475 }
1476 flush_egress (peer->conn);
1477 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "peer identity sent to peer\n");
1478 peer->id_sent = GNUNET_YES;
1479 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "setting up peer mq\n");
1480 setup_peer_mq (peer);
1484 }
1485 process_pkt = quiche_conn_recv (peer->conn->conn, buf, rcvd, &recv_info);
1486 if (0 > process_pkt)
1487 {
1489 "quiche failed to process received packet: %zd\n",
1490 process_pkt);
1491 return;
1492 }
1494 "quiche processed %zd bytes\n", process_pkt);
1495 // Check for data on all available streams if the connection is established
1496 if (GNUNET_YES == quiche_conn_is_established (peer->conn->conn))
1497 {
1498 recv_from_streams (peer);
1499 }
1506 quiche_stats stats;
1507 quiche_path_stats path_stats;
1508
1509 flush_egress (peer->conn);
1510
1511 if (quiche_conn_is_closed (peer->conn->conn))
1512 {
1513 quiche_conn_stats (peer->conn->conn, &stats);
1514 quiche_conn_path_stats (peer->conn->conn, 0, &path_stats);
1515
1517 "connection closed. quiche stats: sent=%zu, recv=%zu\n",
1518 stats.sent, stats.recv);
1519 peer_destroy (peer);
1520 }
1521 }
1523}
1524
1525
1534static void
1535run (void *cls,
1536 char *const *args,
1537 const char *cfgfile,
1538 const struct GNUNET_CONFIGURATION_Handle *c)
1539{
1540 char *bindto;
1541 struct sockaddr *in;
1542 socklen_t in_len;
1543 struct sockaddr_storage in_sto;
1544 socklen_t sto_len;
1545
1546 (void) cls;
1547 cfg = c;
1548
1549 if (GNUNET_OK !=
1552 "BINDTO",
1553 &bindto))
1554 {
1557 "BINDTO");
1558 return;
1559 }
1560
1561 in = udp_address_to_sockaddr (bindto, &in_len);
1562
1563 if (NULL == in)
1564 {
1566 "Failed to setup UDP socket address with path `%s'\n",
1567 bindto);
1568 GNUNET_free (bindto);
1569 return;
1570 }
1571 udp_sock =
1572 GNUNET_NETWORK_socket_create (in->sa_family,
1573 SOCK_DGRAM,
1574 IPPROTO_UDP);
1575 if (NULL == udp_sock)
1576 {
1578 GNUNET_free (in);
1579 GNUNET_free (bindto);
1580 return;
1581 }
1582 if (AF_INET6 == in->sa_family)
1584 if (GNUNET_OK !=
1586 in,
1587 in_len))
1588 {
1590 "bind",
1591 bindto);
1593 udp_sock = NULL;
1594 GNUNET_free (in);
1595 GNUNET_free (bindto);
1596 return;
1597 }
1598 sto_len = sizeof(in_sto);
1599 if (0 != getsockname (GNUNET_NETWORK_get_fd (udp_sock),
1600 (struct sockaddr *) &in_sto,
1601 &sto_len))
1602 {
1603 memcpy (&in_sto, in, in_len);
1604 sto_len = in_len;
1605 }
1606 GNUNET_free (in);
1607 GNUNET_free (bindto);
1608 in = (struct sockaddr *) &in_sto;
1609 in_len = sto_len;
1611 "transport",
1612 "Bound to `%s'\n",
1613 GNUNET_a2s ((const struct sockaddr *) &in_sto,
1614 sto_len));
1615 switch (in->sa_family)
1616 {
1617 case AF_INET:
1618 my_port = ntohs (((struct sockaddr_in *) in)->sin_port);
1619 break;
1620
1621 case AF_INET6:
1622 my_port = ntohs (((struct sockaddr_in6 *) in)->sin6_port);
1623 break;
1624
1625 default:
1626 GNUNET_break (0);
1627 my_port = 0;
1628 }
1633 config = quiche_config_new (QUICHE_PROTOCOL_VERSION);
1634 quiche_config_verify_peer (config, false);
1638 quiche_config_load_cert_chain_from_pem_file (config, "./cert.crt");
1639 quiche_config_load_priv_key_from_pem_file (config, "./cert.key");
1640 quiche_config_set_application_protos (config,
1641 (uint8_t *)
1642 "\x0ahq-interop\x05hq-29\x05hq-28\x05hq-27\x08http/0.9",
1643 38);
1644 quiche_config_set_max_idle_timeout (config, 5000);
1645 quiche_config_set_max_recv_udp_payload_size (config, 1200);
1646 quiche_config_set_max_send_udp_payload_size (config, 1200);
1647 quiche_config_set_initial_max_data (config, 10000000);
1648 quiche_config_set_initial_max_stream_data_bidi_local (config, 1000000);
1649 quiche_config_set_initial_max_stream_data_bidi_remote (config, 1000000);
1650 quiche_config_set_initial_max_stream_data_uni (config, 1000000);
1651 quiche_config_set_initial_max_streams_bidi (config, 100);
1652 quiche_config_set_initial_max_streams_uni (config, 100);
1653 quiche_config_set_cc_algorithm (config, QUICHE_CC_RENO);
1654 quiche_config_set_disable_active_migration (config, true);
1660 if (NULL == my_private_key)
1661 {
1662 GNUNET_log (
1664 _ (
1665 "Transport service is lacking key configuration settings. Exiting.\n"));
1667 return;
1668 }
1670 /* start reading */
1672 udp_sock,
1673 &sock_read,
1674 NULL);
1679 &mq_init,
1680 NULL,
1681 &notify_cb,
1682 NULL,
1683 NULL);
1687 IPPROTO_UDP,
1688 1 /* one address */,
1689 (const struct sockaddr **) &in,
1690 &in_len,
1693 NULL /* closure */);
1694 if (NULL == ch)
1695 {
1696 GNUNET_break (0);
1698 return;
1699 }
1701 if (NULL == ah)
1702 {
1703 GNUNET_break (0);
1705 return;
1706 }
1707
1708 /* start broadcasting */
1709 // if (GNUNET_YES !=
1710 // GNUNET_CONFIGURATION_get_value_yesno (cfg,
1711 // COMMUNICATOR_CONFIG_SECTION,
1712 // "DISABLE_BROADCAST"))
1713 // {
1714 // broadcast_task = GNUNET_SCHEDULER_add_now (&do_broadcast, NULL);
1715 // }
1716}
1717
1718
1719int
1720main (int argc, char *const *argv)
1721{
1722 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1724 };
1725 int ret;
1726
1728 "transport",
1729 "Starting quic communicator\n");
1730 ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc,
1731 argv,
1732 "gnunet-communicator-quic",
1733 _ ("GNUnet QUIC communicator"),
1734 options,
1735 &run,
1736 NULL))
1737 ? 0
1738 : 1;
1739 return ret;
1740}
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:38
static int ret
Final status code.
Definition: gnunet-arm.c:93
static uint16_t port
Port number.
Definition: gnunet-bcd.c:146
static char * peer_id
Option –peer.
Definition: gnunet-cadet.c:42
static void mq_destroy_d(struct GNUNET_MQ_Handle *mq, void *impl_state)
Signature of functions implementing the destruction of a message queue.
struct GNUNET_PeerIdentity my_identity
Our peer identity.
#define COMMUNICATOR_ADDRESS_PREFIX
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 (...
#define ADDRESS_VALIDITY_PERIOD
How long do we believe our addresses to remain up (before the other peer should revalidate).
#define MAX_TOKEN_LEN
static enum GNUNET_GenericReturnValue validate_token(const uint8_t *token, size_t token_len, struct sockaddr_storage *addr, socklen_t addr_len, uint8_t *odcid, size_t *odcid_len)
static void try_connection_reversal(void *cls, const struct sockaddr *addr, socklen_t addrlen)
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Handle to the config.
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 void mint_token(const uint8_t *dcid, size_t dcid_len, struct sockaddr_storage *addr, socklen_t addr_len, uint8_t *token, size_t *token_len)
FIXME: review token generation, assure tokens are generated properly.
#define LOCAL_CONN_ID_LEN
static void flush_egress(struct quic_conn *conn)
static struct GNUNET_NETWORK_Handle * udp_sock
FIXME undocumented.
static void peer_destroy(struct PeerAddress *peer)
Destroys a receiving state due to timeout or shutdown.
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)
static void do_shutdown(void *cls)
Shutdown the QUIC communicator.
#define COMMUNICATOR_CONFIG_SECTION
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
FIXME undocumented.
static void reschedule_peer_timeout(struct PeerAddress *peer)
Increment receiver timeout due to activity.
static quiche_config * config
FIXME undocumented.
static struct sockaddr * udp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
Convert UDP bind specification to a struct sockaddr *
struct GNUNET_CONTAINER_MultiHashMap * conn_map
Map of DCID (uint8_t) -> quic_conn for quickly retrieving connections to other peers.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Setup communicator and launch network interactions.
static struct GNUNET_NAT_Handle * nat
Connection to NAT service.
struct GNUNET_CONTAINER_MultiHashMap * addr_map
Map of sockaddr -> struct PeerAddress.
static struct GNUNET_SCHEDULER_Task * read_task
FIXME undocumented.
static int get_peer_delete_it(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator over all peers to clean up.
static void mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state)
Implementation function that cancels the currently sent message.
static struct GNUNET_TRANSPORT_ApplicationHandle * ah
FIXME undocumented.
static int have_v6_socket
FIXME undocumented.
#define STREAMID_BI
static uint16_t my_port
FIXME undocumented.
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 ...
#define MAX_DATAGRAM_SIZE
static void recv_from_streams(struct PeerAddress *peer)
Given a PeerAddress, receive data from streams after doing connection logic.
static struct GNUNET_SCHEDULER_Task * timeout_task
ID of timeout task.
int main(int argc, char *const *argv)
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Our private key.
static void setup_peer_mq(struct PeerAddress *peer)
Setup the MQ for the peer.
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 struct quic_conn * create_conn(uint8_t *scid, size_t scid_len, uint8_t *odcid, size_t odcid_len, struct sockaddr *local_addr, socklen_t local_addr_len, struct sockaddr_storage *peer_addr, socklen_t peer_addr_len)
static struct GNUNET_TRANSPORT_AddressIdentifier * ai
Handle to the operation that publishes our address.
static char * address
GNS address for this phone.
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 * value
Value of the record to add/remove.
static struct GNUNET_NAT_AUTO_Test * nt
Handle to a NAT test operation.
static char * local_addr
Local address to use for connection reversal request.
Definition: gnunet-nat.c:65
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...
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.
void GNUNET_TRANSPORT_application_done(struct GNUNET_TRANSPORT_ApplicationHandle *ch)
Shutdown TRANSPORT application client.
#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_ApplicationHandle * GNUNET_TRANSPORT_application_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the TRANSPORT application client handle.
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_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.
Definition: crypto_ecc.c:201
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.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
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,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#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_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(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.
Definition: mq.c:482
void GNUNET_MQ_impl_send_continue(struct GNUNET_MQ_Handle *mq)
Call the send implementation for the next queued message, if any.
Definition: mq.c:437
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...
Definition: nat_api.c:366
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.
Definition: network.c:508
int GNUNET_NETWORK_get_fd(const struct GNUNET_NETWORK_Handle *desc)
Return file descriptor for this network handle.
Definition: network.c:1001
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).
Definition: network.c:688
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition: network.c:833
enum GNUNET_GenericReturnValue GNUNET_NETWORK_test_pf(int pf)
Test if the given protocol family is supported by this system.
Definition: network.c:79
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.
Definition: network.c:439
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).
Definition: network.c:772
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:44
struct GNUNET_NT_InterfaceScanner * GNUNET_NT_scanner_init(void)
Initialize the address characterization client handle.
Definition: nt.c:407
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.
Definition: nt.c:309
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, 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,...
Definition: program.c:407
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:567
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...
Definition: scheduler.c:1511
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,...
Definition: scheduler.c:1339
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:980
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:316
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
Internal representation of the hash map.
Private ECC key encoded for transmission.
Definition of a command line option.
A 512-bit hashcode.
Handle to a message queue.
Definition: mq.c:87
Header for all communications.
Handle for active NAT registrations.
Definition: nat_api.c:72
handle to a socket
Definition: network.c:53
Handle to the interface scanner.
Definition: nt.c:104
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Entry in list of pending tasks.
Definition: scheduler.c:136
Handle for the service.
Time for absolute times used by GNUnet, in microseconds.
Internal representation of an address a communicator is currently providing for the transport service...
Handle to the TRANSPORT subsystem for application management.
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...
Standard IPv4 header.
Standard IPv6 header.
UDP packet header.
Information we track per peer we have recently been in contact with.
int id_rcvd
Flag to indicate whether we know the PeerIdentity (target) yet.
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct GNUNET_TRANSPORT_QueueHandle * d_qh
handle for default queue with the ch.
struct sockaddr * address
Address of the other peer.
size_t d_mtu
MTU we allowed transport for this peer's default queue.
enum GNUNET_NetworkType nt
Which network type does this queue use?
struct GNUNET_TIME_Absolute timeout
Timeout for this peer address.
struct quic_conn * conn
The QUIC connection associated with this peer.
struct GNUNET_MQ_Handle * d_mq
Default message queue we are providing for the ch.
int id_sent
Flag to indicate whether we have sent OUR PeerIdentity to this peer.
char * foreign_addr
Address of the receiver in the human-readable format with the COMMUNICATOR_ADDRESS_PREFIX.
int peer_destroy_called
receiver_destroy already called on receiver.
socklen_t address_len
Length of the address.
int is_receiver
Flag to indicate if we are the initiator of the connection.
QUIC_header is used to store information received from an incoming QUIC packet.
uint8_t scid[QUICHE_MAX_CONN_ID_LEN]
uint8_t dcid[QUICHE_MAX_CONN_ID_LEN]
uint8_t token[sizeof("quiche") - 1+sizeof(struct sockaddr_storage)+QUICHE_MAX_CONN_ID_LEN]
uint8_t odcid[QUICHE_MAX_CONN_ID_LEN]
QUIC connection object.
quiche_conn * conn