add completion callback for overlay topology configure functions
[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  * Maximum length of any name, including 0-termination.
31  */
32 #define MAX_NAME_LEN 256
33
34 /**
35  * Convert a UTF-8 string to UTF-8 lowercase
36  * @param src source string
37  * @return converted result
38  */
39 char *
40 GNUNET_NAMESTORE_normalize_string (const char *src);
41
42 /**
43  * Convert a short hash to a string (for printing debug messages).
44  * This is one of the very few calls in the entire API that is
45  * NOT reentrant!
46  *
47  * @param hc the short hash code
48  * @return string form; will be overwritten by next call to GNUNET_h2s.
49  */
50 const char *
51 GNUNET_short_h2s (const struct GNUNET_CRYPTO_ShortHashCode * hc);
52
53
54 /**
55  * Sign name and records
56  *
57  * @param key the private key
58  * @param expire block expiration
59  * @param name the name
60  * @param rd record data
61  * @param rd_count number of records
62  *
63  * @return the signature
64  */
65 struct GNUNET_CRYPTO_RsaSignature *
66 GNUNET_NAMESTORE_create_signature (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
67     struct GNUNET_TIME_Absolute expire,
68     const char *name,
69     const struct GNUNET_NAMESTORE_RecordData *rd,
70     unsigned int rd_count);
71
72
73 /**
74  * Compares if two records are equal
75  *
76  * @param a Record a
77  * @param b Record b
78  *
79  * @return GNUNET_YES or GNUNET_NO
80  */
81 int
82 GNUNET_NAMESTORE_records_cmp (const struct GNUNET_NAMESTORE_RecordData *a,
83                               const struct GNUNET_NAMESTORE_RecordData *b);
84
85
86 GNUNET_NETWORK_STRUCT_BEGIN
87 /**
88  * A GNS record serialized for network transmission.
89  *
90  * Layout is [struct GNUNET_NAMESTORE_NetworkRecord][char[data_size] data]
91  */
92 struct GNUNET_NAMESTORE_NetworkRecord
93 {
94   /**
95    * Expiration time for the DNS record.
96    */
97   struct GNUNET_TIME_AbsoluteNBO expiration;
98
99   /**
100    * Number of bytes in 'data'.
101    */
102   uint32_t data_size;
103
104   /**
105    * Type of the GNS/DNS record.
106    */
107   uint32_t record_type;
108
109   /**
110    * Flags for the record.
111    */
112   uint32_t flags;
113 };
114
115
116
117 /**
118  * Connect to namestore service.  FIXME: UNNECESSARY.
119  */
120 struct StartMessage
121 {
122
123   /**
124    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_START
125    */
126   struct GNUNET_MessageHeader header;
127
128 };
129
130
131 /**
132  * Generic namestore message with op id
133  */
134 struct GNUNET_NAMESTORE_Header
135 {
136   /**
137    * header.type will be GNUNET_MESSAGE_TYPE_NAMESTORE_*
138    * header.size will be message size
139    */
140   struct GNUNET_MessageHeader header;
141
142   /**
143    * Request ID in NBO
144    */
145   uint32_t r_id;
146 };
147
148
149 /**
150  * Lookup a name in the namestore
151  */
152 struct LookupNameMessage
153 {
154   struct GNUNET_NAMESTORE_Header gns_header;
155
156   /**
157    * The zone 
158    */
159   struct GNUNET_CRYPTO_ShortHashCode zone;
160
161   /**
162    * Requested record type 
163    */
164   uint32_t record_type;
165
166   /**
167    * Length of the name
168    */
169   uint32_t name_len;
170
171   /* 0-terminated name here */
172 };
173
174
175 /**
176  * Lookup response
177  */
178 struct LookupNameResponseMessage
179 {
180   /**
181    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE
182    */
183   struct GNUNET_NAMESTORE_Header gns_header;
184
185   /**
186    * Expiration time
187    */
188   struct GNUNET_TIME_AbsoluteNBO expire;
189
190
191   /**
192    * Name length
193    */
194   uint16_t name_len;
195
196   /**
197    * Bytes of serialized record data
198    */
199   uint16_t rd_len;
200
201   /**
202    * Number of records contained
203    */
204   uint16_t rd_count;
205
206   /**
207    * Is the signature valid
208    * GNUNET_YES or GNUNET_NO
209    */
210   int16_t contains_sig;
211
212   /**
213    * All zeros if 'contains_sig' is GNUNET_NO.
214    */
215   struct GNUNET_CRYPTO_RsaSignature signature;
216
217   /**
218    * The public key for the name
219    */
220   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
221
222   /* 0-terminated name and serialized record data */
223   /* rd_len bytes serialized record data */
224 };
225
226
227 /**
228  * Put a record to the namestore
229  */
230 struct RecordPutMessage
231 {
232   /**
233    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_RECORD_PUT
234    */
235   struct GNUNET_NAMESTORE_Header gns_header;
236
237   /**
238    * Expiration time
239    */
240   struct GNUNET_TIME_AbsoluteNBO expire;
241
242   /**
243    * Name length
244    */
245   uint16_t name_len;
246
247   /**
248    * Length of serialized record data
249    */
250   uint16_t rd_len;
251
252   /**
253    * Number of records contained 
254    */
255   uint16_t rd_count;
256
257   /**
258    * always zero (for alignment)
259    */
260   uint16_t reserved;
261
262   /**
263    * The signature
264    */
265   struct GNUNET_CRYPTO_RsaSignature signature;
266
267   /**
268    * The public key
269    */
270   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
271
272   /* name (0-terminated) followed by "rd_count" serialized records */
273
274 };
275
276
277 /**
278  * Put a record to the namestore response
279  */
280 struct RecordPutResponseMessage
281 {
282   /**
283    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE
284    */
285   struct GNUNET_NAMESTORE_Header gns_header;
286
287   /**
288    * result:
289    * GNUNET_SYSERR on failure
290    * GNUNET_OK on success
291    */
292   int32_t op_result;
293 };
294
295
296 /**
297  * Create a record and put it to the namestore
298  * Memory layout:
299  */
300 struct RecordCreateMessage
301 {
302   /**
303    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE
304    */
305   struct GNUNET_NAMESTORE_Header gns_header;
306
307   struct GNUNET_TIME_AbsoluteNBO expire;
308
309   /**
310    * Name length
311    */
312   uint16_t name_len;
313
314   /**
315    * Length of serialized record data
316    */
317   uint16_t rd_len;
318
319   /**
320    * Record count 
321    */
322   uint16_t rd_count;
323
324   /**
325    * private key length 
326    */
327   uint16_t pkey_len;
328
329   /* followed by:
330    * GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded private key with length pkey_len
331    * name with length name_len
332    * serialized record data with length rd_len
333    * */
334 };
335
336
337 /**
338  * Create a record to the namestore response
339  */
340 struct RecordCreateResponseMessage
341 {
342   /**
343    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE
344    */
345   struct GNUNET_NAMESTORE_Header gns_header;
346
347   /**
348    *  name length: GNUNET_NO already exists, GNUNET_YES on success, GNUNET_SYSERR error
349    */
350   int32_t op_result;
351 };
352
353
354 /**
355  * Remove a record from the namestore
356  * Memory layout:
357  */
358 struct RecordRemoveMessage
359 {
360   /**
361    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE
362    */
363   struct GNUNET_NAMESTORE_Header gns_header;
364
365   /**
366    * Name length 
367    */
368   uint16_t name_len;
369
370   /**
371    * Length of serialized rd data 
372    */
373   uint16_t rd_len;
374
375   /**
376    * Number of records contained 
377    */
378   uint16_t rd_count;
379
380   /**
381    * Length of private key
382    */
383   uint16_t pkey_len;
384
385   /* followed by:
386    * GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded private key with length pkey_len
387    * name with length name_len
388    * serialized record data with length rd_len
389    * */
390 };
391
392
393 /**
394  * Removal of the record succeeded.
395  */
396 #define RECORD_REMOVE_RESULT_SUCCESS 0
397
398 /**
399  * There are NO records for the given name.
400  */
401 #define RECORD_REMOVE_RESULT_NO_RECORDS 1
402
403 /**
404  * The specific record that was to be removed was
405  * not found.
406  */
407 #define RECORD_REMOVE_RESULT_RECORD_NOT_FOUND 2
408
409 /**
410  * Internal error, failed to sign the remaining records.
411  * (Note: not used?)
412  */
413 #define RECORD_REMOVE_RESULT_FAILED_TO_SIGN 3
414
415 /**
416  * Internal error, failed to store the updated record set
417  */
418 #define RECORD_REMOVE_RESULT_FAILED_TO_PUT_UPDATE 4
419
420 /**
421  * Internal error, failed to remove records from database
422  */
423 #define RECORD_REMOVE_RESULT_FAILED_TO_REMOVE 5
424
425 /**
426  * Internal error, failed to access database
427  */
428 #define RECORD_REMOVE_RESULT_FAILED_ACCESS_DATABASE 6
429
430 /**
431  * Internal error, failed to access database
432  */
433 #define RECORD_REMOVE_RESULT_FAILED_INTERNAL_ERROR 7
434
435
436 /**
437  * Remove a record from the namestore response
438  */
439 struct RecordRemoveResponseMessage
440 {
441   /**
442    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE
443    */
444   struct GNUNET_NAMESTORE_Header gns_header;
445
446   /**
447    * Result code (see RECORD_REMOVE_RESULT_*).  In network byte order.
448    */
449   int32_t op_result;
450 };
451
452
453 /**
454  * Lookup a name for a zone hash
455  */
456 struct ZoneToNameMessage
457 {
458   /**
459    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME
460    */
461   struct GNUNET_NAMESTORE_Header gns_header;
462
463   /**
464    * The hash of public key of the zone to look up in 
465    */
466   struct GNUNET_CRYPTO_ShortHashCode zone;
467
468   /**
469    * The  hash of the public key of the target zone  
470    */
471   struct GNUNET_CRYPTO_ShortHashCode value_zone;
472 };
473
474 /**
475  * Respone for zone to name lookup
476  */
477 struct ZoneToNameResponseMessage
478 {
479   /**
480    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE
481    */
482   struct GNUNET_NAMESTORE_Header gns_header;
483
484   /**
485    * Record block expiration
486    */
487   struct GNUNET_TIME_AbsoluteNBO expire;
488
489   /**
490    * Length of the name
491    */
492   uint16_t name_len;
493
494   /**
495    * Length of serialized record data
496    */
497   uint16_t rd_len;
498
499   /**
500    * Number of records contained
501    */
502   uint16_t rd_count;
503
504   /* result in NBO: GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error */
505   int16_t res;
506
507   /**
508    * Signature
509    */
510   struct GNUNET_CRYPTO_RsaSignature signature;
511
512   /**
513    * Publik key
514    */
515   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded zone_key;
516
517 };
518
519
520
521 /**
522  * Start a zone iteration for the given zone
523  */
524 struct ZoneIterationStartMessage
525 {
526   /**
527    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START
528    */
529   struct GNUNET_NAMESTORE_Header gns_header;
530
531   /**
532    * Zone hash
533    */
534   struct GNUNET_CRYPTO_ShortHashCode zone;
535
536   /**
537    * Which flags must be included
538    */
539   uint16_t must_have_flags;
540
541   /**
542    * Which flags must not be included
543    */
544   uint16_t must_not_have_flags;
545 };
546
547
548 /**
549  * Ask for next result of zone iteration for the given operation
550  */
551 struct ZoneIterationNextMessage
552 {
553   /**
554    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT
555    */
556   struct GNUNET_NAMESTORE_Header gns_header;
557 };
558
559
560 /**
561  * Stop zone iteration for the given operation
562  */
563 struct ZoneIterationStopMessage
564 {
565   /**
566    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP
567    */
568   struct GNUNET_NAMESTORE_Header gns_header;
569 };
570
571 /**
572  * Next result of zone iteration for the given operation
573  * // FIXME: use 'struct LookupResponseMessage' instead? (identical except
574  * for having 'contains_sig' instead of 'reserved', but fully compatible otherwise).
575  */
576 struct ZoneIterationResponseMessage
577 {
578   /**
579    * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE
580    */
581   struct GNUNET_NAMESTORE_Header gns_header;
582
583   struct GNUNET_TIME_AbsoluteNBO expire;
584
585   uint16_t name_len;
586
587   /* Record data length */
588   uint16_t rd_len;
589
590   /**
591    * Number of records contained 
592    */
593   uint16_t rd_count;
594
595   /**
596    * always zero (for alignment)
597    */
598   uint16_t reserved;
599
600   /**
601    * All zeros if 'contains_sig' is GNUNET_NO.
602    */
603   struct GNUNET_CRYPTO_RsaSignature signature;
604
605   /**
606    * The public key
607    */
608   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
609
610  
611  
612 };
613 GNUNET_NETWORK_STRUCT_END
614
615
616 /* end of namestore.h */
617 #endif