diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-08-13 21:07:54 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-08-13 21:07:54 +0000 |
commit | 9b87e5d8f6b762cc8fd4625b7dd369e36722978c (patch) | |
tree | 43f5d336224f1513733acea0253e3098520e771d | |
parent | 4c0d35b75913b66abfd69a4f1d76cd0000d1a9ec (diff) | |
download | gnunet-9b87e5d8f6b762cc8fd4625b7dd369e36722978c.tar.gz gnunet-9b87e5d8f6b762cc8fd4625b7dd369e36722978c.zip |
-more work on new GNS implementation
-rw-r--r-- | src/gns/Makefile.am | 1 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns.c | 25 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns_resolver.c | 1393 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns_resolver.h | 9 | ||||
-rw-r--r-- | src/include/gnunet_namestore_service.h | 15 | ||||
-rw-r--r-- | src/namestore/gnunet-service-namestore.c | 2 |
6 files changed, 495 insertions, 950 deletions
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am index 6fde83578..16bd6ca1c 100644 --- a/src/gns/Makefile.am +++ b/src/gns/Makefile.am | |||
@@ -137,6 +137,7 @@ gnunet_service_gns_LDADD = \ | |||
137 | libgnunetgns_common.la \ | 137 | libgnunetgns_common.la \ |
138 | $(top_builddir)/src/dns/libgnunetdns.la \ | 138 | $(top_builddir)/src/dns/libgnunetdns.la \ |
139 | $(top_builddir)/src/dns/libgnunetdnsparser.la \ | 139 | $(top_builddir)/src/dns/libgnunetdnsparser.la \ |
140 | $(top_builddir)/src/dns/libgnunetdnsstub.la \ | ||
140 | $(top_builddir)/src/dht/libgnunetdht.la \ | 141 | $(top_builddir)/src/dht/libgnunetdht.la \ |
141 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ | 142 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ |
142 | $(USE_VPN) \ | 143 | $(USE_VPN) \ |
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 9f05269f1..7a6f8e277 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c | |||
@@ -598,7 +598,6 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
598 | }; | 598 | }; |
599 | struct GNUNET_CRYPTO_EccPublicKey dns_root; | 599 | struct GNUNET_CRYPTO_EccPublicKey dns_root; |
600 | unsigned long long max_parallel_bg_queries = 0; | 600 | unsigned long long max_parallel_bg_queries = 0; |
601 | int ignore_pending = GNUNET_NO; | ||
602 | char *dns_root_name; | 601 | char *dns_root_name; |
603 | 602 | ||
604 | v6_enabled = GNUNET_NETWORK_test_pf (PF_INET6); | 603 | v6_enabled = GNUNET_NETWORK_test_pf (PF_INET6); |
@@ -635,15 +634,6 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
635 | max_parallel_bg_queries); | 634 | max_parallel_bg_queries); |
636 | } | 635 | } |
637 | 636 | ||
638 | if (GNUNET_YES == | ||
639 | GNUNET_CONFIGURATION_get_value_yesno (c, "gns", | ||
640 | "AUTO_IMPORT_CONFIRMATION_REQ")) | ||
641 | { | ||
642 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
643 | "Auto import requires user confirmation\n"); | ||
644 | ignore_pending = GNUNET_YES; | ||
645 | } | ||
646 | |||
647 | if (GNUNET_OK == | 637 | if (GNUNET_OK == |
648 | GNUNET_CONFIGURATION_get_value_time (c, "gns", | 638 | GNUNET_CONFIGURATION_get_value_time (c, "gns", |
649 | "DEFAULT_LOOKUP_TIMEOUT", | 639 | "DEFAULT_LOOKUP_TIMEOUT", |
@@ -665,18 +655,6 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
665 | return; | 655 | return; |
666 | } | 656 | } |
667 | 657 | ||
668 | if (GNUNET_SYSERR == | ||
669 | GNS_resolver_init (namestore_handle, dht_handle, | ||
670 | c, | ||
671 | max_parallel_bg_queries, | ||
672 | ignore_pending)) | ||
673 | { | ||
674 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
675 | _("Unable to initialize resolver!\n")); | ||
676 | GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | ||
677 | return; | ||
678 | } | ||
679 | |||
680 | if (GNUNET_OK == | 658 | if (GNUNET_OK == |
681 | GNUNET_CONFIGURATION_get_value_string (c, "gns", "DNS_ROOT", | 659 | GNUNET_CONFIGURATION_get_value_string (c, "gns", "DNS_ROOT", |
682 | &dns_root_name)) | 660 | &dns_root_name)) |
@@ -706,6 +684,9 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
706 | } | 684 | } |
707 | /* FIXME: install client disconnect handle to clean up pending | 685 | /* FIXME: install client disconnect handle to clean up pending |
708 | lookups on client disconnect! */ | 686 | lookups on client disconnect! */ |
687 | GNS_resolver_init (namestore_handle, dht_handle, | ||
688 | c, | ||
689 | max_parallel_bg_queries); | ||
709 | 690 | ||
710 | /* Schedule periodic put for our records. */ | 691 | /* Schedule periodic put for our records. */ |
711 | first_zone_iteration = GNUNET_YES; | 692 | first_zone_iteration = GNUNET_YES; |
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index fb334c1a0..bcffbcb14 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2009, 2010, 2011, 2012, 2013 Christian Grothoff (and other contributing authors) | 3 | (C) 2011-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 |
@@ -27,7 +27,7 @@ | |||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
29 | #include "gnunet_transport_service.h" | 29 | #include "gnunet_transport_service.h" |
30 | #include "gnunet_dns_service.h" | 30 | #include "gnunet_dnsstub_lib.h" |
31 | #include "gnunet_dht_service.h" | 31 | #include "gnunet_dht_service.h" |
32 | #include "gnunet_namestore_service.h" | 32 | #include "gnunet_namestore_service.h" |
33 | #include "gnunet_dns_service.h" | 33 | #include "gnunet_dns_service.h" |
@@ -38,9 +38,7 @@ | |||
38 | #include "gns_common.h" | 38 | #include "gns_common.h" |
39 | #include "gns.h" | 39 | #include "gns.h" |
40 | #include "gnunet-service-gns_resolver.h" | 40 | #include "gnunet-service-gns_resolver.h" |
41 | #ifndef WINDOWS | ||
42 | #include "gnunet_vpn_service.h" | 41 | #include "gnunet_vpn_service.h" |
43 | #endif | ||
44 | 42 | ||
45 | 43 | ||
46 | #define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) | 44 | #define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) |
@@ -68,63 +66,65 @@ | |||
68 | #define DHT_GNS_REPLICATION_LEVEL 5 | 66 | #define DHT_GNS_REPLICATION_LEVEL 5 |
69 | 67 | ||
70 | 68 | ||
71 | /* | 69 | /** |
72 | * DLL to hold the authority chain | 70 | * DLL to hold the authority chain we had to pass in the resolution |
73 | * we had to pass in the resolution process | 71 | * process. |
74 | */ | 72 | */ |
75 | struct AuthorityChain | 73 | struct AuthorityChain |
76 | { | 74 | { |
75 | /** | ||
76 | * This is a DLL. | ||
77 | */ | ||
77 | struct AuthorityChain *prev; | 78 | struct AuthorityChain *prev; |
78 | 79 | ||
79 | struct AuthorityChain *next; | ||
80 | |||
81 | /** | 80 | /** |
82 | * the zone hash of the authority | 81 | * This is a DLL. |
83 | */ | 82 | */ |
84 | struct GNUNET_CRYPTO_ShortHashCode zone; | 83 | struct AuthorityChain *next; |
85 | 84 | ||
86 | /** | 85 | /** |
87 | * (local) name of the authority | 86 | * label corresponding to the authority |
88 | */ | 87 | */ |
89 | char name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH]; | 88 | char label[GNUNET_DNSPARSER_MAX_LABEL_LENGTH]; |
90 | 89 | ||
91 | /** | 90 | /** |
92 | * was the ns entry fresh | 91 | * #GNUNET_YES if the authority was a GNS authority, |
92 | * #GNUNET_NO if the authority was a DNS authority. | ||
93 | */ | 93 | */ |
94 | int fresh; | 94 | int gns_authority; |
95 | }; | ||
96 | 95 | ||
96 | /** | ||
97 | * Information about the resolver authority for this label. | ||
98 | */ | ||
99 | union | ||
100 | { | ||
97 | 101 | ||
98 | /** | 102 | /** |
99 | * handle to a resolution process | 103 | * The zone of the GNS authority |
100 | */ | 104 | */ |
101 | struct ResolverHandle; | 105 | struct GNUNET_CRYPTO_EccPublicKey gns_authority; |
102 | 106 | ||
107 | struct | ||
108 | { | ||
109 | /** | ||
110 | * Domain of the DNS resolver that is the authority. | ||
111 | * (appended to construct the DNS name to resolve; | ||
112 | * this is NOT the DNS name of the DNS server!). | ||
113 | */ | ||
114 | char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH]; | ||
103 | 115 | ||
104 | /** | 116 | /** |
105 | * processor for a record lookup result | 117 | * IP address of the DNS resolver that is authoritative. |
106 | * | 118 | * (this implementation currently only supports one |
107 | * @param cls the closure | 119 | * IP at a time). |
108 | * @param rd_count number of results | 120 | */ |
109 | * @param rd result data | 121 | struct sockaddr_storage dns_ip; |
110 | */ | ||
111 | typedef void (*RecordLookupProcessor) (void *cls, | ||
112 | uint32_t rd_count, | ||
113 | const struct GNUNET_NAMESTORE_RecordData *rd); | ||
114 | 122 | ||
123 | } dns_authority; | ||
115 | 124 | ||
116 | /** | 125 | } authority_info; |
117 | * processor for a resolution result | 126 | |
118 | * | 127 | }; |
119 | * @param cls the closure | ||
120 | * @param rh the resolution handle | ||
121 | * @param rd_count number of results | ||
122 | * @param rd result data (array of 'rd_count' records) | ||
123 | */ | ||
124 | typedef void (*ResolutionResultProcessor) (void *cls, | ||
125 | struct ResolverHandle *rh, | ||
126 | uint32_t rd_count, | ||
127 | const struct GNUNET_NAMESTORE_RecordData *rd); | ||
128 | 128 | ||
129 | 129 | ||
130 | /** | 130 | /** |
@@ -175,14 +175,8 @@ enum ResolutionStatus | |||
175 | 175 | ||
176 | 176 | ||
177 | /** | 177 | /** |
178 | * Handle to a currenty pending resolution | 178 | * Handle to a currenty pending resolution. On result (positive or |
179 | * a ResolverHandle is passed to, for example | 179 | * negative) the #GNS_ResultProcessor is called. |
180 | * resolve_record_ns to resolve a record in the namestore. | ||
181 | * On result (positive or negative) the ResolutionResultProcessor | ||
182 | * is called. | ||
183 | * If a timeout is set timeout_cont will be called. | ||
184 | * If no timeout is set (ie timeout forever) then background resolutions | ||
185 | * might be triggered. | ||
186 | */ | 180 | */ |
187 | struct GNS_ResolverHandle | 181 | struct GNS_ResolverHandle |
188 | { | 182 | { |
@@ -190,127 +184,53 @@ struct GNS_ResolverHandle | |||
190 | /** | 184 | /** |
191 | * DLL | 185 | * DLL |
192 | */ | 186 | */ |
193 | struct ResolverHandle *next; | 187 | struct GNS_ResolverHandle *next; |
194 | 188 | ||
195 | /** | 189 | /** |
196 | * DLL | 190 | * DLL |
197 | */ | 191 | */ |
198 | struct ResolverHandle *prev; | 192 | struct GNS_ResolverHandle *prev; |
199 | |||
200 | /** | ||
201 | * Last record data found | ||
202 | */ | ||
203 | struct GNUNET_NAMESTORE_RecordData rd; | ||
204 | |||
205 | /** | ||
206 | * Number of last record data found | ||
207 | */ | ||
208 | unsigned int rd_count; | ||
209 | 193 | ||
210 | /** | 194 | /** |
211 | * The name to resolve | 195 | * The top-level GNS authoritative zone to query |
212 | */ | 196 | */ |
213 | char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH]; | 197 | struct GNUNET_CRYPTO_EccPublicKey authority_zone; |
214 | 198 | ||
215 | /** | 199 | /** |
216 | * has this query been answered? how many matches | 200 | * called when resolution phase finishes |
217 | */ | ||
218 | int answered; | ||
219 | |||
220 | /** | ||
221 | * Use only cache | ||
222 | */ | ||
223 | int only_cached; | ||
224 | |||
225 | /** | ||
226 | * the authoritative zone to query | ||
227 | */ | 201 | */ |
228 | struct GNUNET_CRYPTO_ShortHashCode authority; | 202 | GNS_ResultProcessor proc; |
229 | 203 | ||
230 | /** | 204 | /** |
231 | * the name of the authoritative zone to query | 205 | * closure passed to proc |
232 | */ | 206 | */ |
233 | char authority_name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH]; | 207 | void* proc_cls; |
234 | 208 | ||
235 | /** | 209 | /** |
236 | * a handle for dht lookups. should be NULL if no lookups are in progress | 210 | * Handle for DHT lookups. should be NULL if no lookups are in progress |
237 | */ | 211 | */ |
238 | struct GNUNET_DHT_GetHandle *get_handle; | 212 | struct GNUNET_DHT_GetHandle *get_handle; |
239 | 213 | ||
240 | /** | 214 | /** |
241 | * timeout set for this lookup task | 215 | * Handle to a VPN request, NULL if none is active. |
242 | */ | ||
243 | struct GNUNET_TIME_Relative timeout; | ||
244 | |||
245 | /** | ||
246 | * a handle to a vpn request | ||
247 | */ | 216 | */ |
248 | struct GNUNET_VPN_RedirectionRequest *vpn_handle; | 217 | struct GNUNET_VPN_RedirectionRequest *vpn_handle; |
249 | 218 | ||
250 | /** | 219 | /** |
251 | * a socket for a dns request | 220 | * Socket for a DNS request, NULL if none is active. |
252 | */ | ||
253 | struct GNUNET_NETWORK_Handle *dns_sock; | ||
254 | |||
255 | /** | ||
256 | * a synthesized dns name | ||
257 | */ | ||
258 | char dns_name[GNUNET_DNSPARSER_MAX_NAME_LENGTH]; | ||
259 | |||
260 | /** | ||
261 | * the authoritative dns zone | ||
262 | */ | ||
263 | char dns_zone[GNUNET_DNSPARSER_MAX_NAME_LENGTH]; | ||
264 | |||
265 | /** | ||
266 | * the address of the DNS server FIXME not needed? | ||
267 | */ | ||
268 | struct sockaddr_in dns_addr; | ||
269 | |||
270 | /** | ||
271 | * handle to the local stub resolver request | ||
272 | */ | ||
273 | struct GNUNET_RESOLVER_RequestHandle *dns_resolver_handle; | ||
274 | |||
275 | /** | ||
276 | * select task for DNS | ||
277 | */ | ||
278 | GNUNET_SCHEDULER_TaskIdentifier dns_read_task; | ||
279 | |||
280 | /** | ||
281 | * pointer to raw dns query payload FIXME needs to be freed/NULL | ||
282 | */ | ||
283 | char *dns_raw_packet; | ||
284 | |||
285 | /** | ||
286 | * size of the raw dns query | ||
287 | */ | 221 | */ |
288 | size_t dns_raw_packet_size; | 222 | struct GNUNET_DNSSTUB_RequestSocket *dns_request; |
289 | 223 | ||
290 | /** | 224 | /** |
291 | * timeout task for the lookup | 225 | * Pending Namestore task |
292 | */ | ||
293 | GNUNET_SCHEDULER_TaskIdentifier timeout_task; | ||
294 | |||
295 | /** | ||
296 | * continuation to call on timeout | ||
297 | */ | ||
298 | GNUNET_SCHEDULER_Task timeout_cont; | ||
299 | |||
300 | /** | ||
301 | * closure for timeout cont | ||
302 | */ | 226 | */ |
303 | void* timeout_cont_cls; | 227 | struct GNUNET_NAMESTORE_QueueEntry *namestore_task; |
304 | 228 | ||
305 | /** | 229 | /** |
306 | * called when resolution phase finishes | 230 | * Heap node associated with this lookup. Used to limit number of |
231 | * concurrent requests. | ||
307 | */ | 232 | */ |
308 | ResolutionResultProcessor proc; | 233 | struct GNUNET_CONTAINER_HeapNode *dht_heap_node; |
309 | |||
310 | /** | ||
311 | * closure passed to proc | ||
312 | */ | ||
313 | void* proc_cls; | ||
314 | 234 | ||
315 | /** | 235 | /** |
316 | * DLL to store the authority chain | 236 | * DLL to store the authority chain |
@@ -323,70 +243,30 @@ struct GNS_ResolverHandle | |||
323 | struct AuthorityChain *authority_chain_tail; | 243 | struct AuthorityChain *authority_chain_tail; |
324 | 244 | ||
325 | /** | 245 | /** |
326 | * status of the resolution result | 246 | * Private key of the shorten zone, NULL to not shorten. |
327 | */ | ||
328 | enum ResolutionStatus status; | ||
329 | |||
330 | /** | ||
331 | * The provate local zone of this request | ||
332 | */ | ||
333 | struct GNUNET_CRYPTO_ShortHashCode private_local_zone; | ||
334 | |||
335 | /** | ||
336 | * private key of an/our authoritative zone | ||
337 | * can be NULL but automatical PKEY import will not work | ||
338 | */ | ||
339 | struct GNUNET_CRYPTO_EccPrivateKey *priv_key; | ||
340 | |||
341 | /** | ||
342 | * the heap node associated with this lookup, null if timeout is set | ||
343 | * used for DHT background lookups. | ||
344 | */ | ||
345 | struct GNUNET_CONTAINER_HeapNode *dht_heap_node; | ||
346 | |||
347 | /** | ||
348 | * Id for resolution process | ||
349 | */ | ||
350 | unsigned long long id; | ||
351 | |||
352 | /** | ||
353 | * Pending Namestore task | ||
354 | */ | ||
355 | struct GNUNET_NAMESTORE_QueueEntry *namestore_task; | ||
356 | |||
357 | }; | ||
358 | |||
359 | |||
360 | /** | ||
361 | * Handle to a record lookup | ||
362 | */ | ||
363 | struct RecordLookupHandle | ||
364 | { | ||
365 | /** | ||
366 | * the record type to look up | ||
367 | */ | 247 | */ |
368 | int record_type; | 248 | struct GNUNET_CRYPTO_EccPrivateKey *shorten_key; |
369 | 249 | ||
370 | /** | 250 | /** |
371 | * the name to look up | 251 | * The name to resolve |
372 | */ | 252 | */ |
373 | char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH]; | 253 | char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH]; |
374 | 254 | ||
375 | /** | 255 | /** |
376 | * Method to call on record resolution result | 256 | * Current offset in 'name' where we are resolving. |
377 | */ | 257 | */ |
378 | RecordLookupProcessor proc; | 258 | size_t name_resolution_pos; |
379 | 259 | ||
380 | /** | 260 | /** |
381 | * closure to pass to proc | 261 | * Use only cache |
382 | */ | 262 | */ |
383 | void* proc_cls; | 263 | int only_cached; |
384 | 264 | ||
385 | }; | 265 | }; |
386 | 266 | ||
387 | 267 | ||
388 | /** | 268 | /** |
389 | * Handle to a pseu lookup | 269 | * Handle for a PSEU lookup used to shorten names. |
390 | */ | 270 | */ |
391 | struct GetPseuAuthorityHandle | 271 | struct GetPseuAuthorityHandle |
392 | { | 272 | { |
@@ -401,61 +281,36 @@ struct GetPseuAuthorityHandle | |||
401 | struct GetPseuAuthorityHandle *prev; | 281 | struct GetPseuAuthorityHandle *prev; |
402 | 282 | ||
403 | /** | 283 | /** |
404 | * the name to store the zone under | 284 | * Private key of the (shorten) zone to store the resulting |
285 | * pseudonym in. | ||
405 | */ | 286 | */ |
406 | char name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH]; | 287 | struct GNUNET_CRYPTO_EccPrivateKey shorten_zone_key; |
407 | 288 | ||
408 | /** | 289 | /** |
409 | * test name to store the zone under | 290 | * Original label (used if no PSEU record is found). |
410 | */ | 291 | */ |
411 | char test_name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH]; | 292 | char label[GNUNET_DNSPARSER_MAX_LABEL_LENGTH + 1]; |
412 | |||
413 | /** | ||
414 | * the zone of our authority | ||
415 | */ | ||
416 | struct GNUNET_CRYPTO_ShortHashCode our_zone; | ||
417 | 293 | ||
418 | /** | 294 | /** |
419 | * the private key of the zone to store the pseu in | 295 | * The zone for which we are trying to find the PSEU record. |
420 | */ | 296 | */ |
421 | struct GNUNET_CRYPTO_EccPrivateKey *key; | 297 | struct GNUNET_CRYPTO_EccPublicKey target_zone; |
422 | 298 | ||
423 | /** | 299 | /** |
424 | * a handle for dht lookups. should be NULL if no lookups are in progress | 300 | * Handle for DHT lookups. Should be NULL if no lookups are in progress |
425 | */ | 301 | */ |
426 | struct GNUNET_DHT_GetHandle *get_handle; | 302 | struct GNUNET_DHT_GetHandle *get_handle; |
427 | 303 | ||
428 | /** | 304 | /** |
429 | * timeout task for lookup | 305 | * Handle to namestore request |
430 | */ | ||
431 | GNUNET_SCHEDULER_TaskIdentifier timeout; | ||
432 | |||
433 | /** | ||
434 | * Authority to shorten | ||
435 | */ | 306 | */ |
436 | struct AuthorityChain *auth; | 307 | struct GNUNET_NAMESTORE_QueueEntry *namestore_task; |
437 | |||
438 | /** | ||
439 | * handle to namestore request | ||
440 | */ | ||
441 | struct GNUNET_NAMESTORE_QueueEntry* namestore_task; | ||
442 | }; | ||
443 | |||
444 | 308 | ||
445 | /** | ||
446 | * Namestore queue entries in background | ||
447 | */ | ||
448 | struct NamestoreBGTask | ||
449 | { | ||
450 | /** | 309 | /** |
451 | * node in heap | 310 | * Task to abort DHT lookup operation. |
452 | */ | 311 | */ |
453 | struct GNUNET_CONTAINER_HeapNode *node; | 312 | GNUNET_SCHEDULER_TaskIdentifier timeout_task; |
454 | 313 | ||
455 | /** | ||
456 | * queue entry | ||
457 | */ | ||
458 | struct GNUNET_NAMESTORE_QueueEntry *qe; | ||
459 | }; | 314 | }; |
460 | 315 | ||
461 | 316 | ||
@@ -475,14 +330,14 @@ static struct GNUNET_VPN_Handle *vpn_handle; | |||
475 | static struct GNUNET_DHT_Handle *dht_handle; | 330 | static struct GNUNET_DHT_Handle *dht_handle; |
476 | 331 | ||
477 | /** | 332 | /** |
478 | * Heap for parallel DHT lookups | 333 | * Handle to perform DNS lookups. |
479 | */ | 334 | */ |
480 | static struct GNUNET_CONTAINER_Heap *dht_lookup_heap; | 335 | static struct GNUNET_DNSSTUB_Context *dns_handle; |
481 | 336 | ||
482 | /** | 337 | /** |
483 | * Heap for namestore queues | 338 | * Heap for limiting parallel DHT lookups |
484 | */ | 339 | */ |
485 | static struct GNUNET_CONTAINER_Heap *ns_task_heap; | 340 | static struct GNUNET_CONTAINER_Heap *dht_lookup_heap; |
486 | 341 | ||
487 | /** | 342 | /** |
488 | * Maximum amount of parallel queries in background | 343 | * Maximum amount of parallel queries in background |
@@ -490,36 +345,30 @@ static struct GNUNET_CONTAINER_Heap *ns_task_heap; | |||
490 | static unsigned long long max_allowed_background_queries; | 345 | static unsigned long long max_allowed_background_queries; |
491 | 346 | ||
492 | /** | 347 | /** |
493 | * Maximum amount of parallel namestore tasks in background | 348 | * Head of PSEU/shorten operations list. |
494 | */ | 349 | */ |
495 | static unsigned long long max_allowed_ns_tasks; | 350 | struct GetPseuAuthorityHandle *gph_head; |
496 | 351 | ||
497 | /** | 352 | /** |
498 | * Whether or not to ignore pending records | 353 | * Tail of PSEU/shorten operations list. |
499 | */ | 354 | */ |
500 | static int ignore_pending_records; | 355 | struct GetPseuAuthorityHandle *gph_tail; |
501 | 356 | ||
502 | /** | 357 | /** |
503 | * Resolver lookup list | 358 | * Head of resolver lookup list |
504 | */ | 359 | */ |
505 | static struct ResolverHandle *rlh_head; | 360 | static struct GNS_ResolverHandle *rlh_head; |
506 | 361 | ||
507 | /** | 362 | /** |
508 | * Resolver lookup list | 363 | * Tail of resolver lookup list |
509 | */ | 364 | */ |
510 | static struct ResolverHandle *rlh_tail; | 365 | static struct GNS_ResolverHandle *rlh_tail; |
511 | 366 | ||
512 | /** | 367 | /** |
513 | * Global configuration. | 368 | * Global configuration. |
514 | */ | 369 | */ |
515 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | 370 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
516 | 371 | ||
517 | /** | ||
518 | * a resolution identifier pool variable | ||
519 | * This is a non critical identifier useful for debugging | ||
520 | */ | ||
521 | static unsigned long long rid_gen; | ||
522 | |||
523 | 372 | ||
524 | /** | 373 | /** |
525 | * Check if name is in srv format (_x._y.xxx) | 374 | * Check if name is in srv format (_x._y.xxx) |
@@ -586,24 +435,36 @@ is_canonical (const char *name) | |||
586 | } | 435 | } |
587 | 436 | ||
588 | 437 | ||
589 | static void | 438 | /* ******************** Shortening logic ************************ */ |
590 | free_get_pseu_authority_handle (struct GetPseuAuthorityHandle *gph) | ||
591 | { | ||
592 | gph->namestore_task = NULL; | ||
593 | GNUNET_free (gph->auth); | ||
594 | GNUNET_CRYPTO_ecc_key_free (gph->key); | ||
595 | GNUNET_CONTAINER_DLL_remove (gph_head, gph_tail, gph); | ||
596 | GNUNET_free (gph); | ||
597 | } | ||
598 | 439 | ||
599 | 440 | ||
600 | /** | 441 | /** |
601 | * Callback that shortens authorities | 442 | * Cleanup a 'struct GetPseuAuthorityHandle', terminating all |
443 | * pending activities. | ||
602 | * | 444 | * |
603 | * @param gph the handle containing the name to shorten | 445 | * @param gph handle to terminate |
604 | */ | 446 | */ |
605 | static void | 447 | static void |
606 | shorten_authority_chain (struct GetPseuAuthorityHandle *gph); | 448 | free_get_pseu_authority_handle (struct GetPseuAuthorityHandle *gph) |
449 | { | ||
450 | if (NULL != gph->get_handle) | ||
451 | { | ||
452 | GNUNET_DHT_get_stop (gph->get_handle); | ||
453 | gph->get_handle = NULL; | ||
454 | } | ||
455 | if (NULL != gph->namestore_task) | ||
456 | { | ||
457 | GNUNET_NAMESTORE_cancel (gph->namestore_task); | ||
458 | gph->namestore_task = NULL; | ||
459 | } | ||
460 | if (GNUNET_SCHEDULER_NO_TASK != gph->timeout_task) | ||
461 | { | ||
462 | GNUNET_SCHEDULER_cancel (gph->timeout_task); | ||
463 | gph->timeout_task = GNUNET_SCHEDULER_NO_TASK; | ||
464 | } | ||
465 | GNUNET_CONTAINER_DLL_remove (gph_head, gph_tail, gph); | ||
466 | GNUNET_free (gph); | ||
467 | } | ||
607 | 468 | ||
608 | 469 | ||
609 | /** | 470 | /** |
@@ -614,192 +475,327 @@ shorten_authority_chain (struct GetPseuAuthorityHandle *gph); | |||
614 | * @param emsg unused | 475 | * @param emsg unused |
615 | */ | 476 | */ |
616 | static void | 477 | static void |
617 | create_pkey_cont (void* cls, int32_t success, const char* emsg) | 478 | create_pkey_cont (void* cls, |
479 | int32_t success, | ||
480 | const char *emsg) | ||
618 | { | 481 | { |
619 | //FIXME do sth with error | ||
620 | struct GetPseuAuthorityHandle* gph = cls; | 482 | struct GetPseuAuthorityHandle* gph = cls; |
621 | 483 | ||
484 | gph->namestore_task = NULL; | ||
622 | free_get_pseu_authority_handle (gph); | 485 | free_get_pseu_authority_handle (gph); |
623 | } | 486 | } |
624 | 487 | ||
625 | 488 | ||
626 | /** | 489 | /** |
627 | * Namestore calls this function if we have record for this name. | 490 | * Namestore calls this function if we have record for this name. |
628 | * (or with rd_count=0 to indicate no matches) | 491 | * (or with rd_count=0 to indicate no matches). |
629 | * | 492 | * |
630 | * @param cls the pending query | 493 | * @param cls the pending query |
631 | * @param key the key of the zone we did the lookup | 494 | * @param key the key of the zone we did the lookup |
632 | * @param expiration expiration date of the namestore entry | ||
633 | * @param name the name for which we need an authority | 495 | * @param name the name for which we need an authority |
634 | * @param rd_count the number of records with 'name' | 496 | * @param rd_count the number of records with 'name' |
635 | * @param rd the record data | 497 | * @param rd the record data |
636 | * @param signature the signature of the authority for the record data | ||
637 | */ | 498 | */ |
638 | static void | 499 | static void |
639 | process_pseu_lookup_ns (void* cls, | 500 | process_pseu_lookup_ns (void *cls, |
640 | const struct GNUNET_CRYPTO_EccPublicKey *key, | 501 | const struct GNUNET_CRYPTO_EccPrivateKey *key, |
641 | struct GNUNET_TIME_Absolute expiration, | 502 | const char *name, |
642 | const char *name, unsigned int rd_count, | 503 | unsigned int rd_count, |
643 | const struct GNUNET_NAMESTORE_RecordData *rd, | 504 | const struct GNUNET_NAMESTORE_RecordData *rd) |
644 | const struct GNUNET_CRYPTO_EccSignature *signature) | ||
645 | { | 505 | { |
646 | struct GetPseuAuthorityHandle* gph = cls; | 506 | struct GetPseuAuthorityHandle *gph = cls; |
647 | struct GNUNET_NAMESTORE_RecordData new_pkey; | 507 | struct GNUNET_NAMESTORE_RecordData new_pkey; |
648 | 508 | ||
649 | gph->namestore_task = NULL; | 509 | gph->namestore_task = NULL; |
650 | if (rd_count > 0) | 510 | if (rd_count > 0) |
651 | { | 511 | { |
652 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 512 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
653 | "GNS_AUTO_PSEU: Name %s already taken in NS!\n", name); | 513 | "Name `%s' already taken, cannot shorten.\n", |
654 | free_get_pseu_authority_handle (gph); | 514 | name); |
515 | /* if this was not yet the original label, try one more | ||
516 | time, this time not using PSEU but the original label */ | ||
517 | if (0 == strcmp (name, | ||
518 | gph->label)) | ||
519 | free_get_pseu_authority_handle (gph); | ||
520 | else | ||
521 | gph->namestore_task = GNUNET_NAMESTORE_lookup (namestore_handle, | ||
522 | &gph->shorten_zone_key, | ||
523 | gph->label, | ||
524 | GNUNET_NAMESTORE_TYPE_ANY, | ||
525 | &process_pseu_lookup_ns, | ||
526 | gph); | ||
655 | return; | 527 | return; |
656 | } | 528 | } |
657 | 529 | /* name is available */ | |
658 | /* name is free */ | ||
659 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 530 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
660 | "GNS_AUTO_PSEU: Name %s not taken in NS! Adding\n", | 531 | "Shortening `%s' to `%s'\n", |
661 | gph->test_name); | 532 | GNUNET_NAMESTORE_z2s (&gph->target_zone), |
662 | 533 | name); | |
663 | new_pkey.expiration_time = UINT64_MAX; | 534 | new_pkey.expiration_time = UINT64_MAX; |
664 | new_pkey.data_size = sizeof (struct GNUNET_CRYPTO_ShortHashCode); | 535 | new_pkey.data_size = sizeof (struct GNUNET_CRYPTO_EccPublicKey); |
665 | new_pkey.data = &gph->auth->zone; | 536 | new_pkey.data = &gph->target_zone; |
666 | new_pkey.record_type = GNUNET_NAMESTORE_TYPE_PKEY; | 537 | new_pkey.record_type = GNUNET_NAMESTORE_TYPE_PKEY; |
667 | new_pkey.flags = GNUNET_NAMESTORE_RF_AUTHORITY | 538 | new_pkey.flags = GNUNET_NAMESTORE_RF_AUTHORITY |
668 | | GNUNET_NAMESTORE_RF_PRIVATE | 539 | | GNUNET_NAMESTORE_RF_PRIVATE |
669 | | GNUNET_NAMESTORE_RF_PENDING; | 540 | | GNUNET_NAMESTORE_RF_PENDING; |
670 | gph->namestore_task = GNUNET_NAMESTORE_record_put_by_authority (namestore_handle, | 541 | gph->namestore_task |
671 | gph->key, | 542 | = GNUNET_NAMESTORE_records_store (namestore_handle, |
672 | gph->test_name, | 543 | &gph->shorten_zone_key, |
673 | 1, | 544 | name, |
674 | &new_pkey, | 545 | 1, &new_pkey, |
675 | &create_pkey_cont, | 546 | &create_pkey_cont, gph); |
676 | gph); | ||
677 | } | 547 | } |
678 | 548 | ||
679 | 549 | ||
680 | /** | 550 | /** |
681 | * process result of a dht pseu lookup | 551 | * Process result of a DHT lookup for a PSEU record. |
682 | * | 552 | * |
683 | * @param gph the handle | 553 | * @param gph the handle to our shorten operation |
684 | * @param name the pseu result or NULL | 554 | * @param pseu the pseu result or NULL |
685 | */ | 555 | */ |
686 | static void | 556 | static void |
687 | process_pseu_result (struct GetPseuAuthorityHandle* gph, | 557 | process_pseu_result (struct GetPseuAuthorityHandle* gph, |
688 | const char* name) | 558 | const char *pseu) |
689 | { | 559 | { |
690 | if (NULL == name) | 560 | if (NULL == pseu) |
691 | { | 561 | { |
562 | /* no PSEU found, try original label */ | ||
692 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 563 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
693 | "GNS_AUTO_PSEU: No PSEU, no shorten. Finished.\n"); | 564 | "No PSEU found, trying original label `%s' instead.\n", |
694 | free_get_pseu_authority_handle (gph); | 565 | gph->label); |
566 | gph->namestore_task = GNUNET_NAMESTORE_lookup (namestore_handle, | ||
567 | &gph->shorten_zone_key, | ||
568 | gph->label, | ||
569 | GNUNET_NAMESTORE_TYPE_ANY, | ||
570 | &process_pseu_lookup_ns, | ||
571 | gph); | ||
695 | return; | 572 | return; |
696 | } | 573 | } |
697 | 574 | ||
698 | memcpy (gph->test_name, name, strlen(name) + 1); | 575 | /* check if 'pseu' is taken */ |
576 | gph->namestore_task = GNUNET_NAMESTORE_lookup (namestore_handle, | ||
577 | &gph->shorten_zone_key, | ||
578 | pseu, | ||
579 | GNUNET_NAMESTORE_TYPE_ANY, | ||
580 | &process_pseu_lookup_ns, | ||
581 | gph); | ||
582 | } | ||
583 | |||
584 | |||
585 | /** | ||
586 | * Handle timeout for DHT request during shortening. | ||
587 | * | ||
588 | * @param cls the request handle as closure | ||
589 | * @param tc the task context | ||
590 | */ | ||
591 | static void | ||
592 | handle_auth_discovery_timeout (void *cls, | ||
593 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
594 | { | ||
595 | struct GetPseuAuthorityHandle *gph = cls; | ||
596 | |||
597 | gph->timeout_task = GNUNET_SCHEDULER_NO_TASK; | ||
699 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 598 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
700 | "GNS_AUTO_PSEU: Checking %s for collision in NS\n", | 599 | "DHT lookup for PSEU query timed out.\n"); |
701 | gph->test_name); | 600 | GNUNET_DHT_get_stop (gph->get_handle); |
702 | /** | 601 | gph->get_handle = NULL; |
703 | * Check for collision | 602 | process_pseu_result (gph, NULL); |
704 | */ | ||
705 | gph->namestore_task = GNUNET_NAMESTORE_lookup_record (namestore_handle, | ||
706 | &gph->our_zone, | ||
707 | gph->test_name, | ||
708 | GNUNET_NAMESTORE_TYPE_ANY, | ||
709 | &process_pseu_lookup_ns, | ||
710 | gph); | ||
711 | } | 603 | } |
712 | 604 | ||
713 | 605 | ||
714 | /** | 606 | /** |
715 | * Start shortening algorithm using auth as | 607 | * Handle decrypted records from DHT result. |
716 | * authority chain | ||
717 | * | 608 | * |
718 | * @param auth the authorities that were resolved | 609 | * @param cls closure with our 'struct GetPseuAuthorityHandle' |
719 | * @param key the private key for PKEY import | 610 | * @param rd_count number of entries in 'rd' array |
611 | * @param rd array of records with data to store | ||
720 | */ | 612 | */ |
721 | static void | 613 | static void |
722 | start_shorten (struct AuthorityChain *auth, | 614 | process_auth_records (void *cls, |
723 | const struct GNUNET_CRYPTO_EccPrivateKey *key) | 615 | unsigned int rd_count, |
616 | const struct GNUNET_NAMESTORE_RecordData *rd) | ||
724 | { | 617 | { |
725 | struct GetPseuAuthorityHandle *gph; | 618 | struct GetPseuAuthorityHandle *gph = cls; |
726 | struct GNUNET_CRYPTO_EccPublicKey pkey; | 619 | unsigned int i; |
727 | 620 | ||
728 | GNUNET_CRYPTO_ecc_key_get_public (key, &pkey); | 621 | for (i=0; i < rd_count; i++) |
729 | gph = GNUNET_new (struct GetPseuAuthorityHandle); | 622 | { |
730 | gph->key = GNUNET_new (struct GNUNET_CRYPTO_EccPrivateKey); | 623 | if (GNUNET_NAMESTORE_TYPE_PSEU == rd[i].record_type) |
731 | *gph->key = *key; | 624 | { |
732 | if (NULL == gph->key) | 625 | /* found pseu */ |
626 | process_pseu_result (gph, | ||
627 | (const char *) rd[i].data); | ||
628 | return; | ||
629 | } | ||
630 | } | ||
631 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
632 | "No PSEU record found in DHT reply.\n"); | ||
633 | process_pseu_result (gph, NULL); | ||
634 | } | ||
635 | |||
636 | |||
637 | /** | ||
638 | * Function called when we find a PSEU entry in the DHT | ||
639 | * | ||
640 | * @param cls the request handle | ||
641 | * @param exp lifetime | ||
642 | * @param key the key the record was stored under | ||
643 | * @param get_path get path | ||
644 | * @param get_path_length get path length | ||
645 | * @param put_path put path | ||
646 | * @param put_path_length put path length | ||
647 | * @param type the block type | ||
648 | * @param size the size of the record | ||
649 | * @param data the record data | ||
650 | */ | ||
651 | static void | ||
652 | process_auth_discovery_dht_result (void* cls, | ||
653 | struct GNUNET_TIME_Absolute exp, | ||
654 | const struct GNUNET_HashCode *key, | ||
655 | const struct GNUNET_PeerIdentity *get_path, | ||
656 | unsigned int get_path_length, | ||
657 | const struct GNUNET_PeerIdentity *put_path, | ||
658 | unsigned int put_path_length, | ||
659 | enum GNUNET_BLOCK_Type type, | ||
660 | size_t size, | ||
661 | const void *data) | ||
662 | { | ||
663 | struct GetPseuAuthorityHandle *gph = cls; | ||
664 | const struct GNUNET_NAMESTORE_Block *block; | ||
665 | |||
666 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
667 | "Got DHT result for PSEU request\n"); | ||
668 | GNUNET_DHT_get_stop (gph->get_handle); | ||
669 | gph->get_handle = NULL; | ||
670 | GNUNET_SCHEDULER_cancel (gph->timeout_task); | ||
671 | gph->timeout_task = GNUNET_SCHEDULER_NO_TASK; | ||
672 | |||
673 | if (NULL == data) | ||
733 | { | 674 | { |
734 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 675 | /* is this allowed!? */ |
735 | "Failed to decode ECC key on shorten\n"); | 676 | GNUNET_break (0); |
736 | GNUNET_free (gph); | 677 | process_pseu_result (gph, NULL); |
737 | return; | 678 | return; |
738 | } | 679 | } |
739 | GNUNET_CRYPTO_short_hash (&pkey, | 680 | if (size < sizeof (struct GNUNET_NAMESTORE_Block)) |
740 | sizeof (struct GNUNET_CRYPTO_EccPublicKey), | 681 | { |
741 | &gph->our_zone); | 682 | /* how did this pass DHT block validation!? */ |
742 | gph->auth = GNUNET_malloc (sizeof (struct AuthorityChain)); | 683 | GNUNET_break (0); |
743 | memcpy (gph->auth, auth, sizeof (struct AuthorityChain)); | 684 | process_pseu_result (gph, NULL); |
744 | GNUNET_CONTAINER_DLL_insert (gph_head, gph_tail, gph); | 685 | return; |
745 | shorten_authority_chain (gph); | 686 | } |
687 | block = data; | ||
688 | if (size != | ||
689 | ntohs (block->purpose.size) + | ||
690 | sizeof (struct GNUNET_CRYPTO_EccPublicKey) + | ||
691 | sizeof (struct GNUNET_CRYPTO_EccSignature)) | ||
692 | { | ||
693 | /* how did this pass DHT block validation!? */ | ||
694 | GNUNET_break (0); | ||
695 | process_pseu_result (gph, NULL); | ||
696 | return; | ||
697 | } | ||
698 | if (GNUNET_OK != | ||
699 | GNUNET_NAMESTORE_block_decrypt (block, | ||
700 | &gph->target_zone, | ||
701 | GNUNET_GNS_TLD_PLUS, | ||
702 | &process_auth_records, | ||
703 | gph)) | ||
704 | { | ||
705 | /* other peer encrypted invalid block, complain */ | ||
706 | GNUNET_break_op (0); | ||
707 | process_pseu_result (gph, NULL); | ||
708 | return; | ||
709 | } | ||
746 | } | 710 | } |
747 | 711 | ||
748 | 712 | ||
749 | /** | 713 | /** |
750 | * Initialize the resolver | 714 | * Callback called by namestore for a zone to name result. We're |
715 | * trying to see if a short name for a given zone already exists. | ||
751 | * | 716 | * |
752 | * @param nh the namestore handle | 717 | * @param cls the closure |
753 | * @param dh the dht handle | 718 | * @param zone_key the zone we queried |
754 | * @param lz the local zone's hash | 719 | * @param name the name found or NULL |
755 | * @param c configuration handle | 720 | * @param rd_len number of records for the name |
756 | * @param max_bg_queries maximum number of parallel background queries in dht | 721 | * @param rd the record data (PKEY) for the name |
757 | * @param ignore_pending ignore records that still require user confirmation | ||
758 | * on lookup | ||
759 | * @return GNUNET_OK on success | ||
760 | */ | 722 | */ |
761 | int | 723 | static void |
762 | GNS_resolver_init (struct GNUNET_NAMESTORE_Handle *nh, | 724 | process_zone_to_name_discover (void *cls, |
763 | struct GNUNET_DHT_Handle *dh, | 725 | const struct GNUNET_CRYPTO_EccPrivateKey *zone_key, |
764 | const struct GNUNET_CONFIGURATION_Handle *c, | 726 | const char *name, |
765 | unsigned long long max_bg_queries, | 727 | unsigned int rd_len, |
766 | int ignore_pending) | 728 | const struct GNUNET_NAMESTORE_RecordData *rd) |
767 | { | 729 | { |
768 | if ( (NULL == nh) || | 730 | struct GetPseuAuthorityHandle* gph = cls; |
769 | (NULL == dh) ) | 731 | struct GNUNET_HashCode lookup_key; |
770 | return GNUNET_SYSERR; | ||
771 | 732 | ||
772 | cfg = c; | 733 | gph->namestore_task = NULL; |
773 | namestore_handle = nh; | 734 | if (0 != rd_len) |
774 | dht_handle = dh; | 735 | { |
775 | local_zone = lz; | 736 | /* we found a match in our own zone */ |
776 | dht_lookup_heap = | 737 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
777 | GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 738 | "Shortening aborted, name `%s' already reserved for the zone\n", |
778 | ns_task_heap = | 739 | name); |
779 | GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 740 | free_get_pseu_authority_handle (gph); |
780 | max_allowed_background_queries = max_bg_queries; | 741 | return; |
781 | max_allowed_ns_tasks = GNUNET_GNS_MAX_NS_TASKS; | 742 | } |
782 | ignore_pending_records = ignore_pending; | 743 | /* record does not yet exist, go into DHT to find PSEU record */ |
783 | GNUNET_RESOLVER_connect (cfg); | 744 | GNUNET_NAMESTORE_query_from_public_key (&gph->target_zone, |
784 | return GNUNET_OK; | 745 | GNUNET_GNS_TLD_PLUS, |
746 | &lookup_key); | ||
747 | gph->timeout_task = GNUNET_SCHEDULER_add_delayed (DHT_LOOKUP_TIMEOUT, | ||
748 | &handle_auth_discovery_timeout, | ||
749 | gph); | ||
750 | gph->get_handle = GNUNET_DHT_get_start (dht_handle, | ||
751 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, | ||
752 | &lookup_key, | ||
753 | DHT_GNS_REPLICATION_LEVEL, | ||
754 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | ||
755 | NULL, 0, | ||
756 | &process_auth_discovery_dht_result, | ||
757 | gph); | ||
785 | } | 758 | } |
786 | 759 | ||
787 | 760 | ||
788 | /** | 761 | /** |
789 | * finish lookup | 762 | * Start shortening algorithm, try to allocate a nice short |
763 | * canonical name for @a pub in @a shorten_zone, using | ||
764 | * @a original_label as one possible suggestion. | ||
790 | * | 765 | * |
791 | * @param rh resolver handle | 766 | * @param original_label original label for the zone |
792 | * @param rlh record lookup handle | 767 | * @param pub public key of the zone to shorten |
793 | * @param rd_count number of results | 768 | * @param shorten_zone private key of the target zone for the new record |
794 | * @param rd results | ||
795 | */ | 769 | */ |
796 | static void | 770 | static void |
797 | finish_lookup (struct ResolverHandle *rh, | 771 | start_shorten (const char *original_label, |
798 | struct RecordLookupHandle* rlh, | 772 | const struct GNUNET_CRYPTO_EccPublicKey *pub, |
799 | unsigned int rd_count, | 773 | const struct GNUNET_CRYPTO_EccPrivateKey *shorten_zone) |
800 | const struct GNUNET_NAMESTORE_RecordData *rd); | 774 | { |
775 | struct GetPseuAuthorityHandle *gph; | ||
776 | |||
777 | if (strlen (original_label) > GNUNET_DNSPARSER_MAX_LABEL_LENGTH) | ||
778 | { | ||
779 | GNUNET_break (0); | ||
780 | return; | ||
781 | } | ||
782 | gph = GNUNET_new (struct GetPseuAuthorityHandle); | ||
783 | gph->shorten_zone_key = *shorten_zone; | ||
784 | gph->target_zone = *pub; | ||
785 | strcpy (gph->label, original_label); | ||
786 | GNUNET_CONTAINER_DLL_insert (gph_head, gph_tail, gph); | ||
787 | /* first, check if we *already* have a record for this zone */ | ||
788 | gph->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle, | ||
789 | shorten_zone, | ||
790 | pub, | ||
791 | &process_zone_to_name_discover, | ||
792 | gph); | ||
793 | } | ||
801 | 794 | ||
802 | 795 | ||
796 | /* ************************** Resolution **************************** */ | ||
797 | |||
798 | #if 0 | ||
803 | /** | 799 | /** |
804 | * Helper function to free resolver handle | 800 | * Helper function to free resolver handle |
805 | * | 801 | * |
@@ -847,89 +843,6 @@ free_resolver_handle (struct ResolverHandle* rh) | |||
847 | 843 | ||
848 | 844 | ||
849 | /** | 845 | /** |
850 | * finish shorten | ||
851 | * | ||
852 | * @param rh resolver handle | ||
853 | * @param nsh name shorten handle | ||
854 | */ | ||
855 | static void | ||
856 | finish_shorten (struct ResolverHandle *rh, | ||
857 | struct NameShortenHandle *nsh); | ||
858 | |||
859 | |||
860 | /** | ||
861 | * finish get auth | ||
862 | * | ||
863 | * @param rh resolver handle | ||
864 | * @param nah get name authority handle | ||
865 | */ | ||
866 | static void | ||
867 | finish_get_auth (struct ResolverHandle *rh, | ||
868 | struct GetNameAuthorityHandle* rlh); | ||
869 | |||
870 | |||
871 | /** | ||
872 | * Shutdown resolver | ||
873 | */ | ||
874 | void | ||
875 | GNS_resolver_done () | ||
876 | { | ||
877 | struct GetPseuAuthorityHandle *tmp; | ||
878 | struct ResolverHandle *rh; | ||
879 | struct NamestoreBGTask *nbg; | ||
880 | |||
881 | while (NULL != (tmp = gph_head)) | ||
882 | { | ||
883 | if (tmp->get_handle != NULL) | ||
884 | { | ||
885 | GNUNET_DHT_get_stop (tmp->get_handle); | ||
886 | tmp->get_handle = NULL; | ||
887 | } | ||
888 | if (tmp->timeout != GNUNET_SCHEDULER_NO_TASK) | ||
889 | { | ||
890 | GNUNET_SCHEDULER_cancel (tmp->timeout); | ||
891 | tmp->timeout = GNUNET_SCHEDULER_NO_TASK; | ||
892 | } | ||
893 | if (NULL != tmp->namestore_task) | ||
894 | { | ||
895 | GNUNET_NAMESTORE_cancel (tmp->namestore_task); | ||
896 | tmp->namestore_task = NULL; | ||
897 | } | ||
898 | free_get_pseu_authority_handle (tmp); | ||
899 | } | ||
900 | |||
901 | while (NULL != rlh_head) | ||
902 | { | ||
903 | finish_lookup (rlh_head, rlh_head->proc_cls, 0, NULL); | ||
904 | } | ||
905 | while (NULL != nsh_head) | ||
906 | { | ||
907 | finish_shorten (nsh_head, nsh_head->proc_cls); | ||
908 | } | ||
909 | while (NULL != nah_head) | ||
910 | { | ||
911 | finish_get_auth (nah_head, nah_head->proc_cls); | ||
912 | } | ||
913 | |||
914 | while (NULL != (rh = GNUNET_CONTAINER_heap_remove_root(dht_lookup_heap))) | ||
915 | { | ||
916 | GNUNET_free (rh); | ||
917 | } | ||
918 | GNUNET_CONTAINER_heap_destroy (dht_lookup_heap); | ||
919 | dht_lookup_heap = NULL; | ||
920 | |||
921 | while (NULL != (nbg = GNUNET_CONTAINER_heap_remove_root(ns_task_heap))) | ||
922 | { | ||
923 | GNUNET_NAMESTORE_cancel (nbg->qe); | ||
924 | GNUNET_free (nbg); | ||
925 | } | ||
926 | GNUNET_CONTAINER_heap_destroy (ns_task_heap); | ||
927 | ns_task_heap = NULL; | ||
928 | |||
929 | } | ||
930 | |||
931 | |||
932 | /** | ||
933 | * Callback when record data is put into namestore | 846 | * Callback when record data is put into namestore |
934 | * | 847 | * |
935 | * @param cls the closure | 848 | * @param cls the closure |
@@ -965,90 +878,6 @@ on_namestore_record_put_result (void *cls, | |||
965 | 878 | ||
966 | 879 | ||
967 | /** | 880 | /** |
968 | * Lookup timeout task | ||
969 | * | ||
970 | * @param cls the ResolverHandle for the task that timed out | ||
971 | * @param tc the task context | ||
972 | */ | ||
973 | static void | ||
974 | handle_lookup_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
975 | { | ||
976 | struct ResolverHandle *rh = cls; | ||
977 | |||
978 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
979 | "Lookup timeout for request %llu triggered\n", | ||
980 | rh->id); | ||
981 | if (NULL != rh->timeout_cont) | ||
982 | rh->timeout_cont (rh->timeout_cont_cls, tc); | ||
983 | } | ||
984 | |||
985 | |||
986 | /** | ||
987 | * Processor for background lookups in the DHT | ||
988 | * | ||
989 | * @param cls closure (NULL) | ||
990 | * @param rd_count number of records found (not 0) | ||
991 | * @param rd record data | ||
992 | */ | ||
993 | static void | ||
994 | background_lookup_result_processor (void *cls, | ||
995 | uint32_t rd_count, | ||
996 | const struct GNUNET_NAMESTORE_RecordData *rd) | ||
997 | { | ||
998 | //We could do sth verbose/more useful here but it doesn't make any difference | ||
999 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1000 | "GNS_BG: background dht lookup finished. (%d results)\n", | ||
1001 | rd_count); | ||
1002 | } | ||
1003 | |||
1004 | |||
1005 | /** | ||
1006 | * Handle timeout for DHT requests | ||
1007 | * | ||
1008 | * @param cls the request handle as closure | ||
1009 | * @param tc the task context | ||
1010 | */ | ||
1011 | static void | ||
1012 | dht_lookup_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1013 | { | ||
1014 | struct ResolverHandle *rh = cls; | ||
1015 | struct RecordLookupHandle *rlh = rh->proc_cls; | ||
1016 | char new_name[GNUNET_DNSPARSER_MAX_NAME_LENGTH]; | ||
1017 | |||
1018 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1019 | "GNS_PHASE_REC-%llu: dht lookup for query %s (%s) timed out.\n", | ||
1020 | rh->id, rh->name, | ||
1021 | GNUNET_STRINGS_relative_time_to_string (rh->timeout, | ||
1022 | GNUNET_YES)); | ||
1023 | /** | ||
1024 | * Start resolution in bg | ||
1025 | */ | ||
1026 | GNUNET_snprintf (new_name, GNUNET_DNSPARSER_MAX_NAME_LENGTH, "%s.%s", | ||
1027 | rh->name, GNUNET_GNS_TLD); | ||
1028 | |||
1029 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1030 | "GNS_PHASE_REC-%llu: Starting background lookup for %s type %d\n", | ||
1031 | rh->id, new_name, rlh->record_type); | ||
1032 | |||
1033 | gns_resolver_lookup_record (rh->authority, | ||
1034 | rh->private_local_zone, | ||
1035 | rlh->record_type, | ||
1036 | new_name, | ||
1037 | NULL, | ||
1038 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1039 | GNUNET_NO, | ||
1040 | &background_lookup_result_processor, | ||
1041 | NULL); | ||
1042 | |||
1043 | rh->timeout_task = GNUNET_SCHEDULER_NO_TASK; | ||
1044 | |||
1045 | GNUNET_DHT_get_stop (rh->get_handle); | ||
1046 | rh->get_handle = NULL; | ||
1047 | rh->proc (rh->proc_cls, rh, 0, NULL); | ||
1048 | } | ||
1049 | |||
1050 | |||
1051 | /** | ||
1052 | * Function called when we get a result from the dht | 881 | * Function called when we get a result from the dht |
1053 | * for our record query | 882 | * for our record query |
1054 | * | 883 | * |
@@ -1474,325 +1303,6 @@ handle_record_vpn (void* cls, struct ResolverHandle *rh, | |||
1474 | 1303 | ||
1475 | 1304 | ||
1476 | /** | 1305 | /** |
1477 | * Sends a UDP dns query to a nameserver specified in the rh | ||
1478 | * | ||
1479 | * @param rh the resolver handle | ||
1480 | */ | ||
1481 | static void | ||
1482 | send_dns_packet (struct ResolverHandle *rh); | ||
1483 | |||
1484 | |||
1485 | /** | ||
1486 | * Read DNS response | ||
1487 | * | ||
1488 | * @param cls the ResolverHandle for this lookup | ||
1489 | * @param addr the sockaddr | ||
1490 | * @param addrlen the socket address length | ||
1491 | */ | ||
1492 | static void | ||
1493 | handle_dns_resolver (void *cls, | ||
1494 | const struct sockaddr *addr, | ||
1495 | socklen_t addrlen) | ||
1496 | { | ||
1497 | struct ResolverHandle *rh = cls; | ||
1498 | struct RecordLookupHandle *rlh = rh->proc_cls; | ||
1499 | struct GNUNET_NAMESTORE_RecordData rd; | ||
1500 | struct sockaddr_in *sai; | ||
1501 | struct sockaddr_in6 *sai6; | ||
1502 | |||
1503 | if (NULL == addr) | ||
1504 | { | ||
1505 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1506 | "No address found in DNS!\n"); | ||
1507 | finish_lookup (rh, rlh, 0, NULL); | ||
1508 | return; | ||
1509 | } | ||
1510 | |||
1511 | if (sizeof (struct sockaddr_in) == addrlen) | ||
1512 | { | ||
1513 | sai = (struct sockaddr_in*) addr; | ||
1514 | rd.record_type = GNUNET_DNSPARSER_TYPE_A; | ||
1515 | rd.data_size = sizeof (struct in_addr); | ||
1516 | rd.data = &sai->sin_addr; | ||
1517 | } | ||
1518 | else if (sizeof (struct sockaddr_in6) == addrlen) | ||
1519 | { | ||
1520 | sai6 = (struct sockaddr_in6*) addr; | ||
1521 | rd.record_type = GNUNET_DNSPARSER_TYPE_AAAA; | ||
1522 | rd.data_size = sizeof (struct in6_addr); | ||
1523 | rd.data = &sai6->sin6_addr; | ||
1524 | } | ||
1525 | else | ||
1526 | { | ||
1527 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1528 | "Address length is garbage!\n"); | ||
1529 | finish_lookup (rh, rlh, 0, NULL); | ||
1530 | return; | ||
1531 | } | ||
1532 | rd.expiration_time = UINT64_MAX; /* FIXME: should probably pick something shorter */ | ||
1533 | rd.flags = 0; | ||
1534 | finish_lookup (rh, rlh, 1, &rd); | ||
1535 | } | ||
1536 | |||
1537 | |||
1538 | /** | ||
1539 | * Resolve DNS name via local stub resolver | ||
1540 | * | ||
1541 | * @param rh the resolver handle | ||
1542 | */ | ||
1543 | static void | ||
1544 | resolve_dns_name (struct ResolverHandle *rh) | ||
1545 | { | ||
1546 | struct RecordLookupHandle *rlh = rh->proc_cls; | ||
1547 | int af; | ||
1548 | |||
1549 | if ((GNUNET_DNSPARSER_TYPE_A != rlh->record_type) && | ||
1550 | (GNUNET_DNSPARSER_TYPE_AAAA != rlh->record_type)) | ||
1551 | { | ||
1552 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1553 | "Can only resolve A/AAAA via stub... abort\n"); | ||
1554 | finish_lookup (rh, rlh, 0, NULL); | ||
1555 | return; | ||
1556 | } | ||
1557 | |||
1558 | if (GNUNET_DNSPARSER_TYPE_A == rlh->record_type) | ||
1559 | af = AF_INET; | ||
1560 | else | ||
1561 | af = AF_INET6; | ||
1562 | |||
1563 | rh->dns_resolver_handle = GNUNET_RESOLVER_ip_get (rh->dns_name, | ||
1564 | af, | ||
1565 | rh->timeout, | ||
1566 | &handle_dns_resolver, | ||
1567 | rh); | ||
1568 | } | ||
1569 | |||
1570 | |||
1571 | /** | ||
1572 | * Read DNS packet from UDP socket and process the reply. | ||
1573 | * | ||
1574 | * @param cls the resolver handle | ||
1575 | * @param tc task context | ||
1576 | */ | ||
1577 | static void | ||
1578 | read_dns_response (void *cls, | ||
1579 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1580 | { | ||
1581 | struct ResolverHandle *rh = cls; | ||
1582 | struct RecordLookupHandle *rlh = rh->proc_cls; | ||
1583 | char buf[UINT16_MAX]; | ||
1584 | ssize_t r; | ||
1585 | struct sockaddr_in addr; | ||
1586 | socklen_t addrlen; | ||
1587 | struct GNUNET_DNSPARSER_Packet *packet; | ||
1588 | struct GNUNET_NAMESTORE_RecordData rd; | ||
1589 | int found_delegation = GNUNET_NO; | ||
1590 | int found_cname = GNUNET_NO; | ||
1591 | char* delegation_name = NULL; | ||
1592 | int zone_offset = 0; | ||
1593 | int i; | ||
1594 | |||
1595 | rh->dns_read_task = GNUNET_SCHEDULER_NO_TASK; | ||
1596 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) | ||
1597 | { | ||
1598 | /* timeout or shutdown */ | ||
1599 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1600 | "Terminating DNS query %d\n", tc->reason); | ||
1601 | finish_lookup (rh, rlh, 0, NULL); | ||
1602 | return; | ||
1603 | } | ||
1604 | |||
1605 | addrlen = sizeof (addr); | ||
1606 | r = GNUNET_NETWORK_socket_recvfrom (rh->dns_sock, | ||
1607 | buf, sizeof (buf), | ||
1608 | (struct sockaddr*) &addr, | ||
1609 | &addrlen); | ||
1610 | |||
1611 | if (-1 == r) | ||
1612 | { | ||
1613 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "recvfrom"); | ||
1614 | finish_lookup (rh, rlh, 0, NULL); | ||
1615 | return; | ||
1616 | } | ||
1617 | if (NULL == (packet = GNUNET_DNSPARSER_parse (buf, r))) | ||
1618 | { | ||
1619 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1620 | "Failed to parse DNS reply!\n"); | ||
1621 | finish_lookup (rh, rlh, 0, NULL); | ||
1622 | return; | ||
1623 | } | ||
1624 | |||
1625 | for (i = 0; i < packet->num_answers; i++) | ||
1626 | { | ||
1627 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1628 | "Got record type %d (want %d)\n", | ||
1629 | packet->answers[i].type, | ||
1630 | rlh->record_type); | ||
1631 | /* http://tools.ietf.org/html/rfc1034#section-3.6.2 */ | ||
1632 | if (GNUNET_DNSPARSER_TYPE_CNAME == packet->answers[i].type) | ||
1633 | { | ||
1634 | struct GNUNET_DNSPARSER_Query query; | ||
1635 | struct GNUNET_DNSPARSER_Packet npacket; | ||
1636 | struct GNUNET_DNSPARSER_Flags flags; | ||
1637 | |||
1638 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1639 | "CNAME record, restarting query with `%s'\n", | ||
1640 | packet->answers[i].data.hostname); | ||
1641 | strcpy (rh->dns_name, | ||
1642 | packet->answers[i].data.hostname); | ||
1643 | found_cname = GNUNET_YES; | ||
1644 | query.name = rh->dns_name; | ||
1645 | query.type = rlh->record_type; | ||
1646 | query.class = GNUNET_DNSPARSER_CLASS_INTERNET; | ||
1647 | memset (&flags, 0, sizeof (flags)); | ||
1648 | flags.recursion_desired = 1; | ||
1649 | flags.checking_disabled = 1; | ||
1650 | npacket.queries = &query; | ||
1651 | npacket.answers = NULL; | ||
1652 | npacket.authority_records = NULL; | ||
1653 | npacket.additional_records = NULL; | ||
1654 | npacket.num_queries = 1; | ||
1655 | npacket.num_answers = 0; | ||
1656 | npacket.num_authority_records = 0; | ||
1657 | npacket.num_additional_records = 0; | ||
1658 | npacket.flags = flags; | ||
1659 | npacket.id = rh->id; | ||
1660 | GNUNET_free_non_null (rh->dns_raw_packet); | ||
1661 | rh->dns_raw_packet = NULL; | ||
1662 | if (GNUNET_OK != GNUNET_DNSPARSER_pack (&npacket, | ||
1663 | UINT16_MAX, | ||
1664 | &rh->dns_raw_packet, | ||
1665 | &rh->dns_raw_packet_size)) | ||
1666 | { | ||
1667 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1668 | "GNS_PHASE_REC_DNS-%llu: Creating raw dns packet!\n", | ||
1669 | rh->id); | ||
1670 | GNUNET_NETWORK_socket_close (rh->dns_sock); | ||
1671 | finish_lookup (rh, rlh, 0, NULL); | ||
1672 | GNUNET_DNSPARSER_free_packet (packet); | ||
1673 | return; | ||
1674 | } | ||
1675 | continue; | ||
1676 | } | ||
1677 | |||
1678 | if ((packet->answers[i].type == rlh->record_type) && | ||
1679 | (0 == strcmp (packet->answers[i].name, rh->dns_name))) | ||
1680 | { | ||
1681 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1682 | "Found record!\n"); | ||
1683 | rd.data = packet->answers[i].data.raw.data; | ||
1684 | rd.data_size = packet->answers[i].data.raw.data_len; | ||
1685 | rd.record_type = packet->answers[i].type; | ||
1686 | rd.flags = 0; | ||
1687 | rd.expiration_time = packet->answers[i].expiration_time.abs_value_us; | ||
1688 | finish_lookup (rh, rlh, 1, &rd); | ||
1689 | GNUNET_DNSPARSER_free_packet (packet); | ||
1690 | return; | ||
1691 | } | ||
1692 | } | ||
1693 | |||
1694 | if (GNUNET_YES == found_cname) | ||
1695 | { | ||
1696 | zone_offset = strlen (rh->dns_name) - strlen (rh->dns_zone) - 1; | ||
1697 | if (0 > zone_offset) | ||
1698 | zone_offset = 0; | ||
1699 | |||
1700 | /* restart query with CNAME */ | ||
1701 | if (0 == strcmp (rh->dns_name + zone_offset, rh->dns_zone)) | ||
1702 | { | ||
1703 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1704 | "Asking DNS server for `%s'\n", | ||
1705 | rh->dns_name); | ||
1706 | |||
1707 | send_dns_packet (rh); | ||
1708 | } | ||
1709 | else | ||
1710 | { | ||
1711 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1712 | "Trying system resolver for `%s'\n", rh->dns_name); | ||
1713 | resolve_dns_name (rh); | ||
1714 | } | ||
1715 | |||
1716 | GNUNET_DNSPARSER_free_packet (packet); | ||
1717 | return; | ||
1718 | } | ||
1719 | |||
1720 | for (i = 0; i < packet->num_authority_records; i++) | ||
1721 | { | ||
1722 | if (packet->authority_records[i].type == GNUNET_DNSPARSER_TYPE_NS) | ||
1723 | { | ||
1724 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1725 | "Found NS delegation!\n"); | ||
1726 | found_delegation = GNUNET_YES; | ||
1727 | delegation_name = packet->authority_records[i].data.hostname; | ||
1728 | break; | ||
1729 | } | ||
1730 | } | ||
1731 | |||
1732 | for (i = 0; i < packet->num_additional_records; i++) | ||
1733 | { | ||
1734 | if (GNUNET_NO == found_delegation) | ||
1735 | break; | ||
1736 | |||
1737 | if ((packet->additional_records[i].type == GNUNET_DNSPARSER_TYPE_A) && | ||
1738 | (0 == strcmp (packet->additional_records[i].name, delegation_name))) | ||
1739 | { | ||
1740 | GNUNET_assert (sizeof (struct in_addr) == | ||
1741 | packet->authority_records[i].data.raw.data_len); | ||
1742 | |||
1743 | rh->dns_addr.sin_addr = | ||
1744 | *((struct in_addr*)packet->authority_records[i].data.raw.data); | ||
1745 | send_dns_packet (rh); | ||
1746 | GNUNET_DNSPARSER_free_packet (packet); | ||
1747 | return; | ||
1748 | } | ||
1749 | } | ||
1750 | |||
1751 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1752 | "Nothing useful in DNS reply!\n"); | ||
1753 | finish_lookup (rh, rlh, 0, NULL); | ||
1754 | GNUNET_DNSPARSER_free_packet (packet); | ||
1755 | } | ||
1756 | |||
1757 | |||
1758 | /** | ||
1759 | * Sends a UDP dns query to a nameserver specified in the rh | ||
1760 | * | ||
1761 | * @param rh the request handle | ||
1762 | */ | ||
1763 | static void | ||
1764 | send_dns_packet (struct ResolverHandle *rh) | ||
1765 | { | ||
1766 | struct GNUNET_NETWORK_FDSet *rset; | ||
1767 | |||
1768 | rset = GNUNET_NETWORK_fdset_create (); | ||
1769 | GNUNET_NETWORK_fdset_set (rset, rh->dns_sock); | ||
1770 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1771 | "Sending %d byte DNS query\n", | ||
1772 | (int) rh->dns_raw_packet_size); | ||
1773 | |||
1774 | if (GNUNET_SYSERR == | ||
1775 | GNUNET_NETWORK_socket_sendto (rh->dns_sock, | ||
1776 | rh->dns_raw_packet, | ||
1777 | rh->dns_raw_packet_size, | ||
1778 | (struct sockaddr*)&rh->dns_addr, | ||
1779 | sizeof (struct sockaddr_in))) | ||
1780 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1781 | _("Failed to send DNS request to %s\n"), | ||
1782 | GNUNET_a2s ((const struct sockaddr *)&rh->dns_addr, | ||
1783 | sizeof (struct sockaddr_in))); | ||
1784 | |||
1785 | rh->dns_read_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | ||
1786 | rh->timeout, //FIXME less? | ||
1787 | rset, | ||
1788 | NULL, | ||
1789 | &read_dns_response, | ||
1790 | rh); | ||
1791 | GNUNET_NETWORK_fdset_destroy (rset); | ||
1792 | } | ||
1793 | |||
1794 | |||
1795 | /** | ||
1796 | * The final phase of resoution. | 1306 | * The final phase of resoution. |
1797 | * We found a NS RR and want to resolve via DNS | 1307 | * We found a NS RR and want to resolve via DNS |
1798 | * | 1308 | * |
@@ -2116,39 +1626,6 @@ dht_authority_lookup_timeout (void *cls, | |||
2116 | 1626 | ||
2117 | 1627 | ||
2118 | /** | 1628 | /** |
2119 | * Start DHT lookup for a name -> PKEY (compare NS) record in | ||
2120 | * rh->authority's zone | ||
2121 | * | ||
2122 | * @param rh the pending gns query | ||
2123 | */ | ||
2124 | static void | ||
2125 | resolve_delegation_dht (struct ResolverHandle *rh); | ||
2126 | |||
2127 | |||
2128 | /** | ||
2129 | * Resolve the delegation chain for the request in our namestore | ||
2130 | * | ||
2131 | * @param rh the resolver handle | ||
2132 | */ | ||
2133 | static void | ||
2134 | resolve_delegation_ns (struct ResolverHandle *rh); | ||
2135 | |||
2136 | |||
2137 | /** | ||
2138 | * Namestore resolution for delegation finished. Processing result. | ||
2139 | * | ||
2140 | * @param cls the closure | ||
2141 | * @param rh resolver handle | ||
2142 | * @param rd_count number of results (always 0) | ||
2143 | * @param rd record data (always NULL) | ||
2144 | */ | ||
2145 | static void | ||
2146 | handle_delegation_ns (void* cls, struct ResolverHandle *rh, | ||
2147 | unsigned int rd_count, | ||
2148 | const struct GNUNET_NAMESTORE_RecordData *rd); | ||
2149 | |||
2150 | |||
2151 | /** | ||
2152 | * This is a callback function that checks for key revocation | 1629 | * This is a callback function that checks for key revocation |
2153 | * | 1630 | * |
2154 | * @param cls the pending query | 1631 | * @param cls the pending query |
@@ -2233,7 +1710,7 @@ process_pkey_revocation_result_ns (void *cls, | |||
2233 | * @param success GNUNET_OK on success | 1710 | * @param success GNUNET_OK on success |
2234 | * @param emsg the error message. NULL if SUCCESS==GNUNET_OK | 1711 | * @param emsg the error message. NULL if SUCCESS==GNUNET_OK |
2235 | */ | 1712 | */ |
2236 | void | 1713 | static void |
2237 | on_namestore_delegation_put_result(void *cls, | 1714 | on_namestore_delegation_put_result(void *cls, |
2238 | int32_t success, | 1715 | int32_t success, |
2239 | const char *emsg) | 1716 | const char *emsg) |
@@ -2941,27 +2418,6 @@ resolve_delegation_dht (struct ResolverHandle *rh) | |||
2941 | 2418 | ||
2942 | 2419 | ||
2943 | /** | 2420 | /** |
2944 | * Checks if "name" ends in ".tld" | ||
2945 | * | ||
2946 | * @param name the name to check | ||
2947 | * @param tld the TLD to check for | ||
2948 | * @return GNUNET_YES or GNUNET_NO | ||
2949 | */ | ||
2950 | int | ||
2951 | is_tld (const char* name, const char* tld) | ||
2952 | { | ||
2953 | size_t offset = 0; | ||
2954 | |||
2955 | if (strlen (name) <= strlen (tld)) | ||
2956 | return GNUNET_NO; | ||
2957 | offset = strlen (name) - strlen (tld); | ||
2958 | if (0 != strcmp (name + offset, tld)) | ||
2959 | return GNUNET_NO; | ||
2960 | return GNUNET_YES; | ||
2961 | } | ||
2962 | |||
2963 | |||
2964 | /** | ||
2965 | * Namestore resolution for delegation finished. Processing result. | 2421 | * Namestore resolution for delegation finished. Processing result. |
2966 | * | 2422 | * |
2967 | * @param cls the closure | 2423 | * @param cls the closure |
@@ -3433,28 +2889,33 @@ resolve_delegation_ns (struct ResolverHandle *rh) | |||
3433 | rh); | 2889 | rh); |
3434 | } | 2890 | } |
3435 | 2891 | ||
2892 | #endif | ||
2893 | |||
2894 | |||
3436 | 2895 | ||
3437 | /** | 2896 | /** |
3438 | * Lookup of a record in a specific zone | 2897 | * Lookup of a record in a specific zone calls lookup result processor |
3439 | * calls lookup result processor on result | 2898 | * on result. |
3440 | * | 2899 | * |
3441 | * @param zone the root zone | 2900 | * @param zone the zone to perform the lookup in |
3442 | * @param record_type the record type to look up | 2901 | * @param record_type the record type to look up |
3443 | * @param name the name to look up | 2902 | * @param name the name to look up |
3444 | * @param shorten_key a private key for use with PSEU import (can be NULL) | 2903 | * @param shorten_key a private key for use with PSEU import (can be NULL) |
3445 | * @param only_cached GNUNET_NO to only check locally not DHT for performance | 2904 | * @param only_cached GNUNET_NO to only check locally not DHT for performance |
3446 | * @param proc the processor to call on result | 2905 | * @param proc the processor to call on result |
3447 | * @param proc_cls the closure to pass to @a proc | 2906 | * @param proc_cls the closure to pass to @a proc |
2907 | * @return handle to cancel operation | ||
3448 | */ | 2908 | */ |
3449 | void | 2909 | struct GNS_ResolverHandle * |
3450 | GNS_resolver_lookup (const struct GNUNET_CRYPTO_EccPublicKey * zone, | 2910 | GNS_resolver_lookup (const struct GNUNET_CRYPTO_EccPublicKey *zone, |
3451 | uint32_t record_type, | 2911 | uint32_t record_type, |
3452 | const char* name, | 2912 | const char *name, |
3453 | struct GNUNET_CRYPTO_EccPrivateKey *shorten_key, | 2913 | const struct GNUNET_CRYPTO_EccPrivateKey *shorten_key, |
3454 | int only_cached, | 2914 | int only_cached, |
3455 | RecordLookupProcessor proc, | 2915 | GNS_ResultProcessor proc, void *proc_cls) |
3456 | void *proc_cls) | ||
3457 | { | 2916 | { |
2917 | return NULL; | ||
2918 | #if 0 | ||
3458 | struct ResolverHandle *rh; | 2919 | struct ResolverHandle *rh; |
3459 | struct RecordLookupHandle* rlh; | 2920 | struct RecordLookupHandle* rlh; |
3460 | char string_hash[GNUNET_DNSPARSER_MAX_LABEL_LENGTH]; | 2921 | char string_hash[GNUNET_DNSPARSER_MAX_LABEL_LENGTH]; |
@@ -3601,7 +3062,101 @@ GNS_resolver_lookup (const struct GNUNET_CRYPTO_EccPublicKey * zone, | |||
3601 | 3062 | ||
3602 | rh->proc = &handle_delegation_ns; | 3063 | rh->proc = &handle_delegation_ns; |
3603 | resolve_delegation_ns (rh); | 3064 | resolve_delegation_ns (rh); |
3065 | #endif | ||
3604 | } | 3066 | } |
3605 | 3067 | ||
3606 | 3068 | ||
3069 | |||
3070 | /** | ||
3071 | * Cancel active resolution (i.e. client disconnected). | ||
3072 | * | ||
3073 | * @param h resolution to abort | ||
3074 | */ | ||
3075 | void | ||
3076 | GNS_resolver_lookup_cancel (struct GNS_ResolverHandle *h) | ||
3077 | { | ||
3078 | } | ||
3079 | |||
3080 | |||
3081 | /* ***************** Resolver initialization ********************* */ | ||
3082 | |||
3083 | |||
3084 | /** | ||
3085 | * Initialize the resolver | ||
3086 | * | ||
3087 | * @param nh the namestore handle | ||
3088 | * @param dh the dht handle | ||
3089 | * @param c configuration handle | ||
3090 | * @param max_bg_queries maximum number of parallel background queries in dht | ||
3091 | * @param ignore_pending ignore records that still require user confirmation | ||
3092 | * on lookup | ||
3093 | */ | ||
3094 | void | ||
3095 | GNS_resolver_init (struct GNUNET_NAMESTORE_Handle *nh, | ||
3096 | struct GNUNET_DHT_Handle *dh, | ||
3097 | const struct GNUNET_CONFIGURATION_Handle *c, | ||
3098 | unsigned long long max_bg_queries) | ||
3099 | { | ||
3100 | char *dns_ip; | ||
3101 | |||
3102 | cfg = c; | ||
3103 | namestore_handle = nh; | ||
3104 | dht_handle = dh; | ||
3105 | dht_lookup_heap = | ||
3106 | GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | ||
3107 | max_allowed_background_queries = max_bg_queries; | ||
3108 | if (GNUNET_OK != | ||
3109 | GNUNET_CONFIGURATION_get_value_string (c, | ||
3110 | "gns", | ||
3111 | "DNS_RESOLVER", | ||
3112 | &dns_ip)) | ||
3113 | { | ||
3114 | /* user did not specify DNS resolver, use 8.8.8.8 */ | ||
3115 | dns_ip = GNUNET_strdup ("8.8.8.8"); | ||
3116 | } | ||
3117 | dns_handle = GNUNET_DNSSTUB_start (dns_ip); | ||
3118 | GNUNET_free (dns_ip); | ||
3119 | } | ||
3120 | |||
3121 | |||
3122 | /** | ||
3123 | * Shutdown resolver | ||
3124 | */ | ||
3125 | void | ||
3126 | GNS_resolver_done () | ||
3127 | { | ||
3128 | while (NULL != gph_head) | ||
3129 | free_get_pseu_authority_handle (gph_head); | ||
3130 | GNUNET_CONTAINER_heap_destroy (dht_lookup_heap); | ||
3131 | dht_lookup_heap = NULL; | ||
3132 | GNUNET_DNSSTUB_stop (dns_handle); | ||
3133 | dns_handle = NULL; | ||
3134 | } | ||
3135 | |||
3136 | |||
3137 | /* *************** common helper functions (do not really belong here) *********** */ | ||
3138 | |||
3139 | /** | ||
3140 | * Checks if "name" ends in ".tld" | ||
3141 | * | ||
3142 | * @param name the name to check | ||
3143 | * @param tld the TLD to check for | ||
3144 | * @return GNUNET_YES or GNUNET_NO | ||
3145 | */ | ||
3146 | int | ||
3147 | is_tld (const char* name, const char* tld) | ||
3148 | { | ||
3149 | size_t offset = 0; | ||
3150 | |||
3151 | if (strlen (name) <= strlen (tld)) | ||
3152 | return GNUNET_NO; | ||
3153 | offset = strlen (name) - strlen (tld); | ||
3154 | if (0 != strcmp (name + offset, tld)) | ||
3155 | return GNUNET_NO; | ||
3156 | return GNUNET_YES; | ||
3157 | } | ||
3158 | |||
3159 | |||
3160 | |||
3161 | |||
3607 | /* end of gnunet-service-gns_resolver.c */ | 3162 | /* end of gnunet-service-gns_resolver.c */ |
diff --git a/src/gns/gnunet-service-gns_resolver.h b/src/gns/gnunet-service-gns_resolver.h index bc83b6b3d..7ee545e2b 100644 --- a/src/gns/gnunet-service-gns_resolver.h +++ b/src/gns/gnunet-service-gns_resolver.h | |||
@@ -36,16 +36,12 @@ | |||
36 | * @param dht handle to the dht | 36 | * @param dht handle to the dht |
37 | * @param c configuration handle | 37 | * @param c configuration handle |
38 | * @param max_bg_queries maximum amount of background queries | 38 | * @param max_bg_queries maximum amount of background queries |
39 | * @param ignore_pending ignore records that still require user confirmation | ||
40 | * on lookup | ||
41 | * @returns GNUNET_OK on success | ||
42 | */ | 39 | */ |
43 | int | 40 | void |
44 | GNS_resolver_init (struct GNUNET_NAMESTORE_Handle *nh, | 41 | GNS_resolver_init (struct GNUNET_NAMESTORE_Handle *nh, |
45 | struct GNUNET_DHT_Handle *dht, | 42 | struct GNUNET_DHT_Handle *dht, |
46 | const struct GNUNET_CONFIGURATION_Handle *c, | 43 | const struct GNUNET_CONFIGURATION_Handle *c, |
47 | unsigned long long max_bg_queries, | 44 | unsigned long long max_bg_queries); |
48 | int ignore_pending); | ||
49 | 45 | ||
50 | 46 | ||
51 | /** | 47 | /** |
@@ -84,6 +80,7 @@ typedef void (*GNS_ResultProcessor)(void *cls, | |||
84 | * @param only_cached GNUNET_NO to only check locally not DHT for performance | 80 | * @param only_cached GNUNET_NO to only check locally not DHT for performance |
85 | * @param proc the processor to call | 81 | * @param proc the processor to call |
86 | * @param proc_cls the closure to pass to @a proc | 82 | * @param proc_cls the closure to pass to @a proc |
83 | * @return handle to cancel operation | ||
87 | */ | 84 | */ |
88 | struct GNS_ResolverHandle * | 85 | struct GNS_ResolverHandle * |
89 | GNS_resolver_lookup (const struct GNUNET_CRYPTO_EccPublicKey *zone, | 86 | GNS_resolver_lookup (const struct GNUNET_CRYPTO_EccPublicKey *zone, |
diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h index c9eb004e1..986e957ec 100644 --- a/src/include/gnunet_namestore_service.h +++ b/src/include/gnunet_namestore_service.h | |||
@@ -656,13 +656,24 @@ GNUNET_NAMESTORE_block_verify (const struct GNUNET_NAMESTORE_Block *block); | |||
656 | 656 | ||
657 | 657 | ||
658 | /** | 658 | /** |
659 | * Process a records that were decrypted from a block. | ||
660 | * | ||
661 | * @param cls closure | ||
662 | * @param rd_count number of entries in @a rd array | ||
663 | * @param rd array of records with data to store | ||
664 | */ | ||
665 | typedef void (*GNUNET_NAMESTORE_RecordCallback) (void *cls, | ||
666 | unsigned int rd_count, | ||
667 | const struct GNUNET_NAMESTORE_RecordData *rd); | ||
668 | |||
669 | /** | ||
659 | * Decrypt block. | 670 | * Decrypt block. |
660 | * | 671 | * |
661 | * @param block block to decrypt | 672 | * @param block block to decrypt |
662 | * @param zone_key public key of the zone | 673 | * @param zone_key public key of the zone |
663 | * @param label the name for the records | 674 | * @param label the name for the records |
664 | * @param proc function to call with the result | 675 | * @param proc function to call with the result |
665 | * @param proc_cls closure for proc | 676 | * @param proc_cls closure for @a proc |
666 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the block was | 677 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the block was |
667 | * not well-formed | 678 | * not well-formed |
668 | */ | 679 | */ |
@@ -670,7 +681,7 @@ int | |||
670 | GNUNET_NAMESTORE_block_decrypt (const struct GNUNET_NAMESTORE_Block *block, | 681 | GNUNET_NAMESTORE_block_decrypt (const struct GNUNET_NAMESTORE_Block *block, |
671 | const struct GNUNET_CRYPTO_EccPublicKey *zone_key, | 682 | const struct GNUNET_CRYPTO_EccPublicKey *zone_key, |
672 | const char *label, | 683 | const char *label, |
673 | GNUNET_NAMESTORE_RecordMonitor proc, | 684 | GNUNET_NAMESTORE_RecordCallback proc, |
674 | void *proc_cls); | 685 | void *proc_cls); |
675 | 686 | ||
676 | 687 | ||
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index eeb2bb65d..6cd0334c4 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -29,7 +29,7 @@ | |||
29 | * our own queries as our lookup only goes for the encrypted | 29 | * our own queries as our lookup only goes for the encrypted |
30 | * records; we need a way to ensure that the records available | 30 | * records; we need a way to ensure that the records available |
31 | * in our own zone can actually always be used for our own | 31 | * in our own zone can actually always be used for our own |
32 | * resolutions! | 32 | * resolutions! (#2993) |
33 | */ | 33 | */ |
34 | #include "platform.h" | 34 | #include "platform.h" |
35 | #include "gnunet_util_lib.h" | 35 | #include "gnunet_util_lib.h" |