aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_plugin_transport_http.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2010-07-07 12:04:28 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2010-07-07 12:04:28 +0000
commitfe9c5d688c274fe3a64ae6c1e3fbaf9c2c11498c (patch)
tree2e78b54e6be9d604c3d62a1061352a7158587936 /src/transport/test_plugin_transport_http.c
parentb07600e49d50666d1200b6f42a13366452f93521 (diff)
downloadgnunet-fe9c5d688c274fe3a64ae6c1e3fbaf9c2c11498c.tar.gz
gnunet-fe9c5d688c274fe3a64ae6c1e3fbaf9c2c11498c.zip
Diffstat (limited to 'src/transport/test_plugin_transport_http.c')
-rw-r--r--src/transport/test_plugin_transport_http.c187
1 files changed, 121 insertions, 66 deletions
diff --git a/src/transport/test_plugin_transport_http.c b/src/transport/test_plugin_transport_http.c
index fd56b335a..699ca3582 100644
--- a/src/transport/test_plugin_transport_http.c
+++ b/src/transport/test_plugin_transport_http.c
@@ -339,6 +339,17 @@ static struct HTTP_Transfer test_too_long_ident;
339static struct HTTP_Transfer test_valid_ident; 339static struct HTTP_Transfer test_valid_ident;
340 340
341/** 341/**
342 * Test: session selection, use any existing
343 */
344static int fail_session_selection_any;
345
346
347/**
348* Test: session selection, use reliable existing
349 */
350static int fail_session_selection_reliable;
351
352/**
342 * Did the test pass or fail? 353 * Did the test pass or fail?
343 */ 354 */
344static int fail; 355static int fail;
@@ -491,6 +502,18 @@ receive (void *cls,
491 run_connection_tests(2); 502 run_connection_tests(2);
492 } 503 }
493 504
505
506 if ((ntohs(message->type)==60))
507 {
508 fail_session_selection_reliable = GNUNET_NO;
509 }
510
511 if ((ntohs(message->type)==61))
512 {
513 fail_session_selection_any = GNUNET_NO;
514 run_connection_tests(3);
515 }
516
494 if ((ntohs(message->type)==40) || (ntohs(message->type)==41)) 517 if ((ntohs(message->type)==40) || (ntohs(message->type)==41))
495 { 518 {
496 fail_multiple_msgs_in_transmission ++; 519 fail_multiple_msgs_in_transmission ++;
@@ -621,7 +644,7 @@ static void send_execute (void *cls,
621 curl_easy_cleanup(curl_handle); 644 curl_easy_cleanup(curl_handle);
622 curl_handle=NULL; 645 curl_handle=NULL;
623 646
624 run_connection_tests(1); 647 run_connection_tests(0);
625 } 648 }
626 if (res == &test_no_ident) 649 if (res == &test_no_ident)
627 { 650 {
@@ -647,7 +670,7 @@ static void send_execute (void *cls,
647 { 670 {
648 if ((res->http_result_code==404) && (buffer_in.len==208)) 671 if ((res->http_result_code==404) && (buffer_in.len==208))
649 { 672 {
650 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too long peer identification: test passed\n")); 673 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too long peer identification: test passed\n"));
651 res->test_failed = GNUNET_NO; 674 res->test_failed = GNUNET_NO;
652 } 675 }
653 else 676 else
@@ -665,8 +688,9 @@ static void send_execute (void *cls,
665 } 688 }
666 curl_easy_cleanup(curl_handle); 689 curl_easy_cleanup(curl_handle);
667 curl_handle=NULL; 690 curl_handle=NULL;
668 691 if ((res == &test_valid_ident) && (res->test_failed == GNUNET_NO))
669 run_connection_tests(1); 692 run_connection_tests(1);
693 run_connection_tests(0);
670 return; 694 return;
671 default: 695 default:
672 break; 696 break;
@@ -751,7 +775,7 @@ static int send_data( struct HTTP_Transfer * result, char * url)
751 return GNUNET_SYSERR; 775 return GNUNET_SYSERR;
752 } 776 }
753#if DEBUG_CURL 777#if DEBUG_CURL
754 curl_easy_setopt(put_curl_handle, CURLOPT_VERBOSE, 1L); 778 curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L);
755#endif 779#endif
756 curl_easy_setopt(curl_handle, CURLOPT_URL, url); 780 curl_easy_setopt(curl_handle, CURLOPT_URL, url);
757 curl_easy_setopt(curl_handle, CURLOPT_PUT, 1L); 781 curl_easy_setopt(curl_handle, CURLOPT_PUT, 1L);
@@ -877,71 +901,68 @@ static void pretty_printer_cb (void *cls,
877 */ 901 */
878static void run_connection_tests( int phase ) 902static void run_connection_tests( int phase )
879{ 903{
904 if (phase==0)
905 {
906 char * host_str = NULL;
907 /* resetting buffers */
908 buffer_in.size = HTTP_BUFFER_SIZE;
909 buffer_in.pos = 0;
910 buffer_in.len = 0;
880 911
881 char * host_str = NULL; 912 buffer_out.size = HTTP_BUFFER_SIZE;
882 /* resetting buffers */ 913 buffer_out.pos = 0;
883 buffer_in.size = HTTP_BUFFER_SIZE; 914 buffer_out.len = 0;
884 buffer_in.pos = 0;
885 buffer_in.len = 0;
886
887 buffer_out.size = HTTP_BUFFER_SIZE;
888 buffer_out.pos = 0;
889 buffer_out.len = 0;
890 915
891 if (test_no_ident.test_executed == GNUNET_NO) 916 if (test_no_ident.test_executed == GNUNET_NO)
892 { 917 {
893 /* Connecting to peer without identification */ 918 /* Connecting to peer without identification */
894 char * ident = ""; 919 char * ident = "";
895 host_str = GNUNET_malloc (strlen ("http:///")+ 1 + strlen (test_addr)+ strlen (ident)); 920 GNUNET_asprintf (&host_str, "http://%s/%s",test_addr,ident);
896 GNUNET_asprintf (&host_str, "http://%s/%s",test_addr,ident); 921 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer without any peer identification.\n"));
897 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer without any peer identification.\n")); 922 test_no_ident.test_executed = GNUNET_YES;
898 test_no_ident.test_executed = GNUNET_YES; 923 send_data ( &test_no_ident, host_str);
899 send_data ( &test_no_ident, host_str); 924 GNUNET_free (host_str);
900 GNUNET_free (host_str); 925 return;
901 return; 926 }
902 } 927 if (test_too_short_ident.test_executed == GNUNET_NO)
903 if (test_too_short_ident.test_executed == GNUNET_NO) 928 {
904 { 929 char * ident = "AAAAAAAAAA";
905 char * ident = "AAAAAAAAAA"; 930 /* Connecting to peer with too short identification */
906 /* Connecting to peer with too short identification */ 931 GNUNET_asprintf (&host_str, "http://%s/%s",test_addr,ident);
907 host_str = GNUNET_malloc (strlen ("http:///")+ 1 + strlen (test_addr)+ strlen (ident)); 932 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too short peer identification.\n"));
908 GNUNET_asprintf (&host_str, "http://%s/%s",test_addr,ident); 933 test_too_short_ident.test_executed = GNUNET_YES;
909 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too short peer identification.\n")); 934 send_data ( &test_too_short_ident, host_str);
910 test_too_short_ident.test_executed = GNUNET_YES; 935 GNUNET_free (host_str);
911 send_data ( &test_too_short_ident, host_str); 936 return;
912 GNUNET_free (host_str); 937 }
913 return;
914 }
915 938
916 if (test_too_long_ident.test_executed == GNUNET_NO) 939 if (test_too_long_ident.test_executed == GNUNET_NO)
917 { 940 {
918 char * ident = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; 941 char * ident = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
919 942
920 /* Connecting to peer with too long identification */ 943 /* Connecting to peer with too long identification */
921 host_str = GNUNET_malloc (strlen ("http:///")+ 1 + strlen (test_addr)+ strlen (ident)); 944 GNUNET_asprintf (&host_str, "http://%s/%s",test_addr,ident);
922 GNUNET_asprintf (&host_str, "http://%s/%s",test_addr,ident); 945 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too long peer identification.\n"));
923 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too long peer identification.\n")); 946 test_too_long_ident.test_executed = GNUNET_YES;
924 test_too_long_ident.test_executed = GNUNET_YES; 947 send_data ( &test_too_long_ident, host_str);
925 send_data ( &test_too_long_ident, host_str); 948 GNUNET_free (host_str);
926 GNUNET_free (host_str); 949 return;
927 return; 950 }
928 } 951 if (test_valid_ident.test_executed == GNUNET_NO)
929 if (test_valid_ident.test_executed == GNUNET_NO) 952 {
930 { 953 struct GNUNET_CRYPTO_HashAsciiEncoded ident;
931 struct GNUNET_CRYPTO_HashAsciiEncoded ident; 954 GNUNET_CRYPTO_hash_to_enc(&my_identity.hashPubKey,&ident);
932 GNUNET_CRYPTO_hash_to_enc(&my_identity.hashPubKey,&ident); 955 GNUNET_asprintf (&host_str, "http://%s/%s%s",test_addr,(char *) &ident,";0");
933 host_str = GNUNET_malloc (strlen ("http:///")+ 1 + strlen (test_addr)+ strlen ((char *) &ident)); 956 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with valid peer identification.\n"));
934 GNUNET_asprintf (&host_str, "http://%s/%s",test_addr,(char *) &ident); 957 test_valid_ident.test_executed = GNUNET_YES;
935 958 send_data ( &test_valid_ident, host_str);
936 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with valid peer identification.\n")); 959 GNUNET_free (host_str);
937 test_valid_ident.test_executed = GNUNET_YES; 960 return;
938 send_data ( &test_valid_ident, host_str); 961 }
939 GNUNET_free (host_str);
940 return;
941 } 962 }
942
943 if (phase==1) 963 if (phase==1)
944 { 964 {
965 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("\nPhase 1: transmit data to all suggested addresses\n\n"));
945 /* Using one of the addresses the plugin proposed */ 966 /* Using one of the addresses the plugin proposed */
946 GNUNET_assert (addr_head->addr != NULL); 967 GNUNET_assert (addr_head->addr != NULL);
947 968
@@ -979,11 +1000,33 @@ static void run_connection_tests( int phase )
979 count ++; 1000 count ++;
980 type ++; 1001 type ++;
981 } 1002 }
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);
982 return; 1011 return;
983 } 1012 }
984 1013
985 if (phase==2) 1014 if (phase==2)
986 { 1015 {
1016 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("\nPhase 2: session selection\n\n"));
1017
1018 struct GNUNET_MessageHeader msg;
1019 msg.size=htons(sizeof(struct GNUNET_MessageHeader));
1020 msg.type = htons(60);
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);
1022
1023 msg.type = htons(61);
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);
1025 }
1026
1027 if (phase==3)
1028 {
1029 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("\nPhase 3: send multiple or big messages after disconnect\n\n"));
987 /* disconnect from peer, so new connections are created */ 1030 /* disconnect from peer, so new connections are created */
988 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Disconnect from peer: `%s'\n", GNUNET_i2s(&my_identity)); 1031 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Disconnect from peer: `%s'\n", GNUNET_i2s(&my_identity));
989 api->disconnect(api->cls, &my_identity); 1032 api->disconnect(api->cls, &my_identity);
@@ -999,7 +1042,7 @@ static void run_connection_tests( int phase )
999 struct GNUNET_MessageHeader * msg2 = &msg1[2]; 1042 struct GNUNET_MessageHeader * msg2 = &msg1[2];
1000 msg2->size = htons(2 * sizeof(struct GNUNET_MessageHeader)); 1043 msg2->size = htons(2 * sizeof(struct GNUNET_MessageHeader));
1001 msg2->type = htons(41); 1044 msg2->type = htons(41);
1002 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); 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);
1003 1046
1004 /* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE-1 */ 1047 /* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE-1 */
1005 GNUNET_free(tmp); 1048 GNUNET_free(tmp);
@@ -1007,7 +1050,15 @@ static void run_connection_tests( int phase )
1007 uint16_t t = (uint16_t)GNUNET_SERVER_MAX_MESSAGE_SIZE-1; 1050 uint16_t t = (uint16_t)GNUNET_SERVER_MAX_MESSAGE_SIZE-1;
1008 msg.size = htons(t); 1051 msg.size = htons(t);
1009 memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader)); 1052 memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader));
1010 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); 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);
1054 GNUNET_free(tmp);
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);
1011 GNUNET_free(tmp); 1062 GNUNET_free(tmp);
1012 } 1063 }
1013 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No more tests to run\n"); 1064 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No more tests to run\n");
@@ -1044,6 +1095,8 @@ run (void *cls,
1044 fail_msgs_transmited_to_local_addrs = 0; 1095 fail_msgs_transmited_to_local_addrs = 0;
1045 fail_msg_transmited_max_size = GNUNET_YES; 1096 fail_msg_transmited_max_size = GNUNET_YES;
1046 fail_multiple_msgs_in_transmission = 0; 1097 fail_multiple_msgs_in_transmission = 0;
1098 fail_session_selection_reliable = GNUNET_YES;
1099 fail_session_selection_reliable = GNUNET_YES;
1047 1100
1048 addr_head = NULL; 1101 addr_head = NULL;
1049 count_str_addr = 0; 1102 count_str_addr = 0;
@@ -1191,6 +1244,8 @@ run (void *cls,
1191 test_valid_ident.test_failed = GNUNET_YES; 1244 test_valid_ident.test_failed = GNUNET_YES;
1192 1245
1193 test_addr = (char *) api->address_to_string (api->cls,addr_head->addr,addr_head->addrlen); 1246 test_addr = (char *) api->address_to_string (api->cls,addr_head->addr,addr_head->addrlen);
1247
1248 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("\nPhase 0\n\n"));
1194 run_connection_tests(0); 1249 run_connection_tests(0);
1195 1250
1196 /* testing finished */ 1251 /* testing finished */