-consistently use struct GNUNET_HashCode
[oweals/gnunet.git] / src / namestore / namestore.h
1 /*
2      This file is part of GNUnet.
3      (C) 2009 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19 */
20
21 /**
22  * @file namestore/namestore.h
23  * @brief common internal definitions for namestore service
24  * @author Matthias Wachs
25  */
26 #ifndef NAMESTORE_H
27 #define NAMESTORE_H
28
29 /*
30  * Collect message types here, move to protocols later
31  */
32 #define GNUNET_MESSAGE_TYPE_NAMESTORE_START 430
33 #define GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME 431
34 #define GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE 432
35 #define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT 433
36 #define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE 434
37 #define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE 435
38 #define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE 436
39 #define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE 437
40 #define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE 438
41 #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME 439
42 #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE 440
43
44 #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START 445
45 #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE 446
46 #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT 447
47 #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP 448
48
49
50 /**
51  * Convert a short hash to a string (for printing debug messages).
52  * This is one of the very few calls in the entire API that is
53  * NOT reentrant!
54  *
55  * @param hc the short hash code
56  * @return string form; will be overwritten by next call to GNUNET_h2s.
57  */
58 const char *
59 GNUNET_short_h2s (const struct GNUNET_CRYPTO_ShortHashCode * hc);
60
61
62 /**
63  * Sign name and records
64  *
65  * @param key the private key
66  * @param expire block expiration
67  * @param name the name
68  * @param rd record data
69  * @param rd_count number of records
70  *
71  * @return the signature
72  */
73 struct GNUNET_CRYPTO_RsaSignature *
74 GNUNET_NAMESTORE_create_signature (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
75     struct GNUNET_TIME_Absolute expire,
76     const char *name,
77     const struct GNUNET_NAMESTORE_RecordData *rd,
78     unsigned int rd_count);
79
80
81 /**
82  * Compares if two records are equal
83  *
84  * @param a Record a
85  * @param b Record b
86  *
87  * @return GNUNET_YES or GNUNET_NO
88  */
89 int
90 GNUNET_NAMESTORE_records_cmp (const struct GNUNET_NAMESTORE_RecordData *a,
91                               const struct GNUNET_NAMESTORE_RecordData *b);
92
93
94 GNUNET_NETWORK_STRUCT_BEGIN
95 /**
96  * A GNS record serialized for network transmission.
97  *
98  * Layout is [struct GNUNET_NAMESTORE_NetworkRecord][char[data_size] data]
99  */
100 struct GNUNET_NAMESTORE_NetworkRecord
101 {
102   /**
103    * Expiration time for the DNS record.
104    */
105   struct GNUNET_TIME_AbsoluteNBO expiration;
106
107   /**
108    * Number of bytes in 'data'.
109    */
110   uint32_t data_size;
111
112   /**
113    * Type of the GNS/DNS record.
114    */
115   uint32_t record_type;
116
117   /**
118    * Flags for the record.
119    */
120   uint32_t flags;
121 };
122
123
124
125 /**
126  * Connect to namestore service.  FIXME: UNNECESSARY.
127  */
128 struct StartMessage
129 {
130
131   /**
132    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_START
133    */
134   struct GNUNET_MessageHeader header;
135
136 };
137
138
139 /**
140  * Generic namestore message with op id
141  */
142 struct GNUNET_NAMESTORE_Header
143 {
144   /**
145    * header.type will be GNUNET_MESSAGE_TYPE_NAMESTORE_*
146    * header.size will be message size
147    */
148   struct GNUNET_MessageHeader header;
149
150   /**
151    * Request ID in NBO
152    */
153   uint32_t r_id;
154 };
155
156
157 /**
158  * Lookup a name in the namestore
159  */
160 struct LookupNameMessage
161 {
162   struct GNUNET_NAMESTORE_Header gns_header;
163
164   /**
165    * The zone 
166    */
167   struct GNUNET_CRYPTO_ShortHashCode zone;
168
169   /**
170    * Requested record type 
171    */
172   uint32_t record_type;
173
174   /**
175    * Length of the name
176    */
177   uint32_t name_len;
178
179   /* 0-terminated name here */
180 };
181
182
183 /**
184  * Lookup response
185  */
186 struct LookupNameResponseMessage
187 {
188   /**
189    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE
190    */
191   struct GNUNET_NAMESTORE_Header gns_header;
192
193   /**
194    * Expiration time
195    */
196   struct GNUNET_TIME_AbsoluteNBO expire;
197
198
199   /**
200    * Name length
201    */
202   uint16_t name_len;
203
204   /**
205    * Bytes of serialized record data
206    */
207   uint16_t rd_len;
208
209   /**
210    * Number of records contained
211    */
212   uint16_t rd_count;
213
214   /**
215    * Is the signature valid
216    * GNUNET_YES or GNUNET_NO
217    */
218   int16_t contains_sig;
219
220   /**
221    * All zeros if 'contains_sig' is GNUNET_NO.
222    */
223   struct GNUNET_CRYPTO_RsaSignature signature;
224
225   /**
226    * The public key for the name
227    */
228   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
229
230   /* 0-terminated name and serialized record data */
231   /* rd_len bytes serialized record data */
232 };
233
234
235 /**
236  * Put a record to the namestore
237  */
238 struct RecordPutMessage
239 {
240   /**
241    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_RECORD_PUT
242    */
243   struct GNUNET_NAMESTORE_Header gns_header;
244
245   /**
246    * Expiration time
247    */
248   struct GNUNET_TIME_AbsoluteNBO expire;
249
250   /**
251    * Name length
252    */
253   uint16_t name_len;
254
255   /**
256    * Length of serialized record data
257    */
258   uint16_t rd_len;
259
260   /**
261    * Number of records contained 
262    */
263   uint16_t rd_count;
264
265   /**
266    * always zero (for alignment)
267    */
268   uint16_t reserved;
269
270   /**
271    * The signature
272    */
273   struct GNUNET_CRYPTO_RsaSignature signature;
274
275   /**
276    * The public key
277    */
278   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
279
280   /* name (0-terminated) followed by "rd_count" serialized records */
281
282 };
283
284
285 /**
286  * Put a record to the namestore response
287  */
288 struct RecordPutResponseMessage
289 {
290   /**
291    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE
292    */
293   struct GNUNET_NAMESTORE_Header gns_header;
294
295   /**
296    * result:
297    * GNUNET_SYSERR on failure
298    * GNUNET_OK on success
299    */
300   int32_t op_result;
301 };
302
303
304 /**
305  * Create a record and put it to the namestore
306  * Memory layout:
307  */
308 struct RecordCreateMessage
309 {
310   /**
311    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE
312    */
313   struct GNUNET_NAMESTORE_Header gns_header;
314
315   struct GNUNET_TIME_AbsoluteNBO expire;
316
317   /**
318    * Name length
319    */
320   uint16_t name_len;
321
322   /**
323    * Length of serialized record data
324    */
325   uint16_t rd_len;
326
327   /**
328    * Record count 
329    */
330   uint16_t rd_count;
331
332   /**
333    * private key length 
334    */
335   uint16_t pkey_len;
336
337   /* followed by:
338    * GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded private key with length pkey_len
339    * name with length name_len
340    * serialized record data with length rd_len
341    * */
342 };
343
344
345 /**
346  * Create a record to the namestore response
347  */
348 struct RecordCreateResponseMessage
349 {
350   /**
351    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE
352    */
353   struct GNUNET_NAMESTORE_Header gns_header;
354
355   /**
356    *  name length: GNUNET_NO already exists, GNUNET_YES on success, GNUNET_SYSERR error
357    */
358   int32_t op_result;
359 };
360
361
362 /**
363  * Remove a record from the namestore
364  * Memory layout:
365  */
366 struct RecordRemoveMessage
367 {
368   /**
369    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE
370    */
371   struct GNUNET_NAMESTORE_Header gns_header;
372
373   /**
374    * Name length 
375    */
376   uint16_t name_len;
377
378   /**
379    * Length of serialized rd data 
380    */
381   uint16_t rd_len;
382
383   /**
384    * Number of records contained 
385    */
386   uint16_t rd_count;
387
388   /**
389    * Length of private key
390    */
391   uint16_t pkey_len;
392
393   /* followed by:
394    * GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded private key with length pkey_len
395    * name with length name_len
396    * serialized record data with length rd_len
397    * */
398 };
399
400
401 /**
402  * Remove a record from the namestore response
403  */
404 struct RecordRemoveResponseMessage
405 {
406   /**
407    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE
408    */
409   struct GNUNET_NAMESTORE_Header gns_header;
410
411   /**
412    *  result:
413    *  0 : successful
414    *  1 : no records for entry
415    *  2 : Could not find record to remove
416    *  3 : Failed to create new signature
417    *  4 : Failed to put new set of records in database
418    */
419   int32_t op_result;
420 };
421
422
423 /**
424  * Lookup a name for a zone hash
425  */
426 struct ZoneToNameMessage
427 {
428   /**
429    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME
430    */
431   struct GNUNET_NAMESTORE_Header gns_header;
432
433   /**
434    * The hash of public key of the zone to look up in 
435    */
436   struct GNUNET_CRYPTO_ShortHashCode zone;
437
438   /**
439    * The  hash of the public key of the target zone  
440    */
441   struct GNUNET_CRYPTO_ShortHashCode value_zone;
442 };
443
444 /**
445  * Respone for zone to name lookup
446  */
447 struct ZoneToNameResponseMessage
448 {
449   /**
450    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE
451    */
452   struct GNUNET_NAMESTORE_Header gns_header;
453
454   /**
455    * Record block expiration
456    */
457   struct GNUNET_TIME_AbsoluteNBO expire;
458
459   /**
460    * Length of the name
461    */
462   uint16_t name_len;
463
464   /**
465    * Length of serialized record data
466    */
467   uint16_t rd_len;
468
469   /**
470    * Number of records contained
471    */
472   uint16_t rd_count;
473
474   /* result in NBO: GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error */
475   int16_t res;
476
477   /**
478    * Signature
479    */
480   struct GNUNET_CRYPTO_RsaSignature signature;
481
482   /**
483    * Publik key
484    */
485   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded zone_key;
486
487 };
488
489
490
491 /**
492  * Start a zone iteration for the given zone
493  */
494 struct ZoneIterationStartMessage
495 {
496   /**
497    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START
498    */
499   struct GNUNET_NAMESTORE_Header gns_header;
500
501   /**
502    * Zone hash
503    */
504   struct GNUNET_CRYPTO_ShortHashCode zone;
505
506   /**
507    * Which flags must be included
508    */
509   uint16_t must_have_flags;
510
511   /**
512    * Which flags must not be included
513    */
514   uint16_t must_not_have_flags;
515 };
516
517
518 /**
519  * Ask for next result of zone iteration for the given operation
520  */
521 struct ZoneIterationNextMessage
522 {
523   /**
524    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT
525    */
526   struct GNUNET_NAMESTORE_Header gns_header;
527 };
528
529
530 /**
531  * Stop zone iteration for the given operation
532  */
533 struct ZoneIterationStopMessage
534 {
535   /**
536    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP
537    */
538   struct GNUNET_NAMESTORE_Header gns_header;
539 };
540
541 /**
542  * Next result of zone iteration for the given operation
543  * // FIXME: use 'struct LookupResponseMessage' instead? (identical except
544  * for having 'contains_sig' instead of 'reserved', but fully compatible otherwise).
545  */
546 struct ZoneIterationResponseMessage
547 {
548   /**
549    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE
550    */
551   struct GNUNET_NAMESTORE_Header gns_header;
552
553   struct GNUNET_TIME_AbsoluteNBO expire;
554
555   uint16_t name_len;
556
557   /* Record data length */
558   uint16_t rd_len;
559
560   /**
561    * Number of records contained 
562    */
563   uint16_t rd_count;
564
565   /**
566    * always zero (for alignment)
567    */
568   uint16_t reserved;
569
570   /**
571    * All zeros if 'contains_sig' is GNUNET_NO.
572    */
573   struct GNUNET_CRYPTO_RsaSignature signature;
574
575   /**
576    * The public key
577    */
578   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
579
580  
581  
582 };
583 GNUNET_NETWORK_STRUCT_END
584
585
586 /* end of namestore.h */
587 #endif