GNUnet  0.11.x
gnunet-communicator-tcp.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2010-2014, 2018, 2019 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
30 #include "platform.h"
31 #include "gnunet_util_lib.h"
32 #include "gnunet_core_service.h"
34 #include "gnunet_protocols.h"
35 #include "gnunet_signatures.h"
36 #include "gnunet_constants.h"
37 #include "gnunet_nt_lib.h"
38 #include "gnunet_nat_service.h"
42 
47 #define ADDRESS_VALIDITY_PERIOD \
48  GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
49 
58 #define DEFAULT_MAX_QUEUE_LENGTH 8
59 
64 #define BUF_SIZE (2 * 64 * 1024 + sizeof(struct TCPBox))
65 
69 #define DEFAULT_REKEY_INTERVAL GNUNET_TIME_UNIT_DAYS
70 
74 #define PROTO_QUEUE_TIMEOUT GNUNET_TIME_UNIT_MINUTES
75 
80 #define REKEY_MAX_BYTES (1024LLU * 1024 * 1024 * 4LLU)
81 
86 #define INITIAL_KX_SIZE \
87  (sizeof(struct GNUNET_CRYPTO_EcdhePublicKey) \
88  + sizeof(struct TCPConfirmation))
89 
93 #define INITIAL_CORE_KX_SIZE \
94  (sizeof(struct EphemeralKeyMessage) \
95  + sizeof(struct PingMessage) \
96  + sizeof(struct PongMessage))
97 
101 #define COMMUNICATOR_ADDRESS_PREFIX "tcp"
102 
106 #define COMMUNICATOR_CONFIG_SECTION "communicator-tcp"
107 
109 
110 
116 {
121 
126 
131 
136 
142 
147 };
148 
154 {
159 
164 
169 
175 
179  struct ChallengeNonceP challenge;
180 };
181 
186 {
191 
195  struct GNUNET_CRYPTO_EddsaSignature sender_sig;
196 
202 
206  struct ChallengeNonceP challenge;
207 
208 };
209 
214 {
215 
216 
220  struct GNUNET_MessageHeader header;
221 
226 
230  struct GNUNET_CRYPTO_EddsaSignature sender_sig;
231 
237 
241  struct ChallengeNonceP challenge;
242 
243 };
244 
248 struct TCPBox
249 {
256  struct GNUNET_MessageHeader header;
257 
266  struct GNUNET_ShortHashCode hmac;
267 
268  /* followed by as may bytes of payload as indicated in @e header,
269  excluding the TCPBox itself! */
270 };
271 
272 
277 struct TCPRekey
278 {
282  struct GNUNET_MessageHeader header;
283 
292  struct GNUNET_ShortHashCode hmac;
293 
298 
302  struct GNUNET_CRYPTO_EddsaSignature sender_sig;
303 
309 };
310 
316 {
321 
326 
331 
336 
341  struct GNUNET_TIME_AbsoluteNBO monotonic_time;
342 };
343 
349 struct TCPFinish
350 {
354  struct GNUNET_MessageHeader header;
355 
364  struct GNUNET_ShortHashCode hmac;
365 };
366 
367 
369 
374 {
379 
384 };
385 
389 struct Queue
390 {
394  struct GNUNET_PeerIdentity target;
395 
400 
405 
409  gcry_cipher_hd_t in_cipher;
410 
414  gcry_cipher_hd_t out_cipher;
415 
419  struct GNUNET_HashCode in_hmac;
420 
425  struct GNUNET_HashCode out_hmac;
426 
432 
437 
442 
446  struct sockaddr *address;
447 
453 
458  struct GNUNET_TIME_Absolute rekey_time;
459 
463  socklen_t address_len;
464 
469 
474 
478  unsigned long long bytes_in_queue;
479 
483  char cread_buf[BUF_SIZE];
484 
488  char cwrite_buf[BUF_SIZE];
489 
493  char pread_buf[UINT16_MAX + 1 + sizeof(struct TCPBox)];
494 
498  char pwrite_buf[UINT16_MAX + 1 + sizeof(struct TCPBox)];
499 
504  size_t cread_off;
505 
510  size_t cwrite_off;
511 
516  size_t pread_off;
517 
522  size_t pwrite_off;
523 
528 
536  unsigned int backpressure;
537 
542 
547 
552 
557 
565 
570  int rekeyed;
571 
575  struct GNUNET_TIME_AbsoluteNBO rekey_monotonic_time;
576 
580  struct GNUNET_TIME_AbsoluteNBO handshake_monotonic_time;
581 
585  struct GNUNET_TIME_AbsoluteNBO handshake_ack_monotonic_time;
586 
590  struct ChallengeNonceP challenge;
591 
596 
601 
606 
611 
616 
621 };
622 
623 
629 {
633  struct ProtoQueue *next;
634 
638  struct ProtoQueue *prev;
639 
644 
649 
654 
658  struct sockaddr *address;
659 
663  socklen_t address_len;
664 
669 
674  char ibuf[INITIAL_KX_SIZE];
675 
679  size_t ibuf_off;
680 };
681 
686 {
690  struct sockaddr *addr_ipv4;
691 
695  socklen_t addr_len_ipv4;
696 
700  struct sockaddr *addr_ipv6;
701 
705  socklen_t addr_len_ipv6;
706 
707 };
708 
712 struct Addresses
713 {
717  struct Addresses *next;
718 
722  struct Addresses *prev;
723 
727  struct sockaddr *addr;
728 
732  socklen_t addr_len;
733 
734 };
735 
736 
737 
741 static unsigned long long max_queue_length;
742 
747 
752 
757 
762 
767 
772 
777 
781 static const struct GNUNET_CONFIGURATION_Handle *cfg;
782 
787 
791 static struct GNUNET_NAT_Handle *nat;
792 
796 static struct ProtoQueue *proto_head;
797 
801 static struct ProtoQueue *proto_tail;
802 
807 
812 
817 
822 
827 
832 
836 // TODO remove?
837 // size_t unverified_size;
838 
843 
848 
852 unsigned int bind_port;
853 
861 static void
862 listen_cb (void *cls);
863 
871 static void
873 {
874  struct ListenTask *lt = NULL;
875  struct GNUNET_HashCode h_sock;
876 
878  sizeof(queue->listen_sock),
879  &h_sock);
880 
881  lt = GNUNET_CONTAINER_multihashmap_get (lt_map, &h_sock);
882 
884  "Disconnecting queue for peer `%s'\n",
885  GNUNET_i2s (&queue->target));
886  if (NULL != queue->rekey_monotime_sc)
887  {
889  queue->rekey_monotime_sc = NULL;
890  }
891  if (NULL != queue->handshake_monotime_sc)
892  {
894  queue->handshake_monotime_sc = NULL;
895  }
896  if (NULL != queue->handshake_ack_monotime_sc)
897  {
899  queue->handshake_ack_monotime_sc = NULL;
900  }
901  if (NULL != queue->rekey_monotime_get)
902  {
904  queue->rekey_monotime_get = NULL;
905  }
906  if (NULL != queue->handshake_monotime_get)
907  {
909  queue->handshake_monotime_get = NULL;
910  }
911  if (NULL != queue->handshake_ack_monotime_get)
912  {
914  queue->handshake_ack_monotime_get = NULL;
915  }
916  if (NULL != queue->qh)
917  {
919  queue->qh = NULL;
920  }
921  GNUNET_assert (
922  GNUNET_YES ==
923  GNUNET_CONTAINER_multipeermap_remove (queue_map, &queue->target, queue));
924  GNUNET_STATISTICS_set (stats,
925  "# queues active",
927  GNUNET_NO);
928  if (NULL != queue->read_task)
929  {
931  queue->read_task = NULL;
932  }
933  if (NULL != queue->write_task)
934  {
936  queue->write_task = NULL;
937  }
939  {
941  "closing socket failed\n");
942  }
943  gcry_cipher_close (queue->in_cipher);
944  gcry_cipher_close (queue->out_cipher);
945  GNUNET_free (queue->address);
946  if (0 != queue->backpressure)
947  queue->destroyed = GNUNET_YES;
948  else
949  GNUNET_free (queue);
950 
951  if ((! shutdown_running) && (NULL == lt->listen_task))
952  {
954  "add read net listen\n");
957  lt->listen_sock,
958  &listen_cb,
959  lt);
960  }
961  else
962  GNUNET_free (lt);
963 }
964 
965 
974 static void
975 calculate_hmac (struct GNUNET_HashCode *hmac_secret,
976  const void *buf,
977  size_t buf_size,
978  struct GNUNET_ShortHashCode *smac)
979 {
980  struct GNUNET_HashCode mac;
981 
982  GNUNET_CRYPTO_hmac_raw (hmac_secret,
983  sizeof(struct GNUNET_HashCode),
984  buf,
985  buf_size,
986  &mac);
987  /* truncate to `struct GNUNET_ShortHashCode` */
988  memcpy (smac, &mac, sizeof(struct GNUNET_ShortHashCode));
989  /* ratchet hmac key */
990  GNUNET_CRYPTO_hash (hmac_secret,
991  sizeof(struct GNUNET_HashCode),
992  hmac_secret);
993 }
994 
995 
1002 static void
1004 {
1005  struct TCPFinish fin;
1006 
1007  memset (&fin, 0, sizeof(fin));
1008  fin.header.size = htons (sizeof(fin));
1010  calculate_hmac (&queue->out_hmac, &fin, sizeof(fin), &fin.hmac);
1011  /* if there is any message left in pwrite_buf, we
1012  overwrite it (possibly dropping the last message
1013  from CORE hard here) */
1014  memcpy (queue->pwrite_buf, &fin, sizeof(fin));
1015  queue->pwrite_off = sizeof(fin);
1016  /* This flag will ensure that #queue_write() no longer
1017  notifies CORE about the possibility of sending
1018  more data, and that #queue_write() will call
1019  #queue_destroy() once the @c fin was fully written. */
1020  queue->finishing = GNUNET_YES;
1021 }
1022 
1023 
1031 static void
1033 {
1034  queue->timeout =
1036 }
1037 
1038 
1044 static void
1045 queue_read (void *cls);
1046 
1047 
1055 static void
1056 core_read_finished_cb (void *cls, int success)
1057 {
1058  struct Queue *queue = cls;
1059  if (GNUNET_OK != success)
1060  GNUNET_STATISTICS_update (stats,
1061  "# messages lost in communicator API towards CORE",
1062  1,
1063  GNUNET_NO);
1064  if (NULL == queue)
1065  return;
1066 
1068  "backpressure %u\n",
1069  queue->backpressure);
1070 
1071  queue->backpressure--;
1072  /* handle deferred queue destruction */
1073  if ((queue->destroyed) && (0 == queue->backpressure))
1074  {
1075  GNUNET_free (queue);
1076  return;
1077  }
1078  else if (GNUNET_YES != queue->destroyed)
1079  {
1080  reschedule_queue_timeout (queue);
1081  /* possibly unchoke reading, now that CORE made progress */
1082  if (NULL == queue->read_task)
1083  queue->read_task =
1085  queue->timeout),
1086  queue->sock,
1087  &queue_read,
1088  queue);
1089  }
1090 }
1091 
1092 
1102 static void
1104  const void *plaintext,
1105  size_t plaintext_len)
1106 {
1107  const struct GNUNET_MessageHeader *hdr = plaintext;
1108  int ret;
1109 
1110  if (ntohs (hdr->size) != plaintext_len)
1111  {
1112  /* NOTE: If we ever allow multiple CORE messages in one
1113  BOX, this will have to change! */
1114  GNUNET_break (0);
1115  return;
1116  }
1118  &queue->target,
1119  hdr,
1122  queue);
1123  if (GNUNET_OK == ret)
1124  queue->backpressure++;
1125  GNUNET_break (GNUNET_NO != ret); /* backpressure not working!? */
1126  if (GNUNET_SYSERR == ret)
1127  GNUNET_STATISTICS_update (stats,
1128  "# bytes lost due to CORE not running",
1129  plaintext_len,
1130  GNUNET_NO);
1131 }
1132 
1133 
1143 static void
1144 setup_cipher (const struct GNUNET_HashCode *dh,
1145  const struct GNUNET_PeerIdentity *pid,
1146  gcry_cipher_hd_t *cipher,
1147  struct GNUNET_HashCode *hmac_key)
1148 {
1149  char key[256 / 8];
1150  char ctr[128 / 8];
1151 
1152  gcry_cipher_open (cipher,
1153  GCRY_CIPHER_AES256 /* low level: go for speed */,
1154  GCRY_CIPHER_MODE_CTR,
1155  0 /* flags */);
1157  sizeof(key),
1158  "TCP-key",
1159  strlen ("TCP-key"),
1160  dh,
1161  sizeof(*dh),
1162  pid,
1163  sizeof(*pid),
1164  NULL,
1165  0));
1166  gcry_cipher_setkey (*cipher, key, sizeof(key));
1168  sizeof(ctr),
1169  "TCP-ctr",
1170  strlen ("TCP-ctr"),
1171  dh,
1172  sizeof(*dh),
1173  pid,
1174  sizeof(*pid),
1175  NULL,
1176  0));
1177  gcry_cipher_setctr (*cipher, ctr, sizeof(ctr));
1179  GNUNET_CRYPTO_kdf (hmac_key,
1180  sizeof(struct GNUNET_HashCode),
1181  "TCP-hmac",
1182  strlen ("TCP-hmac"),
1183  dh,
1184  sizeof(*dh),
1185  pid,
1186  sizeof(*pid),
1187  NULL,
1188  0));
1189 }
1190 
1191 
1198 static void
1200  struct Queue *queue)
1201 {
1202  struct GNUNET_HashCode dh;
1203 
1204  GNUNET_CRYPTO_eddsa_ecdh (my_private_key, ephemeral, &dh);
1205  setup_cipher (&dh, &my_identity, &queue->in_cipher, &queue->in_hmac);
1206 }
1207 
1213 static void
1214 rekey_monotime_store_cb (void *cls, int success)
1215 {
1216  struct Queue *queue = cls;
1217  if (GNUNET_OK != success)
1218  {
1220  "Failed to store rekey monotonic time in PEERSTORE!\n");
1221  }
1222  queue->rekey_monotime_sc = NULL;
1223 }
1224 
1232 static void
1234  const struct GNUNET_PEERSTORE_Record *record,
1235  const char *emsg)
1236 {
1237  struct Queue *queue = cls;
1238  struct GNUNET_TIME_AbsoluteNBO *mtbe;
1239  struct GNUNET_TIME_Absolute mt;
1240  const struct GNUNET_PeerIdentity *pid;
1241  struct GNUNET_TIME_AbsoluteNBO *rekey_monotonic_time;
1242 
1243  (void) emsg;
1244 
1245  rekey_monotonic_time = &queue->rekey_monotonic_time;
1246  pid = &queue->target;
1247  if (NULL == record)
1248  {
1249  queue->rekey_monotime_get = NULL;
1250  return;
1251  }
1252  if (sizeof(*mtbe) != record->value_size)
1253  {
1254  GNUNET_break (0);
1255  return;
1256  }
1257  mtbe = record->value;
1258  mt = GNUNET_TIME_absolute_ntoh (*mtbe);
1261  {
1263  "Queue from %s dropped, rekey monotime in the past\n",
1264  GNUNET_i2s (&queue->target));
1265  GNUNET_break (0);
1266  queue_finish (queue);
1267  return;
1268  }
1269  queue->rekey_monotime_sc = GNUNET_PEERSTORE_store (peerstore,
1270  "transport_tcp_communicator",
1271  pid,
1273  rekey_monotonic_time,
1274  sizeof(rekey_monotonic_time),
1278  queue);
1279 }
1280 
1289 static void
1290 do_rekey (struct Queue *queue, const struct TCPRekey *rekey)
1291 {
1292  struct TcpRekeySignature thp;
1293 
1295  thp.purpose.size = htonl (sizeof(thp));
1297  "do_rekey size %u\n",
1298  thp.purpose.size);
1299  thp.sender = queue->target;
1301  "sender %s\n",
1302  GNUNET_p2s (&thp.sender.public_key));
1304  "sender %s\n",
1305  GNUNET_p2s (&queue->target.public_key));
1306  thp.receiver = my_identity;
1308  "receiver %s\n",
1309  GNUNET_p2s (&thp.receiver.public_key));
1310  thp.ephemeral = rekey->ephemeral;
1312  "ephemeral %s\n",
1313  GNUNET_e2s (&thp.ephemeral));
1314  thp.monotonic_time = rekey->monotonic_time;
1316  "time %s\n",
1319  GNUNET_assert (ntohl ((&thp)->purpose.size) == sizeof (*(&thp)));
1320  if (GNUNET_OK !=
1322  &thp,
1323  &rekey->sender_sig,
1324  &queue->target.public_key))
1325  {
1326  GNUNET_break (0);
1327  queue_finish (queue);
1328  return;
1329  }
1330  queue->rekey_monotonic_time = rekey->monotonic_time;
1331  queue->rekey_monotime_get = GNUNET_PEERSTORE_iterate (peerstore,
1332  "transport_tcp_communicator",
1333  &queue->target,
1336  queue);
1337  gcry_cipher_close (queue->in_cipher);
1338  queue->rekeyed = GNUNET_YES;
1339  setup_in_cipher (&rekey->ephemeral, queue);
1340 }
1341 
1347 static void
1348 handshake_ack_monotime_store_cb (void *cls, int success)
1349 {
1350  struct Queue *queue = cls;
1351 
1352  if (GNUNET_OK != success)
1353  {
1355  "Failed to store handshake ack monotonic time in PEERSTORE!\n");
1356  }
1357  queue->handshake_ack_monotime_sc = NULL;
1358 }
1359 
1367 static void
1369  const struct GNUNET_PEERSTORE_Record *record,
1370  const char *emsg)
1371 {
1372  struct Queue *queue = cls;
1373  struct GNUNET_TIME_AbsoluteNBO *mtbe;
1374  struct GNUNET_TIME_Absolute mt;
1375  const struct GNUNET_PeerIdentity *pid;
1376  struct GNUNET_TIME_AbsoluteNBO *handshake_ack_monotonic_time;
1377 
1378  (void) emsg;
1379 
1380  handshake_ack_monotonic_time = &queue->handshake_ack_monotonic_time;
1381  pid = &queue->target;
1382  if (NULL == record)
1383  {
1384  queue->handshake_ack_monotime_get = NULL;
1385  return;
1386  }
1387  if (sizeof(*mtbe) != record->value_size)
1388  {
1389  GNUNET_break (0);
1390  return;
1391  }
1392  mtbe = record->value;
1393  mt = GNUNET_TIME_absolute_ntoh (*mtbe);
1396  {
1398  "Queue from %s dropped, handshake ack monotime in the past\n",
1399  GNUNET_i2s (&queue->target));
1400  GNUNET_break (0);
1401  queue_finish (queue);
1402  return;
1403  }
1405  "transport_tcp_communicator",
1406  pid,
1408  handshake_ack_monotonic_time,
1409  sizeof(
1410  handshake_ack_monotonic_time),
1413  &
1415  queue);
1416 }
1417 
1425 static size_t
1427 {
1428  const struct GNUNET_MessageHeader *hdr =
1429  (const struct GNUNET_MessageHeader *) queue->pread_buf;
1430  const struct TCPConfirmationAck *tca = (const struct
1431  TCPConfirmationAck *) queue->pread_buf;
1432  const struct TCPBox *box = (const struct TCPBox *) queue->pread_buf;
1433  const struct TCPRekey *rekey = (const struct TCPRekey *) queue->pread_buf;
1434  const struct TCPFinish *fin = (const struct TCPFinish *) queue->pread_buf;
1435  struct TCPRekey rekeyz;
1436  struct TCPFinish finz;
1437  struct GNUNET_ShortHashCode tmac;
1438  uint16_t type;
1439  size_t size = 0; /* make compiler happy */
1440  struct TcpHandshakeAckSignature thas;
1441  const struct ChallengeNonceP challenge = queue->challenge;
1442 
1444  "try handle plaintext!\n");
1445 
1446  if ((sizeof(*hdr) > queue->pread_off))
1447  {
1449  "Handling plaintext, not even a header!\n");
1450  return 0; /* not even a header */
1451  }
1452 
1453  /* if ((-1 != unverified_size) && (unverified_size > INITIAL_CORE_KX_SIZE)) */
1454  /* { */
1455  /* GNUNET_log (GNUNET_ERROR_TYPE_ERROR, */
1456  /* "Already received data of size %lu bigger than KX size %lu!\n", */
1457  /* unverified_size, */
1458  /* INITIAL_CORE_KX_SIZE); */
1459  /* GNUNET_break_op (0); */
1460  /* queue_finish (queue); */
1461  /* return 0; */
1462  /* } */
1463 
1464  type = ntohs (hdr->type);
1465  switch (type)
1466  {
1469  "start processing ack\n");
1470  if (sizeof(*tca) > queue->pread_off)
1471  {
1473  "Handling plaintext size of tca greater than pread offset.\n");
1474  return 0;
1475  }
1476  if (ntohs (hdr->size) != sizeof(*tca))
1477  {
1479  "Handling plaintext size does not match message type.\n");
1480  GNUNET_break_op (0);
1481  queue_finish (queue);
1482  return 0;
1483  }
1484 
1485  thas.purpose.purpose = htonl (
1487  thas.purpose.size = htonl (sizeof(thas));
1488  thas.sender = tca->sender;
1489  thas.receiver = my_identity;
1490  thas.monotonic_time = tca->monotonic_time;
1491  thas.challenge = tca->challenge;
1492 
1495  &thas,
1496  &tca->sender_sig,
1497  &tca->sender.public_key))
1498  {
1500  "Verification of signature failed!\n");
1501  GNUNET_break (0);
1502  queue_finish (queue);
1503  return 0;
1504  }
1505  if (0 != GNUNET_memcmp (&tca->challenge, &challenge))
1506  {
1508  "Challenge in TCPConfirmationAck not correct!\n");
1509  GNUNET_break (0);
1510  queue_finish (queue);
1511  return 0;
1512  }
1513 
1515  "transport_tcp_communicator",
1516  &queue->target,
1518  &
1520  queue);
1521 
1523  "Handling plaintext, ack processed!");
1524 
1525  // unverified_size = -1;
1526 
1527  /* char *foreign_addr; */
1528 
1529  /* switch (queue->address->sa_family) */
1530  /* { */
1531  /* case AF_INET: */
1532  /* GNUNET_asprintf (&foreign_addr, */
1533  /* "%s-%s", */
1534  /* COMMUNICATOR_ADDRESS_PREFIX, */
1535  /* GNUNET_a2s (queue->address, queue->address_len)); */
1536  /* break; */
1537 
1538  /* case AF_INET6: */
1539  /* GNUNET_asprintf (&foreign_addr, */
1540  /* "%s-%s", */
1541  /* COMMUNICATOR_ADDRESS_PREFIX, */
1542  /* GNUNET_a2s (queue->address, queue->address_len)); */
1543  /* break; */
1544 
1545  /* default: */
1546  /* GNUNET_assert (0); */
1547  /* } */
1548 
1549  /* queue->qh = GNUNET_TRANSPORT_communicator_mq_add (ch, */
1550  /* &queue->target, */
1551  /* foreign_addr, */
1552  /* 0 /\* no MTU *\/, */
1553  /* GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED, */
1554  /* 0, /\* Priority *\/ */
1555  /* queue->nt, */
1556  /* queue->cs, */
1557  /* queue->mq); */
1558 
1559  /* GNUNET_free (foreign_addr); */
1560 
1561  size = ntohs (hdr->size);
1562  break;
1564  /* Special case: header size excludes box itself! */
1565  if (ntohs (hdr->size) + sizeof(struct TCPBox) > queue->pread_off)
1566  return 0;
1567  calculate_hmac (&queue->in_hmac, &box[1], ntohs (hdr->size), &tmac);
1568  if (0 != memcmp (&tmac, &box->hmac, sizeof(tmac)))
1569  {
1570  GNUNET_break_op (0);
1571  queue_finish (queue);
1572  return 0;
1573  }
1574  pass_plaintext_to_core (queue, (const void *) &box[1], ntohs (hdr->size));
1575  size = ntohs (hdr->size) + sizeof(*box);
1577  "Handling plaintext, box processed!\n");
1578  break;
1579 
1581  if (sizeof(*rekey) > queue->pread_off)
1582  return 0;
1583  if (ntohs (hdr->size) != sizeof(*rekey))
1584  {
1585  GNUNET_break_op (0);
1586  queue_finish (queue);
1587  return 0;
1588  }
1589  rekeyz = *rekey;
1590  memset (&rekeyz.hmac, 0, sizeof(rekeyz.hmac));
1591  calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
1592  if (0 != memcmp (&tmac, &rekey->hmac, sizeof(tmac)))
1593  {
1594  GNUNET_break_op (0);
1595  queue_finish (queue);
1596  return 0;
1597  }
1598  do_rekey (queue, rekey);
1599  size = ntohs (hdr->size);
1601  "Handling plaintext, rekey processed!\n");
1602  break;
1603 
1605  if (sizeof(*fin) > queue->pread_off)
1606  return 0;
1607  if (ntohs (hdr->size) != sizeof(*fin))
1608  {
1609  GNUNET_break_op (0);
1610  queue_finish (queue);
1611  return 0;
1612  }
1613  finz = *fin;
1614  memset (&finz.hmac, 0, sizeof(finz.hmac));
1615  calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
1616  if (0 != memcmp (&tmac, &fin->hmac, sizeof(tmac)))
1617  {
1618  GNUNET_break_op (0);
1619  queue_finish (queue);
1620  return 0;
1621  }
1622  /* handle FINISH by destroying queue */
1623  queue_destroy (queue);
1625  "Handling plaintext, finish processed!\n");
1626  break;
1627 
1628  default:
1630  "Handling plaintext, nothing processed!\n");
1631  GNUNET_break_op (0);
1632  queue_finish (queue);
1633  return 0;
1634  }
1635  GNUNET_assert (0 != size);
1636  /* if (-1 != unverified_size) */
1637  /* unverified_size += size; */
1638  return size;
1639 }
1640 
1641 
1647 static void
1648 queue_read (void *cls)
1649 {
1650  struct Queue *queue = cls;
1651  struct GNUNET_TIME_Relative left;
1652  ssize_t rcvd;
1653 
1654  queue->read_task = NULL;
1655  rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
1656  &queue->cread_buf[queue->cread_off],
1657  BUF_SIZE - queue->cread_off);
1659  "Received %lu bytes from TCP queue\n", rcvd);
1660  if (-1 == rcvd)
1661  {
1662  if ((EAGAIN != errno) && (EINTR != errno))
1663  {
1665  queue_finish (queue);
1666  return;
1667  }
1668  /* try again */
1670  queue->read_task =
1671  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read, queue);
1672  return;
1673  }
1674  if (0 != rcvd)
1675  reschedule_queue_timeout (queue);
1676  queue->cread_off += rcvd;
1677  while ((queue->pread_off < sizeof(queue->pread_buf)) &&
1678  (queue->cread_off > 0))
1679  {
1680  size_t max = GNUNET_MIN (sizeof(queue->pread_buf) - queue->pread_off,
1681  queue->cread_off);
1682  size_t done;
1683  size_t total;
1684  size_t old_pread_off = queue->pread_off;
1685 
1686  GNUNET_assert (0 ==
1687  gcry_cipher_decrypt (queue->in_cipher,
1688  &queue->pread_buf[queue->pread_off],
1689  max,
1690  queue->cread_buf,
1691  max));
1692  queue->pread_off += max;
1693  total = 0;
1694  while (0 != (done = try_handle_plaintext (queue)))
1695  {
1696  /* 'done' bytes of plaintext were used, shift buffer */
1697  GNUNET_assert (done <= queue->pread_off);
1698  /* NOTE: this memmove() could possibly sometimes be
1699  avoided if we pass 'total' into try_handle_plaintext()
1700  and use it at an offset into the buffer there! */
1701  memmove (queue->pread_buf,
1702  &queue->pread_buf[done],
1703  queue->pread_off - done);
1704  queue->pread_off -= done;
1705  total += done;
1706  /* The last plaintext was a rekey, abort for now */
1707  if (GNUNET_YES == queue->rekeyed)
1708  break;
1709  }
1710  /* when we encounter a rekey message, the decryption above uses the
1711  wrong key for everything after the rekey; in that case, we have
1712  to re-do the decryption at 'total' instead of at 'max'.
1713  However, we have to take into account that the plaintext buffer may have
1714  already contained data and not jumpt too far ahead in the ciphertext.
1715  If there is no rekey and the last message is incomplete (max > total),
1716  it is safe to keep the decryption so we shift by 'max' */
1717  if (GNUNET_YES == queue->rekeyed)
1718  {
1719  max = total - old_pread_off;
1720  queue->rekeyed = GNUNET_NO;
1721  queue->pread_off = 0;
1722  }
1723  memmove (queue->cread_buf, &queue->cread_buf[max], queue->cread_off - max);
1724  queue->cread_off -= max;
1725  }
1726  if (BUF_SIZE == queue->cread_off)
1727  return; /* buffer full, suspend reading */
1729  if (0 != left.rel_value_us)
1730  {
1731  if (max_queue_length > queue->backpressure)
1732  {
1733  /* continue reading */
1735  queue->read_task =
1736  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read, queue);
1737  }
1738  return;
1739  }
1741  "Queue %p was idle for %s, disconnecting\n",
1742  queue,
1745  GNUNET_YES));
1746  queue_finish (queue);
1747 }
1748 
1756 static struct sockaddr *
1757 tcp_address_to_sockaddr_numeric_v6 (socklen_t *sock_len, struct sockaddr_in6 v6,
1758  unsigned int port)
1759 {
1760  struct sockaddr *in;
1761 
1762  v6.sin6_family = AF_INET6;
1763  v6.sin6_port = htons ((uint16_t) port);
1764 #if HAVE_SOCKADDR_IN_SIN_LEN
1765  v6.sin6_len = sizeof(sizeof(struct sockaddr_in6));
1766 #endif
1767  v6.sin6_flowinfo = 0;
1768  v6.sin6_scope_id = 0;
1769  in = GNUNET_memdup (&v6, sizeof(v6));
1770  *sock_len = sizeof(struct sockaddr_in6);
1771 
1772  return in;
1773 }
1774 
1782 static struct sockaddr *
1783 tcp_address_to_sockaddr_numeric_v4 (socklen_t *sock_len, struct sockaddr_in v4,
1784  unsigned int port)
1785 {
1786  struct sockaddr *in;
1787 
1788  v4.sin_family = AF_INET;
1789  v4.sin_port = htons ((uint16_t) port);
1790 #if HAVE_SOCKADDR_IN_SIN_LEN
1791  v4.sin_len = sizeof(struct sockaddr_in);
1792 #endif
1793  in = GNUNET_memdup (&v4, sizeof(v4));
1794  *sock_len = sizeof(struct sockaddr_in);
1795  return in;
1796 }
1797 
1804 static struct PortOnlyIpv4Ipv6 *
1805 tcp_address_to_sockaddr_port_only (const char *bindto, unsigned int *port)
1806 {
1807  struct PortOnlyIpv4Ipv6 *po;
1808  struct sockaddr_in *i4;
1809  struct sockaddr_in6 *i6;
1810  socklen_t sock_len_ipv4;
1811  socklen_t sock_len_ipv6;
1812 
1813  /* interpreting value as just a PORT number */
1814  if (*port > UINT16_MAX)
1815  {
1817  "BINDTO specification `%s' invalid: value too large for port\n",
1818  bindto);
1819  return NULL;
1820  }
1821 
1822  po = GNUNET_new (struct PortOnlyIpv4Ipv6);
1823 
1824  if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
1825  (GNUNET_YES ==
1828  "DISABLE_V6")))
1829  {
1830  i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
1831  po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
1832  *port);
1833  po->addr_len_ipv4 = sock_len_ipv4;
1834  }
1835  else
1836  {
1837 
1838  i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
1839  po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
1840  *port);
1841  po->addr_len_ipv4 = sock_len_ipv4;
1842 
1843  i6 = GNUNET_malloc (sizeof(struct sockaddr_in6));
1844  po->addr_ipv6 = tcp_address_to_sockaddr_numeric_v6 (&sock_len_ipv6, *i6,
1845  *port);
1846 
1847  po->addr_len_ipv6 = sock_len_ipv6;
1848 
1849  GNUNET_free (i6);
1850  }
1851 
1852  GNUNET_free (i4);
1853 
1854  return po;
1855 }
1856 
1863 static char *
1864 extract_address (const char *bindto)
1865 {
1866 
1867  char *start;
1868  char *token;
1869  char *cp;
1870  char *rest = NULL;
1871 
1873  "extract address with bindto %s\n",
1874  bindto);
1875 
1876  if (NULL == bindto)
1878  "bindto is NULL\n");
1879 
1880  cp = GNUNET_strdup (bindto);
1881 
1883  "extract address 2\n");
1884 
1885  start = cp;
1886  if (('[' == *cp) && (']' == cp[strlen (cp) - 1]))
1887  {
1888  start++; /* skip over '['*/
1889  cp[strlen (cp) - 1] = '\0'; /* eat ']'*/
1890  }
1891  else {
1892  token = strtok_r (cp, "]", &rest);
1893  if (strlen (bindto) == strlen (token))
1894  {
1895  token = strtok_r (cp, ":", &rest);
1896  }
1897  else
1898  {
1899  token++;
1900  return token;
1901  }
1902  }
1903 
1905  "extract address 3\n");
1907  "extract address with start %s\n",
1908  start);
1909 
1910  return start;
1911 }
1912 
1919 static unsigned int
1920 extract_port (const char *addr_and_port)
1921 {
1922  unsigned int port;
1923  char dummy[2];
1924  char *token;
1925  char *addr;
1926  char *colon;
1927  char *cp;
1928  char *rest = NULL;
1929 
1930  if (NULL != addr_and_port)
1931  {
1932  cp = GNUNET_strdup (addr_and_port);
1933  token = strtok_r (cp, "]", &rest);
1934  if (strlen (addr_and_port) == strlen (token))
1935  {
1936  colon = strrchr (cp, ':');
1937  if (NULL == colon)
1938  {
1939  return 0;
1940  }
1941  addr = colon;
1942  addr++;
1943  }
1944  else
1945  {
1946  token = strtok_r (NULL, "]", &rest);
1947  if (NULL == token)
1948  {
1949  return 0;
1950  }
1951  else
1952  {
1953  addr = token;
1954  addr++;
1955  }
1956  }
1957 
1958 
1959  if (1 == sscanf (addr, "%u%1s", &port, dummy))
1960  {
1961  /* interpreting value as just a PORT number */
1962  if (port > UINT16_MAX)
1963  {
1965  "Port `%u' invalid: value too large for port\n",
1966  port);
1967  // GNUNET_free (cp);
1968  return 0;
1969  }
1970  }
1971  else
1972  {
1974  "BINDTO specification invalid: last ':' not followed by number\n");
1975  // GNUNET_free (cp);
1976  return 0;
1977  }
1978  }
1979  else
1980  {
1982  "return 0\n");
1983  /* interpret missing port as 0, aka pick any free one */
1984  port = 0;
1985  }
1986 
1987 
1988  return port;
1989 }
1990 
1998 static struct sockaddr *
1999 tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
2000 {
2001  struct sockaddr *in;
2002  unsigned int port;
2003  struct sockaddr_in v4;
2004  struct sockaddr_in6 v6;
2005  const char *start;
2006 
2007  // cp = GNUNET_strdup (bindto);
2008  start = extract_address (bindto);
2009 
2011  "start %s\n",
2012  start);
2013 
2015  "!bindto %s\n",
2016  bindto);
2017 
2018 
2019 
2020  if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
2021  {
2022  // colon = strrchr (cp, ':');
2023  port = extract_port (bindto);
2024 
2026  "port %u\n",
2027  port);
2028 
2029  in = tcp_address_to_sockaddr_numeric_v4 (sock_len, v4, port);
2030  }
2031  else if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
2032  {
2033  // colon = strrchr (cp, ':');
2034  port = extract_port (bindto);
2035  in = tcp_address_to_sockaddr_numeric_v6 (sock_len, v6, port);
2036  }
2037  else{
2038  GNUNET_assert (0);
2039  }
2040 
2041  // GNUNET_free (start);
2042 
2043  return in;
2044 }
2045 
2046 
2053 static void
2055 {
2056  struct GNUNET_HashCode dh;
2057 
2058  GNUNET_CRYPTO_ecdh_eddsa (&queue->ephemeral, &queue->target.public_key, &dh);
2059  /* we don't need the private key anymore, drop it! */
2060  memset (&queue->ephemeral, 0, sizeof(queue->ephemeral));
2061  setup_cipher (&dh, &queue->target, &queue->out_cipher, &queue->out_hmac);
2063  queue->rekey_left_bytes =
2065 }
2066 
2067 
2074 static void
2076 {
2077  struct TCPRekey rekey;
2078  struct TcpRekeySignature thp;
2079 
2080  GNUNET_assert (0 == queue->pwrite_off);
2081  memset (&rekey, 0, sizeof(rekey));
2084  rekey.header.size = ntohs (sizeof(rekey));
2086  rekey.monotonic_time =
2089  thp.purpose.size = htonl (sizeof(thp));
2091  "inject_rekey size %u\n",
2092  thp.purpose.size);
2093  thp.sender = my_identity;
2095  "sender %s\n",
2096  GNUNET_p2s (&thp.sender.public_key));
2097  thp.receiver = queue->target;
2099  "receiver %s\n",
2100  GNUNET_p2s (&thp.receiver.public_key));
2101  thp.ephemeral = rekey.ephemeral;
2103  "ephemeral %s\n",
2104  GNUNET_e2s (&thp.ephemeral));
2105  thp.monotonic_time = rekey.monotonic_time;
2107  "time %s\n",
2110  GNUNET_CRYPTO_eddsa_sign (my_private_key,
2111  &thp,
2112  &rekey.sender_sig);
2113  calculate_hmac (&queue->out_hmac, &rekey, sizeof(rekey), &rekey.hmac);
2114  /* Encrypt rekey message with 'old' cipher */
2115  GNUNET_assert (0 ==
2116  gcry_cipher_encrypt (queue->out_cipher,
2117  &queue->cwrite_buf[queue->cwrite_off],
2118  sizeof(rekey),
2119  &rekey,
2120  sizeof(rekey)));
2121  queue->cwrite_off += sizeof(rekey);
2122  /* Setup new cipher for successive messages */
2123  gcry_cipher_close (queue->out_cipher);
2124  setup_out_cipher (queue);
2125 }
2126 
2127 
2134 static void
2135 queue_write (void *cls)
2136 {
2137  struct Queue *queue = cls;
2138  ssize_t sent;
2139  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "In queue write\n");
2140  queue->write_task = NULL;
2141  if (0 != queue->cwrite_off)
2142  {
2143  sent = GNUNET_NETWORK_socket_send (queue->sock,
2144  queue->cwrite_buf,
2145  queue->cwrite_off);
2147  "Sent %lu bytes to TCP queue\n", sent);
2148  if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno))
2149  {
2151  queue_destroy (queue);
2152  return;
2153  }
2154  if (sent > 0)
2155  {
2156  size_t usent = (size_t) sent;
2157  queue->cwrite_off -= usent;
2158  memmove (queue->cwrite_buf,
2159  &queue->cwrite_buf[usent],
2160  queue->cwrite_off);
2161  reschedule_queue_timeout (queue);
2162  }
2163  }
2164  /* can we encrypt more? (always encrypt full messages, needed
2165  such that #mq_cancel() can work!) */
2166  if ((0 < queue->rekey_left_bytes) &&
2167  (queue->pwrite_off > 0) &&
2168  (queue->cwrite_off + queue->pwrite_off <= BUF_SIZE))
2169  {
2171  "Encrypting %lu bytes\n", queue->pwrite_off);
2172  GNUNET_assert (0 ==
2173  gcry_cipher_encrypt (queue->out_cipher,
2174  &queue->cwrite_buf[queue->cwrite_off],
2175  queue->pwrite_off,
2176  queue->pwrite_buf,
2177  queue->pwrite_off));
2178  if (queue->rekey_left_bytes > queue->pwrite_off)
2179  queue->rekey_left_bytes -= queue->pwrite_off;
2180  else
2181  queue->rekey_left_bytes = 0;
2182  queue->cwrite_off += queue->pwrite_off;
2183  queue->pwrite_off = 0;
2184  }
2185  // if ((-1 != unverified_size)&& ((0 == queue->pwrite_off) &&
2186  if (((0 == queue->pwrite_off) &&
2187  ((0 == queue->rekey_left_bytes) ||
2188  (0 ==
2190  queue->rekey_time).rel_value_us))))
2191  {
2192  inject_rekey (queue);
2193  }
2194  if ((0 == queue->pwrite_off) && (! queue->finishing) &&
2195  (GNUNET_YES == queue->mq_awaits_continue))
2196  {
2197  queue->mq_awaits_continue = GNUNET_NO;
2199  }
2200  /* did we just finish writing 'finish'? */
2201  if ((0 == queue->cwrite_off) && (GNUNET_YES == queue->finishing))
2202  {
2204  "Finishing queue\n");
2205  queue_destroy (queue);
2206  return;
2207  }
2208  /* do we care to write more? */
2209  if ((0 < queue->cwrite_off) || (0 < queue->pwrite_off))
2210  queue->write_task =
2212  queue->sock,
2213  &queue_write,
2214  queue);
2215 }
2216 
2217 
2226 static void
2228  const struct GNUNET_MessageHeader *msg,
2229  void *impl_state)
2230 {
2231  struct Queue *queue = impl_state;
2232  uint16_t msize = ntohs (msg->size);
2233  struct TCPBox box;
2235  "In MQ send. Queue finishing: %s; write task running: %s\n",
2236  (GNUNET_YES == queue->finishing) ? "yes" : "no",
2237  (NULL == queue->write_task) ? "yes" : "no");
2238  GNUNET_assert (mq == queue->mq);
2239  queue->mq_awaits_continue = GNUNET_YES;
2240  if (GNUNET_YES == queue->finishing)
2241  return; /* this queue is dying, drop msg */
2242  GNUNET_assert (0 == queue->pwrite_off);
2244  box.header.size = htons (msize);
2245  calculate_hmac (&queue->out_hmac, msg, msize, &box.hmac);
2246  memcpy (&queue->pwrite_buf[queue->pwrite_off], &box, sizeof(box));
2247  queue->pwrite_off += sizeof(box);
2248  memcpy (&queue->pwrite_buf[queue->pwrite_off], msg, msize);
2249  queue->pwrite_off += msize;
2251  "%lu bytes of plaintext to send\n", queue->pwrite_off);
2252  GNUNET_assert (NULL != queue->sock);
2253  if (NULL == queue->write_task)
2254  queue->write_task =
2256  queue->sock,
2257  &queue_write,
2258  queue);
2259 }
2260 
2261 
2270 static void
2271 mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state)
2272 {
2273  struct Queue *queue = impl_state;
2274 
2275  if (mq == queue->mq)
2276  {
2277  queue->mq = NULL;
2278  queue_finish (queue);
2279  }
2280 }
2281 
2282 
2289 static void
2290 mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
2291 {
2292  struct Queue *queue = impl_state;
2293 
2294  GNUNET_assert (0 != queue->pwrite_off);
2295  queue->pwrite_off = 0;
2296 }
2297 
2298 
2308 static void
2309 mq_error (void *cls, enum GNUNET_MQ_Error error)
2310 {
2311  struct Queue *queue = cls;
2312 
2314  "MQ error in queue to %s: %d\n",
2315  GNUNET_i2s (&queue->target),
2316  (int) error);
2317  queue_finish (queue);
2318 }
2319 
2320 
2328 static void
2330 {
2331  queue->nt =
2332  GNUNET_NT_scanner_get_type (is, queue->address, queue->address_len);
2334  queue_map,
2335  &queue->target,
2336  queue,
2338  GNUNET_STATISTICS_set (stats,
2339  "# queues active",
2341  GNUNET_NO);
2342  queue->timeout =
2345  &mq_destroy,
2346  &mq_cancel,
2347  queue,
2348  NULL,
2349  &mq_error,
2350  queue);
2351  {
2352  char *foreign_addr;
2353 
2354  switch (queue->address->sa_family)
2355  {
2356  case AF_INET:
2357  GNUNET_asprintf (&foreign_addr,
2358  "%s-%s",
2360  GNUNET_a2s (queue->address, queue->address_len));
2361  break;
2362 
2363  case AF_INET6:
2364  GNUNET_asprintf (&foreign_addr,
2365  "%s-%s",
2367  GNUNET_a2s (queue->address, queue->address_len));
2368  break;
2369 
2370  default:
2371  GNUNET_assert (0);
2372  }
2374  &queue->target,
2375  foreign_addr,
2376  0 /* no MTU */,
2378  0, /* Priority */
2379  queue->nt,
2380  queue->cs,
2381  queue->mq);
2382  GNUNET_free (foreign_addr);
2383  }
2384 }
2385 
2386 
2397 static void
2399  const struct GNUNET_CRYPTO_EcdhePublicKey *epub)
2400 {
2401  struct TcpHandshakeSignature ths;
2402  struct TCPConfirmation tc;
2403 
2404  memcpy (queue->cwrite_buf, epub, sizeof(*epub));
2405  queue->cwrite_off = sizeof(*epub);
2406  /* compute 'tc' and append in encrypted format to cwrite_buf */
2407  tc.sender = my_identity;
2408  tc.monotonic_time =
2411  &tc.challenge,
2412  sizeof(tc.challenge));
2414  ths.purpose.size = htonl (sizeof(ths));
2415  ths.sender = my_identity;
2416  ths.receiver = queue->target;
2417  ths.ephemeral = *epub;
2418  ths.monotonic_time = tc.monotonic_time;
2419  ths.challenge = tc.challenge;
2420  GNUNET_CRYPTO_eddsa_sign (my_private_key,
2421  &ths,
2422  &tc.sender_sig);
2423  GNUNET_assert (0 ==
2424  gcry_cipher_encrypt (queue->out_cipher,
2425  &queue->cwrite_buf[queue->cwrite_off],
2426  sizeof(tc),
2427  &tc,
2428  sizeof(tc)));
2429  queue->challenge = tc.challenge;
2430  queue->cwrite_off += sizeof(tc);
2431 
2433  "transport",
2434  "handshake written\n");
2435 }
2436 
2437 
2445 static void
2447 {
2448  struct GNUNET_CRYPTO_EcdhePublicKey epub;
2449 
2452  setup_out_cipher (queue);
2453  transmit_kx (queue, &epub);
2454 }
2455 
2461 static void
2462 handshake_monotime_store_cb (void *cls, int success)
2463 {
2464  struct Queue *queue = cls;
2465  if (GNUNET_OK != success)
2466  {
2468  "Failed to store handshake monotonic time in PEERSTORE!\n");
2469  }
2470  queue->handshake_monotime_sc = NULL;
2471 }
2472 
2480 static void
2482  const struct GNUNET_PEERSTORE_Record *record,
2483  const char *emsg)
2484 {
2485  struct Queue *queue = cls;
2486  struct GNUNET_TIME_AbsoluteNBO *mtbe;
2487  struct GNUNET_TIME_Absolute mt;
2488  const struct GNUNET_PeerIdentity *pid;
2489  struct GNUNET_TIME_AbsoluteNBO *handshake_monotonic_time;
2490 
2491  (void) emsg;
2492 
2493  handshake_monotonic_time = &queue->handshake_monotonic_time;
2494  pid = &queue->target;
2495  if (NULL == record)
2496  {
2497  queue->handshake_monotime_get = NULL;
2498  return;
2499  }
2500  if (sizeof(*mtbe) != record->value_size)
2501  {
2502  GNUNET_break (0);
2503  return;
2504  }
2505  mtbe = record->value;
2506  mt = GNUNET_TIME_absolute_ntoh (*mtbe);
2509  {
2511  "Queue from %s dropped, handshake monotime in the past\n",
2512  GNUNET_i2s (&queue->target));
2513  GNUNET_break (0);
2514  queue_finish (queue);
2515  return;
2516  }
2517  queue->handshake_monotime_sc = GNUNET_PEERSTORE_store (peerstore,
2518  "transport_tcp_communicator",
2519  pid,
2521  handshake_monotonic_time,
2522  sizeof(
2523  handshake_monotonic_time),
2526  &
2528  queue);
2529 }
2530 
2542 static int
2544  struct TCPConfirmation *tc,
2545  char *ibuf)
2546 {
2547  struct TcpHandshakeSignature ths;
2548 
2549  GNUNET_assert (
2550  0 ==
2551  gcry_cipher_decrypt (queue->in_cipher,
2552  tc,
2553  sizeof(*tc),
2554  &ibuf[sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)],
2555  sizeof(*tc)));
2557  ths.purpose.size = htonl (sizeof(ths));
2558  ths.sender = tc->sender;
2559  ths.receiver = my_identity;
2560  memcpy (&ths.ephemeral, ibuf, sizeof(struct GNUNET_CRYPTO_EcdhePublicKey));
2561  ths.monotonic_time = tc->monotonic_time;
2562  ths.challenge = tc->challenge;
2565  &ths,
2566  &tc->sender_sig,
2567  &tc->sender.public_key);
2569  "transport_tcp_communicator",
2570  &queue->target,
2572  &
2574  queue);
2575 }
2576 
2577 
2583 static void
2585 {
2586  if (NULL != pq->listen_sock)
2587  {
2589  pq->listen_sock = NULL;
2590  }
2592  GNUNET_free (pq->address);
2593  GNUNET_CONTAINER_DLL_remove (proto_head, proto_tail, pq);
2594  GNUNET_free (pq);
2595 }
2596 
2603 static void
2604 send_challenge (struct ChallengeNonceP challenge, struct Queue *queue)
2605 {
2606  struct TCPConfirmationAck tca;
2607  struct TcpHandshakeAckSignature thas;
2608 
2610  "transport",
2611  "sending challenge\n");
2612 
2613  tca.header.type = ntohs (
2615  tca.header.size = ntohs (sizeof(tca));
2616  tca.challenge = challenge;
2617  tca.sender = my_identity;
2618  tca.monotonic_time =
2620  thas.purpose.purpose = htonl (
2622  thas.purpose.size = htonl (sizeof(thas));
2623  thas.sender = my_identity;
2624  thas.receiver = queue->target;
2625  thas.monotonic_time = tca.monotonic_time;
2626  thas.challenge = tca.challenge;
2627  GNUNET_CRYPTO_eddsa_sign (my_private_key,
2628  &thas,
2629  &tca.sender_sig);
2630  GNUNET_assert (0 ==
2631  gcry_cipher_encrypt (queue->out_cipher,
2632  &queue->cwrite_buf[queue->cwrite_off],
2633  sizeof(tca),
2634  &tca,
2635  sizeof(tca)));
2636  queue->cwrite_off += sizeof(tca);
2637 }
2638 
2645 static void
2646 proto_read_kx (void *cls)
2647 {
2648  struct ProtoQueue *pq = cls;
2649  ssize_t rcvd;
2650  struct GNUNET_TIME_Relative left;
2651  struct Queue *queue;
2652  struct TCPConfirmation tc;
2653 
2654  pq->read_task = NULL;
2656  if (0 == left.rel_value_us)
2657  {
2658  free_proto_queue (pq);
2659  return;
2660  }
2661  rcvd = GNUNET_NETWORK_socket_recv (pq->sock,
2662  &pq->ibuf[pq->ibuf_off],
2663  sizeof(pq->ibuf) - pq->ibuf_off);
2665  "Received %lu bytes for KX\n", rcvd);
2666  if (-1 == rcvd)
2667  {
2668  if ((EAGAIN != errno) && (EINTR != errno))
2669  {
2671  free_proto_queue (pq);
2672  return;
2673  }
2674  /* try again */
2675  pq->read_task =
2677  return;
2678  }
2679  pq->ibuf_off += rcvd;
2680  if (pq->ibuf_off > sizeof(pq->ibuf))
2681  {
2682  /* read more */
2683  pq->read_task =
2685  return;
2686  }
2687  /* we got all the data, let's find out who we are talking to! */
2688  queue = GNUNET_new (struct Queue);
2689  setup_in_cipher ((const struct GNUNET_CRYPTO_EcdhePublicKey *) pq->ibuf,
2690  queue);
2691  if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, pq->ibuf))
2692  {
2694  "Invalid TCP KX received from %s\n",
2695  GNUNET_a2s (queue->address, queue->address_len));
2696  gcry_cipher_close (queue->in_cipher);
2697  GNUNET_free (queue);
2698  free_proto_queue (pq);
2699  return;
2700  }
2701  queue->address = pq->address; /* steals reference */
2702  queue->address_len = pq->address_len;
2703  queue->target = tc.sender;
2704  queue->listen_sock = pq->listen_sock;
2705  queue->sock = pq->sock;
2706 
2707 
2709  "start kx proto\n");
2710 
2711  start_initial_kx_out (queue);
2713  boot_queue (queue);
2714  queue->read_task =
2716  queue->sock,
2717  &queue_read,
2718  queue);
2719  queue->write_task =
2721  queue->sock,
2722  &queue_write,
2723  queue);
2724  // TODO To early! Move it somewhere else.
2725  // send_challenge (tc, queue);
2726 
2727  GNUNET_CONTAINER_DLL_remove (proto_head, proto_tail, pq);
2728  GNUNET_free (pq);
2729 }
2730 
2731 
2739 static void
2740 listen_cb (void *cls)
2741 {
2742  struct sockaddr_storage in;
2743  socklen_t addrlen;
2744  struct GNUNET_NETWORK_Handle *sock;
2745  struct ProtoQueue *pq;
2746  struct ListenTask *lt;
2747 
2749  "listen_cb\n");
2750 
2751  lt = cls;
2752 
2753  lt->listen_task = NULL;
2754  GNUNET_assert (NULL != lt->listen_sock);
2755  addrlen = sizeof(in);
2756  memset (&in, 0, sizeof(in));
2758  (struct sockaddr*) &in,
2759  &addrlen);
2760  if ((NULL == sock) && ((EMFILE == errno) || (ENFILE == errno)))
2761  return; /* system limit reached, wait until connection goes down */
2763  lt->listen_sock,
2764  &listen_cb,
2765  lt);
2766  if ((NULL == sock) && ((EAGAIN == errno) || (ENOBUFS == errno)))
2767  return;
2768  if (NULL == sock)
2769  {
2771  return;
2772  }
2773  pq = GNUNET_new (struct ProtoQueue);
2774  pq->address_len = addrlen;
2775  pq->address = GNUNET_memdup (&in, addrlen);
2777  pq->sock = sock;
2779  pq->sock,
2780  &proto_read_kx,
2781  pq);
2782  GNUNET_CONTAINER_DLL_insert (proto_head, proto_tail, pq);
2783 }
2784 
2785 
2793 static void
2794 queue_read_kx (void *cls)
2795 {
2796  struct Queue *queue = cls;
2797  ssize_t rcvd;
2798  struct GNUNET_TIME_Relative left;
2799  struct TCPConfirmation tc;
2800 
2801  queue->read_task = NULL;
2803  if (0 == left.rel_value_us)
2804  {
2805  queue_destroy (queue);
2806  return;
2807  }
2808  rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
2809  &queue->cread_buf[queue->cread_off],
2810  BUF_SIZE - queue->cread_off);
2812  "Received %lu bytes for KX\n",
2813  rcvd);
2814  if (-1 == rcvd)
2815  {
2816  if ((EAGAIN != errno) && (EINTR != errno))
2817  {
2819  queue_destroy (queue);
2820  return;
2821  }
2822  queue->read_task =
2823  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read_kx, queue);
2824  return;
2825  }
2826  queue->cread_off += rcvd;
2827  if (queue->cread_off < INITIAL_KX_SIZE)
2828  {
2829  /* read more */
2830  queue->read_task =
2831  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read_kx, queue);
2832  return;
2833  }
2834  /* we got all the data, let's find out who we are talking to! */
2836  queue->cread_buf,
2837  queue);
2838  if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, queue->cread_buf))
2839  {
2841  "Invalid TCP KX received from %s\n",
2842  GNUNET_a2s (queue->address, queue->address_len));
2843  queue_destroy (queue);
2844  return;
2845  }
2846  if (0 !=
2847  memcmp (&tc.sender, &queue->target, sizeof(struct GNUNET_PeerIdentity)))
2848  {
2850  "Invalid sender in TCP KX received from %s\n",
2851  GNUNET_a2s (queue->address, queue->address_len));
2852  queue_destroy (queue);
2853  return;
2854  }
2855  send_challenge (tc.challenge, queue);
2856  /* update queue timeout */
2857  reschedule_queue_timeout (queue);
2858  /* prepare to continue with regular read task immediately */
2859  memmove (queue->cread_buf,
2860  &queue->cread_buf[INITIAL_KX_SIZE],
2861  queue->cread_off - (INITIAL_KX_SIZE));
2863  "cread_off is %lu bytes before adjusting\n",
2864  queue->cread_off);
2865  queue->cread_off -= INITIAL_KX_SIZE;
2867  "cread_off set to %lu bytes\n",
2868  queue->cread_off);
2869  if (0 < queue->cread_off)
2870  queue->read_task = GNUNET_SCHEDULER_add_now (&queue_read, queue);
2871 }
2872 
2891 static int
2892 mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
2893 {
2894  struct Queue *queue;
2895  const char *path;
2896  struct sockaddr *in;
2897  socklen_t in_len = 0;
2898  struct GNUNET_NETWORK_Handle *sock;
2899 
2901  "Connecting to %s\n", address);
2902  if (0 != strncmp (address,
2904  strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
2905  {
2906  GNUNET_break_op (0);
2907  return GNUNET_SYSERR;
2908  }
2909  path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
2910  in = tcp_address_to_sockaddr (path, &in_len);
2911 
2912  if (NULL == in)
2913  {
2915  "Failed to setup TCP socket address\n");
2916  return GNUNET_SYSERR;
2917  }
2918 
2920  "in %s\n",
2921  GNUNET_a2s (in, in_len));
2922 
2923  sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, IPPROTO_TCP);
2924  if (NULL == sock)
2925  {
2927  "socket(%d) failed: %s",
2928  in->sa_family,
2929  strerror (errno));
2930  GNUNET_free (in);
2931  return GNUNET_SYSERR;
2932  }
2933  if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, in_len)) &&
2934  (errno != EINPROGRESS))
2935  {
2937  "connect to `%s' failed: %s",
2938  address,
2939  strerror (errno));
2941  GNUNET_free (in);
2942  return GNUNET_SYSERR;
2943  }
2944 
2945  queue = GNUNET_new (struct Queue);
2946  queue->target = *peer;
2947  queue->address = in;
2948  queue->address_len = in_len;
2949  queue->sock = sock;
2951  boot_queue (queue);
2952  // queue->mq_awaits_continue = GNUNET_YES;
2953  queue->read_task =
2955  queue->sock,
2956  &queue_read_kx,
2957  queue);
2958 
2959 
2961  "start kx mq_init\n");
2962 
2963  start_initial_kx_out (queue);
2964  queue->write_task =
2966  queue->sock,
2967  &queue_write,
2968  queue);
2969  return GNUNET_OK;
2970 }
2971 
2980 static int
2981 get_lt_delete_it (void *cls,
2982  const struct GNUNET_HashCode *key,
2983  void *value)
2984 {
2985  struct ListenTask *lt = value;
2986 
2987  (void) cls;
2988  (void) key;
2989  if (NULL != lt->listen_task)
2990  {
2992  lt->listen_task = NULL;
2993  }
2994  if (NULL != lt->listen_sock)
2995  {
2997  lt->listen_sock = NULL;
2998  }
2999  return GNUNET_OK;
3000 }
3001 
3010 static int
3012  const struct GNUNET_PeerIdentity *target,
3013  void *value)
3014 {
3015  struct Queue *queue = value;
3016 
3017  (void) cls;
3018  (void) target;
3019  queue_destroy (queue);
3020  return GNUNET_OK;
3021 }
3022 
3028 static void
3029 do_shutdown (void *cls)
3030 {
3032  "Shutdown %s!\n",
3033  shutdown_running ? "running" : "not running");
3034 
3036  return;
3037  else
3039 
3040  while (NULL != proto_head)
3041  free_proto_queue (proto_head);
3042  if (NULL != nat)
3043  {
3044  GNUNET_NAT_unregister (nat);
3045  nat = NULL;
3046  }
3051  if (NULL != ch)
3052  {
3054  ch = NULL;
3055  }
3056  if (NULL != stats)
3057  {
3059  stats = NULL;
3060  }
3061  if (NULL != my_private_key)
3062  {
3063  GNUNET_free (my_private_key);
3064  my_private_key = NULL;
3065  }
3066  if (NULL != is)
3067  {
3069  is = NULL;
3070  }
3071  if (NULL != peerstore)
3072  {
3074  peerstore = NULL;
3075  }
3076  if (NULL != resolve_request_handle)
3077  {
3078  GNUNET_RESOLVER_request_cancel (resolve_request_handle);
3079  resolve_request_handle = NULL;
3080  }
3082  "Shutdown done!\n");
3083 }
3084 
3085 
3097 static void
3098 enc_notify_cb (void *cls,
3099  const struct GNUNET_PeerIdentity *sender,
3100  const struct GNUNET_MessageHeader *msg)
3101 {
3102  (void) cls;
3103  (void) sender;
3104  (void) msg;
3105  GNUNET_break_op (0);
3106 }
3107 
3108 
3122 static void
3123 nat_address_cb (void *cls,
3124  void **app_ctx,
3125  int add_remove,
3127  const struct sockaddr *addr,
3128  socklen_t addrlen)
3129 {
3130  char *my_addr;
3132 
3134  "nat address cb %s %s\n",
3135  add_remove ? "add" : "remove",
3136  GNUNET_a2s (addr, addrlen));
3137 
3138  if (GNUNET_YES == add_remove)
3139  {
3140  enum GNUNET_NetworkType nt;
3141 
3142  GNUNET_asprintf (&my_addr,
3143  "%s-%s",
3145  GNUNET_a2s (addr, addrlen));
3146  nt = GNUNET_NT_scanner_get_type (is, addr, addrlen);
3147  ai =
3149  my_addr,
3150  nt,
3152  GNUNET_free (my_addr);
3153  *app_ctx = ai;
3154  }
3155  else
3156  {
3157  ai = *app_ctx;
3159  *app_ctx = NULL;
3160  }
3161 }
3162 
3166 static void
3167 add_addr (struct sockaddr *in, socklen_t in_len)
3168 {
3169 
3170  struct Addresses *saddrs;
3171 
3173  "add address %s\n",
3174  GNUNET_a2s (in, in_len));
3175 
3176  saddrs = GNUNET_new (struct Addresses);
3177  saddrs->addr = in;
3178  saddrs->addr_len = in_len;
3179  GNUNET_CONTAINER_DLL_insert (addrs_head, addrs_tail, saddrs);
3180 
3182  "after add address %s\n",
3183  GNUNET_a2s (in, in_len));
3184 
3186  "add address %s\n",
3187  GNUNET_a2s (saddrs->addr, saddrs->addr_len));
3188 
3189  addrs_lens++;
3190 }
3191 
3199 static int
3200 init_socket (struct sockaddr *addr,
3201  socklen_t in_len)
3202 {
3203  struct sockaddr_storage in_sto;
3204  socklen_t sto_len;
3205  struct GNUNET_NETWORK_Handle *listen_sock;
3206  struct ListenTask *lt;
3207  struct GNUNET_HashCode h_sock;
3208 
3209  if (NULL == addr)
3210  {
3212  "Address is NULL.\n");
3213  return GNUNET_SYSERR;
3214  }
3215 
3217  "address %s\n",
3218  GNUNET_a2s (addr, in_len));
3219 
3220  listen_sock =
3221  GNUNET_NETWORK_socket_create (addr->sa_family, SOCK_STREAM, IPPROTO_TCP);
3222  if (NULL == listen_sock)
3223  {
3225  return GNUNET_SYSERR;
3226  }
3227 
3228  if (GNUNET_OK != GNUNET_NETWORK_socket_bind (listen_sock, addr, in_len))
3229  {
3231  GNUNET_NETWORK_socket_close (listen_sock);
3232  listen_sock = NULL;
3233  return GNUNET_SYSERR;
3234  }
3235 
3236  if (GNUNET_OK !=
3237  GNUNET_NETWORK_socket_listen (listen_sock,
3238  5))
3239  {
3241  "listen");
3242  GNUNET_NETWORK_socket_close (listen_sock);
3243  listen_sock = NULL;
3244  return GNUNET_SYSERR;
3245  }
3246 
3247  /* We might have bound to port 0, allowing the OS to figure it out;
3248  thus, get the real IN-address from the socket */
3249  sto_len = sizeof(in_sto);
3250 
3251  if (0 != getsockname (GNUNET_NETWORK_get_fd (listen_sock),
3252  (struct sockaddr *) &in_sto,
3253  &sto_len))
3254  {
3255  memcpy (&in_sto, addr, in_len);
3256  sto_len = in_len;
3257  }
3258 
3259  // addr = (struct sockaddr *) &in_sto;
3260  in_len = sto_len;
3262  "Bound to `%s'\n",
3263  GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len));
3264  stats = GNUNET_STATISTICS_create ("C-TCP", cfg);
3265 
3266  if (NULL == is)
3267  is = GNUNET_NT_scanner_init ();
3268 
3269  if (NULL == my_private_key)
3271  if (NULL == my_private_key)
3272  {
3273  GNUNET_log (
3275  _ (
3276  "Transport service is lacking key configuration settings. Exiting.\n"));
3277  if (NULL != resolve_request_handle)
3278  GNUNET_RESOLVER_request_cancel (resolve_request_handle);
3280  return GNUNET_SYSERR;
3281  }
3283  /* start listening */
3284 
3285  lt = GNUNET_new (struct ListenTask);
3286  lt->listen_sock = listen_sock;
3287 
3289  listen_sock,
3290  &listen_cb,
3291  lt);
3292 
3294  "creating hash\n");
3296  sizeof(lt->listen_sock),
3297  &h_sock);
3298 
3300  "creating map\n");
3301  if (NULL == lt_map)
3303 
3305  "creating map entry\n");
3307  &h_sock,
3308  lt,
3310 
3312  "map entry created\n");
3313 
3314  if (NULL == queue_map)
3316 
3317  if (NULL == ch )
3322  &mq_init,
3323  NULL,
3324  &enc_notify_cb,
3325  NULL);
3326 
3327  if (NULL == ch)
3328  {
3329  GNUNET_break (0);
3330  if (NULL != resolve_request_handle)
3331  GNUNET_RESOLVER_request_cancel (resolve_request_handle);
3333  return GNUNET_SYSERR;
3334  }
3335 
3336  add_addr (addr, in_len);
3337  return GNUNET_OK;
3338 
3339 }
3340 
3344 static void
3346 {
3347 
3348  struct sockaddr **saddrs;
3349  socklen_t *saddr_lens;
3350  int i;
3351  struct Addresses *pos;
3352 
3353 
3355  "starting nat register!\n");
3356 
3357  i = 0;
3358  saddrs = GNUNET_malloc ((addrs_lens + 1) * sizeof(struct sockaddr *));
3359 
3360  saddr_lens = GNUNET_malloc ((addrs_lens + 1) * sizeof(socklen_t));
3361 
3362  for (pos = addrs_head; NULL != pos; pos = pos->next)
3363  {
3364 
3366  "registering address %s\n",
3367  GNUNET_a2s (addrs_head->addr, addrs_head->addr_len));
3368 
3369  saddr_lens[i] = addrs_head->addr_len;
3370  saddrs[i] = GNUNET_memdup (addrs_head->addr, saddr_lens[i]);
3371 
3372  i++;
3373 
3374  }
3375 
3376  nat = GNUNET_NAT_register (cfg,
3378  IPPROTO_TCP,
3379  addrs_lens,
3380  (const struct sockaddr **) saddrs,
3381  saddr_lens,
3382  &nat_address_cb,
3383  NULL /* FIXME: support reversal: #5529 */,
3384  NULL /* closure */);
3385 
3386  i = 0;
3387 
3388  for (i = addrs_lens - 1; i >= 0; i--)
3389  GNUNET_free (saddrs[i]);
3390  GNUNET_free (saddrs);
3391  GNUNET_free (saddr_lens);
3392 
3393  if (NULL == nat)
3394  {
3395  GNUNET_break (0);
3396  if (NULL != resolve_request_handle)
3397  GNUNET_RESOLVER_request_cancel (resolve_request_handle);
3399  }
3400 }
3401 
3409 static void
3411  const struct sockaddr *addr,
3412  socklen_t in_len)
3413 {
3414  struct sockaddr_in *v4;
3415  struct sockaddr_in6 *v6;
3416  struct sockaddr *in;
3417 
3418  (void) cls;
3419  if (NULL != addr)
3420  {
3421  if (AF_INET == addr->sa_family)
3422  {
3423  v4 = (struct sockaddr_in *) addr;
3424  in = tcp_address_to_sockaddr_numeric_v4 (&in_len, *v4, bind_port);// _global);
3425  }
3426  else if (AF_INET6 == addr->sa_family)
3427  {
3428  v6 = (struct sockaddr_in6 *) addr;
3429  in = tcp_address_to_sockaddr_numeric_v6 (&in_len, *v6, bind_port);// _global);
3430  }
3431  else
3432  {
3434  "Address family %u not suitable (not AF_INET %u nor AF_INET6 %u \n",
3435  addr->sa_family,
3436  AF_INET,
3437  AF_INET6);
3438  return;
3439  }
3440  init_socket (in, in_len);
3441  }
3442  else
3443  {
3445  "Address is NULL. This might be an error or the resolver finished resolving.\n");
3446  if (NULL == addrs_head)
3447  {
3449  "Resolver finished resolving, but we do not listen to an address!.\n");
3450  return;
3451  }
3452  nat_register ();
3453 
3454  }
3455 }
3456 
3465 static void
3466 run (void *cls,
3467  char *const *args,
3468  const char *cfgfile,
3469  const struct GNUNET_CONFIGURATION_Handle *c)
3470 {
3471  char *bindto;
3472  struct sockaddr *in;
3473  socklen_t in_len;
3474  struct sockaddr_in v4;
3475  struct sockaddr_in6 v6;
3476  char *start;
3477  unsigned int port;
3478  char dummy[2];
3479  char *rest = NULL;
3480  struct PortOnlyIpv4Ipv6 *po;
3481  socklen_t addr_len_ipv4;
3482  socklen_t addr_len_ipv6;
3483 
3484  (void) cls;
3485  cfg = c;
3486  if (GNUNET_OK !=
3489  "BINDTO",
3490  &bindto))
3491  {
3494  "BINDTO");
3495  return;
3496  }
3497  if (GNUNET_OK !=
3500  "MAX_QUEUE_LENGTH",
3501  &max_queue_length))
3503  if (GNUNET_OK !=
3506  "REKEY_INTERVAL",
3507  &rekey_interval))
3509 
3510  peerstore = GNUNET_PEERSTORE_connect (cfg);
3511  if (NULL == peerstore)
3512  {
3513  GNUNET_break (0);
3515  return;
3516  }
3517 
3519 
3520  if (1 == sscanf (bindto, "%u%1s", &bind_port, dummy))
3521  {
3523 
3524  addr_len_ipv4 = po->addr_len_ipv4;
3525 
3526 
3528  "address po %s\n",
3529  GNUNET_a2s (po->addr_ipv4, addr_len_ipv4));
3530 
3531  if (NULL != po->addr_ipv4)
3532  {
3533  init_socket (po->addr_ipv4, addr_len_ipv4);
3534  }
3535 
3536  if (NULL != po->addr_ipv6)
3537  {
3538  addr_len_ipv6 = po->addr_len_ipv6;
3539  init_socket (po->addr_ipv6, addr_len_ipv6);
3540  }
3541 
3542  GNUNET_free (po);
3543  nat_register ();
3544  GNUNET_free (bindto);
3545 
3546  return;
3547  }
3548 
3549  start = extract_address (bindto);
3550 
3551  if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
3552  {
3553  bind_port = extract_port (bindto);
3554 
3555  in = tcp_address_to_sockaddr_numeric_v4 (&in_len, v4, bind_port);
3556  init_socket (in, in_len);
3557  nat_register ();
3558  GNUNET_free (bindto);
3559 
3560  return;
3561  }
3562 
3563  if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
3564  {
3565  bind_port = extract_port (bindto);
3566  in = tcp_address_to_sockaddr_numeric_v6 (&in_len, v6, bind_port);
3567  init_socket (in, in_len);
3568  nat_register ();
3569  GNUNET_free (bindto);
3570 
3571  return;
3572  }
3573 
3574 
3575  bind_port = extract_port (bindto);
3576 
3577  resolve_request_handle = GNUNET_RESOLVER_ip_get (strtok_r (bindto, ":",
3578  &rest),
3579  AF_UNSPEC,
3582  &port);
3583  GNUNET_free (bindto);
3584 }
3585 
3586 
3594 int
3595 main (int argc, char *const *argv)
3596 {
3597  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
3599  };
3600  int ret;
3601 
3602  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
3603  return 2;
3604 
3605  ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc,
3606  argv,
3607  "gnunet-communicator-tcp",
3608  _ ("GNUnet TCP communicator"),
3609  options,
3610  &run,
3611  NULL))
3612  ? 0
3613  : 1;
3614  GNUNET_free_nz ((void *) argv);
3615  return ret;
3616 }
3617 
3618 
3619 /* end of gnunet-communicator-tcp.c */
#define GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE
Signature used by TCP communicator handshake,.
In case of port only configuration we like to bind to ipv4 and ipv6 addresses.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
int GNUNET_NETWORK_socket_listen(const struct GNUNET_NETWORK_Handle *desc, int backlog)
Listen on a socket.
Definition: network.c:708
void GNUNET_TRANSPORT_communicator_address_remove_all(struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
Notify transport service that this communicator no longer provides all its addresses for this peer...
#define COMMUNICATOR_CONFIG_SECTION
Configuration section used by the communicator.
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
Handle to the interface scanner.
Definition: nt.c:110
int rekeyed
GNUNET_YES if we just rekeyed and must thus possibly re-decrypt ciphertext.
char ibuf[(sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)+sizeof(struct TCPConfirmation))]
Buffer for reading all the information we need to upgrade from protoqueue to queue.
static void listen_cb(void *cls)
We have been notified that our listen socket has something to read.
static int get_lt_delete_it(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator over all ListenTasks to clean up.
Transmission is reliabile (with ACKs), i.e.
int GNUNET_NETWORK_get_fd(const struct GNUNET_NETWORK_Handle *desc)
Return file descriptor for this network handle.
Definition: network.c:1077
static void setup_in_cipher(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, struct Queue *queue)
Setup cipher of queue for decryption.
static void queue_read_kx(void *cls)
Read from the socket of the queue until we have enough data to initialize the decryption logic and ca...
char cread_buf[(2 *64 *1024+sizeof(struct TCPBox))]
Buffer for reading ciphertext from network into.
static void init_socket_resolv(void *cls, const struct sockaddr *addr, socklen_t in_len)
This method is the callback called by the resolver API, and wraps method init_socket.
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 WANT.
Definition: nt.c:314
static void done()
struct GNUNET_PEERSTORE_IterateContext * handshake_monotime_get
Iteration Context for retrieving the monotonic time send with the handshake.
struct sockaddr * addr_ipv4
Ipv4 address we like to bind to.
Handle for active NAT registrations.
Definition: nat_api.c:71
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE_ACK.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_PeerIdentity target
To whom are we talking to.
void GNUNET_RESOLVER_request_cancel(struct GNUNET_RESOLVER_RequestHandle *rh)
Cancel a request that is still pending with the resolver.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:673
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, parse options).
Definition: program.c:363
static void handshake_monotime_cb(void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE w...
GNUNET_NAT_AddressClass
Some addresses contain sensitive information or are not suitable for global distribution.
static void core_read_finished_cb(void *cls, int success)
Core tells us it is done processing a message that transport received on a queue with status success...
uint64_t rel_value_us
The actual value.
int main(int argc, char *const *argv)
The main function for the UNIX communicator.
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
#define GNUNET_CRYPTO_eddsa_sign(priv, ps, sig)
EdDSA sign a given block.
static struct GNUNET_NAT_Handle * nat
Connection to NAT service.
int finishing
Did we enqueue a finish message and are closing down the queue?
struct GNUNET_HashCode in_hmac
Shared secret for HMAC verification on incoming data.
struct GNUNET_PeerIdentity sender
Identity of the inititor of the TCP connection (TCP client).
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
socklen_t address_len
Length of the address.
ssize_t GNUNET_NETWORK_socket_send(const struct GNUNET_NETWORK_Handle *desc, const void *buffer, size_t length)
Send data (always non-blocking).
Definition: network.c:812
static struct GNUNET_PeerIdentity my_identity
Our public key.
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
size_t cread_off
At which offset in the ciphertext read buffer should we append more ciphertext for transmission next...
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 void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Setup communicator and launch network interactions.
struct GNUNET_CRYPTO_EcdhePublicKey ephemeral
Ephemeral key used by the sender.
void GNUNET_CRYPTO_hmac_raw(const void *key, size_t key_len, const void *plaintext, size_t plaintext_len, struct GNUNET_HashCode *hmac)
Calculate HMAC of a message (RFC 2104) TODO: Shouldn&#39; this be the standard hmac function and the abov...
Definition: crypto_hash.c:274
struct GNUNET_PeerIdentity sender
Sender&#39;s identity.
Delete any previous values for the given key before storing the given value.
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.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_CONFIRMATION_ACK
TCP communicator confirmation ack.
struct GNUNET_PEERSTORE_IterateContext * GNUNET_PEERSTORE_iterate(struct GNUNET_PEERSTORE_Handle *h, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, GNUNET_PEERSTORE_Processor callback, void *callback_cls)
Iterate over records matching supplied key information.
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
DLL to store the addresses we like to register at NAT service.
struct GNUNET_CRYPTO_EddsaSignature sender_sig
Sender&#39;s signature of type GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE.
struct GNUNET_PEERSTORE_StoreContext * handshake_monotime_sc
Store Context for retrieving the monotonic time send with the handshake.
#define GNUNET_TIME_UNIT_MINUTES
One minute.
unsigned int backpressure
How may messages did we pass from this queue to CORE for which we have yet to receive an acknoweldgem...
ssize_t GNUNET_NETWORK_socket_recv(const struct GNUNET_NETWORK_Handle *desc, void *buffer, size_t length)
Read data from a connected socket (always non-blocking).
Definition: network.c:783
unsigned int bind_port
The port the communicator should be assigned to.
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
#define GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY
Signature used by TCP communicator rekey.
int destroyed
Did we technically destroy this queue, but kept the allocation around because of backpressure not bei...
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
struct ChallengeNonceP challenge
Challenge value used to protect against replay attack, if there is no stored monotonic time value...
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
size_t value_size
Size of value BLOB.
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1459
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
struct ListenTask * lts_tail
Head of DLL with ListenTask.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY
TCP communicator rekey message.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void proto_read_kx(void *cls)
Read from the socket of the proto queue until we have enough data to upgrade to full queue...
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition: scheduler.c:423
struct ChallengeNonceP challenge
Challenge value used to protect against replay attack, if there is no stored monotonic time value...
uint64_t rekey_left_bytes
How many more bytes may we sent with the current out_cipher before we should rekey?
#define BUF_SIZE
Size of our IO buffers for ciphertext data.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_CONFIRMATION_ACK.
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
#define PROTO_QUEUE_TIMEOUT
How long do we wait until we must have received the initial KX?
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_write_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *wfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1588
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static void pass_plaintext_to_core(struct Queue *queue, const void *plaintext, size_t plaintext_len)
We received plaintext_len bytes of plaintext on queue.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
static struct PortOnlyIpv4Ipv6 * tcp_address_to_sockaddr_port_only(const char *bindto, unsigned int *port)
Convert TCP bind specification to a struct PortOnlyIpv4Ipv6 *
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.
struct GNUNET_TIME_Absolute rekey_time
Until what time may we sent with the current out_cipher before we should rekey?
int addrs_lens
Number of addresses in the DLL for register at NAT service.
struct GNUNET_RESOLVER_RequestHandle * GNUNET_RESOLVER_ip_get(const char *hostname, int af, struct GNUNET_TIME_Relative timeout, GNUNET_RESOLVER_AddressCallback callback, void *callback_cls)
Convert a string to one or more IP addresses.
Definition: resolver_api.c:939
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
static void transmit_kx(struct Queue *queue, const struct GNUNET_CRYPTO_EcdhePublicKey *epub)
Generate and transmit our ephemeral key and the signature for the initial KX with the other peer...
socklen_t addr_len_ipv4
Length of ipv4 address.
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
struct GNUNET_CRYPTO_EcdhePrivateKey ephemeral
Our ephemeral key.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Definition of a command line option.
#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY
Key used to store sender&#39;s monotonic time from rekey message.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX
TCP communicator payload box.
#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE
Key used to store sender&#39;s monotonic time from handshake message.
struct GNUNET_RESOLVER_RequestHandle * resolve_request_handle
Handle for DNS lookup of bindto address.
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
static void calculate_hmac(struct GNUNET_HashCode *hmac_secret, const void *buf, size_t buf_size, struct GNUNET_ShortHashCode *smac)
Compute mac over buf, and ratched the hmac_secret.
struct GNUNET_SCHEDULER_Task * listen_task
ID of listen task.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
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.
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).
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531
Handle for the service.
static void queue_read(void *cls)
Queue read task.
#define GNUNET_CRYPTO_eddsa_verify(purp, ps, sig, pub)
Verify EdDSA signature.
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_strdup(a)
Wrapper around GNUNET_xstrdup_.
static void rekey_monotime_store_cb(void *cls, int success)
Callback called when peerstore store operation for rekey monotime value is finished.
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
uint64_t abs_value_us
The actual value.
static struct GNUNET_PEERSTORE_Handle * peerstore
Size of data received without KX challenge played back.
struct GNUNET_MQ_Handle * mq
Message queue we are providing for the ch.
Internal representation of the hash map.
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:35
Handle for an incoming connection where we do not yet have enough information to setup a full queue...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct Addresses * prev
Kept in a DLL.
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won&#39;t work on W32.
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
static void inject_rekey(struct Queue *queue)
Inject a struct TCPRekey message into the queue&#39;s plaintext buffer.
struct GNUNET_PeerIdentity sender
Identity of the inititor of the TCP connection (TCP client).
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
A 256-bit hashcode.
Opaque handle to the transport service for communicators.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
#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.
static int decrypt_and_check_tc(struct Queue *queue, struct TCPConfirmation *tc, char *ibuf)
We have received the first bytes from the other side on a queue.
Signature we use to verify that the ack from the receiver of the ephemeral key was really send by the...
struct GNUNET_PeerIdentity sender
Identity of the inititor of the TCP connection (TCP client).
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_accept(const struct GNUNET_NETWORK_Handle *desc, struct sockaddr *address, socklen_t *address_len)
Accept a new connection on a socket.
Definition: network.c:430
Signature we use to verify that the ephemeral key was really chosen by the specified sender...
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
static struct GNUNET_TIME_Relative rekey_interval
The rekey interval.
static unsigned long long max_queue_length
Maximum queue length before we stop reading towards the transport service.
void GNUNET_TRANSPORT_communicator_mq_del(struct GNUNET_TRANSPORT_QueueHandle *qh)
Notify transport service that an MQ became unavailable due to a disconnect or timeout.
#define INITIAL_KX_SIZE
Size of the initial key exchange message sent first in both directions.
struct GNUNET_HashCode out_hmac
Shared secret for HMAC generation on outgoing data, ratcheted after each operation.
#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...
void GNUNET_CRYPTO_ecdhe_key_create(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:419
static void enc_notify_cb(void *cls, const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *msg)
Function called when the transport service has received an acknowledgement for this communicator (!) ...
int GNUNET_NETWORK_socket_connect(const struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Connect a socket to some remote address.
Definition: network.c:658
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
unsigned long long bytes_in_queue
Number of bytes we currently have in our write queue.
static struct GNUNET_CONTAINER_MultiPeerMap * queue_map
Queues (map from peer identity to struct Queue)
struct GNUNET_PEERSTORE_IterateContext * rekey_monotime_get
Iteration Context for retrieving the monotonic time send with key for rekeying.
static struct sockaddr * tcp_address_to_sockaddr_numeric_v4(socklen_t *sock_len, struct sockaddr_in v4, unsigned int port)
Convert a struct sockaddr_in4 to astruct sockaddr *`.
struct GNUNET_TIME_AbsoluteNBO handshake_ack_monotonic_time
Monotonic time value for handshake ack message.
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
static void queue_destroy(struct Queue *queue)
Functions with this signature are called whenever we need to close a queue due to a disconnect or fai...
void * value
Record value BLOB.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
static char * value
Value of the record to add/remove.
const char * GNUNET_p2s(const struct GNUNET_CRYPTO_EddsaPublicKey *p)
Convert a public key value to a string (for printing debug messages).
Handle for a queue.
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:867
#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:41
void GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h, int sync_first)
Disconnect from the PEERSTORE service.
Context for a store request.
Definition: peerstore_api.c:96
struct GNUNET_PEERSTORE_StoreContext * GNUNET_PEERSTORE_store(struct GNUNET_PEERSTORE_Handle *h, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, const void *value, size_t size, struct GNUNET_TIME_Absolute expiry, enum GNUNET_PEERSTORE_StoreOption options, GNUNET_PEERSTORE_Continuation cont, void *cont_cls)
Store a new entry in the PEERSTORE.
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
size_t cwrite_off
At which offset in the ciphertext write buffer should we append more ciphertext from reading next...
#define COMMUNICATOR_ADDRESS_PREFIX
Address prefix used by the communicator.
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:93
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:702
#define GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE_ACK
Signature by a peer sending back the nonce received at initial handshake.
Randomness for IVs etc.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_kdf(void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
Derive key.
Definition: crypto_kdf.c:90
static char buf[2048]
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Our private key.
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.
void GNUNET_PEERSTORE_store_cancel(struct GNUNET_PEERSTORE_StoreContext *sc)
Cancel a store request.
struct GNUNET_PEERSTORE_StoreContext * rekey_monotime_sc
Store Context for retrieving the monotonic time send with key for rekeying.
static void setup_cipher(const struct GNUNET_HashCode *dh, const struct GNUNET_PeerIdentity *pid, gcry_cipher_hd_t *cipher, struct GNUNET_HashCode *hmac_key)
Setup cipher based on shared secret dh and decrypting peer pid.
this is an inbound connection (communicator initiated)
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static void mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state)
Signature of functions implementing the destruction of a message queue.
struct GNUNET_CRYPTO_EddsaSignature sender_sig
Sender&#39;s signature of type GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE_ACK.
static void reschedule_queue_timeout(struct Queue *queue)
Increment queue timeout due to activity.
static void queue_finish(struct Queue *queue)
Append a &#39;finish&#39; message to the outgoing transmission.
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)...
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH.
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
struct GNUNET_TIME_Absolute timeout
Timeout for this protoqueue.
struct sockaddr * addr_ipv6
Ipv6 address we like to bind to.
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_SCHEDULER_Task * write_task
ID of write task for this connection.
struct sockaddr * address
Address of the other peer.
struct Addresses * addrs_head
Head of DLL with addresses we like to register at NAT servcie.
Handle to the PEERSTORE service.
Definition: peerstore_api.c:40
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
A 512-bit hashcode.
struct GNUNET_CRYPTO_EddsaSignature sender_sig
Sender&#39;s signature of type GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH
TCP communicator end of stream.
struct ChallengeNonceP challenge
Challenge value used to protect against replay attack, if there is no stored monotonic time value...
char cwrite_buf[(2 *64 *1024+sizeof(struct TCPBox))]
buffer for writing ciphertext to network.
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
static void do_rekey(struct Queue *queue, const struct TCPRekey *rekey)
Handle rekey message on queue.
char pwrite_buf[UINT16_MAX+1+sizeof(struct TCPBox)]
Plaintext buffer for messages to be encrypted.
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
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
static struct sockaddr * tcp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
Convert TCP bind specification to a struct sockaddr *
static void mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state)
Implementation function that cancels the currently sent message.
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
struct ChallengeNonceP challenge
Challenge value used to protect against replay attack, if there is no stored monotonic time value...
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
#define GNUNET_free_nz(ptr)
Wrapper around free.
struct GNUNET_CRYPTO_EcdhePublicKey ephemeral
New ephemeral key.
size_t pread_off
At which offset in the plaintext input buffer should we append more plaintext from decryption next...
struct Addresses * next
Kept in a DLL.
int mq_awaits_continue
Is MQ awaiting a GNUNET_MQ_impl_send_continue() call?
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
There must only be one value per key; storing a value should fail if a value under the same key alrea...
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...
static void handshake_monotime_store_cb(void *cls, int success)
Callback called when peerstore store operation for handshake monotime is finished.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_HashCode key
The key used in the DHT.
static unsigned int size
Size of the "table".
Definition: peer.c:67
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:197
struct GNUNET_PeerIdentity sender
Sender&#39;s identity.
struct GNUNET_PEERSTORE_IterateContext * handshake_ack_monotime_get
Iteration Context for retrieving the monotonic time send with the handshake ack.
static int get_queue_delete_it(void *cls, const struct GNUNET_PeerIdentity *target, void *value)
Iterator over all message queues to clean up.
struct GNUNET_PEERSTORE_Handle * GNUNET_PEERSTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the PEERSTORE service.
Handle to a request given to the resolver.
Definition: resolver_api.c:102
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 char * extract_address(const char *bindto)
This Method extracts the address part of the BINDTO string.
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.
static void mq_send(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *msg, void *impl_state)
Signature of functions implementing the sending functionality of a message queue. ...
struct GNUNET_NT_InterfaceScanner * GNUNET_NT_scanner_init(void)
Initialize the address characterization client handle.
Definition: nt.c:412
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 ChallengeNonceP challenge
Challenge value used to protect against replay attack, if there is no stored monotonic time value...
static struct ProtoQueue * proto_tail
Protoqueues DLL tail.
struct GNUNET_PeerIdentity receiver
Presumed identity of the target of the TCP connection (TCP server)
static void rekey_monotime_cb(void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY where...
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
#define DEFAULT_MAX_QUEUE_LENGTH
How many messages do we keep at most in the queue to the transport service before we start to drop (d...
int GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
static struct GNUNET_CONTAINER_MultiHashMap * lt_map
ListenTasks (map from socket to struct ListenTask)
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:837
Type of a nonce used for challenges.
struct Addresses * addrs_tail
Head of DLL with addresses we like to register at NAT servcie.
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.
TCP message box.
static void start_initial_kx_out(struct Queue *queue)
Initialize our key material for outgoing transmissions and inform the other peer about it...
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
an ECC signature using EdDSA.
struct GNUNET_PeerIdentity receiver
Presumed identity of the target of the TCP connection (TCP server)
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:181
struct GNUNET_TIME_AbsoluteNBO rekey_monotonic_time
Monotonic time value for rekey message.
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
void GNUNET_log_from_nocheck(enum GNUNET_ErrorType kind, const char *comp, const char *message,...) __attribute__((format(printf
Log function that specifies an alternative component.
#define REKEY_MAX_BYTES
How often do we rekey based on number of bytes transmitted? (additionally randomized).
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
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.
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
struct GNUNET_PeerIdentity receiver
Presumed identity of the target of the TCP connection (TCP server)
socklen_t address_len
Length of the address.
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won&#39;t work on W32;.
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.
static void nat_register()
This method reads from the DLL addrs_head to register them at the NAT service.
int shutdown_running
A flag indicating we are already doing a shutdown.
The identity of the host (wraps the signing key of the peer).
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:827
static void free_proto_queue(struct ProtoQueue *pq)
Closes socket and frees memory associated with pq.
Ack for the encrypted continuation of TCP initial handshake.
struct sockaddr * address
Address of the other peer.
size_t ibuf_off
Current offset for reading into ibuf.
static void setup_out_cipher(struct Queue *queue)
Setup cipher for outgoing data stream based on target and our ephemeral private key.
#define GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED
Queue length.
TCP rekey message box.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:82
struct GNUNET_ShortHashCode hmac
HMAC for the following encrypted message.
struct sockaddr * addr
Address we like to register at NAT service.
configuration data
Definition: configuration.c:84
struct GNUNET_TIME_AbsoluteNBO handshake_monotonic_time
Monotonic time value for handshake message.
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.
this is an outbound connection (transport initiated)
struct GNUNET_CRYPTO_EcdhePublicKey ephemeral
Ephemeral key used by the sender.
struct GNUNET_PEERSTORE_StoreContext * handshake_ack_monotime_sc
Store Context for retrieving the monotonic time send with the handshake ack.
static void handshake_ack_monotime_store_cb(void *cls, int success)
Callback called when peerstore store operation for handshake ack monotime value is finished...
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
enum GNUNET_TRANSPORT_ConnectionStatus cs
The connection status of this queue.
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
Encrypted continuation of TCP initial handshake.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
Single PEERSTORE record.
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
#define ADDRESS_VALIDITY_PERIOD
How long do we believe our addresses to remain up (before the other peer should revalidate).
size_t pwrite_off
At which offset in the plaintext output buffer should we append more plaintext for encryption next...
#define GNUNET_log(kind,...)
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 ...
Entry in list of pending tasks.
Definition: scheduler.c:134
struct ProtoQueue * next
Kept in a DLL.
struct ListenTask * lts_head
Head of DLL with ListenTasks.
static void boot_queue(struct Queue *queue)
Add the given queue to our internal data structure.
void GNUNET_PEERSTORE_iterate_cancel(struct GNUNET_PEERSTORE_IterateContext *ic)
Cancel an iterate request Please do not call after the iterate request is done.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY.
static unsigned int extract_port(const char *addr_and_port)
This Method extracts the port part of the BINDTO string.
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX.
handle to a socket
Definition: network.c:52
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
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".
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
struct GNUNET_ShortHashCode hmac
HMAC for the following encrypted message.
struct ProtoQueue * prev
Kept in a DLL.
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 size_t try_handle_plaintext(struct Queue *queue)
Test if we have received a full message in plaintext.
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...
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
socklen_t addr_len
Length of address we like to register at NAT service.
socklen_t addr_len_ipv6
Length of ipv6 address.
static struct sockaddr * tcp_address_to_sockaddr_numeric_v6(socklen_t *sock_len, struct sockaddr_in6 v6, unsigned int port)
Convert a struct sockaddr_in6 to astruct sockaddr *`.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
static void add_addr(struct sockaddr *in, socklen_t in_len)
This method adds addresses to the DLL, that are later register at the NAT service.
gcry_cipher_hd_t in_cipher
cipher for decryption of incoming data.
Header for all communications.
Time for absolute times used by GNUnet, in microseconds.
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
GNUNET_TRANSPORT_ConnectionStatus
Possible states of a connection.
struct GNUNET_NETWORK_Handle * listen_sock
Listen socket.
enum GNUNET_NetworkType nt
Which network type does this queue use?
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE.
struct GNUNET_TIME_Absolute timeout
Timeout for this queue.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY.
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:758
static void do_shutdown(void *cls)
Shutdown the UNIX communicator.
const char * GNUNET_e2s(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key value to a string (for printing debug messages).
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
struct GNUNET_ShortHashCode hmac
HMAC for the following encrypted message.
#define DEFAULT_REKEY_INTERVAL
How often do we rekey based on time (at least)
static int init_socket(struct sockaddr *addr, socklen_t in_len)
This method launch network interactions for each address we like to bind to.
static struct ProtoQueue * proto_head
Protoqueues DLL head.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK
Key used to store sender&#39;s monotonic time from handshake ack message.
struct GNUNET_TRANSPORT_QueueHandle * qh
handle for this queue with the ch.
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
gcry_cipher_hd_t out_cipher
cipher for encryption of outgoing data.
static void handshake_ack_monotime_cb(void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_A...
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Handle returned to identify the internal data structure the transport API has created to manage a mes...
char pread_buf[UINT16_MAX+1+sizeof(struct TCPBox)]
Plaintext buffer for decrypted plaintext.
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:560
Signature we use to verify that the ephemeral key was really chosen by the specified sender...
static void send_challenge(struct ChallengeNonceP challenge, struct Queue *queue)
Sending challenge with TcpConfirmationAck back to sender of ephemeral key.
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
Struct to use as closure.
#define GNUNET_malloc(size)
Wrapper around malloc.
int GNUNET_NETWORK_test_pf(int pf)
Test if the given protocol family is supported by this system.
Definition: network.c:85
Context for a iterate request.
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:909
static void queue_write(void *cls)
We have been notified that our socket is ready to write.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972