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