From 0d3758807bb2fcce4a2dd7b845b7f6bacb363fa7 Mon Sep 17 00:00:00 2001 From: Marcello Stanisci Date: Wed, 10 Apr 2019 19:01:26 +0200 Subject: Better calculation of # DKs --- src/exchange-tools/taler-exchange-keyup.c | 9 ---- src/exchangedb/exchangedb_denomkeys.c | 2 +- .../test_exchange_api_keys_cherry_picking_new.c | 55 +++++++++++++--------- 3 files changed, 34 insertions(+), 32 deletions(-) diff --git a/src/exchange-tools/taler-exchange-keyup.c b/src/exchange-tools/taler-exchange-keyup.c index 8b6d32ac8..28e2ea1d0 100644 --- a/src/exchange-tools/taler-exchange-keyup.c +++ b/src/exchange-tools/taler-exchange-keyup.c @@ -439,21 +439,12 @@ get_anchor (const char *dir, } else if (anchor->abs_value_us != now.abs_value_us) { - - /** - * XXX-ANCHOR question: why adding the duration only in this - * case, and not _all the times we found a anchor_ ? Like for - * instance, below out of this block? - * - */ *anchor = GNUNET_TIME_absolute_add (*anchor, duration); *anchor = GNUNET_TIME_absolute_subtract (*anchor, overlap); } - /* ==>Missing to add the duration to the anchor here?<== */ - /* anchor is now the stamp where we need to create a new key */ } diff --git a/src/exchangedb/exchangedb_denomkeys.c b/src/exchangedb/exchangedb_denomkeys.c index 32955dcc1..d9e604ebe 100644 --- a/src/exchangedb/exchangedb_denomkeys.c +++ b/src/exchangedb/exchangedb_denomkeys.c @@ -200,7 +200,7 @@ TALER_EXCHANGEDB_denomination_key_write (const char *filename, if (NULL == (fh = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_TRUNCATE, - GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE))) + GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE | GNUNET_DISK_OPEN_FAILIFEXISTS))) goto cleanup; wsize = sizeof (struct TALER_EXCHANGEDB_DenominationKeyInformationP); if (GNUNET_SYSERR == (wrote = GNUNET_DISK_file_write (fh, diff --git a/src/lib/test_exchange_api_keys_cherry_picking_new.c b/src/lib/test_exchange_api_keys_cherry_picking_new.c index 0be980a36..916af33fc 100644 --- a/src/lib/test_exchange_api_keys_cherry_picking_new.c +++ b/src/lib/test_exchange_api_keys_cherry_picking_new.c @@ -55,19 +55,28 @@ "test_exchange_api_keys_cherry_picking_extended_2.conf" /** - * Current time. + * Add seconds. + * + * @param base absolute time to add seconds to. + * @param relative number of seconds to add. + * @return a new absolute time, modified according to @e relative. */ -struct GNUNET_TIME_Absolute now; +#define ADDSECS(base, secs) \ + GNUNET_TIME_absolute_add \ + (base, \ + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \ + secs)) /** - * Adds to the current time. + * Subtract seconds. * - * @param relative number of _seconds_ to add to the current time. + * @param base absolute time to subtract seconds to. + * @param secs relative number of _seconds_ to subtract. * @return a new absolute time, modified according to @e relative. */ -#define NOWPLUSSECS(secs) \ - GNUNET_TIME_absolute_add \ - (now, \ +#define SUBSECS(base, secs) \ + GNUNET_TIME_absolute_sub \ + (base, \ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \ secs)) #define JAN1971 "1971-01-01" @@ -169,7 +178,6 @@ run (void *cls, }; - now = GNUNET_TIME_absolute_get (); struct TALER_TESTING_Command ordinary_cherry_pick[] = { /** @@ -201,26 +209,29 @@ run (void *cls, 2, TTH_parse_time (JAN2030)), - /** - * We now load a very high lookahead_sign value of 3500 s, - * with now == JAN2030. - */ TALER_TESTING_cmd_exec_keyup_with_now ("keyup-3", CONFIG_FILE_EXTENDED_2, - TTH_parse_time (JAN2030)), + /* Taking care of not using a 'now' that equals the + * last DK timestamp, otherwise it would get silently + * overridden. */ + ADDSECS (TTH_parse_time (JAN2030), + 10)), /** - * For each DK with a withdraw duration of 80 s - * (- 1 s of overlap), and for the latest 3500 s - * lookahead_sign value, we should have ((3500 - _79_) / 79) - * keys we just downloaded + 2 old DK keys stored in memory - * (total 46). The _79_ seconds we subtract are from the one - * key generated at "keyup-1". + * Expected number of DK: * - * This currently fails: look for XXX-ANCHOR at - * taler-exchange-keyup.c to get some insight about the reason - * behind. + * 3500 (the lookaeahd_sign time frame, in seconds) + * - 69 (how many seconds are covered by the latest DK) + * ---- + * 3431 + * / 79 (how many seconds each DK will cover) + * ---- + * 44 (rounded up) + * + 2 (old DKs already stored locally: 1 from the + * very initial setup, and 1 from the 'keyup-1' CMD) + * ---- + * 46 */ TALER_TESTING_cmd_check_keys_with_now ("check-keys-3", -- cgit v1.2.3