diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2020-04-19 20:05:26 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2020-04-19 20:05:26 +0200 |
commit | 8f9a45e853d9759f04a5f4fe9aa0146ed3f3fb17 (patch) | |
tree | b9ef6928b2fdb8647a8c7d3e0f6d316198b51d48 /src/revocation/gnunet-revocation.c | |
parent | eb6b547e243144f27749811c15b6cce90e03aaa7 (diff) | |
download | gnunet-8f9a45e853d9759f04a5f4fe9aa0146ed3f3fb17.tar.gz gnunet-8f9a45e853d9759f04a5f4fe9aa0146ed3f3fb17.zip |
towards less variance
Diffstat (limited to 'src/revocation/gnunet-revocation.c')
-rw-r--r-- | src/revocation/gnunet-revocation.c | 137 |
1 files changed, 58 insertions, 79 deletions
diff --git a/src/revocation/gnunet-revocation.c b/src/revocation/gnunet-revocation.c index 42ec71d16..2d83da8b6 100644 --- a/src/revocation/gnunet-revocation.c +++ b/src/revocation/gnunet-revocation.c | |||
@@ -218,16 +218,12 @@ struct RevocationData | |||
218 | * Perform the revocation. | 218 | * Perform the revocation. |
219 | */ | 219 | */ |
220 | static void | 220 | static void |
221 | perform_revocation (const struct RevocationData *rd) | 221 | perform_revocation (const struct GNUNET_REVOCATION_Pow *pow) |
222 | { | 222 | { |
223 | struct GNUNET_TIME_Absolute ts; | 223 | struct GNUNET_TIME_Absolute ts; |
224 | 224 | ||
225 | ts = GNUNET_TIME_absolute_ntoh (rd->ts); | ||
226 | h = GNUNET_REVOCATION_revoke (cfg, | 225 | h = GNUNET_REVOCATION_revoke (cfg, |
227 | &rd->key, | 226 | pow, |
228 | &rd->sig, | ||
229 | &ts, | ||
230 | rd->pow, | ||
231 | &print_revocation_result, | 227 | &print_revocation_result, |
232 | NULL); | 228 | NULL); |
233 | } | 229 | } |
@@ -240,13 +236,13 @@ perform_revocation (const struct RevocationData *rd) | |||
240 | * @param rd data to sync | 236 | * @param rd data to sync |
241 | */ | 237 | */ |
242 | static void | 238 | static void |
243 | sync_rd (const struct RevocationData *rd) | 239 | sync_pow (const struct GNUNET_REVOCATION_Pow *pow) |
244 | { | 240 | { |
245 | if ((NULL != filename) && | 241 | if ((NULL != filename) && |
246 | (sizeof(struct RevocationData) == | 242 | (sizeof(struct GNUNET_REVOCATION_Pow) == |
247 | GNUNET_DISK_fn_write (filename, | 243 | GNUNET_DISK_fn_write (filename, |
248 | &rd, | 244 | &pow, |
249 | sizeof(rd), | 245 | sizeof(pow), |
250 | GNUNET_DISK_PERM_USER_READ | 246 | GNUNET_DISK_PERM_USER_READ |
251 | | GNUNET_DISK_PERM_USER_WRITE))) | 247 | | GNUNET_DISK_PERM_USER_WRITE))) |
252 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); | 248 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); |
@@ -261,15 +257,14 @@ sync_rd (const struct RevocationData *rd) | |||
261 | static void | 257 | static void |
262 | calculate_pow_shutdown (void *cls) | 258 | calculate_pow_shutdown (void *cls) |
263 | { | 259 | { |
264 | struct RevocationData *rd = cls; | 260 | struct GNUNET_REVOCATION_PowCalculationHandle *ph = cls; |
265 | 261 | ||
266 | if (NULL != pow_task) | 262 | if (NULL != pow_task) |
267 | { | 263 | { |
268 | GNUNET_SCHEDULER_cancel (pow_task); | 264 | GNUNET_SCHEDULER_cancel (pow_task); |
269 | pow_task = NULL; | 265 | pow_task = NULL; |
270 | } | 266 | } |
271 | sync_rd (rd); | 267 | GNUNET_REVOCATION_pow_cleanup (ph); |
272 | GNUNET_free (rd); | ||
273 | } | 268 | } |
274 | 269 | ||
275 | 270 | ||
@@ -281,40 +276,27 @@ calculate_pow_shutdown (void *cls) | |||
281 | static void | 276 | static void |
282 | calculate_pow (void *cls) | 277 | calculate_pow (void *cls) |
283 | { | 278 | { |
284 | struct RevocationData *rd = cls; | 279 | struct GNUNET_REVOCATION_PowCalculationHandle *ph = cls; |
285 | struct GNUNET_TIME_Absolute ts = GNUNET_TIME_absolute_ntoh (rd->ts); | ||
286 | 280 | ||
287 | /* store temporary results */ | 281 | /* store temporary results */ |
288 | pow_task = NULL; | 282 | pow_task = NULL; |
289 | if (0 == (rd->pow % 128)) | 283 | //if (0 == (rd->pow % 128)) |
290 | sync_rd (rd); | 284 | // sync_rd (rd); |
291 | /* display progress estimate */ | ||
292 | if ((0 == ((1 << matching_bits) / 100 / 50)) || | ||
293 | (0 == (rd->pow % ((1 << matching_bits) / 100 / 50)))) | ||
294 | fprintf (stderr, "%s", "."); | ||
295 | if ((0 != rd->pow) && ((0 == ((1 << matching_bits) / 100)) || | ||
296 | (0 == (rd->pow % ((1 << matching_bits) / 100))))) | ||
297 | fprintf (stderr, | ||
298 | " - @ %3u%% (estimate)\n", | ||
299 | (unsigned int) (rd->pow * 100) / (1 << matching_bits)); | ||
300 | /* actually do POW calculation */ | 285 | /* actually do POW calculation */ |
301 | rd->pow++; | 286 | if (GNUNET_OK == GNUNET_REVOCATION_pow_round (ph)) |
302 | if (GNUNET_OK == GNUNET_REVOCATION_check_pow (&rd->key, | ||
303 | &ts, | ||
304 | rd->pow, | ||
305 | (unsigned int) matching_bits)) | ||
306 | { | 287 | { |
288 | const struct GNUNET_REVOCATION_Pow *pow = GNUNET_REVOCATION_pow_get (ph); | ||
307 | if ((NULL != filename) && | 289 | if ((NULL != filename) && |
308 | (sizeof(struct RevocationData) != | 290 | (sizeof(struct GNUNET_REVOCATION_Pow) != |
309 | GNUNET_DISK_fn_write (filename, | 291 | GNUNET_DISK_fn_write (filename, |
310 | rd, | 292 | pow, |
311 | sizeof(struct RevocationData), | 293 | sizeof(struct GNUNET_REVOCATION_Pow), |
312 | GNUNET_DISK_PERM_USER_READ | 294 | GNUNET_DISK_PERM_USER_READ |
313 | | GNUNET_DISK_PERM_USER_WRITE))) | 295 | | GNUNET_DISK_PERM_USER_WRITE))) |
314 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); | 296 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); |
315 | if (perform) | 297 | if (perform) |
316 | { | 298 | { |
317 | perform_revocation (rd); | 299 | perform_revocation (pow); |
318 | } | 300 | } |
319 | else | 301 | else |
320 | { | 302 | { |
@@ -327,7 +309,7 @@ calculate_pow (void *cls) | |||
327 | } | 309 | } |
328 | return; | 310 | return; |
329 | } | 311 | } |
330 | pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, rd); | 312 | pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, ph); |
331 | } | 313 | } |
332 | 314 | ||
333 | 315 | ||
@@ -340,9 +322,8 @@ calculate_pow (void *cls) | |||
340 | static void | 322 | static void |
341 | ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego) | 323 | ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego) |
342 | { | 324 | { |
343 | struct RevocationData *rd; | 325 | struct GNUNET_REVOCATION_Pow *pow; |
344 | struct GNUNET_CRYPTO_EcdsaPublicKey key; | 326 | struct GNUNET_CRYPTO_EcdsaPublicKey key; |
345 | struct GNUNET_TIME_Absolute ts; | ||
346 | 327 | ||
347 | el = NULL; | 328 | el = NULL; |
348 | if (NULL == ego) | 329 | if (NULL == ego) |
@@ -352,49 +333,49 @@ ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego) | |||
352 | return; | 333 | return; |
353 | } | 334 | } |
354 | GNUNET_IDENTITY_ego_get_public_key (ego, &key); | 335 | GNUNET_IDENTITY_ego_get_public_key (ego, &key); |
355 | rd = GNUNET_new (struct RevocationData); | 336 | pow = GNUNET_new (struct GNUNET_REVOCATION_Pow); |
356 | if ((NULL != filename) && (GNUNET_YES == GNUNET_DISK_file_test (filename)) && | 337 | if ((NULL != filename) && (GNUNET_YES == GNUNET_DISK_file_test (filename)) && |
357 | (sizeof(struct RevocationData) == | 338 | (sizeof(struct GNUNET_REVOCATION_Pow) == |
358 | GNUNET_DISK_fn_read (filename, rd, sizeof(struct RevocationData)))) | 339 | GNUNET_DISK_fn_read (filename, pow, sizeof(struct |
340 | GNUNET_REVOCATION_Pow)))) | ||
359 | { | 341 | { |
360 | if (0 != GNUNET_memcmp (&rd->key, &key)) | 342 | if (0 != GNUNET_memcmp (&pow->key, &key)) |
361 | { | 343 | { |
362 | fprintf (stderr, | 344 | fprintf (stderr, |
363 | _ ("Error: revocation certificate in `%s' is not for `%s'\n"), | 345 | _ ("Error: revocation certificate in `%s' is not for `%s'\n"), |
364 | filename, | 346 | filename, |
365 | revoke_ego); | 347 | revoke_ego); |
366 | GNUNET_free (rd); | 348 | GNUNET_free (pow); |
367 | return; | 349 | return; |
368 | } | 350 | } |
369 | } | 351 | if (GNUNET_YES == |
370 | else | 352 | GNUNET_REVOCATION_check_pow (pow, |
371 | { | 353 | (unsigned int) matching_bits)) |
372 | GNUNET_REVOCATION_sign_revocation (GNUNET_IDENTITY_ego_get_private_key ( | 354 | { |
373 | ego), | 355 | fprintf (stderr, "%s", _ ("Revocation certificate ready\n")); |
374 | &rd->sig); | 356 | if (perform) |
375 | rd->key = key; | 357 | perform_revocation (pow); |
376 | rd->ts = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); | 358 | else |
377 | } | 359 | GNUNET_SCHEDULER_shutdown (); |
378 | ts = GNUNET_TIME_absolute_ntoh (rd->ts); | 360 | GNUNET_free (pow); |
379 | if (GNUNET_YES == | 361 | return; |
380 | GNUNET_REVOCATION_check_pow (&key, | 362 | } |
381 | &ts, | 363 | fprintf (stderr, |
382 | rd->pow, | 364 | _ ("Error: revocation certificate in `%s' invalid\n"), |
383 | (unsigned int) matching_bits)) | 365 | filename); |
384 | { | 366 | GNUNET_free (pow); |
385 | fprintf (stderr, "%s", _ ("Revocation certificate ready\n")); | ||
386 | if (perform) | ||
387 | perform_revocation (rd); | ||
388 | else | ||
389 | GNUNET_SCHEDULER_shutdown (); | ||
390 | GNUNET_free (rd); | ||
391 | return; | 367 | return; |
392 | } | 368 | } |
393 | fprintf (stderr, | 369 | fprintf (stderr, |
394 | "%s", | 370 | "%s", |
395 | _ ("Revocation certificate not ready, calculating proof of work\n")); | 371 | _ ("Revocation certificate not ready, calculating proof of work\n")); |
396 | pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, rd); | 372 | GNUNET_free (pow); |
397 | GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, rd); | 373 | struct GNUNET_REVOCATION_PowCalculationHandle *ph; |
374 | ph = GNUNET_REVOCATION_pow_init (&key, | ||
375 | 1, /* Epochs */ | ||
376 | matching_bits); | ||
377 | pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, ph); | ||
378 | GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, ph); | ||
398 | } | 379 | } |
399 | 380 | ||
400 | 381 | ||
@@ -413,8 +394,7 @@ run (void *cls, | |||
413 | const struct GNUNET_CONFIGURATION_Handle *c) | 394 | const struct GNUNET_CONFIGURATION_Handle *c) |
414 | { | 395 | { |
415 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; | 396 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; |
416 | struct RevocationData rd; | 397 | struct GNUNET_REVOCATION_Pow pow; |
417 | struct GNUNET_TIME_Absolute ts; | ||
418 | 398 | ||
419 | cfg = c; | 399 | cfg = c; |
420 | if (NULL != test_ego) | 400 | if (NULL != test_ego) |
@@ -463,7 +443,7 @@ run (void *cls, | |||
463 | } | 443 | } |
464 | if ((NULL != filename) && (perform)) | 444 | if ((NULL != filename) && (perform)) |
465 | { | 445 | { |
466 | if (sizeof(rd) != GNUNET_DISK_fn_read (filename, &rd, sizeof(rd))) | 446 | if (sizeof(pow) != GNUNET_DISK_fn_read (filename, &pow, sizeof(pow))) |
467 | { | 447 | { |
468 | fprintf (stderr, | 448 | fprintf (stderr, |
469 | _ ("Failed to read revocation certificate from `%s'\n"), | 449 | _ ("Failed to read revocation certificate from `%s'\n"), |
@@ -471,21 +451,20 @@ run (void *cls, | |||
471 | return; | 451 | return; |
472 | } | 452 | } |
473 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 453 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); |
474 | ts = GNUNET_TIME_absolute_ntoh (rd.ts); | ||
475 | if (GNUNET_YES != | 454 | if (GNUNET_YES != |
476 | GNUNET_REVOCATION_check_pow (&rd.key, | 455 | GNUNET_REVOCATION_check_pow (&pow, |
477 | &ts, | ||
478 | rd.pow, | ||
479 | (unsigned int) matching_bits)) | 456 | (unsigned int) matching_bits)) |
480 | { | 457 | { |
481 | struct RevocationData *cp = GNUNET_new (struct RevocationData); | 458 | struct GNUNET_REVOCATION_PowCalculationHandle *ph; |
459 | ph = GNUNET_REVOCATION_pow_init (&pk, | ||
460 | 1, /* Epochs */ | ||
461 | matching_bits); | ||
482 | 462 | ||
483 | *cp = rd; | 463 | pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, ph); |
484 | pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, cp); | 464 | GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, ph); |
485 | GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, cp); | ||
486 | return; | 465 | return; |
487 | } | 466 | } |
488 | perform_revocation (&rd); | 467 | perform_revocation (&pow); |
489 | return; | 468 | return; |
490 | } | 469 | } |
491 | fprintf (stderr, "%s", _ ("No action specified. Nothing to do.\n")); | 470 | fprintf (stderr, "%s", _ ("No action specified. Nothing to do.\n")); |