#include "gnunet_protocols.h"
#include "gnunet_datastore_service.h"
-static struct GNUNET_DATASTORE_Handle *datastore;
+#define VERBOSE GNUNET_YES
/**
* How long until we give up on transmitting the message?
*/
#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
+
+static struct GNUNET_DATASTORE_Handle *datastore;
+
/**
* Target datastore size (in bytes).
* <p>
int success,
const char *msg)
{
+ struct CpsRunContext *crc = cls;
+
static int dc;
dc++;
#if REPORT_ID
fprintf (stderr, "D");
#endif
GNUNET_assert (GNUNET_OK == success);
+ GNUNET_SCHEDULER_add_continuation (crc->sched,
+ GNUNET_NO,
+ &run_continuation,
+ crc,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
{
struct CpsRunContext *crc = cls;
+ stored_bytes -= crc->esize;
+ stored_entries--;
GNUNET_DATASTORE_remove (datastore,
&crc->key,
crc->esize,
{
struct CpsRunContext *crc = cls;
- if (stored_bytes < MAX_SIZE)
- return;
if (key == NULL)
{
crc->phase = RP_REPORT;
- GNUNET_SCHEDULER_add_continuation (crc->sched,
- GNUNET_NO,
- &run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ if (stored_bytes < MAX_SIZE)
+ {
+ GNUNET_SCHEDULER_add_continuation (crc->sched,
+ GNUNET_NO,
+ &run_continuation,
+ crc,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ return;
+ }
+ GNUNET_SCHEDULER_add_after (crc->sched,
+ GNUNET_NO,
+ GNUNET_SCHEDULER_PRIORITY_HIGH,
+ GNUNET_SCHEDULER_NO_PREREQUISITE_TASK,
+ &do_delete,
+ crc);
return;
}
- stored_bytes -= size;
- stored_entries--;
+ if (stored_bytes < MAX_SIZE)
+ return;
crc->key = *key;
crc->esize = size;
memcpy (crc->data, data, size);
- GNUNET_SCHEDULER_add_after (crc->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_HIGH,
- GNUNET_SCHEDULER_NO_PREREQUISITE_TASK,
- &do_delete,
- crc);
}
&key,
size,
data,
- i,
+ i+1,
GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100),
i,
GNUNET_TIME_relative_to_absolute
{
int ret;
+ GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-datastore");
GNUNET_log_setup ("perf-datastore-api",
#if VERBOSE
"DEBUG",
#include "gnunet_protocols.h"
#include "gnunet_datastore_service.h"
-#define VERBOSE GNUNET_YES
+#define VERBOSE GNUNET_NO
/**
* How long until we give up on transmitting the message?
RP_PUT,
RP_GET,
RP_DEL,
+ RP_DO_DEL,
RP_DELVALIDATE
};
int *iptr;
struct GNUNET_SCHEDULER_Handle *sched;
struct GNUNET_CONFIGURATION_Handle *cfg;
+ void *data;
+ size_t size;
enum RunPhase phase;
};
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"%s\n", msg);
GNUNET_assert (GNUNET_OK == success);
- GNUNET_SCHEDULER_add_continuation (crc->sched,
- GNUNET_NO,
- &run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
-}
-
-
-static void
-check_failure (void *cls,
- int success,
- const char *msg)
-{
- struct CpsRunContext *crc = cls;
- GNUNET_assert (GNUNET_OK != success);
- GNUNET_assert (NULL != msg);
+ GNUNET_free_non_null (crc->data);
+ crc->data = NULL;
GNUNET_SCHEDULER_add_continuation (crc->sched,
GNUNET_NO,
&run_continuation,
int i;
if (key == NULL)
- return;
+ {
+ if (crc->i == 0)
+ {
+ crc->phase = RP_DEL;
+ crc->i = ITERATIONS;
+ }
+ GNUNET_SCHEDULER_add_continuation (crc->sched,
+ GNUNET_NO,
+ &run_continuation,
+ crc,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ return;
+ }
i = crc->i;
GNUNET_assert (size == get_size (i));
GNUNET_assert (0 == memcmp (data, get_data(i), size));
GNUNET_assert (priority == get_priority (i));
GNUNET_assert (anonymity == get_anonymity(i));
GNUNET_assert (expiration.value == get_expiration(i).value);
- GNUNET_SCHEDULER_add_continuation (crc->sched,
- GNUNET_NO,
- &run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
{
struct CpsRunContext *crc = cls;
if (key == NULL)
- return;
- GNUNET_DATASTORE_remove (datastore,
- key,
- size,
- data,
- &check_success,
- NULL,
- TIMEOUT);
- ((int*)key)[0]++;
- GNUNET_DATASTORE_remove (datastore,
- key,
- size,
- data,
- &check_failure,
- NULL,
- TIMEOUT);
- GNUNET_SCHEDULER_add_continuation (crc->sched,
- GNUNET_NO,
- &run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ {
+ crc->phase = RP_DO_DEL;
+ GNUNET_SCHEDULER_add_continuation (crc->sched,
+ GNUNET_NO,
+ &run_continuation,
+ crc,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ return;
+ }
+ GNUNET_assert (crc->data == NULL);
+ crc->size = size;
+ crc->key = *key;
+ crc->data = GNUNET_malloc (size);
+ memcpy (crc->data, data, size);
}
-
static void
check_nothing (void *cls,
const GNUNET_HashCode * key,
{
struct CpsRunContext *crc = cls;
GNUNET_assert (key == NULL);
+ if (crc->i == 0)
+ {
+ crc->phase = RP_DONE;
+ }
GNUNET_SCHEDULER_add_continuation (crc->sched,
GNUNET_NO,
&run_continuation,
"PUT",
crc->i);
#endif
- memset (&crc->key, ITERATIONS - crc->i, sizeof (GNUNET_HashCode));
+ GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
GNUNET_DATASTORE_put (datastore,
0,
&crc->key,
"GET",
crc->i);
#endif
- memset (&crc->key, ITERATIONS - crc->i, sizeof (GNUNET_HashCode));
+ GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
GNUNET_DATASTORE_get (datastore,
&crc->key,
get_type (crc->i),
&check_value,
crc,
TIMEOUT);
- if (crc->i == 0)
- {
- crc->phase = RP_DEL;
- crc->i = ITERATIONS;
- }
break;
case RP_DEL:
crc->i--;
"DEL",
crc->i);
#endif
- memset (&crc->key, ITERATIONS - crc->i, sizeof (GNUNET_HashCode));
+ GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
GNUNET_DATASTORE_get (datastore,
&crc->key,
get_type (crc->i),
&delete_value,
crc,
TIMEOUT);
+ break;
+ case RP_DO_DEL:
+#if VERBOSE
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Executing `%s' number %u\n",
+ "DO_DEL",
+ crc->i);
+#endif
if (crc->i == 0)
{
- crc->phase = RP_DELVALIDATE;
crc->i = ITERATIONS;
+ crc->phase = RP_DELVALIDATE;
+ }
+ else
+ {
+ crc->phase = RP_DEL;
}
- break;
+ GNUNET_DATASTORE_remove (datastore,
+ &crc->key,
+ crc->size,
+ crc->data,
+ &check_success,
+ crc,
+ TIMEOUT);
+ break;
case RP_DELVALIDATE:
crc->i--;
#if VERBOSE
"DEL-VALIDATE",
crc->i);
#endif
- memset (&crc->key, ITERATIONS - crc->i, sizeof (GNUNET_HashCode));
+ GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
GNUNET_DATASTORE_get (datastore,
&crc->key,
get_type (crc->i),
&check_nothing,
crc,
TIMEOUT);
- if (crc->i == 0)
- {
- crc->phase = RP_DONE;
- }
break;
/* check reservations */
/* check update */
main (int argc, char *argv[])
{
int ret;
-
+
+ GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-datastore");
GNUNET_log_setup ("test-datastore-api",
#if VERBOSE
"DEBUG",