aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-08-05 22:07:52 +0000
committerChristian Grothoff <christian@grothoff.org>2016-08-05 22:07:52 +0000
commitbf25446f57eca4e3fb38ec68a100b575d8573cd0 (patch)
tree6ba705c38268214f87fa84e793f72b44f10db834 /src/core
parent319422c2d2ae7f88f931fae0bd0e7b1efe2ad68d (diff)
downloadgnunet-bf25446f57eca4e3fb38ec68a100b575d8573cd0.tar.gz
gnunet-bf25446f57eca4e3fb38ec68a100b575d8573cd0.zip
-convert quota test to MQ API
Diffstat (limited to 'src/core')
-rw-r--r--src/core/test_core_quota_compliance.c269
1 files changed, 78 insertions, 191 deletions
diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c
index 118347e88..31063b814 100644
--- a/src/core/test_core_quota_compliance.c
+++ b/src/core/test_core_quota_compliance.c
@@ -54,7 +54,7 @@
54#define FAST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 150) 54#define FAST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 150)
55 55
56#define MTYPE 12345 56#define MTYPE 12345
57#define MESSAGESIZE 1024 57#define MESSAGESIZE (1024 - 8)
58#define MEASUREMENT_LENGTH GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 58#define MEASUREMENT_LENGTH GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
59 59
60static unsigned long long total_bytes_sent; 60static unsigned long long total_bytes_sent;
@@ -71,7 +71,7 @@ struct PeerContext
71{ 71{
72 struct GNUNET_CONFIGURATION_Handle *cfg; 72 struct GNUNET_CONFIGURATION_Handle *cfg;
73 struct GNUNET_CORE_Handle *ch; 73 struct GNUNET_CORE_Handle *ch;
74 struct GNUNET_CORE_TransmitHandle *nth; 74 struct GNUNET_MQ_Handle *mq;
75 struct GNUNET_TRANSPORT_OfferHelloHandle *oh; 75 struct GNUNET_TRANSPORT_OfferHelloHandle *oh;
76 struct GNUNET_PeerIdentity id; 76 struct GNUNET_PeerIdentity id;
77 struct GNUNET_MessageHeader *hello; 77 struct GNUNET_MessageHeader *hello;
@@ -107,21 +107,17 @@ static int running;
107struct TestMessage 107struct TestMessage
108{ 108{
109 struct GNUNET_MessageHeader header; 109 struct GNUNET_MessageHeader header;
110 uint32_t num; 110 uint32_t num GNUNET_PACKED;
111 uint8_t pad[MESSAGESIZE];
111}; 112};
112 113
113 114
114static void 115static void
115terminate_peer (struct PeerContext *p) 116terminate_peer (struct PeerContext *p)
116{ 117{
117 if (NULL != p->nth)
118 {
119 GNUNET_CORE_notify_transmit_ready_cancel (p->nth);
120 p->nth = NULL;
121 }
122 if (NULL != p->ch) 118 if (NULL != p->ch)
123 { 119 {
124 GNUNET_CORE_disconnect (p->ch); 120 GNUNET_CORE_disconnecT (p->ch);
125 p->ch = NULL; 121 p->ch = NULL;
126 } 122 }
127 if (NULL != p->ghh) 123 if (NULL != p->ghh)
@@ -343,85 +339,44 @@ measurement_stop (void *cls)
343} 339}
344 340
345 341
346static size_t 342static void
347transmit_ready (void *cls, 343do_transmit (void *cls)
348 size_t size,
349 void *buf)
350{ 344{
351 char *cbuf = buf; 345 struct TestMessage *hdr;
352 struct TestMessage hdr; 346 struct GNUNET_MQ_Envelope *env;
353 unsigned int ret; 347
354 348 env = GNUNET_MQ_msg (hdr,
355 p1.nth = NULL; 349 MTYPE);
356 GNUNET_assert (size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE); 350 hdr->num = htonl (tr_n);
357 if (NULL == buf) 351 memset (&hdr->pad,
358 { 352 tr_n,
359 if ( (NULL != p1.ch) && 353 MESSAGESIZE);
360 (1 == p1.connect_status) ) 354 tr_n++;
361 GNUNET_break (NULL !=
362 (p1.nth =
363 GNUNET_CORE_notify_transmit_ready (p1.ch,
364 GNUNET_NO,
365 GNUNET_CORE_PRIO_BEST_EFFORT,
366 FAST_TIMEOUT,
367 &p2.id,
368 MESSAGESIZE,
369 &transmit_ready,
370 &p1)));
371 return 0;
372 }
373 GNUNET_assert (tr_n < TOTAL_MSGS);
374 ret = 0;
375 GNUNET_assert (size >= MESSAGESIZE);
376 GNUNET_assert (NULL != buf);
377 cbuf = buf;
378 do
379 {
380 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
381 "Sending message %u of size %u at offset %u\n",
382 tr_n,
383 MESSAGESIZE,
384 ret);
385 hdr.header.size = htons (MESSAGESIZE);
386 hdr.header.type = htons (MTYPE);
387 hdr.num = htonl (tr_n);
388 GNUNET_memcpy (&cbuf[ret],
389 &hdr,
390 sizeof (struct TestMessage));
391 ret += sizeof (struct TestMessage);
392 memset (&cbuf[ret],
393 tr_n,
394 MESSAGESIZE - sizeof (struct TestMessage));
395 ret += MESSAGESIZE - sizeof (struct TestMessage);
396 tr_n++;
397 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
398 16))
399 break; /* sometimes pack buffer full, sometimes not */
400 }
401 while (size - ret >= MESSAGESIZE);
402 GNUNET_SCHEDULER_cancel (err_task); 355 GNUNET_SCHEDULER_cancel (err_task);
403 err_task = 356 err_task =
404 GNUNET_SCHEDULER_add_delayed (TIMEOUT, 357 GNUNET_SCHEDULER_add_delayed (TIMEOUT,
405 &terminate_task_error, 358 &terminate_task_error,
406 NULL); 359 NULL);
407 360 total_bytes_sent += sizeof (struct TestMessage);
408 total_bytes_sent += ret; 361 GNUNET_MQ_send (p1.mq,
409 return ret; 362 env);
410} 363}
411 364
412 365
413static void 366static void *
414connect_notify (void *cls, 367connect_notify (void *cls,
415 const struct GNUNET_PeerIdentity *peer) 368 const struct GNUNET_PeerIdentity *peer,
369 struct GNUNET_MQ_Handle *mq)
416{ 370{
417 struct PeerContext *pc = cls; 371 struct PeerContext *pc = cls;
418 372
419 if (0 == memcmp (&pc->id, 373 if (0 == memcmp (&pc->id,
420 peer, 374 peer,
421 sizeof (struct GNUNET_PeerIdentity))) 375 sizeof (struct GNUNET_PeerIdentity)))
422 return; /* loopback */ 376 return NULL; /* loopback */
423 GNUNET_assert (0 == pc->connect_status); 377 GNUNET_assert (0 == pc->connect_status);
424 pc->connect_status = 1; 378 pc->connect_status = 1;
379 pc->mq = mq;
425 if (pc == &p1) 380 if (pc == &p1)
426 { 381 {
427 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 382 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -441,32 +396,23 @@ connect_notify (void *cls,
441 GNUNET_SCHEDULER_add_delayed (MEASUREMENT_LENGTH, 396 GNUNET_SCHEDULER_add_delayed (MEASUREMENT_LENGTH,
442 &measurement_stop, 397 &measurement_stop,
443 NULL); 398 NULL);
444 399 do_transmit (NULL);
445 GNUNET_break (NULL !=
446 (p1.nth =
447 GNUNET_CORE_notify_transmit_ready (p1.ch,
448 GNUNET_NO,
449 GNUNET_CORE_PRIO_BEST_EFFORT,
450 TIMEOUT,
451 &p2.id,
452 MESSAGESIZE,
453 &transmit_ready,
454 &p1)));
455 } 400 }
401 return pc;
456} 402}
457 403
458 404
459static void 405static void
460disconnect_notify (void *cls, 406disconnect_notify (void *cls,
461 const struct GNUNET_PeerIdentity *peer) 407 const struct GNUNET_PeerIdentity *peer,
408 void *internal_cls)
462{ 409{
463 struct PeerContext *pc = cls; 410 struct PeerContext *pc = cls;
464 411
465 if (0 == memcmp (&pc->id, 412 if (NULL == internal_cls)
466 peer,
467 sizeof (struct GNUNET_PeerIdentity)))
468 return; /* loopback */ 413 return; /* loopback */
469 pc->connect_status = 0; 414 pc->connect_status = 0;
415 pc->mq = NULL;
470 if (NULL != measure_task) 416 if (NULL != measure_task)
471 { 417 {
472 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 418 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -474,121 +420,58 @@ disconnect_notify (void *cls,
474 GNUNET_SCHEDULER_cancel (measure_task); 420 GNUNET_SCHEDULER_cancel (measure_task);
475 measure_task = NULL; 421 measure_task = NULL;
476 } 422 }
477 if (NULL != pc->nth)
478 {
479 GNUNET_CORE_notify_transmit_ready_cancel (pc->nth);
480 pc->nth = NULL;
481 }
482 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 423 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
483 "Encrypted connection to `%s' cut\n", 424 "Encrypted connection to `%s' cut\n",
484 GNUNET_i2s (peer)); 425 GNUNET_i2s (peer));
485} 426}
486 427
487 428
488static int
489inbound_notify (void *cls,
490 const struct GNUNET_PeerIdentity *other,
491 const struct GNUNET_MessageHeader *message)
492{
493 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
494 "Core provides inbound data from `%s' %u.\n",
495 GNUNET_i2s (other),
496 (unsigned int) ntohs (message->size));
497 total_bytes_recv += ntohs (message->size);
498 return GNUNET_OK;
499}
500
501
502static int
503outbound_notify (void *cls,
504 const struct GNUNET_PeerIdentity *other,
505 const struct GNUNET_MessageHeader *message)
506{
507 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
508 "Core notifies about outbound data for `%s'.\n",
509 GNUNET_i2s (other));
510 return GNUNET_OK;
511}
512
513
514static size_t
515transmit_ready (void *cls, size_t size, void *buf);
516 429
517 430static void
518static int 431handle_test (void *cls,
519process_mtype (void *cls, 432 const struct TestMessage *hdr)
520 const struct GNUNET_PeerIdentity *peer,
521 const struct GNUNET_MessageHeader *message)
522{ 433{
523 static int n; 434 static int n;
524 const struct TestMessage *hdr;
525 435
526 hdr = (const struct TestMessage *) message; 436 total_bytes_recv += sizeof (struct TestMessage);
527 if (MTYPE != ntohs (message->type))
528 return GNUNET_SYSERR;
529 if (ntohs (message->size) != MESSAGESIZE)
530 {
531 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
532 "Expected message %u of size %u, got %u bytes of message %u\n",
533 n,
534 MESSAGESIZE,
535 ntohs (message->size),
536 ntohl (hdr->num));
537 GNUNET_SCHEDULER_cancel (err_task);
538 err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error,
539 NULL);
540 return GNUNET_SYSERR;
541 }
542 if (ntohl (hdr->num) != n) 437 if (ntohl (hdr->num) != n)
543 { 438 {
544 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 439 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
545 "Expected message %u of size %u, got %u bytes of message %u\n", 440 "Expected message %u, got message %u\n",
546 n, 441 n,
547 MESSAGESIZE,
548 ntohs (message->size),
549 ntohl (hdr->num)); 442 ntohl (hdr->num));
550 GNUNET_SCHEDULER_cancel (err_task); 443 GNUNET_SCHEDULER_cancel (err_task);
551 err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, 444 err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error,
552 NULL); 445 NULL);
553 return GNUNET_SYSERR; 446 return;
554 } 447 }
555 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 448 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
556 "Got message %u of size %u\n", 449 "Got message %u\n",
557 ntohl (hdr->num), 450 ntohl (hdr->num));
558 ntohs (message->size));
559 n++; 451 n++;
560 if (0 == (n % 10)) 452 if (0 == (n % 10))
561 FPRINTF (stderr, "%s", "."); 453 FPRINTF (stderr, "%s", ".");
562 454
563 if (GNUNET_YES == running) 455 if (GNUNET_YES == running)
564 GNUNET_break (NULL != 456 do_transmit (NULL);
565 (p1.nth = GNUNET_CORE_notify_transmit_ready (p1.ch,
566 GNUNET_NO,
567 GNUNET_CORE_PRIO_BEST_EFFORT,
568 FAST_TIMEOUT,
569 &p2.id,
570 MESSAGESIZE,
571 &transmit_ready,
572 &p1)));
573 return GNUNET_OK;
574} 457}
575 458
576 459
577static struct GNUNET_CORE_MessageHandler handlers[] = {
578 {&process_mtype, MTYPE, 0},
579 {NULL, 0, 0}
580};
581
582
583
584static void 460static void
585init_notify (void *cls, 461init_notify (void *cls,
586 const struct GNUNET_PeerIdentity *my_identity) 462 const struct GNUNET_PeerIdentity *my_identity)
587{ 463{
464 GNUNET_MQ_hd_fixed_size (test,
465 MTYPE,
466 struct TestMessage);
588 struct PeerContext *p = cls; 467 struct PeerContext *p = cls;
468 struct GNUNET_MQ_MessageHandler handlers[] = {
469 make_test_handler (NULL),
470 GNUNET_MQ_handler_end ()
471 };
589 472
590 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 473 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
591 "Connection to CORE service of `%4s' established\n", 474 "Connection to CORE service of `%s' established\n",
592 GNUNET_i2s (my_identity)); 475 GNUNET_i2s (my_identity));
593 GNUNET_assert (NULL != my_identity); 476 GNUNET_assert (NULL != my_identity);
594 p->id = *my_identity; 477 p->id = *my_identity;
@@ -597,17 +480,12 @@ init_notify (void *cls,
597 GNUNET_assert (ok == 2); 480 GNUNET_assert (ok == 2);
598 OKPP; 481 OKPP;
599 /* connect p2 */ 482 /* connect p2 */
600 p2.ch = 483 p2.ch = GNUNET_CORE_connecT (p2.cfg,
601 GNUNET_CORE_connect (p2.cfg, 484 &p2,
602 &p2, 485 &init_notify,
603 &init_notify, 486 &connect_notify,
604 &connect_notify, 487 &disconnect_notify,
605 &disconnect_notify, 488 handlers);
606 &inbound_notify,
607 GNUNET_YES,
608 &outbound_notify,
609 GNUNET_YES,
610 handlers);
611 } 489 }
612 else 490 else
613 { 491 {
@@ -647,22 +525,28 @@ process_hello (void *cls,
647 GNUNET_assert (message != NULL); 525 GNUNET_assert (message != NULL);
648 p->hello = GNUNET_malloc (ntohs (message->size)); 526 p->hello = GNUNET_malloc (ntohs (message->size));
649 GNUNET_memcpy (p->hello, message, ntohs (message->size)); 527 GNUNET_memcpy (p->hello, message, ntohs (message->size));
650 if ((p == &p1) && (NULL == p2.oh)) 528 if ( (p == &p1) &&
529 (NULL == p2.oh) )
651 p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg, 530 p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg,
652 message, 531 message,
653 &offer_hello_done, 532 &offer_hello_done,
654 &p2); 533 &p2);
655 if ((p == &p2) && (NULL == p1.oh)) 534 if ( (p == &p2) &&
535 (NULL == p1.oh) )
656 p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg, message, 536 p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg, message,
657 &offer_hello_done, 537 &offer_hello_done,
658 &p1); 538 &p1);
659 539
660 if ((p == &p1) && (p2.hello != NULL) && (NULL == p1.oh)) 540 if ( (p == &p1) &&
541 (NULL != p2.hello) &&
542 (NULL == p1.oh) )
661 p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg, 543 p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg,
662 p2.hello, 544 p2.hello,
663 &offer_hello_done, 545 &offer_hello_done,
664 &p1); 546 &p1);
665 if ((p == &p2) && (p1.hello != NULL) && (NULL == p2.oh) ) 547 if ( (p == &p2) &&
548 (NULL != p1.hello) &&
549 (NULL == p2.oh) )
666 p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg, 550 p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg,
667 p1.hello, 551 p1.hello,
668 &offer_hello_done, 552 &offer_hello_done,
@@ -709,6 +593,14 @@ run (void *cls,
709 const char *cfgfile, 593 const char *cfgfile,
710 const struct GNUNET_CONFIGURATION_Handle *cfg) 594 const struct GNUNET_CONFIGURATION_Handle *cfg)
711{ 595{
596 GNUNET_MQ_hd_fixed_size (test,
597 MTYPE,
598 struct TestMessage);
599 struct GNUNET_MQ_MessageHandler handlers[] = {
600 make_test_handler (NULL),
601 GNUNET_MQ_handler_end ()
602 };
603
712 GNUNET_assert (ok == 1); 604 GNUNET_assert (ok == 1);
713 OKPP; 605 OKPP;
714 err_task = 606 err_task =
@@ -761,17 +653,12 @@ run (void *cls,
761 "WAN_QUOTA_OUT", 653 "WAN_QUOTA_OUT",
762 &current_quota_p2_out)); 654 &current_quota_p2_out));
763 655
764 p1.ch = 656 p1.ch = GNUNET_CORE_connecT (p1.cfg,
765 GNUNET_CORE_connect (p1.cfg, 657 &p1,
766 &p1, 658 &init_notify,
767 &init_notify, 659 &connect_notify,
768 &connect_notify, 660 &disconnect_notify,
769 &disconnect_notify, 661 handlers);
770 &inbound_notify,
771 GNUNET_YES,
772 &outbound_notify,
773 GNUNET_YES,
774 handlers);
775} 662}
776 663
777 664