From beb7e51b1c1606856e2a8cbe2d6f5d64a56ca3b8 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 11 Sep 2009 14:21:00 +0000 Subject: [PATCH] better datastore API --- src/datastore/datastore_api.c | 37 +++++++++++++++++-- src/datastore/perf_datastore_api.c | 6 ++- src/datastore/test_datastore_api.c | 4 ++ src/datastore/test_datastore_api_management.c | 1 + src/include/gnunet_datastore_service.h | 21 ++++++++++- 5 files changed, 62 insertions(+), 7 deletions(-) diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c index 7b674087e..58fb5a795 100644 --- a/src/datastore/datastore_api.c +++ b/src/datastore/datastore_api.c @@ -566,10 +566,6 @@ with_result_response_handler (void *cls, ntohl(dm->anonymity), GNUNET_TIME_absolute_ntoh(dm->expiration), GNUNET_ntohll(dm->uid)); - GNUNET_CLIENT_receive (h->client, - &with_result_response_handler, - h, - GNUNET_TIME_absolute_get_remaining (h->timeout)); } @@ -618,6 +614,39 @@ transmit_get_result (void *cls, } + +/** + * Function called to trigger obtaining the next result + * from the datastore. + * + * @param h handle to the datastore + * @param more GNUNET_YES to get moxre results, GNUNET_NO to abort + * iteration (with a final call to "iter" with key/data == NULL). + */ +void +GNUNET_DATASTORE_get_next (struct GNUNET_DATASTORE_Handle *h, + int more) +{ + GNUNET_DATASTORE_Iterator cont; + + if (GNUNET_YES == more) + { + GNUNET_CLIENT_receive (h->client, + &with_result_response_handler, + h, + GNUNET_TIME_absolute_get_remaining (h->timeout)); + return; + } + cont = h->response_proc; + h->response_proc = NULL; + GNUNET_CLIENT_disconnect (h->client); + h->client = GNUNET_CLIENT_connect (h->sched, "datastore", h->cfg); + cont (h->response_proc_cls, + NULL, 0, NULL, 0, 0, 0, + GNUNET_TIME_UNIT_ZERO_ABS, 0); +} + + /** * Helper function that will initiate the * transmission of a message to the datastore diff --git a/src/datastore/perf_datastore_api.c b/src/datastore/perf_datastore_api.c index 626fbcf73..4ba8216bf 100644 --- a/src/datastore/perf_datastore_api.c +++ b/src/datastore/perf_datastore_api.c @@ -230,10 +230,14 @@ delete_value (void *cls, } stored_ops++; if (stored_bytes < MAX_SIZE) - return; + { + GNUNET_DATASTORE_get_next (datastore, GNUNET_YES); + return; + } crc->key = *key; crc->esize = size; memcpy (crc->data, data, size); + GNUNET_DATASTORE_get_next (datastore, GNUNET_YES); } diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c index e8e303436..a63f0425f 100644 --- a/src/datastore/test_datastore_api.c +++ b/src/datastore/test_datastore_api.c @@ -207,6 +207,7 @@ check_value (void *cls, GNUNET_assert (priority == get_priority (i)); GNUNET_assert (anonymity == get_anonymity(i)); GNUNET_assert (expiration.value == get_expiration(i).value); + GNUNET_DATASTORE_get_next (datastore, GNUNET_YES); } @@ -237,6 +238,7 @@ delete_value (void *cls, crc->key = *key; crc->data = GNUNET_malloc (size); memcpy (crc->data, data, size); + GNUNET_DATASTORE_get_next (datastore, GNUNET_YES); } @@ -292,6 +294,7 @@ check_multiple (void *cls, crc->phase++; if (priority == get_priority (42)) crc->uid = uid; + GNUNET_DATASTORE_get_next (datastore, GNUNET_YES); } @@ -327,6 +330,7 @@ check_update (void *cls, } else GNUNET_assert (size == get_size (43)); + GNUNET_DATASTORE_get_next (datastore, GNUNET_YES); } diff --git a/src/datastore/test_datastore_api_management.c b/src/datastore/test_datastore_api_management.c index fadb77131..54289dd7b 100644 --- a/src/datastore/test_datastore_api_management.c +++ b/src/datastore/test_datastore_api_management.c @@ -186,6 +186,7 @@ check_value (void *cls, GNUNET_assert (priority == get_priority (i)); GNUNET_assert (anonymity == get_anonymity(i)); GNUNET_assert (expiration.value == get_expiration(i).value); + GNUNET_DATASTORE_get_next (datastore, GNUNET_YES); } diff --git a/src/include/gnunet_datastore_service.h b/src/include/gnunet_datastore_service.h index 7c1fd1961..bcc89a8e1 100644 --- a/src/include/gnunet_datastore_service.h +++ b/src/include/gnunet_datastore_service.h @@ -218,7 +218,10 @@ typedef void (*GNUNET_DATASTORE_Iterator) (void *cls, /** * Iterate over the results for a particular key - * in the datastore. + * in the datastore. The iterator will only be called + * once initially; if the first call did contain a + * result, further results can be obtained by calling + * "GNUNET_DATASTORE_get_next" with the given argument. * * @param h handle to the datastore * @param key maybe NULL (to match all entries) @@ -232,10 +235,24 @@ void GNUNET_DATASTORE_get (struct GNUNET_DATASTORE_Handle *h, const GNUNET_HashCode * key, uint32_t type, - GNUNET_DATASTORE_Iterator iter, void *iter_cls, + GNUNET_DATASTORE_Iterator iter, + void *iter_cls, struct GNUNET_TIME_Relative timeout); +/** + * Function called to trigger obtaining the next result + * from the datastore. + * + * @param h handle to the datastore + * @param more GNUNET_YES to get moxre results, GNUNET_NO to abort + * iteration (with a final call to "iter" with key/data == NULL). + */ +void +GNUNET_DATASTORE_get_next (struct GNUNET_DATASTORE_Handle *h, + int more); + + /** * Get a random value from the datastore. * -- 2.25.1