From 7181a8fb4f75af69d82709b975ffb9c991e45ec7 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Wed, 5 May 2010 15:35:43 +0000 Subject: [PATCH] --- src/transport/plugin_transport_http.c | 44 +++++++-------- .../test_plugin_transport_data_http.conf | 25 ++++++++- src/transport/test_plugin_transport_http.c | 54 +++++++++++++++++-- 3 files changed, 92 insertions(+), 31 deletions(-) diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index 0b7e58f76..f138268b6 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c @@ -142,22 +142,22 @@ struct Plugin static struct Plugin *plugin; /** - * Daemon for listening for new connections. + * Daemon for listening for new IPv4 connections. */ static struct MHD_Daemon *http_daemon_v4; /** - * Daemon for listening for new connections. + * Daemon for listening for new IPv6connections. */ static struct MHD_Daemon *http_daemon_v6; /** - * Our primary task for http + * Our primary task for http daemon handling IPv4 connections */ static GNUNET_SCHEDULER_TaskIdentifier http_task_v4; /** - * Our primary task for http + * Our primary task for http daemon handling IPv6 connections */ static GNUNET_SCHEDULER_TaskIdentifier http_task_v6; @@ -324,13 +324,12 @@ accessHandlerCallback (void *cls, { /* PUT method here */ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Got PUT Request with size %u \n",upload_data_size); - - // GNUNET_STATISTICS_update( plugin->env->stats , gettext_noop("# PUT requests"), 1, GNUNET_NO); + GNUNET_STATISTICS_update( plugin->env->stats , gettext_noop("# PUT requests"), 1, GNUNET_NO); } if ( 0 == strcmp (MHD_HTTP_METHOD_GET, method) ) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Got GET Request with size\n"); - // GNUNET_STATISTICS_update( plugin->env->stats , gettext_noop("# GET requests"), 1, GNUNET_NO); + GNUNET_STATISTICS_update( plugin->env->stats , gettext_noop("# GET requests"), 1, GNUNET_NO); } response = MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE), @@ -368,7 +367,8 @@ run_daemon (void *cls, GNUNET_assert (MHD_YES == MHD_run (daemon_handle)); if (daemon_handle == http_daemon_v4) http_task_v4 = prepare_daemon (daemon_handle); - + if (daemon_handle == http_daemon_v6) + http_task_v6 = prepare_daemon (daemon_handle); } /** @@ -463,7 +463,6 @@ libgnunet_plugin_transport_http_done (void *cls) curl_multi_cleanup (curl_multi); curl_multi = NULL; } - /* GNUNET_SERVICE_stop (plugin->service); */ GNUNET_free (plugin); GNUNET_free (api); return NULL; @@ -478,7 +477,6 @@ libgnunet_plugin_transport_http_init (void *cls) struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; struct GNUNET_TRANSPORT_PluginFunctions *api; long long unsigned int port; - /* struct GNUNET_SERVICE_Context *service; */ plugin = GNUNET_malloc (sizeof (struct Plugin)); plugin->env = env; @@ -490,18 +488,7 @@ libgnunet_plugin_transport_http_init (void *cls) api->address_pretty_printer = &http_plugin_address_pretty_printer; api->check_address = &http_plugin_address_suggested; - /* - service = GNUNET_SERVICE_start ("transport-http", env->sched, env->cfg); - if (service == NULL) - { - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, - "http", - _("Failed to start service for `%s' transport plugin.\n"), - "http"); - return NULL; - } - plugin->service = service; - */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting http plugin...\n"); /* Reading port number from config file */ if ((GNUNET_OK != @@ -521,7 +508,6 @@ libgnunet_plugin_transport_http_init (void *cls) } if ((http_daemon_v4 == NULL) && (http_daemon_v6 == NULL) && (port != 0)) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD on port %u with IPv6 disabled\n",port); http_daemon_v4 = MHD_start_daemon (MHD_NO_FLAG, port, &acceptPolicyCallback, @@ -531,7 +517,6 @@ libgnunet_plugin_transport_http_init (void *cls) MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16, MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (16 * 1024), MHD_OPTION_END); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD on port %u with IPv6 enabled\n",port); http_daemon_v6 = MHD_start_daemon (MHD_USE_IPv6, port, &acceptPolicyCallback, @@ -543,6 +528,14 @@ libgnunet_plugin_transport_http_init (void *cls) MHD_OPTION_END); } + + if ((http_daemon_v4 != NULL) && (http_daemon_v6 != NULL)) + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD on port %u with IPv4 and IPv6 enabled\n",port); + if ((http_daemon_v4 != NULL) && (http_daemon_v6 == NULL)) + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD on port %u with IPv4 enabled\n",port); + if ((http_daemon_v4 == NULL) && (http_daemon_v6 != NULL)) + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD on port %u with IPv6 enabled\n",port); + curl_multi = curl_multi_init (); if (http_daemon_v4 != NULL) @@ -550,14 +543,13 @@ libgnunet_plugin_transport_http_init (void *cls) if (http_daemon_v6 != NULL) http_task_v6 = prepare_daemon (http_daemon_v6); - /* if (NULL == plugin->env->stats) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to retrieve statistics handle\n")); libgnunet_plugin_transport_http_done (api); return NULL; - }*/ + } GNUNET_STATISTICS_set ( env->stats, "# PUT requests", 0, GNUNET_NO); GNUNET_STATISTICS_set ( env->stats, "# GET requests", 0, GNUNET_NO); diff --git a/src/transport/test_plugin_transport_data_http.conf b/src/transport/test_plugin_transport_data_http.conf index 7b771b425..63272b203 100644 --- a/src/transport/test_plugin_transport_data_http.conf +++ b/src/transport/test_plugin_transport_data_http.conf @@ -1,7 +1,28 @@ [PATHS] -DEFAULTCONFIG = test_transport_api_tcp_peer1.conf +DEFAULTCONFIG = test_plugin_transport_data_http.conf SERVICEHOME = /tmp/test-gnunetd-transport-peer-1/ [transport-http] PORT = 12389 -DEBUG = YES \ No newline at end of file +DEBUG = YES + +[statistics] +ALLOW_SHUTDOWN = YES +ACCEPT_FROM6 = ::1; +ACCEPT_FROM = 127.0.0.1; +BINARY = gnunet-service-statistics +CONFIG = $DEFAULTCONFIG +HOME = $SERVICEHOME +HOSTNAME = localhost +PORT = 12367 + +[arm] +DEFAULTSERVICES = resolver transport core statistics topology hostlist +ALLOW_SHUTDOWN = YES +ACCEPT_FROM6 = ::1; +ACCEPT_FROM = 127.0.0.1; +BINARY = gnunet-service-arm +CONFIG = $DEFAULTCONFIG +HOME = $SERVICEHOME +HOSTNAME = localhost +PORT = 12366 \ No newline at end of file diff --git a/src/transport/test_plugin_transport_http.c b/src/transport/test_plugin_transport_http.c index a7a2c2cb7..0412badd4 100644 --- a/src/transport/test_plugin_transport_http.c +++ b/src/transport/test_plugin_transport_http.c @@ -33,6 +33,7 @@ #include "gnunet_protocols.h" #include "gnunet_program_lib.h" #include "gnunet_signatures.h" +#include "gnunet_service_lib.h" #include "plugin_transport.h" #include "gnunet_statistics_service.h" #include "transport.h" @@ -84,12 +85,14 @@ static uint32_t max_connect_per_transport; /** * Environment for this plugin. */ -struct GNUNET_TRANSPORT_PluginEnvironment env; +static struct GNUNET_TRANSPORT_PluginEnvironment env; /** *handle for the api provided by this plugin */ -struct GNUNET_TRANSPORT_PluginFunctions *api; +static struct GNUNET_TRANSPORT_PluginFunctions *api; + +static struct GNUNET_SERVICE_Context *service; /** * Did the test pass or fail? @@ -98,6 +101,8 @@ static int fail; static GNUNET_SCHEDULER_TaskIdentifier timeout_task; +pid_t pid; + /** * Initialize Environment for this plugin */ @@ -152,6 +157,12 @@ shutdown_clean () { if (timeout_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel( sched, timeout_task ); + if (NULL != service) GNUNET_SERVICE_stop (service); + if (0 != PLIBC_KILL (pid, SIGTERM)) + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); + fail = 1; + } unload_plugins(env.cls, env.cfg); } @@ -184,6 +195,20 @@ setup_plugin_environment () env.max_connections = max_connect_per_transport; } +static int +process_stat (void *cls, + const char *subsystem, + const char *name, + uint64_t value, + int is_persistent) +{ + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _("Value: %llums\n"), + (unsigned long long) value); + return GNUNET_OK; +} + + /** * Runs the test. * @@ -222,9 +247,32 @@ run (void *cls, return; } + pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics", + "gnunet-service-statistics", + "-L", "DEBUG", + "-c", "test_plugin_transport_data_http.conf", NULL); + + + if ( pid == -1) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + _("Failed to start service for `%s' http transport plugin test.\n"), + "statistics"); + return; + } - // stats = GNUNET_STATISTICS_create (sched, "http-transport", cfg); + + stats = GNUNET_STATISTICS_create (sched, "http-transport", cfg); + env.stats = stats; + + GNUNET_STATISTICS_get (stats, + "http-transport", + gettext_noop("# PUT requests"), + GNUNET_TIME_UNIT_MINUTES, + NULL, + &process_stat, + NULL); /* max_connect_per_transport = (uint32_t) tneigh; my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); -- 2.25.1