5 #include "gnunet_dht_service.h"
7 #define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
8 #define DHT_LOOKUP_TIMEOUT DHT_OPERATION_TIMEOUT
9 #define DHT_GNS_REPLICATION_LEVEL 5
10 #define MAX_DNS_LABEL_LENGTH 63
11 #define MAX_DNS_NAME_LENGTH 253
14 * DLL to hold the authority chain
15 * we had to pass in the resolution process
19 struct AuthorityChain *prev;
21 struct AuthorityChain *next;
23 /* the zone hash of the authority */
26 /* (local) name of the authority */
27 char name[MAX_DNS_LABEL_LENGTH];
29 /* was the ns entry fresh */
33 /* handle to a resolution process */
34 struct ResolverHandle;
38 * processor for a resultion result
40 * @param cls the closure
41 * @param rh the resolution handle
42 * @param rd_count number of results
43 * @pram rd resukt data
45 typedef void (*RecordLookupProcessor) (void *cls,
47 const struct GNUNET_NAMESTORE_RecordData *rd);
51 * processor for a shorten result
53 * @param cls the closure
54 * @param name shortened name
56 typedef void (*ShortenResultProcessor) (void *cls, const char* name);
60 * processor for an authority result
62 * @param cls the closure
65 typedef void (*GetAuthorityResultProcessor) (void *cls, const char* name);
68 * processor for a resultion result
70 * @param cls the closure
71 * @param rh the resolution handle
72 * @param rd_count number of results
73 * @param rd result data
75 typedef void (*ResolutionResultProcessor) (void *cls,
76 struct ResolverHandle *rh,
78 const struct GNUNET_NAMESTORE_RecordData *rd);
82 * Resoltion status indicator
83 * EXISTS: the name to lookup exists
84 * EXPIRED: the name in the record expired
93 * Handle to a currenty pending resolution
97 /* The name to resolve */
98 char name[MAX_DNS_NAME_LENGTH];
100 /* has this query been answered? how many matches */
103 /* the authoritative zone to query */
104 GNUNET_HashCode authority;
106 /* the name of the authoritative zone to query */
107 char authority_name[MAX_DNS_LABEL_LENGTH];
110 * we have an authority in namestore that
111 * may be able to resolve
115 /* a handle for dht lookups. should be NULL if no lookups are in progress */
116 struct GNUNET_DHT_GetHandle *get_handle;
118 /* timeout task for dht lookups */
119 GNUNET_SCHEDULER_TaskIdentifier dht_timeout_task;
121 /* called when resolution phase finishes */
122 ResolutionResultProcessor proc;
124 /* closure passed to proc */
127 /* DLL to store the authority chain */
128 struct AuthorityChain *authority_chain_head;
130 /* DLL to store the authority chain */
131 struct AuthorityChain *authority_chain_tail;
133 /* status of the resolution result */
134 enum ResolutionStatus status;
136 struct GNUNET_CRYPTO_RsaPrivateKey *priv_key;
142 * Handle to a record lookup
144 struct RecordLookupHandle
146 /* the record type to look up */
147 enum GNUNET_GNS_RecordType record_type;
149 /* the name to look up */
150 char name[MAX_DNS_NAME_LENGTH];
152 /* Method to call on record resolution result */
153 RecordLookupProcessor proc;
155 /* closure to pass to proc */
162 * Handle to a shorten context
164 struct NameShortenHandle
168 /* Method to call on shorten result */
169 ShortenResultProcessor proc;
171 /* closure to pass to proc */
177 * Handle to a get authority context
179 struct GetNameAuthorityHandle
182 /* the name to look up authority for */
183 char name[MAX_DNS_NAME_LENGTH];
185 /* Method to call on result */
186 GetAuthorityResultProcessor proc;
188 /* closure to pass to proc */
194 * Handle to a pseu lookup
196 struct GetPseuAuthorityHandle
198 /* the name given from delegation */
199 char name[MAX_DNS_LABEL_LENGTH];
201 /* name to store the pseu under */
202 char new_name[MAX_DNS_LABEL_LENGTH];
204 /* the zone of discovered authority */
205 GNUNET_HashCode new_zone;
207 /* the zone of our authority */
208 GNUNET_HashCode zone;
210 /* the private key of the zone to store the pseu in */
211 struct GNUNET_CRYPTO_RsaPrivateKey *key;
213 /* a handle for dht lookups. should be NULL if no lookups are in progress */
214 struct GNUNET_DHT_GetHandle *get_handle;
216 /* timeout task for dht lookups */
217 GNUNET_SCHEDULER_TaskIdentifier dht_timeout;
221 * Initialize the resolver
223 * @param nh handle to the namestore
224 * @param dh handle to the dht
225 * @returns GNUNET_OK on success
228 gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh,
229 struct GNUNET_DHT_Handle *dh);
232 * Lookup of a record in a specific zone
233 * calls lookup result processor on result
235 * @param zone the root zone
236 * @param record_type the record type to look up
237 * @param name the name to look up
238 * @param key optional private key for authority caching
239 * @param proc the processor to call
240 * @param cls the closure to pass to proc
243 gns_resolver_lookup_record(GNUNET_HashCode zone,
244 uint32_t record_type,
246 struct GNUNET_CRYPTO_RsaPrivateKey *key,
247 RecordLookupProcessor proc,
251 gns_resolver_shorten_name(GNUNET_HashCode zone,
253 ShortenResultProcessor proc,
257 * Tries to resolve the authority for name
260 * @param zone the root zone to look up for
261 * @param name the name to lookup up
262 * @param proc the processor to call when finished
263 * @param cls the closure to pass to the processor
266 gns_resolver_get_authority(GNUNET_HashCode zone,
268 GetAuthorityResultProcessor proc,