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
96 RSL_RECORD_EXISTS = 1,
97 RSL_RECORD_EXPIRED = 2,
104 * Handle to a currenty pending resolution
105 * a ResolverHandle is passed to, for example
106 * resolve_record_ns to resolve a record in the namestore.
107 * On result (positive or negative) the ResolutionResultProcessor
109 * If a timeout is set timeout_cont will be called.
110 * If no timeout is set (ie timeout forever) then background resolutions
111 * might be triggered.
113 struct ResolverHandle
115 /* The name to resolve */
116 char name[MAX_DNS_NAME_LENGTH];
118 /* has this query been answered? how many matches */
124 /* the authoritative zone to query */
125 struct GNUNET_CRYPTO_ShortHashCode authority;
127 /* the name of the authoritative zone to query */
128 char authority_name[MAX_DNS_LABEL_LENGTH];
130 /* a handle for dht lookups. should be NULL if no lookups are in progress */
131 struct GNUNET_DHT_GetHandle *get_handle;
133 /* timeout set for this lookup task */
134 struct GNUNET_TIME_Relative timeout;
136 /* a handle to a vpn request */
137 struct GNUNET_VPN_RedirectionRequest *vpn_handle;
139 /* a socket for a dns request */
140 struct GNUNET_NETWORK_Handle *dns_sock;
142 /* the address of the DNS server FIXME not needed? */
143 struct in_addr dns_ip;
145 /* pointer to raw dns query payload FIXME needs to be freed/NULL */
146 char *dns_raw_packet;
148 /* timeout task for the lookup */
149 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
151 /* continuation to call on timeout */
152 GNUNET_SCHEDULER_Task timeout_cont;
154 /* closure for timeout cont */
155 void* timeout_cont_cls;
157 /* called when resolution phase finishes */
158 ResolutionResultProcessor proc;
160 /* closure passed to proc */
163 /* DLL to store the authority chain */
164 struct AuthorityChain *authority_chain_head;
166 /* DLL to store the authority chain */
167 struct AuthorityChain *authority_chain_tail;
169 /* status of the resolution result */
170 enum ResolutionStatus status;
172 /* The provate local zone of this request */
173 struct GNUNET_CRYPTO_ShortHashCode private_local_zone;
176 * private key of an/our authoritative zone
177 * can be NULL but automatical PKEY import will not work
179 struct GNUNET_CRYPTO_RsaPrivateKey *priv_key;
182 * the heap node associated with this lookup, null if timeout is set
183 * used for DHT background lookups.
185 struct GNUNET_CONTAINER_HeapNode *dht_heap_node;
188 * Id for resolution process
190 unsigned long long id;
196 * Handle to a record lookup
198 struct RecordLookupHandle
200 /* the record type to look up */
201 enum GNUNET_GNS_RecordType record_type;
203 /* the name to look up */
204 char name[MAX_DNS_NAME_LENGTH];
206 /* Method to call on record resolution result */
207 RecordLookupProcessor proc;
209 /* closure to pass to proc */
216 * Handle to a shorten context
218 struct NameShortenHandle
220 /* Method to call on shorten result */
221 ShortenResultProcessor proc;
223 /* closure to pass to proc */
226 /* result of shorten */
227 char result[MAX_DNS_NAME_LENGTH];
230 struct GNUNET_CRYPTO_ShortHashCode *root_zone;
233 struct GNUNET_CRYPTO_ShortHashCode *private_zone;
235 /* name of private zone */
236 char private_zone_name[MAX_DNS_LABEL_LENGTH];
239 struct GNUNET_CRYPTO_ShortHashCode *shorten_zone;
241 /* name of shorten zone */
242 char shorten_zone_name[MAX_DNS_LABEL_LENGTH];
247 * Handle to a get authority context
249 struct GetNameAuthorityHandle
251 /* the name to look up authority for */
252 char name[MAX_DNS_NAME_LENGTH];
254 /* Method to call on result */
255 GetAuthorityResultProcessor proc;
257 /* closure to pass to proc */
262 * Handle to a pseu lookup
264 struct GetPseuAuthorityHandle
266 /* the name to store the zone under */
267 char name[MAX_DNS_LABEL_LENGTH];
269 /* test name to store the zone under */
270 char test_name[MAX_DNS_LABEL_LENGTH];
272 /* the zone of our authority */
273 struct GNUNET_CRYPTO_ShortHashCode our_zone;
275 /* the private key of the zone to store the pseu in */
276 struct GNUNET_CRYPTO_RsaPrivateKey *key;
278 /* a handle for dht lookups. should be NULL if no lookups are in progress */
279 struct GNUNET_DHT_GetHandle *get_handle;
281 /* timeout task for lookup */
282 GNUNET_SCHEDULER_TaskIdentifier timeout;
284 /* Head of the authority list */
285 struct AuthorityChain *ahead;
289 * Initialize the resolver
290 * MUST be called before other gns_resolver_* methods
292 * @param nh handle to the namestore
293 * @param dh handle to the dht
294 * @param lz the local zone
295 * @param max_bg_queries maximum amount of background queries
296 * @param ignore_pending ignore records that still require user confirmation
298 * @returns GNUNET_OK on success
301 gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh,
302 struct GNUNET_DHT_Handle *dh,
303 struct GNUNET_CRYPTO_ShortHashCode lz,
304 unsigned long long max_bg_queries,
308 * Cleanup resolver: Terminate pending lookups
310 * @param cont continuation to call when finished
313 gns_resolver_cleanup(ResolverCleanupContinuation cont);
316 * Lookup of a record in a specific zone
317 * calls RecordLookupProcessor on result or timeout
319 * @param zone the root zone
320 * @param pzone the private local zone
321 * @param record_type the record type to look up
322 * @param name the name to look up
323 * @param key optional private key for authority caching
324 * @param timeout timeout for the resolution
325 * @param only_cached GNUNET_NO to only check locally not DHT for performance
326 * @param proc the processor to call
327 * @param cls the closure to pass to proc
330 gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone,
331 struct GNUNET_CRYPTO_ShortHashCode pzone,
332 uint32_t record_type,
334 struct GNUNET_CRYPTO_RsaPrivateKey *key,
335 struct GNUNET_TIME_Relative timeout,
337 RecordLookupProcessor proc,
341 * Shortens a name if possible. If the shortening fails
342 * name will be returned as shortened string. Else
343 * a shorter version of the name will be returned.
344 * There is no guarantee that the shortened name will
345 * actually be canonical/short etc.
347 * @param zone the root zone to use
348 * @param pzone the private zone to use
349 * @param szone the shorten zone to use
350 * @param name name to shorten
351 * @param private_zone_name name of the private zone
352 * @param shorten_zone_name name of the shorten zone
353 * @param proc the processor to call on shorten result
354 * @param proc_cls the closure to pass to proc
357 gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode *zone,
358 struct GNUNET_CRYPTO_ShortHashCode *pzone,
359 struct GNUNET_CRYPTO_ShortHashCode *szone,
361 const char* private_zone_name,
362 const char* shorten_zone_name,
363 ShortenResultProcessor proc,
367 * Tries to resolve the authority for name
370 * @param zone the root zone to look up for
371 * @param pzone the private local zone
372 * @param name the name to lookup up
373 * @param proc the processor to call when finished
374 * @param proc_cls the closure to pass to the processor
377 gns_resolver_get_authority(struct GNUNET_CRYPTO_ShortHashCode zone,
378 struct GNUNET_CRYPTO_ShortHashCode pzone,
380 GetAuthorityResultProcessor proc,
384 * Generic function to check for TLDs
386 * @param name the name to check
387 * @param tld the tld to check
388 * @return GNUNET_YES or GNUNET_NO
391 is_tld(const char* name, const char* tld);
394 * Checks for gnunet/zkey
396 #define is_gnunet_tld(name) is_tld(name, GNUNET_GNS_TLD)
397 #define is_zkey_tld(name) is_tld(name, GNUNET_GNS_TLD_ZKEY)