2 This file is part of GNUnet.
3 (C) 2010 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file transport/test_plugin_transport_http.c
22 * @brief testcase for plugin_transport_http.c
23 * @author Matthias Wachs
27 #include "gnunet_constants.h"
28 #include "gnunet_common.h"
29 #include "gnunet_getopt_lib.h"
30 #include "gnunet_hello_lib.h"
31 #include "gnunet_os_lib.h"
32 #include "gnunet_peerinfo_service.h"
33 #include "gnunet_plugin_lib.h"
34 #include "gnunet_protocols.h"
35 #include "gnunet_program_lib.h"
36 #include "gnunet_signatures.h"
37 #include "gnunet_service_lib.h"
38 #include "gnunet_crypto_lib.h"
40 #include "plugin_transport.h"
41 #include "gnunet_statistics_service.h"
42 #include "transport.h"
43 #include <curl/curl.h>
45 #define VERBOSE GNUNET_YES
46 #define DEBUG GNUNET_NO
47 #define DEBUG_CURL GNUNET_NO
48 #define HTTP_BUFFER_SIZE 2048
50 #define PLUGIN libgnunet_plugin_transport_template
53 * How long until we give up on transmitting the message?
55 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90)
58 * How long until we give up on transmitting the message?
60 #define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
63 * How long between recieve and send?
65 #define WAIT_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
70 * Struct for plugin addresses
75 * Next field for linked list
77 struct Plugin_Address * next;
80 * buffer containing data to send
85 * amount of data to sent
91 * Message to send using http
98 unsigned char buf[HTTP_BUFFER_SIZE];
101 * current position in buffer
118 * Struct for plugin addresses
123 * amount of bytes we recieved
128 * buffer for http transfers
130 unsigned char buf[HTTP_BUFFER_SIZE];
133 * buffer size this transfer
138 * amount of bytes we recieved
143 * HTTP Header result for transfer
145 unsigned int http_result_code;
150 unsigned int test_failed;
153 * was this test already executed?
155 unsigned int test_executed;
160 * Network format for IPv4 addresses.
162 struct IPv4HttpAddress
165 * IPv4 address, in network byte order.
170 * Port number, in network byte order.
178 * Network format for IPv6 addresses.
180 struct IPv6HttpAddress
185 struct in6_addr ipv6_addr;
188 * Port number, in network byte order.
198 /* static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key; */
203 static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key;
208 static struct GNUNET_PeerIdentity my_identity;
213 static struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key;
218 static long long unsigned int port;
223 struct GNUNET_SCHEDULER_Handle *sched;
226 * Our statistics handle.
228 struct GNUNET_STATISTICS_Handle *stats;
234 const struct GNUNET_CONFIGURATION_Handle *cfg;
237 * Number of neighbours we'd like to have.
239 static uint32_t max_connect_per_transport;
242 * Environment for this plugin.
244 static struct GNUNET_TRANSPORT_PluginEnvironment env;
247 *handle for the api provided by this plugin
249 static struct GNUNET_TRANSPORT_PluginFunctions *api;
252 * ID of the task controlling the testcase timeout
254 static GNUNET_SCHEDULER_TaskIdentifier ti_timeout;
256 static GNUNET_SCHEDULER_TaskIdentifier ti_send;
258 //const struct GNUNET_PeerIdentity * p;
261 * buffer for data to send
263 static struct HTTP_Message buffer_out;
266 * buffer for data to recieve
268 static struct HTTP_Message buffer_in;
271 struct Plugin_Address * addr_head;
274 * Did the test pass or fail?
276 static int fail_notify_address;
278 * Did the test pass or fail?
280 static int fail_notify_address_count;
283 * Did the test pass or fail?
285 static int fail_pretty_printer;
288 * Did the test pass or fail?
290 static int fail_pretty_printer_count;
293 * Did the test pass or fail?
295 static int fail_addr_to_str;
298 * Did the test pass or fail?
300 static int fail_transmit_to_local_addrs;
303 * Test: connect to peer without peer identification
305 static struct HTTP_Transfer test_no_ident;
308 * Test: connect to peer without peer identification
310 static struct HTTP_Transfer test_too_short_ident;
313 * Test: connect to peer without peer identification
315 static struct HTTP_Transfer test_too_long_ident;
318 * Test: connect to peer with valid peer identification
320 static struct HTTP_Transfer test_valid_ident;
323 * Did the test pass or fail?
332 static CURLM *multi_handle;
335 * The task sending data
337 static GNUNET_SCHEDULER_TaskIdentifier http_task_send;
345 struct Plugin_Address * cur;
346 struct Plugin_Address * tmp;
348 /* Evaluate results */
349 if ((fail_notify_address == GNUNET_NO) && (fail_pretty_printer == GNUNET_NO) && (fail_addr_to_str == GNUNET_NO) &&
350 (test_no_ident.test_failed == GNUNET_NO) && (test_too_short_ident.test_failed == GNUNET_NO) && (test_too_long_ident.test_failed == GNUNET_NO) &&
351 (test_valid_ident.test_failed == GNUNET_NO) && (fail_transmit_to_local_addrs == GNUNET_NO))
353 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Tests successful\n");
358 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Tests failed\n");
362 curl_multi_cleanup(multi_handle);
364 if (NULL != curl_handle)
365 curl_easy_cleanup (curl_handle);
367 /* cleaning addresses */
368 while (addr_head != NULL)
371 tmp = addr_head->next;
372 GNUNET_free (addr_head->addr);
373 GNUNET_free (addr_head);
377 if (ti_send != GNUNET_SCHEDULER_NO_TASK)
379 GNUNET_SCHEDULER_cancel(sched,ti_send);
380 ti_send = GNUNET_SCHEDULER_NO_TASK;
383 if (http_task_send != GNUNET_SCHEDULER_NO_TASK)
385 GNUNET_SCHEDULER_cancel(sched,http_task_send);
386 http_task_send = GNUNET_SCHEDULER_NO_TASK;
389 if (ti_timeout != GNUNET_SCHEDULER_NO_TASK)
391 GNUNET_SCHEDULER_cancel(sched,ti_timeout);
392 ti_timeout = GNUNET_SCHEDULER_NO_TASK;
394 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unloading http plugin\n");
395 GNUNET_assert (NULL == GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_http", api));
397 GNUNET_SCHEDULER_shutdown(sched);
399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Exiting testcase\n");
406 * Continuation called after plugin send message
409 * @result GNUNET_OK or GNUNET_SYSERR
412 static void task_send_cont (void *cls,
413 const struct GNUNET_PeerIdentity * target,
416 struct Plugin_Address * tmp_addr;
417 tmp_addr = addr_head;
418 while (tmp_addr->next != NULL)
420 tmp_addr = tmp_addr->next;
425 fail_transmit_to_local_addrs = GNUNET_NO;
429 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message was sent!\n");
436 * Task sending recieved message back to peer
442 task_send (void *cls,
443 const struct GNUNET_SCHEDULER_TaskContext *tc)
445 ti_timeout = GNUNET_SCHEDULER_NO_TASK;
446 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
449 if (GNUNET_YES==sent)
452 struct GNUNET_MessageHeader * msg = cls;
453 unsigned int len = ntohs(msg->size);
454 const char * msgc = (const char *) msg;
456 api->send(api->cls, p, msgc, len, 0, TIMEOUT, NULL,NULL, 0, GNUNET_NO, &task_send_cont, NULL);
463 * Recieves messages from plugin, in real world transport
465 static struct GNUNET_TIME_Relative
467 const struct GNUNET_PeerIdentity * peer,
468 const struct GNUNET_MessageHeader * message,
470 struct Session *session,
471 const char *sender_address,
472 uint16_t sender_address_len)
474 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testcase recieved new message from peer `%s' with type %u and length %u\n", GNUNET_i2s(peer),ntohs(message->type),ntohs(message->size));
475 return GNUNET_TIME_UNIT_ZERO;
478 static size_t send_function (void *stream, size_t size, size_t nmemb, void *ptr)
482 len = buffer_out.len;
484 if (( buffer_out.pos == len) || (len > (size * nmemb)))
486 memcpy(stream, buffer_out.buf, len);
487 buffer_out.pos = len;
491 static size_t recv_function (void *ptr, size_t size, size_t nmemb, void *ctx)
494 if (buffer_in.pos + size * nmemb > buffer_in.size)
495 return 0; /* overflow */
497 buffer_in.len = size * nmemb;
498 memcpy (&buffer_in.buf[buffer_in.pos], ptr, size * nmemb);
499 buffer_in.pos += size * nmemb;
500 buffer_in.len = buffer_in.pos;
501 buffer_in.buf[buffer_in.pos] = '\0';
502 return buffer_in.pos;
505 static size_t header_function( void *ptr, size_t size, size_t nmemb, void *stream)
507 struct HTTP_Transfer * res = (struct HTTP_Transfer *) stream;
509 unsigned int len = size * nmemb;
511 tmp = GNUNET_malloc ( len+1 );
513 if (tmp[len-2] == 13)
516 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Header: `%s'\n",tmp);
518 if (0==strcmp (tmp,"HTTP/1.1 100 Continue"))
520 res->http_result_code=100;
522 if (0==strcmp (tmp,"HTTP/1.1 200 OK"))
524 res->http_result_code=200;
526 if (0==strcmp (tmp,"HTTP/1.1 400 Bad Request"))
528 res->http_result_code=400;
530 if (0==strcmp (tmp,"HTTP/1.1 404 Not Found"))
532 res->http_result_code=404;
534 if (0==strcmp (tmp,"HTTP/1.1 413 Request entity too large"))
536 res->http_result_code=413;
543 static size_t send_prepare( struct HTTP_Transfer * result);
545 static void run_connection_tests( void );
547 static void send_execute (void *cls,
548 const struct GNUNET_SCHEDULER_TaskContext *tc)
550 struct HTTP_Transfer *res;
556 res = (struct HTTP_Transfer *) cls;
557 http_task_send = GNUNET_SCHEDULER_NO_TASK;
558 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
564 mret = curl_multi_perform (multi_handle, &running);
570 msg = curl_multi_info_read (multi_handle, &running);
571 GNUNET_break (msg != NULL);
574 /* get session for affected curl handle */
575 //cs = find_session_by_curlhandle (msg->easy_handle);
576 //GNUNET_assert ( cs != NULL );
581 if ( (msg->data.result != CURLE_OK) &&
582 (msg->data.result != CURLE_GOT_NOTHING) )
585 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
586 _("curl failed for `%s' at %s:%d: `%s'\n"),
587 "curl_multi_perform",
590 curl_easy_strerror (msg->data.result));
591 /* sending msg failed*/
593 if (res == &test_no_ident)
595 if ((res->http_result_code==404) && (buffer_in.len==208))
597 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer without any peer identification: test passed\n"));
598 res->test_failed = GNUNET_NO;
601 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer without any peer identification: test failed\n"));
603 if (res == &test_too_short_ident)
605 if ((res->http_result_code==404) && (buffer_in.len==208))
607 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too short peer identification: test passed\n"));
608 res->test_failed = GNUNET_NO;
611 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too short peer identification: test failed\n"));
613 if (res == &test_too_long_ident)
615 if ((res->http_result_code==404) && (buffer_in.len==208))
617 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too long peer identification: test passed\n"));
618 res->test_failed = GNUNET_NO;
621 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too long peer identification: test failed\n"));
623 if (res == &test_valid_ident)
625 if ((res->http_result_code==400))
627 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with valid peer identification: test passed\n"));
628 res->test_failed = GNUNET_NO;
631 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with valid peer identification: test failed\n"));
633 curl_easy_cleanup(curl_handle);
636 run_connection_tests();
643 while ( (running > 0) );
646 while (mret == CURLM_CALL_MULTI_PERFORM);
651 * Function setting up file descriptors and scheduling task to run
652 * @param ses session to send data to
653 * @return bytes sent to peer
655 static size_t send_prepare( struct HTTP_Transfer * result)
661 struct GNUNET_NETWORK_FDSet *grs;
662 struct GNUNET_NETWORK_FDSet *gws;
670 mret = curl_multi_fdset (multi_handle, &rs, &ws, &es, &max);
671 if (mret != CURLM_OK)
673 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
674 _("%s failed at %s:%d: `%s'\n"),
675 "curl_multi_fdset", __FILE__, __LINE__,
676 curl_multi_strerror (mret));
679 mret = curl_multi_timeout (multi_handle, &to);
680 if (mret != CURLM_OK)
682 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
683 _("%s failed at %s:%d: `%s'\n"),
684 "curl_multi_timeout", __FILE__, __LINE__,
685 curl_multi_strerror (mret));
689 grs = GNUNET_NETWORK_fdset_create ();
690 gws = GNUNET_NETWORK_fdset_create ();
691 GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
692 GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
693 http_task_send = GNUNET_SCHEDULER_add_select (sched,
694 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
695 GNUNET_SCHEDULER_NO_TASK,
696 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 0),
701 GNUNET_NETWORK_fdset_destroy (gws);
702 GNUNET_NETWORK_fdset_destroy (grs);
704 /* FIXME: return bytes REALLY sent */
709 * function to send data to server
711 static int send_data( struct HTTP_Transfer * result, char * url)
714 curl_handle = curl_easy_init();
715 if( NULL == curl_handle)
717 printf("easy_init failed \n");
718 return GNUNET_SYSERR;
721 curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L);
723 curl_easy_setopt(curl_handle, CURLOPT_URL, url);
724 curl_easy_setopt(curl_handle, CURLOPT_PUT, 1L);
725 curl_easy_setopt (curl_handle, CURLOPT_HEADERFUNCTION, &header_function);
726 curl_easy_setopt (curl_handle, CURLOPT_WRITEHEADER, result);
727 curl_easy_setopt (curl_handle, CURLOPT_WRITEFUNCTION, &recv_function);
728 curl_easy_setopt (curl_handle, CURLOPT_WRITEDATA, result);
729 curl_easy_setopt (curl_handle, CURLOPT_READFUNCTION, &send_function);
730 curl_easy_setopt (curl_handle, CURLOPT_READDATA, result);
731 curl_easy_setopt(curl_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t) buffer_out.len);
732 curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 30);
733 curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 20);
735 curl_multi_add_handle(multi_handle, curl_handle);
737 send_prepare(result);
744 * Plugin notifies transport (aka testcase) about its addresses
747 notify_address (void *cls,
751 struct GNUNET_TIME_Relative expires)
753 char address[INET6_ADDRSTRLEN];
755 struct Plugin_Address * pl_addr;
756 struct Plugin_Address * cur;
758 if (addrlen == (sizeof (struct IPv4HttpAddress)))
760 inet_ntop(AF_INET, (struct in_addr *) addr,address,INET_ADDRSTRLEN);
761 port = ntohs(((struct IPv4HttpAddress *) addr)->u_port);
763 else if (addrlen == (sizeof (struct IPv6HttpAddress)))
765 inet_ntop(AF_INET6, (struct in6_addr *) addr,address,INET6_ADDRSTRLEN);
766 port = ntohs(((struct IPv6HttpAddress *) addr)->u6_port);
773 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
774 _("Transport plugin notification for address: `%s':%u\n"),
777 pl_addr = GNUNET_malloc (sizeof (struct Plugin_Address) );
778 pl_addr->addrlen = addrlen;
779 pl_addr->addr = GNUNET_malloc(addrlen);
780 memcpy(pl_addr->addr,addr,addrlen);
781 pl_addr->next = NULL;
783 if ( NULL == addr_head)
790 while (NULL != cur->next)
796 fail_notify_address_count++;
797 fail_notify_address = GNUNET_NO;
801 * Setup plugin environment
804 setup_plugin_environment ()
809 env.my_identity = &my_identity;
811 env.receive = &receive;
812 env.notify_address = ¬ify_address;
813 env.max_connections = max_connect_per_transport;
818 * Task shutting down testcase if it a timeout occurs
821 task_timeout (void *cls,
822 const struct GNUNET_SCHEDULER_TaskContext *tc)
824 ti_timeout = GNUNET_SCHEDULER_NO_TASK;
825 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
828 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testcase timeout\n");
834 static void pretty_printer_cb (void *cls,
839 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Plugin returned pretty address: `%s'\n",address);
840 fail_pretty_printer_count++;
844 * Runs every single test to test the plugin
846 static void run_connection_tests( void )
850 /* resetting buffers */
851 buffer_in.size = HTTP_BUFFER_SIZE;
855 buffer_out.size = HTTP_BUFFER_SIZE;
860 if (test_no_ident.test_executed == GNUNET_NO)
862 /* Connecting to peer without identification */
863 host_str = GNUNET_malloc (strlen ("http://localhost:12389/")+1);
864 GNUNET_asprintf (&host_str, "http://localhost:%u/",port);
865 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer without any peer identification.\n"));
866 test_no_ident.test_executed = GNUNET_YES;
867 send_data ( &test_no_ident, host_str);
868 GNUNET_free (host_str);
873 if (test_too_short_ident.test_executed == GNUNET_NO)
875 char * ident = "AAAAAAAAAA";
876 /* Connecting to peer with too short identification */
877 host_str = GNUNET_malloc (strlen ("http://localhost:12389/") + strlen (ident));
878 GNUNET_asprintf (&host_str, "http://localhost:%u/%s",port,ident);
879 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too short peer identification.\n"));
880 test_too_short_ident.test_executed = GNUNET_YES;
881 send_data ( &test_too_short_ident, host_str);
882 GNUNET_free (host_str);
887 if (test_too_long_ident.test_executed == GNUNET_NO)
889 char * ident = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
891 /* Connecting to peer with too long identification */
892 host_str = GNUNET_malloc (strlen ("http://localhost:12389/") + strlen (ident));
893 GNUNET_asprintf (&host_str, "http://localhost:%u/%s",port,ident);
895 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too long peer identification.\n"));
896 test_too_long_ident.test_executed = GNUNET_YES;
897 send_data ( &test_too_long_ident, host_str);
898 GNUNET_free (host_str);
902 if (test_valid_ident.test_executed == GNUNET_NO)
904 struct GNUNET_CRYPTO_HashAsciiEncoded result;
906 GNUNET_CRYPTO_hash_to_enc(&my_identity.hashPubKey,&result);
907 host_str = GNUNET_malloc (strlen ("http://localhost:12389/") + strlen ((const char *) &result));
908 GNUNET_asprintf (&host_str, "http://localhost:%u/%s",port,(char *) &result);
910 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with valid peer identification.\n"));
911 test_valid_ident.test_executed = GNUNET_YES;
912 send_data ( &test_valid_ident, host_str);
913 GNUNET_free (host_str);
917 /* Using one of the addresses the plugin proposed */
918 GNUNET_assert (addr_head->addr != NULL);
920 struct Plugin_Address * tmp_addr;
921 struct GNUNET_MessageHeader msg;
922 char * tmp = GNUNET_malloc(sizeof(struct GNUNET_MessageHeader));
923 char address[INET6_ADDRSTRLEN];
926 msg.size=htons(sizeof(struct GNUNET_MessageHeader));
928 memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader));
930 tmp_addr = addr_head;
931 /* send a message to all addresses advertised by plugin */
934 while (tmp_addr != NULL)
936 if (tmp_addr->addrlen == (sizeof (struct IPv4HttpAddress)))
938 inet_ntop(AF_INET, (struct in_addr *) tmp_addr->addr,address,INET_ADDRSTRLEN);
939 port = ntohs(((struct IPv4HttpAddress *) tmp_addr->addr)->u_port);
940 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sending message to addres no. %u: `%s':%u\n", count,address, port);
942 else if (tmp_addr->addrlen == (sizeof (struct IPv6HttpAddress)))
944 inet_ntop(AF_INET6, (struct in6_addr *) tmp_addr->addr,address,INET6_ADDRSTRLEN);
945 port = ntohs(((struct IPv6HttpAddress *) tmp_addr->addr)->u6_port);
946 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sending message to addres no. %u: `%s':%u\n", count,address,port);
953 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, tmp_addr);
954 tmp_addr = tmp_addr->next;
958 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No more tests to run\n");
966 * @param s scheduler to use
967 * @param c configuration to use
971 struct GNUNET_SCHEDULER_Handle *s,
973 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
979 unsigned long long tneigh;
980 struct Plugin_Address * cur;
981 const char * addr_str;
983 unsigned int count_str_addr;
984 unsigned int suggest_res;
986 fail_pretty_printer = GNUNET_YES;
987 fail_notify_address = GNUNET_YES;
988 fail_addr_to_str = GNUNET_YES;
989 fail_transmit_to_local_addrs = GNUNET_YES;
993 /* parse configuration */
995 GNUNET_CONFIGURATION_get_value_number (c,
1000 GNUNET_CONFIGURATION_get_value_filename (c,
1002 "HOSTKEY", &keyfile)))
1004 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1006 ("Transport service is lacking key configuration settings. Exiting.\n"));
1007 GNUNET_SCHEDULER_shutdown (s);
1013 GNUNET_CONFIGURATION_get_value_number (cfg,
1019 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
1022 ("Require valid port number for transport plugin `%s' in configuration!\n"),
1025 max_connect_per_transport = (uint32_t) tneigh;
1026 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
1027 GNUNET_free (keyfile);
1028 if (my_private_key == NULL)
1030 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1031 _("Transport service could not access hostkey. Exiting.\n"));
1032 GNUNET_SCHEDULER_shutdown (s);
1036 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
1037 GNUNET_CRYPTO_hash (&my_public_key,
1038 sizeof (my_public_key), &my_identity.hashPubKey);
1040 /* load plugins... */
1041 setup_plugin_environment ();
1042 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading HTTP transport plugin `%s'\n"),"libgnunet_plugin_transport_http");
1043 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_http");
1044 api = GNUNET_PLUGIN_load (libname, &env);
1045 GNUNET_free (libname);
1048 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1049 _("Failed to load transport plugin for http\n"));
1054 ti_timeout = GNUNET_SCHEDULER_add_delayed (sched, TEST_TIMEOUT, &task_timeout, NULL);
1056 /* testing plugin functionality */
1057 GNUNET_assert (0!=fail_notify_address_count);
1058 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Transport plugin returned %u addresses to connect to\n"), fail_notify_address_count);
1060 /* testing pretty printer with all addresses obtained from the plugin*/
1065 api->address_pretty_printer (NULL,"http",cur->addr,cur->addrlen,GNUNET_NO,TEST_TIMEOUT,&pretty_printer_cb,NULL);
1066 addr_str = api->address_to_string (NULL,cur->addr,cur->addrlen);
1067 suggest_res = api->check_address (NULL,cur->addr,cur->addrlen);
1069 GNUNET_assert (GNUNET_OK == suggest_res);
1070 GNUNET_assert (NULL != addr_str);
1077 GNUNET_assert (fail_pretty_printer_count==fail_notify_address_count);
1078 GNUNET_assert (fail_pretty_printer_count==count_str_addr);
1079 fail_pretty_printer=GNUNET_NO;
1080 fail_addr_to_str=GNUNET_NO;
1082 /* Suggesting addresses with wrong port*/
1083 struct IPv4HttpAddress failing_addr;
1084 failing_addr.ipv4_addr = INADDR_LOOPBACK;
1085 failing_addr.u_port = 0;
1086 suggest_res = api->check_address (NULL,&failing_addr,sizeof (struct IPv4HttpAddress));
1087 GNUNET_assert (GNUNET_SYSERR == suggest_res);
1089 /* Suggesting addresses with wrong size*/
1090 failing_addr.ipv4_addr = INADDR_LOOPBACK;
1091 failing_addr.u_port = 0;
1092 suggest_res = api->check_address (NULL,&failing_addr,sizeof (struct IPv6HttpAddress));
1093 GNUNET_assert (GNUNET_SYSERR == suggest_res);
1095 /* Suggesting addresses with wrong address*/
1096 failing_addr.ipv4_addr = 0;
1097 failing_addr.u_port = 12389;
1098 suggest_res = api->check_address (NULL,&failing_addr,sizeof (struct IPv4HttpAddress));
1099 GNUNET_assert (GNUNET_SYSERR == suggest_res);
1101 /* test sending to client */
1102 multi_handle = curl_multi_init();
1104 /* Setting up buffers */
1105 buffer_in.size = HTTP_BUFFER_SIZE;
1109 buffer_out.size = HTTP_BUFFER_SIZE;
1113 /* Setting up connection tests */
1115 /* Test: connecting without a peer identification */
1116 test_no_ident.test_executed = GNUNET_NO;
1117 test_no_ident.test_failed = GNUNET_YES;
1119 /* Test: connecting with too short peer identification */
1120 test_too_short_ident.test_executed = GNUNET_NO;
1121 test_too_short_ident.test_failed = GNUNET_YES;
1123 /* Test: connecting with too long peer identification */
1124 test_too_long_ident.test_executed = GNUNET_NO;
1125 test_too_long_ident.test_failed = GNUNET_YES;
1127 /* Test: connecting with valid identification */
1128 test_valid_ident.test_executed = GNUNET_NO;
1129 test_valid_ident.test_failed = GNUNET_YES;
1131 run_connection_tests();
1133 /* testing finished */
1140 * The main function for the transport service.
1142 * @param argc number of arguments from the command line
1143 * @param argv command line arguments
1144 * @return 0 ok, 1 on error
1147 main (int argc, char *const *argv)
1150 static struct GNUNET_GETOPT_CommandLineOption options[] = {
1151 GNUNET_GETOPT_OPTION_END
1154 char *const argv_prog[] = {
1155 "test_plugin_transport_http",
1157 "test_plugin_transport_data_http.conf",
1166 GNUNET_log_setup ("test_plugin_transport_http",
1175 GNUNET_PROGRAM_run (5,
1177 "test_plugin_transport_http",
1178 "testcase", options, &run, NULL)) ? GNUNET_NO : GNUNET_YES;
1180 GNUNET_DISK_directory_remove ("/tmp/test_plugin_transport_http");
1185 /* end of test_plugin_transport_http.c */