aboutsummaryrefslogtreecommitdiff
path: root/src/core/test_core_quota_compliance.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
commit5746309cb4be2073d550ad7a6885e918631dbc38 (patch)
tree89455bc4aadf977816b38df13f990372cd81d71a /src/core/test_core_quota_compliance.c
parent6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff)
downloadgnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz
gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip
indentation
Diffstat (limited to 'src/core/test_core_quota_compliance.c')
-rw-r--r--src/core/test_core_quota_compliance.c183
1 files changed, 73 insertions, 110 deletions
diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c
index 5dcc20597..88ba2c0f2 100644
--- a/src/core/test_core_quota_compliance.c
+++ b/src/core/test_core_quota_compliance.c
@@ -173,16 +173,15 @@ terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
173 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration 173 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
174 */ 174 */
175static int 175static int
176print_stat (void *cls, 176print_stat (void *cls, const char *subsystem, const char *name, uint64_t value,
177 const char *subsystem, 177 int is_persistent)
178 const char *name, uint64_t value, int is_persistent)
179{ 178{
180 if (cls == &p1) 179 if (cls == &p1)
181 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer1 %50s = %12llu\n", name,
182 "Peer1 %50s = %12llu\n", name, (unsigned long long) value); 181 (unsigned long long) value);
183 if (cls == &p2) 182 if (cls == &p2)
184 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 183 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer2 %50s = %12llu\n", name,
185 "Peer2 %50s = %12llu\n", name, (unsigned long long) value); 184 (unsigned long long) value);
186 return GNUNET_OK; 185 return GNUNET_OK;
187} 186}
188 187
@@ -225,38 +224,28 @@ measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
225 else 224 else
226 ok = 0; 225 ok = 0;
227 226
228 GNUNET_STATISTICS_get (p1.stats, 227 GNUNET_STATISTICS_get (p1.stats, "core", "# discarded CORE_SEND requests",
229 "core",
230 "# discarded CORE_SEND requests",
231 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1); 228 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1);
232 229
233 GNUNET_STATISTICS_get (p1.stats, 230 GNUNET_STATISTICS_get (p1.stats, "core",
234 "core",
235 "# discarded CORE_SEND request bytes", 231 "# discarded CORE_SEND request bytes",
236 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1); 232 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1);
237 GNUNET_STATISTICS_get (p1.stats, 233 GNUNET_STATISTICS_get (p1.stats, "core",
238 "core",
239 "# discarded lower priority CORE_SEND requests", 234 "# discarded lower priority CORE_SEND requests",
240 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, NULL); 235 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, NULL);
241 GNUNET_STATISTICS_get (p1.stats, 236 GNUNET_STATISTICS_get (p1.stats, "core",
242 "core",
243 "# discarded lower priority CORE_SEND request bytes", 237 "# discarded lower priority CORE_SEND request bytes",
244 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1); 238 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1);
245 GNUNET_STATISTICS_get (p2.stats, 239 GNUNET_STATISTICS_get (p2.stats, "core", "# discarded CORE_SEND requests",
246 "core",
247 "# discarded CORE_SEND requests",
248 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2); 240 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2);
249 241
250 GNUNET_STATISTICS_get (p2.stats, 242 GNUNET_STATISTICS_get (p2.stats, "core",
251 "core",
252 "# discarded CORE_SEND request bytes", 243 "# discarded CORE_SEND request bytes",
253 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2); 244 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2);
254 GNUNET_STATISTICS_get (p2.stats, 245 GNUNET_STATISTICS_get (p2.stats, "core",
255 "core",
256 "# discarded lower priority CORE_SEND requests", 246 "# discarded lower priority CORE_SEND requests",
257 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2); 247 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2);
258 GNUNET_STATISTICS_get (p2.stats, 248 GNUNET_STATISTICS_get (p2.stats, "core",
259 "core",
260 "# discarded lower priority CORE_SEND request bytes", 249 "# discarded lower priority CORE_SEND request bytes",
261 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2); 250 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2);
262 251
@@ -312,11 +301,8 @@ transmit_ready (void *cls, size_t size, void *buf)
312 { 301 {
313 if ((p1.ch != NULL) && (p1.connect_status == 1)) 302 if ((p1.ch != NULL) && (p1.connect_status == 1))
314 GNUNET_break (NULL != 303 GNUNET_break (NULL !=
315 GNUNET_CORE_notify_transmit_ready (p1.ch, 304 GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0,
316 GNUNET_NO, 305 FAST_TIMEOUT, &p2.id,
317 0,
318 FAST_TIMEOUT,
319 &p2.id,
320 MESSAGESIZE, 306 MESSAGESIZE,
321 &transmit_ready, &p1)); 307 &transmit_ready, &p1));
322 return 0; 308 return 0;
@@ -330,8 +316,8 @@ transmit_ready (void *cls, size_t size, void *buf)
330 { 316 {
331#if DEBUG_TRANSMISSION 317#if DEBUG_TRANSMISSION
332 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 318 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
333 "Sending message %u of size %u at offset %u\n", 319 "Sending message %u of size %u at offset %u\n", tr_n,
334 tr_n, MESSAGESIZE, ret); 320 MESSAGESIZE, ret);
335#endif 321#endif
336 hdr.header.size = htons (MESSAGESIZE); 322 hdr.header.size = htons (MESSAGESIZE);
337 hdr.header.type = htons (MTYPE); 323 hdr.header.type = htons (MTYPE);
@@ -346,8 +332,8 @@ transmit_ready (void *cls, size_t size, void *buf)
346 } 332 }
347 while (size - ret >= MESSAGESIZE); 333 while (size - ret >= MESSAGESIZE);
348 GNUNET_SCHEDULER_cancel (err_task); 334 GNUNET_SCHEDULER_cancel (err_task);
349 err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 335 err_task =
350 &terminate_task_error, NULL); 336 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL);
351 337
352 total_bytes_sent += ret; 338 total_bytes_sent += ret;
353 return ret; 339 return ret;
@@ -356,8 +342,7 @@ transmit_ready (void *cls, size_t size, void *buf)
356 342
357 343
358static void 344static void
359connect_notify (void *cls, 345connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
360 const struct GNUNET_PeerIdentity *peer,
361 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 346 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
362{ 347{
363 struct PeerContext *pc = cls; 348 struct PeerContext *pc = cls;
@@ -378,22 +363,19 @@ connect_notify (void *cls,
378#endif 363#endif
379 if (err_task != GNUNET_SCHEDULER_NO_TASK) 364 if (err_task != GNUNET_SCHEDULER_NO_TASK)
380 GNUNET_SCHEDULER_cancel (err_task); 365 GNUNET_SCHEDULER_cancel (err_task);
381 err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 366 err_task =
382 &terminate_task_error, NULL); 367 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL);
383 start_time = GNUNET_TIME_absolute_get (); 368 start_time = GNUNET_TIME_absolute_get ();
384 running = GNUNET_YES; 369 running = GNUNET_YES;
385 measure_task = 370 measure_task =
386 GNUNET_SCHEDULER_add_delayed (MEASUREMENT_LENGTH, &measurement_stop, 371 GNUNET_SCHEDULER_add_delayed (MEASUREMENT_LENGTH, &measurement_stop,
387 NULL); 372 NULL);
388 373
389 GNUNET_break (NULL != GNUNET_CORE_notify_transmit_ready (p1.ch, 374 GNUNET_break (NULL !=
390 GNUNET_NO, 375 GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0,
391 0, 376 TIMEOUT, &p2.id,
392 TIMEOUT, 377 MESSAGESIZE,
393 &p2.id, 378 &transmit_ready, &p1));
394 MESSAGESIZE,
395 &transmit_ready,
396 &p1));
397 } 379 }
398} 380}
399 381
@@ -407,15 +389,14 @@ disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
407 return; 389 return;
408 pc->connect_status = 0; 390 pc->connect_status = 0;
409#if DEBUG_TRANSMISSION 391#if DEBUG_TRANSMISSION
410 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 392 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypted connection to `%4s' cut\n",
411 "Encrypted connection to `%4s' cut\n", GNUNET_i2s (peer)); 393 GNUNET_i2s (peer));
412#endif 394#endif
413} 395}
414 396
415 397
416static int 398static int
417inbound_notify (void *cls, 399inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
418 const struct GNUNET_PeerIdentity *other,
419 const struct GNUNET_MessageHeader *message, 400 const struct GNUNET_MessageHeader *message,
420 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 401 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
421{ 402{
@@ -430,8 +411,7 @@ inbound_notify (void *cls,
430 411
431 412
432static int 413static int
433outbound_notify (void *cls, 414outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
434 const struct GNUNET_PeerIdentity *other,
435 const struct GNUNET_MessageHeader *message, 415 const struct GNUNET_MessageHeader *message,
436 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 416 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
437{ 417{
@@ -447,8 +427,7 @@ outbound_notify (void *cls,
447static size_t transmit_ready (void *cls, size_t size, void *buf); 427static size_t transmit_ready (void *cls, size_t size, void *buf);
448 428
449static int 429static int
450process_mtype (void *cls, 430process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer,
451 const struct GNUNET_PeerIdentity *peer,
452 const struct GNUNET_MessageHeader *message, 431 const struct GNUNET_MessageHeader *message,
453 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 432 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
454{ 433{
@@ -477,8 +456,7 @@ process_mtype (void *cls,
477 return GNUNET_SYSERR; 456 return GNUNET_SYSERR;
478 } 457 }
479#if DEBUG_TRANSMISSION 458#if DEBUG_TRANSMISSION
480 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 459 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got message %u of size %u\n",
481 "Got message %u of size %u\n",
482 ntohl (hdr->num), ntohs (message->size)); 460 ntohl (hdr->num), ntohs (message->size));
483#endif 461#endif
484 n++; 462 n++;
@@ -488,11 +466,8 @@ process_mtype (void *cls,
488 466
489 if (running == GNUNET_YES) 467 if (running == GNUNET_YES)
490 GNUNET_break (NULL != 468 GNUNET_break (NULL !=
491 GNUNET_CORE_notify_transmit_ready (p1.ch, 469 GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0,
492 GNUNET_NO, 470 FAST_TIMEOUT, &p2.id,
493 0,
494 FAST_TIMEOUT,
495 &p2.id,
496 MESSAGESIZE, 471 MESSAGESIZE,
497 &transmit_ready, &p1)); 472 &transmit_ready, &p1));
498 return GNUNET_OK; 473 return GNUNET_OK;
@@ -507,8 +482,7 @@ static struct GNUNET_CORE_MessageHandler handlers[] = {
507 482
508 483
509static void 484static void
510init_notify (void *cls, 485init_notify (void *cls, struct GNUNET_CORE_Handle *server,
511 struct GNUNET_CORE_Handle *server,
512 const struct GNUNET_PeerIdentity *my_identity, 486 const struct GNUNET_PeerIdentity *my_identity,
513 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) 487 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
514{ 488{
@@ -525,14 +499,9 @@ init_notify (void *cls,
525 GNUNET_assert (ok == 2); 499 GNUNET_assert (ok == 2);
526 OKPP; 500 OKPP;
527 /* connect p2 */ 501 /* connect p2 */
528 GNUNET_CORE_connect (p2.cfg, 1, 502 GNUNET_CORE_connect (p2.cfg, 1, &p2, &init_notify, &connect_notify,
529 &p2, 503 &disconnect_notify, NULL, &inbound_notify, GNUNET_YES,
530 &init_notify, 504 &outbound_notify, GNUNET_YES, handlers);
531 &connect_notify,
532 &disconnect_notify,
533 NULL,
534 &inbound_notify,
535 GNUNET_YES, &outbound_notify, GNUNET_YES, handlers);
536 } 505 }
537 else 506 else
538 { 507 {
@@ -580,12 +549,13 @@ setup_peer (struct PeerContext *p, const char *cfgname)
580{ 549{
581 p->cfg = GNUNET_CONFIGURATION_create (); 550 p->cfg = GNUNET_CONFIGURATION_create ();
582#if START_ARM 551#if START_ARM
583 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 552 p->arm_proc =
584 "gnunet-service-arm", 553 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
554 "gnunet-service-arm",
585#if VERBOSE 555#if VERBOSE
586 "-L", "DEBUG", 556 "-L", "DEBUG",
587#endif 557#endif
588 "-c", cfgname, NULL); 558 "-c", cfgname, NULL);
589#endif 559#endif
590 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 560 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
591 p->stats = GNUNET_STATISTICS_create ("core", p->cfg); 561 p->stats = GNUNET_STATISTICS_create ("core", p->cfg);
@@ -597,14 +567,13 @@ setup_peer (struct PeerContext *p, const char *cfgname)
597 567
598 568
599static void 569static void
600run (void *cls, 570run (void *cls, char *const *args, const char *cfgfile,
601 char *const *args, 571 const struct GNUNET_CONFIGURATION_Handle *cfg)
602 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
603{ 572{
604 GNUNET_assert (ok == 1); 573 GNUNET_assert (ok == 1);
605 OKPP; 574 OKPP;
606 err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 575 err_task =
607 &terminate_task_error, NULL); 576 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL);
608 if (test == SYMMETRIC) 577 if (test == SYMMETRIC)
609 { 578 {
610 setup_peer (&p1, "test_core_quota_peer1.conf"); 579 setup_peer (&p1, "test_core_quota_peer1.conf");
@@ -622,31 +591,26 @@ run (void *cls,
622 } 591 }
623 592
624 GNUNET_assert (test != -1); 593 GNUNET_assert (test != -1);
625 GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p1.cfg, 594 GNUNET_assert (GNUNET_SYSERR !=
626 "CORE", 595 GNUNET_CONFIGURATION_get_value_number (p1.cfg, "CORE",
627 "TOTAL_QUOTA_IN", 596 "TOTAL_QUOTA_IN",
628 &current_quota_p1_in)); 597 &current_quota_p1_in));
629 GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p2.cfg, 598 GNUNET_assert (GNUNET_SYSERR !=
630 "CORE", 599 GNUNET_CONFIGURATION_get_value_number (p2.cfg, "CORE",
631 "TOTAL_QUOTA_IN", 600 "TOTAL_QUOTA_IN",
632 &current_quota_p2_in)); 601 &current_quota_p2_in));
633 GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p1.cfg, 602 GNUNET_assert (GNUNET_SYSERR !=
634 "CORE", 603 GNUNET_CONFIGURATION_get_value_number (p1.cfg, "CORE",
635 "TOTAL_QUOTA_OUT", 604 "TOTAL_QUOTA_OUT",
636 &current_quota_p1_out)); 605 &current_quota_p1_out));
637 GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p2.cfg, 606 GNUNET_assert (GNUNET_SYSERR !=
638 "CORE", 607 GNUNET_CONFIGURATION_get_value_number (p2.cfg, "CORE",
639 "TOTAL_QUOTA_OUT", 608 "TOTAL_QUOTA_OUT",
640 &current_quota_p2_out)); 609 &current_quota_p2_out));
641 610
642 GNUNET_CORE_connect (p1.cfg, 1, 611 GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify,
643 &p1, 612 &disconnect_notify, NULL, &inbound_notify, GNUNET_YES,
644 &init_notify, 613 &outbound_notify, GNUNET_YES, handlers);
645 &connect_notify,
646 &disconnect_notify,
647 NULL,
648 &inbound_notify,
649 GNUNET_YES, &outbound_notify, GNUNET_YES, handlers);
650} 614}
651 615
652 616
@@ -658,8 +622,7 @@ stop_arm (struct PeerContext *p)
658 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 622 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
659 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) 623 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
660 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 624 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
661 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 625 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
662 "ARM process %u stopped\n",
663 GNUNET_OS_process_get_pid (p->arm_proc)); 626 GNUNET_OS_process_get_pid (p->arm_proc));
664 GNUNET_OS_process_close (p->arm_proc); 627 GNUNET_OS_process_close (p->arm_proc);
665 p->arm_proc = NULL; 628 p->arm_proc = NULL;
@@ -684,9 +647,9 @@ check ()
684 GNUNET_GETOPT_OPTION_END 647 GNUNET_GETOPT_OPTION_END
685 }; 648 };
686 ok = 1; 649 ok = 1;
687 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 650 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
688 argv, "test-core-quota-compliance", "nohelp", options, 651 "test-core-quota-compliance", "nohelp", options, &run,
689 &run, &ok); 652 &ok);
690 stop_arm (&p1); 653 stop_arm (&p1);
691 stop_arm (&p2); 654 stop_arm (&p2);
692 return ok; 655 return ok;