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 indicating any record/'*'
49 #define GNUNET_NAMESTORE_TYPE_ANY 0
52 * Record type for GNS zone transfer ("PKEY").
54 #define GNUNET_NAMESTORE_TYPE_PKEY 65536
57 * Record type for GNS zone transfer ("PSEU").
59 #define GNUNET_NAMESTORE_TYPE_PSEU 65537
62 * Record type for GNS legacy hostnames ("LEHO").
64 #define GNUNET_NAMESTORE_TYPE_LEHO 65538
69 struct GNUNET_NAMESTORE_QueueEntry;
72 * Handle to the namestore service.
74 struct GNUNET_NAMESTORE_Handle;
77 * Handle to the namestore zone iterator.
79 struct GNUNET_NAMESTORE_ZoneIterator;
82 * Maximum size of a value that can be stored in the namestore.
84 #define GNUNET_NAMESTORE_MAX_VALUE_SIZE (63 * 1024)
89 * Connect to the namestore service.
91 * @param cfg configuration to use
92 * @return handle to use to access the service
94 struct GNUNET_NAMESTORE_Handle *
95 GNUNET_NAMESTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
99 * Disconnect from the namestore service (and free associated
102 * @param h handle to the namestore
103 * @param drop set to GNUNET_YES to delete all data in namestore (!)
106 GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h, int drop);
110 * Continuation called to notify client about result of the
114 * @param success GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate)
115 * GNUNET_NO if content was already there or not found
116 * GNUNET_YES (or other positive value) on success
117 * @param emsg NULL on success, otherwise an error message
119 typedef void (*GNUNET_NAMESTORE_ContinuationWithStatus) (void *cls,
125 * Flags that can be set for a record.
127 enum GNUNET_NAMESTORE_RecordFlags
131 * No special options.
133 GNUNET_NAMESTORE_RF_NONE = 0,
136 * This peer is the authority for this record; it must thus
137 * not be deleted (other records can be deleted if we run
140 GNUNET_NAMESTORE_RF_AUTHORITY = 1,
143 * This is a private record of this peer and it should
144 * thus not be handed out to other peers.
146 GNUNET_NAMESTORE_RF_PRIVATE = 2,
149 * This record was added by the system
150 * and is pending user confimation
152 GNUNET_NAMESTORE_RF_PENDING = 4
160 struct GNUNET_NAMESTORE_RecordData
164 * Binary value stored in the DNS record.
169 * Expiration time for the DNS record.
171 struct GNUNET_TIME_Absolute expiration;
174 * Number of bytes in 'data'.
179 * Type of the GNS/DNS record.
181 uint32_t record_type;
184 * Flags for the record.
186 enum GNUNET_NAMESTORE_RecordFlags flags;
191 * Store an item in the namestore. If the item is already present,
192 * the expiration time is updated to the max of the existing time and
193 * the new time. This API is used when we cache signatures from other
196 * @param h handle to the namestore
197 * @param zone_key public key of the zone
198 * @param name name that is being mapped (at most 255 characters long)
199 * @param freshness when does the corresponding block in the DHT expire (until
200 * when should we never do a DHT lookup for the same name again)?
201 * @param rd_count number of entries in 'rd' array
202 * @param rd array of records with data to store
203 * @param signature signature for all the records in the zone under the given name
204 * @param cont continuation to call when done
205 * @param cont_cls closure for cont
206 * @return handle to abort the request
208 struct GNUNET_NAMESTORE_QueueEntry *
209 GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h,
210 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
212 struct GNUNET_TIME_Absolute freshness,
213 unsigned int rd_count,
214 const struct GNUNET_NAMESTORE_RecordData *rd,
215 const struct GNUNET_CRYPTO_RsaSignature *signature,
216 GNUNET_NAMESTORE_ContinuationWithStatus cont,
221 * Check if a signature is valid. This API is used by the GNS Block
222 * to validate signatures received from the network.
224 * @param public_key public key of the zone
225 * @param expire block expiration
226 * @param name name that is being mapped (at most 255 characters long)
227 * @param rd_count number of entries in 'rd' array
228 * @param rd array of records with data to store
229 * @param signature signature for all the records in the zone under the given name
230 * @return GNUNET_OK if the signature is valid
233 GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key,
234 const struct GNUNET_TIME_Absolute freshness,
236 unsigned int rd_count,
237 const struct GNUNET_NAMESTORE_RecordData *rd,
238 const struct GNUNET_CRYPTO_RsaSignature *signature);
242 * Store an item in the namestore. If the item is already present,
243 * the expiration time is updated to the max of the existing time and
244 * the new time. This API is used by the authority of a zone.
246 * @param h handle to the namestore
247 * @param pkey private key of the zone
248 * @param name name that is being mapped (at most 255 characters long)
249 * @param rd record data to store
250 * @param cont continuation to call when done
251 * @param cont_cls closure for cont
252 * @return handle to abort the request
254 struct GNUNET_NAMESTORE_QueueEntry *
255 GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h,
256 const struct GNUNET_CRYPTO_RsaPrivateKey *pkey,
258 const struct GNUNET_NAMESTORE_RecordData *rd,
259 GNUNET_NAMESTORE_ContinuationWithStatus cont,
264 * Explicitly remove some content from the database. The
265 * "cont"inuation will be called with status "GNUNET_OK" if content
266 * was removed, "GNUNET_NO" if no matching entry was found and
267 * "GNUNET_SYSERR" on all other types of errors.
268 * This API is used by the authority of a zone.
270 * @param h handle to the namestore
271 * @param pkey private key of the zone
272 * @param name name that is being mapped (at most 255 characters long)
273 * @param rd record data, remove specific record, NULL to remove the name and all records
274 * @param cont continuation to call when done
275 * @param cont_cls closure for cont
276 * @return handle to abort the request
278 struct GNUNET_NAMESTORE_QueueEntry *
279 GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h,
280 const struct GNUNET_CRYPTO_RsaPrivateKey *pkey,
282 const struct GNUNET_NAMESTORE_RecordData *rd,
283 GNUNET_NAMESTORE_ContinuationWithStatus cont,
288 * Process a record that was stored in the namestore.
291 * @param zone_key public key of the zone
292 * @param expire when does the corresponding block in the DHT expire (until
293 * when should we never do a DHT lookup for the same name again)?;
294 * GNUNET_TIME_UNIT_ZERO_ABS if there are no records of any type in the namestore,
295 * or the expiration time of the block in the namestore (even if there are zero
296 * records matching the desired record type)
297 * @param name name that is being mapped (at most 255 characters long)
298 * @param rd_count number of entries in 'rd' array
299 * @param rd array of records with data to store
300 * @param signature signature of the record block, NULL if signature is unavailable (i.e.
301 * because the user queried for a particular record type only)
303 typedef void (*GNUNET_NAMESTORE_RecordProcessor) (void *cls,
304 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
305 struct GNUNET_TIME_Absolute freshness,
308 const struct GNUNET_NAMESTORE_RecordData *rd,
309 const struct GNUNET_CRYPTO_RsaSignature *signature);
313 * Get a result for a particular key from the namestore. The processor
314 * will only be called once.
316 * @param h handle to the namestore
317 * @param zone zone to look up a record from
318 * @param name name to look up
319 * @param record_type desired record type, 0 for all
320 * @param proc function to call on the matching records, or with
321 * NULL (rd_count == 0) if there are no matching records
322 * @param proc_cls closure for proc
323 * @return a handle that can be used to
326 struct GNUNET_NAMESTORE_QueueEntry *
327 GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h,
328 const struct GNUNET_CRYPTO_ShortHashCode *zone,
330 uint32_t record_type,
331 GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls);
335 * Look for an existing PKEY delegation record for a given public key.
336 * Returns at most one result to the processor.
338 * @param h handle to the namestore
339 * @param zone hash of public key of the zone to look up in, never NULL
340 * @param value_zone hash of the public key of the target zone (value), never NULL
341 * @param proc function to call on the matching records, or with
342 * NULL (rd_count == 0) if there are no matching records
343 * @param proc_cls closure for proc
344 * @return a handle that can be used to
347 struct GNUNET_NAMESTORE_QueueEntry *
348 GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h,
349 const struct GNUNET_CRYPTO_ShortHashCode *zone,
350 const struct GNUNET_CRYPTO_ShortHashCode *value_zone,
351 GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls);
356 * Starts a new zone iteration (used to periodically PUT all of our
357 * records into our DHT). "proc" will be called once
358 * immediately, and then again after
359 * "GNUNET_NAMESTORE_zone_iterator_next" is invoked.
361 * @param h handle to the namestore
362 * @param zone zone to access, NULL for all zones
363 * @param must_have_flags flags that must be set for the record to be returned
364 * @param must_not_have_flags flags that must NOT be set for the record to be returned
365 * @param proc function to call on each name from the zone; it
366 * will be called repeatedly with a value (if available)
367 * and always once at the end with a name of NULL.
368 * @param proc_cls closure for proc
369 * @return an iterator handle to use for iteration
371 struct GNUNET_NAMESTORE_ZoneIterator *
372 GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
373 const struct GNUNET_CRYPTO_ShortHashCode *zone,
374 enum GNUNET_NAMESTORE_RecordFlags must_have_flags,
375 enum GNUNET_NAMESTORE_RecordFlags must_not_have_flags,
376 GNUNET_NAMESTORE_RecordProcessor proc,
381 * Calls the record processor specified in GNUNET_NAMESTORE_zone_iteration_start
382 * for the next record.
384 * @param it the iterator
387 GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it);
391 * Stops iteration and releases the namestore handle for further calls.
393 * @param it the iterator
396 GNUNET_NAMESTORE_zone_iteration_stop (struct GNUNET_NAMESTORE_ZoneIterator *it);
400 * Cancel a namestore operation. The final callback from the
401 * operation must not have been done yet.
403 * @param qe operation to cancel
406 GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe);
410 /* convenience APIs for serializing / deserializing GNS records */
413 * Calculate how many bytes we will need to serialize the given
416 * @param rd_count number of records in the rd array
417 * @param rd array of GNUNET_NAMESTORE_RecordData with rd_count elements
419 * @return the required size to serialize
423 GNUNET_NAMESTORE_records_get_size (unsigned int rd_count,
424 const struct GNUNET_NAMESTORE_RecordData *rd);
427 * Serialize the given records to the given destination buffer.
429 * @param rd_count number of records in the rd array
430 * @param rd array of GNUNET_NAMESTORE_RecordData with rd_count elements
431 * @param dest_size size of the destination array
432 * @param dest where to write the result
434 * @return the size of serialized records
437 GNUNET_NAMESTORE_records_serialize (unsigned int rd_count,
438 const struct GNUNET_NAMESTORE_RecordData *rd,
444 * Deserialize the given records to the given destination.
446 * @param len size of the serialized record data
447 * @param src the serialized record data
448 * @param rd_count number of records in the rd array
449 * @param dest where to put the data
451 * @return GNUNET_OK on success, GNUNET_SYSERR on error
454 GNUNET_NAMESTORE_records_deserialize (size_t len,
456 unsigned int rd_count,
457 struct GNUNET_NAMESTORE_RecordData *dest);
461 * Checks if a name is wellformed
463 * @param name the name to check
464 * @return GNUNET_OK on success, GNUNET_SYSERR on error
467 GNUNET_NAMESTORE_check_name (const char * name);
470 * Convert the 'value' of a record to a string.
472 * @param type type of the record
473 * @param data value in binary encoding
474 * @param data_size number of bytes in data
475 * @return NULL on error, otherwise human-readable representation of the value
478 GNUNET_NAMESTORE_value_to_string (uint32_t type,
484 * Convert human-readable version of a 'value' of a record to the binary
487 * @param type type of the record
488 * @param s human-readable string
489 * @param data set to value in binary encoding (will be allocated)
490 * @param data_size set to number of bytes in data
491 * @return GNUNET_OK on success
494 GNUNET_NAMESTORE_string_to_value (uint32_t type,
501 * Convert a type name (i.e. "AAAA") to the corresponding number.
503 * @param typename name to convert
504 * @return corresponding number, UINT32_MAX on error
507 GNUNET_NAMESTORE_typename_to_number (const char *typename);
511 * Convert a type number (i.e. 1) to the corresponding type string (i.e. "A")
513 * @param type number of a type to convert
514 * @return corresponding typestring, NULL on error
517 GNUNET_NAMESTORE_number_to_typename (uint32_t type);
520 #if 0 /* keep Emacsens' auto-indent happy */
527 /* end of gnunet_namestore_service.h */