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