From: Schanzenbach, Martin Date: Tue, 24 Dec 2019 13:44:15 +0000 (+0900) Subject: start nat for tcp X-Git-Tag: v0.12.1~7 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=5c5a31d18c22192922e7dac302e10a53135d3248;p=oweals%2Fgnunet.git start nat for tcp --- diff --git a/src/transport/test_communicator_basic.c b/src/transport/test_communicator_basic.c index d7622a2cc..ef91e133d 100644 --- a/src/transport/test_communicator_basic.c +++ b/src/transport/test_communicator_basic.c @@ -69,7 +69,7 @@ static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *my_tc; #define BURST_RUNS 1 #define SHORT_BURST_WINDOW \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,5) + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,2) #define LONG_BURST_WINDOW \ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,2) @@ -81,7 +81,7 @@ static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *my_tc; #define SIZE_CHECK 2 -static int num_sent = 0; +static size_t num_sent = 0; static uint32_t ack = 0; @@ -91,6 +91,8 @@ static size_t num_received = 0; static uint64_t avg_latency = 0; +static struct GNUNET_TIME_Relative duration; + static void communicator_available_cb (void *cls, struct @@ -187,18 +189,20 @@ size_test (void *cls) ack); GNUNET_free (payload); ack += 5; + num_sent++; if (ack < 64000) GNUNET_SCHEDULER_add_now (&size_test, NULL); else - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, + GNUNET_SCHEDULER_add_delayed (SHORT_BURST_WINDOW, &size_test, NULL); return; } GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "Size packet test done.\n"); GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, - "#packets: %lu -- latency: %lu microseconds\n", + "%lu/%lu packets -- avg latency: %lu us\n", num_received, + num_sent, avg_latency); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished\n"); @@ -210,8 +214,6 @@ size_test (void *cls) static void long_test (void *cls) { - struct GNUNET_TIME_Relative duration = GNUNET_TIME_absolute_get_duration ( - start_long); char *payload; if (num_sent < BURST_PACKETS) { @@ -228,13 +230,14 @@ long_test (void *cls) &long_test, NULL); return; } - duration = GNUNET_TIME_absolute_get_duration (start_long); GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "Long size packet test done.\n"); GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, - "goodput: %lu kb/s -- #packets: %lu -- latency: %lu microseconds\n", - (LONG_MESSAGE_SIZE * num_received) / (duration.rel_value_us / 1000), + "%lu/%lu packets in %lu us (%lu kb/s) -- avg latency: %lu us\n", num_received, + num_sent, + duration.rel_value_us, + (LONG_MESSAGE_SIZE * num_received) / (duration.rel_value_us / 1000), avg_latency); ack = 10; num_received = 0; @@ -247,9 +250,8 @@ long_test (void *cls) static void short_test (void *cls) { - struct GNUNET_TIME_Relative duration; char *payload; - if (num_sent < BURST_PACKETS) + while (num_sent < BURST_PACKETS) { payload = make_payload (SHORT_MESSAGE_SIZE); GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, @@ -257,20 +259,23 @@ short_test (void *cls) SHORT_MESSAGE_SIZE); num_sent++; GNUNET_free (payload); - if (num_sent < BURST_PACKETS) - GNUNET_SCHEDULER_add_now (&short_test, NULL); + //if (num_sent < BURST_PACKETS) + // GNUNET_SCHEDULER_add_now (&short_test, NULL); if (num_sent == BURST_PACKETS) + { GNUNET_SCHEDULER_add_delayed (SHORT_BURST_WINDOW, &short_test, NULL); - return; + return; + } } - duration = GNUNET_TIME_absolute_get_duration (start_short); GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "Short size packet test done.\n"); GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, - "goodput: %lu kb/s -- #packets: %lu -- latency: %lu microseconds\n", - (SHORT_MESSAGE_SIZE * num_received) / (duration.rel_value_us / 1000), + "%lu/%lu packets in %lu us (%lu kb/s) -- avg latency: %lu us\n", num_received, + num_sent, + duration.rel_value_us, + (SHORT_MESSAGE_SIZE * num_received) / (duration.rel_value_us / 1000), avg_latency); start_long = GNUNET_TIME_absolute_get (); phase = BURST_LONG; @@ -345,18 +350,28 @@ incoming_message_cb (void *cls, size_t payload_len) { if (0 != strcmp ((char*) cls, cfg_peers_name[NUM_PEERS - 1])) - return; // TODO? + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "unexpected receiver...\n"); + return; + } if (phase == BURST_SHORT) { GNUNET_assert (SHORT_MESSAGE_SIZE == payload_len); num_received++; + duration = GNUNET_TIME_absolute_get_duration (start_short); update_avg_latency (payload); } else if (phase == BURST_LONG) { if (LONG_MESSAGE_SIZE != payload_len) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Ignoring packet with wrong length\n"); return; // Ignore + } num_received++; + duration = GNUNET_TIME_absolute_get_duration (start_long); update_avg_latency (payload); } else // if (phase == SIZE_CHECK) { diff --git a/src/transport/transport-testing2.c b/src/transport/transport-testing2.c index ba58776fb..558bf007f 100644 --- a/src/transport/transport-testing2.c +++ b/src/transport/transport-testing2.c @@ -79,6 +79,11 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle */ struct GNUNET_OS_Process *c_proc; + /** + * NAT process + */ + struct GNUNET_OS_Process *nat_proc; + /** * @brief Task that will be run on shutdown to stop and clean communicator */ @@ -660,10 +665,8 @@ transport_communicator_start ( * @param cls Closure - Process of communicator */ static void -shutdown_communicator (void *cls) +shutdown_process (struct GNUNET_OS_Process *proc) { - struct GNUNET_OS_Process *proc = cls; - if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) { LOG (GNUNET_ERROR_TYPE_WARNING, @@ -677,6 +680,13 @@ shutdown_communicator (void *cls) GNUNET_OS_process_destroy (proc); } +static void +shutdown_communicator (void *cls) +{ + struct GNUNET_OS_Process *proc = cls; + shutdown_process(proc); +} + /** * @brief Start the communicator @@ -711,6 +721,51 @@ communicator_start ( GNUNET_free (binary); } +/** + * @brief Task run at shutdown to kill communicator and clean up + * + * @param cls Closure - Process of communicator + */ +static void +shutdown_nat (void *cls) +{ + struct GNUNET_OS_Process *proc = cls; + shutdown_process (proc); +} + + +/** + * @brief Start NAT + * + */ +static void +nat_start ( + struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h) +{ + char *binary; + + LOG (GNUNET_ERROR_TYPE_DEBUG, "nat_start\n"); + binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-nat"); + tc_h->nat_proc = GNUNET_OS_start_process (GNUNET_YES, + GNUNET_OS_INHERIT_STD_OUT_AND_ERR, + NULL, + NULL, + NULL, + binary, + "gnunet-service-nat", + "-c", + tc_h->cfg_filename, + NULL); + if (NULL == tc_h->nat_proc) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start NAT!"); + return; + } + LOG (GNUNET_ERROR_TYPE_INFO, "started NAT\n"); + GNUNET_free (binary); +} + + static void do_shutdown (void *cls) @@ -718,6 +773,7 @@ do_shutdown (void *cls) struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; shutdown_communicator(tc_h->c_proc); shutdown_service(tc_h->sh); + shutdown_nat(tc_h->nat_proc); } @@ -771,7 +827,8 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( /* Start communicator part of service */ transport_communicator_start (tc_h); - + /* Start NAT */ + nat_start (tc_h); /* Schedule start communicator */ communicator_start (tc_h, binary_name);