- fix coverity
[oweals/gnunet.git] / src / cadet / gnunet-cadet.c
index 958c1ad7f7f5e45531f4e50e92291baf36fd07d0..f24975203e7e0227383d38eb0603f8314214919e 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2012 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2012 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
@@ -14,8 +14,8 @@
 
      You should have received a copy of the GNU General Public License
      along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
 */
 
 /**
@@ -72,22 +72,22 @@ static uint32_t listen_port;
 /**
  * Request echo service
  */
-int echo;
+static int echo;
 
 /**
  * Request a debug dump
  */
-int dump;
+static int dump;
 
 /**
  * Time of last echo request.
  */
-struct GNUNET_TIME_Absolute echo_time;
+static struct GNUNET_TIME_Absolute echo_time;
 
 /**
  * Task for next echo request.
  */
-struct GNUNET_SCHEDULER_Task * echo_task;
+static struct GNUNET_SCHEDULER_Task *echo_task;
 
 /**
  * Peer to connect to.
@@ -102,8 +102,7 @@ static uint32_t target_port;
 /**
  * Data pending in netcat mode.
  */
-size_t data_size;
-
+static size_t data_size;
 
 /**
  * Cadet handle.
@@ -115,30 +114,102 @@ static struct GNUNET_CADET_Handle *mh;
  */
 static struct GNUNET_CADET_Channel *ch;
 
+/**
+ * Transmit handle.
+ */
+static struct GNUNET_CADET_TransmitHandle *th;
+
 /**
  * Shutdown task handle.
  */
-struct GNUNET_SCHEDULER_Task * sd;
+static struct GNUNET_SCHEDULER_Task *sd;
+
+/**
+ * Task for reading from stdin.
+ */
+static struct GNUNET_SCHEDULER_Task *rd_task;
 
+/**
+ * Task for main job.
+ */
+static struct GNUNET_SCHEDULER_Task *job;
 
 
 static void
 listen_stdio (void);
 
 
+/**
+ * Convert encryption status to human readable string.
+ *
+ * @param status Encryption status.
+ *
+ * @return Human readable string.
+ */
+static const char *
+enc_2s (uint16_t status)
+{
+  switch (status)
+  {
+    case 0:
+      return "NULL ";
+    case 1:
+      return "KSENT";
+    case 2:
+      return "KRECV";
+    case 3:
+      return "READY";
+    default:
+      return "";
+  }
+}
+
+
+/**
+ * Convert connection status to human readable string.
+ *
+ * @param status Connection status.
+ *
+ * @return Human readable string.
+ */
+static const char *
+conn_2s (uint16_t status)
+{
+  switch (status)
+  {
+    case 0:
+      return "NEW  ";
+    case 1:
+      return "SRCH ";
+    case 2:
+      return "WAIT ";
+    case 3:
+      return "READY";
+    case 4:
+      return "SHUTD";
+    default:
+      return "";
+  }
+}
+
+
 
 /**
  * Task run in monitor mode when the user presses CTRL-C to abort.
  * Stops monitoring activity.
  *
  * @param cls Closure (unused).
- * @param tc scheduler context
  */
 static void
-shutdown_task (void *cls,
-               const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Shutdown\n");
+  if (NULL != th)
+  {
+    GNUNET_CADET_notify_transmit_ready_cancel (th);
+    th = NULL;
+  }
   if (NULL != ch)
   {
     GNUNET_CADET_channel_destroy (ch);
@@ -147,7 +218,22 @@ shutdown_task (void *cls,
   if (NULL != mh)
   {
     GNUNET_CADET_disconnect (mh);
-        mh = NULL;
+    mh = NULL;
+  }
+  if (NULL != rd_task)
+  {
+    GNUNET_SCHEDULER_cancel (rd_task);
+    rd_task = NULL;
+  }
+  if (NULL != echo_task)
+  {
+    GNUNET_SCHEDULER_cancel (echo_task);
+    echo_task = NULL;
+  }
+  if (NULL != job)
+  {
+    GNUNET_SCHEDULER_cancel (job);
+    job = NULL;
   }
 }
 
@@ -165,12 +251,14 @@ shutdown_task (void *cls,
  * @param buf where the callee should write the message
  * @return number of bytes written to buf
  */
-size_t
+static size_t
 data_ready (void *cls, size_t size, void *buf)
 {
   struct GNUNET_MessageHeader *msg;
   size_t total_size;
 
+  th = NULL;
+
   if (NULL == buf || 0 == size)
   {
     GNUNET_SCHEDULER_shutdown();
@@ -178,7 +266,9 @@ data_ready (void *cls, size_t size, void *buf)
   }
 
   total_size = data_size + sizeof (struct GNUNET_MessageHeader);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sending %u bytes\n", data_size);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "sending %u bytes\n",
+              (unsigned int) data_size);
   GNUNET_assert (size >= total_size);
 
   msg = buf;
@@ -199,35 +289,30 @@ data_ready (void *cls, size_t size, void *buf)
 
 
 /**
- * Task run in monitor mode when the user presses CTRL-C to abort.
- * Stops monitoring activity.
+ * Task run in stdio mode, after some data is available at stdin.
  *
  * @param cls Closure (unused).
- * @param tc scheduler context
  */
 static void
-read_stdio (void *cls,
-            const struct GNUNET_SCHEDULER_TaskContext *tc)
+read_stdio (void *cls)
 {
   static char buf[60000];
 
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-  {
-    return;
-  }
-
   data_size = read (0, buf, 60000);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "stdio read %u bytes\n", data_size);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "stdio read %u bytes\n",
+              (unsigned int) data_size);
   if (data_size < 1)
   {
     GNUNET_SCHEDULER_shutdown();
     return;
   }
-  GNUNET_CADET_notify_transmit_ready (ch, GNUNET_NO,
-                                     GNUNET_TIME_UNIT_FOREVER_REL,
-                                     data_size
-                                     + sizeof (struct GNUNET_MessageHeader),
-                                     &data_ready, buf);
+  GNUNET_assert (NULL == th);
+  th = GNUNET_CADET_notify_transmit_ready (ch, GNUNET_NO,
+                                           GNUNET_TIME_UNIT_FOREVER_REL,
+                                           sizeof (struct GNUNET_MessageHeader)
+                                           + data_size,
+                                           &data_ready, buf);
 }
 
 
@@ -241,10 +326,10 @@ listen_stdio (void)
 
   rs = GNUNET_NETWORK_fdset_create ();
   GNUNET_NETWORK_fdset_set_native (rs, 0);
-  GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
-                               GNUNET_TIME_UNIT_FOREVER_REL,
-                               rs, NULL,
-                               &read_stdio, NULL);
+  rd_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+                                        GNUNET_TIME_UNIT_FOREVER_REL,
+                                        rs, NULL,
+                                        &read_stdio, NULL);
   GNUNET_NETWORK_fdset_destroy (rs);
 }
 
@@ -266,8 +351,21 @@ channel_ended (void *cls,
                void *channel_ctx)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel ended!\n");
-  GNUNET_break (channel == ch);
-  ch = NULL;
+  if (channel != ch)
+  {
+    GNUNET_break (0);
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ended: %p, expected: %p\n", channel, ch);
+  }
+  else
+  {
+    ch = NULL;
+  }
+  if (NULL != th)
+  {
+    GNUNET_CADET_notify_transmit_ready_cancel (th);
+    th = NULL;
+  }
+
   GNUNET_SCHEDULER_shutdown ();
 }
 
@@ -301,7 +399,11 @@ channel_incoming (void *cls,
               channel, port);
   if (NULL != ch)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "A channel already exists\n");
+    GNUNET_break (0);
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "A channel already exists (%p)\n", ch);
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Incoming channel %p on port %u\n", channel, port);
     return NULL;
   }
   if (0 == listen_port)
@@ -323,18 +425,17 @@ channel_incoming (void *cls,
  * @brief Send an echo request to the remote peer.
  *
  * @param cls Closure (NULL).
- * @param tc Task context.
  */
 static void
-send_echo (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+send_echo (void *cls)
 {
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) || NULL == ch)
+  if (NULL == ch)
     return;
-
-  GNUNET_CADET_notify_transmit_ready (ch, GNUNET_NO,
-                                     GNUNET_TIME_UNIT_FOREVER_REL,
-                                     sizeof (struct GNUNET_MessageHeader),
-                                     &data_ready, NULL);
+  GNUNET_assert (NULL == th);
+  th = GNUNET_CADET_notify_transmit_ready (ch, GNUNET_NO,
+                                           GNUNET_TIME_UNIT_FOREVER_REL,
+                                           sizeof (struct GNUNET_MessageHeader),
+                                           &data_ready, NULL);
 }
 
 
@@ -342,14 +443,14 @@ send_echo (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * Call CADET's monitor API, request debug dump on the service.
  *
  * @param cls Closure (unused).
- * @param tc TaskContext
  */
 static void
-request_dump (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+request_dump (void *cls)
 {
   GNUNET_CADET_request_dump (mh);
   GNUNET_SCHEDULER_cancel (sd);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &shutdown_task, NULL);
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+                               &shutdown_task, NULL);
 }
 
 
@@ -357,10 +458,9 @@ request_dump (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * Call CADET's monitor API, get info of one connection.
  *
  * @param cls Closure (unused).
- * @param tc TaskContext
  */
 static void
-create_channel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+create_channel (void *cls)
 {
   struct GNUNET_PeerIdentity pid;
   enum GNUNET_CADET_ChannelOption opt;
@@ -384,7 +484,7 @@ create_channel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   if (GNUNET_NO == echo)
     listen_stdio ();
   else
-    GNUNET_SCHEDULER_add_now (send_echo, NULL);
+    echo_task = GNUNET_SCHEDULER_add_now (&send_echo, NULL);
 }
 
 
@@ -413,16 +513,23 @@ data_callback (void *cls,
   uint16_t off;
   const char *buf;
   GNUNET_break (ch == channel);
+  GNUNET_CADET_receive_done (channel);
 
   if (GNUNET_YES == echo)
   {
     if (0 != listen_port)
     {
       /* Just listening to echo incoming messages*/
-      GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO,
-                                        GNUNET_TIME_UNIT_FOREVER_REL,
-                                        sizeof (struct GNUNET_MessageHeader),
-                                        &data_ready, NULL);
+      if (NULL != th)
+      {
+        GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                    "Last echo reply not yet sent, dropping current reply.\n");
+        return GNUNET_OK;
+      }
+      th = GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO,
+                                               GNUNET_TIME_UNIT_FOREVER_REL,
+                                               sizeof (struct GNUNET_MessageHeader),
+                                               &data_ready, NULL);
       return GNUNET_OK;
     }
     else
@@ -472,8 +579,11 @@ data_callback (void *cls,
  *                  (0 = unknown, 1 = ourselves, 2 = neighbor)
  */
 static void
-peers_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
-                int tunnel, unsigned int n_paths, unsigned int best_path)
+peers_callback (void *cls,
+               const struct GNUNET_PeerIdentity *peer,
+                int tunnel,
+               unsigned int n_paths,
+               unsigned int best_path)
 {
   if (NULL == peer)
   {
@@ -500,7 +610,7 @@ peers_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
  *              Each path starts with the local peer.
  *              Each path ends with the destination peer (given in @c peer).
  */
-void
+static void
 peer_callback (void *cls,
                const struct GNUNET_PeerIdentity *peer,
                int tunnel,
@@ -515,15 +625,17 @@ peer_callback (void *cls,
            GNUNET_i2s_full (peer),
            tunnel ? "Y" : "N", neighbor ? "Y" : "N", n_paths);
   p = paths;
-  for (i = 0; i < n_paths && NULL != p; i++)
+  for (i = 0; i < n_paths && NULL != p;)
   {
-    FPRINTF (stdout, "%s ", GNUNET_i2s_full (p));
+    FPRINTF (stdout, "%s ", GNUNET_i2s (p));
     if (0 == memcmp (p, peer, sizeof (*p)))
     {
       FPRINTF (stdout, "\n");
+      i++;
     }
     p++;
   }
+
   GNUNET_SCHEDULER_shutdown();
 }
 
@@ -538,7 +650,7 @@ peer_callback (void *cls,
  * @param estate Encryption state.
  * @param cstate Connectivity state.
  */
-void
+static void
 tunnels_callback (void *cls,
                   const struct GNUNET_PeerIdentity *peer,
                   unsigned int channels,
@@ -554,8 +666,10 @@ tunnels_callback (void *cls,
     }
     return;
   }
-  FPRINTF (stdout, "%s [ENC: %u, CON: %u] CHs: %u, CONNs: %u\n",
-           GNUNET_i2s_full (peer), estate, cstate, channels, connections);
+  FPRINTF (stdout, "%s [ENC: %s, CON: %s] CHs: %u, CONNs: %u\n",
+           GNUNET_i2s_full (peer),
+           enc_2s (estate), conn_2s (cstate),
+           channels, connections);
 }
 
 
@@ -572,7 +686,7 @@ tunnels_callback (void *cls,
  * @param estate Encryption status.
  * @param cstate Connectivity status.
  */
-void
+static void
 tunnel_callback (void *cls,
                  const struct GNUNET_PeerIdentity *peer,
                  unsigned int n_channels,
@@ -587,21 +701,20 @@ tunnel_callback (void *cls,
   if (NULL != peer)
   {
     FPRINTF (stdout, "Tunnel %s\n", GNUNET_i2s_full (peer));
-    FPRINTF (stdout, "%u channels\n", n_channels);
+    FPRINTF (stdout, "\t%u channels\n", n_channels);
     for (i = 0; i < n_channels; i++)
-      FPRINTF (stdout, "   %u\n", channels[i]);
-    FPRINTF (stdout, "%u connections\n", n_connections);
+      FPRINTF (stdout, "\t\t%X\n", ntohl (channels[i]));
+    FPRINTF (stdout, "\t%u connections\n", n_connections);
     for (i = 0; i < n_connections; i++)
-      FPRINTF (stdout, "   %s\n", GC_h2s (&connections[i]));
-    FPRINTF (stdout, "- enc state: %u\n", estate);
-    FPRINTF (stdout, "- con state: %u\n", cstate);
+      FPRINTF (stdout, "\t\t%s\n", GC_h2s (&connections[i]));
+    FPRINTF (stdout, "\tencryption state: %s\n", enc_2s (estate));
+    FPRINTF (stdout, "\tconnection state: %s\n", conn_2s (cstate));
   }
   if (GNUNET_YES != monitor_mode)
   {
-    GNUNET_SCHEDULER_shutdown();
+    GNUNET_SCHEDULER_shutdown ();
   }
   return;
-
 }
 
 
@@ -609,16 +722,11 @@ tunnel_callback (void *cls,
  * Call CADET's meta API, get all peers known to a peer.
  *
  * @param cls Closure (unused).
- * @param tc TaskContext
  */
 static void
-get_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+get_peers (void *cls)
 {
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
-    return;
-  }
+  job = NULL;
   GNUNET_CADET_get_peers (mh, &peers_callback, NULL);
 }
 
@@ -627,18 +735,18 @@ get_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * Call CADET's monitor API, get info of one peer.
  *
  * @param cls Closure (unused).
- * @param tc TaskContext
  */
 static void
-show_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+show_peer (void *cls)
 {
   struct GNUNET_PeerIdentity pid;
 
+  job = NULL;
   if (GNUNET_OK !=
-    GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
-                                                strlen (peer_id),
-                                                &pid.public_key))
-  {
+      GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
+                                                  strlen (peer_id),
+                                                  &pid.public_key))
+    {
     fprintf (stderr,
              _("Invalid peer ID `%s'\n"),
              peer_id);
@@ -648,20 +756,16 @@ show_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   GNUNET_CADET_get_peer (mh, &pid, peer_callback, NULL);
 }
 
+
 /**
  * Call CADET's meta API, get all tunnels known to a peer.
  *
  * @param cls Closure (unused).
- * @param tc TaskContext
  */
 static void
-get_tunnels (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+get_tunnels (void *cls)
 {
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
-    return;
-  }
+  job = NULL;
   GNUNET_CADET_get_tunnels (mh, &tunnels_callback, NULL);
 }
 
@@ -670,10 +774,9 @@ get_tunnels (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * Call CADET's monitor API, get info of one tunnel.
  *
  * @param cls Closure (unused).
- * @param tc TaskContext
  */
 static void
-show_tunnel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+show_tunnel (void *cls)
 {
   struct GNUNET_PeerIdentity pid;
 
@@ -685,7 +788,7 @@ show_tunnel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     fprintf (stderr,
              _("Invalid tunnel owner `%s'\n"),
              tunnel_id);
-    GNUNET_SCHEDULER_shutdown();
+    GNUNET_SCHEDULER_shutdown ();
     return;
   }
   GNUNET_CADET_get_tunnel (mh, &pid, tunnel_callback, NULL);
@@ -696,12 +799,12 @@ show_tunnel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * Call CADET's monitor API, get info of one channel.
  *
  * @param cls Closure (unused).
- * @param tc TaskContext
  */
 static void
-show_channel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+show_channel (void *cls)
 {
-
+  job = NULL;
+  GNUNET_break (0);
 }
 
 
@@ -709,12 +812,12 @@ show_channel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * Call CADET's monitor API, get info of one connection.
  *
  * @param cls Closure (unused).
- * @param tc TaskContext
  */
 static void
-show_connection (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+show_connection (void *cls)
 {
-
+  job = NULL;
+  GNUNET_break (0);
 }
 
 
@@ -727,7 +830,9 @@ show_connection (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * @param cfg configuration
  */
 static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+     char *const *args,
+     const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   GNUNET_CADET_InboundChannelNotificationHandler *newch = NULL;
@@ -749,7 +854,7 @@ run (void *cls, char *const *args, const char *cfgfile,
        && target_id != NULL)
   {
     FPRINTF (stderr,
-             _("You must NOT give a TARGET"
+             _("You must NOT give a TARGET "
                "when using 'request all' options\n"));
     return;
   }
@@ -779,32 +884,32 @@ run (void *cls, char *const *args, const char *cfgfile,
   else if (NULL != peer_id)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show peer\n");
-    GNUNET_SCHEDULER_add_now (&show_peer, NULL);
+    job = GNUNET_SCHEDULER_add_now (&show_peer, NULL);
   }
   else if (NULL != tunnel_id)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show tunnel\n");
-    GNUNET_SCHEDULER_add_now (&show_tunnel, NULL);
+    job = GNUNET_SCHEDULER_add_now (&show_tunnel, NULL);
   }
   else if (NULL != channel_id)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show channel\n");
-    GNUNET_SCHEDULER_add_now (&show_channel, NULL);
+    job = GNUNET_SCHEDULER_add_now (&show_channel, NULL);
   }
   else if (NULL != conn_id)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show connection\n");
-    GNUNET_SCHEDULER_add_now (&show_connection, NULL);
+    job = GNUNET_SCHEDULER_add_now (&show_connection, NULL);
   }
   else if (GNUNET_YES == request_peers)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all peers\n");
-    GNUNET_SCHEDULER_add_now (&get_peers, NULL);
+    job = GNUNET_SCHEDULER_add_now (&get_peers, NULL);
   }
   else if (GNUNET_YES == request_tunnels)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all tunnels\n");
-    GNUNET_SCHEDULER_add_now (&get_tunnels, NULL);
+    job = GNUNET_SCHEDULER_add_now (&get_tunnels, NULL);
   }
   else
   {
@@ -821,11 +926,9 @@ run (void *cls, char *const *args, const char *cfgfile,
                             ports);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Done\n");
   if (NULL == mh)
-    GNUNET_SCHEDULER_add_now (shutdown_task, NULL);
+    GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
   else
-    sd = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                       shutdown_task, NULL);
-
+    sd = GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
 }