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
95 * Handle to a currenty pending resolution
99 /* The name to resolve */
100 char name[MAX_DNS_NAME_LENGTH];
102 /* has this query been answered? how many matches */
105 /* the authoritative zone to query */
106 struct GNUNET_CRYPTO_ShortHashCode authority;
108 /* the name of the authoritative zone to query */
109 char authority_name[MAX_DNS_LABEL_LENGTH];
112 * we have an authority in namestore that
113 * may be able to resolve
117 /* a handle for dht lookups. should be NULL if no lookups are in progress */
118 struct GNUNET_DHT_GetHandle *get_handle;
120 /* timeout set for this lookup task */
121 struct GNUNET_TIME_Relative timeout;
123 /* timeout task for the lookup */
124 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
126 /* continuation to call on timeout */
127 GNUNET_SCHEDULER_Task timeout_cont;
129 /* closure for timeout cont */
130 void* timeout_cont_cls;
132 /* called when resolution phase finishes */
133 ResolutionResultProcessor proc;
135 /* closure passed to proc */
138 /* DLL to store the authority chain */
139 struct AuthorityChain *authority_chain_head;
141 /* DLL to store the authority chain */
142 struct AuthorityChain *authority_chain_tail;
144 /* status of the resolution result */
145 enum ResolutionStatus status;
147 struct GNUNET_CRYPTO_RsaPrivateKey *priv_key;
149 /* the heap node associated with this lookup, null if timeout is set */
150 struct GNUNET_CONTAINER_HeapNode *dht_heap_node;
156 * Handle to a record lookup
158 struct RecordLookupHandle
160 /* the record type to look up */
161 enum GNUNET_GNS_RecordType record_type;
163 /* the name to look up */
164 char name[MAX_DNS_NAME_LENGTH];
166 /* Method to call on record resolution result */
167 RecordLookupProcessor proc;
169 /* closure to pass to proc */
176 * Handle to a shorten context
178 struct NameShortenHandle
182 /* Method to call on shorten result */
183 ShortenResultProcessor proc;
185 /* closure to pass to proc */
191 * Handle to a get authority context
193 struct GetNameAuthorityHandle
196 /* the name to look up authority for */
197 char name[MAX_DNS_NAME_LENGTH];
199 /* Method to call on result */
200 GetAuthorityResultProcessor proc;
202 /* closure to pass to proc */
208 * Handle to a pseu lookup
210 struct GetPseuAuthorityHandle
212 /* the name given from delegation */
213 char name[MAX_DNS_LABEL_LENGTH];
215 /* name to store the pseu under */
216 char new_name[MAX_DNS_LABEL_LENGTH];
218 /* the zone of discovered authority */
219 struct GNUNET_CRYPTO_ShortHashCode new_zone;
221 /* the zone of our authority */
222 struct GNUNET_CRYPTO_ShortHashCode zone;
224 /* the private key of the zone to store the pseu in */
225 struct GNUNET_CRYPTO_RsaPrivateKey *key;
227 /* a handle for dht lookups. should be NULL if no lookups are in progress */
228 struct GNUNET_DHT_GetHandle *get_handle;
230 /* timeout task for lookup */
231 GNUNET_SCHEDULER_TaskIdentifier timeout;
235 * Initialize the resolver
237 * @param nh handle to the namestore
238 * @param dh handle to the dht
239 * @returns GNUNET_OK on success
242 gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh,
243 struct GNUNET_DHT_Handle *dh);
246 * Lookup of a record in a specific zone
247 * calls lookup result processor on result
249 * @param zone the root zone
250 * @param record_type the record type to look up
251 * @param name the name to look up
252 * @param key optional private key for authority caching
253 * @param proc the processor to call
254 * @param cls the closure to pass to proc
257 gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone,
258 uint32_t record_type,
260 struct GNUNET_CRYPTO_RsaPrivateKey *key,
261 struct GNUNET_TIME_Relative timeout,
262 RecordLookupProcessor proc,
266 gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode zone,
268 ShortenResultProcessor proc,
272 * Tries to resolve the authority for name
275 * @param zone the root zone to look up for
276 * @param name the name to lookup up
277 * @param proc the processor to call when finished
278 * @param cls the closure to pass to the processor
281 gns_resolver_get_authority(struct GNUNET_CRYPTO_ShortHashCode zone,
283 GetAuthorityResultProcessor proc,
287 * Generic function to check for TLDs
289 * @param name the name to check
290 * @param tld the tld to check
291 * @return GNUNET_YES or GNUNET_NO
294 is_tld(const char* name, const char* tld);
297 * Checks for gnunet/zkey
299 #define is_gnunet_tld(name) is_tld(name, GNUNET_GNS_TLD)
300 #define is_zkey_tld(name) is_tld(name, GNUNET_GNS_TLD_ZKEY)