aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2020-05-18 08:59:06 +0200
committerMartin Schanzenbach <mschanzenbach@posteo.de>2020-05-18 08:59:06 +0200
commit22343a741e14ea9d5e6ac6ed30af87c3d4a291e1 (patch)
treec11b979bb5325bdd55811c5ef96f79f53412a0b4
parent3be730446ba439170a67798dca8c634625c82cea (diff)
downloadgnunet-22343a741e14ea9d5e6ac6ed30af87c3d4a291e1.tar.gz
gnunet-22343a741e14ea9d5e6ac6ed30af87c3d4a291e1.zip
add smi pow values
-rw-r--r--src/revocation/revocation_api.c35
1 files changed, 26 insertions, 9 deletions
diff --git a/src/revocation/revocation_api.c b/src/revocation/revocation_api.c
index 12cb63c57..721c40c2a 100644
--- a/src/revocation/revocation_api.c
+++ b/src/revocation/revocation_api.c
@@ -467,15 +467,12 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_PowP *pow,
467 } 467 }
468 468
469 /** 469 /**
470 * First, check if any duplicates are in the PoW set 470 * First, check if PoW set is strictly monotically increasing
471 */ 471 */
472 for (unsigned int i = 0; i < POW_COUNT; i++) 472 for (unsigned int i = 0; i < POW_COUNT-1; i++)
473 { 473 {
474 for (unsigned int j = i + 1; j < POW_COUNT; j++) 474 if (GNUNET_ntohll (pow->pow[i]) >= GNUNET_ntohll (pow->pow[i+1]))
475 { 475 return GNUNET_NO;
476 if (pow->pow[i] == pow->pow[j])
477 return GNUNET_NO;
478 }
479 } 476 }
480 GNUNET_memcpy (&buf[sizeof(uint64_t)], 477 GNUNET_memcpy (&buf[sizeof(uint64_t)],
481 &pow->timestamp, 478 &pow->timestamp,
@@ -590,6 +587,18 @@ GNUNET_REVOCATION_pow_start (struct GNUNET_REVOCATION_PowP *pow,
590 return pc; 587 return pc;
591} 588}
592 589
590/**
591 * Comparison function for quicksort
592 *
593 * @param a left element
594 * @param b right element
595 * @return a-b
596 */
597static int
598cmp_pow_value (const void *a, const void *b)
599{
600 return ( GNUNET_ntohll(*(uint64_t*)a) - GNUNET_ntohll(*(uint64_t*)b));
601}
593 602
594/** 603/**
595 * Calculate a key revocation valid for broadcasting for a number 604 * Calculate a key revocation valid for broadcasting for a number
@@ -609,6 +618,7 @@ GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc)
609 + sizeof (uint64_t)] GNUNET_ALIGN; 618 + sizeof (uint64_t)] GNUNET_ALIGN;
610 struct GNUNET_HashCode result; 619 struct GNUNET_HashCode result;
611 unsigned int zeros; 620 unsigned int zeros;
621 int ret;
612 622
613 pc->current_pow++; 623 pc->current_pow++;
614 624
@@ -641,11 +651,18 @@ GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc)
641 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 651 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
642 "New best score %u with %" PRIu64 " (#%u)\n", 652 "New best score %u with %" PRIu64 " (#%u)\n",
643 zeros, pc->current_pow, i); 653 zeros, pc->current_pow, i);
654
644 break; 655 break;
645 } 656 }
646 } 657 }
647 return calculate_score (pc) >= pc->difficulty + pc->epochs ? GNUNET_YES : 658 ret = calculate_score (pc) >= pc->difficulty + pc->epochs ? GNUNET_YES :
648 GNUNET_NO; 659 GNUNET_NO;
660 if (GNUNET_YES == ret)
661 {
662 /* Sort POWs) */
663 qsort (pc->pow->pow, POW_COUNT, sizeof (uint64_t), &cmp_pow_value);
664 }
665 return ret;
649} 666}
650 667
651 668