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;
148 * private key of an/our authoritative zone
149 * can be NULL but automatical PKEY import will not work
151 struct GNUNET_CRYPTO_RsaPrivateKey *priv_key;
154 * the heap node associated with this lookup, null if timeout is set
155 * used for DHT background lookups.
157 struct GNUNET_CONTAINER_HeapNode *dht_heap_node;
163 * Handle to a record lookup
165 struct RecordLookupHandle
167 /* the record type to look up */
168 enum GNUNET_GNS_RecordType record_type;
170 /* the name to look up */
171 char name[MAX_DNS_NAME_LENGTH];
173 /* Method to call on record resolution result */
174 RecordLookupProcessor proc;
176 /* closure to pass to proc */
183 * Handle to a shorten context
185 struct NameShortenHandle
189 /* Method to call on shorten result */
190 ShortenResultProcessor proc;
192 /* closure to pass to proc */
198 * Handle to a get authority context
200 struct GetNameAuthorityHandle
203 /* the name to look up authority for */
204 char name[MAX_DNS_NAME_LENGTH];
206 /* Method to call on result */
207 GetAuthorityResultProcessor proc;
209 /* closure to pass to proc */
215 * Handle to a pseu lookup
217 struct GetPseuAuthorityHandle
219 /* the name given from delegation */
220 char name[MAX_DNS_LABEL_LENGTH];
222 /* name to store the pseu under */
223 char new_name[MAX_DNS_LABEL_LENGTH];
225 /* the zone of discovered authority */
226 struct GNUNET_CRYPTO_ShortHashCode new_zone;
228 /* the zone of our authority */
229 struct GNUNET_CRYPTO_ShortHashCode zone;
231 /* the private key of the zone to store the pseu in */
232 struct GNUNET_CRYPTO_RsaPrivateKey *key;
234 /* a handle for dht lookups. should be NULL if no lookups are in progress */
235 struct GNUNET_DHT_GetHandle *get_handle;
237 /* timeout task for lookup */
238 GNUNET_SCHEDULER_TaskIdentifier timeout;
242 * Initialize the resolver
243 * MUST be called before other gns_resolver_* methods
245 * @param nh handle to the namestore
246 * @param dh handle to the dht
247 * @returns GNUNET_OK on success
250 gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh,
251 struct GNUNET_DHT_Handle *dh);
254 * Lookup of a record in a specific zone
255 * calls lookup result processor on result
257 * @param zone the root zone
258 * @param record_type the record type to look up
259 * @param name the name to look up
260 * @param key optional private key for authority caching
261 * @param proc the processor to call
262 * @param cls the closure to pass to proc
265 gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone,
266 uint32_t record_type,
268 struct GNUNET_CRYPTO_RsaPrivateKey *key,
269 struct GNUNET_TIME_Relative timeout,
270 RecordLookupProcessor proc,
274 * Shortens a name if possible. If the shortening fails
275 * name will be returned as shortened string. Else
276 * a shorter version of the name will be returned.
277 * There is no guarantee that the shortened name will
278 * actually be canonical/short etc.
280 * @param zone the zone to perform the operation in
281 * @param name name to shorten
282 * @param proc the processor to call on shorten result
283 * @param proc_cls teh closure to pass to proc
286 gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode zone,
288 ShortenResultProcessor proc,
292 * Tries to resolve the authority for name
295 * @param zone the root zone to look up for
296 * @param name the name to lookup up
297 * @param proc the processor to call when finished
298 * @param cls the closure to pass to the processor
301 gns_resolver_get_authority(struct GNUNET_CRYPTO_ShortHashCode zone,
303 GetAuthorityResultProcessor proc,
307 * Generic function to check for TLDs
309 * @param name the name to check
310 * @param tld the tld to check
311 * @return GNUNET_YES or GNUNET_NO
314 is_tld(const char* name, const char* tld);
317 * Checks for gnunet/zkey
319 #define is_gnunet_tld(name) is_tld(name, GNUNET_GNS_TLD)
320 #define is_zkey_tld(name) is_tld(name, GNUNET_GNS_TLD_ZKEY)