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