aboutsummaryrefslogtreecommitdiff
path: root/src/gns/plugin_block_gns.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gns/plugin_block_gns.c')
-rw-r--r--src/gns/plugin_block_gns.c290
1 files changed, 0 insertions, 290 deletions
diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c
deleted file mode 100644
index a683ecacc..000000000
--- a/src/gns/plugin_block_gns.c
+++ /dev/null
@@ -1,290 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2010-2013, 2021, 2022 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file gns/plugin_block_gns.c
23 * @brief blocks used for GNS records
24 * @author Martin Schanzenbach
25 * @author Christian Grothoff
26 */
27
28#include "platform.h"
29#include "gnunet_block_group_lib.h"
30#include "gnunet_block_plugin.h"
31#include "gnunet_namestore_service.h"
32#include "gnunet_signatures.h"
33
34/**
35 * Number of bits we set per entry in the bloomfilter.
36 * Do not change! -from fs
37 */
38#define BLOOMFILTER_K 16
39
40/**
41 * How big is the BF we use for GNS blocks?
42 */
43#define GNS_BF_SIZE 8
44
45
46/**
47 * Create a new block group.
48 *
49 * @param ctx block context in which the block group is created
50 * @param type type of the block for which we are creating the group
51 * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh
52 * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh
53 * @param va variable arguments specific to @a type
54 * @return block group handle, NULL if block groups are not supported
55 * by this @a type of block (this is not an error)
56 */
57static struct GNUNET_BLOCK_Group *
58block_plugin_gns_create_group (void *cls,
59 enum GNUNET_BLOCK_Type type,
60 const void *raw_data,
61 size_t raw_data_size,
62 va_list va)
63{
64 unsigned int bf_size;
65 const char *guard;
66
67 guard = va_arg (va, const char *);
68 if (0 == strcmp (guard,
69 "seen-set-size"))
70 bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned
71 int),
72 BLOOMFILTER_K);
73 else if (0 == strcmp (guard,
74 "filter-size"))
75 bf_size = va_arg (va, unsigned int);
76 else
77 {
78 GNUNET_break (0);
79 bf_size = GNS_BF_SIZE;
80 }
81 GNUNET_break (NULL == va_arg (va, const char *));
82 return GNUNET_BLOCK_GROUP_bf_create (cls,
83 bf_size,
84 BLOOMFILTER_K,
85 type,
86 raw_data,
87 raw_data_size);
88}
89
90
91/**
92 * Function called to obtain the key for a block.
93 * If the @a block is malformed, the function should
94 * zero-out @a key and return #GNUNET_OK.
95 *
96 * @param cls closure
97 * @param type block type
98 * @param reply_block block to get the key for
99 * @param reply_block_size number of bytes in @a reply_block
100 * @param key set to the key (query) for the given block
101 * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported, #GNUNET_NO if extracting a key from a block of this type does not work
102 */
103static enum GNUNET_GenericReturnValue
104block_plugin_gns_get_key (void *cls,
105 enum GNUNET_BLOCK_Type type,
106 const void *reply_block,
107 size_t reply_block_size,
108 struct GNUNET_HashCode *key)
109{
110 const struct GNUNET_GNSRECORD_Block *block;
111
112 if (GNUNET_BLOCK_TYPE_GNS_NAMERECORD != type)
113 {
114 GNUNET_break (0);
115 return GNUNET_SYSERR;
116 }
117 if (reply_block_size < sizeof(struct GNUNET_GNSRECORD_Block))
118 {
119 GNUNET_break_op (0);
120 memset (key,
121 0,
122 sizeof (*key));
123 return GNUNET_OK;
124 }
125 block = reply_block;
126 GNUNET_GNSRECORD_query_from_block (block,
127 key);
128 return GNUNET_OK;
129}
130
131
132/**
133 * Function called to validate a query.
134 *
135 * @param cls closure
136 * @param ctx block context
137 * @param type block type
138 * @param query original query (hash)
139 * @param xquery extrended query data (can be NULL, depending on type)
140 * @param xquery_size number of bytes in @a xquery
141 * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not
142 */
143static enum GNUNET_GenericReturnValue
144block_plugin_gns_check_query (void *cls,
145 enum GNUNET_BLOCK_Type type,
146 const struct GNUNET_HashCode *query,
147 const void *xquery,
148 size_t xquery_size)
149{
150 if (GNUNET_BLOCK_TYPE_GNS_NAMERECORD != type)
151 {
152 GNUNET_break (0);
153 return GNUNET_SYSERR;
154 }
155 if (0 != xquery_size)
156 {
157 GNUNET_break_op (0);
158 return GNUNET_NO;
159 }
160 return GNUNET_OK;
161}
162
163
164/**
165 * Function called to validate a block for storage.
166 *
167 * @param cls closure
168 * @param type block type
169 * @param block block data to validate
170 * @param block_size number of bytes in @a block
171 * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not
172 */
173static enum GNUNET_GenericReturnValue
174block_plugin_gns_check_block (void *cls,
175 enum GNUNET_BLOCK_Type type,
176 const void *block,
177 size_t block_size)
178{
179 const struct GNUNET_GNSRECORD_Block *gblock;
180
181 if (GNUNET_BLOCK_TYPE_GNS_NAMERECORD != type)
182 {
183 GNUNET_break (0);
184 return GNUNET_SYSERR;
185 }
186 if (block_size < sizeof(struct GNUNET_GNSRECORD_Block))
187 {
188 GNUNET_break_op (0);
189 return GNUNET_NO;
190 }
191 gblock = block;
192 if (GNUNET_GNSRECORD_block_get_size (gblock) > block_size)
193 {
194 GNUNET_break_op (0);
195 return GNUNET_NO;
196 }
197 if (GNUNET_OK !=
198 GNUNET_GNSRECORD_block_verify (gblock))
199 {
200 GNUNET_break_op (0);
201 return GNUNET_NO;
202 }
203 return GNUNET_OK;
204}
205
206
207/**
208 * Function called to validate a reply to a request. Note that it is assumed
209 * that the reply has already been matched to the key (and signatures checked)
210 * as it would be done with the GetKeyFunction and the
211 * BlockEvaluationFunction.
212 *
213 * @param cls closure
214 * @param type block type
215 * @param group which block group to use for evaluation
216 * @param query original query (hash)
217 * @param xquery extrended query data (can be NULL, depending on type)
218 * @param xquery_size number of bytes in @a xquery
219 * @param reply_block response to validate
220 * @param reply_block_size number of bytes in @a reply_block
221 * @return characterization of result
222 */
223static enum GNUNET_BLOCK_ReplyEvaluationResult
224block_plugin_gns_check_reply (void *cls,
225 enum GNUNET_BLOCK_Type type,
226 struct GNUNET_BLOCK_Group *group,
227 const struct GNUNET_HashCode *query,
228 const void *xquery,
229 size_t xquery_size,
230 const void *reply_block,
231 size_t reply_block_size)
232{
233 const struct GNUNET_GNSRECORD_Block *block = reply_block;
234 struct GNUNET_HashCode chash;
235
236 if (GNUNET_BLOCK_TYPE_GNS_NAMERECORD != type)
237 {
238 GNUNET_break (0);
239 return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED;
240 }
241 GNUNET_assert (reply_block_size >= sizeof(struct GNUNET_GNSRECORD_Block));
242 GNUNET_assert (reply_block_size >= GNUNET_GNSRECORD_block_get_size (block));
243 GNUNET_CRYPTO_hash (reply_block,
244 reply_block_size,
245 &chash);
246 if (GNUNET_YES ==
247 GNUNET_BLOCK_GROUP_bf_test_and_set (group,
248 &chash))
249 return GNUNET_BLOCK_REPLY_OK_DUPLICATE;
250 return GNUNET_BLOCK_REPLY_OK_MORE;
251}
252
253
254/**
255 * Entry point for the plugin.
256 */
257void *
258libgnunet_plugin_block_gns_init (void *cls)
259{
260 static const enum GNUNET_BLOCK_Type types[] = {
261 GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
262 GNUNET_BLOCK_TYPE_ANY /* end of list */
263 };
264 struct GNUNET_BLOCK_PluginFunctions *api;
265
266 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
267 api->get_key = &block_plugin_gns_get_key;
268 api->create_group = &block_plugin_gns_create_group;
269 api->check_query = &block_plugin_gns_check_query;
270 api->check_block = &block_plugin_gns_check_block;
271 api->check_reply = &block_plugin_gns_check_reply;
272 api->types = types;
273 return api;
274}
275
276
277/**
278 * Exit point from the plugin.
279 */
280void *
281libgnunet_plugin_block_gns_done (void *cls)
282{
283 struct GNUNET_BLOCK_PluginFunctions *api = cls;
284
285 GNUNET_free (api);
286 return NULL;
287}
288
289
290/* end of plugin_block_gns.c */