ff3110406a654ed9c4c400990a66d7027b800674
[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 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  */
156 void
157 GNUNET_GNS_lookup_cancel (struct GNUNET_GNS_LookupRequest *lr);
158
159
160 /**
161  * Iterator called on obtained result for a GNS lookup
162  * where "not GNS" is a valid answer.
163  *
164  * @param cls closure
165  * @param gns_tld #GNUNET_YES if a GNS lookup was attempted,
166  *                #GNUNET_NO if the TLD is not configured for GNS
167  * @param rd_count number of records in @a rd
168  * @param rd the records in the reply
169  */
170 typedef void
171 (*GNUNET_GNS_LookupResultProcessor2) (void *cls,
172                                       int gns_tld,
173                                       uint32_t rd_count,
174                                       const struct GNUNET_GNSRECORD_Data *rd);
175
176
177 /**
178  * Perform an asynchronous lookup operation on the GNS,
179  * determining the zone using the TLD of the given name
180  * and the current configuration to resolve TLDs to zones.
181  *
182  * @param handle handle to the GNS service
183  * @param name the name to look up, including TLD
184  * @param type the record type to look up
185  * @param options local options for the lookup
186  * @param proc processor to call on result
187  * @param proc_cls closure for @a proc
188  * @return handle to the get request
189  */
190 struct GNUNET_GNS_LookupWithTldRequest*
191 GNUNET_GNS_lookup_with_tld (struct GNUNET_GNS_Handle *handle,
192                             const char *name,
193                             uint32_t type,
194                             enum GNUNET_GNS_LocalOptions options,
195                             GNUNET_GNS_LookupResultProcessor2 proc,
196                             void *proc_cls);
197
198
199 /**
200  * Cancel pending lookup request
201  *
202  * @param ltr the lookup request to cancel
203  */
204 void
205 GNUNET_GNS_lookup_with_tld_cancel (struct GNUNET_GNS_LookupWithTldRequest *ltr);
206
207
208 #if 0                           /* keep Emacsens' auto-indent happy */
209 {
210 #endif
211 #ifdef __cplusplus
212 }
213 #endif
214
215 #endif
216
217 /** @} */  /* end of group */