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