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)
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_NAMESPACE_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), NULL for root
257 * @param top_sig signature at the top, NULL if 'loc.depth > 0'
258 * @param num_entries number of entries at this node in the B-tree
259 * @param entries the 'num_entries' entries to store (hashes over the
261 * @param cont continuation to call when done
262 * @param cont_cls closure for cont
263 * @return handle to abort the request
265 struct GNUNET_NAMESTORE_QueueEntry *
266 GNUNET_NAMESTORE_stree_put (struct GNUNET_NAMESTORE_Handle *h,
267 const struct GNUNET_CRYPTO_PublicKey *zone_key,
268 const struct GNUNET_NAMESTORE_SignatureLocation *loc,
269 const struct GNUNET_NAMESTORE_SignatureLocation *ploc,
270 const struct GNUNET_CRYPTO_RsaSignature *sig,
271 unsigned int num_entries,
272 const GNUNET_HashCode *entries,
273 GNUNET_NAMESTORE_ContinuationWithStatus cont,
278 * Store an item in the namestore. If the item is already present,
279 * the expiration time is updated to the max of the existing time and
280 * the new time. The operation must fail if there is no matching
281 * entry in the signature tree.
283 * @param h handle to the namestore
284 * @param zone hash of the public key of the zone
285 * @param name name that is being mapped (at most 255 characters long)
286 * @param record_type type of the record (A, AAAA, PKEY, etc.)
287 * @param expiration expiration time for the content
288 * @param flags flags for the content
289 * @param sig_loc where is the information about the signature for this record stored?
290 * @param data_size number of bytes in data
291 * @param data value, semantics depend on 'record_type' (see RFCs for DNS and
292 * GNS specification for GNS extensions)
293 * @param cont continuation to call when done
294 * @param cont_cls closure for cont
295 * @return handle to abort the request
297 struct GNUNET_NAMESTORE_QueueEntry *
298 GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h,
299 const GNUNET_HashCode *zone,
301 uint32_t record_type,
302 struct GNUNET_TIME_Absolute expiration,
303 enum GNUNET_NAMESTORE_RecordFlags flags,
304 const struct GNUNET_NAMESTORE_SignatureLocation *sig_loc,
307 GNUNET_NAMESTORE_ContinuationWithStatus cont,
312 * Explicitly remove some content from the database. The
313 * "cont"inuation will be called with status "GNUNET_OK" if content
314 * was removed, "GNUNET_NO" if no matching entry was found and
315 * "GNUNET_SYSERR" on all other types of errors.
317 * @param h handle to the namestore
318 * @param zone hash of the public key of the zone
319 * @param name name that is being mapped (at most 255 characters long)
320 * @param record_type type of the record (A, AAAA, PKEY, etc.)
321 * @param size number of bytes in data
322 * @param data content stored
323 * @param cont continuation to call when done
324 * @param cont_cls closure for cont
325 * @return handle to abort the request
327 struct GNUNET_NAMESTORE_QueueEntry *
328 GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h,
329 const GNUNET_HashCode *zone,
331 uint32_t record_type,
334 GNUNET_NAMESTORE_ContinuationWithStatus cont,
339 * Process a record that was stored in the namestore.
342 * @param zone hash of the public key of the zone
343 * @param name name that is being mapped (at most 255 characters long)
344 * @param record_type type of the record (A, AAAA, PKEY, etc.)
345 * @param expiration expiration time for the content
346 * @param flags flags for the content
347 * @param sig_loc where is the information about the signature for this record stored?
348 * @param size number of bytes in data
349 * @param data content stored
351 typedef void (*GNUNET_NAMESTORE_RecordProcessor) (void *cls,
352 const GNUNET_HashCode *zone,
354 uint32_t record_type,
355 struct GNUNET_TIME_Absolute expiration,
356 enum GNUNET_NAMESTORE_RecordFlags flags,
357 const struct GNUNET_NAMESTORE_SignatureLocation *sig_loc,
358 size_t size, const void *data);
362 * Get a result for a particular key from the namestore. The processor
363 * will only be called once.
365 * @param h handle to the namestore
366 * @param zone zone to look up a record from
367 * @param name name to look up
368 * @param record_type desired record type
369 * @param proc function to call on each matching value;
370 * will be called once with a NULL value at the end
371 * @param proc_cls closure for proc
372 * @return a handle that can be used to
375 struct GNUNET_NAMESTORE_QueueEntry *
376 GNUNET_NAMESTORE_lookup_name (struct GNUNET_NAMESTORE_Handle *h,
377 const GNUNET_HashCode *zone,
379 uint32_t record_type,
380 GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls);
385 * Get the hash of a subtree in the STree (what will be signed in the parent
388 * @param zone hash of the public key of the zone
389 * @param loc where we are in the signature tree
390 * @param num_entries number of entries being stored here
391 * @param entries the entries themselves
392 * @param st_hash hash of the stree node (set)
395 GNUNET_NAMESTORE_record_hash (struct GNUNET_NAMESTORE_Handle *h,
396 const GNUNET_HashCode *zone,
397 const struct GNUNET_NAMESTORE_SignatureLocation *loc,
398 unsigned int num_entries,
399 const GNUNET_HashCode *entries,
400 GNUNET_HashCode *st_hash);
404 * Process a Stree node that was stored in the namestore.
407 * @param zone hash of the public key of the zone
408 * @param loc where we are in the signature tree
409 * @param ploc location of our parent in the signature tree (NULL if 'loc.depth == 0')
410 * @param top_sig signature at the root (NULL if 'loc.depth > 0')
411 * @param num_entries number of entries being stored here
412 * @param entries the entries themselves
414 typedef void (*GNUNET_NAMESTORE_StreeProcessor) (void *cls,
415 const GNUNET_HashCode *zone,
416 const struct GNUNET_NAMESTORE_SignatureLocation *loc,
417 const struct GNUNET_NAMESTORE_SignatureLocation *ploc,
418 const struct GNUNET_CRYPTO_RsaSignature *top_sig,
419 unsigned int num_entries,
420 const GNUNET_HashCode *entries);
424 * Obtain part of a signature B-tree. The processor
425 * will only be called once.
427 * @param h handle to the namestore
428 * @param zone zone to look up a record from
429 * @param sig_loc location to look up
430 * @param proc function to call on each matching value;
431 * will be called once with a NULL value at the end
432 * @param proc_cls closure for proc
433 * @return a handle that can be used to
436 struct GNUNET_NAMESTORE_QueueEntry *
437 GNUNET_NAMESTORE_lookup_stree (struct GNUNET_NAMESTORE_Handle *h,
438 const GNUNET_HashCode *zone,
439 const struct GNUNET_NAMESTORE_SignatureLocation *sig_loc,
440 GNUNET_NAMESTORE_StreeProcessor proc, void *proc_cls);
444 * Get all records of a zone.
446 * @param h handle to the namestore
447 * @param zone zone to access
448 * @param proc function to call on a random value; it
449 * will be called repeatedly with a value (if available)
450 * and always once at the end with a zone and name of NULL.
451 * @param proc_cls closure for proc
452 * @return a handle that can be used to
455 struct GNUNET_NAMESTORE_QueueEntry *
456 GNUNET_NAMESTORE_zone_transfer (struct GNUNET_NAMESTORE_Handle *h,
457 const GNUNET_HashCode *zone,
458 GNUNET_NAMESTORE_RecordProcessor proc,
465 * Cancel a namestore operation. The final callback from the
466 * operation must not have been done yet.
468 * @param qe operation to cancel
471 GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe);
474 #if 0 /* keep Emacsens' auto-indent happy */
481 /* end of gnunet_namestore_service.h */