- unregister from client on destroy
[oweals/gnunet.git] / src / cadet / gnunet-service-cadet_local.c
index b1c9a8babe837a540a0ca69463a16b1a5a71409f..ff8367a3c287179a71e447bac1dbfc63e6db4195 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2013 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2013 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
@@ -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.
 */
 
 
@@ -160,68 +160,128 @@ client_release_ports (void *cls,
   {
     GNUNET_break (0);
     LOG (GNUNET_ERROR_TYPE_WARNING,
-                "Port %u by client %p was not registered.\n",
-                key, value);
+         "Port %u by client %p was not registered.\n",
+         key, value);
   }
   return GNUNET_OK;
 }
 
 
+/**
+ * Iterator for deleting each channel whose client endpoint disconnected.
+ *
+ * @param cls Closure (client that has disconnected).
+ * @param key The local channel id (used to access the hashmap).
+ * @param value The value stored at the key (channel to destroy).
+ *
+ * @return GNUNET_OK, keep iterating.
+ */
+static int
+channel_destroy_iterator (void *cls,
+                          uint32_t key,
+                          void *value)
+{
+  struct CadetChannel *ch = value;
+  struct CadetClient *c = cls;
 
-/******************************************************************************/
-/********************************  HANDLES  ***********************************/
-/******************************************************************************/
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       " Channel %s destroy, due to client %s shutdown.\n",
+       GCCH_2s (ch), GML_2s (c));
+
+  GCCH_handle_local_destroy (ch, c, key < GNUNET_CADET_LOCAL_CHANNEL_ID_SERV);
+  return GNUNET_OK;
+}
 
 
 /**
- * Handler for client connection.
+ * Unregister data and free memory for a client.
  *
- * @param cls Closure (unused).
- * @param client Client handler.
+ * @param c Client to destroy. No longer valid after call.
  */
 static void
-handle_client_connect (void *cls, struct GNUNET_SERVER_Client *client)
+client_destroy (struct CadetClient *c)
+{
+  LOG (GNUNET_ERROR_TYPE_INFO, "  client destroy: %p/%u\n", c, c->id);
+  GNUNET_SERVER_client_drop (c->handle);
+  c->shutting_down = GNUNET_YES;
+
+  if (NULL != c->own_channels)
+  {
+    GNUNET_CONTAINER_multihashmap32_iterate (c->own_channels,
+                                             &channel_destroy_iterator, c);
+    GNUNET_CONTAINER_multihashmap32_destroy (c->own_channels);
+  }
+  if (NULL != c->incoming_channels)
+  {
+    GNUNET_CONTAINER_multihashmap32_iterate (c->incoming_channels,
+                                             &channel_destroy_iterator, c);
+    GNUNET_CONTAINER_multihashmap32_destroy (c->incoming_channels);
+  }
+  if (NULL != c->ports)
+  {
+    GNUNET_CONTAINER_multihashmap32_iterate (c->ports,
+                                             &client_release_ports, c);
+    GNUNET_CONTAINER_multihashmap32_destroy (c->ports);
+  }
+
+  GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, c);
+  GNUNET_STATISTICS_update (stats, "# clients", -1, GNUNET_NO);
+  GNUNET_SERVER_client_set_user_context (c->handle, NULL);
+  GNUNET_free (c);
+}
+
+/**
+ * Create a client record, register data and initialize memory.
+ *
+ * @param client Client's handle.
+ */
+static struct CadetClient *
+client_new (struct GNUNET_SERVER_Client *client)
 {
   struct CadetClient *c;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "client connected: %p\n", client);
-  if (NULL == client)
-    return;
+  GNUNET_SERVER_client_keep (client);
+  GNUNET_SERVER_notification_context_add (nc, client);
+
   c = GNUNET_new (struct CadetClient);
   c->handle = client;
   c->id = next_client_id++; /* overflow not important: just for debug */
   c->next_chid = GNUNET_CADET_LOCAL_CHANNEL_ID_SERV;
-  GNUNET_SERVER_client_keep (client);
+
+  c->own_channels = GNUNET_CONTAINER_multihashmap32_create (32);
+  c->incoming_channels = GNUNET_CONTAINER_multihashmap32_create (32);
+
   GNUNET_SERVER_client_set_user_context (client, c);
   GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, c);
+  GNUNET_STATISTICS_update (stats, "# clients", +1, GNUNET_NO);
+
+  LOG (GNUNET_ERROR_TYPE_INFO, "  client created: %p/%u\n", c, c->id);
+
+  return c;
 }
 
 
+/******************************************************************************/
+/********************************  HANDLES  ***********************************/
+/******************************************************************************/
+
 /**
- * Iterator for deleting each channel whose client endpoint disconnected.
- *
- * @param cls Closure (client that has disconnected).
- * @param key The local channel id (used to access the hashmap).
- * @param value The value stored at the key (channel to destroy).
+ * Handler for client connection.
  *
- * @return GNUNET_OK, keep iterating.
+ * @param cls Closure (unused).
+ * @param client Client handler.
  */
-static int
-channel_destroy_iterator (void *cls,
-                          uint32_t key,
-                          void *value)
+static void
+handle_client_connect (void *cls, struct GNUNET_SERVER_Client *client)
 {
-  struct CadetChannel *ch = value;
-  struct CadetClient *c = cls;
-
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-              " Channel %s destroy, due to client %s shutdown.\n",
-              GCCH_2s (ch), GML_2s (c));
+  LOG (GNUNET_ERROR_TYPE_INFO, "Client connected: %p\n", client);
+  if (NULL == client)
+    return;
 
-  GCCH_handle_local_destroy (ch, c, key < GNUNET_CADET_LOCAL_CHANNEL_ID_SERV);
-  return GNUNET_OK;
+  (void) client_new (client);
 }
 
+
 /**
  * Handler for client disconnection
  *
@@ -234,50 +294,19 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
 {
   struct CadetClient *c;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "client disconnected: %p\n", client);
-  if (client == NULL)
-  {
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "   (SERVER DOWN)\n");
-    return;
-  }
+  LOG (GNUNET_ERROR_TYPE_INFO, "Client disconnected: %p\n", client);
 
   c = GML_client_get (client);
   if (NULL != c)
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG, "matching client found (%u, %p)\n",
                 c->id, c);
-    GNUNET_SERVER_client_drop (c->handle);
-    c->shutting_down = GNUNET_YES;
-    if (NULL != c->own_channels)
-    {
-      GNUNET_CONTAINER_multihashmap32_iterate (c->own_channels,
-                                               &channel_destroy_iterator, c);
-      GNUNET_CONTAINER_multihashmap32_destroy (c->own_channels);
-    }
-
-    if (NULL != c->incoming_channels)
-    {
-      GNUNET_CONTAINER_multihashmap32_iterate (c->incoming_channels,
-                                               &channel_destroy_iterator, c);
-      GNUNET_CONTAINER_multihashmap32_destroy (c->incoming_channels);
-    }
-
-    if (NULL != c->ports)
-    {
-      GNUNET_CONTAINER_multihashmap32_iterate (c->ports,
-                                               &client_release_ports, c);
-      GNUNET_CONTAINER_multihashmap32_destroy (c->ports);
-    }
-    GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, c);
-    GNUNET_STATISTICS_update (stats, "# clients", -1, GNUNET_NO);
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "  client free (%p)\n", c);
-    GNUNET_free (c);
+    client_destroy (c);
   }
   else
   {
-    LOG (GNUNET_ERROR_TYPE_WARNING, " context NULL!\n");
+    LOG (GNUNET_ERROR_TYPE_DEBUG, " disconnecting client's context NULL\n");
   }
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "done!\n");
   return;
 }
 
@@ -300,23 +329,36 @@ handle_new_client (void *cls, struct GNUNET_SERVER_Client *client,
   unsigned int i;
 
   LOG (GNUNET_ERROR_TYPE_DEBUG, "\n");
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "new client connected %p\n", client);
+  LOG (GNUNET_ERROR_TYPE_INFO, "new client registering %p\n", client);
 
   /* Check data sanity */
-  size = ntohs (message->size) - sizeof (struct GNUNET_CADET_ClientConnect);
-  cc_msg = (struct GNUNET_CADET_ClientConnect *) message;
+  size = ntohs (message->size);
+  if (size < sizeof (struct GNUNET_CADET_ClientConnect))
+  {
+    GNUNET_break (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+    return;
+  }
+  size -= sizeof (struct GNUNET_CADET_ClientConnect); /* Array size */
   if (0 != (size % sizeof (uint32_t)))
   {
     GNUNET_break (0);
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
     return;
   }
-  size /= sizeof (uint32_t);
+  size /= sizeof (uint32_t); /* Number of ports */
+  cc_msg = (struct GNUNET_CADET_ClientConnect *) message;
 
-  /* Initialize new client structure */
+  /* Retrieve client structure */
   c = GNUNET_SERVER_client_get_user_context (client, struct CadetClient);
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "  client id %u\n", c->id);
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "  client has %u ports\n", size);
+  if (NULL == c)
+  {
+    GNUNET_break (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+    return;
+  }
+
+  LOG (GNUNET_ERROR_TYPE_INFO, "  client %u has %u ports\n", c-> id, size);
   if (size > 0)
   {
     uint32_t u32;
@@ -326,7 +368,7 @@ handle_new_client (void *cls, struct GNUNET_SERVER_Client *client,
     for (i = 0; i < size; i++)
     {
       u32 = ntohl (p[i]);
-      LOG (GNUNET_ERROR_TYPE_DEBUG, "    port: %u\n", u32);
+      LOG (GNUNET_ERROR_TYPE_INFO, "    port: %u\n", u32);
 
       /* store in client's hashmap */
       GNUNET_CONTAINER_multihashmap32_put (c->ports, u32, c,
@@ -339,13 +381,8 @@ handle_new_client (void *cls, struct GNUNET_SERVER_Client *client,
     }
   }
 
-  c->own_channels = GNUNET_CONTAINER_multihashmap32_create (32);
-  c->incoming_channels = GNUNET_CONTAINER_multihashmap32_create (32);
-  GNUNET_SERVER_notification_context_add (nc, client);
-  GNUNET_STATISTICS_update (stats, "# clients", 1, GNUNET_NO);
-
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "new client processed\n");
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "new regitering processed\n");
 }
 
 
@@ -464,14 +501,19 @@ static void
 handle_data (void *cls, struct GNUNET_SERVER_Client *client,
              const struct GNUNET_MessageHeader *message)
 {
+  const struct GNUNET_MessageHeader *payload;
   struct GNUNET_CADET_LocalData *msg;
   struct CadetClient *c;
   struct CadetChannel *ch;
   CADET_ChannelNumber chid;
-  size_t size;
+  size_t message_size;
+  size_t payload_size;
+  size_t payload_claimed_size;
   int fwd;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "Got data from a client!\n");
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "\n");
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "\n");
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Got data from a client\n");
 
   /* Sanity check for client registration */
   if (NULL == (c = GML_client_get (client)))
@@ -480,22 +522,40 @@ handle_data (void *cls, struct GNUNET_SERVER_Client *client,
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
     return;
   }
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "  by client %u\n", c->id);
-
-  msg = (struct GNUNET_CADET_LocalData *) message;
 
   /* Sanity check for message size */
-  size = ntohs (message->size) - sizeof (struct GNUNET_CADET_LocalData);
-  if (size < sizeof (struct GNUNET_MessageHeader))
+  message_size = ntohs (message->size);
+  if (sizeof (struct GNUNET_CADET_LocalData)
+      + sizeof (struct GNUNET_MessageHeader) > message_size
+      || GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE < message_size)
   {
     GNUNET_break (0);
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
     return;
   }
 
-  /* Channel exists? */
+  /* Sanity check for payload size */
+  payload_size = message_size - sizeof (struct GNUNET_CADET_LocalData);
+  msg = (struct GNUNET_CADET_LocalData *) message;
+  payload = (struct GNUNET_MessageHeader *) &msg[1];
+  payload_claimed_size = ntohs (payload->size);
+  if (sizeof (struct GNUNET_MessageHeader) > payload_claimed_size
+      || GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE < payload_claimed_size
+      || payload_claimed_size > payload_size)
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING,
+         "client claims to send %u bytes in %u payload\n",
+         payload_claimed_size, payload_size);
+    GNUNET_break (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+    return;
+  }
+
   chid = ntohl (msg->id);
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "  on channel %X\n", chid);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "  %u bytes (%u payload) by client %u\n",
+       payload_size, payload_claimed_size, c->id);
+
+  /* Channel exists? */
   fwd = chid < GNUNET_CADET_LOCAL_CHANNEL_ID_SERV;
   ch = GML_channel_get (c, chid);
   if (NULL == ch)
@@ -507,9 +567,7 @@ handle_data (void *cls, struct GNUNET_SERVER_Client *client,
     return;
   }
 
-  if (GNUNET_OK !=
-      GCCH_handle_local_data (ch, c,
-                              (struct GNUNET_MessageHeader *)&msg[1], fwd))
+  if (GNUNET_OK != GCCH_handle_local_data (ch, c, fwd, payload, payload_size))
   {
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
     return;
@@ -642,6 +700,61 @@ show_peer_iterator (void *cls,
 }
 
 
+/**
+ * Iterator over all paths of a peer to build an InfoPeer message.
+ *
+ * Message contains blocks of peers, first not included.
+ *
+ * @param cls Closure (message to build).
+ * @param peer Peer this path is towards.
+ * @param path Path itself
+ * @return #GNUNET_YES if should keep iterating.
+ *         #GNUNET_NO otherwise.
+ */
+static int
+path_info_iterator (void *cls,
+                    struct CadetPeer *peer,
+                    struct CadetPeerPath *path)
+{
+  struct GNUNET_CADET_LocalInfoPeer *resp = cls;
+  struct GNUNET_PeerIdentity *id;
+  uint16_t msg_size;
+  uint16_t path_size;
+  unsigned int i;
+
+  msg_size = ntohs (resp->header.size);
+  path_size = sizeof (struct GNUNET_PeerIdentity) * (path->length - 1);
+
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Info Path %u\n", path->length);
+  if (msg_size + path_size > UINT16_MAX)
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING, "path too long for info message\n");
+    return GNUNET_NO;
+  }
+
+  i = msg_size - sizeof (struct GNUNET_CADET_LocalInfoPeer);
+  i = i / sizeof (struct GNUNET_PeerIdentity);
+
+  /* Set id to the address of the first free peer slot. */
+  id = (struct GNUNET_PeerIdentity *) &resp[1];
+  id = &id[i];
+
+  /* Don't copy first peers.
+   * First peer is always the local one.
+   * Last peer is always the destination (leave as 0, EOL).
+   */
+  for (i = 0; i < path->length - 1; i++)
+  {
+    GNUNET_PEER_resolve (path->peers[i + 1], &id[i]);
+    LOG (GNUNET_ERROR_TYPE_DEBUG, " %s\n", GNUNET_i2s (&id[i]));
+  }
+
+  resp->header.size = htons (msg_size + path_size);
+
+  return GNUNET_YES;
+}
+
+
 /**
  * Handler for client's INFO PEERS request.
  *
@@ -679,6 +792,69 @@ handle_get_peers (void *cls, struct GNUNET_SERVER_Client *client,
 }
 
 
+/**
+ * Handler for client's SHOW_PEER request.
+ *
+ * @param cls Closure (unused).
+ * @param client Identification of the client.
+ * @param message The actual message.
+ */
+void
+handle_show_peer (void *cls, struct GNUNET_SERVER_Client *client,
+                  const struct GNUNET_MessageHeader *message)
+{
+  const struct GNUNET_CADET_LocalInfo *msg;
+  struct GNUNET_CADET_LocalInfoPeer *resp;
+  struct CadetPeer *p;
+  struct CadetClient *c;
+  unsigned char cbuf[64 * 1024];
+
+  /* Sanity check for client registration */
+  if (NULL == (c = GML_client_get (client)))
+  {
+    GNUNET_break (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+    return;
+  }
+
+  msg = (struct GNUNET_CADET_LocalInfo *) message;
+  resp = (struct GNUNET_CADET_LocalInfoPeer *) cbuf;
+  LOG (GNUNET_ERROR_TYPE_INFO,
+       "Received peer info request from client %u for peer %s\n",
+       c->id, GNUNET_i2s_full (&msg->peer));
+
+  resp->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER);
+  resp->header.size = htons (sizeof (struct GNUNET_CADET_LocalInfoPeer));
+  resp->destination = msg->peer;
+  p = GCP_get (&msg->peer, GNUNET_NO);
+  if (NULL == p)
+  {
+    /* We don't know the peer */
+
+    LOG (GNUNET_ERROR_TYPE_INFO, "Peer %s unknown\n",
+         GNUNET_i2s_full (&msg->peer));
+    resp->paths = htons (0);
+    resp->tunnel = htons (NULL != GCP_get_tunnel (p));
+
+    GNUNET_SERVER_notification_context_unicast (nc, client,
+                                                &resp->header,
+                                                GNUNET_NO);
+    GNUNET_SERVER_receive_done (client, GNUNET_OK);
+    return;
+  }
+
+  resp->paths = htons (GCP_count_paths (p));
+  resp->tunnel = htons (NULL != GCP_get_tunnel (p));
+  GCP_iterate_paths (p, &path_info_iterator, resp);
+
+  GNUNET_SERVER_notification_context_unicast (nc, c->handle,
+                                              &resp->header, GNUNET_NO);
+
+  LOG (GNUNET_ERROR_TYPE_INFO, "Show peer request from client %u completed.\n");
+  GNUNET_SERVER_receive_done (client, GNUNET_OK);
+}
+
+
 /**
  * Iterator over all tunnels to send a monitoring client info about each tunnel.
  *
@@ -701,7 +877,7 @@ get_all_tunnels_iterator (void *cls,
   msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS);
   msg.destination = *peer;
   msg.channels = htonl (GCT_count_channels (t));
-  msg.connections = htonl (GCT_count_connections (t));
+  msg.connections = htonl (GCT_count_any_connections (t));
   msg.cstate = htons ((uint16_t) GCT_get_cstate (t));
   msg.estate = htons ((uint16_t) GCT_get_estate (t));
 
@@ -768,7 +944,7 @@ iter_channel (void *cls, struct CadetChannel *ch)
   struct GNUNET_HashCode *h = (struct GNUNET_HashCode *) &msg[1];
   CADET_ChannelNumber *chn = (CADET_ChannelNumber *) &h[msg->connections];
 
-  chn[msg->channels] = GCCH_get_id (ch);
+  chn[msg->channels] = htonl (GCCH_get_id (ch));
   msg->channels++;
 }
 
@@ -801,11 +977,11 @@ handle_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client,
   }
 
   msg = (struct GNUNET_CADET_LocalInfo *) message;
-  LOG (GNUNET_ERROR_TYPE_INFO,
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Received tunnel info request from client %u for tunnel %s\n",
        c->id, GNUNET_i2s_full(&msg->peer));
 
-  t = GCP_get_tunnel (GCP_get (&msg->peer));
+  t = GCP_get_tunnel (GCP_get (&msg->peer, GNUNET_NO));
   if (NULL == t)
   {
     /* We don't know the tunnel */
@@ -830,7 +1006,7 @@ handle_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client,
 
   /* Initialize context */
   ch_n = GCT_count_channels (t);
-  c_n = GCT_count_connections (t);
+  c_n = GCT_count_any_connections (t);
 
   size = sizeof (struct GNUNET_CADET_LocalInfoTunnel);
   size += c_n * sizeof (struct GNUNET_CADET_Hash);
@@ -851,7 +1027,7 @@ handle_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client,
                                               &resp->header, GNUNET_NO);
   GNUNET_free (resp);
 
-  LOG (GNUNET_ERROR_TYPE_INFO,
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Show tunnel request from client %u completed. %u conn, %u ch\n",
        c->id, c_n, ch_n);
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -908,6 +1084,8 @@ static struct GNUNET_SERVER_MessageHandler client_handlers[] = {
    sizeof (struct GNUNET_CADET_LocalAck)},
   {&handle_get_peers, NULL, GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS,
    sizeof (struct GNUNET_MessageHeader)},
+  {&handle_show_peer, NULL, GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER,
+   sizeof (struct GNUNET_CADET_LocalInfo)},
   {&handle_get_tunnels, NULL, GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS,
    sizeof (struct GNUNET_MessageHeader)},
   {&handle_show_tunnel, NULL, GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL,
@@ -963,11 +1141,17 @@ GML_start (void)
 void
 GML_shutdown (void)
 {
+  struct CadetClient *c;
+
+  for (c = clients_head; NULL != clients_head; c = clients_head)
+    client_destroy (c);
+
   if (nc != NULL)
   {
     GNUNET_SERVER_notification_context_destroy (nc);
     nc = NULL;
   }
+
 }
 
 
@@ -1303,6 +1487,6 @@ GML_2s (const struct CadetClient *c)
 {
   static char buf[32];
 
-  sprintf (buf, "%u", c->id);
+  SPRINTF (buf, "%u", c->id);
   return buf;
 }