760d491e2d0d91909c871b14c9a73139ee78cde6
[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   uint16_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   /* Length of pubkey */
206   uint16_t key_len;
207
208   struct GNUNET_TIME_AbsoluteNBO expire;
209
210   struct GNUNET_CRYPTO_RsaSignature signature;
211 };
212 GNUNET_NETWORK_STRUCT_END
213
214 /**
215  * Put a record to the namestore response
216  */
217 GNUNET_NETWORK_STRUCT_BEGIN
218 struct RecordPutResponseMessage
219 {
220   /**
221    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE
222    */
223   struct GNUNET_MessageHeader header;
224
225   /**
226    * Operation ID in NBO
227    */
228   uint32_t op_id;
229
230   /* Contenct starts here */
231
232   /**
233    *  name length: GNUNET_NO (0) on error, GNUNET_OK (1) on success
234    */
235   uint16_t op_result;
236 };
237 GNUNET_NETWORK_STRUCT_END
238
239
240 /**
241  * Create a record and put it to the namestore
242  * Memory layout:
243  * [struct RecordCreateMessage][char *name][rc_count * struct GNUNET_NAMESTORE_RecordData]
244  */
245 GNUNET_NETWORK_STRUCT_BEGIN
246 struct RecordCreateMessage
247 {
248   /**
249    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE
250    */
251   struct GNUNET_MessageHeader header;
252
253   /**
254    * Operation ID in NBO
255    */
256   uint32_t op_id;
257
258   /* Contenct starts here */
259
260   /* name length */
261   uint16_t name_len;
262
263   /* Record data length */
264   uint16_t rd_len;
265
266   /* private key length */
267   uint16_t pkey_len;
268 };
269 GNUNET_NETWORK_STRUCT_END
270
271
272 /**
273  * Create a record to the namestore response
274  * Memory layout:
275  */
276 GNUNET_NETWORK_STRUCT_BEGIN
277 struct RecordCreateResponseMessage
278 {
279   /**
280    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE
281    */
282   struct GNUNET_MessageHeader header;
283
284   /**
285    * Operation ID in NBO
286    */
287   uint32_t op_id;
288
289   /* Contenct starts here */
290
291   /**
292    *  name length: GNUNET_NO (0) on error, GNUNET_OK (1) on success
293    */
294   uint16_t op_result;
295
296
297 };
298 GNUNET_NETWORK_STRUCT_END
299
300 /**
301  * Remove a record from the namestore
302  * Memory layout:
303  * [struct RecordRemoveMessage][char *name][struct GNUNET_NAMESTORE_RecordData]
304  */
305 GNUNET_NETWORK_STRUCT_BEGIN
306 struct RecordRemoveMessage
307 {
308   /**
309    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE
310    */
311   struct GNUNET_MessageHeader header;
312
313   /**
314    * Operation ID in NBO
315    */
316   uint32_t op_id;
317
318   /* Contenct starts here */
319
320   /* name length */
321   uint16_t name_len;
322
323   struct GNUNET_CRYPTO_RsaSignature signature;
324 };
325 GNUNET_NETWORK_STRUCT_END
326
327
328 /**
329  * Remove a record from the namestore response
330  */
331 GNUNET_NETWORK_STRUCT_BEGIN
332 struct RecordRemoveResponseMessage
333 {
334   /**
335    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE
336    */
337   struct GNUNET_MessageHeader header;
338
339   /**
340    * Operation ID in NBO
341    */
342   uint32_t op_id;
343
344   /* Contenct starts here */
345
346   /**
347    *  name length: GNUNET_NO (0) on error, GNUNET_OK (1) on success
348    */
349   uint16_t op_result;
350 };
351 GNUNET_NETWORK_STRUCT_END
352
353
354 /**
355  * Start a zone iteration for the given zone
356  */
357 GNUNET_NETWORK_STRUCT_BEGIN
358 struct ZoneIterationStartMessage
359 {
360   /**
361    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START
362    */
363   struct GNUNET_MessageHeader header;
364
365   /**
366    * Operation ID in NBO
367    */
368   uint32_t op_id;
369
370   /* Contenct starts here */
371
372   uint16_t must_have_flags;
373   uint16_t must_not_have_flags;
374
375   GNUNET_HashCode zone;
376 };
377 GNUNET_NETWORK_STRUCT_END
378
379 /**
380  * Ask for next result of zone iteration for the given operation
381  */
382 GNUNET_NETWORK_STRUCT_BEGIN
383 struct ZoneIterationNextMessage
384 {
385   /**
386    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT
387    */
388   struct GNUNET_MessageHeader header;
389
390   /**
391    * Operation ID in NBO
392    */
393   uint32_t op_id;
394 };
395 GNUNET_NETWORK_STRUCT_END
396
397
398 /**
399  * Stop zone iteration for the given operation
400  */
401 GNUNET_NETWORK_STRUCT_BEGIN
402 struct ZoneIterationStopMessage
403 {
404   /**
405    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP
406    */
407   struct GNUNET_MessageHeader header;
408
409   /**
410    * Operation ID in NBO
411    */
412   uint32_t op_id;
413 };
414 GNUNET_NETWORK_STRUCT_END
415
416 /**
417  * Ask for next result of zone iteration for the given operation
418  */
419 GNUNET_NETWORK_STRUCT_BEGIN
420 struct ZoneIterationResponseMessage
421 {
422   /**
423    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE
424    */
425   struct GNUNET_MessageHeader header;
426
427   /**
428    * Operation ID in NBO
429    */
430   uint32_t op_id;
431
432   struct GNUNET_TIME_AbsoluteNBO expire;
433
434   uint16_t name_len;
435
436   uint16_t contains_sig;
437
438   /* Record data length */
439   uint16_t rd_len;
440
441 };
442 GNUNET_NETWORK_STRUCT_END
443
444
445 /* end of namestore.h */
446 #endif