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
30 #ifndef GNUNET_NAMESTORE_SERVICE_H
31 #define GNUNET_NAMESTORE_SERVICE_H
33 #include "gnunet_util_lib.h"
34 #include "gnunet_block_lib.h"
39 #if 0 /* keep Emacsens' auto-indent happy */
45 * Record type indicating any record/'*'
47 #define GNUNET_NAMESTORE_TYPE_ANY 0
50 * Record type for GNS zone transfer ("PKEY").
52 #define GNUNET_NAMESTORE_TYPE_PKEY 65536
55 * Record type for GNS zone transfer ("PSEU").
57 #define GNUNET_NAMESTORE_TYPE_PSEU 65537
60 * Record type for GNS legacy hostnames ("LEHO").
62 #define GNUNET_NAMESTORE_TYPE_LEHO 65538
65 * Record type for VPN resolution
67 #define GNUNET_NAMESTORE_TYPE_VPN 65539
70 * Record type for zone revocation
72 #define GNUNET_NAMESTORE_TYPE_REV 65540
77 struct GNUNET_NAMESTORE_QueueEntry;
80 * Handle to the namestore service.
82 struct GNUNET_NAMESTORE_Handle;
85 * Handle to the namestore zone iterator.
87 struct GNUNET_NAMESTORE_ZoneIterator;
90 * Maximum size of a value that can be stored in the namestore.
92 #define GNUNET_NAMESTORE_MAX_VALUE_SIZE (63 * 1024)
97 * Connect to the namestore service.
99 * @param cfg configuration to use
100 * @return handle to use to access the service
102 struct GNUNET_NAMESTORE_Handle *
103 GNUNET_NAMESTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
107 * Disconnect from the namestore service (and free associated
110 * @param h handle to the namestore
113 GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h);
117 * Continuation called to notify client about result of the
121 * @param success GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate)
122 * GNUNET_NO if content was already there or not found
123 * GNUNET_YES (or other positive value) on success
124 * @param emsg NULL on success, otherwise an error message
126 typedef void (*GNUNET_NAMESTORE_ContinuationWithStatus) (void *cls,
132 * Flags that can be set for a record.
134 enum GNUNET_NAMESTORE_RecordFlags
138 * No special options.
140 GNUNET_NAMESTORE_RF_NONE = 0,
143 * This peer is the authority for this record; it must thus
144 * not be deleted (other records can be deleted if we run
147 GNUNET_NAMESTORE_RF_AUTHORITY = 1,
150 * This is a private record of this peer and it should
151 * thus not be handed out to other peers.
153 GNUNET_NAMESTORE_RF_PRIVATE = 2,
156 * This record was added by the system
157 * and is pending user confimation
159 GNUNET_NAMESTORE_RF_PENDING = 4,
162 * This expiration time of the record is a relative
163 * time (not an absolute time).
165 GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION = 8,
168 * This record should not be used unless all (other) records with an absolute
169 * expiration time have expired.
171 GNUNET_NAMESTORE_RF_SHADOW_RECORD = 16
179 struct GNUNET_NAMESTORE_RecordData
183 * Binary value stored in the DNS record.
188 * Expiration time for the DNS record. Can be relative
189 * or absolute, depending on 'flags'.
191 uint64_t expiration_time;
194 * Number of bytes in 'data'.
199 * Type of the GNS/DNS record.
201 uint32_t record_type;
204 * Flags for the record.
206 enum GNUNET_NAMESTORE_RecordFlags flags;
211 * Store an item in the namestore. If the item is already present,
212 * the expiration time is updated to the max of the existing time and
213 * the new time. This API is used when we cache signatures from other
216 * @param h handle to the namestore
217 * @param zone_key public key of the zone
218 * @param name name that is being mapped (at most 255 characters long)
219 * @param freshness when does the corresponding block in the DHT expire (until
220 * when should we never do a DHT lookup for the same name again)?
221 * @param rd_count number of entries in 'rd' array
222 * @param rd array of records with data to store
223 * @param signature signature for all the records in the zone under the given name
224 * @param cont continuation to call when done
225 * @param cont_cls closure for cont
226 * @return handle to abort the request
228 struct GNUNET_NAMESTORE_QueueEntry *
229 GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h,
230 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
232 struct GNUNET_TIME_Absolute freshness,
233 unsigned int rd_count,
234 const struct GNUNET_NAMESTORE_RecordData *rd,
235 const struct GNUNET_CRYPTO_RsaSignature *signature,
236 GNUNET_NAMESTORE_ContinuationWithStatus cont,
241 * Check if a signature is valid. This API is used by the GNS Block
242 * to validate signatures received from the network.
244 * @param public_key public key of the zone
245 * @param freshness time set for block expiration
246 * @param name name that is being mapped (at most 255 characters long)
247 * @param rd_count number of entries in 'rd' array
248 * @param rd array of records with data to store
249 * @param signature signature for all the records in the zone under the given name
250 * @return GNUNET_OK if the signature is valid
253 GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key,
254 const struct GNUNET_TIME_Absolute freshness,
256 unsigned int rd_count,
257 const struct GNUNET_NAMESTORE_RecordData *rd,
258 const struct GNUNET_CRYPTO_RsaSignature *signature);
262 * Store an item in the namestore. If the item is already present,
263 * the expiration time is updated to the max of the existing time and
264 * the new time. This API is used by the authority of a zone.
265 * FIXME: consider allowing to pass multiple records in one call!
267 * @param h handle to the namestore
268 * @param pkey private key of the zone
269 * @param name name that is being mapped (at most 255 characters long)
270 * @param rd record data to store
271 * @param cont continuation to call when done
272 * @param cont_cls closure for cont
273 * @return handle to abort the request
275 struct GNUNET_NAMESTORE_QueueEntry *
276 GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h,
277 const struct GNUNET_CRYPTO_RsaPrivateKey *pkey,
279 const struct GNUNET_NAMESTORE_RecordData *rd,
280 GNUNET_NAMESTORE_ContinuationWithStatus cont,
285 * Explicitly remove some content from the database. The
286 * "cont"inuation will be called with status "GNUNET_OK" if content
287 * was removed, "GNUNET_NO" if no matching entry was found and
288 * "GNUNET_SYSERR" on all other types of errors.
289 * This API is used by the authority of a zone.
291 * @param h handle to the namestore
292 * @param pkey private key of the zone
293 * @param name name that is being mapped (at most 255 characters long)
294 * @param rd record data, remove specific record, NULL to remove the name and all records
295 * @param cont continuation to call when done
296 * @param cont_cls closure for cont
297 * @return handle to abort the request
299 struct GNUNET_NAMESTORE_QueueEntry *
300 GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h,
301 const struct GNUNET_CRYPTO_RsaPrivateKey *pkey,
303 const struct GNUNET_NAMESTORE_RecordData *rd,
304 GNUNET_NAMESTORE_ContinuationWithStatus cont,
309 * Process a record that was stored in the namestore.
312 * @param zone_key public key of the zone
313 * @param freshness when does the corresponding block in the DHT expire (until
314 * when should we never do a DHT lookup for the same name again)?;
315 * GNUNET_TIME_UNIT_ZERO_ABS if there are no records of any type in the namestore,
316 * or the expiration time of the block in the namestore (even if there are zero
317 * records matching the desired record type)
318 * @param name name that is being mapped (at most 255 characters long)
319 * @param rd_count number of entries in 'rd' array
320 * @param rd array of records with data to store
321 * @param signature signature of the record block, NULL if signature is unavailable (i.e.
322 * because the user queried for a particular record type only)
324 typedef void (*GNUNET_NAMESTORE_RecordProcessor) (void *cls,
325 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
326 struct GNUNET_TIME_Absolute freshness,
329 const struct GNUNET_NAMESTORE_RecordData *rd,
330 const struct GNUNET_CRYPTO_RsaSignature *signature);
334 * Get a result for a particular key from the namestore. The processor
335 * will only be called once. When using this functions, relative expiration
336 * times will be converted to absolute expiration times and a signature
337 * will be created if we are the authority. The record data and signature
338 * passed to 'proc' is thus always suitable for passing on to other peers
339 * (if we are the authority). If the record type is NOT set to 'ANY' and
340 * if we are NOT the authority, then non-matching records may be omitted
341 * from the result and no valid signature can be created; in this case,
342 * 'signature' will be NULL and the result cannot be given to other peers.
344 * @param h handle to the namestore
345 * @param zone zone to look up a record from
346 * @param name name to look up
347 * @param record_type desired record type, 0 for all
348 * @param proc function to call on the matching records, or with
349 * NULL (rd_count == 0) if there are no matching records
350 * @param proc_cls closure for proc
351 * @return a handle that can be used to
354 struct GNUNET_NAMESTORE_QueueEntry *
355 GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h,
356 const struct GNUNET_CRYPTO_ShortHashCode *zone,
358 uint32_t record_type,
359 GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls);
363 * Look for an existing PKEY delegation record for a given public key.
364 * Returns at most one result to the processor.
366 * @param h handle to the namestore
367 * @param zone hash of public key of the zone to look up in, never NULL
368 * @param value_zone hash of the public key of the target zone (value), never NULL
369 * @param proc function to call on the matching records, or with
370 * NULL (rd_count == 0) if there are no matching records
371 * @param proc_cls closure for proc
372 * @return a handle that can be used to
375 struct GNUNET_NAMESTORE_QueueEntry *
376 GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h,
377 const struct GNUNET_CRYPTO_ShortHashCode *zone,
378 const struct GNUNET_CRYPTO_ShortHashCode *value_zone,
379 GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls);
384 * Starts a new zone iteration (used to periodically PUT all of our
385 * records into our DHT). "proc" will be called once immediately, and
386 * then again after "GNUNET_NAMESTORE_zone_iterator_next" is invoked.
388 * By specifying a 'zone' of NULL and setting 'GNUNET_NAMESTORE_RF_AUTHORITY'
389 * in 'must_have_flags', we can iterate over all records for which we are
390 * the authority. In this case, the 'GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION'
391 * bit in 'must_have_flags' has a special meaning:
393 * 0) If the bit is clear, all relative expriation times are converted to
394 * absolute expiration times. This is useful for performing DHT PUT
395 * operations (and zone transfers) of our zone. The generated signatures
396 * will be valid for other peers.
397 * 1) if it is set, it means that relative expiration times should be
398 * preserved when returned (this is useful for the zone editor user
399 * interface). No signatures will be created in this case, as
400 * signatures must not cover records with relative expiration times.
402 * Note that not all queries against this interface are equally performant
403 * as for some combinations no efficient index may exist.
405 * @param h handle to the namestore
406 * @param zone zone to access, NULL for all zones
407 * @param must_have_flags flags that must be set for the record to be returned
408 * @param must_not_have_flags flags that must NOT be set for the record to be returned
409 * @param proc function to call on each name from the zone; it
410 * will be called repeatedly with a value (if available)
411 * and always once at the end with a name of NULL.
412 * @param proc_cls closure for proc
413 * @return an iterator handle to use for iteration
415 struct GNUNET_NAMESTORE_ZoneIterator *
416 GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
417 const struct GNUNET_CRYPTO_ShortHashCode *zone,
418 enum GNUNET_NAMESTORE_RecordFlags must_have_flags,
419 enum GNUNET_NAMESTORE_RecordFlags must_not_have_flags,
420 GNUNET_NAMESTORE_RecordProcessor proc,
425 * Calls the record processor specified in GNUNET_NAMESTORE_zone_iteration_start
426 * for the next record.
428 * @param it the iterator
431 GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it);
435 * Stops iteration and releases the namestore handle for further calls. Must
436 * be called on any iteration that has not yet completed prior to calling
437 * 'GNUNET_NAMESTORE_disconnect'.
439 * @param it the iterator
442 GNUNET_NAMESTORE_zone_iteration_stop (struct GNUNET_NAMESTORE_ZoneIterator *it);
446 * Cancel a namestore operation. The final callback from the
447 * operation must not have been done yet. Must be called on any
448 * namestore operation that has not yet completed prior to calling
449 * 'GNUNET_NAMESTORE_disconnect'.
451 * @param qe operation to cancel
454 GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe);
458 /* convenience APIs for serializing / deserializing GNS records */
461 * Calculate how many bytes we will need to serialize the given
464 * @param rd_count number of records in the rd array
465 * @param rd array of GNUNET_NAMESTORE_RecordData with rd_count elements
467 * @return the required size to serialize
471 GNUNET_NAMESTORE_records_get_size (unsigned int rd_count,
472 const struct GNUNET_NAMESTORE_RecordData *rd);
476 * Serialize the given records to the given destination buffer.
478 * @param rd_count number of records in the rd array
479 * @param rd array of GNUNET_NAMESTORE_RecordData with rd_count elements
480 * @param dest_size size of the destination array
481 * @param dest where to write the result
483 * @return the size of serialized records
486 GNUNET_NAMESTORE_records_serialize (unsigned int rd_count,
487 const struct GNUNET_NAMESTORE_RecordData *rd,
493 * Deserialize the given records to the given destination.
495 * @param len size of the serialized record data
496 * @param src the serialized record data
497 * @param rd_count number of records in the rd array
498 * @param dest where to put the data
500 * @return GNUNET_OK on success, GNUNET_SYSERR on error
503 GNUNET_NAMESTORE_records_deserialize (size_t len,
505 unsigned int rd_count,
506 struct GNUNET_NAMESTORE_RecordData *dest);
510 * Checks if a name is wellformed
512 * @param name the name to check
513 * @return GNUNET_OK on success, GNUNET_SYSERR on error
516 GNUNET_NAMESTORE_check_name (const char * name);
520 * Convert the 'value' of a record to a string.
522 * @param type type of the record
523 * @param data value in binary encoding
524 * @param data_size number of bytes in data
525 * @return NULL on error, otherwise human-readable representation of the value
528 GNUNET_NAMESTORE_value_to_string (uint32_t type,
534 * Convert human-readable version of a 'value' of a record to the binary
537 * @param type type of the record
538 * @param s human-readable string
539 * @param data set to value in binary encoding (will be allocated)
540 * @param data_size set to number of bytes in data
541 * @return GNUNET_OK on success
544 GNUNET_NAMESTORE_string_to_value (uint32_t type,
551 * Convert a type name (i.e. "AAAA") to the corresponding number.
553 * @param typename name to convert
554 * @return corresponding number, UINT32_MAX on error
557 GNUNET_NAMESTORE_typename_to_number (const char *typename);
561 * Convert a type number (i.e. 1) to the corresponding type string (i.e. "A")
563 * @param type number of a type to convert
564 * @return corresponding typestring, NULL on error
567 GNUNET_NAMESTORE_number_to_typename (uint32_t type);
571 * Test if a given record is expired.
573 * @return GNUNET_YES if the record is expired,
577 GNUNET_NAMESTORE_is_expired (const struct GNUNET_NAMESTORE_RecordData *rd);
580 #if 0 /* keep Emacsens' auto-indent happy */
587 /* end of gnunet_namestore_service.h */