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