GNUnet 0.21.0
gnunet-communicator-tcp.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet
3 Copyright (C) 2010-2014, 2018, 2019 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
30#include "platform.h"
31#include "gnunet_util_lib.h"
32#include "gnunet_core_service.h"
34#include "gnunet_protocols.h"
35#include "gnunet_signatures.h"
36#include "gnunet_constants.h"
37#include "gnunet_nat_service.h"
41
42
47#define NAT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
48
53#define ADDRESS_VALIDITY_PERIOD \
54 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
55
64#define DEFAULT_MAX_QUEUE_LENGTH 8
65
70#define BUF_SIZE (2 * 64 * 1024 + sizeof(struct TCPBox))
71
75#define DEFAULT_REKEY_INTERVAL GNUNET_TIME_UNIT_DAYS
76
80#define PROTO_QUEUE_TIMEOUT GNUNET_TIME_UNIT_MINUTES
81
86#define REKEY_MAX_BYTES (1024LLU * 1024 * 400)
87
92#define INITIAL_KX_SIZE \
93 (sizeof(struct GNUNET_CRYPTO_EcdhePublicKey) \
94 + sizeof(struct TCPConfirmation))
95
99#define INITIAL_CORE_KX_SIZE \
100 (sizeof(struct EphemeralKeyMessage) \
101 + sizeof(struct PingMessage) \
102 + sizeof(struct PongMessage))
103
107#define COMMUNICATOR_ADDRESS_PREFIX "tcp"
108
112#define COMMUNICATOR_CONFIG_SECTION "communicator-tcp"
113
115
116
122{
127
132
137
142
148
153};
154
160{
165
170
175
181
186};
187
192{
197
202
208
213
214};
215
220{
221
222
227
232
237
243
248
249};
250
254struct TCPBox
255{
263
273
274 /* followed by as may bytes of payload as indicated in @e header,
275 excluding the TCPBox itself! */
276};
277
278
284{
289
299
304
309
315};
316
322{
327
332
337
342
348};
349
356{
361
371};
372
378{
383
388};
389
391
396{
397 /*
398 * Timeout task.
399 */
401
406
410 struct sockaddr *in;
411};
412
417{
422
427};
428
432struct Queue
433{
438
443
448
452 gcry_cipher_hd_t in_cipher;
453
457 gcry_cipher_hd_t out_cipher;
458
463
469
474
479
483 struct sockaddr *address;
484
490
496
500 socklen_t address_len;
501
506
511
515 unsigned long long bytes_in_queue;
516
521
526
530 char pread_buf[UINT16_MAX + 1 + sizeof(struct TCPBox)];
531
535 char pwrite_buf[UINT16_MAX + 1 + sizeof(struct TCPBox)];
536
541 size_t cread_off;
542
548
553 size_t pread_off;
554
560
565
573 unsigned int backpressure;
574
579
584
589
594
602
608
613
618
623
628
633
638
643
648
653
658
663
667 // TODO remove?
669
674};
675
676
682{
687
692
697
702
707
711 char write_buf[sizeof (struct TCPNATProbeMessage)];
712
716 size_t write_off;
717
722
726 struct sockaddr *address;
727
731 socklen_t address_len;
732
737
743
747 size_t ibuf_off;
748};
749
754{
758 struct sockaddr *addr_ipv4;
759
763 socklen_t addr_len_ipv4;
764
768 struct sockaddr *addr_ipv6;
769
773 socklen_t addr_len_ipv6;
774
775};
776
781{
786
791
795 struct sockaddr *addr;
796
800 socklen_t addr_len;
801
802};
803
804
808static unsigned long long max_queue_length;
809
814
819
824
829
834
839
844
848static const struct GNUNET_CONFIGURATION_Handle *cfg;
849
854
858static struct GNUNET_NAT_Handle *nat;
859
863static struct ProtoQueue *proto_head;
864
868static struct ProtoQueue *proto_tail;
869
874
879
884
889
894
899
900
905
910
914unsigned int bind_port;
915
920
928static void
929listen_cb (void *cls);
930
938static void
940{
941 struct ListenTask *lt = NULL;
942 struct GNUNET_HashCode h_sock;
943 int sockfd;
944
945 if (NULL != queue->listen_sock)
946 {
947 sockfd = GNUNET_NETWORK_get_fd (queue->listen_sock);
948 GNUNET_CRYPTO_hash (&sockfd,
949 sizeof(int),
950 &h_sock);
951
953 }
954
956 "Disconnecting queue for peer `%s'\n",
957 GNUNET_i2s (&queue->target));
958 if (NULL != queue->rekey_monotime_sc)
959 {
960 GNUNET_PEERSTORE_store_cancel (queue->rekey_monotime_sc);
961 queue->rekey_monotime_sc = NULL;
962 }
963 if (NULL != queue->handshake_monotime_sc)
964 {
965 GNUNET_PEERSTORE_store_cancel (queue->handshake_monotime_sc);
966 queue->handshake_monotime_sc = NULL;
967 }
968 if (NULL != queue->handshake_ack_monotime_sc)
969 {
970 GNUNET_PEERSTORE_store_cancel (queue->handshake_ack_monotime_sc);
971 queue->handshake_ack_monotime_sc = NULL;
972 }
973 if (NULL != queue->rekey_monotime_get)
974 {
975 GNUNET_PEERSTORE_iteration_stop (queue->rekey_monotime_get);
976 queue->rekey_monotime_get = NULL;
977 }
978 if (NULL != queue->handshake_monotime_get)
979 {
980 GNUNET_PEERSTORE_iteration_stop (queue->handshake_monotime_get);
981 queue->handshake_monotime_get = NULL;
982 }
983 if (NULL != queue->handshake_ack_monotime_get)
984 {
985 GNUNET_PEERSTORE_iteration_stop (queue->handshake_ack_monotime_get);
986 queue->handshake_ack_monotime_get = NULL;
987 }
988 if (NULL != queue->qh)
989 {
991 queue->qh = NULL;
992 }
994 GNUNET_YES ==
997 "# queues active",
999 GNUNET_NO);
1000 if (NULL != queue->read_task)
1001 {
1002 GNUNET_SCHEDULER_cancel (queue->read_task);
1003 queue->read_task = NULL;
1004 }
1005 if (NULL != queue->write_task)
1006 {
1007 GNUNET_SCHEDULER_cancel (queue->write_task);
1008 queue->write_task = NULL;
1009 }
1011 {
1013 "closing socket failed\n");
1014 }
1015 gcry_cipher_close (queue->in_cipher);
1016 gcry_cipher_close (queue->out_cipher);
1017 GNUNET_free (queue->address);
1018 if (0 != queue->backpressure)
1019 queue->destroyed = GNUNET_YES;
1020 else
1022
1023 if (NULL == lt)
1024 return;
1025
1026 if ((! shutdown_running) && (NULL == lt->listen_task))
1027 {
1029 "add read net listen\n");
1032 lt->listen_sock,
1033 &listen_cb,
1034 lt);
1035 }
1036 else
1037 GNUNET_free (lt);
1038}
1039
1040
1049static void
1050calculate_hmac (struct GNUNET_HashCode *hmac_secret,
1051 const void *buf,
1052 size_t buf_size,
1053 struct GNUNET_ShortHashCode *smac)
1054{
1055 struct GNUNET_HashCode mac;
1056
1057 GNUNET_CRYPTO_hmac_raw (hmac_secret,
1058 sizeof(struct GNUNET_HashCode),
1059 buf,
1060 buf_size,
1061 &mac);
1062 /* truncate to `struct GNUNET_ShortHashCode` */
1063 memcpy (smac, &mac, sizeof(struct GNUNET_ShortHashCode));
1064 /* ratchet hmac key */
1065 GNUNET_CRYPTO_hash (hmac_secret,
1066 sizeof(struct GNUNET_HashCode),
1067 hmac_secret);
1068}
1069
1070
1077static void
1079{
1080 struct TCPFinish fin;
1081
1082 memset (&fin, 0, sizeof(fin));
1083 fin.header.size = htons (sizeof(fin));
1085 calculate_hmac (&queue->out_hmac, &fin, sizeof(fin), &fin.hmac);
1086 /* if there is any message left in pwrite_buf, we
1087 overwrite it (possibly dropping the last message
1088 from CORE hard here) */
1089 memcpy (queue->pwrite_buf, &fin, sizeof(fin));
1090 queue->pwrite_off = sizeof(fin);
1091 /* This flag will ensure that #queue_write() no longer
1092 notifies CORE about the possibility of sending
1093 more data, and that #queue_write() will call
1094 #queue_destroy() once the @c fin was fully written. */
1095 queue->finishing = GNUNET_YES;
1096}
1097
1098
1104static void
1105queue_read (void *cls);
1106
1107
1115static void
1116core_read_finished_cb (void *cls, int success)
1117{
1118 struct Queue *queue = cls;
1119 if (GNUNET_OK != success)
1121 "# messages lost in communicator API towards CORE",
1122 1,
1123 GNUNET_NO);
1124 if (NULL == queue)
1125 return;
1126
1128 "backpressure %u\n",
1129 queue->backpressure);
1130
1131 queue->backpressure--;
1132 /* handle deferred queue destruction */
1133 if ((queue->destroyed) && (0 == queue->backpressure))
1134 {
1136 return;
1137 }
1138 else if (GNUNET_YES != queue->destroyed)
1139 {
1140 queue->timeout =
1142 );
1143 /* possibly unchoke reading, now that CORE made progress */
1144 if (NULL == queue->read_task)
1145 queue->read_task =
1147 queue->timeout),
1148 queue->sock,
1149 &queue_read,
1150 queue);
1151 }
1152}
1153
1154
1164static void
1166 const void *plaintext,
1167 size_t plaintext_len)
1168{
1169 const struct GNUNET_MessageHeader *hdr = plaintext;
1170 int ret;
1171
1173 "pass message from %s to core\n",
1174 GNUNET_i2s (&queue->target));
1175
1176 if (ntohs (hdr->size) != plaintext_len)
1177 {
1178 /* NOTE: If we ever allow multiple CORE messages in one
1179 BOX, this will have to change! */
1180 GNUNET_break (0);
1181 return;
1182 }
1184 &queue->target,
1185 hdr,
1188 queue);
1190 "passed to core\n");
1191 if (GNUNET_OK == ret)
1192 queue->backpressure++;
1193 GNUNET_break (GNUNET_NO != ret); /* backpressure not working!? */
1194 if (GNUNET_SYSERR == ret)
1196 "# bytes lost due to CORE not running",
1197 plaintext_len,
1198 GNUNET_NO);
1199}
1200
1201
1211static void
1213 const struct GNUNET_PeerIdentity *pid,
1214 gcry_cipher_hd_t *cipher,
1215 struct GNUNET_HashCode *hmac_key)
1216{
1217 char key[256 / 8];
1218 char ctr[128 / 8];
1219
1220 GNUNET_assert (0 == gcry_cipher_open (cipher,
1221 GCRY_CIPHER_AES256 /* low level: go for speed */
1222 ,
1223 GCRY_CIPHER_MODE_CTR,
1224 0 /* flags */));
1226 sizeof(key),
1227 "TCP-key",
1228 strlen ("TCP-key"),
1229 dh,
1230 sizeof(*dh),
1231 pid,
1232 sizeof(*pid),
1233 NULL,
1234 0));
1235 GNUNET_assert (0 == gcry_cipher_setkey (*cipher, key, sizeof(key)));
1237 sizeof(ctr),
1238 "TCP-ctr",
1239 strlen ("TCP-ctr"),
1240 dh,
1241 sizeof(*dh),
1242 pid,
1243 sizeof(*pid),
1244 NULL,
1245 0));
1246 gcry_cipher_setctr (*cipher, ctr, sizeof(ctr));
1248 GNUNET_CRYPTO_kdf (hmac_key,
1249 sizeof(struct GNUNET_HashCode),
1250 "TCP-hmac",
1251 strlen ("TCP-hmac"),
1252 dh,
1253 sizeof(*dh),
1254 pid,
1255 sizeof(*pid),
1256 NULL,
1257 0));
1258}
1259
1260
1266static void
1267rekey_monotime_store_cb (void *cls, int success)
1268{
1269 struct Queue *queue = cls;
1270 if (GNUNET_OK != success)
1271 {
1273 "Failed to store rekey monotonic time in PEERSTORE!\n");
1274 }
1275 queue->rekey_monotime_sc = NULL;
1276 GNUNET_PEERSTORE_iteration_next (queue->rekey_monotime_get, 1);
1277}
1278
1279
1287static void
1289 const struct GNUNET_PEERSTORE_Record *record,
1290 const char *emsg)
1291{
1292 struct Queue *queue = cls;
1293 struct GNUNET_TIME_AbsoluteNBO *mtbe;
1294 struct GNUNET_TIME_Absolute mt;
1295 const struct GNUNET_PeerIdentity *pid;
1296 struct GNUNET_TIME_AbsoluteNBO *rekey_monotonic_time;
1297
1298 (void) emsg;
1299
1300 rekey_monotonic_time = &queue->rekey_monotonic_time;
1301 pid = &queue->target;
1302 if (NULL == record)
1303 {
1304 queue->rekey_monotime_get = NULL;
1305 return;
1306 }
1307 if (sizeof(*mtbe) != record->value_size)
1308 {
1309 GNUNET_PEERSTORE_iteration_next (queue->rekey_monotime_get, 1);
1310 GNUNET_break (0);
1311 return;
1312 }
1313 mtbe = record->value;
1314 mt = GNUNET_TIME_absolute_ntoh (*mtbe);
1316 queue->rekey_monotonic_time).abs_value_us)
1317 {
1319 "Queue from %s dropped, rekey monotime in the past\n",
1320 GNUNET_i2s (&queue->target));
1321 GNUNET_break (0);
1322 GNUNET_PEERSTORE_iteration_stop (queue->rekey_monotime_get);
1323 queue->rekey_monotime_get = NULL;
1325 return;
1326 }
1327 queue->rekey_monotime_sc = GNUNET_PEERSTORE_store (peerstore,
1328 "transport_tcp_communicator",
1329 pid,
1331 rekey_monotonic_time,
1332 sizeof(*
1333 rekey_monotonic_time),
1337 queue);
1338}
1339
1340
1347static void
1349 struct Queue *queue)
1350{
1351 struct GNUNET_HashCode k;
1352
1354 setup_cipher (&k, &my_identity, &queue->in_cipher, &queue->in_hmac);
1355}
1356
1357
1366static void
1367do_rekey (struct Queue *queue, const struct TCPRekey *rekey)
1368{
1369 struct TcpRekeySignature thp;
1370
1372 thp.purpose.size = htonl (sizeof(thp));
1374 "do_rekey size %u\n",
1375 thp.purpose.size);
1376 thp.sender = queue->target;
1378 "sender %s\n",
1381 "sender %s\n",
1382 GNUNET_p2s (&queue->target.public_key));
1383 thp.receiver = my_identity;
1385 "receiver %s\n",
1387 thp.ephemeral = rekey->ephemeral;
1389 "ephemeral %s\n",
1390 GNUNET_e2s (&thp.ephemeral));
1391 thp.monotonic_time = rekey->monotonic_time;
1393 "time %s\n",
1396 GNUNET_assert (ntohl ((&thp)->purpose.size) == sizeof (*(&thp)));
1397 if (GNUNET_OK !=
1400 &thp,
1401 &rekey->sender_sig,
1402 &queue->target.public_key))
1403 {
1404 GNUNET_break (0);
1406 return;
1407 }
1408 queue->rekey_monotonic_time = rekey->monotonic_time;
1409 queue->rekey_monotime_get = GNUNET_PEERSTORE_iteration_start (peerstore,
1410 "transport_tcp_communicator",
1411 &queue->target,
1413 &
1415 queue);
1416 gcry_cipher_close (queue->in_cipher);
1417 queue->rekeyed = GNUNET_YES;
1418 setup_in_cipher (&rekey->ephemeral, queue);
1419}
1420
1421
1427static void
1428handshake_ack_monotime_store_cb (void *cls, int success)
1429{
1430 struct Queue *queue = cls;
1431
1432 if (GNUNET_OK != success)
1433 {
1435 "Failed to store handshake ack monotonic time in PEERSTORE!\n");
1436 }
1437 queue->handshake_ack_monotime_sc = NULL;
1438 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
1439}
1440
1441
1449static void
1451 const struct GNUNET_PEERSTORE_Record *record,
1452 const char *emsg)
1453{
1454 struct Queue *queue = cls;
1455 struct GNUNET_TIME_AbsoluteNBO *mtbe;
1456 struct GNUNET_TIME_Absolute mt;
1457 const struct GNUNET_PeerIdentity *pid;
1458 struct GNUNET_TIME_AbsoluteNBO *handshake_ack_monotonic_time;
1459
1460 (void) emsg;
1461
1462 handshake_ack_monotonic_time = &queue->handshake_ack_monotonic_time;
1463 pid = &queue->target;
1464 if (NULL == record)
1465 {
1466 queue->handshake_ack_monotime_get = NULL;
1467 return;
1468 }
1469 if (sizeof(*mtbe) != record->value_size)
1470 {
1471 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
1472 GNUNET_break (0);
1473 return;
1474 }
1475 mtbe = record->value;
1476 mt = GNUNET_TIME_absolute_ntoh (*mtbe);
1478 queue->handshake_ack_monotonic_time).abs_value_us)
1479 {
1481 "Queue from %s dropped, handshake ack monotime in the past\n",
1482 GNUNET_i2s (&queue->target));
1483 GNUNET_break (0);
1484 GNUNET_PEERSTORE_iteration_stop (queue->handshake_ack_monotime_get);
1485 queue->handshake_ack_monotime_get = NULL;
1487 return;
1488 }
1489 queue->handshake_ack_monotime_sc =
1491 "transport_tcp_communicator",
1492 pid,
1494 handshake_ack_monotonic_time,
1495 sizeof(*handshake_ack_monotonic_time),
1499 queue);
1500}
1501
1502
1509static void
1511 struct Queue *queue)
1512{
1513 struct TCPConfirmationAck tca;
1514 struct TcpHandshakeAckSignature thas;
1515
1517 "sending challenge\n");
1518
1519 tca.header.type = ntohs (
1521 tca.header.size = ntohs (sizeof(tca));
1522 tca.challenge = challenge;
1523 tca.sender = my_identity;
1524 tca.monotonic_time =
1526 thas.purpose.purpose = htonl (
1528 thas.purpose.size = htonl (sizeof(thas));
1529 thas.sender = my_identity;
1530 thas.receiver = queue->target;
1531 thas.monotonic_time = tca.monotonic_time;
1532 thas.challenge = tca.challenge;
1534 &thas,
1535 &tca.sender_sig);
1536 GNUNET_assert (0 ==
1537 gcry_cipher_encrypt (queue->out_cipher,
1538 &queue->cwrite_buf[queue->cwrite_off],
1539 sizeof(tca),
1540 &tca,
1541 sizeof(tca)));
1542 queue->cwrite_off += sizeof(tca);
1544 "sending challenge done\n");
1545}
1546
1547
1554static void
1556{
1557 setup_cipher (dh, &queue->target, &queue->out_cipher, &queue->out_hmac);
1559 queue->rekey_left_bytes =
1561}
1562
1563
1570static void
1572{
1573 struct TCPRekey rekey;
1574 struct TcpRekeySignature thp;
1575 struct GNUNET_HashCode k;
1576
1577 GNUNET_assert (0 == queue->pwrite_off);
1578 memset (&rekey, 0, sizeof(rekey));
1579 GNUNET_CRYPTO_eddsa_kem_encaps (&queue->target.public_key, &rekey.ephemeral,
1580 &k);
1582 rekey.header.size = ntohs (sizeof(rekey));
1583 rekey.monotonic_time =
1586 thp.purpose.size = htonl (sizeof(thp));
1588 "inject_rekey size %u\n",
1589 thp.purpose.size);
1590 thp.sender = my_identity;
1592 "sender %s\n",
1594 thp.receiver = queue->target;
1596 "receiver %s\n",
1598 thp.ephemeral = rekey.ephemeral;
1600 "ephemeral %s\n",
1601 GNUNET_e2s (&thp.ephemeral));
1602 thp.monotonic_time = rekey.monotonic_time;
1604 "time %s\n",
1608 &thp,
1609 &rekey.sender_sig);
1610 calculate_hmac (&queue->out_hmac, &rekey, sizeof(rekey), &rekey.hmac);
1611 /* Encrypt rekey message with 'old' cipher */
1612 GNUNET_assert (0 ==
1613 gcry_cipher_encrypt (queue->out_cipher,
1614 &queue->cwrite_buf[queue->cwrite_off],
1615 sizeof(rekey),
1616 &rekey,
1617 sizeof(rekey)));
1618 queue->cwrite_off += sizeof(rekey);
1619 /* Setup new cipher for successive messages */
1620 gcry_cipher_close (queue->out_cipher);
1621 setup_out_cipher (queue, &k);
1622}
1623
1624
1625static int
1627 const struct GNUNET_HashCode *key,
1628 void *value)
1629{
1630 (void) cls;
1631 struct PendingReversal *pending_reversal = value;
1632
1633 if (NULL != pending_reversal->timeout_task)
1634 {
1635 GNUNET_SCHEDULER_cancel (pending_reversal->timeout_task);
1636 pending_reversal->timeout_task = NULL;
1637 }
1640 key,
1641 pending_reversal));
1642 GNUNET_free (pending_reversal->in);
1643 GNUNET_free (pending_reversal);
1644 return GNUNET_OK;
1645}
1646
1647
1648static void
1649check_and_remove_pending_reversal (struct sockaddr *in, sa_family_t sa_family,
1650 struct GNUNET_PeerIdentity *sender)
1651{
1652 if (AF_INET == sa_family)
1653 {
1654 struct PendingReversal *pending_reversal;
1655 struct GNUNET_HashCode key;
1656 struct sockaddr_in *natted_address;
1657
1658 natted_address = GNUNET_memdup (in, sizeof (struct sockaddr));
1659 natted_address->sin_port = 0;
1660 GNUNET_CRYPTO_hash (natted_address,
1661 sizeof(struct sockaddr),
1662 &key);
1663
1665 &key);
1666 if (NULL != pending_reversal && (NULL == sender ||
1667 0 != memcmp (sender,
1668 &pending_reversal->target,
1669 sizeof(struct
1671 {
1673 "Removing invalid pending reversal for `%s'at `%s'\n",
1674 GNUNET_i2s (&pending_reversal->target),
1675 GNUNET_a2s (in, sizeof (struct sockaddr)));
1676 pending_reversals_delete_it (NULL, &key, pending_reversal);
1677 }
1678 GNUNET_free (natted_address);
1679 }
1680}
1681
1682
1688static void
1690{
1691 if (NULL != pq->listen_sock)
1692 {
1694 pq->listen_sock = NULL;
1695 }
1696 if (NULL != pq->read_task)
1697 {
1699 pq->read_task = NULL;
1700 }
1701 if (NULL != pq->write_task)
1702 {
1704 pq->write_task = NULL;
1705 }
1706 check_and_remove_pending_reversal (pq->address, pq->address->sa_family, NULL);
1708 GNUNET_free (pq->address);
1710 GNUNET_free (pq);
1711}
1712
1713
1720static void
1722{
1723 struct ProtoQueue *pq = cls;
1724 ssize_t sent;
1725 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "In proto queue write\n");
1726 pq->write_task = NULL;
1727 if (0 != pq->write_off)
1728 {
1729 sent = GNUNET_NETWORK_socket_send (pq->sock,
1730 pq->write_buf,
1731 pq->write_off);
1733 "Sent %lu bytes to TCP queue\n", sent);
1734 if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno))
1735 {
1737 free_proto_queue (pq);
1738 return;
1739 }
1740 if (sent > 0)
1741 {
1742 size_t usent = (size_t) sent;
1743 pq->write_off -= usent;
1744 memmove (pq->write_buf,
1745 &pq->write_buf[usent],
1746 pq->write_off);
1747 }
1748 }
1749 /* do we care to write more? */
1750 if ((0 < pq->write_off))
1751 pq->write_task =
1753 pq->sock,
1755 pq);
1756}
1757
1758
1765static void
1766queue_write (void *cls)
1767{
1768 struct Queue *queue = cls;
1769 ssize_t sent;
1770 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "In queue write\n");
1771 queue->write_task = NULL;
1772 if (0 != queue->cwrite_off)
1773 {
1774 sent = GNUNET_NETWORK_socket_send (queue->sock,
1775 queue->cwrite_buf,
1776 queue->cwrite_off);
1778 "Sent %lu bytes to TCP queue\n", sent);
1779 if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno))
1780 {
1783 return;
1784 }
1785 if (sent > 0)
1786 {
1787 size_t usent = (size_t) sent;
1788 queue->cwrite_off -= usent;
1789 memmove (queue->cwrite_buf,
1790 &queue->cwrite_buf[usent],
1791 queue->cwrite_off);
1792 queue->timeout =
1795 }
1796 }
1797 /* can we encrypt more? (always encrypt full messages, needed
1798 such that #mq_cancel() can work!) */
1799 unsigned int we_do_not_need_to_rekey = (0 < queue->rekey_left_bytes
1800 - (queue->cwrite_off
1801 + queue->pwrite_off
1802 + sizeof (struct TCPRekey)));
1803 if (we_do_not_need_to_rekey &&
1804 (queue->pwrite_off > 0) &&
1805 (queue->cwrite_off + queue->pwrite_off <= BUF_SIZE))
1806 {
1808 "Encrypting %lu bytes\n", queue->pwrite_off);
1809 GNUNET_assert (0 ==
1810 gcry_cipher_encrypt (queue->out_cipher,
1811 &queue->cwrite_buf[queue->cwrite_off],
1812 queue->pwrite_off,
1813 queue->pwrite_buf,
1814 queue->pwrite_off));
1815 if (queue->rekey_left_bytes > queue->pwrite_off)
1816 queue->rekey_left_bytes -= queue->pwrite_off;
1817 else
1818 queue->rekey_left_bytes = 0;
1819 queue->cwrite_off += queue->pwrite_off;
1820 queue->pwrite_off = 0;
1821 }
1822 // if ((-1 != unverified_size)&& ((0 == queue->pwrite_off) &&
1823 if (((0 == queue->rekey_left_bytes) ||
1825 queue->rekey_time).rel_value_us)) &&
1826 (((0 == queue->pwrite_off) || ! we_do_not_need_to_rekey) &&
1827 (queue->cwrite_off + sizeof (struct TCPRekey) <= BUF_SIZE)))
1828 {
1830 }
1831 if ((0 == queue->pwrite_off) && (! queue->finishing) &&
1832 (GNUNET_YES == queue->mq_awaits_continue))
1833 {
1834 queue->mq_awaits_continue = GNUNET_NO;
1836 }
1837 /* did we just finish writing 'finish'? */
1838 if ((0 == queue->cwrite_off) && (GNUNET_YES == queue->finishing))
1839 {
1841 "Finishing queue\n");
1843 return;
1844 }
1845 /* do we care to write more? */
1846 if ((0 < queue->cwrite_off) || (0 < queue->pwrite_off))
1847 queue->write_task =
1849 queue->sock,
1850 &queue_write,
1851 queue);
1852}
1853
1854
1862static size_t
1864{
1865 const struct GNUNET_MessageHeader *hdr;
1866 const struct TCPConfirmationAck *tca;
1867 const struct TCPBox *box;
1868 const struct TCPRekey *rekey;
1869 const struct TCPFinish *fin;
1870 struct TCPRekey rekeyz;
1871 struct TCPFinish finz;
1872 struct GNUNET_ShortHashCode tmac;
1873 uint16_t type;
1874 size_t size = 0;
1875 struct TcpHandshakeAckSignature thas;
1876 const struct GNUNET_CRYPTO_ChallengeNonceP challenge = queue->challenge;
1877
1879 "try handle plaintext!\n");
1880
1881 hdr = (const struct GNUNET_MessageHeader *) queue->pread_buf;
1882 if ((sizeof(*hdr) > queue->pread_off))
1883 {
1885 "Handling plaintext, not even a header!\n");
1886 return 0; /* not even a header */
1887 }
1888
1889 if ((GNUNET_YES != queue->initial_core_kx_done) && (queue->unverified_size >
1891 {
1893 "Already received data of size %lu bigger than KX size %lu!\n",
1894 queue->unverified_size,
1896 GNUNET_break_op (0);
1898 return 0;
1899 }
1900
1901 type = ntohs (hdr->type);
1902 switch (type)
1903 {
1905 tca = (const struct TCPConfirmationAck *) queue->pread_buf;
1907 "start processing ack\n");
1908 if (sizeof(*tca) > queue->pread_off)
1909 {
1911 "Handling plaintext size of tca greater than pread offset.\n")
1912 ;
1913 return 0;
1914 }
1915 if (ntohs (hdr->size) != sizeof(*tca))
1916 {
1918 "Handling plaintext size does not match message type.\n");
1919 GNUNET_break_op (0);
1921 return 0;
1922 }
1923
1924 thas.purpose.purpose = htonl (
1926 thas.purpose.size = htonl (sizeof(thas));
1927 thas.sender = tca->sender;
1928 thas.receiver = my_identity;
1929 thas.monotonic_time = tca->monotonic_time;
1930 thas.challenge = tca->challenge;
1931
1934 &thas,
1935 &tca->sender_sig,
1936 &tca->sender.public_key))
1937 {
1939 "Verification of signature failed!\n");
1940 GNUNET_break (0);
1942 return 0;
1943 }
1944 if (0 != GNUNET_memcmp (&tca->challenge, &challenge))
1945 {
1947 "Challenge in TCPConfirmationAck not correct!\n");
1948 GNUNET_break (0);
1950 return 0;
1951 }
1952
1953 queue->handshake_ack_monotime_get = GNUNET_PEERSTORE_iteration_start (
1954 peerstore,
1955 "transport_tcp_communicator",
1956 &queue->target,
1959 queue);
1960
1962 "Handling plaintext, ack processed!\n");
1963
1965 {
1966 send_challenge (queue->challenge_received, queue);
1967 queue->write_task =
1969 queue->sock,
1970 &queue_write,
1971 queue);
1972 }
1973 else if (GNUNET_TRANSPORT_CS_OUTBOUND == queue->cs)
1974 {
1976 queue->address->sa_family, NULL);
1977 }
1978
1983 queue->initial_core_kx_done = GNUNET_YES;
1984
1985 char *foreign_addr;
1986
1987 switch (queue->address->sa_family)
1988 {
1989 case AF_INET:
1990 GNUNET_asprintf (&foreign_addr,
1991 "%s-%s",
1993 GNUNET_a2s (queue->address, queue->address_len));
1994 break;
1995
1996 case AF_INET6:
1997 GNUNET_asprintf (&foreign_addr,
1998 "%s-%s",
2000 GNUNET_a2s (queue->address, queue->address_len));
2001 break;
2002
2003 default:
2004 GNUNET_assert (0);
2005 }
2006
2008 &queue->target,
2009 foreign_addr,
2010 UINT16_MAX, /* no MTU */
2012 0, /* Priority */
2013 queue->nt,
2014 queue->cs,
2015 queue->mq);
2016
2017 GNUNET_free (foreign_addr);
2018
2019 size = ntohs (hdr->size);
2020 break;
2022 /* Special case: header size excludes box itself! */
2023 box = (const struct TCPBox *) queue->pread_buf;
2024 if (ntohs (hdr->size) + sizeof(struct TCPBox) > queue->pread_off)
2025 return 0;
2026 calculate_hmac (&queue->in_hmac, &box[1], ntohs (hdr->size), &tmac);
2027 if (0 != memcmp (&tmac, &box->hmac, sizeof(tmac)))
2028 {
2029 GNUNET_break_op (0);
2031 return 0;
2032 }
2033 pass_plaintext_to_core (queue, (const void *) &box[1], ntohs (hdr->size));
2034 size = ntohs (hdr->size) + sizeof(*box);
2036 "Handling plaintext, box processed!\n");
2037 break;
2038
2040 rekey = (const struct TCPRekey *) queue->pread_buf;
2041 if (sizeof(*rekey) > queue->pread_off)
2042 return 0;
2043 if (ntohs (hdr->size) != sizeof(*rekey))
2044 {
2045 GNUNET_break_op (0);
2047 return 0;
2048 }
2049 rekeyz = *rekey;
2050 memset (&rekeyz.hmac, 0, sizeof(rekeyz.hmac));
2051 calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
2052 if (0 != memcmp (&tmac, &rekey->hmac, sizeof(tmac)))
2053 {
2054 GNUNET_break_op (0);
2056 return 0;
2057 }
2058 do_rekey (queue, rekey);
2059 size = ntohs (hdr->size);
2061 "Handling plaintext, rekey processed!\n");
2062 break;
2063
2065 fin = (const struct TCPFinish *) queue->pread_buf;
2066 if (sizeof(*fin) > queue->pread_off)
2067 return 0;
2068 if (ntohs (hdr->size) != sizeof(*fin))
2069 {
2070 GNUNET_break_op (0);
2072 return 0;
2073 }
2074 finz = *fin;
2075 memset (&finz.hmac, 0, sizeof(finz.hmac));
2076 calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
2077 if (0 != memcmp (&tmac, &fin->hmac, sizeof(tmac)))
2078 {
2079 GNUNET_break_op (0);
2081 return 0;
2082 }
2083 /* handle FINISH by destroying queue */
2086 "Handling plaintext, finish processed!\n");
2087 break;
2088
2089 default:
2091 "Handling plaintext, nothing processed!\n");
2092 GNUNET_break_op (0);
2094 return 0;
2095 }
2096 GNUNET_assert (0 != size);
2097 if (-1 != queue->unverified_size)
2098 queue->unverified_size += size;
2099 return size;
2100}
2101
2102
2108static void
2109queue_read (void *cls)
2110{
2111 struct Queue *queue = cls;
2112 struct GNUNET_TIME_Relative left;
2113 ssize_t rcvd;
2114
2115 queue->read_task = NULL;
2116 rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
2117 &queue->cread_buf[queue->cread_off],
2118 BUF_SIZE - queue->cread_off);
2120 "Received %zd bytes from TCP queue\n", rcvd);
2121 if (-1 == rcvd)
2122 {
2123 if ((EAGAIN != errno) && (EINTR != errno))
2124 {
2127 return;
2128 }
2129 /* try again */
2130 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
2131 if (0 != left.rel_value_us)
2132 {
2133 queue->read_task =
2135 return;
2136 }
2138 "Queue %p was idle for %s, disconnecting\n",
2139 queue,
2142 GNUNET_YES));
2144 return;
2145 }
2146 if (0 == rcvd)
2147 {
2148 /* Orderly shutdown of connection */
2150 "Socket for queue %p seems to have been closed\n", queue);
2152 return;
2153 }
2154 queue->timeout =
2156 queue->cread_off += rcvd;
2157 while ((queue->pread_off < sizeof(queue->pread_buf)) &&
2158 (queue->cread_off > 0))
2159 {
2160 size_t max = GNUNET_MIN (sizeof(queue->pread_buf) - queue->pread_off,
2161 queue->cread_off);
2162 size_t done;
2163 size_t total;
2164 size_t old_pread_off = queue->pread_off;
2165
2166 GNUNET_assert (0 ==
2167 gcry_cipher_decrypt (queue->in_cipher,
2168 &queue->pread_buf[queue->pread_off],
2169 max,
2170 queue->cread_buf,
2171 max));
2172 queue->pread_off += max;
2173 total = 0;
2174 while (0 != (done = try_handle_plaintext (queue)))
2175 {
2176 /* 'done' bytes of plaintext were used, shift buffer */
2177 GNUNET_assert (done <= queue->pread_off);
2178 /* NOTE: this memmove() could possibly sometimes be
2179 avoided if we pass 'total' into try_handle_plaintext()
2180 and use it at an offset into the buffer there! */
2181 memmove (queue->pread_buf,
2182 &queue->pread_buf[done],
2183 queue->pread_off - done);
2184 queue->pread_off -= done;
2185 total += done;
2186 /* The last plaintext was a rekey, abort for now */
2187 if (GNUNET_YES == queue->rekeyed)
2188 break;
2189 }
2190 /* when we encounter a rekey message, the decryption above uses the
2191 wrong key for everything after the rekey; in that case, we have
2192 to re-do the decryption at 'total' instead of at 'max'.
2193 However, we have to take into account that the plaintext buffer may have
2194 already contained data and not jumped too far ahead in the ciphertext.
2195 If there is no rekey and the last message is incomplete (max > total),
2196 it is safe to keep the decryption so we shift by 'max' */
2197 if (GNUNET_YES == queue->rekeyed)
2198 {
2199 max = total - old_pread_off;
2200 queue->rekeyed = GNUNET_NO;
2201 queue->pread_off = 0;
2202 }
2203 memmove (queue->cread_buf, &queue->cread_buf[max], queue->cread_off - max);
2204 queue->cread_off -= max;
2205 }
2206 if (BUF_SIZE == queue->cread_off)
2207 return; /* buffer full, suspend reading */
2208 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
2209 if (0 != left.rel_value_us)
2210 {
2211 if (max_queue_length > queue->backpressure)
2212 {
2213 /* continue reading */
2214 queue->read_task =
2216 }
2217 return;
2218 }
2220 "Queue %p was idle for %s, disconnecting\n",
2221 queue,
2224 GNUNET_YES));
2226}
2227
2228
2236static struct sockaddr *
2238 struct sockaddr_in6 v6,
2239 unsigned int port)
2240{
2241 struct sockaddr *in;
2242
2243 v6.sin6_family = AF_INET6;
2244 v6.sin6_port = htons ((uint16_t) port);
2245#if HAVE_SOCKADDR_IN_SIN_LEN
2246 v6.sin6_len = sizeof(struct sockaddr_in6);
2247#endif
2248 v6.sin6_flowinfo = 0;
2249 v6.sin6_scope_id = 0;
2250 in = GNUNET_memdup (&v6, sizeof(v6));
2251 *sock_len = sizeof(struct sockaddr_in6);
2252
2253 return in;
2254}
2255
2256
2264static struct sockaddr *
2266 struct sockaddr_in v4,
2267 unsigned int port)
2268{
2269 struct sockaddr *in;
2270
2271 v4.sin_family = AF_INET;
2272 v4.sin_port = htons ((uint16_t) port);
2273#if HAVE_SOCKADDR_IN_SIN_LEN
2274 v4.sin_len = sizeof(struct sockaddr_in);
2275#endif
2276 in = GNUNET_memdup (&v4, sizeof(v4));
2277 *sock_len = sizeof(struct sockaddr_in);
2278 return in;
2279}
2280
2281
2288static struct PortOnlyIpv4Ipv6 *
2289tcp_address_to_sockaddr_port_only (const char *bindto, unsigned int *port)
2290{
2291 struct PortOnlyIpv4Ipv6 *po;
2292 struct sockaddr_in *i4;
2293 struct sockaddr_in6 *i6;
2294 socklen_t sock_len_ipv4;
2295 socklen_t sock_len_ipv6;
2296
2297 /* interpreting value as just a PORT number */
2298 if (*port > UINT16_MAX)
2299 {
2301 "BINDTO specification `%s' invalid: value too large for port\n",
2302 bindto);
2303 return NULL;
2304 }
2305
2306 po = GNUNET_new (struct PortOnlyIpv4Ipv6);
2307
2308 if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
2309 (GNUNET_YES ==
2312 "DISABLE_V6")))
2313 {
2314 i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
2315 po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
2316 *port);
2317 po->addr_len_ipv4 = sock_len_ipv4;
2318 }
2319 else
2320 {
2321
2322 i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
2323 po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
2324 *port);
2325 po->addr_len_ipv4 = sock_len_ipv4;
2326
2327 i6 = GNUNET_malloc (sizeof(struct sockaddr_in6));
2328 po->addr_ipv6 = tcp_address_to_sockaddr_numeric_v6 (&sock_len_ipv6, *i6,
2329 *port);
2330
2331 po->addr_len_ipv6 = sock_len_ipv6;
2332
2333 GNUNET_free (i6);
2334 }
2335
2336 GNUNET_free (i4);
2337
2338 return po;
2339}
2340
2341
2348static char *
2349extract_address (const char *bindto)
2350{
2351 char *addr;
2352 char *start;
2353 char *token;
2354 char *cp;
2355 char *rest = NULL;
2356 char *res;
2357
2359 "extract address with bindto %s\n",
2360 bindto);
2361
2362 if (NULL == bindto)
2364 "bindto is NULL\n");
2365
2366 cp = GNUNET_strdup (bindto);
2367
2369 "extract address 2\n");
2370
2371 start = cp;
2372 if (('[' == *cp) && (']' == cp[strlen (cp) - 1]))
2373 {
2374 start++; /* skip over '['*/
2375 cp[strlen (cp) - 1] = '\0'; /* eat ']'*/
2376 addr = GNUNET_strdup (start);
2377 }
2378 else
2379 {
2380 token = strtok_r (cp, "]", &rest);
2381 if (strlen (bindto) == strlen (token))
2382 {
2383 token = strtok_r (cp, ":", &rest);
2384 addr = GNUNET_strdup (token);
2385 }
2386 else
2387 {
2388 token++;
2389 res = GNUNET_strdup (token);
2390 addr = GNUNET_strdup (res);
2391 }
2392 }
2393
2395 "tcp address: %s\n",
2396 addr);
2397 GNUNET_free (cp);
2398 return addr;
2399}
2400
2401
2408static unsigned int
2409extract_port (const char *addr_and_port)
2410{
2411 unsigned int port;
2412 char dummy[2];
2413 char *token;
2414 char *addr;
2415 char *colon;
2416 char *cp;
2417 char *rest = NULL;
2418
2419 if (NULL != addr_and_port)
2420 {
2421 cp = GNUNET_strdup (addr_and_port);
2422 token = strtok_r (cp, "]", &rest);
2423 if (strlen (addr_and_port) == strlen (token))
2424 {
2425 colon = strrchr (cp, ':');
2426 if (NULL == colon)
2427 {
2428 GNUNET_free (cp);
2429 return 0;
2430 }
2431 addr = colon;
2432 addr++;
2433 }
2434 else
2435 {
2436 token = strtok_r (NULL, "]", &rest);
2437 if (NULL == token)
2438 {
2439 GNUNET_free (cp);
2440 return 0;
2441 }
2442 else
2443 {
2444 addr = token;
2445 addr++;
2446 }
2447 }
2448
2449
2450 if (1 == sscanf (addr, "%u%1s", &port, dummy))
2451 {
2452 /* interpreting value as just a PORT number */
2453 if (port > UINT16_MAX)
2454 {
2456 "Port `%u' invalid: value too large for port\n",
2457 port);
2458 GNUNET_free (cp);
2459 return 0;
2460 }
2461 }
2462 else
2463 {
2465 "BINDTO specification invalid: last ':' not followed by number\n");
2466 GNUNET_free (cp);
2467 return 0;
2468 }
2469 GNUNET_free (cp);
2470 }
2471 else
2472 {
2474 "return 0\n");
2475 /* interpret missing port as 0, aka pick any free one */
2476 port = 0;
2477 }
2478
2479 return port;
2480}
2481
2482
2490static struct sockaddr *
2491tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
2492{
2493 struct sockaddr *in;
2494 unsigned int port;
2495 struct sockaddr_in v4;
2496 struct sockaddr_in6 v6;
2497 char *start;
2498
2499 memset (&v4, 0, sizeof(v4));
2500 start = extract_address (bindto);
2501 GNUNET_assert (NULL != start);
2503 "start %s\n",
2504 start);
2505
2507 "!bindto %s\n",
2508 bindto);
2509
2510
2511 if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
2512 {
2513 // colon = strrchr (cp, ':');
2514 port = extract_port (bindto);
2515
2517 "port %u\n",
2518 port);
2519
2520 in = tcp_address_to_sockaddr_numeric_v4 (sock_len, v4, port);
2521 }
2522 else if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
2523 {
2524 // colon = strrchr (cp, ':');
2525 port = extract_port (bindto);
2526 in = tcp_address_to_sockaddr_numeric_v6 (sock_len, v6, port);
2527 }
2528 else
2529 {
2530 GNUNET_assert (0);
2531 }
2532
2534 return in;
2535}
2536
2537
2546static void
2548 const struct GNUNET_MessageHeader *msg,
2549 void *impl_state)
2550{
2551 struct Queue *queue = impl_state;
2552 uint16_t msize = ntohs (msg->size);
2553 struct TCPBox box;
2555 "In MQ send. Queue finishing: %s; write task running: %s\n",
2556 (GNUNET_YES == queue->finishing) ? "yes" : "no",
2557 (NULL == queue->write_task) ? "yes" : "no");
2558 GNUNET_assert (mq == queue->mq);
2559 queue->mq_awaits_continue = GNUNET_YES;
2560 if (GNUNET_YES == queue->finishing)
2561 return; /* this queue is dying, drop msg */
2562 GNUNET_assert (0 == queue->pwrite_off);
2564 box.header.size = htons (msize);
2565 calculate_hmac (&queue->out_hmac, msg, msize, &box.hmac);
2566 memcpy (&queue->pwrite_buf[queue->pwrite_off], &box, sizeof(box));
2567 queue->pwrite_off += sizeof(box);
2568 memcpy (&queue->pwrite_buf[queue->pwrite_off], msg, msize);
2569 queue->pwrite_off += msize;
2571 "%lu bytes of plaintext to send\n", queue->pwrite_off);
2572 GNUNET_assert (NULL != queue->sock);
2573 if (NULL == queue->write_task)
2574 queue->write_task =
2576 queue->sock,
2577 &queue_write,
2578 queue);
2579}
2580
2581
2590static void
2591mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state)
2592{
2593 struct Queue *queue = impl_state;
2594
2595 if (mq == queue->mq)
2596 {
2597 queue->mq = NULL;
2599 }
2600}
2601
2602
2609static void
2610mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
2611{
2612 struct Queue *queue = impl_state;
2613
2614 GNUNET_assert (0 != queue->pwrite_off);
2615 queue->pwrite_off = 0;
2616}
2617
2618
2628static void
2629mq_error (void *cls, enum GNUNET_MQ_Error error)
2630{
2631 struct Queue *queue = cls;
2632
2634 "MQ error in queue to %s: %d\n",
2635 GNUNET_i2s (&queue->target),
2636 (int) error);
2638}
2639
2640
2648static void
2650{
2651 queue->nt =
2652 GNUNET_NT_scanner_get_type (is, queue->address, queue->address_len);
2654 queue_map,
2655 &queue->target,
2656 queue,
2659 "# queues active",
2661 GNUNET_NO);
2662 queue->timeout =
2665 &mq_destroy,
2666 &mq_cancel,
2667 queue,
2668 NULL,
2669 &mq_error,
2670 queue);
2671}
2672
2673
2684static void
2686 const struct GNUNET_CRYPTO_EcdhePublicKey *epub)
2687{
2688 struct TcpHandshakeSignature ths;
2689 struct TCPConfirmation tc;
2690
2691 memcpy (queue->cwrite_buf, epub, sizeof(*epub));
2692 queue->cwrite_off = sizeof(*epub);
2693 /* compute 'tc' and append in encrypted format to cwrite_buf */
2694 tc.sender = my_identity;
2695 tc.monotonic_time =
2698 &tc.challenge,
2699 sizeof(tc.challenge));
2700 ths.purpose.purpose = htonl (
2702 ths.purpose.size = htonl (sizeof(ths));
2703 ths.sender = my_identity;
2704 ths.receiver = queue->target;
2705 ths.ephemeral = *epub;
2706 ths.monotonic_time = tc.monotonic_time;
2707 ths.challenge = tc.challenge;
2709 &ths,
2710 &tc.sender_sig);
2711 GNUNET_assert (0 ==
2712 gcry_cipher_encrypt (queue->out_cipher,
2713 &queue->cwrite_buf[queue->cwrite_off],
2714 sizeof(tc),
2715 &tc,
2716 sizeof(tc)));
2717 queue->challenge = tc.challenge;
2718 queue->cwrite_off += sizeof(tc);
2719
2721 "handshake written\n");
2722}
2723
2724
2732static void
2734{
2735 struct GNUNET_CRYPTO_EcdhePublicKey epub;
2736 struct GNUNET_HashCode k;
2737
2738 GNUNET_CRYPTO_eddsa_kem_encaps (&queue->target.public_key, &epub, &k);
2739 setup_out_cipher (queue, &k);
2740 transmit_kx (queue, &epub);
2741}
2742
2743
2749static void
2750handshake_monotime_store_cb (void *cls, int success)
2751{
2752 struct Queue *queue = cls;
2753 if (GNUNET_OK != success)
2754 {
2756 "Failed to store handshake monotonic time in PEERSTORE!\n");
2757 }
2758 queue->handshake_monotime_sc = NULL;
2759 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
2760}
2761
2762
2770static void
2772 const struct GNUNET_PEERSTORE_Record *record,
2773 const char *emsg)
2774{
2775 struct Queue *queue = cls;
2776 struct GNUNET_TIME_AbsoluteNBO *mtbe;
2777 struct GNUNET_TIME_Absolute mt;
2778 const struct GNUNET_PeerIdentity *pid;
2779 struct GNUNET_TIME_AbsoluteNBO *handshake_monotonic_time;
2780
2781 (void) emsg;
2782
2783 handshake_monotonic_time = &queue->handshake_monotonic_time;
2784 pid = &queue->target;
2786 "tcp handshake with us %s\n",
2788 if (NULL == record)
2789 {
2790 queue->handshake_monotime_get = NULL;
2791 return;
2792 }
2794 "tcp handshake from peer %s\n",
2795 GNUNET_i2s (pid));
2796 if (sizeof(*mtbe) != record->value_size)
2797 {
2798 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
2799 GNUNET_break (0);
2800 return;
2801 }
2802 mtbe = record->value;
2803 mt = GNUNET_TIME_absolute_ntoh (*mtbe);
2805 queue->handshake_monotonic_time).abs_value_us)
2806 {
2808 "Queue from %s dropped, handshake monotime in the past\n",
2809 GNUNET_i2s (&queue->target));
2810 GNUNET_break (0);
2811 GNUNET_PEERSTORE_iteration_stop (queue->handshake_ack_monotime_get);
2812 queue->handshake_ack_monotime_get = NULL;
2814 return;
2815 }
2816 queue->handshake_monotime_sc = GNUNET_PEERSTORE_store (peerstore,
2817 "transport_tcp_communicator",
2818 pid,
2820 handshake_monotonic_time,
2821 sizeof(*
2822 handshake_monotonic_time),
2825 &
2827 queue);
2828}
2829
2830
2842static int
2844 struct TCPConfirmation *tc,
2845 char *ibuf)
2846{
2847 struct TcpHandshakeSignature ths;
2849
2851 0 ==
2852 gcry_cipher_decrypt (queue->in_cipher,
2853 tc,
2854 sizeof(*tc),
2855 &ibuf[sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)],
2856 sizeof(*tc)));
2857 ths.purpose.purpose = htonl (
2859 ths.purpose.size = htonl (sizeof(ths));
2860 ths.sender = tc->sender;
2861 ths.receiver = my_identity;
2862 memcpy (&ths.ephemeral, ibuf, sizeof(struct GNUNET_CRYPTO_EcdhePublicKey));
2863 ths.monotonic_time = tc->monotonic_time;
2864 ths.challenge = tc->challenge;
2867 &ths,
2868 &tc->sender_sig,
2869 &tc->sender.public_key);
2870 if (GNUNET_YES == ret)
2871 queue->handshake_monotime_get =
2873 "transport_tcp_communicator",
2874 &queue->target,
2877 queue);
2878 return ret;
2879}
2880
2881
2889static void
2890queue_read_kx (void *cls)
2891{
2892 struct Queue *queue = cls;
2893 ssize_t rcvd;
2894 struct GNUNET_TIME_Relative left;
2895 struct TCPConfirmation tc;
2896
2897 queue->read_task = NULL;
2898 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
2899 if (0 == left.rel_value_us)
2900 {
2902 return;
2903 }
2904 rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
2905 &queue->cread_buf[queue->cread_off],
2906 BUF_SIZE - queue->cread_off);
2908 "Received %lu bytes to write in buffer of size %lu for KX from queue %p (expires in %"
2909 PRIu64 ")\n",
2910 rcvd, BUF_SIZE - queue->cread_off, queue, left.rel_value_us);
2911 if (-1 == rcvd)
2912 {
2913 if ((EAGAIN != errno) && (EINTR != errno))
2914 {
2917 return;
2918 }
2919 queue->read_task =
2921 return;
2922 }
2923 if (0 == rcvd)
2924 {
2925 /* Orderly shutdown of connection */
2927 "Socket for queue %p seems to have been closed\n", queue);
2929 return;
2930 }
2931 queue->cread_off += rcvd;
2932 if (queue->cread_off < INITIAL_KX_SIZE)
2933 {
2934 /* read more */
2936 "%lu/%lu bytes of KX read. Rescheduling...\n",
2937 queue->cread_off, INITIAL_KX_SIZE);
2938 queue->read_task =
2940 return;
2941 }
2942 /* we got all the data, let's find out who we are talking to! */
2944 queue->cread_buf,
2945 queue);
2946 if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, queue->cread_buf))
2947 {
2949 "Invalid TCP KX received from %s\n",
2950 GNUNET_a2s (queue->address, queue->address_len));
2952 return;
2953 }
2954 if (0 !=
2955 memcmp (&tc.sender, &queue->target, sizeof(struct GNUNET_PeerIdentity)))
2956 {
2958 "Invalid sender in TCP KX received from %s\n",
2959 GNUNET_a2s (queue->address, queue->address_len));
2961 return;
2962 }
2963 send_challenge (tc.challenge, queue);
2964 queue->write_task =
2966 queue->sock,
2967 &queue_write,
2968 queue);
2969
2970 /* update queue timeout */
2971 queue->timeout =
2973 /* prepare to continue with regular read task immediately */
2974 memmove (queue->cread_buf,
2975 &queue->cread_buf[INITIAL_KX_SIZE],
2976 queue->cread_off - (INITIAL_KX_SIZE));
2978 "cread_off is %lu bytes before adjusting\n",
2979 queue->cread_off);
2980 queue->cread_off -= INITIAL_KX_SIZE;
2982 "cread_off set to %lu bytes\n",
2983 queue->cread_off);
2985}
2986
2987
2994static void
2995proto_read_kx (void *cls)
2996{
2997 struct ProtoQueue *pq = cls;
2998 ssize_t rcvd;
2999 struct GNUNET_TIME_Relative left;
3000 struct Queue *queue;
3001 struct TCPConfirmation tc;
3003
3004 pq->read_task = NULL;
3006 if (0 == left.rel_value_us)
3007 {
3008 free_proto_queue (pq);
3009 return;
3010 }
3011 rcvd = GNUNET_NETWORK_socket_recv (pq->sock,
3012 &pq->ibuf[pq->ibuf_off],
3013 sizeof(pq->ibuf) - pq->ibuf_off);
3015 "Proto received %lu bytes for KX\n", rcvd);
3016 if (-1 == rcvd)
3017 {
3018 if ((EAGAIN != errno) && (EINTR != errno))
3019 {
3021 free_proto_queue (pq);
3022 return;
3023 }
3024 /* try again */
3025 pq->read_task =
3027 return;
3028 }
3029 if (0 == rcvd)
3030 {
3031 /* Orderly shutdown of connection */
3033 "Socket for proto queue %p seems to have been closed\n", pq);
3034 free_proto_queue (pq);
3035 return;
3036 }
3037 pq->ibuf_off += rcvd;
3038 if (sizeof (struct TCPNATProbeMessage) == pq->ibuf_off)
3039 {
3040 struct TCPNATProbeMessage *pm = (struct TCPNATProbeMessage *) pq->ibuf;
3041
3043 &pm->clientIdentity);
3044
3045 queue = GNUNET_new (struct Queue);
3046 queue->target = pm->clientIdentity;
3049 }
3050 else if (pq->ibuf_off > sizeof(pq->ibuf))
3051 {
3052 /* read more */
3053 pq->read_task =
3055 return;
3056 }
3057 else
3058 {
3059 /* we got all the data, let's find out who we are talking to! */
3060 queue = GNUNET_new (struct Queue);
3062 queue);
3063 if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, pq->ibuf))
3064 {
3066 "Invalid TCP KX received from %s\n",
3067 GNUNET_a2s (pq->address, pq->address_len));
3068 gcry_cipher_close (queue->in_cipher);
3070 free_proto_queue (pq);
3071 return;
3072 }
3073 queue->target = tc.sender;
3076 }
3077 queue->address = pq->address; /* steals reference */
3078 queue->address_len = pq->address_len;
3079 queue->listen_sock = pq->listen_sock;
3080 queue->sock = pq->sock;
3081
3083 "created queue with target %s\n",
3084 GNUNET_i2s (&queue->target));
3085
3087 "start kx proto\n");
3088
3090 boot_queue (queue);
3091 queue->read_task =
3093 queue->sock,
3094 read_task,
3095 queue);
3096 queue->write_task =
3098 queue->sock,
3099 &queue_write,
3100 queue);
3101 // TODO To early! Move it somewhere else.
3102 // send_challenge (tc.challenge, queue);
3103 queue->challenge_received = tc.challenge;
3104
3106 GNUNET_free (pq);
3107}
3108
3109
3110static struct ProtoQueue *
3112 struct sockaddr *in,
3113 socklen_t addrlen)
3114{
3115 struct ProtoQueue *pq = GNUNET_new (struct ProtoQueue);
3116
3117 if (NULL == sock)
3118 {
3119 // sock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET, addr, addrlen);
3120 sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, 0);
3121 if (NULL == sock)
3122 {
3124 "socket(%d) failed: %s",
3125 in->sa_family,
3126 strerror (errno));
3127 GNUNET_free (in);
3128 GNUNET_free (pq);
3129 return NULL;
3130 }
3131 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, addrlen)) &&
3132 (errno != EINPROGRESS))
3133 {
3135 "connect to `%s' failed: %s",
3136 GNUNET_a2s (in, addrlen),
3137 strerror (errno));
3139 GNUNET_free (in);
3140 GNUNET_free (pq);
3141 return NULL;
3142 }
3143 }
3144 pq->address_len = addrlen;
3145 pq->address = in;
3147 pq->sock = sock;
3149 pq->sock,
3151 pq);
3153
3154 return pq;
3155}
3156
3157
3165static void
3166listen_cb (void *cls)
3167{
3168 struct sockaddr_storage in;
3169 socklen_t addrlen;
3170 struct GNUNET_NETWORK_Handle *sock;
3171 struct ListenTask *lt;
3172 struct sockaddr *in_addr;
3173
3175 "listen_cb\n");
3176
3177 lt = cls;
3178
3179 lt->listen_task = NULL;
3180 GNUNET_assert (NULL != lt->listen_sock);
3181 addrlen = sizeof(in);
3182 memset (&in, 0, sizeof(in));
3184 (struct sockaddr*) &in,
3185 &addrlen);
3186 if ((NULL == sock) && ((EMFILE == errno) || (ENFILE == errno)))
3187 return; /* system limit reached, wait until connection goes down */
3189 lt->listen_sock,
3190 &listen_cb,
3191 lt);
3192 if ((NULL == sock) && ((EAGAIN == errno) || (ENOBUFS == errno)))
3193 return;
3194 if (NULL == sock)
3195 {
3197 return;
3198 }
3199 in_addr = GNUNET_memdup (&in, addrlen);
3200 create_proto_queue (sock, in_addr, addrlen);
3201}
3202
3203
3204static void
3206 const struct sockaddr *addr,
3207 socklen_t addrlen)
3208{
3209 (void) cls;
3210 struct TCPNATProbeMessage pm;
3211 struct ProtoQueue *pq;
3212 struct sockaddr *in_addr;
3213
3215 "addr->sa_family %d\n",
3216 addr->sa_family);
3218 "Try to connect back\n");
3219 in_addr = GNUNET_memdup (addr, addrlen);
3221 "in_addr->sa_family %d\n",
3222 in_addr->sa_family);
3223 pq = create_proto_queue (NULL, in_addr, addrlen);
3224 if (NULL != pq)
3225 {
3226 pm.header.size = htons (sizeof(struct TCPNATProbeMessage));
3227 pm.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE);
3228 pm.clientIdentity = my_identity;
3229 memcpy (pq->write_buf, &pm, sizeof(struct TCPNATProbeMessage));
3230 pq->write_off = sizeof(struct TCPNATProbeMessage);
3232 pq->sock,
3234 pq);
3235 }
3236 else
3237 {
3239 "Couldn't create ProtoQueue for sending TCPNATProbeMessage\n");
3240 }
3241}
3242
3243
3244static void
3246{
3247 struct sockaddr *in = cls;
3248 struct PendingReversal *pending_reversal;
3249 struct GNUNET_HashCode key;
3250
3252 sizeof(struct sockaddr),
3253 &key);
3255 &key);
3256
3257 GNUNET_assert (NULL != pending_reversal);
3258
3260 &key,
3261 pending_reversal))
3263 "No pending reversal found for address %s\n",
3264 GNUNET_a2s (in, sizeof (struct sockaddr)));
3265 GNUNET_free (pending_reversal->in);
3266 GNUNET_free (pending_reversal);
3267}
3268
3269
3288static int
3289mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
3290{
3291 struct sockaddr *in;
3292 socklen_t in_len = 0;
3293 const char *path;
3294 struct sockaddr_in *v4;
3295 struct sockaddr_in6 *v6;
3296 unsigned int is_natd = GNUNET_NO;
3297 struct GNUNET_HashCode key;
3298
3300 "Connecting to %s at %s\n",
3301 GNUNET_i2s (peer),
3302 address);
3303 if (0 != strncmp (address,
3305 strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
3306 {
3307 GNUNET_break_op (0);
3308 return GNUNET_SYSERR;
3309 }
3310 path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
3311 in = tcp_address_to_sockaddr (path, &in_len);
3312
3313 if (NULL == in)
3314 {
3316 "Failed to setup TCP socket address\n");
3317 return GNUNET_SYSERR;
3318 }
3319
3321 "in %s\n",
3322 GNUNET_a2s (in, in_len));
3323
3324 switch (in->sa_family)
3325 {
3326 case AF_INET:
3327 v4 = (struct sockaddr_in *) in;
3328 if (0 == v4->sin_port)
3329 {
3330 is_natd = GNUNET_YES;
3332 sizeof(struct sockaddr),
3333 &key);
3336 &key))
3337 {
3339 "There is already a request reversal for `%s'at `%s'\n",
3340 GNUNET_i2s (peer),
3341 address);
3342 GNUNET_free (in);
3343 return GNUNET_SYSERR;
3344 }
3345 }
3346 break;
3347
3348 case AF_INET6:
3349 v6 = (struct sockaddr_in6 *) in;
3350 if (0 == v6->sin6_port)
3351 {
3353 "Request reversal for `%s' at `%s' not possible for an IPv6 address\n",
3354 GNUNET_i2s (peer),
3355 address);
3356 GNUNET_free (in);
3357 return GNUNET_SYSERR;
3358 }
3359 break;
3360
3361 default:
3362 GNUNET_assert (0);
3363 }
3364
3365 if (GNUNET_YES == is_natd)
3366 {
3367 struct sockaddr_in local_sa;
3368 struct PendingReversal *pending_reversal;
3369
3370 memset (&local_sa, 0, sizeof(local_sa));
3371 local_sa.sin_family = AF_INET;
3372 local_sa.sin_port = htons (bind_port);
3373 /* We leave sin_address at 0, let the kernel figure it out,
3374 even if our bind() is more specific. (May want to reconsider
3375 later.) */
3376 if (GNUNET_OK != GNUNET_NAT_request_reversal (nat, &local_sa, v4))
3377 {
3379 "request reversal for `%s' at `%s' failed\n",
3380 GNUNET_i2s (peer),
3381 address);
3382 GNUNET_free (in);
3383 return GNUNET_SYSERR;
3384 }
3385 pending_reversal = GNUNET_new (struct PendingReversal);
3386 pending_reversal->in = in;
3389 &key,
3390 pending_reversal,
3392 pending_reversal->target = *peer;
3394 &
3396 in);
3398 "Created NAT WAIT connection to `%s' at `%s'\n",
3399 GNUNET_i2s (peer),
3400 GNUNET_a2s (in, sizeof (struct sockaddr)));
3401 }
3402 else
3403 {
3404 struct GNUNET_NETWORK_Handle *sock;
3405 struct Queue *queue;
3406
3407 sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM,
3408 IPPROTO_TCP);
3409 if (NULL == sock)
3410 {
3412 "socket(%d) failed: %s",
3413 in->sa_family,
3414 strerror (errno));
3415 GNUNET_free (in);
3416 return GNUNET_SYSERR;
3417 }
3418 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, in_len)) &&
3419 (errno != EINPROGRESS))
3420 {
3422 "connect to `%s' failed: %s",
3423 address,
3424 strerror (errno));
3426 GNUNET_free (in);
3427 return GNUNET_SYSERR;
3428 }
3429
3430 queue = GNUNET_new (struct Queue);
3431 queue->target = *peer;
3432 queue->address = in;
3433 queue->address_len = in_len;
3434 queue->sock = sock;
3436 boot_queue (queue);
3438 "booted queue with target %s\n",
3439 GNUNET_i2s (&queue->target));
3440 // queue->mq_awaits_continue = GNUNET_YES;
3441 queue->read_task =
3443 queue->sock,
3445 queue);
3446
3447
3449 "start kx mq_init\n");
3450
3452 queue->write_task =
3454 queue->sock,
3455 &queue_write,
3456 queue);
3457 }
3458
3459 return GNUNET_OK;
3460}
3461
3462
3471static int
3473 const struct GNUNET_HashCode *key,
3474 void *value)
3475{
3476 struct ListenTask *lt = value;
3477
3478 (void) cls;
3479 (void) key;
3480 if (NULL != lt->listen_task)
3481 {
3483 lt->listen_task = NULL;
3484 }
3485 if (NULL != lt->listen_sock)
3486 {
3488 lt->listen_sock = NULL;
3489 }
3490 GNUNET_free (lt);
3491 return GNUNET_OK;
3492}
3493
3494
3503static int
3505 const struct GNUNET_PeerIdentity *target,
3506 void *value)
3507{
3508 struct Queue *queue = value;
3509
3510 (void) cls;
3511 (void) target;
3513 return GNUNET_OK;
3514}
3515
3516
3522static void
3523do_shutdown (void *cls)
3524{
3526 "Shutdown %s!\n",
3527 shutdown_running ? "running" : "not running");
3528
3530 return;
3531 else
3533
3534 while (NULL != proto_head)
3536 if (NULL != nat)
3537 {
3539 nat = NULL;
3540 }
3548 if (NULL != ch)
3549 {
3552 ch = NULL;
3553 }
3554 if (NULL != stats)
3555 {
3557 stats = NULL;
3558 }
3559 if (NULL != my_private_key)
3560 {
3562 my_private_key = NULL;
3563 }
3564 if (NULL != is)
3565 {
3567 is = NULL;
3568 }
3569 if (NULL != peerstore)
3570 {
3572 peerstore = NULL;
3573 }
3574 if (NULL != resolve_request_handle)
3575 {
3578 }
3580 "Shutdown done!\n");
3581}
3582
3583
3595static void
3596enc_notify_cb (void *cls,
3597 const struct GNUNET_PeerIdentity *sender,
3598 const struct GNUNET_MessageHeader *msg)
3599{
3600 (void) cls;
3601 (void) sender;
3602 (void) msg;
3603 GNUNET_break_op (0);
3604}
3605
3606
3620static void
3622 void **app_ctx,
3623 int add_remove,
3625 const struct sockaddr *addr,
3626 socklen_t addrlen)
3627{
3628 char *my_addr;
3630
3632 "nat address cb %s %s\n",
3633 add_remove ? "add" : "remove",
3634 GNUNET_a2s (addr, addrlen));
3635
3636 if (GNUNET_YES == add_remove)
3637 {
3639
3640 GNUNET_asprintf (&my_addr,
3641 "%s-%s",
3643 GNUNET_a2s (addr, addrlen));
3644 nt = GNUNET_NT_scanner_get_type (is, addr, addrlen);
3645 ai =
3647 my_addr,
3648 nt,
3650 GNUNET_free (my_addr);
3651 *app_ctx = ai;
3652 }
3653 else
3654 {
3655 ai = *app_ctx;
3657 *app_ctx = NULL;
3658 }
3659}
3660
3661
3665static void
3666add_addr (struct sockaddr *in, socklen_t in_len)
3667{
3668
3669 struct Addresses *saddrs;
3670
3672 "add address %s\n",
3673 GNUNET_a2s (in, in_len));
3674
3675 saddrs = GNUNET_new (struct Addresses);
3676 saddrs->addr = in;
3677 saddrs->addr_len = in_len;
3679
3681 "after add address %s\n",
3682 GNUNET_a2s (in, in_len));
3683
3685 "add address %s\n",
3686 GNUNET_a2s (saddrs->addr, saddrs->addr_len));
3687
3688 addrs_lens++;
3689}
3690
3691
3699static int
3700init_socket (struct sockaddr *addr,
3701 socklen_t in_len)
3702{
3703 struct sockaddr_storage in_sto;
3704 socklen_t sto_len;
3705 struct GNUNET_NETWORK_Handle *listen_sock;
3706 struct ListenTask *lt;
3707 int sockfd;
3708 struct GNUNET_HashCode h_sock;
3709
3710 if (NULL == addr)
3711 {
3713 "Address is NULL.\n");
3714 return GNUNET_SYSERR;
3715 }
3716
3718 "address %s\n",
3719 GNUNET_a2s (addr, in_len));
3720
3721 listen_sock =
3722 GNUNET_NETWORK_socket_create (addr->sa_family, SOCK_STREAM, IPPROTO_TCP);
3723 if (NULL == listen_sock)
3724 {
3726 return GNUNET_SYSERR;
3727 }
3728
3729 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (listen_sock, addr, in_len))
3730 {
3732 GNUNET_NETWORK_socket_close (listen_sock);
3733 listen_sock = NULL;
3734 return GNUNET_SYSERR;
3735 }
3736
3737 if (GNUNET_OK !=
3738 GNUNET_NETWORK_socket_listen (listen_sock,
3739 5))
3740 {
3742 "listen");
3743 GNUNET_NETWORK_socket_close (listen_sock);
3744 listen_sock = NULL;
3745 return GNUNET_SYSERR;
3746 }
3747
3748 /* We might have bound to port 0, allowing the OS to figure it out;
3749 thus, get the real IN-address from the socket */
3750 sto_len = sizeof(in_sto);
3751
3752 if (0 != getsockname (GNUNET_NETWORK_get_fd (listen_sock),
3753 (struct sockaddr *) &in_sto,
3754 &sto_len))
3755 {
3756 memcpy (&in_sto, addr, in_len);
3757 sto_len = in_len;
3758 }
3759
3760 // addr = (struct sockaddr *) &in_sto;
3761 in_len = sto_len;
3763 "Bound to `%s'\n",
3764 GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len));
3765 stats = GNUNET_STATISTICS_create ("C-TCP", cfg);
3766
3767 if (NULL == is)
3769
3770 if (NULL == my_private_key)
3772 if (NULL == my_private_key)
3773 {
3774 GNUNET_log (
3776 _ (
3777 "Transport service is lacking key configuration settings. Exiting.\n"));
3778 if (NULL != resolve_request_handle)
3781 return GNUNET_SYSERR;
3782 }
3784 /* start listening */
3785
3786 lt = GNUNET_new (struct ListenTask);
3787 lt->listen_sock = listen_sock;
3788
3790 listen_sock,
3791 &listen_cb,
3792 lt);
3793
3795 "creating hash\n");
3796 sockfd = GNUNET_NETWORK_get_fd (lt->listen_sock);
3797 GNUNET_CRYPTO_hash (&sockfd,
3798 sizeof(int),
3799 &h_sock);
3800
3802 "creating map\n");
3803 if (NULL == lt_map)
3805
3807 "creating map entry\n");
3810 &h_sock,
3811 lt,
3813
3815 "map entry created\n");
3816
3817 if (NULL == queue_map)
3819
3820 if (NULL == ch)
3825 &mq_init,
3826 NULL,
3828 NULL);
3829
3830 if (NULL == ch)
3831 {
3832 GNUNET_break (0);
3833 if (NULL != resolve_request_handle)
3836 return GNUNET_SYSERR;
3837 }
3838
3839 add_addr (addr, in_len);
3840 return GNUNET_OK;
3841
3842}
3843
3844
3848static void
3850{
3851 struct sockaddr **saddrs;
3852 socklen_t *saddr_lens;
3853 int i;
3854 size_t len;
3855
3857 "starting nat register!\n");
3858 len = 0;
3859 i = 0;
3860 saddrs = GNUNET_malloc ((addrs_lens) * sizeof(struct sockaddr *));
3861 saddr_lens = GNUNET_malloc ((addrs_lens) * sizeof(socklen_t));
3862 for (struct Addresses *pos = addrs_head; NULL != pos; pos = pos->next)
3863 {
3865 "registering address %s\n",
3867
3868 saddr_lens[i] = addrs_head->addr_len;
3869 len += saddr_lens[i];
3870 saddrs[i] = GNUNET_memdup (addrs_head->addr, saddr_lens[i]);
3871 i++;
3872 }
3873
3875 "registering addresses %lu %lu %lu %lu\n",
3876 (addrs_lens) * sizeof(struct sockaddr *),
3877 (addrs_lens) * sizeof(socklen_t),
3878 len,
3882 IPPROTO_TCP,
3883 addrs_lens,
3884 (const struct sockaddr **) saddrs,
3885 saddr_lens,
3888 NULL /* closure */);
3889 for (i = addrs_lens - 1; i >= 0; i--)
3890 GNUNET_free (saddrs[i]);
3891 GNUNET_free (saddrs);
3892 GNUNET_free (saddr_lens);
3893
3894 if (NULL == nat)
3895 {
3896 GNUNET_break (0);
3897 if (NULL != resolve_request_handle)
3900 }
3901}
3902
3903
3911static void
3913 const struct sockaddr *addr,
3914 socklen_t in_len)
3915{
3916 struct sockaddr_in *v4;
3917 struct sockaddr_in6 *v6;
3918 struct sockaddr *in;
3919
3920 (void) cls;
3921 if (NULL != addr)
3922 {
3923 if (AF_INET == addr->sa_family)
3924 {
3925 v4 = (struct sockaddr_in *) addr;
3926 in = tcp_address_to_sockaddr_numeric_v4 (&in_len, *v4, bind_port);// _global);
3927 }
3928 else if (AF_INET6 == addr->sa_family)
3929 {
3930 v6 = (struct sockaddr_in6 *) addr;
3931 in = tcp_address_to_sockaddr_numeric_v6 (&in_len, *v6, bind_port);// _global);
3932 }
3933 else
3934 {
3936 "Address family %u not suitable (not AF_INET %u nor AF_INET6 %u \n",
3937 addr->sa_family,
3938 AF_INET,
3939 AF_INET6);
3940 return;
3941 }
3942 init_socket (in, in_len);
3943 }
3944 else
3945 {
3947 "Address is NULL. This might be an error or the resolver finished resolving.\n");
3948 if (NULL == addrs_head)
3949 {
3951 "Resolver finished resolving, but we do not listen to an address!.\n");
3952 return;
3953 }
3954 nat_register ();
3955 }
3956}
3957
3958
3967static void
3968run (void *cls,
3969 char *const *args,
3970 const char *cfgfile,
3971 const struct GNUNET_CONFIGURATION_Handle *c)
3972{
3973 char *bindto;
3974 struct sockaddr *in;
3975 socklen_t in_len;
3976 struct sockaddr_in v4;
3977 struct sockaddr_in6 v6;
3978 char *start;
3979 unsigned int port;
3980 char dummy[2];
3981 char *rest = NULL;
3982 struct PortOnlyIpv4Ipv6 *po;
3983 socklen_t addr_len_ipv4;
3984 socklen_t addr_len_ipv6;
3985
3986 (void) cls;
3987
3989 memset (&v4,0,sizeof(struct sockaddr_in));
3990 memset (&v6,0,sizeof(struct sockaddr_in6));
3991 cfg = c;
3992 if (GNUNET_OK !=
3995 "BINDTO",
3996 &bindto))
3997 {
4000 "BINDTO");
4001 return;
4002 }
4003 if (GNUNET_OK !=
4006 "MAX_QUEUE_LENGTH",
4009 if (GNUNET_OK !=
4012 "REKEY_INTERVAL",
4015
4017 if (NULL == peerstore)
4018 {
4019 GNUNET_free (bindto);
4020 GNUNET_break (0);
4022 return;
4023 }
4024
4026
4027 if (1 == sscanf (bindto, "%u%1s", &bind_port, dummy))
4028 {
4032 "address po %s\n",
4034 if (NULL != po->addr_ipv4)
4035 {
4037 }
4038 if (NULL != po->addr_ipv6)
4039 {
4042 }
4043 GNUNET_free (po);
4044 nat_register ();
4045 GNUNET_free (bindto);
4046 return;
4047 }
4048
4049 start = extract_address (bindto);
4050 // FIXME: check for NULL == start...
4051 if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
4052 {
4053 bind_port = extract_port (bindto);
4054
4056 init_socket (in, in_len);
4057 nat_register ();
4059 GNUNET_free (bindto);
4060 return;
4061 }
4062
4063 if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
4064 {
4065 bind_port = extract_port (bindto);
4067 init_socket (in, in_len);
4068 nat_register ();
4070 GNUNET_free (bindto);
4071 return;
4072 }
4073
4074 bind_port = extract_port (bindto);
4076 ":",
4077 &rest),
4078 AF_UNSPEC,
4081 &port);
4082
4083 GNUNET_free (bindto);
4085}
4086
4087
4095int
4096main (int argc, char *const *argv)
4097{
4098 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
4100 };
4101 int ret;
4102
4104 "Starting tcp communicator\n");
4105 if (GNUNET_OK !=
4106 GNUNET_STRINGS_get_utf8_args (argc, argv,
4107 &argc, &argv))
4108 return 2;
4109
4110 ret = (GNUNET_OK ==
4111 GNUNET_PROGRAM_run (argc,
4112 argv,
4113 "gnunet-communicator-tcp",
4114 _ ("GNUnet TCP communicator"),
4115 options,
4116 &run,
4117 NULL))
4118 ? 0
4119 : 1;
4120 GNUNET_free_nz ((void *) argv);
4121 return ret;
4122}
4123
4124
4125/* end of gnunet-communicator-tcp.c */
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
static int ret
Final status code.
Definition: gnunet-arm.c:94
static uint16_t port
Port number.
Definition: gnunet-bcd.c:147
static void calculate_hmac(struct GNUNET_HashCode *hmac_secret, const void *buf, size_t buf_size, struct GNUNET_ShortHashCode *smac)
Compute mac over buf, and ratched the hmac_secret.
static void queue_finish(struct Queue *queue)
Append a 'finish' message to the outgoing transmission.
static struct GNUNET_CONTAINER_MultiPeerMap * queue_map
Queues (map from peer identity to struct Queue)
static void boot_queue(struct Queue *queue)
Add the given queue to our internal data structure.
unsigned int bind_port
The port the communicator should be assigned to.
struct ListenTask * lts_tail
Head of DLL with ListenTask.
static size_t try_handle_plaintext(struct Queue *queue)
Test if we have received a full message in plaintext.
static void pass_plaintext_to_core(struct Queue *queue, const void *plaintext, size_t plaintext_len)
We received plaintext_len bytes of plaintext on queue.
static struct sockaddr * tcp_address_to_sockaddr_numeric_v6(socklen_t *sock_len, struct sockaddr_in6 v6, unsigned int port)
Convert a struct sockaddr_in6 to astruct sockaddr *`.
static struct GNUNET_PeerIdentity my_identity
Our public key.
static int get_queue_delete_it(void *cls, const struct GNUNET_PeerIdentity *target, void *value)
Iterator over all message queues to clean up.
#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 *
#define INITIAL_CORE_KX_SIZE
Size of the initial core key exchange messages.
static void do_rekey(struct Queue *queue, const struct TCPRekey *rekey)
Handle rekey message on queue.
static struct ProtoQueue * create_proto_queue(struct GNUNET_NETWORK_Handle *sock, struct sockaddr *in, socklen_t addrlen)
static int init_socket(struct sockaddr *addr, socklen_t in_len)
This method launch network interactions for each address we like to bind to.
static void try_connection_reversal(void *cls, const struct sockaddr *addr, socklen_t addrlen)
static 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 void setup_out_cipher(struct Queue *queue, struct GNUNET_HashCode *dh)
Setup cipher for outgoing data stream based on target and our ephemeral private key.
struct GNUNET_CONTAINER_MultiHashMap * pending_reversals
Map of pending reversals.
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
static void queue_destroy(struct Queue *queue)
Functions with this signature are called whenever we need to close a queue due to a disconnect or fai...
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static void enc_notify_cb(void *cls, const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *msg)
Function called when the transport service has received an acknowledgement for this communicator (!...
static void handshake_ack_monotime_store_cb(void *cls, int success)
Callback called when peerstore store operation for handshake ack monotime value is finished.
static struct GNUNET_PEERSTORE_Handle * peerstore
Database for peer's HELLOs.
static int pending_reversals_delete_it(void *cls, const struct GNUNET_HashCode *key, void *value)
static struct ProtoQueue * proto_tail
Protoqueues DLL tail.
static void queue_read_kx(void *cls)
Read from the socket of the queue until we have enough data to initialize the decryption logic and ca...
static int get_lt_delete_it(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator over all ListenTasks to clean up.
static void inject_rekey(struct Queue *queue)
Inject a struct TCPRekey message into the queue's plaintext buffer.
static struct GNUNET_TIME_Relative rekey_interval
The rekey interval.
#define NAT_TIMEOUT
How long until we give up on establishing an NAT connection? Must be > 4 RTT.
#define BUF_SIZE
Size of our IO buffers for ciphertext data.
static void do_shutdown(void *cls)
Shutdown the UNIX communicator.
#define COMMUNICATOR_CONFIG_SECTION
Configuration section used by the communicator.
static 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.
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.
struct ListenTask * lts_head
Head of DLL with ListenTasks.
static struct GNUNET_NAT_Handle * nat
Connection to NAT service.
static void pending_reversal_timeout(void *cls)
#define PROTO_QUEUE_TIMEOUT
How long do we wait until we must have received the initial KX?
static void queue_read(void *cls)
Queue read task.
#define REKEY_MAX_BYTES
How often do we rekey based on number of bytes transmitted? (additionally randomized).
static 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 setup_cipher(const struct GNUNET_HashCode *dh, const struct GNUNET_PeerIdentity *pid, gcry_cipher_hd_t *cipher, struct GNUNET_HashCode *hmac_key)
Setup cipher based on shared secret dh and decrypting peer pid.
static void 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 void setup_in_cipher(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, struct Queue *queue)
Setup cipher of queue for decryption.
int shutdown_running
A flag indicating we are already doing a shutdown.
static void transmit_kx(struct Queue *queue, const struct GNUNET_CRYPTO_EcdhePublicKey *epub)
Generate and transmit our ephemeral key and the signature for the initial KX with the other peer.
static int decrypt_and_check_tc(struct Queue *queue, struct TCPConfirmation *tc, char *ibuf)
We have received the first bytes from the other side on a queue.
#define DEFAULT_REKEY_INTERVAL
How often do we rekey based on time (at least)
int main(int argc, char *const *argv)
The main function for the UNIX communicator.
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Our private key.
static void queue_write(void *cls)
We have been notified that our socket is ready to write.
static void add_addr(struct sockaddr *in, socklen_t in_len)
This method adds addresses to the DLL, that are later register at the NAT service.
static void handshake_monotime_cb(void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE w...
struct Addresses * addrs_head
Head of DLL with addresses we like to register at NAT servcie.
static struct sockaddr * tcp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
Convert TCP bind specification to a struct sockaddr *
struct Addresses * addrs_tail
Head of DLL with addresses we like to register at NAT servcie.
#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 void start_initial_kx_out(struct Queue *queue)
Initialize our key material for outgoing transmissions and inform the other peer about it.
static void free_proto_queue(struct ProtoQueue *pq)
Closes socket and frees memory associated with pq.
static struct GNUNET_CONTAINER_MultiHashMap * lt_map
ListenTasks (map from socket to struct ListenTask)
static void core_read_finished_cb(void *cls, int success)
Core tells us it is done processing a message that transport received on a queue with status success.
static 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_SCHEDULER_Task * read_task
static char * res
Currently read line or NULL on EOF.
static char * value
Value of the record to add/remove.
static uint32_t type
Type string converted to DNS type value.
static struct GNUNET_NAT_AUTO_Test * nt
Handle to a NAT test operation.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
static struct GNUNET_TRANSPORT_PluginMonitor * pm
Handle if we are monitoring plugin session activity.
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
Core service; the main API for encrypted P2P communications.
API to the peerstore service.
Constants for network protocols.
Functions related to doing DNS lookups.
API to create, modify and access statistics.
API of the transport service towards the communicator processes.
void GNUNET_TRANSPORT_communicator_address_remove(struct GNUNET_TRANSPORT_AddressIdentifier *ai)
Notify transport service about an address that this communicator no longer provides for this peer.
int GNUNET_TRANSPORT_communicator_receive(struct GNUNET_TRANSPORT_CommunicatorHandle *handle, const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *msg, struct GNUNET_TIME_Relative expected_addr_validity, GNUNET_TRANSPORT_MessageCompletedCallback cb, void *cb_cls)
Notify transport service that the communicator has received a message.
void GNUNET_TRANSPORT_communicator_mq_del(struct GNUNET_TRANSPORT_QueueHandle *qh)
Notify transport service that an MQ became unavailable due to a disconnect or timeout.
#define GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED
Queue length.
struct GNUNET_TRANSPORT_QueueHandle * GNUNET_TRANSPORT_communicator_mq_add(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const struct GNUNET_PeerIdentity *peer, const char *address, uint32_t mtu, uint64_t q_len, uint32_t priority, enum GNUNET_NetworkType nt, enum GNUNET_TRANSPORT_ConnectionStatus cs, struct GNUNET_MQ_Handle *mq)
Notify transport service that a MQ became available due to an "inbound" connection or because the com...
void GNUNET_TRANSPORT_communicator_disconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
Disconnect from the transport service.
struct GNUNET_TRANSPORT_CommunicatorHandle * GNUNET_TRANSPORT_communicator_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *config_section_name, const char *addr_prefix, enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, GNUNET_TRANSPORT_CommunicatorMqInit mq_init, void *mq_init_cls, GNUNET_TRANSPORT_CommunicatorNotify notify_cb, void *notify_cb_cls)
Connect to the transport service.
GNUNET_TRANSPORT_ConnectionStatus
Possible states of a connection.
struct GNUNET_TRANSPORT_AddressIdentifier * GNUNET_TRANSPORT_communicator_address_add(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const char *address, enum GNUNET_NetworkType nt, struct GNUNET_TIME_Relative expiration)
Notify transport service about an address that this communicator provides for this peer.
void GNUNET_TRANSPORT_communicator_address_remove_all(struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
Notify transport service that this communicator no longer provides all its addresses for this peer.
@ GNUNET_TRANSPORT_CC_RELIABLE
Transmission is reliabile (with ACKs), e.g.
@ GNUNET_TRANSPORT_CS_INBOUND
this is an inbound connection (communicator initiated)
@ GNUNET_TRANSPORT_CS_OUTBOUND
this is an outbound connection (transport initiated)
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_time(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, struct GNUNET_TIME_Relative *time)
Get a configuration value that should be a relative time.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don't receive messages from the peer?
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Generate a random unsigned 64-bit value.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_kem_decaps(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *c, struct GNUNET_HashCode *key_material)
Decapsulate a key for a private EdDSA key.
Definition: crypto_ecc.c:749
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:198
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_kem_encaps(const struct GNUNET_CRYPTO_EddsaPublicKey *pub, struct GNUNET_CRYPTO_EcdhePublicKey *c, struct GNUNET_HashCode *key_material)
Encapsulate key material for a EdDSA public key.
Definition: crypto_ecc.c:794
#define GNUNET_CRYPTO_eddsa_sign(priv, ps, sig)
EdDSA sign a given block.
#define GNUNET_CRYPTO_eddsa_verify(purp, ps, sig, pub)
Verify EdDSA signature.
struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_CRYPTO_eddsa_key_create_from_configuration(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create a new private key by reading our peer's key from the file specified in the configuration.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
@ GNUNET_CRYPTO_QUALITY_NONCE
Randomness for IVs etc.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_kdf(void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
Derive key.
Definition: crypto_kdf.c:70
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_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash 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.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in 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.
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.
struct GNUNET_CONTAINER_MultiPeerMap * GNUNET_CONTAINER_multipeermap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the 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.
#define GNUNET_log(kind,...)
#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.
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_MIN(a, b)
void GNUNET_CRYPTO_hmac_raw(const void *key, size_t key_len, const void *plaintext, size_t plaintext_len, struct GNUNET_HashCode *hmac)
Calculate HMAC of a message (RFC 2104) TODO: Shouldn't this be the standard hmac function and the abo...
Definition: crypto_hash.c:300
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
const char * GNUNET_e2s(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key value to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages).
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
const char * GNUNET_p2s(const struct GNUNET_CRYPTO_EddsaPublicKey *p)
Convert a public key value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_free_nz(ptr)
Wrapper around free.
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
GNUNET_MQ_Error
Error codes for the queue.
struct GNUNET_MQ_Handle * GNUNET_MQ_queue_for_callbacks(GNUNET_MQ_SendImpl send, GNUNET_MQ_DestroyImpl destroy, GNUNET_MQ_CancelImpl cancel, void *impl_state, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *cls)
Create a message queue for the specified handlers.
Definition: mq.c:465
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:421
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:646
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:674
GNUNET_NAT_AddressClass
Some addresses contain sensitive information or are not suitable for global distribution.
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_accept(const struct GNUNET_NETWORK_Handle *desc, struct sockaddr *address, socklen_t *address_len)
Accept a new connection on a socket.
Definition: network.c:392
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:508
int GNUNET_NETWORK_get_fd(const struct GNUNET_NETWORK_Handle *desc)
Return file descriptor for this network handle.
Definition: network.c:1000
ssize_t GNUNET_NETWORK_socket_recv(const struct GNUNET_NETWORK_Handle *desc, void *buffer, size_t length)
Read data from a connected socket (always non-blocking).
Definition: network.c:716
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition: network.c:832
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_connect(const struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Connect a socket to some remote address.
Definition: network.c:601
ssize_t GNUNET_NETWORK_socket_send(const struct GNUNET_NETWORK_Handle *desc, const void *buffer, size_t length)
Send data (always non-blocking).
Definition: network.c:737
enum GNUNET_GenericReturnValue GNUNET_NETWORK_test_pf(int pf)
Test if the given protocol family is supported by this system.
Definition: network.c:79
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_bind(struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Bind a socket to a particular address.
Definition: network.c:439
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_listen(const struct GNUNET_NETWORK_Handle *desc, int backlog)
Listen on a socket.
Definition: network.c:651
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:44
void GNUNET_NT_scanner_done(struct GNUNET_NT_InterfaceScanner *is)
Terminate interface scanner.
Definition: nt.c:426
struct GNUNET_NT_InterfaceScanner * GNUNET_NT_scanner_init(void)
Initialize the address characterization client handle.
Definition: nt.c:405
enum GNUNET_NetworkType GNUNET_NT_scanner_get_type(struct GNUNET_NT_InterfaceScanner *is, const struct sockaddr *addr, socklen_t addrlen)
Returns where the address is located: loopback, LAN or WAN.
Definition: nt.c:307
struct GNUNET_PEERSTORE_IterateContext * GNUNET_PEERSTORE_iteration_start(struct GNUNET_PEERSTORE_Handle *h, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, GNUNET_PEERSTORE_Processor callback, void *callback_cls)
Iterate over peerstore entries.
void GNUNET_PEERSTORE_iteration_next(struct GNUNET_PEERSTORE_IterateContext *ic, uint64_t limit)
Continue an iteration.
void GNUNET_PEERSTORE_store_cancel(struct GNUNET_PEERSTORE_StoreContext *sc)
Cancel a store request.
void GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h)
Disconnect from the PEERSTORE service.
struct GNUNET_PEERSTORE_Handle * GNUNET_PEERSTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the PEERSTORE service.
#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE
Key used to store sender's monotonic time from handshake message.
struct GNUNET_PEERSTORE_StoreContext * GNUNET_PEERSTORE_store(struct GNUNET_PEERSTORE_Handle *h, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, const void *value, size_t size, struct GNUNET_TIME_Absolute expiry, enum GNUNET_PEERSTORE_StoreOption options, GNUNET_PEERSTORE_Continuation cont, void *cont_cls)
Store a new entry in the PEERSTORE.
#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK
Key used to store sender's monotonic time from handshake ack message.
#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY
Key used to store sender's monotonic time from rekey message.
void GNUNET_PEERSTORE_iteration_stop(struct GNUNET_PEERSTORE_IterateContext *ic)
Cancel an iteration.
@ GNUNET_PEERSTORE_STOREOPTION_REPLACE
Delete any previous values for the given key before storing the given value.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition: program.c:400
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_CONFIRMATION_ACK
TCP communicator confirmation ack.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE
TCP NAT probe message, send from NAT'd peer to other peer to establish bi-directional communication.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH
TCP communicator end of stream.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX
TCP communicator payload box.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY
TCP communicator rekey message.
struct GNUNET_RESOLVER_RequestHandle * GNUNET_RESOLVER_ip_get(const char *hostname, int af, struct GNUNET_TIME_Relative timeout, GNUNET_RESOLVER_AddressCallback callback, void *callback_cls)
Convert a string to one or more IP addresses.
Definition: resolver_api.c:940
void GNUNET_RESOLVER_request_cancel(struct GNUNET_RESOLVER_RequestHandle *rh)
Cancel a request that is still pending with the resolver.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:562
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:1506
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:1577
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:1334
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975
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:1299
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:1272
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1230
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:405
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:570
#define GNUNET_TIME_UNIT_MINUTES
One minute.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:737
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:316
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_monotonic(const struct GNUNET_CONFIGURATION_Handle *cfg)
Obtain the current time and make sure it is monotonically increasing.
Definition: time.c:860
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:638
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:617
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
#define max(x, y)
static unsigned int size
Size of the "table".
Definition: peer.c:68
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition: scheduler.c:431
#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE_ACK
Signature by a peer sending back the nonce received at initial handshake.
#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_REKEY
Signature used by TCP communicator rekey.
#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE
Signature used by TCP communicator handshake.
DLL to store the addresses we like to register at NAT service.
struct Addresses * next
Kept in a DLL.
struct Addresses * prev
Kept in a DLL.
struct sockaddr * addr
Address we like to register at NAT service.
socklen_t addr_len
Length of address we like to register at NAT service.
Internal representation of the hash map.
Internal representation of the hash map.
Type of a nonce used for challenges.
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
Private ECC key encoded for transmission.
an ECC signature using EdDSA.
Definition of a command line option.
A 512-bit hashcode.
Handle to a message queue.
Definition: mq.c:87
Header for all communications.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
Handle for active NAT registrations.
Definition: nat_api.c:72
handle to a socket
Definition: network.c:53
Handle to the interface scanner.
Definition: nt.c:104
Handle to the PEERSTORE service.
Definition: peerstore_api.c:46
Context for a iterate request.
Single PEERSTORE record.
Context for a store request.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Handle to a request given to the resolver.
Definition: resolver_api.c:104
Entry in list of pending tasks.
Definition: scheduler.c:136
Handle for the service.
A 256-bit hashcode.
Time for absolute time used by GNUnet, in microseconds and in network byte order.
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
Internal representation of an address a communicator is currently providing for the transport service...
Opaque handle to the transport service for communicators.
Handle returned to identify the internal data structure the transport API has created to manage a mes...
Struct to use as closure.
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
struct GNUNET_SCHEDULER_Task * listen_task
ID of listen task.
Struct for pending nat reversals.
struct sockaddr * in
Address the reversal was send to.
struct GNUNET_SCHEDULER_Task * timeout_task
struct GNUNET_PeerIdentity target
To whom are we like to talk to.
In case of port only configuration we like to bind to ipv4 and ipv6 addresses.
struct sockaddr * addr_ipv4
Ipv4 address we like to bind to.
struct sockaddr * addr_ipv6
Ipv6 address we like to bind to.
socklen_t addr_len_ipv6
Length of ipv6 address.
socklen_t addr_len_ipv4
Length of ipv4 address.
Handle for an incoming connection where we do not yet have enough information to setup a full queue.
socklen_t address_len
Length of the address.
struct GNUNET_SCHEDULER_Task * write_task
ID of write task for this connection.
char write_buf[sizeof(struct TCPNATProbeMessage)]
buffer for writing struct TCPNATProbeMessage to network.
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
size_t ibuf_off
Current offset for reading into ibuf.
struct GNUNET_TIME_Absolute timeout
Timeout for this protoqueue.
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
struct sockaddr * address
Address of the other peer.
struct ProtoQueue * prev
Kept in a DLL.
char ibuf[(sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)+sizeof(struct TCPConfirmation))]
Buffer for reading all the information we need to upgrade from protoqueue to queue.
size_t write_off
Offset of the buffer?
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
struct ProtoQueue * next
Kept in a DLL.
Handle for a queue.
unsigned int backpressure
How may messages did we pass from this queue to CORE for which we have yet to receive an acknoweldgem...
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
struct GNUNET_PEERSTORE_IterateContext * handshake_ack_monotime_get
Iteration Context for retrieving the monotonic time send with the handshake ack.
int rekeyed
GNUNET_YES if we just rekeyed and must thus possibly re-decrypt ciphertext.
struct GNUNET_CRYPTO_ChallengeNonceP challenge
Challenge value used to protect against replay attack, if there is no stored monotonic time value.
size_t unverified_size
Size of data received without KX challenge played back.
struct GNUNET_TRANSPORT_QueueHandle * qh
handle for this queue with the ch.
struct GNUNET_HashCode out_hmac
Shared secret for HMAC generation on outgoing data, ratcheted after each operation.
int finishing
Did we enqueue a finish message and are closing down the queue?
int initial_core_kx_done
Has the initial (core) handshake already happened?
socklen_t address_len
Length of the address.
struct GNUNET_MQ_Handle * mq
Message queue we are providing for the ch.
unsigned long long bytes_in_queue
Number of bytes we currently have in our write queue.
char pread_buf[UINT16_MAX+1+sizeof(struct TCPBox)]
Plaintext buffer for decrypted plaintext.
int destroyed
Did we technically destroy this queue, but kept the allocation around because of backpressure not bei...
struct GNUNET_PEERSTORE_StoreContext * rekey_monotime_sc
Store Context for retrieving the monotonic time send with key for rekeying.
size_t cwrite_off
At which offset in the ciphertext write buffer should we append more ciphertext from reading next?
struct GNUNET_PEERSTORE_IterateContext * rekey_monotime_get
Iteration Context for retrieving the monotonic time send with key for rekeying.
char cread_buf[(2 *64 *1024+sizeof(struct TCPBox))]
Buffer for reading ciphertext from network into.
enum GNUNET_NetworkType nt
Which network type does this queue use?
struct GNUNET_CRYPTO_ChallengeNonceP challenge_received
Challenge value received.
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
uint64_t rekey_left_bytes
How many more bytes may we sent with the current out_cipher before we should rekey?
int mq_awaits_continue
Is MQ awaiting a GNUNET_MQ_impl_send_continue() call?
gcry_cipher_hd_t in_cipher
cipher for decryption of incoming data.
struct GNUNET_PEERSTORE_StoreContext * handshake_ack_monotime_sc
Store Context for retrieving the monotonic time send with the handshake ack.
size_t pwrite_off
At which offset in the plaintext output buffer should we append more plaintext for encryption next?
struct GNUNET_TIME_Absolute timeout
Timeout for this queue.
struct sockaddr * address
Address of the other peer.
size_t cread_off
At which offset in the ciphertext read buffer should we append more ciphertext for transmission next?
struct GNUNET_TIME_Absolute rekey_time
Until what time may we sent with the current out_cipher before we should rekey?
struct GNUNET_PeerIdentity target
To whom are we talking to.
char cwrite_buf[(2 *64 *1024+sizeof(struct TCPBox))]
buffer for writing ciphertext to network.
struct GNUNET_PEERSTORE_StoreContext * handshake_monotime_sc
Store Context for retrieving the monotonic time send with the handshake.
size_t pread_off
At which offset in the plaintext input buffer should we append more plaintext from decryption next?
enum GNUNET_TRANSPORT_ConnectionStatus cs
The connection status of this queue.
gcry_cipher_hd_t out_cipher
cipher for encryption of outgoing data.
char pwrite_buf[UINT16_MAX+1+sizeof(struct TCPBox)]
Plaintext buffer for messages to be encrypted.
struct GNUNET_HashCode in_hmac
Shared secret for HMAC verification on incoming data.
struct GNUNET_PEERSTORE_IterateContext * handshake_monotime_get
Iteration Context for retrieving the monotonic time send with the handshake.
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
struct GNUNET_SCHEDULER_Task * write_task
ID of write task for this connection.
struct GNUNET_TIME_AbsoluteNBO handshake_ack_monotonic_time
Monotonic time value for handshake ack message.
struct GNUNET_TIME_AbsoluteNBO rekey_monotonic_time
Monotonic time value for rekey message.
struct GNUNET_TIME_AbsoluteNBO handshake_monotonic_time
Monotonic time value for handshake message.
TCP message box.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX.
struct GNUNET_ShortHashCode hmac
HMAC for the following encrypted message.
Ack for the encrypted continuation of TCP initial handshake.
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
struct GNUNET_CRYPTO_EddsaSignature sender_sig
Sender's signature of type GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE_ACK.
struct GNUNET_CRYPTO_ChallengeNonceP challenge
Challenge value used to protect against replay attack, if there is no stored monotonic time value.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_CONFIRMATION_ACK.
struct GNUNET_PeerIdentity sender
Sender's identity.
Encrypted continuation of TCP initial handshake.
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
struct GNUNET_CRYPTO_EddsaSignature sender_sig
Sender's signature of type GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE.
struct GNUNET_PeerIdentity sender
Sender's identity.
struct GNUNET_CRYPTO_ChallengeNonceP challenge
Challenge value used to protect against replay attack, if there is no stored monotonic time value.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH.
struct GNUNET_ShortHashCode hmac
HMAC for the following encrypted message.
Basically a WELCOME message, but with the purpose of giving the waiting peer a client handle to use.
struct GNUNET_PeerIdentity clientIdentity
Identity of the sender of the message.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE.
TCP rekey message box.
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
struct GNUNET_CRYPTO_EcdhePublicKey ephemeral
New ephemeral key.
struct GNUNET_CRYPTO_EddsaSignature sender_sig
Sender's signature of type GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_REKEY.
struct GNUNET_ShortHashCode hmac
HMAC for the following encrypted message.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY.
Signature we use to verify that the ack from the receiver of the ephemeral key was really send by the...
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE_ACK.
struct GNUNET_PeerIdentity sender
Identity of the inititor of the TCP connection (TCP client).
struct GNUNET_CRYPTO_ChallengeNonceP challenge
Challenge value used to protect against replay attack, if there is no stored monotonic time value.
struct GNUNET_PeerIdentity receiver
Presumed identity of the target of the TCP connection (TCP server)
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
Signature we use to verify that the ephemeral key was really chosen by the specified sender.
struct GNUNET_CRYPTO_ChallengeNonceP challenge
Challenge value used to protect against replay attack, if there is no stored monotonic time value.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE.
struct GNUNET_PeerIdentity sender
Identity of the inititor of the TCP connection (TCP client).
struct GNUNET_CRYPTO_EcdhePublicKey ephemeral
Ephemeral key used by the sender.
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_EcdhePublicKey ephemeral
Ephemeral key used by the sender.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_REKEY.
struct GNUNET_PeerIdentity sender
Identity of the inititor of the TCP connection (TCP client).
struct GNUNET_PeerIdentity receiver
Presumed identity of the target of the TCP connection (TCP server)
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...