fixing stats iteration
[oweals/gnunet.git] / src / testing / testing_group.c
index 80840a83b43e79eb3f82b53119da38f2fd5b8eee..f0786db7d8c9c9587febff791cd08dd1673cefff 100644 (file)
@@ -348,16 +348,6 @@ struct TopologyIterateContext
 
 struct StatsIterateContext
 {
-  /**
-   * Handle to the statistics service.
-   */
-  struct GNUNET_STATISTICS_Handle *stats_handle;
-
-  /**
-   * Handle for getting statistics.
-   */
-  struct GNUNET_STATISTICS_GetHandle *stats_get_handle;
-
   /**
    * Continuation to call once all stats information has been retrieved.
    */
@@ -395,6 +385,21 @@ struct CoreContext
   struct GNUNET_TESTING_Daemon *daemon;
 };
 
+struct StatsCoreContext
+{
+  void *iter_context;
+  struct GNUNET_TESTING_Daemon *daemon;
+  /**
+   * Handle to the statistics service.
+   */
+  struct GNUNET_STATISTICS_Handle *stats_handle;
+
+  /**
+   * Handle for getting statistics.
+   */
+  struct GNUNET_STATISTICS_GetHandle *stats_get_handle;
+};
+
 /**
  * Handle to a group of GNUnet peers.
  */
@@ -772,12 +777,16 @@ make_config (const struct GNUNET_CONFIGURATION_Handle *cfg,
   if (hostname != NULL)
     {
       GNUNET_asprintf(&allowed_hosts, "%s; 127.0.0.1;", hostname);
+      GNUNET_CONFIGURATION_set_value_string(uc.ret, "transport-udp", "BINDTO", hostname);
       GNUNET_CONFIGURATION_set_value_string(uc.ret, "transport-tcp", "BINDTO", hostname);
       GNUNET_CONFIGURATION_set_value_string(uc.ret, "arm", "ACCEPT_FROM", allowed_hosts);
       GNUNET_free(allowed_hosts);
     }
   else
-    GNUNET_CONFIGURATION_set_value_string(uc.ret, "transport-tcp", "BINDTO", "127.0.0.1");
+    {
+      GNUNET_CONFIGURATION_set_value_string(uc.ret, "transport-tcp", "BINDTO", "127.0.0.1");
+      GNUNET_CONFIGURATION_set_value_string(uc.ret, "transport-udp", "BINDTO", "127.0.0.1");
+    }
 
   *port = (uint16_t) uc.nport;
   *upnum = uc.upnum;
@@ -2930,7 +2939,7 @@ static int internal_stats_callback (void *cls,
                                     uint64_t value,
                                     int is_persistent)
 {
-  struct CoreContext *core_context = cls;
+  struct StatsCoreContext *core_context = cls;
   struct StatsIterateContext *stats_context = (struct StatsIterateContext *)core_context->iter_context;
 
   return stats_context->proc(stats_context->cls, &core_context->daemon->id, subsystem, name, value, is_persistent);
@@ -2945,7 +2954,7 @@ static int internal_stats_callback (void *cls,
  */
 static void internal_stats_cont (void *cls, int success)
 {
-  struct CoreContext *core_context = cls;
+  struct StatsCoreContext *core_context = cls;
   struct StatsIterateContext *stats_context = (struct StatsIterateContext *)core_context->iter_context;
 
   stats_context->connected--;
@@ -2954,10 +2963,12 @@ static void internal_stats_cont (void *cls, int success)
   if (stats_context->completed == stats_context->total)
     {
       stats_context->cont(stats_context->cls, GNUNET_YES);
-      if (stats_context->stats_handle != NULL)
-        GNUNET_STATISTICS_destroy(stats_context->stats_handle, GNUNET_NO);
       GNUNET_free(stats_context);
     }
+
+  if (core_context->stats_handle != NULL)
+    GNUNET_STATISTICS_destroy(core_context->stats_handle, GNUNET_NO);
+
   GNUNET_free(core_context);
 }
 
@@ -2968,7 +2979,7 @@ static void internal_stats_cont (void *cls, int success)
 static void
 schedule_get_statistics(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  struct CoreContext *core_context = cls;
+  struct StatsCoreContext *core_context = cls;
   struct StatsIterateContext *stats_context = (struct StatsIterateContext *)core_context->iter_context;
 
   if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
@@ -2990,16 +3001,16 @@ schedule_get_statistics(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc
 #endif
 
       stats_context->connected++;
-      stats_context->stats_handle = GNUNET_STATISTICS_create(core_context->daemon->sched, "testing", core_context->daemon->cfg);
-      if (stats_context->stats_handle == NULL)
+      core_context->stats_handle = GNUNET_STATISTICS_create(core_context->daemon->sched, "testing", core_context->daemon->cfg);
+      if (core_context->stats_handle == NULL)
         {
           internal_stats_cont (core_context, GNUNET_NO);
           return;
         }
 
-      stats_context->stats_get_handle = GNUNET_STATISTICS_get(stats_context->stats_handle, NULL, NULL, GNUNET_TIME_relative_get_forever(), &internal_stats_cont, &internal_stats_callback, core_context);
-      if (stats_context->stats_get_handle == NULL)
-         internal_stats_cont (core_context, GNUNET_NO);
+      core_context->stats_get_handle = GNUNET_STATISTICS_get(core_context->stats_handle, NULL, NULL, GNUNET_TIME_relative_get_forever(), &internal_stats_cont, &internal_stats_callback, core_context);
+      if (core_context->stats_get_handle == NULL)
+        internal_stats_cont (core_context, GNUNET_NO);
 
     }
 }