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
37 * Collect message types here, move to protocols later
39 #define GNUNET_MESSAGE_TYPE_NAMESTORE_START 430
40 #define GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME 431
41 #define GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE 432
42 #define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT 433
43 #define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE 434
44 #define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE 435
45 #define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE 436
46 #define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE 437
47 #define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE 438
48 #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME 439
49 #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE 440
51 #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START 445
52 #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE 446
53 #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT 447
54 #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP 448
58 * Convert a short hash to a string (for printing debug messages).
59 * This is one of the very few calls in the entire API that is
62 * @param hc the short hash code
63 * @return string form; will be overwritten by next call to GNUNET_h2s.
66 GNUNET_short_h2s (const struct GNUNET_CRYPTO_ShortHashCode * hc);
70 * Sign name and records
72 * @param key the private key
73 * @param expire block expiration
74 * @param name the name
75 * @param rd record data
76 * @param rd_count number of records
78 * @return the signature
80 struct GNUNET_CRYPTO_RsaSignature *
81 GNUNET_NAMESTORE_create_signature (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
82 struct GNUNET_TIME_Absolute expire,
84 const struct GNUNET_NAMESTORE_RecordData *rd,
85 unsigned int rd_count);
89 * Compares if two records are equal
94 * @return GNUNET_YES or GNUNET_NO
97 GNUNET_NAMESTORE_records_cmp (const struct GNUNET_NAMESTORE_RecordData *a,
98 const struct GNUNET_NAMESTORE_RecordData *b);
101 GNUNET_NETWORK_STRUCT_BEGIN
103 * A GNS record serialized for network transmission.
105 * Layout is [struct GNUNET_NAMESTORE_NetworkRecord][char[data_size] data]
107 struct GNUNET_NAMESTORE_NetworkRecord
110 * Expiration time for the DNS record.
112 struct GNUNET_TIME_AbsoluteNBO expiration;
115 * Number of bytes in 'data'.
120 * Type of the GNS/DNS record.
122 uint32_t record_type;
125 * Flags for the record.
133 * Connect to namestore service. FIXME: UNNECESSARY.
139 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_START
141 struct GNUNET_MessageHeader header;
147 * Generic namestore message with op id
149 struct GNUNET_NAMESTORE_Header
152 * header.type will be GNUNET_MESSAGE_TYPE_NAMESTORE_*
153 * header.size will be message size
155 struct GNUNET_MessageHeader header;
165 * Lookup a name in the namestore
167 struct LookupNameMessage
169 struct GNUNET_NAMESTORE_Header gns_header;
174 struct GNUNET_CRYPTO_ShortHashCode zone;
177 * Requested record type
179 uint32_t record_type;
186 /* 0-terminated name here */
193 struct LookupNameResponseMessage
196 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE
198 struct GNUNET_NAMESTORE_Header gns_header;
203 struct GNUNET_TIME_AbsoluteNBO expire;
212 * Bytes of serialized record data
217 * Number of records contained
222 * Is the signature valid
223 * GNUNET_YES or GNUNET_NO
225 int16_t contains_sig;
228 * All zeros if 'contains_sig' is GNUNET_NO.
230 struct GNUNET_CRYPTO_RsaSignature signature;
233 * The public key for the name
235 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
237 /* 0-terminated name and serialized record data */
238 /* rd_len bytes serialized record data */
243 * Put a record to the namestore
245 struct RecordPutMessage
248 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_RECORD_PUT
250 struct GNUNET_NAMESTORE_Header gns_header;
255 struct GNUNET_TIME_AbsoluteNBO expire;
263 * Length of serialized record data
268 * Number of records contained
273 * always zero (for alignment)
280 struct GNUNET_CRYPTO_RsaSignature signature;
285 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
287 /* name (0-terminated) followed by "rd_count" serialized records */
293 * Put a record to the namestore response
295 struct RecordPutResponseMessage
298 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE
300 struct GNUNET_NAMESTORE_Header gns_header;
304 * GNUNET_SYSERR on failure
305 * GNUNET_OK on success
312 * Create a record and put it to the namestore
315 struct RecordCreateMessage
318 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE
320 struct GNUNET_NAMESTORE_Header gns_header;
322 struct GNUNET_TIME_AbsoluteNBO expire;
330 * Length of serialized record data
345 * GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded private key with length pkey_len
346 * name with length name_len
347 * serialized record data with length rd_len
353 * Create a record to the namestore response
355 struct RecordCreateResponseMessage
358 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE
360 struct GNUNET_NAMESTORE_Header gns_header;
363 * name length: GNUNET_NO already exists, GNUNET_YES on success, GNUNET_SYSERR error
370 * Remove a record from the namestore
373 struct RecordRemoveMessage
376 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE
378 struct GNUNET_NAMESTORE_Header gns_header;
386 * Length of serialized rd data
391 * Number of records contained
396 * Length of private key
401 * GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded private key with length pkey_len
402 * name with length name_len
403 * serialized record data with length rd_len
409 * Removal of the record succeeded.
411 #define RECORD_REMOVE_RESULT_SUCCESS 0
414 * There are NO records for the given name.
416 #define RECORD_REMOVE_RESULT_NO_RECORDS 1
419 * The specific record that was to be removed was
422 #define RECORD_REMOVE_RESULT_RECORD_NOT_FOUND 2
425 * Internal error, failed to sign the remaining records.
428 #define RECORD_REMOVE_RESULT_FAILED_TO_SIGN 3
431 * Internal error, failed to store the updated record set
433 #define RECORD_REMOVE_RESULT_FAILED_TO_PUT_UPDATE 4
436 * Internal error, failed to remove records from database
438 #define RECORD_REMOVE_RESULT_FAILED_TO_REMOVE 5
441 * Internal error, failed to access database
443 #define RECORD_REMOVE_RESULT_FAILED_ACCESS_DATABASE 6
446 * Internal error, failed to access database
448 #define RECORD_REMOVE_RESULT_FAILED_INTERNAL_ERROR 7
452 * Remove a record from the namestore response
454 struct RecordRemoveResponseMessage
457 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE
459 struct GNUNET_NAMESTORE_Header gns_header;
462 * Result code (see RECORD_REMOVE_RESULT_*). In network byte order.
469 * Lookup a name for a zone hash
471 struct ZoneToNameMessage
474 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME
476 struct GNUNET_NAMESTORE_Header gns_header;
479 * The hash of public key of the zone to look up in
481 struct GNUNET_CRYPTO_ShortHashCode zone;
484 * The hash of the public key of the target zone
486 struct GNUNET_CRYPTO_ShortHashCode value_zone;
490 * Respone for zone to name lookup
492 struct ZoneToNameResponseMessage
495 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE
497 struct GNUNET_NAMESTORE_Header gns_header;
500 * Record block expiration
502 struct GNUNET_TIME_AbsoluteNBO expire;
510 * Length of serialized record data
515 * Number of records contained
519 /* result in NBO: GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error */
525 struct GNUNET_CRYPTO_RsaSignature signature;
530 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded zone_key;
537 * Start a zone iteration for the given zone
539 struct ZoneIterationStartMessage
542 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START
544 struct GNUNET_NAMESTORE_Header gns_header;
549 struct GNUNET_CRYPTO_ShortHashCode zone;
552 * Which flags must be included
554 uint16_t must_have_flags;
557 * Which flags must not be included
559 uint16_t must_not_have_flags;
564 * Ask for next result of zone iteration for the given operation
566 struct ZoneIterationNextMessage
569 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT
571 struct GNUNET_NAMESTORE_Header gns_header;
576 * Stop zone iteration for the given operation
578 struct ZoneIterationStopMessage
581 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP
583 struct GNUNET_NAMESTORE_Header gns_header;
587 * Next result of zone iteration for the given operation
588 * // FIXME: use 'struct LookupResponseMessage' instead? (identical except
589 * for having 'contains_sig' instead of 'reserved', but fully compatible otherwise).
591 struct ZoneIterationResponseMessage
594 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE
596 struct GNUNET_NAMESTORE_Header gns_header;
598 struct GNUNET_TIME_AbsoluteNBO expire;
602 /* Record data length */
606 * Number of records contained
611 * always zero (for alignment)
616 * All zeros if 'contains_sig' is GNUNET_NO.
618 struct GNUNET_CRYPTO_RsaSignature signature;
623 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
628 GNUNET_NETWORK_STRUCT_END
631 /* end of namestore.h */