doxygen: add documentation links
[oweals/gnunet.git] / src / include / gnunet_namestore_service.h
1 /*
2      This file is part of GNUnet
3      Copyright (C) 2012, 2013 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 Christian Grothoff
23  *
24  * @file
25  * API that can be used to store naming information on a GNUnet node;
26  *
27  * @defgroup namestore  Name Store service
28  * Store naming information on a GNUnet node.
29  *
30  * Naming information can either be records for which this peer/user is
31  * authoritative, or blocks which are cached, encrypted naming data from other
32  * peers.
33  *
34  * @see [Documentation](https://gnunet.org/namestore-subsystem)
35  *
36  * @{
37  */
38 #ifndef GNUNET_NAMESTORE_SERVICE_H
39 #define GNUNET_NAMESTORE_SERVICE_H
40
41 #include "gnunet_util_lib.h"
42 #include "gnunet_block_lib.h"
43 #include "gnunet_gnsrecord_lib.h"
44
45 #ifdef __cplusplus
46 extern "C"
47 {
48 #if 0                           /* keep Emacsens' auto-indent happy */
49 }
50 #endif
51 #endif
52
53
54 /**
55  * Entry in the queue.
56  */
57 struct GNUNET_NAMESTORE_QueueEntry;
58
59 /**
60  * Handle to the namestore service.
61  */
62 struct GNUNET_NAMESTORE_Handle;
63
64 /**
65  * Handle to the namestore zone iterator.
66  */
67 struct GNUNET_NAMESTORE_ZoneIterator;
68
69
70 /**
71  * Connect to the namestore service.
72  *
73  * @param cfg configuration to use
74  * @return handle to use to access the service
75  */
76 struct GNUNET_NAMESTORE_Handle *
77 GNUNET_NAMESTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
78
79
80 /**
81  * Disconnect from the namestore service (and free associated
82  * resources).  Must not be called from within operation callbacks of
83  * the API.
84  *
85  * @param h handle to the namestore
86  */
87 void
88 GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h);
89
90
91 /**
92  * Continuation called to notify client about result of the
93  * operation.
94  *
95  * @param cls closure
96  * @param success #GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate)
97  *                #GNUNET_NO if content was already there or not found
98  *                #GNUNET_YES (or other positive value) on success
99  * @param emsg NULL on success, otherwise an error message
100  */
101 typedef void
102 (*GNUNET_NAMESTORE_ContinuationWithStatus) (void *cls,
103                                             int32_t success,
104                                             const char *emsg);
105
106
107 /**
108  * Store an item in the namestore.  If the item is already present,
109  * it is replaced with the new record.  Use an empty array to
110  * remove all records under the given name.
111  *
112  * @param h handle to the namestore
113  * @param pkey private key of the zone
114  * @param label name that is being mapped
115  * @param rd_count number of records in the 'rd' array
116  * @param rd array of records with data to store
117  * @param cont continuation to call when done
118  * @param cont_cls closure for @a cont
119  * @return handle to abort the request
120  */
121 struct GNUNET_NAMESTORE_QueueEntry *
122 GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h,
123                                 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
124                                 const char *label,
125                                 unsigned int rd_count,
126                                 const struct GNUNET_GNSRECORD_Data *rd,
127                                 GNUNET_NAMESTORE_ContinuationWithStatus cont,
128                                 void *cont_cls);
129
130
131
132 /**
133  * Process a record that was stored in the namestore.
134  *
135  * @param cls closure
136  * @param zone private key of the zone; NULL on disconnect
137  * @param label label of the records; NULL on disconnect
138  * @param rd_count number of entries in @a rd array, 0 if label was deleted
139  * @param rd array of records with data to store
140  */
141 typedef void
142 (*GNUNET_NAMESTORE_RecordMonitor) (void *cls,
143                                    const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
144                                    const char *label,
145                                    unsigned int rd_count,
146                                    const struct GNUNET_GNSRECORD_Data *rd);
147
148
149 /**
150  * Set the desired nick name for a zone
151  *
152  * @param h handle to the namestore
153  * @param pkey private key of the zone
154  * @param nick the nick name to set
155  * @param cont continuation to call when done
156  * @param cont_cls closure for 'cont'
157  * @return handle to abort the request
158  */
159 struct GNUNET_NAMESTORE_QueueEntry *
160 GNUNET_NAMESTORE_set_nick (struct GNUNET_NAMESTORE_Handle *h,
161                            const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
162                            const char *nick,
163                            GNUNET_NAMESTORE_ContinuationWithStatus cont,
164                            void *cont_cls);
165
166
167 /**
168  * Lookup an item in the namestore.
169  *
170  * @param h handle to the namestore
171  * @param pkey private key of the zone
172  * @param label name that is being mapped
173  * @param rm function to call with the result (with 0 records if we don't have that label)
174  * @param rm_cls closure for @a rm
175  * @return handle to abort the request
176  */
177 struct GNUNET_NAMESTORE_QueueEntry *
178 GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h,
179                                  const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
180                                  const char *label,
181                                  GNUNET_NAMESTORE_RecordMonitor rm,
182                                  void *rm_cls);
183
184
185 /**
186  * Look for an existing PKEY delegation record for a given public key.
187  * Returns at most one result to the processor.
188  *
189  * @param h handle to the namestore
190  * @param zone public key of the zone to look up in, never NULL
191  * @param value_zone public key of the target zone (value), never NULL
192  * @param proc function to call on the matching records, or with
193  *        NULL (rd_count == 0) if there are no matching records
194  * @param proc_cls closure for @a proc
195  * @return a handle that can be used to
196  *         cancel
197  */
198 struct GNUNET_NAMESTORE_QueueEntry *
199 GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h,
200                                const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
201                                const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone,
202                                GNUNET_NAMESTORE_RecordMonitor proc, void *proc_cls);
203
204
205 /**
206  * Cancel a namestore operation.  The final callback from the
207  * operation must not have been done yet.  Must be called on any
208  * namestore operation that has not yet completed prior to calling
209  * #GNUNET_NAMESTORE_disconnect.
210  *
211  * @param qe operation to cancel
212  */
213 void
214 GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe);
215
216
217 /**
218  * Starts a new zone iteration (used to periodically PUT all of our
219  * records into our DHT). This MUST lock the struct GNUNET_NAMESTORE_Handle
220  * for any other calls than #GNUNET_NAMESTORE_zone_iterator_next and
221  * #GNUNET_NAMESTORE_zone_iteration_stop. @a proc will be called once
222  * immediately, and then again after
223  * #GNUNET_NAMESTORE_zone_iterator_next is invoked.
224  *
225  * @param h handle to the namestore
226  * @param zone zone to access, NULL for all zones
227  * @param proc function to call on each name from the zone; it
228  *        will be called repeatedly with a value (if available)
229  *        and always once at the end with a label of NULL.
230  * @param proc_cls closure for @a proc
231  * @return an iterator handle to use for iteration
232  */
233 struct GNUNET_NAMESTORE_ZoneIterator *
234 GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
235                                        const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
236                                        GNUNET_NAMESTORE_RecordMonitor proc,
237                                        void *proc_cls);
238
239
240 /**
241  * Calls the record processor specified in #GNUNET_NAMESTORE_zone_iteration_start
242  * for the next record.
243  *
244  * @param it the iterator
245  */
246 void
247 GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it);
248
249
250 /**
251  * Stops iteration and releases the namestore handle for further calls.  Must
252  * be called on any iteration that has not yet completed prior to calling
253  * #GNUNET_NAMESTORE_disconnect.
254  *
255  * @param it the iterator
256  */
257 void
258 GNUNET_NAMESTORE_zone_iteration_stop (struct GNUNET_NAMESTORE_ZoneIterator *it);
259
260
261 /**
262  * Handle for a monitoring activity.
263  */
264 struct GNUNET_NAMESTORE_ZoneMonitor;
265
266
267 /**
268  * Function called once the monitor has caught up with the current
269  * state of the database.  Will be called AGAIN after each disconnect
270  * (record monitor called with 'NULL' for zone_key) once we're again
271  * in sync.
272  *
273  * @param cls closure
274  */
275 typedef void
276 (*GNUNET_NAMESTORE_RecordsSynchronizedCallback)(void *cls);
277
278
279 /**
280  * Begin monitoring a zone for changes.  Will first call the @a
281  * monitor function on all existing records in the selected zone(s) if
282  * @a iterate_first is #GNUNET_YES.  In any case, we will then call @a
283  * sync_cb, and then afterwards call the @a monitor whenever a record
284  * changes.  If the namestore disconnects, the @a monitor function is
285  * called with a disconnect event; if the connection is
286  * re-established, the process begins from the start (depending on @a
287  * iterate_first, we first do all existing records, then @a sync, then
288  * updates).
289  *
290  * @param cfg configuration to use to connect to namestore
291  * @param zone zone to monitor, NULL for all zones
292  * @param iterate_first #GNUNET_YES to first iterate over all existing records,
293  *                      #GNUNET_NO to only return changes that happen from now on
294  * @param monitor function to call on zone changes
295  * @param sync_cb function called when we're in sync with the namestore
296  * @param cls closure for @a monitor and @a sync_cb
297  * @return handle to stop monitoring
298  */
299 struct GNUNET_NAMESTORE_ZoneMonitor *
300 GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
301                                      const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
302                                      int iterate_first,
303                                      GNUNET_NAMESTORE_RecordMonitor monitor,
304                                      GNUNET_NAMESTORE_RecordsSynchronizedCallback sync_cb,
305                                      void *cls);
306
307
308 /**
309  * Stop monitoring a zone for changes.
310  *
311  * @param zm handle to the monitor activity to stop
312  */
313 void
314 GNUNET_NAMESTORE_zone_monitor_stop (struct GNUNET_NAMESTORE_ZoneMonitor *zm);
315
316
317 #if 0                           /* keep Emacsens' auto-indent happy */
318 {
319 #endif
320 #ifdef __cplusplus
321 }
322 #endif
323
324 #endif
325
326 /** @} */  /* end of group */