}
+/**
+ * Initializes a fresh PoW computation
+ *
+ * @param key the key to calculate the PoW for.
+ * @param epochs the number of epochs for which the PoW must be valid.
+ * @param difficulty the base difficulty of the PoW
+ * @return a handle for use in PoW rounds
+ */
struct GNUNET_REVOCATION_PowCalculationHandle*
GNUNET_REVOCATION_pow_init (const struct GNUNET_CRYPTO_EcdsaPublicKey *key,
int epochs,
unsigned int difficulty)
{
- struct GNUNET_REVOCATION_PowCalculationHandle*pc;
+ struct GNUNET_REVOCATION_PowCalculationHandle *pc;
struct GNUNET_TIME_Absolute ts = GNUNET_TIME_absolute_get ();
pc = GNUNET_new (struct GNUNET_REVOCATION_PowCalculationHandle);
}
+/**
+ * Initializes PoW computation based on an existing PoW.
+ *
+ * @param pow the PoW to continue the calculations from.
+ * @param epochs the number of epochs for which the PoW must be valid.
+ * @param difficulty the base difficulty of the PoW
+ * @return a handle for use in PoW rounds
+ */
+struct GNUNET_REVOCATION_PowCalculationHandle*
+GNUNET_REVOCATION_pow_init2 (const struct GNUNET_REVOCATION_Pow *pow,
+ int epochs,
+ unsigned int difficulty)
+{
+ struct GNUNET_REVOCATION_PowCalculationHandle *pc;
+
+ pc = GNUNET_new (struct GNUNET_REVOCATION_PowCalculationHandle);
+ pc->pow.key = pow->key;
+ pc->pow.timestamp = pow->timestamp;
+ pc->current_pow = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
+ UINT64_MAX);
+ pc->difficulty = difficulty;
+ pc->epochs = epochs;
+ return pc;
+}
+
+
+
/**
* Calculate a key revocation valid for broadcasting for a number
* of epochs.
}
+/**
+ * Return the curren PoW state from the calculation
+ *
+ * @param pc the calculation to get it from
+ * @return a pointer to the PoW
+ */
const struct GNUNET_REVOCATION_Pow*
GNUNET_REVOCATION_pow_get (const struct
GNUNET_REVOCATION_PowCalculationHandle *pc)
{
- return calculate_score (pc) >= pc->difficulty + pc->epochs ? &pc->pow :
- NULL;
+ return &pc->pow;
}
+/**
+ * Cleanup a PoW calculation
+ *
+ * @param pc the calculation to clean up
+ */
void
GNUNET_REVOCATION_pow_cleanup (struct
GNUNET_REVOCATION_PowCalculationHandle *pc)