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 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)
58 typedef void (*GNUNET_NAMESTORE_RecordIterator) (void *cls,
59 const GNUNET_HashCode *zone,
62 struct GNUNET_TIME_Absolute expiration,
63 enum GNUNET_NAMESTORE_RecordFlags flags,
69 * Function called with the matching node.
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
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);
88 * Function called with the matching signature.
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
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);
106 * @brief struct returned by the initialization function of the plugin
108 struct GNUNET_NAMESTORE_PluginFunctions
112 * Closure to pass to all plugin functions.
117 * Store a record in the datastore.
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
131 int (*put_record) (void *cls,
132 const GNUNET_HashCode *zone,
134 uint32_t record_type,
135 const struct GNUNET_NAMESTORE_SignatureLocation *loc,
136 struct GNUNET_TIME_Absolute expiration,
137 enum GNUNET_NAMESTORE_RecordFlags flags,
143 * Store a Merkle tree node in the datastore.
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
153 * @return GNUNET_OK on success
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);
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.
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
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);
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).
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
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);
205 * Get a particular node from the signature tree.
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
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);
220 * Get the current signature for a zone.
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
227 void (*get_signature) (void *cls,
228 const GNUNET_HashCode *zone,
229 GNUNET_NAMESTORE_SignatureCallback cb, void *cb_cls);
233 * Delete an entire zone (all revisions, all records, all nodes,
234 * all signatures). Not used in normal operation.
236 * @param cls closure (internal context for the plugin)
237 * @param zone zone to delete
239 void (*delete_zone) (void *cls,
240 const GNUNET_HashCode *zone);
246 #if 0 /* keep Emacsens' auto-indent happy */
253 /* end of gnunet_namestore_plugin.h */