diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-07-13 08:59:32 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-07-13 08:59:32 +0000 |
commit | 29d18056622e35e1f86dd4a5130039dbb6e81afe (patch) | |
tree | e633a8dcb23c2a42a04ea0f28806cca40c47c98e /src/namestore | |
parent | aef5657ec217334e901b8d79308817e8710f4b8b (diff) | |
download | gnunet-29d18056622e35e1f86dd4a5130039dbb6e81afe.tar.gz gnunet-29d18056622e35e1f86dd4a5130039dbb6e81afe.zip |
- test for namestore
Diffstat (limited to 'src/namestore')
-rw-r--r-- | src/namestore/gnunet-namestore.c | 178 |
1 files changed, 100 insertions, 78 deletions
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c index ad263e7d0..ed6d37244 100644 --- a/src/namestore/gnunet-namestore.c +++ b/src/namestore/gnunet-namestore.c | |||
@@ -317,17 +317,9 @@ display_record (void *cls, | |||
317 | } | 317 | } |
318 | 318 | ||
319 | 319 | ||
320 | /** | ||
321 | * Main function that will be run. | ||
322 | * | ||
323 | * @param cls closure | ||
324 | * @param args remaining command-line arguments | ||
325 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
326 | * @param cfg configuration | ||
327 | */ | ||
328 | static void | 320 | static void |
329 | run (void *cls, char *const *args, const char *cfgfile, | 321 | testservice_task (void *cls, |
330 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 322 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
331 | { | 323 | { |
332 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; | 324 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; |
333 | uint32_t type; | 325 | uint32_t type; |
@@ -338,21 +330,28 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
338 | int etime_is_rel = GNUNET_SYSERR; | 330 | int etime_is_rel = GNUNET_SYSERR; |
339 | struct GNUNET_NAMESTORE_RecordData rd; | 331 | struct GNUNET_NAMESTORE_RecordData rd; |
340 | 332 | ||
341 | if ( (NULL != args[0]) && (NULL == uri) ) | 333 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
342 | uri = GNUNET_strdup (args[0]); | 334 | |
335 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) | ||
336 | { | ||
337 | FPRINTF (stderr, _("Service `%s' is not running\n"), "namestore"); | ||
338 | return; | ||
339 | } | ||
340 | |||
341 | |||
343 | if (NULL == keyfile) | 342 | if (NULL == keyfile) |
344 | { | 343 | { |
345 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", | 344 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", |
346 | "ZONEKEY", &keyfile)) | 345 | "ZONEKEY", &keyfile)) |
347 | { | 346 | { |
348 | fprintf (stderr, | 347 | fprintf (stderr, |
349 | _("Option `%s' not given, but I need a zone key file!\n"), | 348 | _("Option `%s' not given, but I need a zone key file!\n"), |
350 | "z"); | 349 | "z"); |
351 | return; | 350 | return; |
352 | } | 351 | } |
353 | fprintf (stderr, | 352 | fprintf (stderr, |
354 | _("Using default zone file `%s'\n"), | 353 | _("Using default zone file `%s'\n"), |
355 | keyfile); | 354 | keyfile); |
356 | } | 355 | } |
357 | zone_pkey = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); | 356 | zone_pkey = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); |
358 | GNUNET_free (keyfile); | 357 | GNUNET_free (keyfile); |
@@ -369,22 +368,22 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
369 | if (NULL == zone_pkey) | 368 | if (NULL == zone_pkey) |
370 | { | 369 | { |
371 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 370 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
372 | _("Failed to read or create private zone key\n")); | 371 | _("Failed to read or create private zone key\n")); |
373 | return; | 372 | return; |
374 | } | 373 | } |
375 | GNUNET_CRYPTO_rsa_key_get_public (zone_pkey, | 374 | GNUNET_CRYPTO_rsa_key_get_public (zone_pkey, |
376 | &pub); | 375 | &pub); |
377 | GNUNET_CRYPTO_short_hash (&pub, sizeof (pub), &zone); | 376 | GNUNET_CRYPTO_short_hash (&pub, sizeof (pub), &zone); |
378 | 377 | ||
379 | ns = GNUNET_NAMESTORE_connect (cfg); | 378 | ns = GNUNET_NAMESTORE_connect (cfg); |
380 | if (NULL == ns) | 379 | if (NULL == ns) |
381 | { | 380 | { |
382 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 381 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
383 | _("Failed to connect to namestore\n")); | 382 | _("Failed to connect to namestore\n")); |
384 | return; | 383 | return; |
385 | } | 384 | } |
386 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 385 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
387 | &do_shutdown, NULL); | 386 | &do_shutdown, NULL); |
388 | if (NULL == typestring) | 387 | if (NULL == typestring) |
389 | type = 0; | 388 | type = 0; |
390 | else | 389 | else |
@@ -399,8 +398,8 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
399 | if ((NULL == typestring) && (add | del)) | 398 | if ((NULL == typestring) && (add | del)) |
400 | { | 399 | { |
401 | fprintf (stderr, | 400 | fprintf (stderr, |
402 | _("Missing option `%s' for operation `%s'\n"), | 401 | _("Missing option `%s' for operation `%s'\n"), |
403 | "-t", _("add/del")); | 402 | "-t", _("add/del")); |
404 | GNUNET_SCHEDULER_shutdown (); | 403 | GNUNET_SCHEDULER_shutdown (); |
405 | ret = 1; | 404 | ret = 1; |
406 | return; | 405 | return; |
@@ -408,23 +407,23 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
408 | if (NULL != value) | 407 | if (NULL != value) |
409 | { | 408 | { |
410 | if (GNUNET_OK != | 409 | if (GNUNET_OK != |
411 | GNUNET_NAMESTORE_string_to_value (type, | 410 | GNUNET_NAMESTORE_string_to_value (type, |
412 | value, | 411 | value, |
413 | &data, | 412 | &data, |
414 | &data_size)) | 413 | &data_size)) |
415 | { | 414 | { |
416 | fprintf (stderr, _("Value `%s' invalid for record type `%s'\n"), | 415 | fprintf (stderr, _("Value `%s' invalid for record type `%s'\n"), |
417 | value, | 416 | value, |
418 | typestring); | 417 | typestring); |
419 | GNUNET_SCHEDULER_shutdown (); | 418 | GNUNET_SCHEDULER_shutdown (); |
420 | ret = 1; | 419 | ret = 1; |
421 | return; | 420 | return; |
422 | } | 421 | } |
423 | } else if (add | del) | 422 | } else if (add | del) |
424 | { | 423 | { |
425 | fprintf (stderr, | 424 | fprintf (stderr, |
426 | _("Missing option `%s' for operation `%s'\n"), | 425 | _("Missing option `%s' for operation `%s'\n"), |
427 | "-V", _("add/del")); | 426 | "-V", _("add/del")); |
428 | ret = 1; | 427 | ret = 1; |
429 | GNUNET_SCHEDULER_shutdown (); | 428 | GNUNET_SCHEDULER_shutdown (); |
430 | return; | 429 | return; |
@@ -437,22 +436,22 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
437 | etime_is_rel = GNUNET_NO; | 436 | etime_is_rel = GNUNET_NO; |
438 | } | 437 | } |
439 | else if (GNUNET_OK == | 438 | else if (GNUNET_OK == |
440 | GNUNET_STRINGS_fancy_time_to_relative (expirationstring, | 439 | GNUNET_STRINGS_fancy_time_to_relative (expirationstring, |
441 | &etime_rel)) | 440 | &etime_rel)) |
442 | { | 441 | { |
443 | etime_is_rel = GNUNET_YES; | 442 | etime_is_rel = GNUNET_YES; |
444 | } | 443 | } |
445 | else if (GNUNET_OK == | 444 | else if (GNUNET_OK == |
446 | GNUNET_STRINGS_fancy_time_to_absolute (expirationstring, | 445 | GNUNET_STRINGS_fancy_time_to_absolute (expirationstring, |
447 | &etime_abs)) | 446 | &etime_abs)) |
448 | { | 447 | { |
449 | etime_is_rel = GNUNET_NO; | 448 | etime_is_rel = GNUNET_NO; |
450 | } | 449 | } |
451 | else | 450 | else |
452 | { | 451 | { |
453 | fprintf (stderr, | 452 | fprintf (stderr, |
454 | _("Invalid time format `%s'\n"), | 453 | _("Invalid time format `%s'\n"), |
455 | expirationstring); | 454 | expirationstring); |
456 | GNUNET_SCHEDULER_shutdown (); | 455 | GNUNET_SCHEDULER_shutdown (); |
457 | ret = 1; | 456 | ret = 1; |
458 | return; | 457 | return; |
@@ -460,8 +459,8 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
460 | if (etime_is_rel && del) | 459 | if (etime_is_rel && del) |
461 | { | 460 | { |
462 | fprintf (stderr, | 461 | fprintf (stderr, |
463 | _("Deletion requires either absolute time, or no time at all. Got relative time `%s' instead.\n"), | 462 | _("Deletion requires either absolute time, or no time at all. Got relative time `%s' instead.\n"), |
464 | expirationstring); | 463 | expirationstring); |
465 | GNUNET_SCHEDULER_shutdown (); | 464 | GNUNET_SCHEDULER_shutdown (); |
466 | ret = 1; | 465 | ret = 1; |
467 | return; | 466 | return; |
@@ -470,8 +469,8 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
470 | else if (add) | 469 | else if (add) |
471 | { | 470 | { |
472 | fprintf (stderr, | 471 | fprintf (stderr, |
473 | _("Missing option `%s' for operation `%s'\n"), | 472 | _("Missing option `%s' for operation `%s'\n"), |
474 | "-e", _("add")); | 473 | "-e", _("add")); |
475 | GNUNET_SCHEDULER_shutdown (); | 474 | GNUNET_SCHEDULER_shutdown (); |
476 | ret = 1; | 475 | ret = 1; |
477 | return; | 476 | return; |
@@ -482,8 +481,8 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
482 | if (NULL == name) | 481 | if (NULL == name) |
483 | { | 482 | { |
484 | fprintf (stderr, | 483 | fprintf (stderr, |
485 | _("Missing option `%s' for operation `%s'\n"), | 484 | _("Missing option `%s' for operation `%s'\n"), |
486 | "-n", _("add")); | 485 | "-n", _("add")); |
487 | GNUNET_SCHEDULER_shutdown (); | 486 | GNUNET_SCHEDULER_shutdown (); |
488 | ret = 1; | 487 | ret = 1; |
489 | return; | 488 | return; |
@@ -501,8 +500,8 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
501 | else | 500 | else |
502 | { | 501 | { |
503 | fprintf (stderr, | 502 | fprintf (stderr, |
504 | _("No valid expiration time for operation `%s'\n"), | 503 | _("No valid expiration time for operation `%s'\n"), |
505 | _("add")); | 504 | _("add")); |
506 | GNUNET_SCHEDULER_shutdown (); | 505 | GNUNET_SCHEDULER_shutdown (); |
507 | ret = 1; | 506 | ret = 1; |
508 | return; | 507 | return; |
@@ -512,19 +511,19 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
512 | if (1 != public) | 511 | if (1 != public) |
513 | rd.flags |= GNUNET_NAMESTORE_RF_PRIVATE; | 512 | rd.flags |= GNUNET_NAMESTORE_RF_PRIVATE; |
514 | add_qe = GNUNET_NAMESTORE_record_create (ns, | 513 | add_qe = GNUNET_NAMESTORE_record_create (ns, |
515 | zone_pkey, | 514 | zone_pkey, |
516 | name, | 515 | name, |
517 | &rd, | 516 | &rd, |
518 | &add_continuation, | 517 | &add_continuation, |
519 | &add_qe); | 518 | &add_qe); |
520 | } | 519 | } |
521 | if (del) | 520 | if (del) |
522 | { | 521 | { |
523 | if (NULL == name) | 522 | if (NULL == name) |
524 | { | 523 | { |
525 | fprintf (stderr, | 524 | fprintf (stderr, |
526 | _("Missing option `%s' for operation `%s'\n"), | 525 | _("Missing option `%s' for operation `%s'\n"), |
527 | "-n", _("del")); | 526 | "-n", _("del")); |
528 | GNUNET_SCHEDULER_shutdown (); | 527 | GNUNET_SCHEDULER_shutdown (); |
529 | ret = 1; | 528 | ret = 1; |
530 | return; | 529 | return; |
@@ -537,11 +536,11 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
537 | rd.expiration_time = etime_abs.abs_value; | 536 | rd.expiration_time = etime_abs.abs_value; |
538 | rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY; | 537 | rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY; |
539 | del_qe = GNUNET_NAMESTORE_record_remove (ns, | 538 | del_qe = GNUNET_NAMESTORE_record_remove (ns, |
540 | zone_pkey, | 539 | zone_pkey, |
541 | name, | 540 | name, |
542 | &rd, | 541 | &rd, |
543 | &del_continuation, | 542 | &del_continuation, |
544 | NULL); | 543 | NULL); |
545 | } | 544 | } |
546 | if (list) | 545 | if (list) |
547 | { | 546 | { |
@@ -554,11 +553,11 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
554 | must_not_flags |= GNUNET_NAMESTORE_RF_PRIVATE; | 553 | must_not_flags |= GNUNET_NAMESTORE_RF_PRIVATE; |
555 | 554 | ||
556 | list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, | 555 | list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, |
557 | &zone, | 556 | &zone, |
558 | GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION, | 557 | GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION, |
559 | must_not_flags, | 558 | must_not_flags, |
560 | &display_record, | 559 | &display_record, |
561 | NULL); | 560 | NULL); |
562 | } | 561 | } |
563 | if (NULL != uri) | 562 | if (NULL != uri) |
564 | { | 563 | { |
@@ -567,15 +566,15 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
567 | struct GNUNET_CRYPTO_ShortHashCode sc; | 566 | struct GNUNET_CRYPTO_ShortHashCode sc; |
568 | 567 | ||
569 | if ( (2 != (sscanf (uri, | 568 | if ( (2 != (sscanf (uri, |
570 | "gnunet://gns/%52s/%63s", | 569 | "gnunet://gns/%52s/%63s", |
571 | sh, | 570 | sh, |
572 | name)) ) || | 571 | name)) ) || |
573 | (GNUNET_OK != | 572 | (GNUNET_OK != |
574 | GNUNET_CRYPTO_short_hash_from_string (sh, &sc)) ) | 573 | GNUNET_CRYPTO_short_hash_from_string (sh, &sc)) ) |
575 | { | 574 | { |
576 | fprintf (stderr, | 575 | fprintf (stderr, |
577 | _("Invalid URI `%s'\n"), | 576 | _("Invalid URI `%s'\n"), |
578 | uri); | 577 | uri); |
579 | GNUNET_SCHEDULER_shutdown (); | 578 | GNUNET_SCHEDULER_shutdown (); |
580 | ret = 1; | 579 | ret = 1; |
581 | return; | 580 | return; |
@@ -596,17 +595,40 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
596 | rd.flags |= GNUNET_NAMESTORE_RF_AUTHORITY; | 595 | rd.flags |= GNUNET_NAMESTORE_RF_AUTHORITY; |
597 | 596 | ||
598 | add_qe_uri = GNUNET_NAMESTORE_record_create (ns, | 597 | add_qe_uri = GNUNET_NAMESTORE_record_create (ns, |
599 | zone_pkey, | 598 | zone_pkey, |
600 | name, | 599 | name, |
601 | &rd, | 600 | &rd, |
602 | &add_continuation, | 601 | &add_continuation, |
603 | &add_qe_uri); | 602 | &add_qe_uri); |
604 | } | 603 | } |
605 | GNUNET_free_non_null (data); | 604 | GNUNET_free_non_null (data); |
606 | } | 605 | } |
607 | 606 | ||
608 | 607 | ||
609 | /** | 608 | /** |
609 | * Main function that will be run. | ||
610 | * | ||
611 | * @param cls closure | ||
612 | * @param args remaining command-line arguments | ||
613 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
614 | * @param cfg configuration | ||
615 | */ | ||
616 | static void | ||
617 | run (void *cls, char *const *args, const char *cfgfile, | ||
618 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
619 | { | ||
620 | |||
621 | if ( (NULL != args[0]) && (NULL == uri) ) | ||
622 | uri = GNUNET_strdup (args[0]); | ||
623 | |||
624 | GNUNET_CLIENT_service_test ("namestore", cfg, | ||
625 | GNUNET_TIME_UNIT_SECONDS, | ||
626 | &testservice_task, | ||
627 | (void *) cfg); | ||
628 | } | ||
629 | |||
630 | |||
631 | /** | ||
610 | * The main function for gnunet-namestore. | 632 | * The main function for gnunet-namestore. |
611 | * | 633 | * |
612 | * @param argc number of arguments from the command line | 634 | * @param argc number of arguments from the command line |