aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_gnsrecord_lib.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/gnunet_gnsrecord_lib.h')
-rw-r--r--src/include/gnunet_gnsrecord_lib.h441
1 files changed, 384 insertions, 57 deletions
diff --git a/src/include/gnunet_gnsrecord_lib.h b/src/include/gnunet_gnsrecord_lib.h
index f00a5d0f8..b4e45727b 100644
--- a/src/include/gnunet_gnsrecord_lib.h
+++ b/src/include/gnunet_gnsrecord_lib.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup GNS
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -34,6 +37,8 @@
34#ifndef GNUNET_GNSRECORD_LIB_H 37#ifndef GNUNET_GNSRECORD_LIB_H
35#define GNUNET_GNSRECORD_LIB_H 38#define GNUNET_GNSRECORD_LIB_H
36 39
40
41#include "gnunet_common.h"
37#include "gnunet_identity_service.h" 42#include "gnunet_identity_service.h"
38 43
39#ifdef __cplusplus 44#ifdef __cplusplus
@@ -44,6 +49,12 @@ extern "C" {
44#endif 49#endif
45 50
46/** 51/**
52 * String we use to indicate an empty label (top-level
53 * entry in the zone). DNS uses "@", so do we.
54 */
55#define GNUNET_GNS_EMPTY_LABEL_AT "@"
56
57/**
47 * Maximum size of a value that can be stored in a GNS block. 58 * Maximum size of a value that can be stored in a GNS block.
48 */ 59 */
49#define GNUNET_GNSRECORD_MAX_BLOCK_SIZE (63 * 1024) 60#define GNUNET_GNSRECORD_MAX_BLOCK_SIZE (63 * 1024)
@@ -60,50 +71,102 @@ extern "C" {
60#include "gnu_name_system_record_types.h" 71#include "gnu_name_system_record_types.h"
61 72
62/** 73/**
74 * When comparing flags for record equality for removal,
75 * which flags should must match (in addition to the type,
76 * name, expiration value and data of the record)? All flags
77 * that are not listed here will be ignored for this purpose.
78 * (for example, we don't expect that users will remember to
79 * pass the '--private' option when removing a record from
80 * the namestore, hence we don't require this particular option
81 * to match upon removal). See also
82 * #GNUNET_GNSRECORD_records_cmp.
83 */
84#define GNUNET_GNSRECORD_RF_RCMP_FLAGS (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)
85
86
87/**
63 * Flags that can be set for a record. 88 * Flags that can be set for a record.
89 * The numbers in the registry correspond to the bit index as specified in
90 * LSD0001 Chapter "Resource Records".
91 * Each enum member represents the 16-bit integer value of the flags field if
92 * only that particular flag was set.
93 * The value can be used to efficiently compare the bitmask setting for the
94 * record flag in C.
95 * WARNING: The values are in host byte order! In order to correctly check
96 * against the flags field a record, the respective fields must
97 * also be converted to HBO (or the enum value to NBO).
64 */ 98 */
65enum GNUNET_GNSRECORD_Flags 99enum GNUNET_GNSRECORD_Flags
66{ 100{
67 /** 101 /**
68 * No special options. 102 * Entry for no flags / cleared flags.
69 */ 103 */
70 GNUNET_GNSRECORD_RF_NONE = 0, 104 GNUNET_GNSRECORD_RF_NONE = 0,
71 105
106
107 /**
108 * This record is critical. If it cannot be processed (for example because the record type is unknown) resolution MUST fail
109 */
110 GNUNET_GNSRECORD_RF_CRITICAL = 1 << (15 - 15),
111
112
72 /** 113 /**
73 * This is a private record of this peer and it should 114 * This record should not be used unless all (other) records in the set with an absolute expiration time have expired.
74 * thus not be handed out to other peers.
75 */ 115 */
76 GNUNET_GNSRECORD_RF_PRIVATE = 2, 116 GNUNET_GNSRECORD_RF_SHADOW = 1 << (15 - 14),
117
77 118
78 /** 119 /**
79 * This is a supplemental record. 120 * This is a supplemental record.
80 */ 121 */
81 GNUNET_GNSRECORD_RF_SUPPLEMENTAL = 4, 122 GNUNET_GNSRECORD_RF_SUPPLEMENTAL = 1 << (15 - 13),
82 123
83 /** 124 /**
84 * This expiration time of the record is a relative 125 * Maintenance records. E.g. TOMBSTONEs
85 * time (not an absolute time).
86 */ 126 */
87 GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION = 8, 127 GNUNET_GNSRECORD_RF_MAINTENANCE = 1 << (15 - 2),
88 128
89 /** 129 /**
90 * This record should not be used unless all (other) records with an absolute 130 * This expiration time of the record is a relative time (not an absolute time). Used in GNUnet implementation.
91 * expiration time have expired.
92 */ 131 */
93 GNUNET_GNSRECORD_RF_SHADOW_RECORD = 16 132 GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION = 1 << (15 - 1),
133
134
135 /**
136 * This is a private record of this peer and it should thus not be published.
137 */
138 GNUNET_GNSRECORD_RF_PRIVATE = 1 << (15 - 0),
139
140};
141
94 142
95/** 143/**
96 * When comparing flags for record equality for removal, 144 * Filter for GNUNET_GNSRECORD_normalize_record_set().
97 * which flags should must match (in addition to the type,
98 * name, expiration value and data of the record)? All flags
99 * that are not listed here will be ignored for this purpose.
100 * (for example, we don't expect that users will remember to
101 * pass the '--private' option when removing a record from
102 * the namestore, hence we don't require this particular option
103 * to match upon removal). See also
104 * #GNUNET_GNSRECORD_records_cmp.
105 */ 145 */
106#define GNUNET_GNSRECORD_RF_RCMP_FLAGS (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION) 146enum GNUNET_GNSRECORD_Filter
147{
148 /**
149 * No filter flags set.
150 * Private and public records are returned,
151 * maintenance records (TOMBSTONE etc) are not.
152 */
153 GNUNET_GNSRECORD_FILTER_NONE = 0,
154
155 /**
156 * Include maintenance records (TOMBSTONE etc).
157 */
158 GNUNET_GNSRECORD_FILTER_INCLUDE_MAINTENANCE = 1,
159
160 /**
161 * Filter private records
162 */
163 GNUNET_GNSRECORD_FILTER_OMIT_PRIVATE = 2,
164
165 /**
166 * Filter public records.
167 * FIXME: Not implemented
168 */
169 // GNUNET_NAMESTORE_FILTER_OMIT_PUBLIC = 4,
107}; 170};
108 171
109 172
@@ -184,12 +247,6 @@ struct GNUNET_GNSRECORD_EcdsaBlock
184 struct GNUNET_CRYPTO_EcdsaSignature signature; 247 struct GNUNET_CRYPTO_EcdsaSignature signature;
185 248
186 /** 249 /**
187 * Number of bytes signed; also specifies the number of bytes
188 * of encrypted data that follow.
189 */
190 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
191
192 /**
193 * Expiration time of the block. 250 * Expiration time of the block.
194 */ 251 */
195 struct GNUNET_TIME_AbsoluteNBO expiration_time; 252 struct GNUNET_TIME_AbsoluteNBO expiration_time;
@@ -214,22 +271,25 @@ struct GNUNET_GNSRECORD_EddsaBlock
214 struct GNUNET_CRYPTO_EddsaSignature signature; 271 struct GNUNET_CRYPTO_EddsaSignature signature;
215 272
216 /** 273 /**
217 * Number of bytes signed; also specifies the number of bytes
218 * of encrypted data that follow.
219 */
220 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
221
222 /**
223 * Expiration time of the block. 274 * Expiration time of the block.
224 */ 275 */
225 struct GNUNET_TIME_AbsoluteNBO expiration_time; 276 struct GNUNET_TIME_AbsoluteNBO expiration_time;
226 277
278
227 /* followed by encrypted data */ 279 /* followed by encrypted data */
228}; 280};
229 281
230 282
231struct GNUNET_GNSRECORD_Block 283struct GNUNET_GNSRECORD_Block
232{ 284{
285 /**
286 * Size of the block.
287 */
288 uint32_t size;
289
290 /**
291 * The zone type (GNUNET_GNSRECORD_TYPE_PKEY)
292 */
233 uint32_t type; 293 uint32_t type;
234 294
235 union 295 union
@@ -271,6 +331,31 @@ struct GNUNET_GNSRECORD_BoxRecord
271 /* followed by the 'original' record */ 331 /* followed by the 'original' record */
272}; 332};
273 333
334
335/**
336 * Record type used to box up SMIMEA records. For example, a
337 * SMIMEA record for "c93f1e400f26708f98cb19d936620da35eec8f72e57
338 * f9eec01c1afd6._smimecert.foo.gnu" will be stored under
339 * "foo.gnu" as a SBOX record with the local-path of the associated
340 * e-mails hash turnicated to 28 octets encoded as hex and protocol _smimecert
341 * and record_type "SMIMEA". When a BOX record is received, GNS
342 * unboxes it if the name contained "hash._PROTO", otherwise GNS
343 * leaves it untouched. This is done to ensure that SMIMEA
344 * records do not require a separate network request, thus making SMIMEA
345 * records inseparable from the "main" A/AAAA/VPN/etc. records.
346 */
347struct GNUNET_GNSRECORD_SBoxRecord
348{
349 /**
350 * GNS record type of the boxed record. In NBO.
351 */
352 uint32_t record_type GNUNET_PACKED;
353
354 /* followed by the zero terminated hostname prefix */
355 /* followed by the 'original' record */
356};
357
358
274/** 359/**
275 * Record type used internally to keep track of reverse mappings into a 360 * Record type used internally to keep track of reverse mappings into a
276 * namespace. 361 * namespace.
@@ -283,7 +368,7 @@ struct GNUNET_GNSRECORD_ReverseRecord
283 /** 368 /**
284 * The public key of the namespace the is delegating to our namespace 369 * The public key of the namespace the is delegating to our namespace
285 */ 370 */
286 struct GNUNET_IDENTITY_PublicKey pkey; 371 struct GNUNET_CRYPTO_PublicKey pkey;
287 372
288 /** 373 /**
289 * The expiration time of the delegation 374 * The expiration time of the delegation
@@ -293,8 +378,6 @@ struct GNUNET_GNSRECORD_ReverseRecord
293 /* followed by the name the delegator uses to refer to our namespace */ 378 /* followed by the name the delegator uses to refer to our namespace */
294}; 379};
295 380
296GNUNET_NETWORK_STRUCT_END
297
298 381
299/** 382/**
300 * Process a records that were decrypted from a block. 383 * Process a records that were decrypted from a block.
@@ -387,6 +470,9 @@ GNUNET_GNSRECORD_records_serialize (unsigned int rd_count,
387 const struct GNUNET_GNSRECORD_Data *rd, 470 const struct GNUNET_GNSRECORD_Data *rd,
388 size_t dest_size, char *dest); 471 size_t dest_size, char *dest);
389 472
473unsigned int
474GNUNET_GNSRECORD_records_deserialize_get_size (size_t len,
475 const char *src);
390 476
391/** 477/**
392 * Deserialize the given records to the given destination. 478 * Deserialize the given records to the given destination.
@@ -418,12 +504,13 @@ GNUNET_GNSRECORD_is_expired (const struct GNUNET_GNSRECORD_Data *rd);
418 504
419 505
420/** 506/**
421 * Convert a UTF-8 string to UTF-8 lowercase 507 * Normalize a UTF-8 string to a GNS name
508 *
422 * @param src source string 509 * @param src source string
423 * @return converted result 510 * @return converted result
424 */ 511 */
425char * 512char *
426GNUNET_GNSRECORD_string_to_lowercase (const char *src); 513GNUNET_GNSRECORD_string_normalize (const char *src);
427 514
428 515
429/** 516/**
@@ -436,7 +523,7 @@ GNUNET_GNSRECORD_string_to_lowercase (const char *src);
436 * #GNUNET_GNSRECORD_z2s. 523 * #GNUNET_GNSRECORD_z2s.
437 */ 524 */
438const char * 525const char *
439GNUNET_GNSRECORD_z2s (const struct GNUNET_IDENTITY_PublicKey *z); 526GNUNET_GNSRECORD_z2s (const struct GNUNET_CRYPTO_PublicKey *z);
440 527
441 528
442/** 529/**
@@ -450,7 +537,7 @@ GNUNET_GNSRECORD_z2s (const struct GNUNET_IDENTITY_PublicKey *z);
450 * key in an encoding suitable for DNS labels. 537 * key in an encoding suitable for DNS labels.
451 */ 538 */
452const char * 539const char *
453GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_IDENTITY_PublicKey *pkey); 540GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_CRYPTO_PublicKey *pkey);
454 541
455 542
456/** 543/**
@@ -464,7 +551,7 @@ GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_IDENTITY_PublicKey *pkey);
464 */ 551 */
465int 552int
466GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, 553GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey,
467 struct GNUNET_IDENTITY_PublicKey *pkey); 554 struct GNUNET_CRYPTO_PublicKey *pkey);
468 555
469 556
470/** 557/**
@@ -476,12 +563,13 @@ GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey,
476 */ 563 */
477void 564void
478GNUNET_GNSRECORD_query_from_private_key ( 565GNUNET_GNSRECORD_query_from_private_key (
479 const struct GNUNET_IDENTITY_PrivateKey *zone, const char *label, 566 const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label,
480 struct GNUNET_HashCode *query); 567 struct GNUNET_HashCode *query);
481 568
482 569
483/** 570/**
484 * Calculate the DHT query for a given @a label in a given @a zone. 571 * Calculate the DHT query for a given @a label in a given @a zone.
572 * FIXME: We may want to plugin-ize this at some point.
485 * 573 *
486 * @param pub public key of the zone 574 * @param pub public key of the zone
487 * @param label label of the record 575 * @param label label of the record
@@ -489,11 +577,39 @@ GNUNET_GNSRECORD_query_from_private_key (
489 */ 577 */
490void 578void
491GNUNET_GNSRECORD_query_from_public_key ( 579GNUNET_GNSRECORD_query_from_public_key (
492 const struct GNUNET_IDENTITY_PublicKey *pub, const char *label, 580 const struct GNUNET_CRYPTO_PublicKey *pub, const char *label,
493 struct GNUNET_HashCode *query); 581 struct GNUNET_HashCode *query);
494 582
495 583
496/** 584/**
585 * Get size of buffer for block creation.
586 *
587 * @param key the zone key
588 * @param rd record data
589 * @param rd_count number of records
590 * @return -1 on error (otherwise the length of the block)
591 */
592ssize_t
593GNUNET_GNSRECORD_block_calculate_size (const struct
594 GNUNET_CRYPTO_PrivateKey *key,
595 const struct GNUNET_GNSRECORD_Data *rd,
596 unsigned int rd_count);
597
598/**
599 * Sign a block create with #GNUNET_GNSRECORD_block_create_unsigned
600 *
601 * @param key the private key
602 * @param label the label of the block
603 * @param block the unsigned block
604 * @return GNUNET_OK on success
605 */
606enum GNUNET_GenericReturnValue
607GNUNET_GNSRECORD_block_sign (const struct
608 GNUNET_CRYPTO_PrivateKey *key,
609 const char *label,
610 struct GNUNET_GNSRECORD_Block *block);
611
612/**
497 * Sign name and records 613 * Sign name and records
498 * 614 *
499 * @param key the private key 615 * @param key the private key
@@ -501,13 +617,41 @@ GNUNET_GNSRECORD_query_from_public_key (
501 * @param label the name for the records 617 * @param label the name for the records
502 * @param rd record data 618 * @param rd record data
503 * @param rd_count number of records in @a rd 619 * @param rd_count number of records in @a rd
620 * @param result the block buffer. Will be allocated.
621 * @return GNUNET_OK on success
504 */ 622 */
505struct GNUNET_GNSRECORD_Block * 623enum GNUNET_GenericReturnValue
506GNUNET_GNSRECORD_block_create (const struct GNUNET_IDENTITY_PrivateKey *key, 624GNUNET_GNSRECORD_block_create (const struct GNUNET_CRYPTO_PrivateKey *key,
507 struct GNUNET_TIME_Absolute expire, 625 struct GNUNET_TIME_Absolute expire,
508 const char *label, 626 const char *label,
509 const struct GNUNET_GNSRECORD_Data *rd, 627 const struct GNUNET_GNSRECORD_Data *rd,
510 unsigned int rd_count); 628 unsigned int rd_count,
629 struct GNUNET_GNSRECORD_Block **block);
630
631
632/**
633 * Create name and records but do not sign!
634 * Sign later with #GNUNET_GNSRECORD_block_sign().
635 * Cache derived public key (also keeps the
636 * private key in static memory, so do not use this function if
637 * keeping the private key in the process'es RAM is a major issue).
638 *
639 * @param key the private key
640 * @param expire block expiration
641 * @param label the name for the records
642 * @param rd record data
643 * @param rd_count number of records in @a rd
644 * @param result the block buffer. Will be allocated.
645 * @return GNUNET_OK on success.
646 */
647enum GNUNET_GenericReturnValue
648GNUNET_GNSRECORD_block_create_unsigned (const struct
649 GNUNET_CRYPTO_PrivateKey *key,
650 struct GNUNET_TIME_Absolute expire,
651 const char *label,
652 const struct GNUNET_GNSRECORD_Data *rd,
653 unsigned int rd_count,
654 struct GNUNET_GNSRECORD_Block **result);
511 655
512 656
513/** 657/**
@@ -520,13 +664,16 @@ GNUNET_GNSRECORD_block_create (const struct GNUNET_IDENTITY_PrivateKey *key,
520 * @param label the name for the records 664 * @param label the name for the records
521 * @param rd record data 665 * @param rd record data
522 * @param rd_count number of records in @a rd 666 * @param rd_count number of records in @a rd
667 * @param result the block buffer. Will be allocated.
668 * @return GNUNET_OK on success.
523 */ 669 */
524struct GNUNET_GNSRECORD_Block * 670enum GNUNET_GenericReturnValue
525GNUNET_GNSRECORD_block_create2 (const struct GNUNET_IDENTITY_PrivateKey *key, 671GNUNET_GNSRECORD_block_create2 (const struct GNUNET_CRYPTO_PrivateKey *key,
526 struct GNUNET_TIME_Absolute expire, 672 struct GNUNET_TIME_Absolute expire,
527 const char *label, 673 const char *label,
528 const struct GNUNET_GNSRECORD_Data *rd, 674 const struct GNUNET_GNSRECORD_Data *rd,
529 unsigned int rd_count); 675 unsigned int rd_count,
676 struct GNUNET_GNSRECORD_Block **result);
530 677
531 678
532/** 679/**
@@ -536,7 +683,7 @@ GNUNET_GNSRECORD_block_create2 (const struct GNUNET_IDENTITY_PrivateKey *key,
536 * @param block block to verify 683 * @param block block to verify
537 * @return #GNUNET_OK if the signature is valid 684 * @return #GNUNET_OK if the signature is valid
538 */ 685 */
539int 686enum GNUNET_GenericReturnValue
540GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block); 687GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block);
541 688
542 689
@@ -551,10 +698,10 @@ GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block);
551 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the block was 698 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the block was
552 * not well-formed 699 * not well-formed
553 */ 700 */
554int 701enum GNUNET_GenericReturnValue
555GNUNET_GNSRECORD_block_decrypt ( 702GNUNET_GNSRECORD_block_decrypt (
556 const struct GNUNET_GNSRECORD_Block *block, 703 const struct GNUNET_GNSRECORD_Block *block,
557 const struct GNUNET_IDENTITY_PublicKey *zone_key, const char *label, 704 const struct GNUNET_CRYPTO_PublicKey *zone_key, const char *label,
558 GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls); 705 GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls);
559 706
560 707
@@ -565,7 +712,7 @@ GNUNET_GNSRECORD_block_decrypt (
565 * @param b another record 712 * @param b another record
566 * @return #GNUNET_YES if the records are equal, or #GNUNET_NO if not. 713 * @return #GNUNET_YES if the records are equal, or #GNUNET_NO if not.
567 */ 714 */
568int 715enum GNUNET_GenericReturnValue
569GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a, 716GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a,
570 const struct GNUNET_GNSRECORD_Data *b); 717 const struct GNUNET_GNSRECORD_Data *b);
571 718
@@ -577,11 +724,14 @@ GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a,
577 * 724 *
578 * @param rd_count number of records given in @a rd 725 * @param rd_count number of records given in @a rd
579 * @param rd array of records 726 * @param rd array of records
727 * @param min minimum expiration time
580 * @return absolute expiration time 728 * @return absolute expiration time
581 */ 729 */
582struct GNUNET_TIME_Absolute 730struct GNUNET_TIME_Absolute
583GNUNET_GNSRECORD_record_get_expiration_time ( 731GNUNET_GNSRECORD_record_get_expiration_time (unsigned int rd_count,
584 unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd); 732 const struct
733 GNUNET_GNSRECORD_Data *rd,
734 struct GNUNET_TIME_Absolute min);
585 735
586 736
587/** 737/**
@@ -631,7 +781,7 @@ enum GNUNET_GenericReturnValue
631GNUNET_GNSRECORD_identity_from_data (const char *data, 781GNUNET_GNSRECORD_identity_from_data (const char *data,
632 size_t data_size, 782 size_t data_size,
633 uint32_t type, 783 uint32_t type,
634 struct GNUNET_IDENTITY_PublicKey *key); 784 struct GNUNET_CRYPTO_PublicKey *key);
635 785
636 786
637/** 787/**
@@ -645,7 +795,7 @@ GNUNET_GNSRECORD_identity_from_data (const char *data,
645 */ 795 */
646enum GNUNET_GenericReturnValue 796enum GNUNET_GenericReturnValue
647GNUNET_GNSRECORD_data_from_identity (const struct 797GNUNET_GNSRECORD_data_from_identity (const struct
648 GNUNET_IDENTITY_PublicKey *key, 798 GNUNET_CRYPTO_PublicKey *key,
649 char **data, 799 char **data,
650 size_t *data_size, 800 size_t *data_size,
651 uint32_t *type); 801 uint32_t *type);
@@ -661,6 +811,181 @@ GNUNET_GNSRECORD_data_from_identity (const struct
661enum GNUNET_GenericReturnValue 811enum GNUNET_GenericReturnValue
662GNUNET_GNSRECORD_is_zonekey_type (uint32_t type); 812GNUNET_GNSRECORD_is_zonekey_type (uint32_t type);
663 813
814/**
815 * Check if this type is a critical record.
816 *
817 * @param type the type to check
818 * @return GNUNET_YES if it is critical.
819 */
820enum GNUNET_GenericReturnValue
821GNUNET_GNSRECORD_is_critical (uint32_t type);
822
823/**
824 * Normalize namestore records: Check for consistency and
825 * expirations. Purge expired records. Returns a "clean" record set.
826 * Also returns the minimum expiration time this block should be
827 * published under.
828 * Also checks rules with respect to labels (e.g. no delegations under
829 * the empty label)
830 *
831 * @param label the label under which this set (supposed to be) stored.
832 * @param rd input records
833 * @param rd_count size of the @a rd and @a rd_public arrays
834 * @param rd_public where to write the converted records
835 * @param rd_count_public number of records written to @a rd_public
836 * @param min_expiry the minimum expiration of this set
837 * @param filter the record set filter, see GNUNET_GNSRECORD_Filter.
838 * @param emsg the error message if something went wrong
839 * @return GNUNET_OK if set could be normalized and is consistent
840 */
841enum GNUNET_GenericReturnValue
842GNUNET_GNSRECORD_normalize_record_set (const char *label,
843 const struct GNUNET_GNSRECORD_Data *rd,
844 unsigned int rd_count,
845 struct GNUNET_GNSRECORD_Data *rd_public,
846 unsigned int *rd_count_public,
847 struct GNUNET_TIME_Absolute *min_expiry,
848 enum GNUNET_GNSRECORD_Filter filter,
849 char **emsg);
850
851/**
852 * Check label for invalid characters.
853 *
854 * @param label the label to check
855 * @param emsg an error message (NULL if label is valid). Will be allocated.
856 * @return GNUNET_OK if label is valid.
857 */
858enum GNUNET_GenericReturnValue
859GNUNET_GNSRECORD_label_check (const char*label, char **emsg);
860
861/**
862 * Maximum length of a revocation
863 */
864#define GNUNET_MAX_POW_SIZE sizeof(struct GNUNET_GNSRECORD_PowP) \
865 + sizeof(struct GNUNET_CRYPTO_PublicKey) \
866 + 1024 // FIXME max sig_len
867
868/**
869 * The proof-of-work narrowing factor.
870 * The number of PoWs that are calculates as part of revocation.
871 */
872#define POW_COUNT 32
873
874
875GNUNET_NETWORK_STRUCT_BEGIN
876
877/**
878 * Struct for a proof of work as part of the revocation.
879 */
880struct GNUNET_GNSRECORD_PowP
881{
882 /**
883 * The timestamp of the revocation
884 */
885 struct GNUNET_TIME_AbsoluteNBO timestamp;
886
887 /**
888 * The TTL of this revocation (purely informational)
889 */
890 struct GNUNET_TIME_RelativeNBO ttl;
891
892 /**
893 * The PoWs
894 */
895 uint64_t pow[POW_COUNT] GNUNET_PACKED;
896
897 /** followed by the public key type, the key and a signature **/
898};
899
900
901/**
902 * The signature object we use for the PoW
903 */
904struct GNUNET_GNSRECORD_SignaturePurposePS
905{
906 /**
907 * The signature purpose
908 */
909 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
910
911 /**
912 * The timestamp of the revocation
913 */
914 struct GNUNET_TIME_AbsoluteNBO timestamp;
915
916 /** Followed by the zone public key type and key **/
917};
918
919GNUNET_NETWORK_STRUCT_END
920
921
922/**
923 * Handle to a running proof-of-work calculation.
924 */
925struct GNUNET_GNSRECORD_PowCalculationHandle;
926
927
928/**
929 * Check if the given proof-of-work is valid.
930 *
931 * @param pow proof of work
932 * @param matching_bits how many bits must match (configuration)
933 * @param epoch_duration length of single epoch in configuration
934 * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not
935 */
936enum GNUNET_GenericReturnValue
937GNUNET_GNSRECORD_check_pow (const struct GNUNET_GNSRECORD_PowP *pow,
938 unsigned int matching_bits,
939 struct GNUNET_TIME_Relative epoch_duration);
940
941
942/**
943 * Initializes a fresh PoW computation.
944 *
945 * @param key the key to calculate the PoW for.
946 * @param pow the pow object to work with in the calculation.
947 */
948void
949GNUNET_GNSRECORD_pow_init (const struct GNUNET_CRYPTO_PrivateKey *key,
950 struct GNUNET_GNSRECORD_PowP *pow);
951
952
953/**
954 * Starts a proof-of-work calculation given the pow object as well as
955 * target epochs and difficulty.
956 *
957 * @param pow the PoW to based calculations on.
958 * @param epochs the number of epochs for which the PoW must be valid.
959 * @param difficulty the base difficulty of the PoW.
960 * @return a handle for use in PoW rounds
961 */
962struct GNUNET_GNSRECORD_PowCalculationHandle*
963GNUNET_GNSRECORD_pow_start (struct GNUNET_GNSRECORD_PowP *pow,
964 int epochs,
965 unsigned int difficulty);
966
967
968/**
969 * Calculate a single round in the key revocation PoW.
970 *
971 * @param pc handle to the PoW, initially called with NULL.
972 * @return GNUNET_YES if the @a pow is acceptable, GNUNET_NO if not
973 */
974enum GNUNET_GenericReturnValue
975GNUNET_GNSRECORD_pow_round (struct GNUNET_GNSRECORD_PowCalculationHandle *pc);
976
977size_t
978GNUNET_GNSRECORD_proof_get_size (const struct GNUNET_GNSRECORD_PowP *pow);
979
980/**
981 * Stop a PoW calculation
982 *
983 * @param pc the calculation to clean up
984 * @return #GNUNET_YES if pow valid, #GNUNET_NO if pow was set but is not
985 * valid
986 */
987void
988GNUNET_GNSRECORD_pow_stop (struct GNUNET_GNSRECORD_PowCalculationHandle *pc);
664 989
665#if 0 /* keep Emacsens' auto-indent happy */ 990#if 0 /* keep Emacsens' auto-indent happy */
666{ 991{
@@ -672,3 +997,5 @@ GNUNET_GNSRECORD_is_zonekey_type (uint32_t type);
672#endif 997#endif
673 998
674/** @} */ /* end of group */ 999/** @} */ /* end of group */
1000
1001/** @} */ /* end of group addition */