allow empty/NULL context message
[oweals/gnunet.git] / src / transport / gnunet-transport.c
index f8d3e26d8e90da23cb8e9b7c21e4b9be810c37f5..cbddee9055345b033abe53978c3ca0ec66f4e416 100644 (file)
@@ -1,6 +1,6 @@
 /*
  This file is part of GNUnet.
- Copyright (C) 2011-2014 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2011-2014 GNUnet e.V.
 
  GNUnet is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published
@@ -426,11 +426,6 @@ struct GNUNET_OS_Process *resolver;
  */
 static unsigned int address_resolutions;
 
-/**
- * Address resolutions pending in progress
- */
-static unsigned int address_resolution_in_progress;
-
 /**
  * DLL for NAT Test Contexts: head
  */
@@ -492,11 +487,9 @@ destroy_it (void *cls,
  * Stops monitoring activity.
  *
  * @param cls NULL
- * @param tc scheduler context
  */
 static void
-shutdown_task (void *cls,
-               const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls)
 {
   struct GNUNET_TIME_Relative duration;
   struct ValidationResolutionContext *cur;
@@ -603,8 +596,7 @@ shutdown_task (void *cls,
  * We are done, shut down.
  */
 static void
-operation_timeout (void *cls,
-                   const struct GNUNET_SCHEDULER_TaskContext *tc)
+operation_timeout (void *cls)
 {
   struct PeerResolutionContext *cur;
   struct PeerResolutionContext *next;
@@ -615,9 +607,7 @@ operation_timeout (void *cls,
     FPRINTF (stdout,
              _("Failed to connect to `%s'\n"),
              GNUNET_i2s_full (&pid));
-    if (NULL != end)
-      GNUNET_SCHEDULER_cancel (end);
-    end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+    GNUNET_SCHEDULER_shutdown ();
     ret = 1;
     return;
   }
@@ -641,9 +631,7 @@ operation_timeout (void *cls,
     FPRINTF (stdout,
              "%s",
              _("Failed to list connections, timeout occured\n"));
-    if (NULL != end)
-      GNUNET_SCHEDULER_cancel (end);
-    end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+    GNUNET_SCHEDULER_shutdown ();
     ret = 1;
     return;
   }
@@ -859,18 +847,13 @@ process_validation_string (void *cls,
   GNUNET_free (vc);
   if ((0 == address_resolutions) && (iterate_validation))
   {
-    if (NULL != end)
-    {
-      GNUNET_SCHEDULER_cancel (end);
-      end = NULL;
-    }
     if (NULL != op_timeout)
     {
       GNUNET_SCHEDULER_cancel (op_timeout);
       op_timeout = NULL;
     }
     ret = 0;
-    end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+    GNUNET_SCHEDULER_shutdown ();
   }
 }
 
@@ -945,9 +928,7 @@ process_validation_cb (void *cls,
       return;
     }
     vic = NULL;
-    if (NULL != end)
-      GNUNET_SCHEDULER_cancel (end);
-    end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+    GNUNET_SCHEDULER_shutdown ();
     return;
   }
   resolve_validation_address (address,
@@ -1372,19 +1353,13 @@ process_peer_string (void *cls,
   GNUNET_free (rc);
   if ((0 == address_resolutions) && (iterate_connections))
   {
-    if (NULL != end)
-    {
-      GNUNET_SCHEDULER_cancel (end);
-      end = NULL;
-    }
     if (NULL != op_timeout)
     {
       GNUNET_SCHEDULER_cancel (op_timeout);
       op_timeout = NULL;
     }
     ret = 0;
-    end = GNUNET_SCHEDULER_add_now (&shutdown_task,
-                                   NULL);
+    GNUNET_SCHEDULER_shutdown ();
   }
 }
 
@@ -1446,11 +1421,7 @@ process_peer_iteration_cb (void *cls,
   if (NULL == peer)
   {
     /* done */
-    address_resolution_in_progress = GNUNET_NO;
     pic = NULL;
-    if (NULL != end)
-      GNUNET_SCHEDULER_cancel (end);
-    end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
     return;
   }
 
@@ -1467,7 +1438,7 @@ process_peer_iteration_cb (void *cls,
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Received address for peer `%s': %s\n",
               GNUNET_i2s (peer),
-              address->transport_name);
+              address ? address->transport_name : "");
 
   if (NULL != address)
     resolve_peer_address (address,
@@ -1904,7 +1875,6 @@ testservice_task (void *cls,
   }
   else if (iterate_connections) /* -i: List information about peers once */
   {
-    address_resolution_in_progress = GNUNET_YES;
     pic = GNUNET_TRANSPORT_monitor_peers (cfg, (NULL == cpid) ? NULL : &pid,
         GNUNET_YES, TIMEOUT, &process_peer_iteration_cb, (void *) cfg);
     op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
@@ -1915,7 +1885,6 @@ testservice_task (void *cls,
   {
     monitored_peers = GNUNET_CONTAINER_multipeermap_create (10,
                                                            GNUNET_NO);
-    address_resolution_in_progress = GNUNET_YES;
     pic = GNUNET_TRANSPORT_monitor_peers (cfg,
                                          (NULL == cpid) ? NULL : &pid,
                                           GNUNET_NO,
@@ -1964,10 +1933,9 @@ testservice_task (void *cls,
     GNUNET_break(0);
     return;
   }
-
-  end = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                      &shutdown_task,
-                                      NULL);
+  
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+                                NULL);
 }