5 #include "gnunet_dht_service.h"
7 #define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
8 #define GNUNET_GNS_DEFAULT_LOOKUP_TIMEOUT \
9 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
10 #define DHT_LOOKUP_TIMEOUT DHT_OPERATION_TIMEOUT
11 #define DHT_GNS_REPLICATION_LEVEL 5
13 #define GNUNET_GNS_MAX_PARALLEL_LOOKUPS 500
14 #define GNUNET_GNS_MAX_NS_TASKS 500
17 * DLL to hold the authority chain
18 * we had to pass in the resolution process
22 struct AuthorityChain *prev;
24 struct AuthorityChain *next;
26 /* the zone hash of the authority */
27 struct GNUNET_CRYPTO_ShortHashCode zone;
29 /* (local) name of the authority */
30 char name[MAX_DNS_LABEL_LENGTH];
32 /* was the ns entry fresh */
36 /* handle to a resolution process */
37 struct ResolverHandle;
40 * continuation called when cleanup of resolver finishes
42 typedef void (*ResolverCleanupContinuation) (void);
45 * processor for a record lookup result
47 * @param cls the closure
48 * @param rd_count number of results
49 * @param rd result data
51 typedef void (*RecordLookupProcessor) (void *cls,
53 const struct GNUNET_NAMESTORE_RecordData *rd);
57 * processor for a shorten result
59 * @param cls the closure
60 * @param name shortened name
62 typedef void (*ShortenResultProcessor) (void *cls, const char* name);
66 * processor for an authority result
68 * @param cls the closure
71 typedef void (*GetAuthorityResultProcessor) (void *cls, const char* name);
74 * processor for a resolution result
76 * @param cls the closure
77 * @param rh the resolution handle
78 * @param rd_count number of results
79 * @param rd result data
81 typedef void (*ResolutionResultProcessor) (void *cls,
82 struct ResolverHandle *rh,
84 const struct GNUNET_NAMESTORE_RecordData *rd);
88 * Resolution status indicator
89 * RSL_RECORD_EXISTS: the name to lookup exists
90 * RSL_RECORD_EXPIRED: the name in the record expired
91 * RSL_TIMED_OUT: resolution timed out
92 * RSL_DELEGATE_VPN: Found VPN delegation
93 * RSL_DELEGATE_NS: Found NS delegation
94 * RSL_DELEGATE_PKEY: Found PKEY delegation
95 * RSL_CNAME_FOUND: Found CNAME record
96 * RSL_PKEY_REVOKED: Found PKEY has been revoked
100 RSL_RECORD_EXISTS = 1,
101 RSL_RECORD_EXPIRED = 2,
103 RSL_DELEGATE_VPN = 8,
104 RSL_DELEGATE_NS = 16,
105 RSL_DELEGATE_PKEY = 32,
106 RSL_CNAME_FOUND = 64,
107 RSL_PKEY_REVOKED = 128
111 * Handle to a currenty pending resolution
112 * a ResolverHandle is passed to, for example
113 * resolve_record_ns to resolve a record in the namestore.
114 * On result (positive or negative) the ResolutionResultProcessor
116 * If a timeout is set timeout_cont will be called.
117 * If no timeout is set (ie timeout forever) then background resolutions
118 * might be triggered.
120 struct ResolverHandle
124 struct ResolverHandle *next;
127 struct ResolverHandle *prev;
129 /* The name to resolve */
130 char name[MAX_DNS_NAME_LENGTH];
132 /* has this query been answered? how many matches */
138 /* the authoritative zone to query */
139 struct GNUNET_CRYPTO_ShortHashCode authority;
141 /* the name of the authoritative zone to query */
142 char authority_name[MAX_DNS_LABEL_LENGTH];
144 /* a handle for dht lookups. should be NULL if no lookups are in progress */
145 struct GNUNET_DHT_GetHandle *get_handle;
147 /* timeout set for this lookup task */
148 struct GNUNET_TIME_Relative timeout;
150 /* a handle to a vpn request */
151 struct GNUNET_VPN_RedirectionRequest *vpn_handle;
153 /* a socket for a dns request */
154 struct GNUNET_NETWORK_Handle *dns_sock;
156 /* a synthesized dns name */
157 char dns_name[MAX_DNS_NAME_LENGTH];
159 /* the authoritative dns zone */
160 char dns_zone[MAX_DNS_NAME_LENGTH];
162 /* the address of the DNS server FIXME not needed? */
163 struct sockaddr_in dns_addr;
165 /* handle to the local stub resolver request */
166 struct GNUNET_RESOLVER_RequestHandle *dns_resolver_handle;
168 /* select task for DNS */
169 GNUNET_SCHEDULER_TaskIdentifier dns_read_task;
171 /* pointer to raw dns query payload FIXME needs to be freed/NULL */
172 char *dns_raw_packet;
174 /* size of the raw dns query */
175 size_t dns_raw_packet_size;
177 /* timeout task for the lookup */
178 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
180 /* continuation to call on timeout */
181 GNUNET_SCHEDULER_Task timeout_cont;
183 /* closure for timeout cont */
184 void* timeout_cont_cls;
186 /* called when resolution phase finishes */
187 ResolutionResultProcessor proc;
189 /* closure passed to proc */
192 /* DLL to store the authority chain */
193 struct AuthorityChain *authority_chain_head;
195 /* DLL to store the authority chain */
196 struct AuthorityChain *authority_chain_tail;
198 /* status of the resolution result */
199 enum ResolutionStatus status;
201 /* The provate local zone of this request */
202 struct GNUNET_CRYPTO_ShortHashCode private_local_zone;
205 * private key of an/our authoritative zone
206 * can be NULL but automatical PKEY import will not work
208 struct GNUNET_CRYPTO_RsaPrivateKey *priv_key;
211 * the heap node associated with this lookup, null if timeout is set
212 * used for DHT background lookups.
214 struct GNUNET_CONTAINER_HeapNode *dht_heap_node;
217 * Id for resolution process
219 unsigned long long id;
222 * Pending Namestore task
224 struct GNUNET_NAMESTORE_QueueEntry *namestore_task;
230 * Handle to a record lookup
232 struct RecordLookupHandle
234 /* the record type to look up */
235 enum GNUNET_GNS_RecordType record_type;
237 /* the name to look up */
238 char name[MAX_DNS_NAME_LENGTH];
240 /* Method to call on record resolution result */
241 RecordLookupProcessor proc;
243 /* closure to pass to proc */
250 * Handle to a shorten context
252 struct NameShortenHandle
254 /* Method to call on shorten result */
255 ShortenResultProcessor proc;
257 /* closure to pass to proc */
260 /* result of shorten */
261 char result[MAX_DNS_NAME_LENGTH];
264 struct GNUNET_CRYPTO_ShortHashCode *root_zone;
267 struct GNUNET_CRYPTO_ShortHashCode *private_zone;
269 /* name of private zone */
270 char private_zone_name[MAX_DNS_LABEL_LENGTH];
273 struct GNUNET_CRYPTO_ShortHashCode *shorten_zone;
275 /* name of shorten zone */
276 char shorten_zone_name[MAX_DNS_LABEL_LENGTH];
281 * Handle to a get authority context
283 struct GetNameAuthorityHandle
285 /* the name to look up authority for */
286 char name[MAX_DNS_NAME_LENGTH];
289 char result[MAX_DNS_NAME_LENGTH];
291 /* Method to call on result */
292 GetAuthorityResultProcessor proc;
294 /* closure to pass to proc */
299 * Handle to a pseu lookup
301 struct GetPseuAuthorityHandle
304 struct GetPseuAuthorityHandle *next;
307 struct GetPseuAuthorityHandle *prev;
309 /* the name to store the zone under */
310 char name[MAX_DNS_LABEL_LENGTH];
312 /* test name to store the zone under */
313 char test_name[MAX_DNS_LABEL_LENGTH];
315 /* the zone of our authority */
316 struct GNUNET_CRYPTO_ShortHashCode our_zone;
318 /* the private key of the zone to store the pseu in */
319 struct GNUNET_CRYPTO_RsaPrivateKey *key;
321 /* a handle for dht lookups. should be NULL if no lookups are in progress */
322 struct GNUNET_DHT_GetHandle *get_handle;
324 /* timeout task for lookup */
325 GNUNET_SCHEDULER_TaskIdentifier timeout;
327 /* Head of the authority list */
328 struct AuthorityChain *ahead;
330 /* handle to namestore request */
331 struct GNUNET_NAMESTORE_QueueEntry* namestore_task;
335 * Namestore queue entries in background
337 struct NamestoreBGTask
340 struct GNUNET_CONTAINER_HeapNode *node;
343 struct GNUNET_NAMESTORE_QueueEntry *qe;
347 * Initialize the resolver
348 * MUST be called before other gns_resolver_* methods
350 * @param nh handle to the namestore
351 * @param dh handle to the dht
352 * @param lz the local zone
353 * @param c configuration handle
354 * @param max_bg_queries maximum amount of background queries
355 * @param ignore_pending ignore records that still require user confirmation
357 * @returns GNUNET_OK on success
360 gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh,
361 struct GNUNET_DHT_Handle *dh,
362 struct GNUNET_CRYPTO_ShortHashCode lz,
363 const struct GNUNET_CONFIGURATION_Handle *c,
364 unsigned long long max_bg_queries,
368 * Cleanup resolver: Terminate pending lookups
370 * @param cont continuation to call when finished
373 gns_resolver_cleanup(ResolverCleanupContinuation cont);
376 * Lookup of a record in a specific zone
377 * calls RecordLookupProcessor on result or timeout
379 * @param zone the root zone
380 * @param pzone the private local zone
381 * @param record_type the record type to look up
382 * @param name the name to look up
383 * @param key optional private key for authority caching
384 * @param timeout timeout for the resolution
385 * @param only_cached GNUNET_NO to only check locally not DHT for performance
386 * @param proc the processor to call
387 * @param cls the closure to pass to proc
390 gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone,
391 struct GNUNET_CRYPTO_ShortHashCode pzone,
392 uint32_t record_type,
394 struct GNUNET_CRYPTO_RsaPrivateKey *key,
395 struct GNUNET_TIME_Relative timeout,
397 RecordLookupProcessor proc,
401 * Shortens a name if possible. If the shortening fails
402 * name will be returned as shortened string. Else
403 * a shorter version of the name will be returned.
404 * There is no guarantee that the shortened name will
405 * actually be canonical/short etc.
407 * @param zone the root zone to use
408 * @param pzone the private zone to use
409 * @param szone the shorten zone to use
410 * @param name name to shorten
411 * @param private_zone_name name of the private zone
412 * @param shorten_zone_name name of the shorten zone
413 * @param proc the processor to call on shorten result
414 * @param proc_cls the closure to pass to proc
417 gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode *zone,
418 struct GNUNET_CRYPTO_ShortHashCode *pzone,
419 struct GNUNET_CRYPTO_ShortHashCode *szone,
421 const char* private_zone_name,
422 const char* shorten_zone_name,
423 ShortenResultProcessor proc,
427 * Tries to resolve the authority for name
430 * @param zone the root zone to look up for
431 * @param pzone the private local zone
432 * @param name the name to lookup up
433 * @param proc the processor to call when finished
434 * @param proc_cls the closure to pass to the processor
437 gns_resolver_get_authority(struct GNUNET_CRYPTO_ShortHashCode zone,
438 struct GNUNET_CRYPTO_ShortHashCode pzone,
440 GetAuthorityResultProcessor proc,
444 * Generic function to check for TLDs
446 * @param name the name to check
447 * @param tld the tld to check
448 * @return GNUNET_YES or GNUNET_NO
451 is_tld(const char* name, const char* tld);
454 * Checks for gnunet/zkey
456 #define is_gnunet_tld(name) is_tld(name, GNUNET_GNS_TLD)
457 #define is_zkey_tld(name) is_tld(name, GNUNET_GNS_TLD_ZKEY)