aboutsummaryrefslogtreecommitdiff
path: root/src/revocation/gnunet-revocation.c
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2020-04-21 11:52:12 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2020-04-21 11:52:12 +0200
commit19b772329cb8968e5e96e33d5238f172f5553dc4 (patch)
treeefc2631a96f2e903fb4469d894cfa10d89dc49bd /src/revocation/gnunet-revocation.c
parentd4fd97e693e462f3bd16425f4e803fe5a99b9d62 (diff)
downloadgnunet-19b772329cb8968e5e96e33d5238f172f5553dc4.tar.gz
gnunet-19b772329cb8968e5e96e33d5238f172f5553dc4.zip
new pass API
Diffstat (limited to 'src/revocation/gnunet-revocation.c')
-rw-r--r--src/revocation/gnunet-revocation.c92
1 files changed, 34 insertions, 58 deletions
diff --git a/src/revocation/gnunet-revocation.c b/src/revocation/gnunet-revocation.c
index d290d34c7..2230114ae 100644
--- a/src/revocation/gnunet-revocation.c
+++ b/src/revocation/gnunet-revocation.c
@@ -93,6 +93,10 @@ static struct GNUNET_TIME_Relative epoch_length;
93 */ 93 */
94static struct GNUNET_SCHEDULER_Task *pow_task; 94static struct GNUNET_SCHEDULER_Task *pow_task;
95 95
96/**
97 * Proof-of-work object
98 */
99static struct GNUNET_REVOCATION_Pow proof_of_work;
96 100
97/** 101/**
98 * Function run if the user aborts with CTRL-C. 102 * Function run if the user aborts with CTRL-C.
@@ -198,40 +202,13 @@ print_revocation_result (void *cls, int is_valid)
198 202
199 203
200/** 204/**
201 * Data needed to perform a revocation.
202 */
203struct RevocationData
204{
205 /**
206 * Public key.
207 */
208 struct GNUNET_CRYPTO_EcdsaPublicKey key;
209
210 /**
211 * Revocation signature data.
212 */
213 struct GNUNET_CRYPTO_EcdsaSignature sig;
214
215 /**
216 * Time of revocation
217 */
218 struct GNUNET_TIME_AbsoluteNBO ts;
219
220 /**
221 * Proof of work (in NBO).
222 */
223 uint64_t pow GNUNET_PACKED;
224};
225
226
227/**
228 * Perform the revocation. 205 * Perform the revocation.
229 */ 206 */
230static void 207static void
231perform_revocation (const struct GNUNET_REVOCATION_Pow *pow) 208perform_revocation ()
232{ 209{
233 h = GNUNET_REVOCATION_revoke (cfg, 210 h = GNUNET_REVOCATION_revoke (cfg,
234 pow, 211 &proof_of_work,
235 &print_revocation_result, 212 &print_revocation_result,
236 NULL); 213 NULL);
237} 214}
@@ -244,12 +221,12 @@ perform_revocation (const struct GNUNET_REVOCATION_Pow *pow)
244 * @param rd data to sync 221 * @param rd data to sync
245 */ 222 */
246static void 223static void
247sync_pow (const struct GNUNET_REVOCATION_Pow *pow) 224sync_pow ()
248{ 225{
249 if ((NULL != filename) && 226 if ((NULL != filename) &&
250 (sizeof(struct GNUNET_REVOCATION_Pow) != 227 (sizeof(struct GNUNET_REVOCATION_Pow) !=
251 GNUNET_DISK_fn_write (filename, 228 GNUNET_DISK_fn_write (filename,
252 pow, 229 &proof_of_work,
253 sizeof(struct GNUNET_REVOCATION_Pow), 230 sizeof(struct GNUNET_REVOCATION_Pow),
254 GNUNET_DISK_PERM_USER_READ 231 GNUNET_DISK_PERM_USER_READ
255 | GNUNET_DISK_PERM_USER_WRITE))) 232 | GNUNET_DISK_PERM_USER_WRITE)))
@@ -267,7 +244,7 @@ calculate_pow_shutdown (void *cls)
267{ 244{
268 struct GNUNET_REVOCATION_PowCalculationHandle *ph = cls; 245 struct GNUNET_REVOCATION_PowCalculationHandle *ph = cls;
269 fprintf (stderr, "%s", _ ("Cancelling calculation.\n")); 246 fprintf (stderr, "%s", _ ("Cancelling calculation.\n"));
270 sync_pow (GNUNET_REVOCATION_pow_get (ph)); 247 sync_pow ();
271 if (NULL != pow_task) 248 if (NULL != pow_task)
272 { 249 {
273 GNUNET_SCHEDULER_cancel (pow_task); 250 GNUNET_SCHEDULER_cancel (pow_task);
@@ -290,22 +267,21 @@ calculate_pow (void *cls)
290 /* store temporary results */ 267 /* store temporary results */
291 pow_task = NULL; 268 pow_task = NULL;
292 if (0 == (pow_passes % 128)) 269 if (0 == (pow_passes % 128))
293 sync_pow (GNUNET_REVOCATION_pow_get(ph)); 270 sync_pow ();
294 /* actually do POW calculation */ 271 /* actually do POW calculation */
295 if (GNUNET_OK == GNUNET_REVOCATION_pow_round (ph)) 272 if (GNUNET_OK == GNUNET_REVOCATION_pow_round (ph))
296 { 273 {
297 const struct GNUNET_REVOCATION_Pow *pow = GNUNET_REVOCATION_pow_get (ph);
298 if ((NULL != filename) && 274 if ((NULL != filename) &&
299 (sizeof(struct GNUNET_REVOCATION_Pow) != 275 (sizeof(struct GNUNET_REVOCATION_Pow) !=
300 GNUNET_DISK_fn_write (filename, 276 GNUNET_DISK_fn_write (filename,
301 pow, 277 &proof_of_work,
302 sizeof(struct GNUNET_REVOCATION_Pow), 278 sizeof(struct GNUNET_REVOCATION_Pow),
303 GNUNET_DISK_PERM_USER_READ 279 GNUNET_DISK_PERM_USER_READ
304 | GNUNET_DISK_PERM_USER_WRITE))) 280 | GNUNET_DISK_PERM_USER_WRITE)))
305 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); 281 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename);
306 if (perform) 282 if (perform)
307 { 283 {
308 perform_revocation (pow); 284 perform_revocation ();
309 } 285 }
310 else 286 else
311 { 287 {
@@ -343,7 +319,6 @@ calculate_pow (void *cls)
343static void 319static void
344ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego) 320ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
345{ 321{
346 struct GNUNET_REVOCATION_Pow *pow;
347 struct GNUNET_CRYPTO_EcdsaPublicKey key; 322 struct GNUNET_CRYPTO_EcdsaPublicKey key;
348 const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; 323 const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
349 struct GNUNET_REVOCATION_PowCalculationHandle *ph = NULL; 324 struct GNUNET_REVOCATION_PowCalculationHandle *ph = NULL;
@@ -357,32 +332,29 @@ ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
357 } 332 }
358 GNUNET_IDENTITY_ego_get_public_key (ego, &key); 333 GNUNET_IDENTITY_ego_get_public_key (ego, &key);
359 privkey = GNUNET_IDENTITY_ego_get_private_key (ego); 334 privkey = GNUNET_IDENTITY_ego_get_private_key (ego);
360 pow = GNUNET_new (struct GNUNET_REVOCATION_Pow); 335 memset(&proof_of_work, 0, sizeof (proof_of_work));
361 if ((NULL != filename) && (GNUNET_YES == GNUNET_DISK_file_test (filename)) && 336 if ((NULL != filename) && (GNUNET_YES == GNUNET_DISK_file_test (filename)) &&
362 (sizeof(struct GNUNET_REVOCATION_Pow) == 337 (sizeof(proof_of_work) ==
363 GNUNET_DISK_fn_read (filename, pow, sizeof(struct 338 GNUNET_DISK_fn_read (filename, &proof_of_work, sizeof(proof_of_work))))
364 GNUNET_REVOCATION_Pow))))
365 { 339 {
366 if (0 != GNUNET_memcmp (&pow->key, &key)) 340 if (0 != GNUNET_memcmp (&proof_of_work.key, &key))
367 { 341 {
368 fprintf (stderr, 342 fprintf (stderr,
369 _ ("Error: revocation certificate in `%s' is not for `%s'\n"), 343 _ ("Error: revocation certificate in `%s' is not for `%s'\n"),
370 filename, 344 filename,
371 revoke_ego); 345 revoke_ego);
372 GNUNET_free (pow);
373 return; 346 return;
374 } 347 }
375 if (GNUNET_YES == 348 if (GNUNET_YES ==
376 GNUNET_REVOCATION_check_pow (pow, 349 GNUNET_REVOCATION_check_pow (&proof_of_work,
377 (unsigned int) matching_bits, 350 (unsigned int) matching_bits,
378 epoch_length)) 351 epoch_length))
379 { 352 {
380 fprintf (stderr, "%s", _ ("Revocation certificate ready\n")); 353 fprintf (stderr, "%s", _ ("Revocation certificate ready\n"));
381 if (perform) 354 if (perform)
382 perform_revocation (pow); 355 perform_revocation ();
383 else 356 else
384 GNUNET_SCHEDULER_shutdown (); 357 GNUNET_SCHEDULER_shutdown ();
385 GNUNET_free (pow);
386 return; 358 return;
387 } 359 }
388 /** 360 /**
@@ -391,18 +363,21 @@ ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
391 fprintf (stderr, 363 fprintf (stderr,
392 "%s", 364 "%s",
393 _("Continuing calculation where left off...\n")); 365 _("Continuing calculation where left off...\n"));
394 ph = GNUNET_REVOCATION_pow_init2 (pow, 366 ph = GNUNET_REVOCATION_pow_start (&proof_of_work,
395 1, /* Epochs */ 367 1, /* Epochs */
396 matching_bits); 368 matching_bits);
397 GNUNET_free (pow);
398 } 369 }
399 fprintf (stderr, 370 fprintf (stderr,
400 "%s", 371 "%s",
401 _ ("Revocation certificate not ready, calculating proof of work\n")); 372 _ ("Revocation certificate not ready, calculating proof of work\n"));
402 if (NULL == ph) 373 if (NULL == ph)
403 ph = GNUNET_REVOCATION_pow_init (privkey, 374 {
404 1, /* Epochs */ 375 GNUNET_REVOCATION_pow_init (privkey,
405 matching_bits); 376 &proof_of_work);
377 ph = GNUNET_REVOCATION_pow_start (&proof_of_work,
378 1, /* Epochs */
379 matching_bits);
380 }
406 pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, ph); 381 pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, ph);
407 GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, ph); 382 GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, ph);
408} 383}
@@ -423,7 +398,6 @@ run (void *cls,
423 const struct GNUNET_CONFIGURATION_Handle *c) 398 const struct GNUNET_CONFIGURATION_Handle *c)
424{ 399{
425 struct GNUNET_CRYPTO_EcdsaPublicKey pk; 400 struct GNUNET_CRYPTO_EcdsaPublicKey pk;
426 struct GNUNET_REVOCATION_Pow pow;
427 401
428 cfg = c; 402 cfg = c;
429 if (NULL != test_ego) 403 if (NULL != test_ego)
@@ -483,7 +457,9 @@ run (void *cls,
483 } 457 }
484 if ((NULL != filename) && (perform)) 458 if ((NULL != filename) && (perform))
485 { 459 {
486 if (sizeof(pow) != GNUNET_DISK_fn_read (filename, &pow, sizeof(pow))) 460 if (sizeof(proof_of_work) != GNUNET_DISK_fn_read (filename,
461 &proof_of_work,
462 sizeof(proof_of_work)))
487 { 463 {
488 fprintf (stderr, 464 fprintf (stderr,
489 _ ("Failed to read revocation certificate from `%s'\n"), 465 _ ("Failed to read revocation certificate from `%s'\n"),
@@ -492,20 +468,20 @@ run (void *cls,
492 } 468 }
493 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); 469 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
494 if (GNUNET_YES != 470 if (GNUNET_YES !=
495 GNUNET_REVOCATION_check_pow (&pow, 471 GNUNET_REVOCATION_check_pow (&proof_of_work,
496 (unsigned int) matching_bits, 472 (unsigned int) matching_bits,
497 epoch_length)) 473 epoch_length))
498 { 474 {
499 struct GNUNET_REVOCATION_PowCalculationHandle *ph; 475 struct GNUNET_REVOCATION_PowCalculationHandle *ph;
500 ph = GNUNET_REVOCATION_pow_init2 (&pow, 476 ph = GNUNET_REVOCATION_pow_start (&proof_of_work,
501 1, /* Epochs */ 477 1, /* Epochs */
502 matching_bits); 478 matching_bits);
503 479
504 pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, ph); 480 pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, ph);
505 GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, ph); 481 GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, ph);
506 return; 482 return;
507 } 483 }
508 perform_revocation (&pow); 484 perform_revocation ();
509 return; 485 return;
510 } 486 }
511 fprintf (stderr, "%s", _ ("No action specified. Nothing to do.\n")); 487 fprintf (stderr, "%s", _ ("No action specified. Nothing to do.\n"));