aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_plugin_transport_http.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2010-07-08 11:01:35 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2010-07-08 11:01:35 +0000
commit5bde2a730f688695ecd49aa2c65ffc60152218e7 (patch)
treecd14396bbd96ee9e8e7f2c4c75dc13a35df253ee /src/transport/test_plugin_transport_http.c
parentaaf312180fd09f08e30316a0a646a662efb29219 (diff)
downloadgnunet-5bde2a730f688695ecd49aa2c65ffc60152218e7.tar.gz
gnunet-5bde2a730f688695ecd49aa2c65ffc60152218e7.zip
Diffstat (limited to 'src/transport/test_plugin_transport_http.c')
-rw-r--r--src/transport/test_plugin_transport_http.c153
1 files changed, 92 insertions, 61 deletions
diff --git a/src/transport/test_plugin_transport_http.c b/src/transport/test_plugin_transport_http.c
index 699ca3582..52121d3cf 100644
--- a/src/transport/test_plugin_transport_http.c
+++ b/src/transport/test_plugin_transport_http.c
@@ -57,7 +57,7 @@
57/** 57/**
58 * How long until we give up on transmitting the message? 58 * How long until we give up on transmitting the message?
59 */ 59 */
60#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) 60#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
61 61
62/** 62/**
63 * How long between recieve and send? 63 * How long between recieve and send?
@@ -343,6 +343,16 @@ static struct HTTP_Transfer test_valid_ident;
343 */ 343 */
344static int fail_session_selection_any; 344static int fail_session_selection_any;
345 345
346/**
347 * Test: session selection, use existing inbound session
348 */
349static int fail_session_selection_session;
350
351/**
352 * Test: session selection, use existing inbound session
353 * max message, not fitting in send & recv buffers at one time
354 */
355static int fail_session_selection_session_big;
346 356
347/** 357/**
348* Test: session selection, use reliable existing 358* Test: session selection, use reliable existing
@@ -384,17 +394,22 @@ shutdown_clean ()
384 fail = 0; 394 fail = 0;
385 if ((fail_notify_address == GNUNET_YES) || (fail_pretty_printer == GNUNET_YES) || (fail_addr_to_str == GNUNET_YES)) 395 if ((fail_notify_address == GNUNET_YES) || (fail_pretty_printer == GNUNET_YES) || (fail_addr_to_str == GNUNET_YES))
386 { 396 {
387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test plugin functions failed\n"); 397 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Phase 0: Test plugin functions failed\n");
388 fail = 1; 398 fail = 1;
389 } 399 }
390 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)) 400 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))
391 { 401 {
392 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test connect with wrong data failed\n"); 402 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Phase 1: Test connect with wrong data failed\n");
403 fail = 1;
404 }
405 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))
406 {
407 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Phase 2: Test session selection failed\n");
393 fail = 1; 408 fail = 1;
394 } 409 }
395 if ((fail_msgs_transmited_to_local_addrs != count_str_addr) || (fail_multiple_msgs_in_transmission != 2) || (fail_msg_transmited_max_size == GNUNET_YES)) 410 if ((fail_msgs_transmited_to_local_addrs != count_str_addr) || (fail_multiple_msgs_in_transmission != 2) || (fail_msg_transmited_max_size == GNUNET_YES))
396 { 411 {
397 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test sending with plugin failed\n"); 412 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Phase 3: Test sending with plugin failed\n");
398 fail = 1; 413 fail = 1;
399 } 414 }
400 if (fail != 1) 415 if (fail != 1)
@@ -479,7 +494,7 @@ static void task_send_cont (void *cls,
479} 494}
480 495
481 496
482static void run_connection_tests( int ); 497static void run_connection_tests( int phase , void * cls);
483 498
484/** 499/**
485 * Recieves messages from plugin, in real world transport 500 * Recieves messages from plugin, in real world transport
@@ -493,33 +508,42 @@ receive (void *cls,
493 const char *sender_address, 508 const char *sender_address,
494 uint16_t sender_address_len) 509 uint16_t sender_address_len)
495{ 510{
496 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testcase recieved new message from peer `%s' with type %u and length %u\n", GNUNET_i2s(peer), ntohs(message->type), ntohs(message->size)); 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);
497 512
498 if ((ntohs(message->type)>=10) && (ntohs(message->type)<=20)) 513 if ((ntohs(message->type)>=10) && (ntohs(message->type)<20))
499 { 514 {
500 fail_msgs_transmited_to_local_addrs++; 515 fail_msgs_transmited_to_local_addrs++;
501 if (fail_msgs_transmited_to_local_addrs == count_str_addr) 516 if (fail_msgs_transmited_to_local_addrs == count_str_addr)
502 run_connection_tests(2); 517 run_connection_tests(2, session);
503 } 518 }
504 519
505 520
506 if ((ntohs(message->type)==60)) 521 if ((ntohs(message->type)==20))
507 { 522 {
508 fail_session_selection_reliable = GNUNET_NO; 523 fail_session_selection_reliable = GNUNET_NO;
509 } 524 }
510 525
511 if ((ntohs(message->type)==61)) 526 if ((ntohs(message->type)==21))
512 { 527 {
513 fail_session_selection_any = GNUNET_NO; 528 fail_session_selection_any = GNUNET_NO;
514 run_connection_tests(3); 529 }
530 if ((ntohs(message->type)==22))
531 {
532 fail_session_selection_session = GNUNET_NO;
515 } 533 }
516 534
517 if ((ntohs(message->type)==40) || (ntohs(message->type)==41)) 535 if ((ntohs(message->type)==23))
536 {
537 fail_session_selection_session_big = GNUNET_NO;
538 run_connection_tests(3, NULL);
539 }
540
541 if ((ntohs(message->type)==30) || (ntohs(message->type)==31))
518 { 542 {
519 fail_multiple_msgs_in_transmission ++; 543 fail_multiple_msgs_in_transmission ++;
520 } 544 }
521 545
522 if (ntohs(message->size) == GNUNET_SERVER_MAX_MESSAGE_SIZE-1) 546 if ((ntohs(message->type)==32) && (ntohs(message->size) == GNUNET_SERVER_MAX_MESSAGE_SIZE-1))
523 { 547 {
524 fail_msg_transmited_max_size = GNUNET_NO; 548 fail_msg_transmited_max_size = GNUNET_NO;
525 shutdown_clean(); 549 shutdown_clean();
@@ -595,7 +619,7 @@ static size_t header_function( void *ptr, size_t size, size_t nmemb, void *strea
595 619
596static size_t send_prepare( struct HTTP_Transfer * result); 620static size_t send_prepare( struct HTTP_Transfer * result);
597 621
598static void run_connection_tests( ); 622
599 623
600static void send_execute (void *cls, 624static void send_execute (void *cls,
601 const struct GNUNET_SCHEDULER_TaskContext *tc) 625 const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -644,7 +668,7 @@ static void send_execute (void *cls,
644 curl_easy_cleanup(curl_handle); 668 curl_easy_cleanup(curl_handle);
645 curl_handle=NULL; 669 curl_handle=NULL;
646 670
647 run_connection_tests(0); 671 run_connection_tests(0, NULL);
648 } 672 }
649 if (res == &test_no_ident) 673 if (res == &test_no_ident)
650 { 674 {
@@ -689,8 +713,8 @@ static void send_execute (void *cls,
689 curl_easy_cleanup(curl_handle); 713 curl_easy_cleanup(curl_handle);
690 curl_handle=NULL; 714 curl_handle=NULL;
691 if ((res == &test_valid_ident) && (res->test_failed == GNUNET_NO)) 715 if ((res == &test_valid_ident) && (res->test_failed == GNUNET_NO))
692 run_connection_tests(1); 716 run_connection_tests(1, NULL);
693 run_connection_tests(0); 717 run_connection_tests(0, NULL);
694 return; 718 return;
695 default: 719 default:
696 break; 720 break;
@@ -899,8 +923,11 @@ static void pretty_printer_cb (void *cls,
899/** 923/**
900 * Runs every single test to test the plugin 924 * Runs every single test to test the plugin
901 */ 925 */
902static void run_connection_tests( int phase ) 926static void run_connection_tests( int phase , void * cls)
903{ 927{
928 struct GNUNET_MessageHeader * msg;
929 unsigned int size;
930
904 if (phase==0) 931 if (phase==0)
905 { 932 {
906 char * host_str = NULL; 933 char * host_str = NULL;
@@ -1000,66 +1027,68 @@ static void run_connection_tests( int phase )
1000 count ++; 1027 count ++;
1001 type ++; 1028 type ++;
1002 } 1029 }
1003
1004 msg.type = htons(60);
1005 memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader));
1006 api->send(api->cls, &my_identity, tmp, sizeof(struct GNUNET_MessageHeader), 0, TIMEOUT, NULL, NULL, 0, GNUNET_NO, &task_send_cont, &fail_msgs_transmited_to_local_addrs);
1007
1008 msg.type = htons(61);
1009 memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader));
1010 api->send(api->cls, &my_identity, tmp, sizeof(struct GNUNET_MessageHeader), 0, TIMEOUT, NULL, NULL, 0, GNUNET_SYSERR, &task_send_cont, &fail_msgs_transmited_to_local_addrs);
1011 return; 1030 return;
1012 } 1031 }
1013 1032
1014 if (phase==2) 1033 if (phase==2)
1015 { 1034 {
1016 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("\nPhase 2: session selection\n\n")); 1035 struct Session * session = cls;
1036 msg = GNUNET_malloc (sizeof(struct GNUNET_MessageHeader));
1017 1037
1018 struct GNUNET_MessageHeader msg; 1038 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("\nPhase 2: session selection\n\n"));
1019 msg.size=htons(sizeof(struct GNUNET_MessageHeader)); 1039 size = sizeof(struct GNUNET_MessageHeader);
1020 msg.type = htons(60); 1040 msg->size=htons(size);
1021 api->send(api->cls, &my_identity, (const char *) &msg, sizeof(struct GNUNET_MessageHeader), 0, TIMEOUT, NULL, NULL, 0, GNUNET_NO, &task_send_cont, NULL); 1041 msg->type = htons(20);
1022 1042 api->send(api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT, NULL, NULL, 0, GNUNET_NO, &task_send_cont, NULL);
1023 msg.type = htons(61); 1043
1024 api->send(api->cls, &my_identity, (const char *) &msg, sizeof(struct GNUNET_MessageHeader), 0, TIMEOUT, NULL, NULL, 0, GNUNET_SYSERR, &task_send_cont, NULL); 1044 msg->type = htons(21);
1045 api->send(api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT, NULL, NULL, 0, GNUNET_SYSERR, &task_send_cont, NULL);
1046
1047 /* answer on session*/
1048 size = sizeof( struct GNUNET_MessageHeader);
1049 msg->size = htons(size);
1050 msg->type = htons(22);
1051 api->send(api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT, session, NULL, 0, GNUNET_SYSERR, &task_send_cont, NULL);
1052
1053 GNUNET_free(msg);
1054
1055 /* answer on session with big message not fitting in mhd send buffer*/
1056 size = GNUNET_SERVER_MAX_MESSAGE_SIZE-1;
1057 msg = GNUNET_malloc (size);
1058 msg->size=htons(size);
1059 msg->type = htons(23);
1060 api->send(api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT, session, NULL, 0, GNUNET_NO, &task_send_cont, NULL);
1061 GNUNET_free(msg);
1062 return;
1025 } 1063 }
1026 1064
1027 if (phase==3) 1065 if (phase==3)
1028 { 1066 {
1067
1029 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("\nPhase 3: send multiple or big messages after disconnect\n\n")); 1068 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("\nPhase 3: send multiple or big messages after disconnect\n\n"));
1030 /* disconnect from peer, so new connections are created */ 1069 /* disconnect from peer, so new connections are created */
1031 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Disconnect from peer: `%s'\n", GNUNET_i2s(&my_identity)); 1070 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Disconnect from peer: `%s'\n", GNUNET_i2s(&my_identity));
1032 api->disconnect(api->cls, &my_identity); 1071 api->disconnect(api->cls, &my_identity);
1033 1072
1034 struct GNUNET_MessageHeader msg;
1035 char * tmp = GNUNET_malloc(sizeof(struct GNUNET_MessageHeader));
1036 /* send a multiple GNUNET_messages at a time*/ 1073 /* send a multiple GNUNET_messages at a time*/
1037 GNUNET_free(tmp);
1038 tmp = GNUNET_malloc(4 * sizeof(struct GNUNET_MessageHeader));
1039 struct GNUNET_MessageHeader * msg1 = (struct GNUNET_MessageHeader *) tmp;
1040 msg1->size = htons(2 * sizeof(struct GNUNET_MessageHeader));
1041 msg1->type = htons(40);
1042 struct GNUNET_MessageHeader * msg2 = &msg1[2];
1043 msg2->size = htons(2 * sizeof(struct GNUNET_MessageHeader));
1044 msg2->type = htons(41);
1045 api->send(api->cls, &my_identity, tmp, 4 * sizeof(struct GNUNET_MessageHeader), 0, TIMEOUT, NULL,addr_head->addr, addr_head->addrlen, GNUNET_NO, &task_send_cont, &fail_multiple_msgs_in_transmission);
1046 1074
1075 size = 2 * sizeof(struct GNUNET_MessageHeader);
1076 msg = GNUNET_malloc( 2* size);
1077 msg->size = htons(size);
1078 msg->type = htons(30);
1079 struct GNUNET_MessageHeader * msg2 = &msg[2];
1080 msg2->size = htons(2 * sizeof(struct GNUNET_MessageHeader));
1081 msg2->type = htons(31);
1082 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);
1083 GNUNET_free(msg);
1047 /* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE-1 */ 1084 /* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE-1 */
1048 GNUNET_free(tmp); 1085
1049 tmp = GNUNET_malloc(GNUNET_SERVER_MAX_MESSAGE_SIZE-1); 1086 size = GNUNET_SERVER_MAX_MESSAGE_SIZE-1;
1050 uint16_t t = (uint16_t)GNUNET_SERVER_MAX_MESSAGE_SIZE-1; 1087 msg = GNUNET_malloc(size);
1051 msg.size = htons(t); 1088 msg->size = htons(size);
1052 memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader)); 1089 msg->type = htons(32);
1053 api->send(api->cls, &my_identity, tmp, GNUNET_SERVER_MAX_MESSAGE_SIZE-1, 0, TIMEOUT, NULL,addr_head->addr, addr_head->addrlen, GNUNET_NO, &task_send_cont, &fail_msg_transmited_max_size); 1090 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);
1054 GNUNET_free(tmp); 1091 GNUNET_free(msg);
1055 /* send a message without address, use existing session */
1056 tmp = GNUNET_malloc(GNUNET_SERVER_MAX_MESSAGE_SIZE-1);
1057 t = (uint16_t)GNUNET_SERVER_MAX_MESSAGE_SIZE-1;
1058 msg.size = htons(t);
1059 msg.type = htons(50);
1060 memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader));
1061 api->send(api->cls, &my_identity, tmp, GNUNET_SERVER_MAX_MESSAGE_SIZE-1, 0, TIMEOUT, NULL, NULL, 0, GNUNET_NO, &task_send_cont, &fail_msg_transmited_max_size);
1062 GNUNET_free(tmp);
1063 } 1092 }
1064 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No more tests to run\n"); 1093 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No more tests to run\n");
1065} 1094}
@@ -1097,6 +1126,8 @@ run (void *cls,
1097 fail_multiple_msgs_in_transmission = 0; 1126 fail_multiple_msgs_in_transmission = 0;
1098 fail_session_selection_reliable = GNUNET_YES; 1127 fail_session_selection_reliable = GNUNET_YES;
1099 fail_session_selection_reliable = GNUNET_YES; 1128 fail_session_selection_reliable = GNUNET_YES;
1129 fail_session_selection_session = GNUNET_YES;
1130 fail_session_selection_session_big = GNUNET_YES;
1100 1131
1101 addr_head = NULL; 1132 addr_head = NULL;
1102 count_str_addr = 0; 1133 count_str_addr = 0;
@@ -1246,7 +1277,7 @@ run (void *cls,
1246 test_addr = (char *) api->address_to_string (api->cls,addr_head->addr,addr_head->addrlen); 1277 test_addr = (char *) api->address_to_string (api->cls,addr_head->addr,addr_head->addrlen);
1247 1278
1248 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("\nPhase 0\n\n")); 1279 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("\nPhase 0\n\n"));
1249 run_connection_tests(0); 1280 run_connection_tests(0, NULL);
1250 1281
1251 /* testing finished */ 1282 /* testing finished */
1252 1283