more comments, allow to pick up pow later
[oweals/gnunet.git] / src / revocation / revocation_api.c
index 667ed4ec104e0170bb8dcda230d7def54f326ea9..565ce9d0d517c76bc06b7d534b097e3c82233669 100644 (file)
@@ -467,12 +467,20 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_Pow *pow,
 }
 
 
+/**
+ * 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);
@@ -486,6 +494,33 @@ GNUNET_REVOCATION_pow_init (const struct GNUNET_CRYPTO_EcdsaPublicKey *key,
 }
 
 
+/**
+ * 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.
@@ -544,15 +579,25 @@ GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc)
 }
 
 
+/**
+ * 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)