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 (3f9aafdc -> 081280a


From: gnunet
Subject: [GNUnet-SVN] [taler-exchange] branch master updated (3f9aafdc -> 081280a8)
Date: Fri, 10 May 2019 20:12:09 +0200

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

dold pushed a change to branch master
in repository exchange.

    from 3f9aafdc doc fixes in format and typos.
     new b8a718f8 Remove non-working curl config
     new 081280a8 Create async scopes.

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.c | 112 +++++++++++++++++++++++++++++++-----
 src/lib/auditor_api_curl_defaults.c |  23 +-------
 src/lib/testing_api_loop.c          |   1 +
 3 files changed, 101 insertions(+), 35 deletions(-)

diff --git a/src/exchange/taler-exchange-httpd.c 
b/src/exchange/taler-exchange-httpd.c
index 8f86bf79..b24feef6 100644
--- a/src/exchange/taler-exchange-httpd.c
+++ b/src/exchange/taler-exchange-httpd.c
@@ -54,6 +54,24 @@
  */
 #define UNIX_BACKLOG 500
 
+
+/**
+ * Type of the closure associated with each HTTP request to the exchange.
+ */
+struct ExchangeHttpRequestClosure
+{
+  /**
+   * Async Scope ID associated with this request.
+   */
+  struct GNUNET_AsyncScopeId async_scope_id;
+
+  /**
+   * Opaque parsing context.
+   */
+  void *opaque_post_parsing_context;
+};
+
+
 /**
  * Which currency is used by this exchange?
  */
@@ -142,16 +160,38 @@ handle_mhd_completion_callback (void *cls,
                                 void **con_cls,
                                 enum MHD_RequestTerminationCode toe)
 {
-  if (NULL == *con_cls)
+  struct ExchangeHttpRequestClosure *ecls = *con_cls;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Request completed\n");
+
+  if (NULL == ecls)
     return;
-  TEH_PARSE_post_cleanup_callback (*con_cls);
+  TEH_PARSE_post_cleanup_callback (ecls->opaque_post_parsing_context);
+  GNUNET_free (ecls);
   *con_cls = NULL;
   /* check that we didn't leave any transactions hanging */
   /* NOTE: In high-performance production, we might want to
      remove this. */
   TEH_plugin->preflight (TEH_plugin->cls,
                          TEH_plugin->get_session (TEH_plugin->cls));
+}
 
+
+/**
+ * Return GNUNET_YES if given a valid correlation ID and
+ * GNUNET_NO otherwise.
+ *
+ * @returns GNUNET_YES iff given a valid correlation ID
+ */
+static int
+is_valid_correlation_id (const char *correlation_id)
+{
+  if (strlen (correlation_id) >= 64)
+    return GNUNET_NO;
+  for (int i = 0; i < strlen (correlation_id); i++)
+    if (!(isalnum (correlation_id[i]) || correlation_id[i] == '-'))
+      return GNUNET_NO;
+  return GNUNET_YES;
 }
 
 
@@ -367,10 +407,45 @@ handle_mhd_request (void *cls,
       &TEH_MHD_handler_static_response, MHD_HTTP_NOT_FOUND
     };
   struct TEH_RequestHandler *rh;
+  struct ExchangeHttpRequestClosure *ecls = *con_cls;
+  int ret;
+  void **inner_cls;
+  struct GNUNET_AsyncScopeSave old_scope;
+  const char *correlation_id = NULL;
+
+  if (NULL == ecls) {
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Handling new request\n");
+    /* We're in a new async scope! */
+    ecls = *con_cls = GNUNET_new (struct ExchangeHttpRequestClosure);
+    GNUNET_async_scope_fresh (&ecls->async_scope_id);
+    /* We only read the correlation ID on the first callback for every client 
*/
+    correlation_id = MHD_lookup_connection_value (connection,
+                                                  MHD_HEADER_KIND,
+                                                  "Taler-Correlation-Id");
+    if ((NULL != correlation_id) &&
+        (GNUNET_YES != is_valid_correlation_id (correlation_id)))
+    {
+        GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "illegal incoming correlation 
ID\n");
+        correlation_id = NULL;
+    }
+  }
+
+  inner_cls = &ecls->opaque_post_parsing_context;
+
+  GNUNET_async_scope_enter (&ecls->async_scope_id, &old_scope);
+
+  if (NULL != correlation_id)
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "Handling request (%s) for URL '%s', correlation_id=%s\n",
+                method,
+                url,
+                correlation_id);
+  else
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "Handling request (%s) for URL '%s'\n",
+                method,
+                url);
 
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "Handling request for URL '%s'\n",
-              url);
   if (0 == strcasecmp (method,
                        MHD_HTTP_METHOD_HEAD))
     method = MHD_HTTP_METHOD_GET; /* treat HEAD as GET here, MHD will do the 
rest */
@@ -382,17 +457,24 @@ handle_mhd_request (void *cls,
          ( (NULL == rh->method) ||
            (0 == strcasecmp (method,
                              rh->method)) ) )
-      return rh->handler (rh,
-                          connection,
-                          con_cls,
-                          upload_data,
-                          upload_data_size);
+    {
+      ret = rh->handler (rh,
+                         connection,
+                         inner_cls,
+                         upload_data,
+                         upload_data_size);
+      GNUNET_async_scope_restore (&old_scope);
+      return ret;
+    }
   }
-  return TEH_MHD_handler_static_response (&h404,
-                                          connection,
-                                          con_cls,
-                                          upload_data,
-                                          upload_data_size);
+  ret = TEH_MHD_handler_static_response (&h404,
+                                         connection,
+                                         inner_cls,
+                                         upload_data,
+                                         upload_data_size);
+  GNUNET_async_scope_restore (&old_scope);
+
+  return ret;
 }
 
 
diff --git a/src/lib/auditor_api_curl_defaults.c 
b/src/lib/auditor_api_curl_defaults.c
index 507ae0e5..7beb592e 100644
--- a/src/lib/auditor_api_curl_defaults.c
+++ b/src/lib/auditor_api_curl_defaults.c
@@ -33,6 +33,9 @@ CURL *
 TAL_curl_easy_get (const char *url)
 {
   CURL *eh;
+  struct GNUNET_AsyncScopeSave scope;
+
+  GNUNET_async_scope_get (&scope);
 
   eh = curl_easy_init ();
 
@@ -48,26 +51,6 @@ TAL_curl_easy_get (const char *url)
                  curl_easy_setopt (eh,
                                    CURLOPT_TCP_FASTOPEN,
                                    1L));
-  {
-    /* Unfortunately libcurl needs chunk to be alive until after
-    curl_easy_perform.  To avoid manual cleanup, we keep
-    one static list here.  */
-    static struct curl_slist *chunk = NULL;
-    if (NULL == chunk)
-    {
-      /* With POST requests, we do not want to wait for the
-      "100 Continue" response, as our request bodies are usually
-      small and directy sending them saves us a round trip.
-
-      Clearing the expect header like this disables libcurl's
-      default processing of the header.
-
-      Disabling this header is safe for other HTTP methods, thus
-      we don't distinguish further before setting it.  */
-      chunk = curl_slist_append (chunk, "Expect:");
-    }
-    GNUNET_assert (CURLE_OK == curl_easy_setopt (eh, CURLOPT_HTTPHEADER, 
chunk));
-  }
 
   return eh;
 }
diff --git a/src/lib/testing_api_loop.c b/src/lib/testing_api_loop.c
index 071388f2..bebd159d 100644
--- a/src/lib/testing_api_loop.c
+++ b/src/lib/testing_api_loop.c
@@ -807,6 +807,7 @@ TALER_TESTING_setup (TALER_TESTING_Main main_cb,
   is.ctx = GNUNET_CURL_init
     (&GNUNET_CURL_gnunet_scheduler_reschedule,
      &is.rc);
+  GNUNET_CURL_enable_async_scope_header (is.ctx, "Taler-Correlation-Id");
   GNUNET_assert (NULL != is.ctx);
   is.rc = GNUNET_CURL_gnunet_rc_create (is.ctx);
 

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



reply via email to

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