From bf5093d63a384e216fc765a8a800ecb17840d56b Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 27 Apr 2011 19:04:31 +0000 Subject: [PATCH] pass repl --- src/datastore/datastore.h | 10 ++++++++++ src/datastore/datastore_api.c | 7 +++++-- src/datastore/gnunet-service-datastore.c | 19 ++++++++++++++++--- src/datastore/plugin_datastore_sqlite.c | 12 +++++++++--- 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/datastore/datastore.h b/src/datastore/datastore.h index d66ec0e95..70acffc99 100644 --- a/src/datastore/datastore.h +++ b/src/datastore/datastore.h @@ -219,6 +219,16 @@ struct DataMessage */ uint32_t anonymity GNUNET_PACKED; + /** + * Desired replication level. 0 from service to API. + */ + uint32_t replication GNUNET_PACKED; + + /** + * For alignment. + */ + uint32_t reserved GNUNET_PACKED; + /** * Unique ID for the content (can be used for UPDATE); * can be zero for remove (which indicates that diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c index 99060bd60..7818ed05c 100644 --- a/src/datastore/datastore_api.c +++ b/src/datastore/datastore_api.c @@ -854,9 +854,10 @@ GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h, #if DEBUG_DATASTORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Asked to put %u bytes of data under key `%s'\n", + "Asked to put %u bytes of data under key `%s' for %llu ms\n", size, - GNUNET_h2s (key)); + GNUNET_h2s (key), + GNUNET_TIME_absolute_get_remaining (expiration).rel_value); #endif msize = sizeof(struct DataMessage) + size; GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); @@ -885,6 +886,8 @@ GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h, dm->type = htonl(type); 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; diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c index deab62dd0..a0d5f7bab 100644 --- a/src/datastore/gnunet-service-datastore.c +++ b/src/datastore/gnunet-service-datastore.c @@ -646,16 +646,20 @@ 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->expiration = GNUNET_TIME_absolute_hton(expiration); dm->uid = GNUNET_htonll(uid); dm->key = *key; memcpy (&dm[1], data, size); #if DEBUG_DATASTORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Transmitting `%s' message for `%s' of type %u\n", + "Transmitting `%s' message for `%s' of type %u with expiration %llu (now: %llu)\n", "DATA", GNUNET_h2s (key), - type); + type, + (unsigned long long) expiration.abs_value, + (unsigned long long) GNUNET_TIME_absolute_get ().abs_value); #endif GNUNET_STATISTICS_update (stats, gettext_noop ("# results found"), @@ -870,7 +874,7 @@ execute_put (struct GNUNET_SERVER_Client *client, ntohl(dm->type), ntohl(dm->priority), ntohl(dm->anonymity), - 0 /* FIXME: replication */, + ntohl(dm->replication), GNUNET_TIME_absolute_ntoh(dm->expiration), &msg); if (GNUNET_OK == ret) @@ -956,6 +960,15 @@ check_present (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result already present in datastore\n"); #endif + /* FIXME: change API to allow increasing 'replication' counter */ + if ( (ntohl (dm->priority) > 0) || + (GNUNET_TIME_absolute_ntoh(dm->expiration).abs_value > + expiration.abs_value) ) + plugin->api->update (plugin->api->cls, + uid, + (int32_t) ntohl(dm->priority), + GNUNET_TIME_absolute_ntoh(dm->expiration), + NULL); transmit_status (pc->client, GNUNET_NO, NULL); GNUNET_SERVER_client_drop (pc->client); GNUNET_free (pc); diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c index 3710b7eb7..f58c5bd28 100644 --- a/src/datastore/plugin_datastore_sqlite.c +++ b/src/datastore/plugin_datastore_sqlite.c @@ -31,7 +31,7 @@ /** * Enable or disable logging debug messages. */ -#define DEBUG_SQLITE GNUNET_NO +#define DEBUG_SQLITE GNUNET_YES /** * We allocate items on the stack at times. To prevent a stack @@ -475,7 +475,7 @@ sqlite_plugin_put (void *cls, #if DEBUG_SQLITE GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", - "Storing in database block with type %u/key `%s'/priority %u/expiration %llu (%lld).\n", + "Storing in database block with type %u/key `%s'/priority %u/expiration in %llu ms (%lld).\n", type, GNUNET_h2s(key), priority, @@ -650,6 +650,12 @@ execute_get (struct Plugin *plugin, break; } expiration.abs_value = sqlite3_column_int64 (stmt, 3); +#if DEBUG_SQLITE + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, + "sqlite", + "Found reply in database with expiration %llu\n", + (unsigned long long) expiration.abs_value); +#endif ret = proc (proc_cls, sqlite3_column_blob (stmt, 4) /* key */, size, @@ -1175,7 +1181,7 @@ libgnunet_plugin_datastore_sqlite_done (void *cls) #if DEBUG_SQLITE GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", - "sqlite plugin is finished doneing\n"); + "sqlite plugin is finished\n"); #endif return NULL; } -- 2.25.1