diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-10-25 09:04:43 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-10-25 09:04:43 +0000 |
commit | cc00a944fc56e23f02788f951ca3f3b7b6e0b50c (patch) | |
tree | b7db841b355a11659e25dea361e4d2f16d1007f7 /src/transport/test_quota_compliance.c | |
parent | f1f0ee0597c7c7d3d697e58f1f0d104b67b836db (diff) | |
download | gnunet-cc00a944fc56e23f02788f951ca3f3b7b6e0b50c.tar.gz gnunet-cc00a944fc56e23f02788f951ca3f3b7b6e0b50c.zip |
Diffstat (limited to 'src/transport/test_quota_compliance.c')
-rw-r--r-- | src/transport/test_quota_compliance.c | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/src/transport/test_quota_compliance.c b/src/transport/test_quota_compliance.c index b516ac4ed..018324a4e 100644 --- a/src/transport/test_quota_compliance.c +++ b/src/transport/test_quota_compliance.c | |||
@@ -82,6 +82,9 @@ static struct GNUNET_SCHEDULER_Handle *sched; | |||
82 | static int ok; | 82 | static int ok; |
83 | 83 | ||
84 | static int connected; | 84 | static int connected; |
85 | static int measurement_running; | ||
86 | static int send_running; | ||
87 | static int recv_running; | ||
85 | 88 | ||
86 | static unsigned long long total_bytes; | 89 | static unsigned long long total_bytes; |
87 | static unsigned long long current_quota_p1; | 90 | static unsigned long long current_quota_p1; |
@@ -226,6 +229,10 @@ notify_ready_new (void *cls, size_t size, void *buf) | |||
226 | ok = 42; | 229 | ok = 42; |
227 | return 0; | 230 | return 0; |
228 | } | 231 | } |
232 | |||
233 | if (measurement_running != GNUNET_YES) | ||
234 | return 0; | ||
235 | |||
229 | ret = 0; | 236 | ret = 0; |
230 | s = get_size_new (n); | 237 | s = get_size_new (n); |
231 | GNUNET_assert (size >= s); | 238 | GNUNET_assert (size >= s); |
@@ -290,6 +297,7 @@ measurement_end (void *cls, | |||
290 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 297 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
291 | return; | 298 | return; |
292 | 299 | ||
300 | measurement_running = GNUNET_NO; | ||
293 | struct GNUNET_TIME_Relative duration = GNUNET_TIME_absolute_get_difference(start_time, GNUNET_TIME_absolute_get()); | 301 | struct GNUNET_TIME_Relative duration = GNUNET_TIME_absolute_get_difference(start_time, GNUNET_TIME_absolute_get()); |
294 | 302 | ||
295 | if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK) | 303 | if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK) |
@@ -297,17 +305,14 @@ measurement_end (void *cls, | |||
297 | GNUNET_SCHEDULER_cancel (sched, measurement_counter_task); | 305 | GNUNET_SCHEDULER_cancel (sched, measurement_counter_task); |
298 | measurement_counter_task = GNUNET_SCHEDULER_NO_TASK; | 306 | measurement_counter_task = GNUNET_SCHEDULER_NO_TASK; |
299 | } | 307 | } |
300 | 308 | #if VERBOSE | |
309 | fprintf(stderr,"\n"); | ||
310 | #endif | ||
301 | if (transmit_handle != NULL) | 311 | if (transmit_handle != NULL) |
302 | { | 312 | { |
303 | GNUNET_TRANSPORT_notify_transmit_ready_cancel(transmit_handle); | 313 | GNUNET_TRANSPORT_notify_transmit_ready_cancel(transmit_handle); |
304 | transmit_handle = NULL; | 314 | transmit_handle = NULL; |
305 | } | 315 | } |
306 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
307 | "\nQuota compliance ok: \n"\ | ||
308 | "Quota allowed: %10llu kb/s\n"\ | ||
309 | "Throughput : %10llu kb/s\n", (current_quota_p1 / (1024)) , (total_bytes/(duration.value / 1000)/1024)); | ||
310 | |||
311 | if (current_quota_p1 < total_bytes/(duration.value / 1000)) | 316 | if (current_quota_p1 < total_bytes/(duration.value / 1000)) |
312 | { | 317 | { |
313 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 318 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -320,6 +325,11 @@ measurement_end (void *cls, | |||
320 | } | 325 | } |
321 | else | 326 | else |
322 | { | 327 | { |
328 | |||
329 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
330 | "\nQuota compliance ok: \n"\ | ||
331 | "Quota allowed: %10llu kb/s\n"\ | ||
332 | "Throughput : %10llu kb/s\n", (current_quota_p1 / (1024)) , (total_bytes/(duration.value / 1000)/1024)); | ||
323 | ok = 0; | 333 | ok = 0; |
324 | } | 334 | } |
325 | if (current_quota_p1 < (MEASUREMENT_MIN_QUOTA)) | 335 | if (current_quota_p1 < (MEASUREMENT_MIN_QUOTA)) |
@@ -349,15 +359,6 @@ static void measure (unsigned long long quota_p1, unsigned long long quota_p2 ) | |||
349 | GNUNET_TIME_UNIT_FOREVER_REL, | 359 | GNUNET_TIME_UNIT_FOREVER_REL, |
350 | NULL, NULL); | 360 | NULL, NULL); |
351 | 361 | ||
352 | if (transmit_handle != NULL) | ||
353 | GNUNET_TRANSPORT_notify_transmit_ready_cancel(transmit_handle); | ||
354 | |||
355 | transmit_handle = GNUNET_TRANSPORT_notify_transmit_ready (p2.th, | ||
356 | &p1.id, | ||
357 | get_size_new (0), 0, TIMEOUT, | ||
358 | ¬ify_ready_new, | ||
359 | NULL); | ||
360 | |||
361 | GNUNET_SCHEDULER_cancel (sched, die_task); | 362 | GNUNET_SCHEDULER_cancel (sched, die_task); |
362 | die_task = GNUNET_SCHEDULER_add_delayed (sched, | 363 | die_task = GNUNET_SCHEDULER_add_delayed (sched, |
363 | TIMEOUT, | 364 | TIMEOUT, |
@@ -374,7 +375,17 @@ static void measure (unsigned long long quota_p1, unsigned long long quota_p2 ) | |||
374 | &measurement_end, | 375 | &measurement_end, |
375 | NULL); | 376 | NULL); |
376 | total_bytes = 0; | 377 | total_bytes = 0; |
378 | measurement_running = GNUNET_YES; | ||
377 | start_time = GNUNET_TIME_absolute_get (); | 379 | start_time = GNUNET_TIME_absolute_get (); |
380 | |||
381 | if (transmit_handle != NULL) | ||
382 | GNUNET_TRANSPORT_notify_transmit_ready_cancel(transmit_handle); | ||
383 | |||
384 | transmit_handle = GNUNET_TRANSPORT_notify_transmit_ready (p2.th, | ||
385 | &p1.id, | ||
386 | get_size_new (0), 0, TIMEOUT, | ||
387 | ¬ify_ready_new, | ||
388 | NULL); | ||
378 | } | 389 | } |
379 | 390 | ||
380 | static void | 391 | static void |
@@ -490,10 +501,9 @@ run (void *cls, | |||
490 | TIMEOUT, | 501 | TIMEOUT, |
491 | &end_badly, | 502 | &end_badly, |
492 | NULL); | 503 | NULL); |
493 | 504 | measurement_running = GNUNET_NO; | |
494 | /* Setting initial quota for both peers */ | 505 | send_running = GNUNET_NO; |
495 | // current_quota_p1 = 1024 * 1024 * 1024; | 506 | recv_running = GNUNET_NO; |
496 | // current_quota_p2 = 1024 * 1024 * 1024; | ||
497 | 507 | ||
498 | setup_peer (&p1, "test_quota_compliance_peer1.conf"); | 508 | setup_peer (&p1, "test_quota_compliance_peer1.conf"); |
499 | setup_peer (&p2, "test_quota_compliance_peer2.conf"); | 509 | setup_peer (&p2, "test_quota_compliance_peer2.conf"); |