aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-10-07 13:07:30 +0200
committert3sserakt <t3ss@posteo.de>2021-10-07 13:07:30 +0200
commitd7fa0579995790840199ec86cb4d518f9d372fcd (patch)
treeb41accedea6cd0fb78d75afee61911b94a1099fb /src/transport
parent658bceab7ba3aab5121e8874d8508264d3f63ce3 (diff)
downloadgnunet-d7fa0579995790840199ec86cb4d518f9d372fcd.tar.gz
gnunet-d7fa0579995790840199ec86cb4d518f9d372fcd.zip
- add generic topology configuration by file
- cmd simple send using file configuration from file - added cmd to check the logs for backchannel encapsulation - added cmd which notifies the master loop of local loop being prepared to finish - added logging to helper.c - moved code from connecting peers cmd into global functions - added parameters given to the connecting peers cmd - added assertion when notifying the transport service about a new queue, if the communicator has no intial capacity - added optional valgrind cmd to test script - added flag für queues with unlimited length - added check for queues with higher priority - added attribute queue_capacity to struct Queue - bug fixing worker task for kce generation and transport notification about available queue in udp communicator - change value for unlimited queue length from 0 to UINT16_MAX in tcp communicator and service - added loop to stop the test system for the globally known peers in stop testsystem cmd - refactored endless growing array to handle further messages from the local loops, and added logic to handle the local test prepare msg - added utility methods in testing.c - added forwarding of all tests prepared msg in gnunet-cmds-helper.c - added cmd to end loop without shutdown - added without shutdown cmd to simple send testcase - added backchannel check, without shutdown and prepared cmd to udp backchannel testcase.
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/Makefile.am2
-rw-r--r--src/transport/gnunet-communicator-tcp.c20
-rw-r--r--src/transport/gnunet-communicator-udp.c101
-rw-r--r--src/transport/gnunet-service-tng.c207
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send.c7
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send_v2.c3
-rw-r--r--src/transport/test_transport_plugin_cmd_udp_backchannel.c37
-rwxr-xr-xsrc/transport/test_transport_udp_backchannel.sh2
-rw-r--r--src/transport/transport-testing-cmds.h72
-rw-r--r--src/transport/transport_api2_communication.c9
-rw-r--r--src/transport/transport_api_cmd_backchannel_check.c628
-rw-r--r--src/transport/transport_api_cmd_connecting_peers.c14
-rw-r--r--src/transport/transport_api_cmd_connecting_peers_v3.c251
-rw-r--r--src/transport/transport_api_cmd_send_simple_v3.c194
14 files changed, 1229 insertions, 318 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index 32075ee16..73544a8d5 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -163,12 +163,14 @@ libgnunettransporttesting2_la_SOURCES = \
163 transport_api_cmd_connecting_peers.c \ 163 transport_api_cmd_connecting_peers.c \
164 transport_api_cmd_connecting_peers_v2.c \ 164 transport_api_cmd_connecting_peers_v2.c \
165 transport_api_cmd_connecting_peers_v3.c \ 165 transport_api_cmd_connecting_peers_v3.c \
166 transport_api_cmd_backchannel_check.c \
166 transport_api_cmd_start_peer.c \ 167 transport_api_cmd_start_peer.c \
167 transport_api_cmd_start_peer_v2.c \ 168 transport_api_cmd_start_peer_v2.c \
168 transport_api_cmd_start_peer_v3.c \ 169 transport_api_cmd_start_peer_v3.c \
169 transport_api_cmd_stop_peer.c \ 170 transport_api_cmd_stop_peer.c \
170 transport_api_cmd_send_simple.c \ 171 transport_api_cmd_send_simple.c \
171 transport_api_cmd_send_simple_v2.c \ 172 transport_api_cmd_send_simple_v2.c \
173 transport_api_cmd_send_simple_v3.c \
172 transport-testing2.c transport-testing2.h \ 174 transport-testing2.c transport-testing2.h \
173 transport-testing-cmds.h \ 175 transport-testing-cmds.h \
174 transport-testing-filenames2.c \ 176 transport-testing-filenames2.c \
diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c
index d8bf7c1a8..025326de7 100644
--- a/src/transport/gnunet-communicator-tcp.c
+++ b/src/transport/gnunet-communicator-tcp.c
@@ -1119,6 +1119,10 @@ pass_plaintext_to_core (struct Queue *queue,
1119 const struct GNUNET_MessageHeader *hdr = plaintext; 1119 const struct GNUNET_MessageHeader *hdr = plaintext;
1120 int ret; 1120 int ret;
1121 1121
1122 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1123 "pass message from %s to core\n",
1124 GNUNET_i2s (&queue->target));
1125
1122 if (ntohs (hdr->size) != plaintext_len) 1126 if (ntohs (hdr->size) != plaintext_len)
1123 { 1127 {
1124 /* NOTE: If we ever allow multiple CORE messages in one 1128 /* NOTE: If we ever allow multiple CORE messages in one
@@ -1132,6 +1136,8 @@ pass_plaintext_to_core (struct Queue *queue,
1132 ADDRESS_VALIDITY_PERIOD, 1136 ADDRESS_VALIDITY_PERIOD,
1133 &core_read_finished_cb, 1137 &core_read_finished_cb,
1134 queue); 1138 queue);
1139 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1140 "passed to core\n");
1135 if (GNUNET_OK == ret) 1141 if (GNUNET_OK == ret)
1136 queue->backpressure++; 1142 queue->backpressure++;
1137 GNUNET_break (GNUNET_NO != ret); /* backpressure not working!? */ 1143 GNUNET_break (GNUNET_NO != ret); /* backpressure not working!? */
@@ -1795,7 +1801,7 @@ try_handle_plaintext (struct Queue *queue)
1795 queue->qh = GNUNET_TRANSPORT_communicator_mq_add (ch, 1801 queue->qh = GNUNET_TRANSPORT_communicator_mq_add (ch,
1796 &queue->target, 1802 &queue->target,
1797 foreign_addr, 1803 foreign_addr,
1798 UINT32_MAX, /* no MTU */ 1804 UINT16_MAX, /* no MTU */
1799 GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED, 1805 GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED,
1800 0, /* Priority */ 1806 0, /* Priority */
1801 queue->nt, 1807 queue->nt,
@@ -2444,7 +2450,7 @@ boot_queue (struct Queue *queue)
2444 * Generate and transmit our ephemeral key and the signature for 2450 * Generate and transmit our ephemeral key and the signature for
2445 * the initial KX with the other peer. Must be called first, before 2451 * the initial KX with the other peer. Must be called first, before
2446 * any other bytes are ever written to the output buffer. Note that 2452 * any other bytes are ever written to the output buffer. Note that
2447 * our cipher must already be initialized when calling this function. 2453 * our cipher must already be initialized when calling thi function.
2448 * Helper function for #start_initial_kx_out(). 2454 * Helper function for #start_initial_kx_out().
2449 * 2455 *
2450 * @param queue queue to do KX for 2456 * @param queue queue to do KX for
@@ -2725,6 +2731,9 @@ proto_read_kx (void *cls)
2725 queue->listen_sock = pq->listen_sock; 2731 queue->listen_sock = pq->listen_sock;
2726 queue->sock = pq->sock; 2732 queue->sock = pq->sock;
2727 2733
2734 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2735 "created queue with target %s\n",
2736 GNUNET_i2s (&queue->target));
2728 2737
2729 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2738 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2730 "start kx proto\n"); 2739 "start kx proto\n");
@@ -2984,6 +2993,9 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
2984 queue->sock = sock; 2993 queue->sock = sock;
2985 queue->cs = GNUNET_TRANSPORT_CS_OUTBOUND; 2994 queue->cs = GNUNET_TRANSPORT_CS_OUTBOUND;
2986 boot_queue (queue); 2995 boot_queue (queue);
2996 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2997 "booted queue with target %s\n",
2998 GNUNET_i2s (&queue->target));
2987 // queue->mq_awaits_continue = GNUNET_YES; 2999 // queue->mq_awaits_continue = GNUNET_YES;
2988 queue->read_task = 3000 queue->read_task =
2989 GNUNET_SCHEDULER_add_read_net (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 3001 GNUNET_SCHEDULER_add_read_net (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
@@ -3646,6 +3658,10 @@ main (int argc, char *const *argv)
3646 }; 3658 };
3647 int ret; 3659 int ret;
3648 3660
3661 GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG,
3662 "transport",
3663 "Starting tcp communicator\n");
3664
3649 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 3665 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
3650 return 2; 3666 return 2;
3651 3667
diff --git a/src/transport/gnunet-communicator-udp.c b/src/transport/gnunet-communicator-udp.c
index ef7b1d6c0..659fd7d26 100644
--- a/src/transport/gnunet-communicator-udp.c
+++ b/src/transport/gnunet-communicator-udp.c
@@ -1494,7 +1494,27 @@ add_acks (struct SharedSecret *ss, int acks_to_add)
1494 1494
1495 GNUNET_assert (NULL != ss); 1495 GNUNET_assert (NULL != ss);
1496 GNUNET_assert (NULL != receiver); 1496 GNUNET_assert (NULL != receiver);
1497 GNUNET_assert (NULL != receiver->d_qh); 1497
1498 if (NULL == receiver->d_qh)
1499 {
1500 receiver->d_qh =
1501 GNUNET_TRANSPORT_communicator_mq_add (ch,
1502 &receiver->target,
1503 receiver->foreign_addr,
1504 receiver->d_mtu,
1505 acks_to_add,
1506 1, /* Priority */
1507 receiver->nt,
1508 GNUNET_TRANSPORT_CS_OUTBOUND,
1509 receiver->d_mq);
1510 }
1511 else
1512 {
1513 GNUNET_TRANSPORT_communicator_mq_update (ch,
1514 receiver->d_qh,
1515 acks_to_add,
1516 1);
1517 }
1498 1518
1499 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1519 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1500 "Tell transport we have %u more acks!\n", 1520 "Tell transport we have %u more acks!\n",
@@ -1502,10 +1522,7 @@ add_acks (struct SharedSecret *ss, int acks_to_add)
1502 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1522 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1503 "%u kce for rekeying.\n", 1523 "%u kce for rekeying.\n",
1504 receiver->number_rekeying_kce); 1524 receiver->number_rekeying_kce);
1505 GNUNET_TRANSPORT_communicator_mq_update (ch, 1525
1506 receiver->d_qh,
1507 acks_to_add,
1508 1);
1509 // Until here for alternativ 1 1526 // Until here for alternativ 1
1510 1527
1511 /* move ss to head to avoid discarding it anytime soon! */ 1528 /* move ss to head to avoid discarding it anytime soon! */
@@ -1744,7 +1761,7 @@ kce_generate_cb (void *cls)
1744 if (((GNUNET_NO == ss->sender->rekeying) && (ss->sender->acks_available < 1761 if (((GNUNET_NO == ss->sender->rekeying) && (ss->sender->acks_available <
1745 KCN_TARGET) ) || 1762 KCN_TARGET) ) ||
1746 ((ss->sender->ss_rekey == ss) && (GNUNET_YES == ss->sender->rekeying) && 1763 ((ss->sender->ss_rekey == ss) && (GNUNET_YES == ss->sender->rekeying) &&
1747 (ss->sender->acks_available < 128))) 1764 (ss->sender->acks_available < KCN_TARGET)))
1748 { 1765 {
1749 1766
1750 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1767 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1754,20 +1771,24 @@ kce_generate_cb (void *cls)
1754 for (int i = 0; i < GENERATE_AT_ONCE; i++) 1771 for (int i = 0; i < GENERATE_AT_ONCE; i++)
1755 kce_generate (ss, ++ss->sequence_allowed); 1772 kce_generate (ss, ++ss->sequence_allowed);
1756 1773
1757 ss->sender->kce_task = GNUNET_SCHEDULER_add_delayed ( 1774 if (KCN_TARGET > ss->sender->acks_available)
1758 WORKING_QUEUE_INTERVALL, 1775 {
1759 kce_generate_cb, 1776 ss->sender->kce_task = GNUNET_SCHEDULER_add_delayed (
1760 ss); 1777 WORKING_QUEUE_INTERVALL,
1761 } 1778 kce_generate_cb,
1762 else 1779 ss);
1763 { 1780 }
1764 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1781 else
1765 "We have enough keys.\n"); 1782 {
1766 ss_finished = ss; 1783 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1767 ss->sender->kce_task_finished = GNUNET_YES; 1784 "We have enough keys.\n");
1785 ss_finished = ss;
1786 ss->sender->kce_task_finished = GNUNET_YES;
1787 }
1768 } 1788 }
1769 1789
1770 1790
1791
1771} 1792}
1772 1793
1773 1794
@@ -1850,7 +1871,17 @@ consider_ss_ack (struct SharedSecret *ss, int initial)
1850 kce_generate (ss, ++ss->sequence_allowed); 1871 kce_generate (ss, ++ss->sequence_allowed);
1851 }*/ 1872 }*/
1852 1873
1853 if (((NULL != kce_task) && kce_task_finished) || (GNUNET_NO == initial)) 1874 if (NULL != kce_task)
1875 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1876 "kce_task is not NULL\n");
1877 if (kce_task_finished)
1878 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1879 "kce_task_finished: GNUNET_YES\n");
1880 if (initial)
1881 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1882 "initial: GNUNET_YES\n");
1883
1884 if ( kce_task_finished || (GNUNET_NO == initial))
1854 { 1885 {
1855 struct UDPAck ack; 1886 struct UDPAck ack;
1856 struct SharedSecret *ss_tell; 1887 struct SharedSecret *ss_tell;
@@ -1877,8 +1908,7 @@ consider_ss_ack (struct SharedSecret *ss, int initial)
1877 if (GNUNET_NO != initial) 1908 if (GNUNET_NO != initial)
1878 { 1909 {
1879 destroy_all_secrets (ss, GNUNET_YES); 1910 destroy_all_secrets (ss, GNUNET_YES);
1880 kce_task = NULL; 1911 ss->sender->kce_task_finished = GNUNET_NO;
1881 kce_task_finished = GNUNET_NO;
1882 } 1912 }
1883 } 1913 }
1884 else if ((NULL == kce_task) && ((KCN_THRESHOLD > 1914 else if ((NULL == kce_task) && ((KCN_THRESHOLD >
@@ -2678,8 +2708,10 @@ mq_send_kx (struct GNUNET_MQ_Handle *mq,
2678 receiver->address_len)) 2708 receiver->address_len))
2679 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send"); 2709 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send");
2680 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2710 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2681 "Sending KX to %s\n", GNUNET_a2s (receiver->address, 2711 "Sending KX with payload size %u to %s\n",
2682 receiver->address_len)); 2712 msize,
2713 GNUNET_a2s (receiver->address,
2714 receiver->address_len));
2683 GNUNET_MQ_impl_send_continue (mq); 2715 GNUNET_MQ_impl_send_continue (mq);
2684} 2716}
2685 2717
@@ -2940,7 +2972,8 @@ mq_send_d (struct GNUNET_MQ_Handle *mq,
2940 receiver->address_len)) 2972 receiver->address_len))
2941 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send"); 2973 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send");
2942 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2974 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2943 "Sending UDPBox %u acks left\n", 2975 "Sending UDPBox with payload size %u, %u acks left\n",
2976 msize,
2944 receiver->acks_available); 2977 receiver->acks_available);
2945 GNUNET_MQ_impl_send_continue (mq); 2978 GNUNET_MQ_impl_send_continue (mq);
2946 receiver->acks_available--; 2979 receiver->acks_available--;
@@ -3135,17 +3168,6 @@ setup_receiver_mq (struct ReceiverAddress *receiver)
3135 receiver->nt, 3168 receiver->nt,
3136 GNUNET_TRANSPORT_CS_OUTBOUND, 3169 GNUNET_TRANSPORT_CS_OUTBOUND,
3137 receiver->kx_mq); 3170 receiver->kx_mq);
3138 receiver->d_qh =
3139 GNUNET_TRANSPORT_communicator_mq_add (ch,
3140 &receiver->target,
3141 receiver->foreign_addr,
3142 receiver->d_mtu,
3143 0, /* Initialize with 0 acks */
3144 1, /* Priority */
3145 receiver->nt,
3146 GNUNET_TRANSPORT_CS_OUTBOUND,
3147 receiver->d_mq);
3148
3149} 3171}
3150 3172
3151 3173
@@ -3755,9 +3777,11 @@ run (void *cls,
3755 GNUNET_free (bindto); 3777 GNUNET_free (bindto);
3756 in = (struct sockaddr *) &in_sto; 3778 in = (struct sockaddr *) &in_sto;
3757 in_len = sto_len; 3779 in_len = sto_len;
3758 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3780 GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG,
3759 "Bound to `%s'\n", 3781 "transport",
3760 GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len)); 3782 "Bound to `%s'\n",
3783 GNUNET_a2s ((const struct sockaddr *) &in_sto,
3784 sto_len));
3761 switch (in->sa_family) 3785 switch (in->sa_family)
3762 { 3786 {
3763 case AF_INET: 3787 case AF_INET:
@@ -3853,6 +3877,9 @@ main (int argc, char *const *argv)
3853 }; 3877 };
3854 int ret; 3878 int ret;
3855 3879
3880 GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG,
3881 "transport",
3882 "Starting udp communicator\n");
3856 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 3883 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
3857 return 2; 3884 return 2;
3858 3885
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c
index a7e2a8c04..a90bef3b5 100644
--- a/src/transport/gnunet-service-tng.c
+++ b/src/transport/gnunet-service-tng.c
@@ -1736,6 +1736,11 @@ struct Queue
1736 const char *address; 1736 const char *address;
1737 1737
1738 /** 1738 /**
1739 * Is this queue of unlimited length.
1740 */
1741 unsigned int unlimited_length;
1742
1743 /**
1739 * Task scheduled for the time when this queue can (likely) transmit the 1744 * Task scheduled for the time when this queue can (likely) transmit the
1740 * next message. 1745 * next message.
1741 */ 1746 */
@@ -1787,6 +1792,11 @@ struct Queue
1787 unsigned int queue_length; 1792 unsigned int queue_length;
1788 1793
1789 /** 1794 /**
1795 * Capacity of the queue.
1796 */
1797 uint64_t q_capacity;
1798
1799 /**
1790 * Queue priority 1800 * Queue priority
1791 */ 1801 */
1792 uint32_t priority; 1802 uint32_t priority;
@@ -3446,6 +3456,35 @@ transmit_on_queue (void *cls);
3446 3456
3447 3457
3448/** 3458/**
3459 * Check if the communicator has another queue with higher prio ready for sending.
3460 */
3461static unsigned int
3462check_for_queue_with_higher_prio (struct Queue *queue, struct Queue *queue_head)
3463{
3464 for (struct Queue *s = queue_head; NULL != s;
3465 s = s->next_client)
3466 {
3467 if (s->tc->details.communicator.address_prefix !=
3468 queue->tc->details.communicator.address_prefix)
3469 {
3470 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3471 "queue address %s qid %u compare with queue: address %s qid %u\n",
3472 queue->address,
3473 queue->qid,
3474 s->address,
3475 s->qid);
3476 if ((s->priority > queue->priority) && (0 < s->q_capacity) &&
3477 (QUEUE_LENGTH_LIMIT > s->queue_length) )
3478 return GNUNET_YES;
3479 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3480 "Lower prio\n");
3481 }
3482 }
3483 return GNUNET_NO;
3484}
3485
3486
3487/**
3449 * Called whenever something changed that might effect when we 3488 * Called whenever something changed that might effect when we
3450 * try to do the next transmission on @a queue using #transmit_on_queue(). 3489 * try to do the next transmission on @a queue using #transmit_on_queue().
3451 * 3490 *
@@ -3456,6 +3495,11 @@ static void
3456schedule_transmit_on_queue (struct Queue *queue, 3495schedule_transmit_on_queue (struct Queue *queue,
3457 enum GNUNET_SCHEDULER_Priority p) 3496 enum GNUNET_SCHEDULER_Priority p)
3458{ 3497{
3498 if (check_for_queue_with_higher_prio (queue,
3499 queue->tc->details.communicator.
3500 queue_head))
3501 return;
3502
3459 if (queue->tc->details.communicator.total_queue_length >= 3503 if (queue->tc->details.communicator.total_queue_length >=
3460 COMMUNICATOR_TOTAL_QUEUE_LIMIT) 3504 COMMUNICATOR_TOTAL_QUEUE_LIMIT)
3461 { 3505 {
@@ -3480,6 +3524,19 @@ schedule_transmit_on_queue (struct Queue *queue,
3480 queue->idle = GNUNET_NO; 3524 queue->idle = GNUNET_NO;
3481 return; 3525 return;
3482 } 3526 }
3527 if (0 == queue->q_capacity)
3528 {
3529 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3530 "Transmission throttled due to communicator message queue qid %u has capacity %lu.\n",
3531 queue->qid,
3532 queue->q_capacity);
3533 GNUNET_STATISTICS_update (GST_stats,
3534 "# Transmission throttled due to message queue capacity",
3535 1,
3536 GNUNET_NO);
3537 queue->idle = GNUNET_NO;
3538 return;
3539 }
3483 /* queue might indeed be ready, schedule it */ 3540 /* queue might indeed be ready, schedule it */
3484 if (NULL != queue->transmit_task) 3541 if (NULL != queue->transmit_task)
3485 GNUNET_SCHEDULER_cancel (queue->transmit_task); 3542 GNUNET_SCHEDULER_cancel (queue->transmit_task);
@@ -3582,8 +3639,9 @@ free_queue (struct Queue *queue)
3582 tc->details.communicator.queue_head, 3639 tc->details.communicator.queue_head,
3583 tc->details.communicator.queue_tail, 3640 tc->details.communicator.queue_tail,
3584 queue); 3641 queue);
3585 maxxed = (COMMUNICATOR_TOTAL_QUEUE_LIMIT >= 3642 maxxed = (COMMUNICATOR_TOTAL_QUEUE_LIMIT <=
3586 tc->details.communicator.total_queue_length); 3643 tc->details.communicator.
3644 total_queue_length);
3587 while (NULL != (qe = queue->queue_head)) 3645 while (NULL != (qe = queue->queue_head))
3588 { 3646 {
3589 GNUNET_CONTAINER_DLL_remove (queue->queue_head, queue->queue_tail, qe); 3647 GNUNET_CONTAINER_DLL_remove (queue->queue_head, queue->queue_tail, qe);
@@ -3597,7 +3655,7 @@ free_queue (struct Queue *queue)
3597 GNUNET_free (qe); 3655 GNUNET_free (qe);
3598 } 3656 }
3599 GNUNET_assert (0 == queue->queue_length); 3657 GNUNET_assert (0 == queue->queue_length);
3600 if ((maxxed) && (COMMUNICATOR_TOTAL_QUEUE_LIMIT < 3658 if ((maxxed) && (COMMUNICATOR_TOTAL_QUEUE_LIMIT >
3601 tc->details.communicator.total_queue_length)) 3659 tc->details.communicator.total_queue_length))
3602 { 3660 {
3603 /* Communicator dropped below threshold, resume all _other_ queues */ 3661 /* Communicator dropped below threshold, resume all _other_ queues */
@@ -4223,18 +4281,36 @@ queue_send_msg (struct Queue *queue,
4223 if (NULL != pm) 4281 if (NULL != pm)
4224 { 4282 {
4225 qe->pm = pm; 4283 qe->pm = pm;
4226 GNUNET_assert (NULL == pm->qe); 4284 // TODO Why do we have a retransmission. When we know, make decision if we still want this.
4285 // GNUNET_assert (NULL == pm->qe);
4286 /*if (NULL != pm->qe)
4287 {
4288 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4289 "Retransmitting message <%llu> remove pm from qe with MID: %llu \n",
4290 pm->logging_uuid,
4291 (unsigned long long) pm->qe->mid);
4292 pm->qe->pm = NULL;
4293 }*/
4227 pm->qe = qe; 4294 pm->qe = qe;
4228 } 4295 }
4229 GNUNET_CONTAINER_DLL_insert (queue->queue_head, queue->queue_tail, qe); 4296 GNUNET_CONTAINER_DLL_insert (queue->queue_head, queue->queue_tail, qe);
4230 GNUNET_assert (CT_COMMUNICATOR == queue->tc->type); 4297 GNUNET_assert (CT_COMMUNICATOR == queue->tc->type);
4231 queue->queue_length++; 4298 queue->queue_length++;
4232 queue->tc->details.communicator.total_queue_length++; 4299 queue->tc->details.communicator.total_queue_length++;
4300 if (GNUNET_NO == queue->unlimited_length)
4301 queue->q_capacity--;
4302 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4303 "Queue %s with qid %u has capacity %lu\n",
4304 queue->address,
4305 queue->qid,
4306 queue->q_capacity);
4233 if (COMMUNICATOR_TOTAL_QUEUE_LIMIT == 4307 if (COMMUNICATOR_TOTAL_QUEUE_LIMIT ==
4234 queue->tc->details.communicator.total_queue_length) 4308 queue->tc->details.communicator.total_queue_length)
4235 queue->idle = GNUNET_NO; 4309 queue->idle = GNUNET_NO;
4236 if (QUEUE_LENGTH_LIMIT == queue->queue_length) 4310 if (QUEUE_LENGTH_LIMIT == queue->queue_length)
4237 queue->idle = GNUNET_NO; 4311 queue->idle = GNUNET_NO;
4312 if (0 == queue->q_capacity)
4313 queue->idle = GNUNET_NO;
4238 GNUNET_MQ_send (queue->tc->mq, env); 4314 GNUNET_MQ_send (queue->tc->mq, env);
4239 } 4315 }
4240} 4316}
@@ -4672,8 +4748,16 @@ route_control_message_without_fc (const struct GNUNET_PeerIdentity *target,
4672 struct GNUNET_TIME_Relative rtt1; 4748 struct GNUNET_TIME_Relative rtt1;
4673 struct GNUNET_TIME_Relative rtt2; 4749 struct GNUNET_TIME_Relative rtt2;
4674 4750
4751 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4752 "Trying to route message of type %u to %s without fc\n",
4753 ntohs (hdr->type),
4754 GNUNET_i2s (target));
4755
4756 // TODO Do this elsewhere. vl should be given as parameter to method.
4675 vl = lookup_virtual_link (target); 4757 vl = lookup_virtual_link (target);
4676 GNUNET_assert (NULL != vl); 4758 GNUNET_assert (NULL != vl);
4759 if (NULL == vl)
4760 return GNUNET_TIME_UNIT_FOREVER_REL;
4677 n = vl->n; 4761 n = vl->n;
4678 dv = (0 != (options & RMO_DV_ALLOWED)) ? vl->dv : NULL; 4762 dv = (0 != (options & RMO_DV_ALLOWED)) ? vl->dv : NULL;
4679 if (0 == (options & RMO_UNCONFIRMED_ALLOWED)) 4763 if (0 == (options & RMO_UNCONFIRMED_ALLOWED))
@@ -4718,6 +4802,10 @@ route_control_message_without_fc (const struct GNUNET_PeerIdentity *target,
4718 rtt2 = GNUNET_TIME_UNIT_FOREVER_REL; 4802 rtt2 = GNUNET_TIME_UNIT_FOREVER_REL;
4719 if (NULL != n) 4803 if (NULL != n)
4720 { 4804 {
4805 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4806 "Try to route message of type %u to %s without fc via neighbour\n",
4807 ntohs (hdr->type),
4808 GNUNET_i2s (target));
4721 rtt1 = route_via_neighbour (n, hdr, options); 4809 rtt1 = route_via_neighbour (n, hdr, options);
4722 } 4810 }
4723 if (NULL != dv) 4811 if (NULL != dv)
@@ -4889,7 +4977,9 @@ check_vl_transmission (struct VirtualLink *vl)
4889 schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); 4977 schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
4890 else 4978 else
4891 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4979 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4892 "Queue busy or invalid\n"); 4980 "Neighbour Queue QID: %u (%u) busy or invalid\n",
4981 queue->qid,
4982 queue->idle);
4893 } 4983 }
4894 } 4984 }
4895 /* Notify queues via DV that we are interested */ 4985 /* Notify queues via DV that we are interested */
@@ -4910,6 +5000,11 @@ check_vl_transmission (struct VirtualLink *vl)
4910 (queue->validated_until.abs_value_us > now.abs_value_us)) 5000 (queue->validated_until.abs_value_us > now.abs_value_us))
4911 schedule_transmit_on_queue (queue, 5001 schedule_transmit_on_queue (queue,
4912 GNUNET_SCHEDULER_PRIORITY_BACKGROUND); 5002 GNUNET_SCHEDULER_PRIORITY_BACKGROUND);
5003 else
5004 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5005 "DV Queue QID: %u (%u) busy or invalid\n",
5006 queue->qid,
5007 queue->idle);
4913 } 5008 }
4914 } 5009 }
4915} 5010}
@@ -4996,8 +5091,9 @@ handle_communicator_backchannel (
4996 (const struct GNUNET_MessageHeader *) &cb[1]; 5091 (const struct GNUNET_MessageHeader *) &cb[1];
4997 uint16_t isize = ntohs (inbox->size); 5092 uint16_t isize = ntohs (inbox->size);
4998 const char *is = ((const char *) &cb[1]) + isize; 5093 const char *is = ((const char *) &cb[1]) + isize;
5094 size_t slen = strlen (is) + 1;
4999 char 5095 char
5000 mbuf[isize 5096 mbuf[slen + isize
5001 + sizeof(struct 5097 + sizeof(struct
5002 TransportBackchannelEncapsulationMessage)] GNUNET_ALIGN; 5098 TransportBackchannelEncapsulationMessage)] GNUNET_ALIGN;
5003 struct TransportBackchannelEncapsulationMessage *be = 5099 struct TransportBackchannelEncapsulationMessage *be =
@@ -5006,9 +5102,10 @@ handle_communicator_backchannel (
5006 /* 0-termination of 'is' was checked already in 5102 /* 0-termination of 'is' was checked already in
5007 #check_communicator_backchannel() */ 5103 #check_communicator_backchannel() */
5008 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5009 "Preparing backchannel transmission to %s:%s of type %u\n", 5105 "Preparing backchannel transmission to %s:%s of type %u and size %u\n",
5010 GNUNET_i2s (&cb->pid), 5106 GNUNET_i2s (&cb->pid),
5011 is, 5107 is,
5108 ntohs (inbox->type),
5012 ntohs (inbox->size)); 5109 ntohs (inbox->size));
5013 /* encapsulate and encrypt message */ 5110 /* encapsulate and encrypt message */
5014 be->header.type = 5111 be->header.type =
@@ -5264,6 +5361,11 @@ handle_raw_message (void *cls, const struct GNUNET_MessageHeader *mh)
5264 uint16_t size = ntohs (mh->size); 5361 uint16_t size = ntohs (mh->size);
5265 int have_core; 5362 int have_core;
5266 5363
5364 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5365 "Handling message of type %u with %u bytes\n",
5366 (unsigned int) ntohs (mh->type),
5367 (unsigned int) ntohs (mh->size));
5368
5267 if ((size > UINT16_MAX - sizeof(struct InboundMessage)) || 5369 if ((size > UINT16_MAX - sizeof(struct InboundMessage)) ||
5268 (size < sizeof(struct GNUNET_MessageHeader))) 5370 (size < sizeof(struct GNUNET_MessageHeader)))
5269 { 5371 {
@@ -5290,6 +5392,10 @@ handle_raw_message (void *cls, const struct GNUNET_MessageHeader *mh)
5290 1, 5392 1,
5291 GNUNET_NO); 5393 GNUNET_NO);
5292 5394
5395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5396 "CORE messages of type %u with %u bytes dropped (virtual link still down)\n",
5397 (unsigned int) ntohs (mh->type),
5398 (unsigned int) ntohs (mh->size));
5293 finish_cmc_handling (cmc); 5399 finish_cmc_handling (cmc);
5294 return; 5400 return;
5295 } 5401 }
@@ -5299,7 +5405,10 @@ handle_raw_message (void *cls, const struct GNUNET_MessageHeader *mh)
5299 "# CORE messages dropped (FC arithmetic overflow)", 5405 "# CORE messages dropped (FC arithmetic overflow)",
5300 1, 5406 1,
5301 GNUNET_NO); 5407 GNUNET_NO);
5302 5408 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5409 "CORE messages of type %u with %u bytes dropped (FC arithmetic overflow)\n",
5410 (unsigned int) ntohs (mh->type),
5411 (unsigned int) ntohs (mh->size));
5303 finish_cmc_handling (cmc); 5412 finish_cmc_handling (cmc);
5304 return; 5413 return;
5305 } 5414 }
@@ -5309,6 +5418,10 @@ handle_raw_message (void *cls, const struct GNUNET_MessageHeader *mh)
5309 "# CORE messages dropped (FC window overflow)", 5418 "# CORE messages dropped (FC window overflow)",
5310 1, 5419 1,
5311 GNUNET_NO); 5420 GNUNET_NO);
5421 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5422 "CORE messages of type %u with %u bytes dropped (FC window overflow)\n",
5423 (unsigned int) ntohs (mh->type),
5424 (unsigned int) ntohs (mh->size));
5312 finish_cmc_handling (cmc); 5425 finish_cmc_handling (cmc);
5313 return; 5426 return;
5314 } 5427 }
@@ -5345,6 +5458,10 @@ handle_raw_message (void *cls, const struct GNUNET_MessageHeader *mh)
5345 perspective of the other peer! */ 5458 perspective of the other peer! */
5346 vl->incoming_fc_window_size_used += size; 5459 vl->incoming_fc_window_size_used += size;
5347 /* TODO-M1 */ 5460 /* TODO-M1 */
5461 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5462 "Dropped message of type %u with %u bytes to CORE: no CORE client connected!",
5463 (unsigned int) ntohs (mh->type),
5464 (unsigned int) ntohs (mh->size));
5348 finish_cmc_handling (cmc); 5465 finish_cmc_handling (cmc);
5349 return; 5466 return;
5350 } 5467 }
@@ -6074,6 +6191,15 @@ handle_backchannel_encapsulation (
6074 (const struct GNUNET_MessageHeader *) &be[1]; 6191 (const struct GNUNET_MessageHeader *) &be[1];
6075 uint16_t isize = ntohs (inbox->size); 6192 uint16_t isize = ntohs (inbox->size);
6076 const char *target_communicator = ((const char *) inbox) + isize; 6193 const char *target_communicator = ((const char *) inbox) + isize;
6194 char *sender;
6195 char *self;
6196
6197 GNUNET_asprintf (&sender,
6198 "%s",
6199 GNUNET_i2s (&cmc->im.sender));
6200 GNUNET_asprintf (&self,
6201 "%s",
6202 GNUNET_i2s (&GST_my_identity));
6077 6203
6078 /* Find client providing this communicator */ 6204 /* Find client providing this communicator */
6079 for (tc = clients_head; NULL != tc; tc = tc->next) 6205 for (tc = clients_head; NULL != tc; tc = tc->next)
@@ -6095,8 +6221,9 @@ handle_backchannel_encapsulation (
6095 } 6221 }
6096 /* Finally, deliver backchannel message to communicator */ 6222 /* Finally, deliver backchannel message to communicator */
6097 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
6098 "Delivering backchannel message from %s of type %u to %s\n", 6224 "Delivering backchannel message from %s to %s of type %u to %s\n",
6099 GNUNET_i2s (&cmc->im.sender), 6225 sender,
6226 self,
6100 ntohs (inbox->type), 6227 ntohs (inbox->type),
6101 target_communicator); 6228 target_communicator);
6102 env = GNUNET_MQ_msg_extra ( 6229 env = GNUNET_MQ_msg_extra (
@@ -8407,14 +8534,15 @@ fragment_message (struct Queue *queue,
8407 struct PendingMessage *ff; 8534 struct PendingMessage *ff;
8408 uint16_t mtu; 8535 uint16_t mtu;
8409 8536
8410 mtu = (0 == queue->mtu) 8537 mtu = (UINT16_MAX == queue->mtu)
8411 ? UINT16_MAX - sizeof(struct GNUNET_TRANSPORT_SendMessageTo) 8538 ? UINT16_MAX - sizeof(struct GNUNET_TRANSPORT_SendMessageTo)
8412 : queue->mtu; 8539 : queue->mtu;
8413 set_pending_message_uuid (pm); 8540 set_pending_message_uuid (pm);
8414 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 8541 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
8415 "Fragmenting message %llu <%llu> to %s for MTU %u\n", 8542 "Fragmenting message %llu <%llu> with size %u to %s for MTU %u\n",
8416 (unsigned long long) pm->msg_uuid.uuid, 8543 (unsigned long long) pm->msg_uuid.uuid,
8417 pm->logging_uuid, 8544 pm->logging_uuid,
8545 pm->bytes_msg,
8418 GNUNET_i2s (&pm->vl->target), 8546 GNUNET_i2s (&pm->vl->target),
8419 (unsigned int) mtu); 8547 (unsigned int) mtu);
8420 pa = prepare_pending_acknowledgement (queue, dvh, pm); 8548 pa = prepare_pending_acknowledgement (queue, dvh, pm);
@@ -8700,7 +8828,7 @@ select_best_pending_from_link (struct PendingMessageScoreContext *sc,
8700 GNUNET_TRANSPORT_SendMessageTo)) 8828 GNUNET_TRANSPORT_SendMessageTo))
8701 || 8829 ||
8702 (NULL != pos->head_frag /* fragments already exist, should 8830 (NULL != pos->head_frag /* fragments already exist, should
8703 respect that even if MTU is 0 for 8831 respect that even if MTU is UINT16_MAX for
8704 this queue */)) 8832 this queue */))
8705 { 8833 {
8706 frag = GNUNET_YES; 8834 frag = GNUNET_YES;
@@ -9069,12 +9197,17 @@ handle_send_message_ack (void *cls,
9069 qep = qep->next) 9197 qep = qep->next)
9070 { 9198 {
9071 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 9199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
9072 "QueueEntry MID: %llu, Ack MID: %llu\n", 9200 "QueueEntry MID: %llu on queue QID: %llu, Ack MID: %llu\n",
9073 (unsigned long long) qep->mid, 9201 (unsigned long long) qep->mid,
9202 (unsigned long long) queue->qid,
9074 (unsigned long long) sma->mid); 9203 (unsigned long long) sma->mid);
9075 if (qep->mid != sma->mid) 9204 if (qep->mid != sma->mid)
9076 continue; 9205 continue;
9077 qe = qep; 9206 qe = qep;
9207 if ((NULL != qe->pm)&&(qe->pm->qe != qe))
9208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
9209 "For pending message %llu we had retransmissions.\n",
9210 qe->pm->logging_uuid);
9078 break; 9211 break;
9079 } 9212 }
9080 } 9213 }
@@ -9125,12 +9258,26 @@ handle_send_message_ack (void *cls,
9125 GNUNET_NO); 9258 GNUNET_NO);
9126 schedule_transmit_on_queue (qe->queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); 9259 schedule_transmit_on_queue (qe->queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
9127 } 9260 }
9261 else if (1 == qe->queue->q_capacity)
9262 {
9263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
9264 "Transmission rescheduled due to communicator message queue with qid %u has capacity %lu.\n",
9265 qe->queue->qid,
9266 qe->queue->q_capacity);
9267 /* message queue has capacity; only resume this one queue */
9268 /* queue dropped below threshold; only resume this one queue */
9269 GNUNET_STATISTICS_update (GST_stats,
9270 "# Transmission throttled due to message queue capacity",
9271 -1,
9272 GNUNET_NO);
9273 schedule_transmit_on_queue (qe->queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
9274 }
9128 9275
9129 if (NULL != (pm = qe->pm)) 9276 if (NULL != (pm = qe->pm))
9130 { 9277 {
9131 struct VirtualLink *vl; 9278 struct VirtualLink *vl;
9132 9279
9133 GNUNET_assert (qe == pm->qe); 9280 // GNUNET_assert (qe == pm->qe);
9134 pm->qe = NULL; 9281 pm->qe = NULL;
9135 /* If waiting for this communicator may have blocked transmission 9282 /* If waiting for this communicator may have blocked transmission
9136 of pm on other queues for this neighbour, force schedule 9283 of pm on other queues for this neighbour, force schedule
@@ -9671,16 +9818,20 @@ handle_add_queue_message (void *cls,
9671 addr_len = ntohs (aqm->header.size) - sizeof(*aqm); 9818 addr_len = ntohs (aqm->header.size) - sizeof(*aqm);
9672 addr = (const char *) &aqm[1]; 9819 addr = (const char *) &aqm[1];
9673 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 9820 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
9674 "New queue %s to %s available with QID %llu\n", 9821 "New queue %s to %s available with QID %llu and q_len %lu \n",
9675 addr, 9822 addr,
9676 GNUNET_i2s (&aqm->receiver), 9823 GNUNET_i2s (&aqm->receiver),
9677 (unsigned long long) aqm->qid); 9824 (unsigned long long) aqm->qid,
9825 GNUNET_ntohll (aqm->q_len));
9678 queue = GNUNET_malloc (sizeof(struct Queue) + addr_len); 9826 queue = GNUNET_malloc (sizeof(struct Queue) + addr_len);
9679 queue->tc = tc; 9827 queue->tc = tc;
9680 queue->address = (const char *) &queue[1]; 9828 queue->address = (const char *) &queue[1];
9681 queue->pd.aged_rtt = GNUNET_TIME_UNIT_FOREVER_REL; 9829 queue->pd.aged_rtt = GNUNET_TIME_UNIT_FOREVER_REL;
9682 queue->qid = aqm->qid; 9830 queue->qid = aqm->qid;
9683 queue->neighbour = neighbour; 9831 queue->neighbour = neighbour;
9832 if (GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED == GNUNET_ntohll (aqm->q_len))
9833 queue->unlimited_length = GNUNET_YES;
9834 queue->q_capacity = GNUNET_ntohll (aqm->q_len);
9684 memcpy (&queue[1], addr, addr_len); 9835 memcpy (&queue[1], addr, addr_len);
9685 /* notify monitors about new queue */ 9836 /* notify monitors about new queue */
9686 { 9837 {
@@ -9752,10 +9903,14 @@ handle_update_queue_message (void *cls,
9752 target_queue->mtu = ntohl (msg->mtu); 9903 target_queue->mtu = ntohl (msg->mtu);
9753 target_queue->cs = msg->cs; 9904 target_queue->cs = msg->cs;
9754 target_queue->priority = ntohl (msg->priority); 9905 target_queue->priority = ntohl (msg->priority);
9755 /* The update message indicates how many _additional_ 9906 /* The update message indicates how many messages
9756 * messages the queue should be able to handle 9907 * the queue should be able to handle.
9757 */ 9908 */
9758 target_queue->queue_length += GNUNET_ntohll (msg->q_len); 9909 if (GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED == GNUNET_ntohll (msg->q_len))
9910 target_queue->unlimited_length = GNUNET_YES;
9911 else
9912 target_queue->unlimited_length = GNUNET_NO;
9913 target_queue->q_capacity = GNUNET_ntohll (msg->q_len);
9759 GNUNET_SERVICE_client_continue (tc->client); 9914 GNUNET_SERVICE_client_continue (tc->client);
9760} 9915}
9761 9916
@@ -10179,8 +10334,18 @@ static void
10179shutdown_task (void *cls) 10334shutdown_task (void *cls)
10180{ 10335{
10181 in_shutdown = GNUNET_YES; 10336 in_shutdown = GNUNET_YES;
10337
10182 if (NULL == clients_head) 10338 if (NULL == clients_head)
10183 do_shutdown (cls); 10339 {
10340 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
10341 {
10342 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
10343 "client still connected: %u\n",
10344 tc->type);
10345 }
10346 }
10347 do_shutdown (cls);
10348
10184} 10349}
10185 10350
10186 10351
diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c b/src/transport/test_transport_plugin_cmd_simple_send.c
index 07255a1a5..b578219ca 100644
--- a/src/transport/test_transport_plugin_cmd_simple_send.c
+++ b/src/transport/test_transport_plugin_cmd_simple_send.c
@@ -180,7 +180,8 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
180 GNUNET_TESTING_cmd_system_destroy ("system-destroy", 180 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
181 "system-create"), 181 "system-create"),
182 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished", 182 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished",
183 write_message) 183 write_message),
184 GNUNET_TESTING_cmd_end_without_shutdown ()
184 }; 185 };
185 186
186 GNUNET_TESTING_run (NULL, 187 GNUNET_TESTING_run (NULL,
@@ -201,6 +202,10 @@ libgnunet_test_transport_plugin_cmd_simple_send_init (void *cls)
201{ 202{
202 struct GNUNET_TESTING_PluginFunctions *api; 203 struct GNUNET_TESTING_PluginFunctions *api;
203 204
205 GNUNET_log_setup ("simple-send",
206 "DEBUG",
207 NULL);
208
204 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions); 209 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
205 api->start_testcase = &start_testcase; 210 api->start_testcase = &start_testcase;
206 api->all_peers_started = &all_peers_started; 211 api->all_peers_started = &all_peers_started;
diff --git a/src/transport/test_transport_plugin_cmd_simple_send_v2.c b/src/transport/test_transport_plugin_cmd_simple_send_v2.c
index c79b5c7e2..acfe784d6 100644
--- a/src/transport/test_transport_plugin_cmd_simple_send_v2.c
+++ b/src/transport/test_transport_plugin_cmd_simple_send_v2.c
@@ -185,7 +185,8 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
185 GNUNET_TESTING_cmd_system_destroy ("system-destroy", 185 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
186 "system-create"), 186 "system-create"),
187 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished", 187 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished",
188 write_message) 188 write_message),
189 GNUNET_TESTING_cmd_end_without_shutdown ()
189 }; 190 };
190 191
191 GNUNET_TESTING_run (NULL, 192 GNUNET_TESTING_run (NULL,
diff --git a/src/transport/test_transport_plugin_cmd_udp_backchannel.c b/src/transport/test_transport_plugin_cmd_udp_backchannel.c
index 90e474aea..e2e0b258b 100644
--- a/src/transport/test_transport_plugin_cmd_udp_backchannel.c
+++ b/src/transport/test_transport_plugin_cmd_udp_backchannel.c
@@ -58,6 +58,12 @@ char *cfgname;
58unsigned int are_all_peers_started; 58unsigned int are_all_peers_started;
59 59
60/** 60/**
61 * Flag indicating if all local tests are prepared to finish.
62 *
63 */
64unsigned int are_all_local_tests_prepared;
65
66/**
61 * Flag indicating a received message. 67 * Flag indicating a received message.
62 */ 68 */
63unsigned int message_received; 69unsigned int message_received;
@@ -85,6 +91,8 @@ static void
85handle_test (void *cls, 91handle_test (void *cls,
86 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 92 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
87{ 93{
94 LOG (GNUNET_ERROR_TYPE_DEBUG,
95 "Message received.\n");
88 message_received = GNUNET_YES; 96 message_received = GNUNET_YES;
89} 97}
90 98
@@ -104,6 +112,16 @@ all_peers_started ()
104 112
105 113
106/** 114/**
115 * Callback to set the flag indicating all peers are prepared to finish. Will be called via the plugin api.
116 */
117static void
118all_local_tests_prepared ()
119{
120 are_all_local_tests_prepared = GNUNET_YES;
121}
122
123
124/**
107 * Function to start a local test case. 125 * Function to start a local test case.
108 * 126 *
109 * @param write_message Callback to send a message to the master loop. 127 * @param write_message Callback to send a message to the master loop.
@@ -179,17 +197,23 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
179 "system-create", 197 "system-create",
180 num, 198 num,
181 topology), 199 topology),
182 GNUNET_TRANSPORT_cmd_send_simple_v2 ("send-simple", 200 GNUNET_TRANSPORT_cmd_backchannel_check ("backchannel-check",
183 "start-peer", 201 "start-peer",
184 num), 202 "system-create",
185 GNUNET_TESTING_cmd_block_until_external_trigger ("block-receive", 203 num,
186 &message_received), 204 m_int,
205 n_int,
206 topology),
207 GNUNET_TESTING_cmd_local_test_prepared ("local-test-prepared",
208 write_message,
209 &are_all_local_tests_prepared),
187 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer", 210 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
188 "start-peer"), 211 "start-peer"),
189 GNUNET_TESTING_cmd_system_destroy ("system-destroy", 212 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
190 "system-create"), 213 "system-create"),
191 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished", 214 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished",
192 write_message) 215 write_message),
216 GNUNET_TESTING_cmd_end_without_shutdown ()
193 }; 217 };
194 218
195 GNUNET_TESTING_run (NULL, 219 GNUNET_TESTING_run (NULL,
@@ -217,6 +241,7 @@ libgnunet_test_transport_plugin_cmd_udp_backchannel_init (void *cls)
217 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions); 241 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
218 api->start_testcase = &start_testcase; 242 api->start_testcase = &start_testcase;
219 api->all_peers_started = &all_peers_started; 243 api->all_peers_started = &all_peers_started;
244 api->all_local_tests_prepared = all_local_tests_prepared;
220 return api; 245 return api;
221} 246}
222 247
diff --git a/src/transport/test_transport_udp_backchannel.sh b/src/transport/test_transport_udp_backchannel.sh
index 3322e5853..0c37be469 100755
--- a/src/transport/test_transport_udp_backchannel.sh
+++ b/src/transport/test_transport_udp_backchannel.sh
@@ -1,2 +1,4 @@
1#!/bin/bash 1#!/bin/bash
2#exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; valgrind --leak-check=full --track-origins=yes --trace-children=yes --trace-children-skip=/usr/bin/awk,/usr/bin/cut,/usr/bin/seq,/sbin/ip ./test_transport_start_with_config test_transport_udp_backchannel_topo.conf"
2exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_start_with_config test_transport_udp_backchannel_topo.conf" 3exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_start_with_config test_transport_udp_backchannel_topo.conf"
4# exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; valgrind --leak-check=full --track-origins=yes ./test_transport_start_with_config test_transport_udp_backchannel_topo.conf"
diff --git a/src/transport/transport-testing-cmds.h b/src/transport/transport-testing-cmds.h
index ecdabd35f..67e5723f5 100644
--- a/src/transport/transport-testing-cmds.h
+++ b/src/transport/transport-testing-cmds.h
@@ -228,22 +228,36 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label,
228 struct GNUNET_MQ_MessageHandler *handlers, 228 struct GNUNET_MQ_MessageHandler *handlers,
229 const char *cfgname); 229 const char *cfgname);
230 230
231
231struct GNUNET_TESTING_Command 232struct GNUNET_TESTING_Command
232GNUNET_TRANSPORT_cmd_stop_peer (const char *label, 233GNUNET_TRANSPORT_cmd_stop_peer (const char *label,
233 const char *start_label); 234 const char *start_label);
234 235
236
235struct GNUNET_TESTING_Command 237struct GNUNET_TESTING_Command
236GNUNET_TRANSPORT_cmd_connect_peers (const char *label, 238GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
237 const char *start_peer_label, 239 const char *start_peer_label,
238 const char *create_label, 240 const char *create_label,
239 uint32_t num); 241 uint32_t num);
240 242
243
241struct GNUNET_TESTING_Command 244struct GNUNET_TESTING_Command
242GNUNET_TRANSPORT_cmd_connect_peers_v2 (const char *label, 245GNUNET_TRANSPORT_cmd_connect_peers_v2 (const char *label,
243 const char *start_peer_label, 246 const char *start_peer_label,
244 const char *create_label, 247 const char *create_label,
245 uint32_t num); 248 uint32_t num);
246 249
250
251/**
252 * Create command.
253 *
254 * @param label name for command.
255 * @param start_peer_label Label of the cmd to start a peer.
256 * @param create_label Label of the cmd to create the testing system.
257 * @param num Number globally identifying the node.
258 * @param The topology for the test setup.
259 * @return command.
260 */
247struct GNUNET_TESTING_Command 261struct GNUNET_TESTING_Command
248GNUNET_TRANSPORT_cmd_connect_peers_v3 (const char *label, 262GNUNET_TRANSPORT_cmd_connect_peers_v3 (const char *label,
249 const char *start_peer_label, 263 const char *start_peer_label,
@@ -252,6 +266,40 @@ GNUNET_TRANSPORT_cmd_connect_peers_v3 (const char *label,
252 struct GNUNET_TESTING_NetjailTopology * 266 struct GNUNET_TESTING_NetjailTopology *
253 topology); 267 topology);
254 268
269
270/**
271 * Create command.
272 *
273 * @param label name for command.
274 * @param start_peer_label Label of the cmd to start a peer.
275 * @param create_label Label of the cmd to create the testing system.
276 * @param num Number globally identifying the node.
277 * @param node_n The number of the node in a network namespace.
278 * @param namespace_n The number of the network namespace.
279 * @param The topology for the test setup.
280 * @return command.
281 */
282struct GNUNET_TESTING_Command
283GNUNET_TRANSPORT_cmd_backchannel_check (const char *label,
284 const char *start_peer_label,
285 const char *create_label,
286 uint32_t num,
287 unsigned int node_n,
288 unsigned int namespace_n,
289 struct GNUNET_TESTING_NetjailTopology *
290 topology);
291
292
293/**
294 * Create command.
295 *
296 * @param label name for command.
297 * @param m The number of the local node of the actual network namespace.
298 * @param n The number of the actual namespace.
299 * @param num Number globally identifying the node.
300 * @param start_peer_label Label of the cmd to start a peer.
301 * @return command.
302 */
255struct GNUNET_TESTING_Command 303struct GNUNET_TESTING_Command
256GNUNET_TRANSPORT_cmd_send_simple (const char *label, 304GNUNET_TRANSPORT_cmd_send_simple (const char *label,
257 char *m, 305 char *m,
@@ -263,10 +311,8 @@ GNUNET_TRANSPORT_cmd_send_simple (const char *label,
263 * Create command. 311 * Create command.
264 * 312 *
265 * @param label name for command. 313 * @param label name for command.
266 * @param m The number of the local node of the actual network namespace.
267 * @param n The number of the actual namespace.
268 * @param num Number globally identifying the node.
269 * @param start_peer_label Label of the cmd to start a peer. 314 * @param start_peer_label Label of the cmd to start a peer.
315 * @param num Number globally identifying the node.
270 * @return command. 316 * @return command.
271 */ 317 */
272struct GNUNET_TESTING_Command 318struct GNUNET_TESTING_Command
@@ -274,6 +320,26 @@ GNUNET_TRANSPORT_cmd_send_simple_v2 (const char *label,
274 const char *start_peer_label, 320 const char *start_peer_label,
275 uint32_t num); 321 uint32_t num);
276 322
323
324/**
325 * Create command.
326 *
327 * @param label name for command.
328 * @param start_peer_label Label of the cmd to start a peer.
329 * @param start_peer_label Label of the cmd which started the test system.
330 * @param num Number globally identifying the node.
331 * @param The topology for the test setup.
332 * @return command.
333 */
334struct GNUNET_TESTING_Command
335GNUNET_TRANSPORT_cmd_send_simple_v3 (const char *label,
336 const char *start_peer_label,
337 const char *create_label,
338 uint32_t num,
339 struct GNUNET_TESTING_NetjailTopology *
340 topology);
341
342
277int 343int
278GNUNET_TRANSPORT_get_trait_peer_id (const struct 344GNUNET_TRANSPORT_get_trait_peer_id (const struct
279 GNUNET_TESTING_Command *cmd, 345 GNUNET_TESTING_Command *cmd,
diff --git a/src/transport/transport_api2_communication.c b/src/transport/transport_api2_communication.c
index 446add6f6..2a80db87b 100644
--- a/src/transport/transport_api2_communication.c
+++ b/src/transport/transport_api2_communication.c
@@ -904,6 +904,10 @@ GNUNET_TRANSPORT_communicator_receive (
904 struct GNUNET_TRANSPORT_IncomingMessage *im; 904 struct GNUNET_TRANSPORT_IncomingMessage *im;
905 uint16_t msize; 905 uint16_t msize;
906 906
907
908 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
909 "communicator receive\n");
910
907 if (NULL == ch->mq) 911 if (NULL == ch->mq)
908 return GNUNET_SYSERR; 912 return GNUNET_SYSERR;
909 if ((NULL == cb) && (GNUNET_MQ_get_length (ch->mq) >= ch->max_queue_length)) 913 if ((NULL == cb) && (GNUNET_MQ_get_length (ch->mq) >= ch->max_queue_length))
@@ -986,6 +990,9 @@ GNUNET_TRANSPORT_communicator_mq_add (
986{ 990{
987 struct GNUNET_TRANSPORT_QueueHandle *qh; 991 struct GNUNET_TRANSPORT_QueueHandle *qh;
988 992
993 // Do not notify the service if there is no intial capacity.
994 GNUNET_assert (0 < q_len);
995
989 qh = GNUNET_new (struct GNUNET_TRANSPORT_QueueHandle); 996 qh = GNUNET_new (struct GNUNET_TRANSPORT_QueueHandle);
990 qh->ch = ch; 997 qh->ch = ch;
991 qh->peer = *peer; 998 qh->peer = *peer;
@@ -1106,7 +1113,7 @@ GNUNET_TRANSPORT_communicator_address_remove (
1106 */ 1113 */
1107void 1114void
1108GNUNET_TRANSPORT_communicator_address_remove_all ( 1115GNUNET_TRANSPORT_communicator_address_remove_all (
1109 struct GNUNET_TRANSPORT_CommunicatorHandle *ch) 1116 struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
1110{ 1117{
1111 for (struct GNUNET_TRANSPORT_AddressIdentifier *ai = ch->ai_head; NULL != ai; 1118 for (struct GNUNET_TRANSPORT_AddressIdentifier *ai = ch->ai_head; NULL != ai;
1112 ai = ai->next) 1119 ai = ai->next)
diff --git a/src/transport/transport_api_cmd_backchannel_check.c b/src/transport/transport_api_cmd_backchannel_check.c
new file mode 100644
index 000000000..da44e91ca
--- /dev/null
+++ b/src/transport/transport_api_cmd_backchannel_check.c
@@ -0,0 +1,628 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 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
21/**
22 * @file testing_api_cmd_backchannel_check.c
23 * @brief cmd to start a peer.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_common.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_testing_ng_lib.h"
30#include "gnunet_transport_application_service.h"
31#include "gnunet_hello_lib.h"
32#include "gnunet_transport_service.h"
33#include "transport-testing-cmds.h"
34
35/**
36 * Generic logging shortcut
37 */
38#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
39
40#define UDP "udp"
41
42/**
43 * Maximum length allowed for line input.
44 */
45#define MAX_LINE_LENGTH 1024
46
47/**
48 * Struct to store information needed in callbacks.
49 *
50 */
51struct CheckState
52{
53 /**
54 * The number of the node in a network namespace.
55 */
56 unsigned int node_n;
57
58 /**
59 * The number of the network namespace.
60 */
61 unsigned int namespace_n;
62
63 /**
64 * The testing system of this node.
65 */
66 struct GNUNET_TESTING_System *tl_system;
67
68 // Label of the cmd which started the test system.
69 const char *create_label;
70
71 /**
72 * Number globally identifying the node.
73 *
74 */
75 uint32_t num;
76
77 /**
78 * Label of the cmd to start a peer.
79 *
80 */
81 const char *start_peer_label;
82
83 /**
84 * The topology of the test setup.
85 */
86 struct GNUNET_TESTING_NetjailTopology *topology;
87
88 /**
89 * Connections to other peers.
90 */
91 struct GNUNET_TESTING_NodeConnection *node_connections_head;
92
93 /**
94 * Number of connections.
95 */
96 unsigned int con_num;
97
98 /**
99 * Number of received backchannel messages.
100 */
101 unsigned int received_backchannel_msgs;
102
103 /**
104 * Array with search strings.
105 */
106 char **search_string;
107
108 /**
109 * File handle for log file.
110 */
111 struct GNUNET_DISK_FileHandle *fh;
112
113 /**
114 * Task which handles the reading
115 */
116 struct GNUNET_SCHEDULER_Task *task;
117
118 /**
119 * Stream to read log file lines.
120 */
121 FILE *stream;
122
123 /**
124 * Did we get all bachchannel messages.
125 */
126 enum GNUNET_GenericReturnValue finished;
127};
128
129/**
130 *
131 * @param cls The cmd state CheckState.
132 */
133static void
134read_from_log (void *cls)
135{
136 struct CheckState *cs = cls;
137 char line[MAX_LINE_LENGTH + 1];
138 char *search_string;
139
140
141 LOG (GNUNET_ERROR_TYPE_DEBUG,
142 "read_from_log\n");
143
144 cs->fh = GNUNET_DISK_file_open ("test.out",
145 GNUNET_DISK_OPEN_READ,
146 GNUNET_DISK_PERM_USER_READ);
147
148 cs->task = NULL;
149
150 /* read message from line and handle it */
151 cs->stream = fdopen (cs->fh->fd, "r");
152 memset (line, 0, MAX_LINE_LENGTH + 1);
153
154 // fgets (line, MAX_LINE_LENGTH, cs->stream);
155 // while (NULL != line && 0 != strcmp (line, ""))// '\0' != line[0])
156 while (NULL != fgets (line, MAX_LINE_LENGTH, cs->stream))
157 {
158 /*LOG (GNUNET_ERROR_TYPE_DEBUG,
159 "cs->received_backchannel_msgs: %u\n",
160 cs->received_backchannel_msgs);*/
161 /*if (NULL == strstr (line, "line"))
162 LOG (GNUNET_ERROR_TYPE_DEBUG,
163 "line: %s",
164 line);*/
165
166
167 for (int i = 0; i < cs->con_num; i++)
168 {
169 search_string = cs->search_string[i];
170 /*LOG (GNUNET_ERROR_TYPE_DEBUG,
171 "search %u %u: %s %p\n",
172 i,
173 cs->con_num,
174 cs->search_string[i],
175 cs->search_string);
176 fprintf (stderr,
177 line);*/
178 if (NULL != strstr (line,
179 search_string))
180 // "Delivering backchannel message from 4TTC to F7B5 of type 1460 to udp"))
181 // cs->search_string[i]))
182 {
183 cs->received_backchannel_msgs++;
184 LOG (GNUNET_ERROR_TYPE_DEBUG,
185 "received_backchannel_msgs %u con_num %u\n",
186 cs->received_backchannel_msgs,
187 cs->con_num);
188 if (cs->received_backchannel_msgs == cs->con_num)
189 {
190 LOG (GNUNET_ERROR_TYPE_DEBUG,
191 "search finished %lu %lu %u\n",
192 strlen (cs->search_string[i]),
193 strlen (
194 "Delivering backchannel message from 4TTC to F7B5 of type 1460 to udp"),
195 strcmp (
196 "Delivering backchannel message from 4TTC to F7B5 of type 1460 to udp",
197 cs->search_string[i]));
198 if (NULL != strstr (line,
199 cs->search_string[i]))
200 {
201 LOG (GNUNET_ERROR_TYPE_DEBUG,
202 "gaga\n");
203 }
204 cs->finished = GNUNET_YES;
205 fclose (cs->stream);
206 return;
207 }
208 }
209 }
210 }
211 LOG (GNUNET_ERROR_TYPE_DEBUG,
212 "read_from_log end\n");
213 fclose (cs->stream);
214 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
215 &read_from_log,
216 cs);
217 /*if (NULL == fgets (line, MAX_LINE_LENGTH, cs->stream))
218 {
219 LOG (GNUNET_ERROR_TYPE_DEBUG,
220 "read null\n");
221 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
222 &read_from_log,
223 cs);
224 return;
225 }*/
226 /*else {
227 cs->task =
228 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
229 cs->fh,
230 &read_from_log,
231 cs);
232
233
234 }*/
235}
236
237
238static enum GNUNET_GenericReturnValue
239will_the_other_node_connect_via_udp (
240 struct CheckState *cs,
241 const struct GNUNET_TESTING_NetjailNode *node)
242// struct GNUNET_TESTING_NodeConnection *connection)
243{
244 // struct GNUNET_TESTING_NetjailTopology *topology = cs->topology;
245 // unsigned int node_n = connection->node_n;
246 // unsigned int namespace_n = connection->namespace_n;
247 // struct GNUNET_HashCode hc;
248 // struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
249 // struct GNUNET_HashCode hc_namespace;
250 /*struct GNUNET_ShortHashCode *key_namespace = GNUNET_new (struct
251 GNUNET_ShortHashCode);*/
252 // struct GNUNET_TESTING_NetjailNode *node;
253 struct GNUNET_TESTING_NodeConnection *pos_connection;
254 struct GNUNET_TESTING_AddressPrefix *pos_prefix;
255 // struct GNUNET_TESTING_NetjailNamespace *namespace;
256 // struct GNUNET_CONTAINER_MultiShortmap *map;
257
258 /* if (0 == connection->namespace_n) */
259 /* { */
260 /* map = topology->map_globals; */
261 /* } */
262 /* else */
263 /* { */
264 /* GNUNET_CRYPTO_hash (&namespace_n, sizeof(namespace_n), &hc_namespace); */
265 /* memcpy (key_namespace, */
266 /* &hc_namespace, */
267 /* sizeof (*key_namespace)); */
268 /* if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains ( */
269 /* topology->map_namespaces, */
270 /* key_namespace)) */
271 /* { */
272 /* namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces, */
273 /* key_namespace); */
274 /* map = namespace->nodes; */
275 /* } */
276 /* else */
277 /* GNUNET_assert (0); */
278 /* } */
279
280 /* GNUNET_CRYPTO_hash (&node_n, sizeof(node_n), &hc); */
281 /* memcpy (key, */
282 /* &hc, */
283 /* sizeof (*key)); */
284 /* if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains ( */
285 /* map, */
286 /* key)) */
287 /* { */
288 /* node = GNUNET_CONTAINER_multishortmap_get (cs->topology->map_globals, */
289 /* key); */
290 /* for (pos_connection = node->node_connections_head; NULL != pos_connection; */
291 /* pos_connection = pos_connection->next) */
292 /* { */
293 /* if ((node->namespace_n == pos_connection->namespace_n) && */
294 /* (node->node_n == pos_connection->node_n) ) */
295 /* { */
296 /* for (pos_prefix = pos_connection->address_prefixes_head; NULL != */
297 /* pos_prefix; */
298 /* pos_prefix = */
299 /* pos_prefix->next) */
300 /* { */
301 /* if (0 == strcmp (UDP, pos_prefix->address_prefix)) */
302 /* { */
303 /* return GNUNET_YES; */
304 /* } */
305 /* } */
306 /* } */
307 /* } */
308 /* } */
309
310 for (pos_connection = node->node_connections_head; NULL != pos_connection;
311 pos_connection = pos_connection->next)
312 {
313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
314 "connect via udp %u %u %u %u\n",
315 node->namespace_n,
316 cs->namespace_n,
317 node->node_n,
318 cs->node_n);
319 if ((pos_connection->namespace_n == cs->namespace_n) &&
320 (pos_connection->node_n == cs->node_n) )
321 {
322 for (pos_prefix = pos_connection->address_prefixes_head; NULL !=
323 pos_prefix;
324 pos_prefix =
325 pos_prefix->next)
326 {
327 if (0 == strcmp (UDP, pos_prefix->address_prefix))
328 {
329 return GNUNET_YES;
330 }
331 }
332 }
333 }
334
335 return GNUNET_NO;
336}
337
338static void
339add_search_string (struct CheckState *cs, const struct
340 GNUNET_TESTING_NetjailNode *node)
341{
342 unsigned int num;
343 struct GNUNET_PeerIdentity *peer;
344 struct GNUNET_PeerIdentity *us;
345 char *buf;
346 char *part_one = "Delivering backchannel message from ";
347 char *part_two = " to ";
348 char *part_three = " of type 1460 to udp";
349 char *peer_id;
350 char *us_id;
351
352 if (0 == node->namespace_n)
353 num = node->node_n;
354 else
355 num = (node->namespace_n - 1) * cs->topology->nodes_m + node->node_n
356 + cs->topology->nodes_x;
357
358 // num = GNUNET_TESTING_calculate_num (pos_connection, cs->topology);
359 peer = GNUNET_TESTING_get_pub_key (num, cs->tl_system);
360 LOG (GNUNET_ERROR_TYPE_DEBUG,
361 "peer: %s num %u\n",
362 GNUNET_i2s (peer),
363 num);
364 us = GNUNET_TESTING_get_pub_key (cs->num, cs->tl_system);
365 LOG (GNUNET_ERROR_TYPE_DEBUG,
366 "us: %s cs->num %d\n",
367 GNUNET_i2s (us),
368 cs->num);
369
370 GNUNET_asprintf (&peer_id,
371 "%s",
372 GNUNET_i2s (peer));
373 GNUNET_asprintf (&us_id,
374 "%s",
375 GNUNET_i2s (us));
376
377 if (0 < GNUNET_asprintf (&buf,
378 "%s%s%s%s%s",
379 part_one,
380 us_id,
381 part_two,
382 peer_id,
383 part_three))
384 {
385 GNUNET_array_append (cs->search_string,
386 cs->con_num,
387 buf);
388 /*LOG (GNUNET_ERROR_TYPE_DEBUG,
389 "con_num: %u search: %s %p\n",
390 cs->con_num,
391 cs->search_string[cs->con_num - 1],
392 cs->search_string);*/
393 }
394 else
395 GNUNET_assert (0);
396}
397
398
399/**
400 * The run method of this cmd will connect to peers.
401 *
402 */
403static void
404backchannel_check_run (void *cls,
405 const struct GNUNET_TESTING_Command *cmd,
406 struct GNUNET_TESTING_Interpreter *is)
407{
408 struct CheckState *cs = cls;
409 // char *buf;
410 // char *part_one = "Delivering backchannel message from ";
411 // char *part_two = " of type 1460 to udp";
412 const struct GNUNET_TESTING_Command *system_cmd;
413 struct GNUNET_TESTING_System *tl_system;
414 const struct GNUNET_TESTING_Command *peer1_cmd;
415 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
416 // struct GNUNET_PeerIdentity *peer;
417 // uint32_t num;
418 // struct GNUNET_TESTING_NodeConnection *pos_connection;
419 // unsigned int con_num = 0;
420 struct GNUNET_CONTAINER_MultiShortmapIterator *node_it;
421 struct GNUNET_CONTAINER_MultiShortmapIterator *namespace_it;
422 struct GNUNET_ShortHashCode node_key;
423 struct GNUNET_ShortHashCode namespace_key;
424 const struct GNUNET_TESTING_NetjailNode *node;
425 const struct GNUNET_TESTING_NetjailNamespace *namespace;
426
427 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (
428 cs->start_peer_label);
429 GNUNET_TRANSPORT_get_trait_application_handle_v2 (peer1_cmd,
430 &ah);
431
432 system_cmd = GNUNET_TESTING_interpreter_lookup_command (cs->create_label);
433 GNUNET_TESTING_get_trait_test_system (system_cmd,
434 &tl_system);
435
436 cs->tl_system = tl_system;
437
438 cs->node_connections_head = GNUNET_TESTING_get_connections (cs->num,
439 cs->topology);
440
441 LOG (GNUNET_ERROR_TYPE_DEBUG,
442 "check run\n");
443
444
445 node_it = GNUNET_CONTAINER_multishortmap_iterator_create (
446 cs->topology->map_globals);
447
448 while (GNUNET_YES == GNUNET_CONTAINER_multishortmap_iterator_next (node_it,
449 &node_key,
450 (const
451 void**) &
452 node))
453 {
454 LOG (GNUNET_ERROR_TYPE_DEBUG,
455 "namespace_n %u node_n %u\n",
456 node->namespace_n,
457 node->node_n);
458 if (GNUNET_YES == will_the_other_node_connect_via_udp (cs, node))
459 {
460 add_search_string (cs, node);
461 }
462 }
463 namespace_it = GNUNET_CONTAINER_multishortmap_iterator_create (
464 cs->topology->map_namespaces);
465 while (GNUNET_YES == GNUNET_CONTAINER_multishortmap_iterator_next (
466 namespace_it,
467 &namespace_key,
468 (const
469 void**) &namespace))
470 {
471 LOG (GNUNET_ERROR_TYPE_DEBUG,
472 "namespace_n %u\n",
473 node->namespace_n);
474 node_it = GNUNET_CONTAINER_multishortmap_iterator_create (
475 namespace->nodes);
476 while (GNUNET_YES == GNUNET_CONTAINER_multishortmap_iterator_next (node_it,
477 &node_key,
478 (const
479 void**)
480 &node))
481 {
482 LOG (GNUNET_ERROR_TYPE_DEBUG,
483 "namespace_n %u node_n %u\n",
484 node->namespace_n,
485 node->node_n);
486 if (GNUNET_YES == will_the_other_node_connect_via_udp (cs, node))
487 {
488 add_search_string (cs, node);
489 }
490 }
491 }
492 /* for (pos_connection = cs->node_connections_head; NULL != pos_connection; */
493 /* pos_connection = pos_connection->next) */
494 /* { */
495
496 /* if (GNUNET_YES == will_the_other_node_connect_via_udp (cs, node)) */
497 /* { */
498 /* num = GNUNET_TESTING_calculate_num (pos_connection, cs->topology); */
499 /* peer = GNUNET_TESTING_get_pub_key (num, tl_system); */
500 /* LOG (GNUNET_ERROR_TYPE_DEBUG, */
501 /* "peer: %s\n", */
502 /* GNUNET_i2s (peer)); */
503
504 /* if (0 < GNUNET_asprintf (&buf, */
505 /* "%s%s%s", */
506 /* part_one, */
507 /* GNUNET_i2s (peer), */
508 /* part_two)) */
509 /* { */
510 /* GNUNET_array_append (cs->search_string, */
511 /* con_num, */
512 /* buf); */
513 /* /\*LOG (GNUNET_ERROR_TYPE_DEBUG, */
514 /* "con_num: %u search: %s %p\n", */
515 /* con_num, */
516 /* cs->search_string[con_num - 1], */
517 /* cs->search_string);*\/ */
518 /* } */
519 /* else */
520 /* GNUNET_assert (0); */
521 /* } */
522
523
524 /* } */
525 // cs->con_num = con_num;
526 if (0 != cs->con_num)
527 {
528 cs->task =
529 GNUNET_SCHEDULER_add_now (&read_from_log,
530 cs);
531 }
532 else
533 cs->finished = GNUNET_YES;
534
535}
536
537
538/**
539 * The finish function of this cmd will check if the peers we are trying to
540 * connect to are in the connected peers map of the start peer cmd for this peer.
541 *
542 */
543static int
544backchannel_check_finish (void *cls,
545 GNUNET_SCHEDULER_TaskCallback cont,
546 void *cont_cls)
547{
548 struct CheckState *cs = cls;
549
550 if (cs->finished)
551 {
552 cont (cont_cls);
553 }
554 return cs->finished;
555}
556
557
558/**
559 * Trait function of this cmd does nothing.
560 *
561 */
562static int
563backchannel_check_traits (void *cls,
564 const void **ret,
565 const char *trait,
566 unsigned int index)
567{
568 return GNUNET_OK;
569}
570
571
572/**
573 * The cleanup function of this cmd frees resources the cmd allocated.
574 *
575 */
576static void
577backchannel_check_cleanup (void *cls,
578 const struct GNUNET_TESTING_Command *cmd)
579{
580 struct ConnectPeersState *cs = cls;
581
582 GNUNET_free (cs);
583}
584
585
586/**
587 * Create command.
588 *
589 * @param label name for command.
590 * @param start_peer_label Label of the cmd to start a peer.
591 * @param create_label Label of the cmd to create the testing system.
592 * @param num Number globally identifying the node.
593 * @param node_n The number of the node in a network namespace.
594 * @param namespace_n The number of the network namespace.
595 * @param The topology for the test setup.
596 * @return command.
597 */
598struct GNUNET_TESTING_Command
599GNUNET_TRANSPORT_cmd_backchannel_check (const char *label,
600 const char *start_peer_label,
601 const char *create_label,
602 uint32_t num,
603 unsigned int node_n,
604 unsigned int namespace_n,
605 struct GNUNET_TESTING_NetjailTopology *
606 topology)
607{
608 struct CheckState *cs;
609
610 cs = GNUNET_new (struct CheckState);
611 cs->start_peer_label = start_peer_label;
612 cs->num = num;
613 cs->create_label = create_label;
614 cs->topology = topology;
615 cs->node_n = node_n;
616 cs->namespace_n = namespace_n;
617
618 struct GNUNET_TESTING_Command cmd = {
619 .cls = cs,
620 .label = label,
621 .run = &backchannel_check_run,
622 .finish = &backchannel_check_finish,
623 .cleanup = &backchannel_check_cleanup,
624 .traits = &backchannel_check_traits
625 };
626
627 return cmd;
628}
diff --git a/src/transport/transport_api_cmd_connecting_peers.c b/src/transport/transport_api_cmd_connecting_peers.c
index 09ca9e54c..39c7db450 100644
--- a/src/transport/transport_api_cmd_connecting_peers.c
+++ b/src/transport/transport_api_cmd_connecting_peers.c
@@ -91,7 +91,7 @@ connect_peers_run (void *cls,
91 char *hello; 91 char *hello;
92 // size_t *hello_size; 92 // size_t *hello_size;
93 enum GNUNET_NetworkType nt = 0; 93 enum GNUNET_NetworkType nt = 0;
94 char *peer_id; 94 // char *peer_id;
95 struct GNUNET_PeerIdentity *id; 95 struct GNUNET_PeerIdentity *id;
96 struct GNUNET_PeerIdentity *other = GNUNET_new (struct GNUNET_PeerIdentity); 96 struct GNUNET_PeerIdentity *other = GNUNET_new (struct GNUNET_PeerIdentity);
97 uint32_t num; 97 uint32_t num;
@@ -122,12 +122,12 @@ connect_peers_run (void *cls,
122 if (2 == num) 122 if (2 == num)
123 { 123 {
124 addr = "tcp-192.168.15.2:60002"; 124 addr = "tcp-192.168.15.2:60002";
125 peer_id = "F2F3X9G1YNCTXKK7A4J6M4ZM4BBSKC9DEXZVHCWQ475M0C7PNWCG"; 125 // peer_id = "F2F3X9G1YNCTXKK7A4J6M4ZM4BBSKC9DEXZVHCWQ475M0C7PNWCG";
126 } 126 }
127 else 127 else
128 { 128 {
129 addr = "tcp-192.168.15.1:60002"; 129 addr = "tcp-192.168.15.1:60002";
130 peer_id = "4TTC9WBSVP9RJT6DVEZ7E0TDW7TQXC11NR1EMR2F8ARS87WZ2730"; 130 // peer_id = "4TTC9WBSVP9RJT6DVEZ7E0TDW7TQXC11NR1EMR2F8ARS87WZ2730";
131 } 131 }
132 132
133 priv_key = GNUNET_TESTING_hostkey_get (tl_system, 133 priv_key = GNUNET_TESTING_hostkey_get (tl_system,
@@ -137,16 +137,16 @@ connect_peers_run (void *cls,
137 GNUNET_CRYPTO_eddsa_key_get_public (priv_key, 137 GNUNET_CRYPTO_eddsa_key_get_public (priv_key,
138 pub_key); 138 pub_key);
139 139
140 GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id, 140 /*GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
141 strlen (peer_id), 141 strlen (peer_id),
142 &peer->public_key); 142 &peer->public_key);*/
143 143
144 peer->public_key = *pub_key; 144 peer->public_key = *pub_key;
145 145
146 LOG (GNUNET_ERROR_TYPE_ERROR, 146 LOG (GNUNET_ERROR_TYPE_ERROR,
147 "\nnum: %u\n peer_id: %s\n pub_key %s\n", 147 "num: %u id: %s pub_key %s\n",
148 num, 148 num,
149 peer_id, 149 GNUNET_i2s_full (id),
150 GNUNET_CRYPTO_eddsa_public_key_to_string (pub_key)); 150 GNUNET_CRYPTO_eddsa_public_key_to_string (pub_key));
151 151
152 cps->id = peer; 152 cps->id = peer;
diff --git a/src/transport/transport_api_cmd_connecting_peers_v3.c b/src/transport/transport_api_cmd_connecting_peers_v3.c
index e90781637..2273d9852 100644
--- a/src/transport/transport_api_cmd_connecting_peers_v3.c
+++ b/src/transport/transport_api_cmd_connecting_peers_v3.c
@@ -36,22 +36,6 @@
36 */ 36 */
37#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) 37#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
38 38
39#define CONNECT_ADDRESS_TEMPLATE_TCP "tcp-192.168.15.%u:60002"
40
41#define CONNECT_ADDRESS_TEMPLATE_UDP "udp-192.168.15.%u:60002"
42
43#define ROUTER_CONNECT_ADDRESS_TEMPLATE_TCP "tcp-92.68.150.%u:60002"
44
45#define ROUTER_CONNECT_ADDRESS_TEMPLATE_UDP "udp-92.68.150.%u:60002"
46
47#define GLOBAL_CONNECT_ADDRESS_TEMPLATE_TCP "tcp-92.68.151.%u:60002"
48
49#define GLOBAL_CONNECT_ADDRESS_TEMPLATE_UDP "udp-92.68.151.%u:60002"
50
51#define PREFIX_TCP "tcp"
52
53#define PREFIX_UDP "udp"
54
55/** 39/**
56 * Struct to store information needed in callbacks. 40 * Struct to store information needed in callbacks.
57 * 41 *
@@ -101,222 +85,6 @@ struct ConnectPeersState
101}; 85};
102 86
103 87
104static struct GNUNET_PeerIdentity *
105get_pub_key (unsigned int num, struct GNUNET_TESTING_System *tl_system)
106{
107 struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity);
108 struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct
109 GNUNET_CRYPTO_EddsaPublicKey);
110 struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct
111 GNUNET_CRYPTO_EddsaPrivateKey);
112
113 priv_key = GNUNET_TESTING_hostkey_get (tl_system,
114 num,
115 peer);
116
117 GNUNET_CRYPTO_eddsa_key_get_public (priv_key,
118 pub_key);
119 peer->public_key = *pub_key;
120 return peer;
121}
122
123
124static int
125log_nodes (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
126{
127 struct GNUNET_TESTING_NetjailNode *node = value;
128 struct GNUNET_TESTING_NodeConnection *pos_connection;
129 struct GNUNET_TESTING_ADDRESS_PREFIX *pos_prefix;
130
131 LOG (GNUNET_ERROR_TYPE_ERROR,
132 "plugin: %s space: %u node: %u global: %u\n",
133 node->plugin,
134 node->namespace_n,
135 node->node_n,
136 node->is_global);
137
138 for (pos_connection = node->node_connections_head; NULL != pos_connection;
139 pos_connection = pos_connection->next)
140 {
141
142 LOG (GNUNET_ERROR_TYPE_ERROR,
143 "namespace_n: %u node_n: %u node_type: %u\n",
144 pos_connection->namespace_n,
145 pos_connection->node_n,
146 pos_connection->node_type);
147
148 for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
149 pos_prefix =
150 pos_prefix->next)
151 {
152 LOG (GNUNET_ERROR_TYPE_ERROR,
153 "prefix: %s\n",
154 pos_prefix->address_prefix);
155 }
156 }
157 return GNUNET_YES;
158}
159
160
161static int
162log_namespaces (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
163{
164 struct GNUNET_TESTING_NetjailNamespace *namespace = value;
165 struct GNUNET_TESTING_NetjailRouter *router = namespace->router;
166
167 LOG (GNUNET_ERROR_TYPE_ERROR,
168 "router_tcp: %u router_udp: %u spaces: %u\n",
169 router->tcp_port,
170 router->udp_port,
171 namespace->namespace_n);
172 GNUNET_CONTAINER_multishortmap_iterate (namespace->nodes, &log_nodes, NULL);
173 return GNUNET_YES;
174}
175
176
177static int
178log_topo (struct GNUNET_TESTING_NetjailTopology *topology)
179{
180 LOG (GNUNET_ERROR_TYPE_ERROR,
181 "plugin: %s spaces: %u nodes: %u known: %u\n",
182 topology->plugin,
183 topology->namespaces_n,
184 topology->nodes_m,
185 topology->nodes_x);
186
187 GNUNET_CONTAINER_multishortmap_iterate (topology->map_namespaces,
188 log_namespaces, NULL);
189 GNUNET_CONTAINER_multishortmap_iterate (topology->map_globals, &log_nodes,
190 NULL);
191 return GNUNET_YES;
192}
193
194
195static struct GNUNET_TESTING_NodeConnection *
196get_connections (unsigned int num, struct
197 GNUNET_TESTING_NetjailTopology *topology)
198{
199 struct GNUNET_TESTING_NetjailNode *node;
200 struct GNUNET_ShortHashCode *hkey;
201 struct GNUNET_HashCode hc;
202 struct GNUNET_TESTING_NetjailNamespace *namespace;
203 unsigned int namespace_n, node_m;
204
205 log_topo (topology);
206
207 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
208 if (topology->nodes_x >= num)
209 {
210
211 GNUNET_CRYPTO_hash (&num, sizeof(num), &hc);
212 memcpy (hkey,
213 &hc,
214 sizeof (*hkey));
215 node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals,
216 hkey);
217 }
218 else
219 {
220 namespace_n = (unsigned int) floor ((num - topology->nodes_x)
221 / topology->nodes_m);
222 LOG (GNUNET_ERROR_TYPE_ERROR,
223 "num: %u nodes_x: %u nodes_m: %u namespace_n: %u\n",
224 num,
225 topology->nodes_x,
226 topology->nodes_m,
227 namespace_n);
228 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
229 GNUNET_CRYPTO_hash (&namespace_n, sizeof(namespace_n), &hc);
230 memcpy (hkey,
231 &hc,
232 sizeof (*hkey));
233 namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces,
234 hkey);
235 node_m = num - topology->nodes_x - topology->nodes_m * (namespace_n - 1);
236 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
237 GNUNET_CRYPTO_hash (&node_m, sizeof(node_m), &hc);
238 memcpy (hkey,
239 &hc,
240 sizeof (*hkey));
241 node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
242 hkey);
243 }
244
245
246 return node->node_connections_head;
247}
248
249
250static unsigned int
251calculate_num (struct GNUNET_TESTING_NodeConnection *node_connection,
252 struct GNUNET_TESTING_NetjailTopology *topology)
253{
254 unsigned int n, m, num;
255
256 n = node_connection->namespace_n;
257 m = node_connection->node_n;
258
259 if (0 == n)
260 num = m;
261 else
262 num = (n - 1) * topology->nodes_m + m + topology->nodes_x;
263
264 return num;
265}
266
267static char *
268get_address (struct GNUNET_TESTING_NodeConnection *connection,
269 char *prefix)
270{
271 struct GNUNET_TESTING_NetjailNode *node;
272 char *addr;
273
274 node = connection->node;
275 if (connection->namespace_n == node->namespace_n)
276 {
277 if (0 == strcmp (PREFIX_TCP, prefix))
278 {
279
280 GNUNET_asprintf (&addr,
281 CONNECT_ADDRESS_TEMPLATE_TCP,
282 connection->node_n);
283 }
284 else if (0 == strcmp (PREFIX_UDP, prefix))
285 {
286 GNUNET_asprintf (&addr,
287 CONNECT_ADDRESS_TEMPLATE_UDP,
288 connection->node_n);
289 }
290 else
291 {
292 GNUNET_break (0);
293 }
294 }
295 else
296 {
297 if (0 == strcmp (PREFIX_TCP, prefix))
298 {
299
300 GNUNET_asprintf (&addr,
301 ROUTER_CONNECT_ADDRESS_TEMPLATE_TCP,
302 connection->namespace_n);
303 }
304 else if (0 == strcmp (PREFIX_UDP, prefix))
305 {
306 GNUNET_asprintf (&addr,
307 ROUTER_CONNECT_ADDRESS_TEMPLATE_UDP,
308 connection->namespace_n);
309 }
310 else
311 {
312 GNUNET_break (0);
313 }
314 }
315
316 return addr;
317}
318
319
320/** 88/**
321 * The run method of this cmd will connect to peers. 89 * The run method of this cmd will connect to peers.
322 * 90 *
@@ -338,7 +106,7 @@ connect_peers_run (void *cls,
338 enum GNUNET_NetworkType nt = 0; 106 enum GNUNET_NetworkType nt = 0;
339 uint32_t num; 107 uint32_t num;
340 struct GNUNET_TESTING_NodeConnection *pos_connection; 108 struct GNUNET_TESTING_NodeConnection *pos_connection;
341 struct GNUNET_TESTING_ADDRESS_PREFIX *pos_prefix; 109 struct GNUNET_TESTING_AddressPrefix *pos_prefix;
342 unsigned int con_num = 0; 110 unsigned int con_num = 0;
343 111
344 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label); 112 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label);
@@ -351,13 +119,14 @@ connect_peers_run (void *cls,
351 119
352 cps->tl_system = tl_system; 120 cps->tl_system = tl_system;
353 121
354 cps->node_connections_head = get_connections (cps->num, cps->topology); 122 cps->node_connections_head = GNUNET_TESTING_get_connections (cps->num,
123 cps->topology);
355 124
356 for (pos_connection = cps->node_connections_head; NULL != pos_connection; 125 for (pos_connection = cps->node_connections_head; NULL != pos_connection;
357 pos_connection = pos_connection->next) 126 pos_connection = pos_connection->next)
358 { 127 {
359 con_num++; 128 con_num++;
360 num = calculate_num (pos_connection, cps->topology); 129 num = GNUNET_TESTING_calculate_num (pos_connection, cps->topology);
361 for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix; 130 for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
362 pos_prefix = 131 pos_prefix =
363 pos_prefix->next) 132 pos_prefix->next)
@@ -367,9 +136,10 @@ connect_peers_run (void *cls,
367 "prefix: %s\n", 136 "prefix: %s\n",
368 pos_prefix->address_prefix); 137 pos_prefix->address_prefix);
369 138
370 addr = get_address (pos_connection, pos_prefix->address_prefix); 139 addr = GNUNET_TESTING_get_address (pos_connection,
140 pos_prefix->address_prefix);
371 141
372 peer = get_pub_key (num, tl_system); 142 peer = GNUNET_TESTING_get_pub_key (num, tl_system);
373 143
374 LOG (GNUNET_ERROR_TYPE_ERROR, 144 LOG (GNUNET_ERROR_TYPE_ERROR,
375 "num: %u pub_key %s addr: %s\n", 145 "num: %u pub_key %s addr: %s\n",
@@ -417,8 +187,8 @@ connect_peers_finish (void *cls,
417 for (pos_connection = cps->node_connections_head; NULL != pos_connection; 187 for (pos_connection = cps->node_connections_head; NULL != pos_connection;
418 pos_connection = pos_connection->next) 188 pos_connection = pos_connection->next)
419 { 189 {
420 num = calculate_num (pos_connection, cps->topology); 190 num = GNUNET_TESTING_calculate_num (pos_connection, cps->topology);
421 peer = get_pub_key (num, cps->tl_system); 191 peer = GNUNET_TESTING_get_pub_key (num, cps->tl_system);
422 GNUNET_CRYPTO_hash (&(peer->public_key), sizeof(peer->public_key), &hc); 192 GNUNET_CRYPTO_hash (&(peer->public_key), sizeof(peer->public_key), &hc);
423 memcpy (key, 193 memcpy (key,
424 &hc, 194 &hc,
@@ -476,6 +246,9 @@ connect_peers_cleanup (void *cls,
476 * 246 *
477 * @param label name for command. 247 * @param label name for command.
478 * @param start_peer_label Label of the cmd to start a peer. 248 * @param start_peer_label Label of the cmd to start a peer.
249 * @param create_label Label of the cmd to create the testing system.
250 * @param num Number globally identifying the node.
251 * @param The topology for the test setup.
479 * @return command. 252 * @return command.
480 */ 253 */
481struct GNUNET_TESTING_Command 254struct GNUNET_TESTING_Command
diff --git a/src/transport/transport_api_cmd_send_simple_v3.c b/src/transport/transport_api_cmd_send_simple_v3.c
new file mode 100644
index 000000000..a4ce2c4e9
--- /dev/null
+++ b/src/transport/transport_api_cmd_send_simple_v3.c
@@ -0,0 +1,194 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 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
21/**
22 * @file testing_api_cmd_start_peer.c
23 * @brief cmd to start a peer.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29#include "transport-testing2.h"
30#include "transport-testing-cmds.h"
31
32/**
33 * Struct to hold information for callbacks.
34 *
35 */
36struct SendSimpleState
37{
38 /**
39 * Number globally identifying the node.
40 *
41 */
42 uint32_t num;
43
44 /**
45 * Label of the cmd to start a peer.
46 *
47 */
48 const char *start_peer_label;
49
50 /**
51 * Label of the cmd which started the test system.
52 *
53 */
54 const char *create_label;
55
56 /**
57 * The topology we get the connected nodes from.
58 */
59 struct GNUNET_TESTING_NetjailTopology *topology;
60};
61
62
63/**
64 * Trait function of this cmd does nothing.
65 *
66 */
67static int
68send_simple_traits (void *cls,
69 const void **ret,
70 const char *trait,
71 unsigned int index)
72{
73 return GNUNET_OK;
74}
75
76
77/**
78 * The cleanup function of this cmd frees resources the cmd allocated.
79 *
80 */
81static void
82send_simple_cleanup (void *cls,
83 const struct GNUNET_TESTING_Command *cmd)
84{
85 struct SendSimpleState *sss = cls;
86
87 GNUNET_free (sss);
88}
89
90
91/**
92 * The run method of this cmd will send a simple message to the connected peers.
93 *
94 */
95static void
96send_simple_run (void *cls,
97 const struct GNUNET_TESTING_Command *cmd,
98 struct GNUNET_TESTING_Interpreter *is)
99{
100 struct SendSimpleState *sss = cls;
101 struct GNUNET_MQ_Envelope *env;
102 struct GNUNET_TRANSPORT_TESTING_TestMessage *test;
103 struct GNUNET_MQ_Handle *mq;
104 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
105 const struct GNUNET_TESTING_Command *peer1_cmd;
106 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
107 struct GNUNET_HashCode hc;
108 struct GNUNET_TESTING_NodeConnection *node_connections_head;
109 struct GNUNET_PeerIdentity *peer;
110 struct GNUNET_CRYPTO_EddsaPublicKey public_key;
111 uint32_t num;
112 struct GNUNET_TESTING_NodeConnection *pos_connection;
113 const struct GNUNET_TESTING_Command *system_cmd;
114 struct GNUNET_TESTING_System *tl_system;
115
116 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->start_peer_label);
117 GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd,
118 &connected_peers_map);
119
120 system_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->create_label);
121 GNUNET_TESTING_get_trait_test_system (system_cmd,
122 &tl_system);
123
124 node_connections_head = GNUNET_TESTING_get_connections (sss->num,
125 sss->topology);
126
127 for (int i = 0; i < 1; i++)
128 {
129 for (pos_connection = node_connections_head; NULL != pos_connection;
130 pos_connection = pos_connection->next)
131 {
132 num = GNUNET_TESTING_calculate_num (pos_connection, sss->topology);
133 peer = GNUNET_TESTING_get_pub_key (num, tl_system);
134 public_key = peer->public_key;
135 GNUNET_CRYPTO_hash (&public_key, sizeof(public_key), &hc);
136
137 memcpy (key,
138 &hc,
139 sizeof (*key));
140 mq = GNUNET_CONTAINER_multishortmap_get (connected_peers_map,
141 key);
142 env = GNUNET_MQ_msg_extra (test,
143 1000 - sizeof(*test),
144 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE);
145 test->num = htonl (sss->num);
146 memset (&test[1],
147 sss->num,
148 1000 - sizeof(*test));
149 GNUNET_MQ_send (mq,
150 env);
151 }
152 }
153
154 GNUNET_free (key);
155
156}
157
158
159/**
160 * Create command.
161 *
162 * @param label name for command.
163 * @param start_peer_label Label of the cmd to start a peer.
164 * @param start_peer_label Label of the cmd which started the test system.
165 * @param num Number globally identifying the node.
166 * @param The topology for the test setup.
167 * @return command.
168 */
169struct GNUNET_TESTING_Command
170GNUNET_TRANSPORT_cmd_send_simple_v3 (const char *label,
171 const char *start_peer_label,
172 const char *create_label,
173 uint32_t num,
174 struct GNUNET_TESTING_NetjailTopology *
175 topology)
176{
177 struct SendSimpleState *sss;
178
179 sss = GNUNET_new (struct SendSimpleState);
180 sss->num = num;
181 sss->start_peer_label = start_peer_label;
182 sss->create_label = create_label;
183 sss->topology = topology;
184
185 struct GNUNET_TESTING_Command cmd = {
186 .cls = sss,
187 .label = label,
188 .run = &send_simple_run,
189 .cleanup = &send_simple_cleanup,
190 .traits = &send_simple_traits
191 };
192
193 return cmd;
194}