- fixed definition
[oweals/gnunet.git] / src / include / gnunet_namestore_plugin.h
1 /*
2      This file is part of GNUnet
3      (C) 2012 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 2, 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 include/gnunet_namestore_plugin.h
23  * @brief plugin API for the namestore database backend
24  * @author Christian Grothoff
25  *
26  * Other functions we might want:
27  * - enumerate all known zones
28  */
29 #ifndef GNUNET_NAMESTORE_PLUGIN_H
30 #define GNUNET_NAMESTORE_PLUGIN_H
31
32 #include "gnunet_common.h"
33 #include "gnunet_util_lib.h"
34 #include "gnunet_namestore_service.h"
35
36 #ifdef __cplusplus
37 extern "C"
38 {
39 #if 0                           /* keep Emacsens' auto-indent happy */
40 }
41 #endif
42 #endif
43
44
45 /**
46  * Function called by for each matching record.
47  *
48  * @param cls closure
49  * @param zone hash of the public key of the zone
50  * @param record_hash hash of the record 
51  * @param record_key XOR of zone and hash of name
52  * @param name name that is being mapped (at most 255 characters long)
53  * @param record_type type of the record (A, AAAA, PKEY, etc.)
54  * @param expiration expiration time for the content
55  * @param flags flags for the content
56  * @param data_size number of bytes in data
57  * @param data value, semantics depend on 'record_type' (see RFCs for DNS and 
58  *             GNS specification for GNS extensions) 
59  */
60 typedef void (*GNUNET_NAMESTORE_RecordIterator) (void *cls,
61                                                  const GNUNET_HashCode *zone,
62                                                  const GNUNET_HashCode *record_hash,
63                                                  const GNUNET_HashCode *record_key,
64                                                  const char *name,
65                                                  uint32_t record_type,
66                                                  struct GNUNET_TIME_Absolute expiration,
67                                                  enum GNUNET_NAMESTORE_RecordFlags flags,
68                                                  size_t data_size,
69                                                  const void *data);
70
71
72 /**
73  * Function called with the matching node.
74  *
75  * @param cls closure
76  * @param zone hash of public key of the zone
77  * @param loc location in the B-tree
78  * @param ploc parent's location in the B-tree (must have depth = loc.depth - 1), NULL for root
79  * @param num_entries number of entries at this node in the B-tree
80  * @param entries the 'num_entries' entries to store (hashes over the
81  *                records)
82  */
83 typedef void (*GNUNET_NAMESTORE_NodeCallback) (void *cls,
84                                                const GNUNET_HashCode *zone,
85                                                const struct GNUNET_NAMESTORE_SignatureLocation *loc,
86                                                const struct GNUNET_NAMESTORE_SignatureLocation *ploc,
87                                                unsigned int num_entries,
88                                                const GNUNET_HashCode *entries);
89
90
91 /**
92  * Function called with the matching signature.
93  *
94  * @param cls closure
95  * @param zone public key of the zone
96  * @param loc location of the root in the B-tree (depth, revision)
97  * @param top_sig 
98  * @param root_hash top level hash that is being signed
99  */
100 typedef void (*GNUNET_NAMESTORE_SignatureCallback) (void *cls,
101                                                     const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
102                                                     const struct GNUNET_NAMESTORE_SignatureLocation *loc,
103                                                     const struct GNUNET_CRYPTO_RsaSignature *top_sig,
104                                                     const GNUNET_HashCode *root_hash);
105
106
107 /**
108  * @brief struct returned by the initialization function of the plugin
109  */
110 struct GNUNET_NAMESTORE_PluginFunctions
111 {
112
113   /**
114    * Closure to pass to all plugin functions.
115    */
116   void *cls;
117
118   /**
119    * Store a record in the datastore.
120    *
121    * @param cls closure (internal context for the plugin)
122    * @param zone hash of the public key of the zone
123    * @param record_hash hash of the record 
124    * @param record_key XOR of zone and hash of name
125    * @param name name that is being mapped (at most 255 characters long)
126    * @param record_type type of the record (A, AAAA, PKEY, etc.)
127    * @param expiration expiration time for the content
128    * @param flags flags for the content
129    * @param data_size number of bytes in data
130    * @param data value, semantics depend on 'record_type' (see RFCs for DNS and 
131    *             GNS specification for GNS extensions)
132    * @return GNUNET_OK on success
133    */
134   int (*put_record) (void *cls, 
135                      const GNUNET_HashCode *zone,
136                      const GNUNET_HashCode *record_hash,
137                      const GNUNET_HashCode *record_key,
138                      const char *name,
139                      uint32_t record_type,
140                      struct GNUNET_TIME_Absolute expiration,
141                      enum GNUNET_NAMESTORE_RecordFlags flags,
142                      size_t data_size,
143                      const void *data);
144
145
146   /**
147    * Store a Merkle tree node in the datastore.
148    *
149    * @param cls closure (internal context for the plugin)
150    * @param zone hash of public key of the zone
151    * @param loc location in the B-tree
152    * @param ploc parent's location in the B-tree (must have depth = loc.depth - 1), NULL for root
153    * @param num_entries number of entries at this node in the B-tree
154    * @param entries the 'num_entries' entries to store (hashes over the
155    *                records)
156    * @return GNUNET_OK on success
157    */
158   int (*put_node) (void *cls, 
159                    const GNUNET_HashCode *zone,
160                    const struct GNUNET_NAMESTORE_SignatureLocation *loc,
161                    const struct GNUNET_NAMESTORE_SignatureLocation *ploc,
162                    unsigned int num_entries,
163                    const GNUNET_HashCode *entries);
164   
165
166   /**
167    * Store a zone signature in the datastore.  If a signature for the zone with a
168    * lower depth exists, the old signature is removed.  If a signature for an
169    * older revision of the zone exists, this will delete all records, nodes
170    * and signatures for the older revision of the zone.
171    *
172    * @param cls closure (internal context for the plugin)
173    * @param zone_key public key of the zone
174    * @param loc location in the B-tree (top of the tree, offset 0, depth at 'maximum')
175    * @param top_sig signature at the top, NULL if 'loc.depth > 0'
176    * @param root_hash top level hash that is signed
177    * @return GNUNET_OK on success
178    */
179   int (*put_signature) (void *cls, 
180                         const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
181                         const struct GNUNET_NAMESTORE_SignatureLocation *loc,
182                         const struct GNUNET_CRYPTO_RsaSignature *top_sig,
183                         const GNUNET_HashCode *root_hash);
184   
185   
186   /**
187    * Iterate over the results for a particular key and zone in the
188    * datastore.  Will only query the latest revision known for the
189    * zone (as adding a new zone revision will cause the plugin to
190    * delete all records from previous revisions).
191    *
192    * @param cls closure (internal context for the plugin)
193    * @param zone hash of public key of the zone
194    * @param record_key key for the record (XOR of zone and hash of name);
195    *                   NULL to iterate over all records of the zone
196    * @param iter maybe NULL (to just count)
197    * @param iter_cls closure for iter
198    * @return the number of results found
199    */
200   unsigned int (*iterate_records) (void *cls, 
201                                    const GNUNET_HashCode *zone,
202                                    const GNUNET_HashCode *record_key,
203                                    GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls);
204
205  
206   /**
207    * Get a particular node from the signature tree.
208    *
209    * @param cls closure (internal context for the plugin)
210    * @param zone hash of public key of the zone
211    * @param loc location of the node in the signature tree
212    * @param cb function to call with the result
213    * @param cb_cls closure for cont
214    */
215   void (*get_node) (void *cls, 
216                     const GNUNET_HashCode *zone,
217                     const struct GNUNET_NAMESTORE_SignatureLocation *loc,
218                     GNUNET_NAMESTORE_NodeCallback cb, void *cb_cls);
219
220
221   /**
222    * Get the current signature for a zone.
223    *
224    * @param cls closure (internal context for the plugin)
225    * @param zone hash of public key of the zone
226    * @param cb function to call with the result
227    * @param cb_cls closure for cont
228    */
229   void (*get_signature) (void *cls, 
230                          const GNUNET_HashCode *zone,
231                          GNUNET_NAMESTORE_SignatureCallback cb, void *cb_cls);
232
233
234   /**
235    * Delete an entire zone (all revisions, all records, all nodes,
236    * all signatures).  Not used in normal operation.
237    *
238    * @param cls closure (internal context for the plugin)
239    * @param zone zone to delete
240    */
241   void (*delete_zone) (void *cls,
242                        const GNUNET_HashCode *zone);
243
244
245 };
246
247
248 #if 0                           /* keep Emacsens' auto-indent happy */
249 {
250 #endif
251 #ifdef __cplusplus
252 }
253 #endif
254
255 /* end of gnunet_namestore_plugin.h */
256 #endif