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