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.c105
1 files changed, 78 insertions, 27 deletions
diff --git a/src/fs/plugin_block_fs.c b/src/fs/plugin_block_fs.c
index 415a2e3ed..902519f15 100644
--- a/src/fs/plugin_block_fs.c
+++ b/src/fs/plugin_block_fs.c
@@ -23,12 +23,12 @@
23 * @brief blocks used for file-sharing 23 * @brief blocks used for file-sharing
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
26
27#include "platform.h" 26#include "platform.h"
28#include "gnunet_block_plugin.h" 27#include "gnunet_block_plugin.h"
29#include "gnunet_fs_service.h" 28#include "gnunet_fs_service.h"
30#include "block_fs.h" 29#include "block_fs.h"
31#include "gnunet_signatures.h" 30#include "gnunet_signatures.h"
31#include "gnunet_block_group_lib.h"
32 32
33 33
34/** 34/**
@@ -37,6 +37,70 @@
37 */ 37 */
38#define BLOOMFILTER_K 16 38#define BLOOMFILTER_K 16
39 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 case GNUNET_BLOCK_TYPE_FS_IBLOCK:
70 GNUNET_break (NULL == va_arg (va, const char *));
71 return NULL;
72 case GNUNET_BLOCK_TYPE_FS_UBLOCK:
73 guard = va_arg (va, const char *);
74 if (0 != strcmp (guard,
75 "seen-set-size"))
76 {
77 /* va-args invalid! bad bug, complain! */
78 GNUNET_break (0);
79 size = 8;
80 }
81 else
82 {
83 size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned int),
84 BLOOMFILTER_K);
85 }
86 if (0 == size)
87 size = raw_data_size; /* not for us to determine, use what we got! */
88 GNUNET_break (NULL == va_arg (va, const char *));
89 return GNUNET_BLOCK_GROUP_bf_create (cls,
90 size,
91 BLOOMFILTER_K,
92 type,
93 nonce,
94 raw_data,
95 raw_data_size);
96 default:
97 GNUNET_break (NULL == va_arg (va, const char *));
98 GNUNET_break (0);
99 return NULL;
100 }
101}
102
103
40/** 104/**
41 * Function called to validate a reply or a request. For 105 * Function called to validate a reply or a request. For
42 * request evaluation, simply pass "NULL" for the reply_block. 106 * request evaluation, simply pass "NULL" for the reply_block.
@@ -45,11 +109,11 @@
45 * be done with the #GNUNET_BLOCK_get_key() function. 109 * be done with the #GNUNET_BLOCK_get_key() function.
46 * 110 *
47 * @param cls closure 111 * @param cls closure
112 * @param ctx block context
48 * @param type block type 113 * @param type block type
114 * @param bg group to use for evaluation
49 * @param eo control flags 115 * @param eo control flags
50 * @param query original query (hash) 116 * @param query original query (hash)
51 * @param bf pointer to bloom filter associated with query; possibly updated (!)
52 * @param bf_mutator mutation value for @a bf
53 * @param xquery extrended query data (can be NULL, depending on type) 117 * @param xquery extrended query data (can be NULL, depending on type)
54 * @param xquery_size number of bytes in @a xquery 118 * @param xquery_size number of bytes in @a xquery
55 * @param reply_block response to validate 119 * @param reply_block response to validate
@@ -58,11 +122,11 @@
58 */ 122 */
59static enum GNUNET_BLOCK_EvaluationResult 123static enum GNUNET_BLOCK_EvaluationResult
60block_plugin_fs_evaluate (void *cls, 124block_plugin_fs_evaluate (void *cls,
125 struct GNUNET_BLOCK_Context *ctx,
61 enum GNUNET_BLOCK_Type type, 126 enum GNUNET_BLOCK_Type type,
127 struct GNUNET_BLOCK_Group *bg,
62 enum GNUNET_BLOCK_EvaluationOptions eo, 128 enum GNUNET_BLOCK_EvaluationOptions eo,
63 const struct GNUNET_HashCode *query, 129 const struct GNUNET_HashCode *query,
64 struct GNUNET_CONTAINER_BloomFilter **bf,
65 int32_t bf_mutator,
66 const void *xquery, 130 const void *xquery,
67 size_t xquery_size, 131 size_t xquery_size,
68 const void *reply_block, 132 const void *reply_block,
@@ -71,7 +135,6 @@ block_plugin_fs_evaluate (void *cls,
71 const struct UBlock *ub; 135 const struct UBlock *ub;
72 struct GNUNET_HashCode hc; 136 struct GNUNET_HashCode hc;
73 struct GNUNET_HashCode chash; 137 struct GNUNET_HashCode chash;
74 struct GNUNET_HashCode mhash;
75 138
76 switch (type) 139 switch (type)
77 { 140 {
@@ -125,26 +188,13 @@ block_plugin_fs_evaluate (void *cls,
125 GNUNET_break_op (0); 188 GNUNET_break_op (0);
126 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 189 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
127 } 190 }
128 if (NULL != bf) 191 GNUNET_CRYPTO_hash (reply_block,
129 { 192 reply_block_size,
130 GNUNET_CRYPTO_hash (reply_block, 193 &chash);
131 reply_block_size, 194 if (GNUNET_YES ==
132 &chash); 195 GNUNET_BLOCK_GROUP_bf_test_and_set (bg,
133 GNUNET_BLOCK_mingle_hash (&chash, 196 &chash))
134 bf_mutator, 197 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
135 &mhash);
136 if (NULL != *bf)
137 {
138 if (GNUNET_YES ==
139 GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
140 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
141 }
142 else
143 {
144 *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K);
145 }
146 GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
147 }
148 return GNUNET_BLOCK_EVALUATION_OK_MORE; 198 return GNUNET_BLOCK_EVALUATION_OK_MORE;
149 default: 199 default:
150 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; 200 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
@@ -214,6 +264,7 @@ libgnunet_plugin_block_fs_init (void *cls)
214 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); 264 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
215 api->evaluate = &block_plugin_fs_evaluate; 265 api->evaluate = &block_plugin_fs_evaluate;
216 api->get_key = &block_plugin_fs_get_key; 266 api->get_key = &block_plugin_fs_get_key;
267 api->create_group = &block_plugin_fs_create_group;
217 api->types = types; 268 api->types = types;
218 return api; 269 return api;
219} 270}
@@ -225,7 +276,7 @@ libgnunet_plugin_block_fs_init (void *cls)
225void * 276void *
226libgnunet_plugin_block_fs_done (void *cls) 277libgnunet_plugin_block_fs_done (void *cls)
227{ 278{
228 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 279 struct GNUNET_BLOCK_PluginFunctions *api = cls;
229 280
230 GNUNET_free (api); 281 GNUNET_free (api);
231 return NULL; 282 return NULL;