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_key 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 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
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 * GNUNET_TIME_UNIT_ZERO_ABS if there are no records of any type in the namestore,
265 * or the expiration time of the block in the namestore (even if there are zero
266 * records matching the desired record type)
267 * @param name name that is being mapped (at most 255 characters long)
268 * @param rd_count number of entries in 'rd' array
269 * @param rd array of records with data to store
270 * @param signature signature of the record block, NULL if signature is unavailable (i.e.
271 * because the user queried for a particular record type only)
273 typedef void (*GNUNET_NAMESTORE_RecordProcessor) (void *cls,
274 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
275 struct GNUNET_TIME_Absolute expire,
278 const struct GNUNET_NAMESTORE_RecordData *rd,
279 const struct GNUNET_CRYPTO_RsaSignature *signature);
283 * Get a result for a particular key from the namestore. The processor
284 * will only be called once.
286 * @param h handle to the namestore
287 * @param zone zone to look up a record from
288 * @param name name to look up
289 * @param record_type desired record type, 0 for all
290 * @param proc function to call on the matching records, or with
291 * NULL (rd_count == 0) if there are no matching records
292 * @param proc_cls closure for proc
293 * @return a handle that can be used to
296 struct GNUNET_NAMESTORE_QueueEntry *
297 GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h,
298 const GNUNET_HashCode *zone,
300 uint32_t record_type,
301 GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls);
305 * Starts a new zone iteration (used to periodically PUT all of our
306 * records into our DHT). This MUST lock the GNUNET_NAMESTORE_Handle
307 * for any other calls than GNUNET_NAMESTORE_zone_iterator_next and
308 * GNUNET_NAMESTORE_zone_iteration_stop. "proc" will be called once
309 * immediately, and then again after
310 * "GNUNET_NAMESTORE_zone_iterator_next" is invoked.
312 * @param h handle to the namestore
313 * @param zone zone to access, NULL for all zones
314 * @param must_have_flags flags that must be set for the record to be returned
315 * @param must_not_have_flags flags that must NOT be set for the record to be returned
316 * @param proc function to call on each name from the zone; it
317 * will be called repeatedly with a value (if available)
318 * and always once at the end with a name of NULL.
319 * @param proc_cls closure for proc
320 * @return an iterator handle to use for iteration
322 struct GNUNET_NAMESTORE_ZoneIterator *
323 GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
324 const GNUNET_HashCode *zone,
325 enum GNUNET_NAMESTORE_RecordFlags must_have_flags,
326 enum GNUNET_NAMESTORE_RecordFlags must_not_have_flags,
327 GNUNET_NAMESTORE_RecordProcessor proc,
332 * Calls the record processor specified in GNUNET_NAMESTORE_zone_iteration_start
333 * for the next record.
335 * @param it the iterator
338 GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it);
342 * Stops iteration and releases the namestore handle for further calls.
344 * @param it the iterator
347 GNUNET_NAMESTORE_zone_iteration_stop (struct GNUNET_NAMESTORE_ZoneIterator *it);
351 * Cancel a namestore operation. The final callback from the
352 * operation must not have been done yet.
354 * @param qe operation to cancel
357 GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe);
361 /* convenience APIs for serializing / deserializing GNS records */
364 * Calculate how many bytes we will need to serialize the given
367 * @param rd_count number of records in the rd array
368 * @param rd array of GNUNET_NAMESTORE_RecordData with rd_count elements
370 * @return the required size to serialize
374 GNUNET_NAMESTORE_records_get_size (unsigned int rd_count,
375 const struct GNUNET_NAMESTORE_RecordData *rd);
378 * Serialize the given records to the given destination buffer.
380 * @param rd_cound number of records in the rd array
381 * @param rd array of GNUNET_NAMESTORE_RecordData with rd_count elements
382 * @param dest_size size of the destination array
383 * @param dest where to write the result
385 * @return the size of serialized records
388 GNUNET_NAMESTORE_records_serialize (unsigned int rd_count,
389 const struct GNUNET_NAMESTORE_RecordData *rd,
395 * Deserialize the given records to the given destination.
397 * @param len size of the serialized record data
398 * @param src the serialized record data
399 * @param rd_cound number of records in the rd array
400 * @param dest where to put the data
402 * @return GNUNET_OK on success, GNUNET_SYSERR on error
405 GNUNET_NAMESTORE_records_deserialize (size_t len,
407 unsigned int rd_count,
408 struct GNUNET_NAMESTORE_RecordData *dest);
411 #if 0 /* keep Emacsens' auto-indent happy */
418 /* end of gnunet_namestore_service.h */