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 
595  struct ChallengeNonceP challenge_received;
596 
601 
606 
611 
616 
621 
626 };
627 
628 
634 {
638  struct ProtoQueue *next;
639 
643  struct ProtoQueue *prev;
644 
649 
654 
659 
663  struct sockaddr *address;
664 
668  socklen_t address_len;
669 
674 
679  char ibuf[INITIAL_KX_SIZE];
680 
684  size_t ibuf_off;
685 };
686 
691 {
695  struct sockaddr *addr_ipv4;
696 
700  socklen_t addr_len_ipv4;
701 
705  struct sockaddr *addr_ipv6;
706 
710  socklen_t addr_len_ipv6;
711 
712 };
713 
717 struct Addresses
718 {
722  struct Addresses *next;
723 
727  struct Addresses *prev;
728 
732  struct sockaddr *addr;
733 
737  socklen_t addr_len;
738 
739 };
740 
741 
745 static unsigned long long max_queue_length;
746 
751 
756 
761 
766 
771 
776 
781 
785 static const struct GNUNET_CONFIGURATION_Handle *cfg;
786 
791 
795 static struct GNUNET_NAT_Handle *nat;
796 
800 static struct ProtoQueue *proto_head;
801 
805 static struct ProtoQueue *proto_tail;
806 
811 
816 
821 
826 
831 
836 
840 // TODO remove?
842 
847 
852 
856 unsigned int bind_port;
857 
865 static void
866 listen_cb (void *cls);
867 
875 static void
877 {
878  struct ListenTask *lt = NULL;
879  struct GNUNET_HashCode h_sock;
880  int sockfd;
881 
882  sockfd = GNUNET_NETWORK_get_fd (queue->listen_sock);
883  GNUNET_CRYPTO_hash (&sockfd,
884  sizeof(int),
885  &h_sock);
886 
887  lt = GNUNET_CONTAINER_multihashmap_get (lt_map, &h_sock);
888 
890  "Disconnecting queue for peer `%s'\n",
891  GNUNET_i2s (&queue->target));
892  if (NULL != queue->rekey_monotime_sc)
893  {
895  queue->rekey_monotime_sc = NULL;
896  }
897  if (NULL != queue->handshake_monotime_sc)
898  {
900  queue->handshake_monotime_sc = NULL;
901  }
902  if (NULL != queue->handshake_ack_monotime_sc)
903  {
905  queue->handshake_ack_monotime_sc = NULL;
906  }
907  if (NULL != queue->rekey_monotime_get)
908  {
910  queue->rekey_monotime_get = NULL;
911  }
912  if (NULL != queue->handshake_monotime_get)
913  {
915  queue->handshake_monotime_get = NULL;
916  }
917  if (NULL != queue->handshake_ack_monotime_get)
918  {
920  queue->handshake_ack_monotime_get = NULL;
921  }
922  if (NULL != queue->qh)
923  {
925  queue->qh = NULL;
926  }
927  GNUNET_assert (
928  GNUNET_YES ==
929  GNUNET_CONTAINER_multipeermap_remove (queue_map, &queue->target, queue));
930  GNUNET_STATISTICS_set (stats,
931  "# queues active",
933  GNUNET_NO);
934  if (NULL != queue->read_task)
935  {
937  queue->read_task = NULL;
938  }
939  if (NULL != queue->write_task)
940  {
942  queue->write_task = NULL;
943  }
945  {
947  "closing socket failed\n");
948  }
949  gcry_cipher_close (queue->in_cipher);
950  gcry_cipher_close (queue->out_cipher);
951  GNUNET_free (queue->address);
952  if (0 != queue->backpressure)
953  queue->destroyed = GNUNET_YES;
954  else
955  GNUNET_free (queue);
956 
957  if (NULL == lt)
958  return;
959 
960  if ((! shutdown_running) && (NULL == lt->listen_task))
961  {
963  "add read net listen\n");
966  lt->listen_sock,
967  &listen_cb,
968  lt);
969  }
970  else
971  GNUNET_free (lt);
972 }
973 
974 
983 static void
984 calculate_hmac (struct GNUNET_HashCode *hmac_secret,
985  const void *buf,
986  size_t buf_size,
987  struct GNUNET_ShortHashCode *smac)
988 {
989  struct GNUNET_HashCode mac;
990 
991  GNUNET_CRYPTO_hmac_raw (hmac_secret,
992  sizeof(struct GNUNET_HashCode),
993  buf,
994  buf_size,
995  &mac);
996  /* truncate to `struct GNUNET_ShortHashCode` */
997  memcpy (smac, &mac, sizeof(struct GNUNET_ShortHashCode));
998  /* ratchet hmac key */
999  GNUNET_CRYPTO_hash (hmac_secret,
1000  sizeof(struct GNUNET_HashCode),
1001  hmac_secret);
1002 }
1003 
1004 
1011 static void
1013 {
1014  struct TCPFinish fin;
1015 
1016  memset (&fin, 0, sizeof(fin));
1017  fin.header.size = htons (sizeof(fin));
1019  calculate_hmac (&queue->out_hmac, &fin, sizeof(fin), &fin.hmac);
1020  /* if there is any message left in pwrite_buf, we
1021  overwrite it (possibly dropping the last message
1022  from CORE hard here) */
1023  memcpy (queue->pwrite_buf, &fin, sizeof(fin));
1024  queue->pwrite_off = sizeof(fin);
1025  /* This flag will ensure that #queue_write() no longer
1026  notifies CORE about the possibility of sending
1027  more data, and that #queue_write() will call
1028  #queue_destroy() once the @c fin was fully written. */
1029  queue->finishing = GNUNET_YES;
1030 }
1031 
1032 
1040 static void
1042 {
1043  queue->timeout =
1045 }
1046 
1047 
1053 static void
1054 queue_read (void *cls);
1055 
1056 
1064 static void
1065 core_read_finished_cb (void *cls, int success)
1066 {
1067  struct Queue *queue = cls;
1068  if (GNUNET_OK != success)
1069  GNUNET_STATISTICS_update (stats,
1070  "# messages lost in communicator API towards CORE",
1071  1,
1072  GNUNET_NO);
1073  if (NULL == queue)
1074  return;
1075 
1077  "backpressure %u\n",
1078  queue->backpressure);
1079 
1080  queue->backpressure--;
1081  /* handle deferred queue destruction */
1082  if ((queue->destroyed) && (0 == queue->backpressure))
1083  {
1084  GNUNET_free (queue);
1085  return;
1086  }
1087  else if (GNUNET_YES != queue->destroyed)
1088  {
1089  reschedule_queue_timeout (queue);
1090  /* possibly unchoke reading, now that CORE made progress */
1091  if (NULL == queue->read_task)
1092  queue->read_task =
1094  queue->timeout),
1095  queue->sock,
1096  &queue_read,
1097  queue);
1098  }
1099 }
1100 
1101 
1111 static void
1113  const void *plaintext,
1114  size_t plaintext_len)
1115 {
1116  const struct GNUNET_MessageHeader *hdr = plaintext;
1117  int ret;
1118 
1119  if (ntohs (hdr->size) != plaintext_len)
1120  {
1121  /* NOTE: If we ever allow multiple CORE messages in one
1122  BOX, this will have to change! */
1123  GNUNET_break (0);
1124  return;
1125  }
1127  &queue->target,
1128  hdr,
1131  queue);
1132  if (GNUNET_OK == ret)
1133  queue->backpressure++;
1134  GNUNET_break (GNUNET_NO != ret); /* backpressure not working!? */
1135  if (GNUNET_SYSERR == ret)
1136  GNUNET_STATISTICS_update (stats,
1137  "# bytes lost due to CORE not running",
1138  plaintext_len,
1139  GNUNET_NO);
1140 }
1141 
1142 
1152 static void
1153 setup_cipher (const struct GNUNET_HashCode *dh,
1154  const struct GNUNET_PeerIdentity *pid,
1155  gcry_cipher_hd_t *cipher,
1156  struct GNUNET_HashCode *hmac_key)
1157 {
1158  char key[256 / 8];
1159  char ctr[128 / 8];
1160 
1161  GNUNET_assert (0 == gcry_cipher_open (cipher,
1162  GCRY_CIPHER_AES256 /* low level: go for speed */,
1163  GCRY_CIPHER_MODE_CTR,
1164  0 /* flags */));
1166  sizeof(key),
1167  "TCP-key",
1168  strlen ("TCP-key"),
1169  dh,
1170  sizeof(*dh),
1171  pid,
1172  sizeof(*pid),
1173  NULL,
1174  0));
1175  GNUNET_assert (0 == gcry_cipher_setkey (*cipher, key, sizeof(key)));
1177  sizeof(ctr),
1178  "TCP-ctr",
1179  strlen ("TCP-ctr"),
1180  dh,
1181  sizeof(*dh),
1182  pid,
1183  sizeof(*pid),
1184  NULL,
1185  0));
1186  gcry_cipher_setctr (*cipher, ctr, sizeof(ctr));
1188  GNUNET_CRYPTO_kdf (hmac_key,
1189  sizeof(struct GNUNET_HashCode),
1190  "TCP-hmac",
1191  strlen ("TCP-hmac"),
1192  dh,
1193  sizeof(*dh),
1194  pid,
1195  sizeof(*pid),
1196  NULL,
1197  0));
1198 }
1199 
1200 
1206 static void
1207 rekey_monotime_store_cb (void *cls, int success)
1208 {
1209  struct Queue *queue = cls;
1210  if (GNUNET_OK != success)
1211  {
1213  "Failed to store rekey monotonic time in PEERSTORE!\n");
1214  }
1215  queue->rekey_monotime_sc = NULL;
1216 }
1217 
1218 
1226 static void
1228  const struct GNUNET_PEERSTORE_Record *record,
1229  const char *emsg)
1230 {
1231  struct Queue *queue = cls;
1232  struct GNUNET_TIME_AbsoluteNBO *mtbe;
1233  struct GNUNET_TIME_Absolute mt;
1234  const struct GNUNET_PeerIdentity *pid;
1235  struct GNUNET_TIME_AbsoluteNBO *rekey_monotonic_time;
1236 
1237  (void) emsg;
1238 
1239  rekey_monotonic_time = &queue->rekey_monotonic_time;
1240  pid = &queue->target;
1241  if (NULL == record)
1242  {
1243  queue->rekey_monotime_get = NULL;
1244  return;
1245  }
1246  if (sizeof(*mtbe) != record->value_size)
1247  {
1248  GNUNET_break (0);
1249  return;
1250  }
1251  mtbe = record->value;
1252  mt = GNUNET_TIME_absolute_ntoh (*mtbe);
1255  {
1257  "Queue from %s dropped, rekey monotime in the past\n",
1258  GNUNET_i2s (&queue->target));
1259  GNUNET_break (0);
1260  queue_finish (queue);
1261  return;
1262  }
1263  queue->rekey_monotime_sc = GNUNET_PEERSTORE_store (peerstore,
1264  "transport_tcp_communicator",
1265  pid,
1267  rekey_monotonic_time,
1268  sizeof(*
1269  rekey_monotonic_time),
1273  queue);
1274 }
1275 
1276 
1283 static void
1285  struct Queue *queue)
1286 {
1287  struct GNUNET_HashCode dh;
1288 
1289  GNUNET_CRYPTO_eddsa_ecdh (my_private_key, ephemeral, &dh);
1290  setup_cipher (&dh, &my_identity, &queue->in_cipher, &queue->in_hmac);
1291 }
1292 
1293 
1302 static void
1303 do_rekey (struct Queue *queue, const struct TCPRekey *rekey)
1304 {
1305  struct TcpRekeySignature thp;
1306 
1308  thp.purpose.size = htonl (sizeof(thp));
1310  "do_rekey size %u\n",
1311  thp.purpose.size);
1312  thp.sender = queue->target;
1314  "sender %s\n",
1315  GNUNET_p2s (&thp.sender.public_key));
1317  "sender %s\n",
1318  GNUNET_p2s (&queue->target.public_key));
1319  thp.receiver = my_identity;
1321  "receiver %s\n",
1322  GNUNET_p2s (&thp.receiver.public_key));
1323  thp.ephemeral = rekey->ephemeral;
1325  "ephemeral %s\n",
1326  GNUNET_e2s (&thp.ephemeral));
1327  thp.monotonic_time = rekey->monotonic_time;
1329  "time %s\n",
1332  GNUNET_assert (ntohl ((&thp)->purpose.size) == sizeof (*(&thp)));
1333  if (GNUNET_OK !=
1335  &thp,
1336  &rekey->sender_sig,
1337  &queue->target.public_key))
1338  {
1339  GNUNET_break (0);
1340  queue_finish (queue);
1341  return;
1342  }
1343  queue->rekey_monotonic_time = rekey->monotonic_time;
1344  queue->rekey_monotime_get = GNUNET_PEERSTORE_iterate (peerstore,
1345  "transport_tcp_communicator",
1346  &queue->target,
1349  queue);
1350  gcry_cipher_close (queue->in_cipher);
1351  queue->rekeyed = GNUNET_YES;
1352  setup_in_cipher (&rekey->ephemeral, queue);
1353 }
1354 
1355 
1361 static void
1362 handshake_ack_monotime_store_cb (void *cls, int success)
1363 {
1364  struct Queue *queue = cls;
1365 
1366  if (GNUNET_OK != success)
1367  {
1369  "Failed to store handshake ack monotonic time in PEERSTORE!\n");
1370  }
1371  queue->handshake_ack_monotime_sc = NULL;
1372 }
1373 
1374 
1382 static void
1384  const struct GNUNET_PEERSTORE_Record *record,
1385  const char *emsg)
1386 {
1387  struct Queue *queue = cls;
1388  struct GNUNET_TIME_AbsoluteNBO *mtbe;
1389  struct GNUNET_TIME_Absolute mt;
1390  const struct GNUNET_PeerIdentity *pid;
1391  struct GNUNET_TIME_AbsoluteNBO *handshake_ack_monotonic_time;
1392 
1393  (void) emsg;
1394 
1395  handshake_ack_monotonic_time = &queue->handshake_ack_monotonic_time;
1396  pid = &queue->target;
1397  if (NULL == record)
1398  {
1399  queue->handshake_ack_monotime_get = NULL;
1400  return;
1401  }
1402  if (sizeof(*mtbe) != record->value_size)
1403  {
1404  GNUNET_break (0);
1405  return;
1406  }
1407  mtbe = record->value;
1408  mt = GNUNET_TIME_absolute_ntoh (*mtbe);
1411  {
1413  "Queue from %s dropped, handshake ack monotime in the past\n",
1414  GNUNET_i2s (&queue->target));
1415  GNUNET_break (0);
1416  queue_finish (queue);
1417  return;
1418  }
1419  queue->handshake_ack_monotime_sc =
1420  GNUNET_PEERSTORE_store (peerstore,
1421  "transport_tcp_communicator",
1422  pid,
1424  handshake_ack_monotonic_time,
1425  sizeof(*handshake_ack_monotonic_time),
1428  &
1430  queue);
1431 }
1432 
1433 
1440 static void
1441 send_challenge (struct ChallengeNonceP challenge, struct Queue *queue)
1442 {
1443  struct TCPConfirmationAck tca;
1444  struct TcpHandshakeAckSignature thas;
1445 
1447  "transport",
1448  "sending challenge\n");
1449 
1450  tca.header.type = ntohs (
1452  tca.header.size = ntohs (sizeof(tca));
1453  tca.challenge = challenge;
1454  tca.sender = my_identity;
1455  tca.monotonic_time =
1457  thas.purpose.purpose = htonl (
1459  thas.purpose.size = htonl (sizeof(thas));
1460  thas.sender = my_identity;
1461  thas.receiver = queue->target;
1462  thas.monotonic_time = tca.monotonic_time;
1463  thas.challenge = tca.challenge;
1464  GNUNET_CRYPTO_eddsa_sign (my_private_key,
1465  &thas,
1466  &tca.sender_sig);
1467  GNUNET_assert (0 ==
1468  gcry_cipher_encrypt (queue->out_cipher,
1469  &queue->cwrite_buf[queue->cwrite_off],
1470  sizeof(tca),
1471  &tca,
1472  sizeof(tca)));
1473  queue->cwrite_off += sizeof(tca);
1475  "transport",
1476  "sending challenge done\n");
1477 }
1478 
1479 
1486 static void
1488 {
1489  struct GNUNET_HashCode dh;
1490 
1491  GNUNET_CRYPTO_ecdh_eddsa (&queue->ephemeral, &queue->target.public_key, &dh);
1492  /* we don't need the private key anymore, drop it! */
1493  memset (&queue->ephemeral, 0, sizeof(queue->ephemeral));
1494  setup_cipher (&dh, &queue->target, &queue->out_cipher, &queue->out_hmac);
1496  queue->rekey_left_bytes =
1498 }
1499 
1500 
1507 static void
1509 {
1510  struct TCPRekey rekey;
1511  struct TcpRekeySignature thp;
1512 
1513  GNUNET_assert (0 == queue->pwrite_off);
1514  memset (&rekey, 0, sizeof(rekey));
1517  rekey.header.size = ntohs (sizeof(rekey));
1519  rekey.monotonic_time =
1522  thp.purpose.size = htonl (sizeof(thp));
1524  "inject_rekey size %u\n",
1525  thp.purpose.size);
1526  thp.sender = my_identity;
1528  "sender %s\n",
1529  GNUNET_p2s (&thp.sender.public_key));
1530  thp.receiver = queue->target;
1532  "receiver %s\n",
1533  GNUNET_p2s (&thp.receiver.public_key));
1534  thp.ephemeral = rekey.ephemeral;
1536  "ephemeral %s\n",
1537  GNUNET_e2s (&thp.ephemeral));
1538  thp.monotonic_time = rekey.monotonic_time;
1540  "time %s\n",
1543  GNUNET_CRYPTO_eddsa_sign (my_private_key,
1544  &thp,
1545  &rekey.sender_sig);
1546  calculate_hmac (&queue->out_hmac, &rekey, sizeof(rekey), &rekey.hmac);
1547  /* Encrypt rekey message with 'old' cipher */
1548  GNUNET_assert (0 ==
1549  gcry_cipher_encrypt (queue->out_cipher,
1550  &queue->cwrite_buf[queue->cwrite_off],
1551  sizeof(rekey),
1552  &rekey,
1553  sizeof(rekey)));
1554  queue->cwrite_off += sizeof(rekey);
1555  /* Setup new cipher for successive messages */
1556  gcry_cipher_close (queue->out_cipher);
1557  setup_out_cipher (queue);
1558 }
1559 
1560 
1567 static void
1568 queue_write (void *cls)
1569 {
1570  struct Queue *queue = cls;
1571  ssize_t sent;
1572  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "In queue write\n");
1573  queue->write_task = NULL;
1574  if (0 != queue->cwrite_off)
1575  {
1576  sent = GNUNET_NETWORK_socket_send (queue->sock,
1577  queue->cwrite_buf,
1578  queue->cwrite_off);
1580  "Sent %lu bytes to TCP queue\n", sent);
1581  if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno))
1582  {
1584  queue_destroy (queue);
1585  return;
1586  }
1587  if (sent > 0)
1588  {
1589  size_t usent = (size_t) sent;
1590  queue->cwrite_off -= usent;
1591  memmove (queue->cwrite_buf,
1592  &queue->cwrite_buf[usent],
1593  queue->cwrite_off);
1594  reschedule_queue_timeout (queue);
1595  }
1596  }
1597  /* can we encrypt more? (always encrypt full messages, needed
1598  such that #mq_cancel() can work!) */
1599  if ((0 < queue->rekey_left_bytes) &&
1600  (queue->pwrite_off > 0) &&
1601  (queue->cwrite_off + queue->pwrite_off <= BUF_SIZE))
1602  {
1604  "Encrypting %lu bytes\n", queue->pwrite_off);
1605  GNUNET_assert (0 ==
1606  gcry_cipher_encrypt (queue->out_cipher,
1607  &queue->cwrite_buf[queue->cwrite_off],
1608  queue->pwrite_off,
1609  queue->pwrite_buf,
1610  queue->pwrite_off));
1611  if (queue->rekey_left_bytes > queue->pwrite_off)
1612  queue->rekey_left_bytes -= queue->pwrite_off;
1613  else
1614  queue->rekey_left_bytes = 0;
1615  queue->cwrite_off += queue->pwrite_off;
1616  queue->pwrite_off = 0;
1617  }
1618  // if ((-1 != unverified_size)&& ((0 == queue->pwrite_off) &&
1619  if (((0 == queue->pwrite_off) &&
1620  ((0 == queue->rekey_left_bytes) ||
1621  (0 ==
1623  queue->rekey_time).rel_value_us))))
1624  {
1625  inject_rekey (queue);
1626  }
1627  if ((0 == queue->pwrite_off) && (! queue->finishing) &&
1628  (GNUNET_YES == queue->mq_awaits_continue))
1629  {
1630  queue->mq_awaits_continue = GNUNET_NO;
1632  }
1633  /* did we just finish writing 'finish'? */
1634  if ((0 == queue->cwrite_off) && (GNUNET_YES == queue->finishing))
1635  {
1637  "Finishing queue\n");
1638  queue_destroy (queue);
1639  return;
1640  }
1641  /* do we care to write more? */
1642  if ((0 < queue->cwrite_off) || (0 < queue->pwrite_off))
1643  queue->write_task =
1645  queue->sock,
1646  &queue_write,
1647  queue);
1648 }
1649 
1650 
1658 static size_t
1660 {
1661  const struct GNUNET_MessageHeader *hdr =
1662  (const struct GNUNET_MessageHeader *) queue->pread_buf;
1663  const struct TCPConfirmationAck *tca = (const struct
1664  TCPConfirmationAck *) queue->pread_buf;
1665  const struct TCPBox *box = (const struct TCPBox *) queue->pread_buf;
1666  const struct TCPRekey *rekey = (const struct TCPRekey *) queue->pread_buf;
1667  const struct TCPFinish *fin = (const struct TCPFinish *) queue->pread_buf;
1668  struct TCPRekey rekeyz;
1669  struct TCPFinish finz;
1670  struct GNUNET_ShortHashCode tmac;
1671  uint16_t type;
1672  size_t size = 0; /* make compiler happy */
1673  struct TcpHandshakeAckSignature thas;
1674  const struct ChallengeNonceP challenge = queue->challenge;
1675 
1677  "try handle plaintext!\n");
1678 
1679  if ((sizeof(*hdr) > queue->pread_off))
1680  {
1682  "Handling plaintext, not even a header!\n");
1683  return 0; /* not even a header */
1684  }
1685 
1687  {
1689  "Already received data of size %lu bigger than KX size %lu!\n",
1692  GNUNET_break_op (0);
1693  queue_finish (queue);
1694  return 0;
1695  }
1696 
1697  type = ntohs (hdr->type);
1698  switch (type)
1699  {
1702  "start processing ack\n");
1703  if (sizeof(*tca) > queue->pread_off)
1704  {
1706  "Handling plaintext size of tca greater than pread offset.\n");
1707  return 0;
1708  }
1709  if (ntohs (hdr->size) != sizeof(*tca))
1710  {
1712  "Handling plaintext size does not match message type.\n");
1713  GNUNET_break_op (0);
1714  queue_finish (queue);
1715  return 0;
1716  }
1717 
1718  thas.purpose.purpose = htonl (
1720  thas.purpose.size = htonl (sizeof(thas));
1721  thas.sender = tca->sender;
1722  thas.receiver = my_identity;
1723  thas.monotonic_time = tca->monotonic_time;
1724  thas.challenge = tca->challenge;
1725 
1728  &thas,
1729  &tca->sender_sig,
1730  &tca->sender.public_key))
1731  {
1733  "Verification of signature failed!\n");
1734  GNUNET_break (0);
1735  queue_finish (queue);
1736  return 0;
1737  }
1738  if (0 != GNUNET_memcmp (&tca->challenge, &challenge))
1739  {
1741  "Challenge in TCPConfirmationAck not correct!\n");
1742  GNUNET_break (0);
1743  queue_finish (queue);
1744  return 0;
1745  }
1746 
1748  "transport_tcp_communicator",
1749  &queue->target,
1751  &
1753  queue);
1754 
1756  "Handling plaintext, ack processed!\n");
1757 
1758  if (GNUNET_TRANSPORT_CS_INBOUND == queue->cs)
1759  {
1760  send_challenge (queue->challenge_received, queue);
1761  queue->write_task =
1763  queue->sock,
1764  &queue_write,
1765  queue);
1766  }
1767 
1768  unverified_size = -1;
1769 
1770  char *foreign_addr;
1771 
1772  switch (queue->address->sa_family)
1773  {
1774  case AF_INET:
1775  GNUNET_asprintf (&foreign_addr,
1776  "%s-%s",
1778  GNUNET_a2s (queue->address, queue->address_len));
1779  break;
1780 
1781  case AF_INET6:
1782  GNUNET_asprintf (&foreign_addr,
1783  "%s-%s",
1785  GNUNET_a2s (queue->address, queue->address_len));
1786  break;
1787 
1788  default:
1789  GNUNET_assert (0);
1790  }
1791 
1793  &queue->target,
1794  foreign_addr,
1795  UINT32_MAX, /* no MTU */
1797  0, /* Priority */
1798  queue->nt,
1799  queue->cs,
1800  queue->mq);
1801 
1802  GNUNET_free (foreign_addr);
1803 
1804  size = ntohs (hdr->size);
1805  break;
1807  /* Special case: header size excludes box itself! */
1808  if (ntohs (hdr->size) + sizeof(struct TCPBox) > queue->pread_off)
1809  return 0;
1810  calculate_hmac (&queue->in_hmac, &box[1], ntohs (hdr->size), &tmac);
1811  if (0 != memcmp (&tmac, &box->hmac, sizeof(tmac)))
1812  {
1813  GNUNET_break_op (0);
1814  queue_finish (queue);
1815  return 0;
1816  }
1817  pass_plaintext_to_core (queue, (const void *) &box[1], ntohs (hdr->size));
1818  size = ntohs (hdr->size) + sizeof(*box);
1820  "Handling plaintext, box processed!\n");
1821  break;
1822 
1824  if (sizeof(*rekey) > queue->pread_off)
1825  return 0;
1826  if (ntohs (hdr->size) != sizeof(*rekey))
1827  {
1828  GNUNET_break_op (0);
1829  queue_finish (queue);
1830  return 0;
1831  }
1832  rekeyz = *rekey;
1833  memset (&rekeyz.hmac, 0, sizeof(rekeyz.hmac));
1834  calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
1835  if (0 != memcmp (&tmac, &rekey->hmac, sizeof(tmac)))
1836  {
1837  GNUNET_break_op (0);
1838  queue_finish (queue);
1839  return 0;
1840  }
1841  do_rekey (queue, rekey);
1842  size = ntohs (hdr->size);
1844  "Handling plaintext, rekey processed!\n");
1845  break;
1846 
1848  if (sizeof(*fin) > queue->pread_off)
1849  return 0;
1850  if (ntohs (hdr->size) != sizeof(*fin))
1851  {
1852  GNUNET_break_op (0);
1853  queue_finish (queue);
1854  return 0;
1855  }
1856  finz = *fin;
1857  memset (&finz.hmac, 0, sizeof(finz.hmac));
1858  calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
1859  if (0 != memcmp (&tmac, &fin->hmac, sizeof(tmac)))
1860  {
1861  GNUNET_break_op (0);
1862  queue_finish (queue);
1863  return 0;
1864  }
1865  /* handle FINISH by destroying queue */
1866  queue_destroy (queue);
1868  "Handling plaintext, finish processed!\n");
1869  break;
1870 
1871  default:
1873  "Handling plaintext, nothing processed!\n");
1874  GNUNET_break_op (0);
1875  queue_finish (queue);
1876  return 0;
1877  }
1878  GNUNET_assert (0 != size);
1879  if (-1 != unverified_size)
1880  unverified_size += size;
1881  return size;
1882 }
1883 
1884 
1890 static void
1891 queue_read (void *cls)
1892 {
1893  struct Queue *queue = cls;
1894  struct GNUNET_TIME_Relative left;
1895  ssize_t rcvd;
1896 
1897  queue->read_task = NULL;
1898  rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
1899  &queue->cread_buf[queue->cread_off],
1900  BUF_SIZE - queue->cread_off);
1902  "Received %lu bytes from TCP queue\n", rcvd);
1904  "transport",
1905  "Received %lu bytes from TCP queue\n", rcvd);
1906  if (-1 == rcvd)
1907  {
1908  if ((EAGAIN != errno) && (EINTR != errno))
1909  {
1911  queue_finish (queue);
1912  return;
1913  }
1914  /* try again */
1916  queue->read_task =
1917  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read, queue);
1918  return;
1919  }
1920  if (0 != rcvd)
1921  reschedule_queue_timeout (queue);
1922  queue->cread_off += rcvd;
1923  while ((queue->pread_off < sizeof(queue->pread_buf)) &&
1924  (queue->cread_off > 0))
1925  {
1926  size_t max = GNUNET_MIN (sizeof(queue->pread_buf) - queue->pread_off,
1927  queue->cread_off);
1928  size_t done;
1929  size_t total;
1930  size_t old_pread_off = queue->pread_off;
1931 
1932  GNUNET_assert (0 ==
1933  gcry_cipher_decrypt (queue->in_cipher,
1934  &queue->pread_buf[queue->pread_off],
1935  max,
1936  queue->cread_buf,
1937  max));
1938  queue->pread_off += max;
1939  total = 0;
1940  while (0 != (done = try_handle_plaintext (queue)))
1941  {
1942  /* 'done' bytes of plaintext were used, shift buffer */
1943  GNUNET_assert (done <= queue->pread_off);
1944  /* NOTE: this memmove() could possibly sometimes be
1945  avoided if we pass 'total' into try_handle_plaintext()
1946  and use it at an offset into the buffer there! */
1947  memmove (queue->pread_buf,
1948  &queue->pread_buf[done],
1949  queue->pread_off - done);
1950  queue->pread_off -= done;
1951  total += done;
1952  /* The last plaintext was a rekey, abort for now */
1953  if (GNUNET_YES == queue->rekeyed)
1954  break;
1955  }
1956  /* when we encounter a rekey message, the decryption above uses the
1957  wrong key for everything after the rekey; in that case, we have
1958  to re-do the decryption at 'total' instead of at 'max'.
1959  However, we have to take into account that the plaintext buffer may have
1960  already contained data and not jumped too far ahead in the ciphertext.
1961  If there is no rekey and the last message is incomplete (max > total),
1962  it is safe to keep the decryption so we shift by 'max' */
1963  if (GNUNET_YES == queue->rekeyed)
1964  {
1965  max = total - old_pread_off;
1966  queue->rekeyed = GNUNET_NO;
1967  queue->pread_off = 0;
1968  }
1969  memmove (queue->cread_buf, &queue->cread_buf[max], queue->cread_off - max);
1970  queue->cread_off -= max;
1971  }
1972  if (BUF_SIZE == queue->cread_off)
1973  return; /* buffer full, suspend reading */
1975  if (0 != left.rel_value_us)
1976  {
1977  if (max_queue_length > queue->backpressure)
1978  {
1979  /* continue reading */
1981  queue->read_task =
1982  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read, queue);
1983  }
1984  return;
1985  }
1987  "Queue %p was idle for %s, disconnecting\n",
1988  queue,
1991  GNUNET_YES));
1992  queue_finish (queue);
1993 }
1994 
1995 
2003 static struct sockaddr *
2004 tcp_address_to_sockaddr_numeric_v6 (socklen_t *sock_len, struct sockaddr_in6 v6,
2005  unsigned int port)
2006 {
2007  struct sockaddr *in;
2008 
2009  v6.sin6_family = AF_INET6;
2010  v6.sin6_port = htons ((uint16_t) port);
2011 #if HAVE_SOCKADDR_IN_SIN_LEN
2012  v6.sin6_len = sizeof(sizeof(struct sockaddr_in6));
2013 #endif
2014  v6.sin6_flowinfo = 0;
2015  v6.sin6_scope_id = 0;
2016  in = GNUNET_memdup (&v6, sizeof(v6));
2017  *sock_len = sizeof(struct sockaddr_in6);
2018 
2019  return in;
2020 }
2021 
2022 
2030 static struct sockaddr *
2031 tcp_address_to_sockaddr_numeric_v4 (socklen_t *sock_len, struct sockaddr_in v4,
2032  unsigned int port)
2033 {
2034  struct sockaddr *in;
2035 
2036  v4.sin_family = AF_INET;
2037  v4.sin_port = htons ((uint16_t) port);
2038 #if HAVE_SOCKADDR_IN_SIN_LEN
2039  v4.sin_len = sizeof(struct sockaddr_in);
2040 #endif
2041  in = GNUNET_memdup (&v4, sizeof(v4));
2042  *sock_len = sizeof(struct sockaddr_in);
2043  return in;
2044 }
2045 
2046 
2053 static struct PortOnlyIpv4Ipv6 *
2054 tcp_address_to_sockaddr_port_only (const char *bindto, unsigned int *port)
2055 {
2056  struct PortOnlyIpv4Ipv6 *po;
2057  struct sockaddr_in *i4;
2058  struct sockaddr_in6 *i6;
2059  socklen_t sock_len_ipv4;
2060  socklen_t sock_len_ipv6;
2061 
2062  /* interpreting value as just a PORT number */
2063  if (*port > UINT16_MAX)
2064  {
2066  "BINDTO specification `%s' invalid: value too large for port\n",
2067  bindto);
2068  return NULL;
2069  }
2070 
2071  po = GNUNET_new (struct PortOnlyIpv4Ipv6);
2072 
2073  if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
2074  (GNUNET_YES ==
2077  "DISABLE_V6")))
2078  {
2079  i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
2080  po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
2081  *port);
2082  po->addr_len_ipv4 = sock_len_ipv4;
2083  }
2084  else
2085  {
2086 
2087  i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
2088  po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
2089  *port);
2090  po->addr_len_ipv4 = sock_len_ipv4;
2091 
2092  i6 = GNUNET_malloc (sizeof(struct sockaddr_in6));
2093  po->addr_ipv6 = tcp_address_to_sockaddr_numeric_v6 (&sock_len_ipv6, *i6,
2094  *port);
2095 
2096  po->addr_len_ipv6 = sock_len_ipv6;
2097 
2098  GNUNET_free (i6);
2099  }
2100 
2101  GNUNET_free (i4);
2102 
2103  return po;
2104 }
2105 
2106 
2113 static char *
2114 extract_address (const char *bindto)
2115 {
2116 
2117  char *start;
2118  char *token;
2119  char *cp;
2120  char *rest = NULL;
2121  char *res;
2122 
2124  "extract address with bindto %s\n",
2125  bindto);
2126 
2127  if (NULL == bindto)
2129  "bindto is NULL\n");
2130 
2131  cp = GNUNET_strdup (bindto);
2132 
2134  "extract address 2\n");
2135 
2136  start = cp;
2137  if (('[' == *cp) && (']' == cp[strlen (cp) - 1]))
2138  {
2139  start++; /* skip over '['*/
2140  cp[strlen (cp) - 1] = '\0'; /* eat ']'*/
2141  }
2142  else
2143  {
2144  token = strtok_r (cp, "]", &rest);
2145  if (strlen (bindto) == strlen (token))
2146  {
2147  token = strtok_r (cp, ":", &rest);
2148  }
2149  else
2150  {
2151  token++;
2152  res = GNUNET_strdup (token);
2153  GNUNET_free (cp);
2154  return res;
2155  }
2156  }
2157 
2159  "extract address 3\n");
2161  "extract address with start %s\n",
2162  start);
2163 
2164  return GNUNET_strdup (start);
2165 }
2166 
2167 
2174 static unsigned int
2175 extract_port (const char *addr_and_port)
2176 {
2177  unsigned int port;
2178  char dummy[2];
2179  char *token;
2180  char *addr;
2181  char *colon;
2182  char *cp;
2183  char *rest = NULL;
2184 
2185  if (NULL != addr_and_port)
2186  {
2187  cp = GNUNET_strdup (addr_and_port);
2188  token = strtok_r (cp, "]", &rest);
2189  if (strlen (addr_and_port) == strlen (token))
2190  {
2191  colon = strrchr (cp, ':');
2192  if (NULL == colon)
2193  {
2194  GNUNET_free (cp);
2195  return 0;
2196  }
2197  addr = colon;
2198  addr++;
2199  }
2200  else
2201  {
2202  token = strtok_r (NULL, "]", &rest);
2203  if (NULL == token)
2204  {
2205  GNUNET_free (cp);
2206  return 0;
2207  }
2208  else
2209  {
2210  addr = token;
2211  addr++;
2212  }
2213  }
2214 
2215 
2216  if (1 == sscanf (addr, "%u%1s", &port, dummy))
2217  {
2218  /* interpreting value as just a PORT number */
2219  if (port > UINT16_MAX)
2220  {
2222  "Port `%u' invalid: value too large for port\n",
2223  port);
2224  GNUNET_free (cp);
2225  return 0;
2226  }
2227  }
2228  else
2229  {
2231  "BINDTO specification invalid: last ':' not followed by number\n");
2232  GNUNET_free (cp);
2233  return 0;
2234  }
2235  }
2236  else
2237  {
2239  "return 0\n");
2240  /* interpret missing port as 0, aka pick any free one */
2241  port = 0;
2242  }
2243 
2244 
2245  return port;
2246 }
2247 
2248 
2256 static struct sockaddr *
2257 tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
2258 {
2259  struct sockaddr *in;
2260  unsigned int port;
2261  struct sockaddr_in v4;
2262  struct sockaddr_in6 v6;
2263  char *start;
2264 
2265  // cp = GNUNET_strdup (bindto);
2266  start = extract_address (bindto);
2267 
2269  "start %s\n",
2270  start);
2271 
2273  "!bindto %s\n",
2274  bindto);
2275 
2276 
2277  if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
2278  {
2279  // colon = strrchr (cp, ':');
2280  port = extract_port (bindto);
2281 
2283  "port %u\n",
2284  port);
2285 
2286  in = tcp_address_to_sockaddr_numeric_v4 (sock_len, v4, port);
2287  }
2288  else if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
2289  {
2290  // colon = strrchr (cp, ':');
2291  port = extract_port (bindto);
2292  in = tcp_address_to_sockaddr_numeric_v6 (sock_len, v6, port);
2293  }
2294  else
2295  {
2296  GNUNET_assert (0);
2297  }
2298 
2299  GNUNET_free (start);
2300  return in;
2301 }
2302 
2303 
2312 static void
2314  const struct GNUNET_MessageHeader *msg,
2315  void *impl_state)
2316 {
2317  struct Queue *queue = impl_state;
2318  uint16_t msize = ntohs (msg->size);
2319  struct TCPBox box;
2321  "In MQ send. Queue finishing: %s; write task running: %s\n",
2322  (GNUNET_YES == queue->finishing) ? "yes" : "no",
2323  (NULL == queue->write_task) ? "yes" : "no");
2324  GNUNET_assert (mq == queue->mq);
2325  queue->mq_awaits_continue = GNUNET_YES;
2326  if (GNUNET_YES == queue->finishing)
2327  return; /* this queue is dying, drop msg */
2328  GNUNET_assert (0 == queue->pwrite_off);
2330  box.header.size = htons (msize);
2331  calculate_hmac (&queue->out_hmac, msg, msize, &box.hmac);
2332  memcpy (&queue->pwrite_buf[queue->pwrite_off], &box, sizeof(box));
2333  queue->pwrite_off += sizeof(box);
2334  memcpy (&queue->pwrite_buf[queue->pwrite_off], msg, msize);
2335  queue->pwrite_off += msize;
2337  "%lu bytes of plaintext to send\n", queue->pwrite_off);
2338  GNUNET_assert (NULL != queue->sock);
2339  if (NULL == queue->write_task)
2340  queue->write_task =
2342  queue->sock,
2343  &queue_write,
2344  queue);
2345 }
2346 
2347 
2356 static void
2357 mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state)
2358 {
2359  struct Queue *queue = impl_state;
2360 
2361  if (mq == queue->mq)
2362  {
2363  queue->mq = NULL;
2364  queue_finish (queue);
2365  }
2366 }
2367 
2368 
2375 static void
2376 mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
2377 {
2378  struct Queue *queue = impl_state;
2379 
2380  GNUNET_assert (0 != queue->pwrite_off);
2381  queue->pwrite_off = 0;
2382 }
2383 
2384 
2394 static void
2395 mq_error (void *cls, enum GNUNET_MQ_Error error)
2396 {
2397  struct Queue *queue = cls;
2398 
2400  "MQ error in queue to %s: %d\n",
2401  GNUNET_i2s (&queue->target),
2402  (int) error);
2403  queue_finish (queue);
2404 }
2405 
2406 
2414 static void
2416 {
2417  queue->nt =
2418  GNUNET_NT_scanner_get_type (is, queue->address, queue->address_len);
2420  queue_map,
2421  &queue->target,
2422  queue,
2424  GNUNET_STATISTICS_set (stats,
2425  "# queues active",
2427  GNUNET_NO);
2428  queue->timeout =
2431  &mq_destroy,
2432  &mq_cancel,
2433  queue,
2434  NULL,
2435  &mq_error,
2436  queue);
2437 }
2438 
2439 
2450 static void
2452  const struct GNUNET_CRYPTO_EcdhePublicKey *epub)
2453 {
2454  struct TcpHandshakeSignature ths;
2455  struct TCPConfirmation tc;
2456 
2457  memcpy (queue->cwrite_buf, epub, sizeof(*epub));
2458  queue->cwrite_off = sizeof(*epub);
2459  /* compute 'tc' and append in encrypted format to cwrite_buf */
2460  tc.sender = my_identity;
2461  tc.monotonic_time =
2464  &tc.challenge,
2465  sizeof(tc.challenge));
2467  ths.purpose.size = htonl (sizeof(ths));
2468  ths.sender = my_identity;
2469  ths.receiver = queue->target;
2470  ths.ephemeral = *epub;
2471  ths.monotonic_time = tc.monotonic_time;
2472  ths.challenge = tc.challenge;
2473  GNUNET_CRYPTO_eddsa_sign (my_private_key,
2474  &ths,
2475  &tc.sender_sig);
2476  GNUNET_assert (0 ==
2477  gcry_cipher_encrypt (queue->out_cipher,
2478  &queue->cwrite_buf[queue->cwrite_off],
2479  sizeof(tc),
2480  &tc,
2481  sizeof(tc)));
2482  queue->challenge = tc.challenge;
2483  queue->cwrite_off += sizeof(tc);
2484 
2486  "transport",
2487  "handshake written\n");
2488 }
2489 
2490 
2498 static void
2500 {
2501  struct GNUNET_CRYPTO_EcdhePublicKey epub;
2502 
2505  setup_out_cipher (queue);
2506  transmit_kx (queue, &epub);
2507 }
2508 
2509 
2515 static void
2516 handshake_monotime_store_cb (void *cls, int success)
2517 {
2518  struct Queue *queue = cls;
2519  if (GNUNET_OK != success)
2520  {
2522  "Failed to store handshake monotonic time in PEERSTORE!\n");
2523  }
2524  queue->handshake_monotime_sc = NULL;
2525 }
2526 
2527 
2535 static void
2537  const struct GNUNET_PEERSTORE_Record *record,
2538  const char *emsg)
2539 {
2540  struct Queue *queue = cls;
2541  struct GNUNET_TIME_AbsoluteNBO *mtbe;
2542  struct GNUNET_TIME_Absolute mt;
2543  const struct GNUNET_PeerIdentity *pid;
2544  struct GNUNET_TIME_AbsoluteNBO *handshake_monotonic_time;
2545 
2546  (void) emsg;
2547 
2548  handshake_monotonic_time = &queue->handshake_monotonic_time;
2549  pid = &queue->target;
2550  if (NULL == record)
2551  {
2552  queue->handshake_monotime_get = NULL;
2553  return;
2554  }
2555  if (sizeof(*mtbe) != record->value_size)
2556  {
2557  GNUNET_break (0);
2558  return;
2559  }
2560  mtbe = record->value;
2561  mt = GNUNET_TIME_absolute_ntoh (*mtbe);
2564  {
2566  "Queue from %s dropped, handshake monotime in the past\n",
2567  GNUNET_i2s (&queue->target));
2568  GNUNET_break (0);
2569  queue_finish (queue);
2570  return;
2571  }
2572  queue->handshake_monotime_sc = GNUNET_PEERSTORE_store (peerstore,
2573  "transport_tcp_communicator",
2574  pid,
2576  handshake_monotonic_time,
2577  sizeof(*
2578  handshake_monotonic_time),
2581  &
2583  queue);
2584 }
2585 
2586 
2598 static int
2600  struct TCPConfirmation *tc,
2601  char *ibuf)
2602 {
2603  struct TcpHandshakeSignature ths;
2604 
2605  GNUNET_assert (
2606  0 ==
2607  gcry_cipher_decrypt (queue->in_cipher,
2608  tc,
2609  sizeof(*tc),
2610  &ibuf[sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)],
2611  sizeof(*tc)));
2613  ths.purpose.size = htonl (sizeof(ths));
2614  ths.sender = tc->sender;
2615  ths.receiver = my_identity;
2616  memcpy (&ths.ephemeral, ibuf, sizeof(struct GNUNET_CRYPTO_EcdhePublicKey));
2617  ths.monotonic_time = tc->monotonic_time;
2618  ths.challenge = tc->challenge;
2619  queue->handshake_monotime_get =
2620  GNUNET_PEERSTORE_iterate (peerstore,
2621  "transport_tcp_communicator",
2622  &queue->target,
2625  queue);
2628  &ths,
2629  &tc->sender_sig,
2630  &tc->sender.public_key);
2631 }
2632 
2633 
2639 static void
2641 {
2642  if (NULL != pq->listen_sock)
2643  {
2645  pq->listen_sock = NULL;
2646  }
2648  GNUNET_free (pq->address);
2649  GNUNET_CONTAINER_DLL_remove (proto_head, proto_tail, pq);
2650  GNUNET_free (pq);
2651 }
2652 
2653 
2660 static void
2661 proto_read_kx (void *cls)
2662 {
2663  struct ProtoQueue *pq = cls;
2664  ssize_t rcvd;
2665  struct GNUNET_TIME_Relative left;
2666  struct Queue *queue;
2667  struct TCPConfirmation tc;
2668 
2669  pq->read_task = NULL;
2671  if (0 == left.rel_value_us)
2672  {
2673  free_proto_queue (pq);
2674  return;
2675  }
2676  rcvd = GNUNET_NETWORK_socket_recv (pq->sock,
2677  &pq->ibuf[pq->ibuf_off],
2678  sizeof(pq->ibuf) - pq->ibuf_off);
2680  "Received %lu bytes for KX\n", rcvd);
2682  "transport",
2683  "Received %lu bytes for KX\n", rcvd);
2684  if (-1 == rcvd)
2685  {
2686  if ((EAGAIN != errno) && (EINTR != errno))
2687  {
2689  free_proto_queue (pq);
2690  return;
2691  }
2692  /* try again */
2693  pq->read_task =
2695  return;
2696  }
2697  pq->ibuf_off += rcvd;
2698  if (pq->ibuf_off > sizeof(pq->ibuf))
2699  {
2700  /* read more */
2701  pq->read_task =
2703  return;
2704  }
2705  /* we got all the data, let's find out who we are talking to! */
2706  queue = GNUNET_new (struct Queue);
2707  setup_in_cipher ((const struct GNUNET_CRYPTO_EcdhePublicKey *) pq->ibuf,
2708  queue);
2709  if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, pq->ibuf))
2710  {
2712  "Invalid TCP KX received from %s\n",
2713  GNUNET_a2s (pq->address, pq->address_len));
2714  gcry_cipher_close (queue->in_cipher);
2715  GNUNET_free (queue);
2716  free_proto_queue (pq);
2717  return;
2718  }
2719  queue->address = pq->address; /* steals reference */
2720  queue->address_len = pq->address_len;
2721  queue->target = tc.sender;
2722  queue->listen_sock = pq->listen_sock;
2723  queue->sock = pq->sock;
2724 
2725 
2727  "start kx proto\n");
2728 
2729  start_initial_kx_out (queue);
2731  boot_queue (queue);
2732  queue->read_task =
2734  queue->sock,
2735  &queue_read,
2736  queue);
2737  queue->write_task =
2739  queue->sock,
2740  &queue_write,
2741  queue);
2742  // TODO To early! Move it somewhere else.
2743  // send_challenge (tc.challenge, queue);
2744  queue->challenge_received = tc.challenge;
2745 
2746  GNUNET_CONTAINER_DLL_remove (proto_head, proto_tail, pq);
2747  GNUNET_free (pq);
2748 }
2749 
2750 
2758 static void
2759 listen_cb (void *cls)
2760 {
2761  struct sockaddr_storage in;
2762  socklen_t addrlen;
2763  struct GNUNET_NETWORK_Handle *sock;
2764  struct ProtoQueue *pq;
2765  struct ListenTask *lt;
2766 
2768  "listen_cb\n");
2769 
2770  lt = cls;
2771 
2772  lt->listen_task = NULL;
2773  GNUNET_assert (NULL != lt->listen_sock);
2774  addrlen = sizeof(in);
2775  memset (&in, 0, sizeof(in));
2777  (struct sockaddr*) &in,
2778  &addrlen);
2779  if ((NULL == sock) && ((EMFILE == errno) || (ENFILE == errno)))
2780  return; /* system limit reached, wait until connection goes down */
2782  lt->listen_sock,
2783  &listen_cb,
2784  lt);
2785  if ((NULL == sock) && ((EAGAIN == errno) || (ENOBUFS == errno)))
2786  return;
2787  if (NULL == sock)
2788  {
2790  return;
2791  }
2792  pq = GNUNET_new (struct ProtoQueue);
2793  pq->address_len = addrlen;
2794  pq->address = GNUNET_memdup (&in, addrlen);
2796  pq->sock = sock;
2798  pq->sock,
2799  &proto_read_kx,
2800  pq);
2801  GNUNET_CONTAINER_DLL_insert (proto_head, proto_tail, pq);
2802 }
2803 
2804 
2812 static void
2813 queue_read_kx (void *cls)
2814 {
2815  struct Queue *queue = cls;
2816  ssize_t rcvd;
2817  struct GNUNET_TIME_Relative left;
2818  struct TCPConfirmation tc;
2819 
2820  queue->read_task = NULL;
2822  if (0 == left.rel_value_us)
2823  {
2824  queue_destroy (queue);
2825  return;
2826  }
2827  rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
2828  &queue->cread_buf[queue->cread_off],
2829  BUF_SIZE - queue->cread_off);
2831  "Received %lu bytes for KX\n",
2832  rcvd);
2834  "transport",
2835  "Received %lu bytes for KX\n",
2836  rcvd);
2837  if (-1 == rcvd)
2838  {
2839  if ((EAGAIN != errno) && (EINTR != errno))
2840  {
2842  queue_destroy (queue);
2843  return;
2844  }
2845  queue->read_task =
2846  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read_kx, queue);
2847  return;
2848  }
2849  queue->cread_off += rcvd;
2850  if (queue->cread_off < INITIAL_KX_SIZE)
2851  {
2852  /* read more */
2853  queue->read_task =
2854  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read_kx, queue);
2855  return;
2856  }
2857  /* we got all the data, let's find out who we are talking to! */
2859  queue->cread_buf,
2860  queue);
2861  if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, queue->cread_buf))
2862  {
2864  "Invalid TCP KX received from %s\n",
2865  GNUNET_a2s (queue->address, queue->address_len));
2866  queue_destroy (queue);
2867  return;
2868  }
2869  if (0 !=
2870  memcmp (&tc.sender, &queue->target, sizeof(struct GNUNET_PeerIdentity)))
2871  {
2873  "Invalid sender in TCP KX received from %s\n",
2874  GNUNET_a2s (queue->address, queue->address_len));
2875  queue_destroy (queue);
2876  return;
2877  }
2878  send_challenge (tc.challenge, queue);
2879  queue->write_task =
2881  queue->sock,
2882  &queue_write,
2883  queue);
2884 
2885  /* update queue timeout */
2886  reschedule_queue_timeout (queue);
2887  /* prepare to continue with regular read task immediately */
2888  memmove (queue->cread_buf,
2889  &queue->cread_buf[INITIAL_KX_SIZE],
2890  queue->cread_off - (INITIAL_KX_SIZE));
2892  "cread_off is %lu bytes before adjusting\n",
2893  queue->cread_off);
2894  queue->cread_off -= INITIAL_KX_SIZE;
2896  "cread_off set to %lu bytes\n",
2897  queue->cread_off);
2898  queue->read_task = GNUNET_SCHEDULER_add_now (&queue_read, queue);
2899 }
2900 
2901 
2920 static int
2921 mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
2922 {
2923  struct Queue *queue;
2924  const char *path;
2925  struct sockaddr *in;
2926  socklen_t in_len = 0;
2927  struct GNUNET_NETWORK_Handle *sock;
2928 
2930  "Connecting to %s\n", address);
2932  "transport",
2933  "Connecting to %s\n", address);
2934  if (0 != strncmp (address,
2936  strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
2937  {
2938  GNUNET_break_op (0);
2939  return GNUNET_SYSERR;
2940  }
2941  path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
2942  in = tcp_address_to_sockaddr (path, &in_len);
2943 
2944  if (NULL == in)
2945  {
2947  "Failed to setup TCP socket address\n");
2948  return GNUNET_SYSERR;
2949  }
2950 
2952  "in %s\n",
2953  GNUNET_a2s (in, in_len));
2954 
2955  sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, IPPROTO_TCP);
2956  if (NULL == sock)
2957  {
2959  "socket(%d) failed: %s",
2960  in->sa_family,
2961  strerror (errno));
2962  GNUNET_free (in);
2963  return GNUNET_SYSERR;
2964  }
2965  if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, in_len)) &&
2966  (errno != EINPROGRESS))
2967  {
2969  "connect to `%s' failed: %s",
2970  address,
2971  strerror (errno));
2973  GNUNET_free (in);
2974  return GNUNET_SYSERR;
2975  }
2976 
2977  queue = GNUNET_new (struct Queue);
2978  queue->target = *peer;
2979  queue->address = in;
2980  queue->address_len = in_len;
2981  queue->sock = sock;
2983  boot_queue (queue);
2984  // queue->mq_awaits_continue = GNUNET_YES;
2985  queue->read_task =
2987  queue->sock,
2988  &queue_read_kx,
2989  queue);
2990 
2991 
2993  "start kx mq_init\n");
2994 
2995  start_initial_kx_out (queue);
2996  queue->write_task =
2998  queue->sock,
2999  &queue_write,
3000  queue);
3001  return GNUNET_OK;
3002 }
3003 
3004 
3013 static int
3014 get_lt_delete_it (void *cls,
3015  const struct GNUNET_HashCode *key,
3016  void *value)
3017 {
3018  struct ListenTask *lt = value;
3019 
3020  (void) cls;
3021  (void) key;
3022  if (NULL != lt->listen_task)
3023  {
3025  lt->listen_task = NULL;
3026  }
3027  if (NULL != lt->listen_sock)
3028  {
3030  lt->listen_sock = NULL;
3031  }
3032  return GNUNET_OK;
3033 }
3034 
3035 
3044 static int
3046  const struct GNUNET_PeerIdentity *target,
3047  void *value)
3048 {
3049  struct Queue *queue = value;
3050 
3051  (void) cls;
3052  (void) target;
3053  queue_destroy (queue);
3054  return GNUNET_OK;
3055 }
3056 
3057 
3063 static void
3064 do_shutdown (void *cls)
3065 {
3067  "Shutdown %s!\n",
3068  shutdown_running ? "running" : "not running");
3069 
3071  return;
3072  else
3074 
3075  while (NULL != proto_head)
3076  free_proto_queue (proto_head);
3077  if (NULL != nat)
3078  {
3079  GNUNET_NAT_unregister (nat);
3080  nat = NULL;
3081  }
3086  if (NULL != ch)
3087  {
3089  ch = NULL;
3090  }
3091  if (NULL != stats)
3092  {
3094  stats = NULL;
3095  }
3096  if (NULL != my_private_key)
3097  {
3098  GNUNET_free (my_private_key);
3099  my_private_key = NULL;
3100  }
3101  if (NULL != is)
3102  {
3104  is = NULL;
3105  }
3106  if (NULL != peerstore)
3107  {
3109  peerstore = NULL;
3110  }
3111  if (NULL != resolve_request_handle)
3112  {
3113  GNUNET_RESOLVER_request_cancel (resolve_request_handle);
3114  resolve_request_handle = NULL;
3115  }
3117  "Shutdown done!\n");
3118 }
3119 
3120 
3132 static void
3133 enc_notify_cb (void *cls,
3134  const struct GNUNET_PeerIdentity *sender,
3135  const struct GNUNET_MessageHeader *msg)
3136 {
3137  (void) cls;
3138  (void) sender;
3139  (void) msg;
3140  GNUNET_break_op (0);
3141 }
3142 
3143 
3157 static void
3158 nat_address_cb (void *cls,
3159  void **app_ctx,
3160  int add_remove,
3162  const struct sockaddr *addr,
3163  socklen_t addrlen)
3164 {
3165  char *my_addr;
3167 
3169  "nat address cb %s %s\n",
3170  add_remove ? "add" : "remove",
3171  GNUNET_a2s (addr, addrlen));
3172 
3173  if (GNUNET_YES == add_remove)
3174  {
3175  enum GNUNET_NetworkType nt;
3176 
3177  GNUNET_asprintf (&my_addr,
3178  "%s-%s",
3180  GNUNET_a2s (addr, addrlen));
3181  nt = GNUNET_NT_scanner_get_type (is, addr, addrlen);
3182  ai =
3184  my_addr,
3185  nt,
3187  GNUNET_free (my_addr);
3188  *app_ctx = ai;
3189  }
3190  else
3191  {
3192  ai = *app_ctx;
3194  *app_ctx = NULL;
3195  }
3196 }
3197 
3198 
3202 static void
3203 add_addr (struct sockaddr *in, socklen_t in_len)
3204 {
3205 
3206  struct Addresses *saddrs;
3207 
3209  "add address %s\n",
3210  GNUNET_a2s (in, in_len));
3211 
3212  saddrs = GNUNET_new (struct Addresses);
3213  saddrs->addr = in;
3214  saddrs->addr_len = in_len;
3215  GNUNET_CONTAINER_DLL_insert (addrs_head, addrs_tail, saddrs);
3216 
3218  "after add address %s\n",
3219  GNUNET_a2s (in, in_len));
3220 
3222  "add address %s\n",
3223  GNUNET_a2s (saddrs->addr, saddrs->addr_len));
3224 
3225  addrs_lens++;
3226 }
3227 
3228 
3236 static int
3237 init_socket (struct sockaddr *addr,
3238  socklen_t in_len)
3239 {
3240  struct sockaddr_storage in_sto;
3241  socklen_t sto_len;
3242  struct GNUNET_NETWORK_Handle *listen_sock;
3243  struct ListenTask *lt;
3244  int sockfd;
3245  struct GNUNET_HashCode h_sock;
3246 
3247  if (NULL == addr)
3248  {
3250  "Address is NULL.\n");
3251  return GNUNET_SYSERR;
3252  }
3253 
3255  "address %s\n",
3256  GNUNET_a2s (addr, in_len));
3257 
3258  listen_sock =
3259  GNUNET_NETWORK_socket_create (addr->sa_family, SOCK_STREAM, IPPROTO_TCP);
3260  if (NULL == listen_sock)
3261  {
3263  return GNUNET_SYSERR;
3264  }
3265 
3266  if (GNUNET_OK != GNUNET_NETWORK_socket_bind (listen_sock, addr, in_len))
3267  {
3269  GNUNET_NETWORK_socket_close (listen_sock);
3270  listen_sock = NULL;
3271  return GNUNET_SYSERR;
3272  }
3273 
3274  if (GNUNET_OK !=
3275  GNUNET_NETWORK_socket_listen (listen_sock,
3276  5))
3277  {
3279  "listen");
3280  GNUNET_NETWORK_socket_close (listen_sock);
3281  listen_sock = NULL;
3282  return GNUNET_SYSERR;
3283  }
3284 
3285  /* We might have bound to port 0, allowing the OS to figure it out;
3286  thus, get the real IN-address from the socket */
3287  sto_len = sizeof(in_sto);
3288 
3289  if (0 != getsockname (GNUNET_NETWORK_get_fd (listen_sock),
3290  (struct sockaddr *) &in_sto,
3291  &sto_len))
3292  {
3293  memcpy (&in_sto, addr, in_len);
3294  sto_len = in_len;
3295  }
3296 
3297  // addr = (struct sockaddr *) &in_sto;
3298  in_len = sto_len;
3300  "Bound to `%s'\n",
3301  GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len));
3302  stats = GNUNET_STATISTICS_create ("C-TCP", cfg);
3303 
3304  if (NULL == is)
3305  is = GNUNET_NT_scanner_init ();
3306 
3307  if (NULL == my_private_key)
3309  if (NULL == my_private_key)
3310  {
3311  GNUNET_log (
3313  _ (
3314  "Transport service is lacking key configuration settings. Exiting.\n"));
3315  if (NULL != resolve_request_handle)
3316  GNUNET_RESOLVER_request_cancel (resolve_request_handle);
3318  return GNUNET_SYSERR;
3319  }
3321  /* start listening */
3322 
3323  lt = GNUNET_new (struct ListenTask);
3324  lt->listen_sock = listen_sock;
3325 
3327  listen_sock,
3328  &listen_cb,
3329  lt);
3330 
3332  "creating hash\n");
3333  sockfd = GNUNET_NETWORK_get_fd (lt->listen_sock);
3334  GNUNET_CRYPTO_hash (&sockfd,
3335  sizeof(int),
3336  &h_sock);
3337 
3339  "creating map\n");
3340  if (NULL == lt_map)
3342 
3344  "creating map entry\n");
3347  &h_sock,
3348  lt,
3350 
3352  "map entry created\n");
3353 
3354  if (NULL == queue_map)
3356 
3357  if (NULL == ch)
3362  &mq_init,
3363  NULL,
3364  &enc_notify_cb,
3365  NULL);
3366 
3367  if (NULL == ch)
3368  {
3369  GNUNET_break (0);
3370  if (NULL != resolve_request_handle)
3371  GNUNET_RESOLVER_request_cancel (resolve_request_handle);
3373  return GNUNET_SYSERR;
3374  }
3375 
3376  add_addr (addr, in_len);
3377  return GNUNET_OK;
3378 
3379 }
3380 
3381 
3385 static void
3387 {
3388 
3389  struct sockaddr **saddrs;
3390  socklen_t *saddr_lens;
3391  int i;
3392  struct Addresses *pos;
3393 
3394 
3396  "starting nat register!\n");
3397 
3398  i = 0;
3399  saddrs = GNUNET_malloc ((addrs_lens + 1) * sizeof(struct sockaddr *));
3400 
3401  saddr_lens = GNUNET_malloc ((addrs_lens + 1) * sizeof(socklen_t));
3402 
3403  for (pos = addrs_head; NULL != pos; pos = pos->next)
3404  {
3405 
3407  "registering address %s\n",
3408  GNUNET_a2s (addrs_head->addr, addrs_head->addr_len));
3409 
3410  saddr_lens[i] = addrs_head->addr_len;
3411  saddrs[i] = GNUNET_memdup (addrs_head->addr, saddr_lens[i]);
3412 
3413  i++;
3414 
3415  }
3416 
3417  nat = GNUNET_NAT_register (cfg,
3419  IPPROTO_TCP,
3420  addrs_lens,
3421  (const struct sockaddr **) saddrs,
3422  saddr_lens,
3423  &nat_address_cb,
3424  NULL /* FIXME: support reversal: #5529 */,
3425  NULL /* closure */);
3426 
3427  i = 0;
3428 
3429  for (i = addrs_lens - 1; i >= 0; i--)
3430  GNUNET_free (saddrs[i]);
3431  GNUNET_free (saddrs);
3432  GNUNET_free (saddr_lens);
3433 
3434  if (NULL == nat)
3435  {
3436  GNUNET_break (0);
3437  if (NULL != resolve_request_handle)
3438  GNUNET_RESOLVER_request_cancel (resolve_request_handle);
3440  }
3441 }
3442 
3443 
3451 static void
3453  const struct sockaddr *addr,
3454  socklen_t in_len)
3455 {
3456  struct sockaddr_in *v4;
3457  struct sockaddr_in6 *v6;
3458  struct sockaddr *in;
3459 
3460  (void) cls;
3461  if (NULL != addr)
3462  {
3463  if (AF_INET == addr->sa_family)
3464  {
3465  v4 = (struct sockaddr_in *) addr;
3466  in = tcp_address_to_sockaddr_numeric_v4 (&in_len, *v4, bind_port);// _global);
3467  }
3468  else if (AF_INET6 == addr->sa_family)
3469  {
3470  v6 = (struct sockaddr_in6 *) addr;
3471  in = tcp_address_to_sockaddr_numeric_v6 (&in_len, *v6, bind_port);// _global);
3472  }
3473  else
3474  {
3476  "Address family %u not suitable (not AF_INET %u nor AF_INET6 %u \n",
3477  addr->sa_family,
3478  AF_INET,
3479  AF_INET6);
3480  return;
3481  }
3482  init_socket (in, in_len);
3483  }
3484  else
3485  {
3487  "Address is NULL. This might be an error or the resolver finished resolving.\n");
3488  if (NULL == addrs_head)
3489  {
3491  "Resolver finished resolving, but we do not listen to an address!.\n");
3492  return;
3493  }
3494  nat_register ();
3495 
3496  }
3497 }
3498 
3499 
3508 static void
3509 run (void *cls,
3510  char *const *args,
3511  const char *cfgfile,
3512  const struct GNUNET_CONFIGURATION_Handle *c)
3513 {
3514  char *bindto;
3515  struct sockaddr *in;
3516  socklen_t in_len;
3517  struct sockaddr_in v4;
3518  struct sockaddr_in6 v6;
3519  char *start;
3520  unsigned int port;
3521  char dummy[2];
3522  char *rest = NULL;
3523  struct PortOnlyIpv4Ipv6 *po;
3524  socklen_t addr_len_ipv4;
3525  socklen_t addr_len_ipv6;
3526 
3527  (void) cls;
3528  cfg = c;
3529  if (GNUNET_OK !=
3532  "BINDTO",
3533  &bindto))
3534  {
3537  "BINDTO");
3538  return;
3539  }
3540  if (GNUNET_OK !=
3543  "MAX_QUEUE_LENGTH",
3544  &max_queue_length))
3546  if (GNUNET_OK !=
3549  "REKEY_INTERVAL",
3550  &rekey_interval))
3552 
3553  peerstore = GNUNET_PEERSTORE_connect (cfg);
3554  if (NULL == peerstore)
3555  {
3556  GNUNET_free (bindto);
3557  GNUNET_break (0);
3559  return;
3560  }
3561 
3563 
3564  if (1 == sscanf (bindto, "%u%1s", &bind_port, dummy))
3565  {
3567 
3568  addr_len_ipv4 = po->addr_len_ipv4;
3569 
3570 
3572  "address po %s\n",
3573  GNUNET_a2s (po->addr_ipv4, addr_len_ipv4));
3574 
3575  if (NULL != po->addr_ipv4)
3576  {
3577  init_socket (po->addr_ipv4, addr_len_ipv4);
3578  }
3579 
3580  if (NULL != po->addr_ipv6)
3581  {
3582  addr_len_ipv6 = po->addr_len_ipv6;
3583  init_socket (po->addr_ipv6, addr_len_ipv6);
3584  }
3585 
3586  GNUNET_free (po);
3587  nat_register ();
3588  GNUNET_free (bindto);
3589  return;
3590  }
3591 
3592  start = extract_address (bindto);
3593 
3594  if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
3595  {
3596  bind_port = extract_port (bindto);
3597 
3598  in = tcp_address_to_sockaddr_numeric_v4 (&in_len, v4, bind_port);
3599  init_socket (in, in_len);
3600  nat_register ();
3601  GNUNET_free (start);
3602  GNUNET_free (bindto);
3603  return;
3604  }
3605 
3606  if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
3607  {
3608  bind_port = extract_port (bindto);
3609  in = tcp_address_to_sockaddr_numeric_v6 (&in_len, v6, bind_port);
3610  init_socket (in, in_len);
3611  nat_register ();
3612  GNUNET_free (start);
3613  GNUNET_free (bindto);
3614  return;
3615  }
3616 
3617 
3618  bind_port = extract_port (bindto);
3619 
3620  resolve_request_handle = GNUNET_RESOLVER_ip_get (strtok_r (bindto, ":",
3621  &rest),
3622  AF_UNSPEC,
3625  &port);
3626  GNUNET_free (bindto);
3627  GNUNET_free (start);
3628 }
3629 
3630 
3638 int
3639 main (int argc, char *const *argv)
3640 {
3641  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
3643  };
3644  int ret;
3645 
3646  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
3647  return 2;
3648 
3649  ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc,
3650  argv,
3651  "gnunet-communicator-tcp",
3652  _ ("GNUnet TCP communicator"),
3653  options,
3654  &run,
3655  NULL))
3656  ? 0
3657  : 1;
3658  GNUNET_free_nz ((void *) argv);
3659  return ret;
3660 }
3661 
3662 
3663 /* 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), e.g.
static void setup_in_cipher(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, struct Queue *queue)
Setup cipher of queue for decryption.
int GNUNET_NETWORK_get_fd(const struct GNUNET_NETWORK_Handle *desc)
Return file descriptor for this network handle.
Definition: network.c:1077
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 WAN.
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:542
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:360
size_t unverified_size
Size of data received without KX challenge played back.
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.
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
struct ChallengeNonceP challenge
Challenge value used to protect against replay attack, if there is no stored monotonic time value...
size_t value_size
Size of value BLOB.
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:181
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.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1209
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
Database for peer&#39;s HELLOs.
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:178
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 ...
#define max(x, y)
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:435
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:758
#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:557
#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.
struct ChallengeNonceP challenge_received
Challenge value received.
#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.
static int res
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:213
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:658
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:197
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:718
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.
#define INITIAL_CORE_KX_SIZE
Size of the initial core key exchange messages.
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:83
struct GNUNET_ShortHashCode hmac
HMAC for the following encrypted message.
struct sockaddr * addr
Address we like to register at NAT service.
configuration data
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:232
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:604
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:464
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