gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-twister] branch master updated: Implementing chaos p


From: gnunet
Subject: [GNUnet-SVN] [taler-twister] branch master updated: Implementing chaos probability (5737).
Date: Wed, 05 Jun 2019 16:18:30 +0200

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

marcello pushed a commit to branch master
in repository twister.

The following commit(s) were added to refs/heads/master by this push:
     new bcb0c70  Implementing chaos probability (5737).
bcb0c70 is described below

commit bcb0c70668243672a63dc6f4bba3ce417b05abb2
Author: Marcello Stanisci <address@hidden>
AuthorDate: Wed Jun 5 16:18:00 2019 +0200

    Implementing chaos probability (5737).
---
 src/twister/taler-twister-service.c | 65 ++++++++++++++++++++++++++++++++++---
 1 file changed, 61 insertions(+), 4 deletions(-)

diff --git a/src/twister/taler-twister-service.c 
b/src/twister/taler-twister-service.c
index af2551b..518d95f 100644
--- a/src/twister/taler-twister-service.c
+++ b/src/twister/taler-twister-service.c
@@ -298,6 +298,13 @@ static char *target_server_base_url;
 /* ******************* Transformations ***************** */
 
 /**
+ * Chaos probability (in percent); this value is taken from
+ * the config and stays valid for all the Twister's lifetime.
+ */
+static long long unsigned int chaos_rate = 0;
+
+
+/**
  * Set to non-zero if we should change the next response code.
  * In this case, this is the value to use.
  */
@@ -1332,6 +1339,49 @@ inflate_data (struct HttpRequest *request)
   } /* while (1) */
 }
 
+
+/**
+ * Create the response object according to the "chaos rate".
+ * If this latter strikes, then the response will be "503 Service
+ * Unavailable" with a empty body (overriding every other mod that
+ * the user might have given.)
+ *
+ * @param request the HTTP object representing the current state.
+ */
+static void
+create_response_with_chaos_rate (struct HttpRequest *request)
+{
+  uint64_t random;
+
+  void *resp_buf;
+  size_t resp_len;
+
+  random = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
+                                     100);
+  TALER_LOG_INFO ("p: %llu, random: %llu\n",
+                  chaos_rate,
+                  random);
+
+  if (random <= chaos_rate)
+  {
+    /* p won */
+    TALER_LOG_INFO ("Chaos probability won the case.\n");
+    resp_buf = "Service unavailable";
+    resp_len = strlen (resp_buf);
+    request->response_code = MHD_HTTP_SERVICE_UNAVAILABLE;
+  }
+  else
+  {
+    resp_len = request->io_len;
+    resp_buf = request->io_buf;
+  }
+
+  request->response = MHD_create_response_from_buffer
+    (resp_len,
+     resp_buf,
+     MHD_RESPMEM_MUST_COPY);
+}
+
 /**
  * Main MHD callback for handling requests.
  *
@@ -1748,10 +1798,7 @@ create_response (void *cls,
     malform = GNUNET_NO;
   }
 
-  hr->response = MHD_create_response_from_buffer
-    (hr->io_len,
-     hr->io_buf,
-     MHD_RESPMEM_MUST_COPY);
+  create_response_with_chaos_rate (hr);
 
   for (header = hr->header_head;
        NULL != header;
@@ -1767,6 +1814,7 @@ create_response (void *cls,
                                            header->value));
   }
   run_mhd_now ();
+
   return MHD_queue_response (con,
                              hr->response_code,
                              hr->response);
@@ -2095,6 +2143,15 @@ run (void *cls,
                 "Failed to create cURL multi handle!\n");
     return;
   }
+
+  /* No need to check return value.  If given, we take,
+   * otherwise it stays zero.  */
+  GNUNET_CONFIGURATION_get_value_number (c,
+                                         "twister",
+                                         "CHAOS_RATE",
+                                         &chaos_rate);
+  GNUNET_assert (100 >= chaos_rate);
+
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_string
         (c,

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



reply via email to

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