aboutsummaryrefslogtreecommitdiff
path: root/src/fs/plugin_block_fs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/plugin_block_fs.c')
-rw-r--r--src/fs/plugin_block_fs.c337
1 files changed, 0 insertions, 337 deletions
diff --git a/src/fs/plugin_block_fs.c b/src/fs/plugin_block_fs.c
deleted file mode 100644
index 18aa289ef..000000000
--- a/src/fs/plugin_block_fs.c
+++ /dev/null
@@ -1,337 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2010, 2013, 2021 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 fs/plugin_block_fs.c
23 * @brief blocks used for file-sharing
24 * @author Christian Grothoff
25 */
26#include "platform.h"
27#include "gnunet_block_plugin.h"
28#include "gnunet_fs_service.h"
29#include "block_fs.h"
30#include "gnunet_signatures.h"
31#include "gnunet_block_group_lib.h"
32
33
34/**
35 * Number of bits we set per entry in the bloomfilter.
36 * Do not change!
37 */
38#define BLOOMFILTER_K 16
39
40
41/**
42 * Create a new block group.
43 *
44 * @param ctx block context in which the block group is created
45 * @param type type of the block for which we are creating the group
46 * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh
47 * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh
48 * @param va variable arguments specific to @a type
49 * @return block group handle, NULL if block groups are not supported
50 * by this @a type of block (this is not an error)
51 */
52static struct GNUNET_BLOCK_Group *
53block_plugin_fs_create_group (void *cls,
54 enum GNUNET_BLOCK_Type type,
55 const void *raw_data,
56 size_t raw_data_size,
57 va_list va)
58{
59 unsigned int size;
60 const char *guard;
61
62 switch (type)
63 {
64 case GNUNET_BLOCK_TYPE_FS_DBLOCK:
65 GNUNET_break (NULL == va_arg (va, const char *));
66 return NULL;
67 case GNUNET_BLOCK_TYPE_FS_IBLOCK:
68 GNUNET_break (NULL == va_arg (va, const char *));
69 return NULL;
70 case GNUNET_BLOCK_TYPE_FS_UBLOCK:
71 guard = va_arg (va, const char *);
72 if (0 == strcmp (guard,
73 "seen-set-size"))
74 {
75 size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned
76 int),
77 BLOOMFILTER_K);
78 }
79 else if (0 == strcmp (guard,
80 "filter-size"))
81 {
82 size = va_arg (va, unsigned int);
83 }
84 else
85 {
86 /* va-args invalid! bad bug, complain! */
87 GNUNET_break (0);
88 size = 8;
89 }
90 if (0 == size)
91 size = raw_data_size; /* not for us to determine, use what we got! */
92 GNUNET_break (NULL == va_arg (va, const char *));
93 return GNUNET_BLOCK_GROUP_bf_create (cls,
94 size,
95 BLOOMFILTER_K,
96 type,
97 raw_data,
98 raw_data_size);
99
100 default:
101 GNUNET_break (NULL == va_arg (va, const char *));
102 GNUNET_break (0);
103 return NULL;
104 }
105}
106
107
108/**
109 * Function called to obtain the key for a block.
110 *
111 * @param cls closure
112 * @param type block type
113 * @param block block to get the key for
114 * @param block_size number of bytes in @a block
115 * @param key set to the key (query) for the given block
116 * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported
117 * (or if extracting a key from a block of this type does not work)
118 */
119static enum GNUNET_GenericReturnValue
120block_plugin_fs_get_key (void *cls,
121 enum GNUNET_BLOCK_Type type,
122 const void *block,
123 size_t block_size,
124 struct GNUNET_HashCode *key)
125{
126 const struct UBlock *ub;
127
128 switch (type)
129 {
130 case GNUNET_BLOCK_TYPE_FS_DBLOCK:
131 case GNUNET_BLOCK_TYPE_FS_IBLOCK:
132 GNUNET_CRYPTO_hash (block,
133 block_size,
134 key);
135 return GNUNET_OK;
136 case GNUNET_BLOCK_TYPE_FS_UBLOCK:
137 if (block_size < sizeof(struct UBlock))
138 {
139 GNUNET_break_op (0);
140 memset (key,
141 0,
142 sizeof (*key));
143 return GNUNET_OK;
144 }
145 ub = block;
146 GNUNET_CRYPTO_hash (&ub->verification_key,
147 sizeof(ub->verification_key),
148 key);
149 return GNUNET_OK;
150 default:
151 GNUNET_break (0);
152 return GNUNET_SYSERR;
153 }
154}
155
156
157/**
158 * Function called to validate a query.
159 *
160 * @param cls closure
161 * @param ctx block context
162 * @param type block type
163 * @param query original query (hash)
164 * @param xquery extrended query data (can be NULL, depending on type)
165 * @param xquery_size number of bytes in @a xquery
166 * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not
167 */
168static enum GNUNET_GenericReturnValue
169block_plugin_fs_check_query (void *cls,
170 enum GNUNET_BLOCK_Type type,
171 const struct GNUNET_HashCode *query,
172 const void *xquery,
173 size_t xquery_size)
174{
175 switch (type)
176 {
177 case GNUNET_BLOCK_TYPE_FS_DBLOCK:
178 case GNUNET_BLOCK_TYPE_FS_IBLOCK:
179 case GNUNET_BLOCK_TYPE_FS_UBLOCK:
180 if (0 != xquery_size)
181 {
182 GNUNET_break_op (0);
183 return GNUNET_NO;
184 }
185 return GNUNET_OK;
186 default:
187 GNUNET_break (0);
188 return GNUNET_SYSERR;
189 }
190}
191
192
193/**
194 * Function called to validate a block for storage.
195 *
196 * @param cls closure
197 * @param type block type
198 * @param block block data to validate
199 * @param block_size number of bytes in @a block
200 * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not
201 */
202static enum GNUNET_GenericReturnValue
203block_plugin_fs_check_block (void *cls,
204 enum GNUNET_BLOCK_Type type,
205 const void *block,
206 size_t block_size)
207{
208 switch (type)
209 {
210 case GNUNET_BLOCK_TYPE_FS_DBLOCK:
211 case GNUNET_BLOCK_TYPE_FS_IBLOCK:
212 return GNUNET_OK;
213 case GNUNET_BLOCK_TYPE_FS_UBLOCK:
214 {
215 const struct UBlock *ub;
216
217 if (block_size < sizeof(struct UBlock))
218 {
219 GNUNET_break_op (0);
220 return GNUNET_NO;
221 }
222 ub = block;
223 if (block_size !=
224 ntohl (ub->purpose.size)
225 + sizeof (struct GNUNET_CRYPTO_EcdsaSignature))
226 {
227 GNUNET_break_op (0);
228 return GNUNET_NO;
229 }
230 if (GNUNET_OK !=
231 GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK,
232 &ub->purpose,
233 &ub->signature,
234 &ub->verification_key))
235 {
236 GNUNET_break_op (0);
237 return GNUNET_NO;
238 }
239 return GNUNET_OK;
240 }
241 default:
242 GNUNET_break (0);
243 return GNUNET_SYSERR;
244 }
245}
246
247
248/**
249 * Function called to validate a reply to a request. Note that it is assumed
250 * that the reply has already been matched to the key (and signatures checked)
251 * as it would be done with the GetKeyFunction and the
252 * BlockEvaluationFunction.
253 *
254 * @param cls closure
255 * @param type block type
256 * @param group which block group to use for evaluation
257 * @param query original query (hash)
258 * @param xquery extrended query data (can be NULL, depending on type)
259 * @param xquery_size number of bytes in @a xquery
260 * @param reply_block response to validate
261 * @param reply_block_size number of bytes in @a reply_block
262 * @return characterization of result
263 */
264static enum GNUNET_BLOCK_ReplyEvaluationResult
265block_plugin_fs_check_reply (void *cls,
266 enum GNUNET_BLOCK_Type type,
267 struct GNUNET_BLOCK_Group *group,
268 const struct GNUNET_HashCode *query,
269 const void *xquery,
270 size_t xquery_size,
271 const void *reply_block,
272 size_t reply_block_size)
273{
274 switch (type)
275 {
276 case GNUNET_BLOCK_TYPE_FS_DBLOCK:
277 case GNUNET_BLOCK_TYPE_FS_IBLOCK:
278 return GNUNET_BLOCK_REPLY_OK_LAST;
279 case GNUNET_BLOCK_TYPE_FS_UBLOCK:
280 {
281 struct GNUNET_HashCode chash;
282
283 GNUNET_CRYPTO_hash (reply_block,
284 reply_block_size,
285 &chash);
286 if (GNUNET_YES ==
287 GNUNET_BLOCK_GROUP_bf_test_and_set (group,
288 &chash))
289 return GNUNET_BLOCK_REPLY_OK_DUPLICATE;
290 return GNUNET_BLOCK_REPLY_OK_MORE;
291 }
292 default:
293 GNUNET_break (0);
294 return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED;
295 }
296}
297
298
299/**
300 * Entry point for the plugin.
301 */
302void *
303libgnunet_plugin_block_fs_init (void *cls)
304{
305 static const enum GNUNET_BLOCK_Type types[] = {
306 GNUNET_BLOCK_TYPE_FS_DBLOCK,
307 GNUNET_BLOCK_TYPE_FS_IBLOCK,
308 GNUNET_BLOCK_TYPE_FS_UBLOCK,
309 GNUNET_BLOCK_TYPE_ANY /* end of list */
310 };
311 struct GNUNET_BLOCK_PluginFunctions *api;
312
313 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
314 api->get_key = &block_plugin_fs_get_key;
315 api->create_group = &block_plugin_fs_create_group;
316 api->check_query = &block_plugin_fs_check_query;
317 api->check_block = &block_plugin_fs_check_block;
318 api->check_reply = &block_plugin_fs_check_reply;
319 api->types = types;
320 return api;
321}
322
323
324/**
325 * Exit point from the plugin.
326 */
327void *
328libgnunet_plugin_block_fs_done (void *cls)
329{
330 struct GNUNET_BLOCK_PluginFunctions *api = cls;
331
332 GNUNET_free (api);
333 return NULL;
334}
335
336
337/* end of plugin_block_fs.c */