GNUnet debian-0.24.3-23-g589b01d60
gnunet-communicator-libp2p.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet
3 Copyright (C) 2025 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
29#include "platform.h"
30#include "gnunet_common.h"
31#include "gnunet_util_lib.h"
32#include "gnunet_pils_service.h"
33#include "gnunet_core_service.h"
35#include "gnunet_protocols.h"
36#include "gnunet_signatures.h"
37#include "gnunet_constants.h"
38#include "gnunet_nat_service.h"
42
43#include <libp2p/basic/scheduler.hpp>
44#include <libp2p/common/literals.hpp>
45#include <libp2p/injector/host_injector.hpp>
46#include <libp2p/layer/websocket/ws_adaptor.hpp>
47#include <libp2p/log/configurator.hpp>
48#include <libp2p/log/logger.hpp>
49#include <libp2p/protocol/echo.hpp>
50
51
52/* Shorthand for Logging */
53#define LOG(kind, ...) GNUNET_log_from (kind, "communicator-tcp", __VA_ARGS__)
54
55
56
58
59
60
64struct Queue
65{
70
75
80
84 struct sockaddr *address;
85
86};
87
88
89
94{
98 struct Addresses *next;
99
104
108 struct sockaddr *addr;
109
113 socklen_t addr_len;
114
115};
116
117
122
127
132
137
142
147
152
157
161static const struct GNUNET_CONFIGURATION_Handle *cfg;
162
166static struct Addresses *addrs_head;
167
171static struct Addresses *addrs_tail;
172
177
182
190static void
191listen_cb (void *cls);
192
193static void
196{
198 key.type = htonl (GNUNET_PUBLIC_KEY_TYPE_EDDSA);
199 key.eddsa_key = *edpk;
201}
202
203
204static void
207{
209 key.type = htonl (GNUNET_PUBLIC_KEY_TYPE_EDDSA);
210 key.eddsa_key = *edpk;
212}
213
214
222static void
224{
225 struct ListenTask *lt = NULL;
226 struct GNUNET_HashCode h_sock;
227 int sockfd;
228
229 if (NULL != queue->listen_sock)
230 {
231 sockfd = GNUNET_NETWORK_get_fd (queue->listen_sock);
232 GNUNET_CRYPTO_hash (&sockfd,
233 sizeof(int),
234 &h_sock);
235
237 }
238
240 "Disconnecting queue for peer `%s'\n",
241 GNUNET_i2s (&queue->target));
242 if (NULL != queue->rekey_monotime_sc)
243 {
244 GNUNET_PEERSTORE_store_cancel (queue->rekey_monotime_sc);
245 queue->rekey_monotime_sc = NULL;
246 }
247 if (NULL != queue->handshake_monotime_sc)
248 {
249 GNUNET_PEERSTORE_store_cancel (queue->handshake_monotime_sc);
250 queue->handshake_monotime_sc = NULL;
251 }
252 if (NULL != queue->handshake_ack_monotime_sc)
253 {
254 GNUNET_PEERSTORE_store_cancel (queue->handshake_ack_monotime_sc);
255 queue->handshake_ack_monotime_sc = NULL;
256 }
257 if (NULL != queue->rekey_monotime_get)
258 {
259 GNUNET_PEERSTORE_iteration_stop (queue->rekey_monotime_get);
260 queue->rekey_monotime_get = NULL;
261 }
262 if (NULL != queue->handshake_monotime_get)
263 {
264 GNUNET_PEERSTORE_iteration_stop (queue->handshake_monotime_get);
265 queue->handshake_monotime_get = NULL;
266 }
267 if (NULL != queue->handshake_ack_monotime_get)
268 {
269 GNUNET_PEERSTORE_iteration_stop (queue->handshake_ack_monotime_get);
270 queue->handshake_ack_monotime_get = NULL;
271 }
272 if (NULL != queue->qh)
273 {
275 queue->qh = NULL;
276 }
278 GNUNET_YES ==
281 "# queues active",
283 GNUNET_NO);
284 if (NULL != queue->read_task)
285 {
286 GNUNET_SCHEDULER_cancel (queue->read_task);
287 queue->read_task = NULL;
288 }
289 if (NULL != queue->write_task)
290 {
291 GNUNET_SCHEDULER_cancel (queue->write_task);
292 queue->write_task = NULL;
293 }
295 {
297 "closing socket failed\n");
298 }
299 gcry_cipher_close (queue->in_cipher);
300 gcry_cipher_close (queue->out_cipher);
301 GNUNET_free (queue->address);
302 if (0 != queue->backpressure)
303 queue->destroyed = GNUNET_YES;
304 else
306
307 if (NULL == lt)
308 return;
309
310 if ((! shutdown_running) && (NULL == lt->listen_task))
311 {
313 "add read net listen\n");
316 lt->listen_sock,
317 &listen_cb,
318 lt);
319 }
320 else
321 GNUNET_free (lt);
322}
323
324
333static void
334calculate_hmac (struct GNUNET_HashCode *hmac_secret,
335 const void *buf,
336 size_t buf_size,
337 struct GNUNET_ShortHashCode *smac)
338{
339 struct GNUNET_HashCode mac;
340
341 GNUNET_CRYPTO_hmac_raw (hmac_secret,
342 sizeof(struct GNUNET_HashCode),
343 buf,
344 buf_size,
345 &mac);
346 /* truncate to `struct GNUNET_ShortHashCode` */
347 memcpy (smac, &mac, sizeof(struct GNUNET_ShortHashCode));
348 /* ratchet hmac key */
349 GNUNET_CRYPTO_hash (hmac_secret,
350 sizeof(struct GNUNET_HashCode),
351 hmac_secret);
352}
353
354
361static void
363{
364 struct TCPFinish fin;
365
366 memset (&fin, 0, sizeof(fin));
367 fin.header.size = htons (sizeof(fin));
369 calculate_hmac (&queue->out_hmac, &fin, sizeof(fin), &fin.hmac);
370 /* if there is any message left in pwrite_buf, we
371 overwrite it (possibly dropping the last message
372 from CORE hard here) */
373 memcpy (queue->pwrite_buf, &fin, sizeof(fin));
374 queue->pwrite_off = sizeof(fin);
375 /* This flag will ensure that #queue_write() no longer
376 notifies CORE about the possibility of sending
377 more data, and that #queue_write() will call
378 #queue_destroy() once the @c fin was fully written. */
379 queue->finishing = GNUNET_YES;
380}
381
382
388static void
389queue_read (void *cls);
390
391
399static void
400core_read_finished_cb (void *cls, int success)
401{
402 struct Queue *queue = cls;
403 if (GNUNET_OK != success)
405 "# messages lost in communicator API towards CORE",
406 1,
407 GNUNET_NO);
408 if (NULL == queue)
409 return;
410
412 "backpressure %u\n",
413 queue->backpressure);
414
415 queue->backpressure--;
416 /* handle deferred queue destruction */
417 if ((queue->destroyed) && (0 == queue->backpressure))
418 {
420 return;
421 }
422 else if (GNUNET_YES != queue->destroyed)
423 {
424 queue->timeout =
426 );
427 /* possibly unchoke reading, now that CORE made progress */
428 if (NULL == queue->read_task)
429 queue->read_task =
431 queue->timeout),
432 queue->sock,
433 &queue_read,
434 queue);
435 }
436}
437
438
448static void
450 const void *plaintext,
451 size_t plaintext_len)
452{
453 const struct GNUNET_MessageHeader *hdr = plaintext;
454 int ret;
455
457 "pass message from %s to core\n",
458 GNUNET_i2s (&queue->target));
459
460 if (ntohs (hdr->size) != plaintext_len)
461 {
462 /* NOTE: If we ever allow multiple CORE messages in one
463 BOX, this will have to change! */
464 GNUNET_break (0);
465 return;
466 }
468 &queue->target,
469 hdr,
472 queue);
474 "passed to core\n");
475 if (GNUNET_OK == ret)
476 queue->backpressure++;
477 GNUNET_break (GNUNET_NO != ret); /* backpressure not working!? */
478 if (GNUNET_SYSERR == ret)
480 "# bytes lost due to CORE not running",
481 plaintext_len,
482 GNUNET_NO);
483}
484
485
495static void
497 const struct GNUNET_PeerIdentity *pid,
498 gcry_cipher_hd_t *cipher,
499 struct GNUNET_HashCode *hmac_key)
500{
501 char key[256 / 8];
502 char ctr[128 / 8];
503
504 GNUNET_assert (0 == gcry_cipher_open (cipher,
505 GCRY_CIPHER_AES256 /* low level: go for speed */
506 ,
507 GCRY_CIPHER_MODE_CTR,
508 0 /* flags */));
511 sizeof(key),
512 prk,
513 "gnunet-communicator-tcp-key",
514 strlen (
515 "gnunet-communicator-tcp-key"),
516 NULL,
517 0));
518 GNUNET_assert (0 == gcry_cipher_setkey (*cipher, key, sizeof(key)));
521 sizeof(ctr),
522 prk,
523 "gnunet-communicator-tcp-ctr",
524 strlen (
525 "gnunet-communicator-tcp-ctr"),
526 NULL,
527 0));
528 gcry_cipher_setctr (*cipher, ctr, sizeof(ctr));
531 sizeof(struct GNUNET_HashCode),
532 prk,
533 "gnunet-communicator-hmac",
534 strlen ("gnunet-communicator-hmac"),
535 NULL,
536 0));
537}
538
539
545static void
546rekey_monotime_store_cb (void *cls, int success)
547{
548 struct Queue *queue = cls;
549 if (GNUNET_OK != success)
550 {
552 "Failed to store rekey monotonic time in PEERSTORE!\n");
553 }
554 queue->rekey_monotime_sc = NULL;
555 GNUNET_PEERSTORE_iteration_next (queue->rekey_monotime_get, 1);
556}
557
558
566static void
568 const struct GNUNET_PEERSTORE_Record *record,
569 const char *emsg)
570{
571 struct Queue *queue = cls;
572 struct GNUNET_TIME_AbsoluteNBO *mtbe;
573 struct GNUNET_TIME_Absolute mt;
574 const struct GNUNET_PeerIdentity *pid;
575 struct GNUNET_TIME_AbsoluteNBO *rekey_monotonic_time;
576
577 (void) emsg;
578
579 rekey_monotonic_time = &queue->rekey_monotonic_time;
580 pid = &queue->target;
581 if (NULL == record)
582 {
583 queue->rekey_monotime_get = NULL;
584 return;
585 }
586 if (sizeof(*mtbe) != record->value_size)
587 {
588 GNUNET_PEERSTORE_iteration_next (queue->rekey_monotime_get, 1);
589 GNUNET_break (0);
590 return;
591 }
592 mtbe = record->value;
593 mt = GNUNET_TIME_absolute_ntoh (*mtbe);
595 queue->rekey_monotonic_time).abs_value_us)
596 {
598 "Queue from %s dropped, rekey monotime in the past\n",
599 GNUNET_i2s (&queue->target));
600 GNUNET_break (0);
601 GNUNET_PEERSTORE_iteration_stop (queue->rekey_monotime_get);
602 queue->rekey_monotime_get = NULL;
603 // FIXME: Why should we try to gracefully finish here??
605 return;
606 }
607 queue->rekey_monotime_sc = GNUNET_PEERSTORE_store (peerstore,
608 "transport_tcp_communicator",
609 pid,
611 rekey_monotonic_time,
612 sizeof(*
613 rekey_monotonic_time),
617 queue);
618}
619
620
627static void
629 const struct GNUNET_CRYPTO_HpkeEncapsulation *c,
630 struct Queue *queue)
631{
632 struct GNUNET_ShortHashCode k;
633
635 setup_cipher (&k, &my_identity, &queue->in_cipher, &queue->in_hmac);
636}
637
638
645static void
647 struct Queue *queue)
648{
649 struct GNUNET_ShortHashCode k;
650
652 setup_cipher (&k, &my_identity, &queue->in_cipher, &queue->in_hmac);
653}
654
655
664static void
665do_rekey (struct Queue *queue, const struct TCPRekey *rekey)
666{
667 struct TcpRekeySignature thp;
668
670 thp.purpose.size = htonl (sizeof(thp));
672 "do_rekey size %u\n",
673 thp.purpose.size);
674 thp.sender = queue->target;
676 "sender %s\n",
679 "sender %s\n",
680 GNUNET_p2s (&queue->target.public_key));
681 thp.receiver = my_identity;
683 "receiver %s\n",
685 thp.ephemeral = rekey->ephemeral;
687 "ephemeral %s\n",
689 );
690 thp.monotonic_time = rekey->monotonic_time;
692 "time %s\n",
695 GNUNET_assert (ntohl ((&thp)->purpose.size) == sizeof (*(&thp)));
696 if (GNUNET_OK !=
699 &thp,
700 &rekey->sender_sig,
701 &queue->target.public_key))
702 {
703 GNUNET_break (0);
704 // FIXME Why should we try to gracefully finish here?
706 return;
707 }
708 queue->rekey_monotonic_time = rekey->monotonic_time;
709 queue->rekey_monotime_get = GNUNET_PEERSTORE_iteration_start (peerstore,
710 "transport_tcp_communicator",
711 &queue->target,
713 &
715 queue);
716 gcry_cipher_close (queue->in_cipher);
717 queue->rekeyed = GNUNET_YES;
719}
720
721
727static void
728handshake_ack_monotime_store_cb (void *cls, int success)
729{
730 struct Queue *queue = cls;
731
732 if (GNUNET_OK != success)
733 {
735 "Failed to store handshake ack monotonic time in PEERSTORE!\n");
736 }
737 queue->handshake_ack_monotime_sc = NULL;
738 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
739}
740
741
749static void
751 const struct GNUNET_PEERSTORE_Record *record,
752 const char *emsg)
753{
754 struct Queue *queue = cls;
755 struct GNUNET_TIME_AbsoluteNBO *mtbe;
756 struct GNUNET_TIME_Absolute mt;
757 const struct GNUNET_PeerIdentity *pid;
758 struct GNUNET_TIME_AbsoluteNBO *handshake_ack_monotonic_time;
759
760 (void) emsg;
761
762 handshake_ack_monotonic_time = &queue->handshake_ack_monotonic_time;
763 pid = &queue->target;
764 if (NULL == record)
765 {
766 queue->handshake_ack_monotime_get = NULL;
767 return;
768 }
769 if (sizeof(*mtbe) != record->value_size)
770 {
771 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
772 GNUNET_break (0);
773 return;
774 }
775 mtbe = record->value;
776 mt = GNUNET_TIME_absolute_ntoh (*mtbe);
778 queue->handshake_ack_monotonic_time).abs_value_us)
779 {
781 "Queue from %s dropped, handshake ack monotime in the past\n",
782 GNUNET_i2s (&queue->target));
783 GNUNET_break (0);
784 GNUNET_PEERSTORE_iteration_stop (queue->handshake_ack_monotime_get);
785 queue->handshake_ack_monotime_get = NULL;
786 // FIXME: Why should we try to gracefully finish here?
788 return;
789 }
790 queue->handshake_ack_monotime_sc =
792 "transport_tcp_communicator",
793 pid,
795 handshake_ack_monotonic_time,
796 sizeof(*handshake_ack_monotonic_time),
800 queue);
801}
802
803
810static void
812 struct Queue *queue)
813{
814 struct TCPConfirmationAck tca;
815 struct TcpHandshakeAckSignature thas;
816
818 "sending challenge\n");
819
820 tca.header.type = ntohs (
822 tca.header.size = ntohs (sizeof(tca));
823 tca.challenge = challenge;
824 tca.sender = my_identity;
825 tca.monotonic_time =
827 thas.purpose.purpose = htonl (
829 thas.purpose.size = htonl (sizeof(thas));
830 thas.sender = my_identity;
831 thas.receiver = queue->target;
833 thas.challenge = tca.challenge;
835 &thas,
836 &tca.sender_sig);
837 GNUNET_assert (0 ==
838 gcry_cipher_encrypt (queue->out_cipher,
839 &queue->cwrite_buf[queue->cwrite_off],
840 sizeof(tca),
841 &tca,
842 sizeof(tca)));
843 queue->cwrite_off += sizeof(tca);
845 "sending challenge done\n");
846}
847
848
855static void
857{
858 setup_cipher (dh, &queue->target, &queue->out_cipher, &queue->out_hmac);
860 queue->rekey_left_bytes =
862}
863
864
871static void
873{
874 struct TCPRekey rekey;
875 struct TcpRekeySignature thp;
876 struct GNUNET_ShortHashCode k;
877
878 GNUNET_assert (0 == queue->pwrite_off);
879 memset (&rekey, 0, sizeof(rekey));
880 GNUNET_CRYPTO_eddsa_kem_encaps (&queue->target.public_key, &rekey.ephemeral,
881 &k);
883 rekey.header.size = ntohs (sizeof(rekey));
884 rekey.monotonic_time =
887 thp.purpose.size = htonl (sizeof(thp));
889 "inject_rekey size %u\n",
890 thp.purpose.size);
891 thp.sender = my_identity;
893 "sender %s\n",
895 thp.receiver = queue->target;
897 "receiver %s\n",
899 thp.ephemeral = rekey.ephemeral;
901 "ephemeral %s\n",
903 );
904 thp.monotonic_time = rekey.monotonic_time;
906 "time %s\n",
910 &thp,
911 &rekey.sender_sig);
912 calculate_hmac (&queue->out_hmac, &rekey, sizeof(rekey), &rekey.hmac);
913 /* Encrypt rekey message with 'old' cipher */
914 GNUNET_assert (0 ==
915 gcry_cipher_encrypt (queue->out_cipher,
916 &queue->cwrite_buf[queue->cwrite_off],
917 sizeof(rekey),
918 &rekey,
919 sizeof(rekey)));
920 queue->cwrite_off += sizeof(rekey);
921 /* Setup new cipher for successive messages */
922 gcry_cipher_close (queue->out_cipher);
924}
925
926
927static int
929 const struct GNUNET_HashCode *key,
930 void *value)
931{
932 struct PendingReversal *pending_reversal = value;
933 (void) cls;
934
935 if (NULL != pending_reversal->timeout_task)
936 {
937 GNUNET_SCHEDULER_cancel (pending_reversal->timeout_task);
938 pending_reversal->timeout_task = NULL;
939 }
942 key,
943 pending_reversal));
944 GNUNET_free (pending_reversal->in);
945 GNUNET_free (pending_reversal);
946 return GNUNET_OK;
947}
948
949
950static void
951check_and_remove_pending_reversal (struct sockaddr *in, sa_family_t sa_family,
952 struct GNUNET_PeerIdentity *sender)
953{
954 if (AF_INET == sa_family)
955 {
956 struct PendingReversal *pending_reversal;
957 struct GNUNET_HashCode key;
958 struct sockaddr_in *natted_address;
959
960 natted_address = GNUNET_memdup (in, sizeof (struct sockaddr));
961 natted_address->sin_port = 0;
962 GNUNET_CRYPTO_hash (natted_address,
963 sizeof(struct sockaddr),
964 &key);
965
967 &key);
968 if (NULL != pending_reversal && (NULL == sender ||
969 0 != memcmp (sender,
970 &pending_reversal->target,
971 sizeof(struct
973 {
975 "Removing invalid pending reversal for `%s'at `%s'\n",
976 GNUNET_i2s (&pending_reversal->target),
977 GNUNET_a2s (in, sizeof (struct sockaddr)));
978 pending_reversals_delete_it (NULL, &key, pending_reversal);
979 }
980 GNUNET_free (natted_address);
981 }
982}
983
984
990static void
992{
993 if (NULL != pq->listen_sock)
994 {
996 pq->listen_sock = NULL;
997 }
998 if (NULL != pq->read_task)
999 {
1001 pq->read_task = NULL;
1002 }
1003 if (NULL != pq->write_task)
1004 {
1006 pq->write_task = NULL;
1007 }
1008 check_and_remove_pending_reversal (pq->address, pq->address->sa_family, NULL);
1010 GNUNET_free (pq->address);
1012 GNUNET_free (pq);
1013}
1014
1015
1022static void
1024{
1025 struct ProtoQueue *pq = cls;
1026 ssize_t sent;
1027 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "In proto queue write\n");
1028 pq->write_task = NULL;
1029 if (0 != pq->write_off)
1030 {
1031 sent = GNUNET_NETWORK_socket_send (pq->sock,
1032 pq->write_buf,
1033 pq->write_off);
1035 "Sent %lu bytes to TCP queue\n", sent);
1036 if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno))
1037 {
1039 free_proto_queue (pq);
1040 return;
1041 }
1042 if (sent > 0)
1043 {
1044 size_t usent = (size_t) sent;
1045 pq->write_off -= usent;
1046 memmove (pq->write_buf,
1047 &pq->write_buf[usent],
1048 pq->write_off);
1049 }
1050 }
1051 /* do we care to write more? */
1052 if ((0 < pq->write_off))
1053 pq->write_task =
1055 pq->sock,
1057 pq);
1058}
1059
1060
1067static void
1068queue_write (void *cls)
1069{
1070 struct Queue *queue = cls;
1071 ssize_t sent;
1072 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "In queue write\n");
1073 queue->write_task = NULL;
1074 if (0 != queue->cwrite_off)
1075 {
1076 sent = GNUNET_NETWORK_socket_send (queue->sock,
1077 queue->cwrite_buf,
1078 queue->cwrite_off);
1080 "Sent %lu bytes to TCP queue\n", sent);
1081 if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno))
1082 {
1085 return;
1086 }
1087 if (sent > 0)
1088 {
1089 size_t usent = (size_t) sent;
1090 queue->cwrite_off -= usent;
1091 memmove (queue->cwrite_buf,
1092 &queue->cwrite_buf[usent],
1093 queue->cwrite_off);
1094 queue->timeout =
1097 }
1098 }
1099 {
1100 /* can we encrypt more? (always encrypt full messages, needed
1101 such that #mq_cancel() can work!) */
1102 unsigned int we_do_not_need_to_rekey = (0 < queue->rekey_left_bytes
1103 - (queue->cwrite_off
1104 + queue->pwrite_off
1105 + sizeof (struct TCPRekey)));
1106 if (we_do_not_need_to_rekey &&
1107 (queue->pwrite_off > 0) &&
1108 (queue->cwrite_off + queue->pwrite_off <= BUF_SIZE))
1109 {
1111 "Encrypting %lu bytes\n", queue->pwrite_off);
1112 GNUNET_assert (0 ==
1113 gcry_cipher_encrypt (queue->out_cipher,
1114 &queue->cwrite_buf[queue->cwrite_off],
1115 queue->pwrite_off,
1116 queue->pwrite_buf,
1117 queue->pwrite_off));
1118 if (queue->rekey_left_bytes > queue->pwrite_off)
1119 queue->rekey_left_bytes -= queue->pwrite_off;
1120 else
1121 queue->rekey_left_bytes = 0;
1122 queue->cwrite_off += queue->pwrite_off;
1123 queue->pwrite_off = 0;
1124 }
1125 // if ((-1 != unverified_size)&& ((0 == queue->pwrite_off) &&
1126 if (((0 == queue->rekey_left_bytes) ||
1128 queue->rekey_time).rel_value_us)) &&
1129 (((0 == queue->pwrite_off) || ! we_do_not_need_to_rekey) &&
1130 (queue->cwrite_off + sizeof (struct TCPRekey) <= BUF_SIZE)))
1131 {
1133 }
1134 }
1135 if ((0 == queue->pwrite_off) && (! queue->finishing) &&
1136 (GNUNET_YES == queue->mq_awaits_continue))
1137 {
1138 queue->mq_awaits_continue = GNUNET_NO;
1140 }
1141 /* did we just finish writing 'finish'? */
1142 if ((0 == queue->cwrite_off) && (GNUNET_YES == queue->finishing))
1143 {
1145 "Finishing queue\n");
1147 return;
1148 }
1149 /* do we care to write more? */
1150 if ((0 < queue->cwrite_off) || (0 < queue->pwrite_off))
1151 queue->write_task =
1153 queue->sock,
1154 &queue_write,
1155 queue);
1156}
1157
1158
1166static size_t
1168{
1169 const struct GNUNET_MessageHeader *hdr;
1170 const struct TCPConfirmationAck *tca;
1171 const struct TCPBox *box;
1172 const struct TCPRekey *rekey;
1173 const struct TCPFinish *fin;
1174 struct TCPRekey rekeyz;
1175 struct TCPFinish finz;
1176 struct GNUNET_ShortHashCode tmac;
1177 uint16_t type;
1178 size_t size = 0;
1179 struct TcpHandshakeAckSignature thas;
1180 const struct GNUNET_CRYPTO_ChallengeNonceP challenge = queue->challenge;
1181
1183 "try handle plaintext!\n");
1184
1185 hdr = (const struct GNUNET_MessageHeader *) queue->pread_buf;
1186 if ((sizeof(*hdr) > queue->pread_off))
1187 {
1189 "Handling plaintext, not even a header!\n");
1190 return 0; /* not even a header */
1191 }
1192
1193 if ((GNUNET_YES != queue->initial_core_kx_done) && (queue->unverified_size >
1195 {
1197 "Already received data of size %lu bigger than KX size %lu!\n",
1198 queue->unverified_size,
1200 GNUNET_break_op (0);
1202 return 0;
1203 }
1204
1205 type = ntohs (hdr->type);
1206 switch (type)
1207 {
1209 tca = (const struct TCPConfirmationAck *) queue->pread_buf;
1211 "start processing ack\n");
1212 if (sizeof(*tca) > queue->pread_off)
1213 {
1215 "Handling plaintext size of tca greater than pread offset.\n")
1216 ;
1217 return 0;
1218 }
1219 if (ntohs (hdr->size) != sizeof(*tca))
1220 {
1222 "Handling plaintext size does not match message type.\n");
1223 GNUNET_break_op (0);
1225 return 0;
1226 }
1227
1228 thas.purpose.purpose = htonl (
1230 thas.purpose.size = htonl (sizeof(thas));
1231 thas.sender = tca->sender;
1232 thas.receiver = my_identity;
1233 thas.monotonic_time = tca->monotonic_time;
1234 thas.challenge = tca->challenge;
1235
1238 &thas,
1239 &tca->sender_sig,
1240 &tca->sender.public_key))
1241 {
1243 "Verification of signature failed!\n");
1244 GNUNET_break (0);
1246 return 0;
1247 }
1248 if (0 != GNUNET_memcmp (&tca->challenge, &challenge))
1249 {
1251 "Challenge in TCPConfirmationAck not correct!\n");
1252 GNUNET_break (0);
1254 return 0;
1255 }
1256
1257 queue->handshake_ack_monotime_get = GNUNET_PEERSTORE_iteration_start (
1258 peerstore,
1259 "transport_tcp_communicator",
1260 &queue->target,
1263 queue);
1264
1266 "Handling plaintext, ack processed!\n");
1267
1269 {
1270 send_challenge (queue->challenge_received, queue);
1271 queue->write_task =
1273 queue->sock,
1274 &queue_write,
1275 queue);
1276 }
1277 else if (GNUNET_TRANSPORT_CS_OUTBOUND == queue->cs)
1278 {
1280 queue->address->sa_family, NULL);
1281 }
1282
1287 queue->initial_core_kx_done = GNUNET_YES;
1288
1289 {
1290 char *foreign_addr;
1291
1292 switch (queue->address->sa_family)
1293 {
1294 case AF_INET:
1295 GNUNET_asprintf (&foreign_addr,
1296 "%s-%s",
1298 GNUNET_a2s (queue->address, queue->address_len));
1299 break;
1300
1301 case AF_INET6:
1302 GNUNET_asprintf (&foreign_addr,
1303 "%s-%s",
1305 GNUNET_a2s (queue->address, queue->address_len));
1306 break;
1307
1308 default:
1309 GNUNET_assert (0);
1310 }
1312 &queue->target,
1313 foreign_addr,
1314 UINT16_MAX, /* no MTU */
1316 0, /* Priority */
1317 queue->nt,
1318 queue->cs,
1319 queue->mq);
1320
1321 GNUNET_free (foreign_addr);
1322 }
1323
1324 size = ntohs (hdr->size);
1325 break;
1327 /* Special case: header size excludes box itself! */
1328 box = (const struct TCPBox *) queue->pread_buf;
1329 if (ntohs (hdr->size) + sizeof(struct TCPBox) > queue->pread_off)
1330 return 0;
1331 calculate_hmac (&queue->in_hmac, &box[1], ntohs (hdr->size), &tmac);
1332 if (0 != memcmp (&tmac, &box->hmac, sizeof(tmac)))
1333 {
1334 GNUNET_break_op (0);
1336 return 0;
1337 }
1338 pass_plaintext_to_core (queue, (const void *) &box[1], ntohs (hdr->size));
1339 size = ntohs (hdr->size) + sizeof(*box);
1341 "Handling plaintext, box processed!\n");
1343 "# bytes decrypted with BOX",
1344 size,
1345 GNUNET_NO);
1347 "# messages decrypted with BOX",
1348 1,
1349 GNUNET_NO);
1350 break;
1351
1353 rekey = (const struct TCPRekey *) queue->pread_buf;
1354 if (sizeof(*rekey) > queue->pread_off)
1355 return 0;
1356 if (ntohs (hdr->size) != sizeof(*rekey))
1357 {
1358 GNUNET_break_op (0);
1360 return 0;
1361 }
1362 rekeyz = *rekey;
1363 memset (&rekeyz.hmac, 0, sizeof(rekeyz.hmac));
1364 calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
1365 if (0 != memcmp (&tmac, &rekey->hmac, sizeof(tmac)))
1366 {
1367 GNUNET_break_op (0);
1369 return 0;
1370 }
1371 do_rekey (queue, rekey);
1372 size = ntohs (hdr->size);
1374 "Handling plaintext, rekey processed!\n");
1376 "# rekeying successful",
1377 1,
1378 GNUNET_NO);
1379 break;
1380
1382 fin = (const struct TCPFinish *) queue->pread_buf;
1383 if (sizeof(*fin) > queue->pread_off)
1384 return 0;
1385 if (ntohs (hdr->size) != sizeof(*fin))
1386 {
1387 GNUNET_break_op (0);
1389 return 0;
1390 }
1391 finz = *fin;
1392 memset (&finz.hmac, 0, sizeof(finz.hmac));
1393 calculate_hmac (&queue->in_hmac, &finz, sizeof(finz), &tmac);
1394 if (0 != memcmp (&tmac, &fin->hmac, sizeof(tmac)))
1395 {
1396 GNUNET_break_op (0);
1398 return 0;
1399 }
1400 /* handle FINISH by destroying queue */
1403 "Handling plaintext, finish processed!\n");
1404 break;
1405
1406 default:
1408 "Handling plaintext, nothing processed!\n");
1409 GNUNET_break_op (0);
1411 return 0;
1412 }
1413 GNUNET_assert (0 != size);
1414 if (-1 != queue->unverified_size)
1415 queue->unverified_size += size;
1416 return size;
1417}
1418
1419
1425static void
1426queue_read (void *cls)
1427{
1428 struct Queue *queue = cls;
1429 struct GNUNET_TIME_Relative left;
1430 ssize_t rcvd;
1431
1432 queue->read_task = NULL;
1433 rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
1434 &queue->cread_buf[queue->cread_off],
1435 BUF_SIZE - queue->cread_off);
1437 "Received %zd bytes from TCP queue\n", rcvd);
1438 if (-1 == rcvd)
1439 {
1440 if ((EAGAIN != errno) && (EINTR != errno))
1441 {
1444 return;
1445 }
1446 /* try again */
1447 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
1448 if (0 != left.rel_value_us)
1449 {
1450 queue->read_task =
1452 return;
1453 }
1455 "Queue %p was idle for %s, disconnecting\n",
1456 queue,
1459 GNUNET_YES));
1461 return;
1462 }
1463 if (0 == rcvd)
1464 {
1465 /* Orderly shutdown of connection */
1467 "Socket for queue %p seems to have been closed\n", queue);
1469 return;
1470 }
1471 queue->timeout =
1473 queue->cread_off += rcvd;
1474 while ((queue->pread_off < sizeof(queue->pread_buf)) &&
1475 (queue->cread_off > 0))
1476 {
1477 size_t max = GNUNET_MIN (sizeof(queue->pread_buf) - queue->pread_off,
1478 queue->cread_off);
1479 size_t done;
1480 size_t total;
1481 size_t old_pread_off = queue->pread_off;
1482
1483 GNUNET_assert (0 ==
1484 gcry_cipher_decrypt (queue->in_cipher,
1485 &queue->pread_buf[queue->pread_off],
1486 max,
1487 queue->cread_buf,
1488 max));
1489 queue->pread_off += max;
1490 total = 0;
1491 while (0 != (done = try_handle_plaintext (queue)))
1492 {
1493 /* 'done' bytes of plaintext were used, shift buffer */
1494 GNUNET_assert (done <= queue->pread_off);
1495 /* NOTE: this memmove() could possibly sometimes be
1496 avoided if we pass 'total' into try_handle_plaintext()
1497 and use it at an offset into the buffer there! */
1498 memmove (queue->pread_buf,
1499 &queue->pread_buf[done],
1500 queue->pread_off - done);
1501 queue->pread_off -= done;
1502 total += done;
1503 /* The last plaintext was a rekey, abort for now */
1504 if (GNUNET_YES == queue->rekeyed)
1505 break;
1506 }
1507 /* when we encounter a rekey message, the decryption above uses the
1508 wrong key for everything after the rekey; in that case, we have
1509 to re-do the decryption at 'total' instead of at 'max'.
1510 However, we have to take into account that the plaintext buffer may have
1511 already contained data and not jumped too far ahead in the ciphertext.
1512 If there is no rekey and the last message is incomplete (max > total),
1513 it is safe to keep the decryption so we shift by 'max' */
1514 if (GNUNET_YES == queue->rekeyed)
1515 {
1516 max = total - old_pread_off;
1517 queue->rekeyed = GNUNET_NO;
1518 queue->pread_off = 0;
1519 }
1520 memmove (queue->cread_buf, &queue->cread_buf[max], queue->cread_off - max);
1521 queue->cread_off -= max;
1522 }
1523 if (BUF_SIZE == queue->cread_off)
1524 return; /* buffer full, suspend reading */
1525 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
1526 if (0 != left.rel_value_us)
1527 {
1528 if (max_queue_length > queue->backpressure)
1529 {
1530 /* continue reading */
1531 queue->read_task =
1533 }
1534 return;
1535 }
1537 "Queue %p was idle for %s, disconnecting\n",
1538 queue,
1541 GNUNET_YES));
1543}
1544
1545
1553static struct sockaddr *
1555 struct sockaddr_in6 v6,
1556 unsigned int port)
1557{
1558 struct sockaddr *in;
1559
1560 v6.sin6_family = AF_INET6;
1561 v6.sin6_port = htons ((uint16_t) port);
1562#if HAVE_SOCKADDR_IN_SIN_LEN
1563 v6.sin6_len = sizeof(struct sockaddr_in6);
1564#endif
1565 v6.sin6_flowinfo = 0;
1566 v6.sin6_scope_id = 0;
1567 in = GNUNET_memdup (&v6, sizeof(v6));
1568 *sock_len = sizeof(struct sockaddr_in6);
1569
1570 return in;
1571}
1572
1573
1581static struct sockaddr *
1583 struct sockaddr_in v4,
1584 unsigned int port)
1585{
1586 struct sockaddr *in;
1587
1588 v4.sin_family = AF_INET;
1589 v4.sin_port = htons ((uint16_t) port);
1590#if HAVE_SOCKADDR_IN_SIN_LEN
1591 v4.sin_len = sizeof(struct sockaddr_in);
1592#endif
1593 in = GNUNET_memdup (&v4, sizeof(v4));
1594 *sock_len = sizeof(struct sockaddr_in);
1595 return in;
1596}
1597
1598
1605static struct PortOnlyIpv4Ipv6 *
1606tcp_address_to_sockaddr_port_only (const char *bindto, unsigned int *port)
1607{
1608 struct PortOnlyIpv4Ipv6 *po;
1609 struct sockaddr_in *i4;
1610 struct sockaddr_in6 *i6;
1611 socklen_t sock_len_ipv4;
1612 socklen_t sock_len_ipv6;
1613
1614 /* interpreting value as just a PORT number */
1615 if (*port > UINT16_MAX)
1616 {
1618 "BINDTO specification `%s' invalid: value too large for port\n",
1619 bindto);
1620 return NULL;
1621 }
1622
1623 po = GNUNET_new (struct PortOnlyIpv4Ipv6);
1624
1625 if (GNUNET_YES == disable_v6)
1626 {
1627 i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
1628 po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
1629 *port);
1630 po->addr_len_ipv4 = sock_len_ipv4;
1631 }
1632 else
1633 {
1634
1635 i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
1636 po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
1637 *port);
1638 po->addr_len_ipv4 = sock_len_ipv4;
1639
1640 i6 = GNUNET_malloc (sizeof(struct sockaddr_in6));
1641 po->addr_ipv6 = tcp_address_to_sockaddr_numeric_v6 (&sock_len_ipv6, *i6,
1642 *port);
1643
1644 po->addr_len_ipv6 = sock_len_ipv6;
1645
1646 GNUNET_free (i6);
1647 }
1648
1649 GNUNET_free (i4);
1650
1651 return po;
1652}
1653
1654
1661static char *
1662extract_address (const char *bindto)
1663{
1664 char *addr;
1665 char *start;
1666 char *token;
1667 char *cp;
1668 char *rest = NULL;
1669
1671 "extract address with bindto %s\n",
1672 bindto);
1673
1674 if (NULL == bindto)
1676 "bindto is NULL\n");
1677
1678 cp = GNUNET_strdup (bindto);
1679
1681 "extract address 2\n");
1682
1683 start = cp;
1684 if (('[' == *cp) && (']' == cp[strlen (cp) - 1]))
1685 {
1686 start++; /* skip over '['*/
1687 cp[strlen (cp) - 1] = '\0'; /* eat ']'*/
1688 addr = GNUNET_strdup (start);
1689 }
1690 else
1691 {
1692 token = strtok_r (cp, "]", &rest);
1693 if (strlen (bindto) == strlen (token))
1694 {
1695 token = strtok_r (cp, ":", &rest);
1696 addr = GNUNET_strdup (token);
1697 }
1698 else
1699 {
1700 token++;
1701 addr = GNUNET_strdup (token);
1702 }
1703 }
1704
1706 "tcp address: %s\n",
1707 addr);
1708 GNUNET_free (cp);
1709 return addr;
1710}
1711
1712
1719static unsigned int
1720extract_port (const char *addr_and_port)
1721{
1722 unsigned int port;
1723 char dummy[2];
1724 char *token;
1725 char *addr;
1726 char *colon;
1727 char *cp;
1728 char *rest = NULL;
1729
1730 if (NULL != addr_and_port)
1731 {
1732 cp = GNUNET_strdup (addr_and_port);
1733 token = strtok_r (cp, "]", &rest);
1734 if (strlen (addr_and_port) == strlen (token))
1735 {
1736 colon = strrchr (cp, ':');
1737 if (NULL == colon)
1738 {
1739 GNUNET_free (cp);
1740 return 0;
1741 }
1742 addr = colon;
1743 addr++;
1744 }
1745 else
1746 {
1747 token = strtok_r (NULL, "]", &rest);
1748 if (NULL == token)
1749 {
1750 GNUNET_free (cp);
1751 return 0;
1752 }
1753 else
1754 {
1755 addr = token;
1756 addr++;
1757 }
1758 }
1759
1760
1761 if (1 == sscanf (addr, "%u%1s", &port, dummy))
1762 {
1763 /* interpreting value as just a PORT number */
1764 if (port > UINT16_MAX)
1765 {
1767 "Port `%u' invalid: value too large for port\n",
1768 port);
1769 GNUNET_free (cp);
1770 return 0;
1771 }
1772 }
1773 else
1774 {
1776 "BINDTO specification invalid: last ':' not followed by number\n");
1777 GNUNET_free (cp);
1778 return 0;
1779 }
1780 GNUNET_free (cp);
1781 }
1782 else
1783 {
1785 "return 0\n");
1786 /* interpret missing port as 0, aka pick any free one */
1787 port = 0;
1788 }
1789
1790 return port;
1791}
1792
1793
1801static struct sockaddr *
1802tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
1803{
1804 struct sockaddr *in;
1805 unsigned int port;
1806 struct sockaddr_in v4;
1807 struct sockaddr_in6 v6;
1808 char *start;
1809
1810 memset (&v4, 0, sizeof(v4));
1811 start = extract_address (bindto);
1812 GNUNET_assert (NULL != start);
1814 "start %s\n",
1815 start);
1816
1818 "!bindto %s\n",
1819 bindto);
1820
1821
1822 if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
1823 {
1824 port = extract_port (bindto);
1825
1827 "port %u\n",
1828 port);
1829
1830 in = tcp_address_to_sockaddr_numeric_v4 (sock_len, v4, port);
1831 }
1832 else if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
1833 {
1834 port = extract_port (bindto);
1835 in = tcp_address_to_sockaddr_numeric_v6 (sock_len, v6, port);
1836 }
1837 else
1838 {
1839 GNUNET_assert (0);
1840 }
1841
1843 return in;
1844}
1845
1846
1855static void
1857 const struct GNUNET_MessageHeader *msg,
1858 void *impl_state)
1859{
1860 struct Queue *queue = impl_state;
1861 uint16_t msize = ntohs (msg->size);
1862 struct TCPBox box;
1864 "In MQ send. Queue finishing: %s; write task running: %s\n",
1865 (GNUNET_YES == queue->finishing) ? "yes" : "no",
1866 (NULL == queue->write_task) ? "yes" : "no");
1867 GNUNET_assert (mq == queue->mq);
1868 queue->mq_awaits_continue = GNUNET_YES;
1869 if (GNUNET_YES == queue->finishing)
1870 return; /* this queue is dying, drop msg */
1871 GNUNET_assert (0 == queue->pwrite_off);
1873 box.header.size = htons (msize);
1874 calculate_hmac (&queue->out_hmac, msg, msize, &box.hmac);
1875 memcpy (&queue->pwrite_buf[queue->pwrite_off], &box, sizeof(box));
1876 queue->pwrite_off += sizeof(box);
1877 memcpy (&queue->pwrite_buf[queue->pwrite_off], msg, msize);
1878 queue->pwrite_off += msize;
1880 "%lu bytes of plaintext to send\n", queue->pwrite_off);
1881 GNUNET_assert (NULL != queue->sock);
1882 if (NULL == queue->write_task)
1883 queue->write_task =
1885 queue->sock,
1886 &queue_write,
1887 queue);
1888}
1889
1890
1899static void
1900mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state)
1901{
1902 struct Queue *queue = impl_state;
1903
1904 if (mq == queue->mq)
1905 {
1906 queue->mq = NULL;
1908 }
1909}
1910
1911
1918static void
1919mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
1920{
1921 struct Queue *queue = impl_state;
1922
1923 GNUNET_assert (0 != queue->pwrite_off);
1924 queue->pwrite_off = 0;
1925}
1926
1927
1937static void
1938mq_error (void *cls, enum GNUNET_MQ_Error error)
1939{
1940 struct Queue *queue = cls;
1941
1943 "MQ error in queue to %s: %d\n",
1944 GNUNET_i2s (&queue->target),
1945 (int) error);
1947}
1948
1949
1957static void
1959{
1960 queue->nt =
1961 GNUNET_NT_scanner_get_type (is, queue->address, queue->address_len);
1963 queue_map,
1964 &queue->key,
1965 queue,
1968 "# queues active",
1970 GNUNET_NO);
1971 queue->timeout =
1974 &mq_destroy,
1975 &mq_cancel,
1976 queue,
1977 NULL,
1978 &mq_error,
1979 queue);
1980}
1981
1982
1993static void
1995 const struct GNUNET_CRYPTO_HpkeEncapsulation *c)
1996{
1997 struct TcpHandshakeSignature ths;
1998 struct TCPConfirmation tc;
1999
2000 memcpy (queue->cwrite_buf, c, sizeof(*c));
2001 queue->cwrite_off = sizeof(*c);
2002 /* compute 'tc' and append in encrypted format to cwrite_buf */
2003 tc.sender = my_identity;
2004 tc.monotonic_time =
2007 &tc.challenge,
2008 sizeof(tc.challenge));
2009 ths.purpose.purpose = htonl (
2011 ths.purpose.size = htonl (sizeof(ths));
2012 ths.sender = my_identity;
2013 ths.receiver = queue->target;
2014 ths.ephemeral = *c;
2015 ths.monotonic_time = tc.monotonic_time;
2016 ths.challenge = tc.challenge;
2018 &ths,
2019 &tc.sender_sig);
2020 GNUNET_assert (0 ==
2021 gcry_cipher_encrypt (queue->out_cipher,
2022 &queue->cwrite_buf[queue->cwrite_off],
2023 sizeof(tc),
2024 &tc,
2025 sizeof(tc)));
2026 queue->challenge = tc.challenge;
2027 queue->cwrite_off += sizeof(tc);
2028
2030 "handshake written\n");
2031}
2032
2033
2041static void
2043{
2045 struct GNUNET_ShortHashCode k;
2046
2048 &c, &k);
2049 setup_out_cipher (queue, &k);
2050 transmit_kx (queue, &c);
2051}
2052
2053
2059static void
2060handshake_monotime_store_cb (void *cls, int success)
2061{
2062 struct Queue *queue = cls;
2063 if (GNUNET_OK != success)
2064 {
2066 "Failed to store handshake monotonic time in PEERSTORE!\n");
2067 }
2068 queue->handshake_monotime_sc = NULL;
2069 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
2070}
2071
2072
2080static void
2082 const struct GNUNET_PEERSTORE_Record *record,
2083 const char *emsg)
2084{
2085 struct Queue *queue = cls;
2086 struct GNUNET_TIME_AbsoluteNBO *mtbe;
2087 struct GNUNET_TIME_Absolute mt;
2088 const struct GNUNET_PeerIdentity *pid;
2089 struct GNUNET_TIME_AbsoluteNBO *handshake_monotonic_time;
2090
2091 (void) emsg;
2092
2093 handshake_monotonic_time = &queue->handshake_monotonic_time;
2094 pid = &queue->target;
2096 "tcp handshake with us %s\n",
2098 if (NULL == record)
2099 {
2100 queue->handshake_monotime_get = NULL;
2101 return;
2102 }
2104 "tcp handshake from peer %s\n",
2105 GNUNET_i2s (pid));
2106 if (sizeof(*mtbe) != record->value_size)
2107 {
2108 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
2109 GNUNET_break (0);
2110 return;
2111 }
2112 mtbe = record->value;
2113 mt = GNUNET_TIME_absolute_ntoh (*mtbe);
2115 queue->handshake_monotonic_time).abs_value_us)
2116 {
2118 "Queue from %s dropped, handshake monotime in the past\n",
2119 GNUNET_i2s (&queue->target));
2120 GNUNET_break (0);
2121 GNUNET_PEERSTORE_iteration_stop (queue->handshake_ack_monotime_get);
2122 queue->handshake_ack_monotime_get = NULL;
2124 return;
2125 }
2126 queue->handshake_monotime_sc = GNUNET_PEERSTORE_store (peerstore,
2127 "transport_tcp_communicator",
2128 pid,
2130 handshake_monotonic_time,
2131 sizeof(*
2132 handshake_monotonic_time),
2135 &
2137 queue);
2138}
2139
2140
2152static int
2154 struct TCPConfirmation *tc,
2155 char *ibuf)
2156{
2157 struct TcpHandshakeSignature ths;
2159
2161 0 ==
2162 gcry_cipher_decrypt (queue->in_cipher,
2163 tc,
2164 sizeof(*tc),
2165 &ibuf[sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)],
2166 sizeof(*tc)));
2167 ths.purpose.purpose = htonl (
2169 ths.purpose.size = htonl (sizeof(ths));
2170 ths.sender = tc->sender;
2171 ths.receiver = my_identity;
2172 memcpy (&ths.ephemeral, ibuf, sizeof(struct GNUNET_CRYPTO_EcdhePublicKey));
2173 ths.monotonic_time = tc->monotonic_time;
2174 ths.challenge = tc->challenge;
2177 &ths,
2178 &tc->sender_sig,
2179 &tc->sender.public_key);
2180 if (GNUNET_YES == ret)
2181 queue->handshake_monotime_get =
2183 "transport_tcp_communicator",
2184 &queue->target,
2187 queue);
2188 return ret;
2189}
2190
2191
2199static void
2200queue_read_kx (void *cls)
2201{
2202 struct Queue *queue = cls;
2203 ssize_t rcvd;
2204 struct GNUNET_TIME_Relative left;
2205 struct TCPConfirmation tc;
2206
2207 queue->read_task = NULL;
2208 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
2209 if (0 == left.rel_value_us)
2210 {
2212 return;
2213 }
2214 rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
2215 &queue->cread_buf[queue->cread_off],
2216 BUF_SIZE - queue->cread_off);
2218 "Received %lu bytes to write in buffer of size %lu for KX from queue %p (expires in %"
2219 PRIu64 ")\n",
2220 rcvd, BUF_SIZE - queue->cread_off, queue, left.rel_value_us);
2221 if (-1 == rcvd)
2222 {
2223 if ((EAGAIN != errno) && (EINTR != errno))
2224 {
2227 return;
2228 }
2229 queue->read_task =
2231 return;
2232 }
2233 if (0 == rcvd)
2234 {
2235 /* Orderly shutdown of connection */
2237 "Socket for queue %p seems to have been closed\n", queue);
2239 return;
2240 }
2241 queue->cread_off += rcvd;
2242 if (queue->cread_off < INITIAL_KX_SIZE)
2243 {
2244 /* read more */
2246 "%lu/%lu bytes of KX read. Rescheduling...\n",
2247 queue->cread_off, INITIAL_KX_SIZE);
2248 queue->read_task =
2250 return;
2251 }
2252 /* we got all the data, let's find out who we are talking to! */
2254 (const struct GNUNET_CRYPTO_HpkeEncapsulation*)
2255 queue->cread_buf,
2256 queue);
2257 if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, queue->cread_buf))
2258 {
2260 "Invalid TCP KX received from %s\n",
2261 GNUNET_a2s (queue->address, queue->address_len));
2263 return;
2264 }
2265 if (0 !=
2266 memcmp (&tc.sender, &queue->target, sizeof(struct GNUNET_PeerIdentity)))
2267 {
2269 "Invalid sender in TCP KX received from %s\n",
2270 GNUNET_a2s (queue->address, queue->address_len));
2272 return;
2273 }
2274 send_challenge (tc.challenge, queue);
2275 queue->write_task =
2277 queue->sock,
2278 &queue_write,
2279 queue);
2280
2281 /* update queue timeout */
2282 queue->timeout =
2284 /* prepare to continue with regular read task immediately */
2285 memmove (queue->cread_buf,
2286 &queue->cread_buf[INITIAL_KX_SIZE],
2287 queue->cread_off - (INITIAL_KX_SIZE));
2289 "cread_off is %lu bytes before adjusting\n",
2290 queue->cread_off);
2291 queue->cread_off -= INITIAL_KX_SIZE;
2293 "cread_off set to %lu bytes\n",
2294 queue->cread_off);
2296}
2297
2298
2305static void
2306proto_read_kx (void *cls)
2307{
2308 struct ProtoQueue *pq = cls;
2309 ssize_t rcvd;
2310 struct GNUNET_TIME_Relative left;
2311 struct Queue *queue;
2312 struct TCPConfirmation tc;
2314
2315 pq->read_task = NULL;
2317 if (0 == left.rel_value_us)
2318 {
2319 free_proto_queue (pq);
2320 return;
2321 }
2322 rcvd = GNUNET_NETWORK_socket_recv (pq->sock,
2323 &pq->ibuf[pq->ibuf_off],
2324 sizeof(pq->ibuf) - pq->ibuf_off);
2326 "Proto received %lu bytes for KX\n", rcvd);
2327 if (-1 == rcvd)
2328 {
2329 if ((EAGAIN != errno) && (EINTR != errno))
2330 {
2332 free_proto_queue (pq);
2333 return;
2334 }
2335 /* try again */
2336 pq->read_task =
2338 return;
2339 }
2340 if (0 == rcvd)
2341 {
2342 /* Orderly shutdown of connection */
2344 "Socket for proto queue %p seems to have been closed\n", pq);
2345 free_proto_queue (pq);
2346 return;
2347 }
2348 pq->ibuf_off += rcvd;
2349 if (sizeof (struct TCPNATProbeMessage) == pq->ibuf_off)
2350 {
2351 struct TCPNATProbeMessage *pm = (struct TCPNATProbeMessage *) pq->ibuf;
2352
2354 &pm->clientIdentity);
2355
2356 queue = GNUNET_new (struct Queue);
2357 queue->target = pm->clientIdentity;
2358 eddsa_pub_to_hpke_key (&queue->target.public_key, &queue->target_hpke_key);
2361 }
2362 else if (pq->ibuf_off > sizeof(pq->ibuf))
2363 {
2364 /* read more */
2365 pq->read_task =
2367 return;
2368 }
2369 else
2370 {
2371 /* we got all the data, let's find out who we are talking to! */
2372 queue = GNUNET_new (struct Queue);
2374 (const struct GNUNET_CRYPTO_HpkeEncapsulation *) pq->
2375 ibuf,
2376 queue);
2377 if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, pq->ibuf))
2378 {
2380 "Invalid TCP KX received from %s\n",
2381 GNUNET_a2s (pq->address, pq->address_len));
2382 gcry_cipher_close (queue->in_cipher);
2384 free_proto_queue (pq);
2385 return;
2386 }
2387 queue->target = tc.sender;
2388 eddsa_pub_to_hpke_key (&queue->target.public_key, &queue->target_hpke_key);
2391 }
2392 queue->address = pq->address; /* steals reference */
2393 queue->address_len = pq->address_len;
2394 queue->listen_sock = pq->listen_sock;
2395 queue->sock = pq->sock;
2396
2398 "created queue with target %s\n",
2399 GNUNET_i2s (&queue->target));
2400
2402 "start kx proto\n");
2403
2405 boot_queue (queue);
2406 queue->read_task =
2408 queue->sock,
2409 read_task,
2410 queue);
2411 queue->write_task =
2413 queue->sock,
2414 &queue_write,
2415 queue);
2416 // TODO To early! Move it somewhere else.
2417 // send_challenge (tc.challenge, queue);
2418 queue->challenge_received = tc.challenge;
2419
2421 GNUNET_free (pq);
2422}
2423
2424
2425static struct ProtoQueue *
2427 struct sockaddr *in,
2428 socklen_t addrlen)
2429{
2430 struct ProtoQueue *pq = GNUNET_new (struct ProtoQueue);
2431
2432 if (NULL == sock)
2433 {
2434 // sock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET, addr, addrlen);
2435 sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, 0);
2436 if (NULL == sock)
2437 {
2439 "socket(%d) failed: %s",
2440 in->sa_family,
2441 strerror (errno));
2442 GNUNET_free (in);
2443 GNUNET_free (pq);
2444 return NULL;
2445 }
2446 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, addrlen)) &&
2447 (errno != EINPROGRESS))
2448 {
2450 "connect to `%s' failed: %s",
2451 GNUNET_a2s (in, addrlen),
2452 strerror (errno));
2454 GNUNET_free (in);
2455 GNUNET_free (pq);
2456 return NULL;
2457 }
2458 }
2459 pq->address_len = addrlen;
2460 pq->address = in;
2462 pq->sock = sock;
2464 pq->sock,
2466 pq);
2468
2469 return pq;
2470}
2471
2472
2480static void
2481listen_cb (void *cls)
2482{
2483 struct sockaddr_storage in;
2484 socklen_t addrlen;
2485 struct GNUNET_NETWORK_Handle *sock;
2486 struct ListenTask *lt;
2487 struct sockaddr *in_addr;
2488
2490 "listen_cb\n");
2491
2492 lt = cls;
2493
2494 lt->listen_task = NULL;
2495 GNUNET_assert (NULL != lt->listen_sock);
2496 addrlen = sizeof(in);
2497 memset (&in, 0, sizeof(in));
2499 (struct sockaddr*) &in,
2500 &addrlen);
2501 if ((NULL == sock) && ((EMFILE == errno) || (ENFILE == errno)))
2502 return; /* system limit reached, wait until connection goes down */
2504 lt->listen_sock,
2505 &listen_cb,
2506 lt);
2507 if ((NULL == sock) && ((EAGAIN == errno) || (ENOBUFS == errno)))
2508 return;
2509 if (NULL == sock)
2510 {
2512 return;
2513 }
2514 in_addr = GNUNET_memdup (&in, addrlen);
2515 create_proto_queue (sock, in_addr, addrlen);
2516}
2517
2518
2519static void
2521{
2522 struct sockaddr *in = cls;
2523 struct PendingReversal *pending_reversal;
2524 struct GNUNET_HashCode key;
2525
2527 sizeof(struct sockaddr),
2528 &key);
2530 &key);
2531
2532 GNUNET_assert (NULL != pending_reversal);
2533
2535 &key,
2536 pending_reversal))
2538 "No pending reversal found for address %s\n",
2539 GNUNET_a2s (in, sizeof (struct sockaddr)));
2540 GNUNET_free (pending_reversal->in);
2541 GNUNET_free (pending_reversal);
2542}
2543
2544
2563static int
2564mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
2565{
2566 struct sockaddr *in;
2567 socklen_t in_len = 0;
2568 const char *path;
2569 struct sockaddr_in *v4;
2570 struct sockaddr_in6 *v6;
2571 unsigned int is_natd = GNUNET_NO;
2572 struct GNUNET_HashCode key;
2573 struct GNUNET_HashCode queue_map_key;
2574 struct GNUNET_HashContext *hsh;
2575 struct Queue *queue;
2576
2578 "Connecting to %s at %s\n",
2579 GNUNET_i2s (peer),
2580 address);
2581 if (0 != strncmp (address,
2583 strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
2584 {
2585 GNUNET_break_op (0);
2586 return GNUNET_SYSERR;
2587 }
2588 path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
2589 in = tcp_address_to_sockaddr (path, &in_len);
2590
2591 if (NULL == in)
2592 {
2594 "Failed to setup TCP socket address\n");
2595 return GNUNET_SYSERR;
2596 }
2597
2599 "in %s\n",
2600 GNUNET_a2s (in, in_len));
2601
2604 GNUNET_CRYPTO_hash_context_read (hsh, peer, sizeof (*peer));
2605 GNUNET_CRYPTO_hash_context_finish (hsh, &queue_map_key);
2607
2608 if (NULL != queue)
2609 {
2611 "Queue for %s already exists or is in construction\n", address);
2612 GNUNET_free (in);
2613 return GNUNET_NO;
2614 }
2615 switch (in->sa_family)
2616 {
2617 case AF_INET:
2618 v4 = (struct sockaddr_in *) in;
2619 if (0 == v4->sin_port)
2620 {
2621 is_natd = GNUNET_YES;
2623 sizeof(struct sockaddr),
2624 &key);
2627 &key))
2628 {
2630 "There is already a request reversal for `%s'at `%s'\n",
2631 GNUNET_i2s (peer),
2632 address);
2633 GNUNET_free (in);
2634 return GNUNET_SYSERR;
2635 }
2636 }
2637 break;
2638
2639 case AF_INET6:
2640 if (GNUNET_YES == disable_v6)
2641 {
2643 "IPv6 disabled, skipping %s\n", address);
2644 GNUNET_free (in);
2645 return GNUNET_SYSERR;
2646 }
2647 v6 = (struct sockaddr_in6 *) in;
2648 if (0 == v6->sin6_port)
2649 {
2651 "Request reversal for `%s' at `%s' not possible for an IPv6 address\n",
2652 GNUNET_i2s (peer),
2653 address);
2654 GNUNET_free (in);
2655 return GNUNET_SYSERR;
2656 }
2657 break;
2658
2659 default:
2660 GNUNET_assert (0);
2661 }
2662
2663 if (GNUNET_YES == is_natd)
2664 {
2665 struct sockaddr_in local_sa;
2666 struct PendingReversal *pending_reversal;
2667
2668 memset (&local_sa, 0, sizeof(local_sa));
2669 local_sa.sin_family = AF_INET;
2670 local_sa.sin_port = htons (bind_port);
2671 /* We leave sin_address at 0, let the kernel figure it out,
2672 even if our bind() is more specific. (May want to reconsider
2673 later.) */
2674 if (GNUNET_OK != GNUNET_NAT_request_reversal (nat, &local_sa, v4))
2675 {
2677 "request reversal for `%s' at `%s' failed\n",
2678 GNUNET_i2s (peer),
2679 address);
2680 GNUNET_free (in);
2681 return GNUNET_SYSERR;
2682 }
2683 pending_reversal = GNUNET_new (struct PendingReversal);
2684 pending_reversal->in = in;
2687 &key,
2688 pending_reversal,
2690 pending_reversal->target = *peer;
2692 &
2694 in);
2696 "Created NAT WAIT connection to `%s' at `%s'\n",
2697 GNUNET_i2s (peer),
2698 GNUNET_a2s (in, sizeof (struct sockaddr)));
2699 }
2700 else
2701 {
2702 struct GNUNET_NETWORK_Handle *sock;
2703
2704 sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM,
2705 IPPROTO_TCP);
2706 if (NULL == sock)
2707 {
2709 "socket(%d) failed: %s",
2710 in->sa_family,
2711 strerror (errno));
2712 GNUNET_free (in);
2713 return GNUNET_SYSERR;
2714 }
2715 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, in_len)) &&
2716 (errno != EINPROGRESS))
2717 {
2719 "connect to `%s' failed: %s",
2720 address,
2721 strerror (errno));
2723 GNUNET_free (in);
2724 return GNUNET_SYSERR;
2725 }
2726
2727 queue = GNUNET_new (struct Queue);
2728 queue->target = *peer;
2729 eddsa_pub_to_hpke_key (&queue->target.public_key, &queue->target_hpke_key);
2730 queue->key = queue_map_key;
2731 queue->address = in;
2732 queue->address_len = in_len;
2733 queue->sock = sock;
2735 boot_queue (queue);
2737 "booted queue with target %s\n",
2738 GNUNET_i2s (&queue->target));
2739 // queue->mq_awaits_continue = GNUNET_YES;
2740 queue->read_task =
2742 queue->sock,
2744 queue);
2745
2746
2748 "start kx mq_init\n");
2749
2751 queue->write_task =
2753 queue->sock,
2754 &queue_write,
2755 queue);
2756 }
2757
2758 return GNUNET_OK;
2759}
2760
2761
2770static int
2772 const struct GNUNET_HashCode *key,
2773 void *value)
2774{
2775 struct ListenTask *lt = value;
2776
2777 (void) cls;
2778 (void) key;
2779 if (NULL != lt->listen_task)
2780 {
2782 lt->listen_task = NULL;
2783 }
2784 if (NULL != lt->listen_sock)
2785 {
2787 lt->listen_sock = NULL;
2788 }
2789 GNUNET_free (lt);
2790 return GNUNET_OK;
2791}
2792
2793
2802static int
2804 const struct GNUNET_HashCode *target,
2805 void *value)
2806{
2807 struct Queue *queue = value;
2808
2809 (void) cls;
2810 (void) target;
2812 return GNUNET_OK;
2813}
2814
2815
2821static void
2822do_shutdown (void *cls)
2823{
2825 "Shutdown %s!\n",
2826 shutdown_running ? "running" : "not running");
2827
2829 return;
2830 else
2832
2833 while (NULL != proto_head)
2835 if (NULL != nat)
2836 {
2838 nat = NULL;
2839 }
2847 if (NULL != ch)
2848 {
2851 ch = NULL;
2852 }
2853 if (NULL != stats)
2854 {
2856 stats = NULL;
2857 }
2858 if (NULL != my_private_key)
2859 {
2861 my_private_key = NULL;
2862 }
2863 if (NULL != is)
2864 {
2866 is = NULL;
2867 }
2868 if (NULL != pils)
2869 {
2871 pils = NULL;
2872 }
2873 if (NULL != peerstore)
2874 {
2876 peerstore = NULL;
2877 }
2878 if (NULL != resolve_request_handle)
2879 {
2882 }
2884 "Shutdown done!\n");
2885}
2886
2887
2899static void
2900enc_notify_cb (void *cls,
2901 const struct GNUNET_PeerIdentity *sender,
2902 const struct GNUNET_MessageHeader *msg)
2903{
2904 (void) cls;
2905 (void) sender;
2906 (void) msg;
2907 GNUNET_break_op (0);
2908}
2909
2910
2914static void
2915add_addr (struct sockaddr *in, socklen_t in_len)
2916{
2917
2918 struct Addresses *saddrs;
2919
2921 "add address %s\n",
2922 GNUNET_a2s (in, in_len));
2923
2924 saddrs = GNUNET_new (struct Addresses);
2925 saddrs->addr = in;
2926 saddrs->addr_len = in_len;
2928
2930 "after add address %s\n",
2931 GNUNET_a2s (in, in_len));
2932
2934 "add address %s\n",
2935 GNUNET_a2s (saddrs->addr, saddrs->addr_len));
2936
2937 addrs_lens++;
2938}
2939
2940
2954static enum GNUNET_GenericReturnValue
2956{
2957 char *filename;
2958 struct GNUNET_DISK_FileHandle *filehandle;
2959 int ret;
2960
2961 if (GNUNET_OK !=
2963 "pils",
2964 "SECRET_KEY_FILE",
2965 &filename))
2966 {
2968 "PILS service is lacking initial secret key file configuration setting. Exiting\n");
2969 return GNUNET_SYSERR;
2970 }
2971 if (NULL == filename)
2972 return GNUNET_SYSERR;
2974 if (GNUNET_SYSERR == ret)
2975 return GNUNET_SYSERR;
2976 if (GNUNET_NO == ret)
2977 {
2978 /* File does not exist - generate a new initial secret key and save it */
2979 // TODO consider the case that the file exists and ist not readable
2981 ikm,
2982 sizeof ikm);
2984 {
2986 "PILS service cannot create dir for saving initial secret key file. Exiting\n");
2987 return GNUNET_SYSERR;
2988 }
2989 filehandle = GNUNET_DISK_file_open (filename,
2993 | // would
2994 // the
2995 // group
2996 // need
2997 // read
2998 // perm?
3000 if (NULL == filehandle)
3001 {
3003 "PILS service had an issue with opening the initial secret key file. Exiting\n");
3004 GNUNET_DISK_file_close (filehandle);
3005 return GNUNET_SYSERR;
3006 }
3007 ret = GNUNET_DISK_file_write (filehandle,
3008 ikm,
3009 sizeof ikm);
3010 GNUNET_DISK_file_close (filehandle);
3011 if (sizeof ikm != ret)
3012 {
3014 "PILS service had an issue with writing the initial secret key to file. Exiting\n")
3015 ;
3016 return GNUNET_SYSERR;
3017 }
3018 }
3019 else
3020 {
3021 /* File existes - just read from it */
3022 off_t size;
3024 "PILS is going to read initial secret key from file %s\n",
3025 filename);
3026 filehandle = GNUNET_DISK_file_open (filename,
3029 if (NULL == filehandle)
3030 {
3032 " Not able to open file\n");
3033 return GNUNET_SYSERR;
3034 }
3035 if (GNUNET_OK != GNUNET_DISK_file_handle_size (filehandle, &size))
3036 {
3038 " File has the wrong size %lu\n",
3039 size);
3040 GNUNET_DISK_file_close (filehandle);
3041 return GNUNET_SYSERR;
3042 }
3043 if (sizeof ikm != size)
3044 {
3046 " Something is wrong with the file size, expected: %lu size, got: %lu\n",
3047 size,
3048 sizeof ikm);
3049 GNUNET_DISK_file_close (filehandle);
3050 return GNUNET_SYSERR;
3051 }
3052 ret = GNUNET_DISK_file_read (filehandle,
3053 ikm,
3054 sizeof ikm);
3055 GNUNET_DISK_file_close (filehandle);
3056 if (sizeof ikm != ret)
3057 {
3059 " Read initial secret key with wrong size %u, expected %lu\n", ret,
3060 sizeof ikm);
3061 return GNUNET_SYSERR;
3062 }
3063
3064 }
3065 return GNUNET_OK;
3066}
3067
3068
3076static int
3077init_socket (struct sockaddr *addr,
3078 socklen_t in_len)
3079{
3080 struct sockaddr_storage in_sto;
3081 socklen_t sto_len;
3082 struct GNUNET_NETWORK_Handle *listen_sock;
3083 struct ListenTask *lt;
3084 int sockfd;
3085 struct GNUNET_HashCode h_sock;
3086
3087 if (NULL == addr)
3088 {
3090 "Address is NULL.\n");
3091 return GNUNET_SYSERR;
3092 }
3093
3095 "address %s\n",
3096 GNUNET_a2s (addr, in_len));
3097
3098 listen_sock =
3099 GNUNET_NETWORK_socket_create (addr->sa_family, SOCK_STREAM, IPPROTO_TCP);
3100 if (NULL == listen_sock)
3101 {
3103 return GNUNET_SYSERR;
3104 }
3105
3106 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (listen_sock, addr, in_len))
3107 {
3109 GNUNET_NETWORK_socket_close (listen_sock);
3110 listen_sock = NULL;
3111 return GNUNET_SYSERR;
3112 }
3113
3114 if (GNUNET_OK !=
3115 GNUNET_NETWORK_socket_listen (listen_sock,
3116 5))
3117 {
3119 "listen");
3120 GNUNET_NETWORK_socket_close (listen_sock);
3121 listen_sock = NULL;
3122 return GNUNET_SYSERR;
3123 }
3124
3125 /* We might have bound to port 0, allowing the OS to figure it out;
3126 thus, get the real IN-address from the socket */
3127 sto_len = sizeof(in_sto);
3128
3129 if (0 != getsockname (GNUNET_NETWORK_get_fd (listen_sock),
3130 (struct sockaddr *) &in_sto,
3131 &sto_len))
3132 {
3133 memcpy (&in_sto, addr, in_len);
3134 sto_len = in_len;
3135 }
3136
3137 // addr = (struct sockaddr *) &in_sto;
3138 in_len = sto_len;
3140 "Bound to `%s'\n",
3141 GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len));
3142 if (NULL == stats)
3143 stats = GNUNET_STATISTICS_create ("communicator-tcp", cfg);
3144
3145 if (NULL == is)
3147
3148 /* start listening */
3149
3150 lt = GNUNET_new (struct ListenTask);
3151 lt->listen_sock = listen_sock;
3152
3154 listen_sock,
3155 &listen_cb,
3156 lt);
3157
3159 "creating hash\n");
3160 sockfd = GNUNET_NETWORK_get_fd (lt->listen_sock);
3161 GNUNET_CRYPTO_hash (&sockfd,
3162 sizeof(int),
3163 &h_sock);
3164
3166 "creating map\n");
3167 if (NULL == lt_map)
3169
3171 "creating map entry\n");
3174 &h_sock,
3175 lt,
3177
3179 "map entry created\n");
3180
3181 if (NULL == queue_map)
3183
3184 if (NULL == ch)
3189 &mq_init,
3190 NULL,
3192 NULL,
3193 NULL);
3194
3195 if (NULL == ch)
3196 {
3197 GNUNET_break (0);
3198 if (NULL != resolve_request_handle)
3201 return GNUNET_SYSERR;
3202 }
3203
3204 add_addr (addr, in_len);
3205 return GNUNET_OK;
3206
3207}
3208
3209
3210void
3211pid_change_cb (void *cls,
3212 const struct GNUNET_HELLO_Parser *parser,
3213 const struct GNUNET_HashCode *addr_hash)
3214{
3216 "Got PID to derive from `%s':\n",
3217 GNUNET_h2s (addr_hash));
3218 if (NULL == my_private_key)
3220
3222 (uint8_t*) ikm,
3223 addr_hash,
3229}
3230
3231
3240static void
3241run (void *cls,
3242 char *const *args,
3243 const char *cfgfile,
3244 const struct GNUNET_CONFIGURATION_Handle *c)
3245{
3246 struct sockaddr *in;
3247
3248 (void) cls;
3249
3250 cfg = c;
3251 if (GNUNET_OK !=
3254 "REKEY_INTERVAL",
3256 {
3258 }
3259 load_ikm ();
3261 GNUNET_assert (NULL != pils);
3263 if (NULL == peerstore)
3264 {
3265 GNUNET_free (bindto);
3266 GNUNET_break (0);
3268 return;
3269 }
3270
3272
3273 if (1 == sscanf (bindto, "%u%1s", &bind_port, dummy))
3274 {
3276 addr_len_ipv4 = po->addr_len_ipv4;
3278 "address po %s\n",
3279 GNUNET_a2s (po->addr_ipv4, addr_len_ipv4));
3280 if (NULL != po->addr_ipv4)
3281 {
3282 init_socket (po->addr_ipv4, addr_len_ipv4);
3283 }
3284 if (NULL != po->addr_ipv6)
3285 {
3286 addr_len_ipv6 = po->addr_len_ipv6;
3287 init_socket (po->addr_ipv6, addr_len_ipv6);
3288 }
3289
3290 // The following snippet is taken from https://github.com/libp2p/cpp-libp2p/blob/master/example/01-echo/libp2p_echo_client.cpp
3291 // and needs to be wrapped to c for being able to be called from within
3292 // this communicator.
3293 // It is merely there as a reminder of the needed functions and general
3294 // structure in order to send something via the c++ implementation of
3295 // libp2p.
3296 //
3297 //post(
3298 // *context,
3299 // [log,
3300 // host{std::move(host)},
3301 // &echo,
3302 // &message,
3303 // argv, // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
3304 // sch] {
3305 // auto server_ma_res =
3306 // libp2p::multi::Multiaddress::create(argv[1]); // NOLINT
3307 // if (!server_ma_res) {
3308 // log->error("unable to create server multiaddress: {}",
3309 // server_ma_res.error());
3310 // std::exit(EXIT_FAILURE);
3311 // }
3312 // const auto &server_ma = server_ma_res.value();
3313
3314 // auto server_peer_id_str = server_ma.getPeerId();
3315 // if (!server_peer_id_str) {
3316 // log->error("unable to get peer id");
3317 // std::exit(EXIT_FAILURE);
3318 // }
3319
3320 // auto server_peer_id_res =
3321 // libp2p::peer::PeerId::fromBase58(*server_peer_id_str);
3322 // if (!server_peer_id_res) {
3323 // log->error("Unable to decode peer id from base 58: {}",
3324 // server_peer_id_res.error());
3325 // std::exit(EXIT_FAILURE);
3326 // }
3327
3328 // const auto &server_peer_id = server_peer_id_res.value();
3329
3330 // auto peer_info = libp2p::peer::PeerInfo{server_peer_id, {server_ma}};
3331
3332 // // create Host object and open a stream through it
3333 // host->newStream(
3334 // peer_info,
3335 // {echo.getProtocolId()},
3336 // [log, &echo, &message, sch](auto &&stream_res) {
3337 // if (!stream_res) {
3338 // log->error("Cannot connect to server: {}", stream_res.error());
3339 // std::exit(EXIT_FAILURE);
3340 // }
3341
3342 // auto stream_p = std::move(stream_res.value().stream);
3343
3344 // auto echo_client = echo.createClient(stream_p);
3345
3346 // if (message.size() < 120) {
3347 // log->info("SENDING {}", message);
3348 // } else {
3349 // log->info("SENDING {} bytes", message.size());
3350 // }
3351
3352 // sch->schedule(
3353 // [log, message, stream = std::move(stream_p), echo_client] {
3354 // echo_client->sendAnd(
3355 // message,
3356 // [log,
3357 // stream = std::move(stream)](auto &&response_result) {
3358 // if (response_result.has_error()) {
3359 // log->info("Error happened: {}",
3360 // response_result.error());
3361 // stream->close(
3362 // [log](auto &&) { std::exit(EXIT_SUCCESS); });
3363 // return;
3364 // }
3365 // auto &resp = response_result.value();
3366 // if (resp.size() < 120) {
3367 // log->info("RESPONSE {}", resp);
3368 // } else {
3369 // log->info("RESPONSE size={}", resp.size());
3370 // }
3371 // stream->close(
3372 // [](auto &&) { std::exit(EXIT_SUCCESS); });
3373 // });
3374 // },
3375 // std::chrono::milliseconds(1000));
3376 // });
3377 // });
3378
3379 GNUNET_free (po);
3380 GNUNET_free (bindto);
3381 return;
3382 }
3383}
3384
3385
3393int
3394main (int argc, char *const *argv)
3395{
3396 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
3398 };
3399 int ret;
3400
3402 "Starting tcp communicator\n");
3403
3404 ret = (GNUNET_OK ==
3406 argc,
3407 argv,
3408 "gnunet-communicator-libp2p",
3409 _ ("GNUnet libp2p communicator"),
3410 options,
3411 &run,
3412 NULL))
3413 ? 0
3414 : 1;
3415 return ret;
3416}
3417
3418
3419/* end of gnunet-communicator-tcp.c */
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 struct GNUNET_TESTING_Interpreter * is
#define COMMUNICATOR_ADDRESS_PREFIX
Address prefix used by the communicator.
#define ADDRESS_VALIDITY_PERIOD
How long do we believe our addresses to remain up (before the other peer should revalidate).
#define COMMUNICATOR_CONFIG_SECTION
Configuration section used by the communicator.
static struct GNUNET_NAT_Handle * nat
Connection to NAT service.
void pid_change_cb(void *cls, const struct GNUNET_HELLO_Parser *parser, const struct GNUNET_HashCode *addr_hash)
static void calculate_hmac(struct GNUNET_HashCode *hmac_secret, const void *buf, size_t buf_size, struct GNUNET_ShortHashCode *smac)
Compute mac over buf, and ratched the hmac_secret.
static void queue_finish(struct Queue *queue)
Append a 'finish' message to the outgoing transmission.
static void transmit_kx(struct Queue *queue, const struct GNUNET_CRYPTO_HpkeEncapsulation *c)
Generate and transmit our ephemeral key and the signature for the initial KX with the other peer.
static void boot_queue(struct Queue *queue)
Add the given queue to our internal data structure.
static size_t try_handle_plaintext(struct Queue *queue)
Test if we have received a full message in plaintext.
static void pass_plaintext_to_core(struct Queue *queue, const void *plaintext, size_t plaintext_len)
We received plaintext_len bytes of plaintext on queue.
static struct sockaddr * tcp_address_to_sockaddr_numeric_v6(socklen_t *sock_len, struct sockaddr_in6 v6, unsigned int port)
Convert a struct sockaddr_in6 to astruct sockaddr *`.
static struct GNUNET_PeerIdentity my_identity
Our public key.
static void mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state)
Signature of functions implementing the destruction of a message queue.
static struct PortOnlyIpv4Ipv6 * tcp_address_to_sockaddr_port_only(const char *bindto, unsigned int *port)
Convert TCP bind specification to a struct PortOnlyIpv4Ipv6 *
static void setup_in_cipher(const struct GNUNET_CRYPTO_HpkeEncapsulation *ephemeral, struct Queue *queue)
Setup cipher of queue for decryption.
static void do_rekey(struct Queue *queue, const struct TCPRekey *rekey)
Handle rekey message on queue.
static void eddsa_priv_to_hpke_key(struct GNUNET_CRYPTO_EddsaPrivateKey *edpk, struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
static struct ProtoQueue * create_proto_queue(struct GNUNET_NETWORK_Handle *sock, struct sockaddr *in, socklen_t addrlen)
static int init_socket(struct sockaddr *addr, socklen_t in_len)
This method launch network interactions for each address we like to bind to.
static void listen_cb(void *cls)
We have been notified that our listen socket has something to read.
static void rekey_monotime_cb(void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY where...
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
static void queue_destroy(struct Queue *queue)
Functions with this signature are called whenever we need to close a queue due to a disconnect or fai...
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static void enc_notify_cb(void *cls, const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *msg)
Function called when the transport service has received an acknowledgement for this communicator (!...
static void handshake_ack_monotime_store_cb(void *cls, int success)
Callback called when peerstore store operation for handshake ack monotime value is finished.
static struct GNUNET_PEERSTORE_Handle * peerstore
Database for peer's HELLOs.
static int pending_reversals_delete_it(void *cls, const struct GNUNET_HashCode *key, void *value)
static void queue_read_kx(void *cls)
Read from the socket of the queue until we have enough data to initialize the decryption logic and ca...
static int get_lt_delete_it(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator over all ListenTasks to clean up.
static void inject_rekey(struct Queue *queue)
Inject a struct TCPRekey message into the queue's plaintext buffer.
static void do_shutdown(void *cls)
Shutdown the UNIX communicator.
static struct GNUNET_CONTAINER_MultiHashMap * queue_map
Queues (map from peer identity to struct Queue)
static void proto_read_kx(void *cls)
Read from the socket of the proto queue until we have enough data to upgrade to full queue.
static struct sockaddr * tcp_address_to_sockaddr_numeric_v4(socklen_t *sock_len, struct sockaddr_in v4, unsigned int port)
Convert a struct sockaddr_in4 to astruct sockaddr *`.
static void check_and_remove_pending_reversal(struct sockaddr *in, sa_family_t sa_family, struct GNUNET_PeerIdentity *sender)
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
static void setup_cipher(const struct GNUNET_ShortHashCode *prk, const struct GNUNET_PeerIdentity *pid, gcry_cipher_hd_t *cipher, struct GNUNET_HashCode *hmac_key)
Setup cipher based on shared secret dh and decrypting peer pid.
static void setup_out_cipher(struct Queue *queue, struct GNUNET_ShortHashCode *dh)
Setup cipher for outgoing data stream based on target and our ephemeral private key.
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 pending_reversal_timeout(void *cls)
static void queue_read(void *cls)
Queue read task.
static int get_queue_delete_it(void *cls, const struct GNUNET_HashCode *target, void *value)
Iterator over all message queues to clean up.
static void mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state)
Implementation function that cancels the currently sent message.
static void handshake_ack_monotime_cb(void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_A...
static int mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
Function called by the transport service to initialize a message queue given address information abou...
static void proto_queue_write(void *cls)
We have been notified that our socket is ready to write.
static void handshake_monotime_store_cb(void *cls, int success)
Callback called when peerstore store operation for handshake monotime is finished.
static void send_challenge(struct GNUNET_CRYPTO_ChallengeNonceP challenge, struct Queue *queue)
Sending challenge with TcpConfirmationAck back to sender of ephemeral key.
static void rekey_monotime_store_cb(void *cls, int success)
Callback called when peerstore store operation for rekey monotime value is finished.
static char * extract_address(const char *bindto)
This Method extracts the address part of the BINDTO string.
static int shutdown_running
A flag indicating we are already doing a shutdown.
static enum GNUNET_GenericReturnValue load_ikm()
FIXME: We could alternatively ask PILS for de/encaps, but at a high cost wrt async RPC calls....
static int decrypt_and_check_tc(struct Queue *queue, struct TCPConfirmation *tc, char *ibuf)
We have received the first bytes from the other side on a queue.
#define LOG(kind,...)
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 queue_write(void *cls)
We have been notified that our socket is ready to write.
static void add_addr(struct sockaddr *in, socklen_t in_len)
This method adds addresses to the DLL, that are later register at the NAT service.
static void handshake_monotime_cb(void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE w...
static struct Addresses * addrs_head
Head of DLL with addresses we like to register at NAT service.
static struct sockaddr * tcp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
Convert TCP bind specification to a struct sockaddr *
static void eddsa_pub_to_hpke_key(struct GNUNET_CRYPTO_EddsaPublicKey *edpk, struct GNUNET_CRYPTO_EcdhePublicKey *pk)
static struct Addresses * addrs_tail
Head of DLL with addresses we like to register at NAT service.
static void setup_in_cipher_elligator(const struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct Queue *queue)
Setup cipher of queue for decryption from an elligator representative.
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 unsigned int extract_port(const char *addr_and_port)
This Method extracts the port part of the BINDTO string.
static struct GNUNET_CRYPTO_EcdhePrivateKey my_x25519_private_key
Our private key.
static void mq_send(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 struct GNUNET_PILS_Handle * pils
For PILS.
static void start_initial_kx_out(struct Queue *queue)
Initialize our key material for outgoing transmissions and inform the other peer about it.
static void free_proto_queue(struct ProtoQueue *pq)
Closes socket and frees memory associated with pq.
static struct GNUNET_CONTAINER_MultiHashMap * lt_map
ListenTasks (map from socket to struct ListenTask)
static void core_read_finished_cb(void *cls, int success)
Core tells us it is done processing a message that transport received on a queue with status success.
static unsigned int bind_port
The port the communicator should be assigned to.
#define INITIAL_CORE_KX_SIZE
Size of the initial core key exchange messages.
static struct GNUNET_CONTAINER_MultiHashMap * pending_reversals
Map of pending reversals.
static struct ProtoQueue * proto_tail
Protoqueues DLL tail.
static struct GNUNET_TIME_Relative rekey_interval
The rekey interval.
#define NAT_TIMEOUT
How long until we give up on establishing an NAT connection? Must be > 4 RTT.
#define BUF_SIZE
Size of our IO buffers for ciphertext data.
static unsigned long long max_queue_length
Maximum queue length before we stop reading towards the transport service.
struct GNUNET_RESOLVER_RequestHandle * resolve_request_handle
Handle for DNS lookup of bindto address.
static int addrs_lens
Number of addresses in the DLL for register at NAT service.
#define PROTO_QUEUE_TIMEOUT
How long do we wait until we must have received the initial KX?
#define INITIAL_KX_SIZE
Size of the initial key exchange message sent first in both directions.
static struct ProtoQueue * proto_head
Protoqueues DLL head.
#define DEFAULT_REKEY_INTERVAL
How often do we rekey based on time (at least)
static unsigned long long rekey_max_bytes
The rekey byte maximum.
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
static char * address
GNS address for this phone.
struct GNUNET_HashCode key
The key used in the DHT.
static char * filename
static int disable_v6
Disable IPv6.
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
struct GNUNET_SCHEDULER_Task * read_task
static char * value
Value of the record to add/remove.
static uint32_t type
Type string converted to DNS type value.
static unsigned char ikm[256/8]
The initial key material for the peer.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
static struct GNUNET_TRANSPORT_PluginMonitor * pm
Handle if we are monitoring plugin session activity.
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
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.
API to the peerstore service.
struct GNUNET_PILS_Handle * GNUNET_PILS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_PILS_PidChangeCallback pid_change_cb, void *cls)
Connect to the PILS service.
Definition: pils_api.c:367
void GNUNET_PILS_disconnect(struct GNUNET_PILS_Handle *handle)
Disconnect from the PILS service.
Definition: pils_api.c:390
void GNUNET_PILS_derive_pid(size_t seed_key_bytes, const uint8_t seed_key[seed_key_bytes], const struct GNUNET_HashCode *addrs_hash, struct GNUNET_CRYPTO_EddsaPrivateKey *outkey)
Generate the peer id from the addresses hash and the initial secret key.
Definition: pils_api.c:507
Constants for network protocols.
Functions related to doing DNS lookups.
#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE_ACK
Signature by a peer sending back the nonce received at initial handshake.
#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_REKEY
Signature used by TCP communicator rekey.
#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE
Signature used by TCP communicator handshake.
API to create, modify and access statistics.
API of the transport service towards the communicator processes.
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.
void GNUNET_TRANSPORT_communicator_address_remove_all(struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
Notify transport service that this communicator no longer provides all its addresses for this peer.
@ GNUNET_TRANSPORT_CC_RELIABLE
Transmission is reliabile (with ACKs), e.g.
@ GNUNET_TRANSPORT_CS_INBOUND
this is an inbound connection (communicator initiated)
@ 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_time(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, struct GNUNET_TIME_Relative *time)
Get a configuration value that should be a relative time.
#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?
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_kem_decaps(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *prk)
Decapsulate a key for a private EdDSA key.
Definition: crypto_hpke.c:285
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Generate a random unsigned 64-bit value.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_elligator_kem_decaps(const struct GNUNET_CRYPTO_EcdhePrivateKey *skR, const struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *shared_secret)
Carries out ecdh decapsulation with own private key and the representative of the received public key...
Definition: crypto_hpke.c:348
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
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_elligator_kem_encaps(const struct GNUNET_CRYPTO_EcdhePublicKey *pkR, struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *shared_secret)
Carries out ecdh encapsulation with given public key and the private key from a freshly created ephem...
Definition: crypto_hpke.c:327
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_kem_encaps(const struct GNUNET_CRYPTO_EddsaPublicKey *pub, struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *prk)
Encapsulate key material for a EdDSA public key.
Definition: crypto_hpke.c:233
#define GNUNET_CRYPTO_eddsa_sign(priv, ps, sig)
EdDSA sign a given block.
#define GNUNET_CRYPTO_eddsa_verify(purp, ps, sig, pub)
Verify EdDSA signature.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
@ GNUNET_CRYPTO_QUALITY_NONCE
Randomness for IVs etc.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1258
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:710
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test_read(const char *fil)
Check that fil corresponds to a filename and the file has read permissions.
Definition: disk.c:540
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1332
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:633
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:673
enum GNUNET_GenericReturnValue GNUNET_DISK_file_handle_size(struct GNUNET_DISK_FileHandle *fh, off_t *size)
Get the size of an open file.
Definition: disk.c:206
@ GNUNET_DISK_OPEN_READ
Open the file for reading.
@ GNUNET_DISK_OPEN_WRITE
Open the file for writing.
@ GNUNET_DISK_OPEN_CREATE
Create file if it doesn't exist.
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_NONE
Nobody is allowed to do anything to the file.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
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
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hkdf_expand(void *result, size_t out_len, const struct GNUNET_ShortHashCode *prk,...)
HKDF-Expand using SHA256.
Definition: crypto_hkdf.c:156
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_contains(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Check if the map contains any value under the given key (including values that are NULL).
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_MULTIPLE
Allow multiple values with the same key.
@ 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_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_log(kind,...)
void GNUNET_CRYPTO_hash_context_read(struct GNUNET_HashContext *hc, const void *buf, size_t size)
Add data to be hashed.
Definition: crypto_hash.c:363
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
void GNUNET_CRYPTO_hash_context_finish(struct GNUNET_HashContext *hc, struct GNUNET_HashCode *r_hash)
Finish the hash computation.
Definition: crypto_hash.c:387
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_sk_to_x25519(const struct GNUNET_CRYPTO_PrivateKey *sk, struct GNUNET_CRYPTO_EcdhePrivateKey *x25519)
Convert a GNUnet identity key to a key sutiable for HPKE (X25519)
Definition: crypto_hpke.c:832
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_pk_to_x25519(const struct GNUNET_CRYPTO_PublicKey *pk, struct GNUNET_CRYPTO_EcdhePublicKey *x25519)
Convert a GNUnet identity key to a key sutiable for HPKE (X25519)
Definition: crypto_hpke.c:808
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_MIN(a, b)
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
struct GNUNET_HashContext * GNUNET_CRYPTO_hash_context_start(void)
Start incremental hashing operation.
Definition: crypto_hash.c:347
void GNUNET_CRYPTO_hmac_raw(const void *key, size_t key_len, const void *plaintext, size_t plaintext_len, struct GNUNET_HashCode *hmac)
Calculate HMAC of a message (RFC 2104) TODO: Shouldn't this be the standard hmac function and the abo...
Definition: crypto_hash.c:297
@ GNUNET_PUBLIC_KEY_TYPE_EDDSA
EDDSA identity.
@ 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).
const char * GNUNET_e2s(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key value 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_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
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).
#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...
const char * GNUNET_p2s(const struct GNUNET_CRYPTO_EddsaPublicKey *p)
Convert a public key value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_WARNING
@ 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
int GNUNET_NAT_request_reversal(struct GNUNET_NAT_Handle *nh, const struct sockaddr_in *local_sa, const struct sockaddr_in *remote_sa)
We learned about a peer (possibly behind NAT) so run the gnunet-nat-client to send dummy ICMP respons...
Definition: nat_api.c:675
void GNUNET_NAT_unregister(struct GNUNET_NAT_Handle *nh)
Stop port redirection and public IP address detection for the given handle.
Definition: nat_api.c:703
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_accept(const struct GNUNET_NETWORK_Handle *desc, struct sockaddr *address, socklen_t *address_len)
Accept a new connection on a socket.
Definition: network.c:392
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_recv(const struct GNUNET_NETWORK_Handle *desc, void *buffer, size_t length)
Read data from a connected socket (always non-blocking).
Definition: network.c:717
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_socket_connect(const struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Connect a socket to some remote address.
Definition: network.c:602
ssize_t GNUNET_NETWORK_socket_send(const struct GNUNET_NETWORK_Handle *desc, const void *buffer, size_t length)
Send data (always non-blocking).
Definition: network.c:738
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
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_listen(const struct GNUNET_NETWORK_Handle *desc, int backlog)
Listen on a socket.
Definition: network.c:652
void GNUNET_NT_scanner_done(struct GNUNET_NT_InterfaceScanner *is)
Terminate interface scanner.
Definition: nt.c:428
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
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
struct GNUNET_PEERSTORE_IterateContext * GNUNET_PEERSTORE_iteration_start(struct GNUNET_PEERSTORE_Handle *h, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, GNUNET_PEERSTORE_Processor callback, void *callback_cls)
Iterate over peerstore entries.
void GNUNET_PEERSTORE_iteration_next(struct GNUNET_PEERSTORE_IterateContext *ic, uint64_t limit)
Continue an iteration.
void GNUNET_PEERSTORE_store_cancel(struct GNUNET_PEERSTORE_StoreContext *sc)
Cancel a store request.
void GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h)
Disconnect from the PEERSTORE service.
struct GNUNET_PEERSTORE_Handle * GNUNET_PEERSTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the PEERSTORE service.
#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE
Key used to store sender's monotonic time from handshake message.
struct GNUNET_PEERSTORE_StoreContext * GNUNET_PEERSTORE_store(struct GNUNET_PEERSTORE_Handle *h, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, const void *value, size_t size, struct GNUNET_TIME_Absolute expiry, enum GNUNET_PEERSTORE_StoreOption options, GNUNET_PEERSTORE_Continuation cont, void *cont_cls)
Store a new entry in the PEERSTORE.
#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK
Key used to store sender's monotonic time from handshake ack message.
#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY
Key used to store sender's monotonic time from rekey message.
void GNUNET_PEERSTORE_iteration_stop(struct GNUNET_PEERSTORE_IterateContext *ic)
Cancel an iteration.
@ GNUNET_PEERSTORE_STOREOPTION_REPLACE
Delete any previous values for the given key before storing the given value.
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
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_CONFIRMATION_ACK
TCP communicator confirmation ack.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH
TCP communicator end of stream.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX
TCP communicator payload box.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY
TCP communicator rekey message.
void GNUNET_RESOLVER_request_cancel(struct GNUNET_RESOLVER_RequestHandle *rh)
Cancel a request that is still pending with the resolver.
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_write_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *wfd, 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:1582
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
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.
Definition: scheduler.c:1304
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
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.
Definition: scheduler.c:1277
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
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_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, 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).
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:406
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:599
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:741
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
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_monotonic(const struct GNUNET_CONFIGURATION_Handle *cfg)
Obtain the current time and make sure it is monotonically increasing.
Definition: time.c:864
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:640
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:660
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
#define max(x, y)
static unsigned int size
Size of the "table".
Definition: peer.c:68
#define _(String)
GNU gettext support macro.
Definition: platform.h:179
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition: scheduler.c:431
DLL to store the addresses we like to register at NAT service.
struct Addresses * next
Kept in a DLL.
struct Addresses * prev
Kept in a DLL.
struct sockaddr * addr
Address we like to register at NAT service.
socklen_t addr_len
Length of address we like to register at NAT service.
Internal representation of the hash map.
Type of a nonce used for challenges.
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
Private ECC key encoded for transmission.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
Private ECC key encoded for transmission.
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
HPKE DHKEM encapsulation (X25519) See RFC 9180.
A private key for an identity as per LSD0001.
An identity key as per LSD0001.
Handle used to access files (and pipes).
Definition of a command line option.
Context for parsing HELLOs.
Definition: hello-uri.c:232
A 512-bit hashcode.
Handle to a message queue.
Definition: mq.c:87
Header for all communications.
handle to a socket
Definition: network.c:53
Handle to the PEERSTORE service.
Definition: peerstore_api.c:44
Single PEERSTORE record.
A handle for the PILS service.
Definition: pils_api.c:82
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.
A 256-bit hashcode.
Time for absolute time used by GNUnet, in microseconds and in network byte order.
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
Opaque handle to the transport service for communicators.
Struct to use as closure.
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
struct GNUNET_SCHEDULER_Task * listen_task
ID of listen task.
Struct for pending nat reversals.
struct sockaddr * in
Address the reversal was send to.
struct GNUNET_SCHEDULER_Task * timeout_task
struct GNUNET_PeerIdentity target
To whom are we like to talk to.
In case of port only configuration we like to bind to ipv4 and ipv6 addresses.
struct sockaddr * addr_ipv4
Ipv4 address we like to bind to.
struct sockaddr * addr_ipv6
Ipv6 address we like to bind to.
socklen_t addr_len_ipv6
Length of ipv6 address.
socklen_t addr_len_ipv4
Length of ipv4 address.
Handle for an incoming connection where we do not yet have enough information to setup a full queue.
socklen_t address_len
Length of the address.
struct GNUNET_SCHEDULER_Task * write_task
ID of write task for this connection.
char write_buf[sizeof(struct TCPNATProbeMessage)]
buffer for writing struct TCPNATProbeMessage to network.
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
size_t ibuf_off
Current offset for reading into ibuf.
struct GNUNET_TIME_Absolute timeout
Timeout for this protoqueue.
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
struct sockaddr * address
Address of the other peer.
char ibuf[(sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)+sizeof(struct TCPConfirmation))]
Buffer for reading all the information we need to upgrade from protoqueue to queue.
size_t write_off
Offset of the buffer?
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
Handle for a queue.
struct GNUNET_SCHEDULER_Task * write_task
ID of write task for this connection.
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
struct sockaddr * address
Address of the other peer.
TCP message box.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX.
struct GNUNET_ShortHashCode hmac
HMAC for the following encrypted message.
Ack for the encrypted continuation of TCP initial handshake.
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
struct GNUNET_CRYPTO_EddsaSignature sender_sig
Sender's signature of type GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE_ACK.
struct GNUNET_CRYPTO_ChallengeNonceP challenge
Challenge value used to protect against replay attack, if there is no stored monotonic time value.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_CONFIRMATION_ACK.
struct GNUNET_PeerIdentity sender
Sender's identity.
Encrypted continuation of TCP initial handshake.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH.
struct GNUNET_ShortHashCode hmac
HMAC for the following encrypted message.
Basically a WELCOME message, but with the purpose of giving the waiting peer a client handle to use.
TCP rekey message box.
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
struct GNUNET_CRYPTO_EddsaSignature sender_sig
Sender's signature of type GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_REKEY.
struct GNUNET_CRYPTO_HpkeEncapsulation ephemeral
New ephemeral key.
struct GNUNET_ShortHashCode hmac
HMAC for the following encrypted message.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY.
Signature we use to verify that the ack from the receiver of the ephemeral key was really send by the...
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE_ACK.
struct GNUNET_PeerIdentity sender
Identity of the inititor of the TCP connection (TCP client).
struct GNUNET_CRYPTO_ChallengeNonceP challenge
Challenge value used to protect against replay attack, if there is no stored monotonic time value.
struct GNUNET_PeerIdentity receiver
Presumed identity of the target of the TCP connection (TCP server)
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
Signature we use to verify that the ephemeral key was really chosen by the specified sender.
struct GNUNET_CRYPTO_ChallengeNonceP challenge
Challenge value used to protect against replay attack, if there is no stored monotonic time value.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE.
struct GNUNET_CRYPTO_HpkeEncapsulation ephemeral
Ephemeral key used by the sender (as Elligator representative).
struct GNUNET_PeerIdentity sender
Identity of the inititor of the TCP connection (TCP client).
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
struct GNUNET_PeerIdentity receiver
Presumed identity of the target of the TCP connection (TCP server)
Signature we use to verify that the ephemeral key was really chosen by the specified sender.
struct GNUNET_CRYPTO_HpkeEncapsulation ephemeral
Ephemeral key used by the sender.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_REKEY.
struct GNUNET_PeerIdentity sender
Identity of the inititor of the TCP connection (TCP client).
struct GNUNET_PeerIdentity receiver
Presumed identity of the target of the TCP connection (TCP server)
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...