GNUnet 0.21.2
gnunet-communicator-tcp.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet
3 Copyright (C) 2010-2014, 2018, 2019 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
30#include "platform.h"
31#include "gnunet_common.h"
32#include "gnunet_util_lib.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
48#define NAT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
49
54#define ADDRESS_VALIDITY_PERIOD \
55 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
56
65#define DEFAULT_MAX_QUEUE_LENGTH 8
66
71#define BUF_SIZE (2 * 64 * 1024 + sizeof(struct TCPBox))
72
76#define DEFAULT_REKEY_INTERVAL GNUNET_TIME_UNIT_DAYS
77
81#define PROTO_QUEUE_TIMEOUT GNUNET_TIME_UNIT_MINUTES
82
87#define REKEY_MAX_BYTES (1024LLU * 1024 * 400)
88
93#define INITIAL_KX_SIZE \
94 (sizeof(struct GNUNET_CRYPTO_EcdhePublicKey) \
95 + sizeof(struct TCPConfirmation))
96
100#define INITIAL_CORE_KX_SIZE \
101 (sizeof(struct EphemeralKeyMessage) \
102 + sizeof(struct PingMessage) \
103 + sizeof(struct PongMessage))
104
108#define COMMUNICATOR_ADDRESS_PREFIX "tcp"
109
113#define COMMUNICATOR_CONFIG_SECTION "communicator-tcp"
114
116
117
123{
128
133
138
143
149
154};
155
161{
166
171
176
182
187};
188
193{
198
203
209
214
215};
216
221{
222
223
228
233
238
244
249
250};
251
255struct TCPBox
256{
264
274
275 /* followed by as may bytes of payload as indicated in @e header,
276 excluding the TCPBox itself! */
277};
278
279
285{
290
300
305
310
316};
317
323{
328
333
338
343
349};
350
357{
362
372};
373
379{
384
389};
390
392
397{
398 /*
399 * Timeout task.
400 */
402
407
411 struct sockaddr *in;
412};
413
418{
423
428};
429
433struct Queue
434{
439
444
449
454
458 gcry_cipher_hd_t in_cipher;
459
463 gcry_cipher_hd_t out_cipher;
464
469
474
480
485
490
494 struct sockaddr *address;
495
501
507
511 socklen_t address_len;
512
517
522
526 unsigned long long bytes_in_queue;
527
532
537
541 char pread_buf[UINT16_MAX + 1 + sizeof(struct TCPBox)];
542
546 char pwrite_buf[UINT16_MAX + 1 + sizeof(struct TCPBox)];
547
552 size_t cread_off;
553
559
564 size_t pread_off;
565
571
576
584 unsigned int backpressure;
585
590
595
600
605
613
619
624
629
634
639
644
649
654
659
664
669
674
678 // TODO remove?
680
685};
686
687
693{
698
703
708
713
718
722 char write_buf[sizeof (struct TCPNATProbeMessage)];
723
727 size_t write_off;
728
733
737 struct sockaddr *address;
738
742 socklen_t address_len;
743
748
754
758 size_t ibuf_off;
759};
760
765{
769 struct sockaddr *addr_ipv4;
770
774 socklen_t addr_len_ipv4;
775
779 struct sockaddr *addr_ipv6;
780
784 socklen_t addr_len_ipv6;
785
786};
787
792{
797
802
806 struct sockaddr *addr;
807
811 socklen_t addr_len;
812
813};
814
815
819static unsigned long long max_queue_length;
820
825
830
835
840
845
849static unsigned long long rekey_max_bytes;
850
855
860
865
869static const struct GNUNET_CONFIGURATION_Handle *cfg;
870
875
879static struct GNUNET_NAT_Handle *nat;
880
884static struct ProtoQueue *proto_head;
885
889static struct ProtoQueue *proto_tail;
890
895
899static struct Addresses *addrs_head;
900
904static struct Addresses *addrs_tail;
905
909static int addrs_lens;
910
915
920
924static int disable_v6;
925
929static unsigned int bind_port;
930
935
943static void
944listen_cb (void *cls);
945
946static void
949{
951 key.type = htonl (GNUNET_PUBLIC_KEY_TYPE_EDDSA);
952 key.eddsa_key = *edpk;
954}
955
956static void
959{
961 key.type = htonl (GNUNET_PUBLIC_KEY_TYPE_EDDSA);
962 key.eddsa_key = *edpk;
964}
965
973static void
975{
976 struct ListenTask *lt = NULL;
977 struct GNUNET_HashCode h_sock;
978 int sockfd;
979
980 if (NULL != queue->listen_sock)
981 {
982 sockfd = GNUNET_NETWORK_get_fd (queue->listen_sock);
983 GNUNET_CRYPTO_hash (&sockfd,
984 sizeof(int),
985 &h_sock);
986
988 }
989
991 "Disconnecting queue for peer `%s'\n",
992 GNUNET_i2s (&queue->target));
993 if (NULL != queue->rekey_monotime_sc)
994 {
995 GNUNET_PEERSTORE_store_cancel (queue->rekey_monotime_sc);
996 queue->rekey_monotime_sc = NULL;
997 }
998 if (NULL != queue->handshake_monotime_sc)
999 {
1000 GNUNET_PEERSTORE_store_cancel (queue->handshake_monotime_sc);
1001 queue->handshake_monotime_sc = NULL;
1002 }
1003 if (NULL != queue->handshake_ack_monotime_sc)
1004 {
1005 GNUNET_PEERSTORE_store_cancel (queue->handshake_ack_monotime_sc);
1006 queue->handshake_ack_monotime_sc = NULL;
1007 }
1008 if (NULL != queue->rekey_monotime_get)
1009 {
1010 GNUNET_PEERSTORE_iteration_stop (queue->rekey_monotime_get);
1011 queue->rekey_monotime_get = NULL;
1012 }
1013 if (NULL != queue->handshake_monotime_get)
1014 {
1015 GNUNET_PEERSTORE_iteration_stop (queue->handshake_monotime_get);
1016 queue->handshake_monotime_get = NULL;
1017 }
1018 if (NULL != queue->handshake_ack_monotime_get)
1019 {
1020 GNUNET_PEERSTORE_iteration_stop (queue->handshake_ack_monotime_get);
1021 queue->handshake_ack_monotime_get = NULL;
1022 }
1023 if (NULL != queue->qh)
1024 {
1026 queue->qh = NULL;
1027 }
1029 GNUNET_YES ==
1032 "# queues active",
1034 GNUNET_NO);
1035 if (NULL != queue->read_task)
1036 {
1037 GNUNET_SCHEDULER_cancel (queue->read_task);
1038 queue->read_task = NULL;
1039 }
1040 if (NULL != queue->write_task)
1041 {
1042 GNUNET_SCHEDULER_cancel (queue->write_task);
1043 queue->write_task = NULL;
1044 }
1046 {
1048 "closing socket failed\n");
1049 }
1050 gcry_cipher_close (queue->in_cipher);
1051 gcry_cipher_close (queue->out_cipher);
1052 GNUNET_free (queue->address);
1053 if (0 != queue->backpressure)
1054 queue->destroyed = GNUNET_YES;
1055 else
1057
1058 if (NULL == lt)
1059 return;
1060
1061 if ((! shutdown_running) && (NULL == lt->listen_task))
1062 {
1064 "add read net listen\n");
1067 lt->listen_sock,
1068 &listen_cb,
1069 lt);
1070 }
1071 else
1072 GNUNET_free (lt);
1073}
1074
1075
1084static void
1085calculate_hmac (struct GNUNET_HashCode *hmac_secret,
1086 const void *buf,
1087 size_t buf_size,
1088 struct GNUNET_ShortHashCode *smac)
1089{
1090 struct GNUNET_HashCode mac;
1091
1092 GNUNET_CRYPTO_hmac_raw (hmac_secret,
1093 sizeof(struct GNUNET_HashCode),
1094 buf,
1095 buf_size,
1096 &mac);
1097 /* truncate to `struct GNUNET_ShortHashCode` */
1098 memcpy (smac, &mac, sizeof(struct GNUNET_ShortHashCode));
1099 /* ratchet hmac key */
1100 GNUNET_CRYPTO_hash (hmac_secret,
1101 sizeof(struct GNUNET_HashCode),
1102 hmac_secret);
1103}
1104
1105
1112static void
1114{
1115 struct TCPFinish fin;
1116
1117 memset (&fin, 0, sizeof(fin));
1118 fin.header.size = htons (sizeof(fin));
1120 calculate_hmac (&queue->out_hmac, &fin, sizeof(fin), &fin.hmac);
1121 /* if there is any message left in pwrite_buf, we
1122 overwrite it (possibly dropping the last message
1123 from CORE hard here) */
1124 memcpy (queue->pwrite_buf, &fin, sizeof(fin));
1125 queue->pwrite_off = sizeof(fin);
1126 /* This flag will ensure that #queue_write() no longer
1127 notifies CORE about the possibility of sending
1128 more data, and that #queue_write() will call
1129 #queue_destroy() once the @c fin was fully written. */
1130 queue->finishing = GNUNET_YES;
1131}
1132
1133
1139static void
1140queue_read (void *cls);
1141
1142
1150static void
1151core_read_finished_cb (void *cls, int success)
1152{
1153 struct Queue *queue = cls;
1154 if (GNUNET_OK != success)
1156 "# messages lost in communicator API towards CORE",
1157 1,
1158 GNUNET_NO);
1159 if (NULL == queue)
1160 return;
1161
1163 "backpressure %u\n",
1164 queue->backpressure);
1165
1166 queue->backpressure--;
1167 /* handle deferred queue destruction */
1168 if ((queue->destroyed) && (0 == queue->backpressure))
1169 {
1171 return;
1172 }
1173 else if (GNUNET_YES != queue->destroyed)
1174 {
1175 queue->timeout =
1177 );
1178 /* possibly unchoke reading, now that CORE made progress */
1179 if (NULL == queue->read_task)
1180 queue->read_task =
1182 queue->timeout),
1183 queue->sock,
1184 &queue_read,
1185 queue);
1186 }
1187}
1188
1189
1199static void
1201 const void *plaintext,
1202 size_t plaintext_len)
1203{
1204 const struct GNUNET_MessageHeader *hdr = plaintext;
1205 int ret;
1206
1208 "pass message from %s to core\n",
1209 GNUNET_i2s (&queue->target));
1210
1211 if (ntohs (hdr->size) != plaintext_len)
1212 {
1213 /* NOTE: If we ever allow multiple CORE messages in one
1214 BOX, this will have to change! */
1215 GNUNET_break (0);
1216 return;
1217 }
1219 &queue->target,
1220 hdr,
1223 queue);
1225 "passed to core\n");
1226 if (GNUNET_OK == ret)
1227 queue->backpressure++;
1228 GNUNET_break (GNUNET_NO != ret); /* backpressure not working!? */
1229 if (GNUNET_SYSERR == ret)
1231 "# bytes lost due to CORE not running",
1232 plaintext_len,
1233 GNUNET_NO);
1234}
1235
1236
1246static void
1248 const struct GNUNET_PeerIdentity *pid,
1249 gcry_cipher_hd_t *cipher,
1250 struct GNUNET_HashCode *hmac_key)
1251{
1252 char key[256 / 8];
1253 char ctr[128 / 8];
1254
1255 GNUNET_assert (0 == gcry_cipher_open (cipher,
1256 GCRY_CIPHER_AES256 /* low level: go for speed */
1257 ,
1258 GCRY_CIPHER_MODE_CTR,
1259 0 /* flags */));
1262 sizeof(key),
1263 prk,
1264 "gnunet-communicator-tcp-key",
1265 strlen (
1266 "gnunet-communicator-tcp-key"),
1267 NULL,
1268 0));
1269 GNUNET_assert (0 == gcry_cipher_setkey (*cipher, key, sizeof(key)));
1272 sizeof(ctr),
1273 prk,
1274 "gnunet-communicator-tcp-ctr",
1275 strlen (
1276 "gnunet-communicator-tcp-ctr"),
1277 NULL,
1278 0));
1279 gcry_cipher_setctr (*cipher, ctr, sizeof(ctr));
1281 GNUNET_CRYPTO_hkdf_expand (hmac_key,
1282 sizeof(struct GNUNET_HashCode),
1283 prk,
1284 "gnunet-communicator-hmac",
1285 strlen ("gnunet-communicator-hmac"),
1286 NULL,
1287 0));
1288}
1289
1290
1296static void
1297rekey_monotime_store_cb (void *cls, int success)
1298{
1299 struct Queue *queue = cls;
1300 if (GNUNET_OK != success)
1301 {
1303 "Failed to store rekey monotonic time in PEERSTORE!\n");
1304 }
1305 queue->rekey_monotime_sc = NULL;
1306 GNUNET_PEERSTORE_iteration_next (queue->rekey_monotime_get, 1);
1307}
1308
1309
1317static void
1319 const struct GNUNET_PEERSTORE_Record *record,
1320 const char *emsg)
1321{
1322 struct Queue *queue = cls;
1323 struct GNUNET_TIME_AbsoluteNBO *mtbe;
1324 struct GNUNET_TIME_Absolute mt;
1325 const struct GNUNET_PeerIdentity *pid;
1326 struct GNUNET_TIME_AbsoluteNBO *rekey_monotonic_time;
1327
1328 (void) emsg;
1329
1330 rekey_monotonic_time = &queue->rekey_monotonic_time;
1331 pid = &queue->target;
1332 if (NULL == record)
1333 {
1334 queue->rekey_monotime_get = NULL;
1335 return;
1336 }
1337 if (sizeof(*mtbe) != record->value_size)
1338 {
1339 GNUNET_PEERSTORE_iteration_next (queue->rekey_monotime_get, 1);
1340 GNUNET_break (0);
1341 return;
1342 }
1343 mtbe = record->value;
1344 mt = GNUNET_TIME_absolute_ntoh (*mtbe);
1346 queue->rekey_monotonic_time).abs_value_us)
1347 {
1349 "Queue from %s dropped, rekey monotime in the past\n",
1350 GNUNET_i2s (&queue->target));
1351 GNUNET_break (0);
1352 GNUNET_PEERSTORE_iteration_stop (queue->rekey_monotime_get);
1353 queue->rekey_monotime_get = NULL;
1354 // FIXME: Why should we try to gracefully finish here??
1356 return;
1357 }
1358 queue->rekey_monotime_sc = GNUNET_PEERSTORE_store (peerstore,
1359 "transport_tcp_communicator",
1360 pid,
1362 rekey_monotonic_time,
1363 sizeof(*
1364 rekey_monotonic_time),
1368 queue);
1369}
1370
1371
1378static void
1380 const struct GNUNET_CRYPTO_HpkeEncapsulation *c,
1381 struct Queue *queue)
1382{
1383 struct GNUNET_ShortHashCode k;
1384
1386 setup_cipher (&k, &my_identity, &queue->in_cipher, &queue->in_hmac);
1387}
1388
1389
1396static void
1398 struct Queue *queue)
1399{
1400 struct GNUNET_ShortHashCode k;
1401
1403 setup_cipher (&k, &my_identity, &queue->in_cipher, &queue->in_hmac);
1404}
1405
1406
1415static void
1416do_rekey (struct Queue *queue, const struct TCPRekey *rekey)
1417{
1418 struct TcpRekeySignature thp;
1419
1421 thp.purpose.size = htonl (sizeof(thp));
1423 "do_rekey size %u\n",
1424 thp.purpose.size);
1425 thp.sender = queue->target;
1427 "sender %s\n",
1430 "sender %s\n",
1431 GNUNET_p2s (&queue->target.public_key));
1432 thp.receiver = my_identity;
1434 "receiver %s\n",
1436 thp.ephemeral = rekey->ephemeral;
1438 "ephemeral %s\n",
1440 );
1441 thp.monotonic_time = rekey->monotonic_time;
1443 "time %s\n",
1446 GNUNET_assert (ntohl ((&thp)->purpose.size) == sizeof (*(&thp)));
1447 if (GNUNET_OK !=
1450 &thp,
1451 &rekey->sender_sig,
1452 &queue->target.public_key))
1453 {
1454 GNUNET_break (0);
1455 // FIXME Why should we try to gracefully finish here?
1457 return;
1458 }
1459 queue->rekey_monotonic_time = rekey->monotonic_time;
1460 queue->rekey_monotime_get = GNUNET_PEERSTORE_iteration_start (peerstore,
1461 "transport_tcp_communicator",
1462 &queue->target,
1464 &
1466 queue);
1467 gcry_cipher_close (queue->in_cipher);
1468 queue->rekeyed = GNUNET_YES;
1469 setup_in_cipher (&rekey->ephemeral, queue);
1470}
1471
1472
1478static void
1479handshake_ack_monotime_store_cb (void *cls, int success)
1480{
1481 struct Queue *queue = cls;
1482
1483 if (GNUNET_OK != success)
1484 {
1486 "Failed to store handshake ack monotonic time in PEERSTORE!\n");
1487 }
1488 queue->handshake_ack_monotime_sc = NULL;
1489 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
1490}
1491
1492
1500static void
1502 const struct GNUNET_PEERSTORE_Record *record,
1503 const char *emsg)
1504{
1505 struct Queue *queue = cls;
1506 struct GNUNET_TIME_AbsoluteNBO *mtbe;
1507 struct GNUNET_TIME_Absolute mt;
1508 const struct GNUNET_PeerIdentity *pid;
1509 struct GNUNET_TIME_AbsoluteNBO *handshake_ack_monotonic_time;
1510
1511 (void) emsg;
1512
1513 handshake_ack_monotonic_time = &queue->handshake_ack_monotonic_time;
1514 pid = &queue->target;
1515 if (NULL == record)
1516 {
1517 queue->handshake_ack_monotime_get = NULL;
1518 return;
1519 }
1520 if (sizeof(*mtbe) != record->value_size)
1521 {
1522 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
1523 GNUNET_break (0);
1524 return;
1525 }
1526 mtbe = record->value;
1527 mt = GNUNET_TIME_absolute_ntoh (*mtbe);
1529 queue->handshake_ack_monotonic_time).abs_value_us)
1530 {
1532 "Queue from %s dropped, handshake ack monotime in the past\n",
1533 GNUNET_i2s (&queue->target));
1534 GNUNET_break (0);
1535 GNUNET_PEERSTORE_iteration_stop (queue->handshake_ack_monotime_get);
1536 queue->handshake_ack_monotime_get = NULL;
1537 // FIXME: Why should we try to gracefully finish here?
1539 return;
1540 }
1541 queue->handshake_ack_monotime_sc =
1543 "transport_tcp_communicator",
1544 pid,
1546 handshake_ack_monotonic_time,
1547 sizeof(*handshake_ack_monotonic_time),
1551 queue);
1552}
1553
1554
1561static void
1563 struct Queue *queue)
1564{
1565 struct TCPConfirmationAck tca;
1566 struct TcpHandshakeAckSignature thas;
1567
1569 "sending challenge\n");
1570
1571 tca.header.type = ntohs (
1573 tca.header.size = ntohs (sizeof(tca));
1574 tca.challenge = challenge;
1575 tca.sender = my_identity;
1576 tca.monotonic_time =
1578 thas.purpose.purpose = htonl (
1580 thas.purpose.size = htonl (sizeof(thas));
1581 thas.sender = my_identity;
1582 thas.receiver = queue->target;
1583 thas.monotonic_time = tca.monotonic_time;
1584 thas.challenge = tca.challenge;
1586 &thas,
1587 &tca.sender_sig);
1588 GNUNET_assert (0 ==
1589 gcry_cipher_encrypt (queue->out_cipher,
1590 &queue->cwrite_buf[queue->cwrite_off],
1591 sizeof(tca),
1592 &tca,
1593 sizeof(tca)));
1594 queue->cwrite_off += sizeof(tca);
1596 "sending challenge done\n");
1597}
1598
1599
1606static void
1608{
1609 setup_cipher (dh, &queue->target, &queue->out_cipher, &queue->out_hmac);
1611 queue->rekey_left_bytes =
1613}
1614
1615
1622static void
1624{
1625 struct TCPRekey rekey;
1626 struct TcpRekeySignature thp;
1627 struct GNUNET_ShortHashCode k;
1628
1629 GNUNET_assert (0 == queue->pwrite_off);
1630 memset (&rekey, 0, sizeof(rekey));
1631 GNUNET_CRYPTO_eddsa_kem_encaps (&queue->target.public_key, &rekey.ephemeral,
1632 &k);
1634 rekey.header.size = ntohs (sizeof(rekey));
1635 rekey.monotonic_time =
1638 thp.purpose.size = htonl (sizeof(thp));
1640 "inject_rekey size %u\n",
1641 thp.purpose.size);
1642 thp.sender = my_identity;
1644 "sender %s\n",
1646 thp.receiver = queue->target;
1648 "receiver %s\n",
1650 thp.ephemeral = rekey.ephemeral;
1652 "ephemeral %s\n",
1654 );
1655 thp.monotonic_time = rekey.monotonic_time;
1657 "time %s\n",
1661 &thp,
1662 &rekey.sender_sig);
1663 calculate_hmac (&queue->out_hmac, &rekey, sizeof(rekey), &rekey.hmac);
1664 /* Encrypt rekey message with 'old' cipher */
1665 GNUNET_assert (0 ==
1666 gcry_cipher_encrypt (queue->out_cipher,
1667 &queue->cwrite_buf[queue->cwrite_off],
1668 sizeof(rekey),
1669 &rekey,
1670 sizeof(rekey)));
1671 queue->cwrite_off += sizeof(rekey);
1672 /* Setup new cipher for successive messages */
1673 gcry_cipher_close (queue->out_cipher);
1674 setup_out_cipher (queue, &k);
1675}
1676
1677
1678static int
1680 const struct GNUNET_HashCode *key,
1681 void *value)
1682{
1683 (void) cls;
1684 struct PendingReversal *pending_reversal = value;
1685
1686 if (NULL != pending_reversal->timeout_task)
1687 {
1688 GNUNET_SCHEDULER_cancel (pending_reversal->timeout_task);
1689 pending_reversal->timeout_task = NULL;
1690 }
1693 key,
1694 pending_reversal));
1695 GNUNET_free (pending_reversal->in);
1696 GNUNET_free (pending_reversal);
1697 return GNUNET_OK;
1698}
1699
1700
1701static void
1702check_and_remove_pending_reversal (struct sockaddr *in, sa_family_t sa_family,
1703 struct GNUNET_PeerIdentity *sender)
1704{
1705 if (AF_INET == sa_family)
1706 {
1707 struct PendingReversal *pending_reversal;
1708 struct GNUNET_HashCode key;
1709 struct sockaddr_in *natted_address;
1710
1711 natted_address = GNUNET_memdup (in, sizeof (struct sockaddr));
1712 natted_address->sin_port = 0;
1713 GNUNET_CRYPTO_hash (natted_address,
1714 sizeof(struct sockaddr),
1715 &key);
1716
1718 &key);
1719 if (NULL != pending_reversal && (NULL == sender ||
1720 0 != memcmp (sender,
1721 &pending_reversal->target,
1722 sizeof(struct
1724 {
1726 "Removing invalid pending reversal for `%s'at `%s'\n",
1727 GNUNET_i2s (&pending_reversal->target),
1728 GNUNET_a2s (in, sizeof (struct sockaddr)));
1729 pending_reversals_delete_it (NULL, &key, pending_reversal);
1730 }
1731 GNUNET_free (natted_address);
1732 }
1733}
1734
1735
1741static void
1743{
1744 if (NULL != pq->listen_sock)
1745 {
1747 pq->listen_sock = NULL;
1748 }
1749 if (NULL != pq->read_task)
1750 {
1752 pq->read_task = NULL;
1753 }
1754 if (NULL != pq->write_task)
1755 {
1757 pq->write_task = NULL;
1758 }
1759 check_and_remove_pending_reversal (pq->address, pq->address->sa_family, NULL);
1761 GNUNET_free (pq->address);
1763 GNUNET_free (pq);
1764}
1765
1766
1773static void
1775{
1776 struct ProtoQueue *pq = cls;
1777 ssize_t sent;
1778 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "In proto queue write\n");
1779 pq->write_task = NULL;
1780 if (0 != pq->write_off)
1781 {
1782 sent = GNUNET_NETWORK_socket_send (pq->sock,
1783 pq->write_buf,
1784 pq->write_off);
1786 "Sent %lu bytes to TCP queue\n", sent);
1787 if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno))
1788 {
1790 free_proto_queue (pq);
1791 return;
1792 }
1793 if (sent > 0)
1794 {
1795 size_t usent = (size_t) sent;
1796 pq->write_off -= usent;
1797 memmove (pq->write_buf,
1798 &pq->write_buf[usent],
1799 pq->write_off);
1800 }
1801 }
1802 /* do we care to write more? */
1803 if ((0 < pq->write_off))
1804 pq->write_task =
1806 pq->sock,
1808 pq);
1809}
1810
1811
1818static void
1819queue_write (void *cls)
1820{
1821 struct Queue *queue = cls;
1822 ssize_t sent;
1823 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "In queue write\n");
1824 queue->write_task = NULL;
1825 if (0 != queue->cwrite_off)
1826 {
1827 sent = GNUNET_NETWORK_socket_send (queue->sock,
1828 queue->cwrite_buf,
1829 queue->cwrite_off);
1831 "Sent %lu bytes to TCP queue\n", sent);
1832 if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno))
1833 {
1836 return;
1837 }
1838 if (sent > 0)
1839 {
1840 size_t usent = (size_t) sent;
1841 queue->cwrite_off -= usent;
1842 memmove (queue->cwrite_buf,
1843 &queue->cwrite_buf[usent],
1844 queue->cwrite_off);
1845 queue->timeout =
1848 }
1849 }
1850 /* can we encrypt more? (always encrypt full messages, needed
1851 such that #mq_cancel() can work!) */
1852 unsigned int we_do_not_need_to_rekey = (0 < queue->rekey_left_bytes
1853 - (queue->cwrite_off
1854 + queue->pwrite_off
1855 + sizeof (struct TCPRekey)));
1856 if (we_do_not_need_to_rekey &&
1857 (queue->pwrite_off > 0) &&
1858 (queue->cwrite_off + queue->pwrite_off <= BUF_SIZE))
1859 {
1861 "Encrypting %lu bytes\n", queue->pwrite_off);
1862 GNUNET_assert (0 ==
1863 gcry_cipher_encrypt (queue->out_cipher,
1864 &queue->cwrite_buf[queue->cwrite_off],
1865 queue->pwrite_off,
1866 queue->pwrite_buf,
1867 queue->pwrite_off));
1868 if (queue->rekey_left_bytes > queue->pwrite_off)
1869 queue->rekey_left_bytes -= queue->pwrite_off;
1870 else
1871 queue->rekey_left_bytes = 0;
1872 queue->cwrite_off += queue->pwrite_off;
1873 queue->pwrite_off = 0;
1874 }
1875 // if ((-1 != unverified_size)&& ((0 == queue->pwrite_off) &&
1876 if (((0 == queue->rekey_left_bytes) ||
1878 queue->rekey_time).rel_value_us)) &&
1879 (((0 == queue->pwrite_off) || ! we_do_not_need_to_rekey) &&
1880 (queue->cwrite_off + sizeof (struct TCPRekey) <= BUF_SIZE)))
1881 {
1883 }
1884 if ((0 == queue->pwrite_off) && (! queue->finishing) &&
1885 (GNUNET_YES == queue->mq_awaits_continue))
1886 {
1887 queue->mq_awaits_continue = GNUNET_NO;
1889 }
1890 /* did we just finish writing 'finish'? */
1891 if ((0 == queue->cwrite_off) && (GNUNET_YES == queue->finishing))
1892 {
1894 "Finishing queue\n");
1896 return;
1897 }
1898 /* do we care to write more? */
1899 if ((0 < queue->cwrite_off) || (0 < queue->pwrite_off))
1900 queue->write_task =
1902 queue->sock,
1903 &queue_write,
1904 queue);
1905}
1906
1907
1915static size_t
1917{
1918 const struct GNUNET_MessageHeader *hdr;
1919 const struct TCPConfirmationAck *tca;
1920 const struct TCPBox *box;
1921 const struct TCPRekey *rekey;
1922 const struct TCPFinish *fin;
1923 struct TCPRekey rekeyz;
1924 struct TCPFinish finz;
1925 struct GNUNET_ShortHashCode tmac;
1926 uint16_t type;
1927 size_t size = 0;
1928 struct TcpHandshakeAckSignature thas;
1929 const struct GNUNET_CRYPTO_ChallengeNonceP challenge = queue->challenge;
1930
1932 "try handle plaintext!\n");
1933
1934 hdr = (const struct GNUNET_MessageHeader *) queue->pread_buf;
1935 if ((sizeof(*hdr) > queue->pread_off))
1936 {
1938 "Handling plaintext, not even a header!\n");
1939 return 0; /* not even a header */
1940 }
1941
1942 if ((GNUNET_YES != queue->initial_core_kx_done) && (queue->unverified_size >
1944 {
1946 "Already received data of size %lu bigger than KX size %lu!\n",
1947 queue->unverified_size,
1949 GNUNET_break_op (0);
1951 return 0;
1952 }
1953
1954 type = ntohs (hdr->type);
1955 switch (type)
1956 {
1958 tca = (const struct TCPConfirmationAck *) queue->pread_buf;
1960 "start processing ack\n");
1961 if (sizeof(*tca) > queue->pread_off)
1962 {
1964 "Handling plaintext size of tca greater than pread offset.\n")
1965 ;
1966 return 0;
1967 }
1968 if (ntohs (hdr->size) != sizeof(*tca))
1969 {
1971 "Handling plaintext size does not match message type.\n");
1972 GNUNET_break_op (0);
1974 return 0;
1975 }
1976
1977 thas.purpose.purpose = htonl (
1979 thas.purpose.size = htonl (sizeof(thas));
1980 thas.sender = tca->sender;
1981 thas.receiver = my_identity;
1982 thas.monotonic_time = tca->monotonic_time;
1983 thas.challenge = tca->challenge;
1984
1987 &thas,
1988 &tca->sender_sig,
1989 &tca->sender.public_key))
1990 {
1992 "Verification of signature failed!\n");
1993 GNUNET_break (0);
1995 return 0;
1996 }
1997 if (0 != GNUNET_memcmp (&tca->challenge, &challenge))
1998 {
2000 "Challenge in TCPConfirmationAck not correct!\n");
2001 GNUNET_break (0);
2003 return 0;
2004 }
2005
2006 queue->handshake_ack_monotime_get = GNUNET_PEERSTORE_iteration_start (
2007 peerstore,
2008 "transport_tcp_communicator",
2009 &queue->target,
2012 queue);
2013
2015 "Handling plaintext, ack processed!\n");
2016
2018 {
2019 send_challenge (queue->challenge_received, queue);
2020 queue->write_task =
2022 queue->sock,
2023 &queue_write,
2024 queue);
2025 }
2026 else if (GNUNET_TRANSPORT_CS_OUTBOUND == queue->cs)
2027 {
2029 queue->address->sa_family, NULL);
2030 }
2031
2036 queue->initial_core_kx_done = GNUNET_YES;
2037
2038 char *foreign_addr;
2039
2040 switch (queue->address->sa_family)
2041 {
2042 case AF_INET:
2043 GNUNET_asprintf (&foreign_addr,
2044 "%s-%s",
2046 GNUNET_a2s (queue->address, queue->address_len));
2047 break;
2048
2049 case AF_INET6:
2050 GNUNET_asprintf (&foreign_addr,
2051 "%s-%s",
2053 GNUNET_a2s (queue->address, queue->address_len));
2054 break;
2055
2056 default:
2057 GNUNET_assert (0);
2058 }
2059
2061 &queue->target,
2062 foreign_addr,
2063 UINT16_MAX, /* no MTU */
2065 0, /* Priority */
2066 queue->nt,
2067 queue->cs,
2068 queue->mq);
2069
2070 GNUNET_free (foreign_addr);
2071
2072 size = ntohs (hdr->size);
2073 break;
2075 /* Special case: header size excludes box itself! */
2076 box = (const struct TCPBox *) queue->pread_buf;
2077 if (ntohs (hdr->size) + sizeof(struct TCPBox) > queue->pread_off)
2078 return 0;
2079 calculate_hmac (&queue->in_hmac, &box[1], ntohs (hdr->size), &tmac);
2080 if (0 != memcmp (&tmac, &box->hmac, sizeof(tmac)))
2081 {
2082 GNUNET_break_op (0);
2084 return 0;
2085 }
2086 pass_plaintext_to_core (queue, (const void *) &box[1], ntohs (hdr->size));
2087 size = ntohs (hdr->size) + sizeof(*box);
2089 "Handling plaintext, box processed!\n");
2091 "# bytes decrypted with BOX",
2092 size,
2093 GNUNET_NO);
2095 "# messages decrypted with BOX",
2096 1,
2097 GNUNET_NO);
2098 break;
2099
2101 rekey = (const struct TCPRekey *) queue->pread_buf;
2102 if (sizeof(*rekey) > queue->pread_off)
2103 return 0;
2104 if (ntohs (hdr->size) != sizeof(*rekey))
2105 {
2106 GNUNET_break_op (0);
2108 return 0;
2109 }
2110 rekeyz = *rekey;
2111 memset (&rekeyz.hmac, 0, sizeof(rekeyz.hmac));
2112 calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
2113 if (0 != memcmp (&tmac, &rekey->hmac, sizeof(tmac)))
2114 {
2115 GNUNET_break_op (0);
2117 return 0;
2118 }
2119 do_rekey (queue, rekey);
2120 size = ntohs (hdr->size);
2122 "Handling plaintext, rekey processed!\n");
2124 "# rekeying successful",
2125 1,
2126 GNUNET_NO);
2127 break;
2128
2130 fin = (const struct TCPFinish *) queue->pread_buf;
2131 if (sizeof(*fin) > queue->pread_off)
2132 return 0;
2133 if (ntohs (hdr->size) != sizeof(*fin))
2134 {
2135 GNUNET_break_op (0);
2137 return 0;
2138 }
2139 finz = *fin;
2140 memset (&finz.hmac, 0, sizeof(finz.hmac));
2141 calculate_hmac (&queue->in_hmac, &finz, sizeof(finz), &tmac);
2142 if (0 != memcmp (&tmac, &fin->hmac, sizeof(tmac)))
2143 {
2144 GNUNET_break_op (0);
2146 return 0;
2147 }
2148 /* handle FINISH by destroying queue */
2151 "Handling plaintext, finish processed!\n");
2152 break;
2153
2154 default:
2156 "Handling plaintext, nothing processed!\n");
2157 GNUNET_break_op (0);
2159 return 0;
2160 }
2161 GNUNET_assert (0 != size);
2162 if (-1 != queue->unverified_size)
2163 queue->unverified_size += size;
2164 return size;
2165}
2166
2167
2173static void
2174queue_read (void *cls)
2175{
2176 struct Queue *queue = cls;
2177 struct GNUNET_TIME_Relative left;
2178 ssize_t rcvd;
2179
2180 queue->read_task = NULL;
2181 rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
2182 &queue->cread_buf[queue->cread_off],
2183 BUF_SIZE - queue->cread_off);
2185 "Received %zd bytes from TCP queue\n", rcvd);
2186 if (-1 == rcvd)
2187 {
2188 if ((EAGAIN != errno) && (EINTR != errno))
2189 {
2192 return;
2193 }
2194 /* try again */
2195 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
2196 if (0 != left.rel_value_us)
2197 {
2198 queue->read_task =
2200 return;
2201 }
2203 "Queue %p was idle for %s, disconnecting\n",
2204 queue,
2207 GNUNET_YES));
2209 return;
2210 }
2211 if (0 == rcvd)
2212 {
2213 /* Orderly shutdown of connection */
2215 "Socket for queue %p seems to have been closed\n", queue);
2217 return;
2218 }
2219 queue->timeout =
2221 queue->cread_off += rcvd;
2222 while ((queue->pread_off < sizeof(queue->pread_buf)) &&
2223 (queue->cread_off > 0))
2224 {
2225 size_t max = GNUNET_MIN (sizeof(queue->pread_buf) - queue->pread_off,
2226 queue->cread_off);
2227 size_t done;
2228 size_t total;
2229 size_t old_pread_off = queue->pread_off;
2230
2231 GNUNET_assert (0 ==
2232 gcry_cipher_decrypt (queue->in_cipher,
2233 &queue->pread_buf[queue->pread_off],
2234 max,
2235 queue->cread_buf,
2236 max));
2237 queue->pread_off += max;
2238 total = 0;
2239 while (0 != (done = try_handle_plaintext (queue)))
2240 {
2241 /* 'done' bytes of plaintext were used, shift buffer */
2242 GNUNET_assert (done <= queue->pread_off);
2243 /* NOTE: this memmove() could possibly sometimes be
2244 avoided if we pass 'total' into try_handle_plaintext()
2245 and use it at an offset into the buffer there! */
2246 memmove (queue->pread_buf,
2247 &queue->pread_buf[done],
2248 queue->pread_off - done);
2249 queue->pread_off -= done;
2250 total += done;
2251 /* The last plaintext was a rekey, abort for now */
2252 if (GNUNET_YES == queue->rekeyed)
2253 break;
2254 }
2255 /* when we encounter a rekey message, the decryption above uses the
2256 wrong key for everything after the rekey; in that case, we have
2257 to re-do the decryption at 'total' instead of at 'max'.
2258 However, we have to take into account that the plaintext buffer may have
2259 already contained data and not jumped too far ahead in the ciphertext.
2260 If there is no rekey and the last message is incomplete (max > total),
2261 it is safe to keep the decryption so we shift by 'max' */
2262 if (GNUNET_YES == queue->rekeyed)
2263 {
2264 max = total - old_pread_off;
2265 queue->rekeyed = GNUNET_NO;
2266 queue->pread_off = 0;
2267 }
2268 memmove (queue->cread_buf, &queue->cread_buf[max], queue->cread_off - max);
2269 queue->cread_off -= max;
2270 }
2271 if (BUF_SIZE == queue->cread_off)
2272 return; /* buffer full, suspend reading */
2273 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
2274 if (0 != left.rel_value_us)
2275 {
2276 if (max_queue_length > queue->backpressure)
2277 {
2278 /* continue reading */
2279 queue->read_task =
2281 }
2282 return;
2283 }
2285 "Queue %p was idle for %s, disconnecting\n",
2286 queue,
2289 GNUNET_YES));
2291}
2292
2293
2301static struct sockaddr *
2303 struct sockaddr_in6 v6,
2304 unsigned int port)
2305{
2306 struct sockaddr *in;
2307
2308 v6.sin6_family = AF_INET6;
2309 v6.sin6_port = htons ((uint16_t) port);
2310#if HAVE_SOCKADDR_IN_SIN_LEN
2311 v6.sin6_len = sizeof(struct sockaddr_in6);
2312#endif
2313 v6.sin6_flowinfo = 0;
2314 v6.sin6_scope_id = 0;
2315 in = GNUNET_memdup (&v6, sizeof(v6));
2316 *sock_len = sizeof(struct sockaddr_in6);
2317
2318 return in;
2319}
2320
2321
2329static struct sockaddr *
2331 struct sockaddr_in v4,
2332 unsigned int port)
2333{
2334 struct sockaddr *in;
2335
2336 v4.sin_family = AF_INET;
2337 v4.sin_port = htons ((uint16_t) port);
2338#if HAVE_SOCKADDR_IN_SIN_LEN
2339 v4.sin_len = sizeof(struct sockaddr_in);
2340#endif
2341 in = GNUNET_memdup (&v4, sizeof(v4));
2342 *sock_len = sizeof(struct sockaddr_in);
2343 return in;
2344}
2345
2346
2353static struct PortOnlyIpv4Ipv6 *
2354tcp_address_to_sockaddr_port_only (const char *bindto, unsigned int *port)
2355{
2356 struct PortOnlyIpv4Ipv6 *po;
2357 struct sockaddr_in *i4;
2358 struct sockaddr_in6 *i6;
2359 socklen_t sock_len_ipv4;
2360 socklen_t sock_len_ipv6;
2361
2362 /* interpreting value as just a PORT number */
2363 if (*port > UINT16_MAX)
2364 {
2366 "BINDTO specification `%s' invalid: value too large for port\n",
2367 bindto);
2368 return NULL;
2369 }
2370
2371 po = GNUNET_new (struct PortOnlyIpv4Ipv6);
2372
2373 if (GNUNET_YES == disable_v6)
2374 {
2375 i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
2376 po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
2377 *port);
2378 po->addr_len_ipv4 = sock_len_ipv4;
2379 }
2380 else
2381 {
2382
2383 i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
2384 po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
2385 *port);
2386 po->addr_len_ipv4 = sock_len_ipv4;
2387
2388 i6 = GNUNET_malloc (sizeof(struct sockaddr_in6));
2389 po->addr_ipv6 = tcp_address_to_sockaddr_numeric_v6 (&sock_len_ipv6, *i6,
2390 *port);
2391
2392 po->addr_len_ipv6 = sock_len_ipv6;
2393
2394 GNUNET_free (i6);
2395 }
2396
2397 GNUNET_free (i4);
2398
2399 return po;
2400}
2401
2402
2409static char *
2410extract_address (const char *bindto)
2411{
2412 char *addr;
2413 char *start;
2414 char *token;
2415 char *cp;
2416 char *rest = NULL;
2417
2419 "extract address with bindto %s\n",
2420 bindto);
2421
2422 if (NULL == bindto)
2424 "bindto is NULL\n");
2425
2426 cp = GNUNET_strdup (bindto);
2427
2429 "extract address 2\n");
2430
2431 start = cp;
2432 if (('[' == *cp) && (']' == cp[strlen (cp) - 1]))
2433 {
2434 start++; /* skip over '['*/
2435 cp[strlen (cp) - 1] = '\0'; /* eat ']'*/
2436 addr = GNUNET_strdup (start);
2437 }
2438 else
2439 {
2440 token = strtok_r (cp, "]", &rest);
2441 if (strlen (bindto) == strlen (token))
2442 {
2443 token = strtok_r (cp, ":", &rest);
2444 addr = GNUNET_strdup (token);
2445 }
2446 else
2447 {
2448 token++;
2449 addr = GNUNET_strdup (token);
2450 }
2451 }
2452
2454 "tcp address: %s\n",
2455 addr);
2456 GNUNET_free (cp);
2457 return addr;
2458}
2459
2460
2467static unsigned int
2468extract_port (const char *addr_and_port)
2469{
2470 unsigned int port;
2471 char dummy[2];
2472 char *token;
2473 char *addr;
2474 char *colon;
2475 char *cp;
2476 char *rest = NULL;
2477
2478 if (NULL != addr_and_port)
2479 {
2480 cp = GNUNET_strdup (addr_and_port);
2481 token = strtok_r (cp, "]", &rest);
2482 if (strlen (addr_and_port) == strlen (token))
2483 {
2484 colon = strrchr (cp, ':');
2485 if (NULL == colon)
2486 {
2487 GNUNET_free (cp);
2488 return 0;
2489 }
2490 addr = colon;
2491 addr++;
2492 }
2493 else
2494 {
2495 token = strtok_r (NULL, "]", &rest);
2496 if (NULL == token)
2497 {
2498 GNUNET_free (cp);
2499 return 0;
2500 }
2501 else
2502 {
2503 addr = token;
2504 addr++;
2505 }
2506 }
2507
2508
2509 if (1 == sscanf (addr, "%u%1s", &port, dummy))
2510 {
2511 /* interpreting value as just a PORT number */
2512 if (port > UINT16_MAX)
2513 {
2515 "Port `%u' invalid: value too large for port\n",
2516 port);
2517 GNUNET_free (cp);
2518 return 0;
2519 }
2520 }
2521 else
2522 {
2524 "BINDTO specification invalid: last ':' not followed by number\n");
2525 GNUNET_free (cp);
2526 return 0;
2527 }
2528 GNUNET_free (cp);
2529 }
2530 else
2531 {
2533 "return 0\n");
2534 /* interpret missing port as 0, aka pick any free one */
2535 port = 0;
2536 }
2537
2538 return port;
2539}
2540
2541
2549static struct sockaddr *
2550tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
2551{
2552 struct sockaddr *in;
2553 unsigned int port;
2554 struct sockaddr_in v4;
2555 struct sockaddr_in6 v6;
2556 char *start;
2557
2558 memset (&v4, 0, sizeof(v4));
2559 start = extract_address (bindto);
2560 GNUNET_assert (NULL != start);
2562 "start %s\n",
2563 start);
2564
2566 "!bindto %s\n",
2567 bindto);
2568
2569
2570 if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
2571 {
2572 port = extract_port (bindto);
2573
2575 "port %u\n",
2576 port);
2577
2578 in = tcp_address_to_sockaddr_numeric_v4 (sock_len, v4, port);
2579 }
2580 else if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
2581 {
2582 port = extract_port (bindto);
2583 in = tcp_address_to_sockaddr_numeric_v6 (sock_len, v6, port);
2584 }
2585 else
2586 {
2587 GNUNET_assert (0);
2588 }
2589
2591 return in;
2592}
2593
2594
2603static void
2605 const struct GNUNET_MessageHeader *msg,
2606 void *impl_state)
2607{
2608 struct Queue *queue = impl_state;
2609 uint16_t msize = ntohs (msg->size);
2610 struct TCPBox box;
2612 "In MQ send. Queue finishing: %s; write task running: %s\n",
2613 (GNUNET_YES == queue->finishing) ? "yes" : "no",
2614 (NULL == queue->write_task) ? "yes" : "no");
2615 GNUNET_assert (mq == queue->mq);
2616 queue->mq_awaits_continue = GNUNET_YES;
2617 if (GNUNET_YES == queue->finishing)
2618 return; /* this queue is dying, drop msg */
2619 GNUNET_assert (0 == queue->pwrite_off);
2621 box.header.size = htons (msize);
2622 calculate_hmac (&queue->out_hmac, msg, msize, &box.hmac);
2623 memcpy (&queue->pwrite_buf[queue->pwrite_off], &box, sizeof(box));
2624 queue->pwrite_off += sizeof(box);
2625 memcpy (&queue->pwrite_buf[queue->pwrite_off], msg, msize);
2626 queue->pwrite_off += msize;
2628 "%lu bytes of plaintext to send\n", queue->pwrite_off);
2629 GNUNET_assert (NULL != queue->sock);
2630 if (NULL == queue->write_task)
2631 queue->write_task =
2633 queue->sock,
2634 &queue_write,
2635 queue);
2636}
2637
2638
2647static void
2648mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state)
2649{
2650 struct Queue *queue = impl_state;
2651
2652 if (mq == queue->mq)
2653 {
2654 queue->mq = NULL;
2656 }
2657}
2658
2659
2666static void
2667mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
2668{
2669 struct Queue *queue = impl_state;
2670
2671 GNUNET_assert (0 != queue->pwrite_off);
2672 queue->pwrite_off = 0;
2673}
2674
2675
2685static void
2686mq_error (void *cls, enum GNUNET_MQ_Error error)
2687{
2688 struct Queue *queue = cls;
2689
2691 "MQ error in queue to %s: %d\n",
2692 GNUNET_i2s (&queue->target),
2693 (int) error);
2695}
2696
2697
2705static void
2707{
2708 queue->nt =
2709 GNUNET_NT_scanner_get_type (is, queue->address, queue->address_len);
2711 queue_map,
2712 &queue->key,
2713 queue,
2716 "# queues active",
2718 GNUNET_NO);
2719 queue->timeout =
2722 &mq_destroy,
2723 &mq_cancel,
2724 queue,
2725 NULL,
2726 &mq_error,
2727 queue);
2728}
2729
2730
2741static void
2743 const struct GNUNET_CRYPTO_HpkeEncapsulation *c)
2744{
2745 struct TcpHandshakeSignature ths;
2746 struct TCPConfirmation tc;
2747
2748 memcpy (queue->cwrite_buf, c, sizeof(*c));
2749 queue->cwrite_off = sizeof(*c);
2750 /* compute 'tc' and append in encrypted format to cwrite_buf */
2751 tc.sender = my_identity;
2752 tc.monotonic_time =
2755 &tc.challenge,
2756 sizeof(tc.challenge));
2757 ths.purpose.purpose = htonl (
2759 ths.purpose.size = htonl (sizeof(ths));
2760 ths.sender = my_identity;
2761 ths.receiver = queue->target;
2762 ths.ephemeral = *c;
2763 ths.monotonic_time = tc.monotonic_time;
2764 ths.challenge = tc.challenge;
2766 &ths,
2767 &tc.sender_sig);
2768 GNUNET_assert (0 ==
2769 gcry_cipher_encrypt (queue->out_cipher,
2770 &queue->cwrite_buf[queue->cwrite_off],
2771 sizeof(tc),
2772 &tc,
2773 sizeof(tc)));
2774 queue->challenge = tc.challenge;
2775 queue->cwrite_off += sizeof(tc);
2776
2778 "handshake written\n");
2779}
2780
2781
2789static void
2791{
2793 struct GNUNET_ShortHashCode k;
2794
2796 &c, &k);
2797 setup_out_cipher (queue, &k);
2798 transmit_kx (queue, &c);
2799}
2800
2801
2807static void
2808handshake_monotime_store_cb (void *cls, int success)
2809{
2810 struct Queue *queue = cls;
2811 if (GNUNET_OK != success)
2812 {
2814 "Failed to store handshake monotonic time in PEERSTORE!\n");
2815 }
2816 queue->handshake_monotime_sc = NULL;
2817 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
2818}
2819
2820
2828static void
2830 const struct GNUNET_PEERSTORE_Record *record,
2831 const char *emsg)
2832{
2833 struct Queue *queue = cls;
2834 struct GNUNET_TIME_AbsoluteNBO *mtbe;
2835 struct GNUNET_TIME_Absolute mt;
2836 const struct GNUNET_PeerIdentity *pid;
2837 struct GNUNET_TIME_AbsoluteNBO *handshake_monotonic_time;
2838
2839 (void) emsg;
2840
2841 handshake_monotonic_time = &queue->handshake_monotonic_time;
2842 pid = &queue->target;
2844 "tcp handshake with us %s\n",
2846 if (NULL == record)
2847 {
2848 queue->handshake_monotime_get = NULL;
2849 return;
2850 }
2852 "tcp handshake from peer %s\n",
2853 GNUNET_i2s (pid));
2854 if (sizeof(*mtbe) != record->value_size)
2855 {
2856 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
2857 GNUNET_break (0);
2858 return;
2859 }
2860 mtbe = record->value;
2861 mt = GNUNET_TIME_absolute_ntoh (*mtbe);
2863 queue->handshake_monotonic_time).abs_value_us)
2864 {
2866 "Queue from %s dropped, handshake monotime in the past\n",
2867 GNUNET_i2s (&queue->target));
2868 GNUNET_break (0);
2869 GNUNET_PEERSTORE_iteration_stop (queue->handshake_ack_monotime_get);
2870 queue->handshake_ack_monotime_get = NULL;
2872 return;
2873 }
2874 queue->handshake_monotime_sc = GNUNET_PEERSTORE_store (peerstore,
2875 "transport_tcp_communicator",
2876 pid,
2878 handshake_monotonic_time,
2879 sizeof(*
2880 handshake_monotonic_time),
2883 &
2885 queue);
2886}
2887
2888
2900static int
2902 struct TCPConfirmation *tc,
2903 char *ibuf)
2904{
2905 struct TcpHandshakeSignature ths;
2907
2909 0 ==
2910 gcry_cipher_decrypt (queue->in_cipher,
2911 tc,
2912 sizeof(*tc),
2913 &ibuf[sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)],
2914 sizeof(*tc)));
2915 ths.purpose.purpose = htonl (
2917 ths.purpose.size = htonl (sizeof(ths));
2918 ths.sender = tc->sender;
2919 ths.receiver = my_identity;
2920 memcpy (&ths.ephemeral, ibuf, sizeof(struct GNUNET_CRYPTO_EcdhePublicKey));
2921 ths.monotonic_time = tc->monotonic_time;
2922 ths.challenge = tc->challenge;
2925 &ths,
2926 &tc->sender_sig,
2927 &tc->sender.public_key);
2928 if (GNUNET_YES == ret)
2929 queue->handshake_monotime_get =
2931 "transport_tcp_communicator",
2932 &queue->target,
2935 queue);
2936 return ret;
2937}
2938
2939
2947static void
2948queue_read_kx (void *cls)
2949{
2950 struct Queue *queue = cls;
2951 ssize_t rcvd;
2952 struct GNUNET_TIME_Relative left;
2953 struct TCPConfirmation tc;
2954
2955 queue->read_task = NULL;
2956 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
2957 if (0 == left.rel_value_us)
2958 {
2960 return;
2961 }
2962 rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
2963 &queue->cread_buf[queue->cread_off],
2964 BUF_SIZE - queue->cread_off);
2966 "Received %lu bytes to write in buffer of size %lu for KX from queue %p (expires in %"
2967 PRIu64 ")\n",
2968 rcvd, BUF_SIZE - queue->cread_off, queue, left.rel_value_us);
2969 if (-1 == rcvd)
2970 {
2971 if ((EAGAIN != errno) && (EINTR != errno))
2972 {
2975 return;
2976 }
2977 queue->read_task =
2979 return;
2980 }
2981 if (0 == rcvd)
2982 {
2983 /* Orderly shutdown of connection */
2985 "Socket for queue %p seems to have been closed\n", queue);
2987 return;
2988 }
2989 queue->cread_off += rcvd;
2990 if (queue->cread_off < INITIAL_KX_SIZE)
2991 {
2992 /* read more */
2994 "%lu/%lu bytes of KX read. Rescheduling...\n",
2995 queue->cread_off, INITIAL_KX_SIZE);
2996 queue->read_task =
2998 return;
2999 }
3000 /* we got all the data, let's find out who we are talking to! */
3002 (const struct GNUNET_CRYPTO_HpkeEncapsulation*)
3003 queue->cread_buf,
3004 queue);
3005 if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, queue->cread_buf))
3006 {
3008 "Invalid TCP KX received from %s\n",
3009 GNUNET_a2s (queue->address, queue->address_len));
3011 return;
3012 }
3013 if (0 !=
3014 memcmp (&tc.sender, &queue->target, sizeof(struct GNUNET_PeerIdentity)))
3015 {
3017 "Invalid sender in TCP KX received from %s\n",
3018 GNUNET_a2s (queue->address, queue->address_len));
3020 return;
3021 }
3022 send_challenge (tc.challenge, queue);
3023 queue->write_task =
3025 queue->sock,
3026 &queue_write,
3027 queue);
3028
3029 /* update queue timeout */
3030 queue->timeout =
3032 /* prepare to continue with regular read task immediately */
3033 memmove (queue->cread_buf,
3034 &queue->cread_buf[INITIAL_KX_SIZE],
3035 queue->cread_off - (INITIAL_KX_SIZE));
3037 "cread_off is %lu bytes before adjusting\n",
3038 queue->cread_off);
3039 queue->cread_off -= INITIAL_KX_SIZE;
3041 "cread_off set to %lu bytes\n",
3042 queue->cread_off);
3044}
3045
3046
3053static void
3054proto_read_kx (void *cls)
3055{
3056 struct ProtoQueue *pq = cls;
3057 ssize_t rcvd;
3058 struct GNUNET_TIME_Relative left;
3059 struct Queue *queue;
3060 struct TCPConfirmation tc;
3062
3063 pq->read_task = NULL;
3065 if (0 == left.rel_value_us)
3066 {
3067 free_proto_queue (pq);
3068 return;
3069 }
3070 rcvd = GNUNET_NETWORK_socket_recv (pq->sock,
3071 &pq->ibuf[pq->ibuf_off],
3072 sizeof(pq->ibuf) - pq->ibuf_off);
3074 "Proto received %lu bytes for KX\n", rcvd);
3075 if (-1 == rcvd)
3076 {
3077 if ((EAGAIN != errno) && (EINTR != errno))
3078 {
3080 free_proto_queue (pq);
3081 return;
3082 }
3083 /* try again */
3084 pq->read_task =
3086 return;
3087 }
3088 if (0 == rcvd)
3089 {
3090 /* Orderly shutdown of connection */
3092 "Socket for proto queue %p seems to have been closed\n", pq);
3093 free_proto_queue (pq);
3094 return;
3095 }
3096 pq->ibuf_off += rcvd;
3097 if (sizeof (struct TCPNATProbeMessage) == pq->ibuf_off)
3098 {
3099 struct TCPNATProbeMessage *pm = (struct TCPNATProbeMessage *) pq->ibuf;
3100
3102 &pm->clientIdentity);
3103
3104 queue = GNUNET_new (struct Queue);
3105 queue->target = pm->clientIdentity;
3106 eddsa_pub_to_hpke_key (&queue->target.public_key, &queue->target_hpke_key);
3109 }
3110 else if (pq->ibuf_off > sizeof(pq->ibuf))
3111 {
3112 /* read more */
3113 pq->read_task =
3115 return;
3116 }
3117 else
3118 {
3119 /* we got all the data, let's find out who we are talking to! */
3120 queue = GNUNET_new (struct Queue);
3122 (const struct GNUNET_CRYPTO_HpkeEncapsulation *) pq->
3123 ibuf,
3124 queue);
3125 if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, pq->ibuf))
3126 {
3128 "Invalid TCP KX received from %s\n",
3129 GNUNET_a2s (pq->address, pq->address_len));
3130 gcry_cipher_close (queue->in_cipher);
3132 free_proto_queue (pq);
3133 return;
3134 }
3135 queue->target = tc.sender;
3136 eddsa_pub_to_hpke_key (&queue->target.public_key, &queue->target_hpke_key);
3139 }
3140 queue->address = pq->address; /* steals reference */
3141 queue->address_len = pq->address_len;
3142 queue->listen_sock = pq->listen_sock;
3143 queue->sock = pq->sock;
3144
3146 "created queue with target %s\n",
3147 GNUNET_i2s (&queue->target));
3148
3150 "start kx proto\n");
3151
3153 boot_queue (queue);
3154 queue->read_task =
3156 queue->sock,
3157 read_task,
3158 queue);
3159 queue->write_task =
3161 queue->sock,
3162 &queue_write,
3163 queue);
3164 // TODO To early! Move it somewhere else.
3165 // send_challenge (tc.challenge, queue);
3166 queue->challenge_received = tc.challenge;
3167
3169 GNUNET_free (pq);
3170}
3171
3172
3173static struct ProtoQueue *
3175 struct sockaddr *in,
3176 socklen_t addrlen)
3177{
3178 struct ProtoQueue *pq = GNUNET_new (struct ProtoQueue);
3179
3180 if (NULL == sock)
3181 {
3182 // sock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET, addr, addrlen);
3183 sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, 0);
3184 if (NULL == sock)
3185 {
3187 "socket(%d) failed: %s",
3188 in->sa_family,
3189 strerror (errno));
3190 GNUNET_free (in);
3191 GNUNET_free (pq);
3192 return NULL;
3193 }
3194 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, addrlen)) &&
3195 (errno != EINPROGRESS))
3196 {
3198 "connect to `%s' failed: %s",
3199 GNUNET_a2s (in, addrlen),
3200 strerror (errno));
3202 GNUNET_free (in);
3203 GNUNET_free (pq);
3204 return NULL;
3205 }
3206 }
3207 pq->address_len = addrlen;
3208 pq->address = in;
3210 pq->sock = sock;
3212 pq->sock,
3214 pq);
3216
3217 return pq;
3218}
3219
3220
3228static void
3229listen_cb (void *cls)
3230{
3231 struct sockaddr_storage in;
3232 socklen_t addrlen;
3233 struct GNUNET_NETWORK_Handle *sock;
3234 struct ListenTask *lt;
3235 struct sockaddr *in_addr;
3236
3238 "listen_cb\n");
3239
3240 lt = cls;
3241
3242 lt->listen_task = NULL;
3243 GNUNET_assert (NULL != lt->listen_sock);
3244 addrlen = sizeof(in);
3245 memset (&in, 0, sizeof(in));
3247 (struct sockaddr*) &in,
3248 &addrlen);
3249 if ((NULL == sock) && ((EMFILE == errno) || (ENFILE == errno)))
3250 return; /* system limit reached, wait until connection goes down */
3252 lt->listen_sock,
3253 &listen_cb,
3254 lt);
3255 if ((NULL == sock) && ((EAGAIN == errno) || (ENOBUFS == errno)))
3256 return;
3257 if (NULL == sock)
3258 {
3260 return;
3261 }
3262 in_addr = GNUNET_memdup (&in, addrlen);
3263 create_proto_queue (sock, in_addr, addrlen);
3264}
3265
3266
3267static void
3269 const struct sockaddr *addr,
3270 socklen_t addrlen)
3271{
3272 (void) cls;
3273 struct TCPNATProbeMessage pm;
3274 struct ProtoQueue *pq;
3275 struct sockaddr *in_addr;
3276
3278 "addr->sa_family %d\n",
3279 addr->sa_family);
3281 "Try to connect back\n");
3282 in_addr = GNUNET_memdup (addr, addrlen);
3284 "in_addr->sa_family %d\n",
3285 in_addr->sa_family);
3286 pq = create_proto_queue (NULL, in_addr, addrlen);
3287 if (NULL != pq)
3288 {
3289 pm.header.size = htons (sizeof(struct TCPNATProbeMessage));
3290 pm.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE);
3291 pm.clientIdentity = my_identity;
3292 memcpy (pq->write_buf, &pm, sizeof(struct TCPNATProbeMessage));
3293 pq->write_off = sizeof(struct TCPNATProbeMessage);
3295 pq->sock,
3297 pq);
3298 }
3299 else
3300 {
3302 "Couldn't create ProtoQueue for sending TCPNATProbeMessage\n");
3303 }
3304}
3305
3306
3307static void
3309{
3310 struct sockaddr *in = cls;
3311 struct PendingReversal *pending_reversal;
3312 struct GNUNET_HashCode key;
3313
3315 sizeof(struct sockaddr),
3316 &key);
3318 &key);
3319
3320 GNUNET_assert (NULL != pending_reversal);
3321
3323 &key,
3324 pending_reversal))
3326 "No pending reversal found for address %s\n",
3327 GNUNET_a2s (in, sizeof (struct sockaddr)));
3328 GNUNET_free (pending_reversal->in);
3329 GNUNET_free (pending_reversal);
3330}
3331
3332
3351static int
3352mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
3353{
3354 struct sockaddr *in;
3355 socklen_t in_len = 0;
3356 const char *path;
3357 struct sockaddr_in *v4;
3358 struct sockaddr_in6 *v6;
3359 unsigned int is_natd = GNUNET_NO;
3360 struct GNUNET_HashCode key;
3361 struct GNUNET_HashCode queue_map_key;
3362 struct GNUNET_HashContext *hsh;
3363 struct Queue *queue;
3364
3366 "Connecting to %s at %s\n",
3367 GNUNET_i2s (peer),
3368 address);
3369 if (0 != strncmp (address,
3371 strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
3372 {
3373 GNUNET_break_op (0);
3374 return GNUNET_SYSERR;
3375 }
3376 path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
3377 in = tcp_address_to_sockaddr (path, &in_len);
3378
3379 if (NULL == in)
3380 {
3382 "Failed to setup TCP socket address\n");
3383 return GNUNET_SYSERR;
3384 }
3385
3387 "in %s\n",
3388 GNUNET_a2s (in, in_len));
3389
3392 GNUNET_CRYPTO_hash_context_read (hsh, peer, sizeof (*peer));
3393 GNUNET_CRYPTO_hash_context_finish (hsh, &queue_map_key);
3395
3396 if (NULL != queue)
3397 {
3399 "Queue for %s already exists or is in construction\n", address);
3400 GNUNET_free (in);
3401 return GNUNET_NO;
3402 }
3403 switch (in->sa_family)
3404 {
3405 case AF_INET:
3406 v4 = (struct sockaddr_in *) in;
3407 if (0 == v4->sin_port)
3408 {
3409 is_natd = GNUNET_YES;
3411 sizeof(struct sockaddr),
3412 &key);
3415 &key))
3416 {
3418 "There is already a request reversal for `%s'at `%s'\n",
3419 GNUNET_i2s (peer),
3420 address);
3421 GNUNET_free (in);
3422 return GNUNET_SYSERR;
3423 }
3424 }
3425 break;
3426
3427 case AF_INET6:
3428 if (GNUNET_YES == disable_v6)
3429 {
3431 "IPv6 disabled, skipping %s\n", address);
3432 GNUNET_free (in);
3433 return GNUNET_SYSERR;
3434 }
3435 v6 = (struct sockaddr_in6 *) in;
3436 if (0 == v6->sin6_port)
3437 {
3439 "Request reversal for `%s' at `%s' not possible for an IPv6 address\n",
3440 GNUNET_i2s (peer),
3441 address);
3442 GNUNET_free (in);
3443 return GNUNET_SYSERR;
3444 }
3445 break;
3446
3447 default:
3448 GNUNET_assert (0);
3449 }
3450
3451 if (GNUNET_YES == is_natd)
3452 {
3453 struct sockaddr_in local_sa;
3454 struct PendingReversal *pending_reversal;
3455
3456 memset (&local_sa, 0, sizeof(local_sa));
3457 local_sa.sin_family = AF_INET;
3458 local_sa.sin_port = htons (bind_port);
3459 /* We leave sin_address at 0, let the kernel figure it out,
3460 even if our bind() is more specific. (May want to reconsider
3461 later.) */
3462 if (GNUNET_OK != GNUNET_NAT_request_reversal (nat, &local_sa, v4))
3463 {
3465 "request reversal for `%s' at `%s' failed\n",
3466 GNUNET_i2s (peer),
3467 address);
3468 GNUNET_free (in);
3469 return GNUNET_SYSERR;
3470 }
3471 pending_reversal = GNUNET_new (struct PendingReversal);
3472 pending_reversal->in = in;
3475 &key,
3476 pending_reversal,
3478 pending_reversal->target = *peer;
3480 &
3482 in);
3484 "Created NAT WAIT connection to `%s' at `%s'\n",
3485 GNUNET_i2s (peer),
3486 GNUNET_a2s (in, sizeof (struct sockaddr)));
3487 }
3488 else
3489 {
3490 struct GNUNET_NETWORK_Handle *sock;
3491
3492 sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM,
3493 IPPROTO_TCP);
3494 if (NULL == sock)
3495 {
3497 "socket(%d) failed: %s",
3498 in->sa_family,
3499 strerror (errno));
3500 GNUNET_free (in);
3501 return GNUNET_SYSERR;
3502 }
3503 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, in_len)) &&
3504 (errno != EINPROGRESS))
3505 {
3507 "connect to `%s' failed: %s",
3508 address,
3509 strerror (errno));
3511 GNUNET_free (in);
3512 return GNUNET_SYSERR;
3513 }
3514
3515 queue = GNUNET_new (struct Queue);
3516 queue->target = *peer;
3517 eddsa_pub_to_hpke_key (&queue->target.public_key, &queue->target_hpke_key);
3518 queue->key = queue_map_key;
3519 queue->address = in;
3520 queue->address_len = in_len;
3521 queue->sock = sock;
3523 boot_queue (queue);
3525 "booted queue with target %s\n",
3526 GNUNET_i2s (&queue->target));
3527 // queue->mq_awaits_continue = GNUNET_YES;
3528 queue->read_task =
3530 queue->sock,
3532 queue);
3533
3534
3536 "start kx mq_init\n");
3537
3539 queue->write_task =
3541 queue->sock,
3542 &queue_write,
3543 queue);
3544 }
3545
3546 return GNUNET_OK;
3547}
3548
3549
3558static int
3560 const struct GNUNET_HashCode *key,
3561 void *value)
3562{
3563 struct ListenTask *lt = value;
3564
3565 (void) cls;
3566 (void) key;
3567 if (NULL != lt->listen_task)
3568 {
3570 lt->listen_task = NULL;
3571 }
3572 if (NULL != lt->listen_sock)
3573 {
3575 lt->listen_sock = NULL;
3576 }
3577 GNUNET_free (lt);
3578 return GNUNET_OK;
3579}
3580
3581
3590static int
3592 const struct GNUNET_HashCode *target,
3593 void *value)
3594{
3595 struct Queue *queue = value;
3596
3597 (void) cls;
3598 (void) target;
3600 return GNUNET_OK;
3601}
3602
3603
3609static void
3610do_shutdown (void *cls)
3611{
3613 "Shutdown %s!\n",
3614 shutdown_running ? "running" : "not running");
3615
3617 return;
3618 else
3620
3621 while (NULL != proto_head)
3623 if (NULL != nat)
3624 {
3626 nat = NULL;
3627 }
3635 if (NULL != ch)
3636 {
3639 ch = NULL;
3640 }
3641 if (NULL != stats)
3642 {
3644 stats = NULL;
3645 }
3646 if (NULL != my_private_key)
3647 {
3649 my_private_key = NULL;
3650 }
3651 if (NULL != is)
3652 {
3654 is = NULL;
3655 }
3656 if (NULL != peerstore)
3657 {
3659 peerstore = NULL;
3660 }
3661 if (NULL != resolve_request_handle)
3662 {
3665 }
3667 "Shutdown done!\n");
3668}
3669
3670
3682static void
3683enc_notify_cb (void *cls,
3684 const struct GNUNET_PeerIdentity *sender,
3685 const struct GNUNET_MessageHeader *msg)
3686{
3687 (void) cls;
3688 (void) sender;
3689 (void) msg;
3690 GNUNET_break_op (0);
3691}
3692
3693
3707static void
3709 void **app_ctx,
3710 int add_remove,
3712 const struct sockaddr *addr,
3713 socklen_t addrlen)
3714{
3715 char *my_addr;
3717
3719 "nat address cb %s %s\n",
3720 add_remove ? "add" : "remove",
3721 GNUNET_a2s (addr, addrlen));
3722
3723 if (GNUNET_YES == add_remove)
3724 {
3726
3727 GNUNET_asprintf (&my_addr,
3728 "%s-%s",
3730 GNUNET_a2s (addr, addrlen));
3731 nt = GNUNET_NT_scanner_get_type (is, addr, addrlen);
3732 ai =
3734 my_addr,
3735 nt,
3737 GNUNET_free (my_addr);
3738 *app_ctx = ai;
3739 }
3740 else
3741 {
3742 ai = *app_ctx;
3744 *app_ctx = NULL;
3745 }
3746}
3747
3748
3752static void
3753add_addr (struct sockaddr *in, socklen_t in_len)
3754{
3755
3756 struct Addresses *saddrs;
3757
3759 "add address %s\n",
3760 GNUNET_a2s (in, in_len));
3761
3762 saddrs = GNUNET_new (struct Addresses);
3763 saddrs->addr = in;
3764 saddrs->addr_len = in_len;
3766
3768 "after add address %s\n",
3769 GNUNET_a2s (in, in_len));
3770
3772 "add address %s\n",
3773 GNUNET_a2s (saddrs->addr, saddrs->addr_len));
3774
3775 addrs_lens++;
3776}
3777
3778
3786static int
3787init_socket (struct sockaddr *addr,
3788 socklen_t in_len)
3789{
3790 struct sockaddr_storage in_sto;
3791 socklen_t sto_len;
3792 struct GNUNET_NETWORK_Handle *listen_sock;
3793 struct ListenTask *lt;
3794 int sockfd;
3795 struct GNUNET_HashCode h_sock;
3796
3797 if (NULL == addr)
3798 {
3800 "Address is NULL.\n");
3801 return GNUNET_SYSERR;
3802 }
3803
3805 "address %s\n",
3806 GNUNET_a2s (addr, in_len));
3807
3808 listen_sock =
3809 GNUNET_NETWORK_socket_create (addr->sa_family, SOCK_STREAM, IPPROTO_TCP);
3810 if (NULL == listen_sock)
3811 {
3813 return GNUNET_SYSERR;
3814 }
3815
3816 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (listen_sock, addr, in_len))
3817 {
3819 GNUNET_NETWORK_socket_close (listen_sock);
3820 listen_sock = NULL;
3821 return GNUNET_SYSERR;
3822 }
3823
3824 if (GNUNET_OK !=
3825 GNUNET_NETWORK_socket_listen (listen_sock,
3826 5))
3827 {
3829 "listen");
3830 GNUNET_NETWORK_socket_close (listen_sock);
3831 listen_sock = NULL;
3832 return GNUNET_SYSERR;
3833 }
3834
3835 /* We might have bound to port 0, allowing the OS to figure it out;
3836 thus, get the real IN-address from the socket */
3837 sto_len = sizeof(in_sto);
3838
3839 if (0 != getsockname (GNUNET_NETWORK_get_fd (listen_sock),
3840 (struct sockaddr *) &in_sto,
3841 &sto_len))
3842 {
3843 memcpy (&in_sto, addr, in_len);
3844 sto_len = in_len;
3845 }
3846
3847 // addr = (struct sockaddr *) &in_sto;
3848 in_len = sto_len;
3850 "Bound to `%s'\n",
3851 GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len));
3852 if (NULL == stats)
3853 stats = GNUNET_STATISTICS_create ("communicator-tcp", cfg);
3854
3855 if (NULL == is)
3857
3858 if (NULL == my_private_key)
3860 if (NULL == my_private_key)
3861 {
3862 GNUNET_log (
3864 _ (
3865 "Transport service is lacking key configuration settings. Exiting.\n"));
3866 if (NULL != resolve_request_handle)
3869 return GNUNET_SYSERR;
3870 }
3874 /* start listening */
3875
3876 lt = GNUNET_new (struct ListenTask);
3877 lt->listen_sock = listen_sock;
3878
3880 listen_sock,
3881 &listen_cb,
3882 lt);
3883
3885 "creating hash\n");
3886 sockfd = GNUNET_NETWORK_get_fd (lt->listen_sock);
3887 GNUNET_CRYPTO_hash (&sockfd,
3888 sizeof(int),
3889 &h_sock);
3890
3892 "creating map\n");
3893 if (NULL == lt_map)
3895
3897 "creating map entry\n");
3900 &h_sock,
3901 lt,
3903
3905 "map entry created\n");
3906
3907 if (NULL == queue_map)
3909
3910 if (NULL == ch)
3915 &mq_init,
3916 NULL,
3918 NULL);
3919
3920 if (NULL == ch)
3921 {
3922 GNUNET_break (0);
3923 if (NULL != resolve_request_handle)
3926 return GNUNET_SYSERR;
3927 }
3928
3929 add_addr (addr, in_len);
3930 return GNUNET_OK;
3931
3932}
3933
3934
3938static void
3940{
3941 struct sockaddr **saddrs;
3942 socklen_t *saddr_lens;
3943 int i;
3944 size_t len;
3945
3947 "starting nat register!\n");
3948 len = 0;
3949 i = 0;
3950 saddrs = GNUNET_malloc ((addrs_lens) * sizeof(struct sockaddr *));
3951 saddr_lens = GNUNET_malloc ((addrs_lens) * sizeof(socklen_t));
3952 for (struct Addresses *pos = addrs_head; NULL != pos; pos = pos->next)
3953 {
3955 "registering address %s\n",
3957
3958 saddr_lens[i] = addrs_head->addr_len;
3959 len += saddr_lens[i];
3960 saddrs[i] = GNUNET_memdup (addrs_head->addr, saddr_lens[i]);
3961 i++;
3962 }
3963
3965 "registering addresses %lu %lu %lu %lu\n",
3966 (addrs_lens) * sizeof(struct sockaddr *),
3967 (addrs_lens) * sizeof(socklen_t),
3968 len,
3972 IPPROTO_TCP,
3973 addrs_lens,
3974 (const struct sockaddr **) saddrs,
3975 saddr_lens,
3978 NULL /* closure */);
3979 for (i = addrs_lens - 1; i >= 0; i--)
3980 GNUNET_free (saddrs[i]);
3981 GNUNET_free (saddrs);
3982 GNUNET_free (saddr_lens);
3983
3984 if (NULL == nat)
3985 {
3986 GNUNET_break (0);
3987 if (NULL != resolve_request_handle)
3990 }
3991}
3992
3993
4001static void
4003 const struct sockaddr *addr,
4004 socklen_t in_len)
4005{
4006 struct sockaddr_in *v4;
4007 struct sockaddr_in6 *v6;
4008 struct sockaddr *in;
4009
4010 (void) cls;
4011 if (NULL != addr)
4012 {
4013 if (AF_INET == addr->sa_family)
4014 {
4015 v4 = (struct sockaddr_in *) addr;
4016 in = tcp_address_to_sockaddr_numeric_v4 (&in_len, *v4, bind_port);// _global);
4017 }
4018 else if (AF_INET6 == addr->sa_family)
4019 {
4020 v6 = (struct sockaddr_in6 *) addr;
4021 in = tcp_address_to_sockaddr_numeric_v6 (&in_len, *v6, bind_port);// _global);
4022 }
4023 else
4024 {
4026 "Address family %u not suitable (not AF_INET %u nor AF_INET6 %u \n",
4027 addr->sa_family,
4028 AF_INET,
4029 AF_INET6);
4030 return;
4031 }
4032 init_socket (in, in_len);
4033 }
4034 else
4035 {
4037 "Address is NULL. This might be an error or the resolver finished resolving.\n");
4038 if (NULL == addrs_head)
4039 {
4041 "Resolver finished resolving, but we do not listen to an address!.\n");
4042 return;
4043 }
4044 nat_register ();
4045 }
4046}
4047
4048
4057static void
4058run (void *cls,
4059 char *const *args,
4060 const char *cfgfile,
4061 const struct GNUNET_CONFIGURATION_Handle *c)
4062{
4063 char *bindto;
4064 struct sockaddr *in;
4065 socklen_t in_len;
4066 struct sockaddr_in v4;
4067 struct sockaddr_in6 v6;
4068 char *start;
4069 unsigned int port;
4070 char dummy[2];
4071 char *rest = NULL;
4072 struct PortOnlyIpv4Ipv6 *po;
4073 socklen_t addr_len_ipv4;
4074 socklen_t addr_len_ipv6;
4075
4076 (void) cls;
4077
4079 memset (&v4,0,sizeof(struct sockaddr_in));
4080 memset (&v6,0,sizeof(struct sockaddr_in6));
4081 cfg = c;
4082 if (GNUNET_OK !=
4085 "BINDTO",
4086 &bindto))
4087 {
4090 "BINDTO");
4091 return;
4092 }
4093 if (GNUNET_OK !=
4096 "MAX_QUEUE_LENGTH",
4098 {
4100 }
4101 if (GNUNET_OK !=
4104 "REKEY_INTERVAL",
4106 {
4108 }
4109 if (GNUNET_OK !=
4112 "REKEY_MAX_BYTES",
4114 {
4116 }
4118 if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
4119 (GNUNET_YES ==
4122 "DISABLE_V6")))
4123 {
4125 }
4127 if (NULL == peerstore)
4128 {
4129 GNUNET_free (bindto);
4130 GNUNET_break (0);
4132 return;
4133 }
4134
4136
4137 if (1 == sscanf (bindto, "%u%1s", &bind_port, dummy))
4138 {
4142 "address po %s\n",
4144 if (NULL != po->addr_ipv4)
4145 {
4147 }
4148 if (NULL != po->addr_ipv6)
4149 {
4152 }
4153 GNUNET_free (po);
4154 nat_register ();
4155 GNUNET_free (bindto);
4156 return;
4157 }
4158
4159 start = extract_address (bindto);
4160 // FIXME: check for NULL == start...
4161 if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
4162 {
4163 bind_port = extract_port (bindto);
4164
4166 init_socket (in, in_len);
4167 nat_register ();
4169 GNUNET_free (bindto);
4170 return;
4171 }
4172
4173 if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
4174 {
4175 bind_port = extract_port (bindto);
4177 init_socket (in, in_len);
4178 nat_register ();
4180 GNUNET_free (bindto);
4181 return;
4182 }
4183
4184 bind_port = extract_port (bindto);
4186 ":",
4187 &rest),
4188 AF_UNSPEC,
4191 &port);
4192
4193 GNUNET_free (bindto);
4195}
4196
4197
4205int
4206main (int argc, char *const *argv)
4207{
4208 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
4210 };
4211 int ret;
4212
4214 "Starting tcp communicator\n");
4215 if (GNUNET_OK !=
4216 GNUNET_STRINGS_get_utf8_args (argc, argv,
4217 &argc, &argv))
4218 return 2;
4219
4220 ret = (GNUNET_OK ==
4221 GNUNET_PROGRAM_run (argc,
4222 argv,
4223 "gnunet-communicator-tcp",
4224 _ ("GNUnet TCP communicator"),
4225 options,
4226 &run,
4227 NULL))
4228 ? 0
4229 : 1;
4230 GNUNET_free_nz ((void *) argv);
4231 return ret;
4232}
4233
4234
4235/* 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:39
static int ret
Final status code.
Definition: gnunet-arm.c:94
static uint16_t port
Port number.
Definition: gnunet-bcd.c:147
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 unsigned int bind_port
The port the communicator should be assigned to.
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.
#define COMMUNICATOR_ADDRESS_PREFIX
Address prefix used by the communicator.
static void mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state)
Signature of functions implementing the destruction of a message queue.
#define ADDRESS_VALIDITY_PERIOD
How long do we believe our addresses to remain up (before the other peer should revalidate).
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.
#define INITIAL_CORE_KX_SIZE
Size of the initial core key exchange messages.
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 try_connection_reversal(void *cls, const struct sockaddr *addr, socklen_t addrlen)
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
static 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 int disable_v6
IPv6 disabled.
static struct GNUNET_CONTAINER_MultiHashMap * pending_reversals
Map of pending reversals.
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 struct ProtoQueue * proto_tail
Protoqueues DLL tail.
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 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 void do_shutdown(void *cls)
Shutdown the UNIX communicator.
#define COMMUNICATOR_CONFIG_SECTION
Configuration section used by the 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 void nat_address_cb(void *cls, void **app_ctx, int add_remove, enum GNUNET_NAT_AddressClass ac, const struct sockaddr *addr, socklen_t addrlen)
Signature of the callback passed to GNUNET_NAT_register() for a function to call whenever our set of ...
static struct 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 void init_socket_resolv(void *cls, const struct sockaddr *addr, socklen_t in_len)
This method is the callback called by the resolver API, and wraps method init_socket.
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
static unsigned long long max_queue_length
Maximum queue length before we stop reading towards the transport service.
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.
struct GNUNET_RESOLVER_RequestHandle * resolve_request_handle
Handle for DNS lookup of bindto address.
static void nat_register()
This method reads from the DLL addrs_head to register them at the NAT service.
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 int addrs_lens
Number of addresses in the DLL for register at NAT service.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Setup communicator and launch network interactions.
static struct GNUNET_NAT_Handle * nat
Connection to NAT service.
static void pending_reversal_timeout(void *cls)
#define PROTO_QUEUE_TIMEOUT
How long do we wait until we must have received the initial KX?
static void queue_read(void *cls)
Queue read task.
#define REKEY_MAX_BYTES
How often do we rekey based on number of bytes transmitted? (additionally randomized).
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.
#define INITIAL_KX_SIZE
Size of the initial key exchange message sent first in both directions.
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 struct ProtoQueue * proto_head
Protoqueues DLL head.
static int shutdown_running
A flag indicating we are already doing a shutdown.
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 DEFAULT_REKEY_INTERVAL
How often do we rekey based on time (at least)
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.
#define DEFAULT_MAX_QUEUE_LENGTH
How many messages do we keep at most in the queue to the transport service before we start to drop (d...
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 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 unsigned long long rekey_max_bytes
The rekey byte maximum.
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 struct GNUNET_TRANSPORT_AddressIdentifier * ai
Handle to the operation that publishes our address.
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 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 struct GNUNET_NAT_AUTO_Test * nt
Handle to a NAT test operation.
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.
Constants for network protocols.
Functions related to doing DNS lookups.
API to create, modify and access statistics.
API of the transport service towards the communicator processes.
void GNUNET_TRANSPORT_communicator_address_remove(struct GNUNET_TRANSPORT_AddressIdentifier *ai)
Notify transport service about an address that this communicator no longer provides for this peer.
int GNUNET_TRANSPORT_communicator_receive(struct GNUNET_TRANSPORT_CommunicatorHandle *handle, const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *msg, struct GNUNET_TIME_Relative expected_addr_validity, GNUNET_TRANSPORT_MessageCompletedCallback cb, void *cb_cls)
Notify transport service that the communicator has received a message.
void GNUNET_TRANSPORT_communicator_mq_del(struct GNUNET_TRANSPORT_QueueHandle *qh)
Notify transport service that an MQ became unavailable due to a disconnect or timeout.
#define GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED
Queue length.
struct GNUNET_TRANSPORT_QueueHandle * GNUNET_TRANSPORT_communicator_mq_add(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const struct GNUNET_PeerIdentity *peer, const char *address, uint32_t mtu, uint64_t q_len, uint32_t priority, enum GNUNET_NetworkType nt, enum GNUNET_TRANSPORT_ConnectionStatus cs, struct GNUNET_MQ_Handle *mq)
Notify transport service that a MQ became available due to an "inbound" connection or because the com...
void GNUNET_TRANSPORT_communicator_disconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
Disconnect from the transport service.
struct GNUNET_TRANSPORT_CommunicatorHandle * GNUNET_TRANSPORT_communicator_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *config_section_name, const char *addr_prefix, enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, GNUNET_TRANSPORT_CommunicatorMqInit mq_init, void *mq_init_cls, GNUNET_TRANSPORT_CommunicatorNotify notify_cb, void *notify_cb_cls)
Connect to the transport service.
GNUNET_TRANSPORT_ConnectionStatus
Possible states of a connection.
struct GNUNET_TRANSPORT_AddressIdentifier * GNUNET_TRANSPORT_communicator_address_add(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const char *address, enum GNUNET_NetworkType nt, struct GNUNET_TIME_Relative expiration)
Notify transport service about an address that this communicator provides for this peer.
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_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_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.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don't receive messages from the peer?
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:407
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:459
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:443
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:312
#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.
struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_CRYPTO_eddsa_key_create_from_configuration(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create a new private key by reading our peer's key from the file specified in the configuration.
@ GNUNET_CRYPTO_QUALITY_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.
#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:366
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;.
#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:390
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:973
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:951
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:350
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:300
@ 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_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages).
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
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_free_nz(ptr)
Wrapper around free.
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
GNUNET_MQ_Error
Error codes for the queue.
struct GNUNET_MQ_Handle * GNUNET_MQ_queue_for_callbacks(GNUNET_MQ_SendImpl send, GNUNET_MQ_DestroyImpl destroy, GNUNET_MQ_CancelImpl cancel, void *impl_state, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *cls)
Create a message queue for the specified handlers.
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:674
struct GNUNET_NAT_Handle * GNUNET_NAT_register(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *config_section, uint8_t proto, unsigned int num_addrs, const struct sockaddr **addrs, const socklen_t *addrlens, GNUNET_NAT_AddressCallback address_callback, GNUNET_NAT_ReversalCallback reversal_callback, void *callback_cls)
Attempt to enable port redirection and detect public IP address contacting UPnP or NAT-PMP routers on...
Definition: nat_api.c:366
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:702
GNUNET_NAT_AddressClass
Some addresses contain sensitive information or are not suitable for global distribution.
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:1000
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:716
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition: network.c:832
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:601
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:737
enum GNUNET_GenericReturnValue GNUNET_NETWORK_test_pf(int pf)
Test if the given protocol family is supported by this system.
Definition: network.c:79
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_bind(struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Bind a socket to a particular address.
Definition: network.c:439
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_listen(const struct GNUNET_NETWORK_Handle *desc, int backlog)
Listen on a socket.
Definition: network.c:651
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:44
void GNUNET_NT_scanner_done(struct GNUNET_NT_InterfaceScanner *is)
Terminate interface scanner.
Definition: nt.c:426
struct GNUNET_NT_InterfaceScanner * GNUNET_NT_scanner_init(void)
Initialize the address characterization client handle.
Definition: nt.c:405
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:307
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(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:400
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_CONFIRMATION_ACK
TCP communicator confirmation ack.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE
TCP NAT probe message, send from NAT'd peer to other peer to establish bi-directional communication.
#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.
struct GNUNET_RESOLVER_RequestHandle * GNUNET_RESOLVER_ip_get(const char *hostname, int af, struct GNUNET_TIME_Relative timeout, GNUNET_RESOLVER_AddressCallback callback, void *callback_cls)
Convert a string to one or more IP addresses.
Definition: resolver_api.c:940
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:1512
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:1583
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:1340
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:981
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:1305
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:1278
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).
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1230
#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:405
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:570
#define GNUNET_TIME_UNIT_MINUTES
One minute.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:737
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:860
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:638
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:617
#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:178
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition: scheduler.c:431
#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.
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.
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
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...
an ECC signature using EdDSA.
HPKE DHKEM encapsulation (X25519) See RFC 9180.
A private key for an identity as per LSD0001.
An identity key as per LSD0001.
Definition of a command line option.
A 512-bit hashcode.
Handle to a message queue.
Definition: mq.c:87
Header for all communications.
Handle for active NAT registrations.
Definition: nat_api.c:72
handle to a socket
Definition: network.c:53
Handle to the interface scanner.
Definition: nt.c:104
Handle to the PEERSTORE service.
Definition: peerstore_api.c:44
Context for a iterate request.
Single PEERSTORE record.
Context for a store request.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Handle to a request given to the resolver.
Definition: resolver_api.c:104
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.
Internal representation of an address a communicator is currently providing for the transport service...
Opaque handle to the transport service for communicators.
Handle returned to identify the internal data structure the transport API has created to manage a mes...
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.
struct ProtoQueue * prev
Kept in a DLL.
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.
struct ProtoQueue * next
Kept in a DLL.
Handle for a queue.
struct GNUNET_CRYPTO_EcdhePublicKey target_hpke_key
To whom are we talking to.
unsigned int backpressure
How may messages did we pass from this queue to CORE for which we have yet to receive an acknowledgem...
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
struct GNUNET_PEERSTORE_IterateContext * handshake_ack_monotime_get
Iteration Context for retrieving the monotonic time send with the handshake ack.
int rekeyed
GNUNET_YES if we just rekeyed and must thus possibly re-decrypt ciphertext.
struct GNUNET_CRYPTO_ChallengeNonceP challenge
Challenge value used to protect against replay attack, if there is no stored monotonic time value.
size_t unverified_size
Size of data received without KX challenge played back.
struct GNUNET_TRANSPORT_QueueHandle * qh
handle for this queue with the ch.
struct GNUNET_HashCode out_hmac
Shared secret for HMAC generation on outgoing data, ratcheted after each operation.
int finishing
Did we enqueue a finish message and are closing down the queue?
int initial_core_kx_done
Has the initial (core) handshake already happened?
struct GNUNET_HashCode key
Key in hash map.
socklen_t address_len
Length of the address.
struct GNUNET_MQ_Handle * mq
Message queue we are providing for the ch.
unsigned long long bytes_in_queue
Number of bytes we currently have in our write queue.
char pread_buf[UINT16_MAX+1+sizeof(struct TCPBox)]
Plaintext buffer for decrypted plaintext.
int destroyed
Did we technically destroy this queue, but kept the allocation around because of backpressure not bei...
struct GNUNET_PEERSTORE_StoreContext * rekey_monotime_sc
Store Context for retrieving the monotonic time send with key for rekeying.
size_t cwrite_off
At which offset in the ciphertext write buffer should we append more ciphertext from reading next?
struct GNUNET_PEERSTORE_IterateContext * rekey_monotime_get
Iteration Context for retrieving the monotonic time send with key for rekeying.
char cread_buf[(2 *64 *1024+sizeof(struct TCPBox))]
Buffer for reading ciphertext from network into.
enum GNUNET_NetworkType nt
Which network type does this queue use?
struct GNUNET_CRYPTO_ChallengeNonceP challenge_received
Challenge value received.
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
uint64_t rekey_left_bytes
How many more bytes may we sent with the current out_cipher before we should rekey?
int mq_awaits_continue
Is MQ awaiting a GNUNET_MQ_impl_send_continue() call?
gcry_cipher_hd_t in_cipher
cipher for decryption of incoming data.
struct GNUNET_PEERSTORE_StoreContext * handshake_ack_monotime_sc
Store Context for retrieving the monotonic time send with the handshake ack.
size_t pwrite_off
At which offset in the plaintext output buffer should we append more plaintext for encryption next?
struct GNUNET_TIME_Absolute timeout
Timeout for this queue.
struct sockaddr * address
Address of the other peer.
size_t cread_off
At which offset in the ciphertext read buffer should we append more ciphertext for transmission next?
struct GNUNET_TIME_Absolute rekey_time
Until what time may we sent with the current out_cipher before we should rekey?
struct GNUNET_PeerIdentity target
To whom are we talking to.
char cwrite_buf[(2 *64 *1024+sizeof(struct TCPBox))]
buffer for writing ciphertext to network.
struct GNUNET_PEERSTORE_StoreContext * handshake_monotime_sc
Store Context for retrieving the monotonic time send with the handshake.
size_t pread_off
At which offset in the plaintext input buffer should we append more plaintext from decryption next?
enum GNUNET_TRANSPORT_ConnectionStatus cs
The connection status of this queue.
gcry_cipher_hd_t out_cipher
cipher for encryption of outgoing data.
char pwrite_buf[UINT16_MAX+1+sizeof(struct TCPBox)]
Plaintext buffer for messages to be encrypted.
struct GNUNET_HashCode in_hmac
Shared secret for HMAC verification on incoming data.
struct GNUNET_PEERSTORE_IterateContext * handshake_monotime_get
Iteration Context for retrieving the monotonic time send with the handshake.
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
struct GNUNET_SCHEDULER_Task * write_task
ID of write task for this connection.
struct GNUNET_TIME_AbsoluteNBO handshake_ack_monotonic_time
Monotonic time value for handshake ack message.
struct GNUNET_TIME_AbsoluteNBO rekey_monotonic_time
Monotonic time value for rekey message.
struct GNUNET_TIME_AbsoluteNBO handshake_monotonic_time
Monotonic time value for handshake message.
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_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.
struct GNUNET_PeerIdentity sender
Sender's identity.
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_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.
struct GNUNET_PeerIdentity clientIdentity
Identity of the sender of the message.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE.
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...