14a13801a6d8f6f62c08598efc34db201bbe3121
[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
41 #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START 439
42 #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE 440
43 #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT 441
44 #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP 442
45
46 size_t
47 GNUNET_NAMESTORE_records_serialize (char ** dest,
48                              unsigned int rd_count,
49                              const struct GNUNET_NAMESTORE_RecordData *rd);
50
51 int
52 GNUNET_NAMESTORE_records_deserialize ( struct GNUNET_NAMESTORE_RecordData **dest, char *src, size_t len);
53
54 void
55 GNUNET_NAMESTORE_records_free (unsigned int rd_count, struct GNUNET_NAMESTORE_RecordData *rd);
56
57 /**
58  * A GNS record serialized for network transmission.
59  * layout is [struct GNUNET_NAMESTORE_NetworkRecord][char[data_size] data]
60  */
61 struct GNUNET_NAMESTORE_NetworkRecord
62 {
63   /**
64    * Expiration time for the DNS record.
65    */
66   struct GNUNET_TIME_AbsoluteNBO expiration;
67
68   /**
69    * Number of bytes in 'data'.
70    */
71   uint32_t data_size;
72
73   /**
74    * Type of the GNS/DNS record.
75    */
76   uint32_t record_type;
77
78   /**
79    * Flags for the record.
80    */
81   uint32_t flags;
82 };
83
84
85
86 GNUNET_NETWORK_STRUCT_BEGIN
87 /**
88  * Connect to namestore service
89  */
90 struct StartMessage
91 {
92
93   /**
94    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_START
95    */
96   struct GNUNET_MessageHeader header;
97
98 };
99 GNUNET_NETWORK_STRUCT_END
100
101
102 GNUNET_NETWORK_STRUCT_BEGIN
103 /**
104  * Generic namestore message with op id
105  */
106 struct GenericMessage
107 {
108   /**
109    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_*
110    */
111   struct GNUNET_MessageHeader header;
112
113   /**
114    * Operation ID in NBO
115    */
116   uint32_t op_id;
117 };
118 GNUNET_NETWORK_STRUCT_END
119
120
121 /**
122  * Connect to namestore service
123  */
124 GNUNET_NETWORK_STRUCT_BEGIN
125 struct LookupNameMessage
126 {
127   /**
128    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME
129    */
130   struct GNUNET_MessageHeader header;
131
132   /**
133    * Operation ID in NBO
134    */
135   uint32_t op_id;
136
137   /* The zone */
138   GNUNET_HashCode zone;
139
140   /* Requested record type */
141   uint32_t record_type;
142
143   /* Requested record type */
144   uint32_t name_len;
145 };
146 GNUNET_NETWORK_STRUCT_END
147
148
149 /**
150  * Lookup response
151  * Memory layout:
152  * [struct LookupNameResponseMessage][struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded][char *name][rc_count * struct GNUNET_NAMESTORE_RecordData][struct GNUNET_CRYPTO_RsaSignature]
153  */
154 GNUNET_NETWORK_STRUCT_BEGIN
155 struct LookupNameResponseMessage
156 {
157   /**
158    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE
159    */
160   struct GNUNET_MessageHeader header;
161
162   /**
163    * Operation ID in NBO
164    */
165   uint32_t op_id;
166
167   struct GNUNET_TIME_AbsoluteNBO expire;
168
169   uint16_t name_len;
170
171   uint16_t contains_sig;
172
173   /* Requested record type */
174   uint32_t rd_len;
175 };
176 GNUNET_NETWORK_STRUCT_END
177
178
179 /**
180  * Put a record to the namestore
181  * Memory layout:
182  * [struct RecordPutMessage][struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded][char *name][rc_count * struct GNUNET_NAMESTORE_RecordData]
183  */
184 GNUNET_NETWORK_STRUCT_BEGIN
185 struct RecordPutMessage
186 {
187   /**
188    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_RECORD_PUT
189    */
190   struct GNUNET_MessageHeader header;
191
192   /**
193    * Operation ID in NBO
194    */
195   uint32_t op_id;
196
197   /* Contenct starts here */
198
199   /* name length */
200   uint16_t name_len;
201
202   /* Length of serialized rd data */
203   uint16_t rd_len;
204
205   struct GNUNET_TIME_AbsoluteNBO expire;
206
207   struct GNUNET_CRYPTO_RsaSignature signature;
208 };
209 GNUNET_NETWORK_STRUCT_END
210
211 /**
212  * Put a record to the namestore response
213  */
214 GNUNET_NETWORK_STRUCT_BEGIN
215 struct RecordPutResponseMessage
216 {
217   /**
218    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE
219    */
220   struct GNUNET_MessageHeader header;
221
222   /**
223    * Operation ID in NBO
224    */
225   uint32_t op_id;
226
227   /* Contenct starts here */
228
229   /**
230    *  name length: GNUNET_NO (0) on error, GNUNET_OK (1) on success
231    */
232   uint16_t op_result;
233 };
234 GNUNET_NETWORK_STRUCT_END
235
236
237 /**
238  * Put a record to the namestore
239  * Memory layout:
240  * [struct RecordPutMessage][struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded][char *name][rc_count * struct GNUNET_NAMESTORE_RecordData]
241  */
242 GNUNET_NETWORK_STRUCT_BEGIN
243 struct RecordCreateMessage
244 {
245   /**
246    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE
247    */
248   struct GNUNET_MessageHeader header;
249
250   /**
251    * Operation ID in NBO
252    */
253   uint32_t op_id;
254
255   /* Contenct starts here */
256
257   /* name length */
258   uint16_t name_len;
259
260   struct GNUNET_CRYPTO_RsaSignature signature;
261 };
262 GNUNET_NETWORK_STRUCT_END
263
264
265 /**
266  * Create a record to the namestore response
267  * Memory layout:
268  */
269 GNUNET_NETWORK_STRUCT_BEGIN
270 struct RecordCreateResponseMessage
271 {
272   /**
273    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE
274    */
275   struct GNUNET_MessageHeader header;
276
277   /**
278    * Operation ID in NBO
279    */
280   uint32_t op_id;
281
282   /* Contenct starts here */
283
284   /**
285    *  name length: GNUNET_NO (0) on error, GNUNET_OK (1) on success
286    */
287   uint16_t op_result;
288 };
289 GNUNET_NETWORK_STRUCT_END
290
291 /**
292  * Remove a record from the namestore
293  * Memory layout:
294  * [struct RecordRemoveMessage][char *name][struct GNUNET_NAMESTORE_RecordData]
295  */
296 GNUNET_NETWORK_STRUCT_BEGIN
297 struct RecordRemoveMessage
298 {
299   /**
300    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE
301    */
302   struct GNUNET_MessageHeader header;
303
304   /**
305    * Operation ID in NBO
306    */
307   uint32_t op_id;
308
309   /* Contenct starts here */
310
311   /* name length */
312   uint16_t name_len;
313
314   struct GNUNET_CRYPTO_RsaSignature signature;
315 };
316 GNUNET_NETWORK_STRUCT_END
317
318
319 /**
320  * Remove a record from the namestore response
321  */
322 GNUNET_NETWORK_STRUCT_BEGIN
323 struct RecordRemoveResponseMessage
324 {
325   /**
326    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE
327    */
328   struct GNUNET_MessageHeader header;
329
330   /**
331    * Operation ID in NBO
332    */
333   uint32_t op_id;
334
335   /* Contenct starts here */
336
337   /**
338    *  name length: GNUNET_NO (0) on error, GNUNET_OK (1) on success
339    */
340   uint16_t op_result;
341 };
342 GNUNET_NETWORK_STRUCT_END
343
344
345 /**
346  * Start a zone iteration for the given zone
347  */
348 GNUNET_NETWORK_STRUCT_BEGIN
349 struct ZoneIterationStartMessage
350 {
351   /**
352    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START
353    */
354   struct GNUNET_MessageHeader header;
355
356   /**
357    * Operation ID in NBO
358    */
359   uint32_t op_id;
360
361   /* Contenct starts here */
362
363   uint16_t must_have_flags;
364   uint16_t must_not_have_flags;
365
366   GNUNET_HashCode zone;
367 };
368 GNUNET_NETWORK_STRUCT_END
369
370 /**
371  * Ask for next result of zone iteration for the given operation
372  */
373 GNUNET_NETWORK_STRUCT_BEGIN
374 struct ZoneIterationNextMessage
375 {
376   /**
377    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT
378    */
379   struct GNUNET_MessageHeader header;
380
381   /**
382    * Operation ID in NBO
383    */
384   uint32_t op_id;
385 };
386 GNUNET_NETWORK_STRUCT_END
387
388
389 /**
390  * Stop zone iteration for the given operation
391  */
392 GNUNET_NETWORK_STRUCT_BEGIN
393 struct ZoneIterationStopMessage
394 {
395   /**
396    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP
397    */
398   struct GNUNET_MessageHeader header;
399
400   /**
401    * Operation ID in NBO
402    */
403   uint32_t op_id;
404 };
405 GNUNET_NETWORK_STRUCT_END
406
407 /**
408  * Ask for next result of zone iteration for the given operation
409  */
410 GNUNET_NETWORK_STRUCT_BEGIN
411 struct ZoneIterationResponseMessage
412 {
413   /**
414    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE
415    */
416   struct GNUNET_MessageHeader header;
417
418   /**
419    * Operation ID in NBO
420    */
421   uint32_t op_id;
422
423   struct GNUNET_TIME_AbsoluteNBO expire;
424
425   uint16_t name_len;
426
427   uint16_t contains_sig;
428
429   /* Record data length */
430   uint16_t rd_len;
431
432 };
433 GNUNET_NETWORK_STRUCT_END
434
435
436 /* end of namestore.h */
437 #endif