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  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  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);
1903  if (-1 == rcvd)
1904  {
1905  if ((EAGAIN != errno) && (EINTR != errno))
1906  {
1908  queue_finish (queue);
1909  return;
1910  }
1911  /* try again */
1913  queue->read_task =
1914  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read, queue);
1915  return;
1916  }
1917  if (0 != rcvd)
1918  reschedule_queue_timeout (queue);
1919  queue->cread_off += rcvd;
1920  while ((queue->pread_off < sizeof(queue->pread_buf)) &&
1921  (queue->cread_off > 0))
1922  {
1923  size_t max = GNUNET_MIN (sizeof(queue->pread_buf) - queue->pread_off,
1924  queue->cread_off);
1925  size_t done;
1926  size_t total;
1927  size_t old_pread_off = queue->pread_off;
1928 
1929  GNUNET_assert (0 ==
1930  gcry_cipher_decrypt (queue->in_cipher,
1931  &queue->pread_buf[queue->pread_off],
1932  max,
1933  queue->cread_buf,
1934  max));
1935  queue->pread_off += max;
1936  total = 0;
1937  while (0 != (done = try_handle_plaintext (queue)))
1938  {
1939  /* 'done' bytes of plaintext were used, shift buffer */
1940  GNUNET_assert (done <= queue->pread_off);
1941  /* NOTE: this memmove() could possibly sometimes be
1942  avoided if we pass 'total' into try_handle_plaintext()
1943  and use it at an offset into the buffer there! */
1944  memmove (queue->pread_buf,
1945  &queue->pread_buf[done],
1946  queue->pread_off - done);
1947  queue->pread_off -= done;
1948  total += done;
1949  /* The last plaintext was a rekey, abort for now */
1950  if (GNUNET_YES == queue->rekeyed)
1951  break;
1952  }
1953  /* when we encounter a rekey message, the decryption above uses the
1954  wrong key for everything after the rekey; in that case, we have
1955  to re-do the decryption at 'total' instead of at 'max'.
1956  However, we have to take into account that the plaintext buffer may have
1957  already contained data and not jumped too far ahead in the ciphertext.
1958  If there is no rekey and the last message is incomplete (max > total),
1959  it is safe to keep the decryption so we shift by 'max' */
1960  if (GNUNET_YES == queue->rekeyed)
1961  {
1962  max = total - old_pread_off;
1963  queue->rekeyed = GNUNET_NO;
1964  queue->pread_off = 0;
1965  }
1966  memmove (queue->cread_buf, &queue->cread_buf[max], queue->cread_off - max);
1967  queue->cread_off -= max;
1968  }
1969  if (BUF_SIZE == queue->cread_off)
1970  return; /* buffer full, suspend reading */
1972  if (0 != left.rel_value_us)
1973  {
1974  if (max_queue_length > queue->backpressure)
1975  {
1976  /* continue reading */
1978  queue->read_task =
1979  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read, queue);
1980  }
1981  return;
1982  }
1984  "Queue %p was idle for %s, disconnecting\n",
1985  queue,
1988  GNUNET_YES));
1989  queue_finish (queue);
1990 }
1991 
1992 
2000 static struct sockaddr *
2001 tcp_address_to_sockaddr_numeric_v6 (socklen_t *sock_len, struct sockaddr_in6 v6,
2002  unsigned int port)
2003 {
2004  struct sockaddr *in;
2005 
2006  v6.sin6_family = AF_INET6;
2007  v6.sin6_port = htons ((uint16_t) port);
2008 #if HAVE_SOCKADDR_IN_SIN_LEN
2009  v6.sin6_len = sizeof(sizeof(struct sockaddr_in6));
2010 #endif
2011  v6.sin6_flowinfo = 0;
2012  v6.sin6_scope_id = 0;
2013  in = GNUNET_memdup (&v6, sizeof(v6));
2014  *sock_len = sizeof(struct sockaddr_in6);
2015 
2016  return in;
2017 }
2018 
2019 
2027 static struct sockaddr *
2028 tcp_address_to_sockaddr_numeric_v4 (socklen_t *sock_len, struct sockaddr_in v4,
2029  unsigned int port)
2030 {
2031  struct sockaddr *in;
2032 
2033  v4.sin_family = AF_INET;
2034  v4.sin_port = htons ((uint16_t) port);
2035 #if HAVE_SOCKADDR_IN_SIN_LEN
2036  v4.sin_len = sizeof(struct sockaddr_in);
2037 #endif
2038  in = GNUNET_memdup (&v4, sizeof(v4));
2039  *sock_len = sizeof(struct sockaddr_in);
2040  return in;
2041 }
2042 
2043 
2050 static struct PortOnlyIpv4Ipv6 *
2051 tcp_address_to_sockaddr_port_only (const char *bindto, unsigned int *port)
2052 {
2053  struct PortOnlyIpv4Ipv6 *po;
2054  struct sockaddr_in *i4;
2055  struct sockaddr_in6 *i6;
2056  socklen_t sock_len_ipv4;
2057  socklen_t sock_len_ipv6;
2058 
2059  /* interpreting value as just a PORT number */
2060  if (*port > UINT16_MAX)
2061  {
2063  "BINDTO specification `%s' invalid: value too large for port\n",
2064  bindto);
2065  return NULL;
2066  }
2067 
2068  po = GNUNET_new (struct PortOnlyIpv4Ipv6);
2069 
2070  if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
2071  (GNUNET_YES ==
2074  "DISABLE_V6")))
2075  {
2076  i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
2077  po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
2078  *port);
2079  po->addr_len_ipv4 = sock_len_ipv4;
2080  }
2081  else
2082  {
2083 
2084  i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
2085  po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
2086  *port);
2087  po->addr_len_ipv4 = sock_len_ipv4;
2088 
2089  i6 = GNUNET_malloc (sizeof(struct sockaddr_in6));
2090  po->addr_ipv6 = tcp_address_to_sockaddr_numeric_v6 (&sock_len_ipv6, *i6,
2091  *port);
2092 
2093  po->addr_len_ipv6 = sock_len_ipv6;
2094 
2095  GNUNET_free (i6);
2096  }
2097 
2098  GNUNET_free (i4);
2099 
2100  return po;
2101 }
2102 
2103 
2110 static char *
2111 extract_address (const char *bindto)
2112 {
2113 
2114  char *start;
2115  char *token;
2116  char *cp;
2117  char *rest = NULL;
2118 
2120  "extract address with bindto %s\n",
2121  bindto);
2122 
2123  if (NULL == bindto)
2125  "bindto is NULL\n");
2126 
2127  cp = GNUNET_strdup (bindto);
2128 
2130  "extract address 2\n");
2131 
2132  start = cp;
2133  if (('[' == *cp) && (']' == cp[strlen (cp) - 1]))
2134  {
2135  start++; /* skip over '['*/
2136  cp[strlen (cp) - 1] = '\0'; /* eat ']'*/
2137  }
2138  else
2139  {
2140  token = strtok_r (cp, "]", &rest);
2141  if (strlen (bindto) == strlen (token))
2142  {
2143  token = strtok_r (cp, ":", &rest);
2144  }
2145  else
2146  {
2147  token++;
2148  return token;
2149  }
2150  }
2151 
2153  "extract address 3\n");
2155  "extract address with start %s\n",
2156  start);
2157 
2158  return start;
2159 }
2160 
2161 
2168 static unsigned int
2169 extract_port (const char *addr_and_port)
2170 {
2171  unsigned int port;
2172  char dummy[2];
2173  char *token;
2174  char *addr;
2175  char *colon;
2176  char *cp;
2177  char *rest = NULL;
2178 
2179  if (NULL != addr_and_port)
2180  {
2181  cp = GNUNET_strdup (addr_and_port);
2182  token = strtok_r (cp, "]", &rest);
2183  if (strlen (addr_and_port) == strlen (token))
2184  {
2185  colon = strrchr (cp, ':');
2186  if (NULL == colon)
2187  {
2188  return 0;
2189  }
2190  addr = colon;
2191  addr++;
2192  }
2193  else
2194  {
2195  token = strtok_r (NULL, "]", &rest);
2196  if (NULL == token)
2197  {
2198  return 0;
2199  }
2200  else
2201  {
2202  addr = token;
2203  addr++;
2204  }
2205  }
2206 
2207 
2208  if (1 == sscanf (addr, "%u%1s", &port, dummy))
2209  {
2210  /* interpreting value as just a PORT number */
2211  if (port > UINT16_MAX)
2212  {
2214  "Port `%u' invalid: value too large for port\n",
2215  port);
2216  // GNUNET_free (cp);
2217  return 0;
2218  }
2219  }
2220  else
2221  {
2223  "BINDTO specification invalid: last ':' not followed by number\n");
2224  // GNUNET_free (cp);
2225  return 0;
2226  }
2227  }
2228  else
2229  {
2231  "return 0\n");
2232  /* interpret missing port as 0, aka pick any free one */
2233  port = 0;
2234  }
2235 
2236 
2237  return port;
2238 }
2239 
2240 
2248 static struct sockaddr *
2249 tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
2250 {
2251  struct sockaddr *in;
2252  unsigned int port;
2253  struct sockaddr_in v4;
2254  struct sockaddr_in6 v6;
2255  const char *start;
2256 
2257  // cp = GNUNET_strdup (bindto);
2258  start = extract_address (bindto);
2259 
2261  "start %s\n",
2262  start);
2263 
2265  "!bindto %s\n",
2266  bindto);
2267 
2268 
2269  if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
2270  {
2271  // colon = strrchr (cp, ':');
2272  port = extract_port (bindto);
2273 
2275  "port %u\n",
2276  port);
2277 
2278  in = tcp_address_to_sockaddr_numeric_v4 (sock_len, v4, port);
2279  }
2280  else if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
2281  {
2282  // colon = strrchr (cp, ':');
2283  port = extract_port (bindto);
2284  in = tcp_address_to_sockaddr_numeric_v6 (sock_len, v6, port);
2285  }
2286  else
2287  {
2288  GNUNET_assert (0);
2289  }
2290 
2291  // GNUNET_free (start);
2292 
2293  return in;
2294 }
2295 
2296 
2305 static void
2307  const struct GNUNET_MessageHeader *msg,
2308  void *impl_state)
2309 {
2310  struct Queue *queue = impl_state;
2311  uint16_t msize = ntohs (msg->size);
2312  struct TCPBox box;
2314  "In MQ send. Queue finishing: %s; write task running: %s\n",
2315  (GNUNET_YES == queue->finishing) ? "yes" : "no",
2316  (NULL == queue->write_task) ? "yes" : "no");
2317  GNUNET_assert (mq == queue->mq);
2318  queue->mq_awaits_continue = GNUNET_YES;
2319  if (GNUNET_YES == queue->finishing)
2320  return; /* this queue is dying, drop msg */
2321  GNUNET_assert (0 == queue->pwrite_off);
2323  box.header.size = htons (msize);
2324  calculate_hmac (&queue->out_hmac, msg, msize, &box.hmac);
2325  memcpy (&queue->pwrite_buf[queue->pwrite_off], &box, sizeof(box));
2326  queue->pwrite_off += sizeof(box);
2327  memcpy (&queue->pwrite_buf[queue->pwrite_off], msg, msize);
2328  queue->pwrite_off += msize;
2330  "%lu bytes of plaintext to send\n", queue->pwrite_off);
2331  GNUNET_assert (NULL != queue->sock);
2332  if (NULL == queue->write_task)
2333  queue->write_task =
2335  queue->sock,
2336  &queue_write,
2337  queue);
2338 }
2339 
2340 
2349 static void
2350 mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state)
2351 {
2352  struct Queue *queue = impl_state;
2353 
2354  if (mq == queue->mq)
2355  {
2356  queue->mq = NULL;
2357  queue_finish (queue);
2358  }
2359 }
2360 
2361 
2368 static void
2369 mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
2370 {
2371  struct Queue *queue = impl_state;
2372 
2373  GNUNET_assert (0 != queue->pwrite_off);
2374  queue->pwrite_off = 0;
2375 }
2376 
2377 
2387 static void
2388 mq_error (void *cls, enum GNUNET_MQ_Error error)
2389 {
2390  struct Queue *queue = cls;
2391 
2393  "MQ error in queue to %s: %d\n",
2394  GNUNET_i2s (&queue->target),
2395  (int) error);
2396  queue_finish (queue);
2397 }
2398 
2399 
2407 static void
2409 {
2410  queue->nt =
2411  GNUNET_NT_scanner_get_type (is, queue->address, queue->address_len);
2413  queue_map,
2414  &queue->target,
2415  queue,
2417  GNUNET_STATISTICS_set (stats,
2418  "# queues active",
2420  GNUNET_NO);
2421  queue->timeout =
2424  &mq_destroy,
2425  &mq_cancel,
2426  queue,
2427  NULL,
2428  &mq_error,
2429  queue);
2430  /* { */
2431  /* char *foreign_addr; */
2432 
2433  /* switch (queue->address->sa_family) */
2434  /* { */
2435  /* case AF_INET: */
2436  /* GNUNET_asprintf (&foreign_addr, */
2437  /* "%s-%s", */
2438  /* COMMUNICATOR_ADDRESS_PREFIX, */
2439  /* GNUNET_a2s (queue->address, queue->address_len)); */
2440  /* break; */
2441 
2442  /* case AF_INET6: */
2443  /* GNUNET_asprintf (&foreign_addr, */
2444  /* "%s-%s", */
2445  /* COMMUNICATOR_ADDRESS_PREFIX, */
2446  /* GNUNET_a2s (queue->address, queue->address_len)); */
2447  /* break; */
2448 
2449  /* default: */
2450  /* GNUNET_assert (0); */
2451  /* } */
2452  /* queue->qh = GNUNET_TRANSPORT_communicator_mq_add (ch, */
2453  /* &queue->target, */
2454  /* foreign_addr, */
2455  /* 0 /\* no MTU *\/, */
2456  /* GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED, */
2457  /* 0, /\* Priority *\/ */
2458  /* queue->nt, */
2459  /* queue->cs, */
2460  /* queue->mq); */
2461  /* GNUNET_free (foreign_addr); */
2462  /* } */
2463 }
2464 
2465 
2476 static void
2478  const struct GNUNET_CRYPTO_EcdhePublicKey *epub)
2479 {
2480  struct TcpHandshakeSignature ths;
2481  struct TCPConfirmation tc;
2482 
2483  memcpy (queue->cwrite_buf, epub, sizeof(*epub));
2484  queue->cwrite_off = sizeof(*epub);
2485  /* compute 'tc' and append in encrypted format to cwrite_buf */
2486  tc.sender = my_identity;
2487  tc.monotonic_time =
2490  &tc.challenge,
2491  sizeof(tc.challenge));
2493  ths.purpose.size = htonl (sizeof(ths));
2494  ths.sender = my_identity;
2495  ths.receiver = queue->target;
2496  ths.ephemeral = *epub;
2497  ths.monotonic_time = tc.monotonic_time;
2498  ths.challenge = tc.challenge;
2499  GNUNET_CRYPTO_eddsa_sign (my_private_key,
2500  &ths,
2501  &tc.sender_sig);
2502  GNUNET_assert (0 ==
2503  gcry_cipher_encrypt (queue->out_cipher,
2504  &queue->cwrite_buf[queue->cwrite_off],
2505  sizeof(tc),
2506  &tc,
2507  sizeof(tc)));
2508  queue->challenge = tc.challenge;
2509  queue->cwrite_off += sizeof(tc);
2510 
2512  "transport",
2513  "handshake written\n");
2514 }
2515 
2516 
2524 static void
2526 {
2527  struct GNUNET_CRYPTO_EcdhePublicKey epub;
2528 
2531  setup_out_cipher (queue);
2532  transmit_kx (queue, &epub);
2533 }
2534 
2535 
2541 static void
2542 handshake_monotime_store_cb (void *cls, int success)
2543 {
2544  struct Queue *queue = cls;
2545  if (GNUNET_OK != success)
2546  {
2548  "Failed to store handshake monotonic time in PEERSTORE!\n");
2549  }
2550  queue->handshake_monotime_sc = NULL;
2551 }
2552 
2553 
2561 static void
2563  const struct GNUNET_PEERSTORE_Record *record,
2564  const char *emsg)
2565 {
2566  struct Queue *queue = cls;
2567  struct GNUNET_TIME_AbsoluteNBO *mtbe;
2568  struct GNUNET_TIME_Absolute mt;
2569  const struct GNUNET_PeerIdentity *pid;
2570  struct GNUNET_TIME_AbsoluteNBO *handshake_monotonic_time;
2571 
2572  (void) emsg;
2573 
2574  handshake_monotonic_time = &queue->handshake_monotonic_time;
2575  pid = &queue->target;
2576  if (NULL == record)
2577  {
2578  queue->handshake_monotime_get = NULL;
2579  return;
2580  }
2581  if (sizeof(*mtbe) != record->value_size)
2582  {
2583  GNUNET_break (0);
2584  return;
2585  }
2586  mtbe = record->value;
2587  mt = GNUNET_TIME_absolute_ntoh (*mtbe);
2590  {
2592  "Queue from %s dropped, handshake monotime in the past\n",
2593  GNUNET_i2s (&queue->target));
2594  GNUNET_break (0);
2595  queue_finish (queue);
2596  return;
2597  }
2598  queue->handshake_monotime_sc = GNUNET_PEERSTORE_store (peerstore,
2599  "transport_tcp_communicator",
2600  pid,
2602  handshake_monotonic_time,
2603  sizeof(
2604  handshake_monotonic_time),
2607  &
2609  queue);
2610 }
2611 
2612 
2624 static int
2626  struct TCPConfirmation *tc,
2627  char *ibuf)
2628 {
2629  struct TcpHandshakeSignature ths;
2630 
2631  GNUNET_assert (
2632  0 ==
2633  gcry_cipher_decrypt (queue->in_cipher,
2634  tc,
2635  sizeof(*tc),
2636  &ibuf[sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)],
2637  sizeof(*tc)));
2639  ths.purpose.size = htonl (sizeof(ths));
2640  ths.sender = tc->sender;
2641  ths.receiver = my_identity;
2642  memcpy (&ths.ephemeral, ibuf, sizeof(struct GNUNET_CRYPTO_EcdhePublicKey));
2643  ths.monotonic_time = tc->monotonic_time;
2644  ths.challenge = tc->challenge;
2647  &ths,
2648  &tc->sender_sig,
2649  &tc->sender.public_key);
2651  "transport_tcp_communicator",
2652  &queue->target,
2654  &
2656  queue);
2657 }
2658 
2659 
2665 static void
2667 {
2668  if (NULL != pq->listen_sock)
2669  {
2671  pq->listen_sock = NULL;
2672  }
2674  GNUNET_free (pq->address);
2675  GNUNET_CONTAINER_DLL_remove (proto_head, proto_tail, pq);
2676  GNUNET_free (pq);
2677 }
2678 
2679 
2686 static void
2687 proto_read_kx (void *cls)
2688 {
2689  struct ProtoQueue *pq = cls;
2690  ssize_t rcvd;
2691  struct GNUNET_TIME_Relative left;
2692  struct Queue *queue;
2693  struct TCPConfirmation tc;
2694 
2695  pq->read_task = NULL;
2697  if (0 == left.rel_value_us)
2698  {
2699  free_proto_queue (pq);
2700  return;
2701  }
2702  rcvd = GNUNET_NETWORK_socket_recv (pq->sock,
2703  &pq->ibuf[pq->ibuf_off],
2704  sizeof(pq->ibuf) - pq->ibuf_off);
2706  "Received %lu bytes for KX\n", rcvd);
2707  if (-1 == rcvd)
2708  {
2709  if ((EAGAIN != errno) && (EINTR != errno))
2710  {
2712  free_proto_queue (pq);
2713  return;
2714  }
2715  /* try again */
2716  pq->read_task =
2718  return;
2719  }
2720  pq->ibuf_off += rcvd;
2721  if (pq->ibuf_off > sizeof(pq->ibuf))
2722  {
2723  /* read more */
2724  pq->read_task =
2726  return;
2727  }
2728  /* we got all the data, let's find out who we are talking to! */
2729  queue = GNUNET_new (struct Queue);
2730  setup_in_cipher ((const struct GNUNET_CRYPTO_EcdhePublicKey *) pq->ibuf,
2731  queue);
2732  if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, pq->ibuf))
2733  {
2735  "Invalid TCP KX received from %s\n",
2736  GNUNET_a2s (queue->address, queue->address_len));
2737  gcry_cipher_close (queue->in_cipher);
2738  GNUNET_free (queue);
2739  free_proto_queue (pq);
2740  return;
2741  }
2742  queue->address = pq->address; /* steals reference */
2743  queue->address_len = pq->address_len;
2744  queue->target = tc.sender;
2745  queue->listen_sock = pq->listen_sock;
2746  queue->sock = pq->sock;
2747 
2748 
2750  "start kx proto\n");
2751 
2752  start_initial_kx_out (queue);
2754  boot_queue (queue);
2755  queue->read_task =
2757  queue->sock,
2758  &queue_read,
2759  queue);
2760  queue->write_task =
2762  queue->sock,
2763  &queue_write,
2764  queue);
2765  // TODO To early! Move it somewhere else.
2766  // send_challenge (tc.challenge, queue);
2767  queue->challenge_received = tc.challenge;
2768 
2769  GNUNET_CONTAINER_DLL_remove (proto_head, proto_tail, pq);
2770  GNUNET_free (pq);
2771 }
2772 
2773 
2781 static void
2782 listen_cb (void *cls)
2783 {
2784  struct sockaddr_storage in;
2785  socklen_t addrlen;
2786  struct GNUNET_NETWORK_Handle *sock;
2787  struct ProtoQueue *pq;
2788  struct ListenTask *lt;
2789 
2791  "listen_cb\n");
2792 
2793  lt = cls;
2794 
2795  lt->listen_task = NULL;
2796  GNUNET_assert (NULL != lt->listen_sock);
2797  addrlen = sizeof(in);
2798  memset (&in, 0, sizeof(in));
2800  (struct sockaddr*) &in,
2801  &addrlen);
2802  if ((NULL == sock) && ((EMFILE == errno) || (ENFILE == errno)))
2803  return; /* system limit reached, wait until connection goes down */
2805  lt->listen_sock,
2806  &listen_cb,
2807  lt);
2808  if ((NULL == sock) && ((EAGAIN == errno) || (ENOBUFS == errno)))
2809  return;
2810  if (NULL == sock)
2811  {
2813  return;
2814  }
2815  pq = GNUNET_new (struct ProtoQueue);
2816  pq->address_len = addrlen;
2817  pq->address = GNUNET_memdup (&in, addrlen);
2819  pq->sock = sock;
2821  pq->sock,
2822  &proto_read_kx,
2823  pq);
2824  GNUNET_CONTAINER_DLL_insert (proto_head, proto_tail, pq);
2825 }
2826 
2827 
2835 static void
2836 queue_read_kx (void *cls)
2837 {
2838  struct Queue *queue = cls;
2839  ssize_t rcvd;
2840  struct GNUNET_TIME_Relative left;
2841  struct TCPConfirmation tc;
2842 
2843  queue->read_task = NULL;
2845  if (0 == left.rel_value_us)
2846  {
2847  queue_destroy (queue);
2848  return;
2849  }
2850  rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
2851  &queue->cread_buf[queue->cread_off],
2852  BUF_SIZE - queue->cread_off);
2854  "Received %lu bytes for KX\n",
2855  rcvd);
2856  if (-1 == rcvd)
2857  {
2858  if ((EAGAIN != errno) && (EINTR != errno))
2859  {
2861  queue_destroy (queue);
2862  return;
2863  }
2864  queue->read_task =
2865  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read_kx, queue);
2866  return;
2867  }
2868  queue->cread_off += rcvd;
2869  if (queue->cread_off < INITIAL_KX_SIZE)
2870  {
2871  /* read more */
2872  queue->read_task =
2873  GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read_kx, queue);
2874  return;
2875  }
2876  /* we got all the data, let's find out who we are talking to! */
2878  queue->cread_buf,
2879  queue);
2880  if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, queue->cread_buf))
2881  {
2883  "Invalid TCP KX received from %s\n",
2884  GNUNET_a2s (queue->address, queue->address_len));
2885  queue_destroy (queue);
2886  return;
2887  }
2888  if (0 !=
2889  memcmp (&tc.sender, &queue->target, sizeof(struct GNUNET_PeerIdentity)))
2890  {
2892  "Invalid sender in TCP KX received from %s\n",
2893  GNUNET_a2s (queue->address, queue->address_len));
2894  queue_destroy (queue);
2895  return;
2896  }
2897  send_challenge (tc.challenge, queue);
2898  queue->write_task =
2900  queue->sock,
2901  &queue_write,
2902  queue);
2903 
2904  /* update queue timeout */
2905  reschedule_queue_timeout (queue);
2906  /* prepare to continue with regular read task immediately */
2907  memmove (queue->cread_buf,
2908  &queue->cread_buf[INITIAL_KX_SIZE],
2909  queue->cread_off - (INITIAL_KX_SIZE));
2911  "cread_off is %lu bytes before adjusting\n",
2912  queue->cread_off);
2913  queue->cread_off -= INITIAL_KX_SIZE;
2915  "cread_off set to %lu bytes\n",
2916  queue->cread_off);
2917  if (0 <= queue->cread_off)
2918  queue->read_task = GNUNET_SCHEDULER_add_now (&queue_read, queue);
2919 }
2920 
2921 
2940 static int
2941 mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
2942 {
2943  struct Queue *queue;
2944  const char *path;
2945  struct sockaddr *in;
2946  socklen_t in_len = 0;
2947  struct GNUNET_NETWORK_Handle *sock;
2948 
2950  "Connecting to %s\n", address);
2951  if (0 != strncmp (address,
2953  strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
2954  {
2955  GNUNET_break_op (0);
2956  return GNUNET_SYSERR;
2957  }
2958  path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
2959  in = tcp_address_to_sockaddr (path, &in_len);
2960 
2961  if (NULL == in)
2962  {
2964  "Failed to setup TCP socket address\n");
2965  return GNUNET_SYSERR;
2966  }
2967 
2969  "in %s\n",
2970  GNUNET_a2s (in, in_len));
2971 
2972  sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, IPPROTO_TCP);
2973  if (NULL == sock)
2974  {
2976  "socket(%d) failed: %s",
2977  in->sa_family,
2978  strerror (errno));
2979  GNUNET_free (in);
2980  return GNUNET_SYSERR;
2981  }
2982  if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, in_len)) &&
2983  (errno != EINPROGRESS))
2984  {
2986  "connect to `%s' failed: %s",
2987  address,
2988  strerror (errno));
2990  GNUNET_free (in);
2991  return GNUNET_SYSERR;
2992  }
2993 
2994  queue = GNUNET_new (struct Queue);
2995  queue->target = *peer;
2996  queue->address = in;
2997  queue->address_len = in_len;
2998  queue->sock = sock;
3000  boot_queue (queue);
3001  // queue->mq_awaits_continue = GNUNET_YES;
3002  queue->read_task =
3004  queue->sock,
3005  &queue_read_kx,
3006  queue);
3007 
3008 
3010  "start kx mq_init\n");
3011 
3012  start_initial_kx_out (queue);
3013  queue->write_task =
3015  queue->sock,
3016  &queue_write,
3017  queue);
3018  return GNUNET_OK;
3019 }
3020 
3021 
3030 static int
3031 get_lt_delete_it (void *cls,
3032  const struct GNUNET_HashCode *key,
3033  void *value)
3034 {
3035  struct ListenTask *lt = value;
3036 
3037  (void) cls;
3038  (void) key;
3039  if (NULL != lt->listen_task)
3040  {
3042  lt->listen_task = NULL;
3043  }
3044  if (NULL != lt->listen_sock)
3045  {
3047  lt->listen_sock = NULL;
3048  }
3049  return GNUNET_OK;
3050 }
3051 
3052 
3061 static int
3063  const struct GNUNET_PeerIdentity *target,
3064  void *value)
3065 {
3066  struct Queue *queue = value;
3067 
3068  (void) cls;
3069  (void) target;
3070  queue_destroy (queue);
3071  return GNUNET_OK;
3072 }
3073 
3074 
3080 static void
3081 do_shutdown (void *cls)
3082 {
3084  "Shutdown %s!\n",
3085  shutdown_running ? "running" : "not running");
3086 
3088  return;
3089  else
3091 
3092  while (NULL != proto_head)
3093  free_proto_queue (proto_head);
3094  if (NULL != nat)
3095  {
3096  GNUNET_NAT_unregister (nat);
3097  nat = NULL;
3098  }
3103  if (NULL != ch)
3104  {
3106  ch = NULL;
3107  }
3108  if (NULL != stats)
3109  {
3111  stats = NULL;
3112  }
3113  if (NULL != my_private_key)
3114  {
3115  GNUNET_free (my_private_key);
3116  my_private_key = NULL;
3117  }
3118  if (NULL != is)
3119  {
3121  is = NULL;
3122  }
3123  if (NULL != peerstore)
3124  {
3126  peerstore = NULL;
3127  }
3128  if (NULL != resolve_request_handle)
3129  {
3130  GNUNET_RESOLVER_request_cancel (resolve_request_handle);
3131  resolve_request_handle = NULL;
3132  }
3134  "Shutdown done!\n");
3135 }
3136 
3137 
3149 static void
3150 enc_notify_cb (void *cls,
3151  const struct GNUNET_PeerIdentity *sender,
3152  const struct GNUNET_MessageHeader *msg)
3153 {
3154  (void) cls;
3155  (void) sender;
3156  (void) msg;
3157  GNUNET_break_op (0);
3158 }
3159 
3160 
3174 static void
3175 nat_address_cb (void *cls,
3176  void **app_ctx,
3177  int add_remove,
3179  const struct sockaddr *addr,
3180  socklen_t addrlen)
3181 {
3182  char *my_addr;
3184 
3186  "nat address cb %s %s\n",
3187  add_remove ? "add" : "remove",
3188  GNUNET_a2s (addr, addrlen));
3189 
3190  if (GNUNET_YES == add_remove)
3191  {
3192  enum GNUNET_NetworkType nt;
3193 
3194  GNUNET_asprintf (&my_addr,
3195  "%s-%s",
3197  GNUNET_a2s (addr, addrlen));
3198  nt = GNUNET_NT_scanner_get_type (is, addr, addrlen);
3199  ai =
3201  my_addr,
3202  nt,
3204  GNUNET_free (my_addr);
3205  *app_ctx = ai;
3206  }
3207  else
3208  {
3209  ai = *app_ctx;
3211  *app_ctx = NULL;
3212  }
3213 }
3214 
3215 
3219 static void
3220 add_addr (struct sockaddr *in, socklen_t in_len)
3221 {
3222 
3223  struct Addresses *saddrs;
3224 
3226  "add address %s\n",
3227  GNUNET_a2s (in, in_len));
3228 
3229  saddrs = GNUNET_new (struct Addresses);
3230  saddrs->addr = in;
3231  saddrs->addr_len = in_len;
3232  GNUNET_CONTAINER_DLL_insert (addrs_head, addrs_tail, saddrs);
3233 
3235  "after add address %s\n",
3236  GNUNET_a2s (in, in_len));
3237 
3239  "add address %s\n",
3240  GNUNET_a2s (saddrs->addr, saddrs->addr_len));
3241 
3242  addrs_lens++;
3243 }
3244 
3245 
3253 static int
3254 init_socket (struct sockaddr *addr,
3255  socklen_t in_len)
3256 {
3257  struct sockaddr_storage in_sto;
3258  socklen_t sto_len;
3259  struct GNUNET_NETWORK_Handle *listen_sock;
3260  struct ListenTask *lt;
3261  int sockfd;
3262  struct GNUNET_HashCode h_sock;
3263 
3264  if (NULL == addr)
3265  {
3267  "Address is NULL.\n");
3268  return GNUNET_SYSERR;
3269  }
3270 
3272  "address %s\n",
3273  GNUNET_a2s (addr, in_len));
3274 
3275  listen_sock =
3276  GNUNET_NETWORK_socket_create (addr->sa_family, SOCK_STREAM, IPPROTO_TCP);
3277  if (NULL == listen_sock)
3278  {
3280  return GNUNET_SYSERR;
3281  }
3282 
3283  if (GNUNET_OK != GNUNET_NETWORK_socket_bind (listen_sock, addr, in_len))
3284  {
3286  GNUNET_NETWORK_socket_close (listen_sock);
3287  listen_sock = NULL;
3288  return GNUNET_SYSERR;
3289  }
3290 
3291  if (GNUNET_OK !=
3292  GNUNET_NETWORK_socket_listen (listen_sock,
3293  5))
3294  {
3296  "listen");
3297  GNUNET_NETWORK_socket_close (listen_sock);
3298  listen_sock = NULL;
3299  return GNUNET_SYSERR;
3300  }
3301 
3302  /* We might have bound to port 0, allowing the OS to figure it out;
3303  thus, get the real IN-address from the socket */
3304  sto_len = sizeof(in_sto);
3305 
3306  if (0 != getsockname (GNUNET_NETWORK_get_fd (listen_sock),
3307  (struct sockaddr *) &in_sto,
3308  &sto_len))
3309  {
3310  memcpy (&in_sto, addr, in_len);
3311  sto_len = in_len;
3312  }
3313 
3314  // addr = (struct sockaddr *) &in_sto;
3315  in_len = sto_len;
3317  "Bound to `%s'\n",
3318  GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len));
3319  stats = GNUNET_STATISTICS_create ("C-TCP", cfg);
3320 
3321  if (NULL == is)
3322  is = GNUNET_NT_scanner_init ();
3323 
3324  if (NULL == my_private_key)
3326  if (NULL == my_private_key)
3327  {
3328  GNUNET_log (
3330  _ (
3331  "Transport service is lacking key configuration settings. Exiting.\n"));
3332  if (NULL != resolve_request_handle)
3333  GNUNET_RESOLVER_request_cancel (resolve_request_handle);
3335  return GNUNET_SYSERR;
3336  }
3338  /* start listening */
3339 
3340  lt = GNUNET_new (struct ListenTask);
3341  lt->listen_sock = listen_sock;
3342 
3344  listen_sock,
3345  &listen_cb,
3346  lt);
3347 
3349  "creating hash\n");
3350  sockfd = GNUNET_NETWORK_get_fd (lt->listen_sock);
3351  GNUNET_CRYPTO_hash (&sockfd,
3352  sizeof(int),
3353  &h_sock);
3354 
3356  "creating map\n");
3357  if (NULL == lt_map)
3359 
3361  "creating map entry\n");
3363  &h_sock,
3364  lt,
3366 
3368  "map entry created\n");
3369 
3370  if (NULL == queue_map)
3372 
3373  if (NULL == ch)
3378  &mq_init,
3379  NULL,
3380  &enc_notify_cb,
3381  NULL);
3382 
3383  if (NULL == ch)
3384  {
3385  GNUNET_break (0);
3386  if (NULL != resolve_request_handle)
3387  GNUNET_RESOLVER_request_cancel (resolve_request_handle);
3389  return GNUNET_SYSERR;
3390  }
3391 
3392  add_addr (addr, in_len);
3393  return GNUNET_OK;
3394 
3395 }
3396 
3397 
3401 static void
3403 {
3404 
3405  struct sockaddr **saddrs;
3406  socklen_t *saddr_lens;
3407  int i;
3408  struct Addresses *pos;
3409 
3410 
3412  "starting nat register!\n");
3413 
3414  i = 0;
3415  saddrs = GNUNET_malloc ((addrs_lens + 1) * sizeof(struct sockaddr *));
3416 
3417  saddr_lens = GNUNET_malloc ((addrs_lens + 1) * sizeof(socklen_t));
3418 
3419  for (pos = addrs_head; NULL != pos; pos = pos->next)
3420  {
3421 
3423  "registering address %s\n",
3424  GNUNET_a2s (addrs_head->addr, addrs_head->addr_len));
3425 
3426  saddr_lens[i] = addrs_head->addr_len;
3427  saddrs[i] = GNUNET_memdup (addrs_head->addr, saddr_lens[i]);
3428 
3429  i++;
3430 
3431  }
3432 
3433  nat = GNUNET_NAT_register (cfg,
3435  IPPROTO_TCP,
3436  addrs_lens,
3437  (const struct sockaddr **) saddrs,
3438  saddr_lens,
3439  &nat_address_cb,
3440  NULL /* FIXME: support reversal: #5529 */,
3441  NULL /* closure */);
3442 
3443  i = 0;
3444 
3445  for (i = addrs_lens - 1; i >= 0; i--)
3446  GNUNET_free (saddrs[i]);
3447  GNUNET_free (saddrs);
3448  GNUNET_free (saddr_lens);
3449 
3450  if (NULL == nat)
3451  {
3452  GNUNET_break (0);
3453  if (NULL != resolve_request_handle)
3454  GNUNET_RESOLVER_request_cancel (resolve_request_handle);
3456  }
3457 }
3458 
3459 
3467 static void
3469  const struct sockaddr *addr,
3470  socklen_t in_len)
3471 {
3472  struct sockaddr_in *v4;
3473  struct sockaddr_in6 *v6;
3474  struct sockaddr *in;
3475 
3476  (void) cls;
3477  if (NULL != addr)
3478  {
3479  if (AF_INET == addr->sa_family)
3480  {
3481  v4 = (struct sockaddr_in *) addr;
3482  in = tcp_address_to_sockaddr_numeric_v4 (&in_len, *v4, bind_port);// _global);
3483  }
3484  else if (AF_INET6 == addr->sa_family)
3485  {
3486  v6 = (struct sockaddr_in6 *) addr;
3487  in = tcp_address_to_sockaddr_numeric_v6 (&in_len, *v6, bind_port);// _global);
3488  }
3489  else
3490  {
3492  "Address family %u not suitable (not AF_INET %u nor AF_INET6 %u \n",
3493  addr->sa_family,
3494  AF_INET,
3495  AF_INET6);
3496  return;
3497  }
3498  init_socket (in, in_len);
3499  }
3500  else
3501  {
3503  "Address is NULL. This might be an error or the resolver finished resolving.\n");
3504  if (NULL == addrs_head)
3505  {
3507  "Resolver finished resolving, but we do not listen to an address!.\n");
3508  return;
3509  }
3510  nat_register ();
3511 
3512  }
3513 }
3514 
3515 
3524 static void
3525 run (void *cls,
3526  char *const *args,
3527  const char *cfgfile,
3528  const struct GNUNET_CONFIGURATION_Handle *c)
3529 {
3530  char *bindto;
3531  struct sockaddr *in;
3532  socklen_t in_len;
3533  struct sockaddr_in v4;
3534  struct sockaddr_in6 v6;
3535  char *start;
3536  unsigned int port;
3537  char dummy[2];
3538  char *rest = NULL;
3539  struct PortOnlyIpv4Ipv6 *po;
3540  socklen_t addr_len_ipv4;
3541  socklen_t addr_len_ipv6;
3542 
3543  (void) cls;
3544  cfg = c;
3545  if (GNUNET_OK !=
3548  "BINDTO",
3549  &bindto))
3550  {
3553  "BINDTO");
3554  return;
3555  }
3556  if (GNUNET_OK !=
3559  "MAX_QUEUE_LENGTH",
3560  &max_queue_length))
3562  if (GNUNET_OK !=
3565  "REKEY_INTERVAL",
3566  &rekey_interval))
3568 
3569  peerstore = GNUNET_PEERSTORE_connect (cfg);
3570  if (NULL == peerstore)
3571  {
3572  GNUNET_free (bindto);
3573  GNUNET_break (0);
3575  return;
3576  }
3577 
3579 
3580  if (1 == sscanf (bindto, "%u%1s", &bind_port, dummy))
3581  {
3583 
3584  addr_len_ipv4 = po->addr_len_ipv4;
3585 
3586 
3588  "address po %s\n",
3589  GNUNET_a2s (po->addr_ipv4, addr_len_ipv4));
3590 
3591  if (NULL != po->addr_ipv4)
3592  {
3593  init_socket (po->addr_ipv4, addr_len_ipv4);
3594  }
3595 
3596  if (NULL != po->addr_ipv6)
3597  {
3598  addr_len_ipv6 = po->addr_len_ipv6;
3599  init_socket (po->addr_ipv6, addr_len_ipv6);
3600  }
3601 
3602  GNUNET_free (po);
3603  nat_register ();
3604  GNUNET_free (bindto);
3605  return;
3606  }
3607 
3608  start = extract_address (bindto);
3609 
3610  if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
3611  {
3612  bind_port = extract_port (bindto);
3613 
3614  in = tcp_address_to_sockaddr_numeric_v4 (&in_len, v4, bind_port);
3615  init_socket (in, in_len);
3616  nat_register ();
3617  GNUNET_free (start);
3618  GNUNET_free (bindto);
3619  return;
3620  }
3621 
3622  if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
3623  {
3624  bind_port = extract_port (bindto);
3625  in = tcp_address_to_sockaddr_numeric_v6 (&in_len, v6, bind_port);
3626  init_socket (in, in_len);
3627  nat_register ();
3628  GNUNET_free (start);
3629  GNUNET_free (bindto);
3630  return;
3631  }
3632 
3633 
3634  bind_port = extract_port (bindto);
3635 
3636  resolve_request_handle = GNUNET_RESOLVER_ip_get (strtok_r (bindto, ":",
3637  &rest),
3638  AF_UNSPEC,
3641  &port);
3642  GNUNET_free (bindto);
3643  GNUNET_free (start);
3644 }
3645 
3646 
3654 int
3655 main (int argc, char *const *argv)
3656 {
3657  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
3659  };
3660  int ret;
3661 
3662  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
3663  return 2;
3664 
3665  ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc,
3666  argv,
3667  "gnunet-communicator-tcp",
3668  _ ("GNUnet TCP communicator"),
3669  options,
3670  &run,
3671  NULL))
3672  ? 0
3673  : 1;
3674  GNUNET_free_nz ((void *) argv);
3675  return ret;
3676 }
3677 
3678 
3679 /* 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:474
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration, parse options).
Definition: program.c:363
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.
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1459
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c: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.
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:702
#define GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE_ACK
Signature by a peer sending back the nonce received at initial handshake.
Randomness for IVs etc.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_kdf(void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
Derive key.
Definition: crypto_kdf.c:90
static char buf[2048]
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Our private key.
struct GNUNET_TRANSPORT_CommunicatorHandle * GNUNET_TRANSPORT_communicator_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *config_section_name, const char *addr_prefix, enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, GNUNET_TRANSPORT_CommunicatorMqInit mq_init, void *mq_init_cls, GNUNET_TRANSPORT_CommunicatorNotify notify_cb, void *notify_cb_cls)
Connect to the transport service.
void GNUNET_PEERSTORE_store_cancel(struct GNUNET_PEERSTORE_StoreContext *sc)
Cancel a store request.
struct GNUNET_PEERSTORE_StoreContext * rekey_monotime_sc
Store Context for retrieving the monotonic time send with key for rekeying.
static void setup_cipher(const struct GNUNET_HashCode *dh, const struct GNUNET_PeerIdentity *pid, gcry_cipher_hd_t *cipher, struct GNUNET_HashCode *hmac_key)
Setup cipher based on shared secret dh and decrypting peer pid.
this is an inbound connection (communicator initiated)
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static void mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state)
Signature of functions implementing the destruction of a message queue.
struct GNUNET_CRYPTO_EddsaSignature sender_sig
Sender&#39;s signature of type GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE_ACK.
static void reschedule_queue_timeout(struct Queue *queue)
Increment queue timeout due to activity.
static void queue_finish(struct Queue *queue)
Append a &#39;finish&#39; message to the outgoing transmission.
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages)...
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH.
struct GNUNET_NETWORK_Handle * sock
socket that we transmit all data with on this queue
struct GNUNET_TIME_Absolute timeout
Timeout for this protoqueue.
struct sockaddr * addr_ipv6
Ipv6 address we like to bind to.
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!)...
Internal representation of the hash map.
struct GNUNET_SCHEDULER_Task * write_task
ID of write task for this connection.
struct sockaddr * address
Address of the other peer.
struct Addresses * addrs_head
Head of DLL with addresses we like to register at NAT servcie.
Handle to the PEERSTORE service.
Definition: peerstore_api.c:40
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
A 512-bit hashcode.
struct GNUNET_CRYPTO_EddsaSignature sender_sig
Sender&#39;s signature of type GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY.
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.
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:590
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
Definition: configuration.c:84
struct GNUNET_TIME_AbsoluteNBO handshake_monotonic_time
Monotonic time value for handshake message.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_time(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, struct GNUNET_TIME_Relative *time)
Get a configuration value that should be a relative time.
this is an outbound connection (transport initiated)
struct GNUNET_CRYPTO_EcdhePublicKey ephemeral
Ephemeral key used by the sender.
struct GNUNET_PEERSTORE_StoreContext * handshake_ack_monotime_sc
Store Context for retrieving the monotonic time send with the handshake ack.
static void handshake_ack_monotime_store_cb(void *cls, int success)
Callback called when peerstore store operation for handshake ack monotime value is finished...
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
enum GNUNET_TRANSPORT_ConnectionStatus cs
The connection status of this queue.
struct GNUNET_SCHEDULER_Task * read_task
ID of read task for this connection.
Encrypted continuation of TCP initial handshake.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
Single PEERSTORE record.
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
#define ADDRESS_VALIDITY_PERIOD
How long do we believe our addresses to remain up (before the other peer should revalidate).
size_t pwrite_off
At which offset in the plaintext output buffer should we append more plaintext for encryption next...
#define GNUNET_log(kind,...)
static void nat_address_cb(void *cls, void **app_ctx, int add_remove, enum GNUNET_NAT_AddressClass ac, const struct sockaddr *addr, socklen_t addrlen)
Signature of the callback passed to GNUNET_NAT_register() for a function to call whenever our set of ...
Entry in list of pending tasks.
Definition: scheduler.c:134
struct ProtoQueue * next
Kept in a DLL.
struct ListenTask * lts_head
Head of DLL with ListenTasks.
static void boot_queue(struct Queue *queue)
Add the given queue to our internal data structure.
void GNUNET_PEERSTORE_iterate_cancel(struct GNUNET_PEERSTORE_IterateContext *ic)
Cancel an iterate request Please do not call after the iterate request is done.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY.
static unsigned int extract_port(const char *addr_and_port)
This Method extracts the port part of the BINDTO string.
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX.
handle to a socket
Definition: network.c:52
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
struct GNUNET_ShortHashCode hmac
HMAC for the following encrypted message.
struct ProtoQueue * prev
Kept in a DLL.
static void mq_error(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
static size_t try_handle_plaintext(struct Queue *queue)
Test if we have received a full message in plaintext.
struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_CRYPTO_eddsa_key_create_from_configuration(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create a new private key by reading our peer&#39;s key from the file specified in the configuration...
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c: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:758
static void do_shutdown(void *cls)
Shutdown the UNIX communicator.
const char * GNUNET_e2s(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key value to a string (for printing debug messages).
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
struct GNUNET_ShortHashCode hmac
HMAC for the following encrypted message.
#define DEFAULT_REKEY_INTERVAL
How often do we rekey based on time (at least)
static int init_socket(struct sockaddr *addr, socklen_t in_len)
This method launch network interactions for each address we like to bind to.
static struct ProtoQueue * proto_head
Protoqueues DLL head.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK
Key used to store sender&#39;s monotonic time from handshake ack message.
struct GNUNET_TRANSPORT_QueueHandle * qh
handle for this queue with the ch.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c: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