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