de-experimentalizing
[oweals/gnunet.git] / src / datastore / datastore_api.c
index 344a7084205d78bf63d149c34f018ec636848673..ef373695063ed11e94ed89c7b2239b9486571fae 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet
-     (C) 2004, 2005, 2006, 2007, 2009, 2010 Christian Grothoff (and other contributing authors)
+     (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011 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
@@ -166,7 +166,13 @@ struct GNUNET_DATASTORE_QueueEntry
    * Note that the overall struct should end at a 
    * multiple of 64 bits.
    */
-  int32_t was_transmitted;
+  int was_transmitted;
+  
+  /**
+   * Are we expecting a single message in response to this
+   * request (and, if it is data, no 'END' message)?
+   */
+  int one_shot; 
   
 };
 
@@ -305,8 +311,9 @@ transmit_drop (void *cls,
  * @param h handle to the datastore
  * @param drop set to GNUNET_YES to delete all data in datastore (!)
  */
-void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
-                                 int drop)
+void
+GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
+                            int drop)
 {
   struct GNUNET_DATASTORE_QueueEntry *qe;
 
@@ -668,7 +675,7 @@ process_queue (struct GNUNET_DATASTORE_Handle *h)
  * @param emsg error message
  */
 static void
-drop_status_cont (void *cls, int result, const char *emsg)
+drop_status_cont (void *cls, int32_t result, const char *emsg)
 {
   /* do nothing */
 }
@@ -806,7 +813,7 @@ process_status_message (void *cls,
  */
 struct GNUNET_DATASTORE_QueueEntry *
 GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
-                     int rid,
+                     uint32_t rid,
                       const GNUNET_HashCode * key,
                       size_t size,
                       const void *data,
@@ -959,7 +966,7 @@ GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h,
  */
 struct GNUNET_DATASTORE_QueueEntry *
 GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
-                                 int rid,
+                                 uint32_t rid,
                                  unsigned int queue_priority,
                                  unsigned int max_queue_size,
                                  struct GNUNET_TIME_Relative timeout,
@@ -1022,7 +1029,7 @@ GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
  */
 struct GNUNET_DATASTORE_QueueEntry *
 GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
-                        unsigned long long uid,
+                        uint64_t uid,
                         uint32_t priority,
                         struct GNUNET_TIME_Absolute expiration,
                         unsigned int queue_priority,
@@ -1250,7 +1257,10 @@ process_result_message (void *cls,
          do_disconnect (h);      
          return;
        }
-      GNUNET_DATASTORE_get_next (h);
+      if (GNUNET_YES == qe->one_shot)
+       free_queue_entry (qe);
+      else
+       GNUNET_DATASTORE_iterate_get_next (h);
       return;
     }
   dm = (const struct DataMessage*) msg;
@@ -1262,6 +1272,8 @@ process_result_message (void *cls,
              ntohl(dm->size),
              GNUNET_h2s(&dm->key));
 #endif
+  if (GNUNET_YES == qe->one_shot)
+    free_queue_entry (qe);
   h->retry_time.rel_value = 0;
   rc.iter (rc.iter_cls,
           &dm->key,
@@ -1309,7 +1321,7 @@ GNUNET_DATASTORE_get_for_replication (struct GNUNET_DATASTORE_Handle *h,
 
 #if DEBUG_DATASTORE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Asked to get random entry in %llu ms\n",
+             "Asked to get replication entry in %llu ms\n",
              (unsigned long long) timeout.rel_value);
 #endif
   qc.rc.iter = iter;
@@ -1321,16 +1333,17 @@ GNUNET_DATASTORE_get_for_replication (struct GNUNET_DATASTORE_Handle *h,
     {
 #if DEBUG_DATASTORE
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                 "Could not create queue entry for GET RANDOM\n");
+                 "Could not create queue entry for GET REPLICATION\n");
 #endif
       return NULL;    
     }
+  qe->one_shot = GNUNET_YES;
   GNUNET_STATISTICS_update (h->stats,
-                           gettext_noop ("# GET RANDOM requests executed"),
+                           gettext_noop ("# GET REPLICATION requests executed"),
                            1,
                            GNUNET_NO);
   m = (struct GNUNET_MessageHeader*) &qe[1];
-  m->type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_GET_RANDOM);
+  m->type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION);
   m->size = htons(sizeof (struct GNUNET_MessageHeader));
   process_queue (h);
   return qe;
@@ -1355,18 +1368,19 @@ GNUNET_DATASTORE_get_for_replication (struct GNUNET_DATASTORE_Handle *h,
  *         (or rather, will already have been invoked)
  */
 struct GNUNET_DATASTORE_QueueEntry *
-GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
-                                    unsigned int queue_priority,
-                                    unsigned int max_queue_size,
-                                    struct GNUNET_TIME_Relative timeout,
-                                    enum GNUNET_BLOCK_Type type,
-                                    GNUNET_DATASTORE_Iterator iter, 
-                                    void *iter_cls)
+GNUNET_DATASTORE_iterate_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
+                                        unsigned int queue_priority,
+                                        unsigned int max_queue_size,
+                                        struct GNUNET_TIME_Relative timeout,
+                                        enum GNUNET_BLOCK_Type type,
+                                        GNUNET_DATASTORE_Iterator iter, 
+                                        void *iter_cls)
 {
   struct GNUNET_DATASTORE_QueueEntry *qe;
   struct GetZeroAnonymityMessage *m;
   union QueueContext qc;
 
+  GNUNET_assert (type != GNUNET_BLOCK_TYPE_ANY);
 #if DEBUG_DATASTORE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Asked to get zero-anonymity entry in %llu ms\n",
@@ -1404,7 +1418,7 @@ GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
  * in the datastore.  The iterator will only be called
  * once initially; if the first call did contain a
  * result, further results can be obtained by calling
- * "GNUNET_DATASTORE_get_next" with the given argument.
+ * "GNUNET_DATASTORE_iterate_get_next" with the given argument.
  *
  * @param h handle to the datastore
  * @param key maybe NULL (to match all entries)
@@ -1421,14 +1435,14 @@ GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
  *         (or rather, will already have been invoked)
  */
 struct GNUNET_DATASTORE_QueueEntry *
-GNUNET_DATASTORE_get (struct GNUNET_DATASTORE_Handle *h,
-                      const GNUNET_HashCode * key,
-                     enum GNUNET_BLOCK_Type type,
-                     unsigned int queue_priority,
-                     unsigned int max_queue_size,
-                     struct GNUNET_TIME_Relative timeout,
-                      GNUNET_DATASTORE_Iterator iter, 
-                     void *iter_cls)
+GNUNET_DATASTORE_iterate_key (struct GNUNET_DATASTORE_Handle *h,
+                             const GNUNET_HashCode * key,
+                             enum GNUNET_BLOCK_Type type,
+                             unsigned int queue_priority,
+                             unsigned int max_queue_size,
+                             struct GNUNET_TIME_Relative timeout,
+                             GNUNET_DATASTORE_Iterator iter, 
+                             void *iter_cls)
 {
   struct GNUNET_DATASTORE_QueueEntry *qe;
   struct GetMessage *gm;
@@ -1482,7 +1496,7 @@ GNUNET_DATASTORE_get (struct GNUNET_DATASTORE_Handle *h,
  * @param h handle to the datastore
  */
 void 
-GNUNET_DATASTORE_get_next (struct GNUNET_DATASTORE_Handle *h)
+GNUNET_DATASTORE_iterate_get_next (struct GNUNET_DATASTORE_Handle *h)
 {
   struct GNUNET_DATASTORE_QueueEntry *qe = h->queue_head;