-stat counter for http
authorMatthias Wachs <wachs@net.in.tum.de>
Fri, 27 Apr 2012 13:14:57 +0000 (13:14 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Fri, 27 Apr 2012 13:14:57 +0000 (13:14 +0000)
src/transport/plugin_transport_http.c
src/transport/plugin_transport_http.h
src/transport/plugin_transport_http_client.c
src/transport/plugin_transport_http_server.c

index fb06bd7f5d925d66804a67f01d41d631ef2c1ff3..1078b541a86d36ae469e05310b799af08ada93eb 100644 (file)
@@ -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;
index ab268e244b14c1bb46208f28e3061aeea722d52c..89fb86dd92a276ce14af33b5ad9288a3d1f9b541 100644 (file)
@@ -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);
 
index eefc98b2ef3e52ce1bcd40a7c413155525d63929..c64a594cdf9ef319f5976ccaf3cd0765414f6863 100644 (file)
@@ -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)
   {
index 22196b2184ffe5b23ea29740b4d0f01daeb2d4bf..1ce08435d7206386bed8ef456be2e83c3f1ce89a 100644 (file)
@@ -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);
   }
 }