diff options
author | Marcello Stanisci <stanisci.m@gmail.com> | 2018-03-13 16:12:45 +0100 |
---|---|---|
committer | Marcello Stanisci <stanisci.m@gmail.com> | 2018-03-13 16:12:45 +0100 |
commit | 1dd44afd032ed46d38500256222973044e4db95d (patch) | |
tree | 76f3bc1b4afd40df9f9809eea2b8405fba8a3f2e | |
parent | cd9a77bb86ddbb716bfef112a9532f8be1526696 (diff) | |
download | twister-1dd44afd032ed46d38500256222973044e4db95d.tar.gz twister-1dd44afd032ed46d38500256222973044e4db95d.tar.bz2 twister-1dd44afd032ed46d38500256222973044e4db95d.zip |
adding command for randomly truncating responses.
-rw-r--r-- | src/include/taler_twister_service.h | 13 | ||||
-rw-r--r-- | src/twister/taler-twister-service.c | 41 | ||||
-rw-r--r-- | src/twister/taler-twister.c | 18 | ||||
-rw-r--r-- | src/twister/twister.h | 12 | ||||
-rw-r--r-- | src/twister/twister_api.c | 33 |
5 files changed, 117 insertions, 0 deletions
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. |