reservations
[oweals/gnunet.git] / src / datastore / datastore_api.c
index 4fc719629d37955aae85e5c4cacbfd34727daeb2..f9a28800c94ea832cdc3006050d8fc2aac414294 100644 (file)
@@ -215,7 +215,7 @@ with_status_response_handler (void *cls,
        }
     }  
   h->response_proc = NULL;
-#if VERBOSE
+#if DEBUG_DATASTORE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Received status %d/%s\n",
              status,
@@ -255,12 +255,13 @@ transmit_get_status (void *cls,
            gettext_noop ("Error transmitting message to datastore service.\n"));
       return 0;
     }
-  GNUNET_assert (h->message_size <= size);
-  memcpy (buf, &h[1], h->message_size);
-#if VERBOSE
+  msize = h->message_size;
+  GNUNET_assert (msize <= size);
+  memcpy (buf, &h[1], msize);
+#if DEBUG_DATASTORE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Transmitted %u byte message to datastore service, now waiting for status.\n",
-             h->message_size);
+             msize);
 #endif
   h->message_size = 0;
   GNUNET_CLIENT_receive (h->client,
@@ -293,9 +294,10 @@ transmit_for_status (struct GNUNET_DATASTORE_Handle *h,
   const struct GNUNET_MessageHeader *hdr;
   uint16_t msize;
 
+  GNUNET_assert (cont != NULL);
   hdr = (const struct GNUNET_MessageHeader*) &h[1];
   msize = ntohs(hdr->size);
-#if VERBOSE
+#if DEBUG_DATASTORE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Transmitting %u byte message of type %u to datastore service\n",
              msize,
@@ -356,6 +358,11 @@ GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
   struct DataMessage *dm;
   size_t msize;
 
+#if DEBUG_DATASTORE
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Asked to put %u bytes of data\n",
+             size);
+#endif
   msize = sizeof(struct DataMessage) + size;
   GNUNET_assert (msize <= GNUNET_SERVER_MAX_MESSAGE_SIZE);
   dm = (struct DataMessage*) &h[1];
@@ -390,7 +397,7 @@ GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
 void
 GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h,
                          uint64_t amount,
-                         uint64_t entries,
+                         uint32_t entries,
                          GNUNET_DATASTORE_ContinuationWithStatus cont,
                          void *cont_cls,
                          struct GNUNET_TIME_Relative timeout)
@@ -400,9 +407,8 @@ GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h,
   rm = (struct ReserveMessage*) &h[1];
   rm->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE);
   rm->header.size = htons(sizeof (struct ReserveMessage));
-  rm->reserved = htonl(0);
-  rm->amount = htonl(amount);
   rm->entries = htonl(entries);
+  rm->amount = htonl(amount);
   transmit_for_status (h, cont, cont_cls, timeout);
 }
 
@@ -502,7 +508,7 @@ with_result_response_handler (void *cls,
     {
       GNUNET_break (ntohs(msg->size) == sizeof(struct GNUNET_MessageHeader));
       h->response_proc = NULL;
-#if VERBOSE
+#if DEBUG_DATASTORE
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                  "Received end of result set\n");
 #endif
@@ -533,7 +539,7 @@ with_result_response_handler (void *cls,
            NULL, 0, NULL, 0, 0, 0, zero, 0);
       return;
     }
-#if VERBOSE
+#if DEBUG_DATASTORE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Received result %llu with type %u and size %u with key %s\n",
              (unsigned long long) GNUNET_ntohll(dm->uid),
@@ -576,21 +582,22 @@ transmit_get_result (void *cls,
   GNUNET_DATASTORE_ContinuationWithStatus cont = h->response_proc;
   uint16_t msize;
 
-  h->response_proc = NULL;
   if (buf == NULL)
     {
+      h->response_proc = NULL;
       h->message_size = 0;
       cont (h->response_proc_cls, 
            GNUNET_SYSERR,
            gettext_noop ("Error transmitting message to datastore service.\n"));
       return 0;
     }
-  GNUNET_assert (h->message_size <= size);
-  memcpy (buf, &h[1], h->message_size);
-#if VERBOSE
+  msize = h->message_size;
+  GNUNET_assert (msize <= size);
+  memcpy (buf, &h[1], msize);
+#if DEBUG_DATASTORE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Transmitted %u byte message to datastore service, now waiting for result.\n",
-             h->message_size);
+             msize);
 #endif
   h->message_size = 0;
   GNUNET_CLIENT_receive (h->client,
@@ -624,9 +631,10 @@ transmit_for_result (struct GNUNET_DATASTORE_Handle *h,
   const struct GNUNET_MessageHeader *hdr;
   uint16_t msize;
 
+  GNUNET_assert (cont != NULL);
   hdr = (const struct GNUNET_MessageHeader*) &h[1];
   msize = ntohs(hdr->size);
-#if VERBOSE
+#if DEBUG_DATASTORE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Transmitting %u byte message of type %u to datastore service\n",
              msize,