diff options
Diffstat (limited to 'src/namestore/perf_namestore_api_zone_iteration.c')
-rw-r--r-- | src/namestore/perf_namestore_api_zone_iteration.c | 386 |
1 files changed, 193 insertions, 193 deletions
diff --git a/src/namestore/perf_namestore_api_zone_iteration.c b/src/namestore/perf_namestore_api_zone_iteration.c index 156f9227c..6b79a35f6 100644 --- a/src/namestore/perf_namestore_api_zone_iteration.c +++ b/src/namestore/perf_namestore_api_zone_iteration.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file namestore/perf_namestore_api_zone_iteration.c | 21 | * @file namestore/perf_namestore_api_zone_iteration.c |
22 | * @brief testcase for zone iteration functionality: iterate all zones | 22 | * @brief testcase for zone iteration functionality: iterate all zones |
@@ -35,7 +35,7 @@ | |||
35 | * modern system, so 30 minutes should be OK even for very, very | 35 | * modern system, so 30 minutes should be OK even for very, very |
36 | * slow systems. | 36 | * slow systems. |
37 | */ | 37 | */ |
38 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30) | 38 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 30) |
39 | 39 | ||
40 | /** | 40 | /** |
41 | * The runtime of the benchmark is expected to be linear | 41 | * The runtime of the benchmark is expected to be linear |
@@ -87,39 +87,39 @@ static struct GNUNET_TIME_Absolute start; | |||
87 | * @param cls NULL | 87 | * @param cls NULL |
88 | */ | 88 | */ |
89 | static void | 89 | static void |
90 | end (void *cls) | 90 | end(void *cls) |
91 | { | 91 | { |
92 | (void) cls; | 92 | (void)cls; |
93 | if (NULL != qe) | 93 | if (NULL != qe) |
94 | { | 94 | { |
95 | GNUNET_NAMESTORE_cancel (qe); | 95 | GNUNET_NAMESTORE_cancel(qe); |
96 | qe = NULL; | 96 | qe = NULL; |
97 | } | 97 | } |
98 | if (NULL != zi) | 98 | if (NULL != zi) |
99 | { | 99 | { |
100 | GNUNET_NAMESTORE_zone_iteration_stop (zi); | 100 | GNUNET_NAMESTORE_zone_iteration_stop(zi); |
101 | zi = NULL; | 101 | zi = NULL; |
102 | } | 102 | } |
103 | if (NULL != nsh) | 103 | if (NULL != nsh) |
104 | { | 104 | { |
105 | GNUNET_NAMESTORE_disconnect (nsh); | 105 | GNUNET_NAMESTORE_disconnect(nsh); |
106 | nsh = NULL; | 106 | nsh = NULL; |
107 | } | 107 | } |
108 | if (NULL != t) | 108 | if (NULL != t) |
109 | { | 109 | { |
110 | GNUNET_SCHEDULER_cancel (t); | 110 | GNUNET_SCHEDULER_cancel(t); |
111 | t = NULL; | 111 | t = NULL; |
112 | } | 112 | } |
113 | if (NULL != timeout_task) | 113 | if (NULL != timeout_task) |
114 | { | 114 | { |
115 | GNUNET_SCHEDULER_cancel (timeout_task); | 115 | GNUNET_SCHEDULER_cancel(timeout_task); |
116 | timeout_task = NULL; | 116 | timeout_task = NULL; |
117 | } | 117 | } |
118 | if (NULL != privkey) | 118 | if (NULL != privkey) |
119 | { | 119 | { |
120 | GNUNET_free (privkey); | 120 | GNUNET_free(privkey); |
121 | privkey = NULL; | 121 | privkey = NULL; |
122 | } | 122 | } |
123 | } | 123 | } |
124 | 124 | ||
125 | 125 | ||
@@ -128,228 +128,228 @@ end (void *cls) | |||
128 | * fail hard but return "skipped". | 128 | * fail hard but return "skipped". |
129 | */ | 129 | */ |
130 | static void | 130 | static void |
131 | timeout (void *cls) | 131 | timeout(void *cls) |
132 | { | 132 | { |
133 | (void) cls; | 133 | (void)cls; |
134 | timeout_task = NULL; | 134 | timeout_task = NULL; |
135 | GNUNET_SCHEDULER_shutdown (); | 135 | GNUNET_SCHEDULER_shutdown(); |
136 | res = 77; | 136 | res = 77; |
137 | } | 137 | } |
138 | 138 | ||
139 | 139 | ||
140 | static struct GNUNET_GNSRECORD_Data * | 140 | static struct GNUNET_GNSRECORD_Data * |
141 | create_record (unsigned int count) | 141 | create_record(unsigned int count) |
142 | { | 142 | { |
143 | struct GNUNET_GNSRECORD_Data *rd; | 143 | struct GNUNET_GNSRECORD_Data *rd; |
144 | 144 | ||
145 | rd = GNUNET_malloc (count + sizeof (struct GNUNET_GNSRECORD_Data)); | 145 | rd = GNUNET_malloc(count + sizeof(struct GNUNET_GNSRECORD_Data)); |
146 | rd->expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; | 146 | rd->expiration_time = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS).abs_value_us; |
147 | rd->record_type = TEST_RECORD_TYPE; | 147 | rd->record_type = TEST_RECORD_TYPE; |
148 | rd->data_size = count; | 148 | rd->data_size = count; |
149 | rd->data = (void *) &rd[1]; | 149 | rd->data = (void *)&rd[1]; |
150 | rd->flags = 0; | 150 | rd->flags = 0; |
151 | memset (&rd[1], | 151 | memset(&rd[1], |
152 | 'a', | 152 | 'a', |
153 | count); | 153 | count); |
154 | return rd; | 154 | return rd; |
155 | } | 155 | } |
156 | 156 | ||
157 | 157 | ||
158 | static void | 158 | static void |
159 | zone_end (void *cls) | 159 | zone_end(void *cls) |
160 | { | 160 | { |
161 | struct GNUNET_TIME_Relative delay; | 161 | struct GNUNET_TIME_Relative delay; |
162 | 162 | ||
163 | zi = NULL; | 163 | zi = NULL; |
164 | delay = GNUNET_TIME_absolute_get_duration (start); | 164 | delay = GNUNET_TIME_absolute_get_duration(start); |
165 | fprintf (stdout, | 165 | fprintf(stdout, |
166 | "Iterating over %u records took %s\n", | 166 | "Iterating over %u records took %s\n", |
167 | off, | 167 | off, |
168 | GNUNET_STRINGS_relative_time_to_string (delay, | 168 | GNUNET_STRINGS_relative_time_to_string(delay, |
169 | GNUNET_YES)); | 169 | GNUNET_YES)); |
170 | if (BENCHMARK_SIZE == off) | 170 | if (BENCHMARK_SIZE == off) |
171 | { | 171 | { |
172 | res = 0; | 172 | res = 0; |
173 | } | 173 | } |
174 | else | 174 | else |
175 | { | 175 | { |
176 | GNUNET_break (0); | 176 | GNUNET_break(0); |
177 | res = 1; | 177 | res = 1; |
178 | } | 178 | } |
179 | GNUNET_SCHEDULER_shutdown (); | 179 | GNUNET_SCHEDULER_shutdown(); |
180 | } | 180 | } |
181 | 181 | ||
182 | 182 | ||
183 | static void | 183 | static void |
184 | fail_cb (void *cls) | 184 | fail_cb(void *cls) |
185 | { | 185 | { |
186 | zi = NULL; | 186 | zi = NULL; |
187 | res = 2; | 187 | res = 2; |
188 | GNUNET_break (0); | 188 | GNUNET_break(0); |
189 | GNUNET_SCHEDULER_shutdown (); | 189 | GNUNET_SCHEDULER_shutdown(); |
190 | } | 190 | } |
191 | 191 | ||
192 | 192 | ||
193 | static void | 193 | static void |
194 | zone_proc (void *cls, | 194 | zone_proc(void *cls, |
195 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 195 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
196 | const char *label, | 196 | const char *label, |
197 | unsigned int rd_count, | 197 | unsigned int rd_count, |
198 | const struct GNUNET_GNSRECORD_Data *rd) | 198 | const struct GNUNET_GNSRECORD_Data *rd) |
199 | { | 199 | { |
200 | struct GNUNET_GNSRECORD_Data *wrd; | 200 | struct GNUNET_GNSRECORD_Data *wrd; |
201 | unsigned int xoff; | 201 | unsigned int xoff; |
202 | 202 | ||
203 | GNUNET_assert (NULL != zone); | 203 | GNUNET_assert(NULL != zone); |
204 | if (1 != sscanf (label, | 204 | if (1 != sscanf(label, |
205 | "l%u", | 205 | "l%u", |
206 | &xoff)) | 206 | &xoff)) |
207 | { | 207 | { |
208 | res = 3; | 208 | res = 3; |
209 | GNUNET_break (0); | 209 | GNUNET_break(0); |
210 | GNUNET_SCHEDULER_shutdown (); | 210 | GNUNET_SCHEDULER_shutdown(); |
211 | return; | 211 | return; |
212 | } | 212 | } |
213 | if ( (xoff > BENCHMARK_SIZE) || | 213 | if ((xoff > BENCHMARK_SIZE) || |
214 | (0 != (seen[xoff / 8] & (1U << (xoff % 8)))) ) | 214 | (0 != (seen[xoff / 8] & (1U << (xoff % 8))))) |
215 | { | 215 | { |
216 | res = 3; | 216 | res = 3; |
217 | GNUNET_break (0); | 217 | GNUNET_break(0); |
218 | GNUNET_SCHEDULER_shutdown (); | 218 | GNUNET_SCHEDULER_shutdown(); |
219 | return; | 219 | return; |
220 | } | 220 | } |
221 | seen[xoff / 8] |= (1U << (xoff % 8)); | 221 | seen[xoff / 8] |= (1U << (xoff % 8)); |
222 | wrd = create_record (xoff % MAX_REC_SIZE); | 222 | wrd = create_record(xoff % MAX_REC_SIZE); |
223 | if ( (rd->record_type != wrd->record_type) || | 223 | if ((rd->record_type != wrd->record_type) || |
224 | (rd->data_size != wrd->data_size) || | 224 | (rd->data_size != wrd->data_size) || |
225 | (rd->flags != wrd->flags) ) | 225 | (rd->flags != wrd->flags)) |
226 | { | 226 | { |
227 | res = 4; | 227 | res = 4; |
228 | GNUNET_break (0); | 228 | GNUNET_break(0); |
229 | GNUNET_SCHEDULER_shutdown (); | 229 | GNUNET_SCHEDULER_shutdown(); |
230 | GNUNET_free (wrd); | 230 | GNUNET_free(wrd); |
231 | return; | 231 | return; |
232 | } | 232 | } |
233 | if (0 != memcmp (rd->data, | 233 | if (0 != memcmp(rd->data, |
234 | wrd->data, | 234 | wrd->data, |
235 | wrd->data_size)) | 235 | wrd->data_size)) |
236 | { | 236 | { |
237 | res = 4; | 237 | res = 4; |
238 | GNUNET_break (0); | 238 | GNUNET_break(0); |
239 | GNUNET_SCHEDULER_shutdown (); | 239 | GNUNET_SCHEDULER_shutdown(); |
240 | GNUNET_free (wrd); | 240 | GNUNET_free(wrd); |
241 | return; | 241 | return; |
242 | } | 242 | } |
243 | GNUNET_free (wrd); | 243 | GNUNET_free(wrd); |
244 | if (0 != GNUNET_memcmp (zone, | 244 | if (0 != GNUNET_memcmp(zone, |
245 | privkey)) | 245 | privkey)) |
246 | { | 246 | { |
247 | res = 5; | 247 | res = 5; |
248 | GNUNET_break (0); | 248 | GNUNET_break(0); |
249 | GNUNET_SCHEDULER_shutdown (); | 249 | GNUNET_SCHEDULER_shutdown(); |
250 | return; | 250 | return; |
251 | } | 251 | } |
252 | off++; | 252 | off++; |
253 | left_until_next--; | 253 | left_until_next--; |
254 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 254 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
255 | "Obtained record %u, expecting %u more until asking for mor explicitly\n", | 255 | "Obtained record %u, expecting %u more until asking for mor explicitly\n", |
256 | off, | 256 | off, |
257 | left_until_next); | 257 | left_until_next); |
258 | if (0 == left_until_next) | 258 | if (0 == left_until_next) |
259 | { | 259 | { |
260 | left_until_next = BLOCK_SIZE; | 260 | left_until_next = BLOCK_SIZE; |
261 | GNUNET_NAMESTORE_zone_iterator_next (zi, | 261 | GNUNET_NAMESTORE_zone_iterator_next(zi, |
262 | left_until_next); | 262 | left_until_next); |
263 | } | 263 | } |
264 | } | 264 | } |
265 | 265 | ||
266 | 266 | ||
267 | static void | 267 | static void |
268 | publish_record (void *cls); | 268 | publish_record(void *cls); |
269 | 269 | ||
270 | 270 | ||
271 | static void | 271 | static void |
272 | put_cont (void *cls, | 272 | put_cont(void *cls, |
273 | int32_t success, | 273 | int32_t success, |
274 | const char *emsg) | 274 | const char *emsg) |
275 | { | 275 | { |
276 | (void) cls; | 276 | (void)cls; |
277 | qe = NULL; | 277 | qe = NULL; |
278 | if (GNUNET_OK != success) | 278 | if (GNUNET_OK != success) |
279 | { | 279 | { |
280 | GNUNET_break (0); | 280 | GNUNET_break(0); |
281 | GNUNET_SCHEDULER_shutdown (); | 281 | GNUNET_SCHEDULER_shutdown(); |
282 | return; | 282 | return; |
283 | } | 283 | } |
284 | t = GNUNET_SCHEDULER_add_now (&publish_record, | 284 | t = GNUNET_SCHEDULER_add_now(&publish_record, |
285 | NULL); | 285 | NULL); |
286 | } | 286 | } |
287 | 287 | ||
288 | 288 | ||
289 | static void | 289 | static void |
290 | publish_record (void *cls) | 290 | publish_record(void *cls) |
291 | { | 291 | { |
292 | struct GNUNET_GNSRECORD_Data *rd; | 292 | struct GNUNET_GNSRECORD_Data *rd; |
293 | char *label; | 293 | char *label; |
294 | 294 | ||
295 | (void) cls; | 295 | (void)cls; |
296 | t = NULL; | 296 | t = NULL; |
297 | if (BENCHMARK_SIZE == off) | 297 | if (BENCHMARK_SIZE == off) |
298 | { | 298 | { |
299 | struct GNUNET_TIME_Relative delay; | 299 | struct GNUNET_TIME_Relative delay; |
300 | 300 | ||
301 | delay = GNUNET_TIME_absolute_get_duration (start); | 301 | delay = GNUNET_TIME_absolute_get_duration(start); |
302 | fprintf (stdout, | 302 | fprintf(stdout, |
303 | "Inserting %u records took %s\n", | 303 | "Inserting %u records took %s\n", |
304 | off, | 304 | off, |
305 | GNUNET_STRINGS_relative_time_to_string (delay, | 305 | GNUNET_STRINGS_relative_time_to_string(delay, |
306 | GNUNET_YES)); | 306 | GNUNET_YES)); |
307 | start = GNUNET_TIME_absolute_get (); | 307 | start = GNUNET_TIME_absolute_get(); |
308 | off = 0; | 308 | off = 0; |
309 | left_until_next = 1; | 309 | left_until_next = 1; |
310 | zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, | 310 | zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, |
311 | NULL, | 311 | NULL, |
312 | &fail_cb, | 312 | &fail_cb, |
313 | NULL, | 313 | NULL, |
314 | &zone_proc, | 314 | &zone_proc, |
315 | NULL, | 315 | NULL, |
316 | &zone_end, | 316 | &zone_end, |
317 | NULL); | 317 | NULL); |
318 | GNUNET_assert (NULL != zi); | 318 | GNUNET_assert(NULL != zi); |
319 | return; | 319 | return; |
320 | } | 320 | } |
321 | rd = create_record ((++off) % MAX_REC_SIZE); | 321 | rd = create_record((++off) % MAX_REC_SIZE); |
322 | GNUNET_asprintf (&label, | 322 | GNUNET_asprintf(&label, |
323 | "l%u", | 323 | "l%u", |
324 | off); | 324 | off); |
325 | qe = GNUNET_NAMESTORE_records_store (nsh, | 325 | qe = GNUNET_NAMESTORE_records_store(nsh, |
326 | privkey, | 326 | privkey, |
327 | label, | 327 | label, |
328 | 1, rd, | 328 | 1, rd, |
329 | &put_cont, | 329 | &put_cont, |
330 | NULL); | 330 | NULL); |
331 | GNUNET_free (label); | 331 | GNUNET_free(label); |
332 | GNUNET_free (rd); | 332 | GNUNET_free(rd); |
333 | } | 333 | } |
334 | 334 | ||
335 | 335 | ||
336 | static void | 336 | static void |
337 | run (void *cls, | 337 | run(void *cls, |
338 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 338 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
339 | struct GNUNET_TESTING_Peer *peer) | 339 | struct GNUNET_TESTING_Peer *peer) |
340 | { | 340 | { |
341 | GNUNET_SCHEDULER_add_shutdown (&end, | 341 | GNUNET_SCHEDULER_add_shutdown(&end, |
342 | NULL); | ||
343 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | ||
344 | &timeout, | ||
345 | NULL); | ||
346 | nsh = GNUNET_NAMESTORE_connect (cfg); | ||
347 | GNUNET_assert (NULL != nsh); | ||
348 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); | ||
349 | GNUNET_assert (NULL != privkey); | ||
350 | start = GNUNET_TIME_absolute_get (); | ||
351 | t = GNUNET_SCHEDULER_add_now (&publish_record, | ||
352 | NULL); | 342 | NULL); |
343 | timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, | ||
344 | &timeout, | ||
345 | NULL); | ||
346 | nsh = GNUNET_NAMESTORE_connect(cfg); | ||
347 | GNUNET_assert(NULL != nsh); | ||
348 | privkey = GNUNET_CRYPTO_ecdsa_key_create(); | ||
349 | GNUNET_assert(NULL != privkey); | ||
350 | start = GNUNET_TIME_absolute_get(); | ||
351 | t = GNUNET_SCHEDULER_add_now(&publish_record, | ||
352 | NULL); | ||
353 | } | 353 | } |
354 | 354 | ||
355 | 355 | ||
@@ -357,25 +357,25 @@ run (void *cls, | |||
357 | 357 | ||
358 | 358 | ||
359 | int | 359 | int |
360 | main (int argc, | 360 | main(int argc, |
361 | char *argv[]) | 361 | char *argv[]) |
362 | { | 362 | { |
363 | const char *plugin_name; | 363 | const char *plugin_name; |
364 | char *cfg_name; | 364 | char *cfg_name; |
365 | 365 | ||
366 | SETUP_CFG (plugin_name, cfg_name); | 366 | SETUP_CFG(plugin_name, cfg_name); |
367 | res = 1; | 367 | res = 1; |
368 | if (0 != | 368 | if (0 != |
369 | GNUNET_TESTING_peer_run ("perf-namestore-api-zone-iteration", | 369 | GNUNET_TESTING_peer_run("perf-namestore-api-zone-iteration", |
370 | cfg_name, | 370 | cfg_name, |
371 | &run, | 371 | &run, |
372 | NULL)) | 372 | NULL)) |
373 | { | 373 | { |
374 | res = 1; | 374 | res = 1; |
375 | } | 375 | } |
376 | GNUNET_DISK_purge_cfg_dir (cfg_name, | 376 | GNUNET_DISK_purge_cfg_dir(cfg_name, |
377 | "GNUNET_TEST_HOME"); | 377 | "GNUNET_TEST_HOME"); |
378 | GNUNET_free (cfg_name); | 378 | GNUNET_free(cfg_name); |
379 | return res; | 379 | return res; |
380 | } | 380 | } |
381 | 381 | ||