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