2 This file is part of GNUnet.
3 (C) 2009, 2010, 2011, 2012 Christian Grothoff (and other contributing authors)
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
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file gns/gnunet-service-gns_resolver.h
22 * @brief GNUnet GNS service
23 * @author Martin Schanzenbach
25 #ifndef GNS_RESOLVER_H
26 #define GNS_RESOLVER_H
29 #include "gnunet_dht_service.h"
31 #define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
33 #define GNUNET_GNS_DEFAULT_LOOKUP_TIMEOUT \
34 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
36 #define DHT_LOOKUP_TIMEOUT DHT_OPERATION_TIMEOUT
38 #define DHT_GNS_REPLICATION_LEVEL 5
40 #define GNUNET_GNS_MAX_PARALLEL_LOOKUPS 500
42 #define GNUNET_GNS_MAX_NS_TASKS 500
45 * DLL to hold the authority chain
46 * we had to pass in the resolution process
50 struct AuthorityChain *prev;
52 struct AuthorityChain *next;
55 * the zone hash of the authority
57 struct GNUNET_CRYPTO_ShortHashCode zone;
60 * (local) name of the authority
62 char name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
65 * was the ns entry fresh
72 * handle to a resolution process
74 struct ResolverHandle;
78 * processor for a record lookup result
80 * @param cls the closure
81 * @param rd_count number of results
82 * @param rd result data
84 typedef void (*RecordLookupProcessor) (void *cls,
86 const struct GNUNET_NAMESTORE_RecordData *rd);
90 * processor for a shorten result
92 * @param cls the closure
93 * @param name shortened name
95 typedef void (*ShortenResultProcessor) (void *cls,
100 * processor for an authority result
102 * @param cls the closure
103 * @param name name of the authority
105 typedef void (*GetAuthorityResultProcessor) (void *cls,
109 * processor for a resolution result
111 * @param cls the closure
112 * @param rh the resolution handle
113 * @param rd_count number of results
114 * @param rd result data (array of 'rd_count' records)
116 typedef void (*ResolutionResultProcessor) (void *cls,
117 struct ResolverHandle *rh,
119 const struct GNUNET_NAMESTORE_RecordData *rd);
123 * Resolution status indicator
125 enum ResolutionStatus
128 * the name to lookup exists
130 RSL_RECORD_EXISTS = 1,
133 * the name in the record expired
135 RSL_RECORD_EXPIRED = 2,
138 * resolution timed out
143 * Found VPN delegation
145 RSL_DELEGATE_VPN = 8,
148 * Found NS delegation
150 RSL_DELEGATE_NS = 16,
153 * Found PKEY delegation
155 RSL_DELEGATE_PKEY = 32,
160 RSL_CNAME_FOUND = 64,
163 * Found PKEY has been revoked
165 RSL_PKEY_REVOKED = 128
169 * Handle to a currenty pending resolution
170 * a ResolverHandle is passed to, for example
171 * resolve_record_ns to resolve a record in the namestore.
172 * On result (positive or negative) the ResolutionResultProcessor
174 * If a timeout is set timeout_cont will be called.
175 * If no timeout is set (ie timeout forever) then background resolutions
176 * might be triggered.
178 struct ResolverHandle
184 struct ResolverHandle *next;
189 struct ResolverHandle *prev;
192 * Last record data found
194 struct GNUNET_NAMESTORE_RecordData rd;
197 * Number of last record data found
199 unsigned int rd_count;
202 * The name to resolve
204 char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
207 * has this query been answered? how many matches
217 * the authoritative zone to query
219 struct GNUNET_CRYPTO_ShortHashCode authority;
222 * the name of the authoritative zone to query
224 char authority_name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
227 * a handle for dht lookups. should be NULL if no lookups are in progress
229 struct GNUNET_DHT_GetHandle *get_handle;
232 * timeout set for this lookup task
234 struct GNUNET_TIME_Relative timeout;
237 * a handle to a vpn request
239 struct GNUNET_VPN_RedirectionRequest *vpn_handle;
242 * a socket for a dns request
244 struct GNUNET_NETWORK_Handle *dns_sock;
247 * a synthesized dns name
249 char dns_name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
252 * the authoritative dns zone
254 char dns_zone[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
257 * the address of the DNS server FIXME not needed?
259 struct sockaddr_in dns_addr;
262 * handle to the local stub resolver request
264 struct GNUNET_RESOLVER_RequestHandle *dns_resolver_handle;
267 * select task for DNS
269 GNUNET_SCHEDULER_TaskIdentifier dns_read_task;
272 * pointer to raw dns query payload FIXME needs to be freed/NULL
274 char *dns_raw_packet;
277 * size of the raw dns query
279 size_t dns_raw_packet_size;
282 * timeout task for the lookup
284 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
287 * continuation to call on timeout
289 GNUNET_SCHEDULER_Task timeout_cont;
292 * closure for timeout cont
294 void* timeout_cont_cls;
297 * called when resolution phase finishes
299 ResolutionResultProcessor proc;
302 * closure passed to proc
307 * DLL to store the authority chain
309 struct AuthorityChain *authority_chain_head;
312 * DLL to store the authority chain
314 struct AuthorityChain *authority_chain_tail;
317 * status of the resolution result
319 enum ResolutionStatus status;
322 * The provate local zone of this request
324 struct GNUNET_CRYPTO_ShortHashCode private_local_zone;
327 * private key of an/our authoritative zone
328 * can be NULL but automatical PKEY import will not work
330 struct GNUNET_CRYPTO_RsaPrivateKey *priv_key;
333 * the heap node associated with this lookup, null if timeout is set
334 * used for DHT background lookups.
336 struct GNUNET_CONTAINER_HeapNode *dht_heap_node;
339 * Id for resolution process
341 unsigned long long id;
344 * Pending Namestore task
346 struct GNUNET_NAMESTORE_QueueEntry *namestore_task;
352 * Handle to a record lookup
354 struct RecordLookupHandle
357 * the record type to look up
359 enum GNUNET_GNS_RecordType record_type;
362 * the name to look up
364 char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
367 * Method to call on record resolution result
369 RecordLookupProcessor proc;
372 * closure to pass to proc
380 * Handle to a shorten context
382 struct NameShortenHandle
385 * Method to call on shorten result
387 ShortenResultProcessor proc;
390 * closure to pass to proc
397 char result[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
402 struct GNUNET_CRYPTO_ShortHashCode *root_zone;
407 struct GNUNET_CRYPTO_ShortHashCode *private_zone;
410 * name of private zone
412 char private_zone_name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
417 struct GNUNET_CRYPTO_ShortHashCode *shorten_zone;
420 * name of shorten zone
422 char shorten_zone_name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
428 * Handle to a get authority context
430 struct GetNameAuthorityHandle
433 * the name to look up authority for
435 char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
440 char result[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
443 * Method to call on result
445 GetAuthorityResultProcessor proc;
448 * closure to pass to proc
455 * Handle to a pseu lookup
457 struct GetPseuAuthorityHandle
462 struct GetPseuAuthorityHandle *next;
467 struct GetPseuAuthorityHandle *prev;
470 * the name to store the zone under
472 char name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
475 * test name to store the zone under
477 char test_name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
480 * the zone of our authority
482 struct GNUNET_CRYPTO_ShortHashCode our_zone;
485 * the private key of the zone to store the pseu in
487 struct GNUNET_CRYPTO_RsaPrivateKey *key;
490 * a handle for dht lookups. should be NULL if no lookups are in progress
492 struct GNUNET_DHT_GetHandle *get_handle;
495 * timeout task for lookup
497 GNUNET_SCHEDULER_TaskIdentifier timeout;
500 * Authority to shorten
502 struct AuthorityChain *auth;
505 * handle to namestore request
507 struct GNUNET_NAMESTORE_QueueEntry* namestore_task;
512 * Namestore queue entries in background
514 struct NamestoreBGTask
519 struct GNUNET_CONTAINER_HeapNode *node;
524 struct GNUNET_NAMESTORE_QueueEntry *qe;
529 * Initialize the resolver
530 * MUST be called before other gns_resolver_* methods
532 * @param nh handle to the namestore
533 * @param dh handle to the dht
534 * @param lz the local zone
535 * @param c configuration handle
536 * @param max_bg_queries maximum amount of background queries
537 * @param ignore_pending ignore records that still require user confirmation
539 * @returns GNUNET_OK on success
542 gns_resolver_init (struct GNUNET_NAMESTORE_Handle *nh,
543 struct GNUNET_DHT_Handle *dh,
544 struct GNUNET_CRYPTO_ShortHashCode lz,
545 const struct GNUNET_CONFIGURATION_Handle *c,
546 unsigned long long max_bg_queries,
551 * Cleanup resolver: Terminate pending lookups
554 gns_resolver_cleanup (void);
558 * Lookup of a record in a specific zone
559 * calls RecordLookupProcessor on result or timeout
561 * @param zone the root zone
562 * @param pzone the private local zone
563 * @param record_type the record type to look up
564 * @param name the name to look up
565 * @param key optional private key for authority caching
566 * @param timeout timeout for the resolution
567 * @param only_cached GNUNET_NO to only check locally not DHT for performance
568 * @param proc the processor to call
569 * @param cls the closure to pass to proc
572 gns_resolver_lookup_record (struct GNUNET_CRYPTO_ShortHashCode zone,
573 struct GNUNET_CRYPTO_ShortHashCode pzone,
574 uint32_t record_type,
576 struct GNUNET_CRYPTO_RsaPrivateKey *key,
577 struct GNUNET_TIME_Relative timeout,
579 RecordLookupProcessor proc,
584 * Shortens a name if possible. If the shortening fails
585 * name will be returned as shortened string. Else
586 * a shorter version of the name will be returned.
587 * There is no guarantee that the shortened name will
588 * actually be canonical/short etc.
590 * @param zone the root zone to use
591 * @param pzone the private zone to use
592 * @param szone the shorten zone to use
593 * @param name name to shorten
594 * @param private_zone_name name of the private zone
595 * @param shorten_zone_name name of the shorten zone
596 * @param proc the processor to call on shorten result
597 * @param proc_cls the closure to pass to proc
600 gns_resolver_shorten_name (struct GNUNET_CRYPTO_ShortHashCode *zone,
601 struct GNUNET_CRYPTO_ShortHashCode *pzone,
602 struct GNUNET_CRYPTO_ShortHashCode *szone,
604 const char* private_zone_name,
605 const char* shorten_zone_name,
606 ShortenResultProcessor proc,
611 * Tries to resolve the authority for name
614 * @param zone the root zone to look up for
615 * @param pzone the private local zone
616 * @param name the name to lookup up
617 * @param proc the processor to call when finished
618 * @param proc_cls the closure to pass to the processor
621 gns_resolver_get_authority (struct GNUNET_CRYPTO_ShortHashCode zone,
622 struct GNUNET_CRYPTO_ShortHashCode pzone,
624 GetAuthorityResultProcessor proc,
628 * Generic function to check for TLDs
630 * @param name the name to check
631 * @param tld the tld to check
632 * @return GNUNET_YES or GNUNET_NO
635 is_tld (const char* name,
640 * Checks for gads/zkey
642 #define is_gads_tld(name) is_tld(name, GNUNET_GNS_TLD)
643 #define is_zkey_tld(name) is_tld(name, GNUNET_GNS_TLD_ZKEY)