diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-10-16 21:52:04 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-10-16 21:52:04 +0000 |
commit | dbc823a07a03e1085172038125b0edf15b0dc6fe (patch) | |
tree | 4e7c3bf60ce83e801c69a6566ea36d514b571cba /src/namestore/gnunet-namestore-fcfsd.c | |
parent | eec0e5088ec9437f5c0cf9d3ffef87603ad2777a (diff) | |
download | gnunet-dbc823a07a03e1085172038125b0edf15b0dc6fe.tar.gz gnunet-dbc823a07a03e1085172038125b0edf15b0dc6fe.zip |
-finishing split of namestore into namestore and namecache (#3065) -- in theory; in practice, somehow something broke badly, so the tests are now failing
Diffstat (limited to 'src/namestore/gnunet-namestore-fcfsd.c')
-rw-r--r-- | src/namestore/gnunet-namestore-fcfsd.c | 136 |
1 files changed, 56 insertions, 80 deletions
diff --git a/src/namestore/gnunet-namestore-fcfsd.c b/src/namestore/gnunet-namestore-fcfsd.c index 198d0a9dc..4feb7fc05 100644 --- a/src/namestore/gnunet-namestore-fcfsd.c +++ b/src/namestore/gnunet-namestore-fcfsd.c | |||
@@ -132,6 +132,11 @@ struct Request | |||
132 | struct GNUNET_NAMESTORE_QueueEntry *qe; | 132 | struct GNUNET_NAMESTORE_QueueEntry *qe; |
133 | 133 | ||
134 | /** | 134 | /** |
135 | * Active iteration with the namestore. | ||
136 | */ | ||
137 | struct GNUNET_NAMESTORE_ZoneIterator *zi; | ||
138 | |||
139 | /** | ||
135 | * Current processing phase. | 140 | * Current processing phase. |
136 | */ | 141 | */ |
137 | enum Phase phase; | 142 | enum Phase phase; |
@@ -460,16 +465,14 @@ post_iterator (void *cls, | |||
460 | } | 465 | } |
461 | 466 | ||
462 | 467 | ||
463 | |||
464 | |||
465 | /** | 468 | /** |
466 | * Continuation called to notify client about result of the | 469 | * Continuation called to notify client about result of the |
467 | * operation. | 470 | * operation. |
468 | * | 471 | * |
469 | * @param cls closure | 472 | * @param cls closure |
470 | * @param success GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate) | 473 | * @param success #GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate) |
471 | * GNUNET_NO if content was already there | 474 | * #GNUNET_NO if content was already there |
472 | * GNUNET_YES (or other positive value) on success | 475 | * #GNUNET_YES (or other positive value) on success |
473 | * @param emsg NULL on success, otherwise an error message | 476 | * @param emsg NULL on success, otherwise an error message |
474 | */ | 477 | */ |
475 | static void | 478 | static void |
@@ -500,7 +503,7 @@ put_continuation (void *cls, | |||
500 | * @param cls closure | 503 | * @param cls closure |
501 | * @param zone_key public key of the zone | 504 | * @param zone_key public key of the zone |
502 | * @param name name that is being mapped (at most 255 characters long) | 505 | * @param name name that is being mapped (at most 255 characters long) |
503 | * @param rd_count number of entries in 'rd' array | 506 | * @param rd_count number of entries in @a rd array |
504 | * @param rd array of records with data to store | 507 | * @param rd array of records with data to store |
505 | */ | 508 | */ |
506 | static void | 509 | static void |
@@ -541,84 +544,62 @@ zone_to_name_cb (void *cls, | |||
541 | 544 | ||
542 | 545 | ||
543 | /** | 546 | /** |
544 | * Process a record that was stored in the namestore. Used to check if | ||
545 | * the requested name already exists in the namestore. If not, | ||
546 | * proceed to check if the requested key already exists. | ||
547 | * | ||
548 | * @param cls closure | ||
549 | * @param rd_count number of entries in 'rd' array | ||
550 | * @param rd array of records with data to store | ||
551 | */ | ||
552 | static void | ||
553 | lookup_result_processor (void *cls, | ||
554 | unsigned int rd_count, | ||
555 | const struct GNUNET_GNSRECORD_Data *rd) | ||
556 | { | ||
557 | struct Request *request = cls; | ||
558 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | ||
559 | |||
560 | if (0 != rd_count) | ||
561 | { | ||
562 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
563 | _("Found %u existing records for domain `%s'\n"), | ||
564 | rd_count, | ||
565 | request->domain_name); | ||
566 | request->phase = RP_FAIL; | ||
567 | run_httpd_now (); | ||
568 | return; | ||
569 | } | ||
570 | if (GNUNET_OK != | ||
571 | GNUNET_CRYPTO_ecdsa_public_key_from_string (request->public_key, | ||
572 | strlen (request->public_key), | ||
573 | &pub)) | ||
574 | { | ||
575 | GNUNET_break (0); | ||
576 | request->phase = RP_FAIL; | ||
577 | run_httpd_now (); | ||
578 | return; | ||
579 | } | ||
580 | request->qe = GNUNET_NAMESTORE_zone_to_name (ns, | ||
581 | &fcfs_zone_pkey, | ||
582 | &pub, | ||
583 | &zone_to_name_cb, | ||
584 | request); | ||
585 | } | ||
586 | |||
587 | |||
588 | /** | ||
589 | * We got a block back from the namestore. Decrypt it | 547 | * We got a block back from the namestore. Decrypt it |
590 | * and continue to process the result. | 548 | * and continue to process the result. |
591 | * | 549 | * |
592 | * @param cls the 'struct Request' we are processing | 550 | * @param cls the 'struct Request' we are processing |
593 | * @param block block returned form namestore, NULL on error | 551 | * @param zone private key of the zone; NULL on disconnect |
552 | * @param label label of the records; NULL on disconnect | ||
553 | * @param rd_count number of entries in @a rd array, 0 if label was deleted | ||
554 | * @param rd array of records with data to store | ||
594 | */ | 555 | */ |
595 | static void | 556 | static void |
596 | lookup_block_processor (void *cls, | 557 | lookup_block_processor (void *cls, |
597 | const struct GNUNET_GNSRECORD_Block *block) | 558 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
559 | const char *label, | ||
560 | unsigned int rd_count, | ||
561 | const struct GNUNET_GNSRECORD_Data *rd) | ||
598 | { | 562 | { |
599 | struct Request *request = cls; | 563 | struct Request *request = cls; |
600 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | 564 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; |
601 | 565 | ||
602 | request->qe = NULL; | 566 | request->qe = NULL; |
603 | if (NULL == block) | 567 | if (NULL == label) |
604 | { | 568 | { |
605 | lookup_result_processor (request, 0, NULL); | 569 | request->zi = NULL; |
570 | if (GNUNET_OK != | ||
571 | GNUNET_CRYPTO_ecdsa_public_key_from_string (request->public_key, | ||
572 | strlen (request->public_key), | ||
573 | &pub)) | ||
574 | { | ||
575 | GNUNET_break (0); | ||
576 | request->phase = RP_FAIL; | ||
577 | run_httpd_now (); | ||
578 | return; | ||
579 | } | ||
580 | request->qe = GNUNET_NAMESTORE_zone_to_name (ns, | ||
581 | &fcfs_zone_pkey, | ||
582 | &pub, | ||
583 | &zone_to_name_cb, | ||
584 | request); | ||
606 | return; | 585 | return; |
607 | } | 586 | } |
608 | GNUNET_CRYPTO_ecdsa_key_get_public (&fcfs_zone_pkey, | 587 | if (0 != strcmp (label, |
609 | &pub); | 588 | request->domain_name)) |
610 | if (GNUNET_OK != | ||
611 | GNUNET_GNSRECORD_block_decrypt (block, | ||
612 | &pub, | ||
613 | request->domain_name, | ||
614 | &lookup_result_processor, | ||
615 | request)) | ||
616 | { | 589 | { |
617 | GNUNET_break (0); | 590 | GNUNET_NAMESTORE_zone_iterator_next (request->zi); |
618 | request->phase = RP_FAIL; | ||
619 | run_httpd_now (); | ||
620 | return; | 591 | return; |
621 | } | 592 | } |
593 | GNUNET_NAMESTORE_zone_iteration_stop (request->zi); | ||
594 | request->zi = NULL; | ||
595 | GNUNET_break (0 != rd_count); | ||
596 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
597 | _("Found %u existing records for domain `%s'\n"), | ||
598 | rd_count, | ||
599 | request->domain_name); | ||
600 | request->phase = RP_FAIL; | ||
601 | run_httpd_now (); | ||
602 | return; | ||
622 | } | 603 | } |
623 | 604 | ||
624 | 605 | ||
@@ -638,7 +619,7 @@ lookup_block_processor (void *cls, | |||
638 | * data *will* be made available incrementally in | 619 | * data *will* be made available incrementally in |
639 | * upload_data) | 620 | * upload_data) |
640 | * @param upload_data_size set initially to the size of the | 621 | * @param upload_data_size set initially to the size of the |
641 | * upload_data provided; the method must update this | 622 | * @a upload_data provided; the method must update this |
642 | * value to the number of bytes NOT processed; | 623 | * value to the number of bytes NOT processed; |
643 | * @param ptr pointer to location where we store the 'struct Request' | 624 | * @param ptr pointer to location where we store the 'struct Request' |
644 | * @return MHD_YES if the connection was handled successfully, | 625 | * @return MHD_YES if the connection was handled successfully, |
@@ -657,9 +638,8 @@ create_response (void *cls, | |||
657 | { | 638 | { |
658 | struct MHD_Response *response; | 639 | struct MHD_Response *response; |
659 | struct Request *request; | 640 | struct Request *request; |
660 | int ret; | ||
661 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | 641 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; |
662 | struct GNUNET_HashCode query; | 642 | int ret; |
663 | 643 | ||
664 | if ( (0 == strcmp (method, MHD_HTTP_METHOD_GET)) || | 644 | if ( (0 == strcmp (method, MHD_HTTP_METHOD_GET)) || |
665 | (0 == strcmp (method, MHD_HTTP_METHOD_HEAD)) ) | 645 | (0 == strcmp (method, MHD_HTTP_METHOD_HEAD)) ) |
@@ -709,8 +689,8 @@ create_response (void *cls, | |||
709 | } | 689 | } |
710 | if (GNUNET_OK != | 690 | if (GNUNET_OK != |
711 | GNUNET_CRYPTO_ecdsa_public_key_from_string (request->public_key, | 691 | GNUNET_CRYPTO_ecdsa_public_key_from_string (request->public_key, |
712 | strlen (request->public_key), | 692 | strlen (request->public_key), |
713 | &pub)) | 693 | &pub)) |
714 | { | 694 | { |
715 | /* parse error */ | 695 | /* parse error */ |
716 | return fill_s_reply ("Failed to parse given public key", | 696 | return fill_s_reply ("Failed to parse given public key", |
@@ -736,15 +716,11 @@ create_response (void *cls, | |||
736 | request, connection); | 716 | request, connection); |
737 | } | 717 | } |
738 | request->phase = RP_LOOKUP; | 718 | request->phase = RP_LOOKUP; |
739 | GNUNET_CRYPTO_ecdsa_key_get_public (&fcfs_zone_pkey, | 719 | /* FIXME: would be nice to have a more efficient API for this */ |
740 | &pub); | 720 | request->zi = GNUNET_NAMESTORE_zone_iteration_start (ns, |
741 | GNUNET_GNSRECORD_query_from_public_key (&pub, | 721 | &fcfs_zone_pkey, |
742 | request->domain_name, | 722 | &lookup_block_processor, |
743 | &query); | 723 | request); |
744 | request->qe = GNUNET_NAMESTORE_lookup_block (ns, | ||
745 | &query, | ||
746 | &lookup_block_processor, | ||
747 | request); | ||
748 | break; | 724 | break; |
749 | case RP_LOOKUP: | 725 | case RP_LOOKUP: |
750 | break; | 726 | break; |