2 This file is part of GNUnet
3 Copyright (C) 2012, 2013, 2018 GNUnet e.V.
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.
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.
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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @author Christian Grothoff
25 * API that can be used to store naming information on a GNUnet node;
27 * @defgroup namestore Name Store service
28 * Store naming information on a GNUnet node.
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
34 * @see [Documentation](https://gnunet.org/namestore-subsystem)
38 #ifndef GNUNET_NAMESTORE_SERVICE_H
39 #define GNUNET_NAMESTORE_SERVICE_H
41 #include "gnunet_util_lib.h"
42 #include "gnunet_block_lib.h"
43 #include "gnunet_gnsrecord_lib.h"
48 #if 0 /* keep Emacsens' auto-indent happy */
57 struct GNUNET_NAMESTORE_QueueEntry;
60 * Handle to the namestore service.
62 struct GNUNET_NAMESTORE_Handle;
65 * Handle to the namestore zone iterator.
67 struct GNUNET_NAMESTORE_ZoneIterator;
71 * Connect to the namestore service.
73 * @param cfg configuration to use
74 * @return handle to use to access the service
76 struct GNUNET_NAMESTORE_Handle *
77 GNUNET_NAMESTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
81 * Disconnect from the namestore service (and free associated
82 * resources). Must not be called from within operation callbacks of
85 * @param h handle to the namestore
88 GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h);
92 * Continuation called to notify client about result of the
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
102 (*GNUNET_NAMESTORE_ContinuationWithStatus) (void *cls,
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.
112 * The continuation is called after the value has been stored in the
113 * database. Monitors may be notified asynchronously (basically with
114 * a buffer). However, if any monitor is consistently too slow to
115 * keep up with the changes, calling @a cont will be delayed until the
116 * monitors do keep up.
118 * @param h handle to the namestore
119 * @param pkey private key of the zone
120 * @param label name that is being mapped
121 * @param rd_count number of records in the 'rd' array
122 * @param rd array of records with data to store
123 * @param cont continuation to call when done
124 * @param cont_cls closure for @a cont
125 * @return handle to abort the request
127 struct GNUNET_NAMESTORE_QueueEntry *
128 GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h,
129 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
131 unsigned int rd_count,
132 const struct GNUNET_GNSRECORD_Data *rd,
133 GNUNET_NAMESTORE_ContinuationWithStatus cont,
138 * Process a record that was stored in the namestore.
141 * @param zone private key of the zone
142 * @param label label of the records
143 * @param rd_count number of entries in @a rd array, 0 if label was deleted
144 * @param rd array of records with data to store
147 (*GNUNET_NAMESTORE_RecordMonitor) (void *cls,
148 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
150 unsigned int rd_count,
151 const struct GNUNET_GNSRECORD_Data *rd);
155 * Set the desired nick name for a zone
157 * @param h handle to the namestore
158 * @param pkey private key of the zone
159 * @param nick the nick name to set
160 * @param cont continuation to call when done
161 * @param cont_cls closure for @a cont
162 * @return handle to abort the request
164 struct GNUNET_NAMESTORE_QueueEntry *
165 GNUNET_NAMESTORE_set_nick (struct GNUNET_NAMESTORE_Handle *h,
166 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
168 GNUNET_NAMESTORE_ContinuationWithStatus cont,
173 * Lookup an item in the namestore.
175 * @param h handle to the namestore
176 * @param pkey private key of the zone
177 * @param label name that is being mapped
178 * @param error_cb function to call on error (i.e. disconnect)
179 * the handle is afterwards invalid
180 * @param error_cb_cls closure for @a error_cb
181 * @param rm function to call with the result (with 0 records if we don't have that label);
182 * the handle is afterwards invalid
183 * @param rm_cls closure for @a rm
184 * @return handle to abort the request
186 struct GNUNET_NAMESTORE_QueueEntry *
187 GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h,
188 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
190 GNUNET_SCHEDULER_TaskCallback error_cb,
192 GNUNET_NAMESTORE_RecordMonitor rm,
197 * Look for an existing PKEY delegation record for a given public key.
198 * Returns at most one result to the processor.
200 * @param h handle to the namestore
201 * @param zone private key of the zone to look up in, never NULL
202 * @param value_zone public key of the target zone (value), never NULL
203 * @param error_cb function to call on error (i.e. disconnect)
204 * the handle is afterwards invalid
205 * @param error_cb_cls closure for @a error_cb
206 * @param proc function to call on the matching records, or with
207 * NULL (rd_count == 0) if there are no matching records;
208 * the handle is afterwards invalid
209 * @param proc_cls closure for @a proc
210 * @return a handle that can be used to
213 struct GNUNET_NAMESTORE_QueueEntry *
214 GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h,
215 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
216 const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone,
217 GNUNET_SCHEDULER_TaskCallback error_cb,
219 GNUNET_NAMESTORE_RecordMonitor proc,
224 * Cancel a namestore operation. The final callback from the
225 * operation must not have been done yet. Must be called on any
226 * namestore operation that has not yet completed prior to calling
227 * #GNUNET_NAMESTORE_disconnect.
229 * @param qe operation to cancel
232 GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe);
236 * Starts a new zone iteration (used to periodically PUT all of our
237 * records into our DHT). This MUST lock the `struct GNUNET_NAMESTORE_Handle`
238 * for any other calls than #GNUNET_NAMESTORE_zone_iterator_next() and
239 * #GNUNET_NAMESTORE_zone_iteration_stop. @a proc will be called once
240 * immediately, and then again after
241 * #GNUNET_NAMESTORE_zone_iterator_next() is invoked.
243 * On error (disconnect), @a error_cb will be invoked.
244 * On normal completion, @a finish_cb proc will be
247 * @param h handle to the namestore
248 * @param zone zone to access, NULL for all zones
249 * @param error_cb function to call on error (i.e. disconnect),
250 * the handle is afterwards invalid
251 * @param error_cb_cls closure for @a error_cb
252 * @param proc function to call on each name from the zone; it
253 * will be called repeatedly with a value (if available)
254 * @param proc_cls closure for @a proc
255 * @param finish_cb function to call on completion
256 * the handle is afterwards invalid
257 * @param finish_cb_cls closure for @a finish_cb
258 * @return an iterator handle to use for iteration
260 struct GNUNET_NAMESTORE_ZoneIterator *
261 GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
262 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
263 GNUNET_SCHEDULER_TaskCallback error_cb,
265 GNUNET_NAMESTORE_RecordMonitor proc,
267 GNUNET_SCHEDULER_TaskCallback finish_cb,
268 void *finish_cb_cls);
272 * Calls the record processor specified in #GNUNET_NAMESTORE_zone_iteration_start
273 * for the next record.
275 * @param it the iterator
276 * @param limit number of records to return to the iterator in one shot
277 * (before #GNUNET_NAMESTORE_zone_iterator_next is to be called again)
280 GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it,
285 * Stops iteration and releases the namestore handle for further calls. Must
286 * be called on any iteration that has not yet completed prior to calling
287 * #GNUNET_NAMESTORE_disconnect.
289 * @param it the iterator
292 GNUNET_NAMESTORE_zone_iteration_stop (struct GNUNET_NAMESTORE_ZoneIterator *it);
296 * Handle for a monitoring activity.
298 struct GNUNET_NAMESTORE_ZoneMonitor;
302 * Begin monitoring a zone for changes. Will first call the @a
303 * monitor function on all existing records in the selected zone(s) if
304 * @a iterate_first is #GNUNET_YES. In any case, we will then call @a
305 * sync_cb, and then afterwards call the @a monitor whenever a record
306 * changes. If the namestore disconnects, the @a error_cb function is
307 * called with a disconnect event. Once the connection is
308 * re-established, the process begins from the start (depending on @a
309 * iterate_first, we will again first do all existing records, then @a
310 * sync, then updates).
312 * @param cfg configuration to use to connect to namestore
313 * @param zone zone to monitor, NULL for all zones
314 * @param iterate_first #GNUNET_YES to first iterate over all existing records,
315 * #GNUNET_NO to only return changes that happen from now on
316 * @param error_cb function to call on error (i.e. disconnect); note that
317 * unlike the other error callbacks in this API, a call to this
318 * function does NOT destroy the monitor handle, it merely signals
319 * that monitoring is down. You need to still explicitly call
320 * #GNUNET_NAMESTORE_zone_monitor_stop().
321 * @param error_cb_cls closure for @a error_cb
322 * @param monitor function to call on zone changes, with an initial limit of 1
323 * @param monitor_cls closure for @a monitor
324 * @param sync_cb function called when we're in sync with the namestore
325 * @param sync_cb_cls closure for @a sync_cb
326 * @return handle to stop monitoring
328 struct GNUNET_NAMESTORE_ZoneMonitor *
329 GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
330 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
332 GNUNET_SCHEDULER_TaskCallback error_cb,
334 GNUNET_NAMESTORE_RecordMonitor monitor,
336 GNUNET_SCHEDULER_TaskCallback sync_cb,
341 * Calls the monitor processor specified in #GNUNET_NAMESTORE_zone_monitor_start
342 * for the next record(s). This function is used to allow clients that merely
343 * monitor the NAMESTORE to still throttle namestore operations, so we can be
344 * sure that the monitors can keep up.
346 * Note that #GNUNET_NAMESTORE_records_store() only waits for this
347 * call if the previous limit set by the client was already reached.
348 * Thus, by using a @a limit greater than 1, monitors basically enable
349 * a queue of notifications to be processed asynchronously with some
350 * delay. Note that even with a limit of 1 the
351 * #GNUNET_NAMESTORE_records_store() function will run asynchronously
352 * and the continuation may be invoked before the monitors completed
353 * (or even started) processing the notification. Thus, monitors will
354 * only closely track the current state of the namestore, but not
355 * be involved in the transactions.
357 * @param zm the monitor
358 * @param limit number of records to return to the iterator in one shot
359 * (before #GNUNET_NAMESTORE_zone_monitor_next is to be called again)
362 GNUNET_NAMESTORE_zone_monitor_next (struct GNUNET_NAMESTORE_ZoneMonitor *zm,
367 * Stop monitoring a zone for changes.
369 * @param zm handle to the monitor activity to stop
372 GNUNET_NAMESTORE_zone_monitor_stop (struct GNUNET_NAMESTORE_ZoneMonitor *zm);
375 #if 0 /* keep Emacsens' auto-indent happy */
384 /** @} */ /* end of group */