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