8ff2adf4a130ded2bc93c7b52d2ae32cb03075a3
[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 loc location of the signature for this record
51  * @param name name that is being mapped (at most 255 characters long)
52  * @param record_type type of the record (A, AAAA, PKEY, etc.)
53  * @param expiration expiration time for the content
54  * @param flags flags for the content
55  * @param data_size number of bytes in data
56  * @param data value, semantics depend on 'record_type' (see RFCs for DNS and 
57  *             GNS specification for GNS extensions) 
58  */
59 typedef void (*GNUNET_NAMESTORE_RecordIterator) (void *cls,
60                                                  const GNUNET_HashCode *zone,
61                                                  const struct GNUNET_NAMESTORE_SignatureLocation *loc,
62                                                  const char *name,
63                                                  uint32_t record_type,
64                                                  struct GNUNET_TIME_Absolute expiration,
65                                                  enum GNUNET_NAMESTORE_RecordFlags flags,
66                                                  size_t data_size,
67                                                  const void *data);
68
69
70 /**
71  * Function called with the matching node.
72  *
73  * @param cls closure
74  * @param zone hash of public key of the zone
75  * @param loc location in the B-tree
76  * @param ploc parent's location in the B-tree (must have depth = loc.depth - 1), NULL for root
77  * @param num_entries number of entries at this node in the B-tree
78  * @param entries the 'num_entries' entries to store (hashes over the
79  *                records)
80  */
81 typedef void (*GNUNET_NAMESTORE_NodeCallback) (void *cls,
82                                                const GNUNET_HashCode *zone,
83                                                const struct GNUNET_NAMESTORE_SignatureLocation *loc,
84                                                const struct GNUNET_NAMESTORE_SignatureLocation *ploc,
85                                                unsigned int num_entries,
86                                                const GNUNET_HashCode *entries);
87
88
89 /**
90  * Function called with the matching signature.
91  *
92  * @param cls closure
93  * @param zone public key of the zone
94  * @param loc location of the root in the B-tree (depth, revision)
95  * @param top_sig signature signing the zone
96  * @param zone_time time the signature was created
97  * @param root_hash top level hash that is being signed
98  */
99 typedef void (*GNUNET_NAMESTORE_SignatureCallback) (void *cls,
100                                                     const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
101                                                     const struct GNUNET_NAMESTORE_SignatureLocation *loc,
102                                                     const struct GNUNET_CRYPTO_RsaSignature *top_sig,
103                                                     struct GNUNET_TIME_Absolute zone_time,
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 name name that is being mapped (at most 255 characters long)
124    * @param record_type type of the record (A, AAAA, PKEY, etc.)
125    * @param loc location of the signature for the record
126    * @param expiration expiration time for the content
127    * @param flags flags for the content
128    * @param data_size number of bytes in data
129    * @param data value, semantics depend on 'record_type' (see RFCs for DNS and 
130    *             GNS specification for GNS extensions)
131    * @return GNUNET_OK on success
132    */
133   int (*put_record) (void *cls, 
134                      const GNUNET_HashCode *zone,
135                      const char *name,
136                      uint32_t record_type,
137                      const struct GNUNET_NAMESTORE_SignatureLocation *loc,
138                      struct GNUNET_TIME_Absolute expiration,
139                      enum GNUNET_NAMESTORE_RecordFlags flags,
140                      size_t data_size,
141                      const void *data);
142
143
144   /**
145    * Store a Merkle tree node in the datastore.
146    *
147    * @param cls closure (internal context for the plugin)
148    * @param zone hash of public key of the zone
149    * @param loc location in the B-tree
150    * @param ploc parent's location in the B-tree (must have depth = loc.depth + 1) and the
151    *             revision must also match loc's revision; NULL for root
152    * @param num_entries number of entries at this node in the B-tree
153    * @param entries the 'num_entries' entries to store (hashes over the
154    *                records)
155    * @return GNUNET_OK on success
156    */
157   int (*put_node) (void *cls, 
158                    const GNUNET_HashCode *zone,
159                    const struct GNUNET_NAMESTORE_SignatureLocation *loc,
160                    const struct GNUNET_NAMESTORE_SignatureLocation *ploc,
161                    unsigned int num_entries,
162                    const GNUNET_HashCode *entries);
163   
164
165   /**
166    * Store a zone signature in the datastore.  If a signature for the zone with a
167    * lower depth exists, the old signature is removed.  If a signature for an
168    * older revision of the zone exists, this will delete all records, nodes
169    * and signatures for the older revision of the zone.
170    *
171    * @param cls closure (internal context for the plugin)
172    * @param zone_key public key of the zone
173    * @param loc location in the B-tree (top of the tree, offset 0, depth at 'maximum')
174    * @param top_sig signature at the top
175    * @param root_hash top level hash that is signed
176    * @param zone_time time the zone was 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                         struct GNUNET_TIME_Absolute zone_time);
185   
186   
187   /**
188    * Iterate over the results for a particular key and zone in the
189    * datastore.  Will only query the latest revision known for the
190    * zone (as adding a new zone revision will cause the plugin to
191    * delete all records from previous revisions).
192    *
193    * @param cls closure (internal context for the plugin)
194    * @param zone hash of public key of the zone
195    * @param name_hash hash of name, 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 *name_hash,
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   int (*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   int (*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