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 */
49 struct GNUNET_NAMESTORE_QueueEntry;
52 * Handle to the namestore service.
54 struct GNUNET_NAMESTORE_Handle;
57 * Maximum size of a value that can be stored in the namestore.
59 #define GNUNET_NAMESTORE_MAX_VALUE_SIZE (63 * 1024)
62 * Connect to the namestore service.
64 * @param cfg configuration to use
65 * @return handle to use to access the service
67 struct GNUNET_NAMESTORE_Handle *
68 GNUNET_NAMESTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
72 * Disconnect from the namestore service (and free
73 * associated resources).
75 * @param h handle to the namestore
76 * @param drop set to GNUNET_YES to delete all data in namestore (!)
79 GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h, int drop);
83 * Continuation called to notify client about result of the
87 * @param success GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate)
88 * GNUNET_NO if content was already there
89 * GNUNET_YES (or other positive value) on success
90 * @param emsg NULL on success, otherwise an error message
92 typedef void (*GNUNET_NAMESTORE_ContinuationWithStatus) (void *cls,
98 * Flags that can be set for a record.
100 enum GNUNET_NAMESTORE_RecordFlags
104 * No special options.
106 GNUNET_NAMESTORE_RF_NONE = 0,
109 * This peer is the authority for this record; it must thus
110 * not be deleted (other records can be deleted if we run
113 GNUNET_NAMESTORE_RF_AUTHORITY = 1,
116 * This is a private record of this peer and it should
117 * thus not be handed out to other peers.
119 GNUNET_NAMESTORE_RF_PRIVATE = 2
125 * We formally store records in a B-tree for signing. This struct
126 * identifies the location of a record in the B-tree.
128 struct GNUNET_NAMESTORE_SignatureLocation
131 * Offset in the B-tree.
136 * Depth in the B-tree.
141 * Revision of the B-tree.
148 * Continuation called to notify client about result of the
152 * @param sig where the signature is now located in the S-tree
154 typedef void (*GNUNET_NAMESTORE_ContinuationWithSignature) (void *cls,
155 const struct GNUNET_NAMESTORE_SignatureLocation *sig);
162 * Get the hash of a record (what will be signed in the Stree for
165 * @param zone hash of the public key of the zone
166 * @param name name that is being mapped (at most 255 characters long)
167 * @param record_type type of the record (A, AAAA, PKEY, etc.)
168 * @param expiration expiration time for the content
169 * @param flags flags for the content
170 * @param data_size number of bytes in data
171 * @param data value, semantics depend on 'record_type' (see RFCs for DNS and
172 * GNS specification for GNS extensions)
173 * @param record_hash hash of the record (set)
176 GNUNET_NAMESTORE_record_hash (struct GNUNET_NAMESTORE_Handle *h,
177 const GNUNET_HashCode *zone,
179 uint32_t record_type,
180 struct GNUNET_TIME_Absolute expiration,
181 enum GNUNET_NAMESTORE_RecordFlags flags,
184 GNUNET_HashCode *record_hash);
188 * Sign a record. This function is used by the authority of the zone
191 * @param h handle to the namestore
192 * @param zone_privkey private key of the zone
193 * @param record_hash hash of the record to be signed
194 * @param cont continuation to call when done
195 * @param cont_cls closure for cont
196 * @return handle to abort the request
198 struct GNUNET_NAMESTORE_QueueEntry *
199 GNUNET_NAMESTORE_stree_extend (struct GNUNET_NAMESTORE_Handle *h,
200 const struct GNUNET_CRYPTO_RsaPrivateKey *zone_privkey,
201 const GNUNET_HashCode *record_hash,
202 GNUNET_NAMESTORE_ContinuationWithSignature cont,
207 * Rebalance the signature tree of our zone. This function should
208 * be called "rarely" to rebalance the tree.
210 * @param h handle to the namestore
211 * @param zone_privkey private key for the zone to rebalance
212 * @param cont continuation to call when done
213 * @param cont_cls closure for cont
214 * @return handle to abort the request
216 struct GNUNET_NAMESTORE_QueueEntry *
217 GNUNET_NAMESTORE_stree_rebalance (struct GNUNET_NAMESTORE_Handle *h,
218 const struct GNUNET_CRYPTO_RsaPrivateKey *zone_privkey,
219 GNUNET_NAMESTORE_ContinuationWithStatus cont,
224 * Provide the root of a signature tree. This function is
225 * used by non-authorities as the first operation when
226 * adding a foreign zone.
228 * @param h handle to the namestore
229 * @param zone_key public key of the zone
230 * @param signature signature of the top-level entry of the zone
231 * @param revision revision number of the zone
232 * @param top_hash top-level hash of the zone
233 * @param cont continuation to call when done
234 * @param cont_cls closure for cont
235 * @return handle to abort the request
237 struct GNUNET_NAMESTORE_QueueEntry *
238 GNUNET_NAMESTORE_stree_start (struct GNUNET_NAMESTORE_Handle *h,
239 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
240 const struct GNUNET_CRYPTO_RsaSignature *signature,
242 const GNUNET_HashCode *top_hash,
243 GNUNET_NAMESTORE_ContinuationWithSignature cont,
248 * Store part of a signature B-tree in the namestore. This function
249 * is used by non-authorities to cache parts of a zone's signature tree.
250 * Note that the tree must be build top-down. This function must check
251 * that the nodes being added are valid, and if not refuse the operation.
253 * @param h handle to the namestore
254 * @param zone_key public key of the zone
255 * @param loc location in the B-tree
256 * @param ploc parent's location in the B-tree (must have depth = loc.depth - 1)
257 * @param num_entries number of entries at this node in the B-tree
258 * @param entries the 'num_entries' entries to store (hashes over the
260 * @param cont continuation to call when done
261 * @param cont_cls closure for cont
262 * @return handle to abort the request
264 struct GNUNET_NAMESTORE_QueueEntry *
265 GNUNET_NAMESTORE_stree_put (struct GNUNET_NAMESTORE_Handle *h,
266 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
267 const struct GNUNET_NAMESTORE_SignatureLocation *loc,
268 const struct GNUNET_NAMESTORE_SignatureLocation *ploc,
269 unsigned int num_entries,
270 const GNUNET_HashCode *entries,
271 GNUNET_NAMESTORE_ContinuationWithStatus cont,
276 * Store current zone signature in the namestore. This function
277 * is used by non-authorities to cache the top of a zone's signature tree.
278 * Note that the tree must be build top-down, so this function is called
279 * first for a given zone and revision.
281 * @param h handle to the namestore
282 * @param zone_key public key of the zone
283 * @param loc identifies the top of the B-tree (depth and revision)
284 * @param time time of the signature creation
285 * @param top_sig signature at the top
286 * @param root_hash top level hash code in the Merkle-tree / stree
287 * @param cont continuation to call when done
288 * @param cont_cls closure for cont
289 * @return handle to abort the request
291 struct GNUNET_NAMESTORE_QueueEntry *
292 GNUNET_NAMESTORE_signature_put (struct GNUNET_NAMESTORE_Handle *h,
293 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
294 const struct GNUNET_NAMESTORE_SignatureLocation *loc,
295 struct GNUNET_TIME_Absolute time,
296 const struct GNUNET_CRYPTO_RsaSignature *top_sig,
297 const GNUNET_HashCode *root_hash,
298 GNUNET_NAMESTORE_ContinuationWithStatus cont,
303 * Store an item in the namestore. If the item is already present,
304 * the expiration time is updated to the max of the existing time and
305 * the new time. The operation must fail if there is no matching
306 * entry in the signature tree.
308 * @param h handle to the namestore
309 * @param zone hash of the public key of the zone
310 * @param name name that is being mapped (at most 255 characters long)
311 * @param record_type type of the record (A, AAAA, PKEY, etc.)
312 * @param expiration expiration time for the content
313 * @param flags flags for the content
314 * @param sig_loc where is the information about the signature for this record stored?
315 * @param data_size number of bytes in data
316 * @param data value, semantics depend on 'record_type' (see RFCs for DNS and
317 * GNS specification for GNS extensions)
318 * @param cont continuation to call when done
319 * @param cont_cls closure for cont
320 * @return handle to abort the request
322 struct GNUNET_NAMESTORE_QueueEntry *
323 GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h,
324 const GNUNET_HashCode *zone,
326 uint32_t record_type,
327 struct GNUNET_TIME_Absolute expiration,
328 enum GNUNET_NAMESTORE_RecordFlags flags,
329 const struct GNUNET_NAMESTORE_SignatureLocation *sig_loc,
332 GNUNET_NAMESTORE_ContinuationWithStatus cont,
337 * Explicitly remove some content from the database. The
338 * "cont"inuation will be called with status "GNUNET_OK" if content
339 * was removed, "GNUNET_NO" if no matching entry was found and
340 * "GNUNET_SYSERR" on all other types of errors.
342 * @param h handle to the namestore
343 * @param zone hash of the public key of the zone
344 * @param name name that is being mapped (at most 255 characters long)
345 * @param record_type type of the record (A, AAAA, PKEY, etc.)
346 * @param size number of bytes in data
347 * @param data content stored
348 * @param cont continuation to call when done
349 * @param cont_cls closure for cont
350 * @return handle to abort the request
352 struct GNUNET_NAMESTORE_QueueEntry *
353 GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h,
354 const GNUNET_HashCode *zone,
356 uint32_t record_type,
359 GNUNET_NAMESTORE_ContinuationWithStatus cont,
364 * Process a record that was stored in the namestore.
367 * @param zone hash of the public key of the zone
368 * @param name name that is being mapped (at most 255 characters long)
369 * @param record_type type of the record (A, AAAA, PKEY, etc.)
370 * @param expiration expiration time for the content
371 * @param flags flags for the content
372 * @param sig_loc where is the information about the signature for this record stored?
373 * @param size number of bytes in data
374 * @param data content stored
376 typedef void (*GNUNET_NAMESTORE_RecordProcessor) (void *cls,
377 const GNUNET_HashCode *zone,
379 uint32_t record_type,
380 struct GNUNET_TIME_Absolute expiration,
381 enum GNUNET_NAMESTORE_RecordFlags flags,
382 const struct GNUNET_NAMESTORE_SignatureLocation *sig_loc,
383 size_t size, const void *data);
387 * Get a result for a particular key from the namestore. The processor
388 * will only be called once.
390 * @param h handle to the namestore
391 * @param zone zone to look up a record from
392 * @param name name to look up
393 * @param record_type desired record type
394 * @param proc function to call on each matching value;
395 * will be called once with a NULL value at the end
396 * @param proc_cls closure for proc
397 * @return a handle that can be used to
400 struct GNUNET_NAMESTORE_QueueEntry *
401 GNUNET_NAMESTORE_lookup_name (struct GNUNET_NAMESTORE_Handle *h,
402 const GNUNET_HashCode *zone,
404 uint32_t record_type,
405 GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls);
410 * Get the hash of a subtree in the STree (what will be signed in the parent
411 * location). FIXME naming conflict!
413 * @param zone hash of the public key of the zone
414 * @param loc where we are in the signature tree
415 * @param num_entries number of entries being stored here
416 * @param entries the entries themselves
417 * @param st_hash hash of the stree node (set)
420 GNUNET_NAMESTORE_record_hash_dup (struct GNUNET_NAMESTORE_Handle *h,
421 const GNUNET_HashCode *zone,
422 const struct GNUNET_NAMESTORE_SignatureLocation *loc,
423 unsigned int num_entries,
424 const GNUNET_HashCode *entries,
425 GNUNET_HashCode *st_hash);
429 * Process a Stree node that was stored in the namestore.
432 * @param zone hash of the public key of the zone
433 * @param loc where we are in the signature tree
434 * @param ploc location of our parent in the signature tree
435 * @param num_entries number of entries being stored here
436 * @param entries the entries themselves
438 typedef void (*GNUNET_NAMESTORE_StreeProcessor) (void *cls,
439 const GNUNET_HashCode *zone,
440 const struct GNUNET_NAMESTORE_SignatureLocation *loc,
441 const struct GNUNET_NAMESTORE_SignatureLocation *ploc,
442 unsigned int num_entries,
443 const GNUNET_HashCode *entries);
447 * Obtain part of a signature B-tree. The processor
448 * will only be called once.
450 * @param h handle to the namestore
451 * @param zone zone to look up a record from
452 * @param sig_loc location to look up
453 * @param proc function to call on each matching value;
454 * will be called once with a NULL value at the end
455 * @param proc_cls closure for proc
456 * @return a handle that can be used to
459 struct GNUNET_NAMESTORE_QueueEntry *
460 GNUNET_NAMESTORE_lookup_stree (struct GNUNET_NAMESTORE_Handle *h,
461 const GNUNET_HashCode *zone,
462 const struct GNUNET_NAMESTORE_SignatureLocation *sig_loc,
463 GNUNET_NAMESTORE_StreeProcessor proc, void *proc_cls);
466 * Process zone signature information that was stored in the namestore.
469 * @param zone hash of the public key of the zone
470 * @param loc where we are in the signature tree (identifies top)
471 * @param top_sig signature at the root
472 * @param time timestamp of the signature
473 * @param top_hash hash at the top of the tree
475 typedef void (*GNUNET_NAMESTORE_SignatureProcessor) (void *cls,
476 const GNUNET_HashCode *zone,
477 const struct GNUNET_NAMESTORE_SignatureLocation *loc,
478 const struct GNUNET_CRYPTO_RsaSignature *top_sig,
479 struct GNUNET_TIME_Absolute time,
480 const GNUNET_HashCode *top_hash);
484 * Obtain latest/current signature of a zone. The processor
485 * will only be called once.
487 * @param h handle to the namestore
488 * @param zone zone to look up a record from
489 * @param proc function to call on each matching value;
490 * will be called once with a NULL value at the end
491 * @param proc_cls closure for proc
492 * @return a handle that can be used to
495 struct GNUNET_NAMESTORE_QueueEntry *
496 GNUNET_NAMESTORE_lookup_signature (struct GNUNET_NAMESTORE_Handle *h,
497 const GNUNET_HashCode *zone,
498 GNUNET_NAMESTORE_SignatureProcessor proc, void *proc_cls);
502 * Get all records of a zone.
504 * @param h handle to the namestore
505 * @param zone zone to access
506 * @param proc function to call on a random value; it
507 * will be called repeatedly with a value (if available)
508 * and always once at the end with a zone and name of NULL.
509 * @param proc_cls closure for proc
510 * @return a handle that can be used to
513 struct GNUNET_NAMESTORE_QueueEntry *
514 GNUNET_NAMESTORE_zone_transfer (struct GNUNET_NAMESTORE_Handle *h,
515 const GNUNET_HashCode *zone,
516 GNUNET_NAMESTORE_RecordProcessor proc,
523 * Cancel a namestore operation. The final callback from the
524 * operation must not have been done yet.
526 * @param qe operation to cancel
529 GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe);
532 #if 0 /* keep Emacsens' auto-indent happy */
539 /* end of gnunet_namestore_service.h */