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
173 struct GNUNET_NAMESTORE_RecordData
177 * Binary value stored in the DNS record.
182 * Expiration time for the DNS record. Can be relative
183 * or absolute, depending on 'flags'.
185 uint64_t expiration_time;
188 * Number of bytes in 'data'.
193 * Type of the GNS/DNS record.
195 uint32_t record_type;
198 * Flags for the record.
200 enum GNUNET_NAMESTORE_RecordFlags flags;
205 * Store an item in the namestore. If the item is already present,
206 * the expiration time is updated to the max of the existing time and
207 * the new time. This API is used when we cache signatures from other
210 * @param h handle to the namestore
211 * @param zone_key public key of the zone
212 * @param name name that is being mapped (at most 255 characters long)
213 * @param freshness when does the corresponding block in the DHT expire (until
214 * when should we never do a DHT lookup for the same name again)?
215 * @param rd_count number of entries in 'rd' array
216 * @param rd array of records with data to store
217 * @param signature signature for all the records in the zone under the given name
218 * @param cont continuation to call when done
219 * @param cont_cls closure for cont
220 * @return handle to abort the request
222 struct GNUNET_NAMESTORE_QueueEntry *
223 GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h,
224 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
226 struct GNUNET_TIME_Absolute freshness,
227 unsigned int rd_count,
228 const struct GNUNET_NAMESTORE_RecordData *rd,
229 const struct GNUNET_CRYPTO_RsaSignature *signature,
230 GNUNET_NAMESTORE_ContinuationWithStatus cont,
235 * Check if a signature is valid. This API is used by the GNS Block
236 * to validate signatures received from the network.
238 * @param public_key public key of the zone
239 * @param freshness time set for block expiration
240 * @param name name that is being mapped (at most 255 characters long)
241 * @param rd_count number of entries in 'rd' array
242 * @param rd array of records with data to store
243 * @param signature signature for all the records in the zone under the given name
244 * @return GNUNET_OK if the signature is valid
247 GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key,
248 const struct GNUNET_TIME_Absolute freshness,
250 unsigned int rd_count,
251 const struct GNUNET_NAMESTORE_RecordData *rd,
252 const struct GNUNET_CRYPTO_RsaSignature *signature);
256 * Store an item in the namestore. If the item is already present,
257 * the expiration time is updated to the max of the existing time and
258 * the new time. This API is used by the authority of a zone.
260 * @param h handle to the namestore
261 * @param pkey private key of the zone
262 * @param name name that is being mapped (at most 255 characters long)
263 * @param rd record data to store
264 * @param cont continuation to call when done
265 * @param cont_cls closure for cont
266 * @return handle to abort the request
268 struct GNUNET_NAMESTORE_QueueEntry *
269 GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h,
270 const struct GNUNET_CRYPTO_RsaPrivateKey *pkey,
272 const struct GNUNET_NAMESTORE_RecordData *rd,
273 GNUNET_NAMESTORE_ContinuationWithStatus cont,
278 * Explicitly remove some content from the database. The
279 * "cont"inuation will be called with status "GNUNET_OK" if content
280 * was removed, "GNUNET_NO" if no matching entry was found and
281 * "GNUNET_SYSERR" on all other types of errors.
282 * This API is used by the authority of a zone.
284 * @param h handle to the namestore
285 * @param pkey private key of the zone
286 * @param name name that is being mapped (at most 255 characters long)
287 * @param rd record data, remove specific record, NULL to remove the name and all records
288 * @param cont continuation to call when done
289 * @param cont_cls closure for cont
290 * @return handle to abort the request
292 struct GNUNET_NAMESTORE_QueueEntry *
293 GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h,
294 const struct GNUNET_CRYPTO_RsaPrivateKey *pkey,
296 const struct GNUNET_NAMESTORE_RecordData *rd,
297 GNUNET_NAMESTORE_ContinuationWithStatus cont,
302 * Process a record that was stored in the namestore.
305 * @param zone_key public key of the zone
306 * @param freshness when does the corresponding block in the DHT expire (until
307 * when should we never do a DHT lookup for the same name again)?;
308 * GNUNET_TIME_UNIT_ZERO_ABS if there are no records of any type in the namestore,
309 * or the expiration time of the block in the namestore (even if there are zero
310 * records matching the desired record type)
311 * @param name name that is being mapped (at most 255 characters long)
312 * @param rd_count number of entries in 'rd' array
313 * @param rd array of records with data to store
314 * @param signature signature of the record block, NULL if signature is unavailable (i.e.
315 * because the user queried for a particular record type only)
317 typedef void (*GNUNET_NAMESTORE_RecordProcessor) (void *cls,
318 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
319 struct GNUNET_TIME_Absolute freshness,
322 const struct GNUNET_NAMESTORE_RecordData *rd,
323 const struct GNUNET_CRYPTO_RsaSignature *signature);
327 * Get a result for a particular key from the namestore. The processor
328 * will only be called once.
330 * @param h handle to the namestore
331 * @param zone zone to look up a record from
332 * @param name name to look up
333 * @param record_type desired record type, 0 for all
334 * @param proc function to call on the matching records, or with
335 * NULL (rd_count == 0) if there are no matching records
336 * @param proc_cls closure for proc
337 * @return a handle that can be used to
340 struct GNUNET_NAMESTORE_QueueEntry *
341 GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h,
342 const struct GNUNET_CRYPTO_ShortHashCode *zone,
344 uint32_t record_type,
345 GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls);
349 * Look for an existing PKEY delegation record for a given public key.
350 * Returns at most one result to the processor.
352 * @param h handle to the namestore
353 * @param zone hash of public key of the zone to look up in, never NULL
354 * @param value_zone hash of the public key of the target zone (value), never NULL
355 * @param proc function to call on the matching records, or with
356 * NULL (rd_count == 0) if there are no matching records
357 * @param proc_cls closure for proc
358 * @return a handle that can be used to
361 struct GNUNET_NAMESTORE_QueueEntry *
362 GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h,
363 const struct GNUNET_CRYPTO_ShortHashCode *zone,
364 const struct GNUNET_CRYPTO_ShortHashCode *value_zone,
365 GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls);
370 * Starts a new zone iteration (used to periodically PUT all of our
371 * records into our DHT). "proc" will be called once immediately, and
372 * then again after "GNUNET_NAMESTORE_zone_iterator_next" is invoked.
374 * By specifying a 'zone' of NULL and setting 'GNUNET_NAMESTORE_RF_AUTHORITY'
375 * in 'must_have_flags', we can iterate over all records for which we are
376 * the authority. In this case, the 'GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION'
377 * bit in 'must_have_flags' has a special meaning:
379 * 0) If the bit is clear, all relative expriation times are converted to
380 * absolute expiration times. This is useful for performing DHT PUT
381 * operations (and zone transfers) of our zone.
382 * 1) if it is set, it means that relative expiration times should be
383 * preserved when returned (this is useful for the zone editor user
386 * Note that not all queries against this interface are equally performant
387 * as for some combinations no efficient index may exist.
389 * @param h handle to the namestore
390 * @param zone zone to access, NULL for all zones
391 * @param must_have_flags flags that must be set for the record to be returned
392 * @param must_not_have_flags flags that must NOT be set for the record to be returned
393 * @param proc function to call on each name from the zone; it
394 * will be called repeatedly with a value (if available)
395 * and always once at the end with a name of NULL.
396 * @param proc_cls closure for proc
397 * @return an iterator handle to use for iteration
399 struct GNUNET_NAMESTORE_ZoneIterator *
400 GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
401 const struct GNUNET_CRYPTO_ShortHashCode *zone,
402 enum GNUNET_NAMESTORE_RecordFlags must_have_flags,
403 enum GNUNET_NAMESTORE_RecordFlags must_not_have_flags,
404 GNUNET_NAMESTORE_RecordProcessor proc,
409 * Calls the record processor specified in GNUNET_NAMESTORE_zone_iteration_start
410 * for the next record.
412 * @param it the iterator
415 GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it);
419 * Stops iteration and releases the namestore handle for further calls.
421 * @param it the iterator
424 GNUNET_NAMESTORE_zone_iteration_stop (struct GNUNET_NAMESTORE_ZoneIterator *it);
428 * Cancel a namestore operation. The final callback from the
429 * operation must not have been done yet.
431 * @param qe operation to cancel
434 GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe);
438 /* convenience APIs for serializing / deserializing GNS records */
441 * Calculate how many bytes we will need to serialize the given
444 * @param rd_count number of records in the rd array
445 * @param rd array of GNUNET_NAMESTORE_RecordData with rd_count elements
447 * @return the required size to serialize
451 GNUNET_NAMESTORE_records_get_size (unsigned int rd_count,
452 const struct GNUNET_NAMESTORE_RecordData *rd);
455 * Serialize the given records to the given destination buffer.
457 * @param rd_count number of records in the rd array
458 * @param rd array of GNUNET_NAMESTORE_RecordData with rd_count elements
459 * @param dest_size size of the destination array
460 * @param dest where to write the result
462 * @return the size of serialized records
465 GNUNET_NAMESTORE_records_serialize (unsigned int rd_count,
466 const struct GNUNET_NAMESTORE_RecordData *rd,
472 * Deserialize the given records to the given destination.
474 * @param len size of the serialized record data
475 * @param src the serialized record data
476 * @param rd_count number of records in the rd array
477 * @param dest where to put the data
479 * @return GNUNET_OK on success, GNUNET_SYSERR on error
482 GNUNET_NAMESTORE_records_deserialize (size_t len,
484 unsigned int rd_count,
485 struct GNUNET_NAMESTORE_RecordData *dest);
489 * Checks if a name is wellformed
491 * @param name the name to check
492 * @return GNUNET_OK on success, GNUNET_SYSERR on error
495 GNUNET_NAMESTORE_check_name (const char * name);
498 * Convert the 'value' of a record to a string.
500 * @param type type of the record
501 * @param data value in binary encoding
502 * @param data_size number of bytes in data
503 * @return NULL on error, otherwise human-readable representation of the value
506 GNUNET_NAMESTORE_value_to_string (uint32_t type,
512 * Convert human-readable version of a 'value' of a record to the binary
515 * @param type type of the record
516 * @param s human-readable string
517 * @param data set to value in binary encoding (will be allocated)
518 * @param data_size set to number of bytes in data
519 * @return GNUNET_OK on success
522 GNUNET_NAMESTORE_string_to_value (uint32_t type,
529 * Convert a type name (i.e. "AAAA") to the corresponding number.
531 * @param typename name to convert
532 * @return corresponding number, UINT32_MAX on error
535 GNUNET_NAMESTORE_typename_to_number (const char *typename);
539 * Convert a type number (i.e. 1) to the corresponding type string (i.e. "A")
541 * @param type number of a type to convert
542 * @return corresponding typestring, NULL on error
545 GNUNET_NAMESTORE_number_to_typename (uint32_t type);
548 #if 0 /* keep Emacsens' auto-indent happy */
555 /* end of gnunet_namestore_service.h */