gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-exchange] branch master updated (41afe6fd -> 35c064b


From: gnunet
Subject: [GNUnet-SVN] [taler-exchange] branch master updated (41afe6fd -> 35c064b9)
Date: Wed, 03 Apr 2019 16:07:41 +0200

This is an automated email from the git hooks/post-receive script.

marcello pushed a change to branch master
in repository exchange.

    from 41afe6fd fix git link to Taler repo
     new 219f7029 Faking the time.
     new 35c064b9 Faking the time.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/exchange/taler-exchange-httpd_deposit.c        |  4 +-
 src/exchange/taler-exchange-httpd_keystate.c       | 66 ++++++++++++------
 src/exchange/taler-exchange-httpd_keystate.h       |  7 +-
 src/exchange/taler-exchange-httpd_payback.c        |  2 +-
 src/exchange/taler-exchange-httpd_refresh_melt.c   |  2 +-
 src/exchange/taler-exchange-httpd_refresh_reveal.c |  2 +-
 src/exchange/taler-exchange-httpd_refund.c         |  2 +-
 .../taler-exchange-httpd_reserve_withdraw.c        |  2 +-
 src/include/taler_testing_lib.h                    | 16 +++++
 .../test_exchange_api_keys_cherry_picking_new.c    | 40 +++++++----
 src/lib/testing_api_cmd_bank_check.c               | 24 ++++---
 src/lib/testing_api_cmd_exec_keyup.c               | 78 +++++++++++++++++++---
 12 files changed, 184 insertions(+), 61 deletions(-)

diff --git a/src/exchange/taler-exchange-httpd_deposit.c 
b/src/exchange/taler-exchange-httpd_deposit.c
index 3e91218c..2aaa3c74 100644
--- a/src/exchange/taler-exchange-httpd_deposit.c
+++ b/src/exchange/taler-exchange-httpd_deposit.c
@@ -274,7 +274,7 @@ verify_and_execute_deposit (struct MHD_Connection 
*connection,
   }
 
   /* check denomination */
-  mks = TEH_KS_acquire ();
+  mks = TEH_KS_acquire (GNUNET_TIME_absolute_get ());
   if (NULL == mks)
   {
     TALER_LOG_ERROR ("Lacking keys to operate\n");
@@ -479,7 +479,7 @@ TEH_DEPOSIT_handler_deposit (struct TEH_RequestHandler *rh,
   }
 
   /* check denomination exists and is valid */
-  key_state = TEH_KS_acquire ();
+  key_state = TEH_KS_acquire (GNUNET_TIME_absolute_get ());
   if (NULL == key_state)
   {
     TALER_LOG_ERROR ("Lacking keys to operate\n");
diff --git a/src/exchange/taler-exchange-httpd_keystate.c 
b/src/exchange/taler-exchange-httpd_keystate.c
index b15749ca..0ee3806f 100644
--- a/src/exchange/taler-exchange-httpd_keystate.c
+++ b/src/exchange/taler-exchange-httpd_keystate.c
@@ -211,6 +211,10 @@ struct ResponseFactoryContext
    */
   unsigned int denomkey_array_length;
 
+  /**
+   * Time stamp used as "now".
+   */
+  struct GNUNET_TIME_Absolute now;
 };
 
 
@@ -700,7 +704,6 @@ reload_keys_denom_iter (void *cls,
 {
   struct ResponseFactoryContext *rfc = cls;
   struct TEH_KS_StateHandle *key_state = rfc->key_state;
-  struct GNUNET_TIME_Absolute now;
   struct GNUNET_TIME_Absolute start;
   struct GNUNET_TIME_Absolute horizon;
   struct GNUNET_TIME_Absolute expire_deposit;
@@ -709,9 +712,8 @@ reload_keys_denom_iter (void *cls,
               "Loading denomination key `%s' (%s)\n",
               alias,
              GNUNET_h2s (&dki->issue.properties.denom_hash));
-  now = GNUNET_TIME_absolute_get ();
   expire_deposit = GNUNET_TIME_absolute_ntoh 
(dki->issue.properties.expire_deposit);
-  if (expire_deposit.abs_value_us < now.abs_value_us)
+  if (expire_deposit.abs_value_us < rfc->now.abs_value_us)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Skipping expired denomination key `%s'\n",
@@ -1524,7 +1526,7 @@ reload_public_denoms_cb (void *cls,
  * @return NULL on error (usually pretty fatal...)
  */
 static struct TEH_KS_StateHandle *
-make_fresh_key_state ()
+make_fresh_key_state (struct GNUNET_TIME_Absolute now)
 {
   struct TEH_KS_StateHandle *key_state;
   struct ResponseFactoryContext rfc;
@@ -1551,6 +1553,7 @@ make_fresh_key_state ()
 
   key_state = GNUNET_new (struct TEH_KS_StateHandle);
   rfc.key_state = key_state;
+  rfc.now = now;
   key_state->min_dk_expire = GNUNET_TIME_UNIT_FOREVER_ABS;
   key_state->denomkey_map = GNUNET_CONTAINER_multihashmap_create (32,
                                                                   GNUNET_NO);
@@ -1774,9 +1777,9 @@ TEH_KS_release_ (const char *location,
  * @return the key state, NULL on error (usually pretty fatal)
  */
 struct TEH_KS_StateHandle *
-TEH_KS_acquire_ (const char *location)
+TEH_KS_acquire_ (struct GNUNET_TIME_Absolute now,
+                 const char *location)
 {
-  struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
   struct TEH_KS_StateHandle *key_state;
   unsigned int rcd;
 
@@ -1795,7 +1798,7 @@ TEH_KS_acquire_ (const char *location)
   }
   if (NULL == internal_key_state)
   {
-    internal_key_state = make_fresh_key_state ();
+    internal_key_state = make_fresh_key_state (now);
     /* bump RC by 1 if we released internal_key_state above */
     if (NULL == internal_key_state)
     {
@@ -2041,7 +2044,7 @@ TEH_KS_loop (void)
     }
     /* This will re-initialize 'internal_key_state' with
        an initial refcnt of 1 */
-    if (NULL == TEH_KS_acquire ())
+    if (NULL == TEH_KS_acquire (GNUNET_TIME_absolute_get ()))
     {
       ret = GNUNET_SYSERR;
       break;
@@ -2133,7 +2136,7 @@ TEH_KS_sign (const struct 
GNUNET_CRYPTO_EccSignaturePurpose *purpose,
 {
   struct TEH_KS_StateHandle *key_state;
 
-  key_state = TEH_KS_acquire ();
+  key_state = TEH_KS_acquire (GNUNET_TIME_absolute_get ());
   if (NULL == key_state)
   {
     /* This *can* happen if the exchange's keys are
@@ -2195,34 +2198,57 @@ TEH_KS_handler_keys (struct TEH_RequestHandler *rh,
 {
   struct TEH_KS_StateHandle *key_state;
   int ret;
-  const char *have;
+  const char *have_cherrypick;
+  const char *have_fakenow;
   struct GNUNET_TIME_Absolute last_issue_date;
+  struct GNUNET_TIME_Absolute now;
   const struct KeysResponseData *krd;
 
-  have = MHD_lookup_connection_value (connection,
-                                     MHD_GET_ARGUMENT_KIND,
-                                     "last_issue_date");
-  if (NULL != have)
+  have_cherrypick = MHD_lookup_connection_value (connection,
+                                                 MHD_GET_ARGUMENT_KIND,
+                                                 "last_issue_date");
+  if (NULL != have_cherrypick)
   {
-    unsigned long long haven;
+    unsigned long long cherrypickn;
 
     if (1 !=
-       sscanf (have,
+       sscanf (have_cherrypick,
                "%llu",
-               &haven))
+               &cherrypickn))
     {
       GNUNET_break_op (0);
       return TEH_RESPONSE_reply_arg_invalid (connection,
                                             TALER_EC_KEYS_HAVE_NOT_NUMERIC,
-                                            "have");
+                                            "last_issue_date");
     }
-    last_issue_date.abs_value_us = (uint64_t) haven * 1000000LLU;
+    last_issue_date.abs_value_us = (uint64_t) cherrypickn * 1000000LLU;
   }
   else
   {
     last_issue_date.abs_value_us = 0LLU;
   }
-  key_state = TEH_KS_acquire ();
+  now = GNUNET_TIME_absolute_get ();
+  have_fakenow = MHD_lookup_connection_value (connection,
+                                              MHD_GET_ARGUMENT_KIND,
+                                              "now");
+  if (NULL != have_fakenow)
+  {
+    unsigned long long fakenown;
+
+    if (1 !=
+       sscanf (have_fakenow,
+               "%llu",
+               &fakenown))
+    {
+      GNUNET_break_op (0);
+      return TEH_RESPONSE_reply_arg_invalid (connection,
+                                            TALER_EC_KEYS_HAVE_NOT_NUMERIC,
+                                            "now");
+    }
+    now.abs_value_us = (uint64_t) fakenown * 1000000LLU;
+  }
+
+  key_state = TEH_KS_acquire (now);
   if (NULL == key_state)
   {
     TALER_LOG_ERROR ("Lacking keys to operate\n");
diff --git a/src/exchange/taler-exchange-httpd_keystate.h 
b/src/exchange/taler-exchange-httpd_keystate.h
index 29e8cd50..62d69373 100644
--- a/src/exchange/taler-exchange-httpd_keystate.h
+++ b/src/exchange/taler-exchange-httpd_keystate.h
@@ -45,7 +45,8 @@ struct TEH_KS_StateHandle;
  * @return the key state, NULL on error (usually pretty fatal)
  */
 struct TEH_KS_StateHandle *
-TEH_KS_acquire_ (const char *location);
+TEH_KS_acquire_ (struct GNUNET_TIME_Absolute now,
+                 const char *location);
 
 
 /**
@@ -64,9 +65,11 @@ TEH_KS_release_ (const char *location,
  * For every call to #TEH_KS_acquire(), a matching call
  * to #TEH_KS_release() must be made.
  *
+ * @param now current time snapshot; either true, or given by the
+ *        client via the "now" URL parameter of "/keys".
  * @return the key state
  */
-#define TEH_KS_acquire(void) TEH_KS_acquire_(__FUNCTION__)
+#define TEH_KS_acquire(now) TEH_KS_acquire_(now, __FUNCTION__)
 
 
 /**
diff --git a/src/exchange/taler-exchange-httpd_payback.c 
b/src/exchange/taler-exchange-httpd_payback.c
index 877a3ce2..2164863e 100644
--- a/src/exchange/taler-exchange-httpd_payback.c
+++ b/src/exchange/taler-exchange-httpd_payback.c
@@ -318,7 +318,7 @@ verify_and_execute_payback (struct MHD_Connection 
*connection,
   int mhd_ret;
 
   /* check denomination exists and is in payback mode */
-  key_state = TEH_KS_acquire ();
+  key_state = TEH_KS_acquire (GNUNET_TIME_absolute_get ());
   if (NULL == key_state)
   {
     TALER_LOG_ERROR ("Lacking keys to operate\n");
diff --git a/src/exchange/taler-exchange-httpd_refresh_melt.c 
b/src/exchange/taler-exchange-httpd_refresh_melt.c
index 81a8aca9..8e776c77 100644
--- a/src/exchange/taler-exchange-httpd_refresh_melt.c
+++ b/src/exchange/taler-exchange-httpd_refresh_melt.c
@@ -455,7 +455,7 @@ TEH_REFRESH_handler_refresh_melt (struct TEH_RequestHandler 
*rh,
   }
 
   /* run actual logic, now that the request was parsed */
-  key_state = TEH_KS_acquire ();
+  key_state = TEH_KS_acquire (GNUNET_TIME_absolute_get ());
   if (NULL == key_state)
   {
     TALER_LOG_ERROR ("Lacking keys to operate\n");
diff --git a/src/exchange/taler-exchange-httpd_refresh_reveal.c 
b/src/exchange/taler-exchange-httpd_refresh_reveal.c
index 6eaa286d..14dd12ad 100644
--- a/src/exchange/taler-exchange-httpd_refresh_reveal.c
+++ b/src/exchange/taler-exchange-httpd_refresh_reveal.c
@@ -579,7 +579,7 @@ handle_refresh_reveal_json (struct MHD_Connection 
*connection,
     int res;
 
     /* Resolve denomination hashes */
-    key_state = TEH_KS_acquire ();
+    key_state = TEH_KS_acquire (GNUNET_TIME_absolute_get ());
     if (NULL == key_state)
     {
       TALER_LOG_ERROR ("Lacking keys to operate\n");
diff --git a/src/exchange/taler-exchange-httpd_refund.c 
b/src/exchange/taler-exchange-httpd_refund.c
index 86915806..92dd54e9 100644
--- a/src/exchange/taler-exchange-httpd_refund.c
+++ b/src/exchange/taler-exchange-httpd_refund.c
@@ -331,7 +331,7 @@ refund_transaction (void *cls,
 
   // FIXME: do this outside of transaction function?
   /* Check refund fee matches fee of denomination key! */
-  mks = TEH_KS_acquire ();
+  mks = TEH_KS_acquire (GNUNET_TIME_absolute_get ());
   if (NULL == mks)
   {
     TALER_LOG_ERROR ("Lacking keys to operate\n");
diff --git a/src/exchange/taler-exchange-httpd_reserve_withdraw.c 
b/src/exchange/taler-exchange-httpd_reserve_withdraw.c
index 1a05326d..370916b0 100644
--- a/src/exchange/taler-exchange-httpd_reserve_withdraw.c
+++ b/src/exchange/taler-exchange-httpd_reserve_withdraw.c
@@ -390,7 +390,7 @@ TEH_RESERVE_handler_reserve_withdraw (struct 
TEH_RequestHandler *rh,
   json_decref (root);
   if (GNUNET_OK != res)
     return (GNUNET_SYSERR == res) ? MHD_NO : MHD_YES;
-  wc.key_state = TEH_KS_acquire ();
+  wc.key_state = TEH_KS_acquire (GNUNET_TIME_absolute_get ());
   if (NULL == wc.key_state)
   {
     TALER_LOG_ERROR ("Lacking keys to operate\n");
diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h
index 711a1323..7c2f6f29 100644
--- a/src/include/taler_testing_lib.h
+++ b/src/include/taler_testing_lib.h
@@ -920,6 +920,22 @@ TALER_TESTING_cmd_exec_keyup (const char *label,
                               const char *config_filename);
 
 /**
+ * Make the "keyup" CMD, with "--timestamp" option.
+ *
+ * @param label command label.
+ * @param config_filename configuration filename.
+ * @param now Unix timestamp representing the fake "now".
+ *
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_exec_keyup_with_now
+  (const char *label,
+   const char *config_filename,
+   struct GNUNET_TIME_Absolute now);
+
+
+/**
  * Make a "auditor sign" CMD.
  *
  * @param label command label
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 4702b29d..9760d91b 100644
--- a/src/lib/test_exchange_api_keys_cherry_picking_new.c
+++ b/src/lib/test_exchange_api_keys_cherry_picking_new.c
@@ -35,6 +35,7 @@
 #include "taler_fakebank_lib.h"
 #include "taler_testing_lib.h"
 
+
 /**
  * Configuration file we use.  One (big) configuration is used
  * for the various components for this test.
@@ -54,6 +55,23 @@
   "test_exchange_api_keys_cherry_picking_extended_2.conf"
 
 /**
+ * Current time.
+ */
+struct GNUNET_TIME_Absolute now;
+
+/**
+ * Adds to the current time.  XXX, open question: shall  we
+ * also _set_ the global current time after the faking?
+ *
+ * @param relative number of _seconds_ to add to the current time.
+ * @return a new absolute time, modified according to @e relative.
+ */
+#define NOWPLUSSECS(secs) \
+  GNUNET_TIME_absolute_add \
+    (now, \
+     GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \
+                                    secs))
+/**
  * Exchange base URL; mainly purpose is to make the compiler happy.
  */
 static char *exchange_url;
@@ -140,20 +158,18 @@ run (void *cls,
                               is->exchanged,
                               SIGUSR1),
     /**
-     * 1 DK with 80s spend duration.
+     * 1 DK with 80s withdraw duration.  Lookahead_sign is 60s.
      */
     TALER_TESTING_cmd_check_keys ("check-keys-1",
                                   1, /* generation */
                                   1),
-
-    TALER_TESTING_cmd_sleep ("sleep",
-                             10),
-
     /**
-     * We set lookahead_sign to 90s.
+     * We now set lookahead_sign to 90s, and fake 10s passed.
      */
-    TALER_TESTING_cmd_exec_keyup ("keyup-2",
-                                  CONFIG_FILE_EXTENDED),
+    TALER_TESTING_cmd_exec_keyup_with_now ("keyup-2",
+                                           CONFIG_FILE_EXTENDED,
+                                           NOWPLUSSECS (10)),
+
     TALER_TESTING_cmd_exec_auditor_sign ("sign-keys-1",
                                          CONFIG_FILE_EXTENDED),
 
@@ -170,10 +186,10 @@ run (void *cls,
                                   2, /* generation */
                                   2),
 
-    TALER_TESTING_cmd_sleep ("sleep",
-                             20),
-    TALER_TESTING_cmd_exec_keyup ("keyup-3",
-                                  CONFIG_FILE_EXTENDED),
+    /* Must fake 20s lapse now.  */
+    TALER_TESTING_cmd_exec_keyup_with_now ("keyup-3",
+                                           CONFIG_FILE_EXTENDED,
+                                           NOWPLUSSECS (20)),
     TALER_TESTING_cmd_exec_auditor_sign ("sign-keys-2",
                                          CONFIG_FILE),
     TALER_TESTING_cmd_signal ("trigger-keys-reload-2",
diff --git a/src/lib/testing_api_cmd_bank_check.c 
b/src/lib/testing_api_cmd_bank_check.c
index 265cba17..67dbc0e1 100644
--- a/src/lib/testing_api_cmd_bank_check.c
+++ b/src/lib/testing_api_cmd_bank_check.c
@@ -335,12 +335,13 @@ check_bank_empty_traits (void *cls,
 struct TALER_TESTING_Command
 TALER_TESTING_cmd_check_bank_empty (const char *label)
 {
-  struct TALER_TESTING_Command cmd;
 
-  cmd.label = label;
-  cmd.run = &check_bank_empty_run;
-  cmd.cleanup = &check_bank_empty_cleanup;
-  cmd.traits = &check_bank_empty_traits;
+  struct TALER_TESTING_Command cmd = {
+    .label = label,
+    .run = &check_bank_empty_run,
+    .cleanup = &check_bank_empty_cleanup,
+    .traits = &check_bank_empty_traits
+  };
   
   return cmd;
 }
@@ -364,16 +365,17 @@ TALER_TESTING_cmd_check_bank_transfer_with_ref
 {
 
   struct BankCheckState *bcs;
-  struct TALER_TESTING_Command cmd;
 
   bcs = GNUNET_new (struct BankCheckState);
   bcs->deposit_reference = deposit_reference;
 
-  cmd.label = label;
-  cmd.cls = bcs;
-  cmd.run = &check_bank_transfer_run;
-  cmd.cleanup = &check_bank_transfer_cleanup;
-  cmd.traits = &check_bank_transfer_traits;
+  struct TALER_TESTING_Command cmd = {
+    .label = label,
+    .cls = bcs,
+    .run = &check_bank_transfer_run,
+    .cleanup = &check_bank_transfer_cleanup,
+    .traits = &check_bank_transfer_traits
+  };
 
   return cmd;
 }
diff --git a/src/lib/testing_api_cmd_exec_keyup.c 
b/src/lib/testing_api_cmd_exec_keyup.c
index 576aab3c..d534db06 100644
--- a/src/lib/testing_api_cmd_exec_keyup.c
+++ b/src/lib/testing_api_cmd_exec_keyup.c
@@ -46,6 +46,18 @@ struct KeyupState
    * Configuration file used by the command.
    */
   const char *config_filename;
+
+  /**
+   * If GNUNET_YES, then the fake @e now value will be
+   * passed to taler-exchange-keyup via the --timestamp
+   * option.
+   */
+  unsigned int with_now;
+
+  /**
+   * User-provided fake now.
+   */
+  struct GNUNET_TIME_Absolute now;
 };
 
 
@@ -63,15 +75,30 @@ keyup_run (void *cls,
 {
   struct KeyupState *ks = cls;
 
-  ks->keyup_proc = GNUNET_OS_start_process
-    (GNUNET_NO,
-     GNUNET_OS_INHERIT_STD_ALL,
-     NULL, NULL, NULL,
-     "taler-exchange-keyup",
-     "taler-exchange-keyup",
-     "-c", ks->config_filename,
-     "-o", "auditor.in",
-     NULL);
+  if (GNUNET_YES == ks->with_now)
+  {
+     ks->keyup_proc = GNUNET_OS_start_process
+      (GNUNET_NO,
+       GNUNET_OS_INHERIT_STD_ALL,
+       NULL, NULL, NULL,
+       "taler-exchange-keyup",
+       "taler-exchange-keyup",
+       "-c", ks->config_filename,
+       "-o", "auditor.in",
+       "--timestamp",
+       GNUNET_STRINGS_absolute_time_to_string (ks->now),
+       NULL);
+  }
+  else
+    ks->keyup_proc = GNUNET_OS_start_process
+      (GNUNET_NO,
+       GNUNET_OS_INHERIT_STD_ALL,
+       NULL, NULL, NULL,
+       "taler-exchange-keyup",
+       "taler-exchange-keyup",
+       "-c", ks->config_filename,
+       "-o", "auditor.in",
+       NULL);
 
   if (NULL == ks->keyup_proc)
   {
@@ -139,6 +166,39 @@ keyup_traits (void *cls,
 
 
 /**
+ * Make the "keyup" CMD, with "--timestamp" option.
+ *
+ * @param label command label.
+ * @param config_filename configuration filename.
+ * @param now Unix timestamp representing the fake "now".
+ *
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_exec_keyup_with_now
+  (const char *label,
+   const char *config_filename,
+   struct GNUNET_TIME_Absolute now)
+{
+  struct KeyupState *ks;
+
+  ks = GNUNET_new (struct KeyupState);
+  ks->config_filename = config_filename;
+  ks->now = now;
+  ks->with_now = GNUNET_YES;
+
+  struct TALER_TESTING_Command cmd = {
+    .cls = ks,
+    .label = label,
+    .run = &keyup_run,
+    .cleanup = &keyup_cleanup,
+    .traits = &keyup_traits
+  };
+
+  return cmd;
+}
+
+/**
  * Make the "keyup" CMD.
  *
  * @param label command label.

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]