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