diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-02-20 17:19:47 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-02-20 17:19:47 +0100 |
commit | f6f7fbbe98c110867febbcca647da8308be123c7 (patch) | |
tree | af69447cf4f08c417197685855c097c132aea8a1 /src/block/plugin_block_template.c | |
parent | a3882b58f1c5976677aa65b0af8a48e8e946b06e (diff) | |
download | gnunet-f6f7fbbe98c110867febbcca647da8308be123c7.tar.gz gnunet-f6f7fbbe98c110867febbcca647da8308be123c7.zip |
completed big block refactoring in preparation for SET-BLOCK integration
Diffstat (limited to 'src/block/plugin_block_template.c')
-rw-r--r-- | src/block/plugin_block_template.c | 88 |
1 files changed, 61 insertions, 27 deletions
diff --git a/src/block/plugin_block_template.c b/src/block/plugin_block_template.c index 6cb69ef5f..0e8107af2 100644 --- a/src/block/plugin_block_template.c +++ b/src/block/plugin_block_template.c | |||
@@ -26,9 +26,52 @@ | |||
26 | 26 | ||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_block_plugin.h" | 28 | #include "gnunet_block_plugin.h" |
29 | #include "gnunet_block_group_lib.h" | ||
29 | 30 | ||
30 | #define DEBUG_TEMPLATE GNUNET_EXTRA_LOGGING | 31 | #define DEBUG_TEMPLATE GNUNET_EXTRA_LOGGING |
31 | 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 | /** | ||
41 | * How big is the BF we use for DHT blocks? | ||
42 | */ | ||
43 | #define TEMPLATE_BF_SIZE 8 | ||
44 | |||
45 | |||
46 | /** | ||
47 | * Create a new block group. | ||
48 | * | ||
49 | * @param ctx block context in which the block group is created | ||
50 | * @param type type of the block for which we are creating the group | ||
51 | * @param nonce random value used to seed the group creation | ||
52 | * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh | ||
53 | * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh | ||
54 | * @param va variable arguments specific to @a type | ||
55 | * @return block group handle, NULL if block groups are not supported | ||
56 | * by this @a type of block (this is not an error) | ||
57 | */ | ||
58 | static struct GNUNET_BLOCK_Group * | ||
59 | block_plugin_template_create_group (void *cls, | ||
60 | enum GNUNET_BLOCK_Type type, | ||
61 | uint32_t nonce, | ||
62 | const void *raw_data, | ||
63 | size_t raw_data_size, | ||
64 | va_list va) | ||
65 | { | ||
66 | return GNUNET_BLOCK_GROUP_bf_create (cls, | ||
67 | TEMPLATE_BF_SIZE, | ||
68 | BLOOMFILTER_K, | ||
69 | type, | ||
70 | nonce, | ||
71 | raw_data, | ||
72 | raw_data_size); | ||
73 | } | ||
74 | |||
32 | 75 | ||
33 | /** | 76 | /** |
34 | * Function called to validate a reply or a request. For | 77 | * Function called to validate a reply or a request. For |
@@ -36,10 +79,9 @@ | |||
36 | * | 79 | * |
37 | * @param cls closure | 80 | * @param cls closure |
38 | * @param type block type | 81 | * @param type block type |
82 | * @param group block group to use | ||
39 | * @param eo control flags | 83 | * @param eo control flags |
40 | * @param query original query (hash) | 84 | * @param query original query (hash) |
41 | * @param bf pointer to bloom filter associated with query; possibly updated (!) | ||
42 | * @param bf_mutator mutation value for bf | ||
43 | * @param xquery extrended query data (can be NULL, depending on type) | 85 | * @param xquery extrended query data (can be NULL, depending on type) |
44 | * @param xquery_size number of bytes in xquery | 86 | * @param xquery_size number of bytes in xquery |
45 | * @param reply_block response to validate | 87 | * @param reply_block response to validate |
@@ -49,36 +91,25 @@ | |||
49 | static enum GNUNET_BLOCK_EvaluationResult | 91 | static enum GNUNET_BLOCK_EvaluationResult |
50 | block_plugin_template_evaluate (void *cls, | 92 | block_plugin_template_evaluate (void *cls, |
51 | enum GNUNET_BLOCK_Type type, | 93 | enum GNUNET_BLOCK_Type type, |
94 | struct GNUNET_BLOCK_Group *group, | ||
52 | enum GNUNET_BLOCK_EvaluationOptions eo, | 95 | enum GNUNET_BLOCK_EvaluationOptions eo, |
53 | const struct GNUNET_HashCode *query, | 96 | const struct GNUNET_HashCode *query, |
54 | struct GNUNET_CONTAINER_BloomFilter **bf, | ||
55 | int32_t bf_mutator, | ||
56 | const void *xquery, | 97 | const void *xquery, |
57 | size_t xquery_size, | 98 | size_t xquery_size, |
58 | const void *reply_block, | 99 | const void *reply_block, |
59 | size_t reply_block_size) | 100 | size_t reply_block_size) |
60 | { | 101 | { |
61 | struct GNUNET_HashCode chash; | 102 | struct GNUNET_HashCode chash; |
62 | struct GNUNET_HashCode mhash; | ||
63 | /* FIXME: check validity first... */ | ||
64 | 103 | ||
65 | /* mandatory duplicate-detection code... */ | 104 | if (NULL == reply_block) |
66 | if (NULL != bf) | 105 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; |
67 | { | 106 | GNUNET_CRYPTO_hash (reply_block, |
68 | GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash); | 107 | reply_block_size, |
69 | GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash); | 108 | &chash); |
70 | if (NULL != *bf) | 109 | if (GNUNET_YES == |
71 | { | 110 | GNUNET_BLOCK_GROUP_bf_test_and_set (group, |
72 | if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash)) | 111 | &chash)) |
73 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | 112 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; |
74 | } | ||
75 | else | ||
76 | { | ||
77 | *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, 64 /* BLOOMFILTER_K */); | ||
78 | } | ||
79 | GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash); | ||
80 | } | ||
81 | /* FIXME: other stuff here... */ | ||
82 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | 113 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; |
83 | } | 114 | } |
84 | 115 | ||
@@ -91,13 +122,15 @@ block_plugin_template_evaluate (void *cls, | |||
91 | * @param block block to get the key for | 122 | * @param block block to get the key for |
92 | * @param block_size number of bytes in block | 123 | * @param block_size number of bytes in block |
93 | * @param key set to the key (query) for the given block | 124 | * @param key set to the key (query) for the given block |
94 | * @return GNUNET_OK on success, GNUNET_SYSERR if type not supported | 125 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported |
95 | * (or if extracting a key from a block of this type does not work) | 126 | * (or if extracting a key from a block of this type does not work) |
96 | */ | 127 | */ |
97 | static int | 128 | static int |
98 | block_plugin_template_get_key (void *cls, enum GNUNET_BLOCK_Type type, | 129 | block_plugin_template_get_key (void *cls, |
99 | const void *block, size_t block_size, | 130 | enum GNUNET_BLOCK_Type type, |
100 | struct GNUNET_HashCode * key) | 131 | const void *block, |
132 | size_t block_size, | ||
133 | struct GNUNET_HashCode *key) | ||
101 | { | 134 | { |
102 | return GNUNET_SYSERR; | 135 | return GNUNET_SYSERR; |
103 | } | 136 | } |
@@ -119,6 +152,7 @@ libgnunet_plugin_block_template_init (void *cls) | |||
119 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 152 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
120 | api->evaluate = &block_plugin_template_evaluate; | 153 | api->evaluate = &block_plugin_template_evaluate; |
121 | api->get_key = &block_plugin_template_get_key; | 154 | api->get_key = &block_plugin_template_get_key; |
155 | api->create_group = &block_plugin_template_create_group; | ||
122 | api->types = types; | 156 | api->types = types; |
123 | return api; | 157 | return api; |
124 | } | 158 | } |