GNUnet  0.11.x
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 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 
81 #define AES_KEY_SIZE (256 / 8)
82 
86 #define AES_IV_SIZE (96 / 8)
87 
91 #define GCM_TAG_SIZE (128 / 8)
92 
102 #define KCN_THRESHOLD 92
103 
110 #define KCN_TARGET 128
111 
121 #define MAX_SQN_DELTA 160
122 
132 #define MAX_SECRETS 128
133 
138 #define REKEY_MAX_BYTES (1024LLU * 1024 * 1024 * 4LLU)
139 
144 #define COMMUNICATOR_ADDRESS_PREFIX "udp"
145 
149 #define COMMUNICATOR_CONFIG_SECTION "communicator-udp"
150 
152 
153 
160 {
165 
170 
175 
180 
186 };
187 
188 
193 struct InitialKX
194 {
199 
204  char gcm_tag[GCM_TAG_SIZE];
205 };
206 
207 
213 {
218 
222  struct GNUNET_CRYPTO_EddsaSignature sender_sig;
223 
228  struct GNUNET_TIME_AbsoluteNBO monotonic_time;
229 
230  /* followed by messages */
231 
232  /* padding may follow actual messages */
233 };
234 
235 
240 struct UDPAck
241 {
245  struct GNUNET_MessageHeader header;
246 
251  uint32_t sequence_max GNUNET_PACKED;
252 
256  struct GNUNET_HashCode cmac;
257 };
258 
259 
269 {
274 
279 
283  struct GNUNET_HashCode h_address;
284 };
285 
286 
294 {
299 
304  struct GNUNET_CRYPTO_EddsaSignature sender_sig;
305 };
306 
307 
312 struct UDPBox
313 {
322 
330  char gcm_tag[GCM_TAG_SIZE];
331 };
332 
333 
335 
339 struct SharedSecret;
340 
341 
347 {
352 
357 
366 
370  struct SharedSecret *ss;
371 
375  uint32_t sequence_number;
376 };
377 
378 
383 struct SenderAddress;
384 
389 struct ReceiverAddress;
390 
395 {
400 
405 
410 
415 
420 
425 
429  struct GNUNET_HashCode master;
430 
434  struct GNUNET_HashCode cmac;
435 
440  uint32_t sequence_used;
441 
448 
452  unsigned int active_kce_count;
453 };
454 
455 
461 {
465  struct GNUNET_PeerIdentity target;
466 
471 
476 
481 
485  struct sockaddr *address;
486 
490  socklen_t address_len;
491 
496 
500  unsigned int num_secrets;
501 
506 };
507 
508 
514 {
518  struct GNUNET_PeerIdentity target;
519 
524 
529 
535 
539  struct sockaddr *address;
540 
544  socklen_t address_len;
545 
550 
555 
560 
565 
570 
575 
579  size_t kx_mtu;
580 
584  size_t d_mtu;
585 
589  unsigned int num_secrets;
590 
595  unsigned int acks_available;
596 
601 };
602 
603 
608 {
613 
618 
623 
627  struct sockaddr *sa;
628 
632  struct sockaddr *ba;
633 
637  struct UDPBroadcast bcm;
638 
643  struct ipv6_mreq mcreq;
644 
648  socklen_t salen;
649 
653  int found;
654 };
655 
656 
661 
666 
671 
676 
681 
686 
691 
696 
701 
706 
711 
716 
721 
725 static int have_v6_socket;
726 
731 
736 
740 static const struct GNUNET_CONFIGURATION_Handle *cfg;
741 
746 
751 
755 static struct GNUNET_NAT_Handle *nat;
756 
760 static uint16_t my_port;
761 
762 
768 static void
770 {
771  if (AF_INET6 == bi->sa->sa_family)
772  {
773  /* Leave the multicast group */
775  IPPROTO_IPV6,
776  IPV6_LEAVE_GROUP,
777  &bi->mcreq,
778  sizeof(bi->mcreq)))
779  {
781  }
782  }
783  GNUNET_CONTAINER_DLL_remove (bi_head, bi_tail, bi);
785  GNUNET_free (bi->sa);
786  GNUNET_free (bi->ba);
787  GNUNET_free (bi);
788 }
789 
790 
796 static void
798 {
799  struct GNUNET_MQ_Handle *mq;
800 
802  "Disconnecting receiver for peer `%s'\n",
803  GNUNET_i2s (&receiver->target));
804  if (NULL != (mq = receiver->kx_mq))
805  {
806  receiver->kx_mq = NULL;
807  GNUNET_MQ_destroy (mq);
808  }
809  if (NULL != receiver->kx_qh)
810  {
812  receiver->kx_qh = NULL;
813  }
814  if (NULL != (mq = receiver->d_mq))
815  {
816  receiver->d_mq = NULL;
817  GNUNET_MQ_destroy (mq);
818  }
819  if (NULL != receiver->d_qh)
820  {
822  receiver->d_qh = NULL;
823  }
826  &receiver->target,
827  receiver));
828  GNUNET_assert (receiver == GNUNET_CONTAINER_heap_remove_node (receiver->hn));
829  GNUNET_STATISTICS_set (stats,
830  "# receivers active",
832  GNUNET_NO);
833  GNUNET_free (receiver->address);
834  GNUNET_free (receiver->foreign_addr);
835  GNUNET_free (receiver);
836 }
837 
838 
844 static void
846 {
847  struct SharedSecret *ss = kce->ss;
848 
849  ss->active_kce_count--;
852  &kce->kid,
853  kce));
854  GNUNET_free (kce);
855 }
856 
857 
865 static void
866 get_kid (const struct GNUNET_HashCode *msec,
867  uint32_t serial,
868  struct GNUNET_ShortHashCode *kid)
869 {
870  uint32_t sid = htonl (serial);
871 
872  GNUNET_CRYPTO_hkdf (kid,
873  sizeof(*kid),
874  GCRY_MD_SHA512,
875  GCRY_MD_SHA256,
876  &sid,
877  sizeof(sid),
878  msec,
879  sizeof(*msec),
880  "UDP-KID",
881  strlen ("UDP-KID"),
882  NULL,
883  0);
884 }
885 
886 
893 static void
894 kce_generate (struct SharedSecret *ss, uint32_t seq)
895 {
896  struct KeyCacheEntry *kce;
897 
898  GNUNET_assert (0 < seq);
899  kce = GNUNET_new (struct KeyCacheEntry);
900  kce->ss = ss;
901  kce->sequence_number = seq;
902  get_kid (&ss->master, seq, &kce->kid);
904  ss->active_kce_count++;
906  key_cache,
907  &kce->kid,
908  kce,
910  GNUNET_STATISTICS_set (stats,
911  "# KIDs active",
913  GNUNET_NO);
914 }
915 
916 
922 static void
924 {
925  struct SenderAddress *sender;
926  struct ReceiverAddress *receiver;
927  struct KeyCacheEntry *kce;
928 
929  if (NULL != (sender = ss->sender))
930  {
931  GNUNET_CONTAINER_DLL_remove (sender->ss_head, sender->ss_tail, ss);
932  sender->num_secrets--;
933  }
934  if (NULL != (receiver = ss->receiver))
935  {
936  GNUNET_CONTAINER_DLL_remove (receiver->ss_head, receiver->ss_tail, ss);
937  receiver->num_secrets--;
938  receiver->acks_available -= (ss->sequence_allowed - ss->sequence_used);
939  }
940  while (NULL != (kce = ss->kce_head))
941  kce_destroy (kce);
942  GNUNET_STATISTICS_update (stats, "# Secrets active", -1, GNUNET_NO);
943  GNUNET_STATISTICS_set (stats,
944  "# KIDs active",
946  GNUNET_NO);
947  GNUNET_free (ss);
948 }
949 
950 
957 static void
959 {
960  GNUNET_assert (
961  GNUNET_YES ==
962  GNUNET_CONTAINER_multipeermap_remove (senders, &sender->target, sender));
963  GNUNET_assert (sender == GNUNET_CONTAINER_heap_remove_node (sender->hn));
964  GNUNET_STATISTICS_set (stats,
965  "# senders active",
967  GNUNET_NO);
968  GNUNET_free (sender->address);
969  GNUNET_free (sender);
970 }
971 
972 
981 static void
982 get_iv_key (const struct GNUNET_HashCode *msec,
983  uint32_t serial,
984  char key[AES_KEY_SIZE],
985  char iv[AES_IV_SIZE])
986 {
987  uint32_t sid = htonl (serial);
988  char res[AES_KEY_SIZE + AES_IV_SIZE];
989 
990  GNUNET_CRYPTO_hkdf (res,
991  sizeof(res),
992  GCRY_MD_SHA512,
993  GCRY_MD_SHA256,
994  &sid,
995  sizeof(sid),
996  msec,
997  sizeof(*msec),
998  "UDP-IV-KEY",
999  strlen ("UDP-IV-KEY"),
1000  NULL,
1001  0);
1002  memcpy (key, res, AES_KEY_SIZE);
1003  memcpy (iv, &res[AES_KEY_SIZE], AES_IV_SIZE);
1004 }
1005 
1006 
1012 static void
1014 {
1015  sender->timeout =
1018 }
1019 
1020 
1026 static void
1028 {
1029  receiver->timeout =
1032  receiver->timeout.abs_value_us);
1033 }
1034 
1035 
1041 static void
1042 check_timeouts (void *cls)
1043 {
1044  struct GNUNET_TIME_Relative st;
1045  struct GNUNET_TIME_Relative rt;
1046  struct GNUNET_TIME_Relative delay;
1047  struct ReceiverAddress *receiver;
1048  struct SenderAddress *sender;
1049 
1050  (void) cls;
1051  timeout_task = NULL;
1053  while (NULL != (receiver = GNUNET_CONTAINER_heap_peek (receivers_heap)))
1054  {
1056  if (0 != rt.rel_value_us)
1057  break;
1059  "Receiver timed out\n");
1060  receiver_destroy (receiver);
1061  }
1063  while (NULL != (sender = GNUNET_CONTAINER_heap_peek (senders_heap)))
1064  {
1066  if (0 != st.rel_value_us)
1067  break;
1068  sender_destroy (sender);
1069  }
1070  delay = GNUNET_TIME_relative_min (rt, st);
1071  if (delay.rel_value_us < GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
1072  timeout_task = GNUNET_SCHEDULER_add_delayed (delay, &check_timeouts, NULL);
1073 }
1074 
1075 
1081 static void
1083 {
1084  GNUNET_CRYPTO_hkdf (&ss->cmac,
1085  sizeof(ss->cmac),
1086  GCRY_MD_SHA512,
1087  GCRY_MD_SHA256,
1088  "CMAC",
1089  strlen ("CMAC"),
1090  &ss->master,
1091  sizeof(ss->master),
1092  "UDP-CMAC",
1093  strlen ("UDP-CMAC"),
1094  NULL,
1095  0);
1096 }
1097 
1098 
1107 static void
1109  const void *plaintext,
1110  size_t plaintext_len)
1111 {
1112  const struct GNUNET_MessageHeader *hdr = plaintext;
1113  const char *pos = plaintext;
1114 
1115  while (ntohs (hdr->size) < plaintext_len)
1116  {
1117  GNUNET_STATISTICS_update (stats,
1118  "# bytes given to core",
1119  ntohs (hdr->size),
1120  GNUNET_NO);
1122  "Giving %u bytes to TNG\n", ntohs (hdr->size));
1125  &sender->target,
1126  hdr,
1128  NULL /* no flow control possible */
1129  ,
1130  NULL));
1131  /* move on to next message, if any */
1132  plaintext_len -= ntohs (hdr->size);
1133  if (plaintext_len < sizeof(*hdr))
1134  break;
1135  pos += ntohs (hdr->size);
1136  hdr = (const struct GNUNET_MessageHeader *) pos;
1137  // TODO for now..., we do not actually sen >1msg or have a way of telling
1138  // if we are done
1139  break;
1140  }
1141  GNUNET_STATISTICS_update (stats,
1142  "# bytes padding discarded",
1143  plaintext_len,
1144  GNUNET_NO);
1145 }
1146 
1147 
1156 static void
1157 setup_cipher (const struct GNUNET_HashCode *msec,
1158  uint32_t serial,
1159  gcry_cipher_hd_t *cipher)
1160 {
1161  char key[AES_KEY_SIZE];
1162  char iv[AES_IV_SIZE];
1163  int rc;
1164 
1165  GNUNET_assert (0 ==
1166  gcry_cipher_open (cipher,
1167  GCRY_CIPHER_AES256 /* low level: go for speed */,
1168  GCRY_CIPHER_MODE_GCM,
1169  0 /* flags */));
1170  get_iv_key (msec, serial, key, iv);
1171  rc = gcry_cipher_setkey (*cipher, key, sizeof(key));
1172  GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
1173  rc = gcry_cipher_setiv (*cipher, iv, sizeof(iv));
1174  GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
1175 }
1176 
1177 
1190 static int
1191 try_decrypt (const struct SharedSecret *ss,
1192  const char tag[GCM_TAG_SIZE],
1193  uint32_t serial,
1194  const char *in_buf,
1195  size_t in_buf_size,
1196  char *out_buf)
1197 {
1198  gcry_cipher_hd_t cipher;
1199 
1200  setup_cipher (&ss->master, serial, &cipher);
1201  GNUNET_assert (
1202  0 ==
1203  gcry_cipher_decrypt (cipher, out_buf, in_buf_size, in_buf, in_buf_size));
1204  if (0 != gcry_cipher_checktag (cipher, tag, GCM_TAG_SIZE))
1205  {
1206  gcry_cipher_close (cipher);
1207  GNUNET_STATISTICS_update (stats,
1208  "# AEAD authentication failures",
1209  1,
1210  GNUNET_NO);
1211  return GNUNET_SYSERR;
1212  }
1213  gcry_cipher_close (cipher);
1214  return GNUNET_OK;
1215 }
1216 
1217 
1224 static struct SharedSecret *
1226 {
1227  struct SharedSecret *ss;
1228 
1229  ss = GNUNET_new (struct SharedSecret);
1230  GNUNET_CRYPTO_eddsa_ecdh (my_private_key, ephemeral, &ss->master);
1231  return ss;
1232 }
1233 
1234 
1242 static struct SharedSecret *
1244  struct ReceiverAddress *receiver)
1245 {
1246  struct SharedSecret *ss;
1247 
1248  ss = GNUNET_new (struct SharedSecret);
1249  GNUNET_CRYPTO_ecdh_eddsa (ephemeral,
1250  &receiver->target.public_key,
1251  &ss->master);
1252  calculate_cmac (ss);
1253  ss->receiver = receiver;
1254  GNUNET_CONTAINER_DLL_insert (receiver->ss_head, receiver->ss_tail, ss);
1255  receiver->num_secrets++;
1256  GNUNET_STATISTICS_update (stats, "# Secrets active", 1, GNUNET_NO);
1257  return ss;
1258 }
1259 
1260 
1268 static void
1270 
1271 
1282 static int
1283 handle_ack (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
1284 {
1285  const struct UDPAck *ack = cls;
1286  struct ReceiverAddress *receiver = value;
1288  "in handle ack\n");
1289 
1290  (void) pid;
1291  for (struct SharedSecret *ss = receiver->ss_head; NULL != ss; ss = ss->next)
1292  {
1293  if (0 == memcmp (&ack->cmac, &ss->cmac, sizeof(struct GNUNET_HashCode)))
1294  {
1295  uint32_t allowed;
1297  "Found matching mac\n");
1298 
1299  allowed = ntohl (ack->sequence_max);
1300 
1301  if (allowed > ss->sequence_allowed)
1302  {
1304  "%u > %u (%u)\n", allowed, ss->sequence_allowed,
1305  receiver->acks_available);
1306 
1307  receiver->acks_available += (allowed - ss->sequence_allowed);
1309  "Tell transport we have more acks!\n");
1311  receiver->d_qh,
1312  (allowed
1313  - ss->sequence_allowed),
1314  1);
1315  ss->sequence_allowed = allowed;
1316  /* move ss to head to avoid discarding it anytime soon! */
1317  GNUNET_CONTAINER_DLL_remove (receiver->ss_head, receiver->ss_tail, ss);
1318  GNUNET_CONTAINER_DLL_insert (receiver->ss_head, receiver->ss_tail, ss);
1319  }
1320  return GNUNET_NO;
1321  }
1322  }
1323  return GNUNET_YES;
1324 }
1325 
1326 
1335 static void
1337  const void *buf,
1338  size_t buf_size)
1339 {
1340  const struct GNUNET_MessageHeader *hdr =
1341  (const struct GNUNET_MessageHeader *) buf;
1342  const struct UDPAck *ack = (const struct UDPAck *) buf;
1343  uint16_t type;
1344 
1345  if (sizeof(*hdr) > buf_size)
1346  return; /* not even a header */
1347  if (ntohs (hdr->size) > buf_size)
1348  return; /* not even a header */
1349  type = ntohs (hdr->type);
1350  switch (type)
1351  {
1353  /* lookup master secret by 'cmac', then update sequence_max */
1355  &sender->target,
1356  &handle_ack,
1357  (void *) ack);
1358  /* There could be more messages after the ACK, handle those as well */
1359  buf += ntohs (hdr->size);
1360  buf_size -= ntohs (hdr->size);
1361  pass_plaintext_to_core (sender, buf, buf_size);
1362  break;
1363 
1365  /* skip padding */
1366  break;
1367 
1368  default:
1369  pass_plaintext_to_core (sender, buf, buf_size);
1370  }
1371 }
1372 
1373 
1382 static void
1384 {
1385  GNUNET_assert (NULL != ss->sender);
1387  "Considering SS UDPAck %s\n",
1388  GNUNET_i2s_full (&ss->sender->target));
1389 
1390  /* drop ancient KeyCacheEntries */
1391  while ((NULL != ss->kce_head) &&
1392  (MAX_SQN_DELTA <
1394  kce_destroy (ss->kce_tail);
1395  if (ss->active_kce_count < KCN_THRESHOLD)
1396  {
1397  struct UDPAck ack;
1398 
1406  if (0 < ss->active_kce_count) {
1407  while (ss->active_kce_count < KCN_TARGET)
1408  kce_generate (ss, ++ss->sequence_allowed);
1409  } else {
1410  kce_generate (ss, ++ss->sequence_allowed);
1411  }
1413  ack.header.size = htons (sizeof(ack));
1414  ack.sequence_max = htonl (ss->sequence_allowed);
1415  ack.cmac = ss->cmac;
1417  "Notifying transport of UDPAck %s\n",
1418  GNUNET_i2s_full (&ss->sender->target));
1420  &ss->sender->target,
1422  &ack.header);
1423  }
1424 }
1425 
1426 
1434 static void
1435 decrypt_box (const struct UDPBox *box,
1436  size_t box_len,
1437  struct KeyCacheEntry *kce)
1438 {
1439  struct SharedSecret *ss = kce->ss;
1440  char out_buf[box_len - sizeof(*box)];
1441 
1442  GNUNET_assert (NULL != ss->sender);
1443  if (GNUNET_OK != try_decrypt (ss,
1444  box->gcm_tag,
1445  kce->sequence_number,
1446  (const char *) &box[1],
1447  sizeof(out_buf),
1448  out_buf))
1449  {
1450  GNUNET_STATISTICS_update (stats,
1451  "# Decryption failures with valid KCE",
1452  1,
1453  GNUNET_NO);
1454  kce_destroy (kce);
1455  return;
1456  }
1457  kce_destroy (kce);
1458  GNUNET_STATISTICS_update (stats,
1459  "# bytes decrypted with BOX",
1460  sizeof(out_buf),
1461  GNUNET_NO);
1462  try_handle_plaintext (ss->sender, out_buf, sizeof(out_buf));
1463  consider_ss_ack (ss);
1464 }
1465 
1466 
1470 struct SearchContext
1471 {
1475  const struct sockaddr *address;
1476 
1480  socklen_t address_len;
1481 
1486 };
1487 
1488 
1497 static int
1499  const struct GNUNET_PeerIdentity *key,
1500  void *value)
1501 {
1502  struct SearchContext *sc = cls;
1503  struct SenderAddress *sender = value;
1504 
1505  if ((sender->address_len == sc->address_len) &&
1506  (0 == memcmp (sender->address, sc->address, sender->address_len)))
1507  {
1508  sc->sender = sender;
1509  return GNUNET_NO; /* stop iterating! */
1510  }
1511  return GNUNET_YES;
1512 }
1513 
1514 
1526 static struct SenderAddress *
1528  const struct sockaddr *address,
1529  socklen_t address_len)
1530 {
1531  struct SenderAddress *sender;
1532  struct SearchContext sc = { .address = address,
1533  .address_len = address_len,
1534  .sender = NULL };
1535 
1537  target,
1539  &sc);
1540  if (NULL != sc.sender)
1541  {
1543  return sc.sender;
1544  }
1545  sender = GNUNET_new (struct SenderAddress);
1546  sender->target = *target;
1547  sender->address = GNUNET_memdup (address, address_len);
1548  sender->address_len = address_len;
1550  senders,
1551  &sender->target,
1552  sender,
1554  GNUNET_STATISTICS_set (stats,
1555  "# senders active",
1557  GNUNET_NO);
1558  sender->timeout =
1560  sender->hn = GNUNET_CONTAINER_heap_insert (senders_heap,
1561  sender,
1562  sender->timeout.abs_value_us);
1563  sender->nt = GNUNET_NT_scanner_get_type (is, address, address_len);
1564  if (NULL == timeout_task)
1565  timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts, NULL);
1566  return sender;
1567 }
1568 
1569 
1577 static int
1579  const struct UDPConfirmation *uc)
1580 {
1581  struct UdpHandshakeSignature uhs;
1582 
1584  uhs.purpose.size = htonl (sizeof(uhs));
1585  uhs.sender = uc->sender;
1586  uhs.receiver = my_identity;
1587  uhs.ephemeral = *ephemeral;
1588  uhs.monotonic_time = uc->monotonic_time;
1591  &uhs,
1592  &uc->sender_sig,
1593  &uc->sender.public_key);
1594 }
1595 
1596 
1605 static char *
1606 sockaddr_to_udpaddr_string (const struct sockaddr *address,
1607  socklen_t address_len)
1608 {
1609  char *ret;
1610 
1611  switch (address->sa_family)
1612  {
1613  case AF_INET:
1614  GNUNET_asprintf (&ret,
1615  "%s-%s",
1617  GNUNET_a2s (address, address_len));
1618  break;
1619 
1620  case AF_INET6:
1621  GNUNET_asprintf (&ret,
1622  "%s-%s",
1624  GNUNET_a2s (address, address_len));
1625  break;
1626 
1627  default:
1628  GNUNET_assert (0);
1629  }
1630  return ret;
1631 }
1632 
1633 
1639 static void
1640 sock_read (void *cls)
1641 {
1642  struct sockaddr_storage sa;
1643  socklen_t salen = sizeof(sa);
1644  char buf[UINT16_MAX];
1645  ssize_t rcvd;
1646 
1647  (void) cls;
1649  udp_sock,
1650  &sock_read,
1651  NULL);
1652  rcvd = GNUNET_NETWORK_socket_recvfrom (udp_sock,
1653  buf,
1654  sizeof(buf),
1655  (struct sockaddr *) &sa,
1656  &salen);
1657  if (-1 == rcvd)
1658  {
1660  return;
1661  }
1663  "Read %lu bytes\n", rcvd);
1664  /* first, see if it is a UDPBox */
1665  if (rcvd > sizeof(struct UDPBox))
1666  {
1667  const struct UDPBox *box;
1668  struct KeyCacheEntry *kce;
1669 
1670  box = (const struct UDPBox *) buf;
1671  kce = GNUNET_CONTAINER_multishortmap_get (key_cache, &box->kid);
1672  if (NULL != kce)
1673  {
1674  decrypt_box (box, (size_t) rcvd, kce);
1675  return;
1676  }
1677  }
1678 
1679  /* next, check if it is a broadcast */
1680  if (sizeof(struct UDPBroadcast) == rcvd)
1681  {
1682  const struct UDPBroadcast *ub;
1683  struct UdpBroadcastSignature uhs;
1684 
1685  ub = (const struct UDPBroadcast *) buf;
1687  uhs.purpose.size = htonl (sizeof(uhs));
1688  uhs.sender = ub->sender;
1689  GNUNET_CRYPTO_hash (&sa, salen, &uhs.h_address);
1690  if (GNUNET_OK ==
1692  &uhs,
1693  &ub->sender_sig,
1694  &ub->sender.public_key))
1695  {
1696  char *addr_s;
1697  enum GNUNET_NetworkType nt;
1698 
1699  addr_s =
1700  sockaddr_to_udpaddr_string ((const struct sockaddr *) &sa, salen);
1701  GNUNET_STATISTICS_update (stats, "# broadcasts received", 1, GNUNET_NO);
1702  /* use our own mechanism to determine network type */
1703  nt =
1704  GNUNET_NT_scanner_get_type (is, (const struct sockaddr *) &sa, salen);
1705  GNUNET_TRANSPORT_application_validate (ah, &ub->sender, nt, addr_s);
1706  GNUNET_free (addr_s);
1707  return;
1708  }
1709  /* continue with KX, mostly for statistics... */
1710  }
1711 
1712 
1713  /* finally, test if it is a KX */
1714  if (rcvd < sizeof(struct UDPConfirmation) + sizeof(struct InitialKX))
1715  {
1716  GNUNET_STATISTICS_update (stats,
1717  "# messages dropped (no kid, too small for KX)",
1718  1,
1719  GNUNET_NO);
1720  return;
1721  }
1723  "Got KX\n");
1724  {
1725  const struct InitialKX *kx;
1726  struct SharedSecret *ss;
1727  char pbuf[rcvd - sizeof(struct InitialKX)];
1728  const struct UDPConfirmation *uc;
1729  struct SenderAddress *sender;
1730 
1731  kx = (const struct InitialKX *) buf;
1732  ss = setup_shared_secret_dec (&kx->ephemeral);
1734  "Before DEC\n");
1735 
1736  if (GNUNET_OK != try_decrypt (ss,
1737  kx->gcm_tag,
1738  0,
1739  &buf[sizeof(*kx)],
1740  sizeof(pbuf),
1741  pbuf))
1742  {
1744  "Unable to decrypt tag, dropping...\n");
1745  GNUNET_free (ss);
1747  stats,
1748  "# messages dropped (no kid, AEAD decryption failed)",
1749  1,
1750  GNUNET_NO);
1751  return;
1752  }
1754  "Before VERIFY\n");
1755 
1756  uc = (const struct UDPConfirmation *) pbuf;
1757  if (GNUNET_OK != verify_confirmation (&kx->ephemeral, uc))
1758  {
1759  GNUNET_break_op (0);
1760  GNUNET_free (ss);
1761  GNUNET_STATISTICS_update (stats,
1762  "# messages dropped (sender signature invalid)",
1763  1,
1764  GNUNET_NO);
1765  return;
1766  }
1768  "Before SETUP_SENDER\n");
1769 
1770  calculate_cmac (ss);
1771  sender = setup_sender (&uc->sender, (const struct sockaddr *) &sa, salen);
1772  ss->sender = sender;
1773  GNUNET_CONTAINER_DLL_insert (sender->ss_head, sender->ss_tail, ss);
1774  sender->num_secrets++;
1775  GNUNET_STATISTICS_update (stats, "# Secrets active", 1, GNUNET_NO);
1776  GNUNET_STATISTICS_update (stats,
1777  "# messages decrypted without BOX",
1778  1,
1779  GNUNET_NO);
1780  try_handle_plaintext (sender, &uc[1], sizeof(pbuf) - sizeof(*uc));
1781  consider_ss_ack (ss);
1782  if (sender->num_secrets > MAX_SECRETS)
1783  secret_destroy (sender->ss_tail);
1784  }
1785 }
1786 
1787 
1795 static struct sockaddr *
1796 udp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
1797 {
1798  struct sockaddr *in;
1799  unsigned int port;
1800  char dummy[2];
1801  char *colon;
1802  char *cp;
1803 
1804  if (1 == sscanf (bindto, "%u%1s", &port, dummy))
1805  {
1806  /* interpreting value as just a PORT number */
1807  if (port > UINT16_MAX)
1808  {
1810  "BINDTO specification `%s' invalid: value too large for port\n",
1811  bindto);
1812  return NULL;
1813  }
1814  if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
1815  (GNUNET_YES ==
1818  "DISABLE_V6")))
1819  {
1820  struct sockaddr_in *i4;
1821 
1822  i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
1823  i4->sin_family = AF_INET;
1824  i4->sin_port = htons ((uint16_t) port);
1825  *sock_len = sizeof(struct sockaddr_in);
1826  in = (struct sockaddr *) i4;
1827  }
1828  else
1829  {
1830  struct sockaddr_in6 *i6;
1831 
1832  i6 = GNUNET_malloc (sizeof(struct sockaddr_in6));
1833  i6->sin6_family = AF_INET6;
1834  i6->sin6_port = htons ((uint16_t) port);
1835  *sock_len = sizeof(struct sockaddr_in6);
1836  in = (struct sockaddr *) i6;
1837  }
1838  return in;
1839  }
1840  cp = GNUNET_strdup (bindto);
1841  colon = strrchr (cp, ':');
1842  if (NULL != colon)
1843  {
1844  /* interpet value after colon as port */
1845  *colon = '\0';
1846  colon++;
1847  if (1 == sscanf (colon, "%u%1s", &port, dummy))
1848  {
1849  /* interpreting value as just a PORT number */
1850  if (port > UINT16_MAX)
1851  {
1853  "BINDTO specification `%s' invalid: value too large for port\n",
1854  bindto);
1855  GNUNET_free (cp);
1856  return NULL;
1857  }
1858  }
1859  else
1860  {
1861  GNUNET_log (
1863  "BINDTO specification `%s' invalid: last ':' not followed by number\n",
1864  bindto);
1865  GNUNET_free (cp);
1866  return NULL;
1867  }
1868  }
1869  else
1870  {
1871  /* interpret missing port as 0, aka pick any free one */
1872  port = 0;
1873  }
1874  {
1875  /* try IPv4 */
1876  struct sockaddr_in v4;
1877  if (1 == inet_pton (AF_INET, cp, &v4.sin_addr))
1878  {
1879  v4.sin_family = AF_INET;
1880  v4.sin_port = htons ((uint16_t) port);
1881 #if HAVE_SOCKADDR_IN_SIN_LEN
1882  v4.sin_len = sizeof(struct sockaddr_in);
1883 #endif
1884  in = GNUNET_memdup (&v4, sizeof(struct sockaddr_in));
1885  *sock_len = sizeof(struct sockaddr_in);
1886  GNUNET_free (cp);
1887  return in;
1888  }
1889  }
1890  {
1891  /* try IPv6 */
1892  struct sockaddr_in6 v6;
1893  const char *start;
1894 
1895  start = cp;
1896  if (('[' == *cp) && (']' == cp[strlen (cp) - 1]))
1897  {
1898  start++; /* skip over '[' */
1899  cp[strlen (cp) - 1] = '\0'; /* eat ']' */
1900  }
1901  if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
1902  {
1903  v6.sin6_family = AF_INET6;
1904  v6.sin6_port = htons ((uint16_t) port);
1905 #if HAVE_SOCKADDR_IN_SIN_LEN
1906  v6.sin6_len = sizeof(sizeof(struct sockaddr_in6));
1907 #endif
1908  in = GNUNET_memdup (&v6, sizeof(v6));
1909  *sock_len = sizeof(v6);
1910  GNUNET_free (cp);
1911  return in;
1912  }
1913  }
1914  /* #5528 FIXME (feature!): maybe also try getnameinfo()? */
1915  GNUNET_free (cp);
1916  return NULL;
1917 }
1918 
1919 
1927 static void
1928 do_pad (gcry_cipher_hd_t out_cipher, char *dgram, size_t pad_size)
1929 {
1930  char pad[pad_size];
1931 
1933  if (sizeof(pad) > sizeof(struct GNUNET_MessageHeader))
1934  {
1935  struct GNUNET_MessageHeader hdr =
1936  { .size = htons (sizeof(pad)),
1937  .type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD) };
1938 
1939  memcpy (pad, &hdr, sizeof(hdr));
1940  }
1941  GNUNET_assert (
1942  0 ==
1943  gcry_cipher_encrypt (out_cipher, dgram, sizeof(pad), pad, sizeof(pad)));
1944 }
1945 
1946 
1955 static void
1957  const struct GNUNET_MessageHeader *msg,
1958  void *impl_state)
1959 {
1960  struct ReceiverAddress *receiver = impl_state;
1961  uint16_t msize = ntohs (msg->size);
1962  struct UdpHandshakeSignature uhs;
1963  struct UDPConfirmation uc;
1964  struct InitialKX kx;
1965  struct GNUNET_CRYPTO_EcdhePrivateKey epriv;
1966  char dgram[receiver->kx_mtu + sizeof(uc) + sizeof(kx)];
1967  size_t dpos;
1968  gcry_cipher_hd_t out_cipher;
1969  struct SharedSecret *ss;
1970 
1971 
1972  GNUNET_assert (mq == receiver->kx_mq);
1973  if (msize > receiver->kx_mtu)
1974  {
1975  GNUNET_break (0);
1976  receiver_destroy (receiver);
1977  return;
1978  }
1979  reschedule_receiver_timeout (receiver);
1980 
1981  /* setup key material */
1983 
1984  ss = setup_shared_secret_enc (&epriv, receiver);
1985  setup_cipher (&ss->master, 0, &out_cipher);
1986  /* compute 'uc' */
1987  uc.sender = my_identity;
1988  uc.monotonic_time =
1991  uhs.purpose.size = htonl (sizeof(uhs));
1992  uhs.sender = my_identity;
1993  uhs.receiver = receiver->target;
1995  uhs.monotonic_time = uc.monotonic_time;
1996  GNUNET_CRYPTO_eddsa_sign (my_private_key,
1997  &uhs,
1998  &uc.sender_sig);
1999  /* Leave space for kx */
2000  dpos = sizeof(kx);
2001  /* Append encrypted uc to dgram */
2002  GNUNET_assert (0 == gcry_cipher_encrypt (out_cipher,
2003  &dgram[dpos],
2004  sizeof(uc),
2005  &uc,
2006  sizeof(uc)));
2007  dpos += sizeof(uc);
2008  /* Append encrypted payload to dgram */
2009  GNUNET_assert (
2010  0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize));
2011  dpos += msize;
2012  do_pad (out_cipher, &dgram[dpos], sizeof(dgram) - dpos);
2013  /* Datagram starts with kx */
2014  kx.ephemeral = uhs.ephemeral;
2015  GNUNET_assert (
2016  0 == gcry_cipher_gettag (out_cipher, kx.gcm_tag, sizeof(kx.gcm_tag)));
2017  gcry_cipher_close (out_cipher);
2018  memcpy (dgram, &kx, sizeof(kx));
2019  if (-1 == GNUNET_NETWORK_socket_sendto (udp_sock,
2020  dgram,
2021  sizeof(dgram),
2022  receiver->address,
2023  receiver->address_len))
2026  "Sending KX to %s\n", GNUNET_a2s (receiver->address,
2027  receiver->address_len));
2029 }
2030 
2031 
2040 static void
2042  const struct GNUNET_MessageHeader *msg,
2043  void *impl_state)
2044 {
2045  struct ReceiverAddress *receiver = impl_state;
2046  uint16_t msize = ntohs (msg->size);
2047 
2048  GNUNET_assert (mq == receiver->d_mq);
2049  if ((msize > receiver->d_mtu) ||
2050  (0 == receiver->acks_available))
2051  {
2052  GNUNET_break (0);
2053  receiver_destroy (receiver);
2054  return;
2055  }
2056  reschedule_receiver_timeout (receiver);
2057 
2058  /* begin "BOX" encryption method, scan for ACKs from tail! */
2059  for (struct SharedSecret *ss = receiver->ss_tail; NULL != ss; ss = ss->prev)
2060  {
2061  if (ss->sequence_used >= ss->sequence_allowed)
2062  {
2063  continue;
2064  }
2065  char dgram[sizeof(struct UDPBox) + receiver->d_mtu];
2066  struct UDPBox *box;
2067  gcry_cipher_hd_t out_cipher;
2068  size_t dpos;
2069 
2070  box = (struct UDPBox *) dgram;
2071  ss->sequence_used++;
2072  get_kid (&ss->master, ss->sequence_used, &box->kid);
2073  setup_cipher (&ss->master, ss->sequence_used, &out_cipher);
2074  /* Append encrypted payload to dgram */
2075  dpos = sizeof(struct UDPBox);
2076  GNUNET_assert (
2077  0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize));
2078  dpos += msize;
2079  do_pad (out_cipher, &dgram[dpos], sizeof(dgram) - dpos);
2080  GNUNET_assert (0 == gcry_cipher_gettag (out_cipher,
2081  box->gcm_tag,
2082  sizeof(box->gcm_tag)));
2083  gcry_cipher_close (out_cipher);
2084  if (-1 == GNUNET_NETWORK_socket_sendto (udp_sock,
2085  dgram,
2086  sizeof(dgram),
2087  receiver->address,
2088  receiver->address_len))
2091  receiver->acks_available--;
2092  if (0 == receiver->acks_available)
2093  {
2094  /* We have no more ACKs */
2096  "No more acks\n");
2097  }
2098  return;
2099  }
2100 }
2101 
2102 
2111 static void
2112 mq_destroy_d (struct GNUNET_MQ_Handle *mq, void *impl_state)
2113 {
2114  struct ReceiverAddress *receiver = impl_state;
2116  "Default MQ destroyed\n");
2117  if (mq == receiver->d_mq)
2118  {
2119  receiver->d_mq = NULL;
2120  receiver_destroy (receiver);
2121  }
2122 }
2123 
2124 
2133 static void
2134 mq_destroy_kx (struct GNUNET_MQ_Handle *mq, void *impl_state)
2135 {
2136  struct ReceiverAddress *receiver = impl_state;
2138  "KX MQ destroyed\n");
2139  if (mq == receiver->kx_mq)
2140  {
2141  receiver->kx_mq = NULL;
2142  receiver_destroy (receiver);
2143  }
2144 }
2145 
2146 
2153 static void
2154 mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
2155 {
2156  /* Cancellation is impossible with UDP; bail */
2157  GNUNET_assert (0);
2158 }
2159 
2160 
2170 static void
2171 mq_error (void *cls, enum GNUNET_MQ_Error error)
2172 {
2173  struct ReceiverAddress *receiver = cls;
2174 
2176  "MQ error in queue to %s: %d\n",
2177  GNUNET_i2s (&receiver->target),
2178  (int) error);
2179  receiver_destroy (receiver);
2180 }
2181 
2182 
2190 static void
2192 {
2193  size_t base_mtu;
2194 
2195  /*if (NULL != receiver->kx_qh)
2196  {
2197  GNUNET_TRANSPORT_communicator_mq_del (receiver->kx_qh);
2198  receiver->kx_qh = NULL;
2199  }
2200  if (NULL != receiver->d_qh)
2201  {
2202  GNUNET_TRANSPORT_communicator_mq_del (receiver->d_qh);
2203  receiver->d_qh = NULL;
2204  }*/
2205  // GNUNET_assert (NULL == receiver->mq);
2206  switch (receiver->address->sa_family)
2207  {
2208  case AF_INET:
2209  base_mtu = 1480 /* Ethernet MTU, 1500 - Ethernet header - VLAN tag */
2210  - sizeof(struct GNUNET_TUN_IPv4Header) /* 20 */
2211  - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */;
2212  break;
2213 
2214  case AF_INET6:
2215  base_mtu = 1280 /* Minimum MTU required by IPv6 */
2216  - sizeof(struct GNUNET_TUN_IPv6Header) /* 40 */
2217  - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */;
2218  break;
2219 
2220  default:
2221  GNUNET_assert (0);
2222  break;
2223  }
2224  /* MTU based on full KX messages */
2225  receiver->kx_mtu = base_mtu - sizeof(struct InitialKX) /* 48 */
2226  - sizeof(struct UDPConfirmation); /* 104 */
2227  /* MTU based on BOXed messages */
2228  receiver->d_mtu = base_mtu - sizeof(struct UDPBox);
2229 
2231  "Setting up MQs and QHs\n");
2232  /* => Effective MTU for CORE will range from 1080 (IPv6 + KX) to
2233  1404 (IPv4 + Box) bytes, depending on circumstances... */
2234  if (NULL == receiver->kx_mq)
2236  &mq_destroy_kx,
2237  &mq_cancel,
2238  receiver,
2239  NULL,
2240  &mq_error,
2241  receiver);
2242  if (NULL == receiver->d_mq)
2244  &mq_destroy_d,
2245  &mq_cancel,
2246  receiver,
2247  NULL,
2248  &mq_error,
2249  receiver);
2250 
2251  receiver->kx_qh =
2253  &receiver->target,
2254  receiver->foreign_addr,
2255  receiver->kx_mtu,
2257  0, /* Priority */
2258  receiver->nt,
2260  receiver->kx_mq);
2261  receiver->d_qh =
2263  &receiver->target,
2264  receiver->foreign_addr,
2265  receiver->d_mtu,
2266  0, /* Initialize with 0 acks */
2267  1, /* Priority */
2268  receiver->nt,
2270  receiver->d_mq);
2271 
2272 }
2273 
2274 
2293 static int
2294 mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
2295 {
2296  struct ReceiverAddress *receiver;
2297  const char *path;
2298  struct sockaddr *in;
2299  socklen_t in_len;
2300 
2301  if (0 != strncmp (address,
2303  strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
2304  {
2305  GNUNET_break_op (0);
2306  return GNUNET_SYSERR;
2307  }
2308  path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
2309  in = udp_address_to_sockaddr (path, &in_len);
2310 
2311  receiver = GNUNET_new (struct ReceiverAddress);
2312  receiver->address = in;
2313  receiver->address_len = in_len;
2314  receiver->target = *peer;
2315  receiver->nt = GNUNET_NT_scanner_get_type (is, in, in_len);
2317  receivers,
2318  &receiver->target,
2319  receiver,
2322  "Added %s to receivers\n",
2323  GNUNET_i2s_full (&receiver->target));
2324  receiver->timeout =
2326  receiver->hn = GNUNET_CONTAINER_heap_insert (receivers_heap,
2327  receiver,
2328  receiver->timeout.abs_value_us);
2329  GNUNET_STATISTICS_set (stats,
2330  "# receivers active",
2332  GNUNET_NO);
2333  receiver->foreign_addr =
2334  sockaddr_to_udpaddr_string (receiver->address, receiver->address_len);
2335  setup_receiver_mq (receiver);
2336  if (NULL == timeout_task)
2337  timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts, NULL);
2338  return GNUNET_OK;
2339 }
2340 
2341 
2350 static int
2352  const struct GNUNET_PeerIdentity *target,
2353  void *value)
2354 {
2355  struct ReceiverAddress *receiver = value;
2356 
2357  (void) cls;
2358  (void) target;
2359  receiver_destroy (receiver);
2360  return GNUNET_OK;
2361 }
2362 
2363 
2372 static int
2374  const struct GNUNET_PeerIdentity *target,
2375  void *value)
2376 {
2377  struct SenderAddress *sender = value;
2378 
2379  (void) cls;
2380  (void) target;
2381  sender_destroy (sender);
2382  return GNUNET_OK;
2383 }
2384 
2385 
2391 static void
2392 do_shutdown (void *cls)
2393 {
2394  if (NULL != nat)
2395  {
2396  GNUNET_NAT_unregister (nat);
2397  nat = NULL;
2398  }
2399  while (NULL != bi_head)
2400  bi_destroy (bi_head);
2401  if (NULL != broadcast_task)
2402  {
2403  GNUNET_SCHEDULER_cancel (broadcast_task);
2404  broadcast_task = NULL;
2405  }
2406  if (NULL != read_task)
2407  {
2408  GNUNET_SCHEDULER_cancel (read_task);
2409  read_task = NULL;
2410  }
2411  if (NULL != udp_sock)
2412  {
2414  udp_sock = NULL;
2415  }
2418  NULL);
2423  GNUNET_CONTAINER_heap_destroy (senders_heap);
2424  GNUNET_CONTAINER_heap_destroy (receivers_heap);
2425  if (NULL != ch)
2426  {
2428  ch = NULL;
2429  }
2430  if (NULL != ah)
2431  {
2433  ah = NULL;
2434  }
2435  if (NULL != stats)
2436  {
2438  stats = NULL;
2439  }
2440  if (NULL != my_private_key)
2441  {
2442  GNUNET_free (my_private_key);
2443  my_private_key = NULL;
2444  }
2445  if (NULL != is)
2446  {
2448  is = NULL;
2449  }
2450 }
2451 
2452 
2462 static void
2463 enc_notify_cb (void *cls,
2464  const struct GNUNET_PeerIdentity *sender,
2465  const struct GNUNET_MessageHeader *msg)
2466 {
2467  const struct UDPAck *ack;
2468 
2469  (void) cls;
2471  "Storing UDPAck received from backchannel from %s\n",
2472  GNUNET_i2s_full (sender));
2473  if ((ntohs (msg->type) != GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK) ||
2474  (ntohs (msg->size) != sizeof(struct UDPAck)))
2475  {
2476  GNUNET_break_op (0);
2477  return;
2478  }
2479  ack = (const struct UDPAck *) msg;
2481  sender,
2482  &handle_ack,
2483  (void *) ack);
2484 }
2485 
2486 
2500 static void
2501 nat_address_cb (void *cls,
2502  void **app_ctx,
2503  int add_remove,
2505  const struct sockaddr *addr,
2506  socklen_t addrlen)
2507 {
2508  char *my_addr;
2510 
2511  if (GNUNET_YES == add_remove)
2512  {
2513  enum GNUNET_NetworkType nt;
2514 
2515  GNUNET_asprintf (&my_addr,
2516  "%s-%s",
2518  GNUNET_a2s (addr, addrlen));
2519  nt = GNUNET_NT_scanner_get_type (is, addr, addrlen);
2520  ai =
2522  my_addr,
2523  nt,
2525  GNUNET_free (my_addr);
2526  *app_ctx = ai;
2527  }
2528  else
2529  {
2530  ai = *app_ctx;
2532  *app_ctx = NULL;
2533  }
2534 }
2535 
2536 
2542 static void
2543 ifc_broadcast (void *cls)
2544 {
2545  struct BroadcastInterface *bi = cls;
2546  struct GNUNET_TIME_Relative delay;
2547 
2548  delay = BROADCAST_FREQUENCY;
2549  delay.rel_value_us =
2551  bi->broadcast_task =
2553 
2554  switch (bi->sa->sa_family)
2555  {
2556  case AF_INET: {
2557  static int yes = 1;
2558  static int no = 0;
2559  ssize_t sent;
2560 
2562  SOL_SOCKET,
2563  SO_BROADCAST,
2564  &yes,
2565  sizeof(int)))
2567  sent = GNUNET_NETWORK_socket_sendto (udp_sock,
2568  &bi->bcm,
2569  sizeof(bi->bcm),
2570  bi->ba,
2571  bi->salen);
2572  if (-1 == sent)
2575  SOL_SOCKET,
2576  SO_BROADCAST,
2577  &no,
2578  sizeof(int)))
2580  break;
2581  }
2582 
2583  case AF_INET6: {
2584  ssize_t sent;
2585  struct sockaddr_in6 dst;
2586 
2587  dst.sin6_family = AF_INET6;
2588  dst.sin6_port = htons (my_port);
2589  dst.sin6_addr = bi->mcreq.ipv6mr_multiaddr;
2590  dst.sin6_scope_id = ((struct sockaddr_in6 *) bi->ba)->sin6_scope_id;
2591 
2592  sent = GNUNET_NETWORK_socket_sendto (udp_sock,
2593  &bi->bcm,
2594  sizeof(bi->bcm),
2595  (const struct sockaddr *) &dst,
2596  sizeof(dst));
2597  if (-1 == sent)
2599  break;
2600  }
2601 
2602  default:
2603  GNUNET_break (0);
2604  break;
2605  }
2606 }
2607 
2608 
2623 static int
2624 iface_proc (void *cls,
2625  const char *name,
2626  int isDefault,
2627  const struct sockaddr *addr,
2628  const struct sockaddr *broadcast_addr,
2629  const struct sockaddr *netmask,
2630  socklen_t addrlen)
2631 {
2632  struct BroadcastInterface *bi;
2633  enum GNUNET_NetworkType network;
2634  struct UdpBroadcastSignature ubs;
2635 
2636  (void) cls;
2637  (void) netmask;
2638  if (NULL == addr)
2639  return GNUNET_YES; /* need to know our address! */
2640  network = GNUNET_NT_scanner_get_type (is, addr, addrlen);
2641  if (GNUNET_NT_LOOPBACK == network)
2642  {
2643  /* Broadcasting on loopback does not make sense */
2644  return GNUNET_YES;
2645  }
2646  for (bi = bi_head; NULL != bi; bi = bi->next)
2647  {
2648  if ((bi->salen == addrlen) && (0 == memcmp (addr, bi->sa, addrlen)))
2649  {
2650  bi->found = GNUNET_YES;
2651  return GNUNET_OK;
2652  }
2653  }
2654 
2655  if ((AF_INET6 == addr->sa_family) && (NULL == broadcast_addr))
2656  return GNUNET_OK; /* broadcast_addr is required for IPv6! */
2657  if ((AF_INET6 == addr->sa_family) && (GNUNET_YES != have_v6_socket))
2658  return GNUNET_OK; /* not using IPv6 */
2659 
2660  bi = GNUNET_new (struct BroadcastInterface);
2661  bi->sa = GNUNET_memdup (addr, addrlen);
2662  if (NULL != broadcast_addr)
2663  bi->ba = GNUNET_memdup (broadcast_addr, addrlen);
2664  bi->salen = addrlen;
2665  bi->found = GNUNET_YES;
2666  bi->bcm.sender = my_identity;
2668  ubs.purpose.size = htonl (sizeof(ubs));
2669  ubs.sender = my_identity;
2670  GNUNET_CRYPTO_hash (addr, addrlen, &ubs.h_address);
2671  GNUNET_CRYPTO_eddsa_sign (my_private_key,
2672  &ubs,
2673  &bi->bcm.sender_sig);
2674  if (NULL != broadcast_addr)
2675  {
2677  GNUNET_CONTAINER_DLL_insert (bi_head, bi_tail, bi);
2678  }
2679  if ((AF_INET6 == addr->sa_family) && (NULL != broadcast_addr))
2680  {
2681  /* Create IPv6 multicast request */
2682  const struct sockaddr_in6 *s6 =
2683  (const struct sockaddr_in6 *) broadcast_addr;
2684 
2685  GNUNET_assert (
2686  1 == inet_pton (AF_INET6, "FF05::13B", &bi->mcreq.ipv6mr_multiaddr));
2687 
2688  /* http://tools.ietf.org/html/rfc2553#section-5.2:
2689  *
2690  * IPV6_JOIN_GROUP
2691  *
2692  * Join a multicast group on a specified local interface. If the
2693  * interface index is specified as 0, the kernel chooses the local
2694  * interface. For example, some kernels look up the multicast
2695  * group in the normal IPv6 routing table and using the resulting
2696  * interface; we do this for each interface, so no need to use
2697  * zero (anymore...).
2698  */bi->mcreq.ipv6mr_interface = s6->sin6_scope_id;
2699 
2700  /* Join the multicast group */
2702  IPPROTO_IPV6,
2703  IPV6_JOIN_GROUP,
2704  &bi->mcreq,
2705  sizeof(bi->mcreq)))
2706  {
2708  }
2709  }
2710  return GNUNET_OK;
2711 }
2712 
2713 
2719 static void
2720 do_broadcast (void *cls)
2721 {
2722  struct BroadcastInterface *bin;
2723 
2724  (void) cls;
2725  for (struct BroadcastInterface *bi = bi_head; NULL != bi; bi = bi->next)
2726  bi->found = GNUNET_NO;
2728  for (struct BroadcastInterface *bi = bi_head; NULL != bi; bi = bin)
2729  {
2730  bin = bi->next;
2731  if (GNUNET_NO == bi->found)
2732  bi_destroy (bi);
2733  }
2735  &do_broadcast,
2736  NULL);
2737 }
2738 
2739 
2748 static void
2749 run (void *cls,
2750  char *const *args,
2751  const char *cfgfile,
2752  const struct GNUNET_CONFIGURATION_Handle *c)
2753 {
2754  char *bindto;
2755  struct sockaddr *in;
2756  socklen_t in_len;
2757  struct sockaddr_storage in_sto;
2758  socklen_t sto_len;
2759 
2760  (void) cls;
2761  cfg = c;
2762  if (GNUNET_OK !=
2765  "BINDTO",
2766  &bindto))
2767  {
2770  "BINDTO");
2771  return;
2772  }
2773 
2774  in = udp_address_to_sockaddr (bindto, &in_len);
2775  if (NULL == in)
2776  {
2778  "Failed to setup UDP socket address with path `%s'\n",
2779  bindto);
2780  GNUNET_free (bindto);
2781  return;
2782  }
2783  udp_sock =
2784  GNUNET_NETWORK_socket_create (in->sa_family, SOCK_DGRAM, IPPROTO_UDP);
2785  if (NULL == udp_sock)
2786  {
2788  GNUNET_free (in);
2789  GNUNET_free (bindto);
2790  return;
2791  }
2792  if (AF_INET6 == in->sa_family)
2794  if (GNUNET_OK != GNUNET_NETWORK_socket_bind (udp_sock, in, in_len))
2795  {
2797  GNUNET_NETWORK_socket_close (udp_sock);
2798  udp_sock = NULL;
2799  GNUNET_free (in);
2800  GNUNET_free (bindto);
2801  return;
2802  }
2803 
2804  /* We might have bound to port 0, allowing the OS to figure it out;
2805  thus, get the real IN-address from the socket */
2806  sto_len = sizeof(in_sto);
2807  if (0 != getsockname (GNUNET_NETWORK_get_fd (udp_sock),
2808  (struct sockaddr *) &in_sto,
2809  &sto_len))
2810  {
2811  memcpy (&in_sto, in, in_len);
2812  sto_len = in_len;
2813  }
2814  GNUNET_free (in);
2815  GNUNET_free (bindto);
2816  in = (struct sockaddr *) &in_sto;
2817  in_len = sto_len;
2819  "Bound to `%s'\n",
2820  GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len));
2821  switch (in->sa_family)
2822  {
2823  case AF_INET:
2824  my_port = ntohs (((struct sockaddr_in *) in)->sin_port);
2825  break;
2826 
2827  case AF_INET6:
2828  my_port = ntohs (((struct sockaddr_in6 *) in)->sin6_port);
2829  break;
2830 
2831  default:
2832  GNUNET_break (0);
2833  my_port = 0;
2834  }
2835  stats = GNUNET_STATISTICS_create ("C-UDP", cfg);
2839  receivers_heap =
2843  is = GNUNET_NT_scanner_init ();
2845  if (NULL == my_private_key)
2846  {
2847  GNUNET_log (
2849  _ (
2850  "Transport service is lacking key configuration settings. Exiting.\n"));
2852  return;
2853  }
2855  /* start reading */
2857  udp_sock,
2858  &sock_read,
2859  NULL);
2864  &mq_init,
2865  NULL,
2866  &enc_notify_cb,
2867  NULL);
2868  if (NULL == ch)
2869  {
2870  GNUNET_break (0);
2872  return;
2873  }
2875  if (NULL == ah)
2876  {
2877  GNUNET_break (0);
2879  return;
2880  }
2881  /* start broadcasting */
2882  if (GNUNET_YES !=
2885  "DISABLE_BROADCAST"))
2886  {
2887  broadcast_task = GNUNET_SCHEDULER_add_now (&do_broadcast, NULL);
2888  }
2889  nat = GNUNET_NAT_register (cfg,
2891  IPPROTO_UDP,
2892  1 /* one address */,
2893  (const struct sockaddr **) &in,
2894  &in_len,
2895  &nat_address_cb,
2896  NULL /* FIXME: support reversal: #5529 */,
2897  NULL /* closure */);
2898 }
2899 
2900 
2908 int
2909 main (int argc, char *const *argv)
2910 {
2911  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
2913  };
2914  int ret;
2915 
2916  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
2917  return 2;
2918 
2919  ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc,
2920  argv,
2921  "gnunet-communicator-udp",
2922  _ ("GNUnet UDP communicator"),
2923  options,
2924  &run,
2925  NULL))
2926  ? 0
2927  : 1;
2928  GNUNET_free_nz ((void *) argv);
2929  return ret;
2930 }
2931 
2932 
2933 /* end of gnunet-communicator-udp.c */
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
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. ...
struct KeyCacheEntry * next
Kept in a DLL.
Handle to the interface scanner.
Definition: nt.c:110
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:883
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD
UDP communicator padding.
int GNUNET_NETWORK_get_fd(const struct GNUNET_NETWORK_Handle *desc)
Return file descriptor for this network handle.
Definition: network.c:1080
#define COMMUNICATOR_CONFIG_SECTION
Configuration section used by the communicator.
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:314
static void mq_destroy_d(struct GNUNET_MQ_Handle *mq, void *impl_state)
Signature of functions implementing the destruction of a message queue.
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.
static struct BroadcastInterface * bi_tail
Broadcast interface tasks.
static void consider_ss_ack(struct SharedSecret *ss)
We established a shared secret with a sender.
struct SharedSecret * ss_tail
Shared secrets we used with target, last used is tail.
Handle for active NAT registrations.
Definition: nat_api.c:71
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK.
#define BROADCAST_FREQUENCY
How often do we broadcast our presence on the LAN?
struct GNUNET_PeerIdentity sender
Identity of the inititor of the UDP connection (UDP client).
int main(int argc, char *const *argv)
The main function for the UNIX communicator.
struct KeyCacheEntry * prev
Kept in a DLL.
int found
Was this interface found in the last iface_proc() scan?
static void do_broadcast(void *cls)
Scan interfaces to broadcast our presence on the LAN.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static struct GNUNET_TRANSPORT_ApplicationHandle * ah
Our handle to report addresses for validation to TRANSPORT.
GNUNET_NAT_AddressClass
Some addresses contain sensitive information or are not suitable for global distribution.
uint64_t rel_value_us
The actual value.
#define GNUNET_CRYPTO_eddsa_sign(priv, ps, sig)
EdDSA sign a given block.
struct GNUNET_PeerIdentity sender
Sender&#39;s peer identity.
struct KeyCacheEntry * kce_head
Kept in a DLL, sorted by sequence number.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
static uint16_t my_port
Port number to which we are actually bound.
Broadcast by peer in LAN announcing its presence.
unsigned int GNUNET_CONTAINER_multishortmap_size(const struct GNUNET_CONTAINER_MultiShortmap *map)
Get the number of key-value pairs in the map.
static struct SenderAddress * setup_sender(const struct GNUNET_PeerIdentity *target, const struct sockaddr *address, socklen_t address_len)
Create sender address for target.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK
UDP KX acknowledgement.
struct GNUNET_PeerIdentity receiver
Presumed identity of the target of the UDP connection (UDP server)
static struct GNUNET_NAT_Handle * nat
Connection to NAT service.
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.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Setup communicator and launch network interactions.
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
char gcm_tag[(128/8)]
HMAC for the following encrypted message, using GCM.
#define KCN_TARGET
How many KCNs do we keep around after we hit the KCN_THRESHOLD? Should be larger than KCN_THRESHOLD s...
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...
static struct GNUNET_PeerIdentity my_identity
Our public key.
struct GNUNET_HashCode cmac
CMAC is used to identify master in ACKs.
static struct SharedSecret * setup_shared_secret_dec(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral)
Setup shared secret for decryption.
GNUNET_MQ_Error
Error codes for the queue.
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Random on unsigned 64-bit values.
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, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1331
char gcm_tag[(128/8)]
128-bit authentication tag for the following encrypted message, from GCM.
socklen_t address_len
Number of bytes in address.
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
struct GNUNET_CONTAINER_HeapNode * hn
Entry in sender expiration heap.
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1458
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...
static struct sockaddr * udp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
Convert UDP bind specification to a struct sockaddr *
struct GNUNET_CRYPTO_EcdhePublicKey ephemeral
Ephemeral key for KX.
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:246
static void secret_destroy(struct SharedSecret *ss)
Destroy ss and associated key cache entries.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Bandwidth allocation API for applications to interact with.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST.
static struct GNUNET_CONTAINER_MultiShortmap * key_cache
Cache of pre-generated key IDs.
static struct BroadcastInterface * bi_head
Broadcast interface tasks.
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...
socklen_t address_len
Length of the address.
struct sockaddr * address
Address of the other peer.
int 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:485
static struct GNUNET_FS_UnindexContext * uc
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
unsigned int num_secrets
Length of the DLL at ss_head.
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.
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
struct SharedSecret * ss
Corresponding shared secret.
int 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.
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
int 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:320
Standard IPv4 header.
static void kce_destroy(struct KeyCacheEntry *kce)
Free memory used by key cache entry.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Definition of a command line option.
struct SenderAddress * sender
Sender we use this shared secret with, or NULL.
void GNUNET_OS_network_interfaces_list(GNUNET_OS_NetworkInterfaceProcessor proc, void *proc_cls)
Enumerate all network interfaces.
Definition: os_network.c:396
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 int have_v6_socket
GNUNET_YES if udp_sock supports IPv6.
#define GCM_TAG_SIZE
Size of the GCM tag.
struct GNUNET_TIME_Absolute timeout
Timeout for this sender.
static int handle_ack(void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
We received an ACK for pid.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
Encrypted continuation of UDP initial handshake, followed by message header with payload.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE
Signature used by UDP communicator handshake.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531
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).
Handle for the service.
#define GNUNET_CRYPTO_eddsa_verify(purp, ps, sig, pub)
Verify EdDSA signature.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
void GNUNET_TRANSPORT_application_done(struct GNUNET_TRANSPORT_ApplicationHandle *ch)
Shutdown TRANSPORT application client.
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.
uint64_t abs_value_us
The actual value.
static void reschedule_sender_timeout(struct SenderAddress *sender)
Increment sender timeout due to activity.
static void bi_destroy(struct BroadcastInterface *bi)
An interface went away, stop broadcasting on it.
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:35
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
uint32_t sequence_number
Sequence number used to derive this entry from master key.
"Plaintext" header at beginning of KX message.
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.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won&#39;t work on W32.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
A 256-bit hashcode.
Opaque handle to the transport service for communicators.
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
void GNUNET_TRANSPORT_communicator_disconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
Disconnect from the transport service.
struct GNUNET_ShortHashCode kid
Key and IV identification code.
struct GNUNET_CRYPTO_EddsaSignature sender_sig
Sender&#39;s signature of type GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE.
struct sockaddr * ba
Broadcast address to use on the interface.
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
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 (...
struct GNUNET_ShortHashCode kid
Key and IV identification code.
static void ifc_broadcast(void *cls)
Broadcast our presence on one of our interfaces.
struct SharedSecret * ss_head
Shared secrets we used with target, first used is head.
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.
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct GNUNET_TRANSPORT_QueueHandle * d_qh
handle for default queue with the ch.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
char * foreign_addr
Address of the receiver in the human-readable format with the COMMUNICATOR_ADDRESS_PREFIX.
void GNUNET_CRYPTO_ecdhe_key_create(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:508
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
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:1269
static struct GNUNET_CONTAINER_MultiPeerMap * receivers
Receivers (map from peer identity to struct ReceiverAddress)
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
Pre-generated "kid" code (key and IV identification code) to quickly derive master key for a struct U...
static struct GNUNET_SCHEDULER_Task * broadcast_task
ID of master broadcast task.
uint32_t sequence_used
Up to which sequence number did we use this master already? (for encrypting only) ...
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
Definition: gnunet-abd.c:61
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:565
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
int 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:1024
static char * value
Value of the record to add/remove.
static int get_sender_delete_it(void *cls, const struct GNUNET_PeerIdentity *target, void *value)
Iterator over all senders to clean up.
static int verify_confirmation(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, const struct UDPConfirmation *uc)
Check signature from uc against ephemeral.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:48
struct GNUNET_HashCode master
Master shared secret.
enum GNUNET_NetworkType nt
Which network type does this queue use?
#define GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST
Signature used by UDP broadcasts.
struct GNUNET_MQ_Handle * kx_mq
KX message queue we are providing for the ch.
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:1296
struct KeyCacheEntry * kce_tail
Kept in a DLL, sorted by sequence number.
#define MAX_SECRETS
How many shared master secrets do we keep around at most per sender? Should be large enough so that w...
#define AES_IV_SIZE
AES (GCM) IV size.
void * GNUNET_CONTAINER_heap_peek(const struct GNUNET_CONTAINER_Heap *heap)
Get element stored at the root of heap.
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.
struct SharedSecret * ss_tail
Shared secrets we received with target, last used is tail.
size_t kx_mtu
MTU we allowed transport for this receiver&#39;s KX queue.
static void check_timeouts(void *cls)
Task run to check #receiver_heap and #sender_heap for timeouts.
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:850
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE.
static char buf[2048]
#define COMMUNICATOR_ADDRESS_PREFIX
Address prefix used by the communicator.
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.
int 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.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
Handle to a node in a heap.
struct GNUNET_PeerIdentity sender
Identity of the inititor of the UDP broadcast.
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)...
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Our private key.
struct sockaddr * address
Address of the other peer.
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!)...
Internal representation of the hash map.
struct GNUNET_CONTAINER_MultiShortmap * GNUNET_CONTAINER_multishortmap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
Heap with the minimum cost at the root.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
UDP message box.
void GNUNET_CONTAINER_heap_destroy(struct GNUNET_CONTAINER_Heap *heap)
Destroys the heap.
struct sockaddr * sa
Sender&#39;s address of the interface.
A 512-bit hashcode.
socklen_t salen
Number of bytes in sa.
static void mq_destroy_kx(struct GNUNET_MQ_Handle *mq, void *impl_state)
Signature of functions implementing the destruction of a message queue.
static void sock_read(void *cls)
Socket read task.
int 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:1084
static void mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state)
Implementation function that cancels the currently sent message.
static void setup_receiver_mq(struct ReceiverAddress *receiver)
Setup the MQ for the receiver.
static int res
struct SharedSecret * next
Kept in a DLL.
Information we track per receiving address we have recently been in contact with (encryption to recei...
static struct GNUNET_NAT_AUTO_Test * nt
Handle to a NAT test operation.
void GNUNET_NT_scanner_done(struct GNUNET_NT_InterfaceScanner *is)
Terminate interface scanner.
Definition: nt.c:433
size_t d_mtu
MTU we allowed transport for this receiver&#39;s default queue.
int 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.
struct GNUNET_HashCode cmac
CMAC of the base key being acknowledged.
Node in the heap.
Private ECC key encoded for transmission.
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:692
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.
#define GNUNET_free_nz(ptr)
Wrapper around free.
Shared secret we generated for a particular sender or receiver.
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
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...
unsigned int num_secrets
Length of the DLL at ss_head.
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:272
struct GNUNET_CRYPTO_EddsaSignature sender_sig
Sender&#39;s signature of type GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_HashCode key
The key used in the DHT.
Internal representation of the hash map.
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 struct GNUNET_TRANSPORT_AddressIdentifier * ai
Handle to the operation that publishes our address.
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:215
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_Heap * senders_heap
Expiration heap for senders (contains struct SenderAddress)
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:378
static struct GNUNET_MQ_Envelope * ac
Handle to current GNUNET_PEERINFO_add_peer() operation.
struct GNUNET_NT_InterfaceScanner * GNUNET_NT_scanner_init(void)
Initialize the address characterization client handle.
Definition: nt.c:412
struct GNUNET_HashCode h_address
Hash of the sender&#39;s UDP address.
static void get_kid(const struct GNUNET_HashCode *msec, uint32_t serial, struct GNUNET_ShortHashCode *kid)
Compute kid.
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...
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
Loopback (same host).
Definition: gnunet_nt_lib.h:45
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.
unsigned int active_kce_count
Number of active KCN entries.
struct SharedSecret * prev
Kept in a DLL.
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:807
static struct GNUNET_CONTAINER_MultiPeerMap * senders
Senders (map from peer identity to struct SenderAddress)
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.
struct UDPBroadcast bcm
Message we broadcast on this interface.
static void decrypt_box(const struct UDPBox *box, size_t box_len, struct KeyCacheEntry *kce)
We received a box with matching kce.
void GNUNET_CONTAINER_multishortmap_destroy(struct GNUNET_CONTAINER_MultiShortmap *map)
Destroy a hash map.
struct GNUNET_CONTAINER_Heap * GNUNET_CONTAINER_heap_create(enum GNUNET_CONTAINER_HeapOrder order)
Create a new heap.
an ECC signature using EdDSA.
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:193
Standard IPv6 header.
static struct GNUNET_CONTAINER_Heap * receivers_heap
Expiration heap for receivers (contains struct ReceiverAddress)
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
#define KCN_THRESHOLD
If we fall below this number of available KCNs, we generate additional ACKs until we reach KCN_TARGET...
Allow multiple values with the same key.
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don&#39;t receive messages from the peer...
Handle to a message queue.
Definition: mq.c:85
unsigned int acks_available
Number of BOX keys from ACKs we have currently available for this receiver.
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.
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won&#39;t work on W32;.
struct GNUNET_CONTAINER_HeapNode * hn
Entry in sender expiration heap.
Private ECC key encoded for transmission.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
struct GNUNET_PeerIdentity sender
Sender&#39;s identity.
uint32_t sequence_max
Sequence acknowledgement limit.
struct ipv6_mreq mcreq
If this is an IPv6 interface, this is the request we use to join/leave the group. ...
The identity of the host (wraps the signing key of the peer).
#define AES_KEY_SIZE
AES key size.
static void reschedule_receiver_timeout(struct ReceiverAddress *receiver)
Increment receiver timeout due to activity.
struct ReceiverAddress * receiver
Receiver we use this shared secret with, or NULL.
Context information to be used while searching for operation contexts.
Definition: testbed_api.c:225
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.
struct GNUNET_TRANSPORT_ApplicationHandle * GNUNET_TRANSPORT_application_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the TRANSPORT application client handle.
#define GNUNET_PACKED
gcc-ism to get packed structs.
#define GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED
Queue length.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:82
configuration data
Definition: configuration.c:84
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.
socklen_t address_len
Length of the address.
const char * name
this is an outbound connection (transport initiated)
#define ADDRESS_VALIDITY_PERIOD
How long do we believe our addresses to remain up (before the other peer should revalidate).
Information we track per sender address we have recently been in contact with (we decrypt messages fr...
Signature we use to verify that the broadcast was really made by the peer that claims to have made it...
#define INTERFACE_SCAN_FREQUENCY
How often do we scan for changes to our network interfaces?
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...
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
static void receiver_destroy(struct ReceiverAddress *receiver)
Destroys a receiving state due to timeout or shutdown.
#define GNUNET_log(kind,...)
UDP key acknowledgement.
Entry in list of pending tasks.
Definition: scheduler.c:134
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
Signature we use to verify that the ephemeral key was really chosen by the specified sender...
static struct GNUNET_SCHEDULER_Task * read_task
ID of read task.
handle to a socket
Definition: network.c:52
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 ...
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
int 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, parse options).
Definition: program.c:367
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&#39;s key from the file specified in the configuration...
static struct SharedSecret * setup_shared_secret_enc(const struct GNUNET_CRYPTO_EcdhePrivateKey *ephemeral, struct ReceiverAddress *receiver)
Setup shared secret for encryption.
struct GNUNET_SCHEDULER_Task * broadcast_task
Task for this broadcast interface.
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:331
static void calculate_cmac(struct SharedSecret *ss)
Calcualte cmac from master in ss.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
Header for all communications.
static int find_sender_by_address(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Find existing struct SenderAddress by matching addresses.
Time for absolute times used by GNUnet, in microseconds.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:837
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...
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1517
struct SenderAddress * sender
Return value to set if we found a match.
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
#define MAX_SQN_DELTA
What is the maximum delta between KCN sequence numbers that we allow.
struct GNUNET_CRYPTO_EcdhePublicKey ephemeral
Ephemeral key used by the sender.
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
struct GNUNET_PeerIdentity target
To whom are we talking to.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
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. ...
int 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".
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:754
struct GNUNET_TIME_Absolute timeout
Timeout for this receiver address.
static void kce_generate(struct SharedSecret *ss, uint32_t seq)
Setup key cache entry for sequence number seq and shared secret ss.
void * GNUNET_CONTAINER_heap_remove_node(struct GNUNET_CONTAINER_HeapNode *node)
Removes a node from the heap.
static void do_shutdown(void *cls)
Shutdown the UNIX communicator.
Interface we broadcast our presence on.
Handle to the TRANSPORT subsystem for application management.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:657
static char * address
GNS address for this phone.
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:499
struct GNUNET_TRANSPORT_QueueHandle * kx_qh
handle for KX queue with the ch.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
struct BroadcastInterface * prev
Kept in a DLL.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static void sender_destroy(struct SenderAddress *sender)
Functions with this signature are called whenever we need to close a sender&#39;s state due to timeout...
Handle returned to identify the internal data structure the transport API has created to manage a mes...
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:560
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.
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
#define GNUNET_malloc(size)
Wrapper around malloc.
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.
int GNUNET_NETWORK_test_pf(int pf)
Test if the given protocol family is supported by this system.
Definition: network.c:85
struct BroadcastInterface * next
Kept in a DLL.
Internal representation of an address a communicator is currently providing for the transport service...
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
struct GNUNET_CRYPTO_EddsaPublicKey public_key
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition: network.c:912
struct SharedSecret * ss_head
Shared secrets we received from target, first used is head.
static struct GNUNET_SCHEDULER_Task * timeout_task
ID of timeout task.
const struct sockaddr * address
Address we are looking for.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
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.
struct GNUNET_MQ_Handle * d_mq
Default message queue we are providing for the ch.
enum GNUNET_NetworkType nt
Which network type does this queue use?