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 | |
parent | f76eea97484af4869b1c3aa96459bc7860634444 (diff) | |
download | gnunet-41d573de1a9bd510a15ec971762c0d7dc77f2901.tar.gz gnunet-41d573de1a9bd510a15ec971762c0d7dc77f2901.zip |
-simplifying GNS API
-rw-r--r-- | src/gns/gns.h | 118 | ||||
-rw-r--r-- | src/gns/gns_api.c | 489 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns.c | 563 |
3 files changed, 13 insertions, 1157 deletions
diff --git a/src/gns/gns.h b/src/gns/gns.h index a7697be1d..c8d27b673 100644 --- a/src/gns/gns.h +++ b/src/gns/gns.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | (C) 2012 Christian Grothoff (and other contributing authors) | 3 | (C) 2012-2013 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -28,9 +28,9 @@ | |||
28 | #include "gnunet_gns_service.h" | 28 | #include "gnunet_gns_service.h" |
29 | 29 | ||
30 | /** | 30 | /** |
31 | * Name of the GADS TLD. | 31 | * Name of the GNS TLD. |
32 | */ | 32 | */ |
33 | #define GNUNET_GNS_TLD "gads" | 33 | #define GNUNET_GNS_TLD "gnu" |
34 | 34 | ||
35 | /** | 35 | /** |
36 | * Name of the zone key TLD. | 36 | * Name of the zone key TLD. |
@@ -61,29 +61,24 @@ struct GNUNET_GNS_ClientLookupMessage | |||
61 | uint32_t id GNUNET_PACKED; | 61 | uint32_t id GNUNET_PACKED; |
62 | 62 | ||
63 | /** | 63 | /** |
64 | * If use_default_zone is empty this zone is used for lookup | 64 | * Zone that is to be used for lookup |
65 | */ | 65 | */ |
66 | struct GNUNET_CRYPTO_ShortHashCode zone; | 66 | struct GNUNET_CRYPTO_EccPublicKey zone; |
67 | 67 | ||
68 | /** | 68 | /** |
69 | * Only check cached results | 69 | * Only check cached results |
70 | */ | 70 | */ |
71 | uint32_t only_cached GNUNET_PACKED; | 71 | int16_t only_cached GNUNET_PACKED; |
72 | |||
73 | /** | ||
74 | * Should we look up in the given zone, instead of the default zone? | ||
75 | */ | ||
76 | uint32_t have_zone GNUNET_PACKED; | ||
77 | 72 | ||
78 | /** | 73 | /** |
79 | * Is a shorten key attached? | 74 | * Is a shorten key attached? |
80 | */ | 75 | */ |
81 | uint32_t have_key GNUNET_PACKED; | 76 | int16_t have_key GNUNET_PACKED; |
82 | 77 | ||
83 | /** | 78 | /** |
84 | * the type of record to look up | 79 | * the type of record to look up |
85 | */ | 80 | */ |
86 | /* int */ uint32_t type; | 81 | int32_t type; |
87 | 82 | ||
88 | /** | 83 | /** |
89 | * The key for shorten, if 'have_key' is set | 84 | * The key for shorten, if 'have_key' is set |
@@ -119,103 +114,6 @@ struct GNUNET_GNS_ClientLookupResultMessage | |||
119 | }; | 114 | }; |
120 | 115 | ||
121 | 116 | ||
122 | /** | ||
123 | * Message from client to GNS service to shorten names. | ||
124 | */ | ||
125 | struct GNUNET_GNS_ClientShortenMessage | ||
126 | { | ||
127 | /** | ||
128 | * Header of type GNUNET_MESSAGE_TYPE_GNS_CLIENT_SHORTEN | ||
129 | */ | ||
130 | struct GNUNET_MessageHeader header; | ||
131 | |||
132 | /** | ||
133 | * Unique identifier for this request | ||
134 | */ | ||
135 | uint32_t id GNUNET_PACKED; | ||
136 | |||
137 | /** | ||
138 | * If use_default_zone is empty this zone is used for lookup | ||
139 | */ | ||
140 | struct GNUNET_CRYPTO_ShortHashCode zone; | ||
141 | |||
142 | /** | ||
143 | * Shorten zone | ||
144 | */ | ||
145 | struct GNUNET_CRYPTO_ShortHashCode shorten_zone; | ||
146 | |||
147 | /** | ||
148 | * Private zone | ||
149 | */ | ||
150 | struct GNUNET_CRYPTO_ShortHashCode private_zone; | ||
151 | |||
152 | /** | ||
153 | * Should we look up in the default zone? | ||
154 | */ | ||
155 | uint32_t use_default_zone GNUNET_PACKED; | ||
156 | |||
157 | /* Followed by the name to shorten up */ | ||
158 | }; | ||
159 | |||
160 | |||
161 | /** | ||
162 | * Message from GNS service to client: shorten result. | ||
163 | */ | ||
164 | struct GNUNET_GNS_ClientShortenResultMessage | ||
165 | { | ||
166 | /** | ||
167 | * Header of type GNUNET_MESSAGE_TYPE_GNS_CLIENT_SHORTEN_RESULT | ||
168 | */ | ||
169 | struct GNUNET_MessageHeader header; | ||
170 | |||
171 | /** | ||
172 | * Unique identifier for this request (for key collisions). | ||
173 | */ | ||
174 | uint32_t id GNUNET_PACKED; | ||
175 | |||
176 | /* followed by the shortened name or '\0' for no result*/ | ||
177 | |||
178 | }; | ||
179 | |||
180 | |||
181 | /** | ||
182 | * Message from client to GNS service to lookup an authority of a name. | ||
183 | */ | ||
184 | struct GNUNET_GNS_ClientGetAuthMessage | ||
185 | { | ||
186 | /** | ||
187 | * Header of type GNUNET_MESSAGE_TYPE_GNS_CLIENT_GET_AUTH | ||
188 | */ | ||
189 | struct GNUNET_MessageHeader header; | ||
190 | |||
191 | /** | ||
192 | * Unique identifier for this request | ||
193 | */ | ||
194 | uint32_t id GNUNET_PACKED; | ||
195 | |||
196 | /* Followed by the name to get authority for */ | ||
197 | }; | ||
198 | |||
199 | |||
200 | /** | ||
201 | * Message from GNS service to client: authority result. | ||
202 | */ | ||
203 | struct GNUNET_GNS_ClientGetAuthResultMessage | ||
204 | { | ||
205 | /** | ||
206 | * Header of type GNUNET_MESSAGE_TYPE_GNS_CLIENT_GET_AUTH_RESULT | ||
207 | */ | ||
208 | struct GNUNET_MessageHeader header; | ||
209 | |||
210 | /** | ||
211 | * Unique identifier for this request (for key collisions). | ||
212 | */ | ||
213 | uint32_t id GNUNET_PACKED; | ||
214 | |||
215 | /* followed by the authority part of the name or '\0' for no result*/ | ||
216 | |||
217 | }; | ||
218 | |||
219 | GNUNET_NETWORK_STRUCT_END | 117 | GNUNET_NETWORK_STRUCT_END |
220 | 118 | ||
221 | #endif | 119 | #endif |
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c index 64f5144c6..9bc85efea 100644 --- a/src/gns/gns_api.c +++ b/src/gns/gns_api.c | |||
@@ -74,82 +74,6 @@ struct GNUNET_GNS_LookupRequest | |||
74 | 74 | ||
75 | 75 | ||
76 | /** | 76 | /** |
77 | * Handle to a shorten request | ||
78 | */ | ||
79 | struct GNUNET_GNS_ShortenRequest | ||
80 | { | ||
81 | /** | ||
82 | * DLL | ||
83 | */ | ||
84 | struct GNUNET_GNS_ShortenRequest *next; | ||
85 | |||
86 | /** | ||
87 | * DLL | ||
88 | */ | ||
89 | struct GNUNET_GNS_ShortenRequest *prev; | ||
90 | |||
91 | /** | ||
92 | * handle to gns | ||
93 | */ | ||
94 | struct GNUNET_GNS_Handle *gns_handle; | ||
95 | |||
96 | /** | ||
97 | * processor to call on shorten result | ||
98 | */ | ||
99 | GNUNET_GNS_ShortenResultProcessor shorten_proc; | ||
100 | |||
101 | /** | ||
102 | * processor closure | ||
103 | */ | ||
104 | void *proc_cls; | ||
105 | |||
106 | /** | ||
107 | * request id | ||
108 | */ | ||
109 | uint32_t r_id; | ||
110 | |||
111 | }; | ||
112 | |||
113 | |||
114 | /** | ||
115 | * Handle to GetAuthorityRequest | ||
116 | */ | ||
117 | struct GNUNET_GNS_GetAuthRequest | ||
118 | { | ||
119 | /** | ||
120 | * DLL | ||
121 | */ | ||
122 | struct GNUNET_GNS_GetAuthRequest *next; | ||
123 | |||
124 | /** | ||
125 | * DLL | ||
126 | */ | ||
127 | struct GNUNET_GNS_GetAuthRequest *prev; | ||
128 | |||
129 | /** | ||
130 | * handle to gns | ||
131 | */ | ||
132 | struct GNUNET_GNS_Handle *gns_handle; | ||
133 | |||
134 | /** | ||
135 | * processor to call on authority lookup result | ||
136 | */ | ||
137 | GNUNET_GNS_GetAuthResultProcessor auth_proc; | ||
138 | |||
139 | /** | ||
140 | * processor closure | ||
141 | */ | ||
142 | void *proc_cls; | ||
143 | |||
144 | /** | ||
145 | * request id | ||
146 | */ | ||
147 | uint32_t r_id; | ||
148 | |||
149 | }; | ||
150 | |||
151 | |||
152 | /** | ||
153 | * Entry in our list of messages to be (re-)transmitted. | 77 | * Entry in our list of messages to be (re-)transmitted. |
154 | */ | 78 | */ |
155 | struct PendingMessage | 79 | struct PendingMessage |
@@ -216,16 +140,6 @@ struct GNUNET_GNS_Handle | |||
216 | struct PendingMessage *pending_tail; | 140 | struct PendingMessage *pending_tail; |
217 | 141 | ||
218 | /** | 142 | /** |
219 | * Head of linked list of shorten messages we would like to transmit. | ||
220 | */ | ||
221 | struct GNUNET_GNS_ShortenRequest *shorten_head; | ||
222 | |||
223 | /** | ||
224 | * Tail of linked list of shorten messages we would like to transmit. | ||
225 | */ | ||
226 | struct GNUNET_GNS_ShortenRequest *shorten_tail; | ||
227 | |||
228 | /** | ||
229 | * Head of linked list of lookup messages we would like to transmit. | 143 | * Head of linked list of lookup messages we would like to transmit. |
230 | */ | 144 | */ |
231 | struct GNUNET_GNS_LookupRequest *lookup_head; | 145 | struct GNUNET_GNS_LookupRequest *lookup_head; |
@@ -234,16 +148,6 @@ struct GNUNET_GNS_Handle | |||
234 | * Tail of linked list of lookup messages we would like to transmit. | 148 | * Tail of linked list of lookup messages we would like to transmit. |
235 | */ | 149 | */ |
236 | struct GNUNET_GNS_LookupRequest *lookup_tail; | 150 | struct GNUNET_GNS_LookupRequest *lookup_tail; |
237 | |||
238 | /** | ||
239 | * Head of linked list of authority lookup messages we would like to transmit. | ||
240 | */ | ||
241 | struct GNUNET_GNS_GetAuthRequest *get_auth_head; | ||
242 | |||
243 | /** | ||
244 | * Tail of linked list of authority lookup messages we would like to transmit. | ||
245 | */ | ||
246 | struct GNUNET_GNS_GetAuthRequest *get_auth_tail; | ||
247 | 151 | ||
248 | /** | 152 | /** |
249 | * Reconnect task | 153 | * Reconnect task |
@@ -317,24 +221,12 @@ reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
317 | static void | 221 | static void |
318 | force_reconnect (struct GNUNET_GNS_Handle *handle) | 222 | force_reconnect (struct GNUNET_GNS_Handle *handle) |
319 | { | 223 | { |
320 | struct GNUNET_GNS_ShortenRequest *st; | ||
321 | struct GNUNET_GNS_LookupRequest *lh; | 224 | struct GNUNET_GNS_LookupRequest *lh; |
322 | struct GNUNET_GNS_GetAuthRequest *ga; | ||
323 | struct PendingMessage *p; | 225 | struct PendingMessage *p; |
324 | 226 | ||
325 | GNUNET_CLIENT_disconnect (handle->client); | 227 | GNUNET_CLIENT_disconnect (handle->client); |
326 | handle->client = NULL; | 228 | handle->client = NULL; |
327 | handle->in_receive = GNUNET_NO; | 229 | handle->in_receive = GNUNET_NO; |
328 | for (st = handle->shorten_head; NULL != st; st = st->next) | ||
329 | { | ||
330 | p = (struct PendingMessage *) &st[1]; | ||
331 | if (GNUNET_NO == p->transmitted) | ||
332 | continue; | ||
333 | p->transmitted = GNUNET_NO; | ||
334 | GNUNET_CONTAINER_DLL_insert (handle->pending_head, | ||
335 | handle->pending_tail, | ||
336 | p); | ||
337 | } | ||
338 | for (lh = handle->lookup_head; NULL != lh; lh = lh->next) | 230 | for (lh = handle->lookup_head; NULL != lh; lh = lh->next) |
339 | { | 231 | { |
340 | p = (struct PendingMessage *) &lh[1]; | 232 | p = (struct PendingMessage *) &lh[1]; |
@@ -345,16 +237,6 @@ force_reconnect (struct GNUNET_GNS_Handle *handle) | |||
345 | handle->pending_tail, | 237 | handle->pending_tail, |
346 | p); | 238 | p); |
347 | } | 239 | } |
348 | for (ga = handle->get_auth_head; NULL != ga; ga = ga->next) | ||
349 | { | ||
350 | p = (struct PendingMessage *) &ga[1]; | ||
351 | if (GNUNET_NO == p->transmitted) | ||
352 | continue; | ||
353 | p->transmitted = GNUNET_NO; | ||
354 | GNUNET_CONTAINER_DLL_insert (handle->pending_head, | ||
355 | handle->pending_tail, | ||
356 | p); | ||
357 | } | ||
358 | handle->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff); | 240 | handle->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff); |
359 | handle->reconnect_task = GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff, | 241 | handle->reconnect_task = GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff, |
360 | &reconnect_task, | 242 | &reconnect_task, |
@@ -470,101 +352,6 @@ transmit_pending (void *cls, size_t size, void *buf) | |||
470 | 352 | ||
471 | 353 | ||
472 | /** | 354 | /** |
473 | * Process a given reply that might match the given | ||
474 | * request. | ||
475 | * | ||
476 | * @param qe a queue entry | ||
477 | * @param msg the shorten msg received | ||
478 | */ | ||
479 | static void | ||
480 | process_shorten_reply (struct GNUNET_GNS_ShortenRequest *qe, | ||
481 | const struct GNUNET_GNS_ClientShortenResultMessage *msg) | ||
482 | { | ||
483 | struct GNUNET_GNS_Handle *handle = qe->gns_handle; | ||
484 | struct PendingMessage *p = (struct PendingMessage *)&qe[1]; | ||
485 | const char *short_name; | ||
486 | size_t mlen; | ||
487 | |||
488 | if (GNUNET_YES != p->transmitted) | ||
489 | { | ||
490 | /* service send reply to query we never managed to send!? */ | ||
491 | GNUNET_break (0); | ||
492 | force_reconnect (handle); | ||
493 | return; | ||
494 | } | ||
495 | mlen = ntohs (msg->header.size); | ||
496 | if (ntohs (msg->header.size) == sizeof (struct GNUNET_GNS_ClientShortenResultMessage)) | ||
497 | { | ||
498 | /* service reports resolution failed */ | ||
499 | short_name = NULL; | ||
500 | } | ||
501 | else | ||
502 | { | ||
503 | short_name = (const char *) &msg[1]; | ||
504 | if ('\0' != short_name[mlen - sizeof (struct GNUNET_GNS_ClientShortenResultMessage) - 1]) | ||
505 | { | ||
506 | GNUNET_break (0); | ||
507 | force_reconnect (handle); | ||
508 | return; | ||
509 | } | ||
510 | } | ||
511 | GNUNET_CONTAINER_DLL_remove (handle->shorten_head, handle->shorten_tail, qe); | ||
512 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
513 | "Received shortened reply `%s' from GNS service\n", | ||
514 | short_name); | ||
515 | qe->shorten_proc (qe->proc_cls, short_name); | ||
516 | GNUNET_free (qe); | ||
517 | } | ||
518 | |||
519 | |||
520 | /** | ||
521 | * Process a given reply that might match the given | ||
522 | * request. | ||
523 | * | ||
524 | * @param qe the handle to the request | ||
525 | * @param msg the message to process | ||
526 | */ | ||
527 | static void | ||
528 | process_get_auth_reply (struct GNUNET_GNS_GetAuthRequest *qe, | ||
529 | const struct GNUNET_GNS_ClientGetAuthResultMessage *msg) | ||
530 | { | ||
531 | struct GNUNET_GNS_Handle *handle = qe->gns_handle; | ||
532 | struct PendingMessage *p = (struct PendingMessage *)&qe[1]; | ||
533 | const char *auth_name; | ||
534 | size_t mlen; | ||
535 | |||
536 | if (GNUNET_YES != p->transmitted) | ||
537 | { | ||
538 | /* service send reply to query we never managed to send!? */ | ||
539 | GNUNET_break (0); | ||
540 | force_reconnect (handle); | ||
541 | return; | ||
542 | } | ||
543 | mlen = ntohs (msg->header.size); | ||
544 | if (mlen == sizeof (struct GNUNET_GNS_ClientGetAuthResultMessage)) | ||
545 | { | ||
546 | auth_name = NULL; | ||
547 | } | ||
548 | else | ||
549 | { | ||
550 | auth_name = (const char*) &msg[1]; | ||
551 | if ('\0' != auth_name[mlen - sizeof (struct GNUNET_GNS_ClientGetAuthResultMessage) - 1]) | ||
552 | { | ||
553 | GNUNET_break (0); | ||
554 | force_reconnect (handle); | ||
555 | return; | ||
556 | } | ||
557 | } | ||
558 | GNUNET_CONTAINER_DLL_remove (handle->get_auth_head, handle->get_auth_tail, qe); | ||
559 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
560 | "Received GET_AUTH reply `%s' from GNS service\n", | ||
561 | auth_name); | ||
562 | qe->auth_proc (qe->proc_cls, auth_name); | ||
563 | GNUNET_free (qe); | ||
564 | } | ||
565 | |||
566 | |||
567 | /** | ||
568 | * Process a given reply to the lookup request | 355 | * Process a given reply to the lookup request |
569 | * | 356 | * |
570 | * @param qe a queue entry | 357 | * @param qe a queue entry |
@@ -621,11 +408,7 @@ process_message (void *cls, const struct GNUNET_MessageHeader *msg) | |||
621 | { | 408 | { |
622 | struct GNUNET_GNS_Handle *handle = cls; | 409 | struct GNUNET_GNS_Handle *handle = cls; |
623 | struct GNUNET_GNS_LookupRequest *lr; | 410 | struct GNUNET_GNS_LookupRequest *lr; |
624 | struct GNUNET_GNS_ShortenRequest *sr; | ||
625 | struct GNUNET_GNS_GetAuthRequest *gar; | ||
626 | const struct GNUNET_GNS_ClientLookupResultMessage *lookup_msg; | 411 | const struct GNUNET_GNS_ClientLookupResultMessage *lookup_msg; |
627 | const struct GNUNET_GNS_ClientShortenResultMessage *shorten_msg; | ||
628 | const struct GNUNET_GNS_ClientGetAuthResultMessage *get_auth_msg; | ||
629 | uint32_t r_id; | 412 | uint32_t r_id; |
630 | 413 | ||
631 | if (NULL == msg) | 414 | if (NULL == msg) |
@@ -653,42 +436,6 @@ process_message (void *cls, const struct GNUNET_MessageHeader *msg) | |||
653 | break; | 436 | break; |
654 | } | 437 | } |
655 | break; | 438 | break; |
656 | case GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT: | ||
657 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
658 | "Got SHORTEN_RESULT msg\n"); | ||
659 | if (ntohs (msg->size) < sizeof (struct GNUNET_GNS_ClientShortenResultMessage)) | ||
660 | { | ||
661 | GNUNET_break (0); | ||
662 | force_reconnect (handle); | ||
663 | return; | ||
664 | } | ||
665 | shorten_msg = (const struct GNUNET_GNS_ClientShortenResultMessage *) msg; | ||
666 | r_id = ntohl (shorten_msg->id); | ||
667 | for (sr = handle->shorten_head; NULL != sr; sr = sr->next) | ||
668 | if (sr->r_id == r_id) | ||
669 | { | ||
670 | process_shorten_reply (sr, shorten_msg); | ||
671 | break; | ||
672 | } | ||
673 | break; | ||
674 | case GNUNET_MESSAGE_TYPE_GNS_GET_AUTH_RESULT: | ||
675 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
676 | "Got GET_AUTH_RESULT msg\n"); | ||
677 | if (ntohs (msg->size) < sizeof (struct GNUNET_GNS_ClientGetAuthResultMessage)) | ||
678 | { | ||
679 | GNUNET_break (0); | ||
680 | force_reconnect (handle); | ||
681 | return; | ||
682 | } | ||
683 | get_auth_msg = (const struct GNUNET_GNS_ClientGetAuthResultMessage *) msg; | ||
684 | r_id = ntohl (get_auth_msg->id); | ||
685 | for (gar = handle->get_auth_head; NULL != gar; gar = gar->next) | ||
686 | if (gar->r_id == r_id) | ||
687 | { | ||
688 | process_get_auth_reply (gar, get_auth_msg); | ||
689 | break; | ||
690 | } | ||
691 | break; | ||
692 | default: | 439 | default: |
693 | GNUNET_break (0); | 440 | GNUNET_break (0); |
694 | force_reconnect (handle); | 441 | force_reconnect (handle); |
@@ -710,7 +457,7 @@ GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
710 | { | 457 | { |
711 | struct GNUNET_GNS_Handle *handle; | 458 | struct GNUNET_GNS_Handle *handle; |
712 | 459 | ||
713 | handle = GNUNET_malloc (sizeof (struct GNUNET_GNS_Handle)); | 460 | handle = GNUNET_new (struct GNUNET_GNS_Handle); |
714 | handle->cfg = cfg; | 461 | handle->cfg = cfg; |
715 | reconnect (handle); | 462 | reconnect (handle); |
716 | return handle; | 463 | return handle; |
@@ -732,8 +479,6 @@ GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle) | |||
732 | handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK; | 479 | handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK; |
733 | } | 480 | } |
734 | GNUNET_assert (NULL == handle->lookup_head); | 481 | GNUNET_assert (NULL == handle->lookup_head); |
735 | GNUNET_assert (NULL == handle->shorten_head); | ||
736 | GNUNET_assert (NULL == handle->get_auth_head); | ||
737 | GNUNET_free (handle); | 482 | GNUNET_free (handle); |
738 | } | 483 | } |
739 | 484 | ||
@@ -761,50 +506,6 @@ GNUNET_GNS_cancel_lookup_request (struct GNUNET_GNS_LookupRequest *lr) | |||
761 | 506 | ||
762 | 507 | ||
763 | /** | 508 | /** |
764 | * Cancel pending shorten request | ||
765 | * | ||
766 | * @param sr the lookup request to cancel | ||
767 | */ | ||
768 | void | ||
769 | GNUNET_GNS_cancel_shorten_request (struct GNUNET_GNS_ShortenRequest *sr) | ||
770 | { | ||
771 | struct PendingMessage *p = (struct PendingMessage*) &sr[1]; | ||
772 | |||
773 | GNUNET_assert (NULL != sr->gns_handle); | ||
774 | if (GNUNET_NO == p->transmitted) | ||
775 | GNUNET_CONTAINER_DLL_remove (sr->gns_handle->pending_head, | ||
776 | sr->gns_handle->pending_tail, | ||
777 | p); | ||
778 | GNUNET_CONTAINER_DLL_remove (sr->gns_handle->shorten_head, | ||
779 | sr->gns_handle->shorten_tail, | ||
780 | sr); | ||
781 | GNUNET_free (sr); | ||
782 | } | ||
783 | |||
784 | |||
785 | /** | ||
786 | * Cancel pending get auth request | ||
787 | * | ||
788 | * @param gar the lookup request to cancel | ||
789 | */ | ||
790 | void | ||
791 | GNUNET_GNS_cancel_get_auth_request (struct GNUNET_GNS_GetAuthRequest *gar) | ||
792 | { | ||
793 | struct PendingMessage *p = (struct PendingMessage*) &gar[1]; | ||
794 | |||
795 | GNUNET_assert (NULL != gar->gns_handle); | ||
796 | if (GNUNET_NO == p->transmitted) | ||
797 | GNUNET_CONTAINER_DLL_remove (gar->gns_handle->pending_head, | ||
798 | gar->gns_handle->pending_tail, | ||
799 | p); | ||
800 | GNUNET_CONTAINER_DLL_remove (gar->gns_handle->get_auth_head, | ||
801 | gar->gns_handle->get_auth_tail, | ||
802 | gar); | ||
803 | GNUNET_free (gar); | ||
804 | } | ||
805 | |||
806 | |||
807 | /** | ||
808 | * Perform an asynchronous Lookup operation on the GNS. | 509 | * Perform an asynchronous Lookup operation on the GNS. |
809 | * | 510 | * |
810 | * @param handle handle to the GNS service | 511 | * @param handle handle to the GNS service |
@@ -885,192 +586,4 @@ GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle, | |||
885 | } | 586 | } |
886 | 587 | ||
887 | 588 | ||
888 | /** | ||
889 | * Perform an asynchronous Lookup operation on the GNS. | ||
890 | * | ||
891 | * @param handle handle to the GNS service | ||
892 | * @param name the name to look up | ||
893 | * @param type the record type to look up | ||
894 | * @param only_cached GNUNET_YES to only check locally not DHT for performance | ||
895 | * @param shorten_key the private key of the shorten zone (can be NULL) | ||
896 | * @param proc processor to call on result | ||
897 | * @param proc_cls closure for processor | ||
898 | * @return handle to the lookup request | ||
899 | */ | ||
900 | struct GNUNET_GNS_LookupRequest * | ||
901 | GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, | ||
902 | const char *name, | ||
903 | int type, | ||
904 | int only_cached, | ||
905 | struct GNUNET_CRYPTO_EccPrivateKey *shorten_key, | ||
906 | GNUNET_GNS_LookupResultProcessor proc, | ||
907 | void *proc_cls) | ||
908 | { | ||
909 | return GNUNET_GNS_lookup_zone (handle, name, | ||
910 | NULL, | ||
911 | type, only_cached, | ||
912 | shorten_key, | ||
913 | proc, proc_cls); | ||
914 | } | ||
915 | |||
916 | |||
917 | /** | ||
918 | * Perform a name shortening operation on the GNS. | ||
919 | * | ||
920 | * @param handle handle to the GNS service | ||
921 | * @param name the name to look up | ||
922 | * @param private_zone the public zone of the private zone | ||
923 | * @param shorten_zone the public zone of the shorten zone | ||
924 | * @param zone the zone to start the resolution in | ||
925 | * @param proc function to call on result | ||
926 | * @param proc_cls closure for processor | ||
927 | * @return handle to the operation | ||
928 | */ | ||
929 | struct GNUNET_GNS_ShortenRequest* | ||
930 | GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle, | ||
931 | const char *name, | ||
932 | struct GNUNET_CRYPTO_ShortHashCode *private_zone, | ||
933 | struct GNUNET_CRYPTO_ShortHashCode *shorten_zone, | ||
934 | struct GNUNET_CRYPTO_ShortHashCode *zone, | ||
935 | GNUNET_GNS_ShortenResultProcessor proc, | ||
936 | void *proc_cls) | ||
937 | { | ||
938 | /* IPC to shorten gns names, return shorten_handle */ | ||
939 | struct GNUNET_GNS_ClientShortenMessage *shorten_msg; | ||
940 | struct GNUNET_GNS_ShortenRequest *sr; | ||
941 | size_t msize; | ||
942 | struct PendingMessage *pending; | ||
943 | |||
944 | if (NULL == name) | ||
945 | { | ||
946 | GNUNET_break (0); | ||
947 | return NULL; | ||
948 | } | ||
949 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to shorten `%s' in GNS\n", name); | ||
950 | msize = sizeof (struct GNUNET_GNS_ClientShortenMessage) + strlen (name) + 1; | ||
951 | if (msize > UINT16_MAX) | ||
952 | { | ||
953 | GNUNET_break (0); | ||
954 | return NULL; | ||
955 | } | ||
956 | sr = GNUNET_malloc (sizeof (struct GNUNET_GNS_ShortenRequest) + | ||
957 | sizeof (struct PendingMessage) + msize); | ||
958 | sr->gns_handle = handle; | ||
959 | sr->shorten_proc = proc; | ||
960 | sr->proc_cls = proc_cls; | ||
961 | sr->r_id = handle->r_id_gen++; | ||
962 | GNUNET_CONTAINER_DLL_insert_tail (handle->shorten_head, | ||
963 | handle->shorten_tail, sr); | ||
964 | pending = (struct PendingMessage *)&sr[1]; | ||
965 | pending->size = msize; | ||
966 | pending->r_id = sr->r_id; | ||
967 | |||
968 | shorten_msg = (struct GNUNET_GNS_ClientShortenMessage *) &pending[1]; | ||
969 | shorten_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_SHORTEN); | ||
970 | shorten_msg->header.size = htons ((uint16_t) msize); | ||
971 | shorten_msg->id = htonl (sr->r_id); | ||
972 | shorten_msg->private_zone = *private_zone; | ||
973 | shorten_msg->shorten_zone = *shorten_zone; | ||
974 | if (NULL != zone) | ||
975 | { | ||
976 | shorten_msg->use_default_zone = htonl (GNUNET_NO); | ||
977 | memcpy (&shorten_msg->zone, zone, | ||
978 | sizeof (struct GNUNET_CRYPTO_ShortHashCode)); | ||
979 | } | ||
980 | else | ||
981 | { | ||
982 | shorten_msg->use_default_zone = htonl (GNUNET_YES); | ||
983 | memset (&shorten_msg->zone, 0, sizeof (struct GNUNET_CRYPTO_ShortHashCode)); | ||
984 | } | ||
985 | memcpy (&shorten_msg[1], name, strlen (name) + 1); | ||
986 | GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head, handle->pending_tail, | ||
987 | pending); | ||
988 | process_pending_messages (handle); | ||
989 | return sr; | ||
990 | } | ||
991 | |||
992 | |||
993 | /** | ||
994 | * Perform a name shortening operation on the GNS. | ||
995 | * | ||
996 | * @param handle handle to the GNS service | ||
997 | * @param name the name to look up | ||
998 | * @param private_zone the public zone of the private zone | ||
999 | * @param shorten_zone the public zone of the shorten zone | ||
1000 | * @param proc function to call on result | ||
1001 | * @param proc_cls closure for processor | ||
1002 | * @return handle to the operation | ||
1003 | */ | ||
1004 | struct GNUNET_GNS_ShortenRequest* | ||
1005 | GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle, | ||
1006 | const char *name, | ||
1007 | struct GNUNET_CRYPTO_ShortHashCode *private_zone, | ||
1008 | struct GNUNET_CRYPTO_ShortHashCode *shorten_zone, | ||
1009 | GNUNET_GNS_ShortenResultProcessor proc, | ||
1010 | void *proc_cls) | ||
1011 | { | ||
1012 | return GNUNET_GNS_shorten_zone (handle, name, | ||
1013 | private_zone, shorten_zone, | ||
1014 | NULL, proc, proc_cls); | ||
1015 | } | ||
1016 | |||
1017 | |||
1018 | /** | ||
1019 | * Perform an authority lookup for a given name. | ||
1020 | * | ||
1021 | * @param handle handle to the GNS service | ||
1022 | * @param name the name to look up authority for | ||
1023 | * @param proc function to call on result | ||
1024 | * @param proc_cls closure for processor | ||
1025 | * @return handle to the operation | ||
1026 | */ | ||
1027 | struct GNUNET_GNS_GetAuthRequest* | ||
1028 | GNUNET_GNS_get_authority (struct GNUNET_GNS_Handle *handle, | ||
1029 | const char *name, | ||
1030 | GNUNET_GNS_GetAuthResultProcessor proc, | ||
1031 | void *proc_cls) | ||
1032 | { | ||
1033 | struct GNUNET_GNS_ClientGetAuthMessage *get_auth_msg; | ||
1034 | struct GNUNET_GNS_GetAuthRequest *gar; | ||
1035 | size_t msize; | ||
1036 | struct PendingMessage *pending; | ||
1037 | |||
1038 | if (NULL == name) | ||
1039 | { | ||
1040 | GNUNET_break (0); | ||
1041 | return NULL; | ||
1042 | } | ||
1043 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1044 | "Trying to look up authority for %s in GNS\n", name); | ||
1045 | msize = sizeof (struct GNUNET_GNS_ClientGetAuthMessage) + strlen (name) + 1; | ||
1046 | if (msize > UINT16_MAX) | ||
1047 | { | ||
1048 | GNUNET_break (0); | ||
1049 | return NULL; | ||
1050 | } | ||
1051 | gar = GNUNET_malloc (sizeof (struct GNUNET_GNS_GetAuthRequest) + | ||
1052 | sizeof (struct PendingMessage) + msize); | ||
1053 | gar->gns_handle = handle; | ||
1054 | gar->auth_proc = proc; | ||
1055 | gar->proc_cls = proc_cls; | ||
1056 | gar->r_id = handle->r_id_gen++; | ||
1057 | GNUNET_CONTAINER_DLL_insert_tail (handle->get_auth_head, | ||
1058 | handle->get_auth_tail, gar); | ||
1059 | |||
1060 | pending = (struct PendingMessage *) &gar[1]; | ||
1061 | pending->size = msize; | ||
1062 | pending->r_id = gar->r_id; | ||
1063 | get_auth_msg = (struct GNUNET_GNS_ClientGetAuthMessage *) &pending[1]; | ||
1064 | get_auth_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_GET_AUTH); | ||
1065 | get_auth_msg->header.size = htons (msize); | ||
1066 | get_auth_msg->id = htonl (gar->r_id); | ||
1067 | memcpy (&get_auth_msg[1], name, strlen (name) + 1); | ||
1068 | GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head, | ||
1069 | handle->pending_tail, | ||
1070 | pending); | ||
1071 | process_pending_messages (handle); | ||
1072 | return gar; | ||
1073 | } | ||
1074 | |||
1075 | |||
1076 | /* end of gns_api.c */ | 589 | /* end of gns_api.c */ |
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); |