aboutsummaryrefslogtreecommitdiff
path: root/src/revocation/gnunet-revocation.c
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2020-04-20 07:48:19 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2020-04-20 07:48:19 +0200
commit196a465c2254c224055b71a5bdb3697e7a468801 (patch)
treee6ab30ab3458ceb77bca7a54f995a604de540f7c /src/revocation/gnunet-revocation.c
parent2408dd18af486517a484544ebf468e5790e7ce05 (diff)
downloadgnunet-196a465c2254c224055b71a5bdb3697e7a468801.tar.gz
gnunet-196a465c2254c224055b71a5bdb3697e7a468801.zip
more comments, allow to pick up pow later
Diffstat (limited to 'src/revocation/gnunet-revocation.c')
-rw-r--r--src/revocation/gnunet-revocation.c57
1 files changed, 39 insertions, 18 deletions
diff --git a/src/revocation/gnunet-revocation.c b/src/revocation/gnunet-revocation.c
index 16f62de9d..5566162f4 100644
--- a/src/revocation/gnunet-revocation.c
+++ b/src/revocation/gnunet-revocation.c
@@ -28,6 +28,10 @@
28#include "gnunet_revocation_service.h" 28#include "gnunet_revocation_service.h"
29#include "gnunet_identity_service.h" 29#include "gnunet_identity_service.h"
30 30
31/**
32 * Pow passes
33 */
34static unsigned int pow_passes = 1;
31 35
32/** 36/**
33 * Final status code. 37 * Final status code.
@@ -93,6 +97,7 @@ static struct GNUNET_SCHEDULER_Task *pow_task;
93static void 97static void
94do_shutdown (void *cls) 98do_shutdown (void *cls)
95{ 99{
100 fprintf (stderr, "%s", _ ("Shutting down...\n"));
96 if (NULL != el) 101 if (NULL != el)
97 { 102 {
98 GNUNET_IDENTITY_ego_lookup_cancel (el); 103 GNUNET_IDENTITY_ego_lookup_cancel (el);
@@ -220,8 +225,6 @@ struct RevocationData
220static void 225static void
221perform_revocation (const struct GNUNET_REVOCATION_Pow *pow) 226perform_revocation (const struct GNUNET_REVOCATION_Pow *pow)
222{ 227{
223 struct GNUNET_TIME_Absolute ts;
224
225 h = GNUNET_REVOCATION_revoke (cfg, 228 h = GNUNET_REVOCATION_revoke (cfg,
226 pow, 229 pow,
227 &print_revocation_result, 230 &print_revocation_result,
@@ -239,10 +242,10 @@ static void
239sync_pow (const struct GNUNET_REVOCATION_Pow *pow) 242sync_pow (const struct GNUNET_REVOCATION_Pow *pow)
240{ 243{
241 if ((NULL != filename) && 244 if ((NULL != filename) &&
242 (sizeof(struct GNUNET_REVOCATION_Pow) == 245 (sizeof(struct GNUNET_REVOCATION_Pow) !=
243 GNUNET_DISK_fn_write (filename, 246 GNUNET_DISK_fn_write (filename,
244 &pow, 247 pow,
245 sizeof(pow), 248 sizeof(struct GNUNET_REVOCATION_Pow),
246 GNUNET_DISK_PERM_USER_READ 249 GNUNET_DISK_PERM_USER_READ
247 | GNUNET_DISK_PERM_USER_WRITE))) 250 | GNUNET_DISK_PERM_USER_WRITE)))
248 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); 251 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename);
@@ -258,7 +261,8 @@ static void
258calculate_pow_shutdown (void *cls) 261calculate_pow_shutdown (void *cls)
259{ 262{
260 struct GNUNET_REVOCATION_PowCalculationHandle *ph = cls; 263 struct GNUNET_REVOCATION_PowCalculationHandle *ph = cls;
261 264 fprintf (stderr, "%s", _ ("Cancelling calculation.\n"));
265 sync_pow (GNUNET_REVOCATION_pow_get (ph));
262 if (NULL != pow_task) 266 if (NULL != pow_task)
263 { 267 {
264 GNUNET_SCHEDULER_cancel (pow_task); 268 GNUNET_SCHEDULER_cancel (pow_task);
@@ -280,8 +284,8 @@ calculate_pow (void *cls)
280 284
281 /* store temporary results */ 285 /* store temporary results */
282 pow_task = NULL; 286 pow_task = NULL;
283 // if (0 == (rd->pow % 128)) 287 if (0 == (pow_passes % 128))
284 // sync_rd (rd); 288 sync_pow (GNUNET_REVOCATION_pow_get(ph));
285 /* actually do POW calculation */ 289 /* actually do POW calculation */
286 if (GNUNET_OK == GNUNET_REVOCATION_pow_round (ph)) 290 if (GNUNET_OK == GNUNET_REVOCATION_pow_round (ph))
287 { 291 {
@@ -309,7 +313,19 @@ calculate_pow (void *cls)
309 } 313 }
310 return; 314 return;
311 } 315 }
312 pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, ph); 316 pow_passes++;
317 /**
318 * Otherwise CTRL-C does not work
319 */
320 if (0 == pow_passes % 128)
321 pow_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
322 &calculate_pow,
323 ph);
324 else
325 pow_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
326 &calculate_pow,
327 ph);
328
313} 329}
314 330
315 331
@@ -324,6 +340,7 @@ ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
324{ 340{
325 struct GNUNET_REVOCATION_Pow *pow; 341 struct GNUNET_REVOCATION_Pow *pow;
326 struct GNUNET_CRYPTO_EcdsaPublicKey key; 342 struct GNUNET_CRYPTO_EcdsaPublicKey key;
343 struct GNUNET_REVOCATION_PowCalculationHandle *ph = NULL;
327 344
328 el = NULL; 345 el = NULL;
329 if (NULL == ego) 346 if (NULL == ego)
@@ -360,20 +377,24 @@ ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
360 GNUNET_free (pow); 377 GNUNET_free (pow);
361 return; 378 return;
362 } 379 }
380 /**
381 * Certificate not yet ready
382 */
363 fprintf (stderr, 383 fprintf (stderr,
364 _ ("Error: revocation certificate in `%s' invalid\n"), 384 "%s",
365 filename); 385 _("Continuing calculation where left off...\n"));
386 ph = GNUNET_REVOCATION_pow_init2 (pow,
387 1, /* Epochs */
388 matching_bits);
366 GNUNET_free (pow); 389 GNUNET_free (pow);
367 return;
368 } 390 }
369 fprintf (stderr, 391 fprintf (stderr,
370 "%s", 392 "%s",
371 _ ("Revocation certificate not ready, calculating proof of work\n")); 393 _ ("Revocation certificate not ready, calculating proof of work\n"));
372 GNUNET_free (pow); 394 if (NULL == ph)
373 struct GNUNET_REVOCATION_PowCalculationHandle *ph; 395 ph = GNUNET_REVOCATION_pow_init (&key,
374 ph = GNUNET_REVOCATION_pow_init (&key, 396 1, /* Epochs */
375 1, /* Epochs */ 397 matching_bits);
376 matching_bits);
377 pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, ph); 398 pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, ph);
378 GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, ph); 399 GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, ph);
379} 400}
@@ -456,7 +477,7 @@ run (void *cls,
456 (unsigned int) matching_bits)) 477 (unsigned int) matching_bits))
457 { 478 {
458 struct GNUNET_REVOCATION_PowCalculationHandle *ph; 479 struct GNUNET_REVOCATION_PowCalculationHandle *ph;
459 ph = GNUNET_REVOCATION_pow_init (&pk, 480 ph = GNUNET_REVOCATION_pow_init2 (&pow,
460 1, /* Epochs */ 481 1, /* Epochs */
461 matching_bits); 482 matching_bits);
462 483