c86a2513b80624d04342fed6d8634a82cb55f19a
[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  * Removal of the record succeeded.
410  */
411 #define RECORD_REMOVE_RESULT_SUCCESS 0
412
413 /**
414  * There are NO records for the given name.
415  */
416 #define RECORD_REMOVE_RESULT_NO_RECORDS 1
417
418 /**
419  * The specific record that was to be removed was
420  * not found.
421  */
422 #define RECORD_REMOVE_RESULT_RECORD_NOT_FOUND 2
423
424 /**
425  * Internal error, failed to sign the remaining records.
426  */
427 #define RECORD_REMOVE_RESULT_FAILED_TO_SIGN 3
428
429 /**
430  * Internal error, failed to store the updated record set
431  */
432 #define RECORD_REMOVE_RESULT_FAILED_TO_PUT_UPDATE 4
433
434 /**
435  * Remove a record from the namestore response
436  */
437 struct RecordRemoveResponseMessage
438 {
439   /**
440    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE
441    */
442   struct GNUNET_NAMESTORE_Header gns_header;
443
444   /**
445    * Result code (see RECORD_REMOVE_RESULT_*).  In network byte order.
446    */
447   int32_t op_result;
448 };
449
450
451 /**
452  * Lookup a name for a zone hash
453  */
454 struct ZoneToNameMessage
455 {
456   /**
457    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME
458    */
459   struct GNUNET_NAMESTORE_Header gns_header;
460
461   /**
462    * The hash of public key of the zone to look up in 
463    */
464   struct GNUNET_CRYPTO_ShortHashCode zone;
465
466   /**
467    * The  hash of the public key of the target zone  
468    */
469   struct GNUNET_CRYPTO_ShortHashCode value_zone;
470 };
471
472 /**
473  * Respone for zone to name lookup
474  */
475 struct ZoneToNameResponseMessage
476 {
477   /**
478    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE
479    */
480   struct GNUNET_NAMESTORE_Header gns_header;
481
482   /**
483    * Record block expiration
484    */
485   struct GNUNET_TIME_AbsoluteNBO expire;
486
487   /**
488    * Length of the name
489    */
490   uint16_t name_len;
491
492   /**
493    * Length of serialized record data
494    */
495   uint16_t rd_len;
496
497   /**
498    * Number of records contained
499    */
500   uint16_t rd_count;
501
502   /* result in NBO: GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error */
503   int16_t res;
504
505   /**
506    * Signature
507    */
508   struct GNUNET_CRYPTO_RsaSignature signature;
509
510   /**
511    * Publik key
512    */
513   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded zone_key;
514
515 };
516
517
518
519 /**
520  * Start a zone iteration for the given zone
521  */
522 struct ZoneIterationStartMessage
523 {
524   /**
525    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START
526    */
527   struct GNUNET_NAMESTORE_Header gns_header;
528
529   /**
530    * Zone hash
531    */
532   struct GNUNET_CRYPTO_ShortHashCode zone;
533
534   /**
535    * Which flags must be included
536    */
537   uint16_t must_have_flags;
538
539   /**
540    * Which flags must not be included
541    */
542   uint16_t must_not_have_flags;
543 };
544
545
546 /**
547  * Ask for next result of zone iteration for the given operation
548  */
549 struct ZoneIterationNextMessage
550 {
551   /**
552    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT
553    */
554   struct GNUNET_NAMESTORE_Header gns_header;
555 };
556
557
558 /**
559  * Stop zone iteration for the given operation
560  */
561 struct ZoneIterationStopMessage
562 {
563   /**
564    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP
565    */
566   struct GNUNET_NAMESTORE_Header gns_header;
567 };
568
569 /**
570  * Next result of zone iteration for the given operation
571  * // FIXME: use 'struct LookupResponseMessage' instead? (identical except
572  * for having 'contains_sig' instead of 'reserved', but fully compatible otherwise).
573  */
574 struct ZoneIterationResponseMessage
575 {
576   /**
577    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE
578    */
579   struct GNUNET_NAMESTORE_Header gns_header;
580
581   struct GNUNET_TIME_AbsoluteNBO expire;
582
583   uint16_t name_len;
584
585   /* Record data length */
586   uint16_t rd_len;
587
588   /**
589    * Number of records contained 
590    */
591   uint16_t rd_count;
592
593   /**
594    * always zero (for alignment)
595    */
596   uint16_t reserved;
597
598   /**
599    * All zeros if 'contains_sig' is GNUNET_NO.
600    */
601   struct GNUNET_CRYPTO_RsaSignature signature;
602
603   /**
604    * The public key
605    */
606   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
607
608  
609  
610 };
611 GNUNET_NETWORK_STRUCT_END
612
613
614 /* end of namestore.h */
615 #endif