-towards namestore support for the new privacy-preserving GNS queries
[oweals/gnunet.git] / src / include / gnunet_namestore_plugin.h
1 /*
2      This file is part of GNUnet
3      (C) 2012, 2013 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 3, 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 #ifndef GNUNET_NAMESTORE_PLUGIN_H
27 #define GNUNET_NAMESTORE_PLUGIN_H
28
29 #include "gnunet_common.h"
30 #include "gnunet_util_lib.h"
31 #include "gnunet_namestore_service.h"
32
33 #ifdef __cplusplus
34 extern "C"
35 {
36 #if 0                           /* keep Emacsens' auto-indent happy */
37 }
38 #endif
39 #endif
40
41
42 /**
43  * Function called for matching blocks.
44  *
45  * @param cls closure
46  * @param block lookup result
47  */
48 typedef void (*GNUNET_NAMESTORE_BlockCallback) (void *cls,
49                                                 const struct GNUNET_NAMESTORE_Block *block);
50
51
52 /**
53  * Function called by for each matching record.
54  *
55  * @param cls closure
56  * @param zone_key private key of the zone
57  * @param label name that is being mapped (at most 255 characters long)
58  * @param rd_count number of entries in 'rd' array
59  * @param rd array of records with data to store
60  */
61 typedef void (*GNUNET_NAMESTORE_RecordIterator) (void *cls,
62                                                  const struct GNUNET_CRYPTO_EccPrivateKey *private_key,
63                                                  const char *label,
64                                                  unsigned int rd_count,
65                                                  const struct GNUNET_NAMESTORE_RecordData *rd);
66
67
68 /**
69  * @brief struct returned by the initialization function of the plugin
70  */
71 struct GNUNET_NAMESTORE_PluginFunctions
72 {
73
74   /**
75    * Closure to pass to all plugin functions.
76    */
77   void *cls;
78
79   /**
80    * Cache a block in the datastore. Overwrites (older) existing blocks
81    * for the same zone and label.
82    *
83    * @param cls closure (internal context for the plugin)
84    * @param block block to cache
85    * @return GNUNET_OK on success, else GNUNET_SYSERR
86    */
87   int (*cache_block) (void *cls, 
88                       const struct GNUNET_NAMESTORE_Block *block);
89
90
91   /**
92    * Get the block for a particular zone and label in the
93    * datastore.  Will return at most one result to the iterator.
94    *
95    * @param cls closure (internal context for the plugin)
96    * @param query hash of public key derived from the zone and the label
97    * @param iter function to call with the result
98    * @param iter_cls closure for iter
99    * @return GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error
100    *         'iter' will have been called unless the return value is 'GNUNET_SYSERR'
101    */
102   int (*lookup_block) (void *cls, 
103                        const struct GNUNET_HashCode *query,
104                        GNUNET_NAMESTORE_BlockCallback iter, void *iter_cls);
105
106
107
108   /**
109    * Store a record in the datastore for which we are the authority.
110    * Removes any existing record in the same zone with the same name.
111    *
112    * @param cls closure (internal context for the plugin)
113    * @param zone private key of the zone
114    * @param label name of the record in the zone
115    * @param rd_count number of entries in 'rd' array, 0 to delete all records
116    * @param rd array of records with data to store
117    * @return GNUNET_OK on success, else GNUNET_SYSERR
118    */
119   int (*store_records) (void *cls, 
120                         const struct GNUNET_CRYPTO_EccPrivateKey *zone,
121                         const char *label,
122                         unsigned int rd_count,
123                         const struct GNUNET_NAMESTORE_RecordData *rd);
124
125
126   /**
127    * Iterate over the results for a particular zone in the
128    * datastore.  Will return at most one result to the iterator.
129    *
130    * @param cls closure (internal context for the plugin)
131    * @param zone private key of the zone
132    * @param offset offset in the list of all matching records
133    * @param iter function to call with the result
134    * @param iter_cls closure for iter
135    * @return GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error
136    *       'iter' will have been called unless the return value is 'GNUNET_SYSERR'
137    */
138   int (*iterate_records) (void *cls, 
139                           const struct GNUNET_CRYPTO_EccPrivateKey *zone,
140                           uint64_t offset,
141                           GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls);
142
143
144   /**
145    * Look for an existing PKEY delegation record for a given public key.
146    * Returns at most one result to the iterator.
147    *
148    * @param cls closure (internal context for the plugin)
149    * @param zone private key of the zone to look up in, never NULL
150    * @param value_zone public key of the target zone (value), never NULL
151    * @param iter function to call with the result
152    * @param iter_cls closure for iter
153    * @return GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error
154    *       'iter' will have been called unless the return value is 'GNUNET_SYSERR'
155    */
156   int (*zone_to_name) (void *cls, 
157                        const struct GNUNET_CRYPTO_EccPrivateKey *zone,
158                        const struct GNUNET_CRYPTO_EccPublicKey *value_zone,
159                        GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls);
160
161
162 };
163
164
165 #if 0                           /* keep Emacsens' auto-indent happy */
166 {
167 #endif
168 #ifdef __cplusplus
169 }
170 #endif
171
172 /* end of gnunet_namestore_plugin.h */
173 #endif