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
12 * DLL to hold the authority chain
13 * we had to pass in the resolution process
17 struct AuthorityChain *prev;
19 struct AuthorityChain *next;
21 /* the zone hash of the authority */
22 struct GNUNET_CRYPTO_ShortHashCode zone;
24 /* (local) name of the authority */
25 char name[MAX_DNS_LABEL_LENGTH];
27 /* was the ns entry fresh */
31 /* handle to a resolution process */
32 struct ResolverHandle;
36 * processor for a resultion result
38 * @param cls the closure
39 * @param rh the resolution handle
40 * @param rd_count number of results
41 * @pram rd resukt data
43 typedef void (*RecordLookupProcessor) (void *cls,
45 const struct GNUNET_NAMESTORE_RecordData *rd);
49 * processor for a shorten result
51 * @param cls the closure
52 * @param name shortened name
54 typedef void (*ShortenResultProcessor) (void *cls, const char* name);
58 * processor for an authority result
60 * @param cls the closure
63 typedef void (*GetAuthorityResultProcessor) (void *cls, const char* name);
66 * processor for a resultion result
68 * @param cls the closure
69 * @param rh the resolution handle
70 * @param rd_count number of results
71 * @param rd result data
73 typedef void (*ResolutionResultProcessor) (void *cls,
74 struct ResolverHandle *rh,
76 const struct GNUNET_NAMESTORE_RecordData *rd);
80 * Resoltion status indicator
81 * EXISTS: the name to lookup exists
82 * EXPIRED: the name in the record expired
91 * Handle to a currenty pending resolution
95 /* The name to resolve */
96 char name[MAX_DNS_NAME_LENGTH];
98 /* has this query been answered? how many matches */
101 /* the authoritative zone to query */
102 struct GNUNET_CRYPTO_ShortHashCode authority;
104 /* the name of the authoritative zone to query */
105 char authority_name[MAX_DNS_LABEL_LENGTH];
108 * we have an authority in namestore that
109 * may be able to resolve
113 /* a handle for dht lookups. should be NULL if no lookups are in progress */
114 struct GNUNET_DHT_GetHandle *get_handle;
116 /* timeout task for dht lookups */
117 GNUNET_SCHEDULER_TaskIdentifier dht_timeout_task;
119 /* called when resolution phase finishes */
120 ResolutionResultProcessor proc;
122 /* closure passed to proc */
125 /* DLL to store the authority chain */
126 struct AuthorityChain *authority_chain_head;
128 /* DLL to store the authority chain */
129 struct AuthorityChain *authority_chain_tail;
131 /* status of the resolution result */
132 enum ResolutionStatus status;
134 struct GNUNET_CRYPTO_RsaPrivateKey *priv_key;
140 * Handle to a record lookup
142 struct RecordLookupHandle
144 /* the record type to look up */
145 enum GNUNET_GNS_RecordType record_type;
147 /* the name to look up */
148 char name[MAX_DNS_NAME_LENGTH];
150 /* Method to call on record resolution result */
151 RecordLookupProcessor proc;
153 /* closure to pass to proc */
160 * Handle to a shorten context
162 struct NameShortenHandle
166 /* Method to call on shorten result */
167 ShortenResultProcessor proc;
169 /* closure to pass to proc */
175 * Handle to a get authority context
177 struct GetNameAuthorityHandle
180 /* the name to look up authority for */
181 char name[MAX_DNS_NAME_LENGTH];
183 /* Method to call on result */
184 GetAuthorityResultProcessor proc;
186 /* closure to pass to proc */
192 * Handle to a pseu lookup
194 struct GetPseuAuthorityHandle
196 /* the name given from delegation */
197 char name[MAX_DNS_LABEL_LENGTH];
199 /* name to store the pseu under */
200 char new_name[MAX_DNS_LABEL_LENGTH];
202 /* the zone of discovered authority */
203 struct GNUNET_CRYPTO_ShortHashCode new_zone;
205 /* the zone of our authority */
206 struct GNUNET_CRYPTO_ShortHashCode zone;
208 /* the private key of the zone to store the pseu in */
209 struct GNUNET_CRYPTO_RsaPrivateKey *key;
211 /* a handle for dht lookups. should be NULL if no lookups are in progress */
212 struct GNUNET_DHT_GetHandle *get_handle;
214 /* timeout task for dht lookups */
215 GNUNET_SCHEDULER_TaskIdentifier dht_timeout;
219 * Initialize the resolver
221 * @param nh handle to the namestore
222 * @param dh handle to the dht
223 * @returns GNUNET_OK on success
226 gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh,
227 struct GNUNET_DHT_Handle *dh);
230 * Lookup of a record in a specific zone
231 * calls lookup result processor on result
233 * @param zone the root zone
234 * @param record_type the record type to look up
235 * @param name the name to look up
236 * @param key optional private key for authority caching
237 * @param proc the processor to call
238 * @param cls the closure to pass to proc
241 gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone,
242 uint32_t record_type,
244 struct GNUNET_CRYPTO_RsaPrivateKey *key,
245 RecordLookupProcessor proc,
249 gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode zone,
251 ShortenResultProcessor proc,
255 * Tries to resolve the authority for name
258 * @param zone the root zone to look up for
259 * @param name the name to lookup up
260 * @param proc the processor to call when finished
261 * @param cls the closure to pass to the processor
264 gns_resolver_get_authority(struct GNUNET_CRYPTO_ShortHashCode zone,
266 GetAuthorityResultProcessor proc,
270 * Generic function to check for TLDs
272 * @param name the name to check
273 * @param tld the tld to check
274 * @return GNUNET_YES or GNUNET_NO
277 is_tld(const char* name, const char* tld);
280 * Checks for gnunet/zkey
282 #define is_gnunet_tld(name) is_tld(name, GNUNET_GNS_TLD)
283 #define is_zkey_tld(name) is_tld(name, GNUNET_GNS_TLD_ZKEY)