diff options
Diffstat (limited to 'src/block/plugin_block_test.c')
-rw-r--r-- | src/block/plugin_block_test.c | 80 |
1 files changed, 55 insertions, 25 deletions
diff --git a/src/block/plugin_block_test.c b/src/block/plugin_block_test.c index b692d6230..615f1571b 100644 --- a/src/block/plugin_block_test.c +++ b/src/block/plugin_block_test.c | |||
@@ -27,7 +27,7 @@ | |||
27 | 27 | ||
28 | #include "platform.h" | 28 | #include "platform.h" |
29 | #include "gnunet_block_plugin.h" | 29 | #include "gnunet_block_plugin.h" |
30 | 30 | #include "gnunet_block_group_lib.h" | |
31 | 31 | ||
32 | /** | 32 | /** |
33 | * Number of bits we set per entry in the bloomfilter. | 33 | * Number of bits we set per entry in the bloomfilter. |
@@ -36,15 +36,50 @@ | |||
36 | #define BLOOMFILTER_K 16 | 36 | #define BLOOMFILTER_K 16 |
37 | 37 | ||
38 | /** | 38 | /** |
39 | * How big is the BF we use for DHT blocks? | ||
40 | */ | ||
41 | #define TEST_BF_SIZE 8 | ||
42 | |||
43 | |||
44 | /** | ||
45 | * Create a new block group. | ||
46 | * | ||
47 | * @param ctx block context in which the block group is created | ||
48 | * @param type type of the block for which we are creating the group | ||
49 | * @param nonce random value used to seed the group creation | ||
50 | * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh | ||
51 | * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh | ||
52 | * @param va variable arguments specific to @a type | ||
53 | * @return block group handle, NULL if block groups are not supported | ||
54 | * by this @a type of block (this is not an error) | ||
55 | */ | ||
56 | static struct GNUNET_BLOCK_Group * | ||
57 | block_plugin_test_create_group (void *cls, | ||
58 | enum GNUNET_BLOCK_Type type, | ||
59 | uint32_t nonce, | ||
60 | const void *raw_data, | ||
61 | size_t raw_data_size, | ||
62 | va_list va) | ||
63 | { | ||
64 | return GNUNET_BLOCK_GROUP_bf_create (cls, | ||
65 | TEST_BF_SIZE, | ||
66 | BLOOMFILTER_K, | ||
67 | type, | ||
68 | nonce, | ||
69 | raw_data, | ||
70 | raw_data_size); | ||
71 | } | ||
72 | |||
73 | |||
74 | /** | ||
39 | * Function called to validate a reply or a request. For | 75 | * Function called to validate a reply or a request. For |
40 | * request evaluation, simply pass "NULL" for the reply_block. | 76 | * request evaluation, simply pass "NULL" for the reply_block. |
41 | * | 77 | * |
42 | * @param cls closure | 78 | * @param cls closure |
43 | * @param type block type | 79 | * @param type block type |
80 | * @param group group to check against | ||
44 | * @param eo control flags | 81 | * @param eo control flags |
45 | * @param query original query (hash) | 82 | * @param query original query (hash) |
46 | * @param bf pointer to bloom filter associated with query; possibly updated (!) | ||
47 | * @param bf_mutator mutation value for @a bf | ||
48 | * @param xquery extrended query data (can be NULL, depending on type) | 83 | * @param xquery extrended query data (can be NULL, depending on type) |
49 | * @param xquery_size number of bytes in @a xquery | 84 | * @param xquery_size number of bytes in @a xquery |
50 | * @param reply_block response to validate | 85 | * @param reply_block response to validate |
@@ -54,20 +89,21 @@ | |||
54 | static enum GNUNET_BLOCK_EvaluationResult | 89 | static enum GNUNET_BLOCK_EvaluationResult |
55 | block_plugin_test_evaluate (void *cls, | 90 | block_plugin_test_evaluate (void *cls, |
56 | enum GNUNET_BLOCK_Type type, | 91 | enum GNUNET_BLOCK_Type type, |
92 | struct GNUNET_BLOCK_Group *group, | ||
57 | enum GNUNET_BLOCK_EvaluationOptions eo, | 93 | enum GNUNET_BLOCK_EvaluationOptions eo, |
58 | const struct GNUNET_HashCode *query, | 94 | const struct GNUNET_HashCode *query, |
59 | struct GNUNET_CONTAINER_BloomFilter **bf, | ||
60 | int32_t bf_mutator, | ||
61 | const void *xquery, | 95 | const void *xquery, |
62 | size_t xquery_size, | 96 | size_t xquery_size, |
63 | const void *reply_block, | 97 | const void *reply_block, |
64 | size_t reply_block_size) | 98 | size_t reply_block_size) |
65 | { | 99 | { |
66 | struct GNUNET_HashCode chash; | 100 | struct GNUNET_HashCode chash; |
67 | struct GNUNET_HashCode mhash; | ||
68 | 101 | ||
69 | if ( GNUNET_BLOCK_TYPE_TEST != type) | 102 | if ( GNUNET_BLOCK_TYPE_TEST != type) |
103 | { | ||
104 | GNUNET_break (0); | ||
70 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | 105 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; |
106 | } | ||
71 | if (0 != xquery_size) | 107 | if (0 != xquery_size) |
72 | { | 108 | { |
73 | GNUNET_break_op (0); | 109 | GNUNET_break_op (0); |
@@ -75,22 +111,13 @@ block_plugin_test_evaluate (void *cls, | |||
75 | } | 111 | } |
76 | if (NULL == reply_block) | 112 | if (NULL == reply_block) |
77 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | 113 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; |
78 | 114 | GNUNET_CRYPTO_hash (reply_block, | |
79 | if (NULL != bf) | 115 | reply_block_size, |
80 | { | 116 | &chash); |
81 | GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash); | 117 | if (GNUNET_YES == |
82 | GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash); | 118 | GNUNET_BLOCK_GROUP_bf_test_and_set (group, |
83 | if (NULL != *bf) | 119 | &chash)) |
84 | { | 120 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; |
85 | if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash)) | ||
86 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | ||
87 | } | ||
88 | else | ||
89 | { | ||
90 | *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K); | ||
91 | } | ||
92 | GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash); | ||
93 | } | ||
94 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | 121 | return GNUNET_BLOCK_EVALUATION_OK_MORE; |
95 | } | 122 | } |
96 | 123 | ||
@@ -107,9 +134,11 @@ block_plugin_test_evaluate (void *cls, | |||
107 | * (or if extracting a key from a block of this type does not work) | 134 | * (or if extracting a key from a block of this type does not work) |
108 | */ | 135 | */ |
109 | static int | 136 | static int |
110 | block_plugin_test_get_key (void *cls, enum GNUNET_BLOCK_Type type, | 137 | block_plugin_test_get_key (void *cls, |
111 | const void *block, size_t block_size, | 138 | enum GNUNET_BLOCK_Type type, |
112 | struct GNUNET_HashCode * key) | 139 | const void *block, |
140 | size_t block_size, | ||
141 | struct GNUNET_HashCode *key) | ||
113 | { | 142 | { |
114 | /* always fails since there is no fixed relationship between | 143 | /* always fails since there is no fixed relationship between |
115 | * keys and values for test values */ | 144 | * keys and values for test values */ |
@@ -136,6 +165,7 @@ libgnunet_plugin_block_test_init (void *cls) | |||
136 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 165 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
137 | api->evaluate = &block_plugin_test_evaluate; | 166 | api->evaluate = &block_plugin_test_evaluate; |
138 | api->get_key = &block_plugin_test_get_key; | 167 | api->get_key = &block_plugin_test_get_key; |
168 | api->create_group = &block_plugin_test_create_group; | ||
139 | api->types = types; | 169 | api->types = types; |
140 | return api; | 170 | return api; |
141 | } | 171 | } |