[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r13373 - gnunet/src/transport
From: |
gnunet |
Subject: |
[GNUnet-SVN] r13373 - gnunet/src/transport |
Date: |
Fri, 22 Oct 2010 16:51:29 +0200 |
Author: wachs
Date: 2010-10-22 16:51:29 +0200 (Fri, 22 Oct 2010)
New Revision: 13373
Modified:
gnunet/src/transport/test_quota_compliance.c
Log:
Modified: gnunet/src/transport/test_quota_compliance.c
===================================================================
--- gnunet/src/transport/test_quota_compliance.c 2010-10-22 14:28:51 UTC
(rev 13372)
+++ gnunet/src/transport/test_quota_compliance.c 2010-10-22 14:51:29 UTC
(rev 13373)
@@ -91,13 +91,10 @@
static GNUNET_SCHEDULER_TaskIdentifier die_task;
static GNUNET_SCHEDULER_TaskIdentifier measurement_task;
+static GNUNET_SCHEDULER_TaskIdentifier measurement_counter_task;
-static int msg_scheduled;
-static int msg_sent;
-static int msg_recv_expected;
-static int msg_recv;
+struct GNUNET_TRANSPORT_TransmitHandle * transmit_handle;
-
#if VERBOSE
#define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok,
__FILE__, __LINE__); } while (0)
#else
@@ -108,10 +105,20 @@
static void
end ()
{
- unsigned long long delta;
-
GNUNET_SCHEDULER_cancel (sched, die_task);
die_task = GNUNET_SCHEDULER_NO_TASK;
+
+ if (measurement_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (sched, measurement_task);
+ measurement_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (sched, measurement_counter_task);
+ measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n");
#endif
@@ -121,10 +128,6 @@
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;
}
@@ -147,9 +150,16 @@
end_badly (void *cls,
const struct GNUNET_SCHEDULER_TaskContext *tc)
{
-
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "end_badly \n ");
+ if (measurement_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (sched, measurement_task);
+ measurement_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (sched, measurement_counter_task);
+ measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_break (0);
if (p1.th != NULL)
GNUNET_TRANSPORT_disconnect (p1.th);
@@ -164,19 +174,7 @@
uint32_t num;
};
-
static unsigned int
-get_size (unsigned int iter)
-{
- unsigned int ret;
-
- if (iter < 60000)
- return iter + sizeof (struct TestMessage);
- ret = (iter * iter * iter);
- return sizeof (struct TestMessage) + (ret % 60000);
-}
-
-static unsigned int
get_size_new (unsigned int iter)
{
return MEASUREMENT_MSG_SIZE + sizeof (struct TestMessage);
@@ -191,54 +189,12 @@
{
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))
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 DEBUG_MEASUREMENT
if (ntohl(hdr->num) % 5000 == 0)
{
@@ -249,12 +205,6 @@
}
#endif
n++;
-
-
- if (0 == (n % (TOTAL_MSGS/10)))
- {
- fprintf (stderr, ".");
- }
}
static size_t
@@ -266,6 +216,8 @@
unsigned int s;
unsigned int ret;
+ transmit_handle = NULL;
+
if (buf == NULL)
{
GNUNET_break (0);
@@ -282,7 +234,6 @@
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));
@@ -300,23 +251,53 @@
break; /* sometimes pack buffer full, sometimes not */
}
while (size - ret >= s);
- GNUNET_TRANSPORT_notify_transmit_ready (p2.th,
+ transmit_handle = GNUNET_TRANSPORT_notify_transmit_ready (p2.th,
&p1.id,
s, 0, TIMEOUT,
¬ify_ready_new,
NULL);
- msg_scheduled = n;
total_bytes += s;
return ret;
}
static void measure (unsigned long long quota_p1, unsigned long long quota_p2
);
+static void measurement_counter
+ (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
+
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ return;
+#if VERBOSE
+ fprintf(stderr,".");
+#endif
+ measurement_counter_task = GNUNET_SCHEDULER_add_delayed (sched,
+
GNUNET_TIME_UNIT_SECONDS,
+ &measurement_counter,
+ NULL);
+}
+
static void
-stop_measurement (void *cls,
+measurement_end (void *cls,
const struct GNUNET_SCHEDULER_TaskContext *tc)
{
+ measurement_task = GNUNET_SCHEDULER_NO_TASK;
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ return;
+
struct GNUNET_TIME_Relative duration =
GNUNET_TIME_absolute_get_difference(start_time, GNUNET_TIME_absolute_get());
+
+ if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (sched, measurement_counter_task);
+ measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+/*
+ if (transmit_handle != NULL)
+ GNUNET_TRANSPORT_notify_transmit_ready_cancel(transmit_handle);
+*/
fprintf (stderr, "\n");
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Measurement finished: \n Quota allowed: %llu kb/s\n
Throughput: %llu kb/s\n", (current_quota_p1 / (1024)) ,
(total_bytes/(duration.value / 1000)/1024));
@@ -326,7 +307,6 @@
measure (current_quota_p1/100, current_quota_p2/100);
}
-
static void measure (unsigned long long quota_p1, unsigned long long quota_p2 )
{
current_quota_p1 = quota_p1;
@@ -335,36 +315,41 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Starting measurement: Duration: %u Quota: %u\n",
MEASUREMENT_INTERVALL, current_quota_p1);
#endif
-
- GNUNET_TRANSPORT_set_quota (p1.th,
+ 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,
+ 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);
+ transmit_handle =GNUNET_TRANSPORT_notify_transmit_ready (p2.th,
+
&p1.id,
+
get_size_new (0), 0, TIMEOUT,
+
¬ify_ready_new,
+
NULL);
- GNUNET_SCHEDULER_cancel (sched, die_task);
- die_task = GNUNET_SCHEDULER_add_delayed (sched,
- TIMEOUT,
- &end_badly,
- NULL);
- measurement_task = GNUNET_SCHEDULER_add_delayed (sched,
- MEASUREMENT_INTERVALL,
- &stop_measurement,
- NULL);
- total_bytes = 0;
- start_time = GNUNET_TIME_absolute_get ();
+ GNUNET_SCHEDULER_cancel (sched, die_task);
+ die_task = GNUNET_SCHEDULER_add_delayed (sched,
+ TIMEOUT,
+ &end_badly,
+ NULL);
+ if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (sched, measurement_counter_task);
+ measurement_counter_task = GNUNET_SCHEDULER_add_delayed (sched,
+
GNUNET_TIME_UNIT_SECONDS,
+
&measurement_counter,
+ NULL);
+ measurement_task = GNUNET_SCHEDULER_add_delayed (sched,
+ MEASUREMENT_INTERVALL,
+ &measurement_end,
+ NULL);
+ total_bytes = 0;
+ start_time = GNUNET_TIME_absolute_get ();
}
static void
@@ -482,8 +467,8 @@
NULL);
/* Setting initial quota for both peers */
- current_quota_p1 = 1024 * 1024 * 1024;
- current_quota_p2 = 1024 * 1024 * 1024;
+// current_quota_p1 = 1024 * 1024 * 1024;
+// current_quota_p2 = 1024 * 1024 * 1024;
setup_peer (&p1, "test_quota_compliance_peer1.conf");
setup_peer (&p2, "test_quota_compliance_peer2.conf");
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r13373 - gnunet/src/transport,
gnunet <=