diff options
Diffstat (limited to 'src/block/block.c')
-rw-r--r-- | src/block/block.c | 250 |
1 files changed, 126 insertions, 124 deletions
diff --git a/src/block/block.c b/src/block/block.c index 78e9bc2dd..dafba9d8c 100644 --- a/src/block/block.c +++ b/src/block/block.c | |||
@@ -34,7 +34,8 @@ | |||
34 | /** | 34 | /** |
35 | * Handle for a plugin. | 35 | * Handle for a plugin. |
36 | */ | 36 | */ |
37 | struct Plugin { | 37 | struct Plugin |
38 | { | ||
38 | /** | 39 | /** |
39 | * Name of the shared library. | 40 | * Name of the shared library. |
40 | */ | 41 | */ |
@@ -50,7 +51,8 @@ struct Plugin { | |||
50 | /** | 51 | /** |
51 | * Handle to an initialized block library. | 52 | * Handle to an initialized block library. |
52 | */ | 53 | */ |
53 | struct GNUNET_BLOCK_Context { | 54 | struct GNUNET_BLOCK_Context |
55 | { | ||
54 | /** | 56 | /** |
55 | * Array of our plugins. | 57 | * Array of our plugins. |
56 | */ | 58 | */ |
@@ -76,18 +78,18 @@ struct GNUNET_BLOCK_Context { | |||
76 | * @param hc where to store the result. | 78 | * @param hc where to store the result. |
77 | */ | 79 | */ |
78 | void | 80 | void |
79 | GNUNET_BLOCK_mingle_hash(const struct GNUNET_HashCode *in, | 81 | GNUNET_BLOCK_mingle_hash (const struct GNUNET_HashCode *in, |
80 | uint32_t mingle_number, | 82 | uint32_t mingle_number, |
81 | struct GNUNET_HashCode *hc) | 83 | struct GNUNET_HashCode *hc) |
82 | { | 84 | { |
83 | struct GNUNET_HashCode m; | 85 | struct GNUNET_HashCode m; |
84 | 86 | ||
85 | GNUNET_CRYPTO_hash(&mingle_number, | 87 | GNUNET_CRYPTO_hash (&mingle_number, |
86 | sizeof(uint32_t), | 88 | sizeof(uint32_t), |
87 | &m); | 89 | &m); |
88 | GNUNET_CRYPTO_hash_xor(&m, | 90 | GNUNET_CRYPTO_hash_xor (&m, |
89 | in, | 91 | in, |
90 | hc); | 92 | hc); |
91 | } | 93 | } |
92 | 94 | ||
93 | 95 | ||
@@ -99,23 +101,23 @@ GNUNET_BLOCK_mingle_hash(const struct GNUNET_HashCode *in, | |||
99 | * @param lib_ret the plugin API | 101 | * @param lib_ret the plugin API |
100 | */ | 102 | */ |
101 | static void | 103 | static void |
102 | add_plugin(void *cls, | 104 | add_plugin (void *cls, |
103 | const char *library_name, | 105 | const char *library_name, |
104 | void *lib_ret) | 106 | void *lib_ret) |
105 | { | 107 | { |
106 | struct GNUNET_BLOCK_Context *ctx = cls; | 108 | struct GNUNET_BLOCK_Context *ctx = cls; |
107 | struct GNUNET_BLOCK_PluginFunctions *api = lib_ret; | 109 | struct GNUNET_BLOCK_PluginFunctions *api = lib_ret; |
108 | struct Plugin *plugin; | 110 | struct Plugin *plugin; |
109 | 111 | ||
110 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 112 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
111 | "Loading block plugin `%s'\n", | 113 | "Loading block plugin `%s'\n", |
112 | library_name); | 114 | library_name); |
113 | plugin = GNUNET_new(struct Plugin); | 115 | plugin = GNUNET_new (struct Plugin); |
114 | plugin->api = api; | 116 | plugin->api = api; |
115 | plugin->library_name = GNUNET_strdup(library_name); | 117 | plugin->library_name = GNUNET_strdup (library_name); |
116 | GNUNET_array_append(ctx->plugins, | 118 | GNUNET_array_append (ctx->plugins, |
117 | ctx->num_plugins, | 119 | ctx->num_plugins, |
118 | plugin); | 120 | plugin); |
119 | } | 121 | } |
120 | 122 | ||
121 | 123 | ||
@@ -127,16 +129,16 @@ add_plugin(void *cls, | |||
127 | * @return NULL on error | 129 | * @return NULL on error |
128 | */ | 130 | */ |
129 | struct GNUNET_BLOCK_Context * | 131 | struct GNUNET_BLOCK_Context * |
130 | GNUNET_BLOCK_context_create(const struct GNUNET_CONFIGURATION_Handle *cfg) | 132 | GNUNET_BLOCK_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg) |
131 | { | 133 | { |
132 | struct GNUNET_BLOCK_Context *ctx; | 134 | struct GNUNET_BLOCK_Context *ctx; |
133 | 135 | ||
134 | ctx = GNUNET_new(struct GNUNET_BLOCK_Context); | 136 | ctx = GNUNET_new (struct GNUNET_BLOCK_Context); |
135 | ctx->cfg = cfg; | 137 | ctx->cfg = cfg; |
136 | GNUNET_PLUGIN_load_all("libgnunet_plugin_block_", | 138 | GNUNET_PLUGIN_load_all ("libgnunet_plugin_block_", |
137 | (void *)cfg, | 139 | (void *) cfg, |
138 | &add_plugin, | 140 | &add_plugin, |
139 | ctx); | 141 | ctx); |
140 | return ctx; | 142 | return ctx; |
141 | } | 143 | } |
142 | 144 | ||
@@ -147,21 +149,21 @@ GNUNET_BLOCK_context_create(const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
147 | * @param ctx context to destroy | 149 | * @param ctx context to destroy |
148 | */ | 150 | */ |
149 | void | 151 | void |
150 | GNUNET_BLOCK_context_destroy(struct GNUNET_BLOCK_Context *ctx) | 152 | GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx) |
151 | { | 153 | { |
152 | struct Plugin *plugin; | 154 | struct Plugin *plugin; |
153 | 155 | ||
154 | for (unsigned int i = 0; i < ctx->num_plugins; i++) | 156 | for (unsigned int i = 0; i < ctx->num_plugins; i++) |
155 | { | 157 | { |
156 | plugin = ctx->plugins[i]; | 158 | plugin = ctx->plugins[i]; |
157 | GNUNET_break(NULL == | 159 | GNUNET_break (NULL == |
158 | GNUNET_PLUGIN_unload(plugin->library_name, | 160 | GNUNET_PLUGIN_unload (plugin->library_name, |
159 | plugin->api)); | 161 | plugin->api)); |
160 | GNUNET_free(plugin->library_name); | 162 | GNUNET_free (plugin->library_name); |
161 | GNUNET_free(plugin); | 163 | GNUNET_free (plugin); |
162 | } | 164 | } |
163 | GNUNET_free(ctx->plugins); | 165 | GNUNET_free (ctx->plugins); |
164 | GNUNET_free(ctx); | 166 | GNUNET_free (ctx); |
165 | } | 167 | } |
166 | 168 | ||
167 | 169 | ||
@@ -176,10 +178,10 @@ GNUNET_BLOCK_context_destroy(struct GNUNET_BLOCK_Context *ctx) | |||
176 | * supported, #GNUNET_SYSERR on error | 178 | * supported, #GNUNET_SYSERR on error |
177 | */ | 179 | */ |
178 | int | 180 | int |
179 | GNUNET_BLOCK_group_serialize(struct GNUNET_BLOCK_Group *bg, | 181 | GNUNET_BLOCK_group_serialize (struct GNUNET_BLOCK_Group *bg, |
180 | uint32_t *nonce, | 182 | uint32_t *nonce, |
181 | void **raw_data, | 183 | void **raw_data, |
182 | size_t *raw_data_size) | 184 | size_t *raw_data_size) |
183 | { | 185 | { |
184 | *nonce = 0; | 186 | *nonce = 0; |
185 | *raw_data = NULL; | 187 | *raw_data = NULL; |
@@ -188,10 +190,10 @@ GNUNET_BLOCK_group_serialize(struct GNUNET_BLOCK_Group *bg, | |||
188 | return GNUNET_NO; | 190 | return GNUNET_NO; |
189 | if (NULL == bg->serialize_cb) | 191 | if (NULL == bg->serialize_cb) |
190 | return GNUNET_NO; | 192 | return GNUNET_NO; |
191 | return bg->serialize_cb(bg, | 193 | return bg->serialize_cb (bg, |
192 | nonce, | 194 | nonce, |
193 | raw_data, | 195 | raw_data, |
194 | raw_data_size); | 196 | raw_data_size); |
195 | } | 197 | } |
196 | 198 | ||
197 | 199 | ||
@@ -201,11 +203,11 @@ GNUNET_BLOCK_group_serialize(struct GNUNET_BLOCK_Group *bg, | |||
201 | * @param bg group to destroy, NULL is allowed | 203 | * @param bg group to destroy, NULL is allowed |
202 | */ | 204 | */ |
203 | void | 205 | void |
204 | GNUNET_BLOCK_group_destroy(struct GNUNET_BLOCK_Group *bg) | 206 | GNUNET_BLOCK_group_destroy (struct GNUNET_BLOCK_Group *bg) |
205 | { | 207 | { |
206 | if (NULL == bg) | 208 | if (NULL == bg) |
207 | return; | 209 | return; |
208 | bg->destroy_cb(bg); | 210 | bg->destroy_cb (bg); |
209 | } | 211 | } |
210 | 212 | ||
211 | 213 | ||
@@ -222,24 +224,24 @@ GNUNET_BLOCK_group_destroy(struct GNUNET_BLOCK_Group *bg) | |||
222 | * #GNUNET_SYSERR if merging is not supported | 224 | * #GNUNET_SYSERR if merging is not supported |
223 | */ | 225 | */ |
224 | int | 226 | int |
225 | GNUNET_BLOCK_group_merge(struct GNUNET_BLOCK_Group *bg1, | 227 | GNUNET_BLOCK_group_merge (struct GNUNET_BLOCK_Group *bg1, |
226 | struct GNUNET_BLOCK_Group *bg2) | 228 | struct GNUNET_BLOCK_Group *bg2) |
227 | { | 229 | { |
228 | int ret; | 230 | int ret; |
229 | 231 | ||
230 | if (NULL == bg2) | 232 | if (NULL == bg2) |
231 | return GNUNET_OK; | 233 | return GNUNET_OK; |
232 | if (NULL == bg1) | 234 | if (NULL == bg1) |
233 | { | 235 | { |
234 | bg2->destroy_cb(bg2); | 236 | bg2->destroy_cb (bg2); |
235 | return GNUNET_OK; | 237 | return GNUNET_OK; |
236 | } | 238 | } |
237 | if (NULL == bg1->merge_cb) | 239 | if (NULL == bg1->merge_cb) |
238 | return GNUNET_SYSERR; | 240 | return GNUNET_SYSERR; |
239 | GNUNET_assert(bg1->merge_cb == bg1->merge_cb); | 241 | GNUNET_assert (bg1->merge_cb == bg1->merge_cb); |
240 | ret = bg1->merge_cb(bg1, | 242 | ret = bg1->merge_cb (bg1, |
241 | bg2); | 243 | bg2); |
242 | bg2->destroy_cb(bg2); | 244 | bg2->destroy_cb (bg2); |
243 | return ret; | 245 | return ret; |
244 | } | 246 | } |
245 | 247 | ||
@@ -252,23 +254,23 @@ GNUNET_BLOCK_group_merge(struct GNUNET_BLOCK_Group *bg1, | |||
252 | * @return NULL if no matching plugin exists | 254 | * @return NULL if no matching plugin exists |
253 | */ | 255 | */ |
254 | static struct GNUNET_BLOCK_PluginFunctions * | 256 | static struct GNUNET_BLOCK_PluginFunctions * |
255 | find_plugin(struct GNUNET_BLOCK_Context *ctx, | 257 | find_plugin (struct GNUNET_BLOCK_Context *ctx, |
256 | enum GNUNET_BLOCK_Type type) | 258 | enum GNUNET_BLOCK_Type type) |
257 | { | 259 | { |
258 | struct Plugin *plugin; | 260 | struct Plugin *plugin; |
259 | unsigned int j; | 261 | unsigned int j; |
260 | 262 | ||
261 | for (unsigned i = 0; i < ctx->num_plugins; i++) | 263 | for (unsigned i = 0; i < ctx->num_plugins; i++) |
264 | { | ||
265 | plugin = ctx->plugins[i]; | ||
266 | j = 0; | ||
267 | while (0 != (plugin->api->types[j])) | ||
262 | { | 268 | { |
263 | plugin = ctx->plugins[i]; | 269 | if (type == plugin->api->types[j]) |
264 | j = 0; | 270 | return plugin->api; |
265 | while (0 != (plugin->api->types[j])) | 271 | j++; |
266 | { | ||
267 | if (type == plugin->api->types[j]) | ||
268 | return plugin->api; | ||
269 | j++; | ||
270 | } | ||
271 | } | 272 | } |
273 | } | ||
272 | return NULL; | 274 | return NULL; |
273 | } | 275 | } |
274 | 276 | ||
@@ -285,32 +287,32 @@ find_plugin(struct GNUNET_BLOCK_Context *ctx, | |||
285 | * by this @a type of block (this is not an error) | 287 | * by this @a type of block (this is not an error) |
286 | */ | 288 | */ |
287 | struct GNUNET_BLOCK_Group * | 289 | struct GNUNET_BLOCK_Group * |
288 | GNUNET_BLOCK_group_create(struct GNUNET_BLOCK_Context *ctx, | 290 | GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx, |
289 | enum GNUNET_BLOCK_Type type, | 291 | enum GNUNET_BLOCK_Type type, |
290 | uint32_t nonce, | 292 | uint32_t nonce, |
291 | const void *raw_data, | 293 | const void *raw_data, |
292 | size_t raw_data_size, | 294 | size_t raw_data_size, |
293 | ...) | 295 | ...) |
294 | { | 296 | { |
295 | struct GNUNET_BLOCK_PluginFunctions *plugin; | 297 | struct GNUNET_BLOCK_PluginFunctions *plugin; |
296 | struct GNUNET_BLOCK_Group *bg; | 298 | struct GNUNET_BLOCK_Group *bg; |
297 | va_list ap; | 299 | va_list ap; |
298 | 300 | ||
299 | plugin = find_plugin(ctx, | 301 | plugin = find_plugin (ctx, |
300 | type); | 302 | type); |
301 | if (NULL == plugin) | 303 | if (NULL == plugin) |
302 | return NULL; | 304 | return NULL; |
303 | if (NULL == plugin->create_group) | 305 | if (NULL == plugin->create_group) |
304 | return NULL; | 306 | return NULL; |
305 | va_start(ap, | 307 | va_start (ap, |
306 | raw_data_size); | 308 | raw_data_size); |
307 | bg = plugin->create_group(plugin->cls, | 309 | bg = plugin->create_group (plugin->cls, |
308 | type, | 310 | type, |
309 | nonce, | 311 | nonce, |
310 | raw_data, | 312 | raw_data, |
311 | raw_data_size, | 313 | raw_data_size, |
312 | ap); | 314 | ap); |
313 | va_end(ap); | 315 | va_end (ap); |
314 | return bg; | 316 | return bg; |
315 | } | 317 | } |
316 | 318 | ||
@@ -334,31 +336,31 @@ GNUNET_BLOCK_group_create(struct GNUNET_BLOCK_Context *ctx, | |||
334 | * @return characterization of result | 336 | * @return characterization of result |
335 | */ | 337 | */ |
336 | enum GNUNET_BLOCK_EvaluationResult | 338 | enum GNUNET_BLOCK_EvaluationResult |
337 | GNUNET_BLOCK_evaluate(struct GNUNET_BLOCK_Context *ctx, | 339 | GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx, |
338 | enum GNUNET_BLOCK_Type type, | 340 | enum GNUNET_BLOCK_Type type, |
339 | struct GNUNET_BLOCK_Group *group, | 341 | struct GNUNET_BLOCK_Group *group, |
340 | enum GNUNET_BLOCK_EvaluationOptions eo, | 342 | enum GNUNET_BLOCK_EvaluationOptions eo, |
341 | const struct GNUNET_HashCode *query, | 343 | const struct GNUNET_HashCode *query, |
342 | const void *xquery, | 344 | const void *xquery, |
343 | size_t xquery_size, | 345 | size_t xquery_size, |
344 | const void *reply_block, | 346 | const void *reply_block, |
345 | size_t reply_block_size) | 347 | size_t reply_block_size) |
346 | { | 348 | { |
347 | struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin(ctx, | 349 | struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx, |
348 | type); | 350 | type); |
349 | 351 | ||
350 | if (NULL == plugin) | 352 | if (NULL == plugin) |
351 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | 353 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; |
352 | return plugin->evaluate(plugin->cls, | 354 | return plugin->evaluate (plugin->cls, |
353 | ctx, | 355 | ctx, |
354 | type, | 356 | type, |
355 | group, | 357 | group, |
356 | eo, | 358 | eo, |
357 | query, | 359 | query, |
358 | xquery, | 360 | xquery, |
359 | xquery_size, | 361 | xquery_size, |
360 | reply_block, | 362 | reply_block, |
361 | reply_block_size); | 363 | reply_block_size); |
362 | } | 364 | } |
363 | 365 | ||
364 | 366 | ||
@@ -374,22 +376,22 @@ GNUNET_BLOCK_evaluate(struct GNUNET_BLOCK_Context *ctx, | |||
374 | * (or if extracting a key from a block of this type does not work) | 376 | * (or if extracting a key from a block of this type does not work) |
375 | */ | 377 | */ |
376 | int | 378 | int |
377 | GNUNET_BLOCK_get_key(struct GNUNET_BLOCK_Context *ctx, | 379 | GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx, |
378 | enum GNUNET_BLOCK_Type type, | 380 | enum GNUNET_BLOCK_Type type, |
379 | const void *block, | 381 | const void *block, |
380 | size_t block_size, | 382 | size_t block_size, |
381 | struct GNUNET_HashCode *key) | 383 | struct GNUNET_HashCode *key) |
382 | { | 384 | { |
383 | struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin(ctx, | 385 | struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx, |
384 | type); | 386 | type); |
385 | 387 | ||
386 | if (plugin == NULL) | 388 | if (plugin == NULL) |
387 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | 389 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; |
388 | return plugin->get_key(plugin->cls, | 390 | return plugin->get_key (plugin->cls, |
389 | type, | 391 | type, |
390 | block, | 392 | block, |
391 | block_size, | 393 | block_size, |
392 | key); | 394 | key); |
393 | } | 395 | } |
394 | 396 | ||
395 | 397 | ||
@@ -405,17 +407,17 @@ GNUNET_BLOCK_get_key(struct GNUNET_BLOCK_Context *ctx, | |||
405 | * @return #GNUNET_SYSERR if not supported, #GNUNET_OK on success | 407 | * @return #GNUNET_SYSERR if not supported, #GNUNET_OK on success |
406 | */ | 408 | */ |
407 | int | 409 | int |
408 | GNUNET_BLOCK_group_set_seen(struct GNUNET_BLOCK_Group *bg, | 410 | GNUNET_BLOCK_group_set_seen (struct GNUNET_BLOCK_Group *bg, |
409 | const struct GNUNET_HashCode *seen_results, | 411 | const struct GNUNET_HashCode *seen_results, |
410 | unsigned int seen_results_count) | 412 | unsigned int seen_results_count) |
411 | { | 413 | { |
412 | if (NULL == bg) | 414 | if (NULL == bg) |
413 | return GNUNET_OK; | 415 | return GNUNET_OK; |
414 | if (NULL == bg->mark_seen_cb) | 416 | if (NULL == bg->mark_seen_cb) |
415 | return GNUNET_SYSERR; | 417 | return GNUNET_SYSERR; |
416 | bg->mark_seen_cb(bg, | 418 | bg->mark_seen_cb (bg, |
417 | seen_results, | 419 | seen_results, |
418 | seen_results_count); | 420 | seen_results_count); |
419 | return GNUNET_OK; | 421 | return GNUNET_OK; |
420 | } | 422 | } |
421 | 423 | ||