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