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