aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-08-14 22:44:18 +0000
committerChristian Grothoff <christian@grothoff.org>2013-08-14 22:44:18 +0000
commit17d1146c625092753e1b29b7ce6f0dfb603fbd09 (patch)
treea747d21a24654dceebe2b31b9960bfcc1333d222
parent670ef7244591123c4d6432b8a76fe8b4a9e39ee4 (diff)
downloadgnunet-17d1146c625092753e1b29b7ce6f0dfb603fbd09.tar.gz
gnunet-17d1146c625092753e1b29b7ce6f0dfb603fbd09.zip
-addressing #2995
-rw-r--r--src/gns/gnunet-service-gns_resolver.c123
-rw-r--r--src/include/gnunet_namestore_service.h16
-rw-r--r--src/namestore/gnunet-namestore-fcfsd.c55
-rw-r--r--src/namestore/gnunet-service-namestore.c14
-rw-r--r--src/namestore/namestore_api.c21
5 files changed, 143 insertions, 86 deletions
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c
index 4eba4dae8..db5d8b93f 100644
--- a/src/gns/gnunet-service-gns_resolver.c
+++ b/src/gns/gnunet-service-gns_resolver.c
@@ -371,6 +371,11 @@ struct GetPseuAuthorityHandle
371 char label[GNUNET_DNSPARSER_MAX_LABEL_LENGTH + 1]; 371 char label[GNUNET_DNSPARSER_MAX_LABEL_LENGTH + 1];
372 372
373 /** 373 /**
374 * Label we are currently trying out (during #perform_pseu_lookup).
375 */
376 char *current_label;
377
378 /**
374 * The zone for which we are trying to find the PSEU record. 379 * The zone for which we are trying to find the PSEU record.
375 */ 380 */
376 struct GNUNET_CRYPTO_EccPublicKey target_zone; 381 struct GNUNET_CRYPTO_EccPublicKey target_zone;
@@ -542,6 +547,7 @@ free_get_pseu_authority_handle (struct GetPseuAuthorityHandle *gph)
542 gph->timeout_task = GNUNET_SCHEDULER_NO_TASK; 547 gph->timeout_task = GNUNET_SCHEDULER_NO_TASK;
543 } 548 }
544 GNUNET_CONTAINER_DLL_remove (gph_head, gph_tail, gph); 549 GNUNET_CONTAINER_DLL_remove (gph_head, gph_tail, gph);
550 GNUNET_free_non_null (gph->current_label);
545 GNUNET_free (gph); 551 GNUNET_free (gph);
546} 552}
547 553
@@ -570,44 +576,110 @@ create_pkey_cont (void* cls,
570 * (or with rd_count=0 to indicate no matches). 576 * (or with rd_count=0 to indicate no matches).
571 * 577 *
572 * @param cls the pending query 578 * @param cls the pending query
573 * @param key the key of the zone we did the lookup
574 * @param name the name for which we need an authority
575 * @param rd_count the number of records with 'name' 579 * @param rd_count the number of records with 'name'
576 * @param rd the record data 580 * @param rd the record data
577 */ 581 */
578static void 582static void
579process_pseu_lookup_ns (void *cls, 583process_pseu_lookup_ns (void *cls,
580 const struct GNUNET_CRYPTO_EccPrivateKey *key, 584 unsigned int rd_count,
581 const char *name, 585 const struct GNUNET_NAMESTORE_RecordData *rd);
586
587
588/**
589 * We obtained a result for our query to the shorten zone from
590 * the namestore. Try to decrypt.
591 *
592 * @param cls the handle to our shorten operation
593 * @param block resulting encrypted block
594 */
595static void
596process_pseu_block_ns (void *cls,
597 const struct GNUNET_NAMESTORE_Block *block)
598{
599 struct GetPseuAuthorityHandle *gph = cls;
600 struct GNUNET_CRYPTO_EccPublicKey pub;
601
602 gph->namestore_task = NULL;
603 if (NULL == block)
604 {
605 process_pseu_lookup_ns (gph, 0, NULL);
606 return;
607 }
608 GNUNET_CRYPTO_ecc_key_get_public (&gph->shorten_zone_key,
609 &pub);
610 if (GNUNET_OK !=
611 GNUNET_NAMESTORE_block_decrypt (block,
612 &pub,
613 gph->current_label,
614 &process_pseu_lookup_ns,
615 gph))
616 {
617 GNUNET_break (0);
618 free_get_pseu_authority_handle (gph);
619 return;
620 }
621}
622
623
624/**
625 * Lookup in the namestore for the shorten zone the given label.
626 *
627 * @param gph the handle to our shorten operation
628 * @param label the label to lookup
629 */
630static void
631perform_pseu_lookup (struct GetPseuAuthorityHandle *gph,
632 const char *label)
633{
634 struct GNUNET_CRYPTO_EccPublicKey pub;
635 struct GNUNET_HashCode query;
636
637 GNUNET_CRYPTO_ecc_key_get_public (&gph->shorten_zone_key,
638 &pub);
639 GNUNET_free_non_null (gph->current_label);
640 gph->current_label = GNUNET_strdup (label);
641 GNUNET_NAMESTORE_query_from_public_key (&pub,
642 label,
643 &query);
644 gph->namestore_task = GNUNET_NAMESTORE_lookup_block (namestore_handle,
645 &query,
646 &process_pseu_block_ns,
647 gph);
648}
649
650
651/**
652 * Namestore calls this function if we have record for this name.
653 * (or with rd_count=0 to indicate no matches).
654 *
655 * @param cls the pending query
656 * @param rd_count the number of records with 'name'
657 * @param rd the record data
658 */
659static void
660process_pseu_lookup_ns (void *cls,
582 unsigned int rd_count, 661 unsigned int rd_count,
583 const struct GNUNET_NAMESTORE_RecordData *rd) 662 const struct GNUNET_NAMESTORE_RecordData *rd)
584{ 663{
585 struct GetPseuAuthorityHandle *gph = cls; 664 struct GetPseuAuthorityHandle *gph = cls;
586 struct GNUNET_NAMESTORE_RecordData new_pkey; 665 struct GNUNET_NAMESTORE_RecordData new_pkey;
587 struct GNUNET_CRYPTO_EccPublicKey pub;
588 666
589 gph->namestore_task = NULL; 667 gph->namestore_task = NULL;
590 if (rd_count > 0) 668 if (rd_count > 0)
591 { 669 {
592 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 670 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
593 "Name `%s' already taken, cannot shorten.\n", 671 "Name `%s' already taken, cannot shorten.\n",
594 name); 672 gph->current_label);
595 /* if this was not yet the original label, try one more 673 /* if this was not yet the original label, try one more
596 time, this time not using PSEU but the original label */ 674 time, this time not using PSEU but the original label */
597 if (0 == strcmp (name, 675 if (0 == strcmp (gph->current_label,
598 gph->label)) 676 gph->label))
599 { 677 {
600 free_get_pseu_authority_handle (gph); 678 free_get_pseu_authority_handle (gph);
601 } 679 }
602 else 680 else
603 { 681 {
604 GNUNET_CRYPTO_ecc_key_get_public (&gph->shorten_zone_key, 682 perform_pseu_lookup (gph, gph->label);
605 &pub);
606 gph->namestore_task = GNUNET_NAMESTORE_lookup (namestore_handle,
607 &pub,
608 gph->label,
609 &process_pseu_lookup_ns,
610 gph);
611 } 683 }
612 return; 684 return;
613 } 685 }
@@ -615,7 +687,7 @@ process_pseu_lookup_ns (void *cls,
615 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 687 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
616 "Shortening `%s' to `%s'\n", 688 "Shortening `%s' to `%s'\n",
617 GNUNET_NAMESTORE_z2s (&gph->target_zone), 689 GNUNET_NAMESTORE_z2s (&gph->target_zone),
618 name); 690 gph->current_label);
619 new_pkey.expiration_time = UINT64_MAX; 691 new_pkey.expiration_time = UINT64_MAX;
620 new_pkey.data_size = sizeof (struct GNUNET_CRYPTO_EccPublicKey); 692 new_pkey.data_size = sizeof (struct GNUNET_CRYPTO_EccPublicKey);
621 new_pkey.data = &gph->target_zone; 693 new_pkey.data = &gph->target_zone;
@@ -626,7 +698,7 @@ process_pseu_lookup_ns (void *cls,
626 gph->namestore_task 698 gph->namestore_task
627 = GNUNET_NAMESTORE_records_store (namestore_handle, 699 = GNUNET_NAMESTORE_records_store (namestore_handle,
628 &gph->shorten_zone_key, 700 &gph->shorten_zone_key,
629 name, 701 gph->current_label,
630 1, &new_pkey, 702 1, &new_pkey,
631 &create_pkey_cont, gph); 703 &create_pkey_cont, gph);
632} 704}
@@ -642,30 +714,17 @@ static void
642process_pseu_result (struct GetPseuAuthorityHandle* gph, 714process_pseu_result (struct GetPseuAuthorityHandle* gph,
643 const char *pseu) 715 const char *pseu)
644{ 716{
645 struct GNUNET_CRYPTO_EccPublicKey pub;
646
647 GNUNET_CRYPTO_ecc_key_get_public (&gph->shorten_zone_key,
648 &pub);
649 if (NULL == pseu) 717 if (NULL == pseu)
650 { 718 {
651 /* no PSEU found, try original label */ 719 /* no PSEU found, try original label */
652 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 720 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
653 "No PSEU found, trying original label `%s' instead.\n", 721 "No PSEU found, trying original label `%s' instead.\n",
654 gph->label); 722 gph->label);
655 gph->namestore_task = GNUNET_NAMESTORE_lookup (namestore_handle, 723 perform_pseu_lookup (gph, gph->label);
656 &pub,
657 gph->label,
658 &process_pseu_lookup_ns,
659 gph);
660 return; 724 return;
661 } 725 }
662
663 /* check if 'pseu' is taken */ 726 /* check if 'pseu' is taken */
664 gph->namestore_task = GNUNET_NAMESTORE_lookup (namestore_handle, 727 perform_pseu_lookup (gph, pseu);
665 &pub,
666 pseu,
667 &process_pseu_lookup_ns,
668 gph);
669} 728}
670 729
671 730
diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h
index ddc7b038c..5b622e6f2 100644
--- a/src/include/gnunet_namestore_service.h
+++ b/src/include/gnunet_namestore_service.h
@@ -382,22 +382,6 @@ typedef void (*GNUNET_NAMESTORE_RecordCallback) (void *cls,
382 382
383 383
384/** 384/**
385 * Perform a lookup and decrypt the resulting block.
386 *
387 * @param h namestore to perform lookup in
388 * @param value_zone zone to look up record in
389 * @param label label to look for
390 * @param proc function to call with the result
391 * @param proc_cls closure for @a proc
392 */
393struct GNUNET_NAMESTORE_QueueEntry *
394GNUNET_NAMESTORE_lookup (struct GNUNET_NAMESTORE_Handle *h,
395 const struct GNUNET_CRYPTO_EccPublicKey *value_zone,
396 const char *label,
397 GNUNET_NAMESTORE_RecordMonitor proc, void *proc_cls);
398
399
400/**
401 * Cancel a namestore operation. The final callback from the 385 * Cancel a namestore operation. The final callback from the
402 * operation must not have been done yet. Must be called on any 386 * operation must not have been done yet. Must be called on any
403 * namestore operation that has not yet completed prior to calling 387 * namestore operation that has not yet completed prior to calling
diff --git a/src/namestore/gnunet-namestore-fcfsd.c b/src/namestore/gnunet-namestore-fcfsd.c
index d949806db..9fc75ee5e 100644
--- a/src/namestore/gnunet-namestore-fcfsd.c
+++ b/src/namestore/gnunet-namestore-fcfsd.c
@@ -525,22 +525,17 @@ zone_to_name_cb (void *cls,
525 * proceed to check if the requested key already exists. 525 * proceed to check if the requested key already exists.
526 * 526 *
527 * @param cls closure 527 * @param cls closure
528 * @param zone_key private key of the zone
529 * @param name name that is being mapped (at most 255 characters long)
530 * @param rd_count number of entries in 'rd' array 528 * @param rd_count number of entries in 'rd' array
531 * @param rd array of records with data to store 529 * @param rd array of records with data to store
532 */ 530 */
533static void 531static void
534lookup_result_processor (void *cls, 532lookup_result_processor (void *cls,
535 const struct GNUNET_CRYPTO_EccPrivateKey *zone_key,
536 const char *name,
537 unsigned int rd_count, 533 unsigned int rd_count,
538 const struct GNUNET_NAMESTORE_RecordData *rd) 534 const struct GNUNET_NAMESTORE_RecordData *rd)
539{ 535{
540 struct Request *request = cls; 536 struct Request *request = cls;
541 struct GNUNET_CRYPTO_EccPublicKey pub; 537 struct GNUNET_CRYPTO_EccPublicKey pub;
542 538
543 request->qe = NULL;
544 if (0 != rd_count) 539 if (0 != rd_count)
545 { 540 {
546 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 541 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -570,6 +565,43 @@ lookup_result_processor (void *cls,
570 565
571 566
572/** 567/**
568 * We got a block back from the namestore. Decrypt it
569 * and continue to process the result.
570 *
571 * @param cls the 'struct Request' we are processing
572 * @param block block returned form namestore, NULL on error
573 */
574static void
575lookup_block_processor (void *cls,
576 const struct GNUNET_NAMESTORE_Block *block)
577{
578 struct Request *request = cls;
579 struct GNUNET_CRYPTO_EccPublicKey pub;
580
581 request->qe = NULL;
582 if (NULL == block)
583 {
584 lookup_result_processor (request, 0, NULL);
585 return;
586 }
587 GNUNET_CRYPTO_ecc_key_get_public (fcfs_zone_pkey,
588 &pub);
589 if (GNUNET_OK !=
590 GNUNET_NAMESTORE_block_decrypt (block,
591 &pub,
592 request->domain_name,
593 &lookup_result_processor,
594 request))
595 {
596 GNUNET_break (0);
597 request->phase = RP_FAIL;
598 run_httpd_now ();
599 return;
600 }
601}
602
603
604/**
573 * Main MHD callback for handling requests. 605 * Main MHD callback for handling requests.
574 * 606 *
575 * @param cls unused 607 * @param cls unused
@@ -606,6 +638,7 @@ create_response (void *cls,
606 struct Request *request; 638 struct Request *request;
607 int ret; 639 int ret;
608 struct GNUNET_CRYPTO_EccPublicKey pub; 640 struct GNUNET_CRYPTO_EccPublicKey pub;
641 struct GNUNET_HashCode query;
609 642
610 if ( (0 == strcmp (method, MHD_HTTP_METHOD_GET)) || 643 if ( (0 == strcmp (method, MHD_HTTP_METHOD_GET)) ||
611 (0 == strcmp (method, MHD_HTTP_METHOD_HEAD)) ) 644 (0 == strcmp (method, MHD_HTTP_METHOD_HEAD)) )
@@ -684,11 +717,13 @@ create_response (void *cls,
684 request->phase = RP_LOOKUP; 717 request->phase = RP_LOOKUP;
685 GNUNET_CRYPTO_ecc_key_get_public (fcfs_zone_pkey, 718 GNUNET_CRYPTO_ecc_key_get_public (fcfs_zone_pkey,
686 &pub); 719 &pub);
687 request->qe = GNUNET_NAMESTORE_lookup (ns, 720 GNUNET_NAMESTORE_query_from_public_key (&pub,
688 &pub, 721 request->domain_name,
689 request->domain_name, 722 &query);
690 &lookup_result_processor, 723 request->qe = GNUNET_NAMESTORE_lookup_block (ns,
691 request); 724 &query,
725 &lookup_block_processor,
726 request);
692 break; 727 break;
693 case RP_LOOKUP: 728 case RP_LOOKUP:
694 break; 729 break;
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index 6cd0334c4..066bfa5bb 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -334,10 +334,10 @@ client_lookup (struct GNUNET_SERVER_Client *client)
334 334
335 335
336/** 336/**
337 * Context for name lookups passed from 'handle_lookup_name' to 337 * Context for name lookups passed from #handle_lookup_block to
338 * 'handle_lookup_name_it' as closure 338 * #handle_lookup_block_it as closure
339 */ 339 */
340struct LookupNameContext 340struct LookupBlockContext
341{ 341{
342 /** 342 /**
343 * The client to send the response to 343 * The client to send the response to
@@ -362,7 +362,7 @@ static void
362handle_lookup_block_it (void *cls, 362handle_lookup_block_it (void *cls,
363 const struct GNUNET_NAMESTORE_Block *block) 363 const struct GNUNET_NAMESTORE_Block *block)
364{ 364{
365 struct LookupNameContext *lnc = cls; 365 struct LookupBlockContext *lnc = cls;
366 struct LookupBlockResponseMessage *r; 366 struct LookupBlockResponseMessage *r;
367 size_t esize; 367 size_t esize;
368 368
@@ -379,7 +379,7 @@ handle_lookup_block_it (void *cls,
379 memcpy (&r[1], &block[1], esize); 379 memcpy (&r[1], &block[1], esize);
380 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 380 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
381 "Sending `%s' message\n", 381 "Sending `%s' message\n",
382 "NAMESTORE_LOOKUP_NAME_RESPONSE"); 382 "NAMESTORE_LOOKUP_BLOCK_RESPONSE");
383 GNUNET_SERVER_notification_context_unicast (snc, 383 GNUNET_SERVER_notification_context_unicast (snc,
384 lnc->nc->client, 384 lnc->nc->client,
385 &r->gns_header.header, 385 &r->gns_header.header,
@@ -401,14 +401,14 @@ handle_lookup_block (void *cls,
401 const struct GNUNET_MessageHeader *message) 401 const struct GNUNET_MessageHeader *message)
402{ 402{
403 const struct LookupBlockMessage *ln_msg; 403 const struct LookupBlockMessage *ln_msg;
404 struct LookupNameContext lnc; 404 struct LookupBlockContext lnc;
405 struct NamestoreClient *nc; 405 struct NamestoreClient *nc;
406 struct LookupBlockResponseMessage zir_end; 406 struct LookupBlockResponseMessage zir_end;
407 int ret; 407 int ret;
408 408
409 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 409 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
410 "Received `%s' message\n", 410 "Received `%s' message\n",
411 "NAMESTORE_LOOKUP_NAME"); 411 "NAMESTORE_LOOKUP_BLOCK");
412 nc = client_lookup(client); 412 nc = client_lookup(client);
413 ln_msg = (const struct LookupBlockMessage *) message; 413 ln_msg = (const struct LookupBlockMessage *) message;
414 lnc.request_id = ntohl (ln_msg->gns_header.r_id); 414 lnc.request_id = ntohl (ln_msg->gns_header.r_id);
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index 13cc32035..ea5d48eeb 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -1097,7 +1097,6 @@ GNUNET_NAMESTORE_lookup_block (struct GNUNET_NAMESTORE_Handle *h,
1097 const struct GNUNET_HashCode *derived_hash, 1097 const struct GNUNET_HashCode *derived_hash,
1098 GNUNET_NAMESTORE_BlockProcessor proc, void *proc_cls) 1098 GNUNET_NAMESTORE_BlockProcessor proc, void *proc_cls)
1099{ 1099{
1100
1101 struct GNUNET_NAMESTORE_QueueEntry *qe; 1100 struct GNUNET_NAMESTORE_QueueEntry *qe;
1102 struct PendingMessage *pe; 1101 struct PendingMessage *pe;
1103 struct LookupBlockMessage *msg; 1102 struct LookupBlockMessage *msg;
@@ -1132,26 +1131,6 @@ GNUNET_NAMESTORE_lookup_block (struct GNUNET_NAMESTORE_Handle *h,
1132 1131
1133 1132
1134/** 1133/**
1135 * Perform a lookup and decrypt the resulting block.
1136 *
1137 * @param h namestore to perform lookup in
1138 * @param value_zone zone to look up record in
1139 * @param label label to look for
1140 * @param proc function to call with the result
1141 * @param proc_cls closure for @a proc
1142 */
1143struct GNUNET_NAMESTORE_QueueEntry *
1144GNUNET_NAMESTORE_lookup (struct GNUNET_NAMESTORE_Handle *h,
1145 const struct GNUNET_CRYPTO_EccPublicKey *value_zone,
1146 const char *label,
1147 GNUNET_NAMESTORE_RecordMonitor proc, void *proc_cls)
1148{
1149 GNUNET_break (0); // FIXME: not implemented
1150 return NULL;
1151}
1152
1153
1154/**
1155 * Look for an existing PKEY delegation record for a given public key. 1134 * Look for an existing PKEY delegation record for a given public key.
1156 * Returns at most one result to the processor. 1135 * Returns at most one result to the processor.
1157 * 1136 *