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