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
67 * Record type for VPN resolution
69 #define GNUNET_NAMESTORE_TYPE_VPN 65539
74 struct GNUNET_NAMESTORE_QueueEntry;
77 * Handle to the namestore service.
79 struct GNUNET_NAMESTORE_Handle;
82 * Handle to the namestore zone iterator.
84 struct GNUNET_NAMESTORE_ZoneIterator;
87 * Maximum size of a value that can be stored in the namestore.
89 #define GNUNET_NAMESTORE_MAX_VALUE_SIZE (63 * 1024)
94 * Connect to the namestore service.
96 * @param cfg configuration to use
97 * @return handle to use to access the service
99 struct GNUNET_NAMESTORE_Handle *
100 GNUNET_NAMESTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
104 * Disconnect from the namestore service (and free associated
107 * @param h handle to the namestore
108 * @param drop set to GNUNET_YES to delete all data in namestore (!)
111 GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h, int drop);
115 * Continuation called to notify client about result of the
119 * @param success GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate)
120 * GNUNET_NO if content was already there or not found
121 * GNUNET_YES (or other positive value) on success
122 * @param emsg NULL on success, otherwise an error message
124 typedef void (*GNUNET_NAMESTORE_ContinuationWithStatus) (void *cls,
130 * Flags that can be set for a record.
132 enum GNUNET_NAMESTORE_RecordFlags
136 * No special options.
138 GNUNET_NAMESTORE_RF_NONE = 0,
141 * This peer is the authority for this record; it must thus
142 * not be deleted (other records can be deleted if we run
145 GNUNET_NAMESTORE_RF_AUTHORITY = 1,
148 * This is a private record of this peer and it should
149 * thus not be handed out to other peers.
151 GNUNET_NAMESTORE_RF_PRIVATE = 2,
154 * This record was added by the system
155 * and is pending user confimation
157 GNUNET_NAMESTORE_RF_PENDING = 4
165 struct GNUNET_NAMESTORE_RecordData
169 * Binary value stored in the DNS record.
174 * Expiration time for the DNS record.
176 struct GNUNET_TIME_Absolute expiration;
179 * Number of bytes in 'data'.
184 * Type of the GNS/DNS record.
186 uint32_t record_type;
189 * Flags for the record.
191 enum GNUNET_NAMESTORE_RecordFlags flags;
196 * Store an item in the namestore. If the item is already present,
197 * the expiration time is updated to the max of the existing time and
198 * the new time. This API is used when we cache signatures from other
201 * @param h handle to the namestore
202 * @param zone_key public key of the zone
203 * @param name name that is being mapped (at most 255 characters long)
204 * @param freshness when does the corresponding block in the DHT expire (until
205 * when should we never do a DHT lookup for the same name again)?
206 * @param rd_count number of entries in 'rd' array
207 * @param rd array of records with data to store
208 * @param signature signature for all the records in the zone under the given name
209 * @param cont continuation to call when done
210 * @param cont_cls closure for cont
211 * @return handle to abort the request
213 struct GNUNET_NAMESTORE_QueueEntry *
214 GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h,
215 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
217 struct GNUNET_TIME_Absolute freshness,
218 unsigned int rd_count,
219 const struct GNUNET_NAMESTORE_RecordData *rd,
220 const struct GNUNET_CRYPTO_RsaSignature *signature,
221 GNUNET_NAMESTORE_ContinuationWithStatus cont,
226 * Check if a signature is valid. This API is used by the GNS Block
227 * to validate signatures received from the network.
229 * @param public_key public key of the zone
230 * @param expire block expiration
231 * @param name name that is being mapped (at most 255 characters long)
232 * @param rd_count number of entries in 'rd' array
233 * @param rd array of records with data to store
234 * @param signature signature for all the records in the zone under the given name
235 * @return GNUNET_OK if the signature is valid
238 GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key,
239 const struct GNUNET_TIME_Absolute freshness,
241 unsigned int rd_count,
242 const struct GNUNET_NAMESTORE_RecordData *rd,
243 const struct GNUNET_CRYPTO_RsaSignature *signature);
247 * Store an item in the namestore. If the item is already present,
248 * the expiration time is updated to the max of the existing time and
249 * the new time. This API is used by the authority of a zone.
251 * @param h handle to the namestore
252 * @param pkey private key of the zone
253 * @param name name that is being mapped (at most 255 characters long)
254 * @param rd record data to store
255 * @param cont continuation to call when done
256 * @param cont_cls closure for cont
257 * @return handle to abort the request
259 struct GNUNET_NAMESTORE_QueueEntry *
260 GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h,
261 const struct GNUNET_CRYPTO_RsaPrivateKey *pkey,
263 const struct GNUNET_NAMESTORE_RecordData *rd,
264 GNUNET_NAMESTORE_ContinuationWithStatus cont,
269 * Explicitly remove some content from the database. The
270 * "cont"inuation will be called with status "GNUNET_OK" if content
271 * was removed, "GNUNET_NO" if no matching entry was found and
272 * "GNUNET_SYSERR" on all other types of errors.
273 * This API is used by the authority of a zone.
275 * @param h handle to the namestore
276 * @param pkey private key of the zone
277 * @param name name that is being mapped (at most 255 characters long)
278 * @param rd record data, remove specific record, NULL to remove the name and all records
279 * @param cont continuation to call when done
280 * @param cont_cls closure for cont
281 * @return handle to abort the request
283 struct GNUNET_NAMESTORE_QueueEntry *
284 GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h,
285 const struct GNUNET_CRYPTO_RsaPrivateKey *pkey,
287 const struct GNUNET_NAMESTORE_RecordData *rd,
288 GNUNET_NAMESTORE_ContinuationWithStatus cont,
293 * Process a record that was stored in the namestore.
296 * @param zone_key public key of the zone
297 * @param expire when does the corresponding block in the DHT expire (until
298 * when should we never do a DHT lookup for the same name again)?;
299 * GNUNET_TIME_UNIT_ZERO_ABS if there are no records of any type in the namestore,
300 * or the expiration time of the block in the namestore (even if there are zero
301 * records matching the desired record type)
302 * @param name name that is being mapped (at most 255 characters long)
303 * @param rd_count number of entries in 'rd' array
304 * @param rd array of records with data to store
305 * @param signature signature of the record block, NULL if signature is unavailable (i.e.
306 * because the user queried for a particular record type only)
308 typedef void (*GNUNET_NAMESTORE_RecordProcessor) (void *cls,
309 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
310 struct GNUNET_TIME_Absolute freshness,
313 const struct GNUNET_NAMESTORE_RecordData *rd,
314 const struct GNUNET_CRYPTO_RsaSignature *signature);
318 * Get a result for a particular key from the namestore. The processor
319 * will only be called once.
321 * @param h handle to the namestore
322 * @param zone zone to look up a record from
323 * @param name name to look up
324 * @param record_type desired record type, 0 for all
325 * @param proc function to call on the matching records, or with
326 * NULL (rd_count == 0) if there are no matching records
327 * @param proc_cls closure for proc
328 * @return a handle that can be used to
331 struct GNUNET_NAMESTORE_QueueEntry *
332 GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h,
333 const struct GNUNET_CRYPTO_ShortHashCode *zone,
335 uint32_t record_type,
336 GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls);
340 * Look for an existing PKEY delegation record for a given public key.
341 * Returns at most one result to the processor.
343 * @param h handle to the namestore
344 * @param zone hash of public key of the zone to look up in, never NULL
345 * @param value_zone hash of the public key of the target zone (value), never NULL
346 * @param proc function to call on the matching records, or with
347 * NULL (rd_count == 0) if there are no matching records
348 * @param proc_cls closure for proc
349 * @return a handle that can be used to
352 struct GNUNET_NAMESTORE_QueueEntry *
353 GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h,
354 const struct GNUNET_CRYPTO_ShortHashCode *zone,
355 const struct GNUNET_CRYPTO_ShortHashCode *value_zone,
356 GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls);
361 * Starts a new zone iteration (used to periodically PUT all of our
362 * records into our DHT). "proc" will be called once
363 * immediately, and then again after
364 * "GNUNET_NAMESTORE_zone_iterator_next" is invoked.
366 * @param h handle to the namestore
367 * @param zone zone to access, NULL for all zones
368 * @param must_have_flags flags that must be set for the record to be returned
369 * @param must_not_have_flags flags that must NOT be set for the record to be returned
370 * @param proc function to call on each name from the zone; it
371 * will be called repeatedly with a value (if available)
372 * and always once at the end with a name of NULL.
373 * @param proc_cls closure for proc
374 * @return an iterator handle to use for iteration
376 struct GNUNET_NAMESTORE_ZoneIterator *
377 GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
378 const struct GNUNET_CRYPTO_ShortHashCode *zone,
379 enum GNUNET_NAMESTORE_RecordFlags must_have_flags,
380 enum GNUNET_NAMESTORE_RecordFlags must_not_have_flags,
381 GNUNET_NAMESTORE_RecordProcessor proc,
386 * Calls the record processor specified in GNUNET_NAMESTORE_zone_iteration_start
387 * for the next record.
389 * @param it the iterator
392 GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it);
396 * Stops iteration and releases the namestore handle for further calls.
398 * @param it the iterator
401 GNUNET_NAMESTORE_zone_iteration_stop (struct GNUNET_NAMESTORE_ZoneIterator *it);
405 * Cancel a namestore operation. The final callback from the
406 * operation must not have been done yet.
408 * @param qe operation to cancel
411 GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe);
415 /* convenience APIs for serializing / deserializing GNS records */
418 * Calculate how many bytes we will need to serialize the given
421 * @param rd_count number of records in the rd array
422 * @param rd array of GNUNET_NAMESTORE_RecordData with rd_count elements
424 * @return the required size to serialize
428 GNUNET_NAMESTORE_records_get_size (unsigned int rd_count,
429 const struct GNUNET_NAMESTORE_RecordData *rd);
432 * Serialize the given records to the given destination buffer.
434 * @param rd_count number of records in the rd array
435 * @param rd array of GNUNET_NAMESTORE_RecordData with rd_count elements
436 * @param dest_size size of the destination array
437 * @param dest where to write the result
439 * @return the size of serialized records
442 GNUNET_NAMESTORE_records_serialize (unsigned int rd_count,
443 const struct GNUNET_NAMESTORE_RecordData *rd,
449 * Deserialize the given records to the given destination.
451 * @param len size of the serialized record data
452 * @param src the serialized record data
453 * @param rd_count number of records in the rd array
454 * @param dest where to put the data
456 * @return GNUNET_OK on success, GNUNET_SYSERR on error
459 GNUNET_NAMESTORE_records_deserialize (size_t len,
461 unsigned int rd_count,
462 struct GNUNET_NAMESTORE_RecordData *dest);
466 * Checks if a name is wellformed
468 * @param name the name to check
469 * @return GNUNET_OK on success, GNUNET_SYSERR on error
472 GNUNET_NAMESTORE_check_name (const char * name);
475 * Convert the 'value' of a record to a string.
477 * @param type type of the record
478 * @param data value in binary encoding
479 * @param data_size number of bytes in data
480 * @return NULL on error, otherwise human-readable representation of the value
483 GNUNET_NAMESTORE_value_to_string (uint32_t type,
489 * Convert human-readable version of a 'value' of a record to the binary
492 * @param type type of the record
493 * @param s human-readable string
494 * @param data set to value in binary encoding (will be allocated)
495 * @param data_size set to number of bytes in data
496 * @return GNUNET_OK on success
499 GNUNET_NAMESTORE_string_to_value (uint32_t type,
506 * Convert a type name (i.e. "AAAA") to the corresponding number.
508 * @param typename name to convert
509 * @return corresponding number, UINT32_MAX on error
512 GNUNET_NAMESTORE_typename_to_number (const char *typename);
516 * Convert a type number (i.e. 1) to the corresponding type string (i.e. "A")
518 * @param type number of a type to convert
519 * @return corresponding typestring, NULL on error
522 GNUNET_NAMESTORE_number_to_typename (uint32_t type);
525 #if 0 /* keep Emacsens' auto-indent happy */
532 /* end of gnunet_namestore_service.h */