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