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 (2e773e8 -> 5ac6f8f)


From: gnunet
Subject: [GNUnet-SVN] [taler-twister] branch master updated (2e773e8 -> 5ac6f8f)
Date: Wed, 16 May 2018 10:41:55 +0200

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

marcello pushed a change to branch master
in repository twister.

    from 2e773e8  remove strace from tests.
     new a28e9e0  Walk objects..
     new 5b9947e  Differentiate between bit-flipping in download and upload.
     new 381051f  Bring difference into the service component.
     new 3e89376  cosmetics.
     new 0bd9dbb  object "walker" is HttpResponse-agnostic.
     new bffe839  dumping stringified flipped object into io_buf.
     new d8deed2  debug stmt
     new fe0013a  export "flippers" to the internal API.
     new 650fbad  debug stmt
     new a1537b1  do not use "tmp" buffer for response
     new 5ac6f8f  json_dumpb() way better.

The 11 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/include/taler_twister_service.h       |  19 ++++-
 src/include/taler_twister_testing_lib.h   |   7 +-
 src/twister/taler-twister-service.c       | 136 ++++++++++++++++++++----------
 src/twister/taler-twister.c               |  32 +++++--
 src/twister/testing_api_cmd_exec_client.c |  69 ++++++++++++++-
 src/twister/twister.h                     |   4 +-
 src/twister/twister_api.c                 |  35 +++++++-
 7 files changed, 241 insertions(+), 61 deletions(-)

diff --git a/src/include/taler_twister_service.h 
b/src/include/taler_twister_service.h
index 7adf40e..ae16847 100644
--- a/src/include/taler_twister_service.h
+++ b/src/include/taler_twister_service.h
@@ -107,12 +107,29 @@ TALER_TWISTER_modify_path (struct TALER_TWISTER_Handle *h,
  * @return operation handle (to possibly abort)
  */
 struct TALER_TWISTER_Operation *
-TALER_TWISTER_flip_path
+TALER_TWISTER_flip_download
   (struct TALER_TWISTER_Handle *h,
    const char *path,
    GNUNET_SCHEDULER_TaskCallback cb,
    void *cb_cls);
 
+/**
+ * Randomly flip a character into the JSON string
+ * object pointed to by @a path.
+ *
+ * @param h twister instance to control
+ * @param path object-like notation to point the string
+ *        object where we seek a character to flip.
+ * @param cb function to call once twister is ready
+ * @param cb_cls closure for @a cb
+ * @return operation handle (to possibly abort)
+ */
+struct TALER_TWISTER_Operation *
+TALER_TWISTER_flip_upload
+  (struct TALER_TWISTER_Handle *h,
+   const char *path,
+   GNUNET_SCHEDULER_TaskCallback cb,
+   void *cb_cls);
 
 /**
  * Change the next response code to @a new_rc.
diff --git a/src/include/taler_twister_testing_lib.h 
b/src/include/taler_twister_testing_lib.h
index d7417b8..9f3d7e5 100644
--- a/src/include/taler_twister_testing_lib.h
+++ b/src/include/taler_twister_testing_lib.h
@@ -119,7 +119,12 @@ TALER_TESTING_cmd_malform_request (const char *label,
  * @return the command
  */
 struct TALER_TESTING_Command
-TALER_TESTING_cmd_flip_object (const char *label,
+TALER_TESTING_cmd_flip_upload (const char *label,
                                const char *config_filename,
                                const char *path);
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_flip_download (const char *label,
+                                 const char *config_filename,
+                                 const char *path);
 #endif
diff --git a/src/twister/taler-twister-service.c 
b/src/twister/taler-twister-service.c
index 66ae9f5..ea26ad0 100644
--- a/src/twister/taler-twister-service.c
+++ b/src/twister/taler-twister-service.c
@@ -256,7 +256,9 @@ static char delete_path[TWISTER_PATH_LENGTH] = {'\0'};
  * Will point to a JSON string object which will get a
  * character flipped.
  */
-static char flip_path[TWISTER_PATH_LENGTH] = {'\0'};
+static char flip_path_dl[TWISTER_PATH_LENGTH] = {'\0'};
+
+static char flip_path_ul[TWISTER_PATH_LENGTH] = {'\0'};
 
 /**
  * Will point to a JSON object to modify 
@@ -539,7 +541,10 @@ curl_download_cb (void *ptr,
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Curl download proceeding\n");
-  GNUNET_assert (REQUEST_STATE_DOWNLOAD_STARTED == hr->state);
+
+  GNUNET_assert
+    (REQUEST_STATE_DOWNLOAD_STARTED == hr->state);
+
   if (hr->io_size - hr->io_len < total)
   {
     GNUNET_assert (total + hr->io_size >= total);
@@ -549,6 +554,7 @@ curl_download_cb (void *ptr,
                       GNUNET_MAX (total + hr->io_len,
                                   hr->io_size * 2 + 1024));
   }
+
   GNUNET_memcpy (&hr->io_buf[hr->io_len],
                  ptr,
                  total);
@@ -577,6 +583,10 @@ curl_upload_cb (void *buf,
   size_t len = size * nmemb;
   size_t to_copy;
 
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Uploader cb, size: %u.\n",
+              size);
+
   if (REQUEST_STATE_UPLOAD_STARTED != hr->state) 
   {
     GNUNET_break (0);
@@ -879,7 +889,7 @@ static unsigned int
 walk_response_object (const char *path,
                       json_t **parent,
                       char **target,
-                      struct HttpRequest *hr)
+                      json_t *json)
 {
 
   json_t *element;
@@ -896,7 +906,7 @@ walk_response_object (const char *path,
   /* Give first nondelim char. */
   token = strtok (path_dup, ".");
 
-  if (NULL == (element = hr->json))
+  if (NULL == (element = json))
   {
     TALER_LOG_ERROR ("Attempting to walk a non JSON response!\n");
     return GNUNET_SYSERR;
@@ -973,7 +983,7 @@ modify_object (struct MHD_Connection *con,
   if (GNUNET_OK != walk_response_object (modify_path,
                                          &parent,
                                          &target,
-                                         hr))
+                                         hr->json))
     return;
 
   /* At this point, the parent and the target are pointed to. */
@@ -1028,7 +1038,8 @@ modify_object (struct MHD_Connection *con,
 
 static void
 flip_object (struct MHD_Connection *con,
-             struct HttpRequest *hr)
+             json_t *json,
+             char *flip_path)
 {
   char *target;
   json_t *parent;
@@ -1036,7 +1047,7 @@ flip_object (struct MHD_Connection *con,
   if (GNUNET_OK != walk_response_object (flip_path,
                                          &parent,
                                          &target,
-                                         hr))
+                                         json))
     return;
 
   /* here, element is the parent of the element to be deleted. */
@@ -1107,7 +1118,7 @@ delete_object (struct MHD_Connection *con,
   if (GNUNET_OK != walk_response_object (delete_path,
                                          &parent,
                                          &target,
-                                         hr))
+                                         hr->json))
     return;
 
   /* here, element is the parent of the element to be deleted. */
@@ -1172,9 +1183,6 @@ create_response (void *cls,
   (void) cls;
   (void) url;
 
-  char *body;
-  size_t body_len;
-
   if (NULL == hr)
   {
     GNUNET_break (0);
@@ -1191,7 +1199,9 @@ create_response (void *cls,
   /* continuing to process request */
   if (0 != *upload_data_size)
   {
-    GNUNET_assert (REQUEST_STATE_UPLOAD_STARTED == hr->state);
+    GNUNET_assert
+      (REQUEST_STATE_UPLOAD_STARTED == hr->state);
+
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Processing %u bytes UPLOAD\n",
                (unsigned int) *upload_data_size);
@@ -1221,21 +1231,46 @@ create_response (void *cls,
     return MHD_YES;
   }
 
-  /* Malform request body.  Note, this flag will be
-   * cleared only after having set the right malformed
-   * body lenght in the request headers.  */
-  if (GNUNET_YES == malform_upload)
-  {
-    TALER_LOG_DEBUG
-      ("Will (badly) truncate the request.\n");
-    malformed_size = GNUNET_CRYPTO_random_u32
-      (GNUNET_CRYPTO_QUALITY_WEAK, hr->io_len);
-    hr->io_len = malformed_size;
-  }
-
-  /* Upload finished, generate curl request */
+  /* Upload (from the *client*) finished,
+   * generate curl request to the proxied service.  */
   if (NULL == hr->curl)
   {
+    /* Malform request body.  Note, this flag will be
+     * cleared only after having set the right malformed
+     * body lenght in the request headers.  */
+    if (GNUNET_YES == malform_upload)
+    {
+      TALER_LOG_DEBUG
+        ("Will (badly) truncate the request.\n");
+      malformed_size = GNUNET_CRYPTO_random_u32
+        (GNUNET_CRYPTO_QUALITY_WEAK, hr->io_len);
+      hr->io_len = malformed_size;
+    }
+  
+    if ('\0' != flip_path_ul[0])
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Going to modify the upload object (%s)\n",
+                  hr->io_buf);
+      json_t *tmp;
+      tmp = json_loads (hr->io_buf,
+                        JSON_REJECT_DUPLICATES,
+                        NULL);
+      flip_object (con,
+                   tmp,
+                   flip_path_ul);
+
+      json_dumpb (tmp,
+                  hr->io_buf,
+                  hr->io_len, /* Existing io_len is enough to accomodate this 
encoding.  */
+                  JSON_COMPACT);
+
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Flipped (?) upload object (%s)\n",
+                  hr->io_buf);
+      json_decref (tmp);
+    }
+
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Generating curl request\n");
     hr->curl = curl_easy_init ();
@@ -1424,11 +1459,11 @@ create_response (void *cls,
     hack_response_code = 0; /* reset for next request */
   }
 
-  if ('\0' != flip_path[0])
+  if ('\0' != flip_path_dl[0])
   {
     TALER_LOG_DEBUG ("Will flip path: %s\n",
-                     flip_path);
-    flip_object (con, hr);
+                     flip_path_dl);
+    flip_object (con, hr->json, flip_path_dl);
   }
 
   if ('\0' != delete_path[0])
@@ -1446,14 +1481,13 @@ create_response (void *cls,
     modify_object (con, hr);
   }
 
-  body_len = hr->io_len;
-  body = hr->io_buf;
 
   if (NULL != hr->json)
   {
     TALER_LOG_DEBUG ("Parsing final JSON.\n");
-    body = json_dumps (hr->json, JSON_COMPACT);
-    body_len = strlen (body);
+    GNUNET_free (hr->io_buf);
+    hr->io_buf = json_dumps (hr->json, JSON_COMPACT);
+    hr->io_len = strlen (hr->io_buf);
     json_decref (hr->json);
   }
 
@@ -1464,17 +1498,16 @@ create_response (void *cls,
     TALER_LOG_DEBUG
       ("Will (badly) truncate the response.\n");
     fake_len = GNUNET_CRYPTO_random_u32
-      (GNUNET_CRYPTO_QUALITY_WEAK, body_len);
-    body_len = fake_len; 
+      (GNUNET_CRYPTO_QUALITY_WEAK, hr->io_len);
+    hr->io_len = fake_len; 
     malform = GNUNET_NO;
   }
 
   hr->response = MHD_create_response_from_buffer
-    (body_len,
-     body,
+    (hr->io_len,
+     hr->io_buf,
      MHD_RESPMEM_MUST_COPY);
 
-  GNUNET_free_non_null (body);
   for (header = hr->header_head;
        NULL != header;
        header = header->next)
@@ -1558,11 +1591,13 @@ mhd_completed_cb (void *cls,
     GNUNET_free (header->value);
     GNUNET_free (header);
   }
+
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Finished request for %s\n",
               hr->url);
+
   GNUNET_free (hr->url);
-  GNUNET_free_non_null (hr->io_buf);
+  GNUNET_free (hr->io_buf);
   GNUNET_free (hr);
   *con_cls = NULL;
 }
@@ -1965,12 +2000,22 @@ handle_modify_path (void *cls,
  * @param src received message
  */
 static void
-handle_flip_path (void *cls,
-                  const struct TWISTER_FlipPath *src)
+handle_flip_path_dl (void *cls,
+                     const struct TWISTER_FlipPath *src)
+{
+  struct GNUNET_SERVICE_Client *c = cls;
+
+  strcpy (flip_path_dl, src->path);
+  send_acknowledgement (c);
+}
+
+static void
+handle_flip_path_ul (void *cls,
+                     const struct TWISTER_FlipPath *src)
 {
   struct GNUNET_SERVICE_Client *c = cls;
 
-  strcpy (flip_path, src->path);
+  strcpy (flip_path_ul, src->path);
   send_acknowledgement (c);
 }
 
@@ -2042,12 +2087,15 @@ GNUNET_SERVICE_MAIN
                          struct TWISTER_DeletePath,
                          NULL),
 
- GNUNET_MQ_hd_fixed_size (flip_path,
-                         TWISTER_MESSAGE_TYPE_FLIP_PATH,
+ GNUNET_MQ_hd_fixed_size (flip_path_ul,
+                         TWISTER_MESSAGE_TYPE_FLIP_PATH_UL,
                          struct TWISTER_FlipPath,
                          NULL),
 
-
+ GNUNET_MQ_hd_fixed_size (flip_path_dl,
+                         TWISTER_MESSAGE_TYPE_FLIP_PATH_DL,
+                         struct TWISTER_FlipPath,
+                         NULL),
  GNUNET_MQ_handler_end ());
 
 
diff --git a/src/twister/taler-twister.c b/src/twister/taler-twister.c
index 3ff4a04..6806f74 100644
--- a/src/twister/taler-twister.c
+++ b/src/twister/taler-twister.c
@@ -65,7 +65,9 @@ static int malform_upload;
 /**
  * Path to the string json object to flip.
  */
-static char *flip_path;
+static char *flip_path_dl;
+
+static char *flip_path_ul;
 
 /**
  * Path to the object to modify.
@@ -178,12 +180,18 @@ run (void *cls,
           NULL)) )
     num_ops++;
 
-  /* TODO: add other operations here */
+  if ( (NULL != flip_path_ul) &&
+       (NULL != TALER_TWISTER_flip_upload
+         (tth,
+          flip_path_ul,
+          &handle_acknowledgement,
+          NULL)) )
+    num_ops++;
 
-  if ( (NULL != flip_path) &&
-       (NULL != TALER_TWISTER_flip_path
+  if ( (NULL != flip_path_dl) &&
+       (NULL != TALER_TWISTER_flip_download
          (tth,
-          flip_path,
+          flip_path_dl,
           &handle_acknowledgement,
           NULL)) )
     num_ops++;
@@ -243,12 +251,20 @@ main (int argc,
        &modify_path),
 
     GNUNET_GETOPT_option_string
+      ('F',
+       "flip-ul",
+       "PATH",
+       gettext_noop
+         ("Flip a char in the *string* upload object pointed by PATH.\n"),
+       &flip_path_ul),
+
+    GNUNET_GETOPT_option_string
       ('f',
-       "flip",
+       "flip-dl",
        "PATH",
        gettext_noop
-         ("Flip a char in the _string_ object pointed by PATH.\n"),
-       &flip_path),
+         ("Flip a char in the *string* download object pointed by PATH.\n"),
+       &flip_path_dl),
 
     GNUNET_GETOPT_option_string
       ('V',
diff --git a/src/twister/testing_api_cmd_exec_client.c 
b/src/twister/testing_api_cmd_exec_client.c
index 1e5b480..8f651a5 100644
--- a/src/twister/testing_api_cmd_exec_client.c
+++ b/src/twister/testing_api_cmd_exec_client.c
@@ -507,7 +507,7 @@ flip_object_traits (void *cls,
  * FIXME: document.
  */
 static void
-flip_object_run (void *cls,
+flip_upload_run (void *cls,
                  const struct TALER_TESTING_Command *cmd,
                  struct TALER_TESTING_Interpreter *is)
 {
@@ -519,7 +519,36 @@ flip_object_run (void *cls,
                                        "taler-twister",
                                        "taler-twister",
                                        "-c", fos->config_filename,
-                                       "--flip", fos->path,
+                                       "--flip-ul", fos->path,
+                                       NULL);
+  if (NULL == fos->proc)
+  {
+    GNUNET_break (0);
+    TALER_TESTING_interpreter_fail (is);
+    return;
+  }
+  TALER_TESTING_wait_for_sigchld (is);
+}
+
+
+
+/**
+ * FIXME: document.
+ */
+static void
+flip_download_run (void *cls,
+                   const struct TALER_TESTING_Command *cmd,
+                   struct TALER_TESTING_Interpreter *is)
+{
+  struct FlipObjectState *fos = cls;
+
+  fos->proc = GNUNET_OS_start_process (GNUNET_NO,
+                                       GNUNET_OS_INHERIT_STD_ALL,
+                                       NULL, NULL, NULL,
+                                       "taler-twister",
+                                       "taler-twister",
+                                       "-c", fos->config_filename,
+                                       "--flip-dl", fos->path,
                                        NULL);
   if (NULL == fos->proc)
   {
@@ -541,7 +570,7 @@ flip_object_run (void *cls,
  * @return the command
  */
 struct TALER_TESTING_Command
-TALER_TESTING_cmd_flip_object (const char *label,
+TALER_TESTING_cmd_flip_upload (const char *label,
                                const char *config_filename,
                                const char *path)
 {
@@ -553,7 +582,39 @@ TALER_TESTING_cmd_flip_object (const char *label,
   dos->config_filename = config_filename;
 
   cmd.label = label;
-  cmd.run = &flip_object_run;
+  cmd.run = &flip_upload_run;
+  cmd.cleanup = &flip_object_cleanup;
+  cmd.traits = &flip_object_traits;
+  cmd.cls = dos;
+
+  return cmd;
+}
+
+
+/**
+ * This command deletes the JSON object pointed by @a path.
+ *
+ * @param label command label
+ * @param config_filename configuration filename.
+ * @param path object-like path notation to point the object
+ *        to delete.
+ *
+ * @return the command
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_flip_download (const char *label,
+                                 const char *config_filename,
+                                 const char *path)
+{
+  struct FlipObjectState *dos;
+  struct TALER_TESTING_Command cmd;
+
+  dos = GNUNET_new (struct FlipObjectState);
+  dos->path = path;
+  dos->config_filename = config_filename;
+
+  cmd.label = label;
+  cmd.run = &flip_download_run;
   cmd.cleanup = &flip_object_cleanup;
   cmd.traits = &flip_object_traits;
   cmd.cls = dos;
diff --git a/src/twister/twister.h b/src/twister/twister.h
index 3e943f7..59ae659 100644
--- a/src/twister/twister.h
+++ b/src/twister/twister.h
@@ -51,7 +51,9 @@
 
 #define TWISTER_MESSAGE_TYPE_MALFORM_UPLOAD 6
 
-#define TWISTER_MESSAGE_TYPE_FLIP_PATH 7
+#define TWISTER_MESSAGE_TYPE_FLIP_PATH_DL 7
+
+#define TWISTER_MESSAGE_TYPE_FLIP_PATH_UL 8
 
 GNUNET_NETWORK_STRUCT_BEGIN
 struct TWISTER_Malform
diff --git a/src/twister/twister_api.c b/src/twister/twister_api.c
index aa96e6f..672e434 100644
--- a/src/twister/twister_api.c
+++ b/src/twister/twister_api.c
@@ -287,7 +287,7 @@ TALER_TWISTER_malform
  * @return operation handle (to possibly abort)
  */
 struct TALER_TWISTER_Operation *
-TALER_TWISTER_flip_path
+TALER_TWISTER_flip_download
   (struct TALER_TWISTER_Handle *h,
    const char *path,
    GNUNET_SCHEDULER_TaskCallback cb,
@@ -306,7 +306,7 @@ TALER_TWISTER_flip_path
                                     op);
   /* Prepare *env*elope. */
   env = GNUNET_MQ_msg
-    (src, TWISTER_MESSAGE_TYPE_FLIP_PATH);
+    (src, TWISTER_MESSAGE_TYPE_FLIP_PATH_DL);
   /* Put data into the envelope. */
   strcpy (src->path, path);
   /* Send message. */
@@ -314,6 +314,37 @@ TALER_TWISTER_flip_path
   return op;
 }
 
+struct TALER_TWISTER_Operation *
+TALER_TWISTER_flip_upload
+  (struct TALER_TWISTER_Handle *h,
+   const char *path,
+   GNUNET_SCHEDULER_TaskCallback cb,
+   void *cb_cls)
+{
+  struct TALER_TWISTER_Operation *op;
+  struct GNUNET_MQ_Envelope *env;
+  struct TWISTER_FlipPath *src; //FIXME 'src' right name?
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
+              "Will UL-flip: %s\n",
+              path);
+
+  op = GNUNET_new (struct TALER_TWISTER_Operation);
+  op->h = h;
+  op->cb = cb;
+  op->cb_cls = cb_cls;
+  GNUNET_CONTAINER_DLL_insert_tail (h->op_head,
+                                    h->op_tail,
+                                    op);
+  /* Prepare *env*elope. */
+  env = GNUNET_MQ_msg
+    (src, TWISTER_MESSAGE_TYPE_FLIP_PATH_UL);
+  /* Put data into the envelope. */
+  strcpy (src->path, path);
+  /* Send message. */
+  GNUNET_MQ_send (h->mq, env);
+  return op;
+}
 
 /**
  * Delete the object pointed to by @a path.

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



reply via email to

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