[datastore] Return and update replication
authorDavid Barksdale <amatus@amat.us>
Thu, 23 Mar 2017 03:17:05 +0000 (22:17 -0500)
committerDavid Barksdale <amatus@amat.us>
Thu, 23 Mar 2017 03:19:13 +0000 (22:19 -0500)
This fixes a couple FIXMEs in the datastore code. The replication value
is now returned from the datastore and the update function can increase
the replication.

20 files changed:
src/datastore/datastore.h
src/datastore/datastore_api.c
src/datastore/gnunet-datastore.c
src/datastore/gnunet-service-datastore.c
src/datastore/plugin_datastore_heap.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/datastore/test_datastore_api.c
src/datastore/test_datastore_api_management.c
src/datastore/test_plugin_datastore.c
src/fs/gnunet-service-fs_cadet_server.c
src/fs/gnunet-service-fs_indexing.c
src/fs/gnunet-service-fs_indexing.h
src/fs/gnunet-service-fs_pr.c
src/fs/gnunet-service-fs_push.c
src/fs/gnunet-service-fs_put.c
src/include/gnunet_datastore_plugin.h
src/include/gnunet_datastore_service.h

index 5fd3601612062a11b612782e1518f09080afeec4..98f8b82ef1fd00695e3ba9cb750307a3aa9ee8e4 100644 (file)
@@ -229,7 +229,7 @@ struct DataMessage
   uint32_t anonymity GNUNET_PACKED;
 
   /**
-   * Desired replication level. 0 from service to API.
+   * Desired replication level.
    */
   uint32_t replication GNUNET_PACKED;
 
index 26e1e501dde643e172e7041d4628c7069fa1441d..31f7a997f7a61d8a80ab7ac57945c813e5a75ad6 100644 (file)
@@ -352,7 +352,11 @@ mq_error_handler (void *cls,
         qc.rc.proc (qc.rc.proc_cls,
                     NULL,
                     0,
-                    NULL, 0, 0, 0,
+                    NULL,
+                    0,
+                    0,
+                    0,
+                    0,
                     GNUNET_TIME_UNIT_ZERO_ABS,
                     0);
       break;
@@ -468,7 +472,11 @@ GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
         qe->qc.rc.proc (qe->qc.rc.proc_cls,
                         NULL,
                         0,
-                        NULL, 0, 0, 0,
+                        NULL,
+                        0,
+                        0,
+                        0,
+                        0,
                         GNUNET_TIME_UNIT_ZERO_ABS,
                         0);
       break;
@@ -825,6 +833,7 @@ handle_data (void *cls,
              ntohl (dm->type),
              ntohl (dm->priority),
              ntohl (dm->anonymity),
+             ntohl (dm->replication),
              GNUNET_TIME_absolute_ntoh (dm->expiration),
              GNUNET_ntohll (dm->uid));
 }
@@ -887,6 +896,7 @@ handle_data_end (void *cls,
              0,
              0,
              0,
+             0,
              GNUNET_TIME_UNIT_ZERO_ABS,
              0);
 }
@@ -1022,8 +1032,6 @@ GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
   dm->priority = htonl (priority);
   dm->anonymity = htonl (anonymity);
   dm->replication = htonl (replication);
-  dm->reserved = htonl (0);
-  dm->uid = GNUNET_htonll (0);
   dm->expiration = GNUNET_TIME_absolute_hton (expiration);
   dm->key = *key;
   GNUNET_memcpy (&dm[1],
@@ -1226,13 +1234,7 @@ GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
   env = GNUNET_MQ_msg_extra (dm,
                              size,
                              GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE);
-  dm->rid = htonl (0);
   dm->size = htonl (size);
-  dm->type = htonl (0);
-  dm->priority = htonl (0);
-  dm->anonymity = htonl (0);
-  dm->uid = GNUNET_htonll (0);
-  dm->expiration = GNUNET_TIME_absolute_hton (GNUNET_TIME_UNIT_ZERO_ABS);
   dm->key = *key;
   GNUNET_memcpy (&dm[1],
           data,
index c93bc8dd332d5140ede9e74a1968fe86d9e571eb..7caf5d175bb98e894592ee26fd9d6bc47bb0955e 100644 (file)
@@ -130,20 +130,23 @@ do_finish (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 uid unique identifier for the datum;
  *        maybe 0 if no unique identifier is available
  */
 static void
 do_put (void *cls,
-       const struct GNUNET_HashCode *key,
-       size_t size,
+        const struct GNUNET_HashCode *key,
+        size_t size,
         const void *data,
-       enum GNUNET_BLOCK_Type type,
-       uint32_t priority,
-       uint32_t anonymity,
-       struct GNUNET_TIME_Absolute
-       expiration, uint64_t uid)
+        enum GNUNET_BLOCK_Type type,
+        uint32_t priority,
+        uint32_t anonymity,
+        uint32_t replication,
+        struct GNUNET_TIME_Absolute
+        expiration,
+        uint64_t uid)
 {
   qe = NULL;
   if ( (0 != offset) &&
@@ -154,13 +157,20 @@ do_put (void *cls,
   }
   if (0 == offset)
     first_uid = uid;
-  qe = GNUNET_DATASTORE_put (db_dst, 0,
-                            key, size, data, type,
-                            priority, anonymity,
-                            0 /* FIXME: replication is lost... */,
-                            expiration,
-                            0, 1,
-                            &do_finish, NULL);
+  qe = GNUNET_DATASTORE_put (db_dst,
+                             0,
+                             key,
+                             size,
+                             data,
+                             type,
+                             priority,
+                             anonymity,
+                             replication,
+                             expiration,
+                             0,
+                             1,
+                             &do_finish,
+                             NULL);
 }
 
 
index af33c4412620419dba72effb08c2e24a5bdf1399..277530843230f157d51d2e428584c0492a6ec950 100644 (file)
@@ -286,6 +286,7 @@ delete_expired (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 uid unique identifier for the datum;
  *        maybe 0 if no unique identifier is available
@@ -302,6 +303,7 @@ expired_processor (void *cls,
                    enum GNUNET_BLOCK_Type type,
                    uint32_t priority,
                    uint32_t anonymity,
+                   uint32_t replication,
                    struct GNUNET_TIME_Absolute expiration,
                    uint64_t uid)
 {
@@ -374,6 +376,7 @@ delete_expired (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 uid unique identifier for the datum;
  *        maybe 0 if no unique identifier is available
@@ -389,6 +392,7 @@ quota_processor (void *cls,
                  enum GNUNET_BLOCK_Type type,
                  uint32_t priority,
                  uint32_t anonymity,
+                 uint32_t replication,
                  struct GNUNET_TIME_Absolute expiration,
                  uint64_t uid)
 {
@@ -495,6 +499,7 @@ transmit_status (struct GNUNET_SERVICE_Client *client,
  * @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 uid unique identifier for the datum;
  *        maybe 0 if no unique identifier is available
@@ -509,6 +514,7 @@ transmit_item (void *cls,
                enum GNUNET_BLOCK_Type type,
                uint32_t priority,
                uint32_t anonymity,
+               uint32_t replication,
                struct GNUNET_TIME_Absolute expiration,
                uint64_t uid)
 {
@@ -538,8 +544,7 @@ transmit_item (void *cls,
   dm->type = htonl (type);
   dm->priority = htonl (priority);
   dm->anonymity = htonl (anonymity);
-  dm->replication = htonl (0);
-  dm->reserved = htonl (0);
+  dm->replication = htonl (replication);
   dm->expiration = GNUNET_TIME_absolute_hton (expiration);
   dm->uid = GNUNET_htonll (uid);
   dm->key = *key;
@@ -848,6 +853,7 @@ check_present_continuation (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 uid unique identifier for the datum;
  *        maybe 0 if no unique identifier is available
@@ -856,13 +862,14 @@ check_present_continuation (void *cls,
  */
 static int
 check_present (void *cls,
-              const struct GNUNET_HashCode *key,
-              uint32_t size,
+               const struct GNUNET_HashCode *key,
+               uint32_t size,
                const void *data,
-              enum GNUNET_BLOCK_Type type,
-              uint32_t priority,
+               enum GNUNET_BLOCK_Type type,
+               uint32_t priority,
                uint32_t anonymity,
-              struct GNUNET_TIME_Absolute expiration,
+               uint32_t replication,
+               struct GNUNET_TIME_Absolute expiration,
                uint64_t uid)
 {
   struct PutContext *pc = cls;
@@ -883,16 +890,17 @@ check_present (void *cls,
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Result already present in datastore\n");
-    /* FIXME: change API to allow increasing 'replication' counter */
-    if ((ntohl (dm->priority) > 0) ||
-        (GNUNET_TIME_absolute_ntoh (dm->expiration).abs_value_us >
-         expiration.abs_value_us))
+    if ( (ntohl (dm->priority) > 0) ||
+         (ntohl (dm->replication) > 0) ||
+         (GNUNET_TIME_absolute_ntoh (dm->expiration).abs_value_us >
+          expiration.abs_value_us) )
       plugin->api->update (plugin->api->cls,
-                          uid,
+                           uid,
                            ntohl (dm->priority),
+                           ntohl (dm->replication),
                            GNUNET_TIME_absolute_ntoh (dm->expiration),
                            &check_present_continuation,
-                          pc->client);
+                           pc->client);
     else
     {
       transmit_status (pc->client,
@@ -1064,7 +1072,7 @@ handle_get_key (void *cls,
                               1,
                               GNUNET_NO);
     transmit_item (client,
-                   NULL, 0, NULL, 0, 0, 0,
+                   NULL, 0, NULL, 0, 0, 0, 0,
                    GNUNET_TIME_UNIT_ZERO_ABS,
                    0);
     GNUNET_SERVICE_client_continue (client);
@@ -1153,6 +1161,7 @@ handle_get_zero_anonymity (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 uid unique identifier for the datum
  * @return #GNUNET_OK to keep the item
@@ -1166,6 +1175,7 @@ remove_callback (void *cls,
                  enum GNUNET_BLOCK_Type type,
                  uint32_t priority,
                  uint32_t anonymity,
+                 uint32_t replication,
                  struct GNUNET_TIME_Absolute expiration,
                  uint64_t uid)
 {
index e15cacb5bdfdd05bf2673d6cb6659462d5ee8406..d04c1cf6049e705667579028c638e7d2def28725 100644 (file)
@@ -439,7 +439,7 @@ heap_plugin_get_key (void *cls, uint64_t next_uid, bool random,
   }
   if (NULL == gc.value)
   {
-    proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+    proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
     return;
   }
   if (GNUNET_NO ==
@@ -450,6 +450,7 @@ heap_plugin_get_key (void *cls, uint64_t next_uid, bool random,
             gc.value->type,
             gc.value->priority,
             gc.value->anonymity,
+            gc.value->replication,
             gc.value->expiration,
             (uint64_t) (intptr_t) gc.value))
   {
@@ -480,8 +481,7 @@ heap_plugin_get_replication (void *cls,
   value = GNUNET_CONTAINER_heap_remove_root (plugin->by_replication);
   if (NULL == value)
   {
-    proc (proc_cls,
-         NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+    proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
     return;
   }
   if (value->replication > 0)
@@ -501,14 +501,15 @@ heap_plugin_get_replication (void *cls,
   }
   if (GNUNET_NO ==
       proc (proc_cls,
-           &value->key,
-           value->size,
-           &value[1],
-           value->type,
-           value->priority,
-           value->anonymity,
-           value->expiration,
-           (uint64_t) (intptr_t) value))
+            &value->key,
+            value->size,
+            &value[1],
+            value->type,
+            value->priority,
+            value->anonymity,
+            value->replication,
+            value->expiration,
+            (uint64_t) (intptr_t) value))
     delete_value (plugin, value);
 }
 
@@ -531,35 +532,36 @@ heap_plugin_get_expiration (void *cls, PluginDatumProcessor proc,
   value = GNUNET_CONTAINER_heap_peek (plugin->by_expiration);
   if (NULL == value)
   {
-    proc (proc_cls,
-         NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+    proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
     return;
   }
   if (GNUNET_NO ==
       proc (proc_cls,
-           &value->key,
-           value->size,
-           &value[1],
-           value->type,
-           value->priority,
-           value->anonymity,
-           value->expiration,
-           (uint64_t) (intptr_t) value))
+            &value->key,
+            value->size,
+            &value[1],
+            value->type,
+            value->priority,
+            value->anonymity,
+            value->replication,
+            value->expiration,
+            (uint64_t) (intptr_t) value))
     delete_value (plugin, value);
 }
 
 
 /**
- * Update the priority for a particular key in the datastore.  If
- * the expiration time in value is different than the time found in
- * the datastore, the higher value should be kept.  For the
- * anonymity level, the lower value is to be used.  The specified
- * priority should be added to the existing priority, ignoring the
- * priority in value.
+ * Update the priority, replication and expiration for a particular
+ * unique ID in the datastore.  If the expiration time in value is
+ * different than the time found in the datastore, the higher value
+ * should be kept.  The specified priority and replication is added
+ * to the existing value.
  *
  * @param cls our `struct Plugin *`
  * @param uid unique identifier of the datum
- * @param delta by how much should the priority
+ * @param priority by how much should the priority
+ *     change?
+ * @param replication by how much should the replication
  *     change?
  * @param expire new expiration time should be the
  *     MAX of any existing expiration time and
@@ -569,11 +571,12 @@ heap_plugin_get_expiration (void *cls, PluginDatumProcessor proc,
  */
 static void
 heap_plugin_update (void *cls,
-                   uint64_t uid,
-                   uint32_t delta,
-                   struct GNUNET_TIME_Absolute expire,
-                   PluginUpdateCont cont,
-                   void *cont_cls)
+                    uint64_t uid,
+                    uint32_t priority,
+                    uint32_t replication,
+                    struct GNUNET_TIME_Absolute expire,
+                    PluginUpdateCont cont,
+                    void *cont_cls)
 {
   struct Value *value;
 
@@ -585,11 +588,15 @@ heap_plugin_update (void *cls,
     GNUNET_CONTAINER_heap_update_cost (value->expire_heap,
                                       expire.abs_value_us);
   }
-  /* Saturating add, don't overflow */
-  if (value->priority > UINT32_MAX - delta)
+  /* Saturating adds, don't overflow */
+  if (value->priority > UINT32_MAX - priority)
     value->priority = UINT32_MAX;
   else
-    value->priority += delta;
+    value->priority += priority;
+  if (value->replication > UINT32_MAX - replication)
+    value->replication = UINT32_MAX;
+  else
+    value->replication += replication;
   cont (cont_cls, GNUNET_OK, NULL);
 }
 
@@ -631,20 +638,20 @@ heap_plugin_get_zero_anonymity (void *cls, uint64_t next_uid,
   }
   if (NULL == value)
   {
-    proc (proc_cls,
-          NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+    proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
     return;
   }
   if (GNUNET_NO ==
       proc (proc_cls,
-           &value->key,
-           value->size,
-           &value[1],
-           value->type,
-           value->priority,
-           value->anonymity,
-           value->expiration,
-           (uint64_t) (intptr_t) value))
+            &value->key,
+            value->size,
+            &value[1],
+            value->type,
+            value->priority,
+            value->anonymity,
+            value->replication,
+            value->expiration,
+            (uint64_t) (intptr_t) value))
     delete_value (plugin, value);
 }
 
index 5ae4485cbb9b47fc2635f6841e4a5fb35d89979a..6f2a7649988a1c8560bbd0b3f6c0f9067bb015a6 100644 (file)
@@ -150,22 +150,56 @@ struct Plugin
 #define DELETE_ENTRY_BY_UID "DELETE FROM gn090 WHERE uid=?"
   struct GNUNET_MYSQL_StatementHandle *delete_entry_by_uid;
 
-#define SELECT_ENTRY "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 WHERE uid >= ? AND (rvalue >= ? OR 0 = ?) ORDER BY uid LIMIT 1"
+#define RESULT_COLUMNS "repl, type, prio, anonLevel, expire, hash, value, uid"
+
+#define SELECT_ENTRY "SELECT " RESULT_COLUMNS " FROM gn090 "\
+  "WHERE uid >= ? AND "\
+  "(rvalue >= ? OR 0 = ?) "\
+  "ORDER BY uid LIMIT 1"
   struct GNUNET_MYSQL_StatementHandle *select_entry;
 
-#define SELECT_ENTRY_BY_HASH "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_hash) WHERE hash=? AND uid >= ? AND (rvalue >= ? OR 0 = ?) ORDER BY uid LIMIT 1"
+#define SELECT_ENTRY_BY_HASH "SELECT " RESULT_COLUMNS " FROM gn090 "\
+  "FORCE INDEX (idx_hash) "\
+  "WHERE hash=? AND "\
+  "uid >= ? AND "\
+  "(rvalue >= ? OR 0 = ?) "\
+  "ORDER BY uid LIMIT 1"
   struct GNUNET_MYSQL_StatementHandle *select_entry_by_hash;
 
-#define SELECT_ENTRY_BY_HASH_AND_VHASH "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_hash_vhash) WHERE hash=? AND vhash=? AND uid >= ? AND (rvalue >= ? OR 0 = ?) ORDER BY uid LIMIT 1"
+#define SELECT_ENTRY_BY_HASH_AND_VHASH "SELECT " RESULT_COLUMNS " FROM gn090 "\
+  "FORCE INDEX (idx_hash_vhash) "\
+  "WHERE hash = ? AND "\
+  "vhash = ? AND "\
+  "uid >= ? AND "\
+  "(rvalue >= ? OR 0 = ?) "\
+  "ORDER BY uid LIMIT 1"
   struct GNUNET_MYSQL_StatementHandle *select_entry_by_hash_and_vhash;
 
-#define SELECT_ENTRY_BY_HASH_AND_TYPE "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_hash_type_uid) WHERE hash=? AND type=? AND uid >= ? AND (rvalue >= ? OR 0 = ?) ORDER BY uid LIMIT 1"
+#define SELECT_ENTRY_BY_HASH_AND_TYPE "SELECT " RESULT_COLUMNS " FROM gn090 "\
+  "FORCE INDEX (idx_hash_type_uid) "\
+  "WHERE hash = ? AND "\
+  "type = ? AND "\
+  "uid >= ? AND "\
+  "(rvalue >= ? OR 0 = ?) "\
+  "ORDER BY uid LIMIT 1"
   struct GNUNET_MYSQL_StatementHandle *select_entry_by_hash_and_type;
 
-#define SELECT_ENTRY_BY_HASH_VHASH_AND_TYPE "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_hash_vhash) WHERE hash=? AND vhash=? AND type=? AND uid >= ? AND (rvalue >= ? OR 0 = ?) ORDER BY uid LIMIT 1"
+#define SELECT_ENTRY_BY_HASH_VHASH_AND_TYPE "SELECT " RESULT_COLUMNS " "\
+  "FROM gn090 "\
+  "FORCE INDEX (idx_hash_vhash) "\
+  "WHERE hash = ? AND "\
+  "vhash = ? AND "\
+  "type = ? AND "\
+  "uid >= ? AND "\
+  "(rvalue >= ? OR 0 = ?) "\
+  "ORDER BY uid LIMIT 1"
   struct GNUNET_MYSQL_StatementHandle *select_entry_by_hash_vhash_and_type;
 
-#define UPDATE_ENTRY "UPDATE gn090 SET prio=prio+?,expire=IF(expire>=?,expire,?) WHERE uid=?"
+#define UPDATE_ENTRY "UPDATE gn090 SET "\
+  "prio = prio + ?, "\
+  "repl = repl + ?, "\
+  "expire = IF(expire >= ?, expire, ?) "\
+  "WHERE uid = ?"
   struct GNUNET_MYSQL_StatementHandle *update_entry;
 
 #define DEC_REPL "UPDATE gn090 SET repl=GREATEST (1, repl) - 1 WHERE uid=?"
@@ -174,20 +208,27 @@ struct Plugin
 #define SELECT_SIZE "SELECT SUM(LENGTH(value)+256) FROM gn090"
   struct GNUNET_MYSQL_StatementHandle *get_size;
 
-#define SELECT_IT_NON_ANONYMOUS "SELECT type,prio,anonLevel,expire,hash,value,uid "\
-   "FROM gn090 FORCE INDEX (idx_anonLevel_type_rvalue) "\
-   "WHERE anonLevel=0 AND type=? AND uid >= ? "\
-   "ORDER BY uid LIMIT 1"
+#define SELECT_IT_NON_ANONYMOUS "SELECT " RESULT_COLUMNS " FROM gn090 "\
+  "FORCE INDEX (idx_anonLevel_type_rvalue) "\
+  "WHERE anonLevel=0 AND "\
+  "type=? AND "\
+  "uid >= ? "\
+  "ORDER BY uid LIMIT 1"
   struct GNUNET_MYSQL_StatementHandle *zero_iter;
 
-#define SELECT_IT_EXPIRATION "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_expire) WHERE expire < ? ORDER BY expire ASC LIMIT 1"
+#define SELECT_IT_EXPIRATION "SELECT " RESULT_COLUMNS " FROM gn090 "\
+  "FORCE INDEX (idx_expire) "\
+  "WHERE expire < ? "\
+  "ORDER BY expire ASC LIMIT 1"
   struct GNUNET_MYSQL_StatementHandle *select_expiration;
 
-#define SELECT_IT_PRIORITY "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_prio) ORDER BY prio ASC LIMIT 1"
+#define SELECT_IT_PRIORITY "SELECT " RESULT_COLUMNS " FROM gn090 "\
+  "FORCE INDEX (idx_prio) "\
+  "ORDER BY prio ASC LIMIT 1"
   struct GNUNET_MYSQL_StatementHandle *select_priority;
 
-#define SELECT_IT_REPLICATION "SELECT type,prio,anonLevel,expire,hash,value,uid "\
-  "FROM gn090 FORCE INDEX (idx_repl_rvalue) "\
+#define SELECT_IT_REPLICATION "SELECT " RESULT_COLUMNS " FROM gn090 "\
+  "FORCE INDEX (idx_repl_rvalue) "\
   "WHERE repl=? AND "\
   " (rvalue>=? OR"\
   "  NOT EXISTS (SELECT 1 FROM gn090 FORCE INDEX (idx_repl_rvalue) WHERE repl=? AND rvalue>=?)) "\
@@ -371,19 +412,17 @@ mysql_plugin_put (void *cls,
 
 
 /**
- * Update the priority for a particular key in the datastore.  If
- * the expiration time in value is different than the time found in
- * the datastore, the higher value should be kept.  For the
- * anonymity level, the lower value is to be used.  The specified
- * priority should be added to the existing priority, ignoring the
- * priority in value.
- *
- * Note that it is possible for multiple values to match this put.
- * In that case, all of the respective values are updated.
+ * Update the priority, replication and expiration for a particular
+ * unique ID in the datastore.  If the expiration time in value is
+ * different than the time found in the datastore, the higher value
+ * should be kept.  The specified priority and replication is added
+ * to the existing value.
  *
  * @param cls our "struct Plugin*"
  * @param uid unique identifier of the datum
- * @param delta by how much should the priority
+ * @param priority by how much should the priority
+ *     change?
+ * @param replication by how much should the replication
  *     change?
  * @param expire new expiration time should be the
  *     MAX of any existing expiration time and
@@ -394,7 +433,8 @@ mysql_plugin_put (void *cls,
 static void
 mysql_plugin_update (void *cls,
                      uint64_t uid,
-                     uint32_t delta,
+                     uint32_t priority,
+                     uint32_t replication,
                      struct GNUNET_TIME_Absolute expire,
                      PluginUpdateCont cont,
                      void *cont_cls)
@@ -404,13 +444,15 @@ mysql_plugin_update (void *cls,
   int ret;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Updating value %llu adding %d to priority and maxing exp at %s\n",
+              "Updating value %llu adding %d to priority %d to replication and maxing exp at %s\n",
               (unsigned long long) uid,
-              delta,
-             GNUNET_STRINGS_absolute_time_to_string (expire));
+              priority,
+              replication,
+              GNUNET_STRINGS_absolute_time_to_string (expire));
 
   struct GNUNET_MY_QueryParam params_update[] = {
-    GNUNET_MY_query_param_uint32 (&delta),
+    GNUNET_MY_query_param_uint32 (&priority),
+    GNUNET_MY_query_param_uint32 (&replication),
     GNUNET_MY_query_param_uint64 (&lexpire),
     GNUNET_MY_query_param_uint64 (&lexpire),
     GNUNET_MY_query_param_uint64 (&uid),
@@ -457,6 +499,7 @@ execute_select (struct Plugin *plugin,
                 struct GNUNET_MY_QueryParam *params_select)
 {
   int ret;
+  uint32_t replication;
   uint32_t type;
   uint32_t priority;
   uint32_t anonymity;
@@ -466,6 +509,7 @@ execute_select (struct Plugin *plugin,
   struct GNUNET_HashCode key;
   struct GNUNET_TIME_Absolute expiration;
   struct GNUNET_MY_ResultSpec results_select[] = {
+    GNUNET_MY_result_spec_uint32 (&replication),
     GNUNET_MY_result_spec_uint32 (&type),
     GNUNET_MY_result_spec_uint32 (&priority),
     GNUNET_MY_result_spec_uint32 (&anonymity),
@@ -482,7 +526,7 @@ execute_select (struct Plugin *plugin,
   if (GNUNET_OK != ret)
   {
     proc (proc_cls,
-          NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+          NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
     return;
   }
 
@@ -491,7 +535,7 @@ execute_select (struct Plugin *plugin,
   if (GNUNET_OK != ret)
   {
     proc (proc_cls,
-          NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+          NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
     return;
   }
 
@@ -513,6 +557,7 @@ execute_select (struct Plugin *plugin,
               type,
               priority,
               anonymity,
+              replication,
               expiration,
               uid);
   GNUNET_MY_cleanup_result (results_select);
@@ -729,6 +774,7 @@ struct ReplCtx
  * @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 uid unique identifier for the datum;
  *        maybe 0 if no unique identifier is available
@@ -744,6 +790,7 @@ repl_proc (void *cls,
            enum GNUNET_BLOCK_Type type,
            uint32_t priority,
            uint32_t anonymity,
+           uint32_t replication,
            struct GNUNET_TIME_Absolute expiration,
            uint64_t uid)
 {
@@ -759,6 +806,7 @@ repl_proc (void *cls,
                   type,
                   priority,
                   anonymity,
+                  replication,
                   expiration,
                   uid);
   if (NULL != key)
@@ -826,7 +874,7 @@ mysql_plugin_get_replication (void *cls,
                                plugin->max_repl,
                                params_get))
   {
-    proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+    proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
     return;
   }
 
@@ -834,7 +882,7 @@ mysql_plugin_get_replication (void *cls,
       GNUNET_MY_extract_result (plugin->max_repl,
                                 results_get))
   {
-    proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+    proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
     return;
   }
   GNUNET_break (GNUNET_NO ==
@@ -976,6 +1024,7 @@ struct ExpiCtx
  * @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 uid unique identifier for the datum;
  *        maybe 0 if no unique identifier is available
@@ -991,6 +1040,7 @@ expi_proc (void *cls,
            enum GNUNET_BLOCK_Type type,
            uint32_t priority,
            uint32_t anonymity,
+           uint32_t replication,
            struct GNUNET_TIME_Absolute expiration,
            uint64_t uid)
 {
@@ -1016,6 +1066,7 @@ expi_proc (void *cls,
                    type,
                    priority,
                    anonymity,
+                   replication,
                    expiration,
                    uid);
 }
index 0376ebb6cd4809542532f2bba7fdfdd7cd6f0dc2..87a7acbdc9e3d3f40414afb7803eceff44ea54d7 100644 (file)
@@ -176,9 +176,10 @@ init_connection (struct Plugin *plugin)
     return GNUNET_SYSERR;
   }
   PQclear (ret);
+#define RESULT_COLUMNS "repl, type, prio, anonLevel, expire, hash, value, oid"
   if ((GNUNET_OK !=
        GNUNET_POSTGRES_prepare (plugin->dbh, "get",
-                   "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 "
+                   "SELECT " RESULT_COLUMNS " FROM gn090 "
                    "WHERE oid >= $1::bigint AND "
                    "(rvalue >= $2 OR 0 = $3::smallint) AND "
                    "(hash = $4 OR 0 = $5::smallint) AND "
@@ -191,28 +192,33 @@ init_connection (struct Plugin *plugin)
                    "VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", 9)) ||
       (GNUNET_OK !=
        GNUNET_POSTGRES_prepare (plugin->dbh, "update",
-                   "UPDATE gn090 SET prio = prio + $1, expire = CASE WHEN expire < $2 THEN $2 ELSE expire END "
-                   "WHERE oid = $3", 3)) ||
+                   "UPDATE gn090 "
+                   "SET prio = prio + $1, "
+                   "repl = repl + $2, "
+                   "expire = CASE WHEN expire < $3 THEN $3 ELSE expire END "
+                   "WHERE oid = $4", 4)) ||
       (GNUNET_OK !=
        GNUNET_POSTGRES_prepare (plugin->dbh, "decrepl",
                    "UPDATE gn090 SET repl = GREATEST (repl - 1, 0) "
                    "WHERE oid = $1", 1)) ||
       (GNUNET_OK !=
        GNUNET_POSTGRES_prepare (plugin->dbh, "select_non_anonymous",
-                   "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 "
+                   "SELECT " RESULT_COLUMNS " FROM gn090 "
                    "WHERE anonLevel = 0 AND type = $1 AND oid >= $2::bigint "
                    "ORDER BY oid ASC LIMIT 1",
                    2)) ||
       (GNUNET_OK !=
        GNUNET_POSTGRES_prepare (plugin->dbh, "select_expiration_order",
-                   "(SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 "
-                   "WHERE expire < $1 ORDER BY prio ASC LIMIT 1) " "UNION "
-                   "(SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 "
-                   "ORDER BY prio ASC LIMIT 1) " "ORDER BY expire ASC LIMIT 1",
+                   "(SELECT " RESULT_COLUMNS " FROM gn090 "
+                    "WHERE expire < $1 ORDER BY prio ASC LIMIT 1) "
+                   "UNION "
+                   "(SELECT " RESULT_COLUMNS " FROM gn090 "
+                    "ORDER BY prio ASC LIMIT 1) "
+                   "ORDER BY expire ASC LIMIT 1",
                    1)) ||
       (GNUNET_OK !=
        GNUNET_POSTGRES_prepare (plugin->dbh, "select_replication_order",
-                   "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 "
+                   "SELECT " RESULT_COLUMNS " FROM gn090 "
                    "ORDER BY repl DESC,RANDOM() LIMIT 1", 0)) ||
       (GNUNET_OK !=
        GNUNET_POSTGRES_prepare (plugin->dbh, "delrow", "DELETE FROM gn090 " "WHERE oid=$1", 1)) ||
@@ -371,19 +377,21 @@ process_result (struct Plugin *plugin,
   uint32_t rowid;
   uint32_t utype;
   uint32_t anonymity;
+  uint32_t replication;
   uint32_t priority;
   size_t size;
   void *data;
   struct GNUNET_TIME_Absolute expiration_time;
   struct GNUNET_HashCode key;
   struct GNUNET_PQ_ResultSpec rs[] = {
+    GNUNET_PQ_result_spec_uint32 ("repl", &replication),
     GNUNET_PQ_result_spec_uint32 ("type", &utype),
     GNUNET_PQ_result_spec_uint32 ("prio", &priority),
     GNUNET_PQ_result_spec_uint32 ("anonLevel", &anonymity),
-    GNUNET_PQ_result_spec_uint32 ("oid", &rowid),
     GNUNET_PQ_result_spec_absolute_time ("expire", &expiration_time),
     GNUNET_PQ_result_spec_auto_from_type ("hash", &key),
     GNUNET_PQ_result_spec_variable_size ("value", &data, &size),
+    GNUNET_PQ_result_spec_uint32 ("oid", &rowid),
     GNUNET_PQ_result_spec_end
   };
 
@@ -398,8 +406,7 @@ process_result (struct Plugin *plugin,
     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
                     "datastore-postgres",
                      "Ending iteration (postgres error)\n");
-    proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
-         GNUNET_TIME_UNIT_ZERO_ABS, 0);
+    proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
     return;
   }
 
@@ -409,16 +416,14 @@ process_result (struct Plugin *plugin,
     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
                     "datastore-postgres",
                      "Ending iteration (no more results)\n");
-    proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
-         GNUNET_TIME_UNIT_ZERO_ABS, 0);
+    proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
     PQclear (res);
     return;
   }
   if (1 != PQntuples (res))
   {
     GNUNET_break (0);
-    proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
-         GNUNET_TIME_UNIT_ZERO_ABS, 0);
+    proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
     PQclear (res);
     return;
   }
@@ -432,8 +437,7 @@ process_result (struct Plugin *plugin,
     GNUNET_POSTGRES_delete_by_rowid (plugin->dbh,
                                     "delrow",
                                     rowid);
-    proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
-         GNUNET_TIME_UNIT_ZERO_ABS, 0);
+    proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
     return;
   }
 
@@ -443,14 +447,15 @@ process_result (struct Plugin *plugin,
                    (unsigned int) size,
                   (unsigned int) utype);
   iret = proc (proc_cls,
-              &key,
-              size,
-              data,
-              (enum GNUNET_BLOCK_Type) utype,
-              priority,
-              anonymity,
-              expiration_time,
-              rowid);
+               &key,
+               size,
+               data,
+               (enum GNUNET_BLOCK_Type) utype,
+               priority,
+               anonymity,
+               replication,
+               expiration_time,
+               rowid);
   PQclear (res);
   if (iret == GNUNET_NO)
   {
@@ -620,6 +625,7 @@ struct ReplCtx
  * @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 uid unique identifier for the datum;
  *        maybe 0 if no unique identifier is available
@@ -630,13 +636,14 @@ struct ReplCtx
  */
 static int
 repl_proc (void *cls,
-          const struct GNUNET_HashCode *key,
-          uint32_t size,
+           const struct GNUNET_HashCode *key,
+           uint32_t size,
            const void *data,
-          enum GNUNET_BLOCK_Type type,
-          uint32_t priority,
+           enum GNUNET_BLOCK_Type type,
+           uint32_t priority,
            uint32_t anonymity,
-          struct GNUNET_TIME_Absolute expiration,
+           uint32_t replication,
+           struct GNUNET_TIME_Absolute expiration,
            uint64_t uid)
 {
   struct ReplCtx *rc = cls;
@@ -650,12 +657,15 @@ repl_proc (void *cls,
   PGresult *qret;
 
   ret = rc->proc (rc->proc_cls,
-                 key,
-                 size, data,
-                 type,
-                 priority,
-                 anonymity,
-                 expiration, uid);
+                  key,
+                  size,
+                  data,
+                  type,
+                  priority,
+                  anonymity,
+                  replication,
+                  expiration,
+                  uid);
   if (NULL == key)
     return ret;
   qret = GNUNET_PQ_exec_prepared (plugin->dbh,
@@ -740,19 +750,17 @@ postgres_plugin_get_expiration (void *cls,
 
 
 /**
- * Update the priority for a particular key in the datastore.  If
- * the expiration time in value is different than the time found in
- * the datastore, the higher value should be kept.  For the
- * anonymity level, the lower value is to be used.  The specified
- * priority should be added to the existing priority, ignoring the
- * priority in value.
- *
- * Note that it is possible for multiple values to match this put.
- * In that case, all of the respective values are updated.
+ * Update the priority, replication and expiration for a particular
+ * unique ID in the datastore.  If the expiration time in value is
+ * different than the time found in the datastore, the higher value
+ * should be kept.  The specified priority and replication is added
+ * to the existing value.
  *
  * @param cls our `struct Plugin *`
  * @param uid unique identifier of the datum
- * @param delta by how much should the priority
+ * @param priority by how much should the priority
+ *     change?
+ * @param replication by how much should the replication
  *     change?
  * @param expire new expiration time should be the
  *     MAX of any existing expiration time and
@@ -762,16 +770,18 @@ postgres_plugin_get_expiration (void *cls,
  */
 static void
 postgres_plugin_update (void *cls,
-                       uint64_t uid,
-                       uint32_t delta,
+                        uint64_t uid,
+                        uint32_t priority,
+                        uint32_t replication,
                         struct GNUNET_TIME_Absolute expire,
                         PluginUpdateCont cont,
-                       void *cont_cls)
+                        void *cont_cls)
 {
   struct Plugin *plugin = cls;
   uint32_t oid = (uint32_t) uid;
   struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_uint32 (&delta),
+    GNUNET_PQ_query_param_uint32 (&priority),
+    GNUNET_PQ_query_param_uint32 (&replication),
     GNUNET_PQ_query_param_absolute_time (&expire),
     GNUNET_PQ_query_param_uint32 (&oid),
     GNUNET_PQ_query_param_end
index 76f791ad4296f86304fb801e2b7a0dab48d266dd..1f874e1908093faedcc0f881c98eea5de4393d34 100644 (file)
@@ -349,10 +349,14 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
   sqlite3_finalize (stmt);
   create_indices (plugin->dbh);
 
+#define RESULT_COLUMNS "repl, type, prio, anonLevel, expire, hash, value, _ROWID_"
   if ( (SQLITE_OK !=
         sq_prepare (plugin->dbh,
                     "UPDATE gn090 "
-                    "SET prio = prio + ?, expire = MAX(expire,?) WHERE _ROWID_ = ?",
+                    "SET prio = prio + ?, "
+                    "repl = repl + ?, "
+                    "expire = MAX(expire, ?) "
+                    "WHERE _ROWID_ = ?",
                     &plugin->updPrio)) ||
        (SQLITE_OK !=
         sq_prepare (plugin->dbh,
@@ -360,7 +364,7 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
                     &plugin->updRepl)) ||
        (SQLITE_OK !=
         sq_prepare (plugin->dbh,
-                    "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " "FROM gn090 "
+                    "SELECT " RESULT_COLUMNS " FROM gn090 "
 #if SQLITE_VERSION_NUMBER >= 3007000
                     "INDEXED BY idx_repl_rvalue "
 #endif
@@ -382,7 +386,7 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
                     &plugin->maxRepl)) ||
        (SQLITE_OK !=
         sq_prepare (plugin->dbh,
-                    "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " "FROM gn090 "
+                    "SELECT " RESULT_COLUMNS " FROM gn090 "
 #if SQLITE_VERSION_NUMBER >= 3007000
                     "INDEXED BY idx_expire "
 #endif
@@ -391,7 +395,7 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
                     &plugin->selExpi)) ||
        (SQLITE_OK !=
         sq_prepare (plugin->dbh,
-                    "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " "FROM gn090 "
+                    "SELECT " RESULT_COLUMNS " FROM gn090 "
 #if SQLITE_VERSION_NUMBER >= 3007000
                     "INDEXED BY idx_anon_type_hash "
 #endif
@@ -407,7 +411,7 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
                     &plugin->insertContent)) ||
        (SQLITE_OK !=
         sq_prepare (plugin->dbh,
-                    "SELECT type, prio, anonLevel, expire, hash, value, _ROWID_ FROM gn090 "
+                    "SELECT " RESULT_COLUMNS " FROM gn090 "
                     "WHERE _ROWID_ >= ? AND "
                     "(rvalue >= ? OR 0 = ?) AND "
                     "(hash = ? OR 0 = ?) AND "
@@ -642,19 +646,17 @@ sqlite_plugin_put (void *cls,
 
 
 /**
- * Update the priority for a particular key in the datastore.  If
- * the expiration time in value is different than the time found in
- * the datastore, the higher value should be kept.  For the
- * anonymity level, the lower value is to be used.  The specified
- * priority should be added to the existing priority, ignoring the
- * priority in value.
- *
- * Note that it is possible for multiple values to match this put.
- * In that case, all of the respective values are updated.
+ * Update the priority, replication and expiration for a particular
+ * unique ID in the datastore.  If the expiration time in value is
+ * different than the time found in the datastore, the higher value
+ * should be kept.  The specified priority and replication is added
+ * to the existing value.
  *
  * @param cls the plugin context (state for this module)
  * @param uid unique identifier of the datum
- * @param delta by how much should the priority
+ * @param priority by how much should the priority
+ *     change?
+ * @param replication by how much should the replication
  *     change?
  * @param expire new expiration time should be the
  *     MAX of any existing expiration time and
@@ -665,14 +667,16 @@ sqlite_plugin_put (void *cls,
 static void
 sqlite_plugin_update (void *cls,
                       uint64_t uid,
-                      uint32_t delta,
+                      uint32_t priority,
+                      uint32_t replication,
                       struct GNUNET_TIME_Absolute expire,
                       PluginUpdateCont cont,
                       void *cont_cls)
 {
   struct Plugin *plugin = cls;
   struct GNUNET_SQ_QueryParam params[] = {
-    GNUNET_SQ_query_param_uint32 (&delta),
+    GNUNET_SQ_query_param_uint32 (&priority),
+    GNUNET_SQ_query_param_uint32 (&replication),
     GNUNET_SQ_query_param_absolute_time (&expire),
     GNUNET_SQ_query_param_uint64 (&uid),
     GNUNET_SQ_query_param_end
@@ -731,6 +735,7 @@ execute_get (struct Plugin *plugin,
 {
   int n;
   struct GNUNET_TIME_Absolute expiration;
+  uint32_t replication;
   uint32_t type;
   uint32_t priority;
   uint32_t anonymity;
@@ -740,6 +745,7 @@ execute_get (struct Plugin *plugin,
   struct GNUNET_HashCode key;
   int ret;
   struct GNUNET_SQ_ResultSpec rs[] = {
+    GNUNET_SQ_result_spec_uint32 (&replication),
     GNUNET_SQ_result_spec_uint32 (&type),
     GNUNET_SQ_result_spec_uint32 (&priority),
     GNUNET_SQ_result_spec_uint32 (&anonymity),
@@ -773,6 +779,7 @@ execute_get (struct Plugin *plugin,
                 type,
                 priority,
                 anonymity,
+                replication,
                 expiration,
                 rowid);
     GNUNET_SQ_cleanup_result (rs);
@@ -801,7 +808,7 @@ execute_get (struct Plugin *plugin,
                   GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
                   "sqlite3_reset");
     GNUNET_break (0);
-    proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+    proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
     database_shutdown (plugin);
     database_setup (plugin->env->cfg,
                     plugin);
@@ -809,7 +816,7 @@ execute_get (struct Plugin *plugin,
   }
   GNUNET_SQ_reset (plugin->dbh,
                    stmt);
-  proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+  proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
 }
 
 
@@ -844,7 +851,7 @@ sqlite_plugin_get_zero_anonymity (void *cls,
       GNUNET_SQ_bind (plugin->selZeroAnon,
                       params))
   {
-    proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+    proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
     return;
   }
   execute_get (plugin, plugin->selZeroAnon, proc, proc_cls);
@@ -912,7 +919,7 @@ sqlite_plugin_get_key (void *cls,
       GNUNET_SQ_bind (plugin->get,
                       params))
   {
-    proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+    proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
     return;
   }
   execute_get (plugin,
@@ -962,6 +969,7 @@ struct ReplCtx
  * @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 uid unique identifier for the datum;
  *        maybe 0 if no unique identifier is available
@@ -976,6 +984,7 @@ repl_proc (void *cls,
            enum GNUNET_BLOCK_Type type,
            uint32_t priority,
            uint32_t anonymity,
+           uint32_t replication,
            struct GNUNET_TIME_Absolute expiration,
            uint64_t uid)
 {
@@ -991,6 +1000,7 @@ repl_proc (void *cls,
                   type,
                   priority,
                   anonymity,
+                  replication,
                   expiration,
                   uid);
   if (NULL != key)
@@ -1040,7 +1050,7 @@ sqlite_plugin_get_replication (void *cls,
     GNUNET_SQ_reset (plugin->dbh,
                      plugin->maxRepl);
     /* DB empty */
-    proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+    proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
     return;
   }
   repl = sqlite3_column_int (plugin->maxRepl,
@@ -1053,7 +1063,7 @@ sqlite_plugin_get_replication (void *cls,
       GNUNET_SQ_bind (plugin->selRepl,
                       params_sel_repl))
   {
-    proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+    proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
     return;
   }
   rc.have_uid = GNUNET_SYSERR;
@@ -1069,7 +1079,7 @@ sqlite_plugin_get_replication (void *cls,
         GNUNET_SQ_bind (plugin->updRepl,
                         params_upd_repl))
     {
-      proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+      proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
       return;
     }
     if (SQLITE_DONE !=
@@ -1083,7 +1093,7 @@ sqlite_plugin_get_replication (void *cls,
   if (GNUNET_SYSERR == rc.have_uid)
   {
     /* proc was not called at all so far, do it now. */
-    proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+    proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
   }
 }
 
@@ -1117,7 +1127,7 @@ sqlite_plugin_get_expiration (void *cls, PluginDatumProcessor proc,
       GNUNET_SQ_bind (stmt,
                       params))
   {
-    proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+    proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
     return;
   }
   execute_get (plugin, stmt, proc, proc_cls);
index 18722179835ff9130ce8b2c203df07c8bd0c2ee5..8e44f020d42e0e5c8c3954b5e1b5a30fadf71f46 100644 (file)
@@ -151,19 +151,17 @@ template_plugin_get_expiration (void *cls, PluginDatumProcessor proc,
 
 
 /**
- * Update the priority for a particular key in the datastore.  If
- * the expiration time in value is different than the time found in
- * the datastore, the higher value should be kept.  For the
- * anonymity level, the lower value is to be used.  The specified
- * priority should be added to the existing priority, ignoring the
- * priority in value.
- *
- * Note that it is possible for multiple values to match this put.
- * In that case, all of the respective values are updated.
+ * Update the priority, replication and expiration for a particular
+ * unique ID in the datastore.  If the expiration time in value is
+ * different than the time found in the datastore, the higher value
+ * should be kept.  The specified priority and replication is added
+ * to the existing value.
  *
  * @param cls our "struct Plugin*"
  * @param uid unique identifier of the datum
- * @param delta by how much should the priority
+ * @param priority by how much should the priority
+ *     change?
+ * @param replication by how much should the replication
  *     change?
  * @param expire new expiration time should be the
  *     MAX of any existing expiration time and
@@ -172,9 +170,13 @@ template_plugin_get_expiration (void *cls, PluginDatumProcessor proc,
  * @param cons_cls continuation closure
  */
 static void
-template_plugin_update (void *cls, uint64_t uid, uint32_t delta,
+template_plugin_update (void *cls,
+                        uint64_t uid,
+                        uint32_t priority,
+                        uint32_t replication,
                         struct GNUNET_TIME_Absolute expire,
-                        PluginUpdateCont cont, void *cont_cls)
+                        PluginUpdateCont cont,
+                        void *cont_cls)
 {
   GNUNET_break (0);
   cont (cont_cls, GNUNET_SYSERR, "not implemented");
index 0da68b26643ff6a74df6ba3785bb01dca5377cce..63927a3643b094aa855002574573a69f3ac338de 100644 (file)
@@ -231,6 +231,7 @@ check_value (void *cls,
              enum GNUNET_BLOCK_Type type,
              uint32_t priority,
              uint32_t anonymity,
+             uint32_t replication,
              struct GNUNET_TIME_Absolute expiration,
              uint64_t uid)
 {
@@ -283,6 +284,7 @@ delete_value (void *cls,
               enum GNUNET_BLOCK_Type type,
               uint32_t priority,
               uint32_t anonymity,
+              uint32_t replication,
               struct GNUNET_TIME_Absolute expiration,
               uint64_t uid)
 {
@@ -308,6 +310,7 @@ check_nothing (void *cls,
                enum GNUNET_BLOCK_Type type,
                uint32_t priority,
                uint32_t anonymity,
+               uint32_t replication,
                struct GNUNET_TIME_Absolute expiration,
                uint64_t uid)
 {
@@ -329,6 +332,7 @@ check_multiple (void *cls,
                 enum GNUNET_BLOCK_Type type,
                 uint32_t priority,
                 uint32_t anonymity,
+                uint32_t replication,
                 struct GNUNET_TIME_Absolute expiration,
                 uint64_t uid)
 {
index de4dc657ff34bd6adac8f61dd3564bd4dc1754f2..e50b989099ccd752b5772ea1e6a946d3feeea738 100644 (file)
@@ -137,9 +137,15 @@ check_success (void *cls, int success, struct GNUNET_TIME_Absolute min_expiratio
 
 
 static void
-check_value (void *cls, const struct GNUNET_HashCode * key, size_t size,
-             const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority,
-             uint32_t anonymity, struct GNUNET_TIME_Absolute expiration,
+check_value (void *cls,
+             const struct GNUNET_HashCode *key,
+             size_t size,
+             const void *data,
+             enum GNUNET_BLOCK_Type type,
+             uint32_t priority,
+             uint32_t anonymity,
+             uint32_t replication,
+             struct GNUNET_TIME_Absolute expiration,
              uint64_t uid)
 {
   struct CpsRunContext *crc = cls;
@@ -166,9 +172,15 @@ check_value (void *cls, const struct GNUNET_HashCode * key, size_t size,
 
 
 static void
-check_nothing (void *cls, const struct GNUNET_HashCode * key, size_t size,
-               const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority,
-               uint32_t anonymity, struct GNUNET_TIME_Absolute expiration,
+check_nothing (void *cls,
+               const struct GNUNET_HashCode *key,
+               size_t size,
+               const void *data,
+               enum GNUNET_BLOCK_Type type,
+               uint32_t priority,
+               uint32_t anonymity,
+               uint32_t replication,
+               struct GNUNET_TIME_Absolute expiration,
                uint64_t uid)
 {
   struct CpsRunContext *crc = cls;
index 94d93aac672a5ea09cc4937d79a289334edc9527..1867d67553de2e27e0ac9fd64acd4c763da09729 100644 (file)
@@ -193,6 +193,7 @@ iterate_one_shot (void *cls,
                   enum GNUNET_BLOCK_Type type,
                   uint32_t priority,
                   uint32_t anonymity,
+                  uint32_t replication,
                   struct GNUNET_TIME_Absolute expiration,
                   uint64_t uid)
 {
@@ -317,11 +318,12 @@ test (void *cls)
     break;
   case RP_UPDATE:
     crc->api->update (crc->api->cls,
-                     guid,
-                     1,
-                     GNUNET_TIME_UNIT_ZERO_ABS,
+                      guid,
+                      1,
+                      1,
+                      GNUNET_TIME_UNIT_ZERO_ABS,
                       &update_continuation,
-                     crc);
+                      crc);
     break;
 
   case RP_ITER_ZERO:
index f8619b8125de44916c060aba0f68bf5b552e2567..02ebb2ffee357650fe58c043e8d2c9027810107b 100644 (file)
@@ -219,19 +219,21 @@ continue_writing (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 uid unique identifier for the datum;
  *        maybe 0 if no unique identifier is available
  */
 static void
 handle_datastore_reply (void *cls,
-                       const struct GNUNET_HashCode *key,
-                       size_t size,
-                       const void *data,
-                       enum GNUNET_BLOCK_Type type,
-                       uint32_t priority,
-                       uint32_t anonymity,
-                       struct GNUNET_TIME_Absolute expiration,
+                        const struct GNUNET_HashCode *key,
+                        size_t size,
+                        const void *data,
+                        enum GNUNET_BLOCK_Type type,
+                        uint32_t priority,
+                        uint32_t anonymity,
+                        uint32_t replication,
+                        struct GNUNET_TIME_Absolute expiration,
                         uint64_t uid)
 {
   struct CadetClient *sc = cls;
@@ -273,15 +275,16 @@ handle_datastore_reply (void *cls,
                GNUNET_h2s (key));
     if (GNUNET_OK !=
        GNUNET_FS_handle_on_demand_block (key,
-                                         size,
-                                          data,
-                                          type,
-                                         priority,
-                                          anonymity,
-                                         expiration,
-                                          uid,
-                                         &handle_datastore_reply,
-                                         sc))
+                                    size,
+                                    data,
+                                    type,
+                                    priority,
+                                    anonymity,
+                                    replication,
+                                    expiration,
+                                    uid,
+                                    &handle_datastore_reply,
+                                    sc))
     {
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                  "On-demand encoding request failed\n");
index ce6bcec414f124d6bc8f48146bb81fda54acdda2..b5e8af95ffc21cb789d3daef063cf7c93d602e1f 100644 (file)
@@ -266,6 +266,7 @@ remove_cont (void *cls, int success,
  * @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 uid unique identifier for the datum;
  *        maybe 0 if no unique identifier is available
@@ -280,6 +281,7 @@ GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode * key,
                                   enum GNUNET_BLOCK_Type type,
                                   uint32_t priority,
                                   uint32_t anonymity,
+                                  uint32_t replication,
                                   struct GNUNET_TIME_Absolute expiration,
                                   uint64_t uid,
                                   GNUNET_DATASTORE_DatumProcessor cont,
@@ -412,6 +414,7 @@ GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode * key,
         GNUNET_BLOCK_TYPE_FS_DBLOCK,
         priority,
         anonymity,
+        replication,
         expiration,
         uid);
   return GNUNET_OK;
index 8b861e3f7ad8bd78b957923e72b787fc2897f38b..331c5110533dbc95dea466737d9b2c933ebee86a 100644 (file)
@@ -47,6 +47,7 @@
  * @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 uid unique identifier for the datum;
  *        maybe 0 if no unique identifier is available
  * @return #GNUNET_OK on success
  */
 int
-GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode * key, uint32_t size,
-                                  const void *data, enum GNUNET_BLOCK_Type type,
-                                  uint32_t priority, uint32_t anonymity,
+GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode *key,
+                                  uint32_t size,
+                                  const void *data,
+                                  enum GNUNET_BLOCK_Type type,
+                                  uint32_t priority,
+                                  uint32_t anonymity,
+                                  uint32_t replication,
                                   struct GNUNET_TIME_Absolute expiration,
                                   uint64_t uid,
                                   GNUNET_DATASTORE_DatumProcessor cont,
index b736b49c2ba08262443b3ac2d5f8ba442c992930..7c64ab98b701915177c5905fc788b857b37086ed 100644 (file)
@@ -1409,6 +1409,7 @@ process_local_reply (void *cls,
                      enum GNUNET_BLOCK_Type type,
                      uint32_t priority,
                      uint32_t anonymity,
+                     uint32_t replication,
                      struct GNUNET_TIME_Absolute expiration,
                      uint64_t uid);
 
@@ -1470,6 +1471,7 @@ start_local_query (struct GSF_PendingRequest *pr,
  * @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 uid unique identifier for the datum;
  *        maybe 0 if no unique identifier is available
@@ -1482,6 +1484,7 @@ process_local_reply (void *cls,
                      enum GNUNET_BLOCK_Type type,
                      uint32_t priority,
                      uint32_t anonymity,
+                     uint32_t replication,
                      struct GNUNET_TIME_Absolute expiration,
                      uint64_t uid)
 {
@@ -1563,9 +1566,17 @@ process_local_reply (void *cls,
         GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
                                       &odc_warn_delay_task, pr);
     if (GNUNET_OK ==
-        GNUNET_FS_handle_on_demand_block (key, size, data, type, priority,
-                                          anonymity, expiration, uid,
-                                          &process_local_reply, pr))
+        GNUNET_FS_handle_on_demand_block (key,
+                                          size,
+                                          data,
+                                          type,
+                                          priority,
+                                          anonymity,
+                                          replication,
+                                          expiration,
+                                          uid,
+                                          &process_local_reply,
+                                          pr))
     {
       GNUNET_STATISTICS_update (GSF_stats,
                                 gettext_noop
index 361d30755d1ba1d2cb8b0bad51622eb02d81adab..21c598a72cefa9a1821370f752d3782da3792f6c 100644 (file)
@@ -448,6 +448,7 @@ consider_gathering ()
  * @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 uid unique identifier for the datum;
  *        maybe 0 if no unique identifier is available
@@ -460,6 +461,7 @@ process_migration_content (void *cls,
                            enum GNUNET_BLOCK_Type type,
                            uint32_t priority,
                            uint32_t anonymity,
+                           uint32_t replication,
                            struct GNUNET_TIME_Absolute expiration,
                            uint64_t uid)
 {
@@ -491,9 +493,11 @@ process_migration_content (void *cls,
                                           type,
                                           priority,
                                           anonymity,
+                                          replication,
                                           expiration,
                                           uid,
-                                          &process_migration_content, NULL))
+                                          &process_migration_content,
+                                          NULL))
       consider_gathering ();
     return;
   }
index cd062bf2b71efe55e8be7dd9bce68a211a95925b..e8c7f586d1992bd4ec981cd70524765737b3c2d4 100644 (file)
@@ -176,6 +176,7 @@ delay_dht_put_task (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 uid unique identifier for the datum;
  *        maybe 0 if no unique identifier is available
@@ -188,6 +189,7 @@ process_dht_put_content (void *cls,
                          enum GNUNET_BLOCK_Type type,
                          uint32_t priority,
                          uint32_t anonymity,
+                         uint32_t replication,
                          struct GNUNET_TIME_Absolute expiration,
                          uint64_t uid)
 {
index b1c9cb7c331ffafc9ffa7ebe5104ca6eda056fcb..516ba525caabbdc00796a7b73b20c43f1dede7d7 100644 (file)
@@ -93,6 +93,7 @@ struct GNUNET_DATASTORE_PluginEnvironment
  * @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 uid unique identifier for the datum
  * @return #GNUNET_OK to keep the item
@@ -100,14 +101,15 @@ struct GNUNET_DATASTORE_PluginEnvironment
  */
 typedef int
 (*PluginDatumProcessor) (void *cls,
-                        const struct GNUNET_HashCode *key,
-                        uint32_t size,
-                        const void *data,
-                        enum GNUNET_BLOCK_Type type,
-                        uint32_t priority,
-                        uint32_t anonymity,
-                        struct GNUNET_TIME_Absolute expiration,
-                        uint64_t uid);
+                         const struct GNUNET_HashCode *key,
+                         uint32_t size,
+                         const void *data,
+                         enum GNUNET_BLOCK_Type type,
+                         uint32_t priority,
+                         uint32_t anonymity,
+                         uint32_t replication,
+                         struct GNUNET_TIME_Absolute expiration,
+                         uint64_t uid);
 
 
 /**
@@ -259,16 +261,17 @@ typedef void
 
 
 /**
- * Update the priority for a particular key in the datastore.  If
- * the expiration time in value is different than the time found in
- * the datastore, the higher value should be kept.  For the
- * anonymity level, the lower value is to be used.  The specified
- * priority should be added to the existing priority, ignoring the
- * priority in value.
+ * Update the priority, replication and expiration for a particular
+ * unique ID in the datastore.  If the expiration time in value is
+ * different than the time found in the datastore, the higher value
+ * should be kept.  The specified priority and replication is added
+ * to the existing value.
  *
  * @param cls closure
  * @param uid unique identifier of the datum
- * @param delta by how much should the priority
+ * @param priority by how much should the priority
+ *     change?
+ * @param replication by how much should the replication
  *     change?
  * @param expire new expiration time should be the
  *     MAX of any existing expiration time and
@@ -278,11 +281,12 @@ typedef void
  */
 typedef void
 (*PluginUpdate) (void *cls,
-                uint64_t uid,
-                uint32_t delta,
-                struct GNUNET_TIME_Absolute expire,
-                PluginUpdateCont cont,
-                void *cont_cls);
+                 uint64_t uid,
+                 uint32_t priority,
+                 uint32_t replication,
+                 struct GNUNET_TIME_Absolute expire,
+                 PluginUpdateCont cont,
+                 void *cont_cls);
 
 
 /**
index 830e7da866b772870987c56c577e365cd1710bdb..f851385c5578a3da272f8b28ef1ba00e06d317f9 100644 (file)
@@ -240,6 +240,7 @@ GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
  * @param type type of the content
  * @param priority priority of the content
  * @param anonymity anonymity-level for the content
+ * @param replication how often should the content be replicated to other peers?
  * @param expiration expiration time for the content
  * @param uid unique identifier for the datum;
  *        maybe 0 if no unique identifier is available
@@ -252,6 +253,7 @@ typedef void
                                     enum GNUNET_BLOCK_Type type,
                                     uint32_t priority,
                                     uint32_t anonymity,
+                                    uint32_t replication,
                                     struct GNUNET_TIME_Absolute expiration,
                                     uint64_t uid);