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
16 * DLL to hold the authority chain
17 * we had to pass in the resolution process
21 struct AuthorityChain *prev;
23 struct AuthorityChain *next;
25 /* the zone hash of the authority */
26 struct GNUNET_CRYPTO_ShortHashCode zone;
28 /* (local) name of the authority */
29 char name[MAX_DNS_LABEL_LENGTH];
31 /* was the ns entry fresh */
35 /* handle to a resolution process */
36 struct ResolverHandle;
39 * continuation called when cleanup of resolver finishes
41 typedef void (*ResolverCleanupContinuation) (void);
44 * processor for a record lookup result
46 * @param cls the closure
47 * @param rd_count number of results
48 * @param rd result data
50 typedef void (*RecordLookupProcessor) (void *cls,
52 const struct GNUNET_NAMESTORE_RecordData *rd);
56 * processor for a shorten result
58 * @param cls the closure
59 * @param name shortened name
61 typedef void (*ShortenResultProcessor) (void *cls, const char* name);
65 * processor for an authority result
67 * @param cls the closure
70 typedef void (*GetAuthorityResultProcessor) (void *cls, const char* name);
73 * processor for a resolution result
75 * @param cls the closure
76 * @param rh the resolution handle
77 * @param rd_count number of results
78 * @param rd result data
80 typedef void (*ResolutionResultProcessor) (void *cls,
81 struct ResolverHandle *rh,
83 const struct GNUNET_NAMESTORE_RecordData *rd);
87 * Resolution status indicator
88 * RSL_RECORD_EXISTS: the name to lookup exists
89 * RSL_RECORD_EXPIRED: the name in the record expired
90 * RSL_TIMED_OUT: resolution timed out
91 * RSL_DELEGATE_VPN: Found VPN delegation
92 * RSL_DELEGATE_NS: Found NS delegation
93 * RSL_DELEGATE_PKEY: Found PKEY delegation
94 * RSL_CNAME_FOUND: Found CNAME record
98 RSL_RECORD_EXISTS = 1,
99 RSL_RECORD_EXPIRED = 2,
101 RSL_DELEGATE_VPN = 8,
102 RSL_DELEGATE_NS = 16,
103 RSL_DELEGATE_PKEY = 32,
108 * Handle to a currenty pending resolution
109 * a ResolverHandle is passed to, for example
110 * resolve_record_ns to resolve a record in the namestore.
111 * On result (positive or negative) the ResolutionResultProcessor
113 * If a timeout is set timeout_cont will be called.
114 * If no timeout is set (ie timeout forever) then background resolutions
115 * might be triggered.
117 struct ResolverHandle
119 /* The name to resolve */
120 char name[MAX_DNS_NAME_LENGTH];
122 /* has this query been answered? how many matches */
128 /* the authoritative zone to query */
129 struct GNUNET_CRYPTO_ShortHashCode authority;
131 /* the name of the authoritative zone to query */
132 char authority_name[MAX_DNS_LABEL_LENGTH];
134 /* a handle for dht lookups. should be NULL if no lookups are in progress */
135 struct GNUNET_DHT_GetHandle *get_handle;
137 /* timeout set for this lookup task */
138 struct GNUNET_TIME_Relative timeout;
140 /* a handle to a vpn request */
141 struct GNUNET_VPN_RedirectionRequest *vpn_handle;
143 /* a socket for a dns request */
144 struct GNUNET_NETWORK_Handle *dns_sock;
146 /* a synthesized dns name */
147 char dns_name[MAX_DNS_NAME_LENGTH];
149 /* the authoritative dns zone */
150 char dns_zone[MAX_DNS_NAME_LENGTH];
152 /* the address of the DNS server FIXME not needed? */
153 struct sockaddr_in dns_addr;
155 /* handle to the local stub resolver request */
156 struct GNUNET_RESOLVER_RequestHandle *dns_resolver_handle;
158 /* select task for DNS */
159 GNUNET_SCHEDULER_TaskIdentifier dns_read_task;
161 /* pointer to raw dns query payload FIXME needs to be freed/NULL */
162 char *dns_raw_packet;
164 /* size of the raw dns query */
165 size_t dns_raw_packet_size;
167 /* timeout task for the lookup */
168 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
170 /* continuation to call on timeout */
171 GNUNET_SCHEDULER_Task timeout_cont;
173 /* closure for timeout cont */
174 void* timeout_cont_cls;
176 /* called when resolution phase finishes */
177 ResolutionResultProcessor proc;
179 /* closure passed to proc */
182 /* DLL to store the authority chain */
183 struct AuthorityChain *authority_chain_head;
185 /* DLL to store the authority chain */
186 struct AuthorityChain *authority_chain_tail;
188 /* status of the resolution result */
189 enum ResolutionStatus status;
191 /* The provate local zone of this request */
192 struct GNUNET_CRYPTO_ShortHashCode private_local_zone;
195 * private key of an/our authoritative zone
196 * can be NULL but automatical PKEY import will not work
198 struct GNUNET_CRYPTO_RsaPrivateKey *priv_key;
201 * the heap node associated with this lookup, null if timeout is set
202 * used for DHT background lookups.
204 struct GNUNET_CONTAINER_HeapNode *dht_heap_node;
207 * Id for resolution process
209 unsigned long long id;
215 * Handle to a record lookup
217 struct RecordLookupHandle
219 /* the record type to look up */
220 enum GNUNET_GNS_RecordType record_type;
222 /* the name to look up */
223 char name[MAX_DNS_NAME_LENGTH];
225 /* Method to call on record resolution result */
226 RecordLookupProcessor proc;
228 /* closure to pass to proc */
235 * Handle to a shorten context
237 struct NameShortenHandle
239 /* Method to call on shorten result */
240 ShortenResultProcessor proc;
242 /* closure to pass to proc */
245 /* result of shorten */
246 char result[MAX_DNS_NAME_LENGTH];
249 struct GNUNET_CRYPTO_ShortHashCode *root_zone;
252 struct GNUNET_CRYPTO_ShortHashCode *private_zone;
254 /* name of private zone */
255 char private_zone_name[MAX_DNS_LABEL_LENGTH];
258 struct GNUNET_CRYPTO_ShortHashCode *shorten_zone;
260 /* name of shorten zone */
261 char shorten_zone_name[MAX_DNS_LABEL_LENGTH];
266 * Handle to a get authority context
268 struct GetNameAuthorityHandle
270 /* the name to look up authority for */
271 char name[MAX_DNS_NAME_LENGTH];
273 /* Method to call on result */
274 GetAuthorityResultProcessor proc;
276 /* closure to pass to proc */
281 * Handle to a pseu lookup
283 struct GetPseuAuthorityHandle
285 /* the name to store the zone under */
286 char name[MAX_DNS_LABEL_LENGTH];
288 /* test name to store the zone under */
289 char test_name[MAX_DNS_LABEL_LENGTH];
291 /* the zone of our authority */
292 struct GNUNET_CRYPTO_ShortHashCode our_zone;
294 /* the private key of the zone to store the pseu in */
295 struct GNUNET_CRYPTO_RsaPrivateKey *key;
297 /* a handle for dht lookups. should be NULL if no lookups are in progress */
298 struct GNUNET_DHT_GetHandle *get_handle;
300 /* timeout task for lookup */
301 GNUNET_SCHEDULER_TaskIdentifier timeout;
303 /* Head of the authority list */
304 struct AuthorityChain *ahead;
308 * Initialize the resolver
309 * MUST be called before other gns_resolver_* methods
311 * @param nh handle to the namestore
312 * @param dh handle to the dht
313 * @param lz the local zone
314 * @param cfg configuration handle
315 * @param max_bg_queries maximum amount of background queries
316 * @param ignore_pending ignore records that still require user confirmation
318 * @returns GNUNET_OK on success
321 gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh,
322 struct GNUNET_DHT_Handle *dh,
323 struct GNUNET_CRYPTO_ShortHashCode lz,
324 const struct GNUNET_CONFIGURATION_Handle *cfg,
325 unsigned long long max_bg_queries,
329 * Cleanup resolver: Terminate pending lookups
331 * @param cont continuation to call when finished
334 gns_resolver_cleanup(ResolverCleanupContinuation cont);
337 * Lookup of a record in a specific zone
338 * calls RecordLookupProcessor on result or timeout
340 * @param zone the root zone
341 * @param pzone the private local zone
342 * @param record_type the record type to look up
343 * @param name the name to look up
344 * @param key optional private key for authority caching
345 * @param timeout timeout for the resolution
346 * @param only_cached GNUNET_NO to only check locally not DHT for performance
347 * @param proc the processor to call
348 * @param cls the closure to pass to proc
351 gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone,
352 struct GNUNET_CRYPTO_ShortHashCode pzone,
353 uint32_t record_type,
355 struct GNUNET_CRYPTO_RsaPrivateKey *key,
356 struct GNUNET_TIME_Relative timeout,
358 RecordLookupProcessor proc,
362 * Shortens a name if possible. If the shortening fails
363 * name will be returned as shortened string. Else
364 * a shorter version of the name will be returned.
365 * There is no guarantee that the shortened name will
366 * actually be canonical/short etc.
368 * @param zone the root zone to use
369 * @param pzone the private zone to use
370 * @param szone the shorten zone to use
371 * @param name name to shorten
372 * @param private_zone_name name of the private zone
373 * @param shorten_zone_name name of the shorten zone
374 * @param proc the processor to call on shorten result
375 * @param proc_cls the closure to pass to proc
378 gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode *zone,
379 struct GNUNET_CRYPTO_ShortHashCode *pzone,
380 struct GNUNET_CRYPTO_ShortHashCode *szone,
382 const char* private_zone_name,
383 const char* shorten_zone_name,
384 ShortenResultProcessor proc,
388 * Tries to resolve the authority for name
391 * @param zone the root zone to look up for
392 * @param pzone the private local zone
393 * @param name the name to lookup up
394 * @param proc the processor to call when finished
395 * @param proc_cls the closure to pass to the processor
398 gns_resolver_get_authority(struct GNUNET_CRYPTO_ShortHashCode zone,
399 struct GNUNET_CRYPTO_ShortHashCode pzone,
401 GetAuthorityResultProcessor proc,
405 * Generic function to check for TLDs
407 * @param name the name to check
408 * @param tld the tld to check
409 * @return GNUNET_YES or GNUNET_NO
412 is_tld(const char* name, const char* tld);
415 * Checks for gnunet/zkey
417 #define is_gnunet_tld(name) is_tld(name, GNUNET_GNS_TLD)
418 #define is_zkey_tld(name) is_tld(name, GNUNET_GNS_TLD_ZKEY)