diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-10-16 20:14:02 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-10-16 20:14:02 +0000 |
commit | 3d670727232e79b7e49a1df7ba9260db4e5798a0 (patch) | |
tree | 093f7b5aec28134dc6c5fe34cd2d8bfb1e1445ad /src/include/gnunet_namestore_service.h | |
parent | 2de26776993a5e591e487321a5dc1d62b86d9cd4 (diff) | |
download | gnunet-3d670727232e79b7e49a1df7ba9260db4e5798a0.tar.gz gnunet-3d670727232e79b7e49a1df7ba9260db4e5798a0.zip |
-moving namestore_common functions to gnsrecord library
Diffstat (limited to 'src/include/gnunet_namestore_service.h')
-rw-r--r-- | src/include/gnunet_namestore_service.h | 348 |
1 files changed, 1 insertions, 347 deletions
diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h index 55fdbef65..30098832c 100644 --- a/src/include/gnunet_namestore_service.h +++ b/src/include/gnunet_namestore_service.h | |||
@@ -31,6 +31,7 @@ | |||
31 | 31 | ||
32 | #include "gnunet_util_lib.h" | 32 | #include "gnunet_util_lib.h" |
33 | #include "gnunet_block_lib.h" | 33 | #include "gnunet_block_lib.h" |
34 | #include "gnunet_gnsrecord_lib.h" | ||
34 | 35 | ||
35 | #ifdef __cplusplus | 36 | #ifdef __cplusplus |
36 | extern "C" | 37 | extern "C" |
@@ -56,11 +57,6 @@ struct GNUNET_NAMESTORE_Handle; | |||
56 | */ | 57 | */ |
57 | struct GNUNET_NAMESTORE_ZoneIterator; | 58 | struct GNUNET_NAMESTORE_ZoneIterator; |
58 | 59 | ||
59 | /** | ||
60 | * Maximum size of a value that can be stored in the namestore. | ||
61 | */ | ||
62 | #define GNUNET_NAMESTORE_MAX_VALUE_SIZE (63 * 1024) | ||
63 | |||
64 | 60 | ||
65 | /** | 61 | /** |
66 | * Connect to the namestore service. | 62 | * Connect to the namestore service. |
@@ -99,131 +95,6 @@ typedef void (*GNUNET_NAMESTORE_ContinuationWithStatus) (void *cls, | |||
99 | 95 | ||
100 | 96 | ||
101 | /** | 97 | /** |
102 | * Flags that can be set for a record. | ||
103 | */ | ||
104 | enum GNUNET_NAMESTORE_RecordFlags | ||
105 | { | ||
106 | |||
107 | /** | ||
108 | * No special options. | ||
109 | */ | ||
110 | GNUNET_NAMESTORE_RF_NONE = 0, | ||
111 | |||
112 | /** | ||
113 | * This is a private record of this peer and it should | ||
114 | * thus not be handed out to other peers. | ||
115 | */ | ||
116 | GNUNET_NAMESTORE_RF_PRIVATE = 2, | ||
117 | |||
118 | /** | ||
119 | * This record was added automatically by the system | ||
120 | * and is pending user confimation. | ||
121 | */ | ||
122 | GNUNET_NAMESTORE_RF_PENDING = 4, | ||
123 | |||
124 | /** | ||
125 | * This expiration time of the record is a relative | ||
126 | * time (not an absolute time). | ||
127 | */ | ||
128 | GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION = 8, | ||
129 | |||
130 | /** | ||
131 | * This record should not be used unless all (other) records with an absolute | ||
132 | * expiration time have expired. | ||
133 | */ | ||
134 | GNUNET_NAMESTORE_RF_SHADOW_RECORD = 16 | ||
135 | |||
136 | /** | ||
137 | * When comparing flags for record equality for removal, | ||
138 | * which flags should must match (in addition to the type, | ||
139 | * name, expiration value and data of the record)? All flags | ||
140 | * that are not listed here will be ignored for this purpose. | ||
141 | * (for example, we don't expect that users will remember to | ||
142 | * pass the '--private' option when removing a record from | ||
143 | * the namestore, hence we don't require this particular option | ||
144 | * to match upon removal). See also | ||
145 | * #GNUNET_NAMESTORE_records_cmp. | ||
146 | */ | ||
147 | #define GNUNET_NAMESTORE_RF_RCMP_FLAGS (GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION) | ||
148 | }; | ||
149 | |||
150 | |||
151 | /** | ||
152 | * A GNS record. | ||
153 | */ | ||
154 | struct GNUNET_NAMESTORE_RecordData | ||
155 | { | ||
156 | |||
157 | /** | ||
158 | * Binary value stored in the DNS record. Note: "data" must never | ||
159 | * be individually 'malloc'ed, but instead always points into some | ||
160 | * existing data area. | ||
161 | */ | ||
162 | const void *data; | ||
163 | |||
164 | /** | ||
165 | * Expiration time for the DNS record. Can be relative | ||
166 | * or absolute, depending on 'flags'. Measured in the same | ||
167 | * unit as GNUnet time (microseconds). | ||
168 | */ | ||
169 | uint64_t expiration_time; | ||
170 | |||
171 | /** | ||
172 | * Number of bytes in 'data'. | ||
173 | */ | ||
174 | size_t data_size; | ||
175 | |||
176 | /** | ||
177 | * Type of the GNS/DNS record. | ||
178 | */ | ||
179 | uint32_t record_type; | ||
180 | |||
181 | /** | ||
182 | * Flags for the record. | ||
183 | */ | ||
184 | enum GNUNET_NAMESTORE_RecordFlags flags; | ||
185 | }; | ||
186 | |||
187 | |||
188 | |||
189 | GNUNET_NETWORK_STRUCT_BEGIN | ||
190 | |||
191 | |||
192 | /** | ||
193 | * Information we have in an encrypted block with record data (i.e. in the DHT). | ||
194 | */ | ||
195 | struct GNUNET_NAMESTORE_Block | ||
196 | { | ||
197 | |||
198 | /** | ||
199 | * Signature of the block. | ||
200 | */ | ||
201 | struct GNUNET_CRYPTO_EcdsaSignature signature; | ||
202 | |||
203 | /** | ||
204 | * Derived key used for signing; hash of this is the query. | ||
205 | */ | ||
206 | struct GNUNET_CRYPTO_EcdsaPublicKey derived_key; | ||
207 | |||
208 | /** | ||
209 | * Number of bytes signed; also specifies the number of bytes | ||
210 | * of encrypted data that follow. | ||
211 | */ | ||
212 | struct GNUNET_CRYPTO_EccSignaturePurpose purpose; | ||
213 | |||
214 | /** | ||
215 | * Expiration time of the block. | ||
216 | */ | ||
217 | struct GNUNET_TIME_AbsoluteNBO expiration_time; | ||
218 | |||
219 | /* followed by encrypted data */ | ||
220 | }; | ||
221 | |||
222 | |||
223 | |||
224 | GNUNET_NETWORK_STRUCT_END | ||
225 | |||
226 | /** | ||
227 | * Store an item in the namestore. If the item is already present, | 98 | * Store an item in the namestore. If the item is already present, |
228 | * it is replaced with the new record. | 99 | * it is replaced with the new record. |
229 | * | 100 | * |
@@ -329,18 +200,6 @@ GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h, | |||
329 | 200 | ||
330 | 201 | ||
331 | /** | 202 | /** |
332 | * Process a records that were decrypted from a block. | ||
333 | * | ||
334 | * @param cls closure | ||
335 | * @param rd_count number of entries in @a rd array | ||
336 | * @param rd array of records with data to store | ||
337 | */ | ||
338 | typedef void (*GNUNET_NAMESTORE_RecordCallback) (void *cls, | ||
339 | unsigned int rd_count, | ||
340 | const struct GNUNET_NAMESTORE_RecordData *rd); | ||
341 | |||
342 | |||
343 | /** | ||
344 | * Cancel a namestore operation. The final callback from the | 203 | * Cancel a namestore operation. The final callback from the |
345 | * operation must not have been done yet. Must be called on any | 204 | * operation must not have been done yet. Must be called on any |
346 | * namestore operation that has not yet completed prior to calling | 205 | * namestore operation that has not yet completed prior to calling |
@@ -445,211 +304,6 @@ void | |||
445 | GNUNET_NAMESTORE_zone_monitor_stop (struct GNUNET_NAMESTORE_ZoneMonitor *zm); | 304 | GNUNET_NAMESTORE_zone_monitor_stop (struct GNUNET_NAMESTORE_ZoneMonitor *zm); |
446 | 305 | ||
447 | 306 | ||
448 | /* convenience APIs for serializing / deserializing GNS records */ | ||
449 | |||
450 | /** | ||
451 | * Calculate how many bytes we will need to serialize the given | ||
452 | * records. | ||
453 | * | ||
454 | * @param rd_count number of records in the @a rd array | ||
455 | * @param rd array of #GNUNET_NAMESTORE_RecordData with @a rd_count elements | ||
456 | * @return the required size to serialize | ||
457 | */ | ||
458 | size_t | ||
459 | GNUNET_NAMESTORE_records_get_size (unsigned int rd_count, | ||
460 | const struct GNUNET_NAMESTORE_RecordData *rd); | ||
461 | |||
462 | |||
463 | /** | ||
464 | * Serialize the given records to the given destination buffer. | ||
465 | * | ||
466 | * @param rd_count number of records in the @a rd array | ||
467 | * @param rd array of #GNUNET_NAMESTORE_RecordData with @a rd_count elements | ||
468 | * @param dest_size size of the destination array @a dst | ||
469 | * @param dest where to write the result | ||
470 | * @return the size of serialized records, -1 if records do not fit | ||
471 | */ | ||
472 | ssize_t | ||
473 | GNUNET_NAMESTORE_records_serialize (unsigned int rd_count, | ||
474 | const struct GNUNET_NAMESTORE_RecordData *rd, | ||
475 | size_t dest_size, | ||
476 | char *dest); | ||
477 | |||
478 | |||
479 | /** | ||
480 | * Deserialize the given records to the given destination. | ||
481 | * | ||
482 | * @param len size of the serialized record data | ||
483 | * @param src the serialized record data | ||
484 | * @param rd_count number of records in the @a dest array | ||
485 | * @param dest where to put the data | ||
486 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
487 | */ | ||
488 | int | ||
489 | GNUNET_NAMESTORE_records_deserialize (size_t len, | ||
490 | const char *src, | ||
491 | unsigned int rd_count, | ||
492 | struct GNUNET_NAMESTORE_RecordData *dest); | ||
493 | |||
494 | |||
495 | /** | ||
496 | * Test if a given record is expired. | ||
497 | * | ||
498 | * @param rd record to test | ||
499 | * @return #GNUNET_YES if the record is expired, | ||
500 | * #GNUNET_NO if not | ||
501 | */ | ||
502 | int | ||
503 | GNUNET_NAMESTORE_is_expired (const struct GNUNET_NAMESTORE_RecordData *rd); | ||
504 | |||
505 | |||
506 | /** | ||
507 | * Convert a UTF-8 string to UTF-8 lowercase | ||
508 | * @param src source string | ||
509 | * @return converted result | ||
510 | */ | ||
511 | char * | ||
512 | GNUNET_NAMESTORE_normalize_string (const char *src); | ||
513 | |||
514 | |||
515 | /** | ||
516 | * Convert a zone to a string (for printing debug messages). | ||
517 | * This is one of the very few calls in the entire API that is | ||
518 | * NOT reentrant! | ||
519 | * | ||
520 | * @param z public key of a zone | ||
521 | * @return string form; will be overwritten by next call to #GNUNET_NAMESTORE_z2s. | ||
522 | */ | ||
523 | const char * | ||
524 | GNUNET_NAMESTORE_z2s (const struct GNUNET_CRYPTO_EcdsaPublicKey *z); | ||
525 | |||
526 | |||
527 | /** | ||
528 | * Convert public key to the respective absolute domain name in the | ||
529 | * ".zkey" pTLD. | ||
530 | * This is one of the very few calls in the entire API that is | ||
531 | * NOT reentrant! | ||
532 | * | ||
533 | * @param pkey a public key with a point on the eliptic curve | ||
534 | * @return string "X.zkey" where X is the coordinates of the public | ||
535 | * key in an encoding suitable for DNS labels. | ||
536 | */ | ||
537 | const char * | ||
538 | GNUNET_NAMESTORE_pkey_to_zkey (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey); | ||
539 | |||
540 | |||
541 | /** | ||
542 | * Convert an absolute domain name in the ".zkey" pTLD to the | ||
543 | * respective public key. | ||
544 | * | ||
545 | * @param zkey string "X.zkey" where X is the public | ||
546 | * key in an encoding suitable for DNS labels. | ||
547 | * @param pkey set to a public key on the eliptic curve | ||
548 | * @return #GNUNET_SYSERR if @a zkey has the wrong syntax | ||
549 | */ | ||
550 | int | ||
551 | GNUNET_NAMESTORE_zkey_to_pkey (const char *zkey, | ||
552 | struct GNUNET_CRYPTO_EcdsaPublicKey *pkey); | ||
553 | |||
554 | |||
555 | /** | ||
556 | * Calculate the DHT query for a given @a label in a given @a zone. | ||
557 | * | ||
558 | * @param zone private key of the zone | ||
559 | * @param label label of the record | ||
560 | * @param query hash to use for the query | ||
561 | */ | ||
562 | void | ||
563 | GNUNET_NAMESTORE_query_from_private_key (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | ||
564 | const char *label, | ||
565 | struct GNUNET_HashCode *query); | ||
566 | |||
567 | |||
568 | /** | ||
569 | * Calculate the DHT query for a given @a label in a given @a zone. | ||
570 | * | ||
571 | * @param pub public key of the zone | ||
572 | * @param label label of the record | ||
573 | * @param query hash to use for the query | ||
574 | */ | ||
575 | void | ||
576 | GNUNET_NAMESTORE_query_from_public_key (const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, | ||
577 | const char *label, | ||
578 | struct GNUNET_HashCode *query); | ||
579 | |||
580 | |||
581 | /** | ||
582 | * Sign name and records | ||
583 | * | ||
584 | * @param key the private key | ||
585 | * @param expire block expiration | ||
586 | * @param label the name for the records | ||
587 | * @param rd record data | ||
588 | * @param rd_count number of records in @a rd | ||
589 | */ | ||
590 | struct GNUNET_NAMESTORE_Block * | ||
591 | GNUNET_NAMESTORE_block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | ||
592 | struct GNUNET_TIME_Absolute expire, | ||
593 | const char *label, | ||
594 | const struct GNUNET_NAMESTORE_RecordData *rd, | ||
595 | unsigned int rd_count); | ||
596 | |||
597 | |||
598 | /** | ||
599 | * Check if a signature is valid. This API is used by the GNS Block | ||
600 | * to validate signatures received from the network. | ||
601 | * | ||
602 | * @param block block to verify | ||
603 | * @return #GNUNET_OK if the signature is valid | ||
604 | */ | ||
605 | int | ||
606 | GNUNET_NAMESTORE_block_verify (const struct GNUNET_NAMESTORE_Block *block); | ||
607 | |||
608 | |||
609 | /** | ||
610 | * Decrypt block. | ||
611 | * | ||
612 | * @param block block to decrypt | ||
613 | * @param zone_key public key of the zone | ||
614 | * @param label the name for the records | ||
615 | * @param proc function to call with the result | ||
616 | * @param proc_cls closure for @a proc | ||
617 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the block was | ||
618 | * not well-formed | ||
619 | */ | ||
620 | int | ||
621 | GNUNET_NAMESTORE_block_decrypt (const struct GNUNET_NAMESTORE_Block *block, | ||
622 | const struct GNUNET_CRYPTO_EcdsaPublicKey *zone_key, | ||
623 | const char *label, | ||
624 | GNUNET_NAMESTORE_RecordCallback proc, | ||
625 | void *proc_cls); | ||
626 | |||
627 | |||
628 | /** | ||
629 | * Compares if two records are equal | ||
630 | * | ||
631 | * @param a a record | ||
632 | * @param b another record | ||
633 | * @return #GNUNET_YES if the records are equal, or #GNUNET_NO if not. | ||
634 | */ | ||
635 | int | ||
636 | GNUNET_NAMESTORE_records_cmp (const struct GNUNET_NAMESTORE_RecordData *a, | ||
637 | const struct GNUNET_NAMESTORE_RecordData *b); | ||
638 | |||
639 | |||
640 | /** | ||
641 | * Returns the expiration time of the given block of records. The block | ||
642 | * expiration time is the expiration time of the record with smallest | ||
643 | * expiration time. | ||
644 | * | ||
645 | * @param rd_count number of records given in @a rd | ||
646 | * @param rd array of records | ||
647 | * @return absolute expiration time | ||
648 | */ | ||
649 | struct GNUNET_TIME_Absolute | ||
650 | GNUNET_NAMESTORE_record_get_expiration_time (unsigned int rd_count, | ||
651 | const struct GNUNET_NAMESTORE_RecordData *rd); | ||
652 | |||
653 | 307 | ||
654 | #if 0 /* keep Emacsens' auto-indent happy */ | 308 | #if 0 /* keep Emacsens' auto-indent happy */ |
655 | { | 309 | { |