diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-06-30 19:21:05 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-06-30 19:21:05 +0000 |
commit | 17de5c9d798109f55059190c886609ba377e4eb6 (patch) | |
tree | 07f2b4241f433b18baf02d5bf189307ad2308166 /src/namestore/gnunet-namestore.c | |
parent | fd87b25438487e1215c68bdb9f1bcac2d7012bc2 (diff) | |
download | gnunet-17de5c9d798109f55059190c886609ba377e4eb6.tar.gz gnunet-17de5c9d798109f55059190c886609ba377e4eb6.zip |
-towards implementing improved namestore API
Diffstat (limited to 'src/namestore/gnunet-namestore.c')
-rw-r--r-- | src/namestore/gnunet-namestore.c | 295 |
1 files changed, 167 insertions, 128 deletions
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c index 20452eb8c..c43b18593 100644 --- a/src/namestore/gnunet-namestore.c +++ b/src/namestore/gnunet-namestore.c | |||
@@ -133,6 +133,36 @@ static char *expirationstring; | |||
133 | */ | 133 | */ |
134 | static int ret; | 134 | static int ret; |
135 | 135 | ||
136 | /** | ||
137 | * Type string converted to DNS type value. | ||
138 | */ | ||
139 | static uint32_t type; | ||
140 | |||
141 | /** | ||
142 | * Value in binary format. | ||
143 | */ | ||
144 | static void *data; | ||
145 | |||
146 | /** | ||
147 | * Number of bytes in 'data'. | ||
148 | */ | ||
149 | static size_t data_size; | ||
150 | |||
151 | /** | ||
152 | * Expirationstring converted to relative time. | ||
153 | */ | ||
154 | static struct GNUNET_TIME_Relative etime_rel; | ||
155 | |||
156 | /** | ||
157 | * Expirationstring converted to absolute time. | ||
158 | */ | ||
159 | static struct GNUNET_TIME_Absolute etime_abs; | ||
160 | |||
161 | /** | ||
162 | * Is expiration time relative or absolute time? | ||
163 | */ | ||
164 | static int etime_is_rel = GNUNET_SYSERR; | ||
165 | |||
136 | 166 | ||
137 | /** | 167 | /** |
138 | * Task run on shutdown. Cleans up everything. | 168 | * Task run on shutdown. Cleans up everything. |
@@ -328,6 +358,69 @@ display_record (void *cls, | |||
328 | 358 | ||
329 | 359 | ||
330 | /** | 360 | /** |
361 | * We're storing a record; this function is given the existing record | ||
362 | * so that we can merge the information. | ||
363 | * | ||
364 | * @param cls closure, unused | ||
365 | * @param zone_key public key of the zone | ||
366 | * @param freshness when does the corresponding block in the DHT expire (until | ||
367 | * when should we never do a DHT lookup for the same name again)?; | ||
368 | * GNUNET_TIME_UNIT_ZERO_ABS if there are no records of any type in the namestore, | ||
369 | * or the expiration time of the block in the namestore (even if there are zero | ||
370 | * records matching the desired record type) | ||
371 | * @param name name that is being mapped (at most 255 characters long) | ||
372 | * @param rd_count number of entries in 'rd' array | ||
373 | * @param rd array of records with data to store | ||
374 | * @param signature signature of the record block, NULL if signature is unavailable (i.e. | ||
375 | * because the user queried for a particular record type only) | ||
376 | */ | ||
377 | static void | ||
378 | get_existing_record (void *cls, | ||
379 | const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key, | ||
380 | struct GNUNET_TIME_Absolute freshness, | ||
381 | const char *name, | ||
382 | unsigned int rd_count, | ||
383 | const struct GNUNET_NAMESTORE_RecordData *rd, | ||
384 | const struct GNUNET_CRYPTO_EccSignature *signature) | ||
385 | { | ||
386 | struct GNUNET_NAMESTORE_RecordData rdn[rd_count + 1]; | ||
387 | struct GNUNET_NAMESTORE_RecordData *rde; | ||
388 | |||
389 | add_qe = NULL; | ||
390 | memset (rdn, 0, sizeof (struct GNUNET_NAMESTORE_RecordData)); | ||
391 | memcpy (&rdn[1], rd, rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData)); | ||
392 | /* FIXME: should add some logic to overwrite records if there | ||
393 | can only be one record of a particular type, and to check | ||
394 | if the combination of records is valid to begin with... */ | ||
395 | rde = &rdn[0]; | ||
396 | rde->data = data; | ||
397 | rde->data_size = data_size; | ||
398 | rde->record_type = type; | ||
399 | if (GNUNET_YES == etime_is_rel) | ||
400 | { | ||
401 | rde->expiration_time = etime_rel.rel_value; | ||
402 | rde->flags |= GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION; | ||
403 | } | ||
404 | else if (GNUNET_NO == etime_is_rel) | ||
405 | { | ||
406 | rde->expiration_time = etime_abs.abs_value; | ||
407 | } | ||
408 | if (1 != nonauthority) | ||
409 | rde->flags |= GNUNET_NAMESTORE_RF_AUTHORITY; | ||
410 | if (1 != public) | ||
411 | rde->flags |= GNUNET_NAMESTORE_RF_PRIVATE; | ||
412 | |||
413 | add_qe = GNUNET_NAMESTORE_record_put_by_authority (ns, | ||
414 | zone_pkey, | ||
415 | name, | ||
416 | rd_count + 1, | ||
417 | rde, | ||
418 | &add_continuation, | ||
419 | &add_qe); | ||
420 | } | ||
421 | |||
422 | |||
423 | /** | ||
331 | * Function called with the result of the ECC key generation. | 424 | * Function called with the result of the ECC key generation. |
332 | * | 425 | * |
333 | * @param cls our configuration | 426 | * @param cls our configuration |
@@ -341,12 +434,6 @@ key_generation_cb (void *cls, | |||
341 | { | 434 | { |
342 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 435 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
343 | struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pub; | 436 | struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pub; |
344 | uint32_t type; | ||
345 | void *data = NULL; | ||
346 | size_t data_size = 0; | ||
347 | struct GNUNET_TIME_Relative etime_rel; | ||
348 | struct GNUNET_TIME_Absolute etime_abs; | ||
349 | int etime_is_rel = GNUNET_SYSERR; | ||
350 | struct GNUNET_NAMESTORE_RecordData rd; | 437 | struct GNUNET_NAMESTORE_RecordData rd; |
351 | 438 | ||
352 | keygen = NULL; | 439 | keygen = NULL; |
@@ -385,138 +472,97 @@ key_generation_cb (void *cls, | |||
385 | } | 472 | } |
386 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 473 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
387 | &do_shutdown, NULL); | 474 | &do_shutdown, NULL); |
388 | if (NULL == typestring) | 475 | if (add) |
389 | type = 0; | ||
390 | else | ||
391 | type = GNUNET_NAMESTORE_typename_to_number (typestring); | ||
392 | if (UINT32_MAX == type) | ||
393 | { | ||
394 | fprintf (stderr, _("Unsupported type `%s'\n"), typestring); | ||
395 | GNUNET_SCHEDULER_shutdown (); | ||
396 | ret = 1; | ||
397 | return; | ||
398 | } | ||
399 | if ((NULL == typestring) && (add | del)) | ||
400 | { | ||
401 | fprintf (stderr, | ||
402 | _("Missing option `%s' for operation `%s'\n"), | ||
403 | "-t", _("add/del")); | ||
404 | GNUNET_SCHEDULER_shutdown (); | ||
405 | ret = 1; | ||
406 | return; | ||
407 | } | ||
408 | if (NULL != value) | ||
409 | { | ||
410 | if (GNUNET_OK != | ||
411 | GNUNET_NAMESTORE_string_to_value (type, | ||
412 | value, | ||
413 | &data, | ||
414 | &data_size)) | ||
415 | { | ||
416 | fprintf (stderr, _("Value `%s' invalid for record type `%s'\n"), | ||
417 | value, | ||
418 | typestring); | ||
419 | GNUNET_SCHEDULER_shutdown (); | ||
420 | ret = 1; | ||
421 | return; | ||
422 | } | ||
423 | } else if (add | del) | ||
424 | { | ||
425 | fprintf (stderr, | ||
426 | _("Missing option `%s' for operation `%s'\n"), | ||
427 | "-V", _("add/del")); | ||
428 | ret = 1; | ||
429 | GNUNET_SCHEDULER_shutdown (); | ||
430 | return; | ||
431 | } | ||
432 | if (NULL != expirationstring) | ||
433 | { | 476 | { |
434 | if (0 == strcmp (expirationstring, "never")) | 477 | if (NULL == name) |
435 | { | 478 | { |
436 | etime_abs = GNUNET_TIME_UNIT_FOREVER_ABS; | 479 | fprintf (stderr, |
437 | etime_is_rel = GNUNET_NO; | 480 | _("Missing option `%s' for operation `%s'\n"), |
481 | "-n", _("add")); | ||
482 | GNUNET_SCHEDULER_shutdown (); | ||
483 | ret = 1; | ||
484 | return; | ||
438 | } | 485 | } |
439 | else if (GNUNET_OK == | 486 | if (NULL == typestring) |
440 | GNUNET_STRINGS_fancy_time_to_relative (expirationstring, | ||
441 | &etime_rel)) | ||
442 | { | 487 | { |
443 | etime_is_rel = GNUNET_YES; | 488 | fprintf (stderr, |
489 | _("Missing option `%s' for operation `%s'\n"), | ||
490 | "-t", _("add")); | ||
491 | GNUNET_SCHEDULER_shutdown (); | ||
492 | ret = 1; | ||
493 | return; | ||
444 | } | 494 | } |
445 | else if (GNUNET_OK == | 495 | type = GNUNET_NAMESTORE_typename_to_number (typestring); |
446 | GNUNET_STRINGS_fancy_time_to_absolute (expirationstring, | 496 | if (UINT32_MAX == type) |
447 | &etime_abs)) | ||
448 | { | 497 | { |
449 | etime_is_rel = GNUNET_NO; | 498 | fprintf (stderr, _("Unsupported type `%s'\n"), typestring); |
499 | GNUNET_SCHEDULER_shutdown (); | ||
500 | ret = 1; | ||
501 | return; | ||
450 | } | 502 | } |
451 | else | 503 | if (NULL == value) |
452 | { | 504 | { |
453 | fprintf (stderr, | 505 | fprintf (stderr, |
454 | _("Invalid time format `%s'\n"), | 506 | _("Missing option `%s' for operation `%s'\n"), |
455 | expirationstring); | 507 | "-V", _("add")); |
508 | ret = 1; | ||
456 | GNUNET_SCHEDULER_shutdown (); | 509 | GNUNET_SCHEDULER_shutdown (); |
457 | ret = 1; | ||
458 | return; | 510 | return; |
459 | } | 511 | } |
460 | if (etime_is_rel && del) | 512 | if (GNUNET_OK != |
513 | GNUNET_NAMESTORE_string_to_value (type, | ||
514 | value, | ||
515 | &data, | ||
516 | &data_size)) | ||
461 | { | 517 | { |
462 | fprintf (stderr, | 518 | fprintf (stderr, _("Value `%s' invalid for record type `%s'\n"), |
463 | _("Deletion requires either absolute time, or no time at all. Got relative time `%s' instead.\n"), | 519 | value, |
464 | expirationstring); | 520 | typestring); |
465 | GNUNET_SCHEDULER_shutdown (); | 521 | GNUNET_SCHEDULER_shutdown (); |
466 | ret = 1; | 522 | ret = 1; |
467 | return; | 523 | return; |
468 | } | 524 | } |
469 | } | 525 | if (NULL == expirationstring) |
470 | else if (add) | ||
471 | { | ||
472 | fprintf (stderr, | ||
473 | _("Missing option `%s' for operation `%s'\n"), | ||
474 | "-e", _("add")); | ||
475 | GNUNET_SCHEDULER_shutdown (); | ||
476 | ret = 1; | ||
477 | return; | ||
478 | } | ||
479 | memset (&rd, 0, sizeof (rd)); | ||
480 | if (add) | ||
481 | { | ||
482 | if (NULL == name) | ||
483 | { | 526 | { |
484 | fprintf (stderr, | 527 | fprintf (stderr, |
485 | _("Missing option `%s' for operation `%s'\n"), | 528 | _("Missing option `%s' for operation `%s'\n"), |
486 | "-n", _("add")); | 529 | "-e", _("add")); |
487 | GNUNET_SCHEDULER_shutdown (); | 530 | GNUNET_SCHEDULER_shutdown (); |
488 | ret = 1; | 531 | ret = 1; |
489 | return; | 532 | return; |
490 | } | 533 | } |
491 | rd.data = data; | 534 | if (0 == strcmp (expirationstring, "never")) |
492 | rd.data_size = data_size; | ||
493 | rd.record_type = type; | ||
494 | if (GNUNET_YES == etime_is_rel) | ||
495 | { | 535 | { |
496 | rd.expiration_time = etime_rel.rel_value; | 536 | etime_abs = GNUNET_TIME_UNIT_FOREVER_ABS; |
497 | rd.flags |= GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION; | 537 | etime_is_rel = GNUNET_NO; |
538 | } | ||
539 | else if (GNUNET_OK == | ||
540 | GNUNET_STRINGS_fancy_time_to_relative (expirationstring, | ||
541 | &etime_rel)) | ||
542 | { | ||
543 | etime_is_rel = GNUNET_YES; | ||
544 | } | ||
545 | else if (GNUNET_OK == | ||
546 | GNUNET_STRINGS_fancy_time_to_absolute (expirationstring, | ||
547 | &etime_abs)) | ||
548 | { | ||
549 | etime_is_rel = GNUNET_NO; | ||
498 | } | 550 | } |
499 | else if (GNUNET_NO == etime_is_rel) | ||
500 | rd.expiration_time = etime_abs.abs_value; | ||
501 | else | 551 | else |
502 | { | 552 | { |
503 | fprintf (stderr, | 553 | fprintf (stderr, |
504 | _("No valid expiration time for operation `%s'\n"), | 554 | _("Invalid time format `%s'\n"), |
505 | _("add")); | 555 | expirationstring); |
506 | GNUNET_SCHEDULER_shutdown (); | 556 | GNUNET_SCHEDULER_shutdown (); |
507 | ret = 1; | 557 | ret = 1; |
508 | return; | 558 | return; |
509 | } | 559 | } |
510 | if (1 != nonauthority) | 560 | add_qe = GNUNET_NAMESTORE_lookup_record (ns, |
511 | rd.flags |= GNUNET_NAMESTORE_RF_AUTHORITY; | 561 | &zone, |
512 | if (1 != public) | 562 | name, |
513 | rd.flags |= GNUNET_NAMESTORE_RF_PRIVATE; | 563 | 0, |
514 | add_qe = GNUNET_NAMESTORE_record_create (ns, | 564 | &get_existing_record, |
515 | zone_pkey, | 565 | NULL); |
516 | name, | ||
517 | &rd, | ||
518 | &add_continuation, | ||
519 | &add_qe); | ||
520 | } | 566 | } |
521 | if (del) | 567 | if (del) |
522 | { | 568 | { |
@@ -529,19 +575,12 @@ key_generation_cb (void *cls, | |||
529 | ret = 1; | 575 | ret = 1; |
530 | return; | 576 | return; |
531 | } | 577 | } |
532 | rd.data = data; | 578 | del_qe = GNUNET_NAMESTORE_record_put_by_authority (ns, |
533 | rd.data_size = data_size; | 579 | zone_pkey, |
534 | rd.record_type = type; | 580 | name, |
535 | rd.expiration_time = 0; | 581 | 0, NULL, |
536 | if (!etime_is_rel) | 582 | &del_continuation, |
537 | rd.expiration_time = etime_abs.abs_value; | 583 | NULL); |
538 | rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY; | ||
539 | del_qe = GNUNET_NAMESTORE_record_remove (ns, | ||
540 | zone_pkey, | ||
541 | name, | ||
542 | &rd, | ||
543 | &del_continuation, | ||
544 | NULL); | ||
545 | } | 584 | } |
546 | if (list) | 585 | if (list) |
547 | { | 586 | { |
@@ -580,6 +619,7 @@ key_generation_cb (void *cls, | |||
580 | ret = 1; | 619 | ret = 1; |
581 | return; | 620 | return; |
582 | } | 621 | } |
622 | memset (&rd, 0, sizeof (rd)); | ||
583 | rd.data = ≻ | 623 | rd.data = ≻ |
584 | rd.data_size = sizeof (struct GNUNET_CRYPTO_ShortHashCode); | 624 | rd.data_size = sizeof (struct GNUNET_CRYPTO_ShortHashCode); |
585 | rd.record_type = GNUNET_NAMESTORE_TYPE_PKEY; | 625 | rd.record_type = GNUNET_NAMESTORE_TYPE_PKEY; |
@@ -594,16 +634,15 @@ key_generation_cb (void *cls, | |||
594 | rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value; | 634 | rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value; |
595 | if (1 != nonauthority) | 635 | if (1 != nonauthority) |
596 | rd.flags |= GNUNET_NAMESTORE_RF_AUTHORITY; | 636 | rd.flags |= GNUNET_NAMESTORE_RF_AUTHORITY; |
597 | 637 | add_qe_uri = GNUNET_NAMESTORE_record_put_by_authority (ns, | |
598 | add_qe_uri = GNUNET_NAMESTORE_record_create (ns, | 638 | zone_pkey, |
599 | zone_pkey, | 639 | name, |
600 | name, | 640 | 1, |
601 | &rd, | 641 | &rd, |
602 | &add_continuation, | 642 | &add_continuation, |
603 | &add_qe_uri); | 643 | &add_qe_uri); |
604 | } | 644 | } |
605 | GNUNET_free_non_null (data); | 645 | GNUNET_free_non_null (data); |
606 | |||
607 | } | 646 | } |
608 | 647 | ||
609 | 648 | ||