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 (60a030c -> 8fbd758)


From: gnunet
Subject: [GNUnet-SVN] [taler-twister] branch master updated (60a030c -> 8fbd758)
Date: Thu, 22 Mar 2018 16:42:02 +0100

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

marcello pushed a change to branch master
in repository twister.

    from 60a030c  address leaks.
     new 600c003  adding flip command, boilerplate (including failing test)
     new 8fbd758  implement char-flipper.

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/include/taler_twister_service.h |  19 +++++++
 src/test/test_twister.sh            |  15 +++++-
 src/twister/taler-twister-service.c | 103 +++++++++++++++++++++++++++++++++++-
 src/twister/taler-twister.c         |  21 ++++++++
 src/twister/twister.h               |  28 ++++++++++
 src/twister/twister_api.c           |  40 ++++++++++++++
 6 files changed, 223 insertions(+), 3 deletions(-)

diff --git a/src/include/taler_twister_service.h 
b/src/include/taler_twister_service.h
index 486baf2..7adf40e 100644
--- a/src/include/taler_twister_service.h
+++ b/src/include/taler_twister_service.h
@@ -96,6 +96,25 @@ TALER_TWISTER_modify_path (struct TALER_TWISTER_Handle *h,
                            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_path
+  (struct TALER_TWISTER_Handle *h,
+   const char *path,
+   GNUNET_SCHEDULER_TaskCallback cb,
+   void *cb_cls);
+
+
+/**
  * Change the next response code to @a new_rc.
  *
  * @param h twister instance to control
diff --git a/src/test/test_twister.sh b/src/test/test_twister.sh
index 1413a0d..dae8697 100755
--- a/src/test/test_twister.sh
+++ b/src/test/test_twister.sh
@@ -39,11 +39,24 @@ if test '{"hello":[{"this":"browser!"}],"when":"today"}' = \
 fi
 
 
+# flip string.
+taler-twister -c ./test_twister.conf -f "when"
+flip_body=$(curl -s ${TWISTER_URL})
+flip_field=$(echo $flip_body | tr -d '"}{' | awk -F, '{print $2}' | awk -F: 
'{print $2}')
+
+# check if pointed object was flipped.
+if test "$flip_field" = 'today'; then
+  printf "Response body (%s vs. %s) has not been flipped as expected\n" 
"$flip_body" "$flip_field"
+  kill $web_server_pid
+  kill $twister_service_pid
+  exit 1
+fi
+
 # delete object.
 taler-twister -c ./test_twister.conf -d "hello.0"
 emptied_body=$(curl -s ${TWISTER_URL})
 
-# check response body has been emptied
+# check if pointed object was deleted.
 if ! test '{"hello":[],"when":"today"}' = "$emptied_body"; then
   printf "Response body (%s) has not been emptied as expected\n" \
     "$emptied_body"
diff --git a/src/twister/taler-twister-service.c 
b/src/twister/taler-twister-service.c
index 8eda2a6..d3687e2 100644
--- a/src/twister/taler-twister-service.c
+++ b/src/twister/taler-twister-service.c
@@ -253,6 +253,12 @@ static unsigned int hack_response_code;
 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'};
+
+/**
  * Will point to a JSON object to modify 
  */
 static char modify_path[TWISTER_PATH_LENGTH] = {'\0'};
@@ -889,7 +895,12 @@ walk_response_object (const char *path,
   last_token = strrchr (path_dup, '.') + 1;
   /* Give first nondelim char. */
   token = strtok (path_dup, ".");
-  element = hr->json;
+
+  if (NULL == (element = hr->json))
+  {
+    TALER_LOG_ERROR ("Attempting to walk a non JSON response!\n");
+    return GNUNET_SYSERR;
+  }
 
   while (last_token != token)
   {
@@ -1008,6 +1019,67 @@ modify_object (struct MHD_Connection *con,
     return;
 }
 
+static void
+flip_object (struct MHD_Connection *con,
+             struct HttpRequest *hr)
+{
+  char *target;
+  json_t *parent;
+
+  if (GNUNET_OK != walk_response_object (flip_path,
+                                         &parent,
+                                         &target,
+                                         hr))
+    return;
+
+  /* here, element is the parent of the element to be deleted. */
+  int ret_flip = -1;
+  json_t *child = NULL;
+  const char *current_value;
+  char *current_value_flip;
+  uint32_t index;
+
+  if (json_is_object (parent))
+    child = json_object_get (parent, target);
+
+  if (json_is_array (parent))
+    child = json_array_get
+      (parent, (unsigned int) strtoul (target,
+                                       NULL,
+                                       10));
+
+  /* json walker is such that at this point the
+   * child's parent is always a object or array.  */
+  GNUNET_assert (NULL != child);
+
+  current_value = json_string_value (child);
+
+  #warning When free this?
+  current_value_flip = GNUNET_strdup (current_value);
+  index = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+                                    strlen (current_value_flip));
+
+  /* flip the LSB.  */
+  current_value_flip[index] ^= 1;
+  if (0 == json_string_set
+      (child,
+       (const char *) current_value_flip))
+    ret_flip = GNUNET_YES;
+
+  if (-1 == ret_flip)
+    TALER_LOG_WARNING ("Could not flip '%s'\n", target);
+  else
+    TALER_LOG_INFO ("Flipped to %s, from %s\n",
+                    current_value_flip,
+                    current_value);
+
+  flip_path[0] = '\0';
+  GNUNET_free (target);
+  return;
+}
+
+
+
 /**
  * Delete object within the proxied response.
  * Always queues a response; only deletes the object if it is
@@ -1345,6 +1417,13 @@ create_response (void *cls,
     hack_response_code = 0; /* reset for next request */
   }
 
+  if ('\0' != flip_path[0])
+  {
+    TALER_LOG_DEBUG ("Will flip path: %s\n",
+                     flip_path);
+    flip_object (con, hr);
+  }
+
   if ('\0' != delete_path[0])
   {
     TALER_LOG_DEBUG ("Will delete path: %s\n",
@@ -1872,6 +1951,21 @@ handle_modify_path (void *cls,
   send_acknowledgement (c);
 }
 
+/**
+ * Control handler for deleting JSON objects
+ *
+ * @param cls message queue for sending replies
+ * @param src received message
+ */
+static void
+handle_flip_path (void *cls,
+                  const struct TWISTER_FlipPath *src)
+{
+  struct GNUNET_SERVICE_Client *c = cls;
+
+  strcpy (flip_path, src->path);
+  send_acknowledgement (c);
+}
 
 /**
  * Control handler for deleting JSON objects
@@ -1889,7 +1983,6 @@ handle_delete_path (void *cls,
   send_acknowledgement (c);
 }
 
-
 /**
  * Control handler for changing the response code
  *
@@ -1942,6 +2035,12 @@ GNUNET_SERVICE_MAIN
                          struct TWISTER_DeletePath,
                          NULL),
 
+ GNUNET_MQ_hd_fixed_size (flip_path,
+                         TWISTER_MESSAGE_TYPE_FLIP_PATH,
+                         struct TWISTER_FlipPath,
+                         NULL),
+
+
  GNUNET_MQ_handler_end ());
 
 
diff --git a/src/twister/taler-twister.c b/src/twister/taler-twister.c
index ce39104..3ff4a04 100644
--- a/src/twister/taler-twister.c
+++ b/src/twister/taler-twister.c
@@ -63,6 +63,11 @@ static int malform_response;
 static int malform_upload;
 
 /**
+ * Path to the string json object to flip.
+ */
+static char *flip_path;
+
+/**
  * Path to the object to modify.
  */
 static char *modify_path;
@@ -175,6 +180,14 @@ run (void *cls,
 
   /* TODO: add other operations here */
 
+  if ( (NULL != flip_path) &&
+       (NULL != TALER_TWISTER_flip_path
+         (tth,
+          flip_path,
+          &handle_acknowledgement,
+          NULL)) )
+    num_ops++;
+
   if ( (NULL != delete_path) &&
        (NULL != TALER_TWISTER_delete_path
          (tth,
@@ -230,6 +243,14 @@ main (int argc,
        &modify_path),
 
     GNUNET_GETOPT_option_string
+      ('f',
+       "flip",
+       "PATH",
+       gettext_noop
+         ("Flip a char in the _string_ object pointed by PATH.\n"),
+       &flip_path),
+
+    GNUNET_GETOPT_option_string
       ('V',
        "value",
        "VALUE",
diff --git a/src/twister/twister.h b/src/twister/twister.h
index c1ebeef..3e943f7 100644
--- a/src/twister/twister.h
+++ b/src/twister/twister.h
@@ -51,6 +51,8 @@
 
 #define TWISTER_MESSAGE_TYPE_MALFORM_UPLOAD 6
 
+#define TWISTER_MESSAGE_TYPE_FLIP_PATH 7
+
 GNUNET_NETWORK_STRUCT_BEGIN
 struct TWISTER_Malform
 {
@@ -92,6 +94,32 @@ GNUNET_NETWORK_STRUCT_BEGIN
  * standard deviation of known estimates.
  *
  */
+struct TWISTER_FlipPath
+{
+  /**
+   * Type: #TWISTER_MESSAGE_TYPE_DELETE_PATH
+   */
+  struct GNUNET_MessageHeader header;
+
+  /**
+   * The new response code, in big endian.
+   */
+  char path[TWISTER_PATH_LENGTH];
+};
+
+GNUNET_NETWORK_STRUCT_END
+
+
+
+GNUNET_NETWORK_STRUCT_BEGIN
+
+/**
+ * Network size estimate sent from the service
+ * to clients.  Contains the current size estimate
+ * (or 0 if none has been calculated) and the
+ * standard deviation of known estimates.
+ *
+ */
 struct TWISTER_DeletePath
 {
   /**
diff --git a/src/twister/twister_api.c b/src/twister/twister_api.c
index 477b774..aa96e6f 100644
--- a/src/twister/twister_api.c
+++ b/src/twister/twister_api.c
@@ -276,6 +276,46 @@ TALER_TWISTER_malform
 
 
 /**
+ * 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_path
+  (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?
+
+  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);
+  /* 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.
  *
  * @param h twister instance to control

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



reply via email to

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