From a689f1c66d2663ab1f3e6ec6347707612908d25c Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Fri, 27 Apr 2012 13:14:57 +0000 Subject: [PATCH] -stat counter for http --- src/transport/plugin_transport_http.c | 6 ++-- src/transport/plugin_transport_http.h | 15 +++++++++- src/transport/plugin_transport_http_client.c | 18 +++++++++--- src/transport/plugin_transport_http_server.c | 29 +++++++++++++++++--- 4 files changed, 57 insertions(+), 11 deletions(-) diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index fb06bd7f5..1078b541a 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c @@ -772,7 +772,7 @@ http_plugin_send (void *cls, { #if DEBUG_HTTP GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Using outbound client session %p to send to `%session'\n", session, + "Using outbound client session %p to send to `%s'\n", session, GNUNET_i2s (&session->target)); #endif @@ -783,7 +783,7 @@ http_plugin_send (void *cls, { #if DEBUG_HTTP GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Using inbound server %p session to send to `%session'\n", session, + "Using inbound server %p session to send to `%s'\n", session, GNUNET_i2s (&session->target)); #endif @@ -1477,6 +1477,8 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) plugin = GNUNET_malloc (sizeof (struct Plugin)); plugin->env = env; + plugin->outbound_sessions = 0; + plugin->inbound_sessions = 0; api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); api->cls = plugin; api->disconnect = &http_plugin_disconnect; diff --git a/src/transport/plugin_transport_http.h b/src/transport/plugin_transport_http.h index ab268e244..89fb86dd9 100644 --- a/src/transport/plugin_transport_http.h +++ b/src/transport/plugin_transport_http.h @@ -45,7 +45,7 @@ #define DEBUG_HTTP GNUNET_EXTRA_LOGGING #define VERBOSE_SERVER GNUNET_EXTRA_LOGGING #define VERBOSE_CLIENT GNUNET_EXTRA_LOGGING -#define VERBOSE_CURL GNUNET_EXTRA_LOGGING +#define VERBOSE_CURL GNUNET_NO #if BUILD_HTTPS #define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_https_init @@ -159,6 +159,16 @@ struct Plugin */ int max_connections; + /** + * Number of outbound sessions + */ + unsigned int outbound_sessions; + + /** + * Number of inbound sessions + */ + unsigned int inbound_sessions; + /** * Plugin HTTPS SSL/TLS options * ---------------------------- @@ -453,6 +463,9 @@ struct HTTP_Message void *transmit_cont_cls; }; +int +exist_session (struct Plugin *plugin, struct Session *s); + void delete_session (struct Session *s); diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c index eefc98b2e..c64a594cd 100644 --- a/src/transport/plugin_transport_http_client.c +++ b/src/transport/plugin_transport_http_client.c @@ -264,11 +264,9 @@ client_disconnect (struct Session *s) if (s->client_put != NULL) { -#if DEBUG_HTTP GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Client: %X Deleting outbound PUT session to peer `%s'\n", s->client_put, GNUNET_i2s (&s->target)); -#endif mret = curl_multi_remove_handle (plugin->client_mh, s->client_put); if (mret != CURLM_OK) @@ -290,11 +288,9 @@ client_disconnect (struct Session *s) if (s->client_get != NULL) { -#if DEBUG_HTTP GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Client: %X Deleting outbound GET session to peer `%s'\n", s->client_get, GNUNET_i2s (&s->target)); -#endif mret = curl_multi_remove_handle (plugin->client_mh, s->client_get); if (mret != CURLM_OK) @@ -319,6 +315,14 @@ client_disconnect (struct Session *s) } plugin->cur_connections -= 2; + + GNUNET_assert (plugin->outbound_sessions > 0); + plugin->outbound_sessions --; + GNUNET_STATISTICS_set (plugin->env->stats, + "# HTTP outbound sessions", + plugin->outbound_sessions, + GNUNET_NO); + /* Re-schedule since handles have changed */ if (plugin->client_perform_task != GNUNET_SCHEDULER_NO_TASK) { @@ -634,6 +638,12 @@ client_connect (struct Session *s) /* Perform connect */ plugin->cur_connections += 2; + plugin->outbound_sessions ++; + GNUNET_STATISTICS_set (plugin->env->stats, + "# HTTP outbound sessions", + plugin->outbound_sessions, + GNUNET_NO); + /* Re-schedule since handles have changed */ if (plugin->client_perform_task != GNUNET_SCHEDULER_NO_TASK) { diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c index 22196b218..1ce08435d 100644 --- a/src/transport/plugin_transport_http_server.c +++ b/src/transport/plugin_transport_http_server.c @@ -419,12 +419,12 @@ server_lookup_session (struct Plugin *plugin, plugin->cur_connections++; GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Server: New inbound connection from %s with tag %u\n", + "Server: New %s connection from %s with tag %u\n", + method, GNUNET_i2s (&target), tag); - /* find duplicate session */ + /* find duplicate session */ t = plugin->head; - while (t != NULL) { if ((t->inbound) && @@ -480,6 +480,13 @@ server_lookup_session (struct Plugin *plugin, "Server: Found matching semi-session, merging session for peer `%s'\n", GNUNET_i2s (&target)); + GNUNET_break (0); + plugin->inbound_sessions ++; + GNUNET_STATISTICS_set (plugin->env->stats, + "# HTTP inbound sessions", + plugin->inbound_sessions, + GNUNET_NO); + goto found; } if ((direction == _RECEIVE) && (t->server_recv != NULL)) @@ -498,6 +505,14 @@ server_lookup_session (struct Plugin *plugin, GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Server: Found matching semi-session, merging session for peer `%s'\n", GNUNET_i2s (&target)); + + GNUNET_break (0); + plugin->inbound_sessions ++; + GNUNET_STATISTICS_set (plugin->env->stats, + "# HTTP inbound sessions", + plugin->inbound_sessions, + GNUNET_NO); + goto found; } @@ -741,7 +756,7 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, struct Session *s = NULL; struct Session *t = NULL; struct Plugin *plugin = NULL; - +GNUNET_break (0); if (sc == NULL) return; @@ -829,6 +844,12 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, s->msg_tk = NULL; } + GNUNET_assert (plugin->inbound_sessions > 0); + plugin->inbound_sessions --; + GNUNET_STATISTICS_set (plugin->env->stats, + "# HTTP inbound sessions", + plugin->inbound_sessions, GNUNET_NO); + notify_session_end (s->plugin, &s->target, s); } } -- 2.25.1