diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-04-25 16:18:31 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-04-25 16:18:31 +0200 |
commit | 4dc79497d7f745996068e62e973e34d220580323 (patch) | |
tree | e6d429d3cf2240ec3459f1d4533201dc40b27015 /src/namestore/test_plugin_namestore.c | |
parent | bdbb7c684f2c9711989d2543ecc08a95be23e6c4 (diff) | |
download | gnunet-4dc79497d7f745996068e62e973e34d220580323.tar.gz gnunet-4dc79497d7f745996068e62e973e34d220580323.zip |
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.c | 82 |
1 files changed, 56 insertions, 26 deletions
diff --git a/src/namestore/test_plugin_namestore.c b/src/namestore/test_plugin_namestore.c index aa5d10809..d591eb325 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) | |||
47 | { | 47 | { |
48 | char *libname; | 48 | char *libname; |
49 | 49 | ||
50 | GNUNET_asprintf (&libname, "libgnunet_plugin_namestore_%s", plugin_name); | 50 | GNUNET_asprintf (&libname, |
51 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api)); | 51 | "libgnunet_plugin_namestore_%s", |
52 | plugin_name); | ||
53 | GNUNET_break (NULL == | ||
54 | GNUNET_PLUGIN_unload (libname, | ||
55 | api)); | ||
52 | GNUNET_free (libname); | 56 | GNUNET_free (libname); |
53 | } | 57 | } |
54 | 58 | ||
@@ -65,12 +69,17 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
65 | struct GNUNET_NAMESTORE_PluginFunctions *ret; | 69 | struct GNUNET_NAMESTORE_PluginFunctions *ret; |
66 | char *libname; | 70 | char *libname; |
67 | 71 | ||
68 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' namestore plugin\n"), | 72 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
73 | _("Loading `%s' namestore plugin\n"), | ||
69 | plugin_name); | 74 | plugin_name); |
70 | GNUNET_asprintf (&libname, "libgnunet_plugin_namestore_%s", plugin_name); | 75 | GNUNET_asprintf (&libname, |
76 | "libgnunet_plugin_namestore_%s", | ||
77 | plugin_name); | ||
71 | if (NULL == (ret = GNUNET_PLUGIN_load (libname, (void*) cfg))) | 78 | if (NULL == (ret = GNUNET_PLUGIN_load (libname, (void*) cfg))) |
72 | { | 79 | { |
73 | FPRINTF (stderr, "Failed to load plugin `%s'!\n", plugin_name); | 80 | FPRINTF (stderr, |
81 | "Failed to load plugin `%s'!\n", | ||
82 | plugin_name); | ||
74 | GNUNET_free (libname); | 83 | GNUNET_free (libname); |
75 | return NULL; | 84 | return NULL; |
76 | } | 85 | } |
@@ -81,21 +90,22 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
81 | 90 | ||
82 | static void | 91 | static void |
83 | test_record (void *cls, | 92 | test_record (void *cls, |
84 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key, | 93 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key, |
85 | const char *label, | 94 | const char *label, |
86 | unsigned int rd_count, | 95 | unsigned int rd_count, |
87 | const struct GNUNET_GNSRECORD_Data *rd) | 96 | const struct GNUNET_GNSRECORD_Data *rd) |
88 | { | 97 | { |
89 | int *idp = cls; | 98 | int *idp = cls; |
90 | int id = *idp; | 99 | int id = *idp; |
91 | struct GNUNET_CRYPTO_EcdsaPrivateKey tzone_private_key; | 100 | struct GNUNET_CRYPTO_EcdsaPrivateKey tzone_private_key; |
92 | char tname[64]; | 101 | char tname[64]; |
93 | unsigned int trd_count = 1 + (id % 1024); | 102 | unsigned int trd_count = 1 + (id % 1024); |
94 | unsigned int i; | ||
95 | 103 | ||
96 | GNUNET_snprintf (tname, sizeof (tname), | 104 | GNUNET_snprintf (tname, |
97 | "a%u", (unsigned int ) id); | 105 | sizeof (tname), |
98 | for (i=0;i<trd_count;i++) | 106 | "a%u", |
107 | (unsigned int ) id); | ||
108 | for (unsigned int i=0;i<trd_count;i++) | ||
99 | { | 109 | { |
100 | GNUNET_assert (rd[i].data_size == id % 10); | 110 | GNUNET_assert (rd[i].data_size == id % 10); |
101 | GNUNET_assert (0 == memcmp ("Hello World", rd[i].data, id % 10)); | 111 | GNUNET_assert (0 == memcmp ("Hello World", rd[i].data, id % 10)); |
@@ -104,31 +114,39 @@ test_record (void *cls, | |||
104 | } | 114 | } |
105 | memset (&tzone_private_key, (id % 241), sizeof (tzone_private_key)); | 115 | memset (&tzone_private_key, (id % 241), sizeof (tzone_private_key)); |
106 | GNUNET_assert (0 == strcmp (label, tname)); | 116 | GNUNET_assert (0 == strcmp (label, tname)); |
107 | GNUNET_assert (0 == memcmp (&tzone_private_key, private_key, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))); | 117 | GNUNET_assert (0 == memcmp (&tzone_private_key, |
118 | private_key, | ||
119 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))); | ||
108 | } | 120 | } |
109 | 121 | ||
110 | 122 | ||
111 | static void | 123 | static void |
112 | get_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id) | 124 | get_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, |
125 | int id) | ||
113 | { | 126 | { |
114 | GNUNET_assert (GNUNET_OK == nsp->iterate_records (nsp->cls, | 127 | GNUNET_assert (GNUNET_OK == |
115 | NULL, 0, &test_record, &id)); | 128 | nsp->iterate_records (nsp->cls, |
129 | NULL, | ||
130 | 0, | ||
131 | 1, | ||
132 | &test_record, | ||
133 | &id)); | ||
116 | } | 134 | } |
117 | 135 | ||
118 | 136 | ||
119 | static void | 137 | static void |
120 | put_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id) | 138 | put_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, |
139 | int id) | ||
121 | { | 140 | { |
122 | struct GNUNET_CRYPTO_EcdsaPrivateKey zone_private_key; | 141 | struct GNUNET_CRYPTO_EcdsaPrivateKey zone_private_key; |
123 | char label[64]; | 142 | char label[64]; |
124 | unsigned int rd_count = 1 + (id % 1024); | 143 | unsigned int rd_count = 1 + (id % 1024); |
125 | struct GNUNET_GNSRECORD_Data rd[rd_count]; | 144 | struct GNUNET_GNSRECORD_Data rd[rd_count]; |
126 | struct GNUNET_CRYPTO_EcdsaSignature signature; | 145 | struct GNUNET_CRYPTO_EcdsaSignature signature; |
127 | unsigned int i; | ||
128 | 146 | ||
129 | GNUNET_snprintf (label, sizeof (label), | 147 | GNUNET_snprintf (label, sizeof (label), |
130 | "a%u", (unsigned int ) id); | 148 | "a%u", (unsigned int ) id); |
131 | for (i=0;i<rd_count;i++) | 149 | for (unsigned int i=0;i<rd_count;i++) |
132 | { | 150 | { |
133 | rd[i].data = "Hello World"; | 151 | rd[i].data = "Hello World"; |
134 | rd[i].data_size = id % 10; | 152 | rd[i].data_size = id % 10; |
@@ -147,7 +165,9 @@ put_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id) | |||
147 | 165 | ||
148 | 166 | ||
149 | static void | 167 | static void |
150 | run (void *cls, char *const *args, const char *cfgfile, | 168 | run (void *cls, |
169 | char *const *args, | ||
170 | const char *cfgfile, | ||
151 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 171 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
152 | { | 172 | { |
153 | struct GNUNET_NAMESTORE_PluginFunctions *nsp; | 173 | struct GNUNET_NAMESTORE_PluginFunctions *nsp; |
@@ -169,7 +189,8 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
169 | 189 | ||
170 | 190 | ||
171 | int | 191 | int |
172 | main (int argc, char *argv[]) | 192 | main (int argc, |
193 | char *argv[]) | ||
173 | { | 194 | { |
174 | char cfg_name[128]; | 195 | char cfg_name[128]; |
175 | char *const xargv[] = { | 196 | char *const xargv[] = { |
@@ -187,12 +208,21 @@ main (int argc, char *argv[]) | |||
187 | "WARNING", | 208 | "WARNING", |
188 | NULL); | 209 | NULL); |
189 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); | 210 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); |
190 | GNUNET_snprintf (cfg_name, sizeof (cfg_name), "test_plugin_namestore_%s.conf", | 211 | GNUNET_snprintf (cfg_name, |
212 | sizeof (cfg_name), | ||
213 | "test_plugin_namestore_%s.conf", | ||
191 | plugin_name); | 214 | plugin_name); |
192 | GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, | 215 | GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, |
193 | "test-plugin-namestore", "nohelp", options, &run, NULL); | 216 | xargv, |
217 | "test-plugin-namestore", | ||
218 | "nohelp", | ||
219 | options, | ||
220 | &run, | ||
221 | NULL); | ||
194 | if (ok != 0) | 222 | if (ok != 0) |
195 | FPRINTF (stderr, "Missed some testcases: %d\n", ok); | 223 | FPRINTF (stderr, |
224 | "Missed some testcases: %d\n", | ||
225 | ok); | ||
196 | //GNUNET_DISK_directory_remove ("/tmp/gnunet-test-plugin-namestore-sqlite"); | 226 | //GNUNET_DISK_directory_remove ("/tmp/gnunet-test-plugin-namestore-sqlite"); |
197 | return ok; | 227 | return ok; |
198 | } | 228 | } |