-fix message types for namestore, eliminate conflict with LM
[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  * Convert a short hash to a string (for printing debug messages).
36  * This is one of the very few calls in the entire API that is
37  * NOT reentrant!
38  *
39  * @param hc the short hash code
40  * @return string form; will be overwritten by next call to GNUNET_h2s.
41  */
42 const char *
43 GNUNET_short_h2s (const struct GNUNET_CRYPTO_ShortHashCode * hc);
44
45
46 /**
47  * Sign name and records
48  *
49  * @param key the private key
50  * @param expire block expiration
51  * @param name the name
52  * @param rd record data
53  * @param rd_count number of records
54  *
55  * @return the signature
56  */
57 struct GNUNET_CRYPTO_RsaSignature *
58 GNUNET_NAMESTORE_create_signature (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
59     struct GNUNET_TIME_Absolute expire,
60     const char *name,
61     const struct GNUNET_NAMESTORE_RecordData *rd,
62     unsigned int rd_count);
63
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   struct GNUNET_CRYPTO_ShortHashCode 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    * result:
281    * GNUNET_SYSERR on failure
282    * GNUNET_OK on success
283    */
284   int32_t op_result;
285 };
286
287
288 /**
289  * Create a record and put it to the namestore
290  * Memory layout:
291  */
292 struct RecordCreateMessage
293 {
294   /**
295    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE
296    */
297   struct GNUNET_NAMESTORE_Header gns_header;
298
299   struct GNUNET_TIME_AbsoluteNBO expire;
300
301   /**
302    * Name length
303    */
304   uint16_t name_len;
305
306   /**
307    * Length of serialized record data
308    */
309   uint16_t rd_len;
310
311   /**
312    * Record count 
313    */
314   uint16_t rd_count;
315
316   /**
317    * private key length 
318    */
319   uint16_t pkey_len;
320
321   /* followed by:
322    * GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded private key with length pkey_len
323    * name with length name_len
324    * serialized record data with length rd_len
325    * */
326 };
327
328
329 /**
330  * Create a record to the namestore response
331  */
332 struct RecordCreateResponseMessage
333 {
334   /**
335    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE
336    */
337   struct GNUNET_NAMESTORE_Header gns_header;
338
339   /**
340    *  name length: GNUNET_NO already exists, GNUNET_YES on success, GNUNET_SYSERR error
341    */
342   int32_t op_result;
343 };
344
345
346 /**
347  * Remove a record from the namestore
348  * Memory layout:
349  */
350 struct RecordRemoveMessage
351 {
352   /**
353    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE
354    */
355   struct GNUNET_NAMESTORE_Header gns_header;
356
357   /**
358    * Name length 
359    */
360   uint16_t name_len;
361
362   /**
363    * Length of serialized rd data 
364    */
365   uint16_t rd_len;
366
367   /**
368    * Number of records contained 
369    */
370   uint16_t rd_count;
371
372   /**
373    * Length of private key
374    */
375   uint16_t pkey_len;
376
377   /* followed by:
378    * GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded private key with length pkey_len
379    * name with length name_len
380    * serialized record data with length rd_len
381    * */
382 };
383
384
385 /**
386  * Removal of the record succeeded.
387  */
388 #define RECORD_REMOVE_RESULT_SUCCESS 0
389
390 /**
391  * There are NO records for the given name.
392  */
393 #define RECORD_REMOVE_RESULT_NO_RECORDS 1
394
395 /**
396  * The specific record that was to be removed was
397  * not found.
398  */
399 #define RECORD_REMOVE_RESULT_RECORD_NOT_FOUND 2
400
401 /**
402  * Internal error, failed to sign the remaining records.
403  * (Note: not used?)
404  */
405 #define RECORD_REMOVE_RESULT_FAILED_TO_SIGN 3
406
407 /**
408  * Internal error, failed to store the updated record set
409  */
410 #define RECORD_REMOVE_RESULT_FAILED_TO_PUT_UPDATE 4
411
412 /**
413  * Internal error, failed to remove records from database
414  */
415 #define RECORD_REMOVE_RESULT_FAILED_TO_REMOVE 5
416
417 /**
418  * Internal error, failed to access database
419  */
420 #define RECORD_REMOVE_RESULT_FAILED_ACCESS_DATABASE 6
421
422 /**
423  * Internal error, failed to access database
424  */
425 #define RECORD_REMOVE_RESULT_FAILED_INTERNAL_ERROR 7
426
427
428 /**
429  * Remove a record from the namestore response
430  */
431 struct RecordRemoveResponseMessage
432 {
433   /**
434    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE
435    */
436   struct GNUNET_NAMESTORE_Header gns_header;
437
438   /**
439    * Result code (see RECORD_REMOVE_RESULT_*).  In network byte order.
440    */
441   int32_t op_result;
442 };
443
444
445 /**
446  * Lookup a name for a zone hash
447  */
448 struct ZoneToNameMessage
449 {
450   /**
451    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME
452    */
453   struct GNUNET_NAMESTORE_Header gns_header;
454
455   /**
456    * The hash of public key of the zone to look up in 
457    */
458   struct GNUNET_CRYPTO_ShortHashCode zone;
459
460   /**
461    * The  hash of the public key of the target zone  
462    */
463   struct GNUNET_CRYPTO_ShortHashCode value_zone;
464 };
465
466 /**
467  * Respone for zone to name lookup
468  */
469 struct ZoneToNameResponseMessage
470 {
471   /**
472    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE
473    */
474   struct GNUNET_NAMESTORE_Header gns_header;
475
476   /**
477    * Record block expiration
478    */
479   struct GNUNET_TIME_AbsoluteNBO expire;
480
481   /**
482    * Length of the name
483    */
484   uint16_t name_len;
485
486   /**
487    * Length of serialized record data
488    */
489   uint16_t rd_len;
490
491   /**
492    * Number of records contained
493    */
494   uint16_t rd_count;
495
496   /* result in NBO: GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error */
497   int16_t res;
498
499   /**
500    * Signature
501    */
502   struct GNUNET_CRYPTO_RsaSignature signature;
503
504   /**
505    * Publik key
506    */
507   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded zone_key;
508
509 };
510
511
512
513 /**
514  * Start a zone iteration for the given zone
515  */
516 struct ZoneIterationStartMessage
517 {
518   /**
519    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START
520    */
521   struct GNUNET_NAMESTORE_Header gns_header;
522
523   /**
524    * Zone hash
525    */
526   struct GNUNET_CRYPTO_ShortHashCode zone;
527
528   /**
529    * Which flags must be included
530    */
531   uint16_t must_have_flags;
532
533   /**
534    * Which flags must not be included
535    */
536   uint16_t must_not_have_flags;
537 };
538
539
540 /**
541  * Ask for next result of zone iteration for the given operation
542  */
543 struct ZoneIterationNextMessage
544 {
545   /**
546    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT
547    */
548   struct GNUNET_NAMESTORE_Header gns_header;
549 };
550
551
552 /**
553  * Stop zone iteration for the given operation
554  */
555 struct ZoneIterationStopMessage
556 {
557   /**
558    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP
559    */
560   struct GNUNET_NAMESTORE_Header gns_header;
561 };
562
563 /**
564  * Next result of zone iteration for the given operation
565  * // FIXME: use 'struct LookupResponseMessage' instead? (identical except
566  * for having 'contains_sig' instead of 'reserved', but fully compatible otherwise).
567  */
568 struct ZoneIterationResponseMessage
569 {
570   /**
571    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE
572    */
573   struct GNUNET_NAMESTORE_Header gns_header;
574
575   struct GNUNET_TIME_AbsoluteNBO expire;
576
577   uint16_t name_len;
578
579   /* Record data length */
580   uint16_t rd_len;
581
582   /**
583    * Number of records contained 
584    */
585   uint16_t rd_count;
586
587   /**
588    * always zero (for alignment)
589    */
590   uint16_t reserved;
591
592   /**
593    * All zeros if 'contains_sig' is GNUNET_NO.
594    */
595   struct GNUNET_CRYPTO_RsaSignature signature;
596
597   /**
598    * The public key
599    */
600   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
601
602  
603  
604 };
605 GNUNET_NETWORK_STRUCT_END
606
607
608 /* end of namestore.h */
609 #endif