58ecbf65d177268f5a3ad450bcb41a618ce4dcf6
[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    * Name length
142    */
143   uint16_t name_len;
144
145   /**
146    * Bytes of serialized record data
147    */
148   uint16_t rd_len;
149
150   /**
151    * Number of records contained
152    */
153   uint16_t rd_count;
154
155   /**
156    * Is the signature valid
157    * GNUNET_YES or GNUNET_NO
158    */
159   int16_t contains_sig;
160
161   /**
162    * All zeros if 'contains_sig' is GNUNET_NO.
163    */
164   struct GNUNET_CRYPTO_EccSignature signature;
165
166   /**
167    * The public key for the name
168    */
169   struct GNUNET_CRYPTO_EccPublicKey public_key;
170
171   /* 0-terminated name and serialized record data */
172   /* rd_len bytes serialized record data */
173 };
174
175
176 /**
177  * Put a record to the namestore
178  */
179 struct RecordPutMessage
180 {
181   /**
182    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_RECORD_PUT
183    */
184   struct GNUNET_NAMESTORE_Header gns_header;
185
186   /**
187    * Expiration time
188    */
189   struct GNUNET_TIME_AbsoluteNBO expire;
190
191   /**
192    * Name length
193    */
194   uint16_t name_len;
195
196   /**
197    * Length of serialized record data
198    */
199   uint16_t rd_len;
200
201   /**
202    * Number of records contained 
203    */
204   uint16_t rd_count;
205
206   /**
207    * always zero (for alignment)
208    */
209   uint16_t reserved;
210
211   /**
212    * The signature
213    */
214   struct GNUNET_CRYPTO_EccSignature signature;
215
216   /**
217    * The public key
218    */
219   struct GNUNET_CRYPTO_EccPublicKey public_key;
220
221   /* name (0-terminated) followed by "rd_count" serialized records */
222
223 };
224
225
226 /**
227  * Put a record to the namestore response
228  */
229 struct RecordPutResponseMessage
230 {
231   /**
232    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE
233    */
234   struct GNUNET_NAMESTORE_Header gns_header;
235
236   /**
237    * result:
238    * GNUNET_SYSERR on failure
239    * GNUNET_OK on success
240    */
241   int32_t op_result;
242 };
243
244
245 /**
246  * Create a record and put it to the namestore
247  * Memory layout:
248  */
249 struct RecordCreateMessage
250 {
251   /**
252    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE
253    */
254   struct GNUNET_NAMESTORE_Header gns_header;
255
256   struct GNUNET_TIME_AbsoluteNBO expire;
257
258   /**
259    * Name length
260    */
261   uint16_t name_len;
262
263   /**
264    * Length of serialized record data
265    */
266   uint16_t rd_len;
267
268   /**
269    * Record count 
270    */
271   uint16_t rd_count;
272
273   /**
274    * always zero
275    */
276   uint16_t reserved;
277
278   struct GNUNET_CRYPTO_EccPrivateKey private_key;
279
280   /* followed by:
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 /**
327  * Respone for zone to name lookup
328  */
329 struct ZoneToNameResponseMessage
330 {
331   /**
332    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE
333    */
334   struct GNUNET_NAMESTORE_Header gns_header;
335
336   /**
337    * Record block expiration
338    */
339   struct GNUNET_TIME_AbsoluteNBO expire;
340
341   /**
342    * Length of the name
343    */
344   uint16_t name_len;
345
346   /**
347    * Length of serialized record data
348    */
349   uint16_t rd_len;
350
351   /**
352    * Number of records contained
353    */
354   uint16_t rd_count;
355
356   /**
357    * result in NBO: GNUNET_OK on success, GNUNET_NO if there were no
358    * results, GNUNET_SYSERR on error 
359    */
360   int16_t res;
361
362   /**
363    * Signature
364    */
365   struct GNUNET_CRYPTO_EccSignature signature;
366
367   /**
368    * Publik key
369    */
370   struct GNUNET_CRYPTO_EccPublicKey zone_key;
371
372 };
373
374
375 /**
376  * Start monitoring a zone.
377  */
378 struct ZoneMonitorStartMessage
379 {
380   /**
381    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START
382    */
383   struct GNUNET_NAMESTORE_Header gns_header;
384
385   /**
386    * Zone hash
387    */
388   struct GNUNET_CRYPTO_ShortHashCode zone;
389
390   /**
391    * All zones. GNUNET_YES to monitor all zones,
392    * GNUNET_NO to only monitor 'zone'.  In NBO.
393    */
394   uint32_t all_zones GNUNET_PACKED;
395
396 };
397
398
399 /**
400  * Start a zone iteration for the given zone
401  */
402 struct ZoneIterationStartMessage
403 {
404   /**
405    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START
406    */
407   struct GNUNET_NAMESTORE_Header gns_header;
408
409   /**
410    * Zone hash
411    */
412   struct GNUNET_CRYPTO_ShortHashCode zone;
413
414   /**
415    * Which flags must be included
416    */
417   uint16_t must_have_flags;
418
419   /**
420    * Which flags must not be included
421    */
422   uint16_t must_not_have_flags;
423 };
424
425
426 /**
427  * Ask for next result of zone iteration for the given operation
428  */
429 struct ZoneIterationNextMessage
430 {
431   /**
432    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT
433    */
434   struct GNUNET_NAMESTORE_Header gns_header;
435 };
436
437
438 /**
439  * Stop zone iteration for the given operation
440  */
441 struct ZoneIterationStopMessage
442 {
443   /**
444    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP
445    */
446   struct GNUNET_NAMESTORE_Header gns_header;
447 };
448
449
450 GNUNET_NETWORK_STRUCT_END
451
452
453 /* end of namestore.h */
454 #endif