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 /* Last record data found */
130 struct GNUNET_NAMESTORE_RecordData rd;
132 /* Number of last record data found */
133 unsigned int rd_count;
135 /* The name to resolve */
136 char name[MAX_DNS_NAME_LENGTH];
138 /* has this query been answered? how many matches */
144 /* the authoritative zone to query */
145 struct GNUNET_CRYPTO_ShortHashCode authority;
147 /* the name of the authoritative zone to query */
148 char authority_name[MAX_DNS_LABEL_LENGTH];
150 /* a handle for dht lookups. should be NULL if no lookups are in progress */
151 struct GNUNET_DHT_GetHandle *get_handle;
153 /* timeout set for this lookup task */
154 struct GNUNET_TIME_Relative timeout;
156 /* a handle to a vpn request */
157 struct GNUNET_VPN_RedirectionRequest *vpn_handle;
159 /* a socket for a dns request */
160 struct GNUNET_NETWORK_Handle *dns_sock;
162 /* a synthesized dns name */
163 char dns_name[MAX_DNS_NAME_LENGTH];
165 /* the authoritative dns zone */
166 char dns_zone[MAX_DNS_NAME_LENGTH];
168 /* the address of the DNS server FIXME not needed? */
169 struct sockaddr_in dns_addr;
171 /* handle to the local stub resolver request */
172 struct GNUNET_RESOLVER_RequestHandle *dns_resolver_handle;
174 /* select task for DNS */
175 GNUNET_SCHEDULER_TaskIdentifier dns_read_task;
177 /* pointer to raw dns query payload FIXME needs to be freed/NULL */
178 char *dns_raw_packet;
180 /* size of the raw dns query */
181 size_t dns_raw_packet_size;
183 /* timeout task for the lookup */
184 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
186 /* continuation to call on timeout */
187 GNUNET_SCHEDULER_Task timeout_cont;
189 /* closure for timeout cont */
190 void* timeout_cont_cls;
192 /* called when resolution phase finishes */
193 ResolutionResultProcessor proc;
195 /* closure passed to proc */
198 /* DLL to store the authority chain */
199 struct AuthorityChain *authority_chain_head;
201 /* DLL to store the authority chain */
202 struct AuthorityChain *authority_chain_tail;
204 /* status of the resolution result */
205 enum ResolutionStatus status;
207 /* The provate local zone of this request */
208 struct GNUNET_CRYPTO_ShortHashCode private_local_zone;
211 * private key of an/our authoritative zone
212 * can be NULL but automatical PKEY import will not work
214 struct GNUNET_CRYPTO_RsaPrivateKey *priv_key;
217 * the heap node associated with this lookup, null if timeout is set
218 * used for DHT background lookups.
220 struct GNUNET_CONTAINER_HeapNode *dht_heap_node;
223 * Id for resolution process
225 unsigned long long id;
228 * Pending Namestore task
230 struct GNUNET_NAMESTORE_QueueEntry *namestore_task;
236 * Handle to a record lookup
238 struct RecordLookupHandle
240 /* the record type to look up */
241 enum GNUNET_GNS_RecordType record_type;
243 /* the name to look up */
244 char name[MAX_DNS_NAME_LENGTH];
246 /* Method to call on record resolution result */
247 RecordLookupProcessor proc;
249 /* closure to pass to proc */
256 * Handle to a shorten context
258 struct NameShortenHandle
260 /* Method to call on shorten result */
261 ShortenResultProcessor proc;
263 /* closure to pass to proc */
266 /* result of shorten */
267 char result[MAX_DNS_NAME_LENGTH];
270 struct GNUNET_CRYPTO_ShortHashCode *root_zone;
273 struct GNUNET_CRYPTO_ShortHashCode *private_zone;
275 /* name of private zone */
276 char private_zone_name[MAX_DNS_LABEL_LENGTH];
279 struct GNUNET_CRYPTO_ShortHashCode *shorten_zone;
281 /* name of shorten zone */
282 char shorten_zone_name[MAX_DNS_LABEL_LENGTH];
287 * Handle to a get authority context
289 struct GetNameAuthorityHandle
291 /* the name to look up authority for */
292 char name[MAX_DNS_NAME_LENGTH];
295 char result[MAX_DNS_NAME_LENGTH];
297 /* Method to call on result */
298 GetAuthorityResultProcessor proc;
300 /* closure to pass to proc */
305 * Handle to a pseu lookup
307 struct GetPseuAuthorityHandle
310 struct GetPseuAuthorityHandle *next;
313 struct GetPseuAuthorityHandle *prev;
315 /* the name to store the zone under */
316 char name[MAX_DNS_LABEL_LENGTH];
318 /* test name to store the zone under */
319 char test_name[MAX_DNS_LABEL_LENGTH];
321 /* the zone of our authority */
322 struct GNUNET_CRYPTO_ShortHashCode our_zone;
324 /* the private key of the zone to store the pseu in */
325 struct GNUNET_CRYPTO_RsaPrivateKey *key;
327 /* a handle for dht lookups. should be NULL if no lookups are in progress */
328 struct GNUNET_DHT_GetHandle *get_handle;
330 /* timeout task for lookup */
331 GNUNET_SCHEDULER_TaskIdentifier timeout;
333 /* Head of the authority list */
334 struct AuthorityChain *ahead;
336 /* handle to namestore request */
337 struct GNUNET_NAMESTORE_QueueEntry* namestore_task;
341 * Namestore queue entries in background
343 struct NamestoreBGTask
346 struct GNUNET_CONTAINER_HeapNode *node;
349 struct GNUNET_NAMESTORE_QueueEntry *qe;
353 * Initialize the resolver
354 * MUST be called before other gns_resolver_* methods
356 * @param nh handle to the namestore
357 * @param dh handle to the dht
358 * @param lz the local zone
359 * @param c configuration handle
360 * @param max_bg_queries maximum amount of background queries
361 * @param ignore_pending ignore records that still require user confirmation
363 * @returns GNUNET_OK on success
366 gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh,
367 struct GNUNET_DHT_Handle *dh,
368 struct GNUNET_CRYPTO_ShortHashCode lz,
369 const struct GNUNET_CONFIGURATION_Handle *c,
370 unsigned long long max_bg_queries,
374 * Cleanup resolver: Terminate pending lookups
376 * @param cont continuation to call when finished
379 gns_resolver_cleanup(ResolverCleanupContinuation cont);
382 * Lookup of a record in a specific zone
383 * calls RecordLookupProcessor on result or timeout
385 * @param zone the root zone
386 * @param pzone the private local zone
387 * @param record_type the record type to look up
388 * @param name the name to look up
389 * @param key optional private key for authority caching
390 * @param timeout timeout for the resolution
391 * @param only_cached GNUNET_NO to only check locally not DHT for performance
392 * @param proc the processor to call
393 * @param cls the closure to pass to proc
396 gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone,
397 struct GNUNET_CRYPTO_ShortHashCode pzone,
398 uint32_t record_type,
400 struct GNUNET_CRYPTO_RsaPrivateKey *key,
401 struct GNUNET_TIME_Relative timeout,
403 RecordLookupProcessor proc,
407 * Shortens a name if possible. If the shortening fails
408 * name will be returned as shortened string. Else
409 * a shorter version of the name will be returned.
410 * There is no guarantee that the shortened name will
411 * actually be canonical/short etc.
413 * @param zone the root zone to use
414 * @param pzone the private zone to use
415 * @param szone the shorten zone to use
416 * @param name name to shorten
417 * @param private_zone_name name of the private zone
418 * @param shorten_zone_name name of the shorten zone
419 * @param proc the processor to call on shorten result
420 * @param proc_cls the closure to pass to proc
423 gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode *zone,
424 struct GNUNET_CRYPTO_ShortHashCode *pzone,
425 struct GNUNET_CRYPTO_ShortHashCode *szone,
427 const char* private_zone_name,
428 const char* shorten_zone_name,
429 ShortenResultProcessor proc,
433 * Tries to resolve the authority for name
436 * @param zone the root zone to look up for
437 * @param pzone the private local zone
438 * @param name the name to lookup up
439 * @param proc the processor to call when finished
440 * @param proc_cls the closure to pass to the processor
443 gns_resolver_get_authority(struct GNUNET_CRYPTO_ShortHashCode zone,
444 struct GNUNET_CRYPTO_ShortHashCode pzone,
446 GetAuthorityResultProcessor proc,
450 * Generic function to check for TLDs
452 * @param name the name to check
453 * @param tld the tld to check
454 * @return GNUNET_YES or GNUNET_NO
457 is_tld(const char* name, const char* tld);
460 * Checks for gnunet/zkey
462 #define is_gnunet_tld(name) is_tld(name, GNUNET_GNS_TLD)
463 #define is_zkey_tld(name) is_tld(name, GNUNET_GNS_TLD_ZKEY)