GNUnet 0.28.0-dev.3-7-g31e20e2e6
 
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
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 (hmac_secret,
1095 buf,
1096 buf_size,
1097 &mac);
1098 /* truncate to `struct GNUNET_ShortHashCode` */
1099 memcpy (smac, &mac, sizeof(struct GNUNET_ShortHashCode));
1100 /* ratchet hmac key */
1101 GNUNET_CRYPTO_hash (hmac_secret,
1102 sizeof(struct GNUNET_HashCode),
1103 (struct GNUNET_HashCode*) hmac_secret);
1104}
1105
1106
1113static void
1115{
1116 struct TCPFinish fin;
1117
1118 memset (&fin, 0, sizeof(fin));
1119 fin.header.size = htons (sizeof(fin));
1121 calculate_hmac (&queue->out_hmac, &fin, sizeof(fin), &fin.hmac);
1122 /* if there is any message left in pwrite_buf, we
1123 overwrite it (possibly dropping the last message
1124 from CORE hard here) */
1125 memcpy (queue->pwrite_buf, &fin, sizeof(fin));
1126 queue->pwrite_off = sizeof(fin);
1127 /* This flag will ensure that #queue_write() no longer
1128 notifies CORE about the possibility of sending
1129 more data, and that #queue_write() will call
1130 #queue_destroy() once the @c fin was fully written. */
1131 queue->finishing = GNUNET_YES;
1132}
1133
1134
1140static void
1141queue_read (void *cls);
1142
1143
1151static void
1152core_read_finished_cb (void *cls, int success)
1153{
1154 struct Queue *queue = cls;
1155 if (GNUNET_OK != success)
1157 "# messages lost in communicator API towards CORE",
1158 1,
1159 GNUNET_NO);
1160 if (NULL == queue)
1161 return;
1162
1164 "backpressure %u\n",
1165 queue->backpressure);
1166
1167 queue->backpressure--;
1168 /* handle deferred queue destruction */
1169 if ((queue->destroyed) && (0 == queue->backpressure))
1170 {
1172 return;
1173 }
1174 else if (GNUNET_YES != queue->destroyed)
1175 {
1176 queue->timeout =
1178 );
1179 /* possibly unchoke reading, now that CORE made progress */
1180 if (NULL == queue->read_task)
1181 queue->read_task =
1183 queue->timeout),
1184 queue->sock,
1185 &queue_read,
1186 queue);
1187 }
1188}
1189
1190
1200static void
1202 const void *plaintext,
1203 size_t plaintext_len)
1204{
1205 const struct GNUNET_MessageHeader *hdr = plaintext;
1206 int ret;
1207
1209 "pass message from %s to core\n",
1210 GNUNET_i2s (&queue->target));
1211
1212 if (ntohs (hdr->size) != plaintext_len)
1213 {
1214 /* NOTE: If we ever allow multiple CORE messages in one
1215 BOX, this will have to change! */
1216 GNUNET_break (0);
1217 return;
1218 }
1220 &queue->target,
1221 hdr,
1224 queue);
1226 "passed to core\n");
1227 if (GNUNET_OK == ret)
1228 queue->backpressure++;
1229 GNUNET_break (GNUNET_NO != ret); /* backpressure not working!? */
1230 if (GNUNET_SYSERR == ret)
1232 "# bytes lost due to CORE not running",
1233 plaintext_len,
1234 GNUNET_NO);
1235}
1236
1237
1247static void
1249 const struct GNUNET_PeerIdentity *pid,
1250 gcry_cipher_hd_t *cipher,
1251 struct GNUNET_CRYPTO_AuthKey *hmac_key)
1252{
1253 char key[256 / 8];
1254 char ctr[128 / 8];
1255
1256 GNUNET_assert (0 == gcry_cipher_open (cipher,
1257 GCRY_CIPHER_AES256 /* low level: go for speed */
1258 ,
1259 GCRY_CIPHER_MODE_CTR,
1260 0 /* flags */));
1263 key,
1264 sizeof(key),
1265 prk,
1266 GNUNET_CRYPTO_kdf_arg_string ("gnunet-communicator-tcp-key"))
1267 );
1268 GNUNET_assert (0 == gcry_cipher_setkey (*cipher, key, sizeof(key)));
1271 ctr,
1272 sizeof(ctr),
1273 prk,
1274 GNUNET_CRYPTO_kdf_arg_string ("gnunet-communicator-tcp-ctr"))
1275 );
1276 gcry_cipher_setctr (*cipher, ctr, sizeof(ctr));
1279 hmac_key,
1280 sizeof(struct GNUNET_HashCode),
1281 prk,
1282 GNUNET_CRYPTO_kdf_arg_string ("gnunet-communicator-hmac")));
1283}
1284
1285
1291static void
1292rekey_monotime_store_cb (void *cls, int success)
1293{
1294 struct Queue *queue = cls;
1295 if (GNUNET_OK != success)
1296 {
1298 "Failed to store rekey monotonic time in PEERSTORE!\n");
1299 }
1300 queue->rekey_monotime_sc = NULL;
1301 GNUNET_PEERSTORE_iteration_next (queue->rekey_monotime_get, 1);
1302}
1303
1304
1312static void
1314 const struct GNUNET_PEERSTORE_Record *record,
1315 const char *emsg)
1316{
1317 struct Queue *queue = cls;
1318 struct GNUNET_TIME_AbsoluteNBO *mtbe;
1319 struct GNUNET_TIME_Absolute mt;
1320 const struct GNUNET_PeerIdentity *pid;
1321 struct GNUNET_TIME_AbsoluteNBO *rekey_monotonic_time;
1322
1323 (void) emsg;
1324
1325 rekey_monotonic_time = &queue->rekey_monotonic_time;
1326 pid = &queue->target;
1327 if (NULL == record)
1328 {
1329 queue->rekey_monotime_get = NULL;
1330 return;
1331 }
1332 if (sizeof(*mtbe) != record->value_size)
1333 {
1334 GNUNET_PEERSTORE_iteration_next (queue->rekey_monotime_get, 1);
1335 GNUNET_break (0);
1336 return;
1337 }
1338 mtbe = record->value;
1339 mt = GNUNET_TIME_absolute_ntoh (*mtbe);
1341 queue->rekey_monotonic_time).abs_value_us)
1342 {
1344 "Queue from %s dropped, rekey monotime in the past\n",
1345 GNUNET_i2s (&queue->target));
1346 GNUNET_break (0);
1347 GNUNET_PEERSTORE_iteration_stop (queue->rekey_monotime_get);
1348 queue->rekey_monotime_get = NULL;
1349 // FIXME: Why should we try to gracefully finish here??
1351 return;
1352 }
1353 queue->rekey_monotime_sc = GNUNET_PEERSTORE_store (peerstore,
1354 "transport_tcp_communicator",
1355 pid,
1357 rekey_monotonic_time,
1358 sizeof(*
1359 rekey_monotonic_time),
1363 queue);
1364}
1365
1366
1373static void
1375 const struct GNUNET_CRYPTO_HpkeEncapsulation *c,
1376 struct Queue *queue)
1377{
1378 const struct GNUNET_PeerIdentity *my_identity;
1380 struct GNUNET_CRYPTO_HpkePrivateKey my_hpke_key;
1381 struct GNUNET_ShortHashCode k;
1382
1386
1387 eddsa_priv_to_hpke_key (my_private_key, &my_hpke_key);
1388
1390 c,
1391 &k);
1392 setup_cipher (&k, my_identity, &queue->in_cipher, &queue->in_hmac);
1393}
1394
1395
1402static void
1417
1418
1427static void
1428do_rekey (struct Queue *queue, const struct TCPRekey *rekey)
1429{
1430 const struct GNUNET_PeerIdentity *my_identity;
1431 struct TcpRekeySignature thp;
1432
1435
1437 thp.purpose.size = htonl (sizeof(thp));
1439 "do_rekey size %u\n",
1440 thp.purpose.size);
1441 thp.sender = queue->target;
1443 "sender %s\n",
1446 "sender %s\n",
1447 GNUNET_p2s (&queue->target.public_key));
1448 thp.receiver = *my_identity;
1450 "receiver %s\n",
1452 thp.ephemeral = rekey->ephemeral;
1454 "ephemeral %s\n",
1456 );
1457 thp.monotonic_time = rekey->monotonic_time;
1459 "time %s\n",
1462 GNUNET_assert (ntohl ((&thp)->purpose.size) == sizeof (*(&thp)));
1463 if (GNUNET_OK !=
1466 &thp,
1467 &rekey->sender_sig,
1468 &queue->target.public_key))
1469 {
1470 GNUNET_break (0);
1471 // FIXME Why should we try to gracefully finish here?
1473 return;
1474 }
1475 queue->rekey_monotonic_time = rekey->monotonic_time;
1476 queue->rekey_monotime_get = GNUNET_PEERSTORE_iteration_start (peerstore,
1477 "transport_tcp_communicator",
1478 &queue->target,
1480 &
1482 queue);
1483 gcry_cipher_close (queue->in_cipher);
1484 queue->rekeyed = GNUNET_YES;
1485 setup_in_cipher (&rekey->ephemeral, queue);
1486}
1487
1488
1494static void
1495handshake_ack_monotime_store_cb (void *cls, int success)
1496{
1497 struct Queue *queue = cls;
1498
1499 if (GNUNET_OK != success)
1500 {
1502 "Failed to store handshake ack monotonic time in PEERSTORE!\n");
1503 }
1504 queue->handshake_ack_monotime_sc = NULL;
1505 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
1506}
1507
1508
1516static void
1518 const struct GNUNET_PEERSTORE_Record *record,
1519 const char *emsg)
1520{
1521 struct Queue *queue = cls;
1522 struct GNUNET_TIME_AbsoluteNBO *mtbe;
1523 struct GNUNET_TIME_Absolute mt;
1524 const struct GNUNET_PeerIdentity *pid;
1525 struct GNUNET_TIME_AbsoluteNBO *handshake_ack_monotonic_time;
1526
1527 (void) emsg;
1528
1529 handshake_ack_monotonic_time = &queue->handshake_ack_monotonic_time;
1530 pid = &queue->target;
1531 if (NULL == record)
1532 {
1533 queue->handshake_ack_monotime_get = NULL;
1534 return;
1535 }
1536 if (sizeof(*mtbe) != record->value_size)
1537 {
1538 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
1539 GNUNET_break (0);
1540 return;
1541 }
1542 mtbe = record->value;
1543 mt = GNUNET_TIME_absolute_ntoh (*mtbe);
1545 queue->handshake_ack_monotonic_time).abs_value_us)
1546 {
1548 "Queue from %s dropped, handshake ack monotime in the past\n",
1549 GNUNET_i2s (&queue->target));
1550 GNUNET_break (0);
1551 GNUNET_PEERSTORE_iteration_stop (queue->handshake_ack_monotime_get);
1552 queue->handshake_ack_monotime_get = NULL;
1553 // FIXME: Why should we try to gracefully finish here?
1555 return;
1556 }
1557 queue->handshake_ack_monotime_sc =
1559 "transport_tcp_communicator",
1560 pid,
1562 handshake_ack_monotonic_time,
1563 sizeof(*handshake_ack_monotonic_time),
1567 queue);
1568}
1569
1570
1577static void
1579 struct Queue *queue)
1580{
1581 const struct GNUNET_PeerIdentity *my_identity;
1583 struct TCPConfirmationAck tca;
1584 struct TcpHandshakeAckSignature thas;
1585
1589
1591 "sending challenge\n");
1592
1593 tca.header.type = ntohs (
1595 tca.header.size = ntohs (sizeof(tca));
1596 tca.challenge = challenge;
1597 tca.sender = *my_identity;
1598 tca.monotonic_time =
1600 thas.purpose.purpose = htonl (
1602 thas.purpose.size = htonl (sizeof(thas));
1603 thas.sender = *my_identity;
1604 thas.receiver = queue->target;
1605 thas.monotonic_time = tca.monotonic_time;
1606 thas.challenge = tca.challenge;
1608 &thas,
1609 &tca.sender_sig);
1610 GNUNET_assert (0 ==
1611 gcry_cipher_encrypt (queue->out_cipher,
1612 &queue->cwrite_buf[queue->cwrite_off],
1613 sizeof(tca),
1614 &tca,
1615 sizeof(tca)));
1616 queue->cwrite_off += sizeof(tca);
1618 "sending challenge done\n");
1619}
1620
1621
1628static void
1630{
1631 setup_cipher (dh, &queue->target, &queue->out_cipher, &queue->out_hmac);
1633 queue->rekey_left_bytes =
1635}
1636
1637
1644static void
1646{
1647 const struct GNUNET_PeerIdentity *my_identity;
1649 struct TCPRekey rekey;
1650 struct TcpRekeySignature thp;
1651 struct GNUNET_ShortHashCode k;
1652
1656
1657 GNUNET_assert (0 == queue->pwrite_off);
1658 memset (&rekey, 0, sizeof(rekey));
1659 GNUNET_CRYPTO_eddsa_kem_encaps (&queue->target.public_key, &rekey.ephemeral,
1660 &k);
1662 rekey.header.size = ntohs (sizeof(rekey));
1663 rekey.monotonic_time =
1666 thp.purpose.size = htonl (sizeof(thp));
1668 "inject_rekey size %u\n",
1669 thp.purpose.size);
1670 thp.sender = *my_identity;
1672 "sender %s\n",
1674 thp.receiver = queue->target;
1676 "receiver %s\n",
1678 thp.ephemeral = rekey.ephemeral;
1680 "ephemeral %s\n",
1682 );
1683 thp.monotonic_time = rekey.monotonic_time;
1685 "time %s\n",
1689 &thp,
1690 &rekey.sender_sig);
1691 calculate_hmac (&queue->out_hmac, &rekey, sizeof(rekey), &rekey.hmac);
1692 /* Encrypt rekey message with 'old' cipher */
1693 GNUNET_assert (0 ==
1694 gcry_cipher_encrypt (queue->out_cipher,
1695 &queue->cwrite_buf[queue->cwrite_off],
1696 sizeof(rekey),
1697 &rekey,
1698 sizeof(rekey)));
1699 queue->cwrite_off += sizeof(rekey);
1700 /* Setup new cipher for successive messages */
1701 gcry_cipher_close (queue->out_cipher);
1702 setup_out_cipher (queue, &k);
1703}
1704
1705
1706static int
1708 const struct GNUNET_HashCode *key,
1709 void *value)
1710{
1711 struct PendingReversal *pending_reversal = value;
1712 (void) cls;
1713
1714 if (NULL != pending_reversal->timeout_task)
1715 {
1716 GNUNET_SCHEDULER_cancel (pending_reversal->timeout_task);
1717 pending_reversal->timeout_task = NULL;
1718 }
1721 key,
1722 pending_reversal));
1723 GNUNET_free (pending_reversal->in);
1724 GNUNET_free (pending_reversal);
1725 return GNUNET_OK;
1726}
1727
1728
1729static void
1730check_and_remove_pending_reversal (struct sockaddr *in, sa_family_t sa_family,
1731 struct GNUNET_PeerIdentity *sender)
1732{
1733 if (AF_INET == sa_family)
1734 {
1735 struct PendingReversal *pending_reversal;
1736 struct GNUNET_HashCode key;
1737 struct sockaddr_in *natted_address;
1738
1739 natted_address = GNUNET_memdup (in, sizeof (struct sockaddr));
1740 natted_address->sin_port = 0;
1741 GNUNET_CRYPTO_hash (natted_address,
1742 sizeof(struct sockaddr),
1743 &key);
1744
1746 &key);
1747 if (NULL != pending_reversal && (NULL == sender ||
1748 0 != memcmp (sender,
1749 &pending_reversal->target,
1750 sizeof(struct
1752 {
1754 "Removing invalid pending reversal for `%s'at `%s'\n",
1755 GNUNET_i2s (&pending_reversal->target),
1756 GNUNET_a2s (in, sizeof (struct sockaddr)));
1757 pending_reversals_delete_it (NULL, &key, pending_reversal);
1758 }
1759 GNUNET_free (natted_address);
1760 }
1761}
1762
1763
1769static void
1771{
1772 if (NULL != pq->listen_sock)
1773 {
1775 pq->listen_sock = NULL;
1776 }
1777 if (NULL != pq->read_task)
1778 {
1780 pq->read_task = NULL;
1781 }
1782 if (NULL != pq->write_task)
1783 {
1785 pq->write_task = NULL;
1786 }
1787 check_and_remove_pending_reversal (pq->address, pq->address->sa_family, NULL);
1789 GNUNET_free (pq->address);
1791 GNUNET_free (pq);
1792}
1793
1794
1801static void
1803{
1804 struct ProtoQueue *pq = cls;
1805 ssize_t sent;
1806 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "In proto queue write\n");
1807 pq->write_task = NULL;
1808 if (0 != pq->write_off)
1809 {
1810 sent = GNUNET_NETWORK_socket_send (pq->sock,
1811 pq->write_buf,
1812 pq->write_off);
1814 "Sent %lu bytes to TCP queue\n", sent);
1815 if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno))
1816 {
1818 free_proto_queue (pq);
1819 return;
1820 }
1821 if (sent > 0)
1822 {
1823 size_t usent = (size_t) sent;
1824 pq->write_off -= usent;
1825 memmove (pq->write_buf,
1826 &pq->write_buf[usent],
1827 pq->write_off);
1828 }
1829 }
1830 /* do we care to write more? */
1831 if ((0 < pq->write_off))
1832 pq->write_task =
1834 pq->sock,
1836 pq);
1837}
1838
1839
1846static void
1847queue_write (void *cls)
1848{
1849 struct Queue *queue = cls;
1850 ssize_t sent;
1851 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "In queue write\n");
1852 queue->write_task = NULL;
1853 if (0 != queue->cwrite_off)
1854 {
1855 sent = GNUNET_NETWORK_socket_send (queue->sock,
1856 queue->cwrite_buf,
1857 queue->cwrite_off);
1859 "Sent %lu bytes to TCP queue\n", sent);
1860 if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno))
1861 {
1864 return;
1865 }
1866 if (sent > 0)
1867 {
1868 size_t usent = (size_t) sent;
1869 queue->cwrite_off -= usent;
1870 memmove (queue->cwrite_buf,
1871 &queue->cwrite_buf[usent],
1872 queue->cwrite_off);
1873 queue->timeout =
1876 }
1877 }
1878 {
1879 /* can we encrypt more? (always encrypt full messages, needed
1880 such that #mq_cancel() can work!) */
1881 unsigned int we_do_not_need_to_rekey = (0 < queue->rekey_left_bytes
1882 - (queue->cwrite_off
1883 + queue->pwrite_off
1884 + sizeof (struct TCPRekey)));
1885 if (we_do_not_need_to_rekey &&
1886 (queue->pwrite_off > 0) &&
1887 (queue->cwrite_off + queue->pwrite_off <= BUF_SIZE))
1888 {
1890 "Encrypting %lu bytes\n", queue->pwrite_off);
1891 GNUNET_assert (0 ==
1892 gcry_cipher_encrypt (queue->out_cipher,
1893 &queue->cwrite_buf[queue->cwrite_off],
1894 queue->pwrite_off,
1895 queue->pwrite_buf,
1896 queue->pwrite_off));
1897 if (queue->rekey_left_bytes > queue->pwrite_off)
1898 queue->rekey_left_bytes -= queue->pwrite_off;
1899 else
1900 queue->rekey_left_bytes = 0;
1901 queue->cwrite_off += queue->pwrite_off;
1902 queue->pwrite_off = 0;
1903 }
1904 // if ((-1 != unverified_size)&& ((0 == queue->pwrite_off) &&
1905 if (((0 == queue->rekey_left_bytes) ||
1907 queue->rekey_time).rel_value_us)) &&
1908 (((0 == queue->pwrite_off) || ! we_do_not_need_to_rekey) &&
1909 (queue->cwrite_off + sizeof (struct TCPRekey) <= BUF_SIZE)))
1910 {
1912 }
1913 }
1914 if ((0 == queue->pwrite_off) && (! queue->finishing) &&
1915 (GNUNET_YES == queue->mq_awaits_continue))
1916 {
1917 queue->mq_awaits_continue = GNUNET_NO;
1919 }
1920 /* did we just finish writing 'finish'? */
1921 if ((0 == queue->cwrite_off) && (GNUNET_YES == queue->finishing))
1922 {
1924 "Finishing queue\n");
1926 return;
1927 }
1928 /* do we care to write more? */
1929 if ((0 < queue->cwrite_off) || (0 < queue->pwrite_off))
1930 queue->write_task =
1932 queue->sock,
1933 &queue_write,
1934 queue);
1935}
1936
1937
1945static size_t
1947{
1948 const struct GNUNET_MessageHeader *hdr;
1949 const struct TCPConfirmationAck *tca;
1950 const struct TCPBox *box;
1951 const struct TCPRekey *rekey;
1952 const struct TCPFinish *fin;
1953 struct TCPRekey rekeyz;
1954 struct TCPFinish finz;
1955 struct GNUNET_ShortHashCode tmac;
1956 uint16_t type;
1957 size_t size = 0;
1958 struct TcpHandshakeAckSignature thas;
1959 const struct GNUNET_PeerIdentity *my_identity;
1960 const struct GNUNET_CRYPTO_ChallengeNonceP challenge = queue->challenge;
1961
1963 "try handle plaintext!\n");
1964
1965 hdr = (const struct GNUNET_MessageHeader *) queue->pread_buf;
1966 if ((sizeof(*hdr) > queue->pread_off))
1967 {
1969 "Handling plaintext, not even a header!\n");
1970 return 0; /* not even a header */
1971 }
1972
1973 if ((GNUNET_YES != queue->initial_core_kx_done) && (queue->unverified_size >
1975 {
1977 "Already received data of size %lu bigger than KX size %lu!\n",
1978 queue->unverified_size,
1980 GNUNET_break_op (0);
1982 return 0;
1983 }
1984
1985 type = ntohs (hdr->type);
1986 switch (type)
1987 {
1989 tca = (const struct TCPConfirmationAck *) queue->pread_buf;
1991 "start processing ack\n");
1992 if (sizeof(*tca) > queue->pread_off)
1993 {
1995 "Handling plaintext size of tca greater than pread offset.\n")
1996 ;
1997 return 0;
1998 }
1999 if (ntohs (hdr->size) != sizeof(*tca))
2000 {
2002 "Handling plaintext size does not match message type.\n");
2003 GNUNET_break_op (0);
2005 return 0;
2006 }
2007
2010
2011 thas.purpose.purpose = htonl (
2013 thas.purpose.size = htonl (sizeof(thas));
2014 thas.sender = tca->sender;
2015 thas.receiver = *my_identity;
2016 thas.monotonic_time = tca->monotonic_time;
2017 thas.challenge = tca->challenge;
2018
2021 &thas,
2022 &tca->sender_sig,
2023 &tca->sender.public_key))
2024 {
2026 "Verification of signature failed!\n");
2027 GNUNET_break (0);
2029 return 0;
2030 }
2031 if (0 != GNUNET_memcmp (&tca->challenge, &challenge))
2032 {
2034 "Challenge in TCPConfirmationAck not correct!\n");
2035 GNUNET_break (0);
2037 return 0;
2038 }
2039
2040 queue->handshake_ack_monotime_get = GNUNET_PEERSTORE_iteration_start (
2041 peerstore,
2042 "transport_tcp_communicator",
2043 &queue->target,
2046 queue);
2047
2049 "Handling plaintext, ack processed!\n");
2050
2052 {
2053 send_challenge (queue->challenge_received, queue);
2054 queue->write_task =
2056 queue->sock,
2057 &queue_write,
2058 queue);
2059 }
2060 else if (GNUNET_TRANSPORT_CS_OUTBOUND == queue->cs)
2061 {
2063 queue->address->sa_family, NULL);
2064 }
2065
2070 queue->initial_core_kx_done = GNUNET_YES;
2071
2072 {
2073 char *foreign_addr;
2074
2075 switch (queue->address->sa_family)
2076 {
2077 case AF_INET:
2078 GNUNET_asprintf (&foreign_addr,
2079 "%s-%s",
2081 GNUNET_a2s (queue->address, queue->address_len));
2082 break;
2083
2084 case AF_INET6:
2085 GNUNET_asprintf (&foreign_addr,
2086 "%s-%s",
2088 GNUNET_a2s (queue->address, queue->address_len));
2089 break;
2090
2091 default:
2092 GNUNET_assert (0);
2093 }
2095 &queue->target,
2096 foreign_addr,
2097 UINT16_MAX, /* no MTU */
2099 0, /* Priority */
2100 queue->nt,
2101 queue->cs,
2102 queue->mq);
2103
2104 GNUNET_free (foreign_addr);
2105 }
2106
2107 size = ntohs (hdr->size);
2108 break;
2110 /* Special case: header size excludes box itself! */
2111 box = (const struct TCPBox *) queue->pread_buf;
2112 if (ntohs (hdr->size) + sizeof(struct TCPBox) > queue->pread_off)
2113 return 0;
2114 calculate_hmac (&queue->in_hmac, &box[1], ntohs (hdr->size), &tmac);
2115 if (0 != memcmp (&tmac, &box->hmac, sizeof(tmac)))
2116 {
2117 GNUNET_break_op (0);
2119 return 0;
2120 }
2121 pass_plaintext_to_core (queue, (const void *) &box[1], ntohs (hdr->size));
2122 size = ntohs (hdr->size) + sizeof(*box);
2124 "Handling plaintext, box processed!\n");
2126 "# bytes decrypted with BOX",
2127 size,
2128 GNUNET_NO);
2130 "# messages decrypted with BOX",
2131 1,
2132 GNUNET_NO);
2133 break;
2134
2136 rekey = (const struct TCPRekey *) queue->pread_buf;
2137 if (sizeof(*rekey) > queue->pread_off)
2138 return 0;
2139 if (ntohs (hdr->size) != sizeof(*rekey))
2140 {
2141 GNUNET_break_op (0);
2143 return 0;
2144 }
2145 rekeyz = *rekey;
2146 memset (&rekeyz.hmac, 0, sizeof(rekeyz.hmac));
2147 calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
2148 if (0 != memcmp (&tmac, &rekey->hmac, sizeof(tmac)))
2149 {
2150 GNUNET_break_op (0);
2152 return 0;
2153 }
2154 do_rekey (queue, rekey);
2155 size = ntohs (hdr->size);
2157 "Handling plaintext, rekey processed!\n");
2159 "# rekeying successful",
2160 1,
2161 GNUNET_NO);
2162 break;
2163
2165 fin = (const struct TCPFinish *) queue->pread_buf;
2166 if (sizeof(*fin) > queue->pread_off)
2167 return 0;
2168 if (ntohs (hdr->size) != sizeof(*fin))
2169 {
2170 GNUNET_break_op (0);
2172 return 0;
2173 }
2174 finz = *fin;
2175 memset (&finz.hmac, 0, sizeof(finz.hmac));
2176 calculate_hmac (&queue->in_hmac, &finz, sizeof(finz), &tmac);
2177 if (0 != memcmp (&tmac, &fin->hmac, sizeof(tmac)))
2178 {
2179 GNUNET_break_op (0);
2181 return 0;
2182 }
2183 /* handle FINISH by destroying queue */
2186 "Handling plaintext, finish processed!\n");
2187 break;
2188
2189 default:
2191 "Handling plaintext, nothing processed!\n");
2192 GNUNET_break_op (0);
2194 return 0;
2195 }
2196 GNUNET_assert (0 != size);
2197 if (-1 != queue->unverified_size)
2198 queue->unverified_size += size;
2199 return size;
2200}
2201
2202
2208static void
2209queue_read (void *cls)
2210{
2211 struct Queue *queue = cls;
2212 struct GNUNET_TIME_Relative left;
2213 ssize_t rcvd;
2214
2215 queue->read_task = NULL;
2216 rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
2217 &queue->cread_buf[queue->cread_off],
2218 BUF_SIZE - queue->cread_off);
2220 "Received %zd bytes from TCP queue\n", rcvd);
2221 if (-1 == rcvd)
2222 {
2223 if ((EAGAIN != errno) && (EINTR != errno))
2224 {
2227 return;
2228 }
2229 /* try again */
2230 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
2231 if (0 != left.rel_value_us)
2232 {
2233 queue->read_task =
2235 return;
2236 }
2238 "Queue %p was idle for %s, disconnecting\n",
2239 queue,
2242 GNUNET_YES));
2244 return;
2245 }
2246 if (0 == rcvd)
2247 {
2248 /* Orderly shutdown of connection */
2250 "Socket for queue %p seems to have been closed\n", queue);
2252 return;
2253 }
2254 queue->timeout =
2256 queue->cread_off += rcvd;
2257 while ((queue->pread_off < sizeof(queue->pread_buf)) &&
2258 (queue->cread_off > 0))
2259 {
2260 size_t max = GNUNET_MIN (sizeof(queue->pread_buf) - queue->pread_off,
2261 queue->cread_off);
2262 size_t done;
2263 size_t total;
2264 size_t old_pread_off = queue->pread_off;
2265
2266 GNUNET_assert (0 ==
2267 gcry_cipher_decrypt (queue->in_cipher,
2268 &queue->pread_buf[queue->pread_off],
2269 max,
2270 queue->cread_buf,
2271 max));
2272 queue->pread_off += max;
2273 total = 0;
2274 while (0 != (done = try_handle_plaintext (queue)))
2275 {
2276 /* 'done' bytes of plaintext were used, shift buffer */
2277 GNUNET_assert (done <= queue->pread_off);
2278 /* NOTE: this memmove() could possibly sometimes be
2279 avoided if we pass 'total' into try_handle_plaintext()
2280 and use it at an offset into the buffer there! */
2281 memmove (queue->pread_buf,
2282 &queue->pread_buf[done],
2283 queue->pread_off - done);
2284 queue->pread_off -= done;
2285 total += done;
2286 /* The last plaintext was a rekey, abort for now */
2287 if (GNUNET_YES == queue->rekeyed)
2288 break;
2289 }
2290 /* when we encounter a rekey message, the decryption above uses the
2291 wrong key for everything after the rekey; in that case, we have
2292 to re-do the decryption at 'total' instead of at 'max'.
2293 However, we have to take into account that the plaintext buffer may have
2294 already contained data and not jumped too far ahead in the ciphertext.
2295 If there is no rekey and the last message is incomplete (max > total),
2296 it is safe to keep the decryption so we shift by 'max' */
2297 if (GNUNET_YES == queue->rekeyed)
2298 {
2299 max = total - old_pread_off;
2300 queue->rekeyed = GNUNET_NO;
2301 queue->pread_off = 0;
2302 }
2303 memmove (queue->cread_buf, &queue->cread_buf[max], queue->cread_off - max);
2304 queue->cread_off -= max;
2305 }
2306 if (BUF_SIZE == queue->cread_off)
2307 return; /* buffer full, suspend reading */
2308 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
2309 if (0 != left.rel_value_us)
2310 {
2311 if (max_queue_length > queue->backpressure)
2312 {
2313 /* continue reading */
2314 queue->read_task =
2316 }
2317 return;
2318 }
2320 "Queue %p was idle for %s, disconnecting\n",
2321 queue,
2324 GNUNET_YES));
2326}
2327
2328
2336static struct sockaddr *
2338 struct sockaddr_in6 v6,
2339 unsigned int port)
2340{
2341 struct sockaddr *in;
2342
2343 v6.sin6_family = AF_INET6;
2344 v6.sin6_port = htons ((uint16_t) port);
2345#if HAVE_SOCKADDR_IN_SIN_LEN
2346 v6.sin6_len = sizeof(struct sockaddr_in6);
2347#endif
2348 v6.sin6_flowinfo = 0;
2349 v6.sin6_scope_id = 0;
2350 in = GNUNET_memdup (&v6, sizeof(v6));
2351 *sock_len = sizeof(struct sockaddr_in6);
2352
2353 return in;
2354}
2355
2356
2364static struct sockaddr *
2366 struct sockaddr_in v4,
2367 unsigned int port)
2368{
2369 struct sockaddr *in;
2370
2371 v4.sin_family = AF_INET;
2372 v4.sin_port = htons ((uint16_t) port);
2373#if HAVE_SOCKADDR_IN_SIN_LEN
2374 v4.sin_len = sizeof(struct sockaddr_in);
2375#endif
2376 in = GNUNET_memdup (&v4, sizeof(v4));
2377 *sock_len = sizeof(struct sockaddr_in);
2378 return in;
2379}
2380
2381
2388static struct PortOnlyIpv4Ipv6 *
2389tcp_address_to_sockaddr_port_only (const char *bindto, unsigned int *port)
2390{
2391 struct PortOnlyIpv4Ipv6 *po;
2392 struct sockaddr_in *i4;
2393 struct sockaddr_in6 *i6;
2394 socklen_t sock_len_ipv4;
2395 socklen_t sock_len_ipv6;
2396
2397 /* interpreting value as just a PORT number */
2398 if (*port > UINT16_MAX)
2399 {
2401 "BINDTO specification `%s' invalid: value too large for port\n",
2402 bindto);
2403 return NULL;
2404 }
2405
2406 po = GNUNET_new (struct PortOnlyIpv4Ipv6);
2407
2408 if (GNUNET_YES == disable_v6)
2409 {
2410 i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
2411 po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
2412 *port);
2413 po->addr_len_ipv4 = sock_len_ipv4;
2414 }
2415 else
2416 {
2417
2418 i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
2419 po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
2420 *port);
2421 po->addr_len_ipv4 = sock_len_ipv4;
2422
2423 i6 = GNUNET_malloc (sizeof(struct sockaddr_in6));
2424 po->addr_ipv6 = tcp_address_to_sockaddr_numeric_v6 (&sock_len_ipv6, *i6,
2425 *port);
2426
2427 po->addr_len_ipv6 = sock_len_ipv6;
2428
2429 GNUNET_free (i6);
2430 }
2431
2432 GNUNET_free (i4);
2433
2434 return po;
2435}
2436
2437
2444static char *
2445extract_address (const char *bindto)
2446{
2447 char *addr;
2448 char *start;
2449 char *token;
2450 char *cp;
2451 char *rest = NULL;
2452
2454 "extract address with bindto %s\n",
2455 bindto);
2456
2457 if (NULL == bindto)
2459 "bindto is NULL\n");
2460
2461 cp = GNUNET_strdup (bindto);
2462
2464 "extract address 2\n");
2465
2466 start = cp;
2467 if (('[' == *cp) && (']' == cp[strlen (cp) - 1]))
2468 {
2469 start++; /* skip over '['*/
2470 cp[strlen (cp) - 1] = '\0'; /* eat ']'*/
2471 addr = GNUNET_strdup (start);
2472 }
2473 else
2474 {
2475 token = strtok_r (cp, "]", &rest);
2476 if (strlen (bindto) == strlen (token))
2477 {
2478 token = strtok_r (cp, ":", &rest);
2479 addr = GNUNET_strdup (token);
2480 }
2481 else
2482 {
2483 token++;
2484 addr = GNUNET_strdup (token);
2485 }
2486 }
2487
2489 "tcp address: %s\n",
2490 addr);
2491 GNUNET_free (cp);
2492 return addr;
2493}
2494
2495
2502static unsigned int
2503extract_port (const char *addr_and_port)
2504{
2505 unsigned int port;
2506 char dummy[2];
2507 char *token;
2508 char *addr;
2509 char *colon;
2510 char *cp;
2511 char *rest = NULL;
2512
2513 if (NULL != addr_and_port)
2514 {
2515 cp = GNUNET_strdup (addr_and_port);
2516 token = strtok_r (cp, "]", &rest);
2517 if (strlen (addr_and_port) == strlen (token))
2518 {
2519 colon = strrchr (cp, ':');
2520 if (NULL == colon)
2521 {
2522 GNUNET_free (cp);
2523 return 0;
2524 }
2525 addr = colon;
2526 addr++;
2527 }
2528 else
2529 {
2530 token = strtok_r (NULL, "]", &rest);
2531 if (NULL == token)
2532 {
2533 GNUNET_free (cp);
2534 return 0;
2535 }
2536 else
2537 {
2538 addr = token;
2539 addr++;
2540 }
2541 }
2542
2543
2544 if (1 == sscanf (addr, "%u%1s", &port, dummy))
2545 {
2546 /* interpreting value as just a PORT number */
2547 if (port > UINT16_MAX)
2548 {
2550 "Port `%u' invalid: value too large for port\n",
2551 port);
2552 GNUNET_free (cp);
2553 return 0;
2554 }
2555 }
2556 else
2557 {
2559 "BINDTO specification invalid: last ':' not followed by number\n");
2560 GNUNET_free (cp);
2561 return 0;
2562 }
2563 GNUNET_free (cp);
2564 }
2565 else
2566 {
2568 "return 0\n");
2569 /* interpret missing port as 0, aka pick any free one */
2570 port = 0;
2571 }
2572
2573 return port;
2574}
2575
2576
2584static struct sockaddr *
2585tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
2586{
2587 struct sockaddr *in;
2588 unsigned int port;
2589 struct sockaddr_in v4;
2590 struct sockaddr_in6 v6;
2591 char *start;
2592
2593 memset (&v4, 0, sizeof(v4));
2594 start = extract_address (bindto);
2595 GNUNET_assert (NULL != start);
2597 "start %s\n",
2598 start);
2599
2601 "!bindto %s\n",
2602 bindto);
2603
2604
2605 if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
2606 {
2607 port = extract_port (bindto);
2608
2610 "port %u\n",
2611 port);
2612
2613 in = tcp_address_to_sockaddr_numeric_v4 (sock_len, v4, port);
2614 }
2615 else if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
2616 {
2617 port = extract_port (bindto);
2618 in = tcp_address_to_sockaddr_numeric_v6 (sock_len, v6, port);
2619 }
2620 else
2621 {
2622 GNUNET_assert (0);
2623 }
2624
2626 return in;
2627}
2628
2629
2638static void
2640 const struct GNUNET_MessageHeader *msg,
2641 void *impl_state)
2642{
2643 struct Queue *queue = impl_state;
2644 uint16_t msize = ntohs (msg->size);
2645 struct TCPBox box;
2647 "In MQ send. Queue finishing: %s; write task running: %s\n",
2648 (GNUNET_YES == queue->finishing) ? "yes" : "no",
2649 (NULL == queue->write_task) ? "yes" : "no");
2650 GNUNET_assert (mq == queue->mq);
2651 queue->mq_awaits_continue = GNUNET_YES;
2652 if (GNUNET_YES == queue->finishing)
2653 return; /* this queue is dying, drop msg */
2654 GNUNET_assert (0 == queue->pwrite_off);
2656 box.header.size = htons (msize);
2657 calculate_hmac (&queue->out_hmac, msg, msize, &box.hmac);
2658 memcpy (&queue->pwrite_buf[queue->pwrite_off], &box, sizeof(box));
2659 queue->pwrite_off += sizeof(box);
2660 memcpy (&queue->pwrite_buf[queue->pwrite_off], msg, msize);
2661 queue->pwrite_off += msize;
2663 "%lu bytes of plaintext to send\n", queue->pwrite_off);
2664 GNUNET_assert (NULL != queue->sock);
2665 if (NULL == queue->write_task)
2666 queue->write_task =
2668 queue->sock,
2669 &queue_write,
2670 queue);
2671}
2672
2673
2682static void
2683mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state)
2684{
2685 struct Queue *queue = impl_state;
2686
2687 if (mq == queue->mq)
2688 {
2689 queue->mq = NULL;
2691 }
2692}
2693
2694
2701static void
2702mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
2703{
2704 struct Queue *queue = impl_state;
2705
2706 GNUNET_assert (0 != queue->pwrite_off);
2707 queue->pwrite_off = 0;
2708}
2709
2710
2720static void
2721mq_error (void *cls, enum GNUNET_MQ_Error error)
2722{
2723 struct Queue *queue = cls;
2724
2726 "MQ error in queue to %s: %d\n",
2727 GNUNET_i2s (&queue->target),
2728 (int) error);
2730}
2731
2732
2740static void
2742{
2743 queue->nt =
2744 GNUNET_NT_scanner_get_type (is, queue->address, queue->address_len);
2746 queue_map,
2747 &queue->key,
2748 queue,
2751 "# queues active",
2753 GNUNET_NO);
2754 queue->timeout =
2757 &mq_destroy,
2758 &mq_cancel,
2759 queue,
2760 NULL,
2761 &mq_error,
2762 queue);
2763}
2764
2765
2776static void
2778 const struct GNUNET_CRYPTO_HpkeEncapsulation *c)
2779{
2780 const struct GNUNET_PeerIdentity *my_identity;
2782 struct TcpHandshakeSignature ths;
2783 struct TCPConfirmation tc;
2784
2788
2789 memcpy (queue->cwrite_buf, c, sizeof(*c));
2790 queue->cwrite_off = sizeof(*c);
2791 /* compute 'tc' and append in encrypted format to cwrite_buf */
2792 tc.sender = *my_identity;
2793 tc.monotonic_time =
2795 GNUNET_CRYPTO_random_block (&tc.challenge,
2796 sizeof(tc.challenge));
2797 ths.purpose.purpose = htonl (
2799 ths.purpose.size = htonl (sizeof(ths));
2800 ths.sender = *my_identity;
2801 ths.receiver = queue->target;
2802 ths.ephemeral = *c;
2803 ths.monotonic_time = tc.monotonic_time;
2804 ths.challenge = tc.challenge;
2806 &ths,
2807 &tc.sender_sig);
2808 GNUNET_assert (0 ==
2809 gcry_cipher_encrypt (queue->out_cipher,
2810 &queue->cwrite_buf[queue->cwrite_off],
2811 sizeof(tc),
2812 &tc,
2813 sizeof(tc)));
2814 queue->challenge = tc.challenge;
2815 queue->cwrite_off += sizeof(tc);
2816
2818 "handshake written\n");
2819}
2820
2821
2829static void
2831{
2833 struct GNUNET_ShortHashCode k;
2834
2836 &c, &k);
2837 setup_out_cipher (queue, &k);
2838 transmit_kx (queue, &c);
2839}
2840
2841
2847static void
2848handshake_monotime_store_cb (void *cls, int success)
2849{
2850 struct Queue *queue = cls;
2851 if (GNUNET_OK != success)
2852 {
2854 "Failed to store handshake monotonic time in PEERSTORE!\n");
2855 }
2856 queue->handshake_monotime_sc = NULL;
2857 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
2858}
2859
2860
2868static void
2870 const struct GNUNET_PEERSTORE_Record *record,
2871 const char *emsg)
2872{
2873 struct Queue *queue = cls;
2874 struct GNUNET_TIME_AbsoluteNBO *mtbe;
2875 struct GNUNET_TIME_Absolute mt;
2876 const struct GNUNET_PeerIdentity *pid;
2877 struct GNUNET_TIME_AbsoluteNBO *handshake_monotonic_time;
2878
2879 (void) emsg;
2880
2881 handshake_monotonic_time = &queue->handshake_monotonic_time;
2882 pid = &queue->target;
2884 "tcp handshake with us %s\n",
2886 if (NULL == record)
2887 {
2888 queue->handshake_monotime_get = NULL;
2889 return;
2890 }
2892 "tcp handshake from peer %s\n",
2893 GNUNET_i2s (pid));
2894 if (sizeof(*mtbe) != record->value_size)
2895 {
2896 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
2897 GNUNET_break (0);
2898 return;
2899 }
2900 mtbe = record->value;
2901 mt = GNUNET_TIME_absolute_ntoh (*mtbe);
2903 queue->handshake_monotonic_time).abs_value_us)
2904 {
2906 "Queue from %s dropped, handshake monotime in the past\n",
2907 GNUNET_i2s (&queue->target));
2908 GNUNET_break (0);
2909 GNUNET_PEERSTORE_iteration_stop (queue->handshake_ack_monotime_get);
2910 queue->handshake_ack_monotime_get = NULL;
2912 return;
2913 }
2914 queue->handshake_monotime_sc = GNUNET_PEERSTORE_store (peerstore,
2915 "transport_tcp_communicator",
2916 pid,
2918 handshake_monotonic_time,
2919 sizeof(*
2920 handshake_monotonic_time),
2923 &
2925 queue);
2926}
2927
2928
2940static int
2942 struct TCPConfirmation *tc,
2943 char *ibuf)
2944{
2945 const struct GNUNET_PeerIdentity *my_identity;
2946 struct TcpHandshakeSignature ths;
2948
2951
2953 0 ==
2954 gcry_cipher_decrypt (queue->in_cipher,
2955 tc,
2956 sizeof(*tc),
2957 &ibuf[sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)],
2958 sizeof(*tc)));
2959 ths.purpose.purpose = htonl (
2961 ths.purpose.size = htonl (sizeof(ths));
2962 ths.sender = tc->sender;
2963 ths.receiver = *my_identity;
2964 memcpy (&ths.ephemeral, ibuf, sizeof(struct GNUNET_CRYPTO_EcdhePublicKey));
2965 ths.monotonic_time = tc->monotonic_time;
2966 ths.challenge = tc->challenge;
2969 &ths,
2970 &tc->sender_sig,
2971 &tc->sender.public_key);
2972 if (GNUNET_YES == ret)
2973 queue->handshake_monotime_get =
2975 "transport_tcp_communicator",
2976 &queue->target,
2979 queue);
2980 return ret;
2981}
2982
2983
2991static void
2992queue_read_kx (void *cls)
2993{
2994 struct Queue *queue = cls;
2995 ssize_t rcvd;
2996 struct GNUNET_TIME_Relative left;
2997 struct TCPConfirmation tc;
2998
2999 queue->read_task = NULL;
3000 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
3001 if (0 == left.rel_value_us)
3002 {
3004 return;
3005 }
3006 rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
3007 &queue->cread_buf[queue->cread_off],
3008 BUF_SIZE - queue->cread_off);
3010 "Received %lu bytes to write in buffer of size %lu for KX from queue %p (expires in %"
3011 PRIu64 ")\n",
3012 rcvd, BUF_SIZE - queue->cread_off, queue, left.rel_value_us);
3013 if (-1 == rcvd)
3014 {
3015 if ((EAGAIN != errno) && (EINTR != errno))
3016 {
3019 return;
3020 }
3021 queue->read_task =
3023 return;
3024 }
3025 if (0 == rcvd)
3026 {
3027 /* Orderly shutdown of connection */
3029 "Socket for queue %p seems to have been closed\n", queue);
3031 return;
3032 }
3033 queue->cread_off += rcvd;
3034 if (queue->cread_off < INITIAL_KX_SIZE)
3035 {
3036 /* read more */
3038 "%lu/%lu bytes of KX read. Rescheduling...\n",
3039 queue->cread_off, INITIAL_KX_SIZE);
3040 queue->read_task =
3042 return;
3043 }
3044 /* we got all the data, let's find out who we are talking to! */
3046 (const struct GNUNET_CRYPTO_HpkeEncapsulation*)
3047 queue->cread_buf,
3048 queue);
3049 if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, queue->cread_buf))
3050 {
3052 "Invalid TCP KX received from %s\n",
3053 GNUNET_a2s (queue->address, queue->address_len));
3055 return;
3056 }
3057 if (0 !=
3058 memcmp (&tc.sender, &queue->target, sizeof(struct GNUNET_PeerIdentity)))
3059 {
3061 "Invalid sender in TCP KX received from %s\n",
3062 GNUNET_a2s (queue->address, queue->address_len));
3064 return;
3065 }
3066 send_challenge (tc.challenge, queue);
3067 queue->write_task =
3069 queue->sock,
3070 &queue_write,
3071 queue);
3072
3073 /* update queue timeout */
3074 queue->timeout =
3076 /* prepare to continue with regular read task immediately */
3077 memmove (queue->cread_buf,
3078 &queue->cread_buf[INITIAL_KX_SIZE],
3079 queue->cread_off - (INITIAL_KX_SIZE));
3081 "cread_off is %lu bytes before adjusting\n",
3082 queue->cread_off);
3083 queue->cread_off -= INITIAL_KX_SIZE;
3085 "cread_off set to %lu bytes\n",
3086 queue->cread_off);
3088}
3089
3090
3097static void
3098proto_read_kx (void *cls)
3099{
3100 struct ProtoQueue *pq = cls;
3101 ssize_t rcvd;
3102 struct GNUNET_TIME_Relative left;
3103 struct Queue *queue;
3104 struct TCPConfirmation tc;
3106
3107 pq->read_task = NULL;
3109 if (0 == left.rel_value_us)
3110 {
3111 free_proto_queue (pq);
3112 return;
3113 }
3114 rcvd = GNUNET_NETWORK_socket_recv (pq->sock,
3115 &pq->ibuf[pq->ibuf_off],
3116 sizeof(pq->ibuf) - pq->ibuf_off);
3118 "Proto received %lu bytes for KX\n", rcvd);
3119 if (-1 == rcvd)
3120 {
3121 if ((EAGAIN != errno) && (EINTR != errno))
3122 {
3124 free_proto_queue (pq);
3125 return;
3126 }
3127 /* try again */
3128 pq->read_task =
3130 return;
3131 }
3132 if (0 == rcvd)
3133 {
3134 /* Orderly shutdown of connection */
3136 "Socket for proto queue %p seems to have been closed\n", pq);
3137 free_proto_queue (pq);
3138 return;
3139 }
3140 pq->ibuf_off += rcvd;
3141 if (sizeof (struct TCPNATProbeMessage) == pq->ibuf_off)
3142 {
3143 struct TCPNATProbeMessage *pm = (struct TCPNATProbeMessage *) pq->ibuf;
3144
3146 &pm->clientIdentity);
3147
3148 queue = GNUNET_new (struct Queue);
3149 queue->target = pm->clientIdentity;
3150 eddsa_pub_to_hpke_key (&queue->target.public_key,
3151 &queue->target_hpke_key);
3154 }
3155 else if (pq->ibuf_off > sizeof(pq->ibuf))
3156 {
3157 /* read more */
3158 pq->read_task =
3160 return;
3161 }
3162 else
3163 {
3164 /* we got all the data, let's find out who we are talking to! */
3165 queue = GNUNET_new (struct Queue);
3167 (const struct GNUNET_CRYPTO_HpkeEncapsulation *) pq->
3168 ibuf,
3169 queue);
3170 if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, pq->ibuf))
3171 {
3173 "Invalid TCP KX received from %s\n",
3174 GNUNET_a2s (pq->address, pq->address_len));
3175 gcry_cipher_close (queue->in_cipher);
3177 free_proto_queue (pq);
3178 return;
3179 }
3180 queue->target = tc.sender;
3181 eddsa_pub_to_hpke_key (&queue->target.public_key,
3182 &queue->target_hpke_key);
3185 }
3186 queue->address = pq->address; /* steals reference */
3187 queue->address_len = pq->address_len;
3188 queue->listen_sock = pq->listen_sock;
3189 queue->sock = pq->sock;
3190
3192 "created queue with target %s\n",
3193 GNUNET_i2s (&queue->target));
3194
3196 "start kx proto\n");
3197
3199 boot_queue (queue);
3200 queue->read_task =
3202 queue->sock,
3203 read_task,
3204 queue);
3205 queue->write_task =
3207 queue->sock,
3208 &queue_write,
3209 queue);
3210 // TODO To early! Move it somewhere else.
3211 // send_challenge (tc.challenge, queue);
3212 queue->challenge_received = tc.challenge;
3213
3215 GNUNET_free (pq);
3216}
3217
3218
3219static struct ProtoQueue *
3221 struct sockaddr *in,
3222 socklen_t addrlen)
3223{
3224 struct ProtoQueue *pq = GNUNET_new (struct ProtoQueue);
3225
3226 if (NULL == sock)
3227 {
3228 // sock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET, addr, addrlen);
3229 sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, 0);
3230 if (NULL == sock)
3231 {
3233 "socket(%d) failed: %s",
3234 in->sa_family,
3235 strerror (errno));
3236 GNUNET_free (in);
3237 GNUNET_free (pq);
3238 return NULL;
3239 }
3240 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, addrlen)) &&
3241 (errno != EINPROGRESS))
3242 {
3244 "connect to `%s' failed: %s",
3245 GNUNET_a2s (in, addrlen),
3246 strerror (errno));
3248 GNUNET_free (in);
3249 GNUNET_free (pq);
3250 return NULL;
3251 }
3252 }
3253 pq->address_len = addrlen;
3254 pq->address = in;
3256 pq->sock = sock;
3258 pq->sock,
3260 pq);
3262
3263 return pq;
3264}
3265
3266
3274static void
3275listen_cb (void *cls)
3276{
3277 struct sockaddr_storage in;
3278 socklen_t addrlen;
3279 struct GNUNET_NETWORK_Handle *sock;
3280 struct ListenTask *lt;
3281 struct sockaddr *in_addr;
3282
3284 "listen_cb\n");
3285
3286 lt = cls;
3287
3288 lt->listen_task = NULL;
3289 GNUNET_assert (NULL != lt->listen_sock);
3290 addrlen = sizeof(in);
3291 memset (&in, 0, sizeof(in));
3293 (struct sockaddr*) &in,
3294 &addrlen);
3295 if ((NULL == sock) && ((EMFILE == errno) || (ENFILE == errno)))
3296 return; /* system limit reached, wait until connection goes down */
3298 lt->listen_sock,
3299 &listen_cb,
3300 lt);
3301 if ((NULL == sock) && ((EAGAIN == errno) || (ENOBUFS == errno)))
3302 return;
3303 if (NULL == sock)
3304 {
3306 return;
3307 }
3308 in_addr = GNUNET_memdup (&in, addrlen);
3309 create_proto_queue (sock, in_addr, addrlen);
3310}
3311
3312
3313static void
3315 const struct sockaddr *addr,
3316 socklen_t addrlen)
3317{
3318 const struct GNUNET_PeerIdentity *my_identity;
3319 struct TCPNATProbeMessage pm;
3320 struct ProtoQueue *pq;
3321 struct sockaddr *in_addr;
3322 (void) cls;
3323
3326
3328 "addr->sa_family %d\n",
3329 addr->sa_family);
3331 "Try to connect back\n");
3332 in_addr = GNUNET_memdup (addr, addrlen);
3334 "in_addr->sa_family %d\n",
3335 in_addr->sa_family);
3336 pq = create_proto_queue (NULL, in_addr, addrlen);
3337 if (NULL != pq)
3338 {
3339 pm.header.size = htons (sizeof(struct TCPNATProbeMessage));
3340 pm.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE);
3341 pm.clientIdentity = *my_identity;
3342 memcpy (pq->write_buf, &pm, sizeof(struct TCPNATProbeMessage));
3343 pq->write_off = sizeof(struct TCPNATProbeMessage);
3345 pq->sock,
3347 pq);
3348 }
3349 else
3350 {
3352 "Couldn't create ProtoQueue for sending TCPNATProbeMessage\n");
3353 }
3354}
3355
3356
3357static void
3359{
3360 struct sockaddr *in = cls;
3361 struct PendingReversal *pending_reversal;
3362 struct GNUNET_HashCode key;
3363
3365 sizeof(struct sockaddr),
3366 &key);
3368 &key);
3369
3370 GNUNET_assert (NULL != pending_reversal);
3371
3373 &key,
3374 pending_reversal))
3376 "No pending reversal found for address %s\n",
3377 GNUNET_a2s (in, sizeof (struct sockaddr)));
3378 GNUNET_free (pending_reversal->in);
3379 GNUNET_free (pending_reversal);
3380}
3381
3382
3401static int
3402mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
3403{
3404 struct sockaddr *in;
3405 socklen_t in_len = 0;
3406 const char *path;
3407 struct sockaddr_in *v4;
3408 struct sockaddr_in6 *v6;
3409 unsigned int is_natd = GNUNET_NO;
3410 struct GNUNET_HashCode key;
3411 struct GNUNET_HashCode queue_map_key;
3412 struct GNUNET_HashContext *hsh;
3413 struct Queue *queue;
3414
3416 "Connecting to %s at %s\n",
3417 GNUNET_i2s (peer),
3418 address);
3419 if (0 != strncmp (address,
3421 strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
3422 {
3423 GNUNET_break_op (0);
3424 return GNUNET_SYSERR;
3425 }
3426 path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
3427 in = tcp_address_to_sockaddr (path, &in_len);
3428
3429 if (NULL == in)
3430 {
3432 "Failed to setup TCP socket address\n");
3433 return GNUNET_SYSERR;
3434 }
3435
3437 "in %s\n",
3438 GNUNET_a2s (in, in_len));
3439
3442 GNUNET_CRYPTO_hash_context_read (hsh, peer, sizeof (*peer));
3443 GNUNET_CRYPTO_hash_context_finish (hsh, &queue_map_key);
3445
3446 if (NULL != queue)
3447 {
3449 "Queue for %s already exists or is in construction\n", address);
3450 GNUNET_free (in);
3451 return GNUNET_NO;
3452 }
3453 switch (in->sa_family)
3454 {
3455 case AF_INET:
3456 v4 = (struct sockaddr_in *) in;
3457 if (0 == v4->sin_port)
3458 {
3459 is_natd = GNUNET_YES;
3461 sizeof(struct sockaddr),
3462 &key);
3465 &key))
3466 {
3468 "There is already a request reversal for `%s'at `%s'\n",
3469 GNUNET_i2s (peer),
3470 address);
3471 GNUNET_free (in);
3472 return GNUNET_SYSERR;
3473 }
3474 }
3475 break;
3476
3477 case AF_INET6:
3478 if (GNUNET_YES == disable_v6)
3479 {
3481 "IPv6 disabled, skipping %s\n", address);
3482 GNUNET_free (in);
3483 return GNUNET_SYSERR;
3484 }
3485 v6 = (struct sockaddr_in6 *) in;
3486 if (0 == v6->sin6_port)
3487 {
3489 "Request reversal for `%s' at `%s' not possible for an IPv6 address\n",
3490 GNUNET_i2s (peer),
3491 address);
3492 GNUNET_free (in);
3493 return GNUNET_SYSERR;
3494 }
3495 break;
3496
3497 default:
3498 GNUNET_assert (0);
3499 }
3500
3501 if (GNUNET_YES == is_natd)
3502 {
3503 struct sockaddr_in local_sa;
3504 struct PendingReversal *pending_reversal;
3505
3506 memset (&local_sa, 0, sizeof(local_sa));
3507 local_sa.sin_family = AF_INET;
3508 local_sa.sin_port = htons (bind_port);
3509 /* We leave sin_address at 0, let the kernel figure it out,
3510 even if our bind() is more specific. (May want to reconsider
3511 later.) */
3512 if (GNUNET_OK != GNUNET_NAT_request_reversal (nat, &local_sa, v4))
3513 {
3515 "request reversal for `%s' at `%s' failed\n",
3516 GNUNET_i2s (peer),
3517 address);
3518 GNUNET_free (in);
3519 return GNUNET_SYSERR;
3520 }
3521 pending_reversal = GNUNET_new (struct PendingReversal);
3522 pending_reversal->in = in;
3525 &key,
3526 pending_reversal,
3528 pending_reversal->target = *peer;
3530 &
3532 in);
3534 "Created NAT WAIT connection to `%s' at `%s'\n",
3535 GNUNET_i2s (peer),
3536 GNUNET_a2s (in, sizeof (struct sockaddr)));
3537 }
3538 else
3539 {
3540 struct GNUNET_NETWORK_Handle *sock;
3541
3542 sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM,
3543 IPPROTO_TCP);
3544 if (NULL == sock)
3545 {
3547 "socket(%d) failed: %s",
3548 in->sa_family,
3549 strerror (errno));
3550 GNUNET_free (in);
3551 return GNUNET_SYSERR;
3552 }
3553 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, in_len)) &&
3554 (errno != EINPROGRESS))
3555 {
3557 "connect to `%s' failed: %s",
3558 address,
3559 strerror (errno));
3561 GNUNET_free (in);
3562 return GNUNET_SYSERR;
3563 }
3564
3565 queue = GNUNET_new (struct Queue);
3566 queue->target = *peer;
3567 eddsa_pub_to_hpke_key (&queue->target.public_key, &queue->target_hpke_key);
3568 queue->key = queue_map_key;
3569 queue->address = in;
3570 queue->address_len = in_len;
3571 queue->sock = sock;
3573 boot_queue (queue);
3575 "booted queue with target %s\n",
3576 GNUNET_i2s (&queue->target));
3577 // queue->mq_awaits_continue = GNUNET_YES;
3578 queue->read_task =
3580 queue->sock,
3582 queue);
3583
3584
3586 "start kx mq_init\n");
3587
3589 queue->write_task =
3591 queue->sock,
3592 &queue_write,
3593 queue);
3594 }
3595
3596 return GNUNET_OK;
3597}
3598
3599
3608static int
3610 const struct GNUNET_HashCode *key,
3611 void *value)
3612{
3613 struct ListenTask *lt = value;
3614
3615 (void) cls;
3616 (void) key;
3617 if (NULL != lt->listen_task)
3618 {
3620 lt->listen_task = NULL;
3621 }
3622 if (NULL != lt->listen_sock)
3623 {
3625 lt->listen_sock = NULL;
3626 }
3627 GNUNET_free (lt);
3628 return GNUNET_OK;
3629}
3630
3631
3640static int
3642 const struct GNUNET_HashCode *target,
3643 void *value)
3644{
3645 struct Queue *queue = value;
3646
3647 (void) cls;
3648 (void) target;
3650 return GNUNET_OK;
3651}
3652
3653
3659static void
3660do_shutdown (void *cls)
3661{
3663 "Shutdown %s!\n",
3664 shutdown_running ? "running" : "not running");
3665
3667 return;
3668 else
3670
3671 while (NULL != proto_head)
3673 if (NULL != nat)
3674 {
3676 nat = NULL;
3677 }
3685 if (NULL != ch)
3686 {
3689 ch = NULL;
3690 }
3691 if (NULL != stats)
3692 {
3694 stats = NULL;
3695 }
3696 if (NULL != is)
3697 {
3699 is = NULL;
3700 }
3701 if (NULL != pils)
3702 {
3704 pils = NULL;
3705 }
3706 if (NULL != key_ring)
3707 {
3709 key_ring = NULL;
3710 }
3711 if (NULL != peerstore)
3712 {
3714 peerstore = NULL;
3715 }
3716 if (NULL != resolve_request_handle)
3717 {
3720 }
3722 "Shutdown done!\n");
3723}
3724
3725
3737static void
3738enc_notify_cb (void *cls,
3739 const struct GNUNET_PeerIdentity *sender,
3740 const struct GNUNET_MessageHeader *msg)
3741{
3742 (void) cls;
3743 (void) sender;
3744 (void) msg;
3745 GNUNET_break_op (0);
3746}
3747
3748
3762static void
3764 void **app_ctx,
3765 int add_remove,
3767 const struct sockaddr *addr,
3768 socklen_t addrlen)
3769{
3770 char *my_addr;
3772
3774 "nat address cb %s %s\n",
3775 add_remove ? "add" : "remove",
3776 GNUNET_a2s (addr, addrlen));
3777
3778 if (GNUNET_YES == add_remove)
3779 {
3781
3782 GNUNET_asprintf (&my_addr,
3783 "%s-%s",
3785 GNUNET_a2s (addr, addrlen));
3786 nt = GNUNET_NT_scanner_get_type (is, addr, addrlen);
3787 ai =
3789 my_addr,
3790 nt,
3792 GNUNET_free (my_addr);
3793 *app_ctx = ai;
3794 }
3795 else
3796 {
3797 ai = *app_ctx;
3799 *app_ctx = NULL;
3800 }
3801}
3802
3803
3807static void
3808add_addr (struct sockaddr *in, socklen_t in_len)
3809{
3810
3811 struct Addresses *saddrs;
3812
3814 "add address %s\n",
3815 GNUNET_a2s (in, in_len));
3816
3817 saddrs = GNUNET_new (struct Addresses);
3818 saddrs->addr = in;
3819 saddrs->addr_len = in_len;
3821
3823 "after add address %s\n",
3824 GNUNET_a2s (in, in_len));
3825
3827 "add address %s\n",
3828 GNUNET_a2s (saddrs->addr, saddrs->addr_len));
3829
3830 addrs_lens++;
3831}
3832
3833
3841static int
3842init_socket (struct sockaddr *addr,
3843 socklen_t in_len)
3844{
3845 struct sockaddr_storage in_sto;
3846 socklen_t sto_len;
3847 struct GNUNET_NETWORK_Handle *listen_sock;
3848 struct ListenTask *lt;
3849 int sockfd;
3850 struct GNUNET_HashCode h_sock;
3851
3852 if (NULL == addr)
3853 {
3855 "Address is NULL.\n");
3856 return GNUNET_SYSERR;
3857 }
3858
3860 "address %s\n",
3861 GNUNET_a2s (addr, in_len));
3862
3863 listen_sock =
3864 GNUNET_NETWORK_socket_create (addr->sa_family, SOCK_STREAM, IPPROTO_TCP);
3865 if (NULL == listen_sock)
3866 {
3868 return GNUNET_SYSERR;
3869 }
3870
3871 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (listen_sock, addr, in_len))
3872 {
3874 GNUNET_NETWORK_socket_close (listen_sock);
3875 listen_sock = NULL;
3876 return GNUNET_SYSERR;
3877 }
3878
3879 if (GNUNET_OK !=
3880 GNUNET_NETWORK_socket_listen (listen_sock,
3881 5))
3882 {
3884 "listen");
3885 GNUNET_NETWORK_socket_close (listen_sock);
3886 listen_sock = NULL;
3887 return GNUNET_SYSERR;
3888 }
3889
3890 /* We might have bound to port 0, allowing the OS to figure it out;
3891 thus, get the real IN-address from the socket */
3892 sto_len = sizeof(in_sto);
3893
3894 if (0 != getsockname (GNUNET_NETWORK_get_fd (listen_sock),
3895 (struct sockaddr *) &in_sto,
3896 &sto_len))
3897 {
3898 memcpy (&in_sto, addr, in_len);
3899 sto_len = in_len;
3900 }
3901
3902 // addr = (struct sockaddr *) &in_sto;
3903 in_len = sto_len;
3905 "Bound to `%s'\n",
3906 GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len));
3907 if (NULL == stats)
3908 stats = GNUNET_STATISTICS_create ("communicator-tcp", cfg);
3909
3910 if (NULL == is)
3912
3913 /* start listening */
3914
3915 lt = GNUNET_new (struct ListenTask);
3916 lt->listen_sock = listen_sock;
3917
3919 listen_sock,
3920 &listen_cb,
3921 lt);
3922
3924 "creating hash\n");
3925 sockfd = GNUNET_NETWORK_get_fd (lt->listen_sock);
3926 GNUNET_CRYPTO_hash (&sockfd,
3927 sizeof(int),
3928 &h_sock);
3929
3931 "creating map\n");
3932 if (NULL == lt_map)
3934
3936 "creating map entry\n");
3939 &h_sock,
3940 lt,
3942
3944 "map entry created\n");
3945
3946 if (NULL == queue_map)
3948
3949 if (NULL == ch)
3954 &mq_init,
3955 NULL,
3957 NULL,
3958 NULL);
3959
3960 if (NULL == ch)
3961 {
3962 GNUNET_break (0);
3963 if (NULL != resolve_request_handle)
3966 return GNUNET_SYSERR;
3967 }
3968
3969 add_addr (addr, in_len);
3970 return GNUNET_OK;
3971
3972}
3973
3974
3978static void
3980{
3981 struct sockaddr **saddrs;
3982 socklen_t *saddr_lens;
3983 int i;
3984 size_t len;
3985
3987 "starting nat register!\n");
3988 len = 0;
3989 i = 0;
3990 saddrs = GNUNET_malloc ((addrs_lens) * sizeof(struct sockaddr *));
3991 saddr_lens = GNUNET_malloc ((addrs_lens) * sizeof(socklen_t));
3992 for (struct Addresses *pos = addrs_head; NULL != pos; pos = pos->next)
3993 {
3995 "registering address %s\n",
3996 GNUNET_a2s (pos->addr, pos->addr_len));
3997
3998 saddr_lens[i] = pos->addr_len;
3999 len += saddr_lens[i];
4000 saddrs[i] = GNUNET_memdup (pos->addr, saddr_lens[i]);
4001 i++;
4002 }
4003
4005 "registering addresses %lu %lu %lu %lu\n",
4006 (addrs_lens) * sizeof(struct sockaddr *),
4007 (addrs_lens) * sizeof(socklen_t),
4008 len,
4012 IPPROTO_TCP,
4013 addrs_lens,
4014 (const struct sockaddr **) saddrs,
4015 saddr_lens,
4018 NULL /* closure */);
4019 for (i = addrs_lens - 1; i >= 0; i--)
4020 GNUNET_free (saddrs[i]);
4021 GNUNET_free (saddrs);
4022 GNUNET_free (saddr_lens);
4023
4024 if (NULL == nat)
4025 {
4026 GNUNET_break (0);
4027 if (NULL != resolve_request_handle)
4030 }
4031}
4032
4033
4041static void
4043 const struct sockaddr *addr,
4044 socklen_t in_len)
4045{
4046 struct sockaddr_in *v4;
4047 struct sockaddr_in6 *v6;
4048 struct sockaddr *in;
4049
4050 (void) cls;
4051 if (NULL != addr)
4052 {
4053 if (AF_INET == addr->sa_family)
4054 {
4055 v4 = (struct sockaddr_in *) addr;
4056 in = tcp_address_to_sockaddr_numeric_v4 (&in_len, *v4, bind_port);// _global);
4057 }
4058 else if (AF_INET6 == addr->sa_family)
4059 {
4060 v6 = (struct sockaddr_in6 *) addr;
4061 in = tcp_address_to_sockaddr_numeric_v6 (&in_len, *v6, bind_port);// _global);
4062 }
4063 else
4064 {
4066 "Address family %u not suitable (not AF_INET %u nor AF_INET6 %u \n",
4067 addr->sa_family,
4068 AF_INET,
4069 AF_INET6);
4070 return;
4071 }
4072 init_socket (in, in_len);
4073 }
4074 else
4075 {
4077 "Address is NULL. This might be an error or the resolver finished resolving.\n");
4078 if (NULL == addrs_head)
4079 {
4081 "Resolver finished resolving, but we do not listen to an address!.\n");
4082 return;
4083 }
4084 nat_register ();
4085 }
4086}
4087
4088
4097static void
4098run (void *cls,
4099 char *const *args,
4100 const char *cfgfile,
4101 const struct GNUNET_CONFIGURATION_Handle *c)
4102{
4103 char *bindto;
4104 struct sockaddr *in;
4105 socklen_t in_len;
4106 struct sockaddr_in v4;
4107 struct sockaddr_in6 v6;
4108 char *start;
4109 unsigned int port;
4110 char dummy[2];
4111 char *rest = NULL;
4112 struct PortOnlyIpv4Ipv6 *po;
4113 socklen_t addr_len_ipv4;
4114 socklen_t addr_len_ipv6;
4115
4116 (void) cls;
4117
4119 memset (&v4,0,sizeof(struct sockaddr_in));
4120 memset (&v6,0,sizeof(struct sockaddr_in6));
4121 cfg = c;
4122 if (GNUNET_OK !=
4125 "BINDTO",
4126 &bindto))
4127 {
4130 "BINDTO");
4131 return;
4132 }
4133 if (GNUNET_OK !=
4136 "MAX_QUEUE_LENGTH",
4138 {
4140 }
4141 if (GNUNET_OK !=
4144 "REKEY_INTERVAL",
4146 {
4148 }
4149 if (GNUNET_OK !=
4152 "REKEY_MAX_BYTES",
4154 {
4156 }
4158 if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
4159 (GNUNET_YES ==
4162 "DISABLE_V6")))
4163 {
4165 }
4167 GNUNET_assert (NULL != key_ring);
4168 pils = GNUNET_PILS_connect (cfg, NULL, NULL);
4169 GNUNET_assert (NULL != pils);
4171 if (NULL == peerstore)
4172 {
4173 GNUNET_free (bindto);
4174 GNUNET_break (0);
4176 return;
4177 }
4178
4180
4181 if (1 == sscanf (bindto, "%u%1s", &bind_port, dummy))
4182 {
4186 "address po %s\n",
4188 if (NULL != po->addr_ipv4)
4189 {
4191 }
4192 if (NULL != po->addr_ipv6)
4193 {
4196 }
4197 GNUNET_free (po);
4198 nat_register ();
4199 GNUNET_free (bindto);
4200 return;
4201 }
4202
4203 start = extract_address (bindto);
4204 // FIXME: check for NULL == start...
4205 if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
4206 {
4207 bind_port = extract_port (bindto);
4208
4210 init_socket (in, in_len);
4211 nat_register ();
4213 GNUNET_free (bindto);
4214 return;
4215 }
4216
4217 if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
4218 {
4219 bind_port = extract_port (bindto);
4221 init_socket (in, in_len);
4222 nat_register ();
4224 GNUNET_free (bindto);
4225 return;
4226 }
4227
4228 bind_port = extract_port (bindto);
4230 ":",
4231 &rest),
4232 AF_UNSPEC,
4235 &port);
4236
4237 GNUNET_free (bindto);
4239}
4240
4241
4249int
4250main (int argc, char *const *argv)
4251{
4252 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
4254 };
4255 int ret;
4256
4258 "Starting tcp communicator\n");
4259
4260 ret = (GNUNET_OK ==
4262 argc,
4263 argv,
4264 "gnunet-communicator-tcp",
4265 _ ("GNUnet TCP communicator"),
4266 options,
4267 &run,
4268 NULL))
4269 ? 0
4270 : 1;
4271 return ret;
4272}
4273
4274
4275/* 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 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 void calculate_hmac(struct GNUNET_CRYPTO_AuthKey *hmac_secret, const void *buf, size_t buf_size, struct GNUNET_ShortHashCode *smac)
Compute mac over buf, and ratched the hmac_secret.
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.
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 setup_cipher(const struct GNUNET_ShortHashCode *prk, const struct GNUNET_PeerIdentity *pid, gcry_cipher_hd_t *cipher, struct GNUNET_CRYPTO_AuthKey *hmac_key)
Setup cipher based on shared secret dh and decrypting peer pid.
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(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...
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...
void GNUNET_CRYPTO_random_block(void *buffer, size_t length)
Fill block with a random values.
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.
#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:40
void GNUNET_CRYPTO_hmac(const struct GNUNET_CRYPTO_AuthKey *key, const void *plaintext, size_t plaintext_len, struct GNUNET_HashCode *hmac)
Calculate HMAC of a message (RFC 2104)
#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.
@ 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:406
#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:610
#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:671
#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.
type for (message) authentication keys
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.
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_CRYPTO_AuthKey in_hmac
Shared secret for HMAC verification on incoming data.
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_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_CRYPTO_AuthKey out_hmac
Shared secret for HMAC generation on outgoing data, ratcheted after each operation.
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...