move to new client API: remove old client API
[oweals/gnunet.git] / src / include / gnunet_gns_service.h
1 /*
2       This file is part of GNUnet
3       Copyright (C) 2012-2014 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 #define GNUNET_GNS_MASTERZONE_STR "+"
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 /**
68  * Initialize the connection with the GNS service.
69  *
70  * @param cfg configuration to use
71  * @return handle to the GNS service, or NULL on error
72  */
73 struct GNUNET_GNS_Handle *
74 GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
75
76
77 /**
78  * Shutdown connection with the GNS service.
79  *
80  * @param handle connection to shut down
81  */
82 void
83 GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle);
84
85
86 /**
87  * Iterator called on obtained result for a GNS lookup.
88  *
89  * @param cls closure
90  * @param rd_count number of records in @a rd
91  * @param rd the records in reply
92  */
93 typedef void (*GNUNET_GNS_LookupResultProcessor) (void *cls,
94                                                   uint32_t rd_count,
95                                                   const struct GNUNET_GNSRECORD_Data *rd);
96
97 /**
98  * Iterator called on obtained result for a GNS lookup.
99  *
100  * @param cls closure
101  * @param rd_count number of records in @a rd
102  * @param rd the records in reply
103  */
104 typedef void (*GNUNET_GNS_ReverseLookupResultProcessor) (void *cls,
105                                                   const char* name);
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 shorten_zone_key the private key of the shorten zone (can be NULL);
141  *                    specify to enable automatic shortening (given a PSEU
142  *                    record, if a given pseudonym is not yet used in the
143  *                    shorten zone, we automatically add the respective zone
144  *                    under that name)
145  * @param proc function to call on result
146  * @param proc_cls closure for processor
147  * @return handle to the queued request
148  */
149 struct GNUNET_GNS_LookupRequest *
150 GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
151                    const char *name,
152                    const struct GNUNET_CRYPTO_EcdsaPublicKey *zone,
153                    uint32_t type,
154                    enum GNUNET_GNS_LocalOptions options,
155                    const struct GNUNET_CRYPTO_EcdsaPrivateKey *shorten_zone_key,
156                    GNUNET_GNS_LookupResultProcessor proc,
157                    void *proc_cls);
158
159 /**
160  * Perform an asynchronous reverse lookup operation on the GNS.
161  *
162  * @param handle handle to the GNS service
163  * @param zone_key zone to find a name for
164  * @param root_key our zone
165  * @param proc processor to call on result
166  * @param proc_cls closure for @a proc
167  * @return handle to the request
168  */
169 struct GNUNET_GNS_ReverseLookupRequest*
170 GNUNET_GNS_reverse_lookup (struct GNUNET_GNS_Handle *handle,
171                            const struct GNUNET_CRYPTO_EcdsaPublicKey *zone_key,
172                            const struct GNUNET_CRYPTO_EcdsaPublicKey *root_key,
173                            GNUNET_GNS_ReverseLookupResultProcessor proc,
174                            void *proc_cls);
175
176
177 /**
178  * Cancel pending lookup request
179  *
180  * @param lr the lookup request to cancel
181  */
182 void
183 GNUNET_GNS_lookup_cancel (struct GNUNET_GNS_LookupRequest *lr);
184
185
186 #if 0                           /* keep Emacsens' auto-indent happy */
187 {
188 #endif
189 #ifdef __cplusplus
190 }
191 #endif
192
193 #endif
194
195 /** @} */  /* end of group */