new plugin API
authorChristian Grothoff <christian@grothoff.org>
Sun, 3 Apr 2011 15:10:41 +0000 (15:10 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sun, 3 Apr 2011 15:10:41 +0000 (15:10 +0000)
src/datastore/gnunet-service-datastore.c
src/datastore/perf_plugin_datastore.c
src/datastore/plugin_datastore_mysql.c
src/datastore/plugin_datastore_postgres.c
src/datastore/plugin_datastore_sqlite.c
src/datastore/plugin_datastore_template.c
src/include/gnunet_datastore_plugin.h

index 82a1f3ded8df814e3ed1d70a0c4b1d649a053b40..2538d5ef6150db74bf0a544b43cda93d0cc2c736 100644 (file)
@@ -953,6 +953,7 @@ execute_put (struct GNUNET_SERVER_Client *client,
                          ntohl(dm->type),
                          ntohl(dm->priority),
                          ntohl(dm->anonymity),
+                         0 /* FIXME: replication */,
                          GNUNET_TIME_absolute_ntoh(dm->expiration),
                          &msg);
   if (GNUNET_OK == ret)
index facf7be670dcb69718c4498c224ffcba874e6b60..cb25da46b366726ccf0e8980cd2d13af99b2470f 100644 (file)
@@ -125,9 +125,10 @@ putValue (struct GNUNET_DATASTORE_PluginFunctions * api, int i, int k)
                             &key, 
                             size,
                             value,
-                            i,
+                            i /* type */,
                             prio,
-                            i,
+                            i /* anonymity */,
+                            0 /* replication */,
                             GNUNET_TIME_relative_to_absolute 
                             (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
                                                             60 * 60 * 60 * 1000 +
index ac81c9011054d0af01bc5d73deca76c879fceedb..fb1b1397800a22961e9c5258f923741126600e7a 100644 (file)
@@ -1348,6 +1348,7 @@ mysql_plugin_get_size (void *cls)
  * @param type type of the content
  * @param priority priority of the content
  * @param anonymity anonymity-level for the content
+ * @param replication replication-level for the content
  * @param expiration expiration time for the content
  * @param msg set to error message
  * @return GNUNET_OK on success
@@ -1360,6 +1361,7 @@ mysql_plugin_put (void *cls,
                  enum GNUNET_BLOCK_Type type,
                  uint32_t priority,
                  uint32_t anonymity,
+                 uint32_t replication,
                  struct GNUNET_TIME_Absolute expiration,
                  char **msg)
 {
@@ -1687,6 +1689,26 @@ mysql_plugin_get (void *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.
+ *
+ * @param cls closure
+ * @param iter function to call the value (once only).
+ * @param iter_cls closure for iter
+ */
+static void
+mysql_plugin_replication_get (void *cls,
+                             PluginIterator iter, void *iter_cls)
+{
+  /* FIXME: not implemented! */
+  iter (iter_cls, NULL, NULL, 0, NULL, 0, 0, 0, 
+       GNUNET_TIME_UNIT_ZERO_ABS, 0);
+}
+
+
 /**
  * Update the priority for a particular key in the datastore.  If
  * the expiration time in value is different than the time found in
@@ -1940,6 +1962,7 @@ libgnunet_plugin_datastore_mysql_init (void *cls)
   api->put = &mysql_plugin_put;
   api->next_request = &mysql_plugin_next_request;
   api->get = &mysql_plugin_get;
+  api->replication_get = &mysql_plugin_replication_get;
   api->update = &mysql_plugin_update;
   api->iter_low_priority = &mysql_plugin_iter_low_priority;
   api->iter_zero_anonymity = &mysql_plugin_iter_zero_anonymity;
index 18ad7788576e055c30bec6ed0fdff9d787649e2c..c004cd59f7df8411f1dac1fed7875155d522a87a 100644 (file)
@@ -587,6 +587,7 @@ postgres_plugin_get_size (void *cls)
  * @param type type of the content
  * @param priority priority of the content
  * @param anonymity anonymity-level for the content
+ * @param replication replication-level for the content
  * @param expiration expiration time for the content
  * @param msg set to error message
  * @return GNUNET_OK on success
@@ -599,6 +600,7 @@ postgres_plugin_put (void *cls,
                     enum GNUNET_BLOCK_Type type,
                     uint32_t priority,
                     uint32_t anonymity,
+                    uint32_t replication,
                     struct GNUNET_TIME_Absolute expiration,
                     char **msg)
 {
@@ -1197,6 +1199,26 @@ postgres_plugin_get (void *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.
+ *
+ * @param cls closure
+ * @param iter function to call the value (once only).
+ * @param iter_cls closure for iter
+ */
+static void
+postgres_plugin_replication_get (void *cls,
+                                PluginIterator iter, void *iter_cls)
+{
+  /* FIXME: not implemented! */
+  iter (iter_cls, NULL, NULL, 0, NULL, 0, 0, 0, 
+       GNUNET_TIME_UNIT_ZERO_ABS, 0);
+}
+
+
 /**
  * Select a subset of the items in the datastore and call
  * the given iterator for each of them.
@@ -1333,6 +1355,7 @@ libgnunet_plugin_datastore_postgres_init (void *cls)
   api->put = &postgres_plugin_put;
   api->next_request = &postgres_plugin_next_request;
   api->get = &postgres_plugin_get;
+  api->replication_get = &postgres_plugin_replication_get;
   api->update = &postgres_plugin_update;
   api->iter_low_priority = &postgres_plugin_iter_low_priority;
   api->iter_zero_anonymity = &postgres_plugin_iter_zero_anonymity;
index 0eba474f618e29fabb874c317950a20a87882897..260bd54cc189313c9cd7f02031d64ada1dc85630 100644 (file)
@@ -689,6 +689,7 @@ sqlite_next_request (void *next_cls,
  * @param type type of the content
  * @param priority priority of the content
  * @param anonymity anonymity-level for the content
+ * @param replication replication-level for the content
  * @param expiration expiration time for the content
  * @param msg set to an error message
  * @return GNUNET_OK on success
@@ -701,6 +702,7 @@ sqlite_plugin_put (void *cls,
                   enum GNUNET_BLOCK_Type type,
                   uint32_t priority,
                   uint32_t anonymity,
+                  uint32_t replication,
                   struct GNUNET_TIME_Absolute expiration,
                   char ** msg)
 {
@@ -1531,6 +1533,26 @@ sqlite_plugin_get (void *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.
+ *
+ * @param cls closure
+ * @param iter function to call the value (once only).
+ * @param iter_cls closure for iter
+ */
+static void
+sqlite_plugin_replication_get (void *cls,
+                              PluginIterator iter, void *iter_cls)
+{
+  /* FIXME: not implemented! */
+  iter (iter_cls, NULL, NULL, 0, NULL, 0, 0, 0, 
+       GNUNET_TIME_UNIT_ZERO_ABS, 0);
+}
+
+
 /**
  * Drop database.
  *
@@ -1623,6 +1645,7 @@ libgnunet_plugin_datastore_sqlite_init (void *cls)
   api->put = &sqlite_plugin_put;
   api->next_request = &sqlite_next_request;
   api->get = &sqlite_plugin_get;
+  api->replication_get = &sqlite_plugin_replication_get;
   api->update = &sqlite_plugin_update;
   api->iter_low_priority = &sqlite_plugin_iter_low_priority;
   api->iter_zero_anonymity = &sqlite_plugin_iter_zero_anonymity;
index 09dfe85d91d450fc17a0eb222a8b55262511d38e..fc67f600e9948537b6656f0f693d0371e4eb88de 100644 (file)
@@ -64,6 +64,7 @@ static unsigned long long template_plugin_get_size (void *cls)
  * @param type type of the content
  * @param priority priority of the content
  * @param anonymity anonymity-level for the content
+ * @param replication replication-level for the content
  * @param expiration expiration time for the content
  * @param msg set to error message
  * @return GNUNET_OK on success
@@ -76,6 +77,7 @@ template_plugin_put (void *cls,
                     enum GNUNET_BLOCK_Type type,
                     uint32_t priority,
                     uint32_t anonymity,
+                    uint32_t replication,
                     struct GNUNET_TIME_Absolute expiration,
                     char **msg)
 {
@@ -133,6 +135,25 @@ template_plugin_get (void *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.
+ *
+ * @param cls closure
+ * @param iter function to call the value (once only).
+ * @param iter_cls closure for iter
+ */
+static void
+template_plugin_replication_get (void *cls,
+                                PluginIterator iter, void *iter_cls)
+{
+  GNUNET_break (0);
+}
+
+
 /**
  * Update the priority for a particular key in the datastore.  If
  * the expiration time in value is different than the time found in
@@ -308,6 +329,7 @@ libgnunet_plugin_datastore_template_init (void *cls)
   api->put = &template_plugin_put;
   api->next_request = &template_plugin_next_request;
   api->get = &template_plugin_get;
+  api->replication_get = &template_plugin_replication_get;
   api->update = &template_plugin_update;
   api->iter_low_priority = &template_plugin_iter_low_priority;
   api->iter_zero_anonymity = &template_plugin_iter_zero_anonymity;
index 8666dac1007d4cb6714feccf7bddcc0af8132cfc..c981ceb1d2dc15619982230d841940a9fa640a87 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet
-     (C) 2009 Christian Grothoff (and other contributing authors)
+     (C) 2009, 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
@@ -136,8 +136,8 @@ typedef unsigned long long (*PluginGetSize) (void *cls);
 
 /**
  * Store an item in the datastore.  If the item is already present,
- * the priorities are summed up and the higher expiration time and
- * lower anonymity level is used.
+ * the priorities and replication levels are summed up and the higher
+ * expiration time and lower anonymity level is used.
  *
  * @param cls closure
  * @param key key for the item
@@ -146,6 +146,7 @@ typedef unsigned long long (*PluginGetSize) (void *cls);
  * @param type type of the content
  * @param priority priority of the content
  * @param anonymity anonymity-level for the content
+ * @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
@@ -159,6 +160,7 @@ typedef int (*PluginPut) (void *cls,
                          enum GNUNET_BLOCK_Type type,
                          uint32_t priority,
                          uint32_t anonymity,
+                         uint32_t replication,
                          struct GNUNET_TIME_Absolute expiration,
                           char **msg);
 
@@ -191,6 +193,22 @@ typedef void (*PluginGet) (void *cls,
                           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.
+ *
+ * @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);
+
+
 /**
  * Update the priority for a particular key in the datastore.  If
  * the expiration time in value is different than the time found in
@@ -287,6 +305,12 @@ struct GNUNET_DATASTORE_PluginFunctions
    */
   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