/*
This file is part of GNUnet.
- (C) 2009, 2010 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2009, 2010, 2011, 2016 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
*/
/**
* @file transport/test_quota_compliance.c
* @brief base test case for transport implementations
*
- * This test case tests quota compliance both on core and transport level
+ * This test case tests quota compliance both on transport level
*/
#include "platform.h"
-#include "gnunet_common.h"
-#include "gnunet_hello_lib.h"
-#include "gnunet_getopt_lib.h"
-#include "gnunet_os_lib.h"
-#include "gnunet_program_lib.h"
-#include "gnunet_scheduler_lib.h"
-#include "gnunet_server_lib.h"
#include "gnunet_transport_service.h"
-#include "transport.h"
-
-#define VERBOSE GNUNET_YES
-
-#define VERBOSE_ARM GNUNET_NO
-
-#define START_ARM GNUNET_YES
-
-/**
- * Note that this value must not significantly exceed
- * 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise
- * messages may be dropped even for a reliable transport.
- */
-#define TOTAL_MSGS (10000 * 2)
-
-#define MEASUREMENT_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
-#define MEASUREMENT_MSG_SIZE 1024
-#define MEASUREMENT_MSG_SIZE_BIG 32768
+#include "gnunet_ats_service.h"
+#include "gauger.h"
+#include "transport-testing.h"
/**
* Testcase timeout
*/
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 200)
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 480)
+#define DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 80)
-#define MTYPE 11111
-struct PeerContext
-{
- struct GNUNET_CONFIGURATION_Handle *cfg;
- struct GNUNET_TRANSPORT_Handle *th;
- struct GNUNET_PeerIdentity id;
-#if START_ARM
- pid_t arm_pid;
-#endif
-};
-
-static struct PeerContext p1;
-
-static struct PeerContext p2;
+static struct GNUNET_SCHEDULER_Task *measure_task;
-static struct GNUNET_SCHEDULER_Handle *sched;
+static char *gen_cfgs[2];
-static int ok;
+static unsigned long long quota_in[] = { 10000, 10000 };
-static int connected;
+static unsigned long long quota_out[] = { 10000, 10000 };
-static unsigned long long total_bytes;
-static unsigned long long current_quota_p1;
-static unsigned long long current_quota_p2;
-
-static struct GNUNET_TIME_Absolute start_time;
+static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
-static GNUNET_SCHEDULER_TaskIdentifier die_task;
-static GNUNET_SCHEDULER_TaskIdentifier measurement_task;
-static int msg_scheduled;
-static int msg_sent;
-static int msg_recv_expected;
-static int msg_recv;
+/**
+ * Note that this value must not significantly exceed
+ * 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise
+ * messages may be dropped even for a reliable transport.
+ */
+#define TOTAL_MSGS (1024 * 32)
+static unsigned long long total_bytes_recv;
-#if VERBOSE
-#define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0)
-#else
-#define OKPP do { ok++; } while (0)
-#endif
+static struct GNUNET_TIME_Absolute start_time;
static void
-end ()
+report ()
{
unsigned long long delta;
-
- GNUNET_SCHEDULER_cancel (sched, die_task);
- die_task = GNUNET_SCHEDULER_NO_TASK;
-#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n");
-#endif
- GNUNET_TRANSPORT_disconnect (p1.th);
- GNUNET_TRANSPORT_disconnect (p2.th);
-#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transports disconnected, returning success!\n");
-#endif
- delta = GNUNET_TIME_absolute_get_duration (start_time).value;
- fprintf (stderr,
- "\nThroughput was %llu kb/s\n",
- total_bytes * 1000 / 1024 / delta);
- ok = 0;
-
+ unsigned long long datarate;
+
+ delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us;
+ datarate = (total_bytes_recv * 1000 * 1000) / delta;
+
+ FPRINTF (stderr,
+ "Throughput was %llu b/s\n",
+ datarate);
+ ccc->global_ret = GNUNET_OK;
+ if (datarate > 1.1 * quota_in[1])
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Datarate of %llu b/s significantly higher than allowed inbound quota of %llu b/s\n",
+ datarate,
+ quota_in[1]);
+ ccc->global_ret = GNUNET_SYSERR;
+ }
+ if (datarate > 1.1 * quota_out[0])
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Datarate of %llu b/s significantly higher than allowed outbound quota of %llu b/s\n",
+ datarate,
+ quota_out[0]);
+ ccc->global_ret = GNUNET_SYSERR;
+ }
+ if (GNUNET_OK == ccc->global_ret)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Datarate of %llu b/s complied to allowed outbound quota of %llu b/s and inbound quota of %llu b/s\n",
+ datarate,
+ quota_out[0],
+ quota_in[1]);
+ }
}
-
static void
-stop_arm (struct PeerContext *p)
+custom_shutdown (void *cls)
{
-#if START_ARM
- if (0 != PLIBC_KILL (p->arm_pid, SIGTERM))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- GNUNET_OS_process_wait (p->arm_pid);
-#endif
- GNUNET_CONFIGURATION_destroy (p->cfg);
+ if (NULL != measure_task)
+ {
+ GNUNET_SCHEDULER_cancel (measure_task);
+ measure_task = NULL;
+ }
+ report ();
}
-static void
-end_badly (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "end_badly \n ");
- GNUNET_break (0);
- if (p1.th != NULL)
- GNUNET_TRANSPORT_disconnect (p1.th);
- if (p2.th != NULL)
- GNUNET_TRANSPORT_disconnect (p2.th);
- ok = 1;
-}
-
-struct TestMessage
-{
- struct GNUNET_MessageHeader header;
- uint32_t num;
-};
-
-
-static unsigned int
+static size_t
get_size (unsigned int iter)
{
- unsigned int ret;
+ size_t ret;
- if (iter < 60000)
- return iter + sizeof (struct TestMessage);
- ret = (iter * iter * iter);
- return sizeof (struct TestMessage) + (ret % 60000);
+ ret = (iter * iter * iter) % 60000;
+ ret += sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage);
+ return ret;
}
-static unsigned int
-get_size_new (unsigned int iter)
-{
- return MEASUREMENT_MSG_SIZE + sizeof (struct TestMessage);
-}
static void
notify_receive (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message,
- struct GNUNET_TIME_Relative latency,
- uint32_t distance)
+ struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
+ const struct GNUNET_PeerIdentity *sender,
+ const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr)
{
- static int n;
- unsigned int s;
- char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
- const struct TestMessage *hdr;
-
- hdr = (const struct TestMessage*) message;
- s = get_size (n);
- if (MTYPE != ntohs (message->type))
- return;
- msg_recv_expected = n;
- msg_recv = ntohl(hdr->num);
- if (ntohs (message->size) != s)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected message %u of size %u, got %u bytes of message %u\n",
- n, s,
- ntohs (message->size),
- ntohl (hdr->num));
- GNUNET_SCHEDULER_cancel (sched, die_task);
- die_task = GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL);
- return;
- }
- if (ntohl (hdr->num) != n)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected message %u of size %u, got %u bytes of message %u\n",
- n, s,
- ntohs (message->size),
- ntohl (hdr->num));
- GNUNET_SCHEDULER_cancel (sched, die_task);
- die_task = GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL);
- return;
- }
- memset (cbuf, n, s - sizeof (struct TestMessage));
- if (0 != memcmp (cbuf,
- &hdr[1],
- s - sizeof (struct TestMessage)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected message %u with bits %u, but body did not match\n",
- n, (unsigned char) n);
- GNUNET_SCHEDULER_cancel (sched, die_task);
- die_task = GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL);
- return;
- }
-#if VERBOSE
- if (ntohl(hdr->num) % 5000 == 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got message %u of size %u\n",
- ntohl (hdr->num),
- ntohs (message->size));
- }
-#endif
- n++;
- if (0 == (n % (TOTAL_MSGS/100)))
- {
- fprintf (stderr, ".");
- GNUNET_SCHEDULER_cancel (sched, die_task);
- die_task = GNUNET_SCHEDULER_add_delayed (sched,
- TIMEOUT,
- &end_badly,
- NULL);
- }
- if (n == TOTAL_MSGS)
- end ();
-}
-static void
-notify_receive_new (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message,
- struct GNUNET_TIME_Relative latency,
- uint32_t distance)
-{
- static int n;
- unsigned int s;
- char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
- const struct TestMessage *hdr;
-
- hdr = (const struct TestMessage*) message;
- s = get_size_new (n);
- if (MTYPE != ntohs (message->type))
+ if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (hdr->header.type))
return;
- msg_recv_expected = n;
- msg_recv = ntohl(hdr->num);
- /*
- if (ntohs (message->size) != s)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected message %u of size %u, got %u bytes of message %u\n",
- n, s,
- ntohs (message->size),
- ntohl (hdr->num));
- GNUNET_SCHEDULER_cancel (sched, die_task);
- die_task = GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL);
- return;
- }
-
- if (ntohl (hdr->num) != n)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected message %u of size %u, got %u bytes of message %u\n",
- n, s,
- ntohs (message->size),
- ntohl (hdr->num));
- GNUNET_SCHEDULER_cancel (sched, die_task);
- die_task = GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL);
- return;
- }
- */
- /*
- memset (cbuf, n, s - sizeof (struct TestMessage));
- if (0 != memcmp (cbuf,
- &hdr[1],
- s - sizeof (struct TestMessage)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected message %u with bits %u, but body did not match\n",
- n, (unsigned char) n);
- GNUNET_SCHEDULER_cancel (sched, die_task);
- die_task = GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL);
- return;
- }
- */
-#if VERBOSE
- if (ntohl(hdr->num) % 5000 == 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got message %u of size %u\n",
- ntohl (hdr->num),
- ntohs (message->size));
- }
-#endif
- n++;
- if (0 == (n % (TOTAL_MSGS/100)))
- {
- fprintf (stderr, ".");
- GNUNET_SCHEDULER_cancel (sched, die_task);
- die_task = GNUNET_SCHEDULER_add_delayed (sched,
- TIMEOUT,
- &end_badly,
- NULL);
- }
-/*
- if (n == TOTAL_MSGS)
- end ();*/
-}
+ total_bytes_recv += ntohs (hdr->header.size);
-static size_t
-notify_ready (void *cls, size_t size, void *buf)
-{
- static int n;
- char *cbuf = buf;
- struct TestMessage hdr;
- unsigned int s;
- unsigned int ret;
-
- if (buf == NULL)
- {
- GNUNET_break (0);
- ok = 42;
- return 0;
- }
- ret = 0;
- s = get_size (n);
- GNUNET_assert (size >= s);
- GNUNET_assert (buf != NULL);
- cbuf = buf;
- do
- {
- hdr.header.size = htons (s);
- hdr.header.type = htons (MTYPE);
- hdr.num = htonl (n);
- msg_sent = n;
- memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage));
- ret += sizeof (struct TestMessage);
- memset (&cbuf[ret], n, s - sizeof (struct TestMessage));
- ret += s - sizeof (struct TestMessage);
-#if VERBOSE
- if (n % 5000 == 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending message %u of size %u\n",
- n,
- s);
- }
-#endif
- n++;
- s = get_size (n);
- if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
- break; /* sometimes pack buffer full, sometimes not */
- }
- while (size - ret >= s);
- if (n < TOTAL_MSGS)
{
- GNUNET_TRANSPORT_notify_transmit_ready (p2.th,
- &p1.id,
- s, 0, TIMEOUT,
- ¬ify_ready,
- NULL);
- msg_scheduled = n;
+ char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Peer %u (`%s') got message %u of size %u from peer (`%s')\n",
+ receiver->no,
+ ps,
+ ntohl (hdr->num),
+ ntohs (hdr->header.size),
+ GNUNET_i2s (sender));
+ GNUNET_free (ps);
}
- if (n % 5000 == 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Returning total message block of size %u\n",
- ret);
- }
- total_bytes += ret;
- return ret;
}
-static size_t
-notify_ready_new (void *cls, size_t size, void *buf)
-{
- static int n;
- char *cbuf = buf;
- struct TestMessage hdr;
- unsigned int s;
- unsigned int ret;
-
- if (buf == NULL)
- {
- GNUNET_break (0);
- ok = 42;
- return 0;
- }
- ret = 0;
- s = get_size_new (n);
- GNUNET_assert (size >= s);
- GNUNET_assert (buf != NULL);
- cbuf = buf;
- do
- {
- hdr.header.size = htons (s);
- hdr.header.type = htons (MTYPE);
- hdr.num = htonl (n);
- msg_sent = n;
- memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage));
- ret += sizeof (struct TestMessage);
- memset (&cbuf[ret], n, s - sizeof (struct TestMessage));
- ret += s - sizeof (struct TestMessage);
-#if VERBOSE
- if (n % 5000 == 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending message %u\n",n);
- }
-#endif
- n++;
- s = get_size_new (n);
- if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
- break; /* sometimes pack buffer full, sometimes not */
- }
- while (size - ret >= s);
- GNUNET_TRANSPORT_notify_transmit_ready (p2.th,
- &p1.id,
- s, 0, TIMEOUT,
- ¬ify_ready_new,
- NULL);
- msg_scheduled = n;
- total_bytes += ret;
- return ret;
-}
static void
-stop_measurement (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+measure (void *cls)
{
+ static int counter;
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "END OF MEASUREMENT %u bytes sent \n ", total_bytes);
-
- end();
-}
-
-
-static void measure ()
-{
-#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Both peers are connected, starting measurement...\n");
-#endif
- GNUNET_TRANSPORT_set_quota (p1.th,
- &p2.id,
- GNUNET_BANDWIDTH_value_init (current_quota_p1 ),
- GNUNET_BANDWIDTH_value_init (current_quota_p1 ),
- GNUNET_TIME_UNIT_FOREVER_REL,
- NULL, NULL);
- GNUNET_TRANSPORT_set_quota (p2.th,
- &p1.id,
- GNUNET_BANDWIDTH_value_init (current_quota_p2),
- GNUNET_BANDWIDTH_value_init (current_quota_p2),
- GNUNET_TIME_UNIT_FOREVER_REL,
- NULL, NULL);
- GNUNET_TRANSPORT_notify_transmit_ready (p2.th,
- &p1.id,
- get_size_new (0), 0, TIMEOUT,
- ¬ify_ready_new,
- NULL);
- measurement_task = GNUNET_SCHEDULER_add_delayed (sched,
- MEASUREMENT_INTERVALL,
- &stop_measurement,
- NULL);
- total_bytes = 0;
- start_time = GNUNET_TIME_absolute_get ();
-}
-
-static void
-notify_connect (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_TIME_Relative latency,
- uint32_t distance)
-{
-#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls);
-#endif
- if (cls == &p1)
- {
- connected++;
- }
- else
- {
- connected++;
- }
- if (connected == 2)
- {
- measure();
- }
+ measure_task = NULL;
+ counter++;
+ if ((DURATION.rel_value_us / 1000 / 1000LL) < counter)
+ {
+ FPRINTF (stderr, "%s", ".\n");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ FPRINTF (stderr, "%s", ".");
+ measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &measure,
+ NULL);
}
static void
-notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
+start_task (void *cls)
{
-#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer `%4s' disconnected (%p)!\n",
- GNUNET_i2s (peer), cls);
-#endif
-}
-
+ static struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
+ .num_messages = TOTAL_MSGS,
+ .get_size_cb = &get_size
+ };
-static void
-setup_peer (struct PeerContext *p, const char *cfgname)
-{
- p->cfg = GNUNET_CONFIGURATION_create ();
-#if START_ARM
- p->arm_pid = GNUNET_OS_start_process (NULL, NULL,
- "gnunet-service-arm",
- "gnunet-service-arm",
-#if VERBOSE_ARM
- "-L", "DEBUG",
-#endif
- "-c", cfgname, NULL);
-#endif
-
- GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
- p->th = GNUNET_TRANSPORT_connect (sched, p->cfg, NULL,
- p,
- ¬ify_receive_new,
- ¬ify_connect,
- ¬ify_disconnect);
- GNUNET_assert (p->th != NULL);
+ sc.ccc = ccc;
+ measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &measure,
+ NULL);
+ start_time = GNUNET_TIME_absolute_get ();
+ GNUNET_SCHEDULER_add_now (&GNUNET_TRANSPORT_TESTING_simple_send,
+ &sc);
}
-static void
-exchange_hello_last (void *cls,
- const struct GNUNET_MessageHeader *message)
+static char *
+generate_config (const char *cfg_file,
+ unsigned long long quota_in,
+ unsigned long long quota_out)
{
- struct PeerContext *me = cls;
+ char *in_name;
+ char *out_name;
+ char *fname = NULL;
+ struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create ();
- GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, me);
-
- GNUNET_assert (ok >= 3);
- OKPP;
- GNUNET_assert (message != NULL);
GNUNET_assert (GNUNET_OK ==
- GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
- message, &me->id));
- /* both HELLOs exchanged, get ready to test transmission! */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Finished exchanging HELLOs, now waiting for peers to connect!\n");
-}
-
-
-static void
-exchange_hello (void *cls,
- const struct GNUNET_MessageHeader *message)
-{
- struct PeerContext *me = cls;
-
- GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, me);
- GNUNET_assert (ok >= 2);
- OKPP;
- GNUNET_assert (message != NULL);
+ GNUNET_CONFIGURATION_load (cfg,
+ cfg_file));
+ GNUNET_asprintf (&fname,
+ "q_in_%llu_q_out_%llu_%s",
+ quota_in,
+ quota_out,
+ cfg_file);
+ GNUNET_CONFIGURATION_set_value_string (cfg,
+ "PATHS",
+ "DEFAULTCONFIG",
+ fname);
+ for (int c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
+ {
+ GNUNET_asprintf (&in_name,
+ "%s_QUOTA_IN",
+ GNUNET_ATS_print_network_type (c));
+ GNUNET_asprintf (&out_name,
+ "%s_QUOTA_OUT",
+ GNUNET_ATS_print_network_type (c));
+ GNUNET_CONFIGURATION_set_value_number (cfg,
+ "ats",
+ in_name,
+ quota_in);
+ GNUNET_CONFIGURATION_set_value_number (cfg,
+ "ats",
+ out_name,
+ quota_out);
+ GNUNET_free (in_name);
+ GNUNET_free (out_name);
+ }
GNUNET_assert (GNUNET_OK ==
- GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
- message, &me->id));
- GNUNET_TRANSPORT_offer_hello (p2.th, message);
- GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2);
+ GNUNET_CONFIGURATION_write (cfg,
+ fname));
+ GNUNET_CONFIGURATION_destroy (cfg);
+ return fname;
}
-static void
-run (void *cls,
- struct GNUNET_SCHEDULER_Handle *s,
- char *const *args,
- const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- GNUNET_assert (ok == 1);
- OKPP;
- sched = s;
-
- die_task = GNUNET_SCHEDULER_add_delayed (sched,
- TIMEOUT,
- &end_badly,
- NULL);
- /* Setting initial quota for both peers */
- current_quota_p1 = 1024 * 1024 * 1024;
- current_quota_p2 = 1024 * 1024 * 1024;
+static int
+check (void *cls,
+ struct GNUNET_TRANSPORT_TESTING_Handle *tth_,
+ const char *test_plugin_,
+ const char *test_name_,
+ unsigned int num_peers,
+ char *cfg_files[])
+{
+ struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
+ .connect_continuation = &start_task,
+ .config_file = "test_quota_compliance_data.conf",
+ .rec = ¬ify_receive,
+ .nc = &GNUNET_TRANSPORT_TESTING_log_connect,
+ .nd = &GNUNET_TRANSPORT_TESTING_log_disconnect,
+ .shutdown_task = &custom_shutdown,
+ .timeout = TIMEOUT
+ };
+ ccc = &my_ccc;
- setup_peer (&p1, "test_quota_compliance_peer1.conf");
- setup_peer (&p2, "test_quota_compliance_peer2.conf");
+ if (NULL != strstr (test_name_,
+ "asymmetric"))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Running asymmetric test with sending peer unlimited, receiving peer (in/out): %llu/%llu b/s \n",
+ quota_in[1],
+ quota_out[1]);
+ quota_out[0] = 1024 * 1024 * 1024;
+ quota_in[0] = 1024 * 1024 * 1024;
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Running symmetric test with (in/out) %llu/%llu b/s \n",
+ quota_in[1],
+ quota_out[1]);
+ }
+ for (unsigned int i=0;i<2;i++)
+ {
+ gen_cfgs[i] = generate_config (cfg_files[i],
+ quota_in[i],
+ quota_out[i]);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Generated config file `%s'\n",
+ gen_cfgs[i]);
+ }
- GNUNET_assert(p1.th != NULL);
- GNUNET_assert(p2.th != NULL);
- GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1);
+ return GNUNET_TRANSPORT_TESTING_connect_check (&my_ccc,
+ tth_,
+ test_plugin_,
+ test_name_,
+ num_peers,
+ gen_cfgs);
}
+
int
-main (int argc, char *argv[])
+main (int argc,
+ char *argv[])
{
- int ret = 0;
-#ifdef MINGW
- return GNUNET_SYSERR;
-#endif
- GNUNET_log_setup ("test-quota-compliance",
-#if VERBOSE
- "DEBUG",
-#else
- "WARNING",
-#endif
- NULL);
- char *const argv1[] = { "test-quota-compliance",
- "-c",
- "test_quota_compliance_data.conf",
-#if VERBOSE
- "-L", "DEBUG",
-#endif
- NULL
- };
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_OPTION_END
- };
-
- ok = 1;
- GNUNET_PROGRAM_run ((sizeof (argv1) / sizeof (char *)) - 1,
- argv1, "test-quota-compliance", "nohelp",
- options, &run, &ok);
- ret = ok;
-
- stop_arm (&p1);
- stop_arm (&p2);
- GNUNET_DISK_directory_remove ("/tmp/test_quota_compliance_peer1");
- GNUNET_DISK_directory_remove ("/tmp/test_quota_compliance_peer2");
- return ret;
+ if (GNUNET_OK !=
+ GNUNET_TRANSPORT_TESTING_main (2,
+ &check,
+ NULL))
+ {
+ GNUNET_break (0);
+ return 1;
+ }
+ for (unsigned int i=0;i<2;i++)
+ {
+ if ( (NULL != gen_cfgs[i]) &&
+ (GNUNET_YES == GNUNET_DISK_file_test (gen_cfgs[i])) )
+ {
+ GNUNET_DISK_directory_remove (gen_cfgs[i]);
+ GNUNET_free (gen_cfgs[i]);
+ }
+ }
+ return 0;
}
+
/* end of test_quota_compliance.c */