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;
41 * processor for a record lookup result
43 * @param cls the closure
44 * @param rd_count number of results
45 * @param rd result data
47 typedef void (*RecordLookupProcessor) (void *cls,
49 const struct GNUNET_NAMESTORE_RecordData *rd);
53 * processor for a shorten result
55 * @param cls the closure
56 * @param name shortened name
58 typedef void (*ShortenResultProcessor) (void *cls, const char* name);
62 * processor for an authority result
64 * @param cls the closure
67 typedef void (*GetAuthorityResultProcessor) (void *cls, const char* name);
70 * processor for a resolution result
72 * @param cls the closure
73 * @param rh the resolution handle
74 * @param rd_count number of results
75 * @param rd result data
77 typedef void (*ResolutionResultProcessor) (void *cls,
78 struct ResolverHandle *rh,
80 const struct GNUNET_NAMESTORE_RecordData *rd);
84 * Resolution status indicator
85 * RSL_RECORD_EXISTS: the name to lookup exists
86 * RSL_RECORD_EXPIRED: the name in the record expired
87 * RSL_TIMED_OUT: resolution timed out
88 * RSL_DELEGATE_VPN: Found VPN delegation
89 * RSL_DELEGATE_NS: Found NS delegation
90 * RSL_DELEGATE_PKEY: Found PKEY delegation
91 * RSL_CNAME_FOUND: Found CNAME record
92 * RSL_PKEY_REVOKED: Found PKEY has been revoked
96 RSL_RECORD_EXISTS = 1,
97 RSL_RECORD_EXPIRED = 2,
100 RSL_DELEGATE_NS = 16,
101 RSL_DELEGATE_PKEY = 32,
102 RSL_CNAME_FOUND = 64,
103 RSL_PKEY_REVOKED = 128
107 * Handle to a currenty pending resolution
108 * a ResolverHandle is passed to, for example
109 * resolve_record_ns to resolve a record in the namestore.
110 * On result (positive or negative) the ResolutionResultProcessor
112 * If a timeout is set timeout_cont will be called.
113 * If no timeout is set (ie timeout forever) then background resolutions
114 * might be triggered.
116 struct ResolverHandle
120 struct ResolverHandle *next;
123 struct ResolverHandle *prev;
125 /* Last record data found */
126 struct GNUNET_NAMESTORE_RecordData rd;
128 /* Number of last record data found */
129 unsigned int rd_count;
131 /* The name to resolve */
132 char name[MAX_DNS_NAME_LENGTH];
134 /* has this query been answered? how many matches */
140 /* the authoritative zone to query */
141 struct GNUNET_CRYPTO_ShortHashCode authority;
143 /* the name of the authoritative zone to query */
144 char authority_name[MAX_DNS_LABEL_LENGTH];
146 /* a handle for dht lookups. should be NULL if no lookups are in progress */
147 struct GNUNET_DHT_GetHandle *get_handle;
149 /* timeout set for this lookup task */
150 struct GNUNET_TIME_Relative timeout;
152 /* a handle to a vpn request */
153 struct GNUNET_VPN_RedirectionRequest *vpn_handle;
155 /* a socket for a dns request */
156 struct GNUNET_NETWORK_Handle *dns_sock;
158 /* a synthesized dns name */
159 char dns_name[MAX_DNS_NAME_LENGTH];
161 /* the authoritative dns zone */
162 char dns_zone[MAX_DNS_NAME_LENGTH];
164 /* the address of the DNS server FIXME not needed? */
165 struct sockaddr_in dns_addr;
167 /* handle to the local stub resolver request */
168 struct GNUNET_RESOLVER_RequestHandle *dns_resolver_handle;
170 /* select task for DNS */
171 GNUNET_SCHEDULER_TaskIdentifier dns_read_task;
173 /* pointer to raw dns query payload FIXME needs to be freed/NULL */
174 char *dns_raw_packet;
176 /* size of the raw dns query */
177 size_t dns_raw_packet_size;
179 /* timeout task for the lookup */
180 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
182 /* continuation to call on timeout */
183 GNUNET_SCHEDULER_Task timeout_cont;
185 /* closure for timeout cont */
186 void* timeout_cont_cls;
188 /* called when resolution phase finishes */
189 ResolutionResultProcessor proc;
191 /* closure passed to proc */
194 /* DLL to store the authority chain */
195 struct AuthorityChain *authority_chain_head;
197 /* DLL to store the authority chain */
198 struct AuthorityChain *authority_chain_tail;
200 /* status of the resolution result */
201 enum ResolutionStatus status;
203 /* The provate local zone of this request */
204 struct GNUNET_CRYPTO_ShortHashCode private_local_zone;
207 * private key of an/our authoritative zone
208 * can be NULL but automatical PKEY import will not work
210 struct GNUNET_CRYPTO_RsaPrivateKey *priv_key;
213 * the heap node associated with this lookup, null if timeout is set
214 * used for DHT background lookups.
216 struct GNUNET_CONTAINER_HeapNode *dht_heap_node;
219 * Id for resolution process
221 unsigned long long id;
224 * Pending Namestore task
226 struct GNUNET_NAMESTORE_QueueEntry *namestore_task;
232 * Handle to a record lookup
234 struct RecordLookupHandle
236 /* the record type to look up */
237 enum GNUNET_GNS_RecordType record_type;
239 /* the name to look up */
240 char name[MAX_DNS_NAME_LENGTH];
242 /* Method to call on record resolution result */
243 RecordLookupProcessor proc;
245 /* closure to pass to proc */
252 * Handle to a shorten context
254 struct NameShortenHandle
256 /* Method to call on shorten result */
257 ShortenResultProcessor proc;
259 /* closure to pass to proc */
262 /* result of shorten */
263 char result[MAX_DNS_NAME_LENGTH];
266 struct GNUNET_CRYPTO_ShortHashCode *root_zone;
269 struct GNUNET_CRYPTO_ShortHashCode *private_zone;
271 /* name of private zone */
272 char private_zone_name[MAX_DNS_LABEL_LENGTH];
275 struct GNUNET_CRYPTO_ShortHashCode *shorten_zone;
277 /* name of shorten zone */
278 char shorten_zone_name[MAX_DNS_LABEL_LENGTH];
283 * Handle to a get authority context
285 struct GetNameAuthorityHandle
287 /* the name to look up authority for */
288 char name[MAX_DNS_NAME_LENGTH];
291 char result[MAX_DNS_NAME_LENGTH];
293 /* Method to call on result */
294 GetAuthorityResultProcessor proc;
296 /* closure to pass to proc */
301 * Handle to a pseu lookup
303 struct GetPseuAuthorityHandle
306 struct GetPseuAuthorityHandle *next;
309 struct GetPseuAuthorityHandle *prev;
311 /* the name to store the zone under */
312 char name[MAX_DNS_LABEL_LENGTH];
314 /* test name to store the zone under */
315 char test_name[MAX_DNS_LABEL_LENGTH];
317 /* the zone of our authority */
318 struct GNUNET_CRYPTO_ShortHashCode our_zone;
320 /* the private key of the zone to store the pseu in */
321 struct GNUNET_CRYPTO_RsaPrivateKey *key;
323 /* a handle for dht lookups. should be NULL if no lookups are in progress */
324 struct GNUNET_DHT_GetHandle *get_handle;
326 /* timeout task for lookup */
327 GNUNET_SCHEDULER_TaskIdentifier timeout;
329 /* Authority to shorten */
330 struct AuthorityChain *auth;
332 /* handle to namestore request */
333 struct GNUNET_NAMESTORE_QueueEntry* namestore_task;
337 * Namestore queue entries in background
339 struct NamestoreBGTask
342 struct GNUNET_CONTAINER_HeapNode *node;
345 struct GNUNET_NAMESTORE_QueueEntry *qe;
349 * Initialize the resolver
350 * MUST be called before other gns_resolver_* methods
352 * @param nh handle to the namestore
353 * @param dh handle to the dht
354 * @param lz the local zone
355 * @param c configuration handle
356 * @param max_bg_queries maximum amount of background queries
357 * @param ignore_pending ignore records that still require user confirmation
359 * @returns GNUNET_OK on success
362 gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh,
363 struct GNUNET_DHT_Handle *dh,
364 struct GNUNET_CRYPTO_ShortHashCode lz,
365 const struct GNUNET_CONFIGURATION_Handle *c,
366 unsigned long long max_bg_queries,
370 * Cleanup resolver: Terminate pending lookups
373 gns_resolver_cleanup(void);
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)