diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2020-04-20 07:48:19 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2020-04-20 07:48:19 +0200 |
commit | 196a465c2254c224055b71a5bdb3697e7a468801 (patch) | |
tree | e6ab30ab3458ceb77bca7a54f995a604de540f7c /src/revocation/revocation_api.c | |
parent | 2408dd18af486517a484544ebf468e5790e7ce05 (diff) | |
download | gnunet-196a465c2254c224055b71a5bdb3697e7a468801.tar.gz gnunet-196a465c2254c224055b71a5bdb3697e7a468801.zip |
more comments, allow to pick up pow later
Diffstat (limited to 'src/revocation/revocation_api.c')
-rw-r--r-- | src/revocation/revocation_api.c | 51 |
1 files changed, 48 insertions, 3 deletions
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 | */ | ||
470 | struct GNUNET_REVOCATION_PowCalculationHandle* | 478 | struct GNUNET_REVOCATION_PowCalculationHandle* |
471 | GNUNET_REVOCATION_pow_init (const struct GNUNET_CRYPTO_EcdsaPublicKey *key, | 479 | GNUNET_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 | */ | ||
505 | struct GNUNET_REVOCATION_PowCalculationHandle* | ||
506 | GNUNET_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 | */ | ||
547 | const struct GNUNET_REVOCATION_Pow* | 588 | const struct GNUNET_REVOCATION_Pow* |
548 | GNUNET_REVOCATION_pow_get (const struct | 589 | GNUNET_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 | */ | ||
556 | void | 601 | void |
557 | GNUNET_REVOCATION_pow_cleanup (struct | 602 | GNUNET_REVOCATION_pow_cleanup (struct |
558 | GNUNET_REVOCATION_PowCalculationHandle *pc) | 603 | GNUNET_REVOCATION_PowCalculationHandle *pc) |