5 #include "gnunet_dht_service.h"
7 #define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
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 resultion result
46 * @param cls the closure
47 * @param rd_count number of results
48 * @param rd resukt 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 resultion 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 * Resoltion status indicator
88 * EXISTS: the name to lookup exists
89 * EXPIRED: the name in the record expired
99 * Handle to a currenty pending resolution
101 struct ResolverHandle
103 /* The name to resolve */
104 char name[MAX_DNS_NAME_LENGTH];
106 /* has this query been answered? how many matches */
109 /* the authoritative zone to query */
110 struct GNUNET_CRYPTO_ShortHashCode authority;
112 /* the name of the authoritative zone to query */
113 char authority_name[MAX_DNS_LABEL_LENGTH];
116 * we have an authority in namestore that
117 * may be able to resolve
121 /* a handle for dht lookups. should be NULL if no lookups are in progress */
122 struct GNUNET_DHT_GetHandle *get_handle;
124 /* timeout set for this lookup task */
125 struct GNUNET_TIME_Relative timeout;
127 /* timeout task for the lookup */
128 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
130 /* continuation to call on timeout */
131 GNUNET_SCHEDULER_Task timeout_cont;
133 /* closure for timeout cont */
134 void* timeout_cont_cls;
136 /* called when resolution phase finishes */
137 ResolutionResultProcessor proc;
139 /* closure passed to proc */
142 /* DLL to store the authority chain */
143 struct AuthorityChain *authority_chain_head;
145 /* DLL to store the authority chain */
146 struct AuthorityChain *authority_chain_tail;
148 /* status of the resolution result */
149 enum ResolutionStatus status;
152 * private key of an/our authoritative zone
153 * can be NULL but automatical PKEY import will not work
155 struct GNUNET_CRYPTO_RsaPrivateKey *priv_key;
158 * the heap node associated with this lookup, null if timeout is set
159 * used for DHT background lookups.
161 struct GNUNET_CONTAINER_HeapNode *dht_heap_node;
164 * Id for resolution process
166 unsigned long long id;
172 * Handle to a record lookup
174 struct RecordLookupHandle
176 /* the record type to look up */
177 enum GNUNET_GNS_RecordType record_type;
179 /* the name to look up */
180 char name[MAX_DNS_NAME_LENGTH];
182 /* Method to call on record resolution result */
183 RecordLookupProcessor proc;
185 /* closure to pass to proc */
192 * Handle to a shorten context
194 struct NameShortenHandle
198 /* Method to call on shorten result */
199 ShortenResultProcessor proc;
201 /* closure to pass to proc */
207 * Handle to a get authority context
209 struct GetNameAuthorityHandle
212 /* the name to look up authority for */
213 char name[MAX_DNS_NAME_LENGTH];
215 /* Method to call on result */
216 GetAuthorityResultProcessor proc;
218 /* closure to pass to proc */
224 * Handle to a pseu lookup
226 struct GetPseuAuthorityHandle
228 /* the name given from delegation */
229 char name[MAX_DNS_LABEL_LENGTH];
231 /* name to store the pseu under */
232 char new_name[MAX_DNS_LABEL_LENGTH];
234 /* the zone of discovered authority */
235 struct GNUNET_CRYPTO_ShortHashCode new_zone;
237 /* the zone of our authority */
238 struct GNUNET_CRYPTO_ShortHashCode 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;
251 * Initialize the resolver
252 * MUST be called before other gns_resolver_* methods
254 * @param nh handle to the namestore
255 * @param dh handle to the dht
256 * @param lz the local zone
257 * @param max_bg_queries maximum amount of background queries
258 * @returns GNUNET_OK on success
261 gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh,
262 struct GNUNET_DHT_Handle *dh,
263 struct GNUNET_CRYPTO_ShortHashCode lz,
264 unsigned long long max_bg_queries);
267 * Cleanup resolver: Terminate pending lookups
269 * @param cont continuation to call when finished
272 gns_resolver_cleanup(ResolverCleanupContinuation cont);
275 * Lookup of a record in a specific zone
276 * calls lookup result processor on result
278 * @param zone the root zone
279 * @param record_type the record type to look up
280 * @param name the name to look up
281 * @param key optional private key for authority caching
282 * @param timeout timeout for the resolution
283 * @param proc the processor to call
284 * @param cls the closure to pass to proc
287 gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone,
288 uint32_t record_type,
290 struct GNUNET_CRYPTO_RsaPrivateKey *key,
291 struct GNUNET_TIME_Relative timeout,
292 RecordLookupProcessor proc,
296 * Shortens a name if possible. If the shortening fails
297 * name will be returned as shortened string. Else
298 * a shorter version of the name will be returned.
299 * There is no guarantee that the shortened name will
300 * actually be canonical/short etc.
302 * @param zone the zone to perform the operation in
303 * @param name name to shorten
304 * @param key optional private key for background lookups and PSEU import
305 * @param proc the processor to call on shorten result
306 * @param proc_cls the closure to pass to proc
309 gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode zone,
311 struct GNUNET_CRYPTO_RsaPrivateKey *key,
312 ShortenResultProcessor proc,
316 * Tries to resolve the authority for name
319 * @param zone the root zone to look up for
320 * @param name the name to lookup up
321 * @param proc the processor to call when finished
322 * @param proc_cls the closure to pass to the processor
325 gns_resolver_get_authority(struct GNUNET_CRYPTO_ShortHashCode zone,
327 GetAuthorityResultProcessor proc,
331 * Generic function to check for TLDs
333 * @param name the name to check
334 * @param tld the tld to check
335 * @return GNUNET_YES or GNUNET_NO
338 is_tld(const char* name, const char* tld);
341 * Checks for gnunet/zkey
343 #define is_gnunet_tld(name) is_tld(name, GNUNET_GNS_TLD)
344 #define is_zkey_tld(name) is_tld(name, GNUNET_GNS_TLD_ZKEY)