From b778d1dc7836038f1b5e89c081c92aec46ba76e4 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Wed, 16 Jun 2010 09:04:35 +0000 Subject: [PATCH] --- src/transport/plugin_transport_http.c | 46 ++++++---------------- src/transport/test_plugin_transport_http.c | 42 ++++++++++++-------- 2 files changed, 36 insertions(+), 52 deletions(-) diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index dcb778de9..58051e90e 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c @@ -246,11 +246,6 @@ struct Plugin */ struct GNUNET_TRANSPORT_PluginEnvironment *env; - /** - * Handle to the network service. - */ - struct GNUNET_SERVICE_Context *service; - unsigned int port_inbound; /** @@ -302,11 +297,6 @@ static struct Plugin *plugin; */ static CURLM *multi_handle; -/** - * Our hostname - */ -static char * hostname; - /** * Our ASCII encoded, hashed peer identity * This string is used to distinguish between connections and is added to the urls @@ -1454,8 +1444,6 @@ process_interfaces (void *cls, void *arg; uint16_t args; - - af = addr->sa_family; if (af == AF_INET) { @@ -1494,7 +1482,6 @@ process_interfaces (void *cls, return GNUNET_OK; } plugin->env->notify_address(plugin->env->cls,"http",arg, args, GNUNET_TIME_UNIT_FOREVER_REL); - return GNUNET_OK; } @@ -1577,10 +1564,6 @@ libgnunet_plugin_transport_http_done (void *cls) cs = cs_next; } - - - /* GNUNET_SERVICE_stop (plugin->service); */ - GNUNET_free (hostname); GNUNET_free (plugin); GNUNET_free (api); return NULL; @@ -1595,29 +1578,15 @@ libgnunet_plugin_transport_http_init (void *cls) { struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; struct GNUNET_TRANSPORT_PluginFunctions *api; - struct GNUNET_SERVICE_Context *service; unsigned int timeout; struct GNUNET_TIME_Relative gn_timeout; long long unsigned int port; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting http plugin...\n"); - service = NULL; - /* - service = GNUNET_SERVICE_start ("transport-http", env->sched, env->cfg); - if (service == NULL) - { - GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "", _ - ("Failed to start service for `%s' transport plugin.\n"), - "http"); - return NULL; - } - */ - plugin = GNUNET_malloc (sizeof (struct Plugin)); plugin->env = env; plugin->sessions = NULL; - plugin->service = service; api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); api->cls = plugin; api->send = &http_plugin_send; @@ -1626,8 +1595,6 @@ libgnunet_plugin_transport_http_init (void *cls) api->check_address = &http_plugin_address_suggested; api->address_to_string = &http_plugin_address_to_string; - hostname = GNUNET_RESOLVER_local_fqdn_get (); - /* Hashing our identity to use it in URLs */ GNUNET_CRYPTO_hash_to_enc ( &(plugin->env->my_identity->hashPubKey), &my_ascii_hash_ident); @@ -1647,6 +1614,10 @@ libgnunet_plugin_transport_http_init (void *cls) libgnunet_plugin_transport_http_done (api); return NULL; } + + GNUNET_assert ((port > 0) && (port <= 65535)); + GNUNET_assert (&my_ascii_hash_ident != NULL); + plugin->port_inbound = port; gn_timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT; timeout = ( gn_timeout.value / 1000); @@ -1682,9 +1653,14 @@ libgnunet_plugin_transport_http_init (void *cls) if (http_task_v4 != GNUNET_SCHEDULER_NO_TASK) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD with IPv4 on port %u\n",port); - if (http_task_v6 != GNUNET_SCHEDULER_NO_TASK) + else if (http_task_v6 != GNUNET_SCHEDULER_NO_TASK) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD with IPv4 and IPv6 on port %u\n",port); - + else + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No MHD was started, transport plugin not functional!\n"); + libgnunet_plugin_transport_http_done (api); + return NULL; + } /* Initializing cURL */ multi_handle = curl_multi_init(); diff --git a/src/transport/test_plugin_transport_http.c b/src/transport/test_plugin_transport_http.c index 882560745..468a2c883 100644 --- a/src/transport/test_plugin_transport_http.c +++ b/src/transport/test_plugin_transport_http.c @@ -351,18 +351,26 @@ shutdown_clean () struct Plugin_Address * tmp; /* Evaluate results */ - if ((fail_notify_address == GNUNET_NO) && (fail_pretty_printer == GNUNET_NO) && (fail_addr_to_str == GNUNET_NO) && - (test_no_ident.test_failed == GNUNET_NO) && (test_too_short_ident.test_failed == GNUNET_NO) && (test_too_long_ident.test_failed == GNUNET_NO) && - (test_valid_ident.test_failed == GNUNET_NO) && (fail_msgs_transmited_to_local_addrs == count_str_addr)) + fail = 0; + if ((fail_notify_address == GNUNET_YES) || (fail_pretty_printer == GNUNET_YES) || (fail_addr_to_str == GNUNET_YES)) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Tests successful\n"); - fail = 0; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test plugin functions failed\n"); + fail = 1; } - else + if ((test_no_ident.test_failed == GNUNET_YES) || (test_too_short_ident.test_failed == GNUNET_YES) || (test_too_long_ident.test_failed == GNUNET_YES)) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test connect with wrong data failed\n"); + fail = 1; + } + if ((test_valid_ident.test_failed == GNUNET_YES) || (fail_msgs_transmited_to_local_addrs != count_str_addr)) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Tests failed\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test sending with plugin failed\n"); fail = 1; } + if (fail != 1) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All tests successful\n"); + } curl_multi_cleanup(multi_handle); @@ -873,16 +881,15 @@ static void run_connection_tests( void ) if (test_no_ident.test_executed == GNUNET_NO) { /* Connecting to peer without identification */ + host_str = GNUNET_malloc (strlen ("http://localhost:12389/")+1); GNUNET_asprintf (&host_str, "http://localhost:%u/",port); GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer without any peer identification.\n")); test_no_ident.test_executed = GNUNET_YES; send_data ( &test_no_ident, host_str); GNUNET_free (host_str); - return; } - if (test_too_short_ident.test_executed == GNUNET_NO) { char * ident = "AAAAAAAAAA"; @@ -893,7 +900,6 @@ static void run_connection_tests( void ) test_too_short_ident.test_executed = GNUNET_YES; send_data ( &test_too_short_ident, host_str); GNUNET_free (host_str); - return; } @@ -904,18 +910,15 @@ static void run_connection_tests( void ) /* Connecting to peer with too long identification */ host_str = GNUNET_malloc (strlen ("http://localhost:12389/") + strlen (ident)); GNUNET_asprintf (&host_str, "http://localhost:%u/%s",port,ident); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too long peer identification.\n")); test_too_long_ident.test_executed = GNUNET_YES; send_data ( &test_too_long_ident, host_str); GNUNET_free (host_str); - return; } if (test_valid_ident.test_executed == GNUNET_NO) { struct GNUNET_CRYPTO_HashAsciiEncoded result; - GNUNET_CRYPTO_hash_to_enc(&my_identity.hashPubKey,&result); host_str = GNUNET_malloc (strlen ("http://localhost:12389/") + strlen ((const char *) &result)); GNUNET_asprintf (&host_str, "http://localhost:%u/%s",port,(char *) &result); @@ -924,7 +927,6 @@ static void run_connection_tests( void ) test_valid_ident.test_executed = GNUNET_YES; send_data ( &test_valid_ident, host_str); GNUNET_free (host_str); - return; } /* Using one of the addresses the plugin proposed */ @@ -1027,7 +1029,7 @@ run (void *cls, "transport-http", "PORT", &port)) || - (port > 65535) ) + (port > 65535) || (port == 0)) { GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "http", @@ -1035,6 +1037,7 @@ run (void *cls, ("Require valid port number for transport plugin `%s' in configuration!\n"), "transport-http"); } + max_connect_per_transport = (uint32_t) tneigh; my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); GNUNET_free (keyfile); @@ -1046,9 +1049,14 @@ run (void *cls, fail = 1; return; } + GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); - GNUNET_CRYPTO_hash (&my_public_key, - sizeof (my_public_key), &my_identity.hashPubKey); + GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key), &my_identity.hashPubKey); + + /* assertions before start */ + GNUNET_assert ((port > 0) && (port <= 65535)); + GNUNET_assert(&my_public_key != NULL); + GNUNET_assert(&my_identity.hashPubKey != NULL); /* load plugins... */ setup_plugin_environment (); -- 2.25.1