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