GNUnet  0.19.3
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 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_util_lib.h"
42 #include "gnunet_protocols.h"
43 #include "gnunet_signatures.h"
44 #include "gnunet_constants.h"
45 #include "gnunet_nt_lib.h"
46 #include "gnunet_nat_service.h"
50 
54 #define DEFAULT_REKEY_TIME_INTERVAL GNUNET_TIME_UNIT_DAYS
55 
59 #define PROTO_QUEUE_TIMEOUT GNUNET_TIME_UNIT_MINUTES
60 
64 #define BROADCAST_FREQUENCY GNUNET_TIME_UNIT_MINUTES
65 
69 #define INTERFACE_SCAN_FREQUENCY \
70  GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
71 
76 #define ADDRESS_VALIDITY_PERIOD GNUNET_TIME_UNIT_HOURS
77 
78 #define WORKING_QUEUE_INTERVALL \
79  GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS,1)
80 
84 #define AES_KEY_SIZE (256 / 8)
85 
89 #define AES_IV_SIZE (96 / 8)
90 
94 #define GCM_TAG_SIZE (128 / 8)
95 
96 #define GENERATE_AT_ONCE 2
97 
107 #define KCN_THRESHOLD 92
108 
115 #define KCN_TARGET 128
116 
126 #define MAX_SQN_DELTA 160
127 
137 #define MAX_SECRETS 128000
138 
143 #define DEFAULT_REKEY_MAX_BYTES (1024LLU * 1024 * 1024 * 4LLU)
144 
149 #define COMMUNICATOR_ADDRESS_PREFIX "udp"
150 
154 #define COMMUNICATOR_CONFIG_SECTION "communicator-udp"
155 
157 
158 
165 {
170 
175 
180 
185 
191 };
192 
193 
198 struct InitialKX
199 {
204 
210 
214  int rekeying;
215 };
216 
217 
223 {
228 
233 
239 
240  /* followed by messages */
241 
242  /* padding may follow actual messages */
243 };
244 
245 
250 struct UDPAck
251 {
256 
262 
268 
272  struct GNUNET_HashCode cmac;
273 };
274 
275 
285 {
290 
295 
299  struct GNUNET_HashCode h_address;
300 };
301 
302 
310 {
315 
321 };
322 
323 
328 struct UDPBox
329 {
337  struct GNUNET_ShortHashCode kid;
338 
347 
351  int rekeying;
352 };
353 
358 struct UDPRekey
359 {
367  struct GNUNET_ShortHashCode kid;
368 
377 
382 };
383 
385 
389 struct SharedSecret;
390 
391 
397 {
402 
407 
415  struct GNUNET_ShortHashCode kid;
416 
420  struct SharedSecret *ss;
421 
425  uint32_t sequence_number;
426 };
427 
428 
433 struct SenderAddress;
434 
439 struct ReceiverAddress;
440 
445 {
450 
455 
460 
465 
470 
475 
479  struct GNUNET_HashCode master;
480 
484  struct GNUNET_HashCode cmac;
485 
490  uint32_t sequence_used;
491 
498 
502  unsigned int active_kce_count;
503 };
504 
505 
511 {
516 
520  int rekeying;
521 
526 
531 
536 
541 
545  struct sockaddr *address;
546 
550  socklen_t address_len;
551 
556 
560  unsigned int num_secrets;
561 
566  unsigned int acks_available;
567 
571  enum GNUNET_NetworkType nt;
572 
577 
578 
583 
588 
593 };
594 
595 
601 {
602 
607 
611  unsigned int rekey_acks_available;
612 
617 
622 
626  int rekeying;
627 
632 
637 
642 
647 
653 
657  struct sockaddr *address;
658 
662  socklen_t address_len;
663 
668 
673 
678 
683 
688 
693 
697  size_t kx_mtu;
698 
702  size_t d_mtu;
703 
707  unsigned int num_secrets;
708 
713  unsigned int acks_available;
714 
718  enum GNUNET_NetworkType nt;
719 
724 };
725 
730 {
735 
740 
745 
749  struct sockaddr *sa;
750 
754  struct sockaddr *ba;
755 
759  struct UDPBroadcast bcm;
760 
765  struct ipv6_mreq mcreq;
766 
770  socklen_t salen;
771 
775  int found;
776 };
777 
782 
786 static unsigned long long rekey_max_bytes;
791 
796 
801 
806 
811 
816 
821 
826 
831 
836 
841 
846 
851 
856 
860 static int have_v6_socket;
861 
865 static struct GNUNET_PeerIdentity my_identity;
866 
871 
875 static const struct GNUNET_CONFIGURATION_Handle *cfg;
876 
881 
886 
890 static struct GNUNET_NAT_Handle *nat;
891 
895 static uint16_t my_port;
896 
897 
903 static void
905 {
906  if (AF_INET6 == bi->sa->sa_family)
907  {
908  /* Leave the multicast group */
910  IPPROTO_IPV6,
911  IPV6_LEAVE_GROUP,
912  &bi->mcreq,
913  sizeof(bi->mcreq)))
914  {
916  }
917  }
920  GNUNET_free (bi->sa);
921  GNUNET_free (bi->ba);
922  GNUNET_free (bi);
923 }
924 
925 
931 static void
933 {
934 
935  receiver->receiver_destroy_called = GNUNET_YES;
936 
938  "Disconnecting receiver for peer `%s'\n",
939  GNUNET_i2s (&receiver->target));
940  /*if (NULL != (mq = receiver->kx_mq))
941  {
942  receiver->kx_mq = NULL;
943  GNUNET_MQ_destroy (mq);
944  }*/
945  if (NULL != receiver->kx_qh)
946  {
948  receiver->kx_qh = NULL;
949  receiver->kx_mq = NULL;
950  }
951  /*if (NULL != (mq = receiver->d_mq))
952  {
953  receiver->d_mq = NULL;
954  GNUNET_MQ_destroy (mq);
955  }*/
956  if (NULL != receiver->d_qh)
957  {
959  receiver->d_qh = NULL;
960  }
963  &receiver->target,
964  receiver));
967  "# receivers active",
969  GNUNET_NO);
970  GNUNET_free (receiver->address);
971  GNUNET_free (receiver->foreign_addr);
973 }
974 
975 
981 static void
983 {
984  struct SharedSecret *ss = kce->ss;
985 
986  ss->active_kce_count--;
987  ss->sender->acks_available--;
990  &kce->kid,
991  kce));
992  GNUNET_free (kce);
993 }
994 
995 
1003 static void
1004 get_kid (const struct GNUNET_HashCode *msec,
1005  uint32_t serial,
1006  struct GNUNET_ShortHashCode *kid)
1007 {
1008  uint32_t sid = htonl (serial);
1009 
1010  GNUNET_CRYPTO_hkdf (kid,
1011  sizeof(*kid),
1012  GCRY_MD_SHA512,
1013  GCRY_MD_SHA256,
1014  &sid,
1015  sizeof(sid),
1016  msec,
1017  sizeof(*msec),
1018  "UDP-KID",
1019  strlen ("UDP-KID"),
1020  NULL,
1021  0);
1022 }
1023 
1024 
1031 static void
1032 kce_generate (struct SharedSecret *ss, uint32_t seq)
1033 {
1034  struct KeyCacheEntry *kce;
1035 
1036  GNUNET_assert (0 < seq);
1037  kce = GNUNET_new (struct KeyCacheEntry);
1038  kce->ss = ss;
1039  kce->sequence_number = seq;
1040  get_kid (&ss->master, seq, &kce->kid);
1042  ss->active_kce_count++;
1043  ss->sender->acks_available++;
1045  key_cache,
1046  &kce->kid,
1047  kce,
1050  "# KIDs active",
1052  GNUNET_NO);
1053 }
1054 
1055 
1062 static int
1063 secret_destroy (struct SharedSecret *ss, int withoutKce)
1064 {
1065  struct SenderAddress *sender;
1066  struct ReceiverAddress *receiver;
1067  struct KeyCacheEntry *kce;
1068 
1069  if (withoutKce && (ss->sequence_allowed > 0))
1070  return GNUNET_NO;
1071 
1073  "secret %s destroy %u %u\n",
1074  GNUNET_h2s (&ss->master),
1075  withoutKce,
1076  ss->sequence_allowed);
1077  if (NULL != (sender = ss->sender))
1078  {
1079  GNUNET_CONTAINER_DLL_remove (sender->ss_head, sender->ss_tail, ss);
1080  sender->num_secrets--;
1081  }
1082  if (NULL != (receiver = ss->receiver))
1083  {
1084  GNUNET_CONTAINER_DLL_remove (receiver->ss_head, receiver->ss_tail, ss);
1085  receiver->num_secrets--;
1086  // Uncomment this for alternativ 1 of backchannel functionality
1087  receiver->acks_available -= (ss->sequence_allowed - ss->sequence_used);
1089  "%u receiver->acks_available 3\n",
1090  receiver->acks_available);
1091  // Until here for alternativ 1
1092  }
1093  while (NULL != (kce = ss->kce_head))
1094  kce_destroy (kce);
1095  GNUNET_STATISTICS_update (stats, "# Secrets active", -1, GNUNET_NO);
1097  "# KIDs active",
1099  GNUNET_NO);
1100  GNUNET_free (ss);
1101  return GNUNET_YES;
1102 }
1103 
1104 
1111 static void
1113 {
1115  GNUNET_assert (
1116  GNUNET_YES ==
1118  GNUNET_assert (sender == GNUNET_CONTAINER_heap_remove_node (sender->hn));
1120  "# senders active",
1122  GNUNET_NO);
1123  GNUNET_free (sender->address);
1124  GNUNET_free (sender);
1125 }
1126 
1127 
1136 static void
1137 get_iv_key (const struct GNUNET_HashCode *msec,
1138  uint32_t serial,
1139  char key[AES_KEY_SIZE],
1140  char iv[AES_IV_SIZE])
1141 {
1142  uint32_t sid = htonl (serial);
1143  char res[AES_KEY_SIZE + AES_IV_SIZE];
1144 
1146  sizeof(res),
1147  GCRY_MD_SHA512,
1148  GCRY_MD_SHA256,
1149  &sid,
1150  sizeof(sid),
1151  msec,
1152  sizeof(*msec),
1153  "UDP-IV-KEY",
1154  strlen ("UDP-IV-KEY"),
1155  NULL,
1156  0);
1157  memcpy (key, res, AES_KEY_SIZE);
1158  memcpy (iv, &res[AES_KEY_SIZE], AES_IV_SIZE);
1159 }
1160 
1161 
1167 static void
1169 {
1170  sender->timeout =
1173 }
1174 
1175 
1181 static void
1183 {
1184  receiver->timeout =
1187  receiver->timeout.abs_value_us);
1188 }
1189 
1190 
1196 static void
1197 check_timeouts (void *cls)
1198 {
1199  struct GNUNET_TIME_Relative st;
1200  struct GNUNET_TIME_Relative rt;
1201  struct GNUNET_TIME_Relative delay;
1202  struct ReceiverAddress *receiver;
1203  struct SenderAddress *sender;
1204 
1205  (void) cls;
1206  timeout_task = NULL;
1208  while (NULL != (receiver = GNUNET_CONTAINER_heap_peek (receivers_heap)))
1209  {
1210  /* if (GNUNET_YES != receiver->receiver_destroy_called) */
1211  /* { */
1213  if (0 != rt.rel_value_us)
1214  break;
1216  "Receiver timed out\n");
1218  // }
1219  }
1221  while (NULL != (sender = GNUNET_CONTAINER_heap_peek (senders_heap)))
1222  {
1223  if (GNUNET_YES != sender->sender_destroy_called)
1224  {
1226  if (0 != st.rel_value_us)
1227  break;
1228  sender_destroy (sender);
1229  }
1230  }
1232  if (delay.rel_value_us < GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
1234 }
1235 
1236 
1242 static void
1244 {
1245  GNUNET_CRYPTO_hkdf (&ss->cmac,
1246  sizeof(ss->cmac),
1247  GCRY_MD_SHA512,
1248  GCRY_MD_SHA256,
1249  "CMAC",
1250  strlen ("CMAC"),
1251  &ss->master,
1252  sizeof(ss->master),
1253  "UDP-CMAC",
1254  strlen ("UDP-CMAC"),
1255  NULL,
1256  0);
1257 }
1258 
1259 
1268 static void
1270  const void *plaintext,
1271  size_t plaintext_len)
1272 {
1273  const struct GNUNET_MessageHeader *hdr = plaintext;
1274  const char *pos = plaintext;
1275 
1276  while (ntohs (hdr->size) <= plaintext_len)
1277  {
1279  "# bytes given to core",
1280  ntohs (hdr->size),
1281  GNUNET_NO);
1283  "Giving %u bytes to TNG\n", ntohs (hdr->size));
1286  &sender->target,
1287  hdr,
1289  NULL /* no flow control possible */
1290  ,
1291  NULL));
1292  /* move on to next message, if any */
1293  plaintext_len -= ntohs (hdr->size);
1294  if (plaintext_len < sizeof(*hdr))
1295  break;
1296  pos += ntohs (hdr->size);
1297  hdr = (const struct GNUNET_MessageHeader *) pos;
1298  // TODO for now..., we do not actually sen >1msg or have a way of telling
1299  // if we are done
1300  break;
1301  }
1303  "# bytes padding discarded",
1304  plaintext_len,
1305  GNUNET_NO);
1306 }
1307 
1308 
1317 static void
1318 setup_cipher (const struct GNUNET_HashCode *msec,
1319  uint32_t serial,
1320  gcry_cipher_hd_t *cipher)
1321 {
1322  char key[AES_KEY_SIZE];
1323  char iv[AES_IV_SIZE];
1324  int rc;
1325 
1326  GNUNET_assert (0 ==
1327  gcry_cipher_open (cipher,
1328  GCRY_CIPHER_AES256 /* low level: go for speed */,
1329  GCRY_CIPHER_MODE_GCM,
1330  0 /* flags */));
1331  get_iv_key (msec, serial, key, iv);
1332  rc = gcry_cipher_setkey (*cipher, key, sizeof(key));
1333  GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
1334  rc = gcry_cipher_setiv (*cipher, iv, sizeof(iv));
1335  GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
1336 }
1337 
1338 
1351 static int
1352 try_decrypt (const struct SharedSecret *ss,
1353  const char tag[GCM_TAG_SIZE],
1354  uint32_t serial,
1355  const char *in_buf,
1356  size_t in_buf_size,
1357  char *out_buf)
1358 {
1359  gcry_cipher_hd_t cipher;
1360 
1361  setup_cipher (&ss->master, serial, &cipher);
1362  GNUNET_assert (
1363  0 ==
1364  gcry_cipher_decrypt (cipher, out_buf, in_buf_size, in_buf, in_buf_size));
1365  if (0 != gcry_cipher_checktag (cipher, tag, GCM_TAG_SIZE))
1366  {
1367  gcry_cipher_close (cipher);
1369  "# AEAD authentication failures",
1370  1,
1371  GNUNET_NO);
1372  return GNUNET_SYSERR;
1373  }
1374  gcry_cipher_close (cipher);
1375  return GNUNET_OK;
1376 }
1377 
1378 
1385 static struct SharedSecret *
1387 {
1388  struct SharedSecret *ss;
1389 
1390  ss = GNUNET_new (struct SharedSecret);
1391  GNUNET_CRYPTO_eddsa_ecdh (my_private_key, ephemeral, &ss->master);
1392  return ss;
1393 }
1394 
1395 
1403 static struct SharedSecret *
1405  struct ReceiverAddress *receiver, int add_to_receiver)
1406 {
1407  struct SharedSecret *ss;
1408 
1409  ss = GNUNET_new (struct SharedSecret);
1410  GNUNET_CRYPTO_ecdh_eddsa (ephemeral,
1411  &receiver->target.public_key,
1412  &ss->master);
1413  calculate_cmac (ss);
1414  ss->receiver = receiver;
1415  GNUNET_CONTAINER_DLL_insert (receiver->ss_head, receiver->ss_tail, ss);
1416  receiver->num_secrets++;
1417  GNUNET_STATISTICS_update (stats, "# Secrets active", 1, GNUNET_NO);
1418  return ss;
1419 }
1420 
1421 
1429 static void
1431 
1438 static void
1439 destroy_all_secrets (struct SharedSecret *ss, int withoutKce)
1440 {
1441  struct SenderAddress *sender;
1442  struct ReceiverAddress *receiver;
1443  struct SharedSecret *ss_to_destroy;
1444  struct SharedSecret *ss_start;
1445  struct SharedSecret *pos;
1446  int at_least_one_destroyed = GNUNET_NO;
1447 
1449  "Starting destroy all withoutKce: %u.\n",
1450  withoutKce);
1451 
1452  if (NULL != (sender = ss->sender))
1453  {
1454  ss_start = sender->ss_head;
1455  }
1456  else if (NULL != (receiver = ss->receiver))
1457  {
1458  ss_start = receiver->ss_head;
1459  }
1460  else
1461  {
1463  "Shared secret has no sender or receiver!\n");
1464  return;
1465  }
1466 
1467  pos = ss_start;
1468  while (NULL != pos)
1469  {
1470  ss_to_destroy = pos;
1471  pos = pos->next;
1472 
1473  if (ss != ss_to_destroy)
1474  at_least_one_destroyed = secret_destroy (ss_to_destroy, withoutKce);
1475  }
1476 
1477  if ((ss != ss_start) && ! at_least_one_destroyed)
1478  {
1480  "Really destroying all.\n");
1481  destroy_all_secrets (ss_start, GNUNET_NO);
1482  }
1483 
1485  "Finished destroy all.\n");
1486 }
1487 
1488 
1489 static void
1490 add_acks (struct SharedSecret *ss, int acks_to_add)
1491 {
1492 
1493  struct ReceiverAddress *receiver = ss->receiver;
1494 
1495  GNUNET_assert (NULL != ss);
1496  GNUNET_assert (NULL != receiver);
1497 
1498  if (NULL == receiver->d_qh)
1499  {
1500  receiver->d_qh =
1502  &receiver->target,
1503  receiver->foreign_addr,
1504  receiver->d_mtu,
1505  acks_to_add,
1506  1, /* Priority */
1507  receiver->nt,
1509  receiver->d_mq);
1510  }
1511  else
1512  {
1514  receiver->d_qh,
1515  acks_to_add,
1516  1);
1517  }
1518 
1520  "Tell transport we have %u more acks!\n",
1521  acks_to_add);
1523  "%u kce for rekeying.\n",
1524  receiver->number_rekeying_kce);
1525 
1526  // Until here for alternativ 1
1527 
1528  /* move ss to head to avoid discarding it anytime soon! */
1529 
1530  GNUNET_CONTAINER_DLL_remove (receiver->ss_head, receiver->ss_tail, ss);
1531  GNUNET_CONTAINER_DLL_insert (receiver->ss_head, receiver->ss_tail, ss);
1533 }
1534 
1535 
1536 static uint32_t
1538  uint32_t acks_to_add)
1539 {
1540  int needed_for_rekeying;
1541 
1543  "%u kce for rekeying and %u acks_to_add\n",
1544  receiver->number_rekeying_kce,
1545  acks_to_add);
1546 
1547  needed_for_rekeying = (3 - receiver->number_rekeying_kce);
1548  if (acks_to_add <= needed_for_rekeying)
1549  {
1550  receiver->number_rekeying_kce += acks_to_add;
1551  acks_to_add = 0;
1552  }
1553  else
1554  {
1555  acks_to_add -= (3 - receiver->number_rekeying_kce);
1556  receiver->number_rekeying_kce = 3;
1557  }
1558 
1560  "%u kce for rekeying and %u acks_to_add\n",
1561  receiver->number_rekeying_kce,
1562  acks_to_add);
1563  return acks_to_add;
1564 }
1565 
1566 
1567 static void
1569 {
1570  uint32_t acks_to_add = receiver->ss_rekey->sequence_allowed;
1571 
1572  if (receiver->number_rekeying_kce < 3)
1573  acks_to_add = reset_rekey_kces (receiver, acks_to_add);
1574  receiver->acks_available = receiver->ss_rekey->sequence_allowed;
1576  "%u receiver->acks_available 4\n",
1577  receiver->acks_available);
1578  /* add_acks (receiver->ss_rekey, acks_to_add - 3); */
1579  if (0 != acks_to_add)
1580  {
1581  add_acks (receiver->ss_rekey, acks_to_add);
1582  }
1583  receiver->ss_rekey = NULL;
1585  "# rekeying successful\n");
1587  "# rekeying successful",
1588  1,
1589  GNUNET_NO);
1590 }
1591 
1592 
1603 static int
1604 handle_ack (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
1605 {
1606  const struct UDPAck *ack = cls;
1607  struct ReceiverAddress *receiver = value;
1608  uint32_t acks_to_add;
1609  uint32_t allowed;
1610  // int needed_for_rekeying;
1611 
1613  "in handle ack with cmac %s\n",
1614  GNUNET_h2s (&ack->cmac));
1615 
1616  if (NULL != receiver->ss_rekey)
1618  "We have rekey secret with cmac %s \n",
1619  GNUNET_h2s (&receiver->ss_rekey->cmac));
1620 
1621  if ((NULL != receiver->ss_rekey) && (0 == memcmp (&ack->cmac,
1622  &receiver->ss_rekey->cmac,
1623  sizeof(struct
1624  GNUNET_HashCode))) )
1625  {
1626  allowed = ntohl (ack->sequence_max);
1627 
1628  if (allowed > receiver->ss_rekey->sequence_allowed)
1629  {
1631  "%u > %u (%u %u) for rekey secrect %s\n", allowed,
1632  receiver->ss_rekey->sequence_allowed,
1633  receiver->acks_available,
1634  ack->acks_available,
1635  GNUNET_h2s (&receiver->ss_rekey->master));
1636 
1637  receiver->ss_rekey->sequence_allowed = allowed;
1638 
1639  if (GNUNET_NO == receiver->rekeying)
1641 
1642  return GNUNET_NO;
1643  }
1644  }
1645 
1646  (void) pid;
1647  for (struct SharedSecret *ss = receiver->ss_head; NULL != ss; ss = ss->next)
1648  {
1649  if (0 == memcmp (&ack->cmac, &ss->cmac, sizeof(struct GNUNET_HashCode)))
1650  {
1651 
1653  "Found matching mac\n");
1654 
1655  allowed = ntohl (ack->sequence_max);
1656 
1657  if (allowed > ss->sequence_allowed)
1658  {
1660  "%u > %u (%u %u) for secrect %s\n", allowed,
1661  ss->sequence_allowed,
1662  receiver->acks_available,
1663  ack->acks_available,
1664  GNUNET_h2s (&ss->master));
1665  // Uncomment this for alternativ 1 of backchannel functionality
1666  acks_to_add = (allowed - ss->sequence_allowed);
1667  if ((GNUNET_NO == receiver->rekeying) &&
1668  (receiver->number_rekeying_kce < 3) )
1669  acks_to_add = reset_rekey_kces (receiver, acks_to_add);
1670  /* if ((GNUNET_NO == receiver->rekeying) && */
1671  /* (receiver->number_rekeying_kce < */
1672  /* 3) ) */
1673  /* { */
1674  /* needed_for_rekeying = (3 - receiver->number_rekeying_kce); */
1675  /* if (acks_to_add <= needed_for_rekeying) */
1676  /* { */
1677  /* receiver->number_rekeying_kce += acks_to_add; */
1678  /* acks_to_add = 0; */
1679  /* } */
1680  /* else */
1681  /* { */
1682  /* acks_to_add -= (3 - receiver->number_rekeying_kce); */
1683  /* receiver->number_rekeying_kce = 3; */
1684  /* } */
1685  /* } */
1686  /* GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, */
1687  /* "%u kce for rekeying\n", */
1688  /* receiver->number_rekeying_kce); */
1689 
1690  if ((0 != acks_to_add) && (GNUNET_NO == receiver->rekeying))
1691  {
1692  receiver->acks_available += (allowed - ss->sequence_allowed);
1693  ss->sequence_allowed = allowed;
1695  "%u receiver->acks_available 5\n",
1696  receiver->acks_available);
1697  add_acks (ss, acks_to_add);
1698  }
1699  }
1700  return GNUNET_NO;
1701  }
1702  }
1703  return GNUNET_YES;
1704 }
1705 
1706 
1715 static void
1717  const void *buf,
1718  size_t buf_size)
1719 {
1720  const struct GNUNET_MessageHeader *hdr =
1721  (const struct GNUNET_MessageHeader *) buf;
1722  const struct UDPAck *ack = (const struct UDPAck *) buf;
1723  uint16_t type;
1724 
1726  "try_handle_plaintext of size %lu (%u %lu) and type %u\n",
1727  buf_size,
1728  ntohs (hdr->size),
1729  sizeof(*hdr),
1730  ntohs (hdr->type));
1731  if (sizeof(*hdr) > buf_size)
1732  return; /* not even a header */
1733  if (ntohs (hdr->size) > buf_size)
1734  return; /* not even a header */
1735  type = ntohs (hdr->type);
1736  switch (type)
1737  {
1739  /* lookup master secret by 'cmac', then update sequence_max */
1741  &sender->target,
1742  &handle_ack,
1743  (void *) ack);
1744  /* There could be more messages after the ACK, handle those as well */
1745  buf += ntohs (hdr->size);
1746  buf_size -= ntohs (hdr->size);
1747  pass_plaintext_to_core (sender, buf, buf_size);
1748  break;
1749 
1751  /* skip padding */
1752  break;
1753 
1754  default:
1755  pass_plaintext_to_core (sender, buf, buf_size);
1756  }
1757 }
1758 
1759 
1760 static void
1761 kce_generate_cb (void *cls)
1762 {
1763  struct SharedSecret *ss = cls;
1764 
1765  ss->sender->kce_task = NULL;
1766 
1767  if (((GNUNET_NO == ss->sender->rekeying) && (ss->sender->acks_available <
1768  KCN_TARGET) ) ||
1769  ((ss->sender->ss_rekey == ss) && (GNUNET_YES == ss->sender->rekeying) &&
1770  (ss->sender->acks_available < KCN_TARGET)))
1771  {
1772 
1774  "Precomputing keys for master %s\n",
1775  GNUNET_h2s (&(ss->master)));
1776 
1777  for (int i = 0; i < GENERATE_AT_ONCE; i++)
1778  kce_generate (ss, ++ss->sequence_allowed);
1779 
1780  if (KCN_TARGET > ss->sender->acks_available)
1781  {
1785  ss);
1786  }
1787  else
1788  {
1790  "We have enough keys.\n");
1791  ss_finished = ss;
1793  }
1794  }
1795 
1796 
1797 
1798 }
1799 
1800 
1801 static void
1803 {
1804  struct SharedSecret *ss = cls;
1805 
1806  ss->sender->kce_task_rekey = NULL;
1807 
1808  if (NULL == ss->sender->kce_task)
1809  {
1810 
1812  "Precomputing keys for rekey master %s\n",
1813  GNUNET_h2s (&(ss->master)));
1814 
1815  for (int i = 0; i < GENERATE_AT_ONCE; i++)
1816  kce_generate (ss, ++ss->sequence_allowed);
1817 
1821  ss);
1822  ss->sender->kce_task_rekey = NULL;
1823  }
1824  else
1825  {
1829  ss);
1830  }
1831 }
1832 
1833 
1843 static void
1844 consider_ss_ack (struct SharedSecret *ss, int initial)
1845 {
1846  struct GNUNET_SCHEDULER_Task *kce_task_rekey;
1847  struct GNUNET_SCHEDULER_Task *kce_task;
1848  int kce_task_finished;
1849 
1850  kce_task_rekey = ss->sender->kce_task_rekey;
1851  kce_task_finished = ss->sender->kce_task_finished;
1852  kce_task = ss->sender->kce_task;
1853 
1854  GNUNET_assert (NULL != ss->sender);
1856  "Considering SS UDPAck %s\n",
1857  GNUNET_i2s_full (&ss->sender->target));
1858 
1860  "We have %u acks available.\n",
1861  ss->sender->acks_available);
1862  /* drop ancient KeyCacheEntries */
1863  while ((NULL != ss->kce_head) &&
1864  (MAX_SQN_DELTA <
1866  kce_destroy (ss->kce_tail);
1867 
1868 
1869  if (GNUNET_NO == initial)
1870  kce_generate (ss, ++ss->sequence_allowed);
1871 
1872  /*if (0 == ss->sender->acks_available)
1873  {
1874  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1875  "Generating keys\n");
1876  while (ss->active_kce_count < KCN_TARGET)
1877  kce_generate (ss, ++ss->sequence_allowed);
1878  }*/
1879 
1880  if (NULL != kce_task)
1882  "kce_task is not NULL\n");
1883  if (kce_task_finished)
1885  "kce_task_finished: GNUNET_YES\n");
1886  if (initial)
1888  "initial: GNUNET_YES\n");
1889 
1890  if ( kce_task_finished || (GNUNET_NO == initial))
1891  {
1892  struct UDPAck ack;
1893  struct SharedSecret *ss_tell;
1894 
1895  if (GNUNET_NO != initial)
1896  ss_tell = ss_finished;
1897  else
1898  ss_tell = ss;
1899 
1901  ack.header.size = htons (sizeof(ack));
1902  ack.sequence_max = htonl (ss_tell->sequence_allowed);
1904  ack.cmac = ss_tell->cmac;
1906  "Notifying transport of UDPAck %s with initial %u and master %s\n",
1907  GNUNET_i2s_full (&ss_tell->sender->target),
1908  initial,
1909  GNUNET_h2s (&(ss_tell->master)));
1911  &ss_tell->sender->target,
1913  &ack.header);
1914  if (GNUNET_NO != initial)
1915  {
1918  }
1919  }
1920  else if ((NULL == kce_task) && ((KCN_THRESHOLD >
1921  ss->sender->acks_available) ||
1922  (GNUNET_YES == ss->sender->rekeying) ||
1923  (ss->sender->num_secrets > MAX_SECRETS) ))
1924  {
1925 
1926  // kce_generate (ss, ++ss->sequence_allowed);
1927  // kce_generate (ss, ++ss->sequence_allowed);
1928  // TODO This task must be per sender!
1931  ss);
1932  kce_task_finished = GNUNET_NO;
1933 
1934  }
1935  else if ((NULL == kce_task_rekey) && (GNUNET_YES ==
1936  ss->sender->rekeying) )
1937  {
1940  ss);
1941  }
1942 }
1943 
1944 
1952 static void
1953 decrypt_box (const struct UDPBox *box,
1954  size_t box_len,
1955  struct KeyCacheEntry *kce)
1956 {
1957  struct SharedSecret *ss = kce->ss;
1958  char out_buf[box_len - sizeof(*box)];
1959 
1960  GNUNET_assert (NULL != ss->sender);
1961  if (GNUNET_OK != try_decrypt (ss,
1962  box->gcm_tag,
1963  kce->sequence_number,
1964  (const char *) &box[1],
1965  sizeof(out_buf),
1966  out_buf))
1967  {
1969  "# Decryption failures with valid KCE",
1970  1,
1971  GNUNET_NO);
1972  kce_destroy (kce);
1973  return;
1974  }
1975  kce_destroy (kce);
1977  "# bytes decrypted with BOX",
1978  sizeof(out_buf),
1979  GNUNET_NO);
1981  "# messages decrypted with BOX",
1982  1,
1983  GNUNET_NO);
1985  "decrypted UDPBox with kid %s\n",
1986  GNUNET_sh2s (&box->kid));
1987  try_handle_plaintext (ss->sender, out_buf, sizeof(out_buf));
1988  if ((GNUNET_NO == box->rekeying) && (GNUNET_YES == ss->sender->rekeying))
1989  {
1990  ss->sender->rekeying = GNUNET_NO;
1991  ss->sender->ss_rekey = NULL;
1992  // destroy_all_secrets (ss, GNUNET_NO);
1994  "Receiver stopped rekeying.\n");
1995  }
1996  else if (GNUNET_NO == box->rekeying)
1997  consider_ss_ack (ss, GNUNET_NO);
1998  else
1999  {
2000  ss->sender->rekeying = GNUNET_YES;
2002  "Got Box: Receiver doing rekeying.\n");
2003  }
2004 }
2005 
2006 
2014 static void
2015 decrypt_rekey (const struct UDPRekey *rekey,
2016  size_t rekey_len,
2017  struct KeyCacheEntry *kce,
2018  struct SenderAddress *sender)
2019 {
2020  struct SharedSecret *ss = kce->ss;
2021  struct SharedSecret *ss_rekey;
2022  char out_buf[rekey_len - sizeof(*rekey)];
2023  struct GNUNET_HashCode *master;
2024 
2025 
2027  "decrypt_rekey.\n");
2028 
2029  GNUNET_assert (NULL != ss->sender);
2030  if (GNUNET_OK != try_decrypt (ss,
2031  rekey->gcm_tag,
2032  kce->sequence_number,
2033  (const char *) &rekey[1],
2034  sizeof(out_buf),
2035  out_buf))
2036  {
2038  "# Decryption failures with valid KCE",
2039  1,
2040  GNUNET_NO);
2042  "Decryption with kid %s failed\n",
2043  GNUNET_sh2s (&rekey->kid));
2044  kce_destroy (kce);
2045  return;
2046  }
2047  kce_destroy (kce);
2049  "# bytes decrypted with Rekey",
2050  sizeof(out_buf),
2051  GNUNET_NO);
2053  "decrypted UDPRekey with kid %s\n",
2054  GNUNET_sh2s (&rekey->kid));
2055  /*cmac = (struct GNUNET_HashCode *) out_buf;
2056  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2057  "Received secret with cmac %s \n",
2058  GNUNET_h2s (&cmac));*/
2059  // ss_rekey = (struct SharedSecret *) out_buf;
2060  master = (struct GNUNET_HashCode *) out_buf;
2061  ss_rekey = GNUNET_new (struct SharedSecret);
2062  ss_rekey->master = *master;
2063  calculate_cmac (ss_rekey);
2064  ss_rekey->sender = sender;
2065  // ss_rekey->sequence_used = 0;
2066  // ss_rekey->sequence_allowed = 0;
2067  /* ss_rekey->active_kce_count = 0; */
2068  /* ss_rekey->prev = NULL; */
2069  /* ss_rekey->next = NULL; */
2070  /* GNUNET_assert (ss_rekey->prev == NULL && sender->ss_head != ss_rekey); */
2071  /* GNUNET_assert (ss_rekey->next == NULL && sender->ss_tail != ss_rekey); */
2072  GNUNET_CONTAINER_DLL_insert (sender->ss_head, sender->ss_tail, ss_rekey);
2073  sender->ss_rekey = ss_rekey;
2074  sender->num_secrets++;
2076  "Received secret with cmac %s\n",
2077  GNUNET_h2s (&(ss_rekey->cmac)));
2079  "Received secret with master %s.\n",
2080  GNUNET_h2s (&(ss_rekey->master)));
2082  "We have %u sequence_allowed.\n",
2083  ss_rekey->sequence_allowed);
2085  "We have a sender %p\n",
2086  ss_rekey->sender);
2088  "We have %u acks available.\n",
2089  ss_rekey->sender->acks_available);
2090  consider_ss_ack (ss_rekey, GNUNET_YES);
2091 
2092 }
2093 
2094 
2098 struct SearchContext
2099 {
2103  const struct sockaddr *address;
2104 
2108  socklen_t address_len;
2109 
2114 };
2115 
2116 
2125 static int
2127  const struct GNUNET_PeerIdentity *key,
2128  void *value)
2129 {
2130  struct SearchContext *sc = cls;
2131  struct SenderAddress *sender = value;
2132 
2133  if ((sender->address_len == sc->address_len) &&
2134  (0 == memcmp (sender->address, sc->address, sender->address_len)))
2135  {
2136  sc->sender = sender;
2137  return GNUNET_NO; /* stop iterating! */
2138  }
2139  return GNUNET_YES;
2140 }
2141 
2142 
2154 static struct SenderAddress *
2156  const struct sockaddr *address,
2157  socklen_t address_len)
2158 {
2159  struct SenderAddress *sender;
2160  struct SearchContext sc = { .address = address,
2161  .address_len = address_len,
2162  .sender = NULL };
2163 
2165  target,
2167  &sc);
2168  if (NULL != sc.sender)
2169  {
2170  reschedule_sender_timeout (sc.sender);
2171  return sc.sender;
2172  }
2173  sender = GNUNET_new (struct SenderAddress);
2174  sender->target = *target;
2178  senders,
2179  &sender->target,
2180  sender,
2183  "# senders active",
2185  GNUNET_NO);
2186  sender->timeout =
2189  sender,
2192  if (NULL == timeout_task)
2194  return sender;
2195 }
2196 
2197 
2205 static int
2207  const struct UDPConfirmation *uc)
2208 {
2209  struct UdpHandshakeSignature uhs;
2210 
2211  uhs.purpose.purpose = htonl (
2213  uhs.purpose.size = htonl (sizeof(uhs));
2214  uhs.sender = uc->sender;
2215  uhs.receiver = my_identity;
2216  uhs.ephemeral = *ephemeral;
2217  uhs.monotonic_time = uc->monotonic_time;
2220  &uhs,
2221  &uc->sender_sig,
2222  &uc->sender.public_key);
2223 }
2224 
2225 
2234 static char *
2235 sockaddr_to_udpaddr_string (const struct sockaddr *address,
2236  socklen_t address_len)
2237 {
2238  char *ret;
2239 
2240  switch (address->sa_family)
2241  {
2242  case AF_INET:
2243  GNUNET_asprintf (&ret,
2244  "%s-%s",
2246  GNUNET_a2s (address, address_len));
2247  break;
2248 
2249  case AF_INET6:
2250  GNUNET_asprintf (&ret,
2251  "%s-%s",
2253  GNUNET_a2s (address, address_len));
2254  break;
2255 
2256  default:
2257  GNUNET_assert (0);
2258  }
2259  return ret;
2260 }
2261 
2262 
2268 static void
2269 sock_read (void *cls)
2270 {
2271  struct sockaddr_storage sa;
2272  struct sockaddr_in *addr_verify;
2273  socklen_t salen = sizeof(sa);
2274  char buf[UINT16_MAX];
2275  ssize_t rcvd;
2276 
2277  (void) cls;
2279  udp_sock,
2280  &sock_read,
2281  NULL);
2283  buf,
2284  sizeof(buf),
2285  (struct sockaddr *) &sa,
2286  &salen);
2287  if (-1 == rcvd)
2288  {
2290  return;
2291  }
2293  "Read %lu bytes\n", rcvd);
2294 
2295  if (rcvd > sizeof(struct UDPRekey))
2296  {
2297  const struct UDPRekey *rekey;
2298  const struct UDPBox *box;
2299  struct KeyCacheEntry *kce;
2300  struct SenderAddress *sender;
2301  int do_decrypt = GNUNET_NO;
2302 
2303  rekey = (const struct UDPRekey *) buf;
2304  box = (const struct UDPBox *) buf;
2306 
2307  if ((GNUNET_YES == box->rekeying) || (GNUNET_NO == box->rekeying))
2309  "UDPRekey has rekeying %u\n",
2310  box->rekeying);
2311  else
2313 
2314  if ((GNUNET_YES == do_decrypt) && (NULL != kce) && (GNUNET_YES ==
2315  kce->ss->sender->
2316  rekeying))
2317  {
2319  "UDPRekey with kid %s\n",
2320  GNUNET_sh2s (&rekey->kid));
2321  sender = setup_sender (&rekey->sender, (const struct sockaddr *) &sa,
2322  salen);
2323 
2324  if (NULL != sender->ss_rekey)
2325  return;
2326 
2327  decrypt_rekey (rekey, (size_t) rcvd, kce, sender);
2328  return;
2329  }
2330  }
2331 
2332  /* first, see if it is a UDPBox */
2333  if (rcvd > sizeof(struct UDPBox))
2334  {
2335  const struct UDPBox *box;
2336  struct KeyCacheEntry *kce;
2337 
2338  box = (const struct UDPBox *) buf;
2340  if (NULL != kce)
2341  {
2342  decrypt_box (box, (size_t) rcvd, kce);
2343  return;
2344  }
2345  }
2346 
2347  /* next, check if it is a broadcast */
2348  if (sizeof(struct UDPBroadcast) == rcvd)
2349  {
2350  const struct UDPBroadcast *ub;
2351  struct UdpBroadcastSignature uhs;
2352  struct GNUNET_PeerIdentity sender;
2353 
2354  addr_verify = GNUNET_memdup (&sa, salen);
2355  addr_verify->sin_port = 0;
2357  "received UDPBroadcast from %s\n",
2358  GNUNET_a2s ((const struct sockaddr *) addr_verify, salen));
2359  ub = (const struct UDPBroadcast *) buf;
2360  uhs.purpose.purpose = htonl (
2362  uhs.purpose.size = htonl (sizeof(uhs));
2363  uhs.sender = ub->sender;
2364  sender = ub->sender;
2365  if (0 == memcmp (&sender, &my_identity, sizeof (struct
2367  {
2369  "Received our own broadcast\n");
2370  GNUNET_free (addr_verify);
2371  return;
2372  }
2374  "checking UDPBroadcastSignature for %s\n",
2375  GNUNET_i2s (&sender));
2376  GNUNET_CRYPTO_hash ((struct sockaddr *) addr_verify, salen, &uhs.h_address);
2377  if (GNUNET_OK ==
2380  &uhs,
2381  &ub->sender_sig,
2382  &ub->sender.public_key))
2383  {
2384  char *addr_s;
2385  enum GNUNET_NetworkType nt;
2386 
2387  addr_s =
2388  sockaddr_to_udpaddr_string ((const struct sockaddr *) &sa, salen);
2389  GNUNET_STATISTICS_update (stats, "# broadcasts received", 1, GNUNET_NO);
2390  /* use our own mechanism to determine network type */
2391  nt =
2392  GNUNET_NT_scanner_get_type (is, (const struct sockaddr *) &sa, salen);
2394  "validating address %s received from UDPBroadcast\n",
2395  GNUNET_i2s (&sender));
2397  GNUNET_free (addr_s);
2398  GNUNET_free (addr_verify);
2399  return;
2400  }
2401  else
2402  {
2404  "VerifyingPeer %s is verifying UDPBroadcast\n",
2405  GNUNET_i2s (&my_identity));
2407  "Verifying UDPBroadcast from %s failed\n",
2408  GNUNET_i2s (&ub->sender));
2409  }
2410  GNUNET_free (addr_verify);
2411  /* continue with KX, mostly for statistics... */
2412  }
2413 
2414 
2415  /* finally, test if it is a KX */
2416  if (rcvd < sizeof(struct UDPConfirmation) + sizeof(struct InitialKX))
2417  {
2419  "# messages dropped (no kid, too small for KX)",
2420  1,
2421  GNUNET_NO);
2422  return;
2423  }
2425  "Got KX\n");
2426  {
2427  const struct InitialKX *kx;
2428  struct SharedSecret *ss;
2429  char pbuf[rcvd - sizeof(struct InitialKX)];
2430  const struct UDPConfirmation *uc;
2431  struct SenderAddress *sender;
2432 
2433  kx = (const struct InitialKX *) buf;
2434  ss = setup_shared_secret_dec (&kx->ephemeral);
2436  "Before DEC\n");
2437 
2438  if (GNUNET_OK != try_decrypt (ss,
2439  kx->gcm_tag,
2440  0,
2441  &buf[sizeof(*kx)],
2442  sizeof(pbuf),
2443  pbuf))
2444  {
2446  "Unable to decrypt tag, dropping...\n");
2447  GNUNET_free (ss);
2449  stats,
2450  "# messages dropped (no kid, AEAD decryption failed)",
2451  1,
2452  GNUNET_NO);
2453  return;
2454  }
2456  "Before VERIFY\n");
2457 
2458  uc = (const struct UDPConfirmation *) pbuf;
2459  if (GNUNET_OK != verify_confirmation (&kx->ephemeral, uc))
2460  {
2461  GNUNET_break_op (0);
2462  GNUNET_free (ss);
2464  "# messages dropped (sender signature invalid)",
2465  1,
2466  GNUNET_NO);
2467  return;
2468  }
2470  "Before SETUP_SENDER\n");
2471 
2472  calculate_cmac (ss);
2473  sender = setup_sender (&uc->sender, (const struct sockaddr *) &sa, salen);
2474  ss->sender = sender;
2475  GNUNET_CONTAINER_DLL_insert (sender->ss_head, sender->ss_tail, ss);
2476  sender->num_secrets++;
2477  GNUNET_STATISTICS_update (stats, "# Secrets active", 1, GNUNET_NO);
2479  "# messages decrypted without BOX",
2480  1,
2481  GNUNET_NO);
2482  try_handle_plaintext (sender, &uc[1], sizeof(pbuf) - sizeof(*uc));
2483  if ((GNUNET_NO == kx->rekeying) && (GNUNET_YES == ss->sender->rekeying))
2484  {
2485  ss->sender->rekeying = GNUNET_NO;
2486  sender->ss_rekey = NULL;
2487  // destroy_all_secrets (ss, GNUNET_NO);
2489  "Receiver stopped rekeying.\n");
2490  }
2491  else if (GNUNET_NO == kx->rekeying)
2493  else
2494  {
2495  ss->sender->rekeying = GNUNET_YES;
2497  "Got KX: Receiver doing rekeying.\n");
2498  }
2499  /*if (sender->num_secrets > MAX_SECRETS)
2500  secret_destroy (sender->ss_tail);*/
2501  }
2502 }
2503 
2504 
2512 static struct sockaddr *
2513 udp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
2514 {
2515  struct sockaddr *in;
2516  unsigned int port;
2517  char dummy[2];
2518  char *colon;
2519  char *cp;
2520 
2521  if (1 == sscanf (bindto, "%u%1s", &port, dummy))
2522  {
2523  /* interpreting value as just a PORT number */
2524  if (port > UINT16_MAX)
2525  {
2527  "BINDTO specification `%s' invalid: value too large for port\n",
2528  bindto);
2529  return NULL;
2530  }
2531  if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
2532  (GNUNET_YES ==
2535  "DISABLE_V6")))
2536  {
2537  struct sockaddr_in *i4;
2538 
2539  i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
2540  i4->sin_family = AF_INET;
2541  i4->sin_port = htons ((uint16_t) port);
2542  *sock_len = sizeof(struct sockaddr_in);
2543  in = (struct sockaddr *) i4;
2544  }
2545  else
2546  {
2547  struct sockaddr_in6 *i6;
2548 
2549  i6 = GNUNET_malloc (sizeof(struct sockaddr_in6));
2550  i6->sin6_family = AF_INET6;
2551  i6->sin6_port = htons ((uint16_t) port);
2552  *sock_len = sizeof(struct sockaddr_in6);
2553  in = (struct sockaddr *) i6;
2554  }
2555  return in;
2556  }
2557  cp = GNUNET_strdup (bindto);
2558  colon = strrchr (cp, ':');
2559  if (NULL != colon)
2560  {
2561  /* interpret value after colon as port */
2562  *colon = '\0';
2563  colon++;
2564  if (1 == sscanf (colon, "%u%1s", &port, dummy))
2565  {
2566  /* interpreting value as just a PORT number */
2567  if (port > UINT16_MAX)
2568  {
2570  "BINDTO specification `%s' invalid: value too large for port\n",
2571  bindto);
2572  GNUNET_free (cp);
2573  return NULL;
2574  }
2575  }
2576  else
2577  {
2578  GNUNET_log (
2580  "BINDTO specification `%s' invalid: last ':' not followed by number\n",
2581  bindto);
2582  GNUNET_free (cp);
2583  return NULL;
2584  }
2585  }
2586  else
2587  {
2588  /* interpret missing port as 0, aka pick any free one */
2589  port = 0;
2590  }
2591  {
2592  /* try IPv4 */
2593  struct sockaddr_in v4;
2594 
2595  memset (&v4, 0, sizeof(v4));
2596  if (1 == inet_pton (AF_INET, cp, &v4.sin_addr))
2597  {
2598  v4.sin_family = AF_INET;
2599  v4.sin_port = htons ((uint16_t) port);
2600 #if HAVE_SOCKADDR_IN_SIN_LEN
2601  v4.sin_len = sizeof(struct sockaddr_in);
2602 #endif
2603  in = GNUNET_memdup (&v4, sizeof(struct sockaddr_in));
2604  *sock_len = sizeof(struct sockaddr_in);
2605  GNUNET_free (cp);
2606  return in;
2607  }
2608  }
2609  {
2610  /* try IPv6 */
2611  struct sockaddr_in6 v6;
2612  const char *start;
2613 
2614  memset (&v6, 0, sizeof(v6));
2615  start = cp;
2616  if (('[' == *cp) && (']' == cp[strlen (cp) - 1]))
2617  {
2618  start++; /* skip over '[' */
2619  cp[strlen (cp) - 1] = '\0'; /* eat ']' */
2620  }
2621  if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
2622  {
2623  v6.sin6_family = AF_INET6;
2624  v6.sin6_port = htons ((uint16_t) port);
2625 #if HAVE_SOCKADDR_IN_SIN_LEN
2626  v6.sin6_len = sizeof(sizeof(struct sockaddr_in6));
2627 #endif
2628  in = GNUNET_memdup (&v6, sizeof(v6));
2629  *sock_len = sizeof(v6);
2630  GNUNET_free (cp);
2631  return in;
2632  }
2633  }
2634  /* #5528 FIXME (feature!): maybe also try getnameinfo()? */
2635  GNUNET_free (cp);
2636  return NULL;
2637 }
2638 
2639 
2647 static void
2648 do_pad (gcry_cipher_hd_t out_cipher, char *dgram, size_t pad_size)
2649 {
2650  char pad[pad_size];
2651 
2653  if (sizeof(pad) > sizeof(struct GNUNET_MessageHeader))
2654  {
2655  struct GNUNET_MessageHeader hdr =
2656  { .size = htons (sizeof(pad)),
2657  .type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD) };
2658 
2659  memcpy (pad, &hdr, sizeof(hdr));
2660  }
2661  GNUNET_assert (
2662  0 ==
2663  gcry_cipher_encrypt (out_cipher, dgram, sizeof(pad), pad, sizeof(pad)));
2664 }
2665 
2666 
2675 static void
2677  const struct GNUNET_MessageHeader *msg,
2678  void *impl_state)
2679 {
2680  struct ReceiverAddress *receiver = impl_state;
2681  uint16_t msize = ntohs (msg->size);
2682  struct UdpHandshakeSignature uhs;
2683  struct UDPConfirmation uc;
2684  struct InitialKX kx;
2685  struct GNUNET_CRYPTO_EcdhePrivateKey epriv;
2686  char dgram[receiver->kx_mtu + sizeof(uc) + sizeof(kx)];
2687  size_t dpos;
2688  gcry_cipher_hd_t out_cipher;
2689  struct SharedSecret *ss;
2690 
2691  GNUNET_assert (mq == receiver->kx_mq);
2692  if (msize > receiver->kx_mtu)
2693  {
2694  GNUNET_break (0);
2695  if (GNUNET_YES != receiver->receiver_destroy_called)
2697  return;
2698  }
2700 
2701  /* setup key material */
2703 
2705 
2706  if (receiver->num_secrets > MAX_SECRETS)
2707  {
2709  }
2710 
2711  setup_cipher (&ss->master, 0, &out_cipher);
2712  /* compute 'uc' */
2713  uc.sender = my_identity;
2714  uc.monotonic_time =
2716  uhs.purpose.purpose = htonl (
2718  uhs.purpose.size = htonl (sizeof(uhs));
2719  uhs.sender = my_identity;
2720  uhs.receiver = receiver->target;
2722  uhs.monotonic_time = uc.monotonic_time;
2724  &uhs,
2725  &uc.sender_sig);
2726  /* Leave space for kx */
2727  dpos = sizeof(kx);
2728  /* Append encrypted uc to dgram */
2729  GNUNET_assert (0 == gcry_cipher_encrypt (out_cipher,
2730  &dgram[dpos],
2731  sizeof(uc),
2732  &uc,
2733  sizeof(uc)));
2734  dpos += sizeof(uc);
2735  /* Append encrypted payload to dgram */
2736  GNUNET_assert (
2737  0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize));
2738  dpos += msize;
2739  do_pad (out_cipher, &dgram[dpos], sizeof(dgram) - dpos);
2740  /* Datagram starts with kx */
2741  kx.ephemeral = uhs.ephemeral;
2742  GNUNET_assert (
2743  0 == gcry_cipher_gettag (out_cipher, kx.gcm_tag, sizeof(kx.gcm_tag)));
2744  gcry_cipher_close (out_cipher);
2745  if (GNUNET_NO == receiver->rekeying)
2746  kx.rekeying = GNUNET_NO;
2747  else
2748  kx.rekeying = GNUNET_YES;
2749  memcpy (dgram, &kx, sizeof(kx));
2751  dgram,
2752  sizeof(dgram),
2753  receiver->address,
2754  receiver->address_len))
2757  "Sending KX with payload size %u to %s\n",
2758  msize,
2759  GNUNET_a2s (receiver->address,
2760  receiver->address_len));
2762 }
2763 
2764 
2765 static void
2767 {
2768 
2769  struct GNUNET_TIME_Relative rt;
2770 
2772  "Timeout is %llu\n.",
2773  (unsigned long long) receiver->rekey_timeout.abs_value_us);
2774 
2775  if (0 == receiver->rekey_timeout.abs_value_us)
2776  {
2777  receiver->rekey_timeout = GNUNET_TIME_relative_to_absolute (
2778  rekey_interval);
2779  }
2780  else
2781  {
2782  rt = GNUNET_TIME_absolute_get_remaining (receiver->rekey_timeout);
2784  "Relative time is %llu and timeout is %llu\n.",
2785  (unsigned long long) rt.rel_value_us,
2786  (unsigned long long) receiver->rekey_timeout.abs_value_us);
2787 
2788  if ((0 == rt.rel_value_us) || (receiver->rekey_send_bytes >
2789  rekey_max_bytes) )
2790  {
2792  "Bytes send %llu greater than %llu max bytes\n.",
2793  (unsigned long long) receiver->rekey_send_bytes,
2794  rekey_max_bytes);
2796  "Relative time is %llu and timeout is %llu\n.",
2797  (unsigned long long) rt.rel_value_us,
2798  (unsigned long long) receiver->rekey_timeout.abs_value_us);
2799 
2800  receiver->rekey_timeout.abs_value_us = 0;
2801  receiver->rekey_send_bytes = 0;
2802  receiver->ss_rekey = NULL;
2803  // destroy_all_secrets (ss, GNUNET_NO);
2804  receiver->rekeying = GNUNET_YES;
2805  receiver->rekey_acks_available = receiver->acks_available;
2806  box->rekeying = GNUNET_YES;
2808  "Sender started rekeying.\n");
2809  if (GNUNET_YES == box->rekeying)
2811  "Sending rekeying with kid %s\n",
2812  GNUNET_sh2s (&box->kid));
2813  }
2814  }
2815 }
2816 
2817 
2818 static void
2820 {
2821  uint8_t is_ss_rekey_sequence_allowed_zero = GNUNET_NO;
2822  uint8_t is_acks_available_below = GNUNET_NO;
2823  uint8_t send_rekey = GNUNET_NO;
2824  uint16_t not_below;
2825  struct GNUNET_CRYPTO_EcdhePrivateKey epriv;
2826  struct UDPRekey *rekey;
2827  size_t dpos;
2828 
2829  char rekey_dgram[sizeof(struct UDPRekey) + receiver->d_mtu];
2830 
2831  if (NULL != receiver->ss_rekey)
2832  {
2833  not_below = (receiver->rekey_acks_available
2834  - (receiver->rekey_acks_available % 3)) / 3;
2835  is_ss_rekey_sequence_allowed_zero = (0 ==
2836  receiver->ss_rekey->sequence_allowed);
2837  is_acks_available_below = (receiver->acks_available >= not_below);
2838  send_rekey = (0 == (receiver->acks_available - not_below) % not_below) &&
2839  is_acks_available_below && is_ss_rekey_sequence_allowed_zero;
2841  "send_rekey: %u, %u, %u\n",
2842  send_rekey,
2843  receiver->rekey_acks_available,
2844  receiver->acks_available);
2845  }
2846  else if (NULL == receiver->ss_rekey)
2847  {
2848  /* setup key material */
2850  receiver->ss_rekey = setup_shared_secret_enc (&epriv, receiver,
2851  GNUNET_NO);
2852  receiver->ss_rekey->sequence_allowed = 0;
2854  "Setup secret with cmac %s\n",
2855  GNUNET_h2s (&(receiver->ss_rekey->cmac)));
2857  "Setup secret with master %s.\n",
2858  GNUNET_h2s (&(receiver->ss_rekey->master)));
2859  }
2860 
2861  if (send_rekey)
2862  {
2863  GNUNET_assert (0 != receiver->number_rekeying_kce);
2864  gcry_cipher_hd_t rekey_out_cipher;
2865 
2866  while (NULL != ss && ss->sequence_used >= ss->sequence_allowed)
2867  {
2868  ss = ss->prev;
2869  }
2870 
2871  if (NULL != ss)
2872  {
2873  rekey = (struct UDPRekey *) rekey_dgram;
2874  rekey->sender = my_identity;
2875  ss->sequence_used++;
2876  get_kid (&ss->master, ss->sequence_used, &rekey->kid);
2877  receiver->number_rekeying_kce--;
2878  setup_cipher (&ss->master, ss->sequence_used, &rekey_out_cipher);
2879  /* Append encrypted payload to dgram */
2880  dpos = sizeof(struct UDPRekey);
2881 
2882  GNUNET_assert (
2883  0 == gcry_cipher_encrypt (rekey_out_cipher, &rekey_dgram[dpos],
2884  sizeof(receiver->ss_rekey->master),
2885  &(receiver->ss_rekey->master),
2886  sizeof(receiver->ss_rekey->master)));
2887  dpos += sizeof(receiver->ss_rekey->master);
2888  /* GNUNET_assert ( */
2889  /* 0 == gcry_cipher_encrypt (rekey_out_cipher, &rekey_dgram[dpos], */
2890  /* /\*sizeof(receiver->ss_rekey->cmac), */
2891  /* &(receiver->ss_rekey->cmac), */
2892  /* sizeof(receiver->ss_rekey->cmac))); */
2893  /* dpos += sizeof(receiver->ss_rekey->cmac);*\/ */
2894  /* sizeof(receiver->ss_rekey), */
2895  /* receiver->ss_rekey, */
2896  /* sizeof(receiver->ss_rekey))); */
2897  /* dpos += sizeof(receiver->ss_rekey); */
2898  do_pad (rekey_out_cipher, &rekey_dgram[dpos], sizeof(rekey_dgram)
2899  - dpos);
2900  GNUNET_assert (0 == gcry_cipher_gettag (rekey_out_cipher,
2901  rekey->gcm_tag,
2902  sizeof(rekey->gcm_tag)));
2903  gcry_cipher_close (rekey_out_cipher);
2904 
2906  "Sending rekey with kid %s and master %s\n",
2907  GNUNET_sh2s (&rekey->kid),
2908  GNUNET_h2s (&(receiver->ss_rekey->master)));
2910  "Sending rekey with cmac %s\n",
2911  GNUNET_h2s (&(receiver->ss_rekey->cmac)));
2913  "%u rekey kces left.\n",
2914  receiver->number_rekeying_kce);
2915 
2917  rekey_dgram,
2918  sizeof(rekey_dgram),
2919  receiver->address,
2920  receiver->address_len))
2922 
2923  receiver->acks_available--;
2925  "%u receiver->acks_available 1\n",
2926  receiver->acks_available);
2928  "Sending UDPRekey to %s\n", GNUNET_a2s (receiver->address,
2929  receiver->
2930  address_len));
2931  }
2932  }
2933 }
2934 
2935 
2944 static void
2946  const struct GNUNET_MessageHeader *msg,
2947  void *impl_state)
2948 {
2949  struct ReceiverAddress *receiver = impl_state;
2950  uint16_t msize = ntohs (msg->size);
2951 
2952  GNUNET_assert (mq == receiver->d_mq);
2953  if ((msize > receiver->d_mtu) ||
2954  (0 == receiver->acks_available))
2955  {
2957  "msize: %u, mtu: %lu, acks: %u\n",
2958  msize,
2959  receiver->d_mtu,
2960  receiver->acks_available);
2961 
2962  GNUNET_break (0);
2963  if (GNUNET_YES != receiver->receiver_destroy_called)
2965  return;
2966  }
2968 
2969  /* begin "BOX" encryption method, scan for ACKs from tail! */
2970  for (struct SharedSecret *ss = receiver->ss_tail; NULL != ss; ss = ss->prev)
2971  {
2972  if (0 < ss->sequence_used)
2974  "Trying to send UDPBox with shared secrect %s sequence_used %u and ss->sequence_allowed %u\n",
2975  GNUNET_h2s (&ss->master),
2976  ss->sequence_used,
2977  ss->sequence_allowed);
2978  // Uncomment this for alternativ 1 of backchannel functionality
2979  if (ss->sequence_used >= ss->sequence_allowed)
2980  // Until here for alternativ 1
2981  // Uncomment this for alternativ 2 of backchannel functionality
2982  // if (0 == ss->sequence_allowed)
2983  // Until here for alternativ 2
2984  {
2985  continue;
2986  }
2987  char dgram[sizeof(struct UDPBox) + receiver->d_mtu];
2988  struct UDPBox *box;
2989  gcry_cipher_hd_t out_cipher;
2990  size_t dpos;
2991 
2992  box = (struct UDPBox *) dgram;
2993  ss->sequence_used++;
2994  get_kid (&ss->master, ss->sequence_used, &box->kid);
2995  setup_cipher (&ss->master, ss->sequence_used, &out_cipher);
2996  /* Append encrypted payload to dgram */
2997  dpos = sizeof(struct UDPBox);
2998  GNUNET_assert (
2999  0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize));
3000  dpos += msize;
3001  do_pad (out_cipher, &dgram[dpos], sizeof(dgram) - dpos);
3002  GNUNET_assert (0 == gcry_cipher_gettag (out_cipher,
3003  box->gcm_tag,
3004  sizeof(box->gcm_tag)));
3005  gcry_cipher_close (out_cipher);
3006 
3007  receiver->rekey_send_bytes += sizeof(struct UDPBox) + receiver->d_mtu;
3008 
3009  if (GNUNET_NO == receiver->rekeying)
3010  box->rekeying = GNUNET_NO;
3011  else
3012  box->rekeying = GNUNET_YES;
3013 
3015  dgram,
3016  sizeof(dgram),
3017  receiver->address,
3018  receiver->address_len))
3021  "Sending UDPBox with payload size %u, %u acks left\n",
3022  msize,
3023  receiver->acks_available);
3025  receiver->acks_available--;
3027  "%u receiver->acks_available 2\n",
3028  receiver->acks_available);
3030  if (0 == receiver->acks_available - receiver->number_rekeying_kce)
3031  {
3032  /* We have no more ACKs */
3034  "No more acks\n");
3035  if (GNUNET_YES == receiver->rekeying)
3036  {
3037  receiver->rekeying = GNUNET_NO;
3039  "Sender stopped rekeying\n");
3040 
3041  if ((NULL != receiver->ss_rekey) && (0 <
3042  receiver->ss_rekey->
3043  sequence_allowed) )
3045  }
3046  }
3047  else if ((GNUNET_YES == receiver->rekeying) )
3048  {
3049  send_UDPRekey (receiver, ss);
3050  }
3051 
3052  return;
3053  }
3054 }
3055 
3056 
3065 static void
3066 mq_destroy_d (struct GNUNET_MQ_Handle *mq, void *impl_state)
3067 {
3068  struct ReceiverAddress *receiver = impl_state;
3070  "Default MQ destroyed\n");
3071  if (mq == receiver->d_mq)
3072  {
3073  receiver->d_mq = NULL;
3074  if (GNUNET_YES != receiver->receiver_destroy_called)
3076  }
3077 }
3078 
3079 
3088 static void
3089 mq_destroy_kx (struct GNUNET_MQ_Handle *mq, void *impl_state)
3090 {
3091  struct ReceiverAddress *receiver = impl_state;
3093  "KX MQ destroyed\n");
3094  if (mq == receiver->kx_mq)
3095  {
3096  receiver->kx_mq = NULL;
3097  if (GNUNET_YES != receiver->receiver_destroy_called)
3099  }
3100 }
3101 
3102 
3109 static void
3110 mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
3111 {
3112  /* Cancellation is impossible with UDP; bail */
3113  GNUNET_assert (0);
3114 }
3115 
3116 
3126 static void
3127 mq_error (void *cls, enum GNUNET_MQ_Error error)
3128 {
3129  struct ReceiverAddress *receiver = cls;
3130 
3132  "MQ error in queue to %s: %d\n",
3133  GNUNET_i2s (&receiver->target),
3134  (int) error);
3136 }
3137 
3138 
3146 static void
3148 {
3149  size_t base_mtu;
3150 
3151  /*if (NULL != receiver->kx_qh)
3152  {
3153  GNUNET_TRANSPORT_communicator_mq_del (receiver->kx_qh);
3154  receiver->kx_qh = NULL;
3155  }
3156  if (NULL != receiver->d_qh)
3157  {
3158  GNUNET_TRANSPORT_communicator_mq_del (receiver->d_qh);
3159  receiver->d_qh = NULL;
3160  }*/
3161  // GNUNET_assert (NULL == receiver->mq);
3162  switch (receiver->address->sa_family)
3163  {
3164  case AF_INET:
3165  base_mtu = 1480 /* Ethernet MTU, 1500 - Ethernet header - VLAN tag */
3166  - sizeof(struct GNUNET_TUN_IPv4Header) /* 20 */
3167  - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */;
3168  break;
3169 
3170  case AF_INET6:
3171  base_mtu = 1280 /* Minimum MTU required by IPv6 */
3172  - sizeof(struct GNUNET_TUN_IPv6Header) /* 40 */
3173  - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */;
3174  break;
3175 
3176  default:
3177  GNUNET_assert (0);
3178  break;
3179  }
3180  /* MTU based on full KX messages */
3181  receiver->kx_mtu = base_mtu - sizeof(struct InitialKX) /* 48 */
3182  - sizeof(struct UDPConfirmation); /* 104 */
3183  /* MTU based on BOXed messages */
3184  receiver->d_mtu = base_mtu - sizeof(struct UDPBox);
3185 
3187  "Setting up MQs and QHs\n");
3188  /* => Effective MTU for CORE will range from 1080 (IPv6 + KX) to
3189  1404 (IPv4 + Box) bytes, depending on circumstances... */
3190  if (NULL == receiver->kx_mq)
3192  &mq_destroy_kx,
3193  &mq_cancel,
3194  receiver,
3195  NULL,
3196  &mq_error,
3197  receiver);
3198  if (NULL == receiver->d_mq)
3200  &mq_destroy_d,
3201  &mq_cancel,
3202  receiver,
3203  NULL,
3204  &mq_error,
3205  receiver);
3206 
3207  receiver->kx_qh =
3209  &receiver->target,
3210  receiver->foreign_addr,
3211  receiver->kx_mtu,
3213  0, /* Priority */
3214  receiver->nt,
3216  receiver->kx_mq);
3217 }
3218 
3219 
3238 static int
3239 mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
3240 {
3241  struct ReceiverAddress *receiver;
3242  const char *path;
3243  struct sockaddr *in;
3244  socklen_t in_len;
3245 
3246  if (0 != strncmp (address,
3248  strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
3249  {
3250  GNUNET_break_op (0);
3251  return GNUNET_SYSERR;
3252  }
3253  path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
3254  in = udp_address_to_sockaddr (path, &in_len);
3255 
3256  receiver = GNUNET_new (struct ReceiverAddress);
3257  receiver->address = in;
3258  receiver->address_len = in_len;
3259  receiver->target = *peer;
3260  receiver->nt = GNUNET_NT_scanner_get_type (is, in, in_len);
3262  receivers,
3263  &receiver->target,
3264  receiver,
3267  "Added %s to receivers\n",
3268  GNUNET_i2s_full (&receiver->target));
3269  receiver->timeout =
3272  receiver,
3273  receiver->timeout.abs_value_us);
3275  "# receivers active",
3277  GNUNET_NO);
3278  receiver->foreign_addr =
3279  sockaddr_to_udpaddr_string (receiver->address, receiver->address_len);
3281  if (NULL == timeout_task)
3283  return GNUNET_OK;
3284 }
3285 
3286 
3295 static int
3297  const struct GNUNET_PeerIdentity *target,
3298  void *value)
3299 {
3300  struct ReceiverAddress *receiver = value;
3301 
3302  (void) cls;
3303  (void) target;
3305  return GNUNET_OK;
3306 }
3307 
3308 
3317 static int
3319  const struct GNUNET_PeerIdentity *target,
3320  void *value)
3321 {
3322  struct SenderAddress *sender = value;
3323 
3324  (void) cls;
3325  (void) target;
3326 
3327  if (NULL != sender->kce_task_rekey)
3328  {
3330  sender->kce_task_rekey = NULL;
3331  }
3332  if (NULL != sender->kce_task)
3333  {
3335  sender->kce_task = NULL;
3336  }
3337 
3338  sender_destroy (sender);
3339  return GNUNET_OK;
3340 }
3341 
3342 
3348 static void
3349 do_shutdown (void *cls)
3350 {
3352  "do_shutdown\n");
3353  if (NULL != nat)
3354  {
3356  nat = NULL;
3357  }
3358  while (NULL != bi_head)
3359  bi_destroy (bi_head);
3360  if (NULL != broadcast_task)
3361  {
3363  broadcast_task = NULL;
3364  }
3365  if (NULL != timeout_task)
3366  {
3368  timeout_task = NULL;
3369  }
3370  if (NULL != read_task)
3371  {
3373  read_task = NULL;
3374  }
3375  if (NULL != udp_sock)
3376  {
3379  udp_sock = NULL;
3380  }
3383  NULL);
3387  NULL);
3392  if (NULL != timeout_task)
3393  {
3395  timeout_task = NULL;
3396  }
3397  if (NULL != ch)
3398  {
3400  ch = NULL;
3401  }
3402  if (NULL != ah)
3403  {
3405  ah = NULL;
3406  }
3407  if (NULL != stats)
3408  {
3410  stats = NULL;
3411  }
3412  if (NULL != my_private_key)
3413  {
3415  my_private_key = NULL;
3416  }
3417  if (NULL != is)
3418  {
3420  is = NULL;
3421  }
3423  "do_shutdown finished\n");
3424 }
3425 
3426 
3436 static void
3437 enc_notify_cb (void *cls,
3438  const struct GNUNET_PeerIdentity *sender,
3439  const struct GNUNET_MessageHeader *msg)
3440 {
3441  const struct UDPAck *ack;
3442 
3443  (void) cls;
3445  "Storing UDPAck received from backchannel from %s\n",
3446  GNUNET_i2s_full (sender));
3448  (ntohs (msg->size) != sizeof(struct UDPAck)))
3449  {
3450  GNUNET_break_op (0);
3451  return;
3452  }
3453  ack = (const struct UDPAck *) msg;
3455  sender,
3456  &handle_ack,
3457  (void *) ack);
3458 }
3459 
3460 
3474 static void
3475 nat_address_cb (void *cls,
3476  void **app_ctx,
3477  int add_remove,
3479  const struct sockaddr *addr,
3480  socklen_t addrlen)
3481 {
3482  char *my_addr;
3484 
3485  if (GNUNET_YES == add_remove)
3486  {
3487  enum GNUNET_NetworkType nt;
3488 
3489  GNUNET_asprintf (&my_addr,
3490  "%s-%s",
3492  GNUNET_a2s (addr, addrlen));
3493  nt = GNUNET_NT_scanner_get_type (is, addr, addrlen);
3494  ai =
3496  my_addr,
3497  nt,
3499  GNUNET_free (my_addr);
3500  *app_ctx = ai;
3501  }
3502  else
3503  {
3504  ai = *app_ctx;
3506  *app_ctx = NULL;
3507  }
3508 }
3509 
3510 
3516 static void
3517 ifc_broadcast (void *cls)
3518 {
3519  struct BroadcastInterface *bi = cls;
3520  struct GNUNET_TIME_Relative delay;
3521 
3525  bi->broadcast_task =
3527 
3528  switch (bi->sa->sa_family)
3529  {
3530  case AF_INET: {
3531  static int yes = 1;
3532  static int no = 0;
3533  ssize_t sent;
3534 
3535  if (GNUNET_OK !=
3537  SOL_SOCKET,
3538  SO_BROADCAST,
3539  &yes,
3540  sizeof(int)))
3542  "setsockopt");
3544  "creating UDPBroadcast from %s\n",
3545  GNUNET_i2s (&(bi->bcm.sender)));
3547  "sending UDPBroadcast to add %s\n",
3548  GNUNET_a2s (bi->ba, bi->salen));
3550  &bi->bcm,
3551  sizeof(bi->bcm),
3552  bi->ba,
3553  bi->salen);
3554  if (-1 == sent)
3556  "sendto");
3558  SOL_SOCKET,
3559  SO_BROADCAST,
3560  &no,
3561  sizeof(int)))
3563  "setsockopt");
3564  break;
3565  }
3566 
3567  case AF_INET6: {
3568  ssize_t sent;
3569  struct sockaddr_in6 dst;
3570 
3571  dst.sin6_family = AF_INET6;
3572  dst.sin6_port = htons (my_port);
3573  dst.sin6_addr = bi->mcreq.ipv6mr_multiaddr;
3574  dst.sin6_scope_id = ((struct sockaddr_in6 *) bi->ba)->sin6_scope_id;
3575 
3577  "sending UDPBroadcast\n");
3579  &bi->bcm,
3580  sizeof(bi->bcm),
3581  (const struct sockaddr *) &dst,
3582  sizeof(dst));
3583  if (-1 == sent)
3585  break;
3586  }
3587 
3588  default:
3589  GNUNET_break (0);
3590  break;
3591  }
3592 }
3593 
3594 
3609 static int
3610 iface_proc (void *cls,
3611  const char *name,
3612  int isDefault,
3613  const struct sockaddr *addr,
3614  const struct sockaddr *broadcast_addr,
3615  const struct sockaddr *netmask,
3616  socklen_t addrlen)
3617 {
3618  struct BroadcastInterface *bi;
3619  enum GNUNET_NetworkType network;
3620  struct UdpBroadcastSignature ubs;
3621 
3622  (void) cls;
3623  (void) netmask;
3624  if (NULL == addr)
3625  return GNUNET_YES; /* need to know our address! */
3626  network = GNUNET_NT_scanner_get_type (is, addr, addrlen);
3627  if (GNUNET_NT_LOOPBACK == network)
3628  {
3629  /* Broadcasting on loopback does not make sense */
3630  return GNUNET_YES;
3631  }
3632  for (bi = bi_head; NULL != bi; bi = bi->next)
3633  {
3634  if ((bi->salen == addrlen) && (0 == memcmp (addr, bi->sa, addrlen)))
3635  {
3636  bi->found = GNUNET_YES;
3637  return GNUNET_OK;
3638  }
3639  }
3640 
3641  if ((AF_INET6 == addr->sa_family) && (NULL == broadcast_addr))
3642  return GNUNET_OK; /* broadcast_addr is required for IPv6! */
3643  if ((AF_INET6 == addr->sa_family) && (GNUNET_YES != have_v6_socket))
3644  return GNUNET_OK; /* not using IPv6 */
3645 
3646  bi = GNUNET_new (struct BroadcastInterface);
3647  bi->sa = GNUNET_memdup (addr,
3648  addrlen);
3649  if ( (NULL != broadcast_addr) &&
3650  (addrlen == sizeof (struct sockaddr_in)) )
3651  {
3652  struct sockaddr_in *ba;
3653 
3654  ba = GNUNET_memdup (broadcast_addr,
3655  addrlen);
3656  ba->sin_port = htons (2086); /* always GNUnet port, ignore configuration! */
3657  bi->ba = (struct sockaddr *) ba;
3658  }
3659  bi->salen = addrlen;
3660  bi->found = GNUNET_YES;
3661  bi->bcm.sender = my_identity;
3662  ubs.purpose.purpose = htonl (
3664  ubs.purpose.size = htonl (sizeof(ubs));
3665  ubs.sender = my_identity;
3667  "creating UDPBroadcastSignature for %s\n",
3668  GNUNET_a2s (addr, addrlen));
3669  GNUNET_CRYPTO_hash (addr, addrlen, &ubs.h_address);
3671  &ubs,
3672  &bi->bcm.sender_sig);
3673  if (NULL != bi->ba)
3674  {
3677  }
3678  if ((AF_INET6 == addr->sa_family) && (NULL != broadcast_addr))
3679  {
3680  /* Create IPv6 multicast request */
3681  const struct sockaddr_in6 *s6 =
3682  (const struct sockaddr_in6 *) broadcast_addr;
3683 
3684  GNUNET_assert (
3685  1 == inet_pton (AF_INET6, "FF05::13B", &bi->mcreq.ipv6mr_multiaddr));
3686 
3687  /* http://tools.ietf.org/html/rfc2553#section-5.2:
3688  *
3689  * IPV6_JOIN_GROUP
3690  *
3691  * Join a multicast group on a specified local interface. If the
3692  * interface index is specified as 0, the kernel chooses the local
3693  * interface. For example, some kernels look up the multicast
3694  * group in the normal IPv6 routing table and using the resulting
3695  * interface; we do this for each interface, so no need to use
3696  * zero (anymore...).
3697  */bi->mcreq.ipv6mr_interface = s6->sin6_scope_id;
3698 
3699  /* Join the multicast group */
3701  IPPROTO_IPV6,
3702  IPV6_JOIN_GROUP,
3703  &bi->mcreq,
3704  sizeof(bi->mcreq)))
3705  {
3707  }
3708  }
3709  return GNUNET_OK;
3710 }
3711 
3712 
3718 static void
3719 do_broadcast (void *cls)
3720 {
3721  struct BroadcastInterface *bin;
3722 
3723  (void) cls;
3724  for (struct BroadcastInterface *bi = bi_head; NULL != bi; bi = bi->next)
3725  bi->found = GNUNET_NO;
3727  for (struct BroadcastInterface *bi = bi_head; NULL != bi; bi = bin)
3728  {
3729  bin = bi->next;
3730  if (GNUNET_NO == bi->found)
3731  bi_destroy (bi);
3732  }
3734  &do_broadcast,
3735  NULL);
3736 }
3737 
3738 static void
3740  const struct sockaddr *addr,
3741  socklen_t addrlen)
3742 {
3743  /* FIXME: support reversal: #5529 */
3744 }
3745 
3754 static void
3755 run (void *cls,
3756  char *const *args,
3757  const char *cfgfile,
3758  const struct GNUNET_CONFIGURATION_Handle *c)
3759 {
3760  char *bindto;
3761  struct sockaddr *in;
3762  socklen_t in_len;
3763  struct sockaddr_storage in_sto;
3764  socklen_t sto_len;
3765 
3766  (void) cls;
3767  cfg = c;
3768  if (GNUNET_OK !=
3771  "BINDTO",
3772  &bindto))
3773  {
3776  "BINDTO");
3777  return;
3778  }
3779 
3780  if (GNUNET_OK !=
3783  "REKEY_INTERVAL",
3784  &rekey_interval))
3786 
3787  if (GNUNET_OK !=
3790  "REKEY_MAX_BYTES",
3791  &rekey_max_bytes))
3793 
3794  in = udp_address_to_sockaddr (bindto, &in_len);
3795  if (NULL == in)
3796  {
3798  "Failed to setup UDP socket address with path `%s'\n",
3799  bindto);
3800  GNUNET_free (bindto);
3801  return;
3802  }
3803  udp_sock =
3804  GNUNET_NETWORK_socket_create (in->sa_family,
3805  SOCK_DGRAM,
3806  IPPROTO_UDP);
3807  if (NULL == udp_sock)
3808  {
3810  GNUNET_free (in);
3811  GNUNET_free (bindto);
3812  return;
3813  }
3814  if (AF_INET6 == in->sa_family)
3816  if (GNUNET_OK !=
3818  in,
3819  in_len))
3820  {
3822  "bind",
3823  bindto);
3825  udp_sock = NULL;
3826  GNUNET_free (in);
3827  GNUNET_free (bindto);
3828  return;
3829  }
3830 
3831  /* We might have bound to port 0, allowing the OS to figure it out;
3832  thus, get the real IN-address from the socket */
3833  sto_len = sizeof(in_sto);
3834  if (0 != getsockname (GNUNET_NETWORK_get_fd (udp_sock),
3835  (struct sockaddr *) &in_sto,
3836  &sto_len))
3837  {
3838  memcpy (&in_sto, in, in_len);
3839  sto_len = in_len;
3840  }
3841  GNUNET_free (in);
3842  GNUNET_free (bindto);
3843  in = (struct sockaddr *) &in_sto;
3844  in_len = sto_len;
3846  "transport",
3847  "Bound to `%s'\n",
3848  GNUNET_a2s ((const struct sockaddr *) &in_sto,
3849  sto_len));
3850  switch (in->sa_family)
3851  {
3852  case AF_INET:
3853  my_port = ntohs (((struct sockaddr_in *) in)->sin_port);
3854  break;
3855 
3856  case AF_INET6:
3857  my_port = ntohs (((struct sockaddr_in6 *) in)->sin6_port);
3858  break;
3859 
3860  default:
3861  GNUNET_break (0);
3862  my_port = 0;
3863  }
3864  stats = GNUNET_STATISTICS_create ("C-UDP", cfg);
3868  receivers_heap =
3874  if (NULL == my_private_key)
3875  {
3876  GNUNET_log (
3878  _ (
3879  "Transport service is lacking key configuration settings. Exiting.\n"));
3881  return;
3882  }
3884  /* start reading */
3886  udp_sock,
3887  &sock_read,
3888  NULL);
3893  &mq_init,
3894  NULL,
3895  &enc_notify_cb,
3896  NULL);
3897  if (NULL == ch)
3898  {
3899  GNUNET_break (0);
3901  return;
3902  }
3904  if (NULL == ah)
3905  {
3906  GNUNET_break (0);
3908  return;
3909  }
3910  /* start broadcasting */
3911  if (GNUNET_YES !=
3914  "DISABLE_BROADCAST"))
3915  {
3917  }
3920  IPPROTO_UDP,
3921  1 /* one address */,
3922  (const struct sockaddr **) &in,
3923  &in_len,
3924  &nat_address_cb,
3926  NULL /* closure */);
3927 }
3928 
3929 
3937 int
3938 main (int argc, char *const *argv)
3939 {
3940  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
3942  };
3943  int ret;
3944 
3946  "transport",
3947  "Starting udp communicator\n");
3948  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
3949  return 2;
3950 
3951  ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc,
3952  argv,
3953  "gnunet-communicator-udp",
3954  _ ("GNUnet UDP communicator"),
3955  options,
3956  &run,
3957  NULL))
3958  ? 0
3959  : 1;
3960  GNUNET_free_nz ((void *) argv);
3961  return ret;
3962 }
3963 
3964 
3965 /* end of gnunet-communicator-udp.c */
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#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.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
static int res
static uint16_t port
Port number.
Definition: gnunet-bcd.c:147
#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)
#define WORKING_QUEUE_INTERVALL
static void kce_destroy(struct KeyCacheEntry *kce)
Free memory used by key cache entry.
static void destroy_all_secrets(struct SharedSecret *ss, int withoutKce)
Destroying all secrets.
static void mq_destroy_d(struct GNUNET_MQ_Handle *mq, void *impl_state)
Signature of functions implementing the destruction of a message queue.
static void get_iv_key(const struct GNUNET_HashCode *msec, uint32_t serial, char key[(256/8)], char iv[(96/8)])
Compute key and iv.
static uint32_t reset_rekey_kces(struct ReceiverAddress *receiver, uint32_t acks_to_add)
static int secret_destroy(struct SharedSecret *ss, int withoutKce)
Destroy ss and associated key cache entries.
static void setup_cipher(const struct GNUNET_HashCode *msec, uint32_t serial, gcry_cipher_hd_t *cipher)
Setup cipher based on shared secret msec and serial number serial.
#define GCM_TAG_SIZE
Size of the GCM tag.
static struct GNUNET_PeerIdentity my_identity
Our public key.
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.
#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 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 void consider_ss_ack(struct SharedSecret *ss, int initial)
We established a shared secret with a sender.
static void mq_destroy_kx(struct GNUNET_MQ_Handle *mq, void *impl_state)
Signature of functions implementing the destruction of a message queue.
static struct GNUNET_CONTAINER_MultiPeerMap * receivers
Receivers (map from peer identity to struct ReceiverAddress)
static void kce_generate_rekey_cb(void *cls)
static int find_sender_by_address(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Find existing struct SenderAddress by matching addresses.
static void try_connection_reversal(void *cls, const struct sockaddr *addr, socklen_t addrlen)
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 struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
static void add_acks_rekey(struct ReceiverAddress *receiver)
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static void enc_notify_cb(void *cls, const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *msg)
Function called when the transport service has received a backchannel message for this communicator (...
static struct GNUNET_TIME_Relative rekey_interval
The rekey interval.
static void reschedule_receiver_timeout(struct ReceiverAddress *receiver)
Increment receiver timeout due to activity.
static struct GNUNET_NETWORK_Handle * udp_sock
Our socket.
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 void do_shutdown(void *cls)
Shutdown the UNIX communicator.
#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.
struct SharedSecret * ss_finished
Shared secret we finished the last kce working queue for.
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 void setup_receiver_mq(struct ReceiverAddress *receiver)
Setup the MQ for the receiver.
static struct SharedSecret * setup_shared_secret_enc(const struct GNUNET_CRYPTO_EcdhePrivateKey *ephemeral, struct ReceiverAddress *receiver, int add_to_receiver)
Setup shared secret for encryption.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Setup communicator and launch network interactions.
#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 struct SenderAddress * setup_sender(const struct GNUNET_PeerIdentity *target, const struct sockaddr *address, socklen_t address_len)
Create sender address for target.
#define GENERATE_AT_ONCE
static void kce_generate_cb(void *cls)
static struct GNUNET_SCHEDULER_Task * read_task
ID of read task.
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 sockaddr * udp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
Convert UDP bind specification to a struct sockaddr *
static void receiver_destroy(struct ReceiverAddress *receiver)
Destroys a receiving state due to timeout or shutdown.
static void check_for_rekeying(struct ReceiverAddress *receiver, struct UDPBox *box)
static struct GNUNET_CONTAINER_MultiShortmap * key_cache
Cache of pre-generated key IDs.
static int handle_ack(void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
We received an ACK for pid.
#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 int have_v6_socket
GNUNET_YES if udp_sock supports IPv6.
static int try_decrypt(const struct SharedSecret *ss, const char tag[(128/8)], 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.
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 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 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 void get_kid(const struct GNUNET_HashCode *msec, uint32_t serial, struct GNUNET_ShortHashCode *kid)
Compute kid.
static void check_timeouts(void *cls)
Task run to check #receiver_heap and #sender_heap for timeouts.
static int get_receiver_delete_it(void *cls, const struct GNUNET_PeerIdentity *target, void *value)
Iterator over all receivers to clean up.
static struct GNUNET_CONTAINER_MultiPeerMap * senders
Senders (map from peer identity to struct SenderAddress)
static void calculate_cmac(struct SharedSecret *ss)
Calculate cmac from master in ss.
static struct GNUNET_SCHEDULER_Task * timeout_task
ID of timeout task.
#define MAX_SQN_DELTA
What is the maximum delta between KCN sequence numbers that we allow.
static void decrypt_rekey(const struct UDPRekey *rekey, size_t rekey_len, struct KeyCacheEntry *kce, struct SenderAddress *sender)
We received a rekey with matching kce.
int main(int argc, char *const *argv)
The main function for the UNIX communicator.
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Our private key.
#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 int get_sender_delete_it(void *cls, const struct GNUNET_PeerIdentity *target, void *value)
Iterator over all senders to clean up.
static struct SharedSecret * setup_shared_secret_dec(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral)
Setup shared secret for decryption.
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 send_UDPRekey(struct ReceiverAddress *receiver, struct SharedSecret *ss)
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 void decrypt_box(const struct UDPBox *box, size_t box_len, struct KeyCacheEntry *kce)
We received a box with matching kce.
static int verify_confirmation(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, const struct UDPConfirmation *uc)
Check signature from uc against ephemeral.
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 struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
static char * value
Value of the record to add/remove.
static struct GNUNET_NAT_AUTO_Test * nt
Handle to a NAT test operation.
static struct GNUNET_MQ_Envelope * ac
Handle to current GNUNET_PEERINFO_add_peer() operation.
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:87
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
static int do_decrypt(struct GSC_KeyExchangeInfo *kx, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, const void *in, void *out, size_t size)
Decrypt size bytes from in and write the result to out.
static char buf[2048]
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
static struct GNUNET_FS_UnindexContext * uc
Constants for network protocols.
API to create, modify and access statistics.
Bandwidth allocation API for applications to interact with.
API of the transport service towards the communicator processes.
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?
void GNUNET_CRYPTO_ecdhe_key_create(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:435
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Generate a random unsigned 64-bit value.
struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_CRYPTO_eddsa_key_create_from_configuration(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create a new private key by reading our peer's key from the file specified in the configuration.
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:197
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_ecdh(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_HashCode *key_material)
Derive key material from a ECDH public key and a private EdDSA key.
Definition: crypto_ecc.c:739
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdh_eddsa(const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, const struct GNUNET_CRYPTO_EddsaPublicKey *pub, struct GNUNET_HashCode *key_material)
Derive key material from a EdDSA public key and a private ECDH key.
Definition: crypto_ecc.c:779
#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.
void GNUNET_CRYPTO_ecdhe_key_get_public(const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, struct GNUNET_CRYPTO_EcdhePublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:213
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hkdf(void *result, size_t out_len, int xtr_algo, int prf_algo, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
Derive key.
Definition: crypto_hkdf.c:341
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_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.
struct GNUNET_CONTAINER_MultiPeerMap * GNUNET_CONTAINER_multipeermap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
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).
void GNUNET_CONTAINER_multishortmap_destroy(struct GNUNET_CONTAINER_MultiShortmap *map)
Destroy a hash 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.
int GNUNET_CONTAINER_multipeermap_get_multiple(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, GNUNET_CONTAINER_PeerMapIterator 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.
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
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.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
void * GNUNET_CONTAINER_heap_remove_node(struct GNUNET_CONTAINER_HeapNode *node)
Removes a node from the 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.
void * GNUNET_CONTAINER_heap_peek(const struct GNUNET_CONTAINER_Heap *heap)
Get element stored at the root of 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.
#define GNUNET_log(kind,...)
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;.
#define GNUNET_PACKED
gcc-ism to get packed structs.
@ 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).
#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).
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#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.
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).
#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
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_free_nz(ptr)
Wrapper around free.
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
GNUNET_MQ_Error
Error codes for the queue.
struct GNUNET_MQ_Handle * GNUNET_MQ_queue_for_callbacks(GNUNET_MQ_SendImpl send, GNUNET_MQ_DestroyImpl destroy, GNUNET_MQ_CancelImpl cancel, void *impl_state, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *cls)
Create a message queue for the specified handlers.
Definition: mq.c:465
void GNUNET_MQ_impl_send_continue(struct GNUNET_MQ_Handle *mq)
Call the send implementation for the next queued message, if any.
Definition: mq.c:421
void GNUNET_NAT_unregister(struct GNUNET_NAT_Handle *nh)
Stop port redirection and public IP address detection for the given handle.
Definition: nat_api.c:674
GNUNET_NAT_AddressClass
Some addresses contain sensitive information or are not suitable for global distribution.
struct GNUNET_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
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.
Definition: gnunet_nt_lib.h:39
void GNUNET_NT_scanner_done(struct GNUNET_NT_InterfaceScanner *is)
Terminate interface scanner.
Definition: nt.c:427
struct GNUNET_NT_InterfaceScanner * GNUNET_NT_scanner_init(void)
Initialize the address characterization client handle.
Definition: nt.c:406
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:308
@ GNUNET_NT_LOOPBACK
Loopback (same host).
Definition: gnunet_nt_lib.h:48
void GNUNET_OS_network_interfaces_list(GNUNET_OS_NetworkInterfaceProcessor proc, void *proc_cls)
Enumerate all network interfaces.
Definition: os_network.c:397
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition: program.c:400
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_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:562
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1299
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1506
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition: scheduler.c:1334
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1272
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1222
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:343
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:405
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:316
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_monotonic(const struct GNUNET_CONFIGURATION_Handle *cfg)
Obtain the current time and make sure it is monotonically increasing.
Definition: time.c:860
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:638
void GNUNET_TRANSPORT_communicator_address_remove(struct GNUNET_TRANSPORT_AddressIdentifier *ai)
Notify transport service about an address that this communicator no longer provides for this peer.
int GNUNET_TRANSPORT_communicator_receive(struct GNUNET_TRANSPORT_CommunicatorHandle *handle, const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *msg, struct GNUNET_TIME_Relative expected_addr_validity, GNUNET_TRANSPORT_MessageCompletedCallback cb, void *cb_cls)
Notify transport service that the communicator has received a message.
void GNUNET_TRANSPORT_communicator_mq_del(struct GNUNET_TRANSPORT_QueueHandle *qh)
Notify transport service that an MQ became unavailable due to a disconnect or timeout.
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_ApplicationHandle * GNUNET_TRANSPORT_application_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the TRANSPORT application client handle.
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...
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_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_CommunicatorHandle * GNUNET_TRANSPORT_communicator_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *config_section_name, const char *addr_prefix, enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, GNUNET_TRANSPORT_CommunicatorMqInit mq_init, void *mq_init_cls, GNUNET_TRANSPORT_CommunicatorNotify notify_cb, void *notify_cb_cls)
Connect to the transport service.
@ GNUNET_TRANSPORT_CC_UNRELIABLE
Transmission is unreliable (e.g.
@ GNUNET_TRANSPORT_CS_OUTBOUND
this is an outbound connection (transport initiated)
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
const char * name
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
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.
Handle to a node in a heap.
Internal representation of the hash map.
Internal representation of the hash map.
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
Private ECC key encoded for transmission.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
Private ECC key encoded for transmission.
an ECC signature using EdDSA.
Definition of a command line option.
A 512-bit hashcode.
Handle to a message queue.
Definition: mq.c:87
Header for all communications.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
Handle for active NAT registrations.
Definition: nat_api.c:72
handle to a socket
Definition: network.c:53
Handle to the interface scanner.
Definition: nt.c:105
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:136
Handle for the service.
A 256-bit hashcode.
Time for absolute time used by GNUnet, in microseconds and in network byte order.
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
Internal representation of an address a communicator is currently providing for the transport service...
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.
"Plaintext" header at beginning of KX message.
char gcm_tag[(128/8)]
HMAC for the following encrypted message, using GCM.
int rekeying
A flag indicating, if the sender is doing rekeying.
struct GNUNET_CRYPTO_EcdhePublicKey ephemeral
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.
int rekeying
Flag indicating sender is initiated rekeying for this receiver.
struct SharedSecret * ss_tail
Shared secrets we received with target, last used is tail.
int number_rekeying_kce
Number of kce we retain for sending the rekeying shared secret.
char * foreign_addr
Address of the receiver in the human-readable format with the COMMUNICATOR_ADDRESS_PREFIX.
unsigned int rekey_acks_available
Acks available when we started rekeying.
unsigned int acks_available
Number of BOX keys from ACKs we have currently available for this receiver.
struct SharedSecret * ss_rekey
Shared secret we use with target for rekeying.
struct SharedSecret * ss_head
Shared secrets we received from target, first used is head.
uint64_t rekey_send_bytes
Send bytes for this receiver address.
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.
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_TRANSPORT_QueueHandle * d_qh
handle for default queue with the ch.
Context information to be used while searching for operation contexts.
Definition: testbed_api.c:226
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.
struct GNUNET_TIME_Absolute timeout
Timeout for this sender.
int rekeying
Flag indicating sender is initiated rekeying for this receiver.
int kce_task_finished
Is the kce_task finished?
struct GNUNET_SCHEDULER_Task * kce_task_rekey
ID of kce rekey working queue task.
struct GNUNET_SCHEDULER_Task * kce_task
ID of kce working queue task.
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_rekey
Shared secret we use with target for rekeying.
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)
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_HashCode master
Master shared secret.
UDP key acknowledgement.
uint32_t sequence_max
Sequence acknowledgement limit.
struct GNUNET_HashCode cmac
CMAC of the base key being acknowledged.
uint32_t acks_available
Sequence acknowledgement limit.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK.
UDP message box.
int rekeying
A flag indicating, if the sender is doing rekeying.
char 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...
UDP message box.
struct GNUNET_PeerIdentity sender
Sender's identity.
struct GNUNET_ShortHashCode kid
Key and IV identification code.
char gcm_tag[(128/8)]
128-bit authentication tag for the following encrypted message, from GCM.
Signature we use to verify that the broadcast was really made by the peer that claims to have made it...
struct GNUNET_CRYPTO_EccSignaturePurpose 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_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_EcdhePublicKey ephemeral
Ephemeral key used by the sender.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_UDP_HANDSHAKE.
struct GNUNET_PeerIdentity sender
Identity of the inititor of the UDP connection (UDP client).
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.