2 This file is part of GNUnet
3 (C) 2012, 2013 Christian Grothoff (and other contributing authors)
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.
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.
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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file include/gnunet_namestore_service.h
23 * @brief API that can be used to store naming information on a GNUnet node;
24 * Naming information can either be records for which this peer/user
25 * is authoritative, or blocks which are cached, encrypted naming
26 * data from other peers.
27 * @author Christian Grothoff
29 #ifndef GNUNET_NAMESTORE_SERVICE_H
30 #define GNUNET_NAMESTORE_SERVICE_H
32 #include "gnunet_util_lib.h"
33 #include "gnunet_block_lib.h"
34 #include "gnunet_gnsrecord_lib.h"
39 #if 0 /* keep Emacsens' auto-indent happy */
48 struct GNUNET_NAMESTORE_QueueEntry;
51 * Handle to the namestore service.
53 struct GNUNET_NAMESTORE_Handle;
56 * Handle to the namestore zone iterator.
58 struct GNUNET_NAMESTORE_ZoneIterator;
62 * Connect to the namestore service.
64 * @param cfg configuration to use
65 * @return handle to use to access the service
67 struct GNUNET_NAMESTORE_Handle *
68 GNUNET_NAMESTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
72 * Disconnect from the namestore service (and free associated
73 * resources). Must not be called from within operation callbacks of
76 * @param h handle to the namestore
79 GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h);
83 * Continuation called to notify client about result of the
87 * @param success #GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate)
88 * #GNUNET_NO if content was already there or not found
89 * #GNUNET_YES (or other positive value) on success
90 * @param emsg NULL on success, otherwise an error message
92 typedef void (*GNUNET_NAMESTORE_ContinuationWithStatus) (void *cls,
98 * Store an item in the namestore. If the item is already present,
99 * it is replaced with the new record. Use an empty array to
100 * remove all records under the given name.
102 * @param h handle to the namestore
103 * @param pkey private key of the zone
104 * @param label name that is being mapped
105 * @param rd_count number of records in the 'rd' array
106 * @param rd array of records with data to store
107 * @param cont continuation to call when done
108 * @param cont_cls closure for @a cont
109 * @return handle to abort the request
111 struct GNUNET_NAMESTORE_QueueEntry *
112 GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h,
113 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
115 unsigned int rd_count,
116 const struct GNUNET_GNSRECORD_Data *rd,
117 GNUNET_NAMESTORE_ContinuationWithStatus cont,
123 * Process a record that was stored in the namestore.
126 * @param zone private key of the zone; NULL on disconnect
127 * @param label label of the records; NULL on disconnect
128 * @param rd_count number of entries in @a rd array, 0 if label was deleted
129 * @param rd array of records with data to store
131 typedef void (*GNUNET_NAMESTORE_RecordMonitor) (void *cls,
132 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
134 unsigned int rd_count,
135 const struct GNUNET_GNSRECORD_Data *rd);
139 * Lookup an item in the namestore.
141 * @param h handle to the namestore
142 * @param pkey private key of the zone
143 * @param label name that is being mapped
144 * @param rm function to call with the result (with 0 records if we don't have that label)
145 * @param rm_cls closure for @a rm
146 * @return handle to abort the request
148 struct GNUNET_NAMESTORE_QueueEntry *
149 GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h,
150 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
152 GNUNET_NAMESTORE_RecordMonitor rm,
157 * Look for an existing PKEY delegation record for a given public key.
158 * Returns at most one result to the processor.
160 * @param h handle to the namestore
161 * @param zone public key of the zone to look up in, never NULL
162 * @param value_zone public key of the target zone (value), never NULL
163 * @param proc function to call on the matching records, or with
164 * NULL (rd_count == 0) if there are no matching records
165 * @param proc_cls closure for @a proc
166 * @return a handle that can be used to
169 struct GNUNET_NAMESTORE_QueueEntry *
170 GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h,
171 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
172 const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone,
173 GNUNET_NAMESTORE_RecordMonitor proc, void *proc_cls);
177 * Cancel a namestore operation. The final callback from the
178 * operation must not have been done yet. Must be called on any
179 * namestore operation that has not yet completed prior to calling
180 * #GNUNET_NAMESTORE_disconnect.
182 * @param qe operation to cancel
185 GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe);
189 * Starts a new zone iteration (used to periodically PUT all of our
190 * records into our DHT). This MUST lock the struct GNUNET_NAMESTORE_Handle
191 * for any other calls than #GNUNET_NAMESTORE_zone_iterator_next and
192 * #GNUNET_NAMESTORE_zone_iteration_stop. @a proc will be called once
193 * immediately, and then again after
194 * #GNUNET_NAMESTORE_zone_iterator_next is invoked.
196 * @param h handle to the namestore
197 * @param zone zone to access, NULL for all zones
198 * @param proc function to call on each name from the zone; it
199 * will be called repeatedly with a value (if available)
200 * and always once at the end with a label of NULL.
201 * @param proc_cls closure for @a proc
202 * @return an iterator handle to use for iteration
204 struct GNUNET_NAMESTORE_ZoneIterator *
205 GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
206 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
207 GNUNET_NAMESTORE_RecordMonitor proc,
212 * Calls the record processor specified in #GNUNET_NAMESTORE_zone_iteration_start
213 * for the next record.
215 * @param it the iterator
218 GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it);
222 * Stops iteration and releases the namestore handle for further calls. Must
223 * be called on any iteration that has not yet completed prior to calling
224 * #GNUNET_NAMESTORE_disconnect.
226 * @param it the iterator
229 GNUNET_NAMESTORE_zone_iteration_stop (struct GNUNET_NAMESTORE_ZoneIterator *it);
233 * Handle for a monitoring activity.
235 struct GNUNET_NAMESTORE_ZoneMonitor;
239 * Function called once the monitor has caught up with the current
240 * state of the database. Will be called AGAIN after each disconnect
241 * (record monitor called with 'NULL' for zone_key) once we're again
246 typedef void (*GNUNET_NAMESTORE_RecordsSynchronizedCallback)(void *cls);
250 * Begin monitoring a zone for changes. Will first call the @a
251 * monitor function on all existing records in the selected zone(s) if
252 * @a iterate_first is #GNUNET_YES. In any case, we will then call @a
253 * sync_cb, and then afterwards call the @a monitor whenever a record
254 * changes. If the namestore disconnects, the @a monitor function is
255 * called with a disconnect event; if the connection is
256 * re-established, the process begins from the start (depending on @a
257 * iterate_first, we first do all existing records, then @a sync, then
260 * @param cfg configuration to use to connect to namestore
261 * @param zone zone to monitor, NULL for all zones
262 * @param iterate_first #GNUNET_YES to first iterate over all existing records,
263 * #GNUNET_NO to only return changes that happen from now on
264 * @param monitor function to call on zone changes
265 * @param sync_cb function called when we're in sync with the namestore
266 * @param cls closure for @a monitor and @a sync_cb
267 * @return handle to stop monitoring
269 struct GNUNET_NAMESTORE_ZoneMonitor *
270 GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
271 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
273 GNUNET_NAMESTORE_RecordMonitor monitor,
274 GNUNET_NAMESTORE_RecordsSynchronizedCallback sync_cb,
279 * Stop monitoring a zone for changes.
281 * @param zm handle to the monitor activity to stop
284 GNUNET_NAMESTORE_zone_monitor_stop (struct GNUNET_NAMESTORE_ZoneMonitor *zm);
288 #if 0 /* keep Emacsens' auto-indent happy */
295 /* end of gnunet_namestore_service.h */