GNUnet 0.21.2
gnunet-communicator-tcp.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet
3 Copyright (C) 2010-2014, 2018, 2019 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
30#include "platform.h"
31#include "gnunet_common.h"
32#include "gnunet_util_lib.h"
33#include "gnunet_core_service.h"
35#include "gnunet_protocols.h"
36#include "gnunet_signatures.h"
37#include "gnunet_constants.h"
38#include "gnunet_nat_service.h"
42
43
48#define NAT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
49
54#define ADDRESS_VALIDITY_PERIOD \
55 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
56
65#define DEFAULT_MAX_QUEUE_LENGTH 8
66
71#define BUF_SIZE (2 * 64 * 1024 + sizeof(struct TCPBox))
72
76#define DEFAULT_REKEY_INTERVAL GNUNET_TIME_UNIT_DAYS
77
81#define PROTO_QUEUE_TIMEOUT GNUNET_TIME_UNIT_MINUTES
82
87#define REKEY_MAX_BYTES (1024LLU * 1024 * 400)
88
93#define INITIAL_KX_SIZE \
94 (sizeof(struct GNUNET_CRYPTO_EcdhePublicKey) \
95 + sizeof(struct TCPConfirmation))
96
100#define INITIAL_CORE_KX_SIZE \
101 (sizeof(struct EphemeralKeyMessage) \
102 + sizeof(struct PingMessage) \
103 + sizeof(struct PongMessage))
104
108#define COMMUNICATOR_ADDRESS_PREFIX "tcp"
109
113#define COMMUNICATOR_CONFIG_SECTION "communicator-tcp"
114
116
117
123{
128
133
138
143
149
154};
155
161{
166
171
176
182
187};
188
193{
198
203
209
214
215};
216
221{
222
223
228
233
238
244
249
250};
251
255struct TCPBox
256{
264
274
275 /* followed by as may bytes of payload as indicated in @e header,
276 excluding the TCPBox itself! */
277};
278
279
285{
290
300
305
310
316};
317
323{
328
333
338
343
349};
350
357{
362
372};
373
379{
384
389};
390
392
397{
398 /*
399 * Timeout task.
400 */
402
407
411 struct sockaddr *in;
412};
413
418{
423
428};
429
433struct Queue
434{
439
444
449
453 gcry_cipher_hd_t in_cipher;
454
458 gcry_cipher_hd_t out_cipher;
459
464
469
475
480
485
489 struct sockaddr *address;
490
496
502
506 socklen_t address_len;
507
512
517
521 unsigned long long bytes_in_queue;
522
527
532
536 char pread_buf[UINT16_MAX + 1 + sizeof(struct TCPBox)];
537
541 char pwrite_buf[UINT16_MAX + 1 + sizeof(struct TCPBox)];
542
547 size_t cread_off;
548
554
559 size_t pread_off;
560
566
571
579 unsigned int backpressure;
580
585
590
595
600
608
614
619
624
629
634
639
644
649
654
659
664
669
673 // TODO remove?
675
680};
681
682
688{
693
698
703
708
713
717 char write_buf[sizeof (struct TCPNATProbeMessage)];
718
722 size_t write_off;
723
728
732 struct sockaddr *address;
733
737 socklen_t address_len;
738
743
749
753 size_t ibuf_off;
754};
755
760{
764 struct sockaddr *addr_ipv4;
765
769 socklen_t addr_len_ipv4;
770
774 struct sockaddr *addr_ipv6;
775
779 socklen_t addr_len_ipv6;
780
781};
782
787{
792
797
801 struct sockaddr *addr;
802
806 socklen_t addr_len;
807
808};
809
810
814static unsigned long long max_queue_length;
815
820
825
830
835
840
844static unsigned long long rekey_max_bytes;
845
850
855
859static const struct GNUNET_CONFIGURATION_Handle *cfg;
860
865
869static struct GNUNET_NAT_Handle *nat;
870
874static struct ProtoQueue *proto_head;
875
879static struct ProtoQueue *proto_tail;
880
885
889static struct Addresses *addrs_head;
890
894static struct Addresses *addrs_tail;
895
899static int addrs_lens;
900
905
910
914static int disable_v6;
915
919static unsigned int bind_port;
920
925
933static void
934listen_cb (void *cls);
935
943static void
945{
946 struct ListenTask *lt = NULL;
947 struct GNUNET_HashCode h_sock;
948 int sockfd;
949
950 if (NULL != queue->listen_sock)
951 {
952 sockfd = GNUNET_NETWORK_get_fd (queue->listen_sock);
953 GNUNET_CRYPTO_hash (&sockfd,
954 sizeof(int),
955 &h_sock);
956
958 }
959
961 "Disconnecting queue for peer `%s'\n",
962 GNUNET_i2s (&queue->target));
963 if (NULL != queue->rekey_monotime_sc)
964 {
965 GNUNET_PEERSTORE_store_cancel (queue->rekey_monotime_sc);
966 queue->rekey_monotime_sc = NULL;
967 }
968 if (NULL != queue->handshake_monotime_sc)
969 {
970 GNUNET_PEERSTORE_store_cancel (queue->handshake_monotime_sc);
971 queue->handshake_monotime_sc = NULL;
972 }
973 if (NULL != queue->handshake_ack_monotime_sc)
974 {
975 GNUNET_PEERSTORE_store_cancel (queue->handshake_ack_monotime_sc);
976 queue->handshake_ack_monotime_sc = NULL;
977 }
978 if (NULL != queue->rekey_monotime_get)
979 {
980 GNUNET_PEERSTORE_iteration_stop (queue->rekey_monotime_get);
981 queue->rekey_monotime_get = NULL;
982 }
983 if (NULL != queue->handshake_monotime_get)
984 {
985 GNUNET_PEERSTORE_iteration_stop (queue->handshake_monotime_get);
986 queue->handshake_monotime_get = NULL;
987 }
988 if (NULL != queue->handshake_ack_monotime_get)
989 {
990 GNUNET_PEERSTORE_iteration_stop (queue->handshake_ack_monotime_get);
991 queue->handshake_ack_monotime_get = NULL;
992 }
993 if (NULL != queue->qh)
994 {
996 queue->qh = NULL;
997 }
999 GNUNET_YES ==
1002 "# queues active",
1004 GNUNET_NO);
1005 if (NULL != queue->read_task)
1006 {
1007 GNUNET_SCHEDULER_cancel (queue->read_task);
1008 queue->read_task = NULL;
1009 }
1010 if (NULL != queue->write_task)
1011 {
1012 GNUNET_SCHEDULER_cancel (queue->write_task);
1013 queue->write_task = NULL;
1014 }
1016 {
1018 "closing socket failed\n");
1019 }
1020 gcry_cipher_close (queue->in_cipher);
1021 gcry_cipher_close (queue->out_cipher);
1022 GNUNET_free (queue->address);
1023 if (0 != queue->backpressure)
1024 queue->destroyed = GNUNET_YES;
1025 else
1027
1028 if (NULL == lt)
1029 return;
1030
1031 if ((! shutdown_running) && (NULL == lt->listen_task))
1032 {
1034 "add read net listen\n");
1037 lt->listen_sock,
1038 &listen_cb,
1039 lt);
1040 }
1041 else
1042 GNUNET_free (lt);
1043}
1044
1045
1054static void
1055calculate_hmac (struct GNUNET_HashCode *hmac_secret,
1056 const void *buf,
1057 size_t buf_size,
1058 struct GNUNET_ShortHashCode *smac)
1059{
1060 struct GNUNET_HashCode mac;
1061
1062 GNUNET_CRYPTO_hmac_raw (hmac_secret,
1063 sizeof(struct GNUNET_HashCode),
1064 buf,
1065 buf_size,
1066 &mac);
1067 /* truncate to `struct GNUNET_ShortHashCode` */
1068 memcpy (smac, &mac, sizeof(struct GNUNET_ShortHashCode));
1069 /* ratchet hmac key */
1070 GNUNET_CRYPTO_hash (hmac_secret,
1071 sizeof(struct GNUNET_HashCode),
1072 hmac_secret);
1073}
1074
1075
1082static void
1084{
1085 struct TCPFinish fin;
1086
1087 memset (&fin, 0, sizeof(fin));
1088 fin.header.size = htons (sizeof(fin));
1090 calculate_hmac (&queue->out_hmac, &fin, sizeof(fin), &fin.hmac);
1091 /* if there is any message left in pwrite_buf, we
1092 overwrite it (possibly dropping the last message
1093 from CORE hard here) */
1094 memcpy (queue->pwrite_buf, &fin, sizeof(fin));
1095 queue->pwrite_off = sizeof(fin);
1096 /* This flag will ensure that #queue_write() no longer
1097 notifies CORE about the possibility of sending
1098 more data, and that #queue_write() will call
1099 #queue_destroy() once the @c fin was fully written. */
1100 queue->finishing = GNUNET_YES;
1101}
1102
1103
1109static void
1110queue_read (void *cls);
1111
1112
1120static void
1121core_read_finished_cb (void *cls, int success)
1122{
1123 struct Queue *queue = cls;
1124 if (GNUNET_OK != success)
1126 "# messages lost in communicator API towards CORE",
1127 1,
1128 GNUNET_NO);
1129 if (NULL == queue)
1130 return;
1131
1133 "backpressure %u\n",
1134 queue->backpressure);
1135
1136 queue->backpressure--;
1137 /* handle deferred queue destruction */
1138 if ((queue->destroyed) && (0 == queue->backpressure))
1139 {
1141 return;
1142 }
1143 else if (GNUNET_YES != queue->destroyed)
1144 {
1145 queue->timeout =
1147 );
1148 /* possibly unchoke reading, now that CORE made progress */
1149 if (NULL == queue->read_task)
1150 queue->read_task =
1152 queue->timeout),
1153 queue->sock,
1154 &queue_read,
1155 queue);
1156 }
1157}
1158
1159
1169static void
1171 const void *plaintext,
1172 size_t plaintext_len)
1173{
1174 const struct GNUNET_MessageHeader *hdr = plaintext;
1175 int ret;
1176
1178 "pass message from %s to core\n",
1179 GNUNET_i2s (&queue->target));
1180
1181 if (ntohs (hdr->size) != plaintext_len)
1182 {
1183 /* NOTE: If we ever allow multiple CORE messages in one
1184 BOX, this will have to change! */
1185 GNUNET_break (0);
1186 return;
1187 }
1189 &queue->target,
1190 hdr,
1193 queue);
1195 "passed to core\n");
1196 if (GNUNET_OK == ret)
1197 queue->backpressure++;
1198 GNUNET_break (GNUNET_NO != ret); /* backpressure not working!? */
1199 if (GNUNET_SYSERR == ret)
1201 "# bytes lost due to CORE not running",
1202 plaintext_len,
1203 GNUNET_NO);
1204}
1205
1206
1216static void
1218 const struct GNUNET_PeerIdentity *pid,
1219 gcry_cipher_hd_t *cipher,
1220 struct GNUNET_HashCode *hmac_key)
1221{
1222 char key[256 / 8];
1223 char ctr[128 / 8];
1224
1225 GNUNET_assert (0 == gcry_cipher_open (cipher,
1226 GCRY_CIPHER_AES256 /* low level: go for speed */
1227 ,
1228 GCRY_CIPHER_MODE_CTR,
1229 0 /* flags */));
1231 sizeof(key),
1232 "TCP-key",
1233 strlen ("TCP-key"),
1234 dh,
1235 sizeof(*dh),
1236 pid,
1237 sizeof(*pid),
1238 NULL,
1239 0));
1240 GNUNET_assert (0 == gcry_cipher_setkey (*cipher, key, sizeof(key)));
1242 sizeof(ctr),
1243 "TCP-ctr",
1244 strlen ("TCP-ctr"),
1245 dh,
1246 sizeof(*dh),
1247 pid,
1248 sizeof(*pid),
1249 NULL,
1250 0));
1251 gcry_cipher_setctr (*cipher, ctr, sizeof(ctr));
1253 GNUNET_CRYPTO_kdf (hmac_key,
1254 sizeof(struct GNUNET_HashCode),
1255 "TCP-hmac",
1256 strlen ("TCP-hmac"),
1257 dh,
1258 sizeof(*dh),
1259 pid,
1260 sizeof(*pid),
1261 NULL,
1262 0));
1263}
1264
1265
1271static void
1272rekey_monotime_store_cb (void *cls, int success)
1273{
1274 struct Queue *queue = cls;
1275 if (GNUNET_OK != success)
1276 {
1278 "Failed to store rekey monotonic time in PEERSTORE!\n");
1279 }
1280 queue->rekey_monotime_sc = NULL;
1281 GNUNET_PEERSTORE_iteration_next (queue->rekey_monotime_get, 1);
1282}
1283
1284
1292static void
1294 const struct GNUNET_PEERSTORE_Record *record,
1295 const char *emsg)
1296{
1297 struct Queue *queue = cls;
1298 struct GNUNET_TIME_AbsoluteNBO *mtbe;
1299 struct GNUNET_TIME_Absolute mt;
1300 const struct GNUNET_PeerIdentity *pid;
1301 struct GNUNET_TIME_AbsoluteNBO *rekey_monotonic_time;
1302
1303 (void) emsg;
1304
1305 rekey_monotonic_time = &queue->rekey_monotonic_time;
1306 pid = &queue->target;
1307 if (NULL == record)
1308 {
1309 queue->rekey_monotime_get = NULL;
1310 return;
1311 }
1312 if (sizeof(*mtbe) != record->value_size)
1313 {
1314 GNUNET_PEERSTORE_iteration_next (queue->rekey_monotime_get, 1);
1315 GNUNET_break (0);
1316 return;
1317 }
1318 mtbe = record->value;
1319 mt = GNUNET_TIME_absolute_ntoh (*mtbe);
1321 queue->rekey_monotonic_time).abs_value_us)
1322 {
1324 "Queue from %s dropped, rekey monotime in the past\n",
1325 GNUNET_i2s (&queue->target));
1326 GNUNET_break (0);
1327 GNUNET_PEERSTORE_iteration_stop (queue->rekey_monotime_get);
1328 queue->rekey_monotime_get = NULL;
1329 // FIXME: Why should we try to gracefully finish here??
1331 return;
1332 }
1333 queue->rekey_monotime_sc = GNUNET_PEERSTORE_store (peerstore,
1334 "transport_tcp_communicator",
1335 pid,
1337 rekey_monotonic_time,
1338 sizeof(*
1339 rekey_monotonic_time),
1343 queue);
1344}
1345
1346
1353static void
1355 const struct GNUNET_CRYPTO_ElligatorRepresentative *repr,
1356 struct Queue *queue)
1357{
1358 struct GNUNET_HashCode k;
1359
1361 setup_cipher (&k, &my_identity, &queue->in_cipher, &queue->in_hmac);
1362}
1363
1364
1371static void
1373 struct Queue *queue)
1374{
1375 struct GNUNET_HashCode k;
1376
1378 setup_cipher (&k, &my_identity, &queue->in_cipher, &queue->in_hmac);
1379}
1380
1381
1390static void
1391do_rekey (struct Queue *queue, const struct TCPRekey *rekey)
1392{
1393 struct TcpRekeySignature thp;
1394
1396 thp.purpose.size = htonl (sizeof(thp));
1398 "do_rekey size %u\n",
1399 thp.purpose.size);
1400 thp.sender = queue->target;
1402 "sender %s\n",
1405 "sender %s\n",
1406 GNUNET_p2s (&queue->target.public_key));
1407 thp.receiver = my_identity;
1409 "receiver %s\n",
1411 thp.ephemeral = rekey->ephemeral;
1413 "ephemeral %s\n",
1414 GNUNET_e2s (&thp.ephemeral));
1415 thp.monotonic_time = rekey->monotonic_time;
1417 "time %s\n",
1420 GNUNET_assert (ntohl ((&thp)->purpose.size) == sizeof (*(&thp)));
1421 if (GNUNET_OK !=
1424 &thp,
1425 &rekey->sender_sig,
1426 &queue->target.public_key))
1427 {
1428 GNUNET_break (0);
1429 // FIXME Why should we try to gracefully finish here?
1431 return;
1432 }
1433 queue->rekey_monotonic_time = rekey->monotonic_time;
1434 queue->rekey_monotime_get = GNUNET_PEERSTORE_iteration_start (peerstore,
1435 "transport_tcp_communicator",
1436 &queue->target,
1438 &
1440 queue);
1441 gcry_cipher_close (queue->in_cipher);
1442 queue->rekeyed = GNUNET_YES;
1443 setup_in_cipher (&rekey->ephemeral, queue);
1444}
1445
1446
1452static void
1453handshake_ack_monotime_store_cb (void *cls, int success)
1454{
1455 struct Queue *queue = cls;
1456
1457 if (GNUNET_OK != success)
1458 {
1460 "Failed to store handshake ack monotonic time in PEERSTORE!\n");
1461 }
1462 queue->handshake_ack_monotime_sc = NULL;
1463 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
1464}
1465
1466
1474static void
1476 const struct GNUNET_PEERSTORE_Record *record,
1477 const char *emsg)
1478{
1479 struct Queue *queue = cls;
1480 struct GNUNET_TIME_AbsoluteNBO *mtbe;
1481 struct GNUNET_TIME_Absolute mt;
1482 const struct GNUNET_PeerIdentity *pid;
1483 struct GNUNET_TIME_AbsoluteNBO *handshake_ack_monotonic_time;
1484
1485 (void) emsg;
1486
1487 handshake_ack_monotonic_time = &queue->handshake_ack_monotonic_time;
1488 pid = &queue->target;
1489 if (NULL == record)
1490 {
1491 queue->handshake_ack_monotime_get = NULL;
1492 return;
1493 }
1494 if (sizeof(*mtbe) != record->value_size)
1495 {
1496 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
1497 GNUNET_break (0);
1498 return;
1499 }
1500 mtbe = record->value;
1501 mt = GNUNET_TIME_absolute_ntoh (*mtbe);
1503 queue->handshake_ack_monotonic_time).abs_value_us)
1504 {
1506 "Queue from %s dropped, handshake ack monotime in the past\n",
1507 GNUNET_i2s (&queue->target));
1508 GNUNET_break (0);
1509 GNUNET_PEERSTORE_iteration_stop (queue->handshake_ack_monotime_get);
1510 queue->handshake_ack_monotime_get = NULL;
1511 // FIXME: Why should we try to gracefully finish here?
1513 return;
1514 }
1515 queue->handshake_ack_monotime_sc =
1517 "transport_tcp_communicator",
1518 pid,
1520 handshake_ack_monotonic_time,
1521 sizeof(*handshake_ack_monotonic_time),
1525 queue);
1526}
1527
1528
1535static void
1537 struct Queue *queue)
1538{
1539 struct TCPConfirmationAck tca;
1540 struct TcpHandshakeAckSignature thas;
1541
1543 "sending challenge\n");
1544
1545 tca.header.type = ntohs (
1547 tca.header.size = ntohs (sizeof(tca));
1548 tca.challenge = challenge;
1549 tca.sender = my_identity;
1550 tca.monotonic_time =
1552 thas.purpose.purpose = htonl (
1554 thas.purpose.size = htonl (sizeof(thas));
1555 thas.sender = my_identity;
1556 thas.receiver = queue->target;
1557 thas.monotonic_time = tca.monotonic_time;
1558 thas.challenge = tca.challenge;
1560 &thas,
1561 &tca.sender_sig);
1562 GNUNET_assert (0 ==
1563 gcry_cipher_encrypt (queue->out_cipher,
1564 &queue->cwrite_buf[queue->cwrite_off],
1565 sizeof(tca),
1566 &tca,
1567 sizeof(tca)));
1568 queue->cwrite_off += sizeof(tca);
1570 "sending challenge done\n");
1571}
1572
1573
1580static void
1582{
1583 setup_cipher (dh, &queue->target, &queue->out_cipher, &queue->out_hmac);
1585 queue->rekey_left_bytes =
1587}
1588
1589
1596static void
1598{
1599 struct TCPRekey rekey;
1600 struct TcpRekeySignature thp;
1601 struct GNUNET_HashCode k;
1602
1603 GNUNET_assert (0 == queue->pwrite_off);
1604 memset (&rekey, 0, sizeof(rekey));
1605 GNUNET_CRYPTO_eddsa_kem_encaps (&queue->target.public_key, &rekey.ephemeral,
1606 &k);
1608 rekey.header.size = ntohs (sizeof(rekey));
1609 rekey.monotonic_time =
1612 thp.purpose.size = htonl (sizeof(thp));
1614 "inject_rekey size %u\n",
1615 thp.purpose.size);
1616 thp.sender = my_identity;
1618 "sender %s\n",
1620 thp.receiver = queue->target;
1622 "receiver %s\n",
1624 thp.ephemeral = rekey.ephemeral;
1626 "ephemeral %s\n",
1627 GNUNET_e2s (&thp.ephemeral));
1628 thp.monotonic_time = rekey.monotonic_time;
1630 "time %s\n",
1634 &thp,
1635 &rekey.sender_sig);
1636 calculate_hmac (&queue->out_hmac, &rekey, sizeof(rekey), &rekey.hmac);
1637 /* Encrypt rekey message with 'old' cipher */
1638 GNUNET_assert (0 ==
1639 gcry_cipher_encrypt (queue->out_cipher,
1640 &queue->cwrite_buf[queue->cwrite_off],
1641 sizeof(rekey),
1642 &rekey,
1643 sizeof(rekey)));
1644 queue->cwrite_off += sizeof(rekey);
1645 /* Setup new cipher for successive messages */
1646 gcry_cipher_close (queue->out_cipher);
1647 setup_out_cipher (queue, &k);
1648}
1649
1650
1651static int
1653 const struct GNUNET_HashCode *key,
1654 void *value)
1655{
1656 (void) cls;
1657 struct PendingReversal *pending_reversal = value;
1658
1659 if (NULL != pending_reversal->timeout_task)
1660 {
1661 GNUNET_SCHEDULER_cancel (pending_reversal->timeout_task);
1662 pending_reversal->timeout_task = NULL;
1663 }
1666 key,
1667 pending_reversal));
1668 GNUNET_free (pending_reversal->in);
1669 GNUNET_free (pending_reversal);
1670 return GNUNET_OK;
1671}
1672
1673
1674static void
1675check_and_remove_pending_reversal (struct sockaddr *in, sa_family_t sa_family,
1676 struct GNUNET_PeerIdentity *sender)
1677{
1678 if (AF_INET == sa_family)
1679 {
1680 struct PendingReversal *pending_reversal;
1681 struct GNUNET_HashCode key;
1682 struct sockaddr_in *natted_address;
1683
1684 natted_address = GNUNET_memdup (in, sizeof (struct sockaddr));
1685 natted_address->sin_port = 0;
1686 GNUNET_CRYPTO_hash (natted_address,
1687 sizeof(struct sockaddr),
1688 &key);
1689
1691 &key);
1692 if (NULL != pending_reversal && (NULL == sender ||
1693 0 != memcmp (sender,
1694 &pending_reversal->target,
1695 sizeof(struct
1697 {
1699 "Removing invalid pending reversal for `%s'at `%s'\n",
1700 GNUNET_i2s (&pending_reversal->target),
1701 GNUNET_a2s (in, sizeof (struct sockaddr)));
1702 pending_reversals_delete_it (NULL, &key, pending_reversal);
1703 }
1704 GNUNET_free (natted_address);
1705 }
1706}
1707
1708
1714static void
1716{
1717 if (NULL != pq->listen_sock)
1718 {
1720 pq->listen_sock = NULL;
1721 }
1722 if (NULL != pq->read_task)
1723 {
1725 pq->read_task = NULL;
1726 }
1727 if (NULL != pq->write_task)
1728 {
1730 pq->write_task = NULL;
1731 }
1732 check_and_remove_pending_reversal (pq->address, pq->address->sa_family, NULL);
1734 GNUNET_free (pq->address);
1736 GNUNET_free (pq);
1737}
1738
1739
1746static void
1748{
1749 struct ProtoQueue *pq = cls;
1750 ssize_t sent;
1751 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "In proto queue write\n");
1752 pq->write_task = NULL;
1753 if (0 != pq->write_off)
1754 {
1755 sent = GNUNET_NETWORK_socket_send (pq->sock,
1756 pq->write_buf,
1757 pq->write_off);
1759 "Sent %lu bytes to TCP queue\n", sent);
1760 if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno))
1761 {
1763 free_proto_queue (pq);
1764 return;
1765 }
1766 if (sent > 0)
1767 {
1768 size_t usent = (size_t) sent;
1769 pq->write_off -= usent;
1770 memmove (pq->write_buf,
1771 &pq->write_buf[usent],
1772 pq->write_off);
1773 }
1774 }
1775 /* do we care to write more? */
1776 if ((0 < pq->write_off))
1777 pq->write_task =
1779 pq->sock,
1781 pq);
1782}
1783
1784
1791static void
1792queue_write (void *cls)
1793{
1794 struct Queue *queue = cls;
1795 ssize_t sent;
1796 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "In queue write\n");
1797 queue->write_task = NULL;
1798 if (0 != queue->cwrite_off)
1799 {
1800 sent = GNUNET_NETWORK_socket_send (queue->sock,
1801 queue->cwrite_buf,
1802 queue->cwrite_off);
1804 "Sent %lu bytes to TCP queue\n", sent);
1805 if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno))
1806 {
1809 return;
1810 }
1811 if (sent > 0)
1812 {
1813 size_t usent = (size_t) sent;
1814 queue->cwrite_off -= usent;
1815 memmove (queue->cwrite_buf,
1816 &queue->cwrite_buf[usent],
1817 queue->cwrite_off);
1818 queue->timeout =
1821 }
1822 }
1823 /* can we encrypt more? (always encrypt full messages, needed
1824 such that #mq_cancel() can work!) */
1825 unsigned int we_do_not_need_to_rekey = (0 < queue->rekey_left_bytes
1826 - (queue->cwrite_off
1827 + queue->pwrite_off
1828 + sizeof (struct TCPRekey)));
1829 if (we_do_not_need_to_rekey &&
1830 (queue->pwrite_off > 0) &&
1831 (queue->cwrite_off + queue->pwrite_off <= BUF_SIZE))
1832 {
1834 "Encrypting %lu bytes\n", queue->pwrite_off);
1835 GNUNET_assert (0 ==
1836 gcry_cipher_encrypt (queue->out_cipher,
1837 &queue->cwrite_buf[queue->cwrite_off],
1838 queue->pwrite_off,
1839 queue->pwrite_buf,
1840 queue->pwrite_off));
1841 if (queue->rekey_left_bytes > queue->pwrite_off)
1842 queue->rekey_left_bytes -= queue->pwrite_off;
1843 else
1844 queue->rekey_left_bytes = 0;
1845 queue->cwrite_off += queue->pwrite_off;
1846 queue->pwrite_off = 0;
1847 }
1848 // if ((-1 != unverified_size)&& ((0 == queue->pwrite_off) &&
1849 if (((0 == queue->rekey_left_bytes) ||
1851 queue->rekey_time).rel_value_us)) &&
1852 (((0 == queue->pwrite_off) || ! we_do_not_need_to_rekey) &&
1853 (queue->cwrite_off + sizeof (struct TCPRekey) <= BUF_SIZE)))
1854 {
1856 }
1857 if ((0 == queue->pwrite_off) && (! queue->finishing) &&
1858 (GNUNET_YES == queue->mq_awaits_continue))
1859 {
1860 queue->mq_awaits_continue = GNUNET_NO;
1862 }
1863 /* did we just finish writing 'finish'? */
1864 if ((0 == queue->cwrite_off) && (GNUNET_YES == queue->finishing))
1865 {
1867 "Finishing queue\n");
1869 return;
1870 }
1871 /* do we care to write more? */
1872 if ((0 < queue->cwrite_off) || (0 < queue->pwrite_off))
1873 queue->write_task =
1875 queue->sock,
1876 &queue_write,
1877 queue);
1878}
1879
1880
1888static size_t
1890{
1891 const struct GNUNET_MessageHeader *hdr;
1892 const struct TCPConfirmationAck *tca;
1893 const struct TCPBox *box;
1894 const struct TCPRekey *rekey;
1895 const struct TCPFinish *fin;
1896 struct TCPRekey rekeyz;
1897 struct TCPFinish finz;
1898 struct GNUNET_ShortHashCode tmac;
1899 uint16_t type;
1900 size_t size = 0;
1901 struct TcpHandshakeAckSignature thas;
1902 const struct GNUNET_CRYPTO_ChallengeNonceP challenge = queue->challenge;
1903
1905 "try handle plaintext!\n");
1906
1907 hdr = (const struct GNUNET_MessageHeader *) queue->pread_buf;
1908 if ((sizeof(*hdr) > queue->pread_off))
1909 {
1911 "Handling plaintext, not even a header!\n");
1912 return 0; /* not even a header */
1913 }
1914
1915 if ((GNUNET_YES != queue->initial_core_kx_done) && (queue->unverified_size >
1917 {
1919 "Already received data of size %lu bigger than KX size %lu!\n",
1920 queue->unverified_size,
1922 GNUNET_break_op (0);
1924 return 0;
1925 }
1926
1927 type = ntohs (hdr->type);
1928 switch (type)
1929 {
1931 tca = (const struct TCPConfirmationAck *) queue->pread_buf;
1933 "start processing ack\n");
1934 if (sizeof(*tca) > queue->pread_off)
1935 {
1937 "Handling plaintext size of tca greater than pread offset.\n")
1938 ;
1939 return 0;
1940 }
1941 if (ntohs (hdr->size) != sizeof(*tca))
1942 {
1944 "Handling plaintext size does not match message type.\n");
1945 GNUNET_break_op (0);
1947 return 0;
1948 }
1949
1950 thas.purpose.purpose = htonl (
1952 thas.purpose.size = htonl (sizeof(thas));
1953 thas.sender = tca->sender;
1954 thas.receiver = my_identity;
1955 thas.monotonic_time = tca->monotonic_time;
1956 thas.challenge = tca->challenge;
1957
1960 &thas,
1961 &tca->sender_sig,
1962 &tca->sender.public_key))
1963 {
1965 "Verification of signature failed!\n");
1966 GNUNET_break (0);
1968 return 0;
1969 }
1970 if (0 != GNUNET_memcmp (&tca->challenge, &challenge))
1971 {
1973 "Challenge in TCPConfirmationAck not correct!\n");
1974 GNUNET_break (0);
1976 return 0;
1977 }
1978
1979 queue->handshake_ack_monotime_get = GNUNET_PEERSTORE_iteration_start (
1980 peerstore,
1981 "transport_tcp_communicator",
1982 &queue->target,
1985 queue);
1986
1988 "Handling plaintext, ack processed!\n");
1989
1991 {
1992 send_challenge (queue->challenge_received, queue);
1993 queue->write_task =
1995 queue->sock,
1996 &queue_write,
1997 queue);
1998 }
1999 else if (GNUNET_TRANSPORT_CS_OUTBOUND == queue->cs)
2000 {
2002 queue->address->sa_family, NULL);
2003 }
2004
2009 queue->initial_core_kx_done = GNUNET_YES;
2010
2011 char *foreign_addr;
2012
2013 switch (queue->address->sa_family)
2014 {
2015 case AF_INET:
2016 GNUNET_asprintf (&foreign_addr,
2017 "%s-%s",
2019 GNUNET_a2s (queue->address, queue->address_len));
2020 break;
2021
2022 case AF_INET6:
2023 GNUNET_asprintf (&foreign_addr,
2024 "%s-%s",
2026 GNUNET_a2s (queue->address, queue->address_len));
2027 break;
2028
2029 default:
2030 GNUNET_assert (0);
2031 }
2032
2034 &queue->target,
2035 foreign_addr,
2036 UINT16_MAX, /* no MTU */
2038 0, /* Priority */
2039 queue->nt,
2040 queue->cs,
2041 queue->mq);
2042
2043 GNUNET_free (foreign_addr);
2044
2045 size = ntohs (hdr->size);
2046 break;
2048 /* Special case: header size excludes box itself! */
2049 box = (const struct TCPBox *) queue->pread_buf;
2050 if (ntohs (hdr->size) + sizeof(struct TCPBox) > queue->pread_off)
2051 return 0;
2052 calculate_hmac (&queue->in_hmac, &box[1], ntohs (hdr->size), &tmac);
2053 if (0 != memcmp (&tmac, &box->hmac, sizeof(tmac)))
2054 {
2055 GNUNET_break_op (0);
2057 return 0;
2058 }
2059 pass_plaintext_to_core (queue, (const void *) &box[1], ntohs (hdr->size));
2060 size = ntohs (hdr->size) + sizeof(*box);
2062 "Handling plaintext, box processed!\n");
2064 "# bytes decrypted with BOX",
2065 size,
2066 GNUNET_NO);
2068 "# messages decrypted with BOX",
2069 1,
2070 GNUNET_NO);
2071 break;
2072
2074 rekey = (const struct TCPRekey *) queue->pread_buf;
2075 if (sizeof(*rekey) > queue->pread_off)
2076 return 0;
2077 if (ntohs (hdr->size) != sizeof(*rekey))
2078 {
2079 GNUNET_break_op (0);
2081 return 0;
2082 }
2083 rekeyz = *rekey;
2084 memset (&rekeyz.hmac, 0, sizeof(rekeyz.hmac));
2085 calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
2086 if (0 != memcmp (&tmac, &rekey->hmac, sizeof(tmac)))
2087 {
2088 GNUNET_break_op (0);
2090 return 0;
2091 }
2092 do_rekey (queue, rekey);
2093 size = ntohs (hdr->size);
2095 "Handling plaintext, rekey processed!\n");
2097 "# rekeying successful",
2098 1,
2099 GNUNET_NO);
2100 break;
2101
2103 fin = (const struct TCPFinish *) queue->pread_buf;
2104 if (sizeof(*fin) > queue->pread_off)
2105 return 0;
2106 if (ntohs (hdr->size) != sizeof(*fin))
2107 {
2108 GNUNET_break_op (0);
2110 return 0;
2111 }
2112 finz = *fin;
2113 memset (&finz.hmac, 0, sizeof(finz.hmac));
2114 calculate_hmac (&queue->in_hmac, &finz, sizeof(finz), &tmac);
2115 if (0 != memcmp (&tmac, &fin->hmac, sizeof(tmac)))
2116 {
2117 GNUNET_break_op (0);
2119 return 0;
2120 }
2121 /* handle FINISH by destroying queue */
2124 "Handling plaintext, finish processed!\n");
2125 break;
2126
2127 default:
2129 "Handling plaintext, nothing processed!\n");
2130 GNUNET_break_op (0);
2132 return 0;
2133 }
2134 GNUNET_assert (0 != size);
2135 if (-1 != queue->unverified_size)
2136 queue->unverified_size += size;
2137 return size;
2138}
2139
2140
2146static void
2147queue_read (void *cls)
2148{
2149 struct Queue *queue = cls;
2150 struct GNUNET_TIME_Relative left;
2151 ssize_t rcvd;
2152
2153 queue->read_task = NULL;
2154 rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
2155 &queue->cread_buf[queue->cread_off],
2156 BUF_SIZE - queue->cread_off);
2158 "Received %zd bytes from TCP queue\n", rcvd);
2159 if (-1 == rcvd)
2160 {
2161 if ((EAGAIN != errno) && (EINTR != errno))
2162 {
2165 return;
2166 }
2167 /* try again */
2168 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
2169 if (0 != left.rel_value_us)
2170 {
2171 queue->read_task =
2173 return;
2174 }
2176 "Queue %p was idle for %s, disconnecting\n",
2177 queue,
2180 GNUNET_YES));
2182 return;
2183 }
2184 if (0 == rcvd)
2185 {
2186 /* Orderly shutdown of connection */
2188 "Socket for queue %p seems to have been closed\n", queue);
2190 return;
2191 }
2192 queue->timeout =
2194 queue->cread_off += rcvd;
2195 while ((queue->pread_off < sizeof(queue->pread_buf)) &&
2196 (queue->cread_off > 0))
2197 {
2198 size_t max = GNUNET_MIN (sizeof(queue->pread_buf) - queue->pread_off,
2199 queue->cread_off);
2200 size_t done;
2201 size_t total;
2202 size_t old_pread_off = queue->pread_off;
2203
2204 GNUNET_assert (0 ==
2205 gcry_cipher_decrypt (queue->in_cipher,
2206 &queue->pread_buf[queue->pread_off],
2207 max,
2208 queue->cread_buf,
2209 max));
2210 queue->pread_off += max;
2211 total = 0;
2212 while (0 != (done = try_handle_plaintext (queue)))
2213 {
2214 /* 'done' bytes of plaintext were used, shift buffer */
2215 GNUNET_assert (done <= queue->pread_off);
2216 /* NOTE: this memmove() could possibly sometimes be
2217 avoided if we pass 'total' into try_handle_plaintext()
2218 and use it at an offset into the buffer there! */
2219 memmove (queue->pread_buf,
2220 &queue->pread_buf[done],
2221 queue->pread_off - done);
2222 queue->pread_off -= done;
2223 total += done;
2224 /* The last plaintext was a rekey, abort for now */
2225 if (GNUNET_YES == queue->rekeyed)
2226 break;
2227 }
2228 /* when we encounter a rekey message, the decryption above uses the
2229 wrong key for everything after the rekey; in that case, we have
2230 to re-do the decryption at 'total' instead of at 'max'.
2231 However, we have to take into account that the plaintext buffer may have
2232 already contained data and not jumped too far ahead in the ciphertext.
2233 If there is no rekey and the last message is incomplete (max > total),
2234 it is safe to keep the decryption so we shift by 'max' */
2235 if (GNUNET_YES == queue->rekeyed)
2236 {
2237 max = total - old_pread_off;
2238 queue->rekeyed = GNUNET_NO;
2239 queue->pread_off = 0;
2240 }
2241 memmove (queue->cread_buf, &queue->cread_buf[max], queue->cread_off - max);
2242 queue->cread_off -= max;
2243 }
2244 if (BUF_SIZE == queue->cread_off)
2245 return; /* buffer full, suspend reading */
2246 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
2247 if (0 != left.rel_value_us)
2248 {
2249 if (max_queue_length > queue->backpressure)
2250 {
2251 /* continue reading */
2252 queue->read_task =
2254 }
2255 return;
2256 }
2258 "Queue %p was idle for %s, disconnecting\n",
2259 queue,
2262 GNUNET_YES));
2264}
2265
2266
2274static struct sockaddr *
2276 struct sockaddr_in6 v6,
2277 unsigned int port)
2278{
2279 struct sockaddr *in;
2280
2281 v6.sin6_family = AF_INET6;
2282 v6.sin6_port = htons ((uint16_t) port);
2283#if HAVE_SOCKADDR_IN_SIN_LEN
2284 v6.sin6_len = sizeof(struct sockaddr_in6);
2285#endif
2286 v6.sin6_flowinfo = 0;
2287 v6.sin6_scope_id = 0;
2288 in = GNUNET_memdup (&v6, sizeof(v6));
2289 *sock_len = sizeof(struct sockaddr_in6);
2290
2291 return in;
2292}
2293
2294
2302static struct sockaddr *
2304 struct sockaddr_in v4,
2305 unsigned int port)
2306{
2307 struct sockaddr *in;
2308
2309 v4.sin_family = AF_INET;
2310 v4.sin_port = htons ((uint16_t) port);
2311#if HAVE_SOCKADDR_IN_SIN_LEN
2312 v4.sin_len = sizeof(struct sockaddr_in);
2313#endif
2314 in = GNUNET_memdup (&v4, sizeof(v4));
2315 *sock_len = sizeof(struct sockaddr_in);
2316 return in;
2317}
2318
2319
2326static struct PortOnlyIpv4Ipv6 *
2327tcp_address_to_sockaddr_port_only (const char *bindto, unsigned int *port)
2328{
2329 struct PortOnlyIpv4Ipv6 *po;
2330 struct sockaddr_in *i4;
2331 struct sockaddr_in6 *i6;
2332 socklen_t sock_len_ipv4;
2333 socklen_t sock_len_ipv6;
2334
2335 /* interpreting value as just a PORT number */
2336 if (*port > UINT16_MAX)
2337 {
2339 "BINDTO specification `%s' invalid: value too large for port\n",
2340 bindto);
2341 return NULL;
2342 }
2343
2344 po = GNUNET_new (struct PortOnlyIpv4Ipv6);
2345
2346 if (GNUNET_YES == disable_v6)
2347 {
2348 i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
2349 po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
2350 *port);
2351 po->addr_len_ipv4 = sock_len_ipv4;
2352 }
2353 else
2354 {
2355
2356 i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
2357 po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
2358 *port);
2359 po->addr_len_ipv4 = sock_len_ipv4;
2360
2361 i6 = GNUNET_malloc (sizeof(struct sockaddr_in6));
2362 po->addr_ipv6 = tcp_address_to_sockaddr_numeric_v6 (&sock_len_ipv6, *i6,
2363 *port);
2364
2365 po->addr_len_ipv6 = sock_len_ipv6;
2366
2367 GNUNET_free (i6);
2368 }
2369
2370 GNUNET_free (i4);
2371
2372 return po;
2373}
2374
2375
2382static char *
2383extract_address (const char *bindto)
2384{
2385 char *addr;
2386 char *start;
2387 char *token;
2388 char *cp;
2389 char *rest = NULL;
2390
2392 "extract address with bindto %s\n",
2393 bindto);
2394
2395 if (NULL == bindto)
2397 "bindto is NULL\n");
2398
2399 cp = GNUNET_strdup (bindto);
2400
2402 "extract address 2\n");
2403
2404 start = cp;
2405 if (('[' == *cp) && (']' == cp[strlen (cp) - 1]))
2406 {
2407 start++; /* skip over '['*/
2408 cp[strlen (cp) - 1] = '\0'; /* eat ']'*/
2409 addr = GNUNET_strdup (start);
2410 }
2411 else
2412 {
2413 token = strtok_r (cp, "]", &rest);
2414 if (strlen (bindto) == strlen (token))
2415 {
2416 token = strtok_r (cp, ":", &rest);
2417 addr = GNUNET_strdup (token);
2418 }
2419 else
2420 {
2421 token++;
2422 addr = GNUNET_strdup (token);
2423 }
2424 }
2425
2427 "tcp address: %s\n",
2428 addr);
2429 GNUNET_free (cp);
2430 return addr;
2431}
2432
2433
2440static unsigned int
2441extract_port (const char *addr_and_port)
2442{
2443 unsigned int port;
2444 char dummy[2];
2445 char *token;
2446 char *addr;
2447 char *colon;
2448 char *cp;
2449 char *rest = NULL;
2450
2451 if (NULL != addr_and_port)
2452 {
2453 cp = GNUNET_strdup (addr_and_port);
2454 token = strtok_r (cp, "]", &rest);
2455 if (strlen (addr_and_port) == strlen (token))
2456 {
2457 colon = strrchr (cp, ':');
2458 if (NULL == colon)
2459 {
2460 GNUNET_free (cp);
2461 return 0;
2462 }
2463 addr = colon;
2464 addr++;
2465 }
2466 else
2467 {
2468 token = strtok_r (NULL, "]", &rest);
2469 if (NULL == token)
2470 {
2471 GNUNET_free (cp);
2472 return 0;
2473 }
2474 else
2475 {
2476 addr = token;
2477 addr++;
2478 }
2479 }
2480
2481
2482 if (1 == sscanf (addr, "%u%1s", &port, dummy))
2483 {
2484 /* interpreting value as just a PORT number */
2485 if (port > UINT16_MAX)
2486 {
2488 "Port `%u' invalid: value too large for port\n",
2489 port);
2490 GNUNET_free (cp);
2491 return 0;
2492 }
2493 }
2494 else
2495 {
2497 "BINDTO specification invalid: last ':' not followed by number\n");
2498 GNUNET_free (cp);
2499 return 0;
2500 }
2501 GNUNET_free (cp);
2502 }
2503 else
2504 {
2506 "return 0\n");
2507 /* interpret missing port as 0, aka pick any free one */
2508 port = 0;
2509 }
2510
2511 return port;
2512}
2513
2514
2522static struct sockaddr *
2523tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
2524{
2525 struct sockaddr *in;
2526 unsigned int port;
2527 struct sockaddr_in v4;
2528 struct sockaddr_in6 v6;
2529 char *start;
2530
2531 memset (&v4, 0, sizeof(v4));
2532 start = extract_address (bindto);
2533 GNUNET_assert (NULL != start);
2535 "start %s\n",
2536 start);
2537
2539 "!bindto %s\n",
2540 bindto);
2541
2542
2543 if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
2544 {
2545 port = extract_port (bindto);
2546
2548 "port %u\n",
2549 port);
2550
2551 in = tcp_address_to_sockaddr_numeric_v4 (sock_len, v4, port);
2552 }
2553 else if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
2554 {
2555 port = extract_port (bindto);
2556 in = tcp_address_to_sockaddr_numeric_v6 (sock_len, v6, port);
2557 }
2558 else
2559 {
2560 GNUNET_assert (0);
2561 }
2562
2564 return in;
2565}
2566
2567
2576static void
2578 const struct GNUNET_MessageHeader *msg,
2579 void *impl_state)
2580{
2581 struct Queue *queue = impl_state;
2582 uint16_t msize = ntohs (msg->size);
2583 struct TCPBox box;
2585 "In MQ send. Queue finishing: %s; write task running: %s\n",
2586 (GNUNET_YES == queue->finishing) ? "yes" : "no",
2587 (NULL == queue->write_task) ? "yes" : "no");
2588 GNUNET_assert (mq == queue->mq);
2589 queue->mq_awaits_continue = GNUNET_YES;
2590 if (GNUNET_YES == queue->finishing)
2591 return; /* this queue is dying, drop msg */
2592 GNUNET_assert (0 == queue->pwrite_off);
2594 box.header.size = htons (msize);
2595 calculate_hmac (&queue->out_hmac, msg, msize, &box.hmac);
2596 memcpy (&queue->pwrite_buf[queue->pwrite_off], &box, sizeof(box));
2597 queue->pwrite_off += sizeof(box);
2598 memcpy (&queue->pwrite_buf[queue->pwrite_off], msg, msize);
2599 queue->pwrite_off += msize;
2601 "%lu bytes of plaintext to send\n", queue->pwrite_off);
2602 GNUNET_assert (NULL != queue->sock);
2603 if (NULL == queue->write_task)
2604 queue->write_task =
2606 queue->sock,
2607 &queue_write,
2608 queue);
2609}
2610
2611
2620static void
2621mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state)
2622{
2623 struct Queue *queue = impl_state;
2624
2625 if (mq == queue->mq)
2626 {
2627 queue->mq = NULL;
2629 }
2630}
2631
2632
2639static void
2640mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
2641{
2642 struct Queue *queue = impl_state;
2643
2644 GNUNET_assert (0 != queue->pwrite_off);
2645 queue->pwrite_off = 0;
2646}
2647
2648
2658static void
2659mq_error (void *cls, enum GNUNET_MQ_Error error)
2660{
2661 struct Queue *queue = cls;
2662
2664 "MQ error in queue to %s: %d\n",
2665 GNUNET_i2s (&queue->target),
2666 (int) error);
2668}
2669
2670
2678static void
2680{
2681 queue->nt =
2682 GNUNET_NT_scanner_get_type (is, queue->address, queue->address_len);
2684 queue_map,
2685 &queue->key,
2686 queue,
2689 "# queues active",
2691 GNUNET_NO);
2692 queue->timeout =
2695 &mq_destroy,
2696 &mq_cancel,
2697 queue,
2698 NULL,
2699 &mq_error,
2700 queue);
2701}
2702
2703
2714static void
2716 const struct GNUNET_CRYPTO_ElligatorRepresentative *repr)
2717{
2718 struct TcpHandshakeSignature ths;
2719 struct TCPConfirmation tc;
2720
2721 memcpy (queue->cwrite_buf, repr, sizeof(*repr));
2722 queue->cwrite_off = sizeof(*repr);
2723 /* compute 'tc' and append in encrypted format to cwrite_buf */
2724 tc.sender = my_identity;
2725 tc.monotonic_time =
2728 &tc.challenge,
2729 sizeof(tc.challenge));
2730 ths.purpose.purpose = htonl (
2732 ths.purpose.size = htonl (sizeof(ths));
2733 ths.sender = my_identity;
2734 ths.receiver = queue->target;
2735 ths.ephemeral = *repr;
2736 ths.monotonic_time = tc.monotonic_time;
2737 ths.challenge = tc.challenge;
2739 &ths,
2740 &tc.sender_sig);
2741 GNUNET_assert (0 ==
2742 gcry_cipher_encrypt (queue->out_cipher,
2743 &queue->cwrite_buf[queue->cwrite_off],
2744 sizeof(tc),
2745 &tc,
2746 sizeof(tc)));
2747 queue->challenge = tc.challenge;
2748 queue->cwrite_off += sizeof(tc);
2749
2751 "handshake written\n");
2752}
2753
2754
2762static void
2764{
2766 struct GNUNET_HashCode k;
2767
2769 &repr, &k);
2770 setup_out_cipher (queue, &k);
2771 transmit_kx (queue, &repr);
2772}
2773
2774
2780static void
2781handshake_monotime_store_cb (void *cls, int success)
2782{
2783 struct Queue *queue = cls;
2784 if (GNUNET_OK != success)
2785 {
2787 "Failed to store handshake monotonic time in PEERSTORE!\n");
2788 }
2789 queue->handshake_monotime_sc = NULL;
2790 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
2791}
2792
2793
2801static void
2803 const struct GNUNET_PEERSTORE_Record *record,
2804 const char *emsg)
2805{
2806 struct Queue *queue = cls;
2807 struct GNUNET_TIME_AbsoluteNBO *mtbe;
2808 struct GNUNET_TIME_Absolute mt;
2809 const struct GNUNET_PeerIdentity *pid;
2810 struct GNUNET_TIME_AbsoluteNBO *handshake_monotonic_time;
2811
2812 (void) emsg;
2813
2814 handshake_monotonic_time = &queue->handshake_monotonic_time;
2815 pid = &queue->target;
2817 "tcp handshake with us %s\n",
2819 if (NULL == record)
2820 {
2821 queue->handshake_monotime_get = NULL;
2822 return;
2823 }
2825 "tcp handshake from peer %s\n",
2826 GNUNET_i2s (pid));
2827 if (sizeof(*mtbe) != record->value_size)
2828 {
2829 GNUNET_PEERSTORE_iteration_next (queue->handshake_ack_monotime_get, 1);
2830 GNUNET_break (0);
2831 return;
2832 }
2833 mtbe = record->value;
2834 mt = GNUNET_TIME_absolute_ntoh (*mtbe);
2836 queue->handshake_monotonic_time).abs_value_us)
2837 {
2839 "Queue from %s dropped, handshake monotime in the past\n",
2840 GNUNET_i2s (&queue->target));
2841 GNUNET_break (0);
2842 GNUNET_PEERSTORE_iteration_stop (queue->handshake_ack_monotime_get);
2843 queue->handshake_ack_monotime_get = NULL;
2845 return;
2846 }
2847 queue->handshake_monotime_sc = GNUNET_PEERSTORE_store (peerstore,
2848 "transport_tcp_communicator",
2849 pid,
2851 handshake_monotonic_time,
2852 sizeof(*
2853 handshake_monotonic_time),
2856 &
2858 queue);
2859}
2860
2861
2873static int
2875 struct TCPConfirmation *tc,
2876 char *ibuf)
2877{
2878 struct TcpHandshakeSignature ths;
2880
2882 0 ==
2883 gcry_cipher_decrypt (queue->in_cipher,
2884 tc,
2885 sizeof(*tc),
2886 &ibuf[sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)],
2887 sizeof(*tc)));
2888 ths.purpose.purpose = htonl (
2890 ths.purpose.size = htonl (sizeof(ths));
2891 ths.sender = tc->sender;
2892 ths.receiver = my_identity;
2893 memcpy (&ths.ephemeral, ibuf, sizeof(struct GNUNET_CRYPTO_EcdhePublicKey));
2894 ths.monotonic_time = tc->monotonic_time;
2895 ths.challenge = tc->challenge;
2898 &ths,
2899 &tc->sender_sig,
2900 &tc->sender.public_key);
2901 if (GNUNET_YES == ret)
2902 queue->handshake_monotime_get =
2904 "transport_tcp_communicator",
2905 &queue->target,
2908 queue);
2909 return ret;
2910}
2911
2912
2920static void
2921queue_read_kx (void *cls)
2922{
2923 struct Queue *queue = cls;
2924 ssize_t rcvd;
2925 struct GNUNET_TIME_Relative left;
2926 struct TCPConfirmation tc;
2927
2928 queue->read_task = NULL;
2929 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
2930 if (0 == left.rel_value_us)
2931 {
2933 return;
2934 }
2935 rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
2936 &queue->cread_buf[queue->cread_off],
2937 BUF_SIZE - queue->cread_off);
2939 "Received %lu bytes to write in buffer of size %lu for KX from queue %p (expires in %"
2940 PRIu64 ")\n",
2941 rcvd, BUF_SIZE - queue->cread_off, queue, left.rel_value_us);
2942 if (-1 == rcvd)
2943 {
2944 if ((EAGAIN != errno) && (EINTR != errno))
2945 {
2948 return;
2949 }
2950 queue->read_task =
2952 return;
2953 }
2954 if (0 == rcvd)
2955 {
2956 /* Orderly shutdown of connection */
2958 "Socket for queue %p seems to have been closed\n", queue);
2960 return;
2961 }
2962 queue->cread_off += rcvd;
2963 if (queue->cread_off < INITIAL_KX_SIZE)
2964 {
2965 /* read more */
2967 "%lu/%lu bytes of KX read. Rescheduling...\n",
2968 queue->cread_off, INITIAL_KX_SIZE);
2969 queue->read_task =
2971 return;
2972 }
2973 /* we got all the data, let's find out who we are talking to! */
2975 *)
2976 queue->cread_buf,
2977 queue);
2978 if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, queue->cread_buf))
2979 {
2981 "Invalid TCP KX received from %s\n",
2982 GNUNET_a2s (queue->address, queue->address_len));
2984 return;
2985 }
2986 if (0 !=
2987 memcmp (&tc.sender, &queue->target, sizeof(struct GNUNET_PeerIdentity)))
2988 {
2990 "Invalid sender in TCP KX received from %s\n",
2991 GNUNET_a2s (queue->address, queue->address_len));
2993 return;
2994 }
2995 send_challenge (tc.challenge, queue);
2996 queue->write_task =
2998 queue->sock,
2999 &queue_write,
3000 queue);
3001
3002 /* update queue timeout */
3003 queue->timeout =
3005 /* prepare to continue with regular read task immediately */
3006 memmove (queue->cread_buf,
3007 &queue->cread_buf[INITIAL_KX_SIZE],
3008 queue->cread_off - (INITIAL_KX_SIZE));
3010 "cread_off is %lu bytes before adjusting\n",
3011 queue->cread_off);
3012 queue->cread_off -= INITIAL_KX_SIZE;
3014 "cread_off set to %lu bytes\n",
3015 queue->cread_off);
3017}
3018
3019
3026static void
3027proto_read_kx (void *cls)
3028{
3029 struct ProtoQueue *pq = cls;
3030 ssize_t rcvd;
3031 struct GNUNET_TIME_Relative left;
3032 struct Queue *queue;
3033 struct TCPConfirmation tc;
3035
3036 pq->read_task = NULL;
3038 if (0 == left.rel_value_us)
3039 {
3040 free_proto_queue (pq);
3041 return;
3042 }
3043 rcvd = GNUNET_NETWORK_socket_recv (pq->sock,
3044 &pq->ibuf[pq->ibuf_off],
3045 sizeof(pq->ibuf) - pq->ibuf_off);
3047 "Proto received %lu bytes for KX\n", rcvd);
3048 if (-1 == rcvd)
3049 {
3050 if ((EAGAIN != errno) && (EINTR != errno))
3051 {
3053 free_proto_queue (pq);
3054 return;
3055 }
3056 /* try again */
3057 pq->read_task =
3059 return;
3060 }
3061 if (0 == rcvd)
3062 {
3063 /* Orderly shutdown of connection */
3065 "Socket for proto queue %p seems to have been closed\n", pq);
3066 free_proto_queue (pq);
3067 return;
3068 }
3069 pq->ibuf_off += rcvd;
3070 if (sizeof (struct TCPNATProbeMessage) == pq->ibuf_off)
3071 {
3072 struct TCPNATProbeMessage *pm = (struct TCPNATProbeMessage *) pq->ibuf;
3073
3075 &pm->clientIdentity);
3076
3077 queue = GNUNET_new (struct Queue);
3078 queue->target = pm->clientIdentity;
3081 }
3082 else if (pq->ibuf_off > sizeof(pq->ibuf))
3083 {
3084 /* read more */
3085 pq->read_task =
3087 return;
3088 }
3089 else
3090 {
3091 /* we got all the data, let's find out who we are talking to! */
3092 queue = GNUNET_new (struct Queue);
3093 setup_in_cipher_elligator ((const struct
3095 ibuf,
3096 queue);
3097 if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, pq->ibuf))
3098 {
3100 "Invalid TCP KX received from %s\n",
3101 GNUNET_a2s (pq->address, pq->address_len));
3102 gcry_cipher_close (queue->in_cipher);
3104 free_proto_queue (pq);
3105 return;
3106 }
3107 queue->target = tc.sender;
3110 }
3111 queue->address = pq->address; /* steals reference */
3112 queue->address_len = pq->address_len;
3113 queue->listen_sock = pq->listen_sock;
3114 queue->sock = pq->sock;
3115
3117 "created queue with target %s\n",
3118 GNUNET_i2s (&queue->target));
3119
3121 "start kx proto\n");
3122
3124 boot_queue (queue);
3125 queue->read_task =
3127 queue->sock,
3128 read_task,
3129 queue);
3130 queue->write_task =
3132 queue->sock,
3133 &queue_write,
3134 queue);
3135 // TODO To early! Move it somewhere else.
3136 // send_challenge (tc.challenge, queue);
3137 queue->challenge_received = tc.challenge;
3138
3140 GNUNET_free (pq);
3141}
3142
3143
3144static struct ProtoQueue *
3146 struct sockaddr *in,
3147 socklen_t addrlen)
3148{
3149 struct ProtoQueue *pq = GNUNET_new (struct ProtoQueue);
3150
3151 if (NULL == sock)
3152 {
3153 // sock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET, addr, addrlen);
3154 sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, 0);
3155 if (NULL == sock)
3156 {
3158 "socket(%d) failed: %s",
3159 in->sa_family,
3160 strerror (errno));
3161 GNUNET_free (in);
3162 GNUNET_free (pq);
3163 return NULL;
3164 }
3165 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, addrlen)) &&
3166 (errno != EINPROGRESS))
3167 {
3169 "connect to `%s' failed: %s",
3170 GNUNET_a2s (in, addrlen),
3171 strerror (errno));
3173 GNUNET_free (in);
3174 GNUNET_free (pq);
3175 return NULL;
3176 }
3177 }
3178 pq->address_len = addrlen;
3179 pq->address = in;
3181 pq->sock = sock;
3183 pq->sock,
3185 pq);
3187
3188 return pq;
3189}
3190
3191
3199static void
3200listen_cb (void *cls)
3201{
3202 struct sockaddr_storage in;
3203 socklen_t addrlen;
3204 struct GNUNET_NETWORK_Handle *sock;
3205 struct ListenTask *lt;
3206 struct sockaddr *in_addr;
3207
3209 "listen_cb\n");
3210
3211 lt = cls;
3212
3213 lt->listen_task = NULL;
3214 GNUNET_assert (NULL != lt->listen_sock);
3215 addrlen = sizeof(in);
3216 memset (&in, 0, sizeof(in));
3218 (struct sockaddr*) &in,
3219 &addrlen);
3220 if ((NULL == sock) && ((EMFILE == errno) || (ENFILE == errno)))
3221 return; /* system limit reached, wait until connection goes down */
3223 lt->listen_sock,
3224 &listen_cb,
3225 lt);
3226 if ((NULL == sock) && ((EAGAIN == errno) || (ENOBUFS == errno)))
3227 return;
3228 if (NULL == sock)
3229 {
3231 return;
3232 }
3233 in_addr = GNUNET_memdup (&in, addrlen);
3234 create_proto_queue (sock, in_addr, addrlen);
3235}
3236
3237
3238static void
3240 const struct sockaddr *addr,
3241 socklen_t addrlen)
3242{
3243 (void) cls;
3244 struct TCPNATProbeMessage pm;
3245 struct ProtoQueue *pq;
3246 struct sockaddr *in_addr;
3247
3249 "addr->sa_family %d\n",
3250 addr->sa_family);
3252 "Try to connect back\n");
3253 in_addr = GNUNET_memdup (addr, addrlen);
3255 "in_addr->sa_family %d\n",
3256 in_addr->sa_family);
3257 pq = create_proto_queue (NULL, in_addr, addrlen);
3258 if (NULL != pq)
3259 {
3260 pm.header.size = htons (sizeof(struct TCPNATProbeMessage));
3261 pm.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE);
3262 pm.clientIdentity = my_identity;
3263 memcpy (pq->write_buf, &pm, sizeof(struct TCPNATProbeMessage));
3264 pq->write_off = sizeof(struct TCPNATProbeMessage);
3266 pq->sock,
3268 pq);
3269 }
3270 else
3271 {
3273 "Couldn't create ProtoQueue for sending TCPNATProbeMessage\n");
3274 }
3275}
3276
3277
3278static void
3280{
3281 struct sockaddr *in = cls;
3282 struct PendingReversal *pending_reversal;
3283 struct GNUNET_HashCode key;
3284
3286 sizeof(struct sockaddr),
3287 &key);
3289 &key);
3290
3291 GNUNET_assert (NULL != pending_reversal);
3292
3294 &key,
3295 pending_reversal))
3297 "No pending reversal found for address %s\n",
3298 GNUNET_a2s (in, sizeof (struct sockaddr)));
3299 GNUNET_free (pending_reversal->in);
3300 GNUNET_free (pending_reversal);
3301}
3302
3303
3322static int
3323mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
3324{
3325 struct sockaddr *in;
3326 socklen_t in_len = 0;
3327 const char *path;
3328 struct sockaddr_in *v4;
3329 struct sockaddr_in6 *v6;
3330 unsigned int is_natd = GNUNET_NO;
3331 struct GNUNET_HashCode key;
3332 struct GNUNET_HashCode queue_map_key;
3333 struct GNUNET_HashContext *hsh;
3334 struct Queue *queue;
3335
3337 "Connecting to %s at %s\n",
3338 GNUNET_i2s (peer),
3339 address);
3340 if (0 != strncmp (address,
3342 strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
3343 {
3344 GNUNET_break_op (0);
3345 return GNUNET_SYSERR;
3346 }
3347 path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
3348 in = tcp_address_to_sockaddr (path, &in_len);
3349
3350 if (NULL == in)
3351 {
3353 "Failed to setup TCP socket address\n");
3354 return GNUNET_SYSERR;
3355 }
3356
3358 "in %s\n",
3359 GNUNET_a2s (in, in_len));
3360
3363 GNUNET_CRYPTO_hash_context_read (hsh, peer, sizeof (*peer));
3364 GNUNET_CRYPTO_hash_context_finish (hsh, &queue_map_key);
3366
3367 if (NULL != queue)
3368 {
3370 "Queue for %s already exists or is in construction\n", address);
3371 GNUNET_free (in);
3372 return GNUNET_NO;
3373 }
3374 switch (in->sa_family)
3375 {
3376 case AF_INET:
3377 v4 = (struct sockaddr_in *) in;
3378 if (0 == v4->sin_port)
3379 {
3380 is_natd = GNUNET_YES;
3382 sizeof(struct sockaddr),
3383 &key);
3386 &key))
3387 {
3389 "There is already a request reversal for `%s'at `%s'\n",
3390 GNUNET_i2s (peer),
3391 address);
3392 GNUNET_free (in);
3393 return GNUNET_SYSERR;
3394 }
3395 }
3396 break;
3397
3398 case AF_INET6:
3399 if (GNUNET_YES == disable_v6)
3400 {
3402 "IPv6 disabled, skipping %s\n", address);
3403 GNUNET_free (in);
3404 return GNUNET_SYSERR;
3405 }
3406 v6 = (struct sockaddr_in6 *) in;
3407 if (0 == v6->sin6_port)
3408 {
3410 "Request reversal for `%s' at `%s' not possible for an IPv6 address\n",
3411 GNUNET_i2s (peer),
3412 address);
3413 GNUNET_free (in);
3414 return GNUNET_SYSERR;
3415 }
3416 break;
3417
3418 default:
3419 GNUNET_assert (0);
3420 }
3421
3422 if (GNUNET_YES == is_natd)
3423 {
3424 struct sockaddr_in local_sa;
3425 struct PendingReversal *pending_reversal;
3426
3427 memset (&local_sa, 0, sizeof(local_sa));
3428 local_sa.sin_family = AF_INET;
3429 local_sa.sin_port = htons (bind_port);
3430 /* We leave sin_address at 0, let the kernel figure it out,
3431 even if our bind() is more specific. (May want to reconsider
3432 later.) */
3433 if (GNUNET_OK != GNUNET_NAT_request_reversal (nat, &local_sa, v4))
3434 {
3436 "request reversal for `%s' at `%s' failed\n",
3437 GNUNET_i2s (peer),
3438 address);
3439 GNUNET_free (in);
3440 return GNUNET_SYSERR;
3441 }
3442 pending_reversal = GNUNET_new (struct PendingReversal);
3443 pending_reversal->in = in;
3446 &key,
3447 pending_reversal,
3449 pending_reversal->target = *peer;
3451 &
3453 in);
3455 "Created NAT WAIT connection to `%s' at `%s'\n",
3456 GNUNET_i2s (peer),
3457 GNUNET_a2s (in, sizeof (struct sockaddr)));
3458 }
3459 else
3460 {
3461 struct GNUNET_NETWORK_Handle *sock;
3462
3463 sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM,
3464 IPPROTO_TCP);
3465 if (NULL == sock)
3466 {
3468 "socket(%d) failed: %s",
3469 in->sa_family,
3470 strerror (errno));
3471 GNUNET_free (in);
3472 return GNUNET_SYSERR;
3473 }
3474 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, in_len)) &&
3475 (errno != EINPROGRESS))
3476 {
3478 "connect to `%s' failed: %s",
3479 address,
3480 strerror (errno));
3482 GNUNET_free (in);
3483 return GNUNET_SYSERR;
3484 }
3485
3486 queue = GNUNET_new (struct Queue);
3487 queue->target = *peer;
3488 queue->key = queue_map_key;
3489 queue->address = in;
3490 queue->address_len = in_len;
3491 queue->sock = sock;
3493 boot_queue (queue);
3495 "booted queue with target %s\n",
3496 GNUNET_i2s (&queue->target));
3497 // queue->mq_awaits_continue = GNUNET_YES;
3498 queue->read_task =
3500 queue->sock,
3502 queue);
3503
3504
3506 "start kx mq_init\n");
3507
3509 queue->write_task =
3511 queue->sock,
3512 &queue_write,
3513 queue);
3514 }
3515
3516 return GNUNET_OK;
3517}
3518
3519
3528static int
3530 const struct GNUNET_HashCode *key,
3531 void *value)
3532{
3533 struct ListenTask *lt = value;
3534
3535 (void) cls;
3536 (void) key;
3537 if (NULL != lt->listen_task)
3538 {
3540 lt->listen_task = NULL;
3541 }
3542 if (NULL != lt->listen_sock)
3543 {
3545 lt->listen_sock = NULL;
3546 }
3547 GNUNET_free (lt);
3548 return GNUNET_OK;
3549}
3550
3551
3560static int
3562 const struct GNUNET_HashCode *target,
3563 void *value)
3564{
3565 struct Queue *queue = value;
3566
3567 (void) cls;
3568 (void) target;
3570 return GNUNET_OK;
3571}
3572
3573
3579static void
3580do_shutdown (void *cls)
3581{
3583 "Shutdown %s!\n",
3584 shutdown_running ? "running" : "not running");
3585
3587 return;
3588 else
3590
3591 while (NULL != proto_head)
3593 if (NULL != nat)
3594 {
3596 nat = NULL;
3597 }
3605 if (NULL != ch)
3606 {
3609 ch = NULL;
3610 }
3611 if (NULL != stats)
3612 {
3614 stats = NULL;
3615 }
3616 if (NULL != my_private_key)
3617 {
3619 my_private_key = NULL;
3620 }
3621 if (NULL != is)
3622 {
3624 is = NULL;
3625 }
3626 if (NULL != peerstore)
3627 {
3629 peerstore = NULL;
3630 }
3631 if (NULL != resolve_request_handle)
3632 {
3635 }
3637 "Shutdown done!\n");
3638}
3639
3640
3652static void
3653enc_notify_cb (void *cls,
3654 const struct GNUNET_PeerIdentity *sender,
3655 const struct GNUNET_MessageHeader *msg)
3656{
3657 (void) cls;
3658 (void) sender;
3659 (void) msg;
3660 GNUNET_break_op (0);
3661}
3662
3663
3677static void
3679 void **app_ctx,
3680 int add_remove,
3682 const struct sockaddr *addr,
3683 socklen_t addrlen)
3684{
3685 char *my_addr;
3687
3689 "nat address cb %s %s\n",
3690 add_remove ? "add" : "remove",
3691 GNUNET_a2s (addr, addrlen));
3692
3693 if (GNUNET_YES == add_remove)
3694 {
3696
3697 GNUNET_asprintf (&my_addr,
3698 "%s-%s",
3700 GNUNET_a2s (addr, addrlen));
3701 nt = GNUNET_NT_scanner_get_type (is, addr, addrlen);
3702 ai =
3704 my_addr,
3705 nt,
3707 GNUNET_free (my_addr);
3708 *app_ctx = ai;
3709 }
3710 else
3711 {
3712 ai = *app_ctx;
3714 *app_ctx = NULL;
3715 }
3716}
3717
3718
3722static void
3723add_addr (struct sockaddr *in, socklen_t in_len)
3724{
3725
3726 struct Addresses *saddrs;
3727
3729 "add address %s\n",
3730 GNUNET_a2s (in, in_len));
3731
3732 saddrs = GNUNET_new (struct Addresses);
3733 saddrs->addr = in;
3734 saddrs->addr_len = in_len;
3736
3738 "after add address %s\n",
3739 GNUNET_a2s (in, in_len));
3740
3742 "add address %s\n",
3743 GNUNET_a2s (saddrs->addr, saddrs->addr_len));
3744
3745 addrs_lens++;
3746}
3747
3748
3756static int
3757init_socket (struct sockaddr *addr,
3758 socklen_t in_len)
3759{
3760 struct sockaddr_storage in_sto;
3761 socklen_t sto_len;
3762 struct GNUNET_NETWORK_Handle *listen_sock;
3763 struct ListenTask *lt;
3764 int sockfd;
3765 struct GNUNET_HashCode h_sock;
3766
3767 if (NULL == addr)
3768 {
3770 "Address is NULL.\n");
3771 return GNUNET_SYSERR;
3772 }
3773
3775 "address %s\n",
3776 GNUNET_a2s (addr, in_len));
3777
3778 listen_sock =
3779 GNUNET_NETWORK_socket_create (addr->sa_family, SOCK_STREAM, IPPROTO_TCP);
3780 if (NULL == listen_sock)
3781 {
3783 return GNUNET_SYSERR;
3784 }
3785
3786 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (listen_sock, addr, in_len))
3787 {
3789 GNUNET_NETWORK_socket_close (listen_sock);
3790 listen_sock = NULL;
3791 return GNUNET_SYSERR;
3792 }
3793
3794 if (GNUNET_OK !=
3795 GNUNET_NETWORK_socket_listen (listen_sock,
3796 5))
3797 {
3799 "listen");
3800 GNUNET_NETWORK_socket_close (listen_sock);
3801 listen_sock = NULL;
3802 return GNUNET_SYSERR;
3803 }
3804
3805 /* We might have bound to port 0, allowing the OS to figure it out;
3806 thus, get the real IN-address from the socket */
3807 sto_len = sizeof(in_sto);
3808
3809 if (0 != getsockname (GNUNET_NETWORK_get_fd (listen_sock),
3810 (struct sockaddr *) &in_sto,
3811 &sto_len))
3812 {
3813 memcpy (&in_sto, addr, in_len);
3814 sto_len = in_len;
3815 }
3816
3817 // addr = (struct sockaddr *) &in_sto;
3818 in_len = sto_len;
3820 "Bound to `%s'\n",
3821 GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len));
3822 if (NULL == stats)
3823 stats = GNUNET_STATISTICS_create ("communicator-tcp", cfg);
3824
3825 if (NULL == is)
3827
3828 if (NULL == my_private_key)
3830 if (NULL == my_private_key)
3831 {
3832 GNUNET_log (
3834 _ (
3835 "Transport service is lacking key configuration settings. Exiting.\n"));
3836 if (NULL != resolve_request_handle)
3839 return GNUNET_SYSERR;
3840 }
3842 /* start listening */
3843
3844 lt = GNUNET_new (struct ListenTask);
3845 lt->listen_sock = listen_sock;
3846
3848 listen_sock,
3849 &listen_cb,
3850 lt);
3851
3853 "creating hash\n");
3854 sockfd = GNUNET_NETWORK_get_fd (lt->listen_sock);
3855 GNUNET_CRYPTO_hash (&sockfd,
3856 sizeof(int),
3857 &h_sock);
3858
3860 "creating map\n");
3861 if (NULL == lt_map)
3863
3865 "creating map entry\n");
3868 &h_sock,
3869 lt,
3871
3873 "map entry created\n");
3874
3875 if (NULL == queue_map)
3877
3878 if (NULL == ch)
3883 &mq_init,
3884 NULL,
3886 NULL);
3887
3888 if (NULL == ch)
3889 {
3890 GNUNET_break (0);
3891 if (NULL != resolve_request_handle)
3894 return GNUNET_SYSERR;
3895 }
3896
3897 add_addr (addr, in_len);
3898 return GNUNET_OK;
3899
3900}
3901
3902
3906static void
3908{
3909 struct sockaddr **saddrs;
3910 socklen_t *saddr_lens;
3911 int i;
3912 size_t len;
3913
3915 "starting nat register!\n");
3916 len = 0;
3917 i = 0;
3918 saddrs = GNUNET_malloc ((addrs_lens) * sizeof(struct sockaddr *));
3919 saddr_lens = GNUNET_malloc ((addrs_lens) * sizeof(socklen_t));
3920 for (struct Addresses *pos = addrs_head; NULL != pos; pos = pos->next)
3921 {
3923 "registering address %s\n",
3925
3926 saddr_lens[i] = addrs_head->addr_len;
3927 len += saddr_lens[i];
3928 saddrs[i] = GNUNET_memdup (addrs_head->addr, saddr_lens[i]);
3929 i++;
3930 }
3931
3933 "registering addresses %lu %lu %lu %lu\n",
3934 (addrs_lens) * sizeof(struct sockaddr *),
3935 (addrs_lens) * sizeof(socklen_t),
3936 len,
3940 IPPROTO_TCP,
3941 addrs_lens,
3942 (const struct sockaddr **) saddrs,
3943 saddr_lens,
3946 NULL /* closure */);
3947 for (i = addrs_lens - 1; i >= 0; i--)
3948 GNUNET_free (saddrs[i]);
3949 GNUNET_free (saddrs);
3950 GNUNET_free (saddr_lens);
3951
3952 if (NULL == nat)
3953 {
3954 GNUNET_break (0);
3955 if (NULL != resolve_request_handle)
3958 }
3959}
3960
3961
3969static void
3971 const struct sockaddr *addr,
3972 socklen_t in_len)
3973{
3974 struct sockaddr_in *v4;
3975 struct sockaddr_in6 *v6;
3976 struct sockaddr *in;
3977
3978 (void) cls;
3979 if (NULL != addr)
3980 {
3981 if (AF_INET == addr->sa_family)
3982 {
3983 v4 = (struct sockaddr_in *) addr;
3984 in = tcp_address_to_sockaddr_numeric_v4 (&in_len, *v4, bind_port);// _global);
3985 }
3986 else if (AF_INET6 == addr->sa_family)
3987 {
3988 v6 = (struct sockaddr_in6 *) addr;
3989 in = tcp_address_to_sockaddr_numeric_v6 (&in_len, *v6, bind_port);// _global);
3990 }
3991 else
3992 {
3994 "Address family %u not suitable (not AF_INET %u nor AF_INET6 %u \n",
3995 addr->sa_family,
3996 AF_INET,
3997 AF_INET6);
3998 return;
3999 }
4000 init_socket (in, in_len);
4001 }
4002 else
4003 {
4005 "Address is NULL. This might be an error or the resolver finished resolving.\n");
4006 if (NULL == addrs_head)
4007 {
4009 "Resolver finished resolving, but we do not listen to an address!.\n");
4010 return;
4011 }
4012 nat_register ();
4013 }
4014}
4015
4016
4025static void
4026run (void *cls,
4027 char *const *args,
4028 const char *cfgfile,
4029 const struct GNUNET_CONFIGURATION_Handle *c)
4030{
4031 char *bindto;
4032 struct sockaddr *in;
4033 socklen_t in_len;
4034 struct sockaddr_in v4;
4035 struct sockaddr_in6 v6;
4036 char *start;
4037 unsigned int port;
4038 char dummy[2];
4039 char *rest = NULL;
4040 struct PortOnlyIpv4Ipv6 *po;
4041 socklen_t addr_len_ipv4;
4042 socklen_t addr_len_ipv6;
4043
4044 (void) cls;
4045
4047 memset (&v4,0,sizeof(struct sockaddr_in));
4048 memset (&v6,0,sizeof(struct sockaddr_in6));
4049 cfg = c;
4050 if (GNUNET_OK !=
4053 "BINDTO",
4054 &bindto))
4055 {
4058 "BINDTO");
4059 return;
4060 }
4061 if (GNUNET_OK !=
4064 "MAX_QUEUE_LENGTH",
4066 {
4068 }
4069 if (GNUNET_OK !=
4072 "REKEY_INTERVAL",
4074 {
4076 }
4077 if (GNUNET_OK !=
4080 "REKEY_MAX_BYTES",
4082 {
4084 }
4086 if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
4087 (GNUNET_YES ==
4090 "DISABLE_V6")))
4091 {
4093 }
4095 if (NULL == peerstore)
4096 {
4097 GNUNET_free (bindto);
4098 GNUNET_break (0);
4100 return;
4101 }
4102
4104
4105 if (1 == sscanf (bindto, "%u%1s", &bind_port, dummy))
4106 {
4110 "address po %s\n",
4112 if (NULL != po->addr_ipv4)
4113 {
4115 }
4116 if (NULL != po->addr_ipv6)
4117 {
4120 }
4121 GNUNET_free (po);
4122 nat_register ();
4123 GNUNET_free (bindto);
4124 return;
4125 }
4126
4127 start = extract_address (bindto);
4128 // FIXME: check for NULL == start...
4129 if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
4130 {
4131 bind_port = extract_port (bindto);
4132
4134 init_socket (in, in_len);
4135 nat_register ();
4137 GNUNET_free (bindto);
4138 return;
4139 }
4140
4141 if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
4142 {
4143 bind_port = extract_port (bindto);
4145 init_socket (in, in_len);
4146 nat_register ();
4148 GNUNET_free (bindto);
4149 return;
4150 }
4151
4152 bind_port = extract_port (bindto);
4154 ":",
4155 &rest),
4156 AF_UNSPEC,
4159 &port);
4160
4161 GNUNET_free (bindto);
4163}
4164
4165
4173int
4174main (int argc, char *const *argv)
4175{
4176 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
4178 };
4179 int ret;
4180
4182 "Starting tcp communicator\n");
4183 if (GNUNET_OK !=
4184 GNUNET_STRINGS_get_utf8_args (argc, argv,
4185 &argc, &argv))
4186 return 2;
4187
4188 ret = (GNUNET_OK ==
4189 GNUNET_PROGRAM_run (argc,
4190 argv,
4191 "gnunet-communicator-tcp",
4192 _ ("GNUnet TCP communicator"),
4193 options,
4194 &run,
4195 NULL))
4196 ? 0
4197 : 1;
4198 GNUNET_free_nz ((void *) argv);
4199 return ret;
4200}
4201
4202
4203/* end of gnunet-communicator-tcp.c */
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
static int ret
Final status code.
Definition: gnunet-arm.c:94
static uint16_t port
Port number.
Definition: gnunet-bcd.c:147
static void calculate_hmac(struct GNUNET_HashCode *hmac_secret, const void *buf, size_t buf_size, struct GNUNET_ShortHashCode *smac)
Compute mac over buf, and ratched the hmac_secret.
static void queue_finish(struct Queue *queue)
Append a 'finish' message to the outgoing transmission.
static void boot_queue(struct Queue *queue)
Add the given queue to our internal data structure.
static unsigned int bind_port
The port the communicator should be assigned to.
static size_t try_handle_plaintext(struct Queue *queue)
Test if we have received a full message in plaintext.
static void pass_plaintext_to_core(struct Queue *queue, const void *plaintext, size_t plaintext_len)
We received plaintext_len bytes of plaintext on queue.
static struct sockaddr * tcp_address_to_sockaddr_numeric_v6(socklen_t *sock_len, struct sockaddr_in6 v6, unsigned int port)
Convert a struct sockaddr_in6 to astruct sockaddr *`.
static struct GNUNET_PeerIdentity my_identity
Our public key.
#define COMMUNICATOR_ADDRESS_PREFIX
Address prefix used by the communicator.
static void mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state)
Signature of functions implementing the destruction of a message queue.
#define ADDRESS_VALIDITY_PERIOD
How long do we believe our addresses to remain up (before the other peer should revalidate).
static struct PortOnlyIpv4Ipv6 * tcp_address_to_sockaddr_port_only(const char *bindto, unsigned int *port)
Convert TCP bind specification to a struct PortOnlyIpv4Ipv6 *
#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 int disable_v6
IPv6 disabled.
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.
static struct GNUNET_CONTAINER_MultiHashMap * pending_reversals
Map of pending reversals.
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
static void queue_destroy(struct Queue *queue)
Functions with this signature are called whenever we need to close a queue due to a disconnect or fai...
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static void enc_notify_cb(void *cls, const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *msg)
Function called when the transport service has received an acknowledgement for this communicator (!...
static void handshake_ack_monotime_store_cb(void *cls, int success)
Callback called when peerstore store operation for handshake ack monotime value is finished.
static struct GNUNET_PEERSTORE_Handle * peerstore
Database for peer's HELLOs.
static int pending_reversals_delete_it(void *cls, const struct GNUNET_HashCode *key, void *value)
static struct ProtoQueue * proto_tail
Protoqueues DLL tail.
static void queue_read_kx(void *cls)
Read from the socket of the queue until we have enough data to initialize the decryption logic and ca...
static int get_lt_delete_it(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator over all ListenTasks to clean up.
static void inject_rekey(struct Queue *queue)
Inject a struct TCPRekey message into the queue's plaintext buffer.
static struct GNUNET_TIME_Relative rekey_interval
The rekey interval.
#define NAT_TIMEOUT
How long until we give up on establishing an NAT connection? Must be > 4 RTT.
#define BUF_SIZE
Size of our IO buffers for ciphertext data.
static void do_shutdown(void *cls)
Shutdown the UNIX communicator.
#define COMMUNICATOR_CONFIG_SECTION
Configuration section used by the communicator.
static struct GNUNET_CONTAINER_MultiHashMap * queue_map
Queues (map from peer identity to struct Queue)
static void proto_read_kx(void *cls)
Read from the socket of the proto queue until we have enough data to upgrade to full queue.
static void nat_address_cb(void *cls, void **app_ctx, int add_remove, enum GNUNET_NAT_AddressClass ac, const struct sockaddr *addr, socklen_t addrlen)
Signature of the callback passed to GNUNET_NAT_register() for a function to call whenever our set of ...
static struct sockaddr * tcp_address_to_sockaddr_numeric_v4(socklen_t *sock_len, struct sockaddr_in v4, unsigned int port)
Convert a struct sockaddr_in4 to astruct sockaddr *`.
static void check_and_remove_pending_reversal(struct sockaddr *in, sa_family_t sa_family, struct GNUNET_PeerIdentity *sender)
static void init_socket_resolv(void *cls, const struct sockaddr *addr, socklen_t in_len)
This method is the callback called by the resolver API, and wraps method init_socket.
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
static unsigned long long max_queue_length
Maximum queue length before we stop reading towards the transport service.
struct GNUNET_RESOLVER_RequestHandle * resolve_request_handle
Handle for DNS lookup of bindto address.
static void nat_register()
This method reads from the DLL addrs_head to register them at the NAT service.
static int addrs_lens
Number of addresses in the DLL for register at NAT service.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Setup communicator and launch network interactions.
static struct GNUNET_NAT_Handle * nat
Connection to NAT service.
static void pending_reversal_timeout(void *cls)
#define PROTO_QUEUE_TIMEOUT
How long do we wait until we must have received the initial KX?
static void queue_read(void *cls)
Queue read task.
#define REKEY_MAX_BYTES
How often do we rekey based on number of bytes transmitted? (additionally randomized).
static int get_queue_delete_it(void *cls, const struct GNUNET_HashCode *target, void *value)
Iterator over all message queues to clean up.
static void mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state)
Implementation function that cancels the currently sent message.
#define INITIAL_KX_SIZE
Size of the initial key exchange message sent first in both directions.
static void handshake_ack_monotime_cb(void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_A...
static void setup_in_cipher_elligator(const struct GNUNET_CRYPTO_ElligatorRepresentative *repr, struct Queue *queue)
Setup cipher of queue for decryption from an elligator representative.
static void transmit_kx(struct Queue *queue, const struct GNUNET_CRYPTO_ElligatorRepresentative *repr)
Generate and transmit our ephemeral key and the signature for the initial KX with the other peer.
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.
static int shutdown_running
A flag indicating we are already doing a shutdown.
static int decrypt_and_check_tc(struct Queue *queue, struct TCPConfirmation *tc, char *ibuf)
We have received the first bytes from the other side on a queue.
#define DEFAULT_REKEY_INTERVAL
How often do we rekey based on time (at least)
int main(int argc, char *const *argv)
The main function for the UNIX communicator.
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Our private key.
static void queue_write(void *cls)
We have been notified that our socket is ready to write.
static void add_addr(struct sockaddr *in, socklen_t in_len)
This method adds addresses to the DLL, that are later register at the NAT service.
static void handshake_monotime_cb(void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE w...
static struct Addresses * addrs_head
Head of DLL with addresses we like to register at NAT service.
static struct sockaddr * tcp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
Convert TCP bind specification to a struct sockaddr *
static struct Addresses * addrs_tail
Head of DLL with addresses we like to register at NAT service.
#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 unsigned long long rekey_max_bytes
The rekey byte maximum.
static void core_read_finished_cb(void *cls, int success)
Core tells us it is done processing a message that transport received on a queue with status success.
static struct GNUNET_TRANSPORT_AddressIdentifier * ai
Handle to the operation that publishes our address.
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
static char * address
GNS address for this phone.
struct GNUNET_HashCode key
The key used in the DHT.
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
struct GNUNET_SCHEDULER_Task * read_task
static char * value
Value of the record to add/remove.
static uint32_t type
Type string converted to DNS type value.
static struct GNUNET_NAT_AUTO_Test * nt
Handle to a NAT test operation.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
static struct GNUNET_TRANSPORT_PluginMonitor * pm
Handle if we are monitoring plugin session activity.
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
Core service; the main API for encrypted P2P communications.
API to the peerstore service.
Constants for network protocols.
Functions related to doing DNS lookups.
API to create, modify and access statistics.
API of the transport service towards the communicator processes.
void GNUNET_TRANSPORT_communicator_address_remove(struct GNUNET_TRANSPORT_AddressIdentifier *ai)
Notify transport service about an address that this communicator no longer provides for this peer.
int GNUNET_TRANSPORT_communicator_receive(struct GNUNET_TRANSPORT_CommunicatorHandle *handle, const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *msg, struct GNUNET_TIME_Relative expected_addr_validity, GNUNET_TRANSPORT_MessageCompletedCallback cb, void *cb_cls)
Notify transport service that the communicator has received a message.
void GNUNET_TRANSPORT_communicator_mq_del(struct GNUNET_TRANSPORT_QueueHandle *qh)
Notify transport service that an MQ became unavailable due to a disconnect or timeout.
#define GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED
Queue length.
struct GNUNET_TRANSPORT_QueueHandle * GNUNET_TRANSPORT_communicator_mq_add(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const struct GNUNET_PeerIdentity *peer, const char *address, uint32_t mtu, uint64_t q_len, uint32_t priority, enum GNUNET_NetworkType nt, enum GNUNET_TRANSPORT_ConnectionStatus cs, struct GNUNET_MQ_Handle *mq)
Notify transport service that a MQ became available due to an "inbound" connection or because the com...
void GNUNET_TRANSPORT_communicator_disconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
Disconnect from the transport service.
struct GNUNET_TRANSPORT_CommunicatorHandle * GNUNET_TRANSPORT_communicator_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *config_section_name, const char *addr_prefix, enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, GNUNET_TRANSPORT_CommunicatorMqInit mq_init, void *mq_init_cls, GNUNET_TRANSPORT_CommunicatorNotify notify_cb, void *notify_cb_cls)
Connect to the transport service.
GNUNET_TRANSPORT_ConnectionStatus
Possible states of a connection.
struct GNUNET_TRANSPORT_AddressIdentifier * GNUNET_TRANSPORT_communicator_address_add(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const char *address, enum GNUNET_NetworkType nt, struct GNUNET_TIME_Relative expiration)
Notify transport service about an address that this communicator provides for this peer.
void GNUNET_TRANSPORT_communicator_address_remove_all(struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
Notify transport service that this communicator no longer provides all its addresses for this peer.
@ GNUNET_TRANSPORT_CC_RELIABLE
Transmission is reliabile (with ACKs), e.g.
@ GNUNET_TRANSPORT_CS_INBOUND
this is an inbound connection (communicator initiated)
@ GNUNET_TRANSPORT_CS_OUTBOUND
this is an outbound connection (transport initiated)
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_time(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, struct GNUNET_TIME_Relative *time)
Get a configuration value that should be a relative time.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don't receive messages from the peer?
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:764
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_elligator_kem_encaps(const struct GNUNET_CRYPTO_EddsaPublicKey *pub, struct GNUNET_CRYPTO_ElligatorRepresentative *r, struct GNUNET_HashCode *key_material)
Carries out ecdh encapsulation with given public key and the private key from a freshly created ephem...
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
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:809
#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.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_elligator_kem_decaps(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_ElligatorRepresentative *r, struct GNUNET_HashCode *key_material)
Carries out ecdh decapsulation with own private key and the representative of the received public key...
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:62
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_contains(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Check if the map contains any value under the given key (including values that are NULL).
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
unsigned int GNUNET_CONTAINER_multihashmap_size(const struct GNUNET_CONTAINER_MultiHashMap *map)
Get the number of key-value pairs in the map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_log(kind,...)
void GNUNET_CRYPTO_hash_context_read(struct GNUNET_HashContext *hc, const void *buf, size_t size)
Add data to be hashed.
Definition: crypto_hash.c:366
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
void GNUNET_CRYPTO_hash_context_finish(struct GNUNET_HashContext *hc, struct GNUNET_HashCode *r_hash)
Finish the hash computation.
Definition: crypto_hash.c:390
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_MIN(a, b)
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
struct GNUNET_HashContext * GNUNET_CRYPTO_hash_context_start(void)
Start incremental hashing operation.
Definition: crypto_hash.c:350
void GNUNET_CRYPTO_hmac_raw(const void *key, size_t key_len, const void *plaintext, size_t plaintext_len, struct GNUNET_HashCode *hmac)
Calculate HMAC of a message (RFC 2104) TODO: Shouldn't this be the standard hmac function and the abo...
Definition: crypto_hash.c:300
@ GNUNET_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:674
struct GNUNET_NAT_Handle * GNUNET_NAT_register(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *config_section, uint8_t proto, unsigned int num_addrs, const struct sockaddr **addrs, const socklen_t *addrlens, GNUNET_NAT_AddressCallback address_callback, GNUNET_NAT_ReversalCallback reversal_callback, void *callback_cls)
Attempt to enable port redirection and detect public IP address contacting UPnP or NAT-PMP routers on...
Definition: nat_api.c:366
void GNUNET_NAT_unregister(struct GNUNET_NAT_Handle *nh)
Stop port redirection and public IP address detection for the given handle.
Definition: nat_api.c:702
GNUNET_NAT_AddressClass
Some addresses contain sensitive information or are not suitable for global distribution.
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_accept(const struct GNUNET_NETWORK_Handle *desc, struct sockaddr *address, socklen_t *address_len)
Accept a new connection on a socket.
Definition: network.c:392
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:508
int GNUNET_NETWORK_get_fd(const struct GNUNET_NETWORK_Handle *desc)
Return file descriptor for this network handle.
Definition: network.c:1000
ssize_t GNUNET_NETWORK_socket_recv(const struct GNUNET_NETWORK_Handle *desc, void *buffer, size_t length)
Read data from a connected socket (always non-blocking).
Definition: network.c:716
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition: network.c:832
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_connect(const struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Connect a socket to some remote address.
Definition: network.c:601
ssize_t GNUNET_NETWORK_socket_send(const struct GNUNET_NETWORK_Handle *desc, const void *buffer, size_t length)
Send data (always non-blocking).
Definition: network.c:737
enum GNUNET_GenericReturnValue GNUNET_NETWORK_test_pf(int pf)
Test if the given protocol family is supported by this system.
Definition: network.c:79
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_bind(struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Bind a socket to a particular address.
Definition: network.c:439
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_listen(const struct GNUNET_NETWORK_Handle *desc, int backlog)
Listen on a socket.
Definition: network.c:651
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:44
void GNUNET_NT_scanner_done(struct GNUNET_NT_InterfaceScanner *is)
Terminate interface scanner.
Definition: nt.c:426
struct GNUNET_NT_InterfaceScanner * GNUNET_NT_scanner_init(void)
Initialize the address characterization client handle.
Definition: nt.c:405
enum GNUNET_NetworkType GNUNET_NT_scanner_get_type(struct GNUNET_NT_InterfaceScanner *is, const struct sockaddr *addr, socklen_t addrlen)
Returns where the address is located: loopback, LAN or WAN.
Definition: nt.c:307
struct GNUNET_PEERSTORE_IterateContext * GNUNET_PEERSTORE_iteration_start(struct GNUNET_PEERSTORE_Handle *h, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, GNUNET_PEERSTORE_Processor callback, void *callback_cls)
Iterate over peerstore entries.
void GNUNET_PEERSTORE_iteration_next(struct GNUNET_PEERSTORE_IterateContext *ic, uint64_t limit)
Continue an iteration.
void GNUNET_PEERSTORE_store_cancel(struct GNUNET_PEERSTORE_StoreContext *sc)
Cancel a store request.
void GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h)
Disconnect from the PEERSTORE service.
struct GNUNET_PEERSTORE_Handle * GNUNET_PEERSTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the PEERSTORE service.
#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE
Key used to store sender's monotonic time from handshake message.
struct GNUNET_PEERSTORE_StoreContext * GNUNET_PEERSTORE_store(struct GNUNET_PEERSTORE_Handle *h, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, const void *value, size_t size, struct GNUNET_TIME_Absolute expiry, enum GNUNET_PEERSTORE_StoreOption options, GNUNET_PEERSTORE_Continuation cont, void *cont_cls)
Store a new entry in the PEERSTORE.
#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK
Key used to store sender's monotonic time from handshake ack message.
#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY
Key used to store sender's monotonic time from rekey message.
void GNUNET_PEERSTORE_iteration_stop(struct GNUNET_PEERSTORE_IterateContext *ic)
Cancel an iteration.
@ GNUNET_PEERSTORE_STOREOPTION_REPLACE
Delete any previous values for the given key before storing the given value.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition: program.c:400
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_CONFIRMATION_ACK
TCP communicator confirmation ack.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE
TCP NAT probe message, send from NAT'd peer to other peer to establish bi-directional communication.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH
TCP communicator end of stream.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX
TCP communicator payload box.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY
TCP communicator rekey message.
struct GNUNET_RESOLVER_RequestHandle * GNUNET_RESOLVER_ip_get(const char *hostname, int af, struct GNUNET_TIME_Relative timeout, GNUNET_RESOLVER_AddressCallback callback, void *callback_cls)
Convert a string to one or more IP addresses.
Definition: resolver_api.c:940
void GNUNET_RESOLVER_request_cancel(struct GNUNET_RESOLVER_RequestHandle *rh)
Cancel a request that is still pending with the resolver.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:567
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1512
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_write_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *wfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1583
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition: scheduler.c:1340
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:981
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1305
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1278
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1230
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:405
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:570
#define GNUNET_TIME_UNIT_MINUTES
One minute.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:737
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:316
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_monotonic(const struct GNUNET_CONFIGURATION_Handle *cfg)
Obtain the current time and make sure it is monotonically increasing.
Definition: time.c:860
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:638
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:617
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
#define max(x, y)
static unsigned int size
Size of the "table".
Definition: peer.c:68
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition: scheduler.c:431
#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE_ACK
Signature by a peer sending back the nonce received at initial handshake.
#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_REKEY
Signature used by TCP communicator rekey.
#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE
Signature used by TCP communicator handshake.
DLL to store the addresses we like to register at NAT service.
struct Addresses * next
Kept in a DLL.
struct Addresses * prev
Kept in a DLL.
struct sockaddr * addr
Address we like to register at NAT service.
socklen_t addr_len
Length of address we like to register at NAT service.
Internal representation of the hash map.
Type of a nonce used for challenges.
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
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.
Elligator representative (always for Curve25519)
Definition of a command line option.
A 512-bit hashcode.
Handle to a message queue.
Definition: mq.c:87
Header for all communications.
Handle for active NAT registrations.
Definition: nat_api.c:72
handle to a socket
Definition: network.c:53
Handle to the interface scanner.
Definition: nt.c:104
Handle to the PEERSTORE service.
Definition: peerstore_api.c:44
Context for a iterate request.
Single PEERSTORE record.
Context for a store request.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Handle to a request given to the resolver.
Definition: resolver_api.c:104
Entry in list of pending tasks.
Definition: scheduler.c:136
Handle for the service.
A 256-bit hashcode.
Time for absolute time used by GNUnet, in microseconds and in network byte order.
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
Internal representation of an address a communicator is currently providing for the transport service...
Opaque handle to the transport service for communicators.
Handle returned to identify the internal data structure the transport API has created to manage a mes...
Struct to use as closure.
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
struct GNUNET_SCHEDULER_Task * listen_task
ID of listen task.
Struct for pending nat reversals.
struct sockaddr * in
Address the reversal was send to.
struct GNUNET_SCHEDULER_Task * timeout_task
struct GNUNET_PeerIdentity target
To whom are we like to talk to.
In case of port only configuration we like to bind to ipv4 and ipv6 addresses.
struct sockaddr * addr_ipv4
Ipv4 address we like to bind to.
struct sockaddr * addr_ipv6
Ipv6 address we like to bind to.
socklen_t addr_len_ipv6
Length of ipv6 address.
socklen_t addr_len_ipv4
Length of ipv4 address.
Handle for an incoming connection where we do not yet have enough information to setup a full queue.
socklen_t address_len
Length of the address.
struct GNUNET_SCHEDULER_Task * write_task
ID of write task for this connection.
char write_buf[sizeof(struct TCPNATProbeMessage)]
buffer for writing struct TCPNATProbeMessage to network.
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
size_t ibuf_off
Current offset for reading into ibuf.
struct GNUNET_TIME_Absolute timeout
Timeout for this protoqueue.
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
struct sockaddr * address
Address of the other peer.
struct ProtoQueue * prev
Kept in a DLL.
char ibuf[(sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)+sizeof(struct TCPConfirmation))]
Buffer for reading all the information we need to upgrade from protoqueue to queue.
size_t write_off
Offset of the buffer?
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
struct ProtoQueue * next
Kept in a DLL.
Handle for a queue.
unsigned int backpressure
How may messages did we pass from this queue to CORE for which we have yet to receive an acknowledgem...
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
struct GNUNET_PEERSTORE_IterateContext * handshake_ack_monotime_get
Iteration Context for retrieving the monotonic time send with the handshake ack.
int rekeyed
GNUNET_YES if we just rekeyed and must thus possibly re-decrypt ciphertext.
struct GNUNET_CRYPTO_ChallengeNonceP challenge
Challenge value used to protect against replay attack, if there is no stored monotonic time value.
size_t unverified_size
Size of data received without KX challenge played back.
struct GNUNET_TRANSPORT_QueueHandle * qh
handle for this queue with the ch.
struct GNUNET_HashCode out_hmac
Shared secret for HMAC generation on outgoing data, ratcheted after each operation.
int finishing
Did we enqueue a finish message and are closing down the queue?
int initial_core_kx_done
Has the initial (core) handshake already happened?
struct GNUNET_HashCode key
Key in hash map.
socklen_t address_len
Length of the address.
struct GNUNET_MQ_Handle * mq
Message queue we are providing for the ch.
unsigned long long bytes_in_queue
Number of bytes we currently have in our write queue.
char pread_buf[UINT16_MAX+1+sizeof(struct TCPBox)]
Plaintext buffer for decrypted plaintext.
int destroyed
Did we technically destroy this queue, but kept the allocation around because of backpressure not bei...
struct GNUNET_PEERSTORE_StoreContext * rekey_monotime_sc
Store Context for retrieving the monotonic time send with key for rekeying.
size_t cwrite_off
At which offset in the ciphertext write buffer should we append more ciphertext from reading next?
struct GNUNET_PEERSTORE_IterateContext * rekey_monotime_get
Iteration Context for retrieving the monotonic time send with key for rekeying.
char cread_buf[(2 *64 *1024+sizeof(struct TCPBox))]
Buffer for reading ciphertext from network into.
enum GNUNET_NetworkType nt
Which network type does this queue use?
struct GNUNET_CRYPTO_ChallengeNonceP challenge_received
Challenge value received.
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
uint64_t rekey_left_bytes
How many more bytes may we sent with the current out_cipher before we should rekey?
int mq_awaits_continue
Is MQ awaiting a GNUNET_MQ_impl_send_continue() call?
gcry_cipher_hd_t in_cipher
cipher for decryption of incoming data.
struct GNUNET_PEERSTORE_StoreContext * handshake_ack_monotime_sc
Store Context for retrieving the monotonic time send with the handshake ack.
size_t pwrite_off
At which offset in the plaintext output buffer should we append more plaintext for encryption next?
struct GNUNET_TIME_Absolute timeout
Timeout for this queue.
struct sockaddr * address
Address of the other peer.
size_t cread_off
At which offset in the ciphertext read buffer should we append more ciphertext for transmission next?
struct GNUNET_TIME_Absolute rekey_time
Until what time may we sent with the current out_cipher before we should rekey?
struct GNUNET_PeerIdentity target
To whom are we talking to.
char cwrite_buf[(2 *64 *1024+sizeof(struct TCPBox))]
buffer for writing ciphertext to network.
struct GNUNET_PEERSTORE_StoreContext * handshake_monotime_sc
Store Context for retrieving the monotonic time send with the handshake.
size_t pread_off
At which offset in the plaintext input buffer should we append more plaintext from decryption next?
enum GNUNET_TRANSPORT_ConnectionStatus cs
The connection status of this queue.
gcry_cipher_hd_t out_cipher
cipher for encryption of outgoing data.
char pwrite_buf[UINT16_MAX+1+sizeof(struct TCPBox)]
Plaintext buffer for messages to be encrypted.
struct GNUNET_HashCode in_hmac
Shared secret for HMAC verification on incoming data.
struct GNUNET_PEERSTORE_IterateContext * handshake_monotime_get
Iteration Context for retrieving the monotonic time send with the handshake.
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
struct GNUNET_SCHEDULER_Task * write_task
ID of write task for this connection.
struct GNUNET_TIME_AbsoluteNBO handshake_ack_monotonic_time
Monotonic time value for handshake ack message.
struct GNUNET_TIME_AbsoluteNBO rekey_monotonic_time
Monotonic time value for rekey message.
struct GNUNET_TIME_AbsoluteNBO handshake_monotonic_time
Monotonic time value for handshake message.
TCP message box.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX.
struct GNUNET_ShortHashCode hmac
HMAC for the following encrypted message.
Ack for the encrypted continuation of TCP initial handshake.
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
struct GNUNET_CRYPTO_EddsaSignature sender_sig
Sender's signature of type GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE_ACK.
struct GNUNET_CRYPTO_ChallengeNonceP challenge
Challenge value used to protect against replay attack, if there is no stored monotonic time value.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_CONFIRMATION_ACK.
struct GNUNET_PeerIdentity sender
Sender's identity.
Encrypted continuation of TCP initial handshake.
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
struct GNUNET_CRYPTO_EddsaSignature sender_sig
Sender's signature of type GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE.
struct GNUNET_PeerIdentity sender
Sender's identity.
struct GNUNET_CRYPTO_ChallengeNonceP challenge
Challenge value used to protect against replay attack, if there is no stored monotonic time value.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH.
struct GNUNET_ShortHashCode hmac
HMAC for the following encrypted message.
Basically a WELCOME message, but with the purpose of giving the waiting peer a client handle to use.
struct GNUNET_PeerIdentity clientIdentity
Identity of the sender of the message.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE.
TCP rekey message box.
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
struct GNUNET_CRYPTO_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_CRYPTO_ElligatorRepresentative ephemeral
Ephemeral key used by the sender (as Elligator representative).
struct GNUNET_PeerIdentity sender
Identity of the inititor of the TCP connection (TCP client).
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
struct GNUNET_PeerIdentity receiver
Presumed identity of the target of the TCP connection (TCP server)
Signature we use to verify that the ephemeral key was really chosen by the specified sender.
struct GNUNET_CRYPTO_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...