Merge branch 'master' of ssh://gnunet.org/gnunet
[oweals/gnunet.git] / src / dht / dht_api.c
index de1043ca95655844b7b93a3432da4d18c7c99eb7..ee208b50e73770341630419fd71f1e95142e33f0 100644 (file)
@@ -291,7 +291,7 @@ send_get (struct GNUNET_DHT_GetHandle *gh)
   get_msg->type = htonl (gh->type);
   get_msg->key = gh->key;
   get_msg->unique_id = gh->unique_id;
-  memcpy (&get_msg[1],
+  GNUNET_memcpy (&get_msg[1],
           &gh[1],
           gh->xquery_size);
   GNUNET_MQ_send (h->mq,
@@ -332,7 +332,7 @@ send_get_known_results (struct GNUNET_DHT_GetHandle *gh,
                                GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN);
     msg->key = gh->key;
     msg->unique_id = gh->unique_id;
-    memcpy (&msg[1],
+    GNUNET_memcpy (&msg[1],
            &gh->seen_results[transmission_offset],
            sizeof (struct GNUNET_HashCode) * delta);
     GNUNET_MQ_send (h->mq,
@@ -503,7 +503,7 @@ check_monitor_get (void *cls,
   uint16_t msize = ntohs (msg->header.size) - sizeof (*msg);
 
   if ( (plen > UINT16_MAX) ||
-       (plen * sizeof (struct GNUNET_HashCode) != msize) )
+       (plen * sizeof (struct GNUNET_PeerIdentity) != msize) )
   {
     GNUNET_break (0);
     return GNUNET_SYSERR;
@@ -754,12 +754,25 @@ process_client_result (void *cls,
   meta_length =
       sizeof (struct GNUNET_PeerIdentity) * (get_path_length + put_path_length);
   data_length = msize - meta_length;
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Giving %u byte reply for %s to application\n",
-       (unsigned int) data_length,
-       GNUNET_h2s (key));
   put_path = (const struct GNUNET_PeerIdentity *) &crm[1];
   get_path = &put_path[put_path_length];
+  {
+    char *pp;
+    char *gp;
+
+    gp = GNUNET_STRINGS_pp2s (get_path,
+                              get_path_length);
+    pp = GNUNET_STRINGS_pp2s (put_path,
+                              put_path_length);
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+         "Giving %u byte reply for %s to application (GP: %s, PP: %s)\n",
+         (unsigned int) data_length,
+         GNUNET_h2s (key),
+         gp,
+         pp);
+    GNUNET_free (gp);
+    GNUNET_free (pp);
+  }
   data = &get_path[get_path_length];
   /* remember that we've seen this result */
   GNUNET_CRYPTO_hash (data,
@@ -842,32 +855,32 @@ handle_put_confirmation (void *cls,
 static int
 try_connect (struct GNUNET_DHT_Handle *h)
 {
-  GNUNET_MQ_hd_var_size (monitor_get,
-                         GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET,
-                         struct GNUNET_DHT_MonitorGetMessage);
-  GNUNET_MQ_hd_var_size (monitor_get_resp,
-                         GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET_RESP,
-                         struct GNUNET_DHT_MonitorGetRespMessage);
-  GNUNET_MQ_hd_var_size (monitor_put,
-                         GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT,
-                         struct GNUNET_DHT_MonitorPutMessage);
-  GNUNET_MQ_hd_var_size (client_result,
-                         GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT,
-                         struct GNUNET_DHT_ClientResultMessage);
-  GNUNET_MQ_hd_fixed_size (put_confirmation,
-                           GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT_OK,
-                           struct GNUNET_DHT_ClientPutConfirmationMessage);
   struct GNUNET_MQ_MessageHandler handlers[] = {
-    make_monitor_get_handler (h),
-    make_monitor_get_resp_handler (h),
-    make_monitor_put_handler (h),
-    make_client_result_handler (h),
-    make_put_confirmation_handler (h),
+    GNUNET_MQ_hd_var_size (monitor_get,
+                           GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET,
+                           struct GNUNET_DHT_MonitorGetMessage,
+                           h),
+    GNUNET_MQ_hd_var_size (monitor_get_resp,
+                           GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET_RESP,
+                           struct GNUNET_DHT_MonitorGetRespMessage,
+                           h),
+    GNUNET_MQ_hd_var_size (monitor_put,
+                           GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT,
+                           struct GNUNET_DHT_MonitorPutMessage,
+                           h),
+    GNUNET_MQ_hd_var_size (client_result,
+                           GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT,
+                           struct GNUNET_DHT_ClientResultMessage,
+                           h),
+    GNUNET_MQ_hd_fixed_size (put_confirmation,
+                             GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT_OK,
+                             struct GNUNET_DHT_ClientPutConfirmationMessage,
+                             h),
     GNUNET_MQ_handler_end ()
   };
   if (NULL != h->mq)
     return GNUNET_OK;
-  h->mq = GNUNET_CLIENT_connecT (h->cfg,
+  h->mq = GNUNET_CLIENT_connect (h->cfg,
                                  "dht",
                                  handlers,
                                  &mq_error_handler,
@@ -993,6 +1006,10 @@ GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle,
   }
   if (NULL == handle->mq)
     return NULL;
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Sending PUT for %s to DHT via %p\n",
+       GNUNET_h2s (key),
+       handle);
   ph = GNUNET_new (struct GNUNET_DHT_PutHandle);
   ph->dht_handle = handle;
   ph->cont = cont;
@@ -1010,7 +1027,7 @@ GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle,
   put_msg->unique_id = ph->unique_id;
   put_msg->expiration = GNUNET_TIME_absolute_hton (exp);
   put_msg->key = *key;
-  memcpy (&put_msg[1],
+  GNUNET_memcpy (&put_msg[1],
           data,
           size);
   GNUNET_MQ_send (handle->mq,
@@ -1094,7 +1111,7 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle,
   gh->desired_replication_level = desired_replication_level;
   gh->type = type;
   gh->options = options;
-  memcpy (&gh[1],
+  GNUNET_memcpy (&gh[1],
           xquery,
           xquery_size);
   GNUNET_CONTAINER_multihashmap_put (handle->active_requests,
@@ -1131,7 +1148,7 @@ GNUNET_DHT_get_filter_known_results (struct GNUNET_DHT_GetHandle *get_handle,
     GNUNET_array_grow (get_handle->seen_results,
                       get_handle->seen_results_size,
                       needed);
-  memcpy (&get_handle->seen_results[get_handle->seen_results_end],
+  GNUNET_memcpy (&get_handle->seen_results[get_handle->seen_results_end],
          results,
          num_results * sizeof (struct GNUNET_HashCode));
   get_handle->seen_results_end += num_results;