summaryrefslogtreecommitdiff
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)
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,
}
/**
- * First, check if any duplicates are in the PoW set
+ * First, check if PoW set is strictly monotically increasing
*/
- for (unsigned int i = 0; i < POW_COUNT; i++)
+ for (unsigned int i = 0; i < POW_COUNT-1; i++)
{
- for (unsigned int j = i + 1; j < POW_COUNT; j++)
- {
- if (pow->pow[i] == pow->pow[j])
- return GNUNET_NO;
- }
+ if (GNUNET_ntohll (pow->pow[i]) >= GNUNET_ntohll (pow->pow[i+1]))
+ return GNUNET_NO;
}
GNUNET_memcpy (&buf[sizeof(uint64_t)],
&pow->timestamp,
@@ -590,6 +587,18 @@ GNUNET_REVOCATION_pow_start (struct GNUNET_REVOCATION_PowP *pow,
return pc;
}
+/**
+ * Comparison function for quicksort
+ *
+ * @param a left element
+ * @param b right element
+ * @return a-b
+ */
+static int
+cmp_pow_value (const void *a, const void *b)
+{
+ return ( GNUNET_ntohll(*(uint64_t*)a) - GNUNET_ntohll(*(uint64_t*)b));
+}
/**
* Calculate a key revocation valid for broadcasting for a number
@@ -609,6 +618,7 @@ GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc)
+ sizeof (uint64_t)] GNUNET_ALIGN;
struct GNUNET_HashCode result;
unsigned int zeros;
+ int ret;
pc->current_pow++;
@@ -641,11 +651,18 @@ GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"New best score %u with %" PRIu64 " (#%u)\n",
zeros, pc->current_pow, i);
+
break;
}
}
- return calculate_score (pc) >= pc->difficulty + pc->epochs ? GNUNET_YES :
- GNUNET_NO;
+ ret = calculate_score (pc) >= pc->difficulty + pc->epochs ? GNUNET_YES :
+ GNUNET_NO;
+ if (GNUNET_YES == ret)
+ {
+ /* Sort POWs) */
+ qsort (pc->pow->pow, POW_COUNT, sizeof (uint64_t), &cmp_pow_value);
+ }
+ return ret;
}