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