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