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