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 */
47 * Record type for GNS zone transfer ("PKEY").
49 #define GNUNET_NAMESTORE_TYPE_PKEY 65536
52 * Record type for GNS zone transfer ("PSEU").
54 #define GNUNET_NAMESTORE_TYPE_PSEU 65537
59 struct GNUNET_NAMESTORE_QueueEntry;
62 * Handle to the namestore service.
64 struct GNUNET_NAMESTORE_Handle;
67 * Handle to the namestore zone iterator.
69 struct GNUNET_NAMESTORE_ZoneIterator;
72 * Maximum size of a value that can be stored in the namestore.
74 #define GNUNET_NAMESTORE_MAX_VALUE_SIZE (63 * 1024)
79 * Connect to the namestore service.
81 * @param cfg configuration to use
82 * @return handle to use to access the service
84 struct GNUNET_NAMESTORE_Handle *
85 GNUNET_NAMESTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
89 * Disconnect from the namestore service (and free associated
92 * @param h handle to the namestore
93 * @param drop set to GNUNET_YES to delete all data in namestore (!)
96 GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h, int drop);
100 * Continuation called to notify client about result of the
104 * @param success GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate)
105 * GNUNET_NO if content was already there or not found
106 * GNUNET_YES (or other positive value) on success
107 * @param emsg NULL on success, otherwise an error message
109 typedef void (*GNUNET_NAMESTORE_ContinuationWithStatus) (void *cls,
115 * Flags that can be set for a record.
117 enum GNUNET_NAMESTORE_RecordFlags
121 * No special options.
123 GNUNET_NAMESTORE_RF_NONE = 0,
126 * This peer is the authority for this record; it must thus
127 * not be deleted (other records can be deleted if we run
130 GNUNET_NAMESTORE_RF_AUTHORITY = 1,
133 * This is a private record of this peer and it should
134 * thus not be handed out to other peers.
136 GNUNET_NAMESTORE_RF_PRIVATE = 2
144 struct GNUNET_NAMESTORE_RecordData
148 * Binary value stored in the DNS record.
153 * Expiration time for the DNS record.
155 struct GNUNET_TIME_Absolute expiration;
158 * Number of bytes in 'data'.
163 * Type of the GNS/DNS record.
165 uint32_t record_type;
168 * Flags for the record.
170 enum GNUNET_NAMESTORE_RecordFlags flags;
175 * Store an item in the namestore. If the item is already present,
176 * the expiration time is updated to the max of the existing time and
177 * the new time. This API is used when we cache signatures from other
180 * @param h handle to the namestore
181 * @param zone_key public key of the zone
182 * @param name name that is being mapped (at most 255 characters long)
183 * @param expire when does the corresponding block in the DHT expire (until
184 * when should we never do a DHT lookup for the same name again)?
185 * @param rd_count number of entries in 'rd' array
186 * @param rd array of records with data to store
187 * @param signature signature for all the records in the zone under the given name
188 * @param cont continuation to call when done
189 * @param cont_cls closure for cont
190 * @return handle to abort the request
192 struct GNUNET_NAMESTORE_QueueEntry *
193 GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h,
194 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
196 struct GNUNET_TIME_Absolute expire,
197 unsigned int rd_count,
198 const struct GNUNET_NAMESTORE_RecordData *rd,
199 const struct GNUNET_CRYPTO_RsaSignature *signature,
200 GNUNET_NAMESTORE_ContinuationWithStatus cont,
205 * Check if a signature is valid. This API is used by the GNS Block
206 * to validate signatures received from the network.
208 * @param public_key public key of the zone
209 * @param expire block expiration
210 * @param name name that is being mapped (at most 255 characters long)
211 * @param rd_count number of entries in 'rd' array
212 * @param rd array of records with data to store
213 * @param signature signature for all the records in the zone under the given name
214 * @return GNUNET_OK if the signature is valid
217 GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key,
218 const struct GNUNET_TIME_Absolute expire,
220 unsigned int rd_count,
221 const struct GNUNET_NAMESTORE_RecordData *rd,
222 const struct GNUNET_CRYPTO_RsaSignature *signature);
226 * Store an item in the namestore. If the item is already present,
227 * the expiration time is updated to the max of the existing time and
228 * the new time. This API is used by the authority of a zone.
230 * @param h handle to the namestore
231 * @param pkey private key of the zone
232 * @param expire block expiration time
233 * @param name name that is being mapped (at most 255 characters long)
234 * @param rd record data to store
235 * @param cont continuation to call when done
236 * @param cont_cls closure for cont
237 * @return handle to abort the request
239 struct GNUNET_NAMESTORE_QueueEntry *
240 GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h,
241 const struct GNUNET_CRYPTO_RsaPrivateKey *pkey,
243 const struct GNUNET_NAMESTORE_RecordData *rd,
244 GNUNET_NAMESTORE_ContinuationWithStatus cont,
249 * Explicitly remove some content from the database. The
250 * "cont"inuation will be called with status "GNUNET_OK" if content
251 * was removed, "GNUNET_NO" if no matching entry was found and
252 * "GNUNET_SYSERR" on all other types of errors.
253 * This API is used by the authority of a zone.
255 * @param h handle to the namestore
256 * @param pkey private key of the zone
257 * @param name name that is being mapped (at most 255 characters long)
258 * @param rd record data
259 * @param cont continuation to call when done
260 * @param cont_cls closure for cont
261 * @return handle to abort the request
263 struct GNUNET_NAMESTORE_QueueEntry *
264 GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h,
265 const struct GNUNET_CRYPTO_RsaPrivateKey *pkey,
267 const struct GNUNET_NAMESTORE_RecordData *rd,
268 GNUNET_NAMESTORE_ContinuationWithStatus cont,
273 * Process a record that was stored in the namestore.
276 * @param zone_key public key of the zone
277 * @param expire when does the corresponding block in the DHT expire (until
278 * when should we never do a DHT lookup for the same name again)?;
279 * GNUNET_TIME_UNIT_ZERO_ABS if there are no records of any type in the namestore,
280 * or the expiration time of the block in the namestore (even if there are zero
281 * records matching the desired record type)
282 * @param name name that is being mapped (at most 255 characters long)
283 * @param rd_count number of entries in 'rd' array
284 * @param rd array of records with data to store
285 * @param signature signature of the record block, NULL if signature is unavailable (i.e.
286 * because the user queried for a particular record type only)
288 typedef void (*GNUNET_NAMESTORE_RecordProcessor) (void *cls,
289 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
290 struct GNUNET_TIME_Absolute expire,
293 const struct GNUNET_NAMESTORE_RecordData *rd,
294 const struct GNUNET_CRYPTO_RsaSignature *signature);
298 * Get a result for a particular key from the namestore. The processor
299 * will only be called once.
301 * @param h handle to the namestore
302 * @param zone zone to look up a record from
303 * @param name name to look up
304 * @param record_type desired record type, 0 for all
305 * @param proc function to call on the matching records, or with
306 * NULL (rd_count == 0) if there are no matching records
307 * @param proc_cls closure for proc
308 * @return a handle that can be used to
311 struct GNUNET_NAMESTORE_QueueEntry *
312 GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h,
313 const GNUNET_HashCode *zone,
315 uint32_t record_type,
316 GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls);
320 * Look for an existing PKEY delegation record for a given public key.
321 * Returns at most one result to the processor.
323 * @param h handle to the namestore
324 * @param zone hash of public key of the zone to look up in, never NULL
325 * @param value_zone hash of the public key of the target zone (value), never NULL
326 * @param proc function to call on the matching records, or with
327 * NULL (rd_count == 0) if there are no matching records
328 * @param proc_cls closure for proc
329 * @return a handle that can be used to
332 struct GNUNET_NAMESTORE_QueueEntry *
333 GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h,
334 const GNUNET_HashCode *zone,
335 const GNUNET_HashCode *value_zone,
336 GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls);
341 * Starts a new zone iteration (used to periodically PUT all of our
342 * records into our DHT). This MUST lock the GNUNET_NAMESTORE_Handle
343 * for any other calls than GNUNET_NAMESTORE_zone_iterator_next and
344 * GNUNET_NAMESTORE_zone_iteration_stop. "proc" will be called once
345 * immediately, and then again after
346 * "GNUNET_NAMESTORE_zone_iterator_next" is invoked.
348 * @param h handle to the namestore
349 * @param zone zone to access, NULL for all zones
350 * @param must_have_flags flags that must be set for the record to be returned
351 * @param must_not_have_flags flags that must NOT be set for the record to be returned
352 * @param proc function to call on each name from the zone; it
353 * will be called repeatedly with a value (if available)
354 * and always once at the end with a name of NULL.
355 * @param proc_cls closure for proc
356 * @return an iterator handle to use for iteration
358 struct GNUNET_NAMESTORE_ZoneIterator *
359 GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
360 const GNUNET_HashCode *zone,
361 enum GNUNET_NAMESTORE_RecordFlags must_have_flags,
362 enum GNUNET_NAMESTORE_RecordFlags must_not_have_flags,
363 GNUNET_NAMESTORE_RecordProcessor proc,
368 * Calls the record processor specified in GNUNET_NAMESTORE_zone_iteration_start
369 * for the next record.
371 * @param it the iterator
374 GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it);
378 * Stops iteration and releases the namestore handle for further calls.
380 * @param it the iterator
383 GNUNET_NAMESTORE_zone_iteration_stop (struct GNUNET_NAMESTORE_ZoneIterator *it);
387 * Cancel a namestore operation. The final callback from the
388 * operation must not have been done yet.
390 * @param qe operation to cancel
393 GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe);
397 /* convenience APIs for serializing / deserializing GNS records */
400 * Calculate how many bytes we will need to serialize the given
403 * @param rd_count number of records in the rd array
404 * @param rd array of GNUNET_NAMESTORE_RecordData with rd_count elements
406 * @return the required size to serialize
410 GNUNET_NAMESTORE_records_get_size (unsigned int rd_count,
411 const struct GNUNET_NAMESTORE_RecordData *rd);
414 * Serialize the given records to the given destination buffer.
416 * @param rd_count number of records in the rd array
417 * @param rd array of GNUNET_NAMESTORE_RecordData with rd_count elements
418 * @param dest_size size of the destination array
419 * @param dest where to write the result
421 * @return the size of serialized records
424 GNUNET_NAMESTORE_records_serialize (unsigned int rd_count,
425 const struct GNUNET_NAMESTORE_RecordData *rd,
431 * Deserialize the given records to the given destination.
433 * @param len size of the serialized record data
434 * @param src the serialized record data
435 * @param rd_count number of records in the rd array
436 * @param dest where to put the data
438 * @return GNUNET_OK on success, GNUNET_SYSERR on error
441 GNUNET_NAMESTORE_records_deserialize (size_t len,
443 unsigned int rd_count,
444 struct GNUNET_NAMESTORE_RecordData *dest);
449 * Convert the 'value' of a record to a string.
451 * @param type type of the record
452 * @param data value in binary encoding
453 * @param data_size number of bytes in data
454 * @return NULL on error, otherwise human-readable representation of the value
457 GNUNET_NAMESTORE_value_to_string (uint32_t type,
463 * Convert human-readable version of a 'value' of a record to the binary
466 * @param type type of the record
467 * @param s human-readable string
468 * @param data set to value in binary encoding (will be allocated)
469 * @param data_size set to number of bytes in data
470 * @return GNUNET_OK on success
473 GNUNET_NAMESTORE_string_to_value (uint32_t type,
480 * Convert a type name (i.e. "AAAA") to the corresponding number.
482 * @param typename name to convert
483 * @return corresponding number, UINT32_MAX on error
486 GNUNET_NAMESTORE_typename_to_number (const char *typename);
490 * Convert a type number (i.e. 1) to the corresponding type string (i.e. "A")
492 * @param type number of a type to convert
493 * @return corresponding typestring, NULL on error
496 GNUNET_NAMESTORE_number_to_typename (uint32_t type);
499 #if 0 /* keep Emacsens' auto-indent happy */
506 /* end of gnunet_namestore_service.h */