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