wip
[oweals/gnunet.git] / src / include / gnunet_datastore_plugin.h
index c981ceb1d2dc15619982230d841940a9fa640a87..a5c548146674c8af4cdab154721188bcfba2ce40 100644 (file)
@@ -149,8 +149,7 @@ typedef unsigned long long (*PluginGetSize) (void *cls);
  * @param replication replication-level for the content
  * @param expiration expiration time for the content
  * @param msg set to an error message (on failure)
- * @return GNUNET_OK on success, GNUNET_NO if the content
- *         was already present (and may have been updated);
+ * @return GNUNET_OK on success,
  *         GNUNET_SYSERR on failure
  */
 typedef int (*PluginPut) (void *cls,
@@ -162,7 +161,7 @@ typedef int (*PluginPut) (void *cls,
                          uint32_t anonymity,
                          uint32_t replication,
                          struct GNUNET_TIME_Absolute expiration,
-                          char **msg);
+                         char **msg);
 
 
 /**
@@ -170,7 +169,7 @@ typedef int (*PluginPut) (void *cls,
  * in the datastore.
  *
  * @param cls closure
- * @param key maybe NULL (to match all entries)
+ * @param key key to match, never NULL
  * @param vhash hash of the value, maybe NULL (to
  *        match all values that have the right key).
  *        Note that for DBlocks there is no difference
@@ -187,26 +186,25 @@ typedef int (*PluginPut) (void *cls,
  * @param iter_cls closure for iter
  */
 typedef void (*PluginGet) (void *cls,
-                          const GNUNET_HashCode * key,
-                          const GNUNET_HashCode * vhash,
+                          const GNUNET_HashCode *key,
+                          const GNUNET_HashCode *vhash,
                           enum GNUNET_BLOCK_Type type,
                           PluginIterator iter, void *iter_cls);
 
 
 
 /**
- * Get a random item for replication.  Returns a single, 
- * not expired, random item
- * from those with the highest replication counters.  The item's 
- * replication counter is decremented by one IF it was positive before.
- * Call 'iter' with all values ZERO or NULL if the datastore is empty.
+ * Get a random item (additional constraints may apply depending on
+ * the specific implementation).  Calls 'iter' with all values ZERO or
+ * NULL if no item applies, otherwise 'iter' is called once and only
+ * once with an item, with the 'next_cls' argument being NULL.
  *
  * @param cls closure
  * @param iter function to call the value (once only).
  * @param iter_cls closure for iter
  */
-typedef void (*PluginReplicationGet) (void *cls,
-                                     PluginIterator iter, void *iter_cls);
+typedef void (*PluginRandomGet) (void *cls,
+                                PluginIterator iter, void *iter_cls);
 
 
 /**
@@ -234,17 +232,20 @@ typedef void (*PluginReplicationGet) (void *cls,
  */
 typedef int (*PluginUpdate) (void *cls,
                             uint64_t uid,
-                            int delta, struct GNUNET_TIME_Absolute expire,
+                            int delta, 
+                            struct GNUNET_TIME_Absolute expire,
                             char **msg);
 
 
 /**
- * Select a subset of the items in the datastore and call
- * the given iterator for each of them.
+ * Select a subset of the items in the datastore and call the given
+ * iterator for the first item; then allow getting more items by
+ * calling the 'next_request' callback with the given 'next_cls'
+ * argument passed to 'iter'.
  *
  * @param cls closure
  * @param type entries of which type should be considered?
- *        Use 0 for any type.
+ *        Myst not be zero (ANY).
  * @param iter function to call on each matching value; however,
  *        after the first call to "iter", the plugin must wait
  *        until "NextRequest" was called before giving the iterator
@@ -258,6 +259,7 @@ typedef void (*PluginSelector) (void *cls,
                                 PluginIterator iter,
                                 void *iter_cls);
 
+
 /**
  * Drop database.
  *
@@ -291,26 +293,6 @@ struct GNUNET_DATASTORE_PluginFunctions
    */
   PluginPut put;
 
-  /**
-   * Function called by iterators whenever they want the next value;
-   * note that unlike all of the other callbacks, this one does get a
-   * the "next_cls" closure which is usually different from the "cls"
-   * member of this struct!
-   */
-  PluginNextRequest next_request;
-
-  /**
-   * Function to iterate over the results for a particular key
-   * in the datastore.
-   */
-  PluginGet get;
-
-  /**
-   * Function to get a random item with high replication score from
-   * the database, lowering the item's replication score.
-   */
-  PluginReplicationGet replication_get;
-
   /**
    * Update the priority for a particular key in the datastore.  If
    * the expiration time in value is different than the time found in
@@ -322,37 +304,38 @@ struct GNUNET_DATASTORE_PluginFunctions
   PluginUpdate update;
 
   /**
-   * Iterate over the items in the datastore in ascending
-   * order of priority.
+   * Function called by iterators whenever they want the next value;
+   * note that unlike all of the other callbacks, this one does get a
+   * the "next_cls" closure which is usually different from the "cls"
+   * member of this struct!
    */
-  PluginSelector iter_low_priority;
+  PluginNextRequest next_request;
 
   /**
-   * Iterate over content with anonymity zero.
+   * Function to iterate over the results for a particular key
+   * in the datastore.
    */
-  PluginSelector iter_zero_anonymity;
+  PluginGet get;
 
   /**
-   * Iterate over the items in the datastore in ascending order of
-   * expiration time. 
+   * Iterate over content with anonymity level zero.
    */
-  PluginSelector iter_ascending_expiration;
+  PluginSelector iter_zero_anonymity;
 
   /**
-   * Iterate over the items in the datastore in migration
-   * order.  Call the given function on the next item only
-   * (and then signal 'end' with a second call).  This is
-   * a significant difference from all the other iterators!
+   * Function to get a random item with high replication score from
+   * the database, lowering the item's replication score.  Returns a
+   * single random item from those with the highest replication
+   * counters.  The item's replication counter is decremented by one
+   * IF it was positive before.
    */
-  PluginSelector iter_migration_order;
+  PluginRandomGet replication_get;
 
   /**
-   * Iterate over all the items in the datastore
-   * as fast as possible in a single transaction
-   * (can lock datastore while this happens, focus
-   * is on doing it fast).
+   * Function to get a random expired item or, if none are expired, one
+   * with a low priority.
    */
-  PluginSelector iter_all_now;
+  PluginRandomGet expiration_get;
 
   /**
    * Delete the database.  The next operation is