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;
40 * processor for a resultion result
42 * @param cls the closure
43 * @param rh the resolution handle
44 * @param rd_count number of results
45 * @pram rd resukt data
47 typedef void (*RecordLookupProcessor) (void *cls,
49 const struct GNUNET_NAMESTORE_RecordData *rd);
53 * processor for a shorten result
55 * @param cls the closure
56 * @param name shortened name
58 typedef void (*ShortenResultProcessor) (void *cls, const char* name);
62 * processor for an authority result
64 * @param cls the closure
67 typedef void (*GetAuthorityResultProcessor) (void *cls, const char* name);
70 * processor for a resultion result
72 * @param cls the closure
73 * @param rh the resolution handle
74 * @param rd_count number of results
75 * @param rd result data
77 typedef void (*ResolutionResultProcessor) (void *cls,
78 struct ResolverHandle *rh,
80 const struct GNUNET_NAMESTORE_RecordData *rd);
84 * Resoltion status indicator
85 * EXISTS: the name to lookup exists
86 * EXPIRED: the name in the record expired
96 * Handle to a currenty pending resolution
100 /* The name to resolve */
101 char name[MAX_DNS_NAME_LENGTH];
103 /* has this query been answered? how many matches */
106 /* the authoritative zone to query */
107 struct GNUNET_CRYPTO_ShortHashCode authority;
109 /* the name of the authoritative zone to query */
110 char authority_name[MAX_DNS_LABEL_LENGTH];
113 * we have an authority in namestore that
114 * may be able to resolve
118 /* a handle for dht lookups. should be NULL if no lookups are in progress */
119 struct GNUNET_DHT_GetHandle *get_handle;
121 /* timeout set for this lookup task */
122 struct GNUNET_TIME_Relative timeout;
124 /* timeout task for the lookup */
125 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
127 /* continuation to call on timeout */
128 GNUNET_SCHEDULER_Task timeout_cont;
130 /* closure for timeout cont */
131 void* timeout_cont_cls;
133 /* called when resolution phase finishes */
134 ResolutionResultProcessor proc;
136 /* closure passed to proc */
139 /* DLL to store the authority chain */
140 struct AuthorityChain *authority_chain_head;
142 /* DLL to store the authority chain */
143 struct AuthorityChain *authority_chain_tail;
145 /* status of the resolution result */
146 enum ResolutionStatus status;
149 * private key of an/our authoritative zone
150 * can be NULL but automatical PKEY import will not work
152 struct GNUNET_CRYPTO_RsaPrivateKey *priv_key;
155 * the heap node associated with this lookup, null if timeout is set
156 * used for DHT background lookups.
158 struct GNUNET_CONTAINER_HeapNode *dht_heap_node;
164 * Handle to a record lookup
166 struct RecordLookupHandle
168 /* the record type to look up */
169 enum GNUNET_GNS_RecordType record_type;
171 /* the name to look up */
172 char name[MAX_DNS_NAME_LENGTH];
174 /* Method to call on record resolution result */
175 RecordLookupProcessor proc;
177 /* closure to pass to proc */
184 * Handle to a shorten context
186 struct NameShortenHandle
190 /* Method to call on shorten result */
191 ShortenResultProcessor proc;
193 /* closure to pass to proc */
199 * Handle to a get authority context
201 struct GetNameAuthorityHandle
204 /* the name to look up authority for */
205 char name[MAX_DNS_NAME_LENGTH];
207 /* Method to call on result */
208 GetAuthorityResultProcessor proc;
210 /* closure to pass to proc */
216 * Handle to a pseu lookup
218 struct GetPseuAuthorityHandle
220 /* the name given from delegation */
221 char name[MAX_DNS_LABEL_LENGTH];
223 /* name to store the pseu under */
224 char new_name[MAX_DNS_LABEL_LENGTH];
226 /* the zone of discovered authority */
227 struct GNUNET_CRYPTO_ShortHashCode new_zone;
229 /* the zone of our authority */
230 struct GNUNET_CRYPTO_ShortHashCode zone;
232 /* the private key of the zone to store the pseu in */
233 struct GNUNET_CRYPTO_RsaPrivateKey *key;
235 /* a handle for dht lookups. should be NULL if no lookups are in progress */
236 struct GNUNET_DHT_GetHandle *get_handle;
238 /* timeout task for lookup */
239 GNUNET_SCHEDULER_TaskIdentifier timeout;
243 * Initialize the resolver
244 * MUST be called before other gns_resolver_* methods
246 * @param nh handle to the namestore
247 * @param dh handle to the dht
248 * @param local_zone the local zone
249 * @param max_bg_queries maximum amount of background queries
250 * @returns GNUNET_OK on success
253 gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh,
254 struct GNUNET_DHT_Handle *dh,
255 struct GNUNET_CRYPTO_ShortHashCode local_zone,
256 unsigned long long max_bg_queries);
259 * Cleanup resolver: Terminate pending lookups
262 gns_resolver_cleanup(void);
265 * Lookup of a record in a specific zone
266 * calls lookup result processor on result
268 * @param zone the root zone
269 * @param record_type the record type to look up
270 * @param name the name to look up
271 * @param key optional private key for authority caching
272 * @param proc the processor to call
273 * @param cls the closure to pass to proc
276 gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone,
277 uint32_t record_type,
279 struct GNUNET_CRYPTO_RsaPrivateKey *key,
280 struct GNUNET_TIME_Relative timeout,
281 RecordLookupProcessor proc,
285 * Shortens a name if possible. If the shortening fails
286 * name will be returned as shortened string. Else
287 * a shorter version of the name will be returned.
288 * There is no guarantee that the shortened name will
289 * actually be canonical/short etc.
291 * @param zone the zone to perform the operation in
292 * @param name name to shorten
293 * @param proc the processor to call on shorten result
294 * @param proc_cls teh closure to pass to proc
297 gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode zone,
299 ShortenResultProcessor proc,
303 * Tries to resolve the authority for name
306 * @param zone the root zone to look up for
307 * @param name the name to lookup up
308 * @param proc the processor to call when finished
309 * @param cls the closure to pass to the processor
312 gns_resolver_get_authority(struct GNUNET_CRYPTO_ShortHashCode zone,
314 GetAuthorityResultProcessor proc,
318 * Generic function to check for TLDs
320 * @param name the name to check
321 * @param tld the tld to check
322 * @return GNUNET_YES or GNUNET_NO
325 is_tld(const char* name, const char* tld);
328 * Checks for gnunet/zkey
330 #define is_gnunet_tld(name) is_tld(name, GNUNET_GNS_TLD)
331 #define is_zkey_tld(name) is_tld(name, GNUNET_GNS_TLD_ZKEY)