- fix coverity
[oweals/gnunet.git] / src / cadet / gnunet-service-cadet_local.c
index 20cf1592b42a2a1945c2255688474076f7cb6ff4..0a7c3d14db3eff6c430d644a3a67dfe912d8cb96 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2013 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2013 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
@@ -201,7 +201,7 @@ channel_destroy_iterator (void *cls,
 static void
 client_destroy (struct CadetClient *c)
 {
-  LOG (GNUNET_ERROR_TYPE_INFO, "  client destroy: %p/%u\n", c, c->id);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "  client destroy: %p/%u\n", c, c->id);
   GNUNET_SERVER_client_drop (c->handle);
   c->shutting_down = GNUNET_YES;
 
@@ -255,7 +255,7 @@ client_new (struct GNUNET_SERVER_Client *client)
   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);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "  client created: %p/%u\n", c, c->id);
 
   return c;
 }
@@ -274,7 +274,7 @@ client_new (struct GNUNET_SERVER_Client *client)
 static void
 handle_client_connect (void *cls, struct GNUNET_SERVER_Client *client)
 {
-  LOG (GNUNET_ERROR_TYPE_INFO, "Client connected: %p\n", client);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Client connected: %p\n", client);
   if (NULL == client)
     return;
 
@@ -294,7 +294,7 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
 {
   struct CadetClient *c;
 
-  LOG (GNUNET_ERROR_TYPE_INFO, "Client disconnected: %p\n", client);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected: %p\n", client);
 
   c = GML_client_get (client);
   if (NULL != c)
@@ -328,8 +328,7 @@ handle_new_client (void *cls, struct GNUNET_SERVER_Client *client,
   uint32_t *p;
   unsigned int i;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "\n");
-  LOG (GNUNET_ERROR_TYPE_INFO, "new client registering %p\n", client);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "new client registering %p\n", client);
 
   /* Check data sanity */
   size = ntohs (message->size);
@@ -358,7 +357,7 @@ handle_new_client (void *cls, struct GNUNET_SERVER_Client *client,
     return;
   }
 
-  LOG (GNUNET_ERROR_TYPE_INFO, "  client %u has %u ports\n", c-> id, size);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "  client %u has %u ports\n", c-> id, size);
   if (size > 0)
   {
     uint32_t u32;
@@ -368,7 +367,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_INFO, "    port: %u\n", u32);
+      LOG (GNUNET_ERROR_TYPE_DEBUG, "    port: %u\n", u32);
 
       /* store in client's hashmap */
       GNUNET_CONTAINER_multihashmap32_put (c->ports, u32, c,
@@ -471,11 +470,14 @@ handle_channel_destroy (void *cls, struct GNUNET_SERVER_Client *client,
 
   /* Retrieve tunnel */
   chid = ntohl (msg->channel_id);
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "  for channel %X\n", chid);
   ch = GML_channel_get (c, chid);
+
+  LOG (GNUNET_ERROR_TYPE_INFO, "Client %u is destroying channel %X\n",
+       c->id, chid);
+
   if (NULL == ch)
   {
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "  channel %X not found\n", chid);
+    LOG (GNUNET_ERROR_TYPE_WARNING, "  channel %X not found\n", chid);
     GNUNET_STATISTICS_update (stats,
                               "# client destroy messages on unknown channel",
                               1, GNUNET_NO);
@@ -850,7 +852,7 @@ handle_show_peer (void *cls, struct GNUNET_SERVER_Client *client,
   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");
+  LOG (GNUNET_ERROR_TYPE_INFO, "Show peer from client %u completed.\n", c->id);
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
@@ -941,7 +943,7 @@ static void
 iter_channel (void *cls, struct CadetChannel *ch)
 {
   struct GNUNET_CADET_LocalInfoTunnel *msg = cls;
-  struct GNUNET_HashCode *h = (struct GNUNET_HashCode *) &msg[1];
+  struct GNUNET_CADET_Hash *h = (struct GNUNET_CADET_Hash *) &msg[1];
   CADET_ChannelNumber *chn = (CADET_ChannelNumber *) &h[msg->connections];
 
   chn[msg->channels] = htonl (GCCH_get_id (ch));
@@ -1015,12 +1017,13 @@ handle_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client,
   resp = GNUNET_malloc (size);
   resp->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL);
   resp->header.size = htons (size);
+  resp->destination = msg->peer;
+  /* Do not interleave with iterators, iter_channel needs conn in HBO */
   GCT_iterate_connections (t, &iter_connection, resp);
   GCT_iterate_channels (t, &iter_channel, resp);
-  /* Do not interleave with iterators, iter_channel needs conn in HBO */
-  resp->destination = msg->peer;
   resp->connections = htonl (resp->connections);
   resp->channels = htonl (resp->channels);
+  /* Do not interleave end */
   resp->cstate = htons (GCT_get_cstate (t));
   resp->estate = htons (GCT_get_estate (t));
   GNUNET_SERVER_notification_context_unicast (nc, c->handle,
@@ -1157,6 +1160,8 @@ GML_shutdown (void)
 {
   struct CadetClient *c;
 
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down local\n");
+
   for (c = clients_head; NULL != clients_head; c = clients_head)
     client_destroy (c);
 
@@ -1292,6 +1297,8 @@ GML_get_next_chid (struct CadetClient *c)
 struct CadetClient *
 GML_client_get (struct GNUNET_SERVER_Client *client)
 {
+  if (NULL == client)
+    return NULL;
   return GNUNET_SERVER_client_get_user_context (client, struct CadetClient);
 }