diff options
Diffstat (limited to 'src/namestore')
30 files changed, 8476 insertions, 8369 deletions
diff --git a/src/namestore/gnunet-namestore-fcfsd.c b/src/namestore/gnunet-namestore-fcfsd.c index 3abf1ed21..93048ca1a 100644 --- a/src/namestore/gnunet-namestore-fcfsd.c +++ b/src/namestore/gnunet-namestore-fcfsd.c | |||
@@ -40,22 +40,26 @@ | |||
40 | /** | 40 | /** |
41 | * Invalid method page. | 41 | * Invalid method page. |
42 | */ | 42 | */ |
43 | #define METHOD_ERROR "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><title>Illegal request</title></head><body>Go away.</body></html>" | 43 | #define METHOD_ERROR \ |
44 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><title>Illegal request</title></head><body>Go away.</body></html>" | ||
44 | 45 | ||
45 | /** | 46 | /** |
46 | * Front page. (/) | 47 | * Front page. (/) |
47 | */ | 48 | */ |
48 | #define MAIN_PAGE "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><title>GNUnet FCFS Authority Name Registration Service</title></head><body><form action=\"S\" method=\"post\">What is your desired domain name? (at most 63 lowercase characters, no dots allowed.) <input type=\"text\" name=\"domain\" /> <p> What is your public key? (Copy from gnunet-setup.) <input type=\"text\" name=\"pkey\" /> <input type=\"submit\" value=\"Next\" /><br/><a href=./Zoneinfo> List of all registered names </a></body></html>" | 49 | #define MAIN_PAGE \ |
50 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><title>GNUnet FCFS Authority Name Registration Service</title></head><body><form action=\"S\" method=\"post\">What is your desired domain name? (at most 63 lowercase characters, no dots allowed.) <input type=\"text\" name=\"domain\" /> <p> What is your public key? (Copy from gnunet-setup.) <input type=\"text\" name=\"pkey\" /> <input type=\"submit\" value=\"Next\" /><br/><a href=./Zoneinfo> List of all registered names </a></body></html>" | ||
49 | 51 | ||
50 | /** | 52 | /** |
51 | * Second page (/S) | 53 | * Second page (/S) |
52 | */ | 54 | */ |
53 | #define SUBMIT_PAGE "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><title>%s</title></head><body>%s</body></html>" | 55 | #define SUBMIT_PAGE \ |
56 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><title>%s</title></head><body>%s</body></html>" | ||
54 | 57 | ||
55 | /** | 58 | /** |
56 | * Fcfs zoneinfo page (/Zoneinfo) | 59 | * Fcfs zoneinfo page (/Zoneinfo) |
57 | */ | 60 | */ |
58 | #define ZONEINFO_PAGE "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><title>FCFS Zoneinfo</title></head><body><h1> FCFS Zoneinfo </h1><table border=\"1\"><th>name</th><th>PKEY</th>%s</table></body></html>" | 61 | #define ZONEINFO_PAGE \ |
62 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><title>FCFS Zoneinfo</title></head><body><h1> FCFS Zoneinfo </h1><table border=\"1\"><th>name</th><th>PKEY</th>%s</table></body></html>" | ||
59 | 63 | ||
60 | #define FCFS_ZONEINFO_URL "/Zoneinfo" | 64 | #define FCFS_ZONEINFO_URL "/Zoneinfo" |
61 | 65 | ||
@@ -74,7 +78,8 @@ | |||
74 | /** | 78 | /** |
75 | * Phases a request goes through. | 79 | * Phases a request goes through. |
76 | */ | 80 | */ |
77 | enum Phase { | 81 | enum Phase |
82 | { | ||
78 | /** | 83 | /** |
79 | * Start phase (parsing POST, checking). | 84 | * Start phase (parsing POST, checking). |
80 | */ | 85 | */ |
@@ -105,7 +110,8 @@ enum Phase { | |||
105 | /** | 110 | /** |
106 | * Data kept per request. | 111 | * Data kept per request. |
107 | */ | 112 | */ |
108 | struct Request { | 113 | struct Request |
114 | { | ||
109 | /** | 115 | /** |
110 | * Associated session. | 116 | * Associated session. |
111 | */ | 117 | */ |
@@ -163,7 +169,8 @@ struct Request { | |||
163 | /** | 169 | /** |
164 | * Zoneinfo request | 170 | * Zoneinfo request |
165 | */ | 171 | */ |
166 | struct ZoneinfoRequest { | 172 | struct ZoneinfoRequest |
173 | { | ||
167 | /** | 174 | /** |
168 | * List iterator | 175 | * List iterator |
169 | */ | 176 | */ |
@@ -172,7 +179,7 @@ struct ZoneinfoRequest { | |||
172 | /** | 179 | /** |
173 | * Buffer | 180 | * Buffer |
174 | */ | 181 | */ |
175 | char* zoneinfo; | 182 | char*zoneinfo; |
176 | 183 | ||
177 | /** | 184 | /** |
178 | * Buffer length | 185 | * Buffer length |
@@ -193,7 +200,7 @@ static struct MHD_Daemon *httpd; | |||
193 | /** | 200 | /** |
194 | * Main HTTP task. | 201 | * Main HTTP task. |
195 | */ | 202 | */ |
196 | static struct GNUNET_SCHEDULER_Task * httpd_task; | 203 | static struct GNUNET_SCHEDULER_Task *httpd_task; |
197 | 204 | ||
198 | /** | 205 | /** |
199 | * Handle to the namestore. | 206 | * Handle to the namestore. |
@@ -242,21 +249,21 @@ static char *zone; | |||
242 | * @param cls unused | 249 | * @param cls unused |
243 | */ | 250 | */ |
244 | static void | 251 | static void |
245 | do_httpd(void *cls); | 252 | do_httpd (void *cls); |
246 | 253 | ||
247 | 254 | ||
248 | /** | 255 | /** |
249 | * Schedule task to run MHD server now. | 256 | * Schedule task to run MHD server now. |
250 | */ | 257 | */ |
251 | static void | 258 | static void |
252 | run_httpd_now() | 259 | run_httpd_now () |
253 | { | 260 | { |
254 | if (NULL != httpd_task) | 261 | if (NULL != httpd_task) |
255 | { | 262 | { |
256 | GNUNET_SCHEDULER_cancel(httpd_task); | 263 | GNUNET_SCHEDULER_cancel (httpd_task); |
257 | httpd_task = NULL; | 264 | httpd_task = NULL; |
258 | } | 265 | } |
259 | httpd_task = GNUNET_SCHEDULER_add_now(&do_httpd, NULL); | 266 | httpd_task = GNUNET_SCHEDULER_add_now (&do_httpd, NULL); |
260 | } | 267 | } |
261 | 268 | ||
262 | 269 | ||
@@ -264,22 +271,22 @@ run_httpd_now() | |||
264 | * Create fresh version of zone information. | 271 | * Create fresh version of zone information. |
265 | */ | 272 | */ |
266 | static void | 273 | static void |
267 | update_zoneinfo_page(void *cls); | 274 | update_zoneinfo_page (void *cls); |
268 | 275 | ||
269 | 276 | ||
270 | /** | 277 | /** |
271 | * Function called on error in zone iteration. | 278 | * Function called on error in zone iteration. |
272 | */ | 279 | */ |
273 | static void | 280 | static void |
274 | zone_iteration_error(void *cls) | 281 | zone_iteration_error (void *cls) |
275 | { | 282 | { |
276 | struct ZoneinfoRequest *zr = cls; | 283 | struct ZoneinfoRequest *zr = cls; |
277 | 284 | ||
278 | zr->list_it = NULL; | 285 | zr->list_it = NULL; |
279 | GNUNET_free(zr->zoneinfo); | 286 | GNUNET_free (zr->zoneinfo); |
280 | GNUNET_SCHEDULER_cancel(uzp_task); | 287 | GNUNET_SCHEDULER_cancel (uzp_task); |
281 | uzp_task = GNUNET_SCHEDULER_add_now(&update_zoneinfo_page, | 288 | uzp_task = GNUNET_SCHEDULER_add_now (&update_zoneinfo_page, |
282 | NULL); | 289 | NULL); |
283 | } | 290 | } |
284 | 291 | ||
285 | 292 | ||
@@ -287,28 +294,28 @@ zone_iteration_error(void *cls) | |||
287 | * Function called once the zone iteration is done. | 294 | * Function called once the zone iteration is done. |
288 | */ | 295 | */ |
289 | static void | 296 | static void |
290 | zone_iteration_end(void *cls) | 297 | zone_iteration_end (void *cls) |
291 | { | 298 | { |
292 | struct ZoneinfoRequest *zr = cls; | 299 | struct ZoneinfoRequest *zr = cls; |
293 | struct MHD_Response *response; | 300 | struct MHD_Response *response; |
294 | char* full_page; | 301 | char*full_page; |
295 | 302 | ||
296 | zr->list_it = NULL; | 303 | zr->list_it = NULL; |
297 | 304 | ||
298 | /* return static form */ | 305 | /* return static form */ |
299 | GNUNET_asprintf(&full_page, | 306 | GNUNET_asprintf (&full_page, |
300 | ZONEINFO_PAGE, | 307 | ZONEINFO_PAGE, |
301 | zr->zoneinfo, | 308 | zr->zoneinfo, |
302 | zr->zoneinfo); | 309 | zr->zoneinfo); |
303 | response = MHD_create_response_from_buffer(strlen(full_page), | 310 | response = MHD_create_response_from_buffer (strlen (full_page), |
304 | (void *)full_page, | 311 | (void *) full_page, |
305 | MHD_RESPMEM_MUST_FREE); | 312 | MHD_RESPMEM_MUST_FREE); |
306 | MHD_add_response_header(response, | 313 | MHD_add_response_header (response, |
307 | MHD_HTTP_HEADER_CONTENT_TYPE, | 314 | MHD_HTTP_HEADER_CONTENT_TYPE, |
308 | MIME_HTML); | 315 | MIME_HTML); |
309 | MHD_destroy_response(info_page); | 316 | MHD_destroy_response (info_page); |
310 | info_page = response; | 317 | info_page = response; |
311 | GNUNET_free(zr->zoneinfo); | 318 | GNUNET_free (zr->zoneinfo); |
312 | } | 319 | } |
313 | 320 | ||
314 | 321 | ||
@@ -323,59 +330,59 @@ zone_iteration_end(void *cls) | |||
323 | * @param rd array of records with data to store | 330 | * @param rd array of records with data to store |
324 | */ | 331 | */ |
325 | static void | 332 | static void |
326 | iterate_cb(void *cls, | 333 | iterate_cb (void *cls, |
327 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 334 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, |
328 | const char *name, | 335 | const char *name, |
329 | unsigned int rd_len, | 336 | unsigned int rd_len, |
330 | const struct GNUNET_GNSRECORD_Data *rd) | 337 | const struct GNUNET_GNSRECORD_Data *rd) |
331 | { | 338 | { |
332 | struct ZoneinfoRequest *zr = cls; | 339 | struct ZoneinfoRequest *zr = cls; |
333 | size_t bytes_free; | 340 | size_t bytes_free; |
334 | char* pkey; | 341 | char*pkey; |
335 | char* new_buf; | 342 | char*new_buf; |
336 | 343 | ||
337 | (void)zone_key; | 344 | (void) zone_key; |
338 | if (1 != rd_len) | 345 | if (1 != rd_len) |
339 | { | 346 | { |
340 | GNUNET_NAMESTORE_zone_iterator_next(zr->list_it, | 347 | GNUNET_NAMESTORE_zone_iterator_next (zr->list_it, |
341 | 1); | 348 | 1); |
342 | return; | 349 | return; |
343 | } | 350 | } |
344 | 351 | ||
345 | if (GNUNET_GNSRECORD_TYPE_PKEY != rd->record_type) | 352 | if (GNUNET_GNSRECORD_TYPE_PKEY != rd->record_type) |
346 | { | 353 | { |
347 | GNUNET_NAMESTORE_zone_iterator_next(zr->list_it, | 354 | GNUNET_NAMESTORE_zone_iterator_next (zr->list_it, |
348 | 1); | 355 | 1); |
349 | return; | 356 | return; |
350 | } | 357 | } |
351 | 358 | ||
352 | bytes_free = zr->buf_len - zr->write_offset; | 359 | bytes_free = zr->buf_len - zr->write_offset; |
353 | pkey = GNUNET_GNSRECORD_value_to_string(rd->record_type, | 360 | pkey = GNUNET_GNSRECORD_value_to_string (rd->record_type, |
354 | rd->data, | 361 | rd->data, |
355 | rd->data_size); | 362 | rd->data_size); |
356 | if (NULL == pkey) | 363 | if (NULL == pkey) |
357 | { | 364 | { |
358 | GNUNET_break(0); | 365 | GNUNET_break (0); |
359 | GNUNET_NAMESTORE_zone_iterator_next(zr->list_it, | 366 | GNUNET_NAMESTORE_zone_iterator_next (zr->list_it, |
360 | 1); | 367 | 1); |
361 | return; | 368 | return; |
362 | } | 369 | } |
363 | if (bytes_free < (strlen(name) + strlen(pkey) + 40)) | 370 | if (bytes_free < (strlen (name) + strlen (pkey) + 40)) |
364 | { | 371 | { |
365 | new_buf = GNUNET_malloc(zr->buf_len * 2); | 372 | new_buf = GNUNET_malloc (zr->buf_len * 2); |
366 | GNUNET_memcpy(new_buf, zr->zoneinfo, zr->write_offset); | 373 | GNUNET_memcpy (new_buf, zr->zoneinfo, zr->write_offset); |
367 | GNUNET_free(zr->zoneinfo); | 374 | GNUNET_free (zr->zoneinfo); |
368 | zr->zoneinfo = new_buf; | 375 | zr->zoneinfo = new_buf; |
369 | zr->buf_len *= 2; | 376 | zr->buf_len *= 2; |
370 | } | 377 | } |
371 | sprintf(zr->zoneinfo + zr->write_offset, | 378 | sprintf (zr->zoneinfo + zr->write_offset, |
372 | "<tr><td>%s</td><td>%s</td></tr>", | 379 | "<tr><td>%s</td><td>%s</td></tr>", |
373 | name, | 380 | name, |
374 | pkey); | 381 | pkey); |
375 | zr->write_offset = strlen(zr->zoneinfo); | 382 | zr->write_offset = strlen (zr->zoneinfo); |
376 | GNUNET_NAMESTORE_zone_iterator_next(zr->list_it, | 383 | GNUNET_NAMESTORE_zone_iterator_next (zr->list_it, |
377 | 1); | 384 | 1); |
378 | GNUNET_free(pkey); | 385 | GNUNET_free (pkey); |
379 | } | 386 | } |
380 | 387 | ||
381 | 388 | ||
@@ -385,11 +392,11 @@ iterate_cb(void *cls, | |||
385 | * @param connection connection to use | 392 | * @param connection connection to use |
386 | */ | 393 | */ |
387 | static int | 394 | static int |
388 | serve_zoneinfo_page(struct MHD_Connection *connection) | 395 | serve_zoneinfo_page (struct MHD_Connection *connection) |
389 | { | 396 | { |
390 | return MHD_queue_response(connection, | 397 | return MHD_queue_response (connection, |
391 | MHD_HTTP_OK, | 398 | MHD_HTTP_OK, |
392 | info_page); | 399 | info_page); |
393 | } | 400 | } |
394 | 401 | ||
395 | 402 | ||
@@ -397,27 +404,27 @@ serve_zoneinfo_page(struct MHD_Connection *connection) | |||
397 | * Create fresh version of zone information. | 404 | * Create fresh version of zone information. |
398 | */ | 405 | */ |
399 | static void | 406 | static void |
400 | update_zoneinfo_page(void *cls) | 407 | update_zoneinfo_page (void *cls) |
401 | { | 408 | { |
402 | static struct ZoneinfoRequest zr; | 409 | static struct ZoneinfoRequest zr; |
403 | 410 | ||
404 | (void)cls; | 411 | (void) cls; |
405 | uzp_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, | 412 | uzp_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, |
406 | &update_zoneinfo_page, | 413 | &update_zoneinfo_page, |
407 | NULL); | 414 | NULL); |
408 | if (NULL != zr.list_it) | 415 | if (NULL != zr.list_it) |
409 | return; | 416 | return; |
410 | zr.zoneinfo = GNUNET_malloc(DEFAULT_ZONEINFO_BUFSIZE); | 417 | zr.zoneinfo = GNUNET_malloc (DEFAULT_ZONEINFO_BUFSIZE); |
411 | zr.buf_len = DEFAULT_ZONEINFO_BUFSIZE; | 418 | zr.buf_len = DEFAULT_ZONEINFO_BUFSIZE; |
412 | zr.write_offset = 0; | 419 | zr.write_offset = 0; |
413 | zr.list_it = GNUNET_NAMESTORE_zone_iteration_start(ns, | 420 | zr.list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, |
414 | &fcfs_zone_pkey, | 421 | &fcfs_zone_pkey, |
415 | &zone_iteration_error, | 422 | &zone_iteration_error, |
416 | &zr, | 423 | &zr, |
417 | &iterate_cb, | 424 | &iterate_cb, |
418 | &zr, | 425 | &zr, |
419 | &zone_iteration_end, | 426 | &zone_iteration_end, |
420 | &zr); | 427 | &zr); |
421 | } | 428 | } |
422 | 429 | ||
423 | 430 | ||
@@ -428,22 +435,22 @@ update_zoneinfo_page(void *cls) | |||
428 | * @return #MHD_YES on success | 435 | * @return #MHD_YES on success |
429 | */ | 436 | */ |
430 | static int | 437 | static int |
431 | serve_main_page(struct MHD_Connection *connection) | 438 | serve_main_page (struct MHD_Connection *connection) |
432 | { | 439 | { |
433 | int ret; | 440 | int ret; |
434 | struct MHD_Response *response; | 441 | struct MHD_Response *response; |
435 | 442 | ||
436 | /* return static form */ | 443 | /* return static form */ |
437 | response = MHD_create_response_from_buffer(strlen(MAIN_PAGE), | 444 | response = MHD_create_response_from_buffer (strlen (MAIN_PAGE), |
438 | (void *)MAIN_PAGE, | 445 | (void *) MAIN_PAGE, |
439 | MHD_RESPMEM_PERSISTENT); | 446 | MHD_RESPMEM_PERSISTENT); |
440 | MHD_add_response_header(response, | 447 | MHD_add_response_header (response, |
441 | MHD_HTTP_HEADER_CONTENT_TYPE, | 448 | MHD_HTTP_HEADER_CONTENT_TYPE, |
442 | MIME_HTML); | 449 | MIME_HTML); |
443 | ret = MHD_queue_response(connection, | 450 | ret = MHD_queue_response (connection, |
444 | MHD_HTTP_OK, | 451 | MHD_HTTP_OK, |
445 | response); | 452 | response); |
446 | MHD_destroy_response(response); | 453 | MHD_destroy_response (response); |
447 | return ret; | 454 | return ret; |
448 | } | 455 | } |
449 | 456 | ||
@@ -456,30 +463,30 @@ serve_main_page(struct MHD_Connection *connection) | |||
456 | * @param connection connection to use | 463 | * @param connection connection to use |
457 | */ | 464 | */ |
458 | static int | 465 | static int |
459 | fill_s_reply(const char *info, | 466 | fill_s_reply (const char *info, |
460 | struct Request *request, | 467 | struct Request *request, |
461 | struct MHD_Connection *connection) | 468 | struct MHD_Connection *connection) |
462 | { | 469 | { |
463 | int ret; | 470 | int ret; |
464 | char *reply; | 471 | char *reply; |
465 | struct MHD_Response *response; | 472 | struct MHD_Response *response; |
466 | 473 | ||
467 | (void)request; | 474 | (void) request; |
468 | GNUNET_asprintf(&reply, | 475 | GNUNET_asprintf (&reply, |
469 | SUBMIT_PAGE, | 476 | SUBMIT_PAGE, |
470 | info, | 477 | info, |
471 | info); | 478 | info); |
472 | /* return static form */ | 479 | /* return static form */ |
473 | response = MHD_create_response_from_buffer(strlen(reply), | 480 | response = MHD_create_response_from_buffer (strlen (reply), |
474 | (void *)reply, | 481 | (void *) reply, |
475 | MHD_RESPMEM_MUST_FREE); | 482 | MHD_RESPMEM_MUST_FREE); |
476 | MHD_add_response_header(response, | 483 | MHD_add_response_header (response, |
477 | MHD_HTTP_HEADER_CONTENT_TYPE, | 484 | MHD_HTTP_HEADER_CONTENT_TYPE, |
478 | MIME_HTML); | 485 | MIME_HTML); |
479 | ret = MHD_queue_response(connection, | 486 | ret = MHD_queue_response (connection, |
480 | MHD_HTTP_OK, | 487 | MHD_HTTP_OK, |
481 | response); | 488 | response); |
482 | MHD_destroy_response(response); | 489 | MHD_destroy_response (response); |
483 | return ret; | 490 | return ret; |
484 | } | 491 | } |
485 | 492 | ||
@@ -504,45 +511,45 @@ fill_s_reply(const char *info, | |||
504 | * MHD_NO to abort the iteration | 511 | * MHD_NO to abort the iteration |
505 | */ | 512 | */ |
506 | static int | 513 | static int |
507 | post_iterator(void *cls, | 514 | post_iterator (void *cls, |
508 | enum MHD_ValueKind kind, | 515 | enum MHD_ValueKind kind, |
509 | const char *key, | 516 | const char *key, |
510 | const char *filename, | 517 | const char *filename, |
511 | const char *content_type, | 518 | const char *content_type, |
512 | const char *transfer_encoding, | 519 | const char *transfer_encoding, |
513 | const char *data, | 520 | const char *data, |
514 | uint64_t off, | 521 | uint64_t off, |
515 | size_t size) | 522 | size_t size) |
516 | { | 523 | { |
517 | struct Request *request = cls; | 524 | struct Request *request = cls; |
518 | 525 | ||
519 | (void)kind; | 526 | (void) kind; |
520 | (void)filename; | 527 | (void) filename; |
521 | (void)content_type; | 528 | (void) content_type; |
522 | (void)transfer_encoding; | 529 | (void) transfer_encoding; |
523 | if (0 == strcmp("domain", key)) | 530 | if (0 == strcmp ("domain", key)) |
524 | { | 531 | { |
525 | if (size + off >= sizeof(request->domain_name)) | 532 | if (size + off >= sizeof(request->domain_name)) |
526 | size = sizeof(request->domain_name) - off - 1; | 533 | size = sizeof(request->domain_name) - off - 1; |
527 | GNUNET_memcpy(&request->domain_name[off], | 534 | GNUNET_memcpy (&request->domain_name[off], |
528 | data, | 535 | data, |
529 | size); | 536 | size); |
530 | request->domain_name[size + off] = '\0'; | 537 | request->domain_name[size + off] = '\0'; |
531 | return MHD_YES; | 538 | return MHD_YES; |
532 | } | 539 | } |
533 | if (0 == strcmp("pkey", key)) | 540 | if (0 == strcmp ("pkey", key)) |
534 | { | 541 | { |
535 | if (size + off >= sizeof(request->public_key)) | 542 | if (size + off >= sizeof(request->public_key)) |
536 | size = sizeof(request->public_key) - off - 1; | 543 | size = sizeof(request->public_key) - off - 1; |
537 | GNUNET_memcpy(&request->public_key[off], | 544 | GNUNET_memcpy (&request->public_key[off], |
538 | data, | 545 | data, |
539 | size); | 546 | size); |
540 | request->public_key[size + off] = '\0'; | 547 | request->public_key[size + off] = '\0'; |
541 | return MHD_YES; | 548 | return MHD_YES; |
542 | } | 549 | } |
543 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 550 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
544 | _("Unsupported form value `%s'\n"), | 551 | _ ("Unsupported form value `%s'\n"), |
545 | key); | 552 | key); |
546 | return MHD_YES; | 553 | return MHD_YES; |
547 | } | 554 | } |
548 | 555 | ||
@@ -558,25 +565,25 @@ post_iterator(void *cls, | |||
558 | * @param emsg NULL on success, otherwise an error message | 565 | * @param emsg NULL on success, otherwise an error message |
559 | */ | 566 | */ |
560 | static void | 567 | static void |
561 | put_continuation(void *cls, | 568 | put_continuation (void *cls, |
562 | int32_t success, | 569 | int32_t success, |
563 | const char *emsg) | 570 | const char *emsg) |
564 | { | 571 | { |
565 | struct Request *request = cls; | 572 | struct Request *request = cls; |
566 | 573 | ||
567 | request->qe = NULL; | 574 | request->qe = NULL; |
568 | if (0 >= success) | 575 | if (0 >= success) |
569 | { | 576 | { |
570 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 577 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
571 | _("Failed to create record for domain `%s': %s\n"), | 578 | _ ("Failed to create record for domain `%s': %s\n"), |
572 | request->domain_name, | 579 | request->domain_name, |
573 | emsg); | 580 | emsg); |
574 | request->phase = RP_FAIL; | 581 | request->phase = RP_FAIL; |
575 | } | 582 | } |
576 | else | 583 | else |
577 | request->phase = RP_SUCCESS; | 584 | request->phase = RP_SUCCESS; |
578 | MHD_resume_connection(request->con); | 585 | MHD_resume_connection (request->con); |
579 | run_httpd_now(); | 586 | run_httpd_now (); |
580 | } | 587 | } |
581 | 588 | ||
582 | 589 | ||
@@ -584,15 +591,15 @@ put_continuation(void *cls, | |||
584 | * Function called if we had an error in zone-to-name mapping. | 591 | * Function called if we had an error in zone-to-name mapping. |
585 | */ | 592 | */ |
586 | static void | 593 | static void |
587 | zone_to_name_error(void *cls) | 594 | zone_to_name_error (void *cls) |
588 | { | 595 | { |
589 | struct Request *request = cls; | 596 | struct Request *request = cls; |
590 | 597 | ||
591 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 598 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
592 | _("Error when mapping zone to name\n")); | 599 | _ ("Error when mapping zone to name\n")); |
593 | request->phase = RP_FAIL; | 600 | request->phase = RP_FAIL; |
594 | MHD_resume_connection(request->con); | 601 | MHD_resume_connection (request->con); |
595 | run_httpd_now(); | 602 | run_httpd_now (); |
596 | } | 603 | } |
597 | 604 | ||
598 | 605 | ||
@@ -606,39 +613,39 @@ zone_to_name_error(void *cls) | |||
606 | * @param rd array of records with data to store | 613 | * @param rd array of records with data to store |
607 | */ | 614 | */ |
608 | static void | 615 | static void |
609 | zone_to_name_cb(void *cls, | 616 | zone_to_name_cb (void *cls, |
610 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 617 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, |
611 | const char *name, | 618 | const char *name, |
612 | unsigned int rd_count, | 619 | unsigned int rd_count, |
613 | const struct GNUNET_GNSRECORD_Data *rd) | 620 | const struct GNUNET_GNSRECORD_Data *rd) |
614 | { | 621 | { |
615 | struct Request *request = cls; | 622 | struct Request *request = cls; |
616 | struct GNUNET_GNSRECORD_Data r; | 623 | struct GNUNET_GNSRECORD_Data r; |
617 | 624 | ||
618 | (void)rd; | 625 | (void) rd; |
619 | (void)zone_key; | 626 | (void) zone_key; |
620 | request->qe = NULL; | 627 | request->qe = NULL; |
621 | if (0 != rd_count) | 628 | if (0 != rd_count) |
622 | { | 629 | { |
623 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 630 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
624 | _("Found existing name `%s' for the given key\n"), | 631 | _ ("Found existing name `%s' for the given key\n"), |
625 | name); | 632 | name); |
626 | request->phase = RP_FAIL; | 633 | request->phase = RP_FAIL; |
627 | MHD_resume_connection(request->con); | 634 | MHD_resume_connection (request->con); |
628 | run_httpd_now(); | 635 | run_httpd_now (); |
629 | return; | 636 | return; |
630 | } | 637 | } |
631 | r.data = &request->pub; | 638 | r.data = &request->pub; |
632 | r.data_size = sizeof(request->pub); | 639 | r.data_size = sizeof(request->pub); |
633 | r.expiration_time = UINT64_MAX; | 640 | r.expiration_time = UINT64_MAX; |
634 | r.record_type = GNUNET_GNSRECORD_TYPE_PKEY; | 641 | r.record_type = GNUNET_GNSRECORD_TYPE_PKEY; |
635 | r.flags = GNUNET_GNSRECORD_RF_NONE; | 642 | r.flags = GNUNET_GNSRECORD_RF_NONE; |
636 | request->qe = GNUNET_NAMESTORE_records_store(ns, | 643 | request->qe = GNUNET_NAMESTORE_records_store (ns, |
637 | &fcfs_zone_pkey, | 644 | &fcfs_zone_pkey, |
638 | request->domain_name, | 645 | request->domain_name, |
639 | 1, &r, | 646 | 1, &r, |
640 | &put_continuation, | 647 | &put_continuation, |
641 | request); | 648 | request); |
642 | } | 649 | } |
643 | 650 | ||
644 | 651 | ||
@@ -646,14 +653,14 @@ zone_to_name_cb(void *cls, | |||
646 | * We encountered an error in the name lookup. | 653 | * We encountered an error in the name lookup. |
647 | */ | 654 | */ |
648 | static void | 655 | static void |
649 | lookup_it_error(void *cls) | 656 | lookup_it_error (void *cls) |
650 | { | 657 | { |
651 | struct Request *request = cls; | 658 | struct Request *request = cls; |
652 | 659 | ||
653 | MHD_resume_connection(request->con); | 660 | MHD_resume_connection (request->con); |
654 | request->qe = NULL; | 661 | request->qe = NULL; |
655 | request->phase = RP_FAIL; | 662 | request->phase = RP_FAIL; |
656 | run_httpd_now(); | 663 | run_httpd_now (); |
657 | } | 664 | } |
658 | 665 | ||
659 | 666 | ||
@@ -668,58 +675,58 @@ lookup_it_error(void *cls) | |||
668 | * @param rd array of records with data to store | 675 | * @param rd array of records with data to store |
669 | */ | 676 | */ |
670 | static void | 677 | static void |
671 | lookup_it_processor(void *cls, | 678 | lookup_it_processor (void *cls, |
672 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zonekey, | 679 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zonekey, |
673 | const char *label, | 680 | const char *label, |
674 | unsigned int rd_count, | 681 | unsigned int rd_count, |
675 | const struct GNUNET_GNSRECORD_Data *rd) | 682 | const struct GNUNET_GNSRECORD_Data *rd) |
676 | { | 683 | { |
677 | struct Request *request = cls; | 684 | struct Request *request = cls; |
678 | 685 | ||
679 | (void)label; | 686 | (void) label; |
680 | (void)rd; | 687 | (void) rd; |
681 | (void)zonekey; | 688 | (void) zonekey; |
682 | if (0 == strcmp(label, request->domain_name)) | 689 | if (0 == strcmp (label, request->domain_name)) |
683 | { | 690 | { |
684 | GNUNET_break(0 != rd_count); | 691 | GNUNET_break (0 != rd_count); |
685 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 692 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
686 | _("Found %u existing records for domain `%s'\n"), | 693 | _ ("Found %u existing records for domain `%s'\n"), |
687 | rd_count, | 694 | rd_count, |
688 | request->domain_name); | 695 | request->domain_name); |
689 | request->phase = RP_FAIL; | 696 | request->phase = RP_FAIL; |
690 | } | 697 | } |
691 | GNUNET_NAMESTORE_zone_iterator_next(request->lookup_it, 1); | 698 | GNUNET_NAMESTORE_zone_iterator_next (request->lookup_it, 1); |
692 | } | 699 | } |
693 | 700 | ||
694 | static void | 701 | static void |
695 | lookup_it_finished(void *cls) | 702 | lookup_it_finished (void *cls) |
696 | { | 703 | { |
697 | struct Request *request = cls; | 704 | struct Request *request = cls; |
698 | 705 | ||
699 | if (RP_FAIL == request->phase) | 706 | if (RP_FAIL == request->phase) |
700 | { | 707 | { |
701 | MHD_resume_connection(request->con); | 708 | MHD_resume_connection (request->con); |
702 | run_httpd_now(); | 709 | run_httpd_now (); |
703 | return; | 710 | return; |
704 | } | 711 | } |
705 | if (GNUNET_OK != | 712 | if (GNUNET_OK != |
706 | GNUNET_CRYPTO_ecdsa_public_key_from_string(request->public_key, | 713 | GNUNET_CRYPTO_ecdsa_public_key_from_string (request->public_key, |
707 | strlen(request->public_key), | 714 | strlen (request->public_key), |
708 | &request->pub)) | 715 | &request->pub)) |
709 | { | 716 | { |
710 | GNUNET_break(0); | 717 | GNUNET_break (0); |
711 | request->phase = RP_FAIL; | 718 | request->phase = RP_FAIL; |
712 | MHD_resume_connection(request->con); | 719 | MHD_resume_connection (request->con); |
713 | run_httpd_now(); | 720 | run_httpd_now (); |
714 | return; | 721 | return; |
715 | } | 722 | } |
716 | request->qe = GNUNET_NAMESTORE_zone_to_name(ns, | 723 | request->qe = GNUNET_NAMESTORE_zone_to_name (ns, |
717 | &fcfs_zone_pkey, | 724 | &fcfs_zone_pkey, |
718 | &request->pub, | 725 | &request->pub, |
719 | &zone_to_name_error, | 726 | &zone_to_name_error, |
720 | request, | 727 | request, |
721 | &zone_to_name_cb, | 728 | &zone_to_name_cb, |
722 | request); | 729 | request); |
723 | } | 730 | } |
724 | 731 | ||
725 | /** | 732 | /** |
@@ -746,141 +753,142 @@ lookup_it_finished(void *cls) | |||
746 | * error while handling the request | 753 | * error while handling the request |
747 | */ | 754 | */ |
748 | static int | 755 | static int |
749 | create_response(void *cls, | 756 | create_response (void *cls, |
750 | struct MHD_Connection *connection, | 757 | struct MHD_Connection *connection, |
751 | const char *url, | 758 | const char *url, |
752 | const char *method, | 759 | const char *method, |
753 | const char *version, | 760 | const char *version, |
754 | const char *upload_data, | 761 | const char *upload_data, |
755 | size_t *upload_data_size, | 762 | size_t *upload_data_size, |
756 | void **ptr) | 763 | void **ptr) |
757 | { | 764 | { |
758 | struct MHD_Response *response; | 765 | struct MHD_Response *response; |
759 | struct Request *request; | 766 | struct Request *request; |
760 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | 767 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; |
761 | int ret; | 768 | int ret; |
762 | 769 | ||
763 | (void)cls; | 770 | (void) cls; |
764 | (void)version; | 771 | (void) version; |
765 | if ((0 == strcmp(method, MHD_HTTP_METHOD_GET)) || | 772 | if ((0 == strcmp (method, MHD_HTTP_METHOD_GET)) || |
766 | (0 == strcmp(method, MHD_HTTP_METHOD_HEAD))) | 773 | (0 == strcmp (method, MHD_HTTP_METHOD_HEAD))) |
774 | { | ||
775 | if (0 == strcmp (url, FCFS_ZONEINFO_URL)) | ||
776 | ret = serve_zoneinfo_page (connection); | ||
777 | else | ||
778 | ret = serve_main_page (connection); | ||
779 | if (ret != MHD_YES) | ||
780 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
781 | _ ("Failed to create page for `%s'\n"), | ||
782 | url); | ||
783 | return ret; | ||
784 | } | ||
785 | if (0 == strcmp (method, MHD_HTTP_METHOD_POST)) | ||
786 | { | ||
787 | request = *ptr; | ||
788 | if (NULL == request) | ||
789 | { | ||
790 | request = GNUNET_new (struct Request); | ||
791 | request->con = connection; | ||
792 | *ptr = request; | ||
793 | request->pp = MHD_create_post_processor (connection, | ||
794 | 1024, | ||
795 | &post_iterator, | ||
796 | request); | ||
797 | if (NULL == request->pp) | ||
798 | { | ||
799 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
800 | _ ("Failed to setup post processor for `%s'\n"), | ||
801 | url); | ||
802 | return MHD_NO; /* internal error */ | ||
803 | } | ||
804 | return MHD_YES; | ||
805 | } | ||
806 | if (NULL != request->pp) | ||
767 | { | 807 | { |
768 | if (0 == strcmp(url, FCFS_ZONEINFO_URL)) | 808 | /* evaluate POST data */ |
769 | ret = serve_zoneinfo_page(connection); | 809 | MHD_post_process (request->pp, |
770 | else | 810 | upload_data, |
771 | ret = serve_main_page(connection); | 811 | *upload_data_size); |
772 | if (ret != MHD_YES) | 812 | if (0 != *upload_data_size) |
773 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 813 | { |
774 | _("Failed to create page for `%s'\n"), | 814 | *upload_data_size = 0; |
775 | url); | 815 | return MHD_YES; |
776 | return ret; | 816 | } |
817 | /* done with POST data, serve response */ | ||
818 | MHD_destroy_post_processor (request->pp); | ||
819 | request->pp = NULL; | ||
777 | } | 820 | } |
778 | if (0 == strcmp(method, MHD_HTTP_METHOD_POST)) | 821 | if (GNUNET_OK != |
822 | GNUNET_CRYPTO_ecdsa_public_key_from_string (request->public_key, | ||
823 | strlen ( | ||
824 | request->public_key), | ||
825 | &pub)) | ||
779 | { | 826 | { |
780 | request = *ptr; | 827 | /* parse error */ |
781 | if (NULL == request) | 828 | return fill_s_reply ("Failed to parse given public key", |
782 | { | 829 | request, connection); |
783 | request = GNUNET_new(struct Request); | ||
784 | request->con = connection; | ||
785 | *ptr = request; | ||
786 | request->pp = MHD_create_post_processor(connection, | ||
787 | 1024, | ||
788 | &post_iterator, | ||
789 | request); | ||
790 | if (NULL == request->pp) | ||
791 | { | ||
792 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
793 | _("Failed to setup post processor for `%s'\n"), | ||
794 | url); | ||
795 | return MHD_NO; /* internal error */ | ||
796 | } | ||
797 | return MHD_YES; | ||
798 | } | ||
799 | if (NULL != request->pp) | ||
800 | { | ||
801 | /* evaluate POST data */ | ||
802 | MHD_post_process(request->pp, | ||
803 | upload_data, | ||
804 | *upload_data_size); | ||
805 | if (0 != *upload_data_size) | ||
806 | { | ||
807 | *upload_data_size = 0; | ||
808 | return MHD_YES; | ||
809 | } | ||
810 | /* done with POST data, serve response */ | ||
811 | MHD_destroy_post_processor(request->pp); | ||
812 | request->pp = NULL; | ||
813 | } | ||
814 | if (GNUNET_OK != | ||
815 | GNUNET_CRYPTO_ecdsa_public_key_from_string(request->public_key, | ||
816 | strlen(request->public_key), | ||
817 | &pub)) | ||
818 | { | ||
819 | /* parse error */ | ||
820 | return fill_s_reply("Failed to parse given public key", | ||
821 | request, connection); | ||
822 | } | ||
823 | switch (request->phase) | ||
824 | { | ||
825 | case RP_START: | ||
826 | if (NULL != strchr(request->domain_name, (int)'.')) | ||
827 | { | ||
828 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
829 | _("Domain name must not contain `.'\n")); | ||
830 | request->phase = RP_FAIL; | ||
831 | return fill_s_reply("Domain name must not contain `.', sorry.", | ||
832 | request, | ||
833 | connection); | ||
834 | } | ||
835 | if (NULL != strchr(request->domain_name, (int)'+')) | ||
836 | { | ||
837 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
838 | _("Domain name must not contain `+'\n")); | ||
839 | request->phase = RP_FAIL; | ||
840 | return fill_s_reply("Domain name must not contain `+', sorry.", | ||
841 | request, connection); | ||
842 | } | ||
843 | request->phase = RP_LOOKUP; | ||
844 | MHD_suspend_connection(request->con); | ||
845 | request->lookup_it | ||
846 | = GNUNET_NAMESTORE_zone_iteration_start(ns, | ||
847 | &fcfs_zone_pkey, | ||
848 | &lookup_it_error, | ||
849 | request, | ||
850 | &lookup_it_processor, | ||
851 | request, | ||
852 | &lookup_it_finished, | ||
853 | request); | ||
854 | break; | ||
855 | |||
856 | case RP_LOOKUP: | ||
857 | break; | ||
858 | |||
859 | case RP_PUT: | ||
860 | break; | ||
861 | |||
862 | case RP_FAIL: | ||
863 | return fill_s_reply("Request failed, sorry.", | ||
864 | request, connection); | ||
865 | |||
866 | case RP_SUCCESS: | ||
867 | return fill_s_reply("Success.", | ||
868 | request, connection); | ||
869 | |||
870 | default: | ||
871 | GNUNET_break(0); | ||
872 | return MHD_NO; | ||
873 | } | ||
874 | return MHD_YES; /* will have a reply later... */ | ||
875 | } | 830 | } |
831 | switch (request->phase) | ||
832 | { | ||
833 | case RP_START: | ||
834 | if (NULL != strchr (request->domain_name, (int) '.')) | ||
835 | { | ||
836 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
837 | _ ("Domain name must not contain `.'\n")); | ||
838 | request->phase = RP_FAIL; | ||
839 | return fill_s_reply ("Domain name must not contain `.', sorry.", | ||
840 | request, | ||
841 | connection); | ||
842 | } | ||
843 | if (NULL != strchr (request->domain_name, (int) '+')) | ||
844 | { | ||
845 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
846 | _ ("Domain name must not contain `+'\n")); | ||
847 | request->phase = RP_FAIL; | ||
848 | return fill_s_reply ("Domain name must not contain `+', sorry.", | ||
849 | request, connection); | ||
850 | } | ||
851 | request->phase = RP_LOOKUP; | ||
852 | MHD_suspend_connection (request->con); | ||
853 | request->lookup_it | ||
854 | = GNUNET_NAMESTORE_zone_iteration_start (ns, | ||
855 | &fcfs_zone_pkey, | ||
856 | &lookup_it_error, | ||
857 | request, | ||
858 | &lookup_it_processor, | ||
859 | request, | ||
860 | &lookup_it_finished, | ||
861 | request); | ||
862 | break; | ||
863 | |||
864 | case RP_LOOKUP: | ||
865 | break; | ||
866 | |||
867 | case RP_PUT: | ||
868 | break; | ||
869 | |||
870 | case RP_FAIL: | ||
871 | return fill_s_reply ("Request failed, sorry.", | ||
872 | request, connection); | ||
873 | |||
874 | case RP_SUCCESS: | ||
875 | return fill_s_reply ("Success.", | ||
876 | request, connection); | ||
877 | |||
878 | default: | ||
879 | GNUNET_break (0); | ||
880 | return MHD_NO; | ||
881 | } | ||
882 | return MHD_YES; /* will have a reply later... */ | ||
883 | } | ||
876 | /* unsupported HTTP method */ | 884 | /* unsupported HTTP method */ |
877 | response = MHD_create_response_from_buffer(strlen(METHOD_ERROR), | 885 | response = MHD_create_response_from_buffer (strlen (METHOD_ERROR), |
878 | (void *)METHOD_ERROR, | 886 | (void *) METHOD_ERROR, |
879 | MHD_RESPMEM_PERSISTENT); | 887 | MHD_RESPMEM_PERSISTENT); |
880 | ret = MHD_queue_response(connection, | 888 | ret = MHD_queue_response (connection, |
881 | MHD_HTTP_NOT_ACCEPTABLE, | 889 | MHD_HTTP_NOT_ACCEPTABLE, |
882 | response); | 890 | response); |
883 | MHD_destroy_response(response); | 891 | MHD_destroy_response (response); |
884 | return ret; | 892 | return ret; |
885 | } | 893 | } |
886 | 894 | ||
@@ -895,23 +903,23 @@ create_response(void *cls, | |||
895 | * @param toe status code | 903 | * @param toe status code |
896 | */ | 904 | */ |
897 | static void | 905 | static void |
898 | request_completed_callback(void *cls, | 906 | request_completed_callback (void *cls, |
899 | struct MHD_Connection *connection, | 907 | struct MHD_Connection *connection, |
900 | void **con_cls, | 908 | void **con_cls, |
901 | enum MHD_RequestTerminationCode toe) | 909 | enum MHD_RequestTerminationCode toe) |
902 | { | 910 | { |
903 | struct Request *request = *con_cls; | 911 | struct Request *request = *con_cls; |
904 | 912 | ||
905 | (void)cls; | 913 | (void) cls; |
906 | (void)connection; | 914 | (void) connection; |
907 | (void)toe; | 915 | (void) toe; |
908 | if (NULL == request) | 916 | if (NULL == request) |
909 | return; | 917 | return; |
910 | if (NULL != request->pp) | 918 | if (NULL != request->pp) |
911 | MHD_destroy_post_processor(request->pp); | 919 | MHD_destroy_post_processor (request->pp); |
912 | if (NULL != request->qe) | 920 | if (NULL != request->qe) |
913 | GNUNET_NAMESTORE_cancel(request->qe); | 921 | GNUNET_NAMESTORE_cancel (request->qe); |
914 | GNUNET_free(request); | 922 | GNUNET_free (request); |
915 | } | 923 | } |
916 | 924 | ||
917 | 925 | ||
@@ -922,7 +930,7 @@ request_completed_callback(void *cls, | |||
922 | * Schedule tasks to run MHD server. | 930 | * Schedule tasks to run MHD server. |
923 | */ | 931 | */ |
924 | static void | 932 | static void |
925 | run_httpd() | 933 | run_httpd () |
926 | { | 934 | { |
927 | fd_set rs; | 935 | fd_set rs; |
928 | fd_set ws; | 936 | fd_set ws; |
@@ -935,44 +943,44 @@ run_httpd() | |||
935 | UNSIGNED_MHD_LONG_LONG timeout; | 943 | UNSIGNED_MHD_LONG_LONG timeout; |
936 | struct GNUNET_TIME_Relative tv; | 944 | struct GNUNET_TIME_Relative tv; |
937 | 945 | ||
938 | FD_ZERO(&rs); | 946 | FD_ZERO (&rs); |
939 | FD_ZERO(&ws); | 947 | FD_ZERO (&ws); |
940 | FD_ZERO(&es); | 948 | FD_ZERO (&es); |
941 | wrs = GNUNET_NETWORK_fdset_create(); | 949 | wrs = GNUNET_NETWORK_fdset_create (); |
942 | wes = GNUNET_NETWORK_fdset_create(); | 950 | wes = GNUNET_NETWORK_fdset_create (); |
943 | wws = GNUNET_NETWORK_fdset_create(); | 951 | wws = GNUNET_NETWORK_fdset_create (); |
944 | max = -1; | 952 | max = -1; |
945 | GNUNET_assert(MHD_YES == | 953 | GNUNET_assert (MHD_YES == |
946 | MHD_get_fdset(httpd, | 954 | MHD_get_fdset (httpd, |
947 | &rs, | 955 | &rs, |
948 | &ws, | 956 | &ws, |
949 | &es, | 957 | &es, |
950 | &max)); | 958 | &max)); |
951 | haveto = MHD_get_timeout(httpd, | 959 | haveto = MHD_get_timeout (httpd, |
952 | &timeout); | 960 | &timeout); |
953 | if (haveto == MHD_YES) | 961 | if (haveto == MHD_YES) |
954 | tv.rel_value_us = (uint64_t)timeout * 1000LL; | 962 | tv.rel_value_us = (uint64_t) timeout * 1000LL; |
955 | else | 963 | else |
956 | tv = GNUNET_TIME_UNIT_FOREVER_REL; | 964 | tv = GNUNET_TIME_UNIT_FOREVER_REL; |
957 | GNUNET_NETWORK_fdset_copy_native(wrs, | 965 | GNUNET_NETWORK_fdset_copy_native (wrs, |
958 | &rs, | 966 | &rs, |
959 | max + 1); | 967 | max + 1); |
960 | GNUNET_NETWORK_fdset_copy_native(wws, | 968 | GNUNET_NETWORK_fdset_copy_native (wws, |
961 | &ws, | 969 | &ws, |
962 | max + 1); | 970 | max + 1); |
963 | GNUNET_NETWORK_fdset_copy_native(wes, | 971 | GNUNET_NETWORK_fdset_copy_native (wes, |
964 | &es, | 972 | &es, |
965 | max + 1); | 973 | max + 1); |
966 | httpd_task = | 974 | httpd_task = |
967 | GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_HIGH, | 975 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, |
968 | tv, | 976 | tv, |
969 | wrs, | 977 | wrs, |
970 | wws, | 978 | wws, |
971 | &do_httpd, | 979 | &do_httpd, |
972 | NULL); | 980 | NULL); |
973 | GNUNET_NETWORK_fdset_destroy(wrs); | 981 | GNUNET_NETWORK_fdset_destroy (wrs); |
974 | GNUNET_NETWORK_fdset_destroy(wws); | 982 | GNUNET_NETWORK_fdset_destroy (wws); |
975 | GNUNET_NETWORK_fdset_destroy(wes); | 983 | GNUNET_NETWORK_fdset_destroy (wes); |
976 | } | 984 | } |
977 | 985 | ||
978 | 986 | ||
@@ -982,12 +990,12 @@ run_httpd() | |||
982 | * @param cls unused | 990 | * @param cls unused |
983 | */ | 991 | */ |
984 | static void | 992 | static void |
985 | do_httpd(void *cls) | 993 | do_httpd (void *cls) |
986 | { | 994 | { |
987 | (void)cls; | 995 | (void) cls; |
988 | httpd_task = NULL; | 996 | httpd_task = NULL; |
989 | MHD_run(httpd); | 997 | MHD_run (httpd); |
990 | run_httpd(); | 998 | run_httpd (); |
991 | } | 999 | } |
992 | 1000 | ||
993 | 1001 | ||
@@ -997,39 +1005,39 @@ do_httpd(void *cls) | |||
997 | * @param cls unused | 1005 | * @param cls unused |
998 | */ | 1006 | */ |
999 | static void | 1007 | static void |
1000 | do_shutdown(void *cls) | 1008 | do_shutdown (void *cls) |
1001 | { | 1009 | { |
1002 | (void)cls; | 1010 | (void) cls; |
1003 | if (NULL != httpd_task) | 1011 | if (NULL != httpd_task) |
1004 | { | 1012 | { |
1005 | GNUNET_SCHEDULER_cancel(httpd_task); | 1013 | GNUNET_SCHEDULER_cancel (httpd_task); |
1006 | httpd_task = NULL; | 1014 | httpd_task = NULL; |
1007 | } | 1015 | } |
1008 | if (NULL != uzp_task) | 1016 | if (NULL != uzp_task) |
1009 | { | 1017 | { |
1010 | GNUNET_SCHEDULER_cancel(uzp_task); | 1018 | GNUNET_SCHEDULER_cancel (uzp_task); |
1011 | uzp_task = NULL; | 1019 | uzp_task = NULL; |
1012 | } | 1020 | } |
1013 | if (NULL != ns) | 1021 | if (NULL != ns) |
1014 | { | 1022 | { |
1015 | GNUNET_NAMESTORE_disconnect(ns); | 1023 | GNUNET_NAMESTORE_disconnect (ns); |
1016 | ns = NULL; | 1024 | ns = NULL; |
1017 | } | 1025 | } |
1018 | if (NULL != httpd) | 1026 | if (NULL != httpd) |
1019 | { | 1027 | { |
1020 | MHD_stop_daemon(httpd); | 1028 | MHD_stop_daemon (httpd); |
1021 | httpd = NULL; | 1029 | httpd = NULL; |
1022 | } | 1030 | } |
1023 | if (NULL != id_op) | 1031 | if (NULL != id_op) |
1024 | { | 1032 | { |
1025 | GNUNET_IDENTITY_cancel(id_op); | 1033 | GNUNET_IDENTITY_cancel (id_op); |
1026 | id_op = NULL; | 1034 | id_op = NULL; |
1027 | } | 1035 | } |
1028 | if (NULL != identity) | 1036 | if (NULL != identity) |
1029 | { | 1037 | { |
1030 | GNUNET_IDENTITY_disconnect(identity); | 1038 | GNUNET_IDENTITY_disconnect (identity); |
1031 | identity = NULL; | 1039 | identity = NULL; |
1032 | } | 1040 | } |
1033 | } | 1041 | } |
1034 | 1042 | ||
1035 | 1043 | ||
@@ -1053,55 +1061,59 @@ do_shutdown(void *cls) | |||
1053 | * must thus no longer be used | 1061 | * must thus no longer be used |
1054 | */ | 1062 | */ |
1055 | static void | 1063 | static void |
1056 | identity_cb(void *cls, | 1064 | identity_cb (void *cls, |
1057 | struct GNUNET_IDENTITY_Ego *ego, | 1065 | struct GNUNET_IDENTITY_Ego *ego, |
1058 | void **ctx, | 1066 | void **ctx, |
1059 | const char *name) | 1067 | const char *name) |
1060 | { | 1068 | { |
1061 | int options; | 1069 | int options; |
1062 | 1070 | ||
1063 | (void)cls; | 1071 | (void) cls; |
1064 | (void)ctx; | 1072 | (void) ctx; |
1065 | if (NULL == name) | 1073 | if (NULL == name) |
1066 | return; | 1074 | return; |
1067 | if (0 != strcmp(name, | 1075 | if (0 != strcmp (name, |
1068 | zone)) | 1076 | zone)) |
1069 | return; | 1077 | return; |
1070 | if (NULL == ego) | 1078 | if (NULL == ego) |
1071 | { | 1079 | { |
1072 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1080 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1073 | _("No ego configured for `fcfsd` subsystem\n")); | 1081 | _ ("No ego configured for `fcfsd` subsystem\n")); |
1074 | GNUNET_SCHEDULER_shutdown(); | 1082 | GNUNET_SCHEDULER_shutdown (); |
1075 | return; | 1083 | return; |
1076 | } | 1084 | } |
1077 | fcfs_zone_pkey = *GNUNET_IDENTITY_ego_get_private_key(ego); | 1085 | fcfs_zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego); |
1078 | 1086 | ||
1079 | options = MHD_USE_DUAL_STACK | MHD_USE_DEBUG | MHD_ALLOW_SUSPEND_RESUME; | 1087 | options = MHD_USE_DUAL_STACK | MHD_USE_DEBUG | MHD_ALLOW_SUSPEND_RESUME; |
1080 | do | 1088 | do |
1081 | { | 1089 | { |
1082 | httpd = MHD_start_daemon(options, | 1090 | httpd = MHD_start_daemon (options, |
1083 | (uint16_t)port, | 1091 | (uint16_t) port, |
1084 | NULL, NULL, | 1092 | NULL, NULL, |
1085 | &create_response, NULL, | 1093 | &create_response, NULL, |
1086 | MHD_OPTION_CONNECTION_LIMIT, (unsigned int)128, | 1094 | MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 128, |
1087 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int)1, | 1095 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned |
1088 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int)16, | 1096 | int) 1, |
1089 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t)(4 * 1024), | 1097 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16, |
1090 | MHD_OPTION_NOTIFY_COMPLETED, &request_completed_callback, NULL, | 1098 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (4 |
1091 | MHD_OPTION_END); | 1099 | * |
1092 | if (MHD_USE_DEBUG == options) | 1100 | 1024), |
1093 | break; | 1101 | MHD_OPTION_NOTIFY_COMPLETED, |
1094 | options = MHD_USE_DEBUG; | 1102 | &request_completed_callback, NULL, |
1095 | } | 1103 | MHD_OPTION_END); |
1104 | if (MHD_USE_DEBUG == options) | ||
1105 | break; | ||
1106 | options = MHD_USE_DEBUG; | ||
1107 | } | ||
1096 | while (NULL == httpd); | 1108 | while (NULL == httpd); |
1097 | if (NULL == httpd) | 1109 | if (NULL == httpd) |
1098 | { | 1110 | { |
1099 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1111 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1100 | _("Failed to start HTTP server\n")); | 1112 | _ ("Failed to start HTTP server\n")); |
1101 | GNUNET_SCHEDULER_shutdown(); | 1113 | GNUNET_SCHEDULER_shutdown (); |
1102 | return; | 1114 | return; |
1103 | } | 1115 | } |
1104 | run_httpd(); | 1116 | run_httpd (); |
1105 | } | 1117 | } |
1106 | 1118 | ||
1107 | 1119 | ||
@@ -1114,44 +1126,44 @@ identity_cb(void *cls, | |||
1114 | * @param cfg configuration | 1126 | * @param cfg configuration |
1115 | */ | 1127 | */ |
1116 | static void | 1128 | static void |
1117 | run(void *cls, | 1129 | run (void *cls, |
1118 | char *const *args, | 1130 | char *const *args, |
1119 | const char *cfgfile, | 1131 | const char *cfgfile, |
1120 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 1132 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
1121 | { | 1133 | { |
1122 | (void)cls; | 1134 | (void) cls; |
1123 | (void)args; | 1135 | (void) args; |
1124 | (void)cfgfile; | 1136 | (void) cfgfile; |
1125 | if (GNUNET_OK != | 1137 | if (GNUNET_OK != |
1126 | GNUNET_CONFIGURATION_get_value_number(cfg, | 1138 | GNUNET_CONFIGURATION_get_value_number (cfg, |
1127 | "fcfsd", | 1139 | "fcfsd", |
1128 | "HTTPPORT", | 1140 | "HTTPPORT", |
1129 | &port)) | 1141 | &port)) |
1130 | { | 1142 | { |
1131 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, | 1143 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
1132 | "fcfsd", "HTTPPORT"); | 1144 | "fcfsd", "HTTPPORT"); |
1133 | return; | 1145 | return; |
1134 | } | 1146 | } |
1135 | ns = GNUNET_NAMESTORE_connect(cfg); | 1147 | ns = GNUNET_NAMESTORE_connect (cfg); |
1136 | if (NULL == ns) | 1148 | if (NULL == ns) |
1137 | { | 1149 | { |
1138 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1150 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1139 | _("Failed to connect to namestore\n")); | 1151 | _ ("Failed to connect to namestore\n")); |
1140 | return; | 1152 | return; |
1141 | } | 1153 | } |
1142 | identity = GNUNET_IDENTITY_connect(cfg, | 1154 | identity = GNUNET_IDENTITY_connect (cfg, |
1143 | &identity_cb, | 1155 | &identity_cb, |
1144 | NULL); | ||
1145 | if (NULL == identity) | ||
1146 | { | ||
1147 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
1148 | _("Failed to connect to identity\n")); | ||
1149 | return; | ||
1150 | } | ||
1151 | uzp_task = GNUNET_SCHEDULER_add_now(&update_zoneinfo_page, | ||
1152 | NULL); | 1156 | NULL); |
1153 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, | 1157 | if (NULL == identity) |
1154 | NULL); | 1158 | { |
1159 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1160 | _ ("Failed to connect to identity\n")); | ||
1161 | return; | ||
1162 | } | ||
1163 | uzp_task = GNUNET_SCHEDULER_add_now (&update_zoneinfo_page, | ||
1164 | NULL); | ||
1165 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | ||
1166 | NULL); | ||
1155 | } | 1167 | } |
1156 | 1168 | ||
1157 | 1169 | ||
@@ -1163,38 +1175,40 @@ run(void *cls, | |||
1163 | * @return 0 ok, 1 on error | 1175 | * @return 0 ok, 1 on error |
1164 | */ | 1176 | */ |
1165 | int | 1177 | int |
1166 | main(int argc, | 1178 | main (int argc, |
1167 | char *const *argv) | 1179 | char *const *argv) |
1168 | { | 1180 | { |
1169 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 1181 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
1170 | GNUNET_GETOPT_option_mandatory | 1182 | GNUNET_GETOPT_option_mandatory |
1171 | (GNUNET_GETOPT_option_string('z', | 1183 | (GNUNET_GETOPT_option_string ('z', |
1172 | "zone", | 1184 | "zone", |
1173 | "EGO", | 1185 | "EGO", |
1174 | gettext_noop("name of the zone that is to be managed by FCFSD"), | 1186 | gettext_noop ( |
1175 | &zone)), | 1187 | "name of the zone that is to be managed by FCFSD"), |
1188 | &zone)), | ||
1176 | GNUNET_GETOPT_OPTION_END | 1189 | GNUNET_GETOPT_OPTION_END |
1177 | }; | 1190 | }; |
1178 | int ret; | 1191 | int ret; |
1179 | 1192 | ||
1180 | if (GNUNET_OK != | 1193 | if (GNUNET_OK != |
1181 | GNUNET_STRINGS_get_utf8_args(argc, argv, | 1194 | GNUNET_STRINGS_get_utf8_args (argc, argv, |
1182 | &argc, &argv)) | 1195 | &argc, &argv)) |
1183 | return 2; | 1196 | return 2; |
1184 | 1197 | ||
1185 | GNUNET_log_setup("fcfsd", | 1198 | GNUNET_log_setup ("fcfsd", |
1186 | "WARNING", | 1199 | "WARNING", |
1187 | NULL); | 1200 | NULL); |
1188 | ret = | 1201 | ret = |
1189 | (GNUNET_OK == | 1202 | (GNUNET_OK == |
1190 | GNUNET_PROGRAM_run(argc, | 1203 | GNUNET_PROGRAM_run (argc, |
1191 | argv, | 1204 | argv, |
1192 | "gnunet-namestore-fcfsd", | 1205 | "gnunet-namestore-fcfsd", |
1193 | _("GNU Name System First Come First Serve name registration service"), | 1206 | _ ( |
1194 | options, | 1207 | "GNU Name System First Come First Serve name registration service"), |
1195 | &run, NULL)) ? 0 : 1; | 1208 | options, |
1196 | GNUNET_free((void*)argv); | 1209 | &run, NULL)) ? 0 : 1; |
1197 | GNUNET_CRYPTO_ecdsa_key_clear(&fcfs_zone_pkey); | 1210 | GNUNET_free ((void*) argv); |
1211 | GNUNET_CRYPTO_ecdsa_key_clear (&fcfs_zone_pkey); | ||
1198 | return ret; | 1212 | return ret; |
1199 | } | 1213 | } |
1200 | 1214 | ||
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c index cc1362a51..65c0f7726 100644 --- a/src/namestore/gnunet-namestore.c +++ b/src/namestore/gnunet-namestore.c | |||
@@ -37,7 +37,8 @@ | |||
37 | /** | 37 | /** |
38 | * Entry in record set for bulk processing. | 38 | * Entry in record set for bulk processing. |
39 | */ | 39 | */ |
40 | struct RecordSetEntry { | 40 | struct RecordSetEntry |
41 | { | ||
41 | /** | 42 | /** |
42 | * Kept in a linked list. | 43 | * Kept in a linked list. |
43 | */ | 44 | */ |
@@ -227,75 +228,75 @@ static struct RecordSetEntry *recordset; | |||
227 | * @param cls unused | 228 | * @param cls unused |
228 | */ | 229 | */ |
229 | static void | 230 | static void |
230 | do_shutdown(void *cls) | 231 | do_shutdown (void *cls) |
231 | { | 232 | { |
232 | (void)cls; | 233 | (void) cls; |
233 | if (NULL != get_default) | 234 | if (NULL != get_default) |
234 | { | 235 | { |
235 | GNUNET_IDENTITY_cancel(get_default); | 236 | GNUNET_IDENTITY_cancel (get_default); |
236 | get_default = NULL; | 237 | get_default = NULL; |
237 | } | 238 | } |
238 | if (NULL != idh) | 239 | if (NULL != idh) |
239 | { | 240 | { |
240 | GNUNET_IDENTITY_disconnect(idh); | 241 | GNUNET_IDENTITY_disconnect (idh); |
241 | idh = NULL; | 242 | idh = NULL; |
242 | } | 243 | } |
243 | if (NULL != el) | 244 | if (NULL != el) |
244 | { | 245 | { |
245 | GNUNET_IDENTITY_ego_lookup_cancel(el); | 246 | GNUNET_IDENTITY_ego_lookup_cancel (el); |
246 | el = NULL; | 247 | el = NULL; |
247 | } | 248 | } |
248 | if (NULL != list_it) | 249 | if (NULL != list_it) |
249 | { | 250 | { |
250 | GNUNET_NAMESTORE_zone_iteration_stop(list_it); | 251 | GNUNET_NAMESTORE_zone_iteration_stop (list_it); |
251 | list_it = NULL; | 252 | list_it = NULL; |
252 | } | 253 | } |
253 | if (NULL != add_qe) | 254 | if (NULL != add_qe) |
254 | { | 255 | { |
255 | GNUNET_NAMESTORE_cancel(add_qe); | 256 | GNUNET_NAMESTORE_cancel (add_qe); |
256 | add_qe = NULL; | 257 | add_qe = NULL; |
257 | } | 258 | } |
258 | if (NULL != set_qe) | 259 | if (NULL != set_qe) |
259 | { | 260 | { |
260 | GNUNET_NAMESTORE_cancel(set_qe); | 261 | GNUNET_NAMESTORE_cancel (set_qe); |
261 | set_qe = NULL; | 262 | set_qe = NULL; |
262 | } | 263 | } |
263 | if (NULL != add_qe_uri) | 264 | if (NULL != add_qe_uri) |
264 | { | 265 | { |
265 | GNUNET_NAMESTORE_cancel(add_qe_uri); | 266 | GNUNET_NAMESTORE_cancel (add_qe_uri); |
266 | add_qe_uri = NULL; | 267 | add_qe_uri = NULL; |
267 | } | 268 | } |
268 | if (NULL != get_qe) | 269 | if (NULL != get_qe) |
269 | { | 270 | { |
270 | GNUNET_NAMESTORE_cancel(get_qe); | 271 | GNUNET_NAMESTORE_cancel (get_qe); |
271 | get_qe = NULL; | 272 | get_qe = NULL; |
272 | } | 273 | } |
273 | if (NULL != del_qe) | 274 | if (NULL != del_qe) |
274 | { | 275 | { |
275 | GNUNET_NAMESTORE_cancel(del_qe); | 276 | GNUNET_NAMESTORE_cancel (del_qe); |
276 | del_qe = NULL; | 277 | del_qe = NULL; |
277 | } | 278 | } |
278 | if (NULL != ns) | 279 | if (NULL != ns) |
279 | { | 280 | { |
280 | GNUNET_NAMESTORE_disconnect(ns); | 281 | GNUNET_NAMESTORE_disconnect (ns); |
281 | ns = NULL; | 282 | ns = NULL; |
282 | } | 283 | } |
283 | memset(&zone_pkey, 0, sizeof(zone_pkey)); | 284 | memset (&zone_pkey, 0, sizeof(zone_pkey)); |
284 | if (NULL != uri) | 285 | if (NULL != uri) |
285 | { | 286 | { |
286 | GNUNET_free(uri); | 287 | GNUNET_free (uri); |
287 | uri = NULL; | 288 | uri = NULL; |
288 | } | 289 | } |
289 | if (NULL != zm) | 290 | if (NULL != zm) |
290 | { | 291 | { |
291 | GNUNET_NAMESTORE_zone_monitor_stop(zm); | 292 | GNUNET_NAMESTORE_zone_monitor_stop (zm); |
292 | zm = NULL; | 293 | zm = NULL; |
293 | } | 294 | } |
294 | if (NULL != data) | 295 | if (NULL != data) |
295 | { | 296 | { |
296 | GNUNET_free(data); | 297 | GNUNET_free (data); |
297 | data = NULL; | 298 | data = NULL; |
298 | } | 299 | } |
299 | } | 300 | } |
300 | 301 | ||
301 | 302 | ||
@@ -303,11 +304,11 @@ do_shutdown(void *cls) | |||
303 | * Check if we are finished, and if so, perform shutdown. | 304 | * Check if we are finished, and if so, perform shutdown. |
304 | */ | 305 | */ |
305 | static void | 306 | static void |
306 | test_finished() | 307 | test_finished () |
307 | { | 308 | { |
308 | if ((NULL == add_qe) && (NULL == add_qe_uri) && (NULL == get_qe) && | 309 | if ((NULL == add_qe) && (NULL == add_qe_uri) && (NULL == get_qe) && |
309 | (NULL == del_qe) && (NULL == reverse_qe) && (NULL == list_it)) | 310 | (NULL == del_qe) && (NULL == reverse_qe) && (NULL == list_it)) |
310 | GNUNET_SCHEDULER_shutdown(); | 311 | GNUNET_SCHEDULER_shutdown (); |
311 | } | 312 | } |
312 | 313 | ||
313 | 314 | ||
@@ -322,21 +323,21 @@ test_finished() | |||
322 | * @param emsg NULL on success, otherwise an error message | 323 | * @param emsg NULL on success, otherwise an error message |
323 | */ | 324 | */ |
324 | static void | 325 | static void |
325 | add_continuation(void *cls, int32_t success, const char *emsg) | 326 | add_continuation (void *cls, int32_t success, const char *emsg) |
326 | { | 327 | { |
327 | struct GNUNET_NAMESTORE_QueueEntry **qe = cls; | 328 | struct GNUNET_NAMESTORE_QueueEntry **qe = cls; |
328 | 329 | ||
329 | *qe = NULL; | 330 | *qe = NULL; |
330 | if (GNUNET_YES != success) | 331 | if (GNUNET_YES != success) |
331 | { | 332 | { |
332 | fprintf(stderr, | 333 | fprintf (stderr, |
333 | _("Adding record failed: %s\n"), | 334 | _ ("Adding record failed: %s\n"), |
334 | (GNUNET_NO == success) ? "record exists" : emsg); | 335 | (GNUNET_NO == success) ? "record exists" : emsg); |
335 | if (GNUNET_NO != success) | 336 | if (GNUNET_NO != success) |
336 | ret = 1; | 337 | ret = 1; |
337 | } | 338 | } |
338 | ret = 0; | 339 | ret = 0; |
339 | test_finished(); | 340 | test_finished (); |
340 | } | 341 | } |
341 | 342 | ||
342 | 343 | ||
@@ -351,25 +352,25 @@ add_continuation(void *cls, int32_t success, const char *emsg) | |||
351 | * @param emsg NULL on success, otherwise an error message | 352 | * @param emsg NULL on success, otherwise an error message |
352 | */ | 353 | */ |
353 | static void | 354 | static void |
354 | del_continuation(void *cls, int32_t success, const char *emsg) | 355 | del_continuation (void *cls, int32_t success, const char *emsg) |
355 | { | 356 | { |
356 | (void)cls; | 357 | (void) cls; |
357 | del_qe = NULL; | 358 | del_qe = NULL; |
358 | if (GNUNET_NO == success) | 359 | if (GNUNET_NO == success) |
359 | { | 360 | { |
360 | fprintf(stderr, | 361 | fprintf (stderr, |
361 | _("Deleting record failed, record does not exist%s%s\n"), | 362 | _ ("Deleting record failed, record does not exist%s%s\n"), |
362 | (NULL != emsg) ? ": " : "", | 363 | (NULL != emsg) ? ": " : "", |
363 | (NULL != emsg) ? emsg : ""); | 364 | (NULL != emsg) ? emsg : ""); |
364 | } | 365 | } |
365 | if (GNUNET_SYSERR == success) | 366 | if (GNUNET_SYSERR == success) |
366 | { | 367 | { |
367 | fprintf(stderr, | 368 | fprintf (stderr, |
368 | _("Deleting record failed%s%s\n"), | 369 | _ ("Deleting record failed%s%s\n"), |
369 | (NULL != emsg) ? ": " : "", | 370 | (NULL != emsg) ? ": " : "", |
370 | (NULL != emsg) ? emsg : ""); | 371 | (NULL != emsg) ? emsg : ""); |
371 | } | 372 | } |
372 | test_finished(); | 373 | test_finished (); |
373 | } | 374 | } |
374 | 375 | ||
375 | 376 | ||
@@ -377,11 +378,11 @@ del_continuation(void *cls, int32_t success, const char *emsg) | |||
377 | * Function called when we are done with a zone iteration. | 378 | * Function called when we are done with a zone iteration. |
378 | */ | 379 | */ |
379 | static void | 380 | static void |
380 | zone_iteration_finished(void *cls) | 381 | zone_iteration_finished (void *cls) |
381 | { | 382 | { |
382 | (void)cls; | 383 | (void) cls; |
383 | list_it = NULL; | 384 | list_it = NULL; |
384 | test_finished(); | 385 | test_finished (); |
385 | } | 386 | } |
386 | 387 | ||
387 | 388 | ||
@@ -389,13 +390,13 @@ zone_iteration_finished(void *cls) | |||
389 | * Function called when we encountered an error in a zone iteration. | 390 | * Function called when we encountered an error in a zone iteration. |
390 | */ | 391 | */ |
391 | static void | 392 | static void |
392 | zone_iteration_error_cb(void *cls) | 393 | zone_iteration_error_cb (void *cls) |
393 | { | 394 | { |
394 | (void)cls; | 395 | (void) cls; |
395 | list_it = NULL; | 396 | list_it = NULL; |
396 | fprintf(stderr, "Error iterating over zone\n"); | 397 | fprintf (stderr, "Error iterating over zone\n"); |
397 | ret = 1; | 398 | ret = 1; |
398 | test_finished(); | 399 | test_finished (); |
399 | } | 400 | } |
400 | 401 | ||
401 | 402 | ||
@@ -407,9 +408,9 @@ zone_iteration_error_cb(void *cls) | |||
407 | * @param rd array of records with data to store | 408 | * @param rd array of records with data to store |
408 | */ | 409 | */ |
409 | static void | 410 | static void |
410 | display_record(const char *rname, | 411 | display_record (const char *rname, |
411 | unsigned int rd_len, | 412 | unsigned int rd_len, |
412 | const struct GNUNET_GNSRECORD_Data *rd) | 413 | const struct GNUNET_GNSRECORD_Data *rd) |
413 | { | 414 | { |
414 | const char *typestr; | 415 | const char *typestr; |
415 | char *s; | 416 | char *s; |
@@ -418,69 +419,69 @@ display_record(const char *rname, | |||
418 | struct GNUNET_TIME_Relative rt; | 419 | struct GNUNET_TIME_Relative rt; |
419 | int have_record; | 420 | int have_record; |
420 | 421 | ||
421 | if ((NULL != name) && (0 != strcmp(name, rname))) | 422 | if ((NULL != name) && (0 != strcmp (name, rname))) |
422 | { | 423 | { |
423 | GNUNET_NAMESTORE_zone_iterator_next(list_it, 1); | 424 | GNUNET_NAMESTORE_zone_iterator_next (list_it, 1); |
424 | return; | 425 | return; |
425 | } | 426 | } |
426 | have_record = GNUNET_NO; | 427 | have_record = GNUNET_NO; |
427 | for (unsigned int i = 0; i < rd_len; i++) | 428 | for (unsigned int i = 0; i < rd_len; i++) |
428 | { | 429 | { |
429 | if ((GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) && | 430 | if ((GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) && |
430 | (0 != strcmp(rname, GNUNET_GNS_EMPTY_LABEL_AT))) | 431 | (0 != strcmp (rname, GNUNET_GNS_EMPTY_LABEL_AT))) |
431 | continue; | 432 | continue; |
432 | if ((type != rd[i].record_type) && (GNUNET_GNSRECORD_TYPE_ANY != type)) | 433 | if ((type != rd[i].record_type) && (GNUNET_GNSRECORD_TYPE_ANY != type)) |
433 | continue; | 434 | continue; |
434 | have_record = GNUNET_YES; | 435 | have_record = GNUNET_YES; |
435 | break; | 436 | break; |
436 | } | 437 | } |
437 | if (GNUNET_NO == have_record) | 438 | if (GNUNET_NO == have_record) |
438 | return; | 439 | return; |
439 | fprintf(stdout, "%s:\n", rname); | 440 | fprintf (stdout, "%s:\n", rname); |
440 | if (NULL != typestring) | 441 | if (NULL != typestring) |
441 | type = GNUNET_GNSRECORD_typename_to_number(typestring); | 442 | type = GNUNET_GNSRECORD_typename_to_number (typestring); |
442 | else | 443 | else |
443 | type = GNUNET_GNSRECORD_TYPE_ANY; | 444 | type = GNUNET_GNSRECORD_TYPE_ANY; |
444 | for (unsigned int i = 0; i < rd_len; i++) | 445 | for (unsigned int i = 0; i < rd_len; i++) |
446 | { | ||
447 | if ((GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) && | ||
448 | (0 != strcmp (rname, GNUNET_GNS_EMPTY_LABEL_AT))) | ||
449 | continue; | ||
450 | if ((type != rd[i].record_type) && (GNUNET_GNSRECORD_TYPE_ANY != type)) | ||
451 | continue; | ||
452 | typestr = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type); | ||
453 | s = GNUNET_GNSRECORD_value_to_string (rd[i].record_type, | ||
454 | rd[i].data, | ||
455 | rd[i].data_size); | ||
456 | if (NULL == s) | ||
457 | { | ||
458 | fprintf (stdout, | ||
459 | _ ("\tCorrupt or unsupported record of type %u\n"), | ||
460 | (unsigned int) rd[i].record_type); | ||
461 | continue; | ||
462 | } | ||
463 | if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) | ||
464 | { | ||
465 | rt.rel_value_us = rd[i].expiration_time; | ||
466 | ets = GNUNET_STRINGS_relative_time_to_string (rt, GNUNET_YES); | ||
467 | } | ||
468 | else | ||
445 | { | 469 | { |
446 | if ((GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) && | 470 | at.abs_value_us = rd[i].expiration_time; |
447 | (0 != strcmp(rname, GNUNET_GNS_EMPTY_LABEL_AT))) | 471 | ets = GNUNET_STRINGS_absolute_time_to_string (at); |
448 | continue; | ||
449 | if ((type != rd[i].record_type) && (GNUNET_GNSRECORD_TYPE_ANY != type)) | ||
450 | continue; | ||
451 | typestr = GNUNET_GNSRECORD_number_to_typename(rd[i].record_type); | ||
452 | s = GNUNET_GNSRECORD_value_to_string(rd[i].record_type, | ||
453 | rd[i].data, | ||
454 | rd[i].data_size); | ||
455 | if (NULL == s) | ||
456 | { | ||
457 | fprintf(stdout, | ||
458 | _("\tCorrupt or unsupported record of type %u\n"), | ||
459 | (unsigned int)rd[i].record_type); | ||
460 | continue; | ||
461 | } | ||
462 | if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) | ||
463 | { | ||
464 | rt.rel_value_us = rd[i].expiration_time; | ||
465 | ets = GNUNET_STRINGS_relative_time_to_string(rt, GNUNET_YES); | ||
466 | } | ||
467 | else | ||
468 | { | ||
469 | at.abs_value_us = rd[i].expiration_time; | ||
470 | ets = GNUNET_STRINGS_absolute_time_to_string(at); | ||
471 | } | ||
472 | fprintf(stdout, | ||
473 | "\t%s: %s (%s)\t%s\t%s\n", | ||
474 | typestr, | ||
475 | s, | ||
476 | ets, | ||
477 | (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE)) ? "PRIVATE" | ||
478 | : "PUBLIC", | ||
479 | (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)) ? "SHADOW" | ||
480 | : ""); | ||
481 | GNUNET_free(s); | ||
482 | } | 472 | } |
483 | fprintf(stdout, "%s", "\n"); | 473 | fprintf (stdout, |
474 | "\t%s: %s (%s)\t%s\t%s\n", | ||
475 | typestr, | ||
476 | s, | ||
477 | ets, | ||
478 | (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE)) ? "PRIVATE" | ||
479 | : "PUBLIC", | ||
480 | (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)) ? "SHADOW" | ||
481 | : ""); | ||
482 | GNUNET_free (s); | ||
483 | } | ||
484 | fprintf (stdout, "%s", "\n"); | ||
484 | } | 485 | } |
485 | 486 | ||
486 | 487 | ||
@@ -494,16 +495,16 @@ display_record(const char *rname, | |||
494 | * @param rd array of records with data to store | 495 | * @param rd array of records with data to store |
495 | */ | 496 | */ |
496 | static void | 497 | static void |
497 | display_record_iterator(void *cls, | 498 | display_record_iterator (void *cls, |
498 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 499 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, |
499 | const char *rname, | 500 | const char *rname, |
500 | unsigned int rd_len, | 501 | unsigned int rd_len, |
501 | const struct GNUNET_GNSRECORD_Data *rd) | 502 | const struct GNUNET_GNSRECORD_Data *rd) |
502 | { | 503 | { |
503 | (void)cls; | 504 | (void) cls; |
504 | (void)zone_key; | 505 | (void) zone_key; |
505 | display_record(rname, rd_len, rd); | 506 | display_record (rname, rd_len, rd); |
506 | GNUNET_NAMESTORE_zone_iterator_next(list_it, 1); | 507 | GNUNET_NAMESTORE_zone_iterator_next (list_it, 1); |
507 | } | 508 | } |
508 | 509 | ||
509 | 510 | ||
@@ -517,16 +518,16 @@ display_record_iterator(void *cls, | |||
517 | * @param rd array of records with data to store | 518 | * @param rd array of records with data to store |
518 | */ | 519 | */ |
519 | static void | 520 | static void |
520 | display_record_monitor(void *cls, | 521 | display_record_monitor (void *cls, |
521 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 522 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, |
522 | const char *rname, | 523 | const char *rname, |
523 | unsigned int rd_len, | 524 | unsigned int rd_len, |
524 | const struct GNUNET_GNSRECORD_Data *rd) | 525 | const struct GNUNET_GNSRECORD_Data *rd) |
525 | { | 526 | { |
526 | (void)cls; | 527 | (void) cls; |
527 | (void)zone_key; | 528 | (void) zone_key; |
528 | display_record(rname, rd_len, rd); | 529 | display_record (rname, rd_len, rd); |
529 | GNUNET_NAMESTORE_zone_monitor_next(zm, 1); | 530 | GNUNET_NAMESTORE_zone_monitor_next (zm, 1); |
530 | } | 531 | } |
531 | 532 | ||
532 | 533 | ||
@@ -540,17 +541,17 @@ display_record_monitor(void *cls, | |||
540 | * @param rd array of records with data to store | 541 | * @param rd array of records with data to store |
541 | */ | 542 | */ |
542 | static void | 543 | static void |
543 | display_record_lookup(void *cls, | 544 | display_record_lookup (void *cls, |
544 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 545 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, |
545 | const char *rname, | 546 | const char *rname, |
546 | unsigned int rd_len, | 547 | unsigned int rd_len, |
547 | const struct GNUNET_GNSRECORD_Data *rd) | 548 | const struct GNUNET_GNSRECORD_Data *rd) |
548 | { | 549 | { |
549 | (void)cls; | 550 | (void) cls; |
550 | (void)zone_key; | 551 | (void) zone_key; |
551 | get_qe = NULL; | 552 | get_qe = NULL; |
552 | display_record(rname, rd_len, rd); | 553 | display_record (rname, rd_len, rd); |
553 | test_finished(); | 554 | test_finished (); |
554 | } | 555 | } |
555 | 556 | ||
556 | 557 | ||
@@ -560,10 +561,10 @@ display_record_lookup(void *cls, | |||
560 | * @param cls NULL | 561 | * @param cls NULL |
561 | */ | 562 | */ |
562 | static void | 563 | static void |
563 | sync_cb(void *cls) | 564 | sync_cb (void *cls) |
564 | { | 565 | { |
565 | (void)cls; | 566 | (void) cls; |
566 | fprintf(stdout, "%s", "Monitor is now in sync.\n"); | 567 | fprintf (stdout, "%s", "Monitor is now in sync.\n"); |
567 | } | 568 | } |
568 | 569 | ||
569 | 570 | ||
@@ -573,10 +574,10 @@ sync_cb(void *cls) | |||
573 | * @param cls NULL | 574 | * @param cls NULL |
574 | */ | 575 | */ |
575 | static void | 576 | static void |
576 | monitor_error_cb(void *cls) | 577 | monitor_error_cb (void *cls) |
577 | { | 578 | { |
578 | (void)cls; | 579 | (void) cls; |
579 | fprintf(stderr, "%s", "Monitor disconnected and out of sync.\n"); | 580 | fprintf (stderr, "%s", "Monitor disconnected and out of sync.\n"); |
580 | } | 581 | } |
581 | 582 | ||
582 | 583 | ||
@@ -586,12 +587,12 @@ monitor_error_cb(void *cls) | |||
586 | * @param cls NULL | 587 | * @param cls NULL |
587 | */ | 588 | */ |
588 | static void | 589 | static void |
589 | lookup_error_cb(void *cls) | 590 | lookup_error_cb (void *cls) |
590 | { | 591 | { |
591 | (void)cls; | 592 | (void) cls; |
592 | get_qe = NULL; | 593 | get_qe = NULL; |
593 | fprintf(stderr, "%s", "Failed to lookup record.\n"); | 594 | fprintf (stderr, "%s", "Failed to lookup record.\n"); |
594 | test_finished(); | 595 | test_finished (); |
595 | } | 596 | } |
596 | 597 | ||
597 | 598 | ||
@@ -599,13 +600,13 @@ lookup_error_cb(void *cls) | |||
599 | * Function called if lookup fails. | 600 | * Function called if lookup fails. |
600 | */ | 601 | */ |
601 | static void | 602 | static void |
602 | add_error_cb(void *cls) | 603 | add_error_cb (void *cls) |
603 | { | 604 | { |
604 | (void)cls; | 605 | (void) cls; |
605 | add_qe = NULL; | 606 | add_qe = NULL; |
606 | GNUNET_break(0); | 607 | GNUNET_break (0); |
607 | ret = 1; | 608 | ret = 1; |
608 | test_finished(); | 609 | test_finished (); |
609 | } | 610 | } |
610 | 611 | ||
611 | 612 | ||
@@ -620,118 +621,118 @@ add_error_cb(void *cls) | |||
620 | * @param rd array of records with data to store | 621 | * @param rd array of records with data to store |
621 | */ | 622 | */ |
622 | static void | 623 | static void |
623 | get_existing_record(void *cls, | 624 | get_existing_record (void *cls, |
624 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 625 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, |
625 | const char *rec_name, | 626 | const char *rec_name, |
626 | unsigned int rd_count, | 627 | unsigned int rd_count, |
627 | const struct GNUNET_GNSRECORD_Data *rd) | 628 | const struct GNUNET_GNSRECORD_Data *rd) |
628 | { | 629 | { |
629 | struct GNUNET_GNSRECORD_Data rdn[rd_count + 1]; | 630 | struct GNUNET_GNSRECORD_Data rdn[rd_count + 1]; |
630 | struct GNUNET_GNSRECORD_Data *rde; | 631 | struct GNUNET_GNSRECORD_Data *rde; |
631 | 632 | ||
632 | (void)cls; | 633 | (void) cls; |
633 | (void)zone_key; | 634 | (void) zone_key; |
634 | add_qe = NULL; | 635 | add_qe = NULL; |
635 | if (0 != strcmp(rec_name, name)) | 636 | if (0 != strcmp (rec_name, name)) |
636 | { | 637 | { |
637 | GNUNET_break(0); | 638 | GNUNET_break (0); |
638 | ret = 1; | 639 | ret = 1; |
639 | test_finished(); | 640 | test_finished (); |
640 | return; | 641 | return; |
641 | } | 642 | } |
642 | 643 | ||
643 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 644 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
644 | "Received %u records for name `%s'\n", | 645 | "Received %u records for name `%s'\n", |
645 | rd_count, | 646 | rd_count, |
646 | rec_name); | 647 | rec_name); |
647 | for (unsigned int i = 0; i < rd_count; i++) | 648 | for (unsigned int i = 0; i < rd_count; i++) |
648 | { | 649 | { |
649 | switch (rd[i].record_type) | 650 | switch (rd[i].record_type) |
650 | { | ||
651 | case GNUNET_DNSPARSER_TYPE_CNAME: | ||
652 | fprintf( | ||
653 | stderr, | ||
654 | _( | ||
655 | "A %s record exists already under `%s', no other records can be added.\n"), | ||
656 | "CNAME", | ||
657 | rec_name); | ||
658 | ret = 1; | ||
659 | test_finished(); | ||
660 | return; | ||
661 | |||
662 | case GNUNET_GNSRECORD_TYPE_PKEY: | ||
663 | fprintf( | ||
664 | stderr, | ||
665 | _( | ||
666 | "A %s record exists already under `%s', no other records can be added.\n"), | ||
667 | "PKEY", | ||
668 | rec_name); | ||
669 | ret = 1; | ||
670 | test_finished(); | ||
671 | return; | ||
672 | |||
673 | case GNUNET_DNSPARSER_TYPE_SOA: | ||
674 | if (GNUNET_DNSPARSER_TYPE_SOA == type) | ||
675 | { | ||
676 | fprintf( | ||
677 | stderr, | ||
678 | _( | ||
679 | "A SOA record exists already under `%s', cannot add a second SOA to the same zone.\n"), | ||
680 | rec_name); | ||
681 | ret = 1; | ||
682 | test_finished(); | ||
683 | return; | ||
684 | } | ||
685 | break; | ||
686 | } | ||
687 | } | ||
688 | switch (type) | ||
689 | { | 651 | { |
690 | case GNUNET_DNSPARSER_TYPE_CNAME: | 652 | case GNUNET_DNSPARSER_TYPE_CNAME: |
691 | if (0 != rd_count) | 653 | fprintf ( |
692 | { | 654 | stderr, |
693 | fprintf(stderr, | 655 | _ ( |
694 | _( | 656 | "A %s record exists already under `%s', no other records can be added.\n"), |
695 | "Records already exist under `%s', cannot add `%s' record.\n"), | 657 | "CNAME", |
696 | rec_name, | 658 | rec_name); |
697 | "CNAME"); | 659 | ret = 1; |
698 | ret = 1; | 660 | test_finished (); |
699 | test_finished(); | 661 | return; |
700 | return; | ||
701 | } | ||
702 | break; | ||
703 | 662 | ||
704 | case GNUNET_GNSRECORD_TYPE_PKEY: | 663 | case GNUNET_GNSRECORD_TYPE_PKEY: |
705 | if (0 != rd_count) | 664 | fprintf ( |
706 | { | 665 | stderr, |
707 | fprintf(stderr, | 666 | _ ( |
708 | _( | 667 | "A %s record exists already under `%s', no other records can be added.\n"), |
709 | "Records already exist under `%s', cannot add `%s' record.\n"), | 668 | "PKEY", |
710 | rec_name, | 669 | rec_name); |
711 | "PKEY"); | 670 | ret = 1; |
712 | ret = 1; | 671 | test_finished (); |
713 | test_finished(); | 672 | return; |
714 | return; | ||
715 | } | ||
716 | break; | ||
717 | 673 | ||
718 | case GNUNET_GNSRECORD_TYPE_GNS2DNS: | 674 | case GNUNET_DNSPARSER_TYPE_SOA: |
719 | for (unsigned int i = 0; i < rd_count; i++) | 675 | if (GNUNET_DNSPARSER_TYPE_SOA == type) |
720 | if (GNUNET_GNSRECORD_TYPE_GNS2DNS != rd[i].record_type) | 676 | { |
721 | { | 677 | fprintf ( |
722 | fprintf( | 678 | stderr, |
723 | stderr, | 679 | _ ( |
724 | _( | 680 | "A SOA record exists already under `%s', cannot add a second SOA to the same zone.\n"), |
725 | "Non-GNS2DNS records already exist under `%s', cannot add GNS2DNS record.\n"), | 681 | rec_name); |
726 | rec_name); | 682 | ret = 1; |
727 | ret = 1; | 683 | test_finished (); |
728 | test_finished(); | 684 | return; |
729 | return; | 685 | } |
730 | } | ||
731 | break; | 686 | break; |
732 | } | 687 | } |
733 | memset(rdn, 0, sizeof(struct GNUNET_GNSRECORD_Data)); | 688 | } |
734 | GNUNET_memcpy(&rdn[1], rd, rd_count * sizeof(struct GNUNET_GNSRECORD_Data)); | 689 | switch (type) |
690 | { | ||
691 | case GNUNET_DNSPARSER_TYPE_CNAME: | ||
692 | if (0 != rd_count) | ||
693 | { | ||
694 | fprintf (stderr, | ||
695 | _ ( | ||
696 | "Records already exist under `%s', cannot add `%s' record.\n"), | ||
697 | rec_name, | ||
698 | "CNAME"); | ||
699 | ret = 1; | ||
700 | test_finished (); | ||
701 | return; | ||
702 | } | ||
703 | break; | ||
704 | |||
705 | case GNUNET_GNSRECORD_TYPE_PKEY: | ||
706 | if (0 != rd_count) | ||
707 | { | ||
708 | fprintf (stderr, | ||
709 | _ ( | ||
710 | "Records already exist under `%s', cannot add `%s' record.\n"), | ||
711 | rec_name, | ||
712 | "PKEY"); | ||
713 | ret = 1; | ||
714 | test_finished (); | ||
715 | return; | ||
716 | } | ||
717 | break; | ||
718 | |||
719 | case GNUNET_GNSRECORD_TYPE_GNS2DNS: | ||
720 | for (unsigned int i = 0; i < rd_count; i++) | ||
721 | if (GNUNET_GNSRECORD_TYPE_GNS2DNS != rd[i].record_type) | ||
722 | { | ||
723 | fprintf ( | ||
724 | stderr, | ||
725 | _ ( | ||
726 | "Non-GNS2DNS records already exist under `%s', cannot add GNS2DNS record.\n"), | ||
727 | rec_name); | ||
728 | ret = 1; | ||
729 | test_finished (); | ||
730 | return; | ||
731 | } | ||
732 | break; | ||
733 | } | ||
734 | memset (rdn, 0, sizeof(struct GNUNET_GNSRECORD_Data)); | ||
735 | GNUNET_memcpy (&rdn[1], rd, rd_count * sizeof(struct GNUNET_GNSRECORD_Data)); | ||
735 | rde = &rdn[0]; | 736 | rde = &rdn[0]; |
736 | rde->data = data; | 737 | rde->data = data; |
737 | rde->data_size = data_size; | 738 | rde->data_size = data_size; |
@@ -745,14 +746,14 @@ get_existing_record(void *cls, | |||
745 | rde->flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | 746 | rde->flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; |
746 | else if (GNUNET_NO != etime_is_rel) | 747 | else if (GNUNET_NO != etime_is_rel) |
747 | rde->expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; | 748 | rde->expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; |
748 | GNUNET_assert(NULL != name); | 749 | GNUNET_assert (NULL != name); |
749 | add_qe = GNUNET_NAMESTORE_records_store(ns, | 750 | add_qe = GNUNET_NAMESTORE_records_store (ns, |
750 | &zone_pkey, | 751 | &zone_pkey, |
751 | name, | 752 | name, |
752 | rd_count + 1, | 753 | rd_count + 1, |
753 | rde, | 754 | rde, |
754 | &add_continuation, | 755 | &add_continuation, |
755 | &add_qe); | 756 | &add_qe); |
756 | } | 757 | } |
757 | 758 | ||
758 | 759 | ||
@@ -760,11 +761,11 @@ get_existing_record(void *cls, | |||
760 | * Function called if we encountered an error in zone-to-name. | 761 | * Function called if we encountered an error in zone-to-name. |
761 | */ | 762 | */ |
762 | static void | 763 | static void |
763 | reverse_error_cb(void *cls) | 764 | reverse_error_cb (void *cls) |
764 | { | 765 | { |
765 | (void)cls; | 766 | (void) cls; |
766 | reverse_qe = NULL; | 767 | reverse_qe = NULL; |
767 | fprintf(stdout, "%s.zkey\n", reverse_pkey); | 768 | fprintf (stdout, "%s.zkey\n", reverse_pkey); |
768 | } | 769 | } |
769 | 770 | ||
770 | 771 | ||
@@ -779,22 +780,22 @@ reverse_error_cb(void *cls) | |||
779 | * @param rd array of records with data to store | 780 | * @param rd array of records with data to store |
780 | */ | 781 | */ |
781 | static void | 782 | static void |
782 | handle_reverse_lookup(void *cls, | 783 | handle_reverse_lookup (void *cls, |
783 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 784 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
784 | const char *label, | 785 | const char *label, |
785 | unsigned int rd_count, | 786 | unsigned int rd_count, |
786 | const struct GNUNET_GNSRECORD_Data *rd) | 787 | const struct GNUNET_GNSRECORD_Data *rd) |
787 | { | 788 | { |
788 | (void)cls; | 789 | (void) cls; |
789 | (void)zone; | 790 | (void) zone; |
790 | (void)rd_count; | 791 | (void) rd_count; |
791 | (void)rd; | 792 | (void) rd; |
792 | reverse_qe = NULL; | 793 | reverse_qe = NULL; |
793 | if (NULL == label) | 794 | if (NULL == label) |
794 | fprintf(stdout, "%s\n", reverse_pkey); | 795 | fprintf (stdout, "%s\n", reverse_pkey); |
795 | else | 796 | else |
796 | fprintf(stdout, "%s.%s\n", label, ego_name); | 797 | fprintf (stdout, "%s.%s\n", label, ego_name); |
797 | test_finished(); | 798 | test_finished (); |
798 | } | 799 | } |
799 | 800 | ||
800 | 801 | ||
@@ -802,13 +803,13 @@ handle_reverse_lookup(void *cls, | |||
802 | * Function called if lookup for deletion fails. | 803 | * Function called if lookup for deletion fails. |
803 | */ | 804 | */ |
804 | static void | 805 | static void |
805 | del_lookup_error_cb(void *cls) | 806 | del_lookup_error_cb (void *cls) |
806 | { | 807 | { |
807 | (void)cls; | 808 | (void) cls; |
808 | del_qe = NULL; | 809 | del_qe = NULL; |
809 | GNUNET_break(0); | 810 | GNUNET_break (0); |
810 | ret = 1; | 811 | ret = 1; |
811 | test_finished(); | 812 | test_finished (); |
812 | } | 813 | } |
813 | 814 | ||
814 | 815 | ||
@@ -824,80 +825,80 @@ del_lookup_error_cb(void *cls) | |||
824 | * @param rd existing records | 825 | * @param rd existing records |
825 | */ | 826 | */ |
826 | static void | 827 | static void |
827 | del_monitor(void *cls, | 828 | del_monitor (void *cls, |
828 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 829 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
829 | const char *label, | 830 | const char *label, |
830 | unsigned int rd_count, | 831 | unsigned int rd_count, |
831 | const struct GNUNET_GNSRECORD_Data *rd) | 832 | const struct GNUNET_GNSRECORD_Data *rd) |
832 | { | 833 | { |
833 | struct GNUNET_GNSRECORD_Data rdx[rd_count]; | 834 | struct GNUNET_GNSRECORD_Data rdx[rd_count]; |
834 | unsigned int rd_left; | 835 | unsigned int rd_left; |
835 | uint32_t type; | 836 | uint32_t type; |
836 | char *vs; | 837 | char *vs; |
837 | 838 | ||
838 | (void)cls; | 839 | (void) cls; |
839 | (void)zone; | 840 | (void) zone; |
840 | del_qe = NULL; | 841 | del_qe = NULL; |
841 | if (0 == rd_count) | 842 | if (0 == rd_count) |
842 | { | 843 | { |
843 | fprintf(stderr, | 844 | fprintf (stderr, |
844 | _( | 845 | _ ( |
845 | "There are no records under label `%s' that could be deleted.\n"), | 846 | "There are no records under label `%s' that could be deleted.\n"), |
846 | label); | 847 | label); |
847 | ret = 1; | 848 | ret = 1; |
848 | test_finished(); | 849 | test_finished (); |
849 | return; | 850 | return; |
850 | } | 851 | } |
851 | if ((NULL == value) && (NULL == typestring)) | 852 | if ((NULL == value) && (NULL == typestring)) |
852 | { | 853 | { |
853 | /* delete everything */ | 854 | /* delete everything */ |
854 | del_qe = GNUNET_NAMESTORE_records_store(ns, | 855 | del_qe = GNUNET_NAMESTORE_records_store (ns, |
855 | &zone_pkey, | 856 | &zone_pkey, |
856 | name, | 857 | name, |
857 | 0, | 858 | 0, |
858 | NULL, | 859 | NULL, |
859 | &del_continuation, | 860 | &del_continuation, |
860 | NULL); | 861 | NULL); |
861 | return; | 862 | return; |
862 | } | 863 | } |
863 | rd_left = 0; | 864 | rd_left = 0; |
864 | if (NULL != typestring) | 865 | if (NULL != typestring) |
865 | type = GNUNET_GNSRECORD_typename_to_number(typestring); | 866 | type = GNUNET_GNSRECORD_typename_to_number (typestring); |
866 | else | 867 | else |
867 | type = GNUNET_GNSRECORD_TYPE_ANY; | 868 | type = GNUNET_GNSRECORD_TYPE_ANY; |
868 | for (unsigned int i = 0; i < rd_count; i++) | 869 | for (unsigned int i = 0; i < rd_count; i++) |
869 | { | 870 | { |
870 | vs = NULL; | 871 | vs = NULL; |
871 | if (!(((GNUNET_GNSRECORD_TYPE_ANY == type) || | 872 | if (! (((GNUNET_GNSRECORD_TYPE_ANY == type) || |
872 | (rd[i].record_type == type)) && | 873 | (rd[i].record_type == type)) && |
873 | ((NULL == value) || | 874 | ((NULL == value) || |
874 | (NULL == | 875 | (NULL == |
875 | (vs = (GNUNET_GNSRECORD_value_to_string(rd[i].record_type, | 876 | (vs = (GNUNET_GNSRECORD_value_to_string (rd[i].record_type, |
876 | rd[i].data, | 877 | rd[i].data, |
877 | rd[i].data_size)))) || | 878 | rd[i].data_size)))) || |
878 | (0 == strcmp(vs, value))))) | 879 | (0 == strcmp (vs, value))))) |
879 | rdx[rd_left++] = rd[i]; | 880 | rdx[rd_left++] = rd[i]; |
880 | GNUNET_free_non_null(vs); | 881 | GNUNET_free_non_null (vs); |
881 | } | 882 | } |
882 | if (rd_count == rd_left) | 883 | if (rd_count == rd_left) |
883 | { | 884 | { |
884 | /* nothing got deleted */ | 885 | /* nothing got deleted */ |
885 | fprintf( | 886 | fprintf ( |
886 | stderr, | 887 | stderr, |
887 | _( | 888 | _ ( |
888 | "There are no records under label `%s' that match the request for deletion.\n"), | 889 | "There are no records under label `%s' that match the request for deletion.\n"), |
889 | label); | 890 | label); |
890 | test_finished(); | 891 | test_finished (); |
891 | return; | 892 | return; |
892 | } | 893 | } |
893 | /* delete everything but what we copied to 'rdx' */ | 894 | /* delete everything but what we copied to 'rdx' */ |
894 | del_qe = GNUNET_NAMESTORE_records_store(ns, | 895 | del_qe = GNUNET_NAMESTORE_records_store (ns, |
895 | &zone_pkey, | 896 | &zone_pkey, |
896 | name, | 897 | name, |
897 | rd_left, | 898 | rd_left, |
898 | rdx, | 899 | rdx, |
899 | &del_continuation, | 900 | &del_continuation, |
900 | NULL); | 901 | NULL); |
901 | } | 902 | } |
902 | 903 | ||
903 | 904 | ||
@@ -910,39 +911,39 @@ del_monitor(void *cls, | |||
910 | * @return #GNUNET_OK on success | 911 | * @return #GNUNET_OK on success |
911 | */ | 912 | */ |
912 | static int | 913 | static int |
913 | parse_expiration(const char *expirationstring, | 914 | parse_expiration (const char *expirationstring, |
914 | int *etime_is_rel, | 915 | int *etime_is_rel, |
915 | uint64_t *etime) | 916 | uint64_t *etime) |
916 | { | 917 | { |
917 | struct GNUNET_TIME_Relative etime_rel; | 918 | struct GNUNET_TIME_Relative etime_rel; |
918 | struct GNUNET_TIME_Absolute etime_abs; | 919 | struct GNUNET_TIME_Absolute etime_abs; |
919 | 920 | ||
920 | if (0 == strcmp(expirationstring, "never")) | 921 | if (0 == strcmp (expirationstring, "never")) |
921 | { | 922 | { |
922 | *etime = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; | 923 | *etime = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; |
923 | *etime_is_rel = GNUNET_NO; | 924 | *etime_is_rel = GNUNET_NO; |
924 | return GNUNET_OK; | 925 | return GNUNET_OK; |
925 | } | 926 | } |
926 | if (GNUNET_OK == | 927 | if (GNUNET_OK == |
927 | GNUNET_STRINGS_fancy_time_to_relative(expirationstring, &etime_rel)) | 928 | GNUNET_STRINGS_fancy_time_to_relative (expirationstring, &etime_rel)) |
928 | { | 929 | { |
929 | *etime_is_rel = GNUNET_YES; | 930 | *etime_is_rel = GNUNET_YES; |
930 | *etime = etime_rel.rel_value_us; | 931 | *etime = etime_rel.rel_value_us; |
931 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 932 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
932 | "Storing record with relative expiration time of %s\n", | 933 | "Storing record with relative expiration time of %s\n", |
933 | GNUNET_STRINGS_relative_time_to_string(etime_rel, GNUNET_NO)); | 934 | GNUNET_STRINGS_relative_time_to_string (etime_rel, GNUNET_NO)); |
934 | return GNUNET_OK; | 935 | return GNUNET_OK; |
935 | } | 936 | } |
936 | if (GNUNET_OK == | 937 | if (GNUNET_OK == |
937 | GNUNET_STRINGS_fancy_time_to_absolute(expirationstring, &etime_abs)) | 938 | GNUNET_STRINGS_fancy_time_to_absolute (expirationstring, &etime_abs)) |
938 | { | 939 | { |
939 | *etime_is_rel = GNUNET_NO; | 940 | *etime_is_rel = GNUNET_NO; |
940 | *etime = etime_abs.abs_value_us; | 941 | *etime = etime_abs.abs_value_us; |
941 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 942 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
942 | "Storing record with absolute expiration time of %s\n", | 943 | "Storing record with absolute expiration time of %s\n", |
943 | GNUNET_STRINGS_absolute_time_to_string(etime_abs)); | 944 | GNUNET_STRINGS_absolute_time_to_string (etime_abs)); |
944 | return GNUNET_OK; | 945 | return GNUNET_OK; |
945 | } | 946 | } |
946 | return GNUNET_SYSERR; | 947 | return GNUNET_SYSERR; |
947 | } | 948 | } |
948 | 949 | ||
@@ -958,19 +959,19 @@ parse_expiration(const char *expirationstring, | |||
958 | * @param emsg NULL on success, otherwise an error message | 959 | * @param emsg NULL on success, otherwise an error message |
959 | */ | 960 | */ |
960 | static void | 961 | static void |
961 | replace_cont(void *cls, int success, const char *emsg) | 962 | replace_cont (void *cls, int success, const char *emsg) |
962 | { | 963 | { |
963 | (void)cls; | 964 | (void) cls; |
964 | 965 | ||
965 | set_qe = NULL; | 966 | set_qe = NULL; |
966 | if (GNUNET_OK != success) | 967 | if (GNUNET_OK != success) |
967 | { | 968 | { |
968 | GNUNET_log(GNUNET_ERROR_TYPE_MESSAGE, | 969 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, |
969 | _("Failed to replace records: %s\n"), | 970 | _ ("Failed to replace records: %s\n"), |
970 | emsg); | 971 | emsg); |
971 | ret = 1; /* fail from 'main' */ | 972 | ret = 1; /* fail from 'main' */ |
972 | } | 973 | } |
973 | GNUNET_SCHEDULER_shutdown(); | 974 | GNUNET_SCHEDULER_shutdown (); |
974 | } | 975 | } |
975 | 976 | ||
976 | 977 | ||
@@ -981,261 +982,261 @@ replace_cont(void *cls, int success, const char *emsg) | |||
981 | * @param cfg configuration to use | 982 | * @param cfg configuration to use |
982 | */ | 983 | */ |
983 | static void | 984 | static void |
984 | run_with_zone_pkey(const struct GNUNET_CONFIGURATION_Handle *cfg) | 985 | run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg) |
985 | { | 986 | { |
986 | struct GNUNET_GNSRECORD_Data rd; | 987 | struct GNUNET_GNSRECORD_Data rd; |
987 | 988 | ||
988 | if (!(add | del | list | (NULL != nickstring) | (NULL != uri) | | 989 | if (! (add | del | list | (NULL != nickstring) | (NULL != uri) |
989 | (NULL != reverse_pkey) | (NULL != recordset))) | 990 | | (NULL != reverse_pkey) | (NULL != recordset))) |
991 | { | ||
992 | /* nothing more to be done */ | ||
993 | fprintf (stderr, _ ("No options given\n")); | ||
994 | GNUNET_SCHEDULER_shutdown (); | ||
995 | return; | ||
996 | } | ||
997 | ns = GNUNET_NAMESTORE_connect (cfg); | ||
998 | if (NULL == ns) | ||
999 | { | ||
1000 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1001 | _ ("Failed to connect to namestore\n")); | ||
1002 | return; | ||
1003 | } | ||
1004 | |||
1005 | if (NULL != recordset) | ||
1006 | { | ||
1007 | /* replace entire record set */ | ||
1008 | unsigned int rd_count; | ||
1009 | struct GNUNET_GNSRECORD_Data *rd; | ||
1010 | |||
1011 | if (NULL == name) | ||
990 | { | 1012 | { |
991 | /* nothing more to be done */ | 1013 | fprintf (stderr, |
992 | fprintf(stderr, _("No options given\n")); | 1014 | _ ("Missing option `%s' for operation `%s'\n"), |
993 | GNUNET_SCHEDULER_shutdown(); | 1015 | "-R", |
1016 | _ ("replace")); | ||
1017 | GNUNET_SCHEDULER_shutdown (); | ||
1018 | ret = 1; | ||
994 | return; | 1019 | return; |
995 | } | 1020 | } |
996 | ns = GNUNET_NAMESTORE_connect(cfg); | 1021 | rd_count = 0; |
997 | if (NULL == ns) | 1022 | for (struct RecordSetEntry *e = recordset; NULL != e; e = e->next) |
1023 | rd_count++; | ||
1024 | rd = GNUNET_new_array (rd_count, struct GNUNET_GNSRECORD_Data); | ||
1025 | rd_count = 0; | ||
1026 | for (struct RecordSetEntry *e = recordset; NULL != e; e = e->next) | ||
998 | { | 1027 | { |
999 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1028 | rd[rd_count] = e->record; |
1000 | _("Failed to connect to namestore\n")); | 1029 | rd_count++; |
1001 | return; | ||
1002 | } | 1030 | } |
1031 | set_qe = GNUNET_NAMESTORE_records_store (ns, | ||
1032 | &zone_pkey, | ||
1033 | name, | ||
1034 | rd_count, | ||
1035 | rd, | ||
1036 | &replace_cont, | ||
1037 | NULL); | ||
1038 | GNUNET_free (rd); | ||
1039 | return; | ||
1040 | } | ||
1003 | 1041 | ||
1004 | if (NULL != recordset) | 1042 | if (add) |
1043 | { | ||
1044 | if (NULL == name) | ||
1005 | { | 1045 | { |
1006 | /* replace entire record set */ | 1046 | fprintf (stderr, |
1007 | unsigned int rd_count; | 1047 | _ ("Missing option `%s' for operation `%s'\n"), |
1008 | struct GNUNET_GNSRECORD_Data *rd; | 1048 | "-n", |
1009 | 1049 | _ ("add")); | |
1010 | if (NULL == name) | 1050 | GNUNET_SCHEDULER_shutdown (); |
1011 | { | 1051 | ret = 1; |
1012 | fprintf(stderr, | ||
1013 | _("Missing option `%s' for operation `%s'\n"), | ||
1014 | "-R", | ||
1015 | _("replace")); | ||
1016 | GNUNET_SCHEDULER_shutdown(); | ||
1017 | ret = 1; | ||
1018 | return; | ||
1019 | } | ||
1020 | rd_count = 0; | ||
1021 | for (struct RecordSetEntry *e = recordset; NULL != e; e = e->next) | ||
1022 | rd_count++; | ||
1023 | rd = GNUNET_new_array(rd_count, struct GNUNET_GNSRECORD_Data); | ||
1024 | rd_count = 0; | ||
1025 | for (struct RecordSetEntry *e = recordset; NULL != e; e = e->next) | ||
1026 | { | ||
1027 | rd[rd_count] = e->record; | ||
1028 | rd_count++; | ||
1029 | } | ||
1030 | set_qe = GNUNET_NAMESTORE_records_store(ns, | ||
1031 | &zone_pkey, | ||
1032 | name, | ||
1033 | rd_count, | ||
1034 | rd, | ||
1035 | &replace_cont, | ||
1036 | NULL); | ||
1037 | GNUNET_free(rd); | ||
1038 | return; | 1052 | return; |
1039 | } | 1053 | } |
1040 | 1054 | if (NULL == typestring) | |
1041 | if (add) | ||
1042 | { | 1055 | { |
1043 | if (NULL == name) | 1056 | fprintf (stderr, |
1044 | { | 1057 | _ ("Missing option `%s' for operation `%s'\n"), |
1045 | fprintf(stderr, | 1058 | "-t", |
1046 | _("Missing option `%s' for operation `%s'\n"), | 1059 | _ ("add")); |
1047 | "-n", | 1060 | GNUNET_SCHEDULER_shutdown (); |
1048 | _("add")); | 1061 | ret = 1; |
1049 | GNUNET_SCHEDULER_shutdown(); | 1062 | return; |
1050 | ret = 1; | ||
1051 | return; | ||
1052 | } | ||
1053 | if (NULL == typestring) | ||
1054 | { | ||
1055 | fprintf(stderr, | ||
1056 | _("Missing option `%s' for operation `%s'\n"), | ||
1057 | "-t", | ||
1058 | _("add")); | ||
1059 | GNUNET_SCHEDULER_shutdown(); | ||
1060 | ret = 1; | ||
1061 | return; | ||
1062 | } | ||
1063 | type = GNUNET_GNSRECORD_typename_to_number(typestring); | ||
1064 | if (UINT32_MAX == type) | ||
1065 | { | ||
1066 | fprintf(stderr, _("Unsupported type `%s'\n"), typestring); | ||
1067 | GNUNET_SCHEDULER_shutdown(); | ||
1068 | ret = 1; | ||
1069 | return; | ||
1070 | } | ||
1071 | if (NULL == value) | ||
1072 | { | ||
1073 | fprintf(stderr, | ||
1074 | _("Missing option `%s' for operation `%s'\n"), | ||
1075 | "-V", | ||
1076 | _("add")); | ||
1077 | ret = 1; | ||
1078 | GNUNET_SCHEDULER_shutdown(); | ||
1079 | return; | ||
1080 | } | ||
1081 | if (GNUNET_OK != | ||
1082 | GNUNET_GNSRECORD_string_to_value(type, value, &data, &data_size)) | ||
1083 | { | ||
1084 | fprintf(stderr, | ||
1085 | _("Value `%s' invalid for record type `%s'\n"), | ||
1086 | value, | ||
1087 | typestring); | ||
1088 | GNUNET_SCHEDULER_shutdown(); | ||
1089 | ret = 1; | ||
1090 | return; | ||
1091 | } | ||
1092 | if (NULL == expirationstring) | ||
1093 | { | ||
1094 | fprintf(stderr, | ||
1095 | _("Missing option `%s' for operation `%s'\n"), | ||
1096 | "-e", | ||
1097 | _("add")); | ||
1098 | GNUNET_SCHEDULER_shutdown(); | ||
1099 | ret = 1; | ||
1100 | return; | ||
1101 | } | ||
1102 | if (GNUNET_OK != parse_expiration(expirationstring, &etime_is_rel, &etime)) | ||
1103 | { | ||
1104 | fprintf(stderr, _("Invalid time format `%s'\n"), expirationstring); | ||
1105 | GNUNET_SCHEDULER_shutdown(); | ||
1106 | ret = 1; | ||
1107 | return; | ||
1108 | } | ||
1109 | add_qe = GNUNET_NAMESTORE_records_lookup(ns, | ||
1110 | &zone_pkey, | ||
1111 | name, | ||
1112 | &add_error_cb, | ||
1113 | NULL, | ||
1114 | &get_existing_record, | ||
1115 | NULL); | ||
1116 | } | 1063 | } |
1117 | if (del) | 1064 | type = GNUNET_GNSRECORD_typename_to_number (typestring); |
1065 | if (UINT32_MAX == type) | ||
1118 | { | 1066 | { |
1119 | if (NULL == name) | 1067 | fprintf (stderr, _ ("Unsupported type `%s'\n"), typestring); |
1120 | { | 1068 | GNUNET_SCHEDULER_shutdown (); |
1121 | fprintf(stderr, | 1069 | ret = 1; |
1122 | _("Missing option `%s' for operation `%s'\n"), | 1070 | return; |
1123 | "-n", | ||
1124 | _("del")); | ||
1125 | GNUNET_SCHEDULER_shutdown(); | ||
1126 | ret = 1; | ||
1127 | return; | ||
1128 | } | ||
1129 | del_qe = GNUNET_NAMESTORE_records_lookup(ns, | ||
1130 | &zone_pkey, | ||
1131 | name, | ||
1132 | &del_lookup_error_cb, | ||
1133 | NULL, | ||
1134 | &del_monitor, | ||
1135 | NULL); | ||
1136 | } | 1071 | } |
1137 | if (list) | 1072 | if (NULL == value) |
1138 | { | 1073 | { |
1139 | if (NULL != name) | 1074 | fprintf (stderr, |
1140 | get_qe = GNUNET_NAMESTORE_records_lookup(ns, | 1075 | _ ("Missing option `%s' for operation `%s'\n"), |
1141 | &zone_pkey, | 1076 | "-V", |
1142 | name, | 1077 | _ ("add")); |
1143 | &lookup_error_cb, | 1078 | ret = 1; |
1144 | NULL, | 1079 | GNUNET_SCHEDULER_shutdown (); |
1145 | &display_record_lookup, | 1080 | return; |
1146 | NULL); | 1081 | } |
1147 | else | 1082 | if (GNUNET_OK != |
1148 | list_it = GNUNET_NAMESTORE_zone_iteration_start(ns, | 1083 | GNUNET_GNSRECORD_string_to_value (type, value, &data, &data_size)) |
1149 | &zone_pkey, | 1084 | { |
1150 | &zone_iteration_error_cb, | 1085 | fprintf (stderr, |
1151 | NULL, | 1086 | _ ("Value `%s' invalid for record type `%s'\n"), |
1152 | &display_record_iterator, | 1087 | value, |
1153 | NULL, | 1088 | typestring); |
1154 | &zone_iteration_finished, | 1089 | GNUNET_SCHEDULER_shutdown (); |
1155 | NULL); | 1090 | ret = 1; |
1091 | return; | ||
1092 | } | ||
1093 | if (NULL == expirationstring) | ||
1094 | { | ||
1095 | fprintf (stderr, | ||
1096 | _ ("Missing option `%s' for operation `%s'\n"), | ||
1097 | "-e", | ||
1098 | _ ("add")); | ||
1099 | GNUNET_SCHEDULER_shutdown (); | ||
1100 | ret = 1; | ||
1101 | return; | ||
1102 | } | ||
1103 | if (GNUNET_OK != parse_expiration (expirationstring, &etime_is_rel, &etime)) | ||
1104 | { | ||
1105 | fprintf (stderr, _ ("Invalid time format `%s'\n"), expirationstring); | ||
1106 | GNUNET_SCHEDULER_shutdown (); | ||
1107 | ret = 1; | ||
1108 | return; | ||
1109 | } | ||
1110 | add_qe = GNUNET_NAMESTORE_records_lookup (ns, | ||
1111 | &zone_pkey, | ||
1112 | name, | ||
1113 | &add_error_cb, | ||
1114 | NULL, | ||
1115 | &get_existing_record, | ||
1116 | NULL); | ||
1117 | } | ||
1118 | if (del) | ||
1119 | { | ||
1120 | if (NULL == name) | ||
1121 | { | ||
1122 | fprintf (stderr, | ||
1123 | _ ("Missing option `%s' for operation `%s'\n"), | ||
1124 | "-n", | ||
1125 | _ ("del")); | ||
1126 | GNUNET_SCHEDULER_shutdown (); | ||
1127 | ret = 1; | ||
1128 | return; | ||
1156 | } | 1129 | } |
1130 | del_qe = GNUNET_NAMESTORE_records_lookup (ns, | ||
1131 | &zone_pkey, | ||
1132 | name, | ||
1133 | &del_lookup_error_cb, | ||
1134 | NULL, | ||
1135 | &del_monitor, | ||
1136 | NULL); | ||
1137 | } | ||
1138 | if (list) | ||
1139 | { | ||
1140 | if (NULL != name) | ||
1141 | get_qe = GNUNET_NAMESTORE_records_lookup (ns, | ||
1142 | &zone_pkey, | ||
1143 | name, | ||
1144 | &lookup_error_cb, | ||
1145 | NULL, | ||
1146 | &display_record_lookup, | ||
1147 | NULL); | ||
1148 | else | ||
1149 | list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, | ||
1150 | &zone_pkey, | ||
1151 | &zone_iteration_error_cb, | ||
1152 | NULL, | ||
1153 | &display_record_iterator, | ||
1154 | NULL, | ||
1155 | &zone_iteration_finished, | ||
1156 | NULL); | ||
1157 | } | ||
1157 | if (NULL != reverse_pkey) | 1158 | if (NULL != reverse_pkey) |
1159 | { | ||
1160 | struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | ||
1161 | |||
1162 | if (GNUNET_OK != | ||
1163 | GNUNET_CRYPTO_ecdsa_public_key_from_string (reverse_pkey, | ||
1164 | strlen (reverse_pkey), | ||
1165 | &pubkey)) | ||
1158 | { | 1166 | { |
1159 | struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 1167 | fprintf (stderr, |
1160 | 1168 | _ ("Invalid public key for reverse lookup `%s'\n"), | |
1161 | if (GNUNET_OK != | 1169 | reverse_pkey); |
1162 | GNUNET_CRYPTO_ecdsa_public_key_from_string(reverse_pkey, | 1170 | GNUNET_SCHEDULER_shutdown (); |
1163 | strlen(reverse_pkey), | ||
1164 | &pubkey)) | ||
1165 | { | ||
1166 | fprintf(stderr, | ||
1167 | _("Invalid public key for reverse lookup `%s'\n"), | ||
1168 | reverse_pkey); | ||
1169 | GNUNET_SCHEDULER_shutdown(); | ||
1170 | } | ||
1171 | reverse_qe = GNUNET_NAMESTORE_zone_to_name(ns, | ||
1172 | &zone_pkey, | ||
1173 | &pubkey, | ||
1174 | &reverse_error_cb, | ||
1175 | NULL, | ||
1176 | &handle_reverse_lookup, | ||
1177 | NULL); | ||
1178 | } | 1171 | } |
1172 | reverse_qe = GNUNET_NAMESTORE_zone_to_name (ns, | ||
1173 | &zone_pkey, | ||
1174 | &pubkey, | ||
1175 | &reverse_error_cb, | ||
1176 | NULL, | ||
1177 | &handle_reverse_lookup, | ||
1178 | NULL); | ||
1179 | } | ||
1179 | if (NULL != uri) | 1180 | if (NULL != uri) |
1181 | { | ||
1182 | char sh[105]; | ||
1183 | char sname[64]; | ||
1184 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | ||
1185 | |||
1186 | GNUNET_STRINGS_utf8_tolower (uri, uri); | ||
1187 | if ((2 != (sscanf (uri, "gnunet://gns/%52s/%63s", sh, sname))) || | ||
1188 | (GNUNET_OK != | ||
1189 | GNUNET_CRYPTO_ecdsa_public_key_from_string (sh, strlen (sh), &pkey))) | ||
1180 | { | 1190 | { |
1181 | char sh[105]; | 1191 | fprintf (stderr, _ ("Invalid URI `%s'\n"), uri); |
1182 | char sname[64]; | 1192 | GNUNET_SCHEDULER_shutdown (); |
1183 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | 1193 | ret = 1; |
1184 | 1194 | return; | |
1185 | GNUNET_STRINGS_utf8_tolower(uri, uri); | ||
1186 | if ((2 != (sscanf(uri, "gnunet://gns/%52s/%63s", sh, sname))) || | ||
1187 | (GNUNET_OK != | ||
1188 | GNUNET_CRYPTO_ecdsa_public_key_from_string(sh, strlen(sh), &pkey))) | ||
1189 | { | ||
1190 | fprintf(stderr, _("Invalid URI `%s'\n"), uri); | ||
1191 | GNUNET_SCHEDULER_shutdown(); | ||
1192 | ret = 1; | ||
1193 | return; | ||
1194 | } | ||
1195 | memset(&rd, 0, sizeof(rd)); | ||
1196 | rd.data = &pkey; | ||
1197 | rd.data_size = sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey); | ||
1198 | rd.record_type = GNUNET_GNSRECORD_TYPE_PKEY; | ||
1199 | rd.expiration_time = etime; | ||
1200 | if (GNUNET_YES == etime_is_rel) | ||
1201 | rd.flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | ||
1202 | if (1 == is_shadow) | ||
1203 | rd.flags |= GNUNET_GNSRECORD_RF_SHADOW_RECORD; | ||
1204 | add_qe_uri = GNUNET_NAMESTORE_records_store(ns, | ||
1205 | &zone_pkey, | ||
1206 | sname, | ||
1207 | 1, | ||
1208 | &rd, | ||
1209 | &add_continuation, | ||
1210 | &add_qe_uri); | ||
1211 | } | 1195 | } |
1196 | memset (&rd, 0, sizeof(rd)); | ||
1197 | rd.data = &pkey; | ||
1198 | rd.data_size = sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey); | ||
1199 | rd.record_type = GNUNET_GNSRECORD_TYPE_PKEY; | ||
1200 | rd.expiration_time = etime; | ||
1201 | if (GNUNET_YES == etime_is_rel) | ||
1202 | rd.flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | ||
1203 | if (1 == is_shadow) | ||
1204 | rd.flags |= GNUNET_GNSRECORD_RF_SHADOW_RECORD; | ||
1205 | add_qe_uri = GNUNET_NAMESTORE_records_store (ns, | ||
1206 | &zone_pkey, | ||
1207 | sname, | ||
1208 | 1, | ||
1209 | &rd, | ||
1210 | &add_continuation, | ||
1211 | &add_qe_uri); | ||
1212 | } | ||
1212 | if (NULL != nickstring) | 1213 | if (NULL != nickstring) |
1214 | { | ||
1215 | if (0 == strlen (nickstring)) | ||
1213 | { | 1216 | { |
1214 | if (0 == strlen(nickstring)) | 1217 | fprintf (stderr, _ ("Invalid nick `%s'\n"), nickstring); |
1215 | { | 1218 | GNUNET_SCHEDULER_shutdown (); |
1216 | fprintf(stderr, _("Invalid nick `%s'\n"), nickstring); | 1219 | ret = 1; |
1217 | GNUNET_SCHEDULER_shutdown(); | 1220 | return; |
1218 | ret = 1; | ||
1219 | return; | ||
1220 | } | ||
1221 | add_qe_uri = GNUNET_NAMESTORE_set_nick(ns, | ||
1222 | &zone_pkey, | ||
1223 | nickstring, | ||
1224 | &add_continuation, | ||
1225 | &add_qe_uri); | ||
1226 | } | 1221 | } |
1222 | add_qe_uri = GNUNET_NAMESTORE_set_nick (ns, | ||
1223 | &zone_pkey, | ||
1224 | nickstring, | ||
1225 | &add_continuation, | ||
1226 | &add_qe_uri); | ||
1227 | } | ||
1227 | if (monitor) | 1228 | if (monitor) |
1228 | { | 1229 | { |
1229 | zm = GNUNET_NAMESTORE_zone_monitor_start(cfg, | 1230 | zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, |
1230 | &zone_pkey, | 1231 | &zone_pkey, |
1231 | GNUNET_YES, | 1232 | GNUNET_YES, |
1232 | &monitor_error_cb, | 1233 | &monitor_error_cb, |
1233 | NULL, | 1234 | NULL, |
1234 | &display_record_monitor, | 1235 | &display_record_monitor, |
1235 | NULL, | 1236 | NULL, |
1236 | &sync_cb, | 1237 | &sync_cb, |
1237 | NULL); | 1238 | NULL); |
1238 | } | 1239 | } |
1239 | } | 1240 | } |
1240 | 1241 | ||
1241 | 1242 | ||
@@ -1247,37 +1248,37 @@ run_with_zone_pkey(const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1247 | * @param ego an ego known to identity service, or NULL | 1248 | * @param ego an ego known to identity service, or NULL |
1248 | */ | 1249 | */ |
1249 | static void | 1250 | static void |
1250 | identity_cb(void *cls, const struct GNUNET_IDENTITY_Ego *ego) | 1251 | identity_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego) |
1251 | { | 1252 | { |
1252 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 1253 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
1253 | 1254 | ||
1254 | el = NULL; | 1255 | el = NULL; |
1255 | if ((NULL != name) && (0 != strchr(name, '.'))) | 1256 | if ((NULL != name) && (0 != strchr (name, '.'))) |
1256 | { | 1257 | { |
1257 | fprintf(stderr, | 1258 | fprintf (stderr, |
1258 | _("Label `%s' contains `.' which is not allowed\n"), | 1259 | _ ("Label `%s' contains `.' which is not allowed\n"), |
1259 | name); | 1260 | name); |
1260 | GNUNET_SCHEDULER_shutdown(); | 1261 | GNUNET_SCHEDULER_shutdown (); |
1261 | ret = -1; | 1262 | ret = -1; |
1262 | return; | 1263 | return; |
1263 | } | 1264 | } |
1264 | 1265 | ||
1265 | if (NULL == ego) | 1266 | if (NULL == ego) |
1267 | { | ||
1268 | if (NULL != ego_name) | ||
1266 | { | 1269 | { |
1267 | if (NULL != ego_name) | 1270 | fprintf (stderr, |
1268 | { | 1271 | _ ("Ego `%s' not known to identity service\n"), |
1269 | fprintf(stderr, | 1272 | ego_name); |
1270 | _("Ego `%s' not known to identity service\n"), | ||
1271 | ego_name); | ||
1272 | } | ||
1273 | GNUNET_SCHEDULER_shutdown(); | ||
1274 | ret = -1; | ||
1275 | return; | ||
1276 | } | 1273 | } |
1277 | zone_pkey = *GNUNET_IDENTITY_ego_get_private_key(ego); | 1274 | GNUNET_SCHEDULER_shutdown (); |
1278 | GNUNET_free_non_null(ego_name); | 1275 | ret = -1; |
1276 | return; | ||
1277 | } | ||
1278 | zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego); | ||
1279 | GNUNET_free_non_null (ego_name); | ||
1279 | ego_name = NULL; | 1280 | ego_name = NULL; |
1280 | run_with_zone_pkey(cfg); | 1281 | run_with_zone_pkey (cfg); |
1281 | } | 1282 | } |
1282 | 1283 | ||
1283 | 1284 | ||
@@ -1292,27 +1293,27 @@ identity_cb(void *cls, const struct GNUNET_IDENTITY_Ego *ego) | |||
1292 | * @param name unused | 1293 | * @param name unused |
1293 | */ | 1294 | */ |
1294 | static void | 1295 | static void |
1295 | default_ego_cb(void *cls, | 1296 | default_ego_cb (void *cls, |
1296 | struct GNUNET_IDENTITY_Ego *ego, | 1297 | struct GNUNET_IDENTITY_Ego *ego, |
1297 | void **ctx, | 1298 | void **ctx, |
1298 | const char *name) | 1299 | const char *name) |
1299 | { | 1300 | { |
1300 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 1301 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
1301 | 1302 | ||
1302 | (void)ctx; | 1303 | (void) ctx; |
1303 | (void)name; | 1304 | (void) name; |
1304 | get_default = NULL; | 1305 | get_default = NULL; |
1305 | if (NULL == ego) | 1306 | if (NULL == ego) |
1306 | { | 1307 | { |
1307 | fprintf(stderr, _("No default ego configured in identity service\n")); | 1308 | fprintf (stderr, _ ("No default ego configured in identity service\n")); |
1308 | GNUNET_SCHEDULER_shutdown(); | 1309 | GNUNET_SCHEDULER_shutdown (); |
1309 | ret = -1; | 1310 | ret = -1; |
1310 | return; | 1311 | return; |
1311 | } | 1312 | } |
1312 | else | 1313 | else |
1313 | { | 1314 | { |
1314 | identity_cb((void *)cfg, ego); | 1315 | identity_cb ((void *) cfg, ego); |
1315 | } | 1316 | } |
1316 | } | 1317 | } |
1317 | 1318 | ||
1318 | 1319 | ||
@@ -1329,19 +1330,19 @@ default_ego_cb(void *cls, | |||
1329 | * @param name name associated with @a ego | 1330 | * @param name name associated with @a ego |
1330 | */ | 1331 | */ |
1331 | static void | 1332 | static void |
1332 | id_connect_cb(void *cls, | 1333 | id_connect_cb (void *cls, |
1333 | struct GNUNET_IDENTITY_Ego *ego, | 1334 | struct GNUNET_IDENTITY_Ego *ego, |
1334 | void **ctx, | 1335 | void **ctx, |
1335 | const char *name) | 1336 | const char *name) |
1336 | { | 1337 | { |
1337 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 1338 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
1338 | 1339 | ||
1339 | (void)ctx; | 1340 | (void) ctx; |
1340 | (void)name; | 1341 | (void) name; |
1341 | if (NULL != ego) | 1342 | if (NULL != ego) |
1342 | return; | 1343 | return; |
1343 | get_default = | 1344 | get_default = |
1344 | GNUNET_IDENTITY_get(idh, "namestore", &default_ego_cb, (void *)cfg); | 1345 | GNUNET_IDENTITY_get (idh, "namestore", &default_ego_cb, (void *) cfg); |
1345 | } | 1346 | } |
1346 | 1347 | ||
1347 | 1348 | ||
@@ -1354,53 +1355,53 @@ id_connect_cb(void *cls, | |||
1354 | * @param cfg configuration | 1355 | * @param cfg configuration |
1355 | */ | 1356 | */ |
1356 | static void | 1357 | static void |
1357 | run(void *cls, | 1358 | run (void *cls, |
1358 | char *const *args, | 1359 | char *const *args, |
1359 | const char *cfgfile, | 1360 | const char *cfgfile, |
1360 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 1361 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
1361 | { | 1362 | { |
1362 | const char *pkey_str; | 1363 | const char *pkey_str; |
1363 | 1364 | ||
1364 | (void)cls; | 1365 | (void) cls; |
1365 | (void)args; | 1366 | (void) args; |
1366 | (void)cfgfile; | 1367 | (void) cfgfile; |
1367 | if (NULL != args[0]) | 1368 | if (NULL != args[0]) |
1368 | GNUNET_log( | 1369 | GNUNET_log ( |
1369 | GNUNET_ERROR_TYPE_WARNING, | 1370 | GNUNET_ERROR_TYPE_WARNING, |
1370 | _("Superfluous command line arguments (starting with `%s') ignored\n"), | 1371 | _ ("Superfluous command line arguments (starting with `%s') ignored\n"), |
1371 | args[0]); | 1372 | args[0]); |
1372 | if ((NULL != args[0]) && (NULL == uri)) | 1373 | if ((NULL != args[0]) && (NULL == uri)) |
1373 | uri = GNUNET_strdup(args[0]); | 1374 | uri = GNUNET_strdup (args[0]); |
1374 | 1375 | ||
1375 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, (void *)cfg); | 1376 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, (void *) cfg); |
1376 | pkey_str = getenv("GNUNET_NAMESTORE_EGO_PRIVATE_KEY"); | 1377 | pkey_str = getenv ("GNUNET_NAMESTORE_EGO_PRIVATE_KEY"); |
1377 | if (NULL != pkey_str) | 1378 | if (NULL != pkey_str) |
1379 | { | ||
1380 | if (GNUNET_OK != GNUNET_STRINGS_string_to_data (pkey_str, | ||
1381 | strlen (pkey_str), | ||
1382 | &zone_pkey, | ||
1383 | sizeof(zone_pkey))) | ||
1378 | { | 1384 | { |
1379 | if (GNUNET_OK != GNUNET_STRINGS_string_to_data(pkey_str, | 1385 | fprintf (stderr, |
1380 | strlen(pkey_str), | 1386 | "Malformed private key `%s' in $%s\n", |
1381 | &zone_pkey, | 1387 | pkey_str, |
1382 | sizeof(zone_pkey))) | 1388 | "GNUNET_NAMESTORE_EGO_PRIVATE_KEY"); |
1383 | { | 1389 | ret = 1; |
1384 | fprintf(stderr, | 1390 | GNUNET_SCHEDULER_shutdown (); |
1385 | "Malformed private key `%s' in $%s\n", | ||
1386 | pkey_str, | ||
1387 | "GNUNET_NAMESTORE_EGO_PRIVATE_KEY"); | ||
1388 | ret = 1; | ||
1389 | GNUNET_SCHEDULER_shutdown(); | ||
1390 | return; | ||
1391 | } | ||
1392 | run_with_zone_pkey(cfg); | ||
1393 | return; | 1391 | return; |
1394 | } | 1392 | } |
1393 | run_with_zone_pkey (cfg); | ||
1394 | return; | ||
1395 | } | ||
1395 | if (NULL == ego_name) | 1396 | if (NULL == ego_name) |
1396 | { | 1397 | { |
1397 | idh = GNUNET_IDENTITY_connect(cfg, &id_connect_cb, (void *)cfg); | 1398 | idh = GNUNET_IDENTITY_connect (cfg, &id_connect_cb, (void *) cfg); |
1398 | if (NULL == idh) | 1399 | if (NULL == idh) |
1399 | fprintf(stderr, _("Cannot connect to identity service\n")); | 1400 | fprintf (stderr, _ ("Cannot connect to identity service\n")); |
1400 | ret = -1; | 1401 | ret = -1; |
1401 | return; | 1402 | return; |
1402 | } | 1403 | } |
1403 | el = GNUNET_IDENTITY_ego_lookup(cfg, ego_name, &identity_cb, (void *)cfg); | 1404 | el = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &identity_cb, (void *) cfg); |
1404 | } | 1405 | } |
1405 | 1406 | ||
1406 | 1407 | ||
@@ -1422,10 +1423,10 @@ run(void *cls, | |||
1422 | * @return #GNUNET_OK on success | 1423 | * @return #GNUNET_OK on success |
1423 | */ | 1424 | */ |
1424 | static int | 1425 | static int |
1425 | multirecord_process(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | 1426 | multirecord_process (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, |
1426 | void *scls, | 1427 | void *scls, |
1427 | const char *option, | 1428 | const char *option, |
1428 | const char *value) | 1429 | const char *value) |
1429 | { | 1430 | { |
1430 | struct RecordSetEntry **head = scls; | 1431 | struct RecordSetEntry **head = scls; |
1431 | struct RecordSetEntry *r; | 1432 | struct RecordSetEntry *r; |
@@ -1436,94 +1437,94 @@ multirecord_process(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
1436 | int etime_is_rel; | 1437 | int etime_is_rel; |
1437 | void *raw_data; | 1438 | void *raw_data; |
1438 | 1439 | ||
1439 | (void)ctx; | 1440 | (void) ctx; |
1440 | (void)option; | 1441 | (void) option; |
1441 | cp = GNUNET_strdup(value); | 1442 | cp = GNUNET_strdup (value); |
1442 | tok = strtok_r(cp, " ", &saveptr); | 1443 | tok = strtok_r (cp, " ", &saveptr); |
1443 | if (NULL == tok) | 1444 | if (NULL == tok) |
1444 | { | 1445 | { |
1445 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1446 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1446 | _("Empty record line argument is not allowed.\n")); | 1447 | _ ("Empty record line argument is not allowed.\n")); |
1447 | GNUNET_free(cp); | 1448 | GNUNET_free (cp); |
1448 | return GNUNET_SYSERR; | 1449 | return GNUNET_SYSERR; |
1449 | } | 1450 | } |
1450 | { | 1451 | { |
1451 | char *etime_in_s; | 1452 | char *etime_in_s; |
1452 | 1453 | ||
1453 | GNUNET_asprintf(&etime_in_s, "%s s", tok); | 1454 | GNUNET_asprintf (&etime_in_s, "%s s", tok); |
1454 | if (GNUNET_OK != | 1455 | if (GNUNET_OK != |
1455 | parse_expiration(etime_in_s, &etime_is_rel, &record.expiration_time)) | 1456 | parse_expiration (etime_in_s, &etime_is_rel, &record.expiration_time)) |
1456 | { | ||
1457 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
1458 | _("Invalid expiration time `%s' (must be without unit)\n"), | ||
1459 | tok); | ||
1460 | GNUNET_free(cp); | ||
1461 | GNUNET_free(etime_in_s); | ||
1462 | return GNUNET_SYSERR; | ||
1463 | } | ||
1464 | GNUNET_free(etime_in_s); | ||
1465 | } | ||
1466 | tok = strtok_r(NULL, " ", &saveptr); | ||
1467 | if (NULL == tok) | ||
1468 | { | 1457 | { |
1469 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1458 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1470 | _("Missing entries in record line `%s'.\n"), | 1459 | _ ("Invalid expiration time `%s' (must be without unit)\n"), |
1471 | value); | 1460 | tok); |
1472 | GNUNET_free(cp); | 1461 | GNUNET_free (cp); |
1462 | GNUNET_free (etime_in_s); | ||
1473 | return GNUNET_SYSERR; | 1463 | return GNUNET_SYSERR; |
1474 | } | 1464 | } |
1475 | record.record_type = GNUNET_GNSRECORD_typename_to_number(tok); | 1465 | GNUNET_free (etime_in_s); |
1466 | } | ||
1467 | tok = strtok_r (NULL, " ", &saveptr); | ||
1468 | if (NULL == tok) | ||
1469 | { | ||
1470 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1471 | _ ("Missing entries in record line `%s'.\n"), | ||
1472 | value); | ||
1473 | GNUNET_free (cp); | ||
1474 | return GNUNET_SYSERR; | ||
1475 | } | ||
1476 | record.record_type = GNUNET_GNSRECORD_typename_to_number (tok); | ||
1476 | if (UINT32_MAX == record.record_type) | 1477 | if (UINT32_MAX == record.record_type) |
1477 | { | 1478 | { |
1478 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Unknown record type `%s'\n"), tok); | 1479 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Unknown record type `%s'\n"), tok); |
1479 | GNUNET_free(cp); | 1480 | GNUNET_free (cp); |
1480 | return GNUNET_SYSERR; | 1481 | return GNUNET_SYSERR; |
1481 | } | 1482 | } |
1482 | tok = strtok_r(NULL, " ", &saveptr); | 1483 | tok = strtok_r (NULL, " ", &saveptr); |
1483 | if (NULL == tok) | 1484 | if (NULL == tok) |
1484 | { | 1485 | { |
1485 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1486 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1486 | _("Missing entries in record line `%s'.\n"), | 1487 | _ ("Missing entries in record line `%s'.\n"), |
1487 | value); | 1488 | value); |
1488 | GNUNET_free(cp); | 1489 | GNUNET_free (cp); |
1489 | return GNUNET_SYSERR; | 1490 | return GNUNET_SYSERR; |
1490 | } | 1491 | } |
1491 | record.flags = GNUNET_GNSRECORD_RF_NONE; | 1492 | record.flags = GNUNET_GNSRECORD_RF_NONE; |
1492 | if (etime_is_rel) | 1493 | if (etime_is_rel) |
1493 | record.flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | 1494 | record.flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; |
1494 | if (NULL == strchr(tok, (unsigned char)'p')) /* p = public */ | 1495 | if (NULL == strchr (tok, (unsigned char) 'p')) /* p = public */ |
1495 | record.flags |= GNUNET_GNSRECORD_RF_PRIVATE; | 1496 | record.flags |= GNUNET_GNSRECORD_RF_PRIVATE; |
1496 | if (NULL != strchr(tok, (unsigned char)'s')) | 1497 | if (NULL != strchr (tok, (unsigned char) 's')) |
1497 | record.flags |= GNUNET_GNSRECORD_RF_SHADOW_RECORD; | 1498 | record.flags |= GNUNET_GNSRECORD_RF_SHADOW_RECORD; |
1498 | /* find beginning of record value */ | 1499 | /* find beginning of record value */ |
1499 | tok = strchr(&value[tok - cp], (unsigned char)' '); | 1500 | tok = strchr (&value[tok - cp], (unsigned char) ' '); |
1500 | if (NULL == tok) | 1501 | if (NULL == tok) |
1501 | { | 1502 | { |
1502 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1503 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1503 | _("Missing entries in record line `%s'.\n"), | 1504 | _ ("Missing entries in record line `%s'.\n"), |
1504 | value); | 1505 | value); |
1505 | GNUNET_free(cp); | 1506 | GNUNET_free (cp); |
1506 | return GNUNET_SYSERR; | 1507 | return GNUNET_SYSERR; |
1507 | } | 1508 | } |
1508 | GNUNET_free(cp); | 1509 | GNUNET_free (cp); |
1509 | tok++; /* skip space */ | 1510 | tok++; /* skip space */ |
1510 | if (GNUNET_OK != GNUNET_GNSRECORD_string_to_value(record.record_type, | 1511 | if (GNUNET_OK != GNUNET_GNSRECORD_string_to_value (record.record_type, |
1511 | tok, | 1512 | tok, |
1512 | &raw_data, | 1513 | &raw_data, |
1513 | &record.data_size)) | 1514 | &record.data_size)) |
1514 | { | 1515 | { |
1515 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1516 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1516 | _("Invalid record data for type %s: `%s'.\n"), | 1517 | _ ("Invalid record data for type %s: `%s'.\n"), |
1517 | GNUNET_GNSRECORD_number_to_typename(record.record_type), | 1518 | GNUNET_GNSRECORD_number_to_typename (record.record_type), |
1518 | tok); | 1519 | tok); |
1519 | return GNUNET_SYSERR; | 1520 | return GNUNET_SYSERR; |
1520 | } | 1521 | } |
1521 | 1522 | ||
1522 | r = GNUNET_malloc(sizeof(struct RecordSetEntry) + record.data_size); | 1523 | r = GNUNET_malloc (sizeof(struct RecordSetEntry) + record.data_size); |
1523 | r->next = *head; | 1524 | r->next = *head; |
1524 | record.data = &r[1]; | 1525 | record.data = &r[1]; |
1525 | memcpy(&r[1], raw_data, record.data_size); | 1526 | memcpy (&r[1], raw_data, record.data_size); |
1526 | GNUNET_free(raw_data); | 1527 | GNUNET_free (raw_data); |
1527 | r->record = record; | 1528 | r->record = record; |
1528 | *head = r; | 1529 | *head = r; |
1529 | return GNUNET_OK; | 1530 | return GNUNET_OK; |
@@ -1540,11 +1541,11 @@ multirecord_process(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
1540 | * @param[out] topKeywords set to the desired value | 1541 | * @param[out] topKeywords set to the desired value |
1541 | */ | 1542 | */ |
1542 | struct GNUNET_GETOPT_CommandLineOption | 1543 | struct GNUNET_GETOPT_CommandLineOption |
1543 | multirecord_option(char shortName, | 1544 | multirecord_option (char shortName, |
1544 | const char *name, | 1545 | const char *name, |
1545 | const char *argumentHelp, | 1546 | const char *argumentHelp, |
1546 | const char *description, | 1547 | const char *description, |
1547 | struct RecordSetEntry **rs) | 1548 | struct RecordSetEntry **rs) |
1548 | { | 1549 | { |
1549 | struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = shortName, | 1550 | struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = shortName, |
1550 | .name = name, | 1551 | .name = name, |
@@ -1553,7 +1554,7 @@ multirecord_option(char shortName, | |||
1553 | .require_argument = 1, | 1554 | .require_argument = 1, |
1554 | .processor = | 1555 | .processor = |
1555 | &multirecord_process, | 1556 | &multirecord_process, |
1556 | .scls = (void *)rs }; | 1557 | .scls = (void *) rs }; |
1557 | 1558 | ||
1558 | return clo; | 1559 | return clo; |
1559 | } | 1560 | } |
@@ -1567,112 +1568,112 @@ multirecord_option(char shortName, | |||
1567 | * @return 0 ok, 1 on error | 1568 | * @return 0 ok, 1 on error |
1568 | */ | 1569 | */ |
1569 | int | 1570 | int |
1570 | main(int argc, char *const *argv) | 1571 | main (int argc, char *const *argv) |
1571 | { | 1572 | { |
1572 | struct GNUNET_GETOPT_CommandLineOption options[] = | 1573 | struct GNUNET_GETOPT_CommandLineOption options[] = |
1573 | { GNUNET_GETOPT_option_flag('a', "add", gettext_noop("add record"), &add), | 1574 | { GNUNET_GETOPT_option_flag ('a', "add", gettext_noop ("add record"), &add), |
1574 | GNUNET_GETOPT_option_flag('d', | 1575 | GNUNET_GETOPT_option_flag ('d', |
1575 | "delete", | 1576 | "delete", |
1576 | gettext_noop("delete record"), | 1577 | gettext_noop ("delete record"), |
1577 | &del), | 1578 | &del), |
1578 | GNUNET_GETOPT_option_flag('D', | 1579 | GNUNET_GETOPT_option_flag ('D', |
1579 | "display", | 1580 | "display", |
1580 | gettext_noop("display records"), | 1581 | gettext_noop ("display records"), |
1581 | &list), | 1582 | &list), |
1582 | GNUNET_GETOPT_option_string( | 1583 | GNUNET_GETOPT_option_string ( |
1583 | 'e', | 1584 | 'e', |
1584 | "expiration", | 1585 | "expiration", |
1585 | "TIME", | 1586 | "TIME", |
1586 | gettext_noop( | 1587 | gettext_noop ( |
1587 | "expiration time for record to use (for adding only), \"never\" is possible"), | 1588 | "expiration time for record to use (for adding only), \"never\" is possible"), |
1588 | &expirationstring), | 1589 | &expirationstring), |
1589 | GNUNET_GETOPT_option_string('i', | 1590 | GNUNET_GETOPT_option_string ('i', |
1590 | "nick", | 1591 | "nick", |
1591 | "NICKNAME", | 1592 | "NICKNAME", |
1592 | gettext_noop( | 1593 | gettext_noop ( |
1593 | "set the desired nick name for the zone"), | 1594 | "set the desired nick name for the zone"), |
1594 | &nickstring), | 1595 | &nickstring), |
1595 | GNUNET_GETOPT_option_flag('m', | 1596 | GNUNET_GETOPT_option_flag ('m', |
1596 | "monitor", | 1597 | "monitor", |
1597 | gettext_noop( | 1598 | gettext_noop ( |
1598 | "monitor changes in the namestore"), | 1599 | "monitor changes in the namestore"), |
1599 | &monitor), | 1600 | &monitor), |
1600 | GNUNET_GETOPT_option_string('n', | 1601 | GNUNET_GETOPT_option_string ('n', |
1601 | "name", | 1602 | "name", |
1602 | "NAME", | 1603 | "NAME", |
1603 | gettext_noop( | 1604 | gettext_noop ( |
1604 | "name of the record to add/delete/display"), | 1605 | "name of the record to add/delete/display"), |
1605 | &name), | 1606 | &name), |
1606 | GNUNET_GETOPT_option_string('r', | 1607 | GNUNET_GETOPT_option_string ('r', |
1607 | "reverse", | 1608 | "reverse", |
1608 | "PKEY", | 1609 | "PKEY", |
1609 | gettext_noop( | 1610 | gettext_noop ( |
1610 | "determine our name for the given PKEY"), | 1611 | "determine our name for the given PKEY"), |
1611 | &reverse_pkey), | 1612 | &reverse_pkey), |
1612 | multirecord_option( | 1613 | multirecord_option ( |
1613 | 'R', | 1614 | 'R', |
1614 | "replace", | 1615 | "replace", |
1615 | "RECORDLINE", | 1616 | "RECORDLINE", |
1616 | gettext_noop( | 1617 | gettext_noop ( |
1617 | "set record set to values given by (possibly multiple) RECORDLINES; can be specified multiple times"), | 1618 | "set record set to values given by (possibly multiple) RECORDLINES; can be specified multiple times"), |
1618 | &recordset), | 1619 | &recordset), |
1619 | GNUNET_GETOPT_option_string('t', | 1620 | GNUNET_GETOPT_option_string ('t', |
1620 | "type", | 1621 | "type", |
1621 | "TYPE", | 1622 | "TYPE", |
1622 | gettext_noop( | 1623 | gettext_noop ( |
1623 | "type of the record to add/delete/display"), | 1624 | "type of the record to add/delete/display"), |
1624 | &typestring), | 1625 | &typestring), |
1625 | GNUNET_GETOPT_option_string('u', | 1626 | GNUNET_GETOPT_option_string ('u', |
1626 | "uri", | 1627 | "uri", |
1627 | "URI", | 1628 | "URI", |
1628 | gettext_noop("URI to import into our zone"), | 1629 | gettext_noop ("URI to import into our zone"), |
1629 | &uri), | 1630 | &uri), |
1630 | GNUNET_GETOPT_option_string('V', | 1631 | GNUNET_GETOPT_option_string ('V', |
1631 | "value", | 1632 | "value", |
1632 | "VALUE", | 1633 | "VALUE", |
1633 | gettext_noop( | 1634 | gettext_noop ( |
1634 | "value of the record to add/delete"), | 1635 | "value of the record to add/delete"), |
1635 | &value), | 1636 | &value), |
1636 | GNUNET_GETOPT_option_flag('p', | 1637 | GNUNET_GETOPT_option_flag ('p', |
1637 | "public", | 1638 | "public", |
1638 | gettext_noop("create or list public record"), | 1639 | gettext_noop ("create or list public record"), |
1639 | &is_public), | 1640 | &is_public), |
1640 | GNUNET_GETOPT_option_flag( | 1641 | GNUNET_GETOPT_option_flag ( |
1641 | 's', | 1642 | 's', |
1642 | "shadow", | 1643 | "shadow", |
1643 | gettext_noop( | 1644 | gettext_noop ( |
1644 | "create shadow record (only valid if all other records of the same type have expired"), | 1645 | "create shadow record (only valid if all other records of the same type have expired"), |
1645 | &is_shadow), | 1646 | &is_shadow), |
1646 | GNUNET_GETOPT_option_string('z', | 1647 | GNUNET_GETOPT_option_string ('z', |
1647 | "zone", | 1648 | "zone", |
1648 | "EGO", | 1649 | "EGO", |
1649 | gettext_noop( | 1650 | gettext_noop ( |
1650 | "name of the ego controlling the zone"), | 1651 | "name of the ego controlling the zone"), |
1651 | &ego_name), | 1652 | &ego_name), |
1652 | GNUNET_GETOPT_OPTION_END }; | 1653 | GNUNET_GETOPT_OPTION_END }; |
1653 | int lret; | 1654 | int lret; |
1654 | 1655 | ||
1655 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) | 1656 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
1656 | return 2; | 1657 | return 2; |
1657 | 1658 | ||
1658 | is_public = -1; | 1659 | is_public = -1; |
1659 | is_shadow = -1; | 1660 | is_shadow = -1; |
1660 | GNUNET_log_setup("gnunet-namestore", "WARNING", NULL); | 1661 | GNUNET_log_setup ("gnunet-namestore", "WARNING", NULL); |
1661 | if (GNUNET_OK != | 1662 | if (GNUNET_OK != |
1662 | (lret = GNUNET_PROGRAM_run(argc, | 1663 | (lret = GNUNET_PROGRAM_run (argc, |
1663 | argv, | 1664 | argv, |
1664 | "gnunet-namestore", | 1665 | "gnunet-namestore", |
1665 | _("GNUnet zone manipulation tool"), | 1666 | _ ("GNUnet zone manipulation tool"), |
1666 | options, | 1667 | options, |
1667 | &run, | 1668 | &run, |
1668 | NULL))) | 1669 | NULL))) |
1669 | { | 1670 | { |
1670 | GNUNET_free((void *)argv); | 1671 | GNUNET_free ((void *) argv); |
1671 | GNUNET_CRYPTO_ecdsa_key_clear(&zone_pkey); | 1672 | GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey); |
1672 | return lret; | 1673 | return lret; |
1673 | } | 1674 | } |
1674 | GNUNET_free((void *)argv); | 1675 | GNUNET_free ((void *) argv); |
1675 | GNUNET_CRYPTO_ecdsa_key_clear(&zone_pkey); | 1676 | GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey); |
1676 | return ret; | 1677 | return ret; |
1677 | } | 1678 | } |
1678 | 1679 | ||
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index 71754081e..70e879ce9 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -36,7 +36,7 @@ | |||
36 | #include "namestore.h" | 36 | #include "namestore.h" |
37 | 37 | ||
38 | #define LOG_STRERROR_FILE(kind, syscall, filename) \ | 38 | #define LOG_STRERROR_FILE(kind, syscall, filename) \ |
39 | GNUNET_log_from_strerror_file(kind, "util", syscall, filename) | 39 | GNUNET_log_from_strerror_file (kind, "util", syscall, filename) |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * If a monitor takes more than 1 minute to process an event, print a warning. | 42 | * If a monitor takes more than 1 minute to process an event, print a warning. |
@@ -57,7 +57,8 @@ struct NamestoreClient; | |||
57 | /** | 57 | /** |
58 | * A namestore iteration operation. | 58 | * A namestore iteration operation. |
59 | */ | 59 | */ |
60 | struct ZoneIteration { | 60 | struct ZoneIteration |
61 | { | ||
61 | /** | 62 | /** |
62 | * Next element in the DLL | 63 | * Next element in the DLL |
63 | */ | 64 | */ |
@@ -124,7 +125,8 @@ struct ZoneIteration { | |||
124 | /** | 125 | /** |
125 | * A namestore client | 126 | * A namestore client |
126 | */ | 127 | */ |
127 | struct NamestoreClient { | 128 | struct NamestoreClient |
129 | { | ||
128 | /** | 130 | /** |
129 | * The client | 131 | * The client |
130 | */ | 132 | */ |
@@ -152,7 +154,8 @@ struct NamestoreClient { | |||
152 | /** | 154 | /** |
153 | * A namestore monitor. | 155 | * A namestore monitor. |
154 | */ | 156 | */ |
155 | struct ZoneMonitor { | 157 | struct ZoneMonitor |
158 | { | ||
156 | /** | 159 | /** |
157 | * Next element in the DLL | 160 | * Next element in the DLL |
158 | */ | 161 | */ |
@@ -229,7 +232,8 @@ struct ZoneMonitor { | |||
229 | /** | 232 | /** |
230 | * Pending operation on the namecache. | 233 | * Pending operation on the namecache. |
231 | */ | 234 | */ |
232 | struct CacheOperation { | 235 | struct CacheOperation |
236 | { | ||
233 | /** | 237 | /** |
234 | * Kept in a DLL. | 238 | * Kept in a DLL. |
235 | */ | 239 | */ |
@@ -267,7 +271,8 @@ struct CacheOperation { | |||
267 | * Information for an ongoing #handle_record_store() operation. | 271 | * Information for an ongoing #handle_record_store() operation. |
268 | * Needed as we may wait for monitors to be ready for the notification. | 272 | * Needed as we may wait for monitors to be ready for the notification. |
269 | */ | 273 | */ |
270 | struct StoreActivity { | 274 | struct StoreActivity |
275 | { | ||
271 | /** | 276 | /** |
272 | * Kept in a DLL. | 277 | * Kept in a DLL. |
273 | */ | 278 | */ |
@@ -304,7 +309,8 @@ struct StoreActivity { | |||
304 | /** | 309 | /** |
305 | * Entry in list of cached nick resolutions. | 310 | * Entry in list of cached nick resolutions. |
306 | */ | 311 | */ |
307 | struct NickCache { | 312 | struct NickCache |
313 | { | ||
308 | /** | 314 | /** |
309 | * Zone the cache entry is for. | 315 | * Zone the cache entry is for. |
310 | */ | 316 | */ |
@@ -411,38 +417,38 @@ static int disable_namecache; | |||
411 | * @param cls unused | 417 | * @param cls unused |
412 | */ | 418 | */ |
413 | static void | 419 | static void |
414 | cleanup_task(void *cls) | 420 | cleanup_task (void *cls) |
415 | { | 421 | { |
416 | struct CacheOperation *cop; | 422 | struct CacheOperation *cop; |
417 | 423 | ||
418 | (void)cls; | 424 | (void) cls; |
419 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Stopping namestore service\n"); | 425 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping namestore service\n"); |
420 | while (NULL != (cop = cop_head)) | 426 | while (NULL != (cop = cop_head)) |
421 | { | 427 | { |
422 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 428 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
423 | "Aborting incomplete namecache operation\n"); | 429 | "Aborting incomplete namecache operation\n"); |
424 | GNUNET_NAMECACHE_cancel(cop->qe); | 430 | GNUNET_NAMECACHE_cancel (cop->qe); |
425 | GNUNET_CONTAINER_DLL_remove(cop_head, cop_tail, cop); | 431 | GNUNET_CONTAINER_DLL_remove (cop_head, cop_tail, cop); |
426 | GNUNET_free(cop); | 432 | GNUNET_free (cop); |
427 | } | 433 | } |
428 | if (NULL != namecache) | 434 | if (NULL != namecache) |
429 | { | 435 | { |
430 | GNUNET_NAMECACHE_disconnect(namecache); | 436 | GNUNET_NAMECACHE_disconnect (namecache); |
431 | namecache = NULL; | 437 | namecache = NULL; |
432 | } | 438 | } |
433 | GNUNET_break(NULL == GNUNET_PLUGIN_unload(db_lib_name, GSN_database)); | 439 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, GSN_database)); |
434 | GNUNET_free(db_lib_name); | 440 | GNUNET_free (db_lib_name); |
435 | db_lib_name = NULL; | 441 | db_lib_name = NULL; |
436 | if (NULL != monitor_nc) | 442 | if (NULL != monitor_nc) |
437 | { | 443 | { |
438 | GNUNET_notification_context_destroy(monitor_nc); | 444 | GNUNET_notification_context_destroy (monitor_nc); |
439 | monitor_nc = NULL; | 445 | monitor_nc = NULL; |
440 | } | 446 | } |
441 | if (NULL != statistics) | 447 | if (NULL != statistics) |
442 | { | 448 | { |
443 | GNUNET_STATISTICS_destroy(statistics, GNUNET_NO); | 449 | GNUNET_STATISTICS_destroy (statistics, GNUNET_NO); |
444 | statistics = NULL; | 450 | statistics = NULL; |
445 | } | 451 | } |
446 | } | 452 | } |
447 | 453 | ||
448 | 454 | ||
@@ -452,11 +458,11 @@ cleanup_task(void *cls) | |||
452 | * @param sa activity to free | 458 | * @param sa activity to free |
453 | */ | 459 | */ |
454 | static void | 460 | static void |
455 | free_store_activity(struct StoreActivity *sa) | 461 | free_store_activity (struct StoreActivity *sa) |
456 | { | 462 | { |
457 | GNUNET_CONTAINER_DLL_remove(sa_head, sa_tail, sa); | 463 | GNUNET_CONTAINER_DLL_remove (sa_head, sa_tail, sa); |
458 | GNUNET_free(sa->conv_name); | 464 | GNUNET_free (sa->conv_name); |
459 | GNUNET_free(sa); | 465 | GNUNET_free (sa); |
460 | } | 466 | } |
461 | 467 | ||
462 | 468 | ||
@@ -473,37 +479,37 @@ free_store_activity(struct StoreActivity *sa) | |||
473 | * @param rd records stored under @a label in the zone | 479 | * @param rd records stored under @a label in the zone |
474 | */ | 480 | */ |
475 | static void | 481 | static void |
476 | lookup_nick_it(void *cls, | 482 | lookup_nick_it (void *cls, |
477 | uint64_t seq, | 483 | uint64_t seq, |
478 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key, | 484 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key, |
479 | const char *label, | 485 | const char *label, |
480 | unsigned int rd_count, | 486 | unsigned int rd_count, |
481 | const struct GNUNET_GNSRECORD_Data *rd) | 487 | const struct GNUNET_GNSRECORD_Data *rd) |
482 | { | 488 | { |
483 | struct GNUNET_GNSRECORD_Data **res = cls; | 489 | struct GNUNET_GNSRECORD_Data **res = cls; |
484 | 490 | ||
485 | (void)private_key; | 491 | (void) private_key; |
486 | GNUNET_assert(0 != seq); | 492 | GNUNET_assert (0 != seq); |
487 | if (0 != strcmp(label, GNUNET_GNS_EMPTY_LABEL_AT)) | 493 | if (0 != strcmp (label, GNUNET_GNS_EMPTY_LABEL_AT)) |
488 | { | 494 | { |
489 | GNUNET_break(0); | 495 | GNUNET_break (0); |
490 | return; | 496 | return; |
491 | } | 497 | } |
492 | for (unsigned int c = 0; c < rd_count; c++) | 498 | for (unsigned int c = 0; c < rd_count; c++) |
499 | { | ||
500 | if (GNUNET_GNSRECORD_TYPE_NICK == rd[c].record_type) | ||
493 | { | 501 | { |
494 | if (GNUNET_GNSRECORD_TYPE_NICK == rd[c].record_type) | 502 | (*res) = |
495 | { | 503 | GNUNET_malloc (rd[c].data_size + sizeof(struct GNUNET_GNSRECORD_Data)); |
496 | (*res) = | 504 | (*res)->data = &(*res)[1]; |
497 | GNUNET_malloc(rd[c].data_size + sizeof(struct GNUNET_GNSRECORD_Data)); | 505 | GNUNET_memcpy ((void *) (*res)->data, rd[c].data, rd[c].data_size); |
498 | (*res)->data = &(*res)[1]; | 506 | (*res)->data_size = rd[c].data_size; |
499 | GNUNET_memcpy((void *)(*res)->data, rd[c].data, rd[c].data_size); | 507 | (*res)->expiration_time = rd[c].expiration_time; |
500 | (*res)->data_size = rd[c].data_size; | 508 | (*res)->flags = rd[c].flags; |
501 | (*res)->expiration_time = rd[c].expiration_time; | 509 | (*res)->record_type = GNUNET_GNSRECORD_TYPE_NICK; |
502 | (*res)->flags = rd[c].flags; | 510 | return; |
503 | (*res)->record_type = GNUNET_GNSRECORD_TYPE_NICK; | ||
504 | return; | ||
505 | } | ||
506 | } | 511 | } |
512 | } | ||
507 | (*res) = NULL; | 513 | (*res) = NULL; |
508 | } | 514 | } |
509 | 515 | ||
@@ -515,39 +521,39 @@ lookup_nick_it(void *cls, | |||
515 | * @param nick nick entry to cache | 521 | * @param nick nick entry to cache |
516 | */ | 522 | */ |
517 | static void | 523 | static void |
518 | cache_nick(const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 524 | cache_nick (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
519 | const struct GNUNET_GNSRECORD_Data *nick) | 525 | const struct GNUNET_GNSRECORD_Data *nick) |
520 | { | 526 | { |
521 | struct NickCache *oldest; | 527 | struct NickCache *oldest; |
522 | 528 | ||
523 | oldest = NULL; | 529 | oldest = NULL; |
524 | for (unsigned int i = 0; i < NC_SIZE; i++) | 530 | for (unsigned int i = 0; i < NC_SIZE; i++) |
525 | { | 531 | { |
526 | struct NickCache *pos = &nick_cache[i]; | 532 | struct NickCache *pos = &nick_cache[i]; |
527 | 533 | ||
528 | if ((NULL == oldest) || | 534 | if ((NULL == oldest) || |
529 | (oldest->last_used.abs_value_us > pos->last_used.abs_value_us)) | 535 | (oldest->last_used.abs_value_us > pos->last_used.abs_value_us)) |
530 | oldest = pos; | 536 | oldest = pos; |
531 | if (0 == GNUNET_memcmp(zone, &pos->zone)) | 537 | if (0 == GNUNET_memcmp (zone, &pos->zone)) |
532 | { | 538 | { |
533 | oldest = pos; | 539 | oldest = pos; |
534 | break; | 540 | break; |
535 | } | ||
536 | } | 541 | } |
537 | GNUNET_free_non_null(oldest->rd); | 542 | } |
543 | GNUNET_free_non_null (oldest->rd); | ||
538 | oldest->zone = *zone; | 544 | oldest->zone = *zone; |
539 | if (NULL != nick) | 545 | if (NULL != nick) |
540 | { | 546 | { |
541 | oldest->rd = GNUNET_malloc(sizeof(*nick) + nick->data_size); | 547 | oldest->rd = GNUNET_malloc (sizeof(*nick) + nick->data_size); |
542 | *oldest->rd = *nick; | 548 | *oldest->rd = *nick; |
543 | oldest->rd->data = &oldest->rd[1]; | 549 | oldest->rd->data = &oldest->rd[1]; |
544 | memcpy(&oldest->rd[1], nick->data, nick->data_size); | 550 | memcpy (&oldest->rd[1], nick->data, nick->data_size); |
545 | } | 551 | } |
546 | else | 552 | else |
547 | { | 553 | { |
548 | oldest->rd = NULL; | 554 | oldest->rd = NULL; |
549 | } | 555 | } |
550 | oldest->last_used = GNUNET_TIME_absolute_get(); | 556 | oldest->last_used = GNUNET_TIME_absolute_get (); |
551 | } | 557 | } |
552 | 558 | ||
553 | 559 | ||
@@ -558,7 +564,7 @@ cache_nick(const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | |||
558 | * @return NULL if no NICK record was found | 564 | * @return NULL if no NICK record was found |
559 | */ | 565 | */ |
560 | static struct GNUNET_GNSRECORD_Data * | 566 | static struct GNUNET_GNSRECORD_Data * |
561 | get_nick_record(const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone) | 567 | get_nick_record (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone) |
562 | { | 568 | { |
563 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | 569 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; |
564 | struct GNUNET_GNSRECORD_Data *nick; | 570 | struct GNUNET_GNSRECORD_Data *nick; |
@@ -566,53 +572,53 @@ get_nick_record(const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone) | |||
566 | 572 | ||
567 | /* check cache first */ | 573 | /* check cache first */ |
568 | for (unsigned int i = 0; i < NC_SIZE; i++) | 574 | for (unsigned int i = 0; i < NC_SIZE; i++) |
575 | { | ||
576 | struct NickCache *pos = &nick_cache[i]; | ||
577 | if ((NULL != pos->rd) && (0 == GNUNET_memcmp (zone, &pos->zone))) | ||
569 | { | 578 | { |
570 | struct NickCache *pos = &nick_cache[i]; | 579 | if (NULL == pos->rd) |
571 | if ((NULL != pos->rd) && (0 == GNUNET_memcmp(zone, &pos->zone))) | 580 | return NULL; |
572 | { | 581 | nick = GNUNET_malloc (sizeof(*nick) + pos->rd->data_size); |
573 | if (NULL == pos->rd) | 582 | *nick = *pos->rd; |
574 | return NULL; | 583 | nick->data = &nick[1]; |
575 | nick = GNUNET_malloc(sizeof(*nick) + pos->rd->data_size); | 584 | memcpy (&nick[1], pos->rd->data, pos->rd->data_size); |
576 | *nick = *pos->rd; | 585 | pos->last_used = GNUNET_TIME_absolute_get (); |
577 | nick->data = &nick[1]; | 586 | return nick; |
578 | memcpy(&nick[1], pos->rd->data, pos->rd->data_size); | ||
579 | pos->last_used = GNUNET_TIME_absolute_get(); | ||
580 | return nick; | ||
581 | } | ||
582 | } | 587 | } |
588 | } | ||
583 | 589 | ||
584 | nick = NULL; | 590 | nick = NULL; |
585 | res = GSN_database->lookup_records(GSN_database->cls, | 591 | res = GSN_database->lookup_records (GSN_database->cls, |
586 | zone, | 592 | zone, |
587 | GNUNET_GNS_EMPTY_LABEL_AT, | 593 | GNUNET_GNS_EMPTY_LABEL_AT, |
588 | &lookup_nick_it, | 594 | &lookup_nick_it, |
589 | &nick); | 595 | &nick); |
590 | if ((GNUNET_OK != res) || (NULL == nick)) | 596 | if ((GNUNET_OK != res) || (NULL == nick)) |
597 | { | ||
598 | #if ! defined(GNUNET_CULL_LOGGING) | ||
599 | static int do_log = GNUNET_LOG_CALL_STATUS; | ||
600 | |||
601 | if (0 == do_log) | ||
602 | do_log = GNUNET_get_log_call_status (GNUNET_ERROR_TYPE_DEBUG, | ||
603 | "namestore", | ||
604 | __FILE__, | ||
605 | __FUNCTION__, | ||
606 | __LINE__); | ||
607 | if (1 == do_log) | ||
591 | { | 608 | { |
592 | #if !defined(GNUNET_CULL_LOGGING) | 609 | GNUNET_CRYPTO_ecdsa_key_get_public (zone, &pub); |
593 | static int do_log = GNUNET_LOG_CALL_STATUS; | 610 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
594 | 611 | "No nick name set for zone `%s'\n", | |
595 | if (0 == do_log) | 612 | GNUNET_GNSRECORD_z2s (&pub)); |
596 | do_log = GNUNET_get_log_call_status(GNUNET_ERROR_TYPE_DEBUG, | ||
597 | "namestore", | ||
598 | __FILE__, | ||
599 | __FUNCTION__, | ||
600 | __LINE__); | ||
601 | if (1 == do_log) | ||
602 | { | ||
603 | GNUNET_CRYPTO_ecdsa_key_get_public(zone, &pub); | ||
604 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | ||
605 | "No nick name set for zone `%s'\n", | ||
606 | GNUNET_GNSRECORD_z2s(&pub)); | ||
607 | } | ||
608 | #endif | ||
609 | /* update cache */ | ||
610 | cache_nick(zone, NULL); | ||
611 | return NULL; | ||
612 | } | 613 | } |
614 | #endif | ||
615 | /* update cache */ | ||
616 | cache_nick (zone, NULL); | ||
617 | return NULL; | ||
618 | } | ||
613 | 619 | ||
614 | /* update cache */ | 620 | /* update cache */ |
615 | cache_nick(zone, nick); | 621 | cache_nick (zone, nick); |
616 | return nick; | 622 | return nick; |
617 | } | 623 | } |
618 | 624 | ||
@@ -633,11 +639,11 @@ get_nick_record(const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone) | |||
633 | * allocated in the same chunk of memory! | 639 | * allocated in the same chunk of memory! |
634 | */ | 640 | */ |
635 | static void | 641 | static void |
636 | merge_with_nick_records(const struct GNUNET_GNSRECORD_Data *nick_rd, | 642 | merge_with_nick_records (const struct GNUNET_GNSRECORD_Data *nick_rd, |
637 | unsigned int rd2_length, | 643 | unsigned int rd2_length, |
638 | const struct GNUNET_GNSRECORD_Data *rd2, | 644 | const struct GNUNET_GNSRECORD_Data *rd2, |
639 | unsigned int *rdc_res, | 645 | unsigned int *rdc_res, |
640 | struct GNUNET_GNSRECORD_Data **rd_res) | 646 | struct GNUNET_GNSRECORD_Data **rd_res) |
641 | { | 647 | { |
642 | uint64_t latest_expiration; | 648 | uint64_t latest_expiration; |
643 | size_t req; | 649 | size_t req; |
@@ -647,54 +653,54 @@ merge_with_nick_records(const struct GNUNET_GNSRECORD_Data *nick_rd, | |||
647 | 653 | ||
648 | (*rdc_res) = 1 + rd2_length; | 654 | (*rdc_res) = 1 + rd2_length; |
649 | if (0 == 1 + rd2_length) | 655 | if (0 == 1 + rd2_length) |
650 | { | 656 | { |
651 | GNUNET_break(0); | 657 | GNUNET_break (0); |
652 | (*rd_res) = NULL; | 658 | (*rd_res) = NULL; |
653 | return; | 659 | return; |
654 | } | 660 | } |
655 | req = sizeof(struct GNUNET_GNSRECORD_Data) + nick_rd->data_size; | 661 | req = sizeof(struct GNUNET_GNSRECORD_Data) + nick_rd->data_size; |
656 | for (unsigned int i = 0; i < rd2_length; i++) | 662 | for (unsigned int i = 0; i < rd2_length; i++) |
657 | { | 663 | { |
658 | const struct GNUNET_GNSRECORD_Data *orig = &rd2[i]; | 664 | const struct GNUNET_GNSRECORD_Data *orig = &rd2[i]; |
659 | 665 | ||
660 | if (req + sizeof(struct GNUNET_GNSRECORD_Data) + orig->data_size < req) | 666 | if (req + sizeof(struct GNUNET_GNSRECORD_Data) + orig->data_size < req) |
661 | { | 667 | { |
662 | GNUNET_break(0); | 668 | GNUNET_break (0); |
663 | (*rd_res) = NULL; | 669 | (*rd_res) = NULL; |
664 | return; | 670 | return; |
665 | } | ||
666 | req += sizeof(struct GNUNET_GNSRECORD_Data) + orig->data_size; | ||
667 | } | 671 | } |
668 | target = GNUNET_malloc(req); | 672 | req += sizeof(struct GNUNET_GNSRECORD_Data) + orig->data_size; |
673 | } | ||
674 | target = GNUNET_malloc (req); | ||
669 | (*rd_res) = target; | 675 | (*rd_res) = target; |
670 | data = (char *)&target[1 + rd2_length]; | 676 | data = (char *) &target[1 + rd2_length]; |
671 | data_offset = 0; | 677 | data_offset = 0; |
672 | latest_expiration = 0; | 678 | latest_expiration = 0; |
673 | for (unsigned int i = 0; i < rd2_length; i++) | 679 | for (unsigned int i = 0; i < rd2_length; i++) |
674 | { | 680 | { |
675 | const struct GNUNET_GNSRECORD_Data *orig = &rd2[i]; | 681 | const struct GNUNET_GNSRECORD_Data *orig = &rd2[i]; |
676 | 682 | ||
677 | if (0 != (orig->flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) | 683 | if (0 != (orig->flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) |
678 | { | 684 | { |
679 | if ((GNUNET_TIME_absolute_get().abs_value_us + orig->expiration_time) > | 685 | if ((GNUNET_TIME_absolute_get ().abs_value_us + orig->expiration_time) > |
680 | latest_expiration) | 686 | latest_expiration) |
681 | latest_expiration = orig->expiration_time; | ||
682 | } | ||
683 | else if (orig->expiration_time > latest_expiration) | ||
684 | latest_expiration = orig->expiration_time; | 687 | latest_expiration = orig->expiration_time; |
685 | target[i] = *orig; | ||
686 | target[i].data = (void *)&data[data_offset]; | ||
687 | GNUNET_memcpy(&data[data_offset], orig->data, orig->data_size); | ||
688 | data_offset += orig->data_size; | ||
689 | } | 688 | } |
689 | else if (orig->expiration_time > latest_expiration) | ||
690 | latest_expiration = orig->expiration_time; | ||
691 | target[i] = *orig; | ||
692 | target[i].data = (void *) &data[data_offset]; | ||
693 | GNUNET_memcpy (&data[data_offset], orig->data, orig->data_size); | ||
694 | data_offset += orig->data_size; | ||
695 | } | ||
690 | /* append nick */ | 696 | /* append nick */ |
691 | target[rd2_length] = *nick_rd; | 697 | target[rd2_length] = *nick_rd; |
692 | target[rd2_length].expiration_time = latest_expiration; | 698 | target[rd2_length].expiration_time = latest_expiration; |
693 | target[rd2_length].data = (void *)&data[data_offset]; | 699 | target[rd2_length].data = (void *) &data[data_offset]; |
694 | GNUNET_memcpy(&data[data_offset], nick_rd->data, nick_rd->data_size); | 700 | GNUNET_memcpy (&data[data_offset], nick_rd->data, nick_rd->data_size); |
695 | data_offset += nick_rd->data_size; | 701 | data_offset += nick_rd->data_size; |
696 | GNUNET_assert(req == (sizeof(struct GNUNET_GNSRECORD_Data)) * (*rdc_res) + | 702 | GNUNET_assert (req == (sizeof(struct GNUNET_GNSRECORD_Data)) * (*rdc_res) |
697 | data_offset); | 703 | + data_offset); |
698 | } | 704 | } |
699 | 705 | ||
700 | 706 | ||
@@ -710,12 +716,12 @@ merge_with_nick_records(const struct GNUNET_GNSRECORD_Data *nick_rd, | |||
710 | * @param rd array of records | 716 | * @param rd array of records |
711 | */ | 717 | */ |
712 | static void | 718 | static void |
713 | send_lookup_response(struct NamestoreClient *nc, | 719 | send_lookup_response (struct NamestoreClient *nc, |
714 | uint32_t request_id, | 720 | uint32_t request_id, |
715 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 721 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, |
716 | const char *name, | 722 | const char *name, |
717 | unsigned int rd_count, | 723 | unsigned int rd_count, |
718 | const struct GNUNET_GNSRECORD_Data *rd) | 724 | const struct GNUNET_GNSRECORD_Data *rd) |
719 | { | 725 | { |
720 | struct GNUNET_MQ_Envelope *env; | 726 | struct GNUNET_MQ_Envelope *env; |
721 | struct RecordResultMessage *zir_msg; | 727 | struct RecordResultMessage *zir_msg; |
@@ -727,63 +733,63 @@ send_lookup_response(struct NamestoreClient *nc, | |||
727 | char *name_tmp; | 733 | char *name_tmp; |
728 | char *rd_ser; | 734 | char *rd_ser; |
729 | 735 | ||
730 | nick = get_nick_record(zone_key); | 736 | nick = get_nick_record (zone_key); |
731 | GNUNET_assert(-1 != GNUNET_GNSRECORD_records_get_size(rd_count, rd)); | 737 | GNUNET_assert (-1 != GNUNET_GNSRECORD_records_get_size (rd_count, rd)); |
732 | 738 | ||
733 | if ((NULL != nick) && (0 != strcmp(name, GNUNET_GNS_EMPTY_LABEL_AT))) | 739 | if ((NULL != nick) && (0 != strcmp (name, GNUNET_GNS_EMPTY_LABEL_AT))) |
734 | { | 740 | { |
735 | nick->flags = | 741 | nick->flags = |
736 | (nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE; | 742 | (nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE; |
737 | merge_with_nick_records(nick, rd_count, rd, &res_count, &res); | 743 | merge_with_nick_records (nick, rd_count, rd, &res_count, &res); |
738 | GNUNET_free(nick); | 744 | GNUNET_free (nick); |
739 | } | 745 | } |
740 | else | 746 | else |
741 | { | 747 | { |
742 | res_count = rd_count; | 748 | res_count = rd_count; |
743 | res = (struct GNUNET_GNSRECORD_Data *)rd; | 749 | res = (struct GNUNET_GNSRECORD_Data *) rd; |
744 | } | 750 | } |
745 | 751 | ||
746 | GNUNET_assert(-1 != GNUNET_GNSRECORD_records_get_size(res_count, res)); | 752 | GNUNET_assert (-1 != GNUNET_GNSRECORD_records_get_size (res_count, res)); |
747 | 753 | ||
748 | 754 | ||
749 | name_len = strlen(name) + 1; | 755 | name_len = strlen (name) + 1; |
750 | rd_ser_len = GNUNET_GNSRECORD_records_get_size(res_count, res); | 756 | rd_ser_len = GNUNET_GNSRECORD_records_get_size (res_count, res); |
751 | if (rd_ser_len < 0) | 757 | if (rd_ser_len < 0) |
752 | { | 758 | { |
753 | GNUNET_break(0); | 759 | GNUNET_break (0); |
754 | GNUNET_SERVICE_client_drop(nc->client); | 760 | GNUNET_SERVICE_client_drop (nc->client); |
755 | return; | 761 | return; |
756 | } | 762 | } |
757 | if (((size_t)rd_ser_len) >= UINT16_MAX - name_len - sizeof(*zir_msg)) | 763 | if (((size_t) rd_ser_len) >= UINT16_MAX - name_len - sizeof(*zir_msg)) |
758 | { | 764 | { |
759 | GNUNET_break(0); | 765 | GNUNET_break (0); |
760 | GNUNET_SERVICE_client_drop(nc->client); | 766 | GNUNET_SERVICE_client_drop (nc->client); |
761 | return; | 767 | return; |
762 | } | 768 | } |
763 | env = GNUNET_MQ_msg_extra(zir_msg, | 769 | env = GNUNET_MQ_msg_extra (zir_msg, |
764 | name_len + rd_ser_len, | 770 | name_len + rd_ser_len, |
765 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT); | 771 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT); |
766 | zir_msg->gns_header.r_id = htonl(request_id); | 772 | zir_msg->gns_header.r_id = htonl (request_id); |
767 | zir_msg->name_len = htons(name_len); | 773 | zir_msg->name_len = htons (name_len); |
768 | zir_msg->rd_count = htons(res_count); | 774 | zir_msg->rd_count = htons (res_count); |
769 | zir_msg->rd_len = htons((uint16_t)rd_ser_len); | 775 | zir_msg->rd_len = htons ((uint16_t) rd_ser_len); |
770 | zir_msg->private_key = *zone_key; | 776 | zir_msg->private_key = *zone_key; |
771 | name_tmp = (char *)&zir_msg[1]; | 777 | name_tmp = (char *) &zir_msg[1]; |
772 | GNUNET_memcpy(name_tmp, name, name_len); | 778 | GNUNET_memcpy (name_tmp, name, name_len); |
773 | rd_ser = &name_tmp[name_len]; | 779 | rd_ser = &name_tmp[name_len]; |
774 | GNUNET_assert( | 780 | GNUNET_assert ( |
775 | rd_ser_len == | 781 | rd_ser_len == |
776 | GNUNET_GNSRECORD_records_serialize(res_count, res, rd_ser_len, rd_ser)); | 782 | GNUNET_GNSRECORD_records_serialize (res_count, res, rd_ser_len, rd_ser)); |
777 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 783 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
778 | "Sending RECORD_RESULT message with %u records\n", | 784 | "Sending RECORD_RESULT message with %u records\n", |
779 | res_count); | 785 | res_count); |
780 | GNUNET_STATISTICS_update(statistics, | 786 | GNUNET_STATISTICS_update (statistics, |
781 | "Record sets sent to clients", | 787 | "Record sets sent to clients", |
782 | 1, | 788 | 1, |
783 | GNUNET_NO); | 789 | GNUNET_NO); |
784 | GNUNET_MQ_send(nc->mq, env); | 790 | GNUNET_MQ_send (nc->mq, env); |
785 | if (rd != res) | 791 | if (rd != res) |
786 | GNUNET_free(res); | 792 | GNUNET_free (res); |
787 | } | 793 | } |
788 | 794 | ||
789 | 795 | ||
@@ -795,23 +801,23 @@ send_lookup_response(struct NamestoreClient *nc, | |||
795 | * @param rid client's request ID | 801 | * @param rid client's request ID |
796 | */ | 802 | */ |
797 | static void | 803 | static void |
798 | send_store_response(struct NamestoreClient *nc, int res, uint32_t rid) | 804 | send_store_response (struct NamestoreClient *nc, int res, uint32_t rid) |
799 | { | 805 | { |
800 | struct GNUNET_MQ_Envelope *env; | 806 | struct GNUNET_MQ_Envelope *env; |
801 | struct RecordStoreResponseMessage *rcr_msg; | 807 | struct RecordStoreResponseMessage *rcr_msg; |
802 | 808 | ||
803 | GNUNET_assert(NULL != nc); | 809 | GNUNET_assert (NULL != nc); |
804 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 810 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
805 | "Sending RECORD_STORE_RESPONSE message\n"); | 811 | "Sending RECORD_STORE_RESPONSE message\n"); |
806 | GNUNET_STATISTICS_update(statistics, | 812 | GNUNET_STATISTICS_update (statistics, |
807 | "Store requests completed", | 813 | "Store requests completed", |
808 | 1, | 814 | 1, |
809 | GNUNET_NO); | 815 | GNUNET_NO); |
810 | env = GNUNET_MQ_msg(rcr_msg, | 816 | env = GNUNET_MQ_msg (rcr_msg, |
811 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE); | 817 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE); |
812 | rcr_msg->gns_header.r_id = htonl(rid); | 818 | rcr_msg->gns_header.r_id = htonl (rid); |
813 | rcr_msg->op_result = htonl(res); | 819 | rcr_msg->op_result = htonl (res); |
814 | GNUNET_MQ_send(nc->mq, env); | 820 | GNUNET_MQ_send (nc->mq, env); |
815 | } | 821 | } |
816 | 822 | ||
817 | 823 | ||
@@ -822,21 +828,21 @@ send_store_response(struct NamestoreClient *nc, int res, uint32_t rid) | |||
822 | * @param zi zone iteration we are processing | 828 | * @param zi zone iteration we are processing |
823 | */ | 829 | */ |
824 | static void | 830 | static void |
825 | zone_iteration_done_client_continue(struct ZoneIteration *zi) | 831 | zone_iteration_done_client_continue (struct ZoneIteration *zi) |
826 | { | 832 | { |
827 | struct GNUNET_MQ_Envelope *env; | 833 | struct GNUNET_MQ_Envelope *env; |
828 | struct GNUNET_NAMESTORE_Header *em; | 834 | struct GNUNET_NAMESTORE_Header *em; |
829 | 835 | ||
830 | GNUNET_SERVICE_client_continue(zi->nc->client); | 836 | GNUNET_SERVICE_client_continue (zi->nc->client); |
831 | if (!zi->send_end) | 837 | if (! zi->send_end) |
832 | return; | 838 | return; |
833 | /* send empty response to indicate end of list */ | 839 | /* send empty response to indicate end of list */ |
834 | env = GNUNET_MQ_msg(em, GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT_END); | 840 | env = GNUNET_MQ_msg (em, GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT_END); |
835 | em->r_id = htonl(zi->request_id); | 841 | em->r_id = htonl (zi->request_id); |
836 | GNUNET_MQ_send(zi->nc->mq, env); | 842 | GNUNET_MQ_send (zi->nc->mq, env); |
837 | 843 | ||
838 | GNUNET_CONTAINER_DLL_remove(zi->nc->op_head, zi->nc->op_tail, zi); | 844 | GNUNET_CONTAINER_DLL_remove (zi->nc->op_head, zi->nc->op_tail, zi); |
839 | GNUNET_free(zi); | 845 | GNUNET_free (zi); |
840 | } | 846 | } |
841 | 847 | ||
842 | 848 | ||
@@ -848,30 +854,30 @@ zone_iteration_done_client_continue(struct ZoneIteration *zi) | |||
848 | * @param emsg error messages | 854 | * @param emsg error messages |
849 | */ | 855 | */ |
850 | static void | 856 | static void |
851 | finish_cache_operation(void *cls, int32_t success, const char *emsg) | 857 | finish_cache_operation (void *cls, int32_t success, const char *emsg) |
852 | { | 858 | { |
853 | struct CacheOperation *cop = cls; | 859 | struct CacheOperation *cop = cls; |
854 | struct ZoneIteration *zi; | 860 | struct ZoneIteration *zi; |
855 | 861 | ||
856 | if (NULL != emsg) | 862 | if (NULL != emsg) |
857 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 863 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
858 | _("Failed to replicate block in namecache: %s\n"), | 864 | _ ("Failed to replicate block in namecache: %s\n"), |
859 | emsg); | 865 | emsg); |
860 | else | 866 | else |
861 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "CACHE operation completed\n"); | 867 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CACHE operation completed\n"); |
862 | GNUNET_CONTAINER_DLL_remove(cop_head, cop_tail, cop); | 868 | GNUNET_CONTAINER_DLL_remove (cop_head, cop_tail, cop); |
863 | if (NULL != cop->nc) | 869 | if (NULL != cop->nc) |
864 | send_store_response(cop->nc, success, cop->rid); | 870 | send_store_response (cop->nc, success, cop->rid); |
865 | if (NULL != (zi = cop->zi)) | 871 | if (NULL != (zi = cop->zi)) |
872 | { | ||
873 | zi->cache_ops--; | ||
874 | if (0 == zi->cache_ops) | ||
866 | { | 875 | { |
867 | zi->cache_ops--; | 876 | /* unchoke zone iteration, cache has caught up */ |
868 | if (0 == zi->cache_ops) | 877 | zone_iteration_done_client_continue (zi); |
869 | { | ||
870 | /* unchoke zone iteration, cache has caught up */ | ||
871 | zone_iteration_done_client_continue(zi); | ||
872 | } | ||
873 | } | 878 | } |
874 | GNUNET_free(cop); | 879 | } |
880 | GNUNET_free (cop); | ||
875 | } | 881 | } |
876 | 882 | ||
877 | 883 | ||
@@ -888,13 +894,13 @@ finish_cache_operation(void *cls, int32_t success, const char *emsg) | |||
888 | * @param rd records stored under the given @a name | 894 | * @param rd records stored under the given @a name |
889 | */ | 895 | */ |
890 | static void | 896 | static void |
891 | refresh_block(struct NamestoreClient *nc, | 897 | refresh_block (struct NamestoreClient *nc, |
892 | struct ZoneIteration *zi, | 898 | struct ZoneIteration *zi, |
893 | uint32_t rid, | 899 | uint32_t rid, |
894 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 900 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, |
895 | const char *name, | 901 | const char *name, |
896 | unsigned int rd_count, | 902 | unsigned int rd_count, |
897 | const struct GNUNET_GNSRECORD_Data *rd) | 903 | const struct GNUNET_GNSRECORD_Data *rd) |
898 | { | 904 | { |
899 | struct GNUNET_GNSRECORD_Block *block; | 905 | struct GNUNET_GNSRECORD_Block *block; |
900 | struct CacheOperation *cop; | 906 | struct CacheOperation *cop; |
@@ -904,64 +910,64 @@ refresh_block(struct NamestoreClient *nc, | |||
904 | unsigned int res_count; | 910 | unsigned int res_count; |
905 | struct GNUNET_TIME_Absolute exp_time; | 911 | struct GNUNET_TIME_Absolute exp_time; |
906 | 912 | ||
907 | nick = get_nick_record(zone_key); | 913 | nick = get_nick_record (zone_key); |
908 | res_count = rd_count; | 914 | res_count = rd_count; |
909 | res = (struct GNUNET_GNSRECORD_Data *)rd; /* fixme: a bit unclean... */ | 915 | res = (struct GNUNET_GNSRECORD_Data *) rd; /* fixme: a bit unclean... */ |
910 | if (NULL != nick) | 916 | if (NULL != nick) |
911 | { | 917 | { |
912 | nick->flags = | 918 | nick->flags = |
913 | (nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE; | 919 | (nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE; |
914 | merge_with_nick_records(nick, rd_count, rd, &res_count, &res); | 920 | merge_with_nick_records (nick, rd_count, rd, &res_count, &res); |
915 | GNUNET_free(nick); | 921 | GNUNET_free (nick); |
916 | } | 922 | } |
917 | if (0 == res_count) | 923 | if (0 == res_count) |
918 | { | 924 | { |
919 | if (NULL != nc) | 925 | if (NULL != nc) |
920 | send_store_response(nc, GNUNET_OK, rid); | 926 | send_store_response (nc, GNUNET_OK, rid); |
921 | return; /* no data, no need to update cache */ | 927 | return; /* no data, no need to update cache */ |
922 | } | 928 | } |
923 | if (GNUNET_YES == disable_namecache) | 929 | if (GNUNET_YES == disable_namecache) |
924 | { | 930 | { |
925 | GNUNET_STATISTICS_update(statistics, | 931 | GNUNET_STATISTICS_update (statistics, |
926 | "Namecache updates skipped (NC disabled)", | 932 | "Namecache updates skipped (NC disabled)", |
927 | 1, | 933 | 1, |
928 | GNUNET_NO); | 934 | GNUNET_NO); |
929 | if (NULL != nc) | 935 | if (NULL != nc) |
930 | send_store_response(nc, GNUNET_OK, rid); | 936 | send_store_response (nc, GNUNET_OK, rid); |
931 | return; | 937 | return; |
932 | } | 938 | } |
933 | exp_time = GNUNET_GNSRECORD_record_get_expiration_time(res_count, res); | 939 | exp_time = GNUNET_GNSRECORD_record_get_expiration_time (res_count, res); |
934 | if (cache_keys) | 940 | if (cache_keys) |
935 | block = | 941 | block = |
936 | GNUNET_GNSRECORD_block_create2(zone_key, exp_time, name, res, res_count); | 942 | GNUNET_GNSRECORD_block_create2 (zone_key, exp_time, name, res, res_count); |
937 | else | 943 | else |
938 | block = | 944 | block = |
939 | GNUNET_GNSRECORD_block_create(zone_key, exp_time, name, res, res_count); | 945 | GNUNET_GNSRECORD_block_create (zone_key, exp_time, name, res, res_count); |
940 | GNUNET_assert(NULL != block); | 946 | GNUNET_assert (NULL != block); |
941 | GNUNET_CRYPTO_ecdsa_key_get_public(zone_key, &pkey); | 947 | GNUNET_CRYPTO_ecdsa_key_get_public (zone_key, &pkey); |
942 | GNUNET_log( | 948 | GNUNET_log ( |
943 | GNUNET_ERROR_TYPE_DEBUG, | 949 | GNUNET_ERROR_TYPE_DEBUG, |
944 | "Caching block for label `%s' with %u records and expiration %s in zone `%s' in namecache\n", | 950 | "Caching block for label `%s' with %u records and expiration %s in zone `%s' in namecache\n", |
945 | name, | 951 | name, |
946 | res_count, | 952 | res_count, |
947 | GNUNET_STRINGS_absolute_time_to_string(exp_time), | 953 | GNUNET_STRINGS_absolute_time_to_string (exp_time), |
948 | GNUNET_GNSRECORD_z2s(&pkey)); | 954 | GNUNET_GNSRECORD_z2s (&pkey)); |
949 | GNUNET_STATISTICS_update(statistics, | 955 | GNUNET_STATISTICS_update (statistics, |
950 | "Namecache updates pushed", | 956 | "Namecache updates pushed", |
951 | 1, | 957 | 1, |
952 | GNUNET_NO); | 958 | GNUNET_NO); |
953 | cop = GNUNET_new(struct CacheOperation); | 959 | cop = GNUNET_new (struct CacheOperation); |
954 | cop->nc = nc; | 960 | cop->nc = nc; |
955 | cop->zi = zi; | 961 | cop->zi = zi; |
956 | if (NULL != zi) | 962 | if (NULL != zi) |
957 | zi->cache_ops++; | 963 | zi->cache_ops++; |
958 | cop->rid = rid; | 964 | cop->rid = rid; |
959 | GNUNET_CONTAINER_DLL_insert(cop_head, cop_tail, cop); | 965 | GNUNET_CONTAINER_DLL_insert (cop_head, cop_tail, cop); |
960 | cop->qe = GNUNET_NAMECACHE_block_cache(namecache, | 966 | cop->qe = GNUNET_NAMECACHE_block_cache (namecache, |
961 | block, | 967 | block, |
962 | &finish_cache_operation, | 968 | &finish_cache_operation, |
963 | cop); | 969 | cop); |
964 | GNUNET_free(block); | 970 | GNUNET_free (block); |
965 | } | 971 | } |
966 | 972 | ||
967 | 973 | ||
@@ -971,16 +977,16 @@ refresh_block(struct NamestoreClient *nc, | |||
971 | * @param cls a `struct ZoneMonitor` to warn about | 977 | * @param cls a `struct ZoneMonitor` to warn about |
972 | */ | 978 | */ |
973 | static void | 979 | static void |
974 | warn_monitor_slow(void *cls) | 980 | warn_monitor_slow (void *cls) |
975 | { | 981 | { |
976 | struct ZoneMonitor *zm = cls; | 982 | struct ZoneMonitor *zm = cls; |
977 | 983 | ||
978 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 984 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
979 | "No response from monitor since %s\n", | 985 | "No response from monitor since %s\n", |
980 | GNUNET_STRINGS_absolute_time_to_string(zm->sa_waiting_start)); | 986 | GNUNET_STRINGS_absolute_time_to_string (zm->sa_waiting_start)); |
981 | zm->sa_wait_warning = GNUNET_SCHEDULER_add_delayed(MONITOR_STALL_WARN_DELAY, | 987 | zm->sa_wait_warning = GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY, |
982 | &warn_monitor_slow, | 988 | &warn_monitor_slow, |
983 | zm); | 989 | zm); |
984 | } | 990 | } |
985 | 991 | ||
986 | 992 | ||
@@ -990,7 +996,7 @@ warn_monitor_slow(void *cls) | |||
990 | * @param sa store activity to process | 996 | * @param sa store activity to process |
991 | */ | 997 | */ |
992 | static void | 998 | static void |
993 | continue_store_activity(struct StoreActivity *sa) | 999 | continue_store_activity (struct StoreActivity *sa) |
994 | { | 1000 | { |
995 | const struct RecordStoreMessage *rp_msg = sa->rsm; | 1001 | const struct RecordStoreMessage *rp_msg = sa->rsm; |
996 | unsigned int rd_count; | 1002 | unsigned int rd_count; |
@@ -1000,63 +1006,63 @@ continue_store_activity(struct StoreActivity *sa) | |||
1000 | const char *name_tmp; | 1006 | const char *name_tmp; |
1001 | const char *rd_ser; | 1007 | const char *rd_ser; |
1002 | 1008 | ||
1003 | rid = ntohl(rp_msg->gns_header.r_id); | 1009 | rid = ntohl (rp_msg->gns_header.r_id); |
1004 | name_len = ntohs(rp_msg->name_len); | 1010 | name_len = ntohs (rp_msg->name_len); |
1005 | rd_count = ntohs(rp_msg->rd_count); | 1011 | rd_count = ntohs (rp_msg->rd_count); |
1006 | rd_ser_len = ntohs(rp_msg->rd_len); | 1012 | rd_ser_len = ntohs (rp_msg->rd_len); |
1007 | name_tmp = (const char *)&rp_msg[1]; | 1013 | name_tmp = (const char *) &rp_msg[1]; |
1008 | rd_ser = &name_tmp[name_len]; | 1014 | rd_ser = &name_tmp[name_len]; |
1009 | { | 1015 | { |
1010 | struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)]; | 1016 | struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL (rd_count)]; |
1011 | 1017 | ||
1012 | /* We did this before, must succeed again */ | 1018 | /* We did this before, must succeed again */ |
1013 | GNUNET_assert( | 1019 | GNUNET_assert ( |
1014 | GNUNET_OK == | 1020 | GNUNET_OK == |
1015 | GNUNET_GNSRECORD_records_deserialize(rd_ser_len, rd_ser, rd_count, rd)); | 1021 | GNUNET_GNSRECORD_records_deserialize (rd_ser_len, rd_ser, rd_count, rd)); |
1016 | 1022 | ||
1017 | for (struct ZoneMonitor *zm = sa->zm_pos; NULL != zm; zm = sa->zm_pos) | 1023 | for (struct ZoneMonitor *zm = sa->zm_pos; NULL != zm; zm = sa->zm_pos) |
1024 | { | ||
1025 | if ((0 != GNUNET_memcmp (&rp_msg->private_key, &zm->zone)) && | ||
1026 | (0 != GNUNET_memcmp (&zm->zone, &zero))) | ||
1018 | { | 1027 | { |
1019 | if ((0 != GNUNET_memcmp(&rp_msg->private_key, &zm->zone)) && | 1028 | sa->zm_pos = zm->next; /* not interesting to this monitor */ |
1020 | (0 != GNUNET_memcmp(&zm->zone, &zero))) | 1029 | continue; |
1021 | { | 1030 | } |
1022 | sa->zm_pos = zm->next; /* not interesting to this monitor */ | 1031 | if (zm->limit == zm->iteration_cnt) |
1023 | continue; | 1032 | { |
1024 | } | 1033 | zm->sa_waiting = GNUNET_YES; |
1025 | if (zm->limit == zm->iteration_cnt) | 1034 | zm->sa_waiting_start = GNUNET_TIME_absolute_get (); |
1026 | { | 1035 | if (NULL != zm->sa_wait_warning) |
1027 | zm->sa_waiting = GNUNET_YES; | 1036 | GNUNET_SCHEDULER_cancel (zm->sa_wait_warning); |
1028 | zm->sa_waiting_start = GNUNET_TIME_absolute_get(); | 1037 | zm->sa_wait_warning = |
1029 | if (NULL != zm->sa_wait_warning) | 1038 | GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY, |
1030 | GNUNET_SCHEDULER_cancel(zm->sa_wait_warning); | 1039 | &warn_monitor_slow, |
1031 | zm->sa_wait_warning = | 1040 | zm); |
1032 | GNUNET_SCHEDULER_add_delayed(MONITOR_STALL_WARN_DELAY, | 1041 | return; /* blocked on zone monitor */ |
1033 | &warn_monitor_slow, | ||
1034 | zm); | ||
1035 | return; /* blocked on zone monitor */ | ||
1036 | } | ||
1037 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1038 | "Notifying monitor about changes under label `%s'\n", | ||
1039 | sa->conv_name); | ||
1040 | zm->limit--; | ||
1041 | send_lookup_response(zm->nc, | ||
1042 | 0, | ||
1043 | &rp_msg->private_key, | ||
1044 | sa->conv_name, | ||
1045 | rd_count, | ||
1046 | rd); | ||
1047 | sa->zm_pos = zm->next; | ||
1048 | } | 1042 | } |
1043 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1044 | "Notifying monitor about changes under label `%s'\n", | ||
1045 | sa->conv_name); | ||
1046 | zm->limit--; | ||
1047 | send_lookup_response (zm->nc, | ||
1048 | 0, | ||
1049 | &rp_msg->private_key, | ||
1050 | sa->conv_name, | ||
1051 | rd_count, | ||
1052 | rd); | ||
1053 | sa->zm_pos = zm->next; | ||
1054 | } | ||
1049 | /* great, done with the monitors, unpack (again) for refresh_block operation */ | 1055 | /* great, done with the monitors, unpack (again) for refresh_block operation */ |
1050 | refresh_block(sa->nc, | 1056 | refresh_block (sa->nc, |
1051 | NULL, | 1057 | NULL, |
1052 | rid, | 1058 | rid, |
1053 | &rp_msg->private_key, | 1059 | &rp_msg->private_key, |
1054 | sa->conv_name, | 1060 | sa->conv_name, |
1055 | rd_count, | 1061 | rd_count, |
1056 | rd); | 1062 | rd); |
1057 | } | 1063 | } |
1058 | GNUNET_SERVICE_client_continue(sa->nc->client); | 1064 | GNUNET_SERVICE_client_continue (sa->nc->client); |
1059 | free_store_activity(sa); | 1065 | free_store_activity (sa); |
1060 | } | 1066 | } |
1061 | 1067 | ||
1062 | 1068 | ||
@@ -1069,64 +1075,64 @@ continue_store_activity(struct StoreActivity *sa) | |||
1069 | * @param app_ctx the `struct NamestoreClient` of @a client | 1075 | * @param app_ctx the `struct NamestoreClient` of @a client |
1070 | */ | 1076 | */ |
1071 | static void | 1077 | static void |
1072 | client_disconnect_cb(void *cls, | 1078 | client_disconnect_cb (void *cls, |
1073 | struct GNUNET_SERVICE_Client *client, | 1079 | struct GNUNET_SERVICE_Client *client, |
1074 | void *app_ctx) | 1080 | void *app_ctx) |
1075 | { | 1081 | { |
1076 | struct NamestoreClient *nc = app_ctx; | 1082 | struct NamestoreClient *nc = app_ctx; |
1077 | struct ZoneIteration *no; | 1083 | struct ZoneIteration *no; |
1078 | struct CacheOperation *cop; | 1084 | struct CacheOperation *cop; |
1079 | 1085 | ||
1080 | (void)cls; | 1086 | (void) cls; |
1081 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client); | 1087 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client); |
1082 | for (struct ZoneMonitor *zm = monitor_head; NULL != zm; zm = zm->next) | 1088 | for (struct ZoneMonitor *zm = monitor_head; NULL != zm; zm = zm->next) |
1083 | { | 1089 | { |
1084 | struct StoreActivity *san; | 1090 | struct StoreActivity *san; |
1085 | 1091 | ||
1086 | if (nc != zm->nc) | 1092 | if (nc != zm->nc) |
1087 | continue; | 1093 | continue; |
1088 | GNUNET_CONTAINER_DLL_remove(monitor_head, monitor_tail, zm); | 1094 | GNUNET_CONTAINER_DLL_remove (monitor_head, monitor_tail, zm); |
1089 | if (NULL != zm->task) | 1095 | if (NULL != zm->task) |
1090 | { | 1096 | { |
1091 | GNUNET_SCHEDULER_cancel(zm->task); | 1097 | GNUNET_SCHEDULER_cancel (zm->task); |
1092 | zm->task = NULL; | 1098 | zm->task = NULL; |
1093 | } | ||
1094 | if (NULL != zm->sa_wait_warning) | ||
1095 | { | ||
1096 | GNUNET_SCHEDULER_cancel(zm->sa_wait_warning); | ||
1097 | zm->sa_wait_warning = NULL; | ||
1098 | } | ||
1099 | for (struct StoreActivity *sa = sa_head; NULL != sa; sa = san) | ||
1100 | { | ||
1101 | san = sa->next; | ||
1102 | if (zm == sa->zm_pos) | ||
1103 | { | ||
1104 | sa->zm_pos = zm->next; | ||
1105 | /* this may free sa */ | ||
1106 | continue_store_activity(sa); | ||
1107 | } | ||
1108 | } | ||
1109 | GNUNET_free(zm); | ||
1110 | break; | ||
1111 | } | 1099 | } |
1112 | for (struct StoreActivity *sa = sa_head; NULL != sa; sa = sa->next) | 1100 | if (NULL != zm->sa_wait_warning) |
1113 | { | 1101 | { |
1114 | if (sa->nc == nc) | 1102 | GNUNET_SCHEDULER_cancel (zm->sa_wait_warning); |
1115 | { | 1103 | zm->sa_wait_warning = NULL; |
1116 | /* this may free sa */ | ||
1117 | free_store_activity(sa); | ||
1118 | break; /* there can only be one per nc */ | ||
1119 | } | ||
1120 | } | 1104 | } |
1121 | while (NULL != (no = nc->op_head)) | 1105 | for (struct StoreActivity *sa = sa_head; NULL != sa; sa = san) |
1122 | { | 1106 | { |
1123 | GNUNET_CONTAINER_DLL_remove(nc->op_head, nc->op_tail, no); | 1107 | san = sa->next; |
1124 | GNUNET_free(no); | 1108 | if (zm == sa->zm_pos) |
1109 | { | ||
1110 | sa->zm_pos = zm->next; | ||
1111 | /* this may free sa */ | ||
1112 | continue_store_activity (sa); | ||
1113 | } | ||
1125 | } | 1114 | } |
1115 | GNUNET_free (zm); | ||
1116 | break; | ||
1117 | } | ||
1118 | for (struct StoreActivity *sa = sa_head; NULL != sa; sa = sa->next) | ||
1119 | { | ||
1120 | if (sa->nc == nc) | ||
1121 | { | ||
1122 | /* this may free sa */ | ||
1123 | free_store_activity (sa); | ||
1124 | break; /* there can only be one per nc */ | ||
1125 | } | ||
1126 | } | ||
1127 | while (NULL != (no = nc->op_head)) | ||
1128 | { | ||
1129 | GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, no); | ||
1130 | GNUNET_free (no); | ||
1131 | } | ||
1126 | for (cop = cop_head; NULL != cop; cop = cop->next) | 1132 | for (cop = cop_head; NULL != cop; cop = cop->next) |
1127 | if (nc == cop->nc) | 1133 | if (nc == cop->nc) |
1128 | cop->nc = NULL; | 1134 | cop->nc = NULL; |
1129 | GNUNET_free(nc); | 1135 | GNUNET_free (nc); |
1130 | } | 1136 | } |
1131 | 1137 | ||
1132 | 1138 | ||
@@ -1139,15 +1145,15 @@ client_disconnect_cb(void *cls, | |||
1139 | * @return internal namestore client structure for this client | 1145 | * @return internal namestore client structure for this client |
1140 | */ | 1146 | */ |
1141 | static void * | 1147 | static void * |
1142 | client_connect_cb(void *cls, | 1148 | client_connect_cb (void *cls, |
1143 | struct GNUNET_SERVICE_Client *client, | 1149 | struct GNUNET_SERVICE_Client *client, |
1144 | struct GNUNET_MQ_Handle *mq) | 1150 | struct GNUNET_MQ_Handle *mq) |
1145 | { | 1151 | { |
1146 | struct NamestoreClient *nc; | 1152 | struct NamestoreClient *nc; |
1147 | 1153 | ||
1148 | (void)cls; | 1154 | (void) cls; |
1149 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", client); | 1155 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", client); |
1150 | nc = GNUNET_new(struct NamestoreClient); | 1156 | nc = GNUNET_new (struct NamestoreClient); |
1151 | nc->client = client; | 1157 | nc->client = client; |
1152 | nc->mq = mq; | 1158 | nc->mq = mq; |
1153 | return nc; | 1159 | return nc; |
@@ -1157,7 +1163,8 @@ client_connect_cb(void *cls, | |||
1157 | /** | 1163 | /** |
1158 | * Closure for #lookup_it(). | 1164 | * Closure for #lookup_it(). |
1159 | */ | 1165 | */ |
1160 | struct RecordLookupContext { | 1166 | struct RecordLookupContext |
1167 | { | ||
1161 | /** | 1168 | /** |
1162 | * FIXME. | 1169 | * FIXME. |
1163 | */ | 1170 | */ |
@@ -1203,93 +1210,93 @@ struct RecordLookupContext { | |||
1203 | * @param rd array of records with data to store | 1210 | * @param rd array of records with data to store |
1204 | */ | 1211 | */ |
1205 | static void | 1212 | static void |
1206 | lookup_it(void *cls, | 1213 | lookup_it (void *cls, |
1207 | uint64_t seq, | 1214 | uint64_t seq, |
1208 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key, | 1215 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key, |
1209 | const char *label, | 1216 | const char *label, |
1210 | unsigned int rd_count, | 1217 | unsigned int rd_count, |
1211 | const struct GNUNET_GNSRECORD_Data *rd) | 1218 | const struct GNUNET_GNSRECORD_Data *rd) |
1212 | { | 1219 | { |
1213 | struct RecordLookupContext *rlc = cls; | 1220 | struct RecordLookupContext *rlc = cls; |
1214 | 1221 | ||
1215 | (void)private_key; | 1222 | (void) private_key; |
1216 | GNUNET_assert(0 != seq); | 1223 | GNUNET_assert (0 != seq); |
1217 | if (0 != strcmp(label, rlc->label)) | 1224 | if (0 != strcmp (label, rlc->label)) |
1218 | return; | 1225 | return; |
1219 | rlc->found = GNUNET_YES; | 1226 | rlc->found = GNUNET_YES; |
1220 | if (0 == rd_count) | 1227 | if (0 == rd_count) |
1228 | { | ||
1229 | rlc->rd_ser_len = 0; | ||
1230 | rlc->res_rd_count = 0; | ||
1231 | rlc->res_rd = NULL; | ||
1232 | return; | ||
1233 | } | ||
1234 | if ((NULL != rlc->nick) && (0 != strcmp (label, GNUNET_GNS_EMPTY_LABEL_AT))) | ||
1235 | { | ||
1236 | /* Merge */ | ||
1237 | struct GNUNET_GNSRECORD_Data *rd_res; | ||
1238 | unsigned int rdc_res; | ||
1239 | |||
1240 | rd_res = NULL; | ||
1241 | rdc_res = 0; | ||
1242 | rlc->nick->flags = (rlc->nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) | ||
1243 | ^ GNUNET_GNSRECORD_RF_PRIVATE; | ||
1244 | merge_with_nick_records (rlc->nick, rd_count, rd, &rdc_res, &rd_res); | ||
1245 | rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rdc_res, rd_res); | ||
1246 | if (rlc->rd_ser_len < 0) | ||
1221 | { | 1247 | { |
1248 | GNUNET_break (0); | ||
1249 | GNUNET_free (rd_res); | ||
1250 | rlc->found = GNUNET_NO; | ||
1222 | rlc->rd_ser_len = 0; | 1251 | rlc->rd_ser_len = 0; |
1223 | rlc->res_rd_count = 0; | ||
1224 | rlc->res_rd = NULL; | ||
1225 | return; | 1252 | return; |
1226 | } | 1253 | } |
1227 | if ((NULL != rlc->nick) && (0 != strcmp(label, GNUNET_GNS_EMPTY_LABEL_AT))) | 1254 | rlc->res_rd_count = rdc_res; |
1255 | rlc->res_rd = GNUNET_malloc (rlc->rd_ser_len); | ||
1256 | if (rlc->rd_ser_len != GNUNET_GNSRECORD_records_serialize (rdc_res, | ||
1257 | rd_res, | ||
1258 | rlc->rd_ser_len, | ||
1259 | rlc->res_rd)) | ||
1228 | { | 1260 | { |
1229 | /* Merge */ | 1261 | GNUNET_break (0); |
1230 | struct GNUNET_GNSRECORD_Data *rd_res; | 1262 | GNUNET_free (rlc->res_rd); |
1231 | unsigned int rdc_res; | 1263 | rlc->res_rd = NULL; |
1232 | 1264 | rlc->res_rd_count = 0; | |
1233 | rd_res = NULL; | 1265 | rlc->rd_ser_len = 0; |
1234 | rdc_res = 0; | 1266 | GNUNET_free (rd_res); |
1235 | rlc->nick->flags = (rlc->nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ | 1267 | rlc->found = GNUNET_NO; |
1236 | GNUNET_GNSRECORD_RF_PRIVATE; | 1268 | return; |
1237 | merge_with_nick_records(rlc->nick, rd_count, rd, &rdc_res, &rd_res); | ||
1238 | rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size(rdc_res, rd_res); | ||
1239 | if (rlc->rd_ser_len < 0) | ||
1240 | { | ||
1241 | GNUNET_break(0); | ||
1242 | GNUNET_free(rd_res); | ||
1243 | rlc->found = GNUNET_NO; | ||
1244 | rlc->rd_ser_len = 0; | ||
1245 | return; | ||
1246 | } | ||
1247 | rlc->res_rd_count = rdc_res; | ||
1248 | rlc->res_rd = GNUNET_malloc(rlc->rd_ser_len); | ||
1249 | if (rlc->rd_ser_len != GNUNET_GNSRECORD_records_serialize(rdc_res, | ||
1250 | rd_res, | ||
1251 | rlc->rd_ser_len, | ||
1252 | rlc->res_rd)) | ||
1253 | { | ||
1254 | GNUNET_break(0); | ||
1255 | GNUNET_free(rlc->res_rd); | ||
1256 | rlc->res_rd = NULL; | ||
1257 | rlc->res_rd_count = 0; | ||
1258 | rlc->rd_ser_len = 0; | ||
1259 | GNUNET_free(rd_res); | ||
1260 | rlc->found = GNUNET_NO; | ||
1261 | return; | ||
1262 | } | ||
1263 | GNUNET_free(rd_res); | ||
1264 | GNUNET_free(rlc->nick); | ||
1265 | rlc->nick = NULL; | ||
1266 | } | 1269 | } |
1270 | GNUNET_free (rd_res); | ||
1271 | GNUNET_free (rlc->nick); | ||
1272 | rlc->nick = NULL; | ||
1273 | } | ||
1267 | else | 1274 | else |
1275 | { | ||
1276 | rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count, rd); | ||
1277 | if (rlc->rd_ser_len < 0) | ||
1268 | { | 1278 | { |
1269 | rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size(rd_count, rd); | 1279 | GNUNET_break (0); |
1270 | if (rlc->rd_ser_len < 0) | 1280 | rlc->found = GNUNET_NO; |
1271 | { | 1281 | rlc->rd_ser_len = 0; |
1272 | GNUNET_break(0); | 1282 | return; |
1273 | rlc->found = GNUNET_NO; | ||
1274 | rlc->rd_ser_len = 0; | ||
1275 | return; | ||
1276 | } | ||
1277 | rlc->res_rd_count = rd_count; | ||
1278 | rlc->res_rd = GNUNET_malloc(rlc->rd_ser_len); | ||
1279 | if (rlc->rd_ser_len != GNUNET_GNSRECORD_records_serialize(rd_count, | ||
1280 | rd, | ||
1281 | rlc->rd_ser_len, | ||
1282 | rlc->res_rd)) | ||
1283 | { | ||
1284 | GNUNET_break(0); | ||
1285 | GNUNET_free(rlc->res_rd); | ||
1286 | rlc->res_rd = NULL; | ||
1287 | rlc->res_rd_count = 0; | ||
1288 | rlc->rd_ser_len = 0; | ||
1289 | rlc->found = GNUNET_NO; | ||
1290 | return; | ||
1291 | } | ||
1292 | } | 1283 | } |
1284 | rlc->res_rd_count = rd_count; | ||
1285 | rlc->res_rd = GNUNET_malloc (rlc->rd_ser_len); | ||
1286 | if (rlc->rd_ser_len != GNUNET_GNSRECORD_records_serialize (rd_count, | ||
1287 | rd, | ||
1288 | rlc->rd_ser_len, | ||
1289 | rlc->res_rd)) | ||
1290 | { | ||
1291 | GNUNET_break (0); | ||
1292 | GNUNET_free (rlc->res_rd); | ||
1293 | rlc->res_rd = NULL; | ||
1294 | rlc->res_rd_count = 0; | ||
1295 | rlc->rd_ser_len = 0; | ||
1296 | rlc->found = GNUNET_NO; | ||
1297 | return; | ||
1298 | } | ||
1299 | } | ||
1293 | } | 1300 | } |
1294 | 1301 | ||
1295 | 1302 | ||
@@ -1301,20 +1308,20 @@ lookup_it(void *cls, | |||
1301 | * @return #GNUNET_OK if @a ll_msg is well-formed | 1308 | * @return #GNUNET_OK if @a ll_msg is well-formed |
1302 | */ | 1309 | */ |
1303 | static int | 1310 | static int |
1304 | check_record_lookup(void *cls, const struct LabelLookupMessage *ll_msg) | 1311 | check_record_lookup (void *cls, const struct LabelLookupMessage *ll_msg) |
1305 | { | 1312 | { |
1306 | uint32_t name_len; | 1313 | uint32_t name_len; |
1307 | size_t src_size; | 1314 | size_t src_size; |
1308 | 1315 | ||
1309 | (void)cls; | 1316 | (void) cls; |
1310 | name_len = ntohl(ll_msg->label_len); | 1317 | name_len = ntohl (ll_msg->label_len); |
1311 | src_size = ntohs(ll_msg->gns_header.header.size); | 1318 | src_size = ntohs (ll_msg->gns_header.header.size); |
1312 | if (name_len != src_size - sizeof(struct LabelLookupMessage)) | 1319 | if (name_len != src_size - sizeof(struct LabelLookupMessage)) |
1313 | { | 1320 | { |
1314 | GNUNET_break(0); | 1321 | GNUNET_break (0); |
1315 | return GNUNET_SYSERR; | 1322 | return GNUNET_SYSERR; |
1316 | } | 1323 | } |
1317 | GNUNET_MQ_check_zero_termination(ll_msg); | 1324 | GNUNET_MQ_check_zero_termination (ll_msg); |
1318 | return GNUNET_OK; | 1325 | return GNUNET_OK; |
1319 | } | 1326 | } |
1320 | 1327 | ||
@@ -1326,7 +1333,7 @@ check_record_lookup(void *cls, const struct LabelLookupMessage *ll_msg) | |||
1326 | * @param ll_msg message of type `struct LabelLookupMessage` | 1333 | * @param ll_msg message of type `struct LabelLookupMessage` |
1327 | */ | 1334 | */ |
1328 | static void | 1335 | static void |
1329 | handle_record_lookup(void *cls, const struct LabelLookupMessage *ll_msg) | 1336 | handle_record_lookup (void *cls, const struct LabelLookupMessage *ll_msg) |
1330 | { | 1337 | { |
1331 | struct NamestoreClient *nc = cls; | 1338 | struct NamestoreClient *nc = cls; |
1332 | struct GNUNET_MQ_Envelope *env; | 1339 | struct GNUNET_MQ_Envelope *env; |
@@ -1338,52 +1345,52 @@ handle_record_lookup(void *cls, const struct LabelLookupMessage *ll_msg) | |||
1338 | uint32_t name_len; | 1345 | uint32_t name_len; |
1339 | int res; | 1346 | int res; |
1340 | 1347 | ||
1341 | name_len = ntohl(ll_msg->label_len); | 1348 | name_len = ntohl (ll_msg->label_len); |
1342 | name_tmp = (const char *)&ll_msg[1]; | 1349 | name_tmp = (const char *) &ll_msg[1]; |
1343 | GNUNET_SERVICE_client_continue(nc->client); | 1350 | GNUNET_SERVICE_client_continue (nc->client); |
1344 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1351 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1345 | "Received NAMESTORE_RECORD_LOOKUP message for name `%s'\n", | 1352 | "Received NAMESTORE_RECORD_LOOKUP message for name `%s'\n", |
1346 | name_tmp); | 1353 | name_tmp); |
1347 | 1354 | ||
1348 | conv_name = GNUNET_GNSRECORD_string_to_lowercase(name_tmp); | 1355 | conv_name = GNUNET_GNSRECORD_string_to_lowercase (name_tmp); |
1349 | if (NULL == conv_name) | 1356 | if (NULL == conv_name) |
1350 | { | 1357 | { |
1351 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1358 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1352 | "Error converting name `%s'\n", | 1359 | "Error converting name `%s'\n", |
1353 | name_tmp); | 1360 | name_tmp); |
1354 | GNUNET_SERVICE_client_drop(nc->client); | 1361 | GNUNET_SERVICE_client_drop (nc->client); |
1355 | return; | 1362 | return; |
1356 | } | 1363 | } |
1357 | rlc.label = conv_name; | 1364 | rlc.label = conv_name; |
1358 | rlc.found = GNUNET_NO; | 1365 | rlc.found = GNUNET_NO; |
1359 | rlc.res_rd_count = 0; | 1366 | rlc.res_rd_count = 0; |
1360 | rlc.res_rd = NULL; | 1367 | rlc.res_rd = NULL; |
1361 | rlc.rd_ser_len = 0; | 1368 | rlc.rd_ser_len = 0; |
1362 | rlc.nick = get_nick_record(&ll_msg->zone); | 1369 | rlc.nick = get_nick_record (&ll_msg->zone); |
1363 | res = GSN_database->lookup_records(GSN_database->cls, | 1370 | res = GSN_database->lookup_records (GSN_database->cls, |
1364 | &ll_msg->zone, | 1371 | &ll_msg->zone, |
1365 | conv_name, | 1372 | conv_name, |
1366 | &lookup_it, | 1373 | &lookup_it, |
1367 | &rlc); | 1374 | &rlc); |
1368 | GNUNET_free(conv_name); | 1375 | GNUNET_free (conv_name); |
1369 | env = | 1376 | env = |
1370 | GNUNET_MQ_msg_extra(llr_msg, | 1377 | GNUNET_MQ_msg_extra (llr_msg, |
1371 | name_len + rlc.rd_ser_len, | 1378 | name_len + rlc.rd_ser_len, |
1372 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE); | 1379 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE); |
1373 | llr_msg->gns_header.r_id = ll_msg->gns_header.r_id; | 1380 | llr_msg->gns_header.r_id = ll_msg->gns_header.r_id; |
1374 | llr_msg->private_key = ll_msg->zone; | 1381 | llr_msg->private_key = ll_msg->zone; |
1375 | llr_msg->name_len = htons(name_len); | 1382 | llr_msg->name_len = htons (name_len); |
1376 | llr_msg->rd_count = htons(rlc.res_rd_count); | 1383 | llr_msg->rd_count = htons (rlc.res_rd_count); |
1377 | llr_msg->rd_len = htons(rlc.rd_ser_len); | 1384 | llr_msg->rd_len = htons (rlc.rd_ser_len); |
1378 | res_name = (char *)&llr_msg[1]; | 1385 | res_name = (char *) &llr_msg[1]; |
1379 | if ((GNUNET_YES == rlc.found) && (GNUNET_OK == res)) | 1386 | if ((GNUNET_YES == rlc.found) && (GNUNET_OK == res)) |
1380 | llr_msg->found = ntohs(GNUNET_YES); | 1387 | llr_msg->found = ntohs (GNUNET_YES); |
1381 | else | 1388 | else |
1382 | llr_msg->found = ntohs(GNUNET_NO); | 1389 | llr_msg->found = ntohs (GNUNET_NO); |
1383 | GNUNET_memcpy(&llr_msg[1], name_tmp, name_len); | 1390 | GNUNET_memcpy (&llr_msg[1], name_tmp, name_len); |
1384 | GNUNET_memcpy(&res_name[name_len], rlc.res_rd, rlc.rd_ser_len); | 1391 | GNUNET_memcpy (&res_name[name_len], rlc.res_rd, rlc.rd_ser_len); |
1385 | GNUNET_MQ_send(nc->mq, env); | 1392 | GNUNET_MQ_send (nc->mq, env); |
1386 | GNUNET_free_non_null(rlc.res_rd); | 1393 | GNUNET_free_non_null (rlc.res_rd); |
1387 | } | 1394 | } |
1388 | 1395 | ||
1389 | 1396 | ||
@@ -1395,7 +1402,7 @@ handle_record_lookup(void *cls, const struct LabelLookupMessage *ll_msg) | |||
1395 | * @return #GNUNET_OK if @a rp_msg is well-formed | 1402 | * @return #GNUNET_OK if @a rp_msg is well-formed |
1396 | */ | 1403 | */ |
1397 | static int | 1404 | static int |
1398 | check_record_store(void *cls, const struct RecordStoreMessage *rp_msg) | 1405 | check_record_store (void *cls, const struct RecordStoreMessage *rp_msg) |
1399 | { | 1406 | { |
1400 | size_t name_len; | 1407 | size_t name_len; |
1401 | size_t msg_size; | 1408 | size_t msg_size; |
@@ -1403,27 +1410,27 @@ check_record_store(void *cls, const struct RecordStoreMessage *rp_msg) | |||
1403 | size_t rd_ser_len; | 1410 | size_t rd_ser_len; |
1404 | const char *name_tmp; | 1411 | const char *name_tmp; |
1405 | 1412 | ||
1406 | (void)cls; | 1413 | (void) cls; |
1407 | name_len = ntohs(rp_msg->name_len); | 1414 | name_len = ntohs (rp_msg->name_len); |
1408 | msg_size = ntohs(rp_msg->gns_header.header.size); | 1415 | msg_size = ntohs (rp_msg->gns_header.header.size); |
1409 | rd_ser_len = ntohs(rp_msg->rd_len); | 1416 | rd_ser_len = ntohs (rp_msg->rd_len); |
1410 | msg_size_exp = sizeof(struct RecordStoreMessage) + name_len + rd_ser_len; | 1417 | msg_size_exp = sizeof(struct RecordStoreMessage) + name_len + rd_ser_len; |
1411 | if (msg_size != msg_size_exp) | 1418 | if (msg_size != msg_size_exp) |
1412 | { | 1419 | { |
1413 | GNUNET_break(0); | 1420 | GNUNET_break (0); |
1414 | return GNUNET_SYSERR; | 1421 | return GNUNET_SYSERR; |
1415 | } | 1422 | } |
1416 | if ((0 == name_len) || (name_len > MAX_NAME_LEN)) | 1423 | if ((0 == name_len) || (name_len > MAX_NAME_LEN)) |
1417 | { | 1424 | { |
1418 | GNUNET_break(0); | 1425 | GNUNET_break (0); |
1419 | return GNUNET_SYSERR; | 1426 | return GNUNET_SYSERR; |
1420 | } | 1427 | } |
1421 | name_tmp = (const char *)&rp_msg[1]; | 1428 | name_tmp = (const char *) &rp_msg[1]; |
1422 | if ('\0' != name_tmp[name_len - 1]) | 1429 | if ('\0' != name_tmp[name_len - 1]) |
1423 | { | 1430 | { |
1424 | GNUNET_break(0); | 1431 | GNUNET_break (0); |
1425 | return GNUNET_SYSERR; | 1432 | return GNUNET_SYSERR; |
1426 | } | 1433 | } |
1427 | return GNUNET_OK; | 1434 | return GNUNET_OK; |
1428 | } | 1435 | } |
1429 | 1436 | ||
@@ -1435,7 +1442,7 @@ check_record_store(void *cls, const struct RecordStoreMessage *rp_msg) | |||
1435 | * @param rp_msg message of type `struct RecordStoreMessage` | 1442 | * @param rp_msg message of type `struct RecordStoreMessage` |
1436 | */ | 1443 | */ |
1437 | static void | 1444 | static void |
1438 | handle_record_store(void *cls, const struct RecordStoreMessage *rp_msg) | 1445 | handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg) |
1439 | { | 1446 | { |
1440 | struct NamestoreClient *nc = cls; | 1447 | struct NamestoreClient *nc = cls; |
1441 | size_t name_len; | 1448 | size_t name_len; |
@@ -1448,112 +1455,112 @@ handle_record_store(void *cls, const struct RecordStoreMessage *rp_msg) | |||
1448 | int res; | 1455 | int res; |
1449 | struct StoreActivity *sa; | 1456 | struct StoreActivity *sa; |
1450 | 1457 | ||
1451 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1458 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1452 | "Received NAMESTORE_RECORD_STORE message\n"); | 1459 | "Received NAMESTORE_RECORD_STORE message\n"); |
1453 | rid = ntohl(rp_msg->gns_header.r_id); | 1460 | rid = ntohl (rp_msg->gns_header.r_id); |
1454 | name_len = ntohs(rp_msg->name_len); | 1461 | name_len = ntohs (rp_msg->name_len); |
1455 | rd_count = ntohs(rp_msg->rd_count); | 1462 | rd_count = ntohs (rp_msg->rd_count); |
1456 | rd_ser_len = ntohs(rp_msg->rd_len); | 1463 | rd_ser_len = ntohs (rp_msg->rd_len); |
1457 | GNUNET_break(0 == ntohs(rp_msg->reserved)); | 1464 | GNUNET_break (0 == ntohs (rp_msg->reserved)); |
1458 | name_tmp = (const char *)&rp_msg[1]; | 1465 | name_tmp = (const char *) &rp_msg[1]; |
1459 | rd_ser = &name_tmp[name_len]; | 1466 | rd_ser = &name_tmp[name_len]; |
1460 | { | 1467 | { |
1461 | struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)]; | 1468 | struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL (rd_count)]; |
1462 | 1469 | ||
1463 | if (GNUNET_OK != | 1470 | if (GNUNET_OK != |
1464 | GNUNET_GNSRECORD_records_deserialize(rd_ser_len, rd_ser, rd_count, rd)) | 1471 | GNUNET_GNSRECORD_records_deserialize (rd_ser_len, rd_ser, rd_count, rd)) |
1465 | { | 1472 | { |
1466 | GNUNET_break(0); | 1473 | GNUNET_break (0); |
1467 | GNUNET_SERVICE_client_drop(nc->client); | 1474 | GNUNET_SERVICE_client_drop (nc->client); |
1468 | return; | 1475 | return; |
1469 | } | 1476 | } |
1470 | 1477 | ||
1471 | /* Extracting and converting private key */ | 1478 | /* Extracting and converting private key */ |
1472 | conv_name = GNUNET_GNSRECORD_string_to_lowercase(name_tmp); | 1479 | conv_name = GNUNET_GNSRECORD_string_to_lowercase (name_tmp); |
1473 | if (NULL == conv_name) | 1480 | if (NULL == conv_name) |
1474 | { | 1481 | { |
1475 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1482 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1476 | "Error converting name `%s'\n", | 1483 | "Error converting name `%s'\n", |
1477 | name_tmp); | 1484 | name_tmp); |
1478 | GNUNET_SERVICE_client_drop(nc->client); | 1485 | GNUNET_SERVICE_client_drop (nc->client); |
1479 | return; | 1486 | return; |
1480 | } | 1487 | } |
1481 | GNUNET_STATISTICS_update(statistics, | 1488 | GNUNET_STATISTICS_update (statistics, |
1482 | "Well-formed store requests received", | 1489 | "Well-formed store requests received", |
1483 | 1, | 1490 | 1, |
1484 | GNUNET_NO); | 1491 | GNUNET_NO); |
1485 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1492 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1486 | "Creating %u records for name `%s'\n", | 1493 | "Creating %u records for name `%s'\n", |
1487 | (unsigned int)rd_count, | 1494 | (unsigned int) rd_count, |
1488 | conv_name); | 1495 | conv_name); |
1489 | if ((0 == rd_count) && | 1496 | if ((0 == rd_count) && |
1490 | (GNUNET_NO == GSN_database->lookup_records(GSN_database->cls, | 1497 | (GNUNET_NO == GSN_database->lookup_records (GSN_database->cls, |
1491 | &rp_msg->private_key, | 1498 | &rp_msg->private_key, |
1492 | conv_name, | 1499 | conv_name, |
1493 | NULL, | 1500 | NULL, |
1494 | 0))) | 1501 | 0))) |
1502 | { | ||
1503 | /* This name does not exist, so cannot be removed */ | ||
1504 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1505 | "Name `%s' does not exist, no deletion required\n", | ||
1506 | conv_name); | ||
1507 | res = GNUNET_NO; | ||
1508 | } | ||
1509 | else | ||
1510 | { | ||
1511 | /* remove "NICK" records, unless this is for the | ||
1512 | #GNUNET_GNS_EMPTY_LABEL_AT label */ | ||
1513 | struct GNUNET_GNSRECORD_Data rd_clean[GNUNET_NZL (rd_count)]; | ||
1514 | unsigned int rd_clean_off; | ||
1515 | int have_nick; | ||
1516 | |||
1517 | rd_clean_off = 0; | ||
1518 | have_nick = GNUNET_NO; | ||
1519 | for (unsigned int i = 0; i < rd_count; i++) | ||
1495 | { | 1520 | { |
1496 | /* This name does not exist, so cannot be removed */ | 1521 | rd_clean[rd_clean_off] = rd[i]; |
1497 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1522 | if ((0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, conv_name)) || |
1498 | "Name `%s' does not exist, no deletion required\n", | 1523 | (GNUNET_GNSRECORD_TYPE_NICK != rd[i].record_type)) |
1499 | conv_name); | 1524 | rd_clean_off++; |
1500 | res = GNUNET_NO; | 1525 | |
1526 | if ((0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, conv_name)) && | ||
1527 | (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type)) | ||
1528 | { | ||
1529 | cache_nick (&rp_msg->private_key, &rd[i]); | ||
1530 | have_nick = GNUNET_YES; | ||
1531 | } | ||
1501 | } | 1532 | } |
1502 | else | 1533 | if ((0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, conv_name)) && |
1534 | (GNUNET_NO == have_nick)) | ||
1503 | { | 1535 | { |
1504 | /* remove "NICK" records, unless this is for the | 1536 | /* remove nick record from cache, in case we have one there */ |
1505 | #GNUNET_GNS_EMPTY_LABEL_AT label */ | 1537 | cache_nick (&rp_msg->private_key, NULL); |
1506 | struct GNUNET_GNSRECORD_Data rd_clean[GNUNET_NZL(rd_count)]; | ||
1507 | unsigned int rd_clean_off; | ||
1508 | int have_nick; | ||
1509 | |||
1510 | rd_clean_off = 0; | ||
1511 | have_nick = GNUNET_NO; | ||
1512 | for (unsigned int i = 0; i < rd_count; i++) | ||
1513 | { | ||
1514 | rd_clean[rd_clean_off] = rd[i]; | ||
1515 | if ((0 == strcmp(GNUNET_GNS_EMPTY_LABEL_AT, conv_name)) || | ||
1516 | (GNUNET_GNSRECORD_TYPE_NICK != rd[i].record_type)) | ||
1517 | rd_clean_off++; | ||
1518 | |||
1519 | if ((0 == strcmp(GNUNET_GNS_EMPTY_LABEL_AT, conv_name)) && | ||
1520 | (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type)) | ||
1521 | { | ||
1522 | cache_nick(&rp_msg->private_key, &rd[i]); | ||
1523 | have_nick = GNUNET_YES; | ||
1524 | } | ||
1525 | } | ||
1526 | if ((0 == strcmp(GNUNET_GNS_EMPTY_LABEL_AT, conv_name)) && | ||
1527 | (GNUNET_NO == have_nick)) | ||
1528 | { | ||
1529 | /* remove nick record from cache, in case we have one there */ | ||
1530 | cache_nick(&rp_msg->private_key, NULL); | ||
1531 | } | ||
1532 | res = GSN_database->store_records(GSN_database->cls, | ||
1533 | &rp_msg->private_key, | ||
1534 | conv_name, | ||
1535 | rd_clean_off, | ||
1536 | rd_clean); | ||
1537 | } | 1538 | } |
1539 | res = GSN_database->store_records (GSN_database->cls, | ||
1540 | &rp_msg->private_key, | ||
1541 | conv_name, | ||
1542 | rd_clean_off, | ||
1543 | rd_clean); | ||
1544 | } | ||
1538 | 1545 | ||
1539 | if (GNUNET_OK != res) | 1546 | if (GNUNET_OK != res) |
1540 | { | 1547 | { |
1541 | /* store not successful, not need to tell monitors */ | 1548 | /* store not successful, not need to tell monitors */ |
1542 | send_store_response(nc, res, rid); | 1549 | send_store_response (nc, res, rid); |
1543 | GNUNET_SERVICE_client_continue(nc->client); | 1550 | GNUNET_SERVICE_client_continue (nc->client); |
1544 | GNUNET_free(conv_name); | 1551 | GNUNET_free (conv_name); |
1545 | return; | 1552 | return; |
1546 | } | 1553 | } |
1547 | 1554 | ||
1548 | sa = GNUNET_malloc(sizeof(struct StoreActivity) + | 1555 | sa = GNUNET_malloc (sizeof(struct StoreActivity) |
1549 | ntohs(rp_msg->gns_header.header.size)); | 1556 | + ntohs (rp_msg->gns_header.header.size)); |
1550 | GNUNET_CONTAINER_DLL_insert(sa_head, sa_tail, sa); | 1557 | GNUNET_CONTAINER_DLL_insert (sa_head, sa_tail, sa); |
1551 | sa->nc = nc; | 1558 | sa->nc = nc; |
1552 | sa->rsm = (const struct RecordStoreMessage *)&sa[1]; | 1559 | sa->rsm = (const struct RecordStoreMessage *) &sa[1]; |
1553 | GNUNET_memcpy(&sa[1], rp_msg, ntohs(rp_msg->gns_header.header.size)); | 1560 | GNUNET_memcpy (&sa[1], rp_msg, ntohs (rp_msg->gns_header.header.size)); |
1554 | sa->zm_pos = monitor_head; | 1561 | sa->zm_pos = monitor_head; |
1555 | sa->conv_name = conv_name; | 1562 | sa->conv_name = conv_name; |
1556 | continue_store_activity(sa); | 1563 | continue_store_activity (sa); |
1557 | } | 1564 | } |
1558 | } | 1565 | } |
1559 | 1566 | ||
@@ -1562,7 +1569,8 @@ handle_record_store(void *cls, const struct RecordStoreMessage *rp_msg) | |||
1562 | * Context for record remove operations passed from #handle_zone_to_name to | 1569 | * Context for record remove operations passed from #handle_zone_to_name to |
1563 | * #handle_zone_to_name_it as closure | 1570 | * #handle_zone_to_name_it as closure |
1564 | */ | 1571 | */ |
1565 | struct ZoneToNameCtx { | 1572 | struct ZoneToNameCtx |
1573 | { | ||
1566 | /** | 1574 | /** |
1567 | * Namestore client | 1575 | * Namestore client |
1568 | */ | 1576 | */ |
@@ -1593,12 +1601,12 @@ struct ZoneToNameCtx { | |||
1593 | * @param rd record data | 1601 | * @param rd record data |
1594 | */ | 1602 | */ |
1595 | static void | 1603 | static void |
1596 | handle_zone_to_name_it(void *cls, | 1604 | handle_zone_to_name_it (void *cls, |
1597 | uint64_t seq, | 1605 | uint64_t seq, |
1598 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 1606 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, |
1599 | const char *name, | 1607 | const char *name, |
1600 | unsigned int rd_count, | 1608 | unsigned int rd_count, |
1601 | const struct GNUNET_GNSRECORD_Data *rd) | 1609 | const struct GNUNET_GNSRECORD_Data *rd) |
1602 | { | 1610 | { |
1603 | struct ZoneToNameCtx *ztn_ctx = cls; | 1611 | struct ZoneToNameCtx *ztn_ctx = cls; |
1604 | struct GNUNET_MQ_Envelope *env; | 1612 | struct GNUNET_MQ_Envelope *env; |
@@ -1610,45 +1618,45 @@ handle_zone_to_name_it(void *cls, | |||
1610 | char *name_tmp; | 1618 | char *name_tmp; |
1611 | char *rd_tmp; | 1619 | char *rd_tmp; |
1612 | 1620 | ||
1613 | GNUNET_assert(0 != seq); | 1621 | GNUNET_assert (0 != seq); |
1614 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1622 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1615 | "Found result for zone-to-name lookup: `%s'\n", | 1623 | "Found result for zone-to-name lookup: `%s'\n", |
1616 | name); | 1624 | name); |
1617 | res = GNUNET_YES; | 1625 | res = GNUNET_YES; |
1618 | name_len = (NULL == name) ? 0 : strlen(name) + 1; | 1626 | name_len = (NULL == name) ? 0 : strlen (name) + 1; |
1619 | rd_ser_len = GNUNET_GNSRECORD_records_get_size(rd_count, rd); | 1627 | rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count, rd); |
1620 | if (rd_ser_len < 0) | 1628 | if (rd_ser_len < 0) |
1621 | { | 1629 | { |
1622 | GNUNET_break(0); | 1630 | GNUNET_break (0); |
1623 | ztn_ctx->success = GNUNET_SYSERR; | 1631 | ztn_ctx->success = GNUNET_SYSERR; |
1624 | return; | 1632 | return; |
1625 | } | 1633 | } |
1626 | msg_size = sizeof(struct ZoneToNameResponseMessage) + name_len + rd_ser_len; | 1634 | msg_size = sizeof(struct ZoneToNameResponseMessage) + name_len + rd_ser_len; |
1627 | if (msg_size >= GNUNET_MAX_MESSAGE_SIZE) | 1635 | if (msg_size >= GNUNET_MAX_MESSAGE_SIZE) |
1628 | { | 1636 | { |
1629 | GNUNET_break(0); | 1637 | GNUNET_break (0); |
1630 | ztn_ctx->success = GNUNET_SYSERR; | 1638 | ztn_ctx->success = GNUNET_SYSERR; |
1631 | return; | 1639 | return; |
1632 | } | 1640 | } |
1633 | env = | 1641 | env = |
1634 | GNUNET_MQ_msg_extra(ztnr_msg, | 1642 | GNUNET_MQ_msg_extra (ztnr_msg, |
1635 | name_len + rd_ser_len, | 1643 | name_len + rd_ser_len, |
1636 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE); | 1644 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE); |
1637 | ztnr_msg->gns_header.header.size = htons(msg_size); | 1645 | ztnr_msg->gns_header.header.size = htons (msg_size); |
1638 | ztnr_msg->gns_header.r_id = htonl(ztn_ctx->rid); | 1646 | ztnr_msg->gns_header.r_id = htonl (ztn_ctx->rid); |
1639 | ztnr_msg->res = htons(res); | 1647 | ztnr_msg->res = htons (res); |
1640 | ztnr_msg->rd_len = htons(rd_ser_len); | 1648 | ztnr_msg->rd_len = htons (rd_ser_len); |
1641 | ztnr_msg->rd_count = htons(rd_count); | 1649 | ztnr_msg->rd_count = htons (rd_count); |
1642 | ztnr_msg->name_len = htons(name_len); | 1650 | ztnr_msg->name_len = htons (name_len); |
1643 | ztnr_msg->zone = *zone_key; | 1651 | ztnr_msg->zone = *zone_key; |
1644 | name_tmp = (char *)&ztnr_msg[1]; | 1652 | name_tmp = (char *) &ztnr_msg[1]; |
1645 | GNUNET_memcpy(name_tmp, name, name_len); | 1653 | GNUNET_memcpy (name_tmp, name, name_len); |
1646 | rd_tmp = &name_tmp[name_len]; | 1654 | rd_tmp = &name_tmp[name_len]; |
1647 | GNUNET_assert( | 1655 | GNUNET_assert ( |
1648 | rd_ser_len == | 1656 | rd_ser_len == |
1649 | GNUNET_GNSRECORD_records_serialize(rd_count, rd, rd_ser_len, rd_tmp)); | 1657 | GNUNET_GNSRECORD_records_serialize (rd_count, rd, rd_ser_len, rd_tmp)); |
1650 | ztn_ctx->success = GNUNET_OK; | 1658 | ztn_ctx->success = GNUNET_OK; |
1651 | GNUNET_MQ_send(ztn_ctx->nc->mq, env); | 1659 | GNUNET_MQ_send (ztn_ctx->nc->mq, env); |
1652 | } | 1660 | } |
1653 | 1661 | ||
1654 | 1662 | ||
@@ -1659,41 +1667,41 @@ handle_zone_to_name_it(void *cls, | |||
1659 | * @param ztn_msg message of type 'struct ZoneToNameMessage' | 1667 | * @param ztn_msg message of type 'struct ZoneToNameMessage' |
1660 | */ | 1668 | */ |
1661 | static void | 1669 | static void |
1662 | handle_zone_to_name(void *cls, const struct ZoneToNameMessage *ztn_msg) | 1670 | handle_zone_to_name (void *cls, const struct ZoneToNameMessage *ztn_msg) |
1663 | { | 1671 | { |
1664 | struct NamestoreClient *nc = cls; | 1672 | struct NamestoreClient *nc = cls; |
1665 | struct ZoneToNameCtx ztn_ctx; | 1673 | struct ZoneToNameCtx ztn_ctx; |
1666 | struct GNUNET_MQ_Envelope *env; | 1674 | struct GNUNET_MQ_Envelope *env; |
1667 | struct ZoneToNameResponseMessage *ztnr_msg; | 1675 | struct ZoneToNameResponseMessage *ztnr_msg; |
1668 | 1676 | ||
1669 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_TO_NAME message\n"); | 1677 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_TO_NAME message\n"); |
1670 | ztn_ctx.rid = ntohl(ztn_msg->gns_header.r_id); | 1678 | ztn_ctx.rid = ntohl (ztn_msg->gns_header.r_id); |
1671 | ztn_ctx.nc = nc; | 1679 | ztn_ctx.nc = nc; |
1672 | ztn_ctx.success = GNUNET_NO; | 1680 | ztn_ctx.success = GNUNET_NO; |
1673 | if (GNUNET_SYSERR == GSN_database->zone_to_name(GSN_database->cls, | 1681 | if (GNUNET_SYSERR == GSN_database->zone_to_name (GSN_database->cls, |
1674 | &ztn_msg->zone, | 1682 | &ztn_msg->zone, |
1675 | &ztn_msg->value_zone, | 1683 | &ztn_msg->value_zone, |
1676 | &handle_zone_to_name_it, | 1684 | &handle_zone_to_name_it, |
1677 | &ztn_ctx)) | 1685 | &ztn_ctx)) |
1678 | { | 1686 | { |
1679 | /* internal error, hang up instead of signalling something | 1687 | /* internal error, hang up instead of signalling something |
1680 | that might be wrong */ | 1688 | that might be wrong */ |
1681 | GNUNET_break(0); | 1689 | GNUNET_break (0); |
1682 | GNUNET_SERVICE_client_drop(nc->client); | 1690 | GNUNET_SERVICE_client_drop (nc->client); |
1683 | return; | 1691 | return; |
1684 | } | 1692 | } |
1685 | if (GNUNET_NO == ztn_ctx.success) | 1693 | if (GNUNET_NO == ztn_ctx.success) |
1686 | { | 1694 | { |
1687 | /* no result found, send empty response */ | 1695 | /* no result found, send empty response */ |
1688 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1696 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1689 | "Found no result for zone-to-name lookup.\n"); | 1697 | "Found no result for zone-to-name lookup.\n"); |
1690 | env = GNUNET_MQ_msg(ztnr_msg, | 1698 | env = GNUNET_MQ_msg (ztnr_msg, |
1691 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE); | 1699 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE); |
1692 | ztnr_msg->gns_header.r_id = ztn_msg->gns_header.r_id; | 1700 | ztnr_msg->gns_header.r_id = ztn_msg->gns_header.r_id; |
1693 | ztnr_msg->res = htons(GNUNET_NO); | 1701 | ztnr_msg->res = htons (GNUNET_NO); |
1694 | GNUNET_MQ_send(nc->mq, env); | 1702 | GNUNET_MQ_send (nc->mq, env); |
1695 | } | 1703 | } |
1696 | GNUNET_SERVICE_client_continue(nc->client); | 1704 | GNUNET_SERVICE_client_continue (nc->client); |
1697 | } | 1705 | } |
1698 | 1706 | ||
1699 | 1707 | ||
@@ -1701,7 +1709,8 @@ handle_zone_to_name(void *cls, const struct ZoneToNameMessage *ztn_msg) | |||
1701 | * Context for record remove operations passed from | 1709 | * Context for record remove operations passed from |
1702 | * #run_zone_iteration_round to #zone_iterate_proc as closure | 1710 | * #run_zone_iteration_round to #zone_iterate_proc as closure |
1703 | */ | 1711 | */ |
1704 | struct ZoneIterationProcResult { | 1712 | struct ZoneIterationProcResult |
1713 | { | ||
1705 | /** | 1714 | /** |
1706 | * The zone iteration handle | 1715 | * The zone iteration handle |
1707 | */ | 1716 | */ |
@@ -1725,53 +1734,53 @@ struct ZoneIterationProcResult { | |||
1725 | * @param rd record data | 1734 | * @param rd record data |
1726 | */ | 1735 | */ |
1727 | static void | 1736 | static void |
1728 | zone_iterate_proc(void *cls, | 1737 | zone_iterate_proc (void *cls, |
1729 | uint64_t seq, | 1738 | uint64_t seq, |
1730 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 1739 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, |
1731 | const char *name, | 1740 | const char *name, |
1732 | unsigned int rd_count, | 1741 | unsigned int rd_count, |
1733 | const struct GNUNET_GNSRECORD_Data *rd) | 1742 | const struct GNUNET_GNSRECORD_Data *rd) |
1734 | { | 1743 | { |
1735 | struct ZoneIterationProcResult *proc = cls; | 1744 | struct ZoneIterationProcResult *proc = cls; |
1736 | int do_refresh_block; | 1745 | int do_refresh_block; |
1737 | 1746 | ||
1738 | GNUNET_assert(0 != seq); | 1747 | GNUNET_assert (0 != seq); |
1739 | if ((NULL == zone_key) && (NULL == name)) | 1748 | if ((NULL == zone_key) && (NULL == name)) |
1740 | { | 1749 | { |
1741 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Iteration done\n"); | 1750 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iteration done\n"); |
1742 | return; | 1751 | return; |
1743 | } | 1752 | } |
1744 | if ((NULL == zone_key) || (NULL == name)) | 1753 | if ((NULL == zone_key) || (NULL == name)) |
1745 | { | 1754 | { |
1746 | /* what is this!? should never happen */ | 1755 | /* what is this!? should never happen */ |
1747 | GNUNET_break(0); | 1756 | GNUNET_break (0); |
1748 | return; | 1757 | return; |
1749 | } | 1758 | } |
1750 | if (0 == proc->limit) | 1759 | if (0 == proc->limit) |
1751 | { | 1760 | { |
1752 | /* what is this!? should never happen */ | 1761 | /* what is this!? should never happen */ |
1753 | GNUNET_break(0); | 1762 | GNUNET_break (0); |
1754 | return; | 1763 | return; |
1755 | } | 1764 | } |
1756 | proc->limit--; | 1765 | proc->limit--; |
1757 | proc->zi->seq = seq; | 1766 | proc->zi->seq = seq; |
1758 | send_lookup_response(proc->zi->nc, | 1767 | send_lookup_response (proc->zi->nc, |
1759 | proc->zi->request_id, | 1768 | proc->zi->request_id, |
1760 | zone_key, | 1769 | zone_key, |
1761 | name, | 1770 | name, |
1762 | rd_count, | 1771 | rd_count, |
1763 | rd); | 1772 | rd); |
1764 | 1773 | ||
1765 | 1774 | ||
1766 | do_refresh_block = GNUNET_NO; | 1775 | do_refresh_block = GNUNET_NO; |
1767 | for (unsigned int i = 0; i < rd_count; i++) | 1776 | for (unsigned int i = 0; i < rd_count; i++) |
1768 | if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) | 1777 | if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) |
1769 | { | 1778 | { |
1770 | do_refresh_block = GNUNET_YES; | 1779 | do_refresh_block = GNUNET_YES; |
1771 | break; | 1780 | break; |
1772 | } | 1781 | } |
1773 | if (GNUNET_YES == do_refresh_block) | 1782 | if (GNUNET_YES == do_refresh_block) |
1774 | refresh_block(NULL, proc->zi, 0, zone_key, name, rd_count, rd); | 1783 | refresh_block (NULL, proc->zi, 0, zone_key, name, rd_count, rd); |
1775 | } | 1784 | } |
1776 | 1785 | ||
1777 | 1786 | ||
@@ -1782,42 +1791,42 @@ zone_iterate_proc(void *cls, | |||
1782 | * @param limit number of results to return in one pass | 1791 | * @param limit number of results to return in one pass |
1783 | */ | 1792 | */ |
1784 | static void | 1793 | static void |
1785 | run_zone_iteration_round(struct ZoneIteration *zi, uint64_t limit) | 1794 | run_zone_iteration_round (struct ZoneIteration *zi, uint64_t limit) |
1786 | { | 1795 | { |
1787 | struct ZoneIterationProcResult proc; | 1796 | struct ZoneIterationProcResult proc; |
1788 | struct GNUNET_TIME_Absolute start; | 1797 | struct GNUNET_TIME_Absolute start; |
1789 | struct GNUNET_TIME_Relative duration; | 1798 | struct GNUNET_TIME_Relative duration; |
1790 | 1799 | ||
1791 | memset(&proc, 0, sizeof(proc)); | 1800 | memset (&proc, 0, sizeof(proc)); |
1792 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1801 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1793 | "Asked to return up to %llu records at position %llu\n", | 1802 | "Asked to return up to %llu records at position %llu\n", |
1794 | (unsigned long long)limit, | 1803 | (unsigned long long) limit, |
1795 | (unsigned long long)zi->seq); | 1804 | (unsigned long long) zi->seq); |
1796 | proc.zi = zi; | 1805 | proc.zi = zi; |
1797 | proc.limit = limit; | 1806 | proc.limit = limit; |
1798 | start = GNUNET_TIME_absolute_get(); | 1807 | start = GNUNET_TIME_absolute_get (); |
1799 | GNUNET_break(GNUNET_SYSERR != | 1808 | GNUNET_break (GNUNET_SYSERR != |
1800 | GSN_database->iterate_records(GSN_database->cls, | 1809 | GSN_database->iterate_records (GSN_database->cls, |
1801 | (0 == GNUNET_is_zero(&zi->zone)) | 1810 | (0 == GNUNET_is_zero (&zi->zone)) |
1802 | ? NULL | 1811 | ? NULL |
1803 | : &zi->zone, | 1812 | : &zi->zone, |
1804 | zi->seq, | 1813 | zi->seq, |
1805 | limit, | 1814 | limit, |
1806 | &zone_iterate_proc, | 1815 | &zone_iterate_proc, |
1807 | &proc)); | 1816 | &proc)); |
1808 | duration = GNUNET_TIME_absolute_get_duration(start); | 1817 | duration = GNUNET_TIME_absolute_get_duration (start); |
1809 | duration = GNUNET_TIME_relative_divide(duration, limit - proc.limit); | 1818 | duration = GNUNET_TIME_relative_divide (duration, limit - proc.limit); |
1810 | GNUNET_STATISTICS_set(statistics, | 1819 | GNUNET_STATISTICS_set (statistics, |
1811 | "NAMESTORE iteration delay (μs/record)", | 1820 | "NAMESTORE iteration delay (μs/record)", |
1812 | duration.rel_value_us, | 1821 | duration.rel_value_us, |
1813 | GNUNET_NO); | 1822 | GNUNET_NO); |
1814 | if (0 == proc.limit) | 1823 | if (0 == proc.limit) |
1815 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1824 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1816 | "Returned %llu results, more results available\n", | 1825 | "Returned %llu results, more results available\n", |
1817 | (unsigned long long)limit); | 1826 | (unsigned long long) limit); |
1818 | zi->send_end = (0 != proc.limit); | 1827 | zi->send_end = (0 != proc.limit); |
1819 | if (0 == zi->cache_ops) | 1828 | if (0 == zi->cache_ops) |
1820 | zone_iteration_done_client_continue(zi); | 1829 | zone_iteration_done_client_continue (zi); |
1821 | } | 1830 | } |
1822 | 1831 | ||
1823 | 1832 | ||
@@ -1828,22 +1837,22 @@ run_zone_iteration_round(struct ZoneIteration *zi, uint64_t limit) | |||
1828 | * @param zis_msg message from the client | 1837 | * @param zis_msg message from the client |
1829 | */ | 1838 | */ |
1830 | static void | 1839 | static void |
1831 | handle_iteration_start(void *cls, | 1840 | handle_iteration_start (void *cls, |
1832 | const struct ZoneIterationStartMessage *zis_msg) | 1841 | const struct ZoneIterationStartMessage *zis_msg) |
1833 | { | 1842 | { |
1834 | struct NamestoreClient *nc = cls; | 1843 | struct NamestoreClient *nc = cls; |
1835 | struct ZoneIteration *zi; | 1844 | struct ZoneIteration *zi; |
1836 | 1845 | ||
1837 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1846 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1838 | "Received ZONE_ITERATION_START message\n"); | 1847 | "Received ZONE_ITERATION_START message\n"); |
1839 | zi = GNUNET_new(struct ZoneIteration); | 1848 | zi = GNUNET_new (struct ZoneIteration); |
1840 | zi->request_id = ntohl(zis_msg->gns_header.r_id); | 1849 | zi->request_id = ntohl (zis_msg->gns_header.r_id); |
1841 | zi->offset = 0; | 1850 | zi->offset = 0; |
1842 | zi->nc = nc; | 1851 | zi->nc = nc; |
1843 | zi->zone = zis_msg->zone; | 1852 | zi->zone = zis_msg->zone; |
1844 | 1853 | ||
1845 | GNUNET_CONTAINER_DLL_insert(nc->op_head, nc->op_tail, zi); | 1854 | GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi); |
1846 | run_zone_iteration_round(zi, 1); | 1855 | run_zone_iteration_round (zi, 1); |
1847 | } | 1856 | } |
1848 | 1857 | ||
1849 | 1858 | ||
@@ -1854,28 +1863,28 @@ handle_iteration_start(void *cls, | |||
1854 | * @param zis_msg message from the client | 1863 | * @param zis_msg message from the client |
1855 | */ | 1864 | */ |
1856 | static void | 1865 | static void |
1857 | handle_iteration_stop(void *cls, | 1866 | handle_iteration_stop (void *cls, |
1858 | const struct ZoneIterationStopMessage *zis_msg) | 1867 | const struct ZoneIterationStopMessage *zis_msg) |
1859 | { | 1868 | { |
1860 | struct NamestoreClient *nc = cls; | 1869 | struct NamestoreClient *nc = cls; |
1861 | struct ZoneIteration *zi; | 1870 | struct ZoneIteration *zi; |
1862 | uint32_t rid; | 1871 | uint32_t rid; |
1863 | 1872 | ||
1864 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1873 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1865 | "Received ZONE_ITERATION_STOP message\n"); | 1874 | "Received ZONE_ITERATION_STOP message\n"); |
1866 | rid = ntohl(zis_msg->gns_header.r_id); | 1875 | rid = ntohl (zis_msg->gns_header.r_id); |
1867 | for (zi = nc->op_head; NULL != zi; zi = zi->next) | 1876 | for (zi = nc->op_head; NULL != zi; zi = zi->next) |
1868 | if (zi->request_id == rid) | 1877 | if (zi->request_id == rid) |
1869 | break; | 1878 | break; |
1870 | if (NULL == zi) | 1879 | if (NULL == zi) |
1871 | { | 1880 | { |
1872 | GNUNET_break(0); | 1881 | GNUNET_break (0); |
1873 | GNUNET_SERVICE_client_drop(nc->client); | 1882 | GNUNET_SERVICE_client_drop (nc->client); |
1874 | return; | 1883 | return; |
1875 | } | 1884 | } |
1876 | GNUNET_CONTAINER_DLL_remove(nc->op_head, nc->op_tail, zi); | 1885 | GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, zi); |
1877 | GNUNET_free(zi); | 1886 | GNUNET_free (zi); |
1878 | GNUNET_SERVICE_client_continue(nc->client); | 1887 | GNUNET_SERVICE_client_continue (nc->client); |
1879 | } | 1888 | } |
1880 | 1889 | ||
1881 | 1890 | ||
@@ -1886,32 +1895,32 @@ handle_iteration_stop(void *cls, | |||
1886 | * @param message message from the client | 1895 | * @param message message from the client |
1887 | */ | 1896 | */ |
1888 | static void | 1897 | static void |
1889 | handle_iteration_next(void *cls, | 1898 | handle_iteration_next (void *cls, |
1890 | const struct ZoneIterationNextMessage *zis_msg) | 1899 | const struct ZoneIterationNextMessage *zis_msg) |
1891 | { | 1900 | { |
1892 | struct NamestoreClient *nc = cls; | 1901 | struct NamestoreClient *nc = cls; |
1893 | struct ZoneIteration *zi; | 1902 | struct ZoneIteration *zi; |
1894 | uint32_t rid; | 1903 | uint32_t rid; |
1895 | uint64_t limit; | 1904 | uint64_t limit; |
1896 | 1905 | ||
1897 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1906 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1898 | "Received ZONE_ITERATION_NEXT message\n"); | 1907 | "Received ZONE_ITERATION_NEXT message\n"); |
1899 | GNUNET_STATISTICS_update(statistics, | 1908 | GNUNET_STATISTICS_update (statistics, |
1900 | "Iteration NEXT messages received", | 1909 | "Iteration NEXT messages received", |
1901 | 1, | 1910 | 1, |
1902 | GNUNET_NO); | 1911 | GNUNET_NO); |
1903 | rid = ntohl(zis_msg->gns_header.r_id); | 1912 | rid = ntohl (zis_msg->gns_header.r_id); |
1904 | limit = GNUNET_ntohll(zis_msg->limit); | 1913 | limit = GNUNET_ntohll (zis_msg->limit); |
1905 | for (zi = nc->op_head; NULL != zi; zi = zi->next) | 1914 | for (zi = nc->op_head; NULL != zi; zi = zi->next) |
1906 | if (zi->request_id == rid) | 1915 | if (zi->request_id == rid) |
1907 | break; | 1916 | break; |
1908 | if (NULL == zi) | 1917 | if (NULL == zi) |
1909 | { | 1918 | { |
1910 | GNUNET_break(0); | 1919 | GNUNET_break (0); |
1911 | GNUNET_SERVICE_client_drop(nc->client); | 1920 | GNUNET_SERVICE_client_drop (nc->client); |
1912 | return; | 1921 | return; |
1913 | } | 1922 | } |
1914 | run_zone_iteration_round(zi, limit); | 1923 | run_zone_iteration_round (zi, limit); |
1915 | } | 1924 | } |
1916 | 1925 | ||
1917 | 1926 | ||
@@ -1921,37 +1930,37 @@ handle_iteration_next(void *cls, | |||
1921 | * monitor not being ready. | 1930 | * monitor not being ready. |
1922 | */ | 1931 | */ |
1923 | static void | 1932 | static void |
1924 | monitor_unblock(struct ZoneMonitor *zm) | 1933 | monitor_unblock (struct ZoneMonitor *zm) |
1925 | { | 1934 | { |
1926 | struct StoreActivity *sa = sa_head; | 1935 | struct StoreActivity *sa = sa_head; |
1927 | 1936 | ||
1928 | while ((NULL != sa) && (zm->limit > zm->iteration_cnt)) | 1937 | while ((NULL != sa) && (zm->limit > zm->iteration_cnt)) |
1929 | { | 1938 | { |
1930 | struct StoreActivity *sn = sa->next; | 1939 | struct StoreActivity *sn = sa->next; |
1931 | 1940 | ||
1932 | if (sa->zm_pos == zm) | 1941 | if (sa->zm_pos == zm) |
1933 | continue_store_activity(sa); | 1942 | continue_store_activity (sa); |
1934 | sa = sn; | 1943 | sa = sn; |
1935 | } | 1944 | } |
1936 | if (zm->limit > zm->iteration_cnt) | 1945 | if (zm->limit > zm->iteration_cnt) |
1946 | { | ||
1947 | zm->sa_waiting = GNUNET_NO; | ||
1948 | if (NULL != zm->sa_wait_warning) | ||
1937 | { | 1949 | { |
1938 | zm->sa_waiting = GNUNET_NO; | 1950 | GNUNET_SCHEDULER_cancel (zm->sa_wait_warning); |
1939 | if (NULL != zm->sa_wait_warning) | 1951 | zm->sa_wait_warning = NULL; |
1940 | { | ||
1941 | GNUNET_SCHEDULER_cancel(zm->sa_wait_warning); | ||
1942 | zm->sa_wait_warning = NULL; | ||
1943 | } | ||
1944 | } | 1952 | } |
1953 | } | ||
1945 | else if (GNUNET_YES == zm->sa_waiting) | 1954 | else if (GNUNET_YES == zm->sa_waiting) |
1946 | { | 1955 | { |
1947 | zm->sa_waiting_start = GNUNET_TIME_absolute_get(); | 1956 | zm->sa_waiting_start = GNUNET_TIME_absolute_get (); |
1948 | if (NULL != zm->sa_wait_warning) | 1957 | if (NULL != zm->sa_wait_warning) |
1949 | GNUNET_SCHEDULER_cancel(zm->sa_wait_warning); | 1958 | GNUNET_SCHEDULER_cancel (zm->sa_wait_warning); |
1950 | zm->sa_wait_warning = | 1959 | zm->sa_wait_warning = |
1951 | GNUNET_SCHEDULER_add_delayed(MONITOR_STALL_WARN_DELAY, | 1960 | GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY, |
1952 | &warn_monitor_slow, | 1961 | &warn_monitor_slow, |
1953 | zm); | 1962 | zm); |
1954 | } | 1963 | } |
1955 | } | 1964 | } |
1956 | 1965 | ||
1957 | 1966 | ||
@@ -1961,18 +1970,18 @@ monitor_unblock(struct ZoneMonitor *zm) | |||
1961 | * @param zm monitor that is now in sync | 1970 | * @param zm monitor that is now in sync |
1962 | */ | 1971 | */ |
1963 | static void | 1972 | static void |
1964 | monitor_sync(struct ZoneMonitor *zm) | 1973 | monitor_sync (struct ZoneMonitor *zm) |
1965 | { | 1974 | { |
1966 | struct GNUNET_MQ_Envelope *env; | 1975 | struct GNUNET_MQ_Envelope *env; |
1967 | struct GNUNET_MessageHeader *sync; | 1976 | struct GNUNET_MessageHeader *sync; |
1968 | 1977 | ||
1969 | env = GNUNET_MQ_msg(sync, GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC); | 1978 | env = GNUNET_MQ_msg (sync, GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC); |
1970 | GNUNET_MQ_send(zm->nc->mq, env); | 1979 | GNUNET_MQ_send (zm->nc->mq, env); |
1971 | /* mark iteration done */ | 1980 | /* mark iteration done */ |
1972 | zm->in_first_iteration = GNUNET_NO; | 1981 | zm->in_first_iteration = GNUNET_NO; |
1973 | zm->iteration_cnt = 0; | 1982 | zm->iteration_cnt = 0; |
1974 | if ((zm->limit > 0) && (zm->sa_waiting)) | 1983 | if ((zm->limit > 0) && (zm->sa_waiting)) |
1975 | monitor_unblock(zm); | 1984 | monitor_unblock (zm); |
1976 | } | 1985 | } |
1977 | 1986 | ||
1978 | 1987 | ||
@@ -1982,7 +1991,7 @@ monitor_sync(struct ZoneMonitor *zm) | |||
1982 | * @param cls zone monitor that does its initial iteration | 1991 | * @param cls zone monitor that does its initial iteration |
1983 | */ | 1992 | */ |
1984 | static void | 1993 | static void |
1985 | monitor_iteration_next(void *cls); | 1994 | monitor_iteration_next (void *cls); |
1986 | 1995 | ||
1987 | 1996 | ||
1988 | /** | 1997 | /** |
@@ -1996,32 +2005,32 @@ monitor_iteration_next(void *cls); | |||
1996 | * @param rd array of records | 2005 | * @param rd array of records |
1997 | */ | 2006 | */ |
1998 | static void | 2007 | static void |
1999 | monitor_iterate_cb(void *cls, | 2008 | monitor_iterate_cb (void *cls, |
2000 | uint64_t seq, | 2009 | uint64_t seq, |
2001 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 2010 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, |
2002 | const char *name, | 2011 | const char *name, |
2003 | unsigned int rd_count, | 2012 | unsigned int rd_count, |
2004 | const struct GNUNET_GNSRECORD_Data *rd) | 2013 | const struct GNUNET_GNSRECORD_Data *rd) |
2005 | { | 2014 | { |
2006 | struct ZoneMonitor *zm = cls; | 2015 | struct ZoneMonitor *zm = cls; |
2007 | 2016 | ||
2008 | GNUNET_assert(0 != seq); | 2017 | GNUNET_assert (0 != seq); |
2009 | zm->seq = seq; | 2018 | zm->seq = seq; |
2010 | GNUNET_assert(NULL != name); | 2019 | GNUNET_assert (NULL != name); |
2011 | GNUNET_STATISTICS_update(statistics, | 2020 | GNUNET_STATISTICS_update (statistics, |
2012 | "Monitor notifications sent", | 2021 | "Monitor notifications sent", |
2013 | 1, | 2022 | 1, |
2014 | GNUNET_NO); | 2023 | GNUNET_NO); |
2015 | zm->limit--; | 2024 | zm->limit--; |
2016 | zm->iteration_cnt--; | 2025 | zm->iteration_cnt--; |
2017 | send_lookup_response(zm->nc, 0, zone_key, name, rd_count, rd); | 2026 | send_lookup_response (zm->nc, 0, zone_key, name, rd_count, rd); |
2018 | if ((0 == zm->iteration_cnt) && (0 != zm->limit)) | 2027 | if ((0 == zm->iteration_cnt) && (0 != zm->limit)) |
2019 | { | 2028 | { |
2020 | /* We are done with the current iteration batch, AND the | 2029 | /* We are done with the current iteration batch, AND the |
2021 | client would right now accept more, so go again! */ | 2030 | client would right now accept more, so go again! */ |
2022 | GNUNET_assert(NULL == zm->task); | 2031 | GNUNET_assert (NULL == zm->task); |
2023 | zm->task = GNUNET_SCHEDULER_add_now(&monitor_iteration_next, zm); | 2032 | zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next, zm); |
2024 | } | 2033 | } |
2025 | } | 2034 | } |
2026 | 2035 | ||
2027 | 2036 | ||
@@ -2032,25 +2041,25 @@ monitor_iterate_cb(void *cls, | |||
2032 | * @param zis_msg message from the client | 2041 | * @param zis_msg message from the client |
2033 | */ | 2042 | */ |
2034 | static void | 2043 | static void |
2035 | handle_monitor_start(void *cls, const struct ZoneMonitorStartMessage *zis_msg) | 2044 | handle_monitor_start (void *cls, const struct ZoneMonitorStartMessage *zis_msg) |
2036 | { | 2045 | { |
2037 | struct NamestoreClient *nc = cls; | 2046 | struct NamestoreClient *nc = cls; |
2038 | struct ZoneMonitor *zm; | 2047 | struct ZoneMonitor *zm; |
2039 | 2048 | ||
2040 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_MONITOR_START message\n"); | 2049 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_MONITOR_START message\n"); |
2041 | zm = GNUNET_new(struct ZoneMonitor); | 2050 | zm = GNUNET_new (struct ZoneMonitor); |
2042 | zm->nc = nc; | 2051 | zm->nc = nc; |
2043 | zm->zone = zis_msg->zone; | 2052 | zm->zone = zis_msg->zone; |
2044 | zm->limit = 1; | 2053 | zm->limit = 1; |
2045 | zm->in_first_iteration = (GNUNET_YES == ntohl(zis_msg->iterate_first)); | 2054 | zm->in_first_iteration = (GNUNET_YES == ntohl (zis_msg->iterate_first)); |
2046 | GNUNET_CONTAINER_DLL_insert(monitor_head, monitor_tail, zm); | 2055 | GNUNET_CONTAINER_DLL_insert (monitor_head, monitor_tail, zm); |
2047 | GNUNET_SERVICE_client_mark_monitor(nc->client); | 2056 | GNUNET_SERVICE_client_mark_monitor (nc->client); |
2048 | GNUNET_SERVICE_client_continue(nc->client); | 2057 | GNUNET_SERVICE_client_continue (nc->client); |
2049 | GNUNET_notification_context_add(monitor_nc, nc->mq); | 2058 | GNUNET_notification_context_add (monitor_nc, nc->mq); |
2050 | if (zm->in_first_iteration) | 2059 | if (zm->in_first_iteration) |
2051 | zm->task = GNUNET_SCHEDULER_add_now(&monitor_iteration_next, zm); | 2060 | zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next, zm); |
2052 | else | 2061 | else |
2053 | monitor_sync(zm); | 2062 | monitor_sync (zm); |
2054 | } | 2063 | } |
2055 | 2064 | ||
2056 | 2065 | ||
@@ -2060,36 +2069,36 @@ handle_monitor_start(void *cls, const struct ZoneMonitorStartMessage *zis_msg) | |||
2060 | * @param cls zone monitor that does its initial iteration | 2069 | * @param cls zone monitor that does its initial iteration |
2061 | */ | 2070 | */ |
2062 | static void | 2071 | static void |
2063 | monitor_iteration_next(void *cls) | 2072 | monitor_iteration_next (void *cls) |
2064 | { | 2073 | { |
2065 | struct ZoneMonitor *zm = cls; | 2074 | struct ZoneMonitor *zm = cls; |
2066 | int ret; | 2075 | int ret; |
2067 | 2076 | ||
2068 | zm->task = NULL; | 2077 | zm->task = NULL; |
2069 | GNUNET_assert(0 == zm->iteration_cnt); | 2078 | GNUNET_assert (0 == zm->iteration_cnt); |
2070 | if (zm->limit > 16) | 2079 | if (zm->limit > 16) |
2071 | zm->iteration_cnt = zm->limit / 2; /* leave half for monitor events */ | 2080 | zm->iteration_cnt = zm->limit / 2; /* leave half for monitor events */ |
2072 | else | 2081 | else |
2073 | zm->iteration_cnt = zm->limit; /* use it all */ | 2082 | zm->iteration_cnt = zm->limit; /* use it all */ |
2074 | ret = GSN_database->iterate_records(GSN_database->cls, | 2083 | ret = GSN_database->iterate_records (GSN_database->cls, |
2075 | (0 == GNUNET_is_zero(&zm->zone)) | 2084 | (0 == GNUNET_is_zero (&zm->zone)) |
2076 | ? NULL | 2085 | ? NULL |
2077 | : &zm->zone, | 2086 | : &zm->zone, |
2078 | zm->seq, | 2087 | zm->seq, |
2079 | zm->iteration_cnt, | 2088 | zm->iteration_cnt, |
2080 | &monitor_iterate_cb, | 2089 | &monitor_iterate_cb, |
2081 | zm); | 2090 | zm); |
2082 | if (GNUNET_SYSERR == ret) | 2091 | if (GNUNET_SYSERR == ret) |
2083 | { | 2092 | { |
2084 | GNUNET_SERVICE_client_drop(zm->nc->client); | 2093 | GNUNET_SERVICE_client_drop (zm->nc->client); |
2085 | return; | 2094 | return; |
2086 | } | 2095 | } |
2087 | if (GNUNET_NO == ret) | 2096 | if (GNUNET_NO == ret) |
2088 | { | 2097 | { |
2089 | /* empty zone */ | 2098 | /* empty zone */ |
2090 | monitor_sync(zm); | 2099 | monitor_sync (zm); |
2091 | return; | 2100 | return; |
2092 | } | 2101 | } |
2093 | } | 2102 | } |
2094 | 2103 | ||
2095 | 2104 | ||
@@ -2100,55 +2109,55 @@ monitor_iteration_next(void *cls) | |||
2100 | * @param nm message from the client | 2109 | * @param nm message from the client |
2101 | */ | 2110 | */ |
2102 | static void | 2111 | static void |
2103 | handle_monitor_next(void *cls, const struct ZoneMonitorNextMessage *nm) | 2112 | handle_monitor_next (void *cls, const struct ZoneMonitorNextMessage *nm) |
2104 | { | 2113 | { |
2105 | struct NamestoreClient *nc = cls; | 2114 | struct NamestoreClient *nc = cls; |
2106 | struct ZoneMonitor *zm; | 2115 | struct ZoneMonitor *zm; |
2107 | uint64_t inc; | 2116 | uint64_t inc; |
2108 | 2117 | ||
2109 | inc = GNUNET_ntohll(nm->limit); | 2118 | inc = GNUNET_ntohll (nm->limit); |
2110 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2119 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2111 | "Received ZONE_MONITOR_NEXT message with limit %llu\n", | 2120 | "Received ZONE_MONITOR_NEXT message with limit %llu\n", |
2112 | (unsigned long long)inc); | 2121 | (unsigned long long) inc); |
2113 | for (zm = monitor_head; NULL != zm; zm = zm->next) | 2122 | for (zm = monitor_head; NULL != zm; zm = zm->next) |
2114 | if (zm->nc == nc) | 2123 | if (zm->nc == nc) |
2115 | break; | 2124 | break; |
2116 | if (NULL == zm) | 2125 | if (NULL == zm) |
2117 | { | 2126 | { |
2118 | GNUNET_break(0); | 2127 | GNUNET_break (0); |
2119 | GNUNET_SERVICE_client_drop(nc->client); | 2128 | GNUNET_SERVICE_client_drop (nc->client); |
2120 | return; | 2129 | return; |
2121 | } | 2130 | } |
2122 | GNUNET_SERVICE_client_continue(nc->client); | 2131 | GNUNET_SERVICE_client_continue (nc->client); |
2123 | if (zm->limit + inc < zm->limit) | 2132 | if (zm->limit + inc < zm->limit) |
2124 | { | 2133 | { |
2125 | GNUNET_break(0); | 2134 | GNUNET_break (0); |
2126 | GNUNET_SERVICE_client_drop(nc->client); | 2135 | GNUNET_SERVICE_client_drop (nc->client); |
2127 | return; | 2136 | return; |
2128 | } | 2137 | } |
2129 | zm->limit += inc; | 2138 | zm->limit += inc; |
2130 | if ((zm->in_first_iteration) && (zm->limit == inc)) | 2139 | if ((zm->in_first_iteration) && (zm->limit == inc)) |
2131 | { | 2140 | { |
2132 | /* We are still iterating, and the previous iteration must | 2141 | /* We are still iterating, and the previous iteration must |
2133 | have stopped due to the client's limit, so continue it! */ | 2142 | have stopped due to the client's limit, so continue it! */ |
2134 | GNUNET_assert(NULL == zm->task); | 2143 | GNUNET_assert (NULL == zm->task); |
2135 | zm->task = GNUNET_SCHEDULER_add_now(&monitor_iteration_next, zm); | 2144 | zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next, zm); |
2136 | } | 2145 | } |
2137 | GNUNET_assert(zm->iteration_cnt <= zm->limit); | 2146 | GNUNET_assert (zm->iteration_cnt <= zm->limit); |
2138 | if ((zm->limit > zm->iteration_cnt) && (zm->sa_waiting)) | 2147 | if ((zm->limit > zm->iteration_cnt) && (zm->sa_waiting)) |
2139 | { | 2148 | { |
2140 | monitor_unblock(zm); | 2149 | monitor_unblock (zm); |
2141 | } | 2150 | } |
2142 | else if (GNUNET_YES == zm->sa_waiting) | 2151 | else if (GNUNET_YES == zm->sa_waiting) |
2143 | { | 2152 | { |
2144 | if (NULL != zm->sa_wait_warning) | 2153 | if (NULL != zm->sa_wait_warning) |
2145 | GNUNET_SCHEDULER_cancel(zm->sa_wait_warning); | 2154 | GNUNET_SCHEDULER_cancel (zm->sa_wait_warning); |
2146 | zm->sa_waiting_start = GNUNET_TIME_absolute_get(); | 2155 | zm->sa_waiting_start = GNUNET_TIME_absolute_get (); |
2147 | zm->sa_wait_warning = | 2156 | zm->sa_wait_warning = |
2148 | GNUNET_SCHEDULER_add_delayed(MONITOR_STALL_WARN_DELAY, | 2157 | GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY, |
2149 | &warn_monitor_slow, | 2158 | &warn_monitor_slow, |
2150 | zm); | 2159 | zm); |
2151 | } | 2160 | } |
2152 | } | 2161 | } |
2153 | 2162 | ||
2154 | 2163 | ||
@@ -2160,92 +2169,92 @@ handle_monitor_next(void *cls, const struct ZoneMonitorNextMessage *nm) | |||
2160 | * @param service the initialized service | 2169 | * @param service the initialized service |
2161 | */ | 2170 | */ |
2162 | static void | 2171 | static void |
2163 | run(void *cls, | 2172 | run (void *cls, |
2164 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 2173 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
2165 | struct GNUNET_SERVICE_Handle *service) | 2174 | struct GNUNET_SERVICE_Handle *service) |
2166 | { | 2175 | { |
2167 | char *database; | 2176 | char *database; |
2168 | 2177 | ||
2169 | (void)cls; | 2178 | (void) cls; |
2170 | (void)service; | 2179 | (void) service; |
2171 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Starting namestore service\n"); | 2180 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting namestore service\n"); |
2172 | cache_keys = | 2181 | cache_keys = |
2173 | GNUNET_CONFIGURATION_get_value_yesno(cfg, "namestore", "CACHE_KEYS"); | 2182 | GNUNET_CONFIGURATION_get_value_yesno (cfg, "namestore", "CACHE_KEYS"); |
2174 | disable_namecache = | 2183 | disable_namecache = |
2175 | GNUNET_CONFIGURATION_get_value_yesno(cfg, "namecache", "DISABLE"); | 2184 | GNUNET_CONFIGURATION_get_value_yesno (cfg, "namecache", "DISABLE"); |
2176 | GSN_cfg = cfg; | 2185 | GSN_cfg = cfg; |
2177 | monitor_nc = GNUNET_notification_context_create(1); | 2186 | monitor_nc = GNUNET_notification_context_create (1); |
2178 | if (GNUNET_YES != disable_namecache) | 2187 | if (GNUNET_YES != disable_namecache) |
2179 | { | 2188 | { |
2180 | namecache = GNUNET_NAMECACHE_connect(cfg); | 2189 | namecache = GNUNET_NAMECACHE_connect (cfg); |
2181 | GNUNET_assert(NULL != namecache); | 2190 | GNUNET_assert (NULL != namecache); |
2182 | } | 2191 | } |
2183 | /* Loading database plugin */ | 2192 | /* Loading database plugin */ |
2184 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, | 2193 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, |
2185 | "namestore", | 2194 | "namestore", |
2186 | "database", | 2195 | "database", |
2187 | &database)) | 2196 | &database)) |
2188 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No database backend configured\n"); | 2197 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No database backend configured\n"); |
2189 | 2198 | ||
2190 | GNUNET_asprintf(&db_lib_name, "libgnunet_plugin_namestore_%s", database); | 2199 | GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_namestore_%s", database); |
2191 | GSN_database = GNUNET_PLUGIN_load(db_lib_name, (void *)GSN_cfg); | 2200 | GSN_database = GNUNET_PLUGIN_load (db_lib_name, (void *) GSN_cfg); |
2192 | GNUNET_free(database); | 2201 | GNUNET_free (database); |
2193 | statistics = GNUNET_STATISTICS_create("namestore", cfg); | 2202 | statistics = GNUNET_STATISTICS_create ("namestore", cfg); |
2194 | GNUNET_SCHEDULER_add_shutdown(&cleanup_task, NULL); | 2203 | GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL); |
2195 | if (NULL == GSN_database) | 2204 | if (NULL == GSN_database) |
2196 | { | 2205 | { |
2197 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 2206 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
2198 | "Could not load database backend `%s'\n", | 2207 | "Could not load database backend `%s'\n", |
2199 | db_lib_name); | 2208 | db_lib_name); |
2200 | GNUNET_SCHEDULER_shutdown(); | 2209 | GNUNET_SCHEDULER_shutdown (); |
2201 | return; | 2210 | return; |
2202 | } | 2211 | } |
2203 | } | 2212 | } |
2204 | 2213 | ||
2205 | 2214 | ||
2206 | /** | 2215 | /** |
2207 | * Define "main" method using service macro. | 2216 | * Define "main" method using service macro. |
2208 | */ | 2217 | */ |
2209 | GNUNET_SERVICE_MAIN( | 2218 | GNUNET_SERVICE_MAIN ( |
2210 | "namestore", | 2219 | "namestore", |
2211 | GNUNET_SERVICE_OPTION_NONE, | 2220 | GNUNET_SERVICE_OPTION_NONE, |
2212 | &run, | 2221 | &run, |
2213 | &client_connect_cb, | 2222 | &client_connect_cb, |
2214 | &client_disconnect_cb, | 2223 | &client_disconnect_cb, |
2215 | NULL, | 2224 | NULL, |
2216 | GNUNET_MQ_hd_var_size(record_store, | 2225 | GNUNET_MQ_hd_var_size (record_store, |
2217 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE, | 2226 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE, |
2218 | struct RecordStoreMessage, | 2227 | struct RecordStoreMessage, |
2219 | NULL), | 2228 | NULL), |
2220 | GNUNET_MQ_hd_var_size(record_lookup, | 2229 | GNUNET_MQ_hd_var_size (record_lookup, |
2221 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP, | 2230 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP, |
2222 | struct LabelLookupMessage, | 2231 | struct LabelLookupMessage, |
2223 | NULL), | 2232 | NULL), |
2224 | GNUNET_MQ_hd_fixed_size(zone_to_name, | 2233 | GNUNET_MQ_hd_fixed_size (zone_to_name, |
2225 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME, | 2234 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME, |
2226 | struct ZoneToNameMessage, | 2235 | struct ZoneToNameMessage, |
2227 | NULL), | 2236 | NULL), |
2228 | GNUNET_MQ_hd_fixed_size(iteration_start, | 2237 | GNUNET_MQ_hd_fixed_size (iteration_start, |
2229 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START, | 2238 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START, |
2230 | struct ZoneIterationStartMessage, | 2239 | struct ZoneIterationStartMessage, |
2231 | NULL), | 2240 | NULL), |
2232 | GNUNET_MQ_hd_fixed_size(iteration_next, | 2241 | GNUNET_MQ_hd_fixed_size (iteration_next, |
2233 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT, | 2242 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT, |
2234 | struct ZoneIterationNextMessage, | 2243 | struct ZoneIterationNextMessage, |
2235 | NULL), | 2244 | NULL), |
2236 | GNUNET_MQ_hd_fixed_size(iteration_stop, | 2245 | GNUNET_MQ_hd_fixed_size (iteration_stop, |
2237 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP, | 2246 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP, |
2238 | struct ZoneIterationStopMessage, | 2247 | struct ZoneIterationStopMessage, |
2239 | NULL), | 2248 | NULL), |
2240 | GNUNET_MQ_hd_fixed_size(monitor_start, | 2249 | GNUNET_MQ_hd_fixed_size (monitor_start, |
2241 | GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START, | 2250 | GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START, |
2242 | struct ZoneMonitorStartMessage, | 2251 | struct ZoneMonitorStartMessage, |
2243 | NULL), | 2252 | NULL), |
2244 | GNUNET_MQ_hd_fixed_size(monitor_next, | 2253 | GNUNET_MQ_hd_fixed_size (monitor_next, |
2245 | GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT, | 2254 | GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT, |
2246 | struct ZoneMonitorNextMessage, | 2255 | struct ZoneMonitorNextMessage, |
2247 | NULL), | 2256 | NULL), |
2248 | GNUNET_MQ_handler_end()); | 2257 | GNUNET_MQ_handler_end ()); |
2249 | 2258 | ||
2250 | 2259 | ||
2251 | /* end of gnunet-service-namestore.c */ | 2260 | /* end of gnunet-service-namestore.c */ |
diff --git a/src/namestore/gnunet-zoneimport.c b/src/namestore/gnunet-zoneimport.c index 60d8b0537..bbbe7d783 100644 --- a/src/namestore/gnunet-zoneimport.c +++ b/src/namestore/gnunet-zoneimport.c | |||
@@ -57,7 +57,7 @@ | |||
57 | * How long do we wait at least between series of requests? | 57 | * How long do we wait at least between series of requests? |
58 | */ | 58 | */ |
59 | #define SERIES_DELAY \ | 59 | #define SERIES_DELAY \ |
60 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MICROSECONDS, 10) | 60 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 10) |
61 | 61 | ||
62 | /** | 62 | /** |
63 | * How long do DNS records have to last at least after being imported? | 63 | * How long do DNS records have to last at least after being imported? |
@@ -76,7 +76,8 @@ static struct GNUNET_TIME_Relative minimum_expiration_time; | |||
76 | * each dot represents a zone cut, we then need to create a | 76 | * each dot represents a zone cut, we then need to create a |
77 | * zone on-the-fly to capture those records properly. | 77 | * zone on-the-fly to capture those records properly. |
78 | */ | 78 | */ |
79 | struct Zone { | 79 | struct Zone |
80 | { | ||
80 | /** | 81 | /** |
81 | * Kept in a DLL. | 82 | * Kept in a DLL. |
82 | */ | 83 | */ |
@@ -102,7 +103,8 @@ struct Zone { | |||
102 | /** | 103 | /** |
103 | * Record for the request to be stored by GNS. | 104 | * Record for the request to be stored by GNS. |
104 | */ | 105 | */ |
105 | struct Record { | 106 | struct Record |
107 | { | ||
106 | /** | 108 | /** |
107 | * Kept in a DLL. | 109 | * Kept in a DLL. |
108 | */ | 110 | */ |
@@ -125,7 +127,8 @@ struct Record { | |||
125 | * thus optimizing it is crucial for the overall memory consumption of | 127 | * thus optimizing it is crucial for the overall memory consumption of |
126 | * the zone importer. | 128 | * the zone importer. |
127 | */ | 129 | */ |
128 | struct Request { | 130 | struct Request |
131 | { | ||
129 | /** | 132 | /** |
130 | * Requests are kept in a heap while waiting to be resolved. | 133 | * Requests are kept in a heap while waiting to be resolved. |
131 | */ | 134 | */ |
@@ -375,28 +378,28 @@ typedef void (*RecordProcessor) (void *cls, | |||
375 | * @param rp_cls closure for @a rp | 378 | * @param rp_cls closure for @a rp |
376 | */ | 379 | */ |
377 | static void | 380 | static void |
378 | for_all_records(const struct GNUNET_DNSPARSER_Packet *p, | 381 | for_all_records (const struct GNUNET_DNSPARSER_Packet *p, |
379 | RecordProcessor rp, | 382 | RecordProcessor rp, |
380 | void *rp_cls) | 383 | void *rp_cls) |
381 | { | 384 | { |
382 | for (unsigned int i = 0; i < p->num_answers; i++) | 385 | for (unsigned int i = 0; i < p->num_answers; i++) |
383 | { | 386 | { |
384 | struct GNUNET_DNSPARSER_Record *rs = &p->answers[i]; | 387 | struct GNUNET_DNSPARSER_Record *rs = &p->answers[i]; |
385 | 388 | ||
386 | rp(rp_cls, rs); | 389 | rp (rp_cls, rs); |
387 | } | 390 | } |
388 | for (unsigned int i = 0; i < p->num_authority_records; i++) | 391 | for (unsigned int i = 0; i < p->num_authority_records; i++) |
389 | { | 392 | { |
390 | struct GNUNET_DNSPARSER_Record *rs = &p->authority_records[i]; | 393 | struct GNUNET_DNSPARSER_Record *rs = &p->authority_records[i]; |
391 | 394 | ||
392 | rp(rp_cls, rs); | 395 | rp (rp_cls, rs); |
393 | } | 396 | } |
394 | for (unsigned int i = 0; i < p->num_additional_records; i++) | 397 | for (unsigned int i = 0; i < p->num_additional_records; i++) |
395 | { | 398 | { |
396 | struct GNUNET_DNSPARSER_Record *rs = &p->additional_records[i]; | 399 | struct GNUNET_DNSPARSER_Record *rs = &p->additional_records[i]; |
397 | 400 | ||
398 | rp(rp_cls, rs); | 401 | rp (rp_cls, rs); |
399 | } | 402 | } |
400 | } | 403 | } |
401 | 404 | ||
402 | 405 | ||
@@ -408,23 +411,23 @@ for_all_records(const struct GNUNET_DNSPARSER_Packet *p, | |||
408 | * overwritten upon the next request! | 411 | * overwritten upon the next request! |
409 | */ | 412 | */ |
410 | static const char * | 413 | static const char * |
411 | get_label(struct Request *req) | 414 | get_label (struct Request *req) |
412 | { | 415 | { |
413 | static char label[64]; | 416 | static char label[64]; |
414 | const char *dot; | 417 | const char *dot; |
415 | 418 | ||
416 | dot = strchr(req->hostname, (unsigned char)'.'); | 419 | dot = strchr (req->hostname, (unsigned char) '.'); |
417 | if (NULL == dot) | 420 | if (NULL == dot) |
418 | { | 421 | { |
419 | GNUNET_break(0); | 422 | GNUNET_break (0); |
420 | return NULL; | 423 | return NULL; |
421 | } | 424 | } |
422 | if (((size_t)(dot - req->hostname)) >= sizeof(label)) | 425 | if (((size_t) (dot - req->hostname)) >= sizeof(label)) |
423 | { | 426 | { |
424 | GNUNET_break(0); | 427 | GNUNET_break (0); |
425 | return NULL; | 428 | return NULL; |
426 | } | 429 | } |
427 | GNUNET_memcpy(label, req->hostname, dot - req->hostname); | 430 | GNUNET_memcpy (label, req->hostname, dot - req->hostname); |
428 | label[dot - req->hostname] = '\0'; | 431 | label[dot - req->hostname] = '\0'; |
429 | return label; | 432 | return label; |
430 | } | 433 | } |
@@ -439,7 +442,7 @@ get_label(struct Request *req) | |||
439 | * allocated query buffer | 442 | * allocated query buffer |
440 | */ | 443 | */ |
441 | static void * | 444 | static void * |
442 | build_dns_query(struct Request *req, size_t *raw_size) | 445 | build_dns_query (struct Request *req, size_t *raw_size) |
443 | { | 446 | { |
444 | static char raw[512]; | 447 | static char raw[512]; |
445 | char *rawp; | 448 | char *rawp; |
@@ -447,37 +450,37 @@ build_dns_query(struct Request *req, size_t *raw_size) | |||
447 | struct GNUNET_DNSPARSER_Query q; | 450 | struct GNUNET_DNSPARSER_Query q; |
448 | int ret; | 451 | int ret; |
449 | 452 | ||
450 | q.name = (char *)req->hostname; | 453 | q.name = (char *) req->hostname; |
451 | q.type = GNUNET_DNSPARSER_TYPE_NS; | 454 | q.type = GNUNET_DNSPARSER_TYPE_NS; |
452 | q.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; | 455 | q.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; |
453 | 456 | ||
454 | memset(&p, 0, sizeof(p)); | 457 | memset (&p, 0, sizeof(p)); |
455 | p.num_queries = 1; | 458 | p.num_queries = 1; |
456 | p.queries = &q; | 459 | p.queries = &q; |
457 | p.id = req->id; | 460 | p.id = req->id; |
458 | ret = GNUNET_DNSPARSER_pack(&p, UINT16_MAX, &rawp, raw_size); | 461 | ret = GNUNET_DNSPARSER_pack (&p, UINT16_MAX, &rawp, raw_size); |
459 | if (GNUNET_OK != ret) | 462 | if (GNUNET_OK != ret) |
460 | { | 463 | { |
461 | if (GNUNET_NO == ret) | 464 | if (GNUNET_NO == ret) |
462 | GNUNET_free(rawp); | 465 | GNUNET_free (rawp); |
463 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 466 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
464 | "Failed to pack query for hostname `%s'\n", | 467 | "Failed to pack query for hostname `%s'\n", |
465 | req->hostname); | 468 | req->hostname); |
466 | rejects++; | 469 | rejects++; |
467 | return NULL; | 470 | return NULL; |
468 | } | 471 | } |
469 | if (*raw_size > sizeof(raw)) | 472 | if (*raw_size > sizeof(raw)) |
470 | { | 473 | { |
471 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 474 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
472 | "Failed to pack query for hostname `%s'\n", | 475 | "Failed to pack query for hostname `%s'\n", |
473 | req->hostname); | 476 | req->hostname); |
474 | rejects++; | 477 | rejects++; |
475 | GNUNET_break(0); | 478 | GNUNET_break (0); |
476 | GNUNET_free(rawp); | 479 | GNUNET_free (rawp); |
477 | return NULL; | 480 | return NULL; |
478 | } | 481 | } |
479 | GNUNET_memcpy(raw, rawp, *raw_size); | 482 | GNUNET_memcpy (raw, rawp, *raw_size); |
480 | GNUNET_free(rawp); | 483 | GNUNET_free (rawp); |
481 | return raw; | 484 | return raw; |
482 | } | 485 | } |
483 | 486 | ||
@@ -488,16 +491,16 @@ build_dns_query(struct Request *req, size_t *raw_size) | |||
488 | * @param req request to free records of | 491 | * @param req request to free records of |
489 | */ | 492 | */ |
490 | static void | 493 | static void |
491 | free_records(struct Request *req) | 494 | free_records (struct Request *req) |
492 | { | 495 | { |
493 | struct Record *rec; | 496 | struct Record *rec; |
494 | 497 | ||
495 | /* Free records */ | 498 | /* Free records */ |
496 | while (NULL != (rec = req->rec_head)) | 499 | while (NULL != (rec = req->rec_head)) |
497 | { | 500 | { |
498 | GNUNET_CONTAINER_DLL_remove(req->rec_head, req->rec_tail, rec); | 501 | GNUNET_CONTAINER_DLL_remove (req->rec_head, req->rec_tail, rec); |
499 | GNUNET_free(rec); | 502 | GNUNET_free (rec); |
500 | } | 503 | } |
501 | } | 504 | } |
502 | 505 | ||
503 | 506 | ||
@@ -507,10 +510,10 @@ free_records(struct Request *req) | |||
507 | * @param req request to free | 510 | * @param req request to free |
508 | */ | 511 | */ |
509 | static void | 512 | static void |
510 | free_request(struct Request *req) | 513 | free_request (struct Request *req) |
511 | { | 514 | { |
512 | free_records(req); | 515 | free_records (req); |
513 | GNUNET_free(req); | 516 | GNUNET_free (req); |
514 | } | 517 | } |
515 | 518 | ||
516 | 519 | ||
@@ -520,7 +523,7 @@ free_request(struct Request *req) | |||
520 | * @param cls NULL | 523 | * @param cls NULL |
521 | */ | 524 | */ |
522 | static void | 525 | static void |
523 | process_queue(void *cls); | 526 | process_queue (void *cls); |
524 | 527 | ||
525 | 528 | ||
526 | /** | 529 | /** |
@@ -529,17 +532,17 @@ process_queue(void *cls); | |||
529 | * @param req request to insert into #req_heap | 532 | * @param req request to insert into #req_heap |
530 | */ | 533 | */ |
531 | static void | 534 | static void |
532 | insert_sorted(struct Request *req) | 535 | insert_sorted (struct Request *req) |
533 | { | 536 | { |
534 | req->hn = | 537 | req->hn = |
535 | GNUNET_CONTAINER_heap_insert(req_heap, req, req->expires.abs_value_us); | 538 | GNUNET_CONTAINER_heap_insert (req_heap, req, req->expires.abs_value_us); |
536 | if (req == GNUNET_CONTAINER_heap_peek(req_heap)) | 539 | if (req == GNUNET_CONTAINER_heap_peek (req_heap)) |
537 | { | 540 | { |
538 | if (NULL != t) | 541 | if (NULL != t) |
539 | GNUNET_SCHEDULER_cancel(t); | 542 | GNUNET_SCHEDULER_cancel (t); |
540 | sleep_time_reg_proc = GNUNET_TIME_absolute_get(); | 543 | sleep_time_reg_proc = GNUNET_TIME_absolute_get (); |
541 | t = GNUNET_SCHEDULER_add_at(req->expires, &process_queue, NULL); | 544 | t = GNUNET_SCHEDULER_add_at (req->expires, &process_queue, NULL); |
542 | } | 545 | } |
543 | } | 546 | } |
544 | 547 | ||
545 | 548 | ||
@@ -553,29 +556,30 @@ insert_sorted(struct Request *req) | |||
553 | * @param data_len number of bytes in @a data | 556 | * @param data_len number of bytes in @a data |
554 | */ | 557 | */ |
555 | static void | 558 | static void |
556 | add_record(struct Request *req, | 559 | add_record (struct Request *req, |
557 | uint32_t type, | 560 | uint32_t type, |
558 | struct GNUNET_TIME_Absolute expiration_time, | 561 | struct GNUNET_TIME_Absolute expiration_time, |
559 | const void *data, | 562 | const void *data, |
560 | size_t data_len) | 563 | size_t data_len) |
561 | { | 564 | { |
562 | struct Record *rec; | 565 | struct Record *rec; |
563 | 566 | ||
564 | rec = GNUNET_malloc(sizeof(struct Record) + data_len); | 567 | rec = GNUNET_malloc (sizeof(struct Record) + data_len); |
565 | rec->grd.data = &rec[1]; | 568 | rec->grd.data = &rec[1]; |
566 | rec->grd.expiration_time = expiration_time.abs_value_us; | 569 | rec->grd.expiration_time = expiration_time.abs_value_us; |
567 | rec->grd.data_size = data_len; | 570 | rec->grd.data_size = data_len; |
568 | rec->grd.record_type = type; | 571 | rec->grd.record_type = type; |
569 | rec->grd.flags = GNUNET_GNSRECORD_RF_NONE; | 572 | rec->grd.flags = GNUNET_GNSRECORD_RF_NONE; |
570 | GNUNET_memcpy(&rec[1], data, data_len); | 573 | GNUNET_memcpy (&rec[1], data, data_len); |
571 | GNUNET_CONTAINER_DLL_insert(req->rec_head, req->rec_tail, rec); | 574 | GNUNET_CONTAINER_DLL_insert (req->rec_head, req->rec_tail, rec); |
572 | } | 575 | } |
573 | 576 | ||
574 | 577 | ||
575 | /** | 578 | /** |
576 | * Closure for #check_for_glue. | 579 | * Closure for #check_for_glue. |
577 | */ | 580 | */ |
578 | struct GlueClosure { | 581 | struct GlueClosure |
582 | { | ||
579 | /** | 583 | /** |
580 | * Overall request we are processing. | 584 | * Overall request we are processing. |
581 | */ | 585 | */ |
@@ -600,115 +604,116 @@ struct GlueClosure { | |||
600 | * @param rec record that may contain glue information | 604 | * @param rec record that may contain glue information |
601 | */ | 605 | */ |
602 | static void | 606 | static void |
603 | check_for_glue(void *cls, const struct GNUNET_DNSPARSER_Record *rec) | 607 | check_for_glue (void *cls, const struct GNUNET_DNSPARSER_Record *rec) |
604 | { | 608 | { |
605 | struct GlueClosure *gc = cls; | 609 | struct GlueClosure *gc = cls; |
606 | char dst[65536]; | 610 | char dst[65536]; |
607 | size_t dst_len; | 611 | size_t dst_len; |
608 | size_t off; | 612 | size_t off; |
609 | char ip[INET6_ADDRSTRLEN + 1]; | 613 | char ip[INET6_ADDRSTRLEN + 1]; |
610 | socklen_t ip_size = (socklen_t)sizeof(ip); | 614 | socklen_t ip_size = (socklen_t) sizeof(ip); |
611 | struct GNUNET_TIME_Absolute expiration_time; | 615 | struct GNUNET_TIME_Absolute expiration_time; |
612 | struct GNUNET_TIME_Relative left; | 616 | struct GNUNET_TIME_Relative left; |
613 | 617 | ||
614 | if (0 != strcasecmp(rec->name, gc->ns)) | 618 | if (0 != strcasecmp (rec->name, gc->ns)) |
615 | return; | 619 | return; |
616 | expiration_time = rec->expiration_time; | 620 | expiration_time = rec->expiration_time; |
617 | left = GNUNET_TIME_absolute_get_remaining(expiration_time); | 621 | left = GNUNET_TIME_absolute_get_remaining (expiration_time); |
618 | if (0 == left.rel_value_us) | 622 | if (0 == left.rel_value_us) |
619 | return; /* ignore expired glue records */ | 623 | return; /* ignore expired glue records */ |
620 | /* if expiration window is too short, bump it to configured minimum */ | 624 | /* if expiration window is too short, bump it to configured minimum */ |
621 | if (left.rel_value_us < minimum_expiration_time.rel_value_us) | 625 | if (left.rel_value_us < minimum_expiration_time.rel_value_us) |
622 | expiration_time = | 626 | expiration_time = |
623 | GNUNET_TIME_relative_to_absolute(minimum_expiration_time); | 627 | GNUNET_TIME_relative_to_absolute (minimum_expiration_time); |
624 | dst_len = sizeof(dst); | 628 | dst_len = sizeof(dst); |
625 | off = 0; | 629 | off = 0; |
626 | switch (rec->type) | 630 | switch (rec->type) |
631 | { | ||
632 | case GNUNET_DNSPARSER_TYPE_A: | ||
633 | if (sizeof(struct in_addr) != rec->data.raw.data_len) | ||
627 | { | 634 | { |
628 | case GNUNET_DNSPARSER_TYPE_A: | 635 | GNUNET_break (0); |
629 | if (sizeof(struct in_addr) != rec->data.raw.data_len) | 636 | return; |
630 | { | 637 | } |
631 | GNUNET_break(0); | 638 | if (NULL == inet_ntop (AF_INET, rec->data.raw.data, ip, ip_size)) |
632 | return; | 639 | { |
633 | } | 640 | GNUNET_break (0); |
634 | if (NULL == inet_ntop(AF_INET, rec->data.raw.data, ip, ip_size)) | 641 | return; |
635 | { | 642 | } |
636 | GNUNET_break(0); | 643 | if ((GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst, |
637 | return; | 644 | dst_len, |
638 | } | 645 | &off, |
639 | if ((GNUNET_OK == GNUNET_DNSPARSER_builder_add_name(dst, | 646 | gc->req->hostname)) && |
640 | dst_len, | 647 | (GNUNET_OK == |
641 | &off, | 648 | GNUNET_DNSPARSER_builder_add_name (dst, dst_len, &off, ip))) |
642 | gc->req->hostname)) && | 649 | { |
643 | (GNUNET_OK == | 650 | add_record (gc->req, |
644 | GNUNET_DNSPARSER_builder_add_name(dst, dst_len, &off, ip))) | 651 | GNUNET_GNSRECORD_TYPE_GNS2DNS, |
645 | { | 652 | expiration_time, |
646 | add_record(gc->req, | 653 | dst, |
647 | GNUNET_GNSRECORD_TYPE_GNS2DNS, | 654 | off); |
648 | expiration_time, | 655 | gc->found = GNUNET_YES; |
649 | dst, | 656 | } |
650 | off); | 657 | break; |
651 | gc->found = GNUNET_YES; | ||
652 | } | ||
653 | break; | ||
654 | |||
655 | case GNUNET_DNSPARSER_TYPE_AAAA: | ||
656 | if (sizeof(struct in6_addr) != rec->data.raw.data_len) | ||
657 | { | ||
658 | GNUNET_break(0); | ||
659 | return; | ||
660 | } | ||
661 | if (NULL == inet_ntop(AF_INET6, rec->data.raw.data, ip, ip_size)) | ||
662 | { | ||
663 | GNUNET_break(0); | ||
664 | return; | ||
665 | } | ||
666 | if ((GNUNET_OK == GNUNET_DNSPARSER_builder_add_name(dst, | ||
667 | dst_len, | ||
668 | &off, | ||
669 | gc->req->hostname)) && | ||
670 | (GNUNET_OK == | ||
671 | GNUNET_DNSPARSER_builder_add_name(dst, dst_len, &off, ip))) | ||
672 | { | ||
673 | add_record(gc->req, | ||
674 | GNUNET_GNSRECORD_TYPE_GNS2DNS, | ||
675 | expiration_time, | ||
676 | dst, | ||
677 | off); | ||
678 | gc->found = GNUNET_YES; | ||
679 | } | ||
680 | break; | ||
681 | 658 | ||
682 | case GNUNET_DNSPARSER_TYPE_CNAME: | 659 | case GNUNET_DNSPARSER_TYPE_AAAA: |
683 | if ((GNUNET_OK == GNUNET_DNSPARSER_builder_add_name(dst, | 660 | if (sizeof(struct in6_addr) != rec->data.raw.data_len) |
684 | dst_len, | 661 | { |
685 | &off, | 662 | GNUNET_break (0); |
686 | gc->req->hostname)) && | 663 | return; |
687 | (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name(dst, | 664 | } |
688 | dst_len, | 665 | if (NULL == inet_ntop (AF_INET6, rec->data.raw.data, ip, ip_size)) |
689 | &off, | 666 | { |
690 | rec->data.hostname))) | 667 | GNUNET_break (0); |
691 | { | 668 | return; |
692 | add_record(gc->req, | 669 | } |
693 | GNUNET_GNSRECORD_TYPE_GNS2DNS, | 670 | if ((GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst, |
694 | expiration_time, | 671 | dst_len, |
695 | dst, | 672 | &off, |
696 | off); | 673 | gc->req->hostname)) && |
697 | gc->found = GNUNET_YES; | 674 | (GNUNET_OK == |
698 | } | 675 | GNUNET_DNSPARSER_builder_add_name (dst, dst_len, &off, ip))) |
699 | break; | 676 | { |
677 | add_record (gc->req, | ||
678 | GNUNET_GNSRECORD_TYPE_GNS2DNS, | ||
679 | expiration_time, | ||
680 | dst, | ||
681 | off); | ||
682 | gc->found = GNUNET_YES; | ||
683 | } | ||
684 | break; | ||
700 | 685 | ||
701 | default: | 686 | case GNUNET_DNSPARSER_TYPE_CNAME: |
702 | /* useless, do nothing */ | 687 | if ((GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst, |
703 | break; | 688 | dst_len, |
689 | &off, | ||
690 | gc->req->hostname)) && | ||
691 | (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst, | ||
692 | dst_len, | ||
693 | &off, | ||
694 | rec->data.hostname))) | ||
695 | { | ||
696 | add_record (gc->req, | ||
697 | GNUNET_GNSRECORD_TYPE_GNS2DNS, | ||
698 | expiration_time, | ||
699 | dst, | ||
700 | off); | ||
701 | gc->found = GNUNET_YES; | ||
704 | } | 702 | } |
703 | break; | ||
704 | |||
705 | default: | ||
706 | /* useless, do nothing */ | ||
707 | break; | ||
708 | } | ||
705 | } | 709 | } |
706 | 710 | ||
707 | 711 | ||
708 | /** | 712 | /** |
709 | * Closure for #process_record(). | 713 | * Closure for #process_record(). |
710 | */ | 714 | */ |
711 | struct ProcessRecordContext { | 715 | struct ProcessRecordContext |
716 | { | ||
712 | /** | 717 | /** |
713 | * Answer we got back and are currently parsing, or NULL | 718 | * Answer we got back and are currently parsing, or NULL |
714 | * if not active. | 719 | * if not active. |
@@ -729,7 +734,7 @@ struct ProcessRecordContext { | |||
729 | * @param rec response | 734 | * @param rec response |
730 | */ | 735 | */ |
731 | static void | 736 | static void |
732 | process_record(void *cls, const struct GNUNET_DNSPARSER_Record *rec) | 737 | process_record (void *cls, const struct GNUNET_DNSPARSER_Record *rec) |
733 | { | 738 | { |
734 | struct ProcessRecordContext *prc = cls; | 739 | struct ProcessRecordContext *prc = cls; |
735 | struct Request *req = prc->req; | 740 | struct Request *req = prc->req; |
@@ -742,180 +747,180 @@ process_record(void *cls, const struct GNUNET_DNSPARSER_Record *rec) | |||
742 | dst_len = sizeof(dst); | 747 | dst_len = sizeof(dst); |
743 | off = 0; | 748 | off = 0; |
744 | records++; | 749 | records++; |
745 | if (0 != strcasecmp(rec->name, req->hostname)) | 750 | if (0 != strcasecmp (rec->name, req->hostname)) |
746 | { | 751 | { |
747 | GNUNET_log( | 752 | GNUNET_log ( |
748 | GNUNET_ERROR_TYPE_DEBUG, | 753 | GNUNET_ERROR_TYPE_DEBUG, |
749 | "DNS returned record from zone `%s' of type %u while resolving `%s'\n", | 754 | "DNS returned record from zone `%s' of type %u while resolving `%s'\n", |
750 | rec->name, | 755 | rec->name, |
751 | (unsigned int)rec->type, | 756 | (unsigned int) rec->type, |
752 | req->hostname); | 757 | req->hostname); |
753 | return; /* does not match hostname, might be glue, but | 758 | return; /* does not match hostname, might be glue, but |
754 | not useful for this pass! */ | 759 | not useful for this pass! */ |
755 | } | 760 | } |
756 | expiration_time = rec->expiration_time; | 761 | expiration_time = rec->expiration_time; |
757 | left = GNUNET_TIME_absolute_get_remaining(expiration_time); | 762 | left = GNUNET_TIME_absolute_get_remaining (expiration_time); |
758 | if (0 == left.rel_value_us) | 763 | if (0 == left.rel_value_us) |
759 | { | 764 | { |
760 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 765 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
761 | "DNS returned expired record for `%s'\n", | 766 | "DNS returned expired record for `%s'\n", |
762 | req->hostname); | 767 | req->hostname); |
763 | GNUNET_STATISTICS_update(stats, | 768 | GNUNET_STATISTICS_update (stats, |
764 | "# expired records obtained from DNS", | 769 | "# expired records obtained from DNS", |
765 | 1, | 770 | 1, |
766 | GNUNET_NO); | 771 | GNUNET_NO); |
767 | return; /* record expired */ | 772 | return; /* record expired */ |
768 | } | 773 | } |
769 | 774 | ||
770 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 775 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
771 | "DNS returned record that expires at %s for `%s'\n", | 776 | "DNS returned record that expires at %s for `%s'\n", |
772 | GNUNET_STRINGS_absolute_time_to_string(expiration_time), | 777 | GNUNET_STRINGS_absolute_time_to_string (expiration_time), |
773 | req->hostname); | 778 | req->hostname); |
774 | /* if expiration window is too short, bump it to configured minimum */ | 779 | /* if expiration window is too short, bump it to configured minimum */ |
775 | if (left.rel_value_us < minimum_expiration_time.rel_value_us) | 780 | if (left.rel_value_us < minimum_expiration_time.rel_value_us) |
776 | expiration_time = | 781 | expiration_time = |
777 | GNUNET_TIME_relative_to_absolute(minimum_expiration_time); | 782 | GNUNET_TIME_relative_to_absolute (minimum_expiration_time); |
778 | switch (rec->type) | 783 | switch (rec->type) |
779 | { | 784 | { |
780 | case GNUNET_DNSPARSER_TYPE_NS: { | 785 | case GNUNET_DNSPARSER_TYPE_NS: { |
781 | struct GlueClosure gc; | 786 | struct GlueClosure gc; |
782 | 787 | ||
783 | /* check for glue */ | 788 | /* check for glue */ |
784 | gc.req = req; | 789 | gc.req = req; |
785 | gc.ns = rec->data.hostname; | 790 | gc.ns = rec->data.hostname; |
786 | gc.found = GNUNET_NO; | 791 | gc.found = GNUNET_NO; |
787 | for_all_records(prc->p, &check_for_glue, &gc); | 792 | for_all_records (prc->p, &check_for_glue, &gc); |
788 | if ((GNUNET_NO == gc.found) && | 793 | if ((GNUNET_NO == gc.found) && |
789 | (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name(dst, | 794 | (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst, |
790 | dst_len, | 795 | dst_len, |
791 | &off, | 796 | &off, |
792 | req->hostname)) && | 797 | req->hostname)) && |
793 | (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name(dst, | 798 | (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst, |
794 | dst_len, | 799 | dst_len, |
795 | &off, | 800 | &off, |
796 | rec->data.hostname))) | 801 | rec->data.hostname))) |
797 | { | 802 | { |
798 | /* FIXME: actually check if this is out-of-bailiwick, | 803 | /* FIXME: actually check if this is out-of-bailiwick, |
799 | and if not request explicit resolution... */ | 804 | and if not request explicit resolution... */ |
800 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 805 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
801 | "Converted OOB (`%s') NS record for `%s'\n", | 806 | "Converted OOB (`%s') NS record for `%s'\n", |
802 | rec->data.hostname, | 807 | rec->data.hostname, |
803 | rec->name); | 808 | rec->name); |
804 | add_record(req, | 809 | add_record (req, |
805 | GNUNET_GNSRECORD_TYPE_GNS2DNS, | 810 | GNUNET_GNSRECORD_TYPE_GNS2DNS, |
806 | expiration_time, | 811 | expiration_time, |
807 | dst, | 812 | dst, |
808 | off); | 813 | off); |
809 | } | 814 | } |
810 | else | 815 | else |
811 | { | 816 | { |
812 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 817 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
813 | "Converted NS record for `%s' using glue\n", | 818 | "Converted NS record for `%s' using glue\n", |
814 | rec->name); | 819 | rec->name); |
815 | } | 820 | } |
816 | break; | 821 | break; |
817 | } | 822 | } |
818 | 823 | ||
819 | case GNUNET_DNSPARSER_TYPE_CNAME: | 824 | case GNUNET_DNSPARSER_TYPE_CNAME: |
820 | if (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name(dst, | 825 | if (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst, |
821 | dst_len, | 826 | dst_len, |
822 | &off, | 827 | &off, |
823 | rec->data.hostname)) | 828 | rec->data.hostname)) |
824 | { | 829 | { |
825 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 830 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
826 | "Converting CNAME (`%s') record for `%s'\n", | 831 | "Converting CNAME (`%s') record for `%s'\n", |
827 | rec->data.hostname, | 832 | rec->data.hostname, |
828 | rec->name); | 833 | rec->name); |
829 | add_record(req, rec->type, expiration_time, dst, off); | 834 | add_record (req, rec->type, expiration_time, dst, off); |
830 | } | 835 | } |
831 | break; | 836 | break; |
832 | 837 | ||
833 | case GNUNET_DNSPARSER_TYPE_DNAME: | 838 | case GNUNET_DNSPARSER_TYPE_DNAME: |
834 | /* No support for DNAME in GNS yet! FIXME: support later! */ | 839 | /* No support for DNAME in GNS yet! FIXME: support later! */ |
835 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 840 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
836 | "FIXME: not supported: %s DNAME %s\n", | 841 | "FIXME: not supported: %s DNAME %s\n", |
837 | rec->name, | 842 | rec->name, |
838 | rec->data.hostname); | 843 | rec->data.hostname); |
839 | break; | 844 | break; |
840 | 845 | ||
841 | case GNUNET_DNSPARSER_TYPE_MX: | 846 | case GNUNET_DNSPARSER_TYPE_MX: |
842 | if (GNUNET_OK == | 847 | if (GNUNET_OK == |
843 | GNUNET_DNSPARSER_builder_add_mx(dst, dst_len, &off, rec->data.mx)) | 848 | GNUNET_DNSPARSER_builder_add_mx (dst, dst_len, &off, rec->data.mx)) |
844 | { | 849 | { |
845 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 850 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
846 | "Converting MX (`%s') record for `%s'\n", | 851 | "Converting MX (`%s') record for `%s'\n", |
847 | rec->data.mx->mxhost, | 852 | rec->data.mx->mxhost, |
848 | rec->name); | 853 | rec->name); |
849 | add_record(req, rec->type, expiration_time, dst, off); | 854 | add_record (req, rec->type, expiration_time, dst, off); |
850 | } | 855 | } |
851 | break; | 856 | break; |
852 | |||
853 | case GNUNET_DNSPARSER_TYPE_SOA: | ||
854 | if (GNUNET_OK == | ||
855 | GNUNET_DNSPARSER_builder_add_soa(dst, dst_len, &off, rec->data.soa)) | ||
856 | { | ||
857 | /* NOTE: GNS does not really use SOAs */ | ||
858 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
859 | "Converting SOA record for `%s'\n", | ||
860 | rec->name); | ||
861 | add_record(req, rec->type, expiration_time, dst, off); | ||
862 | } | ||
863 | break; | ||
864 | 857 | ||
865 | case GNUNET_DNSPARSER_TYPE_SRV: | 858 | case GNUNET_DNSPARSER_TYPE_SOA: |
866 | if (GNUNET_OK == | 859 | if (GNUNET_OK == |
867 | GNUNET_DNSPARSER_builder_add_srv(dst, dst_len, &off, rec->data.srv)) | 860 | GNUNET_DNSPARSER_builder_add_soa (dst, dst_len, &off, rec->data.soa)) |
868 | { | 861 | { |
869 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 862 | /* NOTE: GNS does not really use SOAs */ |
870 | "Converting SRV record for `%s'\n", | 863 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
871 | rec->name); | 864 | "Converting SOA record for `%s'\n", |
872 | add_record(req, rec->type, expiration_time, dst, off); | 865 | rec->name); |
873 | } | 866 | add_record (req, rec->type, expiration_time, dst, off); |
874 | break; | 867 | } |
868 | break; | ||
875 | 869 | ||
876 | case GNUNET_DNSPARSER_TYPE_PTR: | 870 | case GNUNET_DNSPARSER_TYPE_SRV: |
877 | if (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name(dst, | 871 | if (GNUNET_OK == |
878 | dst_len, | 872 | GNUNET_DNSPARSER_builder_add_srv (dst, dst_len, &off, rec->data.srv)) |
879 | &off, | 873 | { |
880 | rec->data.hostname)) | 874 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
881 | { | 875 | "Converting SRV record for `%s'\n", |
882 | /* !?: what does a PTR record do in a regular TLD??? */ | 876 | rec->name); |
883 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 877 | add_record (req, rec->type, expiration_time, dst, off); |
884 | "Converting PTR record for `%s' (weird)\n", | 878 | } |
885 | rec->name); | 879 | break; |
886 | add_record(req, rec->type, expiration_time, dst, off); | ||
887 | } | ||
888 | break; | ||
889 | 880 | ||
890 | case GNUNET_DNSPARSER_TYPE_CERT: | 881 | case GNUNET_DNSPARSER_TYPE_PTR: |
891 | if (GNUNET_OK == | 882 | if (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst, |
892 | GNUNET_DNSPARSER_builder_add_cert(dst, dst_len, &off, rec->data.cert)) | 883 | dst_len, |
893 | { | 884 | &off, |
894 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 885 | rec->data.hostname)) |
895 | "Converting CERT record for `%s'\n", | 886 | { |
896 | rec->name); | 887 | /* !?: what does a PTR record do in a regular TLD??? */ |
897 | add_record(req, rec->type, expiration_time, dst, off); | 888 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
898 | } | 889 | "Converting PTR record for `%s' (weird)\n", |
899 | break; | 890 | rec->name); |
891 | add_record (req, rec->type, expiration_time, dst, off); | ||
892 | } | ||
893 | break; | ||
900 | 894 | ||
901 | /* Rest is 'raw' encoded and just needs to be copied IF | 895 | case GNUNET_DNSPARSER_TYPE_CERT: |
902 | the hostname matches the requested name; otherwise we | 896 | if (GNUNET_OK == |
903 | simply cannot use it. */ | 897 | GNUNET_DNSPARSER_builder_add_cert (dst, dst_len, &off, rec->data.cert)) |
904 | case GNUNET_DNSPARSER_TYPE_A: | 898 | { |
905 | case GNUNET_DNSPARSER_TYPE_AAAA: | 899 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
906 | case GNUNET_DNSPARSER_TYPE_TXT: | 900 | "Converting CERT record for `%s'\n", |
907 | default: | 901 | rec->name); |
908 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 902 | add_record (req, rec->type, expiration_time, dst, off); |
909 | "Converting record of type %u for `%s'\n", | ||
910 | (unsigned int)rec->type, | ||
911 | rec->name); | ||
912 | add_record(req, | ||
913 | rec->type, | ||
914 | expiration_time, | ||
915 | rec->data.raw.data, | ||
916 | rec->data.raw.data_len); | ||
917 | break; | ||
918 | } | 903 | } |
904 | break; | ||
905 | |||
906 | /* Rest is 'raw' encoded and just needs to be copied IF | ||
907 | the hostname matches the requested name; otherwise we | ||
908 | simply cannot use it. */ | ||
909 | case GNUNET_DNSPARSER_TYPE_A: | ||
910 | case GNUNET_DNSPARSER_TYPE_AAAA: | ||
911 | case GNUNET_DNSPARSER_TYPE_TXT: | ||
912 | default: | ||
913 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
914 | "Converting record of type %u for `%s'\n", | ||
915 | (unsigned int) rec->type, | ||
916 | rec->name); | ||
917 | add_record (req, | ||
918 | rec->type, | ||
919 | expiration_time, | ||
920 | rec->data.raw.data, | ||
921 | rec->data.raw.data_len); | ||
922 | break; | ||
923 | } | ||
919 | } | 924 | } |
920 | 925 | ||
921 | 926 | ||
@@ -930,89 +935,89 @@ process_record(void *cls, const struct GNUNET_DNSPARSER_Record *rec) | |||
930 | * @param emsg NULL on success, otherwise an error message | 935 | * @param emsg NULL on success, otherwise an error message |
931 | */ | 936 | */ |
932 | static void | 937 | static void |
933 | store_completed_cb(void *cls, int32_t success, const char *emsg) | 938 | store_completed_cb (void *cls, int32_t success, const char *emsg) |
934 | { | 939 | { |
935 | static struct GNUNET_TIME_Absolute last; | 940 | static struct GNUNET_TIME_Absolute last; |
936 | struct Request *req = cls; | 941 | struct Request *req = cls; |
937 | 942 | ||
938 | req->qe = NULL; | 943 | req->qe = NULL; |
939 | if (GNUNET_SYSERR == success) | 944 | if (GNUNET_SYSERR == success) |
940 | { | 945 | { |
941 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 946 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
942 | "Failed to store zone data for `%s': %s\n", | 947 | "Failed to store zone data for `%s': %s\n", |
943 | req->hostname, | 948 | req->hostname, |
944 | emsg); | 949 | emsg); |
945 | } | 950 | } |
946 | else | 951 | else |
947 | { | 952 | { |
948 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 953 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
949 | "Stored records under `%s' (%d)\n", | 954 | "Stored records under `%s' (%d)\n", |
950 | req->hostname, | 955 | req->hostname, |
951 | success); | 956 | success); |
952 | } | 957 | } |
953 | total_reg_proc_dns_ns++; /* finished regular processing */ | 958 | total_reg_proc_dns_ns++; /* finished regular processing */ |
954 | pending_rs--; | 959 | pending_rs--; |
955 | free_records(req); | 960 | free_records (req); |
956 | /* compute NAMESTORE statistics */ | 961 | /* compute NAMESTORE statistics */ |
957 | { | 962 | { |
958 | static uint64_t total_ns_latency_cnt; | 963 | static uint64_t total_ns_latency_cnt; |
959 | static struct GNUNET_TIME_Relative total_ns_latency; | 964 | static struct GNUNET_TIME_Relative total_ns_latency; |
960 | struct GNUNET_TIME_Relative ns_latency; | 965 | struct GNUNET_TIME_Relative ns_latency; |
961 | 966 | ||
962 | ns_latency = GNUNET_TIME_absolute_get_duration(req->op_start_time); | 967 | ns_latency = GNUNET_TIME_absolute_get_duration (req->op_start_time); |
963 | total_ns_latency = GNUNET_TIME_relative_add(total_ns_latency, ns_latency); | 968 | total_ns_latency = GNUNET_TIME_relative_add (total_ns_latency, ns_latency); |
964 | if (0 == total_ns_latency_cnt) | 969 | if (0 == total_ns_latency_cnt) |
965 | last = GNUNET_TIME_absolute_get(); | 970 | last = GNUNET_TIME_absolute_get (); |
966 | total_ns_latency_cnt++; | 971 | total_ns_latency_cnt++; |
967 | if (0 == (total_ns_latency_cnt % 1000)) | 972 | if (0 == (total_ns_latency_cnt % 1000)) |
968 | { | 973 | { |
969 | struct GNUNET_TIME_Relative delta; | 974 | struct GNUNET_TIME_Relative delta; |
970 | 975 | ||
971 | delta = GNUNET_TIME_absolute_get_duration(last); | 976 | delta = GNUNET_TIME_absolute_get_duration (last); |
972 | last = GNUNET_TIME_absolute_get(); | 977 | last = GNUNET_TIME_absolute_get (); |
973 | fprintf(stderr, | 978 | fprintf (stderr, |
974 | "Processed 1000 records in %s\n", | 979 | "Processed 1000 records in %s\n", |
975 | GNUNET_STRINGS_relative_time_to_string(delta, GNUNET_YES)); | 980 | GNUNET_STRINGS_relative_time_to_string (delta, GNUNET_YES)); |
976 | GNUNET_STATISTICS_set(stats, | 981 | GNUNET_STATISTICS_set (stats, |
977 | "# average NAMESTORE PUT latency (μs)", | 982 | "# average NAMESTORE PUT latency (μs)", |
978 | total_ns_latency.rel_value_us / | 983 | total_ns_latency.rel_value_us |
979 | total_ns_latency_cnt, | 984 | / total_ns_latency_cnt, |
980 | GNUNET_NO); | 985 | GNUNET_NO); |
981 | } | 986 | } |
982 | } | 987 | } |
983 | /* compute and publish overall velocity */ | 988 | /* compute and publish overall velocity */ |
984 | if (0 == (total_reg_proc_dns_ns % 100)) | 989 | if (0 == (total_reg_proc_dns_ns % 100)) |
985 | { | 990 | { |
986 | struct GNUNET_TIME_Relative runtime; | 991 | struct GNUNET_TIME_Relative runtime; |
987 | 992 | ||
988 | runtime = GNUNET_TIME_absolute_get_duration(start_time_reg_proc); | 993 | runtime = GNUNET_TIME_absolute_get_duration (start_time_reg_proc); |
989 | runtime = GNUNET_TIME_relative_subtract(runtime, idle_time); | 994 | runtime = GNUNET_TIME_relative_subtract (runtime, idle_time); |
990 | runtime = | 995 | runtime = |
991 | GNUNET_TIME_relative_divide(runtime, | 996 | GNUNET_TIME_relative_divide (runtime, |
992 | total_reg_proc_dns + total_reg_proc_dns_ns); | 997 | total_reg_proc_dns + total_reg_proc_dns_ns); |
993 | GNUNET_STATISTICS_set(stats, | 998 | GNUNET_STATISTICS_set (stats, |
994 | "# Regular processing completed without NAMESTORE", | 999 | "# Regular processing completed without NAMESTORE", |
995 | total_reg_proc_dns, | 1000 | total_reg_proc_dns, |
996 | GNUNET_NO); | 1001 | GNUNET_NO); |
997 | GNUNET_STATISTICS_set(stats, | 1002 | GNUNET_STATISTICS_set (stats, |
998 | "# Regular processing completed with NAMESTORE PUT", | 1003 | "# Regular processing completed with NAMESTORE PUT", |
999 | total_reg_proc_dns_ns, | 1004 | total_reg_proc_dns_ns, |
1000 | GNUNET_NO); | 1005 | GNUNET_NO); |
1001 | GNUNET_STATISTICS_set(stats, | 1006 | GNUNET_STATISTICS_set (stats, |
1002 | "# average request processing latency (μs)", | 1007 | "# average request processing latency (μs)", |
1003 | runtime.rel_value_us, | 1008 | runtime.rel_value_us, |
1004 | GNUNET_NO); | 1009 | GNUNET_NO); |
1005 | GNUNET_STATISTICS_set(stats, | 1010 | GNUNET_STATISTICS_set (stats, |
1006 | "# total time spent idle (μs)", | 1011 | "# total time spent idle (μs)", |
1007 | idle_time.rel_value_us, | 1012 | idle_time.rel_value_us, |
1008 | GNUNET_NO); | 1013 | GNUNET_NO); |
1009 | } | 1014 | } |
1010 | 1015 | ||
1011 | if (NULL == t) | 1016 | if (NULL == t) |
1012 | { | 1017 | { |
1013 | sleep_time_reg_proc = GNUNET_TIME_absolute_get(); | 1018 | sleep_time_reg_proc = GNUNET_TIME_absolute_get (); |
1014 | t = GNUNET_SCHEDULER_add_now(&process_queue, NULL); | 1019 | t = GNUNET_SCHEDULER_add_now (&process_queue, NULL); |
1015 | } | 1020 | } |
1016 | } | 1021 | } |
1017 | 1022 | ||
1018 | 1023 | ||
@@ -1024,148 +1029,148 @@ store_completed_cb(void *cls, int32_t success, const char *emsg) | |||
1024 | * @param dns_len number of bytes in @a dns | 1029 | * @param dns_len number of bytes in @a dns |
1025 | */ | 1030 | */ |
1026 | static void | 1031 | static void |
1027 | process_result(void *cls, | 1032 | process_result (void *cls, |
1028 | const struct GNUNET_TUN_DnsHeader *dns, | 1033 | const struct GNUNET_TUN_DnsHeader *dns, |
1029 | size_t dns_len) | 1034 | size_t dns_len) |
1030 | { | 1035 | { |
1031 | struct Request *req = cls; | 1036 | struct Request *req = cls; |
1032 | struct Record *rec; | 1037 | struct Record *rec; |
1033 | struct GNUNET_DNSPARSER_Packet *p; | 1038 | struct GNUNET_DNSPARSER_Packet *p; |
1034 | unsigned int rd_count; | 1039 | unsigned int rd_count; |
1035 | 1040 | ||
1036 | GNUNET_assert(NULL == req->hn); | 1041 | GNUNET_assert (NULL == req->hn); |
1037 | if (NULL == dns) | 1042 | if (NULL == dns) |
1043 | { | ||
1044 | /* stub gave up */ | ||
1045 | GNUNET_CONTAINER_DLL_remove (req_head, req_tail, req); | ||
1046 | pending--; | ||
1047 | if (NULL == t) | ||
1038 | { | 1048 | { |
1039 | /* stub gave up */ | 1049 | sleep_time_reg_proc = GNUNET_TIME_absolute_get (); |
1040 | GNUNET_CONTAINER_DLL_remove(req_head, req_tail, req); | 1050 | t = GNUNET_SCHEDULER_add_now (&process_queue, NULL); |
1041 | pending--; | ||
1042 | if (NULL == t) | ||
1043 | { | ||
1044 | sleep_time_reg_proc = GNUNET_TIME_absolute_get(); | ||
1045 | t = GNUNET_SCHEDULER_add_now(&process_queue, NULL); | ||
1046 | } | ||
1047 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
1048 | "Stub gave up on DNS reply for `%s'\n", | ||
1049 | req->hostname); | ||
1050 | GNUNET_STATISTICS_update(stats, "# DNS lookups timed out", 1, GNUNET_NO); | ||
1051 | if (req->issue_num > MAX_RETRIES) | ||
1052 | { | ||
1053 | failures++; | ||
1054 | free_request(req); | ||
1055 | GNUNET_STATISTICS_update(stats, "# requests given up on", 1, GNUNET_NO); | ||
1056 | return; | ||
1057 | } | ||
1058 | total_reg_proc_dns++; | ||
1059 | req->rs = NULL; | ||
1060 | insert_sorted(req); | ||
1061 | return; | ||
1062 | } | 1051 | } |
1063 | if (req->id != dns->id) | 1052 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1053 | "Stub gave up on DNS reply for `%s'\n", | ||
1054 | req->hostname); | ||
1055 | GNUNET_STATISTICS_update (stats, "# DNS lookups timed out", 1, GNUNET_NO); | ||
1056 | if (req->issue_num > MAX_RETRIES) | ||
1064 | { | 1057 | { |
1065 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1058 | failures++; |
1066 | "DNS ID did not match request, ignoring reply\n"); | 1059 | free_request (req); |
1067 | GNUNET_STATISTICS_update(stats, "# DNS ID mismatches", 1, GNUNET_NO); | 1060 | GNUNET_STATISTICS_update (stats, "# requests given up on", 1, GNUNET_NO); |
1068 | return; | 1061 | return; |
1069 | } | 1062 | } |
1070 | GNUNET_CONTAINER_DLL_remove(req_head, req_tail, req); | 1063 | total_reg_proc_dns++; |
1071 | GNUNET_DNSSTUB_resolve_cancel(req->rs); | 1064 | req->rs = NULL; |
1065 | insert_sorted (req); | ||
1066 | return; | ||
1067 | } | ||
1068 | if (req->id != dns->id) | ||
1069 | { | ||
1070 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1071 | "DNS ID did not match request, ignoring reply\n"); | ||
1072 | GNUNET_STATISTICS_update (stats, "# DNS ID mismatches", 1, GNUNET_NO); | ||
1073 | return; | ||
1074 | } | ||
1075 | GNUNET_CONTAINER_DLL_remove (req_head, req_tail, req); | ||
1076 | GNUNET_DNSSTUB_resolve_cancel (req->rs); | ||
1072 | req->rs = NULL; | 1077 | req->rs = NULL; |
1073 | pending--; | 1078 | pending--; |
1074 | p = GNUNET_DNSPARSER_parse((const char *)dns, dns_len); | 1079 | p = GNUNET_DNSPARSER_parse ((const char *) dns, dns_len); |
1075 | if (NULL == p) | 1080 | if (NULL == p) |
1081 | { | ||
1082 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1083 | "Failed to parse DNS reply for `%s'\n", | ||
1084 | req->hostname); | ||
1085 | GNUNET_STATISTICS_update (stats, "# DNS parser errors", 1, GNUNET_NO); | ||
1086 | if (NULL == t) | ||
1076 | { | 1087 | { |
1077 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1088 | sleep_time_reg_proc = GNUNET_TIME_absolute_get (); |
1078 | "Failed to parse DNS reply for `%s'\n", | 1089 | t = GNUNET_SCHEDULER_add_now (&process_queue, NULL); |
1079 | req->hostname); | 1090 | } |
1080 | GNUNET_STATISTICS_update(stats, "# DNS parser errors", 1, GNUNET_NO); | 1091 | if (req->issue_num > MAX_RETRIES) |
1081 | if (NULL == t) | 1092 | { |
1082 | { | 1093 | failures++; |
1083 | sleep_time_reg_proc = GNUNET_TIME_absolute_get(); | 1094 | free_request (req); |
1084 | t = GNUNET_SCHEDULER_add_now(&process_queue, NULL); | 1095 | GNUNET_STATISTICS_update (stats, "# requests given up on", 1, GNUNET_NO); |
1085 | } | ||
1086 | if (req->issue_num > MAX_RETRIES) | ||
1087 | { | ||
1088 | failures++; | ||
1089 | free_request(req); | ||
1090 | GNUNET_STATISTICS_update(stats, "# requests given up on", 1, GNUNET_NO); | ||
1091 | return; | ||
1092 | } | ||
1093 | insert_sorted(req); | ||
1094 | return; | 1096 | return; |
1095 | } | 1097 | } |
1098 | insert_sorted (req); | ||
1099 | return; | ||
1100 | } | ||
1096 | /* import new records */ | 1101 | /* import new records */ |
1097 | req->issue_num = 0; /* success, reset counter! */ | 1102 | req->issue_num = 0; /* success, reset counter! */ |
1098 | { | 1103 | { |
1099 | struct ProcessRecordContext prc = { .req = req, .p = p }; | 1104 | struct ProcessRecordContext prc = { .req = req, .p = p }; |
1100 | 1105 | ||
1101 | for_all_records(p, &process_record, &prc); | 1106 | for_all_records (p, &process_record, &prc); |
1102 | } | 1107 | } |
1103 | GNUNET_DNSPARSER_free_packet(p); | 1108 | GNUNET_DNSPARSER_free_packet (p); |
1104 | /* count records found, determine minimum expiration time */ | 1109 | /* count records found, determine minimum expiration time */ |
1105 | req->expires = GNUNET_TIME_UNIT_FOREVER_ABS; | 1110 | req->expires = GNUNET_TIME_UNIT_FOREVER_ABS; |
1106 | { | 1111 | { |
1107 | struct GNUNET_TIME_Relative dns_latency; | 1112 | struct GNUNET_TIME_Relative dns_latency; |
1108 | 1113 | ||
1109 | dns_latency = GNUNET_TIME_absolute_get_duration(req->op_start_time); | 1114 | dns_latency = GNUNET_TIME_absolute_get_duration (req->op_start_time); |
1110 | total_dns_latency = | 1115 | total_dns_latency = |
1111 | GNUNET_TIME_relative_add(total_dns_latency, dns_latency); | 1116 | GNUNET_TIME_relative_add (total_dns_latency, dns_latency); |
1112 | total_dns_latency_cnt++; | 1117 | total_dns_latency_cnt++; |
1113 | if (0 == (total_dns_latency_cnt % 1000)) | 1118 | if (0 == (total_dns_latency_cnt % 1000)) |
1114 | { | 1119 | { |
1115 | GNUNET_STATISTICS_set(stats, | 1120 | GNUNET_STATISTICS_set (stats, |
1116 | "# average DNS lookup latency (μs)", | 1121 | "# average DNS lookup latency (μs)", |
1117 | total_dns_latency.rel_value_us / | 1122 | total_dns_latency.rel_value_us |
1118 | total_dns_latency_cnt, | 1123 | / total_dns_latency_cnt, |
1119 | GNUNET_NO); | 1124 | GNUNET_NO); |
1120 | } | 1125 | } |
1121 | } | 1126 | } |
1122 | rd_count = 0; | 1127 | rd_count = 0; |
1123 | for (rec = req->rec_head; NULL != rec; rec = rec->next) | 1128 | for (rec = req->rec_head; NULL != rec; rec = rec->next) |
1124 | { | 1129 | { |
1125 | struct GNUNET_TIME_Absolute at; | 1130 | struct GNUNET_TIME_Absolute at; |
1126 | 1131 | ||
1127 | at.abs_value_us = rec->grd.expiration_time; | 1132 | at.abs_value_us = rec->grd.expiration_time; |
1128 | req->expires = GNUNET_TIME_absolute_min(req->expires, at); | 1133 | req->expires = GNUNET_TIME_absolute_min (req->expires, at); |
1129 | rd_count++; | 1134 | rd_count++; |
1130 | } | 1135 | } |
1131 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1136 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1132 | "Obtained %u records for `%s'\n", | 1137 | "Obtained %u records for `%s'\n", |
1133 | rd_count, | 1138 | rd_count, |
1134 | req->hostname); | 1139 | req->hostname); |
1135 | /* Instead of going for SOA, simplified for now to look each | 1140 | /* Instead of going for SOA, simplified for now to look each |
1136 | day in case we got an empty response */ | 1141 | day in case we got an empty response */ |
1137 | if (0 == rd_count) | 1142 | if (0 == rd_count) |
1138 | { | 1143 | { |
1139 | req->expires = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_DAYS); | 1144 | req->expires = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_DAYS); |
1140 | GNUNET_STATISTICS_update(stats, | 1145 | GNUNET_STATISTICS_update (stats, |
1141 | "# empty DNS replies (usually NXDOMAIN)", | 1146 | "# empty DNS replies (usually NXDOMAIN)", |
1142 | 1, | 1147 | 1, |
1143 | GNUNET_NO); | 1148 | GNUNET_NO); |
1144 | } | 1149 | } |
1145 | else | 1150 | else |
1146 | { | 1151 | { |
1147 | record_sets++; | 1152 | record_sets++; |
1148 | } | 1153 | } |
1149 | /* convert records to namestore import format */ | 1154 | /* convert records to namestore import format */ |
1150 | { | 1155 | { |
1151 | struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)]; | 1156 | struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL (rd_count)]; |
1152 | unsigned int off = 0; | 1157 | unsigned int off = 0; |
1153 | 1158 | ||
1154 | /* convert linked list into array */ | 1159 | /* convert linked list into array */ |
1155 | for (rec = req->rec_head; NULL != rec; rec = rec->next) | 1160 | for (rec = req->rec_head; NULL != rec; rec = rec->next) |
1156 | rd[off++] = rec->grd; | 1161 | rd[off++] = rec->grd; |
1157 | pending_rs++; | 1162 | pending_rs++; |
1158 | req->op_start_time = GNUNET_TIME_absolute_get(); | 1163 | req->op_start_time = GNUNET_TIME_absolute_get (); |
1159 | req->qe = GNUNET_NAMESTORE_records_store(ns, | 1164 | req->qe = GNUNET_NAMESTORE_records_store (ns, |
1160 | &req->zone->key, | 1165 | &req->zone->key, |
1161 | get_label(req), | 1166 | get_label (req), |
1162 | rd_count, | 1167 | rd_count, |
1163 | rd, | 1168 | rd, |
1164 | &store_completed_cb, | 1169 | &store_completed_cb, |
1165 | req); | 1170 | req); |
1166 | GNUNET_assert(NULL != req->qe); | 1171 | GNUNET_assert (NULL != req->qe); |
1167 | } | 1172 | } |
1168 | insert_sorted(req); | 1173 | insert_sorted (req); |
1169 | } | 1174 | } |
1170 | 1175 | ||
1171 | 1176 | ||
@@ -1175,7 +1180,7 @@ process_result(void *cls, | |||
1175 | * @param cls NULL | 1180 | * @param cls NULL |
1176 | */ | 1181 | */ |
1177 | static void | 1182 | static void |
1178 | process_queue(void *cls) | 1183 | process_queue (void *cls) |
1179 | { | 1184 | { |
1180 | struct Request *req; | 1185 | struct Request *req; |
1181 | unsigned int series; | 1186 | unsigned int series; |
@@ -1183,82 +1188,82 @@ process_queue(void *cls) | |||
1183 | size_t raw_size; | 1188 | size_t raw_size; |
1184 | struct GNUNET_TIME_Relative delay; | 1189 | struct GNUNET_TIME_Relative delay; |
1185 | 1190 | ||
1186 | (void)cls; | 1191 | (void) cls; |
1187 | delay = GNUNET_TIME_absolute_get_duration(sleep_time_reg_proc); | 1192 | delay = GNUNET_TIME_absolute_get_duration (sleep_time_reg_proc); |
1188 | idle_time = GNUNET_TIME_relative_add(idle_time, delay); | 1193 | idle_time = GNUNET_TIME_relative_add (idle_time, delay); |
1189 | series = 0; | 1194 | series = 0; |
1190 | t = NULL; | 1195 | t = NULL; |
1191 | while (pending + pending_rs < THRESH) | 1196 | while (pending + pending_rs < THRESH) |
1197 | { | ||
1198 | req = GNUNET_CONTAINER_heap_peek (req_heap); | ||
1199 | if (NULL == req) | ||
1200 | break; | ||
1201 | if (NULL != req->qe) | ||
1202 | return; /* namestore op still pending */ | ||
1203 | if (NULL != req->rs) | ||
1192 | { | 1204 | { |
1193 | req = GNUNET_CONTAINER_heap_peek(req_heap); | 1205 | GNUNET_break (0); |
1194 | if (NULL == req) | 1206 | return; /* already submitted */ |
1195 | break; | ||
1196 | if (NULL != req->qe) | ||
1197 | return; /* namestore op still pending */ | ||
1198 | if (NULL != req->rs) | ||
1199 | { | ||
1200 | GNUNET_break(0); | ||
1201 | return; /* already submitted */ | ||
1202 | } | ||
1203 | if (GNUNET_TIME_absolute_get_remaining(req->expires).rel_value_us > 0) | ||
1204 | break; | ||
1205 | GNUNET_assert(req == GNUNET_CONTAINER_heap_remove_root(req_heap)); | ||
1206 | req->hn = NULL; | ||
1207 | GNUNET_CONTAINER_DLL_insert(req_head, req_tail, req); | ||
1208 | GNUNET_assert(NULL == req->rs); | ||
1209 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
1210 | "Requesting resolution for `%s'\n", | ||
1211 | req->hostname); | ||
1212 | raw = build_dns_query(req, &raw_size); | ||
1213 | if (NULL == raw) | ||
1214 | { | ||
1215 | GNUNET_break(0); | ||
1216 | free_request(req); | ||
1217 | continue; | ||
1218 | } | ||
1219 | req->op_start_time = GNUNET_TIME_absolute_get(); | ||
1220 | req->rs = GNUNET_DNSSTUB_resolve(ctx, raw, raw_size, &process_result, req); | ||
1221 | GNUNET_assert(NULL != req->rs); | ||
1222 | req->issue_num++; | ||
1223 | lookups++; | ||
1224 | pending++; | ||
1225 | series++; | ||
1226 | if (series > MAX_SERIES) | ||
1227 | break; | ||
1228 | } | 1207 | } |
1229 | if (pending + pending_rs >= THRESH) | 1208 | if (GNUNET_TIME_absolute_get_remaining (req->expires).rel_value_us > 0) |
1209 | break; | ||
1210 | GNUNET_assert (req == GNUNET_CONTAINER_heap_remove_root (req_heap)); | ||
1211 | req->hn = NULL; | ||
1212 | GNUNET_CONTAINER_DLL_insert (req_head, req_tail, req); | ||
1213 | GNUNET_assert (NULL == req->rs); | ||
1214 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1215 | "Requesting resolution for `%s'\n", | ||
1216 | req->hostname); | ||
1217 | raw = build_dns_query (req, &raw_size); | ||
1218 | if (NULL == raw) | ||
1230 | { | 1219 | { |
1231 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1220 | GNUNET_break (0); |
1232 | "Stopped processing queue (%u+%u/%u)]\n", | 1221 | free_request (req); |
1233 | pending, | 1222 | continue; |
1234 | pending_rs, | ||
1235 | THRESH); | ||
1236 | return; /* wait for replies */ | ||
1237 | } | 1223 | } |
1238 | req = GNUNET_CONTAINER_heap_peek(req_heap); | 1224 | req->op_start_time = GNUNET_TIME_absolute_get (); |
1225 | req->rs = GNUNET_DNSSTUB_resolve (ctx, raw, raw_size, &process_result, req); | ||
1226 | GNUNET_assert (NULL != req->rs); | ||
1227 | req->issue_num++; | ||
1228 | lookups++; | ||
1229 | pending++; | ||
1230 | series++; | ||
1231 | if (series > MAX_SERIES) | ||
1232 | break; | ||
1233 | } | ||
1234 | if (pending + pending_rs >= THRESH) | ||
1235 | { | ||
1236 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1237 | "Stopped processing queue (%u+%u/%u)]\n", | ||
1238 | pending, | ||
1239 | pending_rs, | ||
1240 | THRESH); | ||
1241 | return; /* wait for replies */ | ||
1242 | } | ||
1243 | req = GNUNET_CONTAINER_heap_peek (req_heap); | ||
1239 | if (NULL == req) | 1244 | if (NULL == req) |
1240 | { | 1245 | { |
1241 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1246 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1242 | "Stopped processing queue: empty queue\n"); | 1247 | "Stopped processing queue: empty queue\n"); |
1243 | return; | 1248 | return; |
1244 | } | 1249 | } |
1245 | if (GNUNET_TIME_absolute_get_remaining(req->expires).rel_value_us > 0) | 1250 | if (GNUNET_TIME_absolute_get_remaining (req->expires).rel_value_us > 0) |
1246 | { | 1251 | { |
1247 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1252 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1248 | "Waiting until %s for next record (`%s') to expire\n", | 1253 | "Waiting until %s for next record (`%s') to expire\n", |
1249 | GNUNET_STRINGS_absolute_time_to_string(req->expires), | 1254 | GNUNET_STRINGS_absolute_time_to_string (req->expires), |
1250 | req->hostname); | 1255 | req->hostname); |
1251 | if (NULL != t) | 1256 | if (NULL != t) |
1252 | GNUNET_SCHEDULER_cancel(t); | 1257 | GNUNET_SCHEDULER_cancel (t); |
1253 | sleep_time_reg_proc = GNUNET_TIME_absolute_get(); | 1258 | sleep_time_reg_proc = GNUNET_TIME_absolute_get (); |
1254 | t = GNUNET_SCHEDULER_add_at(req->expires, &process_queue, NULL); | 1259 | t = GNUNET_SCHEDULER_add_at (req->expires, &process_queue, NULL); |
1255 | return; | 1260 | return; |
1256 | } | 1261 | } |
1257 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Throttling\n"); | 1262 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Throttling\n"); |
1258 | if (NULL != t) | 1263 | if (NULL != t) |
1259 | GNUNET_SCHEDULER_cancel(t); | 1264 | GNUNET_SCHEDULER_cancel (t); |
1260 | sleep_time_reg_proc = GNUNET_TIME_absolute_get(); | 1265 | sleep_time_reg_proc = GNUNET_TIME_absolute_get (); |
1261 | t = GNUNET_SCHEDULER_add_delayed(SERIES_DELAY, &process_queue, NULL); | 1266 | t = GNUNET_SCHEDULER_add_delayed (SERIES_DELAY, &process_queue, NULL); |
1262 | } | 1267 | } |
1263 | 1268 | ||
1264 | 1269 | ||
@@ -1272,13 +1277,13 @@ process_queue(void *cls) | |||
1272 | * @return #GNUNET_OK | 1277 | * @return #GNUNET_OK |
1273 | */ | 1278 | */ |
1274 | static int | 1279 | static int |
1275 | free_request_it(void *cls, const struct GNUNET_HashCode *key, void *value) | 1280 | free_request_it (void *cls, const struct GNUNET_HashCode *key, void *value) |
1276 | { | 1281 | { |
1277 | struct Request *req = value; | 1282 | struct Request *req = value; |
1278 | 1283 | ||
1279 | (void)cls; | 1284 | (void) cls; |
1280 | (void)key; | 1285 | (void) key; |
1281 | free_request(req); | 1286 | free_request (req); |
1282 | return GNUNET_OK; | 1287 | return GNUNET_OK; |
1283 | } | 1288 | } |
1284 | 1289 | ||
@@ -1289,73 +1294,73 @@ free_request_it(void *cls, const struct GNUNET_HashCode *key, void *value) | |||
1289 | * @param cls NULL | 1294 | * @param cls NULL |
1290 | */ | 1295 | */ |
1291 | static void | 1296 | static void |
1292 | do_shutdown(void *cls) | 1297 | do_shutdown (void *cls) |
1293 | { | 1298 | { |
1294 | struct Request *req; | 1299 | struct Request *req; |
1295 | struct Zone *zone; | 1300 | struct Zone *zone; |
1296 | 1301 | ||
1297 | (void)cls; | 1302 | (void) cls; |
1298 | if (NULL != id) | 1303 | if (NULL != id) |
1299 | { | 1304 | { |
1300 | GNUNET_IDENTITY_disconnect(id); | 1305 | GNUNET_IDENTITY_disconnect (id); |
1301 | id = NULL; | 1306 | id = NULL; |
1302 | } | 1307 | } |
1303 | if (NULL != t) | 1308 | if (NULL != t) |
1304 | { | 1309 | { |
1305 | GNUNET_SCHEDULER_cancel(t); | 1310 | GNUNET_SCHEDULER_cancel (t); |
1306 | t = NULL; | 1311 | t = NULL; |
1307 | } | 1312 | } |
1308 | while (NULL != (req = req_head)) | 1313 | while (NULL != (req = req_head)) |
1309 | { | 1314 | { |
1310 | GNUNET_CONTAINER_DLL_remove(req_head, req_tail, req); | 1315 | GNUNET_CONTAINER_DLL_remove (req_head, req_tail, req); |
1311 | if (NULL != req->qe) | 1316 | if (NULL != req->qe) |
1312 | GNUNET_NAMESTORE_cancel(req->qe); | 1317 | GNUNET_NAMESTORE_cancel (req->qe); |
1313 | free_request(req); | 1318 | free_request (req); |
1314 | } | 1319 | } |
1315 | while (NULL != (req = GNUNET_CONTAINER_heap_remove_root(req_heap))) | 1320 | while (NULL != (req = GNUNET_CONTAINER_heap_remove_root (req_heap))) |
1316 | { | 1321 | { |
1317 | req->hn = NULL; | 1322 | req->hn = NULL; |
1318 | if (NULL != req->qe) | 1323 | if (NULL != req->qe) |
1319 | GNUNET_NAMESTORE_cancel(req->qe); | 1324 | GNUNET_NAMESTORE_cancel (req->qe); |
1320 | free_request(req); | 1325 | free_request (req); |
1321 | } | 1326 | } |
1322 | if (NULL != zone_it) | 1327 | if (NULL != zone_it) |
1323 | { | 1328 | { |
1324 | GNUNET_NAMESTORE_zone_iteration_stop(zone_it); | 1329 | GNUNET_NAMESTORE_zone_iteration_stop (zone_it); |
1325 | zone_it = NULL; | 1330 | zone_it = NULL; |
1326 | } | 1331 | } |
1327 | if (NULL != ns) | 1332 | if (NULL != ns) |
1328 | { | 1333 | { |
1329 | GNUNET_NAMESTORE_disconnect(ns); | 1334 | GNUNET_NAMESTORE_disconnect (ns); |
1330 | ns = NULL; | 1335 | ns = NULL; |
1331 | } | 1336 | } |
1332 | if (NULL != ctx) | 1337 | if (NULL != ctx) |
1333 | { | 1338 | { |
1334 | GNUNET_DNSSTUB_stop(ctx); | 1339 | GNUNET_DNSSTUB_stop (ctx); |
1335 | ctx = NULL; | 1340 | ctx = NULL; |
1336 | } | 1341 | } |
1337 | if (NULL != req_heap) | 1342 | if (NULL != req_heap) |
1338 | { | 1343 | { |
1339 | GNUNET_CONTAINER_heap_destroy(req_heap); | 1344 | GNUNET_CONTAINER_heap_destroy (req_heap); |
1340 | req_heap = NULL; | 1345 | req_heap = NULL; |
1341 | } | 1346 | } |
1342 | if (NULL != ns_pending) | 1347 | if (NULL != ns_pending) |
1343 | { | 1348 | { |
1344 | GNUNET_CONTAINER_multihashmap_iterate(ns_pending, &free_request_it, NULL); | 1349 | GNUNET_CONTAINER_multihashmap_iterate (ns_pending, &free_request_it, NULL); |
1345 | GNUNET_CONTAINER_multihashmap_destroy(ns_pending); | 1350 | GNUNET_CONTAINER_multihashmap_destroy (ns_pending); |
1346 | ns_pending = NULL; | 1351 | ns_pending = NULL; |
1347 | } | 1352 | } |
1348 | while (NULL != (zone = zone_head)) | 1353 | while (NULL != (zone = zone_head)) |
1349 | { | 1354 | { |
1350 | GNUNET_CONTAINER_DLL_remove(zone_head, zone_tail, zone); | 1355 | GNUNET_CONTAINER_DLL_remove (zone_head, zone_tail, zone); |
1351 | GNUNET_free(zone->domain); | 1356 | GNUNET_free (zone->domain); |
1352 | GNUNET_free(zone); | 1357 | GNUNET_free (zone); |
1353 | } | 1358 | } |
1354 | if (NULL != stats) | 1359 | if (NULL != stats) |
1355 | { | 1360 | { |
1356 | GNUNET_STATISTICS_destroy(stats, GNUNET_NO); | 1361 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); |
1357 | stats = NULL; | 1362 | stats = NULL; |
1358 | } | 1363 | } |
1359 | } | 1364 | } |
1360 | 1365 | ||
1361 | 1366 | ||
@@ -1366,7 +1371,7 @@ do_shutdown(void *cls) | |||
1366 | * @param cls NULL | 1371 | * @param cls NULL |
1367 | */ | 1372 | */ |
1368 | static void | 1373 | static void |
1369 | iterate_zones(void *cls); | 1374 | iterate_zones (void *cls); |
1370 | 1375 | ||
1371 | 1376 | ||
1372 | /** | 1377 | /** |
@@ -1376,16 +1381,16 @@ iterate_zones(void *cls); | |||
1376 | * @param cls a `struct Zone` | 1381 | * @param cls a `struct Zone` |
1377 | */ | 1382 | */ |
1378 | static void | 1383 | static void |
1379 | ns_lookup_error_cb(void *cls) | 1384 | ns_lookup_error_cb (void *cls) |
1380 | { | 1385 | { |
1381 | struct Zone *zone = cls; | 1386 | struct Zone *zone = cls; |
1382 | 1387 | ||
1383 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1388 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1384 | "Failed to load data from namestore for zone `%s'\n", | 1389 | "Failed to load data from namestore for zone `%s'\n", |
1385 | zone->domain); | 1390 | zone->domain); |
1386 | zone_it = NULL; | 1391 | zone_it = NULL; |
1387 | ns_iterator_trigger_next = 0; | 1392 | ns_iterator_trigger_next = 0; |
1388 | iterate_zones(NULL); | 1393 | iterate_zones (NULL); |
1389 | } | 1394 | } |
1390 | 1395 | ||
1391 | 1396 | ||
@@ -1399,11 +1404,11 @@ ns_lookup_error_cb(void *cls) | |||
1399 | * @param rd array of records with data to store | 1404 | * @param rd array of records with data to store |
1400 | */ | 1405 | */ |
1401 | static void | 1406 | static void |
1402 | ns_lookup_result_cb(void *cls, | 1407 | ns_lookup_result_cb (void *cls, |
1403 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | 1408 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, |
1404 | const char *label, | 1409 | const char *label, |
1405 | unsigned int rd_count, | 1410 | unsigned int rd_count, |
1406 | const struct GNUNET_GNSRECORD_Data *rd) | 1411 | const struct GNUNET_GNSRECORD_Data *rd) |
1407 | { | 1412 | { |
1408 | struct Zone *zone = cls; | 1413 | struct Zone *zone = cls; |
1409 | struct Request *req; | 1414 | struct Request *req; |
@@ -1411,85 +1416,85 @@ ns_lookup_result_cb(void *cls, | |||
1411 | char *fqdn; | 1416 | char *fqdn; |
1412 | 1417 | ||
1413 | ns_iterator_trigger_next--; | 1418 | ns_iterator_trigger_next--; |
1414 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1419 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1415 | "Obtained NAMESTORE reply, %llu left in round\n", | 1420 | "Obtained NAMESTORE reply, %llu left in round\n", |
1416 | (unsigned long long)ns_iterator_trigger_next); | 1421 | (unsigned long long) ns_iterator_trigger_next); |
1417 | if (0 == ns_iterator_trigger_next) | 1422 | if (0 == ns_iterator_trigger_next) |
1418 | { | 1423 | { |
1419 | ns_iterator_trigger_next = NS_BATCH_SIZE; | 1424 | ns_iterator_trigger_next = NS_BATCH_SIZE; |
1420 | GNUNET_STATISTICS_update(stats, | 1425 | GNUNET_STATISTICS_update (stats, |
1421 | "# NAMESTORE records requested from cache", | 1426 | "# NAMESTORE records requested from cache", |
1422 | ns_iterator_trigger_next, | 1427 | ns_iterator_trigger_next, |
1423 | GNUNET_NO); | 1428 | GNUNET_NO); |
1424 | GNUNET_NAMESTORE_zone_iterator_next(zone_it, ns_iterator_trigger_next); | 1429 | GNUNET_NAMESTORE_zone_iterator_next (zone_it, ns_iterator_trigger_next); |
1425 | } | 1430 | } |
1426 | GNUNET_asprintf(&fqdn, "%s.%s", label, zone->domain); | 1431 | GNUNET_asprintf (&fqdn, "%s.%s", label, zone->domain); |
1427 | GNUNET_CRYPTO_hash(fqdn, strlen(fqdn) + 1, &hc); | 1432 | GNUNET_CRYPTO_hash (fqdn, strlen (fqdn) + 1, &hc); |
1428 | GNUNET_free(fqdn); | 1433 | GNUNET_free (fqdn); |
1429 | req = GNUNET_CONTAINER_multihashmap_get(ns_pending, &hc); | 1434 | req = GNUNET_CONTAINER_multihashmap_get (ns_pending, &hc); |
1430 | if (NULL == req) | 1435 | if (NULL == req) |
1431 | { | 1436 | { |
1432 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1437 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1433 | "Ignoring record `%s' in zone `%s': not on my list!\n", | 1438 | "Ignoring record `%s' in zone `%s': not on my list!\n", |
1434 | label, | 1439 | label, |
1435 | zone->domain); | 1440 | zone->domain); |
1436 | return; | 1441 | return; |
1437 | } | 1442 | } |
1438 | GNUNET_assert(GNUNET_OK == | 1443 | GNUNET_assert (GNUNET_OK == |
1439 | GNUNET_CONTAINER_multihashmap_remove(ns_pending, &hc, req)); | 1444 | GNUNET_CONTAINER_multihashmap_remove (ns_pending, &hc, req)); |
1440 | GNUNET_break(0 == GNUNET_memcmp(key, &req->zone->key)); | 1445 | GNUNET_break (0 == GNUNET_memcmp (key, &req->zone->key)); |
1441 | GNUNET_break(0 == strcasecmp(label, get_label(req))); | 1446 | GNUNET_break (0 == strcasecmp (label, get_label (req))); |
1442 | for (unsigned int i = 0; i < rd_count; i++) | 1447 | for (unsigned int i = 0; i < rd_count; i++) |
1443 | { | 1448 | { |
1444 | struct GNUNET_TIME_Absolute at; | 1449 | struct GNUNET_TIME_Absolute at; |
1445 | 1450 | ||
1446 | if (0 != (rd->flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) | 1451 | if (0 != (rd->flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) |
1447 | { | 1452 | { |
1448 | struct GNUNET_TIME_Relative rel; | 1453 | struct GNUNET_TIME_Relative rel; |
1449 | 1454 | ||
1450 | rel.rel_value_us = rd->expiration_time; | 1455 | rel.rel_value_us = rd->expiration_time; |
1451 | at = GNUNET_TIME_relative_to_absolute(rel); | 1456 | at = GNUNET_TIME_relative_to_absolute (rel); |
1452 | } | ||
1453 | else | ||
1454 | { | ||
1455 | at.abs_value_us = rd->expiration_time; | ||
1456 | } | ||
1457 | add_record(req, rd->record_type, at, rd->data, rd->data_size); | ||
1458 | } | 1457 | } |
1459 | if (0 == rd_count) | 1458 | else |
1460 | { | 1459 | { |
1461 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1460 | at.abs_value_us = rd->expiration_time; |
1462 | "Empty record set in namestore for `%s'\n", | ||
1463 | req->hostname); | ||
1464 | } | 1461 | } |
1462 | add_record (req, rd->record_type, at, rd->data, rd->data_size); | ||
1463 | } | ||
1464 | if (0 == rd_count) | ||
1465 | { | ||
1466 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1467 | "Empty record set in namestore for `%s'\n", | ||
1468 | req->hostname); | ||
1469 | } | ||
1465 | else | 1470 | else |
1471 | { | ||
1472 | unsigned int pos = 0; | ||
1473 | |||
1474 | cached++; | ||
1475 | req->expires = GNUNET_TIME_UNIT_FOREVER_ABS; | ||
1476 | for (struct Record *rec = req->rec_head; NULL != rec; rec = rec->next) | ||
1466 | { | 1477 | { |
1467 | unsigned int pos = 0; | 1478 | struct GNUNET_TIME_Absolute at; |
1468 | 1479 | ||
1469 | cached++; | 1480 | at.abs_value_us = rec->grd.expiration_time; |
1470 | req->expires = GNUNET_TIME_UNIT_FOREVER_ABS; | 1481 | req->expires = GNUNET_TIME_absolute_min (req->expires, at); |
1471 | for (struct Record *rec = req->rec_head; NULL != rec; rec = rec->next) | 1482 | pos++; |
1472 | { | ||
1473 | struct GNUNET_TIME_Absolute at; | ||
1474 | |||
1475 | at.abs_value_us = rec->grd.expiration_time; | ||
1476 | req->expires = GNUNET_TIME_absolute_min(req->expires, at); | ||
1477 | pos++; | ||
1478 | } | ||
1479 | if (0 == pos) | ||
1480 | req->expires = GNUNET_TIME_UNIT_ZERO_ABS; | ||
1481 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
1482 | "Hot-start with %u existing records for `%s'\n", | ||
1483 | pos, | ||
1484 | req->hostname); | ||
1485 | } | 1483 | } |
1486 | free_records(req); | 1484 | if (0 == pos) |
1485 | req->expires = GNUNET_TIME_UNIT_ZERO_ABS; | ||
1486 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1487 | "Hot-start with %u existing records for `%s'\n", | ||
1488 | pos, | ||
1489 | req->hostname); | ||
1490 | } | ||
1491 | free_records (req); | ||
1487 | 1492 | ||
1488 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1493 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1489 | "Adding `%s' to worklist to start at %s\n", | 1494 | "Adding `%s' to worklist to start at %s\n", |
1490 | req->hostname, | 1495 | req->hostname, |
1491 | GNUNET_STRINGS_absolute_time_to_string(req->expires)); | 1496 | GNUNET_STRINGS_absolute_time_to_string (req->expires)); |
1492 | insert_sorted(req); | 1497 | insert_sorted (req); |
1493 | } | 1498 | } |
1494 | 1499 | ||
1495 | 1500 | ||
@@ -1499,7 +1504,7 @@ ns_lookup_result_cb(void *cls, | |||
1499 | * @param hostname name to resolve | 1504 | * @param hostname name to resolve |
1500 | */ | 1505 | */ |
1501 | static void | 1506 | static void |
1502 | queue(const char *hostname) | 1507 | queue (const char *hostname) |
1503 | { | 1508 | { |
1504 | struct Request *req; | 1509 | struct Request *req; |
1505 | const char *dot; | 1510 | const char *dot; |
@@ -1507,55 +1512,55 @@ queue(const char *hostname) | |||
1507 | size_t hlen; | 1512 | size_t hlen; |
1508 | struct GNUNET_HashCode hc; | 1513 | struct GNUNET_HashCode hc; |
1509 | 1514 | ||
1510 | if (GNUNET_OK != GNUNET_DNSPARSER_check_name(hostname)) | 1515 | if (GNUNET_OK != GNUNET_DNSPARSER_check_name (hostname)) |
1511 | { | 1516 | { |
1512 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1517 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1513 | "Refusing invalid hostname `%s'\n", | 1518 | "Refusing invalid hostname `%s'\n", |
1514 | hostname); | 1519 | hostname); |
1515 | rejects++; | 1520 | rejects++; |
1516 | return; | 1521 | return; |
1517 | } | 1522 | } |
1518 | dot = strchr(hostname, (unsigned char)'.'); | 1523 | dot = strchr (hostname, (unsigned char) '.'); |
1519 | if (NULL == dot) | 1524 | if (NULL == dot) |
1520 | { | 1525 | { |
1521 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1526 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1522 | "Refusing invalid hostname `%s' (lacks '.')\n", | 1527 | "Refusing invalid hostname `%s' (lacks '.')\n", |
1523 | hostname); | 1528 | hostname); |
1524 | rejects++; | 1529 | rejects++; |
1525 | return; | 1530 | return; |
1526 | } | 1531 | } |
1527 | for (zone = zone_head; NULL != zone; zone = zone->next) | 1532 | for (zone = zone_head; NULL != zone; zone = zone->next) |
1528 | if (0 == strcmp(zone->domain, dot + 1)) | 1533 | if (0 == strcmp (zone->domain, dot + 1)) |
1529 | break; | 1534 | break; |
1530 | if (NULL == zone) | 1535 | if (NULL == zone) |
1531 | { | 1536 | { |
1532 | rejects++; | 1537 | rejects++; |
1533 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1538 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1534 | "Domain name `%s' not in ego list!\n", | 1539 | "Domain name `%s' not in ego list!\n", |
1535 | dot + 1); | 1540 | dot + 1); |
1536 | return; | 1541 | return; |
1537 | } | 1542 | } |
1538 | 1543 | ||
1539 | hlen = strlen(hostname) + 1; | 1544 | hlen = strlen (hostname) + 1; |
1540 | req = GNUNET_malloc(sizeof(struct Request) + hlen); | 1545 | req = GNUNET_malloc (sizeof(struct Request) + hlen); |
1541 | req->zone = zone; | 1546 | req->zone = zone; |
1542 | req->hostname = (char *)&req[1]; | 1547 | req->hostname = (char *) &req[1]; |
1543 | GNUNET_memcpy(req->hostname, hostname, hlen); | 1548 | GNUNET_memcpy (req->hostname, hostname, hlen); |
1544 | req->id = (uint16_t)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, | 1549 | req->id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, |
1545 | UINT16_MAX); | 1550 | UINT16_MAX); |
1546 | GNUNET_CRYPTO_hash(req->hostname, hlen, &hc); | 1551 | GNUNET_CRYPTO_hash (req->hostname, hlen, &hc); |
1547 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( | 1552 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put ( |
1548 | ns_pending, | 1553 | ns_pending, |
1549 | &hc, | 1554 | &hc, |
1550 | req, | 1555 | req, |
1551 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | 1556 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) |
1552 | { | 1557 | { |
1553 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1558 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1554 | "Duplicate hostname `%s' ignored\n", | 1559 | "Duplicate hostname `%s' ignored\n", |
1555 | hostname); | 1560 | hostname); |
1556 | GNUNET_free(req); | 1561 | GNUNET_free (req); |
1557 | return; | 1562 | return; |
1558 | } | 1563 | } |
1559 | } | 1564 | } |
1560 | 1565 | ||
1561 | 1566 | ||
@@ -1571,13 +1576,13 @@ queue(const char *hostname) | |||
1571 | * @return #GNUNET_OK (continue to iterate) | 1576 | * @return #GNUNET_OK (continue to iterate) |
1572 | */ | 1577 | */ |
1573 | static int | 1578 | static int |
1574 | move_to_queue(void *cls, const struct GNUNET_HashCode *key, void *value) | 1579 | move_to_queue (void *cls, const struct GNUNET_HashCode *key, void *value) |
1575 | { | 1580 | { |
1576 | struct Request *req = value; | 1581 | struct Request *req = value; |
1577 | 1582 | ||
1578 | (void)cls; | 1583 | (void) cls; |
1579 | (void)key; | 1584 | (void) key; |
1580 | insert_sorted(req); | 1585 | insert_sorted (req); |
1581 | return GNUNET_OK; | 1586 | return GNUNET_OK; |
1582 | } | 1587 | } |
1583 | 1588 | ||
@@ -1589,65 +1594,65 @@ move_to_queue(void *cls, const struct GNUNET_HashCode *key, void *value) | |||
1589 | * @param cls NULL | 1594 | * @param cls NULL |
1590 | */ | 1595 | */ |
1591 | static void | 1596 | static void |
1592 | iterate_zones(void *cls) | 1597 | iterate_zones (void *cls) |
1593 | { | 1598 | { |
1594 | static struct Zone *last; | 1599 | static struct Zone *last; |
1595 | 1600 | ||
1596 | (void)cls; | 1601 | (void) cls; |
1597 | if (NULL != zone_it) | 1602 | if (NULL != zone_it) |
1598 | { | 1603 | { |
1599 | zone_it = NULL; | 1604 | zone_it = NULL; |
1600 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1605 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1601 | "Finished iteration over zone `%s'!\n", | 1606 | "Finished iteration over zone `%s'!\n", |
1602 | last->domain); | 1607 | last->domain); |
1603 | /* subtract left-overs from previous iteration */ | 1608 | /* subtract left-overs from previous iteration */ |
1604 | GNUNET_STATISTICS_update(stats, | 1609 | GNUNET_STATISTICS_update (stats, |
1605 | "# NAMESTORE records requested from cache", | 1610 | "# NAMESTORE records requested from cache", |
1606 | (long long)(-ns_iterator_trigger_next), | 1611 | (long long) (-ns_iterator_trigger_next), |
1607 | GNUNET_NO); | 1612 | GNUNET_NO); |
1608 | ns_iterator_trigger_next = 0; | 1613 | ns_iterator_trigger_next = 0; |
1609 | } | 1614 | } |
1610 | GNUNET_assert(NULL != zone_tail); | 1615 | GNUNET_assert (NULL != zone_tail); |
1611 | if (zone_tail == last) | 1616 | if (zone_tail == last) |
1612 | { | 1617 | { |
1613 | /* Done iterating over relevant zones in NAMESTORE, move | 1618 | /* Done iterating over relevant zones in NAMESTORE, move |
1614 | rest of hash map to work queue as well. */ | 1619 | rest of hash map to work queue as well. */ |
1615 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1620 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1616 | "Finished all NAMESTORE iterations!\n"); | 1621 | "Finished all NAMESTORE iterations!\n"); |
1617 | GNUNET_STATISTICS_set(stats, | 1622 | GNUNET_STATISTICS_set (stats, |
1618 | "# Domain names without cached reply", | 1623 | "# Domain names without cached reply", |
1619 | GNUNET_CONTAINER_multihashmap_size(ns_pending), | 1624 | GNUNET_CONTAINER_multihashmap_size (ns_pending), |
1620 | GNUNET_NO); | 1625 | GNUNET_NO); |
1621 | GNUNET_CONTAINER_multihashmap_iterate(ns_pending, &move_to_queue, NULL); | 1626 | GNUNET_CONTAINER_multihashmap_iterate (ns_pending, &move_to_queue, NULL); |
1622 | GNUNET_CONTAINER_multihashmap_destroy(ns_pending); | 1627 | GNUNET_CONTAINER_multihashmap_destroy (ns_pending); |
1623 | ns_pending = NULL; | 1628 | ns_pending = NULL; |
1624 | start_time_reg_proc = GNUNET_TIME_absolute_get(); | 1629 | start_time_reg_proc = GNUNET_TIME_absolute_get (); |
1625 | total_reg_proc_dns = 0; | 1630 | total_reg_proc_dns = 0; |
1626 | total_reg_proc_dns_ns = 0; | 1631 | total_reg_proc_dns_ns = 0; |
1627 | return; | 1632 | return; |
1628 | } | 1633 | } |
1629 | if (NULL == last) | 1634 | if (NULL == last) |
1630 | last = zone_head; | 1635 | last = zone_head; |
1631 | else | 1636 | else |
1632 | last = last->next; | 1637 | last = last->next; |
1633 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1638 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1634 | "Starting iteration over zone `%s'!\n", | 1639 | "Starting iteration over zone `%s'!\n", |
1635 | last->domain); | 1640 | last->domain); |
1636 | /* subtract left-overs from previous iteration */ | 1641 | /* subtract left-overs from previous iteration */ |
1637 | GNUNET_STATISTICS_update(stats, | 1642 | GNUNET_STATISTICS_update (stats, |
1638 | "# NAMESTORE records requested from cache", | 1643 | "# NAMESTORE records requested from cache", |
1639 | 1, | 1644 | 1, |
1640 | GNUNET_NO); | 1645 | GNUNET_NO); |
1641 | ns_iterator_trigger_next = 1; | 1646 | ns_iterator_trigger_next = 1; |
1642 | GNUNET_STATISTICS_update(stats, "# zones iterated", 1, GNUNET_NO); | 1647 | GNUNET_STATISTICS_update (stats, "# zones iterated", 1, GNUNET_NO); |
1643 | zone_it = GNUNET_NAMESTORE_zone_iteration_start(ns, | 1648 | zone_it = GNUNET_NAMESTORE_zone_iteration_start (ns, |
1644 | &last->key, | 1649 | &last->key, |
1645 | &ns_lookup_error_cb, | 1650 | &ns_lookup_error_cb, |
1646 | NULL, | 1651 | NULL, |
1647 | &ns_lookup_result_cb, | 1652 | &ns_lookup_result_cb, |
1648 | last, | 1653 | last, |
1649 | &iterate_zones, | 1654 | &iterate_zones, |
1650 | NULL); | 1655 | NULL); |
1651 | } | 1656 | } |
1652 | 1657 | ||
1653 | 1658 | ||
@@ -1657,44 +1662,44 @@ iterate_zones(void *cls) | |||
1657 | * @param cls NULL | 1662 | * @param cls NULL |
1658 | */ | 1663 | */ |
1659 | static void | 1664 | static void |
1660 | process_stdin(void *cls) | 1665 | process_stdin (void *cls) |
1661 | { | 1666 | { |
1662 | static struct GNUNET_TIME_Absolute last; | 1667 | static struct GNUNET_TIME_Absolute last; |
1663 | static uint64_t idot; | 1668 | static uint64_t idot; |
1664 | char hn[256]; | 1669 | char hn[256]; |
1665 | 1670 | ||
1666 | (void)cls; | 1671 | (void) cls; |
1667 | t = NULL; | 1672 | t = NULL; |
1668 | if (NULL != id) | 1673 | if (NULL != id) |
1674 | { | ||
1675 | GNUNET_IDENTITY_disconnect (id); | ||
1676 | id = NULL; | ||
1677 | } | ||
1678 | while (NULL != fgets (hn, sizeof(hn), stdin)) | ||
1679 | { | ||
1680 | if (strlen (hn) > 0) | ||
1681 | hn[strlen (hn) - 1] = '\0'; /* eat newline */ | ||
1682 | if (0 == idot) | ||
1683 | last = GNUNET_TIME_absolute_get (); | ||
1684 | idot++; | ||
1685 | if (0 == idot % 100000) | ||
1669 | { | 1686 | { |
1670 | GNUNET_IDENTITY_disconnect(id); | 1687 | struct GNUNET_TIME_Relative delta; |
1671 | id = NULL; | 1688 | |
1672 | } | 1689 | delta = GNUNET_TIME_absolute_get_duration (last); |
1673 | while (NULL != fgets(hn, sizeof(hn), stdin)) | 1690 | last = GNUNET_TIME_absolute_get (); |
1674 | { | 1691 | fprintf (stderr, |
1675 | if (strlen(hn) > 0) | 1692 | "Read 100000 domain names in %s\n", |
1676 | hn[strlen(hn) - 1] = '\0'; /* eat newline */ | 1693 | GNUNET_STRINGS_relative_time_to_string (delta, GNUNET_YES)); |
1677 | if (0 == idot) | 1694 | GNUNET_STATISTICS_set (stats, "# domain names provided", idot, GNUNET_NO); |
1678 | last = GNUNET_TIME_absolute_get(); | ||
1679 | idot++; | ||
1680 | if (0 == idot % 100000) | ||
1681 | { | ||
1682 | struct GNUNET_TIME_Relative delta; | ||
1683 | |||
1684 | delta = GNUNET_TIME_absolute_get_duration(last); | ||
1685 | last = GNUNET_TIME_absolute_get(); | ||
1686 | fprintf(stderr, | ||
1687 | "Read 100000 domain names in %s\n", | ||
1688 | GNUNET_STRINGS_relative_time_to_string(delta, GNUNET_YES)); | ||
1689 | GNUNET_STATISTICS_set(stats, "# domain names provided", idot, GNUNET_NO); | ||
1690 | } | ||
1691 | queue(hn); | ||
1692 | } | 1695 | } |
1693 | fprintf(stderr, | 1696 | queue (hn); |
1694 | "Done reading %llu domain names\n", | 1697 | } |
1695 | (unsigned long long)idot); | 1698 | fprintf (stderr, |
1696 | GNUNET_STATISTICS_set(stats, "# domain names provided", idot, GNUNET_NO); | 1699 | "Done reading %llu domain names\n", |
1697 | iterate_zones(NULL); | 1700 | (unsigned long long) idot); |
1701 | GNUNET_STATISTICS_set (stats, "# domain names provided", idot, GNUNET_NO); | ||
1702 | iterate_zones (NULL); | ||
1698 | } | 1703 | } |
1699 | 1704 | ||
1700 | 1705 | ||
@@ -1733,36 +1738,36 @@ process_stdin(void *cls) | |||
1733 | * must thus no longer be used | 1738 | * must thus no longer be used |
1734 | */ | 1739 | */ |
1735 | static void | 1740 | static void |
1736 | identity_cb(void *cls, | 1741 | identity_cb (void *cls, |
1737 | struct GNUNET_IDENTITY_Ego *ego, | 1742 | struct GNUNET_IDENTITY_Ego *ego, |
1738 | void **ctx, | 1743 | void **ctx, |
1739 | const char *name) | 1744 | const char *name) |
1740 | { | 1745 | { |
1741 | (void)cls; | 1746 | (void) cls; |
1742 | (void)ctx; | 1747 | (void) ctx; |
1743 | 1748 | ||
1744 | if (NULL == ego) | 1749 | if (NULL == ego) |
1750 | { | ||
1751 | /* end of iteration */ | ||
1752 | if (NULL == zone_head) | ||
1745 | { | 1753 | { |
1746 | /* end of iteration */ | 1754 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No zone found\n"); |
1747 | if (NULL == zone_head) | 1755 | GNUNET_SCHEDULER_shutdown (); |
1748 | { | ||
1749 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No zone found\n"); | ||
1750 | GNUNET_SCHEDULER_shutdown(); | ||
1751 | return; | ||
1752 | } | ||
1753 | /* zone_head non-null, process hostnames from stdin */ | ||
1754 | t = GNUNET_SCHEDULER_add_now(&process_stdin, NULL); | ||
1755 | return; | 1756 | return; |
1756 | } | 1757 | } |
1758 | /* zone_head non-null, process hostnames from stdin */ | ||
1759 | t = GNUNET_SCHEDULER_add_now (&process_stdin, NULL); | ||
1760 | return; | ||
1761 | } | ||
1757 | if (NULL != name) | 1762 | if (NULL != name) |
1758 | { | 1763 | { |
1759 | struct Zone *zone; | 1764 | struct Zone *zone; |
1760 | 1765 | ||
1761 | zone = GNUNET_new(struct Zone); | 1766 | zone = GNUNET_new (struct Zone); |
1762 | zone->key = *GNUNET_IDENTITY_ego_get_private_key(ego); | 1767 | zone->key = *GNUNET_IDENTITY_ego_get_private_key (ego); |
1763 | zone->domain = GNUNET_strdup(name); | 1768 | zone->domain = GNUNET_strdup (name); |
1764 | GNUNET_CONTAINER_DLL_insert(zone_head, zone_tail, zone); | 1769 | GNUNET_CONTAINER_DLL_insert (zone_head, zone_tail, zone); |
1765 | } | 1770 | } |
1766 | } | 1771 | } |
1767 | 1772 | ||
1768 | 1773 | ||
@@ -1776,52 +1781,52 @@ identity_cb(void *cls, | |||
1776 | * @param cfg configuration | 1781 | * @param cfg configuration |
1777 | */ | 1782 | */ |
1778 | static void | 1783 | static void |
1779 | run(void *cls, | 1784 | run (void *cls, |
1780 | char *const *args, | 1785 | char *const *args, |
1781 | const char *cfgfile, | 1786 | const char *cfgfile, |
1782 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 1787 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
1783 | { | 1788 | { |
1784 | (void)cls; | 1789 | (void) cls; |
1785 | (void)args; | 1790 | (void) args; |
1786 | (void)cfgfile; | 1791 | (void) cfgfile; |
1787 | stats = GNUNET_STATISTICS_create("zoneimport", cfg); | 1792 | stats = GNUNET_STATISTICS_create ("zoneimport", cfg); |
1788 | req_heap = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); | 1793 | req_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
1789 | ns_pending = GNUNET_CONTAINER_multihashmap_create(map_size, GNUNET_NO); | 1794 | ns_pending = GNUNET_CONTAINER_multihashmap_create (map_size, GNUNET_NO); |
1790 | if (NULL == ns_pending) | 1795 | if (NULL == ns_pending) |
1791 | { | 1796 | { |
1792 | fprintf(stderr, "Failed to allocate memory for main hash map\n"); | 1797 | fprintf (stderr, "Failed to allocate memory for main hash map\n"); |
1793 | return; | 1798 | return; |
1794 | } | 1799 | } |
1795 | ctx = GNUNET_DNSSTUB_start(256); | 1800 | ctx = GNUNET_DNSSTUB_start (256); |
1796 | if (NULL == ctx) | 1801 | if (NULL == ctx) |
1797 | { | 1802 | { |
1798 | fprintf(stderr, "Failed to initialize GNUnet DNS STUB\n"); | 1803 | fprintf (stderr, "Failed to initialize GNUnet DNS STUB\n"); |
1799 | return; | 1804 | return; |
1800 | } | 1805 | } |
1801 | if (NULL == args[0]) | 1806 | if (NULL == args[0]) |
1802 | { | 1807 | { |
1803 | fprintf(stderr, | 1808 | fprintf (stderr, |
1804 | "You must provide a list of DNS resolvers on the command line\n"); | 1809 | "You must provide a list of DNS resolvers on the command line\n"); |
1805 | return; | 1810 | return; |
1806 | } | 1811 | } |
1807 | for (unsigned int i = 0; NULL != args[i]; i++) | 1812 | for (unsigned int i = 0; NULL != args[i]; i++) |
1813 | { | ||
1814 | if (GNUNET_OK != GNUNET_DNSSTUB_add_dns_ip (ctx, args[i])) | ||
1808 | { | 1815 | { |
1809 | if (GNUNET_OK != GNUNET_DNSSTUB_add_dns_ip(ctx, args[i])) | 1816 | fprintf (stderr, "Failed to use `%s' for DNS resolver\n", args[i]); |
1810 | { | 1817 | return; |
1811 | fprintf(stderr, "Failed to use `%s' for DNS resolver\n", args[i]); | ||
1812 | return; | ||
1813 | } | ||
1814 | } | 1818 | } |
1819 | } | ||
1815 | 1820 | ||
1816 | 1821 | ||
1817 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); | 1822 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); |
1818 | ns = GNUNET_NAMESTORE_connect(cfg); | 1823 | ns = GNUNET_NAMESTORE_connect (cfg); |
1819 | if (NULL == ns) | 1824 | if (NULL == ns) |
1820 | { | 1825 | { |
1821 | GNUNET_SCHEDULER_shutdown(); | 1826 | GNUNET_SCHEDULER_shutdown (); |
1822 | return; | 1827 | return; |
1823 | } | 1828 | } |
1824 | id = GNUNET_IDENTITY_connect(cfg, &identity_cb, NULL); | 1829 | id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL); |
1825 | } | 1830 | } |
1826 | 1831 | ||
1827 | 1832 | ||
@@ -1833,46 +1838,46 @@ run(void *cls, | |||
1833 | * @return 0 on success | 1838 | * @return 0 on success |
1834 | */ | 1839 | */ |
1835 | int | 1840 | int |
1836 | main(int argc, char *const *argv) | 1841 | main (int argc, char *const *argv) |
1837 | { | 1842 | { |
1838 | struct GNUNET_GETOPT_CommandLineOption options[] = | 1843 | struct GNUNET_GETOPT_CommandLineOption options[] = |
1839 | { GNUNET_GETOPT_option_uint('s', | 1844 | { GNUNET_GETOPT_option_uint ('s', |
1840 | "size", | 1845 | "size", |
1841 | "MAPSIZE", | 1846 | "MAPSIZE", |
1842 | gettext_noop( | 1847 | gettext_noop ( |
1843 | "size to use for the main hash map"), | 1848 | "size to use for the main hash map"), |
1844 | &map_size), | 1849 | &map_size), |
1845 | GNUNET_GETOPT_option_relative_time( | 1850 | GNUNET_GETOPT_option_relative_time ( |
1846 | 'm', | 1851 | 'm', |
1847 | "minimum-expiration", | 1852 | "minimum-expiration", |
1848 | "RELATIVETIME", | 1853 | "RELATIVETIME", |
1849 | gettext_noop("minimum expiration time we assume for imported records"), | 1854 | gettext_noop ("minimum expiration time we assume for imported records"), |
1850 | &minimum_expiration_time), | 1855 | &minimum_expiration_time), |
1851 | GNUNET_GETOPT_OPTION_END }; | 1856 | GNUNET_GETOPT_OPTION_END }; |
1852 | int ret; | 1857 | int ret; |
1853 | 1858 | ||
1854 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) | 1859 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
1855 | return 2; | 1860 | return 2; |
1856 | if (GNUNET_OK != (ret = GNUNET_PROGRAM_run(argc, | 1861 | if (GNUNET_OK != (ret = GNUNET_PROGRAM_run (argc, |
1857 | argv, | 1862 | argv, |
1858 | "gnunet-zoneimport", | 1863 | "gnunet-zoneimport", |
1859 | "import DNS zone into namestore", | 1864 | "import DNS zone into namestore", |
1860 | options, | 1865 | options, |
1861 | &run, | 1866 | &run, |
1862 | NULL))) | 1867 | NULL))) |
1863 | return ret; | 1868 | return ret; |
1864 | GNUNET_free((void *)argv); | 1869 | GNUNET_free ((void *) argv); |
1865 | fprintf(stderr, | 1870 | fprintf (stderr, |
1866 | "Rejected %u names, had %u cached, did %u lookups, stored %u record sets\n" | 1871 | "Rejected %u names, had %u cached, did %u lookups, stored %u record sets\n" |
1867 | "Found %u records, %u lookups failed, %u/%u pending on shutdown\n", | 1872 | "Found %u records, %u lookups failed, %u/%u pending on shutdown\n", |
1868 | rejects, | 1873 | rejects, |
1869 | cached, | 1874 | cached, |
1870 | lookups, | 1875 | lookups, |
1871 | record_sets, | 1876 | record_sets, |
1872 | records, | 1877 | records, |
1873 | failures, | 1878 | failures, |
1874 | pending, | 1879 | pending, |
1875 | pending_rs); | 1880 | pending_rs); |
1876 | return 0; | 1881 | return 0; |
1877 | } | 1882 | } |
1878 | 1883 | ||
diff --git a/src/namestore/namestore.h b/src/namestore/namestore.h index e9a38f0b4..0fb5bea7c 100644 --- a/src/namestore/namestore.h +++ b/src/namestore/namestore.h | |||
@@ -37,7 +37,8 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
37 | /** | 37 | /** |
38 | * Generic namestore message with op id | 38 | * Generic namestore message with op id |
39 | */ | 39 | */ |
40 | struct GNUNET_NAMESTORE_Header { | 40 | struct GNUNET_NAMESTORE_Header |
41 | { | ||
41 | /** | 42 | /** |
42 | * header.type will be GNUNET_MESSAGE_TYPE_NAMESTORE_* | 43 | * header.type will be GNUNET_MESSAGE_TYPE_NAMESTORE_* |
43 | * header.size will be message size | 44 | * header.size will be message size |
@@ -54,7 +55,8 @@ struct GNUNET_NAMESTORE_Header { | |||
54 | /** | 55 | /** |
55 | * Store a record to the namestore (as authority). | 56 | * Store a record to the namestore (as authority). |
56 | */ | 57 | */ |
57 | struct RecordStoreMessage { | 58 | struct RecordStoreMessage |
59 | { | ||
58 | /** | 60 | /** |
59 | * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE | 61 | * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE |
60 | */ | 62 | */ |
@@ -100,7 +102,8 @@ struct RecordStoreMessage { | |||
100 | /** | 102 | /** |
101 | * Response to a record storage request. | 103 | * Response to a record storage request. |
102 | */ | 104 | */ |
103 | struct RecordStoreResponseMessage { | 105 | struct RecordStoreResponseMessage |
106 | { | ||
104 | /** | 107 | /** |
105 | * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE | 108 | * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE |
106 | */ | 109 | */ |
@@ -116,7 +119,8 @@ struct RecordStoreResponseMessage { | |||
116 | /** | 119 | /** |
117 | * Lookup a label | 120 | * Lookup a label |
118 | */ | 121 | */ |
119 | struct LabelLookupMessage { | 122 | struct LabelLookupMessage |
123 | { | ||
120 | /** | 124 | /** |
121 | * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP | 125 | * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP |
122 | */ | 126 | */ |
@@ -141,7 +145,8 @@ struct LabelLookupMessage { | |||
141 | /** | 145 | /** |
142 | * Lookup a label | 146 | * Lookup a label |
143 | */ | 147 | */ |
144 | struct LabelLookupResponseMessage { | 148 | struct LabelLookupResponseMessage |
149 | { | ||
145 | /** | 150 | /** |
146 | * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE | 151 | * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE |
147 | */ | 152 | */ |
@@ -184,7 +189,8 @@ struct LabelLookupResponseMessage { | |||
184 | /** | 189 | /** |
185 | * Lookup a name for a zone hash | 190 | * Lookup a name for a zone hash |
186 | */ | 191 | */ |
187 | struct ZoneToNameMessage { | 192 | struct ZoneToNameMessage |
193 | { | ||
188 | /** | 194 | /** |
189 | * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME | 195 | * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME |
190 | */ | 196 | */ |
@@ -205,7 +211,8 @@ struct ZoneToNameMessage { | |||
205 | /** | 211 | /** |
206 | * Respone for zone to name lookup | 212 | * Respone for zone to name lookup |
207 | */ | 213 | */ |
208 | struct ZoneToNameResponseMessage { | 214 | struct ZoneToNameResponseMessage |
215 | { | ||
209 | /** | 216 | /** |
210 | * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE | 217 | * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE |
211 | */ | 218 | */ |
@@ -247,7 +254,8 @@ struct ZoneToNameResponseMessage { | |||
247 | /** | 254 | /** |
248 | * Record is returned from the namestore (as authority). | 255 | * Record is returned from the namestore (as authority). |
249 | */ | 256 | */ |
250 | struct RecordResultMessage { | 257 | struct RecordResultMessage |
258 | { | ||
251 | /** | 259 | /** |
252 | * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT | 260 | * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT |
253 | */ | 261 | */ |
@@ -288,7 +296,8 @@ struct RecordResultMessage { | |||
288 | /** | 296 | /** |
289 | * Start monitoring a zone. | 297 | * Start monitoring a zone. |
290 | */ | 298 | */ |
291 | struct ZoneMonitorStartMessage { | 299 | struct ZoneMonitorStartMessage |
300 | { | ||
292 | /** | 301 | /** |
293 | * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START | 302 | * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START |
294 | */ | 303 | */ |
@@ -310,7 +319,8 @@ struct ZoneMonitorStartMessage { | |||
310 | /** | 319 | /** |
311 | * Ask for next result of zone iteration for the given operation | 320 | * Ask for next result of zone iteration for the given operation |
312 | */ | 321 | */ |
313 | struct ZoneMonitorNextMessage { | 322 | struct ZoneMonitorNextMessage |
323 | { | ||
314 | /** | 324 | /** |
315 | * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT | 325 | * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT |
316 | */ | 326 | */ |
@@ -334,7 +344,8 @@ struct ZoneMonitorNextMessage { | |||
334 | /** | 344 | /** |
335 | * Start a zone iteration for the given zone | 345 | * Start a zone iteration for the given zone |
336 | */ | 346 | */ |
337 | struct ZoneIterationStartMessage { | 347 | struct ZoneIterationStartMessage |
348 | { | ||
338 | /** | 349 | /** |
339 | * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START | 350 | * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START |
340 | */ | 351 | */ |
@@ -350,7 +361,8 @@ struct ZoneIterationStartMessage { | |||
350 | /** | 361 | /** |
351 | * Ask for next result of zone iteration for the given operation | 362 | * Ask for next result of zone iteration for the given operation |
352 | */ | 363 | */ |
353 | struct ZoneIterationNextMessage { | 364 | struct ZoneIterationNextMessage |
365 | { | ||
354 | /** | 366 | /** |
355 | * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT | 367 | * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT |
356 | */ | 368 | */ |
@@ -368,7 +380,8 @@ struct ZoneIterationNextMessage { | |||
368 | /** | 380 | /** |
369 | * Stop zone iteration for the given operation | 381 | * Stop zone iteration for the given operation |
370 | */ | 382 | */ |
371 | struct ZoneIterationStopMessage { | 383 | struct ZoneIterationStopMessage |
384 | { | ||
372 | /** | 385 | /** |
373 | * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP | 386 | * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP |
374 | */ | 387 | */ |
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index c80ca0bd5..156c115d2 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c | |||
@@ -38,7 +38,7 @@ | |||
38 | #include "namestore.h" | 38 | #include "namestore.h" |
39 | 39 | ||
40 | 40 | ||
41 | #define LOG(kind, ...) GNUNET_log_from(kind, "namestore-api", __VA_ARGS__) | 41 | #define LOG(kind, ...) GNUNET_log_from (kind, "namestore-api", __VA_ARGS__) |
42 | 42 | ||
43 | /** | 43 | /** |
44 | * We grant the namestore up to 1 minute of latency, if it is slower than | 44 | * We grant the namestore up to 1 minute of latency, if it is slower than |
@@ -50,7 +50,8 @@ | |||
50 | * An QueueEntry used to store information for a pending | 50 | * An QueueEntry used to store information for a pending |
51 | * NAMESTORE record operation | 51 | * NAMESTORE record operation |
52 | */ | 52 | */ |
53 | struct GNUNET_NAMESTORE_QueueEntry { | 53 | struct GNUNET_NAMESTORE_QueueEntry |
54 | { | ||
54 | /** | 55 | /** |
55 | * Kept in a DLL. | 56 | * Kept in a DLL. |
56 | */ | 57 | */ |
@@ -117,7 +118,8 @@ struct GNUNET_NAMESTORE_QueueEntry { | |||
117 | /** | 118 | /** |
118 | * Handle for a zone iterator operation | 119 | * Handle for a zone iterator operation |
119 | */ | 120 | */ |
120 | struct GNUNET_NAMESTORE_ZoneIterator { | 121 | struct GNUNET_NAMESTORE_ZoneIterator |
122 | { | ||
121 | /** | 123 | /** |
122 | * Kept in a DLL. | 124 | * Kept in a DLL. |
123 | */ | 125 | */ |
@@ -184,7 +186,8 @@ struct GNUNET_NAMESTORE_ZoneIterator { | |||
184 | /** | 186 | /** |
185 | * Connection to the NAMESTORE service. | 187 | * Connection to the NAMESTORE service. |
186 | */ | 188 | */ |
187 | struct GNUNET_NAMESTORE_Handle { | 189 | struct GNUNET_NAMESTORE_Handle |
190 | { | ||
188 | /** | 191 | /** |
189 | * Configuration to use. | 192 | * Configuration to use. |
190 | */ | 193 | */ |
@@ -243,7 +246,7 @@ struct GNUNET_NAMESTORE_Handle { | |||
243 | * @param h our handle | 246 | * @param h our handle |
244 | */ | 247 | */ |
245 | static void | 248 | static void |
246 | force_reconnect(struct GNUNET_NAMESTORE_Handle *h); | 249 | force_reconnect (struct GNUNET_NAMESTORE_Handle *h); |
247 | 250 | ||
248 | 251 | ||
249 | /** | 252 | /** |
@@ -254,7 +257,7 @@ force_reconnect(struct GNUNET_NAMESTORE_Handle *h); | |||
254 | * @return NULL if @a rid was not found | 257 | * @return NULL if @a rid was not found |
255 | */ | 258 | */ |
256 | static struct GNUNET_NAMESTORE_QueueEntry * | 259 | static struct GNUNET_NAMESTORE_QueueEntry * |
257 | find_qe(struct GNUNET_NAMESTORE_Handle *h, uint32_t rid) | 260 | find_qe (struct GNUNET_NAMESTORE_Handle *h, uint32_t rid) |
258 | { | 261 | { |
259 | struct GNUNET_NAMESTORE_QueueEntry *qe; | 262 | struct GNUNET_NAMESTORE_QueueEntry *qe; |
260 | 263 | ||
@@ -273,7 +276,7 @@ find_qe(struct GNUNET_NAMESTORE_Handle *h, uint32_t rid) | |||
273 | * @return NULL if @a rid was not found | 276 | * @return NULL if @a rid was not found |
274 | */ | 277 | */ |
275 | static struct GNUNET_NAMESTORE_ZoneIterator * | 278 | static struct GNUNET_NAMESTORE_ZoneIterator * |
276 | find_zi(struct GNUNET_NAMESTORE_Handle *h, uint32_t rid) | 279 | find_zi (struct GNUNET_NAMESTORE_Handle *h, uint32_t rid) |
277 | { | 280 | { |
278 | struct GNUNET_NAMESTORE_ZoneIterator *ze; | 281 | struct GNUNET_NAMESTORE_ZoneIterator *ze; |
279 | 282 | ||
@@ -290,16 +293,16 @@ find_zi(struct GNUNET_NAMESTORE_Handle *h, uint32_t rid) | |||
290 | * @param qe entry to free | 293 | * @param qe entry to free |
291 | */ | 294 | */ |
292 | static void | 295 | static void |
293 | free_qe(struct GNUNET_NAMESTORE_QueueEntry *qe) | 296 | free_qe (struct GNUNET_NAMESTORE_QueueEntry *qe) |
294 | { | 297 | { |
295 | struct GNUNET_NAMESTORE_Handle *h = qe->h; | 298 | struct GNUNET_NAMESTORE_Handle *h = qe->h; |
296 | 299 | ||
297 | GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, qe); | 300 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, qe); |
298 | if (NULL != qe->env) | 301 | if (NULL != qe->env) |
299 | GNUNET_MQ_discard(qe->env); | 302 | GNUNET_MQ_discard (qe->env); |
300 | if (NULL != qe->timeout_task) | 303 | if (NULL != qe->timeout_task) |
301 | GNUNET_SCHEDULER_cancel(qe->timeout_task); | 304 | GNUNET_SCHEDULER_cancel (qe->timeout_task); |
302 | GNUNET_free(qe); | 305 | GNUNET_free (qe); |
303 | } | 306 | } |
304 | 307 | ||
305 | 308 | ||
@@ -309,14 +312,14 @@ free_qe(struct GNUNET_NAMESTORE_QueueEntry *qe) | |||
309 | * @param ze entry to free | 312 | * @param ze entry to free |
310 | */ | 313 | */ |
311 | static void | 314 | static void |
312 | free_ze(struct GNUNET_NAMESTORE_ZoneIterator *ze) | 315 | free_ze (struct GNUNET_NAMESTORE_ZoneIterator *ze) |
313 | { | 316 | { |
314 | struct GNUNET_NAMESTORE_Handle *h = ze->h; | 317 | struct GNUNET_NAMESTORE_Handle *h = ze->h; |
315 | 318 | ||
316 | GNUNET_CONTAINER_DLL_remove(h->z_head, h->z_tail, ze); | 319 | GNUNET_CONTAINER_DLL_remove (h->z_head, h->z_tail, ze); |
317 | if (NULL != ze->env) | 320 | if (NULL != ze->env) |
318 | GNUNET_MQ_discard(ze->env); | 321 | GNUNET_MQ_discard (ze->env); |
319 | GNUNET_free(ze); | 322 | GNUNET_free (ze); |
320 | } | 323 | } |
321 | 324 | ||
322 | 325 | ||
@@ -330,16 +333,16 @@ free_ze(struct GNUNET_NAMESTORE_ZoneIterator *ze) | |||
330 | * @return #GNUNET_OK if @a rd_buf is well-formed | 333 | * @return #GNUNET_OK if @a rd_buf is well-formed |
331 | */ | 334 | */ |
332 | static int | 335 | static int |
333 | check_rd(size_t rd_len, const void *rd_buf, unsigned int rd_count) | 336 | check_rd (size_t rd_len, const void *rd_buf, unsigned int rd_count) |
334 | { | 337 | { |
335 | struct GNUNET_GNSRECORD_Data rd[rd_count]; | 338 | struct GNUNET_GNSRECORD_Data rd[rd_count]; |
336 | 339 | ||
337 | if (GNUNET_OK != | 340 | if (GNUNET_OK != |
338 | GNUNET_GNSRECORD_records_deserialize(rd_len, rd_buf, rd_count, rd)) | 341 | GNUNET_GNSRECORD_records_deserialize (rd_len, rd_buf, rd_count, rd)) |
339 | { | 342 | { |
340 | GNUNET_break(0); | 343 | GNUNET_break (0); |
341 | return GNUNET_SYSERR; | 344 | return GNUNET_SYSERR; |
342 | } | 345 | } |
343 | return GNUNET_OK; | 346 | return GNUNET_OK; |
344 | } | 347 | } |
345 | 348 | ||
@@ -352,27 +355,27 @@ check_rd(size_t rd_len, const void *rd_buf, unsigned int rd_count) | |||
352 | * @param msg the message we received | 355 | * @param msg the message we received |
353 | */ | 356 | */ |
354 | static void | 357 | static void |
355 | handle_record_store_response(void *cls, | 358 | handle_record_store_response (void *cls, |
356 | const struct RecordStoreResponseMessage *msg) | 359 | const struct RecordStoreResponseMessage *msg) |
357 | { | 360 | { |
358 | struct GNUNET_NAMESTORE_Handle *h = cls; | 361 | struct GNUNET_NAMESTORE_Handle *h = cls; |
359 | struct GNUNET_NAMESTORE_QueueEntry *qe; | 362 | struct GNUNET_NAMESTORE_QueueEntry *qe; |
360 | int res; | 363 | int res; |
361 | const char *emsg; | 364 | const char *emsg; |
362 | 365 | ||
363 | qe = find_qe(h, ntohl(msg->gns_header.r_id)); | 366 | qe = find_qe (h, ntohl (msg->gns_header.r_id)); |
364 | res = ntohl(msg->op_result); | 367 | res = ntohl (msg->op_result); |
365 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 368 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
366 | "Received RECORD_STORE_RESPONSE with result %d\n", | 369 | "Received RECORD_STORE_RESPONSE with result %d\n", |
367 | res); | 370 | res); |
368 | /* TODO: add actual error message from namestore to response... */ | 371 | /* TODO: add actual error message from namestore to response... */ |
369 | if (GNUNET_SYSERR == res) | 372 | if (GNUNET_SYSERR == res) |
370 | emsg = _("Namestore failed to store record\n"); | 373 | emsg = _ ("Namestore failed to store record\n"); |
371 | else | 374 | else |
372 | emsg = NULL; | 375 | emsg = NULL; |
373 | if (NULL != qe->cont) | 376 | if (NULL != qe->cont) |
374 | qe->cont(qe->cont_cls, res, emsg); | 377 | qe->cont (qe->cont_cls, res, emsg); |
375 | free_qe(qe); | 378 | free_qe (qe); |
376 | } | 379 | } |
377 | 380 | ||
378 | 381 | ||
@@ -385,7 +388,7 @@ handle_record_store_response(void *cls, | |||
385 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 388 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
386 | */ | 389 | */ |
387 | static int | 390 | static int |
388 | check_lookup_result(void *cls, const struct LabelLookupResponseMessage *msg) | 391 | check_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg) |
389 | { | 392 | { |
390 | const char *name; | 393 | const char *name; |
391 | size_t exp_msg_len; | 394 | size_t exp_msg_len; |
@@ -393,32 +396,32 @@ check_lookup_result(void *cls, const struct LabelLookupResponseMessage *msg) | |||
393 | size_t name_len; | 396 | size_t name_len; |
394 | size_t rd_len; | 397 | size_t rd_len; |
395 | 398 | ||
396 | (void)cls; | 399 | (void) cls; |
397 | rd_len = ntohs(msg->rd_len); | 400 | rd_len = ntohs (msg->rd_len); |
398 | msg_len = ntohs(msg->gns_header.header.size); | 401 | msg_len = ntohs (msg->gns_header.header.size); |
399 | name_len = ntohs(msg->name_len); | 402 | name_len = ntohs (msg->name_len); |
400 | exp_msg_len = sizeof(*msg) + name_len + rd_len; | 403 | exp_msg_len = sizeof(*msg) + name_len + rd_len; |
401 | if (msg_len != exp_msg_len) | 404 | if (msg_len != exp_msg_len) |
402 | { | 405 | { |
403 | GNUNET_break(0); | 406 | GNUNET_break (0); |
404 | return GNUNET_SYSERR; | 407 | return GNUNET_SYSERR; |
405 | } | 408 | } |
406 | name = (const char *)&msg[1]; | 409 | name = (const char *) &msg[1]; |
407 | if ((name_len > 0) && ('\0' != name[name_len - 1])) | 410 | if ((name_len > 0) && ('\0' != name[name_len - 1])) |
411 | { | ||
412 | GNUNET_break (0); | ||
413 | return GNUNET_SYSERR; | ||
414 | } | ||
415 | if (GNUNET_NO == ntohs (msg->found)) | ||
416 | { | ||
417 | if (0 != ntohs (msg->rd_count)) | ||
408 | { | 418 | { |
409 | GNUNET_break(0); | 419 | GNUNET_break (0); |
410 | return GNUNET_SYSERR; | 420 | return GNUNET_SYSERR; |
411 | } | 421 | } |
412 | if (GNUNET_NO == ntohs(msg->found)) | 422 | return GNUNET_OK; |
413 | { | 423 | } |
414 | if (0 != ntohs(msg->rd_count)) | 424 | return check_rd (rd_len, &name[name_len], ntohs (msg->rd_count)); |
415 | { | ||
416 | GNUNET_break(0); | ||
417 | return GNUNET_SYSERR; | ||
418 | } | ||
419 | return GNUNET_OK; | ||
420 | } | ||
421 | return check_rd(rd_len, &name[name_len], ntohs(msg->rd_count)); | ||
422 | } | 425 | } |
423 | 426 | ||
424 | 427 | ||
@@ -430,7 +433,7 @@ check_lookup_result(void *cls, const struct LabelLookupResponseMessage *msg) | |||
430 | * @param msg the message we received | 433 | * @param msg the message we received |
431 | */ | 434 | */ |
432 | static void | 435 | static void |
433 | handle_lookup_result(void *cls, const struct LabelLookupResponseMessage *msg) | 436 | handle_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg) |
434 | { | 437 | { |
435 | struct GNUNET_NAMESTORE_Handle *h = cls; | 438 | struct GNUNET_NAMESTORE_Handle *h = cls; |
436 | struct GNUNET_NAMESTORE_QueueEntry *qe; | 439 | struct GNUNET_NAMESTORE_QueueEntry *qe; |
@@ -440,40 +443,40 @@ handle_lookup_result(void *cls, const struct LabelLookupResponseMessage *msg) | |||
440 | size_t rd_len; | 443 | size_t rd_len; |
441 | unsigned int rd_count; | 444 | unsigned int rd_count; |
442 | 445 | ||
443 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_LOOKUP_RESULT\n"); | 446 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_LOOKUP_RESULT\n"); |
444 | qe = find_qe(h, ntohl(msg->gns_header.r_id)); | 447 | qe = find_qe (h, ntohl (msg->gns_header.r_id)); |
445 | if (NULL == qe) | 448 | if (NULL == qe) |
446 | return; | 449 | return; |
447 | rd_len = ntohs(msg->rd_len); | 450 | rd_len = ntohs (msg->rd_len); |
448 | rd_count = ntohs(msg->rd_count); | 451 | rd_count = ntohs (msg->rd_count); |
449 | name_len = ntohs(msg->name_len); | 452 | name_len = ntohs (msg->name_len); |
450 | name = (const char *)&msg[1]; | 453 | name = (const char *) &msg[1]; |
451 | if (GNUNET_NO == ntohs(msg->found)) | 454 | if (GNUNET_NO == ntohs (msg->found)) |
452 | { | 455 | { |
453 | /* label was not in namestore */ | 456 | /* label was not in namestore */ |
454 | if (NULL != qe->proc) | 457 | if (NULL != qe->proc) |
455 | qe->proc(qe->proc_cls, &msg->private_key, name, 0, NULL); | 458 | qe->proc (qe->proc_cls, &msg->private_key, name, 0, NULL); |
456 | free_qe(qe); | 459 | free_qe (qe); |
457 | return; | 460 | return; |
458 | } | 461 | } |
459 | 462 | ||
460 | rd_tmp = &name[name_len]; | 463 | rd_tmp = &name[name_len]; |
461 | { | 464 | { |
462 | struct GNUNET_GNSRECORD_Data rd[rd_count]; | 465 | struct GNUNET_GNSRECORD_Data rd[rd_count]; |
463 | 466 | ||
464 | GNUNET_assert( | 467 | GNUNET_assert ( |
465 | GNUNET_OK == | 468 | GNUNET_OK == |
466 | GNUNET_GNSRECORD_records_deserialize(rd_len, rd_tmp, rd_count, rd)); | 469 | GNUNET_GNSRECORD_records_deserialize (rd_len, rd_tmp, rd_count, rd)); |
467 | if (0 == name_len) | 470 | if (0 == name_len) |
468 | name = NULL; | 471 | name = NULL; |
469 | if (NULL != qe->proc) | 472 | if (NULL != qe->proc) |
470 | qe->proc(qe->proc_cls, | 473 | qe->proc (qe->proc_cls, |
471 | &msg->private_key, | 474 | &msg->private_key, |
472 | name, | 475 | name, |
473 | rd_count, | 476 | rd_count, |
474 | (rd_count > 0) ? rd : NULL); | 477 | (rd_count > 0) ? rd : NULL); |
475 | } | 478 | } |
476 | free_qe(qe); | 479 | free_qe (qe); |
477 | } | 480 | } |
478 | 481 | ||
479 | 482 | ||
@@ -486,7 +489,7 @@ handle_lookup_result(void *cls, const struct LabelLookupResponseMessage *msg) | |||
486 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 489 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
487 | */ | 490 | */ |
488 | static int | 491 | static int |
489 | check_record_result(void *cls, const struct RecordResultMessage *msg) | 492 | check_record_result (void *cls, const struct RecordResultMessage *msg) |
490 | { | 493 | { |
491 | static struct GNUNET_CRYPTO_EcdsaPrivateKey priv_dummy; | 494 | static struct GNUNET_CRYPTO_EcdsaPrivateKey priv_dummy; |
492 | const char *name; | 495 | const char *name; |
@@ -494,32 +497,32 @@ check_record_result(void *cls, const struct RecordResultMessage *msg) | |||
494 | size_t name_len; | 497 | size_t name_len; |
495 | size_t rd_len; | 498 | size_t rd_len; |
496 | 499 | ||
497 | (void)cls; | 500 | (void) cls; |
498 | rd_len = ntohs(msg->rd_len); | 501 | rd_len = ntohs (msg->rd_len); |
499 | msg_len = ntohs(msg->gns_header.header.size); | 502 | msg_len = ntohs (msg->gns_header.header.size); |
500 | name_len = ntohs(msg->name_len); | 503 | name_len = ntohs (msg->name_len); |
501 | if (0 != ntohs(msg->reserved)) | 504 | if (0 != ntohs (msg->reserved)) |
502 | { | 505 | { |
503 | GNUNET_break(0); | 506 | GNUNET_break (0); |
504 | return GNUNET_SYSERR; | 507 | return GNUNET_SYSERR; |
505 | } | 508 | } |
506 | if (msg_len != sizeof(struct RecordResultMessage) + name_len + rd_len) | 509 | if (msg_len != sizeof(struct RecordResultMessage) + name_len + rd_len) |
507 | { | 510 | { |
508 | GNUNET_break(0); | 511 | GNUNET_break (0); |
509 | return GNUNET_SYSERR; | 512 | return GNUNET_SYSERR; |
510 | } | 513 | } |
511 | name = (const char *)&msg[1]; | 514 | name = (const char *) &msg[1]; |
512 | if ((0 == name_len) || ('\0' != name[name_len - 1])) | 515 | if ((0 == name_len) || ('\0' != name[name_len - 1])) |
513 | { | 516 | { |
514 | GNUNET_break(0); | 517 | GNUNET_break (0); |
515 | return GNUNET_SYSERR; | 518 | return GNUNET_SYSERR; |
516 | } | 519 | } |
517 | if (0 == GNUNET_memcmp(&msg->private_key, &priv_dummy)) | 520 | if (0 == GNUNET_memcmp (&msg->private_key, &priv_dummy)) |
518 | { | 521 | { |
519 | GNUNET_break(0); | 522 | GNUNET_break (0); |
520 | return GNUNET_SYSERR; | 523 | return GNUNET_SYSERR; |
521 | } | 524 | } |
522 | return check_rd(rd_len, &name[name_len], ntohs(msg->rd_count)); | 525 | return check_rd (rd_len, &name[name_len], ntohs (msg->rd_count)); |
523 | } | 526 | } |
524 | 527 | ||
525 | 528 | ||
@@ -531,7 +534,7 @@ check_record_result(void *cls, const struct RecordResultMessage *msg) | |||
531 | * @param msg the message we received | 534 | * @param msg the message we received |
532 | */ | 535 | */ |
533 | static void | 536 | static void |
534 | handle_record_result(void *cls, const struct RecordResultMessage *msg) | 537 | handle_record_result (void *cls, const struct RecordResultMessage *msg) |
535 | { | 538 | { |
536 | struct GNUNET_NAMESTORE_Handle *h = cls; | 539 | struct GNUNET_NAMESTORE_Handle *h = cls; |
537 | struct GNUNET_NAMESTORE_QueueEntry *qe; | 540 | struct GNUNET_NAMESTORE_QueueEntry *qe; |
@@ -542,49 +545,49 @@ handle_record_result(void *cls, const struct RecordResultMessage *msg) | |||
542 | size_t rd_len; | 545 | size_t rd_len; |
543 | unsigned int rd_count; | 546 | unsigned int rd_count; |
544 | 547 | ||
545 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_RESULT\n"); | 548 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_RESULT\n"); |
546 | rd_len = ntohs(msg->rd_len); | 549 | rd_len = ntohs (msg->rd_len); |
547 | rd_count = ntohs(msg->rd_count); | 550 | rd_count = ntohs (msg->rd_count); |
548 | name_len = ntohs(msg->name_len); | 551 | name_len = ntohs (msg->name_len); |
549 | ze = find_zi(h, ntohl(msg->gns_header.r_id)); | 552 | ze = find_zi (h, ntohl (msg->gns_header.r_id)); |
550 | qe = find_qe(h, ntohl(msg->gns_header.r_id)); | 553 | qe = find_qe (h, ntohl (msg->gns_header.r_id)); |
551 | if ((NULL == ze) && (NULL == qe)) | 554 | if ((NULL == ze) && (NULL == qe)) |
552 | return; /* rid not found */ | 555 | return; /* rid not found */ |
553 | if ((NULL != ze) && (NULL != qe)) | 556 | if ((NULL != ze) && (NULL != qe)) |
554 | { | 557 | { |
555 | GNUNET_break(0); /* rid ambigous */ | 558 | GNUNET_break (0); /* rid ambigous */ |
556 | force_reconnect(h); | 559 | force_reconnect (h); |
557 | return; | 560 | return; |
558 | } | 561 | } |
559 | name = (const char *)&msg[1]; | 562 | name = (const char *) &msg[1]; |
560 | rd_tmp = &name[name_len]; | 563 | rd_tmp = &name[name_len]; |
561 | { | 564 | { |
562 | struct GNUNET_GNSRECORD_Data rd[rd_count]; | 565 | struct GNUNET_GNSRECORD_Data rd[rd_count]; |
563 | 566 | ||
564 | GNUNET_assert( | 567 | GNUNET_assert ( |
565 | GNUNET_OK == | 568 | GNUNET_OK == |
566 | GNUNET_GNSRECORD_records_deserialize(rd_len, rd_tmp, rd_count, rd)); | 569 | GNUNET_GNSRECORD_records_deserialize (rd_len, rd_tmp, rd_count, rd)); |
567 | if (0 == name_len) | 570 | if (0 == name_len) |
568 | name = NULL; | 571 | name = NULL; |
569 | if (NULL != qe) | 572 | if (NULL != qe) |
570 | { | 573 | { |
571 | if (NULL != qe->proc) | 574 | if (NULL != qe->proc) |
572 | qe->proc(qe->proc_cls, | 575 | qe->proc (qe->proc_cls, |
573 | &msg->private_key, | 576 | &msg->private_key, |
574 | name, | 577 | name, |
575 | rd_count, | 578 | rd_count, |
576 | (rd_count > 0) ? rd : NULL); | 579 | (rd_count > 0) ? rd : NULL); |
577 | free_qe(qe); | 580 | free_qe (qe); |
578 | return; | 581 | return; |
579 | } | 582 | } |
580 | if (NULL != ze) | 583 | if (NULL != ze) |
581 | { | 584 | { |
582 | if (NULL != ze->proc) | 585 | if (NULL != ze->proc) |
583 | ze->proc(ze->proc_cls, &msg->private_key, name, rd_count, rd); | 586 | ze->proc (ze->proc_cls, &msg->private_key, name, rd_count, rd); |
584 | return; | 587 | return; |
585 | } | 588 | } |
586 | } | 589 | } |
587 | GNUNET_assert(0); | 590 | GNUNET_assert (0); |
588 | } | 591 | } |
589 | 592 | ||
590 | 593 | ||
@@ -596,33 +599,33 @@ handle_record_result(void *cls, const struct RecordResultMessage *msg) | |||
596 | * @param msg the message we received | 599 | * @param msg the message we received |
597 | */ | 600 | */ |
598 | static void | 601 | static void |
599 | handle_record_result_end(void *cls, const struct GNUNET_NAMESTORE_Header *msg) | 602 | handle_record_result_end (void *cls, const struct GNUNET_NAMESTORE_Header *msg) |
600 | { | 603 | { |
601 | struct GNUNET_NAMESTORE_Handle *h = cls; | 604 | struct GNUNET_NAMESTORE_Handle *h = cls; |
602 | struct GNUNET_NAMESTORE_QueueEntry *qe; | 605 | struct GNUNET_NAMESTORE_QueueEntry *qe; |
603 | struct GNUNET_NAMESTORE_ZoneIterator *ze; | 606 | struct GNUNET_NAMESTORE_ZoneIterator *ze; |
604 | 607 | ||
605 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_RESULT_END\n"); | 608 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_RESULT_END\n"); |
606 | ze = find_zi(h, ntohl(msg->r_id)); | 609 | ze = find_zi (h, ntohl (msg->r_id)); |
607 | qe = find_qe(h, ntohl(msg->r_id)); | 610 | qe = find_qe (h, ntohl (msg->r_id)); |
608 | if ((NULL == ze) && (NULL == qe)) | 611 | if ((NULL == ze) && (NULL == qe)) |
609 | return; /* rid not found */ | 612 | return; /* rid not found */ |
610 | if ((NULL != ze) && (NULL != qe)) | 613 | if ((NULL != ze) && (NULL != qe)) |
611 | { | 614 | { |
612 | GNUNET_break(0); /* rid ambigous */ | 615 | GNUNET_break (0); /* rid ambigous */ |
613 | force_reconnect(h); | 616 | force_reconnect (h); |
614 | return; | 617 | return; |
615 | } | 618 | } |
616 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Zone iteration completed!\n"); | 619 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Zone iteration completed!\n"); |
617 | if (NULL == ze) | 620 | if (NULL == ze) |
618 | { | 621 | { |
619 | GNUNET_break(0); | 622 | GNUNET_break (0); |
620 | force_reconnect(h); | 623 | force_reconnect (h); |
621 | return; | 624 | return; |
622 | } | 625 | } |
623 | if (NULL != ze->finish_cb) | 626 | if (NULL != ze->finish_cb) |
624 | ze->finish_cb(ze->finish_cb_cls); | 627 | ze->finish_cb (ze->finish_cb_cls); |
625 | free_ze(ze); | 628 | free_ze (ze); |
626 | } | 629 | } |
627 | 630 | ||
628 | 631 | ||
@@ -635,31 +638,31 @@ handle_record_result_end(void *cls, const struct GNUNET_NAMESTORE_Header *msg) | |||
635 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if message malformed | 638 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if message malformed |
636 | */ | 639 | */ |
637 | static int | 640 | static int |
638 | check_zone_to_name_response(void *cls, | 641 | check_zone_to_name_response (void *cls, |
639 | const struct ZoneToNameResponseMessage *msg) | 642 | const struct ZoneToNameResponseMessage *msg) |
640 | { | 643 | { |
641 | size_t name_len; | 644 | size_t name_len; |
642 | size_t rd_ser_len; | 645 | size_t rd_ser_len; |
643 | const char *name_tmp; | 646 | const char *name_tmp; |
644 | 647 | ||
645 | (void)cls; | 648 | (void) cls; |
646 | if (GNUNET_OK != ntohs(msg->res)) | 649 | if (GNUNET_OK != ntohs (msg->res)) |
647 | return GNUNET_OK; | 650 | return GNUNET_OK; |
648 | name_len = ntohs(msg->name_len); | 651 | name_len = ntohs (msg->name_len); |
649 | rd_ser_len = ntohs(msg->rd_len); | 652 | rd_ser_len = ntohs (msg->rd_len); |
650 | if (ntohs(msg->gns_header.header.size) != | 653 | if (ntohs (msg->gns_header.header.size) != |
651 | sizeof(struct ZoneToNameResponseMessage) + name_len + rd_ser_len) | 654 | sizeof(struct ZoneToNameResponseMessage) + name_len + rd_ser_len) |
652 | { | 655 | { |
653 | GNUNET_break(0); | 656 | GNUNET_break (0); |
654 | return GNUNET_SYSERR; | 657 | return GNUNET_SYSERR; |
655 | } | 658 | } |
656 | name_tmp = (const char *)&msg[1]; | 659 | name_tmp = (const char *) &msg[1]; |
657 | if ((name_len > 0) && ('\0' != name_tmp[name_len - 1])) | 660 | if ((name_len > 0) && ('\0' != name_tmp[name_len - 1])) |
658 | { | 661 | { |
659 | GNUNET_break(0); | 662 | GNUNET_break (0); |
660 | return GNUNET_SYSERR; | 663 | return GNUNET_SYSERR; |
661 | } | 664 | } |
662 | return check_rd(rd_ser_len, &name_tmp[name_len], ntohs(msg->rd_count)); | 665 | return check_rd (rd_ser_len, &name_tmp[name_len], ntohs (msg->rd_count)); |
663 | } | 666 | } |
664 | 667 | ||
665 | 668 | ||
@@ -671,8 +674,8 @@ check_zone_to_name_response(void *cls, | |||
671 | * @param msg the message we received | 674 | * @param msg the message we received |
672 | */ | 675 | */ |
673 | static void | 676 | static void |
674 | handle_zone_to_name_response(void *cls, | 677 | handle_zone_to_name_response (void *cls, |
675 | const struct ZoneToNameResponseMessage *msg) | 678 | const struct ZoneToNameResponseMessage *msg) |
676 | { | 679 | { |
677 | struct GNUNET_NAMESTORE_Handle *h = cls; | 680 | struct GNUNET_NAMESTORE_Handle *h = cls; |
678 | struct GNUNET_NAMESTORE_QueueEntry *qe; | 681 | struct GNUNET_NAMESTORE_QueueEntry *qe; |
@@ -683,57 +686,57 @@ handle_zone_to_name_response(void *cls, | |||
683 | const char *name_tmp; | 686 | const char *name_tmp; |
684 | const char *rd_tmp; | 687 | const char *rd_tmp; |
685 | 688 | ||
686 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_TO_NAME_RESPONSE\n"); | 689 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_TO_NAME_RESPONSE\n"); |
687 | qe = find_qe(h, ntohl(msg->gns_header.r_id)); | 690 | qe = find_qe (h, ntohl (msg->gns_header.r_id)); |
688 | res = ntohs(msg->res); | 691 | res = ntohs (msg->res); |
689 | switch (res) | 692 | switch (res) |
693 | { | ||
694 | case GNUNET_SYSERR: | ||
695 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
696 | "An error occurred during zone to name operation\n"); | ||
697 | break; | ||
698 | |||
699 | case GNUNET_NO: | ||
700 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
701 | "Namestore has no result for zone to name mapping \n"); | ||
702 | if (NULL != qe->proc) | ||
703 | qe->proc (qe->proc_cls, &msg->zone, NULL, 0, NULL); | ||
704 | free_qe (qe); | ||
705 | return; | ||
706 | |||
707 | case GNUNET_YES: | ||
708 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
709 | "Namestore has result for zone to name mapping \n"); | ||
710 | name_len = ntohs (msg->name_len); | ||
711 | rd_count = ntohs (msg->rd_count); | ||
712 | rd_ser_len = ntohs (msg->rd_len); | ||
713 | name_tmp = (const char *) &msg[1]; | ||
714 | rd_tmp = &name_tmp[name_len]; | ||
690 | { | 715 | { |
691 | case GNUNET_SYSERR: | 716 | struct GNUNET_GNSRECORD_Data rd[rd_count]; |
692 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
693 | "An error occurred during zone to name operation\n"); | ||
694 | break; | ||
695 | |||
696 | case GNUNET_NO: | ||
697 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
698 | "Namestore has no result for zone to name mapping \n"); | ||
699 | if (NULL != qe->proc) | ||
700 | qe->proc(qe->proc_cls, &msg->zone, NULL, 0, NULL); | ||
701 | free_qe(qe); | ||
702 | return; | ||
703 | 717 | ||
704 | case GNUNET_YES: | 718 | GNUNET_assert (GNUNET_OK == |
705 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 719 | GNUNET_GNSRECORD_records_deserialize (rd_ser_len, |
706 | "Namestore has result for zone to name mapping \n"); | ||
707 | name_len = ntohs(msg->name_len); | ||
708 | rd_count = ntohs(msg->rd_count); | ||
709 | rd_ser_len = ntohs(msg->rd_len); | ||
710 | name_tmp = (const char *)&msg[1]; | ||
711 | rd_tmp = &name_tmp[name_len]; | ||
712 | { | ||
713 | struct GNUNET_GNSRECORD_Data rd[rd_count]; | ||
714 | |||
715 | GNUNET_assert(GNUNET_OK == | ||
716 | GNUNET_GNSRECORD_records_deserialize(rd_ser_len, | ||
717 | rd_tmp, | 720 | rd_tmp, |
718 | rd_count, | 721 | rd_count, |
719 | rd)); | 722 | rd)); |
720 | /* normal end, call continuation with result */ | 723 | /* normal end, call continuation with result */ |
721 | if (NULL != qe->proc) | 724 | if (NULL != qe->proc) |
722 | qe->proc(qe->proc_cls, &msg->zone, name_tmp, rd_count, rd); | 725 | qe->proc (qe->proc_cls, &msg->zone, name_tmp, rd_count, rd); |
723 | /* return is important here: break would call continuation with error! */ | 726 | /* return is important here: break would call continuation with error! */ |
724 | free_qe(qe); | 727 | free_qe (qe); |
725 | return; | ||
726 | } | ||
727 | |||
728 | default: | ||
729 | GNUNET_break(0); | ||
730 | force_reconnect(h); | ||
731 | return; | 728 | return; |
732 | } | 729 | } |
730 | |||
731 | default: | ||
732 | GNUNET_break (0); | ||
733 | force_reconnect (h); | ||
734 | return; | ||
735 | } | ||
733 | /* error case, call continuation with error */ | 736 | /* error case, call continuation with error */ |
734 | if (NULL != qe->error_cb) | 737 | if (NULL != qe->error_cb) |
735 | qe->error_cb(qe->error_cb_cls); | 738 | qe->error_cb (qe->error_cb_cls); |
736 | free_qe(qe); | 739 | free_qe (qe); |
737 | } | 740 | } |
738 | 741 | ||
739 | 742 | ||
@@ -746,12 +749,12 @@ handle_zone_to_name_response(void *cls, | |||
746 | * @param error error code | 749 | * @param error error code |
747 | */ | 750 | */ |
748 | static void | 751 | static void |
749 | mq_error_handler(void *cls, enum GNUNET_MQ_Error error) | 752 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
750 | { | 753 | { |
751 | struct GNUNET_NAMESTORE_Handle *h = cls; | 754 | struct GNUNET_NAMESTORE_Handle *h = cls; |
752 | 755 | ||
753 | (void)error; | 756 | (void) error; |
754 | force_reconnect(h); | 757 | force_reconnect (h); |
755 | } | 758 | } |
756 | 759 | ||
757 | 760 | ||
@@ -761,49 +764,49 @@ mq_error_handler(void *cls, enum GNUNET_MQ_Error error) | |||
761 | * @param h the handle to the NAMESTORE service | 764 | * @param h the handle to the NAMESTORE service |
762 | */ | 765 | */ |
763 | static void | 766 | static void |
764 | reconnect(struct GNUNET_NAMESTORE_Handle *h) | 767 | reconnect (struct GNUNET_NAMESTORE_Handle *h) |
765 | { | 768 | { |
766 | struct GNUNET_MQ_MessageHandler handlers[] = | 769 | struct GNUNET_MQ_MessageHandler handlers[] = |
767 | { GNUNET_MQ_hd_fixed_size(record_store_response, | 770 | { GNUNET_MQ_hd_fixed_size (record_store_response, |
768 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE, | 771 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE, |
769 | struct RecordStoreResponseMessage, | 772 | struct RecordStoreResponseMessage, |
770 | h), | 773 | h), |
771 | GNUNET_MQ_hd_var_size(zone_to_name_response, | 774 | GNUNET_MQ_hd_var_size (zone_to_name_response, |
772 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE, | 775 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE, |
773 | struct ZoneToNameResponseMessage, | 776 | struct ZoneToNameResponseMessage, |
774 | h), | 777 | h), |
775 | GNUNET_MQ_hd_var_size(record_result, | 778 | GNUNET_MQ_hd_var_size (record_result, |
776 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT, | 779 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT, |
777 | struct RecordResultMessage, | 780 | struct RecordResultMessage, |
778 | h), | 781 | h), |
779 | GNUNET_MQ_hd_fixed_size(record_result_end, | 782 | GNUNET_MQ_hd_fixed_size (record_result_end, |
780 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT_END, | 783 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT_END, |
781 | struct GNUNET_NAMESTORE_Header, | 784 | struct GNUNET_NAMESTORE_Header, |
782 | h), | 785 | h), |
783 | GNUNET_MQ_hd_var_size(lookup_result, | 786 | GNUNET_MQ_hd_var_size (lookup_result, |
784 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE, | 787 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE, |
785 | struct LabelLookupResponseMessage, | 788 | struct LabelLookupResponseMessage, |
786 | h), | 789 | h), |
787 | GNUNET_MQ_handler_end() }; | 790 | GNUNET_MQ_handler_end () }; |
788 | struct GNUNET_NAMESTORE_ZoneIterator *it; | 791 | struct GNUNET_NAMESTORE_ZoneIterator *it; |
789 | struct GNUNET_NAMESTORE_QueueEntry *qe; | 792 | struct GNUNET_NAMESTORE_QueueEntry *qe; |
790 | 793 | ||
791 | GNUNET_assert(NULL == h->mq); | 794 | GNUNET_assert (NULL == h->mq); |
792 | h->mq = | 795 | h->mq = |
793 | GNUNET_CLIENT_connect(h->cfg, "namestore", handlers, &mq_error_handler, h); | 796 | GNUNET_CLIENT_connect (h->cfg, "namestore", handlers, &mq_error_handler, h); |
794 | if (NULL == h->mq) | 797 | if (NULL == h->mq) |
795 | return; | 798 | return; |
796 | /* re-transmit pending requests that waited for a reconnect... */ | 799 | /* re-transmit pending requests that waited for a reconnect... */ |
797 | for (it = h->z_head; NULL != it; it = it->next) | 800 | for (it = h->z_head; NULL != it; it = it->next) |
798 | { | 801 | { |
799 | GNUNET_MQ_send(h->mq, it->env); | 802 | GNUNET_MQ_send (h->mq, it->env); |
800 | it->env = NULL; | 803 | it->env = NULL; |
801 | } | 804 | } |
802 | for (qe = h->op_head; NULL != qe; qe = qe->next) | 805 | for (qe = h->op_head; NULL != qe; qe = qe->next) |
803 | { | 806 | { |
804 | GNUNET_MQ_send(h->mq, qe->env); | 807 | GNUNET_MQ_send (h->mq, qe->env); |
805 | qe->env = NULL; | 808 | qe->env = NULL; |
806 | } | 809 | } |
807 | } | 810 | } |
808 | 811 | ||
809 | 812 | ||
@@ -813,12 +816,12 @@ reconnect(struct GNUNET_NAMESTORE_Handle *h) | |||
813 | * @param cls handle to use to re-connect. | 816 | * @param cls handle to use to re-connect. |
814 | */ | 817 | */ |
815 | static void | 818 | static void |
816 | reconnect_task(void *cls) | 819 | reconnect_task (void *cls) |
817 | { | 820 | { |
818 | struct GNUNET_NAMESTORE_Handle *h = cls; | 821 | struct GNUNET_NAMESTORE_Handle *h = cls; |
819 | 822 | ||
820 | h->reconnect_task = NULL; | 823 | h->reconnect_task = NULL; |
821 | reconnect(h); | 824 | reconnect (h); |
822 | } | 825 | } |
823 | 826 | ||
824 | 827 | ||
@@ -828,34 +831,34 @@ reconnect_task(void *cls) | |||
828 | * @param h our handle | 831 | * @param h our handle |
829 | */ | 832 | */ |
830 | static void | 833 | static void |
831 | force_reconnect(struct GNUNET_NAMESTORE_Handle *h) | 834 | force_reconnect (struct GNUNET_NAMESTORE_Handle *h) |
832 | { | 835 | { |
833 | struct GNUNET_NAMESTORE_ZoneIterator *ze; | 836 | struct GNUNET_NAMESTORE_ZoneIterator *ze; |
834 | struct GNUNET_NAMESTORE_QueueEntry *qe; | 837 | struct GNUNET_NAMESTORE_QueueEntry *qe; |
835 | 838 | ||
836 | GNUNET_MQ_destroy(h->mq); | 839 | GNUNET_MQ_destroy (h->mq); |
837 | h->mq = NULL; | 840 | h->mq = NULL; |
838 | while (NULL != (ze = h->z_head)) | 841 | while (NULL != (ze = h->z_head)) |
839 | { | 842 | { |
840 | if (NULL != ze->error_cb) | 843 | if (NULL != ze->error_cb) |
841 | ze->error_cb(ze->error_cb_cls); | 844 | ze->error_cb (ze->error_cb_cls); |
842 | free_ze(ze); | 845 | free_ze (ze); |
843 | } | 846 | } |
844 | while (NULL != (qe = h->op_head)) | 847 | while (NULL != (qe = h->op_head)) |
845 | { | 848 | { |
846 | if (NULL != qe->error_cb) | 849 | if (NULL != qe->error_cb) |
847 | qe->error_cb(qe->error_cb_cls); | 850 | qe->error_cb (qe->error_cb_cls); |
848 | if (NULL != qe->cont) | 851 | if (NULL != qe->cont) |
849 | qe->cont(qe->cont_cls, | 852 | qe->cont (qe->cont_cls, |
850 | GNUNET_SYSERR, | 853 | GNUNET_SYSERR, |
851 | "failure in communication with namestore service"); | 854 | "failure in communication with namestore service"); |
852 | free_qe(qe); | 855 | free_qe (qe); |
853 | } | 856 | } |
854 | 857 | ||
855 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Reconnecting to namestore\n"); | 858 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting to namestore\n"); |
856 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF(h->reconnect_delay); | 859 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); |
857 | h->reconnect_task = | 860 | h->reconnect_task = |
858 | GNUNET_SCHEDULER_add_delayed(h->reconnect_delay, &reconnect_task, h); | 861 | GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect_task, h); |
859 | } | 862 | } |
860 | 863 | ||
861 | 864 | ||
@@ -866,7 +869,7 @@ force_reconnect(struct GNUNET_NAMESTORE_Handle *h) | |||
866 | * @return next operation id to use | 869 | * @return next operation id to use |
867 | */ | 870 | */ |
868 | static uint32_t | 871 | static uint32_t |
869 | get_op_id(struct GNUNET_NAMESTORE_Handle *h) | 872 | get_op_id (struct GNUNET_NAMESTORE_Handle *h) |
870 | { | 873 | { |
871 | return h->last_op_id_used++; | 874 | return h->last_op_id_used++; |
872 | } | 875 | } |
@@ -879,18 +882,18 @@ get_op_id(struct GNUNET_NAMESTORE_Handle *h) | |||
879 | * @return handle to the GNS service, or NULL on error | 882 | * @return handle to the GNS service, or NULL on error |
880 | */ | 883 | */ |
881 | struct GNUNET_NAMESTORE_Handle * | 884 | struct GNUNET_NAMESTORE_Handle * |
882 | GNUNET_NAMESTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg) | 885 | GNUNET_NAMESTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) |
883 | { | 886 | { |
884 | struct GNUNET_NAMESTORE_Handle *h; | 887 | struct GNUNET_NAMESTORE_Handle *h; |
885 | 888 | ||
886 | h = GNUNET_new(struct GNUNET_NAMESTORE_Handle); | 889 | h = GNUNET_new (struct GNUNET_NAMESTORE_Handle); |
887 | h->cfg = cfg; | 890 | h->cfg = cfg; |
888 | reconnect(h); | 891 | reconnect (h); |
889 | if (NULL == h->mq) | 892 | if (NULL == h->mq) |
890 | { | 893 | { |
891 | GNUNET_free(h); | 894 | GNUNET_free (h); |
892 | return NULL; | 895 | return NULL; |
893 | } | 896 | } |
894 | return h; | 897 | return h; |
895 | } | 898 | } |
896 | 899 | ||
@@ -902,35 +905,35 @@ GNUNET_NAMESTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
902 | * @param h handle to the namestore | 905 | * @param h handle to the namestore |
903 | */ | 906 | */ |
904 | void | 907 | void |
905 | GNUNET_NAMESTORE_disconnect(struct GNUNET_NAMESTORE_Handle *h) | 908 | GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h) |
906 | { | 909 | { |
907 | struct GNUNET_NAMESTORE_QueueEntry *q; | 910 | struct GNUNET_NAMESTORE_QueueEntry *q; |
908 | struct GNUNET_NAMESTORE_ZoneIterator *z; | 911 | struct GNUNET_NAMESTORE_ZoneIterator *z; |
909 | 912 | ||
910 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); | 913 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); |
911 | GNUNET_break(NULL == h->op_head); | 914 | GNUNET_break (NULL == h->op_head); |
912 | while (NULL != (q = h->op_head)) | 915 | while (NULL != (q = h->op_head)) |
913 | { | 916 | { |
914 | GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, q); | 917 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, q); |
915 | GNUNET_free(q); | 918 | GNUNET_free (q); |
916 | } | 919 | } |
917 | GNUNET_break(NULL == h->z_head); | 920 | GNUNET_break (NULL == h->z_head); |
918 | while (NULL != (z = h->z_head)) | 921 | while (NULL != (z = h->z_head)) |
919 | { | 922 | { |
920 | GNUNET_CONTAINER_DLL_remove(h->z_head, h->z_tail, z); | 923 | GNUNET_CONTAINER_DLL_remove (h->z_head, h->z_tail, z); |
921 | GNUNET_free(z); | 924 | GNUNET_free (z); |
922 | } | 925 | } |
923 | if (NULL != h->mq) | 926 | if (NULL != h->mq) |
924 | { | 927 | { |
925 | GNUNET_MQ_destroy(h->mq); | 928 | GNUNET_MQ_destroy (h->mq); |
926 | h->mq = NULL; | 929 | h->mq = NULL; |
927 | } | 930 | } |
928 | if (NULL != h->reconnect_task) | 931 | if (NULL != h->reconnect_task) |
929 | { | 932 | { |
930 | GNUNET_SCHEDULER_cancel(h->reconnect_task); | 933 | GNUNET_SCHEDULER_cancel (h->reconnect_task); |
931 | h->reconnect_task = NULL; | 934 | h->reconnect_task = NULL; |
932 | } | 935 | } |
933 | GNUNET_free(h); | 936 | GNUNET_free (h); |
934 | } | 937 | } |
935 | 938 | ||
936 | 939 | ||
@@ -941,21 +944,21 @@ GNUNET_NAMESTORE_disconnect(struct GNUNET_NAMESTORE_Handle *h) | |||
941 | * @param cls a `struct GNUNET_NAMESTORE_QueueEntry *` | 944 | * @param cls a `struct GNUNET_NAMESTORE_QueueEntry *` |
942 | */ | 945 | */ |
943 | static void | 946 | static void |
944 | warn_delay(void *cls) | 947 | warn_delay (void *cls) |
945 | { | 948 | { |
946 | struct GNUNET_NAMESTORE_QueueEntry *qe = cls; | 949 | struct GNUNET_NAMESTORE_QueueEntry *qe = cls; |
947 | 950 | ||
948 | qe->timeout_task = NULL; | 951 | qe->timeout_task = NULL; |
949 | LOG(GNUNET_ERROR_TYPE_WARNING, | 952 | LOG (GNUNET_ERROR_TYPE_WARNING, |
950 | "Did not receive response from namestore after %s!\n", | 953 | "Did not receive response from namestore after %s!\n", |
951 | GNUNET_STRINGS_relative_time_to_string(NAMESTORE_DELAY_TOLERANCE, | 954 | GNUNET_STRINGS_relative_time_to_string (NAMESTORE_DELAY_TOLERANCE, |
952 | GNUNET_YES)); | 955 | GNUNET_YES)); |
953 | if (NULL != qe->cont) | 956 | if (NULL != qe->cont) |
954 | { | 957 | { |
955 | qe->cont(qe->cont_cls, GNUNET_SYSERR, "timeout"); | 958 | qe->cont (qe->cont_cls, GNUNET_SYSERR, "timeout"); |
956 | qe->cont = NULL; | 959 | qe->cont = NULL; |
957 | } | 960 | } |
958 | GNUNET_NAMESTORE_cancel(qe); | 961 | GNUNET_NAMESTORE_cancel (qe); |
959 | } | 962 | } |
960 | 963 | ||
961 | 964 | ||
@@ -974,7 +977,7 @@ warn_delay(void *cls) | |||
974 | * @return handle to abort the request | 977 | * @return handle to abort the request |
975 | */ | 978 | */ |
976 | struct GNUNET_NAMESTORE_QueueEntry * | 979 | struct GNUNET_NAMESTORE_QueueEntry * |
977 | GNUNET_NAMESTORE_records_store( | 980 | GNUNET_NAMESTORE_records_store ( |
978 | struct GNUNET_NAMESTORE_Handle *h, | 981 | struct GNUNET_NAMESTORE_Handle *h, |
979 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | 982 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, |
980 | const char *label, | 983 | const char *label, |
@@ -993,69 +996,69 @@ GNUNET_NAMESTORE_records_store( | |||
993 | struct RecordStoreMessage *msg; | 996 | struct RecordStoreMessage *msg; |
994 | ssize_t sret; | 997 | ssize_t sret; |
995 | 998 | ||
996 | name_len = strlen(label) + 1; | 999 | name_len = strlen (label) + 1; |
997 | if (name_len > MAX_NAME_LEN) | 1000 | if (name_len > MAX_NAME_LEN) |
998 | { | 1001 | { |
999 | GNUNET_break(0); | 1002 | GNUNET_break (0); |
1000 | return NULL; | 1003 | return NULL; |
1001 | } | 1004 | } |
1002 | rd_ser_len = GNUNET_GNSRECORD_records_get_size(rd_count, rd); | 1005 | rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count, rd); |
1003 | if (rd_ser_len < 0) | 1006 | if (rd_ser_len < 0) |
1004 | { | 1007 | { |
1005 | GNUNET_break(0); | 1008 | GNUNET_break (0); |
1006 | return NULL; | 1009 | return NULL; |
1007 | } | 1010 | } |
1008 | if (rd_ser_len > UINT16_MAX) | 1011 | if (rd_ser_len > UINT16_MAX) |
1009 | { | 1012 | { |
1010 | GNUNET_break(0); | 1013 | GNUNET_break (0); |
1011 | return NULL; | 1014 | return NULL; |
1012 | } | 1015 | } |
1013 | rid = get_op_id(h); | 1016 | rid = get_op_id (h); |
1014 | qe = GNUNET_new(struct GNUNET_NAMESTORE_QueueEntry); | 1017 | qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); |
1015 | qe->h = h; | 1018 | qe->h = h; |
1016 | qe->cont = cont; | 1019 | qe->cont = cont; |
1017 | qe->cont_cls = cont_cls; | 1020 | qe->cont_cls = cont_cls; |
1018 | qe->op_id = rid; | 1021 | qe->op_id = rid; |
1019 | GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, qe); | 1022 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe); |
1020 | 1023 | ||
1021 | /* setup msg */ | 1024 | /* setup msg */ |
1022 | env = GNUNET_MQ_msg_extra(msg, | 1025 | env = GNUNET_MQ_msg_extra (msg, |
1023 | name_len + rd_ser_len, | 1026 | name_len + rd_ser_len, |
1024 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE); | 1027 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE); |
1025 | msg->gns_header.r_id = htonl(rid); | 1028 | msg->gns_header.r_id = htonl (rid); |
1026 | msg->name_len = htons(name_len); | 1029 | msg->name_len = htons (name_len); |
1027 | msg->rd_count = htons(rd_count); | 1030 | msg->rd_count = htons (rd_count); |
1028 | msg->rd_len = htons(rd_ser_len); | 1031 | msg->rd_len = htons (rd_ser_len); |
1029 | msg->reserved = htons(0); | 1032 | msg->reserved = htons (0); |
1030 | msg->private_key = *pkey; | 1033 | msg->private_key = *pkey; |
1031 | 1034 | ||
1032 | name_tmp = (char *)&msg[1]; | 1035 | name_tmp = (char *) &msg[1]; |
1033 | GNUNET_memcpy(name_tmp, label, name_len); | 1036 | GNUNET_memcpy (name_tmp, label, name_len); |
1034 | rd_ser = &name_tmp[name_len]; | 1037 | rd_ser = &name_tmp[name_len]; |
1035 | sret = GNUNET_GNSRECORD_records_serialize(rd_count, rd, rd_ser_len, rd_ser); | 1038 | sret = GNUNET_GNSRECORD_records_serialize (rd_count, rd, rd_ser_len, rd_ser); |
1036 | if ((0 > sret) || (sret != rd_ser_len)) | 1039 | if ((0 > sret) || (sret != rd_ser_len)) |
1037 | { | 1040 | { |
1038 | GNUNET_break(0); | 1041 | GNUNET_break (0); |
1039 | GNUNET_free(env); | 1042 | GNUNET_free (env); |
1040 | return NULL; | 1043 | return NULL; |
1041 | } | 1044 | } |
1042 | GNUNET_assert(rd_ser_len == sret); | 1045 | GNUNET_assert (rd_ser_len == sret); |
1043 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1046 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1044 | "Sending NAMESTORE_RECORD_STORE message for name `%s' with %u records\n", | 1047 | "Sending NAMESTORE_RECORD_STORE message for name `%s' with %u records\n", |
1045 | label, | 1048 | label, |
1046 | rd_count); | 1049 | rd_count); |
1047 | qe->timeout_task = | 1050 | qe->timeout_task = |
1048 | GNUNET_SCHEDULER_add_delayed(NAMESTORE_DELAY_TOLERANCE, &warn_delay, qe); | 1051 | GNUNET_SCHEDULER_add_delayed (NAMESTORE_DELAY_TOLERANCE, &warn_delay, qe); |
1049 | if (NULL == h->mq) | 1052 | if (NULL == h->mq) |
1050 | { | 1053 | { |
1051 | qe->env = env; | 1054 | qe->env = env; |
1052 | LOG(GNUNET_ERROR_TYPE_WARNING, | 1055 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1053 | "Delaying NAMESTORE_RECORD_STORE message as namestore is not ready!\n"); | 1056 | "Delaying NAMESTORE_RECORD_STORE message as namestore is not ready!\n"); |
1054 | } | 1057 | } |
1055 | else | 1058 | else |
1056 | { | 1059 | { |
1057 | GNUNET_MQ_send(h->mq, env); | 1060 | GNUNET_MQ_send (h->mq, env); |
1058 | } | 1061 | } |
1059 | return qe; | 1062 | return qe; |
1060 | } | 1063 | } |
1061 | 1064 | ||
@@ -1071,29 +1074,29 @@ GNUNET_NAMESTORE_records_store( | |||
1071 | * @return handle to abort the request | 1074 | * @return handle to abort the request |
1072 | */ | 1075 | */ |
1073 | struct GNUNET_NAMESTORE_QueueEntry * | 1076 | struct GNUNET_NAMESTORE_QueueEntry * |
1074 | GNUNET_NAMESTORE_set_nick(struct GNUNET_NAMESTORE_Handle *h, | 1077 | GNUNET_NAMESTORE_set_nick (struct GNUNET_NAMESTORE_Handle *h, |
1075 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | 1078 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, |
1076 | const char *nick, | 1079 | const char *nick, |
1077 | GNUNET_NAMESTORE_ContinuationWithStatus cont, | 1080 | GNUNET_NAMESTORE_ContinuationWithStatus cont, |
1078 | void *cont_cls) | 1081 | void *cont_cls) |
1079 | { | 1082 | { |
1080 | struct GNUNET_GNSRECORD_Data rd; | 1083 | struct GNUNET_GNSRECORD_Data rd; |
1081 | 1084 | ||
1082 | if (NULL == h->mq) | 1085 | if (NULL == h->mq) |
1083 | return NULL; | 1086 | return NULL; |
1084 | memset(&rd, 0, sizeof(rd)); | 1087 | memset (&rd, 0, sizeof(rd)); |
1085 | rd.data = nick; | 1088 | rd.data = nick; |
1086 | rd.data_size = strlen(nick) + 1; | 1089 | rd.data_size = strlen (nick) + 1; |
1087 | rd.record_type = GNUNET_GNSRECORD_TYPE_NICK; | 1090 | rd.record_type = GNUNET_GNSRECORD_TYPE_NICK; |
1088 | rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; | 1091 | rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; |
1089 | rd.flags |= GNUNET_GNSRECORD_RF_PRIVATE; | 1092 | rd.flags |= GNUNET_GNSRECORD_RF_PRIVATE; |
1090 | return GNUNET_NAMESTORE_records_store(h, | 1093 | return GNUNET_NAMESTORE_records_store (h, |
1091 | pkey, | 1094 | pkey, |
1092 | GNUNET_GNS_EMPTY_LABEL_AT, | 1095 | GNUNET_GNS_EMPTY_LABEL_AT, |
1093 | 1, | 1096 | 1, |
1094 | &rd, | 1097 | &rd, |
1095 | cont, | 1098 | cont, |
1096 | cont_cls); | 1099 | cont_cls); |
1097 | } | 1100 | } |
1098 | 1101 | ||
1099 | 1102 | ||
@@ -1110,7 +1113,7 @@ GNUNET_NAMESTORE_set_nick(struct GNUNET_NAMESTORE_Handle *h, | |||
1110 | * @return handle to abort the request | 1113 | * @return handle to abort the request |
1111 | */ | 1114 | */ |
1112 | struct GNUNET_NAMESTORE_QueueEntry * | 1115 | struct GNUNET_NAMESTORE_QueueEntry * |
1113 | GNUNET_NAMESTORE_records_lookup( | 1116 | GNUNET_NAMESTORE_records_lookup ( |
1114 | struct GNUNET_NAMESTORE_Handle *h, | 1117 | struct GNUNET_NAMESTORE_Handle *h, |
1115 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | 1118 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, |
1116 | const char *label, | 1119 | const char *label, |
@@ -1124,32 +1127,32 @@ GNUNET_NAMESTORE_records_lookup( | |||
1124 | struct LabelLookupMessage *msg; | 1127 | struct LabelLookupMessage *msg; |
1125 | size_t label_len; | 1128 | size_t label_len; |
1126 | 1129 | ||
1127 | if (1 == (label_len = strlen(label) + 1)) | 1130 | if (1 == (label_len = strlen (label) + 1)) |
1128 | { | 1131 | { |
1129 | GNUNET_break(0); | 1132 | GNUNET_break (0); |
1130 | return NULL; | 1133 | return NULL; |
1131 | } | 1134 | } |
1132 | 1135 | ||
1133 | qe = GNUNET_new(struct GNUNET_NAMESTORE_QueueEntry); | 1136 | qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); |
1134 | qe->h = h; | 1137 | qe->h = h; |
1135 | qe->error_cb = error_cb; | 1138 | qe->error_cb = error_cb; |
1136 | qe->error_cb_cls = error_cb_cls; | 1139 | qe->error_cb_cls = error_cb_cls; |
1137 | qe->proc = rm; | 1140 | qe->proc = rm; |
1138 | qe->proc_cls = rm_cls; | 1141 | qe->proc_cls = rm_cls; |
1139 | qe->op_id = get_op_id(h); | 1142 | qe->op_id = get_op_id (h); |
1140 | GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, qe); | 1143 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe); |
1141 | 1144 | ||
1142 | env = GNUNET_MQ_msg_extra(msg, | 1145 | env = GNUNET_MQ_msg_extra (msg, |
1143 | label_len, | 1146 | label_len, |
1144 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP); | 1147 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP); |
1145 | msg->gns_header.r_id = htonl(qe->op_id); | 1148 | msg->gns_header.r_id = htonl (qe->op_id); |
1146 | msg->zone = *pkey; | 1149 | msg->zone = *pkey; |
1147 | msg->label_len = htonl(label_len); | 1150 | msg->label_len = htonl (label_len); |
1148 | GNUNET_memcpy(&msg[1], label, label_len); | 1151 | GNUNET_memcpy (&msg[1], label, label_len); |
1149 | if (NULL == h->mq) | 1152 | if (NULL == h->mq) |
1150 | qe->env = env; | 1153 | qe->env = env; |
1151 | else | 1154 | else |
1152 | GNUNET_MQ_send(h->mq, env); | 1155 | GNUNET_MQ_send (h->mq, env); |
1153 | return qe; | 1156 | return qe; |
1154 | } | 1157 | } |
1155 | 1158 | ||
@@ -1170,7 +1173,7 @@ GNUNET_NAMESTORE_records_lookup( | |||
1170 | * cancel | 1173 | * cancel |
1171 | */ | 1174 | */ |
1172 | struct GNUNET_NAMESTORE_QueueEntry * | 1175 | struct GNUNET_NAMESTORE_QueueEntry * |
1173 | GNUNET_NAMESTORE_zone_to_name( | 1176 | GNUNET_NAMESTORE_zone_to_name ( |
1174 | struct GNUNET_NAMESTORE_Handle *h, | 1177 | struct GNUNET_NAMESTORE_Handle *h, |
1175 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 1178 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
1176 | const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone, | 1179 | const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone, |
@@ -1184,24 +1187,24 @@ GNUNET_NAMESTORE_zone_to_name( | |||
1184 | struct ZoneToNameMessage *msg; | 1187 | struct ZoneToNameMessage *msg; |
1185 | uint32_t rid; | 1188 | uint32_t rid; |
1186 | 1189 | ||
1187 | rid = get_op_id(h); | 1190 | rid = get_op_id (h); |
1188 | qe = GNUNET_new(struct GNUNET_NAMESTORE_QueueEntry); | 1191 | qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); |
1189 | qe->h = h; | 1192 | qe->h = h; |
1190 | qe->error_cb = error_cb; | 1193 | qe->error_cb = error_cb; |
1191 | qe->error_cb_cls = error_cb_cls; | 1194 | qe->error_cb_cls = error_cb_cls; |
1192 | qe->proc = proc; | 1195 | qe->proc = proc; |
1193 | qe->proc_cls = proc_cls; | 1196 | qe->proc_cls = proc_cls; |
1194 | qe->op_id = rid; | 1197 | qe->op_id = rid; |
1195 | GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, qe); | 1198 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe); |
1196 | 1199 | ||
1197 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME); | 1200 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME); |
1198 | msg->gns_header.r_id = htonl(rid); | 1201 | msg->gns_header.r_id = htonl (rid); |
1199 | msg->zone = *zone; | 1202 | msg->zone = *zone; |
1200 | msg->value_zone = *value_zone; | 1203 | msg->value_zone = *value_zone; |
1201 | if (NULL == h->mq) | 1204 | if (NULL == h->mq) |
1202 | qe->env = env; | 1205 | qe->env = env; |
1203 | else | 1206 | else |
1204 | GNUNET_MQ_send(h->mq, env); | 1207 | GNUNET_MQ_send (h->mq, env); |
1205 | return qe; | 1208 | return qe; |
1206 | } | 1209 | } |
1207 | 1210 | ||
@@ -1226,7 +1229,7 @@ GNUNET_NAMESTORE_zone_to_name( | |||
1226 | * @return an iterator handle to use for iteration | 1229 | * @return an iterator handle to use for iteration |
1227 | */ | 1230 | */ |
1228 | struct GNUNET_NAMESTORE_ZoneIterator * | 1231 | struct GNUNET_NAMESTORE_ZoneIterator * |
1229 | GNUNET_NAMESTORE_zone_iteration_start( | 1232 | GNUNET_NAMESTORE_zone_iteration_start ( |
1230 | struct GNUNET_NAMESTORE_Handle *h, | 1233 | struct GNUNET_NAMESTORE_Handle *h, |
1231 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 1234 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
1232 | GNUNET_SCHEDULER_TaskCallback error_cb, | 1235 | GNUNET_SCHEDULER_TaskCallback error_cb, |
@@ -1241,9 +1244,9 @@ GNUNET_NAMESTORE_zone_iteration_start( | |||
1241 | struct ZoneIterationStartMessage *msg; | 1244 | struct ZoneIterationStartMessage *msg; |
1242 | uint32_t rid; | 1245 | uint32_t rid; |
1243 | 1246 | ||
1244 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_START message\n"); | 1247 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_START message\n"); |
1245 | rid = get_op_id(h); | 1248 | rid = get_op_id (h); |
1246 | it = GNUNET_new(struct GNUNET_NAMESTORE_ZoneIterator); | 1249 | it = GNUNET_new (struct GNUNET_NAMESTORE_ZoneIterator); |
1247 | it->h = h; | 1250 | it->h = h; |
1248 | it->error_cb = error_cb; | 1251 | it->error_cb = error_cb; |
1249 | it->error_cb_cls = error_cb_cls; | 1252 | it->error_cb_cls = error_cb_cls; |
@@ -1254,15 +1257,15 @@ GNUNET_NAMESTORE_zone_iteration_start( | |||
1254 | it->op_id = rid; | 1257 | it->op_id = rid; |
1255 | if (NULL != zone) | 1258 | if (NULL != zone) |
1256 | it->zone = *zone; | 1259 | it->zone = *zone; |
1257 | GNUNET_CONTAINER_DLL_insert_tail(h->z_head, h->z_tail, it); | 1260 | GNUNET_CONTAINER_DLL_insert_tail (h->z_head, h->z_tail, it); |
1258 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START); | 1261 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START); |
1259 | msg->gns_header.r_id = htonl(rid); | 1262 | msg->gns_header.r_id = htonl (rid); |
1260 | if (NULL != zone) | 1263 | if (NULL != zone) |
1261 | msg->zone = *zone; | 1264 | msg->zone = *zone; |
1262 | if (NULL == h->mq) | 1265 | if (NULL == h->mq) |
1263 | it->env = env; | 1266 | it->env = env; |
1264 | else | 1267 | else |
1265 | GNUNET_MQ_send(h->mq, env); | 1268 | GNUNET_MQ_send (h->mq, env); |
1266 | return it; | 1269 | return it; |
1267 | } | 1270 | } |
1268 | 1271 | ||
@@ -1276,20 +1279,20 @@ GNUNET_NAMESTORE_zone_iteration_start( | |||
1276 | * (before #GNUNET_NAMESTORE_zone_iterator_next is to be called again) | 1279 | * (before #GNUNET_NAMESTORE_zone_iterator_next is to be called again) |
1277 | */ | 1280 | */ |
1278 | void | 1281 | void |
1279 | GNUNET_NAMESTORE_zone_iterator_next(struct GNUNET_NAMESTORE_ZoneIterator *it, | 1282 | GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it, |
1280 | uint64_t limit) | 1283 | uint64_t limit) |
1281 | { | 1284 | { |
1282 | struct GNUNET_NAMESTORE_Handle *h = it->h; | 1285 | struct GNUNET_NAMESTORE_Handle *h = it->h; |
1283 | struct ZoneIterationNextMessage *msg; | 1286 | struct ZoneIterationNextMessage *msg; |
1284 | struct GNUNET_MQ_Envelope *env; | 1287 | struct GNUNET_MQ_Envelope *env; |
1285 | 1288 | ||
1286 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1289 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1287 | "Sending ZONE_ITERATION_NEXT message with limit %llu\n", | 1290 | "Sending ZONE_ITERATION_NEXT message with limit %llu\n", |
1288 | (unsigned long long)limit); | 1291 | (unsigned long long) limit); |
1289 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT); | 1292 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT); |
1290 | msg->gns_header.r_id = htonl(it->op_id); | 1293 | msg->gns_header.r_id = htonl (it->op_id); |
1291 | msg->limit = GNUNET_htonll(limit); | 1294 | msg->limit = GNUNET_htonll (limit); |
1292 | GNUNET_MQ_send(h->mq, env); | 1295 | GNUNET_MQ_send (h->mq, env); |
1293 | } | 1296 | } |
1294 | 1297 | ||
1295 | 1298 | ||
@@ -1299,21 +1302,21 @@ GNUNET_NAMESTORE_zone_iterator_next(struct GNUNET_NAMESTORE_ZoneIterator *it, | |||
1299 | * @param it the iterator | 1302 | * @param it the iterator |
1300 | */ | 1303 | */ |
1301 | void | 1304 | void |
1302 | GNUNET_NAMESTORE_zone_iteration_stop(struct GNUNET_NAMESTORE_ZoneIterator *it) | 1305 | GNUNET_NAMESTORE_zone_iteration_stop (struct GNUNET_NAMESTORE_ZoneIterator *it) |
1303 | { | 1306 | { |
1304 | struct GNUNET_NAMESTORE_Handle *h = it->h; | 1307 | struct GNUNET_NAMESTORE_Handle *h = it->h; |
1305 | struct GNUNET_MQ_Envelope *env; | 1308 | struct GNUNET_MQ_Envelope *env; |
1306 | struct ZoneIterationStopMessage *msg; | 1309 | struct ZoneIterationStopMessage *msg; |
1307 | 1310 | ||
1308 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_STOP message\n"); | 1311 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_STOP message\n"); |
1309 | if (NULL != h->mq) | 1312 | if (NULL != h->mq) |
1310 | { | 1313 | { |
1311 | env = | 1314 | env = |
1312 | GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP); | 1315 | GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP); |
1313 | msg->gns_header.r_id = htonl(it->op_id); | 1316 | msg->gns_header.r_id = htonl (it->op_id); |
1314 | GNUNET_MQ_send(h->mq, env); | 1317 | GNUNET_MQ_send (h->mq, env); |
1315 | } | 1318 | } |
1316 | free_ze(it); | 1319 | free_ze (it); |
1317 | } | 1320 | } |
1318 | 1321 | ||
1319 | 1322 | ||
@@ -1324,9 +1327,9 @@ GNUNET_NAMESTORE_zone_iteration_stop(struct GNUNET_NAMESTORE_ZoneIterator *it) | |||
1324 | * @param qe operation to cancel | 1327 | * @param qe operation to cancel |
1325 | */ | 1328 | */ |
1326 | void | 1329 | void |
1327 | GNUNET_NAMESTORE_cancel(struct GNUNET_NAMESTORE_QueueEntry *qe) | 1330 | GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe) |
1328 | { | 1331 | { |
1329 | free_qe(qe); | 1332 | free_qe (qe); |
1330 | } | 1333 | } |
1331 | 1334 | ||
1332 | 1335 | ||
diff --git a/src/namestore/namestore_api_monitor.c b/src/namestore/namestore_api_monitor.c index d87a76eed..a7046c940 100644 --- a/src/namestore/namestore_api_monitor.c +++ b/src/namestore/namestore_api_monitor.c | |||
@@ -37,7 +37,8 @@ | |||
37 | /** | 37 | /** |
38 | * Handle for a monitoring activity. | 38 | * Handle for a monitoring activity. |
39 | */ | 39 | */ |
40 | struct GNUNET_NAMESTORE_ZoneMonitor { | 40 | struct GNUNET_NAMESTORE_ZoneMonitor |
41 | { | ||
41 | /** | 42 | /** |
42 | * Configuration (to reconnect). | 43 | * Configuration (to reconnect). |
43 | */ | 44 | */ |
@@ -96,7 +97,7 @@ struct GNUNET_NAMESTORE_ZoneMonitor { | |||
96 | * @param zm monitor to reconnect | 97 | * @param zm monitor to reconnect |
97 | */ | 98 | */ |
98 | static void | 99 | static void |
99 | reconnect(struct GNUNET_NAMESTORE_ZoneMonitor *zm); | 100 | reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm); |
100 | 101 | ||
101 | 102 | ||
102 | /** | 103 | /** |
@@ -106,14 +107,14 @@ reconnect(struct GNUNET_NAMESTORE_ZoneMonitor *zm); | |||
106 | * @param msg the sync message | 107 | * @param msg the sync message |
107 | */ | 108 | */ |
108 | static void | 109 | static void |
109 | handle_sync(void *cls, const struct GNUNET_MessageHeader *msg) | 110 | handle_sync (void *cls, const struct GNUNET_MessageHeader *msg) |
110 | { | 111 | { |
111 | struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; | 112 | struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; |
112 | 113 | ||
113 | (void)cls; | 114 | (void) cls; |
114 | (void)msg; | 115 | (void) msg; |
115 | if (NULL != zm->sync_cb) | 116 | if (NULL != zm->sync_cb) |
116 | zm->sync_cb(zm->sync_cb_cls); | 117 | zm->sync_cb (zm->sync_cb_cls); |
117 | } | 118 | } |
118 | 119 | ||
119 | 120 | ||
@@ -125,7 +126,7 @@ handle_sync(void *cls, const struct GNUNET_MessageHeader *msg) | |||
125 | * @param lrm the message from the service. | 126 | * @param lrm the message from the service. |
126 | */ | 127 | */ |
127 | static int | 128 | static int |
128 | check_result(void *cls, const struct RecordResultMessage *lrm) | 129 | check_result (void *cls, const struct RecordResultMessage *lrm) |
129 | { | 130 | { |
130 | struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; | 131 | struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; |
131 | size_t lrm_len; | 132 | size_t lrm_len; |
@@ -136,49 +137,49 @@ check_result(void *cls, const struct RecordResultMessage *lrm) | |||
136 | const char *name_tmp; | 137 | const char *name_tmp; |
137 | const char *rd_ser_tmp; | 138 | const char *rd_ser_tmp; |
138 | 139 | ||
139 | (void)cls; | 140 | (void) cls; |
140 | if ((0 != GNUNET_memcmp(&lrm->private_key, &zm->zone)) && | 141 | if ((0 != GNUNET_memcmp (&lrm->private_key, &zm->zone)) && |
141 | (0 != GNUNET_is_zero(&zm->zone))) | 142 | (0 != GNUNET_is_zero (&zm->zone))) |
142 | { | 143 | { |
143 | GNUNET_break(0); | 144 | GNUNET_break (0); |
144 | return GNUNET_SYSERR; | 145 | return GNUNET_SYSERR; |
145 | } | 146 | } |
146 | lrm_len = ntohs(lrm->gns_header.header.size); | 147 | lrm_len = ntohs (lrm->gns_header.header.size); |
147 | rd_len = ntohs(lrm->rd_len); | 148 | rd_len = ntohs (lrm->rd_len); |
148 | rd_count = ntohs(lrm->rd_count); | 149 | rd_count = ntohs (lrm->rd_count); |
149 | name_len = ntohs(lrm->name_len); | 150 | name_len = ntohs (lrm->name_len); |
150 | if (name_len > MAX_NAME_LEN) | 151 | if (name_len > MAX_NAME_LEN) |
151 | { | 152 | { |
152 | GNUNET_break(0); | 153 | GNUNET_break (0); |
153 | return GNUNET_SYSERR; | 154 | return GNUNET_SYSERR; |
154 | } | 155 | } |
155 | exp_lrm_len = sizeof(struct RecordResultMessage) + name_len + rd_len; | 156 | exp_lrm_len = sizeof(struct RecordResultMessage) + name_len + rd_len; |
156 | if (lrm_len != exp_lrm_len) | 157 | if (lrm_len != exp_lrm_len) |
157 | { | 158 | { |
158 | GNUNET_break(0); | 159 | GNUNET_break (0); |
159 | return GNUNET_SYSERR; | 160 | return GNUNET_SYSERR; |
160 | } | 161 | } |
161 | if (0 == name_len) | 162 | if (0 == name_len) |
162 | { | 163 | { |
163 | GNUNET_break(0); | 164 | GNUNET_break (0); |
164 | return GNUNET_SYSERR; | 165 | return GNUNET_SYSERR; |
165 | } | 166 | } |
166 | name_tmp = (const char *)&lrm[1]; | 167 | name_tmp = (const char *) &lrm[1]; |
167 | if (name_tmp[name_len - 1] != '\0') | 168 | if (name_tmp[name_len - 1] != '\0') |
168 | { | 169 | { |
169 | GNUNET_break(0); | 170 | GNUNET_break (0); |
170 | return GNUNET_SYSERR; | 171 | return GNUNET_SYSERR; |
171 | } | 172 | } |
172 | rd_ser_tmp = (const char *)&name_tmp[name_len]; | 173 | rd_ser_tmp = (const char *) &name_tmp[name_len]; |
173 | { | 174 | { |
174 | struct GNUNET_GNSRECORD_Data rd[rd_count]; | 175 | struct GNUNET_GNSRECORD_Data rd[rd_count]; |
175 | 176 | ||
176 | if (GNUNET_OK != | 177 | if (GNUNET_OK != |
177 | GNUNET_GNSRECORD_records_deserialize(rd_len, rd_ser_tmp, rd_count, rd)) | 178 | GNUNET_GNSRECORD_records_deserialize (rd_len, rd_ser_tmp, rd_count, rd)) |
178 | { | 179 | { |
179 | GNUNET_break(0); | 180 | GNUNET_break (0); |
180 | return GNUNET_SYSERR; | 181 | return GNUNET_SYSERR; |
181 | } | 182 | } |
182 | } | 183 | } |
183 | return GNUNET_OK; | 184 | return GNUNET_OK; |
184 | } | 185 | } |
@@ -192,7 +193,7 @@ check_result(void *cls, const struct RecordResultMessage *lrm) | |||
192 | * @param lrm the message from the service. | 193 | * @param lrm the message from the service. |
193 | */ | 194 | */ |
194 | static void | 195 | static void |
195 | handle_result(void *cls, const struct RecordResultMessage *lrm) | 196 | handle_result (void *cls, const struct RecordResultMessage *lrm) |
196 | { | 197 | { |
197 | struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; | 198 | struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; |
198 | size_t name_len; | 199 | size_t name_len; |
@@ -201,18 +202,18 @@ handle_result(void *cls, const struct RecordResultMessage *lrm) | |||
201 | const char *name_tmp; | 202 | const char *name_tmp; |
202 | const char *rd_ser_tmp; | 203 | const char *rd_ser_tmp; |
203 | 204 | ||
204 | rd_len = ntohs(lrm->rd_len); | 205 | rd_len = ntohs (lrm->rd_len); |
205 | rd_count = ntohs(lrm->rd_count); | 206 | rd_count = ntohs (lrm->rd_count); |
206 | name_len = ntohs(lrm->name_len); | 207 | name_len = ntohs (lrm->name_len); |
207 | name_tmp = (const char *)&lrm[1]; | 208 | name_tmp = (const char *) &lrm[1]; |
208 | rd_ser_tmp = (const char *)&name_tmp[name_len]; | 209 | rd_ser_tmp = (const char *) &name_tmp[name_len]; |
209 | { | 210 | { |
210 | struct GNUNET_GNSRECORD_Data rd[rd_count]; | 211 | struct GNUNET_GNSRECORD_Data rd[rd_count]; |
211 | 212 | ||
212 | GNUNET_assert( | 213 | GNUNET_assert ( |
213 | GNUNET_OK == | 214 | GNUNET_OK == |
214 | GNUNET_GNSRECORD_records_deserialize(rd_len, rd_ser_tmp, rd_count, rd)); | 215 | GNUNET_GNSRECORD_records_deserialize (rd_len, rd_ser_tmp, rd_count, rd)); |
215 | zm->monitor(zm->monitor_cls, &lrm->private_key, name_tmp, rd_count, rd); | 216 | zm->monitor (zm->monitor_cls, &lrm->private_key, name_tmp, rd_count, rd); |
216 | } | 217 | } |
217 | } | 218 | } |
218 | 219 | ||
@@ -226,12 +227,12 @@ handle_result(void *cls, const struct RecordResultMessage *lrm) | |||
226 | * @param error error code | 227 | * @param error error code |
227 | */ | 228 | */ |
228 | static void | 229 | static void |
229 | mq_error_handler(void *cls, enum GNUNET_MQ_Error error) | 230 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
230 | { | 231 | { |
231 | struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; | 232 | struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; |
232 | 233 | ||
233 | (void)error; | 234 | (void) error; |
234 | reconnect(zm); | 235 | reconnect (zm); |
235 | } | 236 | } |
236 | 237 | ||
237 | 238 | ||
@@ -241,37 +242,37 @@ mq_error_handler(void *cls, enum GNUNET_MQ_Error error) | |||
241 | * @param zm monitor to reconnect | 242 | * @param zm monitor to reconnect |
242 | */ | 243 | */ |
243 | static void | 244 | static void |
244 | reconnect(struct GNUNET_NAMESTORE_ZoneMonitor *zm) | 245 | reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm) |
245 | { | 246 | { |
246 | struct GNUNET_MQ_MessageHandler handlers[] = | 247 | struct GNUNET_MQ_MessageHandler handlers[] = |
247 | { GNUNET_MQ_hd_fixed_size(sync, | 248 | { GNUNET_MQ_hd_fixed_size (sync, |
248 | GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC, | 249 | GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC, |
249 | struct GNUNET_MessageHeader, | 250 | struct GNUNET_MessageHeader, |
250 | zm), | 251 | zm), |
251 | GNUNET_MQ_hd_var_size(result, | 252 | GNUNET_MQ_hd_var_size (result, |
252 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT, | 253 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT, |
253 | struct RecordResultMessage, | 254 | struct RecordResultMessage, |
254 | zm), | 255 | zm), |
255 | GNUNET_MQ_handler_end() }; | 256 | GNUNET_MQ_handler_end () }; |
256 | struct GNUNET_MQ_Envelope *env; | 257 | struct GNUNET_MQ_Envelope *env; |
257 | struct ZoneMonitorStartMessage *sm; | 258 | struct ZoneMonitorStartMessage *sm; |
258 | 259 | ||
259 | if (NULL != zm->mq) | 260 | if (NULL != zm->mq) |
260 | { | 261 | { |
261 | GNUNET_MQ_destroy(zm->mq); | 262 | GNUNET_MQ_destroy (zm->mq); |
262 | zm->error_cb(zm->error_cb_cls); | 263 | zm->error_cb (zm->error_cb_cls); |
263 | } | 264 | } |
264 | zm->mq = GNUNET_CLIENT_connect(zm->cfg, | 265 | zm->mq = GNUNET_CLIENT_connect (zm->cfg, |
265 | "namestore", | 266 | "namestore", |
266 | handlers, | 267 | handlers, |
267 | &mq_error_handler, | 268 | &mq_error_handler, |
268 | zm); | 269 | zm); |
269 | if (NULL == zm->mq) | 270 | if (NULL == zm->mq) |
270 | return; | 271 | return; |
271 | env = GNUNET_MQ_msg(sm, GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START); | 272 | env = GNUNET_MQ_msg (sm, GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START); |
272 | sm->iterate_first = htonl(zm->iterate_first); | 273 | sm->iterate_first = htonl (zm->iterate_first); |
273 | sm->zone = zm->zone; | 274 | sm->zone = zm->zone; |
274 | GNUNET_MQ_send(zm->mq, env); | 275 | GNUNET_MQ_send (zm->mq, env); |
275 | } | 276 | } |
276 | 277 | ||
277 | 278 | ||
@@ -299,7 +300,7 @@ reconnect(struct GNUNET_NAMESTORE_ZoneMonitor *zm) | |||
299 | * @return handle to stop monitoring | 300 | * @return handle to stop monitoring |
300 | */ | 301 | */ |
301 | struct GNUNET_NAMESTORE_ZoneMonitor * | 302 | struct GNUNET_NAMESTORE_ZoneMonitor * |
302 | GNUNET_NAMESTORE_zone_monitor_start( | 303 | GNUNET_NAMESTORE_zone_monitor_start ( |
303 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 304 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
304 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 305 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
305 | int iterate_first, | 306 | int iterate_first, |
@@ -312,7 +313,7 @@ GNUNET_NAMESTORE_zone_monitor_start( | |||
312 | { | 313 | { |
313 | struct GNUNET_NAMESTORE_ZoneMonitor *zm; | 314 | struct GNUNET_NAMESTORE_ZoneMonitor *zm; |
314 | 315 | ||
315 | zm = GNUNET_new(struct GNUNET_NAMESTORE_ZoneMonitor); | 316 | zm = GNUNET_new (struct GNUNET_NAMESTORE_ZoneMonitor); |
316 | if (NULL != zone) | 317 | if (NULL != zone) |
317 | zm->zone = *zone; | 318 | zm->zone = *zone; |
318 | zm->iterate_first = iterate_first; | 319 | zm->iterate_first = iterate_first; |
@@ -323,12 +324,12 @@ GNUNET_NAMESTORE_zone_monitor_start( | |||
323 | zm->sync_cb = sync_cb; | 324 | zm->sync_cb = sync_cb; |
324 | zm->sync_cb_cls = sync_cb_cls; | 325 | zm->sync_cb_cls = sync_cb_cls; |
325 | zm->cfg = cfg; | 326 | zm->cfg = cfg; |
326 | reconnect(zm); | 327 | reconnect (zm); |
327 | if (NULL == zm->mq) | 328 | if (NULL == zm->mq) |
328 | { | 329 | { |
329 | GNUNET_free(zm); | 330 | GNUNET_free (zm); |
330 | return NULL; | 331 | return NULL; |
331 | } | 332 | } |
332 | return zm; | 333 | return zm; |
333 | } | 334 | } |
334 | 335 | ||
@@ -355,15 +356,15 @@ GNUNET_NAMESTORE_zone_monitor_start( | |||
355 | * (before #GNUNET_NAMESTORE_zone_monitor_next is to be called again) | 356 | * (before #GNUNET_NAMESTORE_zone_monitor_next is to be called again) |
356 | */ | 357 | */ |
357 | void | 358 | void |
358 | GNUNET_NAMESTORE_zone_monitor_next(struct GNUNET_NAMESTORE_ZoneMonitor *zm, | 359 | GNUNET_NAMESTORE_zone_monitor_next (struct GNUNET_NAMESTORE_ZoneMonitor *zm, |
359 | uint64_t limit) | 360 | uint64_t limit) |
360 | { | 361 | { |
361 | struct GNUNET_MQ_Envelope *env; | 362 | struct GNUNET_MQ_Envelope *env; |
362 | struct ZoneMonitorNextMessage *nm; | 363 | struct ZoneMonitorNextMessage *nm; |
363 | 364 | ||
364 | env = GNUNET_MQ_msg(nm, GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT); | 365 | env = GNUNET_MQ_msg (nm, GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT); |
365 | nm->limit = GNUNET_htonll(limit); | 366 | nm->limit = GNUNET_htonll (limit); |
366 | GNUNET_MQ_send(zm->mq, env); | 367 | GNUNET_MQ_send (zm->mq, env); |
367 | } | 368 | } |
368 | 369 | ||
369 | 370 | ||
@@ -373,14 +374,14 @@ GNUNET_NAMESTORE_zone_monitor_next(struct GNUNET_NAMESTORE_ZoneMonitor *zm, | |||
373 | * @param zm handle to the monitor activity to stop | 374 | * @param zm handle to the monitor activity to stop |
374 | */ | 375 | */ |
375 | void | 376 | void |
376 | GNUNET_NAMESTORE_zone_monitor_stop(struct GNUNET_NAMESTORE_ZoneMonitor *zm) | 377 | GNUNET_NAMESTORE_zone_monitor_stop (struct GNUNET_NAMESTORE_ZoneMonitor *zm) |
377 | { | 378 | { |
378 | if (NULL != zm->mq) | 379 | if (NULL != zm->mq) |
379 | { | 380 | { |
380 | GNUNET_MQ_destroy(zm->mq); | 381 | GNUNET_MQ_destroy (zm->mq); |
381 | zm->mq = NULL; | 382 | zm->mq = NULL; |
382 | } | 383 | } |
383 | GNUNET_free(zm); | 384 | GNUNET_free (zm); |
384 | } | 385 | } |
385 | 386 | ||
386 | /* end of namestore_api_monitor.c */ | 387 | /* end of namestore_api_monitor.c */ |
diff --git a/src/namestore/perf_namestore_api_zone_iteration.c b/src/namestore/perf_namestore_api_zone_iteration.c index 6b79a35f6..e8277ae65 100644 --- a/src/namestore/perf_namestore_api_zone_iteration.c +++ b/src/namestore/perf_namestore_api_zone_iteration.c | |||
@@ -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,229 @@ 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 ( |
147 | GNUNET_TIME_UNIT_HOURS).abs_value_us; | ||
147 | rd->record_type = TEST_RECORD_TYPE; | 148 | rd->record_type = TEST_RECORD_TYPE; |
148 | rd->data_size = count; | 149 | rd->data_size = count; |
149 | rd->data = (void *)&rd[1]; | 150 | rd->data = (void *) &rd[1]; |
150 | rd->flags = 0; | 151 | rd->flags = 0; |
151 | memset(&rd[1], | 152 | memset (&rd[1], |
152 | 'a', | 153 | 'a', |
153 | count); | 154 | count); |
154 | return rd; | 155 | return rd; |
155 | } | 156 | } |
156 | 157 | ||
157 | 158 | ||
158 | static void | 159 | static void |
159 | zone_end(void *cls) | 160 | zone_end (void *cls) |
160 | { | 161 | { |
161 | struct GNUNET_TIME_Relative delay; | 162 | struct GNUNET_TIME_Relative delay; |
162 | 163 | ||
163 | zi = NULL; | 164 | zi = NULL; |
164 | delay = GNUNET_TIME_absolute_get_duration(start); | 165 | delay = GNUNET_TIME_absolute_get_duration (start); |
165 | fprintf(stdout, | 166 | fprintf (stdout, |
166 | "Iterating over %u records took %s\n", | 167 | "Iterating over %u records took %s\n", |
167 | off, | 168 | off, |
168 | GNUNET_STRINGS_relative_time_to_string(delay, | 169 | GNUNET_STRINGS_relative_time_to_string (delay, |
169 | GNUNET_YES)); | 170 | GNUNET_YES)); |
170 | if (BENCHMARK_SIZE == off) | 171 | if (BENCHMARK_SIZE == off) |
171 | { | 172 | { |
172 | res = 0; | 173 | res = 0; |
173 | } | 174 | } |
174 | else | 175 | else |
175 | { | 176 | { |
176 | GNUNET_break(0); | 177 | GNUNET_break (0); |
177 | res = 1; | 178 | res = 1; |
178 | } | 179 | } |
179 | GNUNET_SCHEDULER_shutdown(); | 180 | GNUNET_SCHEDULER_shutdown (); |
180 | } | 181 | } |
181 | 182 | ||
182 | 183 | ||
183 | static void | 184 | static void |
184 | fail_cb(void *cls) | 185 | fail_cb (void *cls) |
185 | { | 186 | { |
186 | zi = NULL; | 187 | zi = NULL; |
187 | res = 2; | 188 | res = 2; |
188 | GNUNET_break(0); | 189 | GNUNET_break (0); |
189 | GNUNET_SCHEDULER_shutdown(); | 190 | GNUNET_SCHEDULER_shutdown (); |
190 | } | 191 | } |
191 | 192 | ||
192 | 193 | ||
193 | static void | 194 | static void |
194 | zone_proc(void *cls, | 195 | zone_proc (void *cls, |
195 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 196 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
196 | const char *label, | 197 | const char *label, |
197 | unsigned int rd_count, | 198 | unsigned int rd_count, |
198 | const struct GNUNET_GNSRECORD_Data *rd) | 199 | const struct GNUNET_GNSRECORD_Data *rd) |
199 | { | 200 | { |
200 | struct GNUNET_GNSRECORD_Data *wrd; | 201 | struct GNUNET_GNSRECORD_Data *wrd; |
201 | unsigned int xoff; | 202 | unsigned int xoff; |
202 | 203 | ||
203 | GNUNET_assert(NULL != zone); | 204 | GNUNET_assert (NULL != zone); |
204 | if (1 != sscanf(label, | 205 | if (1 != sscanf (label, |
205 | "l%u", | 206 | "l%u", |
206 | &xoff)) | 207 | &xoff)) |
207 | { | 208 | { |
208 | res = 3; | 209 | res = 3; |
209 | GNUNET_break(0); | 210 | GNUNET_break (0); |
210 | GNUNET_SCHEDULER_shutdown(); | 211 | GNUNET_SCHEDULER_shutdown (); |
211 | return; | 212 | return; |
212 | } | 213 | } |
213 | if ((xoff > BENCHMARK_SIZE) || | 214 | if ((xoff > BENCHMARK_SIZE) || |
214 | (0 != (seen[xoff / 8] & (1U << (xoff % 8))))) | 215 | (0 != (seen[xoff / 8] & (1U << (xoff % 8))))) |
215 | { | 216 | { |
216 | res = 3; | 217 | res = 3; |
217 | GNUNET_break(0); | 218 | GNUNET_break (0); |
218 | GNUNET_SCHEDULER_shutdown(); | 219 | GNUNET_SCHEDULER_shutdown (); |
219 | return; | 220 | return; |
220 | } | 221 | } |
221 | seen[xoff / 8] |= (1U << (xoff % 8)); | 222 | seen[xoff / 8] |= (1U << (xoff % 8)); |
222 | wrd = create_record(xoff % MAX_REC_SIZE); | 223 | wrd = create_record (xoff % MAX_REC_SIZE); |
223 | if ((rd->record_type != wrd->record_type) || | 224 | if ((rd->record_type != wrd->record_type) || |
224 | (rd->data_size != wrd->data_size) || | 225 | (rd->data_size != wrd->data_size) || |
225 | (rd->flags != wrd->flags)) | 226 | (rd->flags != wrd->flags)) |
226 | { | 227 | { |
227 | res = 4; | 228 | res = 4; |
228 | GNUNET_break(0); | 229 | GNUNET_break (0); |
229 | GNUNET_SCHEDULER_shutdown(); | 230 | GNUNET_SCHEDULER_shutdown (); |
230 | GNUNET_free(wrd); | 231 | GNUNET_free (wrd); |
231 | return; | 232 | return; |
232 | } | 233 | } |
233 | if (0 != memcmp(rd->data, | 234 | if (0 != memcmp (rd->data, |
234 | wrd->data, | 235 | wrd->data, |
235 | wrd->data_size)) | 236 | wrd->data_size)) |
236 | { | 237 | { |
237 | res = 4; | 238 | res = 4; |
238 | GNUNET_break(0); | 239 | GNUNET_break (0); |
239 | GNUNET_SCHEDULER_shutdown(); | 240 | GNUNET_SCHEDULER_shutdown (); |
240 | GNUNET_free(wrd); | 241 | GNUNET_free (wrd); |
241 | return; | 242 | return; |
242 | } | 243 | } |
243 | GNUNET_free(wrd); | 244 | GNUNET_free (wrd); |
244 | if (0 != GNUNET_memcmp(zone, | 245 | if (0 != GNUNET_memcmp (zone, |
245 | privkey)) | 246 | privkey)) |
246 | { | 247 | { |
247 | res = 5; | 248 | res = 5; |
248 | GNUNET_break(0); | 249 | GNUNET_break (0); |
249 | GNUNET_SCHEDULER_shutdown(); | 250 | GNUNET_SCHEDULER_shutdown (); |
250 | return; | 251 | return; |
251 | } | 252 | } |
252 | off++; | 253 | off++; |
253 | left_until_next--; | 254 | left_until_next--; |
254 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 255 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
255 | "Obtained record %u, expecting %u more until asking for mor explicitly\n", | 256 | "Obtained record %u, expecting %u more until asking for mor explicitly\n", |
256 | off, | 257 | off, |
257 | left_until_next); | 258 | left_until_next); |
258 | if (0 == left_until_next) | 259 | if (0 == left_until_next) |
259 | { | 260 | { |
260 | left_until_next = BLOCK_SIZE; | 261 | left_until_next = BLOCK_SIZE; |
261 | GNUNET_NAMESTORE_zone_iterator_next(zi, | 262 | GNUNET_NAMESTORE_zone_iterator_next (zi, |
262 | left_until_next); | 263 | left_until_next); |
263 | } | 264 | } |
264 | } | 265 | } |
265 | 266 | ||
266 | 267 | ||
267 | static void | 268 | static void |
268 | publish_record(void *cls); | 269 | publish_record (void *cls); |
269 | 270 | ||
270 | 271 | ||
271 | static void | 272 | static void |
272 | put_cont(void *cls, | 273 | put_cont (void *cls, |
273 | int32_t success, | 274 | int32_t success, |
274 | const char *emsg) | 275 | const char *emsg) |
275 | { | 276 | { |
276 | (void)cls; | 277 | (void) cls; |
277 | qe = NULL; | 278 | qe = NULL; |
278 | if (GNUNET_OK != success) | 279 | if (GNUNET_OK != success) |
279 | { | 280 | { |
280 | GNUNET_break(0); | 281 | GNUNET_break (0); |
281 | GNUNET_SCHEDULER_shutdown(); | 282 | GNUNET_SCHEDULER_shutdown (); |
282 | return; | 283 | return; |
283 | } | 284 | } |
284 | t = GNUNET_SCHEDULER_add_now(&publish_record, | 285 | t = GNUNET_SCHEDULER_add_now (&publish_record, |
285 | NULL); | 286 | NULL); |
286 | } | 287 | } |
287 | 288 | ||
288 | 289 | ||
289 | static void | 290 | static void |
290 | publish_record(void *cls) | 291 | publish_record (void *cls) |
291 | { | 292 | { |
292 | struct GNUNET_GNSRECORD_Data *rd; | 293 | struct GNUNET_GNSRECORD_Data *rd; |
293 | char *label; | 294 | char *label; |
294 | 295 | ||
295 | (void)cls; | 296 | (void) cls; |
296 | t = NULL; | 297 | t = NULL; |
297 | if (BENCHMARK_SIZE == off) | 298 | if (BENCHMARK_SIZE == off) |
298 | { | 299 | { |
299 | struct GNUNET_TIME_Relative delay; | 300 | struct GNUNET_TIME_Relative delay; |
300 | 301 | ||
301 | delay = GNUNET_TIME_absolute_get_duration(start); | 302 | delay = GNUNET_TIME_absolute_get_duration (start); |
302 | fprintf(stdout, | 303 | fprintf (stdout, |
303 | "Inserting %u records took %s\n", | 304 | "Inserting %u records took %s\n", |
304 | off, | 305 | off, |
305 | GNUNET_STRINGS_relative_time_to_string(delay, | 306 | GNUNET_STRINGS_relative_time_to_string (delay, |
306 | GNUNET_YES)); | 307 | GNUNET_YES)); |
307 | start = GNUNET_TIME_absolute_get(); | 308 | start = GNUNET_TIME_absolute_get (); |
308 | off = 0; | 309 | off = 0; |
309 | left_until_next = 1; | 310 | left_until_next = 1; |
310 | zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, | 311 | zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, |
311 | NULL, | 312 | NULL, |
312 | &fail_cb, | 313 | &fail_cb, |
313 | NULL, | 314 | NULL, |
314 | &zone_proc, | 315 | &zone_proc, |
315 | NULL, | 316 | NULL, |
316 | &zone_end, | 317 | &zone_end, |
317 | NULL); | 318 | NULL); |
318 | GNUNET_assert(NULL != zi); | 319 | GNUNET_assert (NULL != zi); |
319 | return; | 320 | return; |
320 | } | 321 | } |
321 | rd = create_record((++off) % MAX_REC_SIZE); | 322 | rd = create_record ((++off) % MAX_REC_SIZE); |
322 | GNUNET_asprintf(&label, | 323 | GNUNET_asprintf (&label, |
323 | "l%u", | 324 | "l%u", |
324 | off); | 325 | off); |
325 | qe = GNUNET_NAMESTORE_records_store(nsh, | 326 | qe = GNUNET_NAMESTORE_records_store (nsh, |
326 | privkey, | 327 | privkey, |
327 | label, | 328 | label, |
328 | 1, rd, | 329 | 1, rd, |
329 | &put_cont, | 330 | &put_cont, |
330 | NULL); | 331 | NULL); |
331 | GNUNET_free(label); | 332 | GNUNET_free (label); |
332 | GNUNET_free(rd); | 333 | GNUNET_free (rd); |
333 | } | 334 | } |
334 | 335 | ||
335 | 336 | ||
336 | static void | 337 | static void |
337 | run(void *cls, | 338 | run (void *cls, |
338 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 339 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
339 | struct GNUNET_TESTING_Peer *peer) | 340 | struct GNUNET_TESTING_Peer *peer) |
340 | { | 341 | { |
341 | GNUNET_SCHEDULER_add_shutdown(&end, | 342 | GNUNET_SCHEDULER_add_shutdown (&end, |
343 | NULL); | ||
344 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | ||
345 | &timeout, | ||
346 | NULL); | ||
347 | nsh = GNUNET_NAMESTORE_connect (cfg); | ||
348 | GNUNET_assert (NULL != nsh); | ||
349 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); | ||
350 | GNUNET_assert (NULL != privkey); | ||
351 | start = GNUNET_TIME_absolute_get (); | ||
352 | t = GNUNET_SCHEDULER_add_now (&publish_record, | ||
342 | NULL); | 353 | 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 | } | 354 | } |
354 | 355 | ||
355 | 356 | ||
@@ -357,25 +358,25 @@ run(void *cls, | |||
357 | 358 | ||
358 | 359 | ||
359 | int | 360 | int |
360 | main(int argc, | 361 | main (int argc, |
361 | char *argv[]) | 362 | char *argv[]) |
362 | { | 363 | { |
363 | const char *plugin_name; | 364 | const char *plugin_name; |
364 | char *cfg_name; | 365 | char *cfg_name; |
365 | 366 | ||
366 | SETUP_CFG(plugin_name, cfg_name); | 367 | SETUP_CFG (plugin_name, cfg_name); |
367 | res = 1; | 368 | res = 1; |
368 | if (0 != | 369 | if (0 != |
369 | GNUNET_TESTING_peer_run("perf-namestore-api-zone-iteration", | 370 | GNUNET_TESTING_peer_run ("perf-namestore-api-zone-iteration", |
370 | cfg_name, | 371 | cfg_name, |
371 | &run, | 372 | &run, |
372 | NULL)) | 373 | NULL)) |
373 | { | 374 | { |
374 | res = 1; | 375 | res = 1; |
375 | } | 376 | } |
376 | GNUNET_DISK_purge_cfg_dir(cfg_name, | 377 | GNUNET_DISK_purge_cfg_dir (cfg_name, |
377 | "GNUNET_TEST_HOME"); | 378 | "GNUNET_TEST_HOME"); |
378 | GNUNET_free(cfg_name); | 379 | GNUNET_free (cfg_name); |
379 | return res; | 380 | return res; |
380 | } | 381 | } |
381 | 382 | ||
diff --git a/src/namestore/plugin_namestore_flat.c b/src/namestore/plugin_namestore_flat.c index 083609359..89cab6e52 100644 --- a/src/namestore/plugin_namestore_flat.c +++ b/src/namestore/plugin_namestore_flat.c | |||
@@ -33,7 +33,8 @@ | |||
33 | /** | 33 | /** |
34 | * Context for all functions in this plugin. | 34 | * Context for all functions in this plugin. |
35 | */ | 35 | */ |
36 | struct Plugin { | 36 | struct Plugin |
37 | { | ||
37 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 38 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
38 | 39 | ||
39 | /** | 40 | /** |
@@ -48,7 +49,8 @@ struct Plugin { | |||
48 | }; | 49 | }; |
49 | 50 | ||
50 | 51 | ||
51 | struct FlatFileEntry { | 52 | struct FlatFileEntry |
53 | { | ||
52 | /** | 54 | /** |
53 | * Entry zone | 55 | * Entry zone |
54 | */ | 56 | */ |
@@ -84,27 +86,27 @@ struct FlatFileEntry { | |||
84 | * @param h[out] initialized hash | 86 | * @param h[out] initialized hash |
85 | */ | 87 | */ |
86 | static void | 88 | static void |
87 | hash_pkey_and_label(const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | 89 | hash_pkey_and_label (const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, |
88 | const char *label, | 90 | const char *label, |
89 | struct GNUNET_HashCode *h) | 91 | struct GNUNET_HashCode *h) |
90 | { | 92 | { |
91 | char *key; | 93 | char *key; |
92 | size_t label_len; | 94 | size_t label_len; |
93 | size_t key_len; | 95 | size_t key_len; |
94 | 96 | ||
95 | label_len = strlen(label); | 97 | label_len = strlen (label); |
96 | key_len = label_len + sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey); | 98 | key_len = label_len + sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey); |
97 | key = GNUNET_malloc(key_len); | 99 | key = GNUNET_malloc (key_len); |
98 | GNUNET_memcpy(key, | 100 | GNUNET_memcpy (key, |
99 | label, | 101 | label, |
100 | label_len); | 102 | label_len); |
101 | GNUNET_memcpy(key + label_len, | 103 | GNUNET_memcpy (key + label_len, |
102 | pkey, | 104 | pkey, |
103 | sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey)); | 105 | sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey)); |
104 | GNUNET_CRYPTO_hash(key, | 106 | GNUNET_CRYPTO_hash (key, |
105 | key_len, | 107 | key_len, |
106 | h); | 108 | h); |
107 | GNUNET_free(key); | 109 | GNUNET_free (key); |
108 | } | 110 | } |
109 | 111 | ||
110 | 112 | ||
@@ -117,7 +119,7 @@ hash_pkey_and_label(const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | |||
117 | * @return #GNUNET_OK on success | 119 | * @return #GNUNET_OK on success |
118 | */ | 120 | */ |
119 | static int | 121 | static int |
120 | database_setup(struct Plugin *plugin) | 122 | database_setup (struct Plugin *plugin) |
121 | { | 123 | { |
122 | char *flatdbfile; | 124 | char *flatdbfile; |
123 | char *record_data; | 125 | char *record_data; |
@@ -136,188 +138,188 @@ database_setup(struct Plugin *plugin) | |||
136 | struct GNUNET_DISK_MapHandle *mh; | 138 | struct GNUNET_DISK_MapHandle *mh; |
137 | 139 | ||
138 | if (GNUNET_OK != | 140 | if (GNUNET_OK != |
139 | GNUNET_CONFIGURATION_get_value_filename(plugin->cfg, | 141 | GNUNET_CONFIGURATION_get_value_filename (plugin->cfg, |
140 | "namestore-flat", | 142 | "namestore-flat", |
141 | "FILENAME", | 143 | "FILENAME", |
142 | &flatdbfile)) | 144 | &flatdbfile)) |
143 | { | 145 | { |
144 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, | 146 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
145 | "namestore-flat", | 147 | "namestore-flat", |
146 | "FILENAME"); | 148 | "FILENAME"); |
147 | return GNUNET_SYSERR; | 149 | return GNUNET_SYSERR; |
148 | } | 150 | } |
149 | if (GNUNET_OK != | 151 | if (GNUNET_OK != |
150 | GNUNET_DISK_file_test(flatdbfile)) | 152 | GNUNET_DISK_file_test (flatdbfile)) |
153 | { | ||
154 | if (GNUNET_OK != | ||
155 | GNUNET_DISK_directory_create_for_file (flatdbfile)) | ||
151 | { | 156 | { |
152 | if (GNUNET_OK != | 157 | GNUNET_break (0); |
153 | GNUNET_DISK_directory_create_for_file(flatdbfile)) | 158 | GNUNET_free (flatdbfile); |
154 | { | 159 | return GNUNET_SYSERR; |
155 | GNUNET_break(0); | ||
156 | GNUNET_free(flatdbfile); | ||
157 | return GNUNET_SYSERR; | ||
158 | } | ||
159 | } | 160 | } |
161 | } | ||
160 | /* flatdbfile should be UTF-8-encoded. If it isn't, it's a bug */ | 162 | /* flatdbfile should be UTF-8-encoded. If it isn't, it's a bug */ |
161 | plugin->fn = flatdbfile; | 163 | plugin->fn = flatdbfile; |
162 | 164 | ||
163 | /* Load data from file into hashmap */ | 165 | /* Load data from file into hashmap */ |
164 | plugin->hm = GNUNET_CONTAINER_multihashmap_create(10, | 166 | plugin->hm = GNUNET_CONTAINER_multihashmap_create (10, |
165 | GNUNET_NO); | 167 | GNUNET_NO); |
166 | fh = GNUNET_DISK_file_open(flatdbfile, | 168 | fh = GNUNET_DISK_file_open (flatdbfile, |
167 | GNUNET_DISK_OPEN_CREATE | | 169 | GNUNET_DISK_OPEN_CREATE |
168 | GNUNET_DISK_OPEN_READWRITE, | 170 | | GNUNET_DISK_OPEN_READWRITE, |
169 | GNUNET_DISK_PERM_USER_WRITE | | 171 | GNUNET_DISK_PERM_USER_WRITE |
170 | GNUNET_DISK_PERM_USER_READ); | 172 | | GNUNET_DISK_PERM_USER_READ); |
171 | if (NULL == fh) | 173 | if (NULL == fh) |
172 | { | 174 | { |
173 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 175 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
174 | _("Unable to initialize file: %s.\n"), | 176 | _ ("Unable to initialize file: %s.\n"), |
175 | flatdbfile); | 177 | flatdbfile); |
176 | return GNUNET_SYSERR; | 178 | return GNUNET_SYSERR; |
177 | } | 179 | } |
178 | if (GNUNET_SYSERR == | 180 | if (GNUNET_SYSERR == |
179 | GNUNET_DISK_file_size(flatdbfile, | 181 | GNUNET_DISK_file_size (flatdbfile, |
180 | &size, | 182 | &size, |
181 | GNUNET_YES, | 183 | GNUNET_YES, |
182 | GNUNET_YES)) | 184 | GNUNET_YES)) |
183 | { | 185 | { |
184 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 186 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
185 | _("Unable to get filesize: %s.\n"), | 187 | _ ("Unable to get filesize: %s.\n"), |
186 | flatdbfile); | 188 | flatdbfile); |
187 | GNUNET_DISK_file_close(fh); | 189 | GNUNET_DISK_file_close (fh); |
188 | return GNUNET_SYSERR; | 190 | return GNUNET_SYSERR; |
189 | } | 191 | } |
190 | if (size > SIZE_MAX) | 192 | if (size > SIZE_MAX) |
191 | { | 193 | { |
192 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 194 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
193 | _("File too big to map: %llu bytes.\n"), | 195 | _ ("File too big to map: %llu bytes.\n"), |
194 | (unsigned long long)size); | 196 | (unsigned long long) size); |
195 | GNUNET_DISK_file_close(fh); | 197 | GNUNET_DISK_file_close (fh); |
196 | return GNUNET_SYSERR; | 198 | return GNUNET_SYSERR; |
197 | } | 199 | } |
198 | if (0 == size) | 200 | if (0 == size) |
199 | { | 201 | { |
200 | GNUNET_DISK_file_close(fh); | 202 | GNUNET_DISK_file_close (fh); |
201 | return GNUNET_OK; | 203 | return GNUNET_OK; |
202 | } | 204 | } |
203 | buffer = GNUNET_DISK_file_map(fh, | 205 | buffer = GNUNET_DISK_file_map (fh, |
204 | &mh, | 206 | &mh, |
205 | GNUNET_DISK_MAP_TYPE_READ, | 207 | GNUNET_DISK_MAP_TYPE_READ, |
206 | size); | 208 | size); |
207 | if (NULL == buffer) | 209 | if (NULL == buffer) |
208 | { | 210 | { |
209 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, | 211 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, |
210 | "mmap"); | 212 | "mmap"); |
211 | GNUNET_DISK_file_close(fh); | 213 | GNUNET_DISK_file_close (fh); |
212 | return GNUNET_SYSERR; | 214 | return GNUNET_SYSERR; |
213 | } | 215 | } |
214 | if ('\0' != buffer[size - 1]) | 216 | if ('\0' != buffer[size - 1]) |
215 | { | 217 | { |
216 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 218 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
217 | _("Namestore database file `%s' malformed\n"), | 219 | _ ("Namestore database file `%s' malformed\n"), |
218 | flatdbfile); | 220 | flatdbfile); |
219 | GNUNET_DISK_file_unmap(mh); | 221 | GNUNET_DISK_file_unmap (mh); |
220 | GNUNET_DISK_file_close(fh); | 222 | GNUNET_DISK_file_close (fh); |
221 | return GNUNET_SYSERR; | 223 | return GNUNET_SYSERR; |
222 | } | 224 | } |
223 | 225 | ||
224 | line = strtok(buffer, "\n"); | 226 | line = strtok (buffer, "\n"); |
225 | while (NULL != line) | 227 | while (NULL != line) |
228 | { | ||
229 | zone_private_key = strtok (line, ","); | ||
230 | if (NULL == zone_private_key) | ||
231 | break; | ||
232 | rvalue = strtok (NULL, ","); | ||
233 | if (NULL == rvalue) | ||
234 | break; | ||
235 | record_count = strtok (NULL, ","); | ||
236 | if (NULL == record_count) | ||
237 | break; | ||
238 | record_data_b64 = strtok (NULL, ","); | ||
239 | if (NULL == record_data_b64) | ||
240 | break; | ||
241 | label = strtok (NULL, ","); | ||
242 | if (NULL == label) | ||
243 | break; | ||
244 | line = strtok (NULL, "\n"); | ||
245 | entry = GNUNET_new (struct FlatFileEntry); | ||
226 | { | 246 | { |
227 | zone_private_key = strtok(line, ","); | 247 | unsigned long long ll; |
228 | if (NULL == zone_private_key) | 248 | |
229 | break; | 249 | if (1 != sscanf (rvalue, |
230 | rvalue = strtok(NULL, ","); | 250 | "%llu", |
231 | if (NULL == rvalue) | 251 | &ll)) |
232 | break; | ||
233 | record_count = strtok(NULL, ","); | ||
234 | if (NULL == record_count) | ||
235 | break; | ||
236 | record_data_b64 = strtok(NULL, ","); | ||
237 | if (NULL == record_data_b64) | ||
238 | break; | ||
239 | label = strtok(NULL, ","); | ||
240 | if (NULL == label) | ||
241 | break; | ||
242 | line = strtok(NULL, "\n"); | ||
243 | entry = GNUNET_new(struct FlatFileEntry); | ||
244 | { | 252 | { |
245 | unsigned long long ll; | 253 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
246 | 254 | "Error parsing entry\n"); | |
247 | if (1 != sscanf(rvalue, | 255 | GNUNET_free (entry); |
248 | "%llu", | 256 | break; |
249 | &ll)) | ||
250 | { | ||
251 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
252 | "Error parsing entry\n"); | ||
253 | GNUNET_free(entry); | ||
254 | break; | ||
255 | } | ||
256 | entry->rvalue = (uint64_t)ll; | ||
257 | } | 257 | } |
258 | entry->rvalue = (uint64_t) ll; | ||
259 | } | ||
260 | { | ||
261 | unsigned int ui; | ||
262 | |||
263 | if (1 != sscanf (record_count, | ||
264 | "%u", | ||
265 | &ui)) | ||
258 | { | 266 | { |
259 | unsigned int ui; | 267 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
260 | 268 | "Error parsing entry\n"); | |
261 | if (1 != sscanf(record_count, | 269 | GNUNET_free (entry); |
262 | "%u", | 270 | break; |
263 | &ui)) | ||
264 | { | ||
265 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
266 | "Error parsing entry\n"); | ||
267 | GNUNET_free(entry); | ||
268 | break; | ||
269 | } | ||
270 | entry->record_count = (uint32_t)ui; | ||
271 | } | 271 | } |
272 | entry->label = GNUNET_strdup(label); | 272 | entry->record_count = (uint32_t) ui; |
273 | record_data_size | 273 | } |
274 | = GNUNET_STRINGS_base64_decode(record_data_b64, | 274 | entry->label = GNUNET_strdup (label); |
275 | strlen(record_data_b64), | 275 | record_data_size |
276 | (void **)&record_data); | 276 | = GNUNET_STRINGS_base64_decode (record_data_b64, |
277 | entry->record_data = | 277 | strlen (record_data_b64), |
278 | GNUNET_new_array(entry->record_count, | 278 | (void **) &record_data); |
279 | struct GNUNET_GNSRECORD_Data); | 279 | entry->record_data = |
280 | if (GNUNET_OK != | 280 | GNUNET_new_array (entry->record_count, |
281 | GNUNET_GNSRECORD_records_deserialize(record_data_size, | 281 | struct GNUNET_GNSRECORD_Data); |
282 | record_data, | 282 | if (GNUNET_OK != |
283 | entry->record_count, | 283 | GNUNET_GNSRECORD_records_deserialize (record_data_size, |
284 | entry->record_data)) | 284 | record_data, |
285 | { | 285 | entry->record_count, |
286 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 286 | entry->record_data)) |
287 | "Unable to deserialize record %s\n", | 287 | { |
288 | label); | 288 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
289 | GNUNET_free(entry->label); | 289 | "Unable to deserialize record %s\n", |
290 | GNUNET_free(entry); | 290 | label); |
291 | GNUNET_free(record_data); | 291 | GNUNET_free (entry->label); |
292 | break; | 292 | GNUNET_free (entry); |
293 | } | 293 | GNUNET_free (record_data); |
294 | GNUNET_free(record_data); | 294 | break; |
295 | } | ||
296 | GNUNET_free (record_data); | ||
295 | 297 | ||
296 | { | 298 | { |
297 | struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key; | 299 | struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key; |
298 | 300 | ||
299 | GNUNET_STRINGS_base64_decode(zone_private_key, | 301 | GNUNET_STRINGS_base64_decode (zone_private_key, |
300 | strlen(zone_private_key), | 302 | strlen (zone_private_key), |
301 | (void**)&private_key); | 303 | (void**) &private_key); |
302 | entry->private_key = *private_key; | 304 | entry->private_key = *private_key; |
303 | GNUNET_free(private_key); | 305 | GNUNET_free (private_key); |
304 | } | 306 | } |
305 | 307 | ||
306 | hash_pkey_and_label(&entry->private_key, | 308 | hash_pkey_and_label (&entry->private_key, |
307 | label, | 309 | label, |
308 | &hkey); | 310 | &hkey); |
309 | if (GNUNET_OK != | 311 | if (GNUNET_OK != |
310 | GNUNET_CONTAINER_multihashmap_put(plugin->hm, | 312 | GNUNET_CONTAINER_multihashmap_put (plugin->hm, |
311 | &hkey, | 313 | &hkey, |
312 | entry, | 314 | entry, |
313 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | 315 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) |
314 | { | 316 | { |
315 | GNUNET_free(entry); | 317 | GNUNET_free (entry); |
316 | GNUNET_break(0); | 318 | GNUNET_break (0); |
317 | } | ||
318 | } | 319 | } |
319 | GNUNET_DISK_file_unmap(mh); | 320 | } |
320 | GNUNET_DISK_file_close(fh); | 321 | GNUNET_DISK_file_unmap (mh); |
322 | GNUNET_DISK_file_close (fh); | ||
321 | return GNUNET_OK; | 323 | return GNUNET_OK; |
322 | } | 324 | } |
323 | 325 | ||
@@ -330,9 +332,9 @@ database_setup(struct Plugin *plugin) | |||
330 | * @param value a `struct FlatFileEntry` | 332 | * @param value a `struct FlatFileEntry` |
331 | */ | 333 | */ |
332 | static int | 334 | static int |
333 | store_and_free_entries(void *cls, | 335 | store_and_free_entries (void *cls, |
334 | const struct GNUNET_HashCode *key, | 336 | const struct GNUNET_HashCode *key, |
335 | void *value) | 337 | void *value) |
336 | { | 338 | { |
337 | struct GNUNET_DISK_FileHandle *fh = cls; | 339 | struct GNUNET_DISK_FileHandle *fh = cls; |
338 | struct FlatFileEntry *entry = value; | 340 | struct FlatFileEntry *entry = value; |
@@ -341,61 +343,61 @@ store_and_free_entries(void *cls, | |||
341 | char *record_data_b64; | 343 | char *record_data_b64; |
342 | ssize_t data_size; | 344 | ssize_t data_size; |
343 | 345 | ||
344 | (void)key; | 346 | (void) key; |
345 | GNUNET_STRINGS_base64_encode(&entry->private_key, | 347 | GNUNET_STRINGS_base64_encode (&entry->private_key, |
346 | sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey), | 348 | sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey), |
347 | &zone_private_key); | 349 | &zone_private_key); |
348 | data_size = GNUNET_GNSRECORD_records_get_size(entry->record_count, | 350 | data_size = GNUNET_GNSRECORD_records_get_size (entry->record_count, |
349 | entry->record_data); | 351 | entry->record_data); |
350 | if (data_size < 0) | 352 | if (data_size < 0) |
351 | { | 353 | { |
352 | GNUNET_break(0); | 354 | GNUNET_break (0); |
353 | GNUNET_free(zone_private_key); | 355 | GNUNET_free (zone_private_key); |
354 | return GNUNET_SYSERR; | 356 | return GNUNET_SYSERR; |
355 | } | 357 | } |
356 | if (data_size >= UINT16_MAX) | 358 | if (data_size >= UINT16_MAX) |
357 | { | 359 | { |
358 | GNUNET_break(0); | 360 | GNUNET_break (0); |
359 | GNUNET_free(zone_private_key); | 361 | GNUNET_free (zone_private_key); |
360 | return GNUNET_SYSERR; | 362 | return GNUNET_SYSERR; |
361 | } | 363 | } |
362 | { | 364 | { |
363 | char data[data_size]; | 365 | char data[data_size]; |
364 | ssize_t ret; | 366 | ssize_t ret; |
365 | 367 | ||
366 | ret = GNUNET_GNSRECORD_records_serialize(entry->record_count, | 368 | ret = GNUNET_GNSRECORD_records_serialize (entry->record_count, |
367 | entry->record_data, | 369 | entry->record_data, |
368 | data_size, | 370 | data_size, |
369 | data); | 371 | data); |
370 | if ((ret < 0) || | 372 | if ((ret < 0) || |
371 | (data_size != ret)) | 373 | (data_size != ret)) |
372 | { | 374 | { |
373 | GNUNET_break(0); | 375 | GNUNET_break (0); |
374 | GNUNET_free(zone_private_key); | 376 | GNUNET_free (zone_private_key); |
375 | return GNUNET_SYSERR; | 377 | return GNUNET_SYSERR; |
376 | } | 378 | } |
377 | GNUNET_STRINGS_base64_encode(data, | 379 | GNUNET_STRINGS_base64_encode (data, |
378 | data_size, | 380 | data_size, |
379 | &record_data_b64); | 381 | &record_data_b64); |
380 | } | 382 | } |
381 | GNUNET_asprintf(&line, | 383 | GNUNET_asprintf (&line, |
382 | "%s,%llu,%u,%s,%s\n", | 384 | "%s,%llu,%u,%s,%s\n", |
383 | zone_private_key, | 385 | zone_private_key, |
384 | (unsigned long long)entry->rvalue, | 386 | (unsigned long long) entry->rvalue, |
385 | (unsigned int)entry->record_count, | 387 | (unsigned int) entry->record_count, |
386 | record_data_b64, | 388 | record_data_b64, |
387 | entry->label); | 389 | entry->label); |
388 | GNUNET_free(record_data_b64); | 390 | GNUNET_free (record_data_b64); |
389 | GNUNET_free(zone_private_key); | 391 | GNUNET_free (zone_private_key); |
390 | 392 | ||
391 | GNUNET_DISK_file_write(fh, | 393 | GNUNET_DISK_file_write (fh, |
392 | line, | 394 | line, |
393 | strlen(line)); | 395 | strlen (line)); |
394 | 396 | ||
395 | GNUNET_free(line); | 397 | GNUNET_free (line); |
396 | GNUNET_free(entry->label); | 398 | GNUNET_free (entry->label); |
397 | GNUNET_free(entry->record_data); | 399 | GNUNET_free (entry->record_data); |
398 | GNUNET_free(entry); | 400 | GNUNET_free (entry); |
399 | return GNUNET_YES; | 401 | return GNUNET_YES; |
400 | } | 402 | } |
401 | 403 | ||
@@ -406,33 +408,33 @@ store_and_free_entries(void *cls, | |||
406 | * @param plugin the plugin context (state for this module) | 408 | * @param plugin the plugin context (state for this module) |
407 | */ | 409 | */ |
408 | static void | 410 | static void |
409 | database_shutdown(struct Plugin *plugin) | 411 | database_shutdown (struct Plugin *plugin) |
410 | { | 412 | { |
411 | struct GNUNET_DISK_FileHandle *fh; | 413 | struct GNUNET_DISK_FileHandle *fh; |
412 | 414 | ||
413 | fh = GNUNET_DISK_file_open(plugin->fn, | 415 | fh = GNUNET_DISK_file_open (plugin->fn, |
414 | GNUNET_DISK_OPEN_CREATE | | 416 | GNUNET_DISK_OPEN_CREATE |
415 | GNUNET_DISK_OPEN_TRUNCATE | | 417 | | GNUNET_DISK_OPEN_TRUNCATE |
416 | GNUNET_DISK_OPEN_READWRITE, | 418 | | GNUNET_DISK_OPEN_READWRITE, |
417 | GNUNET_DISK_PERM_USER_WRITE | | 419 | GNUNET_DISK_PERM_USER_WRITE |
418 | GNUNET_DISK_PERM_USER_READ); | 420 | | GNUNET_DISK_PERM_USER_READ); |
419 | if (NULL == fh) | 421 | if (NULL == fh) |
420 | { | 422 | { |
421 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 423 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
422 | _("Unable to initialize file: %s.\n"), | 424 | _ ("Unable to initialize file: %s.\n"), |
423 | plugin->fn); | 425 | plugin->fn); |
424 | return; | 426 | return; |
425 | } | 427 | } |
426 | 428 | ||
427 | GNUNET_CONTAINER_multihashmap_iterate(plugin->hm, | 429 | GNUNET_CONTAINER_multihashmap_iterate (plugin->hm, |
428 | &store_and_free_entries, | 430 | &store_and_free_entries, |
429 | fh); | 431 | fh); |
430 | GNUNET_CONTAINER_multihashmap_destroy(plugin->hm); | 432 | GNUNET_CONTAINER_multihashmap_destroy (plugin->hm); |
431 | /* append 0-terminator */ | 433 | /* append 0-terminator */ |
432 | GNUNET_DISK_file_write(fh, | 434 | GNUNET_DISK_file_write (fh, |
433 | "", | 435 | "", |
434 | 1); | 436 | 1); |
435 | GNUNET_DISK_file_close(fh); | 437 | GNUNET_DISK_file_close (fh); |
436 | } | 438 | } |
437 | 439 | ||
438 | 440 | ||
@@ -448,57 +450,58 @@ database_shutdown(struct Plugin *plugin) | |||
448 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | 450 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR |
449 | */ | 451 | */ |
450 | static int | 452 | static int |
451 | namestore_flat_store_records(void *cls, | 453 | namestore_flat_store_records (void *cls, |
452 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 454 | const struct |
453 | const char *label, | 455 | GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, |
454 | unsigned int rd_count, | 456 | const char *label, |
455 | const struct GNUNET_GNSRECORD_Data *rd) | 457 | unsigned int rd_count, |
458 | const struct GNUNET_GNSRECORD_Data *rd) | ||
456 | { | 459 | { |
457 | struct Plugin *plugin = cls; | 460 | struct Plugin *plugin = cls; |
458 | uint64_t rvalue; | 461 | uint64_t rvalue; |
459 | struct GNUNET_HashCode hkey; | 462 | struct GNUNET_HashCode hkey; |
460 | struct FlatFileEntry *entry; | 463 | struct FlatFileEntry *entry; |
461 | 464 | ||
462 | rvalue = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, | 465 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
463 | UINT64_MAX); | 466 | UINT64_MAX); |
464 | hash_pkey_and_label(zone_key, | 467 | hash_pkey_and_label (zone_key, |
465 | label, | 468 | label, |
466 | &hkey); | 469 | &hkey); |
467 | GNUNET_CONTAINER_multihashmap_remove_all(plugin->hm, | 470 | GNUNET_CONTAINER_multihashmap_remove_all (plugin->hm, |
468 | &hkey); | 471 | &hkey); |
469 | if (0 == rd_count) | 472 | if (0 == rd_count) |
470 | { | 473 | { |
471 | GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, | 474 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
472 | "sqlite", | 475 | "sqlite", |
473 | "Record deleted\n"); | 476 | "Record deleted\n"); |
474 | return GNUNET_OK; | 477 | return GNUNET_OK; |
475 | } | 478 | } |
476 | entry = GNUNET_new(struct FlatFileEntry); | 479 | entry = GNUNET_new (struct FlatFileEntry); |
477 | GNUNET_asprintf(&entry->label, | 480 | GNUNET_asprintf (&entry->label, |
478 | label, | 481 | label, |
479 | strlen(label)); | 482 | strlen (label)); |
480 | GNUNET_memcpy(&entry->private_key, | 483 | GNUNET_memcpy (&entry->private_key, |
481 | zone_key, | 484 | zone_key, |
482 | sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey)); | 485 | sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey)); |
483 | entry->rvalue = rvalue; | 486 | entry->rvalue = rvalue; |
484 | entry->record_count = rd_count; | 487 | entry->record_count = rd_count; |
485 | entry->record_data = GNUNET_new_array(rd_count, | 488 | entry->record_data = GNUNET_new_array (rd_count, |
486 | struct GNUNET_GNSRECORD_Data); | 489 | struct GNUNET_GNSRECORD_Data); |
487 | for (unsigned int i = 0; i < rd_count; i++) | 490 | for (unsigned int i = 0; i < rd_count; i++) |
488 | { | 491 | { |
489 | entry->record_data[i].expiration_time = rd[i].expiration_time; | 492 | entry->record_data[i].expiration_time = rd[i].expiration_time; |
490 | entry->record_data[i].record_type = rd[i].record_type; | 493 | entry->record_data[i].record_type = rd[i].record_type; |
491 | entry->record_data[i].flags = rd[i].flags; | 494 | entry->record_data[i].flags = rd[i].flags; |
492 | entry->record_data[i].data_size = rd[i].data_size; | 495 | entry->record_data[i].data_size = rd[i].data_size; |
493 | entry->record_data[i].data = GNUNET_malloc(rd[i].data_size); | 496 | entry->record_data[i].data = GNUNET_malloc (rd[i].data_size); |
494 | GNUNET_memcpy((char*)entry->record_data[i].data, | 497 | GNUNET_memcpy ((char*) entry->record_data[i].data, |
495 | rd[i].data, | 498 | rd[i].data, |
496 | rd[i].data_size); | 499 | rd[i].data_size); |
497 | } | 500 | } |
498 | return GNUNET_CONTAINER_multihashmap_put(plugin->hm, | 501 | return GNUNET_CONTAINER_multihashmap_put (plugin->hm, |
499 | &hkey, | 502 | &hkey, |
500 | entry, | 503 | entry, |
501 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 504 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
502 | } | 505 | } |
503 | 506 | ||
504 | 507 | ||
@@ -513,36 +516,36 @@ namestore_flat_store_records(void *cls, | |||
513 | * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR | 516 | * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR |
514 | */ | 517 | */ |
515 | static int | 518 | static int |
516 | namestore_flat_lookup_records(void *cls, | 519 | namestore_flat_lookup_records (void *cls, |
517 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 520 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
518 | const char *label, | 521 | const char *label, |
519 | GNUNET_NAMESTORE_RecordIterator iter, | 522 | GNUNET_NAMESTORE_RecordIterator iter, |
520 | void *iter_cls) | 523 | void *iter_cls) |
521 | { | 524 | { |
522 | struct Plugin *plugin = cls; | 525 | struct Plugin *plugin = cls; |
523 | struct FlatFileEntry *entry; | 526 | struct FlatFileEntry *entry; |
524 | struct GNUNET_HashCode hkey; | 527 | struct GNUNET_HashCode hkey; |
525 | 528 | ||
526 | if (NULL == zone) | 529 | if (NULL == zone) |
527 | { | 530 | { |
528 | GNUNET_break(0); | 531 | GNUNET_break (0); |
529 | return GNUNET_SYSERR; | 532 | return GNUNET_SYSERR; |
530 | } | 533 | } |
531 | hash_pkey_and_label(zone, | 534 | hash_pkey_and_label (zone, |
532 | label, | 535 | label, |
533 | &hkey); | 536 | &hkey); |
534 | entry = GNUNET_CONTAINER_multihashmap_get(plugin->hm, | 537 | entry = GNUNET_CONTAINER_multihashmap_get (plugin->hm, |
535 | &hkey); | 538 | &hkey); |
536 | 539 | ||
537 | if (NULL == entry) | 540 | if (NULL == entry) |
538 | return GNUNET_NO; | 541 | return GNUNET_NO; |
539 | if (NULL != iter) | 542 | if (NULL != iter) |
540 | iter(iter_cls, | 543 | iter (iter_cls, |
541 | 1, /* zero is illegal */ | 544 | 1, /* zero is illegal */ |
542 | &entry->private_key, | 545 | &entry->private_key, |
543 | entry->label, | 546 | entry->label, |
544 | entry->record_count, | 547 | entry->record_count, |
545 | entry->record_data); | 548 | entry->record_data); |
546 | return GNUNET_YES; | 549 | return GNUNET_YES; |
547 | } | 550 | } |
548 | 551 | ||
@@ -550,7 +553,8 @@ namestore_flat_lookup_records(void *cls, | |||
550 | /** | 553 | /** |
551 | * Closure for #iterate_zones. | 554 | * Closure for #iterate_zones. |
552 | */ | 555 | */ |
553 | struct IterateContext { | 556 | struct IterateContext |
557 | { | ||
554 | /** | 558 | /** |
555 | * How many more records should we skip before returning results? | 559 | * How many more records should we skip before returning results? |
556 | */ | 560 | */ |
@@ -593,34 +597,34 @@ struct IterateContext { | |||
593 | * @return #GNUNET_YES to continue the iteration | 597 | * @return #GNUNET_YES to continue the iteration |
594 | */ | 598 | */ |
595 | static int | 599 | static int |
596 | iterate_zones(void *cls, | 600 | iterate_zones (void *cls, |
597 | const struct GNUNET_HashCode *key, | 601 | const struct GNUNET_HashCode *key, |
598 | void *value) | 602 | void *value) |
599 | { | 603 | { |
600 | struct IterateContext *ic = cls; | 604 | struct IterateContext *ic = cls; |
601 | struct FlatFileEntry *entry = value; | 605 | struct FlatFileEntry *entry = value; |
602 | 606 | ||
603 | (void)key; | 607 | (void) key; |
604 | if (0 == ic->limit) | 608 | if (0 == ic->limit) |
605 | return GNUNET_NO; | 609 | return GNUNET_NO; |
606 | if ((NULL != ic->zone) && | 610 | if ((NULL != ic->zone) && |
607 | (0 != GNUNET_memcmp(&entry->private_key, | 611 | (0 != GNUNET_memcmp (&entry->private_key, |
608 | ic->zone))) | 612 | ic->zone))) |
609 | return GNUNET_YES; | 613 | return GNUNET_YES; |
610 | ic->pos++; | 614 | ic->pos++; |
611 | if (ic->offset > 0) | 615 | if (ic->offset > 0) |
612 | { | 616 | { |
613 | ic->offset--; | 617 | ic->offset--; |
614 | return GNUNET_YES; | 618 | return GNUNET_YES; |
615 | } | 619 | } |
616 | ic->iter(ic->iter_cls, | 620 | ic->iter (ic->iter_cls, |
617 | ic->pos, | 621 | ic->pos, |
618 | (NULL == ic->zone) | 622 | (NULL == ic->zone) |
619 | ? &entry->private_key | 623 | ? &entry->private_key |
620 | : ic->zone, | 624 | : ic->zone, |
621 | entry->label, | 625 | entry->label, |
622 | entry->record_count, | 626 | entry->record_count, |
623 | entry->record_data); | 627 | entry->record_data); |
624 | ic->limit--; | 628 | ic->limit--; |
625 | if (0 == ic->limit) | 629 | if (0 == ic->limit) |
626 | return GNUNET_NO; | 630 | return GNUNET_NO; |
@@ -641,12 +645,13 @@ iterate_zones(void *cls, | |||
641 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no more results, #GNUNET_SYSERR on error | 645 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no more results, #GNUNET_SYSERR on error |
642 | */ | 646 | */ |
643 | static int | 647 | static int |
644 | namestore_flat_iterate_records(void *cls, | 648 | namestore_flat_iterate_records (void *cls, |
645 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 649 | const struct |
646 | uint64_t serial, | 650 | GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
647 | uint64_t limit, | 651 | uint64_t serial, |
648 | GNUNET_NAMESTORE_RecordIterator iter, | 652 | uint64_t limit, |
649 | void *iter_cls) | 653 | GNUNET_NAMESTORE_RecordIterator iter, |
654 | void *iter_cls) | ||
650 | { | 655 | { |
651 | struct Plugin *plugin = cls; | 656 | struct Plugin *plugin = cls; |
652 | struct IterateContext ic; | 657 | struct IterateContext ic; |
@@ -657,9 +662,9 @@ namestore_flat_iterate_records(void *cls, | |||
657 | ic.iter = iter; | 662 | ic.iter = iter; |
658 | ic.iter_cls = iter_cls; | 663 | ic.iter_cls = iter_cls; |
659 | ic.zone = zone; | 664 | ic.zone = zone; |
660 | GNUNET_CONTAINER_multihashmap_iterate(plugin->hm, | 665 | GNUNET_CONTAINER_multihashmap_iterate (plugin->hm, |
661 | &iterate_zones, | 666 | &iterate_zones, |
662 | &ic); | 667 | &ic); |
663 | return (0 == ic.limit) ? GNUNET_OK : GNUNET_NO; | 668 | return (0 == ic.limit) ? GNUNET_OK : GNUNET_NO; |
664 | } | 669 | } |
665 | 670 | ||
@@ -667,7 +672,8 @@ namestore_flat_iterate_records(void *cls, | |||
667 | /** | 672 | /** |
668 | * Closure for #zone_to_name. | 673 | * Closure for #zone_to_name. |
669 | */ | 674 | */ |
670 | struct ZoneToNameContext { | 675 | struct ZoneToNameContext |
676 | { | ||
671 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone; | 677 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone; |
672 | const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone; | 678 | const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone; |
673 | GNUNET_NAMESTORE_RecordIterator iter; | 679 | GNUNET_NAMESTORE_RecordIterator iter; |
@@ -678,35 +684,35 @@ struct ZoneToNameContext { | |||
678 | 684 | ||
679 | 685 | ||
680 | static int | 686 | static int |
681 | zone_to_name(void *cls, | 687 | zone_to_name (void *cls, |
682 | const struct GNUNET_HashCode *key, | 688 | const struct GNUNET_HashCode *key, |
683 | void *value) | 689 | void *value) |
684 | { | 690 | { |
685 | struct ZoneToNameContext *ztn = cls; | 691 | struct ZoneToNameContext *ztn = cls; |
686 | struct FlatFileEntry *entry = value; | 692 | struct FlatFileEntry *entry = value; |
687 | 693 | ||
688 | (void)key; | 694 | (void) key; |
689 | if (0 != GNUNET_memcmp(&entry->private_key, | 695 | if (0 != GNUNET_memcmp (&entry->private_key, |
690 | ztn->zone)) | 696 | ztn->zone)) |
691 | return GNUNET_YES; | 697 | return GNUNET_YES; |
692 | 698 | ||
693 | for (unsigned int i = 0; i < entry->record_count; i++) | 699 | for (unsigned int i = 0; i < entry->record_count; i++) |
700 | { | ||
701 | if (GNUNET_GNSRECORD_TYPE_PKEY != entry->record_data[i].record_type) | ||
702 | continue; | ||
703 | if (0 == memcmp (ztn->value_zone, | ||
704 | entry->record_data[i].data, | ||
705 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))) | ||
694 | { | 706 | { |
695 | if (GNUNET_GNSRECORD_TYPE_PKEY != entry->record_data[i].record_type) | 707 | ztn->iter (ztn->iter_cls, |
696 | continue; | 708 | i + 1, /* zero is illegal! */ |
697 | if (0 == memcmp(ztn->value_zone, | 709 | &entry->private_key, |
698 | entry->record_data[i].data, | 710 | entry->label, |
699 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))) | 711 | entry->record_count, |
700 | { | 712 | entry->record_data); |
701 | ztn->iter(ztn->iter_cls, | 713 | ztn->result_found = GNUNET_YES; |
702 | i + 1, /* zero is illegal! */ | ||
703 | &entry->private_key, | ||
704 | entry->label, | ||
705 | entry->record_count, | ||
706 | entry->record_data); | ||
707 | ztn->result_found = GNUNET_YES; | ||
708 | } | ||
709 | } | 714 | } |
715 | } | ||
710 | return GNUNET_YES; | 716 | return GNUNET_YES; |
711 | } | 717 | } |
712 | 718 | ||
@@ -723,11 +729,12 @@ zone_to_name(void *cls, | |||
723 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error | 729 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error |
724 | */ | 730 | */ |
725 | static int | 731 | static int |
726 | namestore_flat_zone_to_name(void *cls, | 732 | namestore_flat_zone_to_name (void *cls, |
727 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 733 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
728 | const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone, | 734 | const struct |
729 | GNUNET_NAMESTORE_RecordIterator iter, | 735 | GNUNET_CRYPTO_EcdsaPublicKey *value_zone, |
730 | void *iter_cls) | 736 | GNUNET_NAMESTORE_RecordIterator iter, |
737 | void *iter_cls) | ||
731 | { | 738 | { |
732 | struct Plugin *plugin = cls; | 739 | struct Plugin *plugin = cls; |
733 | struct ZoneToNameContext ztn = { | 740 | struct ZoneToNameContext ztn = { |
@@ -738,12 +745,12 @@ namestore_flat_zone_to_name(void *cls, | |||
738 | .result_found = GNUNET_NO | 745 | .result_found = GNUNET_NO |
739 | }; | 746 | }; |
740 | 747 | ||
741 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 748 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
742 | "Performing reverse lookup for `%s'\n", | 749 | "Performing reverse lookup for `%s'\n", |
743 | GNUNET_GNSRECORD_z2s(value_zone)); | 750 | GNUNET_GNSRECORD_z2s (value_zone)); |
744 | GNUNET_CONTAINER_multihashmap_iterate(plugin->hm, | 751 | GNUNET_CONTAINER_multihashmap_iterate (plugin->hm, |
745 | &zone_to_name, | 752 | &zone_to_name, |
746 | &ztn); | 753 | &ztn); |
747 | return ztn.result_found; | 754 | return ztn.result_found; |
748 | } | 755 | } |
749 | 756 | ||
@@ -755,7 +762,7 @@ namestore_flat_zone_to_name(void *cls, | |||
755 | * @return NULL on error, otherwise the plugin context | 762 | * @return NULL on error, otherwise the plugin context |
756 | */ | 763 | */ |
757 | void * | 764 | void * |
758 | libgnunet_plugin_namestore_flat_init(void *cls) | 765 | libgnunet_plugin_namestore_flat_init (void *cls) |
759 | { | 766 | { |
760 | static struct Plugin plugin; | 767 | static struct Plugin plugin; |
761 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 768 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
@@ -763,23 +770,23 @@ libgnunet_plugin_namestore_flat_init(void *cls) | |||
763 | 770 | ||
764 | if (NULL != plugin.cfg) | 771 | if (NULL != plugin.cfg) |
765 | return NULL; /* can only initialize once! */ | 772 | return NULL; /* can only initialize once! */ |
766 | memset(&plugin, | 773 | memset (&plugin, |
767 | 0, | 774 | 0, |
768 | sizeof(struct Plugin)); | 775 | sizeof(struct Plugin)); |
769 | plugin.cfg = cfg; | 776 | plugin.cfg = cfg; |
770 | if (GNUNET_OK != database_setup(&plugin)) | 777 | if (GNUNET_OK != database_setup (&plugin)) |
771 | { | 778 | { |
772 | database_shutdown(&plugin); | 779 | database_shutdown (&plugin); |
773 | return NULL; | 780 | return NULL; |
774 | } | 781 | } |
775 | api = GNUNET_new(struct GNUNET_NAMESTORE_PluginFunctions); | 782 | api = GNUNET_new (struct GNUNET_NAMESTORE_PluginFunctions); |
776 | api->cls = &plugin; | 783 | api->cls = &plugin; |
777 | api->store_records = &namestore_flat_store_records; | 784 | api->store_records = &namestore_flat_store_records; |
778 | api->iterate_records = &namestore_flat_iterate_records; | 785 | api->iterate_records = &namestore_flat_iterate_records; |
779 | api->zone_to_name = &namestore_flat_zone_to_name; | 786 | api->zone_to_name = &namestore_flat_zone_to_name; |
780 | api->lookup_records = &namestore_flat_lookup_records; | 787 | api->lookup_records = &namestore_flat_lookup_records; |
781 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 788 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
782 | _("Flat file database running\n")); | 789 | _ ("Flat file database running\n")); |
783 | return api; | 790 | return api; |
784 | } | 791 | } |
785 | 792 | ||
@@ -791,16 +798,16 @@ libgnunet_plugin_namestore_flat_init(void *cls) | |||
791 | * @return always NULL | 798 | * @return always NULL |
792 | */ | 799 | */ |
793 | void * | 800 | void * |
794 | libgnunet_plugin_namestore_flat_done(void *cls) | 801 | libgnunet_plugin_namestore_flat_done (void *cls) |
795 | { | 802 | { |
796 | struct GNUNET_NAMESTORE_PluginFunctions *api = cls; | 803 | struct GNUNET_NAMESTORE_PluginFunctions *api = cls; |
797 | struct Plugin *plugin = api->cls; | 804 | struct Plugin *plugin = api->cls; |
798 | 805 | ||
799 | database_shutdown(plugin); | 806 | database_shutdown (plugin); |
800 | plugin->cfg = NULL; | 807 | plugin->cfg = NULL; |
801 | GNUNET_free(api); | 808 | GNUNET_free (api); |
802 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 809 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
803 | "Flat file plugin is finished\n"); | 810 | "Flat file plugin is finished\n"); |
804 | return NULL; | 811 | return NULL; |
805 | } | 812 | } |
806 | 813 | ||
diff --git a/src/namestore/plugin_namestore_postgres.c b/src/namestore/plugin_namestore_postgres.c index ac35b01b4..5148ca0f5 100644 --- a/src/namestore/plugin_namestore_postgres.c +++ b/src/namestore/plugin_namestore_postgres.c | |||
@@ -31,13 +31,14 @@ | |||
31 | #include "namestore.h" | 31 | #include "namestore.h" |
32 | 32 | ||
33 | 33 | ||
34 | #define LOG(kind, ...) GNUNET_log_from(kind, "namestore-postgres", __VA_ARGS__) | 34 | #define LOG(kind, ...) GNUNET_log_from (kind, "namestore-postgres", __VA_ARGS__) |
35 | 35 | ||
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Context for all functions in this plugin. | 38 | * Context for all functions in this plugin. |
39 | */ | 39 | */ |
40 | struct Plugin { | 40 | struct Plugin |
41 | { | ||
41 | /** | 42 | /** |
42 | * Our configuration. | 43 | * Our configuration. |
43 | */ | 44 | */ |
@@ -59,136 +60,137 @@ struct Plugin { | |||
59 | * @return #GNUNET_OK on success | 60 | * @return #GNUNET_OK on success |
60 | */ | 61 | */ |
61 | static int | 62 | static int |
62 | database_setup(struct Plugin *plugin) | 63 | database_setup (struct Plugin *plugin) |
63 | { | 64 | { |
64 | struct GNUNET_PQ_ExecuteStatement es_temporary = | 65 | struct GNUNET_PQ_ExecuteStatement es_temporary = |
65 | GNUNET_PQ_make_execute("CREATE TEMPORARY TABLE IF NOT EXISTS ns098records (" | 66 | GNUNET_PQ_make_execute ( |
66 | " seq BIGSERIAL PRIMARY KEY," | 67 | "CREATE TEMPORARY TABLE IF NOT EXISTS ns098records (" |
67 | " zone_private_key BYTEA NOT NULL DEFAULT ''," | 68 | " seq BIGSERIAL PRIMARY KEY," |
68 | " pkey BYTEA DEFAULT ''," | 69 | " zone_private_key BYTEA NOT NULL DEFAULT ''," |
69 | " rvalue BYTEA NOT NULL DEFAULT ''," | 70 | " pkey BYTEA DEFAULT ''," |
70 | " record_count INTEGER NOT NULL DEFAULT 0," | 71 | " rvalue BYTEA NOT NULL DEFAULT ''," |
71 | " record_data BYTEA NOT NULL DEFAULT ''," | 72 | " record_count INTEGER NOT NULL DEFAULT 0," |
72 | " label TEXT NOT NULL DEFAULT ''," | 73 | " record_data BYTEA NOT NULL DEFAULT ''," |
73 | " CONSTRAINT zl UNIQUE (zone_private_key,label)" | 74 | " label TEXT NOT NULL DEFAULT ''," |
74 | ")" | 75 | " CONSTRAINT zl UNIQUE (zone_private_key,label)" |
75 | "WITH OIDS"); | 76 | ")" |
77 | "WITH OIDS"); | ||
76 | struct GNUNET_PQ_ExecuteStatement es_default = | 78 | struct GNUNET_PQ_ExecuteStatement es_default = |
77 | GNUNET_PQ_make_execute("CREATE TABLE IF NOT EXISTS ns098records (" | 79 | GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS ns098records (" |
78 | " seq BIGSERIAL PRIMARY KEY," | 80 | " seq BIGSERIAL PRIMARY KEY," |
79 | " zone_private_key BYTEA NOT NULL DEFAULT ''," | 81 | " zone_private_key BYTEA NOT NULL DEFAULT ''," |
80 | " pkey BYTEA DEFAULT ''," | 82 | " pkey BYTEA DEFAULT ''," |
81 | " rvalue BYTEA NOT NULL DEFAULT ''," | 83 | " rvalue BYTEA NOT NULL DEFAULT ''," |
82 | " record_count INTEGER NOT NULL DEFAULT 0," | 84 | " record_count INTEGER NOT NULL DEFAULT 0," |
83 | " record_data BYTEA NOT NULL DEFAULT ''," | 85 | " record_data BYTEA NOT NULL DEFAULT ''," |
84 | " label TEXT NOT NULL DEFAULT ''," | 86 | " label TEXT NOT NULL DEFAULT ''," |
85 | " CONSTRAINT zl UNIQUE (zone_private_key,label)" | 87 | " CONSTRAINT zl UNIQUE (zone_private_key,label)" |
86 | ")" | 88 | ")" |
87 | "WITH OIDS"); | 89 | "WITH OIDS"); |
88 | const struct GNUNET_PQ_ExecuteStatement *cr; | 90 | const struct GNUNET_PQ_ExecuteStatement *cr; |
89 | 91 | ||
90 | plugin->dbh = GNUNET_PQ_connect_with_cfg(plugin->cfg, | 92 | plugin->dbh = GNUNET_PQ_connect_with_cfg (plugin->cfg, |
91 | "namestore-postgres"); | 93 | "namestore-postgres"); |
92 | if (NULL == plugin->dbh) | 94 | if (NULL == plugin->dbh) |
93 | return GNUNET_SYSERR; | 95 | return GNUNET_SYSERR; |
94 | if (GNUNET_YES == | 96 | if (GNUNET_YES == |
95 | GNUNET_CONFIGURATION_get_value_yesno(plugin->cfg, | 97 | GNUNET_CONFIGURATION_get_value_yesno (plugin->cfg, |
96 | "namestore-postgres", | 98 | "namestore-postgres", |
97 | "ASYNC_COMMIT")) | 99 | "ASYNC_COMMIT")) |
98 | { | 100 | { |
99 | struct GNUNET_PQ_ExecuteStatement es[] = { | 101 | struct GNUNET_PQ_ExecuteStatement es[] = { |
100 | GNUNET_PQ_make_try_execute("SET synchronous_commit TO off"), | 102 | GNUNET_PQ_make_try_execute ("SET synchronous_commit TO off"), |
101 | GNUNET_PQ_EXECUTE_STATEMENT_END | 103 | GNUNET_PQ_EXECUTE_STATEMENT_END |
102 | }; | 104 | }; |
103 | 105 | ||
104 | if (GNUNET_OK != | 106 | if (GNUNET_OK != |
105 | GNUNET_PQ_exec_statements(plugin->dbh, | 107 | GNUNET_PQ_exec_statements (plugin->dbh, |
106 | es)) | 108 | es)) |
107 | { | ||
108 | PQfinish(plugin->dbh); | ||
109 | plugin->dbh = NULL; | ||
110 | return GNUNET_SYSERR; | ||
111 | } | ||
112 | } | ||
113 | if (GNUNET_YES == | ||
114 | GNUNET_CONFIGURATION_get_value_yesno(plugin->cfg, | ||
115 | "namestore-postgres", | ||
116 | "TEMPORARY_TABLE")) | ||
117 | { | 109 | { |
118 | cr = &es_temporary; | 110 | PQfinish (plugin->dbh); |
111 | plugin->dbh = NULL; | ||
112 | return GNUNET_SYSERR; | ||
119 | } | 113 | } |
114 | } | ||
115 | if (GNUNET_YES == | ||
116 | GNUNET_CONFIGURATION_get_value_yesno (plugin->cfg, | ||
117 | "namestore-postgres", | ||
118 | "TEMPORARY_TABLE")) | ||
119 | { | ||
120 | cr = &es_temporary; | ||
121 | } | ||
120 | else | 122 | else |
121 | { | 123 | { |
122 | cr = &es_default; | 124 | cr = &es_default; |
123 | } | 125 | } |
124 | 126 | ||
125 | { | 127 | { |
126 | struct GNUNET_PQ_ExecuteStatement es[] = { | 128 | struct GNUNET_PQ_ExecuteStatement es[] = { |
127 | *cr, | 129 | *cr, |
128 | GNUNET_PQ_make_try_execute("CREATE INDEX IF NOT EXISTS ir_pkey_reverse " | 130 | GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_reverse " |
129 | "ON ns098records (zone_private_key,pkey)"), | 131 | "ON ns098records (zone_private_key,pkey)"), |
130 | GNUNET_PQ_make_try_execute("CREATE INDEX IF NOT EXISTS ir_pkey_iter " | 132 | GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_iter " |
131 | "ON ns098records (zone_private_key,seq)"), | 133 | "ON ns098records (zone_private_key,seq)"), |
132 | GNUNET_PQ_make_try_execute("CREATE INDEX IF NOT EXISTS ir_label " | 134 | GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_label " |
133 | "ON ns098records (label)"), | 135 | "ON ns098records (label)"), |
134 | GNUNET_PQ_make_try_execute("CREATE INDEX IF NOT EXISTS zone_label " | 136 | GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS zone_label " |
135 | "ON ns098records (zone_private_key,label)"), | 137 | "ON ns098records (zone_private_key,label)"), |
136 | GNUNET_PQ_EXECUTE_STATEMENT_END | 138 | GNUNET_PQ_EXECUTE_STATEMENT_END |
137 | }; | 139 | }; |
138 | 140 | ||
139 | if (GNUNET_OK != | 141 | if (GNUNET_OK != |
140 | GNUNET_PQ_exec_statements(plugin->dbh, | 142 | GNUNET_PQ_exec_statements (plugin->dbh, |
141 | es)) | 143 | es)) |
142 | { | 144 | { |
143 | PQfinish(plugin->dbh); | 145 | PQfinish (plugin->dbh); |
144 | plugin->dbh = NULL; | 146 | plugin->dbh = NULL; |
145 | return GNUNET_SYSERR; | 147 | return GNUNET_SYSERR; |
146 | } | 148 | } |
147 | } | 149 | } |
148 | 150 | ||
149 | { | 151 | { |
150 | struct GNUNET_PQ_PreparedStatement ps[] = { | 152 | struct GNUNET_PQ_PreparedStatement ps[] = { |
151 | GNUNET_PQ_make_prepare("store_records", | 153 | GNUNET_PQ_make_prepare ("store_records", |
152 | "INSERT INTO ns098records" | 154 | "INSERT INTO ns098records" |
153 | " (zone_private_key, pkey, rvalue, record_count, record_data, label)" | 155 | " (zone_private_key, pkey, rvalue, record_count, record_data, label)" |
154 | " VALUES ($1, $2, $3, $4, $5, $6)" | 156 | " VALUES ($1, $2, $3, $4, $5, $6)" |
155 | " ON CONFLICT ON CONSTRAINT zl" | 157 | " ON CONFLICT ON CONSTRAINT zl" |
156 | " DO UPDATE" | 158 | " DO UPDATE" |
157 | " SET pkey=$2,rvalue=$3,record_count=$4,record_data=$5" | 159 | " SET pkey=$2,rvalue=$3,record_count=$4,record_data=$5" |
158 | " WHERE ns098records.zone_private_key = $1" | 160 | " WHERE ns098records.zone_private_key = $1" |
159 | " AND ns098records.label = $6", | 161 | " AND ns098records.label = $6", |
160 | 6), | 162 | 6), |
161 | GNUNET_PQ_make_prepare("delete_records", | 163 | GNUNET_PQ_make_prepare ("delete_records", |
162 | "DELETE FROM ns098records " | 164 | "DELETE FROM ns098records " |
163 | "WHERE zone_private_key=$1 AND label=$2", | 165 | "WHERE zone_private_key=$1 AND label=$2", |
164 | 2), | 166 | 2), |
165 | GNUNET_PQ_make_prepare("zone_to_name", | 167 | GNUNET_PQ_make_prepare ("zone_to_name", |
166 | "SELECT seq,record_count,record_data,label FROM ns098records" | 168 | "SELECT seq,record_count,record_data,label FROM ns098records" |
167 | " WHERE zone_private_key=$1 AND pkey=$2", | 169 | " WHERE zone_private_key=$1 AND pkey=$2", |
168 | 2), | 170 | 2), |
169 | GNUNET_PQ_make_prepare("iterate_zone", | 171 | GNUNET_PQ_make_prepare ("iterate_zone", |
170 | "SELECT seq,record_count,record_data,label FROM ns098records " | 172 | "SELECT seq,record_count,record_data,label FROM ns098records " |
171 | "WHERE zone_private_key=$1 AND seq > $2 ORDER BY seq ASC LIMIT $3", | 173 | "WHERE zone_private_key=$1 AND seq > $2 ORDER BY seq ASC LIMIT $3", |
172 | 3), | 174 | 3), |
173 | GNUNET_PQ_make_prepare("iterate_all_zones", | 175 | GNUNET_PQ_make_prepare ("iterate_all_zones", |
174 | "SELECT seq,record_count,record_data,label,zone_private_key" | 176 | "SELECT seq,record_count,record_data,label,zone_private_key" |
175 | " FROM ns098records WHERE seq > $1 ORDER BY seq ASC LIMIT $2", | 177 | " FROM ns098records WHERE seq > $1 ORDER BY seq ASC LIMIT $2", |
176 | 2), | 178 | 2), |
177 | GNUNET_PQ_make_prepare("lookup_label", | 179 | GNUNET_PQ_make_prepare ("lookup_label", |
178 | "SELECT seq,record_count,record_data,label " | 180 | "SELECT seq,record_count,record_data,label " |
179 | "FROM ns098records WHERE zone_private_key=$1 AND label=$2", | 181 | "FROM ns098records WHERE zone_private_key=$1 AND label=$2", |
180 | 2), | 182 | 2), |
181 | GNUNET_PQ_PREPARED_STATEMENT_END | 183 | GNUNET_PQ_PREPARED_STATEMENT_END |
182 | }; | 184 | }; |
183 | 185 | ||
184 | if (GNUNET_OK != | 186 | if (GNUNET_OK != |
185 | GNUNET_PQ_prepare_statements(plugin->dbh, | 187 | GNUNET_PQ_prepare_statements (plugin->dbh, |
186 | ps)) | 188 | ps)) |
187 | { | 189 | { |
188 | PQfinish(plugin->dbh); | 190 | PQfinish (plugin->dbh); |
189 | plugin->dbh = NULL; | 191 | plugin->dbh = NULL; |
190 | return GNUNET_SYSERR; | 192 | return GNUNET_SYSERR; |
191 | } | 193 | } |
192 | } | 194 | } |
193 | 195 | ||
194 | return GNUNET_OK; | 196 | return GNUNET_OK; |
@@ -207,97 +209,99 @@ database_setup(struct Plugin *plugin) | |||
207 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | 209 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR |
208 | */ | 210 | */ |
209 | static int | 211 | static int |
210 | namestore_postgres_store_records(void *cls, | 212 | namestore_postgres_store_records (void *cls, |
211 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 213 | const struct |
212 | const char *label, | 214 | GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, |
213 | unsigned int rd_count, | 215 | const char *label, |
214 | const struct GNUNET_GNSRECORD_Data *rd) | 216 | unsigned int rd_count, |
217 | const struct GNUNET_GNSRECORD_Data *rd) | ||
215 | { | 218 | { |
216 | struct Plugin *plugin = cls; | 219 | struct Plugin *plugin = cls; |
217 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | 220 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; |
218 | uint64_t rvalue; | 221 | uint64_t rvalue; |
219 | uint32_t rd_count32 = (uint32_t)rd_count; | 222 | uint32_t rd_count32 = (uint32_t) rd_count; |
220 | ssize_t data_size; | 223 | ssize_t data_size; |
221 | 224 | ||
222 | memset(&pkey, | 225 | memset (&pkey, |
223 | 0, | 226 | 0, |
224 | sizeof(pkey)); | 227 | sizeof(pkey)); |
225 | for (unsigned int i = 0; i < rd_count; i++) | 228 | for (unsigned int i = 0; i < rd_count; i++) |
226 | if (GNUNET_GNSRECORD_TYPE_PKEY == rd[i].record_type) | 229 | if (GNUNET_GNSRECORD_TYPE_PKEY == rd[i].record_type) |
227 | { | ||
228 | GNUNET_break(sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) == rd[i].data_size); | ||
229 | GNUNET_memcpy(&pkey, | ||
230 | rd[i].data, | ||
231 | rd[i].data_size); | ||
232 | break; | ||
233 | } | ||
234 | rvalue = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, | ||
235 | UINT64_MAX); | ||
236 | data_size = GNUNET_GNSRECORD_records_get_size(rd_count, | ||
237 | rd); | ||
238 | if (data_size < 0) | ||
239 | { | 230 | { |
240 | GNUNET_break(0); | 231 | GNUNET_break (sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) == |
241 | return GNUNET_SYSERR; | 232 | rd[i].data_size); |
233 | GNUNET_memcpy (&pkey, | ||
234 | rd[i].data, | ||
235 | rd[i].data_size); | ||
236 | break; | ||
242 | } | 237 | } |
238 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
239 | UINT64_MAX); | ||
240 | data_size = GNUNET_GNSRECORD_records_get_size (rd_count, | ||
241 | rd); | ||
242 | if (data_size < 0) | ||
243 | { | ||
244 | GNUNET_break (0); | ||
245 | return GNUNET_SYSERR; | ||
246 | } | ||
243 | if (data_size >= UINT16_MAX) | 247 | if (data_size >= UINT16_MAX) |
244 | { | 248 | { |
245 | GNUNET_break(0); | 249 | GNUNET_break (0); |
246 | return GNUNET_SYSERR; | 250 | return GNUNET_SYSERR; |
247 | } | 251 | } |
248 | /* if record set is empty, delete existing records */ | 252 | /* if record set is empty, delete existing records */ |
249 | if (0 == rd_count) | 253 | if (0 == rd_count) |
254 | { | ||
255 | struct GNUNET_PQ_QueryParam params[] = { | ||
256 | GNUNET_PQ_query_param_auto_from_type (zone_key), | ||
257 | GNUNET_PQ_query_param_string (label), | ||
258 | GNUNET_PQ_query_param_end | ||
259 | }; | ||
260 | enum GNUNET_DB_QueryStatus res; | ||
261 | |||
262 | res = GNUNET_PQ_eval_prepared_non_select (plugin->dbh, | ||
263 | "delete_records", | ||
264 | params); | ||
265 | if ((GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != res) && | ||
266 | (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != res)) | ||
250 | { | 267 | { |
251 | struct GNUNET_PQ_QueryParam params[] = { | 268 | GNUNET_break (0); |
252 | GNUNET_PQ_query_param_auto_from_type(zone_key), | 269 | return GNUNET_SYSERR; |
253 | GNUNET_PQ_query_param_string(label), | ||
254 | GNUNET_PQ_query_param_end | ||
255 | }; | ||
256 | enum GNUNET_DB_QueryStatus res; | ||
257 | |||
258 | res = GNUNET_PQ_eval_prepared_non_select(plugin->dbh, | ||
259 | "delete_records", | ||
260 | params); | ||
261 | if ((GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != res) && | ||
262 | (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != res)) | ||
263 | { | ||
264 | GNUNET_break(0); | ||
265 | return GNUNET_SYSERR; | ||
266 | } | ||
267 | GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, | ||
268 | "postgres", | ||
269 | "Record deleted\n"); | ||
270 | return GNUNET_OK; | ||
271 | } | 270 | } |
271 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | ||
272 | "postgres", | ||
273 | "Record deleted\n"); | ||
274 | return GNUNET_OK; | ||
275 | } | ||
272 | /* otherwise, UPSERT (i.e. UPDATE if exists, otherwise INSERT) */ | 276 | /* otherwise, UPSERT (i.e. UPDATE if exists, otherwise INSERT) */ |
273 | { | 277 | { |
274 | char data[data_size]; | 278 | char data[data_size]; |
275 | struct GNUNET_PQ_QueryParam params[] = { | 279 | struct GNUNET_PQ_QueryParam params[] = { |
276 | GNUNET_PQ_query_param_auto_from_type(zone_key), | 280 | GNUNET_PQ_query_param_auto_from_type (zone_key), |
277 | GNUNET_PQ_query_param_auto_from_type(&pkey), | 281 | GNUNET_PQ_query_param_auto_from_type (&pkey), |
278 | GNUNET_PQ_query_param_uint64(&rvalue), | 282 | GNUNET_PQ_query_param_uint64 (&rvalue), |
279 | GNUNET_PQ_query_param_uint32(&rd_count32), | 283 | GNUNET_PQ_query_param_uint32 (&rd_count32), |
280 | GNUNET_PQ_query_param_fixed_size(data, data_size), | 284 | GNUNET_PQ_query_param_fixed_size (data, data_size), |
281 | GNUNET_PQ_query_param_string(label), | 285 | GNUNET_PQ_query_param_string (label), |
282 | GNUNET_PQ_query_param_end | 286 | GNUNET_PQ_query_param_end |
283 | }; | 287 | }; |
284 | enum GNUNET_DB_QueryStatus res; | 288 | enum GNUNET_DB_QueryStatus res; |
285 | ssize_t ret; | 289 | ssize_t ret; |
286 | 290 | ||
287 | ret = GNUNET_GNSRECORD_records_serialize(rd_count, | 291 | ret = GNUNET_GNSRECORD_records_serialize (rd_count, |
288 | rd, | 292 | rd, |
289 | data_size, | 293 | data_size, |
290 | data); | 294 | data); |
291 | if ((ret < 0) || | 295 | if ((ret < 0) || |
292 | (data_size != ret)) | 296 | (data_size != ret)) |
293 | { | 297 | { |
294 | GNUNET_break(0); | 298 | GNUNET_break (0); |
295 | return GNUNET_SYSERR; | 299 | return GNUNET_SYSERR; |
296 | } | 300 | } |
297 | 301 | ||
298 | res = GNUNET_PQ_eval_prepared_non_select(plugin->dbh, | 302 | res = GNUNET_PQ_eval_prepared_non_select (plugin->dbh, |
299 | "store_records", | 303 | "store_records", |
300 | params); | 304 | params); |
301 | if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != res) | 305 | if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != res) |
302 | return GNUNET_SYSERR; | 306 | return GNUNET_SYSERR; |
303 | } | 307 | } |
@@ -308,7 +312,8 @@ namestore_postgres_store_records(void *cls, | |||
308 | /** | 312 | /** |
309 | * Closure for #parse_result_call_iterator. | 313 | * Closure for #parse_result_call_iterator. |
310 | */ | 314 | */ |
311 | struct ParserContext { | 315 | struct ParserContext |
316 | { | ||
312 | /** | 317 | /** |
313 | * Function to call for each result. | 318 | * Function to call for each result. |
314 | */ | 319 | */ |
@@ -341,81 +346,81 @@ struct ParserContext { | |||
341 | * @param num_result the number of results in @a result | 346 | * @param num_result the number of results in @a result |
342 | */ | 347 | */ |
343 | static void | 348 | static void |
344 | parse_result_call_iterator(void *cls, | 349 | parse_result_call_iterator (void *cls, |
345 | PGresult *res, | 350 | PGresult *res, |
346 | unsigned int num_results) | 351 | unsigned int num_results) |
347 | { | 352 | { |
348 | struct ParserContext *pc = cls; | 353 | struct ParserContext *pc = cls; |
349 | 354 | ||
350 | if (NULL == pc->iter) | 355 | if (NULL == pc->iter) |
351 | return; /* no need to do more work */ | 356 | return; /* no need to do more work */ |
352 | for (unsigned int i = 0; i < num_results; i++) | 357 | for (unsigned int i = 0; i < num_results; i++) |
358 | { | ||
359 | uint64_t serial; | ||
360 | void *data; | ||
361 | size_t data_size; | ||
362 | uint32_t record_count; | ||
363 | char *label; | ||
364 | struct GNUNET_CRYPTO_EcdsaPrivateKey zk; | ||
365 | struct GNUNET_PQ_ResultSpec rs_with_zone[] = { | ||
366 | GNUNET_PQ_result_spec_uint64 ("seq", &serial), | ||
367 | GNUNET_PQ_result_spec_uint32 ("record_count", &record_count), | ||
368 | GNUNET_PQ_result_spec_variable_size ("record_data", &data, &data_size), | ||
369 | GNUNET_PQ_result_spec_string ("label", &label), | ||
370 | GNUNET_PQ_result_spec_auto_from_type ("zone_private_key", &zk), | ||
371 | GNUNET_PQ_result_spec_end | ||
372 | }; | ||
373 | struct GNUNET_PQ_ResultSpec rs_without_zone[] = { | ||
374 | GNUNET_PQ_result_spec_uint64 ("seq", &serial), | ||
375 | GNUNET_PQ_result_spec_uint32 ("record_count", &record_count), | ||
376 | GNUNET_PQ_result_spec_variable_size ("record_data", &data, &data_size), | ||
377 | GNUNET_PQ_result_spec_string ("label", &label), | ||
378 | GNUNET_PQ_result_spec_end | ||
379 | }; | ||
380 | struct GNUNET_PQ_ResultSpec *rs; | ||
381 | |||
382 | rs = (NULL == pc->zone_key) ? rs_with_zone : rs_without_zone; | ||
383 | if (GNUNET_YES != | ||
384 | GNUNET_PQ_extract_result (res, | ||
385 | rs, | ||
386 | i)) | ||
353 | { | 387 | { |
354 | uint64_t serial; | 388 | GNUNET_break (0); |
355 | void *data; | 389 | return; |
356 | size_t data_size; | 390 | } |
357 | uint32_t record_count; | ||
358 | char *label; | ||
359 | struct GNUNET_CRYPTO_EcdsaPrivateKey zk; | ||
360 | struct GNUNET_PQ_ResultSpec rs_with_zone[] = { | ||
361 | GNUNET_PQ_result_spec_uint64("seq", &serial), | ||
362 | GNUNET_PQ_result_spec_uint32("record_count", &record_count), | ||
363 | GNUNET_PQ_result_spec_variable_size("record_data", &data, &data_size), | ||
364 | GNUNET_PQ_result_spec_string("label", &label), | ||
365 | GNUNET_PQ_result_spec_auto_from_type("zone_private_key", &zk), | ||
366 | GNUNET_PQ_result_spec_end | ||
367 | }; | ||
368 | struct GNUNET_PQ_ResultSpec rs_without_zone[] = { | ||
369 | GNUNET_PQ_result_spec_uint64("seq", &serial), | ||
370 | GNUNET_PQ_result_spec_uint32("record_count", &record_count), | ||
371 | GNUNET_PQ_result_spec_variable_size("record_data", &data, &data_size), | ||
372 | GNUNET_PQ_result_spec_string("label", &label), | ||
373 | GNUNET_PQ_result_spec_end | ||
374 | }; | ||
375 | struct GNUNET_PQ_ResultSpec *rs; | ||
376 | |||
377 | rs = (NULL == pc->zone_key) ? rs_with_zone : rs_without_zone; | ||
378 | if (GNUNET_YES != | ||
379 | GNUNET_PQ_extract_result(res, | ||
380 | rs, | ||
381 | i)) | ||
382 | { | ||
383 | GNUNET_break(0); | ||
384 | return; | ||
385 | } | ||
386 | |||
387 | if (record_count > 64 * 1024) | ||
388 | { | ||
389 | /* sanity check, don't stack allocate far too much just | ||
390 | because database might contain a large value here */ | ||
391 | GNUNET_break(0); | ||
392 | GNUNET_PQ_cleanup_result(rs); | ||
393 | return; | ||
394 | } | ||
395 | 391 | ||
392 | if (record_count > 64 * 1024) | ||
393 | { | ||
394 | /* sanity check, don't stack allocate far too much just | ||
395 | because database might contain a large value here */ | ||
396 | GNUNET_break (0); | ||
397 | GNUNET_PQ_cleanup_result (rs); | ||
398 | return; | ||
399 | } | ||
400 | |||
401 | { | ||
402 | struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL (record_count)]; | ||
403 | |||
404 | GNUNET_assert (0 != serial); | ||
405 | if (GNUNET_OK != | ||
406 | GNUNET_GNSRECORD_records_deserialize (data_size, | ||
407 | data, | ||
408 | record_count, | ||
409 | rd)) | ||
396 | { | 410 | { |
397 | struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(record_count)]; | 411 | GNUNET_break (0); |
398 | 412 | GNUNET_PQ_cleanup_result (rs); | |
399 | GNUNET_assert(0 != serial); | 413 | return; |
400 | if (GNUNET_OK != | ||
401 | GNUNET_GNSRECORD_records_deserialize(data_size, | ||
402 | data, | ||
403 | record_count, | ||
404 | rd)) | ||
405 | { | ||
406 | GNUNET_break(0); | ||
407 | GNUNET_PQ_cleanup_result(rs); | ||
408 | return; | ||
409 | } | ||
410 | pc->iter(pc->iter_cls, | ||
411 | serial, | ||
412 | (NULL == pc->zone_key) ? &zk : pc->zone_key, | ||
413 | label, | ||
414 | record_count, | ||
415 | rd); | ||
416 | } | 414 | } |
417 | GNUNET_PQ_cleanup_result(rs); | 415 | pc->iter (pc->iter_cls, |
416 | serial, | ||
417 | (NULL == pc->zone_key) ? &zk : pc->zone_key, | ||
418 | label, | ||
419 | record_count, | ||
420 | rd); | ||
418 | } | 421 | } |
422 | GNUNET_PQ_cleanup_result (rs); | ||
423 | } | ||
419 | pc->limit -= num_results; | 424 | pc->limit -= num_results; |
420 | } | 425 | } |
421 | 426 | ||
@@ -431,34 +436,35 @@ parse_result_call_iterator(void *cls, | |||
431 | * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR | 436 | * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR |
432 | */ | 437 | */ |
433 | static int | 438 | static int |
434 | namestore_postgres_lookup_records(void *cls, | 439 | namestore_postgres_lookup_records (void *cls, |
435 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 440 | const struct |
436 | const char *label, | 441 | GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
437 | GNUNET_NAMESTORE_RecordIterator iter, | 442 | const char *label, |
438 | void *iter_cls) | 443 | GNUNET_NAMESTORE_RecordIterator iter, |
444 | void *iter_cls) | ||
439 | { | 445 | { |
440 | struct Plugin *plugin = cls; | 446 | struct Plugin *plugin = cls; |
441 | struct GNUNET_PQ_QueryParam params[] = { | 447 | struct GNUNET_PQ_QueryParam params[] = { |
442 | GNUNET_PQ_query_param_auto_from_type(zone), | 448 | GNUNET_PQ_query_param_auto_from_type (zone), |
443 | GNUNET_PQ_query_param_string(label), | 449 | GNUNET_PQ_query_param_string (label), |
444 | GNUNET_PQ_query_param_end | 450 | GNUNET_PQ_query_param_end |
445 | }; | 451 | }; |
446 | struct ParserContext pc; | 452 | struct ParserContext pc; |
447 | enum GNUNET_DB_QueryStatus res; | 453 | enum GNUNET_DB_QueryStatus res; |
448 | 454 | ||
449 | if (NULL == zone) | 455 | if (NULL == zone) |
450 | { | 456 | { |
451 | GNUNET_break(0); | 457 | GNUNET_break (0); |
452 | return GNUNET_SYSERR; | 458 | return GNUNET_SYSERR; |
453 | } | 459 | } |
454 | pc.iter = iter; | 460 | pc.iter = iter; |
455 | pc.iter_cls = iter_cls; | 461 | pc.iter_cls = iter_cls; |
456 | pc.zone_key = zone; | 462 | pc.zone_key = zone; |
457 | res = GNUNET_PQ_eval_prepared_multi_select(plugin->dbh, | 463 | res = GNUNET_PQ_eval_prepared_multi_select (plugin->dbh, |
458 | "lookup_label", | 464 | "lookup_label", |
459 | params, | 465 | params, |
460 | &parse_result_call_iterator, | 466 | &parse_result_call_iterator, |
461 | &pc); | 467 | &pc); |
462 | if (res < 0) | 468 | if (res < 0) |
463 | return GNUNET_SYSERR; | 469 | return GNUNET_SYSERR; |
464 | if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == res) | 470 | if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == res) |
@@ -480,12 +486,13 @@ namestore_postgres_lookup_records(void *cls, | |||
480 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no more results, #GNUNET_SYSERR on error | 486 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no more results, #GNUNET_SYSERR on error |
481 | */ | 487 | */ |
482 | static int | 488 | static int |
483 | namestore_postgres_iterate_records(void *cls, | 489 | namestore_postgres_iterate_records (void *cls, |
484 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 490 | const struct |
485 | uint64_t serial, | 491 | GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
486 | uint64_t limit, | 492 | uint64_t serial, |
487 | GNUNET_NAMESTORE_RecordIterator iter, | 493 | uint64_t limit, |
488 | void *iter_cls) | 494 | GNUNET_NAMESTORE_RecordIterator iter, |
495 | void *iter_cls) | ||
489 | { | 496 | { |
490 | struct Plugin *plugin = cls; | 497 | struct Plugin *plugin = cls; |
491 | enum GNUNET_DB_QueryStatus res; | 498 | enum GNUNET_DB_QueryStatus res; |
@@ -496,34 +503,34 @@ namestore_postgres_iterate_records(void *cls, | |||
496 | pc.zone_key = zone; | 503 | pc.zone_key = zone; |
497 | pc.limit = limit; | 504 | pc.limit = limit; |
498 | if (NULL == zone) | 505 | if (NULL == zone) |
499 | { | 506 | { |
500 | struct GNUNET_PQ_QueryParam params_without_zone[] = { | 507 | struct GNUNET_PQ_QueryParam params_without_zone[] = { |
501 | GNUNET_PQ_query_param_uint64(&serial), | 508 | GNUNET_PQ_query_param_uint64 (&serial), |
502 | GNUNET_PQ_query_param_uint64(&limit), | 509 | GNUNET_PQ_query_param_uint64 (&limit), |
503 | GNUNET_PQ_query_param_end | 510 | GNUNET_PQ_query_param_end |
504 | }; | 511 | }; |
505 | 512 | ||
506 | res = GNUNET_PQ_eval_prepared_multi_select(plugin->dbh, | 513 | res = GNUNET_PQ_eval_prepared_multi_select (plugin->dbh, |
507 | "iterate_all_zones", | 514 | "iterate_all_zones", |
508 | params_without_zone, | 515 | params_without_zone, |
509 | &parse_result_call_iterator, | 516 | &parse_result_call_iterator, |
510 | &pc); | 517 | &pc); |
511 | } | 518 | } |
512 | else | 519 | else |
513 | { | 520 | { |
514 | struct GNUNET_PQ_QueryParam params_with_zone[] = { | 521 | struct GNUNET_PQ_QueryParam params_with_zone[] = { |
515 | GNUNET_PQ_query_param_auto_from_type(zone), | 522 | GNUNET_PQ_query_param_auto_from_type (zone), |
516 | GNUNET_PQ_query_param_uint64(&serial), | 523 | GNUNET_PQ_query_param_uint64 (&serial), |
517 | GNUNET_PQ_query_param_uint64(&limit), | 524 | GNUNET_PQ_query_param_uint64 (&limit), |
518 | GNUNET_PQ_query_param_end | 525 | GNUNET_PQ_query_param_end |
519 | }; | 526 | }; |
520 | 527 | ||
521 | res = GNUNET_PQ_eval_prepared_multi_select(plugin->dbh, | 528 | res = GNUNET_PQ_eval_prepared_multi_select (plugin->dbh, |
522 | "iterate_zone", | 529 | "iterate_zone", |
523 | params_with_zone, | 530 | params_with_zone, |
524 | &parse_result_call_iterator, | 531 | &parse_result_call_iterator, |
525 | &pc); | 532 | &pc); |
526 | } | 533 | } |
527 | if (res < 0) | 534 | if (res < 0) |
528 | return GNUNET_SYSERR; | 535 | return GNUNET_SYSERR; |
529 | 536 | ||
@@ -546,15 +553,18 @@ namestore_postgres_iterate_records(void *cls, | |||
546 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error | 553 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error |
547 | */ | 554 | */ |
548 | static int | 555 | static int |
549 | namestore_postgres_zone_to_name(void *cls, | 556 | namestore_postgres_zone_to_name (void *cls, |
550 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 557 | const struct |
551 | const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone, | 558 | GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
552 | GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) | 559 | const struct |
560 | GNUNET_CRYPTO_EcdsaPublicKey *value_zone, | ||
561 | GNUNET_NAMESTORE_RecordIterator iter, | ||
562 | void *iter_cls) | ||
553 | { | 563 | { |
554 | struct Plugin *plugin = cls; | 564 | struct Plugin *plugin = cls; |
555 | struct GNUNET_PQ_QueryParam params[] = { | 565 | struct GNUNET_PQ_QueryParam params[] = { |
556 | GNUNET_PQ_query_param_auto_from_type(zone), | 566 | GNUNET_PQ_query_param_auto_from_type (zone), |
557 | GNUNET_PQ_query_param_auto_from_type(value_zone), | 567 | GNUNET_PQ_query_param_auto_from_type (value_zone), |
558 | GNUNET_PQ_query_param_end | 568 | GNUNET_PQ_query_param_end |
559 | }; | 569 | }; |
560 | enum GNUNET_DB_QueryStatus res; | 570 | enum GNUNET_DB_QueryStatus res; |
@@ -563,11 +573,11 @@ namestore_postgres_zone_to_name(void *cls, | |||
563 | pc.iter = iter; | 573 | pc.iter = iter; |
564 | pc.iter_cls = iter_cls; | 574 | pc.iter_cls = iter_cls; |
565 | pc.zone_key = zone; | 575 | pc.zone_key = zone; |
566 | res = GNUNET_PQ_eval_prepared_multi_select(plugin->dbh, | 576 | res = GNUNET_PQ_eval_prepared_multi_select (plugin->dbh, |
567 | "zone_to_name", | 577 | "zone_to_name", |
568 | params, | 578 | params, |
569 | &parse_result_call_iterator, | 579 | &parse_result_call_iterator, |
570 | &pc); | 580 | &pc); |
571 | if (res < 0) | 581 | if (res < 0) |
572 | return GNUNET_SYSERR; | 582 | return GNUNET_SYSERR; |
573 | return GNUNET_OK; | 583 | return GNUNET_OK; |
@@ -581,9 +591,9 @@ namestore_postgres_zone_to_name(void *cls, | |||
581 | * @param plugin the plugin context (state for this module) | 591 | * @param plugin the plugin context (state for this module) |
582 | */ | 592 | */ |
583 | static void | 593 | static void |
584 | database_shutdown(struct Plugin *plugin) | 594 | database_shutdown (struct Plugin *plugin) |
585 | { | 595 | { |
586 | PQfinish(plugin->dbh); | 596 | PQfinish (plugin->dbh); |
587 | plugin->dbh = NULL; | 597 | plugin->dbh = NULL; |
588 | } | 598 | } |
589 | 599 | ||
@@ -595,7 +605,7 @@ database_shutdown(struct Plugin *plugin) | |||
595 | * @return NULL on error, othrewise the plugin context | 605 | * @return NULL on error, othrewise the plugin context |
596 | */ | 606 | */ |
597 | void * | 607 | void * |
598 | libgnunet_plugin_namestore_postgres_init(void *cls) | 608 | libgnunet_plugin_namestore_postgres_init (void *cls) |
599 | { | 609 | { |
600 | static struct Plugin plugin; | 610 | static struct Plugin plugin; |
601 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 611 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
@@ -603,21 +613,21 @@ libgnunet_plugin_namestore_postgres_init(void *cls) | |||
603 | 613 | ||
604 | if (NULL != plugin.cfg) | 614 | if (NULL != plugin.cfg) |
605 | return NULL; /* can only initialize once! */ | 615 | return NULL; /* can only initialize once! */ |
606 | memset(&plugin, 0, sizeof(struct Plugin)); | 616 | memset (&plugin, 0, sizeof(struct Plugin)); |
607 | plugin.cfg = cfg; | 617 | plugin.cfg = cfg; |
608 | if (GNUNET_OK != database_setup(&plugin)) | 618 | if (GNUNET_OK != database_setup (&plugin)) |
609 | { | 619 | { |
610 | database_shutdown(&plugin); | 620 | database_shutdown (&plugin); |
611 | return NULL; | 621 | return NULL; |
612 | } | 622 | } |
613 | api = GNUNET_new(struct GNUNET_NAMESTORE_PluginFunctions); | 623 | api = GNUNET_new (struct GNUNET_NAMESTORE_PluginFunctions); |
614 | api->cls = &plugin; | 624 | api->cls = &plugin; |
615 | api->store_records = &namestore_postgres_store_records; | 625 | api->store_records = &namestore_postgres_store_records; |
616 | api->iterate_records = &namestore_postgres_iterate_records; | 626 | api->iterate_records = &namestore_postgres_iterate_records; |
617 | api->zone_to_name = &namestore_postgres_zone_to_name; | 627 | api->zone_to_name = &namestore_postgres_zone_to_name; |
618 | api->lookup_records = &namestore_postgres_lookup_records; | 628 | api->lookup_records = &namestore_postgres_lookup_records; |
619 | LOG(GNUNET_ERROR_TYPE_INFO, | 629 | LOG (GNUNET_ERROR_TYPE_INFO, |
620 | "Postgres namestore plugin running\n"); | 630 | "Postgres namestore plugin running\n"); |
621 | return api; | 631 | return api; |
622 | } | 632 | } |
623 | 633 | ||
@@ -629,16 +639,16 @@ libgnunet_plugin_namestore_postgres_init(void *cls) | |||
629 | * @return always NULL | 639 | * @return always NULL |
630 | */ | 640 | */ |
631 | void * | 641 | void * |
632 | libgnunet_plugin_namestore_postgres_done(void *cls) | 642 | libgnunet_plugin_namestore_postgres_done (void *cls) |
633 | { | 643 | { |
634 | struct GNUNET_NAMESTORE_PluginFunctions *api = cls; | 644 | struct GNUNET_NAMESTORE_PluginFunctions *api = cls; |
635 | struct Plugin *plugin = api->cls; | 645 | struct Plugin *plugin = api->cls; |
636 | 646 | ||
637 | database_shutdown(plugin); | 647 | database_shutdown (plugin); |
638 | plugin->cfg = NULL; | 648 | plugin->cfg = NULL; |
639 | GNUNET_free(api); | 649 | GNUNET_free (api); |
640 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 650 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
641 | "Postgres namestore plugin is finished\n"); | 651 | "Postgres namestore plugin is finished\n"); |
642 | return NULL; | 652 | return NULL; |
643 | } | 653 | } |
644 | 654 | ||
diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c index ba031217d..fbf30567b 100644 --- a/src/namestore/plugin_namestore_sqlite.c +++ b/src/namestore/plugin_namestore_sqlite.c | |||
@@ -50,15 +50,23 @@ | |||
50 | * a failure of the command 'cmd' on file 'filename' | 50 | * a failure of the command 'cmd' on file 'filename' |
51 | * with the message given by strerror(errno). | 51 | * with the message given by strerror(errno). |
52 | */ | 52 | */ |
53 | #define LOG_SQLITE(db, level, cmd) do { GNUNET_log_from(level, "namestore-sqlite", _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db->dbh)); } while (0) | 53 | #define LOG_SQLITE(db, level, cmd) do { GNUNET_log_from (level, \ |
54 | "namestore-sqlite", _ ( \ | ||
55 | "`%s' failed at %s:%d with error: %s\n"), \ | ||
56 | cmd, \ | ||
57 | __FILE__, __LINE__, \ | ||
58 | sqlite3_errmsg ( \ | ||
59 | db->dbh)); \ | ||
60 | } while (0) | ||
54 | 61 | ||
55 | #define LOG(kind, ...) GNUNET_log_from(kind, "namestore-sqlite", __VA_ARGS__) | 62 | #define LOG(kind, ...) GNUNET_log_from (kind, "namestore-sqlite", __VA_ARGS__) |
56 | 63 | ||
57 | 64 | ||
58 | /** | 65 | /** |
59 | * Context for all functions in this plugin. | 66 | * Context for all functions in this plugin. |
60 | */ | 67 | */ |
61 | struct Plugin { | 68 | struct Plugin |
69 | { | ||
62 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 70 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
63 | 71 | ||
64 | /** | 72 | /** |
@@ -112,123 +120,124 @@ struct Plugin { | |||
112 | * @return #GNUNET_OK on success | 120 | * @return #GNUNET_OK on success |
113 | */ | 121 | */ |
114 | static int | 122 | static int |
115 | database_setup(struct Plugin *plugin) | 123 | database_setup (struct Plugin *plugin) |
116 | { | 124 | { |
117 | char *sqlite_filename; | 125 | char *sqlite_filename; |
118 | struct GNUNET_SQ_ExecuteStatement es[] = { | 126 | struct GNUNET_SQ_ExecuteStatement es[] = { |
119 | GNUNET_SQ_make_try_execute("PRAGMA temp_store=MEMORY"), | 127 | GNUNET_SQ_make_try_execute ("PRAGMA temp_store=MEMORY"), |
120 | GNUNET_SQ_make_try_execute("PRAGMA synchronous=NORMAL"), | 128 | GNUNET_SQ_make_try_execute ("PRAGMA synchronous=NORMAL"), |
121 | GNUNET_SQ_make_try_execute("PRAGMA legacy_file_format=OFF"), | 129 | GNUNET_SQ_make_try_execute ("PRAGMA legacy_file_format=OFF"), |
122 | GNUNET_SQ_make_try_execute("PRAGMA auto_vacuum=INCREMENTAL"), | 130 | GNUNET_SQ_make_try_execute ("PRAGMA auto_vacuum=INCREMENTAL"), |
123 | GNUNET_SQ_make_try_execute("PRAGMA encoding=\"UTF-8\""), | 131 | GNUNET_SQ_make_try_execute ("PRAGMA encoding=\"UTF-8\""), |
124 | GNUNET_SQ_make_try_execute("PRAGMA locking_mode=EXCLUSIVE"), | 132 | GNUNET_SQ_make_try_execute ("PRAGMA locking_mode=EXCLUSIVE"), |
125 | GNUNET_SQ_make_try_execute("PRAGMA journal_mode=WAL"), | 133 | GNUNET_SQ_make_try_execute ("PRAGMA journal_mode=WAL"), |
126 | GNUNET_SQ_make_try_execute("PRAGMA page_size=4092"), | 134 | GNUNET_SQ_make_try_execute ("PRAGMA page_size=4092"), |
127 | GNUNET_SQ_make_execute("CREATE TABLE IF NOT EXISTS ns098records (" | 135 | GNUNET_SQ_make_execute ("CREATE TABLE IF NOT EXISTS ns098records (" |
128 | " uid INTEGER PRIMARY KEY," | 136 | " uid INTEGER PRIMARY KEY," |
129 | " zone_private_key BLOB NOT NULL," | 137 | " zone_private_key BLOB NOT NULL," |
130 | " pkey BLOB," | 138 | " pkey BLOB," |
131 | " rvalue INT8 NOT NULL," | 139 | " rvalue INT8 NOT NULL," |
132 | " record_count INT NOT NULL," | 140 | " record_count INT NOT NULL," |
133 | " record_data BLOB NOT NULL," | 141 | " record_data BLOB NOT NULL," |
134 | " label TEXT NOT NULL" | 142 | " label TEXT NOT NULL" |
135 | ")"), | 143 | ")"), |
136 | GNUNET_SQ_make_try_execute("CREATE INDEX IF NOT EXISTS ir_pkey_reverse " | 144 | GNUNET_SQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_reverse " |
137 | "ON ns098records (zone_private_key,pkey)"), | 145 | "ON ns098records (zone_private_key,pkey)"), |
138 | GNUNET_SQ_make_try_execute("CREATE INDEX IF NOT EXISTS ir_pkey_iter " | 146 | GNUNET_SQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_iter " |
139 | "ON ns098records (zone_private_key,uid)"), | 147 | "ON ns098records (zone_private_key,uid)"), |
140 | GNUNET_SQ_EXECUTE_STATEMENT_END | 148 | GNUNET_SQ_EXECUTE_STATEMENT_END |
141 | }; | 149 | }; |
142 | struct GNUNET_SQ_PrepareStatement ps[] = { | 150 | struct GNUNET_SQ_PrepareStatement ps[] = { |
143 | GNUNET_SQ_make_prepare("INSERT INTO ns098records " | 151 | GNUNET_SQ_make_prepare ("INSERT INTO ns098records " |
144 | "(zone_private_key,pkey,rvalue,record_count,record_data,label)" | 152 | "(zone_private_key,pkey,rvalue,record_count,record_data,label)" |
145 | " VALUES (?, ?, ?, ?, ?, ?)", | 153 | " VALUES (?, ?, ?, ?, ?, ?)", |
146 | &plugin->store_records), | 154 | &plugin->store_records), |
147 | GNUNET_SQ_make_prepare("DELETE FROM ns098records " | 155 | GNUNET_SQ_make_prepare ("DELETE FROM ns098records " |
148 | "WHERE zone_private_key=? AND label=?", | 156 | "WHERE zone_private_key=? AND label=?", |
149 | &plugin->delete_records), | 157 | &plugin->delete_records), |
150 | GNUNET_SQ_make_prepare("SELECT uid,record_count,record_data,label" | 158 | GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label" |
151 | " FROM ns098records" | 159 | " FROM ns098records" |
152 | " WHERE zone_private_key=? AND pkey=?", | 160 | " WHERE zone_private_key=? AND pkey=?", |
153 | &plugin->zone_to_name), | 161 | &plugin->zone_to_name), |
154 | GNUNET_SQ_make_prepare("SELECT uid,record_count,record_data,label" | 162 | GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label" |
155 | " FROM ns098records" | 163 | " FROM ns098records" |
156 | " WHERE zone_private_key=? AND uid > ?" | 164 | " WHERE zone_private_key=? AND uid > ?" |
157 | " ORDER BY uid ASC" | 165 | " ORDER BY uid ASC" |
158 | " LIMIT ?", | 166 | " LIMIT ?", |
159 | &plugin->iterate_zone), | 167 | &plugin->iterate_zone), |
160 | GNUNET_SQ_make_prepare("SELECT uid,record_count,record_data,label,zone_private_key" | 168 | GNUNET_SQ_make_prepare ( |
161 | " FROM ns098records" | 169 | "SELECT uid,record_count,record_data,label,zone_private_key" |
162 | " WHERE uid > ?" | 170 | " FROM ns098records" |
163 | " ORDER BY uid ASC" | 171 | " WHERE uid > ?" |
164 | " LIMIT ?", | 172 | " ORDER BY uid ASC" |
165 | &plugin->iterate_all_zones), | 173 | " LIMIT ?", |
166 | GNUNET_SQ_make_prepare("SELECT uid,record_count,record_data,label" | 174 | &plugin->iterate_all_zones), |
167 | " FROM ns098records" | 175 | GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label" |
168 | " WHERE zone_private_key=? AND label=?", | 176 | " FROM ns098records" |
169 | &plugin->lookup_label), | 177 | " WHERE zone_private_key=? AND label=?", |
178 | &plugin->lookup_label), | ||
170 | GNUNET_SQ_PREPARE_END | 179 | GNUNET_SQ_PREPARE_END |
171 | }; | 180 | }; |
172 | 181 | ||
173 | if (GNUNET_OK != | 182 | if (GNUNET_OK != |
174 | GNUNET_CONFIGURATION_get_value_filename(plugin->cfg, | 183 | GNUNET_CONFIGURATION_get_value_filename (plugin->cfg, |
175 | "namestore-sqlite", | 184 | "namestore-sqlite", |
176 | "FILENAME", | 185 | "FILENAME", |
177 | &sqlite_filename)) | 186 | &sqlite_filename)) |
178 | { | 187 | { |
179 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, | 188 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
180 | "namestore-sqlite", | 189 | "namestore-sqlite", |
181 | "FILENAME"); | 190 | "FILENAME"); |
182 | return GNUNET_SYSERR; | 191 | return GNUNET_SYSERR; |
183 | } | 192 | } |
184 | if (GNUNET_OK != | 193 | if (GNUNET_OK != |
185 | GNUNET_DISK_file_test(sqlite_filename)) | 194 | GNUNET_DISK_file_test (sqlite_filename)) |
195 | { | ||
196 | if (GNUNET_OK != | ||
197 | GNUNET_DISK_directory_create_for_file (sqlite_filename)) | ||
186 | { | 198 | { |
187 | if (GNUNET_OK != | 199 | GNUNET_break (0); |
188 | GNUNET_DISK_directory_create_for_file(sqlite_filename)) | 200 | GNUNET_free (sqlite_filename); |
189 | { | 201 | return GNUNET_SYSERR; |
190 | GNUNET_break(0); | ||
191 | GNUNET_free(sqlite_filename); | ||
192 | return GNUNET_SYSERR; | ||
193 | } | ||
194 | } | 202 | } |
203 | } | ||
195 | /* sqlite_filename should be UTF-8-encoded. If it isn't, it's a bug */ | 204 | /* sqlite_filename should be UTF-8-encoded. If it isn't, it's a bug */ |
196 | plugin->fn = sqlite_filename; | 205 | plugin->fn = sqlite_filename; |
197 | 206 | ||
198 | /* Open database and precompile statements */ | 207 | /* Open database and precompile statements */ |
199 | if (SQLITE_OK != | 208 | if (SQLITE_OK != |
200 | sqlite3_open(plugin->fn, | 209 | sqlite3_open (plugin->fn, |
201 | &plugin->dbh)) | 210 | &plugin->dbh)) |
202 | { | 211 | { |
203 | LOG(GNUNET_ERROR_TYPE_ERROR, | 212 | LOG (GNUNET_ERROR_TYPE_ERROR, |
204 | _("Unable to initialize SQLite: %s.\n"), | 213 | _ ("Unable to initialize SQLite: %s.\n"), |
205 | sqlite3_errmsg(plugin->dbh)); | 214 | sqlite3_errmsg (plugin->dbh)); |
206 | return GNUNET_SYSERR; | 215 | return GNUNET_SYSERR; |
207 | } | 216 | } |
208 | GNUNET_break(SQLITE_OK == | 217 | GNUNET_break (SQLITE_OK == |
209 | sqlite3_busy_timeout(plugin->dbh, | 218 | sqlite3_busy_timeout (plugin->dbh, |
210 | BUSY_TIMEOUT_MS)); | 219 | BUSY_TIMEOUT_MS)); |
211 | if (GNUNET_OK != | 220 | if (GNUNET_OK != |
212 | GNUNET_SQ_exec_statements(plugin->dbh, | 221 | GNUNET_SQ_exec_statements (plugin->dbh, |
213 | es)) | 222 | es)) |
214 | { | 223 | { |
215 | GNUNET_break(0); | 224 | GNUNET_break (0); |
216 | LOG(GNUNET_ERROR_TYPE_ERROR, | 225 | LOG (GNUNET_ERROR_TYPE_ERROR, |
217 | _("Failed to setup database at `%s'\n"), | 226 | _ ("Failed to setup database at `%s'\n"), |
218 | plugin->fn); | 227 | plugin->fn); |
219 | return GNUNET_SYSERR; | 228 | return GNUNET_SYSERR; |
220 | } | 229 | } |
221 | 230 | ||
222 | if (GNUNET_OK != | 231 | if (GNUNET_OK != |
223 | GNUNET_SQ_prepare(plugin->dbh, | 232 | GNUNET_SQ_prepare (plugin->dbh, |
224 | ps)) | 233 | ps)) |
225 | { | 234 | { |
226 | GNUNET_break(0); | 235 | GNUNET_break (0); |
227 | LOG(GNUNET_ERROR_TYPE_ERROR, | 236 | LOG (GNUNET_ERROR_TYPE_ERROR, |
228 | _("Failed to setup database at `%s'\n"), | 237 | _ ("Failed to setup database at `%s'\n"), |
229 | plugin->fn); | 238 | plugin->fn); |
230 | return GNUNET_SYSERR; | 239 | return GNUNET_SYSERR; |
231 | } | 240 | } |
232 | return GNUNET_OK; | 241 | return GNUNET_OK; |
233 | } | 242 | } |
234 | 243 | ||
@@ -239,54 +248,55 @@ database_setup(struct Plugin *plugin) | |||
239 | * @param plugin the plugin context (state for this module) | 248 | * @param plugin the plugin context (state for this module) |
240 | */ | 249 | */ |
241 | static void | 250 | static void |
242 | database_shutdown(struct Plugin *plugin) | 251 | database_shutdown (struct Plugin *plugin) |
243 | { | 252 | { |
244 | int result; | 253 | int result; |
245 | sqlite3_stmt *stmt; | 254 | sqlite3_stmt *stmt; |
246 | 255 | ||
247 | if (NULL != plugin->store_records) | 256 | if (NULL != plugin->store_records) |
248 | sqlite3_finalize(plugin->store_records); | 257 | sqlite3_finalize (plugin->store_records); |
249 | if (NULL != plugin->delete_records) | 258 | if (NULL != plugin->delete_records) |
250 | sqlite3_finalize(plugin->delete_records); | 259 | sqlite3_finalize (plugin->delete_records); |
251 | if (NULL != plugin->iterate_zone) | 260 | if (NULL != plugin->iterate_zone) |
252 | sqlite3_finalize(plugin->iterate_zone); | 261 | sqlite3_finalize (plugin->iterate_zone); |
253 | if (NULL != plugin->iterate_all_zones) | 262 | if (NULL != plugin->iterate_all_zones) |
254 | sqlite3_finalize(plugin->iterate_all_zones); | 263 | sqlite3_finalize (plugin->iterate_all_zones); |
255 | if (NULL != plugin->zone_to_name) | 264 | if (NULL != plugin->zone_to_name) |
256 | sqlite3_finalize(plugin->zone_to_name); | 265 | sqlite3_finalize (plugin->zone_to_name); |
257 | if (NULL != plugin->lookup_label) | 266 | if (NULL != plugin->lookup_label) |
258 | sqlite3_finalize(plugin->lookup_label); | 267 | sqlite3_finalize (plugin->lookup_label); |
259 | result = sqlite3_close(plugin->dbh); | 268 | result = sqlite3_close (plugin->dbh); |
260 | if (result == SQLITE_BUSY) | 269 | if (result == SQLITE_BUSY) |
270 | { | ||
271 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
272 | _ ( | ||
273 | "Tried to close sqlite without finalizing all prepared statements.\n")); | ||
274 | stmt = sqlite3_next_stmt (plugin->dbh, | ||
275 | NULL); | ||
276 | while (NULL != stmt) | ||
261 | { | 277 | { |
262 | LOG(GNUNET_ERROR_TYPE_WARNING, | 278 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
263 | _("Tried to close sqlite without finalizing all prepared statements.\n")); | 279 | "sqlite", |
264 | stmt = sqlite3_next_stmt(plugin->dbh, | 280 | "Closing statement %p\n", |
265 | NULL); | 281 | stmt); |
266 | while (NULL != stmt) | 282 | result = sqlite3_finalize (stmt); |
267 | { | 283 | if (result != SQLITE_OK) |
268 | GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, | 284 | GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, |
269 | "sqlite", | 285 | "sqlite", |
270 | "Closing statement %p\n", | 286 | "Failed to close statement %p: %d\n", |
271 | stmt); | 287 | stmt, |
272 | result = sqlite3_finalize(stmt); | 288 | result); |
273 | if (result != SQLITE_OK) | 289 | stmt = sqlite3_next_stmt (plugin->dbh, |
274 | GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, | 290 | NULL); |
275 | "sqlite", | ||
276 | "Failed to close statement %p: %d\n", | ||
277 | stmt, | ||
278 | result); | ||
279 | stmt = sqlite3_next_stmt(plugin->dbh, | ||
280 | NULL); | ||
281 | } | ||
282 | result = sqlite3_close(plugin->dbh); | ||
283 | } | 291 | } |
292 | result = sqlite3_close (plugin->dbh); | ||
293 | } | ||
284 | if (SQLITE_OK != result) | 294 | if (SQLITE_OK != result) |
285 | LOG_SQLITE(plugin, | 295 | LOG_SQLITE (plugin, |
286 | GNUNET_ERROR_TYPE_ERROR, | 296 | GNUNET_ERROR_TYPE_ERROR, |
287 | "sqlite3_close"); | 297 | "sqlite3_close"); |
288 | 298 | ||
289 | GNUNET_free_non_null(plugin->fn); | 299 | GNUNET_free_non_null (plugin->fn); |
290 | } | 300 | } |
291 | 301 | ||
292 | 302 | ||
@@ -302,11 +312,12 @@ database_shutdown(struct Plugin *plugin) | |||
302 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | 312 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR |
303 | */ | 313 | */ |
304 | static int | 314 | static int |
305 | namestore_sqlite_store_records(void *cls, | 315 | namestore_sqlite_store_records (void *cls, |
306 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 316 | const struct |
307 | const char *label, | 317 | GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, |
308 | unsigned int rd_count, | 318 | const char *label, |
309 | const struct GNUNET_GNSRECORD_Data *rd) | 319 | unsigned int rd_count, |
320 | const struct GNUNET_GNSRECORD_Data *rd) | ||
310 | { | 321 | { |
311 | struct Plugin *plugin = cls; | 322 | struct Plugin *plugin = cls; |
312 | int n; | 323 | int n; |
@@ -314,122 +325,122 @@ namestore_sqlite_store_records(void *cls, | |||
314 | uint64_t rvalue; | 325 | uint64_t rvalue; |
315 | ssize_t data_size; | 326 | ssize_t data_size; |
316 | 327 | ||
317 | memset(&pkey, | 328 | memset (&pkey, |
318 | 0, | 329 | 0, |
319 | sizeof(pkey)); | 330 | sizeof(pkey)); |
320 | for (unsigned int i = 0; i < rd_count; i++) | 331 | for (unsigned int i = 0; i < rd_count; i++) |
321 | if (GNUNET_GNSRECORD_TYPE_PKEY == rd[i].record_type) | 332 | if (GNUNET_GNSRECORD_TYPE_PKEY == rd[i].record_type) |
322 | { | ||
323 | GNUNET_break(sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) == | ||
324 | rd[i].data_size); | ||
325 | GNUNET_memcpy(&pkey, | ||
326 | rd[i].data, | ||
327 | rd[i].data_size); | ||
328 | break; | ||
329 | } | ||
330 | rvalue = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, | ||
331 | UINT64_MAX); | ||
332 | data_size = GNUNET_GNSRECORD_records_get_size(rd_count, | ||
333 | rd); | ||
334 | if (data_size < 0) | ||
335 | { | 333 | { |
336 | GNUNET_break(0); | 334 | GNUNET_break (sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) == |
337 | return GNUNET_SYSERR; | 335 | rd[i].data_size); |
336 | GNUNET_memcpy (&pkey, | ||
337 | rd[i].data, | ||
338 | rd[i].data_size); | ||
339 | break; | ||
338 | } | 340 | } |
341 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
342 | UINT64_MAX); | ||
343 | data_size = GNUNET_GNSRECORD_records_get_size (rd_count, | ||
344 | rd); | ||
345 | if (data_size < 0) | ||
346 | { | ||
347 | GNUNET_break (0); | ||
348 | return GNUNET_SYSERR; | ||
349 | } | ||
339 | if (data_size > 64 * 65536) | 350 | if (data_size > 64 * 65536) |
340 | { | 351 | { |
341 | GNUNET_break(0); | 352 | GNUNET_break (0); |
342 | return GNUNET_SYSERR; | 353 | return GNUNET_SYSERR; |
343 | } | 354 | } |
344 | { | 355 | { |
345 | /* First delete 'old' records */ | 356 | /* First delete 'old' records */ |
346 | char data[data_size]; | 357 | char data[data_size]; |
347 | struct GNUNET_SQ_QueryParam dparams[] = { | 358 | struct GNUNET_SQ_QueryParam dparams[] = { |
348 | GNUNET_SQ_query_param_auto_from_type(zone_key), | 359 | GNUNET_SQ_query_param_auto_from_type (zone_key), |
349 | GNUNET_SQ_query_param_string(label), | 360 | GNUNET_SQ_query_param_string (label), |
350 | GNUNET_SQ_query_param_end | 361 | GNUNET_SQ_query_param_end |
351 | }; | 362 | }; |
352 | ssize_t ret; | 363 | ssize_t ret; |
353 | 364 | ||
354 | ret = GNUNET_GNSRECORD_records_serialize(rd_count, | 365 | ret = GNUNET_GNSRECORD_records_serialize (rd_count, |
355 | rd, | 366 | rd, |
356 | data_size, | 367 | data_size, |
357 | data); | 368 | data); |
358 | if ((ret < 0) || | 369 | if ((ret < 0) || |
359 | (data_size != ret)) | 370 | (data_size != ret)) |
360 | { | 371 | { |
361 | GNUNET_break(0); | 372 | GNUNET_break (0); |
362 | return GNUNET_SYSERR; | 373 | return GNUNET_SYSERR; |
363 | } | 374 | } |
364 | if (GNUNET_OK != | 375 | if (GNUNET_OK != |
365 | GNUNET_SQ_bind(plugin->delete_records, | 376 | GNUNET_SQ_bind (plugin->delete_records, |
366 | dparams)) | 377 | dparams)) |
367 | { | 378 | { |
368 | LOG_SQLITE(plugin, | 379 | LOG_SQLITE (plugin, |
369 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 380 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
370 | "sqlite3_bind_XXXX"); | 381 | "sqlite3_bind_XXXX"); |
371 | GNUNET_SQ_reset(plugin->dbh, | 382 | GNUNET_SQ_reset (plugin->dbh, |
372 | plugin->delete_records); | 383 | plugin->delete_records); |
373 | return GNUNET_SYSERR; | 384 | return GNUNET_SYSERR; |
374 | } | 385 | } |
375 | n = sqlite3_step(plugin->delete_records); | 386 | n = sqlite3_step (plugin->delete_records); |
376 | GNUNET_SQ_reset(plugin->dbh, | 387 | GNUNET_SQ_reset (plugin->dbh, |
377 | plugin->delete_records); | 388 | plugin->delete_records); |
378 | 389 | ||
379 | if (0 != rd_count) | 390 | if (0 != rd_count) |
380 | { | 391 | { |
381 | uint32_t rd_count32 = (uint32_t)rd_count; | 392 | uint32_t rd_count32 = (uint32_t) rd_count; |
382 | struct GNUNET_SQ_QueryParam sparams[] = { | 393 | struct GNUNET_SQ_QueryParam sparams[] = { |
383 | GNUNET_SQ_query_param_auto_from_type(zone_key), | 394 | GNUNET_SQ_query_param_auto_from_type (zone_key), |
384 | GNUNET_SQ_query_param_auto_from_type(&pkey), | 395 | GNUNET_SQ_query_param_auto_from_type (&pkey), |
385 | GNUNET_SQ_query_param_uint64(&rvalue), | 396 | GNUNET_SQ_query_param_uint64 (&rvalue), |
386 | GNUNET_SQ_query_param_uint32(&rd_count32), | 397 | GNUNET_SQ_query_param_uint32 (&rd_count32), |
387 | GNUNET_SQ_query_param_fixed_size(data, data_size), | 398 | GNUNET_SQ_query_param_fixed_size (data, data_size), |
388 | GNUNET_SQ_query_param_string(label), | 399 | GNUNET_SQ_query_param_string (label), |
389 | GNUNET_SQ_query_param_end | 400 | GNUNET_SQ_query_param_end |
390 | }; | 401 | }; |
391 | 402 | ||
392 | if (GNUNET_OK != | 403 | if (GNUNET_OK != |
393 | GNUNET_SQ_bind(plugin->store_records, | 404 | GNUNET_SQ_bind (plugin->store_records, |
394 | sparams)) | 405 | sparams)) |
395 | { | 406 | { |
396 | LOG_SQLITE(plugin, | 407 | LOG_SQLITE (plugin, |
397 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 408 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
398 | "sqlite3_bind_XXXX"); | 409 | "sqlite3_bind_XXXX"); |
399 | GNUNET_SQ_reset(plugin->dbh, | 410 | GNUNET_SQ_reset (plugin->dbh, |
400 | plugin->store_records); | 411 | plugin->store_records); |
401 | return GNUNET_SYSERR; | 412 | return GNUNET_SYSERR; |
402 | } | ||
403 | n = sqlite3_step(plugin->store_records); | ||
404 | GNUNET_SQ_reset(plugin->dbh, | ||
405 | plugin->store_records); | ||
406 | } | 413 | } |
414 | n = sqlite3_step (plugin->store_records); | ||
415 | GNUNET_SQ_reset (plugin->dbh, | ||
416 | plugin->store_records); | ||
417 | } | ||
407 | } | 418 | } |
408 | switch (n) | 419 | switch (n) |
409 | { | 420 | { |
410 | case SQLITE_DONE: | 421 | case SQLITE_DONE: |
411 | if (0 != rd_count) | 422 | if (0 != rd_count) |
412 | GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, | 423 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
413 | "sqlite", | 424 | "sqlite", |
414 | "Record stored\n"); | 425 | "Record stored\n"); |
415 | else | 426 | else |
416 | GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, | 427 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
417 | "sqlite", | 428 | "sqlite", |
418 | "Record deleted\n"); | 429 | "Record deleted\n"); |
419 | return GNUNET_OK; | 430 | return GNUNET_OK; |
420 | 431 | ||
421 | case SQLITE_BUSY: | 432 | case SQLITE_BUSY: |
422 | LOG_SQLITE(plugin, | 433 | LOG_SQLITE (plugin, |
423 | GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | 434 | GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, |
424 | "sqlite3_step"); | 435 | "sqlite3_step"); |
425 | return GNUNET_NO; | 436 | return GNUNET_NO; |
426 | 437 | ||
427 | default: | 438 | default: |
428 | LOG_SQLITE(plugin, | 439 | LOG_SQLITE (plugin, |
429 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 440 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
430 | "sqlite3_step"); | 441 | "sqlite3_step"); |
431 | return GNUNET_SYSERR; | 442 | return GNUNET_SYSERR; |
432 | } | 443 | } |
433 | } | 444 | } |
434 | 445 | ||
435 | 446 | ||
@@ -447,108 +458,109 @@ namestore_sqlite_store_records(void *cls, | |||
447 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error | 458 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error |
448 | */ | 459 | */ |
449 | static int | 460 | static int |
450 | get_records_and_call_iterator(struct Plugin *plugin, | 461 | get_records_and_call_iterator (struct Plugin *plugin, |
451 | sqlite3_stmt *stmt, | 462 | sqlite3_stmt *stmt, |
452 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 463 | const struct |
453 | uint64_t limit, | 464 | GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, |
454 | GNUNET_NAMESTORE_RecordIterator iter, | 465 | uint64_t limit, |
455 | void *iter_cls) | 466 | GNUNET_NAMESTORE_RecordIterator iter, |
467 | void *iter_cls) | ||
456 | { | 468 | { |
457 | int ret; | 469 | int ret; |
458 | int sret; | 470 | int sret; |
459 | 471 | ||
460 | ret = GNUNET_OK; | 472 | ret = GNUNET_OK; |
461 | for (uint64_t i = 0; i < limit; i++) | 473 | for (uint64_t i = 0; i < limit; i++) |
474 | { | ||
475 | sret = sqlite3_step (stmt); | ||
476 | |||
477 | if (SQLITE_DONE == sret) | ||
462 | { | 478 | { |
463 | sret = sqlite3_step(stmt); | 479 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
480 | "Iteration done (no results)\n"); | ||
481 | ret = GNUNET_NO; | ||
482 | break; | ||
483 | } | ||
484 | if (SQLITE_ROW != sret) | ||
485 | { | ||
486 | LOG_SQLITE (plugin, | ||
487 | GNUNET_ERROR_TYPE_ERROR, | ||
488 | "sqlite_step"); | ||
489 | ret = GNUNET_SYSERR; | ||
490 | break; | ||
491 | } | ||
464 | 492 | ||
465 | if (SQLITE_DONE == sret) | 493 | { |
466 | { | 494 | uint64_t seq; |
467 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 495 | uint32_t record_count; |
468 | "Iteration done (no results)\n"); | 496 | size_t data_size; |
469 | ret = GNUNET_NO; | 497 | void *data; |
470 | break; | 498 | char *label; |
471 | } | 499 | struct GNUNET_CRYPTO_EcdsaPrivateKey zk; |
472 | if (SQLITE_ROW != sret) | 500 | struct GNUNET_SQ_ResultSpec rs[] = { |
501 | GNUNET_SQ_result_spec_uint64 (&seq), | ||
502 | GNUNET_SQ_result_spec_uint32 (&record_count), | ||
503 | GNUNET_SQ_result_spec_variable_size (&data, | ||
504 | &data_size), | ||
505 | GNUNET_SQ_result_spec_string (&label), | ||
506 | GNUNET_SQ_result_spec_end | ||
507 | }; | ||
508 | struct GNUNET_SQ_ResultSpec rsx[] = { | ||
509 | GNUNET_SQ_result_spec_uint64 (&seq), | ||
510 | GNUNET_SQ_result_spec_uint32 (&record_count), | ||
511 | GNUNET_SQ_result_spec_variable_size (&data, | ||
512 | &data_size), | ||
513 | GNUNET_SQ_result_spec_string (&label), | ||
514 | GNUNET_SQ_result_spec_auto_from_type (&zk), | ||
515 | GNUNET_SQ_result_spec_end | ||
516 | }; | ||
517 | |||
518 | ret = GNUNET_SQ_extract_result (stmt, | ||
519 | (NULL == zone_key) | ||
520 | ? rsx | ||
521 | : rs); | ||
522 | if ((GNUNET_OK != ret) || | ||
523 | (record_count > 64 * 1024)) | ||
524 | { | ||
525 | /* sanity check, don't stack allocate far too much just | ||
526 | because database might contain a large value here */ | ||
527 | GNUNET_break (0); | ||
528 | ret = GNUNET_SYSERR; | ||
529 | break; | ||
530 | } | ||
531 | else | ||
532 | { | ||
533 | struct GNUNET_GNSRECORD_Data rd[record_count]; | ||
534 | |||
535 | GNUNET_assert (0 != seq); | ||
536 | if (GNUNET_OK != | ||
537 | GNUNET_GNSRECORD_records_deserialize (data_size, | ||
538 | data, | ||
539 | record_count, | ||
540 | rd)) | ||
473 | { | 541 | { |
474 | LOG_SQLITE(plugin, | 542 | GNUNET_break (0); |
475 | GNUNET_ERROR_TYPE_ERROR, | ||
476 | "sqlite_step"); | ||
477 | ret = GNUNET_SYSERR; | 543 | ret = GNUNET_SYSERR; |
478 | break; | 544 | break; |
479 | } | 545 | } |
480 | |||
481 | { | ||
482 | uint64_t seq; | ||
483 | uint32_t record_count; | ||
484 | size_t data_size; | ||
485 | void *data; | ||
486 | char *label; | ||
487 | struct GNUNET_CRYPTO_EcdsaPrivateKey zk; | ||
488 | struct GNUNET_SQ_ResultSpec rs[] = { | ||
489 | GNUNET_SQ_result_spec_uint64(&seq), | ||
490 | GNUNET_SQ_result_spec_uint32(&record_count), | ||
491 | GNUNET_SQ_result_spec_variable_size(&data, | ||
492 | &data_size), | ||
493 | GNUNET_SQ_result_spec_string(&label), | ||
494 | GNUNET_SQ_result_spec_end | ||
495 | }; | ||
496 | struct GNUNET_SQ_ResultSpec rsx[] = { | ||
497 | GNUNET_SQ_result_spec_uint64(&seq), | ||
498 | GNUNET_SQ_result_spec_uint32(&record_count), | ||
499 | GNUNET_SQ_result_spec_variable_size(&data, | ||
500 | &data_size), | ||
501 | GNUNET_SQ_result_spec_string(&label), | ||
502 | GNUNET_SQ_result_spec_auto_from_type(&zk), | ||
503 | GNUNET_SQ_result_spec_end | ||
504 | }; | ||
505 | |||
506 | ret = GNUNET_SQ_extract_result(stmt, | ||
507 | (NULL == zone_key) | ||
508 | ? rsx | ||
509 | : rs); | ||
510 | if ((GNUNET_OK != ret) || | ||
511 | (record_count > 64 * 1024)) | ||
512 | { | ||
513 | /* sanity check, don't stack allocate far too much just | ||
514 | because database might contain a large value here */ | ||
515 | GNUNET_break(0); | ||
516 | ret = GNUNET_SYSERR; | ||
517 | break; | ||
518 | } | ||
519 | else | 546 | else |
520 | { | 547 | { |
521 | struct GNUNET_GNSRECORD_Data rd[record_count]; | 548 | if (NULL != zone_key) |
522 | 549 | zk = *zone_key; | |
523 | GNUNET_assert(0 != seq); | 550 | if (NULL != iter) |
524 | if (GNUNET_OK != | 551 | iter (iter_cls, |
525 | GNUNET_GNSRECORD_records_deserialize(data_size, | 552 | seq, |
526 | data, | 553 | &zk, |
527 | record_count, | 554 | label, |
528 | rd)) | 555 | record_count, |
529 | { | 556 | rd); |
530 | GNUNET_break(0); | 557 | } |
531 | ret = GNUNET_SYSERR; | ||
532 | break; | ||
533 | } | ||
534 | else | ||
535 | { | ||
536 | if (NULL != zone_key) | ||
537 | zk = *zone_key; | ||
538 | if (NULL != iter) | ||
539 | iter(iter_cls, | ||
540 | seq, | ||
541 | &zk, | ||
542 | label, | ||
543 | record_count, | ||
544 | rd); | ||
545 | } | ||
546 | } | ||
547 | GNUNET_SQ_cleanup_result(rs); | ||
548 | } | 558 | } |
559 | GNUNET_SQ_cleanup_result (rs); | ||
549 | } | 560 | } |
550 | GNUNET_SQ_reset(plugin->dbh, | 561 | } |
551 | stmt); | 562 | GNUNET_SQ_reset (plugin->dbh, |
563 | stmt); | ||
552 | return ret; | 564 | return ret; |
553 | } | 565 | } |
554 | 566 | ||
@@ -564,40 +576,41 @@ get_records_and_call_iterator(struct Plugin *plugin, | |||
564 | * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR | 576 | * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR |
565 | */ | 577 | */ |
566 | static int | 578 | static int |
567 | namestore_sqlite_lookup_records(void *cls, | 579 | namestore_sqlite_lookup_records (void *cls, |
568 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 580 | const struct |
569 | const char *label, | 581 | GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
570 | GNUNET_NAMESTORE_RecordIterator iter, | 582 | const char *label, |
571 | void *iter_cls) | 583 | GNUNET_NAMESTORE_RecordIterator iter, |
584 | void *iter_cls) | ||
572 | { | 585 | { |
573 | struct Plugin *plugin = cls; | 586 | struct Plugin *plugin = cls; |
574 | struct GNUNET_SQ_QueryParam params[] = { | 587 | struct GNUNET_SQ_QueryParam params[] = { |
575 | GNUNET_SQ_query_param_auto_from_type(zone), | 588 | GNUNET_SQ_query_param_auto_from_type (zone), |
576 | GNUNET_SQ_query_param_string(label), | 589 | GNUNET_SQ_query_param_string (label), |
577 | GNUNET_SQ_query_param_end | 590 | GNUNET_SQ_query_param_end |
578 | }; | 591 | }; |
579 | 592 | ||
580 | if (NULL == zone) | 593 | if (NULL == zone) |
581 | { | 594 | { |
582 | GNUNET_break(0); | 595 | GNUNET_break (0); |
583 | return GNUNET_SYSERR; | 596 | return GNUNET_SYSERR; |
584 | } | 597 | } |
585 | if (GNUNET_OK != | 598 | if (GNUNET_OK != |
586 | GNUNET_SQ_bind(plugin->lookup_label, | 599 | GNUNET_SQ_bind (plugin->lookup_label, |
587 | params)) | 600 | params)) |
588 | { | 601 | { |
589 | LOG_SQLITE(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 602 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
590 | "sqlite3_bind_XXXX"); | 603 | "sqlite3_bind_XXXX"); |
591 | GNUNET_SQ_reset(plugin->dbh, | 604 | GNUNET_SQ_reset (plugin->dbh, |
592 | plugin->lookup_label); | 605 | plugin->lookup_label); |
593 | return GNUNET_SYSERR; | 606 | return GNUNET_SYSERR; |
594 | } | 607 | } |
595 | return get_records_and_call_iterator(plugin, | 608 | return get_records_and_call_iterator (plugin, |
596 | plugin->lookup_label, | 609 | plugin->lookup_label, |
597 | zone, | 610 | zone, |
598 | 1, | 611 | 1, |
599 | iter, | 612 | iter, |
600 | iter_cls); | 613 | iter_cls); |
601 | } | 614 | } |
602 | 615 | ||
603 | 616 | ||
@@ -614,57 +627,58 @@ namestore_sqlite_lookup_records(void *cls, | |||
614 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no more results, #GNUNET_SYSERR on error | 627 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no more results, #GNUNET_SYSERR on error |
615 | */ | 628 | */ |
616 | static int | 629 | static int |
617 | namestore_sqlite_iterate_records(void *cls, | 630 | namestore_sqlite_iterate_records (void *cls, |
618 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 631 | const struct |
619 | uint64_t serial, | 632 | GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
620 | uint64_t limit, | 633 | uint64_t serial, |
621 | GNUNET_NAMESTORE_RecordIterator iter, | 634 | uint64_t limit, |
622 | void *iter_cls) | 635 | GNUNET_NAMESTORE_RecordIterator iter, |
636 | void *iter_cls) | ||
623 | { | 637 | { |
624 | struct Plugin *plugin = cls; | 638 | struct Plugin *plugin = cls; |
625 | sqlite3_stmt *stmt; | 639 | sqlite3_stmt *stmt; |
626 | int err; | 640 | int err; |
627 | 641 | ||
628 | if (NULL == zone) | 642 | if (NULL == zone) |
629 | { | 643 | { |
630 | struct GNUNET_SQ_QueryParam params[] = { | 644 | struct GNUNET_SQ_QueryParam params[] = { |
631 | GNUNET_SQ_query_param_uint64(&serial), | 645 | GNUNET_SQ_query_param_uint64 (&serial), |
632 | GNUNET_SQ_query_param_uint64(&limit), | 646 | GNUNET_SQ_query_param_uint64 (&limit), |
633 | GNUNET_SQ_query_param_end | 647 | GNUNET_SQ_query_param_end |
634 | }; | 648 | }; |
635 | 649 | ||
636 | stmt = plugin->iterate_all_zones; | 650 | stmt = plugin->iterate_all_zones; |
637 | err = GNUNET_SQ_bind(stmt, | 651 | err = GNUNET_SQ_bind (stmt, |
638 | params); | 652 | params); |
639 | } | 653 | } |
640 | else | 654 | else |
641 | { | 655 | { |
642 | struct GNUNET_SQ_QueryParam params[] = { | 656 | struct GNUNET_SQ_QueryParam params[] = { |
643 | GNUNET_SQ_query_param_auto_from_type(zone), | 657 | GNUNET_SQ_query_param_auto_from_type (zone), |
644 | GNUNET_SQ_query_param_uint64(&serial), | 658 | GNUNET_SQ_query_param_uint64 (&serial), |
645 | GNUNET_SQ_query_param_uint64(&limit), | 659 | GNUNET_SQ_query_param_uint64 (&limit), |
646 | GNUNET_SQ_query_param_end | 660 | GNUNET_SQ_query_param_end |
647 | }; | 661 | }; |
648 | 662 | ||
649 | stmt = plugin->iterate_zone; | 663 | stmt = plugin->iterate_zone; |
650 | err = GNUNET_SQ_bind(stmt, | 664 | err = GNUNET_SQ_bind (stmt, |
651 | params); | 665 | params); |
652 | } | 666 | } |
653 | if (GNUNET_OK != err) | 667 | if (GNUNET_OK != err) |
654 | { | 668 | { |
655 | LOG_SQLITE(plugin, | 669 | LOG_SQLITE (plugin, |
656 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 670 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
657 | "sqlite3_bind_XXXX"); | 671 | "sqlite3_bind_XXXX"); |
658 | GNUNET_SQ_reset(plugin->dbh, | 672 | GNUNET_SQ_reset (plugin->dbh, |
659 | stmt); | 673 | stmt); |
660 | return GNUNET_SYSERR; | 674 | return GNUNET_SYSERR; |
661 | } | 675 | } |
662 | return get_records_and_call_iterator(plugin, | 676 | return get_records_and_call_iterator (plugin, |
663 | stmt, | 677 | stmt, |
664 | zone, | 678 | zone, |
665 | limit, | 679 | limit, |
666 | iter, | 680 | iter, |
667 | iter_cls); | 681 | iter_cls); |
668 | } | 682 | } |
669 | 683 | ||
670 | 684 | ||
@@ -680,39 +694,40 @@ namestore_sqlite_iterate_records(void *cls, | |||
680 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error | 694 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error |
681 | */ | 695 | */ |
682 | static int | 696 | static int |
683 | namestore_sqlite_zone_to_name(void *cls, | 697 | namestore_sqlite_zone_to_name (void *cls, |
684 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 698 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
685 | const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone, | 699 | const struct |
686 | GNUNET_NAMESTORE_RecordIterator iter, | 700 | GNUNET_CRYPTO_EcdsaPublicKey *value_zone, |
687 | void *iter_cls) | 701 | GNUNET_NAMESTORE_RecordIterator iter, |
702 | void *iter_cls) | ||
688 | { | 703 | { |
689 | struct Plugin *plugin = cls; | 704 | struct Plugin *plugin = cls; |
690 | struct GNUNET_SQ_QueryParam params[] = { | 705 | struct GNUNET_SQ_QueryParam params[] = { |
691 | GNUNET_SQ_query_param_auto_from_type(zone), | 706 | GNUNET_SQ_query_param_auto_from_type (zone), |
692 | GNUNET_SQ_query_param_auto_from_type(value_zone), | 707 | GNUNET_SQ_query_param_auto_from_type (value_zone), |
693 | GNUNET_SQ_query_param_end | 708 | GNUNET_SQ_query_param_end |
694 | }; | 709 | }; |
695 | 710 | ||
696 | if (GNUNET_OK != | 711 | if (GNUNET_OK != |
697 | GNUNET_SQ_bind(plugin->zone_to_name, | 712 | GNUNET_SQ_bind (plugin->zone_to_name, |
698 | params)) | 713 | params)) |
699 | { | 714 | { |
700 | LOG_SQLITE(plugin, | 715 | LOG_SQLITE (plugin, |
701 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 716 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
702 | "sqlite3_bind_XXXX"); | 717 | "sqlite3_bind_XXXX"); |
703 | GNUNET_SQ_reset(plugin->dbh, | 718 | GNUNET_SQ_reset (plugin->dbh, |
704 | plugin->zone_to_name); | 719 | plugin->zone_to_name); |
705 | return GNUNET_SYSERR; | 720 | return GNUNET_SYSERR; |
706 | } | 721 | } |
707 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 722 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
708 | "Performing reverse lookup for `%s'\n", | 723 | "Performing reverse lookup for `%s'\n", |
709 | GNUNET_GNSRECORD_z2s(value_zone)); | 724 | GNUNET_GNSRECORD_z2s (value_zone)); |
710 | return get_records_and_call_iterator(plugin, | 725 | return get_records_and_call_iterator (plugin, |
711 | plugin->zone_to_name, | 726 | plugin->zone_to_name, |
712 | zone, | 727 | zone, |
713 | 1, | 728 | 1, |
714 | iter, | 729 | iter, |
715 | iter_cls); | 730 | iter_cls); |
716 | } | 731 | } |
717 | 732 | ||
718 | 733 | ||
@@ -723,7 +738,7 @@ namestore_sqlite_zone_to_name(void *cls, | |||
723 | * @return NULL on error, otherwise the plugin context | 738 | * @return NULL on error, otherwise the plugin context |
724 | */ | 739 | */ |
725 | void * | 740 | void * |
726 | libgnunet_plugin_namestore_sqlite_init(void *cls) | 741 | libgnunet_plugin_namestore_sqlite_init (void *cls) |
727 | { | 742 | { |
728 | static struct Plugin plugin; | 743 | static struct Plugin plugin; |
729 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 744 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
@@ -731,23 +746,23 @@ libgnunet_plugin_namestore_sqlite_init(void *cls) | |||
731 | 746 | ||
732 | if (NULL != plugin.cfg) | 747 | if (NULL != plugin.cfg) |
733 | return NULL; /* can only initialize once! */ | 748 | return NULL; /* can only initialize once! */ |
734 | memset(&plugin, | 749 | memset (&plugin, |
735 | 0, | 750 | 0, |
736 | sizeof(struct Plugin)); | 751 | sizeof(struct Plugin)); |
737 | plugin.cfg = cfg; | 752 | plugin.cfg = cfg; |
738 | if (GNUNET_OK != database_setup(&plugin)) | 753 | if (GNUNET_OK != database_setup (&plugin)) |
739 | { | 754 | { |
740 | database_shutdown(&plugin); | 755 | database_shutdown (&plugin); |
741 | return NULL; | 756 | return NULL; |
742 | } | 757 | } |
743 | api = GNUNET_new(struct GNUNET_NAMESTORE_PluginFunctions); | 758 | api = GNUNET_new (struct GNUNET_NAMESTORE_PluginFunctions); |
744 | api->cls = &plugin; | 759 | api->cls = &plugin; |
745 | api->store_records = &namestore_sqlite_store_records; | 760 | api->store_records = &namestore_sqlite_store_records; |
746 | api->iterate_records = &namestore_sqlite_iterate_records; | 761 | api->iterate_records = &namestore_sqlite_iterate_records; |
747 | api->zone_to_name = &namestore_sqlite_zone_to_name; | 762 | api->zone_to_name = &namestore_sqlite_zone_to_name; |
748 | api->lookup_records = &namestore_sqlite_lookup_records; | 763 | api->lookup_records = &namestore_sqlite_lookup_records; |
749 | LOG(GNUNET_ERROR_TYPE_INFO, | 764 | LOG (GNUNET_ERROR_TYPE_INFO, |
750 | _("Sqlite database running\n")); | 765 | _ ("Sqlite database running\n")); |
751 | return api; | 766 | return api; |
752 | } | 767 | } |
753 | 768 | ||
@@ -759,16 +774,16 @@ libgnunet_plugin_namestore_sqlite_init(void *cls) | |||
759 | * @return always NULL | 774 | * @return always NULL |
760 | */ | 775 | */ |
761 | void * | 776 | void * |
762 | libgnunet_plugin_namestore_sqlite_done(void *cls) | 777 | libgnunet_plugin_namestore_sqlite_done (void *cls) |
763 | { | 778 | { |
764 | struct GNUNET_NAMESTORE_PluginFunctions *api = cls; | 779 | struct GNUNET_NAMESTORE_PluginFunctions *api = cls; |
765 | struct Plugin *plugin = api->cls; | 780 | struct Plugin *plugin = api->cls; |
766 | 781 | ||
767 | database_shutdown(plugin); | 782 | database_shutdown (plugin); |
768 | plugin->cfg = NULL; | 783 | plugin->cfg = NULL; |
769 | GNUNET_free(api); | 784 | GNUNET_free (api); |
770 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 785 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
771 | "sqlite plugin is finished\n"); | 786 | "sqlite plugin is finished\n"); |
772 | return NULL; | 787 | return NULL; |
773 | } | 788 | } |
774 | 789 | ||
diff --git a/src/namestore/plugin_rest_namestore.c b/src/namestore/plugin_rest_namestore.c index 42fbf8347..07b3840c5 100644 --- a/src/namestore/plugin_rest_namestore.c +++ b/src/namestore/plugin_rest_namestore.c | |||
@@ -87,14 +87,16 @@ static char *allow_methods; | |||
87 | /** | 87 | /** |
88 | * @brief struct returned by the initialization function of the plugin | 88 | * @brief struct returned by the initialization function of the plugin |
89 | */ | 89 | */ |
90 | struct Plugin { | 90 | struct Plugin |
91 | { | ||
91 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 92 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
92 | }; | 93 | }; |
93 | 94 | ||
94 | /** | 95 | /** |
95 | * The default namestore ego | 96 | * The default namestore ego |
96 | */ | 97 | */ |
97 | struct EgoEntry { | 98 | struct EgoEntry |
99 | { | ||
98 | /** | 100 | /** |
99 | * DLL | 101 | * DLL |
100 | */ | 102 | */ |
@@ -124,7 +126,8 @@ struct EgoEntry { | |||
124 | /** | 126 | /** |
125 | * The request handle | 127 | * The request handle |
126 | */ | 128 | */ |
127 | struct RequestHandle { | 129 | struct RequestHandle |
130 | { | ||
128 | /** | 131 | /** |
129 | * Records to store | 132 | * Records to store |
130 | */ | 133 | */ |
@@ -241,61 +244,61 @@ struct RequestHandle { | |||
241 | * @param handle Handle to clean up | 244 | * @param handle Handle to clean up |
242 | */ | 245 | */ |
243 | static void | 246 | static void |
244 | cleanup_handle(void *cls) | 247 | cleanup_handle (void *cls) |
245 | { | 248 | { |
246 | struct RequestHandle *handle = cls; | 249 | struct RequestHandle *handle = cls; |
247 | struct EgoEntry *ego_entry; | 250 | struct EgoEntry *ego_entry; |
248 | struct EgoEntry *ego_tmp; | 251 | struct EgoEntry *ego_tmp; |
249 | 252 | ||
250 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); | 253 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); |
251 | if (NULL != handle->timeout_task) | 254 | if (NULL != handle->timeout_task) |
252 | { | 255 | { |
253 | GNUNET_SCHEDULER_cancel(handle->timeout_task); | 256 | GNUNET_SCHEDULER_cancel (handle->timeout_task); |
254 | handle->timeout_task = NULL; | 257 | handle->timeout_task = NULL; |
255 | } | 258 | } |
256 | if (NULL != handle->record_name) | 259 | if (NULL != handle->record_name) |
257 | GNUNET_free(handle->record_name); | 260 | GNUNET_free (handle->record_name); |
258 | if (NULL != handle->url) | 261 | if (NULL != handle->url) |
259 | GNUNET_free(handle->url); | 262 | GNUNET_free (handle->url); |
260 | if (NULL != handle->emsg) | 263 | if (NULL != handle->emsg) |
261 | GNUNET_free(handle->emsg); | 264 | GNUNET_free (handle->emsg); |
262 | if (NULL != handle->rd) | 265 | if (NULL != handle->rd) |
266 | { | ||
267 | for (int i = 0; i < handle->rd_count; i++) | ||
263 | { | 268 | { |
264 | for (int i = 0; i < handle->rd_count; i++) | 269 | if (NULL != handle->rd[i].data) |
265 | { | 270 | GNUNET_free ((void *) handle->rd[i].data); |
266 | if (NULL != handle->rd[i].data) | ||
267 | GNUNET_free((void *)handle->rd[i].data); | ||
268 | } | ||
269 | GNUNET_free(handle->rd); | ||
270 | } | 271 | } |
272 | GNUNET_free (handle->rd); | ||
273 | } | ||
271 | if (NULL != handle->timeout_task) | 274 | if (NULL != handle->timeout_task) |
272 | GNUNET_SCHEDULER_cancel(handle->timeout_task); | 275 | GNUNET_SCHEDULER_cancel (handle->timeout_task); |
273 | if (NULL != handle->list_it) | 276 | if (NULL != handle->list_it) |
274 | GNUNET_NAMESTORE_zone_iteration_stop(handle->list_it); | 277 | GNUNET_NAMESTORE_zone_iteration_stop (handle->list_it); |
275 | if (NULL != handle->add_qe) | 278 | if (NULL != handle->add_qe) |
276 | GNUNET_NAMESTORE_cancel(handle->add_qe); | 279 | GNUNET_NAMESTORE_cancel (handle->add_qe); |
277 | if (NULL != handle->identity_handle) | 280 | if (NULL != handle->identity_handle) |
278 | GNUNET_IDENTITY_disconnect(handle->identity_handle); | 281 | GNUNET_IDENTITY_disconnect (handle->identity_handle); |
279 | if (NULL != handle->ns_handle) | 282 | if (NULL != handle->ns_handle) |
280 | { | 283 | { |
281 | GNUNET_NAMESTORE_disconnect(handle->ns_handle); | 284 | GNUNET_NAMESTORE_disconnect (handle->ns_handle); |
282 | } | 285 | } |
283 | 286 | ||
284 | for (ego_entry = handle->ego_head; NULL != ego_entry;) | 287 | for (ego_entry = handle->ego_head; NULL != ego_entry;) |
285 | { | 288 | { |
286 | ego_tmp = ego_entry; | 289 | ego_tmp = ego_entry; |
287 | ego_entry = ego_entry->next; | 290 | ego_entry = ego_entry->next; |
288 | GNUNET_free(ego_tmp->identifier); | 291 | GNUNET_free (ego_tmp->identifier); |
289 | GNUNET_free(ego_tmp->keystring); | 292 | GNUNET_free (ego_tmp->keystring); |
290 | GNUNET_free(ego_tmp); | 293 | GNUNET_free (ego_tmp); |
291 | } | 294 | } |
292 | 295 | ||
293 | if (NULL != handle->resp_object) | 296 | if (NULL != handle->resp_object) |
294 | { | 297 | { |
295 | json_decref(handle->resp_object); | 298 | json_decref (handle->resp_object); |
296 | } | 299 | } |
297 | 300 | ||
298 | GNUNET_free(handle); | 301 | GNUNET_free (handle); |
299 | } | 302 | } |
300 | 303 | ||
301 | 304 | ||
@@ -305,26 +308,26 @@ cleanup_handle(void *cls) | |||
305 | * @param cls the `struct RequestHandle` | 308 | * @param cls the `struct RequestHandle` |
306 | */ | 309 | */ |
307 | static void | 310 | static void |
308 | do_error(void *cls) | 311 | do_error (void *cls) |
309 | { | 312 | { |
310 | struct RequestHandle *handle = cls; | 313 | struct RequestHandle *handle = cls; |
311 | struct MHD_Response *resp; | 314 | struct MHD_Response *resp; |
312 | json_t *json_error = json_object(); | 315 | json_t *json_error = json_object (); |
313 | char *response; | 316 | char *response; |
314 | 317 | ||
315 | if (NULL == handle->emsg) | 318 | if (NULL == handle->emsg) |
316 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_ERROR_UNKNOWN); | 319 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_ERROR_UNKNOWN); |
317 | 320 | ||
318 | json_object_set_new(json_error, "error", json_string(handle->emsg)); | 321 | json_object_set_new (json_error, "error", json_string (handle->emsg)); |
319 | 322 | ||
320 | if (0 == handle->response_code) | 323 | if (0 == handle->response_code) |
321 | handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; | 324 | handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; |
322 | response = json_dumps(json_error, 0); | 325 | response = json_dumps (json_error, 0); |
323 | resp = GNUNET_REST_create_response(response); | 326 | resp = GNUNET_REST_create_response (response); |
324 | handle->proc(handle->proc_cls, resp, handle->response_code); | 327 | handle->proc (handle->proc_cls, resp, handle->response_code); |
325 | json_decref(json_error); | 328 | json_decref (json_error); |
326 | GNUNET_free(response); | 329 | GNUNET_free (response); |
327 | GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); | 330 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); |
328 | } | 331 | } |
329 | 332 | ||
330 | 333 | ||
@@ -338,20 +341,20 @@ do_error(void *cls) | |||
338 | * @return EgoEntry or NULL if not found | 341 | * @return EgoEntry or NULL if not found |
339 | */ | 342 | */ |
340 | struct EgoEntry * | 343 | struct EgoEntry * |
341 | get_egoentry_namestore(struct RequestHandle *handle, char *name) | 344 | get_egoentry_namestore (struct RequestHandle *handle, char *name) |
342 | { | 345 | { |
343 | struct EgoEntry *ego_entry; | 346 | struct EgoEntry *ego_entry; |
344 | 347 | ||
345 | if (NULL != name) | 348 | if (NULL != name) |
349 | { | ||
350 | for (ego_entry = handle->ego_head; NULL != ego_entry; | ||
351 | ego_entry = ego_entry->next) | ||
346 | { | 352 | { |
347 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 353 | if (0 != strcasecmp (name, ego_entry->identifier)) |
348 | ego_entry = ego_entry->next) | 354 | continue; |
349 | { | 355 | return ego_entry; |
350 | if (0 != strcasecmp(name, ego_entry->identifier)) | ||
351 | continue; | ||
352 | return ego_entry; | ||
353 | } | ||
354 | } | 356 | } |
357 | } | ||
355 | return NULL; | 358 | return NULL; |
356 | } | 359 | } |
357 | 360 | ||
@@ -362,12 +365,12 @@ get_egoentry_namestore(struct RequestHandle *handle, char *name) | |||
362 | * @param cls the `struct RequestHandle` | 365 | * @param cls the `struct RequestHandle` |
363 | */ | 366 | */ |
364 | static void | 367 | static void |
365 | namestore_iteration_error(void *cls) | 368 | namestore_iteration_error (void *cls) |
366 | { | 369 | { |
367 | struct RequestHandle *handle = cls; | 370 | struct RequestHandle *handle = cls; |
368 | 371 | ||
369 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); | 372 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); |
370 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 373 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
371 | return; | 374 | return; |
372 | } | 375 | } |
373 | 376 | ||
@@ -380,27 +383,27 @@ namestore_iteration_error(void *cls) | |||
380 | * @param emsg the error message (can be NULL) | 383 | * @param emsg the error message (can be NULL) |
381 | */ | 384 | */ |
382 | static void | 385 | static void |
383 | create_finished(void *cls, int32_t success, const char *emsg) | 386 | create_finished (void *cls, int32_t success, const char *emsg) |
384 | { | 387 | { |
385 | struct RequestHandle *handle = cls; | 388 | struct RequestHandle *handle = cls; |
386 | struct MHD_Response *resp; | 389 | struct MHD_Response *resp; |
387 | 390 | ||
388 | handle->add_qe = NULL; | 391 | handle->add_qe = NULL; |
389 | if (GNUNET_YES != success) | 392 | if (GNUNET_YES != success) |
393 | { | ||
394 | if (NULL != emsg) | ||
390 | { | 395 | { |
391 | if (NULL != emsg) | 396 | handle->emsg = GNUNET_strdup (emsg); |
392 | { | 397 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
393 | handle->emsg = GNUNET_strdup(emsg); | ||
394 | GNUNET_SCHEDULER_add_now(&do_error, handle); | ||
395 | return; | ||
396 | } | ||
397 | handle->emsg = GNUNET_strdup("Error storing records"); | ||
398 | GNUNET_SCHEDULER_add_now(&do_error, handle); | ||
399 | return; | 398 | return; |
400 | } | 399 | } |
401 | resp = GNUNET_REST_create_response(NULL); | 400 | handle->emsg = GNUNET_strdup ("Error storing records"); |
402 | handle->proc(handle->proc_cls, resp, MHD_HTTP_NO_CONTENT); | 401 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
403 | GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); | 402 | return; |
403 | } | ||
404 | resp = GNUNET_REST_create_response (NULL); | ||
405 | handle->proc (handle->proc_cls, resp, MHD_HTTP_NO_CONTENT); | ||
406 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | ||
404 | } | 407 | } |
405 | 408 | ||
406 | 409 | ||
@@ -412,34 +415,34 @@ create_finished(void *cls, int32_t success, const char *emsg) | |||
412 | * @param emsg the error message (can be NULL) | 415 | * @param emsg the error message (can be NULL) |
413 | */ | 416 | */ |
414 | static void | 417 | static void |
415 | del_finished(void *cls, int32_t success, const char *emsg) | 418 | del_finished (void *cls, int32_t success, const char *emsg) |
416 | { | 419 | { |
417 | struct RequestHandle *handle = cls; | 420 | struct RequestHandle *handle = cls; |
418 | 421 | ||
419 | handle->add_qe = NULL; | 422 | handle->add_qe = NULL; |
420 | if (GNUNET_NO == success) | 423 | if (GNUNET_NO == success) |
421 | { | 424 | { |
422 | handle->response_code = MHD_HTTP_NOT_FOUND; | 425 | handle->response_code = MHD_HTTP_NOT_FOUND; |
423 | handle->emsg = GNUNET_strdup("No record found"); | 426 | handle->emsg = GNUNET_strdup ("No record found"); |
424 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 427 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
425 | return; | 428 | return; |
426 | } | 429 | } |
427 | if (GNUNET_SYSERR == success) | 430 | if (GNUNET_SYSERR == success) |
431 | { | ||
432 | if (NULL != emsg) | ||
428 | { | 433 | { |
429 | if (NULL != emsg) | 434 | handle->emsg = GNUNET_strdup (emsg); |
430 | { | 435 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
431 | handle->emsg = GNUNET_strdup(emsg); | ||
432 | GNUNET_SCHEDULER_add_now(&do_error, handle); | ||
433 | return; | ||
434 | } | ||
435 | handle->emsg = GNUNET_strdup("Deleting record failed"); | ||
436 | GNUNET_SCHEDULER_add_now(&do_error, handle); | ||
437 | return; | 436 | return; |
438 | } | 437 | } |
439 | handle->proc(handle->proc_cls, | 438 | handle->emsg = GNUNET_strdup ("Deleting record failed"); |
440 | GNUNET_REST_create_response(NULL), | 439 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
441 | MHD_HTTP_NO_CONTENT); | 440 | return; |
442 | GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); | 441 | } |
442 | handle->proc (handle->proc_cls, | ||
443 | GNUNET_REST_create_response (NULL), | ||
444 | MHD_HTTP_NO_CONTENT); | ||
445 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | ||
443 | } | 446 | } |
444 | 447 | ||
445 | 448 | ||
@@ -450,7 +453,7 @@ del_finished(void *cls, int32_t success, const char *emsg) | |||
450 | * @param cls the `struct RequestHandle` | 453 | * @param cls the `struct RequestHandle` |
451 | */ | 454 | */ |
452 | static void | 455 | static void |
453 | namestore_list_finished(void *cls) | 456 | namestore_list_finished (void *cls) |
454 | { | 457 | { |
455 | struct RequestHandle *handle = cls; | 458 | struct RequestHandle *handle = cls; |
456 | char *result_str; | 459 | char *result_str; |
@@ -459,14 +462,14 @@ namestore_list_finished(void *cls) | |||
459 | handle->list_it = NULL; | 462 | handle->list_it = NULL; |
460 | 463 | ||
461 | if (NULL == handle->resp_object) | 464 | if (NULL == handle->resp_object) |
462 | handle->resp_object = json_array(); | 465 | handle->resp_object = json_array (); |
463 | 466 | ||
464 | result_str = json_dumps(handle->resp_object, 0); | 467 | result_str = json_dumps (handle->resp_object, 0); |
465 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); | 468 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); |
466 | resp = GNUNET_REST_create_response(result_str); | 469 | resp = GNUNET_REST_create_response (result_str); |
467 | handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); | 470 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); |
468 | GNUNET_free_non_null(result_str); | 471 | GNUNET_free_non_null (result_str); |
469 | GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); | 472 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); |
470 | } | 473 | } |
471 | 474 | ||
472 | 475 | ||
@@ -476,22 +479,22 @@ namestore_list_finished(void *cls) | |||
476 | * @param handle the RequestHandle | 479 | * @param handle the RequestHandle |
477 | */ | 480 | */ |
478 | static void | 481 | static void |
479 | namestore_list_iteration(void *cls, | 482 | namestore_list_iteration (void *cls, |
480 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 483 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, |
481 | const char *rname, | 484 | const char *rname, |
482 | unsigned int rd_len, | 485 | unsigned int rd_len, |
483 | const struct GNUNET_GNSRECORD_Data *rd) | 486 | const struct GNUNET_GNSRECORD_Data *rd) |
484 | { | 487 | { |
485 | struct RequestHandle *handle = cls; | 488 | struct RequestHandle *handle = cls; |
486 | json_t *record_obj; | 489 | json_t *record_obj; |
487 | 490 | ||
488 | if (NULL == handle->resp_object) | 491 | if (NULL == handle->resp_object) |
489 | handle->resp_object = json_array(); | 492 | handle->resp_object = json_array (); |
490 | record_obj = GNUNET_JSON_from_gnsrecord(rname, | 493 | record_obj = GNUNET_JSON_from_gnsrecord (rname, |
491 | rd, | 494 | rd, |
492 | rd_len); | 495 | rd_len); |
493 | json_array_append_new(handle->resp_object, record_obj); | 496 | json_array_append_new (handle->resp_object, record_obj); |
494 | GNUNET_NAMESTORE_zone_iterator_next(handle->list_it, 1); | 497 | GNUNET_NAMESTORE_zone_iterator_next (handle->list_it, 1); |
495 | } | 498 | } |
496 | 499 | ||
497 | 500 | ||
@@ -503,9 +506,9 @@ namestore_list_iteration(void *cls, | |||
503 | * @param cls the RequestHandle | 506 | * @param cls the RequestHandle |
504 | */ | 507 | */ |
505 | void | 508 | void |
506 | namestore_get(struct GNUNET_REST_RequestHandle *con_handle, | 509 | namestore_get (struct GNUNET_REST_RequestHandle *con_handle, |
507 | const char *url, | 510 | const char *url, |
508 | void *cls) | 511 | void *cls) |
509 | { | 512 | { |
510 | struct RequestHandle *handle = cls; | 513 | struct RequestHandle *handle = cls; |
511 | struct EgoEntry *ego_entry; | 514 | struct EgoEntry *ego_entry; |
@@ -515,56 +518,56 @@ namestore_get(struct GNUNET_REST_RequestHandle *con_handle, | |||
515 | ego_entry = NULL; | 518 | ego_entry = NULL; |
516 | 519 | ||
517 | // set zone to name if given | 520 | // set zone to name if given |
518 | if (strlen(GNUNET_REST_API_NS_NAMESTORE) < strlen(handle->url)) | 521 | if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url)) |
522 | { | ||
523 | egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE) + 1]; | ||
524 | ego_entry = get_egoentry_namestore (handle, egoname); | ||
525 | |||
526 | if (NULL == ego_entry) | ||
519 | { | 527 | { |
520 | egoname = &handle->url[strlen(GNUNET_REST_API_NS_NAMESTORE) + 1]; | 528 | handle->response_code = MHD_HTTP_NOT_FOUND; |
521 | ego_entry = get_egoentry_namestore(handle, egoname); | 529 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); |
522 | 530 | GNUNET_SCHEDULER_add_now (&do_error, handle); | |
523 | if (NULL == ego_entry) | 531 | return; |
524 | { | ||
525 | handle->response_code = MHD_HTTP_NOT_FOUND; | ||
526 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); | ||
527 | GNUNET_SCHEDULER_add_now(&do_error, handle); | ||
528 | return; | ||
529 | } | ||
530 | } | 532 | } |
533 | } | ||
531 | if (NULL != ego_entry) | 534 | if (NULL != ego_entry) |
532 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); | 535 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); |
533 | 536 | ||
534 | handle->list_it = | 537 | handle->list_it = |
535 | GNUNET_NAMESTORE_zone_iteration_start(handle->ns_handle, | 538 | GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle, |
536 | handle->zone_pkey, | 539 | handle->zone_pkey, |
537 | &namestore_iteration_error, | 540 | &namestore_iteration_error, |
538 | handle, | 541 | handle, |
539 | &namestore_list_iteration, | 542 | &namestore_list_iteration, |
540 | handle, | 543 | handle, |
541 | &namestore_list_finished, | 544 | &namestore_list_finished, |
542 | handle); | 545 | handle); |
543 | if (NULL == handle->list_it) | 546 | if (NULL == handle->list_it) |
544 | { | 547 | { |
545 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); | 548 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); |
546 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 549 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
547 | return; | 550 | return; |
548 | } | 551 | } |
549 | } | 552 | } |
550 | 553 | ||
551 | 554 | ||
552 | static void | 555 | static void |
553 | ns_lookup_error_cb(void *cls) | 556 | ns_lookup_error_cb (void *cls) |
554 | { | 557 | { |
555 | struct RequestHandle *handle = cls; | 558 | struct RequestHandle *handle = cls; |
556 | 559 | ||
557 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); | 560 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); |
558 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 561 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
559 | } | 562 | } |
560 | 563 | ||
561 | 564 | ||
562 | static void | 565 | static void |
563 | ns_lookup_cb(void *cls, | 566 | ns_lookup_cb (void *cls, |
564 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 567 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
565 | const char *label, | 568 | const char *label, |
566 | unsigned int rd_count, | 569 | unsigned int rd_count, |
567 | const struct GNUNET_GNSRECORD_Data *rd) | 570 | const struct GNUNET_GNSRECORD_Data *rd) |
568 | { | 571 | { |
569 | struct RequestHandle *handle = cls; | 572 | struct RequestHandle *handle = cls; |
570 | struct GNUNET_GNSRECORD_Data rd_new[rd_count + handle->rd_count]; | 573 | struct GNUNET_GNSRECORD_Data rd_new[rd_count + handle->rd_count]; |
@@ -573,19 +576,19 @@ ns_lookup_cb(void *cls, | |||
573 | rd_new[i] = rd[i]; | 576 | rd_new[i] = rd[i]; |
574 | for (int j = 0; j < handle->rd_count; j++) | 577 | for (int j = 0; j < handle->rd_count; j++) |
575 | rd_new[rd_count + j] = handle->rd[j]; | 578 | rd_new[rd_count + j] = handle->rd[j]; |
576 | handle->add_qe = GNUNET_NAMESTORE_records_store(handle->ns_handle, | 579 | handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle, |
577 | handle->zone_pkey, | 580 | handle->zone_pkey, |
578 | handle->record_name, | 581 | handle->record_name, |
579 | rd_count + handle->rd_count, | 582 | rd_count + handle->rd_count, |
580 | rd_new, | 583 | rd_new, |
581 | &create_finished, | 584 | &create_finished, |
582 | handle); | 585 | handle); |
583 | if (NULL == handle->add_qe) | 586 | if (NULL == handle->add_qe) |
584 | { | 587 | { |
585 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); | 588 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); |
586 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 589 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
587 | return; | 590 | return; |
588 | } | 591 | } |
589 | } | 592 | } |
590 | 593 | ||
591 | 594 | ||
@@ -597,9 +600,9 @@ ns_lookup_cb(void *cls, | |||
597 | * @param cls the RequestHandle | 600 | * @param cls the RequestHandle |
598 | */ | 601 | */ |
599 | void | 602 | void |
600 | namestore_add(struct GNUNET_REST_RequestHandle *con_handle, | 603 | namestore_add (struct GNUNET_REST_RequestHandle *con_handle, |
601 | const char *url, | 604 | const char *url, |
602 | void *cls) | 605 | void *cls) |
603 | { | 606 | { |
604 | struct RequestHandle *handle = cls; | 607 | struct RequestHandle *handle = cls; |
605 | struct EgoEntry *ego_entry; | 608 | struct EgoEntry *ego_entry; |
@@ -610,67 +613,69 @@ namestore_add(struct GNUNET_REST_RequestHandle *con_handle, | |||
610 | char term_data[handle->rest_handle->data_size + 1]; | 613 | char term_data[handle->rest_handle->data_size + 1]; |
611 | 614 | ||
612 | if (0 >= handle->rest_handle->data_size) | 615 | if (0 >= handle->rest_handle->data_size) |
613 | { | 616 | { |
614 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DATA); | 617 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_NO_DATA); |
615 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 618 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
616 | return; | 619 | return; |
617 | } | 620 | } |
618 | term_data[handle->rest_handle->data_size] = '\0'; | 621 | term_data[handle->rest_handle->data_size] = '\0'; |
619 | GNUNET_memcpy(term_data, | 622 | GNUNET_memcpy (term_data, |
620 | handle->rest_handle->data, | 623 | handle->rest_handle->data, |
621 | handle->rest_handle->data_size); | 624 | handle->rest_handle->data_size); |
622 | data_js = json_loads(term_data, JSON_DECODE_ANY, &err); | 625 | data_js = json_loads (term_data, JSON_DECODE_ANY, &err); |
623 | struct GNUNET_JSON_Specification gnsspec[] = | 626 | struct GNUNET_JSON_Specification gnsspec[] = |
624 | { GNUNET_JSON_spec_gnsrecord(&handle->rd, &handle->rd_count, &handle->record_name), GNUNET_JSON_spec_end() }; | 627 | { GNUNET_JSON_spec_gnsrecord (&handle->rd, &handle->rd_count, |
625 | if (GNUNET_OK != GNUNET_JSON_parse(data_js, gnsspec, NULL, NULL)) | 628 | &handle->record_name), |
626 | { | 629 | GNUNET_JSON_spec_end () }; |
627 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA); | 630 | if (GNUNET_OK != GNUNET_JSON_parse (data_js, gnsspec, NULL, NULL)) |
628 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 631 | { |
629 | json_decref(data_js); | 632 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_INVALID_DATA); |
630 | return; | 633 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
631 | } | 634 | json_decref (data_js); |
632 | GNUNET_JSON_parse_free(gnsspec); | 635 | return; |
633 | if (0 >= strlen(handle->record_name)) | 636 | } |
634 | { | 637 | GNUNET_JSON_parse_free (gnsspec); |
635 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA); | 638 | if (0 >= strlen (handle->record_name)) |
636 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 639 | { |
637 | json_decref(data_js); | 640 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_INVALID_DATA); |
638 | return; | 641 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
639 | } | 642 | json_decref (data_js); |
640 | json_decref(data_js); | 643 | return; |
644 | } | ||
645 | json_decref (data_js); | ||
641 | 646 | ||
642 | egoname = NULL; | 647 | egoname = NULL; |
643 | ego_entry = NULL; | 648 | ego_entry = NULL; |
644 | 649 | ||
645 | // set zone to name if given | 650 | // set zone to name if given |
646 | if (strlen(GNUNET_REST_API_NS_NAMESTORE) < strlen(handle->url)) | 651 | if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url)) |
652 | { | ||
653 | egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE) + 1]; | ||
654 | ego_entry = get_egoentry_namestore (handle, egoname); | ||
655 | |||
656 | if (NULL == ego_entry) | ||
647 | { | 657 | { |
648 | egoname = &handle->url[strlen(GNUNET_REST_API_NS_NAMESTORE) + 1]; | 658 | handle->response_code = MHD_HTTP_NOT_FOUND; |
649 | ego_entry = get_egoentry_namestore(handle, egoname); | 659 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); |
650 | 660 | GNUNET_SCHEDULER_add_now (&do_error, handle); | |
651 | if (NULL == ego_entry) | 661 | return; |
652 | { | ||
653 | handle->response_code = MHD_HTTP_NOT_FOUND; | ||
654 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); | ||
655 | GNUNET_SCHEDULER_add_now(&do_error, handle); | ||
656 | return; | ||
657 | } | ||
658 | } | 662 | } |
663 | } | ||
659 | if (NULL != ego_entry) | 664 | if (NULL != ego_entry) |
660 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); | 665 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); |
661 | handle->add_qe = GNUNET_NAMESTORE_records_lookup(handle->ns_handle, | 666 | handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle, |
662 | handle->zone_pkey, | 667 | handle->zone_pkey, |
663 | handle->record_name, | 668 | handle->record_name, |
664 | &ns_lookup_error_cb, | 669 | &ns_lookup_error_cb, |
665 | handle, | 670 | handle, |
666 | &ns_lookup_cb, | 671 | &ns_lookup_cb, |
667 | handle); | 672 | handle); |
668 | if (NULL == handle->add_qe) | 673 | if (NULL == handle->add_qe) |
669 | { | 674 | { |
670 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); | 675 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); |
671 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 676 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
672 | return; | 677 | return; |
673 | } | 678 | } |
674 | } | 679 | } |
675 | 680 | ||
676 | 681 | ||
@@ -682,9 +687,9 @@ namestore_add(struct GNUNET_REST_RequestHandle *con_handle, | |||
682 | * @param cls the RequestHandle | 687 | * @param cls the RequestHandle |
683 | */ | 688 | */ |
684 | void | 689 | void |
685 | namestore_delete(struct GNUNET_REST_RequestHandle *con_handle, | 690 | namestore_delete (struct GNUNET_REST_RequestHandle *con_handle, |
686 | const char *url, | 691 | const char *url, |
687 | void *cls) | 692 | void *cls) |
688 | { | 693 | { |
689 | struct RequestHandle *handle = cls; | 694 | struct RequestHandle *handle = cls; |
690 | struct GNUNET_HashCode key; | 695 | struct GNUNET_HashCode key; |
@@ -695,46 +700,46 @@ namestore_delete(struct GNUNET_REST_RequestHandle *con_handle, | |||
695 | ego_entry = NULL; | 700 | ego_entry = NULL; |
696 | 701 | ||
697 | // set zone to name if given | 702 | // set zone to name if given |
698 | if (strlen(GNUNET_REST_API_NS_NAMESTORE) < strlen(handle->url)) | 703 | if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url)) |
704 | { | ||
705 | egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE) + 1]; | ||
706 | ego_entry = get_egoentry_namestore (handle, egoname); | ||
707 | |||
708 | if (NULL == ego_entry) | ||
699 | { | 709 | { |
700 | egoname = &handle->url[strlen(GNUNET_REST_API_NS_NAMESTORE) + 1]; | 710 | handle->response_code = MHD_HTTP_NOT_FOUND; |
701 | ego_entry = get_egoentry_namestore(handle, egoname); | 711 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); |
702 | 712 | GNUNET_SCHEDULER_add_now (&do_error, handle); | |
703 | if (NULL == ego_entry) | 713 | return; |
704 | { | ||
705 | handle->response_code = MHD_HTTP_NOT_FOUND; | ||
706 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); | ||
707 | GNUNET_SCHEDULER_add_now(&do_error, handle); | ||
708 | return; | ||
709 | } | ||
710 | } | 714 | } |
715 | } | ||
711 | if (NULL != ego_entry) | 716 | if (NULL != ego_entry) |
712 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); | 717 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); |
713 | 718 | ||
714 | GNUNET_CRYPTO_hash("record_name", strlen("record_name"), &key); | 719 | GNUNET_CRYPTO_hash ("record_name", strlen ("record_name"), &key); |
715 | if (GNUNET_NO == | 720 | if (GNUNET_NO == |
716 | GNUNET_CONTAINER_multihashmap_contains(con_handle->url_param_map, &key)) | 721 | GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, &key)) |
717 | { | 722 | { |
718 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA); | 723 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_INVALID_DATA); |
719 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 724 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
720 | return; | 725 | return; |
721 | } | 726 | } |
722 | handle->record_name = GNUNET_strdup( | 727 | handle->record_name = GNUNET_strdup ( |
723 | GNUNET_CONTAINER_multihashmap_get(con_handle->url_param_map, &key)); | 728 | GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key)); |
724 | 729 | ||
725 | handle->add_qe = GNUNET_NAMESTORE_records_store(handle->ns_handle, | 730 | handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle, |
726 | handle->zone_pkey, | 731 | handle->zone_pkey, |
727 | handle->record_name, | 732 | handle->record_name, |
728 | 0, | 733 | 0, |
729 | NULL, | 734 | NULL, |
730 | &del_finished, | 735 | &del_finished, |
731 | handle); | 736 | handle); |
732 | if (NULL == handle->add_qe) | 737 | if (NULL == handle->add_qe) |
733 | { | 738 | { |
734 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); | 739 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); |
735 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 740 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
736 | return; | 741 | return; |
737 | } | 742 | } |
738 | } | 743 | } |
739 | 744 | ||
740 | 745 | ||
@@ -746,18 +751,18 @@ namestore_delete(struct GNUNET_REST_RequestHandle *con_handle, | |||
746 | * @param cls the RequestHandle | 751 | * @param cls the RequestHandle |
747 | */ | 752 | */ |
748 | static void | 753 | static void |
749 | options_cont(struct GNUNET_REST_RequestHandle *con_handle, | 754 | options_cont (struct GNUNET_REST_RequestHandle *con_handle, |
750 | const char *url, | 755 | const char *url, |
751 | void *cls) | 756 | void *cls) |
752 | { | 757 | { |
753 | struct MHD_Response *resp; | 758 | struct MHD_Response *resp; |
754 | struct RequestHandle *handle = cls; | 759 | struct RequestHandle *handle = cls; |
755 | 760 | ||
756 | // independent of path return all options | 761 | // independent of path return all options |
757 | resp = GNUNET_REST_create_response(NULL); | 762 | resp = GNUNET_REST_create_response (NULL); |
758 | MHD_add_response_header(resp, "Access-Control-Allow-Methods", allow_methods); | 763 | MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods); |
759 | handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); | 764 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); |
760 | GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); | 765 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); |
761 | return; | 766 | return; |
762 | } | 767 | } |
763 | 768 | ||
@@ -768,7 +773,7 @@ options_cont(struct GNUNET_REST_RequestHandle *con_handle, | |||
768 | * @param handle the request handle | 773 | * @param handle the request handle |
769 | */ | 774 | */ |
770 | static void | 775 | static void |
771 | init_cont(struct RequestHandle *handle) | 776 | init_cont (struct RequestHandle *handle) |
772 | { | 777 | { |
773 | struct GNUNET_REST_RequestHandlerError err; | 778 | struct GNUNET_REST_RequestHandlerError err; |
774 | static const struct GNUNET_REST_RequestHandler handlers[] = | 779 | static const struct GNUNET_REST_RequestHandler handlers[] = |
@@ -779,11 +784,11 @@ init_cont(struct RequestHandle *handle) | |||
779 | GNUNET_REST_HANDLER_END }; | 784 | GNUNET_REST_HANDLER_END }; |
780 | 785 | ||
781 | if (GNUNET_NO == | 786 | if (GNUNET_NO == |
782 | GNUNET_REST_handle_request(handle->rest_handle, handlers, &err, handle)) | 787 | GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle)) |
783 | { | 788 | { |
784 | handle->response_code = err.error_code; | 789 | handle->response_code = err.error_code; |
785 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 790 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
786 | } | 791 | } |
787 | } | 792 | } |
788 | 793 | ||
789 | 794 | ||
@@ -819,32 +824,32 @@ init_cont(struct RequestHandle *handle) | |||
819 | * must thus no longer be used | 824 | * must thus no longer be used |
820 | */ | 825 | */ |
821 | static void | 826 | static void |
822 | id_connect_cb(void *cls, | 827 | id_connect_cb (void *cls, |
823 | struct GNUNET_IDENTITY_Ego *ego, | 828 | struct GNUNET_IDENTITY_Ego *ego, |
824 | void **ctx, | 829 | void **ctx, |
825 | const char *name) | 830 | const char *name) |
826 | { | 831 | { |
827 | struct RequestHandle *handle = cls; | 832 | struct RequestHandle *handle = cls; |
828 | struct EgoEntry *ego_entry; | 833 | struct EgoEntry *ego_entry; |
829 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; | 834 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; |
830 | 835 | ||
831 | if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) | 836 | if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) |
832 | { | 837 | { |
833 | handle->state = ID_REST_STATE_POST_INIT; | 838 | handle->state = ID_REST_STATE_POST_INIT; |
834 | init_cont(handle); | 839 | init_cont (handle); |
835 | return; | 840 | return; |
836 | } | 841 | } |
837 | if (ID_REST_STATE_INIT == handle->state) | 842 | if (ID_REST_STATE_INIT == handle->state) |
838 | { | 843 | { |
839 | ego_entry = GNUNET_new(struct EgoEntry); | 844 | ego_entry = GNUNET_new (struct EgoEntry); |
840 | GNUNET_IDENTITY_ego_get_public_key(ego, &pk); | 845 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); |
841 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string(&pk); | 846 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); |
842 | ego_entry->ego = ego; | 847 | ego_entry->ego = ego; |
843 | GNUNET_asprintf(&ego_entry->identifier, "%s", name); | 848 | GNUNET_asprintf (&ego_entry->identifier, "%s", name); |
844 | GNUNET_CONTAINER_DLL_insert_tail(handle->ego_head, | 849 | GNUNET_CONTAINER_DLL_insert_tail (handle->ego_head, |
845 | handle->ego_tail, | 850 | handle->ego_tail, |
846 | ego_entry); | 851 | ego_entry); |
847 | } | 852 | } |
848 | } | 853 | } |
849 | 854 | ||
850 | 855 | ||
@@ -860,11 +865,11 @@ id_connect_cb(void *cls, | |||
860 | * @return GNUNET_OK if request accepted | 865 | * @return GNUNET_OK if request accepted |
861 | */ | 866 | */ |
862 | static void | 867 | static void |
863 | rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle, | 868 | rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, |
864 | GNUNET_REST_ResultProcessor proc, | 869 | GNUNET_REST_ResultProcessor proc, |
865 | void *proc_cls) | 870 | void *proc_cls) |
866 | { | 871 | { |
867 | struct RequestHandle *handle = GNUNET_new(struct RequestHandle); | 872 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); |
868 | 873 | ||
869 | handle->response_code = 0; | 874 | handle->response_code = 0; |
870 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; | 875 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; |
@@ -873,18 +878,18 @@ rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle, | |||
873 | handle->rest_handle = rest_handle; | 878 | handle->rest_handle = rest_handle; |
874 | handle->zone_pkey = NULL; | 879 | handle->zone_pkey = NULL; |
875 | 880 | ||
876 | handle->url = GNUNET_strdup(rest_handle->url); | 881 | handle->url = GNUNET_strdup (rest_handle->url); |
877 | if (handle->url[strlen(handle->url) - 1] == '/') | 882 | if (handle->url[strlen (handle->url) - 1] == '/') |
878 | handle->url[strlen(handle->url) - 1] = '\0'; | 883 | handle->url[strlen (handle->url) - 1] = '\0'; |
879 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); | 884 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); |
880 | 885 | ||
881 | handle->ns_handle = GNUNET_NAMESTORE_connect(cfg); | 886 | handle->ns_handle = GNUNET_NAMESTORE_connect (cfg); |
882 | handle->identity_handle = | 887 | handle->identity_handle = |
883 | GNUNET_IDENTITY_connect(cfg, &id_connect_cb, handle); | 888 | GNUNET_IDENTITY_connect (cfg, &id_connect_cb, handle); |
884 | handle->timeout_task = | 889 | handle->timeout_task = |
885 | GNUNET_SCHEDULER_add_delayed(handle->timeout, &do_error, handle); | 890 | GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_error, handle); |
886 | 891 | ||
887 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); | 892 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); |
888 | } | 893 | } |
889 | 894 | ||
890 | 895 | ||
@@ -895,7 +900,7 @@ rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle, | |||
895 | * @return NULL on error, otherwise the plugin context | 900 | * @return NULL on error, otherwise the plugin context |
896 | */ | 901 | */ |
897 | void * | 902 | void * |
898 | libgnunet_plugin_rest_namestore_init(void *cls) | 903 | libgnunet_plugin_rest_namestore_init (void *cls) |
899 | { | 904 | { |
900 | static struct Plugin plugin; | 905 | static struct Plugin plugin; |
901 | struct GNUNET_REST_Plugin *api; | 906 | struct GNUNET_REST_Plugin *api; |
@@ -903,21 +908,21 @@ libgnunet_plugin_rest_namestore_init(void *cls) | |||
903 | cfg = cls; | 908 | cfg = cls; |
904 | if (NULL != plugin.cfg) | 909 | if (NULL != plugin.cfg) |
905 | return NULL; /* can only initialize once! */ | 910 | return NULL; /* can only initialize once! */ |
906 | memset(&plugin, 0, sizeof(struct Plugin)); | 911 | memset (&plugin, 0, sizeof(struct Plugin)); |
907 | plugin.cfg = cfg; | 912 | plugin.cfg = cfg; |
908 | api = GNUNET_new(struct GNUNET_REST_Plugin); | 913 | api = GNUNET_new (struct GNUNET_REST_Plugin); |
909 | api->cls = &plugin; | 914 | api->cls = &plugin; |
910 | api->name = GNUNET_REST_API_NS_NAMESTORE; | 915 | api->name = GNUNET_REST_API_NS_NAMESTORE; |
911 | api->process_request = &rest_process_request; | 916 | api->process_request = &rest_process_request; |
912 | GNUNET_asprintf(&allow_methods, | 917 | GNUNET_asprintf (&allow_methods, |
913 | "%s, %s, %s, %s, %s", | 918 | "%s, %s, %s, %s, %s", |
914 | MHD_HTTP_METHOD_GET, | 919 | MHD_HTTP_METHOD_GET, |
915 | MHD_HTTP_METHOD_POST, | 920 | MHD_HTTP_METHOD_POST, |
916 | MHD_HTTP_METHOD_PUT, | 921 | MHD_HTTP_METHOD_PUT, |
917 | MHD_HTTP_METHOD_DELETE, | 922 | MHD_HTTP_METHOD_DELETE, |
918 | MHD_HTTP_METHOD_OPTIONS); | 923 | MHD_HTTP_METHOD_OPTIONS); |
919 | 924 | ||
920 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, _("Namestore REST API initialized\n")); | 925 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Namestore REST API initialized\n")); |
921 | return api; | 926 | return api; |
922 | } | 927 | } |
923 | 928 | ||
@@ -929,18 +934,17 @@ libgnunet_plugin_rest_namestore_init(void *cls) | |||
929 | * @return always NULL | 934 | * @return always NULL |
930 | */ | 935 | */ |
931 | void * | 936 | void * |
932 | libgnunet_plugin_rest_namestore_done(void *cls) | 937 | libgnunet_plugin_rest_namestore_done (void *cls) |
933 | { | 938 | { |
934 | struct GNUNET_REST_Plugin *api = cls; | 939 | struct GNUNET_REST_Plugin *api = cls; |
935 | struct Plugin *plugin = api->cls; | 940 | struct Plugin *plugin = api->cls; |
936 | 941 | ||
937 | plugin->cfg = NULL; | 942 | plugin->cfg = NULL; |
938 | 943 | ||
939 | GNUNET_free_non_null(allow_methods); | 944 | GNUNET_free_non_null (allow_methods); |
940 | GNUNET_free(api); | 945 | GNUNET_free (api); |
941 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Namestore REST plugin is finished\n"); | 946 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Namestore REST plugin is finished\n"); |
942 | return NULL; | 947 | return NULL; |
943 | } | 948 | } |
944 | 949 | ||
945 | /* end of plugin_rest_namestore.c */ | 950 | /* end of plugin_rest_namestore.c */ |
946 | |||
diff --git a/src/namestore/test_common.c b/src/namestore/test_common.c index d88d1feb9..58afb0a32 100644 --- a/src/namestore/test_common.c +++ b/src/namestore/test_common.c | |||
@@ -26,36 +26,36 @@ | |||
26 | * test if we can load the plugin @a name. | 26 | * test if we can load the plugin @a name. |
27 | */ | 27 | */ |
28 | static int | 28 | static int |
29 | TNC_test_plugin(const char *cfg_name) | 29 | TNC_test_plugin (const char *cfg_name) |
30 | { | 30 | { |
31 | char *database; | 31 | char *database; |
32 | char *db_lib_name; | 32 | char *db_lib_name; |
33 | struct GNUNET_NAMESTORE_PluginFunctions *db; | 33 | struct GNUNET_NAMESTORE_PluginFunctions *db; |
34 | struct GNUNET_CONFIGURATION_Handle *cfg; | 34 | struct GNUNET_CONFIGURATION_Handle *cfg; |
35 | 35 | ||
36 | cfg = GNUNET_CONFIGURATION_create(); | 36 | cfg = GNUNET_CONFIGURATION_create (); |
37 | if (GNUNET_OK != GNUNET_CONFIGURATION_load(cfg, cfg_name)) | 37 | if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfg_name)) |
38 | { | 38 | { |
39 | GNUNET_break(0); | 39 | GNUNET_break (0); |
40 | GNUNET_CONFIGURATION_destroy(cfg); | 40 | GNUNET_CONFIGURATION_destroy (cfg); |
41 | return GNUNET_SYSERR; | 41 | return GNUNET_SYSERR; |
42 | } | 42 | } |
43 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, | 43 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, |
44 | "namestore", | 44 | "namestore", |
45 | "database", | 45 | "database", |
46 | &database)) | 46 | &database)) |
47 | { | 47 | { |
48 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No database backend configured\n"); | 48 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No database backend configured\n"); |
49 | GNUNET_CONFIGURATION_destroy(cfg); | 49 | GNUNET_CONFIGURATION_destroy (cfg); |
50 | return GNUNET_SYSERR; | 50 | return GNUNET_SYSERR; |
51 | } | 51 | } |
52 | GNUNET_asprintf(&db_lib_name, "libgnunet_plugin_namestore_%s", database); | 52 | GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_namestore_%s", database); |
53 | GNUNET_free(database); | 53 | GNUNET_free (database); |
54 | db = GNUNET_PLUGIN_load(db_lib_name, (void *)cfg); | 54 | db = GNUNET_PLUGIN_load (db_lib_name, (void *) cfg); |
55 | if (NULL != db) | 55 | if (NULL != db) |
56 | GNUNET_break(NULL == GNUNET_PLUGIN_unload(db_lib_name, db)); | 56 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, db)); |
57 | GNUNET_free(db_lib_name); | 57 | GNUNET_free (db_lib_name); |
58 | GNUNET_CONFIGURATION_destroy(cfg); | 58 | GNUNET_CONFIGURATION_destroy (cfg); |
59 | if (NULL == db) | 59 | if (NULL == db) |
60 | return GNUNET_NO; | 60 | return GNUNET_NO; |
61 | return GNUNET_YES; | 61 | return GNUNET_YES; |
@@ -68,13 +68,13 @@ TNC_test_plugin(const char *cfg_name) | |||
68 | */ | 68 | */ |
69 | #define SETUP_CFG(plugin_name, cfg_name) \ | 69 | #define SETUP_CFG(plugin_name, cfg_name) \ |
70 | do \ | 70 | do \ |
71 | { \ | 71 | { \ |
72 | plugin_name = GNUNET_TESTING_get_testname_from_underscore(argv[0]); \ | 72 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); \ |
73 | GNUNET_asprintf(&cfg_name, "test_namestore_api_%s.conf", plugin_name); \ | 73 | GNUNET_asprintf (&cfg_name, "test_namestore_api_%s.conf", plugin_name); \ |
74 | if (!TNC_test_plugin(cfg_name)) \ | 74 | if (! TNC_test_plugin (cfg_name)) \ |
75 | { \ | 75 | { \ |
76 | GNUNET_free(cfg_name); \ | 76 | GNUNET_free (cfg_name); \ |
77 | return 77; \ | 77 | return 77; \ |
78 | } \ | 78 | } \ |
79 | GNUNET_DISK_purge_cfg_dir(cfg_name, "GNUNET_TEST_HOME"); \ | 79 | GNUNET_DISK_purge_cfg_dir (cfg_name, "GNUNET_TEST_HOME"); \ |
80 | } while (0) | 80 | } while (0) |
diff --git a/src/namestore/test_namestore_api_lookup_nick.c b/src/namestore/test_namestore_api_lookup_nick.c index 130f9bc1e..976e8bc1e 100644 --- a/src/namestore/test_namestore_api_lookup_nick.c +++ b/src/namestore/test_namestore_api_lookup_nick.c | |||
@@ -34,11 +34,11 @@ | |||
34 | 34 | ||
35 | #define TEST_RECORD_DATA 'a' | 35 | #define TEST_RECORD_DATA 'a' |
36 | 36 | ||
37 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) | 37 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
38 | 38 | ||
39 | static struct GNUNET_NAMESTORE_Handle *nsh; | 39 | static struct GNUNET_NAMESTORE_Handle *nsh; |
40 | 40 | ||
41 | static struct GNUNET_SCHEDULER_Task * endbadly_task; | 41 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
42 | 42 | ||
43 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 43 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; |
44 | 44 | ||
@@ -50,25 +50,25 @@ static struct GNUNET_GNSRECORD_Data rd_orig; | |||
50 | 50 | ||
51 | static struct GNUNET_NAMESTORE_QueueEntry *nsqe; | 51 | static struct GNUNET_NAMESTORE_QueueEntry *nsqe; |
52 | 52 | ||
53 | //static const char * name = "dummy.dummy.gnunet"; | 53 | // static const char * name = "dummy.dummy.gnunet"; |
54 | static const char * name = "d"; | 54 | static const char *name = "d"; |
55 | 55 | ||
56 | 56 | ||
57 | static void | 57 | static void |
58 | cleanup() | 58 | cleanup () |
59 | { | 59 | { |
60 | GNUNET_free_non_null((void *)rd_orig.data); | 60 | GNUNET_free_non_null ((void *) rd_orig.data); |
61 | if (NULL != nsh) | 61 | if (NULL != nsh) |
62 | { | 62 | { |
63 | GNUNET_NAMESTORE_disconnect(nsh); | 63 | GNUNET_NAMESTORE_disconnect (nsh); |
64 | nsh = NULL; | 64 | nsh = NULL; |
65 | } | 65 | } |
66 | if (NULL != privkey) | 66 | if (NULL != privkey) |
67 | { | 67 | { |
68 | GNUNET_free(privkey); | 68 | GNUNET_free (privkey); |
69 | privkey = NULL; | 69 | privkey = NULL; |
70 | } | 70 | } |
71 | GNUNET_SCHEDULER_shutdown(); | 71 | GNUNET_SCHEDULER_shutdown (); |
72 | } | 72 | } |
73 | 73 | ||
74 | 74 | ||
@@ -79,254 +79,254 @@ cleanup() | |||
79 | * @param tc scheduler context | 79 | * @param tc scheduler context |
80 | */ | 80 | */ |
81 | static void | 81 | static void |
82 | endbadly(void *cls) | 82 | endbadly (void *cls) |
83 | { | 83 | { |
84 | if (NULL != nsqe) | 84 | if (NULL != nsqe) |
85 | { | 85 | { |
86 | GNUNET_NAMESTORE_cancel(nsqe); | 86 | GNUNET_NAMESTORE_cancel (nsqe); |
87 | nsqe = NULL; | 87 | nsqe = NULL; |
88 | } | 88 | } |
89 | cleanup(); | 89 | cleanup (); |
90 | res = 1; | 90 | res = 1; |
91 | } | 91 | } |
92 | 92 | ||
93 | 93 | ||
94 | static void | 94 | static void |
95 | end(void *cls) | 95 | end (void *cls) |
96 | { | 96 | { |
97 | cleanup(); | 97 | cleanup (); |
98 | res = 0; | 98 | res = 0; |
99 | } | 99 | } |
100 | 100 | ||
101 | 101 | ||
102 | static void | 102 | static void |
103 | lookup_it(void *cls, | 103 | lookup_it (void *cls, |
104 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 104 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
105 | const char *label, | 105 | const char *label, |
106 | unsigned int rd_count, | 106 | unsigned int rd_count, |
107 | const struct GNUNET_GNSRECORD_Data *rd) | 107 | const struct GNUNET_GNSRECORD_Data *rd) |
108 | { | 108 | { |
109 | nsqe = NULL; | 109 | nsqe = NULL; |
110 | int c; | 110 | int c; |
111 | int found_record = GNUNET_NO; | 111 | int found_record = GNUNET_NO; |
112 | int found_nick = GNUNET_NO; | 112 | int found_nick = GNUNET_NO; |
113 | 113 | ||
114 | if (0 != GNUNET_memcmp(privkey, zone)) | 114 | if (0 != GNUNET_memcmp (privkey, zone)) |
115 | { | 115 | { |
116 | GNUNET_break(0); | 116 | GNUNET_break (0); |
117 | GNUNET_SCHEDULER_cancel(endbadly_task); | 117 | GNUNET_SCHEDULER_cancel (endbadly_task); |
118 | endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 118 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
119 | return; | 119 | return; |
120 | } | 120 | } |
121 | 121 | ||
122 | if (NULL == label) | 122 | if (NULL == label) |
123 | { | 123 | { |
124 | GNUNET_break(0); | 124 | GNUNET_break (0); |
125 | GNUNET_SCHEDULER_cancel(endbadly_task); | 125 | GNUNET_SCHEDULER_cancel (endbadly_task); |
126 | endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 126 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
127 | return; | 127 | return; |
128 | } | 128 | } |
129 | 129 | ||
130 | if (0 != strcmp(label, name)) | 130 | if (0 != strcmp (label, name)) |
131 | { | 131 | { |
132 | GNUNET_break(0); | 132 | GNUNET_break (0); |
133 | GNUNET_SCHEDULER_cancel(endbadly_task); | 133 | GNUNET_SCHEDULER_cancel (endbadly_task); |
134 | endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 134 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
135 | return; | 135 | return; |
136 | } | 136 | } |
137 | 137 | ||
138 | if (2 != rd_count) | 138 | if (2 != rd_count) |
139 | { | 139 | { |
140 | GNUNET_break(0); | 140 | GNUNET_break (0); |
141 | GNUNET_SCHEDULER_cancel(endbadly_task); | 141 | GNUNET_SCHEDULER_cancel (endbadly_task); |
142 | endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 142 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
143 | return; | 143 | return; |
144 | } | 144 | } |
145 | 145 | ||
146 | for (c = 0; c < rd_count; c++) | 146 | for (c = 0; c < rd_count; c++) |
147 | { | ||
148 | if (GNUNET_GNSRECORD_TYPE_NICK == rd[c].record_type) | ||
149 | { | ||
150 | if (rd[c].data_size != strlen (TEST_NICK) + 1) | ||
151 | { | ||
152 | GNUNET_break (0); | ||
153 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
154 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
155 | return; | ||
156 | } | ||
157 | if (0 != (rd[c].flags & GNUNET_GNSRECORD_RF_PRIVATE)) | ||
158 | { | ||
159 | GNUNET_break (0); | ||
160 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
161 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
162 | return; | ||
163 | } | ||
164 | if (0 != strcmp (rd[c].data, TEST_NICK)) | ||
165 | { | ||
166 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
167 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
168 | return; | ||
169 | } | ||
170 | found_nick = GNUNET_YES; | ||
171 | } | ||
172 | else | ||
147 | { | 173 | { |
148 | if (GNUNET_GNSRECORD_TYPE_NICK == rd[c].record_type) | 174 | if (rd[c].record_type != TEST_RECORD_TYPE) |
149 | { | 175 | { |
150 | if (rd[c].data_size != strlen(TEST_NICK) + 1) | 176 | GNUNET_break (0); |
151 | { | 177 | GNUNET_SCHEDULER_cancel (endbadly_task); |
152 | GNUNET_break(0); | 178 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
153 | GNUNET_SCHEDULER_cancel(endbadly_task); | 179 | return; |
154 | endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 180 | } |
155 | return; | 181 | if (rd[c].data_size != TEST_RECORD_DATALEN) |
156 | } | 182 | { |
157 | if (0 != (rd[c].flags & GNUNET_GNSRECORD_RF_PRIVATE)) | 183 | GNUNET_break (0); |
158 | { | 184 | GNUNET_SCHEDULER_cancel (endbadly_task); |
159 | GNUNET_break(0); | 185 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
160 | GNUNET_SCHEDULER_cancel(endbadly_task); | 186 | return; |
161 | endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 187 | } |
162 | return; | 188 | if (0 != memcmp (rd[c].data, rd_orig.data, TEST_RECORD_DATALEN)) |
163 | } | 189 | { |
164 | if (0 != strcmp(rd[c].data, TEST_NICK)) | 190 | GNUNET_break (0); |
165 | { | 191 | GNUNET_SCHEDULER_cancel (endbadly_task); |
166 | GNUNET_SCHEDULER_cancel(endbadly_task); | 192 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
167 | endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 193 | return; |
168 | return; | 194 | } |
169 | } | 195 | if (rd[c].flags != rd->flags) |
170 | found_nick = GNUNET_YES; | 196 | { |
171 | } | 197 | GNUNET_break (0); |
172 | else | 198 | GNUNET_SCHEDULER_cancel (endbadly_task); |
173 | { | 199 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
174 | if (rd[c].record_type != TEST_RECORD_TYPE) | 200 | return; |
175 | { | 201 | } |
176 | GNUNET_break(0); | 202 | found_record = GNUNET_YES; |
177 | GNUNET_SCHEDULER_cancel(endbadly_task); | ||
178 | endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL); | ||
179 | return; | ||
180 | } | ||
181 | if (rd[c].data_size != TEST_RECORD_DATALEN) | ||
182 | { | ||
183 | GNUNET_break(0); | ||
184 | GNUNET_SCHEDULER_cancel(endbadly_task); | ||
185 | endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL); | ||
186 | return; | ||
187 | } | ||
188 | if (0 != memcmp(rd[c].data, rd_orig.data, TEST_RECORD_DATALEN)) | ||
189 | { | ||
190 | GNUNET_break(0); | ||
191 | GNUNET_SCHEDULER_cancel(endbadly_task); | ||
192 | endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL); | ||
193 | return; | ||
194 | } | ||
195 | if (rd[c].flags != rd->flags) | ||
196 | { | ||
197 | GNUNET_break(0); | ||
198 | GNUNET_SCHEDULER_cancel(endbadly_task); | ||
199 | endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL); | ||
200 | return; | ||
201 | } | ||
202 | found_record = GNUNET_YES; | ||
203 | } | ||
204 | } | 203 | } |
204 | } | ||
205 | 205 | ||
206 | /* Done */ | 206 | /* Done */ |
207 | if ((GNUNET_YES == found_nick) && (GNUNET_YES == found_record)) | 207 | if ((GNUNET_YES == found_nick) && (GNUNET_YES == found_record)) |
208 | { | 208 | { |
209 | GNUNET_SCHEDULER_cancel(endbadly_task); | 209 | GNUNET_SCHEDULER_cancel (endbadly_task); |
210 | endbadly_task = NULL; | 210 | endbadly_task = NULL; |
211 | GNUNET_SCHEDULER_add_now(&end, NULL); | 211 | GNUNET_SCHEDULER_add_now (&end, NULL); |
212 | } | 212 | } |
213 | else | 213 | else |
214 | { | 214 | { |
215 | GNUNET_break(0); | 215 | GNUNET_break (0); |
216 | GNUNET_SCHEDULER_cancel(endbadly_task); | 216 | GNUNET_SCHEDULER_cancel (endbadly_task); |
217 | endbadly_task = NULL; | 217 | endbadly_task = NULL; |
218 | GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 218 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
219 | } | 219 | } |
220 | } | 220 | } |
221 | 221 | ||
222 | 222 | ||
223 | static void | 223 | static void |
224 | fail_cb(void *cls) | 224 | fail_cb (void *cls) |
225 | { | 225 | { |
226 | GNUNET_assert(0); | 226 | GNUNET_assert (0); |
227 | } | 227 | } |
228 | 228 | ||
229 | 229 | ||
230 | static void | 230 | static void |
231 | put_cont(void *cls, int32_t success, const char *emsg) | 231 | put_cont (void *cls, int32_t success, const char *emsg) |
232 | { | 232 | { |
233 | const char *name = cls; | 233 | const char *name = cls; |
234 | 234 | ||
235 | nsqe = NULL; | 235 | nsqe = NULL; |
236 | GNUNET_assert(NULL != cls); | 236 | GNUNET_assert (NULL != cls); |
237 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 237 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
238 | "Name store added record for `%s': %s\n", | 238 | "Name store added record for `%s': %s\n", |
239 | name, | 239 | name, |
240 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | 240 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); |
241 | 241 | ||
242 | if (GNUNET_OK != success) | 242 | if (GNUNET_OK != success) |
243 | { | 243 | { |
244 | GNUNET_SCHEDULER_cancel(endbadly_task); | 244 | GNUNET_SCHEDULER_cancel (endbadly_task); |
245 | endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 245 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
246 | return; | 246 | return; |
247 | } | 247 | } |
248 | /* Lookup */ | 248 | /* Lookup */ |
249 | nsqe = GNUNET_NAMESTORE_records_lookup(nsh, | 249 | nsqe = GNUNET_NAMESTORE_records_lookup (nsh, |
250 | privkey, | 250 | privkey, |
251 | name, | 251 | name, |
252 | &fail_cb, | 252 | &fail_cb, |
253 | NULL, | 253 | NULL, |
254 | &lookup_it, | 254 | &lookup_it, |
255 | NULL); | 255 | NULL); |
256 | } | 256 | } |
257 | 257 | ||
258 | 258 | ||
259 | static void | 259 | static void |
260 | nick_cont(void *cls, int32_t success, const char *emsg) | 260 | nick_cont (void *cls, int32_t success, const char *emsg) |
261 | { | 261 | { |
262 | const char *name = cls; | 262 | const char *name = cls; |
263 | 263 | ||
264 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 264 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
265 | "Nick added : %s\n", | 265 | "Nick added : %s\n", |
266 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | 266 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); |
267 | 267 | ||
268 | rd_orig.expiration_time = GNUNET_TIME_absolute_get().abs_value_us; | 268 | rd_orig.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us; |
269 | rd_orig.record_type = TEST_RECORD_TYPE; | 269 | rd_orig.record_type = TEST_RECORD_TYPE; |
270 | rd_orig.data_size = TEST_RECORD_DATALEN; | 270 | rd_orig.data_size = TEST_RECORD_DATALEN; |
271 | rd_orig.data = GNUNET_malloc(TEST_RECORD_DATALEN); | 271 | rd_orig.data = GNUNET_malloc (TEST_RECORD_DATALEN); |
272 | rd_orig.flags = 0; | 272 | rd_orig.flags = 0; |
273 | memset((char *)rd_orig.data, 'a', TEST_RECORD_DATALEN); | 273 | memset ((char *) rd_orig.data, 'a', TEST_RECORD_DATALEN); |
274 | 274 | ||
275 | nsqe = GNUNET_NAMESTORE_records_store(nsh, privkey, name, | 275 | nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, |
276 | 1, &rd_orig, &put_cont, (void *)name); | 276 | 1, &rd_orig, &put_cont, (void *) name); |
277 | } | 277 | } |
278 | 278 | ||
279 | 279 | ||
280 | static void | 280 | static void |
281 | run(void *cls, | 281 | run (void *cls, |
282 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 282 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
283 | struct GNUNET_TESTING_Peer *peer) | 283 | struct GNUNET_TESTING_Peer *peer) |
284 | { | 284 | { |
285 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, | 285 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
286 | &endbadly, | 286 | &endbadly, |
287 | NULL); | 287 | NULL); |
288 | privkey = GNUNET_CRYPTO_ecdsa_key_create(); | 288 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); |
289 | GNUNET_assert(privkey != NULL); | 289 | GNUNET_assert (privkey != NULL); |
290 | GNUNET_CRYPTO_ecdsa_key_get_public(privkey, | 290 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, |
291 | &pubkey); | 291 | &pubkey); |
292 | 292 | ||
293 | nsh = GNUNET_NAMESTORE_connect(cfg); | 293 | nsh = GNUNET_NAMESTORE_connect (cfg); |
294 | GNUNET_break(NULL != nsh); | 294 | GNUNET_break (NULL != nsh); |
295 | 295 | ||
296 | nsqe = GNUNET_NAMESTORE_set_nick(nsh, | 296 | nsqe = GNUNET_NAMESTORE_set_nick (nsh, |
297 | privkey, | 297 | privkey, |
298 | TEST_NICK, | 298 | TEST_NICK, |
299 | &nick_cont, | 299 | &nick_cont, |
300 | (void *)name); | 300 | (void *) name); |
301 | if (NULL == nsqe) | 301 | if (NULL == nsqe) |
302 | { | 302 | { |
303 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 303 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
304 | _("Namestore cannot store no block\n")); | 304 | _ ("Namestore cannot store no block\n")); |
305 | } | 305 | } |
306 | } | 306 | } |
307 | 307 | ||
308 | #include "test_common.c" | 308 | #include "test_common.c" |
309 | 309 | ||
310 | 310 | ||
311 | int | 311 | int |
312 | main(int argc, char *argv[]) | 312 | main (int argc, char *argv[]) |
313 | { | 313 | { |
314 | const char *plugin_name; | 314 | const char *plugin_name; |
315 | char *cfg_name; | 315 | char *cfg_name; |
316 | 316 | ||
317 | SETUP_CFG(plugin_name, cfg_name); | 317 | SETUP_CFG (plugin_name, cfg_name); |
318 | res = 1; | 318 | res = 1; |
319 | if (0 != | 319 | if (0 != |
320 | GNUNET_TESTING_peer_run("test-namestore-api-lookup-nick", | 320 | GNUNET_TESTING_peer_run ("test-namestore-api-lookup-nick", |
321 | cfg_name, | 321 | cfg_name, |
322 | &run, | 322 | &run, |
323 | NULL)) | 323 | NULL)) |
324 | { | 324 | { |
325 | res = 1; | 325 | res = 1; |
326 | } | 326 | } |
327 | GNUNET_DISK_purge_cfg_dir(cfg_name, | 327 | GNUNET_DISK_purge_cfg_dir (cfg_name, |
328 | "GNUNET_TEST_HOME"); | 328 | "GNUNET_TEST_HOME"); |
329 | GNUNET_free(cfg_name); | 329 | GNUNET_free (cfg_name); |
330 | return res; | 330 | return res; |
331 | } | 331 | } |
332 | 332 | ||
diff --git a/src/namestore/test_namestore_api_lookup_private.c b/src/namestore/test_namestore_api_lookup_private.c index a387720a0..e2600855c 100644 --- a/src/namestore/test_namestore_api_lookup_private.c +++ b/src/namestore/test_namestore_api_lookup_private.c | |||
@@ -32,11 +32,11 @@ | |||
32 | 32 | ||
33 | #define TEST_RECORD_DATA 'a' | 33 | #define TEST_RECORD_DATA 'a' |
34 | 34 | ||
35 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) | 35 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) |
36 | 36 | ||
37 | static struct GNUNET_NAMESTORE_Handle *nsh; | 37 | static struct GNUNET_NAMESTORE_Handle *nsh; |
38 | 38 | ||
39 | static struct GNUNET_SCHEDULER_Task * endbadly_task; | 39 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
40 | 40 | ||
41 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 41 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; |
42 | 42 | ||
@@ -46,24 +46,24 @@ static int res; | |||
46 | 46 | ||
47 | static struct GNUNET_NAMESTORE_QueueEntry *nsqe; | 47 | static struct GNUNET_NAMESTORE_QueueEntry *nsqe; |
48 | 48 | ||
49 | //static const char * name = "dummy.dummy.gnunet"; | 49 | // static const char * name = "dummy.dummy.gnunet"; |
50 | static const char * name = "d"; | 50 | static const char *name = "d"; |
51 | 51 | ||
52 | 52 | ||
53 | static void | 53 | static void |
54 | cleanup() | 54 | cleanup () |
55 | { | 55 | { |
56 | if (NULL != nsh) | 56 | if (NULL != nsh) |
57 | { | 57 | { |
58 | GNUNET_NAMESTORE_disconnect(nsh); | 58 | GNUNET_NAMESTORE_disconnect (nsh); |
59 | nsh = NULL; | 59 | nsh = NULL; |
60 | } | 60 | } |
61 | if (NULL != privkey) | 61 | if (NULL != privkey) |
62 | { | 62 | { |
63 | GNUNET_free(privkey); | 63 | GNUNET_free (privkey); |
64 | privkey = NULL; | 64 | privkey = NULL; |
65 | } | 65 | } |
66 | GNUNET_SCHEDULER_shutdown(); | 66 | GNUNET_SCHEDULER_shutdown (); |
67 | } | 67 | } |
68 | 68 | ||
69 | 69 | ||
@@ -73,152 +73,152 @@ cleanup() | |||
73 | * @param cls handle to use to re-connect. | 73 | * @param cls handle to use to re-connect. |
74 | */ | 74 | */ |
75 | static void | 75 | static void |
76 | endbadly(void *cls) | 76 | endbadly (void *cls) |
77 | { | 77 | { |
78 | endbadly_task = NULL; | 78 | endbadly_task = NULL; |
79 | if (NULL != nsqe) | 79 | if (NULL != nsqe) |
80 | { | 80 | { |
81 | GNUNET_NAMESTORE_cancel(nsqe); | 81 | GNUNET_NAMESTORE_cancel (nsqe); |
82 | nsqe = NULL; | 82 | nsqe = NULL; |
83 | } | 83 | } |
84 | cleanup(); | 84 | cleanup (); |
85 | res = 1; | 85 | res = 1; |
86 | } | 86 | } |
87 | 87 | ||
88 | 88 | ||
89 | static void | 89 | static void |
90 | end(void *cls) | 90 | end (void *cls) |
91 | { | 91 | { |
92 | cleanup(); | 92 | cleanup (); |
93 | res = 0; | 93 | res = 0; |
94 | } | 94 | } |
95 | 95 | ||
96 | 96 | ||
97 | static void | 97 | static void |
98 | lookup_it(void *cls, | 98 | lookup_it (void *cls, |
99 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 99 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
100 | const char *label, | 100 | const char *label, |
101 | unsigned int rd_count, | 101 | unsigned int rd_count, |
102 | const struct GNUNET_GNSRECORD_Data *rd) | 102 | const struct GNUNET_GNSRECORD_Data *rd) |
103 | { | 103 | { |
104 | nsqe = NULL; | 104 | nsqe = NULL; |
105 | 105 | ||
106 | if (0 != GNUNET_memcmp(privkey, | 106 | if (0 != GNUNET_memcmp (privkey, |
107 | zone)) | 107 | zone)) |
108 | { | 108 | { |
109 | GNUNET_break(0); | 109 | GNUNET_break (0); |
110 | GNUNET_SCHEDULER_cancel(endbadly_task); | 110 | GNUNET_SCHEDULER_cancel (endbadly_task); |
111 | endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 111 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
112 | return; | 112 | return; |
113 | } | 113 | } |
114 | 114 | ||
115 | 115 | ||
116 | if (NULL == label) | 116 | if (NULL == label) |
117 | { | 117 | { |
118 | GNUNET_break(0); | 118 | GNUNET_break (0); |
119 | GNUNET_SCHEDULER_cancel(endbadly_task); | 119 | GNUNET_SCHEDULER_cancel (endbadly_task); |
120 | endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 120 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
121 | return; | 121 | return; |
122 | } | 122 | } |
123 | 123 | ||
124 | if (0 != strcmp(label, name)) | 124 | if (0 != strcmp (label, name)) |
125 | { | 125 | { |
126 | GNUNET_break(0); | 126 | GNUNET_break (0); |
127 | GNUNET_SCHEDULER_cancel(endbadly_task); | 127 | GNUNET_SCHEDULER_cancel (endbadly_task); |
128 | endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 128 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
129 | return; | 129 | return; |
130 | } | 130 | } |
131 | 131 | ||
132 | if (1 != rd_count) | 132 | if (1 != rd_count) |
133 | { | 133 | { |
134 | GNUNET_break(0); | 134 | GNUNET_break (0); |
135 | GNUNET_SCHEDULER_cancel(endbadly_task); | 135 | GNUNET_SCHEDULER_cancel (endbadly_task); |
136 | endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 136 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
137 | return; | 137 | return; |
138 | } | 138 | } |
139 | 139 | ||
140 | /* Done */ | 140 | /* Done */ |
141 | GNUNET_SCHEDULER_cancel(endbadly_task); | 141 | GNUNET_SCHEDULER_cancel (endbadly_task); |
142 | endbadly_task = NULL; | 142 | endbadly_task = NULL; |
143 | GNUNET_SCHEDULER_add_now(&end, NULL); | 143 | GNUNET_SCHEDULER_add_now (&end, NULL); |
144 | } | 144 | } |
145 | 145 | ||
146 | 146 | ||
147 | static void | 147 | static void |
148 | fail_cb(void *cls) | 148 | fail_cb (void *cls) |
149 | { | 149 | { |
150 | GNUNET_assert(0); | 150 | GNUNET_assert (0); |
151 | } | 151 | } |
152 | 152 | ||
153 | 153 | ||
154 | static void | 154 | static void |
155 | put_cont(void *cls, | 155 | put_cont (void *cls, |
156 | int32_t success, | 156 | int32_t success, |
157 | const char *emsg) | 157 | const char *emsg) |
158 | { | 158 | { |
159 | const char *name = cls; | 159 | const char *name = cls; |
160 | 160 | ||
161 | nsqe = NULL; | 161 | nsqe = NULL; |
162 | GNUNET_assert(NULL != cls); | 162 | GNUNET_assert (NULL != cls); |
163 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 163 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
164 | "Name store added record for `%s': %s\n", | 164 | "Name store added record for `%s': %s\n", |
165 | name, | 165 | name, |
166 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | 166 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); |
167 | 167 | ||
168 | if (GNUNET_OK != success) | 168 | if (GNUNET_OK != success) |
169 | { | 169 | { |
170 | GNUNET_SCHEDULER_cancel(endbadly_task); | 170 | GNUNET_SCHEDULER_cancel (endbadly_task); |
171 | endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 171 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
172 | return; | 172 | return; |
173 | } | 173 | } |
174 | /* Lookup */ | 174 | /* Lookup */ |
175 | nsqe = GNUNET_NAMESTORE_records_lookup(nsh, | 175 | nsqe = GNUNET_NAMESTORE_records_lookup (nsh, |
176 | privkey, | 176 | privkey, |
177 | name, | 177 | name, |
178 | &fail_cb, | 178 | &fail_cb, |
179 | NULL, | 179 | NULL, |
180 | &lookup_it, | 180 | &lookup_it, |
181 | NULL); | 181 | NULL); |
182 | } | 182 | } |
183 | 183 | ||
184 | 184 | ||
185 | static void | 185 | static void |
186 | run(void *cls, | 186 | run (void *cls, |
187 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 187 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
188 | struct GNUNET_TESTING_Peer *peer) | 188 | struct GNUNET_TESTING_Peer *peer) |
189 | { | 189 | { |
190 | struct GNUNET_GNSRECORD_Data rd; | 190 | struct GNUNET_GNSRECORD_Data rd; |
191 | 191 | ||
192 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, | 192 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
193 | &endbadly, | 193 | &endbadly, |
194 | NULL); | 194 | NULL); |
195 | privkey = GNUNET_CRYPTO_ecdsa_key_create(); | 195 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); |
196 | GNUNET_assert(privkey != NULL); | 196 | GNUNET_assert (privkey != NULL); |
197 | GNUNET_CRYPTO_ecdsa_key_get_public(privkey, &pubkey); | 197 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); |
198 | 198 | ||
199 | rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us; | 199 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us; |
200 | rd.record_type = TEST_RECORD_TYPE; | 200 | rd.record_type = TEST_RECORD_TYPE; |
201 | rd.data_size = TEST_RECORD_DATALEN; | 201 | rd.data_size = TEST_RECORD_DATALEN; |
202 | rd.data = GNUNET_malloc(TEST_RECORD_DATALEN); | 202 | rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); |
203 | rd.flags = 0; | 203 | rd.flags = 0; |
204 | memset((char *)rd.data, 'a', TEST_RECORD_DATALEN); | 204 | memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN); |
205 | 205 | ||
206 | nsh = GNUNET_NAMESTORE_connect(cfg); | 206 | nsh = GNUNET_NAMESTORE_connect (cfg); |
207 | GNUNET_break(NULL != nsh); | 207 | GNUNET_break (NULL != nsh); |
208 | nsqe = GNUNET_NAMESTORE_records_store(nsh, | 208 | nsqe = GNUNET_NAMESTORE_records_store (nsh, |
209 | privkey, | 209 | privkey, |
210 | name, | 210 | name, |
211 | 1, | 211 | 1, |
212 | &rd, | 212 | &rd, |
213 | &put_cont, | 213 | &put_cont, |
214 | (void *)name); | 214 | (void *) name); |
215 | if (NULL == nsqe) | 215 | if (NULL == nsqe) |
216 | { | 216 | { |
217 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 217 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
218 | _("Namestore cannot store no block\n")); | 218 | _ ("Namestore cannot store no block\n")); |
219 | } | 219 | } |
220 | 220 | ||
221 | GNUNET_free((void *)rd.data); | 221 | GNUNET_free ((void *) rd.data); |
222 | } | 222 | } |
223 | 223 | ||
224 | 224 | ||
@@ -226,24 +226,24 @@ run(void *cls, | |||
226 | 226 | ||
227 | 227 | ||
228 | int | 228 | int |
229 | main(int argc, char *argv[]) | 229 | main (int argc, char *argv[]) |
230 | { | 230 | { |
231 | const char *plugin_name; | 231 | const char *plugin_name; |
232 | char *cfg_name; | 232 | char *cfg_name; |
233 | 233 | ||
234 | SETUP_CFG(plugin_name, cfg_name); | 234 | SETUP_CFG (plugin_name, cfg_name); |
235 | res = 1; | 235 | res = 1; |
236 | if (0 != | 236 | if (0 != |
237 | GNUNET_TESTING_peer_run("test-namestore-api-lookup-private", | 237 | GNUNET_TESTING_peer_run ("test-namestore-api-lookup-private", |
238 | cfg_name, | 238 | cfg_name, |
239 | &run, | 239 | &run, |
240 | NULL)) | 240 | NULL)) |
241 | { | 241 | { |
242 | res = 1; | 242 | res = 1; |
243 | } | 243 | } |
244 | GNUNET_DISK_purge_cfg_dir(cfg_name, | 244 | GNUNET_DISK_purge_cfg_dir (cfg_name, |
245 | "GNUNET_TEST_HOME"); | 245 | "GNUNET_TEST_HOME"); |
246 | GNUNET_free(cfg_name); | 246 | GNUNET_free (cfg_name); |
247 | return res; | 247 | return res; |
248 | } | 248 | } |
249 | 249 | ||
diff --git a/src/namestore/test_namestore_api_lookup_public.c b/src/namestore/test_namestore_api_lookup_public.c index 01f07eb39..6640f47ed 100644 --- a/src/namestore/test_namestore_api_lookup_public.c +++ b/src/namestore/test_namestore_api_lookup_public.c | |||
@@ -33,14 +33,14 @@ | |||
33 | 33 | ||
34 | #define TEST_RECORD_DATA 'a' | 34 | #define TEST_RECORD_DATA 'a' |
35 | 35 | ||
36 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100) | 36 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) |
37 | 37 | ||
38 | 38 | ||
39 | static struct GNUNET_NAMESTORE_Handle *nsh; | 39 | static struct GNUNET_NAMESTORE_Handle *nsh; |
40 | 40 | ||
41 | static struct GNUNET_NAMECACHE_Handle *nch; | 41 | static struct GNUNET_NAMECACHE_Handle *nch; |
42 | 42 | ||
43 | static struct GNUNET_SCHEDULER_Task * endbadly_task; | 43 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
44 | 44 | ||
45 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 45 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; |
46 | 46 | ||
@@ -54,24 +54,24 @@ static struct GNUNET_NAMECACHE_QueueEntry *ncqe; | |||
54 | 54 | ||
55 | 55 | ||
56 | static void | 56 | static void |
57 | cleanup() | 57 | cleanup () |
58 | { | 58 | { |
59 | if (NULL != nsh) | 59 | if (NULL != nsh) |
60 | { | 60 | { |
61 | GNUNET_NAMESTORE_disconnect(nsh); | 61 | GNUNET_NAMESTORE_disconnect (nsh); |
62 | nsh = NULL; | 62 | nsh = NULL; |
63 | } | 63 | } |
64 | if (NULL != nch) | 64 | if (NULL != nch) |
65 | { | 65 | { |
66 | GNUNET_NAMECACHE_disconnect(nch); | 66 | GNUNET_NAMECACHE_disconnect (nch); |
67 | nch = NULL; | 67 | nch = NULL; |
68 | } | 68 | } |
69 | if (NULL != privkey) | 69 | if (NULL != privkey) |
70 | { | 70 | { |
71 | GNUNET_free(privkey); | 71 | GNUNET_free (privkey); |
72 | privkey = NULL; | 72 | privkey = NULL; |
73 | } | 73 | } |
74 | GNUNET_SCHEDULER_shutdown(); | 74 | GNUNET_SCHEDULER_shutdown (); |
75 | } | 75 | } |
76 | 76 | ||
77 | 77 | ||
@@ -81,145 +81,147 @@ cleanup() | |||
81 | * @param cls handle to use to re-connect. | 81 | * @param cls handle to use to re-connect. |
82 | */ | 82 | */ |
83 | static void | 83 | static void |
84 | endbadly(void *cls) | 84 | endbadly (void *cls) |
85 | { | 85 | { |
86 | if (NULL != nsqe) | 86 | if (NULL != nsqe) |
87 | { | 87 | { |
88 | GNUNET_NAMESTORE_cancel(nsqe); | 88 | GNUNET_NAMESTORE_cancel (nsqe); |
89 | nsqe = NULL; | 89 | nsqe = NULL; |
90 | } | 90 | } |
91 | if (NULL != ncqe) | 91 | if (NULL != ncqe) |
92 | { | 92 | { |
93 | GNUNET_NAMECACHE_cancel(ncqe); | 93 | GNUNET_NAMECACHE_cancel (ncqe); |
94 | ncqe = NULL; | 94 | ncqe = NULL; |
95 | } | 95 | } |
96 | cleanup(); | 96 | cleanup (); |
97 | res = 1; | 97 | res = 1; |
98 | } | 98 | } |
99 | 99 | ||
100 | 100 | ||
101 | static void | 101 | static void |
102 | end(void *cls) | 102 | end (void *cls) |
103 | { | 103 | { |
104 | cleanup(); | 104 | cleanup (); |
105 | res = 0; | 105 | res = 0; |
106 | } | 106 | } |
107 | 107 | ||
108 | 108 | ||
109 | static void | 109 | static void |
110 | rd_decrypt_cb(void *cls, | 110 | rd_decrypt_cb (void *cls, |
111 | unsigned int rd_count, | 111 | unsigned int rd_count, |
112 | const struct GNUNET_GNSRECORD_Data *rd) | 112 | const struct GNUNET_GNSRECORD_Data *rd) |
113 | { | 113 | { |
114 | char rd_cmp_data[TEST_RECORD_DATALEN]; | 114 | char rd_cmp_data[TEST_RECORD_DATALEN]; |
115 | 115 | ||
116 | GNUNET_assert(1 == rd_count); | 116 | GNUNET_assert (1 == rd_count); |
117 | GNUNET_assert(NULL != rd); | 117 | GNUNET_assert (NULL != rd); |
118 | 118 | ||
119 | memset(rd_cmp_data, 'a', TEST_RECORD_DATALEN); | 119 | memset (rd_cmp_data, 'a', TEST_RECORD_DATALEN); |
120 | 120 | ||
121 | GNUNET_assert(TEST_RECORD_TYPE == rd[0].record_type); | 121 | GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type); |
122 | GNUNET_assert(TEST_RECORD_DATALEN == rd[0].data_size); | 122 | GNUNET_assert (TEST_RECORD_DATALEN == rd[0].data_size); |
123 | GNUNET_assert(0 == memcmp(&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN)); | 123 | GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN)); |
124 | 124 | ||
125 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 125 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
126 | "Block was decrypted successfully \n"); | 126 | "Block was decrypted successfully \n"); |
127 | 127 | ||
128 | GNUNET_SCHEDULER_add_now(&end, NULL); | 128 | GNUNET_SCHEDULER_add_now (&end, NULL); |
129 | } | 129 | } |
130 | 130 | ||
131 | 131 | ||
132 | static void | 132 | static void |
133 | name_lookup_proc(void *cls, | 133 | name_lookup_proc (void *cls, |
134 | const struct GNUNET_GNSRECORD_Block *block) | 134 | const struct GNUNET_GNSRECORD_Block *block) |
135 | { | 135 | { |
136 | const char *name = cls; | 136 | const char *name = cls; |
137 | 137 | ||
138 | ncqe = NULL; | 138 | ncqe = NULL; |
139 | GNUNET_assert(NULL != cls); | 139 | GNUNET_assert (NULL != cls); |
140 | 140 | ||
141 | if (endbadly_task != NULL) | 141 | if (endbadly_task != NULL) |
142 | { | 142 | { |
143 | GNUNET_SCHEDULER_cancel(endbadly_task); | 143 | GNUNET_SCHEDULER_cancel (endbadly_task); |
144 | endbadly_task = NULL; | 144 | endbadly_task = NULL; |
145 | } | 145 | } |
146 | 146 | ||
147 | if (NULL == block) | 147 | if (NULL == block) |
148 | { | 148 | { |
149 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 149 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
150 | _("Namestore returned no block\n")); | 150 | _ ("Namestore returned no block\n")); |
151 | if (endbadly_task != NULL) | 151 | if (endbadly_task != NULL) |
152 | GNUNET_SCHEDULER_cancel(endbadly_task); | 152 | GNUNET_SCHEDULER_cancel (endbadly_task); |
153 | endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 153 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
154 | return; | 154 | return; |
155 | } | 155 | } |
156 | 156 | ||
157 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 157 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
158 | "Namestore returned block, decrypting \n"); | 158 | "Namestore returned block, decrypting \n"); |
159 | GNUNET_assert(GNUNET_OK == GNUNET_GNSRECORD_block_decrypt(block, | 159 | GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_decrypt (block, |
160 | &pubkey, name, &rd_decrypt_cb, (void *)name)); | 160 | &pubkey, name, |
161 | &rd_decrypt_cb, | ||
162 | (void *) name)); | ||
161 | } | 163 | } |
162 | 164 | ||
163 | 165 | ||
164 | static void | 166 | static void |
165 | put_cont(void *cls, int32_t success, const char *emsg) | 167 | put_cont (void *cls, int32_t success, const char *emsg) |
166 | { | 168 | { |
167 | const char *name = cls; | 169 | const char *name = cls; |
168 | struct GNUNET_HashCode derived_hash; | 170 | struct GNUNET_HashCode derived_hash; |
169 | struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 171 | struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; |
170 | 172 | ||
171 | nsqe = NULL; | 173 | nsqe = NULL; |
172 | GNUNET_assert(NULL != cls); | 174 | GNUNET_assert (NULL != cls); |
173 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 175 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
174 | "Name store added record for `%s': %s\n", | 176 | "Name store added record for `%s': %s\n", |
175 | name, | 177 | name, |
176 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | 178 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); |
177 | 179 | ||
178 | /* Create derived hash */ | 180 | /* Create derived hash */ |
179 | GNUNET_CRYPTO_ecdsa_key_get_public(privkey, &pubkey); | 181 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); |
180 | GNUNET_GNSRECORD_query_from_public_key(&pubkey, name, &derived_hash); | 182 | GNUNET_GNSRECORD_query_from_public_key (&pubkey, name, &derived_hash); |
181 | 183 | ||
182 | ncqe = GNUNET_NAMECACHE_lookup_block(nch, &derived_hash, | 184 | ncqe = GNUNET_NAMECACHE_lookup_block (nch, &derived_hash, |
183 | &name_lookup_proc, (void *)name); | 185 | &name_lookup_proc, (void *) name); |
184 | } | 186 | } |
185 | 187 | ||
186 | 188 | ||
187 | static void | 189 | static void |
188 | run(void *cls, | 190 | run (void *cls, |
189 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 191 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
190 | struct GNUNET_TESTING_Peer *peer) | 192 | struct GNUNET_TESTING_Peer *peer) |
191 | { | 193 | { |
192 | struct GNUNET_GNSRECORD_Data rd; | 194 | struct GNUNET_GNSRECORD_Data rd; |
193 | const char * name = "dummy.dummy.gnunet"; | 195 | const char *name = "dummy.dummy.gnunet"; |
194 | 196 | ||
195 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, | 197 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
196 | &endbadly, | 198 | &endbadly, |
197 | NULL); | 199 | NULL); |
198 | privkey = GNUNET_CRYPTO_ecdsa_key_create(); | 200 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); |
199 | GNUNET_assert(privkey != NULL); | 201 | GNUNET_assert (privkey != NULL); |
200 | GNUNET_CRYPTO_ecdsa_key_get_public(privkey, | 202 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, |
201 | &pubkey); | 203 | &pubkey); |
202 | 204 | ||
203 | rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; | 205 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us + 1000000000; |
204 | rd.record_type = TEST_RECORD_TYPE; | 206 | rd.record_type = TEST_RECORD_TYPE; |
205 | rd.data_size = TEST_RECORD_DATALEN; | 207 | rd.data_size = TEST_RECORD_DATALEN; |
206 | rd.data = GNUNET_malloc(TEST_RECORD_DATALEN); | 208 | rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); |
207 | rd.flags = 0; | 209 | rd.flags = 0; |
208 | memset((char *)rd.data, 'a', TEST_RECORD_DATALEN); | 210 | memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN); |
209 | 211 | ||
210 | nsh = GNUNET_NAMESTORE_connect(cfg); | 212 | nsh = GNUNET_NAMESTORE_connect (cfg); |
211 | nch = GNUNET_NAMECACHE_connect(cfg); | 213 | nch = GNUNET_NAMECACHE_connect (cfg); |
212 | GNUNET_break(NULL != nsh); | 214 | GNUNET_break (NULL != nsh); |
213 | GNUNET_break(NULL != nch); | 215 | GNUNET_break (NULL != nch); |
214 | nsqe = GNUNET_NAMESTORE_records_store(nsh, privkey, name, | 216 | nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, |
215 | 1, &rd, &put_cont, (void *)name); | 217 | 1, &rd, &put_cont, (void *) name); |
216 | if (NULL == nsqe) | 218 | if (NULL == nsqe) |
217 | { | 219 | { |
218 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 220 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
219 | _("Namestore cannot store no block\n")); | 221 | _ ("Namestore cannot store no block\n")); |
220 | } | 222 | } |
221 | 223 | ||
222 | GNUNET_free((void *)rd.data); | 224 | GNUNET_free ((void *) rd.data); |
223 | } | 225 | } |
224 | 226 | ||
225 | 227 | ||
@@ -227,24 +229,24 @@ run(void *cls, | |||
227 | 229 | ||
228 | 230 | ||
229 | int | 231 | int |
230 | main(int argc, char *argv[]) | 232 | main (int argc, char *argv[]) |
231 | { | 233 | { |
232 | const char *plugin_name; | 234 | const char *plugin_name; |
233 | char *cfg_name; | 235 | char *cfg_name; |
234 | 236 | ||
235 | SETUP_CFG(plugin_name, cfg_name); | 237 | SETUP_CFG (plugin_name, cfg_name); |
236 | res = 1; | 238 | res = 1; |
237 | if (0 != | 239 | if (0 != |
238 | GNUNET_TESTING_peer_run("test-namestore-api", | 240 | GNUNET_TESTING_peer_run ("test-namestore-api", |
239 | cfg_name, | 241 | cfg_name, |
240 | &run, | 242 | &run, |
241 | NULL)) | 243 | NULL)) |
242 | { | 244 | { |
243 | res = 1; | 245 | res = 1; |
244 | } | 246 | } |
245 | GNUNET_DISK_purge_cfg_dir(cfg_name, | 247 | GNUNET_DISK_purge_cfg_dir (cfg_name, |
246 | "GNUNET_TEST_HOME"); | 248 | "GNUNET_TEST_HOME"); |
247 | GNUNET_free(cfg_name); | 249 | GNUNET_free (cfg_name); |
248 | return res; | 250 | return res; |
249 | } | 251 | } |
250 | 252 | ||
diff --git a/src/namestore/test_namestore_api_lookup_shadow.c b/src/namestore/test_namestore_api_lookup_shadow.c index d25cdcdbb..7daa6987c 100644 --- a/src/namestore/test_namestore_api_lookup_shadow.c +++ b/src/namestore/test_namestore_api_lookup_shadow.c | |||
@@ -35,14 +35,14 @@ | |||
35 | 35 | ||
36 | #define TEST_RECORD_DATA 'a' | 36 | #define TEST_RECORD_DATA 'a' |
37 | 37 | ||
38 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100) | 38 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) |
39 | 39 | ||
40 | 40 | ||
41 | static struct GNUNET_NAMESTORE_Handle *nsh; | 41 | static struct GNUNET_NAMESTORE_Handle *nsh; |
42 | 42 | ||
43 | static struct GNUNET_NAMECACHE_Handle *nch; | 43 | static struct GNUNET_NAMECACHE_Handle *nch; |
44 | 44 | ||
45 | static struct GNUNET_SCHEDULER_Task * endbadly_task; | 45 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
46 | 46 | ||
47 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 47 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; |
48 | 48 | ||
@@ -56,24 +56,24 @@ static struct GNUNET_NAMECACHE_QueueEntry *ncqe; | |||
56 | 56 | ||
57 | 57 | ||
58 | static void | 58 | static void |
59 | cleanup() | 59 | cleanup () |
60 | { | 60 | { |
61 | if (NULL != nsh) | 61 | if (NULL != nsh) |
62 | { | 62 | { |
63 | GNUNET_NAMESTORE_disconnect(nsh); | 63 | GNUNET_NAMESTORE_disconnect (nsh); |
64 | nsh = NULL; | 64 | nsh = NULL; |
65 | } | 65 | } |
66 | if (NULL != nch) | 66 | if (NULL != nch) |
67 | { | 67 | { |
68 | GNUNET_NAMECACHE_disconnect(nch); | 68 | GNUNET_NAMECACHE_disconnect (nch); |
69 | nch = NULL; | 69 | nch = NULL; |
70 | } | 70 | } |
71 | if (NULL != privkey) | 71 | if (NULL != privkey) |
72 | { | 72 | { |
73 | GNUNET_free(privkey); | 73 | GNUNET_free (privkey); |
74 | privkey = NULL; | 74 | privkey = NULL; |
75 | } | 75 | } |
76 | GNUNET_SCHEDULER_shutdown(); | 76 | GNUNET_SCHEDULER_shutdown (); |
77 | } | 77 | } |
78 | 78 | ||
79 | 79 | ||
@@ -83,178 +83,180 @@ cleanup() | |||
83 | * @param cls handle to use to re-connect. | 83 | * @param cls handle to use to re-connect. |
84 | */ | 84 | */ |
85 | static void | 85 | static void |
86 | endbadly(void *cls) | 86 | endbadly (void *cls) |
87 | { | 87 | { |
88 | if (NULL != nsqe) | 88 | if (NULL != nsqe) |
89 | { | 89 | { |
90 | GNUNET_NAMESTORE_cancel(nsqe); | 90 | GNUNET_NAMESTORE_cancel (nsqe); |
91 | nsqe = NULL; | 91 | nsqe = NULL; |
92 | } | 92 | } |
93 | if (NULL != ncqe) | 93 | if (NULL != ncqe) |
94 | { | 94 | { |
95 | GNUNET_NAMECACHE_cancel(ncqe); | 95 | GNUNET_NAMECACHE_cancel (ncqe); |
96 | ncqe = NULL; | 96 | ncqe = NULL; |
97 | } | 97 | } |
98 | cleanup(); | 98 | cleanup (); |
99 | res = 1; | 99 | res = 1; |
100 | } | 100 | } |
101 | 101 | ||
102 | 102 | ||
103 | static void | 103 | static void |
104 | end(void *cls) | 104 | end (void *cls) |
105 | { | 105 | { |
106 | cleanup(); | 106 | cleanup (); |
107 | res = 0; | 107 | res = 0; |
108 | } | 108 | } |
109 | 109 | ||
110 | 110 | ||
111 | static void | 111 | static void |
112 | rd_decrypt_cb(void *cls, | 112 | rd_decrypt_cb (void *cls, |
113 | unsigned int rd_count, | 113 | unsigned int rd_count, |
114 | const struct GNUNET_GNSRECORD_Data *rd) | 114 | const struct GNUNET_GNSRECORD_Data *rd) |
115 | { | 115 | { |
116 | char rd_cmp_data[TEST_RECORD_DATALEN]; | 116 | char rd_cmp_data[TEST_RECORD_DATALEN]; |
117 | 117 | ||
118 | if (1 != rd_count) | 118 | if (1 != rd_count) |
119 | { | 119 | { |
120 | GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 120 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
121 | GNUNET_break(0); | 121 | GNUNET_break (0); |
122 | return; | 122 | return; |
123 | } | 123 | } |
124 | if (NULL == rd) | 124 | if (NULL == rd) |
125 | { | 125 | { |
126 | GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 126 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
127 | GNUNET_break(0); | 127 | GNUNET_break (0); |
128 | return; | 128 | return; |
129 | } | 129 | } |
130 | memset(rd_cmp_data, 'a', TEST_RECORD_DATALEN); | 130 | memset (rd_cmp_data, 'a', TEST_RECORD_DATALEN); |
131 | 131 | ||
132 | if (TEST_RECORD_TYPE != rd[0].record_type) | 132 | if (TEST_RECORD_TYPE != rd[0].record_type) |
133 | { | 133 | { |
134 | GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 134 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
135 | GNUNET_break(0); | 135 | GNUNET_break (0); |
136 | return; | 136 | return; |
137 | } | 137 | } |
138 | if (TEST_RECORD_DATALEN != rd[0].data_size) | 138 | if (TEST_RECORD_DATALEN != rd[0].data_size) |
139 | { | 139 | { |
140 | GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 140 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
141 | GNUNET_break(0); | 141 | GNUNET_break (0); |
142 | return; | 142 | return; |
143 | } | 143 | } |
144 | if (0 != memcmp(&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN)) | 144 | if (0 != memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN)) |
145 | { | 145 | { |
146 | GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 146 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
147 | GNUNET_break(0); | 147 | GNUNET_break (0); |
148 | return; | 148 | return; |
149 | } | 149 | } |
150 | if (0 != (GNUNET_GNSRECORD_RF_SHADOW_RECORD & rd[0].flags)) | 150 | if (0 != (GNUNET_GNSRECORD_RF_SHADOW_RECORD & rd[0].flags)) |
151 | { | 151 | { |
152 | GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 152 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
153 | GNUNET_break(0); | 153 | GNUNET_break (0); |
154 | return; | 154 | return; |
155 | } | 155 | } |
156 | 156 | ||
157 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 157 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
158 | "Block was decrypted successfully \n"); | 158 | "Block was decrypted successfully \n"); |
159 | 159 | ||
160 | GNUNET_SCHEDULER_add_now(&end, NULL); | 160 | GNUNET_SCHEDULER_add_now (&end, NULL); |
161 | } | 161 | } |
162 | 162 | ||
163 | 163 | ||
164 | static void | 164 | static void |
165 | name_lookup_proc(void *cls, | 165 | name_lookup_proc (void *cls, |
166 | const struct GNUNET_GNSRECORD_Block *block) | 166 | const struct GNUNET_GNSRECORD_Block *block) |
167 | { | 167 | { |
168 | const char *name = cls; | 168 | const char *name = cls; |
169 | 169 | ||
170 | ncqe = NULL; | 170 | ncqe = NULL; |
171 | GNUNET_assert(NULL != cls); | 171 | GNUNET_assert (NULL != cls); |
172 | 172 | ||
173 | if (endbadly_task != NULL) | 173 | if (endbadly_task != NULL) |
174 | { | 174 | { |
175 | GNUNET_SCHEDULER_cancel(endbadly_task); | 175 | GNUNET_SCHEDULER_cancel (endbadly_task); |
176 | endbadly_task = NULL; | 176 | endbadly_task = NULL; |
177 | } | 177 | } |
178 | 178 | ||
179 | if (NULL == block) | 179 | if (NULL == block) |
180 | { | 180 | { |
181 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 181 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
182 | _("Namestore returned no block\n")); | 182 | _ ("Namestore returned no block\n")); |
183 | if (endbadly_task != NULL) | 183 | if (endbadly_task != NULL) |
184 | GNUNET_SCHEDULER_cancel(endbadly_task); | 184 | GNUNET_SCHEDULER_cancel (endbadly_task); |
185 | endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 185 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
186 | return; | 186 | return; |
187 | } | 187 | } |
188 | 188 | ||
189 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 189 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
190 | "Namestore returned block, decrypting \n"); | 190 | "Namestore returned block, decrypting \n"); |
191 | GNUNET_assert(GNUNET_OK == GNUNET_GNSRECORD_block_decrypt(block, | 191 | GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_decrypt (block, |
192 | &pubkey, name, &rd_decrypt_cb, (void *)name)); | 192 | &pubkey, name, |
193 | &rd_decrypt_cb, | ||
194 | (void *) name)); | ||
193 | } | 195 | } |
194 | 196 | ||
195 | 197 | ||
196 | static void | 198 | static void |
197 | put_cont(void *cls, int32_t success, const char *emsg) | 199 | put_cont (void *cls, int32_t success, const char *emsg) |
198 | { | 200 | { |
199 | const char *name = cls; | 201 | const char *name = cls; |
200 | struct GNUNET_HashCode derived_hash; | 202 | struct GNUNET_HashCode derived_hash; |
201 | struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 203 | struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; |
202 | 204 | ||
203 | nsqe = NULL; | 205 | nsqe = NULL; |
204 | GNUNET_assert(NULL != cls); | 206 | GNUNET_assert (NULL != cls); |
205 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 207 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
206 | "Name store added record for `%s': %s\n", | 208 | "Name store added record for `%s': %s\n", |
207 | name, | 209 | name, |
208 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | 210 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); |
209 | 211 | ||
210 | /* Create derived hash */ | 212 | /* Create derived hash */ |
211 | GNUNET_CRYPTO_ecdsa_key_get_public(privkey, &pubkey); | 213 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); |
212 | GNUNET_GNSRECORD_query_from_public_key(&pubkey, name, &derived_hash); | 214 | GNUNET_GNSRECORD_query_from_public_key (&pubkey, name, &derived_hash); |
213 | 215 | ||
214 | ncqe = GNUNET_NAMECACHE_lookup_block(nch, &derived_hash, | 216 | ncqe = GNUNET_NAMECACHE_lookup_block (nch, &derived_hash, |
215 | &name_lookup_proc, (void *)name); | 217 | &name_lookup_proc, (void *) name); |
216 | } | 218 | } |
217 | 219 | ||
218 | 220 | ||
219 | static void | 221 | static void |
220 | run(void *cls, | 222 | run (void *cls, |
221 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 223 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
222 | struct GNUNET_TESTING_Peer *peer) | 224 | struct GNUNET_TESTING_Peer *peer) |
223 | { | 225 | { |
224 | struct GNUNET_GNSRECORD_Data rd; | 226 | struct GNUNET_GNSRECORD_Data rd; |
225 | const char * name = "dummy.dummy.gnunet"; | 227 | const char *name = "dummy.dummy.gnunet"; |
226 | 228 | ||
227 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, | 229 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
228 | &endbadly, | 230 | &endbadly, |
229 | NULL); | 231 | NULL); |
230 | privkey = GNUNET_CRYPTO_ecdsa_key_create(); | 232 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); |
231 | GNUNET_assert(privkey != NULL); | 233 | GNUNET_assert (privkey != NULL); |
232 | GNUNET_CRYPTO_ecdsa_key_get_public(privkey, | 234 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, |
233 | &pubkey); | 235 | &pubkey); |
234 | rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; | 236 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us + 1000000000; |
235 | rd.record_type = TEST_RECORD_TYPE; | 237 | rd.record_type = TEST_RECORD_TYPE; |
236 | rd.data_size = TEST_RECORD_DATALEN; | 238 | rd.data_size = TEST_RECORD_DATALEN; |
237 | rd.data = GNUNET_malloc(TEST_RECORD_DATALEN); | 239 | rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); |
238 | rd.flags = GNUNET_GNSRECORD_RF_SHADOW_RECORD; | 240 | rd.flags = GNUNET_GNSRECORD_RF_SHADOW_RECORD; |
239 | memset((char *)rd.data, 'a', TEST_RECORD_DATALEN); | 241 | memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN); |
240 | 242 | ||
241 | nsh = GNUNET_NAMESTORE_connect(cfg); | 243 | nsh = GNUNET_NAMESTORE_connect (cfg); |
242 | nch = GNUNET_NAMECACHE_connect(cfg); | 244 | nch = GNUNET_NAMECACHE_connect (cfg); |
243 | GNUNET_break(NULL != nsh); | 245 | GNUNET_break (NULL != nsh); |
244 | GNUNET_break(NULL != nch); | 246 | GNUNET_break (NULL != nch); |
245 | nsqe = GNUNET_NAMESTORE_records_store(nsh, | 247 | nsqe = GNUNET_NAMESTORE_records_store (nsh, |
246 | privkey, | 248 | privkey, |
247 | name, | 249 | name, |
248 | 1, | 250 | 1, |
249 | &rd, | 251 | &rd, |
250 | &put_cont, | 252 | &put_cont, |
251 | (void *)name); | 253 | (void *) name); |
252 | if (NULL == nsqe) | 254 | if (NULL == nsqe) |
253 | { | 255 | { |
254 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 256 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
255 | _("Namestore cannot store no block\n")); | 257 | _ ("Namestore cannot store no block\n")); |
256 | } | 258 | } |
257 | GNUNET_free((void *)rd.data); | 259 | GNUNET_free ((void *) rd.data); |
258 | } | 260 | } |
259 | 261 | ||
260 | 262 | ||
@@ -262,24 +264,24 @@ run(void *cls, | |||
262 | 264 | ||
263 | 265 | ||
264 | int | 266 | int |
265 | main(int argc, char *argv[]) | 267 | main (int argc, char *argv[]) |
266 | { | 268 | { |
267 | const char *plugin_name; | 269 | const char *plugin_name; |
268 | char *cfg_name; | 270 | char *cfg_name; |
269 | 271 | ||
270 | SETUP_CFG(plugin_name, cfg_name); | 272 | SETUP_CFG (plugin_name, cfg_name); |
271 | res = 1; | 273 | res = 1; |
272 | if (0 != | 274 | if (0 != |
273 | GNUNET_TESTING_peer_run("test-namestore-api-lookup-shadow", | 275 | GNUNET_TESTING_peer_run ("test-namestore-api-lookup-shadow", |
274 | cfg_name, | 276 | cfg_name, |
275 | &run, | 277 | &run, |
276 | NULL)) | 278 | NULL)) |
277 | { | 279 | { |
278 | res = 1; | 280 | res = 1; |
279 | } | 281 | } |
280 | GNUNET_DISK_purge_cfg_dir(cfg_name, | 282 | GNUNET_DISK_purge_cfg_dir (cfg_name, |
281 | "GNUNET_TEST_HOME"); | 283 | "GNUNET_TEST_HOME"); |
282 | GNUNET_free(cfg_name); | 284 | GNUNET_free (cfg_name); |
283 | return res; | 285 | return res; |
284 | } | 286 | } |
285 | 287 | ||
diff --git a/src/namestore/test_namestore_api_lookup_shadow_filter.c b/src/namestore/test_namestore_api_lookup_shadow_filter.c index d8d6b8a29..694c189e1 100644 --- a/src/namestore/test_namestore_api_lookup_shadow_filter.c +++ b/src/namestore/test_namestore_api_lookup_shadow_filter.c | |||
@@ -37,16 +37,16 @@ | |||
37 | #define TEST_RECORD_DATA 'a' | 37 | #define TEST_RECORD_DATA 'a' |
38 | #define TEST_SHADOW_RECORD_DATA 'b' | 38 | #define TEST_SHADOW_RECORD_DATA 'b' |
39 | 39 | ||
40 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100) | 40 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) |
41 | #define EXPIRATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) | 41 | #define EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) |
42 | 42 | ||
43 | static struct GNUNET_NAMESTORE_Handle *nsh; | 43 | static struct GNUNET_NAMESTORE_Handle *nsh; |
44 | 44 | ||
45 | static struct GNUNET_NAMECACHE_Handle *nch; | 45 | static struct GNUNET_NAMECACHE_Handle *nch; |
46 | 46 | ||
47 | static struct GNUNET_SCHEDULER_Task * endbadly_task; | 47 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
48 | 48 | ||
49 | static struct GNUNET_SCHEDULER_Task * delayed_lookup_task; | 49 | static struct GNUNET_SCHEDULER_Task *delayed_lookup_task; |
50 | 50 | ||
51 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 51 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; |
52 | 52 | ||
@@ -70,24 +70,24 @@ static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | |||
70 | 70 | ||
71 | 71 | ||
72 | static void | 72 | static void |
73 | cleanup() | 73 | cleanup () |
74 | { | 74 | { |
75 | if (NULL != nsh) | 75 | if (NULL != nsh) |
76 | { | 76 | { |
77 | GNUNET_NAMESTORE_disconnect(nsh); | 77 | GNUNET_NAMESTORE_disconnect (nsh); |
78 | nsh = NULL; | 78 | nsh = NULL; |
79 | } | 79 | } |
80 | if (NULL != nch) | 80 | if (NULL != nch) |
81 | { | 81 | { |
82 | GNUNET_NAMECACHE_disconnect(nch); | 82 | GNUNET_NAMECACHE_disconnect (nch); |
83 | nch = NULL; | 83 | nch = NULL; |
84 | } | 84 | } |
85 | if (NULL != privkey) | 85 | if (NULL != privkey) |
86 | { | 86 | { |
87 | GNUNET_free(privkey); | 87 | GNUNET_free (privkey); |
88 | privkey = NULL; | 88 | privkey = NULL; |
89 | } | 89 | } |
90 | GNUNET_SCHEDULER_shutdown(); | 90 | GNUNET_SCHEDULER_shutdown (); |
91 | } | 91 | } |
92 | 92 | ||
93 | 93 | ||
@@ -97,240 +97,247 @@ cleanup() | |||
97 | * @param cls handle to use to re-connect. | 97 | * @param cls handle to use to re-connect. |
98 | */ | 98 | */ |
99 | static void | 99 | static void |
100 | endbadly(void *cls) | 100 | endbadly (void *cls) |
101 | { | 101 | { |
102 | if (NULL != delayed_lookup_task) | 102 | if (NULL != delayed_lookup_task) |
103 | { | 103 | { |
104 | GNUNET_SCHEDULER_cancel(delayed_lookup_task); | 104 | GNUNET_SCHEDULER_cancel (delayed_lookup_task); |
105 | delayed_lookup_task = NULL; | 105 | delayed_lookup_task = NULL; |
106 | } | 106 | } |
107 | if (NULL != nsqe) | 107 | if (NULL != nsqe) |
108 | { | 108 | { |
109 | GNUNET_NAMESTORE_cancel(nsqe); | 109 | GNUNET_NAMESTORE_cancel (nsqe); |
110 | nsqe = NULL; | 110 | nsqe = NULL; |
111 | } | 111 | } |
112 | if (NULL != ncqe) | 112 | if (NULL != ncqe) |
113 | { | 113 | { |
114 | GNUNET_NAMECACHE_cancel(ncqe); | 114 | GNUNET_NAMECACHE_cancel (ncqe); |
115 | ncqe = NULL; | 115 | ncqe = NULL; |
116 | } | 116 | } |
117 | cleanup(); | 117 | cleanup (); |
118 | res = 1; | 118 | res = 1; |
119 | } | 119 | } |
120 | 120 | ||
121 | 121 | ||
122 | static void | 122 | static void |
123 | end(void *cls) | 123 | end (void *cls) |
124 | { | 124 | { |
125 | cleanup(); | 125 | cleanup (); |
126 | res = 0; | 126 | res = 0; |
127 | } | 127 | } |
128 | 128 | ||
129 | 129 | ||
130 | static void | 130 | static void |
131 | rd_decrypt_cb(void *cls, | 131 | rd_decrypt_cb (void *cls, |
132 | unsigned int rd_count, | 132 | unsigned int rd_count, |
133 | const struct GNUNET_GNSRECORD_Data *rd) | 133 | const struct GNUNET_GNSRECORD_Data *rd) |
134 | { | 134 | { |
135 | struct GNUNET_GNSRECORD_Data *expected_rd = cls; | 135 | struct GNUNET_GNSRECORD_Data *expected_rd = cls; |
136 | char rd_cmp_data[TEST_RECORD_DATALEN]; | 136 | char rd_cmp_data[TEST_RECORD_DATALEN]; |
137 | 137 | ||
138 | if (1 != rd_count) | 138 | if (1 != rd_count) |
139 | { | ||
140 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
141 | GNUNET_break (0); | ||
142 | return; | ||
143 | } | ||
144 | if (NULL == rd) | ||
145 | { | ||
146 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
147 | GNUNET_break (0); | ||
148 | return; | ||
149 | } | ||
150 | if (expected_rd == &records[0]) | ||
151 | { | ||
152 | /* Expecting active record */ | ||
153 | memset (rd_cmp_data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); | ||
154 | if (TEST_RECORD_TYPE != rd[0].record_type) | ||
139 | { | 155 | { |
140 | GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 156 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
141 | GNUNET_break(0); | 157 | GNUNET_break (0); |
142 | return; | 158 | return; |
143 | } | 159 | } |
144 | if (NULL == rd) | 160 | if (TEST_RECORD_DATALEN != rd[0].data_size) |
145 | { | 161 | { |
146 | GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 162 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
147 | GNUNET_break(0); | 163 | GNUNET_break (0); |
148 | return; | 164 | return; |
149 | } | 165 | } |
150 | if (expected_rd == &records[0]) | 166 | if (0 != memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN)) |
151 | { | 167 | { |
152 | /* Expecting active record */ | 168 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
153 | memset(rd_cmp_data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); | 169 | GNUNET_break (0); |
154 | if (TEST_RECORD_TYPE != rd[0].record_type) | 170 | return; |
155 | { | ||
156 | GNUNET_SCHEDULER_add_now(&endbadly, NULL); | ||
157 | GNUNET_break(0); | ||
158 | return; | ||
159 | } | ||
160 | if (TEST_RECORD_DATALEN != rd[0].data_size) | ||
161 | { | ||
162 | GNUNET_SCHEDULER_add_now(&endbadly, NULL); | ||
163 | GNUNET_break(0); | ||
164 | return; | ||
165 | } | ||
166 | if (0 != memcmp(&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN)) | ||
167 | { | ||
168 | GNUNET_SCHEDULER_add_now(&endbadly, NULL); | ||
169 | GNUNET_break(0); | ||
170 | return; | ||
171 | } | ||
172 | if (0 != (GNUNET_GNSRECORD_RF_SHADOW_RECORD & rd[0].flags)) | ||
173 | { | ||
174 | GNUNET_SCHEDULER_add_now(&endbadly, NULL); | ||
175 | GNUNET_break(0); | ||
176 | return; | ||
177 | } | ||
178 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
179 | "Block was decrypted successfully with active record\n"); | ||
180 | } | 171 | } |
172 | if (0 != (GNUNET_GNSRECORD_RF_SHADOW_RECORD & rd[0].flags)) | ||
173 | { | ||
174 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
175 | GNUNET_break (0); | ||
176 | return; | ||
177 | } | ||
178 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
179 | "Block was decrypted successfully with active record\n"); | ||
180 | } | ||
181 | if (expected_rd == &records[1]) | 181 | if (expected_rd == &records[1]) |
182 | { | ||
183 | /* Expecting shadow record but without shadow flag*/ | ||
184 | memset (rd_cmp_data, TEST_SHADOW_RECORD_DATA, TEST_RECORD_DATALEN); | ||
185 | if (TEST_RECORD_TYPE != rd[0].record_type) | ||
186 | { | ||
187 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
188 | GNUNET_break (0); | ||
189 | return; | ||
190 | } | ||
191 | if (TEST_RECORD_DATALEN != rd[0].data_size) | ||
192 | { | ||
193 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
194 | GNUNET_break (0); | ||
195 | return; | ||
196 | } | ||
197 | if (0 != memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN)) | ||
182 | { | 198 | { |
183 | /* Expecting shadow record but without shadow flag*/ | 199 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
184 | memset(rd_cmp_data, TEST_SHADOW_RECORD_DATA, TEST_RECORD_DATALEN); | 200 | GNUNET_break (0); |
185 | if (TEST_RECORD_TYPE != rd[0].record_type) | 201 | return; |
186 | { | ||
187 | GNUNET_SCHEDULER_add_now(&endbadly, NULL); | ||
188 | GNUNET_break(0); | ||
189 | return; | ||
190 | } | ||
191 | if (TEST_RECORD_DATALEN != rd[0].data_size) | ||
192 | { | ||
193 | GNUNET_SCHEDULER_add_now(&endbadly, NULL); | ||
194 | GNUNET_break(0); | ||
195 | return; | ||
196 | } | ||
197 | if (0 != memcmp(&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN)) | ||
198 | { | ||
199 | GNUNET_SCHEDULER_add_now(&endbadly, NULL); | ||
200 | GNUNET_break(0); | ||
201 | return; | ||
202 | } | ||
203 | if (0 != (GNUNET_GNSRECORD_RF_SHADOW_RECORD & rd[0].flags)) | ||
204 | { | ||
205 | GNUNET_SCHEDULER_add_now(&endbadly, NULL); | ||
206 | GNUNET_break(0); | ||
207 | return; | ||
208 | } | ||
209 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
210 | "Block was decrypted successfully with former shadow record \n"); | ||
211 | GNUNET_SCHEDULER_add_now(&end, NULL); | ||
212 | } | 202 | } |
203 | if (0 != (GNUNET_GNSRECORD_RF_SHADOW_RECORD & rd[0].flags)) | ||
204 | { | ||
205 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
206 | GNUNET_break (0); | ||
207 | return; | ||
208 | } | ||
209 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
210 | "Block was decrypted successfully with former shadow record \n"); | ||
211 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
212 | } | ||
213 | } | 213 | } |
214 | 214 | ||
215 | 215 | ||
216 | static void | 216 | static void |
217 | name_lookup_active_proc(void *cls, | 217 | name_lookup_active_proc (void *cls, |
218 | const struct GNUNET_GNSRECORD_Block *block) | 218 | const struct GNUNET_GNSRECORD_Block *block) |
219 | { | 219 | { |
220 | struct GNUNET_GNSRECORD_Data *expected_rd = cls; | 220 | struct GNUNET_GNSRECORD_Data *expected_rd = cls; |
221 | 221 | ||
222 | GNUNET_assert(NULL != expected_rd); | 222 | GNUNET_assert (NULL != expected_rd); |
223 | 223 | ||
224 | ncqe = NULL; | 224 | ncqe = NULL; |
225 | ncqe_shadow = NULL; | 225 | ncqe_shadow = NULL; |
226 | if (endbadly_task != NULL) | 226 | if (endbadly_task != NULL) |
227 | { | 227 | { |
228 | GNUNET_SCHEDULER_cancel(endbadly_task); | 228 | GNUNET_SCHEDULER_cancel (endbadly_task); |
229 | endbadly_task = NULL; | 229 | endbadly_task = NULL; |
230 | } | 230 | } |
231 | 231 | ||
232 | if (NULL == block) | 232 | if (NULL == block) |
233 | { | 233 | { |
234 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 234 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
235 | _("Namestore returned no block\n")); | 235 | _ ("Namestore returned no block\n")); |
236 | if (endbadly_task != NULL) | 236 | if (endbadly_task != NULL) |
237 | GNUNET_SCHEDULER_cancel(endbadly_task); | 237 | GNUNET_SCHEDULER_cancel (endbadly_task); |
238 | endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 238 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
239 | return; | 239 | return; |
240 | } | 240 | } |
241 | 241 | ||
242 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 242 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
243 | "Namestore returned block, decrypting \n"); | 243 | "Namestore returned block, decrypting \n"); |
244 | GNUNET_assert(GNUNET_OK == GNUNET_GNSRECORD_block_decrypt(block, | 244 | GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_decrypt (block, |
245 | &pubkey, TEST_NAME, &rd_decrypt_cb, expected_rd)); | 245 | &pubkey, |
246 | TEST_NAME, | ||
247 | &rd_decrypt_cb, | ||
248 | expected_rd)); | ||
246 | } | 249 | } |
247 | 250 | ||
248 | 251 | ||
249 | static void | 252 | static void |
250 | name_lookup_shadow(void *cls) | 253 | name_lookup_shadow (void *cls) |
251 | { | 254 | { |
252 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 255 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
253 | "Performing lookup for shadow record \n"); | 256 | "Performing lookup for shadow record \n"); |
254 | delayed_lookup_task = NULL; | 257 | delayed_lookup_task = NULL; |
255 | ncqe_shadow = GNUNET_NAMECACHE_lookup_block(nch, &derived_hash, | 258 | ncqe_shadow = GNUNET_NAMECACHE_lookup_block (nch, &derived_hash, |
256 | &name_lookup_active_proc, &records[1]); | 259 | &name_lookup_active_proc, |
260 | &records[1]); | ||
257 | } | 261 | } |
258 | 262 | ||
259 | 263 | ||
260 | static void | 264 | static void |
261 | put_cont(void *cls, int32_t success, const char *emsg) | 265 | put_cont (void *cls, int32_t success, const char *emsg) |
262 | { | 266 | { |
263 | nsqe = NULL; | 267 | nsqe = NULL; |
264 | 268 | ||
265 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 269 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
266 | "Name store added record for `%s': %s\n", | 270 | "Name store added record for `%s': %s\n", |
267 | TEST_NAME, | 271 | TEST_NAME, |
268 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | 272 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); |
269 | 273 | ||
270 | /* Create derived hash */ | 274 | /* Create derived hash */ |
271 | GNUNET_CRYPTO_ecdsa_key_get_public(privkey, &pubkey); | 275 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); |
272 | GNUNET_GNSRECORD_query_from_public_key(&pubkey, TEST_NAME, &derived_hash); | 276 | GNUNET_GNSRECORD_query_from_public_key (&pubkey, TEST_NAME, &derived_hash); |
273 | 277 | ||
274 | if (0 == GNUNET_TIME_absolute_get_remaining(record_expiration).rel_value_us) | 278 | if (0 == GNUNET_TIME_absolute_get_remaining (record_expiration).rel_value_us) |
275 | { | 279 | { |
276 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 280 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
277 | "Test to too long to store records, cannot run test!\n"); | 281 | "Test to too long to store records, cannot run test!\n"); |
278 | GNUNET_SCHEDULER_add_now(&end, NULL); | 282 | GNUNET_SCHEDULER_add_now (&end, NULL); |
279 | return; | 283 | return; |
280 | } | 284 | } |
281 | /* Lookup active record now */ | 285 | /* Lookup active record now */ |
282 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 286 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
283 | "Performing lookup for active record \n"); | 287 | "Performing lookup for active record \n"); |
284 | ncqe = GNUNET_NAMECACHE_lookup_block(nch, &derived_hash, | 288 | ncqe = GNUNET_NAMECACHE_lookup_block (nch, &derived_hash, |
285 | &name_lookup_active_proc, &records[0]); | 289 | &name_lookup_active_proc, &records[0]); |
286 | 290 | ||
287 | delayed_lookup_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(EXPIRATION, 2), &name_lookup_shadow, NULL); | 291 | delayed_lookup_task = GNUNET_SCHEDULER_add_delayed ( |
292 | GNUNET_TIME_relative_multiply (EXPIRATION, 2), &name_lookup_shadow, NULL); | ||
288 | } | 293 | } |
289 | 294 | ||
290 | 295 | ||
291 | static void | 296 | static void |
292 | run(void *cls, | 297 | run (void *cls, |
293 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 298 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
294 | struct GNUNET_TESTING_Peer *peer) | 299 | struct GNUNET_TESTING_Peer *peer) |
295 | { | 300 | { |
296 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, | 301 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
297 | &endbadly, | 302 | &endbadly, |
298 | NULL); | 303 | NULL); |
299 | privkey = GNUNET_CRYPTO_ecdsa_key_create(); | 304 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); |
300 | GNUNET_assert(privkey != NULL); | 305 | GNUNET_assert (privkey != NULL); |
301 | GNUNET_CRYPTO_ecdsa_key_get_public(privkey, | 306 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, |
302 | &pubkey); | 307 | &pubkey); |
303 | 308 | ||
304 | record_expiration = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), | 309 | record_expiration = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), |
305 | EXPIRATION); | 310 | EXPIRATION); |
306 | records[0].expiration_time = record_expiration.abs_value_us; | 311 | records[0].expiration_time = record_expiration.abs_value_us; |
307 | records[0].record_type = TEST_RECORD_TYPE; | 312 | records[0].record_type = TEST_RECORD_TYPE; |
308 | records[0].data_size = TEST_RECORD_DATALEN; | 313 | records[0].data_size = TEST_RECORD_DATALEN; |
309 | records[0].data = GNUNET_malloc(TEST_RECORD_DATALEN); | 314 | records[0].data = GNUNET_malloc (TEST_RECORD_DATALEN); |
310 | records[0].flags = GNUNET_GNSRECORD_RF_NONE; | 315 | records[0].flags = GNUNET_GNSRECORD_RF_NONE; |
311 | memset((char *)records[0].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); | 316 | memset ((char *) records[0].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); |
312 | 317 | ||
313 | records[1].expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; | 318 | records[1].expiration_time = GNUNET_TIME_absolute_get ().abs_value_us |
319 | + 1000000000; | ||
314 | records[1].record_type = TEST_RECORD_TYPE; | 320 | records[1].record_type = TEST_RECORD_TYPE; |
315 | records[1].data_size = TEST_RECORD_DATALEN; | 321 | records[1].data_size = TEST_RECORD_DATALEN; |
316 | records[1].data = GNUNET_malloc(TEST_RECORD_DATALEN); | 322 | records[1].data = GNUNET_malloc (TEST_RECORD_DATALEN); |
317 | records[1].flags = GNUNET_GNSRECORD_RF_SHADOW_RECORD; | 323 | records[1].flags = GNUNET_GNSRECORD_RF_SHADOW_RECORD; |
318 | memset((char *)records[1].data, TEST_SHADOW_RECORD_DATA, TEST_RECORD_DATALEN); | 324 | memset ((char *) records[1].data, TEST_SHADOW_RECORD_DATA, |
319 | 325 | TEST_RECORD_DATALEN); | |
320 | nsh = GNUNET_NAMESTORE_connect(cfg); | 326 | |
321 | nch = GNUNET_NAMECACHE_connect(cfg); | 327 | nsh = GNUNET_NAMESTORE_connect (cfg); |
322 | GNUNET_break(NULL != nsh); | 328 | nch = GNUNET_NAMECACHE_connect (cfg); |
323 | GNUNET_break(NULL != nch); | 329 | GNUNET_break (NULL != nsh); |
324 | nsqe = GNUNET_NAMESTORE_records_store(nsh, privkey, TEST_NAME, | 330 | GNUNET_break (NULL != nch); |
325 | 2, records, &put_cont, NULL); | 331 | nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, TEST_NAME, |
332 | 2, records, &put_cont, NULL); | ||
326 | if (NULL == nsqe) | 333 | if (NULL == nsqe) |
327 | { | 334 | { |
328 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 335 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
329 | _("Namestore cannot store no block\n")); | 336 | _ ("Namestore cannot store no block\n")); |
330 | } | 337 | } |
331 | 338 | ||
332 | GNUNET_free((void *)records[0].data); | 339 | GNUNET_free ((void *) records[0].data); |
333 | GNUNET_free((void *)records[1].data); | 340 | GNUNET_free ((void *) records[1].data); |
334 | } | 341 | } |
335 | 342 | ||
336 | 343 | ||
@@ -338,24 +345,24 @@ run(void *cls, | |||
338 | 345 | ||
339 | 346 | ||
340 | int | 347 | int |
341 | main(int argc, char *argv[]) | 348 | main (int argc, char *argv[]) |
342 | { | 349 | { |
343 | const char *plugin_name; | 350 | const char *plugin_name; |
344 | char *cfg_name; | 351 | char *cfg_name; |
345 | 352 | ||
346 | SETUP_CFG(plugin_name, cfg_name); | 353 | SETUP_CFG (plugin_name, cfg_name); |
347 | res = 1; | 354 | res = 1; |
348 | if (0 != | 355 | if (0 != |
349 | GNUNET_TESTING_peer_run("test-namestore-api-lookup-shadow-filter", | 356 | GNUNET_TESTING_peer_run ("test-namestore-api-lookup-shadow-filter", |
350 | cfg_name, | 357 | cfg_name, |
351 | &run, | 358 | &run, |
352 | NULL)) | 359 | NULL)) |
353 | { | 360 | { |
354 | res = 1; | 361 | res = 1; |
355 | } | 362 | } |
356 | GNUNET_DISK_purge_cfg_dir(cfg_name, | 363 | GNUNET_DISK_purge_cfg_dir (cfg_name, |
357 | "GNUNET_TEST_HOME"); | 364 | "GNUNET_TEST_HOME"); |
358 | GNUNET_free(cfg_name); | 365 | GNUNET_free (cfg_name); |
359 | return res; | 366 | return res; |
360 | } | 367 | } |
361 | 368 | ||
diff --git a/src/namestore/test_namestore_api_monitoring.c b/src/namestore/test_namestore_api_monitoring.c index f1ee980cc..f7271cd76 100644 --- a/src/namestore/test_namestore_api_monitoring.c +++ b/src/namestore/test_namestore_api_monitoring.c | |||
@@ -31,94 +31,94 @@ | |||
31 | 31 | ||
32 | 32 | ||
33 | 33 | ||
34 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100) | 34 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) |
35 | 35 | ||
36 | 36 | ||
37 | static struct GNUNET_NAMESTORE_Handle * nsh; | 37 | static struct GNUNET_NAMESTORE_Handle *nsh; |
38 | 38 | ||
39 | static struct GNUNET_SCHEDULER_Task * endbadly_task; | 39 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
40 | 40 | ||
41 | static struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey; | 41 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; |
42 | 42 | ||
43 | static struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey2; | 43 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey2; |
44 | 44 | ||
45 | static struct GNUNET_NAMESTORE_ZoneMonitor *zm; | 45 | static struct GNUNET_NAMESTORE_ZoneMonitor *zm; |
46 | 46 | ||
47 | static int res; | 47 | static int res; |
48 | 48 | ||
49 | static char * s_name_1; | 49 | static char *s_name_1; |
50 | 50 | ||
51 | static struct GNUNET_GNSRECORD_Data *s_rd_1; | 51 | static struct GNUNET_GNSRECORD_Data *s_rd_1; |
52 | 52 | ||
53 | static char * s_name_2; | 53 | static char *s_name_2; |
54 | 54 | ||
55 | static struct GNUNET_GNSRECORD_Data *s_rd_2; | 55 | static struct GNUNET_GNSRECORD_Data *s_rd_2; |
56 | 56 | ||
57 | static char * s_name_3; | 57 | static char *s_name_3; |
58 | 58 | ||
59 | static struct GNUNET_GNSRECORD_Data *s_rd_3; | 59 | static struct GNUNET_GNSRECORD_Data *s_rd_3; |
60 | 60 | ||
61 | struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3]; | 61 | struct GNUNET_NAMESTORE_QueueEntry *ns_ops[3]; |
62 | 62 | ||
63 | 63 | ||
64 | static void | 64 | static void |
65 | do_shutdown() | 65 | do_shutdown () |
66 | { | 66 | { |
67 | if (NULL != zm) | 67 | if (NULL != zm) |
68 | { | 68 | { |
69 | GNUNET_NAMESTORE_zone_monitor_stop(zm); | 69 | GNUNET_NAMESTORE_zone_monitor_stop (zm); |
70 | zm = NULL; | 70 | zm = NULL; |
71 | } | 71 | } |
72 | if (NULL != ns_ops[0]) | 72 | if (NULL != ns_ops[0]) |
73 | { | 73 | { |
74 | GNUNET_NAMESTORE_cancel(ns_ops[0]); | 74 | GNUNET_NAMESTORE_cancel (ns_ops[0]); |
75 | ns_ops[0] = NULL; | 75 | ns_ops[0] = NULL; |
76 | } | 76 | } |
77 | if (NULL != ns_ops[1]) | 77 | if (NULL != ns_ops[1]) |
78 | { | 78 | { |
79 | GNUNET_NAMESTORE_cancel(ns_ops[1]); | 79 | GNUNET_NAMESTORE_cancel (ns_ops[1]); |
80 | ns_ops[1] = NULL; | 80 | ns_ops[1] = NULL; |
81 | } | 81 | } |
82 | if (NULL != ns_ops[2]) | 82 | if (NULL != ns_ops[2]) |
83 | { | 83 | { |
84 | GNUNET_NAMESTORE_cancel(ns_ops[2]); | 84 | GNUNET_NAMESTORE_cancel (ns_ops[2]); |
85 | ns_ops[2] = NULL; | 85 | ns_ops[2] = NULL; |
86 | } | 86 | } |
87 | if (NULL != nsh) | 87 | if (NULL != nsh) |
88 | { | 88 | { |
89 | GNUNET_NAMESTORE_disconnect(nsh); | 89 | GNUNET_NAMESTORE_disconnect (nsh); |
90 | nsh = NULL; | 90 | nsh = NULL; |
91 | } | 91 | } |
92 | GNUNET_free_non_null(s_name_1); | 92 | GNUNET_free_non_null (s_name_1); |
93 | GNUNET_free_non_null(s_name_2); | 93 | GNUNET_free_non_null (s_name_2); |
94 | GNUNET_free_non_null(s_name_3); | 94 | GNUNET_free_non_null (s_name_3); |
95 | 95 | ||
96 | if (s_rd_1 != NULL) | 96 | if (s_rd_1 != NULL) |
97 | { | 97 | { |
98 | GNUNET_free((void *)s_rd_1->data); | 98 | GNUNET_free ((void *) s_rd_1->data); |
99 | GNUNET_free(s_rd_1); | 99 | GNUNET_free (s_rd_1); |
100 | } | 100 | } |
101 | if (s_rd_2 != NULL) | 101 | if (s_rd_2 != NULL) |
102 | { | 102 | { |
103 | GNUNET_free((void *)s_rd_2->data); | 103 | GNUNET_free ((void *) s_rd_2->data); |
104 | GNUNET_free(s_rd_2); | 104 | GNUNET_free (s_rd_2); |
105 | } | 105 | } |
106 | if (s_rd_3 != NULL) | 106 | if (s_rd_3 != NULL) |
107 | { | 107 | { |
108 | GNUNET_free((void *)s_rd_3->data); | 108 | GNUNET_free ((void *) s_rd_3->data); |
109 | GNUNET_free(s_rd_3); | 109 | GNUNET_free (s_rd_3); |
110 | } | 110 | } |
111 | 111 | ||
112 | if (NULL != privkey) | 112 | if (NULL != privkey) |
113 | { | 113 | { |
114 | GNUNET_free(privkey); | 114 | GNUNET_free (privkey); |
115 | privkey = NULL; | 115 | privkey = NULL; |
116 | } | 116 | } |
117 | if (NULL != privkey2) | 117 | if (NULL != privkey2) |
118 | { | 118 | { |
119 | GNUNET_free(privkey2); | 119 | GNUNET_free (privkey2); |
120 | privkey2 = NULL; | 120 | privkey2 = NULL; |
121 | } | 121 | } |
122 | } | 122 | } |
123 | 123 | ||
124 | 124 | ||
@@ -128,237 +128,238 @@ do_shutdown() | |||
128 | * @param cls handle to use to re-connect. | 128 | * @param cls handle to use to re-connect. |
129 | */ | 129 | */ |
130 | static void | 130 | static void |
131 | endbadly(void *cls) | 131 | endbadly (void *cls) |
132 | { | 132 | { |
133 | do_shutdown(); | 133 | do_shutdown (); |
134 | res = 1; | 134 | res = 1; |
135 | } | 135 | } |
136 | 136 | ||
137 | 137 | ||
138 | static void | 138 | static void |
139 | end(void *cls) | 139 | end (void *cls) |
140 | { | 140 | { |
141 | do_shutdown(); | 141 | do_shutdown (); |
142 | res = 0; | 142 | res = 0; |
143 | } | 143 | } |
144 | 144 | ||
145 | 145 | ||
146 | static void | 146 | static void |
147 | zone_proc(void *cls, | 147 | zone_proc (void *cls, |
148 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 148 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, |
149 | const char *name, | 149 | const char *name, |
150 | unsigned int rd_count, | 150 | unsigned int rd_count, |
151 | const struct GNUNET_GNSRECORD_Data *rd) | 151 | const struct GNUNET_GNSRECORD_Data *rd) |
152 | { | 152 | { |
153 | static int returned_records; | 153 | static int returned_records; |
154 | static int fail = GNUNET_NO; | 154 | static int fail = GNUNET_NO; |
155 | 155 | ||
156 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 156 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
157 | "Comparing results name %s\n", | 157 | "Comparing results name %s\n", |
158 | name); | 158 | name); |
159 | if (0 != GNUNET_memcmp(zone_key, | 159 | if (0 != GNUNET_memcmp (zone_key, |
160 | privkey)) | 160 | privkey)) |
161 | { | 161 | { |
162 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
163 | "Monitoring returned wrong zone key\n"); | 163 | "Monitoring returned wrong zone key\n"); |
164 | GNUNET_break(0); | 164 | GNUNET_break (0); |
165 | GNUNET_SCHEDULER_cancel(endbadly_task); | 165 | GNUNET_SCHEDULER_cancel (endbadly_task); |
166 | endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 166 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
167 | return; | 167 | return; |
168 | } | 168 | } |
169 | 169 | ||
170 | if (0 == strcmp(name, s_name_1)) | 170 | if (0 == strcmp (name, s_name_1)) |
171 | { | 171 | { |
172 | if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_1)) | 172 | if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_1)) |
173 | { | ||
174 | GNUNET_break(0); | ||
175 | fail = GNUNET_YES; | ||
176 | } | ||
177 | } | ||
178 | else if (0 == strcmp(name, s_name_2)) | ||
179 | { | 173 | { |
180 | if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_2)) | 174 | GNUNET_break (0); |
181 | { | 175 | fail = GNUNET_YES; |
182 | GNUNET_break(0); | ||
183 | fail = GNUNET_YES; | ||
184 | } | ||
185 | } | 176 | } |
186 | else | 177 | } |
178 | else if (0 == strcmp (name, s_name_2)) | ||
179 | { | ||
180 | if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_2)) | ||
187 | { | 181 | { |
188 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 182 | GNUNET_break (0); |
189 | "Invalid name %s\n", | ||
190 | name); | ||
191 | GNUNET_break(0); | ||
192 | fail = GNUNET_YES; | 183 | fail = GNUNET_YES; |
193 | } | 184 | } |
194 | GNUNET_NAMESTORE_zone_monitor_next(zm, | 185 | } |
195 | 1); | 186 | else |
187 | { | ||
188 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
189 | "Invalid name %s\n", | ||
190 | name); | ||
191 | GNUNET_break (0); | ||
192 | fail = GNUNET_YES; | ||
193 | } | ||
194 | GNUNET_NAMESTORE_zone_monitor_next (zm, | ||
195 | 1); | ||
196 | if (2 == ++returned_records) | 196 | if (2 == ++returned_records) |
197 | { | ||
198 | if (endbadly_task != NULL) | ||
197 | { | 199 | { |
198 | if (endbadly_task != NULL) | 200 | GNUNET_SCHEDULER_cancel (endbadly_task); |
199 | { | 201 | endbadly_task = NULL; |
200 | GNUNET_SCHEDULER_cancel(endbadly_task); | ||
201 | endbadly_task = NULL; | ||
202 | } | ||
203 | if (GNUNET_YES == fail) | ||
204 | GNUNET_SCHEDULER_add_now(&endbadly, NULL); | ||
205 | else | ||
206 | GNUNET_SCHEDULER_add_now(&end, NULL); | ||
207 | } | 202 | } |
203 | if (GNUNET_YES == fail) | ||
204 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
205 | else | ||
206 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
207 | } | ||
208 | } | 208 | } |
209 | 209 | ||
210 | 210 | ||
211 | static void | 211 | static void |
212 | put_cont(void *cls, | 212 | put_cont (void *cls, |
213 | int32_t success, | 213 | int32_t success, |
214 | const char *emsg) | 214 | const char *emsg) |
215 | { | 215 | { |
216 | static int c = 0; | 216 | static int c = 0; |
217 | char *label = cls; | 217 | char *label = cls; |
218 | 218 | ||
219 | if (0 == strcmp(label, s_name_1)) | 219 | if (0 == strcmp (label, s_name_1)) |
220 | ns_ops[0] = NULL; | 220 | ns_ops[0] = NULL; |
221 | else if (0 == strcmp(label, s_name_2)) | 221 | else if (0 == strcmp (label, s_name_2)) |
222 | ns_ops[1] = NULL; | 222 | ns_ops[1] = NULL; |
223 | else if (0 == strcmp(label, s_name_3)) | 223 | else if (0 == strcmp (label, s_name_3)) |
224 | ns_ops[2] = NULL; | 224 | ns_ops[2] = NULL; |
225 | 225 | ||
226 | if (success == GNUNET_OK) | 226 | if (success == GNUNET_OK) |
227 | { | 227 | { |
228 | c++; | 228 | c++; |
229 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 229 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
230 | "Created record %u: `%s'\n", | 230 | "Created record %u: `%s'\n", |
231 | c, | 231 | c, |
232 | label); | 232 | label); |
233 | } | 233 | } |
234 | else | 234 | else |
235 | { | 235 | { |
236 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 236 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
237 | "Failed to create record `%s'\n", | 237 | "Failed to create record `%s'\n", |
238 | label); | 238 | label); |
239 | GNUNET_break(0); | 239 | GNUNET_break (0); |
240 | GNUNET_SCHEDULER_cancel(endbadly_task); | 240 | GNUNET_SCHEDULER_cancel (endbadly_task); |
241 | endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, | 241 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, |
242 | NULL); | 242 | NULL); |
243 | } | 243 | } |
244 | } | 244 | } |
245 | 245 | ||
246 | 246 | ||
247 | static struct GNUNET_GNSRECORD_Data * | 247 | static struct GNUNET_GNSRECORD_Data * |
248 | create_record(unsigned int count) | 248 | create_record (unsigned int count) |
249 | { | 249 | { |
250 | struct GNUNET_GNSRECORD_Data *rd; | 250 | struct GNUNET_GNSRECORD_Data *rd; |
251 | 251 | ||
252 | rd = GNUNET_new_array(count, | 252 | rd = GNUNET_new_array (count, |
253 | struct GNUNET_GNSRECORD_Data); | 253 | struct GNUNET_GNSRECORD_Data); |
254 | for (unsigned int c = 0; c < count; c++) | 254 | for (unsigned int c = 0; c < count; c++) |
255 | { | 255 | { |
256 | rd[c].expiration_time = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS).abs_value_us; | 256 | rd[c].expiration_time = GNUNET_TIME_relative_to_absolute ( |
257 | rd[c].record_type = TEST_RECORD_TYPE; | 257 | GNUNET_TIME_UNIT_HOURS).abs_value_us; |
258 | rd[c].data_size = 50; | 258 | rd[c].record_type = TEST_RECORD_TYPE; |
259 | rd[c].data = GNUNET_malloc(50); | 259 | rd[c].data_size = 50; |
260 | rd[c].flags = 0; | 260 | rd[c].data = GNUNET_malloc (50); |
261 | memset((char *)rd[c].data, 'a', 50); | 261 | rd[c].flags = 0; |
262 | } | 262 | memset ((char *) rd[c].data, 'a', 50); |
263 | } | ||
263 | return rd; | 264 | return rd; |
264 | } | 265 | } |
265 | 266 | ||
266 | 267 | ||
267 | static void | 268 | static void |
268 | fail_cb(void *cls) | 269 | fail_cb (void *cls) |
269 | { | 270 | { |
270 | GNUNET_assert(0); | 271 | GNUNET_assert (0); |
271 | } | 272 | } |
272 | 273 | ||
273 | 274 | ||
274 | static void | 275 | static void |
275 | sync_cb(void *cls) | 276 | sync_cb (void *cls) |
276 | { | 277 | { |
277 | /* do nothing */ | 278 | /* do nothing */ |
278 | } | 279 | } |
279 | 280 | ||
280 | 281 | ||
281 | static void | 282 | static void |
282 | run(void *cls, | 283 | run (void *cls, |
283 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 284 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
284 | struct GNUNET_TESTING_Peer *peer) | 285 | struct GNUNET_TESTING_Peer *peer) |
285 | { | 286 | { |
286 | res = 1; | 287 | res = 1; |
287 | privkey = GNUNET_CRYPTO_ecdsa_key_create(); | 288 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); |
288 | GNUNET_assert(privkey != NULL); | 289 | GNUNET_assert (privkey != NULL); |
289 | 290 | ||
290 | /* Start monitoring */ | 291 | /* Start monitoring */ |
291 | zm = GNUNET_NAMESTORE_zone_monitor_start(cfg, | 292 | zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, |
292 | privkey, | 293 | privkey, |
293 | GNUNET_YES, | 294 | GNUNET_YES, |
294 | &fail_cb, | 295 | &fail_cb, |
295 | NULL, | 296 | NULL, |
296 | &zone_proc, | 297 | &zone_proc, |
297 | NULL, | 298 | NULL, |
298 | &sync_cb, | 299 | &sync_cb, |
299 | NULL); | 300 | NULL); |
300 | if (NULL == zm) | 301 | if (NULL == zm) |
301 | { | 302 | { |
302 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 303 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
303 | "Failed to create zone monitor\n"); | 304 | "Failed to create zone monitor\n"); |
304 | GNUNET_break(0); | 305 | GNUNET_break (0); |
305 | endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 306 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
306 | return; | 307 | return; |
307 | } | 308 | } |
308 | 309 | ||
309 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &endbadly, NULL); | 310 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL); |
310 | /* Connect to namestore */ | 311 | /* Connect to namestore */ |
311 | nsh = GNUNET_NAMESTORE_connect(cfg); | 312 | nsh = GNUNET_NAMESTORE_connect (cfg); |
312 | if (NULL == nsh) | 313 | if (NULL == nsh) |
313 | { | 314 | { |
314 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Connect to namestore\n"); | 315 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connect to namestore\n"); |
315 | GNUNET_break(0); | 316 | GNUNET_break (0); |
316 | endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 317 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
317 | return; | 318 | return; |
318 | } | 319 | } |
319 | 320 | ||
320 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create(); | 321 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create (); |
321 | GNUNET_assert(privkey2 != NULL); | 322 | GNUNET_assert (privkey2 != NULL); |
322 | 323 | ||
323 | 324 | ||
324 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 325 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
325 | "Created record 3\n"); | 326 | "Created record 3\n"); |
326 | /* name in different zone */ | 327 | /* name in different zone */ |
327 | GNUNET_asprintf(&s_name_3, "dummy3"); | 328 | GNUNET_asprintf (&s_name_3, "dummy3"); |
328 | s_rd_3 = create_record(1); | 329 | s_rd_3 = create_record (1); |
329 | GNUNET_assert(NULL != (ns_ops[2] = | 330 | GNUNET_assert (NULL != (ns_ops[2] = |
330 | GNUNET_NAMESTORE_records_store(nsh, | 331 | GNUNET_NAMESTORE_records_store (nsh, |
331 | privkey2, | 332 | privkey2, |
332 | s_name_3, | 333 | s_name_3, |
333 | 1, | 334 | 1, |
334 | s_rd_3, | 335 | s_rd_3, |
335 | &put_cont, | 336 | &put_cont, |
336 | s_name_3))); | 337 | s_name_3))); |
337 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 338 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
338 | "Created record 1\n"); | 339 | "Created record 1\n"); |
339 | GNUNET_asprintf(&s_name_1, "dummy1"); | 340 | GNUNET_asprintf (&s_name_1, "dummy1"); |
340 | s_rd_1 = create_record(1); | 341 | s_rd_1 = create_record (1); |
341 | GNUNET_assert(NULL != (ns_ops[0] = | 342 | GNUNET_assert (NULL != (ns_ops[0] = |
342 | GNUNET_NAMESTORE_records_store(nsh, | 343 | GNUNET_NAMESTORE_records_store (nsh, |
343 | privkey, | 344 | privkey, |
344 | s_name_1, | 345 | s_name_1, |
345 | 1, | 346 | 1, |
346 | s_rd_1, | 347 | s_rd_1, |
347 | &put_cont, | 348 | &put_cont, |
348 | s_name_1))); | 349 | s_name_1))); |
349 | 350 | ||
350 | 351 | ||
351 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n"); | 352 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n"); |
352 | GNUNET_asprintf(&s_name_2, "dummy2"); | 353 | GNUNET_asprintf (&s_name_2, "dummy2"); |
353 | s_rd_2 = create_record(1); | 354 | s_rd_2 = create_record (1); |
354 | GNUNET_assert(NULL != (ns_ops[1] = | 355 | GNUNET_assert (NULL != (ns_ops[1] = |
355 | GNUNET_NAMESTORE_records_store(nsh, | 356 | GNUNET_NAMESTORE_records_store (nsh, |
356 | privkey, | 357 | privkey, |
357 | s_name_2, | 358 | s_name_2, |
358 | 1, | 359 | 1, |
359 | s_rd_2, | 360 | s_rd_2, |
360 | &put_cont, | 361 | &put_cont, |
361 | s_name_2))); | 362 | s_name_2))); |
362 | } | 363 | } |
363 | 364 | ||
364 | 365 | ||
@@ -366,25 +367,25 @@ run(void *cls, | |||
366 | 367 | ||
367 | 368 | ||
368 | int | 369 | int |
369 | main(int argc, | 370 | main (int argc, |
370 | char *argv[]) | 371 | char *argv[]) |
371 | { | 372 | { |
372 | const char *plugin_name; | 373 | const char *plugin_name; |
373 | char *cfg_name; | 374 | char *cfg_name; |
374 | 375 | ||
375 | SETUP_CFG(plugin_name, cfg_name); | 376 | SETUP_CFG (plugin_name, cfg_name); |
376 | res = 1; | 377 | res = 1; |
377 | if (0 != | 378 | if (0 != |
378 | GNUNET_TESTING_peer_run("test-namestore-api-monitoring", | 379 | GNUNET_TESTING_peer_run ("test-namestore-api-monitoring", |
379 | cfg_name, | 380 | cfg_name, |
380 | &run, | 381 | &run, |
381 | NULL)) | 382 | NULL)) |
382 | { | 383 | { |
383 | res = 1; | 384 | res = 1; |
384 | } | 385 | } |
385 | GNUNET_DISK_purge_cfg_dir(cfg_name, | 386 | GNUNET_DISK_purge_cfg_dir (cfg_name, |
386 | "GNUNET_TEST_HOME"); | 387 | "GNUNET_TEST_HOME"); |
387 | GNUNET_free(cfg_name); | 388 | GNUNET_free (cfg_name); |
388 | return res; | 389 | return res; |
389 | } | 390 | } |
390 | 391 | ||
diff --git a/src/namestore/test_namestore_api_monitoring_existing.c b/src/namestore/test_namestore_api_monitoring_existing.c index 97432b2a2..a0951b943 100644 --- a/src/namestore/test_namestore_api_monitoring_existing.c +++ b/src/namestore/test_namestore_api_monitoring_existing.c | |||
@@ -30,35 +30,35 @@ | |||
30 | #define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT | 30 | #define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT |
31 | 31 | ||
32 | 32 | ||
33 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) | 33 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
34 | 34 | ||
35 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | 35 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
36 | 36 | ||
37 | static struct GNUNET_NAMESTORE_Handle * nsh; | 37 | static struct GNUNET_NAMESTORE_Handle *nsh; |
38 | 38 | ||
39 | static struct GNUNET_SCHEDULER_Task * endbadly_task; | 39 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
40 | 40 | ||
41 | static struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey; | 41 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; |
42 | 42 | ||
43 | static struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey2; | 43 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey2; |
44 | 44 | ||
45 | static struct GNUNET_NAMESTORE_ZoneMonitor *zm; | 45 | static struct GNUNET_NAMESTORE_ZoneMonitor *zm; |
46 | 46 | ||
47 | static int res; | 47 | static int res; |
48 | 48 | ||
49 | static const char * s_name_1; | 49 | static const char *s_name_1; |
50 | 50 | ||
51 | static struct GNUNET_GNSRECORD_Data *s_rd_1; | 51 | static struct GNUNET_GNSRECORD_Data *s_rd_1; |
52 | 52 | ||
53 | static const char * s_name_2; | 53 | static const char *s_name_2; |
54 | 54 | ||
55 | static struct GNUNET_GNSRECORD_Data *s_rd_2; | 55 | static struct GNUNET_GNSRECORD_Data *s_rd_2; |
56 | 56 | ||
57 | static const char * s_name_3; | 57 | static const char *s_name_3; |
58 | 58 | ||
59 | static struct GNUNET_GNSRECORD_Data *s_rd_3; | 59 | static struct GNUNET_GNSRECORD_Data *s_rd_3; |
60 | 60 | ||
61 | struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3]; | 61 | struct GNUNET_NAMESTORE_QueueEntry *ns_ops[3]; |
62 | 62 | ||
63 | 63 | ||
64 | /** | 64 | /** |
@@ -67,311 +67,312 @@ struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3]; | |||
67 | * @param cls handle to use to re-connect. | 67 | * @param cls handle to use to re-connect. |
68 | */ | 68 | */ |
69 | static void | 69 | static void |
70 | endbadly(void *cls) | 70 | endbadly (void *cls) |
71 | { | 71 | { |
72 | endbadly_task = NULL; | 72 | endbadly_task = NULL; |
73 | GNUNET_break(0); | 73 | GNUNET_break (0); |
74 | GNUNET_SCHEDULER_shutdown(); | 74 | GNUNET_SCHEDULER_shutdown (); |
75 | res = 1; | 75 | res = 1; |
76 | } | 76 | } |
77 | 77 | ||
78 | 78 | ||
79 | static void | 79 | static void |
80 | end(void *cls) | 80 | end (void *cls) |
81 | { | 81 | { |
82 | if (NULL != zm) | 82 | if (NULL != zm) |
83 | { | 83 | { |
84 | GNUNET_NAMESTORE_zone_monitor_stop(zm); | 84 | GNUNET_NAMESTORE_zone_monitor_stop (zm); |
85 | zm = NULL; | 85 | zm = NULL; |
86 | } | 86 | } |
87 | if (NULL != ns_ops[0]) | 87 | if (NULL != ns_ops[0]) |
88 | { | 88 | { |
89 | GNUNET_NAMESTORE_cancel(ns_ops[0]); | 89 | GNUNET_NAMESTORE_cancel (ns_ops[0]); |
90 | ns_ops[0] = NULL; | 90 | ns_ops[0] = NULL; |
91 | } | 91 | } |
92 | if (NULL != ns_ops[1]) | 92 | if (NULL != ns_ops[1]) |
93 | { | 93 | { |
94 | GNUNET_NAMESTORE_cancel(ns_ops[1]); | 94 | GNUNET_NAMESTORE_cancel (ns_ops[1]); |
95 | ns_ops[1] = NULL; | 95 | ns_ops[1] = NULL; |
96 | } | 96 | } |
97 | if (NULL != ns_ops[2]) | 97 | if (NULL != ns_ops[2]) |
98 | { | 98 | { |
99 | GNUNET_NAMESTORE_cancel(ns_ops[2]); | 99 | GNUNET_NAMESTORE_cancel (ns_ops[2]); |
100 | ns_ops[2] = NULL; | 100 | ns_ops[2] = NULL; |
101 | } | 101 | } |
102 | if (NULL != endbadly_task) | 102 | if (NULL != endbadly_task) |
103 | { | 103 | { |
104 | GNUNET_SCHEDULER_cancel(endbadly_task); | 104 | GNUNET_SCHEDULER_cancel (endbadly_task); |
105 | endbadly_task = NULL; | 105 | endbadly_task = NULL; |
106 | } | 106 | } |
107 | if (NULL != nsh) | 107 | if (NULL != nsh) |
108 | { | 108 | { |
109 | GNUNET_NAMESTORE_disconnect(nsh); | 109 | GNUNET_NAMESTORE_disconnect (nsh); |
110 | nsh = NULL; | 110 | nsh = NULL; |
111 | } | 111 | } |
112 | if (NULL != s_rd_1) | 112 | if (NULL != s_rd_1) |
113 | { | 113 | { |
114 | GNUNET_free((void *)s_rd_1->data); | 114 | GNUNET_free ((void *) s_rd_1->data); |
115 | GNUNET_free(s_rd_1); | 115 | GNUNET_free (s_rd_1); |
116 | } | 116 | } |
117 | if (NULL != s_rd_2) | 117 | if (NULL != s_rd_2) |
118 | { | 118 | { |
119 | GNUNET_free((void *)s_rd_2->data); | 119 | GNUNET_free ((void *) s_rd_2->data); |
120 | GNUNET_free(s_rd_2); | 120 | GNUNET_free (s_rd_2); |
121 | } | 121 | } |
122 | if (NULL != s_rd_3) | 122 | if (NULL != s_rd_3) |
123 | { | 123 | { |
124 | GNUNET_free((void *)s_rd_3->data); | 124 | GNUNET_free ((void *) s_rd_3->data); |
125 | GNUNET_free(s_rd_3); | 125 | GNUNET_free (s_rd_3); |
126 | } | 126 | } |
127 | if (NULL != privkey) | 127 | if (NULL != privkey) |
128 | { | 128 | { |
129 | GNUNET_free(privkey); | 129 | GNUNET_free (privkey); |
130 | privkey = NULL; | 130 | privkey = NULL; |
131 | } | 131 | } |
132 | if (NULL != privkey2) | 132 | if (NULL != privkey2) |
133 | { | 133 | { |
134 | GNUNET_free(privkey2); | 134 | GNUNET_free (privkey2); |
135 | privkey2 = NULL; | 135 | privkey2 = NULL; |
136 | } | 136 | } |
137 | } | 137 | } |
138 | 138 | ||
139 | 139 | ||
140 | static void | 140 | static void |
141 | zone_proc(void *cls, | 141 | zone_proc (void *cls, |
142 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 142 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, |
143 | const char *name, | 143 | const char *name, |
144 | unsigned int rd_count, | 144 | unsigned int rd_count, |
145 | const struct GNUNET_GNSRECORD_Data *rd) | 145 | const struct GNUNET_GNSRECORD_Data *rd) |
146 | { | 146 | { |
147 | static int returned_records; | 147 | static int returned_records; |
148 | static int fail = GNUNET_NO; | 148 | static int fail = GNUNET_NO; |
149 | 149 | ||
150 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 150 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
151 | "Comparing results name %s\n", | 151 | "Comparing results name %s\n", |
152 | name); | 152 | name); |
153 | if (0 != GNUNET_memcmp(zone_key, | 153 | if (0 != GNUNET_memcmp (zone_key, |
154 | privkey)) | 154 | privkey)) |
155 | { | 155 | { |
156 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 156 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
157 | "Monitoring returned wrong zone key\n"); | 157 | "Monitoring returned wrong zone key\n"); |
158 | GNUNET_break(0); | 158 | GNUNET_break (0); |
159 | GNUNET_SCHEDULER_shutdown(); | 159 | GNUNET_SCHEDULER_shutdown (); |
160 | return; | 160 | return; |
161 | } | 161 | } |
162 | 162 | ||
163 | if (0 == strcmp(name, | 163 | if (0 == strcmp (name, |
164 | s_name_1)) | 164 | s_name_1)) |
165 | { | ||
166 | if (GNUNET_YES != | ||
167 | GNUNET_GNSRECORD_records_cmp (rd, | ||
168 | s_rd_1)) | ||
165 | { | 169 | { |
166 | if (GNUNET_YES != | 170 | GNUNET_break (0); |
167 | GNUNET_GNSRECORD_records_cmp(rd, | 171 | fail = GNUNET_YES; |
168 | s_rd_1)) | ||
169 | { | ||
170 | GNUNET_break(0); | ||
171 | fail = GNUNET_YES; | ||
172 | } | ||
173 | } | 172 | } |
174 | else if (0 == strcmp(name, | 173 | } |
175 | s_name_2)) | 174 | else if (0 == strcmp (name, |
175 | s_name_2)) | ||
176 | { | ||
177 | if (GNUNET_YES != | ||
178 | GNUNET_GNSRECORD_records_cmp (rd, | ||
179 | s_rd_2)) | ||
176 | { | 180 | { |
177 | if (GNUNET_YES != | 181 | GNUNET_break (0); |
178 | GNUNET_GNSRECORD_records_cmp(rd, | 182 | fail = GNUNET_YES; |
179 | s_rd_2)) | ||
180 | { | ||
181 | GNUNET_break(0); | ||
182 | fail = GNUNET_YES; | ||
183 | } | ||
184 | } | 183 | } |
184 | } | ||
185 | else | 185 | else |
186 | { | ||
187 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
188 | "Invalid name %s\n", | ||
189 | name); | ||
190 | GNUNET_break (0); | ||
191 | fail = GNUNET_YES; | ||
192 | } | ||
193 | GNUNET_NAMESTORE_zone_monitor_next (zm, | ||
194 | 1); | ||
195 | if (2 == ++returned_records) | ||
196 | { | ||
197 | GNUNET_SCHEDULER_shutdown (); | ||
198 | if (GNUNET_YES == fail) | ||
186 | { | 199 | { |
187 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 200 | GNUNET_break (0); |
188 | "Invalid name %s\n", | 201 | res = 1; |
189 | name); | ||
190 | GNUNET_break(0); | ||
191 | fail = GNUNET_YES; | ||
192 | } | 202 | } |
193 | GNUNET_NAMESTORE_zone_monitor_next(zm, | 203 | else |
194 | 1); | ||
195 | if (2 == ++returned_records) | ||
196 | { | 204 | { |
197 | GNUNET_SCHEDULER_shutdown(); | 205 | res = 0; |
198 | if (GNUNET_YES == fail) | ||
199 | { | ||
200 | GNUNET_break(0); | ||
201 | res = 1; | ||
202 | } | ||
203 | else | ||
204 | { | ||
205 | res = 0; | ||
206 | } | ||
207 | } | 206 | } |
207 | } | ||
208 | } | 208 | } |
209 | 209 | ||
210 | 210 | ||
211 | static void | 211 | static void |
212 | fail_cb(void *cls) | 212 | fail_cb (void *cls) |
213 | { | 213 | { |
214 | GNUNET_assert(0); | 214 | GNUNET_assert (0); |
215 | } | 215 | } |
216 | 216 | ||
217 | 217 | ||
218 | static void | 218 | static void |
219 | sync_cb(void *cls) | 219 | sync_cb (void *cls) |
220 | { | 220 | { |
221 | /* do nothing */ | 221 | /* do nothing */ |
222 | } | 222 | } |
223 | 223 | ||
224 | 224 | ||
225 | static void | 225 | static void |
226 | put_cont(void *cls, | 226 | put_cont (void *cls, |
227 | int32_t success, | 227 | int32_t success, |
228 | const char *emsg) | 228 | const char *emsg) |
229 | { | 229 | { |
230 | static int c = 0; | 230 | static int c = 0; |
231 | const char *label = cls; | 231 | const char *label = cls; |
232 | 232 | ||
233 | if (0 == strcmp(label, | 233 | if (0 == strcmp (label, |
234 | s_name_1)) | 234 | s_name_1)) |
235 | ns_ops[0] = NULL; | 235 | ns_ops[0] = NULL; |
236 | else if (0 == strcmp(label, | 236 | else if (0 == strcmp (label, |
237 | s_name_2)) | 237 | s_name_2)) |
238 | ns_ops[1] = NULL; | 238 | ns_ops[1] = NULL; |
239 | else if (0 == strcmp(label, | 239 | else if (0 == strcmp (label, |
240 | s_name_3)) | 240 | s_name_3)) |
241 | ns_ops[2] = NULL; | 241 | ns_ops[2] = NULL; |
242 | 242 | ||
243 | if (success == GNUNET_OK) | 243 | if (success == GNUNET_OK) |
244 | { | 244 | { |
245 | c++; | 245 | c++; |
246 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 246 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
247 | "Created record %u: `%s'\n", | 247 | "Created record %u: `%s'\n", |
248 | c, | 248 | c, |
249 | label); | 249 | label); |
250 | } | 250 | } |
251 | else | 251 | else |
252 | { | 252 | { |
253 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 253 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
254 | "Failed to created records\n"); | 254 | "Failed to created records\n"); |
255 | GNUNET_break(0); | 255 | GNUNET_break (0); |
256 | res = 1; | 256 | res = 1; |
257 | GNUNET_SCHEDULER_shutdown(); | 257 | GNUNET_SCHEDULER_shutdown (); |
258 | return; | 258 | return; |
259 | } | 259 | } |
260 | 260 | ||
261 | if (3 == c) | 261 | if (3 == c) |
262 | { | ||
263 | /* Start monitoring */ | ||
264 | zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, | ||
265 | privkey, | ||
266 | GNUNET_YES, | ||
267 | &fail_cb, | ||
268 | NULL, | ||
269 | &zone_proc, | ||
270 | NULL, | ||
271 | &sync_cb, | ||
272 | NULL); | ||
273 | if (NULL == zm) | ||
262 | { | 274 | { |
263 | /* Start monitoring */ | 275 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
264 | zm = GNUNET_NAMESTORE_zone_monitor_start(cfg, | 276 | "Failed to create zone monitor\n"); |
265 | privkey, | 277 | GNUNET_break (0); |
266 | GNUNET_YES, | 278 | res = 1; |
267 | &fail_cb, | 279 | GNUNET_SCHEDULER_shutdown (); |
268 | NULL, | 280 | return; |
269 | &zone_proc, | ||
270 | NULL, | ||
271 | &sync_cb, | ||
272 | NULL); | ||
273 | if (NULL == zm) | ||
274 | { | ||
275 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
276 | "Failed to create zone monitor\n"); | ||
277 | GNUNET_break(0); | ||
278 | res = 1; | ||
279 | GNUNET_SCHEDULER_shutdown(); | ||
280 | return; | ||
281 | } | ||
282 | } | 281 | } |
282 | } | ||
283 | } | 283 | } |
284 | 284 | ||
285 | 285 | ||
286 | static struct GNUNET_GNSRECORD_Data * | 286 | static struct GNUNET_GNSRECORD_Data * |
287 | create_record(unsigned int count) | 287 | create_record (unsigned int count) |
288 | { | 288 | { |
289 | struct GNUNET_GNSRECORD_Data *rd; | 289 | struct GNUNET_GNSRECORD_Data *rd; |
290 | 290 | ||
291 | rd = GNUNET_new_array(count, | 291 | rd = GNUNET_new_array (count, |
292 | struct GNUNET_GNSRECORD_Data); | 292 | struct GNUNET_GNSRECORD_Data); |
293 | for (unsigned int c = 0; c < count; c++) | 293 | for (unsigned int c = 0; c < count; c++) |
294 | { | 294 | { |
295 | rd[c].expiration_time = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS).abs_value_us; | 295 | rd[c].expiration_time = GNUNET_TIME_relative_to_absolute ( |
296 | rd[c].record_type = TEST_RECORD_TYPE; | 296 | GNUNET_TIME_UNIT_HOURS).abs_value_us; |
297 | rd[c].data_size = 50; | 297 | rd[c].record_type = TEST_RECORD_TYPE; |
298 | rd[c].data = GNUNET_malloc(50); | 298 | rd[c].data_size = 50; |
299 | rd[c].flags = 0; | 299 | rd[c].data = GNUNET_malloc (50); |
300 | memset((char *)rd[c].data, | 300 | rd[c].flags = 0; |
301 | 'a', | 301 | memset ((char *) rd[c].data, |
302 | 50); | 302 | 'a', |
303 | } | 303 | 50); |
304 | } | ||
304 | return rd; | 305 | return rd; |
305 | } | 306 | } |
306 | 307 | ||
307 | 308 | ||
308 | static void | 309 | static void |
309 | run(void *cls, | 310 | run (void *cls, |
310 | const struct GNUNET_CONFIGURATION_Handle *mycfg, | 311 | const struct GNUNET_CONFIGURATION_Handle *mycfg, |
311 | struct GNUNET_TESTING_Peer *peer) | 312 | struct GNUNET_TESTING_Peer *peer) |
312 | { | 313 | { |
313 | res = 1; | 314 | res = 1; |
314 | privkey = GNUNET_CRYPTO_ecdsa_key_create(); | 315 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); |
315 | GNUNET_assert(NULL != privkey); | 316 | GNUNET_assert (NULL != privkey); |
316 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create(); | 317 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create (); |
317 | GNUNET_assert(NULL != privkey2); | 318 | GNUNET_assert (NULL != privkey2); |
318 | 319 | ||
319 | cfg = mycfg; | 320 | cfg = mycfg; |
320 | GNUNET_SCHEDULER_add_shutdown(&end, | 321 | GNUNET_SCHEDULER_add_shutdown (&end, |
321 | NULL); | 322 | NULL); |
322 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, | 323 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
323 | &endbadly, | 324 | &endbadly, |
324 | NULL); | 325 | NULL); |
325 | /* Connect to namestore */ | 326 | /* Connect to namestore */ |
326 | nsh = GNUNET_NAMESTORE_connect(cfg); | 327 | nsh = GNUNET_NAMESTORE_connect (cfg); |
327 | if (NULL == nsh) | 328 | if (NULL == nsh) |
328 | { | 329 | { |
329 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 330 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
330 | "Connect to namestore failed\n"); | 331 | "Connect to namestore failed\n"); |
331 | GNUNET_break(0); | 332 | GNUNET_break (0); |
332 | endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, | 333 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, |
333 | NULL); | 334 | NULL); |
334 | return; | 335 | return; |
335 | } | 336 | } |
336 | 337 | ||
337 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 338 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
338 | "Created record 3\n"); | 339 | "Created record 3\n"); |
339 | /* name in different zone */ | 340 | /* name in different zone */ |
340 | s_name_3 = "dummy3"; | 341 | s_name_3 = "dummy3"; |
341 | s_rd_3 = create_record(1); | 342 | s_rd_3 = create_record (1); |
342 | GNUNET_assert(NULL != (ns_ops[2] = | 343 | GNUNET_assert (NULL != (ns_ops[2] = |
343 | GNUNET_NAMESTORE_records_store(nsh, | 344 | GNUNET_NAMESTORE_records_store (nsh, |
344 | privkey2, | 345 | privkey2, |
345 | s_name_3, | 346 | s_name_3, |
346 | 1, | 347 | 1, |
347 | s_rd_3, | 348 | s_rd_3, |
348 | &put_cont, | 349 | &put_cont, |
349 | (void *)s_name_3))); | 350 | (void *) s_name_3))); |
350 | 351 | ||
351 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 352 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
352 | "Created record 1\n"); | 353 | "Created record 1\n"); |
353 | s_name_1 = "dummy1"; | 354 | s_name_1 = "dummy1"; |
354 | s_rd_1 = create_record(1); | 355 | s_rd_1 = create_record (1); |
355 | GNUNET_assert(NULL != (ns_ops[0] = | 356 | GNUNET_assert (NULL != (ns_ops[0] = |
356 | GNUNET_NAMESTORE_records_store(nsh, | 357 | GNUNET_NAMESTORE_records_store (nsh, |
357 | privkey, | 358 | privkey, |
358 | s_name_1, | 359 | s_name_1, |
359 | 1, | 360 | 1, |
360 | s_rd_1, | 361 | s_rd_1, |
361 | &put_cont, | 362 | &put_cont, |
362 | (void *)s_name_1))); | 363 | (void *) s_name_1))); |
363 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 364 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
364 | "Created record 2 \n"); | 365 | "Created record 2 \n"); |
365 | s_name_2 = "dummy2"; | 366 | s_name_2 = "dummy2"; |
366 | s_rd_2 = create_record(1); | 367 | s_rd_2 = create_record (1); |
367 | GNUNET_assert(NULL != (ns_ops[1] = | 368 | GNUNET_assert (NULL != (ns_ops[1] = |
368 | GNUNET_NAMESTORE_records_store(nsh, | 369 | GNUNET_NAMESTORE_records_store (nsh, |
369 | privkey, | 370 | privkey, |
370 | s_name_2, | 371 | s_name_2, |
371 | 1, | 372 | 1, |
372 | s_rd_2, | 373 | s_rd_2, |
373 | &put_cont, | 374 | &put_cont, |
374 | (void *)s_name_2))); | 375 | (void *) s_name_2))); |
375 | } | 376 | } |
376 | 377 | ||
377 | 378 | ||
@@ -379,26 +380,26 @@ run(void *cls, | |||
379 | 380 | ||
380 | 381 | ||
381 | int | 382 | int |
382 | main(int argc, | 383 | main (int argc, |
383 | char *argv[]) | 384 | char *argv[]) |
384 | { | 385 | { |
385 | const char *plugin_name; | 386 | const char *plugin_name; |
386 | char *cfg_name; | 387 | char *cfg_name; |
387 | 388 | ||
388 | SETUP_CFG(plugin_name, cfg_name); | 389 | SETUP_CFG (plugin_name, cfg_name); |
389 | res = 1; | 390 | res = 1; |
390 | if (0 != | 391 | if (0 != |
391 | GNUNET_TESTING_peer_run("test-namestore-api-monitoring-existing", | 392 | GNUNET_TESTING_peer_run ("test-namestore-api-monitoring-existing", |
392 | cfg_name, | 393 | cfg_name, |
393 | &run, | 394 | &run, |
394 | NULL)) | 395 | NULL)) |
395 | { | 396 | { |
396 | GNUNET_break(0); | 397 | GNUNET_break (0); |
397 | res = 1; | 398 | res = 1; |
398 | } | 399 | } |
399 | GNUNET_DISK_purge_cfg_dir(cfg_name, | 400 | GNUNET_DISK_purge_cfg_dir (cfg_name, |
400 | "GNUNET_TEST_HOME"); | 401 | "GNUNET_TEST_HOME"); |
401 | GNUNET_free(cfg_name); | 402 | GNUNET_free (cfg_name); |
402 | return res; | 403 | return res; |
403 | } | 404 | } |
404 | 405 | ||
diff --git a/src/namestore/test_namestore_api_remove.c b/src/namestore/test_namestore_api_remove.c index b2334667e..10160cd13 100644 --- a/src/namestore/test_namestore_api_remove.c +++ b/src/namestore/test_namestore_api_remove.c | |||
@@ -32,12 +32,12 @@ | |||
32 | 32 | ||
33 | #define TEST_RECORD_DATA 'a' | 33 | #define TEST_RECORD_DATA 'a' |
34 | 34 | ||
35 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100) | 35 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) |
36 | 36 | ||
37 | 37 | ||
38 | static struct GNUNET_NAMESTORE_Handle *nsh; | 38 | static struct GNUNET_NAMESTORE_Handle *nsh; |
39 | 39 | ||
40 | static struct GNUNET_SCHEDULER_Task * endbadly_task; | 40 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
41 | 41 | ||
42 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 42 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; |
43 | 43 | ||
@@ -51,19 +51,19 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe; | |||
51 | 51 | ||
52 | 52 | ||
53 | static void | 53 | static void |
54 | cleanup() | 54 | cleanup () |
55 | { | 55 | { |
56 | if (NULL != nsh) | 56 | if (NULL != nsh) |
57 | { | 57 | { |
58 | GNUNET_NAMESTORE_disconnect(nsh); | 58 | GNUNET_NAMESTORE_disconnect (nsh); |
59 | nsh = NULL; | 59 | nsh = NULL; |
60 | } | 60 | } |
61 | if (NULL != privkey) | 61 | if (NULL != privkey) |
62 | { | 62 | { |
63 | GNUNET_free(privkey); | 63 | GNUNET_free (privkey); |
64 | privkey = NULL; | 64 | privkey = NULL; |
65 | } | 65 | } |
66 | GNUNET_SCHEDULER_shutdown(); | 66 | GNUNET_SCHEDULER_shutdown (); |
67 | } | 67 | } |
68 | 68 | ||
69 | 69 | ||
@@ -73,127 +73,127 @@ cleanup() | |||
73 | * @param cls handle to use to re-connect. | 73 | * @param cls handle to use to re-connect. |
74 | */ | 74 | */ |
75 | static void | 75 | static void |
76 | endbadly(void *cls) | 76 | endbadly (void *cls) |
77 | { | 77 | { |
78 | if (NULL != nsqe) | 78 | if (NULL != nsqe) |
79 | { | 79 | { |
80 | GNUNET_NAMESTORE_cancel(nsqe); | 80 | GNUNET_NAMESTORE_cancel (nsqe); |
81 | nsqe = NULL; | 81 | nsqe = NULL; |
82 | } | 82 | } |
83 | cleanup(); | 83 | cleanup (); |
84 | res = 1; | 84 | res = 1; |
85 | } | 85 | } |
86 | 86 | ||
87 | 87 | ||
88 | static void | 88 | static void |
89 | end(void *cls) | 89 | end (void *cls) |
90 | { | 90 | { |
91 | cleanup(); | 91 | cleanup (); |
92 | res = 0; | 92 | res = 0; |
93 | } | 93 | } |
94 | 94 | ||
95 | 95 | ||
96 | static void | 96 | static void |
97 | remove_cont(void *cls, | 97 | remove_cont (void *cls, |
98 | int32_t success, | 98 | int32_t success, |
99 | const char *emsg) | 99 | const char *emsg) |
100 | { | 100 | { |
101 | nsqe = NULL; | 101 | nsqe = NULL; |
102 | if (GNUNET_YES != success) | 102 | if (GNUNET_YES != success) |
103 | { | 103 | { |
104 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 104 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
105 | _("Records could not be removed: `%s'\n"), | 105 | _ ("Records could not be removed: `%s'\n"), |
106 | emsg); | 106 | emsg); |
107 | if (NULL != endbadly_task) | 107 | if (NULL != endbadly_task) |
108 | GNUNET_SCHEDULER_cancel(endbadly_task); | 108 | GNUNET_SCHEDULER_cancel (endbadly_task); |
109 | endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, | 109 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, |
110 | NULL); | 110 | NULL); |
111 | return; | 111 | return; |
112 | } | 112 | } |
113 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 113 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
114 | "Records were removed, perform lookup\n"); | 114 | "Records were removed, perform lookup\n"); |
115 | removed = GNUNET_YES; | 115 | removed = GNUNET_YES; |
116 | if (NULL != endbadly_task) | 116 | if (NULL != endbadly_task) |
117 | GNUNET_SCHEDULER_cancel(endbadly_task); | 117 | GNUNET_SCHEDULER_cancel (endbadly_task); |
118 | GNUNET_SCHEDULER_add_now(&end, NULL); | 118 | GNUNET_SCHEDULER_add_now (&end, NULL); |
119 | } | 119 | } |
120 | 120 | ||
121 | 121 | ||
122 | static void | 122 | static void |
123 | put_cont(void *cls, | 123 | put_cont (void *cls, |
124 | int32_t success, | 124 | int32_t success, |
125 | const char *emsg) | 125 | const char *emsg) |
126 | { | 126 | { |
127 | const char *name = cls; | 127 | const char *name = cls; |
128 | 128 | ||
129 | GNUNET_assert(NULL != cls); | 129 | GNUNET_assert (NULL != cls); |
130 | nsqe = NULL; | 130 | nsqe = NULL; |
131 | if (GNUNET_SYSERR == success) | 131 | if (GNUNET_SYSERR == success) |
132 | { | 132 | { |
133 | GNUNET_break(0); | 133 | GNUNET_break (0); |
134 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 134 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
135 | "Namestore could not store record: `%s'\n", | 135 | "Namestore could not store record: `%s'\n", |
136 | emsg); | 136 | emsg); |
137 | if (endbadly_task != NULL) | 137 | if (endbadly_task != NULL) |
138 | GNUNET_SCHEDULER_cancel(endbadly_task); | 138 | GNUNET_SCHEDULER_cancel (endbadly_task); |
139 | endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 139 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
140 | return; | 140 | return; |
141 | } | 141 | } |
142 | 142 | ||
143 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 143 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
144 | "Name store added record for `%s': %s\n", | 144 | "Name store added record for `%s': %s\n", |
145 | name, | 145 | name, |
146 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | 146 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); |
147 | nsqe = GNUNET_NAMESTORE_records_store(nsh, | 147 | nsqe = GNUNET_NAMESTORE_records_store (nsh, |
148 | privkey, | 148 | privkey, |
149 | name, | 149 | name, |
150 | 0, NULL, | 150 | 0, NULL, |
151 | &remove_cont, (void *)name); | 151 | &remove_cont, (void *) name); |
152 | } | 152 | } |
153 | 153 | ||
154 | 154 | ||
155 | static void | 155 | static void |
156 | run(void *cls, | 156 | run (void *cls, |
157 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 157 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
158 | struct GNUNET_TESTING_Peer *peer) | 158 | struct GNUNET_TESTING_Peer *peer) |
159 | { | 159 | { |
160 | struct GNUNET_GNSRECORD_Data rd; | 160 | struct GNUNET_GNSRECORD_Data rd; |
161 | const char * name = "dummy.dummy.gnunet"; | 161 | const char *name = "dummy.dummy.gnunet"; |
162 | 162 | ||
163 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, | 163 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
164 | &endbadly, | 164 | &endbadly, |
165 | NULL); | 165 | NULL); |
166 | privkey = GNUNET_CRYPTO_ecdsa_key_create(); | 166 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); |
167 | GNUNET_assert(privkey != NULL); | 167 | GNUNET_assert (privkey != NULL); |
168 | GNUNET_CRYPTO_ecdsa_key_get_public(privkey, | 168 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, |
169 | &pubkey); | 169 | &pubkey); |
170 | 170 | ||
171 | removed = GNUNET_NO; | 171 | removed = GNUNET_NO; |
172 | 172 | ||
173 | rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us; | 173 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us; |
174 | rd.record_type = TEST_RECORD_TYPE; | 174 | rd.record_type = TEST_RECORD_TYPE; |
175 | rd.data_size = TEST_RECORD_DATALEN; | 175 | rd.data_size = TEST_RECORD_DATALEN; |
176 | rd.data = GNUNET_malloc(TEST_RECORD_DATALEN); | 176 | rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); |
177 | rd.flags = 0; | 177 | rd.flags = 0; |
178 | memset((char *)rd.data, | 178 | memset ((char *) rd.data, |
179 | 'a', | 179 | 'a', |
180 | TEST_RECORD_DATALEN); | 180 | TEST_RECORD_DATALEN); |
181 | 181 | ||
182 | nsh = GNUNET_NAMESTORE_connect(cfg); | 182 | nsh = GNUNET_NAMESTORE_connect (cfg); |
183 | GNUNET_break(NULL != nsh); | 183 | GNUNET_break (NULL != nsh); |
184 | nsqe = GNUNET_NAMESTORE_records_store(nsh, | 184 | nsqe = GNUNET_NAMESTORE_records_store (nsh, |
185 | privkey, | 185 | privkey, |
186 | name, | 186 | name, |
187 | 1, | 187 | 1, |
188 | &rd, | 188 | &rd, |
189 | &put_cont, | 189 | &put_cont, |
190 | (void *)name); | 190 | (void *) name); |
191 | if (NULL == nsqe) | 191 | if (NULL == nsqe) |
192 | { | 192 | { |
193 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 193 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
194 | _("Namestore cannot store no block\n")); | 194 | _ ("Namestore cannot store no block\n")); |
195 | } | 195 | } |
196 | GNUNET_free((void *)rd.data); | 196 | GNUNET_free ((void *) rd.data); |
197 | } | 197 | } |
198 | 198 | ||
199 | 199 | ||
@@ -201,24 +201,24 @@ run(void *cls, | |||
201 | 201 | ||
202 | 202 | ||
203 | int | 203 | int |
204 | main(int argc, char *argv[]) | 204 | main (int argc, char *argv[]) |
205 | { | 205 | { |
206 | const char *plugin_name; | 206 | const char *plugin_name; |
207 | char *cfg_name; | 207 | char *cfg_name; |
208 | 208 | ||
209 | SETUP_CFG(plugin_name, cfg_name); | 209 | SETUP_CFG (plugin_name, cfg_name); |
210 | res = 1; | 210 | res = 1; |
211 | if (0 != | 211 | if (0 != |
212 | GNUNET_TESTING_peer_run("test-namestore-api-remove", | 212 | GNUNET_TESTING_peer_run ("test-namestore-api-remove", |
213 | cfg_name, | 213 | cfg_name, |
214 | &run, | 214 | &run, |
215 | NULL)) | 215 | NULL)) |
216 | { | 216 | { |
217 | res = 1; | 217 | res = 1; |
218 | } | 218 | } |
219 | GNUNET_DISK_purge_cfg_dir(cfg_name, | 219 | GNUNET_DISK_purge_cfg_dir (cfg_name, |
220 | "GNUNET_TEST_HOME"); | 220 | "GNUNET_TEST_HOME"); |
221 | GNUNET_free(cfg_name); | 221 | GNUNET_free (cfg_name); |
222 | return res; | 222 | return res; |
223 | } | 223 | } |
224 | 224 | ||
diff --git a/src/namestore/test_namestore_api_remove_not_existing_record.c b/src/namestore/test_namestore_api_remove_not_existing_record.c index fee06e3af..5558696a8 100644 --- a/src/namestore/test_namestore_api_remove_not_existing_record.c +++ b/src/namestore/test_namestore_api_remove_not_existing_record.c | |||
@@ -31,12 +31,12 @@ | |||
31 | 31 | ||
32 | #define TEST_RECORD_DATA 'a' | 32 | #define TEST_RECORD_DATA 'a' |
33 | 33 | ||
34 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100) | 34 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) |
35 | 35 | ||
36 | 36 | ||
37 | static struct GNUNET_NAMESTORE_Handle *nsh; | 37 | static struct GNUNET_NAMESTORE_Handle *nsh; |
38 | 38 | ||
39 | static struct GNUNET_SCHEDULER_Task * endbadly_task; | 39 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
40 | 40 | ||
41 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 41 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; |
42 | 42 | ||
@@ -48,19 +48,19 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe; | |||
48 | 48 | ||
49 | 49 | ||
50 | static void | 50 | static void |
51 | cleanup() | 51 | cleanup () |
52 | { | 52 | { |
53 | if (NULL != nsh) | 53 | if (NULL != nsh) |
54 | { | 54 | { |
55 | GNUNET_NAMESTORE_disconnect(nsh); | 55 | GNUNET_NAMESTORE_disconnect (nsh); |
56 | nsh = NULL; | 56 | nsh = NULL; |
57 | } | 57 | } |
58 | if (NULL != privkey) | 58 | if (NULL != privkey) |
59 | { | 59 | { |
60 | GNUNET_free(privkey); | 60 | GNUNET_free (privkey); |
61 | privkey = NULL; | 61 | privkey = NULL; |
62 | } | 62 | } |
63 | GNUNET_SCHEDULER_shutdown(); | 63 | GNUNET_SCHEDULER_shutdown (); |
64 | } | 64 | } |
65 | 65 | ||
66 | 66 | ||
@@ -70,87 +70,87 @@ cleanup() | |||
70 | * @param cls handle to use to re-connect. | 70 | * @param cls handle to use to re-connect. |
71 | */ | 71 | */ |
72 | static void | 72 | static void |
73 | endbadly(void *cls) | 73 | endbadly (void *cls) |
74 | { | 74 | { |
75 | if (NULL != nsqe) | 75 | if (NULL != nsqe) |
76 | { | 76 | { |
77 | GNUNET_NAMESTORE_cancel(nsqe); | 77 | GNUNET_NAMESTORE_cancel (nsqe); |
78 | nsqe = NULL; | 78 | nsqe = NULL; |
79 | } | 79 | } |
80 | cleanup(); | 80 | cleanup (); |
81 | res = 1; | 81 | res = 1; |
82 | } | 82 | } |
83 | 83 | ||
84 | 84 | ||
85 | static void | 85 | static void |
86 | end(void *cls) | 86 | end (void *cls) |
87 | { | 87 | { |
88 | cleanup(); | 88 | cleanup (); |
89 | res = 0; | 89 | res = 0; |
90 | } | 90 | } |
91 | 91 | ||
92 | 92 | ||
93 | static void | 93 | static void |
94 | put_cont(void *cls, | 94 | put_cont (void *cls, |
95 | int32_t success, | 95 | int32_t success, |
96 | const char *emsg) | 96 | const char *emsg) |
97 | { | 97 | { |
98 | GNUNET_assert(NULL != cls); | 98 | GNUNET_assert (NULL != cls); |
99 | nsqe = NULL; | 99 | nsqe = NULL; |
100 | if (endbadly_task != NULL) | 100 | if (endbadly_task != NULL) |
101 | { | 101 | { |
102 | GNUNET_SCHEDULER_cancel(endbadly_task); | 102 | GNUNET_SCHEDULER_cancel (endbadly_task); |
103 | endbadly_task = NULL; | 103 | endbadly_task = NULL; |
104 | } | 104 | } |
105 | switch (success) | 105 | switch (success) |
106 | { | 106 | { |
107 | case GNUNET_NO: | 107 | case GNUNET_NO: |
108 | /* We expected GNUNET_NO, since record was not found */ | 108 | /* We expected GNUNET_NO, since record was not found */ |
109 | GNUNET_SCHEDULER_add_now(&end, NULL); | 109 | GNUNET_SCHEDULER_add_now (&end, NULL); |
110 | break; | 110 | break; |
111 | 111 | ||
112 | case GNUNET_OK: | 112 | case GNUNET_OK: |
113 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 113 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
114 | "Namestore could remove non-existing record: `%s'\n", | 114 | "Namestore could remove non-existing record: `%s'\n", |
115 | (NULL != emsg) ? emsg : ""); | 115 | (NULL != emsg) ? emsg : ""); |
116 | GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 116 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
117 | break; | 117 | break; |
118 | 118 | ||
119 | case GNUNET_SYSERR: | 119 | case GNUNET_SYSERR: |
120 | default: | 120 | default: |
121 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 121 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
122 | "Namestore failed: `%s'\n", | 122 | "Namestore failed: `%s'\n", |
123 | (NULL != emsg) ? emsg : ""); | 123 | (NULL != emsg) ? emsg : ""); |
124 | GNUNET_SCHEDULER_add_now(&endbadly, NULL); | 124 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
125 | break; | 125 | break; |
126 | } | 126 | } |
127 | } | 127 | } |
128 | 128 | ||
129 | 129 | ||
130 | static void | 130 | static void |
131 | run(void *cls, | 131 | run (void *cls, |
132 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 132 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
133 | struct GNUNET_TESTING_Peer *peer) | 133 | struct GNUNET_TESTING_Peer *peer) |
134 | { | 134 | { |
135 | const char * name = "dummy.dummy.gnunet"; | 135 | const char *name = "dummy.dummy.gnunet"; |
136 | 136 | ||
137 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, | 137 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
138 | &endbadly, | 138 | &endbadly, |
139 | NULL); | 139 | NULL); |
140 | privkey = GNUNET_CRYPTO_ecdsa_key_create(); | 140 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); |
141 | GNUNET_assert(privkey != NULL); | 141 | GNUNET_assert (privkey != NULL); |
142 | GNUNET_CRYPTO_ecdsa_key_get_public(privkey, &pubkey); | 142 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); |
143 | 143 | ||
144 | nsh = GNUNET_NAMESTORE_connect(cfg); | 144 | nsh = GNUNET_NAMESTORE_connect (cfg); |
145 | GNUNET_break(NULL != nsh); | 145 | GNUNET_break (NULL != nsh); |
146 | nsqe = GNUNET_NAMESTORE_records_store(nsh, privkey, name, | 146 | nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, |
147 | 0, NULL, | 147 | 0, NULL, |
148 | &put_cont, (void *)name); | 148 | &put_cont, (void *) name); |
149 | if (NULL == nsqe) | 149 | if (NULL == nsqe) |
150 | { | 150 | { |
151 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 151 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
152 | _("Namestore cannot store no block\n")); | 152 | _ ("Namestore cannot store no block\n")); |
153 | } | 153 | } |
154 | } | 154 | } |
155 | 155 | ||
156 | 156 | ||
@@ -158,24 +158,24 @@ run(void *cls, | |||
158 | 158 | ||
159 | 159 | ||
160 | int | 160 | int |
161 | main(int argc, char *argv[]) | 161 | main (int argc, char *argv[]) |
162 | { | 162 | { |
163 | const char *plugin_name; | 163 | const char *plugin_name; |
164 | char *cfg_name; | 164 | char *cfg_name; |
165 | 165 | ||
166 | SETUP_CFG(plugin_name, cfg_name); | 166 | SETUP_CFG (plugin_name, cfg_name); |
167 | res = 1; | 167 | res = 1; |
168 | if (0 != | 168 | if (0 != |
169 | GNUNET_TESTING_peer_run("test-namestore-api-remove-non-existing-record", | 169 | GNUNET_TESTING_peer_run ("test-namestore-api-remove-non-existing-record", |
170 | cfg_name, | 170 | cfg_name, |
171 | &run, | 171 | &run, |
172 | NULL)) | 172 | NULL)) |
173 | { | 173 | { |
174 | res = 1; | 174 | res = 1; |
175 | } | 175 | } |
176 | GNUNET_DISK_purge_cfg_dir(cfg_name, | 176 | GNUNET_DISK_purge_cfg_dir (cfg_name, |
177 | "GNUNET_TEST_HOME"); | 177 | "GNUNET_TEST_HOME"); |
178 | GNUNET_free(cfg_name); | 178 | GNUNET_free (cfg_name); |
179 | return res; | 179 | return res; |
180 | } | 180 | } |
181 | 181 | ||
diff --git a/src/namestore/test_namestore_api_store.c b/src/namestore/test_namestore_api_store.c index 622227471..5bd0c3472 100644 --- a/src/namestore/test_namestore_api_store.c +++ b/src/namestore/test_namestore_api_store.c | |||
@@ -32,12 +32,12 @@ | |||
32 | 32 | ||
33 | #define TEST_RECORD_DATA 'a' | 33 | #define TEST_RECORD_DATA 'a' |
34 | 34 | ||
35 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100) | 35 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) |
36 | 36 | ||
37 | 37 | ||
38 | static struct GNUNET_NAMESTORE_Handle *nsh; | 38 | static struct GNUNET_NAMESTORE_Handle *nsh; |
39 | 39 | ||
40 | static struct GNUNET_SCHEDULER_Task * endbadly_task; | 40 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
41 | 41 | ||
42 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 42 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; |
43 | 43 | ||
@@ -49,19 +49,19 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe; | |||
49 | 49 | ||
50 | 50 | ||
51 | static void | 51 | static void |
52 | cleanup() | 52 | cleanup () |
53 | { | 53 | { |
54 | if (NULL != nsh) | 54 | if (NULL != nsh) |
55 | { | 55 | { |
56 | GNUNET_NAMESTORE_disconnect(nsh); | 56 | GNUNET_NAMESTORE_disconnect (nsh); |
57 | nsh = NULL; | 57 | nsh = NULL; |
58 | } | 58 | } |
59 | if (NULL != privkey) | 59 | if (NULL != privkey) |
60 | { | 60 | { |
61 | GNUNET_free(privkey); | 61 | GNUNET_free (privkey); |
62 | privkey = NULL; | 62 | privkey = NULL; |
63 | } | 63 | } |
64 | GNUNET_SCHEDULER_shutdown(); | 64 | GNUNET_SCHEDULER_shutdown (); |
65 | } | 65 | } |
66 | 66 | ||
67 | 67 | ||
@@ -71,80 +71,80 @@ cleanup() | |||
71 | * @param cls handle to use to re-connect. | 71 | * @param cls handle to use to re-connect. |
72 | */ | 72 | */ |
73 | static void | 73 | static void |
74 | endbadly(void *cls) | 74 | endbadly (void *cls) |
75 | { | 75 | { |
76 | if (NULL != nsqe) | 76 | if (NULL != nsqe) |
77 | { | 77 | { |
78 | GNUNET_NAMESTORE_cancel(nsqe); | 78 | GNUNET_NAMESTORE_cancel (nsqe); |
79 | nsqe = NULL; | 79 | nsqe = NULL; |
80 | } | 80 | } |
81 | cleanup(); | 81 | cleanup (); |
82 | res = 1; | 82 | res = 1; |
83 | } | 83 | } |
84 | 84 | ||
85 | 85 | ||
86 | static void | 86 | static void |
87 | end(void *cls) | 87 | end (void *cls) |
88 | { | 88 | { |
89 | cleanup(); | 89 | cleanup (); |
90 | res = 0; | 90 | res = 0; |
91 | } | 91 | } |
92 | 92 | ||
93 | 93 | ||
94 | static void | 94 | static void |
95 | put_cont(void *cls, int32_t success, const char *emsg) | 95 | put_cont (void *cls, int32_t success, const char *emsg) |
96 | { | 96 | { |
97 | const char *name = cls; | 97 | const char *name = cls; |
98 | 98 | ||
99 | nsqe = NULL; | 99 | nsqe = NULL; |
100 | GNUNET_assert(NULL != cls); | 100 | GNUNET_assert (NULL != cls); |
101 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 101 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
102 | "Name store added record for `%s': %s\n", | 102 | "Name store added record for `%s': %s\n", |
103 | name, | 103 | name, |
104 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | 104 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); |
105 | GNUNET_SCHEDULER_cancel(endbadly_task); | 105 | GNUNET_SCHEDULER_cancel (endbadly_task); |
106 | endbadly_task = NULL; | 106 | endbadly_task = NULL; |
107 | GNUNET_SCHEDULER_add_now(&end, NULL); | 107 | GNUNET_SCHEDULER_add_now (&end, NULL); |
108 | } | 108 | } |
109 | 109 | ||
110 | 110 | ||
111 | static void | 111 | static void |
112 | run(void *cls, | 112 | run (void *cls, |
113 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 113 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
114 | struct GNUNET_TESTING_Peer *peer) | 114 | struct GNUNET_TESTING_Peer *peer) |
115 | { | 115 | { |
116 | struct GNUNET_GNSRECORD_Data rd; | 116 | struct GNUNET_GNSRECORD_Data rd; |
117 | const char * name = "dummy.dummy.gnunet"; | 117 | const char *name = "dummy.dummy.gnunet"; |
118 | 118 | ||
119 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, | 119 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
120 | &endbadly, NULL); | 120 | &endbadly, NULL); |
121 | privkey = GNUNET_CRYPTO_ecdsa_key_create(); | 121 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); |
122 | GNUNET_assert(privkey != NULL); | 122 | GNUNET_assert (privkey != NULL); |
123 | GNUNET_CRYPTO_ecdsa_key_get_public(privkey, &pubkey); | 123 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); |
124 | 124 | ||
125 | 125 | ||
126 | rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us; | 126 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us; |
127 | rd.record_type = TEST_RECORD_TYPE; | 127 | rd.record_type = TEST_RECORD_TYPE; |
128 | rd.data_size = TEST_RECORD_DATALEN; | 128 | rd.data_size = TEST_RECORD_DATALEN; |
129 | rd.data = GNUNET_malloc(TEST_RECORD_DATALEN); | 129 | rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); |
130 | rd.flags = 0; | 130 | rd.flags = 0; |
131 | memset((char *)rd.data, 'a', TEST_RECORD_DATALEN); | 131 | memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN); |
132 | 132 | ||
133 | nsh = GNUNET_NAMESTORE_connect(cfg); | 133 | nsh = GNUNET_NAMESTORE_connect (cfg); |
134 | GNUNET_break(NULL != nsh); | 134 | GNUNET_break (NULL != nsh); |
135 | nsqe = GNUNET_NAMESTORE_records_store(nsh, | 135 | nsqe = GNUNET_NAMESTORE_records_store (nsh, |
136 | privkey, | 136 | privkey, |
137 | name, | 137 | name, |
138 | 1, | 138 | 1, |
139 | &rd, | 139 | &rd, |
140 | &put_cont, | 140 | &put_cont, |
141 | (void *)name); | 141 | (void *) name); |
142 | if (NULL == nsqe) | 142 | if (NULL == nsqe) |
143 | { | 143 | { |
144 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 144 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
145 | _("Namestore cannot store no block\n")); | 145 | _ ("Namestore cannot store no block\n")); |
146 | } | 146 | } |
147 | GNUNET_free((void *)rd.data); | 147 | GNUNET_free ((void *) rd.data); |
148 | } | 148 | } |
149 | 149 | ||
150 | 150 | ||
@@ -152,24 +152,24 @@ run(void *cls, | |||
152 | 152 | ||
153 | 153 | ||
154 | int | 154 | int |
155 | main(int argc, char *argv[]) | 155 | main (int argc, char *argv[]) |
156 | { | 156 | { |
157 | const char *plugin_name; | 157 | const char *plugin_name; |
158 | char *cfg_name; | 158 | char *cfg_name; |
159 | 159 | ||
160 | SETUP_CFG(plugin_name, cfg_name); | 160 | SETUP_CFG (plugin_name, cfg_name); |
161 | res = 1; | 161 | res = 1; |
162 | if (0 != | 162 | if (0 != |
163 | GNUNET_TESTING_peer_run("test-namestore-api", | 163 | GNUNET_TESTING_peer_run ("test-namestore-api", |
164 | cfg_name, | 164 | cfg_name, |
165 | &run, | 165 | &run, |
166 | NULL)) | 166 | NULL)) |
167 | { | 167 | { |
168 | res = 1; | 168 | res = 1; |
169 | } | 169 | } |
170 | GNUNET_DISK_purge_cfg_dir(cfg_name, | 170 | GNUNET_DISK_purge_cfg_dir (cfg_name, |
171 | "GNUNET_TEST_HOME"); | 171 | "GNUNET_TEST_HOME"); |
172 | GNUNET_free(cfg_name); | 172 | GNUNET_free (cfg_name); |
173 | return res; | 173 | return res; |
174 | } | 174 | } |
175 | 175 | ||
diff --git a/src/namestore/test_namestore_api_store_update.c b/src/namestore/test_namestore_api_store_update.c index 5e9885b3e..b0244453a 100644 --- a/src/namestore/test_namestore_api_store_update.c +++ b/src/namestore/test_namestore_api_store_update.c | |||
@@ -39,14 +39,14 @@ | |||
39 | 39 | ||
40 | #define TEST_RECORD_DATA2 'b' | 40 | #define TEST_RECORD_DATA2 'b' |
41 | 41 | ||
42 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100) | 42 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) |
43 | 43 | ||
44 | 44 | ||
45 | static struct GNUNET_NAMESTORE_Handle *nsh; | 45 | static struct GNUNET_NAMESTORE_Handle *nsh; |
46 | 46 | ||
47 | static struct GNUNET_NAMECACHE_Handle *nch; | 47 | static struct GNUNET_NAMECACHE_Handle *nch; |
48 | 48 | ||
49 | static struct GNUNET_SCHEDULER_Task * endbadly_task; | 49 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
50 | 50 | ||
51 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 51 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; |
52 | 52 | ||
@@ -69,217 +69,218 @@ static const char *name = "dummy"; | |||
69 | * @param cls handle to use to re-connect. | 69 | * @param cls handle to use to re-connect. |
70 | */ | 70 | */ |
71 | static void | 71 | static void |
72 | endbadly(void *cls) | 72 | endbadly (void *cls) |
73 | { | 73 | { |
74 | GNUNET_break(0); | 74 | GNUNET_break (0); |
75 | endbadly_task = NULL; | 75 | endbadly_task = NULL; |
76 | GNUNET_SCHEDULER_shutdown(); | 76 | GNUNET_SCHEDULER_shutdown (); |
77 | res = 1; | 77 | res = 1; |
78 | } | 78 | } |
79 | 79 | ||
80 | 80 | ||
81 | static void | 81 | static void |
82 | end(void *cls) | 82 | end (void *cls) |
83 | { | 83 | { |
84 | if (NULL != endbadly_task) | 84 | if (NULL != endbadly_task) |
85 | { | 85 | { |
86 | GNUNET_SCHEDULER_cancel(endbadly_task); | 86 | GNUNET_SCHEDULER_cancel (endbadly_task); |
87 | endbadly_task = NULL; | 87 | endbadly_task = NULL; |
88 | } | 88 | } |
89 | if (NULL != nsqe) | 89 | if (NULL != nsqe) |
90 | { | 90 | { |
91 | GNUNET_NAMESTORE_cancel(nsqe); | 91 | GNUNET_NAMESTORE_cancel (nsqe); |
92 | nsqe = NULL; | 92 | nsqe = NULL; |
93 | } | 93 | } |
94 | if (NULL != ncqe) | 94 | if (NULL != ncqe) |
95 | { | 95 | { |
96 | GNUNET_NAMECACHE_cancel(ncqe); | 96 | GNUNET_NAMECACHE_cancel (ncqe); |
97 | ncqe = NULL; | 97 | ncqe = NULL; |
98 | } | 98 | } |
99 | if (NULL != nsh) | 99 | if (NULL != nsh) |
100 | { | 100 | { |
101 | GNUNET_NAMESTORE_disconnect(nsh); | 101 | GNUNET_NAMESTORE_disconnect (nsh); |
102 | nsh = NULL; | 102 | nsh = NULL; |
103 | } | 103 | } |
104 | if (NULL != nch) | 104 | if (NULL != nch) |
105 | { | 105 | { |
106 | GNUNET_NAMECACHE_disconnect(nch); | 106 | GNUNET_NAMECACHE_disconnect (nch); |
107 | nch = NULL; | 107 | nch = NULL; |
108 | } | 108 | } |
109 | if (NULL != privkey) | 109 | if (NULL != privkey) |
110 | { | 110 | { |
111 | GNUNET_free(privkey); | 111 | GNUNET_free (privkey); |
112 | privkey = NULL; | 112 | privkey = NULL; |
113 | } | 113 | } |
114 | } | 114 | } |
115 | 115 | ||
116 | 116 | ||
117 | static void | 117 | static void |
118 | put_cont(void *cls, | 118 | put_cont (void *cls, |
119 | int32_t success, | 119 | int32_t success, |
120 | const char *emsg); | 120 | const char *emsg); |
121 | 121 | ||
122 | 122 | ||
123 | static void | 123 | static void |
124 | rd_decrypt_cb(void *cls, | 124 | rd_decrypt_cb (void *cls, |
125 | unsigned int rd_count, | 125 | unsigned int rd_count, |
126 | const struct GNUNET_GNSRECORD_Data *rd) | 126 | const struct GNUNET_GNSRECORD_Data *rd) |
127 | { | 127 | { |
128 | struct GNUNET_GNSRECORD_Data rd_new; | 128 | struct GNUNET_GNSRECORD_Data rd_new; |
129 | 129 | ||
130 | GNUNET_assert(1 == rd_count); | 130 | GNUNET_assert (1 == rd_count); |
131 | GNUNET_assert(NULL != rd); | 131 | GNUNET_assert (NULL != rd); |
132 | 132 | ||
133 | if (GNUNET_NO == update_performed) | 133 | if (GNUNET_NO == update_performed) |
134 | { | 134 | { |
135 | char rd_cmp_data[TEST_RECORD_DATALEN]; | 135 | char rd_cmp_data[TEST_RECORD_DATALEN]; |
136 | 136 | ||
137 | memset(rd_cmp_data, | 137 | memset (rd_cmp_data, |
138 | TEST_RECORD_DATA, | 138 | TEST_RECORD_DATA, |
139 | TEST_RECORD_DATALEN); | 139 | TEST_RECORD_DATALEN); |
140 | GNUNET_assert(TEST_RECORD_TYPE == rd[0].record_type); | 140 | GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type); |
141 | GNUNET_assert(TEST_RECORD_DATALEN == rd[0].data_size); | 141 | GNUNET_assert (TEST_RECORD_DATALEN == rd[0].data_size); |
142 | GNUNET_assert(0 == memcmp(&rd_cmp_data, | 142 | GNUNET_assert (0 == memcmp (&rd_cmp_data, |
143 | rd[0].data, | 143 | rd[0].data, |
144 | TEST_RECORD_DATALEN)); | 144 | TEST_RECORD_DATALEN)); |
145 | 145 | ||
146 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 146 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
147 | "Block was decrypted successfully, updating record \n"); | 147 | "Block was decrypted successfully, updating record \n"); |
148 | 148 | ||
149 | rd_new.flags = GNUNET_GNSRECORD_RF_NONE; | 149 | rd_new.flags = GNUNET_GNSRECORD_RF_NONE; |
150 | rd_new.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; | 150 | rd_new.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us |
151 | rd_new.record_type = TEST_RECORD_TYPE; | 151 | + 1000000000; |
152 | rd_new.data_size = TEST_RECORD_DATALEN2; | 152 | rd_new.record_type = TEST_RECORD_TYPE; |
153 | rd_new.data = GNUNET_malloc(TEST_RECORD_DATALEN2); | 153 | rd_new.data_size = TEST_RECORD_DATALEN2; |
154 | memset((char *)rd_new.data, | 154 | rd_new.data = GNUNET_malloc (TEST_RECORD_DATALEN2); |
155 | TEST_RECORD_DATA2, | 155 | memset ((char *) rd_new.data, |
156 | TEST_RECORD_DATALEN2); | 156 | TEST_RECORD_DATA2, |
157 | 157 | TEST_RECORD_DATALEN2); | |
158 | nsqe = GNUNET_NAMESTORE_records_store(nsh, | 158 | |
159 | privkey, | 159 | nsqe = GNUNET_NAMESTORE_records_store (nsh, |
160 | name, | 160 | privkey, |
161 | 1, | 161 | name, |
162 | &rd_new, | 162 | 1, |
163 | &put_cont, | 163 | &rd_new, |
164 | (void *)name); | 164 | &put_cont, |
165 | update_performed = GNUNET_YES; | 165 | (void *) name); |
166 | } | 166 | update_performed = GNUNET_YES; |
167 | } | ||
167 | else | 168 | else |
168 | { | 169 | { |
169 | char rd_cmp_data[TEST_RECORD_DATALEN2]; | 170 | char rd_cmp_data[TEST_RECORD_DATALEN2]; |
170 | 171 | ||
171 | memset(rd_cmp_data, | 172 | memset (rd_cmp_data, |
172 | TEST_RECORD_DATA2, | 173 | TEST_RECORD_DATA2, |
173 | TEST_RECORD_DATALEN2); | 174 | TEST_RECORD_DATALEN2); |
174 | GNUNET_assert(TEST_RECORD_TYPE == rd[0].record_type); | 175 | GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type); |
175 | GNUNET_assert(TEST_RECORD_DATALEN2 == rd[0].data_size); | 176 | GNUNET_assert (TEST_RECORD_DATALEN2 == rd[0].data_size); |
176 | GNUNET_assert(0 == memcmp(&rd_cmp_data, | 177 | GNUNET_assert (0 == memcmp (&rd_cmp_data, |
177 | rd[0].data, | 178 | rd[0].data, |
178 | TEST_RECORD_DATALEN2)); | 179 | TEST_RECORD_DATALEN2)); |
179 | GNUNET_SCHEDULER_shutdown(); | 180 | GNUNET_SCHEDULER_shutdown (); |
180 | res = 0; | 181 | res = 0; |
181 | } | 182 | } |
182 | } | 183 | } |
183 | 184 | ||
184 | 185 | ||
185 | static void | 186 | static void |
186 | name_lookup_proc(void *cls, | 187 | name_lookup_proc (void *cls, |
187 | const struct GNUNET_GNSRECORD_Block *block) | 188 | const struct GNUNET_GNSRECORD_Block *block) |
188 | { | 189 | { |
189 | const char *name = cls; | 190 | const char *name = cls; |
190 | 191 | ||
191 | ncqe = NULL; | 192 | ncqe = NULL; |
192 | GNUNET_assert(NULL != cls); | 193 | GNUNET_assert (NULL != cls); |
193 | if (NULL == block) | 194 | if (NULL == block) |
194 | { | 195 | { |
195 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 196 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
196 | _("Namecache returned no block for `%s'\n"), | 197 | _ ("Namecache returned no block for `%s'\n"), |
197 | name); | 198 | name); |
198 | GNUNET_SCHEDULER_shutdown(); | 199 | GNUNET_SCHEDULER_shutdown (); |
199 | return; | 200 | return; |
200 | } | 201 | } |
201 | 202 | ||
202 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 203 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
203 | "Namecache returned block, decrypting \n"); | 204 | "Namecache returned block, decrypting \n"); |
204 | GNUNET_assert(GNUNET_OK == | 205 | GNUNET_assert (GNUNET_OK == |
205 | GNUNET_GNSRECORD_block_decrypt(block, | 206 | GNUNET_GNSRECORD_block_decrypt (block, |
206 | &pubkey, | 207 | &pubkey, |
207 | name, | 208 | name, |
208 | &rd_decrypt_cb, | 209 | &rd_decrypt_cb, |
209 | (void *)name)); | 210 | (void *) name)); |
210 | } | 211 | } |
211 | 212 | ||
212 | 213 | ||
213 | static void | 214 | static void |
214 | put_cont(void *cls, | 215 | put_cont (void *cls, |
215 | int32_t success, | 216 | int32_t success, |
216 | const char *emsg) | 217 | const char *emsg) |
217 | { | 218 | { |
218 | const char *name = cls; | 219 | const char *name = cls; |
219 | struct GNUNET_HashCode derived_hash; | 220 | struct GNUNET_HashCode derived_hash; |
220 | 221 | ||
221 | nsqe = NULL; | 222 | nsqe = NULL; |
222 | GNUNET_assert(NULL != cls); | 223 | GNUNET_assert (NULL != cls); |
223 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 224 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
224 | "Name store added record for `%s': %s\n", | 225 | "Name store added record for `%s': %s\n", |
225 | name, | 226 | name, |
226 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | 227 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); |
227 | /* Create derived hash */ | 228 | /* Create derived hash */ |
228 | GNUNET_GNSRECORD_query_from_private_key(privkey, | 229 | GNUNET_GNSRECORD_query_from_private_key (privkey, |
229 | name, | 230 | name, |
230 | &derived_hash); | 231 | &derived_hash); |
231 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 232 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
232 | "Looking in namecache for `%s'\n", | 233 | "Looking in namecache for `%s'\n", |
233 | GNUNET_h2s(&derived_hash)); | 234 | GNUNET_h2s (&derived_hash)); |
234 | ncqe = GNUNET_NAMECACHE_lookup_block(nch, | 235 | ncqe = GNUNET_NAMECACHE_lookup_block (nch, |
235 | &derived_hash, | 236 | &derived_hash, |
236 | &name_lookup_proc, (void *)name); | 237 | &name_lookup_proc, (void *) name); |
237 | } | 238 | } |
238 | 239 | ||
239 | 240 | ||
240 | static void | 241 | static void |
241 | run(void *cls, | 242 | run (void *cls, |
242 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 243 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
243 | struct GNUNET_TESTING_Peer *peer) | 244 | struct GNUNET_TESTING_Peer *peer) |
244 | { | 245 | { |
245 | struct GNUNET_GNSRECORD_Data rd; | 246 | struct GNUNET_GNSRECORD_Data rd; |
246 | 247 | ||
247 | update_performed = GNUNET_NO; | 248 | update_performed = GNUNET_NO; |
248 | GNUNET_SCHEDULER_add_shutdown(&end, | 249 | GNUNET_SCHEDULER_add_shutdown (&end, |
249 | NULL); | 250 | NULL); |
250 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, | 251 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
251 | &endbadly, | 252 | &endbadly, |
252 | NULL); | 253 | NULL); |
253 | privkey = GNUNET_CRYPTO_ecdsa_key_create(); | 254 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); |
254 | GNUNET_assert(privkey != NULL); | 255 | GNUNET_assert (privkey != NULL); |
255 | GNUNET_CRYPTO_ecdsa_key_get_public(privkey, | 256 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, |
256 | &pubkey); | 257 | &pubkey); |
257 | rd.flags = GNUNET_GNSRECORD_RF_NONE; | 258 | rd.flags = GNUNET_GNSRECORD_RF_NONE; |
258 | rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; | 259 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us + 1000000000; |
259 | rd.record_type = TEST_RECORD_TYPE; | 260 | rd.record_type = TEST_RECORD_TYPE; |
260 | rd.data_size = TEST_RECORD_DATALEN; | 261 | rd.data_size = TEST_RECORD_DATALEN; |
261 | rd.data = GNUNET_malloc(TEST_RECORD_DATALEN); | 262 | rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); |
262 | memset((char *)rd.data, | 263 | memset ((char *) rd.data, |
263 | TEST_RECORD_DATA, | 264 | TEST_RECORD_DATA, |
264 | TEST_RECORD_DATALEN); | 265 | TEST_RECORD_DATALEN); |
265 | 266 | ||
266 | nsh = GNUNET_NAMESTORE_connect(cfg); | 267 | nsh = GNUNET_NAMESTORE_connect (cfg); |
267 | GNUNET_break(NULL != nsh); | 268 | GNUNET_break (NULL != nsh); |
268 | nch = GNUNET_NAMECACHE_connect(cfg); | 269 | nch = GNUNET_NAMECACHE_connect (cfg); |
269 | GNUNET_break(NULL != nch); | 270 | GNUNET_break (NULL != nch); |
270 | nsqe = GNUNET_NAMESTORE_records_store(nsh, | 271 | nsqe = GNUNET_NAMESTORE_records_store (nsh, |
271 | privkey, | 272 | privkey, |
272 | name, | 273 | name, |
273 | 1, | 274 | 1, |
274 | &rd, | 275 | &rd, |
275 | &put_cont, | 276 | &put_cont, |
276 | (void *)name); | 277 | (void *) name); |
277 | if (NULL == nsqe) | 278 | if (NULL == nsqe) |
278 | { | 279 | { |
279 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 280 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
280 | _("Namestore cannot store no block\n")); | 281 | _ ("Namestore cannot store no block\n")); |
281 | } | 282 | } |
282 | GNUNET_free((void *)rd.data); | 283 | GNUNET_free ((void *) rd.data); |
283 | } | 284 | } |
284 | 285 | ||
285 | 286 | ||
@@ -287,25 +288,25 @@ run(void *cls, | |||
287 | 288 | ||
288 | 289 | ||
289 | int | 290 | int |
290 | main(int argc, | 291 | main (int argc, |
291 | char *argv[]) | 292 | char *argv[]) |
292 | { | 293 | { |
293 | const char *plugin_name; | 294 | const char *plugin_name; |
294 | char *cfg_name; | 295 | char *cfg_name; |
295 | 296 | ||
296 | SETUP_CFG(plugin_name, cfg_name); | 297 | SETUP_CFG (plugin_name, cfg_name); |
297 | res = 1; | 298 | res = 1; |
298 | if (0 != | 299 | if (0 != |
299 | GNUNET_TESTING_peer_run("test-namestore-api-store-update", | 300 | GNUNET_TESTING_peer_run ("test-namestore-api-store-update", |
300 | cfg_name, | 301 | cfg_name, |
301 | &run, | 302 | &run, |
302 | NULL)) | 303 | NULL)) |
303 | { | 304 | { |
304 | res = 1; | 305 | res = 1; |
305 | } | 306 | } |
306 | GNUNET_DISK_purge_cfg_dir(cfg_name, | 307 | GNUNET_DISK_purge_cfg_dir (cfg_name, |
307 | "GNUNET_TEST_HOME"); | 308 | "GNUNET_TEST_HOME"); |
308 | GNUNET_free(cfg_name); | 309 | GNUNET_free (cfg_name); |
309 | return res; | 310 | return res; |
310 | } | 311 | } |
311 | 312 | ||
diff --git a/src/namestore/test_namestore_api_zone_iteration.c b/src/namestore/test_namestore_api_zone_iteration.c index 62686403a..d69b7cc62 100644 --- a/src/namestore/test_namestore_api_zone_iteration.c +++ b/src/namestore/test_namestore_api_zone_iteration.c | |||
@@ -30,16 +30,16 @@ | |||
30 | #define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT | 30 | #define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT |
31 | 31 | ||
32 | 32 | ||
33 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100) | 33 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) |
34 | 34 | ||
35 | 35 | ||
36 | static struct GNUNET_NAMESTORE_Handle * nsh; | 36 | static struct GNUNET_NAMESTORE_Handle *nsh; |
37 | 37 | ||
38 | static struct GNUNET_SCHEDULER_Task * endbadly_task; | 38 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
39 | 39 | ||
40 | static struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey; | 40 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; |
41 | 41 | ||
42 | static struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey2; | 42 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey2; |
43 | 43 | ||
44 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; | 44 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; |
45 | 45 | ||
@@ -47,15 +47,15 @@ static int res; | |||
47 | 47 | ||
48 | static int returned_records; | 48 | static int returned_records; |
49 | 49 | ||
50 | static char * s_name_1; | 50 | static char *s_name_1; |
51 | 51 | ||
52 | static struct GNUNET_GNSRECORD_Data *s_rd_1; | 52 | static struct GNUNET_GNSRECORD_Data *s_rd_1; |
53 | 53 | ||
54 | static char * s_name_2; | 54 | static char *s_name_2; |
55 | 55 | ||
56 | static struct GNUNET_GNSRECORD_Data *s_rd_2; | 56 | static struct GNUNET_GNSRECORD_Data *s_rd_2; |
57 | 57 | ||
58 | static char * s_name_3; | 58 | static char *s_name_3; |
59 | 59 | ||
60 | static struct GNUNET_GNSRECORD_Data *s_rd_3; | 60 | static struct GNUNET_GNSRECORD_Data *s_rd_3; |
61 | 61 | ||
@@ -67,268 +67,269 @@ static struct GNUNET_GNSRECORD_Data *s_rd_3; | |||
67 | * @param tc scheduler context | 67 | * @param tc scheduler context |
68 | */ | 68 | */ |
69 | static void | 69 | static void |
70 | endbadly(void *cls) | 70 | endbadly (void *cls) |
71 | { | 71 | { |
72 | endbadly_task = NULL; | 72 | endbadly_task = NULL; |
73 | GNUNET_SCHEDULER_shutdown(); | 73 | GNUNET_SCHEDULER_shutdown (); |
74 | res = 1; | 74 | res = 1; |
75 | } | 75 | } |
76 | 76 | ||
77 | 77 | ||
78 | static void | 78 | static void |
79 | end(void *cls) | 79 | end (void *cls) |
80 | { | 80 | { |
81 | if (NULL != zi) | 81 | if (NULL != zi) |
82 | { | 82 | { |
83 | GNUNET_NAMESTORE_zone_iteration_stop(zi); | 83 | GNUNET_NAMESTORE_zone_iteration_stop (zi); |
84 | zi = NULL; | 84 | zi = NULL; |
85 | } | 85 | } |
86 | if (NULL != endbadly_task) | 86 | if (NULL != endbadly_task) |
87 | { | 87 | { |
88 | GNUNET_SCHEDULER_cancel(endbadly_task); | 88 | GNUNET_SCHEDULER_cancel (endbadly_task); |
89 | endbadly_task = NULL; | 89 | endbadly_task = NULL; |
90 | } | 90 | } |
91 | if (NULL != privkey) | 91 | if (NULL != privkey) |
92 | { | 92 | { |
93 | GNUNET_free(privkey); | 93 | GNUNET_free (privkey); |
94 | privkey = NULL; | 94 | privkey = NULL; |
95 | } | 95 | } |
96 | if (NULL != privkey2) | 96 | if (NULL != privkey2) |
97 | { | 97 | { |
98 | GNUNET_free(privkey2); | 98 | GNUNET_free (privkey2); |
99 | privkey2 = NULL; | 99 | privkey2 = NULL; |
100 | } | 100 | } |
101 | GNUNET_free_non_null(s_name_1); | 101 | GNUNET_free_non_null (s_name_1); |
102 | GNUNET_free_non_null(s_name_2); | 102 | GNUNET_free_non_null (s_name_2); |
103 | GNUNET_free_non_null(s_name_3); | 103 | GNUNET_free_non_null (s_name_3); |
104 | if (NULL != s_rd_1) | 104 | if (NULL != s_rd_1) |
105 | { | 105 | { |
106 | GNUNET_free((void *)s_rd_1->data); | 106 | GNUNET_free ((void *) s_rd_1->data); |
107 | GNUNET_free(s_rd_1); | 107 | GNUNET_free (s_rd_1); |
108 | } | 108 | } |
109 | if (NULL != s_rd_2) | 109 | if (NULL != s_rd_2) |
110 | { | 110 | { |
111 | GNUNET_free((void *)s_rd_2->data); | 111 | GNUNET_free ((void *) s_rd_2->data); |
112 | GNUNET_free(s_rd_2); | 112 | GNUNET_free (s_rd_2); |
113 | } | 113 | } |
114 | if (NULL != s_rd_3) | 114 | if (NULL != s_rd_3) |
115 | { | 115 | { |
116 | GNUNET_free((void *)s_rd_3->data); | 116 | GNUNET_free ((void *) s_rd_3->data); |
117 | GNUNET_free(s_rd_3); | 117 | GNUNET_free (s_rd_3); |
118 | } | 118 | } |
119 | if (NULL != nsh) | 119 | if (NULL != nsh) |
120 | { | 120 | { |
121 | GNUNET_NAMESTORE_disconnect(nsh); | 121 | GNUNET_NAMESTORE_disconnect (nsh); |
122 | nsh = NULL; | 122 | nsh = NULL; |
123 | } | 123 | } |
124 | } | 124 | } |
125 | 125 | ||
126 | 126 | ||
127 | static void | 127 | static void |
128 | zone_end(void *cls) | 128 | zone_end (void *cls) |
129 | { | 129 | { |
130 | GNUNET_break(3 == returned_records); | 130 | GNUNET_break (3 == returned_records); |
131 | if (3 == returned_records) | 131 | if (3 == returned_records) |
132 | { | 132 | { |
133 | res = 0; /* Last iteraterator callback, we are done */ | 133 | res = 0; /* Last iteraterator callback, we are done */ |
134 | zi = NULL; | 134 | zi = NULL; |
135 | } | 135 | } |
136 | else | 136 | else |
137 | res = 1; | 137 | res = 1; |
138 | 138 | ||
139 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 139 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
140 | "Received last result, iteration done after receing %u results\n", | 140 | "Received last result, iteration done after receing %u results\n", |
141 | returned_records); | 141 | returned_records); |
142 | GNUNET_SCHEDULER_shutdown(); | 142 | GNUNET_SCHEDULER_shutdown (); |
143 | } | 143 | } |
144 | 144 | ||
145 | 145 | ||
146 | static void | 146 | static void |
147 | fail_cb(void *cls) | 147 | fail_cb (void *cls) |
148 | { | 148 | { |
149 | GNUNET_assert(0); | 149 | GNUNET_assert (0); |
150 | } | 150 | } |
151 | 151 | ||
152 | 152 | ||
153 | static void | 153 | static void |
154 | zone_proc(void *cls, | 154 | zone_proc (void *cls, |
155 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 155 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
156 | const char *label, | 156 | const char *label, |
157 | unsigned int rd_count, | 157 | unsigned int rd_count, |
158 | const struct GNUNET_GNSRECORD_Data *rd) | 158 | const struct GNUNET_GNSRECORD_Data *rd) |
159 | { | 159 | { |
160 | int failed = GNUNET_NO; | 160 | int failed = GNUNET_NO; |
161 | 161 | ||
162 | GNUNET_assert(NULL != zone); | 162 | GNUNET_assert (NULL != zone); |
163 | if (0 == GNUNET_memcmp(zone, | 163 | if (0 == GNUNET_memcmp (zone, |
164 | privkey)) | 164 | privkey)) |
165 | { | ||
166 | if (0 == strcmp (label, s_name_1)) | ||
165 | { | 167 | { |
166 | if (0 == strcmp(label, s_name_1)) | 168 | if (rd_count == 1) |
167 | { | 169 | { |
168 | if (rd_count == 1) | 170 | if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_1)) |
169 | { | ||
170 | if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_1)) | ||
171 | { | ||
172 | failed = GNUNET_YES; | ||
173 | GNUNET_break(0); | ||
174 | } | ||
175 | } | ||
176 | else | ||
177 | { | ||
178 | failed = GNUNET_YES; | ||
179 | GNUNET_break(0); | ||
180 | } | ||
181 | } | ||
182 | else if (0 == strcmp(label, s_name_2)) | ||
183 | { | 171 | { |
184 | if (rd_count == 1) | ||
185 | { | ||
186 | if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_2)) | ||
187 | { | ||
188 | failed = GNUNET_YES; | ||
189 | GNUNET_break(0); | ||
190 | } | ||
191 | } | ||
192 | else | ||
193 | { | ||
194 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
195 | "Received invalid record count\n"); | ||
196 | failed = GNUNET_YES; | ||
197 | GNUNET_break(0); | ||
198 | } | ||
199 | } | ||
200 | else | ||
201 | { | ||
202 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
203 | "Comparing result failed: got name `%s' for first zone\n", | ||
204 | label); | ||
205 | failed = GNUNET_YES; | 172 | failed = GNUNET_YES; |
206 | GNUNET_break(0); | 173 | GNUNET_break (0); |
207 | } | 174 | } |
175 | } | ||
176 | else | ||
177 | { | ||
178 | failed = GNUNET_YES; | ||
179 | GNUNET_break (0); | ||
180 | } | ||
208 | } | 181 | } |
209 | else if (0 == GNUNET_memcmp(zone, | 182 | else if (0 == strcmp (label, s_name_2)) |
210 | privkey2)) | ||
211 | { | 183 | { |
212 | if (0 == strcmp(label, s_name_3)) | 184 | if (rd_count == 1) |
185 | { | ||
186 | if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_2)) | ||
213 | { | 187 | { |
214 | if (rd_count == 1) | 188 | failed = GNUNET_YES; |
215 | { | 189 | GNUNET_break (0); |
216 | if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_3)) | ||
217 | { | ||
218 | failed = GNUNET_YES; | ||
219 | GNUNET_break(0); | ||
220 | } | ||
221 | } | ||
222 | else | ||
223 | { | ||
224 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
225 | "Received invalid record count\n"); | ||
226 | failed = GNUNET_YES; | ||
227 | GNUNET_break(0); | ||
228 | } | ||
229 | } | 190 | } |
191 | } | ||
230 | else | 192 | else |
193 | { | ||
194 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
195 | "Received invalid record count\n"); | ||
196 | failed = GNUNET_YES; | ||
197 | GNUNET_break (0); | ||
198 | } | ||
199 | } | ||
200 | else | ||
201 | { | ||
202 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
203 | "Comparing result failed: got name `%s' for first zone\n", | ||
204 | label); | ||
205 | failed = GNUNET_YES; | ||
206 | GNUNET_break (0); | ||
207 | } | ||
208 | } | ||
209 | else if (0 == GNUNET_memcmp (zone, | ||
210 | privkey2)) | ||
211 | { | ||
212 | if (0 == strcmp (label, s_name_3)) | ||
213 | { | ||
214 | if (rd_count == 1) | ||
215 | { | ||
216 | if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_3)) | ||
231 | { | 217 | { |
232 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
233 | "Comparing result failed: got name `%s' for first zone\n", | ||
234 | label); | ||
235 | failed = GNUNET_YES; | 218 | failed = GNUNET_YES; |
236 | GNUNET_break(0); | 219 | GNUNET_break (0); |
237 | } | 220 | } |
221 | } | ||
222 | else | ||
223 | { | ||
224 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
225 | "Received invalid record count\n"); | ||
226 | failed = GNUNET_YES; | ||
227 | GNUNET_break (0); | ||
228 | } | ||
238 | } | 229 | } |
239 | else | 230 | else |
240 | { | 231 | { |
241 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 232 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
242 | "Received invalid zone\n"); | 233 | "Comparing result failed: got name `%s' for first zone\n", |
234 | label); | ||
243 | failed = GNUNET_YES; | 235 | failed = GNUNET_YES; |
244 | GNUNET_break(0); | 236 | GNUNET_break (0); |
245 | } | 237 | } |
238 | } | ||
239 | else | ||
240 | { | ||
241 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
242 | "Received invalid zone\n"); | ||
243 | failed = GNUNET_YES; | ||
244 | GNUNET_break (0); | ||
245 | } | ||
246 | 246 | ||
247 | if (failed == GNUNET_NO) | 247 | if (failed == GNUNET_NO) |
248 | { | 248 | { |
249 | returned_records++; | 249 | returned_records++; |
250 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 250 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
251 | "Telling namestore to send the next result\n"); | 251 | "Telling namestore to send the next result\n"); |
252 | GNUNET_NAMESTORE_zone_iterator_next(zi, | 252 | GNUNET_NAMESTORE_zone_iterator_next (zi, |
253 | 1); | 253 | 1); |
254 | } | 254 | } |
255 | else | 255 | else |
256 | { | 256 | { |
257 | GNUNET_break(0); | 257 | GNUNET_break (0); |
258 | GNUNET_SCHEDULER_shutdown(); | 258 | GNUNET_SCHEDULER_shutdown (); |
259 | res = 1; | 259 | res = 1; |
260 | } | 260 | } |
261 | } | 261 | } |
262 | 262 | ||
263 | 263 | ||
264 | static void | 264 | static void |
265 | put_cont(void *cls, | 265 | put_cont (void *cls, |
266 | int32_t success, | 266 | int32_t success, |
267 | const char *emsg) | 267 | const char *emsg) |
268 | { | 268 | { |
269 | static int c = 0; | 269 | static int c = 0; |
270 | 270 | ||
271 | if (success == GNUNET_OK) | 271 | if (success == GNUNET_OK) |
272 | { | 272 | { |
273 | c++; | 273 | c++; |
274 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 274 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
275 | "Created record %u \n", | 275 | "Created record %u \n", |
276 | c); | 276 | c); |
277 | } | 277 | } |
278 | else | 278 | else |
279 | { | 279 | { |
280 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 280 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
281 | "Failed to created records: `%s'\n", | 281 | "Failed to created records: `%s'\n", |
282 | emsg); | 282 | emsg); |
283 | GNUNET_break(0); | 283 | GNUNET_break (0); |
284 | GNUNET_SCHEDULER_shutdown(); | 284 | GNUNET_SCHEDULER_shutdown (); |
285 | res = 1; | 285 | res = 1; |
286 | return; | 286 | return; |
287 | } | 287 | } |
288 | 288 | ||
289 | if (c == 3) | 289 | if (c == 3) |
290 | { | ||
291 | res = 1; | ||
292 | returned_records = 0; | ||
293 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
294 | "All records created, starting iteration over all zones \n"); | ||
295 | zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, | ||
296 | NULL, | ||
297 | &fail_cb, | ||
298 | NULL, | ||
299 | &zone_proc, | ||
300 | NULL, | ||
301 | &zone_end, | ||
302 | NULL); | ||
303 | if (zi == NULL) | ||
290 | { | 304 | { |
305 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
306 | "Failed to create zone iterator\n"); | ||
307 | GNUNET_break (0); | ||
308 | GNUNET_SCHEDULER_shutdown (); | ||
291 | res = 1; | 309 | res = 1; |
292 | returned_records = 0; | 310 | return; |
293 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
294 | "All records created, starting iteration over all zones \n"); | ||
295 | zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, | ||
296 | NULL, | ||
297 | &fail_cb, | ||
298 | NULL, | ||
299 | &zone_proc, | ||
300 | NULL, | ||
301 | &zone_end, | ||
302 | NULL); | ||
303 | if (zi == NULL) | ||
304 | { | ||
305 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
306 | "Failed to create zone iterator\n"); | ||
307 | GNUNET_break(0); | ||
308 | GNUNET_SCHEDULER_shutdown(); | ||
309 | res = 1; | ||
310 | return; | ||
311 | } | ||
312 | } | 311 | } |
312 | } | ||
313 | } | 313 | } |
314 | 314 | ||
315 | 315 | ||
316 | static struct GNUNET_GNSRECORD_Data * | 316 | static struct GNUNET_GNSRECORD_Data * |
317 | create_record(unsigned int count) | 317 | create_record (unsigned int count) |
318 | { | 318 | { |
319 | struct GNUNET_GNSRECORD_Data * rd; | 319 | struct GNUNET_GNSRECORD_Data *rd; |
320 | 320 | ||
321 | rd = GNUNET_new_array(count, | 321 | rd = GNUNET_new_array (count, |
322 | struct GNUNET_GNSRECORD_Data); | 322 | struct GNUNET_GNSRECORD_Data); |
323 | for (unsigned int c = 0; c < count; c++) | 323 | for (unsigned int c = 0; c < count; c++) |
324 | { | 324 | { |
325 | rd[c].expiration_time = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS).abs_value_us; | 325 | rd[c].expiration_time = GNUNET_TIME_relative_to_absolute ( |
326 | rd[c].record_type = TEST_RECORD_TYPE; | 326 | GNUNET_TIME_UNIT_HOURS).abs_value_us; |
327 | rd[c].data_size = 50; | 327 | rd[c].record_type = TEST_RECORD_TYPE; |
328 | rd[c].data = GNUNET_malloc(50); | 328 | rd[c].data_size = 50; |
329 | rd[c].flags = 0; | 329 | rd[c].data = GNUNET_malloc (50); |
330 | memset((char *)rd[c].data, 'a', 50); | 330 | rd[c].flags = 0; |
331 | } | 331 | memset ((char *) rd[c].data, 'a', 50); |
332 | } | ||
332 | return rd; | 333 | return rd; |
333 | } | 334 | } |
334 | 335 | ||
@@ -339,128 +340,128 @@ create_record(unsigned int count) | |||
339 | * start the actual tests by filling the zone. | 340 | * start the actual tests by filling the zone. |
340 | */ | 341 | */ |
341 | static void | 342 | static void |
342 | empty_zone_proc(void *cls, | 343 | empty_zone_proc (void *cls, |
343 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 344 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
344 | const char *label, | 345 | const char *label, |
345 | unsigned int rd_count, | 346 | unsigned int rd_count, |
346 | const struct GNUNET_GNSRECORD_Data *rd) | 347 | const struct GNUNET_GNSRECORD_Data *rd) |
347 | { | 348 | { |
348 | GNUNET_assert(nsh == cls); | 349 | GNUNET_assert (nsh == cls); |
349 | if (NULL != zone) | 350 | if (NULL != zone) |
350 | { | 351 | { |
351 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 352 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
352 | _("Expected empty zone but received zone private key\n")); | 353 | _ ("Expected empty zone but received zone private key\n")); |
353 | GNUNET_break(0); | 354 | GNUNET_break (0); |
354 | GNUNET_SCHEDULER_shutdown(); | 355 | GNUNET_SCHEDULER_shutdown (); |
355 | res = 1; | 356 | res = 1; |
356 | return; | 357 | return; |
357 | } | 358 | } |
358 | if ((NULL != label) || (NULL != rd) || (0 != rd_count)) | 359 | if ((NULL != label) || (NULL != rd) || (0 != rd_count)) |
359 | { | 360 | { |
360 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 361 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
361 | _("Expected no zone content but received data\n")); | 362 | _ ("Expected no zone content but received data\n")); |
362 | GNUNET_break(0); | 363 | GNUNET_break (0); |
363 | GNUNET_SCHEDULER_shutdown(); | 364 | GNUNET_SCHEDULER_shutdown (); |
364 | res = 1; | 365 | res = 1; |
365 | return; | 366 | return; |
366 | } | 367 | } |
367 | GNUNET_assert(0); | 368 | GNUNET_assert (0); |
368 | } | 369 | } |
369 | 370 | ||
370 | 371 | ||
371 | static void | 372 | static void |
372 | empty_zone_end(void *cls) | 373 | empty_zone_end (void *cls) |
373 | { | 374 | { |
374 | char *hostkey_file; | 375 | char *hostkey_file; |
375 | 376 | ||
376 | zi = NULL; | 377 | zi = NULL; |
377 | GNUNET_asprintf(&hostkey_file, | 378 | GNUNET_asprintf (&hostkey_file, |
378 | "zonefiles%s%s", | 379 | "zonefiles%s%s", |
379 | DIR_SEPARATOR_STR, | 380 | DIR_SEPARATOR_STR, |
380 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | 381 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); |
381 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 382 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
382 | "Using zonekey file `%s' \n", | 383 | "Using zonekey file `%s' \n", |
383 | hostkey_file); | 384 | hostkey_file); |
384 | privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); | 385 | privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file); |
385 | GNUNET_free(hostkey_file); | 386 | GNUNET_free (hostkey_file); |
386 | GNUNET_assert(privkey != NULL); | 387 | GNUNET_assert (privkey != NULL); |
387 | 388 | ||
388 | GNUNET_asprintf(&hostkey_file, | 389 | GNUNET_asprintf (&hostkey_file, |
389 | "zonefiles%s%s", | 390 | "zonefiles%s%s", |
390 | DIR_SEPARATOR_STR, | 391 | DIR_SEPARATOR_STR, |
391 | "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"); | 392 | "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"); |
392 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 393 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
393 | "Using zonekey file `%s' \n", | 394 | "Using zonekey file `%s' \n", |
394 | hostkey_file); | 395 | hostkey_file); |
395 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); | 396 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file); |
396 | GNUNET_free(hostkey_file); | 397 | GNUNET_free (hostkey_file); |
397 | GNUNET_assert(privkey2 != NULL); | 398 | GNUNET_assert (privkey2 != NULL); |
398 | 399 | ||
399 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); | 400 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); |
400 | 401 | ||
401 | GNUNET_asprintf(&s_name_1, "dummy1"); | 402 | GNUNET_asprintf (&s_name_1, "dummy1"); |
402 | s_rd_1 = create_record(1); | 403 | s_rd_1 = create_record (1); |
403 | GNUNET_NAMESTORE_records_store(nsh, | 404 | GNUNET_NAMESTORE_records_store (nsh, |
404 | privkey, | 405 | privkey, |
405 | s_name_1, | 406 | s_name_1, |
406 | 1, s_rd_1, | 407 | 1, s_rd_1, |
407 | &put_cont, | 408 | &put_cont, |
408 | NULL); | 409 | NULL); |
409 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 410 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
410 | "Created record 2 \n"); | 411 | "Created record 2 \n"); |
411 | GNUNET_asprintf(&s_name_2, "dummy2"); | 412 | GNUNET_asprintf (&s_name_2, "dummy2"); |
412 | s_rd_2 = create_record(1); | 413 | s_rd_2 = create_record (1); |
413 | GNUNET_NAMESTORE_records_store(nsh, | 414 | GNUNET_NAMESTORE_records_store (nsh, |
414 | privkey, | 415 | privkey, |
415 | s_name_2, | 416 | s_name_2, |
416 | 1, s_rd_2, | 417 | 1, s_rd_2, |
417 | &put_cont, | 418 | &put_cont, |
418 | NULL); | 419 | NULL); |
419 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 420 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
420 | "Created record 3\n"); | 421 | "Created record 3\n"); |
421 | /* name in different zone */ | 422 | /* name in different zone */ |
422 | GNUNET_asprintf(&s_name_3, "dummy3"); | 423 | GNUNET_asprintf (&s_name_3, "dummy3"); |
423 | s_rd_3 = create_record(1); | 424 | s_rd_3 = create_record (1); |
424 | GNUNET_NAMESTORE_records_store(nsh, | 425 | GNUNET_NAMESTORE_records_store (nsh, |
425 | privkey2, | 426 | privkey2, |
426 | s_name_3, | 427 | s_name_3, |
427 | 1, | 428 | 1, |
428 | s_rd_3, | 429 | s_rd_3, |
429 | &put_cont, | 430 | &put_cont, |
430 | NULL); | 431 | NULL); |
431 | } | 432 | } |
432 | 433 | ||
433 | 434 | ||
434 | static void | 435 | static void |
435 | run(void *cls, | 436 | run (void *cls, |
436 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 437 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
437 | struct GNUNET_TESTING_Peer *peer) | 438 | struct GNUNET_TESTING_Peer *peer) |
438 | { | 439 | { |
439 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, | 440 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
440 | &endbadly, | 441 | &endbadly, |
441 | NULL); | 442 | NULL); |
442 | GNUNET_SCHEDULER_add_shutdown(&end, | 443 | GNUNET_SCHEDULER_add_shutdown (&end, |
443 | NULL); | 444 | NULL); |
444 | 445 | ||
445 | nsh = GNUNET_NAMESTORE_connect(cfg); | 446 | nsh = GNUNET_NAMESTORE_connect (cfg); |
446 | GNUNET_break(NULL != nsh); | 447 | GNUNET_break (NULL != nsh); |
447 | /* first, iterate over empty namestore */ | 448 | /* first, iterate over empty namestore */ |
448 | zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, | 449 | zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, |
449 | NULL, | 450 | NULL, |
450 | &fail_cb, | 451 | &fail_cb, |
451 | NULL, | 452 | NULL, |
452 | &empty_zone_proc, | 453 | &empty_zone_proc, |
453 | nsh, | 454 | nsh, |
454 | &empty_zone_end, | 455 | &empty_zone_end, |
455 | NULL); | 456 | NULL); |
456 | if (NULL == zi) | 457 | if (NULL == zi) |
457 | { | 458 | { |
458 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 459 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
459 | "Failed to create zone iterator\n"); | 460 | "Failed to create zone iterator\n"); |
460 | GNUNET_break(0); | 461 | GNUNET_break (0); |
461 | res = 1; | 462 | res = 1; |
462 | GNUNET_SCHEDULER_shutdown(); | 463 | GNUNET_SCHEDULER_shutdown (); |
463 | } | 464 | } |
464 | } | 465 | } |
465 | 466 | ||
466 | 467 | ||
@@ -468,24 +469,24 @@ run(void *cls, | |||
468 | 469 | ||
469 | 470 | ||
470 | int | 471 | int |
471 | main(int argc, char *argv[]) | 472 | main (int argc, char *argv[]) |
472 | { | 473 | { |
473 | const char *plugin_name; | 474 | const char *plugin_name; |
474 | char *cfg_name; | 475 | char *cfg_name; |
475 | 476 | ||
476 | SETUP_CFG(plugin_name, cfg_name); | 477 | SETUP_CFG (plugin_name, cfg_name); |
477 | res = 1; | 478 | res = 1; |
478 | if (0 != | 479 | if (0 != |
479 | GNUNET_TESTING_peer_run("test-namestore-api-zone-iteration", | 480 | GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration", |
480 | cfg_name, | 481 | cfg_name, |
481 | &run, | 482 | &run, |
482 | NULL)) | 483 | NULL)) |
483 | { | 484 | { |
484 | res = 1; | 485 | res = 1; |
485 | } | 486 | } |
486 | GNUNET_DISK_purge_cfg_dir(cfg_name, | 487 | GNUNET_DISK_purge_cfg_dir (cfg_name, |
487 | "GNUNET_TEST_HOME"); | 488 | "GNUNET_TEST_HOME"); |
488 | GNUNET_free(cfg_name); | 489 | GNUNET_free (cfg_name); |
489 | return res; | 490 | return res; |
490 | } | 491 | } |
491 | 492 | ||
diff --git a/src/namestore/test_namestore_api_zone_iteration_nick.c b/src/namestore/test_namestore_api_zone_iteration_nick.c index 739e71c05..35eab2735 100644 --- a/src/namestore/test_namestore_api_zone_iteration_nick.c +++ b/src/namestore/test_namestore_api_zone_iteration_nick.c | |||
@@ -32,14 +32,14 @@ | |||
32 | #define ZONE_NICK_1 "nick1" | 32 | #define ZONE_NICK_1 "nick1" |
33 | #define ZONE_NICK_2 "nick2" | 33 | #define ZONE_NICK_2 "nick2" |
34 | 34 | ||
35 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100) | 35 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) |
36 | 36 | ||
37 | 37 | ||
38 | static struct GNUNET_NAMESTORE_Handle * nsh; | 38 | static struct GNUNET_NAMESTORE_Handle *nsh; |
39 | 39 | ||
40 | static struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey; | 40 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; |
41 | 41 | ||
42 | static struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey2; | 42 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey2; |
43 | 43 | ||
44 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; | 44 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; |
45 | 45 | ||
@@ -47,15 +47,15 @@ static int res; | |||
47 | 47 | ||
48 | static int returned_records; | 48 | static int returned_records; |
49 | 49 | ||
50 | static char * s_name_1; | 50 | static char *s_name_1; |
51 | 51 | ||
52 | static struct GNUNET_GNSRECORD_Data *s_rd_1; | 52 | static struct GNUNET_GNSRECORD_Data *s_rd_1; |
53 | 53 | ||
54 | static char * s_name_2; | 54 | static char *s_name_2; |
55 | 55 | ||
56 | static struct GNUNET_GNSRECORD_Data *s_rd_2; | 56 | static struct GNUNET_GNSRECORD_Data *s_rd_2; |
57 | 57 | ||
58 | static char * s_name_3; | 58 | static char *s_name_3; |
59 | 59 | ||
60 | static struct GNUNET_GNSRECORD_Data *s_rd_3; | 60 | static struct GNUNET_GNSRECORD_Data *s_rd_3; |
61 | 61 | ||
@@ -69,266 +69,269 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe; | |||
69 | * @param tc scheduler context | 69 | * @param tc scheduler context |
70 | */ | 70 | */ |
71 | static void | 71 | static void |
72 | end(void *cls) | 72 | end (void *cls) |
73 | { | 73 | { |
74 | if (NULL != zi) | 74 | if (NULL != zi) |
75 | { | 75 | { |
76 | GNUNET_NAMESTORE_zone_iteration_stop(zi); | 76 | GNUNET_NAMESTORE_zone_iteration_stop (zi); |
77 | zi = NULL; | 77 | zi = NULL; |
78 | } | 78 | } |
79 | if (nsh != NULL) | 79 | if (nsh != NULL) |
80 | { | 80 | { |
81 | GNUNET_NAMESTORE_disconnect(nsh); | 81 | GNUNET_NAMESTORE_disconnect (nsh); |
82 | nsh = NULL; | 82 | nsh = NULL; |
83 | } | 83 | } |
84 | GNUNET_free_non_null(s_name_1); | 84 | GNUNET_free_non_null (s_name_1); |
85 | GNUNET_free_non_null(s_name_2); | 85 | GNUNET_free_non_null (s_name_2); |
86 | GNUNET_free_non_null(s_name_3); | 86 | GNUNET_free_non_null (s_name_3); |
87 | 87 | ||
88 | if (s_rd_1 != NULL) | 88 | if (s_rd_1 != NULL) |
89 | { | 89 | { |
90 | GNUNET_free((void *)s_rd_1->data); | 90 | GNUNET_free ((void *) s_rd_1->data); |
91 | GNUNET_free(s_rd_1); | 91 | GNUNET_free (s_rd_1); |
92 | } | 92 | } |
93 | if (s_rd_2 != NULL) | 93 | if (s_rd_2 != NULL) |
94 | { | 94 | { |
95 | GNUNET_free((void *)s_rd_2->data); | 95 | GNUNET_free ((void *) s_rd_2->data); |
96 | GNUNET_free(s_rd_2); | 96 | GNUNET_free (s_rd_2); |
97 | } | 97 | } |
98 | if (s_rd_3 != NULL) | 98 | if (s_rd_3 != NULL) |
99 | { | 99 | { |
100 | GNUNET_free((void *)s_rd_3->data); | 100 | GNUNET_free ((void *) s_rd_3->data); |
101 | GNUNET_free(s_rd_3); | 101 | GNUNET_free (s_rd_3); |
102 | } | 102 | } |
103 | 103 | ||
104 | if (privkey != NULL) | 104 | if (privkey != NULL) |
105 | { | 105 | { |
106 | GNUNET_free(privkey); | 106 | GNUNET_free (privkey); |
107 | privkey = NULL; | 107 | privkey = NULL; |
108 | } | 108 | } |
109 | if (privkey2 != NULL) | 109 | if (privkey2 != NULL) |
110 | { | 110 | { |
111 | GNUNET_free(privkey2); | 111 | GNUNET_free (privkey2); |
112 | privkey2 = NULL; | 112 | privkey2 = NULL; |
113 | } | 113 | } |
114 | } | 114 | } |
115 | 115 | ||
116 | 116 | ||
117 | static int | 117 | static int |
118 | check_zone_1(const char *label, unsigned int rd_count, | 118 | check_zone_1 (const char *label, unsigned int rd_count, |
119 | const struct GNUNET_GNSRECORD_Data *rd) | 119 | const struct GNUNET_GNSRECORD_Data *rd) |
120 | { | 120 | { |
121 | for (unsigned int c = 0; c < rd_count; c++) | 121 | for (unsigned int c = 0; c < rd_count; c++) |
122 | { | ||
123 | if ((rd[c].record_type == GNUNET_GNSRECORD_TYPE_NICK) && | ||
124 | (0 != strcmp (rd[c].data, ZONE_NICK_1))) | ||
122 | { | 125 | { |
123 | if ((rd[c].record_type == GNUNET_GNSRECORD_TYPE_NICK) && | 126 | GNUNET_break (0); |
124 | (0 != strcmp(rd[c].data, ZONE_NICK_1))) | 127 | return GNUNET_YES; |
125 | { | ||
126 | GNUNET_break(0); | ||
127 | return GNUNET_YES; | ||
128 | } | ||
129 | } | 128 | } |
129 | } | ||
130 | return GNUNET_NO; | 130 | return GNUNET_NO; |
131 | } | 131 | } |
132 | 132 | ||
133 | 133 | ||
134 | static int | 134 | static int |
135 | check_zone_2(const char *label, | 135 | check_zone_2 (const char *label, |
136 | unsigned int rd_count, | 136 | unsigned int rd_count, |
137 | const struct GNUNET_GNSRECORD_Data *rd) | 137 | const struct GNUNET_GNSRECORD_Data *rd) |
138 | { | 138 | { |
139 | for (unsigned int c = 0; c < rd_count; c++) | 139 | for (unsigned int c = 0; c < rd_count; c++) |
140 | { | ||
141 | if ((rd[c].record_type == GNUNET_GNSRECORD_TYPE_NICK) && | ||
142 | (0 != strcmp (rd[c].data, ZONE_NICK_2))) | ||
140 | { | 143 | { |
141 | if ((rd[c].record_type == GNUNET_GNSRECORD_TYPE_NICK) && | 144 | GNUNET_break (0); |
142 | (0 != strcmp(rd[c].data, ZONE_NICK_2))) | 145 | return GNUNET_YES; |
143 | { | ||
144 | GNUNET_break(0); | ||
145 | return GNUNET_YES; | ||
146 | } | ||
147 | } | 146 | } |
147 | } | ||
148 | return GNUNET_NO; | 148 | return GNUNET_NO; |
149 | } | 149 | } |
150 | 150 | ||
151 | 151 | ||
152 | static void | 152 | static void |
153 | zone_proc_end(void *cls) | 153 | zone_proc_end (void *cls) |
154 | { | 154 | { |
155 | zi = NULL; | 155 | zi = NULL; |
156 | res = 0; | 156 | res = 0; |
157 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 157 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
158 | "Received last result, iteration done after receing %u results\n", | 158 | "Received last result, iteration done after receing %u results\n", |
159 | returned_records); | 159 | returned_records); |
160 | GNUNET_SCHEDULER_shutdown(); | 160 | GNUNET_SCHEDULER_shutdown (); |
161 | } | 161 | } |
162 | 162 | ||
163 | 163 | ||
164 | static void | 164 | static void |
165 | zone_proc(void *cls, | 165 | zone_proc (void *cls, |
166 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 166 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
167 | const char *label, | 167 | const char *label, |
168 | unsigned int rd_count, | 168 | unsigned int rd_count, |
169 | const struct GNUNET_GNSRECORD_Data *rd) | 169 | const struct GNUNET_GNSRECORD_Data *rd) |
170 | { | 170 | { |
171 | int failed = GNUNET_NO; | 171 | int failed = GNUNET_NO; |
172 | 172 | ||
173 | GNUNET_assert(NULL != zone); | 173 | GNUNET_assert (NULL != zone); |
174 | if (0 == GNUNET_memcmp(zone, privkey)) | 174 | if (0 == GNUNET_memcmp (zone, privkey)) |
175 | { | 175 | { |
176 | failed = check_zone_1(label, rd_count, rd); | 176 | failed = check_zone_1 (label, rd_count, rd); |
177 | if (GNUNET_YES == failed) | 177 | if (GNUNET_YES == failed) |
178 | GNUNET_break(0); | 178 | GNUNET_break (0); |
179 | } | 179 | } |
180 | else if (0 == GNUNET_memcmp(zone, privkey2)) | 180 | else if (0 == GNUNET_memcmp (zone, privkey2)) |
181 | { | 181 | { |
182 | failed = check_zone_2(label, rd_count, rd); | 182 | failed = check_zone_2 (label, rd_count, rd); |
183 | if (GNUNET_YES == failed) | 183 | if (GNUNET_YES == failed) |
184 | GNUNET_break(0); | 184 | GNUNET_break (0); |
185 | } | 185 | } |
186 | else | 186 | else |
187 | { | 187 | { |
188 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 188 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
189 | "Received invalid zone\n"); | 189 | "Received invalid zone\n"); |
190 | failed = GNUNET_YES; | 190 | failed = GNUNET_YES; |
191 | GNUNET_break(0); | 191 | GNUNET_break (0); |
192 | } | 192 | } |
193 | 193 | ||
194 | if (failed == GNUNET_NO) | 194 | if (failed == GNUNET_NO) |
195 | { | 195 | { |
196 | returned_records++; | 196 | returned_records++; |
197 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 197 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
198 | "Telling namestore to send the next result\n"); | 198 | "Telling namestore to send the next result\n"); |
199 | GNUNET_NAMESTORE_zone_iterator_next(zi, | 199 | GNUNET_NAMESTORE_zone_iterator_next (zi, |
200 | 1); | 200 | 1); |
201 | } | 201 | } |
202 | else | 202 | else |
203 | { | 203 | { |
204 | GNUNET_break(0); | 204 | GNUNET_break (0); |
205 | res = 1; | 205 | res = 1; |
206 | GNUNET_SCHEDULER_shutdown(); | 206 | GNUNET_SCHEDULER_shutdown (); |
207 | } | 207 | } |
208 | } | 208 | } |
209 | 209 | ||
210 | 210 | ||
211 | static void | 211 | static void |
212 | fail_cb(void *cls) | 212 | fail_cb (void *cls) |
213 | { | 213 | { |
214 | GNUNET_assert(0); | 214 | GNUNET_assert (0); |
215 | } | 215 | } |
216 | 216 | ||
217 | 217 | ||
218 | static void | 218 | static void |
219 | put_cont(void *cls, | 219 | put_cont (void *cls, |
220 | int32_t success, | 220 | int32_t success, |
221 | const char *emsg) | 221 | const char *emsg) |
222 | { | 222 | { |
223 | static int c = 0; | 223 | static int c = 0; |
224 | 224 | ||
225 | if (success == GNUNET_OK) | 225 | if (success == GNUNET_OK) |
226 | { | 226 | { |
227 | c++; | 227 | c++; |
228 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c); | 228 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c); |
229 | } | 229 | } |
230 | else | 230 | else |
231 | { | 231 | { |
232 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to created records: `%s'\n", | 232 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records: `%s'\n", |
233 | emsg); | 233 | emsg); |
234 | GNUNET_break(0); | 234 | GNUNET_break (0); |
235 | GNUNET_SCHEDULER_shutdown(); | 235 | GNUNET_SCHEDULER_shutdown (); |
236 | return; | 236 | return; |
237 | } | 237 | } |
238 | 238 | ||
239 | if (c == 3) | 239 | if (c == 3) |
240 | { | ||
241 | res = 1; | ||
242 | returned_records = 0; | ||
243 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
244 | "All records created, starting iteration over all zones \n"); | ||
245 | zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, | ||
246 | NULL, | ||
247 | &fail_cb, | ||
248 | NULL, | ||
249 | &zone_proc, | ||
250 | NULL, | ||
251 | &zone_proc_end, | ||
252 | NULL); | ||
253 | if (zi == NULL) | ||
240 | { | 254 | { |
241 | res = 1; | 255 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n"); |
242 | returned_records = 0; | 256 | GNUNET_break (0); |
243 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "All records created, starting iteration over all zones \n"); | 257 | GNUNET_SCHEDULER_shutdown (); |
244 | zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, | 258 | return; |
245 | NULL, | ||
246 | &fail_cb, | ||
247 | NULL, | ||
248 | &zone_proc, | ||
249 | NULL, | ||
250 | &zone_proc_end, | ||
251 | NULL); | ||
252 | if (zi == NULL) | ||
253 | { | ||
254 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n"); | ||
255 | GNUNET_break(0); | ||
256 | GNUNET_SCHEDULER_shutdown(); | ||
257 | return; | ||
258 | } | ||
259 | } | 259 | } |
260 | } | ||
260 | } | 261 | } |
261 | 262 | ||
262 | 263 | ||
263 | static struct GNUNET_GNSRECORD_Data * | 264 | static struct GNUNET_GNSRECORD_Data * |
264 | create_record(unsigned int count) | 265 | create_record (unsigned int count) |
265 | { | 266 | { |
266 | struct GNUNET_GNSRECORD_Data * rd; | 267 | struct GNUNET_GNSRECORD_Data *rd; |
267 | 268 | ||
268 | rd = GNUNET_new_array(count, | 269 | rd = GNUNET_new_array (count, |
269 | struct GNUNET_GNSRECORD_Data); | 270 | struct GNUNET_GNSRECORD_Data); |
270 | for (unsigned int c = 0; c < count; c++) | 271 | for (unsigned int c = 0; c < count; c++) |
271 | { | 272 | { |
272 | rd[c].expiration_time = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS).abs_value_us; | 273 | rd[c].expiration_time = GNUNET_TIME_relative_to_absolute ( |
273 | rd[c].record_type = TEST_RECORD_TYPE; | 274 | GNUNET_TIME_UNIT_HOURS).abs_value_us; |
274 | rd[c].data_size = 50; | 275 | rd[c].record_type = TEST_RECORD_TYPE; |
275 | rd[c].data = GNUNET_malloc(50); | 276 | rd[c].data_size = 50; |
276 | rd[c].flags = 0; | 277 | rd[c].data = GNUNET_malloc (50); |
277 | memset((char *)rd[c].data, 'a', 50); | 278 | rd[c].flags = 0; |
278 | } | 279 | memset ((char *) rd[c].data, 'a', 50); |
280 | } | ||
279 | return rd; | 281 | return rd; |
280 | } | 282 | } |
281 | 283 | ||
282 | 284 | ||
283 | static void | 285 | static void |
284 | nick_2_cont(void *cls, | 286 | nick_2_cont (void *cls, |
285 | int32_t success, | 287 | int32_t success, |
286 | const char *emsg) | 288 | const char *emsg) |
287 | { | 289 | { |
288 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 290 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
289 | "Nick added : %s\n", | 291 | "Nick added : %s\n", |
290 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | 292 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); |
291 | 293 | ||
292 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); | 294 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); |
293 | 295 | ||
294 | GNUNET_asprintf(&s_name_1, "dummy1"); | 296 | GNUNET_asprintf (&s_name_1, "dummy1"); |
295 | s_rd_1 = create_record(1); | 297 | s_rd_1 = create_record (1); |
296 | GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1, | 298 | GNUNET_NAMESTORE_records_store (nsh, privkey, s_name_1, |
297 | 1, s_rd_1, | 299 | 1, s_rd_1, |
298 | &put_cont, NULL); | 300 | &put_cont, NULL); |
299 | 301 | ||
300 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 302 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
301 | "Created record 2 \n"); | 303 | "Created record 2 \n"); |
302 | GNUNET_asprintf(&s_name_2, "dummy2"); | 304 | GNUNET_asprintf (&s_name_2, "dummy2"); |
303 | s_rd_2 = create_record(1); | 305 | s_rd_2 = create_record (1); |
304 | GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_2, | 306 | GNUNET_NAMESTORE_records_store (nsh, privkey, s_name_2, |
305 | 1, s_rd_2, &put_cont, NULL); | 307 | 1, s_rd_2, &put_cont, NULL); |
306 | 308 | ||
307 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 309 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
308 | "Created record 3\n"); | 310 | "Created record 3\n"); |
309 | 311 | ||
310 | /* name in different zone */ | 312 | /* name in different zone */ |
311 | GNUNET_asprintf(&s_name_3, "dummy3"); | 313 | GNUNET_asprintf (&s_name_3, "dummy3"); |
312 | s_rd_3 = create_record(1); | 314 | s_rd_3 = create_record (1); |
313 | GNUNET_NAMESTORE_records_store(nsh, privkey2, s_name_3, | 315 | GNUNET_NAMESTORE_records_store (nsh, privkey2, s_name_3, |
314 | 1, s_rd_3, | 316 | 1, s_rd_3, |
315 | &put_cont, NULL); | 317 | &put_cont, NULL); |
316 | } | 318 | } |
317 | 319 | ||
318 | 320 | ||
319 | static void | 321 | static void |
320 | nick_1_cont(void *cls, int32_t success, const char *emsg) | 322 | nick_1_cont (void *cls, int32_t success, const char *emsg) |
321 | { | 323 | { |
322 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 324 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
323 | "Nick 1 added : %s\n", | 325 | "Nick 1 added : %s\n", |
324 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | 326 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); |
325 | 327 | ||
326 | nsqe = GNUNET_NAMESTORE_set_nick(nsh, privkey2, ZONE_NICK_2, &nick_2_cont, &privkey2); | 328 | nsqe = GNUNET_NAMESTORE_set_nick (nsh, privkey2, ZONE_NICK_2, &nick_2_cont, |
329 | &privkey2); | ||
327 | if (NULL == nsqe) | 330 | if (NULL == nsqe) |
328 | { | 331 | { |
329 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 332 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
330 | _("Namestore cannot store no block\n")); | 333 | _ ("Namestore cannot store no block\n")); |
331 | } | 334 | } |
332 | } | 335 | } |
333 | 336 | ||
334 | 337 | ||
@@ -338,82 +341,82 @@ nick_1_cont(void *cls, int32_t success, const char *emsg) | |||
338 | * start the actual tests by filling the zone. | 341 | * start the actual tests by filling the zone. |
339 | */ | 342 | */ |
340 | static void | 343 | static void |
341 | empty_zone_proc(void *cls, | 344 | empty_zone_proc (void *cls, |
342 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 345 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
343 | const char *label, | 346 | const char *label, |
344 | unsigned int rd_count, | 347 | unsigned int rd_count, |
345 | const struct GNUNET_GNSRECORD_Data *rd) | 348 | const struct GNUNET_GNSRECORD_Data *rd) |
346 | { | 349 | { |
347 | GNUNET_assert(nsh == cls); | 350 | GNUNET_assert (nsh == cls); |
348 | 351 | ||
349 | if (NULL != zone) | 352 | if (NULL != zone) |
350 | { | 353 | { |
351 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 354 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
352 | _("Expected empty zone but received zone private key\n")); | 355 | _ ("Expected empty zone but received zone private key\n")); |
353 | GNUNET_break(0); | 356 | GNUNET_break (0); |
354 | GNUNET_SCHEDULER_shutdown(); | 357 | GNUNET_SCHEDULER_shutdown (); |
355 | return; | 358 | return; |
356 | } | 359 | } |
357 | if ((NULL != label) || (NULL != rd) || (0 != rd_count)) | 360 | if ((NULL != label) || (NULL != rd) || (0 != rd_count)) |
358 | { | 361 | { |
359 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 362 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
360 | _("Expected no zone content but received data\n")); | 363 | _ ("Expected no zone content but received data\n")); |
361 | GNUNET_break(0); | 364 | GNUNET_break (0); |
362 | GNUNET_SCHEDULER_shutdown(); | 365 | GNUNET_SCHEDULER_shutdown (); |
363 | return; | 366 | return; |
364 | } | 367 | } |
365 | GNUNET_assert(0); | 368 | GNUNET_assert (0); |
366 | } | 369 | } |
367 | 370 | ||
368 | 371 | ||
369 | static void | 372 | static void |
370 | empty_zone_end(void *cls) | 373 | empty_zone_end (void *cls) |
371 | { | 374 | { |
372 | GNUNET_assert(nsh == cls); | 375 | GNUNET_assert (nsh == cls); |
373 | zi = NULL; | 376 | zi = NULL; |
374 | privkey = GNUNET_CRYPTO_ecdsa_key_create(); | 377 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); |
375 | GNUNET_assert(privkey != NULL); | 378 | GNUNET_assert (privkey != NULL); |
376 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create(); | 379 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create (); |
377 | GNUNET_assert(privkey2 != NULL); | 380 | GNUNET_assert (privkey2 != NULL); |
378 | 381 | ||
379 | nsqe = GNUNET_NAMESTORE_set_nick(nsh, | 382 | nsqe = GNUNET_NAMESTORE_set_nick (nsh, |
380 | privkey, | 383 | privkey, |
381 | ZONE_NICK_1, | 384 | ZONE_NICK_1, |
382 | &nick_1_cont, | 385 | &nick_1_cont, |
383 | &privkey); | 386 | &privkey); |
384 | if (NULL == nsqe) | 387 | if (NULL == nsqe) |
385 | { | 388 | { |
386 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 389 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
387 | _("Namestore cannot store no block\n")); | 390 | _ ("Namestore cannot store no block\n")); |
388 | } | 391 | } |
389 | } | 392 | } |
390 | 393 | ||
391 | 394 | ||
392 | static void | 395 | static void |
393 | run(void *cls, | 396 | run (void *cls, |
394 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 397 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
395 | struct GNUNET_TESTING_Peer *peer) | 398 | struct GNUNET_TESTING_Peer *peer) |
396 | { | 399 | { |
397 | nsh = GNUNET_NAMESTORE_connect(cfg); | 400 | nsh = GNUNET_NAMESTORE_connect (cfg); |
398 | GNUNET_break(NULL != nsh); | 401 | GNUNET_break (NULL != nsh); |
399 | GNUNET_SCHEDULER_add_shutdown(&end, | 402 | GNUNET_SCHEDULER_add_shutdown (&end, |
400 | NULL); | 403 | NULL); |
401 | /* first, iterate over empty namestore */ | 404 | /* first, iterate over empty namestore */ |
402 | zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, | 405 | zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, |
403 | NULL, | 406 | NULL, |
404 | &fail_cb, | 407 | &fail_cb, |
405 | NULL, | 408 | NULL, |
406 | &empty_zone_proc, | 409 | &empty_zone_proc, |
407 | nsh, | 410 | nsh, |
408 | &empty_zone_end, | 411 | &empty_zone_end, |
409 | nsh); | 412 | nsh); |
410 | if (NULL == zi) | 413 | if (NULL == zi) |
411 | { | 414 | { |
412 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 415 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
413 | "Failed to create zone iterator\n"); | 416 | "Failed to create zone iterator\n"); |
414 | GNUNET_break(0); | 417 | GNUNET_break (0); |
415 | GNUNET_SCHEDULER_shutdown(); | 418 | GNUNET_SCHEDULER_shutdown (); |
416 | } | 419 | } |
417 | } | 420 | } |
418 | 421 | ||
419 | 422 | ||
@@ -421,24 +424,24 @@ run(void *cls, | |||
421 | 424 | ||
422 | 425 | ||
423 | int | 426 | int |
424 | main(int argc, char *argv[]) | 427 | main (int argc, char *argv[]) |
425 | { | 428 | { |
426 | const char *plugin_name; | 429 | const char *plugin_name; |
427 | char *cfg_name; | 430 | char *cfg_name; |
428 | 431 | ||
429 | SETUP_CFG(plugin_name, cfg_name); | 432 | SETUP_CFG (plugin_name, cfg_name); |
430 | res = 1; | 433 | res = 1; |
431 | if (0 != | 434 | if (0 != |
432 | GNUNET_TESTING_peer_run("test-namestore-api-zone-iteration-nick", | 435 | GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-nick", |
433 | cfg_name, | 436 | cfg_name, |
434 | &run, | 437 | &run, |
435 | NULL)) | 438 | NULL)) |
436 | { | 439 | { |
437 | res = 1; | 440 | res = 1; |
438 | } | 441 | } |
439 | GNUNET_DISK_purge_cfg_dir(cfg_name, | 442 | GNUNET_DISK_purge_cfg_dir (cfg_name, |
440 | "GNUNET_TEST_HOME"); | 443 | "GNUNET_TEST_HOME"); |
441 | GNUNET_free(cfg_name); | 444 | GNUNET_free (cfg_name); |
442 | return res; | 445 | return res; |
443 | } | 446 | } |
444 | 447 | ||
diff --git a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c index 924e1eb1e..50c247b14 100644 --- a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c +++ b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c | |||
@@ -31,16 +31,16 @@ | |||
31 | #define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT | 31 | #define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT |
32 | 32 | ||
33 | 33 | ||
34 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100) | 34 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) |
35 | 35 | ||
36 | 36 | ||
37 | static struct GNUNET_NAMESTORE_Handle * nsh; | 37 | static struct GNUNET_NAMESTORE_Handle *nsh; |
38 | 38 | ||
39 | static struct GNUNET_SCHEDULER_Task * endbadly_task; | 39 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
40 | 40 | ||
41 | static struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey; | 41 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; |
42 | 42 | ||
43 | static struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey2; | 43 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey2; |
44 | 44 | ||
45 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; | 45 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; |
46 | 46 | ||
@@ -48,15 +48,15 @@ static int res; | |||
48 | 48 | ||
49 | static int returned_records; | 49 | static int returned_records; |
50 | 50 | ||
51 | static char * s_name_1; | 51 | static char *s_name_1; |
52 | 52 | ||
53 | static struct GNUNET_GNSRECORD_Data *s_rd_1; | 53 | static struct GNUNET_GNSRECORD_Data *s_rd_1; |
54 | 54 | ||
55 | static char * s_name_2; | 55 | static char *s_name_2; |
56 | 56 | ||
57 | static struct GNUNET_GNSRECORD_Data *s_rd_2; | 57 | static struct GNUNET_GNSRECORD_Data *s_rd_2; |
58 | 58 | ||
59 | static char * s_name_3; | 59 | static char *s_name_3; |
60 | 60 | ||
61 | static struct GNUNET_GNSRECORD_Data *s_rd_3; | 61 | static struct GNUNET_GNSRECORD_Data *s_rd_3; |
62 | 62 | ||
@@ -67,246 +67,247 @@ static struct GNUNET_GNSRECORD_Data *s_rd_3; | |||
67 | * @param cls handle to use to re-connect. | 67 | * @param cls handle to use to re-connect. |
68 | */ | 68 | */ |
69 | static void | 69 | static void |
70 | endbadly(void *cls) | 70 | endbadly (void *cls) |
71 | { | 71 | { |
72 | endbadly_task = NULL; | 72 | endbadly_task = NULL; |
73 | GNUNET_SCHEDULER_shutdown(); | 73 | GNUNET_SCHEDULER_shutdown (); |
74 | res = 1; | 74 | res = 1; |
75 | } | 75 | } |
76 | 76 | ||
77 | 77 | ||
78 | static void | 78 | static void |
79 | end(void *cls) | 79 | end (void *cls) |
80 | { | 80 | { |
81 | if (NULL != zi) | 81 | if (NULL != zi) |
82 | { | 82 | { |
83 | GNUNET_NAMESTORE_zone_iteration_stop(zi); | 83 | GNUNET_NAMESTORE_zone_iteration_stop (zi); |
84 | zi = NULL; | 84 | zi = NULL; |
85 | } | 85 | } |
86 | if (NULL != endbadly_task) | 86 | if (NULL != endbadly_task) |
87 | { | 87 | { |
88 | GNUNET_SCHEDULER_cancel(endbadly_task); | 88 | GNUNET_SCHEDULER_cancel (endbadly_task); |
89 | endbadly_task = NULL; | 89 | endbadly_task = NULL; |
90 | } | 90 | } |
91 | if (NULL != privkey) | 91 | if (NULL != privkey) |
92 | { | 92 | { |
93 | GNUNET_free(privkey); | 93 | GNUNET_free (privkey); |
94 | privkey = NULL; | 94 | privkey = NULL; |
95 | } | 95 | } |
96 | if (NULL != privkey2) | 96 | if (NULL != privkey2) |
97 | { | 97 | { |
98 | GNUNET_free(privkey2); | 98 | GNUNET_free (privkey2); |
99 | privkey2 = NULL; | 99 | privkey2 = NULL; |
100 | } | 100 | } |
101 | GNUNET_free_non_null(s_name_1); | 101 | GNUNET_free_non_null (s_name_1); |
102 | GNUNET_free_non_null(s_name_2); | 102 | GNUNET_free_non_null (s_name_2); |
103 | GNUNET_free_non_null(s_name_3); | 103 | GNUNET_free_non_null (s_name_3); |
104 | if (s_rd_1 != NULL) | 104 | if (s_rd_1 != NULL) |
105 | { | 105 | { |
106 | GNUNET_free((void *)s_rd_1->data); | 106 | GNUNET_free ((void *) s_rd_1->data); |
107 | GNUNET_free(s_rd_1); | 107 | GNUNET_free (s_rd_1); |
108 | } | 108 | } |
109 | if (s_rd_2 != NULL) | 109 | if (s_rd_2 != NULL) |
110 | { | 110 | { |
111 | GNUNET_free((void *)s_rd_2->data); | 111 | GNUNET_free ((void *) s_rd_2->data); |
112 | GNUNET_free(s_rd_2); | 112 | GNUNET_free (s_rd_2); |
113 | } | 113 | } |
114 | if (s_rd_3 != NULL) | 114 | if (s_rd_3 != NULL) |
115 | { | 115 | { |
116 | GNUNET_free((void *)s_rd_3->data); | 116 | GNUNET_free ((void *) s_rd_3->data); |
117 | GNUNET_free(s_rd_3); | 117 | GNUNET_free (s_rd_3); |
118 | } | 118 | } |
119 | if (nsh != NULL) | 119 | if (nsh != NULL) |
120 | { | 120 | { |
121 | GNUNET_NAMESTORE_disconnect(nsh); | 121 | GNUNET_NAMESTORE_disconnect (nsh); |
122 | nsh = NULL; | 122 | nsh = NULL; |
123 | } | 123 | } |
124 | } | 124 | } |
125 | 125 | ||
126 | 126 | ||
127 | static void | 127 | static void |
128 | fail_cb(void *cls) | 128 | fail_cb (void *cls) |
129 | { | 129 | { |
130 | GNUNET_assert(0); | 130 | GNUNET_assert (0); |
131 | zi = NULL; | 131 | zi = NULL; |
132 | } | 132 | } |
133 | 133 | ||
134 | 134 | ||
135 | static void | 135 | static void |
136 | zone_proc(void *cls, | 136 | zone_proc (void *cls, |
137 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 137 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
138 | const char *label, | 138 | const char *label, |
139 | unsigned int rd_count, | 139 | unsigned int rd_count, |
140 | const struct GNUNET_GNSRECORD_Data *rd) | 140 | const struct GNUNET_GNSRECORD_Data *rd) |
141 | { | 141 | { |
142 | int failed = GNUNET_NO; | 142 | int failed = GNUNET_NO; |
143 | 143 | ||
144 | GNUNET_assert(NULL != zone); | 144 | GNUNET_assert (NULL != zone); |
145 | if (0 == GNUNET_memcmp(zone, | 145 | if (0 == GNUNET_memcmp (zone, |
146 | privkey)) | 146 | privkey)) |
147 | { | ||
148 | if (0 == strcmp (label, s_name_1)) | ||
147 | { | 149 | { |
148 | if (0 == strcmp(label, s_name_1)) | 150 | if (rd_count == 1) |
151 | { | ||
152 | if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_1)) | ||
149 | { | 153 | { |
150 | if (rd_count == 1) | 154 | failed = GNUNET_YES; |
151 | { | 155 | GNUNET_break (0); |
152 | if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_1)) | ||
153 | { | ||
154 | failed = GNUNET_YES; | ||
155 | GNUNET_break(0); | ||
156 | } | ||
157 | } | ||
158 | else | ||
159 | { | ||
160 | failed = GNUNET_YES; | ||
161 | GNUNET_break(0); | ||
162 | } | ||
163 | } | ||
164 | else if (0 == strcmp(label, s_name_2)) | ||
165 | { | ||
166 | if (rd_count == 1) | ||
167 | { | ||
168 | if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_2)) | ||
169 | { | ||
170 | failed = GNUNET_YES; | ||
171 | GNUNET_break(0); | ||
172 | } | ||
173 | } | ||
174 | else | ||
175 | { | ||
176 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
177 | "Received invalid record count\n"); | ||
178 | failed = GNUNET_YES; | ||
179 | GNUNET_break(0); | ||
180 | } | ||
181 | } | 156 | } |
157 | } | ||
182 | else | 158 | else |
159 | { | ||
160 | failed = GNUNET_YES; | ||
161 | GNUNET_break (0); | ||
162 | } | ||
163 | } | ||
164 | else if (0 == strcmp (label, s_name_2)) | ||
165 | { | ||
166 | if (rd_count == 1) | ||
167 | { | ||
168 | if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_2)) | ||
183 | { | 169 | { |
184 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
185 | "Comparing result failed: got name `%s' for first zone\n", | ||
186 | label); | ||
187 | failed = GNUNET_YES; | 170 | failed = GNUNET_YES; |
188 | GNUNET_break(0); | 171 | GNUNET_break (0); |
189 | } | 172 | } |
173 | } | ||
174 | else | ||
175 | { | ||
176 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
177 | "Received invalid record count\n"); | ||
178 | failed = GNUNET_YES; | ||
179 | GNUNET_break (0); | ||
180 | } | ||
190 | } | 181 | } |
191 | else if (0 == GNUNET_memcmp(zone, privkey2)) | 182 | else |
192 | { | 183 | { |
193 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 184 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
194 | "Received data for not requested zone\n"); | 185 | "Comparing result failed: got name `%s' for first zone\n", |
186 | label); | ||
195 | failed = GNUNET_YES; | 187 | failed = GNUNET_YES; |
196 | GNUNET_break(0); | 188 | GNUNET_break (0); |
197 | } | 189 | } |
190 | } | ||
191 | else if (0 == GNUNET_memcmp (zone, privkey2)) | ||
192 | { | ||
193 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
194 | "Received data for not requested zone\n"); | ||
195 | failed = GNUNET_YES; | ||
196 | GNUNET_break (0); | ||
197 | } | ||
198 | else | 198 | else |
199 | { | 199 | { |
200 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 200 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
201 | "Received invalid zone\n"); | 201 | "Received invalid zone\n"); |
202 | failed = GNUNET_YES; | 202 | failed = GNUNET_YES; |
203 | GNUNET_break(0); | 203 | GNUNET_break (0); |
204 | } | 204 | } |
205 | if (failed == GNUNET_NO) | 205 | if (failed == GNUNET_NO) |
206 | { | 206 | { |
207 | returned_records++; | 207 | returned_records++; |
208 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 208 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
209 | "Telling namestore to send the next result\n"); | 209 | "Telling namestore to send the next result\n"); |
210 | GNUNET_NAMESTORE_zone_iterator_next(zi, | 210 | GNUNET_NAMESTORE_zone_iterator_next (zi, |
211 | 1); | 211 | 1); |
212 | } | 212 | } |
213 | else | 213 | else |
214 | { | 214 | { |
215 | GNUNET_break(0); | 215 | GNUNET_break (0); |
216 | res = 2; | 216 | res = 2; |
217 | GNUNET_SCHEDULER_shutdown(); | 217 | GNUNET_SCHEDULER_shutdown (); |
218 | } | 218 | } |
219 | } | 219 | } |
220 | 220 | ||
221 | 221 | ||
222 | static void | 222 | static void |
223 | zone_proc_end(void *cls) | 223 | zone_proc_end (void *cls) |
224 | { | 224 | { |
225 | zi = NULL; | 225 | zi = NULL; |
226 | GNUNET_break(2 == returned_records); | 226 | GNUNET_break (2 == returned_records); |
227 | if (2 == returned_records) | 227 | if (2 == returned_records) |
228 | { | 228 | { |
229 | res = 0; /* Last iteraterator callback, we are done */ | 229 | res = 0; /* Last iteraterator callback, we are done */ |
230 | } | 230 | } |
231 | else | 231 | else |
232 | { | 232 | { |
233 | res = 1; | 233 | res = 1; |
234 | } | 234 | } |
235 | 235 | ||
236 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 236 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
237 | "Received last result, iteration done after receing %u results\n", | 237 | "Received last result, iteration done after receing %u results\n", |
238 | returned_records); | 238 | returned_records); |
239 | GNUNET_SCHEDULER_shutdown(); | 239 | GNUNET_SCHEDULER_shutdown (); |
240 | } | 240 | } |
241 | 241 | ||
242 | 242 | ||
243 | static void | 243 | static void |
244 | put_cont(void *cls, | 244 | put_cont (void *cls, |
245 | int32_t success, | 245 | int32_t success, |
246 | const char *emsg) | 246 | const char *emsg) |
247 | { | 247 | { |
248 | static int c = 0; | 248 | static int c = 0; |
249 | 249 | ||
250 | if (success == GNUNET_OK) | 250 | if (success == GNUNET_OK) |
251 | { | 251 | { |
252 | c++; | 252 | c++; |
253 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 253 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
254 | "Created record %u \n", c); | 254 | "Created record %u \n", c); |
255 | } | 255 | } |
256 | else | 256 | else |
257 | { | 257 | { |
258 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 258 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
259 | "Failed to created records: `%s'\n", | 259 | "Failed to created records: `%s'\n", |
260 | emsg); | 260 | emsg); |
261 | GNUNET_break(0); | 261 | GNUNET_break (0); |
262 | res = 2; | 262 | res = 2; |
263 | GNUNET_SCHEDULER_shutdown(); | 263 | GNUNET_SCHEDULER_shutdown (); |
264 | return; | 264 | return; |
265 | } | 265 | } |
266 | 266 | ||
267 | if (c == 3) | 267 | if (c == 3) |
268 | { | ||
269 | res = 1; | ||
270 | returned_records = 0; | ||
271 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
272 | "All records created, starting iteration over all zones \n"); | ||
273 | zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, | ||
274 | privkey, | ||
275 | &fail_cb, | ||
276 | NULL, | ||
277 | &zone_proc, | ||
278 | NULL, | ||
279 | &zone_proc_end, | ||
280 | NULL); | ||
281 | if (zi == NULL) | ||
268 | { | 282 | { |
269 | res = 1; | 283 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
270 | returned_records = 0; | 284 | "Failed to create zone iterator\n"); |
271 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 285 | GNUNET_break (0); |
272 | "All records created, starting iteration over all zones \n"); | 286 | res = 2; |
273 | zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, | 287 | GNUNET_SCHEDULER_shutdown (); |
274 | privkey, | 288 | return; |
275 | &fail_cb, | ||
276 | NULL, | ||
277 | &zone_proc, | ||
278 | NULL, | ||
279 | &zone_proc_end, | ||
280 | NULL); | ||
281 | if (zi == NULL) | ||
282 | { | ||
283 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
284 | "Failed to create zone iterator\n"); | ||
285 | GNUNET_break(0); | ||
286 | res = 2; | ||
287 | GNUNET_SCHEDULER_shutdown(); | ||
288 | return; | ||
289 | } | ||
290 | } | 289 | } |
290 | } | ||
291 | } | 291 | } |
292 | 292 | ||
293 | 293 | ||
294 | static struct GNUNET_GNSRECORD_Data * | 294 | static struct GNUNET_GNSRECORD_Data * |
295 | create_record(unsigned int count) | 295 | create_record (unsigned int count) |
296 | { | 296 | { |
297 | struct GNUNET_GNSRECORD_Data *rd; | 297 | struct GNUNET_GNSRECORD_Data *rd; |
298 | 298 | ||
299 | rd = GNUNET_new_array(count, | 299 | rd = GNUNET_new_array (count, |
300 | struct GNUNET_GNSRECORD_Data); | 300 | struct GNUNET_GNSRECORD_Data); |
301 | for (unsigned int c = 0; c < count; c++) | 301 | for (unsigned int c = 0; c < count; c++) |
302 | { | 302 | { |
303 | rd[c].expiration_time = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS).abs_value_us; | 303 | rd[c].expiration_time = GNUNET_TIME_relative_to_absolute ( |
304 | rd[c].record_type = TEST_RECORD_TYPE; | 304 | GNUNET_TIME_UNIT_HOURS).abs_value_us; |
305 | rd[c].data_size = 50; | 305 | rd[c].record_type = TEST_RECORD_TYPE; |
306 | rd[c].data = GNUNET_malloc(50); | 306 | rd[c].data_size = 50; |
307 | rd[c].flags = 0; | 307 | rd[c].data = GNUNET_malloc (50); |
308 | memset((char *)rd[c].data, 'a', 50); | 308 | rd[c].flags = 0; |
309 | } | 309 | memset ((char *) rd[c].data, 'a', 50); |
310 | } | ||
310 | return rd; | 311 | return rd; |
311 | } | 312 | } |
312 | 313 | ||
@@ -317,114 +318,114 @@ create_record(unsigned int count) | |||
317 | * start the actual tests by filling the zone. | 318 | * start the actual tests by filling the zone. |
318 | */ | 319 | */ |
319 | static void | 320 | static void |
320 | empty_zone_proc(void *cls, | 321 | empty_zone_proc (void *cls, |
321 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 322 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
322 | const char *label, | 323 | const char *label, |
323 | unsigned int rd_count, | 324 | unsigned int rd_count, |
324 | const struct GNUNET_GNSRECORD_Data *rd) | 325 | const struct GNUNET_GNSRECORD_Data *rd) |
325 | { | 326 | { |
326 | GNUNET_assert(nsh == cls); | 327 | GNUNET_assert (nsh == cls); |
327 | if (NULL != zone) | 328 | if (NULL != zone) |
328 | { | 329 | { |
329 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 330 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
330 | _("Expected empty zone but received zone private key\n")); | 331 | _ ("Expected empty zone but received zone private key\n")); |
331 | GNUNET_break(0); | 332 | GNUNET_break (0); |
332 | res = 2; | 333 | res = 2; |
333 | GNUNET_SCHEDULER_shutdown(); | 334 | GNUNET_SCHEDULER_shutdown (); |
334 | return; | 335 | return; |
335 | } | 336 | } |
336 | if ((NULL != label) || (NULL != rd) || (0 != rd_count)) | 337 | if ((NULL != label) || (NULL != rd) || (0 != rd_count)) |
337 | { | 338 | { |
338 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 339 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
339 | _("Expected no zone content but received data\n")); | 340 | _ ("Expected no zone content but received data\n")); |
340 | GNUNET_break(0); | 341 | GNUNET_break (0); |
341 | res = 2; | 342 | res = 2; |
342 | GNUNET_SCHEDULER_shutdown(); | 343 | GNUNET_SCHEDULER_shutdown (); |
343 | return; | 344 | return; |
344 | } | 345 | } |
345 | GNUNET_assert(0); | 346 | GNUNET_assert (0); |
346 | } | 347 | } |
347 | 348 | ||
348 | 349 | ||
349 | static void | 350 | static void |
350 | empty_zone_proc_end(void *cls) | 351 | empty_zone_proc_end (void *cls) |
351 | { | 352 | { |
352 | zi = NULL; | 353 | zi = NULL; |
353 | privkey = GNUNET_CRYPTO_ecdsa_key_create(); | 354 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); |
354 | GNUNET_assert(privkey != NULL); | 355 | GNUNET_assert (privkey != NULL); |
355 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create(); | 356 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create (); |
356 | GNUNET_assert(privkey2 != NULL); | 357 | GNUNET_assert (privkey2 != NULL); |
357 | 358 | ||
358 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 359 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
359 | "Created record 1\n"); | 360 | "Created record 1\n"); |
360 | GNUNET_asprintf(&s_name_1, | 361 | GNUNET_asprintf (&s_name_1, |
361 | "dummy1"); | 362 | "dummy1"); |
362 | s_rd_1 = create_record(1); | 363 | s_rd_1 = create_record (1); |
363 | GNUNET_NAMESTORE_records_store(nsh, | 364 | GNUNET_NAMESTORE_records_store (nsh, |
364 | privkey, | 365 | privkey, |
365 | s_name_1, | 366 | s_name_1, |
366 | 1, | 367 | 1, |
367 | s_rd_1, | 368 | s_rd_1, |
368 | &put_cont, | 369 | &put_cont, |
369 | NULL); | 370 | NULL); |
370 | 371 | ||
371 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 372 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
372 | "Created record 2 \n"); | 373 | "Created record 2 \n"); |
373 | GNUNET_asprintf(&s_name_2, | 374 | GNUNET_asprintf (&s_name_2, |
374 | "dummy2"); | 375 | "dummy2"); |
375 | s_rd_2 = create_record(1); | 376 | s_rd_2 = create_record (1); |
376 | GNUNET_NAMESTORE_records_store(nsh, | 377 | GNUNET_NAMESTORE_records_store (nsh, |
377 | privkey, | 378 | privkey, |
378 | s_name_2, | 379 | s_name_2, |
379 | 1, | 380 | 1, |
380 | s_rd_2, | 381 | s_rd_2, |
381 | &put_cont, | 382 | &put_cont, |
382 | NULL); | 383 | NULL); |
383 | 384 | ||
384 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 385 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
385 | "Created record 3\n"); | 386 | "Created record 3\n"); |
386 | 387 | ||
387 | /* name in different zone */ | 388 | /* name in different zone */ |
388 | GNUNET_asprintf(&s_name_3, | 389 | GNUNET_asprintf (&s_name_3, |
389 | "dummy3"); | 390 | "dummy3"); |
390 | s_rd_3 = create_record(1); | 391 | s_rd_3 = create_record (1); |
391 | GNUNET_NAMESTORE_records_store(nsh, | 392 | GNUNET_NAMESTORE_records_store (nsh, |
392 | privkey2, | 393 | privkey2, |
393 | s_name_3, | 394 | s_name_3, |
394 | 1, s_rd_3, | 395 | 1, s_rd_3, |
395 | &put_cont, | 396 | &put_cont, |
396 | NULL); | 397 | NULL); |
397 | } | 398 | } |
398 | 399 | ||
399 | 400 | ||
400 | static void | 401 | static void |
401 | run(void *cls, | 402 | run (void *cls, |
402 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 403 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
403 | struct GNUNET_TESTING_Peer *peer) | 404 | struct GNUNET_TESTING_Peer *peer) |
404 | { | 405 | { |
405 | GNUNET_SCHEDULER_add_shutdown(&end, | 406 | GNUNET_SCHEDULER_add_shutdown (&end, |
406 | NULL); | 407 | NULL); |
407 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, | 408 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
408 | &endbadly, | 409 | &endbadly, |
409 | NULL); | 410 | NULL); |
410 | nsh = GNUNET_NAMESTORE_connect(cfg); | 411 | nsh = GNUNET_NAMESTORE_connect (cfg); |
411 | GNUNET_break(NULL != nsh); | 412 | GNUNET_break (NULL != nsh); |
412 | /* first, iterate over empty namestore */ | 413 | /* first, iterate over empty namestore */ |
413 | zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, | 414 | zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, |
414 | NULL, | 415 | NULL, |
415 | &fail_cb, | 416 | &fail_cb, |
416 | NULL, | 417 | NULL, |
417 | &empty_zone_proc, | 418 | &empty_zone_proc, |
418 | nsh, | 419 | nsh, |
419 | &empty_zone_proc_end, | 420 | &empty_zone_proc_end, |
420 | nsh); | 421 | nsh); |
421 | if (NULL == zi) | 422 | if (NULL == zi) |
422 | { | 423 | { |
423 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 424 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
424 | "Failed to create zone iterator\n"); | 425 | "Failed to create zone iterator\n"); |
425 | GNUNET_break(0); | 426 | GNUNET_break (0); |
426 | GNUNET_SCHEDULER_shutdown(); | 427 | GNUNET_SCHEDULER_shutdown (); |
427 | } | 428 | } |
428 | } | 429 | } |
429 | 430 | ||
430 | 431 | ||
@@ -432,24 +433,25 @@ run(void *cls, | |||
432 | 433 | ||
433 | 434 | ||
434 | int | 435 | int |
435 | main(int argc, char *argv[]) | 436 | main (int argc, char *argv[]) |
436 | { | 437 | { |
437 | const char *plugin_name; | 438 | const char *plugin_name; |
438 | char *cfg_name; | 439 | char *cfg_name; |
439 | 440 | ||
440 | SETUP_CFG(plugin_name, cfg_name); | 441 | SETUP_CFG (plugin_name, cfg_name); |
441 | res = 1; | 442 | res = 1; |
442 | if (0 != | 443 | if (0 != |
443 | GNUNET_TESTING_peer_run("test-namestore-api-zone-iteration-specific-zone", | 444 | GNUNET_TESTING_peer_run ( |
444 | cfg_name, | 445 | "test-namestore-api-zone-iteration-specific-zone", |
445 | &run, | 446 | cfg_name, |
446 | NULL)) | 447 | &run, |
447 | { | 448 | NULL)) |
448 | res = 1; | 449 | { |
449 | } | 450 | res = 1; |
450 | GNUNET_DISK_purge_cfg_dir(cfg_name, | 451 | } |
451 | "GNUNET_TEST_HOME"); | 452 | GNUNET_DISK_purge_cfg_dir (cfg_name, |
452 | GNUNET_free(cfg_name); | 453 | "GNUNET_TEST_HOME"); |
454 | GNUNET_free (cfg_name); | ||
453 | return res; | 455 | return res; |
454 | } | 456 | } |
455 | 457 | ||
diff --git a/src/namestore/test_namestore_api_zone_iteration_stop.c b/src/namestore/test_namestore_api_zone_iteration_stop.c index 89007c82c..2f8ea9a97 100644 --- a/src/namestore/test_namestore_api_zone_iteration_stop.c +++ b/src/namestore/test_namestore_api_zone_iteration_stop.c | |||
@@ -29,14 +29,14 @@ | |||
29 | 29 | ||
30 | #define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT | 30 | #define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT |
31 | 31 | ||
32 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100) | 32 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) |
33 | #define WAIT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2) | 33 | #define WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2) |
34 | 34 | ||
35 | static struct GNUNET_NAMESTORE_Handle * nsh; | 35 | static struct GNUNET_NAMESTORE_Handle *nsh; |
36 | 36 | ||
37 | static struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey; | 37 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; |
38 | 38 | ||
39 | static struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey2; | 39 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey2; |
40 | 40 | ||
41 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; | 41 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; |
42 | 42 | ||
@@ -44,15 +44,15 @@ static int res; | |||
44 | 44 | ||
45 | static int returned_records; | 45 | static int returned_records; |
46 | 46 | ||
47 | static char * s_name_1; | 47 | static char *s_name_1; |
48 | 48 | ||
49 | static struct GNUNET_GNSRECORD_Data *s_rd_1; | 49 | static struct GNUNET_GNSRECORD_Data *s_rd_1; |
50 | 50 | ||
51 | static char * s_name_2; | 51 | static char *s_name_2; |
52 | 52 | ||
53 | static struct GNUNET_GNSRECORD_Data *s_rd_2; | 53 | static struct GNUNET_GNSRECORD_Data *s_rd_2; |
54 | 54 | ||
55 | static char * s_name_3; | 55 | static char *s_name_3; |
56 | 56 | ||
57 | static struct GNUNET_GNSRECORD_Data *s_rd_3; | 57 | static struct GNUNET_GNSRECORD_Data *s_rd_3; |
58 | 58 | ||
@@ -63,257 +63,260 @@ static struct GNUNET_GNSRECORD_Data *s_rd_3; | |||
63 | * @param cls handle to use to re-connect. | 63 | * @param cls handle to use to re-connect. |
64 | */ | 64 | */ |
65 | static void | 65 | static void |
66 | end(void *cls) | 66 | end (void *cls) |
67 | { | 67 | { |
68 | if (NULL != zi) | 68 | if (NULL != zi) |
69 | { | 69 | { |
70 | GNUNET_NAMESTORE_zone_iteration_stop(zi); | 70 | GNUNET_NAMESTORE_zone_iteration_stop (zi); |
71 | zi = NULL; | 71 | zi = NULL; |
72 | } | 72 | } |
73 | if (nsh != NULL) | 73 | if (nsh != NULL) |
74 | { | 74 | { |
75 | GNUNET_NAMESTORE_disconnect(nsh); | 75 | GNUNET_NAMESTORE_disconnect (nsh); |
76 | nsh = NULL; | 76 | nsh = NULL; |
77 | } | 77 | } |
78 | GNUNET_free_non_null(s_name_1); | 78 | GNUNET_free_non_null (s_name_1); |
79 | GNUNET_free_non_null(s_name_2); | 79 | GNUNET_free_non_null (s_name_2); |
80 | GNUNET_free_non_null(s_name_3); | 80 | GNUNET_free_non_null (s_name_3); |
81 | if (s_rd_1 != NULL) | 81 | if (s_rd_1 != NULL) |
82 | { | 82 | { |
83 | GNUNET_free((void *)s_rd_1->data); | 83 | GNUNET_free ((void *) s_rd_1->data); |
84 | GNUNET_free(s_rd_1); | 84 | GNUNET_free (s_rd_1); |
85 | } | 85 | } |
86 | if (s_rd_2 != NULL) | 86 | if (s_rd_2 != NULL) |
87 | { | 87 | { |
88 | GNUNET_free((void *)s_rd_2->data); | 88 | GNUNET_free ((void *) s_rd_2->data); |
89 | GNUNET_free(s_rd_2); | 89 | GNUNET_free (s_rd_2); |
90 | } | 90 | } |
91 | if (s_rd_3 != NULL) | 91 | if (s_rd_3 != NULL) |
92 | { | 92 | { |
93 | GNUNET_free((void *)s_rd_3->data); | 93 | GNUNET_free ((void *) s_rd_3->data); |
94 | GNUNET_free(s_rd_3); | 94 | GNUNET_free (s_rd_3); |
95 | } | 95 | } |
96 | if (privkey != NULL) | 96 | if (privkey != NULL) |
97 | { | 97 | { |
98 | GNUNET_free(privkey); | 98 | GNUNET_free (privkey); |
99 | privkey = NULL; | 99 | privkey = NULL; |
100 | } | 100 | } |
101 | if (privkey2 != NULL) | 101 | if (privkey2 != NULL) |
102 | { | 102 | { |
103 | GNUNET_free(privkey2); | 103 | GNUNET_free (privkey2); |
104 | privkey2 = NULL; | 104 | privkey2 = NULL; |
105 | } | 105 | } |
106 | } | 106 | } |
107 | 107 | ||
108 | 108 | ||
109 | static void | 109 | static void |
110 | delayed_end(void *cls) | 110 | delayed_end (void *cls) |
111 | { | 111 | { |
112 | GNUNET_SCHEDULER_shutdown(); | 112 | GNUNET_SCHEDULER_shutdown (); |
113 | } | 113 | } |
114 | 114 | ||
115 | 115 | ||
116 | static void | 116 | static void |
117 | fail_cb(void *cls) | 117 | fail_cb (void *cls) |
118 | { | 118 | { |
119 | GNUNET_assert(0); | 119 | GNUNET_assert (0); |
120 | } | 120 | } |
121 | 121 | ||
122 | 122 | ||
123 | static void | 123 | static void |
124 | zone_proc(void *cls, | 124 | zone_proc (void *cls, |
125 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 125 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
126 | const char *label, | 126 | const char *label, |
127 | unsigned int rd_count, | 127 | unsigned int rd_count, |
128 | const struct GNUNET_GNSRECORD_Data *rd) | 128 | const struct GNUNET_GNSRECORD_Data *rd) |
129 | { | 129 | { |
130 | int failed = GNUNET_NO; | 130 | int failed = GNUNET_NO; |
131 | 131 | ||
132 | GNUNET_assert(NULL != zone); | 132 | GNUNET_assert (NULL != zone); |
133 | if (0 == GNUNET_memcmp(zone, privkey)) | 133 | if (0 == GNUNET_memcmp (zone, privkey)) |
134 | { | ||
135 | if (0 == strcmp (label, s_name_1)) | ||
134 | { | 136 | { |
135 | if (0 == strcmp(label, s_name_1)) | 137 | if (rd_count == 1) |
136 | { | 138 | { |
137 | if (rd_count == 1) | 139 | if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_1)) |
138 | { | ||
139 | if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_1)) | ||
140 | { | ||
141 | failed = GNUNET_YES; | ||
142 | GNUNET_break(0); | ||
143 | } | ||
144 | } | ||
145 | else | ||
146 | { | ||
147 | failed = GNUNET_YES; | ||
148 | GNUNET_break(0); | ||
149 | } | ||
150 | } | ||
151 | else if (0 == strcmp(label, s_name_2)) | ||
152 | { | 140 | { |
153 | if (rd_count == 1) | ||
154 | { | ||
155 | if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_2)) | ||
156 | { | ||
157 | failed = GNUNET_YES; | ||
158 | GNUNET_break(0); | ||
159 | } | ||
160 | } | ||
161 | else | ||
162 | { | ||
163 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
164 | "Received invalid record count\n"); | ||
165 | failed = GNUNET_YES; | ||
166 | GNUNET_break(0); | ||
167 | } | ||
168 | } | ||
169 | else | ||
170 | { | ||
171 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
172 | "Comparing result failed: got name `%s' for first zone\n", label); | ||
173 | failed = GNUNET_YES; | 141 | failed = GNUNET_YES; |
174 | GNUNET_break(0); | 142 | GNUNET_break (0); |
175 | } | 143 | } |
144 | } | ||
145 | else | ||
146 | { | ||
147 | failed = GNUNET_YES; | ||
148 | GNUNET_break (0); | ||
149 | } | ||
176 | } | 150 | } |
177 | else if (0 == GNUNET_memcmp(zone, privkey2)) | 151 | else if (0 == strcmp (label, s_name_2)) |
178 | { | 152 | { |
179 | if (0 == strcmp(label, s_name_3)) | 153 | if (rd_count == 1) |
154 | { | ||
155 | if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_2)) | ||
180 | { | 156 | { |
181 | if (rd_count == 1) | ||
182 | { | ||
183 | if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_3)) | ||
184 | { | ||
185 | failed = GNUNET_YES; | ||
186 | GNUNET_break(0); | ||
187 | } | ||
188 | } | ||
189 | else | ||
190 | { | ||
191 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
192 | "Received invalid record count\n"); | ||
193 | failed = GNUNET_YES; | ||
194 | GNUNET_break(0); | ||
195 | } | ||
196 | } | ||
197 | else | ||
198 | { | ||
199 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
200 | "Comparing result failed: got name `%s' for first zone\n", label); | ||
201 | failed = GNUNET_YES; | 157 | failed = GNUNET_YES; |
202 | GNUNET_break(0); | 158 | GNUNET_break (0); |
203 | } | 159 | } |
160 | } | ||
161 | else | ||
162 | { | ||
163 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
164 | "Received invalid record count\n"); | ||
165 | failed = GNUNET_YES; | ||
166 | GNUNET_break (0); | ||
167 | } | ||
204 | } | 168 | } |
205 | else | 169 | else |
206 | { | 170 | { |
207 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 171 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
208 | "Received invalid zone\n"); | 172 | "Comparing result failed: got name `%s' for first zone\n", |
173 | label); | ||
209 | failed = GNUNET_YES; | 174 | failed = GNUNET_YES; |
210 | GNUNET_break(0); | 175 | GNUNET_break (0); |
211 | } | 176 | } |
212 | if (failed == GNUNET_NO) | 177 | } |
178 | else if (0 == GNUNET_memcmp (zone, privkey2)) | ||
179 | { | ||
180 | if (0 == strcmp (label, s_name_3)) | ||
213 | { | 181 | { |
214 | if (1 == returned_records) | 182 | if (rd_count == 1) |
183 | { | ||
184 | if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_3)) | ||
215 | { | 185 | { |
216 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 186 | failed = GNUNET_YES; |
217 | "Telling namestore to stop zone iteration\n"); | 187 | GNUNET_break (0); |
218 | GNUNET_NAMESTORE_zone_iteration_stop(zi); | ||
219 | zi = NULL; | ||
220 | res = 0; | ||
221 | GNUNET_SCHEDULER_add_delayed(WAIT, | ||
222 | &delayed_end, | ||
223 | NULL); | ||
224 | return; | ||
225 | } | 188 | } |
226 | returned_records++; | 189 | } |
227 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 190 | else |
228 | "Telling namestore to send the next result\n"); | 191 | { |
229 | GNUNET_NAMESTORE_zone_iterator_next(zi, | 192 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
230 | 1); | 193 | "Received invalid record count\n"); |
194 | failed = GNUNET_YES; | ||
195 | GNUNET_break (0); | ||
196 | } | ||
197 | } | ||
198 | else | ||
199 | { | ||
200 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
201 | "Comparing result failed: got name `%s' for first zone\n", | ||
202 | label); | ||
203 | failed = GNUNET_YES; | ||
204 | GNUNET_break (0); | ||
231 | } | 205 | } |
206 | } | ||
232 | else | 207 | else |
208 | { | ||
209 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
210 | "Received invalid zone\n"); | ||
211 | failed = GNUNET_YES; | ||
212 | GNUNET_break (0); | ||
213 | } | ||
214 | if (failed == GNUNET_NO) | ||
215 | { | ||
216 | if (1 == returned_records) | ||
233 | { | 217 | { |
234 | GNUNET_break(0); | 218 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
235 | GNUNET_SCHEDULER_shutdown(); | 219 | "Telling namestore to stop zone iteration\n"); |
220 | GNUNET_NAMESTORE_zone_iteration_stop (zi); | ||
221 | zi = NULL; | ||
222 | res = 0; | ||
223 | GNUNET_SCHEDULER_add_delayed (WAIT, | ||
224 | &delayed_end, | ||
225 | NULL); | ||
226 | return; | ||
236 | } | 227 | } |
228 | returned_records++; | ||
229 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
230 | "Telling namestore to send the next result\n"); | ||
231 | GNUNET_NAMESTORE_zone_iterator_next (zi, | ||
232 | 1); | ||
233 | } | ||
234 | else | ||
235 | { | ||
236 | GNUNET_break (0); | ||
237 | GNUNET_SCHEDULER_shutdown (); | ||
238 | } | ||
237 | } | 239 | } |
238 | 240 | ||
239 | 241 | ||
240 | static void | 242 | static void |
241 | zone_proc_end(void *cls) | 243 | zone_proc_end (void *cls) |
242 | { | 244 | { |
243 | GNUNET_break(1 <= returned_records); | 245 | GNUNET_break (1 <= returned_records); |
244 | if (1 >= returned_records) | 246 | if (1 >= returned_records) |
245 | res = 1; /* Last iteraterator callback, we are done */ | 247 | res = 1; /* Last iteraterator callback, we are done */ |
246 | else | 248 | else |
247 | res = 0; | 249 | res = 0; |
248 | zi = NULL; | 250 | zi = NULL; |
249 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 251 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
250 | "Received last result, iteration done after receing %u results\n", | 252 | "Received last result, iteration done after receing %u results\n", |
251 | returned_records); | 253 | returned_records); |
252 | GNUNET_SCHEDULER_add_now(&end, NULL); | 254 | GNUNET_SCHEDULER_add_now (&end, NULL); |
253 | } | 255 | } |
254 | 256 | ||
255 | 257 | ||
256 | static void | 258 | static void |
257 | put_cont(void *cls, int32_t success, const char *emsg) | 259 | put_cont (void *cls, int32_t success, const char *emsg) |
258 | { | 260 | { |
259 | static int c = 0; | 261 | static int c = 0; |
260 | 262 | ||
261 | if (success == GNUNET_OK) | 263 | if (success == GNUNET_OK) |
262 | { | 264 | { |
263 | c++; | 265 | c++; |
264 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c); | 266 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c); |
265 | } | 267 | } |
266 | else | 268 | else |
267 | { | 269 | { |
268 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to created records: `%s'\n", | 270 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records: `%s'\n", |
269 | emsg); | 271 | emsg); |
270 | GNUNET_break(0); | 272 | GNUNET_break (0); |
271 | GNUNET_SCHEDULER_shutdown(); | 273 | GNUNET_SCHEDULER_shutdown (); |
272 | return; | 274 | return; |
273 | } | 275 | } |
274 | 276 | ||
275 | if (c == 3) | 277 | if (c == 3) |
278 | { | ||
279 | res = 1; | ||
280 | returned_records = 0; | ||
281 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
282 | "All records created, starting iteration over all zones \n"); | ||
283 | zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, | ||
284 | NULL, | ||
285 | &fail_cb, | ||
286 | NULL, | ||
287 | &zone_proc, | ||
288 | NULL, | ||
289 | &zone_proc_end, | ||
290 | NULL); | ||
291 | if (zi == NULL) | ||
276 | { | 292 | { |
277 | res = 1; | 293 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
278 | returned_records = 0; | 294 | "Failed to create zone iterator\n"); |
279 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 295 | GNUNET_break (0); |
280 | "All records created, starting iteration over all zones \n"); | 296 | GNUNET_SCHEDULER_shutdown (); |
281 | zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, | 297 | return; |
282 | NULL, | ||
283 | &fail_cb, | ||
284 | NULL, | ||
285 | &zone_proc, | ||
286 | NULL, | ||
287 | &zone_proc_end, | ||
288 | NULL); | ||
289 | if (zi == NULL) | ||
290 | { | ||
291 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
292 | "Failed to create zone iterator\n"); | ||
293 | GNUNET_break(0); | ||
294 | GNUNET_SCHEDULER_shutdown(); | ||
295 | return; | ||
296 | } | ||
297 | } | 298 | } |
299 | } | ||
298 | } | 300 | } |
299 | 301 | ||
300 | 302 | ||
301 | static struct GNUNET_GNSRECORD_Data * | 303 | static struct GNUNET_GNSRECORD_Data * |
302 | create_record(unsigned int count) | 304 | create_record (unsigned int count) |
303 | { | 305 | { |
304 | struct GNUNET_GNSRECORD_Data *rd; | 306 | struct GNUNET_GNSRECORD_Data *rd; |
305 | 307 | ||
306 | rd = GNUNET_new_array(count, | 308 | rd = GNUNET_new_array (count, |
307 | struct GNUNET_GNSRECORD_Data); | 309 | struct GNUNET_GNSRECORD_Data); |
308 | for (unsigned int c = 0; c < count; c++) | 310 | for (unsigned int c = 0; c < count; c++) |
309 | { | 311 | { |
310 | rd[c].expiration_time = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS).abs_value_us; | 312 | rd[c].expiration_time = GNUNET_TIME_relative_to_absolute ( |
311 | rd[c].record_type = TEST_RECORD_TYPE; | 313 | GNUNET_TIME_UNIT_HOURS).abs_value_us; |
312 | rd[c].data_size = 50; | 314 | rd[c].record_type = TEST_RECORD_TYPE; |
313 | rd[c].data = GNUNET_malloc(50); | 315 | rd[c].data_size = 50; |
314 | rd[c].flags = 0; | 316 | rd[c].data = GNUNET_malloc (50); |
315 | memset((char *)rd[c].data, 'a', 50); | 317 | rd[c].flags = 0; |
316 | } | 318 | memset ((char *) rd[c].data, 'a', 50); |
319 | } | ||
317 | return rd; | 320 | return rd; |
318 | } | 321 | } |
319 | 322 | ||
@@ -324,123 +327,123 @@ create_record(unsigned int count) | |||
324 | * start the actual tests by filling the zone. | 327 | * start the actual tests by filling the zone. |
325 | */ | 328 | */ |
326 | static void | 329 | static void |
327 | empty_zone_proc(void *cls, | 330 | empty_zone_proc (void *cls, |
328 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 331 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
329 | const char *label, | 332 | const char *label, |
330 | unsigned int rd_count, | 333 | unsigned int rd_count, |
331 | const struct GNUNET_GNSRECORD_Data *rd) | 334 | const struct GNUNET_GNSRECORD_Data *rd) |
332 | { | 335 | { |
333 | GNUNET_assert(nsh == cls); | 336 | GNUNET_assert (nsh == cls); |
334 | if (NULL != zone) | 337 | if (NULL != zone) |
335 | { | 338 | { |
336 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 339 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
337 | _("Expected empty zone but received zone private key\n")); | 340 | _ ("Expected empty zone but received zone private key\n")); |
338 | GNUNET_break(0); | 341 | GNUNET_break (0); |
339 | GNUNET_SCHEDULER_shutdown(); | 342 | GNUNET_SCHEDULER_shutdown (); |
340 | return; | 343 | return; |
341 | } | 344 | } |
342 | if ((NULL != label) || (NULL != rd) || (0 != rd_count)) | 345 | if ((NULL != label) || (NULL != rd) || (0 != rd_count)) |
343 | { | 346 | { |
344 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 347 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
345 | _("Expected no zone content but received data\n")); | 348 | _ ("Expected no zone content but received data\n")); |
346 | GNUNET_break(0); | 349 | GNUNET_break (0); |
347 | GNUNET_SCHEDULER_shutdown(); | 350 | GNUNET_SCHEDULER_shutdown (); |
348 | return; | 351 | return; |
349 | } | 352 | } |
350 | GNUNET_assert(0); | 353 | GNUNET_assert (0); |
351 | } | 354 | } |
352 | 355 | ||
353 | 356 | ||
354 | static void | 357 | static void |
355 | empty_zone_proc_end(void *cls) | 358 | empty_zone_proc_end (void *cls) |
356 | { | 359 | { |
357 | char *hostkey_file; | 360 | char *hostkey_file; |
358 | 361 | ||
359 | GNUNET_assert(nsh == cls); | 362 | GNUNET_assert (nsh == cls); |
360 | zi = NULL; | 363 | zi = NULL; |
361 | GNUNET_asprintf(&hostkey_file, | 364 | GNUNET_asprintf (&hostkey_file, |
362 | "zonefiles%s%s", | 365 | "zonefiles%s%s", |
363 | DIR_SEPARATOR_STR, | 366 | DIR_SEPARATOR_STR, |
364 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | 367 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); |
365 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 368 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
366 | "Using zonekey file `%s' \n", | 369 | "Using zonekey file `%s' \n", |
367 | hostkey_file); | 370 | hostkey_file); |
368 | privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); | 371 | privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file); |
369 | GNUNET_free(hostkey_file); | 372 | GNUNET_free (hostkey_file); |
370 | GNUNET_assert(privkey != NULL); | 373 | GNUNET_assert (privkey != NULL); |
371 | 374 | ||
372 | GNUNET_asprintf(&hostkey_file, | 375 | GNUNET_asprintf (&hostkey_file, |
373 | "zonefiles%s%s", | 376 | "zonefiles%s%s", |
374 | DIR_SEPARATOR_STR, | 377 | DIR_SEPARATOR_STR, |
375 | "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"); | 378 | "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"); |
376 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 379 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
377 | "Using zonekey file `%s'\n", | 380 | "Using zonekey file `%s'\n", |
378 | hostkey_file); | 381 | hostkey_file); |
379 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); | 382 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file); |
380 | GNUNET_free(hostkey_file); | 383 | GNUNET_free (hostkey_file); |
381 | GNUNET_assert(privkey2 != NULL); | 384 | GNUNET_assert (privkey2 != NULL); |
382 | 385 | ||
383 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 386 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
384 | "Created record 1\n"); | 387 | "Created record 1\n"); |
385 | 388 | ||
386 | GNUNET_asprintf(&s_name_1, | 389 | GNUNET_asprintf (&s_name_1, |
387 | "dummy1"); | 390 | "dummy1"); |
388 | s_rd_1 = create_record(1); | 391 | s_rd_1 = create_record (1); |
389 | GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1, | 392 | GNUNET_NAMESTORE_records_store (nsh, privkey, s_name_1, |
390 | 1, s_rd_1, &put_cont, NULL); | 393 | 1, s_rd_1, &put_cont, NULL); |
391 | 394 | ||
392 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 395 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
393 | "Created record 2 \n"); | 396 | "Created record 2 \n"); |
394 | GNUNET_asprintf(&s_name_2, | 397 | GNUNET_asprintf (&s_name_2, |
395 | "dummy2"); | 398 | "dummy2"); |
396 | s_rd_2 = create_record(1); | 399 | s_rd_2 = create_record (1); |
397 | GNUNET_NAMESTORE_records_store(nsh, | 400 | GNUNET_NAMESTORE_records_store (nsh, |
398 | privkey, | 401 | privkey, |
399 | s_name_2, | 402 | s_name_2, |
400 | 1, | 403 | 1, |
401 | s_rd_2, | 404 | s_rd_2, |
402 | &put_cont, NULL); | 405 | &put_cont, NULL); |
403 | 406 | ||
404 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 407 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
405 | "Created record 3\n"); | 408 | "Created record 3\n"); |
406 | 409 | ||
407 | /* name in different zone */ | 410 | /* name in different zone */ |
408 | GNUNET_asprintf(&s_name_3, "dummy3"); | 411 | GNUNET_asprintf (&s_name_3, "dummy3"); |
409 | s_rd_3 = create_record(1); | 412 | s_rd_3 = create_record (1); |
410 | GNUNET_NAMESTORE_records_store(nsh, | 413 | GNUNET_NAMESTORE_records_store (nsh, |
411 | privkey2, | 414 | privkey2, |
412 | s_name_3, | 415 | s_name_3, |
413 | 1, | 416 | 1, |
414 | s_rd_3, | 417 | s_rd_3, |
415 | &put_cont, NULL); | 418 | &put_cont, NULL); |
416 | } | 419 | } |
417 | 420 | ||
418 | 421 | ||
419 | static void | 422 | static void |
420 | run(void *cls, | 423 | run (void *cls, |
421 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 424 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
422 | struct GNUNET_TESTING_Peer *peer) | 425 | struct GNUNET_TESTING_Peer *peer) |
423 | { | 426 | { |
424 | nsh = GNUNET_NAMESTORE_connect(cfg); | 427 | nsh = GNUNET_NAMESTORE_connect (cfg); |
425 | GNUNET_break(NULL != nsh); | 428 | GNUNET_break (NULL != nsh); |
426 | GNUNET_SCHEDULER_add_shutdown(&end, | 429 | GNUNET_SCHEDULER_add_shutdown (&end, |
427 | NULL); | 430 | NULL); |
428 | /* first, iterate over empty namestore */ | 431 | /* first, iterate over empty namestore */ |
429 | zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, | 432 | zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, |
430 | NULL, | 433 | NULL, |
431 | &fail_cb, | 434 | &fail_cb, |
432 | NULL, | 435 | NULL, |
433 | &empty_zone_proc, | 436 | &empty_zone_proc, |
434 | nsh, | 437 | nsh, |
435 | &empty_zone_proc_end, | 438 | &empty_zone_proc_end, |
436 | nsh); | 439 | nsh); |
437 | if (NULL == zi) | 440 | if (NULL == zi) |
438 | { | 441 | { |
439 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 442 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
440 | "Failed to create zone iterator\n"); | 443 | "Failed to create zone iterator\n"); |
441 | GNUNET_break(0); | 444 | GNUNET_break (0); |
442 | GNUNET_SCHEDULER_shutdown(); | 445 | GNUNET_SCHEDULER_shutdown (); |
443 | } | 446 | } |
444 | } | 447 | } |
445 | 448 | ||
446 | 449 | ||
@@ -448,24 +451,24 @@ run(void *cls, | |||
448 | 451 | ||
449 | 452 | ||
450 | int | 453 | int |
451 | main(int argc, char *argv[]) | 454 | main (int argc, char *argv[]) |
452 | { | 455 | { |
453 | const char *plugin_name; | 456 | const char *plugin_name; |
454 | char *cfg_name; | 457 | char *cfg_name; |
455 | 458 | ||
456 | SETUP_CFG(plugin_name, cfg_name); | 459 | SETUP_CFG (plugin_name, cfg_name); |
457 | res = 1; | 460 | res = 1; |
458 | if (0 != | 461 | if (0 != |
459 | GNUNET_TESTING_peer_run("test-namestore-api-zone-iteration-stop", | 462 | GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-stop", |
460 | cfg_name, | 463 | cfg_name, |
461 | &run, | 464 | &run, |
462 | NULL)) | 465 | NULL)) |
463 | { | 466 | { |
464 | res = 1; | 467 | res = 1; |
465 | } | 468 | } |
466 | GNUNET_DISK_purge_cfg_dir(cfg_name, | 469 | GNUNET_DISK_purge_cfg_dir (cfg_name, |
467 | "GNUNET_TEST_HOME"); | 470 | "GNUNET_TEST_HOME"); |
468 | GNUNET_free(cfg_name); | 471 | GNUNET_free (cfg_name); |
469 | 472 | ||
470 | return res; | 473 | return res; |
471 | } | 474 | } |
diff --git a/src/namestore/test_namestore_api_zone_to_name.c b/src/namestore/test_namestore_api_zone_to_name.c index 0c02c9a52..68f2461f1 100644 --- a/src/namestore/test_namestore_api_zone_to_name.c +++ b/src/namestore/test_namestore_api_zone_to_name.c | |||
@@ -35,7 +35,7 @@ | |||
35 | 35 | ||
36 | #define TEST_RECORD_DATA 'a' | 36 | #define TEST_RECORD_DATA 'a' |
37 | 37 | ||
38 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100) | 38 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) |
39 | 39 | ||
40 | 40 | ||
41 | static struct GNUNET_NAMESTORE_Handle *nsh; | 41 | static struct GNUNET_NAMESTORE_Handle *nsh; |
@@ -48,7 +48,7 @@ static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | |||
48 | 48 | ||
49 | static struct GNUNET_CRYPTO_EcdsaPublicKey s_zone_value; | 49 | static struct GNUNET_CRYPTO_EcdsaPublicKey s_zone_value; |
50 | 50 | ||
51 | static char * s_name; | 51 | static char *s_name; |
52 | 52 | ||
53 | static int res; | 53 | static int res; |
54 | 54 | ||
@@ -61,46 +61,46 @@ static struct GNUNET_NAMESTORE_QueueEntry *qe; | |||
61 | * @param cls handle to use to re-connect. | 61 | * @param cls handle to use to re-connect. |
62 | */ | 62 | */ |
63 | static void | 63 | static void |
64 | endbadly(void *cls) | 64 | endbadly (void *cls) |
65 | { | 65 | { |
66 | (void)cls; | 66 | (void) cls; |
67 | GNUNET_SCHEDULER_shutdown(); | 67 | GNUNET_SCHEDULER_shutdown (); |
68 | res = 1; | 68 | res = 1; |
69 | } | 69 | } |
70 | 70 | ||
71 | 71 | ||
72 | static void | 72 | static void |
73 | end(void *cls) | 73 | end (void *cls) |
74 | { | 74 | { |
75 | if (NULL != qe) | 75 | if (NULL != qe) |
76 | { | 76 | { |
77 | GNUNET_NAMESTORE_cancel(qe); | 77 | GNUNET_NAMESTORE_cancel (qe); |
78 | qe = NULL; | 78 | qe = NULL; |
79 | } | 79 | } |
80 | if (NULL != endbadly_task) | 80 | if (NULL != endbadly_task) |
81 | { | 81 | { |
82 | GNUNET_SCHEDULER_cancel(endbadly_task); | 82 | GNUNET_SCHEDULER_cancel (endbadly_task); |
83 | endbadly_task = NULL; | 83 | endbadly_task = NULL; |
84 | } | 84 | } |
85 | if (NULL != privkey) | 85 | if (NULL != privkey) |
86 | { | 86 | { |
87 | GNUNET_free(privkey); | 87 | GNUNET_free (privkey); |
88 | privkey = NULL; | 88 | privkey = NULL; |
89 | } | 89 | } |
90 | if (NULL != nsh) | 90 | if (NULL != nsh) |
91 | { | 91 | { |
92 | GNUNET_NAMESTORE_disconnect(nsh); | 92 | GNUNET_NAMESTORE_disconnect (nsh); |
93 | nsh = NULL; | 93 | nsh = NULL; |
94 | } | 94 | } |
95 | } | 95 | } |
96 | 96 | ||
97 | 97 | ||
98 | static void | 98 | static void |
99 | zone_to_name_proc(void *cls, | 99 | zone_to_name_proc (void *cls, |
100 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 100 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, |
101 | const char *n, | 101 | const char *n, |
102 | unsigned int rd_count, | 102 | unsigned int rd_count, |
103 | const struct GNUNET_GNSRECORD_Data *rd) | 103 | const struct GNUNET_GNSRECORD_Data *rd) |
104 | { | 104 | { |
105 | int fail = GNUNET_NO; | 105 | int fail = GNUNET_NO; |
106 | 106 | ||
@@ -109,132 +109,132 @@ zone_to_name_proc(void *cls, | |||
109 | (NULL == n) && | 109 | (NULL == n) && |
110 | (0 == rd_count) && | 110 | (0 == rd_count) && |
111 | (NULL == rd)) | 111 | (NULL == rd)) |
112 | { | ||
113 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
114 | "No result found\n"); | ||
115 | res = 1; | ||
116 | } | ||
117 | else | ||
118 | { | ||
119 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
120 | "Result found: `%s'\n", | ||
121 | n); | ||
122 | if ((NULL == n) || | ||
123 | (0 != strcmp (n, | ||
124 | s_name))) | ||
112 | { | 125 | { |
113 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 126 | fail = GNUNET_YES; |
114 | "No result found\n"); | 127 | GNUNET_break (0); |
115 | res = 1; | ||
116 | } | 128 | } |
117 | else | 129 | if (1 != rd_count) |
118 | { | 130 | { |
119 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 131 | fail = GNUNET_YES; |
120 | "Result found: `%s'\n", | 132 | GNUNET_break (0); |
121 | n); | ||
122 | if ((NULL == n) || | ||
123 | (0 != strcmp(n, | ||
124 | s_name))) | ||
125 | { | ||
126 | fail = GNUNET_YES; | ||
127 | GNUNET_break(0); | ||
128 | } | ||
129 | if (1 != rd_count) | ||
130 | { | ||
131 | fail = GNUNET_YES; | ||
132 | GNUNET_break(0); | ||
133 | } | ||
134 | if ((NULL == zone_key) || | ||
135 | (0 != GNUNET_memcmp(zone_key, | ||
136 | privkey))) | ||
137 | { | ||
138 | fail = GNUNET_YES; | ||
139 | GNUNET_break(0); | ||
140 | } | ||
141 | if (fail == GNUNET_NO) | ||
142 | res = 0; | ||
143 | else | ||
144 | res = 1; | ||
145 | } | 133 | } |
146 | GNUNET_SCHEDULER_add_now(&end, | 134 | if ((NULL == zone_key) || |
147 | NULL); | 135 | (0 != GNUNET_memcmp (zone_key, |
136 | privkey))) | ||
137 | { | ||
138 | fail = GNUNET_YES; | ||
139 | GNUNET_break (0); | ||
140 | } | ||
141 | if (fail == GNUNET_NO) | ||
142 | res = 0; | ||
143 | else | ||
144 | res = 1; | ||
145 | } | ||
146 | GNUNET_SCHEDULER_add_now (&end, | ||
147 | NULL); | ||
148 | } | 148 | } |
149 | 149 | ||
150 | 150 | ||
151 | static void | 151 | static void |
152 | error_cb(void *cls) | 152 | error_cb (void *cls) |
153 | { | 153 | { |
154 | (void)cls; | 154 | (void) cls; |
155 | qe = NULL; | 155 | qe = NULL; |
156 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 156 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
157 | "Not found!\n"); | 157 | "Not found!\n"); |
158 | GNUNET_SCHEDULER_shutdown(); | 158 | GNUNET_SCHEDULER_shutdown (); |
159 | res = 2; | 159 | res = 2; |
160 | } | 160 | } |
161 | 161 | ||
162 | 162 | ||
163 | static void | 163 | static void |
164 | put_cont(void *cls, | 164 | put_cont (void *cls, |
165 | int32_t success, | 165 | int32_t success, |
166 | const char *emsg) | 166 | const char *emsg) |
167 | { | 167 | { |
168 | char *name = cls; | 168 | char *name = cls; |
169 | 169 | ||
170 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 170 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
171 | "Name store added record for `%s': %s\n", | 171 | "Name store added record for `%s': %s\n", |
172 | name, | 172 | name, |
173 | (success == GNUNET_OK) ? "SUCCESS" : emsg); | 173 | (success == GNUNET_OK) ? "SUCCESS" : emsg); |
174 | if (success == GNUNET_OK) | 174 | if (success == GNUNET_OK) |
175 | { | 175 | { |
176 | res = 0; | 176 | res = 0; |
177 | 177 | ||
178 | qe = GNUNET_NAMESTORE_zone_to_name(nsh, | 178 | qe = GNUNET_NAMESTORE_zone_to_name (nsh, |
179 | privkey, | 179 | privkey, |
180 | &s_zone_value, | 180 | &s_zone_value, |
181 | &error_cb, | 181 | &error_cb, |
182 | NULL, | 182 | NULL, |
183 | &zone_to_name_proc, | 183 | &zone_to_name_proc, |
184 | NULL); | 184 | NULL); |
185 | } | 185 | } |
186 | else | 186 | else |
187 | { | 187 | { |
188 | res = 1; | 188 | res = 1; |
189 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 189 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
190 | "Failed to put records for name `%s'\n", | 190 | "Failed to put records for name `%s'\n", |
191 | name); | 191 | name); |
192 | GNUNET_SCHEDULER_add_now(&end, | 192 | GNUNET_SCHEDULER_add_now (&end, |
193 | NULL); | 193 | NULL); |
194 | } | 194 | } |
195 | } | 195 | } |
196 | 196 | ||
197 | 197 | ||
198 | static void | 198 | static void |
199 | run(void *cls, | 199 | run (void *cls, |
200 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 200 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
201 | struct GNUNET_TESTING_Peer *peer) | 201 | struct GNUNET_TESTING_Peer *peer) |
202 | { | 202 | { |
203 | (void)cls; | 203 | (void) cls; |
204 | (void)peer; | 204 | (void) peer; |
205 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, | 205 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
206 | &endbadly, | 206 | &endbadly, |
207 | NULL); | 207 | NULL); |
208 | GNUNET_SCHEDULER_add_shutdown(&end, | 208 | GNUNET_SCHEDULER_add_shutdown (&end, |
209 | NULL); | 209 | NULL); |
210 | GNUNET_asprintf(&s_name, "dummy"); | 210 | GNUNET_asprintf (&s_name, "dummy"); |
211 | privkey = GNUNET_CRYPTO_ecdsa_key_create(); | 211 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); |
212 | GNUNET_assert(NULL != privkey); | 212 | GNUNET_assert (NULL != privkey); |
213 | /* get public key */ | 213 | /* get public key */ |
214 | GNUNET_CRYPTO_ecdsa_key_get_public(privkey, | 214 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, |
215 | &pubkey); | 215 | &pubkey); |
216 | 216 | ||
217 | GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, | 217 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, |
218 | &s_zone_value, | 218 | &s_zone_value, |
219 | sizeof(s_zone_value)); | 219 | sizeof(s_zone_value)); |
220 | { | 220 | { |
221 | struct GNUNET_GNSRECORD_Data rd; | 221 | struct GNUNET_GNSRECORD_Data rd; |
222 | 222 | ||
223 | rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us; | 223 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us; |
224 | rd.record_type = GNUNET_GNSRECORD_TYPE_PKEY; | 224 | rd.record_type = GNUNET_GNSRECORD_TYPE_PKEY; |
225 | rd.data_size = sizeof(s_zone_value); | 225 | rd.data_size = sizeof(s_zone_value); |
226 | rd.data = &s_zone_value; | 226 | rd.data = &s_zone_value; |
227 | rd.flags = 0; | 227 | rd.flags = 0; |
228 | 228 | ||
229 | nsh = GNUNET_NAMESTORE_connect(cfg); | 229 | nsh = GNUNET_NAMESTORE_connect (cfg); |
230 | GNUNET_break(NULL != nsh); | 230 | GNUNET_break (NULL != nsh); |
231 | GNUNET_NAMESTORE_records_store(nsh, | 231 | GNUNET_NAMESTORE_records_store (nsh, |
232 | privkey, | 232 | privkey, |
233 | s_name, | 233 | s_name, |
234 | 1, | 234 | 1, |
235 | &rd, | 235 | &rd, |
236 | &put_cont, | 236 | &put_cont, |
237 | NULL); | 237 | NULL); |
238 | } | 238 | } |
239 | } | 239 | } |
240 | 240 | ||
@@ -243,26 +243,26 @@ run(void *cls, | |||
243 | 243 | ||
244 | 244 | ||
245 | int | 245 | int |
246 | main(int argc, | 246 | main (int argc, |
247 | char *argv[]) | 247 | char *argv[]) |
248 | { | 248 | { |
249 | const char *plugin_name; | 249 | const char *plugin_name; |
250 | char *cfg_name; | 250 | char *cfg_name; |
251 | 251 | ||
252 | (void)argc; | 252 | (void) argc; |
253 | SETUP_CFG(plugin_name, cfg_name); | 253 | SETUP_CFG (plugin_name, cfg_name); |
254 | res = 1; | 254 | res = 1; |
255 | if (0 != | 255 | if (0 != |
256 | GNUNET_TESTING_peer_run("test-namestore-api-zone-to-name", | 256 | GNUNET_TESTING_peer_run ("test-namestore-api-zone-to-name", |
257 | cfg_name, | 257 | cfg_name, |
258 | &run, | 258 | &run, |
259 | NULL)) | 259 | NULL)) |
260 | { | 260 | { |
261 | res = 1; | 261 | res = 1; |
262 | } | 262 | } |
263 | GNUNET_DISK_purge_cfg_dir(cfg_name, | 263 | GNUNET_DISK_purge_cfg_dir (cfg_name, |
264 | "GNUNET_TEST_HOME"); | 264 | "GNUNET_TEST_HOME"); |
265 | GNUNET_free(cfg_name); | 265 | GNUNET_free (cfg_name); |
266 | return res; | 266 | return res; |
267 | } | 267 | } |
268 | 268 | ||
diff --git a/src/namestore/test_plugin_namestore.c b/src/namestore/test_plugin_namestore.c index 8fb30b651..a3d9f44c4 100644 --- a/src/namestore/test_plugin_namestore.c +++ b/src/namestore/test_plugin_namestore.c | |||
@@ -45,13 +45,13 @@ static const char *plugin_name; | |||
45 | * @param api api to unload | 45 | * @param api api to unload |
46 | */ | 46 | */ |
47 | static void | 47 | static void |
48 | unload_plugin(struct GNUNET_NAMESTORE_PluginFunctions *api) | 48 | unload_plugin (struct GNUNET_NAMESTORE_PluginFunctions *api) |
49 | { | 49 | { |
50 | char *libname; | 50 | char *libname; |
51 | 51 | ||
52 | GNUNET_asprintf(&libname, "libgnunet_plugin_namestore_%s", plugin_name); | 52 | GNUNET_asprintf (&libname, "libgnunet_plugin_namestore_%s", plugin_name); |
53 | GNUNET_break(NULL == GNUNET_PLUGIN_unload(libname, api)); | 53 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api)); |
54 | GNUNET_free(libname); | 54 | GNUNET_free (libname); |
55 | } | 55 | } |
56 | 56 | ||
57 | 57 | ||
@@ -62,33 +62,33 @@ unload_plugin(struct GNUNET_NAMESTORE_PluginFunctions *api) | |||
62 | * @return NULL on error | 62 | * @return NULL on error |
63 | */ | 63 | */ |
64 | static struct GNUNET_NAMESTORE_PluginFunctions * | 64 | static struct GNUNET_NAMESTORE_PluginFunctions * |
65 | load_plugin(const struct GNUNET_CONFIGURATION_Handle *cfg) | 65 | load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg) |
66 | { | 66 | { |
67 | struct GNUNET_NAMESTORE_PluginFunctions *ret; | 67 | struct GNUNET_NAMESTORE_PluginFunctions *ret; |
68 | char *libname; | 68 | char *libname; |
69 | 69 | ||
70 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 70 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
71 | _("Loading `%s' namestore plugin\n"), | 71 | _ ("Loading `%s' namestore plugin\n"), |
72 | plugin_name); | 72 | plugin_name); |
73 | GNUNET_asprintf(&libname, "libgnunet_plugin_namestore_%s", plugin_name); | 73 | GNUNET_asprintf (&libname, "libgnunet_plugin_namestore_%s", plugin_name); |
74 | if (NULL == (ret = GNUNET_PLUGIN_load(libname, (void *)cfg))) | 74 | if (NULL == (ret = GNUNET_PLUGIN_load (libname, (void *) cfg))) |
75 | { | 75 | { |
76 | fprintf(stderr, "Failed to load plugin `%s'!\n", plugin_name); | 76 | fprintf (stderr, "Failed to load plugin `%s'!\n", plugin_name); |
77 | GNUNET_free(libname); | 77 | GNUNET_free (libname); |
78 | return NULL; | 78 | return NULL; |
79 | } | 79 | } |
80 | GNUNET_free(libname); | 80 | GNUNET_free (libname); |
81 | return ret; | 81 | return ret; |
82 | } | 82 | } |
83 | 83 | ||
84 | 84 | ||
85 | static void | 85 | static void |
86 | test_record(void *cls, | 86 | test_record (void *cls, |
87 | uint64_t seq, | 87 | uint64_t seq, |
88 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key, | 88 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key, |
89 | const char *label, | 89 | const char *label, |
90 | unsigned int rd_count, | 90 | unsigned int rd_count, |
91 | const struct GNUNET_GNSRECORD_Data *rd) | 91 | const struct GNUNET_GNSRECORD_Data *rd) |
92 | { | 92 | { |
93 | int *idp = cls; | 93 | int *idp = cls; |
94 | int id = *idp; | 94 | int id = *idp; |
@@ -96,106 +96,107 @@ test_record(void *cls, | |||
96 | char tname[64]; | 96 | char tname[64]; |
97 | unsigned int trd_count = 1 + (id % 1024); | 97 | unsigned int trd_count = 1 + (id % 1024); |
98 | 98 | ||
99 | GNUNET_snprintf(tname, sizeof(tname), "a%u", (unsigned int)id); | 99 | GNUNET_snprintf (tname, sizeof(tname), "a%u", (unsigned int) id); |
100 | GNUNET_assert(trd_count == rd_count); | 100 | GNUNET_assert (trd_count == rd_count); |
101 | for (unsigned int i = 0; i < trd_count; i++) | 101 | for (unsigned int i = 0; i < trd_count; i++) |
102 | { | 102 | { |
103 | GNUNET_assert(rd[i].data_size == id % 10); | 103 | GNUNET_assert (rd[i].data_size == id % 10); |
104 | GNUNET_assert(0 == memcmp("Hello World", rd[i].data, id % 10)); | 104 | GNUNET_assert (0 == memcmp ("Hello World", rd[i].data, id % 10)); |
105 | GNUNET_assert(rd[i].record_type == TEST_RECORD_TYPE); | 105 | GNUNET_assert (rd[i].record_type == TEST_RECORD_TYPE); |
106 | GNUNET_assert(rd[i].flags == 0); | 106 | GNUNET_assert (rd[i].flags == 0); |
107 | } | 107 | } |
108 | memset(&tzone_private_key, (id % 241), sizeof(tzone_private_key)); | 108 | memset (&tzone_private_key, (id % 241), sizeof(tzone_private_key)); |
109 | GNUNET_assert(0 == strcmp(label, tname)); | 109 | GNUNET_assert (0 == strcmp (label, tname)); |
110 | GNUNET_assert(0 == GNUNET_memcmp(&tzone_private_key, private_key)); | 110 | GNUNET_assert (0 == GNUNET_memcmp (&tzone_private_key, private_key)); |
111 | } | 111 | } |
112 | 112 | ||
113 | 113 | ||
114 | static void | 114 | static void |
115 | get_record(struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id) | 115 | get_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id) |
116 | { | 116 | { |
117 | GNUNET_assert( | 117 | GNUNET_assert ( |
118 | GNUNET_OK == | 118 | GNUNET_OK == |
119 | nsp->iterate_records(nsp->cls, NULL, 0, 1, &test_record, &id)); | 119 | nsp->iterate_records (nsp->cls, NULL, 0, 1, &test_record, &id)); |
120 | } | 120 | } |
121 | 121 | ||
122 | 122 | ||
123 | static void | 123 | static void |
124 | put_record(struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id) | 124 | put_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id) |
125 | { | 125 | { |
126 | struct GNUNET_CRYPTO_EcdsaPrivateKey zone_private_key; | 126 | struct GNUNET_CRYPTO_EcdsaPrivateKey zone_private_key; |
127 | char label[64]; | 127 | char label[64]; |
128 | unsigned int rd_count = 1 + (id % 1024); | 128 | unsigned int rd_count = 1 + (id % 1024); |
129 | struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)]; | 129 | struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL (rd_count)]; |
130 | struct GNUNET_CRYPTO_EcdsaSignature signature; | 130 | struct GNUNET_CRYPTO_EcdsaSignature signature; |
131 | 131 | ||
132 | GNUNET_snprintf(label, sizeof(label), "a%u", (unsigned int)id); | 132 | GNUNET_snprintf (label, sizeof(label), "a%u", (unsigned int) id); |
133 | for (unsigned int i = 0; i < rd_count; i++) | 133 | for (unsigned int i = 0; i < rd_count; i++) |
134 | { | 134 | { |
135 | rd[i].data = "Hello World"; | 135 | rd[i].data = "Hello World"; |
136 | rd[i].data_size = id % 10; | 136 | rd[i].data_size = id % 10; |
137 | rd[i].expiration_time = | 137 | rd[i].expiration_time = |
138 | GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_MINUTES).abs_value_us; | 138 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES).abs_value_us; |
139 | rd[i].record_type = TEST_RECORD_TYPE; | 139 | rd[i].record_type = TEST_RECORD_TYPE; |
140 | rd[i].flags = 0; | 140 | rd[i].flags = 0; |
141 | } | 141 | } |
142 | memset(&zone_private_key, (id % 241), sizeof(zone_private_key)); | 142 | memset (&zone_private_key, (id % 241), sizeof(zone_private_key)); |
143 | memset(&signature, (id % 243), sizeof(signature)); | 143 | memset (&signature, (id % 243), sizeof(signature)); |
144 | GNUNET_assert( | 144 | GNUNET_assert ( |
145 | GNUNET_OK == | 145 | GNUNET_OK == |
146 | nsp->store_records(nsp->cls, &zone_private_key, label, rd_count, rd)); | 146 | nsp->store_records (nsp->cls, &zone_private_key, label, rd_count, rd)); |
147 | } | 147 | } |
148 | 148 | ||
149 | 149 | ||
150 | static void | 150 | static void |
151 | run(void *cls, | 151 | run (void *cls, |
152 | char *const *args, | 152 | char *const *args, |
153 | const char *cfgfile, | 153 | const char *cfgfile, |
154 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 154 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
155 | { | 155 | { |
156 | struct GNUNET_NAMESTORE_PluginFunctions *nsp; | 156 | struct GNUNET_NAMESTORE_PluginFunctions *nsp; |
157 | 157 | ||
158 | ok = 0; | 158 | ok = 0; |
159 | nsp = load_plugin(cfg); | 159 | nsp = load_plugin (cfg); |
160 | if (NULL == nsp) | 160 | if (NULL == nsp) |
161 | { | 161 | { |
162 | fprintf( | 162 | fprintf ( |
163 | stderr, | 163 | stderr, |
164 | "%s", | 164 | "%s", |
165 | "Failed to initialize namestore. Database likely not setup, skipping test.\n"); | 165 | "Failed to initialize namestore. Database likely not setup, skipping test.\n"); |
166 | return; | 166 | return; |
167 | } | 167 | } |
168 | put_record(nsp, 1); | 168 | put_record (nsp, 1); |
169 | get_record(nsp, 1); | 169 | get_record (nsp, 1); |
170 | 170 | ||
171 | unload_plugin(nsp); | 171 | unload_plugin (nsp); |
172 | } | 172 | } |
173 | 173 | ||
174 | 174 | ||
175 | int | 175 | int |
176 | main(int argc, char *argv[]) | 176 | main (int argc, char *argv[]) |
177 | { | 177 | { |
178 | char cfg_name[PATH_MAX]; | 178 | char cfg_name[PATH_MAX]; |
179 | char *const xargv[] = { "test-plugin-namestore", "-c", cfg_name, NULL }; | 179 | char *const xargv[] = { "test-plugin-namestore", "-c", cfg_name, NULL }; |
180 | struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; | 180 | struct GNUNET_GETOPT_CommandLineOption options[] = |
181 | 181 | { GNUNET_GETOPT_OPTION_END }; | |
182 | GNUNET_log_setup("test-plugin-namestore", "WARNING", NULL); | 182 | |
183 | plugin_name = GNUNET_TESTING_get_testname_from_underscore(argv[0]); | 183 | GNUNET_log_setup ("test-plugin-namestore", "WARNING", NULL); |
184 | GNUNET_snprintf(cfg_name, | 184 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); |
185 | sizeof(cfg_name), | 185 | GNUNET_snprintf (cfg_name, |
186 | "test_plugin_namestore_%s.conf", | 186 | sizeof(cfg_name), |
187 | plugin_name); | 187 | "test_plugin_namestore_%s.conf", |
188 | GNUNET_DISK_purge_cfg_dir(cfg_name, "GNUNET_TMP"); | 188 | plugin_name); |
189 | GNUNET_PROGRAM_run((sizeof(xargv) / sizeof(char *)) - 1, | 189 | GNUNET_DISK_purge_cfg_dir (cfg_name, "GNUNET_TMP"); |
190 | xargv, | 190 | GNUNET_PROGRAM_run ((sizeof(xargv) / sizeof(char *)) - 1, |
191 | "test-plugin-namestore", | 191 | xargv, |
192 | "nohelp", | 192 | "test-plugin-namestore", |
193 | options, | 193 | "nohelp", |
194 | &run, | 194 | options, |
195 | NULL); | 195 | &run, |
196 | GNUNET_DISK_purge_cfg_dir(cfg_name, "GNUNET_TMP"); | 196 | NULL); |
197 | GNUNET_DISK_purge_cfg_dir (cfg_name, "GNUNET_TMP"); | ||
197 | if (ok != 0) | 198 | if (ok != 0) |
198 | fprintf(stderr, "Missed some testcases: %d\n", ok); | 199 | fprintf (stderr, "Missed some testcases: %d\n", ok); |
199 | return ok; | 200 | return ok; |
200 | } | 201 | } |
201 | 202 | ||