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 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)
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,
66 struct GNUNET_TIME_Absolute expiration,
67 enum GNUNET_NAMESTORE_RecordFlags flags,
73 * Function called with the matching node.
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
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);
92 * Function called with the matching signature.
95 * @param zone public key of the zone
96 * @param loc location of the root in the B-tree (depth, revision)
98 * @param root_hash top level hash that is being signed
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);
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 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
134 int (*put_record) (void *cls,
135 const GNUNET_HashCode *zone,
136 const GNUNET_HashCode *record_hash,
137 const GNUNET_HashCode *record_key,
139 uint32_t record_type,
140 struct GNUNET_TIME_Absolute expiration,
141 enum GNUNET_NAMESTORE_RecordFlags flags,
147 * Store a Merkle tree node in the datastore.
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
156 * @return GNUNET_OK on success
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);
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.
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
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);
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).
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
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);
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 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);
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 void (*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 */