add convenience API to gnunetgns lib
[oweals/gnunet.git] / src / include / gnunet_gns_service.h
1 /*
2       This file is part of GNUnet
3       Copyright (C) 2012-2014, 2017 GNUnet e.V.
4
5       GNUnet is free software; you can redistribute it and/or modify
6       it under the terms of the GNU General Public License as published
7       by the Free Software Foundation; either version 3, or (at your
8       option) any later version.
9
10       GNUnet is distributed in the hope that it will be useful, but
11       WITHOUT ANY WARRANTY; without even the implied warranty of
12       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13       General Public License for more details.
14
15       You should have received a copy of the GNU General Public License
16       along with GNUnet; see the file COPYING.  If not, write to the
17       Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18       Boston, MA 02110-1301, USA.
19  */
20
21 /**
22  * @author Martin Schanzenbach
23  *
24  * @file
25  * API to the GNS service
26  *
27  * @defgroup gns  GNS service
28  * GNU Name System
29  *
30  * @see [Documentation](https://gnunet.org/gns-implementation)
31  *
32  * @{
33  */
34 #ifndef GNUNET_GNS_SERVICE_H
35 #define GNUNET_GNS_SERVICE_H
36
37 #include "gnunet_util_lib.h"
38 #include "gnunet_dnsparser_lib.h"
39 #include "gnunet_namestore_service.h"
40
41 #ifdef __cplusplus
42 extern "C"
43 {
44 #if 0                           /* keep Emacsens' auto-indent happy */
45 }
46 #endif
47 #endif
48
49
50 /**
51  * String we use to indicate the local master zone or a
52  * root entry in the current zone.
53  *
54  * FIXME: probably should be changed to "@" and renamed
55  * (this name is confusing!)
56  */
57 #define GNUNET_GNS_MASTERZONE_STR "+"
58
59 /**
60  * Connection to the GNS service.
61  */
62 struct GNUNET_GNS_Handle;
63
64 /**
65  * Handle to control a lookup operation.
66  */
67 struct GNUNET_GNS_LookupRequest;
68
69 /**
70  * Handle to control a lookup operation where the
71  * TLD is resolved to a zone as part of the lookup operation.
72  */
73 struct GNUNET_GNS_LookupWithTldRequest;
74
75
76 /**
77  * Initialize the connection with the GNS service.
78  *
79  * @param cfg configuration to use
80  * @return handle to the GNS service, or NULL on error
81  */
82 struct GNUNET_GNS_Handle *
83 GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
84
85
86 /**
87  * Shutdown connection with the GNS service.
88  *
89  * @param handle connection to shut down
90  */
91 void
92 GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle);
93
94
95 /**
96  * Iterator called on obtained result for a GNS lookup.
97  *
98  * @param cls closure
99  * @param rd_count number of records in @a rd
100  * @param rd the records in reply
101  */
102 typedef void
103 (*GNUNET_GNS_LookupResultProcessor) (void *cls,
104                                      uint32_t rd_count,
105                                      const struct GNUNET_GNSRECORD_Data *rd);
106
107
108 /**
109  * Options for the GNS lookup.
110  */
111 enum GNUNET_GNS_LocalOptions
112 {
113   /**
114    * Defaults, look in cache, then in DHT.
115    */
116   GNUNET_GNS_LO_DEFAULT = 0,
117
118   /**
119    * Never look in the DHT, keep request to local cache.
120    */
121   GNUNET_GNS_LO_NO_DHT = 1,
122
123   /**
124    * For the rightmost label, only look in the cache (it
125    * is our master zone), for the others, the DHT is OK.
126    */
127   GNUNET_GNS_LO_LOCAL_MASTER = 2
128
129 };
130
131
132 /**
133  * Perform an asynchronous lookup operation on the GNS.
134  *
135  * @param handle handle to the GNS service
136  * @param name the name to look up
137  * @param zone zone to look in
138  * @param type the GNS record type to look for
139  * @param options local options for the lookup
140  * @param proc function to call on result
141  * @param proc_cls closure for @a proc
142  * @return handle to the queued request
143  */
144 struct GNUNET_GNS_LookupRequest *
145 GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
146                    const char *name,
147                    const struct GNUNET_CRYPTO_EcdsaPublicKey *zone,
148                    uint32_t type,
149                    enum GNUNET_GNS_LocalOptions options,
150                    GNUNET_GNS_LookupResultProcessor proc,
151                    void *proc_cls);
152
153
154 /**
155  * Cancel pending lookup request
156  *
157  * @param lr the lookup request to cancel
158  */
159 void
160 GNUNET_GNS_lookup_cancel (struct GNUNET_GNS_LookupRequest *lr);
161
162
163 /**
164  * Iterator called on obtained result for a GNS lookup
165  * where "not GNS" is a valid answer.
166  *
167  * @param cls closure
168  * @param gns_tld #GNUNET_YES if a GNS lookup was attempted,
169  *                #GNUNET_NO if the TLD is not configured for GNS
170  * @param rd_count number of records in @a rd
171  * @param rd the records in the reply
172  */
173 typedef void
174 (*GNUNET_GNS_LookupResultProcessor2) (void *cls,
175                                       int gns_tld,
176                                       uint32_t rd_count,
177                                       const struct GNUNET_GNSRECORD_Data *rd);
178
179
180 /**
181  * Perform an asynchronous lookup operation on the GNS,
182  * determining the zone using the TLD of the given name
183  * and the current configuration to resolve TLDs to zones.
184  *
185  * @param handle handle to the GNS service
186  * @param name the name to look up, including TLD
187  * @param type the record type to look up
188  * @param options local options for the lookup
189  * @param proc processor to call on result
190  * @param proc_cls closure for @a proc
191  * @return handle to the get request
192  */
193 struct GNUNET_GNS_LookupWithTldRequest*
194 GNUNET_GNS_lookup_with_tld (struct GNUNET_GNS_Handle *handle,
195                             const char *name,
196                             uint32_t type,
197                             enum GNUNET_GNS_LocalOptions options,
198                             GNUNET_GNS_LookupResultProcessor2 proc,
199                             void *proc_cls);
200
201
202 /**
203  * Cancel pending lookup request
204  *
205  * @param ltr the lookup request to cancel
206  */
207 void
208 GNUNET_GNS_lookup_with_tld_cancel (struct GNUNET_GNS_LookupWithTldRequest *ltr);
209
210
211 #if 0                           /* keep Emacsens' auto-indent happy */
212 {
213 #endif
214 #ifdef __cplusplus
215 }
216 #endif
217
218 #endif
219
220 /** @} */  /* end of group */