GNUnet 0.28.0-dev.3-20-gf1136b0b8
 
Loading...
Searching...
No Matches
gnunet-communicator-udp.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet
3 Copyright (C) 2010-2014, 2018, 2019, 2026 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14 :
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
40#include "platform.h"
41#include "gnunet_common.h"
42#include "gnunet_util_lib.h"
43#include "gnunet_protocols.h"
44#include "gnunet_signatures.h"
45#include "gnunet_constants.h"
46#include "gnunet_pils_service.h"
47#include "gnunet_nat_service.h"
51
52/* Shorthand for Logging */
53#define LOG(kind, ...) GNUNET_log_from (kind, "communicator-udp", __VA_ARGS__)
54
58#define DEFAULT_REKEY_TIME_INTERVAL GNUNET_TIME_UNIT_DAYS
59
63#define PROTO_QUEUE_TIMEOUT GNUNET_TIME_UNIT_MINUTES
64
68#define BROADCAST_FREQUENCY GNUNET_TIME_UNIT_MINUTES
69
73#define INTERFACE_SCAN_FREQUENCY \
74 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
75
80#define ADDRESS_VALIDITY_PERIOD GNUNET_TIME_UNIT_HOURS
81
82#define WORKING_QUEUE_INTERVALL \
83 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS,1)
84
88#define AES_KEY_SIZE (256 / 8)
89
93#define AES_IV_SIZE (96 / 8)
94
98#define GCM_TAG_SIZE (128 / 8)
99
100#define GENERATE_AT_ONCE 64
101
111#define KCN_THRESHOLD 96
112
119#define KCN_TARGET 128
120
130#define MAX_SQN_DELTA 160
131
141#define MAX_SECRETS 256
142
147#define DEFAULT_REKEY_MAX_BYTES (1024LLU * 1024 * 1024 * 4LLU)
148
153#define COMMUNICATOR_ADDRESS_PREFIX "udp"
154
158#define COMMUNICATOR_CONFIG_SECTION "communicator-udp"
159
161
162
196
197
216
217
223{
228
233
239
240 /* followed by messages */
241
242 /* padding may follow actual messages */
243};
244
245
268
269
295
296
316
317
322struct UDPBox
323{
332
341
342};
343
359
361
365struct SharedSecret;
366
367
373{
378
383
392
397
402};
403
404
409struct SenderAddress;
410
415struct ReceiverAddress;
416
495
496
579
580
705
710{
715
720
725
729 struct sockaddr *sa;
730
734 struct sockaddr *ba;
735
740
745 struct ipv6_mreq mcreq;
746
750 socklen_t salen;
751
755 int found;
756};
757
762
767
772
776static unsigned long long rekey_max_bytes;
777
782
787
792
797
802
807
812
817
822
827
832
837
842
847
852
856static const struct GNUNET_CONFIGURATION_Handle *cfg;
857
862
867
871static struct GNUNET_NAT_Handle *nat;
872
876static uint16_t my_port;
877
882
886static int disable_v6;
887
889
890
891static void
901
902
903static void
913
914
920static void
922{
923 if (AF_INET6 == bi->sa->sa_family)
924 {
925 /* Leave the multicast group */
927 IPPROTO_IPV6,
928 IPV6_LEAVE_GROUP,
929 &bi->mcreq,
930 sizeof(bi->mcreq)))
931 {
933 }
934 }
937 GNUNET_free (bi->sa);
938 GNUNET_free (bi->ba);
939 GNUNET_free (bi);
940}
941
942
943static int
944secret_destroy (struct SharedSecret *ss);
945
951static void
953{
954 struct SharedSecret *ss;
955 receiver->receiver_destroy_called = GNUNET_YES;
956
958 "Disconnecting receiver for peer `%s'\n",
959 GNUNET_i2s (&receiver->target));
960 if (NULL != receiver->kx_qh)
961 {
963 receiver->kx_qh = NULL;
964 receiver->kx_mq = NULL;
965 }
966 if (NULL != receiver->d_qh)
967 {
969 receiver->d_qh = NULL;
970 }
971 else if (NULL != receiver->d_mq)
972 {
974 receiver->d_mq = NULL;
975 }
976 if (NULL != receiver->udp_sock)
977 {
980 receiver->udp_sock = NULL;
981 }
984 &receiver->key,
985 receiver));
988 "# receivers active",
990 GNUNET_NO);
991 while (NULL != (ss = receiver->ss_head))
992 {
993 secret_destroy (ss);
994 }
995 GNUNET_free (receiver->address);
996 GNUNET_free (receiver->foreign_addr);
998}
999
1000
1006static void
1008{
1009 struct SharedSecret *ss = kce->ss;
1010
1011 ss->active_kce_count--;
1014 &kce->kid,
1015 kce));
1016 GNUNET_free (kce);
1017}
1018
1019
1027static void
1028get_kid (const struct GNUNET_ShortHashCode *msec,
1029 uint32_t serial,
1030 struct GNUNET_ShortHashCode *kid)
1031{
1032 uint32_t sid = htonl (serial);
1033 struct GNUNET_ShortHashCode prk;
1035 &sid, sizeof (sid),
1036 msec, sizeof (*msec));
1037
1039 kid,
1040 sizeof(*kid),
1041 &prk,
1042 GNUNET_CRYPTO_kdf_arg_string ("gnunet-communicator-udp-kid"));
1043}
1044
1045
1052static void
1053kce_generate (struct SharedSecret *ss, uint32_t seq)
1054{
1055 struct KeyCacheEntry *kce;
1056
1057 GNUNET_assert (0 < seq);
1058 kce = GNUNET_new (struct KeyCacheEntry);
1059 kce->ss = ss;
1060 kce->sequence_number = seq;
1061 get_kid (&ss->master, seq, &kce->kid);
1066 key_cache,
1067 &kce->kid,
1068 kce,
1071 "# KIDs active",
1073 GNUNET_NO);
1074}
1075
1076
1083static int
1085{
1086 struct SenderAddress *sender;
1087 struct ReceiverAddress *receiver;
1088 struct KeyCacheEntry *kce;
1089
1091 "secret %s destroy %u\n",
1092 GNUNET_sh2s (&ss->master),
1094 if (NULL != (sender = ss->sender))
1095 {
1096 GNUNET_CONTAINER_DLL_remove (sender->ss_head, sender->ss_tail, ss);
1097 sender->num_secrets--;
1099 "%u sender->num_secrets %u allowed %u used, %u available\n",
1101 sender->acks_available);
1103 if (NULL != ss->sender->kce_task)
1104 {
1106 ss->sender->kce_task = NULL;
1107 }
1108 }
1109 if (NULL != (receiver = ss->receiver))
1110 {
1111 GNUNET_CONTAINER_DLL_remove (receiver->ss_head, receiver->ss_tail, ss);
1112 receiver->num_secrets--;
1113 receiver->acks_available -= (ss->sequence_allowed - ss->sequence_used);
1115 "%u receiver->num_secrets\n",
1116 receiver->num_secrets);
1117 }
1118 while (NULL != (kce = ss->kce_head))
1119 kce_destroy (kce);
1120 GNUNET_STATISTICS_update (stats, "# Secrets active", -1, GNUNET_NO);
1122 "# KIDs active",
1124 GNUNET_NO);
1125 GNUNET_free (ss);
1126 return GNUNET_YES;
1127}
1128
1129
1136static void
1138{
1139 struct SharedSecret *ss;
1142 GNUNET_YES ==
1146 "# senders active",
1148 GNUNET_NO);
1149 while (NULL != (ss = sender->ss_head))
1150 {
1151 secret_destroy (ss);
1152 }
1155}
1156
1157
1166static void
1168 uint32_t serial,
1169 char key[AES_KEY_SIZE],
1170 char iv[AES_IV_SIZE])
1171{
1172 uint32_t sid = htonl (serial);
1173
1175 key,
1177 msec,
1178 GNUNET_CRYPTO_kdf_arg_string ("gnunet-communicator-udp-key"),
1181 iv,
1183 msec,
1184 GNUNET_CRYPTO_kdf_arg_string ("gnunet-communicator-udp-iv"),
1186}
1187
1188
1194static void
1201
1202
1208static void
1216
1217
1223static void
1225{
1226 struct GNUNET_TIME_Relative st;
1227 struct GNUNET_TIME_Relative rt;
1228 struct GNUNET_TIME_Relative delay;
1229 struct ReceiverAddress *receiver;
1230 struct SenderAddress *sender;
1231
1232 (void) cls;
1233 timeout_task = NULL;
1236 {
1238 if (0 != rt.rel_value_us)
1239 break;
1241 "Receiver timed out\n");
1243 }
1245 while (NULL != (sender = GNUNET_CONTAINER_heap_peek (senders_heap)))
1246 {
1247 if (GNUNET_YES != sender->sender_destroy_called)
1248 {
1250 if (0 != st.rel_value_us)
1251 break;
1252 sender_destroy (sender);
1253 }
1254 }
1255 delay = GNUNET_TIME_relative_min (rt, st);
1256 if (delay.rel_value_us < GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
1258}
1259
1260
1266static void
1268{
1270 &ss->cmac,
1271 sizeof(ss->cmac),
1272 &ss->master,
1273 GNUNET_CRYPTO_kdf_arg_string ("gnunet-communicator-udp-cmac"));
1274}
1275
1276
1285static void
1287 const void *plaintext,
1288 size_t plaintext_len)
1289{
1290 const struct GNUNET_MessageHeader *hdr = plaintext;
1291 const char *pos = plaintext;
1292
1293 while (ntohs (hdr->size) <= plaintext_len)
1294 {
1296 "# bytes given to core",
1297 ntohs (hdr->size),
1298 GNUNET_NO);
1300 "Giving %u bytes to TNG\n", ntohs (hdr->size));
1303 &sender->target,
1304 hdr,
1306 NULL /* no flow control possible */
1307 ,
1308 NULL));
1309 /* move on to next message, if any */
1310 plaintext_len -= ntohs (hdr->size);
1311 if (plaintext_len < sizeof(*hdr))
1312 break;
1313 pos += ntohs (hdr->size);
1314 hdr = (const struct GNUNET_MessageHeader *) pos;
1315 // TODO for now..., we do not actually sen >1msg or have a way of telling
1316 // if we are done
1317 break;
1318 }
1320 "# bytes padding discarded",
1321 plaintext_len,
1322 GNUNET_NO);
1323}
1324
1325
1334static void
1336 uint32_t serial,
1337 gcry_cipher_hd_t *cipher)
1338{
1339 char key[AES_KEY_SIZE];
1340 char iv[AES_IV_SIZE];
1341 int rc;
1342
1343 GNUNET_assert (0 ==
1344 gcry_cipher_open (cipher,
1345 GCRY_CIPHER_AES256 /* low level: go for speed */
1346 ,
1347 GCRY_CIPHER_MODE_GCM,
1348 0 /* flags */));
1349 get_iv_key (msec, serial, key, iv);
1350 rc = gcry_cipher_setkey (*cipher, key, sizeof(key));
1351 GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
1352 rc = gcry_cipher_setiv (*cipher, iv, sizeof(iv));
1353 GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
1354}
1355
1356
1369static int
1370try_decrypt (const struct SharedSecret *ss,
1371 const uint8_t *tag,
1372 uint32_t serial,
1373 const char *in_buf,
1374 size_t in_buf_size,
1375 char *out_buf)
1376{
1377 gcry_cipher_hd_t cipher;
1378
1379 setup_cipher (&ss->master, serial, &cipher);
1381 0 ==
1382 gcry_cipher_decrypt (cipher, out_buf, in_buf_size, in_buf, in_buf_size));
1383 if (0 != gcry_cipher_checktag (cipher, tag, GCM_TAG_SIZE))
1384 {
1385 gcry_cipher_close (cipher);
1387 "# AEAD authentication failures",
1388 1,
1389 GNUNET_NO);
1390 return GNUNET_SYSERR;
1391 }
1392 gcry_cipher_close (cipher);
1393 return GNUNET_OK;
1394}
1395
1396
1403static struct SharedSecret *
1405 )
1406{
1408 struct SharedSecret *ss;
1409
1412
1413 ss = GNUNET_new (struct SharedSecret);
1415 ephemeral,
1416 &ss->master);
1417 calculate_cmac (ss);
1418 return ss;
1419}
1420
1421
1428static struct SharedSecret *
1431{
1433 struct GNUNET_CRYPTO_HpkePrivateKey my_hpke_key;
1434 struct SharedSecret *ss;
1435
1438
1439 eddsa_priv_to_hpke_key (my_private_key, &my_hpke_key);
1440
1441 ss = GNUNET_new (struct SharedSecret);
1443 &ss->master);
1445 "New receiver SS master: %s\n", GNUNET_sh2s (&ss->master));
1446 calculate_cmac (ss);
1447 return ss;
1448}
1449
1450
1458static struct SharedSecret *
1460 ,
1461 struct ReceiverAddress *receiver)
1462{
1463 struct SharedSecret *ss;
1464
1465 ss = GNUNET_new (struct SharedSecret);
1466 GNUNET_CRYPTO_eddsa_kem_encaps (&receiver->target.public_key,
1467 ephemeral,
1468 &ss->master);
1469 calculate_cmac (ss);
1470 ss->receiver = receiver;
1471 GNUNET_CONTAINER_DLL_insert (receiver->ss_head, receiver->ss_tail, ss);
1472 receiver->num_secrets++;
1473 GNUNET_STATISTICS_update (stats, "# Secrets active", 1, GNUNET_NO);
1474 return ss;
1475}
1476
1477
1485static struct SharedSecret *
1488 struct ReceiverAddress *receiver)
1489{
1490 struct SharedSecret *ss;
1491
1492 ss = GNUNET_new (struct SharedSecret);
1494 c, &ss->master);
1496 "New sender SS master: %s\n", GNUNET_sh2s (&ss->master));
1497 calculate_cmac (ss);
1498 ss->receiver = receiver;
1499 GNUNET_CONTAINER_DLL_insert (receiver->ss_head, receiver->ss_tail, ss);
1500 receiver->num_secrets++;
1501 GNUNET_STATISTICS_update (stats, "# Secrets active", 1, GNUNET_NO);
1502 return ss;
1503}
1504
1505
1513static void
1515
1516
1524static unsigned int
1525purge_secrets (struct SharedSecret *ss_list_tail)
1526{
1527 struct SharedSecret *pos;
1528 struct SharedSecret *ss_to_purge;
1529 unsigned int deleted = 0;
1530
1532 "Purging secrets.\n");
1533 pos = ss_list_tail;
1534 while (NULL != pos)
1535 {
1536 ss_to_purge = pos;
1537 pos = pos->prev;
1538
1539 // FIXME we may also want to purge old unacked.
1540 if (rekey_max_bytes <= ss_to_purge->bytes_sent)
1541 {
1542 secret_destroy (ss_to_purge);
1543 deleted++;
1544 }
1545 }
1547 "Finished purging all, deleted %u.\n", deleted);
1548 return deleted;
1549}
1550
1551
1552static void
1553add_acks (struct SharedSecret *ss, int acks_to_add)
1554{
1555
1556 struct ReceiverAddress *receiver = ss->receiver;
1557
1558 GNUNET_assert (NULL != ss);
1559 GNUNET_assert (NULL != receiver);
1560
1561 if (NULL == receiver->d_qh)
1562 {
1563 receiver->d_qh =
1565 &receiver->target,
1566 receiver->foreign_addr,
1567 receiver->d_mtu,
1568 acks_to_add,
1569 1, /* Priority */
1570 receiver->nt,
1572 receiver->d_mq);
1573 }
1574 else
1575 {
1577 receiver->d_qh,
1578 acks_to_add,
1579 1);
1580 }
1581
1583 "Tell transport we have %u more acks!\n",
1584 acks_to_add);
1585
1586 // Until here for alternative 1
1587
1588 /* move ss to head to avoid discarding it anytime soon! */
1589
1590 // GNUNET_CONTAINER_DLL_remove (receiver->ss_head, receiver->ss_tail, ss);
1591 // GNUNET_CONTAINER_DLL_insert (receiver->ss_head, receiver->ss_tail, ss);
1592}
1593
1594
1605static int
1606handle_ack (void *cls, const struct GNUNET_HashCode *key, void *value)
1607{
1608 const struct UDPAck *ack = cls;
1609 struct ReceiverAddress *receiver = value;
1610 uint32_t acks_to_add;
1611 uint32_t allowed;
1612
1614 "in handle ack with cmac %s\n",
1615 GNUNET_h2s (&ack->cmac));
1616
1617 (void) key;
1618 for (struct SharedSecret *ss = receiver->ss_head; NULL != ss; ss = ss->next)
1619 {
1620 if (0 == memcmp (&ack->cmac, &ss->cmac, sizeof(struct GNUNET_HashCode)))
1621 {
1622
1624 "Found matching cmac\n");
1625
1626 allowed = ntohl (ack->sequence_ack);
1627
1628 if (allowed <= ss->sequence_allowed)
1629 {
1631 "Ignoring ack, not giving us increased window\n.");
1632 return GNUNET_NO;
1633 }
1634 acks_to_add = (allowed - ss->sequence_allowed);
1635 GNUNET_assert (0 != acks_to_add);
1636 receiver->acks_available += (allowed - ss->sequence_allowed);
1637 ss->sequence_allowed = allowed;
1638 add_acks (ss, acks_to_add);
1640 "New sequence allows until %u (+%u). Acks available to us: %u. For secret %s\n",
1641 allowed,
1642 acks_to_add,
1643 receiver->acks_available,
1644 GNUNET_sh2s (&ss->master));
1645 return GNUNET_NO;
1646 }
1647 }
1649 "Matching cmac not found for ack!\n");
1650 return GNUNET_YES;
1651}
1652
1653
1662static void
1664{
1665 struct UDPAck ack;
1666 GNUNET_assert (NULL != ss->sender);
1668 "Considering SS UDPAck %s\n",
1669 GNUNET_i2s_full (&ss->sender->target));
1670
1672 "Sender has %u acks available.\n",
1673 ss->sender->acks_available);
1674 /* drop ancient KeyCacheEntries */
1675 while ((NULL != ss->kce_head) &&
1676 (MAX_SQN_DELTA <
1678 kce_destroy (ss->kce_tail);
1679
1680
1682 ack.header.size = htons (sizeof(ack));
1683 ack.sequence_ack = htonl (ss->sequence_allowed);
1684 ack.cmac = ss->cmac;
1686 "Notifying transport with UDPAck %s, sequence %u and master %s\n",
1688 ss->sequence_allowed,
1689 GNUNET_sh2s (&(ss->master)));
1691 &ss->sender->target,
1693 &ack.header);
1694}
1695
1696
1697static void
1699{
1700 struct SharedSecret *ss = cls;
1701 ss->sender->kce_task = NULL;
1702
1704 "Precomputing %u keys for master %s\n",
1706 GNUNET_sh2s (&ss->master));
1707 if ((ss->override_available_acks != GNUNET_YES) &&
1708 (KCN_TARGET < ss->sender->acks_available))
1709 return;
1710 for (int i = 0; i < GENERATE_AT_ONCE; i++)
1711 kce_generate (ss, ++ss->sequence_allowed);
1712
1717 if (KCN_TARGET > ss->sender->acks_available)
1718 {
1722 ss);
1723 return;
1724 }
1726 "We have enough keys (ACKs: %u).\n", ss->sender->acks_available);
1730 consider_ss_ack (ss);
1731}
1732
1733
1742static void
1744 const void *buf,
1745 size_t buf_size)
1746{
1747 const struct GNUNET_MessageHeader *hdr;
1748 const struct UDPAck *ack;
1749 const struct UDPRekey *rekey;
1750 struct SharedSecret *ss_rekey;
1751 const char *buf_pos = buf;
1752 size_t bytes_remaining = buf_size;
1753 uint16_t type;
1754
1755 hdr = (struct GNUNET_MessageHeader*) buf_pos;
1756 if (sizeof(*hdr) > bytes_remaining)
1757 {
1758 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Plaintext too short, dropping...\n");
1759 return; /* no data left */
1760 }
1762 "try_handle_plaintext of size %llu (%u %lu) and type %u\n",
1763 (unsigned long long) bytes_remaining,
1764 ntohs (hdr->size),
1765 sizeof(*hdr),
1766 ntohs (hdr->type));
1767 if (ntohs (hdr->size) > bytes_remaining)
1768 return; /* buffer too short for indicated message length */
1769 type = ntohs (hdr->type);
1770 switch (type)
1771 {
1773 rekey = (struct UDPRekey*) buf_pos;
1774 if (ntohs (hdr->size) < sizeof (struct UDPRekey))
1775 {
1776 GNUNET_break_op (0);
1777 return;
1778 }
1779 ss_rekey = setup_shared_secret_dec (&rekey->ephemeral);
1780 ss_rekey->sender = sender;
1781 GNUNET_CONTAINER_DLL_insert (sender->ss_head, sender->ss_tail, ss_rekey);
1782 sender->num_secrets++;
1784 "Received rekey secret with cmac %s\n",
1785 GNUNET_h2s (&(ss_rekey->cmac)));
1787 "Received secret with master %s.\n",
1788 GNUNET_sh2s (&(ss_rekey->master)));
1790 "We have %u sequence_allowed.\n",
1791 ss_rekey->sequence_allowed);
1793 "We have a sender %p\n",
1794 ss_rekey->sender);
1796 "We have %u acks available.\n",
1797 ss_rekey->sender->acks_available);
1799 "# rekeying successful",
1800 1,
1801 GNUNET_NO);
1804 // FIXME
1805 kce_generate_cb (ss_rekey);
1806 /* ss_rekey->sender->kce_task = GNUNET_SCHEDULER_add_delayed (
1807 WORKING_QUEUE_INTERVALL,
1808 kce_generate_cb,
1809 ss_rekey);*/
1810 // FIXME: Theoretically, this could be an Ack
1811 buf_pos += ntohs (hdr->size);
1812 bytes_remaining -= ntohs (hdr->size);
1813 pass_plaintext_to_core (sender, buf_pos, bytes_remaining);
1814 if (0 == purge_secrets (sender->ss_tail))
1815 {
1816 // No secret purged. Delete oldest.
1817 if (sender->num_secrets > MAX_SECRETS)
1818 {
1819 secret_destroy (sender->ss_tail);
1820 }
1821 }
1822 break;
1824 /* lookup master secret by 'cmac', then update sequence_max */
1825 ack = (struct UDPAck*) buf_pos;
1826 if (ntohs (hdr->size) < sizeof (struct UDPAck))
1827 {
1828 GNUNET_break_op (0);
1829 return;
1830 }
1832 &sender->key,
1833 &handle_ack,
1834 (void *) ack);
1835 /* There could be more messages after the ACK, handle those as well */
1836 buf_pos += ntohs (hdr->size);
1837 bytes_remaining -= ntohs (hdr->size);
1838 pass_plaintext_to_core (sender, buf_pos, bytes_remaining);
1839 break;
1840
1842 /* skip padding */
1843 break;
1844
1845 default:
1846 pass_plaintext_to_core (sender, buf_pos, bytes_remaining);
1847 }
1848 return;
1849}
1850
1851
1859static void
1860decrypt_box (const struct UDPBox *box,
1861 size_t box_len,
1862 struct KeyCacheEntry *kce)
1863{
1864 struct SharedSecret *ss = kce->ss;
1865 struct SharedSecret *ss_c = ss->sender->ss_tail;
1866 struct SharedSecret *ss_tmp;
1867 int ss_destroyed = 0;
1868 char out_buf[box_len - sizeof(*box)];
1869
1870 GNUNET_assert (NULL != ss->sender);
1871 if (GNUNET_OK != try_decrypt (ss,
1872 box->gcm_tag,
1873 kce->sequence_number,
1874 (const char *) &box[1],
1875 sizeof(out_buf),
1876 out_buf))
1877 {
1878 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed decryption.\n");
1880 "# Decryption failures with valid KCE",
1881 1,
1882 GNUNET_NO);
1883 kce_destroy (kce);
1884 ss->sender->acks_available--;
1885 return;
1886 }
1887 kce_destroy (kce);
1888 kce = NULL;
1889 ss->bytes_sent += box_len;
1890 ss->sender->acks_available--;
1891 ss->sequence_used++;
1893 "# bytes decrypted with BOX",
1894 sizeof(out_buf),
1895 GNUNET_NO);
1897 "# messages decrypted with BOX",
1898 1,
1899 GNUNET_NO);
1901 "decrypted UDPBox with kid %s\n",
1902 GNUNET_sh2s (&box->kid));
1903 try_handle_plaintext (ss->sender, out_buf, sizeof(out_buf));
1904
1905 while (NULL != ss_c)
1906 {
1907 if (ss_c->bytes_sent >= rekey_max_bytes)
1908 {
1910 "Removing SS because rekey bytes reached.\n");
1911 ss_tmp = ss_c->prev;
1912 if (ss == ss_c)
1913 ss_destroyed = 1;
1914 secret_destroy (ss_c);
1915 ss_c = ss_tmp;
1916 continue;
1917 }
1918 ss_c = ss_c->prev;
1919 }
1920 if (1 == ss_destroyed)
1921 return;
1923 "Sender has %u ack left.\n",
1924 ss->sender->acks_available);
1925 if ((KCN_THRESHOLD > ss->sender->acks_available) &&
1926 (NULL == ss->sender->kce_task) &&
1928 {
1930 "Sender has %u ack left which is under threshold.\n",
1931 ss->sender->acks_available);
1935 ss);
1936 }
1937}
1938
1939
1944{
1948 const struct sockaddr *address;
1949
1953 socklen_t address_len;
1954
1959};
1960
1961
1973static struct SenderAddress *
1975 const struct sockaddr *address,
1976 socklen_t address_len)
1977{
1978 struct SenderAddress *sender;
1979 struct GNUNET_HashContext *hsh;
1980 struct GNUNET_HashCode sender_key;
1981
1983 GNUNET_CRYPTO_hash_context_read (hsh, address, address_len);
1984 GNUNET_CRYPTO_hash_context_read (hsh, target, sizeof(*target));
1985 GNUNET_CRYPTO_hash_context_finish (hsh, &sender_key);
1986
1987 sender = GNUNET_CONTAINER_multihashmap_get (senders, &sender_key);
1988 if (NULL != sender)
1989 {
1991 return sender;
1992 }
1993 sender = GNUNET_new (struct SenderAddress);
1994 sender->key = sender_key;
1995 sender->target = *target;
1996 sender->address = GNUNET_memdup (address, address_len);
1997 sender->address_len = address_len;
1999 senders,
2000 &sender->key,
2001 sender,
2004 "# senders active",
2006 GNUNET_NO);
2007 sender->timeout =
2010 sender,
2011 sender->timeout.abs_value_us);
2012 sender->nt = GNUNET_NT_scanner_get_type (is, address, address_len);
2013 if (NULL == timeout_task)
2015 return sender;
2016}
2017
2018
2026static int
2028 const struct UDPConfirmation *uc)
2029{
2030 const struct GNUNET_PeerIdentity *my_identity;
2031 struct UdpHandshakeSignature uhs;
2032
2035
2036 uhs.purpose.purpose = htonl (
2038 uhs.purpose.size = htonl (sizeof(uhs));
2039 uhs.sender = uc->sender;
2040 uhs.receiver = *my_identity;
2041 uhs.enc = *enc;
2042 uhs.monotonic_time = uc->monotonic_time;
2045 &uhs,
2046 &uc->sender_sig,
2047 &uc->sender.public_key);
2048}
2049
2050
2059static char *
2060sockaddr_to_udpaddr_string (const struct sockaddr *address,
2061 socklen_t address_len)
2062{
2063 char *ret;
2064
2065 switch (address->sa_family)
2066 {
2067 case AF_INET:
2069 "%s-%s",
2071 GNUNET_a2s (address, address_len));
2072 break;
2073
2074 case AF_INET6:
2076 "%s-%s",
2078 GNUNET_a2s (address, address_len));
2079 break;
2080
2081 default:
2082 GNUNET_assert (0);
2083 }
2084 return ret;
2085}
2086
2087
2088static struct GNUNET_NETWORK_Handle *
2090{
2092
2093 if (NULL == receiver->udp_sock)
2094 {
2095 if (AF_INET6 == receiver->address->sa_family)
2097 else
2099 }
2100 else
2101 udp_sock = receiver->udp_sock;
2102
2103 return udp_sock;
2104}
2105
2106
2115static struct sockaddr *
2116udp_address_to_sockaddr (const char *bindto,
2117 sa_family_t family,
2118 socklen_t *sock_len)
2119{
2120 struct sockaddr *in;
2121 unsigned int port;
2122 char dummy[2];
2123 char *colon;
2124 char *cp;
2125
2126 if (1 == sscanf (bindto, "%u%1s", &port, dummy))
2127 {
2128 /* interpreting value as just a PORT number */
2129 if (port > UINT16_MAX)
2130 {
2132 "BINDTO specification `%s' invalid: value too large for port\n",
2133 bindto);
2134 return NULL;
2135 }
2136 if ((AF_INET == family) || (GNUNET_YES == disable_v6))
2137 {
2138 struct sockaddr_in *i4;
2139
2140 i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
2141 i4->sin_family = AF_INET;
2142 i4->sin_port = htons ((uint16_t) port);
2143 *sock_len = sizeof(struct sockaddr_in);
2144 in = (struct sockaddr *) i4;
2145 }
2146 else
2147 {
2148 struct sockaddr_in6 *i6;
2149
2150 i6 = GNUNET_malloc (sizeof(struct sockaddr_in6));
2151 i6->sin6_family = AF_INET6;
2152 i6->sin6_port = htons ((uint16_t) port);
2153 *sock_len = sizeof(struct sockaddr_in6);
2154 in = (struct sockaddr *) i6;
2155 }
2156 return in;
2157 }
2158 cp = GNUNET_strdup (bindto);
2159 colon = strrchr (cp, ':');
2160 if (NULL != colon)
2161 {
2162 /* interpret value after colon as port */
2163 *colon = '\0';
2164 colon++;
2165 if (1 == sscanf (colon, "%u%1s", &port, dummy))
2166 {
2167 /* interpreting value as just a PORT number */
2168 if (port > UINT16_MAX)
2169 {
2171 "BINDTO specification `%s' invalid: value too large for port\n",
2172 bindto);
2173 GNUNET_free (cp);
2174 return NULL;
2175 }
2176 }
2177 else
2178 {
2179 GNUNET_log (
2181 "BINDTO specification `%s' invalid: last ':' not followed by number\n",
2182 bindto);
2183 GNUNET_free (cp);
2184 return NULL;
2185 }
2186 }
2187 else
2188 {
2189 /* interpret missing port as 0, aka pick any free one */
2190 port = 0;
2191 }
2192 if (AF_INET6 != family)
2193 {
2194 /* try IPv4 */
2195 struct sockaddr_in v4;
2196
2197 memset (&v4, 0, sizeof(v4));
2198 if (1 == inet_pton (AF_INET, cp, &v4.sin_addr))
2199 {
2200 v4.sin_family = AF_INET;
2201 v4.sin_port = htons ((uint16_t) port);
2202#if HAVE_SOCKADDR_IN_SIN_LEN
2203 v4.sin_len = sizeof(struct sockaddr_in);
2204#endif
2205 in = GNUNET_memdup (&v4, sizeof(struct sockaddr_in));
2206 *sock_len = sizeof(struct sockaddr_in);
2207 GNUNET_free (cp);
2208 return in;
2209 }
2210 }
2211 if (AF_INET != family)
2212 {
2213 /* try IPv6 */
2214 struct sockaddr_in6 v6;
2215 const char *start;
2216
2217 memset (&v6, 0, sizeof(v6));
2218 start = cp;
2219 if (('[' == *cp) && (']' == cp[strlen (cp) - 1]))
2220 {
2221 start++; /* skip over '[' */
2222 cp[strlen (cp) - 1] = '\0'; /* eat ']' */
2223 }
2224 if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
2225 {
2226 v6.sin6_family = AF_INET6;
2227 v6.sin6_port = htons ((uint16_t) port);
2228#if HAVE_SOCKADDR_IN_SIN_LEN
2229 v6.sin6_len = sizeof(struct sockaddr_in6);
2230#endif
2231 in = GNUNET_memdup (&v6, sizeof(v6));
2232 *sock_len = sizeof(v6);
2233 GNUNET_free (cp);
2234 return in;
2235 }
2236 }
2237 /* #5528 FIXME (feature!): maybe also try getnameinfo()? */
2238 GNUNET_free (cp);
2239 return NULL;
2240}
2241
2242
2243static void
2244sock_read (void *cls);
2245
2246
2247static enum GNUNET_GenericReturnValue
2249 const char *address,
2251{
2252 struct GNUNET_HashContext *hsh;
2253 struct ReceiverAddress *receiver;
2254 struct GNUNET_HashCode receiver_key;
2255 const char *path;
2256 struct sockaddr *in;
2257 socklen_t in_len;
2258
2259 if (0 != strncmp (address,
2261 strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
2262 {
2263 GNUNET_break_op (0);
2264 return GNUNET_SYSERR;
2265 }
2266 path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
2267 in = udp_address_to_sockaddr (path, AF_UNSPEC, &in_len);
2268
2269 if (NULL == in)
2270 {
2272 "Failed to setup UDP socket address\n");
2273 return GNUNET_SYSERR;
2274 }
2275 if ((AF_INET6 == in->sa_family) &&
2277 {
2279 "IPv6 disabled, skipping %s\n", address);
2280 GNUNET_free (in);
2281 return GNUNET_SYSERR;
2282 }
2283 else if (AF_INET == in->sa_family)
2284 {
2285 struct sockaddr_in *sin = (struct sockaddr_in *) in;
2286 if (0 == sin->sin_port)
2287 {
2288 GNUNET_free (in);
2289 return GNUNET_NO;
2290 }
2291 }
2292
2294 GNUNET_CRYPTO_hash_context_read (hsh, in, in_len);
2295 GNUNET_CRYPTO_hash_context_read (hsh, peer, sizeof(*peer));
2296 GNUNET_CRYPTO_hash_context_finish (hsh, &receiver_key);
2297
2299 if (NULL != receiver)
2300 {
2302 "receiver %s already exist or is being connected to\n",
2303 address);
2304 return GNUNET_NO;
2305 }
2306
2308 receiver->udp_sock = udp_sock;
2309 receiver->key = receiver_key;
2310 receiver->address = in;
2311 receiver->address_len = in_len;
2312 receiver->target = *peer;
2313 eddsa_pub_to_hpke_key (&receiver->target.public_key,
2314 &receiver->target_hpke_key);
2315 receiver->nt = GNUNET_NT_scanner_get_type (is, in, in_len);
2317 receivers,
2318 &receiver->key,
2319 receiver,
2322 "Added %s to receivers with address %s and sock %p\n",
2323 GNUNET_i2s_full (&receiver->target),
2324 address,
2325 udp_sock);
2326 receiver->timeout =
2329 receiver,
2330 receiver->timeout.abs_value_us);
2332 "# receivers active",
2334 GNUNET_NO);
2335 receiver->foreign_addr =
2336 sockaddr_to_udpaddr_string (receiver->address, receiver->address_len);
2337 if (NULL != udp_sock)
2340 udp_sock,
2341 &sock_read,
2342 udp_sock);
2344 if (NULL == timeout_task)
2346 return GNUNET_OK;
2347}
2348
2349
2355static void
2356sock_read (void *cls)
2357{
2358 struct sockaddr_storage sa;
2359 struct sockaddr_in *addr_verify;
2360 socklen_t salen = sizeof(sa);
2361 char buf[UINT16_MAX];
2362 ssize_t rcvd;
2363
2364 struct GNUNET_NETWORK_Handle *udp_sock = cls;
2365
2368 udp_sock,
2369 &sock_read,
2370 udp_sock);
2373 udp_sock,
2374 &sock_read,
2375 udp_sock);
2376 while (1)
2377 {
2379 buf,
2380 sizeof(buf),
2381 (struct sockaddr *) &sa,
2382 &salen);
2383 if (-1 == rcvd)
2384 {
2385 struct sockaddr *addr = (struct sockaddr*) &sa;
2386
2387 if (EAGAIN == errno)
2388 break; // We are done reading data
2390 "Failed to recv from %s family %d failed sock %p\n",
2391 GNUNET_a2s ((struct sockaddr*) &sa,
2392 sizeof (*addr)),
2393 addr->sa_family,
2394 udp_sock);
2396 return;
2397 }
2399 "Read %llu bytes\n",
2400 (unsigned long long) rcvd);
2401 if (0 == rcvd)
2402 {
2403 GNUNET_break_op (0);
2405 "Read 0 bytes from UDP socket\n");
2406 return;
2407 }
2408
2409 /* first, see if it is a GNUNET_BurstMessage */
2410 if (rcvd == sizeof (struct GNUNET_BurstMessage))
2411 {
2412 struct GNUNET_BurstMessage *bm = (struct GNUNET_BurstMessage *) buf;
2413 struct sockaddr *addr = (struct sockaddr*) &sa;
2414 char *address = sockaddr_to_udpaddr_string (addr, sizeof (*addr));
2415
2416 if (0 != bm->local_port)
2417 {
2418 GNUNET_break_op (0);
2420 "Received a burst message on port %u\n",
2421 bm->local_port);
2422 return;
2423 }
2425 "Received a burst message for default port\n");
2426 create_receiver (&bm->peer,
2427 address,
2428 NULL);
2429 if (AF_INET6 == addr->sa_family)
2431 else
2435 return;
2436 }
2437 /* second, see if it is a UDPBox */
2438 if (rcvd > sizeof(struct UDPBox))
2439 {
2440 const struct UDPBox *box;
2441 struct KeyCacheEntry *kce;
2442
2443 box = (const struct UDPBox *) buf;
2445 if (NULL != kce)
2446 {
2448 "Found KCE with kid %s\n",
2449 GNUNET_sh2s (&box->kid));
2450 decrypt_box (box, (size_t) rcvd, kce);
2451 continue;
2452 }
2453 }
2454
2455 /* next, check if it is a broadcast */
2456 if (sizeof(struct UDPBroadcast) == rcvd)
2457 {
2458 const struct GNUNET_PeerIdentity *my_identity;
2459 const struct UDPBroadcast *ub;
2460 struct UdpBroadcastSignature uhs;
2461 struct GNUNET_PeerIdentity sender;
2462
2465
2466 addr_verify = GNUNET_memdup (&sa, salen);
2467 addr_verify->sin_port = 0;
2469 "received UDPBroadcast from %s\n",
2470 GNUNET_a2s ((const struct sockaddr *) addr_verify, salen));
2471 ub = (const struct UDPBroadcast *) buf;
2472 uhs.purpose.purpose = htonl (
2474 uhs.purpose.size = htonl (sizeof(uhs));
2475 uhs.sender = ub->sender;
2476 sender = ub->sender;
2477 if (0 == memcmp (&sender, my_identity, sizeof (struct
2479 {
2481 "Received our own broadcast\n");
2482 GNUNET_free (addr_verify);
2483 continue;
2484 }
2486 "checking UDPBroadcastSignature for %s\n",
2487 GNUNET_i2s (&sender));
2488 GNUNET_CRYPTO_hash ((struct sockaddr *) addr_verify, salen,
2489 &uhs.h_address);
2490 if (GNUNET_OK ==
2493 &uhs,
2494 &ub->sender_sig,
2495 &ub->sender.public_key))
2496 {
2497 char *addr_s;
2499
2500 addr_s =
2501 sockaddr_to_udpaddr_string ((const struct sockaddr *) &sa, salen);
2502 GNUNET_STATISTICS_update (stats, "# broadcasts received", 1, GNUNET_NO);
2503 /* use our own mechanism to determine network type */
2504 nt =
2505 GNUNET_NT_scanner_get_type (is, (const struct sockaddr *) &sa, salen);
2507 "validating address %s received from UDPBroadcast\n",
2508 GNUNET_i2s (&sender));
2510 GNUNET_free (addr_s);
2511 GNUNET_free (addr_verify);
2512 continue;
2513 }
2514 else
2515 {
2517 "VerifyingPeer %s is verifying UDPBroadcast\n",
2520 "Verifying UDPBroadcast from %s failed\n",
2521 GNUNET_i2s (&ub->sender));
2522 }
2523 GNUNET_free (addr_verify);
2524 /* continue with KX, mostly for statistics... */
2525 }
2526
2527
2528 /* finally, test if it is a KX */
2529 if (rcvd < sizeof(struct UDPConfirmation) + sizeof(struct InitialKX))
2530 {
2532 "# messages dropped (no kid, too small for KX)",
2533 1,
2534 GNUNET_NO);
2535 continue;
2536 }
2538 "Got KX\n");
2539 {
2540 const struct InitialKX *kx;
2541 struct SharedSecret *ss;
2542 char pbuf[rcvd - sizeof(struct InitialKX)];
2543 const struct UDPConfirmation *uc;
2544 struct SenderAddress *sender;
2545
2546 kx = (const struct InitialKX *) buf;
2549 "Before DEC\n");
2550
2551 if (GNUNET_OK != try_decrypt (ss,
2552 kx->gcm_tag,
2553 0,
2554 &buf[sizeof(*kx)],
2555 sizeof(pbuf),
2556 pbuf))
2557 {
2559 "Unable to decrypt tag, dropping...\n");
2560 GNUNET_free (ss);
2562 stats,
2563 "# messages dropped (no kid, AEAD decryption failed)",
2564 1,
2565 GNUNET_NO);
2566 continue;
2567 }
2569 "Before VERIFY\n");
2570
2571 uc = (const struct UDPConfirmation *) pbuf;
2572
2573 if (GNUNET_OK != verify_confirmation (&kx->enc, uc)) // TODO: need ephemeral instead of representative
2574 {
2575 GNUNET_break_op (0);
2576 GNUNET_free (ss);
2578 "# messages dropped (sender signature invalid)",
2579 1,
2580 GNUNET_NO);
2581 continue;
2582 }
2584 "Before SETUP_SENDER\n");
2585
2586 calculate_cmac (ss);
2587 sender = setup_sender (&uc->sender, (const struct sockaddr *) &sa, salen);
2588 ss->sender = sender;
2589 GNUNET_CONTAINER_DLL_insert (sender->ss_head, sender->ss_tail, ss);
2590 if ((KCN_THRESHOLD > ss->sender->acks_available) &&
2591 (NULL == ss->sender->kce_task) &&
2593 {
2594 // TODO This task must be per sender! FIXME: This is a nice todo, but I do not know what must be done here to fix.
2598 ss);
2599 }
2600 sender->num_secrets++;
2601 GNUNET_STATISTICS_update (stats, "# Secrets active", 1, GNUNET_NO);
2603 "# messages decrypted without BOX",
2604 1,
2605 GNUNET_NO);
2606 try_handle_plaintext (sender, &uc[1], sizeof(pbuf) - sizeof(*uc));
2607 if (0 == purge_secrets (sender->ss_tail))
2608 {
2609 // No secret purged. Delete oldest.
2610 if (sender->num_secrets > MAX_SECRETS)
2611 {
2612 secret_destroy (sender->ss_tail);
2613 }
2614 }
2615 }
2616 }
2617}
2618
2619
2627static void
2628do_pad (gcry_cipher_hd_t out_cipher, char *dgram, size_t pad_size)
2629{
2630 char pad[pad_size];
2631
2633 sizeof(pad));
2634 if (sizeof(pad) > sizeof(struct GNUNET_MessageHeader))
2635 {
2636 struct GNUNET_MessageHeader hdr =
2637 { .size = htons (sizeof(pad)),
2639
2640 memcpy (pad, &hdr, sizeof(hdr));
2641 }
2643 0 ==
2644 gcry_cipher_encrypt (out_cipher, dgram, sizeof(pad), pad, sizeof(pad)));
2645}
2646
2647
2648static void
2651 struct GNUNET_MQ_Handle *mq)
2652{
2653 const struct GNUNET_PeerIdentity *my_identity;
2655 uint16_t msize = ntohs (msg->size);
2656 struct UdpHandshakeSignature uhs;
2657 struct UDPConfirmation uc;
2658 struct InitialKX kx;
2659 char dgram[receiver->kx_mtu + sizeof(uc) + sizeof(kx)];
2660 size_t dpos;
2661 gcry_cipher_hd_t out_cipher;
2662 struct SharedSecret *ss;
2663
2667
2668 if (msize > receiver->kx_mtu)
2669 {
2670 GNUNET_break (0);
2671 if (GNUNET_YES != receiver->receiver_destroy_called)
2673 return;
2674 }
2676
2677 /* setup key material */
2679
2680 if (0 == purge_secrets (receiver->ss_tail))
2681 {
2682 // No secret purged. Delete oldest.
2683 if (receiver->num_secrets > MAX_SECRETS)
2684 {
2685 secret_destroy (receiver->ss_tail);
2686 }
2687 }
2688
2689 setup_cipher (&ss->master, 0, &out_cipher);
2690 /* compute 'uc' */
2691 uc.sender = *my_identity;
2692 uc.monotonic_time =
2694 uhs.purpose.purpose = htonl (
2696 uhs.purpose.size = htonl (sizeof(uhs));
2697 uhs.sender = *my_identity;
2698 uhs.receiver = receiver->target;
2699 uhs.monotonic_time = uc.monotonic_time;
2701 &uhs,
2702 &uc.sender_sig);
2703 /* Leave space for kx */
2704 dpos = sizeof(kx);
2705 /* Append encrypted uc to dgram */
2706 GNUNET_assert (0 == gcry_cipher_encrypt (out_cipher,
2707 &dgram[dpos],
2708 sizeof(uc),
2709 &uc,
2710 sizeof(uc)));
2711 dpos += sizeof(uc);
2712 /* Append encrypted payload to dgram */
2714 0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize));
2715 dpos += msize;
2716 do_pad (out_cipher, &dgram[dpos], sizeof(dgram) - dpos);
2717 /* Datagram starts with kx */
2718 kx.enc = uhs.enc;
2720 0 == gcry_cipher_gettag (out_cipher, kx.gcm_tag, sizeof(kx.gcm_tag)));
2721 gcry_cipher_close (out_cipher);
2722 memcpy (dgram, &kx, sizeof(kx));
2724 dgram,
2725 sizeof(dgram),
2726 receiver->address,
2727 receiver->address_len))
2728 {
2731 "Sending KX with payload size %u to %s family %d failed sock %p\n",
2732 msize,
2733 GNUNET_a2s (receiver->address,
2734 receiver->address_len),
2735 receiver->address->sa_family,
2739 return;
2740 }
2742 "Sending KX with payload size %u to %s with socket %p\n",
2743 msize,
2744 GNUNET_a2s (receiver->address,
2745 receiver->address_len),
2748}
2749
2750
2759static void
2761 const struct GNUNET_MessageHeader *msg,
2762 void *impl_state)
2763{
2764 struct ReceiverAddress *receiver = impl_state;
2765
2766 GNUNET_assert (mq == receiver->kx_mq);
2768}
2769
2770
2771static void
2773 UDPRekey *rekey)
2774{
2775 struct SharedSecret *ss_rekey;
2776
2778 /* setup key material */
2779 ss_rekey = setup_shared_secret_ephemeral (&rekey->ephemeral,
2780 receiver);
2781 ss_rekey->sequence_allowed = 0;
2783 "Setup secret with k = %s\n",
2784 GNUNET_sh2s (&ss_rekey->master));
2786 "Setup secret with H(k) = %s\n",
2787 GNUNET_h2s (&(ss_rekey->cmac)));
2788
2789 /* Append encrypted payload to dgram */
2791 rekey->header.size = htons (sizeof (struct UDPRekey));
2792}
2793
2794
2803static void
2805 const struct GNUNET_MessageHeader *msg,
2806 void *impl_state)
2807{
2808 struct ReceiverAddress *receiver = impl_state;
2809 struct UDPRekey rekey;
2810 struct SharedSecret *ss;
2811 int inject_rekey = GNUNET_NO;
2812 uint16_t msize = ntohs (msg->size);
2813
2814 GNUNET_assert (mq == receiver->d_mq);
2815 if ((msize > receiver->d_mtu) ||
2816 (0 == receiver->acks_available))
2817 {
2819 "msize: %u, mtu: %llu, acks: %u\n",
2820 (unsigned int) msize,
2821 (unsigned long long) receiver->d_mtu,
2822 receiver->acks_available);
2823
2824 GNUNET_break (0);
2825 if (GNUNET_YES != receiver->receiver_destroy_called)
2827 return;
2828 }
2830
2831 if (receiver->num_secrets > MAX_SECRETS)
2832 {
2833 if ((0 == purge_secrets (receiver->ss_tail)) &&
2834 (NULL != receiver->ss_tail))
2835 {
2836 // No secret purged. Delete oldest.
2837 secret_destroy (receiver->ss_tail);
2838 }
2839 }
2840 /* begin "BOX" encryption method, scan for ACKs from tail! */
2841 ss = receiver->ss_tail;
2842 while (NULL != ss)
2843 {
2844 size_t payload_len = sizeof(struct UDPBox) + receiver->d_mtu;
2846 "Considering SS %s sequence used: %u sequence allowed: %u bytes sent: %lu.\n",
2847 GNUNET_sh2s (&ss->master), ss->sequence_used,
2848 ss->sequence_allowed, ss->bytes_sent);
2849 if (ss->sequence_used >= ss->sequence_allowed)
2850 {
2851 // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2852 // "Skipping ss because no acks to use.\n");
2853 ss = ss->prev;
2854 continue;
2855 }
2856 if (ss->bytes_sent >= rekey_max_bytes)
2857 {
2858 struct SharedSecret *ss_tmp;
2860 "Skipping ss because rekey bytes reached.\n");
2861 // FIXME cleanup ss with too many bytes sent!
2862 ss_tmp = ss->prev;
2863 secret_destroy (ss);
2864 ss = ss_tmp;
2865 continue;
2866 }
2867 if (ss->bytes_sent > rekey_max_bytes * 0.7)
2868 {
2869 if (ss->rekey_initiated == GNUNET_NO)
2870 {
2872 "Injecting rekey for ss with byte sent %lu\n",
2873 (unsigned long) ss->bytes_sent);
2874 create_rekey (receiver, ss, &rekey);
2876 payload_len += sizeof (rekey);
2878 }
2879 }
2880 if (0 < ss->sequence_used)
2882 "Trying to send UDPBox with shared secret %s sequence_used %u and ss->sequence_allowed %u\n",
2883 GNUNET_sh2s (&ss->master),
2884 ss->sequence_used,
2885 ss->sequence_allowed);
2886 {
2887 char dgram[payload_len];
2888 struct UDPBox *box;
2889 gcry_cipher_hd_t out_cipher;
2890 size_t dpos;
2891
2892 box = (struct UDPBox *) dgram;
2893 ss->sequence_used++;
2894 get_kid (&ss->master, ss->sequence_used, &box->kid);
2895 setup_cipher (&ss->master, ss->sequence_used, &out_cipher);
2896 /* Append encrypted payload to dgram */
2897 dpos = sizeof(struct UDPBox);
2898 if (GNUNET_YES == inject_rekey)
2899 {
2901 0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], sizeof (rekey),
2902 &rekey, sizeof (rekey)));
2903 dpos += sizeof (rekey);
2904 }
2906 0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize));
2907 dpos += msize;
2908 do_pad (out_cipher, &dgram[dpos], sizeof(dgram) - dpos);
2909 GNUNET_assert (0 == gcry_cipher_gettag (out_cipher,
2910 box->gcm_tag,
2911 sizeof(box->gcm_tag)));
2912 gcry_cipher_close (out_cipher);
2913
2915 dgram,
2916 payload_len, // FIXME why always send sizeof dgram?
2917 receiver->address,
2918 receiver->address_len))
2919 {
2922 "Sending UDPBox to %s family %d failed sock %p failed\n",
2923 GNUNET_a2s (receiver->address,
2924 receiver->address_len),
2925 receiver->address->sa_family,
2928 return;
2929 }
2931 "Sending UDPBox with payload size %u, %u acks left, %lu bytes sent with socket %p\n",
2932 msize,
2933 receiver->acks_available,
2934 (unsigned long) ss->bytes_sent,
2936 ss->bytes_sent += sizeof (dgram);
2937 receiver->acks_available--;
2939 return;
2940 }
2941 }
2943 "No suitable ss found, sending as KX...\n");
2945}
2946
2947
2956static void
2957mq_destroy_d (struct GNUNET_MQ_Handle *mq, void *impl_state)
2958{
2959 struct ReceiverAddress *receiver = impl_state;
2961 "Default MQ destroyed\n");
2962 if (mq == receiver->d_mq)
2963 {
2964 receiver->d_mq = NULL;
2965 if (GNUNET_YES != receiver->receiver_destroy_called)
2967 }
2968}
2969
2970
2979static void
2980mq_destroy_kx (struct GNUNET_MQ_Handle *mq, void *impl_state)
2981{
2982 struct ReceiverAddress *receiver = impl_state;
2984 "KX MQ destroyed\n");
2985 if (mq == receiver->kx_mq)
2986 {
2987 receiver->kx_mq = NULL;
2988 if (GNUNET_YES != receiver->receiver_destroy_called)
2990 }
2991}
2992
2993
3000static void
3001mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
3002{
3003 /* Cancellation is impossible with UDP; bail */
3004 GNUNET_assert (0);
3005}
3006
3007
3017static void
3018mq_error (void *cls, enum GNUNET_MQ_Error error)
3019{
3020 struct ReceiverAddress *receiver = cls;
3021
3023 "MQ error in queue to %s: %d\n",
3024 GNUNET_i2s (&receiver->target),
3025 (int) error);
3027}
3028
3029
3037static void
3039{
3040 size_t base_mtu;
3041
3042 switch (receiver->address->sa_family)
3043 {
3044 case AF_INET:
3045 base_mtu = 1480 /* Ethernet MTU, 1500 - Ethernet header - VLAN tag */
3046 - sizeof(struct GNUNET_TUN_IPv4Header) /* 20 */
3047 - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */;
3048 break;
3049
3050 case AF_INET6:
3051 base_mtu = 1280 /* Minimum MTU required by IPv6 */
3052 - sizeof(struct GNUNET_TUN_IPv6Header) /* 40 */
3053 - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */;
3054 break;
3055
3056 default:
3057 GNUNET_assert (0);
3058 break;
3059 }
3060 /* MTU based on full KX messages */
3061 receiver->kx_mtu = base_mtu - sizeof(struct InitialKX) /* 48 */
3062 - sizeof(struct UDPConfirmation); /* 104 */
3063 /* MTU based on BOXed messages */
3064 receiver->d_mtu = base_mtu - sizeof(struct UDPBox);
3065
3067 "Setting up MQs and QHs\n");
3068 /* => Effective MTU for CORE will range from 1080 (IPv6 + KX) to
3069 1404 (IPv4 + Box) bytes, depending on circumstances... */
3070 if (NULL == receiver->kx_mq)
3073 &mq_cancel,
3074 receiver,
3075 NULL,
3076 &mq_error,
3077 receiver);
3078 if (NULL == receiver->d_mq)
3080 &mq_destroy_d,
3081 &mq_cancel,
3082 receiver,
3083 NULL,
3084 &mq_error,
3085 receiver);
3086
3087 receiver->kx_qh =
3089 &receiver->target,
3090 receiver->foreign_addr,
3091 receiver->kx_mtu,
3093 0, /* Priority */
3094 receiver->nt,
3096 receiver->kx_mq);
3097}
3098
3099
3118static int
3119mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
3120{
3121 (void) cls;
3123 "create receiver for mq_init\n");
3124 return create_receiver (peer,
3125 address,
3126 NULL);
3127}
3128
3129
3138static int
3140 const struct GNUNET_HashCode *target,
3141 void *value)
3142{
3143 struct ReceiverAddress *receiver = value;
3144
3145 (void) cls;
3146 (void) target;
3148 return GNUNET_OK;
3149}
3150
3151
3160static int
3162 const struct GNUNET_HashCode *target,
3163 void *value)
3164{
3165 struct SenderAddress *sender = value;
3166
3167 (void) cls;
3168 (void) target;
3169
3170
3171 sender_destroy (sender);
3172 return GNUNET_OK;
3173}
3174
3175
3181static void
3182do_shutdown (void *cls)
3183{
3185 "do_shutdown\n");
3186 GNUNET_stop_burst (NULL);
3187 if (NULL != nat)
3188 {
3190 nat = NULL;
3191 }
3192 while (NULL != bi_head)
3194 if (NULL != broadcast_task)
3195 {
3197 broadcast_task = NULL;
3198 }
3199 if (NULL != timeout_task)
3200 {
3202 timeout_task = NULL;
3203 }
3204 if (NULL != read_v6_task)
3205 {
3207 read_v6_task = NULL;
3208 }
3209 if (NULL != read_v4_task)
3210 {
3212 read_v4_task = NULL;
3213 }
3214 if (NULL != default_v6_sock)
3215 {
3218 default_v6_sock = NULL;
3219 }
3220 if (NULL != default_v4_sock)
3221 {
3224 default_v4_sock = NULL;
3225 }
3228 NULL);
3232 NULL);
3237 if (NULL != timeout_task)
3238 {
3240 timeout_task = NULL;
3241 }
3242 if (NULL != ch)
3243 {
3246 ch = NULL;
3247 }
3248 if (NULL != ah)
3249 {
3251 ah = NULL;
3252 }
3253 if (NULL != pils)
3254 {
3256 pils = NULL;
3257 }
3258 if (NULL != key_ring)
3259 {
3261 key_ring = NULL;
3262 }
3263 if (NULL != stats)
3264 {
3266 stats = NULL;
3267 }
3268 if (NULL != is)
3269 {
3271 is = NULL;
3272 }
3274 "do_shutdown finished\n");
3275}
3276
3277
3279{
3280 const struct UDPAck *ack;
3281
3283};
3284
3285static int
3286handle_ack_by_sender (void *cls, const struct GNUNET_HashCode *key, void *value)
3287{
3288 struct ReceiverAddress *receiver = value;
3289 struct AckInfo *ai = cls;
3290
3291 if (0 != GNUNET_memcmp (ai->sender, &receiver->target))
3292 {
3293 return GNUNET_YES;
3294 }
3295 handle_ack ((void*) ai->ack, key, receiver);
3296 return GNUNET_YES;
3297}
3298
3299
3309static void
3310enc_notify_cb (void *cls,
3311 const struct GNUNET_PeerIdentity *sender,
3312 const struct GNUNET_MessageHeader *msg)
3313{
3314 struct AckInfo ai;
3315
3316 (void) cls;
3318 "Storing UDPAck received from backchannel from %s\n",
3321 (ntohs (msg->size) != sizeof(struct UDPAck)))
3322 {
3323 GNUNET_break_op (0);
3324 return;
3325 }
3326 ai.ack = (const struct UDPAck *) msg;
3327 ai.sender = sender;
3330 &ai);
3331}
3332
3333
3347static void
3349 void **app_ctx,
3350 int add_remove,
3352 const struct sockaddr *addr,
3353 socklen_t addrlen)
3354{
3355 char *my_addr;
3357
3358 if (GNUNET_YES == add_remove)
3359 {
3361
3362 GNUNET_asprintf (&my_addr,
3363 "%s-%s",
3365 GNUNET_a2s (addr, addrlen));
3366 nt = GNUNET_NT_scanner_get_type (is, addr, addrlen);
3367 ai =
3369 my_addr,
3370 nt,
3372 GNUNET_free (my_addr);
3373 *app_ctx = ai;
3374 }
3375 else
3376 {
3377 ai = *app_ctx;
3379 *app_ctx = NULL;
3380 }
3381}
3382
3383
3389static void
3390ifc_broadcast (void *cls)
3391{
3392 struct BroadcastInterface *bi = cls;
3393 struct GNUNET_TIME_Relative delay;
3394
3395 delay = BROADCAST_FREQUENCY;
3396 delay.rel_value_us =
3398 bi->broadcast_task =
3400
3401 switch (bi->sa->sa_family)
3402 {
3403 case AF_INET: {
3404 static int yes = 1;
3405 static int no = 0;
3406 ssize_t sent;
3407
3408 if (GNUNET_OK !=
3410 SOL_SOCKET,
3411 SO_BROADCAST,
3412 &yes,
3413 sizeof(int)))
3415 "setsockopt");
3417 "creating UDPBroadcast from %s\n",
3418 GNUNET_i2s (&(bi->bcm.sender)));
3420 "sending UDPBroadcast to add %s\n",
3421 GNUNET_a2s (bi->ba, bi->salen));
3423 &bi->bcm,
3424 sizeof(bi->bcm),
3425 bi->ba,
3426 bi->salen);
3427 if (-1 == sent)
3429 "sendto");
3431 SOL_SOCKET,
3432 SO_BROADCAST,
3433 &no,
3434 sizeof(int)))
3436 "setsockopt");
3437 break;
3438 }
3439
3440 case AF_INET6: {
3441 ssize_t sent;
3442 struct sockaddr_in6 dst;
3443
3444 dst.sin6_family = AF_INET6;
3445 dst.sin6_port = htons (my_port);
3446 dst.sin6_addr = bi->mcreq.ipv6mr_multiaddr;
3447 dst.sin6_scope_id = ((struct sockaddr_in6 *) bi->ba)->sin6_scope_id;
3448
3450 "sending UDPBroadcast\n");
3452 &bi->bcm,
3453 sizeof(bi->bcm),
3454 (const struct sockaddr *) &dst,
3455 sizeof(dst));
3456 if (-1 == sent)
3458 break;
3459 }
3460
3461 default:
3462 GNUNET_break (0);
3463 break;
3464 }
3465}
3466
3467
3482static int
3483iface_proc (void *cls,
3484 const char *name,
3485 int isDefault,
3486 const struct sockaddr *addr,
3487 const struct sockaddr *broadcast_addr,
3488 const struct sockaddr *netmask,
3489 socklen_t addrlen)
3490{
3491 const struct GNUNET_PeerIdentity *my_identity;
3493 struct BroadcastInterface *bi;
3494 enum GNUNET_NetworkType network;
3495 struct UdpBroadcastSignature ubs;
3496
3497 (void) cls;
3498 (void) netmask;
3499
3502
3503 if ((NULL == my_identity) || (NULL == my_private_key))
3504 return GNUNET_YES;
3505 if (NULL == addr)
3506 return GNUNET_YES; /* need to know our address! */
3507 network = GNUNET_NT_scanner_get_type (is, addr, addrlen);
3508 if (GNUNET_NT_LOOPBACK == network)
3509 {
3510 /* Broadcasting on loopback does not make sense */
3511 return GNUNET_YES;
3512 }
3513 for (bi = bi_head; NULL != bi; bi = bi->next)
3514 {
3515 if ((bi->salen == addrlen) && (0 == memcmp (addr, bi->sa, addrlen)))
3516 {
3517 bi->found = GNUNET_YES;
3518 return GNUNET_OK;
3519 }
3520 }
3521
3522 if ((AF_INET6 == addr->sa_family) && (NULL == broadcast_addr))
3523 return GNUNET_OK; /* broadcast_addr is required for IPv6! */
3524 if ((AF_INET6 == addr->sa_family) && (NULL == default_v6_sock))
3525 return GNUNET_OK; /* not using IPv6 */
3526
3527 bi = GNUNET_new (struct BroadcastInterface);
3528 bi->sa = GNUNET_memdup (addr,
3529 addrlen);
3530 if ( (NULL != broadcast_addr) &&
3531 (addrlen == sizeof (struct sockaddr_in)) )
3532 {
3533 struct sockaddr_in *ba;
3534
3535 ba = GNUNET_memdup (broadcast_addr,
3536 addrlen);
3537 ba->sin_port = htons (2086); /* always GNUnet port, ignore configuration! */
3538 bi->ba = (struct sockaddr *) ba;
3539 }
3540 bi->salen = addrlen;
3541 bi->found = GNUNET_YES;
3542 bi->bcm.sender = *my_identity;
3543 ubs.purpose.purpose = htonl (
3545 ubs.purpose.size = htonl (sizeof(ubs));
3546 ubs.sender = *my_identity;
3548 "creating UDPBroadcastSignature for %s\n",
3549 GNUNET_a2s (addr, addrlen));
3550 GNUNET_CRYPTO_hash (addr, addrlen, &ubs.h_address);
3552 &ubs,
3553 &bi->bcm.sender_sig);
3554 if (NULL != bi->ba)
3555 {
3558 }
3559 if ((AF_INET6 == addr->sa_family) && (NULL != broadcast_addr))
3560 {
3561 /* Create IPv6 multicast request */
3562 const struct sockaddr_in6 *s6 =
3563 (const struct sockaddr_in6 *) broadcast_addr;
3564
3566 1 == inet_pton (AF_INET6, "FF05::13B", &bi->mcreq.ipv6mr_multiaddr));
3567
3568 /* http://tools.ietf.org/html/rfc2553#section-5.2:
3569 *
3570 * IPV6_JOIN_GROUP
3571 *
3572 * Join a multicast group on a specified local interface. If the
3573 * interface index is specified as 0, the kernel chooses the local
3574 * interface. For example, some kernels look up the multicast
3575 * group in the normal IPv6 routing table and using the resulting
3576 * interface; we do this for each interface, so no need to use
3577 * zero (anymore...).
3578 */
3579 bi->mcreq.ipv6mr_interface = s6->sin6_scope_id;
3580
3581 /* Join the multicast group */
3583 IPPROTO_IPV6,
3584 IPV6_JOIN_GROUP,
3585 &bi->mcreq,
3586 sizeof(bi->mcreq)))
3587 {
3589 }
3590 }
3591 return GNUNET_OK;
3592}
3593
3594
3600static void
3601do_broadcast (void *cls)
3602{
3603 struct BroadcastInterface *bin;
3604
3605 (void) cls;
3606 for (struct BroadcastInterface *bi = bi_head; NULL != bi; bi = bi->next)
3607 bi->found = GNUNET_NO;
3609 for (struct BroadcastInterface *bi = bi_head; NULL != bi; bi = bin)
3610 {
3611 bin = bi->next;
3612 if (GNUNET_NO == bi->found)
3613 bi_destroy (bi);
3614 }
3616 &do_broadcast,
3617 NULL);
3618}
3619
3620
3621static void
3623 const struct sockaddr *addr,
3624 socklen_t addrlen)
3625{
3626 /* FIXME: support reversal: #5529 */
3628 "No connection reversal implemented!\n");
3629}
3630
3631
3632static void
3634{
3635 // FIXME: This sizeof application truncates IPv6 addresses!
3637 sizeof (*sock_info->actual_address
3638 ));
3639 create_receiver (sock_info->pid,
3640 address,
3641 default_v4_sock == sock_info->udp_sock ||
3642 default_v6_sock == sock_info->udp_sock ?
3643 NULL : sock_info->udp_sock);
3645 GNUNET_free (sock_info);
3646}
3647
3648
3649static void
3650start_burst (const char *addr,
3651 struct GNUNET_TIME_Relative rtt,
3652 struct GNUNET_PeerIdentity *pid)
3653{
3654 struct GNUNET_UdpSocketInfo *sock_info;
3655
3657 "Communicator was called to start burst to address %s from %s\n",
3658 addr,
3659 my_ipv4);
3660
3661 GNUNET_stop_burst (NULL);
3662
3663 sock_info = GNUNET_new (struct GNUNET_UdpSocketInfo);
3664 sock_info->pid = GNUNET_new (struct GNUNET_PeerIdentity);
3665 sock_info->address = GNUNET_strdup (addr);
3666 sock_info->bind_address = my_ipv4;
3667 sock_info->has_port = GNUNET_YES;
3668 sock_info->udp_sock = default_v4_sock;
3669 sock_info->rtt = rtt;
3670 GNUNET_memcpy (sock_info->pid, pid, sizeof (struct GNUNET_PeerIdentity));
3671 sock_info->std_port = my_port;
3673 "1 sock addr %s addr %s rtt %lu %u\n",
3674 sock_info->address,
3675 addr,
3676 (unsigned long) sock_info->rtt.rel_value_us,
3677 my_port);
3678 burst_task = GNUNET_get_udp_socket (sock_info,
3680 GNUNET_free (sock_info);
3681}
3682
3683
3684static struct GNUNET_NETWORK_Handle*
3685create_udp_socket (const char *bindto,
3686 sa_family_t family,
3687 struct sockaddr **out,
3688 socklen_t *out_len)
3689{
3690 struct GNUNET_NETWORK_Handle *sock;
3691 struct sockaddr *in;
3692 socklen_t in_len;
3693 struct sockaddr_storage in_sto;
3694 socklen_t sto_len;
3695
3696 in = udp_address_to_sockaddr (bindto, family, &in_len);
3697 if (NULL == in)
3698 {
3700 "Failed to setup UDP socket address with path `%s'\n",
3701 bindto);
3702 return NULL;
3703 }
3704
3705 if ((AF_UNSPEC != family) && (in->sa_family != family))
3706 {
3708 "Invalid UDP socket address setup with path `%s'\n",
3709 bindto);
3710 GNUNET_free (in);
3711 return NULL;
3712 }
3713
3714 sock =
3715 GNUNET_NETWORK_socket_create (in->sa_family,
3716 SOCK_DGRAM,
3717 IPPROTO_UDP);
3718 if (NULL == sock)
3719 {
3722 "Failed to create socket for %s family %d\n",
3723 GNUNET_a2s (in,
3724 in_len),
3725 in->sa_family);
3726 GNUNET_free (in);
3727 return NULL;
3728 }
3729 if (GNUNET_OK !=
3731 in,
3732 in_len))
3733 {
3735 "bind",
3736 bindto);
3738 "Failed to bind socket for %s family %d sock %p\n",
3739 GNUNET_a2s (in,
3740 in_len),
3741 in->sa_family,
3742 sock);
3744 sock = NULL;
3745 GNUNET_free (in);
3746 return NULL;
3747 }
3748
3749 /* We might have bound to port 0, allowing the OS to figure it out;
3750 thus, get the real IN-address from the socket */
3751 sto_len = sizeof(in_sto);
3752 if (0 != getsockname (GNUNET_NETWORK_get_fd (sock),
3753 (struct sockaddr *) &in_sto,
3754 &sto_len))
3755 {
3756 memcpy (&in_sto, in, in_len);
3757 sto_len = in_len;
3758 }
3759 GNUNET_free (in);
3760 *out = GNUNET_malloc (sto_len);
3761 memcpy (*out, (struct sockaddr *) &in_sto, sto_len);
3762 *out_len = sto_len;
3763 return sock;
3764}
3765
3766
3767static void
3768shutdown_run (struct sockaddr *addrs[2])
3769{
3770 if (NULL != addrs[0])
3771 GNUNET_free (addrs[0]);
3772 if (NULL != addrs[1])
3773 GNUNET_free (addrs[1]);
3775}
3776
3777
3778static void
3779run (void *cls,
3780 char *const *args,
3781 const char *cfgfile,
3782 const struct GNUNET_CONFIGURATION_Handle *c)
3783{
3784 const struct sockaddr_in *v4;
3785 char *bindto;
3786 char *bindto6;
3787 struct sockaddr *in[2];
3788 socklen_t in_len[2];
3789
3791 "Entering the run method of udp communicator.\n");
3792
3793 cfg = c;
3795 if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
3796 (GNUNET_YES ==
3799 "DISABLE_V6")))
3800 {
3802 }
3803
3804 if (GNUNET_OK !=
3807 "BINDTO",
3808 &bindto))
3809 {
3812 "BINDTO");
3813 return;
3814 }
3816 "The udp communicator will bind to %s for IPv4\n",
3817 bindto);
3818 if (GNUNET_YES != disable_v6)
3819 {
3820 if (GNUNET_OK !=
3823 "BINDTO6",
3824 &bindto6))
3825 {
3828 "BINDTO6");
3829 return;
3830 }
3831
3833 "The udp communicator will bind to %s for IPv6\n",
3834 bindto6);
3835 }
3836 else
3837 bindto6 = NULL;
3838 if (GNUNET_OK !=
3841 "REKEY_INTERVAL",
3844
3845 if (GNUNET_OK !=
3848 "REKEY_MAX_BYTES",
3850 {
3852 }
3853
3854 memset (in, 0, sizeof(struct sockaddr*) * 2);
3855 memset (in_len, 0, sizeof(socklen_t) * 2);
3856
3857 GNUNET_assert (bindto);
3859 bindto, AF_INET, &(in[0]), &(in_len[0]));
3860 GNUNET_free (bindto);
3861
3862 if (GNUNET_YES != disable_v6)
3863 {
3864 GNUNET_assert (bindto6);
3866 bindto6, AF_INET6, &(in[1]), &(in_len[1]));
3867 GNUNET_free (bindto6);
3868 }
3869 else
3870 default_v6_sock = NULL;
3871
3872 if ((NULL == default_v4_sock) && (NULL == default_v6_sock))
3873 return;
3874
3875 my_port = 0;
3876 if (NULL != default_v4_sock)
3877 {
3878 GNUNET_assert (in[0]);
3880 "transport",
3881 "Bound to `%s' sock %p\n",
3882 GNUNET_a2s ((const struct sockaddr *) in[0],
3883 in_len[0]),
3885
3886 v4 = (const struct sockaddr_in *) in[0];
3887
3888 my_ipv4 = GNUNET_malloc (INET_ADDRSTRLEN);
3889 my_port = ntohs (((struct sockaddr_in *) in[0])->sin_port);
3890 inet_ntop (AF_INET, &v4->sin_addr, my_ipv4, in_len[0]);
3891 }
3892 if (NULL != default_v6_sock)
3893 {
3894 GNUNET_assert (in[1]);
3896 "transport",
3897 "Bound to `%s' sock %p\n",
3898 GNUNET_a2s ((const struct sockaddr *) in[1],
3899 in_len[1]),
3901 my_port = ntohs (((struct sockaddr_in6 *) in[1])->sin6_port);
3902 }
3903 stats = GNUNET_STATISTICS_create ("communicator-udp", cfg);
3912 /* start reading */
3913 if (NULL != default_v4_sock)
3916 &sock_read,
3918 else
3919 read_v4_task = NULL;
3920 if (NULL != default_v6_sock)
3923 &sock_read,
3925 else
3926 read_v6_task = NULL;
3931 &mq_init,
3932 NULL,
3934 NULL,
3935 &start_burst);
3936 if (NULL == ch)
3937 {
3938 GNUNET_break (0);
3939 shutdown_run (in);
3940 return;
3941 }
3943 if (NULL == ah)
3944 {
3945 GNUNET_break (0);
3946 shutdown_run (in);
3947 return;
3948 }
3949 /* start broadcasting */
3950 if (GNUNET_YES !=
3953 "DISABLE_BROADCAST"))
3954 {
3956 }
3958 GNUNET_assert (NULL != key_ring);
3959 pils = GNUNET_PILS_connect (cfg, NULL, NULL);
3960 GNUNET_assert (NULL != pils);
3961
3964 IPPROTO_UDP,
3965 (NULL != in[0]? 1 : 0)
3966 + (NULL != in[1]? 1 : 0),
3967 (const struct sockaddr**)
3968 (NULL != in[0]? in : &(in[1])),
3969 NULL != in[0]? in_len : &(in_len[1]),
3972 NULL /* closure */);
3973 if (NULL != in[0])
3974 GNUNET_free (in[0]);
3975 if (NULL != in[1])
3976 GNUNET_free (in[1]);
3977}
3978
3979
3980GNUNET_DAEMON_MAIN ("gnunet-communicator-udp",
3981 _ ("GNUnet UDP communicator"),
3982 &run)
3983/* end of gnunet-communicator-udp.c */
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:38
static int ret
Final status code.
Definition gnunet-arm.c:93
static int do_shutdown
Set to GNUNET_YES if we are shutting down.
static uint16_t port
Port number.
Definition gnunet-bcd.c:146
static struct GNUNET_NETWORK_Handle * udp_sock
Our socket.
static void inject_rekey(struct Queue *queue)
Inject a struct TCPRekey message into the queue's plaintext buffer.
#define AES_KEY_SIZE
AES key size.
static struct BroadcastInterface * bi_tail
Broadcast interface tasks.
#define DEFAULT_REKEY_TIME_INTERVAL
How often do we rekey based on time (at least)
static int try_decrypt(const struct SharedSecret *ss, const uint8_t *tag, uint32_t serial, const char *in_buf, size_t in_buf_size, char *out_buf)
Try to decrypt buf using shared secret ss and key/iv derived using serial.
#define WORKING_QUEUE_INTERVALL
static void kce_destroy(struct KeyCacheEntry *kce)
Free memory used by key cache entry.
static int handle_ack(void *cls, const struct GNUNET_HashCode *key, void *value)
We received an ACK for pid.
static void create_rekey(struct ReceiverAddress *receiver, struct SharedSecret *ss, struct UDPRekey *rekey)
static void mq_destroy_d(struct GNUNET_MQ_Handle *mq, void *impl_state)
Signature of functions implementing the destruction of a message queue.
static int secret_destroy(struct SharedSecret *ss)
Destroy ss and associated key cache entries.
#define GCM_TAG_SIZE
Size of the GCM tag.
static void get_iv_key(const struct GNUNET_ShortHashCode *msec, uint32_t serial, char key[(256/8)], char iv[(96/8)])
Compute key and iv.
static void mq_send_kx(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *msg, void *impl_state)
Signature of functions implementing the sending functionality of a message queue.
static struct SharedSecret * setup_initial_shared_secret_ephemeral(struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct ReceiverAddress *receiver)
Setup new shared secret for encryption using KEM for initial handshake.
#define COMMUNICATOR_ADDRESS_PREFIX
Address prefix used by the communicator.
static void kce_generate(struct SharedSecret *ss, uint32_t seq)
Setup key cache entry for sequence number seq and shared secret ss.
static void setup_cipher(const struct GNUNET_ShortHashCode *msec, uint32_t serial, gcry_cipher_hd_t *cipher)
Setup cipher based on shared secret msec and serial number serial.
static struct GNUNET_NETWORK_Handle * create_udp_socket(const char *bindto, sa_family_t family, struct sockaddr **out, socklen_t *out_len)
static void add_acks(struct SharedSecret *ss, int acks_to_add)
#define ADDRESS_VALIDITY_PERIOD
How long do we believe our addresses to remain up (before the other peer should revalidate).
static struct GNUNET_SCHEDULER_Task * read_v6_task
ID of read IPv6 task.
static void eddsa_pub_to_hpke_key(const struct GNUNET_CRYPTO_EddsaPublicKey *edpk, struct GNUNET_CRYPTO_HpkePublicKey *pk)
static struct GNUNET_SCHEDULER_Task * read_v4_task
ID of read IPv4 task.
static void mq_destroy_kx(struct GNUNET_MQ_Handle *mq, void *impl_state)
Signature of functions implementing the destruction of a message queue.
static int get_receiver_delete_it(void *cls, const struct GNUNET_HashCode *target, void *value)
Iterator over all receivers to clean up.
static void try_connection_reversal(void *cls, const struct sockaddr *addr, socklen_t addrlen)
static void eddsa_priv_to_hpke_key(const struct GNUNET_CRYPTO_EddsaPrivateKey *edpk, struct GNUNET_CRYPTO_HpkePrivateKey *pk)
static struct GNUNET_SCHEDULER_Task * broadcast_task
ID of master broadcast task.
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
static int verify_confirmation(const struct GNUNET_CRYPTO_HpkeEncapsulation *enc, const struct UDPConfirmation *uc)
Check signature from uc against ephemeral.
static int disable_v6
IPv6 disabled or not.
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static struct GNUNET_NETWORK_Handle * default_v4_sock
Our IPv4 socket.
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 a backchannel message for this communicator (...
static struct SenderAddress * setup_sender(const struct GNUNET_PeerIdentity *target, const struct sockaddr *address, socklen_t address_len)
Create sender address for target.
static struct GNUNET_TIME_Relative rekey_interval
The rekey interval.
static void start_burst(const char *addr, struct GNUNET_TIME_Relative rtt, struct GNUNET_PeerIdentity *pid)
static void reschedule_receiver_timeout(struct ReceiverAddress *receiver)
Increment receiver timeout due to activity.
static struct SharedSecret * setup_shared_secret_ephemeral(struct GNUNET_CRYPTO_HpkeEncapsulation *ephemeral, struct ReceiverAddress *receiver)
Setup new shared secret for encryption using KEM.
static void get_kid(const struct GNUNET_ShortHashCode *msec, uint32_t serial, struct GNUNET_ShortHashCode *kid)
Compute kid.
static void do_pad(gcry_cipher_hd_t out_cipher, char *dgram, size_t pad_size)
Pad dgram by pad_size using out_cipher.
static void mq_send_d(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 sock_read(void *cls)
Socket read task.
static void reschedule_sender_timeout(struct SenderAddress *sender)
Increment sender timeout due to activity.
static struct GNUNET_CONTAINER_Heap * senders_heap
Expiration heap for senders (contains struct SenderAddress)
static int get_sender_delete_it(void *cls, const struct GNUNET_HashCode *target, void *value)
Iterator over all senders to clean up.
#define COMMUNICATOR_CONFIG_SECTION
Configuration section used by the communicator.
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 GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
static void sender_destroy(struct SenderAddress *sender)
Functions with this signature are called whenever we need to close a sender's state due to timeout.
static struct SharedSecret * setup_initial_shared_secret_dec(const struct GNUNET_CRYPTO_HpkeEncapsulation *c)
Setup shared secret for decryption for initial handshake.
static void setup_receiver_mq(struct ReceiverAddress *receiver)
Setup the MQ for the receiver.
static int handle_ack_by_sender(void *cls, const struct GNUNET_HashCode *key, void *value)
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
#define DEFAULT_REKEY_MAX_BYTES
Default value for how often we do rekey based on number of bytes transmitted? (additionally randomize...
static struct GNUNET_NAT_Handle * nat
Connection to NAT service.
static void shutdown_run(struct sockaddr *addrs[2])
static struct GNUNET_CONTAINER_MultiHashMap * receivers
Receivers (map from peer identity to struct ReceiverAddress)
#define GENERATE_AT_ONCE
static void kce_generate_cb(void *cls)
static void try_handle_plaintext(struct SenderAddress *sender, const void *buf, size_t buf_size)
Test if we have received a valid message in plaintext.
static struct GNUNET_PILS_KeyRing * key_ring
For PILS.
static void receiver_destroy(struct ReceiverAddress *receiver)
Destroys a receiving state due to timeout or shutdown.
static struct GNUNET_CONTAINER_MultiShortmap * key_cache
Cache of pre-generated key IDs.
static void udp_socket_notify(struct GNUNET_UdpSocketInfo *sock_info)
#define KCN_TARGET
How many KCNs do we keep around after we hit the KCN_THRESHOLD? Should be larger than KCN_THRESHOLD s...
static void mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state)
Implementation function that cancels the currently sent message.
static struct GNUNET_TRANSPORT_ApplicationHandle * ah
Our handle to report addresses for validation to TRANSPORT.
static void bi_destroy(struct BroadcastInterface *bi)
An interface went away, stop broadcasting on it.
static void pass_plaintext_to_core(struct SenderAddress *sender, const void *plaintext, size_t plaintext_len)
We received plaintext_len bytes of plaintext from a sender.
static struct GNUNET_CONTAINER_MultiHashMap * senders
Senders (map from peer identity to struct SenderAddress)
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 do_broadcast(void *cls)
Scan interfaces to broadcast our presence on the LAN.
#define INTERFACE_SCAN_FREQUENCY
How often do we scan for changes to our network interfaces?
static struct sockaddr * udp_address_to_sockaddr(const char *bindto, sa_family_t family, socklen_t *sock_len)
Convert UDP bind specification to a struct sockaddr *
static struct GNUNET_CONTAINER_Heap * receivers_heap
Expiration heap for receivers (contains struct ReceiverAddress)
static uint16_t my_port
Port number to which we are actually bound.
static char * sockaddr_to_udpaddr_string(const struct sockaddr *address, socklen_t address_len)
Converts address to the address string format used by this communicator in HELLOs.
static void check_timeouts(void *cls)
Task run to check #receiver_heap and #sender_heap for timeouts.
static void calculate_cmac(struct SharedSecret *ss)
Calculate cmac from master in ss.
static struct GNUNET_SCHEDULER_Task * timeout_task
ID of timeout task.
char * my_ipv4
Our ipv4 address.
static struct GNUNET_SCHEDULER_Task * burst_task
static struct SharedSecret * setup_shared_secret_dec(const struct GNUNET_CRYPTO_HpkeEncapsulation *ephemeral)
Setup shared secret for decryption.
#define MAX_SQN_DELTA
What is the maximum delta between KCN sequence numbers that we allow.
#define KCN_THRESHOLD
If we fall below this number of available KCNs, we generate additional ACKs until we reach KCN_TARGET...
#define MAX_SECRETS
How many shared master secrets do we keep around at most per sender? Should be large enough so that w...
static struct BroadcastInterface * bi_head
Broadcast interface tasks.
static enum GNUNET_GenericReturnValue create_receiver(const struct GNUNET_PeerIdentity *peer, const char *address, struct GNUNET_NETWORK_Handle *udp_sock)
static struct GNUNET_NETWORK_Handle * get_socket(struct ReceiverAddress *receiver)
static void send_msg_with_kx(const struct GNUNET_MessageHeader *msg, struct ReceiverAddress *receiver, struct GNUNET_MQ_Handle *mq)
static struct GNUNET_NETWORK_Handle * default_v6_sock
Our IPv6 socket.
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 int iface_proc(void *cls, const char *name, int isDefault, const struct sockaddr *addr, const struct sockaddr *broadcast_addr, const struct sockaddr *netmask, socklen_t addrlen)
Callback function invoked for each interface found.
static void ifc_broadcast(void *cls)
Broadcast our presence on one of our interfaces.
static struct GNUNET_PILS_Handle * pils
For PILS.
static void decrypt_box(const struct UDPBox *box, size_t box_len, struct KeyCacheEntry *kce)
We received a box with matching kce.
static unsigned int purge_secrets(struct SharedSecret *ss_list_tail)
Best effort try to purge some secrets.
static void consider_ss_ack(struct SharedSecret *ss)
We established a shared secret with a sender.
static unsigned long long rekey_max_bytes
How often we do rekey based on number of bytes transmitted.
#define AES_IV_SIZE
AES (GCM) IV size.
#define BROADCAST_FREQUENCY
How often do we broadcast our presence on the LAN?
static struct GNUNET_TRANSPORT_AddressIdentifier * ai
Handle to the operation that publishes our address.
static struct GNUNET_SCHEDULER_Task * st
The shutdown task.
static char * address
GNS address for this phone.
struct GNUNET_HashCode key
The key used in the DHT.
static OpusEncoder * enc
OPUS encoder.
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
struct GNUNET_CRYPTO_BlindablePrivateKey pk
Private key from command line option, or NULL.
static char * name
Name (label) of the records to list.
static char * value
Value of the record to add/remove.
static uint32_t type
Type string converted to DNS type value.
static struct GNUNET_NAT_AUTO_Test * nt
Handle to a NAT test operation.
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
struct GNUNET_CRYPTO_EddsaPrivateKey my_private_key
The current private key.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
static struct GNUNET_FS_UnindexContext * uc
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
struct GNUNET_PILS_Handle * GNUNET_PILS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_PILS_PidChangeCallback pid_change_cb, void *cls)
Connect to the PILS service.
Definition pils_api.c:465
void GNUNET_PILS_disconnect(struct GNUNET_PILS_Handle *handle)
Disconnect from the PILS service.
Definition pils_api.c:488
struct GNUNET_PILS_KeyRing * GNUNET_PILS_create_key_ring(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_SCHEDULER_TaskCallback init_cb, void *cls)
Create a key ring handle to use the current peer identity key.
Definition pils_api.c:804
void GNUNET_PILS_destroy_key_ring(struct GNUNET_PILS_KeyRing *key_ring)
Destroy a key ring handle and free its memory.
Definition pils_api.c:864
const struct GNUNET_PeerIdentity * GNUNET_PILS_get_identity(const struct GNUNET_PILS_Handle *handle)
Return the current peer identity of a given handle.
Definition pils_api.c:727
const struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_PILS_key_ring_get_private_key(const struct GNUNET_PILS_KeyRing *key_ring)
Return the current private key of a given key ring handle.
Definition pils_api.c:887
Constants for network protocols.
#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_UDP_BROADCAST
Signature used by UDP broadcasts.
#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_UDP_HANDSHAKE
Signature used by UDP communicator handshake.
API to create, modify and access statistics.
Bandwidth allocation API for applications to interact with.
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_burst_finished(struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
The communicator tells the transport service that it finished the burst.
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.
void GNUNET_TRANSPORT_application_done(struct GNUNET_TRANSPORT_ApplicationHandle *ch)
Shutdown TRANSPORT application client.
#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_application_validate(struct GNUNET_TRANSPORT_ApplicationHandle *ch, const struct GNUNET_PeerIdentity *peer, enum GNUNET_NetworkType nt, const char *addr)
An application (or a communicator) has received a HELLO (or other address data of another peer) and w...
void GNUNET_TRANSPORT_communicator_mq_update(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const struct GNUNET_TRANSPORT_QueueHandle *u_qh, uint64_t q_len, uint32_t priority)
Notify transport service that an MQ was updated.
void GNUNET_TRANSPORT_communicator_notify(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const struct GNUNET_PeerIdentity *pid, const char *comm, const struct GNUNET_MessageHeader *header)
The communicator asks the transport service to route a message via a different path to another commun...
void GNUNET_TRANSPORT_communicator_disconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
Disconnect from the transport service.
struct GNUNET_TRANSPORT_ApplicationHandle * GNUNET_TRANSPORT_application_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the TRANSPORT application client handle.
struct GNUNET_TRANSPORT_CommunicatorHandle * GNUNET_TRANSPORT_communicator_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *config_section_name, const char *addr_prefix, enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, GNUNET_TRANSPORT_CommunicatorMqInit mq_init, void *mq_init_cls, GNUNET_TRANSPORT_CommunicatorNotify notify_cb, void *notify_cb_cls, GNUNET_TRANSPORT_StartBurstNotify sb)
Connect to the transport service.
struct GNUNET_TRANSPORT_AddressIdentifier * GNUNET_TRANSPORT_communicator_address_add(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const char *address, enum GNUNET_NetworkType nt, struct GNUNET_TIME_Relative expiration)
Notify transport service about an address that this communicator provides for this peer.
void GNUNET_TRANSPORT_communicator_address_remove_all(struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
Notify transport service that this communicator no longer provides all its addresses for this peer.
@ GNUNET_TRANSPORT_CC_UNRELIABLE
Transmission is unreliable (e.g.
@ GNUNET_TRANSPORT_CS_OUTBOUND
this is an outbound connection (transport initiated)
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_size(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *size)
Get a configuration value that should be a size in bytes.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_time(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, struct GNUNET_TIME_Relative *time)
Get a configuration value that should be a relative time.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don't receive messages from the peer?
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_kem_decaps(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *prk)
Decapsulate a key for a private EdDSA key.
uint64_t GNUNET_CRYPTO_random_u64(uint64_t max)
Generate a random unsigned 64-bit value.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_elligator_kem_encaps(const struct GNUNET_CRYPTO_HpkePublicKey *pkR, struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *shared_secret)
Carries out ecdh encapsulation with given public key and the private key from a freshly created ephem...
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_elligator_kem_decaps(const struct GNUNET_CRYPTO_HpkePrivateKey *skR, const struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *shared_secret)
Carries out ecdh decapsulation with own private key and the representative of the received public key...
void GNUNET_CRYPTO_random_block(void *buffer, size_t length)
Fill block with a random values.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_kem_encaps(const struct GNUNET_CRYPTO_EddsaPublicKey *pub, struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *prk)
Encapsulate key material for a EdDSA public key.
#define GNUNET_CRYPTO_eddsa_sign(priv, ps, sig)
EdDSA sign a given block.
#define GNUNET_CRYPTO_eddsa_verify(purp, ps, sig, pub)
Verify EdDSA signature.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hkdf_extract(struct GNUNET_ShortHashCode *prk, const void *salt, size_t salt_len, const void *ikm, size_t ikm_len)
HKDF-Extract using SHA256.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition crypto_hash.c:40
#define GNUNET_CRYPTO_hkdf_expand(result, out_len, prk,...)
HKDF-Expand using SHA256.
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.
struct GNUNET_CONTAINER_MultiShortmap * GNUNET_CONTAINER_multishortmap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multishortmap_put(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
void * GNUNET_CONTAINER_multishortmap_get(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Given a key find a value in the map matching the key.
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.
void GNUNET_CONTAINER_multishortmap_destroy(struct GNUNET_CONTAINER_MultiShortmap *map)
Destroy a hash map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_get_multiple(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map that match a particular key.
unsigned int GNUNET_CONTAINER_multishortmap_size(const struct GNUNET_CONTAINER_MultiShortmap *map)
Get the number of key-value pairs in the map.
int GNUNET_CONTAINER_multishortmap_remove(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, const void *value)
Remove the given key-value pair from the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
void * GNUNET_CONTAINER_heap_remove_node(struct GNUNET_CONTAINER_HeapNode *node)
Removes a node from the heap.
void * GNUNET_CONTAINER_heap_peek(const struct GNUNET_CONTAINER_Heap *heap)
Get element stored at the root of heap.
void GNUNET_CONTAINER_heap_update_cost(struct GNUNET_CONTAINER_HeapNode *node, GNUNET_CONTAINER_HeapCostType new_cost)
Updates the cost of any node in the tree.
struct GNUNET_CONTAINER_HeapNode * GNUNET_CONTAINER_heap_insert(struct GNUNET_CONTAINER_Heap *heap, void *element, GNUNET_CONTAINER_HeapCostType cost)
Inserts a new element into the heap.
struct GNUNET_CONTAINER_Heap * GNUNET_CONTAINER_heap_create(enum GNUNET_CONTAINER_HeapOrder order)
Create a new heap.
void GNUNET_CONTAINER_heap_destroy(struct GNUNET_CONTAINER_Heap *heap)
Destroys the heap.
@ GNUNET_CONTAINER_HEAP_ORDER_MIN
Heap with the minimum cost at the root.
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_log(kind,...)
void GNUNET_CRYPTO_hash_context_read(struct GNUNET_HashContext *hc, const void *buf, size_t size)
Add data to be hashed.
#define GNUNET_CRYPTO_kdf_arg_string(d)
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_sk_to_x25519(const struct GNUNET_CRYPTO_BlindablePrivateKey *sk, struct GNUNET_CRYPTO_HpkePrivateKey *sk_enc)
Convert a GNUnet identity key to a key sutiable for HPKE (X25519)
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
void GNUNET_CRYPTO_hash_context_finish(struct GNUNET_HashContext *hc, struct GNUNET_HashCode *r_hash)
Finish the hash computation.
#define GNUNET_CRYPTO_kdf_arg_auto(d)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_pk_to_x25519(const struct GNUNET_CRYPTO_BlindablePublicKey *pk, struct GNUNET_CRYPTO_HpkePublicKey *pk_enc)
Convert a GNUnet identity key to a key sutiable for HPKE (X25519)
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.
#define GNUNET_PACKED
gcc-ism to get packed structs.
@ GNUNET_PUBLIC_KEY_TYPE_EDDSA
EDDSA identity.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
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...
void GNUNET_log_from_nocheck(enum GNUNET_ErrorType kind, const char *comp, const char *message,...) __attribute__((format(printf
Log function that specifies an alternative component.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
GNUNET_MQ_Error
Error codes for the queue.
struct GNUNET_MQ_Handle * GNUNET_MQ_queue_for_callbacks(GNUNET_MQ_SendImpl send, GNUNET_MQ_DestroyImpl destroy, GNUNET_MQ_CancelImpl cancel, void *impl_state, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *cls)
Create a message queue for the specified handlers.
Definition mq.c:482
void GNUNET_MQ_impl_send_continue(struct GNUNET_MQ_Handle *mq)
Call the send implementation for the next queued message, if any.
Definition mq.c:437
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition mq.c:700
struct GNUNET_SCHEDULER_Task * GNUNET_get_udp_socket(struct GNUNET_UdpSocketInfo *sock_info, GNUNET_NotifyUdpSocket nus)
Method to get a UDP socket for a peer that is natted.
Definition nat.c:513
struct GNUNET_NAT_Handle * GNUNET_NAT_register(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *config_section, uint8_t proto, unsigned int num_addrs, const struct sockaddr **addrs, const socklen_t *addrlens, GNUNET_NAT_AddressCallback address_callback, GNUNET_NAT_ReversalCallback reversal_callback, void *callback_cls)
Attempt to enable port redirection and detect public IP address contacting UPnP or NAT-PMP routers on...
Definition nat_api.c:366
void GNUNET_NAT_unregister(struct GNUNET_NAT_Handle *nh)
Stop port redirection and public IP address detection for the given handle.
Definition nat_api.c:703
void GNUNET_stop_burst(struct GNUNET_NETWORK_Handle *do_not_touch)
Method to stop all sockets we established to the other peer.
Definition nat.c:568
GNUNET_NAT_AddressClass
Some addresses contain sensitive information or are not suitable for global distribution.
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_recvfrom(const struct GNUNET_NETWORK_Handle *desc, void *buffer, size_t length, struct sockaddr *src_addr, socklen_t *addrlen)
Read data from a socket (always non-blocking).
Definition network.c:687
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_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
int GNUNET_NETWORK_socket_setsockopt(struct GNUNET_NETWORK_Handle *fd, int level, int option_name, const void *option_value, socklen_t option_len)
Set socket option.
Definition network.c:805
ssize_t GNUNET_NETWORK_socket_sendto(const struct GNUNET_NETWORK_Handle *desc, const void *message, size_t length, const struct sockaddr *dest_addr, socklen_t dest_len)
Send data to a particular destination (always non-blocking).
Definition network.c:771
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
void GNUNET_NT_scanner_done(struct GNUNET_NT_InterfaceScanner *is)
Terminate interface scanner.
Definition nt.c:428
struct GNUNET_NT_InterfaceScanner * GNUNET_NT_scanner_init(void)
Initialize the address characterization client handle.
Definition nt.c:407
enum GNUNET_NetworkType GNUNET_NT_scanner_get_type(struct GNUNET_NT_InterfaceScanner *is, const struct sockaddr *addr, socklen_t addrlen)
Returns where the address is located: loopback, LAN or WAN.
Definition nt.c:309
@ GNUNET_NT_LOOPBACK
Loopback (same host).
void GNUNET_OS_network_interfaces_list(GNUNET_OS_NetworkInterfaceProcessor proc, void *proc_cls)
Enumerate all network interfaces.
Definition os_network.c:397
#define GNUNET_DAEMON_MAIN(daemon_name, daemon_help, init_cb)
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_REKEY
UDP Rekey.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD
UDP communicator padding.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK
UDP KX acknowledgement.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition scheduler.c:572
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition scheduler.c:1517
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition scheduler.c:1345
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:986
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition scheduler.c:1310
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition scheduler.c:1283
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
struct GNUNET_TIME_Relative GNUNET_TIME_relative_min(struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
Return the minimum of two relative time values.
Definition time.c:344
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition time.c:406
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition time.c:316
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_monotonic(const struct GNUNET_CONFIGURATION_Handle *cfg)
Obtain the current time and make sure it is monotonically increasing.
Definition time.c:860
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition time.c:636
#define _(String)
GNU gettext support macro.
Definition platform.h:179
static struct GNUNET_MQ_Handle * mq
Our connection to the resolver service, created on-demand, but then persists until error or shutdown.
static void receiver(void *cls, const void *buf, size_t available, const struct sockaddr *addr, socklen_t addrlen, int errCode)
Callback to read from the SOCKS5 proxy.
Definition socks.c:330
const struct UDPAck * ack
const struct GNUNET_PeerIdentity * sender
Interface we broadcast our presence on.
socklen_t salen
Number of bytes in sa.
struct ipv6_mreq mcreq
If this is an IPv6 interface, this is the request we use to join/leave the group.
struct BroadcastInterface * next
Kept in a DLL.
int found
Was this interface found in the last iface_proc() scan?
struct UDPBroadcast bcm
Message we broadcast on this interface.
struct sockaddr * ba
Broadcast address to use on the interface.
struct GNUNET_SCHEDULER_Task * broadcast_task
Task for this broadcast interface.
struct BroadcastInterface * prev
Kept in a DLL.
struct sockaddr * sa
Sender's address of the interface.
Message send during burst mode.
struct GNUNET_PeerIdentity peer
The peer who send the msg.
unsigned int local_port
The local port the message was send from.
Handle to a node in a heap.
Internal representation of the hash map.
Internal representation of the hash map.
A private key for an identity as per LSD0001.
An identity key as per LSD0001.
Private ECC key encoded for transmission.
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
an ECC signature using EdDSA.
HPKE DHKEM encapsulation (X25519) See RFC 9180.
A public key used for decryption.
A public key used for encryption.
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
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
A handle for the PILS service.
Definition pils_api.c:82
A simplified handle for using the peer identity key.
Definition pils_api.c:132
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Entry in list of pending tasks.
Definition scheduler.c:141
Handle for the service.
A 256-bit hashcode.
Time for absolute time used by GNUnet, in microseconds and in network byte order.
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
Internal representation of an address a communicator is currently providing for the transport service...
Handle to the TRANSPORT subsystem for application management.
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...
Standard IPv4 header.
Standard IPv6 header.
UDP packet header.
Struct with the socket we like to use to send messages to another peer.
const char * bind_address
Our address without port.
enum GNUNET_GenericReturnValue has_port
Flag indicating, if the address is without port information.
struct GNUNET_TIME_Relative rtt
The actual RTT between the peers.
char * address
The address of the other peer without port.
unsigned int std_port
Default local port we are bound to.
struct sockaddr * actual_address
The address of the other peer we received a burst message from.
struct GNUNET_NETWORK_Handle * udp_sock
struct GNUNET_PeerIdentity * pid
The peer we like to connect to.
"Plaintext" header at beginning of KX message.
uint8_t gcm_tag[(128/8)]
HMAC for the following encrypted message, using GCM.
struct GNUNET_CRYPTO_HpkeEncapsulation enc
Representative of ephemeral key for KX.
Pre-generated "kid" code (key and IV identification code) to quickly derive master key for a struct U...
struct GNUNET_ShortHashCode kid
Key and IV identification code.
uint32_t sequence_number
Sequence number used to derive this entry from master key.
struct KeyCacheEntry * next
Kept in a DLL.
struct KeyCacheEntry * prev
Kept in a DLL.
struct SharedSecret * ss
Corresponding shared secret.
Information we track per receiving address we have recently been in contact with (encryption to recei...
struct GNUNET_CONTAINER_HeapNode * hn
Entry in sender expiration heap.
struct GNUNET_TIME_Absolute rekey_timeout
Timeout for this receiver address.
struct SharedSecret * ss_tail
Shared secrets we received with target, last used is tail.
char * foreign_addr
Address of the receiver in the human-readable format with the COMMUNICATOR_ADDRESS_PREFIX.
struct GNUNET_SCHEDULER_Task * read_task
Read task, if this receiver has its own socket.
unsigned int acks_available
Number of BOX keys from ACKs we have currently available for this receiver.
struct SharedSecret * ss_head
Shared secrets we received from target, first used is head.
struct GNUNET_TRANSPORT_QueueHandle * kx_qh
handle for KX queue with the ch.
unsigned int num_secrets
Length of the DLL at ss_head.
struct GNUNET_TIME_Absolute timeout
Timeout for this receiver address.
size_t kx_mtu
MTU we allowed transport for this receiver's KX queue.
struct sockaddr * address
Address of the other peer.
struct GNUNET_PeerIdentity target
To whom are we talking to.
socklen_t address_len
Length of the address.
struct GNUNET_MQ_Handle * kx_mq
KX message queue we are providing for the ch.
int receiver_destroy_called
receiver_destroy already called on receiver.
struct GNUNET_NETWORK_Handle * udp_sock
Socket this receiver got via NAT traversal.
size_t d_mtu
MTU we allowed transport for this receiver's default queue.
enum GNUNET_NetworkType nt
Which network type does this queue use?
struct GNUNET_MQ_Handle * d_mq
Default message queue we are providing for the ch.
struct GNUNET_CRYPTO_HpkePublicKey target_hpke_key
To whom are we talking to.
struct GNUNET_TRANSPORT_QueueHandle * d_qh
handle for default queue with the ch.
struct GNUNET_HashCode key
The address key for this entry.
Closure for #find_sender_by_address()
const struct sockaddr * address
Address we are looking for.
struct SenderAddress * sender
Return value to set if we found a match.
socklen_t address_len
Number of bytes in address.
Information we track per sender address we have recently been in contact with (we decrypt messages fr...
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct GNUNET_CONTAINER_HeapNode * hn
Entry in sender expiration heap.
struct sockaddr * address
Address of the other peer.
socklen_t address_len
Length of the address.
enum GNUNET_NetworkType nt
Which network type does this queue use?
unsigned int acks_available
Number of BOX keys from ACKs we have currently available for this sender.
unsigned int num_secrets
Length of the DLL at ss_head.
int kce_send_ack_on_finish
When KCE finishes, send ACK if GNUNET_YES.
struct GNUNET_TIME_Absolute timeout
Timeout for this sender.
int kce_task_finished
Is the kce_task finished?
struct GNUNET_SCHEDULER_Task * kce_task
ID of kce working queue task.
struct GNUNET_HashCode key
The address key for this entry.
struct SharedSecret * ss_head
Shared secrets we used with target, first used is head.
int sender_destroy_called
sender_destroy already called on sender.
struct SharedSecret * ss_tail
Shared secrets we used with target, last used is tail.
Shared secret we generated for a particular sender or receiver.
struct KeyCacheEntry * kce_tail
Kept in a DLL, sorted by sequence number.
uint32_t sequence_allowed
Up to which sequence number did the other peer allow us to use this key, or up to which number did we...
struct SharedSecret * next
Kept in a DLL.
unsigned int active_kce_count
Number of active KCN entries.
uint32_t sequence_used
Up to which sequence number did we use this master already? (for encrypting only)
size_t bytes_sent
Bytes sent with this shared secret.
struct SharedSecret * prev
Kept in a DLL.
struct SenderAddress * sender
Sender we use this shared secret with, or NULL.
struct KeyCacheEntry * kce_head
Kept in a DLL, sorted by sequence number.
struct GNUNET_HashCode cmac
CMAC is used to identify master in ACKs.
struct ReceiverAddress * receiver
Receiver we use this shared secret with, or NULL.
struct GNUNET_ShortHashCode master
Master shared secret.
int override_available_acks
Also precompute keys despite sufficient acks (for rekey)
int rekey_initiated
rekey initiated for this secret?
UDP key acknowledgement.
uint32_t sequence_ack
Sequence acknowledgement limit.
struct GNUNET_HashCode cmac
CMAC of the base key being acknowledged.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK.
UDP message box.
uint8_t gcm_tag[(128/8)]
128-bit authentication tag for the following encrypted message, from GCM.
struct GNUNET_ShortHashCode kid
Key and IV identification code.
Broadcast by peer in LAN announcing its presence.
struct GNUNET_CRYPTO_EddsaSignature sender_sig
Sender's signature of type GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_UDP_BROADCAST.
struct GNUNET_PeerIdentity sender
Sender's peer identity.
Encrypted continuation of UDP initial handshake, followed by message header with payload.
struct GNUNET_PeerIdentity sender
Sender's identity.
struct GNUNET_CRYPTO_EddsaSignature sender_sig
Sender's signature of type GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_UDP_HANDSHAKE.
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
Plaintext of a rekey payload in a UDPBox.
struct GNUNET_CRYPTO_HpkeEncapsulation ephemeral
Ephemeral key to rekey with.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_REKEY.
Signature we use to verify that the broadcast was really made by the peer that claims to have made it...
struct GNUNET_CRYPTO_SignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_UDP_BROADCAST.
struct GNUNET_HashCode h_address
Hash of the sender's UDP address.
struct GNUNET_PeerIdentity sender
Identity of the inititor of the UDP broadcast.
Signature we use to verify that the ephemeral key was really chosen by the specified sender.
struct GNUNET_CRYPTO_HpkeEncapsulation enc
Ephemeral key used by the sender.
struct GNUNET_PeerIdentity receiver
Presumed identity of the target of the UDP connection (UDP server)
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_SignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_UDP_HANDSHAKE.
struct GNUNET_PeerIdentity sender
Identity of the inititor of the UDP connection (UDP client).