From: Christian Grothoff Date: Sun, 3 Apr 2011 15:10:41 +0000 (+0000) Subject: new plugin API X-Git-Tag: initial-import-from-subversion-38251~18824 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=d2f2c8800aa6ea07a024c5511a1b1d23ad356090;p=oweals%2Fgnunet.git new plugin API --- diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c index 82a1f3ded..2538d5ef6 100644 --- a/src/datastore/gnunet-service-datastore.c +++ b/src/datastore/gnunet-service-datastore.c @@ -953,6 +953,7 @@ execute_put (struct GNUNET_SERVER_Client *client, ntohl(dm->type), ntohl(dm->priority), ntohl(dm->anonymity), + 0 /* FIXME: replication */, GNUNET_TIME_absolute_ntoh(dm->expiration), &msg); if (GNUNET_OK == ret) diff --git a/src/datastore/perf_plugin_datastore.c b/src/datastore/perf_plugin_datastore.c index facf7be67..cb25da46b 100644 --- a/src/datastore/perf_plugin_datastore.c +++ b/src/datastore/perf_plugin_datastore.c @@ -125,9 +125,10 @@ putValue (struct GNUNET_DATASTORE_PluginFunctions * api, int i, int k) &key, size, value, - i, + i /* type */, prio, - i, + i /* anonymity */, + 0 /* replication */, GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 60 * 60 * 60 * 1000 + diff --git a/src/datastore/plugin_datastore_mysql.c b/src/datastore/plugin_datastore_mysql.c index ac81c9011..fb1b13978 100644 --- a/src/datastore/plugin_datastore_mysql.c +++ b/src/datastore/plugin_datastore_mysql.c @@ -1348,6 +1348,7 @@ mysql_plugin_get_size (void *cls) * @param type type of the content * @param priority priority of the content * @param anonymity anonymity-level for the content + * @param replication replication-level for the content * @param expiration expiration time for the content * @param msg set to error message * @return GNUNET_OK on success @@ -1360,6 +1361,7 @@ mysql_plugin_put (void *cls, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, + uint32_t replication, struct GNUNET_TIME_Absolute expiration, char **msg) { @@ -1687,6 +1689,26 @@ mysql_plugin_get (void *cls, } +/** + * Get a random item for replication. Returns a single, not expired, random item + * from those with the highest replication counters. The item's + * replication counter is decremented by one IF it was positive before. + * Call 'iter' with all values ZERO or NULL if the datastore is empty. + * + * @param cls closure + * @param iter function to call the value (once only). + * @param iter_cls closure for iter + */ +static void +mysql_plugin_replication_get (void *cls, + PluginIterator iter, void *iter_cls) +{ + /* FIXME: not implemented! */ + iter (iter_cls, NULL, NULL, 0, NULL, 0, 0, 0, + GNUNET_TIME_UNIT_ZERO_ABS, 0); +} + + /** * Update the priority for a particular key in the datastore. If * the expiration time in value is different than the time found in @@ -1940,6 +1962,7 @@ libgnunet_plugin_datastore_mysql_init (void *cls) api->put = &mysql_plugin_put; api->next_request = &mysql_plugin_next_request; api->get = &mysql_plugin_get; + api->replication_get = &mysql_plugin_replication_get; api->update = &mysql_plugin_update; api->iter_low_priority = &mysql_plugin_iter_low_priority; api->iter_zero_anonymity = &mysql_plugin_iter_zero_anonymity; diff --git a/src/datastore/plugin_datastore_postgres.c b/src/datastore/plugin_datastore_postgres.c index 18ad77885..c004cd59f 100644 --- a/src/datastore/plugin_datastore_postgres.c +++ b/src/datastore/plugin_datastore_postgres.c @@ -587,6 +587,7 @@ postgres_plugin_get_size (void *cls) * @param type type of the content * @param priority priority of the content * @param anonymity anonymity-level for the content + * @param replication replication-level for the content * @param expiration expiration time for the content * @param msg set to error message * @return GNUNET_OK on success @@ -599,6 +600,7 @@ postgres_plugin_put (void *cls, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, + uint32_t replication, struct GNUNET_TIME_Absolute expiration, char **msg) { @@ -1197,6 +1199,26 @@ postgres_plugin_get (void *cls, } +/** + * Get a random item for replication. Returns a single, not expired, random item + * from those with the highest replication counters. The item's + * replication counter is decremented by one IF it was positive before. + * Call 'iter' with all values ZERO or NULL if the datastore is empty. + * + * @param cls closure + * @param iter function to call the value (once only). + * @param iter_cls closure for iter + */ +static void +postgres_plugin_replication_get (void *cls, + PluginIterator iter, void *iter_cls) +{ + /* FIXME: not implemented! */ + iter (iter_cls, NULL, NULL, 0, NULL, 0, 0, 0, + GNUNET_TIME_UNIT_ZERO_ABS, 0); +} + + /** * Select a subset of the items in the datastore and call * the given iterator for each of them. @@ -1333,6 +1355,7 @@ libgnunet_plugin_datastore_postgres_init (void *cls) api->put = &postgres_plugin_put; api->next_request = &postgres_plugin_next_request; api->get = &postgres_plugin_get; + api->replication_get = &postgres_plugin_replication_get; api->update = &postgres_plugin_update; api->iter_low_priority = &postgres_plugin_iter_low_priority; api->iter_zero_anonymity = &postgres_plugin_iter_zero_anonymity; diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c index 0eba474f6..260bd54cc 100644 --- a/src/datastore/plugin_datastore_sqlite.c +++ b/src/datastore/plugin_datastore_sqlite.c @@ -689,6 +689,7 @@ sqlite_next_request (void *next_cls, * @param type type of the content * @param priority priority of the content * @param anonymity anonymity-level for the content + * @param replication replication-level for the content * @param expiration expiration time for the content * @param msg set to an error message * @return GNUNET_OK on success @@ -701,6 +702,7 @@ sqlite_plugin_put (void *cls, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, + uint32_t replication, struct GNUNET_TIME_Absolute expiration, char ** msg) { @@ -1531,6 +1533,26 @@ sqlite_plugin_get (void *cls, } +/** + * Get a random item for replication. Returns a single, not expired, random item + * from those with the highest replication counters. The item's + * replication counter is decremented by one IF it was positive before. + * Call 'iter' with all values ZERO or NULL if the datastore is empty. + * + * @param cls closure + * @param iter function to call the value (once only). + * @param iter_cls closure for iter + */ +static void +sqlite_plugin_replication_get (void *cls, + PluginIterator iter, void *iter_cls) +{ + /* FIXME: not implemented! */ + iter (iter_cls, NULL, NULL, 0, NULL, 0, 0, 0, + GNUNET_TIME_UNIT_ZERO_ABS, 0); +} + + /** * Drop database. * @@ -1623,6 +1645,7 @@ libgnunet_plugin_datastore_sqlite_init (void *cls) api->put = &sqlite_plugin_put; api->next_request = &sqlite_next_request; api->get = &sqlite_plugin_get; + api->replication_get = &sqlite_plugin_replication_get; api->update = &sqlite_plugin_update; api->iter_low_priority = &sqlite_plugin_iter_low_priority; api->iter_zero_anonymity = &sqlite_plugin_iter_zero_anonymity; diff --git a/src/datastore/plugin_datastore_template.c b/src/datastore/plugin_datastore_template.c index 09dfe85d9..fc67f600e 100644 --- a/src/datastore/plugin_datastore_template.c +++ b/src/datastore/plugin_datastore_template.c @@ -64,6 +64,7 @@ static unsigned long long template_plugin_get_size (void *cls) * @param type type of the content * @param priority priority of the content * @param anonymity anonymity-level for the content + * @param replication replication-level for the content * @param expiration expiration time for the content * @param msg set to error message * @return GNUNET_OK on success @@ -76,6 +77,7 @@ template_plugin_put (void *cls, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, + uint32_t replication, struct GNUNET_TIME_Absolute expiration, char **msg) { @@ -133,6 +135,25 @@ template_plugin_get (void *cls, } + +/** + * Get a random item for replication. Returns a single, not expired, random item + * from those with the highest replication counters. The item's + * replication counter is decremented by one IF it was positive before. + * Call 'iter' with all values ZERO or NULL if the datastore is empty. + * + * @param cls closure + * @param iter function to call the value (once only). + * @param iter_cls closure for iter + */ +static void +template_plugin_replication_get (void *cls, + PluginIterator iter, void *iter_cls) +{ + GNUNET_break (0); +} + + /** * Update the priority for a particular key in the datastore. If * the expiration time in value is different than the time found in @@ -308,6 +329,7 @@ libgnunet_plugin_datastore_template_init (void *cls) api->put = &template_plugin_put; api->next_request = &template_plugin_next_request; api->get = &template_plugin_get; + api->replication_get = &template_plugin_replication_get; api->update = &template_plugin_update; api->iter_low_priority = &template_plugin_iter_low_priority; api->iter_zero_anonymity = &template_plugin_iter_zero_anonymity; diff --git a/src/include/gnunet_datastore_plugin.h b/src/include/gnunet_datastore_plugin.h index 8666dac10..c981ceb1d 100644 --- a/src/include/gnunet_datastore_plugin.h +++ b/src/include/gnunet_datastore_plugin.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet - (C) 2009 Christian Grothoff (and other contributing authors) + (C) 2009, 2011 Christian Grothoff (and other contributing authors) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -136,8 +136,8 @@ typedef unsigned long long (*PluginGetSize) (void *cls); /** * Store an item in the datastore. If the item is already present, - * the priorities are summed up and the higher expiration time and - * lower anonymity level is used. + * the priorities and replication levels are summed up and the higher + * expiration time and lower anonymity level is used. * * @param cls closure * @param key key for the item @@ -146,6 +146,7 @@ typedef unsigned long long (*PluginGetSize) (void *cls); * @param type type of the content * @param priority priority of the content * @param anonymity anonymity-level for the content + * @param replication replication-level for the content * @param expiration expiration time for the content * @param msg set to an error message (on failure) * @return GNUNET_OK on success, GNUNET_NO if the content @@ -159,6 +160,7 @@ typedef int (*PluginPut) (void *cls, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, + uint32_t replication, struct GNUNET_TIME_Absolute expiration, char **msg); @@ -191,6 +193,22 @@ typedef void (*PluginGet) (void *cls, PluginIterator iter, void *iter_cls); + +/** + * Get a random item for replication. Returns a single, + * not expired, random item + * from those with the highest replication counters. The item's + * replication counter is decremented by one IF it was positive before. + * Call 'iter' with all values ZERO or NULL if the datastore is empty. + * + * @param cls closure + * @param iter function to call the value (once only). + * @param iter_cls closure for iter + */ +typedef void (*PluginReplicationGet) (void *cls, + PluginIterator iter, void *iter_cls); + + /** * Update the priority for a particular key in the datastore. If * the expiration time in value is different than the time found in @@ -287,6 +305,12 @@ struct GNUNET_DATASTORE_PluginFunctions */ PluginGet get; + /** + * Function to get a random item with high replication score from + * the database, lowering the item's replication score. + */ + PluginReplicationGet replication_get; + /** * Update the priority for a particular key in the datastore. If * the expiration time in value is different than the time found in