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_namestore_service.h"
37 #if 0 /* keep Emacsens' auto-indent happy */
44 * Function called by for each matching record.
47 * @param zone hash of the public key of the zone
48 * @param record_hash hash of the record
49 * @param record_key XOR of zone and hash of name
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,
60 const GNUNET_HashCode *record_hash,
61 const GNUNET_HashCode *record_key,
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 struct 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)
96 * @param root_hash top level hash that is being signed
98 typedef void (*GNUNET_NAMESTORE_SignatureCallback) (void *cls,
99 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
100 const struct GNUNET_NAMESTORE_SignatureLocation *loc,
101 const struct GNUNET_CRYPTO_RsaSignature *top_sig,
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 record_hash hash of the record
122 * @param record_key XOR of zone and hash of name
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 expiration expiration time for the content
126 * @param flags flags for the content
127 * @param data_size number of bytes in data
128 * @param data value, semantics depend on 'record_type' (see RFCs for DNS and
129 * GNS specification for GNS extensions)
130 * @return GNUNET_OK on success
132 int (*put_record) (void *cls,
133 const GNUNET_HashCode *zone,
134 const GNUNET_HashCode *record_hash,
135 const GNUNET_HashCode *record_key,
137 uint32_t record_type,
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), NULL for root
151 * @param num_entries number of entries at this node in the B-tree
152 * @param entries the 'num_entries' entries to store (hashes over the
154 * @return GNUNET_OK on success
156 int (*put_node) (void *cls,
157 const struct GNUNET_HashCode *zone,
158 const struct GNUNET_NAMESTORE_SignatureLocation *loc,
159 const struct GNUNET_NAMESTORE_SignatureLocation *ploc,
160 unsigned int num_entries,
161 const GNUNET_HashCode *entries);
165 * Store a zone signature in the datastore. If a signature for the zone with a
166 * lower depth exists, the old signature is removed. If a signature for an
167 * older revision of the zone exists, this will delete all records, nodes
168 * and signatures for the older revision of the zone.
170 * @param cls closure (internal context for the plugin)
171 * @param zone_key public key of the zone
172 * @param loc location in the B-tree (top of the tree, offset 0, depth at 'maximum')
173 * @param top_sig signature at the top, NULL if 'loc.depth > 0'
174 * @param root_hash top level hash that is 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);
185 * Iterate over the results for a particular key and zone in the
186 * datastore. Will only query the latest revision known for the
187 * zone (as adding a new zone revision will cause the plugin to
188 * delete all records from previous revisions).
190 * @param cls closure (internal context for the plugin)
191 * @param zone hash of public key of the zone
192 * @param record_key key for the record (XOR of zone and hash of name);
193 * 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 *record_key,
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 */