diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/revocation | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/revocation')
-rw-r--r-- | src/revocation/gnunet-revocation.c | 491 | ||||
-rw-r--r-- | src/revocation/gnunet-service-revocation.c | 943 | ||||
-rw-r--r-- | src/revocation/plugin_block_revocation.c | 173 | ||||
-rw-r--r-- | src/revocation/revocation.h | 12 | ||||
-rw-r--r-- | src/revocation/revocation_api.c | 289 | ||||
-rw-r--r-- | src/revocation/test_revocation.c | 421 |
6 files changed, 1172 insertions, 1157 deletions
diff --git a/src/revocation/gnunet-revocation.c b/src/revocation/gnunet-revocation.c index da93e6903..652c1e62d 100644 --- a/src/revocation/gnunet-revocation.c +++ b/src/revocation/gnunet-revocation.c | |||
@@ -91,23 +91,23 @@ static struct GNUNET_SCHEDULER_Task *pow_task; | |||
91 | * @param cls closure | 91 | * @param cls closure |
92 | */ | 92 | */ |
93 | static void | 93 | static void |
94 | do_shutdown(void *cls) | 94 | do_shutdown (void *cls) |
95 | { | 95 | { |
96 | if (NULL != el) | 96 | if (NULL != el) |
97 | { | 97 | { |
98 | GNUNET_IDENTITY_ego_lookup_cancel(el); | 98 | GNUNET_IDENTITY_ego_lookup_cancel (el); |
99 | el = NULL; | 99 | el = NULL; |
100 | } | 100 | } |
101 | if (NULL != q) | 101 | if (NULL != q) |
102 | { | 102 | { |
103 | GNUNET_REVOCATION_query_cancel(q); | 103 | GNUNET_REVOCATION_query_cancel (q); |
104 | q = NULL; | 104 | q = NULL; |
105 | } | 105 | } |
106 | if (NULL != h) | 106 | if (NULL != h) |
107 | { | 107 | { |
108 | GNUNET_REVOCATION_revoke_cancel(h); | 108 | GNUNET_REVOCATION_revoke_cancel (h); |
109 | h = NULL; | 109 | h = NULL; |
110 | } | 110 | } |
111 | } | 111 | } |
112 | 112 | ||
113 | 113 | ||
@@ -118,28 +118,28 @@ do_shutdown(void *cls) | |||
118 | * @param is_valid #GNUNET_YES if the key is still valid, #GNUNET_NO if not, #GNUNET_SYSERR on error | 118 | * @param is_valid #GNUNET_YES if the key is still valid, #GNUNET_NO if not, #GNUNET_SYSERR on error |
119 | */ | 119 | */ |
120 | static void | 120 | static void |
121 | print_query_result(void *cls, int is_valid) | 121 | print_query_result (void *cls, int is_valid) |
122 | { | 122 | { |
123 | q = NULL; | 123 | q = NULL; |
124 | switch (is_valid) | 124 | switch (is_valid) |
125 | { | 125 | { |
126 | case GNUNET_YES: | 126 | case GNUNET_YES: |
127 | fprintf(stdout, _("Key `%s' is valid\n"), test_ego); | 127 | fprintf (stdout, _ ("Key `%s' is valid\n"), test_ego); |
128 | break; | 128 | break; |
129 | 129 | ||
130 | case GNUNET_NO: | 130 | case GNUNET_NO: |
131 | fprintf(stdout, _("Key `%s' has been revoked\n"), test_ego); | 131 | fprintf (stdout, _ ("Key `%s' has been revoked\n"), test_ego); |
132 | break; | 132 | break; |
133 | 133 | ||
134 | case GNUNET_SYSERR: | 134 | case GNUNET_SYSERR: |
135 | fprintf(stdout, "%s", _("Internal error\n")); | 135 | fprintf (stdout, "%s", _ ("Internal error\n")); |
136 | break; | 136 | break; |
137 | 137 | ||
138 | default: | 138 | default: |
139 | GNUNET_break(0); | 139 | GNUNET_break (0); |
140 | break; | 140 | break; |
141 | } | 141 | } |
142 | GNUNET_SCHEDULER_shutdown(); | 142 | GNUNET_SCHEDULER_shutdown (); |
143 | } | 143 | } |
144 | 144 | ||
145 | 145 | ||
@@ -150,47 +150,48 @@ print_query_result(void *cls, int is_valid) | |||
150 | * @param is_valid #GNUNET_YES if the key is still valid, #GNUNET_NO if not, #GNUNET_SYSERR on error | 150 | * @param is_valid #GNUNET_YES if the key is still valid, #GNUNET_NO if not, #GNUNET_SYSERR on error |
151 | */ | 151 | */ |
152 | static void | 152 | static void |
153 | print_revocation_result(void *cls, int is_valid) | 153 | print_revocation_result (void *cls, int is_valid) |
154 | { | 154 | { |
155 | h = NULL; | 155 | h = NULL; |
156 | switch (is_valid) | 156 | switch (is_valid) |
157 | { | 157 | { |
158 | case GNUNET_YES: | 158 | case GNUNET_YES: |
159 | if (NULL != revoke_ego) | 159 | if (NULL != revoke_ego) |
160 | fprintf(stdout, | 160 | fprintf (stdout, |
161 | _("Key for ego `%s' is still valid, revocation failed (!)\n"), | 161 | _ ("Key for ego `%s' is still valid, revocation failed (!)\n"), |
162 | revoke_ego); | 162 | revoke_ego); |
163 | else | 163 | else |
164 | fprintf(stdout, "%s", _("Revocation failed (!)\n")); | 164 | fprintf (stdout, "%s", _ ("Revocation failed (!)\n")); |
165 | break; | 165 | break; |
166 | 166 | ||
167 | case GNUNET_NO: | 167 | case GNUNET_NO: |
168 | if (NULL != revoke_ego) | 168 | if (NULL != revoke_ego) |
169 | fprintf(stdout, | 169 | fprintf (stdout, |
170 | _("Key for ego `%s' has been successfully revoked\n"), | 170 | _ ("Key for ego `%s' has been successfully revoked\n"), |
171 | revoke_ego); | 171 | revoke_ego); |
172 | else | 172 | else |
173 | fprintf(stdout, "%s", _("Revocation successful.\n")); | 173 | fprintf (stdout, "%s", _ ("Revocation successful.\n")); |
174 | break; | 174 | break; |
175 | 175 | ||
176 | case GNUNET_SYSERR: | 176 | case GNUNET_SYSERR: |
177 | fprintf(stdout, | 177 | fprintf (stdout, |
178 | "%s", | 178 | "%s", |
179 | _("Internal error, key revocation might have failed\n")); | 179 | _ ("Internal error, key revocation might have failed\n")); |
180 | break; | 180 | break; |
181 | 181 | ||
182 | default: | 182 | default: |
183 | GNUNET_break(0); | 183 | GNUNET_break (0); |
184 | break; | 184 | break; |
185 | } | 185 | } |
186 | GNUNET_SCHEDULER_shutdown(); | 186 | GNUNET_SCHEDULER_shutdown (); |
187 | } | 187 | } |
188 | 188 | ||
189 | 189 | ||
190 | /** | 190 | /** |
191 | * Data needed to perform a revocation. | 191 | * Data needed to perform a revocation. |
192 | */ | 192 | */ |
193 | struct RevocationData { | 193 | struct RevocationData |
194 | { | ||
194 | /** | 195 | /** |
195 | * Public key. | 196 | * Public key. |
196 | */ | 197 | */ |
@@ -212,14 +213,14 @@ struct RevocationData { | |||
212 | * Perform the revocation. | 213 | * Perform the revocation. |
213 | */ | 214 | */ |
214 | static void | 215 | static void |
215 | perform_revocation(const struct RevocationData *rd) | 216 | perform_revocation (const struct RevocationData *rd) |
216 | { | 217 | { |
217 | h = GNUNET_REVOCATION_revoke(cfg, | 218 | h = GNUNET_REVOCATION_revoke (cfg, |
218 | &rd->key, | 219 | &rd->key, |
219 | &rd->sig, | 220 | &rd->sig, |
220 | rd->pow, | 221 | rd->pow, |
221 | &print_revocation_result, | 222 | &print_revocation_result, |
222 | NULL); | 223 | NULL); |
223 | } | 224 | } |
224 | 225 | ||
225 | 226 | ||
@@ -230,16 +231,16 @@ perform_revocation(const struct RevocationData *rd) | |||
230 | * @param rd data to sync | 231 | * @param rd data to sync |
231 | */ | 232 | */ |
232 | static void | 233 | static void |
233 | sync_rd(const struct RevocationData *rd) | 234 | sync_rd (const struct RevocationData *rd) |
234 | { | 235 | { |
235 | if ((NULL != filename) && | 236 | if ((NULL != filename) && |
236 | (sizeof(struct RevocationData) == | 237 | (sizeof(struct RevocationData) == |
237 | GNUNET_DISK_fn_write(filename, | 238 | GNUNET_DISK_fn_write (filename, |
238 | &rd, | 239 | &rd, |
239 | sizeof(rd), | 240 | sizeof(rd), |
240 | GNUNET_DISK_PERM_USER_READ | | 241 | GNUNET_DISK_PERM_USER_READ |
241 | GNUNET_DISK_PERM_USER_WRITE))) | 242 | | GNUNET_DISK_PERM_USER_WRITE))) |
242 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "write", filename); | 243 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); |
243 | } | 244 | } |
244 | 245 | ||
245 | 246 | ||
@@ -249,17 +250,17 @@ sync_rd(const struct RevocationData *rd) | |||
249 | * @param cls the `struct RevocationData` | 250 | * @param cls the `struct RevocationData` |
250 | */ | 251 | */ |
251 | static void | 252 | static void |
252 | calculate_pow_shutdown(void *cls) | 253 | calculate_pow_shutdown (void *cls) |
253 | { | 254 | { |
254 | struct RevocationData *rd = cls; | 255 | struct RevocationData *rd = cls; |
255 | 256 | ||
256 | if (NULL != pow_task) | 257 | if (NULL != pow_task) |
257 | { | 258 | { |
258 | GNUNET_SCHEDULER_cancel(pow_task); | 259 | GNUNET_SCHEDULER_cancel (pow_task); |
259 | pow_task = NULL; | 260 | pow_task = NULL; |
260 | } | 261 | } |
261 | sync_rd(rd); | 262 | sync_rd (rd); |
262 | GNUNET_free(rd); | 263 | GNUNET_free (rd); |
263 | } | 264 | } |
264 | 265 | ||
265 | 266 | ||
@@ -269,53 +270,53 @@ calculate_pow_shutdown(void *cls) | |||
269 | * @param cls the `struct RevocationData` | 270 | * @param cls the `struct RevocationData` |
270 | */ | 271 | */ |
271 | static void | 272 | static void |
272 | calculate_pow(void *cls) | 273 | calculate_pow (void *cls) |
273 | { | 274 | { |
274 | struct RevocationData *rd = cls; | 275 | struct RevocationData *rd = cls; |
275 | 276 | ||
276 | /* store temporary results */ | 277 | /* store temporary results */ |
277 | pow_task = NULL; | 278 | pow_task = NULL; |
278 | if (0 == (rd->pow % 128)) | 279 | if (0 == (rd->pow % 128)) |
279 | sync_rd(rd); | 280 | sync_rd (rd); |
280 | /* display progress estimate */ | 281 | /* display progress estimate */ |
281 | if ((0 == ((1 << matching_bits) / 100 / 50)) || | 282 | if ((0 == ((1 << matching_bits) / 100 / 50)) || |
282 | (0 == (rd->pow % ((1 << matching_bits) / 100 / 50)))) | 283 | (0 == (rd->pow % ((1 << matching_bits) / 100 / 50)))) |
283 | fprintf(stderr, "%s", "."); | 284 | fprintf (stderr, "%s", "."); |
284 | if ((0 != rd->pow) && ((0 == ((1 << matching_bits) / 100)) || | 285 | if ((0 != rd->pow) && ((0 == ((1 << matching_bits) / 100)) || |
285 | (0 == (rd->pow % ((1 << matching_bits) / 100))))) | 286 | (0 == (rd->pow % ((1 << matching_bits) / 100))))) |
286 | fprintf(stderr, | 287 | fprintf (stderr, |
287 | " - @ %3u%% (estimate)\n", | 288 | " - @ %3u%% (estimate)\n", |
288 | (unsigned int)(rd->pow * 100) / (1 << matching_bits)); | 289 | (unsigned int) (rd->pow * 100) / (1 << matching_bits)); |
289 | /* actually do POW calculation */ | 290 | /* actually do POW calculation */ |
290 | rd->pow++; | 291 | rd->pow++; |
291 | if (GNUNET_OK == GNUNET_REVOCATION_check_pow(&rd->key, | 292 | if (GNUNET_OK == GNUNET_REVOCATION_check_pow (&rd->key, |
292 | rd->pow, | 293 | rd->pow, |
293 | (unsigned int)matching_bits)) | 294 | (unsigned int) matching_bits)) |
295 | { | ||
296 | if ((NULL != filename) && | ||
297 | (sizeof(struct RevocationData) != | ||
298 | GNUNET_DISK_fn_write (filename, | ||
299 | rd, | ||
300 | sizeof(struct RevocationData), | ||
301 | GNUNET_DISK_PERM_USER_READ | ||
302 | | GNUNET_DISK_PERM_USER_WRITE))) | ||
303 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); | ||
304 | if (perform) | ||
294 | { | 305 | { |
295 | if ((NULL != filename) && | 306 | perform_revocation (rd); |
296 | (sizeof(struct RevocationData) != | ||
297 | GNUNET_DISK_fn_write(filename, | ||
298 | rd, | ||
299 | sizeof(struct RevocationData), | ||
300 | GNUNET_DISK_PERM_USER_READ | | ||
301 | GNUNET_DISK_PERM_USER_WRITE))) | ||
302 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "write", filename); | ||
303 | if (perform) | ||
304 | { | ||
305 | perform_revocation(rd); | ||
306 | } | ||
307 | else | ||
308 | { | ||
309 | fprintf(stderr, "%s", "\n"); | ||
310 | fprintf(stderr, | ||
311 | _("Revocation certificate for `%s' stored in `%s'\n"), | ||
312 | revoke_ego, | ||
313 | filename); | ||
314 | GNUNET_SCHEDULER_shutdown(); | ||
315 | } | ||
316 | return; | ||
317 | } | 307 | } |
318 | pow_task = GNUNET_SCHEDULER_add_now(&calculate_pow, rd); | 308 | else |
309 | { | ||
310 | fprintf (stderr, "%s", "\n"); | ||
311 | fprintf (stderr, | ||
312 | _ ("Revocation certificate for `%s' stored in `%s'\n"), | ||
313 | revoke_ego, | ||
314 | filename); | ||
315 | GNUNET_SCHEDULER_shutdown (); | ||
316 | } | ||
317 | return; | ||
318 | } | ||
319 | pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, rd); | ||
319 | } | 320 | } |
320 | 321 | ||
321 | 322 | ||
@@ -326,57 +327,57 @@ calculate_pow(void *cls) | |||
326 | * @param ego the ego, NULL if not found | 327 | * @param ego the ego, NULL if not found |
327 | */ | 328 | */ |
328 | static void | 329 | static void |
329 | ego_callback(void *cls, const struct GNUNET_IDENTITY_Ego *ego) | 330 | ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego) |
330 | { | 331 | { |
331 | struct RevocationData *rd; | 332 | struct RevocationData *rd; |
332 | struct GNUNET_CRYPTO_EcdsaPublicKey key; | 333 | struct GNUNET_CRYPTO_EcdsaPublicKey key; |
333 | 334 | ||
334 | el = NULL; | 335 | el = NULL; |
335 | if (NULL == ego) | 336 | if (NULL == ego) |
336 | { | 337 | { |
337 | fprintf(stdout, _("Ego `%s' not found.\n"), revoke_ego); | 338 | fprintf (stdout, _ ("Ego `%s' not found.\n"), revoke_ego); |
338 | GNUNET_SCHEDULER_shutdown(); | 339 | GNUNET_SCHEDULER_shutdown (); |
339 | return; | 340 | return; |
340 | } | 341 | } |
341 | GNUNET_IDENTITY_ego_get_public_key(ego, &key); | 342 | GNUNET_IDENTITY_ego_get_public_key (ego, &key); |
342 | rd = GNUNET_new(struct RevocationData); | 343 | rd = GNUNET_new (struct RevocationData); |
343 | if ((NULL != filename) && (GNUNET_YES == GNUNET_DISK_file_test(filename)) && | 344 | if ((NULL != filename) && (GNUNET_YES == GNUNET_DISK_file_test (filename)) && |
344 | (sizeof(struct RevocationData) == | 345 | (sizeof(struct RevocationData) == |
345 | GNUNET_DISK_fn_read(filename, rd, sizeof(struct RevocationData)))) | 346 | GNUNET_DISK_fn_read (filename, rd, sizeof(struct RevocationData)))) |
347 | { | ||
348 | if (0 != GNUNET_memcmp (&rd->key, &key)) | ||
346 | { | 349 | { |
347 | if (0 != GNUNET_memcmp(&rd->key, &key)) | 350 | fprintf (stderr, |
348 | { | 351 | _ ("Error: revocation certificate in `%s' is not for `%s'\n"), |
349 | fprintf(stderr, | 352 | filename, |
350 | _("Error: revocation certificate in `%s' is not for `%s'\n"), | 353 | revoke_ego); |
351 | filename, | 354 | GNUNET_free (rd); |
352 | revoke_ego); | 355 | return; |
353 | GNUNET_free(rd); | ||
354 | return; | ||
355 | } | ||
356 | } | 356 | } |
357 | } | ||
357 | else | 358 | else |
358 | { | 359 | { |
359 | GNUNET_REVOCATION_sign_revocation(GNUNET_IDENTITY_ego_get_private_key( | 360 | GNUNET_REVOCATION_sign_revocation (GNUNET_IDENTITY_ego_get_private_key ( |
360 | ego), | 361 | ego), |
361 | &rd->sig); | 362 | &rd->sig); |
362 | rd->key = key; | 363 | rd->key = key; |
363 | } | 364 | } |
364 | if (GNUNET_YES == | 365 | if (GNUNET_YES == |
365 | GNUNET_REVOCATION_check_pow(&key, rd->pow, (unsigned int)matching_bits)) | 366 | GNUNET_REVOCATION_check_pow (&key, rd->pow, (unsigned int) matching_bits)) |
366 | { | 367 | { |
367 | fprintf(stderr, "%s", _("Revocation certificate ready\n")); | 368 | fprintf (stderr, "%s", _ ("Revocation certificate ready\n")); |
368 | if (perform) | 369 | if (perform) |
369 | perform_revocation(rd); | 370 | perform_revocation (rd); |
370 | else | 371 | else |
371 | GNUNET_SCHEDULER_shutdown(); | 372 | GNUNET_SCHEDULER_shutdown (); |
372 | GNUNET_free(rd); | 373 | GNUNET_free (rd); |
373 | return; | 374 | return; |
374 | } | 375 | } |
375 | fprintf(stderr, | 376 | fprintf (stderr, |
376 | "%s", | 377 | "%s", |
377 | _("Revocation certificate not ready, calculating proof of work\n")); | 378 | _ ("Revocation certificate not ready, calculating proof of work\n")); |
378 | pow_task = GNUNET_SCHEDULER_add_now(&calculate_pow, rd); | 379 | pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, rd); |
379 | GNUNET_SCHEDULER_add_shutdown(&calculate_pow_shutdown, rd); | 380 | GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, rd); |
380 | } | 381 | } |
381 | 382 | ||
382 | 383 | ||
@@ -389,85 +390,85 @@ ego_callback(void *cls, const struct GNUNET_IDENTITY_Ego *ego) | |||
389 | * @param c configuration | 390 | * @param c configuration |
390 | */ | 391 | */ |
391 | static void | 392 | static void |
392 | run(void *cls, | 393 | run (void *cls, |
393 | char *const *args, | 394 | char *const *args, |
394 | const char *cfgfile, | 395 | const char *cfgfile, |
395 | const struct GNUNET_CONFIGURATION_Handle *c) | 396 | const struct GNUNET_CONFIGURATION_Handle *c) |
396 | { | 397 | { |
397 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; | 398 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; |
398 | struct RevocationData rd; | 399 | struct RevocationData rd; |
399 | 400 | ||
400 | cfg = c; | 401 | cfg = c; |
401 | if (NULL != test_ego) | 402 | if (NULL != test_ego) |
403 | { | ||
404 | if (GNUNET_OK != | ||
405 | GNUNET_CRYPTO_ecdsa_public_key_from_string (test_ego, | ||
406 | strlen (test_ego), | ||
407 | &pk)) | ||
402 | { | 408 | { |
403 | if (GNUNET_OK != | 409 | fprintf (stderr, _ ("Public key `%s' malformed\n"), test_ego); |
404 | GNUNET_CRYPTO_ecdsa_public_key_from_string(test_ego, | ||
405 | strlen(test_ego), | ||
406 | &pk)) | ||
407 | { | ||
408 | fprintf(stderr, _("Public key `%s' malformed\n"), test_ego); | ||
409 | return; | ||
410 | } | ||
411 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); | ||
412 | q = GNUNET_REVOCATION_query(cfg, &pk, &print_query_result, NULL); | ||
413 | if (NULL != revoke_ego) | ||
414 | fprintf( | ||
415 | stderr, | ||
416 | "%s", | ||
417 | _( | ||
418 | "Testing and revoking at the same time is not allowed, only executing test.\n")); | ||
419 | return; | 410 | return; |
420 | } | 411 | } |
421 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg, | 412 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); |
422 | "REVOCATION", | 413 | q = GNUNET_REVOCATION_query (cfg, &pk, &print_query_result, NULL); |
423 | "WORKBITS", | 414 | if (NULL != revoke_ego) |
424 | &matching_bits)) | 415 | fprintf ( |
416 | stderr, | ||
417 | "%s", | ||
418 | _ ( | ||
419 | "Testing and revoking at the same time is not allowed, only executing test.\n")); | ||
420 | return; | ||
421 | } | ||
422 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, | ||
423 | "REVOCATION", | ||
424 | "WORKBITS", | ||
425 | &matching_bits)) | ||
426 | { | ||
427 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | ||
428 | "REVOCATION", | ||
429 | "WORKBITS"); | ||
430 | return; | ||
431 | } | ||
432 | if (NULL != revoke_ego) | ||
433 | { | ||
434 | if (! perform && (NULL == filename)) | ||
425 | { | 435 | { |
426 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, | 436 | fprintf (stderr, |
427 | "REVOCATION", | 437 | "%s", |
428 | "WORKBITS"); | 438 | _ ("No filename to store revocation certificate given.\n")); |
429 | return; | 439 | return; |
430 | } | 440 | } |
431 | if (NULL != revoke_ego) | 441 | /* main code here */ |
442 | el = GNUNET_IDENTITY_ego_lookup (cfg, revoke_ego, &ego_callback, NULL); | ||
443 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | ||
444 | return; | ||
445 | } | ||
446 | if ((NULL != filename) && (perform)) | ||
447 | { | ||
448 | if (sizeof(rd) != GNUNET_DISK_fn_read (filename, &rd, sizeof(rd))) | ||
432 | { | 449 | { |
433 | if (!perform && (NULL == filename)) | 450 | fprintf (stderr, |
434 | { | 451 | _ ("Failed to read revocation certificate from `%s'\n"), |
435 | fprintf(stderr, | 452 | filename); |
436 | "%s", | ||
437 | _("No filename to store revocation certificate given.\n")); | ||
438 | return; | ||
439 | } | ||
440 | /* main code here */ | ||
441 | el = GNUNET_IDENTITY_ego_lookup(cfg, revoke_ego, &ego_callback, NULL); | ||
442 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); | ||
443 | return; | 453 | return; |
444 | } | 454 | } |
445 | if ((NULL != filename) && (perform)) | 455 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); |
456 | if (GNUNET_YES != | ||
457 | GNUNET_REVOCATION_check_pow (&rd.key, | ||
458 | rd.pow, | ||
459 | (unsigned int) matching_bits)) | ||
446 | { | 460 | { |
447 | if (sizeof(rd) != GNUNET_DISK_fn_read(filename, &rd, sizeof(rd))) | 461 | struct RevocationData *cp = GNUNET_new (struct RevocationData); |
448 | { | 462 | |
449 | fprintf(stderr, | 463 | *cp = rd; |
450 | _("Failed to read revocation certificate from `%s'\n"), | 464 | pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, cp); |
451 | filename); | 465 | GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, cp); |
452 | return; | ||
453 | } | ||
454 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); | ||
455 | if (GNUNET_YES != | ||
456 | GNUNET_REVOCATION_check_pow(&rd.key, | ||
457 | rd.pow, | ||
458 | (unsigned int)matching_bits)) | ||
459 | { | ||
460 | struct RevocationData *cp = GNUNET_new(struct RevocationData); | ||
461 | |||
462 | *cp = rd; | ||
463 | pow_task = GNUNET_SCHEDULER_add_now(&calculate_pow, cp); | ||
464 | GNUNET_SCHEDULER_add_shutdown(&calculate_pow_shutdown, cp); | ||
465 | return; | ||
466 | } | ||
467 | perform_revocation(&rd); | ||
468 | return; | 466 | return; |
469 | } | 467 | } |
470 | fprintf(stderr, "%s", _("No action specified. Nothing to do.\n")); | 468 | perform_revocation (&rd); |
469 | return; | ||
470 | } | ||
471 | fprintf (stderr, "%s", _ ("No action specified. Nothing to do.\n")); | ||
471 | } | 472 | } |
472 | 473 | ||
473 | 474 | ||
@@ -479,54 +480,54 @@ run(void *cls, | |||
479 | * @return 0 ok, 1 on error | 480 | * @return 0 ok, 1 on error |
480 | */ | 481 | */ |
481 | int | 482 | int |
482 | main(int argc, char *const *argv) | 483 | main (int argc, char *const *argv) |
483 | { | 484 | { |
484 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 485 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
485 | GNUNET_GETOPT_option_string('f', | 486 | GNUNET_GETOPT_option_string ('f', |
486 | "filename", | 487 | "filename", |
487 | "NAME", | 488 | "NAME", |
488 | gettext_noop( | 489 | gettext_noop ( |
489 | "use NAME for the name of the revocation file"), | 490 | "use NAME for the name of the revocation file"), |
490 | &filename), | 491 | &filename), |
491 | 492 | ||
492 | GNUNET_GETOPT_option_string( | 493 | GNUNET_GETOPT_option_string ( |
493 | 'R', | 494 | 'R', |
494 | "revoke", | 495 | "revoke", |
495 | "NAME", | 496 | "NAME", |
496 | gettext_noop( | 497 | gettext_noop ( |
497 | "revoke the private key associated for the the private key associated with the ego NAME "), | 498 | "revoke the private key associated for the the private key associated with the ego NAME "), |
498 | &revoke_ego), | 499 | &revoke_ego), |
499 | 500 | ||
500 | GNUNET_GETOPT_option_flag( | 501 | GNUNET_GETOPT_option_flag ( |
501 | 'p', | 502 | 'p', |
502 | "perform", | 503 | "perform", |
503 | gettext_noop( | 504 | gettext_noop ( |
504 | "actually perform revocation, otherwise we just do the precomputation"), | 505 | "actually perform revocation, otherwise we just do the precomputation"), |
505 | &perform), | 506 | &perform), |
506 | 507 | ||
507 | GNUNET_GETOPT_option_string('t', | 508 | GNUNET_GETOPT_option_string ('t', |
508 | "test", | 509 | "test", |
509 | "KEY", | 510 | "KEY", |
510 | gettext_noop( | 511 | gettext_noop ( |
511 | "test if the public key KEY has been revoked"), | 512 | "test if the public key KEY has been revoked"), |
512 | &test_ego), | 513 | &test_ego), |
513 | 514 | ||
514 | GNUNET_GETOPT_OPTION_END | 515 | GNUNET_GETOPT_OPTION_END |
515 | }; | 516 | }; |
516 | 517 | ||
517 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) | 518 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
518 | return 2; | 519 | return 2; |
519 | 520 | ||
520 | ret = (GNUNET_OK == GNUNET_PROGRAM_run(argc, | 521 | ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc, |
521 | argv, | 522 | argv, |
522 | "gnunet-revocation", | 523 | "gnunet-revocation", |
523 | gettext_noop("help text"), | 524 | gettext_noop ("help text"), |
524 | options, | 525 | options, |
525 | &run, | 526 | &run, |
526 | NULL)) | 527 | NULL)) |
527 | ? ret | 528 | ? ret |
528 | : 1; | 529 | : 1; |
529 | GNUNET_free((void *)argv); | 530 | GNUNET_free ((void *) argv); |
530 | return ret; | 531 | return ret; |
531 | } | 532 | } |
532 | 533 | ||
diff --git a/src/revocation/gnunet-service-revocation.c b/src/revocation/gnunet-service-revocation.c index 62be5a96b..8be2d3926 100644 --- a/src/revocation/gnunet-service-revocation.c +++ b/src/revocation/gnunet-service-revocation.c | |||
@@ -53,7 +53,8 @@ | |||
53 | /** | 53 | /** |
54 | * Per-peer information. | 54 | * Per-peer information. |
55 | */ | 55 | */ |
56 | struct PeerEntry { | 56 | struct PeerEntry |
57 | { | ||
57 | /** | 58 | /** |
58 | * Queue for sending messages to this peer. | 59 | * Queue for sending messages to this peer. |
59 | */ | 60 | */ |
@@ -141,17 +142,17 @@ static struct GNUNET_HashCode revocation_set_union_app_id; | |||
141 | * @return a pointer to the new PeerEntry | 142 | * @return a pointer to the new PeerEntry |
142 | */ | 143 | */ |
143 | static struct PeerEntry * | 144 | static struct PeerEntry * |
144 | new_peer_entry(const struct GNUNET_PeerIdentity *peer) | 145 | new_peer_entry (const struct GNUNET_PeerIdentity *peer) |
145 | { | 146 | { |
146 | struct PeerEntry *peer_entry; | 147 | struct PeerEntry *peer_entry; |
147 | 148 | ||
148 | peer_entry = GNUNET_new(struct PeerEntry); | 149 | peer_entry = GNUNET_new (struct PeerEntry); |
149 | peer_entry->id = *peer; | 150 | peer_entry->id = *peer; |
150 | GNUNET_assert(GNUNET_OK == | 151 | GNUNET_assert (GNUNET_OK == |
151 | GNUNET_CONTAINER_multipeermap_put(peers, | 152 | GNUNET_CONTAINER_multipeermap_put (peers, |
152 | &peer_entry->id, | 153 | &peer_entry->id, |
153 | peer_entry, | 154 | peer_entry, |
154 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 155 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
155 | return peer_entry; | 156 | return peer_entry; |
156 | } | 157 | } |
157 | 158 | ||
@@ -164,27 +165,27 @@ new_peer_entry(const struct GNUNET_PeerIdentity *peer) | |||
164 | * #GNUNET_NO if the key/signature don't verify | 165 | * #GNUNET_NO if the key/signature don't verify |
165 | */ | 166 | */ |
166 | static int | 167 | static int |
167 | verify_revoke_message(const struct RevokeMessage *rm) | 168 | verify_revoke_message (const struct RevokeMessage *rm) |
168 | { | 169 | { |
169 | if (GNUNET_YES != | 170 | if (GNUNET_YES != |
170 | GNUNET_REVOCATION_check_pow(&rm->public_key, | 171 | GNUNET_REVOCATION_check_pow (&rm->public_key, |
171 | rm->proof_of_work, | 172 | rm->proof_of_work, |
172 | (unsigned int)revocation_work_required)) | 173 | (unsigned int) revocation_work_required)) |
173 | { | 174 | { |
174 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 175 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
175 | "Proof of work invalid!\n"); | 176 | "Proof of work invalid!\n"); |
176 | GNUNET_break_op(0); | 177 | GNUNET_break_op (0); |
177 | return GNUNET_NO; | 178 | return GNUNET_NO; |
178 | } | 179 | } |
179 | if (GNUNET_OK != | 180 | if (GNUNET_OK != |
180 | GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_REVOCATION, | 181 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_REVOCATION, |
181 | &rm->purpose, | 182 | &rm->purpose, |
182 | &rm->signature, | 183 | &rm->signature, |
183 | &rm->public_key)) | 184 | &rm->public_key)) |
184 | { | 185 | { |
185 | GNUNET_break_op(0); | 186 | GNUNET_break_op (0); |
186 | return GNUNET_NO; | 187 | return GNUNET_NO; |
187 | } | 188 | } |
188 | return GNUNET_YES; | 189 | return GNUNET_YES; |
189 | } | 190 | } |
190 | 191 | ||
@@ -198,9 +199,9 @@ verify_revoke_message(const struct RevokeMessage *rm) | |||
198 | * @return @a client | 199 | * @return @a client |
199 | */ | 200 | */ |
200 | static void * | 201 | static void * |
201 | client_connect_cb(void *cls, | 202 | client_connect_cb (void *cls, |
202 | struct GNUNET_SERVICE_Client *client, | 203 | struct GNUNET_SERVICE_Client *client, |
203 | struct GNUNET_MQ_Handle *mq) | 204 | struct GNUNET_MQ_Handle *mq) |
204 | { | 205 | { |
205 | return client; | 206 | return client; |
206 | } | 207 | } |
@@ -214,11 +215,11 @@ client_connect_cb(void *cls, | |||
214 | * @param app_cls must alias @a client | 215 | * @param app_cls must alias @a client |
215 | */ | 216 | */ |
216 | static void | 217 | static void |
217 | client_disconnect_cb(void *cls, | 218 | client_disconnect_cb (void *cls, |
218 | struct GNUNET_SERVICE_Client *client, | 219 | struct GNUNET_SERVICE_Client *client, |
219 | void *app_cls) | 220 | void *app_cls) |
220 | { | 221 | { |
221 | GNUNET_assert(client == app_cls); | 222 | GNUNET_assert (client == app_cls); |
222 | } | 223 | } |
223 | 224 | ||
224 | 225 | ||
@@ -229,8 +230,8 @@ client_disconnect_cb(void *cls, | |||
229 | * @param qm the message received | 230 | * @param qm the message received |
230 | */ | 231 | */ |
231 | static void | 232 | static void |
232 | handle_query_message(void *cls, | 233 | handle_query_message (void *cls, |
233 | const struct QueryMessage *qm) | 234 | const struct QueryMessage *qm) |
234 | { | 235 | { |
235 | struct GNUNET_SERVICE_Client *client = cls; | 236 | struct GNUNET_SERVICE_Client *client = cls; |
236 | struct GNUNET_MQ_Envelope *env; | 237 | struct GNUNET_MQ_Envelope *env; |
@@ -238,22 +239,22 @@ handle_query_message(void *cls, | |||
238 | struct GNUNET_HashCode hc; | 239 | struct GNUNET_HashCode hc; |
239 | int res; | 240 | int res; |
240 | 241 | ||
241 | GNUNET_CRYPTO_hash(&qm->key, | 242 | GNUNET_CRYPTO_hash (&qm->key, |
242 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), | 243 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), |
243 | &hc); | 244 | &hc); |
244 | res = GNUNET_CONTAINER_multihashmap_contains(revocation_map, | 245 | res = GNUNET_CONTAINER_multihashmap_contains (revocation_map, |
245 | &hc); | 246 | &hc); |
246 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 247 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
247 | (GNUNET_NO == res) | 248 | (GNUNET_NO == res) |
248 | ? "Received revocation check for valid key `%s' from client\n" | 249 | ? "Received revocation check for valid key `%s' from client\n" |
249 | : "Received revocation check for revoked key `%s' from client\n", | 250 | : "Received revocation check for revoked key `%s' from client\n", |
250 | GNUNET_h2s(&hc)); | 251 | GNUNET_h2s (&hc)); |
251 | env = GNUNET_MQ_msg(qrm, | 252 | env = GNUNET_MQ_msg (qrm, |
252 | GNUNET_MESSAGE_TYPE_REVOCATION_QUERY_RESPONSE); | 253 | GNUNET_MESSAGE_TYPE_REVOCATION_QUERY_RESPONSE); |
253 | qrm->is_valid = htonl((GNUNET_YES == res) ? GNUNET_NO : GNUNET_YES); | 254 | qrm->is_valid = htonl ((GNUNET_YES == res) ? GNUNET_NO : GNUNET_YES); |
254 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), | 255 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), |
255 | env); | 256 | env); |
256 | GNUNET_SERVICE_client_continue(client); | 257 | GNUNET_SERVICE_client_continue (client); |
257 | } | 258 | } |
258 | 259 | ||
259 | 260 | ||
@@ -266,9 +267,9 @@ handle_query_message(void *cls, | |||
266 | * @return #GNUNET_OK (continue to iterate) | 267 | * @return #GNUNET_OK (continue to iterate) |
267 | */ | 268 | */ |
268 | static int | 269 | static int |
269 | do_flood(void *cls, | 270 | do_flood (void *cls, |
270 | const struct GNUNET_PeerIdentity *target, | 271 | const struct GNUNET_PeerIdentity *target, |
271 | void *value) | 272 | void *value) |
272 | { | 273 | { |
273 | const struct RevokeMessage *rm = cls; | 274 | const struct RevokeMessage *rm = cls; |
274 | struct PeerEntry *pe = value; | 275 | struct PeerEntry *pe = value; |
@@ -279,14 +280,14 @@ do_flood(void *cls, | |||
279 | return GNUNET_OK; /* peer connected to us via SET, | 280 | return GNUNET_OK; /* peer connected to us via SET, |
280 | but we have no direct CORE | 281 | but we have no direct CORE |
281 | connection for flooding */ | 282 | connection for flooding */ |
282 | e = GNUNET_MQ_msg(cp, | 283 | e = GNUNET_MQ_msg (cp, |
283 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE); | 284 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE); |
284 | *cp = *rm; | 285 | *cp = *rm; |
285 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 286 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
286 | "Flooding revocation to `%s'\n", | 287 | "Flooding revocation to `%s'\n", |
287 | GNUNET_i2s(target)); | 288 | GNUNET_i2s (target)); |
288 | GNUNET_MQ_send(pe->mq, | 289 | GNUNET_MQ_send (pe->mq, |
289 | e); | 290 | e); |
290 | return GNUNET_OK; | 291 | return GNUNET_OK; |
291 | } | 292 | } |
292 | 293 | ||
@@ -301,75 +302,75 @@ do_flood(void *cls, | |||
301 | * #GNUNET_SYSERR if the message was malformed | 302 | * #GNUNET_SYSERR if the message was malformed |
302 | */ | 303 | */ |
303 | static int | 304 | static int |
304 | publicize_rm(const struct RevokeMessage *rm) | 305 | publicize_rm (const struct RevokeMessage *rm) |
305 | { | 306 | { |
306 | struct RevokeMessage *cp; | 307 | struct RevokeMessage *cp; |
307 | struct GNUNET_HashCode hc; | 308 | struct GNUNET_HashCode hc; |
308 | struct GNUNET_SET_Element e; | 309 | struct GNUNET_SET_Element e; |
309 | 310 | ||
310 | GNUNET_CRYPTO_hash(&rm->public_key, | 311 | GNUNET_CRYPTO_hash (&rm->public_key, |
311 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), | 312 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), |
312 | &hc); | 313 | &hc); |
313 | if (GNUNET_YES == | 314 | if (GNUNET_YES == |
314 | GNUNET_CONTAINER_multihashmap_contains(revocation_map, | 315 | GNUNET_CONTAINER_multihashmap_contains (revocation_map, |
315 | &hc)) | 316 | &hc)) |
316 | { | 317 | { |
317 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 318 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
318 | "Duplicate revocation received from peer. Ignored.\n"); | 319 | "Duplicate revocation received from peer. Ignored.\n"); |
319 | return GNUNET_OK; | 320 | return GNUNET_OK; |
320 | } | 321 | } |
321 | if (GNUNET_OK != | 322 | if (GNUNET_OK != |
322 | verify_revoke_message(rm)) | 323 | verify_revoke_message (rm)) |
323 | { | 324 | { |
324 | GNUNET_break_op(0); | 325 | GNUNET_break_op (0); |
325 | return GNUNET_SYSERR; | 326 | return GNUNET_SYSERR; |
326 | } | 327 | } |
327 | /* write to disk */ | 328 | /* write to disk */ |
328 | if (sizeof(struct RevokeMessage) != | 329 | if (sizeof(struct RevokeMessage) != |
329 | GNUNET_DISK_file_write(revocation_db, | 330 | GNUNET_DISK_file_write (revocation_db, |
330 | rm, | 331 | rm, |
331 | sizeof(struct RevokeMessage))) | 332 | sizeof(struct RevokeMessage))) |
332 | { | 333 | { |
333 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, | 334 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, |
334 | "write"); | 335 | "write"); |
335 | return GNUNET_NO; | 336 | return GNUNET_NO; |
336 | } | 337 | } |
337 | if (GNUNET_OK != | 338 | if (GNUNET_OK != |
338 | GNUNET_DISK_file_sync(revocation_db)) | 339 | GNUNET_DISK_file_sync (revocation_db)) |
339 | { | 340 | { |
340 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, | 341 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, |
341 | "sync"); | 342 | "sync"); |
342 | return GNUNET_NO; | 343 | return GNUNET_NO; |
343 | } | 344 | } |
344 | /* keep copy in memory */ | 345 | /* keep copy in memory */ |
345 | cp = (struct RevokeMessage *)GNUNET_copy_message(&rm->header); | 346 | cp = (struct RevokeMessage *) GNUNET_copy_message (&rm->header); |
346 | GNUNET_break(GNUNET_OK == | 347 | GNUNET_break (GNUNET_OK == |
347 | GNUNET_CONTAINER_multihashmap_put(revocation_map, | 348 | GNUNET_CONTAINER_multihashmap_put (revocation_map, |
348 | &hc, | 349 | &hc, |
349 | cp, | 350 | cp, |
350 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 351 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
351 | /* add to set for future connections */ | 352 | /* add to set for future connections */ |
352 | e.size = htons(rm->header.size); | 353 | e.size = htons (rm->header.size); |
353 | e.element_type = GNUNET_BLOCK_TYPE_REVOCATION; | 354 | e.element_type = GNUNET_BLOCK_TYPE_REVOCATION; |
354 | e.data = rm; | 355 | e.data = rm; |
355 | if (GNUNET_OK != | 356 | if (GNUNET_OK != |
356 | GNUNET_SET_add_element(revocation_set, | 357 | GNUNET_SET_add_element (revocation_set, |
357 | &e, | 358 | &e, |
358 | NULL, | 359 | NULL, |
359 | NULL)) | 360 | NULL)) |
360 | { | 361 | { |
361 | GNUNET_break(0); | 362 | GNUNET_break (0); |
362 | return GNUNET_OK; | 363 | return GNUNET_OK; |
363 | } | 364 | } |
364 | else | 365 | else |
365 | { | 366 | { |
366 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 367 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
367 | "Added revocation info to SET\n"); | 368 | "Added revocation info to SET\n"); |
368 | } | 369 | } |
369 | /* flood to neighbours */ | 370 | /* flood to neighbours */ |
370 | GNUNET_CONTAINER_multipeermap_iterate(peers, | 371 | GNUNET_CONTAINER_multipeermap_iterate (peers, |
371 | &do_flood, | 372 | &do_flood, |
372 | cp); | 373 | cp); |
373 | return GNUNET_OK; | 374 | return GNUNET_OK; |
374 | } | 375 | } |
375 | 376 | ||
@@ -381,28 +382,28 @@ publicize_rm(const struct RevokeMessage *rm) | |||
381 | * @param rm the message received | 382 | * @param rm the message received |
382 | */ | 383 | */ |
383 | static void | 384 | static void |
384 | handle_revoke_message(void *cls, | 385 | handle_revoke_message (void *cls, |
385 | const struct RevokeMessage *rm) | 386 | const struct RevokeMessage *rm) |
386 | { | 387 | { |
387 | struct GNUNET_SERVICE_Client *client = cls; | 388 | struct GNUNET_SERVICE_Client *client = cls; |
388 | struct GNUNET_MQ_Envelope *env; | 389 | struct GNUNET_MQ_Envelope *env; |
389 | struct RevocationResponseMessage *rrm; | 390 | struct RevocationResponseMessage *rrm; |
390 | int ret; | 391 | int ret; |
391 | 392 | ||
392 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 393 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
393 | "Received REVOKE message from client\n"); | 394 | "Received REVOKE message from client\n"); |
394 | if (GNUNET_SYSERR == (ret = publicize_rm(rm))) | 395 | if (GNUNET_SYSERR == (ret = publicize_rm (rm))) |
395 | { | 396 | { |
396 | GNUNET_break_op(0); | 397 | GNUNET_break_op (0); |
397 | GNUNET_SERVICE_client_drop(client); | 398 | GNUNET_SERVICE_client_drop (client); |
398 | return; | 399 | return; |
399 | } | 400 | } |
400 | env = GNUNET_MQ_msg(rrm, | 401 | env = GNUNET_MQ_msg (rrm, |
401 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE); | 402 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE); |
402 | rrm->is_valid = htonl((GNUNET_OK == ret) ? GNUNET_NO : GNUNET_YES); | 403 | rrm->is_valid = htonl ((GNUNET_OK == ret) ? GNUNET_NO : GNUNET_YES); |
403 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), | 404 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), |
404 | env); | 405 | env); |
405 | GNUNET_SERVICE_client_continue(client); | 406 | GNUNET_SERVICE_client_continue (client); |
406 | } | 407 | } |
407 | 408 | ||
408 | 409 | ||
@@ -413,13 +414,13 @@ handle_revoke_message(void *cls, | |||
413 | * @param rm revocation message | 414 | * @param rm revocation message |
414 | */ | 415 | */ |
415 | static void | 416 | static void |
416 | handle_p2p_revoke(void *cls, | 417 | handle_p2p_revoke (void *cls, |
417 | const struct RevokeMessage *rm) | 418 | const struct RevokeMessage *rm) |
418 | { | 419 | { |
419 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 420 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
420 | "Received REVOKE message\n"); | 421 | "Received REVOKE message\n"); |
421 | GNUNET_break_op(GNUNET_SYSERR != | 422 | GNUNET_break_op (GNUNET_SYSERR != |
422 | publicize_rm(rm)); | 423 | publicize_rm (rm)); |
423 | } | 424 | } |
424 | 425 | ||
425 | 426 | ||
@@ -434,64 +435,67 @@ handle_p2p_revoke(void *cls, | |||
434 | * @param status see `enum GNUNET_SET_Status` | 435 | * @param status see `enum GNUNET_SET_Status` |
435 | */ | 436 | */ |
436 | static void | 437 | static void |
437 | add_revocation(void *cls, | 438 | add_revocation (void *cls, |
438 | const struct GNUNET_SET_Element *element, | 439 | const struct GNUNET_SET_Element *element, |
439 | uint64_t current_size, | 440 | uint64_t current_size, |
440 | enum GNUNET_SET_Status status) | 441 | enum GNUNET_SET_Status status) |
441 | { | 442 | { |
442 | struct PeerEntry *peer_entry = cls; | 443 | struct PeerEntry *peer_entry = cls; |
443 | const struct RevokeMessage *rm; | 444 | const struct RevokeMessage *rm; |
444 | 445 | ||
445 | switch (status) | 446 | switch (status) |
447 | { | ||
448 | case GNUNET_SET_STATUS_OK: | ||
449 | if (element->size != sizeof(struct RevokeMessage)) | ||
446 | { | 450 | { |
447 | case GNUNET_SET_STATUS_OK: | 451 | GNUNET_break_op (0); |
448 | if (element->size != sizeof(struct RevokeMessage)) | 452 | return; |
449 | { | 453 | } |
450 | GNUNET_break_op(0); | 454 | if (GNUNET_BLOCK_TYPE_REVOCATION != element->element_type) |
451 | return; | 455 | { |
452 | } | 456 | GNUNET_STATISTICS_update (stats, |
453 | if (GNUNET_BLOCK_TYPE_REVOCATION != element->element_type) | 457 | gettext_noop ( |
454 | { | 458 | "# unsupported revocations received via set union"), |
455 | GNUNET_STATISTICS_update(stats, | 459 | 1, |
456 | gettext_noop("# unsupported revocations received via set union"), | 460 | GNUNET_NO); |
457 | 1, | 461 | return; |
458 | GNUNET_NO); | ||
459 | return; | ||
460 | } | ||
461 | rm = element->data; | ||
462 | (void)handle_p2p_revoke(NULL, | ||
463 | rm); | ||
464 | GNUNET_STATISTICS_update(stats, | ||
465 | gettext_noop("# revocation messages received via set union"), | ||
466 | 1, GNUNET_NO); | ||
467 | break; | ||
468 | |||
469 | case GNUNET_SET_STATUS_FAILURE: | ||
470 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
471 | _("Error computing revocation set union with %s\n"), | ||
472 | GNUNET_i2s(&peer_entry->id)); | ||
473 | peer_entry->so = NULL; | ||
474 | GNUNET_STATISTICS_update(stats, | ||
475 | gettext_noop("# revocation set unions failed"), | ||
476 | 1, | ||
477 | GNUNET_NO); | ||
478 | break; | ||
479 | |||
480 | case GNUNET_SET_STATUS_HALF_DONE: | ||
481 | break; | ||
482 | |||
483 | case GNUNET_SET_STATUS_DONE: | ||
484 | peer_entry->so = NULL; | ||
485 | GNUNET_STATISTICS_update(stats, | ||
486 | gettext_noop("# revocation set unions completed"), | ||
487 | 1, | ||
488 | GNUNET_NO); | ||
489 | break; | ||
490 | |||
491 | default: | ||
492 | GNUNET_break(0); | ||
493 | break; | ||
494 | } | 462 | } |
463 | rm = element->data; | ||
464 | (void) handle_p2p_revoke (NULL, | ||
465 | rm); | ||
466 | GNUNET_STATISTICS_update (stats, | ||
467 | gettext_noop ( | ||
468 | "# revocation messages received via set union"), | ||
469 | 1, GNUNET_NO); | ||
470 | break; | ||
471 | |||
472 | case GNUNET_SET_STATUS_FAILURE: | ||
473 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
474 | _ ("Error computing revocation set union with %s\n"), | ||
475 | GNUNET_i2s (&peer_entry->id)); | ||
476 | peer_entry->so = NULL; | ||
477 | GNUNET_STATISTICS_update (stats, | ||
478 | gettext_noop ("# revocation set unions failed"), | ||
479 | 1, | ||
480 | GNUNET_NO); | ||
481 | break; | ||
482 | |||
483 | case GNUNET_SET_STATUS_HALF_DONE: | ||
484 | break; | ||
485 | |||
486 | case GNUNET_SET_STATUS_DONE: | ||
487 | peer_entry->so = NULL; | ||
488 | GNUNET_STATISTICS_update (stats, | ||
489 | gettext_noop ( | ||
490 | "# revocation set unions completed"), | ||
491 | 1, | ||
492 | GNUNET_NO); | ||
493 | break; | ||
494 | |||
495 | default: | ||
496 | GNUNET_break (0); | ||
497 | break; | ||
498 | } | ||
495 | } | 499 | } |
496 | 500 | ||
497 | 501 | ||
@@ -502,31 +506,31 @@ add_revocation(void *cls, | |||
502 | * @param cls NULL | 506 | * @param cls NULL |
503 | */ | 507 | */ |
504 | static void | 508 | static void |
505 | transmit_task_cb(void *cls) | 509 | transmit_task_cb (void *cls) |
506 | { | 510 | { |
507 | struct PeerEntry *peer_entry = cls; | 511 | struct PeerEntry *peer_entry = cls; |
508 | 512 | ||
509 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 513 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
510 | "Starting set exchange with peer `%s'\n", | 514 | "Starting set exchange with peer `%s'\n", |
511 | GNUNET_i2s(&peer_entry->id)); | 515 | GNUNET_i2s (&peer_entry->id)); |
512 | peer_entry->transmit_task = NULL; | 516 | peer_entry->transmit_task = NULL; |
513 | GNUNET_assert(NULL == peer_entry->so); | 517 | GNUNET_assert (NULL == peer_entry->so); |
514 | peer_entry->so = GNUNET_SET_prepare(&peer_entry->id, | 518 | peer_entry->so = GNUNET_SET_prepare (&peer_entry->id, |
515 | &revocation_set_union_app_id, | 519 | &revocation_set_union_app_id, |
516 | NULL, | 520 | NULL, |
517 | GNUNET_SET_RESULT_ADDED, | 521 | GNUNET_SET_RESULT_ADDED, |
518 | (struct GNUNET_SET_Option[]) { { 0 } }, | 522 | (struct GNUNET_SET_Option[]) { { 0 } }, |
519 | &add_revocation, | 523 | &add_revocation, |
520 | peer_entry); | 524 | peer_entry); |
521 | if (GNUNET_OK != | 525 | if (GNUNET_OK != |
522 | GNUNET_SET_commit(peer_entry->so, | 526 | GNUNET_SET_commit (peer_entry->so, |
523 | revocation_set)) | 527 | revocation_set)) |
524 | { | 528 | { |
525 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 529 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
526 | _("SET service crashed, terminating revocation service\n")); | 530 | _ ("SET service crashed, terminating revocation service\n")); |
527 | GNUNET_SCHEDULER_shutdown(); | 531 | GNUNET_SCHEDULER_shutdown (); |
528 | return; | 532 | return; |
529 | } | 533 | } |
530 | } | 534 | } |
531 | 535 | ||
532 | 536 | ||
@@ -538,57 +542,57 @@ transmit_task_cb(void *cls) | |||
538 | * @param peer peer identity this notification is about | 542 | * @param peer peer identity this notification is about |
539 | */ | 543 | */ |
540 | static void * | 544 | static void * |
541 | handle_core_connect(void *cls, | 545 | handle_core_connect (void *cls, |
542 | const struct GNUNET_PeerIdentity *peer, | 546 | const struct GNUNET_PeerIdentity *peer, |
543 | struct GNUNET_MQ_Handle *mq) | 547 | struct GNUNET_MQ_Handle *mq) |
544 | { | 548 | { |
545 | struct PeerEntry *peer_entry; | 549 | struct PeerEntry *peer_entry; |
546 | struct GNUNET_HashCode my_hash; | 550 | struct GNUNET_HashCode my_hash; |
547 | struct GNUNET_HashCode peer_hash; | 551 | struct GNUNET_HashCode peer_hash; |
548 | 552 | ||
549 | if (0 == GNUNET_memcmp(peer, | 553 | if (0 == GNUNET_memcmp (peer, |
550 | &my_identity)) | 554 | &my_identity)) |
551 | { | 555 | { |
552 | return NULL; | 556 | return NULL; |
553 | } | 557 | } |
554 | 558 | ||
555 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 559 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
556 | "Peer `%s' connected to us\n", | 560 | "Peer `%s' connected to us\n", |
557 | GNUNET_i2s(peer)); | 561 | GNUNET_i2s (peer)); |
558 | GNUNET_STATISTICS_update(stats, | 562 | GNUNET_STATISTICS_update (stats, |
559 | "# peers connected", | 563 | "# peers connected", |
560 | 1, | 564 | 1, |
561 | GNUNET_NO); | 565 | GNUNET_NO); |
562 | peer_entry = GNUNET_CONTAINER_multipeermap_get(peers, | 566 | peer_entry = GNUNET_CONTAINER_multipeermap_get (peers, |
563 | peer); | 567 | peer); |
564 | if (NULL != peer_entry) | 568 | if (NULL != peer_entry) |
565 | { | 569 | { |
566 | /* This can happen if "core"'s notification is a tad late | 570 | /* This can happen if "core"'s notification is a tad late |
567 | and CADET+SET were faster and already produced a | 571 | and CADET+SET were faster and already produced a |
568 | #handle_revocation_union_request() for us to deal | 572 | #handle_revocation_union_request() for us to deal |
569 | with. This should be rare, but isn't impossible. */ | 573 | with. This should be rare, but isn't impossible. */ |
570 | peer_entry->mq = mq; | 574 | peer_entry->mq = mq; |
571 | return peer_entry; | 575 | return peer_entry; |
572 | } | 576 | } |
573 | peer_entry = new_peer_entry(peer); | 577 | peer_entry = new_peer_entry (peer); |
574 | peer_entry->mq = mq; | 578 | peer_entry->mq = mq; |
575 | GNUNET_CRYPTO_hash(&my_identity, | 579 | GNUNET_CRYPTO_hash (&my_identity, |
576 | sizeof(my_identity), | 580 | sizeof(my_identity), |
577 | &my_hash); | 581 | &my_hash); |
578 | GNUNET_CRYPTO_hash(peer, | 582 | GNUNET_CRYPTO_hash (peer, |
579 | sizeof(*peer), | 583 | sizeof(*peer), |
580 | &peer_hash); | 584 | &peer_hash); |
581 | if (0 < GNUNET_CRYPTO_hash_cmp(&my_hash, | 585 | if (0 < GNUNET_CRYPTO_hash_cmp (&my_hash, |
582 | &peer_hash)) | 586 | &peer_hash)) |
583 | { | 587 | { |
584 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 588 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
585 | "Starting SET operation with peer `%s'\n", | 589 | "Starting SET operation with peer `%s'\n", |
586 | GNUNET_i2s(peer)); | 590 | GNUNET_i2s (peer)); |
587 | peer_entry->transmit_task = | 591 | peer_entry->transmit_task = |
588 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, | 592 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
589 | &transmit_task_cb, | 593 | &transmit_task_cb, |
590 | peer_entry); | 594 | peer_entry); |
591 | } | 595 | } |
592 | return peer_entry; | 596 | return peer_entry; |
593 | } | 597 | } |
594 | 598 | ||
@@ -602,38 +606,38 @@ handle_core_connect(void *cls, | |||
602 | * @param internal_cls our `struct PeerEntry` for this peer | 606 | * @param internal_cls our `struct PeerEntry` for this peer |
603 | */ | 607 | */ |
604 | static void | 608 | static void |
605 | handle_core_disconnect(void *cls, | 609 | handle_core_disconnect (void *cls, |
606 | const struct GNUNET_PeerIdentity *peer, | 610 | const struct GNUNET_PeerIdentity *peer, |
607 | void *internal_cls) | 611 | void *internal_cls) |
608 | { | 612 | { |
609 | struct PeerEntry *peer_entry = internal_cls; | 613 | struct PeerEntry *peer_entry = internal_cls; |
610 | 614 | ||
611 | if (0 == GNUNET_memcmp(peer, | 615 | if (0 == GNUNET_memcmp (peer, |
612 | &my_identity)) | 616 | &my_identity)) |
613 | return; | 617 | return; |
614 | GNUNET_assert(NULL != peer_entry); | 618 | GNUNET_assert (NULL != peer_entry); |
615 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 619 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
616 | "Peer `%s' disconnected from us\n", | 620 | "Peer `%s' disconnected from us\n", |
617 | GNUNET_i2s(peer)); | 621 | GNUNET_i2s (peer)); |
618 | GNUNET_assert(GNUNET_YES == | 622 | GNUNET_assert (GNUNET_YES == |
619 | GNUNET_CONTAINER_multipeermap_remove(peers, | 623 | GNUNET_CONTAINER_multipeermap_remove (peers, |
620 | peer, | 624 | peer, |
621 | peer_entry)); | 625 | peer_entry)); |
622 | if (NULL != peer_entry->transmit_task) | 626 | if (NULL != peer_entry->transmit_task) |
623 | { | 627 | { |
624 | GNUNET_SCHEDULER_cancel(peer_entry->transmit_task); | 628 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); |
625 | peer_entry->transmit_task = NULL; | 629 | peer_entry->transmit_task = NULL; |
626 | } | 630 | } |
627 | if (NULL != peer_entry->so) | 631 | if (NULL != peer_entry->so) |
628 | { | 632 | { |
629 | GNUNET_SET_operation_cancel(peer_entry->so); | 633 | GNUNET_SET_operation_cancel (peer_entry->so); |
630 | peer_entry->so = NULL; | 634 | peer_entry->so = NULL; |
631 | } | 635 | } |
632 | GNUNET_free(peer_entry); | 636 | GNUNET_free (peer_entry); |
633 | GNUNET_STATISTICS_update(stats, | 637 | GNUNET_STATISTICS_update (stats, |
634 | "# peers connected", | 638 | "# peers connected", |
635 | -1, | 639 | -1, |
636 | GNUNET_NO); | 640 | GNUNET_NO); |
637 | } | 641 | } |
638 | 642 | ||
639 | 643 | ||
@@ -646,11 +650,11 @@ handle_core_disconnect(void *cls, | |||
646 | * @return #GNUNET_OK (continue to iterate) | 650 | * @return #GNUNET_OK (continue to iterate) |
647 | */ | 651 | */ |
648 | static int | 652 | static int |
649 | free_entry(void *cls, | 653 | free_entry (void *cls, |
650 | const struct GNUNET_HashCode *key, | 654 | const struct GNUNET_HashCode *key, |
651 | void *value) | 655 | void *value) |
652 | { | 656 | { |
653 | GNUNET_free(value); | 657 | GNUNET_free (value); |
654 | return GNUNET_OK; | 658 | return GNUNET_OK; |
655 | } | 659 | } |
656 | 660 | ||
@@ -661,42 +665,42 @@ free_entry(void *cls, | |||
661 | * @param cls unused | 665 | * @param cls unused |
662 | */ | 666 | */ |
663 | static void | 667 | static void |
664 | shutdown_task(void *cls) | 668 | shutdown_task (void *cls) |
665 | { | 669 | { |
666 | if (NULL != revocation_set) | 670 | if (NULL != revocation_set) |
667 | { | 671 | { |
668 | GNUNET_SET_destroy(revocation_set); | 672 | GNUNET_SET_destroy (revocation_set); |
669 | revocation_set = NULL; | 673 | revocation_set = NULL; |
670 | } | 674 | } |
671 | if (NULL != revocation_union_listen_handle) | 675 | if (NULL != revocation_union_listen_handle) |
672 | { | 676 | { |
673 | GNUNET_SET_listen_cancel(revocation_union_listen_handle); | 677 | GNUNET_SET_listen_cancel (revocation_union_listen_handle); |
674 | revocation_union_listen_handle = NULL; | 678 | revocation_union_listen_handle = NULL; |
675 | } | 679 | } |
676 | if (NULL != core_api) | 680 | if (NULL != core_api) |
677 | { | 681 | { |
678 | GNUNET_CORE_disconnect(core_api); | 682 | GNUNET_CORE_disconnect (core_api); |
679 | core_api = NULL; | 683 | core_api = NULL; |
680 | } | 684 | } |
681 | if (NULL != stats) | 685 | if (NULL != stats) |
682 | { | 686 | { |
683 | GNUNET_STATISTICS_destroy(stats, GNUNET_NO); | 687 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); |
684 | stats = NULL; | 688 | stats = NULL; |
685 | } | 689 | } |
686 | if (NULL != peers) | 690 | if (NULL != peers) |
687 | { | 691 | { |
688 | GNUNET_CONTAINER_multipeermap_destroy(peers); | 692 | GNUNET_CONTAINER_multipeermap_destroy (peers); |
689 | peers = NULL; | 693 | peers = NULL; |
690 | } | 694 | } |
691 | if (NULL != revocation_db) | 695 | if (NULL != revocation_db) |
692 | { | 696 | { |
693 | GNUNET_DISK_file_close(revocation_db); | 697 | GNUNET_DISK_file_close (revocation_db); |
694 | revocation_db = NULL; | 698 | revocation_db = NULL; |
695 | } | 699 | } |
696 | GNUNET_CONTAINER_multihashmap_iterate(revocation_map, | 700 | GNUNET_CONTAINER_multihashmap_iterate (revocation_map, |
697 | &free_entry, | 701 | &free_entry, |
698 | NULL); | 702 | NULL); |
699 | GNUNET_CONTAINER_multihashmap_destroy(revocation_map); | 703 | GNUNET_CONTAINER_multihashmap_destroy (revocation_map); |
700 | } | 704 | } |
701 | 705 | ||
702 | 706 | ||
@@ -707,16 +711,16 @@ shutdown_task(void *cls) | |||
707 | * @param identity the public identity of this peer | 711 | * @param identity the public identity of this peer |
708 | */ | 712 | */ |
709 | static void | 713 | static void |
710 | core_init(void *cls, | 714 | core_init (void *cls, |
711 | const struct GNUNET_PeerIdentity *identity) | 715 | const struct GNUNET_PeerIdentity *identity) |
712 | { | 716 | { |
713 | if (NULL == identity) | 717 | if (NULL == identity) |
714 | { | 718 | { |
715 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 719 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
716 | "Connection to core FAILED!\n"); | 720 | "Connection to core FAILED!\n"); |
717 | GNUNET_SCHEDULER_shutdown(); | 721 | GNUNET_SCHEDULER_shutdown (); |
718 | return; | 722 | return; |
719 | } | 723 | } |
720 | my_identity = *identity; | 724 | my_identity = *identity; |
721 | } | 725 | } |
722 | 726 | ||
@@ -737,45 +741,45 @@ core_init(void *cls, | |||
737 | * message. It's necessary to specify the timeout. | 741 | * message. It's necessary to specify the timeout. |
738 | */ | 742 | */ |
739 | static void | 743 | static void |
740 | handle_revocation_union_request(void *cls, | 744 | handle_revocation_union_request (void *cls, |
741 | const struct GNUNET_PeerIdentity *other_peer, | 745 | const struct GNUNET_PeerIdentity *other_peer, |
742 | const struct GNUNET_MessageHeader *context_msg, | 746 | const struct GNUNET_MessageHeader *context_msg, |
743 | struct GNUNET_SET_Request *request) | 747 | struct GNUNET_SET_Request *request) |
744 | { | 748 | { |
745 | struct PeerEntry *peer_entry; | 749 | struct PeerEntry *peer_entry; |
746 | 750 | ||
747 | if (NULL == request) | 751 | if (NULL == request) |
748 | { | 752 | { |
749 | GNUNET_break(0); | 753 | GNUNET_break (0); |
750 | return; | 754 | return; |
751 | } | 755 | } |
752 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 756 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
753 | "Received set exchange request from peer `%s'\n", | 757 | "Received set exchange request from peer `%s'\n", |
754 | GNUNET_i2s(other_peer)); | 758 | GNUNET_i2s (other_peer)); |
755 | peer_entry = GNUNET_CONTAINER_multipeermap_get(peers, | 759 | peer_entry = GNUNET_CONTAINER_multipeermap_get (peers, |
756 | other_peer); | 760 | other_peer); |
757 | if (NULL == peer_entry) | 761 | if (NULL == peer_entry) |
758 | { | 762 | { |
759 | peer_entry = new_peer_entry(other_peer); | 763 | peer_entry = new_peer_entry (other_peer); |
760 | } | 764 | } |
761 | if (NULL != peer_entry->so) | 765 | if (NULL != peer_entry->so) |
762 | { | 766 | { |
763 | GNUNET_break_op(0); | 767 | GNUNET_break_op (0); |
764 | return; | 768 | return; |
765 | } | 769 | } |
766 | peer_entry->so = GNUNET_SET_accept(request, | 770 | peer_entry->so = GNUNET_SET_accept (request, |
767 | GNUNET_SET_RESULT_ADDED, | 771 | GNUNET_SET_RESULT_ADDED, |
768 | (struct GNUNET_SET_Option[]) { { 0 } }, | 772 | (struct GNUNET_SET_Option[]) { { 0 } }, |
769 | &add_revocation, | 773 | &add_revocation, |
770 | peer_entry); | 774 | peer_entry); |
771 | if (GNUNET_OK != | 775 | if (GNUNET_OK != |
772 | GNUNET_SET_commit(peer_entry->so, | 776 | GNUNET_SET_commit (peer_entry->so, |
773 | revocation_set)) | 777 | revocation_set)) |
774 | { | 778 | { |
775 | GNUNET_break(0); | 779 | GNUNET_break (0); |
776 | GNUNET_SCHEDULER_shutdown(); | 780 | GNUNET_SCHEDULER_shutdown (); |
777 | return; | 781 | return; |
778 | } | 782 | } |
779 | } | 783 | } |
780 | 784 | ||
781 | 785 | ||
@@ -787,136 +791,137 @@ handle_revocation_union_request(void *cls, | |||
787 | * @param c configuration to use | 791 | * @param c configuration to use |
788 | */ | 792 | */ |
789 | static void | 793 | static void |
790 | run(void *cls, | 794 | run (void *cls, |
791 | const struct GNUNET_CONFIGURATION_Handle *c, | 795 | const struct GNUNET_CONFIGURATION_Handle *c, |
792 | struct GNUNET_SERVICE_Handle *service) | 796 | struct GNUNET_SERVICE_Handle *service) |
793 | { | 797 | { |
794 | struct GNUNET_MQ_MessageHandler core_handlers[] = { | 798 | struct GNUNET_MQ_MessageHandler core_handlers[] = { |
795 | GNUNET_MQ_hd_fixed_size(p2p_revoke, | 799 | GNUNET_MQ_hd_fixed_size (p2p_revoke, |
796 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE, | 800 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE, |
797 | struct RevokeMessage, | 801 | struct RevokeMessage, |
798 | NULL), | 802 | NULL), |
799 | GNUNET_MQ_handler_end() | 803 | GNUNET_MQ_handler_end () |
800 | }; | 804 | }; |
801 | char *fn; | 805 | char *fn; |
802 | uint64_t left; | 806 | uint64_t left; |
803 | struct RevokeMessage *rm; | 807 | struct RevokeMessage *rm; |
804 | struct GNUNET_HashCode hc; | 808 | struct GNUNET_HashCode hc; |
805 | 809 | ||
806 | GNUNET_CRYPTO_hash("revocation-set-union-application-id", | 810 | GNUNET_CRYPTO_hash ("revocation-set-union-application-id", |
807 | strlen("revocation-set-union-application-id"), | 811 | strlen ("revocation-set-union-application-id"), |
808 | &revocation_set_union_app_id); | 812 | &revocation_set_union_app_id); |
809 | if (GNUNET_OK != | 813 | if (GNUNET_OK != |
810 | GNUNET_CONFIGURATION_get_value_filename(c, | 814 | GNUNET_CONFIGURATION_get_value_filename (c, |
811 | "REVOCATION", | 815 | "REVOCATION", |
812 | "DATABASE", | 816 | "DATABASE", |
813 | &fn)) | 817 | &fn)) |
814 | { | 818 | { |
815 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, | 819 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
816 | "REVOCATION", | 820 | "REVOCATION", |
817 | "DATABASE"); | 821 | "DATABASE"); |
818 | GNUNET_SCHEDULER_shutdown(); | 822 | GNUNET_SCHEDULER_shutdown (); |
819 | return; | 823 | return; |
820 | } | 824 | } |
821 | cfg = c; | 825 | cfg = c; |
822 | revocation_map = GNUNET_CONTAINER_multihashmap_create(16, | 826 | revocation_map = GNUNET_CONTAINER_multihashmap_create (16, |
823 | GNUNET_NO); | 827 | GNUNET_NO); |
824 | if (GNUNET_OK != | 828 | if (GNUNET_OK != |
825 | GNUNET_CONFIGURATION_get_value_number(cfg, | 829 | GNUNET_CONFIGURATION_get_value_number (cfg, |
826 | "REVOCATION", | 830 | "REVOCATION", |
827 | "WORKBITS", | 831 | "WORKBITS", |
828 | &revocation_work_required)) | 832 | &revocation_work_required)) |
829 | { | 833 | { |
830 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, | 834 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
831 | "REVOCATION", | 835 | "REVOCATION", |
832 | "WORKBITS"); | 836 | "WORKBITS"); |
833 | GNUNET_SCHEDULER_shutdown(); | 837 | GNUNET_SCHEDULER_shutdown (); |
834 | GNUNET_free(fn); | 838 | GNUNET_free (fn); |
835 | return; | 839 | return; |
836 | } | 840 | } |
837 | if (revocation_work_required >= sizeof(struct GNUNET_HashCode) * 8) | 841 | if (revocation_work_required >= sizeof(struct GNUNET_HashCode) * 8) |
838 | { | 842 | { |
839 | GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, | 843 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, |
840 | "REVOCATION", | 844 | "REVOCATION", |
841 | "WORKBITS", | 845 | "WORKBITS", |
842 | _("Value is too large.\n")); | 846 | _ ("Value is too large.\n")); |
843 | GNUNET_SCHEDULER_shutdown(); | 847 | GNUNET_SCHEDULER_shutdown (); |
844 | GNUNET_free(fn); | 848 | GNUNET_free (fn); |
845 | return; | 849 | return; |
846 | } | 850 | } |
847 | revocation_set = GNUNET_SET_create(cfg, | 851 | revocation_set = GNUNET_SET_create (cfg, |
848 | GNUNET_SET_OPERATION_UNION); | 852 | GNUNET_SET_OPERATION_UNION); |
849 | revocation_union_listen_handle | 853 | revocation_union_listen_handle |
850 | = GNUNET_SET_listen(cfg, | 854 | = GNUNET_SET_listen (cfg, |
851 | GNUNET_SET_OPERATION_UNION, | 855 | GNUNET_SET_OPERATION_UNION, |
852 | &revocation_set_union_app_id, | 856 | &revocation_set_union_app_id, |
853 | &handle_revocation_union_request, | 857 | &handle_revocation_union_request, |
854 | NULL); | 858 | NULL); |
855 | revocation_db = GNUNET_DISK_file_open(fn, | 859 | revocation_db = GNUNET_DISK_file_open (fn, |
856 | GNUNET_DISK_OPEN_READWRITE | | 860 | GNUNET_DISK_OPEN_READWRITE |
857 | GNUNET_DISK_OPEN_CREATE, | 861 | | GNUNET_DISK_OPEN_CREATE, |
858 | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE | | 862 | GNUNET_DISK_PERM_USER_READ |
859 | GNUNET_DISK_PERM_GROUP_READ | | 863 | | GNUNET_DISK_PERM_USER_WRITE |
860 | GNUNET_DISK_PERM_OTHER_READ); | 864 | | GNUNET_DISK_PERM_GROUP_READ |
865 | | GNUNET_DISK_PERM_OTHER_READ); | ||
861 | if (NULL == revocation_db) | 866 | if (NULL == revocation_db) |
862 | { | 867 | { |
863 | GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, | 868 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, |
864 | "REVOCATION", | 869 | "REVOCATION", |
865 | "DATABASE", | 870 | "DATABASE", |
866 | _("Could not open revocation database file!")); | 871 | _ ("Could not open revocation database file!")); |
867 | GNUNET_SCHEDULER_shutdown(); | 872 | GNUNET_SCHEDULER_shutdown (); |
868 | GNUNET_free(fn); | 873 | GNUNET_free (fn); |
869 | return; | 874 | return; |
870 | } | 875 | } |
871 | if (GNUNET_OK != | 876 | if (GNUNET_OK != |
872 | GNUNET_DISK_file_size(fn, &left, GNUNET_YES, GNUNET_YES)) | 877 | GNUNET_DISK_file_size (fn, &left, GNUNET_YES, GNUNET_YES)) |
873 | left = 0; | 878 | left = 0; |
874 | while (left > sizeof(struct RevokeMessage)) | 879 | while (left > sizeof(struct RevokeMessage)) |
875 | { | 880 | { |
876 | rm = GNUNET_new(struct RevokeMessage); | 881 | rm = GNUNET_new (struct RevokeMessage); |
877 | if (sizeof(struct RevokeMessage) != | 882 | if (sizeof(struct RevokeMessage) != |
878 | GNUNET_DISK_file_read(revocation_db, | 883 | GNUNET_DISK_file_read (revocation_db, |
879 | rm, | 884 | rm, |
880 | sizeof(struct RevokeMessage))) | 885 | sizeof(struct RevokeMessage))) |
881 | { | 886 | { |
882 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, | 887 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, |
883 | "read", | 888 | "read", |
884 | fn); | 889 | fn); |
885 | GNUNET_free(rm); | 890 | GNUNET_free (rm); |
886 | GNUNET_SCHEDULER_shutdown(); | 891 | GNUNET_SCHEDULER_shutdown (); |
887 | GNUNET_free(fn); | 892 | GNUNET_free (fn); |
888 | return; | 893 | return; |
889 | } | 894 | } |
890 | GNUNET_break(0 == ntohl(rm->reserved)); | 895 | GNUNET_break (0 == ntohl (rm->reserved)); |
891 | GNUNET_CRYPTO_hash(&rm->public_key, | 896 | GNUNET_CRYPTO_hash (&rm->public_key, |
892 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), | 897 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), |
893 | &hc); | 898 | &hc); |
894 | GNUNET_break(GNUNET_OK == | 899 | GNUNET_break (GNUNET_OK == |
895 | GNUNET_CONTAINER_multihashmap_put(revocation_map, | 900 | GNUNET_CONTAINER_multihashmap_put (revocation_map, |
896 | &hc, | 901 | &hc, |
897 | rm, | 902 | rm, |
898 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 903 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
899 | } | 904 | } |
900 | GNUNET_free(fn); | 905 | GNUNET_free (fn); |
901 | 906 | ||
902 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, | 907 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, |
903 | NULL); | 908 | NULL); |
904 | peers = GNUNET_CONTAINER_multipeermap_create(128, | 909 | peers = GNUNET_CONTAINER_multipeermap_create (128, |
905 | GNUNET_YES); | 910 | GNUNET_YES); |
906 | /* Connect to core service and register core handlers */ | 911 | /* Connect to core service and register core handlers */ |
907 | core_api = GNUNET_CORE_connect(cfg, /* Main configuration */ | 912 | core_api = GNUNET_CORE_connect (cfg, /* Main configuration */ |
908 | NULL, /* Closure passed to functions */ | 913 | NULL, /* Closure passed to functions */ |
909 | &core_init, /* Call core_init once connected */ | 914 | &core_init, /* Call core_init once connected */ |
910 | &handle_core_connect, /* Handle connects */ | 915 | &handle_core_connect, /* Handle connects */ |
911 | &handle_core_disconnect, /* Handle disconnects */ | 916 | &handle_core_disconnect, /* Handle disconnects */ |
912 | core_handlers); /* Register these handlers */ | 917 | core_handlers); /* Register these handlers */ |
913 | if (NULL == core_api) | 918 | if (NULL == core_api) |
914 | { | 919 | { |
915 | GNUNET_SCHEDULER_shutdown(); | 920 | GNUNET_SCHEDULER_shutdown (); |
916 | return; | 921 | return; |
917 | } | 922 | } |
918 | stats = GNUNET_STATISTICS_create("revocation", | 923 | stats = GNUNET_STATISTICS_create ("revocation", |
919 | cfg); | 924 | cfg); |
920 | } | 925 | } |
921 | 926 | ||
922 | 927 | ||
@@ -930,15 +935,15 @@ GNUNET_SERVICE_MAIN | |||
930 | &client_connect_cb, | 935 | &client_connect_cb, |
931 | &client_disconnect_cb, | 936 | &client_disconnect_cb, |
932 | NULL, | 937 | NULL, |
933 | GNUNET_MQ_hd_fixed_size(query_message, | 938 | GNUNET_MQ_hd_fixed_size (query_message, |
934 | GNUNET_MESSAGE_TYPE_REVOCATION_QUERY, | 939 | GNUNET_MESSAGE_TYPE_REVOCATION_QUERY, |
935 | struct QueryMessage, | 940 | struct QueryMessage, |
936 | NULL), | 941 | NULL), |
937 | GNUNET_MQ_hd_fixed_size(revoke_message, | 942 | GNUNET_MQ_hd_fixed_size (revoke_message, |
938 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE, | 943 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE, |
939 | struct RevokeMessage, | 944 | struct RevokeMessage, |
940 | NULL), | 945 | NULL), |
941 | GNUNET_MQ_handler_end()); | 946 | GNUNET_MQ_handler_end ()); |
942 | 947 | ||
943 | 948 | ||
944 | #if defined(LINUX) && defined(__GLIBC__) | 949 | #if defined(LINUX) && defined(__GLIBC__) |
@@ -948,11 +953,11 @@ GNUNET_SERVICE_MAIN | |||
948 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. | 953 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. |
949 | */ | 954 | */ |
950 | void __attribute__ ((constructor)) | 955 | void __attribute__ ((constructor)) |
951 | GNUNET_REVOCATION_memory_init() | 956 | GNUNET_REVOCATION_memory_init () |
952 | { | 957 | { |
953 | mallopt(M_TRIM_THRESHOLD, 4 * 1024); | 958 | mallopt (M_TRIM_THRESHOLD, 4 * 1024); |
954 | mallopt(M_TOP_PAD, 1 * 1024); | 959 | mallopt (M_TOP_PAD, 1 * 1024); |
955 | malloc_trim(0); | 960 | malloc_trim (0); |
956 | } | 961 | } |
957 | 962 | ||
958 | #endif | 963 | #endif |
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 | ||
diff --git a/src/revocation/revocation.h b/src/revocation/revocation.h index 43efd5ff2..60cc05457 100644 --- a/src/revocation/revocation.h +++ b/src/revocation/revocation.h | |||
@@ -33,7 +33,8 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
33 | /** | 33 | /** |
34 | * Query key revocation status. | 34 | * Query key revocation status. |
35 | */ | 35 | */ |
36 | struct QueryMessage { | 36 | struct QueryMessage |
37 | { | ||
37 | /** | 38 | /** |
38 | * Type: #GNUNET_MESSAGE_TYPE_REVOCATION_QUERY | 39 | * Type: #GNUNET_MESSAGE_TYPE_REVOCATION_QUERY |
39 | */ | 40 | */ |
@@ -54,7 +55,8 @@ struct QueryMessage { | |||
54 | /** | 55 | /** |
55 | * Key revocation response. | 56 | * Key revocation response. |
56 | */ | 57 | */ |
57 | struct QueryResponseMessage { | 58 | struct QueryResponseMessage |
59 | { | ||
58 | /** | 60 | /** |
59 | * Type: #GNUNET_MESSAGE_TYPE_REVOCATION_QUERY_RESPONSE | 61 | * Type: #GNUNET_MESSAGE_TYPE_REVOCATION_QUERY_RESPONSE |
60 | */ | 62 | */ |
@@ -74,7 +76,8 @@ struct QueryResponseMessage { | |||
74 | * #GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE (which is just | 76 | * #GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE (which is just |
75 | * in a `struct GNUNET_MessageHeader`. | 77 | * in a `struct GNUNET_MessageHeader`. |
76 | */ | 78 | */ |
77 | struct RevokeMessage { | 79 | struct RevokeMessage |
80 | { | ||
78 | /** | 81 | /** |
79 | * Type: #GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE | 82 | * Type: #GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE |
80 | */ | 83 | */ |
@@ -111,7 +114,8 @@ struct RevokeMessage { | |||
111 | /** | 114 | /** |
112 | * Key revocation response. | 115 | * Key revocation response. |
113 | */ | 116 | */ |
114 | struct RevocationResponseMessage { | 117 | struct RevocationResponseMessage |
118 | { | ||
115 | /** | 119 | /** |
116 | * Type: #GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE | 120 | * Type: #GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE |
117 | */ | 121 | */ |
diff --git a/src/revocation/revocation_api.c b/src/revocation/revocation_api.c index 091f6ae85..fd25050e2 100644 --- a/src/revocation/revocation_api.c +++ b/src/revocation/revocation_api.c | |||
@@ -33,7 +33,8 @@ | |||
33 | /** | 33 | /** |
34 | * Handle for the key revocation query. | 34 | * Handle for the key revocation query. |
35 | */ | 35 | */ |
36 | struct GNUNET_REVOCATION_Query { | 36 | struct GNUNET_REVOCATION_Query |
37 | { | ||
37 | /** | 38 | /** |
38 | * Message queue to the service. | 39 | * Message queue to the service. |
39 | */ | 40 | */ |
@@ -61,16 +62,16 @@ struct GNUNET_REVOCATION_Query { | |||
61 | * @param error error code | 62 | * @param error error code |
62 | */ | 63 | */ |
63 | static void | 64 | static void |
64 | query_mq_error_handler(void *cls, | 65 | query_mq_error_handler (void *cls, |
65 | enum GNUNET_MQ_Error error) | 66 | enum GNUNET_MQ_Error error) |
66 | { | 67 | { |
67 | struct GNUNET_REVOCATION_Query *q = cls; | 68 | struct GNUNET_REVOCATION_Query *q = cls; |
68 | 69 | ||
69 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 70 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
70 | "Revocation query MQ error\n"); | 71 | "Revocation query MQ error\n"); |
71 | q->func(q->func_cls, | 72 | q->func (q->func_cls, |
72 | GNUNET_SYSERR); | 73 | GNUNET_SYSERR); |
73 | GNUNET_REVOCATION_query_cancel(q); | 74 | GNUNET_REVOCATION_query_cancel (q); |
74 | } | 75 | } |
75 | 76 | ||
76 | 77 | ||
@@ -81,17 +82,17 @@ query_mq_error_handler(void *cls, | |||
81 | * @param qrm response we got | 82 | * @param qrm response we got |
82 | */ | 83 | */ |
83 | static void | 84 | static void |
84 | handle_revocation_query_response(void *cls, | 85 | handle_revocation_query_response (void *cls, |
85 | const struct QueryResponseMessage *qrm) | 86 | const struct QueryResponseMessage *qrm) |
86 | { | 87 | { |
87 | struct GNUNET_REVOCATION_Query *q = cls; | 88 | struct GNUNET_REVOCATION_Query *q = cls; |
88 | 89 | ||
89 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 90 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
90 | "Revocation query result: %d\n", | 91 | "Revocation query result: %d\n", |
91 | (uint32_t)ntohl(qrm->is_valid)); | 92 | (uint32_t) ntohl (qrm->is_valid)); |
92 | q->func(q->func_cls, | 93 | q->func (q->func_cls, |
93 | ntohl(qrm->is_valid)); | 94 | ntohl (qrm->is_valid)); |
94 | GNUNET_REVOCATION_query_cancel(q); | 95 | GNUNET_REVOCATION_query_cancel (q); |
95 | } | 96 | } |
96 | 97 | ||
97 | 98 | ||
@@ -105,41 +106,41 @@ handle_revocation_query_response(void *cls, | |||
105 | * @return handle to use in #GNUNET_REVOCATION_query_cancel to stop REVOCATION from invoking the callback | 106 | * @return handle to use in #GNUNET_REVOCATION_query_cancel to stop REVOCATION from invoking the callback |
106 | */ | 107 | */ |
107 | struct GNUNET_REVOCATION_Query * | 108 | struct GNUNET_REVOCATION_Query * |
108 | GNUNET_REVOCATION_query(const struct GNUNET_CONFIGURATION_Handle *cfg, | 109 | GNUNET_REVOCATION_query (const struct GNUNET_CONFIGURATION_Handle *cfg, |
109 | const struct GNUNET_CRYPTO_EcdsaPublicKey *key, | 110 | const struct GNUNET_CRYPTO_EcdsaPublicKey *key, |
110 | GNUNET_REVOCATION_Callback func, | 111 | GNUNET_REVOCATION_Callback func, |
111 | void *func_cls) | 112 | void *func_cls) |
112 | { | 113 | { |
113 | struct GNUNET_REVOCATION_Query *q | 114 | struct GNUNET_REVOCATION_Query *q |
114 | = GNUNET_new(struct GNUNET_REVOCATION_Query); | 115 | = GNUNET_new (struct GNUNET_REVOCATION_Query); |
115 | struct GNUNET_MQ_MessageHandler handlers[] = { | 116 | struct GNUNET_MQ_MessageHandler handlers[] = { |
116 | GNUNET_MQ_hd_fixed_size(revocation_query_response, | 117 | GNUNET_MQ_hd_fixed_size (revocation_query_response, |
117 | GNUNET_MESSAGE_TYPE_REVOCATION_QUERY_RESPONSE, | 118 | GNUNET_MESSAGE_TYPE_REVOCATION_QUERY_RESPONSE, |
118 | struct QueryResponseMessage, | 119 | struct QueryResponseMessage, |
119 | q), | 120 | q), |
120 | GNUNET_MQ_handler_end() | 121 | GNUNET_MQ_handler_end () |
121 | }; | 122 | }; |
122 | struct QueryMessage *qm; | 123 | struct QueryMessage *qm; |
123 | struct GNUNET_MQ_Envelope *env; | 124 | struct GNUNET_MQ_Envelope *env; |
124 | 125 | ||
125 | q->mq = GNUNET_CLIENT_connect(cfg, | 126 | q->mq = GNUNET_CLIENT_connect (cfg, |
126 | "revocation", | 127 | "revocation", |
127 | handlers, | 128 | handlers, |
128 | &query_mq_error_handler, | 129 | &query_mq_error_handler, |
129 | q); | 130 | q); |
130 | if (NULL == q->mq) | 131 | if (NULL == q->mq) |
131 | { | 132 | { |
132 | GNUNET_free(q); | 133 | GNUNET_free (q); |
133 | return NULL; | 134 | return NULL; |
134 | } | 135 | } |
135 | q->func = func; | 136 | q->func = func; |
136 | q->func_cls = func_cls; | 137 | q->func_cls = func_cls; |
137 | env = GNUNET_MQ_msg(qm, | 138 | env = GNUNET_MQ_msg (qm, |
138 | GNUNET_MESSAGE_TYPE_REVOCATION_QUERY); | 139 | GNUNET_MESSAGE_TYPE_REVOCATION_QUERY); |
139 | qm->reserved = htonl(0); | 140 | qm->reserved = htonl (0); |
140 | qm->key = *key; | 141 | qm->key = *key; |
141 | GNUNET_MQ_send(q->mq, | 142 | GNUNET_MQ_send (q->mq, |
142 | env); | 143 | env); |
143 | return q; | 144 | return q; |
144 | } | 145 | } |
145 | 146 | ||
@@ -150,21 +151,22 @@ GNUNET_REVOCATION_query(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
150 | * @param q query to cancel | 151 | * @param q query to cancel |
151 | */ | 152 | */ |
152 | void | 153 | void |
153 | GNUNET_REVOCATION_query_cancel(struct GNUNET_REVOCATION_Query *q) | 154 | GNUNET_REVOCATION_query_cancel (struct GNUNET_REVOCATION_Query *q) |
154 | { | 155 | { |
155 | if (NULL != q->mq) | 156 | if (NULL != q->mq) |
156 | { | 157 | { |
157 | GNUNET_MQ_destroy(q->mq); | 158 | GNUNET_MQ_destroy (q->mq); |
158 | q->mq = NULL; | 159 | q->mq = NULL; |
159 | } | 160 | } |
160 | GNUNET_free(q); | 161 | GNUNET_free (q); |
161 | } | 162 | } |
162 | 163 | ||
163 | 164 | ||
164 | /** | 165 | /** |
165 | * Handle for the key revocation operation. | 166 | * Handle for the key revocation operation. |
166 | */ | 167 | */ |
167 | struct GNUNET_REVOCATION_Handle { | 168 | struct GNUNET_REVOCATION_Handle |
169 | { | ||
168 | /** | 170 | /** |
169 | * Message queue to the service. | 171 | * Message queue to the service. |
170 | */ | 172 | */ |
@@ -192,16 +194,16 @@ struct GNUNET_REVOCATION_Handle { | |||
192 | * @param error error code | 194 | * @param error error code |
193 | */ | 195 | */ |
194 | static void | 196 | static void |
195 | revocation_mq_error_handler(void *cls, | 197 | revocation_mq_error_handler (void *cls, |
196 | enum GNUNET_MQ_Error error) | 198 | enum GNUNET_MQ_Error error) |
197 | { | 199 | { |
198 | struct GNUNET_REVOCATION_Handle *h = cls; | 200 | struct GNUNET_REVOCATION_Handle *h = cls; |
199 | 201 | ||
200 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 202 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
201 | "Revocation MQ error\n"); | 203 | "Revocation MQ error\n"); |
202 | h->func(h->func_cls, | 204 | h->func (h->func_cls, |
203 | GNUNET_SYSERR); | 205 | GNUNET_SYSERR); |
204 | GNUNET_REVOCATION_revoke_cancel(h); | 206 | GNUNET_REVOCATION_revoke_cancel (h); |
205 | } | 207 | } |
206 | 208 | ||
207 | 209 | ||
@@ -212,17 +214,17 @@ revocation_mq_error_handler(void *cls, | |||
212 | * @param rrm response we got | 214 | * @param rrm response we got |
213 | */ | 215 | */ |
214 | static void | 216 | static void |
215 | handle_revocation_response(void *cls, | 217 | handle_revocation_response (void *cls, |
216 | const struct RevocationResponseMessage *rrm) | 218 | const struct RevocationResponseMessage *rrm) |
217 | { | 219 | { |
218 | struct GNUNET_REVOCATION_Handle *h = cls; | 220 | struct GNUNET_REVOCATION_Handle *h = cls; |
219 | 221 | ||
220 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 222 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
221 | "Revocation transmission result: %d\n", | 223 | "Revocation transmission result: %d\n", |
222 | (uint32_t)ntohl(rrm->is_valid)); | 224 | (uint32_t) ntohl (rrm->is_valid)); |
223 | h->func(h->func_cls, | 225 | h->func (h->func_cls, |
224 | ntohl(rrm->is_valid)); | 226 | ntohl (rrm->is_valid)); |
225 | GNUNET_REVOCATION_revoke_cancel(h); | 227 | GNUNET_REVOCATION_revoke_cancel (h); |
226 | } | 228 | } |
227 | 229 | ||
228 | 230 | ||
@@ -242,64 +244,64 @@ handle_revocation_response(void *cls, | |||
242 | * @return handle to use in #GNUNET_REVOCATION_revoke_cancel to stop REVOCATION from invoking the callback | 244 | * @return handle to use in #GNUNET_REVOCATION_revoke_cancel to stop REVOCATION from invoking the callback |
243 | */ | 245 | */ |
244 | struct GNUNET_REVOCATION_Handle * | 246 | struct GNUNET_REVOCATION_Handle * |
245 | GNUNET_REVOCATION_revoke(const struct GNUNET_CONFIGURATION_Handle *cfg, | 247 | GNUNET_REVOCATION_revoke (const struct GNUNET_CONFIGURATION_Handle *cfg, |
246 | const struct GNUNET_CRYPTO_EcdsaPublicKey *key, | 248 | const struct GNUNET_CRYPTO_EcdsaPublicKey *key, |
247 | const struct GNUNET_CRYPTO_EcdsaSignature *sig, | 249 | const struct GNUNET_CRYPTO_EcdsaSignature *sig, |
248 | uint64_t pow, | 250 | uint64_t pow, |
249 | GNUNET_REVOCATION_Callback func, | 251 | GNUNET_REVOCATION_Callback func, |
250 | void *func_cls) | 252 | void *func_cls) |
251 | { | 253 | { |
252 | struct GNUNET_REVOCATION_Handle *h | 254 | struct GNUNET_REVOCATION_Handle *h |
253 | = GNUNET_new(struct GNUNET_REVOCATION_Handle); | 255 | = GNUNET_new (struct GNUNET_REVOCATION_Handle); |
254 | struct GNUNET_MQ_MessageHandler handlers[] = { | 256 | struct GNUNET_MQ_MessageHandler handlers[] = { |
255 | GNUNET_MQ_hd_fixed_size(revocation_response, | 257 | GNUNET_MQ_hd_fixed_size (revocation_response, |
256 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE, | 258 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE, |
257 | struct RevocationResponseMessage, | 259 | struct RevocationResponseMessage, |
258 | h), | 260 | h), |
259 | GNUNET_MQ_handler_end() | 261 | GNUNET_MQ_handler_end () |
260 | }; | 262 | }; |
261 | unsigned long long matching_bits; | 263 | unsigned long long matching_bits; |
262 | struct RevokeMessage *rm; | 264 | struct RevokeMessage *rm; |
263 | struct GNUNET_MQ_Envelope *env; | 265 | struct GNUNET_MQ_Envelope *env; |
264 | 266 | ||
265 | if ((GNUNET_OK == | 267 | if ((GNUNET_OK == |
266 | GNUNET_CONFIGURATION_get_value_number(cfg, | 268 | GNUNET_CONFIGURATION_get_value_number (cfg, |
267 | "REVOCATION", | 269 | "REVOCATION", |
268 | "WORKBITS", | 270 | "WORKBITS", |
269 | &matching_bits)) && | 271 | &matching_bits)) && |
270 | (GNUNET_YES != | 272 | (GNUNET_YES != |
271 | GNUNET_REVOCATION_check_pow(key, | 273 | GNUNET_REVOCATION_check_pow (key, |
272 | pow, | 274 | pow, |
273 | (unsigned int)matching_bits))) | 275 | (unsigned int) matching_bits))) |
274 | { | 276 | { |
275 | GNUNET_break(0); | 277 | GNUNET_break (0); |
276 | GNUNET_free(h); | 278 | GNUNET_free (h); |
277 | return NULL; | 279 | return NULL; |
278 | } | 280 | } |
279 | 281 | ||
280 | h->mq = GNUNET_CLIENT_connect(cfg, | 282 | h->mq = GNUNET_CLIENT_connect (cfg, |
281 | "revocation", | 283 | "revocation", |
282 | handlers, | 284 | handlers, |
283 | &revocation_mq_error_handler, | 285 | &revocation_mq_error_handler, |
284 | h); | 286 | h); |
285 | if (NULL == h->mq) | 287 | if (NULL == h->mq) |
286 | { | 288 | { |
287 | GNUNET_free(h); | 289 | GNUNET_free (h); |
288 | return NULL; | 290 | return NULL; |
289 | } | 291 | } |
290 | h->func = func; | 292 | h->func = func; |
291 | h->func_cls = func_cls; | 293 | h->func_cls = func_cls; |
292 | env = GNUNET_MQ_msg(rm, | 294 | env = GNUNET_MQ_msg (rm, |
293 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE); | 295 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE); |
294 | rm->reserved = htonl(0); | 296 | rm->reserved = htonl (0); |
295 | rm->proof_of_work = pow; | 297 | rm->proof_of_work = pow; |
296 | rm->purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_REVOCATION); | 298 | rm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION); |
297 | rm->purpose.size = htonl(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + | 299 | rm->purpose.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) |
298 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); | 300 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); |
299 | rm->public_key = *key; | 301 | rm->public_key = *key; |
300 | rm->signature = *sig; | 302 | rm->signature = *sig; |
301 | GNUNET_MQ_send(h->mq, | 303 | GNUNET_MQ_send (h->mq, |
302 | env); | 304 | env); |
303 | return h; | 305 | return h; |
304 | } | 306 | } |
305 | 307 | ||
@@ -310,14 +312,14 @@ GNUNET_REVOCATION_revoke(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
310 | * @param h operation to cancel | 312 | * @param h operation to cancel |
311 | */ | 313 | */ |
312 | void | 314 | void |
313 | GNUNET_REVOCATION_revoke_cancel(struct GNUNET_REVOCATION_Handle *h) | 315 | GNUNET_REVOCATION_revoke_cancel (struct GNUNET_REVOCATION_Handle *h) |
314 | { | 316 | { |
315 | if (NULL != h->mq) | 317 | if (NULL != h->mq) |
316 | { | 318 | { |
317 | GNUNET_MQ_destroy(h->mq); | 319 | GNUNET_MQ_destroy (h->mq); |
318 | h->mq = NULL; | 320 | h->mq = NULL; |
319 | } | 321 | } |
320 | GNUNET_free(h); | 322 | GNUNET_free (h); |
321 | } | 323 | } |
322 | 324 | ||
323 | 325 | ||
@@ -329,18 +331,18 @@ GNUNET_REVOCATION_revoke_cancel(struct GNUNET_REVOCATION_Handle *h) | |||
329 | * @param result where to write the resulting hash | 331 | * @param result where to write the resulting hash |
330 | */ | 332 | */ |
331 | static void | 333 | static void |
332 | pow_hash(const void *buf, | 334 | pow_hash (const void *buf, |
333 | size_t buf_len, | 335 | size_t buf_len, |
334 | struct GNUNET_HashCode *result) | 336 | struct GNUNET_HashCode *result) |
335 | { | 337 | { |
336 | GNUNET_break(0 == | 338 | GNUNET_break (0 == |
337 | gcry_kdf_derive(buf, buf_len, | 339 | gcry_kdf_derive (buf, buf_len, |
338 | GCRY_KDF_SCRYPT, | 340 | GCRY_KDF_SCRYPT, |
339 | 1 /* subalgo */, | 341 | 1 /* subalgo */, |
340 | "gnunet-revocation-proof-of-work", | 342 | "gnunet-revocation-proof-of-work", |
341 | strlen("gnunet-revocation-proof-of-work"), | 343 | strlen ("gnunet-revocation-proof-of-work"), |
342 | 2 /* iterations; keep cost of individual op small */, | 344 | 2 /* iterations; keep cost of individual op small */, |
343 | sizeof(struct GNUNET_HashCode), result)); | 345 | sizeof(struct GNUNET_HashCode), result)); |
344 | } | 346 | } |
345 | 347 | ||
346 | 348 | ||
@@ -351,12 +353,12 @@ pow_hash(const void *buf, | |||
351 | * @return the number of leading zero bits. | 353 | * @return the number of leading zero bits. |
352 | */ | 354 | */ |
353 | static unsigned int | 355 | static unsigned int |
354 | count_leading_zeroes(const struct GNUNET_HashCode *hash) | 356 | count_leading_zeroes (const struct GNUNET_HashCode *hash) |
355 | { | 357 | { |
356 | unsigned int hash_count; | 358 | unsigned int hash_count; |
357 | 359 | ||
358 | hash_count = 0; | 360 | hash_count = 0; |
359 | while ((0 == GNUNET_CRYPTO_hash_get_bit(hash, hash_count))) | 361 | while ((0 == GNUNET_CRYPTO_hash_get_bit (hash, hash_count))) |
360 | hash_count++; | 362 | hash_count++; |
361 | return hash_count; | 363 | return hash_count; |
362 | } | 364 | } |
@@ -372,19 +374,19 @@ count_leading_zeroes(const struct GNUNET_HashCode *hash) | |||
372 | * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not | 374 | * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not |
373 | */ | 375 | */ |
374 | int | 376 | int |
375 | GNUNET_REVOCATION_check_pow(const struct GNUNET_CRYPTO_EcdsaPublicKey *key, | 377 | GNUNET_REVOCATION_check_pow (const struct GNUNET_CRYPTO_EcdsaPublicKey *key, |
376 | uint64_t pow, | 378 | uint64_t pow, |
377 | unsigned int matching_bits) | 379 | unsigned int matching_bits) |
378 | { | 380 | { |
379 | char buf[sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) + | 381 | char buf[sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) |
380 | sizeof(pow)] GNUNET_ALIGN; | 382 | + sizeof(pow)] GNUNET_ALIGN; |
381 | struct GNUNET_HashCode result; | 383 | struct GNUNET_HashCode result; |
382 | 384 | ||
383 | GNUNET_memcpy(buf, &pow, sizeof(pow)); | 385 | GNUNET_memcpy (buf, &pow, sizeof(pow)); |
384 | GNUNET_memcpy(&buf[sizeof(pow)], key, | 386 | GNUNET_memcpy (&buf[sizeof(pow)], key, |
385 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); | 387 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); |
386 | pow_hash(buf, sizeof(buf), &result); | 388 | pow_hash (buf, sizeof(buf), &result); |
387 | return (count_leading_zeroes(&result) >= | 389 | return (count_leading_zeroes (&result) >= |
388 | matching_bits) ? GNUNET_YES : GNUNET_NO; | 390 | matching_bits) ? GNUNET_YES : GNUNET_NO; |
389 | } | 391 | } |
390 | 392 | ||
@@ -396,19 +398,20 @@ GNUNET_REVOCATION_check_pow(const struct GNUNET_CRYPTO_EcdsaPublicKey *key, | |||
396 | * @param sig where to write the revocation signature | 398 | * @param sig where to write the revocation signature |
397 | */ | 399 | */ |
398 | void | 400 | void |
399 | GNUNET_REVOCATION_sign_revocation(const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | 401 | GNUNET_REVOCATION_sign_revocation (const struct |
400 | struct GNUNET_CRYPTO_EcdsaSignature *sig) | 402 | GNUNET_CRYPTO_EcdsaPrivateKey *key, |
403 | struct GNUNET_CRYPTO_EcdsaSignature *sig) | ||
401 | { | 404 | { |
402 | struct RevokeMessage rm; | 405 | struct RevokeMessage rm; |
403 | 406 | ||
404 | rm.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_REVOCATION); | 407 | rm.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION); |
405 | rm.purpose.size = htonl(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + | 408 | rm.purpose.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) |
406 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); | 409 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); |
407 | GNUNET_CRYPTO_ecdsa_key_get_public(key, &rm.public_key); | 410 | GNUNET_CRYPTO_ecdsa_key_get_public (key, &rm.public_key); |
408 | GNUNET_assert(GNUNET_OK == | 411 | GNUNET_assert (GNUNET_OK == |
409 | GNUNET_CRYPTO_ecdsa_sign(key, | 412 | GNUNET_CRYPTO_ecdsa_sign (key, |
410 | &rm.purpose, | 413 | &rm.purpose, |
411 | sig)); | 414 | sig)); |
412 | } | 415 | } |
413 | 416 | ||
414 | 417 | ||
diff --git a/src/revocation/test_revocation.c b/src/revocation/test_revocation.c index 22cb98887..44d6c6ec8 100644 --- a/src/revocation/test_revocation.c +++ b/src/revocation/test_revocation.c | |||
@@ -31,7 +31,8 @@ | |||
31 | 31 | ||
32 | #define NUM_TEST_PEERS 2 | 32 | #define NUM_TEST_PEERS 2 |
33 | 33 | ||
34 | struct TestPeer { | 34 | struct TestPeer |
35 | { | ||
35 | struct GNUNET_TESTBED_Peer *p; | 36 | struct GNUNET_TESTBED_Peer *p; |
36 | struct GNUNET_TESTBED_Operation *identity_op; | 37 | struct GNUNET_TESTBED_Operation *identity_op; |
37 | struct GNUNET_TESTBED_Operation *core_op; | 38 | struct GNUNET_TESTBED_Operation *core_op; |
@@ -56,352 +57,352 @@ static int ok; | |||
56 | 57 | ||
57 | 58 | ||
58 | static void | 59 | static void |
59 | do_shutdown(void *cls) | 60 | do_shutdown (void *cls) |
60 | { | 61 | { |
61 | for (unsigned int c = 0; c < NUM_TEST_PEERS; c++) | 62 | for (unsigned int c = 0; c < NUM_TEST_PEERS; c++) |
63 | { | ||
64 | if (NULL != testpeers[c].create_id_op) | ||
65 | { | ||
66 | GNUNET_IDENTITY_cancel (testpeers[c].create_id_op); | ||
67 | testpeers[c].create_id_op = NULL; | ||
68 | } | ||
69 | if (NULL != testpeers[c].ego_lookup) | ||
70 | { | ||
71 | GNUNET_IDENTITY_ego_lookup_cancel (testpeers[c].ego_lookup); | ||
72 | testpeers[c].ego_lookup = NULL; | ||
73 | } | ||
74 | if (NULL != testpeers[c].revok_handle) | ||
75 | { | ||
76 | GNUNET_REVOCATION_revoke_cancel (testpeers[c].revok_handle); | ||
77 | testpeers[c].revok_handle = NULL; | ||
78 | } | ||
79 | if (NULL != testpeers[c].identity_op) | ||
80 | { | ||
81 | GNUNET_TESTBED_operation_done (testpeers[c].identity_op); | ||
82 | testpeers[c].identity_op = NULL; | ||
83 | } | ||
84 | if (NULL != testpeers[c].core_op) | ||
62 | { | 85 | { |
63 | if (NULL != testpeers[c].create_id_op) | 86 | GNUNET_TESTBED_operation_done (testpeers[c].core_op); |
64 | { | 87 | testpeers[c].core_op = NULL; |
65 | GNUNET_IDENTITY_cancel(testpeers[c].create_id_op); | ||
66 | testpeers[c].create_id_op = NULL; | ||
67 | } | ||
68 | if (NULL != testpeers[c].ego_lookup) | ||
69 | { | ||
70 | GNUNET_IDENTITY_ego_lookup_cancel(testpeers[c].ego_lookup); | ||
71 | testpeers[c].ego_lookup = NULL; | ||
72 | } | ||
73 | if (NULL != testpeers[c].revok_handle) | ||
74 | { | ||
75 | GNUNET_REVOCATION_revoke_cancel(testpeers[c].revok_handle); | ||
76 | testpeers[c].revok_handle = NULL; | ||
77 | } | ||
78 | if (NULL != testpeers[c].identity_op) | ||
79 | { | ||
80 | GNUNET_TESTBED_operation_done(testpeers[c].identity_op); | ||
81 | testpeers[c].identity_op = NULL; | ||
82 | } | ||
83 | if (NULL != testpeers[c].core_op) | ||
84 | { | ||
85 | GNUNET_TESTBED_operation_done(testpeers[c].core_op); | ||
86 | testpeers[c].core_op = NULL; | ||
87 | } | ||
88 | } | 88 | } |
89 | } | ||
89 | } | 90 | } |
90 | 91 | ||
91 | 92 | ||
92 | static void | 93 | static void |
93 | check_revocation(void *cls); | 94 | check_revocation (void *cls); |
94 | 95 | ||
95 | 96 | ||
96 | static void | 97 | static void |
97 | revocation_remote_cb(void *cls, int is_valid) | 98 | revocation_remote_cb (void *cls, int is_valid) |
98 | { | 99 | { |
99 | static int repeat = 0; | 100 | static int repeat = 0; |
100 | 101 | ||
101 | if (GNUNET_NO == is_valid) | 102 | if (GNUNET_NO == is_valid) |
102 | { | 103 | { |
103 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Local revocation successful\n"); | 104 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Local revocation successful\n"); |
104 | ok = 0; | 105 | ok = 0; |
105 | GNUNET_SCHEDULER_shutdown(); | 106 | GNUNET_SCHEDULER_shutdown (); |
106 | return; | 107 | return; |
107 | } | 108 | } |
108 | if (repeat < 10) | 109 | if (repeat < 10) |
109 | { | 110 | { |
110 | repeat++; | 111 | repeat++; |
111 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, | 112 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
112 | &check_revocation, | 113 | &check_revocation, |
113 | NULL); | 114 | NULL); |
114 | return; | 115 | return; |
115 | } | 116 | } |
116 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Flooding of revocation failed\n"); | 117 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Flooding of revocation failed\n"); |
117 | ok = 2; | 118 | ok = 2; |
118 | GNUNET_SCHEDULER_shutdown(); | 119 | GNUNET_SCHEDULER_shutdown (); |
119 | } | 120 | } |
120 | 121 | ||
121 | 122 | ||
122 | static void | 123 | static void |
123 | check_revocation(void *cls) | 124 | check_revocation (void *cls) |
124 | { | 125 | { |
125 | GNUNET_REVOCATION_query(testpeers[0].cfg, | 126 | GNUNET_REVOCATION_query (testpeers[0].cfg, |
126 | &testpeers[1].pubkey, | 127 | &testpeers[1].pubkey, |
127 | &revocation_remote_cb, | 128 | &revocation_remote_cb, |
128 | NULL); | 129 | NULL); |
129 | } | 130 | } |
130 | 131 | ||
131 | 132 | ||
132 | static void | 133 | static void |
133 | revocation_cb(void *cls, int is_valid) | 134 | revocation_cb (void *cls, int is_valid) |
134 | { | 135 | { |
135 | testpeers[1].revok_handle = NULL; | 136 | testpeers[1].revok_handle = NULL; |
136 | if (GNUNET_NO == is_valid) | 137 | if (GNUNET_NO == is_valid) |
137 | { | 138 | { |
138 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Revocation successful\n"); | 139 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Revocation successful\n"); |
139 | check_revocation(NULL); | 140 | check_revocation (NULL); |
140 | } | 141 | } |
141 | } | 142 | } |
142 | 143 | ||
143 | 144 | ||
144 | static void | 145 | static void |
145 | ego_cb(void *cls, const struct GNUNET_IDENTITY_Ego *ego) | 146 | ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego) |
146 | { | 147 | { |
147 | static int completed = 0; | 148 | static int completed = 0; |
148 | 149 | ||
149 | if ((NULL != ego) && (cls == &testpeers[0])) | 150 | if ((NULL != ego) && (cls == &testpeers[0])) |
150 | { | 151 | { |
151 | testpeers[0].ego_lookup = NULL; | 152 | testpeers[0].ego_lookup = NULL; |
152 | testpeers[0].privkey = GNUNET_IDENTITY_ego_get_private_key(ego); | 153 | testpeers[0].privkey = GNUNET_IDENTITY_ego_get_private_key (ego); |
153 | GNUNET_IDENTITY_ego_get_public_key(ego, &testpeers[0].pubkey); | 154 | GNUNET_IDENTITY_ego_get_public_key (ego, &testpeers[0].pubkey); |
154 | completed++; | 155 | completed++; |
155 | } | 156 | } |
156 | if ((NULL != ego) && (cls == &testpeers[1])) | 157 | if ((NULL != ego) && (cls == &testpeers[1])) |
158 | { | ||
159 | testpeers[1].ego_lookup = NULL; | ||
160 | testpeers[1].privkey = GNUNET_IDENTITY_ego_get_private_key (ego); | ||
161 | GNUNET_IDENTITY_ego_get_public_key (ego, &testpeers[1].pubkey); | ||
162 | GNUNET_REVOCATION_sign_revocation (testpeers[1].privkey, &testpeers[1].sig); | ||
163 | |||
164 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Calculating proof of work...\n"); | ||
165 | testpeers[1].pow = 0; | ||
166 | int res = | ||
167 | GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey, testpeers[1].pow, 5); | ||
168 | while (GNUNET_OK != res) | ||
157 | { | 169 | { |
158 | testpeers[1].ego_lookup = NULL; | 170 | testpeers[1].pow++; |
159 | testpeers[1].privkey = GNUNET_IDENTITY_ego_get_private_key(ego); | 171 | res = |
160 | GNUNET_IDENTITY_ego_get_public_key(ego, &testpeers[1].pubkey); | 172 | GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey, testpeers[1].pow, 5); |
161 | GNUNET_REVOCATION_sign_revocation(testpeers[1].privkey, &testpeers[1].sig); | ||
162 | |||
163 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Calculating proof of work...\n"); | ||
164 | testpeers[1].pow = 0; | ||
165 | int res = | ||
166 | GNUNET_REVOCATION_check_pow(&testpeers[1].pubkey, testpeers[1].pow, 5); | ||
167 | while (GNUNET_OK != res) | ||
168 | { | ||
169 | testpeers[1].pow++; | ||
170 | res = | ||
171 | GNUNET_REVOCATION_check_pow(&testpeers[1].pubkey, testpeers[1].pow, 5); | ||
172 | } | ||
173 | fprintf(stderr, "Done calculating proof of work\n"); | ||
174 | completed++; | ||
175 | } | 173 | } |
174 | fprintf (stderr, "Done calculating proof of work\n"); | ||
175 | completed++; | ||
176 | } | ||
176 | if (2 == completed) | 177 | if (2 == completed) |
177 | { | 178 | { |
178 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Egos retrieved\n"); | 179 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Egos retrieved\n"); |
179 | testpeers[1].revok_handle = GNUNET_REVOCATION_revoke(testpeers[1].cfg, | 180 | testpeers[1].revok_handle = GNUNET_REVOCATION_revoke (testpeers[1].cfg, |
180 | &testpeers[1].pubkey, | 181 | &testpeers[1].pubkey, |
181 | &testpeers[1].sig, | 182 | &testpeers[1].sig, |
182 | testpeers[1].pow, | 183 | testpeers[1].pow, |
183 | &revocation_cb, | 184 | &revocation_cb, |
184 | NULL); | 185 | NULL); |
185 | } | 186 | } |
186 | } | 187 | } |
187 | 188 | ||
188 | 189 | ||
189 | static void | 190 | static void |
190 | identity_create_cb(void *cls, | 191 | identity_create_cb (void *cls, |
191 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 192 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, |
192 | const char *emsg) | 193 | const char *emsg) |
193 | { | 194 | { |
194 | static int completed = 0; | 195 | static int completed = 0; |
195 | 196 | ||
196 | if ((NULL == emsg) && (cls == &testpeers[0])) | 197 | if ((NULL == emsg) && (cls == &testpeers[0])) |
197 | { | 198 | { |
198 | testpeers[0].create_id_op = NULL; | 199 | testpeers[0].create_id_op = NULL; |
199 | completed++; | 200 | completed++; |
200 | } | 201 | } |
201 | if ((NULL == emsg) && (cls == &testpeers[1])) | 202 | if ((NULL == emsg) && (cls == &testpeers[1])) |
202 | { | 203 | { |
203 | testpeers[1].create_id_op = NULL; | 204 | testpeers[1].create_id_op = NULL; |
204 | completed++; | 205 | completed++; |
205 | } | 206 | } |
206 | if (2 != completed) | 207 | if (2 != completed) |
207 | return; | 208 | return; |
208 | fprintf(stderr, "Identities created\n"); | 209 | fprintf (stderr, "Identities created\n"); |
209 | testpeers[0].ego_lookup = GNUNET_IDENTITY_ego_lookup(testpeers[0].cfg, | 210 | testpeers[0].ego_lookup = GNUNET_IDENTITY_ego_lookup (testpeers[0].cfg, |
210 | "client", | 211 | "client", |
211 | &ego_cb, | 212 | &ego_cb, |
212 | &testpeers[0]); | 213 | &testpeers[0]); |
213 | testpeers[1].ego_lookup = GNUNET_IDENTITY_ego_lookup(testpeers[1].cfg, | 214 | testpeers[1].ego_lookup = GNUNET_IDENTITY_ego_lookup (testpeers[1].cfg, |
214 | "toberevoked", | 215 | "toberevoked", |
215 | &ego_cb, | 216 | &ego_cb, |
216 | &testpeers[1]); | 217 | &testpeers[1]); |
217 | } | 218 | } |
218 | 219 | ||
219 | 220 | ||
220 | static void | 221 | static void |
221 | identity_completion_cb(void *cls, | 222 | identity_completion_cb (void *cls, |
222 | struct GNUNET_TESTBED_Operation *op, | 223 | struct GNUNET_TESTBED_Operation *op, |
223 | void *ca_result, | 224 | void *ca_result, |
224 | const char *emsg) | 225 | const char *emsg) |
225 | { | 226 | { |
226 | static int completed = 0; | 227 | static int completed = 0; |
227 | 228 | ||
228 | completed++; | 229 | completed++; |
229 | if (NUM_TEST_PEERS != completed) | 230 | if (NUM_TEST_PEERS != completed) |
230 | return; | 231 | return; |
231 | fprintf(stderr, "All peers connected @ IDENTITY ...\n"); | 232 | fprintf (stderr, "All peers connected @ IDENTITY ...\n"); |
232 | testpeers[0].create_id_op = GNUNET_IDENTITY_create(testpeers[0].idh, | 233 | testpeers[0].create_id_op = GNUNET_IDENTITY_create (testpeers[0].idh, |
233 | "client", | 234 | "client", |
234 | &identity_create_cb, | 235 | &identity_create_cb, |
235 | &testpeers[0]); | 236 | &testpeers[0]); |
236 | testpeers[1].create_id_op = GNUNET_IDENTITY_create(testpeers[1].idh, | 237 | testpeers[1].create_id_op = GNUNET_IDENTITY_create (testpeers[1].idh, |
237 | "toberevoked", | 238 | "toberevoked", |
238 | &identity_create_cb, | 239 | &identity_create_cb, |
239 | &testpeers[1]); | 240 | &testpeers[1]); |
240 | } | 241 | } |
241 | 242 | ||
242 | 243 | ||
243 | static void * | 244 | static void * |
244 | identity_connect_adapter(void *cls, | 245 | identity_connect_adapter (void *cls, |
245 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 246 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
246 | { | 247 | { |
247 | struct TestPeer *me = cls; | 248 | struct TestPeer *me = cls; |
248 | 249 | ||
249 | me->cfg = cfg; | 250 | me->cfg = cfg; |
250 | me->idh = GNUNET_IDENTITY_connect(cfg, NULL, NULL); | 251 | me->idh = GNUNET_IDENTITY_connect (cfg, NULL, NULL); |
251 | if (NULL == me->idh) | 252 | if (NULL == me->idh) |
252 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create IDENTITY handle \n"); | 253 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create IDENTITY handle \n"); |
253 | return me->idh; | 254 | return me->idh; |
254 | } | 255 | } |
255 | 256 | ||
256 | 257 | ||
257 | static void | 258 | static void |
258 | identity_disconnect_adapter(void *cls, void *op_result) | 259 | identity_disconnect_adapter (void *cls, void *op_result) |
259 | { | 260 | { |
260 | struct TestPeer *me = cls; | 261 | struct TestPeer *me = cls; |
261 | 262 | ||
262 | GNUNET_IDENTITY_disconnect(me->idh); | 263 | GNUNET_IDENTITY_disconnect (me->idh); |
263 | me->idh = NULL; | 264 | me->idh = NULL; |
264 | } | 265 | } |
265 | 266 | ||
266 | 267 | ||
267 | static void * | 268 | static void * |
268 | connect_cb(void *cls, | 269 | connect_cb (void *cls, |
269 | const struct GNUNET_PeerIdentity *peer, | 270 | const struct GNUNET_PeerIdentity *peer, |
270 | struct GNUNET_MQ_Handle *mq) | 271 | struct GNUNET_MQ_Handle *mq) |
271 | { | 272 | { |
272 | static int connects = 0; | 273 | static int connects = 0; |
273 | 274 | ||
274 | connects++; | 275 | connects++; |
275 | if (NUM_TEST_PEERS * NUM_TEST_PEERS == connects) | 276 | if (NUM_TEST_PEERS * NUM_TEST_PEERS == connects) |
276 | { | 277 | { |
277 | fprintf(stderr, "All peers connected @ CORE ...\n"); | 278 | fprintf (stderr, "All peers connected @ CORE ...\n"); |
278 | 279 | ||
279 | /* Connect to identity service */ | 280 | /* Connect to identity service */ |
280 | testpeers[0].identity_op = | 281 | testpeers[0].identity_op = |
281 | GNUNET_TESTBED_service_connect(NULL, | 282 | GNUNET_TESTBED_service_connect (NULL, |
282 | testpeers[0].p, | 283 | testpeers[0].p, |
283 | "identity", | 284 | "identity", |
284 | &identity_completion_cb, | 285 | &identity_completion_cb, |
285 | NULL, | 286 | NULL, |
286 | &identity_connect_adapter, | 287 | &identity_connect_adapter, |
287 | &identity_disconnect_adapter, | 288 | &identity_disconnect_adapter, |
288 | &testpeers[0]); | 289 | &testpeers[0]); |
289 | testpeers[1].identity_op = | 290 | testpeers[1].identity_op = |
290 | GNUNET_TESTBED_service_connect(NULL, | 291 | GNUNET_TESTBED_service_connect (NULL, |
291 | testpeers[1].p, | 292 | testpeers[1].p, |
292 | "identity", | 293 | "identity", |
293 | *identity_completion_cb, | 294 | *identity_completion_cb, |
294 | NULL, | 295 | NULL, |
295 | &identity_connect_adapter, | 296 | &identity_connect_adapter, |
296 | &identity_disconnect_adapter, | 297 | &identity_disconnect_adapter, |
297 | &testpeers[1]); | 298 | &testpeers[1]); |
298 | } | 299 | } |
299 | return NULL; | 300 | return NULL; |
300 | } | 301 | } |
301 | 302 | ||
302 | 303 | ||
303 | static void | 304 | static void |
304 | core_completion_cb(void *cls, | 305 | core_completion_cb (void *cls, |
305 | struct GNUNET_TESTBED_Operation *op, | 306 | struct GNUNET_TESTBED_Operation *op, |
306 | void *ca_result, | 307 | void *ca_result, |
307 | const char *emsg) | 308 | const char *emsg) |
308 | { | 309 | { |
309 | static int completed = 0; | 310 | static int completed = 0; |
310 | 311 | ||
311 | completed++; | 312 | completed++; |
312 | if (NUM_TEST_PEERS == completed) | 313 | if (NUM_TEST_PEERS == completed) |
313 | { | 314 | { |
314 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to CORE\n"); | 315 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connected to CORE\n"); |
315 | } | 316 | } |
316 | } | 317 | } |
317 | 318 | ||
318 | 319 | ||
319 | static void * | 320 | static void * |
320 | core_connect_adapter(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | 321 | core_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) |
321 | { | 322 | { |
322 | struct TestPeer *me = cls; | 323 | struct TestPeer *me = cls; |
323 | 324 | ||
324 | me->cfg = cfg; | 325 | me->cfg = cfg; |
325 | me->ch = GNUNET_CORE_connect(cfg, me, NULL, &connect_cb, NULL, NULL); | 326 | me->ch = GNUNET_CORE_connect (cfg, me, NULL, &connect_cb, NULL, NULL); |
326 | if (NULL == me->ch) | 327 | if (NULL == me->ch) |
327 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create CORE handle \n"); | 328 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create CORE handle \n"); |
328 | return me->ch; | 329 | return me->ch; |
329 | } | 330 | } |
330 | 331 | ||
331 | 332 | ||
332 | static void | 333 | static void |
333 | core_disconnect_adapter(void *cls, void *op_result) | 334 | core_disconnect_adapter (void *cls, void *op_result) |
334 | { | 335 | { |
335 | struct TestPeer *me = cls; | 336 | struct TestPeer *me = cls; |
336 | 337 | ||
337 | GNUNET_CORE_disconnect(me->ch); | 338 | GNUNET_CORE_disconnect (me->ch); |
338 | me->ch = NULL; | 339 | me->ch = NULL; |
339 | } | 340 | } |
340 | 341 | ||
341 | 342 | ||
342 | static void | 343 | static void |
343 | test_connection(void *cls, | 344 | test_connection (void *cls, |
344 | struct GNUNET_TESTBED_RunHandle *h, | 345 | struct GNUNET_TESTBED_RunHandle *h, |
345 | unsigned int num_peers, | 346 | unsigned int num_peers, |
346 | struct GNUNET_TESTBED_Peer **peers, | 347 | struct GNUNET_TESTBED_Peer **peers, |
347 | unsigned int links_succeeded, | 348 | unsigned int links_succeeded, |
348 | unsigned int links_failed) | 349 | unsigned int links_failed) |
349 | { | 350 | { |
350 | unsigned int c; | 351 | unsigned int c; |
351 | 352 | ||
352 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); | 353 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); |
353 | if (NUM_TEST_PEERS != num_peers) | 354 | if (NUM_TEST_PEERS != num_peers) |
354 | { | 355 | { |
355 | ok = 4; | 356 | ok = 4; |
356 | fprintf(stderr, | 357 | fprintf (stderr, |
357 | "Only %u out of %u peers were started ...\n", | 358 | "Only %u out of %u peers were started ...\n", |
358 | num_peers, | 359 | num_peers, |
359 | NUM_TEST_PEERS); | 360 | NUM_TEST_PEERS); |
360 | GNUNET_SCHEDULER_shutdown(); | 361 | GNUNET_SCHEDULER_shutdown (); |
361 | return; | 362 | return; |
362 | } | 363 | } |
363 | /* We are generating a CLIQUE */ | 364 | /* We are generating a CLIQUE */ |
364 | if (NUM_TEST_PEERS * (NUM_TEST_PEERS - 1) == links_succeeded) | 365 | if (NUM_TEST_PEERS * (NUM_TEST_PEERS - 1) == links_succeeded) |
366 | { | ||
367 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
368 | "Testbed connected peers, initializing test\n"); | ||
369 | for (c = 0; c < num_peers; c++) | ||
365 | { | 370 | { |
366 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 371 | testpeers[c].p = peers[c]; |
367 | "Testbed connected peers, initializing test\n"); | 372 | testpeers[c].core_op = |
368 | for (c = 0; c < num_peers; c++) | 373 | GNUNET_TESTBED_service_connect (NULL, |
369 | { | 374 | testpeers[c].p, |
370 | testpeers[c].p = peers[c]; | 375 | "core", |
371 | testpeers[c].core_op = | 376 | &core_completion_cb, |
372 | GNUNET_TESTBED_service_connect(NULL, | 377 | NULL, |
373 | testpeers[c].p, | 378 | &core_connect_adapter, |
374 | "core", | 379 | &core_disconnect_adapter, |
375 | &core_completion_cb, | 380 | &testpeers[c]); |
376 | NULL, | ||
377 | &core_connect_adapter, | ||
378 | &core_disconnect_adapter, | ||
379 | &testpeers[c]); | ||
380 | } | ||
381 | } | 381 | } |
382 | } | ||
382 | else | 383 | else |
383 | { | 384 | { |
384 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Testbed failed to connect peers\n"); | 385 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testbed failed to connect peers\n"); |
385 | ok = 5; | 386 | ok = 5; |
386 | GNUNET_SCHEDULER_shutdown(); | 387 | GNUNET_SCHEDULER_shutdown (); |
387 | return; | 388 | return; |
388 | } | 389 | } |
389 | } | 390 | } |
390 | 391 | ||
391 | 392 | ||
392 | int | 393 | int |
393 | main(int argc, char *argv[]) | 394 | main (int argc, char *argv[]) |
394 | { | 395 | { |
395 | ok = 1; | 396 | ok = 1; |
396 | /* Connecting initial topology */ | 397 | /* Connecting initial topology */ |
397 | (void)GNUNET_TESTBED_test_run("test-revocation", | 398 | (void) GNUNET_TESTBED_test_run ("test-revocation", |
398 | "test_revocation.conf", | 399 | "test_revocation.conf", |
399 | NUM_TEST_PEERS, | 400 | NUM_TEST_PEERS, |
400 | 0, | 401 | 0, |
401 | NULL, | 402 | NULL, |
402 | NULL, | 403 | NULL, |
403 | &test_connection, | 404 | &test_connection, |
404 | NULL); | 405 | NULL); |
405 | return ok; | 406 | return ok; |
406 | } | 407 | } |
407 | 408 | ||