From 1408842544b1cbea01efc636bdcb6be73a4e20a9 Mon Sep 17 00:00:00 2001 From: t3sserakt Date: Wed, 1 Dec 2021 14:06:12 +0100 Subject: - using the big macrofication of the traits from GNU Taler now --- src/include/gnunet_testing_netjail_lib.h | 58 +-- src/include/gnunet_testing_ng_lib.h | 399 +++++++-------------- src/testing/Makefile.am | 2 - src/testing/testing.c | 4 +- .../testing_api_cmd_block_until_external_trigger.c | 48 +-- src/testing/testing_api_cmd_local_test_prepared.c | 25 +- .../testing_api_cmd_netjail_start_testsystem.c | 34 +- .../testing_api_cmd_netjail_stop_testsystem.c | 2 +- src/testing/testing_api_cmd_system_create.c | 24 +- src/testing/testing_api_cmd_system_destroy.c | 4 +- src/testing/testing_api_trait_cmd.c | 79 ---- src/testing/testing_api_trait_process.c | 81 ----- src/testing/testing_api_traits.c | 7 + src/transport/Makefile.am | 1 + ...st_transport_plugin_cmd_simple_send_broadcast.c | 33 +- src/transport/test_transport_start_with_config.c | 1 + src/transport/transport-testing-cmds.h | 105 +++--- .../transport_api_cmd_backchannel_check.c | 6 +- src/transport/transport_api_cmd_connecting_peers.c | 35 +- src/transport/transport_api_cmd_send_simple.c | 10 +- src/transport/transport_api_cmd_start_peer.c | 168 +-------- src/transport/transport_api_cmd_stop_peer.c | 9 +- 22 files changed, 259 insertions(+), 876 deletions(-) delete mode 100644 src/testing/testing_api_trait_cmd.c delete mode 100644 src/testing/testing_api_trait_process.c diff --git a/src/include/gnunet_testing_netjail_lib.h b/src/include/gnunet_testing_netjail_lib.h index 334f43c88..7ec6b294b 100644 --- a/src/include/gnunet_testing_netjail_lib.h +++ b/src/include/gnunet_testing_netjail_lib.h @@ -351,12 +351,6 @@ GNUNET_TESTING_cmd_system_create (const char *label, const char *testdir); -int -GNUNET_TESTING_get_trait_test_system (const struct - GNUNET_TESTING_Command *cmd, - struct GNUNET_TESTING_System **test_system); - - /** * Create command. * @@ -427,30 +421,8 @@ struct GNUNET_MessageHeader * GNUNET_TESTING_send_local_test_finished_msg (enum GNUNET_GenericReturnValue rv); -/** - * Function to get the trait with the async context. - * - * @param[out] ac GNUNET_TESTING_AsyncContext. - * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. - */ -int -GNUNET_TESTING_get_trait_async_context ( - const struct GNUNET_TESTING_Command *cmd, - struct GNUNET_TESTING_AsyncContext **ac); -/** - * Offer handles to testing cmd helper from trait - * - * @param cmd command to extract the message from. - * @param pt pointer to message. - * @return #GNUNET_OK on success. - */ -enum GNUNET_GenericReturnValue -GNUNET_TESTING_get_trait_helper_handles ( - const struct GNUNET_TESTING_Command *cmd, - struct GNUNET_HELPER_Handle ***helper); - struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_block_until_all_peers_started ( @@ -501,28 +473,20 @@ GNUNET_TESTING_cmd_local_test_prepared (const char *label, TESTING_CMD_HELPER_write_cb write_message); -/** - * Function to get the trait with the struct LocalPreparedState. - * - * @param[out] lfs struct LocalPreparedState. - * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. - * - */ -enum GNUNET_GenericReturnValue -GNUNET_TESTING_get_trait_local_prepared_state ( - const struct GNUNET_TESTING_Command *cmd, - struct LocalPreparedState **lfs); + +/* ***** Netjail trait support ***** */ /** - * Function to get the trait with the internal command state BlockState. - * - * * @param[out] ac struct BlockState. -* @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. + * Call #op on all simple traits. */ -int -GNUNET_TESTING_get_trait_block_state ( - const struct GNUNET_TESTING_Command *cmd, - struct BlockState **bs); +#define GNUNET_TESTING_SIMPLE_NETJAIL_TRAITS(op) \ + op (test_system, const struct GNUNET_TESTING_System) \ + op (async_context, const struct GNUNET_TESTING_AsyncContext) \ + op (helper_handles, const void *) \ + op (local_prepared_state, const struct LocalPreparedState) \ + op (block_state, const struct BlockState) + +GNUNET_TESTING_SIMPLE_NETJAIL_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT) #endif diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h index c9f5e3e00..c0e534594 100644 --- a/src/include/gnunet_testing_ng_lib.h +++ b/src/include/gnunet_testing_ng_lib.h @@ -31,6 +31,14 @@ #include "gnunet_testing_plugin.h" #include "gnunet_testing_lib.h" +/** + * Stringify operator. + * + * @param a some expression to stringify. Must NOT be a macro. + * @return same expression as a constant string. + */ +#define GNUNET_S(a) #a + /* ********************* Helper functions ********************* */ @@ -195,7 +203,7 @@ struct GNUNET_TESTING_Command /** * If "true", the interpreter should not immediately call * @e finish, even if @e finish is non-NULL. Otherwise, - * #TALER_TESTING_cmd_finish() must be used + * #GNUNET_TESTING_cmd_finish() must be used * to ensure that a command actually completed. */ bool asynchronous_finish; @@ -575,8 +583,8 @@ GNUNET_TESTING_calculate_num (struct * @return The peer identity wrapping the public key. */ struct GNUNET_PeerIdentity * -GNUNET_TESTING_get_pub_key (unsigned int num, struct - GNUNET_TESTING_System *tl_system); +GNUNET_TESTING_get_pub_key (unsigned int num, + const struct GNUNET_TESTING_System *tl_system); /** @@ -642,279 +650,120 @@ GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait *traits, /* ****** Specific traits supported by this component ******* */ -/** - * Obtain location where a command stores a pointer to a process. - * - * @param cmd command to extract trait from. - * @param index which process to pick if @a cmd - * has multiple on offer. -- FIXME: remove? - * @param[out] processp set to the address of the pointer to the - * process. - * @return #GNUNET_OK on success. - */ -enum GNUNET_GenericReturnValue -GNUNET_TESTING_get_trait_process (const struct GNUNET_TESTING_Command *cmd, - unsigned int index, - struct GNUNET_OS_Process ***processp); - - -/** - * Offer location where a command stores a pointer to a process. - * - * @param index offered location index number, in case there are - * multiple on offer. // FIXME: remove? - * @param processp process location to offer. - * @return the trait. - */ -struct GNUNET_TESTING_Trait -GNUNET_TESTING_make_trait_process (unsigned int index, - struct GNUNET_OS_Process **processp); - - -/** - * Offer number trait, 32-bit version. - * - * @param index the number's index number. // FIXME: introduce enum? - * @param n number to offer. - */ -struct GNUNET_TESTING_Trait -GNUNET_TESTING_make_trait_uint32 (unsigned int index, - const uint32_t *n); - - -/** - * Obtain a "number" value from @a cmd, 32-bit version. - * - * @param cmd command to extract the number from. - * @param index the number's index number. // FIXME: introduce enum? - * @param[out] n set to the number coming from @a cmd. - * @return #GNUNET_OK on success. - */ -enum GNUNET_GenericReturnValue -GNUNET_TESTING_get_trait_uint32 (const struct GNUNET_TESTING_Command *cmd, - unsigned int index, - const uint32_t **n); - - -/** - * Offer number trait, 64-bit version. - * - * @param index the number's index number. // FIXME: introduce enum? - * @param n number to offer. - */ -struct GNUNET_TESTING_Trait -GNUNET_TESTING_make_trait_uint64 (unsigned int index, - const uint64_t *n); - - -/** - * Obtain a "number" value from @a cmd, 64-bit version. - * - * @param cmd command to extract the number from. - * @param index the number's index number. // FIXME: introduce enum? - * @param[out] n set to the number coming from @a cmd. - * @return #GNUNET_OK on success. - */ -enum GNUNET_GenericReturnValue -GNUNET_TESTING_get_trait_uint64 (const struct GNUNET_TESTING_Command *cmd, - unsigned int index, - const uint64_t **n); - - -/** - * Offer number trait, 64-bit signed version. - * - * @param index the number's index number. // FIXME: introduce enum? - * @param n number to offer. - */ -struct GNUNET_TESTING_Trait -GNUNET_TESTING_make_trait_int64 (unsigned int index, - const int64_t *n); - - -/** - * Obtain a "number" value from @a cmd, 64-bit signed version. - * - * @param cmd command to extract the number from. - * @param index the number's index number. // FIXME: introduce enum? - * @param[out] n set to the number coming from @a cmd. - * @return #GNUNET_OK on success. - */ -enum GNUNET_GenericReturnValue -GNUNET_TESTING_get_trait_int64 (const struct GNUNET_TESTING_Command *cmd, - unsigned int index, - const int64_t **n); - - -/** - * Offer a number. - * - * @param index the number's index number. - * @param n the number to offer. // FIXME: introduce enum? - * @return #GNUNET_OK on success. - */ -struct GNUNET_TESTING_Trait -GNUNET_TESTING_make_trait_uint (unsigned int index, - const unsigned int *i); - - -/** - * Obtain a number from @a cmd. - * - * @param cmd command to extract the number from. - * @param index the number's index number. // FIXME: introduce enum? - * @param[out] n set to the number coming from @a cmd. - * @return #GNUNET_OK on success. - */ -enum GNUNET_GenericReturnValue -GNUNET_TESTING_get_trait_uint (const struct GNUNET_TESTING_Command *cmd, - unsigned int index, - const unsigned int **n); - -/** - * Obtain a string from @a cmd. - * - * @param cmd command to extract the subject from. - * @param index index number associated with the transfer - * subject to offer. // FIXME: introduce enum? - * @param[out] s where to write the offered - * string. - * @return #GNUNET_OK on success. - */ -enum GNUNET_GenericReturnValue -GNUNET_TESTING_get_trait_string ( - const struct GNUNET_TESTING_Command *cmd, - unsigned int index, - const char **s); - - -/** - * Offer string subject. - * - * @param index index number associated with the transfer - * subject being offered. // FIXME: introduce enum? - * @param s string to offer. - * @return the trait. - */ -struct GNUNET_TESTING_Trait -GNUNET_TESTING_make_trait_string (unsigned int index, - const char *s); - -/** - * Offer a command in a trait. - * - * @param index always zero. Commands offering this - * kind of traits do not need this index. For - * example, a "meta" CMD returns always the - * CMD currently being executed. FIXME: remove! - * @param cmd wire details to offer. - * @return the trait. - */ -struct GNUNET_TESTING_Trait -GNUNET_TESTING_make_trait_cmd (unsigned int index, - const struct GNUNET_TESTING_Command *cmd); - /** - * Obtain a command from @a cmd. - * - * @param cmd command to extract the command from. - * @param index always zero. Commands offering this - * kind of traits do not need this index. For - * example, a "meta" CMD returns always the - * CMD currently being executed. FIXME: remove! - * @param[out] _cmd where to write the wire details. - * @return #GNUNET_OK on success. - */ -enum GNUNET_GenericReturnValue -GNUNET_TESTING_get_trait_cmd (const struct GNUNET_TESTING_Command *cmd, - unsigned int index, - struct GNUNET_TESTING_Command **_cmd); - - -/** - * Obtain a uuid from @a cmd. - * - * @param cmd command to extract the uuid from. - * @param index which amount to pick if @a cmd has multiple - * on offer // FIXME: introduce enum? - * @param[out] uuid where to write the uuid. - * @return #GNUNET_OK on success. - */ -enum GNUNET_GenericReturnValue -GNUNET_TESTING_get_trait_uuid (const struct GNUNET_TESTING_Command *cmd, - unsigned int index, - struct GNUNET_Uuid **uuid); - - -/** - * Offer a uuid in a trait. - * - * @param index which uuid to offer, in case there are - * multiple available. // FIXME: introduce enum? - * @param uuid the uuid to offer. - * @return the trait. - */ -struct GNUNET_TESTING_Trait -GNUNET_TESTING_make_trait_uuid (unsigned int index, - const struct GNUNET_Uuid *uuid); - - -/** - * Obtain a absolute time from @a cmd. - * - * @param cmd command to extract trait from - * @param index which time stamp to pick if - * @a cmd has multiple on offer // FIXME: introduce enum? - * @param[out] time set to the wanted WTID. - * @return #GNUNET_OK on success - */ -enum GNUNET_GenericReturnValue -GNUNET_TESTING_get_trait_absolute_time ( - const struct GNUNET_TESTING_Command *cmd, - unsigned int index, - const struct GNUNET_TIME_Absolute **time); - - -/** - * Offer a absolute time. - * - * @param index associate the object with this index - * @param time which object should be returned - * @return the trait. - */ -struct GNUNET_TESTING_Trait -GNUNET_TESTING_make_trait_absolute_time ( - unsigned int index, - const struct GNUNET_TIME_Absolute *time); - - -/** - * Obtain a relative time from @a cmd. - * - * @param cmd command to extract trait from - * @param index which time to pick if - * @a cmd has multiple on offer. - * @param[out] time set to the wanted WTID. - * @return #GNUNET_OK on success - */ -int -GNUNET_TESTING_get_trait_relative_time ( - const struct GNUNET_TESTING_Command *cmd, - unsigned int index, - const struct GNUNET_TIME_Relative **time); - - -/** - * Offer a relative time. - * - * @param index associate the object with this index - * @param time which object should be returned - * @return the trait. - */ -struct GNUNET_TESTING_Trait -GNUNET_TESTING_make_trait_relative_time ( - unsigned int index, - const struct GNUNET_TIME_Relative *time); + * Create headers for a trait with name @a name for + * statically allocated data of type @a type. + */ +#define GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT(name,type) \ + enum GNUNET_GenericReturnValue \ + GNUNET_TESTING_get_trait_ ## name ( \ + const struct GNUNET_TESTING_Command *cmd, \ + type **ret); \ + struct GNUNET_TESTING_Trait \ + GNUNET_TESTING_make_trait_ ## name ( \ + type * value); + + +/** + * Create C implementation for a trait with name @a name for statically + * allocated data of type @a type. + */ +#define GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT(name,type) \ + enum GNUNET_GenericReturnValue \ + GNUNET_TESTING_get_trait_ ## name ( \ + const struct GNUNET_TESTING_Command *cmd, \ + type **ret) \ + { \ + if (NULL == cmd->traits) return GNUNET_SYSERR; \ + return cmd->traits (cmd->cls, \ + (const void **) ret, \ + GNUNET_S (name), \ + 0); \ + } \ + struct GNUNET_TESTING_Trait \ + GNUNET_TESTING_make_trait_ ## name ( \ + type * value) \ + { \ + struct GNUNET_TESTING_Trait ret = { \ + .trait_name = GNUNET_S (name), \ + .ptr = (const void *) value \ + }; \ + return ret; \ + } + + +/** + * Create headers for a trait with name @a name for + * statically allocated data of type @a type. + */ +#define GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT(name,type) \ + enum GNUNET_GenericReturnValue \ + GNUNET_TESTING_get_trait_ ## name ( \ + const struct GNUNET_TESTING_Command *cmd, \ + unsigned int index, \ + type **ret); \ + struct GNUNET_TESTING_Trait \ + GNUNET_TESTING_make_trait_ ## name ( \ + unsigned int index, \ + type * value); + + +/** + * Create C implementation for a trait with name @a name for statically + * allocated data of type @a type. + */ +#define GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT(name,type) \ + enum GNUNET_GenericReturnValue \ + GNUNET_TESTING_get_trait_ ## name ( \ + const struct GNUNET_TESTING_Command *cmd, \ + unsigned int index, \ + type **ret) \ + { \ + if (NULL == cmd->traits) return GNUNET_SYSERR; \ + return cmd->traits (cmd->cls, \ + (const void **) ret, \ + GNUNET_S (name), \ + index); \ + } \ + struct GNUNET_TESTING_Trait \ + GNUNET_TESTING_make_trait_ ## name ( \ + unsigned int index, \ + type * value) \ + { \ + struct GNUNET_TESTING_Trait ret = { \ + .index = index, \ + .trait_name = GNUNET_S (name), \ + .ptr = (const void *) value \ + }; \ + return ret; \ + } + + +/** + * Call #op on all simple traits. + */ +#define GNUNET_TESTING_SIMPLE_TRAITS(op) \ + op (process, struct GNUNET_OS_Process *) + + +/** + * Call #op on all indexed traits. + */ +#define GNUNET_TESTING_INDEXED_TRAITS(op) \ + op (uint32, const uint32_t) \ + op (uint64, const uint64_t) \ + op (int64, const int64_t) \ + op (uint, const unsigned int) \ + op (string, const char) \ + op (cmd, const struct GNUNET_TESTING_Command) \ + op (uuid, const struct GNUNET_Uuid) \ + op (time, const struct GNUNET_TIME_Absolute) \ + op (absolute_time, const struct GNUNET_TIME_Absolute) \ + op (relative_time, const struct GNUNET_TIME_Relative) + +GNUNET_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT) + +GNUNET_TESTING_INDEXED_TRAITS (GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT) #endif diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am index a9a1b5a02..bcb45da70 100644 --- a/src/testing/Makefile.am +++ b/src/testing/Makefile.am @@ -44,8 +44,6 @@ libgnunettesting_la_SOURCES = \ testing_api_cmd_system_destroy.c \ testing_api_cmd_batch.c \ testing_api_loop.c \ - testing_api_trait_cmd.c \ - testing_api_trait_process.c \ testing_api_traits.c libgnunettesting_la_LIBADD = \ $(top_builddir)/src/arm/libgnunetarm.la \ diff --git a/src/testing/testing.c b/src/testing/testing.c index 7474d9b5f..fd0701d7d 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c @@ -2169,8 +2169,8 @@ GNUNET_TESTING_get_connections (unsigned int num, struct * @return The peer identity wrapping the public key. */ struct GNUNET_PeerIdentity * -GNUNET_TESTING_get_pub_key (unsigned int num, struct - GNUNET_TESTING_System *tl_system) +GNUNET_TESTING_get_pub_key (unsigned int num, + const struct GNUNET_TESTING_System *tl_system) { struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity); struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct diff --git a/src/testing/testing_api_cmd_block_until_external_trigger.c b/src/testing/testing_api_cmd_block_until_external_trigger.c index 9360dd02e..f51b2109b 100644 --- a/src/testing/testing_api_cmd_block_until_external_trigger.c +++ b/src/testing/testing_api_cmd_block_until_external_trigger.c @@ -55,16 +55,8 @@ block_until_external_trigger_traits (void *cls, struct BlockState *bs = cls; struct GNUNET_TESTING_AsyncContext *ac = &bs->ac; struct GNUNET_TESTING_Trait traits[] = { - { - .index = 0, - .trait_name = "async_context", - .ptr = (const void *) ac, - }, - { - .index = 1, - .trait_name = "block_state", - .ptr = (const void *) bs, - }, + GNUNET_TESTING_make_trait_async_context ((const void *) ac), + GNUNET_TESTING_make_trait_block_state ((const void *) bs), GNUNET_TESTING_trait_end () }; @@ -75,42 +67,6 @@ block_until_external_trigger_traits (void *cls, } -/** - * Function to get the trait with the internal command state BlockState. - * - * * @param[out] ac struct BlockState. -* @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. - */ -int -GNUNET_TESTING_get_trait_block_state ( - const struct GNUNET_TESTING_Command *cmd, - struct BlockState **bs) -{ - return cmd->traits (cmd->cls, - (const void **) bs, - "block_state", - (unsigned int) 1); -} - - -/** - * Function to get the trait with the async context. - * - * @param[out] ac struct GNUNET_TESTING_AsyncContext. - * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. - */ -int -GNUNET_TESTING_get_trait_async_context ( - const struct GNUNET_TESTING_Command *cmd, - struct GNUNET_TESTING_AsyncContext **ac) -{ - return cmd->traits (cmd->cls, - (const void **) ac, - "async_context", - (unsigned int) 0); -} - - /** * This function does nothing but to start the cmd. * diff --git a/src/testing/testing_api_cmd_local_test_prepared.c b/src/testing/testing_api_cmd_local_test_prepared.c index 9dc7dfa9a..1f470a6c1 100644 --- a/src/testing/testing_api_cmd_local_test_prepared.c +++ b/src/testing/testing_api_cmd_local_test_prepared.c @@ -47,11 +47,7 @@ local_test_prepared_traits (void *cls, { struct LocalPreparedState *lfs = cls; struct GNUNET_TESTING_Trait traits[] = { - { - .index = 0, - .trait_name = "state", - .ptr = (const void *) lfs, - }, + GNUNET_TESTING_make_trait_local_prepared_state ((const void *) lfs), GNUNET_TESTING_trait_end () }; return GNUNET_TESTING_get_trait (traits, @@ -61,25 +57,6 @@ local_test_prepared_traits (void *cls, } -/** - * Function to get the trait with the struct LocalPreparedState. - * - * @param[out] lfs struct LocalPreparedState. - * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. - * - */ -enum GNUNET_GenericReturnValue -GNUNET_TESTING_get_trait_local_prepared_state ( - const struct GNUNET_TESTING_Command *cmd, - struct LocalPreparedState **lfs) -{ - return cmd->traits (cmd->cls, - (const void **) lfs, - "state", - (unsigned int) 0); -} - - /** * The cleanup function of this cmd frees resources the cmd allocated. * diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem.c b/src/testing/testing_api_cmd_netjail_start_testsystem.c index 1709a58d2..d24ad3d28 100644 --- a/src/testing/testing_api_cmd_netjail_start_testsystem.c +++ b/src/testing/testing_api_cmd_netjail_start_testsystem.c @@ -86,7 +86,7 @@ struct NetJailState /** * Array with handles of helper processes. */ - struct GNUNET_HELPER_Handle **helper; + const struct GNUNET_HELPER_Handle **helper; /** * Size of the array NetJailState#helper. @@ -211,22 +211,18 @@ netjail_exec_cleanup (void *cls) * This function prepares an array with traits. * */ -static int +static enum GNUNET_GenericReturnValue netjail_exec_traits (void *cls, const void **ret, const char *trait, unsigned int index) { struct NetJailState *ns = cls; - struct GNUNET_HELPER_Handle **helper = ns->helper; + const struct GNUNET_HELPER_Handle **helper = ns->helper; struct GNUNET_TESTING_Trait traits[] = { - { - .index = 0, - .trait_name = "helper_handles", - .ptr = (const void *) helper, - }, + GNUNET_TESTING_make_trait_helper_handles ((const void **) helper), GNUNET_TESTING_trait_end () }; @@ -237,26 +233,6 @@ netjail_exec_traits (void *cls, } -/** - * Offer handles to testing cmd helper from trait - * - * @param cmd command to extract the message from. - * @param pt pointer to message. - * @return #GNUNET_OK on success. - */ -int -GNUNET_TESTING_get_trait_helper_handles (const struct - GNUNET_TESTING_Command *cmd, - struct GNUNET_HELPER_Handle *** - helper) -{ - return cmd->traits (cmd->cls, - (const void **) helper, - "helper_handles", - (unsigned int) 0); -} - - /** * Continuation function from GNUNET_HELPER_send() * @@ -287,7 +263,7 @@ send_message_to_locals ( ) { // unsigned int total_number = ns->local_m * ns->global_n + ns->known; - struct GNUNET_HELPER_Handle *helper; + const struct GNUNET_HELPER_Handle *helper; struct TestingSystemCount *tbc; LOG (GNUNET_ERROR_TYPE_DEBUG, diff --git a/src/testing/testing_api_cmd_netjail_stop_testsystem.c b/src/testing/testing_api_cmd_netjail_stop_testsystem.c index 4b52878c4..caf83ab0e 100644 --- a/src/testing/testing_api_cmd_netjail_stop_testsystem.c +++ b/src/testing/testing_api_cmd_netjail_stop_testsystem.c @@ -86,7 +86,7 @@ stop_testing_system_run (void *cls, struct GNUNET_TESTING_Interpreter *is) { struct StopHelperState *shs = cls; - struct GNUNET_HELPER_Handle **helper; + const struct GNUNET_HELPER_Handle **helper; const struct GNUNET_TESTING_Command *start_helper_cmd; start_helper_cmd = GNUNET_TESTING_interpreter_lookup_command (is, diff --git a/src/testing/testing_api_cmd_system_create.c b/src/testing/testing_api_cmd_system_create.c index 275132684..221bbb8f6 100644 --- a/src/testing/testing_api_cmd_system_create.c +++ b/src/testing/testing_api_cmd_system_create.c @@ -77,11 +77,7 @@ system_create_traits (void *cls, struct GNUNET_TESTING_System *test_system = tss->test_system; struct GNUNET_TESTING_Trait traits[] = { - { - .index = 0, - .trait_name = "test_system", - .ptr = (const void *) test_system, - }, + GNUNET_TESTING_make_trait_test_system ((const void *) test_system), GNUNET_TESTING_trait_end () }; @@ -92,24 +88,6 @@ system_create_traits (void *cls, } -/** - * Function to get the trait with struct GNUNET_TESTING_System - * - * @param[out] test_system The struct GNUNET_TESTING_System. - * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. - */ -int -GNUNET_TESTING_get_trait_test_system (const struct - GNUNET_TESTING_Command *cmd, - struct GNUNET_TESTING_System **test_system) -{ - return cmd->traits (cmd->cls, - (const void **) test_system, - "test_system", - (unsigned int) 0); -} - - /** * The cleanup function of this cmd frees resources the cmd allocated. * diff --git a/src/testing/testing_api_cmd_system_destroy.c b/src/testing/testing_api_cmd_system_destroy.c index cdfc65d53..5a2440766 100644 --- a/src/testing/testing_api_cmd_system_destroy.c +++ b/src/testing/testing_api_cmd_system_destroy.c @@ -51,13 +51,13 @@ system_destroy_run (void *cls, { struct TestSystemState *tss = cls; const struct GNUNET_TESTING_Command *system_cmd; - struct GNUNET_TESTING_System *tl_system; + const struct GNUNET_TESTING_System *tl_system; system_cmd = GNUNET_TESTING_interpreter_lookup_command (is, tss->create_label); GNUNET_TESTING_get_trait_test_system (system_cmd, &tl_system); - GNUNET_TESTING_system_destroy (tl_system, + GNUNET_TESTING_system_destroy ((struct GNUNET_TESTING_System *) tl_system, GNUNET_YES); } diff --git a/src/testing/testing_api_trait_cmd.c b/src/testing/testing_api_trait_cmd.c deleted file mode 100644 index 7afa8b264..000000000 --- a/src/testing/testing_api_trait_cmd.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - This file is part of GNUnet - Copyright (C) 2021 GNUnet e.V. - - GNUnet is free software: you can redistribute it and/or modify it - under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - - SPDX-License-Identifier: AGPL3.0-or-later - */ - -/** - * @file testing/testing_api_trait_cmd.c - * @brief offers CMDs as traits. - * @author Marcello Stanisci (GNU Taler testing) - * @author t3sserakt - */ -#include "platform.h" -#include "gnunet_testing_ng_lib.h" - -#define GNUNET_TESTING_TRAIT_CMD "cmd" - - -/** - * Obtain a command from @a cmd. - * - * @param cmd command to extract the command from. - * @param index always zero. Commands offering this - * kind of traits do not need this index. For - * example, a "batch" CMD returns always the - * CMD currently being executed. - * @param[out] _cmd where to write the wire details. - * @return #GNUNET_OK on success. - */ -enum GNUNET_GenericReturnValue -GNUNET_TESTING_get_trait_cmd (const struct GNUNET_TESTING_Command *cmd, - unsigned int index, - struct GNUNET_TESTING_Command **_cmd) -{ - return cmd->traits (cmd->cls, - (const void **) _cmd, - GNUNET_TESTING_TRAIT_CMD, - index); -} - - -/** - * Offer a command in a trait. - * - * @param index always zero. Commands offering this - * kind of traits do not need this index. For - * example, a "meta" CMD returns always the - * CMD currently being executed. - * @param cmd wire details to offer. - * @return the trait. - */ -struct GNUNET_TESTING_Trait -GNUNET_TESTING_make_trait_cmd (unsigned int index, - const struct GNUNET_TESTING_Command *cmd) -{ - struct GNUNET_TESTING_Trait ret = { - .index = index, - .trait_name = GNUNET_TESTING_TRAIT_CMD, - .ptr = (const struct GNUNET_TESTING_Command *) cmd - }; - return ret; -} - - -/* end of testing_api_trait_cmd.c */ diff --git a/src/testing/testing_api_trait_process.c b/src/testing/testing_api_trait_process.c deleted file mode 100644 index 31cdb01df..000000000 --- a/src/testing/testing_api_trait_process.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - This file is part of GNUnet - Copyright (C) 2021 GNUnet e.V. - - GNUnet is free software: you can redistribute it and/or modify it - under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - - SPDX-License-Identifier: AGPL3.0-or-later - */ - -/** - * @file testing/testing_api_trait_process.c - * @brief trait offering process handles. - * @author Christian Grothoff (GNU Taler testing) - * @author Marcello Stanisci (GNU Taler testing) - * @author t3sserakt - */ -#include "platform.h" -#include "gnunet_testing_ng_lib.h" - -#define GNUNET_TESTING_TRAIT_PROCESS "process" - - -/** - * Obtain location where a command stores a pointer to a process. - * - * @param cmd command to extract trait from. - * @param index which process to pick if @a cmd - * has multiple on offer. - * @param[out] processp set to the address of the pointer to the - * process. - * @return #GNUNET_OK on success. - */ -int -GNUNET_TESTING_get_trait_process - (const struct GNUNET_TESTING_Command *cmd, - unsigned int index, - struct GNUNET_OS_Process ***processp) -{ - return cmd->traits (cmd->cls, - (const void **) processp, - GNUNET_TESTING_TRAIT_PROCESS, - index); -} - - -/** - * Offer location where a command stores a pointer to a process. - * - * @param index offered location index number, in case there are - * multiple on offer. - * @param processp process location to offer. - * - * @return the trait. - */ -struct GNUNET_TESTING_Trait -GNUNET_TESTING_make_trait_process - (unsigned int index, - struct GNUNET_OS_Process **processp) -{ - struct GNUNET_TESTING_Trait ret = { - .index = index, - .trait_name = GNUNET_TESTING_TRAIT_PROCESS, - .ptr = (const void *) processp - }; - - return ret; -} - - -/* end of testing_api_trait_process.c */ diff --git a/src/testing/testing_api_traits.c b/src/testing/testing_api_traits.c index 2f836ddfa..9b54443a1 100644 --- a/src/testing/testing_api_traits.c +++ b/src/testing/testing_api_traits.c @@ -27,8 +27,15 @@ */ #include "platform.h" #include "gnunet_testing_ng_lib.h" +#include "gnunet_testing_netjail_lib.h" +GNUNET_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT) + +GNUNET_TESTING_INDEXED_TRAITS (GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT) + +GNUNET_TESTING_SIMPLE_NETJAIL_TRAITS (GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT) + /** * End a trait array. Usually, commands offer several traits, * and put them in arrays. diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index 423602fea..751bc40c1 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am @@ -159,6 +159,7 @@ libgnunettransporttesting_la_LDFLAGS = \ $(GN_LIB_LDFLAGS) libgnunettransporttesting2_la_SOURCES = \ + transport_api_traits.c \ transport_api_cmd_connecting_peers.c \ transport_api_cmd_backchannel_check.c \ transport_api_cmd_start_peer.c \ diff --git a/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c b/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c index 526f08e6a..9d6844be1 100644 --- a/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c +++ b/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c @@ -96,15 +96,15 @@ static void handle_test (void *cls, const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) { - struct GNUNET_TESTING_AsyncContext *ac; + const struct GNUNET_TESTING_AsyncContext *ac; GNUNET_TESTING_get_trait_async_context (&block_receive, &ac); GNUNET_assert (NULL != ac); - if (NULL == ac->cont) - GNUNET_TESTING_async_fail (ac); - else - GNUNET_TESTING_async_finish (ac); + if ((GNUNET_NO == ac->finished) && (NULL == ac->cont)) + GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) ac); + else if (GNUNET_NO == ac->finished) + GNUNET_TESTING_async_finish ((struct GNUNET_TESTING_AsyncContext *) ac); } @@ -115,7 +115,7 @@ handle_test (void *cls, static void all_peers_started () { - struct GNUNET_TESTING_AsyncContext *ac; + const struct GNUNET_TESTING_AsyncContext *ac; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message\n"); @@ -123,9 +123,9 @@ all_peers_started () &ac); GNUNET_assert (NULL != ac); if (NULL == ac->cont) - GNUNET_TESTING_async_fail (ac); + GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) ac); else - GNUNET_TESTING_async_finish (ac); + GNUNET_TESTING_async_finish ((struct GNUNET_TESTING_AsyncContext *) ac); } @@ -168,7 +168,7 @@ static void * notify_connect (struct GNUNET_TESTING_Interpreter *is, const struct GNUNET_PeerIdentity *peer) { - struct GNUNET_TESTING_AsyncContext *ac; + const struct GNUNET_TESTING_AsyncContext *ac; void *ret = NULL; const struct GNUNET_TESTING_Command *cmd; struct BlockState *bs; @@ -186,9 +186,9 @@ notify_connect (struct GNUNET_TESTING_Interpreter *is, "notify_connect running\n"); GNUNET_assert (NULL != ac); if (NULL == ac->cont) - GNUNET_TESTING_async_fail (ac); + GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) ac); else - GNUNET_TESTING_async_finish (ac); + GNUNET_TESTING_async_finish ((struct GNUNET_TESTING_AsyncContext *) ac); } else { @@ -198,7 +198,9 @@ notify_connect (struct GNUNET_TESTING_Interpreter *is, LOG (GNUNET_ERROR_TYPE_DEBUG, "block state %s\n", cmd->label); - GNUNET_TESTING_get_trait_block_state (cmd,&bs); + GNUNET_TESTING_get_trait_block_state ( + cmd, + (const struct BlockState **) &bs); LOG (GNUNET_ERROR_TYPE_DEBUG, "block state %u\n", @@ -219,15 +221,16 @@ notify_connect (struct GNUNET_TESTING_Interpreter *is, static void all_local_tests_prepared () { - struct LocalPreparedState *lfs; + const struct LocalPreparedState *lfs; GNUNET_TESTING_get_trait_local_prepared_state (&local_prepared, &lfs); GNUNET_assert (NULL != &lfs->ac); if (NULL == lfs->ac.cont) - GNUNET_TESTING_async_fail (&lfs->ac); + GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) &lfs->ac); else - GNUNET_TESTING_async_finish (&lfs->ac); + GNUNET_TESTING_async_finish ((struct + GNUNET_TESTING_AsyncContext *) &lfs->ac); } diff --git a/src/transport/test_transport_start_with_config.c b/src/transport/test_transport_start_with_config.c index 7eb92d629..c3411becc 100644 --- a/src/transport/test_transport_start_with_config.c +++ b/src/transport/test_transport_start_with_config.c @@ -26,6 +26,7 @@ #include "platform.h" #include "gnunet_testing_ng_lib.h" #include "gnunet_testing_netjail_lib.h" +#include "transport-testing-cmds.h" #include "gnunet_util_lib.h" #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) diff --git a/src/transport/transport-testing-cmds.h b/src/transport/transport-testing-cmds.h index d64279aeb..af6f47962 100644 --- a/src/transport/transport-testing-cmds.h +++ b/src/transport/transport-testing-cmds.h @@ -49,7 +49,7 @@ struct ConnectPeersState /** * The testing system of this node. */ - struct GNUNET_TESTING_System *tl_system; + const struct GNUNET_TESTING_System *tl_system; // Label of the cmd which started the test system. const char *create_label; @@ -180,7 +180,7 @@ struct StartPeerState struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map; - struct GNUNET_TESTING_System *tl_system; + const struct GNUNET_TESTING_System *tl_system; GNUNET_TRANSPORT_notify_connect_cb notify_connect; @@ -191,26 +191,6 @@ struct StartPeerState }; -/** - * Function to get the trait with the struct ConnectPeersState. - * - * @param[out] sps struct ConnectPeersState. - * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. - * - */ -int -GNUNET_TRANSPORT_get_trait_connect_peer_state ( - const struct GNUNET_TESTING_Command *cmd, - struct ConnectPeersState **cps); - - -int -GNUNET_TRANSPORT_get_trait_state (const struct - GNUNET_TESTING_Command - *cmd, - struct StartPeerState **sps); - - /** * Create command. * @@ -305,43 +285,62 @@ GNUNET_TRANSPORT_cmd_backchannel_check (const char *label, topology); +/** + * Create headers for a trait with name @a name for + * statically allocated data of type @a type. + */ +#define GNUNET_TRANSPORT_MAKE_DECL_SIMPLE_TRAIT(name,type) \ + enum GNUNET_GenericReturnValue \ + GNUNET_TRANSPORT_get_trait_ ## name ( \ + const struct GNUNET_TESTING_Command *cmd, \ + type **ret); \ + struct GNUNET_TESTING_Trait \ + GNUNET_TRANSPORT_make_trait_ ## name ( \ + type * value); +/** + * Create C implementation for a trait with name @a name for statically + * allocated data of type @a type. + */ +#define GNUNET_TRANSPORT_MAKE_IMPL_SIMPLE_TRAIT(name,type) \ + enum GNUNET_GenericReturnValue \ + GNUNET_TRANSPORT_get_trait_ ## name ( \ + const struct GNUNET_TESTING_Command *cmd, \ + type **ret) \ + { \ + if (NULL == cmd->traits) return GNUNET_SYSERR; \ + return cmd->traits (cmd->cls, \ + (const void **) ret, \ + GNUNET_S (name), \ + 0); \ + } \ + struct GNUNET_TESTING_Trait \ + GNUNET_TRANSPORT_make_trait_ ## name ( \ + type * value) \ + { \ + struct GNUNET_TESTING_Trait ret = { \ + .trait_name = GNUNET_S (name), \ + .ptr = (const void *) value \ + }; \ + return ret; \ + } -int -GNUNET_TRANSPORT_get_trait_peer_id (const struct - GNUNET_TESTING_Command *cmd, - struct GNUNET_PeerIdentity **id); - - -int -GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct - GNUNET_TESTING_Command - *cmd, - struct - GNUNET_CONTAINER_MultiShortmap - * - * - connected_peers_map); -int -GNUNET_TRANSPORT_get_trait_hello_size (const struct - GNUNET_TESTING_Command - *cmd, - size_t **hello_size); -int -GNUNET_TRANSPORT_get_trait_hello (const struct - GNUNET_TESTING_Command - *cmd, - char **hello); +/** + * Call #op on all simple traits. + */ +#define GNUNET_TRANSPORT_SIMPLE_TRAITS(op) \ + op (peer_id, const struct GNUNET_PeerIdentity) \ + op (connected_peers_map, const struct GNUNET_CONTAINER_MultiShortmap) \ + op (hello_size, const size_t) \ + op (hello, const char) \ + op (application_handle, const struct GNUNET_TRANSPORT_ApplicationHandle) \ + op (connect_peer_state, const struct ConnectPeersState) \ + op (state, const struct StartPeerState) +GNUNET_TRANSPORT_SIMPLE_TRAITS (GNUNET_TRANSPORT_MAKE_DECL_SIMPLE_TRAIT) -int -GNUNET_TRANSPORT_get_trait_application_handle (const struct - GNUNET_TESTING_Command *cmd, - struct - GNUNET_TRANSPORT_ApplicationHandle - **ah); #endif /* end of transport_testing.h */ diff --git a/src/transport/transport_api_cmd_backchannel_check.c b/src/transport/transport_api_cmd_backchannel_check.c index 529b4690b..1bec3abd3 100644 --- a/src/transport/transport_api_cmd_backchannel_check.c +++ b/src/transport/transport_api_cmd_backchannel_check.c @@ -69,7 +69,7 @@ struct CheckState /** * The testing system of this node. */ - struct GNUNET_TESTING_System *tl_system; + const struct GNUNET_TESTING_System *tl_system; // Label of the cmd which started the test system. const char *create_label; @@ -404,9 +404,9 @@ backchannel_check_run (void *cls, // char *part_one = "Delivering backchannel message from "; // char *part_two = " of type 1460 to udp"; const struct GNUNET_TESTING_Command *system_cmd; - struct GNUNET_TESTING_System *tl_system; + const struct GNUNET_TESTING_System *tl_system; const struct GNUNET_TESTING_Command *peer1_cmd; - struct GNUNET_TRANSPORT_ApplicationHandle *ah; + const struct GNUNET_TRANSPORT_ApplicationHandle *ah; // struct GNUNET_PeerIdentity *peer; // uint32_t num; // struct GNUNET_TESTING_NodeConnection *pos_connection; diff --git a/src/transport/transport_api_cmd_connecting_peers.c b/src/transport/transport_api_cmd_connecting_peers.c index f65b6f666..fc925675d 100644 --- a/src/transport/transport_api_cmd_connecting_peers.c +++ b/src/transport/transport_api_cmd_connecting_peers.c @@ -47,11 +47,11 @@ connect_peers_run (void *cls, { struct ConnectPeersState *cps = cls; const struct GNUNET_TESTING_Command *system_cmd; - struct GNUNET_TESTING_System *tl_system; + const struct GNUNET_TESTING_System *tl_system; const struct GNUNET_TESTING_Command *peer1_cmd; - struct GNUNET_TRANSPORT_ApplicationHandle *ah; + const struct GNUNET_TRANSPORT_ApplicationHandle *ah; struct GNUNET_PeerIdentity *peer; char *addr; enum GNUNET_NetworkType nt = 0; @@ -98,7 +98,9 @@ connect_peers_run (void *cls, "validating peer number %u with identity %s\n", num, GNUNET_i2s (peer)); - GNUNET_TRANSPORT_application_validate (ah, + GNUNET_TRANSPORT_application_validate ((struct + GNUNET_TRANSPORT_ApplicationHandle + *) ah, peer, nt, addr); @@ -176,13 +178,9 @@ connect_peers_traits (void *cls, const char *trait, unsigned int index) { - struct StartPeerState *cps = cls; + struct ConnectPeersState *cps = cls; struct GNUNET_TESTING_Trait traits[] = { - { - .index = 0, - .trait_name = "state", - .ptr = (const void *) cps, - }, + GNUNET_TRANSPORT_make_trait_connect_peer_state ((const void *) cps), GNUNET_TESTING_trait_end () }; return GNUNET_TESTING_get_trait (traits, @@ -192,25 +190,6 @@ connect_peers_traits (void *cls, } -/** - * Function to get the trait with the struct ConnectPeersState. - * - * @param[out] sps struct ConnectPeersState. - * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. - * - */ -enum GNUNET_GenericReturnValue -GNUNET_TRANSPORT_get_trait_connect_peer_state ( - const struct GNUNET_TESTING_Command *cmd, - struct ConnectPeersState **cps) -{ - return cmd->traits (cmd->cls, - (const void **) cps, - "state", - (unsigned int) 0); -} - - /** * Create command * diff --git a/src/transport/transport_api_cmd_send_simple.c b/src/transport/transport_api_cmd_send_simple.c index 8b37dbf90..ade0cc914 100644 --- a/src/transport/transport_api_cmd_send_simple.c +++ b/src/transport/transport_api_cmd_send_simple.c @@ -114,7 +114,7 @@ send_simple_run (void *cls, struct GNUNET_TESTING_Interpreter *is) { struct SendSimpleState *sss = cls; - struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map; + const struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map; const struct GNUNET_TESTING_Command *peer1_cmd; // struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode); struct GNUNET_HashCode hc; @@ -124,7 +124,7 @@ send_simple_run (void *cls, uint32_t num; struct GNUNET_TESTING_NodeConnection *pos_connection; const struct GNUNET_TESTING_Command *system_cmd; - struct GNUNET_TESTING_System *tl_system; + const struct GNUNET_TESTING_System *tl_system; peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is, sss->start_peer_label); @@ -139,8 +139,10 @@ send_simple_run (void *cls, node_connections_head = GNUNET_TESTING_get_connections (sss->num, sss->topology); - GNUNET_CONTAINER_multishortmap_iterate (connected_peers_map, send_simple_cb, - sss); + GNUNET_CONTAINER_multishortmap_iterate ( + (struct GNUNET_CONTAINER_MultiShortmap *) + connected_peers_map, send_simple_cb, + sss); /*for (int i = 0; i < 1; i++) { for (pos_connection = node_connections_head; NULL != pos_connection; diff --git a/src/transport/transport_api_cmd_start_peer.c b/src/transport/transport_api_cmd_start_peer.c index 52eacabb2..be2ea25b4 100644 --- a/src/transport/transport_api_cmd_start_peer.c +++ b/src/transport/transport_api_cmd_start_peer.c @@ -167,7 +167,7 @@ start_peer_run (void *cls, char *emsg = NULL; struct GNUNET_PeerIdentity dummy; const struct GNUNET_TESTING_Command *system_cmd; - struct GNUNET_TESTING_System *tl_system; + const struct GNUNET_TESTING_System *tl_system; char *home; char *transport_unix_path; char *tcp_communicator_unix_path; @@ -251,7 +251,8 @@ start_peer_run (void *cls, sps->no); if (GNUNET_SYSERR == - GNUNET_TESTING_configuration_create (tl_system, + GNUNET_TESTING_configuration_create ((struct + GNUNET_TESTING_System *) tl_system, sps->cfg)) { LOG (GNUNET_ERROR_TYPE_DEBUG, @@ -262,7 +263,9 @@ start_peer_run (void *cls, return; } - sps->peer = GNUNET_TESTING_peer_configure (sps->tl_system, + sps->peer = GNUNET_TESTING_peer_configure ((struct + GNUNET_TESTING_System *) sps-> + tl_system, sps->cfg, sps->no, NULL, @@ -407,36 +410,14 @@ start_peer_traits (void *cls, struct GNUNET_TESTING_Trait traits[] = { - { - .index = 0, - .trait_name = "application_handle", - .ptr = (const void *) ah, - }, - { - .index = 1, - .trait_name = "peer_id", - .ptr = (const void *) id, - }, - { - .index = 2, - .trait_name = "connected_peers_map", - .ptr = (const void *) connected_peers_map, - }, - { - .index = 3, - .trait_name = "hello", - .ptr = (const void *) hello, - }, - { - .index = 4, - .trait_name = "hello_size", - .ptr = (const void *) hello_size, - }, - { - .index = 5, - .trait_name = "state", - .ptr = (const void *) sps, - }, + GNUNET_TRANSPORT_make_trait_application_handle ((const void *) ah), + GNUNET_TRANSPORT_make_trait_peer_id ((const void *) id), + GNUNET_TRANSPORT_make_trait_connected_peers_map ((const + void *) + connected_peers_map), + GNUNET_TRANSPORT_make_trait_hello ((const void *) hello), + GNUNET_TRANSPORT_make_trait_hello_size ((const void *) hello_size), + GNUNET_TRANSPORT_make_trait_state ((const void *) sps), GNUNET_TESTING_trait_end () }; @@ -447,127 +428,6 @@ start_peer_traits (void *cls, } -/** - * Function to get the trait with the struct StartPeerState. - * - * @param[out] sps struct StartPeerState. - * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. - * - */ -int -GNUNET_TRANSPORT_get_trait_state ( - const struct GNUNET_TESTING_Command *cmd, - struct StartPeerState **sps) -{ - return cmd->traits (cmd->cls, - (const void **) sps, - "state", - (unsigned int) 5); -} - - -/** - * Function to get the trait with the size of the hello. - * - * @param[out] hello_size size of hello. - * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. - * - */ -int -GNUNET_TRANSPORT_get_trait_hello_size (const struct - GNUNET_TESTING_Command - *cmd, - size_t **hello_size) -{ - return cmd->traits (cmd->cls, - (const void **) hello_size, - "hello_size", - (unsigned int) 4); -} - - -/** - * Function to get the trait with the hello. - * - * @param[out] hello The hello for the peer. - * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. - * - */ -int -GNUNET_TRANSPORT_get_trait_hello (const struct - GNUNET_TESTING_Command - *cmd, - char **hello) -{ - return cmd->traits (cmd->cls, - (const void **) hello, - "hello", - (unsigned int) 3); -} - - -/** - * Function to get the trait with the map of connected peers. - * - * @param[out] connected_peers_map The map with connected peers. - * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. - * - */ -int -GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct - GNUNET_TESTING_Command - *cmd, - struct - GNUNET_CONTAINER_MultiShortmap - * - * - connected_peers_map) -{ - return cmd->traits (cmd->cls, - (const void **) connected_peers_map, - "connected_peers_map", - (unsigned int) 2); -} - - -/** - * Function to get the trait with the transport application handle. - * - * @param[out] ah The application handle. - * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. - */ -int -GNUNET_TRANSPORT_get_trait_application_handle (const struct - GNUNET_TESTING_Command *cmd, - struct - GNUNET_TRANSPORT_ApplicationHandle - **ah) -{ - return cmd->traits (cmd->cls, - (const void **) ah, - "application_handle", - (unsigned int) 0); -} - - -/** - * Function to get the trait with the peer id. - * - * @param[out] id The peer id. - * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. - */ -int -GNUNET_TRANSPORT_get_trait_peer_id (const struct - GNUNET_TESTING_Command *cmd, - struct GNUNET_PeerIdentity **id) -{ - return cmd->traits (cmd->cls, - (const void **) id, - "peer_id", - (unsigned int) 1); -} - - /** * Create command. * diff --git a/src/transport/transport_api_cmd_stop_peer.c b/src/transport/transport_api_cmd_stop_peer.c index 97408b083..4ca730add 100644 --- a/src/transport/transport_api_cmd_stop_peer.c +++ b/src/transport/transport_api_cmd_stop_peer.c @@ -58,7 +58,7 @@ stop_peer_run (void *cls, struct GNUNET_TESTING_Interpreter *is) { struct StopPeerState *stop_ps = cls; - struct StartPeerState *sps; + const struct StartPeerState *sps; const struct GNUNET_TESTING_Command *start_cmd; start_cmd = GNUNET_TESTING_interpreter_lookup_command (is, @@ -69,24 +69,20 @@ stop_peer_run (void *cls, if (NULL != sps->pic) { GNUNET_PEERSTORE_iterate_cancel (sps->pic); - sps->pic = NULL; } if (NULL != sps->th) { GNUNET_TRANSPORT_core_disconnect (sps->th); - sps->th = NULL; } if (NULL != sps->ah) { GNUNET_TRANSPORT_application_done (sps->ah); - sps->ah = NULL; } if (NULL != sps->ph) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from PEERSTORE service\n"); GNUNET_PEERSTORE_disconnect (sps->ph, GNUNET_NO); - sps->ph = NULL; } if (NULL != sps->peer) { @@ -99,12 +95,9 @@ stop_peer_run (void *cls, GNUNET_i2s (&sps->id)); } GNUNET_TESTING_peer_destroy (sps->peer); - sps->peer = NULL; } if (NULL != sps->rh_task) GNUNET_SCHEDULER_cancel (sps->rh_task); - sps->rh_task = NULL; - } -- cgit v1.2.3