aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_plugin_transport_http.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-06-05 13:07:13 +0000
committerChristian Grothoff <christian@grothoff.org>2011-06-05 13:07:13 +0000
commit187f3ee1b6edac986b7bc46c62c86a138290b147 (patch)
tree809c2751509e7111ad26e802e5df8d2332c24455 /src/transport/test_plugin_transport_http.c
parent2850662595ec7d25aaaf9674e987449375960c23 (diff)
downloadgnunet-187f3ee1b6edac986b7bc46c62c86a138290b147.tar.gz
gnunet-187f3ee1b6edac986b7bc46c62c86a138290b147.zip
adapting testcases to use new API
Diffstat (limited to 'src/transport/test_plugin_transport_http.c')
-rw-r--r--src/transport/test_plugin_transport_http.c598
1 files changed, 352 insertions, 246 deletions
diff --git a/src/transport/test_plugin_transport_http.c b/src/transport/test_plugin_transport_http.c
index 989e0d69a..73a9c950a 100644
--- a/src/transport/test_plugin_transport_http.c
+++ b/src/transport/test_plugin_transport_http.c
@@ -396,31 +396,46 @@ shutdown_clean ()
396 396
397 /* Evaluate results */ 397 /* Evaluate results */
398 fail = 0; 398 fail = 0;
399 if ((fail_notify_address == GNUNET_YES) || (fail_pretty_printer == GNUNET_YES) || (fail_addr_to_str == GNUNET_YES)) 399 if ( (fail_notify_address == GNUNET_YES) ||
400 { 400 (fail_pretty_printer == GNUNET_YES) ||
401 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Phase 0: Test plugin functions failed\n"); 401 (fail_addr_to_str == GNUNET_YES))
402 fail = 1; 402 {
403 } 403 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
404 if ((test_no_ident.test_failed == GNUNET_YES) || (test_too_short_ident.test_failed == GNUNET_YES) || (test_too_long_ident.test_failed == GNUNET_YES) || (test_valid_ident.test_failed == GNUNET_YES)) 404 "Phase 0: Test plugin functions failed\n");
405 { 405 fail = 1;
406 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Phase 1: Test connect with wrong data failed\n"); 406 }
407 fail = 1; 407 if ( (test_no_ident.test_failed == GNUNET_YES) ||
408 } 408 (test_too_short_ident.test_failed == GNUNET_YES) ||
409 if ((fail_session_selection_any != GNUNET_NO) || (fail_session_selection_reliable != GNUNET_NO) || (fail_session_selection_session != GNUNET_NO) || (fail_session_selection_session_big != GNUNET_NO)) 409 (test_too_long_ident.test_failed == GNUNET_YES) ||
410 { 410 (test_valid_ident.test_failed == GNUNET_YES) )
411 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Phase 2: Test session selection failed\n");
412 fail = 1;
413 }
414 if ((fail_msgs_transmited_to_local_addrs != count_str_addr) || (fail_multiple_msgs_in_transmission != 2) || (fail_msg_transmited_max_size == GNUNET_YES))
415 { 411 {
416 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Phase 3: Test sending with plugin failed\n"); 412 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
413 "Phase 1: Test connect with wrong data failed\n");
417 fail = 1; 414 fail = 1;
418 } 415 }
416 if ( (fail_session_selection_any != GNUNET_NO) ||
417 (fail_session_selection_reliable != GNUNET_NO) ||
418 (fail_session_selection_session != GNUNET_NO) ||
419 (fail_session_selection_session_big != GNUNET_NO) )
420 {
421 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
422 "Phase 2: Test session selection failed\n");
423 fail = 1;
424 }
425 if ( (fail_msgs_transmited_to_local_addrs != count_str_addr) ||
426 (fail_multiple_msgs_in_transmission != 2) ||
427 (fail_msg_transmited_max_size == GNUNET_YES) )
428 {
429 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
430 "Phase 3: Test sending with plugin failed\n");
431 fail = 1;
432 }
419 if (fail != 1) 433 if (fail != 1)
420 { 434 {
421 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All tests successful\n"); 435 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
422 } 436 "All tests successful\n");
423 437 }
438
424 api->disconnect(api->cls,&my_identity); 439 api->disconnect(api->cls,&my_identity);
425 440
426 curl_multi_cleanup(multi_handle); 441 curl_multi_cleanup(multi_handle);
@@ -456,13 +471,15 @@ shutdown_clean ()
456 } 471 }
457 472
458 GNUNET_free(test_addr); 473 GNUNET_free(test_addr);
459 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unloading http plugin\n"); 474 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
475 "Unloading http plugin\n");
460 GNUNET_assert (NULL == GNUNET_PLUGIN_unload ("libgnunet_gnunet_transport_plugin_http", api)); 476 GNUNET_assert (NULL == GNUNET_PLUGIN_unload ("libgnunet_gnunet_transport_plugin_http", api));
461 477
462 GNUNET_SCHEDULER_shutdown(); 478 GNUNET_SCHEDULER_shutdown();
463 GNUNET_DISK_directory_remove ("/tmp/test_gnunet_transport_plugin_http"); 479 GNUNET_DISK_directory_remove ("/tmp/test_gnunet_transport_plugin_http");
464 480
465 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Exiting testcase\n"); 481 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
482 "Exiting testcase\n");
466 exit(fail); 483 exit(fail);
467 return; 484 return;
468} 485}
@@ -475,22 +492,26 @@ shutdown_clean ()
475 * @result GNUNET_OK or GNUNET_SYSERR 492 * @result GNUNET_OK or GNUNET_SYSERR
476 */ 493 */
477 494
478static void task_send_cont (void *cls, 495static void
479 const struct GNUNET_PeerIdentity * target, 496task_send_cont (void *cls,
480 int result) 497 const struct GNUNET_PeerIdentity * target,
498 int result)
481{ 499{
482 if ((cls == &fail_msg_transmited_bigger_max_size) && (result == GNUNET_SYSERR)) 500 if ((cls == &fail_msg_transmited_bigger_max_size) && (result == GNUNET_SYSERR))
483 { 501 {
484 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message bigger max msg size was not sent!\n"); 502 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
485 fail_msg_transmited_bigger_max_size = GNUNET_NO; 503 "Message bigger max msg size was not sent!\n");
486 return; 504 fail_msg_transmited_bigger_max_size = GNUNET_NO;
487 } 505 return;
506 }
488 507
489 if ((cls == &fail_msg_transmited_max_size) && (result == GNUNET_OK)) 508 if ((cls == &fail_msg_transmited_max_size) && (result == GNUNET_OK))
490 { 509 {
491 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message with max msg size succesfully sent!\n",fail_msgs_transmited_to_local_addrs); 510 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
492 fail_msg_transmited_max_size = GNUNET_NO; 511 "Message with max msg size succesfully sent!\n",
493 } 512 fail_msgs_transmited_to_local_addrs);
513 fail_msg_transmited_max_size = GNUNET_NO;
514 }
494} 515}
495 516
496 517
@@ -508,51 +529,52 @@ receive (void *cls, const struct GNUNET_PeerIdentity *peer,
508 const char *sender_address, 529 const char *sender_address,
509 uint16_t sender_address_len) 530 uint16_t sender_address_len)
510{ 531{
511 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testcase recieved new message from peer `%s' with type %u and length %u, session %X\n", GNUNET_i2s(peer), ntohs(message->type), ntohs(message->size),session); 532 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
512 533 "Testcase recieved new message from peer `%s' with type %u and length %u, session %X\n",
513 if ((ntohs(message->type)>=10) && (ntohs(message->type)<20)) 534 GNUNET_i2s(peer),
514 { 535 ntohs(message->type),
515 fail_msgs_transmited_to_local_addrs++; 536 ntohs(message->size),
516 if (fail_msgs_transmited_to_local_addrs == count_str_addr) 537 session);
517 run_connection_tests(2, session); 538
518 } 539 if ( (ntohs(message->type)>=10) &&
519 540 (ntohs(message->type)<20) )
520 541 {
542 fail_msgs_transmited_to_local_addrs++;
543 if (fail_msgs_transmited_to_local_addrs == count_str_addr)
544 run_connection_tests(2, session);
545 }
521 if ((ntohs(message->type)==20)) 546 if ((ntohs(message->type)==20))
522 { 547 {
523 fail_session_selection_reliable = GNUNET_NO; 548 fail_session_selection_reliable = GNUNET_NO;
524 } 549 }
525
526 if ((ntohs(message->type)==21)) 550 if ((ntohs(message->type)==21))
527 { 551 {
528 fail_session_selection_any = GNUNET_NO; 552 fail_session_selection_any = GNUNET_NO;
529 } 553 }
530 if ((ntohs(message->type)==22)) 554 if ((ntohs(message->type)==22))
531 { 555 {
532 fail_session_selection_session = GNUNET_NO; 556 fail_session_selection_session = GNUNET_NO;
533 } 557 }
534
535 if ((ntohs(message->type)==23)) 558 if ((ntohs(message->type)==23))
536 { 559 {
537 fail_session_selection_session_big = GNUNET_NO; 560 fail_session_selection_session_big = GNUNET_NO;
538 run_connection_tests(3, NULL); 561 run_connection_tests(3, NULL);
539 } 562 }
540
541 if ((ntohs(message->type)==30) || (ntohs(message->type)==31)) 563 if ((ntohs(message->type)==30) || (ntohs(message->type)==31))
542 { 564 {
543 fail_multiple_msgs_in_transmission ++; 565 fail_multiple_msgs_in_transmission ++;
544 } 566 }
545
546 if ((ntohs(message->type)==32) && (ntohs(message->size) == GNUNET_SERVER_MAX_MESSAGE_SIZE-1)) 567 if ((ntohs(message->type)==32) && (ntohs(message->size) == GNUNET_SERVER_MAX_MESSAGE_SIZE-1))
547 { 568 {
548 fail_msg_transmited_max_size = GNUNET_NO; 569 fail_msg_transmited_max_size = GNUNET_NO;
549 shutdown_clean(); 570 shutdown_clean();
550 } 571 }
551
552 return GNUNET_TIME_UNIT_ZERO; 572 return GNUNET_TIME_UNIT_ZERO;
553} 573}
554 574
555static size_t send_function (void *stream, size_t size, size_t nmemb, void *ptr) 575
576static size_t
577send_function (void *stream, size_t size, size_t nmemb, void *ptr)
556{ 578{
557 unsigned int len; 579 unsigned int len;
558 580
@@ -563,9 +585,11 @@ static size_t send_function (void *stream, size_t size, size_t nmemb, void *ptr)
563 memcpy(stream, buffer_out.buf, len); 585 memcpy(stream, buffer_out.buf, len);
564 buffer_out.pos = len; 586 buffer_out.pos = len;
565 return len; 587 return len;
588
566} 589}
567 590
568static size_t recv_function (void *ptr, size_t size, size_t nmemb, void *ctx) 591static size_t
592recv_function (void *ptr, size_t size, size_t nmemb, void *ctx)
569{ 593{
570 594
571 if (buffer_in.pos + size * nmemb > buffer_in.size) 595 if (buffer_in.pos + size * nmemb > buffer_in.size)
@@ -579,9 +603,10 @@ static size_t recv_function (void *ptr, size_t size, size_t nmemb, void *ctx)
579 return buffer_in.pos; 603 return buffer_in.pos;
580} 604}
581 605
582static size_t header_function( void *ptr, size_t size, size_t nmemb, void *stream) 606static size_t
607header_function( void *ptr, size_t size, size_t nmemb, void *stream)
583{ 608{
584 struct HTTP_Transfer * res = (struct HTTP_Transfer *) stream; 609 struct HTTP_Transfer * res = stream;
585 char * tmp; 610 char * tmp;
586 unsigned int len = size * nmemb; 611 unsigned int len = size * nmemb;
587 612
@@ -590,39 +615,43 @@ static size_t header_function( void *ptr, size_t size, size_t nmemb, void *strea
590 if (tmp[len-2] == 13) 615 if (tmp[len-2] == 13)
591 tmp[len-2]= '\0'; 616 tmp[len-2]= '\0';
592#if DEBUG_CURL 617#if DEBUG_CURL
593 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Header: `%s'\n",tmp); 618 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
619 "Header: `%s'\n",
620 tmp);
594#endif 621#endif
595 if (0==strcmp (tmp,"HTTP/1.1 100 Continue")) 622 if (0==strcmp (tmp,"HTTP/1.1 100 Continue"))
596 { 623 {
597 res->http_result_code=100; 624 res->http_result_code=100;
598 } 625 }
599 if (0==strcmp (tmp,"HTTP/1.1 200 OK")) 626 if (0==strcmp (tmp,"HTTP/1.1 200 OK"))
600 { 627 {
601 res->http_result_code=200; 628 res->http_result_code=200;
602 } 629 }
603 if (0==strcmp (tmp,"HTTP/1.1 400 Bad Request")) 630 if (0==strcmp (tmp,"HTTP/1.1 400 Bad Request"))
604 { 631 {
605 res->http_result_code=400; 632 res->http_result_code=400;
606 } 633 }
607 if (0==strcmp (tmp,"HTTP/1.1 404 Not Found")) 634 if (0==strcmp (tmp,"HTTP/1.1 404 Not Found"))
608 { 635 {
609 res->http_result_code=404; 636 res->http_result_code=404;
610 } 637 }
611 if (0==strcmp (tmp,"HTTP/1.1 413 Request entity too large")) 638 if (0==strcmp (tmp,"HTTP/1.1 413 Request entity too large"))
612 { 639 {
613 res->http_result_code=413; 640 res->http_result_code=413;
614 } 641 }
615 642
616 GNUNET_free (tmp); 643 GNUNET_free (tmp);
617 return size * nmemb; 644 return size * nmemb;
618} 645}
619 646
620static size_t send_prepare( struct HTTP_Transfer * result);
621 647
648static size_t
649send_prepare( struct HTTP_Transfer * result);
622 650
623 651
624static void send_execute (void *cls, 652static void
625 const struct GNUNET_SCHEDULER_TaskContext *tc) 653send_execute (void *cls,
654 const struct GNUNET_SCHEDULER_TaskContext *tc)
626{ 655{
627 struct HTTP_Transfer *res; 656 struct HTTP_Transfer *res;
628 657
@@ -673,42 +702,50 @@ static void send_execute (void *cls,
673 if (res == &test_no_ident) 702 if (res == &test_no_ident)
674 { 703 {
675 if ((res->http_result_code==404) && (buffer_in.len==208)) 704 if ((res->http_result_code==404) && (buffer_in.len==208))
676 { 705 {
677 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to peer without any peer identification: test passed\n"); 706 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
707 "Connecting to peer without any peer identification: test passed\n");
678 res->test_failed = GNUNET_NO; 708 res->test_failed = GNUNET_NO;
679 } 709 }
680 else 710 else
681 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Connecting to peer without any peer identification: test failed\n")); 711 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
712 _("Connecting to peer without any peer identification: test failed\n"));
682 } 713 }
683 if (res == &test_too_short_ident) 714 if (res == &test_too_short_ident)
684 { 715 {
685 if ((res->http_result_code==404) && (buffer_in.len==208)) 716 if ((res->http_result_code==404) && (buffer_in.len==208))
686 { 717 {
687 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to peer with too short peer identification: test passed\n"); 718 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
719 "Connecting to peer with too short peer identification: test passed\n");
688 res->test_failed = GNUNET_NO; 720 res->test_failed = GNUNET_NO;
689 } 721 }
690 else 722 else
691 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Connecting to peer with too short peer identification: test failed\n")); 723 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
724 _("Connecting to peer with too short peer identification: test failed\n"));
692 } 725 }
693 if (res == &test_too_long_ident) 726 if (res == &test_too_long_ident)
694 { 727 {
695 if ((res->http_result_code==404) && (buffer_in.len==208)) 728 if ((res->http_result_code==404) && (buffer_in.len==208))
696 { 729 {
697 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to peer with too long peer identification: test passed\n"); 730 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
731 "Connecting to peer with too long peer identification: test passed\n");
698 res->test_failed = GNUNET_NO; 732 res->test_failed = GNUNET_NO;
699 } 733 }
700 else 734 else
701 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Connecting to peer with too long peer identification: test failed\n")); 735 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
736 _("Connecting to peer with too long peer identification: test failed\n"));
702 } 737 }
703 if (res == &test_valid_ident) 738 if (res == &test_valid_ident)
704 { 739 {
705 if ((res->http_result_code==200)) 740 if ((res->http_result_code==200))
706 { 741 {
707 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to peer with valid peer identification: test passed\n"); 742 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
743 "Connecting to peer with valid peer identification: test passed\n");
708 res->test_failed = GNUNET_NO; 744 res->test_failed = GNUNET_NO;
709 } 745 }
710 else 746 else
711 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connecting to peer with valid peer identification: test failed\n"); 747 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
748 "Connecting to peer with valid peer identification: test failed\n");
712 } 749 }
713 curl_easy_cleanup(curl_handle); 750 curl_easy_cleanup(curl_handle);
714 curl_handle=NULL; 751 curl_handle=NULL;
@@ -728,12 +765,14 @@ static void send_execute (void *cls,
728 send_prepare(cls); 765 send_prepare(cls);
729} 766}
730 767
768
731/** 769/**
732 * Function setting up file descriptors and scheduling task to run 770 * Function setting up file descriptors and scheduling task to run
733 * @param ses session to send data to 771 * @param ses session to send data to
734 * @return bytes sent to peer 772 * @return bytes sent to peer
735 */ 773 */
736static size_t send_prepare( struct HTTP_Transfer * result) 774static size_t
775send_prepare( struct HTTP_Transfer * result)
737{ 776{
738 fd_set rs; 777 fd_set rs;
739 fd_set ws; 778 fd_set ws;
@@ -772,12 +811,12 @@ static size_t send_prepare( struct HTTP_Transfer * result)
772 GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1); 811 GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
773 GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1); 812 GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
774 http_task_send = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 813 http_task_send = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
775 GNUNET_SCHEDULER_NO_TASK, 814 GNUNET_SCHEDULER_NO_TASK,
776 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 0), 815 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 0),
777 grs, 816 grs,
778 gws, 817 gws,
779 &send_execute, 818 &send_execute,
780 result); 819 result);
781 GNUNET_NETWORK_fdset_destroy (gws); 820 GNUNET_NETWORK_fdset_destroy (gws);
782 GNUNET_NETWORK_fdset_destroy (grs); 821 GNUNET_NETWORK_fdset_destroy (grs);
783 822
@@ -788,15 +827,17 @@ static size_t send_prepare( struct HTTP_Transfer * result)
788/** 827/**
789 * function to send data to server 828 * function to send data to server
790 */ 829 */
791static int send_data( struct HTTP_Transfer * result, char * url) 830static int
831send_data(struct HTTP_Transfer * result,
832 char * url)
792{ 833{
793 834
794 curl_handle = curl_easy_init(); 835 curl_handle = curl_easy_init();
795 if( NULL == curl_handle) 836 if( NULL == curl_handle)
796 { 837 {
797 printf("easy_init failed \n"); 838 printf("easy_init failed \n");
798 return GNUNET_SYSERR; 839 return GNUNET_SYSERR;
799 } 840 }
800#if DEBUG_CURL 841#if DEBUG_CURL
801 curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L); 842 curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L);
802#endif 843#endif
@@ -822,7 +863,7 @@ static int send_data( struct HTTP_Transfer * result, char * url)
822/** 863/**
823 * Plugin notifies transport (aka testcase) about its addresses 864 * Plugin notifies transport (aka testcase) about its addresses
824 */ 865 */
825void 866static void
826notify_address (void *cls, 867notify_address (void *cls,
827 const char *name, 868 const char *name,
828 const void *addr, 869 const void *addr,
@@ -881,11 +922,14 @@ notify_address (void *cls,
881} 922}
882 923
883static void 924static void
884plugin_env_session_end (void *cls, 925plugin_env_session_end (void *cls,
885 const struct GNUNET_PeerIdentity *peer, 926 const struct GNUNET_PeerIdentity *peer,
886 struct Session *session) 927 struct Session *session)
887{ 928{
888 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Pluging tells me: session %X to peer `%s' ended\n", session, GNUNET_i2s(peer)); 929 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
930 "Pluging tells me: session %X to peer `%s' ended\n",
931 session,
932 GNUNET_i2s(peer));
889} 933}
890 934
891 935
@@ -923,19 +967,24 @@ task_timeout (void *cls,
923 return; 967 return;
924} 968}
925 969
926static void pretty_printer_cb (void *cls, 970
927 const char *address) 971static void
972pretty_printer_cb (void *cls,
973 const char *address)
928{ 974{
929 if (NULL==address) 975 if (NULL==address)
930 return; 976 return;
931 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Plugin returned pretty address: `%s'\n",address); 977 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
978 "Plugin returned pretty address: `%s'\n",
979 address);
932 fail_pretty_printer_count++; 980 fail_pretty_printer_count++;
933} 981}
934 982
935/** 983/**
936 * Runs every single test to test the plugin 984 * Runs every single test to test the plugin
937 */ 985 */
938static void run_connection_tests( int phase , void * cls) 986static void
987run_connection_tests( int phase , void * cls)
939{ 988{
940 struct GNUNET_MessageHeader * msg; 989 struct GNUNET_MessageHeader * msg;
941 unsigned int size; 990 unsigned int size;
@@ -953,136 +1002,184 @@ static void run_connection_tests( int phase , void * cls)
953 buffer_out.len = 0; 1002 buffer_out.len = 0;
954 1003
955 if (test_no_ident.test_executed == GNUNET_NO) 1004 if (test_no_ident.test_executed == GNUNET_NO)
956 { 1005 {
957 /* Connecting to peer without identification */ 1006 /* Connecting to peer without identification */
958 char * ident = ""; 1007 const char * ident = "";
959 GNUNET_asprintf (&host_str, "%s://%s/%s",PROTOCOL_PREFIX, test_addr,ident); 1008 GNUNET_asprintf (&host_str,
960 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Connecting to peer without any peer identification.\n")); 1009 "%s://%s/%s",
961 test_no_ident.test_executed = GNUNET_YES; 1010 PROTOCOL_PREFIX,
962 send_data ( &test_no_ident, host_str); 1011 test_addr,ident);
963 GNUNET_free (host_str); 1012 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
964 return; 1013 _("Connecting to peer without any peer identification.\n"));
965 } 1014 test_no_ident.test_executed = GNUNET_YES;
1015 send_data ( &test_no_ident, host_str);
1016 GNUNET_free (host_str);
1017 return;
1018 }
966 if (test_too_short_ident.test_executed == GNUNET_NO) 1019 if (test_too_short_ident.test_executed == GNUNET_NO)
967 { 1020 {
968 char * ident = "AAAAAAAAAA"; 1021 const char * ident = "AAAAAAAAAA";
969 /* Connecting to peer with too short identification */ 1022 /* Connecting to peer with too short identification */
970 GNUNET_asprintf (&host_str, "%s://%s/%s",PROTOCOL_PREFIX,test_addr,ident); 1023 GNUNET_asprintf (&host_str,
971 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Connecting to peer with too short peer identification.\n")); 1024 "%s://%s/%s",
972 test_too_short_ident.test_executed = GNUNET_YES; 1025 PROTOCOL_PREFIX,
973 send_data ( &test_too_short_ident, host_str); 1026 test_addr,
974 GNUNET_free (host_str); 1027 ident);
975 return; 1028 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
976 } 1029 _("Connecting to peer with too short peer identification.\n"));
1030 test_too_short_ident.test_executed = GNUNET_YES;
1031 send_data ( &test_too_short_ident, host_str);
1032 GNUNET_free (host_str);
1033 return;
1034 }
977 1035
978 if (test_too_long_ident.test_executed == GNUNET_NO) 1036 if (test_too_long_ident.test_executed == GNUNET_NO)
979 { 1037 {
980 char * ident = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; 1038 const char * ident = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
981 1039
982 /* Connecting to peer with too long identification */ 1040 /* Connecting to peer with too long identification */
983 GNUNET_asprintf (&host_str, "%s://%s/%s",PROTOCOL_PREFIX, test_addr,ident); 1041 GNUNET_asprintf (&host_str, "%s://%s/%s",PROTOCOL_PREFIX, test_addr,ident);
984 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Connecting to peer with too long peer identification.\n")); 1042 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
985 test_too_long_ident.test_executed = GNUNET_YES; 1043 _("Connecting to peer with too long peer identification.\n"));
986 send_data ( &test_too_long_ident, host_str); 1044 test_too_long_ident.test_executed = GNUNET_YES;
987 GNUNET_free (host_str); 1045 send_data ( &test_too_long_ident, host_str);
988 return; 1046 GNUNET_free (host_str);
1047 return;
989 } 1048 }
990 if (test_valid_ident.test_executed == GNUNET_NO) 1049 if (test_valid_ident.test_executed == GNUNET_NO)
991 { 1050 {
992 struct GNUNET_CRYPTO_HashAsciiEncoded ident; 1051 struct GNUNET_CRYPTO_HashAsciiEncoded ident;
993 GNUNET_CRYPTO_hash_to_enc(&my_identity.hashPubKey,&ident); 1052 GNUNET_CRYPTO_hash_to_enc(&my_identity.hashPubKey,&ident);
994 GNUNET_asprintf (&host_str, "%s://%s/%s%s",PROTOCOL_PREFIX, test_addr,(char *) &ident,";0"); 1053 GNUNET_asprintf (&host_str,
995 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Connecting to peer with valid peer identification.\n")); 1054 "%s://%s/%s%s",
996 test_valid_ident.test_executed = GNUNET_YES; 1055 PROTOCOL_PREFIX,
997 send_data ( &test_valid_ident, host_str); 1056 test_addr,
998 GNUNET_free (host_str); 1057 (char *) &ident,
999 return; 1058 ";0");
1000 } 1059 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1060 _("Connecting to peer with valid peer identification.\n"));
1061 test_valid_ident.test_executed = GNUNET_YES;
1062 send_data ( &test_valid_ident, host_str);
1063 GNUNET_free (host_str);
1064 return;
1065 }
1001 } 1066 }
1002 if (phase==1) 1067 if (phase==1)
1003 {
1004 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\nPhase 1: transmit data to all suggested addresses\n\n");
1005 /* Using one of the addresses the plugin proposed */
1006 GNUNET_assert (addr_head->addr != NULL);
1007
1008 struct Plugin_Address * tmp_addr;
1009 struct GNUNET_MessageHeader msg;
1010 char * tmp = GNUNET_malloc(sizeof(struct GNUNET_MessageHeader));
1011 char address[INET6_ADDRSTRLEN];
1012 unsigned int port;
1013 unsigned int type = 10;
1014
1015 msg.size=htons(sizeof(struct GNUNET_MessageHeader));
1016 tmp_addr = addr_head;
1017 /* send a message to all addresses advertised by plugin */
1018
1019 int count = 0;
1020 while (tmp_addr != NULL)
1021 { 1068 {
1022 if (tmp_addr->addrlen == (sizeof (struct IPv4HttpAddress))) 1069 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1023 { 1070 "\nPhase 1: transmit data to all suggested addresses\n\n");
1024 inet_ntop(AF_INET, (struct in_addr *) tmp_addr->addr,address,INET_ADDRSTRLEN); 1071 /* Using one of the addresses the plugin proposed */
1025 port = ntohs(((struct IPv4HttpAddress *) tmp_addr->addr)->u_port); 1072 GNUNET_assert (addr_head->addr != NULL);
1026 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sending message to addres no. %u: `%s':%u\n", count,address, port); 1073
1027 } 1074 struct Plugin_Address * tmp_addr;
1028 if (tmp_addr->addrlen == (sizeof (struct IPv6HttpAddress))) 1075 struct GNUNET_MessageHeader msg;
1029 { 1076 char * tmp = GNUNET_malloc(sizeof(struct GNUNET_MessageHeader));
1030 inet_ntop(AF_INET6, (struct in6_addr *) tmp_addr->addr,address,INET6_ADDRSTRLEN); 1077 char address[INET6_ADDRSTRLEN];
1031 port = ntohs(((struct IPv6HttpAddress *) tmp_addr->addr)->u6_port); 1078 unsigned int port;
1032 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sending message to addres no. %u: `%s':%u\n", count,address,port); 1079 unsigned int type = 10;
1033 } 1080
1034 msg.type=htons(type); 1081 msg.size=htons(sizeof(struct GNUNET_MessageHeader));
1035 memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader)); 1082 tmp_addr = addr_head;
1036 api->send(api->cls, &my_identity, tmp, sizeof(struct GNUNET_MessageHeader), 0, TIMEOUT, NULL,tmp_addr->addr, tmp_addr->addrlen, GNUNET_YES, &task_send_cont, &fail_msgs_transmited_to_local_addrs); 1083 /* send a message to all addresses advertised by plugin */
1037 tmp_addr = tmp_addr->next; 1084
1038 1085 int count = 0;
1039 count ++; 1086 while (tmp_addr != NULL)
1040 type ++; 1087 {
1088 if (tmp_addr->addrlen == (sizeof (struct IPv4HttpAddress)))
1089 {
1090 inet_ntop(AF_INET, (struct in_addr *) tmp_addr->addr,address,INET_ADDRSTRLEN);
1091 port = ntohs(((struct IPv4HttpAddress *) tmp_addr->addr)->u_port);
1092 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1093 "Sending message to addres no. %u: `%s':%u\n",
1094 count,
1095 address,
1096 port);
1097 }
1098 if (tmp_addr->addrlen == (sizeof (struct IPv6HttpAddress)))
1099 {
1100 inet_ntop(AF_INET6, (struct in6_addr *) tmp_addr->addr,address,INET6_ADDRSTRLEN);
1101 port = ntohs(((struct IPv6HttpAddress *) tmp_addr->addr)->u6_port);
1102 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1103 "Sending message to addres no. %u: `%s':%u\n",
1104 count,
1105 address,
1106 port);
1107 }
1108 msg.type=htons(type);
1109 memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader));
1110 api->send(api->cls,
1111 &my_identity,
1112 tmp, sizeof(struct GNUNET_MessageHeader),
1113 0, TIMEOUT,
1114 NULL,
1115 tmp_addr->addr, tmp_addr->addrlen,
1116 GNUNET_YES,
1117 &task_send_cont, &fail_msgs_transmited_to_local_addrs);
1118 tmp_addr = tmp_addr->next;
1119 count++;
1120 type++;
1121 }
1122 GNUNET_free(tmp);
1123 return;
1041 } 1124 }
1042 GNUNET_free(tmp);
1043 return;
1044 }
1045 1125
1046 if (phase==2) 1126 if (phase==2)
1047 { 1127 {
1048 struct Session * session = cls; 1128 struct Session * session = cls;
1049 msg = GNUNET_malloc (sizeof(struct GNUNET_MessageHeader)); 1129 msg = GNUNET_malloc (sizeof(struct GNUNET_MessageHeader));
1050 1130
1051 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Phase 2: session selection\n\n"); 1131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1052 size = sizeof(struct GNUNET_MessageHeader); 1132 "Phase 2: session selection\n\n");
1053 msg->size=htons(size); 1133 size = sizeof(struct GNUNET_MessageHeader);
1054 msg->type = htons(20); 1134 msg->size=htons(size);
1055 api->send(api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT, NULL, NULL, 0, GNUNET_NO, &task_send_cont, NULL); 1135 msg->type = htons(20);
1056 1136 api->send(api->cls,
1057 msg->type = htons(21); 1137 &my_identity,
1058 api->send(api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT, NULL, NULL, 0, GNUNET_SYSERR, &task_send_cont, NULL); 1138 (const char *) msg, size,
1059 1139 0, TIMEOUT, NULL, NULL, 0, GNUNET_NO,
1060 /* answer on session*/ 1140 &task_send_cont, NULL);
1061 size = sizeof( struct GNUNET_MessageHeader); 1141
1062 msg->size = htons(size); 1142 msg->type = htons(21);
1063 msg->type = htons(22); 1143 api->send(api->cls,
1064 api->send(api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT, session, NULL, 0, GNUNET_SYSERR, &task_send_cont, NULL); 1144 &my_identity,
1065 1145 (const char *) msg, size,
1066 GNUNET_free(msg); 1146 0, TIMEOUT, NULL, NULL, 0, GNUNET_SYSERR,
1067 1147 &task_send_cont, NULL);
1068 /* answer on session with big message not fitting in mhd send buffer*/ 1148
1069 size = GNUNET_SERVER_MAX_MESSAGE_SIZE-1; 1149 /* answer on session*/
1070 msg = GNUNET_malloc (size); 1150 size = sizeof( struct GNUNET_MessageHeader);
1071 msg->size=htons(size); 1151 msg->size = htons(size);
1072 msg->type = htons(23); 1152 msg->type = htons(22);
1073 api->send(api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT, session, NULL, 0, GNUNET_NO, &task_send_cont, NULL); 1153 api->send(api->cls,
1074 GNUNET_free(msg); 1154 &my_identity,
1075 return; 1155 (const char *) msg, size,
1076 } 1156 0, TIMEOUT, session, NULL, 0, GNUNET_SYSERR,
1077 1157 &task_send_cont, NULL);
1158 GNUNET_free(msg);
1159
1160 /* answer on session with big message not fitting in mhd send buffer*/
1161 size = GNUNET_SERVER_MAX_MESSAGE_SIZE-1;
1162 msg = GNUNET_malloc (size);
1163 msg->size=htons(size);
1164 msg->type = htons(23);
1165 api->send(api->cls,
1166 &my_identity,
1167 (const char *) msg, size,
1168 0, TIMEOUT, session, NULL, 0, GNUNET_NO,
1169 &task_send_cont, NULL);
1170 GNUNET_free(msg);
1171 return;
1172 }
1173
1078 if (phase==3) 1174 if (phase==3)
1079 { 1175 {
1080 1176
1081 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Phase 3: send multiple or big messages after disconnect\n\n"); 1177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1178 "Phase 3: send multiple or big messages after disconnect\n\n");
1082 /* disconnect from peer, so new connections are created */ 1179 /* disconnect from peer, so new connections are created */
1083 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Disconnect from peer: `%s'\n", GNUNET_i2s(&my_identity)); 1180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Disconnect from peer: `%s'\n", GNUNET_i2s(&my_identity));
1084 api->disconnect(api->cls, &my_identity); 1181 api->disconnect(api->cls, &my_identity);
1085 1182
1086 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Phase 3: sending messages\n"); 1183 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Phase 3: sending messages\n");
1087 /* send a multiple GNUNET_messages at a time*/ 1184 /* send a multiple GNUNET_messages at a time*/
1088 size = 2 * sizeof(struct GNUNET_MessageHeader); 1185 size = 2 * sizeof(struct GNUNET_MessageHeader);
@@ -1092,7 +1189,13 @@ static void run_connection_tests( int phase , void * cls)
1092 struct GNUNET_MessageHeader * msg2 = &msg[2]; 1189 struct GNUNET_MessageHeader * msg2 = &msg[2];
1093 msg2->size = htons(2 * sizeof(struct GNUNET_MessageHeader)); 1190 msg2->size = htons(2 * sizeof(struct GNUNET_MessageHeader));
1094 msg2->type = htons(31); 1191 msg2->type = htons(31);
1095 api->send(api->cls, &my_identity, (const char *) msg, 4 * sizeof(struct GNUNET_MessageHeader), 0, TIMEOUT, NULL,addr_head->addr, addr_head->addrlen, GNUNET_NO, &task_send_cont, &fail_multiple_msgs_in_transmission); 1192 api->send(api->cls,
1193 &my_identity,
1194 (const char *) msg, 4 * sizeof(struct GNUNET_MessageHeader),
1195 0, TIMEOUT, NULL,
1196 addr_head->addr, addr_head->addrlen,
1197 GNUNET_NO,
1198 &task_send_cont, &fail_multiple_msgs_in_transmission);
1096 GNUNET_free(msg); 1199 GNUNET_free(msg);
1097 /* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE-1 */ 1200 /* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE-1 */
1098 1201
@@ -1100,9 +1203,16 @@ static void run_connection_tests( int phase , void * cls)
1100 msg = GNUNET_malloc(size); 1203 msg = GNUNET_malloc(size);
1101 msg->size = htons(size); 1204 msg->size = htons(size);
1102 msg->type = htons(32); 1205 msg->type = htons(32);
1103 api->send(api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT, NULL,addr_head->addr, addr_head->addrlen, GNUNET_NO, &task_send_cont, &fail_msg_transmited_max_size); 1206 api->send(api->cls,
1207 &my_identity,
1208 (const char *) msg, size,
1209 0, TIMEOUT, NULL,
1210 addr_head->addr, addr_head->addrlen,
1211 GNUNET_NO,
1212 &task_send_cont, &fail_msg_transmited_max_size);
1104 GNUNET_free(msg); 1213 GNUNET_free(msg);
1105 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No more tests to run\n"); 1214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1215 "No more tests to run\n");
1106 } 1216 }
1107} 1217}
1108 1218
@@ -1286,10 +1396,7 @@ run (void *cls,
1286 1396
1287 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Phase 0\n\n")); 1397 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Phase 0\n\n"));
1288 run_connection_tests(0, NULL); 1398 run_connection_tests(0, NULL);
1289
1290 /* testing finished */ 1399 /* testing finished */
1291
1292 return;
1293} 1400}
1294 1401
1295 1402
@@ -1303,7 +1410,6 @@ run (void *cls,
1303int 1410int
1304main (int argc, char *const *argv) 1411main (int argc, char *const *argv)
1305{ 1412{
1306
1307 static struct GNUNET_GETOPT_CommandLineOption options[] = { 1413 static struct GNUNET_GETOPT_CommandLineOption options[] = {
1308 GNUNET_GETOPT_OPTION_END 1414 GNUNET_GETOPT_OPTION_END
1309 }; 1415 };