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
111 * @param drop set to GNUNET_YES to delete all data in namestore (!)
114 GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h, int drop);
118 * Continuation called to notify client about result of the
122 * @param success GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate)
123 * GNUNET_NO if content was already there or not found
124 * GNUNET_YES (or other positive value) on success
125 * @param emsg NULL on success, otherwise an error message
127 typedef void (*GNUNET_NAMESTORE_ContinuationWithStatus) (void *cls,
133 * Flags that can be set for a record.
135 enum GNUNET_NAMESTORE_RecordFlags
139 * No special options.
141 GNUNET_NAMESTORE_RF_NONE = 0,
144 * This peer is the authority for this record; it must thus
145 * not be deleted (other records can be deleted if we run
148 GNUNET_NAMESTORE_RF_AUTHORITY = 1,
151 * This is a private record of this peer and it should
152 * thus not be handed out to other peers.
154 GNUNET_NAMESTORE_RF_PRIVATE = 2,
157 * This record was added by the system
158 * and is pending user confimation
160 GNUNET_NAMESTORE_RF_PENDING = 4,
163 * This expiration time of the record is a relative
164 * time (not an absolute time).
166 GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION = 8
174 struct GNUNET_NAMESTORE_RecordData
178 * Binary value stored in the DNS record.
183 * Expiration time for the DNS record. Can be relative
184 * or absolute, depending on 'flags'.
186 uint64_t expiration_time;
189 * Number of bytes in 'data'.
194 * Type of the GNS/DNS record.
196 uint32_t record_type;
199 * Flags for the record.
201 enum GNUNET_NAMESTORE_RecordFlags flags;
206 * Store an item in the namestore. If the item is already present,
207 * the expiration time is updated to the max of the existing time and
208 * the new time. This API is used when we cache signatures from other
211 * @param h handle to the namestore
212 * @param zone_key public key of the zone
213 * @param name name that is being mapped (at most 255 characters long)
214 * @param freshness when does the corresponding block in the DHT expire (until
215 * when should we never do a DHT lookup for the same name again)?
216 * @param rd_count number of entries in 'rd' array
217 * @param rd array of records with data to store
218 * @param signature signature for all the records in the zone under the given name
219 * @param cont continuation to call when done
220 * @param cont_cls closure for cont
221 * @return handle to abort the request
223 struct GNUNET_NAMESTORE_QueueEntry *
224 GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h,
225 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
227 struct GNUNET_TIME_Absolute freshness,
228 unsigned int rd_count,
229 const struct GNUNET_NAMESTORE_RecordData *rd,
230 const struct GNUNET_CRYPTO_RsaSignature *signature,
231 GNUNET_NAMESTORE_ContinuationWithStatus cont,
236 * Check if a signature is valid. This API is used by the GNS Block
237 * to validate signatures received from the network.
239 * @param public_key public key of the zone
240 * @param freshness time set for block expiration
241 * @param name name that is being mapped (at most 255 characters long)
242 * @param rd_count number of entries in 'rd' array
243 * @param rd array of records with data to store
244 * @param signature signature for all the records in the zone under the given name
245 * @return GNUNET_OK if the signature is valid
248 GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key,
249 const struct GNUNET_TIME_Absolute freshness,
251 unsigned int rd_count,
252 const struct GNUNET_NAMESTORE_RecordData *rd,
253 const struct GNUNET_CRYPTO_RsaSignature *signature);
257 * Store an item in the namestore. If the item is already present,
258 * the expiration time is updated to the max of the existing time and
259 * the new time. This API is used by the authority of a zone.
261 * @param h handle to the namestore
262 * @param pkey private key of the zone
263 * @param name name that is being mapped (at most 255 characters long)
264 * @param rd record data to store
265 * @param cont continuation to call when done
266 * @param cont_cls closure for cont
267 * @return handle to abort the request
269 struct GNUNET_NAMESTORE_QueueEntry *
270 GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h,
271 const struct GNUNET_CRYPTO_RsaPrivateKey *pkey,
273 const struct GNUNET_NAMESTORE_RecordData *rd,
274 GNUNET_NAMESTORE_ContinuationWithStatus cont,
279 * Explicitly remove some content from the database. The
280 * "cont"inuation will be called with status "GNUNET_OK" if content
281 * was removed, "GNUNET_NO" if no matching entry was found and
282 * "GNUNET_SYSERR" on all other types of errors.
283 * This API is used by the authority of a zone.
285 * @param h handle to the namestore
286 * @param pkey private key of the zone
287 * @param name name that is being mapped (at most 255 characters long)
288 * @param rd record data, remove specific record, NULL to remove the name and all records
289 * @param cont continuation to call when done
290 * @param cont_cls closure for cont
291 * @return handle to abort the request
293 struct GNUNET_NAMESTORE_QueueEntry *
294 GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h,
295 const struct GNUNET_CRYPTO_RsaPrivateKey *pkey,
297 const struct GNUNET_NAMESTORE_RecordData *rd,
298 GNUNET_NAMESTORE_ContinuationWithStatus cont,
303 * Process a record that was stored in the namestore.
306 * @param zone_key public key of the zone
307 * @param freshness when does the corresponding block in the DHT expire (until
308 * when should we never do a DHT lookup for the same name again)?;
309 * GNUNET_TIME_UNIT_ZERO_ABS if there are no records of any type in the namestore,
310 * or the expiration time of the block in the namestore (even if there are zero
311 * records matching the desired record type)
312 * @param name name that is being mapped (at most 255 characters long)
313 * @param rd_count number of entries in 'rd' array
314 * @param rd array of records with data to store
315 * @param signature signature of the record block, NULL if signature is unavailable (i.e.
316 * because the user queried for a particular record type only)
318 typedef void (*GNUNET_NAMESTORE_RecordProcessor) (void *cls,
319 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
320 struct GNUNET_TIME_Absolute freshness,
323 const struct GNUNET_NAMESTORE_RecordData *rd,
324 const struct GNUNET_CRYPTO_RsaSignature *signature);
328 * Get a result for a particular key from the namestore. The processor
329 * will only be called once.
331 * @param h handle to the namestore
332 * @param zone zone to look up a record from
333 * @param name name to look up
334 * @param record_type desired record type, 0 for all
335 * @param proc function to call on the matching records, or with
336 * NULL (rd_count == 0) if there are no matching records
337 * @param proc_cls closure for proc
338 * @return a handle that can be used to
341 struct GNUNET_NAMESTORE_QueueEntry *
342 GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h,
343 const struct GNUNET_CRYPTO_ShortHashCode *zone,
345 uint32_t record_type,
346 GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls);
350 * Look for an existing PKEY delegation record for a given public key.
351 * Returns at most one result to the processor.
353 * @param h handle to the namestore
354 * @param zone hash of public key of the zone to look up in, never NULL
355 * @param value_zone hash of the public key of the target zone (value), never NULL
356 * @param proc function to call on the matching records, or with
357 * NULL (rd_count == 0) if there are no matching records
358 * @param proc_cls closure for proc
359 * @return a handle that can be used to
362 struct GNUNET_NAMESTORE_QueueEntry *
363 GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h,
364 const struct GNUNET_CRYPTO_ShortHashCode *zone,
365 const struct GNUNET_CRYPTO_ShortHashCode *value_zone,
366 GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls);
371 * Starts a new zone iteration (used to periodically PUT all of our
372 * records into our DHT). "proc" will be called once immediately, and
373 * then again after "GNUNET_NAMESTORE_zone_iterator_next" is invoked.
375 * By specifying a 'zone' of NULL and setting 'GNUNET_NAMESTORE_RF_AUTHORITY'
376 * in 'must_have_flags', we can iterate over all records for which we are
377 * the authority. In this case, the 'GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION'
378 * bit in 'must_have_flags' has a special meaning:
380 * 0) If the bit is clear, all relative expriation times are converted to
381 * absolute expiration times. This is useful for performing DHT PUT
382 * operations (and zone transfers) of our zone.
383 * 1) if it is set, it means that relative expiration times should be
384 * preserved when returned (this is useful for the zone editor user
387 * Note that not all queries against this interface are equally performant
388 * as for some combinations no efficient index may exist.
390 * @param h handle to the namestore
391 * @param zone zone to access, NULL for all zones
392 * @param must_have_flags flags that must be set for the record to be returned
393 * @param must_not_have_flags flags that must NOT be set for the record to be returned
394 * @param proc function to call on each name from the zone; it
395 * will be called repeatedly with a value (if available)
396 * and always once at the end with a name of NULL.
397 * @param proc_cls closure for proc
398 * @return an iterator handle to use for iteration
400 struct GNUNET_NAMESTORE_ZoneIterator *
401 GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
402 const struct GNUNET_CRYPTO_ShortHashCode *zone,
403 enum GNUNET_NAMESTORE_RecordFlags must_have_flags,
404 enum GNUNET_NAMESTORE_RecordFlags must_not_have_flags,
405 GNUNET_NAMESTORE_RecordProcessor proc,
410 * Calls the record processor specified in GNUNET_NAMESTORE_zone_iteration_start
411 * for the next record.
413 * @param it the iterator
416 GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it);
420 * Stops iteration and releases the namestore handle for further calls.
422 * @param it the iterator
425 GNUNET_NAMESTORE_zone_iteration_stop (struct GNUNET_NAMESTORE_ZoneIterator *it);
429 * Cancel a namestore operation. The final callback from the
430 * operation must not have been done yet.
432 * @param qe operation to cancel
435 GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe);
439 /* convenience APIs for serializing / deserializing GNS records */
442 * Calculate how many bytes we will need to serialize the given
445 * @param rd_count number of records in the rd array
446 * @param rd array of GNUNET_NAMESTORE_RecordData with rd_count elements
448 * @return the required size to serialize
452 GNUNET_NAMESTORE_records_get_size (unsigned int rd_count,
453 const struct GNUNET_NAMESTORE_RecordData *rd);
456 * Serialize the given records to the given destination buffer.
458 * @param rd_count number of records in the rd array
459 * @param rd array of GNUNET_NAMESTORE_RecordData with rd_count elements
460 * @param dest_size size of the destination array
461 * @param dest where to write the result
463 * @return the size of serialized records
466 GNUNET_NAMESTORE_records_serialize (unsigned int rd_count,
467 const struct GNUNET_NAMESTORE_RecordData *rd,
473 * Deserialize the given records to the given destination.
475 * @param len size of the serialized record data
476 * @param src the serialized record data
477 * @param rd_count number of records in the rd array
478 * @param dest where to put the data
480 * @return GNUNET_OK on success, GNUNET_SYSERR on error
483 GNUNET_NAMESTORE_records_deserialize (size_t len,
485 unsigned int rd_count,
486 struct GNUNET_NAMESTORE_RecordData *dest);
490 * Checks if a name is wellformed
492 * @param name the name to check
493 * @return GNUNET_OK on success, GNUNET_SYSERR on error
496 GNUNET_NAMESTORE_check_name (const char * name);
499 * Convert the 'value' of a record to a string.
501 * @param type type of the record
502 * @param data value in binary encoding
503 * @param data_size number of bytes in data
504 * @return NULL on error, otherwise human-readable representation of the value
507 GNUNET_NAMESTORE_value_to_string (uint32_t type,
513 * Convert human-readable version of a 'value' of a record to the binary
516 * @param type type of the record
517 * @param s human-readable string
518 * @param data set to value in binary encoding (will be allocated)
519 * @param data_size set to number of bytes in data
520 * @return GNUNET_OK on success
523 GNUNET_NAMESTORE_string_to_value (uint32_t type,
530 * Convert a type name (i.e. "AAAA") to the corresponding number.
532 * @param typename name to convert
533 * @return corresponding number, UINT32_MAX on error
536 GNUNET_NAMESTORE_typename_to_number (const char *typename);
540 * Convert a type number (i.e. 1) to the corresponding type string (i.e. "A")
542 * @param type number of a type to convert
543 * @return corresponding typestring, NULL on error
546 GNUNET_NAMESTORE_number_to_typename (uint32_t type);
549 #if 0 /* keep Emacsens' auto-indent happy */
556 /* end of gnunet_namestore_service.h */