aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_namestore_service.h
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-08-12 19:09:52 +0000
committerChristian Grothoff <christian@grothoff.org>2013-08-12 19:09:52 +0000
commit5e05019536c0d38bf20f965613636f21ae7c2be6 (patch)
treeeda1dee12e49c010171462d618162d28b21c9c6a /src/include/gnunet_namestore_service.h
parent566dfe32be22ed1f071b974be3c4dd8bc5721151 (diff)
downloadgnunet-5e05019536c0d38bf20f965613636f21ae7c2be6.tar.gz
gnunet-5e05019536c0d38bf20f965613636f21ae7c2be6.zip
-towards namestore support for the new privacy-preserving GNS queries
Diffstat (limited to 'src/include/gnunet_namestore_service.h')
-rw-r--r--src/include/gnunet_namestore_service.h313
1 files changed, 151 insertions, 162 deletions
diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h
index 77da67312..db7453063 100644
--- a/src/include/gnunet_namestore_service.h
+++ b/src/include/gnunet_namestore_service.h
@@ -21,12 +21,11 @@
21/** 21/**
22 * @file include/gnunet_namestore_service.h 22 * @file include/gnunet_namestore_service.h
23 * @brief API that can be used to store naming information on a GNUnet node; 23 * @brief API that can be used to store naming information on a GNUnet node;
24 * Naming information can either be records for which this peer/user
25 * is authoritative, or blocks which are cached, encrypted naming
26 * data from other peers.
24 * @author Christian Grothoff 27 * @author Christian Grothoff
25 *
26 * Other functions we might want:
27 * - enumerate all known zones
28 */ 28 */
29
30#ifndef GNUNET_NAMESTORE_SERVICE_H 29#ifndef GNUNET_NAMESTORE_SERVICE_H
31#define GNUNET_NAMESTORE_SERVICE_H 30#define GNUNET_NAMESTORE_SERVICE_H
32 31
@@ -97,7 +96,6 @@ struct GNUNET_NAMESTORE_ZoneIterator;
97#define GNUNET_NAMESTORE_MAX_VALUE_SIZE (63 * 1024) 96#define GNUNET_NAMESTORE_MAX_VALUE_SIZE (63 * 1024)
98 97
99 98
100
101/** 99/**
102 * Connect to the namestore service. 100 * Connect to the namestore service.
103 * 101 *
@@ -229,53 +227,51 @@ struct GNUNET_NAMESTORE_RecordData
229 227
230 228
231/** 229/**
230 * Information we have in an encrypted block with record data (i.e. in the DHT).
231 */
232struct GNUNET_NAMESTORE_Block
233{
234
235 /**
236 * Signature of the block.
237 */
238 struct GNUNET_CRYPTO_EccSignature signature;
239
240 /**
241 * Derived key used for signing; hash of this is the query.
242 */
243 struct GNUNET_CRYPTO_EccPublicKey derived_key;
244
245 /**
246 * Number of bytes signed; also specifies the number of bytes
247 * of encrypted data that follow.
248 */
249 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
250
251 /**
252 * Expiration time of the block.
253 */
254 struct GNUNET_TIME_AbsoluteNBO expiration_time;
255
256 /* followed by encrypted data */
257};
258
259
260/**
232 * Store an item in the namestore. If the item is already present, 261 * Store an item in the namestore. If the item is already present,
233 * it is replaced with the new record. Use an empty array to 262 * it is replaced with the new record.
234 * remove all records under the given name.
235 * 263 *
236 * @param h handle to the namestore 264 * @param h handle to the namestore
237 * @param zone_key public key of the zone 265 * @param block block to store
238 * @param name name that is being mapped (at most 255 characters long)
239 * @param freshness when does the corresponding block in the DHT expire (until
240 * when should we never do a DHT lookup for the same name again)?
241 * @param rd_count number of entries in 'rd' array
242 * @param rd array of records with data to store
243 * @param signature signature for all the records in the zone under the given name
244 * @param cont continuation to call when done 266 * @param cont continuation to call when done
245 * @param cont_cls closure for cont 267 * @param cont_cls closure for cont
246 * @return handle to abort the request 268 * @return handle to abort the request
247 */ 269 */
248struct GNUNET_NAMESTORE_QueueEntry * 270struct GNUNET_NAMESTORE_QueueEntry *
249GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h, 271GNUNET_NAMESTORE_block_cache (struct GNUNET_NAMESTORE_Handle *h,
250 const struct GNUNET_CRYPTO_EccPublicKey *zone_key, 272 const struct GNUNET_NAMESTORE_Block *block,
251 const char *name, 273 GNUNET_NAMESTORE_ContinuationWithStatus cont,
252 struct GNUNET_TIME_Absolute freshness, 274 void *cont_cls);
253 unsigned int rd_count,
254 const struct GNUNET_NAMESTORE_RecordData *rd,
255 const struct GNUNET_CRYPTO_EccSignature *signature,
256 GNUNET_NAMESTORE_ContinuationWithStatus cont,
257 void *cont_cls);
258
259
260/**
261 * Check if a signature is valid. This API is used by the GNS Block
262 * to validate signatures received from the network.
263 *
264 * @param public_key public key of the zone
265 * @param freshness time set for block expiration
266 * @param name name that is being mapped (at most 255 characters long)
267 * @param rd_count number of entries in 'rd' array
268 * @param rd array of records with data to store
269 * @param signature signature for all the records in the zone under the given name
270 * @return GNUNET_OK if the signature is valid
271 */
272int
273GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_EccPublicKey *public_key,
274 const struct GNUNET_TIME_Absolute freshness,
275 const char *name,
276 unsigned int rd_count,
277 const struct GNUNET_NAMESTORE_RecordData *rd,
278 const struct GNUNET_CRYPTO_EccSignature *signature);
279 275
280 276
281/** 277/**
@@ -285,7 +281,7 @@ GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_EccPublicKey *publ
285 * 281 *
286 * @param h handle to the namestore 282 * @param h handle to the namestore
287 * @param pkey private key of the zone 283 * @param pkey private key of the zone
288 * @param name name that is being mapped (at most 255 characters long) 284 * @param label name that is being mapped (at most 255 characters long)
289 * @param rd_count number of records in the 'rd' array 285 * @param rd_count number of records in the 'rd' array
290 * @param rd array of records with data to store 286 * @param rd array of records with data to store
291 * @param cont continuation to call when done 287 * @param cont continuation to call when done
@@ -293,67 +289,56 @@ GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_EccPublicKey *publ
293 * @return handle to abort the request 289 * @return handle to abort the request
294 */ 290 */
295struct GNUNET_NAMESTORE_QueueEntry * 291struct GNUNET_NAMESTORE_QueueEntry *
296GNUNET_NAMESTORE_record_put_by_authority (struct GNUNET_NAMESTORE_Handle *h, 292GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h,
297 const struct GNUNET_CRYPTO_EccPrivateKey *pkey, 293 const struct GNUNET_CRYPTO_EccPrivateKey *pkey,
298 const char *name, 294 const char *label,
299 unsigned int rd_count, 295 unsigned int rd_count,
300 const struct GNUNET_NAMESTORE_RecordData *rd, 296 const struct GNUNET_NAMESTORE_RecordData *rd,
301 GNUNET_NAMESTORE_ContinuationWithStatus cont, 297 GNUNET_NAMESTORE_ContinuationWithStatus cont,
302 void *cont_cls); 298 void *cont_cls);
303 299
304 300
305/** 301/**
306 * Process a record that was stored in the namestore. 302 * Process a record that was stored in the namestore.
307 * 303 *
308 * @param cls closure 304 * @param cls closure
309 * @param zone_key public key of the zone 305 * @param block block that was stored in the namestore
310 * @param freshness when does the corresponding block in the DHT expire (until
311 * when should we never do a DHT lookup for the same name again)?;
312 * GNUNET_TIME_UNIT_ZERO_ABS if there are no records of any type in the namestore,
313 * or the expiration time of the block in the namestore (even if there are zero
314 * records matching the desired record type)
315 * @param name name that is being mapped (at most 255 characters long)
316 * @param rd_count number of entries in 'rd' array
317 * @param rd array of records with data to store
318 * @param signature signature of the record block, NULL if signature is unavailable (i.e.
319 * because the user queried for a particular record type only)
320 */ 306 */
321typedef void (*GNUNET_NAMESTORE_RecordProcessor) (void *cls, 307typedef void (*GNUNET_NAMESTORE_BlockProcessor) (void *cls,
322 const struct GNUNET_CRYPTO_EccPublicKey *zone_key, 308 const struct GNUNET_NAMESTORE_Block *block);
323 struct GNUNET_TIME_Absolute freshness,
324 const char *name,
325 unsigned int rd_count,
326 const struct GNUNET_NAMESTORE_RecordData *rd,
327 const struct GNUNET_CRYPTO_EccSignature *signature);
328 309
329 310
330/** 311/**
331 * Get a result for a particular key from the namestore. The processor 312 * Get a result for a particular key from the namestore. The processor
332 * will only be called once. When using this functions, relative expiration 313 * will only be called once.
333 * times will be converted to absolute expiration times and a signature
334 * will be created if we are the authority. The record data and signature
335 * passed to 'proc' is thus always suitable for passing on to other peers
336 * (if we are the authority). If the record type is NOT set to 'ANY' and
337 * if we are NOT the authority, then non-matching records may be omitted
338 * from the result and no valid signature can be created; in this case,
339 * 'signature' will be NULL and the result cannot be given to other peers.
340 * 314 *
341 * @param h handle to the namestore 315 * @param h handle to the namestore
342 * @param zone zone to look up a record from 316 * @param derived_hash hash of zone key combined with name to lookup
343 * @param name name to look up 317 * @param proc function to call on the matching block, or with
344 * @param record_type desired record type, 0 for all 318 * NULL if there is no matching block
345 * @param proc function to call on the matching records, or with
346 * NULL (rd_count == 0) if there are no matching records
347 * @param proc_cls closure for proc 319 * @param proc_cls closure for proc
348 * @return a handle that can be used to 320 * @return a handle that can be used to cancel
349 * cancel
350 */ 321 */
351struct GNUNET_NAMESTORE_QueueEntry * 322struct GNUNET_NAMESTORE_QueueEntry *
352GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h, 323GNUNET_NAMESTORE_lookup_block (struct GNUNET_NAMESTORE_Handle *h,
353 const struct GNUNET_CRYPTO_ShortHashCode *zone, 324 const struct GNUNET_HashCode *derived_hash,
354 const char *name, 325 GNUNET_NAMESTORE_BlockProcessor proc, void *proc_cls);
355 uint32_t record_type, 326
356 GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls); 327
328/**
329 * Process a record that was stored in the namestore.
330 *
331 * @param cls closure
332 * @param zone private key of the zone
333 * @param label label of the records
334 * @param rd_count number of entries in 'rd' array
335 * @param rd array of records with data to store
336 */
337typedef void (*GNUNET_NAMESTORE_RecordMonitor) (void *cls,
338 const struct GNUNET_CRYPTO_EccPrivateKey *zone,
339 const char *label,
340 unsigned int rd_count,
341 const struct GNUNET_NAMESTORE_RecordData *rd);
357 342
358 343
359/** 344/**
@@ -361,8 +346,8 @@ GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h,
361 * Returns at most one result to the processor. 346 * Returns at most one result to the processor.
362 * 347 *
363 * @param h handle to the namestore 348 * @param h handle to the namestore
364 * @param zone hash of public key of the zone to look up in, never NULL 349 * @param zone public key of the zone to look up in, never NULL
365 * @param value_zone hash of the public key of the target zone (value), never NULL 350 * @param value_zone public key of the target zone (value), never NULL
366 * @param proc function to call on the matching records, or with 351 * @param proc function to call on the matching records, or with
367 * NULL (rd_count == 0) if there are no matching records 352 * NULL (rd_count == 0) if there are no matching records
368 * @param proc_cls closure for proc 353 * @param proc_cls closure for proc
@@ -371,9 +356,9 @@ GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h,
371 */ 356 */
372struct GNUNET_NAMESTORE_QueueEntry * 357struct GNUNET_NAMESTORE_QueueEntry *
373GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h, 358GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h,
374 const struct GNUNET_CRYPTO_ShortHashCode *zone, 359 const struct GNUNET_CRYPTO_EccPrivateKey *zone,
375 const struct GNUNET_CRYPTO_ShortHashCode *value_zone, 360 const struct GNUNET_CRYPTO_EccPublicKey *value_zone,
376 GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls); 361 GNUNET_NAMESTORE_RecordMonitor proc, void *proc_cls);
377 362
378 363
379/** 364/**
@@ -393,28 +378,8 @@ GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe);
393 * records into our DHT). "proc" will be called once immediately, and 378 * records into our DHT). "proc" will be called once immediately, and
394 * then again after "GNUNET_NAMESTORE_zone_iterator_next" is invoked. 379 * then again after "GNUNET_NAMESTORE_zone_iterator_next" is invoked.
395 * 380 *
396 * By specifying a 'zone' of NULL and setting 'GNUNET_NAMESTORE_RF_AUTHORITY'
397 * in 'must_have_flags', we can iterate over all records for which we are
398 * the authority (the 'authority' flag will NOT be set in the returned
399 * records anyway).
400 *
401 * The 'GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION'
402 * bit in 'must_have_flags' has a special meaning:
403 *
404 * 0) If the bit is clear, all relative expriation times are converted to
405 * absolute expiration times. This is useful for performing DHT PUT
406 * operations (and zone transfers) of our zone. The generated signatures
407 * will be valid for other peers.
408 * 1) if it is set, it means that relative expiration times should be
409 * preserved when returned (this is useful for the zone editor user
410 * interface). No signatures will be created in this case, as
411 * signatures must not cover records with relative expiration times.
412 *
413 * Note that not all queries against this interface are equally performant
414 * as for some combinations no efficient index may exist.
415 *
416 * @param h handle to the namestore 381 * @param h handle to the namestore
417 * @param zone zone to access, NULL for all zones 382 * @param zone zone to access
418 * @param must_have_flags flags that must be set for the record to be returned 383 * @param must_have_flags flags that must be set for the record to be returned
419 * @param must_not_have_flags flags that must NOT be set for the record to be returned 384 * @param must_not_have_flags flags that must NOT be set for the record to be returned
420 * @param proc function to call on each name from the zone; it 385 * @param proc function to call on each name from the zone; it
@@ -425,10 +390,8 @@ GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe);
425 */ 390 */
426struct GNUNET_NAMESTORE_ZoneIterator * 391struct GNUNET_NAMESTORE_ZoneIterator *
427GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h, 392GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
428 const struct GNUNET_CRYPTO_ShortHashCode *zone, 393 const struct GNUNET_CRYPTO_EccPrivateKey *zone,
429 enum GNUNET_NAMESTORE_RecordFlags must_have_flags, 394 GNUNET_NAMESTORE_RecordMonitor proc,
430 enum GNUNET_NAMESTORE_RecordFlags must_not_have_flags,
431 GNUNET_NAMESTORE_RecordProcessor proc,
432 void *proc_cls); 395 void *proc_cls);
433 396
434 397
@@ -460,35 +423,6 @@ struct GNUNET_NAMESTORE_ZoneMonitor;
460 423
461 424
462/** 425/**
463 * Function called whenever the records for a given name changed.
464 *
465 * @param cls closure
466 * @param zone_key NULL if the communication with the namestore broke down
467 * (and thus all entries should be 'cleared' until the communication
468 * can be re-established, at which point the monitor will
469 * re-add all records that are (still) in the namestore after
470 * the reconnect); if this value is NULL, all other arguments
471 * will also be 0/NULL.
472 * @param freshness when does the corresponding block in the DHT expire (until
473 * when should we never do a DHT lookup for the same name again)?;
474 * GNUNET_TIME_UNIT_ZERO_ABS if there are no records of any type in the namestore,
475 * or the expiration time of the block in the namestore (even if there are zero
476 * records matching the desired record type)
477 * @param name name that is being mapped (at most 255 characters long)
478 * @param rd_count number of entries in 'rd' array
479 * @param rd array of records with data to store
480 * @param signature signature of the record block
481 */
482typedef void (*GNUNET_NAMESTORE_RecordMonitor)(void *cls,
483 const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
484 struct GNUNET_TIME_Absolute freshness,
485 const char *name,
486 unsigned int rd_len,
487 const struct GNUNET_NAMESTORE_RecordData *rd,
488 const struct GNUNET_CRYPTO_EccSignature *signature);
489
490
491/**
492 * Function called once the monitor has caught up with the current 426 * Function called once the monitor has caught up with the current
493 * state of the database. Will be called AGAIN after each disconnect 427 * state of the database. Will be called AGAIN after each disconnect
494 * (record monitor called with 'NULL' for zone_key) once we're again 428 * (record monitor called with 'NULL' for zone_key) once we're again
@@ -513,7 +447,7 @@ typedef void (*GNUNET_NAMESTORE_RecordsSynchronizedCallback)(void *cls);
513 * monitoring). 447 * monitoring).
514 * 448 *
515 * @param cfg configuration to use to connect to namestore 449 * @param cfg configuration to use to connect to namestore
516 * @param zone zone to monitor, NULL for all zones 450 * @param zone zone to monitor
517 * @param monitor function to call on zone changes 451 * @param monitor function to call on zone changes
518 * @param sync_cb function called when we're in sync with the namestore 452 * @param sync_cb function called when we're in sync with the namestore
519 * @param cls closure for 'monitor' and 'sync_cb' 453 * @param cls closure for 'monitor' and 'sync_cb'
@@ -521,7 +455,7 @@ typedef void (*GNUNET_NAMESTORE_RecordsSynchronizedCallback)(void *cls);
521 */ 455 */
522struct GNUNET_NAMESTORE_ZoneMonitor * 456struct GNUNET_NAMESTORE_ZoneMonitor *
523GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, 457GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
524 const struct GNUNET_CRYPTO_ShortHashCode *zone, 458 const struct GNUNET_CRYPTO_EccPrivateKey *zone,
525 GNUNET_NAMESTORE_RecordMonitor monitor, 459 GNUNET_NAMESTORE_RecordMonitor monitor,
526 GNUNET_NAMESTORE_RecordsSynchronizedCallback sync_cb, 460 GNUNET_NAMESTORE_RecordsSynchronizedCallback sync_cb,
527 void *cls); 461 void *cls);
@@ -659,15 +593,41 @@ GNUNET_NAMESTORE_normalize_string (const char *src);
659 593
660 594
661/** 595/**
662 * Convert a short hash to a string (for printing debug messages). 596 * Convert a zone to a string (for printing debug messages).
663 * This is one of the very few calls in the entire API that is 597 * This is one of the very few calls in the entire API that is
664 * NOT reentrant! 598 * NOT reentrant!
665 * 599 *
666 * @param hc the short hash code 600 * @param z public key of a zone
667 * @return string form; will be overwritten by next call to GNUNET_h2s. 601 * @return string form; will be overwritten by next call to GNUNET_h2s.
668 */ 602 */
669const char * 603const char *
670GNUNET_NAMESTORE_short_h2s (const struct GNUNET_CRYPTO_ShortHashCode * hc); 604GNUNET_NAMESTORE_z2s (const struct GNUNET_CRYPTO_EccPublicKey *z);
605
606
607/**
608 * Calculate the DHT query for a given 'label' in a given zone.
609 *
610 * @param zone private key of the zone
611 * @param label label of the record
612 * @return query hash to use for the query
613 */
614void
615GNUNET_NAMESTORE_query_from_private_key (const struct GNUNET_CRYPTO_EccPrivateKey *zone,
616 const char *label,
617 struct GNUNET_HashCode *query);
618
619
620/**
621 * Calculate the DHT query for a given 'label' in a given zone.
622 *
623 * @param pub public key of the zone
624 * @param label label of the record
625 * @return query hash to use for the query
626 */
627void
628GNUNET_NAMESTORE_query_from_public_key (const struct GNUNET_CRYPTO_EccPublicKey *pub,
629 const char *label,
630 struct GNUNET_HashCode *query);
671 631
672 632
673/** 633/**
@@ -675,18 +635,47 @@ GNUNET_NAMESTORE_short_h2s (const struct GNUNET_CRYPTO_ShortHashCode * hc);
675 * 635 *
676 * @param key the private key 636 * @param key the private key
677 * @param expire block expiration 637 * @param expire block expiration
678 * @param name the name 638 * @param label the name for the records
679 * @param rd record data 639 * @param rd record data
680 * @param rd_count number of records 640 * @param rd_count number of records
641 * @param signature where to store the signature
642 */
643struct GNUNET_NAMESTORE_Block *
644GNUNET_NAMESTORE_block_create (const struct GNUNET_CRYPTO_EccPrivateKey *key,
645 struct GNUNET_TIME_Absolute expire,
646 const char *label,
647 const struct GNUNET_NAMESTORE_RecordData *rd,
648 unsigned int rd_count);
649
650
651/**
652 * Check if a signature is valid. This API is used by the GNS Block
653 * to validate signatures received from the network.
681 * 654 *
682 * @return the signature 655 * @param block block to verify
656 * @return GNUNET_OK if the signature is valid
683 */ 657 */
684struct GNUNET_CRYPTO_EccSignature * 658int
685GNUNET_NAMESTORE_create_signature (const struct GNUNET_CRYPTO_EccPrivateKey *key, 659GNUNET_NAMESTORE_block_verify (const struct GNUNET_NAMESTORE_Block *block);
686 struct GNUNET_TIME_Absolute expire, 660
687 const char *name, 661
688 const struct GNUNET_NAMESTORE_RecordData *rd, 662/**
689 unsigned int rd_count); 663 * Decrypt block.
664 *
665 * @param block block to decrypt
666 * @param zone_key public key of the zone
667 * @param label the name for the records
668 * @param proc function to call with the result
669 * @param proc_cls closure for proc
670 * @param GNUNET_OK on success, GNUNET_SYSERR if the block was
671 * not well-formed
672 */
673int
674GNUNET_NAMESTORE_block_decrypt (const struct GNUNET_NAMESTORE_Block *block,
675 const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
676 const char *label,
677 GNUNET_NAMESTORE_RecordMonitor proc,
678 void *proc_cls);
690 679
691 680
692/** 681/**