aboutsummaryrefslogtreecommitdiff
path: root/src/revocation
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2020-04-20 07:48:19 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2020-04-20 07:48:19 +0200
commit196a465c2254c224055b71a5bdb3697e7a468801 (patch)
treee6ab30ab3458ceb77bca7a54f995a604de540f7c /src/revocation
parent2408dd18af486517a484544ebf468e5790e7ce05 (diff)
downloadgnunet-196a465c2254c224055b71a5bdb3697e7a468801.tar.gz
gnunet-196a465c2254c224055b71a5bdb3697e7a468801.zip
more comments, allow to pick up pow later
Diffstat (limited to 'src/revocation')
-rw-r--r--src/revocation/gnunet-revocation.c57
-rw-r--r--src/revocation/revocation_api.c51
2 files changed, 87 insertions, 21 deletions
diff --git a/src/revocation/gnunet-revocation.c b/src/revocation/gnunet-revocation.c
index 16f62de9d..5566162f4 100644
--- a/src/revocation/gnunet-revocation.c
+++ b/src/revocation/gnunet-revocation.c
@@ -28,6 +28,10 @@
28#include "gnunet_revocation_service.h" 28#include "gnunet_revocation_service.h"
29#include "gnunet_identity_service.h" 29#include "gnunet_identity_service.h"
30 30
31/**
32 * Pow passes
33 */
34static unsigned int pow_passes = 1;
31 35
32/** 36/**
33 * Final status code. 37 * Final status code.
@@ -93,6 +97,7 @@ static struct GNUNET_SCHEDULER_Task *pow_task;
93static void 97static void
94do_shutdown (void *cls) 98do_shutdown (void *cls)
95{ 99{
100 fprintf (stderr, "%s", _ ("Shutting down...\n"));
96 if (NULL != el) 101 if (NULL != el)
97 { 102 {
98 GNUNET_IDENTITY_ego_lookup_cancel (el); 103 GNUNET_IDENTITY_ego_lookup_cancel (el);
@@ -220,8 +225,6 @@ struct RevocationData
220static void 225static void
221perform_revocation (const struct GNUNET_REVOCATION_Pow *pow) 226perform_revocation (const struct GNUNET_REVOCATION_Pow *pow)
222{ 227{
223 struct GNUNET_TIME_Absolute ts;
224
225 h = GNUNET_REVOCATION_revoke (cfg, 228 h = GNUNET_REVOCATION_revoke (cfg,
226 pow, 229 pow,
227 &print_revocation_result, 230 &print_revocation_result,
@@ -239,10 +242,10 @@ static void
239sync_pow (const struct GNUNET_REVOCATION_Pow *pow) 242sync_pow (const struct GNUNET_REVOCATION_Pow *pow)
240{ 243{
241 if ((NULL != filename) && 244 if ((NULL != filename) &&
242 (sizeof(struct GNUNET_REVOCATION_Pow) == 245 (sizeof(struct GNUNET_REVOCATION_Pow) !=
243 GNUNET_DISK_fn_write (filename, 246 GNUNET_DISK_fn_write (filename,
244 &pow, 247 pow,
245 sizeof(pow), 248 sizeof(struct GNUNET_REVOCATION_Pow),
246 GNUNET_DISK_PERM_USER_READ 249 GNUNET_DISK_PERM_USER_READ
247 | GNUNET_DISK_PERM_USER_WRITE))) 250 | GNUNET_DISK_PERM_USER_WRITE)))
248 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); 251 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename);
@@ -258,7 +261,8 @@ static void
258calculate_pow_shutdown (void *cls) 261calculate_pow_shutdown (void *cls)
259{ 262{
260 struct GNUNET_REVOCATION_PowCalculationHandle *ph = cls; 263 struct GNUNET_REVOCATION_PowCalculationHandle *ph = cls;
261 264 fprintf (stderr, "%s", _ ("Cancelling calculation.\n"));
265 sync_pow (GNUNET_REVOCATION_pow_get (ph));
262 if (NULL != pow_task) 266 if (NULL != pow_task)
263 { 267 {
264 GNUNET_SCHEDULER_cancel (pow_task); 268 GNUNET_SCHEDULER_cancel (pow_task);
@@ -280,8 +284,8 @@ calculate_pow (void *cls)
280 284
281 /* store temporary results */ 285 /* store temporary results */
282 pow_task = NULL; 286 pow_task = NULL;
283 // if (0 == (rd->pow % 128)) 287 if (0 == (pow_passes % 128))
284 // sync_rd (rd); 288 sync_pow (GNUNET_REVOCATION_pow_get(ph));
285 /* actually do POW calculation */ 289 /* actually do POW calculation */
286 if (GNUNET_OK == GNUNET_REVOCATION_pow_round (ph)) 290 if (GNUNET_OK == GNUNET_REVOCATION_pow_round (ph))
287 { 291 {
@@ -309,7 +313,19 @@ calculate_pow (void *cls)
309 } 313 }
310 return; 314 return;
311 } 315 }
312 pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, ph); 316 pow_passes++;
317 /**
318 * Otherwise CTRL-C does not work
319 */
320 if (0 == pow_passes % 128)
321 pow_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
322 &calculate_pow,
323 ph);
324 else
325 pow_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
326 &calculate_pow,
327 ph);
328
313} 329}
314 330
315 331
@@ -324,6 +340,7 @@ ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
324{ 340{
325 struct GNUNET_REVOCATION_Pow *pow; 341 struct GNUNET_REVOCATION_Pow *pow;
326 struct GNUNET_CRYPTO_EcdsaPublicKey key; 342 struct GNUNET_CRYPTO_EcdsaPublicKey key;
343 struct GNUNET_REVOCATION_PowCalculationHandle *ph = NULL;
327 344
328 el = NULL; 345 el = NULL;
329 if (NULL == ego) 346 if (NULL == ego)
@@ -360,20 +377,24 @@ ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
360 GNUNET_free (pow); 377 GNUNET_free (pow);
361 return; 378 return;
362 } 379 }
380 /**
381 * Certificate not yet ready
382 */
363 fprintf (stderr, 383 fprintf (stderr,
364 _ ("Error: revocation certificate in `%s' invalid\n"), 384 "%s",
365 filename); 385 _("Continuing calculation where left off...\n"));
386 ph = GNUNET_REVOCATION_pow_init2 (pow,
387 1, /* Epochs */
388 matching_bits);
366 GNUNET_free (pow); 389 GNUNET_free (pow);
367 return;
368 } 390 }
369 fprintf (stderr, 391 fprintf (stderr,
370 "%s", 392 "%s",
371 _ ("Revocation certificate not ready, calculating proof of work\n")); 393 _ ("Revocation certificate not ready, calculating proof of work\n"));
372 GNUNET_free (pow); 394 if (NULL == ph)
373 struct GNUNET_REVOCATION_PowCalculationHandle *ph; 395 ph = GNUNET_REVOCATION_pow_init (&key,
374 ph = GNUNET_REVOCATION_pow_init (&key, 396 1, /* Epochs */
375 1, /* Epochs */ 397 matching_bits);
376 matching_bits);
377 pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, ph); 398 pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, ph);
378 GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, ph); 399 GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, ph);
379} 400}
@@ -456,7 +477,7 @@ run (void *cls,
456 (unsigned int) matching_bits)) 477 (unsigned int) matching_bits))
457 { 478 {
458 struct GNUNET_REVOCATION_PowCalculationHandle *ph; 479 struct GNUNET_REVOCATION_PowCalculationHandle *ph;
459 ph = GNUNET_REVOCATION_pow_init (&pk, 480 ph = GNUNET_REVOCATION_pow_init2 (&pow,
460 1, /* Epochs */ 481 1, /* Epochs */
461 matching_bits); 482 matching_bits);
462 483
diff --git a/src/revocation/revocation_api.c b/src/revocation/revocation_api.c
index 667ed4ec1..565ce9d0d 100644
--- a/src/revocation/revocation_api.c
+++ b/src/revocation/revocation_api.c
@@ -467,12 +467,20 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_Pow *pow,
467} 467}
468 468
469 469
470/**
471 * Initializes a fresh PoW computation
472 *
473 * @param key the key to calculate the PoW for.
474 * @param epochs the number of epochs for which the PoW must be valid.
475 * @param difficulty the base difficulty of the PoW
476 * @return a handle for use in PoW rounds
477 */
470struct GNUNET_REVOCATION_PowCalculationHandle* 478struct GNUNET_REVOCATION_PowCalculationHandle*
471GNUNET_REVOCATION_pow_init (const struct GNUNET_CRYPTO_EcdsaPublicKey *key, 479GNUNET_REVOCATION_pow_init (const struct GNUNET_CRYPTO_EcdsaPublicKey *key,
472 int epochs, 480 int epochs,
473 unsigned int difficulty) 481 unsigned int difficulty)
474{ 482{
475 struct GNUNET_REVOCATION_PowCalculationHandle*pc; 483 struct GNUNET_REVOCATION_PowCalculationHandle *pc;
476 struct GNUNET_TIME_Absolute ts = GNUNET_TIME_absolute_get (); 484 struct GNUNET_TIME_Absolute ts = GNUNET_TIME_absolute_get ();
477 485
478 pc = GNUNET_new (struct GNUNET_REVOCATION_PowCalculationHandle); 486 pc = GNUNET_new (struct GNUNET_REVOCATION_PowCalculationHandle);
@@ -487,6 +495,33 @@ GNUNET_REVOCATION_pow_init (const struct GNUNET_CRYPTO_EcdsaPublicKey *key,
487 495
488 496
489/** 497/**
498 * Initializes PoW computation based on an existing PoW.
499 *
500 * @param pow the PoW to continue the calculations from.
501 * @param epochs the number of epochs for which the PoW must be valid.
502 * @param difficulty the base difficulty of the PoW
503 * @return a handle for use in PoW rounds
504 */
505struct GNUNET_REVOCATION_PowCalculationHandle*
506GNUNET_REVOCATION_pow_init2 (const struct GNUNET_REVOCATION_Pow *pow,
507 int epochs,
508 unsigned int difficulty)
509{
510 struct GNUNET_REVOCATION_PowCalculationHandle *pc;
511
512 pc = GNUNET_new (struct GNUNET_REVOCATION_PowCalculationHandle);
513 pc->pow.key = pow->key;
514 pc->pow.timestamp = pow->timestamp;
515 pc->current_pow = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
516 UINT64_MAX);
517 pc->difficulty = difficulty;
518 pc->epochs = epochs;
519 return pc;
520}
521
522
523
524/**
490 * Calculate a key revocation valid for broadcasting for a number 525 * Calculate a key revocation valid for broadcasting for a number
491 * of epochs. 526 * of epochs.
492 * 527 *
@@ -544,15 +579,25 @@ GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc)
544} 579}
545 580
546 581
582/**
583 * Return the curren PoW state from the calculation
584 *
585 * @param pc the calculation to get it from
586 * @return a pointer to the PoW
587 */
547const struct GNUNET_REVOCATION_Pow* 588const struct GNUNET_REVOCATION_Pow*
548GNUNET_REVOCATION_pow_get (const struct 589GNUNET_REVOCATION_pow_get (const struct
549 GNUNET_REVOCATION_PowCalculationHandle *pc) 590 GNUNET_REVOCATION_PowCalculationHandle *pc)
550{ 591{
551 return calculate_score (pc) >= pc->difficulty + pc->epochs ? &pc->pow : 592 return &pc->pow;
552 NULL;
553} 593}
554 594
555 595
596/**
597 * Cleanup a PoW calculation
598 *
599 * @param pc the calculation to clean up
600 */
556void 601void
557GNUNET_REVOCATION_pow_cleanup (struct 602GNUNET_REVOCATION_pow_cleanup (struct
558 GNUNET_REVOCATION_PowCalculationHandle *pc) 603 GNUNET_REVOCATION_PowCalculationHandle *pc)