diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-10-06 11:16:26 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-10-06 11:16:26 +0000 |
commit | 2ebfdbbe8af9eef26ad1a2776a20227715560558 (patch) | |
tree | 9ce4e1f88ab32a156653dc6d74a9c02a82c77ee1 /src/revocation | |
parent | b0f956058355ea7e96a7d3022b08dd951acd99a5 (diff) | |
download | gnunet-2ebfdbbe8af9eef26ad1a2776a20227715560558.tar.gz gnunet-2ebfdbbe8af9eef26ad1a2776a20227715560558.zip |
-load revocations from disk, misc doxygen/style fixes
Diffstat (limited to 'src/revocation')
-rw-r--r-- | src/revocation/gnunet-service-revocation.c | 77 |
1 files changed, 76 insertions, 1 deletions
diff --git a/src/revocation/gnunet-service-revocation.c b/src/revocation/gnunet-service-revocation.c index dbf8817f8..a410f7b4e 100644 --- a/src/revocation/gnunet-service-revocation.c +++ b/src/revocation/gnunet-service-revocation.c | |||
@@ -31,7 +31,6 @@ | |||
31 | * peers that connect. | 31 | * peers that connect. |
32 | * | 32 | * |
33 | * TODO: | 33 | * TODO: |
34 | * - load revocations from disk | ||
35 | * - store revocations to disk | 34 | * - store revocations to disk |
36 | * - handle p2p revocations | 35 | * - handle p2p revocations |
37 | * - handle p2p connect (trigger SET union) | 36 | * - handle p2p connect (trigger SET union) |
@@ -122,6 +121,11 @@ static struct GNUNET_SERVER_Handle *srv; | |||
122 | static struct GNUNET_SERVER_NotificationContext *nc; | 121 | static struct GNUNET_SERVER_NotificationContext *nc; |
123 | 122 | ||
124 | /** | 123 | /** |
124 | * File handle for the revocation database. | ||
125 | */ | ||
126 | static struct GNUNET_DISK_FileHandle *revocation_db; | ||
127 | |||
128 | /** | ||
125 | * Amount of work required (W-bit collisions) for REVOCATION proofs, in collision-bits. | 129 | * Amount of work required (W-bit collisions) for REVOCATION proofs, in collision-bits. |
126 | */ | 130 | */ |
127 | static unsigned long long revocation_work_required; | 131 | static unsigned long long revocation_work_required; |
@@ -401,6 +405,11 @@ shutdown_task (void *cls, | |||
401 | GNUNET_SERVER_notification_context_destroy (nc); | 405 | GNUNET_SERVER_notification_context_destroy (nc); |
402 | nc = NULL; | 406 | nc = NULL; |
403 | } | 407 | } |
408 | if (NULL != revocation_db) | ||
409 | { | ||
410 | GNUNET_DISK_file_close (revocation_db); | ||
411 | revocation_db = NULL; | ||
412 | } | ||
404 | GNUNET_CONTAINER_multihashmap_iterate (revocation_map, | 413 | GNUNET_CONTAINER_multihashmap_iterate (revocation_map, |
405 | &free_entry, | 414 | &free_entry, |
406 | NULL); | 415 | NULL); |
@@ -453,7 +462,23 @@ run (void *cls, | |||
453 | sizeof (struct RevokeMessage)}, | 462 | sizeof (struct RevokeMessage)}, |
454 | {NULL, 0, 0} | 463 | {NULL, 0, 0} |
455 | }; | 464 | }; |
465 | char *fn; | ||
466 | uint64_t left; | ||
467 | struct RevokeMessage *rm; | ||
468 | struct GNUNET_HashCode hc; | ||
456 | 469 | ||
470 | if (GNUNET_OK != | ||
471 | GNUNET_CONFIGURATION_get_value_filename (c, | ||
472 | "REVOCATION", | ||
473 | "DATABASE", | ||
474 | &fn)) | ||
475 | { | ||
476 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | ||
477 | "REVOCATION", | ||
478 | "DATABASE"); | ||
479 | GNUNET_SCHEDULER_shutdown (); | ||
480 | return; | ||
481 | } | ||
457 | cfg = c; | 482 | cfg = c; |
458 | srv = server; | 483 | srv = server; |
459 | revocation_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_NO); | 484 | revocation_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_NO); |
@@ -466,6 +491,7 @@ run (void *cls, | |||
466 | "REVOCATION", | 491 | "REVOCATION", |
467 | "WORKBITS"); | 492 | "WORKBITS"); |
468 | GNUNET_SCHEDULER_shutdown (); | 493 | GNUNET_SCHEDULER_shutdown (); |
494 | GNUNET_free (fn); | ||
469 | return; | 495 | return; |
470 | } | 496 | } |
471 | if (revocation_work_required >= sizeof (struct GNUNET_HashCode) * 8) | 497 | if (revocation_work_required >= sizeof (struct GNUNET_HashCode) * 8) |
@@ -475,10 +501,59 @@ run (void *cls, | |||
475 | "WORKBITS", | 501 | "WORKBITS", |
476 | _("Value is too large.\n")); | 502 | _("Value is too large.\n")); |
477 | GNUNET_SCHEDULER_shutdown (); | 503 | GNUNET_SCHEDULER_shutdown (); |
504 | GNUNET_free (fn); | ||
478 | return; | 505 | return; |
479 | } | 506 | } |
480 | revocation_set = GNUNET_SET_create (cfg, | 507 | revocation_set = GNUNET_SET_create (cfg, |
481 | GNUNET_SET_OPERATION_UNION); | 508 | GNUNET_SET_OPERATION_UNION); |
509 | |||
510 | revocation_db = GNUNET_DISK_file_open (fn, | ||
511 | GNUNET_DISK_OPEN_READWRITE | | ||
512 | GNUNET_DISK_OPEN_CREATE, | ||
513 | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE | | ||
514 | GNUNET_DISK_PERM_GROUP_READ | | ||
515 | GNUNET_DISK_PERM_OTHER_READ); | ||
516 | if (NULL == revocation_db) | ||
517 | { | ||
518 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, | ||
519 | "REVOCATION", | ||
520 | "DATABASE", | ||
521 | _("Could not open revocation database file!")); | ||
522 | GNUNET_SCHEDULER_shutdown (); | ||
523 | GNUNET_free (fn); | ||
524 | return; | ||
525 | } | ||
526 | if (GNUNET_OK != | ||
527 | GNUNET_DISK_file_size (fn, &left, GNUNET_YES, GNUNET_YES)) | ||
528 | left = 0; | ||
529 | while (left > sizeof (struct RevokeMessage)) | ||
530 | { | ||
531 | rm = GNUNET_new (struct RevokeMessage); | ||
532 | if (sizeof (struct RevokeMessage) != | ||
533 | GNUNET_DISK_file_read (revocation_db, | ||
534 | rm, | ||
535 | sizeof (struct RevokeMessage))) | ||
536 | { | ||
537 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | ||
538 | "read", | ||
539 | fn); | ||
540 | GNUNET_free (rm); | ||
541 | GNUNET_SCHEDULER_shutdown (); | ||
542 | GNUNET_free (fn); | ||
543 | return; | ||
544 | } | ||
545 | GNUNET_break (0 == ntohl (rm->reserved)); | ||
546 | GNUNET_CRYPTO_hash (&rm->public_key, | ||
547 | sizeof (struct GNUNET_CRYPTO_EccPublicSignKey), | ||
548 | &hc); | ||
549 | GNUNET_break (GNUNET_OK == | ||
550 | GNUNET_CONTAINER_multihashmap_put (revocation_map, | ||
551 | &hc, | ||
552 | rm, | ||
553 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
554 | } | ||
555 | GNUNET_free (fn); | ||
556 | |||
482 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, | 557 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, |
483 | NULL); | 558 | NULL); |
484 | peers = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO); | 559 | peers = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO); |