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