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 for GNS zone transfer ("PKEY").
49 #define GNUNET_NAMESTORE_TYPE_PKEY 65536
52 * Record type for GNS zone transfer ("PSEU").
54 #define GNUNET_NAMESTORE_TYPE_PSEU 65537
59 struct GNUNET_NAMESTORE_QueueEntry;
62 * Handle to the namestore service.
64 struct GNUNET_NAMESTORE_Handle;
67 * Handle to the namestore zone iterator.
69 struct GNUNET_NAMESTORE_ZoneIterator;
72 * Maximum size of a value that can be stored in the namestore.
74 #define GNUNET_NAMESTORE_MAX_VALUE_SIZE (63 * 1024)
78 * Convert a type name (i.e. "AAAA") to the corresponding number.
80 * @param typename name to convert
81 * @return corresponding number, UINT32_MAX on error
84 GNUNET_NAMESTORE_typename_to_number (const char *typename);
88 * Connect to the namestore service.
90 * @param cfg configuration to use
91 * @return handle to use to access the service
93 struct GNUNET_NAMESTORE_Handle *
94 GNUNET_NAMESTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
98 * Disconnect from the namestore service (and free associated
101 * @param h handle to the namestore
102 * @param drop set to GNUNET_YES to delete all data in namestore (!)
105 GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h, int drop);
109 * Continuation called to notify client about result of the
113 * @param success GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate)
114 * GNUNET_NO if content was already there or not found
115 * GNUNET_YES (or other positive value) on success
116 * @param emsg NULL on success, otherwise an error message
118 typedef void (*GNUNET_NAMESTORE_ContinuationWithStatus) (void *cls,
124 * Flags that can be set for a record.
126 enum GNUNET_NAMESTORE_RecordFlags
130 * No special options.
132 GNUNET_NAMESTORE_RF_NONE = 0,
135 * This peer is the authority for this record; it must thus
136 * not be deleted (other records can be deleted if we run
139 GNUNET_NAMESTORE_RF_AUTHORITY = 1,
142 * This is a private record of this peer and it should
143 * thus not be handed out to other peers.
145 GNUNET_NAMESTORE_RF_PRIVATE = 2
153 struct GNUNET_NAMESTORE_RecordData
157 * Binary value stored in the DNS record.
162 * Expiration time for the DNS record.
164 struct GNUNET_TIME_Absolute expiration;
167 * Number of bytes in 'data'.
172 * Type of the GNS/DNS record.
174 uint32_t record_type;
177 * Flags for the record.
179 enum GNUNET_NAMESTORE_RecordFlags flags;
184 * Store an item in the namestore. If the item is already present,
185 * the expiration time is updated to the max of the existing time and
186 * the new time. This API is used when we cache signatures from other
189 * @param h handle to the namestore
190 * @param zone_key public key of the zone
191 * @param name name that is being mapped (at most 255 characters long)
192 * @param expire when does the corresponding block in the DHT expire (until
193 * when should we never do a DHT lookup for the same name again)?
194 * @param rd_count number of entries in 'rd' array
195 * @param rd array of records with data to store
196 * @param signature signature for all the records in the zone under the given name
197 * @param cont continuation to call when done
198 * @param cont_cls closure for cont
199 * @return handle to abort the request
201 struct GNUNET_NAMESTORE_QueueEntry *
202 GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h,
203 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
205 struct GNUNET_TIME_Absolute expire,
206 unsigned int rd_count,
207 const struct GNUNET_NAMESTORE_RecordData *rd,
208 const struct GNUNET_CRYPTO_RsaSignature *signature,
209 GNUNET_NAMESTORE_ContinuationWithStatus cont,
214 * Check if a signature is valid. This API is used by the GNS Block
215 * to validate signatures received from the network.
217 * @param public_key public key of the zone
218 * @param name name that is being mapped (at most 255 characters long)
219 * @param rd_count number of entries in 'rd' array
220 * @param rd array of records with data to store
221 * @param signature signature for all the records in the zone under the given name
222 * @return GNUNET_OK if the signature is valid
225 GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key,
227 unsigned int rd_count,
228 const struct GNUNET_NAMESTORE_RecordData *rd,
229 const struct GNUNET_CRYPTO_RsaSignature *signature);
233 * Store an item in the namestore. If the item is already present,
234 * the expiration time is updated to the max of the existing time and
235 * the new time. This API is used by the authority of a zone.
237 * @param h handle to the namestore
238 * @param pkey private key of the zone
239 * @param name name that is being mapped (at most 255 characters long)
240 * @param rd record data to store
241 * @param cont continuation to call when done
242 * @param cont_cls closure for cont
243 * @return handle to abort the request
245 struct GNUNET_NAMESTORE_QueueEntry *
246 GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h,
247 const struct GNUNET_CRYPTO_RsaPrivateKey *pkey,
249 const struct GNUNET_NAMESTORE_RecordData *rd,
250 GNUNET_NAMESTORE_ContinuationWithStatus cont,
255 * Explicitly remove some content from the database. The
256 * "cont"inuation will be called with status "GNUNET_OK" if content
257 * was removed, "GNUNET_NO" if no matching entry was found and
258 * "GNUNET_SYSERR" on all other types of errors.
259 * 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
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_remove (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 * Process a record that was stored in the namestore.
282 * @param zone_key public key of the zone
283 * @param expire when does the corresponding block in the DHT expire (until
284 * when should we never do a DHT lookup for the same name again)?;
285 * GNUNET_TIME_UNIT_ZERO_ABS if there are no records of any type in the namestore,
286 * or the expiration time of the block in the namestore (even if there are zero
287 * records matching the desired record type)
288 * @param name name that is being mapped (at most 255 characters long)
289 * @param rd_count number of entries in 'rd' array
290 * @param rd array of records with data to store
291 * @param signature signature of the record block, NULL if signature is unavailable (i.e.
292 * because the user queried for a particular record type only)
294 typedef void (*GNUNET_NAMESTORE_RecordProcessor) (void *cls,
295 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
296 struct GNUNET_TIME_Absolute expire,
299 const struct GNUNET_NAMESTORE_RecordData *rd,
300 const struct GNUNET_CRYPTO_RsaSignature *signature);
304 * Get a result for a particular key from the namestore. The processor
305 * will only be called once.
307 * @param h handle to the namestore
308 * @param zone zone to look up a record from
309 * @param name name to look up
310 * @param record_type desired record type, 0 for all
311 * @param proc function to call on the matching records, or with
312 * NULL (rd_count == 0) if there are no matching records
313 * @param proc_cls closure for proc
314 * @return a handle that can be used to
317 struct GNUNET_NAMESTORE_QueueEntry *
318 GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h,
319 const GNUNET_HashCode *zone,
321 uint32_t record_type,
322 GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls);
326 * Look for an existing PKEY delegation record for a given public key.
327 * Returns at most one result to the processor.
329 * @param h handle to the namestore
330 * @param zone hash of public key of the zone to look up in, never NULL
331 * @param value_zone hash of the public key of the target zone (value), never NULL
332 * @param proc function to call on the matching records, or with
333 * NULL (rd_count == 0) if there are no matching records
334 * @param proc_cls closure for proc
335 * @return a handle that can be used to
338 struct GNUNET_NAMESTORE_QueueEntry *
339 GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h,
340 const GNUNET_HashCode *zone,
341 const GNUNET_HashCode *value_zone,
342 GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls);
347 * Starts a new zone iteration (used to periodically PUT all of our
348 * records into our DHT). This MUST lock the GNUNET_NAMESTORE_Handle
349 * for any other calls than GNUNET_NAMESTORE_zone_iterator_next and
350 * GNUNET_NAMESTORE_zone_iteration_stop. "proc" will be called once
351 * immediately, and then again after
352 * "GNUNET_NAMESTORE_zone_iterator_next" is invoked.
354 * @param h handle to the namestore
355 * @param zone zone to access, NULL for all zones
356 * @param must_have_flags flags that must be set for the record to be returned
357 * @param must_not_have_flags flags that must NOT be set for the record to be returned
358 * @param proc function to call on each name from the zone; it
359 * will be called repeatedly with a value (if available)
360 * and always once at the end with a name of NULL.
361 * @param proc_cls closure for proc
362 * @return an iterator handle to use for iteration
364 struct GNUNET_NAMESTORE_ZoneIterator *
365 GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
366 const GNUNET_HashCode *zone,
367 enum GNUNET_NAMESTORE_RecordFlags must_have_flags,
368 enum GNUNET_NAMESTORE_RecordFlags must_not_have_flags,
369 GNUNET_NAMESTORE_RecordProcessor proc,
374 * Calls the record processor specified in GNUNET_NAMESTORE_zone_iteration_start
375 * for the next record.
377 * @param it the iterator
380 GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it);
384 * Stops iteration and releases the namestore handle for further calls.
386 * @param it the iterator
389 GNUNET_NAMESTORE_zone_iteration_stop (struct GNUNET_NAMESTORE_ZoneIterator *it);
393 * Cancel a namestore operation. The final callback from the
394 * operation must not have been done yet.
396 * @param qe operation to cancel
399 GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe);
403 /* convenience APIs for serializing / deserializing GNS records */
406 * Calculate how many bytes we will need to serialize the given
409 * @param rd_count number of records in the rd array
410 * @param rd array of GNUNET_NAMESTORE_RecordData with rd_count elements
412 * @return the required size to serialize
416 GNUNET_NAMESTORE_records_get_size (unsigned int rd_count,
417 const struct GNUNET_NAMESTORE_RecordData *rd);
420 * Serialize the given records to the given destination buffer.
422 * @param rd_count number of records in the rd array
423 * @param rd array of GNUNET_NAMESTORE_RecordData with rd_count elements
424 * @param dest_size size of the destination array
425 * @param dest where to write the result
427 * @return the size of serialized records
430 GNUNET_NAMESTORE_records_serialize (unsigned int rd_count,
431 const struct GNUNET_NAMESTORE_RecordData *rd,
437 * Deserialize the given records to the given destination.
439 * @param len size of the serialized record data
440 * @param src the serialized record data
441 * @param rd_count number of records in the rd array
442 * @param dest where to put the data
444 * @return GNUNET_OK on success, GNUNET_SYSERR on error
447 GNUNET_NAMESTORE_records_deserialize (size_t len,
449 unsigned int rd_count,
450 struct GNUNET_NAMESTORE_RecordData *dest);
453 #if 0 /* keep Emacsens' auto-indent happy */
460 /* end of gnunet_namestore_service.h */