diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2020-04-20 08:24:06 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2020-04-20 08:24:06 +0200 |
commit | 6d61330e3ae457a27f10247cd9caf53987604143 (patch) | |
tree | b877d94ad7bd49be40c0d601e57a09116abc6150 /src | |
parent | 196a465c2254c224055b71a5bdb3697e7a468801 (diff) | |
download | gnunet-6d61330e3ae457a27f10247cd9caf53987604143.tar.gz gnunet-6d61330e3ae457a27f10247cd9caf53987604143.zip |
evaluate epochs
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_revocation_service.h | 2 | ||||
-rw-r--r-- | src/revocation/gnunet-revocation.c | 31 | ||||
-rw-r--r-- | src/revocation/gnunet-service-revocation.c | 3 | ||||
-rw-r--r-- | src/revocation/plugin_block_revocation.c | 2 | ||||
-rw-r--r-- | src/revocation/revocation_api.c | 14 |
5 files changed, 36 insertions, 16 deletions
diff --git a/src/include/gnunet_revocation_service.h b/src/include/gnunet_revocation_service.h index a5a014708..226dce357 100644 --- a/src/include/gnunet_revocation_service.h +++ b/src/include/gnunet_revocation_service.h | |||
@@ -184,7 +184,7 @@ GNUNET_REVOCATION_revoke_cancel (struct GNUNET_REVOCATION_Handle *h); | |||
184 | * @param ts revocation timestamp | 184 | * @param ts revocation timestamp |
185 | * @param pow proof of work value | 185 | * @param pow proof of work value |
186 | * @param matching_bits how many bits must match (configuration) | 186 | * @param matching_bits how many bits must match (configuration) |
187 | * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not | 187 | * @return number of epochs valid if the @a pow is acceptable, -1 if not |
188 | */ | 188 | */ |
189 | int | 189 | int |
190 | GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_Pow *pow, | 190 | GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_Pow *pow, |
diff --git a/src/revocation/gnunet-revocation.c b/src/revocation/gnunet-revocation.c index 5566162f4..c33f12c90 100644 --- a/src/revocation/gnunet-revocation.c +++ b/src/revocation/gnunet-revocation.c | |||
@@ -84,6 +84,11 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
84 | static unsigned long long matching_bits; | 84 | static unsigned long long matching_bits; |
85 | 85 | ||
86 | /** | 86 | /** |
87 | * Epoch length | ||
88 | */ | ||
89 | static struct GNUNET_TIME_Relative epoch_length; | ||
90 | |||
91 | /** | ||
87 | * Task used for proof-of-work calculation. | 92 | * Task used for proof-of-work calculation. |
88 | */ | 93 | */ |
89 | static struct GNUNET_SCHEDULER_Task *pow_task; | 94 | static struct GNUNET_SCHEDULER_Task *pow_task; |
@@ -341,6 +346,7 @@ ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego) | |||
341 | struct GNUNET_REVOCATION_Pow *pow; | 346 | struct GNUNET_REVOCATION_Pow *pow; |
342 | struct GNUNET_CRYPTO_EcdsaPublicKey key; | 347 | struct GNUNET_CRYPTO_EcdsaPublicKey key; |
343 | struct GNUNET_REVOCATION_PowCalculationHandle *ph = NULL; | 348 | struct GNUNET_REVOCATION_PowCalculationHandle *ph = NULL; |
349 | int epochs; | ||
344 | 350 | ||
345 | el = NULL; | 351 | el = NULL; |
346 | if (NULL == ego) | 352 | if (NULL == ego) |
@@ -365,11 +371,19 @@ ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego) | |||
365 | GNUNET_free (pow); | 371 | GNUNET_free (pow); |
366 | return; | 372 | return; |
367 | } | 373 | } |
368 | if (GNUNET_YES == | 374 | if (0 < (epochs = |
369 | GNUNET_REVOCATION_check_pow (pow, | 375 | GNUNET_REVOCATION_check_pow (pow, |
370 | (unsigned int) matching_bits)) | 376 | (unsigned int) matching_bits))) |
371 | { | 377 | { |
378 | struct GNUNET_TIME_Absolute ts; | ||
379 | struct GNUNET_TIME_Relative ttl; | ||
380 | ts = GNUNET_TIME_absolute_ntoh (pow->timestamp); | ||
381 | ttl = GNUNET_TIME_relative_multiply (epoch_length, | ||
382 | epochs); | ||
372 | fprintf (stderr, "%s", _ ("Revocation certificate ready\n")); | 383 | fprintf (stderr, "%s", _ ("Revocation certificate ready\n")); |
384 | fprintf (stderr, "%s %s for %s\n", _ ("Valid from"), | ||
385 | GNUNET_STRINGS_absolute_time_to_string (ts), | ||
386 | GNUNET_STRINGS_relative_time_to_string (ttl, GNUNET_NO)); | ||
373 | if (perform) | 387 | if (perform) |
374 | perform_revocation (pow); | 388 | perform_revocation (pow); |
375 | else | 389 | else |
@@ -448,6 +462,17 @@ run (void *cls, | |||
448 | "WORKBITS"); | 462 | "WORKBITS"); |
449 | return; | 463 | return; |
450 | } | 464 | } |
465 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, | ||
466 | "REVOCATION", | ||
467 | "EPOCH_LENGTH", | ||
468 | &epoch_length)) | ||
469 | { | ||
470 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | ||
471 | "REVOCATION", | ||
472 | "EPOCH_LENGTH"); | ||
473 | return; | ||
474 | } | ||
475 | |||
451 | if (NULL != revoke_ego) | 476 | if (NULL != revoke_ego) |
452 | { | 477 | { |
453 | if (! perform && (NULL == filename)) | 478 | if (! perform && (NULL == filename)) |
@@ -472,7 +497,7 @@ run (void *cls, | |||
472 | return; | 497 | return; |
473 | } | 498 | } |
474 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 499 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); |
475 | if (GNUNET_YES != | 500 | if (0 >= |
476 | GNUNET_REVOCATION_check_pow (&pow, | 501 | GNUNET_REVOCATION_check_pow (&pow, |
477 | (unsigned int) matching_bits)) | 502 | (unsigned int) matching_bits)) |
478 | { | 503 | { |
diff --git a/src/revocation/gnunet-service-revocation.c b/src/revocation/gnunet-service-revocation.c index 420cb392f..4746a7698 100644 --- a/src/revocation/gnunet-service-revocation.c +++ b/src/revocation/gnunet-service-revocation.c | |||
@@ -167,8 +167,7 @@ new_peer_entry (const struct GNUNET_PeerIdentity *peer) | |||
167 | static int | 167 | static int |
168 | verify_revoke_message (const struct RevokeMessage *rm) | 168 | verify_revoke_message (const struct RevokeMessage *rm) |
169 | { | 169 | { |
170 | if (GNUNET_YES != | 170 | if (0 >= GNUNET_REVOCATION_check_pow (&rm->proof_of_work, |
171 | GNUNET_REVOCATION_check_pow (&rm->proof_of_work, | ||
172 | (unsigned int) revocation_work_required)) | 171 | (unsigned int) revocation_work_required)) |
173 | { | 172 | { |
174 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 173 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
diff --git a/src/revocation/plugin_block_revocation.c b/src/revocation/plugin_block_revocation.c index a57a933c3..934c8d8c9 100644 --- a/src/revocation/plugin_block_revocation.c +++ b/src/revocation/plugin_block_revocation.c | |||
@@ -142,7 +142,7 @@ block_plugin_revocation_evaluate (void *cls, | |||
142 | GNUNET_break_op (0); | 142 | GNUNET_break_op (0); |
143 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 143 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
144 | } | 144 | } |
145 | if (GNUNET_YES != | 145 | if (0 >= |
146 | GNUNET_REVOCATION_check_pow (&rm->proof_of_work, | 146 | GNUNET_REVOCATION_check_pow (&rm->proof_of_work, |
147 | ic->matching_bits)) | 147 | ic->matching_bits)) |
148 | { | 148 | { |
diff --git a/src/revocation/revocation_api.c b/src/revocation/revocation_api.c index 565ce9d0d..f2261ff4f 100644 --- a/src/revocation/revocation_api.c +++ b/src/revocation/revocation_api.c | |||
@@ -319,9 +319,7 @@ GNUNET_REVOCATION_revoke (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
319 | "REVOCATION", | 319 | "REVOCATION", |
320 | "WORKBITS", | 320 | "WORKBITS", |
321 | &matching_bits)) && | 321 | &matching_bits)) && |
322 | (GNUNET_YES != | 322 | (0 >= GNUNET_REVOCATION_check_pow (pow, (unsigned int) matching_bits))) |
323 | GNUNET_REVOCATION_check_pow (pow, | ||
324 | (unsigned int) matching_bits))) | ||
325 | { | 323 | { |
326 | GNUNET_break (0); | 324 | GNUNET_break (0); |
327 | GNUNET_free (h); | 325 | GNUNET_free (h); |
@@ -410,7 +408,7 @@ calculate_score (const struct GNUNET_REVOCATION_PowCalculationHandle *ph) | |||
410 | * @param ts revocation timestamp | 408 | * @param ts revocation timestamp |
411 | * @param pow proof of work value | 409 | * @param pow proof of work value |
412 | * @param matching_bits how many bits must match (configuration) | 410 | * @param matching_bits how many bits must match (configuration) |
413 | * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not | 411 | * @return number of epochs valid if the @a pow is acceptable, -1 if not |
414 | */ | 412 | */ |
415 | int | 413 | int |
416 | GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_Pow *pow, | 414 | GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_Pow *pow, |
@@ -433,7 +431,7 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_Pow *pow, | |||
433 | for (unsigned int j = i + 1; j < POW_COUNT; j++) | 431 | for (unsigned int j = i + 1; j < POW_COUNT; j++) |
434 | { | 432 | { |
435 | if (pow->pow[i] == pow->pow[j]) | 433 | if (pow->pow[i] == pow->pow[j]) |
436 | return GNUNET_NO; | 434 | return -1; |
437 | } | 435 | } |
438 | } | 436 | } |
439 | GNUNET_memcpy (&buf[sizeof(uint64_t)], | 437 | GNUNET_memcpy (&buf[sizeof(uint64_t)], |
@@ -460,10 +458,8 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_Pow *pow, | |||
460 | score = score / POW_COUNT; | 458 | score = score / POW_COUNT; |
461 | if (score < difficulty) | 459 | if (score < difficulty) |
462 | return GNUNET_NO; | 460 | return GNUNET_NO; |
463 | // TODO verfiy signature? | 461 | epochs = score - difficulty; |
464 | epochs = score - difficulty + 1; | 462 | return epochs; |
465 | // TODO verify expiration | ||
466 | return GNUNET_YES; | ||
467 | } | 463 | } |
468 | 464 | ||
469 | 465 | ||