gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r11257 - gnunet/src/transport


From: gnunet
Subject: [GNUnet-SVN] r11257 - gnunet/src/transport
Date: Fri, 7 May 2010 15:08:23 +0200

Author: wachs
Date: 2010-05-07 15:08:23 +0200 (Fri, 07 May 2010)
New Revision: 11257

Modified:
   gnunet/src/transport/test_plugin_transport_http.c
Log:


Modified: gnunet/src/transport/test_plugin_transport_http.c
===================================================================
--- gnunet/src/transport/test_plugin_transport_http.c   2010-05-07 12:37:58 UTC 
(rev 11256)
+++ gnunet/src/transport/test_plugin_transport_http.c   2010-05-07 13:08:23 UTC 
(rev 11257)
@@ -50,7 +50,7 @@
 /**
  * How long until we give up on transmitting the message?
  */
-#define STAT_INTERVALL GNUNET_TIME_relative_multiply 
(GNUNET_TIME_UNIT_SECONDS, 1)
+#define STAT_INTERVALL GNUNET_TIME_relative_multiply 
(GNUNET_TIME_UNIT_SECONDS, 3)
 
 /**
  * Our public key.
@@ -103,6 +103,8 @@
  */
 static GNUNET_SCHEDULER_TaskIdentifier ti_check_stat;
 
+static struct GNUNET_STATISTICS_GetHandle * stat_get_handle;
+
 static unsigned int timeout_count;
 
 /**
@@ -138,20 +140,6 @@
 
 }
 
-
-static void
-setup_plugin_environment ()
-{
-  env.cfg = cfg;
-  env.sched = sched;
-  env.stats = stats;
-  env.my_identity = &my_identity;
-  env.cls = &env;
-  env.receive = &receive;
-  env.notify_address = &notify_address;
-  env.max_connections = max_connect_per_transport;
-}
-
 /**
  * Simple example test that invokes
  * the check_address function of the plugin.
@@ -162,6 +150,12 @@
 static void
 shutdown_clean ()
 {
+  if (stat_get_handle != NULL)
+  {
+    GNUNET_STATISTICS_get_cancel(stat_get_handle);
+  }
+
+  GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
   if (ti_check_stat != GNUNET_SCHEDULER_NO_TASK)
     GNUNET_SCHEDULER_cancel(sched,ti_check_stat);
   ti_check_stat = GNUNET_SCHEDULER_NO_TASK;
@@ -171,6 +165,53 @@
   return;
 }
 
+static void
+setup_plugin_environment ()
+{
+  env.cfg = cfg;
+  env.sched = sched;
+  env.stats = stats;
+  env.my_identity = &my_identity;
+  env.cls = &env;
+  env.receive = &receive;
+  env.notify_address = &notify_address;
+  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)
+{
+  stat_get_handle = NULL;
+  if (value==1)
+    {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown, plugin failed \n");
+    fail = GNUNET_YES;
+    shutdown_clean();
+    return GNUNET_YES;
+    }
+  if (value==2)
+    {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown, plugin not failed \n");
+    shutdown_clean();
+    return GNUNET_YES;
+    }
+  return GNUNET_YES;
+}
+
+static void
+cont_func (void *cls,
+              const char *subsystem,
+              const char *name,
+              uint64_t value,
+              int is_persistent)
+{
+  stat_get_handle = NULL;
+}
+
 /**
  * Task that checks if we should try to download a hostlist.
  * If so, we initiate the download, otherwise we schedule
@@ -193,6 +234,14 @@
   }
   timeout_count++;
 
+  stat_get_handle = GNUNET_STATISTICS_get (stats,
+                                           "http-transport",
+                                           gettext_noop("shutdown"),
+                                           GNUNET_TIME_relative_multiply 
(GNUNET_TIME_UNIT_SECONDS, 2),
+                                           &cont_func,
+                                           &process_stat,
+                                           NULL);
+
   ti_check_stat = GNUNET_SCHEDULER_add_delayed (sched, STAT_INTERVALL, 
&task_check_stat, NULL);
   return;
 }
@@ -215,6 +264,17 @@
   sched = s;
   cfg = c;
 
+  /* settings up statistics */
+  stats = GNUNET_STATISTICS_create (sched, "http-transport", cfg);
+  if (NULL == stats)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                _("Failed to retrieve statistics handle\n"));
+    fail = GNUNET_YES;
+    shutdown_clean;
+    return ;
+  }
+
   /* load plugins... */
   setup_plugin_environment ();
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading HTTP transport plugin\n"));
@@ -229,6 +289,7 @@
     return;
   }
 
+
   ti_check_stat = GNUNET_SCHEDULER_add_now (sched, &task_check_stat, NULL);
 }
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]