diff options
author | David Barksdale <amatus@amat.us> | 2017-03-22 22:17:05 -0500 |
---|---|---|
committer | David Barksdale <amatus@amat.us> | 2017-03-22 22:19:13 -0500 |
commit | 78ecfccd774a77ae3d7a51e3f5c7c7c86cf7985b (patch) | |
tree | 1dc23a2f6d78c8026e69181ac90055929d79bba8 | |
parent | aa98f144e6db0da5a0a4cad83fe64a80bbab6692 (diff) |
[datastore] Return and update replication
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.
-rw-r--r-- | src/datastore/datastore.h | 2 | ||||
-rw-r--r-- | src/datastore/datastore_api.c | 22 | ||||
-rw-r--r-- | src/datastore/gnunet-datastore.c | 38 | ||||
-rw-r--r-- | src/datastore/gnunet-service-datastore.c | 38 | ||||
-rw-r--r-- | src/datastore/plugin_datastore_heap.c | 99 | ||||
-rw-r--r-- | src/datastore/plugin_datastore_mysql.c | 117 | ||||
-rw-r--r-- | src/datastore/plugin_datastore_postgres.c | 112 | ||||
-rw-r--r-- | src/datastore/plugin_datastore_sqlite.c | 62 | ||||
-rw-r--r-- | src/datastore/plugin_datastore_template.c | 26 | ||||
-rw-r--r-- | src/datastore/test_datastore_api.c | 4 | ||||
-rw-r--r-- | src/datastore/test_datastore_api_management.c | 24 | ||||
-rw-r--r-- | src/datastore/test_plugin_datastore.c | 10 | ||||
-rw-r--r-- | src/fs/gnunet-service-fs_cadet_server.c | 35 | ||||
-rw-r--r-- | src/fs/gnunet-service-fs_indexing.c | 3 | ||||
-rw-r--r-- | src/fs/gnunet-service-fs_indexing.h | 11 | ||||
-rw-r--r-- | src/fs/gnunet-service-fs_pr.c | 17 | ||||
-rw-r--r-- | src/fs/gnunet-service-fs_push.c | 6 | ||||
-rw-r--r-- | src/fs/gnunet-service-fs_put.c | 2 | ||||
-rw-r--r-- | src/include/gnunet_datastore_plugin.h | 44 | ||||
-rw-r--r-- | src/include/gnunet_datastore_service.h | 2 |
20 files changed, 414 insertions, 260 deletions
diff --git a/src/datastore/datastore.h b/src/datastore/datastore.h index 5fd3601612..98f8b82ef1 100644 --- a/src/datastore/datastore.h +++ b/src/datastore/datastore.h @@ -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; diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c index 26e1e501dd..31f7a997f7 100644 --- a/src/datastore/datastore_api.c +++ b/src/datastore/datastore_api.c @@ -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, diff --git a/src/datastore/gnunet-datastore.c b/src/datastore/gnunet-datastore.c index c93bc8dd33..7caf5d175b 100644 --- a/src/datastore/gnunet-datastore.c +++ b/src/datastore/gnunet-datastore.c @@ -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); } diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c index af33c44126..2775308432 100644 --- a/src/datastore/gnunet-service-datastore.c +++ b/src/datastore/gnunet-service-datastore.c @@ -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) { diff --git a/src/datastore/plugin_datastore_heap.c b/src/datastore/plugin_datastore_heap.c index e15cacb5bd..d04c1cf604 100644 --- a/src/datastore/plugin_datastore_heap.c +++ b/src/datastore/plugin_datastore_heap.c @@ -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); } diff --git a/src/datastore/plugin_datastore_mysql.c b/src/datastore/plugin_datastore_mysql.c index 5ae4485cbb..6f2a764998 100644 --- a/src/datastore/plugin_datastore_mysql.c +++ b/src/datastore/plugin_datastore_mysql.c @@ -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); } diff --git a/src/datastore/plugin_datastore_postgres.c b/src/datastore/plugin_datastore_postgres.c index 0376ebb6cd..87a7acbdc9 100644 --- a/src/datastore/plugin_datastore_postgres.c +++ b/src/datastore/plugin_datastore_postgres.c @@ -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 diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c index 76f791ad42..1f874e1908 100644 --- a/src/datastore/plugin_datastore_sqlite.c +++ b/src/datastore/plugin_datastore_sqlite.c @@ -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); diff --git a/src/datastore/plugin_datastore_template.c b/src/datastore/plugin_datastore_template.c index 1872217983..8e44f020d4 100644 --- a/src/datastore/plugin_datastore_template.c +++ b/src/datastore/plugin_datastore_template.c @@ -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"); diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c index 0da68b2664..63927a3643 100644 --- a/src/datastore/test_datastore_api.c +++ b/src/datastore/test_datastore_api.c @@ -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) { diff --git a/src/datastore/test_datastore_api_management.c b/src/datastore/test_datastore_api_management.c index de4dc657ff..e50b989099 100644 --- a/src/datastore/test_datastore_api_management.c +++ b/src/datastore/test_datastore_api_management.c @@ -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; diff --git a/src/datastore/test_plugin_datastore.c b/src/datastore/test_plugin_datastore.c index 94d93aac67..1867d67553 100644 --- a/src/datastore/test_plugin_datastore.c +++ b/src/datastore/test_plugin_datastore.c @@ -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: diff --git a/src/fs/gnunet-service-fs_cadet_server.c b/src/fs/gnunet-service-fs_cadet_server.c index f8619b8125..02ebb2ffee 100644 --- a/src/fs/gnunet-service-fs_cadet_server.c +++ b/src/fs/gnunet-service-fs_cadet_server.c @@ -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"); diff --git a/src/fs/gnunet-service-fs_indexing.c b/src/fs/gnunet-service-fs_indexing.c index ce6bcec414..b5e8af95ff 100644 --- a/src/fs/gnunet-service-fs_indexing.c +++ b/src/fs/gnunet-service-fs_indexing.c @@ -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; diff --git a/src/fs/gnunet-service-fs_indexing.h b/src/fs/gnunet-service-fs_indexing.h index 8b861e3f7a..331c511053 100644 --- a/src/fs/gnunet-service-fs_indexing.h +++ b/src/fs/gnunet-service-fs_indexing.h @@ -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 @@ -55,9 +56,13 @@ * @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, diff --git a/src/fs/gnunet-service-fs_pr.c b/src/fs/gnunet-service-fs_pr.c index b736b49c2b..7c64ab98b7 100644 --- a/src/fs/gnunet-service-fs_pr.c +++ b/src/fs/gnunet-service-fs_pr.c @@ -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 diff --git a/src/fs/gnunet-service-fs_push.c b/src/fs/gnunet-service-fs_push.c index 361d30755d..21c598a72c 100644 --- a/src/fs/gnunet-service-fs_push.c +++ b/src/fs/gnunet-service-fs_push.c @@ -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; } diff --git a/src/fs/gnunet-service-fs_put.c b/src/fs/gnunet-service-fs_put.c index cd062bf2b7..e8c7f586d1 100644 --- a/src/fs/gnunet-service-fs_put.c +++ b/src/fs/gnunet-service-fs_put.c @@ -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) { diff --git a/src/include/gnunet_datastore_plugin.h b/src/include/gnunet_datastore_plugin.h index b1c9cb7c33..516ba525ca 100644 --- a/src/include/gnunet_datastore_plugin.h +++ b/src/include/gnunet_datastore_plugin.h @@ -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); /** diff --git a/src/include/gnunet_datastore_service.h b/src/include/gnunet_datastore_service.h index 830e7da866..f851385c55 100644 --- a/src/include/gnunet_datastore_service.h +++ b/src/include/gnunet_datastore_service.h @@ -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); |