From 138b0402c39ff1c8e725bc1fe3f96e0d7e82dd70 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 26 Jul 2009 21:47:30 +0000 Subject: [PATCH] DHT and datacache API refinements --- src/datacache/perf_datacache_api.c | 1 + src/datacache/plugin_datacache_sqlite.c | 5 +- src/datacache/test_datacache_api.c | 1 + src/include/gnunet_datacache_lib.h | 2 + src/include/gnunet_dht_service.h | 74 +++++++++++++++++++++++-- 5 files changed, 77 insertions(+), 6 deletions(-) diff --git a/src/datacache/perf_datacache_api.c b/src/datacache/perf_datacache_api.c index aa008a332..aa11fe122 100644 --- a/src/datacache/perf_datacache_api.c +++ b/src/datacache/perf_datacache_api.c @@ -38,6 +38,7 @@ static unsigned int found; static int checkIt (void *cls, + struct GNUNET_TIME_Absolute exp, const GNUNET_HashCode * key, uint32_t size, const char *data, diff --git a/src/datacache/plugin_datacache_sqlite.c b/src/datacache/plugin_datacache_sqlite.c index 51bbf60d7..5493dbb90 100644 --- a/src/datacache/plugin_datacache_sqlite.c +++ b/src/datacache/plugin_datacache_sqlite.c @@ -170,6 +170,7 @@ sqlite_plugin_get (void *cls, struct Plugin *plugin = cls; sqlite3_stmt *stmt; struct GNUNET_TIME_Absolute now; + struct GNUNET_TIME_Absolute exp; unsigned int size; const char *dat; unsigned int cnt; @@ -218,7 +219,7 @@ sqlite_plugin_get (void *cls, off = (off + 1) % total; GNUNET_snprintf (scratch, sizeof(scratch), - "SELECT value FROM ds090 WHERE key=? AND type=? AND expire >= ? LIMIT 1 OFFSET %u", + "SELECT value,expire FROM ds090 WHERE key=? AND type=? AND expire >= ? LIMIT 1 OFFSET %u", off); if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK) { @@ -236,8 +237,10 @@ sqlite_plugin_get (void *cls, break; size = sqlite3_column_bytes (stmt, 0); dat = sqlite3_column_blob (stmt, 0); + exp.value = sqlite3_column_int64 (stmt, 1); cnt++; if (GNUNET_OK != iter (iter_cls, + exp, key, size, dat, diff --git a/src/datacache/test_datacache_api.c b/src/datacache/test_datacache_api.c index 5207fa2a5..8a5a356d2 100644 --- a/src/datacache/test_datacache_api.c +++ b/src/datacache/test_datacache_api.c @@ -35,6 +35,7 @@ static int ok; static int checkIt (void *cls, + struct GNUNET_TIME_Absolute exp, const GNUNET_HashCode * key, uint32_t size, const char *data, diff --git a/src/include/gnunet_datacache_lib.h b/src/include/gnunet_datacache_lib.h index 8eb724bfa..3bd76df32 100644 --- a/src/include/gnunet_datacache_lib.h +++ b/src/include/gnunet_datacache_lib.h @@ -74,6 +74,7 @@ void GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h); * An iterator over a set of items stored in the datacache. * * @param cls closure + * @param exp when will the content expire? * @param key key for the content * @param size number of bytes in data * @param data content stored @@ -81,6 +82,7 @@ void GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h); * @return GNUNET_OK to continue iterating, GNUNET_SYSERR to abort */ typedef int (*GNUNET_DATACACHE_Iterator) (void *cls, + struct GNUNET_TIME_Absolute exp, const GNUNET_HashCode * key, uint32_t size, const char *data, diff --git a/src/include/gnunet_dht_service.h b/src/include/gnunet_dht_service.h index 8dcbc19c5..0dab0bcbc 100644 --- a/src/include/gnunet_dht_service.h +++ b/src/include/gnunet_dht_service.h @@ -37,10 +37,59 @@ extern "C" #endif #endif -// FIXME: document + +/** + * Connection to the DHT service. + */ +struct GNUNET_DHT_Handle; + + +/** + * Initialize the connection with the DHT service. + * + * @param cfg configuration to use + * @param sched scheduler to use + * @return NULL on error + */ +struct GNUNET_DHT_Handle * +GNUNET_DHT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_SCHEDULER_Handle *sched); + + +/** + * Shutdown connection with the DHT service. + * + * @param h connection to shut down + */ +void +GNUNET_DHT_connect (struct GNUNET_DHT_Handle *h); + + +/** + * Handle to control a GET operation. + */ struct GNUNET_DHT_GetHandle; +/** + * Iterator called on each result obtained for a GET + * operation. + * + * @param cls closure + * @param exp when will this value expire + * @param key key of the result + * @param type type of the result + * @param size number of bytes in data + * @param data pointer to the result data + */ +typedef void (*GNUNET_DHT_Iterator)(void *cls, + struct GNUNET_TIME_Absolute exp, + const GNUNET_HashCode * key, + uint32_t type, + uint32_t size, + const void *data); + + /** * Perform an asynchronous GET operation on the DHT identified. * @@ -60,23 +109,38 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *h, /** * Stop async DHT-get. Frees associated resources. + * + * @param record GET operation to stop. */ -int GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *record); +void +GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *record); -// FIXME: add continuation? expiration? /** * Perform a PUT operation on the DHT identified by 'table' storing * a binding of 'key' to 'value'. The peer does not have to be part * of the table (if so, we will attempt to locate a peer that is!) * + * @param h handle to DHT service * @param key the key to store under + * @param type type of the value + * @param size number of bytes in data; must be less than 64k + * @param data the data to store + * @param exp desired expiration time for the value + * @param cont continuation to call when done; + * reason will be TIMEOUT on error, + * reason will be PREREQ_DONE on success + * @param cont_cls closure for cont + * */ int GNUNET_DHT_put (struct GNUNET_DHT_Handle *h, const GNUNET_HashCode * key, - uint32_t type, + uint32_t type, uint32_t size, - const char *data); + const char *data, + struct GNUNET_TIME_Relative exp, + GNUNET_SCHEDULER_Task cont, + void *cont_cls); #if 0 /* keep Emacsens' auto-indent happy */ -- 2.25.1