aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2010-06-28 14:48:43 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2010-06-28 14:48:43 +0000
commitabe735c1cb91b2f1e4fe32a2444d7951b05a9e83 (patch)
tree580f2ddecbd91fbe12bace1a678d4a6c8a604cfa
parente04f6c4b852480817edeb6b718d9ac5311fcba1f (diff)
downloadgnunet-abe735c1cb91b2f1e4fe32a2444d7951b05a9e83.tar.gz
gnunet-abe735c1cb91b2f1e4fe32a2444d7951b05a9e83.zip
-rw-r--r--src/transport/test_plugin_transport_http.c222
1 files changed, 92 insertions, 130 deletions
diff --git a/src/transport/test_plugin_transport_http.c b/src/transport/test_plugin_transport_http.c
index 9c98d8c06..0e26c4639 100644
--- a/src/transport/test_plugin_transport_http.c
+++ b/src/transport/test_plugin_transport_http.c
@@ -44,7 +44,7 @@
44 44
45#define VERBOSE GNUNET_YES 45#define VERBOSE GNUNET_YES
46#define DEBUG GNUNET_NO 46#define DEBUG GNUNET_NO
47#define DEBUG_CURL GNUNET_NO 47#define DEBUG_CURL GNUNET_YES
48#define HTTP_BUFFER_SIZE 2048 48#define HTTP_BUFFER_SIZE 2048
49 49
50#define PLUGIN libgnunet_plugin_transport_template 50#define PLUGIN libgnunet_plugin_transport_template
@@ -382,7 +382,7 @@ shutdown_clean ()
382 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test connect with wrong data failed\n"); 382 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test connect with wrong data failed\n");
383 fail = 1; 383 fail = 1;
384 } 384 }
385 if ((fail_msgs_transmited_to_local_addrs != count_str_addr) || (fail_msg_transmited_max_size == GNUNET_YES) || (fail_msg_transmited_bigger_max_size == GNUNET_YES) || (fail_multiple_msgs_in_transmission != GNUNET_NO)) 385 if ((fail_msgs_transmited_to_local_addrs != count_str_addr) || (fail_multiple_msgs_in_transmission != 2) || (fail_msg_transmited_max_size == GNUNET_YES))
386 { 386 {
387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test sending with plugin failed\n"); 387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test sending with plugin failed\n");
388 fail = 1; 388 fail = 1;
@@ -452,16 +452,6 @@ static void task_send_cont (void *cls,
452 struct Plugin_Address * tmp_addr; 452 struct Plugin_Address * tmp_addr;
453 tmp_addr = addr_head; 453 tmp_addr = addr_head;
454 454
455 if ((cls == &fail_msgs_transmited_to_local_addrs) && (result == GNUNET_OK))
456 {
457 fail_msgs_transmited_to_local_addrs++;
458 if (fail_msgs_transmited_to_local_addrs == count_str_addr)
459 {
460 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message sent to %u addresses!\n",fail_msgs_transmited_to_local_addrs);
461 }
462 return;
463 }
464
465 if ((cls == &fail_msg_transmited_bigger_max_size) && (result == GNUNET_SYSERR)) 455 if ((cls == &fail_msg_transmited_bigger_max_size) && (result == GNUNET_SYSERR))
466 { 456 {
467 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message bigger max msg size was not sent!\n"); 457 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message bigger max msg size was not sent!\n");
@@ -473,37 +463,12 @@ static void task_send_cont (void *cls,
473 { 463 {
474 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message with max msg size succesfully sent!\n",fail_msgs_transmited_to_local_addrs); 464 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message with max msg size succesfully sent!\n",fail_msgs_transmited_to_local_addrs);
475 fail_msg_transmited_max_size = GNUNET_NO; 465 fail_msg_transmited_max_size = GNUNET_NO;
476 shutdown_clean(); 466 //shutdown_clean();
477 } 467 }
478} 468}
479 469
480#if 0
481/**
482 * Task sending recieved message back to peer
483 * @cls closure
484 * @tc task context
485 */
486
487static void
488task_send (void *cls,
489 const struct GNUNET_SCHEDULER_TaskContext *tc)
490{
491 ti_timeout = GNUNET_SCHEDULER_NO_TASK;
492 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
493 return;
494
495 if (GNUNET_YES==sent)
496 return;
497/*
498 struct GNUNET_MessageHeader * msg = cls;
499 unsigned int len = ntohs(msg->size);
500 const char * msgc = (const char *) msg;
501 470
502 api->send(api->cls, p, msgc, len, 0, TIMEOUT, NULL,NULL, 0, GNUNET_NO, &task_send_cont, NULL); 471static void run_connection_tests( int );
503 */
504 sent = GNUNET_YES;
505}
506#endif
507 472
508/** 473/**
509 * Recieves messages from plugin, in real world transport 474 * Recieves messages from plugin, in real world transport
@@ -518,10 +483,25 @@ receive (void *cls,
518 uint16_t sender_address_len) 483 uint16_t sender_address_len)
519{ 484{
520 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)); 485 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));
521 if ((ntohs(message->type) == 40) && (fail_multiple_msgs_in_transmission == 1)) 486
522 fail_multiple_msgs_in_transmission++; 487 if ((ntohs(message->type)>=10) && (ntohs(message->type)<=20))
523 if ((ntohs(message->type) == 41) && (fail_multiple_msgs_in_transmission == 2)) 488 {
524 fail_multiple_msgs_in_transmission = GNUNET_NO; 489 fail_msgs_transmited_to_local_addrs++;
490 if (fail_msgs_transmited_to_local_addrs == count_str_addr)
491 run_connection_tests(2);
492 }
493
494 if ((ntohs(message->type)==40) || (ntohs(message->type)==41))
495 {
496 fail_multiple_msgs_in_transmission ++;
497 }
498
499 if (ntohs(message->size) == GNUNET_SERVER_MAX_MESSAGE_SIZE-1)
500 {
501 fail_msg_transmited_max_size = GNUNET_NO;
502 shutdown_clean();
503 }
504
525 return GNUNET_TIME_UNIT_ZERO; 505 return GNUNET_TIME_UNIT_ZERO;
526} 506}
527 507
@@ -641,7 +621,7 @@ static void send_execute (void *cls,
641 curl_easy_cleanup(curl_handle); 621 curl_easy_cleanup(curl_handle);
642 curl_handle=NULL; 622 curl_handle=NULL;
643 623
644 run_connection_tests(); 624 run_connection_tests(1);
645 } 625 }
646 if (res == &test_no_ident) 626 if (res == &test_no_ident)
647 { 627 {
@@ -675,7 +655,7 @@ static void send_execute (void *cls,
675 } 655 }
676 if (res == &test_valid_ident) 656 if (res == &test_valid_ident)
677 { 657 {
678 if ((res->http_result_code==400)) 658 if ((res->http_result_code==200))
679 { 659 {
680 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with valid peer identification: test passed\n")); 660 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with valid peer identification: test passed\n"));
681 res->test_failed = GNUNET_NO; 661 res->test_failed = GNUNET_NO;
@@ -686,7 +666,7 @@ static void send_execute (void *cls,
686 curl_easy_cleanup(curl_handle); 666 curl_easy_cleanup(curl_handle);
687 curl_handle=NULL; 667 curl_handle=NULL;
688 668
689 run_connection_tests(); 669 run_connection_tests(1);
690 return; 670 return;
691 default: 671 default:
692 break; 672 break;
@@ -792,7 +772,6 @@ static int send_data( struct HTTP_Transfer * result, char * url)
792 return GNUNET_OK; 772 return GNUNET_OK;
793} 773}
794 774
795
796/** 775/**
797 * Plugin notifies transport (aka testcase) about its addresses 776 * Plugin notifies transport (aka testcase) about its addresses
798 */ 777 */
@@ -896,8 +875,9 @@ static void pretty_printer_cb (void *cls,
896/** 875/**
897 * Runs every single test to test the plugin 876 * Runs every single test to test the plugin
898 */ 877 */
899static void run_connection_tests( ) 878static void run_connection_tests( int phase )
900{ 879{
880
901 char * host_str = NULL; 881 char * host_str = NULL;
902 /* resetting buffers */ 882 /* resetting buffers */
903 buffer_in.size = HTTP_BUFFER_SIZE; 883 buffer_in.size = HTTP_BUFFER_SIZE;
@@ -908,7 +888,6 @@ static void run_connection_tests( )
908 buffer_out.pos = 0; 888 buffer_out.pos = 0;
909 buffer_out.len = 0; 889 buffer_out.len = 0;
910 890
911
912 if (test_no_ident.test_executed == GNUNET_NO) 891 if (test_no_ident.test_executed == GNUNET_NO)
913 { 892 {
914 /* Connecting to peer without identification */ 893 /* Connecting to peer without identification */
@@ -960,90 +939,73 @@ static void run_connection_tests( )
960 GNUNET_free (host_str); 939 GNUNET_free (host_str);
961 return; 940 return;
962 } 941 }
963 /* Using one of the addresses the plugin proposed */
964 GNUNET_assert (addr_head->addr != NULL);
965
966 struct Plugin_Address * tmp_addr;
967 struct GNUNET_MessageHeader msg;
968 char * tmp = GNUNET_malloc(sizeof(struct GNUNET_MessageHeader));
969 char address[INET6_ADDRSTRLEN];
970 unsigned int port;
971 unsigned int type = 10;
972 942
973 msg.size=htons(sizeof(struct GNUNET_MessageHeader)); 943 if (phase==1)
974 tmp_addr = addr_head;
975 /* send a message to all addresses advertised by plugin */
976
977 int count = 0;
978 while (tmp_addr != NULL)
979 { 944 {
980 if (tmp_addr->addrlen == (sizeof (struct IPv4HttpAddress))) 945 /* Using one of the addresses the plugin proposed */
981 { 946 GNUNET_assert (addr_head->addr != NULL);
982 inet_ntop(AF_INET, (struct in_addr *) tmp_addr->addr,address,INET_ADDRSTRLEN); 947
983 port = ntohs(((struct IPv4HttpAddress *) tmp_addr->addr)->u_port); 948 struct Plugin_Address * tmp_addr;
984 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sending message to addres no. %u: `%s':%u\n", count,address, port); 949 struct GNUNET_MessageHeader msg;
985 } 950 char * tmp = GNUNET_malloc(sizeof(struct GNUNET_MessageHeader));
986 if (tmp_addr->addrlen == (sizeof (struct IPv6HttpAddress))) 951 char address[INET6_ADDRSTRLEN];
987 { 952 unsigned int port;
988 inet_ntop(AF_INET6, (struct in6_addr *) tmp_addr->addr,address,INET6_ADDRSTRLEN); 953 unsigned int type = 10;
989 port = ntohs(((struct IPv6HttpAddress *) tmp_addr->addr)->u6_port); 954
990 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sending message to addres no. %u: `%s':%u\n", count,address,port); 955 msg.size=htons(sizeof(struct GNUNET_MessageHeader));
991 } 956 tmp_addr = addr_head;
992 msg.type=htons(type); 957 /* send a message to all addresses advertised by plugin */
993 memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader)); 958
994 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); 959 int count = 0;
995 tmp_addr = tmp_addr->next; 960 while (tmp_addr != NULL)
996 count ++; 961 {
997 type ++; 962 if (tmp_addr->addrlen == (sizeof (struct IPv4HttpAddress)))
963 {
964 inet_ntop(AF_INET, (struct in_addr *) tmp_addr->addr,address,INET_ADDRSTRLEN);
965 port = ntohs(((struct IPv4HttpAddress *) tmp_addr->addr)->u_port);
966 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sending message to addres no. %u: `%s':%u\n", count,address, port);
967 }
968 if (tmp_addr->addrlen == (sizeof (struct IPv6HttpAddress)))
969 {
970 inet_ntop(AF_INET6, (struct in6_addr *) tmp_addr->addr,address,INET6_ADDRSTRLEN);
971 port = ntohs(((struct IPv6HttpAddress *) tmp_addr->addr)->u6_port);
972 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sending message to addres no. %u: `%s':%u\n", count,address,port);
973 }
974 msg.type=htons(type);
975 memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader));
976 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);
977 tmp_addr = tmp_addr->next;
978 count ++;
979 type ++;
980 }
981 return;
998 } 982 }
999 983
1000 return; 984 if (phase==2)
985 {
1001 986
1002 /* send a multiple GNUNET_messages at a time*/ 987 struct GNUNET_MessageHeader msg;
1003 GNUNET_free(tmp); 988 char * tmp = GNUNET_malloc(sizeof(struct GNUNET_MessageHeader));
1004 tmp = GNUNET_malloc(4 * sizeof(struct GNUNET_MessageHeader)); 989 /* send a multiple GNUNET_messages at a time*/
1005 struct GNUNET_MessageHeader * msg1 = (struct GNUNET_MessageHeader *) tmp; 990 GNUNET_free(tmp);
1006 msg1->size = htons(2 * sizeof(struct GNUNET_MessageHeader)); 991 tmp = GNUNET_malloc(4 * sizeof(struct GNUNET_MessageHeader));
1007 msg1->type = htons(40); 992 struct GNUNET_MessageHeader * msg1 = (struct GNUNET_MessageHeader *) tmp;
1008 struct GNUNET_MessageHeader * msg2 = &msg1[2]; 993 msg1->size = htons(2 * sizeof(struct GNUNET_MessageHeader));
1009 msg2->size = htons(2 * sizeof(struct GNUNET_MessageHeader)); 994 msg1->type = htons(40);
1010 msg2->type = htons(41); 995 struct GNUNET_MessageHeader * msg2 = &msg1[2];
1011 api->send(api->cls, &my_identity, tmp, 4 * sizeof(struct GNUNET_MessageHeader), 0, TIMEOUT, NULL,addr_head->addr, addr_head->addrlen, GNUNET_YES, &task_send_cont, &fail_multiple_msgs_in_transmission); 996 msg2->size = htons(2 * sizeof(struct GNUNET_MessageHeader));
1012 997 msg2->type = htons(41);
1013 998 api->send(api->cls, &my_identity, tmp, 4 * sizeof(struct GNUNET_MessageHeader), 0, TIMEOUT, NULL,addr_head->addr, addr_head->addrlen, GNUNET_YES, &task_send_cont, &fail_multiple_msgs_in_transmission);
1014 /* send a multiple GNUNET_messages at a time, second message has incorrect size*/ 999
1015 GNUNET_free(tmp); 1000 /* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE-1 */
1016 tmp = GNUNET_malloc(4 * sizeof(struct GNUNET_MessageHeader)); 1001 GNUNET_free(tmp);
1017 msg1 = (struct GNUNET_MessageHeader *) tmp; 1002 tmp = GNUNET_malloc(GNUNET_SERVER_MAX_MESSAGE_SIZE-1);
1018 msg1->size = htons(2 * sizeof(struct GNUNET_MessageHeader)); 1003 uint16_t t = (uint16_t)GNUNET_SERVER_MAX_MESSAGE_SIZE-1;
1019 msg1->type = htons(40); 1004 msg.size = htons(t);
1020 msg2 = &msg1[2]; 1005 memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader));
1021 msg2->size = htons(2 * sizeof(struct GNUNET_MessageHeader)); 1006 api->send(api->cls, &my_identity, tmp, GNUNET_SERVER_MAX_MESSAGE_SIZE-1, 0, TIMEOUT, NULL,addr_head->addr, addr_head->addrlen, GNUNET_YES, &task_send_cont, &fail_msg_transmited_max_size);
1022 msg2->type = htons(41); 1007 GNUNET_free(tmp);
1023 api->send(api->cls, &my_identity, tmp, 4 * sizeof(struct GNUNET_MessageHeader), 0, TIMEOUT, NULL,addr_head->addr, addr_head->addrlen, GNUNET_YES, &task_send_cont, NULL); 1008 }
1024
1025
1026 /* send a multiple GNUNET_messages at a time, second message has incorrect size*/
1027/* GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Ping Hello Message\n");
1028 GNUNET_free(tmp);
1029 tmp = GNUNET_malloc(425);
1030 msg1 = (struct GNUNET_MessageHeader *) tmp;
1031 msg1->size = htons(353);
1032 msg1->type = htons(16);
1033 msg2 = &tmp[353];
1034 msg2->size = htons(72);
1035 msg2->type = htons(32);
1036 api->send(api->cls, &my_identity, tmp, 425, 0, TIMEOUT, NULL,addr_head->addr, addr_head->addrlen, GNUNET_YES, &task_send_cont, NULL);*/
1037
1038
1039 /* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE-1 */
1040 GNUNET_free(tmp);
1041 tmp = GNUNET_malloc(GNUNET_SERVER_MAX_MESSAGE_SIZE-1);
1042 uint16_t t = (uint16_t)GNUNET_SERVER_MAX_MESSAGE_SIZE-1;
1043 msg.size = htons(t);
1044 memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader));
1045 api->send(api->cls, &my_identity, tmp, GNUNET_SERVER_MAX_MESSAGE_SIZE-1, 0, TIMEOUT, NULL,addr_head->addr, addr_head->addrlen, GNUNET_YES, &task_send_cont, &fail_msg_transmited_max_size);
1046 GNUNET_free(tmp);
1047 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No more tests to run\n"); 1009 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No more tests to run\n");
1048} 1010}
1049 1011
@@ -1077,7 +1039,7 @@ run (void *cls,
1077 fail_addr_to_str = GNUNET_YES; 1039 fail_addr_to_str = GNUNET_YES;
1078 fail_msgs_transmited_to_local_addrs = 0; 1040 fail_msgs_transmited_to_local_addrs = 0;
1079 fail_msg_transmited_max_size = GNUNET_YES; 1041 fail_msg_transmited_max_size = GNUNET_YES;
1080 fail_multiple_msgs_in_transmission = GNUNET_YES; 1042 fail_multiple_msgs_in_transmission = 0;
1081 1043
1082 addr_head = NULL; 1044 addr_head = NULL;
1083 count_str_addr = 0; 1045 count_str_addr = 0;
@@ -1225,7 +1187,7 @@ run (void *cls,
1225 test_valid_ident.test_failed = GNUNET_YES; 1187 test_valid_ident.test_failed = GNUNET_YES;
1226 1188
1227 test_addr = (char *) api->address_to_string (api->cls,addr_head->addr,addr_head->addrlen); 1189 test_addr = (char *) api->address_to_string (api->cls,addr_head->addr,addr_head->addrlen);
1228 run_connection_tests(); 1190 run_connection_tests(0);
1229 1191
1230 /* testing finished */ 1192 /* testing finished */
1231 1193