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
94 RSL_RECORD_EXISTS = 1,
95 RSL_RECORD_EXPIRED = 2,
100 * Handle to a currenty pending resolution
101 * a ResolverHandle is passed to, for example
102 * resolve_record_ns to resolve a record in the namestore.
103 * On result (positive or negative) the ResolutionResultProcessor
105 * If a timeout is set timeout_cont will be called.
106 * If no timeout is set (ie timeout forever) then background resolutions
107 * might be triggered.
109 struct ResolverHandle
111 /* The name to resolve */
112 char name[MAX_DNS_NAME_LENGTH];
114 /* has this query been answered? how many matches */
120 /* the authoritative zone to query */
121 struct GNUNET_CRYPTO_ShortHashCode authority;
123 /* the name of the authoritative zone to query */
124 char authority_name[MAX_DNS_LABEL_LENGTH];
126 /* a handle for dht lookups. should be NULL if no lookups are in progress */
127 struct GNUNET_DHT_GetHandle *get_handle;
129 /* timeout set for this lookup task */
130 struct GNUNET_TIME_Relative timeout;
132 /* timeout task for the lookup */
133 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
135 /* continuation to call on timeout */
136 GNUNET_SCHEDULER_Task timeout_cont;
138 /* closure for timeout cont */
139 void* timeout_cont_cls;
141 /* called when resolution phase finishes */
142 ResolutionResultProcessor proc;
144 /* closure passed to proc */
147 /* DLL to store the authority chain */
148 struct AuthorityChain *authority_chain_head;
150 /* DLL to store the authority chain */
151 struct AuthorityChain *authority_chain_tail;
153 /* status of the resolution result */
154 enum ResolutionStatus status;
156 /* The provate local zone of this request */
157 struct GNUNET_CRYPTO_ShortHashCode private_local_zone;
160 * private key of an/our authoritative zone
161 * can be NULL but automatical PKEY import will not work
163 struct GNUNET_CRYPTO_RsaPrivateKey *priv_key;
166 * the heap node associated with this lookup, null if timeout is set
167 * used for DHT background lookups.
169 struct GNUNET_CONTAINER_HeapNode *dht_heap_node;
172 * Id for resolution process
174 unsigned long long id;
180 * Handle to a record lookup
182 struct RecordLookupHandle
184 /* the record type to look up */
185 enum GNUNET_GNS_RecordType record_type;
187 /* the name to look up */
188 char name[MAX_DNS_NAME_LENGTH];
190 /* Method to call on record resolution result */
191 RecordLookupProcessor proc;
193 /* closure to pass to proc */
200 * Handle to a shorten context
202 struct NameShortenHandle
204 /* Method to call on shorten result */
205 ShortenResultProcessor proc;
207 /* closure to pass to proc */
212 * Handle to a get authority context
214 struct GetNameAuthorityHandle
216 /* the name to look up authority for */
217 char name[MAX_DNS_NAME_LENGTH];
219 /* Method to call on result */
220 GetAuthorityResultProcessor proc;
222 /* closure to pass to proc */
227 * Handle to a pseu lookup
229 struct GetPseuAuthorityHandle
231 /* the name to store the zone under */
232 char name[MAX_DNS_LABEL_LENGTH];
234 /* test name to store the zone under */
235 char test_name[MAX_DNS_LABEL_LENGTH];
237 /* the zone of our authority */
238 struct GNUNET_CRYPTO_ShortHashCode our_zone;
240 /* the private key of the zone to store the pseu in */
241 struct GNUNET_CRYPTO_RsaPrivateKey *key;
243 /* a handle for dht lookups. should be NULL if no lookups are in progress */
244 struct GNUNET_DHT_GetHandle *get_handle;
246 /* timeout task for lookup */
247 GNUNET_SCHEDULER_TaskIdentifier timeout;
249 /* Head of the authority list */
250 struct AuthorityChain *ahead;
254 * Initialize the resolver
255 * MUST be called before other gns_resolver_* methods
257 * @param nh handle to the namestore
258 * @param dh handle to the dht
259 * @param lz the local zone
260 * @param max_bg_queries maximum amount of background queries
261 * @param ignore_pending ignore records that still require user confirmation
263 * @returns GNUNET_OK on success
266 gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh,
267 struct GNUNET_DHT_Handle *dh,
268 struct GNUNET_CRYPTO_ShortHashCode lz,
269 unsigned long long max_bg_queries,
273 * Cleanup resolver: Terminate pending lookups
275 * @param cont continuation to call when finished
278 gns_resolver_cleanup(ResolverCleanupContinuation cont);
281 * Lookup of a record in a specific zone
282 * calls RecordLookupProcessor on result or timeout
284 * @param zone the root zone
285 * @param pzone the private local zone
286 * @param record_type the record type to look up
287 * @param name the name to look up
288 * @param key optional private key for authority caching
289 * @param timeout timeout for the resolution
290 * @param only_cached GNUNET_NO to only check locally not DHT for performance
291 * @param proc the processor to call
292 * @param cls the closure to pass to proc
295 gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone,
296 struct GNUNET_CRYPTO_ShortHashCode pzone,
297 uint32_t record_type,
299 struct GNUNET_CRYPTO_RsaPrivateKey *key,
300 struct GNUNET_TIME_Relative timeout,
302 RecordLookupProcessor proc,
306 * Shortens a name if possible. If the shortening fails
307 * name will be returned as shortened string. Else
308 * a shorter version of the name will be returned.
309 * There is no guarantee that the shortened name will
310 * actually be canonical/short etc.
312 * @param zone the zone to perform the operation in
313 * @param pzone the private local zone
314 * @param name name to shorten
315 * @param key optional private key for background lookups and PSEU import
316 * @param proc the processor to call on shorten result
317 * @param proc_cls the closure to pass to proc
320 gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode zone,
321 struct GNUNET_CRYPTO_ShortHashCode pzone,
323 struct GNUNET_CRYPTO_RsaPrivateKey *key,
324 ShortenResultProcessor proc,
328 * Tries to resolve the authority for name
331 * @param zone the root zone to look up for
332 * @param pzone the private local zone
333 * @param name the name to lookup up
334 * @param proc the processor to call when finished
335 * @param proc_cls the closure to pass to the processor
338 gns_resolver_get_authority(struct GNUNET_CRYPTO_ShortHashCode zone,
339 struct GNUNET_CRYPTO_ShortHashCode pzone,
341 GetAuthorityResultProcessor proc,
345 * Generic function to check for TLDs
347 * @param name the name to check
348 * @param tld the tld to check
349 * @return GNUNET_YES or GNUNET_NO
352 is_tld(const char* name, const char* tld);
355 * Checks for gnunet/zkey
357 #define is_gnunet_tld(name) is_tld(name, GNUNET_GNS_TLD)
358 #define is_zkey_tld(name) is_tld(name, GNUNET_GNS_TLD_ZKEY)