-fixes, interceptor now speaks zkey
[oweals/gnunet.git] / src / gns / gnunet-service-gns_resolver.h
1 #ifndef GNS_RESOLVER_H
2 #define GNS_RESOLVER_H
3
4 #include "gns.h"
5 #include "gnunet_dht_service.h"
6
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
11 /*
12  * DLL to hold the authority chain
13  * we had to pass in the resolution process
14  */
15 struct AuthorityChain
16 {
17   struct AuthorityChain *prev;
18
19   struct AuthorityChain *next;
20   
21   /* the zone hash of the authority */
22   GNUNET_HashCode zone;
23
24   /* (local) name of the authority */
25   char name[MAX_DNS_LABEL_LENGTH];
26
27   /* was the ns entry fresh */
28   int fresh;
29 };
30
31 /* handle to a resolution process */
32 struct ResolverHandle;
33
34
35 /**
36  * processor for a resultion result
37  *
38  * @param cls the closure
39  * @param rh the resolution handle
40  * @param rd_count number of results
41  * @pram rd resukt data
42  */
43 typedef void (*RecordLookupProcessor) (void *cls,
44                                   uint32_t rd_count,
45                                   const struct GNUNET_NAMESTORE_RecordData *rd);
46
47
48 /**
49  * processor for a shorten result
50  *
51  * @param cls the closure
52  * @param name shortened name
53  */
54 typedef void (*ShortenResultProcessor) (void *cls, const char* name);
55
56
57 /**
58  * processor for an authority result
59  *
60  * @param cls the closure
61  * @param name name
62  */
63 typedef void (*GetAuthorityResultProcessor) (void *cls, const char* name);
64
65 /**
66  * processor for a resultion result
67  *
68  * @param cls the closure
69  * @param rh the resolution handle
70  * @param rd_count number of results
71  * @param rd result data
72  */
73 typedef void (*ResolutionResultProcessor) (void *cls,
74                                   struct ResolverHandle *rh,
75                                   uint32_t rd_count,
76                                   const struct GNUNET_NAMESTORE_RecordData *rd);
77
78
79 /**
80  * Resoltion status indicator
81  * EXISTS: the name to lookup exists
82  * EXPIRED: the name in the record expired
83  */
84 enum ResolutionStatus
85 {
86   EXISTS = 1,
87   EXPIRED = 2
88 };
89
90 /**
91  * Handle to a currenty pending resolution
92  */
93 struct ResolverHandle
94 {
95   /* The name to resolve */
96   char name[MAX_DNS_NAME_LENGTH];
97
98   /* has this query been answered? how many matches */
99   int answered;
100
101   /* the authoritative zone to query */
102   GNUNET_HashCode authority;
103
104   /* the name of the authoritative zone to query */
105   char authority_name[MAX_DNS_LABEL_LENGTH];
106
107   /**
108    * we have an authority in namestore that
109    * may be able to resolve
110    */
111   int authority_found;
112
113   /* a handle for dht lookups. should be NULL if no lookups are in progress */
114   struct GNUNET_DHT_GetHandle *get_handle;
115
116   /* timeout task for dht lookups */
117   GNUNET_SCHEDULER_TaskIdentifier dht_timeout_task;
118
119   /* called when resolution phase finishes */
120   ResolutionResultProcessor proc;
121   
122   /* closure passed to proc */
123   void* proc_cls;
124
125   /* DLL to store the authority chain */
126   struct AuthorityChain *authority_chain_head;
127
128   /* DLL to store the authority chain */
129   struct AuthorityChain *authority_chain_tail;
130   
131   /* status of the resolution result */
132   enum ResolutionStatus status;
133
134   struct GNUNET_CRYPTO_RsaPrivateKey *priv_key;
135
136 };
137
138
139 /**
140  * Handle to a record lookup
141  */
142 struct RecordLookupHandle
143 {
144   /* the record type to look up */
145   enum GNUNET_GNS_RecordType record_type;
146
147   /* the name to look up */
148   char name[MAX_DNS_NAME_LENGTH];
149
150   /* Method to call on record resolution result */
151   RecordLookupProcessor proc;
152
153   /* closure to pass to proc */
154   void* proc_cls;
155
156 };
157
158
159 /**
160  * Handle to a shorten context
161  */
162 struct NameShortenHandle
163 {
164
165
166   /* Method to call on shorten result */
167   ShortenResultProcessor proc;
168
169   /* closure to pass to proc */
170   void* proc_cls;
171
172 };
173
174 /**
175  * Handle to a get authority context
176  */
177 struct GetNameAuthorityHandle
178 {
179   
180   /* the name to look up authority for */
181   char name[MAX_DNS_NAME_LENGTH];
182   
183   /* Method to call on result */
184   GetAuthorityResultProcessor proc;
185
186   /* closure to pass to proc */
187   void* proc_cls;
188
189 };
190
191 /**
192  * Handle to a pseu lookup
193  */
194 struct GetPseuAuthorityHandle
195 {
196   /* the name given from delegation */
197   char name[MAX_DNS_LABEL_LENGTH];
198
199   /* name to store the pseu under */
200   char new_name[MAX_DNS_LABEL_LENGTH];
201   
202   /* the zone of discovered authority */
203   GNUNET_HashCode new_zone;
204
205   /* the zone of our authority */
206   GNUNET_HashCode zone;
207
208   /* the private key of the zone to store the pseu in */
209   struct GNUNET_CRYPTO_RsaPrivateKey *key;
210
211   /* a handle for dht lookups. should be NULL if no lookups are in progress */
212   struct GNUNET_DHT_GetHandle *get_handle;
213
214   /* timeout task for dht lookups */
215   GNUNET_SCHEDULER_TaskIdentifier dht_timeout;
216 };
217
218 /**
219  * Initialize the resolver
220  *
221  * @param nh handle to the namestore
222  * @param dh handle to the dht
223  * @returns GNUNET_OK on success
224  */
225 int
226 gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh,
227                   struct GNUNET_DHT_Handle *dh);
228
229 /**
230  * Lookup of a record in a specific zone
231  * calls lookup result processor on result
232  *
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
239  */
240 void
241 gns_resolver_lookup_record(GNUNET_HashCode zone,
242                            uint32_t record_type,
243                            const char* name,
244                            struct GNUNET_CRYPTO_RsaPrivateKey *key,
245                            RecordLookupProcessor proc,
246                            void* cls);
247
248 void
249 gns_resolver_shorten_name(GNUNET_HashCode zone,
250                           const char* name,
251                           ShortenResultProcessor proc,
252                           void* cls);
253
254 /**
255  * Tries to resolve the authority for name
256  * in our namestore
257  *
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
262  */
263 void
264 gns_resolver_get_authority(GNUNET_HashCode zone,
265                            const char* name,
266                            GetAuthorityResultProcessor proc,
267                            void* cls);
268
269 /**
270  * Generic function to check for TLDs
271  *
272  * @param name the name to check
273  * @param tld the tld to check
274  * @return GNUNET_YES or GNUNET_NO
275  */
276 int
277 is_tld(const char* name, const char* tld);
278
279 /**
280  * Checks for gnunet/zkey
281  */
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)
284
285
286 #endif