*/
#define POW_COUNT 32
+
+GNUNET_NETWORK_STRUCT_BEGIN
+
struct GNUNET_REVOCATION_Pow
{
/**
/**
* The TTL of this revocation (purely informational)
*/
- uint64_t ttl;
+ uint64_t ttl GNUNET_PACKED;
/**
* The PoWs
*/
- uint64_t pow[POW_COUNT];
+ uint64_t pow[POW_COUNT] GNUNET_PACKED;
/**
* The signature
struct GNUNET_CRYPTO_EcdsaPublicKey key;
};
+GNUNET_NETWORK_STRUCT_END
+
+
struct GNUNET_REVOCATION_PowCalculationHandle;
/**
unsigned int matching_bits);
+
+/**
+ * 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);
+/**
+ * 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);
+
+
/**
* Calculate a key revocation valid for broadcasting for a number
* of epochs.
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);
+/**
+ * Cleanup a PoW calculation
+ *
+ * @param pc the calculation to clean up
+ */
void
GNUNET_REVOCATION_pow_cleanup (struct
GNUNET_REVOCATION_PowCalculationHandle *pc);
#include "gnunet_revocation_service.h"
#include "gnunet_identity_service.h"
+/**
+ * Pow passes
+ */
+static unsigned int pow_passes = 1;
/**
* Final status code.
static void
do_shutdown (void *cls)
{
+ fprintf (stderr, "%s", _ ("Shutting down...\n"));
if (NULL != el)
{
GNUNET_IDENTITY_ego_lookup_cancel (el);
static void
perform_revocation (const struct GNUNET_REVOCATION_Pow *pow)
{
- struct GNUNET_TIME_Absolute ts;
-
h = GNUNET_REVOCATION_revoke (cfg,
pow,
&print_revocation_result,
sync_pow (const struct GNUNET_REVOCATION_Pow *pow)
{
if ((NULL != filename) &&
- (sizeof(struct GNUNET_REVOCATION_Pow) ==
+ (sizeof(struct GNUNET_REVOCATION_Pow) !=
GNUNET_DISK_fn_write (filename,
- &pow,
- sizeof(pow),
+ pow,
+ sizeof(struct GNUNET_REVOCATION_Pow),
GNUNET_DISK_PERM_USER_READ
| GNUNET_DISK_PERM_USER_WRITE)))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename);
calculate_pow_shutdown (void *cls)
{
struct GNUNET_REVOCATION_PowCalculationHandle *ph = cls;
-
+ fprintf (stderr, "%s", _ ("Cancelling calculation.\n"));
+ sync_pow (GNUNET_REVOCATION_pow_get (ph));
if (NULL != pow_task)
{
GNUNET_SCHEDULER_cancel (pow_task);
/* store temporary results */
pow_task = NULL;
- // if (0 == (rd->pow % 128))
- // sync_rd (rd);
+ if (0 == (pow_passes % 128))
+ sync_pow (GNUNET_REVOCATION_pow_get(ph));
/* actually do POW calculation */
if (GNUNET_OK == GNUNET_REVOCATION_pow_round (ph))
{
}
return;
}
- pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, ph);
+ pow_passes++;
+ /**
+ * Otherwise CTRL-C does not work
+ */
+ if (0 == pow_passes % 128)
+ pow_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
+ &calculate_pow,
+ ph);
+ else
+ pow_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
+ &calculate_pow,
+ ph);
+
}
{
struct GNUNET_REVOCATION_Pow *pow;
struct GNUNET_CRYPTO_EcdsaPublicKey key;
+ struct GNUNET_REVOCATION_PowCalculationHandle *ph = NULL;
el = NULL;
if (NULL == ego)
GNUNET_free (pow);
return;
}
+ /**
+ * Certificate not yet ready
+ */
fprintf (stderr,
- _ ("Error: revocation certificate in `%s' invalid\n"),
- filename);
+ "%s",
+ _("Continuing calculation where left off...\n"));
+ ph = GNUNET_REVOCATION_pow_init2 (pow,
+ 1, /* Epochs */
+ matching_bits);
GNUNET_free (pow);
- return;
}
fprintf (stderr,
"%s",
_ ("Revocation certificate not ready, calculating proof of work\n"));
- GNUNET_free (pow);
- struct GNUNET_REVOCATION_PowCalculationHandle *ph;
- ph = GNUNET_REVOCATION_pow_init (&key,
- 1, /* Epochs */
- matching_bits);
+ if (NULL == ph)
+ ph = GNUNET_REVOCATION_pow_init (&key,
+ 1, /* Epochs */
+ matching_bits);
pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, ph);
GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, ph);
}
(unsigned int) matching_bits))
{
struct GNUNET_REVOCATION_PowCalculationHandle *ph;
- ph = GNUNET_REVOCATION_pow_init (&pk,
+ ph = GNUNET_REVOCATION_pow_init2 (&pow,
1, /* Epochs */
matching_bits);
}
+/**
+ * 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)