diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-06-13 17:36:47 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-06-13 17:36:47 +0000 |
commit | 1f5326cd1032cbcc914c7809df1a64994eeebbe9 (patch) | |
tree | bd04389845d0b3096d98e3e97033040486108830 /src/gns/gns_api.c | |
parent | a8c5598ba43fcd61a5a340f14a3bab1613adbe7c (diff) | |
download | gnunet-1f5326cd1032cbcc914c7809df1a64994eeebbe9.tar.gz gnunet-1f5326cd1032cbcc914c7809df1a64994eeebbe9.zip |
- big shorten algorithm rewrite
- API change for lookup
- tests fixed
- introduces 3 zone system: root, private and shortened
Diffstat (limited to 'src/gns/gns_api.c')
-rw-r--r-- | src/gns/gns_api.c | 65 |
1 files changed, 31 insertions, 34 deletions
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c index 2e1e9712c..9806082bc 100644 --- a/src/gns/gns_api.c +++ b/src/gns/gns_api.c | |||
@@ -640,9 +640,9 @@ get_request_id (struct GNUNET_GNS_Handle *h) | |||
640 | * @param handle handle to the GNS service | 640 | * @param handle handle to the GNS service |
641 | * @param name the name to look up | 641 | * @param name the name to look up |
642 | * @param zone the zone to start the resolution in | 642 | * @param zone the zone to start the resolution in |
643 | * @param shorten_zone the zone where to shorten names into | ||
644 | * @param type the record type to look up | 643 | * @param type the record type to look up |
645 | * @param only_cached GNUNET_NO to only check locally not DHT for performance | 644 | * @param only_cached GNUNET_NO to only check locally not DHT for performance |
645 | * @param shorten_key the private key of the shorten zone (can be NULL) | ||
646 | * @param proc processor to call on result | 646 | * @param proc processor to call on result |
647 | * @param proc_cls closure for processor | 647 | * @param proc_cls closure for processor |
648 | * @return handle to the get | 648 | * @return handle to the get |
@@ -651,9 +651,9 @@ struct GNUNET_GNS_QueueEntry * | |||
651 | GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle, | 651 | GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle, |
652 | const char * name, | 652 | const char * name, |
653 | struct GNUNET_CRYPTO_ShortHashCode *zone, | 653 | struct GNUNET_CRYPTO_ShortHashCode *zone, |
654 | struct GNUNET_CRYPTO_ShortHashCode *shorten_zone, | ||
655 | enum GNUNET_GNS_RecordType type, | 654 | enum GNUNET_GNS_RecordType type, |
656 | int only_cached, | 655 | int only_cached, |
656 | struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key, | ||
657 | GNUNET_GNS_LookupResultProcessor proc, | 657 | GNUNET_GNS_LookupResultProcessor proc, |
658 | void *proc_cls) | 658 | void *proc_cls) |
659 | { | 659 | { |
@@ -662,13 +662,24 @@ GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle, | |||
662 | struct GNUNET_GNS_QueueEntry *qe; | 662 | struct GNUNET_GNS_QueueEntry *qe; |
663 | size_t msize; | 663 | size_t msize; |
664 | struct PendingMessage *pending; | 664 | struct PendingMessage *pending; |
665 | struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *pkey_enc=NULL; | ||
666 | size_t key_len = 0; | ||
667 | char* pkey_tmp; | ||
668 | |||
669 | if (NULL != shorten_key) | ||
670 | { | ||
671 | pkey_enc = GNUNET_CRYPTO_rsa_encode_key (shorten_key); | ||
672 | GNUNET_assert (pkey_enc != NULL); | ||
673 | key_len = ntohs (pkey_enc->len); | ||
674 | } | ||
665 | 675 | ||
666 | if (NULL == name) | 676 | if (NULL == name) |
667 | { | 677 | { |
668 | return NULL; | 678 | return NULL; |
669 | } | 679 | } |
670 | 680 | ||
671 | msize = sizeof (struct GNUNET_GNS_ClientLookupMessage) + strlen(name) + 1; | 681 | msize = sizeof (struct GNUNET_GNS_ClientLookupMessage) |
682 | + key_len + strlen(name) + 1; | ||
672 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to lookup %s in GNS\n", name); | 683 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to lookup %s in GNS\n", name); |
673 | 684 | ||
674 | qe = GNUNET_malloc(sizeof (struct GNUNET_GNS_QueueEntry)); | 685 | qe = GNUNET_malloc(sizeof (struct GNUNET_GNS_QueueEntry)); |
@@ -701,26 +712,23 @@ GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle, | |||
701 | memset(&lookup_msg->zone, 0, sizeof(struct GNUNET_CRYPTO_ShortHashCode)); | 712 | memset(&lookup_msg->zone, 0, sizeof(struct GNUNET_CRYPTO_ShortHashCode)); |
702 | } | 713 | } |
703 | 714 | ||
704 | if (NULL != shorten_zone) | 715 | lookup_msg->type = htonl(type); |
716 | |||
717 | pkey_tmp = (char *) &lookup_msg[1]; | ||
718 | |||
719 | if (pkey_enc != NULL) | ||
705 | { | 720 | { |
706 | lookup_msg->use_shorten_zone = htonl(1); | 721 | lookup_msg->have_key = htonl(1); |
707 | memcpy(&lookup_msg->shorten_zone, shorten_zone, | 722 | memcpy(pkey_tmp, pkey_enc, key_len); |
708 | sizeof(struct GNUNET_CRYPTO_ShortHashCode)); | ||
709 | } | 723 | } |
710 | else | 724 | else |
711 | { | 725 | lookup_msg->have_key = htonl(0); |
712 | lookup_msg->use_shorten_zone = htonl(0); | ||
713 | memset(&lookup_msg->shorten_zone, 0, | ||
714 | sizeof(struct GNUNET_CRYPTO_ShortHashCode)); | ||
715 | } | ||
716 | |||
717 | lookup_msg->type = htonl(type); | ||
718 | 726 | ||
719 | memcpy(&lookup_msg[1], name, strlen(name)); | 727 | memcpy(&pkey_tmp[key_len], name, strlen(name)); |
720 | 728 | ||
721 | GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head, handle->pending_tail, | 729 | GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head, handle->pending_tail, |
722 | pending); | 730 | pending); |
723 | 731 | GNUNET_free_non_null (pkey_enc); | |
724 | process_pending_messages (handle); | 732 | process_pending_messages (handle); |
725 | return qe; | 733 | return qe; |
726 | } | 734 | } |
@@ -732,6 +740,7 @@ GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle, | |||
732 | * @param name the name to look up | 740 | * @param name the name to look up |
733 | * @param type the record type to look up | 741 | * @param type the record type to look up |
734 | * @param only_cached GNUNET_NO to only check locally not DHT for performance | 742 | * @param only_cached GNUNET_NO to only check locally not DHT for performance |
743 | * @param shorten_key the private key of the shorten zone (can be NULL) | ||
735 | * @param proc processor to call on result | 744 | * @param proc processor to call on result |
736 | * @param proc_cls closure for processor | 745 | * @param proc_cls closure for processor |
737 | * @return handle to the get | 746 | * @return handle to the get |
@@ -741,12 +750,15 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, | |||
741 | const char * name, | 750 | const char * name, |
742 | enum GNUNET_GNS_RecordType type, | 751 | enum GNUNET_GNS_RecordType type, |
743 | int only_cached, | 752 | int only_cached, |
753 | struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key, | ||
744 | GNUNET_GNS_LookupResultProcessor proc, | 754 | GNUNET_GNS_LookupResultProcessor proc, |
745 | void *proc_cls) | 755 | void *proc_cls) |
746 | { | 756 | { |
747 | return GNUNET_GNS_lookup_zone (handle, name, | 757 | return GNUNET_GNS_lookup_zone (handle, name, |
748 | NULL, NULL, | 758 | NULL, |
749 | type, only_cached, proc, proc_cls); | 759 | type, only_cached, |
760 | shorten_key, | ||
761 | proc, proc_cls); | ||
750 | } | 762 | } |
751 | 763 | ||
752 | /** | 764 | /** |
@@ -755,7 +767,6 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, | |||
755 | * @param handle handle to the GNS service | 767 | * @param handle handle to the GNS service |
756 | * @param name the name to look up | 768 | * @param name the name to look up |
757 | * @param zone the zone to start the resolution in | 769 | * @param zone the zone to start the resolution in |
758 | * @param shorten_zone the zone where to shorten names into | ||
759 | * @param proc function to call on result | 770 | * @param proc function to call on result |
760 | * @param proc_cls closure for processor | 771 | * @param proc_cls closure for processor |
761 | * @return handle to the operation | 772 | * @return handle to the operation |
@@ -764,7 +775,6 @@ struct GNUNET_GNS_QueueEntry * | |||
764 | GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle, | 775 | GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle, |
765 | const char * name, | 776 | const char * name, |
766 | struct GNUNET_CRYPTO_ShortHashCode *zone, | 777 | struct GNUNET_CRYPTO_ShortHashCode *zone, |
767 | struct GNUNET_CRYPTO_ShortHashCode *shorten_zone, | ||
768 | GNUNET_GNS_ShortenResultProcessor proc, | 778 | GNUNET_GNS_ShortenResultProcessor proc, |
769 | void *proc_cls) | 779 | void *proc_cls) |
770 | { | 780 | { |
@@ -812,19 +822,6 @@ GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle, | |||
812 | memset(&shorten_msg->zone, 0, sizeof(struct GNUNET_CRYPTO_ShortHashCode)); | 822 | memset(&shorten_msg->zone, 0, sizeof(struct GNUNET_CRYPTO_ShortHashCode)); |
813 | } | 823 | } |
814 | 824 | ||
815 | if (NULL != shorten_zone) | ||
816 | { | ||
817 | shorten_msg->use_shorten_zone = htonl(1); | ||
818 | memcpy(&shorten_msg->shorten_zone, shorten_zone, | ||
819 | sizeof(struct GNUNET_CRYPTO_ShortHashCode)); | ||
820 | } | ||
821 | else | ||
822 | { | ||
823 | shorten_msg->use_shorten_zone = htonl(0); | ||
824 | memset(&shorten_msg->shorten_zone, 0, | ||
825 | sizeof(struct GNUNET_CRYPTO_ShortHashCode)); | ||
826 | } | ||
827 | |||
828 | memcpy(&shorten_msg[1], name, strlen(name)); | 825 | memcpy(&shorten_msg[1], name, strlen(name)); |
829 | 826 | ||
830 | GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head, handle->pending_tail, | 827 | GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head, handle->pending_tail, |
@@ -849,7 +846,7 @@ GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle, | |||
849 | GNUNET_GNS_ShortenResultProcessor proc, | 846 | GNUNET_GNS_ShortenResultProcessor proc, |
850 | void *proc_cls) | 847 | void *proc_cls) |
851 | { | 848 | { |
852 | return GNUNET_GNS_shorten_zone (handle, name, NULL, NULL, proc, proc_cls); | 849 | return GNUNET_GNS_shorten_zone (handle, name, NULL, proc, proc_cls); |
853 | } | 850 | } |
854 | /** | 851 | /** |
855 | * Perform an authority lookup for a given name. | 852 | * Perform an authority lookup for a given name. |