libgnunetdatacache.la
libgnunetdatacache_la_SOURCES = \
- datacache_api.c plugin_datacache.h
+ datacache.c plugin_datacache.h
libgnunetdatacache_la_LIBADD = \
$(top_builddir)/src/util/libgnunetutil.la \
$(GN_LIBINTL)
check_PROGRAMS = \
- test_datacache_api \
- test_datacache_api_quota \
- perf_datacache_api
+ test_datacache \
+ test_datacache_quota \
+ perf_datacache
TESTS = $(check_PROGRAMS)
-test_datacache_api_SOURCES = \
- test_datacache_api.c
-test_datacache_api_LDADD = \
+test_datacache_SOURCES = \
+ test_datacache.c
+test_datacache_LDADD = \
$(top_builddir)/src/datacache/libgnunetdatacache.la \
$(top_builddir)/src/util/libgnunetutil.la
-test_datacache_api_quota_SOURCES = \
- test_datacache_api_quota.c
-test_datacache_api_quota_LDADD = \
+test_datacache_quota_SOURCES = \
+ test_datacache_quota.c
+test_datacache_quota_LDADD = \
$(top_builddir)/src/datacache/libgnunetdatacache.la \
$(top_builddir)/src/util/libgnunetutil.la
-perf_datacache_api_SOURCES = \
- perf_datacache_api.c
-perf_datacache_api_LDADD = \
+perf_datacache_SOURCES = \
+ perf_datacache.c
+perf_datacache_LDADD = \
$(top_builddir)/src/datacache/libgnunetdatacache.la \
$(top_builddir)/src/util/libgnunetutil.la
EXTRA_DIST = \
- test_datacache_api_data.conf \
- perf_datacache_api_data.conf
+ test_datacache_data.conf \
+ perf_datacache_data.conf
--- /dev/null
+/*
+ This file is part of GNUnet
+ (C) 2004, 2005, 2006, 2007, 2009 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
+ by the Free Software Foundation; either version 2, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file datacache/datacache_api.c
+ * @brief datacache API implementation
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_datacache_lib.h"
+#include "plugin_datacache.h"
+
+/**
+ * Internal state of the datacache library.
+ */
+struct GNUNET_DATACACHE_Handle
+{
+
+ /**
+ * Our datastore plugin (NULL if not available).
+ */
+ struct DatastorePlugin *plugin;
+
+ /**
+ * Bloomfilter to quickly tell if we don't have the content.
+ */
+ struct GNUNET_CONTAINER_BloomFilter *filter;
+
+ /**
+ * Our configuration.
+ */
+ const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+ /**
+ * Configuration section to use.
+ */
+ char *section;
+
+ /**
+ * API of the transport as returned by the plugin's
+ * initialization function.
+ */
+ struct GNUNET_DATACACHE_PluginFunctions *api;
+
+ /**
+ * Short name for the plugin (i.e. "sqlite").
+ */
+ char *short_name;
+
+ /**
+ * Name of the library (i.e. "gnunet_plugin_datacache_sqlite").
+ */
+ char *lib_name;
+
+ /**
+ * Name for the bloom filter file.
+ */
+ char *bloom_name;
+
+ /**
+ * Environment provided to our plugin.
+ */
+ struct GNUNET_DATACACHE_PluginEnvironment env;
+
+ /**
+ * How much space is in use right now?
+ */
+ unsigned long long utilization;
+
+};
+
+
+/**
+ * Function called by plugins to notify the datacache
+ * about content deletions.
+ *
+ * @param cls closure
+ * @param key key of the content that was deleted
+ * @param size number of bytes that were made available
+ */
+static void
+env_delete_notify (void *cls,
+ const GNUNET_HashCode *key,
+ uint32_t size)
+{
+ struct GNUNET_DATACACHE_Handle * h = cls;
+ GNUNET_assert (h->utilization >= size);
+ h->utilization -= size;
+ GNUNET_CONTAINER_bloomfilter_remove (h->filter, key);
+}
+
+
+/**
+ * Create a data cache.
+ *
+ * @param sched scheduler to use
+ * @param cfg configuration to use
+ * @param section section in the configuration that contains our options
+ * @return handle to use to access the service
+ */
+struct GNUNET_DATACACHE_Handle *
+GNUNET_DATACACHE_create (struct GNUNET_SCHEDULER_Handle *sched,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section)
+{
+ int fd;
+ unsigned int bf_size;
+ unsigned long long quota;
+ struct GNUNET_DATACACHE_Handle *ret;
+ char *libname;
+ char *name;
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (cfg,
+ section, "QUOTA", "a))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("No `%s' specified for `%s' in configuration!\n"),
+ "QUOTA",
+ section);
+ return NULL;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ section,
+ "DATABASE", &name))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("No `%s' specified for `%s' in configuration!\n"),
+ "DATABASE",
+ section);
+ return NULL;
+ }
+ bf_size = quota / 32; /* 8 bit per entry, 1 bit per 32 kb in DB */
+
+ ret = GNUNET_malloc (sizeof(struct GNUNET_DATACACHE_Handle));
+ ret->bloom_name = GNUNET_strdup ("/tmp/datacachebloomXXXXXX");
+ fd = mkstemp (ret->bloom_name);
+ if (fd != -1)
+ {
+ ret->filter = GNUNET_CONTAINER_bloomfilter_load (ret->bloom_name,
+ quota / 1024, /* 8 bit per entry in DB, expect 1k entries */
+ 5);
+ CLOSE (fd);
+ }
+ else
+ {
+ ret->filter = GNUNET_CONTAINER_bloomfilter_load (NULL, bf_size, 5); /* approx. 3% false positives at max use */
+ }
+ ret->section = GNUNET_strdup (section);
+ ret->env.sched = sched;
+ ret->env.cfg = cfg;
+ ret->env.delete_notify = &env_delete_notify;
+ ret->env.section = ret->section;
+ ret->env.cls = ret;
+ ret->env.delete_notify = &env_delete_notify;
+ ret->env.quota = quota;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Loading `%s' datacache plugin\n"), name);
+ GNUNET_asprintf (&libname, "libgnunet_plugin_datacache_%s", name);
+ ret->short_name = name;
+ ret->lib_name = libname;
+ ret->api = GNUNET_PLUGIN_load (libname, &ret->env);
+ if (ret->api == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to load datacache plugin for `%s'\n"), name);
+ GNUNET_DATACACHE_destroy (ret);
+ return NULL;
+ }
+ return ret;
+}
+
+
+/**
+ * Destroy a data cache (and free associated resources).
+ *
+ * @param h handle to the datastore
+ */
+void GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h)
+{
+ if (h->filter != NULL)
+ GNUNET_CONTAINER_bloomfilter_free (h->filter);
+ if (h->api != NULL)
+ GNUNET_break (NULL == GNUNET_PLUGIN_unload (h->lib_name, h->api));
+ GNUNET_free (h->lib_name);
+ GNUNET_free (h->short_name);
+ GNUNET_free (h->section);
+ if (h->bloom_name != NULL)
+ {
+ UNLINK (h->bloom_name);
+ GNUNET_free (h->bloom_name);
+ }
+ GNUNET_free (h);
+}
+
+
+/**
+ * Store an item in the datastore.
+ *
+ * @param h handle to the datacache
+ * @param key key to store data under
+ * @param size number of bytes in data
+ * @param data data to store
+ * @param type type of the value
+ * @param discard_time when to discard the value in any case
+ * @return GNUNET_OK on success, GNUNET_SYSERR on error (full, etc.)
+ */
+int
+GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h,
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const char *data,
+ unsigned int type,
+ struct GNUNET_TIME_Absolute discard_time)
+{
+ uint32_t used;
+
+ used = h->api->put (h->api->cls,
+ key,
+ size,
+ data,
+ type,
+ discard_time);
+ if (used == 0)
+ return GNUNET_SYSERR;
+ GNUNET_CONTAINER_bloomfilter_add (h->filter, key);
+ while (h->utilization + used > h->env.quota)
+ GNUNET_assert (GNUNET_OK == h->api->del (h->api->cls));
+ h->utilization += used;
+ return GNUNET_OK;
+}
+
+
+/**
+ * Iterate over the results for a particular key
+ * in the datacache.
+ *
+ * @param h handle to the datacache
+ * @param key what to look up
+ * @param type entries of which type are relevant?
+ * @param iter maybe NULL (to just count)
+ * @param iter_cls closure for iter
+ * @return the number of results found
+ */
+unsigned int
+GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h,
+ const GNUNET_HashCode * key,
+ unsigned int type,
+ GNUNET_DATACACHE_Iterator iter,
+ void *iter_cls)
+{
+ if (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_test (h->filter,
+ key))
+ return 0; /* can not be present */
+ return h->api->get (h->api->cls,
+ key,
+ type,
+ iter,
+ iter_cls);
+}
+
+
+
+/* end of datacache_api.c */
+++ /dev/null
-/*
- This file is part of GNUnet
- (C) 2004, 2005, 2006, 2007, 2009 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
- by the Free Software Foundation; either version 2, or (at your
- option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-*/
-
-/**
- * @file datacache/datacache_api.c
- * @brief datacache API implementation
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_datacache_lib.h"
-#include "plugin_datacache.h"
-
-/**
- * Internal state of the datacache library.
- */
-struct GNUNET_DATACACHE_Handle
-{
-
- /**
- * Our datastore plugin (NULL if not available).
- */
- struct DatastorePlugin *plugin;
-
- /**
- * Bloomfilter to quickly tell if we don't have the content.
- */
- struct GNUNET_CONTAINER_BloomFilter *filter;
-
- /**
- * Our configuration.
- */
- const struct GNUNET_CONFIGURATION_Handle *cfg;
-
- /**
- * Configuration section to use.
- */
- char *section;
-
- /**
- * API of the transport as returned by the plugin's
- * initialization function.
- */
- struct GNUNET_DATACACHE_PluginFunctions *api;
-
- /**
- * Short name for the plugin (i.e. "sqlite").
- */
- char *short_name;
-
- /**
- * Name of the library (i.e. "gnunet_plugin_datacache_sqlite").
- */
- char *lib_name;
-
- /**
- * Name for the bloom filter file.
- */
- char *bloom_name;
-
- /**
- * Environment provided to our plugin.
- */
- struct GNUNET_DATACACHE_PluginEnvironment env;
-
- /**
- * How much space is in use right now?
- */
- unsigned long long utilization;
-
-};
-
-
-/**
- * Function called by plugins to notify the datacache
- * about content deletions.
- *
- * @param cls closure
- * @param key key of the content that was deleted
- * @param size number of bytes that were made available
- */
-static void
-env_delete_notify (void *cls,
- const GNUNET_HashCode *key,
- uint32_t size)
-{
- struct GNUNET_DATACACHE_Handle * h = cls;
- GNUNET_assert (h->utilization >= size);
- h->utilization -= size;
- GNUNET_CONTAINER_bloomfilter_remove (h->filter, key);
-}
-
-
-/**
- * Create a data cache.
- *
- * @param sched scheduler to use
- * @param cfg configuration to use
- * @param section section in the configuration that contains our options
- * @return handle to use to access the service
- */
-struct GNUNET_DATACACHE_Handle *
-GNUNET_DATACACHE_create (struct GNUNET_SCHEDULER_Handle *sched,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section)
-{
- int fd;
- unsigned int bf_size;
- unsigned long long quota;
- struct GNUNET_DATACACHE_Handle *ret;
- char *libname;
- char *name;
-
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
- section, "QUOTA", "a))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("No `%s' specified for `%s' in configuration!\n"),
- "QUOTA",
- section);
- return NULL;
- }
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- section,
- "DATABASE", &name))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("No `%s' specified for `%s' in configuration!\n"),
- "DATABASE",
- section);
- return NULL;
- }
- bf_size = quota / 32; /* 8 bit per entry, 1 bit per 32 kb in DB */
-
- ret = GNUNET_malloc (sizeof(struct GNUNET_DATACACHE_Handle));
- ret->bloom_name = GNUNET_strdup ("/tmp/datacachebloomXXXXXX");
- fd = mkstemp (ret->bloom_name);
- if (fd != -1)
- {
- ret->filter = GNUNET_CONTAINER_bloomfilter_load (ret->bloom_name,
- quota / 1024, /* 8 bit per entry in DB, expect 1k entries */
- 5);
- CLOSE (fd);
- }
- else
- {
- ret->filter = GNUNET_CONTAINER_bloomfilter_load (NULL, bf_size, 5); /* approx. 3% false positives at max use */
- }
- ret->section = GNUNET_strdup (section);
- ret->env.sched = sched;
- ret->env.cfg = cfg;
- ret->env.delete_notify = &env_delete_notify;
- ret->env.section = ret->section;
- ret->env.cls = ret;
- ret->env.delete_notify = &env_delete_notify;
- ret->env.quota = quota;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Loading `%s' datacache plugin\n"), name);
- GNUNET_asprintf (&libname, "libgnunet_plugin_datacache_%s", name);
- ret->short_name = name;
- ret->lib_name = libname;
- ret->api = GNUNET_PLUGIN_load (libname, &ret->env);
- if (ret->api == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to load datacache plugin for `%s'\n"), name);
- GNUNET_DATACACHE_destroy (ret);
- return NULL;
- }
- return ret;
-}
-
-
-/**
- * Destroy a data cache (and free associated resources).
- *
- * @param h handle to the datastore
- */
-void GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h)
-{
- if (h->filter != NULL)
- GNUNET_CONTAINER_bloomfilter_free (h->filter);
- if (h->api != NULL)
- GNUNET_break (NULL == GNUNET_PLUGIN_unload (h->lib_name, h->api));
- GNUNET_free (h->lib_name);
- GNUNET_free (h->short_name);
- GNUNET_free (h->section);
- if (h->bloom_name != NULL)
- {
- UNLINK (h->bloom_name);
- GNUNET_free (h->bloom_name);
- }
- GNUNET_free (h);
-}
-
-
-/**
- * Store an item in the datastore.
- *
- * @param h handle to the datacache
- * @param key key to store data under
- * @param size number of bytes in data
- * @param data data to store
- * @param type type of the value
- * @param discard_time when to discard the value in any case
- * @return GNUNET_OK on success, GNUNET_SYSERR on error (full, etc.)
- */
-int
-GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h,
- const GNUNET_HashCode * key,
- uint32_t size,
- const char *data,
- unsigned int type,
- struct GNUNET_TIME_Absolute discard_time)
-{
- uint32_t used;
-
- used = h->api->put (h->api->cls,
- key,
- size,
- data,
- type,
- discard_time);
- if (used == 0)
- return GNUNET_SYSERR;
- GNUNET_CONTAINER_bloomfilter_add (h->filter, key);
- while (h->utilization + used > h->env.quota)
- GNUNET_assert (GNUNET_OK == h->api->del (h->api->cls));
- h->utilization += used;
- return GNUNET_OK;
-}
-
-
-/**
- * Iterate over the results for a particular key
- * in the datacache.
- *
- * @param h handle to the datacache
- * @param key what to look up
- * @param type entries of which type are relevant?
- * @param iter maybe NULL (to just count)
- * @param iter_cls closure for iter
- * @return the number of results found
- */
-unsigned int
-GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h,
- const GNUNET_HashCode * key,
- unsigned int type,
- GNUNET_DATACACHE_Iterator iter,
- void *iter_cls)
-{
- if (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_test (h->filter,
- key))
- return 0; /* can not be present */
- return h->api->get (h->api->cls,
- key,
- type,
- iter,
- iter_cls);
-}
-
-
-
-/* end of datacache_api.c */
--- /dev/null
+/*
+ This file is part of GNUnet.
+ (C) 2006, 2009 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
+ by the Free Software Foundation; either version 2, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+/*
+ * @file datacache/perf_datacache.c
+ * @brief Performance evaluation for the datacache implementations.
+ * @author Nils Durner
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_datacache_lib.h"
+
+#define VERBOSE GNUNET_NO
+
+#define ASSERT(x) do { if (! (x)) { printf("Error at %s:%d\n", __FILE__, __LINE__); goto FAILURE;} } while (0)
+
+#define ITERATIONS 10000
+
+static int ok;
+
+static unsigned int found;
+
+static int
+checkIt (void *cls,
+ struct GNUNET_TIME_Absolute exp,
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const char *data,
+ uint32_t type)
+{
+ if ( (size == sizeof (GNUNET_HashCode)) &&
+ (0 == memcmp (data, cls, size)) )
+ found++;
+ return GNUNET_OK;
+}
+
+
+static void
+run (void *cls,
+ struct GNUNET_SCHEDULER_Handle *sched,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ struct GNUNET_DATACACHE_Handle *h;
+ GNUNET_HashCode k;
+ GNUNET_HashCode n;
+ struct GNUNET_TIME_Absolute exp;
+ struct GNUNET_TIME_Absolute start;
+ unsigned int i;
+
+ ok = 0;
+ h = GNUNET_DATACACHE_create (sched,
+ cfg,
+ "perfcache");
+
+ ASSERT (NULL != h);
+ exp = GNUNET_TIME_absolute_get ();
+ start = exp;
+ exp.value += 5 * 60 * 1000;
+ memset (&k, 0, sizeof (GNUNET_HashCode));
+ for (i = 0; i < ITERATIONS; i++)
+ {
+ if (0 == i % (ITERATIONS / 80))
+ fprintf (stderr, ".");
+ GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
+ ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h,
+ &k,
+ sizeof (GNUNET_HashCode),
+ (const char *) &n,
+ 1+i%16,
+ exp));
+ k = n;
+ }
+ fprintf (stderr, "\n");
+ fprintf (stdout, "Stored %u items in %llums\n",
+ ITERATIONS,
+ (unsigned long long) GNUNET_TIME_absolute_get_duration(start).value);
+ start = GNUNET_TIME_absolute_get ();
+ memset (&k, 0, sizeof (GNUNET_HashCode));
+ for (i = 0; i < ITERATIONS; i++)
+ {
+ if (0 == i % (ITERATIONS / 80))
+ fprintf (stderr, ".");
+ GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
+ GNUNET_DATACACHE_get (h, &k, 1+i%16,
+ &checkIt, &n);
+ k = n;
+ }
+ fprintf (stderr, "\n");
+ fprintf (stdout, "Found %u/%u items in %llums (%u were deleted during storage processing)\n",
+ found, ITERATIONS,
+ (unsigned long long) GNUNET_TIME_absolute_get_duration(start).value,
+ ITERATIONS - found);
+
+ GNUNET_DATACACHE_destroy (h);
+ ASSERT (ok == 0);
+ return;
+FAILURE:
+ if (h != NULL)
+ GNUNET_DATACACHE_destroy (h);
+ ok = GNUNET_SYSERR;
+}
+
+
+static int
+check ()
+{
+ char *const argv[] = { "perf-datacache-api",
+ "-c",
+ "perf_datacache_data.conf",
+#if VERBOSE
+ "-L", "DEBUG",
+#endif
+ NULL
+ };
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
+ GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
+ argv, "perf-datacache-api", "nohelp",
+ options, &run, NULL);
+ if (ok != 0)
+ fprintf (stderr, "Missed some perfcases: %d\n", ok);
+ return ok;
+}
+
+
+int
+main (int argc, char *argv[])
+{
+ int ret;
+
+ GNUNET_DISK_directory_remove ("/tmp/perf-gnunetd-datacache");
+ GNUNET_log_setup ("perf-datacache-api",
+#if VERBOSE
+ "DEBUG",
+#else
+ "WARNING",
+#endif
+ NULL);
+ ret = check ();
+
+ return ret;
+}
+
+/* end of perf_datacache.c */
+++ /dev/null
-/*
- This file is part of GNUnet.
- (C) 2006, 2009 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
- by the Free Software Foundation; either version 2, or (at your
- option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-*/
-/*
- * @file datacache/perf_datacache_api.c
- * @brief Performance evaluation for the datacache implementations.
- * @author Nils Durner
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_datacache_lib.h"
-
-#define VERBOSE GNUNET_NO
-
-#define ASSERT(x) do { if (! (x)) { printf("Error at %s:%d\n", __FILE__, __LINE__); goto FAILURE;} } while (0)
-
-#define ITERATIONS 10000
-
-static int ok;
-
-static unsigned int found;
-
-static int
-checkIt (void *cls,
- struct GNUNET_TIME_Absolute exp,
- const GNUNET_HashCode * key,
- uint32_t size,
- const char *data,
- uint32_t type)
-{
- if ( (size == sizeof (GNUNET_HashCode)) &&
- (0 == memcmp (data, cls, size)) )
- found++;
- return GNUNET_OK;
-}
-
-
-static void
-run (void *cls,
- struct GNUNET_SCHEDULER_Handle *sched,
- char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- struct GNUNET_DATACACHE_Handle *h;
- GNUNET_HashCode k;
- GNUNET_HashCode n;
- struct GNUNET_TIME_Absolute exp;
- struct GNUNET_TIME_Absolute start;
- unsigned int i;
-
- ok = 0;
- h = GNUNET_DATACACHE_create (sched,
- cfg,
- "perfcache");
-
- ASSERT (NULL != h);
- exp = GNUNET_TIME_absolute_get ();
- start = exp;
- exp.value += 5 * 60 * 1000;
- memset (&k, 0, sizeof (GNUNET_HashCode));
- for (i = 0; i < ITERATIONS; i++)
- {
- if (0 == i % (ITERATIONS / 80))
- fprintf (stderr, ".");
- GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
- ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h,
- &k,
- sizeof (GNUNET_HashCode),
- (const char *) &n,
- 1+i%16,
- exp));
- k = n;
- }
- fprintf (stderr, "\n");
- fprintf (stdout, "Stored %u items in %llums\n",
- ITERATIONS,
- (unsigned long long) GNUNET_TIME_absolute_get_duration(start).value);
- start = GNUNET_TIME_absolute_get ();
- memset (&k, 0, sizeof (GNUNET_HashCode));
- for (i = 0; i < ITERATIONS; i++)
- {
- if (0 == i % (ITERATIONS / 80))
- fprintf (stderr, ".");
- GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
- GNUNET_DATACACHE_get (h, &k, 1+i%16,
- &checkIt, &n);
- k = n;
- }
- fprintf (stderr, "\n");
- fprintf (stdout, "Found %u/%u items in %llums (%u were deleted during storage processing)\n",
- found, ITERATIONS,
- (unsigned long long) GNUNET_TIME_absolute_get_duration(start).value,
- ITERATIONS - found);
-
- GNUNET_DATACACHE_destroy (h);
- ASSERT (ok == 0);
- return;
-FAILURE:
- if (h != NULL)
- GNUNET_DATACACHE_destroy (h);
- ok = GNUNET_SYSERR;
-}
-
-
-static int
-check ()
-{
- char *const argv[] = { "perf-datacache-api",
- "-c",
- "perf_datacache_api_data.conf",
-#if VERBOSE
- "-L", "DEBUG",
-#endif
- NULL
- };
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_OPTION_END
- };
- GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "perf-datacache-api", "nohelp",
- options, &run, NULL);
- if (ok != 0)
- fprintf (stderr, "Missed some perfcases: %d\n", ok);
- return ok;
-}
-
-
-int
-main (int argc, char *argv[])
-{
- int ret;
-
- GNUNET_DISK_directory_remove ("/tmp/perf-gnunetd-datacache");
- GNUNET_log_setup ("perf-datacache-api",
-#if VERBOSE
- "DEBUG",
-#else
- "WARNING",
-#endif
- NULL);
- ret = check ();
-
- return ret;
-}
-
-/* end of perf_datacache_api.c */
+++ /dev/null
-
-[perfcache]
-QUOTA = 500000
-DATABASE = sqlite
--- /dev/null
+
+[perfcache]
+QUOTA = 500000
+DATABASE = sqlite
--- /dev/null
+/*
+ This file is part of GNUnet.
+ (C) 2006, 2009 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
+ by the Free Software Foundation; either version 2, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+/*
+ * @file datacache/test_datacache.c
+ * @brief Test for the datacache implementations.
+ * @author Nils Durner
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_datacache_lib.h"
+
+#define VERBOSE GNUNET_NO
+
+#define ASSERT(x) do { if (! (x)) { printf("Error at %s:%d\n", __FILE__, __LINE__); goto FAILURE;} } while (0)
+
+static int ok;
+
+
+static int
+checkIt (void *cls,
+ struct GNUNET_TIME_Absolute exp,
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const char *data,
+ uint32_t type)
+{
+ if (size != sizeof (GNUNET_HashCode))
+ {
+ printf ("ERROR: Invalid size\n");
+ ok = 2;
+ }
+ if (0 != memcmp (data, cls, size))
+ {
+ printf ("ERROR: Invalid data\n");
+ ok = 3;
+ }
+ return GNUNET_OK;
+}
+
+
+static void
+run (void *cls,
+ struct GNUNET_SCHEDULER_Handle *sched,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ struct GNUNET_DATACACHE_Handle *h;
+ GNUNET_HashCode k;
+ GNUNET_HashCode n;
+ struct GNUNET_TIME_Absolute exp;
+ unsigned int i;
+
+ ok = 0;
+ h = GNUNET_DATACACHE_create (sched,
+ cfg,
+ "testcache");
+
+ ASSERT (NULL != h);
+ exp = GNUNET_TIME_absolute_get ();
+ exp.value += 5 * 60 * 1000;
+ memset (&k, 0, sizeof (GNUNET_HashCode));
+ for (i = 0; i < 100; i++)
+ {
+ GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
+ ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h,
+ &k,
+ sizeof (GNUNET_HashCode),
+ (const char *) &n,
+ 1+i%16,
+ exp));
+ k = n;
+ }
+ memset (&k, 0, sizeof (GNUNET_HashCode));
+ for (i = 0; i < 100; i++)
+ {
+ GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
+ ASSERT (1 ==
+ GNUNET_DATACACHE_get (h, &k, 1+i%16,
+ &checkIt, &n));
+ k = n;
+ }
+ GNUNET_DATACACHE_destroy (h);
+ ASSERT (ok == 0);
+ return;
+FAILURE:
+ if (h != NULL)
+ GNUNET_DATACACHE_destroy (h);
+ ok = GNUNET_SYSERR;
+}
+
+
+static int
+check ()
+{
+ char *const argv[] = { "test-datacache-api",
+ "-c",
+ "test_datacache_data.conf",
+#if VERBOSE
+ "-L", "DEBUG",
+#endif
+ NULL
+ };
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
+ GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
+ argv, "test-datacache-api", "nohelp",
+ options, &run, NULL);
+ if (ok != 0)
+ fprintf (stderr, "Missed some testcases: %d\n", ok);
+ return ok;
+}
+
+
+int
+main (int argc, char *argv[])
+{
+ int ret;
+
+ GNUNET_log_setup ("test-datacache-api",
+#if VERBOSE
+ "DEBUG",
+#else
+ "WARNING",
+#endif
+ NULL);
+ ret = check ();
+
+ return ret;
+}
+
+/* end of test_datacache.c */
+++ /dev/null
-/*
- This file is part of GNUnet.
- (C) 2006, 2009 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
- by the Free Software Foundation; either version 2, or (at your
- option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-*/
-/*
- * @file datacache/test_datacache_api.c
- * @brief Test for the datacache implementations.
- * @author Nils Durner
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_datacache_lib.h"
-
-#define VERBOSE GNUNET_NO
-
-#define ASSERT(x) do { if (! (x)) { printf("Error at %s:%d\n", __FILE__, __LINE__); goto FAILURE;} } while (0)
-
-static int ok;
-
-
-static int
-checkIt (void *cls,
- struct GNUNET_TIME_Absolute exp,
- const GNUNET_HashCode * key,
- uint32_t size,
- const char *data,
- uint32_t type)
-{
- if (size != sizeof (GNUNET_HashCode))
- {
- printf ("ERROR: Invalid size\n");
- ok = 2;
- }
- if (0 != memcmp (data, cls, size))
- {
- printf ("ERROR: Invalid data\n");
- ok = 3;
- }
- return GNUNET_OK;
-}
-
-
-static void
-run (void *cls,
- struct GNUNET_SCHEDULER_Handle *sched,
- char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- struct GNUNET_DATACACHE_Handle *h;
- GNUNET_HashCode k;
- GNUNET_HashCode n;
- struct GNUNET_TIME_Absolute exp;
- unsigned int i;
-
- ok = 0;
- h = GNUNET_DATACACHE_create (sched,
- cfg,
- "testcache");
-
- ASSERT (NULL != h);
- exp = GNUNET_TIME_absolute_get ();
- exp.value += 5 * 60 * 1000;
- memset (&k, 0, sizeof (GNUNET_HashCode));
- for (i = 0; i < 100; i++)
- {
- GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
- ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h,
- &k,
- sizeof (GNUNET_HashCode),
- (const char *) &n,
- 1+i%16,
- exp));
- k = n;
- }
- memset (&k, 0, sizeof (GNUNET_HashCode));
- for (i = 0; i < 100; i++)
- {
- GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
- ASSERT (1 ==
- GNUNET_DATACACHE_get (h, &k, 1+i%16,
- &checkIt, &n));
- k = n;
- }
- GNUNET_DATACACHE_destroy (h);
- ASSERT (ok == 0);
- return;
-FAILURE:
- if (h != NULL)
- GNUNET_DATACACHE_destroy (h);
- ok = GNUNET_SYSERR;
-}
-
-
-static int
-check ()
-{
- char *const argv[] = { "test-datacache-api",
- "-c",
- "test_datacache_api_data.conf",
-#if VERBOSE
- "-L", "DEBUG",
-#endif
- NULL
- };
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_OPTION_END
- };
- GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-datacache-api", "nohelp",
- options, &run, NULL);
- if (ok != 0)
- fprintf (stderr, "Missed some testcases: %d\n", ok);
- return ok;
-}
-
-
-int
-main (int argc, char *argv[])
-{
- int ret;
-
- GNUNET_log_setup ("test-datacache-api",
-#if VERBOSE
- "DEBUG",
-#else
- "WARNING",
-#endif
- NULL);
- ret = check ();
-
- return ret;
-}
-
-/* end of test_datacache_api.c */
+++ /dev/null
-
-[testcache]
-QUOTA = 1000000
-DATABASE = sqlite
+++ /dev/null
-/*
- This file is part of GNUnet.
- (C) 2006, 2009 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
- by the Free Software Foundation; either version 2, or (at your
- option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-*/
-/*
- * @file datacache/test_datacache_api_quota.c
- * @brief Test for the quota code of the datacache implementations.
- * @author Nils Durner
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_datacache_lib.h"
-
-#define VERBOSE GNUNET_NO
-
-#define ASSERT(x) do { if (! (x)) { printf("Error at %s:%d\n", __FILE__, __LINE__); goto FAILURE;} } while (0)
-
-static int ok;
-
-/**
- * Quota is 1 MB. Each iteration of the test puts in about 1 MB of
- * data. We do 10 iterations. Afterwards we check that the data from
- * the first 5 iterations has all been discarded and that at least
- * some of the data from the last iteration is still there.
- */
-static void
-run (void *cls,
- struct GNUNET_SCHEDULER_Handle *sched,
- char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- struct GNUNET_DATACACHE_Handle *h;
- GNUNET_HashCode k;
- GNUNET_HashCode n;
- unsigned int i;
- unsigned int j;
- char buf[3200];
- struct GNUNET_TIME_Absolute exp;
-
- ok = 0;
- h = GNUNET_DATACACHE_create (sched,
- cfg,
- "testcache");
-
- ASSERT (NULL != h);
- exp = GNUNET_TIME_absolute_get ();
- exp.value += 5 * 60 * 1000;
- memset (buf, 1, sizeof (buf));
- memset (&k, 0, sizeof (GNUNET_HashCode));
- for (i = 0; i < 10; i++)
- {
- fprintf (stderr, ".");
- GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
- for (j = i; j < sizeof (buf); j += 10)
- {
- exp.value++;
- buf[j] = i;
- ASSERT (GNUNET_OK ==
- GNUNET_DATACACHE_put (h,
- &k,
- j,
- buf,
- 1+i,
- exp));
- ASSERT (0 < GNUNET_DATACACHE_get (h,
- &k, 1+i,
- NULL, NULL));
- }
- k = n;
- }
- fprintf (stderr, "\n");
- memset (&k, 0, sizeof (GNUNET_HashCode));
- for (i = 0; i < 10; i++)
- {
- fprintf (stderr, ".");
- GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
- if (i < 2)
- ASSERT (0 == GNUNET_DATACACHE_get (h,
- &k, 1+i,
- NULL, NULL));
- if (i == 9)
- ASSERT (0 < GNUNET_DATACACHE_get (h,
- &k, 1+i,
- NULL, NULL));
- k = n;
- }
- fprintf (stderr, "\n");
- return;
-FAILURE:
- if (h != NULL)
- GNUNET_DATACACHE_destroy (h);
- ok = GNUNET_SYSERR;
-}
-
-
-static int
-check ()
-{
- char *const argv[] = { "test-datacache-api-quota",
- "-c",
- "test_datacache_api_data.conf",
-#if VERBOSE
- "-L", "DEBUG",
-#endif
- NULL
- };
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_OPTION_END
- };
- GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-datacache-api-quota", "nohelp",
- options, &run, NULL);
- if (ok != 0)
- fprintf (stderr, "Missed some testcases: %d\n", ok);
- return ok;
-}
-
-
-int
-main (int argc, char *argv[])
-{
- int ret;
-
- GNUNET_log_setup ("test-datacache-api-quota",
-#if VERBOSE
- "DEBUG",
-#else
- "WARNING",
-#endif
- NULL);
- ret = check ();
-
- return ret;
-}
-
-/* end of test_datacache_api_quota.c */
--- /dev/null
+
+[testcache]
+QUOTA = 1000000
+DATABASE = sqlite
--- /dev/null
+/*
+ This file is part of GNUnet.
+ (C) 2006, 2009 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
+ by the Free Software Foundation; either version 2, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+/*
+ * @file datacache/test_datacache_quota.c
+ * @brief Test for the quota code of the datacache implementations.
+ * @author Nils Durner
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_datacache_lib.h"
+
+#define VERBOSE GNUNET_NO
+
+#define ASSERT(x) do { if (! (x)) { printf("Error at %s:%d\n", __FILE__, __LINE__); goto FAILURE;} } while (0)
+
+static int ok;
+
+/**
+ * Quota is 1 MB. Each iteration of the test puts in about 1 MB of
+ * data. We do 10 iterations. Afterwards we check that the data from
+ * the first 5 iterations has all been discarded and that at least
+ * some of the data from the last iteration is still there.
+ */
+static void
+run (void *cls,
+ struct GNUNET_SCHEDULER_Handle *sched,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ struct GNUNET_DATACACHE_Handle *h;
+ GNUNET_HashCode k;
+ GNUNET_HashCode n;
+ unsigned int i;
+ unsigned int j;
+ char buf[3200];
+ struct GNUNET_TIME_Absolute exp;
+
+ ok = 0;
+ h = GNUNET_DATACACHE_create (sched,
+ cfg,
+ "testcache");
+
+ ASSERT (NULL != h);
+ exp = GNUNET_TIME_absolute_get ();
+ exp.value += 5 * 60 * 1000;
+ memset (buf, 1, sizeof (buf));
+ memset (&k, 0, sizeof (GNUNET_HashCode));
+ for (i = 0; i < 10; i++)
+ {
+ fprintf (stderr, ".");
+ GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
+ for (j = i; j < sizeof (buf); j += 10)
+ {
+ exp.value++;
+ buf[j] = i;
+ ASSERT (GNUNET_OK ==
+ GNUNET_DATACACHE_put (h,
+ &k,
+ j,
+ buf,
+ 1+i,
+ exp));
+ ASSERT (0 < GNUNET_DATACACHE_get (h,
+ &k, 1+i,
+ NULL, NULL));
+ }
+ k = n;
+ }
+ fprintf (stderr, "\n");
+ memset (&k, 0, sizeof (GNUNET_HashCode));
+ for (i = 0; i < 10; i++)
+ {
+ fprintf (stderr, ".");
+ GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
+ if (i < 2)
+ ASSERT (0 == GNUNET_DATACACHE_get (h,
+ &k, 1+i,
+ NULL, NULL));
+ if (i == 9)
+ ASSERT (0 < GNUNET_DATACACHE_get (h,
+ &k, 1+i,
+ NULL, NULL));
+ k = n;
+ }
+ fprintf (stderr, "\n");
+ return;
+FAILURE:
+ if (h != NULL)
+ GNUNET_DATACACHE_destroy (h);
+ ok = GNUNET_SYSERR;
+}
+
+
+static int
+check ()
+{
+ char *const argv[] = { "test-datacache-api-quota",
+ "-c",
+ "test_datacache_data.conf",
+#if VERBOSE
+ "-L", "DEBUG",
+#endif
+ NULL
+ };
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
+ GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
+ argv, "test-datacache-api-quota", "nohelp",
+ options, &run, NULL);
+ if (ok != 0)
+ fprintf (stderr, "Missed some testcases: %d\n", ok);
+ return ok;
+}
+
+
+int
+main (int argc, char *argv[])
+{
+ int ret;
+
+ GNUNET_log_setup ("test-datacache-api-quota",
+#if VERBOSE
+ "DEBUG",
+#else
+ "WARNING",
+#endif
+ NULL);
+ ret = check ();
+
+ return ret;
+}
+
+/* end of test_datacache_quota.c */