diff options
Diffstat (limited to 'src/revocation/plugin_block_revocation.c')
-rw-r--r-- | src/revocation/plugin_block_revocation.c | 173 |
1 files changed, 87 insertions, 86 deletions
diff --git a/src/revocation/plugin_block_revocation.c b/src/revocation/plugin_block_revocation.c index e7b4a8cde..124524209 100644 --- a/src/revocation/plugin_block_revocation.c +++ b/src/revocation/plugin_block_revocation.c | |||
@@ -49,7 +49,8 @@ | |||
49 | /** | 49 | /** |
50 | * Context used inside the plugin. | 50 | * Context used inside the plugin. |
51 | */ | 51 | */ |
52 | struct InternalContext { | 52 | struct InternalContext |
53 | { | ||
53 | unsigned int matching_bits; | 54 | unsigned int matching_bits; |
54 | }; | 55 | }; |
55 | 56 | ||
@@ -67,37 +68,38 @@ struct InternalContext { | |||
67 | * by this @a type of block (this is not an error) | 68 | * by this @a type of block (this is not an error) |
68 | */ | 69 | */ |
69 | static struct GNUNET_BLOCK_Group * | 70 | static struct GNUNET_BLOCK_Group * |
70 | block_plugin_revocation_create_group(void *cls, | 71 | block_plugin_revocation_create_group (void *cls, |
71 | enum GNUNET_BLOCK_Type type, | 72 | enum GNUNET_BLOCK_Type type, |
72 | uint32_t nonce, | 73 | uint32_t nonce, |
73 | const void *raw_data, | 74 | const void *raw_data, |
74 | size_t raw_data_size, | 75 | size_t raw_data_size, |
75 | va_list va) | 76 | va_list va) |
76 | { | 77 | { |
77 | unsigned int bf_size; | 78 | unsigned int bf_size; |
78 | const char *guard; | 79 | const char *guard; |
79 | 80 | ||
80 | guard = va_arg(va, const char *); | 81 | guard = va_arg (va, const char *); |
81 | if (0 == strcmp(guard, | 82 | if (0 == strcmp (guard, |
82 | "seen-set-size")) | 83 | "seen-set-size")) |
83 | bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size(va_arg(va, unsigned int), | 84 | bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned |
84 | BLOOMFILTER_K); | 85 | int), |
85 | else if (0 == strcmp(guard, | 86 | BLOOMFILTER_K); |
86 | "filter-size")) | 87 | else if (0 == strcmp (guard, |
87 | bf_size = va_arg(va, unsigned int); | 88 | "filter-size")) |
89 | bf_size = va_arg (va, unsigned int); | ||
88 | else | 90 | else |
89 | { | 91 | { |
90 | GNUNET_break(0); | 92 | GNUNET_break (0); |
91 | bf_size = REVOCATION_BF_SIZE; | 93 | bf_size = REVOCATION_BF_SIZE; |
92 | } | 94 | } |
93 | GNUNET_break(NULL == va_arg(va, const char *)); | 95 | GNUNET_break (NULL == va_arg (va, const char *)); |
94 | return GNUNET_BLOCK_GROUP_bf_create(cls, | 96 | return GNUNET_BLOCK_GROUP_bf_create (cls, |
95 | bf_size, | 97 | bf_size, |
96 | BLOOMFILTER_K, | 98 | BLOOMFILTER_K, |
97 | type, | 99 | type, |
98 | nonce, | 100 | nonce, |
99 | raw_data, | 101 | raw_data, |
100 | raw_data_size); | 102 | raw_data_size); |
101 | } | 103 | } |
102 | 104 | ||
103 | 105 | ||
@@ -118,16 +120,16 @@ block_plugin_revocation_create_group(void *cls, | |||
118 | * @return characterization of result | 120 | * @return characterization of result |
119 | */ | 121 | */ |
120 | static enum GNUNET_BLOCK_EvaluationResult | 122 | static enum GNUNET_BLOCK_EvaluationResult |
121 | block_plugin_revocation_evaluate(void *cls, | 123 | block_plugin_revocation_evaluate (void *cls, |
122 | struct GNUNET_BLOCK_Context *ctx, | 124 | struct GNUNET_BLOCK_Context *ctx, |
123 | enum GNUNET_BLOCK_Type type, | 125 | enum GNUNET_BLOCK_Type type, |
124 | struct GNUNET_BLOCK_Group *group, | 126 | struct GNUNET_BLOCK_Group *group, |
125 | enum GNUNET_BLOCK_EvaluationOptions eo, | 127 | enum GNUNET_BLOCK_EvaluationOptions eo, |
126 | const struct GNUNET_HashCode *query, | 128 | const struct GNUNET_HashCode *query, |
127 | const void *xquery, | 129 | const void *xquery, |
128 | size_t xquery_size, | 130 | size_t xquery_size, |
129 | const void *reply_block, | 131 | const void *reply_block, |
130 | size_t reply_block_size) | 132 | size_t reply_block_size) |
131 | { | 133 | { |
132 | struct InternalContext *ic = cls; | 134 | struct InternalContext *ic = cls; |
133 | struct GNUNET_HashCode chash; | 135 | struct GNUNET_HashCode chash; |
@@ -136,33 +138,33 @@ block_plugin_revocation_evaluate(void *cls, | |||
136 | if (NULL == reply_block) | 138 | if (NULL == reply_block) |
137 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | 139 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; |
138 | if (reply_block_size != sizeof(*rm)) | 140 | if (reply_block_size != sizeof(*rm)) |
139 | { | 141 | { |
140 | GNUNET_break_op(0); | 142 | GNUNET_break_op (0); |
141 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 143 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
142 | } | 144 | } |
143 | if (GNUNET_YES != | 145 | if (GNUNET_YES != |
144 | GNUNET_REVOCATION_check_pow(&rm->public_key, | 146 | GNUNET_REVOCATION_check_pow (&rm->public_key, |
145 | rm->proof_of_work, | 147 | rm->proof_of_work, |
146 | ic->matching_bits)) | 148 | ic->matching_bits)) |
147 | { | 149 | { |
148 | GNUNET_break_op(0); | 150 | GNUNET_break_op (0); |
149 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 151 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
150 | } | 152 | } |
151 | if (GNUNET_OK != | 153 | if (GNUNET_OK != |
152 | GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_REVOCATION, | 154 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_REVOCATION, |
153 | &rm->purpose, | 155 | &rm->purpose, |
154 | &rm->signature, | 156 | &rm->signature, |
155 | &rm->public_key)) | 157 | &rm->public_key)) |
156 | { | 158 | { |
157 | GNUNET_break_op(0); | 159 | GNUNET_break_op (0); |
158 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 160 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
159 | } | 161 | } |
160 | GNUNET_CRYPTO_hash(&rm->public_key, | 162 | GNUNET_CRYPTO_hash (&rm->public_key, |
161 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), | 163 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), |
162 | &chash); | 164 | &chash); |
163 | if (GNUNET_YES == | 165 | if (GNUNET_YES == |
164 | GNUNET_BLOCK_GROUP_bf_test_and_set(group, | 166 | GNUNET_BLOCK_GROUP_bf_test_and_set (group, |
165 | &chash)) | 167 | &chash)) |
166 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | 168 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; |
167 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | 169 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; |
168 | } | 170 | } |
@@ -180,22 +182,22 @@ block_plugin_revocation_evaluate(void *cls, | |||
180 | * (or if extracting a key from a block of this type does not work) | 182 | * (or if extracting a key from a block of this type does not work) |
181 | */ | 183 | */ |
182 | static int | 184 | static int |
183 | block_plugin_revocation_get_key(void *cls, | 185 | block_plugin_revocation_get_key (void *cls, |
184 | enum GNUNET_BLOCK_Type type, | 186 | enum GNUNET_BLOCK_Type type, |
185 | const void *block, | 187 | const void *block, |
186 | size_t block_size, | 188 | size_t block_size, |
187 | struct GNUNET_HashCode *key) | 189 | struct GNUNET_HashCode *key) |
188 | { | 190 | { |
189 | const struct RevokeMessage *rm = block; | 191 | const struct RevokeMessage *rm = block; |
190 | 192 | ||
191 | if (block_size != sizeof(*rm)) | 193 | if (block_size != sizeof(*rm)) |
192 | { | 194 | { |
193 | GNUNET_break_op(0); | 195 | GNUNET_break_op (0); |
194 | return GNUNET_SYSERR; | 196 | return GNUNET_SYSERR; |
195 | } | 197 | } |
196 | GNUNET_CRYPTO_hash(&rm->public_key, | 198 | GNUNET_CRYPTO_hash (&rm->public_key, |
197 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), | 199 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), |
198 | key); | 200 | key); |
199 | return GNUNET_OK; | 201 | return GNUNET_OK; |
200 | } | 202 | } |
201 | 203 | ||
@@ -206,10 +208,9 @@ block_plugin_revocation_get_key(void *cls, | |||
206 | * @param cls the configuration to use | 208 | * @param cls the configuration to use |
207 | */ | 209 | */ |
208 | void * | 210 | void * |
209 | libgnunet_plugin_block_revocation_init(void *cls) | 211 | libgnunet_plugin_block_revocation_init (void *cls) |
210 | { | 212 | { |
211 | static enum GNUNET_BLOCK_Type types[] = | 213 | static enum GNUNET_BLOCK_Type types[] = { |
212 | { | ||
213 | GNUNET_BLOCK_TYPE_REVOCATION, | 214 | GNUNET_BLOCK_TYPE_REVOCATION, |
214 | GNUNET_BLOCK_TYPE_ANY /* end of list */ | 215 | GNUNET_BLOCK_TYPE_ANY /* end of list */ |
215 | }; | 216 | }; |
@@ -219,19 +220,19 @@ libgnunet_plugin_block_revocation_init(void *cls) | |||
219 | unsigned long long matching_bits; | 220 | unsigned long long matching_bits; |
220 | 221 | ||
221 | if (GNUNET_OK != | 222 | if (GNUNET_OK != |
222 | GNUNET_CONFIGURATION_get_value_number(cfg, | 223 | GNUNET_CONFIGURATION_get_value_number (cfg, |
223 | "REVOCATION", | 224 | "REVOCATION", |
224 | "WORKBITS", | 225 | "WORKBITS", |
225 | &matching_bits)) | 226 | &matching_bits)) |
226 | return NULL; | 227 | return NULL; |
227 | 228 | ||
228 | api = GNUNET_new(struct GNUNET_BLOCK_PluginFunctions); | 229 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
229 | api->evaluate = &block_plugin_revocation_evaluate; | 230 | api->evaluate = &block_plugin_revocation_evaluate; |
230 | api->get_key = &block_plugin_revocation_get_key; | 231 | api->get_key = &block_plugin_revocation_get_key; |
231 | api->create_group = &block_plugin_revocation_create_group; | 232 | api->create_group = &block_plugin_revocation_create_group; |
232 | api->types = types; | 233 | api->types = types; |
233 | ic = GNUNET_new(struct InternalContext); | 234 | ic = GNUNET_new (struct InternalContext); |
234 | ic->matching_bits = (unsigned int)matching_bits; | 235 | ic->matching_bits = (unsigned int) matching_bits; |
235 | api->cls = ic; | 236 | api->cls = ic; |
236 | return api; | 237 | return api; |
237 | } | 238 | } |
@@ -241,13 +242,13 @@ libgnunet_plugin_block_revocation_init(void *cls) | |||
241 | * Exit point from the plugin. | 242 | * Exit point from the plugin. |
242 | */ | 243 | */ |
243 | void * | 244 | void * |
244 | libgnunet_plugin_block_revocation_done(void *cls) | 245 | libgnunet_plugin_block_revocation_done (void *cls) |
245 | { | 246 | { |
246 | struct GNUNET_BLOCK_PluginFunctions *api = cls; | 247 | struct GNUNET_BLOCK_PluginFunctions *api = cls; |
247 | struct InternalContext *ic = api->cls; | 248 | struct InternalContext *ic = api->cls; |
248 | 249 | ||
249 | GNUNET_free(ic); | 250 | GNUNET_free (ic); |
250 | GNUNET_free(api); | 251 | GNUNET_free (api); |
251 | return NULL; | 252 | return NULL; |
252 | } | 253 | } |
253 | 254 | ||