aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gns/gns.h21
-rw-r--r--src/gns/gns_api.c69
-rw-r--r--src/gns/gnunet-service-gns.c94
-rw-r--r--src/include/gnunet_gns_service.h40
4 files changed, 214 insertions, 10 deletions
diff --git a/src/gns/gns.h b/src/gns/gns.h
index 5950c460b..408b68606 100644
--- a/src/gns/gns.h
+++ b/src/gns/gns.h
@@ -53,9 +53,18 @@ struct GNUNET_GNS_ClientLookupMessage
53 uint32_t id GNUNET_PACKED; 53 uint32_t id GNUNET_PACKED;
54 54
55 /** 55 /**
56 * Should we look up in the default zone?
57 */
58 uint32_t use_default_zone GNUNET_PACKED;
59
60 /**
61 * If use_default_zone is empty this zone is used for lookup
62 */
63 struct GNUNET_CRYPTO_ShortHashCode zone;
64
65 /**
56 * the type of record to look up 66 * the type of record to look up
57 */ 67 */
58 // FIXME: bad type - should be of GNUNET_GNS_RecordType
59 enum GNUNET_GNS_RecordType type; 68 enum GNUNET_GNS_RecordType type;
60 69
61 /* Followed by the name to look up */ 70 /* Followed by the name to look up */
@@ -102,6 +111,16 @@ struct GNUNET_GNS_ClientShortenMessage
102 */ 111 */
103 uint32_t id GNUNET_PACKED; 112 uint32_t id GNUNET_PACKED;
104 113
114 /**
115 * Should we look up in the default zone?
116 */
117 uint32_t use_default_zone GNUNET_PACKED;
118
119 /**
120 * If use_default_zone is empty this zone is used for lookup
121 */
122 struct GNUNET_CRYPTO_ShortHashCode zone;
123
105 /* Followed by the name to shorten up */ 124 /* Followed by the name to shorten up */
106}; 125};
107 126
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c
index 1a06f34e0..a92280f25 100644
--- a/src/gns/gns_api.c
+++ b/src/gns/gns_api.c
@@ -639,14 +639,16 @@ get_request_id (struct GNUNET_GNS_Handle *h)
639 * 639 *
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 type the record type to look up 643 * @param type the record type to look up
643 * @param proc processor to call on result 644 * @param proc processor to call on result
644 * @param proc_cls closure for processor 645 * @param proc_cls closure for processor
645 * @return handle to the get 646 * @return handle to the get
646 */ 647 */
647struct GNUNET_GNS_QueueEntry * 648struct GNUNET_GNS_QueueEntry *
648GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, 649GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle,
649 const char * name, 650 const char * name,
651 struct GNUNET_CRYPTO_ShortHashCode *zone,
650 enum GNUNET_GNS_RecordType type, 652 enum GNUNET_GNS_RecordType type,
651 GNUNET_GNS_LookupResultProcessor proc, 653 GNUNET_GNS_LookupResultProcessor proc,
652 void *proc_cls) 654 void *proc_cls)
@@ -682,6 +684,18 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
682 lookup_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_LOOKUP); 684 lookup_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_LOOKUP);
683 lookup_msg->header.size = htons (msize); 685 lookup_msg->header.size = htons (msize);
684 lookup_msg->id = htonl(qe->r_id); 686 lookup_msg->id = htonl(qe->r_id);
687
688 if (NULL != zone)
689 {
690 lookup_msg->use_default_zone = htonl(0);
691 memcpy(&lookup_msg->zone, zone, sizeof(struct GNUNET_CRYPTO_ShortHashCode));
692 }
693 else
694 {
695 lookup_msg->use_default_zone = htonl(1);
696 memset(&lookup_msg->zone, 0, sizeof(struct GNUNET_CRYPTO_ShortHashCode));
697 }
698
685 lookup_msg->type = htonl(type); 699 lookup_msg->type = htonl(type);
686 700
687 memcpy(&lookup_msg[1], name, strlen(name)); 701 memcpy(&lookup_msg[1], name, strlen(name));
@@ -693,19 +707,40 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
693 return qe; 707 return qe;
694} 708}
695 709
710/**
711 * Perform an asynchronous Lookup operation on the GNS.
712 *
713 * @param handle handle to the GNS service
714 * @param name the name to look up
715 * @param type the record type to look up
716 * @param proc processor to call on result
717 * @param proc_cls closure for processor
718 * @return handle to the get
719 */
720struct GNUNET_GNS_QueueEntry *
721GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
722 const char * name,
723 enum GNUNET_GNS_RecordType type,
724 GNUNET_GNS_LookupResultProcessor proc,
725 void *proc_cls)
726{
727 return GNUNET_GNS_lookup_zone (handle, name, NULL, type, proc, proc_cls);
728}
696 729
697/** 730/**
698 * Perform a name shortening operation on the GNS. 731 * Perform a name shortening operation on the GNS.
699 * 732 *
700 * @param handle handle to the GNS service 733 * @param handle handle to the GNS service
701 * @param name the name to look up 734 * @param name the name to look up
735 * @param zone the zone to start the resolution in
702 * @param proc function to call on result 736 * @param proc function to call on result
703 * @param proc_cls closure for processor 737 * @param proc_cls closure for processor
704 * @return handle to the operation 738 * @return handle to the operation
705 */ 739 */
706struct GNUNET_GNS_QueueEntry * 740struct GNUNET_GNS_QueueEntry *
707GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle, 741GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle,
708 const char * name, 742 const char * name,
743 struct GNUNET_CRYPTO_ShortHashCode *zone,
709 GNUNET_GNS_ShortenResultProcessor proc, 744 GNUNET_GNS_ShortenResultProcessor proc,
710 void *proc_cls) 745 void *proc_cls)
711{ 746{
@@ -740,6 +775,18 @@ GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle,
740 shorten_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_SHORTEN); 775 shorten_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_SHORTEN);
741 shorten_msg->header.size = htons (msize); 776 shorten_msg->header.size = htons (msize);
742 shorten_msg->id = htonl(qe->r_id); 777 shorten_msg->id = htonl(qe->r_id);
778
779 if (NULL != zone)
780 {
781 shorten_msg->use_default_zone = htonl(0);
782 memcpy(&shorten_msg->zone, zone,
783 sizeof(struct GNUNET_CRYPTO_ShortHashCode));
784 }
785 else
786 {
787 shorten_msg->use_default_zone = htonl(1);
788 memset(&shorten_msg->zone, 0, sizeof(struct GNUNET_CRYPTO_ShortHashCode));
789 }
743 790
744 memcpy(&shorten_msg[1], name, strlen(name)); 791 memcpy(&shorten_msg[1], name, strlen(name));
745 792
@@ -750,7 +797,23 @@ GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle,
750 return qe; 797 return qe;
751} 798}
752 799
753 800/**
801 * Perform a name shortening operation on the GNS.
802 *
803 * @param handle handle to the GNS service
804 * @param name the name to look up
805 * @param proc function to call on result
806 * @param proc_cls closure for processor
807 * @return handle to the operation
808 */
809struct GNUNET_GNS_QueueEntry *
810GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle,
811 const char * name,
812 GNUNET_GNS_ShortenResultProcessor proc,
813 void *proc_cls)
814{
815 return GNUNET_GNS_shorten_zone (handle, name, NULL, proc, proc_cls);
816}
754/** 817/**
755 * Perform an authority lookup for a given name. 818 * Perform an authority lookup for a given name.
756 * 819 *
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index a27d79cc7..d964a6f68 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -60,6 +60,9 @@ struct ClientShortenHandle
60 /* request type */ 60 /* request type */
61 enum GNUNET_GNS_RecordType type; 61 enum GNUNET_GNS_RecordType type;
62 62
63 /* optional zone private key used for lookup */
64 struct GNUNET_CRYPTO_RsaPrivateKey *zone_key;
65
63 /* name to shorten */ 66 /* name to shorten */
64 char* name; 67 char* name;
65 68
@@ -97,6 +100,9 @@ struct ClientLookupHandle
97 /* request type */ 100 /* request type */
98 enum GNUNET_GNS_RecordType type; 101 enum GNUNET_GNS_RecordType type;
99 102
103 /* optional zone private key used for lookup */
104 struct GNUNET_CRYPTO_RsaPrivateKey *zone_key;
105
100 /* the name to look up */ 106 /* the name to look up */
101 char* name; //Needed? 107 char* name; //Needed?
102}; 108};
@@ -416,6 +422,43 @@ update_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
416 NULL); 422 NULL);
417} 423}
418 424
425/**
426 * Lookup the private key for the zone
427 *
428 * @param zone the zone we want a private key for
429 * @return NULL of not found else the key
430 */
431struct GNUNET_CRYPTO_RsaPrivateKey*
432lookup_private_key(struct GNUNET_CRYPTO_ShortHashCode *zone)
433{
434 char* keydir;
435 struct GNUNET_CRYPTO_ShortHashAsciiEncoded zonename;
436 char* location;
437 struct GNUNET_CRYPTO_RsaPrivateKey *key = NULL;
438
439 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (GNS_cfg,
440 "namestore",
441 "ZONEFILE_DIRECTORY", &keydir))
442 {
443 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
444 "No zonefile directory!\n");
445 return NULL;
446 }
447
448 GNUNET_CRYPTO_short_hash_to_enc (zone, &zonename);
449
450 GNUNET_asprintf(&location, "%s%s%s.zkey", keydir,
451 DIR_SEPARATOR_STR, zonename);
452
453 if (GNUNET_YES == GNUNET_DISK_file_test (location))
454 key = GNUNET_CRYPTO_rsa_key_create_from_file (location);
455
456 GNUNET_free(location);
457 GNUNET_free(keydir);
458
459 return key;
460
461}
419 462
420/* END DHT ZONE PROPAGATION */ 463/* END DHT ZONE PROPAGATION */
421 464
@@ -456,6 +499,7 @@ send_shorten_response(void* cls, const char* name)
456 499
457 GNUNET_free(rmsg); 500 GNUNET_free(rmsg);
458 GNUNET_free_non_null(csh->name); 501 GNUNET_free_non_null(csh->name);
502 GNUNET_free_non_null(csh->zone_key);
459 GNUNET_free(csh); 503 GNUNET_free(csh);
460 504
461} 505}
@@ -477,6 +521,8 @@ static void handle_shorten(void *cls,
477 struct ClientShortenHandle *csh; 521 struct ClientShortenHandle *csh;
478 char name[MAX_DNS_NAME_LENGTH]; 522 char name[MAX_DNS_NAME_LENGTH];
479 char* nameptr = name; 523 char* nameptr = name;
524 struct GNUNET_CRYPTO_ShortHashCode zone;
525 struct GNUNET_CRYPTO_RsaPrivateKey *key;
480 526
481 if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientShortenMessage)) 527 if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientShortenMessage))
482 { 528 {
@@ -501,6 +547,7 @@ static void handle_shorten(void *cls,
501 csh = GNUNET_malloc(sizeof(struct ClientShortenHandle)); 547 csh = GNUNET_malloc(sizeof(struct ClientShortenHandle));
502 csh->client = client; 548 csh->client = client;
503 csh->unique_id = sh_msg->id; 549 csh->unique_id = sh_msg->id;
550 csh->zone_key = NULL;
504 551
505 GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr); 552 GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr);
506 553
@@ -531,12 +578,26 @@ static void handle_shorten(void *cls,
531 578
532 GNUNET_SERVER_notification_context_add (nc, client); 579 GNUNET_SERVER_notification_context_add (nc, client);
533 580
581 if (1 == ntohl(sh_msg->use_default_zone))
582 zone = zone_hash; //Default zone
583 else
584 zone = sh_msg->zone;
585
534 /* Start shortening */ 586 /* Start shortening */
535 if (GNUNET_YES == auto_import_pkey) 587 if (GNUNET_YES == auto_import_pkey)
536 gns_resolver_shorten_name(zone_hash, name, zone_key, 588 {
589 if (1 == ntohl(sh_msg->use_default_zone))
590 key = zone_key;
591 else
592 {
593 key = lookup_private_key(&sh_msg->zone);
594 csh->zone_key = key;
595 }
596 gns_resolver_shorten_name(zone, name, key,
537 &send_shorten_response, csh); 597 &send_shorten_response, csh);
598 }
538 else 599 else
539 gns_resolver_shorten_name(zone_hash, name, NULL, 600 gns_resolver_shorten_name(zone, name, NULL,
540 &send_shorten_response, csh); 601 &send_shorten_response, csh);
541} 602}
542 603
@@ -682,6 +743,7 @@ static void handle_get_authority(void *cls,
682} 743}
683 744
684 745
746
685/** 747/**
686 * Reply to client with the result from our lookup. 748 * Reply to client with the result from our lookup.
687 * 749 *
@@ -719,6 +781,10 @@ send_lookup_response(void* cls,
719 781
720 GNUNET_free(rmsg); 782 GNUNET_free(rmsg);
721 GNUNET_free(clh->name); 783 GNUNET_free(clh->name);
784
785 if (NULL != clh->zone_key)
786 GNUNET_free(clh->zone_key);
787
722 GNUNET_free(clh); 788 GNUNET_free(clh);
723 789
724} 790}
@@ -743,6 +809,8 @@ handle_lookup(void *cls,
743 char name[MAX_DNS_NAME_LENGTH]; 809 char name[MAX_DNS_NAME_LENGTH];
744 struct ClientLookupHandle *clh; 810 struct ClientLookupHandle *clh;
745 char* nameptr = name; 811 char* nameptr = name;
812 struct GNUNET_CRYPTO_RsaPrivateKey *key = NULL;
813 struct GNUNET_CRYPTO_ShortHashCode zone;
746 814
747 if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientLookupMessage)) 815 if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientLookupMessage))
748 { 816 {
@@ -773,6 +841,7 @@ handle_lookup(void *cls,
773 strcpy(clh->name, name); 841 strcpy(clh->name, name);
774 clh->unique_id = sh_msg->id; 842 clh->unique_id = sh_msg->id;
775 clh->type = ntohl(sh_msg->type); 843 clh->type = ntohl(sh_msg->type);
844 clh->zone_key = NULL;
776 845
777 if (strlen (name) > MAX_DNS_NAME_LENGTH) { 846 if (strlen (name) > MAX_DNS_NAME_LENGTH) {
778 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 847 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
@@ -781,17 +850,30 @@ handle_lookup(void *cls,
781 send_lookup_response(clh, 0, NULL); 850 send_lookup_response(clh, 0, NULL);
782 return; 851 return;
783 } 852 }
853
854 if (1 == ntohl(sh_msg->use_default_zone))
855 zone = zone_hash; //Default zone
856 else
857 zone = sh_msg->zone;
784 858
785 if (GNUNET_YES == auto_import_pkey) 859 if (GNUNET_YES == auto_import_pkey)
786 { 860 {
787 gns_resolver_lookup_record(zone_hash, clh->type, name, 861 if (1 == ntohl(sh_msg->use_default_zone))
788 zone_key, 862 key = zone_key;
863 else
864 {
865 key = lookup_private_key(&sh_msg->zone);
866 clh->zone_key = key;
867 }
868
869 gns_resolver_lookup_record(zone, clh->type, name,
870 key,
789 default_lookup_timeout, 871 default_lookup_timeout,
790 &send_lookup_response, clh); 872 &send_lookup_response, clh);
791 } 873 }
792 else 874 else
793 { 875 {
794 gns_resolver_lookup_record(zone_hash, clh->type, name, 876 gns_resolver_lookup_record(zone, clh->type, name,
795 NULL, 877 NULL,
796 default_lookup_timeout, 878 default_lookup_timeout,
797 &send_lookup_response, clh); 879 &send_lookup_response, clh);
@@ -826,6 +908,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
826 {&handle_get_authority, NULL, GNUNET_MESSAGE_TYPE_GNS_GET_AUTH, 0} 908 {&handle_get_authority, NULL, GNUNET_MESSAGE_TYPE_GNS_GET_AUTH, 0}
827 }; 909 };
828 910
911 GNS_cfg = c;
912
829 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, "gns", 913 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, "gns",
830 "ZONEKEY", &keyfile)) 914 "ZONEKEY", &keyfile))
831 { 915 {
diff --git a/src/include/gnunet_gns_service.h b/src/include/gnunet_gns_service.h
index 5528532cd..4e040f777 100644
--- a/src/include/gnunet_gns_service.h
+++ b/src/include/gnunet_gns_service.h
@@ -120,7 +120,8 @@ typedef void (*GNUNET_GNS_LookupResultProcessor) (void *cls,
120 120
121 121
122/** 122/**
123 * Perform an asynchronous lookup operation on the GNS. 123 * Perform an asynchronous lookup operation on the GNS
124 * in the default zone.
124 * 125 *
125 * @param handle handle to the GNS service 126 * @param handle handle to the GNS service
126 * @param name the name to look up 127 * @param name the name to look up
@@ -137,6 +138,26 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
137 GNUNET_GNS_LookupResultProcessor proc, 138 GNUNET_GNS_LookupResultProcessor proc,
138 void *proc_cls); 139 void *proc_cls);
139 140
141/**
142 * Perform an asynchronous lookup operation on the GNS
143 * in the zone specified by 'zone'.
144 *
145 * @param handle handle to the GNS service
146 * @param name the name to look up
147 * @param zone the zone to start the resolution in
148 * @param type the GNUNET_GNS_RecordType to look for
149 * @param proc function to call on result
150 * @param proc_cls closure for processor
151 *
152 * @return handle to the queued request
153 */
154struct GNUNET_GNS_QueueEntry *
155GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle,
156 const char * name,
157 struct GNUNET_CRYPTO_ShortHashCode *zone,
158 enum GNUNET_GNS_RecordType type,
159 GNUNET_GNS_LookupResultProcessor proc,
160 void *proc_cls);
140 161
141/* *************** Standard API: shorten ******************* */ 162/* *************** Standard API: shorten ******************* */
142 163
@@ -168,6 +189,23 @@ GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle,
168 void *proc_cls); 189 void *proc_cls);
169 190
170 191
192/**
193 * Perform a name shortening operation on the GNS.
194 *
195 * @param handle handle to the GNS service
196 * @param name the name to look up
197 * @param zone the zone to start the resolution in
198 * @param proc function to call on result
199 * @param proc_cls closure for processor
200 * @return handle to the operation
201 */
202struct GNUNET_GNS_QueueEntry *
203GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle,
204 const char * name,
205 struct GNUNET_CRYPTO_ShortHashCode *zone,
206 GNUNET_GNS_ShortenResultProcessor proc,
207 void *proc_cls);
208
171/* *************** Standard API: get authority ******************* */ 209/* *************** Standard API: get authority ******************* */
172 210
173 211