GNUnet 0.26.2-114-g7c6b613e3
 
Loading...
Searching...
No Matches
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, 2026 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_pils_service.h"
34#include "gnunet_core_service.h"
36#include "gnunet_protocols.h"
37#include "gnunet_signatures.h"
38#include "gnunet_constants.h"
39#include "gnunet_nat_service.h"
43
44/* Shorthand for Logging */
45#define LOG(kind, ...) GNUNET_log_from (kind, "communicator-tcp", __VA_ARGS__)
46
47
52#define NAT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
53
58#define ADDRESS_VALIDITY_PERIOD \
59 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
60
69#define DEFAULT_MAX_QUEUE_LENGTH 8
70
75#define BUF_SIZE (2 * 64 * 1024 + sizeof(struct TCPBox))
76
80#define DEFAULT_REKEY_INTERVAL GNUNET_TIME_UNIT_DAYS
81
85#define PROTO_QUEUE_TIMEOUT GNUNET_TIME_UNIT_MINUTES
86
91#define REKEY_MAX_BYTES (1024LLU * 1024 * 400)
92
97#define INITIAL_KX_SIZE \
98 (sizeof(struct GNUNET_CRYPTO_EcdhePublicKey) \
99 + sizeof(struct TCPConfirmation))
100
104#define INITIAL_CORE_KX_SIZE \
105 (sizeof(struct EphemeralKeyMessage) \
106 + sizeof(struct PingMessage) \
107 + sizeof(struct PongMessage))
108
112#define COMMUNICATOR_ADDRESS_PREFIX "tcp"
113
117#define COMMUNICATOR_CONFIG_SECTION "communicator-tcp"
118
120
121
159
192
220
255
259struct TCPBox
260{
268
278
279 /* followed by as may bytes of payload as indicated in @e header,
280 excluding the TCPBox itself! */
281};
282
283
321
354
377
394
396
401{
402 /*
403 * Timeout task.
404 */
406
411
415 struct sockaddr *in;
416};
417
433
437struct Queue
438{
443
448
453
458
462 gcry_cipher_hd_t in_cipher;
463
467 gcry_cipher_hd_t out_cipher;
468
473
478
484
489
494
498 struct sockaddr *address;
499
505
511
515 socklen_t address_len;
516
521
526
530 unsigned long long bytes_in_queue;
531
536
541
545 char pread_buf[UINT16_MAX + 1 + sizeof(struct TCPBox)];
546
550 char pwrite_buf[UINT16_MAX + 1 + sizeof(struct TCPBox)];
551
556 size_t cread_off;
557
563
568 size_t pread_off;
569
575
580
588 unsigned int backpressure;
589
594
599
604
609
617
623
628
633
638
643
648
653
658
663
668
673
678
682 // TODO remove?
684
689};
690
691
697{
702
707
712
717
722
726 char write_buf[sizeof (struct TCPNATProbeMessage)];
727
731 size_t write_off;
732
737
741 struct sockaddr *address;
742
746 socklen_t address_len;
747
752
758
762 size_t ibuf_off;
763};
764
769{
773 struct sockaddr *addr_ipv4;
774
778 socklen_t addr_len_ipv4;
779
783 struct sockaddr *addr_ipv6;
784
788 socklen_t addr_len_ipv6;
789
790};
791
795struct Addresses
796{
800 struct Addresses *next;
801
805 struct Addresses *prev;
806
810 struct sockaddr *addr;
811
815 socklen_t addr_len;
816
817};
818
819
823static unsigned long long max_queue_length;
824
829
834
839
844
849
854
858static unsigned long long rekey_max_bytes;
859
864
868static const struct GNUNET_CONFIGURATION_Handle *cfg;
869
874
878static struct GNUNET_NAT_Handle *nat;
879
883static struct ProtoQueue *proto_head;
884
888static struct ProtoQueue *proto_tail;
889
894
898static struct Addresses *addrs_head;
899
903static struct Addresses *addrs_tail;
904
908static int addrs_lens;
909
914
919
923static int disable_v6;
924
928static unsigned int bind_port;
929
934
942static void
943listen_cb (void *cls);
944
945static void
955
956
957static void
966
967
975static void
977{
978 struct ListenTask *lt = NULL;
979 struct GNUNET_HashCode h_sock;
980 int sockfd;
981
982 if (NULL != queue->listen_sock)
983 {
984 sockfd = GNUNET_NETWORK_get_fd (queue->listen_sock);
985 GNUNET_CRYPTO_hash (&sockfd,
986 sizeof(int),
987 &h_sock);
988
990 }
991
993 "Disconnecting queue for peer `%s'\n",
994 GNUNET_i2s (&queue->target));
995 if (NULL != queue->rekey_monotime_sc)
996 {
997 GNUNET_PEERSTORE_store_cancel (queue->rekey_monotime_sc);
998 queue->rekey_monotime_sc = NULL;
999 }
1000 if (NULL != queue->handshake_monotime_sc)
1001 {
1002 GNUNET_PEERSTORE_store_cancel (queue->handshake_monotime_sc);
1003 queue->handshake_monotime_sc = NULL;
1004 }
1005 if (NULL != queue->handshake_ack_monotime_sc)
1006 {
1007 GNUNET_PEERSTORE_store_cancel (queue->handshake_ack_monotime_sc);
1008 queue->handshake_ack_monotime_sc = NULL;
1009 }
1010 if (NULL != queue->rekey_monotime_get)
1011 {
1012 GNUNET_PEERSTORE_iteration_stop (queue->rekey_monotime_get);
1013 queue->rekey_monotime_get = NULL;
1014 }
1015 if (NULL != queue->handshake_monotime_get)
1016 {
1017 GNUNET_PEERSTORE_iteration_stop (queue->handshake_monotime_get);
1018 queue->handshake_monotime_get = NULL;
1019 }
1020 if (NULL != queue->handshake_ack_monotime_get)
1021 {
1022 GNUNET_PEERSTORE_iteration_stop (queue->handshake_ack_monotime_get);
1023 queue->handshake_ack_monotime_get = NULL;
1024 }
1025 if (NULL != queue->qh)
1026 {
1028 queue->qh = NULL;
1029 }
1031 GNUNET_YES ==
1034 "# queues active",
1036 GNUNET_NO);
1037 if (NULL != queue->read_task)
1038 {
1039 GNUNET_SCHEDULER_cancel (queue->read_task);
1040 queue->read_task = NULL;
1041 }
1042 if (NULL != queue->write_task)
1043 {
1044 GNUNET_SCHEDULER_cancel (queue->write_task);
1045 queue->write_task = NULL;
1046 }
1048 {
1050 "closing socket failed\n");
1051 }
1052 gcry_cipher_close (queue->in_cipher);
1053 gcry_cipher_close (queue->out_cipher);
1054 GNUNET_free (queue->address);
1055 if (0 != queue->backpressure)
1056 queue->destroyed = GNUNET_YES;
1057 else
1059
1060 if (NULL == lt)
1061 return;
1062
1063 if ((! shutdown_running) && (NULL == lt->listen_task))
1064 {
1066 "add read net listen\n");
1069 lt->listen_sock,
1070 &listen_cb,
1071 lt);
1072 }
1073 else
1074 GNUNET_free (lt);
1075}
1076
1077
1086static void
1087calculate_hmac (struct GNUNET_HashCode *hmac_secret,
1088 const void *buf,
1089 size_t buf_size,
1090 struct GNUNET_ShortHashCode *smac)
1091{
1092 struct GNUNET_HashCode mac;
1093
1094 GNUNET_CRYPTO_hmac_raw (hmac_secret,
1095 sizeof(struct GNUNET_HashCode),
1096 buf,
1097 buf_size,
1098 &mac);
1099 /* truncate to `struct GNUNET_ShortHashCode` */
1100 memcpy (smac, &mac, sizeof(struct GNUNET_ShortHashCode));
1101 /* ratchet hmac key */
1102 GNUNET_CRYPTO_hash (hmac_secret,
1103 sizeof(struct GNUNET_HashCode),
1104 hmac_secret);
1105}
1106
1107
1114static void
1116{
1117 struct TCPFinish fin;
1118
1119 memset (&fin, 0, sizeof(fin));
1120 fin.header.size = htons (sizeof(fin));
1122 calculate_hmac (&queue->out_hmac, &fin, sizeof(fin), &fin.hmac);
1123 /* if there is any message left in pwrite_buf, we
1124 overwrite it (possibly dropping the last message
1125 from CORE hard here) */
1126 memcpy (queue->pwrite_buf, &fin, sizeof(fin));
1127 queue->pwrite_off = sizeof(fin);
1128 /* This flag will ensure that #queue_write() no longer
1129 notifies CORE about the possibility of sending
1130 more data, and that #queue_write() will call
1131 #queue_destroy() once the @c fin was fully written. */
1132 queue->finishing = GNUNET_YES;
1133}
1134
1135
1141static void
1142queue_read (void *cls);
1143
1144
1152static void
1153core_read_finished_cb (void *cls, int success)
1154{
1155 struct Queue *queue = cls;
1156 if (GNUNET_OK != success)
1158 "# messages lost in communicator API towards CORE",
1159 1,
1160 GNUNET_NO);
1161 if (NULL == queue)
1162 return;
1163
1165 "backpressure %u\n",
1166 queue->backpressure);
1167
1168 queue->backpressure--;
1169 /* handle deferred queue destruction */
1170 if ((queue->destroyed) && (0 == queue->backpressure))
1171 {
1173 return;
1174 }
1175 else if (GNUNET_YES != queue->destroyed)
1176 {
1177 queue->timeout =
1179 );
1180 /* possibly unchoke reading, now that CORE made progress */
1181 if (NULL == queue->read_task)
1182 queue->read_task =
1184 queue->timeout),
1185 queue->sock,
1186 &queue_read,
1187 queue);
1188 }
1189}
1190
1191
1201static void
1203 const void *plaintext,
1204 size_t plaintext_len)
1205{
1206 const struct GNUNET_MessageHeader *hdr = plaintext;
1207 int ret;
1208
1210 "pass message from %s to core\n",
1211 GNUNET_i2s (&queue->target));
1212
1213 if (ntohs (hdr->size) != plaintext_len)
1214 {
1215 /* NOTE: If we ever allow multiple CORE messages in one
1216 BOX, this will have to change! */
1217 GNUNET_break (0);
1218 return;
1219 }
1221 &queue->target,
1222 hdr,
1225 queue);
1227 "passed to core\n");
1228 if (GNUNET_OK == ret)
1229 queue->backpressure++;
1230 GNUNET_break (GNUNET_NO != ret); /* backpressure not working!? */
1231 if (GNUNET_SYSERR == ret)
1233 "# bytes lost due to CORE not running",
1234 plaintext_len,
1235 GNUNET_NO);
1236}
1237
1238
1248static void
1250 const struct GNUNET_PeerIdentity *pid,
1251 gcry_cipher_hd_t *cipher,
1252 struct GNUNET_HashCode *hmac_key)
1253{
1254 char key[256 / 8];
1255 char ctr[128 / 8];
1256
1257 GNUNET_assert (0 == gcry_cipher_open (cipher,
1258 GCRY_CIPHER_AES256 /* low level: go for speed */
1259 ,
1260 GCRY_CIPHER_MODE_CTR,
1261 0 /* flags */));
1264 key,
1265 sizeof(key),
1266 prk,
1267 GNUNET_CRYPTO_kdf_arg_string ("gnunet-communicator-tcp-key"))
1268 );
1269 GNUNET_assert (0 == gcry_cipher_setkey (*cipher, key, sizeof(key)));
1272 ctr,
1273 sizeof(ctr),
1274 prk,
1275 GNUNET_CRYPTO_kdf_arg_string ("gnunet-communicator-tcp-ctr"))
1276 );
1277 gcry_cipher_setctr (*cipher, ctr, sizeof(ctr));
1280 hmac_key,
1281 sizeof(struct GNUNET_HashCode),
1282 prk,
1283 GNUNET_CRYPTO_kdf_arg_string ("gnunet-communicator-hmac")));
1284}
1285
1286
1292static void
1293rekey_monotime_store_cb (void *cls, int success)
1294{
1295 struct Queue *queue = cls;
1296 if (GNUNET_OK != success)
1297 {
1299 "Failed to store rekey monotonic time in PEERSTORE!\n");
1300 }
1301 queue->rekey_monotime_sc = NULL;
1302 GNUNET_PEERSTORE_iteration_next (queue->rekey_monotime_get, 1);
1303}
1304
1305
1313static void
1315 const struct GNUNET_PEERSTORE_Record *record,
1316 const char *emsg)
1317{
1318 struct Queue *queue = cls;
1319 struct GNUNET_TIME_AbsoluteNBO *mtbe;
1320 struct GNUNET_TIME_Absolute mt;
1321 const struct GNUNET_PeerIdentity *pid;
1322 struct GNUNET_TIME_AbsoluteNBO *rekey_monotonic_time;
1323
1324 (void) emsg;
1325
1326 rekey_monotonic_time = &queue->rekey_monotonic_time;
1327 pid = &queue->target;
1328 if (NULL == record)
1329 {
1330 queue->rekey_monotime_get = NULL;
1331 return;
1332 }
1333 if (sizeof(*mtbe) != record->value_size)
1334 {
1335 GNUNET_PEERSTORE_iteration_next (queue->rekey_monotime_get, 1);
1336 GNUNET_break (0);
1337 return;
1338 }
1339 mtbe = record->value;
1340 mt = GNUNET_TIME_absolute_ntoh (*mtbe);
1342 queue->rekey_monotonic_time).abs_value_us)
1343 {
1345 "Queue from %s dropped, rekey monotime in the past\n",
1346 GNUNET_i2s (&queue->target));
1347 GNUNET_break (0);
1348 GNUNET_PEERSTORE_iteration_stop (queue->rekey_monotime_get);
1349 queue->rekey_monotime_get = NULL;
1350 // FIXME: Why should we try to gracefully finish here??
1352 return;
1353 }
1354 queue->rekey_monotime_sc = GNUNET_PEERSTORE_store (peerstore,
1355 "transport_tcp_communicator",
1356 pid,
1358 rekey_monotonic_time,
1359 sizeof(*
1360 rekey_monotonic_time),
1364 queue);
1365}
1366
1367
1374static void
1376 const struct GNUNET_CRYPTO_HpkeEncapsulation *c,
1377 struct Queue *queue)
1378{
1379 const struct GNUNET_PeerIdentity *my_identity;
1381 struct GNUNET_CRYPTO_HpkePrivateKey my_hpke_key;
1382 struct GNUNET_ShortHashCode k;
1383
1387
1388 eddsa_priv_to_hpke_key (my_private_key, &my_hpke_key);
1389
1391 c,
1392 &k);
1393 setup_cipher (&k, my_identity, &queue->in_cipher, &queue->in_hmac);
1394}
1395
1396
1403static void
1418
1419
1428static void
1429do_rekey (struct Queue *queue, const struct TCPRekey *rekey)
1430{
1431 const struct GNUNET_PeerIdentity *my_identity;
1432 struct TcpRekeySignature thp;
1433
1436
1438 thp.purpose.size = htonl (sizeof(thp));
1440 "do_rekey size %u\n",
1441 thp.purpose.size);
1442 thp.sender = queue->target;
1444 "sender %s\n",
1447 "sender %s\n",
1448 GNUNET_p2s (&queue->target.public_key));
1449 thp.receiver = *my_identity;
1451 "receiver %s\n",
1453 thp.ephemeral = rekey->ephemeral;
1455 "ephemeral %s\n",
1457 );
1458 thp.monotonic_time = rekey->monotonic_time;
1460 "time %s\n",
1463 GNUNET_assert (ntohl ((&thp)->purpose.size) == sizeof (*(&thp)));
1464 if (GNUNET_OK !=
1467 &thp,
1468 &rekey->sender_sig,
1469 &queue->target.public_key))
1470 {
1471 GNUNET_break (0);
1472 // FIXME Why should we try to gracefully finish here?
1474 return;
1475 }
1476 queue->rekey_monotonic_time = rekey->monotonic_time;
1477 queue->rekey_monotime_get = GNUNET_PEERSTORE_iteration_start (peerstore,
1478 "transport_tcp_communicator",
1479 &queue->target,
1481 &
1483 queue);
1484 gcry_cipher_close (queue->in_cipher);
1485 queue->rekeyed = GNUNET_YES;
1486 setup_in_cipher (&rekey->ephemeral, queue);
1487}
1488
1489
1495static void
1496handshake_ack_monotime_store_cb (void *cls, int success)
1497{
1498 struct Queue *queue = cls;
1499
1500 if (GNUNET_OK != success)
1501 {
1503 "Failed to store handshake ack monotonic time in PEERSTORE!\n");
1504 }
1505 queue->handshake_ack_monotime_sc = NULL;
1506 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
1507}
1508
1509
1517static void
1519 const struct GNUNET_PEERSTORE_Record *record,
1520 const char *emsg)
1521{
1522 struct Queue *queue = cls;
1523 struct GNUNET_TIME_AbsoluteNBO *mtbe;
1524 struct GNUNET_TIME_Absolute mt;
1525 const struct GNUNET_PeerIdentity *pid;
1526 struct GNUNET_TIME_AbsoluteNBO *handshake_ack_monotonic_time;
1527
1528 (void) emsg;
1529
1530 handshake_ack_monotonic_time = &queue->handshake_ack_monotonic_time;
1531 pid = &queue->target;
1532 if (NULL == record)
1533 {
1534 queue->handshake_ack_monotime_get = NULL;
1535 return;
1536 }
1537 if (sizeof(*mtbe) != record->value_size)
1538 {
1539 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
1540 GNUNET_break (0);
1541 return;
1542 }
1543 mtbe = record->value;
1544 mt = GNUNET_TIME_absolute_ntoh (*mtbe);
1546 queue->handshake_ack_monotonic_time).abs_value_us)
1547 {
1549 "Queue from %s dropped, handshake ack monotime in the past\n",
1550 GNUNET_i2s (&queue->target));
1551 GNUNET_break (0);
1552 GNUNET_PEERSTORE_iteration_stop (queue->handshake_ack_monotime_get);
1553 queue->handshake_ack_monotime_get = NULL;
1554 // FIXME: Why should we try to gracefully finish here?
1556 return;
1557 }
1558 queue->handshake_ack_monotime_sc =
1560 "transport_tcp_communicator",
1561 pid,
1563 handshake_ack_monotonic_time,
1564 sizeof(*handshake_ack_monotonic_time),
1568 queue);
1569}
1570
1571
1578static void
1580 struct Queue *queue)
1581{
1582 const struct GNUNET_PeerIdentity *my_identity;
1584 struct TCPConfirmationAck tca;
1585 struct TcpHandshakeAckSignature thas;
1586
1590
1592 "sending challenge\n");
1593
1594 tca.header.type = ntohs (
1596 tca.header.size = ntohs (sizeof(tca));
1597 tca.challenge = challenge;
1598 tca.sender = *my_identity;
1599 tca.monotonic_time =
1601 thas.purpose.purpose = htonl (
1603 thas.purpose.size = htonl (sizeof(thas));
1604 thas.sender = *my_identity;
1605 thas.receiver = queue->target;
1606 thas.monotonic_time = tca.monotonic_time;
1607 thas.challenge = tca.challenge;
1609 &thas,
1610 &tca.sender_sig);
1611 GNUNET_assert (0 ==
1612 gcry_cipher_encrypt (queue->out_cipher,
1613 &queue->cwrite_buf[queue->cwrite_off],
1614 sizeof(tca),
1615 &tca,
1616 sizeof(tca)));
1617 queue->cwrite_off += sizeof(tca);
1619 "sending challenge done\n");
1620}
1621
1622
1629static void
1631{
1632 setup_cipher (dh, &queue->target, &queue->out_cipher, &queue->out_hmac);
1634 queue->rekey_left_bytes =
1636}
1637
1638
1645static void
1647{
1648 const struct GNUNET_PeerIdentity *my_identity;
1650 struct TCPRekey rekey;
1651 struct TcpRekeySignature thp;
1652 struct GNUNET_ShortHashCode k;
1653
1657
1658 GNUNET_assert (0 == queue->pwrite_off);
1659 memset (&rekey, 0, sizeof(rekey));
1660 GNUNET_CRYPTO_eddsa_kem_encaps (&queue->target.public_key, &rekey.ephemeral,
1661 &k);
1663 rekey.header.size = ntohs (sizeof(rekey));
1664 rekey.monotonic_time =
1667 thp.purpose.size = htonl (sizeof(thp));
1669 "inject_rekey size %u\n",
1670 thp.purpose.size);
1671 thp.sender = *my_identity;
1673 "sender %s\n",
1675 thp.receiver = queue->target;
1677 "receiver %s\n",
1679 thp.ephemeral = rekey.ephemeral;
1681 "ephemeral %s\n",
1683 );
1684 thp.monotonic_time = rekey.monotonic_time;
1686 "time %s\n",
1690 &thp,
1691 &rekey.sender_sig);
1692 calculate_hmac (&queue->out_hmac, &rekey, sizeof(rekey), &rekey.hmac);
1693 /* Encrypt rekey message with 'old' cipher */
1694 GNUNET_assert (0 ==
1695 gcry_cipher_encrypt (queue->out_cipher,
1696 &queue->cwrite_buf[queue->cwrite_off],
1697 sizeof(rekey),
1698 &rekey,
1699 sizeof(rekey)));
1700 queue->cwrite_off += sizeof(rekey);
1701 /* Setup new cipher for successive messages */
1702 gcry_cipher_close (queue->out_cipher);
1703 setup_out_cipher (queue, &k);
1704}
1705
1706
1707static int
1709 const struct GNUNET_HashCode *key,
1710 void *value)
1711{
1712 struct PendingReversal *pending_reversal = value;
1713 (void) cls;
1714
1715 if (NULL != pending_reversal->timeout_task)
1716 {
1717 GNUNET_SCHEDULER_cancel (pending_reversal->timeout_task);
1718 pending_reversal->timeout_task = NULL;
1719 }
1722 key,
1723 pending_reversal));
1724 GNUNET_free (pending_reversal->in);
1725 GNUNET_free (pending_reversal);
1726 return GNUNET_OK;
1727}
1728
1729
1730static void
1731check_and_remove_pending_reversal (struct sockaddr *in, sa_family_t sa_family,
1732 struct GNUNET_PeerIdentity *sender)
1733{
1734 if (AF_INET == sa_family)
1735 {
1736 struct PendingReversal *pending_reversal;
1737 struct GNUNET_HashCode key;
1738 struct sockaddr_in *natted_address;
1739
1740 natted_address = GNUNET_memdup (in, sizeof (struct sockaddr));
1741 natted_address->sin_port = 0;
1742 GNUNET_CRYPTO_hash (natted_address,
1743 sizeof(struct sockaddr),
1744 &key);
1745
1747 &key);
1748 if (NULL != pending_reversal && (NULL == sender ||
1749 0 != memcmp (sender,
1750 &pending_reversal->target,
1751 sizeof(struct
1753 {
1755 "Removing invalid pending reversal for `%s'at `%s'\n",
1756 GNUNET_i2s (&pending_reversal->target),
1757 GNUNET_a2s (in, sizeof (struct sockaddr)));
1758 pending_reversals_delete_it (NULL, &key, pending_reversal);
1759 }
1760 GNUNET_free (natted_address);
1761 }
1762}
1763
1764
1770static void
1772{
1773 if (NULL != pq->listen_sock)
1774 {
1776 pq->listen_sock = NULL;
1777 }
1778 if (NULL != pq->read_task)
1779 {
1781 pq->read_task = NULL;
1782 }
1783 if (NULL != pq->write_task)
1784 {
1786 pq->write_task = NULL;
1787 }
1788 check_and_remove_pending_reversal (pq->address, pq->address->sa_family, NULL);
1790 GNUNET_free (pq->address);
1792 GNUNET_free (pq);
1793}
1794
1795
1802static void
1804{
1805 struct ProtoQueue *pq = cls;
1806 ssize_t sent;
1807 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "In proto queue write\n");
1808 pq->write_task = NULL;
1809 if (0 != pq->write_off)
1810 {
1811 sent = GNUNET_NETWORK_socket_send (pq->sock,
1812 pq->write_buf,
1813 pq->write_off);
1815 "Sent %lu bytes to TCP queue\n", sent);
1816 if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno))
1817 {
1819 free_proto_queue (pq);
1820 return;
1821 }
1822 if (sent > 0)
1823 {
1824 size_t usent = (size_t) sent;
1825 pq->write_off -= usent;
1826 memmove (pq->write_buf,
1827 &pq->write_buf[usent],
1828 pq->write_off);
1829 }
1830 }
1831 /* do we care to write more? */
1832 if ((0 < pq->write_off))
1833 pq->write_task =
1835 pq->sock,
1837 pq);
1838}
1839
1840
1847static void
1848queue_write (void *cls)
1849{
1850 struct Queue *queue = cls;
1851 ssize_t sent;
1852 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "In queue write\n");
1853 queue->write_task = NULL;
1854 if (0 != queue->cwrite_off)
1855 {
1856 sent = GNUNET_NETWORK_socket_send (queue->sock,
1857 queue->cwrite_buf,
1858 queue->cwrite_off);
1860 "Sent %lu bytes to TCP queue\n", sent);
1861 if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno))
1862 {
1865 return;
1866 }
1867 if (sent > 0)
1868 {
1869 size_t usent = (size_t) sent;
1870 queue->cwrite_off -= usent;
1871 memmove (queue->cwrite_buf,
1872 &queue->cwrite_buf[usent],
1873 queue->cwrite_off);
1874 queue->timeout =
1877 }
1878 }
1879 {
1880 /* can we encrypt more? (always encrypt full messages, needed
1881 such that #mq_cancel() can work!) */
1882 unsigned int we_do_not_need_to_rekey = (0 < queue->rekey_left_bytes
1883 - (queue->cwrite_off
1884 + queue->pwrite_off
1885 + sizeof (struct TCPRekey)));
1886 if (we_do_not_need_to_rekey &&
1887 (queue->pwrite_off > 0) &&
1888 (queue->cwrite_off + queue->pwrite_off <= BUF_SIZE))
1889 {
1891 "Encrypting %lu bytes\n", queue->pwrite_off);
1892 GNUNET_assert (0 ==
1893 gcry_cipher_encrypt (queue->out_cipher,
1894 &queue->cwrite_buf[queue->cwrite_off],
1895 queue->pwrite_off,
1896 queue->pwrite_buf,
1897 queue->pwrite_off));
1898 if (queue->rekey_left_bytes > queue->pwrite_off)
1899 queue->rekey_left_bytes -= queue->pwrite_off;
1900 else
1901 queue->rekey_left_bytes = 0;
1902 queue->cwrite_off += queue->pwrite_off;
1903 queue->pwrite_off = 0;
1904 }
1905 // if ((-1 != unverified_size)&& ((0 == queue->pwrite_off) &&
1906 if (((0 == queue->rekey_left_bytes) ||
1908 queue->rekey_time).rel_value_us)) &&
1909 (((0 == queue->pwrite_off) || ! we_do_not_need_to_rekey) &&
1910 (queue->cwrite_off + sizeof (struct TCPRekey) <= BUF_SIZE)))
1911 {
1913 }
1914 }
1915 if ((0 == queue->pwrite_off) && (! queue->finishing) &&
1916 (GNUNET_YES == queue->mq_awaits_continue))
1917 {
1918 queue->mq_awaits_continue = GNUNET_NO;
1920 }
1921 /* did we just finish writing 'finish'? */
1922 if ((0 == queue->cwrite_off) && (GNUNET_YES == queue->finishing))
1923 {
1925 "Finishing queue\n");
1927 return;
1928 }
1929 /* do we care to write more? */
1930 if ((0 < queue->cwrite_off) || (0 < queue->pwrite_off))
1931 queue->write_task =
1933 queue->sock,
1934 &queue_write,
1935 queue);
1936}
1937
1938
1946static size_t
1948{
1949 const struct GNUNET_MessageHeader *hdr;
1950 const struct TCPConfirmationAck *tca;
1951 const struct TCPBox *box;
1952 const struct TCPRekey *rekey;
1953 const struct TCPFinish *fin;
1954 struct TCPRekey rekeyz;
1955 struct TCPFinish finz;
1956 struct GNUNET_ShortHashCode tmac;
1957 uint16_t type;
1958 size_t size = 0;
1959 struct TcpHandshakeAckSignature thas;
1960 const struct GNUNET_PeerIdentity *my_identity;
1961 const struct GNUNET_CRYPTO_ChallengeNonceP challenge = queue->challenge;
1962
1964 "try handle plaintext!\n");
1965
1966 hdr = (const struct GNUNET_MessageHeader *) queue->pread_buf;
1967 if ((sizeof(*hdr) > queue->pread_off))
1968 {
1970 "Handling plaintext, not even a header!\n");
1971 return 0; /* not even a header */
1972 }
1973
1974 if ((GNUNET_YES != queue->initial_core_kx_done) && (queue->unverified_size >
1976 {
1978 "Already received data of size %lu bigger than KX size %lu!\n",
1979 queue->unverified_size,
1981 GNUNET_break_op (0);
1983 return 0;
1984 }
1985
1986 type = ntohs (hdr->type);
1987 switch (type)
1988 {
1990 tca = (const struct TCPConfirmationAck *) queue->pread_buf;
1992 "start processing ack\n");
1993 if (sizeof(*tca) > queue->pread_off)
1994 {
1996 "Handling plaintext size of tca greater than pread offset.\n")
1997 ;
1998 return 0;
1999 }
2000 if (ntohs (hdr->size) != sizeof(*tca))
2001 {
2003 "Handling plaintext size does not match message type.\n");
2004 GNUNET_break_op (0);
2006 return 0;
2007 }
2008
2011
2012 thas.purpose.purpose = htonl (
2014 thas.purpose.size = htonl (sizeof(thas));
2015 thas.sender = tca->sender;
2016 thas.receiver = *my_identity;
2017 thas.monotonic_time = tca->monotonic_time;
2018 thas.challenge = tca->challenge;
2019
2022 &thas,
2023 &tca->sender_sig,
2024 &tca->sender.public_key))
2025 {
2027 "Verification of signature failed!\n");
2028 GNUNET_break (0);
2030 return 0;
2031 }
2032 if (0 != GNUNET_memcmp (&tca->challenge, &challenge))
2033 {
2035 "Challenge in TCPConfirmationAck not correct!\n");
2036 GNUNET_break (0);
2038 return 0;
2039 }
2040
2041 queue->handshake_ack_monotime_get = GNUNET_PEERSTORE_iteration_start (
2042 peerstore,
2043 "transport_tcp_communicator",
2044 &queue->target,
2047 queue);
2048
2050 "Handling plaintext, ack processed!\n");
2051
2053 {
2054 send_challenge (queue->challenge_received, queue);
2055 queue->write_task =
2057 queue->sock,
2058 &queue_write,
2059 queue);
2060 }
2061 else if (GNUNET_TRANSPORT_CS_OUTBOUND == queue->cs)
2062 {
2064 queue->address->sa_family, NULL);
2065 }
2066
2071 queue->initial_core_kx_done = GNUNET_YES;
2072
2073 {
2074 char *foreign_addr;
2075
2076 switch (queue->address->sa_family)
2077 {
2078 case AF_INET:
2079 GNUNET_asprintf (&foreign_addr,
2080 "%s-%s",
2082 GNUNET_a2s (queue->address, queue->address_len));
2083 break;
2084
2085 case AF_INET6:
2086 GNUNET_asprintf (&foreign_addr,
2087 "%s-%s",
2089 GNUNET_a2s (queue->address, queue->address_len));
2090 break;
2091
2092 default:
2093 GNUNET_assert (0);
2094 }
2096 &queue->target,
2097 foreign_addr,
2098 UINT16_MAX, /* no MTU */
2100 0, /* Priority */
2101 queue->nt,
2102 queue->cs,
2103 queue->mq);
2104
2105 GNUNET_free (foreign_addr);
2106 }
2107
2108 size = ntohs (hdr->size);
2109 break;
2111 /* Special case: header size excludes box itself! */
2112 box = (const struct TCPBox *) queue->pread_buf;
2113 if (ntohs (hdr->size) + sizeof(struct TCPBox) > queue->pread_off)
2114 return 0;
2115 calculate_hmac (&queue->in_hmac, &box[1], ntohs (hdr->size), &tmac);
2116 if (0 != memcmp (&tmac, &box->hmac, sizeof(tmac)))
2117 {
2118 GNUNET_break_op (0);
2120 return 0;
2121 }
2122 pass_plaintext_to_core (queue, (const void *) &box[1], ntohs (hdr->size));
2123 size = ntohs (hdr->size) + sizeof(*box);
2125 "Handling plaintext, box processed!\n");
2127 "# bytes decrypted with BOX",
2128 size,
2129 GNUNET_NO);
2131 "# messages decrypted with BOX",
2132 1,
2133 GNUNET_NO);
2134 break;
2135
2137 rekey = (const struct TCPRekey *) queue->pread_buf;
2138 if (sizeof(*rekey) > queue->pread_off)
2139 return 0;
2140 if (ntohs (hdr->size) != sizeof(*rekey))
2141 {
2142 GNUNET_break_op (0);
2144 return 0;
2145 }
2146 rekeyz = *rekey;
2147 memset (&rekeyz.hmac, 0, sizeof(rekeyz.hmac));
2148 calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
2149 if (0 != memcmp (&tmac, &rekey->hmac, sizeof(tmac)))
2150 {
2151 GNUNET_break_op (0);
2153 return 0;
2154 }
2155 do_rekey (queue, rekey);
2156 size = ntohs (hdr->size);
2158 "Handling plaintext, rekey processed!\n");
2160 "# rekeying successful",
2161 1,
2162 GNUNET_NO);
2163 break;
2164
2166 fin = (const struct TCPFinish *) queue->pread_buf;
2167 if (sizeof(*fin) > queue->pread_off)
2168 return 0;
2169 if (ntohs (hdr->size) != sizeof(*fin))
2170 {
2171 GNUNET_break_op (0);
2173 return 0;
2174 }
2175 finz = *fin;
2176 memset (&finz.hmac, 0, sizeof(finz.hmac));
2177 calculate_hmac (&queue->in_hmac, &finz, sizeof(finz), &tmac);
2178 if (0 != memcmp (&tmac, &fin->hmac, sizeof(tmac)))
2179 {
2180 GNUNET_break_op (0);
2182 return 0;
2183 }
2184 /* handle FINISH by destroying queue */
2187 "Handling plaintext, finish processed!\n");
2188 break;
2189
2190 default:
2192 "Handling plaintext, nothing processed!\n");
2193 GNUNET_break_op (0);
2195 return 0;
2196 }
2197 GNUNET_assert (0 != size);
2198 if (-1 != queue->unverified_size)
2199 queue->unverified_size += size;
2200 return size;
2201}
2202
2203
2209static void
2210queue_read (void *cls)
2211{
2212 struct Queue *queue = cls;
2213 struct GNUNET_TIME_Relative left;
2214 ssize_t rcvd;
2215
2216 queue->read_task = NULL;
2217 rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
2218 &queue->cread_buf[queue->cread_off],
2219 BUF_SIZE - queue->cread_off);
2221 "Received %zd bytes from TCP queue\n", rcvd);
2222 if (-1 == rcvd)
2223 {
2224 if ((EAGAIN != errno) && (EINTR != errno))
2225 {
2228 return;
2229 }
2230 /* try again */
2231 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
2232 if (0 != left.rel_value_us)
2233 {
2234 queue->read_task =
2236 return;
2237 }
2239 "Queue %p was idle for %s, disconnecting\n",
2240 queue,
2243 GNUNET_YES));
2245 return;
2246 }
2247 if (0 == rcvd)
2248 {
2249 /* Orderly shutdown of connection */
2251 "Socket for queue %p seems to have been closed\n", queue);
2253 return;
2254 }
2255 queue->timeout =
2257 queue->cread_off += rcvd;
2258 while ((queue->pread_off < sizeof(queue->pread_buf)) &&
2259 (queue->cread_off > 0))
2260 {
2261 size_t max = GNUNET_MIN (sizeof(queue->pread_buf) - queue->pread_off,
2262 queue->cread_off);
2263 size_t done;
2264 size_t total;
2265 size_t old_pread_off = queue->pread_off;
2266
2267 GNUNET_assert (0 ==
2268 gcry_cipher_decrypt (queue->in_cipher,
2269 &queue->pread_buf[queue->pread_off],
2270 max,
2271 queue->cread_buf,
2272 max));
2273 queue->pread_off += max;
2274 total = 0;
2275 while (0 != (done = try_handle_plaintext (queue)))
2276 {
2277 /* 'done' bytes of plaintext were used, shift buffer */
2278 GNUNET_assert (done <= queue->pread_off);
2279 /* NOTE: this memmove() could possibly sometimes be
2280 avoided if we pass 'total' into try_handle_plaintext()
2281 and use it at an offset into the buffer there! */
2282 memmove (queue->pread_buf,
2283 &queue->pread_buf[done],
2284 queue->pread_off - done);
2285 queue->pread_off -= done;
2286 total += done;
2287 /* The last plaintext was a rekey, abort for now */
2288 if (GNUNET_YES == queue->rekeyed)
2289 break;
2290 }
2291 /* when we encounter a rekey message, the decryption above uses the
2292 wrong key for everything after the rekey; in that case, we have
2293 to re-do the decryption at 'total' instead of at 'max'.
2294 However, we have to take into account that the plaintext buffer may have
2295 already contained data and not jumped too far ahead in the ciphertext.
2296 If there is no rekey and the last message is incomplete (max > total),
2297 it is safe to keep the decryption so we shift by 'max' */
2298 if (GNUNET_YES == queue->rekeyed)
2299 {
2300 max = total - old_pread_off;
2301 queue->rekeyed = GNUNET_NO;
2302 queue->pread_off = 0;
2303 }
2304 memmove (queue->cread_buf, &queue->cread_buf[max], queue->cread_off - max);
2305 queue->cread_off -= max;
2306 }
2307 if (BUF_SIZE == queue->cread_off)
2308 return; /* buffer full, suspend reading */
2309 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
2310 if (0 != left.rel_value_us)
2311 {
2312 if (max_queue_length > queue->backpressure)
2313 {
2314 /* continue reading */
2315 queue->read_task =
2317 }
2318 return;
2319 }
2321 "Queue %p was idle for %s, disconnecting\n",
2322 queue,
2325 GNUNET_YES));
2327}
2328
2329
2337static struct sockaddr *
2339 struct sockaddr_in6 v6,
2340 unsigned int port)
2341{
2342 struct sockaddr *in;
2343
2344 v6.sin6_family = AF_INET6;
2345 v6.sin6_port = htons ((uint16_t) port);
2346#if HAVE_SOCKADDR_IN_SIN_LEN
2347 v6.sin6_len = sizeof(struct sockaddr_in6);
2348#endif
2349 v6.sin6_flowinfo = 0;
2350 v6.sin6_scope_id = 0;
2351 in = GNUNET_memdup (&v6, sizeof(v6));
2352 *sock_len = sizeof(struct sockaddr_in6);
2353
2354 return in;
2355}
2356
2357
2365static struct sockaddr *
2367 struct sockaddr_in v4,
2368 unsigned int port)
2369{
2370 struct sockaddr *in;
2371
2372 v4.sin_family = AF_INET;
2373 v4.sin_port = htons ((uint16_t) port);
2374#if HAVE_SOCKADDR_IN_SIN_LEN
2375 v4.sin_len = sizeof(struct sockaddr_in);
2376#endif
2377 in = GNUNET_memdup (&v4, sizeof(v4));
2378 *sock_len = sizeof(struct sockaddr_in);
2379 return in;
2380}
2381
2382
2389static struct PortOnlyIpv4Ipv6 *
2390tcp_address_to_sockaddr_port_only (const char *bindto, unsigned int *port)
2391{
2392 struct PortOnlyIpv4Ipv6 *po;
2393 struct sockaddr_in *i4;
2394 struct sockaddr_in6 *i6;
2395 socklen_t sock_len_ipv4;
2396 socklen_t sock_len_ipv6;
2397
2398 /* interpreting value as just a PORT number */
2399 if (*port > UINT16_MAX)
2400 {
2402 "BINDTO specification `%s' invalid: value too large for port\n",
2403 bindto);
2404 return NULL;
2405 }
2406
2407 po = GNUNET_new (struct PortOnlyIpv4Ipv6);
2408
2409 if (GNUNET_YES == disable_v6)
2410 {
2411 i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
2412 po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
2413 *port);
2414 po->addr_len_ipv4 = sock_len_ipv4;
2415 }
2416 else
2417 {
2418
2419 i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
2420 po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
2421 *port);
2422 po->addr_len_ipv4 = sock_len_ipv4;
2423
2424 i6 = GNUNET_malloc (sizeof(struct sockaddr_in6));
2425 po->addr_ipv6 = tcp_address_to_sockaddr_numeric_v6 (&sock_len_ipv6, *i6,
2426 *port);
2427
2428 po->addr_len_ipv6 = sock_len_ipv6;
2429
2430 GNUNET_free (i6);
2431 }
2432
2433 GNUNET_free (i4);
2434
2435 return po;
2436}
2437
2438
2445static char *
2446extract_address (const char *bindto)
2447{
2448 char *addr;
2449 char *start;
2450 char *token;
2451 char *cp;
2452 char *rest = NULL;
2453
2455 "extract address with bindto %s\n",
2456 bindto);
2457
2458 if (NULL == bindto)
2460 "bindto is NULL\n");
2461
2462 cp = GNUNET_strdup (bindto);
2463
2465 "extract address 2\n");
2466
2467 start = cp;
2468 if (('[' == *cp) && (']' == cp[strlen (cp) - 1]))
2469 {
2470 start++; /* skip over '['*/
2471 cp[strlen (cp) - 1] = '\0'; /* eat ']'*/
2472 addr = GNUNET_strdup (start);
2473 }
2474 else
2475 {
2476 token = strtok_r (cp, "]", &rest);
2477 if (strlen (bindto) == strlen (token))
2478 {
2479 token = strtok_r (cp, ":", &rest);
2480 addr = GNUNET_strdup (token);
2481 }
2482 else
2483 {
2484 token++;
2485 addr = GNUNET_strdup (token);
2486 }
2487 }
2488
2490 "tcp address: %s\n",
2491 addr);
2492 GNUNET_free (cp);
2493 return addr;
2494}
2495
2496
2503static unsigned int
2504extract_port (const char *addr_and_port)
2505{
2506 unsigned int port;
2507 char dummy[2];
2508 char *token;
2509 char *addr;
2510 char *colon;
2511 char *cp;
2512 char *rest = NULL;
2513
2514 if (NULL != addr_and_port)
2515 {
2516 cp = GNUNET_strdup (addr_and_port);
2517 token = strtok_r (cp, "]", &rest);
2518 if (strlen (addr_and_port) == strlen (token))
2519 {
2520 colon = strrchr (cp, ':');
2521 if (NULL == colon)
2522 {
2523 GNUNET_free (cp);
2524 return 0;
2525 }
2526 addr = colon;
2527 addr++;
2528 }
2529 else
2530 {
2531 token = strtok_r (NULL, "]", &rest);
2532 if (NULL == token)
2533 {
2534 GNUNET_free (cp);
2535 return 0;
2536 }
2537 else
2538 {
2539 addr = token;
2540 addr++;
2541 }
2542 }
2543
2544
2545 if (1 == sscanf (addr, "%u%1s", &port, dummy))
2546 {
2547 /* interpreting value as just a PORT number */
2548 if (port > UINT16_MAX)
2549 {
2551 "Port `%u' invalid: value too large for port\n",
2552 port);
2553 GNUNET_free (cp);
2554 return 0;
2555 }
2556 }
2557 else
2558 {
2560 "BINDTO specification invalid: last ':' not followed by number\n");
2561 GNUNET_free (cp);
2562 return 0;
2563 }
2564 GNUNET_free (cp);
2565 }
2566 else
2567 {
2569 "return 0\n");
2570 /* interpret missing port as 0, aka pick any free one */
2571 port = 0;
2572 }
2573
2574 return port;
2575}
2576
2577
2585static struct sockaddr *
2586tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
2587{
2588 struct sockaddr *in;
2589 unsigned int port;
2590 struct sockaddr_in v4;
2591 struct sockaddr_in6 v6;
2592 char *start;
2593
2594 memset (&v4, 0, sizeof(v4));
2595 start = extract_address (bindto);
2596 GNUNET_assert (NULL != start);
2598 "start %s\n",
2599 start);
2600
2602 "!bindto %s\n",
2603 bindto);
2604
2605
2606 if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
2607 {
2608 port = extract_port (bindto);
2609
2611 "port %u\n",
2612 port);
2613
2614 in = tcp_address_to_sockaddr_numeric_v4 (sock_len, v4, port);
2615 }
2616 else if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
2617 {
2618 port = extract_port (bindto);
2619 in = tcp_address_to_sockaddr_numeric_v6 (sock_len, v6, port);
2620 }
2621 else
2622 {
2623 GNUNET_assert (0);
2624 }
2625
2627 return in;
2628}
2629
2630
2639static void
2641 const struct GNUNET_MessageHeader *msg,
2642 void *impl_state)
2643{
2644 struct Queue *queue = impl_state;
2645 uint16_t msize = ntohs (msg->size);
2646 struct TCPBox box;
2648 "In MQ send. Queue finishing: %s; write task running: %s\n",
2649 (GNUNET_YES == queue->finishing) ? "yes" : "no",
2650 (NULL == queue->write_task) ? "yes" : "no");
2651 GNUNET_assert (mq == queue->mq);
2652 queue->mq_awaits_continue = GNUNET_YES;
2653 if (GNUNET_YES == queue->finishing)
2654 return; /* this queue is dying, drop msg */
2655 GNUNET_assert (0 == queue->pwrite_off);
2657 box.header.size = htons (msize);
2658 calculate_hmac (&queue->out_hmac, msg, msize, &box.hmac);
2659 memcpy (&queue->pwrite_buf[queue->pwrite_off], &box, sizeof(box));
2660 queue->pwrite_off += sizeof(box);
2661 memcpy (&queue->pwrite_buf[queue->pwrite_off], msg, msize);
2662 queue->pwrite_off += msize;
2664 "%lu bytes of plaintext to send\n", queue->pwrite_off);
2665 GNUNET_assert (NULL != queue->sock);
2666 if (NULL == queue->write_task)
2667 queue->write_task =
2669 queue->sock,
2670 &queue_write,
2671 queue);
2672}
2673
2674
2683static void
2684mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state)
2685{
2686 struct Queue *queue = impl_state;
2687
2688 if (mq == queue->mq)
2689 {
2690 queue->mq = NULL;
2692 }
2693}
2694
2695
2702static void
2703mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
2704{
2705 struct Queue *queue = impl_state;
2706
2707 GNUNET_assert (0 != queue->pwrite_off);
2708 queue->pwrite_off = 0;
2709}
2710
2711
2721static void
2722mq_error (void *cls, enum GNUNET_MQ_Error error)
2723{
2724 struct Queue *queue = cls;
2725
2727 "MQ error in queue to %s: %d\n",
2728 GNUNET_i2s (&queue->target),
2729 (int) error);
2731}
2732
2733
2741static void
2743{
2744 queue->nt =
2745 GNUNET_NT_scanner_get_type (is, queue->address, queue->address_len);
2747 queue_map,
2748 &queue->key,
2749 queue,
2752 "# queues active",
2754 GNUNET_NO);
2755 queue->timeout =
2758 &mq_destroy,
2759 &mq_cancel,
2760 queue,
2761 NULL,
2762 &mq_error,
2763 queue);
2764}
2765
2766
2777static void
2779 const struct GNUNET_CRYPTO_HpkeEncapsulation *c)
2780{
2781 const struct GNUNET_PeerIdentity *my_identity;
2783 struct TcpHandshakeSignature ths;
2784 struct TCPConfirmation tc;
2785
2789
2790 memcpy (queue->cwrite_buf, c, sizeof(*c));
2791 queue->cwrite_off = sizeof(*c);
2792 /* compute 'tc' and append in encrypted format to cwrite_buf */
2793 tc.sender = *my_identity;
2794 tc.monotonic_time =
2797 &tc.challenge,
2798 sizeof(tc.challenge));
2799 ths.purpose.purpose = htonl (
2801 ths.purpose.size = htonl (sizeof(ths));
2802 ths.sender = *my_identity;
2803 ths.receiver = queue->target;
2804 ths.ephemeral = *c;
2805 ths.monotonic_time = tc.monotonic_time;
2806 ths.challenge = tc.challenge;
2808 &ths,
2809 &tc.sender_sig);
2810 GNUNET_assert (0 ==
2811 gcry_cipher_encrypt (queue->out_cipher,
2812 &queue->cwrite_buf[queue->cwrite_off],
2813 sizeof(tc),
2814 &tc,
2815 sizeof(tc)));
2816 queue->challenge = tc.challenge;
2817 queue->cwrite_off += sizeof(tc);
2818
2820 "handshake written\n");
2821}
2822
2823
2831static void
2833{
2835 struct GNUNET_ShortHashCode k;
2836
2838 &c, &k);
2839 setup_out_cipher (queue, &k);
2840 transmit_kx (queue, &c);
2841}
2842
2843
2849static void
2850handshake_monotime_store_cb (void *cls, int success)
2851{
2852 struct Queue *queue = cls;
2853 if (GNUNET_OK != success)
2854 {
2856 "Failed to store handshake monotonic time in PEERSTORE!\n");
2857 }
2858 queue->handshake_monotime_sc = NULL;
2859 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
2860}
2861
2862
2870static void
2872 const struct GNUNET_PEERSTORE_Record *record,
2873 const char *emsg)
2874{
2875 struct Queue *queue = cls;
2876 struct GNUNET_TIME_AbsoluteNBO *mtbe;
2877 struct GNUNET_TIME_Absolute mt;
2878 const struct GNUNET_PeerIdentity *pid;
2879 struct GNUNET_TIME_AbsoluteNBO *handshake_monotonic_time;
2880
2881 (void) emsg;
2882
2883 handshake_monotonic_time = &queue->handshake_monotonic_time;
2884 pid = &queue->target;
2886 "tcp handshake with us %s\n",
2888 if (NULL == record)
2889 {
2890 queue->handshake_monotime_get = NULL;
2891 return;
2892 }
2894 "tcp handshake from peer %s\n",
2895 GNUNET_i2s (pid));
2896 if (sizeof(*mtbe) != record->value_size)
2897 {
2898 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
2899 GNUNET_break (0);
2900 return;
2901 }
2902 mtbe = record->value;
2903 mt = GNUNET_TIME_absolute_ntoh (*mtbe);
2905 queue->handshake_monotonic_time).abs_value_us)
2906 {
2908 "Queue from %s dropped, handshake monotime in the past\n",
2909 GNUNET_i2s (&queue->target));
2910 GNUNET_break (0);
2911 GNUNET_PEERSTORE_iteration_stop (queue->handshake_ack_monotime_get);
2912 queue->handshake_ack_monotime_get = NULL;
2914 return;
2915 }
2916 queue->handshake_monotime_sc = GNUNET_PEERSTORE_store (peerstore,
2917 "transport_tcp_communicator",
2918 pid,
2920 handshake_monotonic_time,
2921 sizeof(*
2922 handshake_monotonic_time),
2925 &
2927 queue);
2928}
2929
2930
2942static int
2944 struct TCPConfirmation *tc,
2945 char *ibuf)
2946{
2947 const struct GNUNET_PeerIdentity *my_identity;
2948 struct TcpHandshakeSignature ths;
2950
2953
2955 0 ==
2956 gcry_cipher_decrypt (queue->in_cipher,
2957 tc,
2958 sizeof(*tc),
2959 &ibuf[sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)],
2960 sizeof(*tc)));
2961 ths.purpose.purpose = htonl (
2963 ths.purpose.size = htonl (sizeof(ths));
2964 ths.sender = tc->sender;
2965 ths.receiver = *my_identity;
2966 memcpy (&ths.ephemeral, ibuf, sizeof(struct GNUNET_CRYPTO_EcdhePublicKey));
2967 ths.monotonic_time = tc->monotonic_time;
2968 ths.challenge = tc->challenge;
2971 &ths,
2972 &tc->sender_sig,
2973 &tc->sender.public_key);
2974 if (GNUNET_YES == ret)
2975 queue->handshake_monotime_get =
2977 "transport_tcp_communicator",
2978 &queue->target,
2981 queue);
2982 return ret;
2983}
2984
2985
2993static void
2994queue_read_kx (void *cls)
2995{
2996 struct Queue *queue = cls;
2997 ssize_t rcvd;
2998 struct GNUNET_TIME_Relative left;
2999 struct TCPConfirmation tc;
3000
3001 queue->read_task = NULL;
3002 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
3003 if (0 == left.rel_value_us)
3004 {
3006 return;
3007 }
3008 rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
3009 &queue->cread_buf[queue->cread_off],
3010 BUF_SIZE - queue->cread_off);
3012 "Received %lu bytes to write in buffer of size %lu for KX from queue %p (expires in %"
3013 PRIu64 ")\n",
3014 rcvd, BUF_SIZE - queue->cread_off, queue, left.rel_value_us);
3015 if (-1 == rcvd)
3016 {
3017 if ((EAGAIN != errno) && (EINTR != errno))
3018 {
3021 return;
3022 }
3023 queue->read_task =
3025 return;
3026 }
3027 if (0 == rcvd)
3028 {
3029 /* Orderly shutdown of connection */
3031 "Socket for queue %p seems to have been closed\n", queue);
3033 return;
3034 }
3035 queue->cread_off += rcvd;
3036 if (queue->cread_off < INITIAL_KX_SIZE)
3037 {
3038 /* read more */
3040 "%lu/%lu bytes of KX read. Rescheduling...\n",
3041 queue->cread_off, INITIAL_KX_SIZE);
3042 queue->read_task =
3044 return;
3045 }
3046 /* we got all the data, let's find out who we are talking to! */
3048 (const struct GNUNET_CRYPTO_HpkeEncapsulation*)
3049 queue->cread_buf,
3050 queue);
3051 if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, queue->cread_buf))
3052 {
3054 "Invalid TCP KX received from %s\n",
3055 GNUNET_a2s (queue->address, queue->address_len));
3057 return;
3058 }
3059 if (0 !=
3060 memcmp (&tc.sender, &queue->target, sizeof(struct GNUNET_PeerIdentity)))
3061 {
3063 "Invalid sender in TCP KX received from %s\n",
3064 GNUNET_a2s (queue->address, queue->address_len));
3066 return;
3067 }
3068 send_challenge (tc.challenge, queue);
3069 queue->write_task =
3071 queue->sock,
3072 &queue_write,
3073 queue);
3074
3075 /* update queue timeout */
3076 queue->timeout =
3078 /* prepare to continue with regular read task immediately */
3079 memmove (queue->cread_buf,
3080 &queue->cread_buf[INITIAL_KX_SIZE],
3081 queue->cread_off - (INITIAL_KX_SIZE));
3083 "cread_off is %lu bytes before adjusting\n",
3084 queue->cread_off);
3085 queue->cread_off -= INITIAL_KX_SIZE;
3087 "cread_off set to %lu bytes\n",
3088 queue->cread_off);
3090}
3091
3092
3099static void
3100proto_read_kx (void *cls)
3101{
3102 struct ProtoQueue *pq = cls;
3103 ssize_t rcvd;
3104 struct GNUNET_TIME_Relative left;
3105 struct Queue *queue;
3106 struct TCPConfirmation tc;
3108
3109 pq->read_task = NULL;
3111 if (0 == left.rel_value_us)
3112 {
3113 free_proto_queue (pq);
3114 return;
3115 }
3116 rcvd = GNUNET_NETWORK_socket_recv (pq->sock,
3117 &pq->ibuf[pq->ibuf_off],
3118 sizeof(pq->ibuf) - pq->ibuf_off);
3120 "Proto received %lu bytes for KX\n", rcvd);
3121 if (-1 == rcvd)
3122 {
3123 if ((EAGAIN != errno) && (EINTR != errno))
3124 {
3126 free_proto_queue (pq);
3127 return;
3128 }
3129 /* try again */
3130 pq->read_task =
3132 return;
3133 }
3134 if (0 == rcvd)
3135 {
3136 /* Orderly shutdown of connection */
3138 "Socket for proto queue %p seems to have been closed\n", pq);
3139 free_proto_queue (pq);
3140 return;
3141 }
3142 pq->ibuf_off += rcvd;
3143 if (sizeof (struct TCPNATProbeMessage) == pq->ibuf_off)
3144 {
3145 struct TCPNATProbeMessage *pm = (struct TCPNATProbeMessage *) pq->ibuf;
3146
3148 &pm->clientIdentity);
3149
3150 queue = GNUNET_new (struct Queue);
3151 queue->target = pm->clientIdentity;
3152 eddsa_pub_to_hpke_key (&queue->target.public_key,
3153 &queue->target_hpke_key);
3156 }
3157 else if (pq->ibuf_off > sizeof(pq->ibuf))
3158 {
3159 /* read more */
3160 pq->read_task =
3162 return;
3163 }
3164 else
3165 {
3166 /* we got all the data, let's find out who we are talking to! */
3167 queue = GNUNET_new (struct Queue);
3169 (const struct GNUNET_CRYPTO_HpkeEncapsulation *) pq->
3170 ibuf,
3171 queue);
3172 if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, pq->ibuf))
3173 {
3175 "Invalid TCP KX received from %s\n",
3176 GNUNET_a2s (pq->address, pq->address_len));
3177 gcry_cipher_close (queue->in_cipher);
3179 free_proto_queue (pq);
3180 return;
3181 }
3182 queue->target = tc.sender;
3183 eddsa_pub_to_hpke_key (&queue->target.public_key,
3184 &queue->target_hpke_key);
3187 }
3188 queue->address = pq->address; /* steals reference */
3189 queue->address_len = pq->address_len;
3190 queue->listen_sock = pq->listen_sock;
3191 queue->sock = pq->sock;
3192
3194 "created queue with target %s\n",
3195 GNUNET_i2s (&queue->target));
3196
3198 "start kx proto\n");
3199
3201 boot_queue (queue);
3202 queue->read_task =
3204 queue->sock,
3205 read_task,
3206 queue);
3207 queue->write_task =
3209 queue->sock,
3210 &queue_write,
3211 queue);
3212 // TODO To early! Move it somewhere else.
3213 // send_challenge (tc.challenge, queue);
3214 queue->challenge_received = tc.challenge;
3215
3217 GNUNET_free (pq);
3218}
3219
3220
3221static struct ProtoQueue *
3223 struct sockaddr *in,
3224 socklen_t addrlen)
3225{
3226 struct ProtoQueue *pq = GNUNET_new (struct ProtoQueue);
3227
3228 if (NULL == sock)
3229 {
3230 // sock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET, addr, addrlen);
3231 sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, 0);
3232 if (NULL == sock)
3233 {
3235 "socket(%d) failed: %s",
3236 in->sa_family,
3237 strerror (errno));
3238 GNUNET_free (in);
3239 GNUNET_free (pq);
3240 return NULL;
3241 }
3242 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, addrlen)) &&
3243 (errno != EINPROGRESS))
3244 {
3246 "connect to `%s' failed: %s",
3247 GNUNET_a2s (in, addrlen),
3248 strerror (errno));
3250 GNUNET_free (in);
3251 GNUNET_free (pq);
3252 return NULL;
3253 }
3254 }
3255 pq->address_len = addrlen;
3256 pq->address = in;
3258 pq->sock = sock;
3260 pq->sock,
3262 pq);
3264
3265 return pq;
3266}
3267
3268
3276static void
3277listen_cb (void *cls)
3278{
3279 struct sockaddr_storage in;
3280 socklen_t addrlen;
3281 struct GNUNET_NETWORK_Handle *sock;
3282 struct ListenTask *lt;
3283 struct sockaddr *in_addr;
3284
3286 "listen_cb\n");
3287
3288 lt = cls;
3289
3290 lt->listen_task = NULL;
3291 GNUNET_assert (NULL != lt->listen_sock);
3292 addrlen = sizeof(in);
3293 memset (&in, 0, sizeof(in));
3295 (struct sockaddr*) &in,
3296 &addrlen);
3297 if ((NULL == sock) && ((EMFILE == errno) || (ENFILE == errno)))
3298 return; /* system limit reached, wait until connection goes down */
3300 lt->listen_sock,
3301 &listen_cb,
3302 lt);
3303 if ((NULL == sock) && ((EAGAIN == errno) || (ENOBUFS == errno)))
3304 return;
3305 if (NULL == sock)
3306 {
3308 return;
3309 }
3310 in_addr = GNUNET_memdup (&in, addrlen);
3311 create_proto_queue (sock, in_addr, addrlen);
3312}
3313
3314
3315static void
3317 const struct sockaddr *addr,
3318 socklen_t addrlen)
3319{
3320 const struct GNUNET_PeerIdentity *my_identity;
3321 struct TCPNATProbeMessage pm;
3322 struct ProtoQueue *pq;
3323 struct sockaddr *in_addr;
3324 (void) cls;
3325
3328
3330 "addr->sa_family %d\n",
3331 addr->sa_family);
3333 "Try to connect back\n");
3334 in_addr = GNUNET_memdup (addr, addrlen);
3336 "in_addr->sa_family %d\n",
3337 in_addr->sa_family);
3338 pq = create_proto_queue (NULL, in_addr, addrlen);
3339 if (NULL != pq)
3340 {
3341 pm.header.size = htons (sizeof(struct TCPNATProbeMessage));
3342 pm.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE);
3343 pm.clientIdentity = *my_identity;
3344 memcpy (pq->write_buf, &pm, sizeof(struct TCPNATProbeMessage));
3345 pq->write_off = sizeof(struct TCPNATProbeMessage);
3347 pq->sock,
3349 pq);
3350 }
3351 else
3352 {
3354 "Couldn't create ProtoQueue for sending TCPNATProbeMessage\n");
3355 }
3356}
3357
3358
3359static void
3361{
3362 struct sockaddr *in = cls;
3363 struct PendingReversal *pending_reversal;
3364 struct GNUNET_HashCode key;
3365
3367 sizeof(struct sockaddr),
3368 &key);
3370 &key);
3371
3372 GNUNET_assert (NULL != pending_reversal);
3373
3375 &key,
3376 pending_reversal))
3378 "No pending reversal found for address %s\n",
3379 GNUNET_a2s (in, sizeof (struct sockaddr)));
3380 GNUNET_free (pending_reversal->in);
3381 GNUNET_free (pending_reversal);
3382}
3383
3384
3403static int
3404mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
3405{
3406 struct sockaddr *in;
3407 socklen_t in_len = 0;
3408 const char *path;
3409 struct sockaddr_in *v4;
3410 struct sockaddr_in6 *v6;
3411 unsigned int is_natd = GNUNET_NO;
3412 struct GNUNET_HashCode key;
3413 struct GNUNET_HashCode queue_map_key;
3414 struct GNUNET_HashContext *hsh;
3415 struct Queue *queue;
3416
3418 "Connecting to %s at %s\n",
3419 GNUNET_i2s (peer),
3420 address);
3421 if (0 != strncmp (address,
3423 strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
3424 {
3425 GNUNET_break_op (0);
3426 return GNUNET_SYSERR;
3427 }
3428 path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
3429 in = tcp_address_to_sockaddr (path, &in_len);
3430
3431 if (NULL == in)
3432 {
3434 "Failed to setup TCP socket address\n");
3435 return GNUNET_SYSERR;
3436 }
3437
3439 "in %s\n",
3440 GNUNET_a2s (in, in_len));
3441
3444 GNUNET_CRYPTO_hash_context_read (hsh, peer, sizeof (*peer));
3445 GNUNET_CRYPTO_hash_context_finish (hsh, &queue_map_key);
3447
3448 if (NULL != queue)
3449 {
3451 "Queue for %s already exists or is in construction\n", address);
3452 GNUNET_free (in);
3453 return GNUNET_NO;
3454 }
3455 switch (in->sa_family)
3456 {
3457 case AF_INET:
3458 v4 = (struct sockaddr_in *) in;
3459 if (0 == v4->sin_port)
3460 {
3461 is_natd = GNUNET_YES;
3463 sizeof(struct sockaddr),
3464 &key);
3467 &key))
3468 {
3470 "There is already a request reversal for `%s'at `%s'\n",
3471 GNUNET_i2s (peer),
3472 address);
3473 GNUNET_free (in);
3474 return GNUNET_SYSERR;
3475 }
3476 }
3477 break;
3478
3479 case AF_INET6:
3480 if (GNUNET_YES == disable_v6)
3481 {
3483 "IPv6 disabled, skipping %s\n", address);
3484 GNUNET_free (in);
3485 return GNUNET_SYSERR;
3486 }
3487 v6 = (struct sockaddr_in6 *) in;
3488 if (0 == v6->sin6_port)
3489 {
3491 "Request reversal for `%s' at `%s' not possible for an IPv6 address\n",
3492 GNUNET_i2s (peer),
3493 address);
3494 GNUNET_free (in);
3495 return GNUNET_SYSERR;
3496 }
3497 break;
3498
3499 default:
3500 GNUNET_assert (0);
3501 }
3502
3503 if (GNUNET_YES == is_natd)
3504 {
3505 struct sockaddr_in local_sa;
3506 struct PendingReversal *pending_reversal;
3507
3508 memset (&local_sa, 0, sizeof(local_sa));
3509 local_sa.sin_family = AF_INET;
3510 local_sa.sin_port = htons (bind_port);
3511 /* We leave sin_address at 0, let the kernel figure it out,
3512 even if our bind() is more specific. (May want to reconsider
3513 later.) */
3514 if (GNUNET_OK != GNUNET_NAT_request_reversal (nat, &local_sa, v4))
3515 {
3517 "request reversal for `%s' at `%s' failed\n",
3518 GNUNET_i2s (peer),
3519 address);
3520 GNUNET_free (in);
3521 return GNUNET_SYSERR;
3522 }
3523 pending_reversal = GNUNET_new (struct PendingReversal);
3524 pending_reversal->in = in;
3527 &key,
3528 pending_reversal,
3530 pending_reversal->target = *peer;
3532 &
3534 in);
3536 "Created NAT WAIT connection to `%s' at `%s'\n",
3537 GNUNET_i2s (peer),
3538 GNUNET_a2s (in, sizeof (struct sockaddr)));
3539 }
3540 else
3541 {
3542 struct GNUNET_NETWORK_Handle *sock;
3543
3544 sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM,
3545 IPPROTO_TCP);
3546 if (NULL == sock)
3547 {
3549 "socket(%d) failed: %s",
3550 in->sa_family,
3551 strerror (errno));
3552 GNUNET_free (in);
3553 return GNUNET_SYSERR;
3554 }
3555 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, in_len)) &&
3556 (errno != EINPROGRESS))
3557 {
3559 "connect to `%s' failed: %s",
3560 address,
3561 strerror (errno));
3563 GNUNET_free (in);
3564 return GNUNET_SYSERR;
3565 }
3566
3567 queue = GNUNET_new (struct Queue);
3568 queue->target = *peer;
3569 eddsa_pub_to_hpke_key (&queue->target.public_key, &queue->target_hpke_key);
3570 queue->key = queue_map_key;
3571 queue->address = in;
3572 queue->address_len = in_len;
3573 queue->sock = sock;
3575 boot_queue (queue);
3577 "booted queue with target %s\n",
3578 GNUNET_i2s (&queue->target));
3579 // queue->mq_awaits_continue = GNUNET_YES;
3580 queue->read_task =
3582 queue->sock,
3584 queue);
3585
3586
3588 "start kx mq_init\n");
3589
3591 queue->write_task =
3593 queue->sock,
3594 &queue_write,
3595 queue);
3596 }
3597
3598 return GNUNET_OK;
3599}
3600
3601
3610static int
3612 const struct GNUNET_HashCode *key,
3613 void *value)
3614{
3615 struct ListenTask *lt = value;
3616
3617 (void) cls;
3618 (void) key;
3619 if (NULL != lt->listen_task)
3620 {
3622 lt->listen_task = NULL;
3623 }
3624 if (NULL != lt->listen_sock)
3625 {
3627 lt->listen_sock = NULL;
3628 }
3629 GNUNET_free (lt);
3630 return GNUNET_OK;
3631}
3632
3633
3642static int
3644 const struct GNUNET_HashCode *target,
3645 void *value)
3646{
3647 struct Queue *queue = value;
3648
3649 (void) cls;
3650 (void) target;
3652 return GNUNET_OK;
3653}
3654
3655
3661static void
3662do_shutdown (void *cls)
3663{
3665 "Shutdown %s!\n",
3666 shutdown_running ? "running" : "not running");
3667
3669 return;
3670 else
3672
3673 while (NULL != proto_head)
3675 if (NULL != nat)
3676 {
3678 nat = NULL;
3679 }
3687 if (NULL != ch)
3688 {
3691 ch = NULL;
3692 }
3693 if (NULL != stats)
3694 {
3696 stats = NULL;
3697 }
3698 if (NULL != is)
3699 {
3701 is = NULL;
3702 }
3703 if (NULL != pils)
3704 {
3706 pils = NULL;
3707 }
3708 if (NULL != key_ring)
3709 {
3711 key_ring = NULL;
3712 }
3713 if (NULL != peerstore)
3714 {
3716 peerstore = NULL;
3717 }
3718 if (NULL != resolve_request_handle)
3719 {
3722 }
3724 "Shutdown done!\n");
3725}
3726
3727
3739static void
3740enc_notify_cb (void *cls,
3741 const struct GNUNET_PeerIdentity *sender,
3742 const struct GNUNET_MessageHeader *msg)
3743{
3744 (void) cls;
3745 (void) sender;
3746 (void) msg;
3747 GNUNET_break_op (0);
3748}
3749
3750
3764static void
3766 void **app_ctx,
3767 int add_remove,
3769 const struct sockaddr *addr,
3770 socklen_t addrlen)
3771{
3772 char *my_addr;
3774
3776 "nat address cb %s %s\n",
3777 add_remove ? "add" : "remove",
3778 GNUNET_a2s (addr, addrlen));
3779
3780 if (GNUNET_YES == add_remove)
3781 {
3783
3784 GNUNET_asprintf (&my_addr,
3785 "%s-%s",
3787 GNUNET_a2s (addr, addrlen));
3788 nt = GNUNET_NT_scanner_get_type (is, addr, addrlen);
3789 ai =
3791 my_addr,
3792 nt,
3794 GNUNET_free (my_addr);
3795 *app_ctx = ai;
3796 }
3797 else
3798 {
3799 ai = *app_ctx;
3801 *app_ctx = NULL;
3802 }
3803}
3804
3805
3809static void
3810add_addr (struct sockaddr *in, socklen_t in_len)
3811{
3812
3813 struct Addresses *saddrs;
3814
3816 "add address %s\n",
3817 GNUNET_a2s (in, in_len));
3818
3819 saddrs = GNUNET_new (struct Addresses);
3820 saddrs->addr = in;
3821 saddrs->addr_len = in_len;
3823
3825 "after add address %s\n",
3826 GNUNET_a2s (in, in_len));
3827
3829 "add address %s\n",
3830 GNUNET_a2s (saddrs->addr, saddrs->addr_len));
3831
3832 addrs_lens++;
3833}
3834
3835
3843static int
3844init_socket (struct sockaddr *addr,
3845 socklen_t in_len)
3846{
3847 struct sockaddr_storage in_sto;
3848 socklen_t sto_len;
3849 struct GNUNET_NETWORK_Handle *listen_sock;
3850 struct ListenTask *lt;
3851 int sockfd;
3852 struct GNUNET_HashCode h_sock;
3853
3854 if (NULL == addr)
3855 {
3857 "Address is NULL.\n");
3858 return GNUNET_SYSERR;
3859 }
3860
3862 "address %s\n",
3863 GNUNET_a2s (addr, in_len));
3864
3865 listen_sock =
3866 GNUNET_NETWORK_socket_create (addr->sa_family, SOCK_STREAM, IPPROTO_TCP);
3867 if (NULL == listen_sock)
3868 {
3870 return GNUNET_SYSERR;
3871 }
3872
3873 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (listen_sock, addr, in_len))
3874 {
3876 GNUNET_NETWORK_socket_close (listen_sock);
3877 listen_sock = NULL;
3878 return GNUNET_SYSERR;
3879 }
3880
3881 if (GNUNET_OK !=
3882 GNUNET_NETWORK_socket_listen (listen_sock,
3883 5))
3884 {
3886 "listen");
3887 GNUNET_NETWORK_socket_close (listen_sock);
3888 listen_sock = NULL;
3889 return GNUNET_SYSERR;
3890 }
3891
3892 /* We might have bound to port 0, allowing the OS to figure it out;
3893 thus, get the real IN-address from the socket */
3894 sto_len = sizeof(in_sto);
3895
3896 if (0 != getsockname (GNUNET_NETWORK_get_fd (listen_sock),
3897 (struct sockaddr *) &in_sto,
3898 &sto_len))
3899 {
3900 memcpy (&in_sto, addr, in_len);
3901 sto_len = in_len;
3902 }
3903
3904 // addr = (struct sockaddr *) &in_sto;
3905 in_len = sto_len;
3907 "Bound to `%s'\n",
3908 GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len));
3909 if (NULL == stats)
3910 stats = GNUNET_STATISTICS_create ("communicator-tcp", cfg);
3911
3912 if (NULL == is)
3914
3915 /* start listening */
3916
3917 lt = GNUNET_new (struct ListenTask);
3918 lt->listen_sock = listen_sock;
3919
3921 listen_sock,
3922 &listen_cb,
3923 lt);
3924
3926 "creating hash\n");
3927 sockfd = GNUNET_NETWORK_get_fd (lt->listen_sock);
3928 GNUNET_CRYPTO_hash (&sockfd,
3929 sizeof(int),
3930 &h_sock);
3931
3933 "creating map\n");
3934 if (NULL == lt_map)
3936
3938 "creating map entry\n");
3941 &h_sock,
3942 lt,
3944
3946 "map entry created\n");
3947
3948 if (NULL == queue_map)
3950
3951 if (NULL == ch)
3956 &mq_init,
3957 NULL,
3959 NULL,
3960 NULL);
3961
3962 if (NULL == ch)
3963 {
3964 GNUNET_break (0);
3965 if (NULL != resolve_request_handle)
3968 return GNUNET_SYSERR;
3969 }
3970
3971 add_addr (addr, in_len);
3972 return GNUNET_OK;
3973
3974}
3975
3976
3980static void
3982{
3983 struct sockaddr **saddrs;
3984 socklen_t *saddr_lens;
3985 int i;
3986 size_t len;
3987
3989 "starting nat register!\n");
3990 len = 0;
3991 i = 0;
3992 saddrs = GNUNET_malloc ((addrs_lens) * sizeof(struct sockaddr *));
3993 saddr_lens = GNUNET_malloc ((addrs_lens) * sizeof(socklen_t));
3994 for (struct Addresses *pos = addrs_head; NULL != pos; pos = pos->next)
3995 {
3997 "registering address %s\n",
3998 GNUNET_a2s (pos->addr, pos->addr_len));
3999
4000 saddr_lens[i] = pos->addr_len;
4001 len += saddr_lens[i];
4002 saddrs[i] = GNUNET_memdup (pos->addr, saddr_lens[i]);
4003 i++;
4004 }
4005
4007 "registering addresses %lu %lu %lu %lu\n",
4008 (addrs_lens) * sizeof(struct sockaddr *),
4009 (addrs_lens) * sizeof(socklen_t),
4010 len,
4014 IPPROTO_TCP,
4015 addrs_lens,
4016 (const struct sockaddr **) saddrs,
4017 saddr_lens,
4020 NULL /* closure */);
4021 for (i = addrs_lens - 1; i >= 0; i--)
4022 GNUNET_free (saddrs[i]);
4023 GNUNET_free (saddrs);
4024 GNUNET_free (saddr_lens);
4025
4026 if (NULL == nat)
4027 {
4028 GNUNET_break (0);
4029 if (NULL != resolve_request_handle)
4032 }
4033}
4034
4035
4043static void
4045 const struct sockaddr *addr,
4046 socklen_t in_len)
4047{
4048 struct sockaddr_in *v4;
4049 struct sockaddr_in6 *v6;
4050 struct sockaddr *in;
4051
4052 (void) cls;
4053 if (NULL != addr)
4054 {
4055 if (AF_INET == addr->sa_family)
4056 {
4057 v4 = (struct sockaddr_in *) addr;
4058 in = tcp_address_to_sockaddr_numeric_v4 (&in_len, *v4, bind_port);// _global);
4059 }
4060 else if (AF_INET6 == addr->sa_family)
4061 {
4062 v6 = (struct sockaddr_in6 *) addr;
4063 in = tcp_address_to_sockaddr_numeric_v6 (&in_len, *v6, bind_port);// _global);
4064 }
4065 else
4066 {
4068 "Address family %u not suitable (not AF_INET %u nor AF_INET6 %u \n",
4069 addr->sa_family,
4070 AF_INET,
4071 AF_INET6);
4072 return;
4073 }
4074 init_socket (in, in_len);
4075 }
4076 else
4077 {
4079 "Address is NULL. This might be an error or the resolver finished resolving.\n");
4080 if (NULL == addrs_head)
4081 {
4083 "Resolver finished resolving, but we do not listen to an address!.\n");
4084 return;
4085 }
4086 nat_register ();
4087 }
4088}
4089
4090
4099static void
4100run (void *cls,
4101 char *const *args,
4102 const char *cfgfile,
4103 const struct GNUNET_CONFIGURATION_Handle *c)
4104{
4105 char *bindto;
4106 struct sockaddr *in;
4107 socklen_t in_len;
4108 struct sockaddr_in v4;
4109 struct sockaddr_in6 v6;
4110 char *start;
4111 unsigned int port;
4112 char dummy[2];
4113 char *rest = NULL;
4114 struct PortOnlyIpv4Ipv6 *po;
4115 socklen_t addr_len_ipv4;
4116 socklen_t addr_len_ipv6;
4117
4118 (void) cls;
4119
4121 memset (&v4,0,sizeof(struct sockaddr_in));
4122 memset (&v6,0,sizeof(struct sockaddr_in6));
4123 cfg = c;
4124 if (GNUNET_OK !=
4127 "BINDTO",
4128 &bindto))
4129 {
4132 "BINDTO");
4133 return;
4134 }
4135 if (GNUNET_OK !=
4138 "MAX_QUEUE_LENGTH",
4140 {
4142 }
4143 if (GNUNET_OK !=
4146 "REKEY_INTERVAL",
4148 {
4150 }
4151 if (GNUNET_OK !=
4154 "REKEY_MAX_BYTES",
4156 {
4158 }
4160 if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
4161 (GNUNET_YES ==
4164 "DISABLE_V6")))
4165 {
4167 }
4169 GNUNET_assert (NULL != key_ring);
4170 pils = GNUNET_PILS_connect (cfg, NULL, NULL);
4171 GNUNET_assert (NULL != pils);
4173 if (NULL == peerstore)
4174 {
4175 GNUNET_free (bindto);
4176 GNUNET_break (0);
4178 return;
4179 }
4180
4182
4183 if (1 == sscanf (bindto, "%u%1s", &bind_port, dummy))
4184 {
4188 "address po %s\n",
4190 if (NULL != po->addr_ipv4)
4191 {
4193 }
4194 if (NULL != po->addr_ipv6)
4195 {
4198 }
4199 GNUNET_free (po);
4200 nat_register ();
4201 GNUNET_free (bindto);
4202 return;
4203 }
4204
4205 start = extract_address (bindto);
4206 // FIXME: check for NULL == start...
4207 if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
4208 {
4209 bind_port = extract_port (bindto);
4210
4212 init_socket (in, in_len);
4213 nat_register ();
4215 GNUNET_free (bindto);
4216 return;
4217 }
4218
4219 if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
4220 {
4221 bind_port = extract_port (bindto);
4223 init_socket (in, in_len);
4224 nat_register ();
4226 GNUNET_free (bindto);
4227 return;
4228 }
4229
4230 bind_port = extract_port (bindto);
4232 ":",
4233 &rest),
4234 AF_UNSPEC,
4237 &port);
4238
4239 GNUNET_free (bindto);
4241}
4242
4243
4251int
4252main (int argc, char *const *argv)
4253{
4254 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
4256 };
4257 int ret;
4258
4260 "Starting tcp communicator\n");
4261
4262 ret = (GNUNET_OK ==
4264 argc,
4265 argv,
4266 "gnunet-communicator-tcp",
4267 _ ("GNUnet TCP communicator"),
4268 options,
4269 &run,
4270 NULL))
4271 ? 0
4272 : 1;
4273 return ret;
4274}
4275
4276
4277/* end of gnunet-communicator-tcp.c */
struct GNUNET_GETOPT_CommandLineOption options[]
Definition 002.c:5
struct GNUNET_MessageHeader * msg
Definition 005.c:2
int main()
Program to simulate results from GCP_get_desirability_of_path() for various plausible inputs.
static int start
Set if we are to start default services (including ARM).
Definition gnunet-arm.c:38
static int ret
Final status code.
Definition gnunet-arm.c:93
static int do_shutdown
Set to GNUNET_YES if we are shutting down.
static uint16_t port
Port number.
Definition gnunet-bcd.c:146
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 *`.
#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.
static void eddsa_pub_to_hpke_key(const struct GNUNET_CRYPTO_EddsaPublicKey *edpk, struct GNUNET_CRYPTO_HpkePublicKey *pk)
#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 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 void eddsa_priv_to_hpke_key(const struct GNUNET_CRYPTO_EddsaPrivateKey *edpk, struct GNUNET_CRYPTO_HpkePrivateKey *pk)
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.
#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.
static struct GNUNET_PILS_KeyRing * key_ring
For PILS.
#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)
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 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 void mq_send(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *msg, void *impl_state)
Signature of functions implementing the sending functionality of a message queue.
static struct GNUNET_PILS_Handle * pils
For PILS.
static void start_initial_kx_out(struct Queue *queue)
Initialize our key material for outgoing transmissions and inform the other peer about it.
static void free_proto_queue(struct ProtoQueue *pq)
Closes socket and frees memory associated with pq.
static struct GNUNET_CONTAINER_MultiHashMap * lt_map
ListenTasks (map from socket to struct ListenTask)
static 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_BlindablePrivateKey pk
Private key from command line option, or NULL.
struct GNUNET_SCHEDULER_Task * read_task
static void queue(const char *label, uint32_t rd_count, struct GNUNET_GNSRECORD_Data *rd, const struct Zone *zone)
Add hostname to the list of requests to be made.
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 my_identity
Identity of this peer.
struct GNUNET_CRYPTO_EddsaPrivateKey my_private_key
The current private key.
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.
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
Core service; the main API for encrypted P2P communications.
API to the peerstore service.
struct GNUNET_PILS_Handle * GNUNET_PILS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_PILS_PidChangeCallback pid_change_cb, void *cls)
Connect to the PILS service.
Definition pils_api.c:465
void GNUNET_PILS_disconnect(struct GNUNET_PILS_Handle *handle)
Disconnect from the PILS service.
Definition pils_api.c:488
struct GNUNET_PILS_KeyRing * GNUNET_PILS_create_key_ring(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_SCHEDULER_TaskCallback init_cb, void *cls)
Create a key ring handle to use the current peer identity key.
Definition pils_api.c:804
void GNUNET_PILS_destroy_key_ring(struct GNUNET_PILS_KeyRing *key_ring)
Destroy a key ring handle and free its memory.
Definition pils_api.c:864
const struct GNUNET_PeerIdentity * GNUNET_PILS_get_identity(const struct GNUNET_PILS_Handle *handle)
Return the current peer identity of a given handle.
Definition pils_api.c:727
const struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_PILS_key_ring_get_private_key(const struct GNUNET_PILS_KeyRing *key_ring)
Return the current private key of a given key ring handle.
Definition pils_api.c:887
Constants for network protocols.
Functions related to doing DNS lookups.
#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE_ACK
Signature by a peer sending back the nonce received at initial handshake.
#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_REKEY
Signature used by TCP communicator rekey.
#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE
Signature used by TCP communicator handshake.
API to create, modify and access statistics.
API of the transport service towards the communicator processes.
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.
GNUNET_TRANSPORT_ConnectionStatus
Possible states of a connection.
struct GNUNET_TRANSPORT_CommunicatorHandle * GNUNET_TRANSPORT_communicator_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *config_section_name, const char *addr_prefix, enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, GNUNET_TRANSPORT_CommunicatorMqInit mq_init, void *mq_init_cls, GNUNET_TRANSPORT_CommunicatorNotify notify_cb, void *notify_cb_cls, GNUNET_TRANSPORT_StartBurstNotify sb)
Connect to the transport service.
struct GNUNET_TRANSPORT_AddressIdentifier * GNUNET_TRANSPORT_communicator_address_add(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const char *address, enum GNUNET_NetworkType nt, struct GNUNET_TIME_Relative expiration)
Notify transport service about an address that this communicator provides for this peer.
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.
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_encaps(const struct GNUNET_CRYPTO_HpkePublicKey *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...
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_elligator_kem_decaps(const struct GNUNET_CRYPTO_HpkePrivateKey *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...
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.
#define GNUNET_CRYPTO_eddsa_sign(priv, ps, sig)
EdDSA sign a given block.
#define GNUNET_CRYPTO_eddsa_verify(purp, ps, sig, pub)
Verify EdDSA signature.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
@ GNUNET_CRYPTO_QUALITY_NONCE
Randomness for IVs etc.
#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.
#define GNUNET_GETOPT_OPTION_END
Marker for the end of the list of options.
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
#define GNUNET_CRYPTO_hkdf_expand(result, out_len, prk,...)
HKDF-Expand using SHA256.
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.
#define GNUNET_CRYPTO_kdf_arg_string(d)
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_sk_to_x25519(const struct GNUNET_CRYPTO_BlindablePrivateKey *sk, struct GNUNET_CRYPTO_HpkePrivateKey *sk_enc)
Convert a GNUnet identity key to a key sutiable for HPKE (X25519)
#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.
GNUNET_GenericReturnValue
Named constants for return values.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_pk_to_x25519(const struct GNUNET_CRYPTO_BlindablePublicKey *pk, struct GNUNET_CRYPTO_HpkePublicKey *pk_enc)
Convert a GNUnet identity key to a key sutiable for HPKE (X25519)
#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.
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...
@ 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_memdup(buf, size)
Allocate and initialize a block of memory.
GNUNET_MQ_Error
Error codes for the queue.
struct GNUNET_MQ_Handle * GNUNET_MQ_queue_for_callbacks(GNUNET_MQ_SendImpl send, GNUNET_MQ_DestroyImpl destroy, GNUNET_MQ_CancelImpl cancel, void *impl_state, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *cls)
Create a message queue for the specified handlers.
Definition mq.c:482
void GNUNET_MQ_impl_send_continue(struct GNUNET_MQ_Handle *mq)
Call the send implementation for the next queued message, if any.
Definition mq.c:437
int GNUNET_NAT_request_reversal(struct GNUNET_NAT_Handle *nh, const struct sockaddr_in *local_sa, const struct sockaddr_in *remote_sa)
We learned about a peer (possibly behind NAT) so run the gnunet-nat-client to send dummy ICMP respons...
Definition nat_api.c:675
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:703
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.
void GNUNET_NT_scanner_done(struct GNUNET_NT_InterfaceScanner *is)
Terminate interface scanner.
Definition nt.c:428
struct GNUNET_NT_InterfaceScanner * GNUNET_NT_scanner_init(void)
Initialize the address characterization client handle.
Definition nt.c:407
enum GNUNET_NetworkType GNUNET_NT_scanner_get_type(struct GNUNET_NT_InterfaceScanner *is, const struct sockaddr *addr, socklen_t addrlen)
Returns where the address is located: loopback, LAN or WAN.
Definition nt.c:309
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
struct GNUNET_PEERSTORE_IterateContext * GNUNET_PEERSTORE_iteration_start(struct GNUNET_PEERSTORE_Handle *h, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, GNUNET_PEERSTORE_Processor callback, void *callback_cls)
Iterate over peerstore entries.
void GNUNET_PEERSTORE_iteration_next(struct GNUNET_PEERSTORE_IterateContext *ic, uint64_t limit)
Continue an iteration.
void GNUNET_PEERSTORE_store_cancel(struct GNUNET_PEERSTORE_StoreContext *sc)
Cancel a store request.
void GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h)
Disconnect from the PEERSTORE service.
struct GNUNET_PEERSTORE_Handle * GNUNET_PEERSTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the PEERSTORE service.
#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE
Key used to store sender's monotonic time from handshake message.
struct GNUNET_PEERSTORE_StoreContext * GNUNET_PEERSTORE_store(struct GNUNET_PEERSTORE_Handle *h, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, const void *value, size_t size, struct GNUNET_TIME_Absolute expiry, enum GNUNET_PEERSTORE_StoreOption options, GNUNET_PEERSTORE_Continuation cont, void *cont_cls)
Store a new entry in the PEERSTORE.
#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK
Key used to store sender's monotonic time from handshake ack message.
#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY
Key used to store sender's monotonic time from rekey message.
void GNUNET_PEERSTORE_iteration_stop(struct GNUNET_PEERSTORE_IterateContext *ic)
Cancel an iteration.
@ GNUNET_PEERSTORE_STOREOPTION_REPLACE
Delete any previous values for the given key before storing the given value.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition program.c:407
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_CONFIRMATION_ACK
TCP communicator confirmation ack.
#define GNUNET_MESSAGE_TYPE_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.
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:572
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:1517
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:1588
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:1345
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:986
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:1310
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:1283
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition time.c:406
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition strings.c:604
#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:636
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition strings.c:665
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
#define max(x, y)
static unsigned int size
Size of the "table".
Definition peer.c:68
#define _(String)
GNU gettext support macro.
Definition platform.h:179
static struct GNUNET_MQ_Handle * mq
Our connection to the resolver service, created on-demand, but then persists until error or shutdown.
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition scheduler.c:436
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.
A private key for an identity as per LSD0001.
An identity key as per LSD0001.
Type of a nonce used for challenges.
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 public key used for decryption.
A public key used for encryption.
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
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.
Context for a iterate request.
Context for a store request.
A handle for the PILS service.
Definition pils_api.c:82
A simplified handle for using the peer identity key.
Definition pils_api.c:132
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.
Entry in list of pending tasks.
Definition scheduler.c:141
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.
struct GNUNET_MQ_Handle * mq
Queue to talk to the transport service.
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.
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.
struct GNUNET_CRYPTO_HpkePublicKey target_hpke_key
To whom are we talking to.
enum GNUNET_NetworkType nt
Which network type does this queue use?
struct GNUNET_CRYPTO_ChallengeNonceP challenge_received
Challenge value received.
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.
struct GNUNET_SCHEDULER_Task * write_task
ID of write task for this connection.
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.
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?
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
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 sockaddr * address
Address of the other peer.
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_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_CRYPTO_SignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE_ACK.
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_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_CRYPTO_SignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_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_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_SignaturePurpose 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...