diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-08-13 17:32:35 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-08-13 17:32:35 +0000 |
commit | 41d573de1a9bd510a15ec971762c0d7dc77f2901 (patch) | |
tree | d0e0249f5a7675d374562fd3ad129c5dac027b04 /src/gns/gnunet-service-gns.c | |
parent | f76eea97484af4869b1c3aa96459bc7860634444 (diff) | |
download | gnunet-41d573de1a9bd510a15ec971762c0d7dc77f2901.tar.gz gnunet-41d573de1a9bd510a15ec971762c0d7dc77f2901.zip |
-simplifying GNS API
Diffstat (limited to 'src/gns/gnunet-service-gns.c')
-rw-r--r-- | src/gns/gnunet-service-gns.c | 563 |
1 files changed, 4 insertions, 559 deletions
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index e1fc507fb..822cc7d12 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c | |||
@@ -62,98 +62,6 @@ | |||
62 | 62 | ||
63 | 63 | ||
64 | /** | 64 | /** |
65 | * Handle to a shorten operation from api | ||
66 | */ | ||
67 | struct ClientShortenHandle | ||
68 | { | ||
69 | |||
70 | /** | ||
71 | * List for all shorten requests | ||
72 | */ | ||
73 | struct ClientShortenHandle *next; | ||
74 | |||
75 | /** | ||
76 | * List for all shorten requests | ||
77 | */ | ||
78 | struct ClientShortenHandle *prev; | ||
79 | |||
80 | /** | ||
81 | * Handle to the requesting client | ||
82 | */ | ||
83 | struct GNUNET_SERVER_Client *client; | ||
84 | |||
85 | /** | ||
86 | * Namestore lookup task | ||
87 | */ | ||
88 | struct GNUNET_NAMESTORE_QueueEntry *namestore_task; | ||
89 | |||
90 | /** | ||
91 | * master zone | ||
92 | */ | ||
93 | struct GNUNET_CRYPTO_ShortHashCode root_zone; | ||
94 | |||
95 | /** | ||
96 | * private zone | ||
97 | */ | ||
98 | struct GNUNET_CRYPTO_ShortHashCode private_zone; | ||
99 | |||
100 | /** | ||
101 | * shorten zone | ||
102 | */ | ||
103 | struct GNUNET_CRYPTO_ShortHashCode shorten_zone; | ||
104 | |||
105 | /** | ||
106 | * The request id | ||
107 | */ | ||
108 | uint32_t request_id; | ||
109 | |||
110 | /** | ||
111 | * request type | ||
112 | */ | ||
113 | int type; | ||
114 | |||
115 | /** | ||
116 | * name to shorten | ||
117 | */ | ||
118 | char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH]; | ||
119 | |||
120 | /** | ||
121 | * name of private zone (relative to root) | ||
122 | */ | ||
123 | char private_zone_id[GNUNET_DNSPARSER_MAX_NAME_LENGTH]; | ||
124 | |||
125 | /** | ||
126 | * name of shorten zone (relative to root) | ||
127 | */ | ||
128 | char shorten_zone_id[GNUNET_DNSPARSER_MAX_NAME_LENGTH]; | ||
129 | |||
130 | }; | ||
131 | |||
132 | |||
133 | /** | ||
134 | * Handle to a get authority operation from api | ||
135 | */ | ||
136 | struct ClientGetAuthHandle | ||
137 | { | ||
138 | /** | ||
139 | * Handle to the requesting client | ||
140 | */ | ||
141 | struct GNUNET_SERVER_Client *client; | ||
142 | |||
143 | /** | ||
144 | * name to lookup authority | ||
145 | */ | ||
146 | char *name; | ||
147 | |||
148 | /** | ||
149 | * request id | ||
150 | */ | ||
151 | uint32_t request_id; | ||
152 | |||
153 | }; | ||
154 | |||
155 | |||
156 | /** | ||
157 | * Handle to a lookup operation from api | 65 | * Handle to a lookup operation from api |
158 | */ | 66 | */ |
159 | struct ClientLookupHandle | 67 | struct ClientLookupHandle |
@@ -278,16 +186,6 @@ static int v6_enabled; | |||
278 | static int v4_enabled; | 186 | static int v4_enabled; |
279 | 187 | ||
280 | /** | 188 | /** |
281 | * List for shorten requests | ||
282 | */ | ||
283 | static struct ClientShortenHandle *csh_head; | ||
284 | |||
285 | /** | ||
286 | * List for shorten requests | ||
287 | */ | ||
288 | static struct ClientShortenHandle *csh_tail; | ||
289 | |||
290 | /** | ||
291 | * Handle to the statistics service | 189 | * Handle to the statistics service |
292 | */ | 190 | */ |
293 | static struct GNUNET_STATISTICS_Handle *statistics; | 191 | static struct GNUNET_STATISTICS_Handle *statistics; |
@@ -306,11 +204,6 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
306 | 204 | ||
307 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 205 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
308 | "Shutting down!\n"); | 206 | "Shutting down!\n"); |
309 | while (NULL != (csh_tmp = csh_head)) | ||
310 | { | ||
311 | GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh_tmp); | ||
312 | GNUNET_free (csh_tmp); | ||
313 | } | ||
314 | GNUNET_SERVER_notification_context_destroy (nc); | 207 | GNUNET_SERVER_notification_context_destroy (nc); |
315 | gns_interceptor_stop (); | 208 | gns_interceptor_stop (); |
316 | gns_resolver_cleanup (); | 209 | gns_resolver_cleanup (); |
@@ -581,433 +474,6 @@ publish_zone_dht_start (void *cls, | |||
581 | 474 | ||
582 | 475 | ||
583 | /** | 476 | /** |
584 | * Send shorten response back to client | ||
585 | * | ||
586 | * @param cls the closure containing a client shorten handle | ||
587 | * @param name the shortened name result or NULL if cannot be shortened | ||
588 | */ | ||
589 | static void | ||
590 | send_shorten_response (void* cls, const char* name) | ||
591 | { | ||
592 | struct ClientShortenHandle *csh = cls; | ||
593 | struct GNUNET_GNS_ClientShortenResultMessage *rmsg; | ||
594 | size_t name_len; | ||
595 | |||
596 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
597 | "Sending `%s' message with %s\n", | ||
598 | "SHORTEN_RESULT", name); | ||
599 | if (NULL == name) | ||
600 | name_len = 0; | ||
601 | else | ||
602 | name_len = strlen (name) + 1; | ||
603 | GNUNET_STATISTICS_update (statistics, | ||
604 | "Name shorten results", 1, GNUNET_NO); | ||
605 | |||
606 | rmsg = GNUNET_malloc (sizeof (struct GNUNET_GNS_ClientShortenResultMessage) + | ||
607 | name_len); | ||
608 | |||
609 | rmsg->id = csh->request_id; | ||
610 | rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT); | ||
611 | rmsg->header.size = | ||
612 | htons(sizeof(struct GNUNET_GNS_ClientShortenResultMessage) + | ||
613 | name_len); | ||
614 | memcpy (&rmsg[1], name, name_len); | ||
615 | GNUNET_SERVER_notification_context_unicast (nc, csh->client, | ||
616 | &rmsg->header, | ||
617 | GNUNET_NO); | ||
618 | if (NULL != csh->namestore_task) | ||
619 | GNUNET_NAMESTORE_cancel (csh->namestore_task); | ||
620 | GNUNET_free (rmsg); | ||
621 | GNUNET_free (csh); | ||
622 | } | ||
623 | |||
624 | |||
625 | /** | ||
626 | * Lookup the zone infos and shorten name | ||
627 | * | ||
628 | * @param cls the client shorten handle | ||
629 | * @param key key of the zone | ||
630 | * @param expiration expiration of record | ||
631 | * @param name name found or null if no result | ||
632 | * @param rd_count number of records found | ||
633 | * @param rd record data | ||
634 | * @param signature | ||
635 | * | ||
636 | */ | ||
637 | static void | ||
638 | process_shorten_in_private_zone_lookup (void *cls, | ||
639 | const struct GNUNET_CRYPTO_EccPublicKey *key, | ||
640 | struct GNUNET_TIME_Absolute expiration, | ||
641 | const char *name, | ||
642 | unsigned int rd_count, | ||
643 | const struct GNUNET_NAMESTORE_RecordData *rd, | ||
644 | const struct GNUNET_CRYPTO_EccSignature *signature) | ||
645 | { | ||
646 | struct ClientShortenHandle *csh = cls; | ||
647 | struct GNUNET_CRYPTO_ShortHashCode *szone = &csh->shorten_zone; | ||
648 | struct GNUNET_CRYPTO_ShortHashCode *pzone = &csh->private_zone; | ||
649 | |||
650 | csh->namestore_task = NULL; | ||
651 | if (0 == strcmp (csh->private_zone_id, "")) | ||
652 | pzone = NULL; | ||
653 | if (0 == rd_count) | ||
654 | { | ||
655 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
656 | "No shorten zone in private zone!\n"); | ||
657 | strcpy (csh->shorten_zone_id, ""); | ||
658 | szone = NULL; | ||
659 | } | ||
660 | else | ||
661 | { | ||
662 | GNUNET_break (1 == rd_count); | ||
663 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
664 | "Shorten zone %s found in private zone %s\n", | ||
665 | name, csh->private_zone_id); | ||
666 | |||
667 | sprintf (csh->shorten_zone_id, "%s.%s", name, csh->private_zone_id); | ||
668 | } | ||
669 | GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh); | ||
670 | gns_resolver_shorten_name (&csh->root_zone, | ||
671 | pzone, | ||
672 | szone, | ||
673 | csh->name, | ||
674 | csh->private_zone_id, | ||
675 | csh->shorten_zone_id, | ||
676 | &send_shorten_response, csh); | ||
677 | |||
678 | } | ||
679 | |||
680 | |||
681 | /** | ||
682 | * Lookup the zone infos and shorten name | ||
683 | * | ||
684 | * @param cls the shorten handle | ||
685 | * @param key key of the zone | ||
686 | * @param expiration expiration of record | ||
687 | * @param name name found or null if no result | ||
688 | * @param rd_count number of records found | ||
689 | * @param rd record data | ||
690 | * @param signature | ||
691 | * | ||
692 | */ | ||
693 | static void | ||
694 | process_shorten_in_root_zone_lookup (void *cls, | ||
695 | const struct GNUNET_CRYPTO_EccPublicKey *key, | ||
696 | struct GNUNET_TIME_Absolute expiration, | ||
697 | const char *name, | ||
698 | unsigned int rd_count, | ||
699 | const struct GNUNET_NAMESTORE_RecordData *rd, | ||
700 | const struct GNUNET_CRYPTO_EccSignature *signature) | ||
701 | { | ||
702 | struct ClientShortenHandle *csh = cls; | ||
703 | struct GNUNET_CRYPTO_ShortHashCode *szone = &csh->shorten_zone; | ||
704 | struct GNUNET_CRYPTO_ShortHashCode *pzone = &csh->private_zone; | ||
705 | |||
706 | csh->namestore_task = NULL; | ||
707 | if (0 == strcmp (csh->private_zone_id, "")) | ||
708 | pzone = NULL; | ||
709 | if (0 == rd_count) | ||
710 | { | ||
711 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
712 | "No shorten zone in zone and no private zone!\n"); | ||
713 | |||
714 | strcpy (csh->shorten_zone_id, ""); | ||
715 | GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh); | ||
716 | szone = NULL; | ||
717 | gns_resolver_shorten_name (&csh->root_zone, | ||
718 | pzone, | ||
719 | szone, | ||
720 | csh->name, | ||
721 | csh->private_zone_id, | ||
722 | csh->shorten_zone_id, | ||
723 | &send_shorten_response, csh); | ||
724 | return; | ||
725 | } | ||
726 | GNUNET_break (rd_count == 1); | ||
727 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
728 | "Private zone %s found in root zone\n", name); | ||
729 | strcpy (csh->private_zone_id, name); | ||
730 | csh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle, | ||
731 | pzone, | ||
732 | szone, | ||
733 | &process_shorten_in_private_zone_lookup, | ||
734 | csh); | ||
735 | } | ||
736 | |||
737 | |||
738 | /** | ||
739 | * Lookup the zone infos and shorten name | ||
740 | * | ||
741 | * @param cls the shorten handle | ||
742 | * @param key key of the zone | ||
743 | * @param expiration expiration of record | ||
744 | * @param name name found or null if no result | ||
745 | * @param rd_count number of records found | ||
746 | * @param rd record data | ||
747 | * @param signature | ||
748 | */ | ||
749 | static void | ||
750 | process_private_in_root_zone_lookup (void *cls, | ||
751 | const struct GNUNET_CRYPTO_EccPublicKey *key, | ||
752 | struct GNUNET_TIME_Absolute expiration, | ||
753 | const char *name, | ||
754 | unsigned int rd_count, | ||
755 | const struct GNUNET_NAMESTORE_RecordData *rd, | ||
756 | const struct GNUNET_CRYPTO_EccSignature *signature) | ||
757 | { | ||
758 | struct ClientShortenHandle *csh = cls; | ||
759 | |||
760 | csh->namestore_task = NULL; | ||
761 | if (0 == rd_count) | ||
762 | { | ||
763 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
764 | "No private zone in root zone\n"); | ||
765 | strcpy (csh->private_zone_id, ""); | ||
766 | csh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle, | ||
767 | &csh->root_zone, | ||
768 | &csh->shorten_zone, | ||
769 | &process_shorten_in_root_zone_lookup, | ||
770 | csh); | ||
771 | return; | ||
772 | } | ||
773 | GNUNET_break (1 == rd_count); | ||
774 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
775 | "Private zone `%s' found in root zone\n", | ||
776 | name); | ||
777 | strcpy (csh->private_zone_id, name); | ||
778 | csh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle, | ||
779 | &csh->private_zone, | ||
780 | &csh->shorten_zone, | ||
781 | &process_shorten_in_private_zone_lookup, | ||
782 | csh); | ||
783 | } | ||
784 | |||
785 | |||
786 | /** | ||
787 | * Handle a shorten message from the api | ||
788 | * | ||
789 | * @param cls the closure (unused) | ||
790 | * @param client the client | ||
791 | * @param message the message | ||
792 | */ | ||
793 | static void | ||
794 | handle_shorten (void *cls, | ||
795 | struct GNUNET_SERVER_Client * client, | ||
796 | const struct GNUNET_MessageHeader * message) | ||
797 | { | ||
798 | struct ClientShortenHandle *csh; | ||
799 | const char *utf_in; | ||
800 | char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH]; | ||
801 | char* nameptr = name; | ||
802 | uint16_t msg_size; | ||
803 | const struct GNUNET_GNS_ClientShortenMessage *sh_msg; | ||
804 | |||
805 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
806 | "Received `%s' message\n", "SHORTEN"); | ||
807 | msg_size = ntohs (message->size); | ||
808 | if (msg_size < sizeof (struct GNUNET_GNS_ClientShortenMessage)) | ||
809 | { | ||
810 | GNUNET_break (0); | ||
811 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
812 | return; | ||
813 | } | ||
814 | sh_msg = (const struct GNUNET_GNS_ClientShortenMessage *) message; | ||
815 | utf_in = (const char *) &sh_msg[1]; | ||
816 | if ('\0' != utf_in[msg_size - sizeof (struct GNUNET_GNS_ClientShortenMessage) - 1]) | ||
817 | { | ||
818 | GNUNET_break (0); | ||
819 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
820 | return; | ||
821 | } | ||
822 | csh = GNUNET_malloc(sizeof (struct ClientShortenHandle)); | ||
823 | csh->client = client; | ||
824 | csh->request_id = sh_msg->id; | ||
825 | GNUNET_CONTAINER_DLL_insert (csh_head, csh_tail, csh); | ||
826 | GNUNET_STRINGS_utf8_tolower (utf_in, &nameptr); | ||
827 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
828 | "SHORTEN: Converted `%s' to `%s'\n", | ||
829 | utf_in, | ||
830 | nameptr); | ||
831 | GNUNET_SERVER_notification_context_add (nc, client); | ||
832 | if (strlen (name) < strlen (GNUNET_GNS_TLD)) | ||
833 | { | ||
834 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
835 | "SHORTEN: %s is too short\n", name); | ||
836 | GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh); | ||
837 | send_shorten_response(csh, name); | ||
838 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
839 | return; | ||
840 | } | ||
841 | if (strlen (name) > GNUNET_DNSPARSER_MAX_NAME_LENGTH) | ||
842 | { | ||
843 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
844 | "SHORTEN: %s is too long\n", name); | ||
845 | GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh); | ||
846 | send_shorten_response(csh, name); | ||
847 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
848 | return; | ||
849 | } | ||
850 | if ( (! is_gads_tld (name)) && | ||
851 | (! is_zkey_tld (name)) ) | ||
852 | { | ||
853 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
854 | "%s is not our domain. Returning\n", name); | ||
855 | GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh); | ||
856 | send_shorten_response (csh, name); | ||
857 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
858 | return; | ||
859 | } | ||
860 | csh->shorten_zone = sh_msg->shorten_zone; | ||
861 | csh->private_zone = sh_msg->private_zone; | ||
862 | strcpy (csh->name, name); | ||
863 | if (1 == ntohl(sh_msg->use_default_zone)) | ||
864 | csh->root_zone = zone_hash; //Default zone | ||
865 | else | ||
866 | csh->root_zone = sh_msg->zone; | ||
867 | csh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle, | ||
868 | &csh->root_zone, | ||
869 | &csh->private_zone, | ||
870 | &process_private_in_root_zone_lookup, | ||
871 | csh); | ||
872 | GNUNET_STATISTICS_update (statistics, | ||
873 | "Name shorten attempts", 1, GNUNET_NO); | ||
874 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
875 | } | ||
876 | |||
877 | |||
878 | /** | ||
879 | * Send get authority response back to client | ||
880 | * | ||
881 | * @param cls the closure containing a client get auth handle | ||
882 | * @param name the name of the authority, or NULL on error | ||
883 | */ | ||
884 | static void | ||
885 | send_get_auth_response (void *cls, | ||
886 | const char* name) | ||
887 | { | ||
888 | struct ClientGetAuthHandle *cah = cls; | ||
889 | struct GNUNET_GNS_ClientGetAuthResultMessage *rmsg; | ||
890 | |||
891 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
892 | "Sending `%s' message with `%s'\n", | ||
893 | "GET_AUTH_RESULT", name); | ||
894 | if (NULL != name) | ||
895 | { | ||
896 | GNUNET_STATISTICS_update (statistics, | ||
897 | "Authorities resolved", 1, GNUNET_NO); | ||
898 | } | ||
899 | if (NULL == name) | ||
900 | name = ""; | ||
901 | rmsg = GNUNET_malloc (sizeof (struct GNUNET_GNS_ClientGetAuthResultMessage) | ||
902 | + strlen (name) + 1); | ||
903 | |||
904 | rmsg->id = cah->request_id; | ||
905 | rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_GET_AUTH_RESULT); | ||
906 | rmsg->header.size = | ||
907 | htons(sizeof(struct GNUNET_GNS_ClientGetAuthResultMessage) + | ||
908 | strlen (name) + 1); | ||
909 | strcpy ((char*)&rmsg[1], name); | ||
910 | |||
911 | GNUNET_SERVER_notification_context_unicast (nc, cah->client, | ||
912 | &rmsg->header, | ||
913 | GNUNET_NO); | ||
914 | GNUNET_SERVER_receive_done (cah->client, GNUNET_OK); | ||
915 | GNUNET_free(rmsg); | ||
916 | GNUNET_free_non_null(cah->name); | ||
917 | GNUNET_free(cah); | ||
918 | } | ||
919 | |||
920 | |||
921 | /** | ||
922 | * Handle a get authority message from the api | ||
923 | * | ||
924 | * @param cls the closure | ||
925 | * @param client the client | ||
926 | * @param message the message | ||
927 | */ | ||
928 | static void | ||
929 | handle_get_authority (void *cls, | ||
930 | struct GNUNET_SERVER_Client * client, | ||
931 | const struct GNUNET_MessageHeader * message) | ||
932 | { | ||
933 | struct ClientGetAuthHandle *cah; | ||
934 | const char *utf_in; | ||
935 | char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH]; | ||
936 | char* nameptr = name; | ||
937 | uint16_t msg_size; | ||
938 | const struct GNUNET_GNS_ClientGetAuthMessage *sh_msg; | ||
939 | |||
940 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
941 | "Received `%s' message\n", "GET_AUTH"); | ||
942 | msg_size = ntohs(message->size); | ||
943 | if (msg_size < sizeof (struct GNUNET_GNS_ClientGetAuthMessage)) | ||
944 | { | ||
945 | GNUNET_break (0); | ||
946 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
947 | return; | ||
948 | } | ||
949 | GNUNET_SERVER_notification_context_add (nc, client); | ||
950 | sh_msg = (const struct GNUNET_GNS_ClientGetAuthMessage *) message; | ||
951 | utf_in = (const char *) &sh_msg[1]; | ||
952 | if ('\0' != utf_in[msg_size - sizeof (struct GNUNET_GNS_ClientGetAuthMessage) - 1]) | ||
953 | { | ||
954 | GNUNET_break (0); | ||
955 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
956 | return; | ||
957 | } | ||
958 | GNUNET_STRINGS_utf8_tolower(utf_in, &nameptr); | ||
959 | cah = GNUNET_malloc(sizeof(struct ClientGetAuthHandle)); | ||
960 | cah->client = client; | ||
961 | cah->request_id = sh_msg->id; | ||
962 | if (strlen (name) < strlen(GNUNET_GNS_TLD)) | ||
963 | { | ||
964 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
965 | "GET_AUTH: `%s' is too short. Returning\n", name); | ||
966 | cah->name = NULL; | ||
967 | send_get_auth_response(cah, name); | ||
968 | return; | ||
969 | } | ||
970 | if (strlen (name) > GNUNET_DNSPARSER_MAX_NAME_LENGTH) | ||
971 | { | ||
972 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
973 | "GET_AUTH: `%s' is too long", name); | ||
974 | cah->name = NULL; | ||
975 | send_get_auth_response(cah, name); | ||
976 | return; | ||
977 | } | ||
978 | if (0 != strcmp (name + strlen (name) - strlen (GNUNET_GNS_TLD), | ||
979 | GNUNET_GNS_TLD)) | ||
980 | { | ||
981 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
982 | "GET_AUTH: %s is not our domain. Returning\n", name); | ||
983 | cah->name = NULL; | ||
984 | send_get_auth_response (cah, name); | ||
985 | return; | ||
986 | } | ||
987 | |||
988 | if (0 == strcmp (name, GNUNET_GNS_TLD)) | ||
989 | { | ||
990 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
991 | "GET_AUTH: %s is us. Returning\n", name); | ||
992 | cah->name = NULL; | ||
993 | send_get_auth_response(cah, name); | ||
994 | return; | ||
995 | } | ||
996 | |||
997 | cah->name = GNUNET_malloc (strlen (name) | ||
998 | - strlen (GNUNET_GNS_TLD) + 1); | ||
999 | memcpy (cah->name, name, | ||
1000 | strlen (name) - strlen (GNUNET_GNS_TLD)); | ||
1001 | |||
1002 | /* Start delegation resolution in our namestore */ | ||
1003 | gns_resolver_get_authority (zone_hash, zone_hash, name, | ||
1004 | &send_get_auth_response, cah); | ||
1005 | GNUNET_STATISTICS_update (statistics, | ||
1006 | "Authority lookup attempts", 1, GNUNET_NO); | ||
1007 | } | ||
1008 | |||
1009 | |||
1010 | /** | ||
1011 | * Reply to client with the result from our lookup. | 477 | * Reply to client with the result from our lookup. |
1012 | * | 478 | * |
1013 | * @param cls the closure (our client lookup handle) | 479 | * @param cls the closure (our client lookup handle) |
@@ -1187,11 +653,9 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
1187 | const struct GNUNET_CONFIGURATION_Handle *c) | 653 | const struct GNUNET_CONFIGURATION_Handle *c) |
1188 | { | 654 | { |
1189 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | 655 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { |
1190 | {&handle_shorten, NULL, GNUNET_MESSAGE_TYPE_GNS_SHORTEN, 0}, | 656 | { &handle_lookup, NULL, GNUNET_MESSAGE_TYPE_GNS_LOOKUP, 0}, |
1191 | {&handle_lookup, NULL, GNUNET_MESSAGE_TYPE_GNS_LOOKUP, 0}, | 657 | {NULL, NULL, 0, 0} |
1192 | {&handle_get_authority, NULL, GNUNET_MESSAGE_TYPE_GNS_GET_AUTH, 0} | ||
1193 | }; | 658 | }; |
1194 | char* keyfile; | ||
1195 | struct GNUNET_CRYPTO_EccPublicKey pkey; | 659 | struct GNUNET_CRYPTO_EccPublicKey pkey; |
1196 | unsigned long long max_parallel_bg_queries = 0; | 660 | unsigned long long max_parallel_bg_queries = 0; |
1197 | int ignore_pending = GNUNET_NO; | 661 | int ignore_pending = GNUNET_NO; |
@@ -1199,24 +663,6 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
1199 | v6_enabled = GNUNET_NETWORK_test_pf (PF_INET6); | 663 | v6_enabled = GNUNET_NETWORK_test_pf (PF_INET6); |
1200 | v4_enabled = GNUNET_NETWORK_test_pf (PF_INET); | 664 | v4_enabled = GNUNET_NETWORK_test_pf (PF_INET); |
1201 | 665 | ||
1202 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, "gns", | ||
1203 | "ZONEKEY", &keyfile)) | ||
1204 | { | ||
1205 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1206 | "No private key for root zone specified!\n"); | ||
1207 | GNUNET_SCHEDULER_shutdown (); | ||
1208 | return; | ||
1209 | } | ||
1210 | |||
1211 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1212 | "Using keyfile %s for root zone.\n", keyfile); | ||
1213 | |||
1214 | zone_key = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile); | ||
1215 | GNUNET_CRYPTO_ecc_key_get_public (zone_key, &pkey); | ||
1216 | GNUNET_CRYPTO_short_hash (&pkey, | ||
1217 | sizeof(struct GNUNET_CRYPTO_EccPublicKey), | ||
1218 | &zone_hash); | ||
1219 | GNUNET_free(keyfile); | ||
1220 | namestore_handle = GNUNET_NAMESTORE_connect (c); | 666 | namestore_handle = GNUNET_NAMESTORE_connect (c); |
1221 | if (NULL == namestore_handle) | 667 | if (NULL == namestore_handle) |
1222 | { | 668 | { |
@@ -1313,9 +759,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
1313 | } | 759 | } |
1314 | 760 | ||
1315 | /** | 761 | /** |
1316 | * Schedule periodic put | 762 | * Schedule periodic put for our records We have roughly an hour for |
1317 | * for our records | 763 | * all records; |
1318 | * We have roughly an hour for all records; | ||
1319 | */ | 764 | */ |
1320 | first_zone_iteration = GNUNET_YES; | 765 | first_zone_iteration = GNUNET_YES; |
1321 | zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start, NULL); | 766 | zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start, NULL); |