diff options
author | t3sserakt <t3ss@posteo.de> | 2021-01-25 15:47:10 +0100 |
---|---|---|
committer | t3sserakt <t3ss@posteo.de> | 2021-01-25 15:47:10 +0100 |
commit | ac71165822501c42b00980db2fb7f5e2144f3d20 (patch) | |
tree | cb62e4f7af0f91bdcf50c69bfc0bb901d3059358 /src/transport | |
parent | 438aca2f666f0e0648f389774adee01c131da25c (diff) | |
download | gnunet-ac71165822501c42b00980db2fb7f5e2144f3d20.tar.gz gnunet-ac71165822501c42b00980db2fb7f5e2144f3d20.zip |
- fixed bug in tcp com challenge logic. added test case for bidirectional test.
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/Makefile.am | 18 | ||||
-rw-r--r-- | src/transport/gnunet-communicator-tcp.c | 654 | ||||
-rw-r--r-- | src/transport/gnunet-communicator-udp.c | 1 | ||||
-rw-r--r-- | src/transport/test_communicator_basic.c | 570 |
4 files changed, 705 insertions, 538 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index a2fc3811e..0251b001e 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am | |||
@@ -618,7 +618,8 @@ check_PROGRAMS += \ | |||
618 | test_communicator_basic-udp \ | 618 | test_communicator_basic-udp \ |
619 | test_communicator_rekey-tcp \ | 619 | test_communicator_rekey-tcp \ |
620 | test_communicator_rekey-udp \ | 620 | test_communicator_rekey-udp \ |
621 | test_communicator_backchannel-udp | 621 | test_communicator_backchannel-udp \ |
622 | test_communicator_bidirect-tcp | ||
622 | endif | 623 | endif |
623 | endif | 624 | endif |
624 | 625 | ||
@@ -696,7 +697,8 @@ TESTS += \ | |||
696 | test_communicator_basic-udp \ | 697 | test_communicator_basic-udp \ |
697 | test_communicator_rekey-tcp \ | 698 | test_communicator_rekey-tcp \ |
698 | test_communicator_rekey-udp \ | 699 | test_communicator_rekey-udp \ |
699 | test_communicator_backchannel-udp | 700 | test_communicator_backchannel-udp \ |
701 | test_communicator_bidirect-tcp | ||
700 | endif | 702 | endif |
701 | endif | 703 | endif |
702 | 704 | ||
@@ -857,6 +859,14 @@ test_communicator_backchannel_udp_LDADD = \ | |||
857 | $(top_builddir)/src/testing/libgnunettesting.la \ | 859 | $(top_builddir)/src/testing/libgnunettesting.la \ |
858 | $(top_builddir)/src/util/libgnunetutil.la \ | 860 | $(top_builddir)/src/util/libgnunetutil.la \ |
859 | $(top_builddir)/src/statistics/libgnunetstatistics.la | 861 | $(top_builddir)/src/statistics/libgnunetstatistics.la |
862 | |||
863 | test_communicator_bidirect_tcp_SOURCES = \ | ||
864 | test_communicator_basic.c | ||
865 | test_communicator_bidirect_tcp_LDADD = \ | ||
866 | libgnunettransporttesting2.la \ | ||
867 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
868 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
869 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
860 | endif | 870 | endif |
861 | 871 | ||
862 | test_plugin_unix_SOURCES = \ | 872 | test_plugin_unix_SOURCES = \ |
@@ -1567,4 +1577,6 @@ test_communicator_tcp_rekey_peer2.conf \ | |||
1567 | test_communicator_udp_rekey_peer1.conf \ | 1577 | test_communicator_udp_rekey_peer1.conf \ |
1568 | test_communicator_udp_rekey_peer2.conf \ | 1578 | test_communicator_udp_rekey_peer2.conf \ |
1569 | test_communicator_udp_backchannel_peer1.conf \ | 1579 | test_communicator_udp_backchannel_peer1.conf \ |
1570 | test_communicator_udp_backchannel_peer2.conf | 1580 | test_communicator_udp_backchannel_peer2.conf \ |
1581 | test_communicator_tcp_bidirect_peer1.conf \ | ||
1582 | test_communicator_tcp_bidirect_peer2.conf | ||
diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c index 0c79fc1b4..ed82dba9f 100644 --- a/src/transport/gnunet-communicator-tcp.c +++ b/src/transport/gnunet-communicator-tcp.c | |||
@@ -590,6 +590,11 @@ struct Queue | |||
590 | struct ChallengeNonceP challenge; | 590 | struct ChallengeNonceP challenge; |
591 | 591 | ||
592 | /** | 592 | /** |
593 | * Challenge value received. In case of inbound connection we have to remember the value, because we send the challenge back later after we received the GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_CONFIRMATION_ACK. | ||
594 | */ | ||
595 | struct ChallengeNonceP challenge_received; | ||
596 | |||
597 | /** | ||
593 | * Iteration Context for retrieving the monotonic time send with key for rekeying. | 598 | * Iteration Context for retrieving the monotonic time send with key for rekeying. |
594 | */ | 599 | */ |
595 | struct GNUNET_PEERSTORE_IterateContext *rekey_monotime_get; | 600 | struct GNUNET_PEERSTORE_IterateContext *rekey_monotime_get; |
@@ -834,7 +839,7 @@ int addrs_lens; | |||
834 | * Size of data received without KX challenge played back. | 839 | * Size of data received without KX challenge played back. |
835 | */ | 840 | */ |
836 | // TODO remove? | 841 | // TODO remove? |
837 | // size_t unverified_size; | 842 | size_t unverified_size; |
838 | 843 | ||
839 | /** | 844 | /** |
840 | * Database for peer's HELLOs. | 845 | * Database for peer's HELLOs. |
@@ -1188,23 +1193,6 @@ setup_cipher (const struct GNUNET_HashCode *dh, | |||
1188 | 0)); | 1193 | 0)); |
1189 | } | 1194 | } |
1190 | 1195 | ||
1191 | |||
1192 | /** | ||
1193 | * Setup cipher of @a queue for decryption. | ||
1194 | * | ||
1195 | * @param ephemeral ephemeral key we received from the other peer | ||
1196 | * @param queue[in,out] queue to initialize decryption cipher for | ||
1197 | */ | ||
1198 | static void | ||
1199 | setup_in_cipher (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, | ||
1200 | struct Queue *queue) | ||
1201 | { | ||
1202 | struct GNUNET_HashCode dh; | ||
1203 | |||
1204 | GNUNET_CRYPTO_eddsa_ecdh (my_private_key, ephemeral, &dh); | ||
1205 | setup_cipher (&dh, &my_identity, &queue->in_cipher, &queue->in_hmac); | ||
1206 | } | ||
1207 | |||
1208 | /** | 1196 | /** |
1209 | * Callback called when peerstore store operation for rekey monotime value is finished. | 1197 | * Callback called when peerstore store operation for rekey monotime value is finished. |
1210 | * @param cls Queue context the store operation was executed. | 1198 | * @param cls Queue context the store operation was executed. |
@@ -1279,6 +1267,23 @@ rekey_monotime_cb (void *cls, | |||
1279 | } | 1267 | } |
1280 | 1268 | ||
1281 | /** | 1269 | /** |
1270 | * Setup cipher of @a queue for decryption. | ||
1271 | * | ||
1272 | * @param ephemeral ephemeral key we received from the other peer | ||
1273 | * @param queue[in,out] queue to initialize decryption cipher for | ||
1274 | */ | ||
1275 | static void | ||
1276 | setup_in_cipher (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, | ||
1277 | struct Queue *queue) | ||
1278 | { | ||
1279 | struct GNUNET_HashCode dh; | ||
1280 | |||
1281 | GNUNET_CRYPTO_eddsa_ecdh (my_private_key, ephemeral, &dh); | ||
1282 | setup_cipher (&dh, &my_identity, &queue->in_cipher, &queue->in_hmac); | ||
1283 | } | ||
1284 | |||
1285 | |||
1286 | /** | ||
1282 | * Handle @a rekey message on @a queue. The message was already | 1287 | * Handle @a rekey message on @a queue. The message was already |
1283 | * HMAC'ed, but we should additionally still check the signature. | 1288 | * HMAC'ed, but we should additionally still check the signature. |
1284 | * Then we need to stop the old cipher and start afresh. | 1289 | * Then we need to stop the old cipher and start afresh. |
@@ -1416,6 +1421,220 @@ handshake_ack_monotime_cb (void *cls, | |||
1416 | } | 1421 | } |
1417 | 1422 | ||
1418 | /** | 1423 | /** |
1424 | * Sending challenge with TcpConfirmationAck back to sender of ephemeral key. | ||
1425 | * | ||
1426 | * @param tc The TCPConfirmation originally send. | ||
1427 | * @param queue The queue context. | ||
1428 | */ | ||
1429 | static void | ||
1430 | send_challenge (struct ChallengeNonceP challenge, struct Queue *queue) | ||
1431 | { | ||
1432 | struct TCPConfirmationAck tca; | ||
1433 | struct TcpHandshakeAckSignature thas; | ||
1434 | |||
1435 | GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG, | ||
1436 | "transport", | ||
1437 | "sending challenge\n"); | ||
1438 | |||
1439 | tca.header.type = ntohs ( | ||
1440 | GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_CONFIRMATION_ACK); | ||
1441 | tca.header.size = ntohs (sizeof(tca)); | ||
1442 | tca.challenge = challenge; | ||
1443 | tca.sender = my_identity; | ||
1444 | tca.monotonic_time = | ||
1445 | GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg)); | ||
1446 | thas.purpose.purpose = htonl ( | ||
1447 | GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE_ACK); | ||
1448 | thas.purpose.size = htonl (sizeof(thas)); | ||
1449 | thas.sender = my_identity; | ||
1450 | thas.receiver = queue->target; | ||
1451 | thas.monotonic_time = tca.monotonic_time; | ||
1452 | thas.challenge = tca.challenge; | ||
1453 | GNUNET_CRYPTO_eddsa_sign (my_private_key, | ||
1454 | &thas, | ||
1455 | &tca.sender_sig); | ||
1456 | GNUNET_assert (0 == | ||
1457 | gcry_cipher_encrypt (queue->out_cipher, | ||
1458 | &queue->cwrite_buf[queue->cwrite_off], | ||
1459 | sizeof(tca), | ||
1460 | &tca, | ||
1461 | sizeof(tca))); | ||
1462 | queue->cwrite_off += sizeof(tca); | ||
1463 | GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG, | ||
1464 | "transport", | ||
1465 | "sending challenge done\n"); | ||
1466 | } | ||
1467 | |||
1468 | /** | ||
1469 | * Setup cipher for outgoing data stream based on target and | ||
1470 | * our ephemeral private key. | ||
1471 | * | ||
1472 | * @param queue queue to setup outgoing (encryption) cipher for | ||
1473 | */ | ||
1474 | static void | ||
1475 | setup_out_cipher (struct Queue *queue) | ||
1476 | { | ||
1477 | struct GNUNET_HashCode dh; | ||
1478 | |||
1479 | GNUNET_CRYPTO_ecdh_eddsa (&queue->ephemeral, &queue->target.public_key, &dh); | ||
1480 | /* we don't need the private key anymore, drop it! */ | ||
1481 | memset (&queue->ephemeral, 0, sizeof(queue->ephemeral)); | ||
1482 | setup_cipher (&dh, &queue->target, &queue->out_cipher, &queue->out_hmac); | ||
1483 | queue->rekey_time = GNUNET_TIME_relative_to_absolute (rekey_interval); | ||
1484 | queue->rekey_left_bytes = | ||
1485 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, REKEY_MAX_BYTES); | ||
1486 | } | ||
1487 | |||
1488 | |||
1489 | /** | ||
1490 | * Inject a `struct TCPRekey` message into the queue's plaintext | ||
1491 | * buffer. | ||
1492 | * | ||
1493 | * @param queue queue to perform rekeying on | ||
1494 | */ | ||
1495 | static void | ||
1496 | inject_rekey (struct Queue *queue) | ||
1497 | { | ||
1498 | struct TCPRekey rekey; | ||
1499 | struct TcpRekeySignature thp; | ||
1500 | |||
1501 | GNUNET_assert (0 == queue->pwrite_off); | ||
1502 | memset (&rekey, 0, sizeof(rekey)); | ||
1503 | GNUNET_CRYPTO_ecdhe_key_create (&queue->ephemeral); | ||
1504 | rekey.header.type = ntohs (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY); | ||
1505 | rekey.header.size = ntohs (sizeof(rekey)); | ||
1506 | GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral, &rekey.ephemeral); | ||
1507 | rekey.monotonic_time = | ||
1508 | GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg)); | ||
1509 | thp.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY); | ||
1510 | thp.purpose.size = htonl (sizeof(thp)); | ||
1511 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1512 | "inject_rekey size %u\n", | ||
1513 | thp.purpose.size); | ||
1514 | thp.sender = my_identity; | ||
1515 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1516 | "sender %s\n", | ||
1517 | GNUNET_p2s (&thp.sender.public_key)); | ||
1518 | thp.receiver = queue->target; | ||
1519 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1520 | "receiver %s\n", | ||
1521 | GNUNET_p2s (&thp.receiver.public_key)); | ||
1522 | thp.ephemeral = rekey.ephemeral; | ||
1523 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1524 | "ephemeral %s\n", | ||
1525 | GNUNET_e2s (&thp.ephemeral)); | ||
1526 | thp.monotonic_time = rekey.monotonic_time; | ||
1527 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1528 | "time %s\n", | ||
1529 | GNUNET_STRINGS_absolute_time_to_string ( | ||
1530 | GNUNET_TIME_absolute_ntoh (thp.monotonic_time))); | ||
1531 | GNUNET_CRYPTO_eddsa_sign (my_private_key, | ||
1532 | &thp, | ||
1533 | &rekey.sender_sig); | ||
1534 | calculate_hmac (&queue->out_hmac, &rekey, sizeof(rekey), &rekey.hmac); | ||
1535 | /* Encrypt rekey message with 'old' cipher */ | ||
1536 | GNUNET_assert (0 == | ||
1537 | gcry_cipher_encrypt (queue->out_cipher, | ||
1538 | &queue->cwrite_buf[queue->cwrite_off], | ||
1539 | sizeof(rekey), | ||
1540 | &rekey, | ||
1541 | sizeof(rekey))); | ||
1542 | queue->cwrite_off += sizeof(rekey); | ||
1543 | /* Setup new cipher for successive messages */ | ||
1544 | gcry_cipher_close (queue->out_cipher); | ||
1545 | setup_out_cipher (queue); | ||
1546 | } | ||
1547 | |||
1548 | /** | ||
1549 | * We have been notified that our socket is ready to write. | ||
1550 | * Then reschedule this function to be called again once more is available. | ||
1551 | * | ||
1552 | * @param cls a `struct Queue` | ||
1553 | */ | ||
1554 | static void | ||
1555 | queue_write (void *cls) | ||
1556 | { | ||
1557 | struct Queue *queue = cls; | ||
1558 | ssize_t sent; | ||
1559 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "In queue write\n"); | ||
1560 | queue->write_task = NULL; | ||
1561 | if (0 != queue->cwrite_off) | ||
1562 | { | ||
1563 | sent = GNUNET_NETWORK_socket_send (queue->sock, | ||
1564 | queue->cwrite_buf, | ||
1565 | queue->cwrite_off); | ||
1566 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1567 | "Sent %lu bytes to TCP queue\n", sent); | ||
1568 | if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno)) | ||
1569 | { | ||
1570 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send"); | ||
1571 | queue_destroy (queue); | ||
1572 | return; | ||
1573 | } | ||
1574 | if (sent > 0) | ||
1575 | { | ||
1576 | size_t usent = (size_t) sent; | ||
1577 | queue->cwrite_off -= usent; | ||
1578 | memmove (queue->cwrite_buf, | ||
1579 | &queue->cwrite_buf[usent], | ||
1580 | queue->cwrite_off); | ||
1581 | reschedule_queue_timeout (queue); | ||
1582 | } | ||
1583 | } | ||
1584 | /* can we encrypt more? (always encrypt full messages, needed | ||
1585 | such that #mq_cancel() can work!) */ | ||
1586 | if ((0 < queue->rekey_left_bytes) && | ||
1587 | (queue->pwrite_off > 0) && | ||
1588 | (queue->cwrite_off + queue->pwrite_off <= BUF_SIZE)) | ||
1589 | { | ||
1590 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1591 | "Encrypting %lu bytes\n", queue->pwrite_off); | ||
1592 | GNUNET_assert (0 == | ||
1593 | gcry_cipher_encrypt (queue->out_cipher, | ||
1594 | &queue->cwrite_buf[queue->cwrite_off], | ||
1595 | queue->pwrite_off, | ||
1596 | queue->pwrite_buf, | ||
1597 | queue->pwrite_off)); | ||
1598 | if (queue->rekey_left_bytes > queue->pwrite_off) | ||
1599 | queue->rekey_left_bytes -= queue->pwrite_off; | ||
1600 | else | ||
1601 | queue->rekey_left_bytes = 0; | ||
1602 | queue->cwrite_off += queue->pwrite_off; | ||
1603 | queue->pwrite_off = 0; | ||
1604 | } | ||
1605 | // if ((-1 != unverified_size)&& ((0 == queue->pwrite_off) && | ||
1606 | if (((0 == queue->pwrite_off) && | ||
1607 | ((0 == queue->rekey_left_bytes) || | ||
1608 | (0 == | ||
1609 | GNUNET_TIME_absolute_get_remaining ( | ||
1610 | queue->rekey_time).rel_value_us)))) | ||
1611 | { | ||
1612 | inject_rekey (queue); | ||
1613 | } | ||
1614 | if ((0 == queue->pwrite_off) && (! queue->finishing) && | ||
1615 | (GNUNET_YES == queue->mq_awaits_continue)) | ||
1616 | { | ||
1617 | queue->mq_awaits_continue = GNUNET_NO; | ||
1618 | GNUNET_MQ_impl_send_continue (queue->mq); | ||
1619 | } | ||
1620 | /* did we just finish writing 'finish'? */ | ||
1621 | if ((0 == queue->cwrite_off) && (GNUNET_YES == queue->finishing)) | ||
1622 | { | ||
1623 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1624 | "Finishing queue\n"); | ||
1625 | queue_destroy (queue); | ||
1626 | return; | ||
1627 | } | ||
1628 | /* do we care to write more? */ | ||
1629 | if ((0 < queue->cwrite_off) || (0 < queue->pwrite_off)) | ||
1630 | queue->write_task = | ||
1631 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, | ||
1632 | queue->sock, | ||
1633 | &queue_write, | ||
1634 | queue); | ||
1635 | } | ||
1636 | |||
1637 | /** | ||
1419 | * Test if we have received a full message in plaintext. | 1638 | * Test if we have received a full message in plaintext. |
1420 | * If so, handle it. | 1639 | * If so, handle it. |
1421 | * | 1640 | * |
@@ -1450,16 +1669,16 @@ try_handle_plaintext (struct Queue *queue) | |||
1450 | return 0; /* not even a header */ | 1669 | return 0; /* not even a header */ |
1451 | } | 1670 | } |
1452 | 1671 | ||
1453 | /* if ((-1 != unverified_size) && (unverified_size > INITIAL_CORE_KX_SIZE)) */ | 1672 | if ((-1 != unverified_size) && (unverified_size > INITIAL_CORE_KX_SIZE)) |
1454 | /* { */ | 1673 | { |
1455 | /* GNUNET_log (GNUNET_ERROR_TYPE_ERROR, */ | 1674 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1456 | /* "Already received data of size %lu bigger than KX size %lu!\n", */ | 1675 | "Already received data of size %lu bigger than KX size %lu!\n", |
1457 | /* unverified_size, */ | 1676 | unverified_size, |
1458 | /* INITIAL_CORE_KX_SIZE); */ | 1677 | INITIAL_CORE_KX_SIZE); |
1459 | /* GNUNET_break_op (0); */ | 1678 | GNUNET_break_op (0); |
1460 | /* queue_finish (queue); */ | 1679 | queue_finish (queue); |
1461 | /* return 0; */ | 1680 | return 0; |
1462 | /* } */ | 1681 | } |
1463 | 1682 | ||
1464 | type = ntohs (hdr->type); | 1683 | type = ntohs (hdr->type); |
1465 | switch (type) | 1684 | switch (type) |
@@ -1520,43 +1739,53 @@ try_handle_plaintext (struct Queue *queue) | |||
1520 | queue); | 1739 | queue); |
1521 | 1740 | ||
1522 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1741 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1523 | "Handling plaintext, ack processed!"); | 1742 | "Handling plaintext, ack processed!\n"); |
1524 | 1743 | ||
1525 | // unverified_size = -1; | 1744 | if (GNUNET_TRANSPORT_CS_INBOUND == queue->cs) |
1526 | 1745 | { | |
1527 | /* char *foreign_addr; */ | 1746 | send_challenge (queue->challenge_received, queue); |
1528 | 1747 | queue->write_task = | |
1529 | /* switch (queue->address->sa_family) */ | 1748 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, |
1530 | /* { */ | 1749 | queue->sock, |
1531 | /* case AF_INET: */ | 1750 | &queue_write, |
1532 | /* GNUNET_asprintf (&foreign_addr, */ | 1751 | queue); |
1533 | /* "%s-%s", */ | 1752 | } |
1534 | /* COMMUNICATOR_ADDRESS_PREFIX, */ | 1753 | |
1535 | /* GNUNET_a2s (queue->address, queue->address_len)); */ | 1754 | unverified_size = -1; |
1536 | /* break; */ | 1755 | |
1537 | 1756 | char *foreign_addr; | |
1538 | /* case AF_INET6: */ | 1757 | |
1539 | /* GNUNET_asprintf (&foreign_addr, */ | 1758 | switch (queue->address->sa_family) |
1540 | /* "%s-%s", */ | 1759 | { |
1541 | /* COMMUNICATOR_ADDRESS_PREFIX, */ | 1760 | case AF_INET: |
1542 | /* GNUNET_a2s (queue->address, queue->address_len)); */ | 1761 | GNUNET_asprintf (&foreign_addr, |
1543 | /* break; */ | 1762 | "%s-%s", |
1544 | 1763 | COMMUNICATOR_ADDRESS_PREFIX, | |
1545 | /* default: */ | 1764 | GNUNET_a2s (queue->address, queue->address_len)); |
1546 | /* GNUNET_assert (0); */ | 1765 | break; |
1547 | /* } */ | 1766 | |
1548 | 1767 | case AF_INET6: | |
1549 | /* queue->qh = GNUNET_TRANSPORT_communicator_mq_add (ch, */ | 1768 | GNUNET_asprintf (&foreign_addr, |
1550 | /* &queue->target, */ | 1769 | "%s-%s", |
1551 | /* foreign_addr, */ | 1770 | COMMUNICATOR_ADDRESS_PREFIX, |
1552 | /* 0 /\* no MTU *\/, */ | 1771 | GNUNET_a2s (queue->address, queue->address_len)); |
1553 | /* GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED, */ | 1772 | break; |
1554 | /* 0, /\* Priority *\/ */ | 1773 | |
1555 | /* queue->nt, */ | 1774 | default: |
1556 | /* queue->cs, */ | 1775 | GNUNET_assert (0); |
1557 | /* queue->mq); */ | 1776 | } |
1558 | 1777 | ||
1559 | /* GNUNET_free (foreign_addr); */ | 1778 | queue->qh = GNUNET_TRANSPORT_communicator_mq_add (ch, |
1779 | &queue->target, | ||
1780 | foreign_addr, | ||
1781 | 0 /* no MTU */, | ||
1782 | GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED, | ||
1783 | 0, /* Priority */ | ||
1784 | queue->nt, | ||
1785 | queue->cs, | ||
1786 | queue->mq); | ||
1787 | |||
1788 | GNUNET_free (foreign_addr); | ||
1560 | 1789 | ||
1561 | size = ntohs (hdr->size); | 1790 | size = ntohs (hdr->size); |
1562 | break; | 1791 | break; |
@@ -1633,8 +1862,8 @@ try_handle_plaintext (struct Queue *queue) | |||
1633 | return 0; | 1862 | return 0; |
1634 | } | 1863 | } |
1635 | GNUNET_assert (0 != size); | 1864 | GNUNET_assert (0 != size); |
1636 | /* if (-1 != unverified_size) */ | 1865 | if (-1 != unverified_size) |
1637 | /* unverified_size += size; */ | 1866 | unverified_size += size; |
1638 | return size; | 1867 | return size; |
1639 | } | 1868 | } |
1640 | 1869 | ||
@@ -2043,178 +2272,6 @@ tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len) | |||
2043 | return in; | 2272 | return in; |
2044 | } | 2273 | } |
2045 | 2274 | ||
2046 | |||
2047 | /** | ||
2048 | * Setup cipher for outgoing data stream based on target and | ||
2049 | * our ephemeral private key. | ||
2050 | * | ||
2051 | * @param queue queue to setup outgoing (encryption) cipher for | ||
2052 | */ | ||
2053 | static void | ||
2054 | setup_out_cipher (struct Queue *queue) | ||
2055 | { | ||
2056 | struct GNUNET_HashCode dh; | ||
2057 | |||
2058 | GNUNET_CRYPTO_ecdh_eddsa (&queue->ephemeral, &queue->target.public_key, &dh); | ||
2059 | /* we don't need the private key anymore, drop it! */ | ||
2060 | memset (&queue->ephemeral, 0, sizeof(queue->ephemeral)); | ||
2061 | setup_cipher (&dh, &queue->target, &queue->out_cipher, &queue->out_hmac); | ||
2062 | queue->rekey_time = GNUNET_TIME_relative_to_absolute (rekey_interval); | ||
2063 | queue->rekey_left_bytes = | ||
2064 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, REKEY_MAX_BYTES); | ||
2065 | } | ||
2066 | |||
2067 | |||
2068 | /** | ||
2069 | * Inject a `struct TCPRekey` message into the queue's plaintext | ||
2070 | * buffer. | ||
2071 | * | ||
2072 | * @param queue queue to perform rekeying on | ||
2073 | */ | ||
2074 | static void | ||
2075 | inject_rekey (struct Queue *queue) | ||
2076 | { | ||
2077 | struct TCPRekey rekey; | ||
2078 | struct TcpRekeySignature thp; | ||
2079 | |||
2080 | GNUNET_assert (0 == queue->pwrite_off); | ||
2081 | memset (&rekey, 0, sizeof(rekey)); | ||
2082 | GNUNET_CRYPTO_ecdhe_key_create (&queue->ephemeral); | ||
2083 | rekey.header.type = ntohs (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY); | ||
2084 | rekey.header.size = ntohs (sizeof(rekey)); | ||
2085 | GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral, &rekey.ephemeral); | ||
2086 | rekey.monotonic_time = | ||
2087 | GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg)); | ||
2088 | thp.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY); | ||
2089 | thp.purpose.size = htonl (sizeof(thp)); | ||
2090 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2091 | "inject_rekey size %u\n", | ||
2092 | thp.purpose.size); | ||
2093 | thp.sender = my_identity; | ||
2094 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2095 | "sender %s\n", | ||
2096 | GNUNET_p2s (&thp.sender.public_key)); | ||
2097 | thp.receiver = queue->target; | ||
2098 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2099 | "receiver %s\n", | ||
2100 | GNUNET_p2s (&thp.receiver.public_key)); | ||
2101 | thp.ephemeral = rekey.ephemeral; | ||
2102 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2103 | "ephemeral %s\n", | ||
2104 | GNUNET_e2s (&thp.ephemeral)); | ||
2105 | thp.monotonic_time = rekey.monotonic_time; | ||
2106 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2107 | "time %s\n", | ||
2108 | GNUNET_STRINGS_absolute_time_to_string ( | ||
2109 | GNUNET_TIME_absolute_ntoh (thp.monotonic_time))); | ||
2110 | GNUNET_CRYPTO_eddsa_sign (my_private_key, | ||
2111 | &thp, | ||
2112 | &rekey.sender_sig); | ||
2113 | calculate_hmac (&queue->out_hmac, &rekey, sizeof(rekey), &rekey.hmac); | ||
2114 | /* Encrypt rekey message with 'old' cipher */ | ||
2115 | GNUNET_assert (0 == | ||
2116 | gcry_cipher_encrypt (queue->out_cipher, | ||
2117 | &queue->cwrite_buf[queue->cwrite_off], | ||
2118 | sizeof(rekey), | ||
2119 | &rekey, | ||
2120 | sizeof(rekey))); | ||
2121 | queue->cwrite_off += sizeof(rekey); | ||
2122 | /* Setup new cipher for successive messages */ | ||
2123 | gcry_cipher_close (queue->out_cipher); | ||
2124 | setup_out_cipher (queue); | ||
2125 | } | ||
2126 | |||
2127 | |||
2128 | /** | ||
2129 | * We have been notified that our socket is ready to write. | ||
2130 | * Then reschedule this function to be called again once more is available. | ||
2131 | * | ||
2132 | * @param cls a `struct Queue` | ||
2133 | */ | ||
2134 | static void | ||
2135 | queue_write (void *cls) | ||
2136 | { | ||
2137 | struct Queue *queue = cls; | ||
2138 | ssize_t sent; | ||
2139 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "In queue write\n"); | ||
2140 | queue->write_task = NULL; | ||
2141 | if (0 != queue->cwrite_off) | ||
2142 | { | ||
2143 | sent = GNUNET_NETWORK_socket_send (queue->sock, | ||
2144 | queue->cwrite_buf, | ||
2145 | queue->cwrite_off); | ||
2146 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2147 | "Sent %lu bytes to TCP queue\n", sent); | ||
2148 | if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno)) | ||
2149 | { | ||
2150 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send"); | ||
2151 | queue_destroy (queue); | ||
2152 | return; | ||
2153 | } | ||
2154 | if (sent > 0) | ||
2155 | { | ||
2156 | size_t usent = (size_t) sent; | ||
2157 | queue->cwrite_off -= usent; | ||
2158 | memmove (queue->cwrite_buf, | ||
2159 | &queue->cwrite_buf[usent], | ||
2160 | queue->cwrite_off); | ||
2161 | reschedule_queue_timeout (queue); | ||
2162 | } | ||
2163 | } | ||
2164 | /* can we encrypt more? (always encrypt full messages, needed | ||
2165 | such that #mq_cancel() can work!) */ | ||
2166 | if ((0 < queue->rekey_left_bytes) && | ||
2167 | (queue->pwrite_off > 0) && | ||
2168 | (queue->cwrite_off + queue->pwrite_off <= BUF_SIZE)) | ||
2169 | { | ||
2170 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2171 | "Encrypting %lu bytes\n", queue->pwrite_off); | ||
2172 | GNUNET_assert (0 == | ||
2173 | gcry_cipher_encrypt (queue->out_cipher, | ||
2174 | &queue->cwrite_buf[queue->cwrite_off], | ||
2175 | queue->pwrite_off, | ||
2176 | queue->pwrite_buf, | ||
2177 | queue->pwrite_off)); | ||
2178 | if (queue->rekey_left_bytes > queue->pwrite_off) | ||
2179 | queue->rekey_left_bytes -= queue->pwrite_off; | ||
2180 | else | ||
2181 | queue->rekey_left_bytes = 0; | ||
2182 | queue->cwrite_off += queue->pwrite_off; | ||
2183 | queue->pwrite_off = 0; | ||
2184 | } | ||
2185 | // if ((-1 != unverified_size)&& ((0 == queue->pwrite_off) && | ||
2186 | if (((0 == queue->pwrite_off) && | ||
2187 | ((0 == queue->rekey_left_bytes) || | ||
2188 | (0 == | ||
2189 | GNUNET_TIME_absolute_get_remaining ( | ||
2190 | queue->rekey_time).rel_value_us)))) | ||
2191 | { | ||
2192 | inject_rekey (queue); | ||
2193 | } | ||
2194 | if ((0 == queue->pwrite_off) && (! queue->finishing) && | ||
2195 | (GNUNET_YES == queue->mq_awaits_continue)) | ||
2196 | { | ||
2197 | queue->mq_awaits_continue = GNUNET_NO; | ||
2198 | GNUNET_MQ_impl_send_continue (queue->mq); | ||
2199 | } | ||
2200 | /* did we just finish writing 'finish'? */ | ||
2201 | if ((0 == queue->cwrite_off) && (GNUNET_YES == queue->finishing)) | ||
2202 | { | ||
2203 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2204 | "Finishing queue\n"); | ||
2205 | queue_destroy (queue); | ||
2206 | return; | ||
2207 | } | ||
2208 | /* do we care to write more? */ | ||
2209 | if ((0 < queue->cwrite_off) || (0 < queue->pwrite_off)) | ||
2210 | queue->write_task = | ||
2211 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, | ||
2212 | queue->sock, | ||
2213 | &queue_write, | ||
2214 | queue); | ||
2215 | } | ||
2216 | |||
2217 | |||
2218 | /** | 2275 | /** |
2219 | * Signature of functions implementing the sending functionality of a | 2276 | * Signature of functions implementing the sending functionality of a |
2220 | * message queue. | 2277 | * message queue. |
@@ -2348,39 +2405,39 @@ boot_queue (struct Queue *queue) | |||
2348 | NULL, | 2405 | NULL, |
2349 | &mq_error, | 2406 | &mq_error, |
2350 | queue); | 2407 | queue); |
2351 | { | 2408 | /* { */ |
2352 | char *foreign_addr; | 2409 | /* char *foreign_addr; */ |
2353 | 2410 | ||
2354 | switch (queue->address->sa_family) | 2411 | /* switch (queue->address->sa_family) */ |
2355 | { | 2412 | /* { */ |
2356 | case AF_INET: | 2413 | /* case AF_INET: */ |
2357 | GNUNET_asprintf (&foreign_addr, | 2414 | /* GNUNET_asprintf (&foreign_addr, */ |
2358 | "%s-%s", | 2415 | /* "%s-%s", */ |
2359 | COMMUNICATOR_ADDRESS_PREFIX, | 2416 | /* COMMUNICATOR_ADDRESS_PREFIX, */ |
2360 | GNUNET_a2s (queue->address, queue->address_len)); | 2417 | /* GNUNET_a2s (queue->address, queue->address_len)); */ |
2361 | break; | 2418 | /* break; */ |
2362 | 2419 | ||
2363 | case AF_INET6: | 2420 | /* case AF_INET6: */ |
2364 | GNUNET_asprintf (&foreign_addr, | 2421 | /* GNUNET_asprintf (&foreign_addr, */ |
2365 | "%s-%s", | 2422 | /* "%s-%s", */ |
2366 | COMMUNICATOR_ADDRESS_PREFIX, | 2423 | /* COMMUNICATOR_ADDRESS_PREFIX, */ |
2367 | GNUNET_a2s (queue->address, queue->address_len)); | 2424 | /* GNUNET_a2s (queue->address, queue->address_len)); */ |
2368 | break; | 2425 | /* break; */ |
2369 | 2426 | ||
2370 | default: | 2427 | /* default: */ |
2371 | GNUNET_assert (0); | 2428 | /* GNUNET_assert (0); */ |
2372 | } | 2429 | /* } */ |
2373 | queue->qh = GNUNET_TRANSPORT_communicator_mq_add (ch, | 2430 | /* queue->qh = GNUNET_TRANSPORT_communicator_mq_add (ch, */ |
2374 | &queue->target, | 2431 | /* &queue->target, */ |
2375 | foreign_addr, | 2432 | /* foreign_addr, */ |
2376 | 0 /* no MTU */, | 2433 | /* 0 /\* no MTU *\/, */ |
2377 | GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED, | 2434 | /* GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED, */ |
2378 | 0, /* Priority */ | 2435 | /* 0, /\* Priority *\/ */ |
2379 | queue->nt, | 2436 | /* queue->nt, */ |
2380 | queue->cs, | 2437 | /* queue->cs, */ |
2381 | queue->mq); | 2438 | /* queue->mq); */ |
2382 | GNUNET_free (foreign_addr); | 2439 | /* GNUNET_free (foreign_addr); */ |
2383 | } | 2440 | /* } */ |
2384 | } | 2441 | } |
2385 | 2442 | ||
2386 | 2443 | ||
@@ -2595,48 +2652,6 @@ free_proto_queue (struct ProtoQueue *pq) | |||
2595 | } | 2652 | } |
2596 | 2653 | ||
2597 | /** | 2654 | /** |
2598 | * Sending challenge with TcpConfirmationAck back to sender of ephemeral key. | ||
2599 | * | ||
2600 | * @param tc The TCPConfirmation originally send. | ||
2601 | * @param queue The queue context. | ||
2602 | */ | ||
2603 | static void | ||
2604 | send_challenge (struct ChallengeNonceP challenge, struct Queue *queue) | ||
2605 | { | ||
2606 | struct TCPConfirmationAck tca; | ||
2607 | struct TcpHandshakeAckSignature thas; | ||
2608 | |||
2609 | GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG, | ||
2610 | "transport", | ||
2611 | "sending challenge\n"); | ||
2612 | |||
2613 | tca.header.type = ntohs ( | ||
2614 | GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_CONFIRMATION_ACK); | ||
2615 | tca.header.size = ntohs (sizeof(tca)); | ||
2616 | tca.challenge = challenge; | ||
2617 | tca.sender = my_identity; | ||
2618 | tca.monotonic_time = | ||
2619 | GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg)); | ||
2620 | thas.purpose.purpose = htonl ( | ||
2621 | GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE_ACK); | ||
2622 | thas.purpose.size = htonl (sizeof(thas)); | ||
2623 | thas.sender = my_identity; | ||
2624 | thas.receiver = queue->target; | ||
2625 | thas.monotonic_time = tca.monotonic_time; | ||
2626 | thas.challenge = tca.challenge; | ||
2627 | GNUNET_CRYPTO_eddsa_sign (my_private_key, | ||
2628 | &thas, | ||
2629 | &tca.sender_sig); | ||
2630 | GNUNET_assert (0 == | ||
2631 | gcry_cipher_encrypt (queue->out_cipher, | ||
2632 | &queue->cwrite_buf[queue->cwrite_off], | ||
2633 | sizeof(tca), | ||
2634 | &tca, | ||
2635 | sizeof(tca))); | ||
2636 | queue->cwrite_off += sizeof(tca); | ||
2637 | } | ||
2638 | |||
2639 | /** | ||
2640 | * Read from the socket of the proto queue until we have enough data | 2655 | * Read from the socket of the proto queue until we have enough data |
2641 | * to upgrade to full queue. | 2656 | * to upgrade to full queue. |
2642 | * | 2657 | * |
@@ -2722,7 +2737,8 @@ proto_read_kx (void *cls) | |||
2722 | &queue_write, | 2737 | &queue_write, |
2723 | queue); | 2738 | queue); |
2724 | // TODO To early! Move it somewhere else. | 2739 | // TODO To early! Move it somewhere else. |
2725 | // send_challenge (tc, queue); | 2740 | // send_challenge (tc.challenge, queue); |
2741 | queue->challenge_received = tc.challenge; | ||
2726 | 2742 | ||
2727 | GNUNET_CONTAINER_DLL_remove (proto_head, proto_tail, pq); | 2743 | GNUNET_CONTAINER_DLL_remove (proto_head, proto_tail, pq); |
2728 | GNUNET_free (pq); | 2744 | GNUNET_free (pq); |
@@ -2853,6 +2869,12 @@ queue_read_kx (void *cls) | |||
2853 | return; | 2869 | return; |
2854 | } | 2870 | } |
2855 | send_challenge (tc.challenge, queue); | 2871 | send_challenge (tc.challenge, queue); |
2872 | queue->write_task = | ||
2873 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, | ||
2874 | queue->sock, | ||
2875 | &queue_write, | ||
2876 | queue); | ||
2877 | |||
2856 | /* update queue timeout */ | 2878 | /* update queue timeout */ |
2857 | reschedule_queue_timeout (queue); | 2879 | reschedule_queue_timeout (queue); |
2858 | /* prepare to continue with regular read task immediately */ | 2880 | /* prepare to continue with regular read task immediately */ |
@@ -2866,7 +2888,7 @@ queue_read_kx (void *cls) | |||
2866 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2888 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2867 | "cread_off set to %lu bytes\n", | 2889 | "cread_off set to %lu bytes\n", |
2868 | queue->cread_off); | 2890 | queue->cread_off); |
2869 | if (0 < queue->cread_off) | 2891 | if (0 <= queue->cread_off) |
2870 | queue->read_task = GNUNET_SCHEDULER_add_now (&queue_read, queue); | 2892 | queue->read_task = GNUNET_SCHEDULER_add_now (&queue_read, queue); |
2871 | } | 2893 | } |
2872 | 2894 | ||
diff --git a/src/transport/gnunet-communicator-udp.c b/src/transport/gnunet-communicator-udp.c index 018da8f0e..2e09bc9d2 100644 --- a/src/transport/gnunet-communicator-udp.c +++ b/src/transport/gnunet-communicator-udp.c | |||
@@ -1882,6 +1882,7 @@ consider_ss_ack (struct SharedSecret *ss, int initial) | |||
1882 | 1882 | ||
1883 | // kce_generate (ss, ++ss->sequence_allowed); | 1883 | // kce_generate (ss, ++ss->sequence_allowed); |
1884 | // kce_generate (ss, ++ss->sequence_allowed); | 1884 | // kce_generate (ss, ++ss->sequence_allowed); |
1885 | // TODO This task must be per sender! | ||
1885 | kce_task = GNUNET_SCHEDULER_add_delayed (WORKING_QUEUE_INTERVALL, | 1886 | kce_task = GNUNET_SCHEDULER_add_delayed (WORKING_QUEUE_INTERVALL, |
1886 | kce_generate_cb, | 1887 | kce_generate_cb, |
1887 | ss); | 1888 | ss); |
diff --git a/src/transport/test_communicator_basic.c b/src/transport/test_communicator_basic.c index 0250de474..ffc21e47a 100644 --- a/src/transport/test_communicator_basic.c +++ b/src/transport/test_communicator_basic.c | |||
@@ -42,7 +42,7 @@ | |||
42 | 42 | ||
43 | #define NUM_PEERS 2 | 43 | #define NUM_PEERS 2 |
44 | 44 | ||
45 | static struct GNUNET_SCHEDULER_Task *to_task; | 45 | static struct GNUNET_SCHEDULER_Task *to_task[NUM_PEERS]; |
46 | 46 | ||
47 | static int queue_est = GNUNET_NO; | 47 | static int queue_est = GNUNET_NO; |
48 | 48 | ||
@@ -59,27 +59,29 @@ static struct GNUNET_STATISTICS_Handle *stats[NUM_PEERS]; | |||
59 | 59 | ||
60 | static char *cfg_peers_name[NUM_PEERS]; | 60 | static char *cfg_peers_name[NUM_PEERS]; |
61 | 61 | ||
62 | static int finished[NUM_PEERS]; | ||
63 | |||
62 | static int ret; | 64 | static int ret; |
63 | 65 | ||
64 | static int bidirect = GNUNET_NO; | 66 | static int bidirect = GNUNET_NO; |
65 | 67 | ||
66 | static size_t long_message_size; | 68 | static size_t long_message_size; |
67 | 69 | ||
68 | static struct GNUNET_TIME_Absolute start_short; | 70 | static struct GNUNET_TIME_Absolute start_short[NUM_PEERS]; |
69 | 71 | ||
70 | static struct GNUNET_TIME_Absolute start_long; | 72 | static struct GNUNET_TIME_Absolute start_long[NUM_PEERS]; |
71 | 73 | ||
72 | static struct GNUNET_TIME_Absolute timeout; | 74 | static struct GNUNET_TIME_Absolute timeout[NUM_PEERS]; |
73 | 75 | ||
74 | static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *my_tc; | 76 | // static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *my_tc; |
75 | 77 | ||
76 | static char *communicator_name; | 78 | static char *communicator_name; |
77 | 79 | ||
78 | static char *test_name; | 80 | static char *test_name; |
79 | 81 | ||
80 | static struct GNUNET_STATISTICS_GetHandle *box_stats; | 82 | static struct GNUNET_STATISTICS_GetHandle *box_stats[NUM_PEERS]; |
81 | 83 | ||
82 | static struct GNUNET_STATISTICS_GetHandle *rekey_stats; | 84 | static struct GNUNET_STATISTICS_GetHandle *rekey_stats[NUM_PEERS]; |
83 | 85 | ||
84 | #define TEST_SECTION "test-setup" | 86 | #define TEST_SECTION "test-setup" |
85 | 87 | ||
@@ -97,7 +99,7 @@ static struct GNUNET_STATISTICS_GetHandle *rekey_stats; | |||
97 | 99 | ||
98 | #define PEER_B 1 | 100 | #define PEER_B 1 |
99 | 101 | ||
100 | static unsigned int iterations_left = TOTAL_ITERATIONS; | 102 | static unsigned int iterations_left[NUM_PEERS]; |
101 | 103 | ||
102 | #define TIMEOUT_MULTIPLIER 1 | 104 | #define TIMEOUT_MULTIPLIER 1 |
103 | 105 | ||
@@ -118,11 +120,11 @@ enum TestPhase | |||
118 | TP_SIZE_CHECK | 120 | TP_SIZE_CHECK |
119 | }; | 121 | }; |
120 | 122 | ||
121 | static unsigned int phase_short; | 123 | static unsigned int phase_short[NUM_PEERS]; |
122 | 124 | ||
123 | static unsigned int phase_long; | 125 | static unsigned int phase_long[NUM_PEERS]; |
124 | 126 | ||
125 | static unsigned int phase_size; | 127 | static unsigned int phase_size[NUM_PEERS]; |
126 | 128 | ||
127 | static long long unsigned int allowed_packet_loss_short; | 129 | static long long unsigned int allowed_packet_loss_short; |
128 | 130 | ||
@@ -140,26 +142,23 @@ static struct GNUNET_TIME_Relative delay_short; | |||
140 | 142 | ||
141 | static struct GNUNET_TIME_Relative delay_long; | 143 | static struct GNUNET_TIME_Relative delay_long; |
142 | 144 | ||
143 | static size_t num_sent_short = 0; | 145 | static size_t num_sent_short[NUM_PEERS]; |
144 | |||
145 | static size_t num_sent_long = 0; | ||
146 | |||
147 | static size_t num_sent_size = 0; | ||
148 | 146 | ||
149 | static uint32_t ack = 0; | 147 | static size_t num_sent_long[NUM_PEERS]; |
150 | 148 | ||
151 | static enum TestPhase phase; | 149 | static size_t num_sent_size[NUM_PEERS]; |
152 | 150 | ||
153 | static size_t num_received_short = 0; | 151 | static uint32_t ack[NUM_PEERS]; |
154 | 152 | ||
155 | static size_t num_received_long = 0; | 153 | static enum TestPhase phase[NUM_PEERS]; |
156 | 154 | ||
157 | static size_t num_received_size = 0; | 155 | static size_t num_received_short[NUM_PEERS]; |
158 | 156 | ||
159 | static uint64_t avg_latency = 0; | 157 | static size_t num_received_long[NUM_PEERS]; |
160 | 158 | ||
161 | static struct GNUNET_TIME_Relative duration; | 159 | static size_t num_received_size[NUM_PEERS]; |
162 | 160 | ||
161 | static uint64_t avg_latency[NUM_PEERS]; | ||
163 | 162 | ||
164 | static void | 163 | static void |
165 | communicator_available_cb ( | 164 | communicator_available_cb ( |
@@ -284,43 +283,87 @@ make_payload (size_t payload_size) | |||
284 | return payload; | 283 | return payload; |
285 | } | 284 | } |
286 | 285 | ||
286 | static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle * | ||
287 | get_tc_h (unsigned int peer_nr) | ||
288 | { | ||
289 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
290 | "Got peer %u\n", | ||
291 | peer_nr); | ||
292 | |||
293 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
294 | "Handle %p peer 0\n", | ||
295 | tc_hs[0]); | ||
296 | |||
297 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
298 | "Handle %p peer 1\n", | ||
299 | tc_hs[1]); | ||
300 | |||
301 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
302 | "Handle %p get\n", | ||
303 | tc_hs[peer_nr]); | ||
304 | |||
305 | return tc_hs[peer_nr]; | ||
306 | } | ||
307 | |||
308 | |||
309 | static unsigned int | ||
310 | get_peer_nr_from_tc (struct | ||
311 | GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h) | ||
312 | { | ||
313 | if (tc_h == get_tc_h (0)) | ||
314 | return PEER_A; | ||
315 | else | ||
316 | return PEER_B; | ||
317 | } | ||
318 | |||
319 | static unsigned int | ||
320 | get_peer_nr (void *cls, unsigned int get_the_other_one) | ||
321 | { | ||
322 | if (0 == strcmp ((char*) cls, cfg_peers_name[0])) | ||
323 | return get_the_other_one ? PEER_B : PEER_A; | ||
324 | else | ||
325 | return get_the_other_one ? PEER_A : PEER_B; | ||
326 | } | ||
287 | 327 | ||
288 | static void | 328 | static void |
289 | latency_timeout (void *cls) | 329 | latency_timeout (void *cls) |
290 | { | 330 | { |
291 | 331 | ||
332 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; | ||
333 | unsigned int peer_nr; | ||
292 | size_t num_sent = 0; | 334 | size_t num_sent = 0; |
293 | size_t num_received = 0; | 335 | size_t num_received = 0; |
294 | 336 | ||
295 | to_task = NULL; | 337 | peer_nr = get_peer_nr_from_tc (tc_h); |
296 | if (GNUNET_TIME_absolute_get_remaining (timeout).rel_value_us > 0) | 338 | to_task[peer_nr] = NULL; |
339 | if (GNUNET_TIME_absolute_get_remaining (timeout[peer_nr]).rel_value_us > 0) | ||
297 | { | 340 | { |
298 | to_task = GNUNET_SCHEDULER_add_at (timeout, | 341 | to_task[peer_nr] = GNUNET_SCHEDULER_add_at (timeout[peer_nr], |
299 | &latency_timeout, | 342 | &latency_timeout, |
300 | NULL); | 343 | cls); |
301 | return; | 344 | return; |
302 | } | 345 | } |
303 | switch (phase) | 346 | switch (phase[peer_nr]) |
304 | { | 347 | { |
305 | case TP_INIT: | 348 | case TP_INIT: |
306 | GNUNET_assert (0); | 349 | GNUNET_assert (0); |
307 | break; | 350 | break; |
308 | case TP_BURST_SHORT: | 351 | case TP_BURST_SHORT: |
309 | num_sent = num_sent_short; | 352 | num_sent = num_sent_short[peer_nr]; |
310 | num_received = num_received_short; | 353 | num_received = num_received_short[peer_nr]; |
311 | break; | 354 | break; |
312 | case TP_BURST_LONG: | 355 | case TP_BURST_LONG: |
313 | num_sent = num_sent_long; | 356 | num_sent = num_sent_long[peer_nr]; |
314 | num_received = num_received_long; | 357 | num_received = num_received_long[peer_nr]; |
315 | break; | 358 | break; |
316 | case TP_SIZE_CHECK: | 359 | case TP_SIZE_CHECK: |
317 | num_sent = num_sent_size; | 360 | num_sent = num_sent_size[peer_nr]; |
318 | num_received = num_received_size; | 361 | num_received = num_received_size[peer_nr]; |
319 | break; | 362 | break; |
320 | } | 363 | } |
321 | LOG (GNUNET_ERROR_TYPE_ERROR, | 364 | LOG (GNUNET_ERROR_TYPE_ERROR, |
322 | "Latency too high. Test failed. (Phase: %d. Sent: %lu, Received: %lu)\n", | 365 | "Latency too high. Test failed. (Phase: %d. Sent: %lu, Received: %lu)\n", |
323 | phase, num_sent, num_received); | 366 | phase[peer_nr], num_sent, num_received); |
324 | ret = 2; | 367 | ret = 2; |
325 | GNUNET_SCHEDULER_shutdown (); | 368 | GNUNET_SCHEDULER_shutdown (); |
326 | } | 369 | } |
@@ -328,31 +371,36 @@ latency_timeout (void *cls) | |||
328 | static void | 371 | static void |
329 | size_test (void *cls) | 372 | size_test (void *cls) |
330 | { | 373 | { |
374 | unsigned int peer_nr; | ||
331 | char *payload; | 375 | char *payload; |
332 | size_t max_size = 64000; | 376 | size_t max_size = 64000; |
377 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; | ||
333 | 378 | ||
379 | peer_nr = get_peer_nr_from_tc (tc_h); | ||
334 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 380 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
335 | "size_test_cb %u\n", | 381 | "size_test_cb %u\n", |
336 | (unsigned int) num_sent_size); | 382 | (unsigned int) num_sent_size[peer_nr]); |
337 | GNUNET_assert (TP_SIZE_CHECK == phase); | 383 | GNUNET_assert (TP_SIZE_CHECK == phase[peer_nr]); |
338 | if (LONG_MESSAGE_SIZE != long_message_size) | 384 | if (LONG_MESSAGE_SIZE != long_message_size) |
339 | max_size = long_message_size; | 385 | max_size = long_message_size; |
340 | if (ack + 10 > max_size) | 386 | if (ack[peer_nr] + 10 > max_size) |
341 | return; /* Leave some room for our protocol, so not 2^16 exactly */ | 387 | return; /* Leave some room for our protocol, so not 2^16 exactly */ |
342 | ack += 10; | 388 | ack[peer_nr] += 10; |
343 | payload = make_payload (ack); | 389 | payload = make_payload (ack[peer_nr]); |
344 | num_sent_size++; | 390 | num_sent_size[peer_nr]++; |
345 | GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, | 391 | GNUNET_TRANSPORT_TESTING_transport_communicator_send (tc_h, |
346 | (ack < max_size) | 392 | (ack[peer_nr] < |
393 | max_size) | ||
347 | ? &size_test | 394 | ? &size_test |
348 | : NULL, | 395 | : NULL, |
349 | NULL, | 396 | cls, |
350 | payload, | 397 | payload, |
351 | ack); | 398 | ack[peer_nr]); |
352 | GNUNET_free (payload); | 399 | GNUNET_free (payload); |
353 | timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply ( | 400 | timeout[peer_nr] = GNUNET_TIME_relative_to_absolute ( |
354 | GNUNET_TIME_UNIT_SECONDS, | 401 | GNUNET_TIME_relative_multiply ( |
355 | TIMEOUT_MULTIPLIER)); | 402 | GNUNET_TIME_UNIT_SECONDS, |
403 | TIMEOUT_MULTIPLIER)); | ||
356 | } | 404 | } |
357 | 405 | ||
358 | 406 | ||
@@ -362,24 +410,28 @@ long_test (void *cls); | |||
362 | static void | 410 | static void |
363 | long_test_cb (void *cls) | 411 | long_test_cb (void *cls) |
364 | { | 412 | { |
413 | unsigned int peer_nr; | ||
365 | char *payload; | 414 | char *payload; |
415 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; | ||
416 | |||
417 | peer_nr = get_peer_nr_from_tc (tc_h); | ||
366 | 418 | ||
367 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 419 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
368 | "long_test_cb %u/%u\n", | 420 | "long_test_cb %u/%u\n", |
369 | (unsigned int) num_sent_long, | 421 | (unsigned int) num_sent_long[peer_nr], |
370 | (unsigned int) num_received_long); | 422 | (unsigned int) num_received_long[peer_nr]); |
371 | payload = make_payload (long_message_size); | 423 | payload = make_payload (long_message_size); |
372 | num_sent_long++; | 424 | num_sent_long[peer_nr]++; |
373 | GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, | 425 | GNUNET_TRANSPORT_TESTING_transport_communicator_send (tc_h, |
374 | (burst_packets_long == | 426 | (burst_packets_long == |
375 | num_sent_long) | 427 | num_sent_long[peer_nr]) |
376 | ? NULL | 428 | ? NULL |
377 | : &long_test, | 429 | : &long_test, |
378 | NULL, | 430 | cls, |
379 | payload, | 431 | payload, |
380 | long_message_size); | 432 | long_message_size); |
381 | GNUNET_free (payload); | 433 | GNUNET_free (payload); |
382 | timeout = GNUNET_TIME_relative_to_absolute ( | 434 | timeout[peer_nr] = GNUNET_TIME_relative_to_absolute ( |
383 | GNUNET_TIME_relative_multiply ( | 435 | GNUNET_TIME_relative_multiply ( |
384 | GNUNET_TIME_UNIT_SECONDS, | 436 | GNUNET_TIME_UNIT_SECONDS, |
385 | TIMEOUT_MULTIPLIER)); | 437 | TIMEOUT_MULTIPLIER)); |
@@ -391,7 +443,7 @@ long_test (void *cls) | |||
391 | { | 443 | { |
392 | GNUNET_SCHEDULER_add_delayed (delay_long, | 444 | GNUNET_SCHEDULER_add_delayed (delay_long, |
393 | &long_test_cb, | 445 | &long_test_cb, |
394 | NULL); | 446 | cls); |
395 | } | 447 | } |
396 | 448 | ||
397 | 449 | ||
@@ -402,26 +454,33 @@ short_test (void *cls); | |||
402 | static void | 454 | static void |
403 | short_test_cb (void *cls) | 455 | short_test_cb (void *cls) |
404 | { | 456 | { |
457 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; | ||
458 | unsigned int peer_nr; | ||
405 | char *payload; | 459 | char *payload; |
406 | 460 | ||
461 | peer_nr = get_peer_nr_from_tc (tc_h); | ||
462 | |||
407 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 463 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
408 | "short_test_cb %u/%u\n", | 464 | "short_test_cb %u/%u for peer %u and handle %p\n", |
409 | (unsigned int) num_sent_short, | 465 | (unsigned int) num_sent_short[peer_nr], |
410 | (unsigned int) num_received_short); | 466 | (unsigned int) num_received_short[peer_nr], |
467 | peer_nr, | ||
468 | tc_h); | ||
411 | payload = make_payload (SHORT_MESSAGE_SIZE); | 469 | payload = make_payload (SHORT_MESSAGE_SIZE); |
412 | num_sent_short++; | 470 | num_sent_short[peer_nr]++; |
413 | GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, | 471 | GNUNET_TRANSPORT_TESTING_transport_communicator_send (tc_h, |
414 | (burst_packets_short == | 472 | (burst_packets_short == |
415 | num_sent_short) | 473 | num_sent_short[peer_nr]) |
416 | ? NULL | 474 | ? NULL |
417 | : &short_test, | 475 | : &short_test, |
418 | NULL, | 476 | cls, |
419 | payload, | 477 | payload, |
420 | SHORT_MESSAGE_SIZE); | 478 | SHORT_MESSAGE_SIZE); |
421 | GNUNET_free (payload); | 479 | GNUNET_free (payload); |
422 | timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply ( | 480 | timeout[peer_nr] = GNUNET_TIME_relative_to_absolute ( |
423 | GNUNET_TIME_UNIT_SECONDS, | 481 | GNUNET_TIME_relative_multiply ( |
424 | TIMEOUT_MULTIPLIER)); | 482 | GNUNET_TIME_UNIT_SECONDS, |
483 | TIMEOUT_MULTIPLIER)); | ||
425 | } | 484 | } |
426 | 485 | ||
427 | 486 | ||
@@ -430,7 +489,7 @@ short_test (void *cls) | |||
430 | { | 489 | { |
431 | GNUNET_SCHEDULER_add_delayed (delay_short, | 490 | GNUNET_SCHEDULER_add_delayed (delay_short, |
432 | &short_test_cb, | 491 | &short_test_cb, |
433 | NULL); | 492 | cls); |
434 | } | 493 | } |
435 | 494 | ||
436 | 495 | ||
@@ -462,9 +521,14 @@ short_test (void *cls) | |||
462 | static void | 521 | static void |
463 | process_statistics_box_done (void *cls, int success) | 522 | process_statistics_box_done (void *cls, int success) |
464 | { | 523 | { |
465 | if (NULL != box_stats) | 524 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; |
466 | box_stats = NULL; | 525 | unsigned int peer_nr; |
467 | if (NULL == rekey_stats) | 526 | |
527 | peer_nr = get_peer_nr_from_tc (tc_h); | ||
528 | |||
529 | if (NULL != box_stats[peer_nr]) | ||
530 | box_stats[peer_nr] = NULL; | ||
531 | if (NULL == rekey_stats[peer_nr]) | ||
468 | { | 532 | { |
469 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 533 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
470 | "Finished\n"); | 534 | "Finished\n"); |
@@ -476,9 +540,14 @@ process_statistics_box_done (void *cls, int success) | |||
476 | static void | 540 | static void |
477 | process_statistics_rekey_done (void *cls, int success) | 541 | process_statistics_rekey_done (void *cls, int success) |
478 | { | 542 | { |
479 | if (NULL != rekey_stats) | 543 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; |
480 | rekey_stats = NULL; | 544 | unsigned int peer_nr; |
481 | if (NULL == box_stats) | 545 | |
546 | peer_nr = get_peer_nr_from_tc (tc_h); | ||
547 | |||
548 | if (NULL != rekey_stats[peer_nr]) | ||
549 | rekey_stats[peer_nr] = NULL; | ||
550 | if (NULL == box_stats[peer_nr]) | ||
482 | { | 551 | { |
483 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 552 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
484 | "Finished\n"); | 553 | "Finished\n"); |
@@ -533,24 +602,37 @@ process_statistics (void *cls, | |||
533 | } | 602 | } |
534 | 603 | ||
535 | static void | 604 | static void |
536 | choose_phase () | 605 | choose_phase (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h) |
537 | { | 606 | { |
538 | if (GNUNET_YES == phase_short) | 607 | unsigned int peer_nr; |
608 | |||
609 | peer_nr = get_peer_nr_from_tc (tc_h); | ||
610 | |||
611 | if (GNUNET_YES == phase_short[peer_nr]) | ||
539 | { | 612 | { |
540 | phase = TP_BURST_SHORT; | 613 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
541 | start_short = GNUNET_TIME_absolute_get (); | 614 | "Choose phase short with peer %u and Handle %p\n", |
542 | short_test (NULL); | 615 | peer_nr, |
616 | tc_h); | ||
617 | phase[peer_nr] = TP_BURST_SHORT; | ||
618 | start_short[peer_nr] = GNUNET_TIME_absolute_get (); | ||
619 | short_test (tc_h); | ||
543 | } | 620 | } |
544 | else if (GNUNET_YES == phase_long) | 621 | else if (GNUNET_YES == phase_long[peer_nr]) |
545 | { | 622 | { |
546 | phase = TP_BURST_LONG; | 623 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
547 | start_long = GNUNET_TIME_absolute_get (); | 624 | "Choose phase long with peer %u\n", |
548 | long_test (NULL); | 625 | peer_nr); |
626 | phase[peer_nr] = TP_BURST_LONG; | ||
627 | start_long[peer_nr] = GNUNET_TIME_absolute_get (); | ||
628 | long_test (tc_h); | ||
549 | } | 629 | } |
550 | else if (GNUNET_YES == phase_size) | 630 | else if (GNUNET_YES == phase_size[peer_nr]) |
551 | { | 631 | { |
552 | phase = TP_SIZE_CHECK; | 632 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
553 | size_test (NULL); | 633 | "Choose phase size\n"); |
634 | phase[peer_nr] = TP_SIZE_CHECK; | ||
635 | size_test (tc_h); | ||
554 | } | 636 | } |
555 | else | 637 | else |
556 | { | 638 | { |
@@ -560,28 +642,33 @@ choose_phase () | |||
560 | "backchannel", | 642 | "backchannel", |
561 | test_name))) ) | 643 | test_name))) ) |
562 | { | 644 | { |
563 | if (NULL != box_stats) | 645 | if (NULL != box_stats[peer_nr]) |
564 | GNUNET_STATISTICS_get_cancel (box_stats); | 646 | GNUNET_STATISTICS_get_cancel (box_stats[peer_nr]); |
565 | box_stats = GNUNET_STATISTICS_get (stats[1], | 647 | box_stats[peer_nr] = GNUNET_STATISTICS_get (stats[1], |
566 | "C-UDP", | 648 | "C-UDP", |
567 | "# messages decrypted with BOX", | 649 | "# messages decrypted with BOX", |
568 | process_statistics_box_done, | 650 | process_statistics_box_done, |
569 | &process_statistics, | 651 | &process_statistics, |
570 | NULL); | 652 | tc_h); |
571 | if (NULL != rekey_stats) | 653 | if (NULL != rekey_stats[peer_nr]) |
572 | GNUNET_STATISTICS_get_cancel (rekey_stats); | 654 | GNUNET_STATISTICS_get_cancel (rekey_stats[peer_nr]); |
573 | rekey_stats = GNUNET_STATISTICS_get (stats[0], | 655 | rekey_stats[peer_nr] = GNUNET_STATISTICS_get (stats[0], |
574 | "C-UDP", | 656 | "C-UDP", |
575 | "# rekeying successful", | 657 | "# rekeying successful", |
576 | process_statistics_rekey_done, | 658 | process_statistics_rekey_done, |
577 | &process_statistics, | 659 | &process_statistics, |
578 | NULL); | 660 | tc_h); |
579 | } | 661 | } |
580 | else | 662 | else |
581 | { | 663 | { |
582 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 664 | if (((PEER_A == peer_nr) && finished[PEER_B]) || ((PEER_B == peer_nr) && |
583 | "Finished\n"); | 665 | finished[PEER_A])) |
584 | GNUNET_SCHEDULER_shutdown (); | 666 | { |
667 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
668 | "Finished\n"); | ||
669 | GNUNET_SCHEDULER_shutdown (); | ||
670 | } | ||
671 | finished[peer_nr] = GNUNET_YES; | ||
585 | } | 672 | } |
586 | } | 673 | } |
587 | } | 674 | } |
@@ -604,37 +691,54 @@ add_queue_cb (void *cls, | |||
604 | tc_queue, | 691 | tc_queue, |
605 | size_t mtu) | 692 | size_t mtu) |
606 | { | 693 | { |
607 | if (TP_INIT != phase) | 694 | |
608 | return; | 695 | unsigned int peer_nr; |
609 | if (0 != strcmp ((char*) cls, cfg_peers_name[0])) | 696 | |
697 | peer_nr = get_peer_nr (cls, GNUNET_NO); | ||
698 | |||
699 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
700 | "Handle %p add %u %u\n", | ||
701 | tc_h, | ||
702 | peer_nr, | ||
703 | get_peer_nr_from_tc (tc_h)); | ||
704 | |||
705 | if ((GNUNET_NO == bidirect)&&(0 != strcmp ((char*) cls, cfg_peers_name[0]))) | ||
706 | { | ||
707 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
708 | "Queue available at receiving peer\n"); | ||
610 | return; // TODO? | 709 | return; // TODO? |
710 | } | ||
711 | else if (TP_INIT != phase[peer_nr]) | ||
712 | return; | ||
611 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 713 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
612 | "Queue established, starting test...\n"); | 714 | "Queue established, starting test...\n"); |
613 | // start_short = GNUNET_TIME_absolute_get (); | 715 | // start_short = GNUNET_TIME_absolute_get (); |
614 | my_tc = tc_h; | 716 | // my_tc = tc_h; |
615 | if (0 != mtu) /* Message header overhead */ | 717 | if (0 != mtu) /* Message header overhead */ |
616 | long_message_size = mtu - sizeof(struct GNUNET_TRANSPORT_SendMessageTo) | 718 | long_message_size = mtu - sizeof(struct GNUNET_TRANSPORT_SendMessageTo) |
617 | - sizeof(struct GNUNET_MessageHeader); | 719 | - sizeof(struct GNUNET_MessageHeader); |
618 | else | 720 | else |
619 | long_message_size = LONG_MESSAGE_SIZE; | 721 | long_message_size = LONG_MESSAGE_SIZE; |
620 | // phase = TP_BURST_SHORT; | 722 | // phase = TP_BURST_SHORT; |
621 | timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply ( | 723 | timeout[peer_nr] = GNUNET_TIME_relative_to_absolute ( |
622 | GNUNET_TIME_UNIT_SECONDS, | 724 | GNUNET_TIME_relative_multiply ( |
623 | TIMEOUT_MULTIPLIER)); | 725 | GNUNET_TIME_UNIT_SECONDS, |
624 | GNUNET_assert (NULL == to_task); | 726 | TIMEOUT_MULTIPLIER)); |
625 | to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply ( | 727 | GNUNET_assert (NULL == to_task[peer_nr]); |
626 | GNUNET_TIME_UNIT_SECONDS, | 728 | to_task[peer_nr] = GNUNET_SCHEDULER_add_delayed ( |
627 | TIMEOUT_MULTIPLIER), | 729 | GNUNET_TIME_relative_multiply ( |
628 | &latency_timeout, | 730 | GNUNET_TIME_UNIT_SECONDS, |
629 | NULL); | 731 | TIMEOUT_MULTIPLIER), |
732 | &latency_timeout, | ||
733 | tc_h); | ||
630 | // prepare_test (NULL); | 734 | // prepare_test (NULL); |
631 | // short_test (NULL); | 735 | // short_test (NULL); |
632 | choose_phase (); | 736 | choose_phase (tc_h); |
633 | } | 737 | } |
634 | 738 | ||
635 | 739 | ||
636 | static void | 740 | static void |
637 | update_avg_latency (const char*payload) | 741 | update_avg_latency (const char *payload, unsigned int peer_nr) |
638 | { | 742 | { |
639 | struct GNUNET_TIME_AbsoluteNBO *ts_n; | 743 | struct GNUNET_TIME_AbsoluteNBO *ts_n; |
640 | struct GNUNET_TIME_Absolute ts; | 744 | struct GNUNET_TIME_Absolute ts; |
@@ -645,31 +749,33 @@ update_avg_latency (const char*payload) | |||
645 | ts = GNUNET_TIME_absolute_ntoh (*ts_n); | 749 | ts = GNUNET_TIME_absolute_ntoh (*ts_n); |
646 | latency = GNUNET_TIME_absolute_get_duration (ts); | 750 | latency = GNUNET_TIME_absolute_get_duration (ts); |
647 | 751 | ||
648 | switch (phase) | 752 | switch (phase[peer_nr]) |
649 | { | 753 | { |
650 | case TP_INIT: | 754 | case TP_INIT: |
651 | GNUNET_assert (0); | 755 | GNUNET_assert (0); |
652 | break; | 756 | break; |
653 | case TP_BURST_SHORT: | 757 | case TP_BURST_SHORT: |
654 | num_received = num_received_short; | 758 | num_received = num_received_short[peer_nr]; |
655 | break; | 759 | break; |
656 | case TP_BURST_LONG: | 760 | case TP_BURST_LONG: |
657 | num_received = num_received_long; | 761 | num_received = num_received_long[peer_nr]; |
658 | break; | 762 | break; |
659 | case TP_SIZE_CHECK: | 763 | case TP_SIZE_CHECK: |
660 | num_received = num_received_size; | 764 | num_received = num_received_size[peer_nr]; |
661 | break; | 765 | break; |
662 | } | 766 | } |
663 | if (1 >= num_received) | 767 | if (1 >= num_received) |
664 | avg_latency = latency.rel_value_us; | 768 | avg_latency[peer_nr] = latency.rel_value_us; |
665 | else | 769 | else |
666 | avg_latency = ((avg_latency * (num_received - 1)) + latency.rel_value_us) | 770 | avg_latency[peer_nr] = ((avg_latency[peer_nr] * (num_received - 1)) |
667 | / num_received; | 771 | + latency.rel_value_us) |
772 | / num_received; | ||
668 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 773 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
669 | "Latency of received packet: %s with avg latency %lu\n", | 774 | "Latency of received packet by peer %u: %s with avg latency %lu\n", |
775 | peer_nr, | ||
670 | GNUNET_STRINGS_relative_time_to_string (latency, | 776 | GNUNET_STRINGS_relative_time_to_string (latency, |
671 | GNUNET_YES), | 777 | GNUNET_YES), |
672 | avg_latency); | 778 | avg_latency[peer_nr]); |
673 | } | 779 | } |
674 | 780 | ||
675 | 781 | ||
@@ -679,25 +785,31 @@ static void | |||
679 | load_phase_config () | 785 | load_phase_config () |
680 | { | 786 | { |
681 | 787 | ||
682 | phase_short = GNUNET_CONFIGURATION_get_value_yesno (cfg_peers[0], | 788 | phase_short[0] = GNUNET_CONFIGURATION_get_value_yesno (cfg_peers[0], |
683 | TEST_SECTION, | 789 | TEST_SECTION, |
684 | "PHASE_SHORT"); | 790 | "PHASE_SHORT"); |
685 | if (GNUNET_SYSERR == phase_short) | 791 | if (GNUNET_SYSERR == phase_short[0]) |
686 | phase_short = GNUNET_YES; | 792 | phase_short[0] = GNUNET_YES; |
687 | 793 | ||
688 | phase_long = GNUNET_CONFIGURATION_get_value_yesno (cfg_peers[0], | 794 | phase_short[1] = phase_short[0]; |
689 | TEST_SECTION, | ||
690 | "PHASE_LONG"); | ||
691 | 795 | ||
692 | if (GNUNET_SYSERR == phase_long) | 796 | phase_long[0] = GNUNET_CONFIGURATION_get_value_yesno (cfg_peers[0], |
693 | phase_long = GNUNET_YES; | 797 | TEST_SECTION, |
798 | "PHASE_LONG"); | ||
694 | 799 | ||
695 | phase_size = GNUNET_CONFIGURATION_get_value_yesno (cfg_peers[0], | 800 | if (GNUNET_SYSERR == phase_long[0]) |
696 | TEST_SECTION, | 801 | phase_long[0] = GNUNET_YES; |
697 | "PHASE_SIZE"); | ||
698 | 802 | ||
699 | if (GNUNET_SYSERR == phase_size) | 803 | phase_long[1] = phase_long[0]; |
700 | phase_size = GNUNET_YES; | 804 | |
805 | phase_size[0] = GNUNET_CONFIGURATION_get_value_yesno (cfg_peers[0], | ||
806 | TEST_SECTION, | ||
807 | "PHASE_SIZE"); | ||
808 | |||
809 | if (GNUNET_SYSERR == phase_size[0]) | ||
810 | phase_size[0] = GNUNET_YES; | ||
811 | |||
812 | phase_size[1] = phase_size[0]; | ||
701 | } | 813 | } |
702 | 814 | ||
703 | /** | 815 | /** |
@@ -716,18 +828,24 @@ incoming_message_cb ( | |||
716 | const char *payload, | 828 | const char *payload, |
717 | size_t payload_len) | 829 | size_t payload_len) |
718 | { | 830 | { |
719 | if (0 != strcmp ((char*) cls, | 831 | unsigned int peer_nr; |
720 | cfg_peers_name[NUM_PEERS - 1])) | 832 | static struct GNUNET_TIME_Relative duration; |
833 | |||
834 | peer_nr = get_peer_nr (cls, GNUNET_YES); | ||
835 | |||
836 | if ((GNUNET_NO == bidirect)&&(0 != strcmp ((char*) cls, | ||
837 | cfg_peers_name[NUM_PEERS - 1]))) | ||
721 | { | 838 | { |
722 | LOG (GNUNET_ERROR_TYPE_WARNING, | 839 | LOG (GNUNET_ERROR_TYPE_WARNING, |
723 | "unexpected receiver...\n"); | 840 | "unexpected receiver...\n"); |
724 | return; | 841 | return; |
725 | } | 842 | } |
726 | /* Reset timeout */ | 843 | /* Reset timeout */ |
727 | timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply ( | 844 | timeout[peer_nr] = GNUNET_TIME_relative_to_absolute ( |
728 | GNUNET_TIME_UNIT_SECONDS, | 845 | GNUNET_TIME_relative_multiply ( |
729 | TIMEOUT_MULTIPLIER)); | 846 | GNUNET_TIME_UNIT_SECONDS, |
730 | switch (phase) | 847 | TIMEOUT_MULTIPLIER)); |
848 | switch (phase[peer_nr]) | ||
731 | { | 849 | { |
732 | case TP_INIT: | 850 | case TP_INIT: |
733 | GNUNET_break (0); | 851 | GNUNET_break (0); |
@@ -735,34 +853,37 @@ incoming_message_cb ( | |||
735 | case TP_BURST_SHORT: | 853 | case TP_BURST_SHORT: |
736 | { | 854 | { |
737 | GNUNET_assert (SHORT_MESSAGE_SIZE == payload_len); | 855 | GNUNET_assert (SHORT_MESSAGE_SIZE == payload_len); |
738 | num_received_short++; | 856 | num_received_short[peer_nr]++; |
739 | duration = GNUNET_TIME_absolute_get_duration (start_short); | 857 | duration = GNUNET_TIME_absolute_get_duration (start_short[peer_nr]); |
740 | update_avg_latency (payload); | 858 | update_avg_latency (payload, peer_nr); |
741 | if ((num_sent_short == burst_packets_short) && (num_received_short > | 859 | if ((num_sent_short[peer_nr] == burst_packets_short) && |
742 | burst_packets_short / 100 | 860 | (num_received_short[peer_nr] > |
743 | * | 861 | burst_packets_short |
744 | allowed_packet_loss_short) ) | 862 | / 100 |
863 | * | ||
864 | allowed_packet_loss_short) ) | ||
745 | { | 865 | { |
746 | LOG (GNUNET_ERROR_TYPE_MESSAGE, | 866 | LOG (GNUNET_ERROR_TYPE_MESSAGE, |
747 | "Short size packet test done.\n"); | 867 | "Short size packet test for peer %u done.\n", |
868 | peer_nr); | ||
748 | char *goodput = GNUNET_STRINGS_byte_size_fancy ( | 869 | char *goodput = GNUNET_STRINGS_byte_size_fancy ( |
749 | (SHORT_MESSAGE_SIZE * num_received_short * 1000 * 1000) | 870 | (SHORT_MESSAGE_SIZE * num_received_short[peer_nr] * 1000 * 1000) |
750 | / duration.rel_value_us); | 871 | / duration.rel_value_us); |
751 | LOG (GNUNET_ERROR_TYPE_MESSAGE, | 872 | LOG (GNUNET_ERROR_TYPE_MESSAGE, |
752 | "%lu/%lu packets in %llu us (%s/s) -- avg latency: %llu us\n", | 873 | "%lu/%lu packets in %llu us (%s/s) -- avg latency: %llu us\n", |
753 | (unsigned long) num_received_short, | 874 | (unsigned long) num_received_short[peer_nr], |
754 | (unsigned long) num_sent_short, | 875 | (unsigned long) num_sent_short[peer_nr], |
755 | (unsigned long long) duration.rel_value_us, | 876 | (unsigned long long) duration.rel_value_us, |
756 | goodput, | 877 | goodput, |
757 | (unsigned long long) avg_latency); | 878 | (unsigned long long) avg_latency[peer_nr]); |
758 | GNUNET_free (goodput); | 879 | GNUNET_free (goodput); |
759 | // start_long = GNUNET_TIME_absolute_get (); | 880 | // start_long = GNUNET_TIME_absolute_get (); |
760 | // phase = TP_BURST_LONG; | 881 | // phase = TP_BURST_LONG; |
761 | // num_sent_short = 0; | 882 | // num_sent_short = 0; |
762 | avg_latency = 0; | 883 | avg_latency[peer_nr] = 0; |
763 | // num_received = 0; | 884 | // num_received = 0; |
764 | phase_short = GNUNET_NO; | 885 | phase_short[peer_nr] = GNUNET_NO; |
765 | choose_phase (); | 886 | choose_phase (get_tc_h (peer_nr)); |
766 | // long_test (NULL); | 887 | // long_test (NULL); |
767 | } | 888 | } |
768 | break; | 889 | break; |
@@ -775,37 +896,40 @@ incoming_message_cb ( | |||
775 | "Ignoring packet with wrong length\n"); | 896 | "Ignoring packet with wrong length\n"); |
776 | return; // Ignore | 897 | return; // Ignore |
777 | } | 898 | } |
778 | num_received_long++; | 899 | num_received_long[peer_nr]++; |
779 | duration = GNUNET_TIME_absolute_get_duration (start_long); | 900 | duration = GNUNET_TIME_absolute_get_duration (start_long[peer_nr]); |
780 | update_avg_latency (payload); | 901 | update_avg_latency (payload, peer_nr); |
781 | if ((num_sent_long == burst_packets_long) && (num_received_long > | 902 | if ((num_sent_long[peer_nr] == burst_packets_long) && |
782 | burst_packets_long | 903 | (num_received_long[peer_nr] > |
783 | / 100 | 904 | burst_packets_long |
784 | * allowed_packet_loss_short) ) | 905 | / 100 |
906 | * | ||
907 | allowed_packet_loss_short) ) | ||
785 | { | 908 | { |
786 | LOG (GNUNET_ERROR_TYPE_MESSAGE, | 909 | LOG (GNUNET_ERROR_TYPE_MESSAGE, |
787 | "Long size packet test done.\n"); | 910 | "Long size packet test for peer %u done.\n", |
911 | peer_nr); | ||
788 | char *goodput = GNUNET_STRINGS_byte_size_fancy ( | 912 | char *goodput = GNUNET_STRINGS_byte_size_fancy ( |
789 | (long_message_size * num_received_long * 1000 * 1000) | 913 | (long_message_size * num_received_long[peer_nr] * 1000 * 1000) |
790 | / duration. | 914 | / duration. |
791 | rel_value_us); | 915 | rel_value_us); |
792 | 916 | ||
793 | LOG (GNUNET_ERROR_TYPE_MESSAGE, | 917 | LOG (GNUNET_ERROR_TYPE_MESSAGE, |
794 | "%lu/%lu packets in %llu us (%s/s) -- avg latency: %llu us\n", | 918 | "%lu/%lu packets in %llu us (%s/s) -- avg latency: %llu us\n", |
795 | (unsigned long) num_received_long, | 919 | (unsigned long) num_received_long[peer_nr], |
796 | (unsigned long) num_sent_long, | 920 | (unsigned long) num_sent_long[peer_nr], |
797 | (unsigned long long) duration.rel_value_us, | 921 | (unsigned long long) duration.rel_value_us, |
798 | goodput, | 922 | goodput, |
799 | (unsigned long long) avg_latency); | 923 | (unsigned long long) avg_latency[peer_nr]); |
800 | GNUNET_free (goodput); | 924 | GNUNET_free (goodput); |
801 | ack = 0; | 925 | ack[peer_nr] = 0; |
802 | // phase = TP_SIZE_CHECK; | 926 | // phase = TP_SIZE_CHECK; |
803 | // num_received = 0; | 927 | // num_received = 0; |
804 | // num_sent_long = 0; | 928 | // num_sent_long = 0; |
805 | avg_latency = 0; | 929 | avg_latency[peer_nr] = 0; |
806 | // size_test (NULL); | 930 | // size_test (NULL); |
807 | phase_long = GNUNET_NO; | 931 | phase_long[peer_nr] = GNUNET_NO; |
808 | choose_phase (); | 932 | choose_phase (get_tc_h (peer_nr)); |
809 | } | 933 | } |
810 | break; | 934 | break; |
811 | } | 935 | } |
@@ -813,39 +937,44 @@ incoming_message_cb ( | |||
813 | { | 937 | { |
814 | size_t max_size = 64000; | 938 | size_t max_size = 64000; |
815 | 939 | ||
816 | GNUNET_assert (TP_SIZE_CHECK == phase); | 940 | GNUNET_assert (TP_SIZE_CHECK == phase[peer_nr]); |
817 | if (LONG_MESSAGE_SIZE != long_message_size) | 941 | if (LONG_MESSAGE_SIZE != long_message_size) |
818 | max_size = long_message_size; | 942 | max_size = long_message_size; |
819 | num_received_size++; | 943 | num_received_size[peer_nr]++; |
820 | update_avg_latency (payload); | 944 | update_avg_latency (payload, peer_nr); |
821 | if (num_received_size >= (max_size) / 10) | 945 | if ((GNUNET_YES == phase_size[peer_nr]) && (num_received_size[peer_nr] >= |
946 | (max_size) / 10) ) | ||
822 | { | 947 | { |
823 | LOG (GNUNET_ERROR_TYPE_MESSAGE, | 948 | LOG (GNUNET_ERROR_TYPE_MESSAGE, |
824 | "Size packet test done.\n"); | 949 | "Size packet test for peer %u done.\n", |
950 | peer_nr); | ||
825 | LOG (GNUNET_ERROR_TYPE_MESSAGE, | 951 | LOG (GNUNET_ERROR_TYPE_MESSAGE, |
826 | "%lu/%lu packets -- avg latency: %llu us\n", | 952 | "%lu/%lu packets -- avg latency: %llu us\n", |
827 | (unsigned long) num_received_size, | 953 | (unsigned long) num_received_size[peer_nr], |
828 | (unsigned long) num_sent_size, | 954 | (unsigned long) num_sent_size[peer_nr], |
829 | (unsigned long long) avg_latency); | 955 | (unsigned long long) avg_latency[peer_nr]); |
830 | num_received_size = 0; | 956 | iterations_left[peer_nr]--; |
831 | num_sent_size = 0; | 957 | phase_size[peer_nr] = GNUNET_NO; |
832 | avg_latency = 0; | 958 | if (0 != iterations_left[peer_nr]) |
833 | iterations_left--; | ||
834 | if (0 != iterations_left) | ||
835 | { | 959 | { |
836 | // start_short = GNUNET_TIME_absolute_get (); | 960 | // start_short = GNUNET_TIME_absolute_get (); |
837 | // phase = TP_BURST_SHORT; | 961 | // phase = TP_BURST_SHORT; |
838 | num_sent_short = 0; | 962 | num_received_size[peer_nr] = 0; |
839 | num_sent_long = 0; | 963 | num_sent_size[peer_nr] = 0; |
840 | num_received_short = 0; | 964 | avg_latency[peer_nr] = 0; |
841 | num_received_long = 0; | 965 | num_sent_short[peer_nr] = 0; |
966 | num_sent_long[peer_nr] = 0; | ||
967 | num_received_short[peer_nr] = 0; | ||
968 | num_received_long[peer_nr] = 0; | ||
842 | // short_test (NULL); | 969 | // short_test (NULL); |
843 | load_phase_config (); | 970 | if (((PEER_A == peer_nr) && finished[PEER_B]) || ((PEER_B == |
844 | choose_phase (); | 971 | peer_nr) && |
845 | break; | 972 | finished[PEER_A])) |
973 | { | ||
974 | load_phase_config (); | ||
975 | } | ||
846 | } | 976 | } |
847 | phase_size = GNUNET_NO; | 977 | choose_phase (get_tc_h (peer_nr)); |
848 | choose_phase (); | ||
849 | } | 978 | } |
850 | break; | 979 | break; |
851 | } | 980 | } |
@@ -859,23 +988,23 @@ do_shutdown (void *cls) | |||
859 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 988 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
860 | "shuting down test.\n"); | 989 | "shuting down test.\n"); |
861 | 990 | ||
862 | if (NULL != box_stats) | ||
863 | { | ||
864 | GNUNET_STATISTICS_get_cancel (box_stats); | ||
865 | box_stats = NULL; | ||
866 | } | ||
867 | if (NULL != rekey_stats) | ||
868 | { | ||
869 | GNUNET_STATISTICS_get_cancel (rekey_stats); | ||
870 | rekey_stats = NULL; | ||
871 | } | ||
872 | if (NULL != to_task) | ||
873 | { | ||
874 | GNUNET_SCHEDULER_cancel (to_task); | ||
875 | to_task = NULL; | ||
876 | } | ||
877 | for (unsigned int i = 0; i < NUM_PEERS; i++) | 991 | for (unsigned int i = 0; i < NUM_PEERS; i++) |
878 | { | 992 | { |
993 | if (NULL != box_stats[i]) | ||
994 | { | ||
995 | GNUNET_STATISTICS_get_cancel (box_stats[i]); | ||
996 | box_stats[i] = NULL; | ||
997 | } | ||
998 | if (NULL != rekey_stats[i]) | ||
999 | { | ||
1000 | GNUNET_STATISTICS_get_cancel (rekey_stats[i]); | ||
1001 | rekey_stats[i] = NULL; | ||
1002 | } | ||
1003 | if (NULL != to_task[i]) | ||
1004 | { | ||
1005 | GNUNET_SCHEDULER_cancel (to_task[i]); | ||
1006 | to_task[i] = NULL; | ||
1007 | } | ||
879 | GNUNET_TRANSPORT_TESTING_transport_communicator_service_stop (tc_hs[i]); | 1008 | GNUNET_TRANSPORT_TESTING_transport_communicator_service_stop (tc_hs[i]); |
880 | GNUNET_STATISTICS_destroy (stats[i], GNUNET_NO); | 1009 | GNUNET_STATISTICS_destroy (stats[i], GNUNET_NO); |
881 | } | 1010 | } |
@@ -935,7 +1064,10 @@ main (int argc, | |||
935 | char *test_mode; | 1064 | char *test_mode; |
936 | char *cfg_peer; | 1065 | char *cfg_peer; |
937 | 1066 | ||
938 | phase = TP_INIT; | 1067 | iterations_left[0] = TOTAL_ITERATIONS; |
1068 | iterations_left[1] = TOTAL_ITERATIONS; | ||
1069 | phase[0] = TP_INIT; | ||
1070 | phase[1] = TP_INIT; | ||
939 | ret = 1; | 1071 | ret = 1; |
940 | test_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); | 1072 | test_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); |
941 | communicator_name = strchr (test_name, '-'); | 1073 | communicator_name = strchr (test_name, '-'); |