aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-09-12 13:08:54 +0000
committerChristian Grothoff <christian@grothoff.org>2010-09-12 13:08:54 +0000
commita42b4e0ed22b65631caea4bb456f3d8fc21f11b1 (patch)
treea3a1e30a7f8e7f8b30c75c96923249831a7e8b2e
parentdd253b7f7591f0869f8ea14ee111b7d3b3e480b6 (diff)
downloadgnunet-a42b4e0ed22b65631caea4bb456f3d8fc21f11b1.tar.gz
gnunet-a42b4e0ed22b65631caea4bb456f3d8fc21f11b1.zip
towards pluggable block library
-rw-r--r--TODO13
-rw-r--r--src/block/Makefile.am23
-rw-r--r--src/block/block.c181
-rw-r--r--src/block/plugin_block.h117
-rw-r--r--src/block/plugin_block_fs.c346
-rw-r--r--src/block/plugin_block_template.c118
-rw-r--r--src/include/gnunet_block_lib.h125
-rw-r--r--src/transport/Makefile.am6
8 files changed, 924 insertions, 5 deletions
diff --git a/TODO b/TODO
index 8ac9a592c..9349189b3 100644
--- a/TODO
+++ b/TODO
@@ -1,4 +1,15 @@
10.9.0pre2: 10.9.0pre2:
2* BLOCK:
3 - implement FS plugin
4 - design new block-lib API
5 - move FS serivce to new block API
6* FS:
7 - integrate with DHT
8 - measure latencies (core, datastore) => trust economy
9 - refuse content migration message (or solicit?)
10 - FS performance benchmarking
11* DHT:
12 - use new block lib
2* CORE: 13* CORE:
3 - derived key generation [Nils] 14 - derived key generation [Nils]
4 - Jun 27 11:51:54 core-7670 ERROR Assertion failed at gnunet-service-core.c:3616. 15 - Jun 27 11:51:54 core-7670 ERROR Assertion failed at gnunet-service-core.c:3616.
@@ -23,7 +34,7 @@
23 - needs more testing (especially F2F topology) & transport blacklisting 34 - needs more testing (especially F2F topology) & transport blacklisting
24* TRANSPORT-TCP [MW]: 35* TRANSPORT-TCP [MW]:
25 - should use hash map to look up sessions 36 - should use hash map to look up sessions
26* NAT/UPNP: [MW] 37* NAT/UPNP: [Milan]
27 - finalize API design 38 - finalize API design
28 - code clean up 39 - code clean up
29 - testing 40 - testing
diff --git a/src/block/Makefile.am b/src/block/Makefile.am
index b9585c260..238c48af3 100644
--- a/src/block/Makefile.am
+++ b/src/block/Makefile.am
@@ -1,5 +1,7 @@
1INCLUDES = -I$(top_srcdir)/src/include 1INCLUDES = -I$(top_srcdir)/src/include
2 2
3plugindir = $(libdir)/gnunet
4
3if MINGW 5if MINGW
4 WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols 6 WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
5endif 7endif
@@ -10,8 +12,27 @@ endif
10 12
11lib_LTLIBRARIES = libgnunetblock.la 13lib_LTLIBRARIES = libgnunetblock.la
12 14
15plugin_LTLIBRARIES = \
16 libgnunet_plugin_block_fs.la \
17 libgnunet_plugin_block_template.la
18
19libgnunet_plugin_block_fs_la_SOURCES = \
20 plugin_block_fs.c
21libgnunet_plugin_block_fs_la_LIBADD = \
22 $(top_builddir)/src/util/libgnunetutil.la
23libgnunet_plugin_block_fs_la_LDFLAGS = \
24 $(GN_PLUGIN_LDFLAGS)
25
26libgnunet_plugin_block_template_la_SOURCES = \
27 plugin_block_template.c
28libgnunet_plugin_block_template_la_LIBADD = \
29 $(top_builddir)/src/util/libgnunetutil.la
30libgnunet_plugin_block_template_la_LDFLAGS = \
31 $(GN_PLUGIN_LDFLAGS)
32
33
13libgnunetblock_la_SOURCES = \ 34libgnunetblock_la_SOURCES = \
14 block.c 35 block.c plugin_block.h
15libgnunetblock_la_LIBADD = \ 36libgnunetblock_la_LIBADD = \
16 $(top_builddir)/src/util/libgnunetutil.la 37 $(top_builddir)/src/util/libgnunetutil.la
17 38
diff --git a/src/block/block.c b/src/block/block.c
index 72dedd7be..cb6837499 100644
--- a/src/block/block.c
+++ b/src/block/block.c
@@ -27,6 +27,7 @@
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_signatures.h" 28#include "gnunet_signatures.h"
29#include "gnunet_block_lib.h" 29#include "gnunet_block_lib.h"
30#include "plugin_block.h"
30 31
31/** 32/**
32 * Check if the given KBlock is well-formed. 33 * Check if the given KBlock is well-formed.
@@ -226,5 +227,185 @@ GNUNET_BLOCK_check_block (enum GNUNET_BLOCK_Type type,
226 return GNUNET_OK; 227 return GNUNET_OK;
227} 228}
228 229
230/* ***************** NEW API ******************* */
231
232/**
233 * Handle for a plugin.
234 */
235struct Plugin
236{
237 /**
238 * Name of the shared library.
239 */
240 char *library_name;
241
242 /**
243 * Plugin API.
244 */
245 struct GNUNET_BLOCK_PluginFunctions *api;
246};
247
248/**
249 * Handle to an initialized block library.
250 */
251struct GNUNET_BLOCK_Context
252{
253 /**
254 * NULL-terminated array of our plugins.
255 */
256 struct Plugin **plugins;
257
258 /**
259 * Our configuration.
260 */
261 const struct GNUNET_CONFIGURATION_Handle *cfg;
262};
263
264
265/**
266 * Create a block context. Loads the block plugins.
267 *
268 * @param cfg configuration to use
269 * @return NULL on error
270 */
271struct GNUNET_BLOCK_Context *
272GNUNET_BLOCK_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg)
273{
274 struct GNUNET_BLOCK_Context *ctx;
275 unsigned int num_plugins;
276
277 ctx = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_Context));
278 ctx->cfg = cfg;
279 num_plugins = 0;
280 /* FIXME: actually load plugins... */
281 GNUNET_array_append (ctx->plugins,
282 num_plugins,
283 NULL);
284 return ctx;
285}
286
287
288/**
289 * Destroy the block context.
290 *
291 * @param ctx context to destroy
292 */
293void
294GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx)
295{
296 unsigned int i;
297 struct Plugin *plugin;
298
299 i = 0;
300 while (NULL != (plugin = ctx->plugins[i]))
301 {
302 GNUNET_break (NULL ==
303 GNUNET_PLUGIN_unload (plugin->library_name,
304 plugin->api));
305 GNUNET_free (plugin->library_name);
306 GNUNET_free (plugin);
307 i++;
308 }
309 GNUNET_free (ctx->plugins);
310 GNUNET_free (ctx);
311}
312
313
314/**
315 * Find a plugin for the given type.
316 *
317 * @param ctx context to search
318 * @param type type to look for
319 * @return NULL if no matching plugin exists
320 */
321static struct GNUNET_BLOCK_PluginFunctions *
322find_plugin (struct GNUNET_BLOCK_Context *ctx,
323 enum GNUNET_BLOCK_Type type)
324{
325 struct Plugin *plugin;
326 unsigned int i;
327 unsigned int j;
328
329 i = 0;
330 while (NULL != (plugin = ctx->plugins[i]))
331 {
332 j = 0;
333 while (0 != (plugin->api->types[j]))
334 {
335 if (type == plugin->api->types[j])
336 return plugin->api;
337 j++;
338 }
339 i++;
340 }
341 return NULL;
342}
343
344
345/**
346 * Function called to validate a reply or a request. For
347 * request evaluation, simply pass "NULL" for the reply_block.
348 * Note that it is assumed that the reply has already been
349 * matched to the key (and signatures checked) as it would
350 * be done with the "get_key" function.
351 *
352 * @param ctx block contxt
353 * @param type block type
354 * @param query original query (hash)
355 * @param bf pointer to bloom filter associated with query; possibly updated (!)
356 * @param bf_mutator mutation value for bf
357 * @param xquery extrended query data (can be NULL, depending on type)
358 * @param xquery_size number of bytes in xquery
359 * @param reply_block response to validate
360 * @param reply_block_size number of bytes in reply block
361 * @return characterization of result
362 */
363enum GNUNET_BLOCK_EvaluationResult
364GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx,
365 enum GNUNET_BLOCK_Type type,
366 const GNUNET_HashCode *query,
367 struct GNUNET_CONTAINER_BloomFilter **bf,
368 int32_t bf_mutator,
369 const void *xquery,
370 size_t xquery_size,
371 const void *reply_block,
372 size_t reply_block_size)
373{
374 struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx, type);
375
376 if (plugin == NULL)
377 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
378 return plugin->evaluate (plugin->cls,
379 type, query, bf, bf_mutator,
380 xquery, xquery_size, reply_block, reply_block_size);
381}
382
383
384/**
385 * Function called to obtain the key for a block.
386 *
387 * @param ctx block context
388 * @param type block type
389 * @param block block to get the key for
390 * @param block_size number of bytes in block
391 * @param key set to the key (query) for the given block
392 * @return GNUNET_OK on success, GNUNET_SYSERR if type not supported
393 * (or if extracting a key from a block of this type does not work)
394 */
395int
396GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx,
397 enum GNUNET_BLOCK_Type type,
398 const void *block,
399 size_t block_size,
400 GNUNET_HashCode *key)
401{
402 struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx, type);
403
404 if (plugin == NULL)
405 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
406 return plugin->get_key (plugin->cls,
407 type, block, block_size, key);
408}
409
229 410
230/* end of block.c */ 411/* end of block.c */
diff --git a/src/block/plugin_block.h b/src/block/plugin_block.h
new file mode 100644
index 000000000..671f83aad
--- /dev/null
+++ b/src/block/plugin_block.h
@@ -0,0 +1,117 @@
1/*
2 This file is part of GNUnet
3 (C) 2010 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 block/plugin_block.h
23 * @brief API for block plugins. Each block plugin must conform to
24 * the API specified by this header.
25 * @author Christian Grothoff
26 */
27#ifndef PLUGIN_BLOCK_H
28#define PLUGIN_BLOCK_H
29
30#include "gnunet_util_lib.h"
31#include "gnunet_container_lib.h"
32#include "gnunet_block_lib.h"
33
34
35
36/**
37 * Function called to validate a reply or a request. For
38 * request evaluation, simply pass "NULL" for the reply_block.
39 * Note that it is assumed that the reply has already been
40 * matched to the key (and signatures checked) as it would
41 * be done with the "get_key" function.
42 *
43 * @param cls closure
44 * @param type block type
45 * @param query original query (hash)
46 * @param bf pointer to bloom filter associated with query; possibly updated (!)
47 * @param bf_mutator mutation value for bf
48 * @param xquery extrended query data (can be NULL, depending on type)
49 * @param xquery_size number of bytes in xquery
50 * @param reply_block response to validate
51 * @param reply_block_size number of bytes in reply block
52 * @return characterization of result
53 */
54typedef enum GNUNET_BLOCK_EvaluationResult
55 (*GNUNET_BLOCK_EvaluationFunction) (void *cls,
56 enum GNUNET_BLOCK_Type type,
57 const GNUNET_HashCode *query,
58 struct GNUNET_CONTAINER_BloomFilter **bf,
59 int32_t bf_mutator,
60 const void *xquery,
61 size_t xquery_size,
62 const void *reply_block,
63 size_t reply_block_size);
64
65
66/**
67 * Function called to obtain the key for a block.
68 *
69 * @param cls closure
70 * @param type block type
71 * @param block block to get the key for
72 * @param block_size number of bytes in block
73 * @param key set to the key (query) for the given block
74 * @return GNUNET_OK on success, GNUNET_SYSERR if type not supported
75 * (or if extracting a key from a block of this type does not work)
76 */
77typedef int
78 (*GNUNET_BLOCK_GetKeyFunction) (void *cls,
79 enum GNUNET_BLOCK_Type type,
80 const void *block,
81 size_t block_size,
82 GNUNET_HashCode *key);
83
84
85
86/**
87 * Each plugin is required to return a pointer to a struct of this
88 * type as the return value from its entry point.
89 */
90struct GNUNET_BLOCK_PluginFunctions
91{
92
93 /**
94 * Closure for all of the callbacks.
95 */
96 void *cls;
97
98 /**
99 * 0-terminated array of block types supported by this plugin.
100 */
101 const enum GNUNET_BLOCK_Type *types;
102
103 /**
104 * Main function of a block plugin. Allows us to check if a
105 * block matches a query.
106 */
107 GNUNET_BLOCK_EvaluationFunction evaluate;
108
109 /**
110 * Obtain the key for a given block (if possible).
111 */
112 GNUNET_BLOCK_GetKeyFunction get_key;
113
114};
115
116
117#endif
diff --git a/src/block/plugin_block_fs.c b/src/block/plugin_block_fs.c
new file mode 100644
index 000000000..362932991
--- /dev/null
+++ b/src/block/plugin_block_fs.c
@@ -0,0 +1,346 @@
1/*
2 This file is part of GNUnet
3 (C) 2010 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 block/plugin_block_fs.c
23 * @brief blocks used for file-sharing
24 * @author Christian Grothoff
25 */
26
27#include "platform.h"
28#include "plugin_block.h"
29#include "gnunet_signatures.h"
30
31#define DEBUG_FS_BLOCK GNUNET_NO
32
33/**
34 * Number of bits we set per entry in the bloomfilter.
35 * Do not change!
36 */
37#define BLOOMFILTER_K 16
38
39/**
40 * Mingle hash with the mingle_number to produce different bits.
41 */
42static void
43mingle_hash (const GNUNET_HashCode * in,
44 int32_t mingle_number,
45 GNUNET_HashCode * hc)
46{
47 GNUNET_HashCode m;
48
49 GNUNET_CRYPTO_hash (&mingle_number,
50 sizeof (int32_t),
51 &m);
52 GNUNET_CRYPTO_hash_xor (&m, in, hc);
53}
54
55
56/**
57 * Function called to validate a reply or a request. For
58 * request evaluation, simply pass "NULL" for the reply_block.
59 * Note that it is assumed that the reply has already been
60 * matched to the key (and signatures checked) as it would
61 * be done with the "get_key" function.
62 *
63 * @param cls closure
64 * @param type block type
65 * @param query original query (hash)
66 * @param bf pointer to bloom filter associated with query; possibly updated (!)
67 * @param bf_mutator mutation value for bf
68 * @param xquery extrended query data (can be NULL, depending on type)
69 * @param xquery_size number of bytes in xquery
70 * @param reply_block response to validate
71 * @param reply_block_size number of bytes in reply block
72 * @return characterization of result
73 */
74static enum GNUNET_BLOCK_EvaluationResult
75block_plugin_fs_evaluate (void *cls,
76 enum GNUNET_BLOCK_Type type,
77 const GNUNET_HashCode *query,
78 struct GNUNET_CONTAINER_BloomFilter **bf,
79 int32_t bf_mutator,
80 const void *xquery,
81 size_t xquery_size,
82 const void *reply_block,
83 size_t reply_block_size)
84{
85 const struct SBlock *sb;
86 GNUNET_HashCode chash;
87 GNUNET_HashCode mhash;
88 const GNUNET_HashCode *nsid;
89 GNUNET_HashCode sh;
90
91 switch (type)
92 {
93 case GNUNET_BLOCK_TYPE_DBLOCK:
94 case GNUNET_BLOCK_TYPE_IBLOCK:
95 if (xquery_size != 0)
96 {
97 GNUNET_break_op (0);
98 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
99 }
100 return GNUNET_BLOCK_EVALUATION_OK_LAST;
101 case GNUNET_BLOCK_TYPE_KBLOCK:
102 case GNUNET_BLOCK_TYPE_NBLOCK:
103 if (xquery_size != 0)
104 {
105 GNUNET_break_op (0);
106 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
107 }
108 if (reply_block == NULL)
109 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
110 GNUNET_CRYPTO_hash (reply_block,
111 reply_block_size,
112 &chash);
113 mingle_hash (&chash, bf_mutator, &mhash);
114 if (NULL != *bf)
115 {
116 if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf,
117 &mhash))
118 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
119 }
120 else
121 {
122 *bf = GNUNET_CONTAINER_bloomfilter_init (NULL,
123 8,
124 BLOOMFILTER_K);
125 }
126 GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
127 return GNUNET_BLOCK_EVALUATION_OK_MORE;
128 case GNUNET_BLOCK_TYPE_SBLOCK:
129 if (xquery_size != sizeof (GNUNET_HashCode))
130 {
131 GNUNET_break_op (0);
132 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
133 }
134 if (reply_block == NULL)
135 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
136 nsid = xquery;
137 if (reply_block_size < sizeof (struct NBlock))
138 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
139 sb = reply_block;
140 GNUNET_CRYPTO_hash (&sb->subspace,
141 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
142 &sh);
143 if (0 != memcmp (nsid,
144 &sh,
145 sizeof (GNUNET_HashCode)))
146 {
147 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
148 _("Reply mismatched in terms of namespace. Discarded.\n"));
149 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
150 }
151 GNUNET_CRYPTO_hash (reply_block,
152 reply_block_size,
153 &chash);
154 mingle_hash (&chash, bf_mutator, &mhash);
155 if (NULL != *bf)
156 {
157 if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf,
158 &mhash))
159 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
160 }
161 else
162 {
163 *bf = GNUNET_CONTAINER_bloomfilter_init (NULL,
164 8,
165 BLOOMFILTER_K);
166 }
167 GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
168 return GNUNET_BLOCK_EVALUATION_OK_MORE;
169 default:
170 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
171 }
172}
173
174
175/**
176 * Function called to obtain the key for a block.
177 *
178 * @param cls closure
179 * @param type block type
180 * @param block block to get the key for
181 * @param block_size number of bytes in block
182 * @param key set to the key (query) for the given block
183 * @return GNUNET_OK on success, GNUNET_SYSERR if type not supported
184 * (or if extracting a key from a block of this type does not work)
185 */
186static int
187block_plugin_fs_get_key (void *cls,
188 enum GNUNET_BLOCK_Type type,
189 const void *block,
190 size_t block_size,
191 GNUNET_HashCode *key)
192{
193 const struct KBlock *kb;
194 const struct SBlock *sb;
195 const struct NBlock *nb;
196
197 switch (type)
198 {
199 case GNUNET_BLOCK_TYPE_DBLOCK:
200 case GNUNET_BLOCK_TYPE_IBLOCK:
201 GNUNET_CRYPTO_hash (block, block_size, key);
202 return GNUNET_OK;
203 case GNUNET_BLOCK_TYPE_KBLOCK:
204 if (block_size < sizeof (struct KBlock))
205 {
206 GNUNET_break_op (0);
207 return GNUNET_SYSERR;
208 }
209 kb = block;
210 if (block_size - sizeof (struct KBlock) !=
211 ntohl (kb->purpose.size)
212 - sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose)
213 - sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) )
214 {
215 GNUNET_break_op (0);
216 return GNUNET_SYSERR;
217 }
218 if (GNUNET_OK !=
219 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK,
220 &kb->purpose,
221 &kb->signature,
222 &kb->keyspace))
223 {
224 GNUNET_break_op (0);
225 return GNUNET_SYSERR;
226 }
227 if (key != NULL)
228 GNUNET_CRYPTO_hash (&kb->keyspace,
229 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
230 key);
231 return GNUNET_OK;
232 case GNUNET_BLOCK_TYPE_SBLOCK:
233 if (block_size < sizeof (struct SBlock))
234 {
235 GNUNET_break_op (0);
236 return GNUNET_SYSERR;
237 }
238 sb = block;
239 if (block_size !=
240 ntohl (sb->purpose.size) + sizeof (struct GNUNET_CRYPTO_RsaSignature))
241 {
242 GNUNET_break_op (0);
243 return GNUNET_SYSERR;
244 }
245 if (GNUNET_OK !=
246 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK,
247 &sb->purpose,
248 &sb->signature,
249 &sb->subspace))
250 {
251 GNUNET_break_op (0);
252 return GNUNET_SYSERR;
253 }
254 if (key != NULL)
255 *key = sb->identifier;
256 return GNUNET_OK;
257 case GNUNET_BLOCK_TYPE_NBLOCK:
258 if (block_size < sizeof (struct NBlock))
259 {
260 GNUNET_break_op (0);
261 return GNUNET_SYSERR;
262 }
263 nb = block;
264 if (block_size - sizeof (struct NBlock) !=
265 ntohl (nb->ns_purpose.size)
266 - sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose)
267 - sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) )
268 {
269 GNUNET_break_op (0);
270 return GNUNET_SYSERR;
271 }
272 if (block_size !=
273 ntohl (nb->ksk_purpose.size) + sizeof (struct GNUNET_CRYPTO_RsaSignature))
274 {
275 GNUNET_break_op (0);
276 return GNUNET_SYSERR;
277 }
278 if (GNUNET_OK !=
279 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK_KSIG,
280 &nb->ksk_purpose,
281 &nb->ksk_signature,
282 &nb->keyspace))
283 {
284 GNUNET_break_op (0);
285 return GNUNET_SYSERR;
286 }
287 if (GNUNET_OK !=
288 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK,
289 &nb->ns_purpose,
290 &nb->ns_signature,
291 &nb->subspace))
292 {
293 GNUNET_break_op (0);
294 return GNUNET_SYSERR;
295 }
296 /* FIXME: we used to xor ID with NSID,
297 why not here? */
298 if (key != NULL)
299 GNUNET_CRYPTO_hash (&nb->keyspace,
300 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
301 key);
302 return GNUNET_OK;
303 default:
304 return GNUNET_SYSERR;
305 }
306}
307
308
309/**
310 * Entry point for the plugin.
311 */
312void *
313gnunet_plugin_block_fs_init (void *cls)
314{
315 static enum GNUNET_BLOCK_Type types[] =
316 {
317 GNUNET_BLOCK_TYPE_DBLOCK,
318 GNUNET_BLOCK_TYPE_IBLOCK,
319 GNUNET_BLOCK_TYPE_KBLOCK,
320 GNUNET_BLOCK_TYPE_SBLOCK,
321 GNUNET_BLOCK_TYPE_NBLOCK,
322 GNUNET_BLOCK_TYPE_ANY /* end of list */
323 };
324 struct GNUNET_BLOCK_PluginFunctions *api;
325
326 api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions));
327 api->evaluate = &block_plugin_fs_evaluate;
328 api->get_key = &block_plugin_fs_get_key;
329 api->types = types;
330 return api;
331}
332
333
334/**
335 * Exit point from the plugin.
336 */
337void *
338gnunet_plugin_block_fs_done (void *cls)
339{
340 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
341
342 GNUNET_free (api);
343 return NULL;
344}
345
346/* end of plugin_block_fs.c */
diff --git a/src/block/plugin_block_template.c b/src/block/plugin_block_template.c
new file mode 100644
index 000000000..016a3fc8f
--- /dev/null
+++ b/src/block/plugin_block_template.c
@@ -0,0 +1,118 @@
1/*
2 This file is part of GNUnet
3 (C) 2010 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 block/plugin_block_template.c
23 * @brief template for a block plugin
24 * @author Christian Grothoff
25 */
26
27#include "platform.h"
28#include "plugin_block.h"
29
30#define DEBUG_TEMPLATE GNUNET_NO
31
32
33/**
34 * Function called to validate a reply or a request. For
35 * request evaluation, simply pass "NULL" for the reply_block.
36 *
37 * @param cls closure
38 * @param type block type
39 * @param query original query (hash)
40 * @param bf pointer to bloom filter associated with query; possibly updated (!)
41 * @param bf_mutator mutation value for bf
42 * @param xquery extrended query data (can be NULL, depending on type)
43 * @param xquery_size number of bytes in xquery
44 * @param reply_block response to validate
45 * @param reply_block_size number of bytes in reply block
46 * @return characterization of result
47 */
48static enum GNUNET_BLOCK_EvaluationResult
49block_plugin_template_evaluate (void *cls,
50 enum GNUNET_BLOCK_Type type,
51 const GNUNET_HashCode *query,
52 struct GNUNET_CONTAINER_BloomFilter **bf,
53 int32_t bf_mutator,
54 const void *xquery,
55 size_t xquery_size,
56 const void *reply_block,
57 size_t reply_block_size)
58{
59 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
60}
61
62
63/**
64 * Function called to obtain the key for a block.
65 *
66 * @param cls closure
67 * @param type block type
68 * @param block block to get the key for
69 * @param block_size number of bytes in block
70 * @param key set to the key (query) for the given block
71 * @return GNUNET_OK on success, GNUNET_SYSERR if type not supported
72 * (or if extracting a key from a block of this type does not work)
73 */
74static int
75block_plugin_template_get_key (void *cls,
76 enum GNUNET_BLOCK_Type type,
77 const void *block,
78 size_t block_size,
79 GNUNET_HashCode *key)
80{
81 return GNUNET_SYSERR;
82}
83
84
85/**
86 * Entry point for the plugin.
87 */
88void *
89gnunet_plugin_block_template_init (void *cls)
90{
91 static enum GNUNET_BLOCK_Type types[] =
92 {
93 /* FIXME: insert supported block types here */
94 GNUNET_BLOCK_TYPE_ANY /* end of list */
95 };
96 struct GNUNET_BLOCK_PluginFunctions *api;
97
98 api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions));
99 api->evaluate = &block_plugin_template_evaluate;
100 api->get_key = &block_plugin_template_get_key;
101 api->types = types;
102 return api;
103}
104
105
106/**
107 * Exit point from the plugin.
108 */
109void *
110gnunet_plugin_block_template_done (void *cls)
111{
112 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
113
114 GNUNET_free (api);
115 return NULL;
116}
117
118/* end of plugin_block_template.c */
diff --git a/src/include/gnunet_block_lib.h b/src/include/gnunet_block_lib.h
index 0bd9848d7..ace4f23bb 100644
--- a/src/include/gnunet_block_lib.h
+++ b/src/include/gnunet_block_lib.h
@@ -35,6 +35,7 @@ extern "C"
35#endif 35#endif
36#endif 36#endif
37 37
38
38/** 39/**
39 * Blocks in the datastore and the datacache must have a unique type. 40 * Blocks in the datastore and the datacache must have a unique type.
40 */ 41 */
@@ -82,6 +83,8 @@ enum GNUNET_BLOCK_Type
82 }; 83 };
83 84
84 85
86/* **************** FIXME: move these to block_fs.h or so ***************** */
87
85/** 88/**
86 * @brief keyword block (advertising data under a keyword) 89 * @brief keyword block (advertising data under a keyword)
87 */ 90 */
@@ -216,6 +219,8 @@ struct OnDemandBlock
216}; 219};
217 220
218 221
222/* **************** OLD API ***************** */
223
219/** 224/**
220 * Check if the given block is well-formed (and of the given type). 225 * Check if the given block is well-formed (and of the given type).
221 * 226 *
@@ -234,6 +239,126 @@ GNUNET_BLOCK_check_block (enum GNUNET_BLOCK_Type type,
234 GNUNET_HashCode *query); 239 GNUNET_HashCode *query);
235 240
236 241
242/* **************** NEW API ***************** */
243
244/**
245 * Possible ways for how a block may relate to a query.
246 */
247enum GNUNET_BLOCK_EvaluationResult
248 {
249 /**
250 * Valid result, and there may be more.
251 */
252 GNUNET_BLOCK_EVALUATION_OK_MORE = 0,
253
254 /**
255 * Last possible valid result.
256 */
257 GNUNET_BLOCK_EVALUATION_OK_LAST = 1,
258
259 /**
260 * Valid result, but suppressed because it is a duplicate.
261 */
262 GNUNET_BLOCK_EVALUATION_OK_DUPLICATE = 2,
263
264 /**
265 * Block does not match query (invalid result)
266 */
267 GNUNET_BLOCK_EVALUATION_RESULT_INVALID = 3,
268
269 /**
270 * Query is valid, no reply given.
271 */
272 GNUNET_BLOCK_EVALUATION_REQUEST_VALID = 4,
273
274 /**
275 * Query format does not match block type (invalid query). For
276 * example, xquery not given or xquery_size not appropriate for
277 * type.
278 */
279 GNUNET_BLOCK_EVALUATION_REQUEST_INVALID = 5,
280
281 /**
282 * Specified block type not supported by this plugin.
283 */
284 GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED = 6
285 };
286
287
288/**
289 * Handle to an initialized block library.
290 */
291struct GNUNET_BLOCK_Context;
292
293
294/**
295 * Create a block context. Loads the block plugins.
296 *
297 * @param cfg configuration to use
298 * @return NULL on error
299 */
300struct GNUNET_BLOCK_Context *
301GNUNET_BLOCK_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg);
302
303
304/**
305 * Destroy the block context.
306 *
307 * @param ctx context to destroy
308 */
309void
310GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx);
311
312
313/**
314 * Function called to validate a reply or a request. For
315 * request evaluation, simply pass "NULL" for the reply_block.
316 * Note that it is assumed that the reply has already been
317 * matched to the key (and signatures checked) as it would
318 * be done with the "get_key" function.
319 *
320 * @param ctx block contxt
321 * @param type block type
322 * @param query original query (hash)
323 * @param bf pointer to bloom filter associated with query; possibly updated (!)
324 * @param bf_mutator mutation value for bf
325 * @param xquery extrended query data (can be NULL, depending on type)
326 * @param xquery_size number of bytes in xquery
327 * @param reply_block response to validate
328 * @param reply_block_size number of bytes in reply block
329 * @return characterization of result
330 */
331enum GNUNET_BLOCK_EvaluationResult
332GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx,
333 enum GNUNET_BLOCK_Type type,
334 const GNUNET_HashCode *query,
335 struct GNUNET_CONTAINER_BloomFilter **bf,
336 int32_t bf_mutator,
337 const void *xquery,
338 size_t xquery_size,
339 const void *reply_block,
340 size_t reply_block_size);
341
342
343/**
344 * Function called to obtain the key for a block.
345 *
346 * @param ctx block context
347 * @param type block type
348 * @param block block to get the key for
349 * @param block_size number of bytes in block
350 * @param key set to the key (query) for the given block
351 * @return GNUNET_OK on success, GNUNET_SYSERR if type not supported
352 * (or if extracting a key from a block of this type does not work)
353 */
354int
355GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx,
356 enum GNUNET_BLOCK_Type type,
357 const void *block,
358 size_t block_size,
359 GNUNET_HashCode *key);
360
361
237#if 0 /* keep Emacsens' auto-indent happy */ 362#if 0 /* keep Emacsens' auto-indent happy */
238{ 363{
239#endif 364#endif
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index cb258a125..d0187af8b 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -73,7 +73,7 @@ bin_SCRIPTS = \
73 73
74gnunet_nat_server_SOURCES = \ 74gnunet_nat_server_SOURCES = \
75 $(NATSERVER) 75 $(NATSERVER)
76 76
77gnunet_transport_wlan_helper_SOURCES = \ 77gnunet_transport_wlan_helper_SOURCES = \
78 gnunet-transport-wlan-helper.c 78 gnunet-transport-wlan-helper.c
79gnunet_transport_wlan_helper_LDADD = \ 79gnunet_transport_wlan_helper_LDADD = \
@@ -296,13 +296,13 @@ test_transport_api_https_SOURCES = \
296test_transport_api_https_LDADD = \ 296test_transport_api_https_LDADD = \
297 $(top_builddir)/src/transport/libgnunettransport.la \ 297 $(top_builddir)/src/transport/libgnunettransport.la \
298 $(top_builddir)/src/util/libgnunetutil.la 298 $(top_builddir)/src/util/libgnunetutil.la
299 299
300test_transport_api_reliability_https_SOURCES = \ 300test_transport_api_reliability_https_SOURCES = \
301 test_transport_api_reliability.c 301 test_transport_api_reliability.c
302test_transport_api_reliability_https_LDADD = \ 302test_transport_api_reliability_https_LDADD = \
303 $(top_builddir)/src/transport/libgnunettransport.la \ 303 $(top_builddir)/src/transport/libgnunettransport.la \
304 $(top_builddir)/src/util/libgnunetutil.la 304 $(top_builddir)/src/util/libgnunetutil.la
305 305
306endif 306endif
307 307
308EXTRA_DIST = \ 308EXTRA_DIST = \