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.c295
1 files changed, 148 insertions, 147 deletions
diff --git a/src/fs/plugin_block_fs.c b/src/fs/plugin_block_fs.c
index 8003e3837..e5ea91c98 100644
--- a/src/fs/plugin_block_fs.c
+++ b/src/fs/plugin_block_fs.c
@@ -51,61 +51,62 @@
51 * by this @a type of block (this is not an error) 51 * by this @a type of block (this is not an error)
52 */ 52 */
53static struct GNUNET_BLOCK_Group * 53static struct GNUNET_BLOCK_Group *
54block_plugin_fs_create_group(void *cls, 54block_plugin_fs_create_group (void *cls,
55 enum GNUNET_BLOCK_Type type, 55 enum GNUNET_BLOCK_Type type,
56 uint32_t nonce, 56 uint32_t nonce,
57 const void *raw_data, 57 const void *raw_data,
58 size_t raw_data_size, 58 size_t raw_data_size,
59 va_list va) 59 va_list va)
60{ 60{
61 unsigned int size; 61 unsigned int size;
62 const char *guard; 62 const char *guard;
63 63
64 switch (type) 64 switch (type)
65 { 65 {
66 case GNUNET_BLOCK_TYPE_FS_DBLOCK: 66 case GNUNET_BLOCK_TYPE_FS_DBLOCK:
67 GNUNET_break(NULL == va_arg(va, const char *)); 67 GNUNET_break (NULL == va_arg (va, const char *));
68 return NULL; 68 return NULL;
69
70 case GNUNET_BLOCK_TYPE_FS_IBLOCK:
71 GNUNET_break(NULL == va_arg(va, const char *));
72 return NULL;
73 69
74 case GNUNET_BLOCK_TYPE_FS_UBLOCK: 70 case GNUNET_BLOCK_TYPE_FS_IBLOCK:
75 guard = va_arg(va, const char *); 71 GNUNET_break (NULL == va_arg (va, const char *));
76 if (0 == strcmp(guard, 72 return NULL;
77 "seen-set-size"))
78 {
79 size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size(va_arg(va, unsigned int),
80 BLOOMFILTER_K);
81 }
82 else if (0 == strcmp(guard,
83 "filter-size"))
84 {
85 size = va_arg(va, unsigned int);
86 }
87 else
88 {
89 /* va-args invalid! bad bug, complain! */
90 GNUNET_break(0);
91 size = 8;
92 }
93 if (0 == size)
94 size = raw_data_size; /* not for us to determine, use what we got! */
95 GNUNET_break(NULL == va_arg(va, const char *));
96 return GNUNET_BLOCK_GROUP_bf_create(cls,
97 size,
98 BLOOMFILTER_K,
99 type,
100 nonce,
101 raw_data,
102 raw_data_size);
103 73
104 default: 74 case GNUNET_BLOCK_TYPE_FS_UBLOCK:
105 GNUNET_break(NULL == va_arg(va, const char *)); 75 guard = va_arg (va, const char *);
106 GNUNET_break(0); 76 if (0 == strcmp (guard,
107 return NULL; 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;
108 } 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 }
109} 110}
110 111
111 112
@@ -129,86 +130,87 @@ block_plugin_fs_create_group(void *cls,
129 * @return characterization of result 130 * @return characterization of result
130 */ 131 */
131static enum GNUNET_BLOCK_EvaluationResult 132static enum GNUNET_BLOCK_EvaluationResult
132block_plugin_fs_evaluate(void *cls, 133block_plugin_fs_evaluate (void *cls,
133 struct GNUNET_BLOCK_Context *ctx, 134 struct GNUNET_BLOCK_Context *ctx,
134 enum GNUNET_BLOCK_Type type, 135 enum GNUNET_BLOCK_Type type,
135 struct GNUNET_BLOCK_Group *bg, 136 struct GNUNET_BLOCK_Group *bg,
136 enum GNUNET_BLOCK_EvaluationOptions eo, 137 enum GNUNET_BLOCK_EvaluationOptions eo,
137 const struct GNUNET_HashCode *query, 138 const struct GNUNET_HashCode *query,
138 const void *xquery, 139 const void *xquery,
139 size_t xquery_size, 140 size_t xquery_size,
140 const void *reply_block, 141 const void *reply_block,
141 size_t reply_block_size) 142 size_t reply_block_size)
142{ 143{
143 const struct UBlock *ub; 144 const struct UBlock *ub;
144 struct GNUNET_HashCode hc; 145 struct GNUNET_HashCode hc;
145 struct GNUNET_HashCode chash; 146 struct GNUNET_HashCode chash;
146 147
147 switch (type) 148 switch (type)
149 {
150 case GNUNET_BLOCK_TYPE_FS_DBLOCK:
151 case GNUNET_BLOCK_TYPE_FS_IBLOCK:
152 if (0 != xquery_size)
148 { 153 {
149 case GNUNET_BLOCK_TYPE_FS_DBLOCK: 154 GNUNET_break_op (0);
150 case GNUNET_BLOCK_TYPE_FS_IBLOCK: 155 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
151 if (0 != xquery_size) 156 }
152 { 157 if (NULL == reply_block)
153 GNUNET_break_op(0); 158 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
154 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; 159 return GNUNET_BLOCK_EVALUATION_OK_LAST;
155 }
156 if (NULL == reply_block)
157 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
158 return GNUNET_BLOCK_EVALUATION_OK_LAST;
159
160 case GNUNET_BLOCK_TYPE_FS_UBLOCK:
161 if (0 != xquery_size)
162 {
163 GNUNET_break_op(0);
164 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
165 }
166 if (NULL == reply_block)
167 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
168 160
169 if (reply_block_size < sizeof(struct UBlock)) 161 case GNUNET_BLOCK_TYPE_FS_UBLOCK:
170 { 162 if (0 != xquery_size)
171 GNUNET_break_op(0); 163 {
172 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 164 GNUNET_break_op (0);
173 } 165 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
174 ub = reply_block; 166 }
175 GNUNET_CRYPTO_hash(&ub->verification_key, 167 if (NULL == reply_block)
176 sizeof(ub->verification_key), 168 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
177 &hc);
178 if (0 != memcmp(&hc,
179 query,
180 sizeof(struct GNUNET_HashCode)))
181 {
182 GNUNET_break_op(0);
183 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
184 }
185 if (reply_block_size != ntohl(ub->purpose.size) + sizeof(struct GNUNET_CRYPTO_EcdsaSignature))
186 {
187 GNUNET_break_op(0);
188 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
189 }
190 if ((0 == (eo & GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO)) &&
191 (GNUNET_OK !=
192 GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK,
193 &ub->purpose,
194 &ub->signature,
195 &ub->verification_key)))
196 {
197 GNUNET_break_op(0);
198 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
199 }
200 GNUNET_CRYPTO_hash(reply_block,
201 reply_block_size,
202 &chash);
203 if (GNUNET_YES ==
204 GNUNET_BLOCK_GROUP_bf_test_and_set(bg,
205 &chash))
206 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
207 return GNUNET_BLOCK_EVALUATION_OK_MORE;
208 169
209 default: 170 if (reply_block_size < sizeof(struct UBlock))
210 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; 171 {
172 GNUNET_break_op (0);
173 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
174 }
175 ub = reply_block;
176 GNUNET_CRYPTO_hash (&ub->verification_key,
177 sizeof(ub->verification_key),
178 &hc);
179 if (0 != memcmp (&hc,
180 query,
181 sizeof(struct GNUNET_HashCode)))
182 {
183 GNUNET_break_op (0);
184 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
185 }
186 if (reply_block_size != ntohl (ub->purpose.size) + sizeof(struct
187 GNUNET_CRYPTO_EcdsaSignature))
188 {
189 GNUNET_break_op (0);
190 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
191 }
192 if ((0 == (eo & GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO)) &&
193 (GNUNET_OK !=
194 GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK,
195 &ub->purpose,
196 &ub->signature,
197 &ub->verification_key)))
198 {
199 GNUNET_break_op (0);
200 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
211 } 201 }
202 GNUNET_CRYPTO_hash (reply_block,
203 reply_block_size,
204 &chash);
205 if (GNUNET_YES ==
206 GNUNET_BLOCK_GROUP_bf_test_and_set (bg,
207 &chash))
208 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
209 return GNUNET_BLOCK_EVALUATION_OK_MORE;
210
211 default:
212 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
213 }
212} 214}
213 215
214 216
@@ -224,37 +226,37 @@ block_plugin_fs_evaluate(void *cls,
224 * (or if extracting a key from a block of this type does not work) 226 * (or if extracting a key from a block of this type does not work)
225 */ 227 */
226static int 228static int
227block_plugin_fs_get_key(void *cls, 229block_plugin_fs_get_key (void *cls,
228 enum GNUNET_BLOCK_Type type, 230 enum GNUNET_BLOCK_Type type,
229 const void *block, 231 const void *block,
230 size_t block_size, 232 size_t block_size,
231 struct GNUNET_HashCode *key) 233 struct GNUNET_HashCode *key)
232{ 234{
233 const struct UBlock *ub; 235 const struct UBlock *ub;
234 236
235 switch (type) 237 switch (type)
236 { 238 {
237 case GNUNET_BLOCK_TYPE_FS_DBLOCK: 239 case GNUNET_BLOCK_TYPE_FS_DBLOCK:
238 case GNUNET_BLOCK_TYPE_FS_IBLOCK: 240 case GNUNET_BLOCK_TYPE_FS_IBLOCK:
239 GNUNET_CRYPTO_hash(block, block_size, key); 241 GNUNET_CRYPTO_hash (block, block_size, key);
240 return GNUNET_OK; 242 return GNUNET_OK;
241
242 case GNUNET_BLOCK_TYPE_FS_UBLOCK:
243 if (block_size < sizeof(struct UBlock))
244 {
245 GNUNET_break(0);
246 return GNUNET_SYSERR;
247 }
248 ub = block;
249 GNUNET_CRYPTO_hash(&ub->verification_key,
250 sizeof(ub->verification_key),
251 key);
252 return GNUNET_OK;
253 243
254 default: 244 case GNUNET_BLOCK_TYPE_FS_UBLOCK:
255 GNUNET_break(0); 245 if (block_size < sizeof(struct UBlock))
246 {
247 GNUNET_break (0);
256 return GNUNET_SYSERR; 248 return GNUNET_SYSERR;
257 } 249 }
250 ub = block;
251 GNUNET_CRYPTO_hash (&ub->verification_key,
252 sizeof(ub->verification_key),
253 key);
254 return GNUNET_OK;
255
256 default:
257 GNUNET_break (0);
258 return GNUNET_SYSERR;
259 }
258} 260}
259 261
260 262
@@ -262,10 +264,9 @@ block_plugin_fs_get_key(void *cls,
262 * Entry point for the plugin. 264 * Entry point for the plugin.
263 */ 265 */
264void * 266void *
265libgnunet_plugin_block_fs_init(void *cls) 267libgnunet_plugin_block_fs_init (void *cls)
266{ 268{
267 static enum GNUNET_BLOCK_Type types[] = 269 static enum GNUNET_BLOCK_Type types[] = {
268 {
269 GNUNET_BLOCK_TYPE_FS_DBLOCK, 270 GNUNET_BLOCK_TYPE_FS_DBLOCK,
270 GNUNET_BLOCK_TYPE_FS_IBLOCK, 271 GNUNET_BLOCK_TYPE_FS_IBLOCK,
271 GNUNET_BLOCK_TYPE_FS_UBLOCK, 272 GNUNET_BLOCK_TYPE_FS_UBLOCK,
@@ -273,7 +274,7 @@ libgnunet_plugin_block_fs_init(void *cls)
273 }; 274 };
274 struct GNUNET_BLOCK_PluginFunctions *api; 275 struct GNUNET_BLOCK_PluginFunctions *api;
275 276
276 api = GNUNET_new(struct GNUNET_BLOCK_PluginFunctions); 277 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
277 api->evaluate = &block_plugin_fs_evaluate; 278 api->evaluate = &block_plugin_fs_evaluate;
278 api->get_key = &block_plugin_fs_get_key; 279 api->get_key = &block_plugin_fs_get_key;
279 api->create_group = &block_plugin_fs_create_group; 280 api->create_group = &block_plugin_fs_create_group;
@@ -286,11 +287,11 @@ libgnunet_plugin_block_fs_init(void *cls)
286 * Exit point from the plugin. 287 * Exit point from the plugin.
287 */ 288 */
288void * 289void *
289libgnunet_plugin_block_fs_done(void *cls) 290libgnunet_plugin_block_fs_done (void *cls)
290{ 291{
291 struct GNUNET_BLOCK_PluginFunctions *api = cls; 292 struct GNUNET_BLOCK_PluginFunctions *api = cls;
292 293
293 GNUNET_free(api); 294 GNUNET_free (api);
294 return NULL; 295 return NULL;
295} 296}
296 297