gnunet-svn
[Top][All Lists]
Advanced

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

[taler-exchange] branch master updated (15489275 -> f76e7c46)


From: gnunet
Subject: [taler-exchange] branch master updated (15489275 -> f76e7c46)
Date: Thu, 19 Mar 2020 19:33:23 +0100

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

grothoff pushed a change to branch master
in repository exchange.

    from 15489275 make DB reset optional in API, use it in tests, but not in 
the benchmark
     new 749d9615 concurrency requires strtok_r
     new 5e98c065 fix macro causing syntax issues
     new f76e7c46 make do_retry not retry forever in tests/benchmark

The 3 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.c                |  9 +++---
 src/include/backoff.h                              |  2 +-
 src/lib/exchange_api_link.c                        |  8 +++++-
 .../testing_api_cmd_auditor_deposit_confirmation.c | 14 +++++++---
 src/testing/testing_api_cmd_auditor_exchanges.c    | 15 +++++++---
 .../testing_api_cmd_bank_admin_add_incoming.c      | 15 +++++++---
 src/testing/testing_api_cmd_bank_transfer.c        | 17 ++++++++----
 src/testing/testing_api_cmd_deposit.c              | 15 +++++++---
 src/testing/testing_api_cmd_refresh.c              | 31 +++++++++++++--------
 src/testing/testing_api_cmd_withdraw.c             | 26 ++++++++++++++----
 src/testing/testing_api_helpers_exchange.c         | 32 ++++++++++++++--------
 11 files changed, 128 insertions(+), 56 deletions(-)

diff --git a/src/exchange/taler-exchange-httpd.c 
b/src/exchange/taler-exchange-httpd.c
index 0754163b..feb599bd 100644
--- a/src/exchange/taler-exchange-httpd.c
+++ b/src/exchange/taler-exchange-httpd.c
@@ -352,21 +352,22 @@ proceed_with_handler (const struct TEH_RequestHandler *rh,
     {
       unsigned int i;
       const char *fin;
+      char *sp;
 
-      /* make a copy of 'url' because 'strtok()' will modify */
+      /* make a copy of 'url' because 'strtok_r()' will modify */
       memcpy (d,
               url,
               ulen);
       i = 0;
-      args[i++] = strtok (d, "/");
+      args[i++] = strtok_r (d, "/", &sp);
       while ( (NULL != args[i - 1]) &&
               (i < rh->nargs) )
-        args[i++] = strtok (NULL, "/");
+        args[i++] = strtok_r (NULL, "/", &sp);
       /* make sure above loop ran nicely until completion, and also
          that there is no excess data in 'd' afterwards */
       if ( (i != rh->nargs) ||
            (NULL == args[i - 1]) ||
-           (NULL != (fin = strtok (NULL, "/"))) )
+           (NULL != (fin = strtok_r (NULL, "/", &sp))) )
       {
         char emsg[128 + 512];
 
diff --git a/src/include/backoff.h b/src/include/backoff.h
index ec59a420..a595fdbd 100644
--- a/src/include/backoff.h
+++ b/src/include/backoff.h
@@ -28,6 +28,6 @@
  */
 #define EXCHANGE_LIB_BACKOFF(r) GNUNET_TIME_randomized_backoff ( \
     (r), \
-    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2));
+    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2))
 
 #endif
diff --git a/src/lib/exchange_api_link.c b/src/lib/exchange_api_link.c
index aa508ecf..75634049 100644
--- a/src/lib/exchange_api_link.c
+++ b/src/lib/exchange_api_link.c
@@ -350,11 +350,13 @@ handle_link_finished (void *cls,
 {
   struct TALER_EXCHANGE_LinkHandle *lh = cls;
   const json_t *j = response;
+  enum TALER_ErrorCode ec;
 
   lh->job = NULL;
   switch (response_code)
   {
   case 0:
+    ec = TALER_EC_INVALID_RESPONSE;
     break;
   case MHD_HTTP_OK:
     if (GNUNET_OK !=
@@ -366,14 +368,17 @@ handle_link_finished (void *cls,
     }
     break;
   case MHD_HTTP_BAD_REQUEST:
+    ec = TALER_JSON_get_error_code (j);
     /* This should never happen, either us or the exchange is buggy
        (or API version conflict); just pass JSON reply to the application */
     break;
   case MHD_HTTP_NOT_FOUND:
+    ec = TALER_JSON_get_error_code (j);
     /* Nothing really to verify, exchange says this coin was not melted; we
        should pass the JSON reply to the application */
     break;
   case MHD_HTTP_INTERNAL_SERVER_ERROR:
+    ec = TALER_JSON_get_error_code (j);
     /* Server had an internal issue; we should retry, but this API
        leaves this to the application */
     break;
@@ -384,12 +389,13 @@ handle_link_finished (void *cls,
                 (unsigned int) response_code);
     GNUNET_break (0);
     response_code = 0;
+    ec = TALER_JSON_get_error_code (j);
     break;
   }
   if (NULL != lh->link_cb)
     lh->link_cb (lh->link_cb_cls,
                  response_code,
-                 TALER_JSON_get_error_code (j),
+                 ec,
                  0,
                  NULL,
                  NULL,
diff --git a/src/testing/testing_api_cmd_auditor_deposit_confirmation.c 
b/src/testing/testing_api_cmd_auditor_deposit_confirmation.c
index 96d0740e..bcef59c5 100644
--- a/src/testing/testing_api_cmd_auditor_deposit_confirmation.c
+++ b/src/testing/testing_api_cmd_auditor_deposit_confirmation.c
@@ -29,6 +29,11 @@
 #include "taler_signatures.h"
 #include "backoff.h"
 
+/**
+ * How often do we retry before giving up?
+ */
+#define NUM_RETRIES 5
+
 
 /**
  * State for a "deposit confirmation" CMD.
@@ -83,9 +88,9 @@ struct DepositConfirmationState
   unsigned int expected_response_code;
 
   /**
-   * Should we retry on (transient) failures?
+   * How often should we retry on (transient) failures?
    */
-  int do_retry;
+  unsigned int do_retry;
 
 };
 
@@ -140,8 +145,9 @@ deposit_confirmation_cb (void *cls,
   dcs->dc = NULL;
   if (dcs->expected_response_code != http_status)
   {
-    if (GNUNET_YES == dcs->do_retry)
+    if (0 != dcs->do_retry)
     {
+      dcs->do_retry--;
       if ( (0 == http_status) ||
            (TALER_EC_DB_COMMIT_FAILED_ON_RETRY == ec) ||
            (MHD_HTTP_INTERNAL_SERVER_ERROR == http_status) )
@@ -436,7 +442,7 @@ TALER_TESTING_cmd_deposit_confirmation_with_retry (struct 
TALER_TESTING_Command
 
   GNUNET_assert (&deposit_confirmation_run == cmd.run);
   dcs = cmd.cls;
-  dcs->do_retry = GNUNET_YES;
+  dcs->do_retry = NUM_RETRIES;
   return cmd;
 }
 
diff --git a/src/testing/testing_api_cmd_auditor_exchanges.c 
b/src/testing/testing_api_cmd_auditor_exchanges.c
index c7acaab9..b5a1cab0 100644
--- a/src/testing/testing_api_cmd_auditor_exchanges.c
+++ b/src/testing/testing_api_cmd_auditor_exchanges.c
@@ -30,6 +30,12 @@
 #include "backoff.h"
 
 
+/**
+ * How often do we retry before giving up?
+ */
+#define NUM_RETRIES 5
+
+
 /**
  * State for a "deposit confirmation" CMD.
  */
@@ -72,9 +78,9 @@ struct ExchangesState
   const char *exchange_url;
 
   /**
-   * Should we retry on (transient) failures?
+   * How often should we retry on (transient) failures?
    */
-  int do_retry;
+  unsigned int do_retry;
 
 };
 
@@ -132,8 +138,9 @@ exchanges_cb (void *cls,
   es->leh = NULL;
   if (es->expected_response_code != http_status)
   {
-    if (GNUNET_YES == es->do_retry)
+    if (0 != es->do_retry)
     {
+      es->do_retry--;
       if ( (0 == http_status) ||
            (TALER_EC_DB_COMMIT_FAILED_ON_RETRY == ec) ||
            (MHD_HTTP_INTERNAL_SERVER_ERROR == http_status) )
@@ -353,7 +360,7 @@ TALER_TESTING_cmd_exchanges_with_retry (struct 
TALER_TESTING_Command cmd)
 
   GNUNET_assert (&exchanges_run == cmd.run);
   es = cmd.cls;
-  es->do_retry = GNUNET_YES;
+  es->do_retry = NUM_RETRIES;
   return cmd;
 }
 
diff --git a/src/testing/testing_api_cmd_bank_admin_add_incoming.c 
b/src/testing/testing_api_cmd_bank_admin_add_incoming.c
index 2398c5be..6e707a2e 100644
--- a/src/testing/testing_api_cmd_bank_admin_add_incoming.c
+++ b/src/testing/testing_api_cmd_bank_admin_add_incoming.c
@@ -32,6 +32,12 @@
 #include "taler_testing_lib.h"
 
 
+/**
+ * How often do we retry before giving up?
+ */
+#define NUM_RETRIES 5
+
+
 /**
  * State for a "fakebank transfer" CMD.
  */
@@ -120,9 +126,9 @@ struct AdminAddIncomingState
   /**
    * Was this command modified via
    * #TALER_TESTING_cmd_admin_add_incoming_with_retry to
-   * enable retries?
+   * enable retries? If so, how often should we still retry?
    */
-  int do_retry;
+  unsigned int do_retry;
 };
 
 
@@ -184,8 +190,9 @@ confirmation_cb (void *cls,
   fts->aih = NULL;
   if (MHD_HTTP_OK != http_status)
   {
-    if (GNUNET_YES == fts->do_retry)
+    if (0 != fts->do_retry)
     {
+      fts->do_retry--;
       if ( (0 == http_status) ||
            (TALER_EC_DB_COMMIT_FAILED_ON_RETRY == ec) ||
            (MHD_HTTP_INTERNAL_SERVER_ERROR == http_status) )
@@ -588,7 +595,7 @@ TALER_TESTING_cmd_admin_add_incoming_retry (struct 
TALER_TESTING_Command cmd)
 
   GNUNET_assert (&admin_add_incoming_run == cmd.run);
   fts = cmd.cls;
-  fts->do_retry = GNUNET_YES;
+  fts->do_retry = NUM_RETRIES;
   return cmd;
 }
 
diff --git a/src/testing/testing_api_cmd_bank_transfer.c 
b/src/testing/testing_api_cmd_bank_transfer.c
index f8dfc0b8..03bf5973 100644
--- a/src/testing/testing_api_cmd_bank_transfer.c
+++ b/src/testing/testing_api_cmd_bank_transfer.c
@@ -32,6 +32,12 @@
 #include "taler_testing_lib.h"
 
 
+/**
+ * How often do we retry before giving up?
+ */
+#define NUM_RETRIES 5
+
+
 /**
  * State for a "transfer" CMD.
  */
@@ -113,9 +119,9 @@ struct TransferState
   /**
    * Was this command modified via
    * #TALER_TESTING_cmd_admin_add_incoming_with_retry to
-   * enable retries?
+   * enable retries? If so, how often should we still retry?
    */
-  int do_retry;
+  unsigned int do_retry;
 };
 
 
@@ -175,8 +181,9 @@ confirmation_cb (void *cls,
   fts->weh = NULL;
   if (MHD_HTTP_OK != http_status)
   {
-    if (GNUNET_YES == fts->do_retry)
+    if (0 != fts->do_retry)
     {
+      fts->do_retry--;
       if ( (0 == http_status) ||
            (TALER_EC_DB_COMMIT_FAILED_ON_RETRY == ec) ||
            (MHD_HTTP_INTERNAL_SERVER_ERROR == http_status) )
@@ -397,9 +404,9 @@ TALER_TESTING_cmd_transfer_retry (struct 
TALER_TESTING_Command cmd)
 
   GNUNET_assert (&transfer_run == cmd.run);
   fts = cmd.cls;
-  fts->do_retry = GNUNET_YES;
+  fts->do_retry = NUM_RETRIES;
   return cmd;
 }
 
 
-/* end of testing_api_cmd_transfer.c */
+/* end of testing_api_cmd_bank_transfer.c */
diff --git a/src/testing/testing_api_cmd_deposit.c 
b/src/testing/testing_api_cmd_deposit.c
index 573c68b9..6781568a 100644
--- a/src/testing/testing_api_cmd_deposit.c
+++ b/src/testing/testing_api_cmd_deposit.c
@@ -29,6 +29,12 @@
 #include "backoff.h"
 
 
+/**
+ * How often do we retry before giving up?
+ */
+#define NUM_RETRIES 5
+
+
 /**
  * State for a "deposit" CMD.
  */
@@ -104,9 +110,9 @@ struct DepositState
   unsigned int expected_response_code;
 
   /**
-   * Should we retry on (transient) failures?
+   * How often should we retry on (transient) failures?
    */
-  int do_retry;
+  unsigned int do_retry;
 
   /**
    * Set to #GNUNET_YES if the /deposit succeeded
@@ -184,8 +190,9 @@ deposit_cb (void *cls,
   ds->dh = NULL;
   if (ds->expected_response_code != http_status)
   {
-    if (GNUNET_YES == ds->do_retry)
+    if (0 != ds->do_retry)
     {
+      ds->do_retry--;
       if ( (0 == http_status) ||
            (TALER_EC_DB_COMMIT_FAILED_ON_RETRY == ec) ||
            (MHD_HTTP_INTERNAL_SERVER_ERROR == http_status) )
@@ -559,7 +566,7 @@ TALER_TESTING_cmd_deposit_with_retry (struct 
TALER_TESTING_Command cmd)
 
   GNUNET_assert (&deposit_run == cmd.run);
   ds = cmd.cls;
-  ds->do_retry = GNUNET_YES;
+  ds->do_retry = NUM_RETRIES;
   return cmd;
 }
 
diff --git a/src/testing/testing_api_cmd_refresh.c 
b/src/testing/testing_api_cmd_refresh.c
index dd861fae..2f91df37 100644
--- a/src/testing/testing_api_cmd_refresh.c
+++ b/src/testing/testing_api_cmd_refresh.c
@@ -28,6 +28,10 @@
 #include "taler_signatures.h"
 #include "backoff.h"
 
+/**
+ * How often do we retry before giving up?
+ */
+#define NUM_RETRIES 5
 
 /**
  * Information about a fresh coin generated by the refresh
@@ -149,9 +153,9 @@ struct RefreshMeltState
   unsigned int double_melt;
 
   /**
-   * Should we retry on (transient) failures?
+   * How often should we retry on (transient) failures?
    */
-  int do_retry;
+  unsigned int do_retry;
 
   /**
    * Set by the melt callback as it comes from the exchange.
@@ -210,9 +214,9 @@ struct RefreshRevealState
   unsigned int expected_response_code;
 
   /**
-   * Should we retry on (transient) failures?
+   * How often should we retry on (transient) failures?
    */
-  int do_retry;
+  unsigned int do_retry;
 
 };
 
@@ -253,9 +257,9 @@ struct RefreshLinkState
   unsigned int expected_response_code;
 
   /**
-   * Should we retry on (transient) failures?
+   * How often should we retry on (transient) failures?
    */
-  int do_retry;
+  unsigned int do_retry;
 
 };
 
@@ -322,8 +326,9 @@ reveal_cb (void *cls,
   rrs->rrh = NULL;
   if (rrs->expected_response_code != http_status)
   {
-    if (GNUNET_YES == rrs->do_retry)
+    if (0 != rrs->do_retry)
     {
+      rrs->do_retry--;
       if ( (0 == http_status) ||
            (TALER_EC_DB_COMMIT_FAILED_ON_RETRY == ec) ||
            (MHD_HTTP_INTERNAL_SERVER_ERROR == http_status) )
@@ -548,8 +553,9 @@ link_cb (void *cls,
   rls->rlh = NULL;
   if (rls->expected_response_code != http_status)
   {
-    if (GNUNET_YES == rls->do_retry)
+    if (0 != rls->do_retry)
     {
+      rls->do_retry--;
       if ( (0 == http_status) ||
            (TALER_EC_DB_COMMIT_FAILED_ON_RETRY == ec) ||
            (MHD_HTTP_INTERNAL_SERVER_ERROR == http_status) )
@@ -830,8 +836,9 @@ melt_cb (void *cls,
   rms->rmh = NULL;
   if (rms->expected_response_code != http_status)
   {
-    if (GNUNET_YES == rms->do_retry)
+    if (0 != rms->do_retry)
     {
+      rms->do_retry--;
       if ( (0 == http_status) ||
            (TALER_EC_DB_COMMIT_FAILED_ON_RETRY == ec) ||
            (MHD_HTTP_INTERNAL_SERVER_ERROR == http_status) )
@@ -1246,7 +1253,7 @@ TALER_TESTING_cmd_melt_with_retry (struct 
TALER_TESTING_Command cmd)
 
   GNUNET_assert (&melt_run == cmd.run);
   rms = cmd.cls;
-  rms->do_retry = GNUNET_YES;
+  rms->do_retry = NUM_RETRIES;
   return cmd;
 }
 
@@ -1356,7 +1363,7 @@ TALER_TESTING_cmd_refresh_reveal_with_retry (struct 
TALER_TESTING_Command cmd)
 
   GNUNET_assert (&refresh_reveal_run == cmd.run);
   rrs = cmd.cls;
-  rrs->do_retry = GNUNET_YES;
+  rrs->do_retry = NUM_RETRIES;
   return cmd;
 }
 
@@ -1405,6 +1412,6 @@ TALER_TESTING_cmd_refresh_link_with_retry (struct 
TALER_TESTING_Command cmd)
 
   GNUNET_assert (&refresh_link_run == cmd.run);
   rls = cmd.cls;
-  rls->do_retry = GNUNET_YES;
+  rls->do_retry = NUM_RETRIES;
   return cmd;
 }
diff --git a/src/testing/testing_api_cmd_withdraw.c 
b/src/testing/testing_api_cmd_withdraw.c
index 96412156..b2fc272e 100644
--- a/src/testing/testing_api_cmd_withdraw.c
+++ b/src/testing/testing_api_cmd_withdraw.c
@@ -31,6 +31,17 @@
 #include "backoff.h"
 
 
+/**
+ * How often do we retry before giving up?
+ */
+#define NUM_RETRIES 15
+
+/**
+ * How long do we wait AT LEAST if the exchange says the reserve is unknown?
+ */
+#define UNKNOWN_MIN_BACKOFF GNUNET_TIME_relative_multiply ( \
+    GNUNET_TIME_UNIT_MILLISECONDS, 100)
+
 /**
  * State for a "withdraw" CMD.
  */
@@ -100,9 +111,9 @@ struct WithdrawState
   /**
    * Was this command modified via
    * #TALER_TESTING_cmd_withdraw_with_retry to
-   * enable retries?
+   * enable retries? How often should we still retry?
    */
-  int do_retry;
+  unsigned int do_retry;
 };
 
 
@@ -160,8 +171,10 @@ reserve_withdraw_cb (void *cls,
   ws->wsh = NULL;
   if (ws->expected_response_code != http_status)
   {
-    if (GNUNET_YES == ws->do_retry)
+    if (0 != ws->do_retry)
     {
+      if (TALER_EC_WITHDRAW_RESERVE_UNKNOWN != ec)
+        ws->do_retry--; /* we don't count reserve unknown as failures here */
       if ( (0 == http_status) ||
            (TALER_EC_DB_COMMIT_FAILED_ON_RETRY == ec) ||
            (TALER_EC_WITHDRAW_INSUFFICIENT_FUNDS == ec) ||
@@ -175,8 +188,11 @@ reserve_withdraw_cb (void *cls,
         /* on DB conflicts, do not use backoff */
         if (TALER_EC_DB_COMMIT_FAILED_ON_RETRY == ec)
           ws->backoff = GNUNET_TIME_UNIT_ZERO;
-        else
+        else if (TALER_EC_WITHDRAW_RESERVE_UNKNOWN != ec)
           ws->backoff = EXCHANGE_LIB_BACKOFF (ws->backoff);
+        else
+          ws->backoff = GNUNET_TIME_relative_max (UNKNOWN_MIN_BACKOFF,
+                                                  ws->backoff);
         ws->retry_task = GNUNET_SCHEDULER_add_delayed (ws->backoff,
                                                        &do_retry,
                                                        ws);
@@ -526,7 +542,7 @@ TALER_TESTING_cmd_withdraw_with_retry (struct 
TALER_TESTING_Command cmd)
 
   GNUNET_assert (&withdraw_run == cmd.run);
   ws = cmd.cls;
-  ws->do_retry = GNUNET_YES;
+  ws->do_retry = NUM_RETRIES;
   return cmd;
 }
 
diff --git a/src/testing/testing_api_helpers_exchange.c 
b/src/testing/testing_api_helpers_exchange.c
index bed6bc8d..56f8bd54 100644
--- a/src/testing/testing_api_helpers_exchange.c
+++ b/src/testing/testing_api_helpers_exchange.c
@@ -368,6 +368,11 @@ struct SignInfo
    * calling #TALER_TESTING_sign_keys_for_exchange.
    */
   const char *auditor_sign_input_filename;
+
+  /**
+   * Did we reset the database?
+   */
+  int db_reset;
 };
 
 
@@ -448,23 +453,25 @@ sign_keys_for_exchange (void *cls,
     ret = GNUNET_SYSERR;
     goto fail;
   }
-  if (GNUNET_OK !=
-      TALER_TESTING_run_auditor_exchange (si->config_filename,
-                                          exchange_master_pub,
-                                          si->ec->exchange_url,
-                                          GNUNET_NO))
+  if ( (GNUNET_OK !=
+        TALER_TESTING_run_auditor_exchange (si->config_filename,
+                                            exchange_master_pub,
+                                            si->ec->exchange_url,
+                                            GNUNET_NO)) &&
+       (GNUNET_YES == si->db_reset) )
   {
     GNUNET_free (signed_keys_out);
     ret = GNUNET_NO;
     goto fail;
   }
 
-  if (GNUNET_OK !=
-      TALER_TESTING_run_auditor_sign (si->config_filename,
-                                      exchange_master_pub,
-                                      si->ec->auditor_url,
-                                      si->auditor_sign_input_filename,
-                                      signed_keys_out))
+  if ( (GNUNET_OK !=
+        TALER_TESTING_run_auditor_sign (si->config_filename,
+                                        exchange_master_pub,
+                                        si->ec->auditor_url,
+                                        si->auditor_sign_input_filename,
+                                        signed_keys_out)) &&
+       (GNUNET_YES == si->db_reset) )
   {
     GNUNET_free (signed_keys_out);
     GNUNET_free (exchange_master_pub);
@@ -503,7 +510,8 @@ TALER_TESTING_prepare_exchange (const char *config_filename,
   struct SignInfo si = {
     .config_filename = config_filename,
     .ec = ec,
-    .auditor_sign_input_filename = "auditor.in"
+    .auditor_sign_input_filename = "auditor.in",
+    .db_reset = reset_db
   };
 
   if (GNUNET_OK !=

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



reply via email to

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