79e916015e9a50395ecd6c3927f150015af082fc
[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  * 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;
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;
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 };
135
136
137 /**
138  * Handle to a record lookup
139  */
140 struct RecordLookupHandle
141 {
142   /* the record type to look up */
143   enum GNUNET_GNS_RecordType record_type;
144
145   /* the name to look up */
146   char *name;
147
148   /* Method to call on record resolution result */
149   RecordLookupProcessor proc;
150
151   /* closure to pass to proc */
152   void* proc_cls;
153
154 };
155
156
157 /**
158  * Handle to a shorten context
159  */
160 struct NameShortenHandle
161 {
162
163
164   /* Method to call on shorten result */
165   ShortenResultProcessor proc;
166
167   /* closure to pass to proc */
168   void* proc_cls;
169
170 };
171
172 /**
173  * Handle to a get authority context
174  */
175 struct GetNameAuthorityHandle
176 {
177   
178   /* the name to look up authority for */
179   char* name;
180   
181   /* Method to call on result */
182   GetAuthorityResultProcessor proc;
183
184   /* closure to pass to proc */
185   void* proc_cls;
186
187 };
188
189 /**
190  * Initialize the resolver
191  *
192  * @param nh handle to the namestore
193  * @param dh handle to the dht
194  * @returns GNUNET_OK on success
195  */
196 int
197 gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh,
198                   struct GNUNET_DHT_Handle *dh);
199
200 /**
201  * Lookup of a record in a specific zone
202  * calls lookup result processor on result
203  *
204  * @param zone the root zone
205  * @param record_type the record type to look up
206  * @param proc the processor to call
207  * @param cls the closure to pass to proc
208  */
209 void
210 gns_resolver_lookup_record(GNUNET_HashCode zone,
211                            uint32_t record_type,
212                            const char* name,
213                            RecordLookupProcessor proc,
214                            void* cls);
215
216 void
217 gns_resolver_shorten_name(GNUNET_HashCode zone,
218                           const char* name,
219                           ShortenResultProcessor proc,
220                           void* cls);
221
222 /**
223  * Tries to resolve the authority for name
224  * in our namestore
225  *
226  * @param zone the root zone to look up for
227  * @param name the name to lookup up
228  * @param proc the processor to call when finished
229  * @param cls the closure to pass to the processor
230  */
231 void
232 gns_resolver_get_authority(GNUNET_HashCode zone,
233                            const char* name,
234                            GetAuthorityResultProcessor proc,
235                            void* cls);
236
237 #endif