8e2625c109cbfa5a07270df4bbb1b376471653c3
[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_EccPublicKeyBinaryEncoded 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_EccPublicKeyBinaryEncoded 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    * private key length 
275    */
276   uint16_t pkey_len;
277
278   /* followed by:
279    * GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded private key with length pkey_len
280    * name with length name_len
281    * serialized record data with length rd_len
282    * */
283 };
284
285
286 /**
287  * Create a record to the namestore response
288  */
289 struct RecordCreateResponseMessage
290 {
291   /**
292    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE
293    */
294   struct GNUNET_NAMESTORE_Header gns_header;
295
296   /**
297    *  name length: GNUNET_NO already exists, GNUNET_YES on success, GNUNET_SYSERR error
298    */
299   int32_t op_result;
300 };
301
302
303 /**
304  * Lookup a name for a zone hash
305  */
306 struct ZoneToNameMessage
307 {
308   /**
309    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME
310    */
311   struct GNUNET_NAMESTORE_Header gns_header;
312
313   /**
314    * The hash of public key of the zone to look up in 
315    */
316   struct GNUNET_CRYPTO_ShortHashCode zone;
317
318   /**
319    * The  hash of the public key of the target zone  
320    */
321   struct GNUNET_CRYPTO_ShortHashCode value_zone;
322 };
323
324 /**
325  * Respone for zone to name lookup
326  */
327 struct ZoneToNameResponseMessage
328 {
329   /**
330    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE
331    */
332   struct GNUNET_NAMESTORE_Header gns_header;
333
334   /**
335    * Record block expiration
336    */
337   struct GNUNET_TIME_AbsoluteNBO expire;
338
339   /**
340    * Length of the name
341    */
342   uint16_t name_len;
343
344   /**
345    * Length of serialized record data
346    */
347   uint16_t rd_len;
348
349   /**
350    * Number of records contained
351    */
352   uint16_t rd_count;
353
354   /**
355    * result in NBO: GNUNET_OK on success, GNUNET_NO if there were no
356    * results, GNUNET_SYSERR on error 
357    */
358   int16_t res;
359
360   /**
361    * Signature
362    */
363   struct GNUNET_CRYPTO_EccSignature signature;
364
365   /**
366    * Publik key
367    */
368   struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded zone_key;
369
370 };
371
372
373 /**
374  * Start monitoring a zone.
375  */
376 struct ZoneMonitorStartMessage
377 {
378   /**
379    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START
380    */
381   struct GNUNET_NAMESTORE_Header gns_header;
382
383   /**
384    * Zone hash
385    */
386   struct GNUNET_CRYPTO_ShortHashCode zone;
387
388   /**
389    * All zones. GNUNET_YES to monitor all zones,
390    * GNUNET_NO to only monitor 'zone'.  In NBO.
391    */
392   uint32_t all_zones GNUNET_PACKED;
393
394 };
395
396
397 /**
398  * Start a zone iteration for the given zone
399  */
400 struct ZoneIterationStartMessage
401 {
402   /**
403    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START
404    */
405   struct GNUNET_NAMESTORE_Header gns_header;
406
407   /**
408    * Zone hash
409    */
410   struct GNUNET_CRYPTO_ShortHashCode zone;
411
412   /**
413    * Which flags must be included
414    */
415   uint16_t must_have_flags;
416
417   /**
418    * Which flags must not be included
419    */
420   uint16_t must_not_have_flags;
421 };
422
423
424 /**
425  * Ask for next result of zone iteration for the given operation
426  */
427 struct ZoneIterationNextMessage
428 {
429   /**
430    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT
431    */
432   struct GNUNET_NAMESTORE_Header gns_header;
433 };
434
435
436 /**
437  * Stop zone iteration for the given operation
438  */
439 struct ZoneIterationStopMessage
440 {
441   /**
442    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP
443    */
444   struct GNUNET_NAMESTORE_Header gns_header;
445 };
446
447
448 GNUNET_NETWORK_STRUCT_END
449
450
451 /* end of namestore.h */
452 #endif