Merge branch 'master' of gnunet.org:gnunet
[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 it
6       under the terms of the GNU Affero General Public License as published
7       by the Free Software Foundation, either version 3 of the License,
8       or (at your 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       Affero General Public License for more details.
14      
15       You should have received a copy of the GNU Affero General Public License
16       along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18      SPDX-License-Identifier: AGPL3.0-or-later
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 an empty label (top-level
52  * entry in the zone).  DNS uses "@", so do we.
53  */
54 #define GNUNET_GNS_EMPTY_LABEL_AT "@"
55
56 /**
57  * Connection to the GNS service.
58  */
59 struct GNUNET_GNS_Handle;
60
61 /**
62  * Handle to control a lookup operation.
63  */
64 struct GNUNET_GNS_LookupRequest;
65
66 /**
67  * Handle to control a lookup operation where the
68  * TLD is resolved to a zone as part of the lookup operation.
69  */
70 struct GNUNET_GNS_LookupWithTldRequest;
71
72
73 /**
74  * Initialize the connection with the GNS service.
75  *
76  * @param cfg configuration to use
77  * @return handle to the GNS service, or NULL on error
78  */
79 struct GNUNET_GNS_Handle *
80 GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
81
82
83 /**
84  * Shutdown connection with the GNS service.
85  *
86  * @param handle connection to shut down
87  */
88 void
89 GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle);
90
91
92 /**
93  * Iterator called on obtained result for a GNS lookup.
94  *
95  * @param cls closure
96  * @param rd_count number of records in @a rd
97  * @param rd the records in reply
98  */
99 typedef void
100 (*GNUNET_GNS_LookupResultProcessor) (void *cls,
101                                      uint32_t rd_count,
102                                      const struct GNUNET_GNSRECORD_Data *rd);
103
104
105 /**
106  * Options for the GNS lookup.
107  */
108 enum GNUNET_GNS_LocalOptions
109 {
110   /**
111    * Defaults, look in cache, then in DHT.
112    */
113   GNUNET_GNS_LO_DEFAULT = 0,
114
115   /**
116    * Never look in the DHT, keep request to local cache.
117    */
118   GNUNET_GNS_LO_NO_DHT = 1,
119
120   /**
121    * For the rightmost label, only look in the cache (it
122    * is our local namestore), for the others, the DHT is OK.
123    */
124   GNUNET_GNS_LO_LOCAL_MASTER = 2
125
126 };
127
128
129 /**
130  * Perform an asynchronous lookup operation on the GNS.
131  *
132  * @param handle handle to the GNS service
133  * @param name the name to look up
134  * @param zone zone to look in
135  * @param type the GNS record type to look for
136  * @param options local options for the lookup
137  * @param proc function to call on result
138  * @param proc_cls closure for @a proc
139  * @return handle to the queued request
140  */
141 struct GNUNET_GNS_LookupRequest *
142 GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
143                    const char *name,
144                    const struct GNUNET_CRYPTO_EcdsaPublicKey *zone,
145                    uint32_t type,
146                    enum GNUNET_GNS_LocalOptions options,
147                    GNUNET_GNS_LookupResultProcessor proc,
148                    void *proc_cls);
149
150
151 /**
152  * Cancel pending lookup request
153  *
154  * @param lr the lookup request to cancel
155  * @return closure from the lookup result processor
156  */
157 void *
158 GNUNET_GNS_lookup_cancel (struct GNUNET_GNS_LookupRequest *lr);
159
160
161 /**
162  * Iterator called on obtained result for a GNS lookup
163  * where "not GNS" is a valid answer.
164  *
165  * @param cls closure
166  * @param gns_tld #GNUNET_YES if a GNS lookup was attempted,
167  *                #GNUNET_NO if the TLD is not configured for GNS
168  * @param rd_count number of records in @a rd
169  * @param rd the records in the reply
170  */
171 typedef void
172 (*GNUNET_GNS_LookupResultProcessor2) (void *cls,
173                                       int gns_tld,
174                                       uint32_t rd_count,
175                                       const struct GNUNET_GNSRECORD_Data *rd);
176
177
178 /**
179  * Perform an asynchronous lookup operation on the GNS,
180  * determining the zone using the TLD of the given name
181  * and the current configuration to resolve TLDs to zones.
182  *
183  * @param handle handle to the GNS service
184  * @param name the name to look up, including TLD
185  * @param type the record type to look up
186  * @param options local options for the lookup
187  * @param proc processor to call on result
188  * @param proc_cls closure for @a proc
189  * @return handle to the get request
190  */
191 struct GNUNET_GNS_LookupWithTldRequest*
192 GNUNET_GNS_lookup_with_tld (struct GNUNET_GNS_Handle *handle,
193                             const char *name,
194                             uint32_t type,
195                             enum GNUNET_GNS_LocalOptions options,
196                             GNUNET_GNS_LookupResultProcessor2 proc,
197                             void *proc_cls);
198
199
200 /**
201  * Cancel pending lookup request
202  *
203  * @param ltr the lookup request to cancel
204  * @return closure from the lookup result processor
205  */
206 void *
207 GNUNET_GNS_lookup_with_tld_cancel (struct GNUNET_GNS_LookupWithTldRequest *ltr);
208
209
210 #if 0                           /* keep Emacsens' auto-indent happy */
211 {
212 #endif
213 #ifdef __cplusplus
214 }
215 #endif
216
217 #endif
218
219 /** @} */  /* end of group */