gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated: implement timeout_ms on server


From: gnunet
Subject: [taler-anastasis] branch master updated: implement timeout_ms on server side
Date: Sat, 13 Mar 2021 10:34:54 +0100

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

grothoff pushed a commit to branch master
in repository anastasis.

The following commit(s) were added to refs/heads/master by this push:
     new 79eb7d0  implement timeout_ms on server side
79eb7d0 is described below

commit 79eb7d0e4fae3219cec7fabe0bcdd247b74ff367
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sat Mar 13 10:34:50 2021 +0100

    implement timeout_ms on server side
---
 src/backend/anastasis-httpd_policy_upload.c | 48 +++++++++++++++++++++++++----
 src/backend/anastasis-httpd_truth_upload.c  | 43 +++++++++++++++++++++++++-
 2 files changed, 84 insertions(+), 7 deletions(-)

diff --git a/src/backend/anastasis-httpd_policy_upload.c 
b/src/backend/anastasis-httpd_policy_upload.c
index 9503a44..126a3a7 100644
--- a/src/backend/anastasis-httpd_policy_upload.c
+++ b/src/backend/anastasis-httpd_policy_upload.c
@@ -116,6 +116,11 @@ struct PolicyUploadContext
    */
   struct GNUNET_TIME_Absolute existing_pi_timestamp;
 
+  /**
+   * When does the operation timeout?
+   */
+  struct GNUNET_TIME_Absolute timeout;
+
   /**
    * Expected total upload size.
    */
@@ -476,9 +481,11 @@ check_payment_cb (void *cls,
  * @param timeout when to give up trying
  */
 static void
-await_payment (struct PolicyUploadContext *puc,
-               struct GNUNET_TIME_Relative timeout)
+await_payment (struct PolicyUploadContext *puc)
 {
+  struct GNUNET_TIME_Relative timeout
+    = GNUNET_TIME_absolute_get_remaining (puc->timeout);
+
   GNUNET_CONTAINER_DLL_insert (puc_head,
                                puc_tail,
                                puc);
@@ -538,8 +545,7 @@ begin_payment (struct PolicyUploadContext *puc)
 
   if (0 != puc->existing_pi_timestamp.abs_value_us)
   {
-    await_payment (puc,
-                   GNUNET_TIME_UNIT_ZERO);
+    await_payment (puc);
     return MHD_YES;
   }
 
@@ -600,8 +606,7 @@ prepare_payment (struct PolicyUploadContext *puc)
       sizeof (struct ANASTASIS_PaymentSecretP));
     return begin_payment (puc);
   }
-  await_payment (puc,
-                 CHECK_PAYMENT_GENERIC_TIMEOUT);
+  await_payment (puc);
   return MHD_YES;
 }
 
@@ -894,6 +899,37 @@ AH_handler_policy_post (
         break;
       }
     }
+    {
+      const char *long_poll_timeout_ms;
+
+      long_poll_timeout_ms = MHD_lookup_connection_value (connection,
+                                                          
MHD_GET_ARGUMENT_KIND,
+                                                          "timeout_ms");
+      if (NULL != long_poll_timeout_ms)
+      {
+        unsigned int timeout;
+
+        if (1 != sscanf (long_poll_timeout_ms,
+                         "%u",
+                         &timeout))
+        {
+          GNUNET_break_op (0);
+          return TALER_MHD_reply_with_error (connection,
+                                             MHD_HTTP_BAD_REQUEST,
+                                             
TALER_EC_GENERIC_PARAMETER_MALFORMED,
+                                             "timeout_ms (must be non-negative 
number)");
+        }
+        puc->timeout
+          = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply (
+                                                GNUNET_TIME_UNIT_MILLISECONDS,
+                                                timeout));
+      }
+      else
+      {
+        puc->timeout = GNUNET_TIME_relative_to_absolute
+                         (CHECK_PAYMENT_GENERIC_TIMEOUT);
+      }
+    }
     /* ready to begin! */
     return MHD_YES;
   }
diff --git a/src/backend/anastasis-httpd_truth_upload.c 
b/src/backend/anastasis-httpd_truth_upload.c
index 6b38c39..575ff1f 100644
--- a/src/backend/anastasis-httpd_truth_upload.c
+++ b/src/backend/anastasis-httpd_truth_upload.c
@@ -78,6 +78,11 @@ struct TruthUploadContext
    */
   struct MHD_Response *resp;
 
+  /**
+   * When should this request time out?
+   */
+  struct GNUNET_TIME_Absolute timeout;
+
   /**
    * HTTP response code to use on resume, if resp is set.
    */
@@ -385,7 +390,9 @@ static MHD_RESULT
 begin_payment (struct TruthUploadContext *tuc)
 {
   char *order_id;
+  struct GNUNET_TIME_Relative timeout;
 
+  timeout = GNUNET_TIME_absolute_get_remaining (tuc->timeout);
   order_id = GNUNET_STRINGS_data_to_string_alloc (
     &tuc->truth_uuid,
     sizeof (tuc->truth_uuid));
@@ -394,7 +401,7 @@ begin_payment (struct TruthUploadContext *tuc)
                                                 order_id,
                                                 NULL /* our payments are NOT 
session-bound */,
                                                 false,
-                                                GNUNET_TIME_UNIT_SECONDS,
+                                                timeout,
                                                 &check_payment_cb,
                                                 tuc);
   GNUNET_free (order_id);
@@ -506,6 +513,40 @@ AH_handler_truth_post (
           return begin_payment (tuc);
       }
     }
+
+    {
+      const char *long_poll_timeout_ms;
+
+      long_poll_timeout_ms = MHD_lookup_connection_value (connection,
+                                                          
MHD_GET_ARGUMENT_KIND,
+                                                          "timeout_ms");
+      if (NULL != long_poll_timeout_ms)
+      {
+        unsigned int timeout;
+
+        if (1 != sscanf (long_poll_timeout_ms,
+                         "%u",
+                         &timeout))
+        {
+          GNUNET_break_op (0);
+          return TALER_MHD_reply_with_error (connection,
+                                             MHD_HTTP_BAD_REQUEST,
+                                             
TALER_EC_GENERIC_PARAMETER_MALFORMED,
+                                             "timeout_ms (must be non-negative 
number)");
+        }
+        tuc->timeout
+          = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply (
+                                                GNUNET_TIME_UNIT_MILLISECONDS,
+                                                timeout));
+      }
+      else
+      {
+        tuc->timeout = GNUNET_TIME_relative_to_absolute (
+          GNUNET_TIME_UNIT_SECONDS);
+      }
+    }
+
+
   } /* end 'if (NULL == tuc)' */
 
   if (NULL != tuc->resp)

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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