diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-06-07 11:35:29 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-06-07 11:35:29 +0000 |
commit | 70e3cae328728422f2db17ffb2a49f73148ae315 (patch) | |
tree | f3479fc8e4e56e8f40dd69be159cb81ed7b1ee24 /src/transport | |
parent | 970d5c40449685f19b2c15d1960c053fc1904b0b (diff) | |
download | gnunet-70e3cae328728422f2db17ffb2a49f73148ae315.tar.gz gnunet-70e3cae328728422f2db17ffb2a49f73148ae315.zip |
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/test_plugin_transport_http.c | 460 |
1 files changed, 317 insertions, 143 deletions
diff --git a/src/transport/test_plugin_transport_http.c b/src/transport/test_plugin_transport_http.c index bb064fd08..d4cae2e40 100644 --- a/src/transport/test_plugin_transport_http.c +++ b/src/transport/test_plugin_transport_http.c | |||
@@ -25,6 +25,7 @@ | |||
25 | 25 | ||
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_constants.h" | 27 | #include "gnunet_constants.h" |
28 | #include "gnunet_common.h" | ||
28 | #include "gnunet_getopt_lib.h" | 29 | #include "gnunet_getopt_lib.h" |
29 | #include "gnunet_hello_lib.h" | 30 | #include "gnunet_hello_lib.h" |
30 | #include "gnunet_os_lib.h" | 31 | #include "gnunet_os_lib.h" |
@@ -34,6 +35,8 @@ | |||
34 | #include "gnunet_program_lib.h" | 35 | #include "gnunet_program_lib.h" |
35 | #include "gnunet_signatures.h" | 36 | #include "gnunet_signatures.h" |
36 | #include "gnunet_service_lib.h" | 37 | #include "gnunet_service_lib.h" |
38 | #include "gnunet_crypto_lib.h" | ||
39 | |||
37 | #include "plugin_transport.h" | 40 | #include "plugin_transport.h" |
38 | #include "gnunet_statistics_service.h" | 41 | #include "gnunet_statistics_service.h" |
39 | #include "transport.h" | 42 | #include "transport.h" |
@@ -42,6 +45,7 @@ | |||
42 | #define VERBOSE GNUNET_YES | 45 | #define VERBOSE GNUNET_YES |
43 | #define DEBUG GNUNET_NO | 46 | #define DEBUG GNUNET_NO |
44 | #define DEBUG_CURL GNUNET_NO | 47 | #define DEBUG_CURL GNUNET_NO |
48 | #define HTTP_BUFFER_SIZE 2048 | ||
45 | 49 | ||
46 | #define PLUGIN libgnunet_plugin_transport_template | 50 | #define PLUGIN libgnunet_plugin_transport_template |
47 | 51 | ||
@@ -60,17 +64,134 @@ | |||
60 | */ | 64 | */ |
61 | #define WAIT_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) | 65 | #define WAIT_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) |
62 | 66 | ||
67 | |||
68 | |||
69 | /** | ||
70 | * Struct for plugin addresses | ||
71 | */ | ||
72 | struct Plugin_Address | ||
73 | { | ||
74 | /** | ||
75 | * Next field for linked list | ||
76 | */ | ||
77 | struct Plugin_Address * next; | ||
78 | |||
79 | /** | ||
80 | * buffer containing data to send | ||
81 | */ | ||
82 | void * addr; | ||
83 | |||
84 | /** | ||
85 | * amount of data to sent | ||
86 | */ | ||
87 | size_t addrlen; | ||
88 | }; | ||
89 | |||
63 | /** | 90 | /** |
64 | * Message to send using http | 91 | * Message to send using http |
65 | */ | 92 | */ |
66 | struct HTTP_Message | 93 | struct HTTP_Message |
67 | { | 94 | { |
95 | /** | ||
96 | * buffer | ||
97 | */ | ||
68 | char *buf; | 98 | char *buf; |
99 | |||
100 | /** | ||
101 | * current position in buffer | ||
102 | */ | ||
69 | size_t pos; | 103 | size_t pos; |
104 | |||
105 | /** | ||
106 | * buffer size | ||
107 | */ | ||
70 | size_t size; | 108 | size_t size; |
109 | |||
110 | /** | ||
111 | * data size | ||
112 | */ | ||
71 | size_t len; | 113 | size_t len; |
72 | }; | 114 | }; |
73 | 115 | ||
116 | |||
117 | /** | ||
118 | * Struct for plugin addresses | ||
119 | */ | ||
120 | struct HTTP_Transfer | ||
121 | { | ||
122 | /** | ||
123 | * amount of bytes we recieved | ||
124 | */ | ||
125 | size_t data_size; | ||
126 | |||
127 | /** | ||
128 | * buffer for http transfers | ||
129 | */ | ||
130 | unsigned char buf[2048]; | ||
131 | |||
132 | /** | ||
133 | * buffer size this transfer | ||
134 | */ | ||
135 | size_t size; | ||
136 | |||
137 | /** | ||
138 | * amount of bytes we recieved | ||
139 | */ | ||
140 | size_t pos; | ||
141 | |||
142 | /** | ||
143 | * HTTP Header result for transfer | ||
144 | */ | ||
145 | unsigned int http_result_code; | ||
146 | |||
147 | /** | ||
148 | * did the test fail? | ||
149 | */ | ||
150 | unsigned int test_failed; | ||
151 | |||
152 | /** | ||
153 | * was this test already executed? | ||
154 | */ | ||
155 | unsigned int test_executed; | ||
156 | }; | ||
157 | |||
158 | |||
159 | /** | ||
160 | * Network format for IPv4 addresses. | ||
161 | */ | ||
162 | struct IPv4HttpAddress | ||
163 | { | ||
164 | /** | ||
165 | * IPv4 address, in network byte order. | ||
166 | */ | ||
167 | uint32_t ipv4_addr; | ||
168 | |||
169 | /** | ||
170 | * Port number, in network byte order. | ||
171 | */ | ||
172 | uint16_t u_port; | ||
173 | |||
174 | }; | ||
175 | |||
176 | |||
177 | /** | ||
178 | * Network format for IPv6 addresses. | ||
179 | */ | ||
180 | struct IPv6HttpAddress | ||
181 | { | ||
182 | /** | ||
183 | * IPv6 address. | ||
184 | */ | ||
185 | struct in6_addr ipv6_addr; | ||
186 | |||
187 | /** | ||
188 | * Port number, in network byte order. | ||
189 | */ | ||
190 | uint16_t u6_port; | ||
191 | |||
192 | }; | ||
193 | |||
194 | |||
74 | /** | 195 | /** |
75 | * Our public key. | 196 | * Our public key. |
76 | */ | 197 | */ |
@@ -91,6 +212,10 @@ static struct GNUNET_PeerIdentity my_identity; | |||
91 | */ | 212 | */ |
92 | static struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key; | 213 | static struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key; |
93 | 214 | ||
215 | /** | ||
216 | * Peer's port | ||
217 | */ | ||
218 | static long long unsigned int port; | ||
94 | 219 | ||
95 | /** | 220 | /** |
96 | * Our scheduler. | 221 | * Our scheduler. |
@@ -133,53 +258,15 @@ static GNUNET_SCHEDULER_TaskIdentifier ti_send; | |||
133 | const struct GNUNET_PeerIdentity * p; | 258 | const struct GNUNET_PeerIdentity * p; |
134 | 259 | ||
135 | /** | 260 | /** |
136 | * Struct for plugin addresses | 261 | * buffer for data to send |
137 | */ | 262 | */ |
138 | struct Plugin_Address | 263 | static struct HTTP_Message buffer_out; |
139 | { | ||
140 | /** | ||
141 | * Next field for linked list | ||
142 | */ | ||
143 | struct Plugin_Address * next; | ||
144 | |||
145 | /** | ||
146 | * buffer containing data to send | ||
147 | */ | ||
148 | void * addr; | ||
149 | |||
150 | /** | ||
151 | * amount of data to sent | ||
152 | */ | ||
153 | size_t addrlen; | ||
154 | }; | ||
155 | 264 | ||
156 | /** | 265 | /** |
157 | * Struct for plugin addresses | 266 | * buffer for data to recieve |
158 | */ | 267 | */ |
159 | struct HTTP_Transfer | 268 | static struct HTTP_Message buffer_in; |
160 | { | ||
161 | /** | ||
162 | * HTTP Header result for transfer | ||
163 | */ | ||
164 | unsigned int http_result_code; | ||
165 | |||
166 | /** | ||
167 | * amount of bytes we recieved | ||
168 | */ | ||
169 | size_t data_size; | ||
170 | |||
171 | unsigned char buf[2048]; | ||
172 | |||
173 | /** | ||
174 | * amount of bytes we recieved | ||
175 | */ | ||
176 | size_t pos; | ||
177 | |||
178 | size_t size; | ||
179 | |||
180 | unsigned int test_failed; | ||
181 | 269 | ||
182 | }; | ||
183 | 270 | ||
184 | struct Plugin_Address * addr_head; | 271 | struct Plugin_Address * addr_head; |
185 | 272 | ||
@@ -208,11 +295,25 @@ static int fail_pretty_printer_count; | |||
208 | static int fail_addr_to_str; | 295 | static int fail_addr_to_str; |
209 | 296 | ||
210 | /** | 297 | /** |
211 | * Did the test pass or fail? | 298 | * Test: connect to peer without peer identification |
212 | */ | 299 | */ |
213 | static struct HTTP_Transfer testtransfer_no_ident; | 300 | static struct HTTP_Transfer test_no_ident; |
214 | 301 | ||
302 | /** | ||
303 | * Test: connect to peer without peer identification | ||
304 | */ | ||
305 | static struct HTTP_Transfer test_too_short_ident; | ||
215 | 306 | ||
307 | /** | ||
308 | * Test: connect to peer without peer identification | ||
309 | */ | ||
310 | static struct HTTP_Transfer test_too_long_ident; | ||
311 | |||
312 | |||
313 | /** | ||
314 | * Test: connect to peer with valid peer identification | ||
315 | */ | ||
316 | static struct HTTP_Transfer test_valid_ident; | ||
216 | 317 | ||
217 | /** | 318 | /** |
218 | * Did the test pass or fail? | 319 | * Did the test pass or fail? |
@@ -232,11 +333,6 @@ CURL *curl_handle; | |||
232 | static CURLM *multi_handle; | 333 | static CURLM *multi_handle; |
233 | 334 | ||
234 | /** | 335 | /** |
235 | * Test message to send | ||
236 | */ | ||
237 | struct HTTP_Message * msg; | ||
238 | |||
239 | /** | ||
240 | * The task sending data | 336 | * The task sending data |
241 | */ | 337 | */ |
242 | static GNUNET_SCHEDULER_TaskIdentifier http_task_send; | 338 | static GNUNET_SCHEDULER_TaskIdentifier http_task_send; |
@@ -247,10 +343,20 @@ static GNUNET_SCHEDULER_TaskIdentifier http_task_send; | |||
247 | static void | 343 | static void |
248 | shutdown_clean () | 344 | shutdown_clean () |
249 | { | 345 | { |
250 | if ((fail_notify_address == GNUNET_NO) && (fail_pretty_printer == GNUNET_NO) && (fail_addr_to_str == GNUNET_NO) && (testtransfer_no_ident.test_failed == GNUNET_NO)) | 346 | |
347 | /* Evaluate results */ | ||
348 | if ((fail_notify_address == GNUNET_NO) && (fail_pretty_printer == GNUNET_NO) && (fail_addr_to_str == GNUNET_NO) && | ||
349 | (test_no_ident.test_failed == GNUNET_NO) && (test_too_short_ident.test_failed == GNUNET_NO) && (test_too_long_ident.test_failed == GNUNET_NO) && | ||
350 | (test_valid_ident.test_failed == GNUNET_NO)) | ||
351 | { | ||
352 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Tests successful\n"); | ||
251 | fail = 0; | 353 | fail = 0; |
354 | } | ||
252 | else | 355 | else |
356 | { | ||
357 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Tests failed\n"); | ||
253 | fail = 1; | 358 | fail = 1; |
359 | } | ||
254 | 360 | ||
255 | curl_multi_cleanup(multi_handle); | 361 | curl_multi_cleanup(multi_handle); |
256 | 362 | ||
@@ -280,8 +386,8 @@ shutdown_clean () | |||
280 | 386 | ||
281 | GNUNET_SCHEDULER_shutdown(sched); | 387 | GNUNET_SCHEDULER_shutdown(sched); |
282 | 388 | ||
283 | GNUNET_free(msg->buf); | 389 | GNUNET_free (buffer_in.buf); |
284 | GNUNET_free(msg); | 390 | GNUNET_free (buffer_out.buf); |
285 | 391 | ||
286 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Exiting testcase\n"); | 392 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Exiting testcase\n"); |
287 | exit(fail); | 393 | exit(fail); |
@@ -350,7 +456,6 @@ receive (void *cls, | |||
350 | return GNUNET_TIME_UNIT_ZERO; | 456 | return GNUNET_TIME_UNIT_ZERO; |
351 | } | 457 | } |
352 | 458 | ||
353 | int done; | ||
354 | static size_t | 459 | static size_t |
355 | putBuffer (void *stream, size_t size, size_t nmemb, void *ptr) | 460 | putBuffer (void *stream, size_t size, size_t nmemb, void *ptr) |
356 | { | 461 | { |
@@ -368,16 +473,15 @@ putBuffer (void *stream, size_t size, size_t nmemb, void *ptr) | |||
368 | 473 | ||
369 | static size_t copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) | 474 | static size_t copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) |
370 | { | 475 | { |
371 | struct HTTP_Transfer * res = (struct HTTP_Transfer *) ctx; | ||
372 | |||
373 | res->data_size = size * nmemb; | ||
374 | 476 | ||
375 | if (res->pos + size * nmemb > res->size) | 477 | if (buffer_in.pos + size * nmemb > buffer_in.size) |
376 | return 0; /* overflow */ | 478 | return 0; /* overflow */ |
377 | memcpy (&res->buf[res->pos], ptr, size * nmemb); | 479 | |
378 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Send completed. %s\n",res->buf); | 480 | buffer_in.len = size * nmemb; |
379 | res->pos += size * nmemb; | 481 | memcpy (&buffer_in.buf[buffer_in.pos], ptr, size * nmemb); |
380 | return size * nmemb; | 482 | buffer_in.pos += size * nmemb; |
483 | buffer_in.len = buffer_in.pos; | ||
484 | return buffer_in.pos; | ||
381 | } | 485 | } |
382 | 486 | ||
383 | static size_t header_function( void *ptr, size_t size, size_t nmemb, void *stream) | 487 | static size_t header_function( void *ptr, size_t size, size_t nmemb, void *stream) |
@@ -390,11 +494,18 @@ static size_t header_function( void *ptr, size_t size, size_t nmemb, void *strea | |||
390 | memcpy(tmp,ptr,len); | 494 | memcpy(tmp,ptr,len); |
391 | if (tmp[len-2] == 13) | 495 | if (tmp[len-2] == 13) |
392 | tmp[len-2]= '\0'; | 496 | tmp[len-2]= '\0'; |
497 | if (0==strcmp (tmp,"HTTP/1.1 100 Continue")) | ||
498 | { | ||
499 | res->http_result_code=100; | ||
500 | } | ||
501 | if (0==strcmp (tmp,"HTTP/1.1 200 OK")) | ||
502 | { | ||
503 | res->http_result_code=200; | ||
504 | } | ||
393 | if (0==strcmp (tmp,"HTTP/1.1 404 Not Found")) | 505 | if (0==strcmp (tmp,"HTTP/1.1 404 Not Found")) |
394 | { | 506 | { |
395 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "404\n"); | ||
396 | res->http_result_code=404; | 507 | res->http_result_code=404; |
397 | } | 508 | } |
398 | 509 | ||
399 | GNUNET_free (tmp); | 510 | GNUNET_free (tmp); |
400 | return size * nmemb; | 511 | return size * nmemb; |
@@ -402,6 +513,8 @@ static size_t header_function( void *ptr, size_t size, size_t nmemb, void *strea | |||
402 | 513 | ||
403 | static size_t send_prepare( struct HTTP_Transfer * result); | 514 | static size_t send_prepare( struct HTTP_Transfer * result); |
404 | 515 | ||
516 | static void run_connection_tests( void ); | ||
517 | |||
405 | static void send_execute (void *cls, | 518 | static void send_execute (void *cls, |
406 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 519 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
407 | { | 520 | { |
@@ -448,22 +561,30 @@ static void send_execute (void *cls, | |||
448 | curl_easy_strerror (msg->data.result)); | 561 | curl_easy_strerror (msg->data.result)); |
449 | /* sending msg failed*/ | 562 | /* sending msg failed*/ |
450 | } | 563 | } |
451 | else | 564 | if (res == &test_no_ident) |
452 | { | ||
453 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Send completed %u\n", res->data_size); | ||
454 | /* sending completed */ | ||
455 | } | ||
456 | if (cls == &testtransfer_no_ident) | ||
457 | { | 565 | { |
458 | if ((res->http_result_code==404) && (res->data_size==208)) | 566 | if ((res->http_result_code==404) && (buffer_in.len==208)) |
567 | res->test_failed = GNUNET_NO; | ||
568 | } | ||
569 | if (res == &test_too_short_ident) | ||
570 | { | ||
571 | if ((res->http_result_code==404) && (buffer_in.len==208)) | ||
572 | res->test_failed = GNUNET_NO; | ||
573 | } | ||
574 | if (res == &test_too_long_ident) | ||
575 | { | ||
576 | if ((res->http_result_code==404) && (buffer_in.len==208)) | ||
577 | res->test_failed = GNUNET_NO; | ||
578 | } | ||
579 | if (res == &test_valid_ident) | ||
580 | { | ||
581 | if ((res->http_result_code==200)) | ||
459 | res->test_failed = GNUNET_NO; | 582 | res->test_failed = GNUNET_NO; |
460 | else | ||
461 | res->test_failed = GNUNET_YES; | ||
462 | } | 583 | } |
463 | |||
464 | curl_easy_cleanup(curl_handle); | 584 | curl_easy_cleanup(curl_handle); |
465 | curl_handle=NULL; | 585 | curl_handle=NULL; |
466 | shutdown_clean(); | 586 | |
587 | run_connection_tests(); | ||
467 | return; | 588 | return; |
468 | default: | 589 | default: |
469 | break; | 590 | break; |
@@ -538,7 +659,7 @@ static size_t send_prepare( struct HTTP_Transfer * result) | |||
538 | /** | 659 | /** |
539 | * function to send data to server | 660 | * function to send data to server |
540 | */ | 661 | */ |
541 | static int send_data(struct HTTP_Message *msg, struct HTTP_Transfer * result, char * url) | 662 | static int send_data( struct HTTP_Transfer * result, char * url) |
542 | { | 663 | { |
543 | 664 | ||
544 | curl_handle = curl_easy_init(); | 665 | curl_handle = curl_easy_init(); |
@@ -557,8 +678,8 @@ static int send_data(struct HTTP_Message *msg, struct HTTP_Transfer * result, ch | |||
557 | curl_easy_setopt (curl_handle, CURLOPT_WRITEFUNCTION, ©Buffer); | 678 | curl_easy_setopt (curl_handle, CURLOPT_WRITEFUNCTION, ©Buffer); |
558 | curl_easy_setopt (curl_handle, CURLOPT_WRITEDATA, result); | 679 | curl_easy_setopt (curl_handle, CURLOPT_WRITEDATA, result); |
559 | curl_easy_setopt (curl_handle, CURLOPT_READFUNCTION, &putBuffer); | 680 | curl_easy_setopt (curl_handle, CURLOPT_READFUNCTION, &putBuffer); |
560 | curl_easy_setopt (curl_handle, CURLOPT_READDATA, msg); | 681 | curl_easy_setopt (curl_handle, CURLOPT_READDATA, &buffer_out); |
561 | curl_easy_setopt(curl_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t) msg->len); | 682 | curl_easy_setopt(curl_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t) buffer_out.len); |
562 | curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 30); | 683 | curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 30); |
563 | curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 20); | 684 | curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 20); |
564 | 685 | ||
@@ -569,40 +690,6 @@ static int send_data(struct HTTP_Message *msg, struct HTTP_Transfer * result, ch | |||
569 | return GNUNET_OK; | 690 | return GNUNET_OK; |
570 | } | 691 | } |
571 | 692 | ||
572 | /** | ||
573 | * Network format for IPv4 addresses. | ||
574 | */ | ||
575 | struct IPv4HttpAddress | ||
576 | { | ||
577 | /** | ||
578 | * IPv4 address, in network byte order. | ||
579 | */ | ||
580 | uint32_t ipv4_addr; | ||
581 | |||
582 | /** | ||
583 | * Port number, in network byte order. | ||
584 | */ | ||
585 | uint16_t u_port; | ||
586 | |||
587 | }; | ||
588 | |||
589 | |||
590 | /** | ||
591 | * Network format for IPv6 addresses. | ||
592 | */ | ||
593 | struct IPv6HttpAddress | ||
594 | { | ||
595 | /** | ||
596 | * IPv6 address. | ||
597 | */ | ||
598 | struct in6_addr ipv6_addr; | ||
599 | |||
600 | /** | ||
601 | * Port number, in network byte order. | ||
602 | */ | ||
603 | uint16_t u6_port; | ||
604 | |||
605 | }; | ||
606 | 693 | ||
607 | /** | 694 | /** |
608 | * Plugin notifies transport (aka testcase) about its addresses | 695 | * Plugin notifies transport (aka testcase) about its addresses |
@@ -704,6 +791,85 @@ static void pretty_printer_cb (void *cls, | |||
704 | fail_pretty_printer_count++; | 791 | fail_pretty_printer_count++; |
705 | } | 792 | } |
706 | 793 | ||
794 | /** | ||
795 | * Runs every single test to test the plugin | ||
796 | */ | ||
797 | static void run_connection_tests( void ) | ||
798 | { | ||
799 | char * host_str; | ||
800 | |||
801 | /* resetting buffers */ | ||
802 | buffer_in.size = HTTP_BUFFER_SIZE; | ||
803 | buffer_in.pos = 0; | ||
804 | buffer_in.len = 0; | ||
805 | |||
806 | buffer_out.size = HTTP_BUFFER_SIZE; | ||
807 | buffer_out.pos = 0; | ||
808 | buffer_out.len = 0; | ||
809 | |||
810 | |||
811 | if (test_no_ident.test_executed == GNUNET_NO) | ||
812 | { | ||
813 | /* Connecting to peer without identification */ | ||
814 | host_str = GNUNET_malloc (strlen ("http://localhost:12389/")+1); | ||
815 | GNUNET_asprintf (&host_str, "http://localhost:%u/",port); | ||
816 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer without any peer identification.\n"), host_str); | ||
817 | test_no_ident.test_executed = GNUNET_YES; | ||
818 | send_data ( &test_no_ident, host_str); | ||
819 | GNUNET_free (host_str); | ||
820 | |||
821 | return; | ||
822 | } | ||
823 | |||
824 | if (test_too_short_ident.test_executed == GNUNET_NO) | ||
825 | { | ||
826 | char * ident = "AAAAAAAAAA"; | ||
827 | /* Connecting to peer with too short identification */ | ||
828 | host_str = GNUNET_malloc (strlen ("http://localhost:12389/") + strlen (ident)); | ||
829 | GNUNET_asprintf (&host_str, "http://localhost:%u/%s",port,ident); | ||
830 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too short peer identification.\n"), host_str); | ||
831 | test_too_short_ident.test_executed = GNUNET_YES; | ||
832 | send_data ( &test_too_short_ident, host_str); | ||
833 | GNUNET_free (host_str); | ||
834 | |||
835 | return; | ||
836 | } | ||
837 | |||
838 | if (test_too_long_ident.test_executed == GNUNET_NO) | ||
839 | { | ||
840 | char * ident = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; | ||
841 | |||
842 | /* Connecting to peer with too long identification */ | ||
843 | host_str = GNUNET_malloc (strlen ("http://localhost:12389/") + strlen (ident)); | ||
844 | GNUNET_asprintf (&host_str, "http://localhost:%u/%s",port,ident); | ||
845 | |||
846 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too long peer identification.\n"), host_str); | ||
847 | test_too_long_ident.test_executed = GNUNET_YES; | ||
848 | send_data ( &test_too_long_ident, host_str); | ||
849 | GNUNET_free (host_str); | ||
850 | |||
851 | return; | ||
852 | } | ||
853 | if (test_valid_ident.test_executed == GNUNET_NO) | ||
854 | { | ||
855 | struct GNUNET_CRYPTO_HashAsciiEncoded result; | ||
856 | |||
857 | GNUNET_CRYPTO_hash_to_enc(&my_identity.hashPubKey,&result); | ||
858 | host_str = GNUNET_malloc (strlen ("http://localhost:12389/") + strlen ((const char *) &result)); | ||
859 | GNUNET_asprintf (&host_str, "http://localhost:%u/%s",port,(char *) &result); | ||
860 | |||
861 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer %s with valid peer identification.\n"), host_str); | ||
862 | test_valid_ident.test_executed = GNUNET_YES; | ||
863 | send_data ( &test_valid_ident, host_str); | ||
864 | GNUNET_free (host_str); | ||
865 | |||
866 | return; | ||
867 | } | ||
868 | |||
869 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No more tests to run\n"); | ||
870 | shutdown_clean(); | ||
871 | } | ||
872 | |||
707 | 873 | ||
708 | /** | 874 | /** |
709 | * Runs the test. | 875 | * Runs the test. |
@@ -726,11 +892,9 @@ run (void *cls, | |||
726 | struct Plugin_Address * cur; | 892 | struct Plugin_Address * cur; |
727 | struct Plugin_Address * tmp; | 893 | struct Plugin_Address * tmp; |
728 | const char * addr_str; | 894 | const char * addr_str; |
729 | char * host_str; | 895 | |
730 | unsigned int count_str_addr; | 896 | unsigned int count_str_addr; |
731 | unsigned int suggest_res; | 897 | unsigned int suggest_res; |
732 | unsigned int res; | ||
733 | long long unsigned int port; | ||
734 | 898 | ||
735 | fail_pretty_printer = GNUNET_YES; | 899 | fail_pretty_printer = GNUNET_YES; |
736 | fail_notify_address = GNUNET_YES; | 900 | fail_notify_address = GNUNET_YES; |
@@ -756,6 +920,20 @@ run (void *cls, | |||
756 | fail = 1; | 920 | fail = 1; |
757 | return; | 921 | return; |
758 | } | 922 | } |
923 | |||
924 | if ((GNUNET_OK != | ||
925 | GNUNET_CONFIGURATION_get_value_number (cfg, | ||
926 | "transport-http", | ||
927 | "PORT", | ||
928 | &port)) || | ||
929 | (port > 65535) ) | ||
930 | { | ||
931 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | ||
932 | "http", | ||
933 | _ | ||
934 | ("Require valid port number for transport plugin `%s' in configuration!\n"), | ||
935 | "transport-http"); | ||
936 | } | ||
759 | max_connect_per_transport = (uint32_t) tneigh; | 937 | max_connect_per_transport = (uint32_t) tneigh; |
760 | my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); | 938 | my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); |
761 | GNUNET_free (keyfile); | 939 | GNUNET_free (keyfile); |
@@ -839,42 +1017,38 @@ run (void *cls, | |||
839 | /* test sending to client */ | 1017 | /* test sending to client */ |
840 | multi_handle = curl_multi_init(); | 1018 | multi_handle = curl_multi_init(); |
841 | 1019 | ||
842 | /*building messages */ | 1020 | /* Setting up buffers */ |
843 | msg = GNUNET_malloc (sizeof (struct HTTP_Message)); | 1021 | buffer_in.size = HTTP_BUFFER_SIZE; |
844 | msg->size = 2048; | 1022 | buffer_in.buf = GNUNET_malloc (HTTP_BUFFER_SIZE); |
845 | msg->pos = 0; | 1023 | buffer_in.pos = 0; |
846 | msg->buf = GNUNET_malloc (2048); | 1024 | buffer_in.len = 0; |
847 | testtransfer_no_ident.size=2048; | ||
848 | testtransfer_no_ident.test_failed = GNUNET_YES; | ||
849 | 1025 | ||
1026 | buffer_out.size = HTTP_BUFFER_SIZE; | ||
1027 | buffer_out.buf = GNUNET_malloc (HTTP_BUFFER_SIZE); | ||
1028 | buffer_out.pos = 0; | ||
1029 | buffer_out.len = 0; | ||
850 | 1030 | ||
851 | if ((GNUNET_OK != | 1031 | /* Setting up connection tests */ |
852 | GNUNET_CONFIGURATION_get_value_number (cfg, | ||
853 | "transport-http", | ||
854 | "PORT", | ||
855 | &port)) || | ||
856 | (port > 65535) ) | ||
857 | { | ||
858 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | ||
859 | "http", | ||
860 | _ | ||
861 | ("Require valid port number for transport plugin `%s' in configuration!\n"), | ||
862 | "transport-http"); | ||
863 | } | ||
864 | 1032 | ||
865 | /* Connecting to peer without identification */ | 1033 | /* Test: connecting without a peer identification */ |
866 | host_str = GNUNET_malloc (strlen ("http://localhost:12389/")); | 1034 | test_no_ident.test_executed = GNUNET_NO; |
867 | GNUNET_asprintf (&host_str, "http://localhost:%u/",port); | 1035 | test_no_ident.test_failed = GNUNET_YES; |
868 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer %s without any peer identification.\n"), host_str); | ||
869 | res = send_data (msg, &testtransfer_no_ident, host_str); | ||
870 | GNUNET_free (host_str); | ||
871 | 1036 | ||
1037 | /* Test: connecting with too short peer identification */ | ||
1038 | test_too_short_ident.test_executed = GNUNET_NO; | ||
1039 | test_too_short_ident.test_failed = GNUNET_YES; | ||
872 | 1040 | ||
873 | /* Add more tests */ | 1041 | /* Test: connecting with too long peer identification */ |
1042 | test_too_long_ident.test_executed = GNUNET_NO; | ||
1043 | test_too_long_ident.test_failed = GNUNET_YES; | ||
874 | 1044 | ||
875 | /* testing finished */ | 1045 | /* Test: connecting with valid identification */ |
1046 | test_valid_ident.test_executed = GNUNET_NO; | ||
1047 | test_valid_ident.test_failed = GNUNET_YES; | ||
876 | 1048 | ||
1049 | run_connection_tests(); | ||
877 | 1050 | ||
1051 | /* testing finished */ | ||
878 | 1052 | ||
879 | return; | 1053 | return; |
880 | } | 1054 | } |