-simplify logic
[oweals/gnunet.git] / src / transport / transport_api_monitor_plugins.c
index d14323ec602893db5f778d1e73408f5b04461edd..f313bdfe9393bb6d0354c71ec1cb370461d857b6 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2014 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2014 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -72,7 +72,7 @@ struct GNUNET_TRANSPORT_PluginMonitor
   /**
    * Task ID for reconnect.
    */
-  GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
+  struct GNUNET_SCHEDULER_Task * reconnect_task;
 
 };
 
@@ -141,7 +141,7 @@ do_plugin_connect (void *cls,
 {
   struct GNUNET_TRANSPORT_PluginMonitor *pm = cls;
 
-  pm->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
+  pm->reconnect_task = NULL;
   pm->client = GNUNET_CLIENT_connect ("transport", pm->cfg);
   GNUNET_assert (NULL != pm->client);
   send_plugin_mon_request (pm);
@@ -178,21 +178,6 @@ free_entry (void *cls,
 }
 
 
-/**
- * We got disconnected, remove all existing entries from
- * the map and notify client.
- *
- * @param pm montitor that got disconnected
- */
-static void
-clear_map (struct GNUNET_TRANSPORT_PluginMonitor *pm)
-{
-  GNUNET_CONTAINER_multihashmap32_iterate (pm->sessions,
-                                           &free_entry,
-                                           pm);
-}
-
-
 /**
  * Cut the existing connection and reconnect.
  *
@@ -203,7 +188,9 @@ reconnect_plugin_ctx (struct GNUNET_TRANSPORT_PluginMonitor *pm)
 {
   GNUNET_CLIENT_disconnect (pm->client);
   pm->client = NULL;
-  clear_map (pm);
+  GNUNET_CONTAINER_multihashmap32_iterate (pm->sessions,
+                                           &free_entry,
+                                           pm);
   pm->backoff = GNUNET_TIME_STD_BACKOFF (pm->backoff);
   pm->reconnect_task = GNUNET_SCHEDULER_add_delayed (pm->backoff,
                                                      &do_plugin_connect,
@@ -291,7 +278,6 @@ response_processor (void *cls,
   struct GNUNET_HELLO_Address addr;
   struct SearchContext rv;
 
-  fprintf (stderr, "R\n");
   if (NULL == msg)
   {
     reconnect_plugin_ctx (pm);
@@ -443,12 +429,14 @@ GNUNET_TRANSPORT_monitor_plugins_cancel (struct GNUNET_TRANSPORT_PluginMonitor *
     GNUNET_CLIENT_disconnect (pm->client);
     pm->client = NULL;
   }
-  if (GNUNET_SCHEDULER_NO_TASK != pm->reconnect_task)
+  if (NULL != pm->reconnect_task)
   {
     GNUNET_SCHEDULER_cancel (pm->reconnect_task);
-    pm->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
+    pm->reconnect_task = NULL;
   }
-  clear_map (pm);
+  GNUNET_CONTAINER_multihashmap32_iterate (pm->sessions,
+                                           &free_entry,
+                                           pm);
   GNUNET_CONTAINER_multihashmap32_destroy (pm->sessions);
   GNUNET_free (pm);
 }