be061e05eabd68ff0c799d77c41324191efdae26
[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   /* Number of records contained */
173   uint16_t rd_count;
174
175   /* Length of pubkey */
176   uint16_t key_len;
177
178   struct GNUNET_TIME_AbsoluteNBO expire;
179
180   struct GNUNET_CRYPTO_RsaSignature signature;
181 };
182
183
184 /**
185  * Put a record to the namestore response
186  */
187 struct RecordPutResponseMessage
188 {
189   /**
190    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE
191    */
192   struct GNUNET_MessageHeader header;
193
194   /**
195    * Operation ID in NBO
196    */
197   uint32_t op_id;
198
199   /* Contenct starts here */
200
201   /**
202    *  name length: GNUNET_NO (0) on error, GNUNET_OK (1) on success
203    */
204   uint16_t op_result;
205 };
206
207
208 /**
209  * Create a record and put it to the namestore
210  * Memory layout:
211  * [struct RecordCreateMessage][char *name][rc_count * struct GNUNET_NAMESTORE_RecordData]
212  */
213 struct RecordCreateMessage
214 {
215   /**
216    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE
217    */
218   struct GNUNET_NAMESTORE_Header gns_header;
219
220   /* Contenct starts here */
221
222   /* name length */
223   uint16_t name_len;
224
225   /* Record data length */
226   uint16_t rd_len;
227
228   /* Record count */
229   uint16_t rd_count;
230
231   /* private key length */
232   uint16_t pkey_len;
233 };
234
235
236 /**
237  * Create a record to the namestore response
238  * Memory layout:
239  */
240 struct RecordCreateResponseMessage
241 {
242   /**
243    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE
244    */
245   struct GNUNET_NAMESTORE_Header gns_header;
246
247   /* Contenct starts here */
248
249   /**
250    *  name length: GNUNET_NO (0) on error, GNUNET_OK (1) on success
251    */
252   uint16_t op_result;
253
254
255 };
256
257 /**
258  * Remove a record from the namestore
259  * Memory layout:
260  * [struct RecordRemoveMessage][char *name][struct GNUNET_NAMESTORE_RecordData]
261  */
262 struct RecordRemoveMessage
263 {
264   /**
265    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE
266    */
267   struct GNUNET_NAMESTORE_Header gns_header;
268
269   /* Contenct starts here */
270
271   /* Name length */
272   uint16_t name_len;
273
274   /* Length of serialized rd data */
275   uint16_t rd_len;
276
277   /* Number of records contained */
278   uint16_t rd_count;
279
280   /* Length of pubkey */
281   uint16_t key_len;
282 };
283 GNUNET_NETWORK_STRUCT_END
284
285
286 /**
287  * Remove a record from the namestore response
288  */
289 GNUNET_NETWORK_STRUCT_BEGIN
290 struct RecordRemoveResponseMessage
291 {
292   /**
293    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE
294    */
295   struct GNUNET_NAMESTORE_Header gns_header;
296
297   /* Contenct starts here */
298
299   /**
300    *  result:
301    *  0 : successful
302    *  1 : no records for entry
303    *  2 : Could not find record to remove
304    *  3 : Failed to create new signature
305    *  4 : Failed to put new set of records in database
306    */
307   uint16_t op_result;
308 };
309 GNUNET_NETWORK_STRUCT_END
310
311
312 /**
313  * Start a zone iteration for the given zone
314  */
315 GNUNET_NETWORK_STRUCT_BEGIN
316 struct ZoneIterationStartMessage
317 {
318   /**
319    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START
320    */
321   struct GNUNET_NAMESTORE_Header gns_header;
322
323   /* Contenct starts here */
324
325   uint16_t must_have_flags;
326   uint16_t must_not_have_flags;
327
328   GNUNET_HashCode zone;
329 };
330 GNUNET_NETWORK_STRUCT_END
331
332 /**
333  * Ask for next result of zone iteration for the given operation
334  */
335 GNUNET_NETWORK_STRUCT_BEGIN
336 struct ZoneIterationNextMessage
337 {
338   /**
339    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT
340    */
341   struct GNUNET_NAMESTORE_Header gns_header;
342 };
343 GNUNET_NETWORK_STRUCT_END
344
345
346 /**
347  * Stop zone iteration for the given operation
348  */
349 GNUNET_NETWORK_STRUCT_BEGIN
350 struct ZoneIterationStopMessage
351 {
352   /**
353    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP
354    */
355   struct GNUNET_NAMESTORE_Header gns_header;
356 };
357 GNUNET_NETWORK_STRUCT_END
358
359 /**
360  * Ask for next result of zone iteration for the given operation
361  */
362 GNUNET_NETWORK_STRUCT_BEGIN
363 struct ZoneIterationResponseMessage
364 {
365   /**
366    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE
367    */
368   struct GNUNET_NAMESTORE_Header gns_header;
369
370   struct GNUNET_TIME_AbsoluteNBO expire;
371
372   uint16_t name_len;
373
374   uint16_t contains_sig;
375
376   /* Record data length */
377   uint16_t rd_len;
378
379 };
380 GNUNET_NETWORK_STRUCT_END
381
382
383 /* end of namestore.h */
384 #endif