[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [taler-twister] 29/34: adding command for randomly truncati
From: |
gnunet |
Subject: |
[GNUnet-SVN] [taler-twister] 29/34: adding command for randomly truncating responses. |
Date: |
Sat, 17 Mar 2018 01:58:20 +0100 |
This is an automated email from the git hooks/post-receive script.
marcello pushed a commit to branch master
in repository twister.
commit 1dd44afd032ed46d38500256222973044e4db95d
Author: Marcello Stanisci <address@hidden>
AuthorDate: Tue Mar 13 16:12:45 2018 +0100
adding command for randomly truncating responses.
---
src/include/taler_twister_service.h | 13 ++++++++++++
src/twister/taler-twister-service.c | 41 +++++++++++++++++++++++++++++++++++++
src/twister/taler-twister.c | 18 ++++++++++++++++
src/twister/twister.h | 12 +++++++++++
src/twister/twister_api.c | 33 +++++++++++++++++++++++++++++
5 files changed, 117 insertions(+)
diff --git a/src/include/taler_twister_service.h
b/src/include/taler_twister_service.h
index d952bcd..701633d 100644
--- a/src/include/taler_twister_service.h
+++ b/src/include/taler_twister_service.h
@@ -111,6 +111,19 @@ TALER_TWISTER_change_response_code
GNUNET_SCHEDULER_TaskCallback cb,
void *cb_cls);
+/**
+ * Randomly truncate the response.
+ *
+ * @param h twister instance to control
+ * @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_malform
+ (struct TALER_TWISTER_Handle *h,
+ GNUNET_SCHEDULER_TaskCallback cb,
+ void *cb_cls);
/**
* Delete the object pointed to by @a path.
diff --git a/src/twister/taler-twister-service.c
b/src/twister/taler-twister-service.c
index 251d5dc..9ea8151 100644
--- a/src/twister/taler-twister-service.c
+++ b/src/twister/taler-twister-service.c
@@ -253,6 +253,12 @@ static char delete_path[TWISTER_PATH_LENGTH] = {'\0'};
static char modify_path[TWISTER_PATH_LENGTH] = {'\0'};
/**
+ * If true, will randomly truncate the response before
+ * returning to the client.
+ */
+static unsigned int malform = GNUNET_NO;
+
+/**
* New value.
*/
static char modify_value[TWISTER_VALUE_LENGTH];
@@ -1298,11 +1304,24 @@ create_response (void *cls,
if (NULL != hr->json)
{
+ TALER_LOG_DEBUG ("Returning altered JSON.\n");
body = json_dumps (hr->json, JSON_COMPACT);
body_len = strlen (body);
json_decref (hr->json);
}
+ if (GNUNET_YES == malform)
+ {
+ size_t fake_len;
+
+ TALER_LOG_DEBUG
+ ("Will (badly) truncate the original output.\n");
+ fake_len = GNUNET_CRYPTO_random_u32
+ (GNUNET_CRYPTO_QUALITY_WEAK, hr->io_len);
+ body_len = fake_len;
+ malform = GNUNET_NO;
+ }
+
hr->response = MHD_create_response_from_buffer
(body_len,
body,
@@ -1740,6 +1759,23 @@ send_acknowledgement (struct GNUNET_SERVICE_Client *c)
}
/**
+ * Control handler for malforming responses.
+ *
+ * @param cls message queue for sending replies
+ * @param src received message
+ */
+static void
+handle_malform (void *cls,
+ const struct TWISTER_Malform *src)
+{
+ struct GNUNET_SERVICE_Client *c = cls;
+
+ malform = GNUNET_YES;
+ send_acknowledgement (c);
+}
+
+
+/**
* Control handler for deleting JSON objects
*
* @param cls message queue for sending replies
@@ -1812,6 +1848,11 @@ GNUNET_SERVICE_MAIN
struct TWISTER_ModifyPath,
NULL),
+ GNUNET_MQ_hd_fixed_size (malform,
+ TWISTER_MESSAGE_TYPE_MALFORM,
+ struct TWISTER_Malform,
+ NULL),
+
GNUNET_MQ_hd_fixed_size (delete_path,
TWISTER_MESSAGE_TYPE_DELETE_PATH,
struct TWISTER_DeletePath,
diff --git a/src/twister/taler-twister.c b/src/twister/taler-twister.c
index e7fe2ea..2807bab 100644
--- a/src/twister/taler-twister.c
+++ b/src/twister/taler-twister.c
@@ -53,6 +53,11 @@ static unsigned int hack_response_code;
static char *delete_path;
/**
+ * If true, will randomly truncate the proxied response.
+ */
+static int malform_response;
+
+/**
* Path to the object to modify.
*/
static char *modify_path;
@@ -134,6 +139,13 @@ run (void *cls,
return;
}
+ if ( (0 != malform_response) &&
+ (NULL != TALER_TWISTER_malform
+ (tth,
+ &handle_acknowledgement,
+ NULL)))
+ num_ops++;
+
if (0 != check_alive)
{
@@ -228,6 +240,12 @@ main (int argc,
gettext_noop ("Check if twister accepts IPC connections\n"),
&check_alive),
+ GNUNET_GETOPT_option_flag
+ ('M',
+ "malform",
+ gettext_noop ("Randomly truncate proxied response"),
+ &malform_response),
+
GNUNET_GETOPT_option_uint
('r',
"responsecode",
diff --git a/src/twister/twister.h b/src/twister/twister.h
index a9846e1..5954b3c 100644
--- a/src/twister/twister.h
+++ b/src/twister/twister.h
@@ -47,6 +47,18 @@
#define TWISTER_MESSAGE_TYPE_MODIFY_PATH 4
+#define TWISTER_MESSAGE_TYPE_MALFORM 5
+
+GNUNET_NETWORK_STRUCT_BEGIN
+struct TWISTER_Malform
+{
+ /**
+ * Type: #TWISTER_MESSAGE_TYPE_MALFORM
+ */
+ struct GNUNET_MessageHeader header;
+
+};
+GNUNET_NETWORK_STRUCT_END
GNUNET_NETWORK_STRUCT_BEGIN
struct TWISTER_ModifyPath
diff --git a/src/twister/twister_api.c b/src/twister/twister_api.c
index 26bae3e..c05e34b 100644
--- a/src/twister/twister_api.c
+++ b/src/twister/twister_api.c
@@ -202,6 +202,39 @@ TALER_TWISTER_cancel (struct TALER_TWISTER_Operation *op)
op->cb = NULL;
}
+/**
+ * Randomly truncate the response.
+ *
+ * @param h twister instance to control
+ * @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_malform
+ (struct TALER_TWISTER_Handle *h,
+ GNUNET_SCHEDULER_TaskCallback cb,
+ void *cb_cls)
+{
+ struct TALER_TWISTER_Operation *op;
+ struct GNUNET_MQ_Envelope *env;
+ struct TWISTER_Malform *src;
+
+ 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_MALFORM);
+ /* 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
- [GNUnet-SVN] [taler-twister] 20/34: option name., (continued)
- [GNUnet-SVN] [taler-twister] 20/34: option name., gnunet, 2018/03/16
- [GNUnet-SVN] [taler-twister] 24/34: add testing-lib command to modify responses., gnunet, 2018/03/16
- [GNUnet-SVN] [taler-twister] 31/34: implement upload data malformation., gnunet, 2018/03/16
- [GNUnet-SVN] [taler-twister] 34/34: leading slash when constructing twister url., gnunet, 2018/03/16
- [GNUnet-SVN] [taler-twister] 19/34: renaming operation., gnunet, 2018/03/16
- [GNUnet-SVN] [taler-twister] 26/34: remove number conversion, for now., gnunet, 2018/03/16
- [GNUnet-SVN] [taler-twister] 32/34: fix headers preparation for malformed uploads., gnunet, 2018/03/16
- [GNUnet-SVN] [taler-twister] 22/34: object walker as separate function., gnunet, 2018/03/16
- [GNUnet-SVN] [taler-twister] 21/34: dup'ing path string., gnunet, 2018/03/16
- [GNUnet-SVN] [taler-twister] 23/34: add command to modify responses., gnunet, 2018/03/16
- [GNUnet-SVN] [taler-twister] 29/34: adding command for randomly truncating responses.,
gnunet <=