diff options
Diffstat (limited to 'src/include/gnunet_gnsrecord_lib.h')
-rw-r--r-- | src/include/gnunet_gnsrecord_lib.h | 354 |
1 files changed, 286 insertions, 68 deletions
diff --git a/src/include/gnunet_gnsrecord_lib.h b/src/include/gnunet_gnsrecord_lib.h index 51dd5972d..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 |
@@ -66,59 +71,102 @@ extern "C" { | |||
66 | #include "gnu_name_system_record_types.h" | 71 | #include "gnu_name_system_record_types.h" |
67 | 72 | ||
68 | /** | 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 | /** | ||
69 | * Flags that can be set for a record. | 88 | * Flags that can be set for a record. |
70 | * MUST fit into 16 bit. | 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). | ||
71 | */ | 98 | */ |
72 | enum GNUNET_GNSRECORD_Flags | 99 | enum GNUNET_GNSRECORD_Flags |
73 | { | 100 | { |
74 | /** | 101 | /** |
75 | * No special options. | 102 | * Entry for no flags / cleared flags. |
76 | */ | 103 | */ |
77 | GNUNET_GNSRECORD_RF_NONE = 0, | 104 | GNUNET_GNSRECORD_RF_NONE = 0, |
78 | 105 | ||
106 | |||
79 | /** | 107 | /** |
80 | * This record is critical. If it cannot be processed | 108 | * This record is critical. If it cannot be processed (for example because the record type is unknown) resolution MUST fail |
81 | * (for example beacuse the record type is unknown) | ||
82 | * resolution MUST fail | ||
83 | */ | 109 | */ |
84 | GNUNET_GNSRECORD_RF_CRITICAL = 1, | 110 | GNUNET_GNSRECORD_RF_CRITICAL = 1 << (15 - 15), |
111 | |||
85 | 112 | ||
86 | /** | 113 | /** |
87 | * This record should not be used unless all (other) records with an absolute | 114 | * This record should not be used unless all (other) records in the set with an absolute expiration time have expired. |
88 | * expiration time have expired. | ||
89 | */ | 115 | */ |
90 | GNUNET_GNSRECORD_RF_SHADOW_RECORD = 2, | 116 | GNUNET_GNSRECORD_RF_SHADOW = 1 << (15 - 14), |
117 | |||
91 | 118 | ||
92 | /** | 119 | /** |
93 | * This is a supplemental record. | 120 | * This is a supplemental record. |
94 | */ | 121 | */ |
95 | GNUNET_GNSRECORD_RF_SUPPLEMENTAL = 4, | 122 | GNUNET_GNSRECORD_RF_SUPPLEMENTAL = 1 << (15 - 13), |
96 | 123 | ||
97 | /** | 124 | /** |
98 | * This expiration time of the record is a relative | 125 | * Maintenance records. E.g. TOMBSTONEs |
99 | * time (not an absolute time). | ||
100 | */ | 126 | */ |
101 | GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION = 16384, /* 2^14 */ | 127 | GNUNET_GNSRECORD_RF_MAINTENANCE = 1 << (15 - 2), |
102 | 128 | ||
103 | /** | 129 | /** |
104 | * This is a private record of this peer and it should | 130 | * This expiration time of the record is a relative time (not an absolute time). Used in GNUnet implementation. |
105 | * thus not be handed out to other peers. | ||
106 | */ | 131 | */ |
107 | GNUNET_GNSRECORD_RF_PRIVATE = 32768, /* 2^15 */ | 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 | }; | ||
108 | 141 | ||
109 | 142 | ||
110 | /** | 143 | /** |
111 | * When comparing flags for record equality for removal, | 144 | * Filter for GNUNET_GNSRECORD_normalize_record_set(). |
112 | * which flags should must match (in addition to the type, | ||
113 | * name, expiration value and data of the record)? All flags | ||
114 | * that are not listed here will be ignored for this purpose. | ||
115 | * (for example, we don't expect that users will remember to | ||
116 | * pass the '--private' option when removing a record from | ||
117 | * the namestore, hence we don't require this particular option | ||
118 | * to match upon removal). See also | ||
119 | * #GNUNET_GNSRECORD_records_cmp. | ||
120 | */ | 145 | */ |
121 | #define GNUNET_GNSRECORD_RF_RCMP_FLAGS (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION) | 146 | enum 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, | ||
122 | }; | 170 | }; |
123 | 171 | ||
124 | 172 | ||
@@ -283,6 +331,31 @@ struct GNUNET_GNSRECORD_BoxRecord | |||
283 | /* followed by the 'original' record */ | 331 | /* followed by the 'original' record */ |
284 | }; | 332 | }; |
285 | 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 | */ | ||
347 | struct 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 | |||
286 | /** | 359 | /** |
287 | * 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 |
288 | * namespace. | 361 | * namespace. |
@@ -295,7 +368,7 @@ struct GNUNET_GNSRECORD_ReverseRecord | |||
295 | /** | 368 | /** |
296 | * 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 |
297 | */ | 370 | */ |
298 | struct GNUNET_IDENTITY_PublicKey pkey; | 371 | struct GNUNET_CRYPTO_PublicKey pkey; |
299 | 372 | ||
300 | /** | 373 | /** |
301 | * The expiration time of the delegation | 374 | * The expiration time of the delegation |
@@ -450,7 +523,7 @@ GNUNET_GNSRECORD_string_normalize (const char *src); | |||
450 | * #GNUNET_GNSRECORD_z2s. | 523 | * #GNUNET_GNSRECORD_z2s. |
451 | */ | 524 | */ |
452 | const char * | 525 | const char * |
453 | GNUNET_GNSRECORD_z2s (const struct GNUNET_IDENTITY_PublicKey *z); | 526 | GNUNET_GNSRECORD_z2s (const struct GNUNET_CRYPTO_PublicKey *z); |
454 | 527 | ||
455 | 528 | ||
456 | /** | 529 | /** |
@@ -464,7 +537,7 @@ GNUNET_GNSRECORD_z2s (const struct GNUNET_IDENTITY_PublicKey *z); | |||
464 | * key in an encoding suitable for DNS labels. | 537 | * key in an encoding suitable for DNS labels. |
465 | */ | 538 | */ |
466 | const char * | 539 | const char * |
467 | GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_IDENTITY_PublicKey *pkey); | 540 | GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_CRYPTO_PublicKey *pkey); |
468 | 541 | ||
469 | 542 | ||
470 | /** | 543 | /** |
@@ -478,7 +551,7 @@ GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_IDENTITY_PublicKey *pkey); | |||
478 | */ | 551 | */ |
479 | int | 552 | int |
480 | GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, | 553 | GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, |
481 | struct GNUNET_IDENTITY_PublicKey *pkey); | 554 | struct GNUNET_CRYPTO_PublicKey *pkey); |
482 | 555 | ||
483 | 556 | ||
484 | /** | 557 | /** |
@@ -490,12 +563,13 @@ GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, | |||
490 | */ | 563 | */ |
491 | void | 564 | void |
492 | GNUNET_GNSRECORD_query_from_private_key ( | 565 | GNUNET_GNSRECORD_query_from_private_key ( |
493 | const struct GNUNET_IDENTITY_PrivateKey *zone, const char *label, | 566 | const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label, |
494 | struct GNUNET_HashCode *query); | 567 | struct GNUNET_HashCode *query); |
495 | 568 | ||
496 | 569 | ||
497 | /** | 570 | /** |
498 | * 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. | ||
499 | * | 573 | * |
500 | * @param pub public key of the zone | 574 | * @param pub public key of the zone |
501 | * @param label label of the record | 575 | * @param label label of the record |
@@ -503,7 +577,7 @@ GNUNET_GNSRECORD_query_from_private_key ( | |||
503 | */ | 577 | */ |
504 | void | 578 | void |
505 | GNUNET_GNSRECORD_query_from_public_key ( | 579 | GNUNET_GNSRECORD_query_from_public_key ( |
506 | const struct GNUNET_IDENTITY_PublicKey *pub, const char *label, | 580 | const struct GNUNET_CRYPTO_PublicKey *pub, const char *label, |
507 | struct GNUNET_HashCode *query); | 581 | struct GNUNET_HashCode *query); |
508 | 582 | ||
509 | 583 | ||
@@ -517,10 +591,23 @@ GNUNET_GNSRECORD_query_from_public_key ( | |||
517 | */ | 591 | */ |
518 | ssize_t | 592 | ssize_t |
519 | GNUNET_GNSRECORD_block_calculate_size (const struct | 593 | GNUNET_GNSRECORD_block_calculate_size (const struct |
520 | GNUNET_IDENTITY_PrivateKey *key, | 594 | GNUNET_CRYPTO_PrivateKey *key, |
521 | const struct GNUNET_GNSRECORD_Data *rd, | 595 | const struct GNUNET_GNSRECORD_Data *rd, |
522 | unsigned int rd_count); | 596 | unsigned int rd_count); |
523 | 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 | */ | ||
606 | enum GNUNET_GenericReturnValue | ||
607 | GNUNET_GNSRECORD_block_sign (const struct | ||
608 | GNUNET_CRYPTO_PrivateKey *key, | ||
609 | const char *label, | ||
610 | struct GNUNET_GNSRECORD_Block *block); | ||
524 | 611 | ||
525 | /** | 612 | /** |
526 | * Sign name and records | 613 | * Sign name and records |
@@ -534,7 +621,7 @@ GNUNET_GNSRECORD_block_calculate_size (const struct | |||
534 | * @return GNUNET_OK on success | 621 | * @return GNUNET_OK on success |
535 | */ | 622 | */ |
536 | enum GNUNET_GenericReturnValue | 623 | enum GNUNET_GenericReturnValue |
537 | GNUNET_GNSRECORD_block_create (const struct GNUNET_IDENTITY_PrivateKey *key, | 624 | GNUNET_GNSRECORD_block_create (const struct GNUNET_CRYPTO_PrivateKey *key, |
538 | struct GNUNET_TIME_Absolute expire, | 625 | struct GNUNET_TIME_Absolute expire, |
539 | const char *label, | 626 | const char *label, |
540 | const struct GNUNET_GNSRECORD_Data *rd, | 627 | const struct GNUNET_GNSRECORD_Data *rd, |
@@ -543,6 +630,31 @@ GNUNET_GNSRECORD_block_create (const struct GNUNET_IDENTITY_PrivateKey *key, | |||
543 | 630 | ||
544 | 631 | ||
545 | /** | 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 | */ | ||
647 | enum GNUNET_GenericReturnValue | ||
648 | GNUNET_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); | ||
655 | |||
656 | |||
657 | /** | ||
546 | * Sign name and records, cache derived public key (also keeps the | 658 | * Sign name and records, cache derived public key (also keeps the |
547 | * private key in static memory, so do not use this function if | 659 | * private key in static memory, so do not use this function if |
548 | * keeping the private key in the process'es RAM is a major issue). | 660 | * keeping the private key in the process'es RAM is a major issue). |
@@ -556,7 +668,7 @@ GNUNET_GNSRECORD_block_create (const struct GNUNET_IDENTITY_PrivateKey *key, | |||
556 | * @return GNUNET_OK on success. | 668 | * @return GNUNET_OK on success. |
557 | */ | 669 | */ |
558 | enum GNUNET_GenericReturnValue | 670 | enum GNUNET_GenericReturnValue |
559 | GNUNET_GNSRECORD_block_create2 (const struct GNUNET_IDENTITY_PrivateKey *key, | 671 | GNUNET_GNSRECORD_block_create2 (const struct GNUNET_CRYPTO_PrivateKey *key, |
560 | struct GNUNET_TIME_Absolute expire, | 672 | struct GNUNET_TIME_Absolute expire, |
561 | const char *label, | 673 | const char *label, |
562 | const struct GNUNET_GNSRECORD_Data *rd, | 674 | const struct GNUNET_GNSRECORD_Data *rd, |
@@ -571,7 +683,7 @@ GNUNET_GNSRECORD_block_create2 (const struct GNUNET_IDENTITY_PrivateKey *key, | |||
571 | * @param block block to verify | 683 | * @param block block to verify |
572 | * @return #GNUNET_OK if the signature is valid | 684 | * @return #GNUNET_OK if the signature is valid |
573 | */ | 685 | */ |
574 | int | 686 | enum GNUNET_GenericReturnValue |
575 | GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block); | 687 | GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block); |
576 | 688 | ||
577 | 689 | ||
@@ -586,10 +698,10 @@ GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block); | |||
586 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the block was | 698 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the block was |
587 | * not well-formed | 699 | * not well-formed |
588 | */ | 700 | */ |
589 | int | 701 | enum GNUNET_GenericReturnValue |
590 | GNUNET_GNSRECORD_block_decrypt ( | 702 | GNUNET_GNSRECORD_block_decrypt ( |
591 | const struct GNUNET_GNSRECORD_Block *block, | 703 | const struct GNUNET_GNSRECORD_Block *block, |
592 | const struct GNUNET_IDENTITY_PublicKey *zone_key, const char *label, | 704 | const struct GNUNET_CRYPTO_PublicKey *zone_key, const char *label, |
593 | GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls); | 705 | GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls); |
594 | 706 | ||
595 | 707 | ||
@@ -600,7 +712,7 @@ GNUNET_GNSRECORD_block_decrypt ( | |||
600 | * @param b another record | 712 | * @param b another record |
601 | * @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. |
602 | */ | 714 | */ |
603 | int | 715 | enum GNUNET_GenericReturnValue |
604 | GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a, | 716 | GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a, |
605 | const struct GNUNET_GNSRECORD_Data *b); | 717 | const struct GNUNET_GNSRECORD_Data *b); |
606 | 718 | ||
@@ -669,7 +781,7 @@ enum GNUNET_GenericReturnValue | |||
669 | GNUNET_GNSRECORD_identity_from_data (const char *data, | 781 | GNUNET_GNSRECORD_identity_from_data (const char *data, |
670 | size_t data_size, | 782 | size_t data_size, |
671 | uint32_t type, | 783 | uint32_t type, |
672 | struct GNUNET_IDENTITY_PublicKey *key); | 784 | struct GNUNET_CRYPTO_PublicKey *key); |
673 | 785 | ||
674 | 786 | ||
675 | /** | 787 | /** |
@@ -683,7 +795,7 @@ GNUNET_GNSRECORD_identity_from_data (const char *data, | |||
683 | */ | 795 | */ |
684 | enum GNUNET_GenericReturnValue | 796 | enum GNUNET_GenericReturnValue |
685 | GNUNET_GNSRECORD_data_from_identity (const struct | 797 | GNUNET_GNSRECORD_data_from_identity (const struct |
686 | GNUNET_IDENTITY_PublicKey *key, | 798 | GNUNET_CRYPTO_PublicKey *key, |
687 | char **data, | 799 | char **data, |
688 | size_t *data_size, | 800 | size_t *data_size, |
689 | uint32_t *type); | 801 | uint32_t *type); |
@@ -720,9 +832,9 @@ GNUNET_GNSRECORD_is_critical (uint32_t type); | |||
720 | * @param rd input records | 832 | * @param rd input records |
721 | * @param rd_count size of the @a rd and @a rd_public arrays | 833 | * @param rd_count size of the @a rd and @a rd_public arrays |
722 | * @param rd_public where to write the converted records | 834 | * @param rd_public where to write the converted records |
723 | * @param rd_public_count number of records written to @a rd_public | 835 | * @param rd_count_public number of records written to @a rd_public |
724 | * @param min_expiry the minimum expiration of this set | 836 | * @param min_expiry the minimum expiration of this set |
725 | * @param include_private GNUNET_YES if private records should be included. | 837 | * @param filter the record set filter, see GNUNET_GNSRECORD_Filter. |
726 | * @param emsg the error message if something went wrong | 838 | * @param emsg the error message if something went wrong |
727 | * @return GNUNET_OK if set could be normalized and is consistent | 839 | * @return GNUNET_OK if set could be normalized and is consistent |
728 | */ | 840 | */ |
@@ -733,43 +845,147 @@ GNUNET_GNSRECORD_normalize_record_set (const char *label, | |||
733 | struct GNUNET_GNSRECORD_Data *rd_public, | 845 | struct GNUNET_GNSRECORD_Data *rd_public, |
734 | unsigned int *rd_count_public, | 846 | unsigned int *rd_count_public, |
735 | struct GNUNET_TIME_Absolute *min_expiry, | 847 | struct GNUNET_TIME_Absolute *min_expiry, |
736 | int include_private, | 848 | enum GNUNET_GNSRECORD_Filter filter, |
737 | char **emsg); | 849 | char **emsg); |
738 | 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 | */ | ||
858 | enum GNUNET_GenericReturnValue | ||
859 | GNUNET_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 | |||
875 | GNUNET_NETWORK_STRUCT_BEGIN | ||
739 | 876 | ||
740 | /** | 877 | /** |
741 | * Convert namestore records from the internal format to that | 878 | * Struct for a proof of work as part of the revocation. |
742 | * suitable for publication (removes private records). | 879 | */ |
880 | struct 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 | */ | ||
904 | struct 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 | |||
919 | GNUNET_NETWORK_STRUCT_END | ||
920 | |||
921 | |||
922 | /** | ||
923 | * Handle to a running proof-of-work calculation. | ||
924 | */ | ||
925 | struct GNUNET_GNSRECORD_PowCalculationHandle; | ||
926 | |||
927 | |||
928 | /** | ||
929 | * Check if the given proof-of-work is valid. | ||
743 | * | 930 | * |
744 | * @param label the label under which this set is (supposed to be) published. | 931 | * @param pow proof of work |
745 | * @param rd input records | 932 | * @param matching_bits how many bits must match (configuration) |
746 | * @param rd_count size of the @a rd and @a rd_public arrays | 933 | * @param epoch_duration length of single epoch in configuration |
747 | * @param rd_public where to write the converted records | 934 | * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not |
748 | * @param rd_public_count number of records written to @a rd_public | ||
749 | * @param expiry the expiration of the block | ||
750 | * @param emsg the error message if something went wrong | ||
751 | * @return GNUNET_OK if set is consistent and can be exported | ||
752 | */ | 935 | */ |
753 | enum GNUNET_GenericReturnValue | 936 | enum GNUNET_GenericReturnValue |
754 | GNUNET_GNSRECORD_convert_records_for_export (const char *label, | 937 | GNUNET_GNSRECORD_check_pow (const struct GNUNET_GNSRECORD_PowP *pow, |
755 | const struct | 938 | unsigned int matching_bits, |
756 | GNUNET_GNSRECORD_Data *rd, | 939 | struct GNUNET_TIME_Relative epoch_duration); |
757 | unsigned int rd_count, | 940 | |
758 | struct GNUNET_GNSRECORD_Data * | ||
759 | rd_public, | ||
760 | unsigned int *rd_count_public, | ||
761 | struct GNUNET_TIME_Absolute *expiry, | ||
762 | char **emsg); | ||
763 | 941 | ||
764 | /** | 942 | /** |
765 | * Check label for invalid characters. | 943 | * Initializes a fresh PoW computation. |
766 | * | 944 | * |
767 | * @param label the label to check | 945 | * @param key the key to calculate the PoW for. |
768 | * @param emsg an error message (NULL if label is valid). Will be allocated. | 946 | * @param pow the pow object to work with in the calculation. |
769 | * @return GNUNET_OK if label is valid. | 947 | */ |
948 | void | ||
949 | GNUNET_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 | */ | ||
962 | struct GNUNET_GNSRECORD_PowCalculationHandle* | ||
963 | GNUNET_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 | ||
770 | */ | 973 | */ |
771 | enum GNUNET_GenericReturnValue | 974 | enum GNUNET_GenericReturnValue |
772 | GNUNET_GNSRECORD_label_check (const char*label, char **emsg); | 975 | GNUNET_GNSRECORD_pow_round (struct GNUNET_GNSRECORD_PowCalculationHandle *pc); |
976 | |||
977 | size_t | ||
978 | GNUNET_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 | */ | ||
987 | void | ||
988 | GNUNET_GNSRECORD_pow_stop (struct GNUNET_GNSRECORD_PowCalculationHandle *pc); | ||
773 | 989 | ||
774 | #if 0 /* keep Emacsens' auto-indent happy */ | 990 | #if 0 /* keep Emacsens' auto-indent happy */ |
775 | { | 991 | { |
@@ -781,3 +997,5 @@ GNUNET_GNSRECORD_label_check (const char*label, char **emsg); | |||
781 | #endif | 997 | #endif |
782 | 998 | ||
783 | /** @} */ /* end of group */ | 999 | /** @} */ /* end of group */ |
1000 | |||
1001 | /** @} */ /* end of group addition */ | ||