2d511755ee7bb15f41f508e7bc3c6d8452a95806
[oweals/gnunet.git] / src / include / gnunet_gns_service.h
1 /*
2       This file is part of GNUnet
3       Copyright (C) 2012-2014 Christian Grothoff (and other contributing authors)
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  */
31 #ifndef GNUNET_GNS_SERVICE_H
32 #define GNUNET_GNS_SERVICE_H
33
34 #include "gnunet_util_lib.h"
35 #include "gnunet_dnsparser_lib.h"
36 #include "gnunet_namestore_service.h"
37
38 #ifdef __cplusplus
39 extern "C"
40 {
41 #if 0                           /* keep Emacsens' auto-indent happy */
42 }
43 #endif
44 #endif
45
46
47 /**
48  * String we use to indicate the local master zone or a
49  * root entry in the current zone.
50  */
51 #define GNUNET_GNS_MASTERZONE_STR "+"
52
53 /**
54  * Connection to the GNS service.
55  */
56 struct GNUNET_GNS_Handle;
57
58 /**
59  * Handle to control a lookup operation.
60  */
61 struct GNUNET_GNS_LookupRequest;
62
63
64 /**
65  * Initialize the connection with the GNS service.
66  *
67  * @param cfg configuration to use
68  * @return handle to the GNS service, or NULL on error
69  */
70 struct GNUNET_GNS_Handle *
71 GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
72
73
74 /**
75  * Shutdown connection with the GNS service.
76  *
77  * @param handle connection to shut down
78  */
79 void
80 GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle);
81
82
83 /**
84  * Iterator called on obtained result for a GNS lookup.
85  *
86  * @param cls closure
87  * @param rd_count number of records in @a rd
88  * @param rd the records in reply
89  */
90 typedef void (*GNUNET_GNS_LookupResultProcessor) (void *cls,
91                                                   uint32_t rd_count,
92                                                   const struct GNUNET_GNSRECORD_Data *rd);
93
94
95 /**
96  * Options for the GNS lookup.
97  */
98 enum GNUNET_GNS_LocalOptions
99 {
100   /**
101    * Defaults, look in cache, then in DHT.
102    */
103   GNUNET_GNS_LO_DEFAULT = 0,
104
105   /**
106    * Never look in the DHT, keep request to local cache.
107    */
108   GNUNET_GNS_LO_NO_DHT = 1,
109
110   /**
111    * For the rightmost label, only look in the cache (it
112    * is our master zone), for the others, the DHT is OK.
113    */
114   GNUNET_GNS_LO_LOCAL_MASTER = 2
115
116 };
117
118
119 /**
120  * Perform an asynchronous lookup operation on the GNS.
121  *
122  * @param handle handle to the GNS service
123  * @param name the name to look up
124  * @param zone zone to look in
125  * @param type the GNS record type to look for
126  * @param options local options for the lookup
127  * @param shorten_zone_key the private key of the shorten zone (can be NULL);
128  *                    specify to enable automatic shortening (given a PSEU
129  *                    record, if a given pseudonym is not yet used in the
130  *                    shorten zone, we automatically add the respective zone
131  *                    under that name)
132  * @param proc function to call on result
133  * @param proc_cls closure for processor
134  * @return handle to the queued request
135  */
136 struct GNUNET_GNS_LookupRequest *
137 GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
138                    const char *name,
139                    const struct GNUNET_CRYPTO_EcdsaPublicKey *zone,
140                    uint32_t type,
141                    enum GNUNET_GNS_LocalOptions options,
142                    const struct GNUNET_CRYPTO_EcdsaPrivateKey *shorten_zone_key,
143                    GNUNET_GNS_LookupResultProcessor proc,
144                    void *proc_cls);
145
146
147 /**
148  * Cancel pending lookup request
149  *
150  * @param lr the lookup request to cancel
151  */
152 void
153 GNUNET_GNS_lookup_cancel (struct GNUNET_GNS_LookupRequest *lr);
154
155
156 #if 0                           /* keep Emacsens' auto-indent happy */
157 {
158 #endif
159 #ifdef __cplusplus
160 }
161 #endif
162
163 #endif
164
165 /** @} */  /* end of group */