static struct GNUNET_SCHEDULER_Task *to_task;
+static struct GNUNET_SCHEDULER_Task *active_task;
+
static int queue_est = GNUNET_NO;
static struct GNUNET_PeerIdentity peer_id[NUM_PEERS];
#define BURST_PACKETS 5000
-#define BURST_RUNS 1
+#define FIXME_DEAD_BURST_RUNS 1
+
+#define TOTAL_ITERATIONS 10
+
+static unsigned int iterations_left = TOTAL_ITERATIONS;
#define SHORT_BURST_WINDOW \
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,2)
static struct GNUNET_TIME_Relative duration;
+
static void
communicator_available_cb (void *cls,
struct
static char*
make_payload (size_t payload_size)
{
- char *payload = GNUNET_malloc (payload_size);
struct GNUNET_TIME_Absolute ts;
struct GNUNET_TIME_AbsoluteNBO ts_n;
+ char *payload = GNUNET_malloc (payload_size);
+
GNUNET_assert (payload_size >= 8); // So that out timestamp fits
ts = GNUNET_TIME_absolute_get ();
ts_n = GNUNET_TIME_absolute_hton (ts);
static void
latency_timeout (void *cls)
{
+ to_task = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Latency too high. Test failed. (Phase: %d. Received: %lu\n",
phase, num_received);
ret = 2;
- to_task = NULL;
GNUNET_SCHEDULER_shutdown ();
}
{
char *payload;
- phase = TP_SIZE_CHECK;
- if (ack < 64000) // Leave some room for our protocol.
- {
- payload = make_payload (ack);
- GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc,
- payload,
- ack);
- GNUNET_free (payload);
- ack += 5;
- num_sent++;
- if (NULL == to_task)
- to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &latency_timeout,
- NULL);
- if (ack < 64000)
- GNUNET_SCHEDULER_add_now (&size_test, NULL);
- }
+ active_task = NULL;
+ GNUNET_assert (TP_SIZE_CHECK == phase);
+ if (ack >= 64000)
+ return; /* Leave some room for our protocol, so not 2^16 exactly */
+ payload = make_payload (ack);
+ GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc,
+ payload,
+ ack);
+ GNUNET_free (payload);
+ ack += 5;
+ num_sent++;
+ if (NULL == to_task)
+ to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &latency_timeout,
+ NULL);
+ if (ack < 64000)
+ active_task = GNUNET_SCHEDULER_add_now (&size_test,
+ NULL);
}
{
char *payload;
- if (num_sent < BURST_PACKETS)
- {
- payload = make_payload (LONG_MESSAGE_SIZE);
- GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc,
- payload,
- LONG_MESSAGE_SIZE);
- num_sent++;
- GNUNET_free (payload);
- if (NULL == to_task)
- to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &latency_timeout,
- NULL);
-
- GNUNET_SCHEDULER_add_now (&long_test, NULL);
- // if (num_sent == BURST_PACKETS)
- // GNUNET_SCHEDULER_add_delayed (LONG_BURST_WINDOW,
- // &long_test, NULL);
+ active_task = NULL;
+ payload = make_payload (LONG_MESSAGE_SIZE);
+ GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc,
+ payload,
+ LONG_MESSAGE_SIZE);
+ num_sent++;
+ GNUNET_free (payload);
+ if (NULL == to_task)
+ to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &latency_timeout,
+ NULL);
+ if (num_sent == BURST_PACKETS)
return;
- }
+ active_task = GNUNET_SCHEDULER_add_now (&long_test,
+ NULL);
}
short_test (void *cls)
{
char *payload;
- if (num_sent < BURST_PACKETS)
- {
- payload = make_payload (SHORT_MESSAGE_SIZE);
- GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc,
- payload,
- SHORT_MESSAGE_SIZE);
- num_sent++;
- GNUNET_free (payload);
- if (NULL == to_task)
- to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &latency_timeout,
- NULL);
-
- GNUNET_SCHEDULER_add_now (&short_test, NULL);
- /*if (num_sent == BURST_PACKETS)
- {
- GNUNET_SCHEDULER_add_delayed (SHORT_BURST_WINDOW,
- &short_test, NULL);
- return;
- }*/}
+
+ active_task = NULL;
+ payload = make_payload (SHORT_MESSAGE_SIZE);
+ GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc,
+ payload,
+ SHORT_MESSAGE_SIZE);
+ num_sent++;
+ GNUNET_free (payload);
+ if (NULL == to_task)
+ to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &latency_timeout,
+ NULL);
+ if (num_sent >= BURST_PACKETS)
+ return;
+ active_task = GNUNET_SCHEDULER_add_now (&short_test,
+ NULL);
}
start_short = GNUNET_TIME_absolute_get ();
my_tc = tc_queue;
phase = TP_BURST_SHORT;
- GNUNET_SCHEDULER_add_now (&short_test, tc_queue);
+ GNUNET_assert (NULL == active_task);
+ active_task = GNUNET_SCHEDULER_add_now (&short_test,
+ NULL);
}
num_sent = 0;
avg_latency = 0;
num_received = 0;
- GNUNET_SCHEDULER_cancel (to_task);
- to_task = NULL;
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &long_test,
- NULL);
+ if (NULL != to_task)
+ {
+ GNUNET_SCHEDULER_cancel (to_task);
+ to_task = NULL;
+ }
+ active_task = GNUNET_SCHEDULER_add_now (&long_test,
+ NULL);
}
break;
}
num_received = 0;
num_sent = 0;
avg_latency = 0;
- GNUNET_SCHEDULER_cancel (to_task);
- to_task = NULL;
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &size_test,
- NULL);
+ if (NULL != to_task)
+ {
+ GNUNET_SCHEDULER_cancel (to_task);
+ to_task = NULL;
+ }
+ active_task = GNUNET_SCHEDULER_add_now (&size_test,
+ NULL);
}
break;
}
(unsigned long) num_received,
(unsigned long) num_sent,
(unsigned long long) avg_latency);
+ num_received = 0;
+ num_sent = 0;
+ avg_latency = 0;
+ if (NULL != to_task)
+ {
+ GNUNET_SCHEDULER_cancel (to_task);
+ to_task = NULL;
+ }
+ iterations_left--;
+ if (0 != iterations_left)
+ {
+ phase = TP_BURST_SHORT;
+ active_task = GNUNET_SCHEDULER_add_now (&short_test,
+ NULL);
+ break;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Finished\n");
- GNUNET_SCHEDULER_cancel (to_task);
- to_task = NULL;
GNUNET_SCHEDULER_shutdown ();
- // Finished!
- // }
}
break;
}
}
- // Reset timeout
+ /* Reset timeout */
if (NULL != to_task)
{
GNUNET_SCHEDULER_cancel (to_task);
}
+static void
+do_shutdown (void *cls)
+{
+ if (NULL != to_task)
+ {
+ GNUNET_SCHEDULER_cancel (to_task);
+ to_task = NULL;
+ }
+ if (NULL != active_task)
+ {
+ GNUNET_SCHEDULER_cancel (active_task);
+ active_task = NULL;
+ }
+}
+
+
/**
* @brief Main function called by the scheduler
*
&incoming_message_cb,
cfg_peers_name[i]); /* cls */
}
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
}
ret = 1;
communicator_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
- GNUNET_asprintf (&communicator_binary, "gnunet-communicator-%s",
+ GNUNET_asprintf (&communicator_binary,
+ "gnunet-communicator-%s",
communicator_name);
- if (GNUNET_OK != GNUNET_log_setup ("test_communicator_basic",
- "DEBUG",
- "test_communicator_basic.log"))
+ if (GNUNET_OK !=
+ GNUNET_log_setup ("test_communicator_basic",
+ "DEBUG",
+ NULL))
{
fprintf (stderr, "Unable to setup log\n");
GNUNET_break (0);
{
struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
struct GNUNET_MessageHeader *msg;
- msg = (struct GNUNET_MessageHeader *)&inc_msg[1];
+ msg = (struct GNUNET_MessageHeader *) &inc_msg[1];
size_t payload_len = ntohs (msg->size) - sizeof (struct
- GNUNET_MessageHeader);
+ GNUNET_MessageHeader);
if (NULL != tc_h->incoming_msg_cb)
{
struct GNUNET_MQ_Handle *mq)
{
struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
- struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue_iter;
LOG (GNUNET_ERROR_TYPE_DEBUG, "Client connected.\n");
tc_h->client = client;
if (NULL == tc_h->queue_head)
return tc_h;
/* Iterate over queues. They are yet to be opened. Request opening. */
- while (NULL != (tc_queue_iter = tc_h->queue_head))
+ for (struct
+ GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue_iter =
+ tc_h->queue_head;
+ NULL != tc_queue_iter;
+ tc_queue_iter = tc_queue_iter->next)
{
if (NULL == tc_queue_iter->open_queue_env)
continue;
/* Send the previously created mq envelope to request the creation of the
* queue. */
- GNUNET_MQ_send (tc_h->c_mq, tc_queue_iter->open_queue_env);
+ GNUNET_MQ_send (tc_h->c_mq,
+ tc_queue_iter->open_queue_env);
tc_queue_iter->open_queue_env = NULL;
}
return tc_h;
tc_h->client = NULL;
}
+
/**
* Message was transmitted. Process the request.
*
{
struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
GNUNET_SERVICE_client_continue (tc_h->client);
- //NOP
+ // NOP
}
-
/**
* @brief Start the communicator part of the transport service
*
tc_h->sh = GNUNET_SERVICE_start ("transport",
- tc_h->cfg,
- &connect_cb,
- &disconnect_cb,
- tc_h,
- mh);
+ tc_h->cfg,
+ &connect_cb,
+ &disconnect_cb,
+ tc_h,
+ mh);
GNUNET_assert (NULL != tc_h->sh);
}
GNUNET_OS_process_destroy (proc);
}
+
static void
shutdown_communicator (void *cls)
{
struct GNUNET_OS_Process *proc = cls;
- shutdown_process(proc);
+ shutdown_process (proc);
}
GNUNET_free (binary);
}
+
/**
* @brief Task run at shutdown to kill communicator and clean up
*
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);
+ 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!");
}
-
static void
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);
+ shutdown_communicator (tc_h->c_proc);
+ shutdown_service (tc_h->sh);
+ shutdown_nat (tc_h->nat_proc);
}
return tc_h;
}
+
/**
* @brief Instruct communicator to open a queue
*
memcpy (&msg[1], mh, inbox_size);
GNUNET_free (mh);
GNUNET_MQ_send (tc_queue->tc_h->c_mq, env);
+ // GNUNET_assert (0); // FIXME: not iplemented!
return tc_t;
}