2 This file is part of GNUnet.
3 (C) 2009 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 3, 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 namestore/namestore.h
23 * @brief common internal definitions for namestore service
24 * @author Matthias Wachs
30 * Maximum length of any name, including 0-termination.
32 #define MAX_NAME_LEN 256
35 * Convert a UTF-8 string to UTF-8 lowercase
36 * @param src source string
37 * @return converted result
40 GNUNET_NAMESTORE_normalize_string (const char *src);
43 * Convert a short hash to a string (for printing debug messages).
44 * This is one of the very few calls in the entire API that is
47 * @param hc the short hash code
48 * @return string form; will be overwritten by next call to GNUNET_h2s.
51 GNUNET_short_h2s (const struct GNUNET_CRYPTO_ShortHashCode * hc);
55 * Sign name and records
57 * @param key the private key
58 * @param expire block expiration
59 * @param name the name
60 * @param rd record data
61 * @param rd_count number of records
63 * @return the signature
65 struct GNUNET_CRYPTO_RsaSignature *
66 GNUNET_NAMESTORE_create_signature (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
67 struct GNUNET_TIME_Absolute expire,
69 const struct GNUNET_NAMESTORE_RecordData *rd,
70 unsigned int rd_count);
74 * Compares if two records are equal
79 * @return GNUNET_YES or GNUNET_NO
82 GNUNET_NAMESTORE_records_cmp (const struct GNUNET_NAMESTORE_RecordData *a,
83 const struct GNUNET_NAMESTORE_RecordData *b);
86 GNUNET_NETWORK_STRUCT_BEGIN
88 * A GNS record serialized for network transmission.
90 * Layout is [struct GNUNET_NAMESTORE_NetworkRecord][char[data_size] data]
92 struct GNUNET_NAMESTORE_NetworkRecord
95 * Expiration time for the DNS record.
97 struct GNUNET_TIME_AbsoluteNBO expiration;
100 * Number of bytes in 'data'.
105 * Type of the GNS/DNS record.
107 uint32_t record_type;
110 * Flags for the record.
118 * Connect to namestore service. FIXME: UNNECESSARY.
124 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_START
126 struct GNUNET_MessageHeader header;
132 * Generic namestore message with op id
134 struct GNUNET_NAMESTORE_Header
137 * header.type will be GNUNET_MESSAGE_TYPE_NAMESTORE_*
138 * header.size will be message size
140 struct GNUNET_MessageHeader header;
150 * Lookup a name in the namestore
152 struct LookupNameMessage
154 struct GNUNET_NAMESTORE_Header gns_header;
159 struct GNUNET_CRYPTO_ShortHashCode zone;
162 * Requested record type
164 uint32_t record_type;
171 /* 0-terminated name here */
178 struct LookupNameResponseMessage
181 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE
183 struct GNUNET_NAMESTORE_Header gns_header;
188 struct GNUNET_TIME_AbsoluteNBO expire;
197 * Bytes of serialized record data
202 * Number of records contained
207 * Is the signature valid
208 * GNUNET_YES or GNUNET_NO
210 int16_t contains_sig;
213 * All zeros if 'contains_sig' is GNUNET_NO.
215 struct GNUNET_CRYPTO_RsaSignature signature;
218 * The public key for the name
220 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
222 /* 0-terminated name and serialized record data */
223 /* rd_len bytes serialized record data */
228 * Put a record to the namestore
230 struct RecordPutMessage
233 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_RECORD_PUT
235 struct GNUNET_NAMESTORE_Header gns_header;
240 struct GNUNET_TIME_AbsoluteNBO expire;
248 * Length of serialized record data
253 * Number of records contained
258 * always zero (for alignment)
265 struct GNUNET_CRYPTO_RsaSignature signature;
270 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
272 /* name (0-terminated) followed by "rd_count" serialized records */
278 * Put a record to the namestore response
280 struct RecordPutResponseMessage
283 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE
285 struct GNUNET_NAMESTORE_Header gns_header;
289 * GNUNET_SYSERR on failure
290 * GNUNET_OK on success
297 * Create a record and put it to the namestore
300 struct RecordCreateMessage
303 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE
305 struct GNUNET_NAMESTORE_Header gns_header;
307 struct GNUNET_TIME_AbsoluteNBO expire;
315 * Length of serialized record data
330 * GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded private key with length pkey_len
331 * name with length name_len
332 * serialized record data with length rd_len
338 * Create a record to the namestore response
340 struct RecordCreateResponseMessage
343 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE
345 struct GNUNET_NAMESTORE_Header gns_header;
348 * name length: GNUNET_NO already exists, GNUNET_YES on success, GNUNET_SYSERR error
355 * Remove a record from the namestore
358 struct RecordRemoveMessage
361 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE
363 struct GNUNET_NAMESTORE_Header gns_header;
371 * Length of serialized rd data
376 * Number of records contained
381 * Length of private key
386 * GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded private key with length pkey_len
387 * name with length name_len
388 * serialized record data with length rd_len
394 * Removal of the record succeeded.
396 #define RECORD_REMOVE_RESULT_SUCCESS 0
399 * There are NO records for the given name.
401 #define RECORD_REMOVE_RESULT_NO_RECORDS 1
404 * The specific record that was to be removed was
407 #define RECORD_REMOVE_RESULT_RECORD_NOT_FOUND 2
410 * Internal error, failed to sign the remaining records.
413 #define RECORD_REMOVE_RESULT_FAILED_TO_SIGN 3
416 * Internal error, failed to store the updated record set
418 #define RECORD_REMOVE_RESULT_FAILED_TO_PUT_UPDATE 4
421 * Internal error, failed to remove records from database
423 #define RECORD_REMOVE_RESULT_FAILED_TO_REMOVE 5
426 * Internal error, failed to access database
428 #define RECORD_REMOVE_RESULT_FAILED_ACCESS_DATABASE 6
431 * Internal error, failed to access database
433 #define RECORD_REMOVE_RESULT_FAILED_INTERNAL_ERROR 7
437 * Remove a record from the namestore response
439 struct RecordRemoveResponseMessage
442 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE
444 struct GNUNET_NAMESTORE_Header gns_header;
447 * Result code (see RECORD_REMOVE_RESULT_*). In network byte order.
454 * Lookup a name for a zone hash
456 struct ZoneToNameMessage
459 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME
461 struct GNUNET_NAMESTORE_Header gns_header;
464 * The hash of public key of the zone to look up in
466 struct GNUNET_CRYPTO_ShortHashCode zone;
469 * The hash of the public key of the target zone
471 struct GNUNET_CRYPTO_ShortHashCode value_zone;
475 * Respone for zone to name lookup
477 struct ZoneToNameResponseMessage
480 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE
482 struct GNUNET_NAMESTORE_Header gns_header;
485 * Record block expiration
487 struct GNUNET_TIME_AbsoluteNBO expire;
495 * Length of serialized record data
500 * Number of records contained
504 /* result in NBO: GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error */
510 struct GNUNET_CRYPTO_RsaSignature signature;
515 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded zone_key;
522 * Start a zone iteration for the given zone
524 struct ZoneIterationStartMessage
527 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START
529 struct GNUNET_NAMESTORE_Header gns_header;
534 struct GNUNET_CRYPTO_ShortHashCode zone;
537 * Which flags must be included
539 uint16_t must_have_flags;
542 * Which flags must not be included
544 uint16_t must_not_have_flags;
549 * Ask for next result of zone iteration for the given operation
551 struct ZoneIterationNextMessage
554 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT
556 struct GNUNET_NAMESTORE_Header gns_header;
561 * Stop zone iteration for the given operation
563 struct ZoneIterationStopMessage
566 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP
568 struct GNUNET_NAMESTORE_Header gns_header;
572 * Next result of zone iteration for the given operation
573 * // FIXME: use 'struct LookupResponseMessage' instead? (identical except
574 * for having 'contains_sig' instead of 'reserved', but fully compatible otherwise).
576 struct ZoneIterationResponseMessage
579 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE
581 struct GNUNET_NAMESTORE_Header gns_header;
583 struct GNUNET_TIME_AbsoluteNBO expire;
587 /* Record data length */
591 * Number of records contained
596 * always zero (for alignment)
601 * All zeros if 'contains_sig' is GNUNET_NO.
603 struct GNUNET_CRYPTO_RsaSignature signature;
608 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
613 GNUNET_NETWORK_STRUCT_END
616 /* end of namestore.h */