More API function tests...
[oweals/gnunet.git] / src / dht / gnunet-service-wdht_clients.c
index 7e92c140abdd4020520cb1aa2f5581f58324aed8..7ad0d2904959674746267fae7db5c0ac2de5f92e 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2009, 2010, 2011, 2016 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
@@ -31,7 +31,7 @@
 #include "gnunet_statistics_service.h"
 #include "gnunet-service-wdht.h"
 #include "gnunet-service-wdht_clients.h"
-#include "gnunet-service-wdht_datacache.h"
+#include "gnunet-service-dht_datacache.h"
 #include "gnunet-service-wdht_neighbours.h"
 #include "dht.h"
 
@@ -64,7 +64,7 @@ struct PendingMessage
   /**
    * Actual message to be sent, allocated at the end of the struct:
    * // msg = (cast) &pm[1];
-   * // memcpy (&pm[1], data, len);
+   * // GNUNET_memcpy (&pm[1], data, len);
    */
   const struct GNUNET_MessageHeader *msg;
 
@@ -316,15 +316,20 @@ send_reply_to_client (void *cls, size_t size, void *buf)
   {
     GNUNET_CONTAINER_DLL_remove (client->pending_head, client->pending_tail,
                                  reply);
-    memcpy (&cbuf[off], reply->msg, msize);
+    GNUNET_memcpy (&cbuf[off], reply->msg, msize);
     GNUNET_free (reply);
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting %u bytes to client %p\n",
-                msize, client->client_handle);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Transmitting %u bytes to client %p\n",
+                (unsigned int) msize,
+                client->client_handle);
     off += msize;
   }
   process_pending_messages (client);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitted %u/%u bytes to client %p\n",
-              (unsigned int) off, (unsigned int) size, client->client_handle);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Transmitted %u/%u bytes to client %p\n",
+              (unsigned int) off,
+              (unsigned int) size,
+              client->client_handle);
   return off;
 }
 
@@ -575,7 +580,7 @@ forward_reply (void *cls,
     /* two clients waiting for same reply, must copy for queueing */
     pm = GNUNET_malloc (sizeof (struct PendingMessage) +
                         ntohs (frc->pm->msg->size));
-    memcpy (pm, frc->pm,
+    GNUNET_memcpy (pm, frc->pm,
             sizeof (struct PendingMessage) + ntohs (frc->pm->msg->size));
     pm->next = pm->prev = NULL;
     pm->msg = (struct GNUNET_MessageHeader *) &pm[1];
@@ -648,7 +653,8 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration,
                 _("Could not pass reply to client, message too big!\n"));
     return;
   }
-  DEBUG("reply FOR DATA_SIZE = %lu\n",msize);
+  DEBUG ("reply FOR DATA_SIZE = %u\n",
+        (unsigned int) msize);
   pm = GNUNET_malloc (msize + sizeof (struct PendingMessage));
   reply = (struct GNUNET_DHT_ClientResultMessage *) &pm[1];
   pm->msg = &reply->header;
@@ -661,17 +667,23 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration,
   reply->expiration = GNUNET_TIME_absolute_hton (expiration);
   reply->key = *key;
   paths = (struct GNUNET_PeerIdentity *) &reply[1];
-  memcpy (paths, put_path,
-          sizeof (struct GNUNET_PeerIdentity) * put_path_length);
-  memcpy (&paths[put_path_length], get_path,
-          sizeof (struct GNUNET_PeerIdentity) * get_path_length);
-  memcpy (&paths[get_path_length + put_path_length], data, data_size);
+  GNUNET_memcpy (paths,
+                put_path,
+                sizeof (struct GNUNET_PeerIdentity) * put_path_length);
+  GNUNET_memcpy (&paths[put_path_length],
+                get_path,
+                sizeof (struct GNUNET_PeerIdentity) * get_path_length);
+  GNUNET_memcpy (&paths[get_path_length + put_path_length],
+                data,
+                data_size);
   frc.do_copy = GNUNET_NO;
   frc.pm = pm;
   frc.data = data;
   frc.data_size = data_size;
   frc.type = type;
-  GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, key, &forward_reply,
+  GNUNET_CONTAINER_multihashmap_get_multiple (forward_map,
+                                             key,
+                                             &forward_reply,
                                               &frc);
   if (GNUNET_NO == frc.do_copy)
   {
@@ -745,10 +757,10 @@ GDS_CLIENTS_process_get (uint32_t options,
       mmsg->hop_count = htonl(hop_count);
       mmsg->desired_replication_level = htonl(desired_replication_level);
       mmsg->get_path_length = htonl(path_length);
-      memcpy (&mmsg->key, key, sizeof (struct GNUNET_HashCode));
+      GNUNET_memcpy (&mmsg->key, key, sizeof (struct GNUNET_HashCode));
       msg_path = (struct GNUNET_PeerIdentity *) &mmsg[1];
       if (path_length > 0)
-        memcpy (msg_path, path,
+        GNUNET_memcpy (msg_path, path,
                 path_length * sizeof (struct GNUNET_PeerIdentity));
       add_pending_message (m->client, pm);
     }
@@ -827,13 +839,13 @@ GDS_CLIENTS_process_put (uint32_t options,
       msg_path = (struct GNUNET_PeerIdentity *) &mmsg[1];
       if (path_length > 0)
       {
-        memcpy (msg_path, path,
+        GNUNET_memcpy (msg_path, path,
                 path_length * sizeof (struct GNUNET_PeerIdentity));
       }
       mmsg->expiration_time = GNUNET_TIME_absolute_hton(exp);
-      memcpy (&mmsg->key, key, sizeof (struct GNUNET_HashCode));
+      GNUNET_memcpy (&mmsg->key, key, sizeof (struct GNUNET_HashCode));
       if (size > 0)
-        memcpy (&msg_path[path_length], data, size);
+        GNUNET_memcpy (&msg_path[path_length], data, size);
       add_pending_message (m->client, pm);
     }
   }
@@ -874,18 +886,14 @@ transmit_request (struct ClientQueryRecord *cqr)
  * itself (unless the heap is empty).
  *
  * @param cls unused
- * @param tc scheduler context
  */
 static void
-transmit_next_request_task (void *cls,
-                            const struct GNUNET_SCHEDULER_TaskContext *tc)
+transmit_next_request_task (void *cls)
 {
   struct ClientQueryRecord *cqr;
   struct GNUNET_TIME_Relative delay;
 
   retry_task = NULL;
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
   while (NULL != (cqr = GNUNET_CONTAINER_heap_remove_root (retry_heap)))
   {
     cqr->hnode = NULL;
@@ -1014,7 +1022,7 @@ handle_dht_local_get (void *cls,
   cqr->key = get->key;
   cqr->client = find_active_client (client);
   cqr->xquery = (void *) &cqr[1];
-  memcpy (&cqr[1], xquery, xquery_size);
+  GNUNET_memcpy (&cqr[1], xquery, xquery_size);
   cqr->hnode = GNUNET_CONTAINER_heap_insert (retry_heap, cqr, 0);
   cqr->retry_frequency = GNUNET_TIME_UNIT_SECONDS;
   cqr->retry_time = GNUNET_TIME_absolute_get ();
@@ -1140,7 +1148,7 @@ handle_dht_local_get_result_seen (void *cls,
   GNUNET_array_grow (cqr->seen_replies,
                     cqr->seen_replies_count,
                     cqr->seen_replies_count + hash_count);
-  memcpy (&cqr->seen_replies[old_count],
+  GNUNET_memcpy (&cqr->seen_replies[old_count],
          hc,
          sizeof (struct GNUNET_HashCode) * hash_count);
 }
@@ -1213,7 +1221,8 @@ handle_dht_local_get_stop (void *cls,
                             GNUNET_NO);
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Received GET STOP request for %s from local client %p\n",
-       client, GNUNET_h2s (&dht_stop_msg->key));
+       GNUNET_h2s (&dht_stop_msg->key),
+       client);
   ctx.client = find_active_client (client);
   ctx.unique_id = dht_stop_msg->unique_id;
   GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, &dht_stop_msg->key,
@@ -1251,7 +1260,7 @@ handle_dht_local_monitor (void *cls,
   else
   {
     r->key = GNUNET_new (struct GNUNET_HashCode);
-    memcpy (r->key, &msg->key, sizeof (struct GNUNET_HashCode));
+    GNUNET_memcpy (r->key, &msg->key, sizeof (struct GNUNET_HashCode));
   }
   GNUNET_CONTAINER_DLL_insert (monitor_head, monitor_tail, r);
   GNUNET_SERVER_receive_done (client, GNUNET_OK);