gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-twister] 02/02: Creating more machine states.


From: gnunet
Subject: [GNUnet-SVN] [taler-twister] 02/02: Creating more machine states.
Date: Wed, 15 May 2019 20:42:41 +0200

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

marcello pushed a commit to branch master
in repository twister.

commit c34ddfff2a79814068daae65746ddca2256158d8
Author: Marcello Stanisci <address@hidden>
AuthorDate: Wed May 15 20:42:18 2019 +0200

    Creating more machine states.
---
 src/twister/taler-twister-service.c | 131 ++++++++++++++++++++----------------
 1 file changed, 74 insertions(+), 57 deletions(-)

diff --git a/src/twister/taler-twister-service.c 
b/src/twister/taler-twister-service.c
index 5b0b748..82a009a 100644
--- a/src/twister/taler-twister-service.c
+++ b/src/twister/taler-twister-service.c
@@ -81,22 +81,32 @@ enum RequestState
   /**
    * We've started receiving upload data from MHD.
    */
-  REQUEST_STATE_UPLOAD_STARTED,
+  REQUEST_STATE_CLIENT_UPLOAD_STARTED,
+
+  /**
+   * Wa have started uploading data to the proxied service.
+   */
+  REQUEST_STATE_PROXY_UPLOAD_STARTED,
 
   /**
    * We're done with the upload from MHD.
    */
-  REQUEST_STATE_UPLOAD_DONE,
+  REQUEST_STATE_CLIENT_UPLOAD_DONE,
+
+  /**
+   * We're done uploading data to the proxied service.
+   */
+  REQUEST_STATE_PROXY_UPLOAD_DONE,
 
   /**
    * We've finished uploading data via CURL and can now download.
    */
-  REQUEST_STATE_DOWNLOAD_STARTED,
+  REQUEST_STATE_PROXY_DOWNLOAD_STARTED,
 
   /**
    * We've finished receiving download data from cURL.
    */
-  REQUEST_STATE_DOWNLOAD_DONE
+  REQUEST_STATE_PROXY_DOWNLOAD_DONE
 };
 
 
@@ -159,12 +169,6 @@ struct HttpRequest
   struct GNUNET_SCHEDULER_Task *wtask;
 
   /**
-   * Buffer we use for moving data between MHD and
-   * curl (in both directions).
-   */
-  char *io_buf;
-
-  /**
    * Hold the response obtained by modifying the original one.
    */
   struct MHD_Response *mod_response;
@@ -205,14 +209,15 @@ struct HttpRequest
   struct HttpResponseHeader *header_tail;
 
   /**
-   * Number of bytes already in the IO buffer.
+   * Buffer we use for moving data between MHD and
+   * curl (in both directions).
    */
-  size_t io_len;
+  char *io_buf;
 
   /**
-   * HTTP response code to give to MHD for the response.
+   * Number of bytes already in the IO buffer.
    */
-  unsigned int response_code;
+  size_t io_len;
 
   /**
    * Number of bytes allocated for the IO buffer.
@@ -220,6 +225,11 @@ struct HttpRequest
   unsigned int io_size;
 
   /**
+   * HTTP response code to give to MHD for the response.
+   */
+  unsigned int response_code;
+
+  /**
    * Request processing state machine.
    */
   enum RequestState state;
@@ -524,8 +534,7 @@ curl_download_cb (void *ptr,
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Curl download proceeding\n");
 
-  if ( (REQUEST_STATE_UPLOAD_STARTED == hr->state) ||
-       (REQUEST_STATE_UPLOAD_DONE == hr->state) )
+  if (REQUEST_STATE_PROXY_UPLOAD_STARTED == hr->state)
   {
     /* Web server started with response before we finished
        the upload.  In this case, current libcurl decides
@@ -535,24 +544,23 @@ curl_download_cb (void *ptr,
        with uploads without "Expect: 100 Continue" and
        Web servers responding with an error (i.e. upload
        not allowed) */
-    hr->state = REQUEST_STATE_DOWNLOAD_STARTED;
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                "Stopping %u byte upload: we are already downloading...\n",
-                (unsigned int) hr->io_len);
+    hr->state = REQUEST_STATE_PROXY_DOWNLOAD_STARTED;
+    GNUNET_log
+      (GNUNET_ERROR_TYPE_INFO,
+       "Stopping %u byte upload: we are already downloading...\n",
+       (unsigned int) hr->io_len);
     hr->io_len = 0;
   }
 
-  if (REQUEST_STATE_DOWNLOAD_STARTED != hr->state)
+  if (REQUEST_STATE_PROXY_DOWNLOAD_STARTED != hr->state)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Download callback goes to sleep\n");
     hr->curl_paused = GNUNET_YES;
     return CURL_WRITEFUNC_PAUSE;
   }
-
   GNUNET_assert
-    (REQUEST_STATE_DOWNLOAD_STARTED == hr->state);
-
+    (REQUEST_STATE_PROXY_DOWNLOAD_STARTED == hr->state);
   if (hr->io_size - hr->io_len < total)
   {
     GNUNET_assert (total + hr->io_size >= total);
@@ -599,24 +607,32 @@ curl_upload_cb (void *buf,
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Upload cb is working...\n");
-  if ( (REQUEST_STATE_UPLOAD_STARTED != hr->state) &&
-       (REQUEST_STATE_UPLOAD_DONE != hr->state) )
+
+  if ( (REQUEST_STATE_PROXY_DOWNLOAD_STARTED == hr->state) ||
+       (REQUEST_STATE_PROXY_DOWNLOAD_DONE == hr->state) )
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                "Upload cb aborts: we are already downloading...\n");
+    GNUNET_log
+      (GNUNET_ERROR_TYPE_INFO,
+       "Upload cb aborts: we are already downloading...\n");
     return CURL_READFUNC_ABORT;
   }
+  
   if ( (0 == hr->io_len) &&
-       (REQUEST_STATE_UPLOAD_DONE != hr->state) )
+      (REQUEST_STATE_PROXY_UPLOAD_STARTED == hr->state) )
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Pausing CURL UPLOAD, need more data\n");
     return CURL_READFUNC_PAUSE;
   }
+
+  /**
+   * We got rescheduled because the download callback was asleep.
+   * FIXME: can this block be eliminated and the unpausing being
+   * moved in the last block where we return zero as well?
+   */
   if ( (0 == hr->io_len) &&
-       (REQUEST_STATE_UPLOAD_DONE == hr->state) )
+       (REQUEST_STATE_PROXY_DOWNLOAD_STARTED == hr->state) )
   {
-    hr->state = REQUEST_STATE_DOWNLOAD_STARTED;
     if (GNUNET_YES == hr->curl_paused)
     {
       hr->curl_paused = GNUNET_NO;
@@ -640,7 +656,7 @@ curl_upload_cb (void *buf,
   hr->io_len -= to_copy;
   if (0 == hr->io_len)
   {
-    hr->state = REQUEST_STATE_DOWNLOAD_STARTED;
+    hr->state = REQUEST_STATE_PROXY_DOWNLOAD_STARTED;
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Completed CURL UPLOAD\n");
   }
@@ -794,7 +810,7 @@ curl_task_download (void *cls)
               if (NULL == hr->response)
                 GNUNET_assert (GNUNET_OK ==
                               create_mhd_response_from_hr (hr));
-              hr->state = REQUEST_STATE_DOWNLOAD_DONE;
+              hr->state = REQUEST_STATE_PROXY_DOWNLOAD_DONE;
              if (GNUNET_YES == hr->suspended)
              {
                MHD_resume_connection (hr->con);
@@ -808,7 +824,7 @@ curl_task_download (void *cls)
                           curl_easy_strerror (msg->data.result));
               /* FIXME: indicate error somehow?
                * close MHD connection badly as well? */
-              hr->state = REQUEST_STATE_DOWNLOAD_DONE;
+              hr->state = REQUEST_STATE_PROXY_DOWNLOAD_DONE;
              if (GNUNET_YES == hr->suspended)
              {
                MHD_resume_connection (hr->con);
@@ -879,9 +895,12 @@ con_val_iter (void *cls,
   (void) kind;
 
   if ((0 == strcmp (MHD_HTTP_HEADER_ACCEPT_ENCODING,
-                    key)))
+                    key)) ||
+    (0 == strcmp (MHD_HTTP_HEADER_CONTENT_ENCODING,
+                  key)))
   {
-    TALER_LOG_INFO ("Do not re-compressed request\n");
+    TALER_LOG_INFO ("Do not re-compress request and/or do not"
+                    " ask for compressed responses\n");
     return MHD_YES;
   }
 
@@ -1367,7 +1386,7 @@ create_response (void *cls,
 
   if (REQUEST_STATE_WITH_MHD == hr->state)
   {
-    hr->state = REQUEST_STATE_UPLOAD_STARTED;
+    hr->state = REQUEST_STATE_CLIENT_UPLOAD_STARTED;
     /* TODO: hacks for 100 continue suppression would go here! */
     return MHD_YES;
   }
@@ -1376,7 +1395,7 @@ create_response (void *cls,
   if (0 != *upload_data_size)
   {
     GNUNET_assert
-      (REQUEST_STATE_UPLOAD_STARTED == hr->state);
+      (REQUEST_STATE_CLIENT_UPLOAD_STARTED == hr->state);
 
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Processing %u bytes UPLOAD\n",
@@ -1408,14 +1427,17 @@ create_response (void *cls,
     return MHD_YES;
   }
 
-  /* Upload (*from the client*) finished */
-  if (REQUEST_STATE_UPLOAD_STARTED == hr->state)
+  /* Upload (*from the client*) finished or just a without-body
+   * request.  */
+  if (REQUEST_STATE_CLIENT_UPLOAD_STARTED == hr->state)
   {
+    hr->state = REQUEST_STATE_CLIENT_UPLOAD_DONE;
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Finished processing UPLOAD\n");
-    hr->state = REQUEST_STATE_UPLOAD_DONE;
     if (0 != hr->io_len)
     {
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Attempting to decompress\n");
       #if 1
       const char *ce;
       ce = MHD_lookup_connection_value
@@ -1433,9 +1455,10 @@ create_response (void *cls,
                              &error);
       if (NULL == hr->json)
       {
-        TALER_LOG_ERROR ("Could not parse JSON from client: %s (%s)\n",
-                         error.text,
-                         error.source);
+        TALER_LOG_ERROR
+          ("Could not parse JSON from client: %s (%s)\n",
+           error.text,
+           error.source);
         /* Quick and dirty.  */
         return MHD_NO;
       }
@@ -1553,6 +1576,7 @@ create_response (void *cls,
       curl_easy_setopt (hr->curl,
                         CURLOPT_READFUNCTION,
                         &curl_upload_cb);
+      hr->state = REQUEST_STATE_PROXY_UPLOAD_STARTED;
       curl_easy_setopt (hr->curl,
                        CURLOPT_READDATA,
                        hr);
@@ -1587,14 +1611,13 @@ create_response (void *cls,
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "Crafting a CURL POST request\n");
 
-      hr->state = REQUEST_STATE_UPLOAD_STARTED;
-
       curl_easy_setopt (hr->curl,
                        CURLOPT_POST,
                        1L);
       curl_easy_setopt (hr->curl,
                         CURLOPT_VERBOSE,
                         1L);
+      hr->state = REQUEST_STATE_PROXY_UPLOAD_STARTED;
       GNUNET_assert
         (CURLE_OK == curl_easy_setopt
           (hr->curl,
@@ -1635,7 +1658,7 @@ create_response (void *cls,
     else if (0 == strcasecmp (meth,
                              MHD_HTTP_METHOD_HEAD))
     {
-      hr->state = REQUEST_STATE_DOWNLOAD_STARTED;
+      hr->state = REQUEST_STATE_PROXY_DOWNLOAD_STARTED;
       curl_easy_setopt (hr->curl,
                        CURLOPT_NOBODY,
                        1L);
@@ -1643,7 +1666,7 @@ create_response (void *cls,
     else if (0 == strcasecmp (meth,
                              MHD_HTTP_METHOD_OPTIONS))
     {
-      hr->state = REQUEST_STATE_DOWNLOAD_STARTED;
+      hr->state = REQUEST_STATE_PROXY_DOWNLOAD_STARTED;
       curl_easy_setopt (hr->curl,
                        CURLOPT_CUSTOMREQUEST,
                        "OPTIONS");
@@ -1651,7 +1674,7 @@ create_response (void *cls,
     else if (0 == strcasecmp (meth,
                              MHD_HTTP_METHOD_GET))
     {
-      hr->state = REQUEST_STATE_DOWNLOAD_STARTED;
+      hr->state = REQUEST_STATE_PROXY_DOWNLOAD_STARTED;
       curl_easy_setopt (hr->curl,
                        CURLOPT_HTTPGET,
                        1L);
@@ -1712,19 +1735,17 @@ create_response (void *cls,
                       hr->headers);
     curl_download_prepare ();
 
-    /* means (?) upload is over.  */
-    if (0 == hr->io_len)
-      hr->state = REQUEST_STATE_DOWNLOAD_STARTED;
     return MHD_YES;
   }
 
-  if (REQUEST_STATE_DOWNLOAD_DONE != hr->state)
+  if (REQUEST_STATE_PROXY_DOWNLOAD_DONE != hr->state)
   {
     MHD_suspend_connection (con);
     hr->suspended = GNUNET_YES;
     return MHD_YES; /* wait for curl */
   }
 
+  GNUNET_assert (REQUEST_STATE_PROXY_DOWNLOAD_DONE == hr->state);
   if (0 != hack_response_code)
   {
     hr->response_code = hack_response_code;
@@ -1848,10 +1869,6 @@ mhd_completed_cb (void *cls,
     hr->io_len = 0;
   }
 
-  if ((NULL != hr->mod_response))
-    /* Destroy hacked responses. */
-    MHD_destroy_response (hr->mod_response);
-
   if ( (NULL != hr->response) &&
        (curl_failure_response != hr->response) )
     /* Destroy non-error responses... (?) */

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



reply via email to

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