2 This file is part of GNUnet
3 (C) 2012 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 2, 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 * @author Christian Grothoff
26 * Other functions we might want:
27 * - enumerate all known zones
28 * - convenience function to gather record and the full affilliated stree
32 #ifndef GNUNET_NAMESTORE_SERVICE_H
33 #define GNUNET_NAMESTORE_SERVICE_H
35 #include "gnunet_util_lib.h"
36 #include "gnunet_block_lib.h"
41 #if 0 /* keep Emacsens' auto-indent happy */
49 struct GNUNET_NAMESTORE_QueueEntry;
52 * Handle to the namestore service.
54 struct GNUNET_NAMESTORE_Handle;
57 * Handle to the namestore zone iterator.
59 struct GNUNET_NAMESTORE_ZoneIterator;
62 * Maximum size of a value that can be stored in the namestore.
64 #define GNUNET_NAMESTORE_MAX_VALUE_SIZE (63 * 1024)
67 * Connect to the namestore service.
69 * @param cfg configuration to use
70 * @return handle to use to access the service
72 struct GNUNET_NAMESTORE_Handle *
73 GNUNET_NAMESTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
77 * Disconnect from the namestore service (and free associated
80 * @param h handle to the namestore
81 * @param drop set to GNUNET_YES to delete all data in namestore (!)
84 GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h, int drop);
88 * Continuation called to notify client about result of the
92 * @param success GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate)
93 * GNUNET_NO if content was already there
94 * GNUNET_YES (or other positive value) on success
95 * @param emsg NULL on success, otherwise an error message
97 typedef void (*GNUNET_NAMESTORE_ContinuationWithStatus) (void *cls,
103 * Flags that can be set for a record.
105 enum GNUNET_NAMESTORE_RecordFlags
109 * No special options.
111 GNUNET_NAMESTORE_RF_NONE = 0,
114 * This peer is the authority for this record; it must thus
115 * not be deleted (other records can be deleted if we run
118 GNUNET_NAMESTORE_RF_AUTHORITY = 1,
121 * This is a private record of this peer and it should
122 * thus not be handed out to other peers.
124 GNUNET_NAMESTORE_RF_PRIVATE = 2
132 struct GNUNET_NAMESTORE_RecordData
136 * Binary value stored in the DNS record.
141 * Expiration time for the DNS record.
143 struct GNUNET_TIME_Absolute expiration;
146 * Number of bytes in 'data'.
151 * Type of the GNS/DNS record.
153 uint32_t record_type;
156 * Flags for the record.
158 enum GNUNET_NAMESTORE_RecordFlags flags;
163 * Store an item in the namestore. If the item is already present,
164 * the expiration time is updated to the max of the existing time and
165 * the new time. This API is used when we cache signatures from other
168 * @param h handle to the namestore
169 * @param zone hash of the public key of the zone
170 * @param name name that is being mapped (at most 255 characters long)
171 * @param expire when does the corresponding block in the DHT expire (until
172 * when should we never do a DHT lookup for the same name again)?
173 * @param rd_count number of entries in 'rd' array
174 * @param rd array of records with data to store
175 * @param signature signature for all the records in the zone under the given name
176 * @param cont continuation to call when done
177 * @param cont_cls closure for cont
178 * @return handle to abort the request
180 struct GNUNET_NAMESTORE_QueueEntry *
181 GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h,
182 const GNUNET_HashCode *zone,
184 struct GNUNET_TIME_Absolute expire,
185 unsigned int rd_count,
186 const struct GNUNET_NAMESTORE_RecordData *rd,
187 const struct GNUNET_CRYPTO_RsaSignature *signature,
188 GNUNET_NAMESTORE_ContinuationWithStatus cont,
193 * Check if a signature is valid. This API is used by the GNS Block
194 * to validate signatures received from the network.
196 * @param public_key public key of the zone
197 * @param name name that is being mapped (at most 255 characters long)
198 * @param rd_count number of entries in 'rd' array
199 * @param rd array of records with data to store
200 * @param signature signature for all the records in the zone under the given name
201 * @return GNUNET_OK if the signature is valid
204 GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key,
206 unsigned int rd_count,
207 const struct GNUNET_NAMESTORE_RecordData *rd,
208 const struct GNUNET_CRYPTO_RsaSignature *signature);
212 * Store an item in the namestore. If the item is already present,
213 * the expiration time is updated to the max of the existing time and
214 * the new time. This API is used by the authority of a zone.
216 * @param h handle to the namestore
217 * @param pkey private key of the zone
218 * @param name name that is being mapped (at most 255 characters long)
219 * @param rd record data to store
220 * @param cont continuation to call when done
221 * @param cont_cls closure for cont
222 * @return handle to abort the request
224 struct GNUNET_NAMESTORE_QueueEntry *
225 GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h,
226 const struct GNUNET_CRYPTO_RsaPrivateKey *pkey,
228 const struct GNUNET_NAMESTORE_RecordData *rd,
229 GNUNET_NAMESTORE_ContinuationWithStatus cont,
234 * Explicitly remove some content from the database. The
235 * "cont"inuation will be called with status "GNUNET_OK" if content
236 * was removed, "GNUNET_NO" if no matching entry was found and
237 * "GNUNET_SYSERR" on all other types of errors.
238 * This API is used by the authority of a zone.
240 * @param h handle to the namestore
241 * @param pkey private key of the zone
242 * @param name name that is being mapped (at most 255 characters long)
243 * @param rd record data
244 * @param cont continuation to call when done
245 * @param cont_cls closure for cont
246 * @return handle to abort the request
248 struct GNUNET_NAMESTORE_QueueEntry *
249 GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h,
250 const struct GNUNET_CRYPTO_RsaPrivateKey *pkey,
252 const struct GNUNET_NAMESTORE_RecordData *rd,
253 GNUNET_NAMESTORE_ContinuationWithStatus cont,
258 * Process a record that was stored in the namestore.
261 * @param zone_key public key of the zone
262 * @param expire when does the corresponding block in the DHT expire (until
263 * when should we never do a DHT lookup for the same name again)?
264 * @param name name that is being mapped (at most 255 characters long)
265 * @param rd_count number of entries in 'rd' array
266 * @param rd array of records with data to store
267 * @param signature signature of the record block, NULL if signature is unavailable (i.e.
268 * because the user queried for a particular record type only)
270 typedef void (*GNUNET_NAMESTORE_RecordProcessor) (void *cls,
271 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
272 struct GNUNET_TIME_Absolute expire,
274 unsigned int rd_count,
275 const struct GNUNET_NAMESTORE_RecordData *rd,
276 const struct GNUNET_CRYPTO_RsaSignature *signature);
280 * Get a result for a particular key from the namestore. The processor
281 * will only be called once.
283 * @param h handle to the namestore
284 * @param zone zone to look up a record from
285 * @param name name to look up
286 * @param record_type desired record type, 0 for all
287 * @param proc function to call on the matching records, or with
288 * NULL (rd_count == 0) if there are no matching records
289 * @param proc_cls closure for proc
290 * @return a handle that can be used to
293 struct GNUNET_NAMESTORE_QueueEntry *
294 GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h,
295 const GNUNET_HashCode *zone,
297 uint32_t record_type,
298 GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls);
302 * Starts a new zone iteration (used to periodically PUT all of our
303 * records into our DHT). This MUST lock the GNUNET_NAMESTORE_Handle
304 * for any other calls than GNUNET_NAMESTORE_zone_iterator_next and
305 * GNUNET_NAMESTORE_zone_iteration_stop. "proc" will be called once
306 * immediately, and then again after
307 * "GNUNET_NAMESTORE_zone_iterator_next" is invoked.
309 * @param h handle to the namestore
310 * @param zone zone to access, NULL for all zones
311 * @param must_have_flags flags that must be set for the record to be returned
312 * @param must_not_have_flags flags that must NOT be set for the record to be returned
313 * @param proc function to call on each name from the zone; it
314 * will be called repeatedly with a value (if available)
315 * and always once at the end with a name of NULL.
316 * @param proc_cls closure for proc
317 * @return an iterator handle to use for iteration
319 struct GNUNET_NAMESTORE_ZoneIterator *
320 GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
321 const GNUNET_HashCode *zone,
322 enum GNUNET_NAMESTORE_RecordFlags must_have_flags,
323 enum GNUNET_NAMESTORE_RecordFlags must_not_have_flags,
324 GNUNET_NAMESTORE_RecordProcessor proc,
329 * Calls the record processor specified in GNUNET_NAMESTORE_zone_iteration_start
330 * for the next record.
332 * @param it the iterator
335 GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it);
339 * Stops iteration and releases the namestore handle for further calls.
341 * @param it the iterator
344 GNUNET_NAMESTORE_zone_iteration_stop (struct GNUNET_NAMESTORE_ZoneIterator *it);
348 * Cancel a namestore operation. The final callback from the
349 * operation must not have been done yet.
351 * @param qe operation to cancel
354 GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe);
357 #if 0 /* keep Emacsens' auto-indent happy */
364 /* end of gnunet_namestore_service.h */