2 This file is part of GNUnet
3 (C) 2012 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file include/gnunet_namestore_plugin.h
23 * @brief plugin API for the namestore database backend
24 * @author Christian Grothoff
26 * Other functions we might want:
27 * - enumerate all known zones
29 #ifndef GNUNET_NAMESTORE_PLUGIN_H
30 #define GNUNET_NAMESTORE_PLUGIN_H
32 #include "gnunet_common.h"
33 #include "gnunet_util_lib.h"
34 #include "gnunet_namestore_service.h"
39 #if 0 /* keep Emacsens' auto-indent happy */
46 * Function called by for each matching record.
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)
59 typedef void (*GNUNET_NAMESTORE_RecordIterator) (void *cls,
60 const GNUNET_HashCode *zone,
61 const struct GNUNET_NAMESTORE_SignatureLocation *loc,
64 struct GNUNET_TIME_Absolute expiration,
65 enum GNUNET_NAMESTORE_RecordFlags flags,
71 * Function called with the matching node.
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
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);
90 * Function called with the matching signature.
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
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);
108 * @brief struct returned by the initialization function of the plugin
110 struct GNUNET_NAMESTORE_PluginFunctions
114 * Closure to pass to all plugin functions.
119 * Store a record in the datastore.
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
133 int (*put_record) (void *cls,
134 const GNUNET_HashCode *zone,
136 uint32_t record_type,
137 const struct GNUNET_NAMESTORE_SignatureLocation *loc,
138 struct GNUNET_TIME_Absolute expiration,
139 enum GNUNET_NAMESTORE_RecordFlags flags,
145 * Store a Merkle tree node in the datastore.
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
155 * @return GNUNET_OK on success
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);
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.
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
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);
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).
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
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);
207 * Get a particular node from the signature tree.
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
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);
222 * Get the current signature for a zone.
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
229 int (*get_signature) (void *cls,
230 const GNUNET_HashCode *zone,
231 GNUNET_NAMESTORE_SignatureCallback cb, void *cb_cls);
235 * Delete an entire zone (all revisions, all records, all nodes,
236 * all signatures). Not used in normal operation.
238 * @param cls closure (internal context for the plugin)
239 * @param zone zone to delete
241 void (*delete_zone) (void *cls,
242 const GNUNET_HashCode *zone);
248 #if 0 /* keep Emacsens' auto-indent happy */
255 /* end of gnunet_namestore_plugin.h */