diff options
Diffstat (limited to 'src/transport/test_plugin_transport_https.c')
-rw-r--r-- | src/transport/test_plugin_transport_https.c | 937 |
1 files changed, 520 insertions, 417 deletions
diff --git a/src/transport/test_plugin_transport_https.c b/src/transport/test_plugin_transport_https.c index 0845c8cd4..e6e71c7f5 100644 --- a/src/transport/test_plugin_transport_https.c +++ b/src/transport/test_plugin_transport_https.c | |||
@@ -75,12 +75,12 @@ struct Plugin_Address | |||
75 | /** | 75 | /** |
76 | * Next field for linked list | 76 | * Next field for linked list |
77 | */ | 77 | */ |
78 | struct Plugin_Address * next; | 78 | struct Plugin_Address *next; |
79 | 79 | ||
80 | /** | 80 | /** |
81 | * buffer containing data to send | 81 | * buffer containing data to send |
82 | */ | 82 | */ |
83 | void * addr; | 83 | void *addr; |
84 | 84 | ||
85 | /** | 85 | /** |
86 | * amount of data to sent | 86 | * amount of data to sent |
@@ -162,9 +162,9 @@ struct HTTP_Transfer | |||
162 | */ | 162 | */ |
163 | struct IPv4HttpAddress | 163 | struct IPv4HttpAddress |
164 | { | 164 | { |
165 | struct IPv4HttpAddress * next; | 165 | struct IPv4HttpAddress *next; |
166 | 166 | ||
167 | struct IPv4HttpAddress * prev; | 167 | struct IPv4HttpAddress *prev; |
168 | 168 | ||
169 | /** | 169 | /** |
170 | * IPv4 address, in network byte order. | 170 | * IPv4 address, in network byte order. |
@@ -184,9 +184,9 @@ struct IPv4HttpAddress | |||
184 | */ | 184 | */ |
185 | struct IPv6HttpAddress | 185 | struct IPv6HttpAddress |
186 | { | 186 | { |
187 | struct IPv6HttpAddress * next; | 187 | struct IPv6HttpAddress *next; |
188 | 188 | ||
189 | struct IPv6HttpAddress * prev; | 189 | struct IPv6HttpAddress *prev; |
190 | 190 | ||
191 | /** | 191 | /** |
192 | * IPv6 address. | 192 | * IPv6 address. |
@@ -228,7 +228,7 @@ static long long unsigned int port; | |||
228 | /** | 228 | /** |
229 | * Peer's addr | 229 | * Peer's addr |
230 | */ | 230 | */ |
231 | static char * test_addr; | 231 | static char *test_addr; |
232 | 232 | ||
233 | /** | 233 | /** |
234 | * Our statistics handle. | 234 | * Our statistics handle. |
@@ -276,12 +276,13 @@ static struct HTTP_Message buffer_out; | |||
276 | static struct HTTP_Message buffer_in; | 276 | static struct HTTP_Message buffer_in; |
277 | 277 | ||
278 | 278 | ||
279 | struct Plugin_Address * addr_head; | 279 | struct Plugin_Address *addr_head; |
280 | 280 | ||
281 | /** | 281 | /** |
282 | * Did the test pass or fail? | 282 | * Did the test pass or fail? |
283 | */ | 283 | */ |
284 | static int fail_notify_address; | 284 | static int fail_notify_address; |
285 | |||
285 | /** | 286 | /** |
286 | * Did the test pass or fail? | 287 | * Did the test pass or fail? |
287 | */ | 288 | */ |
@@ -386,10 +387,10 @@ static CURLM *multi_handle; | |||
386 | static GNUNET_SCHEDULER_TaskIdentifier http_task_send; | 387 | static GNUNET_SCHEDULER_TaskIdentifier http_task_send; |
387 | 388 | ||
388 | 389 | ||
389 | static char * key_file; | 390 | static char *key_file; |
390 | static char * cert_file; | 391 | static char *cert_file; |
391 | 392 | ||
392 | static char * servicehome; | 393 | static char *servicehome; |
393 | 394 | ||
394 | /** | 395 | /** |
395 | * Shutdown testcase | 396 | * Shutdown testcase |
@@ -397,28 +398,41 @@ static char * servicehome; | |||
397 | static void | 398 | static void |
398 | shutdown_clean () | 399 | shutdown_clean () |
399 | { | 400 | { |
400 | struct Plugin_Address * tmp; | 401 | struct Plugin_Address *tmp; |
401 | 402 | ||
402 | /* Evaluate results */ | 403 | /* Evaluate results */ |
403 | fail = 0; | 404 | fail = 0; |
404 | if ((fail_notify_address == GNUNET_YES) || (fail_pretty_printer == GNUNET_YES) || (fail_addr_to_str == GNUNET_YES)) | 405 | if ((fail_notify_address == GNUNET_YES) || (fail_pretty_printer == GNUNET_YES) |
406 | || (fail_addr_to_str == GNUNET_YES)) | ||
405 | { | 407 | { |
406 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Phase 0: Test plugin functions failed\n")); | 408 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
409 | _("Phase 0: Test plugin functions failed\n")); | ||
407 | fail = 1; | 410 | fail = 1; |
408 | } | 411 | } |
409 | 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)) | 412 | if ((test_no_ident.test_failed == GNUNET_YES) || |
413 | (test_too_short_ident.test_failed == GNUNET_YES) || | ||
414 | (test_too_long_ident.test_failed == GNUNET_YES) || | ||
415 | (test_valid_ident.test_failed == GNUNET_YES)) | ||
410 | { | 416 | { |
411 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Phase 1: Test connect with wrong data failed\n")); | 417 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
418 | _("Phase 1: Test connect with wrong data failed\n")); | ||
412 | fail = 1; | 419 | fail = 1; |
413 | } | 420 | } |
414 | 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)) | 421 | if ((fail_session_selection_any != GNUNET_NO) || |
422 | (fail_session_selection_reliable != GNUNET_NO) || | ||
423 | (fail_session_selection_session != GNUNET_NO) || | ||
424 | (fail_session_selection_session_big != GNUNET_NO)) | ||
415 | { | 425 | { |
416 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Phase 2: Test session selection failed\n")); | 426 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
427 | _("Phase 2: Test session selection failed\n")); | ||
417 | fail = 1; | 428 | fail = 1; |
418 | } | 429 | } |
419 | if ((fail_msgs_transmited_to_local_addrs != count_str_addr) || (fail_multiple_msgs_in_transmission != 2) || (fail_msg_transmited_max_size == GNUNET_YES)) | 430 | if ((fail_msgs_transmited_to_local_addrs != count_str_addr) || |
431 | (fail_multiple_msgs_in_transmission != 2) || | ||
432 | (fail_msg_transmited_max_size == GNUNET_YES)) | ||
420 | { | 433 | { |
421 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Phase 3: Test sending with plugin failed\n")); | 434 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
435 | _("Phase 3: Test sending with plugin failed\n")); | ||
422 | fail = 1; | 436 | fail = 1; |
423 | } | 437 | } |
424 | if (fail != 1) | 438 | if (fail != 1) |
@@ -426,9 +440,9 @@ shutdown_clean () | |||
426 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All tests successful\n"); | 440 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All tests successful\n"); |
427 | } | 441 | } |
428 | 442 | ||
429 | api->disconnect(api->cls,&my_identity); | 443 | api->disconnect (api->cls, &my_identity); |
430 | 444 | ||
431 | curl_multi_cleanup(multi_handle); | 445 | curl_multi_cleanup (multi_handle); |
432 | 446 | ||
433 | if (NULL != curl_handle) | 447 | if (NULL != curl_handle) |
434 | curl_easy_cleanup (curl_handle); | 448 | curl_easy_cleanup (curl_handle); |
@@ -439,49 +453,57 @@ shutdown_clean () | |||
439 | tmp = addr_head->next; | 453 | tmp = addr_head->next; |
440 | GNUNET_free (addr_head->addr); | 454 | GNUNET_free (addr_head->addr); |
441 | GNUNET_free (addr_head); | 455 | GNUNET_free (addr_head); |
442 | addr_head=tmp; | 456 | addr_head = tmp; |
443 | } | 457 | } |
444 | 458 | ||
445 | if (ti_send != GNUNET_SCHEDULER_NO_TASK) | 459 | if (ti_send != GNUNET_SCHEDULER_NO_TASK) |
446 | { | 460 | { |
447 | GNUNET_SCHEDULER_cancel(ti_send); | 461 | GNUNET_SCHEDULER_cancel (ti_send); |
448 | ti_send = GNUNET_SCHEDULER_NO_TASK; | 462 | ti_send = GNUNET_SCHEDULER_NO_TASK; |
449 | } | 463 | } |
450 | 464 | ||
451 | if (http_task_send != GNUNET_SCHEDULER_NO_TASK) | 465 | if (http_task_send != GNUNET_SCHEDULER_NO_TASK) |
452 | { | 466 | { |
453 | GNUNET_SCHEDULER_cancel(http_task_send); | 467 | GNUNET_SCHEDULER_cancel (http_task_send); |
454 | http_task_send = GNUNET_SCHEDULER_NO_TASK; | 468 | http_task_send = GNUNET_SCHEDULER_NO_TASK; |
455 | } | 469 | } |
456 | 470 | ||
457 | if (ti_timeout != GNUNET_SCHEDULER_NO_TASK) | 471 | if (ti_timeout != GNUNET_SCHEDULER_NO_TASK) |
458 | { | 472 | { |
459 | GNUNET_SCHEDULER_cancel(ti_timeout); | 473 | GNUNET_SCHEDULER_cancel (ti_timeout); |
460 | ti_timeout = GNUNET_SCHEDULER_NO_TASK; | 474 | ti_timeout = GNUNET_SCHEDULER_NO_TASK; |
461 | } | 475 | } |
462 | 476 | ||
463 | GNUNET_free(test_addr); | 477 | GNUNET_free (test_addr); |
464 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unloading https plugin\n"); | 478 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unloading https plugin\n"); |
465 | GNUNET_assert (NULL == GNUNET_PLUGIN_unload ("libgnunet_gnunet_transport_plugin.https", api)); | 479 | GNUNET_assert (NULL == |
480 | GNUNET_PLUGIN_unload | ||
481 | ("libgnunet_gnunet_transport_plugin.https", api)); | ||
466 | 482 | ||
467 | GNUNET_SCHEDULER_shutdown(); | 483 | GNUNET_SCHEDULER_shutdown (); |
468 | GNUNET_DISK_directory_remove ("/tmp/test_gnunet_transport_plugin.http"); | 484 | GNUNET_DISK_directory_remove ("/tmp/test_gnunet_transport_plugin.http"); |
469 | 485 | ||
470 | struct stat sbuf; | 486 | struct stat sbuf; |
471 | if (0 == stat (cert_file, &sbuf )) | 487 | |
488 | if (0 == stat (cert_file, &sbuf)) | ||
472 | { | 489 | { |
473 | if (0 == remove(cert_file)) | 490 | if (0 == remove (cert_file)) |
474 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed existing certificate file `%s'\n",cert_file); | 491 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
475 | else | 492 | "Successfully removed existing certificate file `%s'\n", |
476 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove certfile `%s'\n",cert_file); | 493 | cert_file); |
494 | else | ||
495 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove certfile `%s'\n", | ||
496 | cert_file); | ||
477 | } | 497 | } |
478 | 498 | ||
479 | if (0 == stat (key_file, &sbuf )) | 499 | if (0 == stat (key_file, &sbuf)) |
480 | { | 500 | { |
481 | if (0 == remove(key_file)) | 501 | if (0 == remove (key_file)) |
482 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed private key file `%s'\n",key_file); | 502 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
483 | else | 503 | "Successfully removed private key file `%s'\n", key_file); |
484 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to private key file `%s'\n",key_file); | 504 | else |
505 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to private key file `%s'\n", | ||
506 | key_file); | ||
485 | } | 507 | } |
486 | 508 | ||
487 | GNUNET_free (key_file); | 509 | GNUNET_free (key_file); |
@@ -495,7 +517,7 @@ shutdown_clean () | |||
495 | GNUNET_free (servicehome); | 517 | GNUNET_free (servicehome); |
496 | } | 518 | } |
497 | 519 | ||
498 | exit(fail); | 520 | exit (fail); |
499 | return; | 521 | return; |
500 | } | 522 | } |
501 | 523 | ||
@@ -507,97 +529,105 @@ shutdown_clean () | |||
507 | * @result GNUNET_OK or GNUNET_SYSERR | 529 | * @result GNUNET_OK or GNUNET_SYSERR |
508 | */ | 530 | */ |
509 | 531 | ||
510 | static void task_send_cont (void *cls, | 532 | static void |
511 | const struct GNUNET_PeerIdentity * target, | 533 | task_send_cont (void *cls, const struct GNUNET_PeerIdentity *target, int result) |
512 | int result) | ||
513 | { | 534 | { |
514 | if ((cls == &fail_msg_transmited_bigger_max_size) && (result == GNUNET_SYSERR)) | 535 | if ((cls == &fail_msg_transmited_bigger_max_size) && |
536 | (result == GNUNET_SYSERR)) | ||
515 | { | 537 | { |
516 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message bigger max msg size was not sent!\n"); | 538 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
539 | "Message bigger max msg size was not sent!\n"); | ||
517 | fail_msg_transmited_bigger_max_size = GNUNET_NO; | 540 | fail_msg_transmited_bigger_max_size = GNUNET_NO; |
518 | return; | 541 | return; |
519 | } | 542 | } |
520 | 543 | ||
521 | if ((cls == &fail_msg_transmited_max_size) && (result == GNUNET_OK)) | 544 | if ((cls == &fail_msg_transmited_max_size) && (result == GNUNET_OK)) |
522 | { | 545 | { |
523 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message with max msg size succesfully sent!\n",fail_msgs_transmited_to_local_addrs); | 546 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
547 | "Message with max msg size succesfully sent!\n", | ||
548 | fail_msgs_transmited_to_local_addrs); | ||
524 | fail_msg_transmited_max_size = GNUNET_NO; | 549 | fail_msg_transmited_max_size = GNUNET_NO; |
525 | } | 550 | } |
526 | } | 551 | } |
527 | 552 | ||
528 | 553 | ||
529 | static void run_connection_tests( int phase , void * cls); | 554 | static void run_connection_tests (int phase, void *cls); |
530 | 555 | ||
531 | /** | 556 | /** |
532 | * Recieves messages from plugin, in real world transport | 557 | * Recieves messages from plugin, in real world transport |
533 | */ | 558 | */ |
534 | static struct GNUNET_TIME_Relative | 559 | static struct GNUNET_TIME_Relative |
535 | receive (void *cls, const struct GNUNET_PeerIdentity *peer, | 560 | receive (void *cls, const struct GNUNET_PeerIdentity *peer, |
536 | const struct GNUNET_MessageHeader *message, | 561 | const struct GNUNET_MessageHeader *message, |
537 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | 562 | const struct GNUNET_TRANSPORT_ATS_Information *ats, |
538 | uint32_t ats_count, | 563 | uint32_t ats_count, |
539 | struct Session *session, | 564 | struct Session *session, |
540 | const char *sender_address, | 565 | const char *sender_address, uint16_t sender_address_len) |
541 | uint16_t sender_address_len) | ||
542 | { | 566 | { |
543 | 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); | 567 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
568 | "Testcase recieved new message from peer `%s' with type %u and length %u, session %X\n", | ||
569 | GNUNET_i2s (peer), ntohs (message->type), ntohs (message->size), | ||
570 | session); | ||
544 | 571 | ||
545 | if ((ntohs(message->type)>=10) && (ntohs(message->type)<20)) | 572 | if ((ntohs (message->type) >= 10) && (ntohs (message->type) < 20)) |
546 | { | 573 | { |
547 | fail_msgs_transmited_to_local_addrs++; | 574 | fail_msgs_transmited_to_local_addrs++; |
548 | if (fail_msgs_transmited_to_local_addrs == count_str_addr) | 575 | if (fail_msgs_transmited_to_local_addrs == count_str_addr) |
549 | run_connection_tests(2, session); | 576 | run_connection_tests (2, session); |
550 | } | 577 | } |
551 | 578 | ||
552 | 579 | ||
553 | if ((ntohs(message->type)==20)) | 580 | if ((ntohs (message->type) == 20)) |
554 | { | 581 | { |
555 | fail_session_selection_reliable = GNUNET_NO; | 582 | fail_session_selection_reliable = GNUNET_NO; |
556 | } | 583 | } |
557 | 584 | ||
558 | if ((ntohs(message->type)==21)) | 585 | if ((ntohs (message->type) == 21)) |
559 | { | 586 | { |
560 | fail_session_selection_any = GNUNET_NO; | 587 | fail_session_selection_any = GNUNET_NO; |
561 | } | 588 | } |
562 | if ((ntohs(message->type)==22)) | 589 | if ((ntohs (message->type) == 22)) |
563 | { | 590 | { |
564 | fail_session_selection_session = GNUNET_NO; | 591 | fail_session_selection_session = GNUNET_NO; |
565 | } | 592 | } |
566 | 593 | ||
567 | if ((ntohs(message->type)==23)) | 594 | if ((ntohs (message->type) == 23)) |
568 | { | 595 | { |
569 | fail_session_selection_session_big = GNUNET_NO; | 596 | fail_session_selection_session_big = GNUNET_NO; |
570 | run_connection_tests(3, NULL); | 597 | run_connection_tests (3, NULL); |
571 | } | 598 | } |
572 | 599 | ||
573 | if ((ntohs(message->type)==30) || (ntohs(message->type)==31)) | 600 | if ((ntohs (message->type) == 30) || (ntohs (message->type) == 31)) |
574 | { | 601 | { |
575 | fail_multiple_msgs_in_transmission ++; | 602 | fail_multiple_msgs_in_transmission++; |
576 | } | 603 | } |
577 | 604 | ||
578 | if ((ntohs(message->type)==32) && (ntohs(message->size) == GNUNET_SERVER_MAX_MESSAGE_SIZE-1)) | 605 | if ((ntohs (message->type) == 32) && |
606 | (ntohs (message->size) == GNUNET_SERVER_MAX_MESSAGE_SIZE - 1)) | ||
579 | { | 607 | { |
580 | fail_msg_transmited_max_size = GNUNET_NO; | 608 | fail_msg_transmited_max_size = GNUNET_NO; |
581 | shutdown_clean(); | 609 | shutdown_clean (); |
582 | } | 610 | } |
583 | 611 | ||
584 | return GNUNET_TIME_UNIT_ZERO; | 612 | return GNUNET_TIME_UNIT_ZERO; |
585 | } | 613 | } |
586 | 614 | ||
587 | static size_t send_function (void *stream, size_t size, size_t nmemb, void *ptr) | 615 | static size_t |
616 | send_function (void *stream, size_t size, size_t nmemb, void *ptr) | ||
588 | { | 617 | { |
589 | unsigned int len; | 618 | unsigned int len; |
590 | 619 | ||
591 | len = buffer_out.len; | 620 | len = buffer_out.len; |
592 | 621 | ||
593 | if (( buffer_out.pos == len) || (len > (size * nmemb))) | 622 | if ((buffer_out.pos == len) || (len > (size * nmemb))) |
594 | return 0; | 623 | return 0; |
595 | memcpy(stream, buffer_out.buf, len); | 624 | memcpy (stream, buffer_out.buf, len); |
596 | buffer_out.pos = len; | 625 | buffer_out.pos = len; |
597 | return len; | 626 | return len; |
598 | } | 627 | } |
599 | 628 | ||
600 | static size_t recv_function (void *ptr, size_t size, size_t nmemb, void *ctx) | 629 | static size_t |
630 | recv_function (void *ptr, size_t size, size_t nmemb, void *ctx) | ||
601 | { | 631 | { |
602 | 632 | ||
603 | if (buffer_in.pos + size * nmemb > buffer_in.size) | 633 | if (buffer_in.pos + size * nmemb > buffer_in.size) |
@@ -611,50 +641,51 @@ static size_t recv_function (void *ptr, size_t size, size_t nmemb, void *ctx) | |||
611 | return buffer_in.pos; | 641 | return buffer_in.pos; |
612 | } | 642 | } |
613 | 643 | ||
614 | static size_t header_function( void *ptr, size_t size, size_t nmemb, void *stream) | 644 | static size_t |
645 | header_function (void *ptr, size_t size, size_t nmemb, void *stream) | ||
615 | { | 646 | { |
616 | struct HTTP_Transfer * res = (struct HTTP_Transfer *) stream; | 647 | struct HTTP_Transfer *res = (struct HTTP_Transfer *) stream; |
617 | char * tmp; | 648 | char *tmp; |
618 | unsigned int len = size * nmemb; | 649 | unsigned int len = size * nmemb; |
619 | 650 | ||
620 | tmp = GNUNET_malloc ( len+1 ); | 651 | tmp = GNUNET_malloc (len + 1); |
621 | memcpy(tmp,ptr,len); | 652 | memcpy (tmp, ptr, len); |
622 | if (tmp[len-2] == 13) | 653 | if (tmp[len - 2] == 13) |
623 | tmp[len-2]= '\0'; | 654 | tmp[len - 2] = '\0'; |
624 | #if DEBUG_CURL | 655 | #if DEBUG_CURL |
625 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Header: `%s'\n",tmp); | 656 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Header: `%s'\n", tmp); |
626 | #endif | 657 | #endif |
627 | if (0==strcmp (tmp,"HTTP/1.1 100 Continue")) | 658 | if (0 == strcmp (tmp, "HTTP/1.1 100 Continue")) |
628 | { | 659 | { |
629 | res->http_result_code=100; | 660 | res->http_result_code = 100; |
630 | } | 661 | } |
631 | if (0==strcmp (tmp,"HTTP/1.1 200 OK")) | 662 | if (0 == strcmp (tmp, "HTTP/1.1 200 OK")) |
632 | { | 663 | { |
633 | res->http_result_code=200; | 664 | res->http_result_code = 200; |
634 | } | 665 | } |
635 | if (0==strcmp (tmp,"HTTP/1.1 400 Bad Request")) | 666 | if (0 == strcmp (tmp, "HTTP/1.1 400 Bad Request")) |
636 | { | 667 | { |
637 | res->http_result_code=400; | 668 | res->http_result_code = 400; |
638 | } | 669 | } |
639 | if (0==strcmp (tmp,"HTTP/1.1 404 Not Found")) | 670 | if (0 == strcmp (tmp, "HTTP/1.1 404 Not Found")) |
640 | { | 671 | { |
641 | res->http_result_code=404; | 672 | res->http_result_code = 404; |
642 | } | 673 | } |
643 | if (0==strcmp (tmp,"HTTP/1.1 413 Request entity too large")) | 674 | if (0 == strcmp (tmp, "HTTP/1.1 413 Request entity too large")) |
644 | { | 675 | { |
645 | res->http_result_code=413; | 676 | res->http_result_code = 413; |
646 | } | 677 | } |
647 | 678 | ||
648 | GNUNET_free (tmp); | 679 | GNUNET_free (tmp); |
649 | return size * nmemb; | 680 | return size * nmemb; |
650 | } | 681 | } |
651 | 682 | ||
652 | static size_t send_prepare( struct HTTP_Transfer * result); | 683 | static size_t send_prepare (struct HTTP_Transfer *result); |
653 | 684 | ||
654 | 685 | ||
655 | 686 | ||
656 | static void send_execute (void *cls, | 687 | static void |
657 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 688 | send_execute (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
658 | { | 689 | { |
659 | struct HTTP_Transfer *res; | 690 | struct HTTP_Transfer *res; |
660 | 691 | ||
@@ -668,96 +699,107 @@ static void send_execute (void *cls, | |||
668 | return; | 699 | return; |
669 | 700 | ||
670 | do | 701 | do |
702 | { | ||
703 | running = 0; | ||
704 | mret = curl_multi_perform (multi_handle, &running); | ||
705 | if (running == 0) | ||
671 | { | 706 | { |
672 | running = 0; | 707 | do |
673 | mret = curl_multi_perform (multi_handle, &running); | 708 | { |
674 | if (running == 0) | 709 | |
710 | msg = curl_multi_info_read (multi_handle, &running); | ||
711 | if (msg == NULL) | ||
712 | break; | ||
713 | /* get session for affected curl handle */ | ||
714 | //cs = find_session_by_curlhandle (msg->easy_handle); | ||
715 | //GNUNET_assert ( cs != NULL ); | ||
716 | switch (msg->msg) | ||
675 | { | 717 | { |
676 | do | ||
677 | { | ||
678 | |||
679 | msg = curl_multi_info_read (multi_handle, &running); | ||
680 | if (msg == NULL) | ||
681 | break; | ||
682 | /* get session for affected curl handle */ | ||
683 | //cs = find_session_by_curlhandle (msg->easy_handle); | ||
684 | //GNUNET_assert ( cs != NULL ); | ||
685 | switch (msg->msg) | ||
686 | { | ||
687 | |||
688 | case CURLMSG_DONE: | ||
689 | if ( (msg->data.result != CURLE_OK) && | ||
690 | (msg->data.result != CURLE_GOT_NOTHING) ) | ||
691 | { | ||
692 | |||
693 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
694 | _("curl failed for `%s' at %s:%d: `%s'\n"), | ||
695 | "curl_multi_perform", | ||
696 | __FILE__, | ||
697 | __LINE__, | ||
698 | curl_easy_strerror (msg->data.result)); | ||
699 | /* sending msg failed*/ | ||
700 | curl_easy_cleanup(curl_handle); | ||
701 | curl_handle=NULL; | ||
702 | |||
703 | run_connection_tests(0, NULL); | ||
704 | } | ||
705 | if (res == &test_no_ident) | ||
706 | { | ||
707 | if ((res->http_result_code==404) && (buffer_in.len==208)) | ||
708 | { | ||
709 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connecting to peer without any peer identification: test passed\n"); | ||
710 | res->test_failed = GNUNET_NO; | ||
711 | } | ||
712 | else | ||
713 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Connecting to peer without any peer identification: test failed\n")); | ||
714 | } | ||
715 | if (res == &test_too_short_ident) | ||
716 | { | ||
717 | if ((res->http_result_code==404) && (buffer_in.len==208)) | ||
718 | { | ||
719 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connecting to peer with too short peer identification: test passed\n"); | ||
720 | res->test_failed = GNUNET_NO; | ||
721 | } | ||
722 | else | ||
723 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Connecting to peer with too short peer identification: test failed\n")); | ||
724 | } | ||
725 | if (res == &test_too_long_ident) | ||
726 | { | ||
727 | if ((res->http_result_code==404) && (buffer_in.len==208)) | ||
728 | { | ||
729 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connecting to peer with too long peer identification: test passed\n"); | ||
730 | res->test_failed = GNUNET_NO; | ||
731 | } | ||
732 | else | ||
733 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Connecting to peer with too long peer identification: test failed\n")); | ||
734 | } | ||
735 | if (res == &test_valid_ident) | ||
736 | { | ||
737 | if ((res->http_result_code==200)) | ||
738 | { | ||
739 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connecting to peer with valid peer identification: test passed\n"); | ||
740 | res->test_failed = GNUNET_NO; | ||
741 | } | ||
742 | else | ||
743 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Connecting to peer with valid peer identification: test failed\n")); | ||
744 | } | ||
745 | curl_easy_cleanup(curl_handle); | ||
746 | curl_handle=NULL; | ||
747 | if ((res == &test_valid_ident) && (res->test_failed == GNUNET_NO)) | ||
748 | run_connection_tests(1, NULL); | ||
749 | run_connection_tests(0, NULL); | ||
750 | return; | ||
751 | default: | ||
752 | break; | ||
753 | } | ||
754 | 718 | ||
719 | case CURLMSG_DONE: | ||
720 | if ((msg->data.result != CURLE_OK) && | ||
721 | (msg->data.result != CURLE_GOT_NOTHING)) | ||
722 | { | ||
723 | |||
724 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
725 | _("curl failed for `%s' at %s:%d: `%s'\n"), | ||
726 | "curl_multi_perform", | ||
727 | __FILE__, | ||
728 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
729 | /* sending msg failed */ | ||
730 | curl_easy_cleanup (curl_handle); | ||
731 | curl_handle = NULL; | ||
732 | |||
733 | run_connection_tests (0, NULL); | ||
734 | } | ||
735 | if (res == &test_no_ident) | ||
736 | { | ||
737 | if ((res->http_result_code == 404) && (buffer_in.len == 208)) | ||
738 | { | ||
739 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
740 | "Connecting to peer without any peer identification: test passed\n"); | ||
741 | res->test_failed = GNUNET_NO; | ||
742 | } | ||
743 | else | ||
744 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
745 | _ | ||
746 | ("Connecting to peer without any peer identification: test failed\n")); | ||
747 | } | ||
748 | if (res == &test_too_short_ident) | ||
749 | { | ||
750 | if ((res->http_result_code == 404) && (buffer_in.len == 208)) | ||
751 | { | ||
752 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
753 | "Connecting to peer with too short peer identification: test passed\n"); | ||
754 | res->test_failed = GNUNET_NO; | ||
755 | } | ||
756 | else | ||
757 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
758 | _ | ||
759 | ("Connecting to peer with too short peer identification: test failed\n")); | ||
760 | } | ||
761 | if (res == &test_too_long_ident) | ||
762 | { | ||
763 | if ((res->http_result_code == 404) && (buffer_in.len == 208)) | ||
764 | { | ||
765 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
766 | "Connecting to peer with too long peer identification: test passed\n"); | ||
767 | res->test_failed = GNUNET_NO; | ||
755 | } | 768 | } |
756 | while ( (running > 0) ); | 769 | else |
770 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
771 | _ | ||
772 | ("Connecting to peer with too long peer identification: test failed\n")); | ||
773 | } | ||
774 | if (res == &test_valid_ident) | ||
775 | { | ||
776 | if ((res->http_result_code == 200)) | ||
777 | { | ||
778 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
779 | "Connecting to peer with valid peer identification: test passed\n"); | ||
780 | res->test_failed = GNUNET_NO; | ||
781 | } | ||
782 | else | ||
783 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
784 | _ | ||
785 | ("Connecting to peer with valid peer identification: test failed\n")); | ||
786 | } | ||
787 | curl_easy_cleanup (curl_handle); | ||
788 | curl_handle = NULL; | ||
789 | if ((res == &test_valid_ident) && (res->test_failed == GNUNET_NO)) | ||
790 | run_connection_tests (1, NULL); | ||
791 | run_connection_tests (0, NULL); | ||
792 | return; | ||
793 | default: | ||
794 | break; | ||
757 | } | 795 | } |
796 | |||
797 | } | ||
798 | while ((running > 0)); | ||
758 | } | 799 | } |
800 | } | ||
759 | while (mret == CURLM_CALL_MULTI_PERFORM); | 801 | while (mret == CURLM_CALL_MULTI_PERFORM); |
760 | send_prepare(cls); | 802 | send_prepare (cls); |
761 | } | 803 | } |
762 | 804 | ||
763 | /** | 805 | /** |
@@ -765,7 +807,8 @@ static void send_execute (void *cls, | |||
765 | * @param ses session to send data to | 807 | * @param ses session to send data to |
766 | * @return bytes sent to peer | 808 | * @return bytes sent to peer |
767 | */ | 809 | */ |
768 | static size_t send_prepare( struct HTTP_Transfer * result) | 810 | static size_t |
811 | send_prepare (struct HTTP_Transfer *result) | ||
769 | { | 812 | { |
770 | fd_set rs; | 813 | fd_set rs; |
771 | fd_set ws; | 814 | fd_set ws; |
@@ -782,34 +825,33 @@ static size_t send_prepare( struct HTTP_Transfer * result) | |||
782 | FD_ZERO (&es); | 825 | FD_ZERO (&es); |
783 | mret = curl_multi_fdset (multi_handle, &rs, &ws, &es, &max); | 826 | mret = curl_multi_fdset (multi_handle, &rs, &ws, &es, &max); |
784 | if (mret != CURLM_OK) | 827 | if (mret != CURLM_OK) |
785 | { | 828 | { |
786 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 829 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
787 | _("%s failed at %s:%d: `%s'\n"), | 830 | _("%s failed at %s:%d: `%s'\n"), |
788 | "curl_multi_fdset", __FILE__, __LINE__, | 831 | "curl_multi_fdset", __FILE__, __LINE__, |
789 | curl_multi_strerror (mret)); | 832 | curl_multi_strerror (mret)); |
790 | return -1; | 833 | return -1; |
791 | } | 834 | } |
792 | mret = curl_multi_timeout (multi_handle, &to); | 835 | mret = curl_multi_timeout (multi_handle, &to); |
793 | if (mret != CURLM_OK) | 836 | if (mret != CURLM_OK) |
794 | { | 837 | { |
795 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 838 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
796 | _("%s failed at %s:%d: `%s'\n"), | 839 | _("%s failed at %s:%d: `%s'\n"), |
797 | "curl_multi_timeout", __FILE__, __LINE__, | 840 | "curl_multi_timeout", __FILE__, __LINE__, |
798 | curl_multi_strerror (mret)); | 841 | curl_multi_strerror (mret)); |
799 | return -1; | 842 | return -1; |
800 | } | 843 | } |
801 | 844 | ||
802 | grs = GNUNET_NETWORK_fdset_create (); | 845 | grs = GNUNET_NETWORK_fdset_create (); |
803 | gws = GNUNET_NETWORK_fdset_create (); | 846 | gws = GNUNET_NETWORK_fdset_create (); |
804 | GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1); | 847 | GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1); |
805 | GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1); | 848 | GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1); |
806 | http_task_send = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 849 | http_task_send = |
850 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | ||
807 | GNUNET_SCHEDULER_NO_TASK, | 851 | GNUNET_SCHEDULER_NO_TASK, |
808 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 0), | 852 | GNUNET_TIME_relative_multiply |
809 | grs, | 853 | (GNUNET_TIME_UNIT_SECONDS, 0), grs, gws, |
810 | gws, | 854 | &send_execute, result); |
811 | &send_execute, | ||
812 | result); | ||
813 | GNUNET_NETWORK_fdset_destroy (gws); | 855 | GNUNET_NETWORK_fdset_destroy (gws); |
814 | GNUNET_NETWORK_fdset_destroy (grs); | 856 | GNUNET_NETWORK_fdset_destroy (grs); |
815 | 857 | ||
@@ -820,36 +862,38 @@ static size_t send_prepare( struct HTTP_Transfer * result) | |||
820 | /** | 862 | /** |
821 | * function to send data to server | 863 | * function to send data to server |
822 | */ | 864 | */ |
823 | static int send_data( struct HTTP_Transfer * result, char * url) | 865 | static int |
866 | send_data (struct HTTP_Transfer *result, char *url) | ||
824 | { | 867 | { |
825 | 868 | ||
826 | curl_handle = curl_easy_init(); | 869 | curl_handle = curl_easy_init (); |
827 | if( NULL == curl_handle) | 870 | if (NULL == curl_handle) |
828 | { | 871 | { |
829 | printf("easy_init failed \n"); | 872 | printf ("easy_init failed \n"); |
830 | return GNUNET_SYSERR; | 873 | return GNUNET_SYSERR; |
831 | } | 874 | } |
832 | #if DEBUG_CURL | 875 | #if DEBUG_CURL |
833 | curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L); | 876 | curl_easy_setopt (curl_handle, CURLOPT_VERBOSE, 1L); |
834 | #endif | 877 | #endif |
835 | curl_easy_setopt(curl_handle, CURLOPT_URL, url); | 878 | curl_easy_setopt (curl_handle, CURLOPT_URL, url); |
836 | curl_easy_setopt(curl_handle, CURLOPT_PUT, 1L); | 879 | curl_easy_setopt (curl_handle, CURLOPT_PUT, 1L); |
837 | //curl_easy_setopt(curl_handle, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); | 880 | //curl_easy_setopt(curl_handle, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); |
838 | curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0); | 881 | curl_easy_setopt (curl_handle, CURLOPT_SSL_VERIFYPEER, 0); |
839 | curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0); | 882 | curl_easy_setopt (curl_handle, CURLOPT_SSL_VERIFYHOST, 0); |
840 | curl_easy_setopt (curl_handle, CURLOPT_HEADERFUNCTION, &header_function); | 883 | curl_easy_setopt (curl_handle, CURLOPT_HEADERFUNCTION, &header_function); |
841 | curl_easy_setopt (curl_handle, CURLOPT_WRITEHEADER, result); | 884 | curl_easy_setopt (curl_handle, CURLOPT_WRITEHEADER, result); |
842 | curl_easy_setopt (curl_handle, CURLOPT_WRITEFUNCTION, &recv_function); | 885 | curl_easy_setopt (curl_handle, CURLOPT_WRITEFUNCTION, &recv_function); |
843 | curl_easy_setopt (curl_handle, CURLOPT_WRITEDATA, result); | 886 | curl_easy_setopt (curl_handle, CURLOPT_WRITEDATA, result); |
844 | curl_easy_setopt (curl_handle, CURLOPT_READFUNCTION, &send_function); | 887 | curl_easy_setopt (curl_handle, CURLOPT_READFUNCTION, &send_function); |
845 | curl_easy_setopt (curl_handle, CURLOPT_READDATA, result); | 888 | curl_easy_setopt (curl_handle, CURLOPT_READDATA, result); |
846 | curl_easy_setopt(curl_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t) buffer_out.len); | 889 | curl_easy_setopt (curl_handle, CURLOPT_INFILESIZE_LARGE, |
847 | curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 30); | 890 | (curl_off_t) buffer_out.len); |
848 | curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 20); | 891 | curl_easy_setopt (curl_handle, CURLOPT_TIMEOUT, 30); |
892 | curl_easy_setopt (curl_handle, CURLOPT_CONNECTTIMEOUT, 20); | ||
849 | 893 | ||
850 | curl_multi_add_handle(multi_handle, curl_handle); | 894 | curl_multi_add_handle (multi_handle, curl_handle); |
851 | 895 | ||
852 | send_prepare(result); | 896 | send_prepare (result); |
853 | 897 | ||
854 | return GNUNET_OK; | 898 | return GNUNET_OK; |
855 | } | 899 | } |
@@ -858,68 +902,66 @@ static int send_data( struct HTTP_Transfer * result, char * url) | |||
858 | * Plugin notifies transport (aka testcase) about its addresses | 902 | * Plugin notifies transport (aka testcase) about its addresses |
859 | */ | 903 | */ |
860 | void | 904 | void |
861 | notify_address (void *cls, | 905 | notify_address (void *cls, int add_remove, const void *addr, size_t addrlen) |
862 | int add_remove, | ||
863 | const void *addr, | ||
864 | size_t addrlen) | ||
865 | { | 906 | { |
866 | char address[INET6_ADDRSTRLEN]; | 907 | char address[INET6_ADDRSTRLEN]; |
867 | unsigned int port; | 908 | unsigned int port; |
868 | struct Plugin_Address * pl_addr; | 909 | struct Plugin_Address *pl_addr; |
869 | struct Plugin_Address * cur; | 910 | struct Plugin_Address *cur; |
870 | 911 | ||
871 | if (addrlen == (sizeof (struct IPv4HttpAddress))) | 912 | if (addrlen == (sizeof (struct IPv4HttpAddress))) |
872 | { | 913 | { |
873 | inet_ntop(AF_INET, (struct in_addr *) addr,address,INET_ADDRSTRLEN); | 914 | inet_ntop (AF_INET, (struct in_addr *) addr, address, INET_ADDRSTRLEN); |
874 | port = ntohs(((struct IPv4HttpAddress *) addr)->u_port); | 915 | port = ntohs (((struct IPv4HttpAddress *) addr)->u_port); |
875 | } | 916 | } |
876 | else if (addrlen == (sizeof (struct IPv6HttpAddress))) | 917 | else if (addrlen == (sizeof (struct IPv6HttpAddress))) |
877 | { | 918 | { |
878 | inet_ntop(AF_INET6, (struct in6_addr *) addr,address,INET6_ADDRSTRLEN); | 919 | inet_ntop (AF_INET6, (struct in6_addr *) addr, address, INET6_ADDRSTRLEN); |
879 | port = ntohs(((struct IPv6HttpAddress *) addr)->u6_port); | 920 | port = ntohs (((struct IPv6HttpAddress *) addr)->u6_port); |
880 | } | 921 | } |
881 | else | 922 | else |
882 | { | 923 | { |
883 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 924 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
884 | _("Unknown address size: ipv6 has %u ipv4 has %u but this has %u\n"), | 925 | _ |
926 | ("Unknown address size: ipv6 has %u ipv4 has %u but this has %u\n"), | ||
885 | sizeof (struct IPv6HttpAddress), | 927 | sizeof (struct IPv6HttpAddress), |
886 | sizeof (struct IPv4HttpAddress), | 928 | sizeof (struct IPv4HttpAddress), addrlen); |
887 | addrlen); | 929 | return; |
888 | return; | 930 | } |
889 | } | ||
890 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 931 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
891 | _("Transport plugin notification for address: `%s':%u\n"), | 932 | _("Transport plugin notification for address: `%s':%u\n"), |
892 | address, | 933 | address, port); |
893 | port); | 934 | pl_addr = GNUNET_malloc (sizeof (struct Plugin_Address)); |
894 | pl_addr = GNUNET_malloc (sizeof (struct Plugin_Address) ); | ||
895 | pl_addr->addrlen = addrlen; | 935 | pl_addr->addrlen = addrlen; |
896 | pl_addr->addr = GNUNET_malloc(addrlen); | 936 | pl_addr->addr = GNUNET_malloc (addrlen); |
897 | memcpy(pl_addr->addr,addr,addrlen); | 937 | memcpy (pl_addr->addr, addr, addrlen); |
898 | pl_addr->next = NULL; | 938 | pl_addr->next = NULL; |
899 | 939 | ||
900 | if ( NULL == addr_head) | 940 | if (NULL == addr_head) |
901 | { | 941 | { |
902 | addr_head = pl_addr; | 942 | addr_head = pl_addr; |
903 | } | 943 | } |
904 | else | 944 | else |
945 | { | ||
946 | cur = addr_head; | ||
947 | while (NULL != cur->next) | ||
905 | { | 948 | { |
906 | cur = addr_head; | 949 | cur = cur->next; |
907 | while (NULL != cur->next) | ||
908 | { | ||
909 | cur = cur->next; | ||
910 | } | ||
911 | cur->next = pl_addr; | ||
912 | } | 950 | } |
951 | cur->next = pl_addr; | ||
952 | } | ||
913 | fail_notify_address_count++; | 953 | fail_notify_address_count++; |
914 | fail_notify_address = GNUNET_NO; | 954 | fail_notify_address = GNUNET_NO; |
915 | } | 955 | } |
916 | 956 | ||
917 | static void | 957 | static void |
918 | plugin_env_session_end (void *cls, | 958 | plugin_env_session_end (void *cls, |
919 | const struct GNUNET_PeerIdentity *peer, | 959 | const struct GNUNET_PeerIdentity *peer, |
920 | struct Session *session) | 960 | struct Session *session) |
921 | { | 961 | { |
922 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Pluging tells me: session %X to peer `%s' ended\n", session, GNUNET_i2s(peer)); | 962 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
963 | "Pluging tells me: session %X to peer `%s' ended\n", session, | ||
964 | GNUNET_i2s (peer)); | ||
923 | } | 965 | } |
924 | 966 | ||
925 | 967 | ||
@@ -944,8 +986,7 @@ setup_plugin_environment () | |||
944 | * Task shutting down testcase if it a timeout occurs | 986 | * Task shutting down testcase if it a timeout occurs |
945 | */ | 987 | */ |
946 | static void | 988 | static void |
947 | task_timeout (void *cls, | 989 | task_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
948 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
949 | { | 990 | { |
950 | ti_timeout = GNUNET_SCHEDULER_NO_TASK; | 991 | ti_timeout = GNUNET_SCHEDULER_NO_TASK; |
951 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 992 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
@@ -953,30 +994,33 @@ task_timeout (void *cls, | |||
953 | 994 | ||
954 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testcase timeout\n"); | 995 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testcase timeout\n"); |
955 | fail = GNUNET_YES; | 996 | fail = GNUNET_YES; |
956 | shutdown_clean(); | 997 | shutdown_clean (); |
957 | return; | 998 | return; |
958 | } | 999 | } |
959 | 1000 | ||
960 | static void pretty_printer_cb (void *cls, | 1001 | static void |
961 | const char *address) | 1002 | pretty_printer_cb (void *cls, const char *address) |
962 | { | 1003 | { |
963 | if (NULL==address) | 1004 | if (NULL == address) |
964 | return; | 1005 | return; |
965 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Plugin returned pretty address: `%s'\n",address); | 1006 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Plugin returned pretty address: `%s'\n", |
1007 | address); | ||
966 | fail_pretty_printer_count++; | 1008 | fail_pretty_printer_count++; |
967 | } | 1009 | } |
968 | 1010 | ||
969 | /** | 1011 | /** |
970 | * Runs every single test to test the plugin | 1012 | * Runs every single test to test the plugin |
971 | */ | 1013 | */ |
972 | static void run_connection_tests( int phase , void * cls) | 1014 | static void |
1015 | run_connection_tests (int phase, void *cls) | ||
973 | { | 1016 | { |
974 | struct GNUNET_MessageHeader * msg; | 1017 | struct GNUNET_MessageHeader *msg; |
975 | unsigned int size; | 1018 | unsigned int size; |
976 | 1019 | ||
977 | if (phase==0) | 1020 | if (phase == 0) |
978 | { | 1021 | { |
979 | char * host_str = NULL; | 1022 | char *host_str = NULL; |
1023 | |||
980 | /* resetting buffers */ | 1024 | /* resetting buffers */ |
981 | buffer_in.size = HTTP_BUFFER_SIZE; | 1025 | buffer_in.size = HTTP_BUFFER_SIZE; |
982 | buffer_in.pos = 0; | 1026 | buffer_in.pos = 0; |
@@ -989,154 +1033,192 @@ static void run_connection_tests( int phase , void * cls) | |||
989 | if (test_no_ident.test_executed == GNUNET_NO) | 1033 | if (test_no_ident.test_executed == GNUNET_NO) |
990 | { | 1034 | { |
991 | /* Connecting to peer without identification */ | 1035 | /* Connecting to peer without identification */ |
992 | char * ident = ""; | 1036 | char *ident = ""; |
993 | GNUNET_asprintf (&host_str, "%s://%s/%s",PROTOCOL_PREFIX, test_addr,ident); | 1037 | |
994 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer without any peer identification.\n")); | 1038 | GNUNET_asprintf (&host_str, "%s://%s/%s", PROTOCOL_PREFIX, test_addr, |
1039 | ident); | ||
1040 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1041 | _("Connecting to peer without any peer identification.\n")); | ||
995 | test_no_ident.test_executed = GNUNET_YES; | 1042 | test_no_ident.test_executed = GNUNET_YES; |
996 | send_data ( &test_no_ident, host_str); | 1043 | send_data (&test_no_ident, host_str); |
997 | GNUNET_free (host_str); | 1044 | GNUNET_free (host_str); |
998 | return; | 1045 | return; |
999 | } | 1046 | } |
1000 | if (test_too_short_ident.test_executed == GNUNET_NO) | 1047 | if (test_too_short_ident.test_executed == GNUNET_NO) |
1001 | { | 1048 | { |
1002 | char * ident = "AAAAAAAAAA"; | 1049 | char *ident = "AAAAAAAAAA"; |
1050 | |||
1003 | /* Connecting to peer with too short identification */ | 1051 | /* Connecting to peer with too short identification */ |
1004 | GNUNET_asprintf (&host_str, "%s://%s/%s",PROTOCOL_PREFIX, test_addr,ident); | 1052 | GNUNET_asprintf (&host_str, "%s://%s/%s", PROTOCOL_PREFIX, test_addr, |
1005 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too short peer identification.\n")); | 1053 | ident); |
1054 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1055 | _ | ||
1056 | ("Connecting to peer with too short peer identification.\n")); | ||
1006 | test_too_short_ident.test_executed = GNUNET_YES; | 1057 | test_too_short_ident.test_executed = GNUNET_YES; |
1007 | send_data ( &test_too_short_ident, host_str); | 1058 | send_data (&test_too_short_ident, host_str); |
1008 | GNUNET_free (host_str); | 1059 | GNUNET_free (host_str); |
1009 | return; | 1060 | return; |
1010 | } | 1061 | } |
1011 | 1062 | ||
1012 | if (test_too_long_ident.test_executed == GNUNET_NO) | 1063 | if (test_too_long_ident.test_executed == GNUNET_NO) |
1013 | { | 1064 | { |
1014 | char * ident = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; | 1065 | char *ident = |
1066 | "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; | ||
1015 | 1067 | ||
1016 | /* Connecting to peer with too long identification */ | 1068 | /* Connecting to peer with too long identification */ |
1017 | GNUNET_asprintf (&host_str, "%s://%s/%s",PROTOCOL_PREFIX, test_addr,ident); | 1069 | GNUNET_asprintf (&host_str, "%s://%s/%s", PROTOCOL_PREFIX, test_addr, |
1018 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too long peer identification.\n")); | 1070 | ident); |
1071 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1072 | _("Connecting to peer with too long peer identification.\n")); | ||
1019 | test_too_long_ident.test_executed = GNUNET_YES; | 1073 | test_too_long_ident.test_executed = GNUNET_YES; |
1020 | send_data ( &test_too_long_ident, host_str); | 1074 | send_data (&test_too_long_ident, host_str); |
1021 | GNUNET_free (host_str); | 1075 | GNUNET_free (host_str); |
1022 | return; | 1076 | return; |
1023 | } | 1077 | } |
1024 | if (test_valid_ident.test_executed == GNUNET_NO) | 1078 | if (test_valid_ident.test_executed == GNUNET_NO) |
1025 | { | 1079 | { |
1026 | struct GNUNET_CRYPTO_HashAsciiEncoded ident; | 1080 | struct GNUNET_CRYPTO_HashAsciiEncoded ident; |
1027 | GNUNET_CRYPTO_hash_to_enc(&my_identity.hashPubKey,&ident); | 1081 | |
1028 | GNUNET_asprintf (&host_str, "%s://%s/%s%s",PROTOCOL_PREFIX, test_addr,(char *) &ident,";0"); | 1082 | GNUNET_CRYPTO_hash_to_enc (&my_identity.hashPubKey, &ident); |
1029 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with valid peer identification.\n")); | 1083 | GNUNET_asprintf (&host_str, "%s://%s/%s%s", PROTOCOL_PREFIX, test_addr, |
1084 | (char *) &ident, ";0"); | ||
1085 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1086 | _("Connecting to peer with valid peer identification.\n")); | ||
1030 | test_valid_ident.test_executed = GNUNET_YES; | 1087 | test_valid_ident.test_executed = GNUNET_YES; |
1031 | send_data ( &test_valid_ident, host_str); | 1088 | send_data (&test_valid_ident, host_str); |
1032 | GNUNET_free (host_str); | 1089 | GNUNET_free (host_str); |
1033 | return; | 1090 | return; |
1034 | } | 1091 | } |
1035 | } | 1092 | } |
1036 | if (phase==1) | 1093 | if (phase == 1) |
1037 | { | 1094 | { |
1038 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("\nPhase 1: transmit data to all suggested addresses\n\n")); | 1095 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1096 | _("\nPhase 1: transmit data to all suggested addresses\n\n")); | ||
1039 | /* Using one of the addresses the plugin proposed */ | 1097 | /* Using one of the addresses the plugin proposed */ |
1040 | GNUNET_assert (addr_head->addr != NULL); | 1098 | GNUNET_assert (addr_head->addr != NULL); |
1041 | 1099 | ||
1042 | struct Plugin_Address * tmp_addr; | 1100 | struct Plugin_Address *tmp_addr; |
1043 | struct GNUNET_MessageHeader msg; | 1101 | struct GNUNET_MessageHeader msg; |
1044 | char * tmp = GNUNET_malloc(sizeof(struct GNUNET_MessageHeader)); | 1102 | char *tmp = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader)); |
1045 | char address[INET6_ADDRSTRLEN]; | 1103 | char address[INET6_ADDRSTRLEN]; |
1046 | unsigned int port; | 1104 | unsigned int port; |
1047 | unsigned int type = 10; | 1105 | unsigned int type = 10; |
1048 | 1106 | ||
1049 | msg.size=htons(sizeof(struct GNUNET_MessageHeader)); | 1107 | msg.size = htons (sizeof (struct GNUNET_MessageHeader)); |
1050 | tmp_addr = addr_head; | 1108 | tmp_addr = addr_head; |
1051 | /* send a message to all addresses advertised by plugin */ | 1109 | /* send a message to all addresses advertised by plugin */ |
1052 | 1110 | ||
1053 | int count = 0; | 1111 | int count = 0; |
1112 | |||
1054 | while (tmp_addr != NULL) | 1113 | while (tmp_addr != NULL) |
1055 | { | 1114 | { |
1056 | if (tmp_addr->addrlen == (sizeof (struct IPv4HttpAddress))) | 1115 | if (tmp_addr->addrlen == (sizeof (struct IPv4HttpAddress))) |
1057 | { | 1116 | { |
1058 | inet_ntop(AF_INET, (struct in_addr *) tmp_addr->addr,address,INET_ADDRSTRLEN); | 1117 | inet_ntop (AF_INET, (struct in_addr *) tmp_addr->addr, address, |
1059 | port = ntohs(((struct IPv4HttpAddress *) tmp_addr->addr)->u_port); | 1118 | INET_ADDRSTRLEN); |
1060 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sending message to addres no. %u: `%s':%u\n", count,address, port); | 1119 | port = ntohs (((struct IPv4HttpAddress *) tmp_addr->addr)->u_port); |
1061 | } | 1120 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1121 | "Sending message to addres no. %u: `%s':%u\n", count, | ||
1122 | address, port); | ||
1123 | } | ||
1062 | if (tmp_addr->addrlen == (sizeof (struct IPv6HttpAddress))) | 1124 | if (tmp_addr->addrlen == (sizeof (struct IPv6HttpAddress))) |
1063 | { | 1125 | { |
1064 | inet_ntop(AF_INET6, (struct in6_addr *) tmp_addr->addr,address,INET6_ADDRSTRLEN); | 1126 | inet_ntop (AF_INET6, (struct in6_addr *) tmp_addr->addr, address, |
1065 | port = ntohs(((struct IPv6HttpAddress *) tmp_addr->addr)->u6_port); | 1127 | INET6_ADDRSTRLEN); |
1066 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sending message to addres no. %u: `%s':%u\n", count,address,port); | 1128 | port = ntohs (((struct IPv6HttpAddress *) tmp_addr->addr)->u6_port); |
1067 | } | 1129 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1068 | msg.type=htons(type); | 1130 | "Sending message to addres no. %u: `%s':%u\n", count, |
1069 | memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader)); | 1131 | address, port); |
1070 | 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); | 1132 | } |
1133 | msg.type = htons (type); | ||
1134 | memcpy (tmp, &msg, sizeof (struct GNUNET_MessageHeader)); | ||
1135 | api->send (api->cls, &my_identity, tmp, | ||
1136 | sizeof (struct GNUNET_MessageHeader), 0, TIMEOUT, NULL, | ||
1137 | tmp_addr->addr, tmp_addr->addrlen, GNUNET_YES, &task_send_cont, | ||
1138 | &fail_msgs_transmited_to_local_addrs); | ||
1071 | tmp_addr = tmp_addr->next; | 1139 | tmp_addr = tmp_addr->next; |
1072 | 1140 | ||
1073 | count ++; | 1141 | count++; |
1074 | type ++; | 1142 | type++; |
1075 | } | 1143 | } |
1076 | GNUNET_free(tmp); | 1144 | GNUNET_free (tmp); |
1077 | return; | 1145 | return; |
1078 | } | 1146 | } |
1079 | 1147 | ||
1080 | if (phase==2) | 1148 | if (phase == 2) |
1081 | { | 1149 | { |
1082 | struct Session * session = cls; | 1150 | struct Session *session = cls; |
1083 | msg = GNUNET_malloc (sizeof(struct GNUNET_MessageHeader)); | ||
1084 | |||
1085 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("\nPhase 2: session selection\n\n")); | ||
1086 | size = sizeof(struct GNUNET_MessageHeader); | ||
1087 | msg->size=htons(size); | ||
1088 | msg->type = htons(20); | ||
1089 | api->send(api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT, NULL, NULL, 0, GNUNET_NO, &task_send_cont, NULL); | ||
1090 | |||
1091 | msg->type = htons(21); | ||
1092 | api->send(api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT, NULL, NULL, 0, GNUNET_SYSERR, &task_send_cont, NULL); | ||
1093 | |||
1094 | /* answer on session*/ | ||
1095 | size = sizeof( struct GNUNET_MessageHeader); | ||
1096 | msg->size = htons(size); | ||
1097 | msg->type = htons(22); | ||
1098 | api->send(api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT, session, NULL, 0, GNUNET_SYSERR, &task_send_cont, NULL); | ||
1099 | 1151 | ||
1100 | GNUNET_free(msg); | 1152 | msg = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader)); |
1101 | 1153 | ||
1102 | /* answer on session with big message not fitting in mhd send buffer*/ | 1154 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("\nPhase 2: session selection\n\n")); |
1103 | size = GNUNET_SERVER_MAX_MESSAGE_SIZE-1; | 1155 | size = sizeof (struct GNUNET_MessageHeader); |
1156 | msg->size = htons (size); | ||
1157 | msg->type = htons (20); | ||
1158 | api->send (api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT, | ||
1159 | NULL, NULL, 0, GNUNET_NO, &task_send_cont, NULL); | ||
1160 | |||
1161 | msg->type = htons (21); | ||
1162 | api->send (api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT, | ||
1163 | NULL, NULL, 0, GNUNET_SYSERR, &task_send_cont, NULL); | ||
1164 | |||
1165 | /* answer on session */ | ||
1166 | size = sizeof (struct GNUNET_MessageHeader); | ||
1167 | msg->size = htons (size); | ||
1168 | msg->type = htons (22); | ||
1169 | api->send (api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT, | ||
1170 | session, NULL, 0, GNUNET_SYSERR, &task_send_cont, NULL); | ||
1171 | |||
1172 | GNUNET_free (msg); | ||
1173 | |||
1174 | /* answer on session with big message not fitting in mhd send buffer */ | ||
1175 | size = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1; | ||
1104 | msg = GNUNET_malloc (size); | 1176 | msg = GNUNET_malloc (size); |
1105 | msg->size=htons(size); | 1177 | msg->size = htons (size); |
1106 | msg->type = htons(23); | 1178 | msg->type = htons (23); |
1107 | api->send(api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT, session, NULL, 0, GNUNET_NO, &task_send_cont, NULL); | 1179 | api->send (api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT, |
1108 | GNUNET_free(msg); | 1180 | session, NULL, 0, GNUNET_NO, &task_send_cont, NULL); |
1181 | GNUNET_free (msg); | ||
1109 | return; | 1182 | return; |
1110 | } | 1183 | } |
1111 | 1184 | ||
1112 | if (phase==3) | 1185 | if (phase == 3) |
1113 | { | 1186 | { |
1114 | 1187 | ||
1115 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("\nPhase 3: send multiple or big messages after disconnect\n\n")); | 1188 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1189 | _ | ||
1190 | ("\nPhase 3: send multiple or big messages after disconnect\n\n")); | ||
1116 | /* disconnect from peer, so new connections are created */ | 1191 | /* disconnect from peer, so new connections are created */ |
1117 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Disconnect from peer: `%s'\n", GNUNET_i2s(&my_identity)); | 1192 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnect from peer: `%s'\n", |
1118 | api->disconnect(api->cls, &my_identity); | 1193 | GNUNET_i2s (&my_identity)); |
1194 | api->disconnect (api->cls, &my_identity); | ||
1119 | 1195 | ||
1120 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Phase 3: sending messages\n")); | 1196 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Phase 3: sending messages\n")); |
1121 | /* send a multiple GNUNET_messages at a time*/ | 1197 | /* send a multiple GNUNET_messages at a time */ |
1122 | size = 2 * sizeof(struct GNUNET_MessageHeader); | 1198 | size = 2 * sizeof (struct GNUNET_MessageHeader); |
1123 | msg = GNUNET_malloc( 2* size); | 1199 | msg = GNUNET_malloc (2 * size); |
1124 | msg->size = htons(size); | 1200 | msg->size = htons (size); |
1125 | msg->type = htons(30); | 1201 | msg->type = htons (30); |
1126 | struct GNUNET_MessageHeader * msg2 = &msg[2]; | 1202 | struct GNUNET_MessageHeader *msg2 = &msg[2]; |
1127 | msg2->size = htons(2 * sizeof(struct GNUNET_MessageHeader)); | 1203 | |
1128 | msg2->type = htons(31); | 1204 | msg2->size = htons (2 * sizeof (struct GNUNET_MessageHeader)); |
1129 | 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); | 1205 | msg2->type = htons (31); |
1130 | GNUNET_free(msg); | 1206 | api->send (api->cls, &my_identity, (const char *) msg, |
1207 | 4 * sizeof (struct GNUNET_MessageHeader), 0, TIMEOUT, NULL, | ||
1208 | addr_head->addr, addr_head->addrlen, GNUNET_NO, &task_send_cont, | ||
1209 | &fail_multiple_msgs_in_transmission); | ||
1210 | GNUNET_free (msg); | ||
1131 | /* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE-1 */ | 1211 | /* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE-1 */ |
1132 | 1212 | ||
1133 | size = GNUNET_SERVER_MAX_MESSAGE_SIZE-1; | 1213 | size = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1; |
1134 | msg = GNUNET_malloc(size); | 1214 | msg = GNUNET_malloc (size); |
1135 | msg->size = htons(size); | 1215 | msg->size = htons (size); |
1136 | msg->type = htons(32); | 1216 | msg->type = htons (32); |
1137 | 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); | 1217 | api->send (api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT, |
1138 | GNUNET_free(msg); | 1218 | NULL, addr_head->addr, addr_head->addrlen, GNUNET_NO, |
1139 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No more tests to run\n"); | 1219 | &task_send_cont, &fail_msg_transmited_max_size); |
1220 | GNUNET_free (msg); | ||
1221 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No more tests to run\n"); | ||
1140 | } | 1222 | } |
1141 | } | 1223 | } |
1142 | 1224 | ||
@@ -1152,12 +1234,13 @@ run (void *cls, | |||
1152 | char *const *args, | 1234 | char *const *args, |
1153 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) | 1235 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) |
1154 | { | 1236 | { |
1155 | char * libname; | 1237 | char *libname; |
1238 | |||
1156 | cfg = c; | 1239 | cfg = c; |
1157 | char *keyfile; | 1240 | char *keyfile; |
1158 | unsigned long long tneigh; | 1241 | unsigned long long tneigh; |
1159 | struct Plugin_Address * cur; | 1242 | struct Plugin_Address *cur; |
1160 | const char * addr_str; | 1243 | const char *addr_str; |
1161 | struct stat sbuf; | 1244 | struct stat sbuf; |
1162 | unsigned int suggest_res; | 1245 | unsigned int suggest_res; |
1163 | 1246 | ||
@@ -1175,8 +1258,9 @@ run (void *cls, | |||
1175 | addr_head = NULL; | 1258 | addr_head = NULL; |
1176 | count_str_addr = 0; | 1259 | count_str_addr = 0; |
1177 | /* parse configuration */ | 1260 | /* parse configuration */ |
1178 | if (GNUNET_CONFIGURATION_have_value (c,"PATHS", "SERVICEHOME")) | 1261 | if (GNUNET_CONFIGURATION_have_value (c, "PATHS", "SERVICEHOME")) |
1179 | GNUNET_CONFIGURATION_get_value_string (c, "PATHS", "SERVICEHOME", &servicehome); | 1262 | GNUNET_CONFIGURATION_get_value_string (c, "PATHS", "SERVICEHOME", |
1263 | &servicehome); | ||
1180 | 1264 | ||
1181 | 1265 | ||
1182 | if ((GNUNET_OK != | 1266 | if ((GNUNET_OK != |
@@ -1188,21 +1272,21 @@ run (void *cls, | |||
1188 | GNUNET_CONFIGURATION_get_value_filename (c, | 1272 | GNUNET_CONFIGURATION_get_value_filename (c, |
1189 | "GNUNETD", | 1273 | "GNUNETD", |
1190 | "HOSTKEY", &keyfile))) | 1274 | "HOSTKEY", &keyfile))) |
1191 | { | 1275 | { |
1192 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1276 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1193 | _ | 1277 | _ |
1194 | ("Transport service is lacking key configuration settings. Exiting.\n")); | 1278 | ("Transport service is lacking key configuration settings. Exiting.\n")); |
1195 | GNUNET_SCHEDULER_shutdown (); | 1279 | GNUNET_SCHEDULER_shutdown (); |
1196 | fail = 1; | 1280 | fail = 1; |
1197 | return; | 1281 | return; |
1198 | } | 1282 | } |
1199 | 1283 | ||
1200 | if ((GNUNET_OK != | 1284 | if ((GNUNET_OK != |
1201 | GNUNET_CONFIGURATION_get_value_number (cfg, | 1285 | GNUNET_CONFIGURATION_get_value_number (cfg, |
1202 | "transport-https", | 1286 | "transport-https", |
1203 | "PORT", | 1287 | "PORT", |
1204 | &port)) || | 1288 | &port)) || |
1205 | (port > 65535) || (port == 0)) | 1289 | (port > 65535) || (port == 0)) |
1206 | { | 1290 | { |
1207 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | 1291 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, |
1208 | "https", | 1292 | "https", |
@@ -1212,59 +1296,63 @@ run (void *cls, | |||
1212 | } | 1296 | } |
1213 | 1297 | ||
1214 | /* Get private key file from config */ | 1298 | /* Get private key file from config */ |
1215 | if (GNUNET_CONFIGURATION_have_value (cfg, | 1299 | if (GNUNET_CONFIGURATION_have_value (cfg, "transport-https", "KEY_FILE")) |
1216 | "transport-https", "KEY_FILE")) | ||
1217 | { | 1300 | { |
1218 | GNUNET_CONFIGURATION_get_value_string (cfg, | 1301 | GNUNET_CONFIGURATION_get_value_string (cfg, |
1219 | "transport-https", | 1302 | "transport-https", |
1220 | "KEY_FILE", | 1303 | "KEY_FILE", &key_file); |
1221 | &key_file); | ||
1222 | } | 1304 | } |
1223 | if (key_file == NULL) | 1305 | if (key_file == NULL) |
1224 | GNUNET_asprintf(&key_file,"https.key"); | 1306 | GNUNET_asprintf (&key_file, "https.key"); |
1225 | 1307 | ||
1226 | if (0 == stat (key_file, &sbuf )) | 1308 | if (0 == stat (key_file, &sbuf)) |
1227 | { | 1309 | { |
1228 | if (0 == remove(key_file)) | 1310 | if (0 == remove (key_file)) |
1229 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Successfully removed existing private key file `%s'\n",key_file); | 1311 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1230 | else | 1312 | "Successfully removed existing private key file `%s'\n", |
1231 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove private key file `%s'\n",key_file); | 1313 | key_file); |
1314 | else | ||
1315 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1316 | "Failed to remove private key file `%s'\n", key_file); | ||
1232 | } | 1317 | } |
1233 | 1318 | ||
1234 | /* Get private key file from config */ | 1319 | /* Get private key file from config */ |
1235 | if (GNUNET_CONFIGURATION_have_value (cfg, | 1320 | if (GNUNET_CONFIGURATION_have_value (cfg, "transport-https", "CERT_FILE")) |
1236 | "transport-https", "CERT_FILE")) | ||
1237 | { | 1321 | { |
1238 | GNUNET_CONFIGURATION_get_value_string (cfg, | 1322 | GNUNET_CONFIGURATION_get_value_string (cfg, |
1239 | "transport-https", | 1323 | "transport-https", |
1240 | "CERT_FILE", | 1324 | "CERT_FILE", &cert_file); |
1241 | &cert_file); | ||
1242 | } | 1325 | } |
1243 | if (cert_file == NULL) | 1326 | if (cert_file == NULL) |
1244 | GNUNET_asprintf(&cert_file,"https.cert"); | 1327 | GNUNET_asprintf (&cert_file, "https.cert"); |
1245 | 1328 | ||
1246 | if (0 == stat (cert_file, &sbuf )) | 1329 | if (0 == stat (cert_file, &sbuf)) |
1247 | { | 1330 | { |
1248 | if (0 == remove(cert_file)) | 1331 | if (0 == remove (cert_file)) |
1249 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Successfully removed existing certificate file `%s'\n",cert_file); | 1332 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1250 | else | 1333 | "Successfully removed existing certificate file `%s'\n", |
1251 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove existing certificate file `%s'\n",cert_file); | 1334 | cert_file); |
1335 | else | ||
1336 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1337 | "Failed to remove existing certificate file `%s'\n", | ||
1338 | cert_file); | ||
1252 | } | 1339 | } |
1253 | 1340 | ||
1254 | max_connect_per_transport = (uint32_t) tneigh; | 1341 | max_connect_per_transport = (uint32_t) tneigh; |
1255 | my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); | 1342 | my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); |
1256 | GNUNET_free (keyfile); | 1343 | GNUNET_free (keyfile); |
1257 | if (my_private_key == NULL) | 1344 | if (my_private_key == NULL) |
1258 | { | 1345 | { |
1259 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1346 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1260 | _("Transport service could not access hostkey. Exiting.\n")); | 1347 | _("Transport service could not access hostkey. Exiting.\n")); |
1261 | GNUNET_SCHEDULER_shutdown (); | 1348 | GNUNET_SCHEDULER_shutdown (); |
1262 | fail = 1; | 1349 | fail = 1; |
1263 | return; | 1350 | return; |
1264 | } | 1351 | } |
1265 | 1352 | ||
1266 | GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); | 1353 | GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); |
1267 | GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key), &my_identity.hashPubKey); | 1354 | GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key), |
1355 | &my_identity.hashPubKey); | ||
1268 | 1356 | ||
1269 | /* assertions before start */ | 1357 | /* assertions before start */ |
1270 | GNUNET_assert ((port > 0) && (port <= 65535)); | 1358 | GNUNET_assert ((port > 0) && (port <= 65535)); |
@@ -1272,7 +1360,8 @@ run (void *cls, | |||
1272 | /* load plugins... */ | 1360 | /* load plugins... */ |
1273 | setup_plugin_environment (); | 1361 | setup_plugin_environment (); |
1274 | GNUNET_asprintf (&libname, "libgnunet_plugin_transport_https"); | 1362 | GNUNET_asprintf (&libname, "libgnunet_plugin_transport_https"); |
1275 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading HTTPS transport plugin `%s'\n"),libname); | 1363 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1364 | _("Loading HTTPS transport plugin `%s'\n"), libname); | ||
1276 | api = GNUNET_PLUGIN_load (libname, &env); | 1365 | api = GNUNET_PLUGIN_load (libname, &env); |
1277 | GNUNET_free (libname); | 1366 | GNUNET_free (libname); |
1278 | if (api == NULL) | 1367 | if (api == NULL) |
@@ -1286,46 +1375,52 @@ run (void *cls, | |||
1286 | ti_timeout = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &task_timeout, NULL); | 1375 | ti_timeout = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &task_timeout, NULL); |
1287 | 1376 | ||
1288 | /* testing plugin functionality */ | 1377 | /* testing plugin functionality */ |
1289 | GNUNET_assert (0!=fail_notify_address_count); | 1378 | GNUNET_assert (0 != fail_notify_address_count); |
1290 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Transport plugin returned %u addresses to connect to\n"), fail_notify_address_count); | 1379 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1380 | _("Transport plugin returned %u addresses to connect to\n"), | ||
1381 | fail_notify_address_count); | ||
1291 | 1382 | ||
1292 | /* testing pretty printer with all addresses obtained from the plugin*/ | 1383 | /* testing pretty printer with all addresses obtained from the plugin */ |
1293 | cur = addr_head; | 1384 | cur = addr_head; |
1294 | while (cur != NULL) | 1385 | while (cur != NULL) |
1295 | { | 1386 | { |
1296 | 1387 | ||
1297 | api->address_pretty_printer (api->cls, "http",cur->addr,cur->addrlen, GNUNET_NO,TEST_TIMEOUT, &pretty_printer_cb,NULL); | 1388 | api->address_pretty_printer (api->cls, "http", cur->addr, cur->addrlen, |
1389 | GNUNET_NO, TEST_TIMEOUT, &pretty_printer_cb, | ||
1390 | NULL); | ||
1298 | addr_str = api->address_to_string (api->cls, cur->addr, cur->addrlen); | 1391 | addr_str = api->address_to_string (api->cls, cur->addr, cur->addrlen); |
1299 | suggest_res = api->check_address (api->cls, cur->addr, cur->addrlen); | 1392 | suggest_res = api->check_address (api->cls, cur->addr, cur->addrlen); |
1300 | 1393 | ||
1301 | GNUNET_assert (GNUNET_OK == suggest_res); | 1394 | GNUNET_assert (GNUNET_OK == suggest_res); |
1302 | GNUNET_assert (NULL != addr_str); | 1395 | GNUNET_assert (NULL != addr_str); |
1303 | count_str_addr++; | 1396 | count_str_addr++; |
1304 | GNUNET_free ( (char *) addr_str); | 1397 | GNUNET_free ((char *) addr_str); |
1305 | cur = cur->next; | 1398 | cur = cur->next; |
1306 | } | 1399 | } |
1307 | GNUNET_assert (fail_pretty_printer_count > 0); | 1400 | GNUNET_assert (fail_pretty_printer_count > 0); |
1308 | GNUNET_assert (fail_pretty_printer_count==fail_notify_address_count); | 1401 | GNUNET_assert (fail_pretty_printer_count == fail_notify_address_count); |
1309 | GNUNET_assert (fail_pretty_printer_count==count_str_addr); | 1402 | GNUNET_assert (fail_pretty_printer_count == count_str_addr); |
1310 | fail_pretty_printer=GNUNET_NO; | 1403 | fail_pretty_printer = GNUNET_NO; |
1311 | fail_addr_to_str=GNUNET_NO; | 1404 | fail_addr_to_str = GNUNET_NO; |
1312 | 1405 | ||
1313 | struct IPv4HttpAddress failing_addr; | 1406 | struct IPv4HttpAddress failing_addr; |
1314 | 1407 | ||
1315 | /* Suggesting addresses with wrong size*/ | 1408 | /* Suggesting addresses with wrong size */ |
1316 | failing_addr.ipv4_addr = htonl(INADDR_LOOPBACK); | 1409 | failing_addr.ipv4_addr = htonl (INADDR_LOOPBACK); |
1317 | failing_addr.u_port = htons(0); | 1410 | failing_addr.u_port = htons (0); |
1318 | suggest_res = api->check_address (api->cls,&failing_addr,sizeof (struct IPv6HttpAddress)); | 1411 | suggest_res = |
1412 | api->check_address (api->cls, &failing_addr, | ||
1413 | sizeof (struct IPv6HttpAddress)); | ||
1319 | GNUNET_assert (GNUNET_SYSERR == suggest_res); | 1414 | GNUNET_assert (GNUNET_SYSERR == suggest_res); |
1320 | 1415 | ||
1321 | /* Suggesting addresses with wrong address*/ | 1416 | /* Suggesting addresses with wrong address */ |
1322 | failing_addr.ipv4_addr = htonl(0xffc00000); | 1417 | failing_addr.ipv4_addr = htonl (0xffc00000); |
1323 | failing_addr.u_port = htons(12389); | 1418 | failing_addr.u_port = htons (12389); |
1324 | suggest_res = api->check_address (api->cls,&failing_addr,100); | 1419 | suggest_res = api->check_address (api->cls, &failing_addr, 100); |
1325 | GNUNET_assert (GNUNET_SYSERR == suggest_res); | 1420 | GNUNET_assert (GNUNET_SYSERR == suggest_res); |
1326 | 1421 | ||
1327 | /* test sending to client */ | 1422 | /* test sending to client */ |
1328 | multi_handle = curl_multi_init(); | 1423 | multi_handle = curl_multi_init (); |
1329 | 1424 | ||
1330 | /* Setting up buffers */ | 1425 | /* Setting up buffers */ |
1331 | buffer_in.size = HTTP_BUFFER_SIZE; | 1426 | buffer_in.size = HTTP_BUFFER_SIZE; |
@@ -1354,10 +1449,12 @@ run (void *cls, | |||
1354 | test_valid_ident.test_executed = GNUNET_NO; | 1449 | test_valid_ident.test_executed = GNUNET_NO; |
1355 | test_valid_ident.test_failed = GNUNET_YES; | 1450 | test_valid_ident.test_failed = GNUNET_YES; |
1356 | 1451 | ||
1357 | test_addr = (char *) api->address_to_string (api->cls,addr_head->addr,addr_head->addrlen); | 1452 | test_addr = |
1453 | (char *) api->address_to_string (api->cls, addr_head->addr, | ||
1454 | addr_head->addrlen); | ||
1358 | 1455 | ||
1359 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("\nPhase 0\n\n")); | 1456 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("\nPhase 0\n\n")); |
1360 | run_connection_tests(0, NULL); | 1457 | run_connection_tests (0, NULL); |
1361 | 1458 | ||
1362 | /* testing finished */ | 1459 | /* testing finished */ |
1363 | 1460 | ||
@@ -1380,6 +1477,7 @@ main (int argc, char *const *argv) | |||
1380 | GNUNET_GETOPT_OPTION_END | 1477 | GNUNET_GETOPT_OPTION_END |
1381 | }; | 1478 | }; |
1382 | int ret; | 1479 | int ret; |
1480 | |||
1383 | char *const argv_prog[] = { | 1481 | char *const argv_prog[] = { |
1384 | "test_gnunet_transport_plugin.https", | 1482 | "test_gnunet_transport_plugin.https", |
1385 | "-c", | 1483 | "-c", |
@@ -1401,11 +1499,15 @@ main (int argc, char *const *argv) | |||
1401 | NULL); | 1499 | NULL); |
1402 | 1500 | ||
1403 | struct GNUNET_CONFIGURATION_Handle *cfg; | 1501 | struct GNUNET_CONFIGURATION_Handle *cfg; |
1502 | |||
1404 | cfg = GNUNET_CONFIGURATION_create (); | 1503 | cfg = GNUNET_CONFIGURATION_create (); |
1405 | 1504 | ||
1406 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg, "test_plugin_transport_data_http.conf")); | 1505 | GNUNET_assert (GNUNET_OK == |
1407 | if (GNUNET_CONFIGURATION_have_value (cfg,"PATHS", "SERVICEHOME")) | 1506 | GNUNET_CONFIGURATION_load (cfg, |
1408 | GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME", &servicehome); | 1507 | "test_plugin_transport_data_http.conf")); |
1508 | if (GNUNET_CONFIGURATION_have_value (cfg, "PATHS", "SERVICEHOME")) | ||
1509 | GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME", | ||
1510 | &servicehome); | ||
1409 | GNUNET_DISK_directory_remove (servicehome); | 1511 | GNUNET_DISK_directory_remove (servicehome); |
1410 | GNUNET_CONFIGURATION_destroy (cfg); | 1512 | GNUNET_CONFIGURATION_destroy (cfg); |
1411 | 1513 | ||
@@ -1413,7 +1515,8 @@ main (int argc, char *const *argv) | |||
1413 | GNUNET_PROGRAM_run (5, | 1515 | GNUNET_PROGRAM_run (5, |
1414 | argv_prog, | 1516 | argv_prog, |
1415 | "test_gnunet_transport_plugin.https", | 1517 | "test_gnunet_transport_plugin.https", |
1416 | "testcase", options, &run, NULL)) ? GNUNET_NO : GNUNET_YES; | 1518 | "testcase", options, &run, |
1519 | NULL)) ? GNUNET_NO : GNUNET_YES; | ||
1417 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("\ndelete\n\n")); | 1520 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("\ndelete\n\n")); |
1418 | if (servicehome != NULL) | 1521 | if (servicehome != NULL) |
1419 | { | 1522 | { |