aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/test_plugin_namestore.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-04-25 16:18:31 +0200
committerChristian Grothoff <christian@grothoff.org>2018-04-25 16:18:31 +0200
commit4dc79497d7f745996068e62e973e34d220580323 (patch)
treee6d429d3cf2240ec3459f1d4533201dc40b27015 /src/namestore/test_plugin_namestore.c
parentbdbb7c684f2c9711989d2543ecc08a95be23e6c4 (diff)
extend namestore API to enable faster iterations by returning more than one result at a time
Diffstat (limited to 'src/namestore/test_plugin_namestore.c')
-rw-r--r--src/namestore/test_plugin_namestore.c82
1 files changed, 56 insertions, 26 deletions
diff --git a/src/namestore/test_plugin_namestore.c b/src/namestore/test_plugin_namestore.c
index aa5d10809e..d591eb3255 100644
--- a/src/namestore/test_plugin_namestore.c
+++ b/src/namestore/test_plugin_namestore.c
@@ -47,8 +47,12 @@ unload_plugin (struct GNUNET_NAMESTORE_PluginFunctions *api)
{
char *libname;
- GNUNET_asprintf (&libname, "libgnunet_plugin_namestore_%s", plugin_name);
- GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api));
+ GNUNET_asprintf (&libname,
+ "libgnunet_plugin_namestore_%s",
+ plugin_name);
+ GNUNET_break (NULL ==
+ GNUNET_PLUGIN_unload (libname,
+ api));
GNUNET_free (libname);
}
@@ -65,12 +69,17 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
struct GNUNET_NAMESTORE_PluginFunctions *ret;
char *libname;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' namestore plugin\n"),
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Loading `%s' namestore plugin\n"),
plugin_name);
- GNUNET_asprintf (&libname, "libgnunet_plugin_namestore_%s", plugin_name);
+ GNUNET_asprintf (&libname,
+ "libgnunet_plugin_namestore_%s",
+ plugin_name);
if (NULL == (ret = GNUNET_PLUGIN_load (libname, (void*) cfg)))
{
- FPRINTF (stderr, "Failed to load plugin `%s'!\n", plugin_name);
+ FPRINTF (stderr,
+ "Failed to load plugin `%s'!\n",
+ plugin_name);
GNUNET_free (libname);
return NULL;
}
@@ -81,21 +90,22 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
static void
test_record (void *cls,
- const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key,
- const char *label,
- unsigned int rd_count,
- const struct GNUNET_GNSRECORD_Data *rd)
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key,
+ const char *label,
+ unsigned int rd_count,
+ const struct GNUNET_GNSRECORD_Data *rd)
{
int *idp = cls;
int id = *idp;
struct GNUNET_CRYPTO_EcdsaPrivateKey tzone_private_key;
char tname[64];
unsigned int trd_count = 1 + (id % 1024);
- unsigned int i;
- GNUNET_snprintf (tname, sizeof (tname),
- "a%u", (unsigned int ) id);
- for (i=0;i<trd_count;i++)
+ GNUNET_snprintf (tname,
+ sizeof (tname),
+ "a%u",
+ (unsigned int ) id);
+ for (unsigned int i=0;i<trd_count;i++)
{
GNUNET_assert (rd[i].data_size == id % 10);
GNUNET_assert (0 == memcmp ("Hello World", rd[i].data, id % 10));
@@ -104,31 +114,39 @@ test_record (void *cls,
}
memset (&tzone_private_key, (id % 241), sizeof (tzone_private_key));
GNUNET_assert (0 == strcmp (label, tname));
- GNUNET_assert (0 == memcmp (&tzone_private_key, private_key, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)));
+ GNUNET_assert (0 == memcmp (&tzone_private_key,
+ private_key,
+ sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)));
}
static void
-get_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id)
+get_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp,
+ int id)
{
- GNUNET_assert (GNUNET_OK == nsp->iterate_records (nsp->cls,
- NULL, 0, &test_record, &id));
+ GNUNET_assert (GNUNET_OK ==
+ nsp->iterate_records (nsp->cls,
+ NULL,
+ 0,
+ 1,
+ &test_record,
+ &id));
}
static void
-put_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id)
+put_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp,
+ int id)
{
struct GNUNET_CRYPTO_EcdsaPrivateKey zone_private_key;
char label[64];
unsigned int rd_count = 1 + (id % 1024);
struct GNUNET_GNSRECORD_Data rd[rd_count];
struct GNUNET_CRYPTO_EcdsaSignature signature;
- unsigned int i;
GNUNET_snprintf (label, sizeof (label),
"a%u", (unsigned int ) id);
- for (i=0;i<rd_count;i++)
+ for (unsigned int i=0;i<rd_count;i++)
{
rd[i].data = "Hello World";
rd[i].data_size = id % 10;
@@ -147,7 +165,9 @@ put_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id)
static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct GNUNET_NAMESTORE_PluginFunctions *nsp;
@@ -169,7 +189,8 @@ run (void *cls, char *const *args, const char *cfgfile,
int
-main (int argc, char *argv[])
+main (int argc,
+ char *argv[])
{
char cfg_name[128];
char *const xargv[] = {
@@ -187,12 +208,21 @@ main (int argc, char *argv[])
"WARNING",
NULL);
plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
- GNUNET_snprintf (cfg_name, sizeof (cfg_name), "test_plugin_namestore_%s.conf",
+ GNUNET_snprintf (cfg_name,
+ sizeof (cfg_name),
+ "test_plugin_namestore_%s.conf",
plugin_name);
- GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv,
- "test-plugin-namestore", "nohelp", options, &run, NULL);
+ GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1,
+ xargv,
+ "test-plugin-namestore",
+ "nohelp",
+ options,
+ &run,
+ NULL);
if (ok != 0)
- FPRINTF (stderr, "Missed some testcases: %d\n", ok);
+ FPRINTF (stderr,
+ "Missed some testcases: %d\n",
+ ok);
//GNUNET_DISK_directory_remove ("/tmp/gnunet-test-plugin-namestore-sqlite");
return ok;
}