2b0c4755d7a1d061ec4bb6bd52c87636466f2065
[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
6 #define DHT_OPERATION_TIMEOUT  GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
7 #define DHT_LOOKUP_TIMEOUT DHT_OPERATION_TIMEOUT
8 #define DHT_GNS_REPLICATION_LEVEL 5
9 #define MAX_DNS_LABEL_LENGTH 63
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;
26
27   /* was the ns entry fresh */
28   int fresh;
29 };
30
31 /* handle to a resolution process */
32 struct ResolverHandle;
33
34 /**
35  * processor for a resultion result
36  *
37  * @param cls the closure
38  * @param rh the resolution handle
39  * @param rd_count number of results
40  * @pram rd resukt data
41  */
42 typedef void (*RecordLookupProcessor) (void *cls,
43                                   uint32_t rd_count,
44                                   const struct GNUNET_NAMESTORE_RecordData *rd);
45
46
47 /**
48  * processor for a shorten result
49  *
50  * @param cls the closure
51  * @param name shortened name
52  */
53 typedef void (*ShortenResultProcessor) (void *cls, const char* name);
54
55
56 /**
57  * processor for an authority result
58  *
59  * @param cls the closure
60  * @param name name
61  */
62 typedef void (*GetAuthorityResultProcessor) (void *cls, const char* name);
63
64 /**
65  * processor for a resultion result
66  *
67  * @param cls the closure
68  * @param rh the resolution handle
69  * @param rd_count number of results
70  * @param rd result data
71  */
72 typedef void (*ResolutionResultProcessor) (void *cls,
73                                   struct ResolverHandle *rh,
74                                   uint32_t rd_count,
75                                   const struct GNUNET_NAMESTORE_RecordData *rd);
76
77
78 /**
79  * Resoltion status indicator
80  * EXISTS: the name to lookup exists
81  * EXPIRED: the name in the record expired
82  */
83 enum ResolutionStatus
84 {
85   EXISTS = 1,
86   EXPIRED = 2
87 };
88
89 /**
90  * Handle to a currenty pending resolution
91  */
92 struct ResolverHandle
93 {
94   /* The name to resolve */
95   char *name;
96
97   /* has this query been answered? how many matches */
98   int answered;
99
100   /* the authoritative zone to query */
101   GNUNET_HashCode authority;
102
103   /* the name of the authoritative zone to query */
104   char *authority_name;
105
106   /**
107    * we have an authority in namestore that
108    * may be able to resolve
109    */
110   int authority_found;
111
112   /* a handle for dht lookups. should be NULL if no lookups are in progress */
113   struct GNUNET_DHT_GetHandle *get_handle;
114
115   /* timeout task for dht lookups */
116   GNUNET_SCHEDULER_TaskIdentifier dht_timeout_task;
117
118   /* called when resolution phase finishes */
119   ResolutionResultProcessor proc;
120   
121   /* closure passed to proc */
122   void* proc_cls;
123
124   /* DLL to store the authority chain */
125   struct AuthorityChain *authority_chain_head;
126
127   /* DLL to store the authority chain */
128   struct AuthorityChain *authority_chain_tail;
129   
130   /* status of the resolution result */
131   enum ResolutionStatus status;
132
133 };
134
135
136 /**
137  * Handle to a record lookup
138  */
139 struct RecordLookupHandle
140 {
141   /* the record type to look up */
142   enum GNUNET_GNS_RecordType record_type;
143
144   /* the name to look up */
145   char *name;
146
147   /* Method to call on record resolution result */
148   RecordLookupProcessor proc;
149
150   /* closure to pass to proc */
151   void* proc_cls;
152
153 };
154
155
156 /**
157  * Handle to a shorten context
158  */
159 struct NameShortenHandle
160 {
161
162
163   /* Method to call on shorten result */
164   ShortenResultProcessor proc;
165
166   /* closure to pass to proc */
167   void* proc_cls;
168
169 };
170
171 /**
172  * Handle to a get authority context
173  */
174 struct GetNameAuthorityHandle
175 {
176   
177   /* the name to look up authority for */
178   char* name;
179   
180   /* Method to call on result */
181   GetAuthorityResultProcessor proc;
182
183   /* closure to pass to proc */
184   void* proc_cls;
185
186 };
187
188
189 /**
190  * Lookup of a record in a specific zone
191  * calls lookup result processor on result
192  *
193  * @param zone the root zone
194  * @param record_type the record type to look up
195  * @param proc the processor to call
196  * @param cls the closure to pass to proc
197  */
198 void
199 gns_resolver_lookup_record(GNUNET_HashCode zone,
200                            uint32_t record_type,
201                            const char* name,
202                            RecordLookupProcessor proc,
203                            void* cls);
204
205 void
206 gns_resolver_shorten_name(GNUNET_HashCode zone,
207                           const char* name,
208                           ShortenResultProcessor proc,
209                           void* cls);
210
211 /**
212  * Tries to resolve the authority for name
213  * in our namestore
214  *
215  * @param zone the root zone to look up for
216  * @param name the name to lookup up
217  * @param proc the processor to call when finished
218  * @param cls the closure to pass to the processor
219  */
220 void
221 gns_resolver_get_authority(GNUNET_HashCode zone,
222                            const char* name,
223                            GetAuthorityResultProcessor proc,
224                            void* cls);
225
226 #endif