summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-10-25 14:49:05 +0200
committert3sserakt <t3ss@posteo.de>2021-10-25 14:49:05 +0200
commit1609d627e509043a946f611d7589105cfae2364d (patch)
treed6022bea17730f96c7d87b0a1c8f602717edb25d /src
parent513f23e74650db9408267e82ef8bcb8f770d1015 (diff)
changes to reflect the changes in testing_api_loop.c
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_testing_ng_lib.h34
-rw-r--r--src/testing/testing_api_cmd_local_test_finished.c1
-rw-r--r--src/testing/testing_api_cmd_local_test_prepared.c93
-rw-r--r--src/testing/testing_api_cmd_netjail_start_testsystem.c185
-rw-r--r--src/testing/testing_api_cmd_netjail_stop_testsystem.c2
-rw-r--r--src/testing/testing_api_cmd_send_peer_ready.c1
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send.c10
-rw-r--r--src/transport/test_transport_plugin_cmd_udp_backchannel.c42
-rw-r--r--src/transport/transport-testing-cmds.h25
-rw-r--r--src/transport/transport_api_cmd_backchannel_check.c51
-rw-r--r--src/transport/transport_api_cmd_connecting_peers.c258
11 files changed, 297 insertions, 405 deletions
diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h
index 96e9af252..45e58299e 100644
--- a/src/include/gnunet_testing_ng_lib.h
+++ b/src/include/gnunet_testing_ng_lib.h
@@ -1046,6 +1046,23 @@ GNUNET_TESTING_make_trait_relative_time (
// FIXME: move these commands into a separate libgnunetestingnetjail lib or so!
+/**
+ * Struct to hold information for callbacks.
+ *
+ */
+struct LocalPreparedState
+{
+ /**
+ * Context for our asynchronous completion.
+ */
+ struct GNUNET_TESTING_AsyncContext ac;
+
+ /**
+ * Callback to write messages to the master loop.
+ *
+ */
+ TESTING_CMD_HELPER_write_cb write_message;
+};
/**
* Create command.
@@ -1223,7 +1240,18 @@ GNUNET_TESTING_cmd_local_test_finished (
struct GNUNET_TESTING_Command
GNUNET_TESTING_cmd_local_test_prepared (const char *label,
TESTING_CMD_HELPER_write_cb
- write_message,
- unsigned int *
- all_local_tests_prepared);
+ 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);
+
#endif
diff --git a/src/testing/testing_api_cmd_local_test_finished.c b/src/testing/testing_api_cmd_local_test_finished.c
index 0e7e214dc..8f8a8230c 100644
--- a/src/testing/testing_api_cmd_local_test_finished.c
+++ b/src/testing/testing_api_cmd_local_test_finished.c
@@ -64,7 +64,6 @@ local_test_finished_cleanup (void *cls)
{
struct LocalFinishedState *lfs = cls;
- GNUNET_free (lfs->reply);
GNUNET_free (lfs);
}
diff --git a/src/testing/testing_api_cmd_local_test_prepared.c b/src/testing/testing_api_cmd_local_test_prepared.c
index 4e915c7c0..2554d6fec 100644
--- a/src/testing/testing_api_cmd_local_test_prepared.c
+++ b/src/testing/testing_api_cmd_local_test_prepared.c
@@ -35,41 +35,47 @@
/**
- * Struct to hold information for callbacks.
+ * This function prepares an array with traits.
*
*/
-struct LocalPreparedState
+enum GNUNET_GenericReturnValue
+local_test_prepared_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
{
- /**
- * Callback to write messages to the master loop.
- *
- */
- TESTING_CMD_HELPER_write_cb write_message;
-
- /**
- * The message send back to the master loop.
- *
- */
- struct GNUNET_CMDS_LOCAL_TEST_PREPARED *reply;
-
- /**
- * Flag indicating if all local tests finished.
- */
- unsigned int *all_local_tests_prepared;
-};
+ struct LocalPreparedState *lfs = cls;
+ struct GNUNET_TESTING_Trait traits[] = {
+ {
+ .index = 0,
+ .trait_name = "state",
+ .ptr = (const void *) lfs,
+ },
+ GNUNET_TESTING_trait_end ()
+ };
+ return GNUNET_TESTING_get_trait (traits,
+ ret,
+ trait,
+ index);
+}
/**
- * Trait function of this cmd does nothing.
+ * Function to get the trait with the struct LocalPreparedState.
+ *
+ * @param[out] lfs struct LocalPreparedState.
+ * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
*
*/
-static int
-local_test_prepared_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
+enum GNUNET_GenericReturnValue
+GNUNET_TESTING_get_trait_local_prepared_state (
+ const struct GNUNET_TESTING_Command *cmd,
+ struct LocalPreparedState **lfs)
{
- return GNUNET_OK;
+ return cmd->traits (cmd->cls,
+ (const void **) lfs,
+ "state",
+ (unsigned int) 0);
}
@@ -78,12 +84,10 @@ local_test_prepared_traits (void *cls,
*
*/
static void
-local_test_prepared_cleanup (void *cls,
- const struct GNUNET_TESTING_Command *cmd)
+local_test_prepared_cleanup (void *cls)
{
struct LocalPreparedState *lfs = cls;
- GNUNET_free (lfs->reply);
GNUNET_free (lfs);
}
@@ -94,7 +98,6 @@ local_test_prepared_cleanup (void *cls,
*/
static void
local_test_prepared_run (void *cls,
- const struct GNUNET_TESTING_Command *cmd,
struct GNUNET_TESTING_Interpreter *is)
{
struct LocalPreparedState *lfs = cls;
@@ -107,34 +110,11 @@ local_test_prepared_run (void *cls,
reply->header.type = htons (
GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TEST_PREPARED);
reply->header.size = htons ((uint16_t) msg_length);
- lfs->reply = reply;
lfs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length);
}
/**
- * This finish function will stop the local loop without shutting down the scheduler, because we do not call the continuation, which is the interpreter_next method.
- *
- */
-static int
-local_test_prepared_finish (void *cls,
- GNUNET_SCHEDULER_TaskCallback cont,
- void *cont_cls)
-{
- struct LocalPreparedState *lfs = cls;
- unsigned int *ret = lfs->all_local_tests_prepared;
-
- if (GNUNET_YES == *ret)
- {
- cont (cont_cls);
- }
-
- return *ret;
-
-}
-
-
-/**
* Create command.
*
* @param label name for command.
@@ -145,21 +125,18 @@ local_test_prepared_finish (void *cls,
struct GNUNET_TESTING_Command
GNUNET_TESTING_cmd_local_test_prepared (const char *label,
TESTING_CMD_HELPER_write_cb
- write_message,
- unsigned int *
- all_local_tests_prepared)
+ write_message)
{
struct LocalPreparedState *lfs;
lfs = GNUNET_new (struct LocalPreparedState);
lfs->write_message = write_message;
- lfs->all_local_tests_prepared = all_local_tests_prepared;
struct GNUNET_TESTING_Command cmd = {
.cls = lfs,
.label = label,
.run = &local_test_prepared_run,
- .finish = &local_test_prepared_finish,
+ .ac = &lfs->ac,
.cleanup = &local_test_prepared_cleanup,
.traits = &local_test_prepared_traits
};
diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem.c b/src/testing/testing_api_cmd_netjail_start_testsystem.c
index a1d71c436..9b567a01f 100644
--- a/src/testing/testing_api_cmd_netjail_start_testsystem.c
+++ b/src/testing/testing_api_cmd_netjail_start_testsystem.c
@@ -30,6 +30,11 @@
#define NETJAIL_EXEC_SCRIPT "./../testing/netjail_exec.sh"
/**
+ * Generic logging shortcut
+ */
+#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
+
+/**
* Struct to store messages send/received by the helper into a DLL
*
*/
@@ -121,13 +126,13 @@ struct NetJailState
/**
* The send handle for the helper
*/
- struct GNUNET_HELPER_SendHandle **shandle;
+ // struct GNUNET_HELPER_SendHandle **shandle;
/**
* Size of the array NetJailState#shandle.
*
*/
- unsigned int n_shandle;
+ // unsigned int n_shandle;
/**
* The messages send to the helper.
@@ -156,7 +161,13 @@ struct NetJailState
* Number of local tests finished.
*
*/
- unsigned int number_of_local_test_finished;
+ unsigned int number_of_local_tests_finished;
+
+ /**
+ * Number of local tests prepared to finish.
+ *
+ */
+ unsigned int number_of_local_tests_prepared;
/**
* Name of the test case plugin the helper will load.
@@ -194,6 +205,17 @@ struct TestingSystemCount
struct TestingSystemCount *prev;
/**
+ * The send handle for the helper
+ */
+ struct GNUNET_HELPER_SendHandle *shandle;// **shandle;
+
+ /**
+ * Size of the array NetJailState#shandle.
+ *
+ */
+ // unsigned int n_shandle;
+
+ /**
* The number of the test environment.
*
*/
@@ -306,47 +328,85 @@ clear_msg (void *cls, int result)
struct TestingSystemCount *tbc = cls;
struct NetJailState *ns = tbc->ns;
- GNUNET_assert (NULL != ns->shandle[tbc->count - 1]);
- ns->shandle[tbc->count - 1] = NULL;
+ GNUNET_assert (NULL != tbc->shandle);// [tbc->count - 1]);
+ tbc->shandle = NULL;// [tbc->count - 1] = NULL;
GNUNET_free (ns->msg[tbc->count - 1]);
ns->msg[tbc->count - 1] = NULL;
}
static void
-send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns)
+send_message_to_locals (
+ unsigned int i,
+ unsigned int j,
+ struct NetJailState *ns,
+ struct GNUNET_MessageHeader *header
+ )
{
- unsigned int total_number = ns->local_m * ns->global_n + ns->known;
- struct GNUNET_CMDS_ALL_PEERS_STARTED *reply;
- size_t msg_length;
+ // unsigned int total_number = ns->local_m * ns->global_n + ns->known;
struct GNUNET_HELPER_Handle *helper;
struct TestingSystemCount *tbc;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "send message of type %u to locals\n",
+ header->type);
tbc = GNUNET_new (struct TestingSystemCount);
tbc->ns = ns;
// TODO This needs to be more generic. As we send more messages back and forth, we can not grow the arrays again and again, because this is to error prone.
if (0 == i)
- tbc->count = j + total_number;
+ tbc->count = j; // + total_number;
else
- tbc->count = (i - 1) * ns->local_m + j + total_number + ns->known;
+ tbc->count = (i - 1) * ns->local_m + j + ns->known; // + total_number ;
- helper = ns->helper[tbc->count - 1 - total_number];
- msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED);
- reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED);
- reply->header.type = htons (
- GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED);
- reply->header.size = htons ((uint16_t) msg_length);
+ helper = ns->helper[tbc->count - 1];// - total_number];
- GNUNET_array_append (ns->msg, ns->n_msg, &reply->header);
+ GNUNET_array_append (ns->msg, ns->n_msg, header);
struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send (
helper,
- &reply->header,
+ header,
GNUNET_NO,
&clear_msg,
tbc);
- GNUNET_array_append (ns->shandle, ns->n_shandle, sh);
+ tbc->shandle = sh;
+ // GNUNET_array_append (tbc->shandle, tbc->n_shandle, sh);
+}
+
+
+static void
+send_all_local_tests_prepared (unsigned int i, unsigned int j, struct
+ NetJailState *ns)
+{
+ struct GNUNET_CMDS_ALL_LOCAL_TESTS_PREPARED *reply;
+ size_t msg_length;
+
+
+ msg_length = sizeof(struct GNUNET_CMDS_ALL_LOCAL_TESTS_PREPARED);
+ reply = GNUNET_new (struct GNUNET_CMDS_ALL_LOCAL_TESTS_PREPARED);
+ reply->header.type = htons (
+ GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_LOCAL_TESTS_PREPARED);
+ reply->header.size = htons ((uint16_t) msg_length);
+
+ send_message_to_locals (i, j, ns, &reply->header);
+}
+
+
+static void
+send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns)
+{
+
+ struct GNUNET_CMDS_ALL_PEERS_STARTED *reply;
+ size_t msg_length;
+
+
+ msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED);
+ reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED);
+ reply->header.type = htons (
+ GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED);
+ reply->header.size = htons ((uint16_t) msg_length);
+
+ send_message_to_locals (i, j, ns, &reply->header);
}
@@ -365,11 +425,22 @@ send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns)
static int
helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
{
- struct TestingSystemCount *tbc = cls;
- struct NetJailState *ns = tbc->ns;
+ // struct TestingSystemCount *tbc = cls;
+ struct NetJailState *ns = cls;// tbc->ns;
struct HelperMessage *hp_msg;
unsigned int total_number = ns->local_m * ns->global_n + ns->known;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "total %u sysstarted %u peersstarted %u prep %u finished %u %u %u %u\n",
+ total_number,
+ ns->number_of_testsystems_started,
+ ns->number_of_peers_started,
+ ns->number_of_local_tests_prepared,
+ ns->number_of_local_tests_finished,
+ ns->local_m,
+ ns->global_n,
+ ns->known);
+
if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type))
{
ns->number_of_testsystems_started++;
@@ -395,11 +466,31 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
ns->number_of_peers_started = 0;
}
}
+ else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TEST_PREPARED == ntohs (
+ message->type))
+ {
+ ns->number_of_local_tests_prepared++;
+ if (ns->number_of_local_tests_prepared == total_number)
+ {
+ for (int i = 1; i <= ns->known; i++)
+ {
+ send_all_local_tests_prepared (0,i, ns);
+ }
+
+ for (int i = 1; i <= ns->global_n; i++)
+ {
+ for (int j = 1; j <= ns->local_m; j++)
+ {
+ send_all_local_tests_prepared (i,j, ns);
+ }
+ }
+ }
+ }
else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED == ntohs (
message->type))
{
- ns->number_of_local_test_finished++;
- if (ns->number_of_local_test_finished == total_number)
+ ns->number_of_local_tests_finished++;
+ if (ns->number_of_local_tests_finished == total_number)
{
GNUNET_TESTING_async_finish (&ns->ac);
}
@@ -477,8 +568,13 @@ start_helper (struct NetJailState *ns, struct
struct GNUNET_HELPER_Handle *helper;
struct GNUNET_CMDS_HelperInit *msg;
struct TestingSystemCount *tbc;
- char *m_char, *n_char, *global_n_char, *local_m_char, *known_char, *node_id,
- *plugin;
+ char *m_char;
+ char *n_char;
+ char *global_n_char;
+ char *local_m_char;
+ char *known_char;
+ char *node_id;
+ char *plugin;
pid_t pid;
unsigned int script_num;
struct GNUNET_ShortHashCode *hkey;
@@ -486,6 +582,7 @@ start_helper (struct NetJailState *ns, struct
struct GNUNET_TESTING_NetjailTopology *topology = ns->topology;
struct GNUNET_TESTING_NetjailNode *node;
struct GNUNET_TESTING_NetjailNamespace *namespace;
+ unsigned int *rv = ns->rv;
if (0 == n)
@@ -526,7 +623,8 @@ start_helper (struct NetJailState *ns, struct
else
tbc->count = (n - 1) * ns->local_m + m + ns->known;
- GNUNET_CONTAINER_DLL_insert (ns->tbcs_head, ns->tbcs_tail,
+ GNUNET_CONTAINER_DLL_insert (ns->tbcs_head,
+ ns->tbcs_tail,
tbc);
@@ -535,23 +633,33 @@ start_helper (struct NetJailState *ns, struct
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"No SUID for %s!\n",
NETJAIL_EXEC_SCRIPT);
- GNUNET_TESTING_interpreter_fail (ns->ac.is);
+ *rv = 1;
}
else if (GNUNET_NO == helper_check)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"%s not found!\n",
NETJAIL_EXEC_SCRIPT);
- GNUNET_TESTING_interpreter_fail (ns->ac.is);
+ *rv = 1;
}
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "sysstarted %u peersstarted %u prep %u finished %u %u %u %u\n",
+ ns->number_of_testsystems_started,
+ ns->number_of_peers_started,
+ ns->number_of_local_tests_prepared,
+ ns->number_of_local_tests_finished,
+ ns->local_m,
+ ns->global_n,
+ ns->known);
+
GNUNET_array_append (ns->helper, ns->n_helper, GNUNET_HELPER_start (
GNUNET_YES,
NETJAIL_EXEC_SCRIPT,
script_argv,
&helper_mst,
&exp_cb,
- tbc));
+ ns));
helper = ns->helper[tbc->count - 1];
@@ -608,19 +716,20 @@ start_helper (struct NetJailState *ns, struct
GNUNET_array_append (ns->msg, ns->n_msg, &msg->header);
- GNUNET_array_append (ns->shandle, ns->n_shandle, GNUNET_HELPER_send (
- helper,
- &msg->header,
- GNUNET_NO,
- &clear_msg,
- tbc));
+ // GNUNET_array_append (tbc->shandle, tbc->n_shandle,
+ tbc->shandle = GNUNET_HELPER_send (
+ helper,
+ &msg->header,
+ GNUNET_NO,
+ &clear_msg,
+ tbc); // );
- if (NULL == ns->shandle[tbc->count - 1])
+ if (NULL == tbc->shandle)// [tbc->count - 1])
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Send handle is NULL!\n");
GNUNET_free (msg);
- GNUNET_TESTING_interpreter_fail (ns->ac.is);
+ *rv = 1;
}
}
diff --git a/src/testing/testing_api_cmd_netjail_stop_testsystem.c b/src/testing/testing_api_cmd_netjail_stop_testsystem.c
index d3754153d..33792f1b0 100644
--- a/src/testing/testing_api_cmd_netjail_stop_testsystem.c
+++ b/src/testing/testing_api_cmd_netjail_stop_testsystem.c
@@ -95,7 +95,7 @@ stop_testing_system_run (void *cls,
struct GNUNET_HELPER_Handle **helper;
const struct GNUNET_TESTING_Command *start_helper_cmd;
- start_helper_cmd = GNUNET_TESTING_interpreter_lookup_command (NULL,
+ start_helper_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
shs->
helper_start_label);
GNUNET_TESTING_get_trait_helper_handles (start_helper_cmd,
diff --git a/src/testing/testing_api_cmd_send_peer_ready.c b/src/testing/testing_api_cmd_send_peer_ready.c
index 8b4c11deb..8eef1d8f1 100644
--- a/src/testing/testing_api_cmd_send_peer_ready.c
+++ b/src/testing/testing_api_cmd_send_peer_ready.c
@@ -72,7 +72,6 @@ send_peer_ready_cleanup (void *cls)
{
struct SendPeerReadyState *sprs = cls;
- GNUNET_free (sprs->reply);
GNUNET_free (sprs);
}
diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c b/src/transport/test_transport_plugin_cmd_simple_send.c
index 8889f9d06..f0b47084b 100644
--- a/src/transport/test_transport_plugin_cmd_simple_send.c
+++ b/src/transport/test_transport_plugin_cmd_simple_send.c
@@ -37,6 +37,7 @@
#define BASE_DIR "testdir"
+#define TOPOLOGY_CONFIG "test_transport_simple_send_topo.conf"
struct TestState
{
@@ -154,8 +155,8 @@ notify_connect (void *cls,
{
struct ConnectPeersState *cps;
- GNUNET_TESTING_get_trait_connect_peer_state (&connect_peers,
- &cps);
+ GNUNET_TRANSPORT_get_trait_connect_peer_state (&connect_peers,
+ &cps);
void *ret = NULL;
cps->notify_connect (cps,
@@ -203,7 +204,7 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
"start-peer",
"system-create",
num,
- NULL);
+ topology);
@@ -257,7 +258,8 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
"start-peer"),
GNUNET_TESTING_cmd_system_destroy ("system-destroy",
- "system-create")
+ "system-create"),
+ GNUNET_TESTING_cmd_end ()
};
GNUNET_TESTING_run (commands,
diff --git a/src/transport/test_transport_plugin_cmd_udp_backchannel.c b/src/transport/test_transport_plugin_cmd_udp_backchannel.c
index b0ca37447..ee6dc0274 100644
--- a/src/transport/test_transport_plugin_cmd_udp_backchannel.c
+++ b/src/transport/test_transport_plugin_cmd_udp_backchannel.c
@@ -62,9 +62,8 @@ struct TestState
static struct GNUNET_TESTING_Command block_send;
-static struct GNUNET_TESTING_Command block_receive;
-
static struct GNUNET_TESTING_Command connect_peers;
+static struct GNUNET_TESTING_Command local_prepared;
/**
@@ -89,14 +88,14 @@ static void
handle_test (void *cls,
const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
{
- struct GNUNET_TESTING_AsyncContext *ac;
+ // struct GNUNET_TESTING_AsyncContext *ac;
- GNUNET_TESTING_get_trait_async_context (&block_receive,
+ /*GNUNET_TESTING_get_trait_async_context (&block_receive,
&ac);
if ((NULL == ac) || (NULL == ac->cont))
GNUNET_TESTING_async_fail (ac);
else
- GNUNET_TESTING_async_finish (ac);
+ GNUNET_TESTING_async_finish (ac);*/
}
@@ -136,8 +135,11 @@ handle_result (void *cls,
rv);
reply = GNUNET_TESTING_send_local_test_finished_msg (rv);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "message prepared\n");
ts->write_message (reply,
ntohs (reply->size));
+
GNUNET_free (ts->testdir);
GNUNET_free (ts->cfgname);
GNUNET_free (ts);
@@ -155,8 +157,8 @@ notify_connect (void *cls,
{
struct ConnectPeersState *cps;
- GNUNET_TESTING_get_trait_connect_peer_state (&connect_peers,
- &cps);
+ GNUNET_TRANSPORT_get_trait_connect_peer_state (&connect_peers,
+ &cps);
void *ret = NULL;
cps->notify_connect (cps,
@@ -171,7 +173,14 @@ notify_connect (void *cls,
static void
all_local_tests_prepared ()
{
- are_all_local_tests_prepared = GNUNET_YES;
+ struct LocalPreparedState *lfs;
+ GNUNET_TESTING_get_trait_local_prepared_state (&local_prepared,
+ &lfs);
+
+ if ((NULL == &lfs->ac) || (NULL == lfs->ac.cont))
+ GNUNET_TESTING_async_fail (&lfs->ac);
+ else
+ GNUNET_TESTING_async_finish (&lfs->ac);
}
/**
@@ -212,13 +221,14 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
block_send = GNUNET_TESTING_cmd_block_until_external_trigger ("block");
- block_receive = GNUNET_TESTING_cmd_block_until_external_trigger (
- "block-receive");
connect_peers = GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers",
"start-peer",
"system-create",
num,
- NULL);
+ topology);
+ local_prepared = GNUNET_TESTING_cmd_local_test_prepared (
+ "local-test-prepared",
+ write_message);
GNUNET_asprintf (&ts->cfgname,
"test_transport_api2_tcp_node1.conf");
@@ -266,16 +276,16 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
m_int,
n_int,
topology),
- GNUNET_TESTING_cmd_local_test_prepared ("local-test-prepared",
- write_message,
- &are_all_local_tests_prepared),
- block_receive,
+ local_prepared,
GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
"start-peer"),
GNUNET_TESTING_cmd_system_destroy ("system-destroy",
- "system-create")
+ "system-create"),
+ GNUNET_TESTING_cmd_end ()
};
+ ts->write_message = write_message;
+
GNUNET_TESTING_run (commands,
GNUNET_TIME_UNIT_FOREVER_REL,
&handle_result,
diff --git a/src/transport/transport-testing-cmds.h b/src/transport/transport-testing-cmds.h
index f6e34df62..d6bb46f7d 100644
--- a/src/transport/transport-testing-cmds.h
+++ b/src/transport/transport-testing-cmds.h
@@ -182,7 +182,7 @@ struct StartPeerState
*
*/
int
-GNUNET_TESTING_get_trait_connect_peer_state (
+GNUNET_TRANSPORT_get_trait_connect_peer_state (
const struct GNUNET_TESTING_Command *cmd,
struct ConnectPeersState **cps);
@@ -234,6 +234,29 @@ GNUNET_TRANSPORT_cmd_send_simple (const char *label,
uint32_t num);
+/**
+ * Create command.
+ *
+ * @param label name for command.
+ * @param start_peer_label Label of the cmd to start a peer.
+ * @param create_label Label of the cmd to create the testing system.
+ * @param num Number globally identifying the node.
+ * @param node_n The number of the node in a network namespace.
+ * @param namespace_n The number of the network namespace.
+ * @param The topology for the test setup.
+ * @return command.
+ */
+struct GNUNET_TESTING_Command
+GNUNET_TRANSPORT_cmd_backchannel_check (const char *label,
+ const char *start_peer_label,
+ const char *create_label,
+ uint32_t num,
+ unsigned int node_n,
+ unsigned int namespace_n,
+ struct GNUNET_TESTING_NetjailTopology *
+ topology);
+
+
diff --git a/src/transport/transport_api_cmd_backchannel_check.c b/src/transport/transport_api_cmd_backchannel_check.c
index 5cc13dbfa..03b231347 100644
--- a/src/transport/transport_api_cmd_backchannel_check.c
+++ b/src/transport/transport_api_cmd_backchannel_check.c
@@ -51,6 +51,11 @@
struct CheckState
{
/**
+ * Context for our asynchronous completion.
+ */
+ struct GNUNET_TESTING_AsyncContext ac;
+
+ /**
* The number of the node in a network namespace.
*/
unsigned int node_n;
@@ -119,11 +124,6 @@ struct CheckState
* Stream to read log file lines.
*/
FILE *stream;
-
- /**
- * Did we get all bachchannel messages.
- */
- enum GNUNET_GenericReturnValue finished;
};
/**
@@ -195,7 +195,7 @@ read_from_log (void *cls)
strcmp (
"Delivering backchannel message from 4TTC to F7B5 of type 1460 to udp",
cs->search_string[i]));
- cs->finished = GNUNET_YES;
+ GNUNET_TESTING_async_finish (&cs->ac);
fclose (cs->stream);
return;
}
@@ -396,7 +396,6 @@ add_search_string (struct CheckState *cs, const struct
*/
static void
backchannel_check_run (void *cls,
- const struct GNUNET_TESTING_Command *cmd,
struct GNUNET_TESTING_Interpreter *is)
{
struct CheckState *cs = cls;
@@ -418,12 +417,13 @@ backchannel_check_run (void *cls,
const struct GNUNET_TESTING_NetjailNode *node;
const struct GNUNET_TESTING_NetjailNamespace *namespace;
- peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (
- cs->start_peer_label);
- GNUNET_TRANSPORT_get_trait_application_handle_v2 (peer1_cmd,
- &ah);
+ peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
+ cs->start_peer_label);
+ GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd,
+ &ah);
- system_cmd = GNUNET_TESTING_interpreter_lookup_command (cs->create_label);
+ system_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
+ cs->create_label);
GNUNET_TESTING_get_trait_test_system (system_cmd,
&tl_system);
@@ -524,28 +524,8 @@ backchannel_check_run (void *cls,
cs);
}
else
- cs->finished = GNUNET_YES;
-
-}
-
+ GNUNET_TESTING_async_finish (&cs->ac);
-/**
- * The finish function of this cmd will check if the peers we are trying to
- * connect to are in the connected peers map of the start peer cmd for this peer.
- *
- */
-static int
-backchannel_check_finish (void *cls,
- GNUNET_SCHEDULER_TaskCallback cont,
- void *cont_cls)
-{
- struct CheckState *cs = cls;
-
- if (cs->finished)
- {
- cont (cont_cls);
- }
- return cs->finished;
}
@@ -568,8 +548,7 @@ backchannel_check_traits (void *cls,
*
*/
static void
-backchannel_check_cleanup (void *cls,
- const struct GNUNET_TESTING_Command *cmd)
+backchannel_check_cleanup (void *cls)
{
struct ConnectPeersState *cs = cls;
@@ -613,7 +592,7 @@ GNUNET_TRANSPORT_cmd_backchannel_check (const char *label,
.cls = cs,
.label = label,
.run = &backchannel_check_run,
- .finish = &backchannel_check_finish,
+ .ac = &cs->ac,
.cleanup = &backchannel_check_cleanup,
.traits = &backchannel_check_traits
};
diff --git a/src/transport/transport_api_cmd_connecting_peers.c b/src/transport/transport_api_cmd_connecting_peers.c
index 2e51363f6..017d1bca3 100644
--- a/src/transport/transport_api_cmd_connecting_peers.c
+++ b/src/transport/transport_api_cmd_connecting_peers.c
@@ -36,242 +36,6 @@
*/
#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
-#define CONNECT_ADDRESS_TEMPLATE_TCP "tcp-192.168.15.%u:60002"
-
-#define CONNECT_ADDRESS_TEMPLATE_UDP "udp-192.168.15.%u:60002"
-
-#define ROUTER_CONNECT_ADDRESS_TEMPLATE_TCP "tcp-92.68.150.%u:60002"
-
-#define ROUTER_CONNECT_ADDRESS_TEMPLATE_UDP "udp-92.68.150.%u:60002"
-
-#define GLOBAL_CONNECT_ADDRESS_TEMPLATE_TCP "tcp-92.68.151.%u:60002"
-
-#define GLOBAL_CONNECT_ADDRESS_TEMPLATE_UDP "udp-92.68.151.%u:60002"
-
-#define PREFIX_TCP "tcp"
-
-#define PREFIX_UDP "udp"
-
-
-
-
-static struct GNUNET_PeerIdentity *
-get_pub_key (unsigned int num, struct GNUNET_TESTING_System *tl_system)
-{
- struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity);
- struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct
- GNUNET_CRYPTO_EddsaPublicKey);
- struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct
- GNUNET_CRYPTO_EddsaPrivateKey);
-
- priv_key = GNUNET_TESTING_hostkey_get (tl_system,
- num,
- peer);
-
- GNUNET_CRYPTO_eddsa_key_get_public (priv_key,
- pub_key);
- peer->public_key = *pub_key;
- return peer;
-}
-
-
-static int
-log_nodes (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
-{
- struct GNUNET_TESTING_NetjailNode *node = value;
- struct GNUNET_TESTING_NodeConnection *pos_connection;
- struct GNUNET_TESTING_ADDRESS_PREFIX *pos_prefix;
-
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "plugin: %s space: %u node: %u global: %u\n",
- node->plugin,
- node->namespace_n,
- node->node_n,
- node->is_global);
-
- for (pos_connection = node->node_connections_head; NULL != pos_connection;
- pos_connection = pos_connection->next)
- {
-
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "namespace_n: %u node_n: %u node_type: %u\n",
- pos_connection->namespace_n,
- pos_connection->node_n,
- pos_connection->node_type);
-
- for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
- pos_prefix =
- pos_prefix->next)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "prefix: %s\n",
- pos_prefix->address_prefix);
- }
- }
- return GNUNET_YES;
-}
-
-
-static int
-log_namespaces (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
-{
- struct GNUNET_TESTING_NetjailNamespace *namespace = value;
- struct GNUNET_TESTING_NetjailRouter *router = namespace->router;
-
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "router_tcp: %u router_udp: %u spaces: %u\n",
- router->tcp_port,
- router->udp_port,
- namespace->namespace_n);
- GNUNET_CONTAINER_multishortmap_iterate (namespace->nodes, &log_nodes, NULL);
- return GNUNET_YES;
-}
-
-
-static int
-log_topo (struct GNUNET_TESTING_NetjailTopology *topology)
-{
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "plugin: %s spaces: %u nodes: %u known: %u\n",
- topology->plugin,
- topology->namespaces_n,
- topology->nodes_m,
- topology->nodes_x);
-
- GNUNET_CONTAINER_multishortmap_iterate (topology->map_namespaces,
- log_namespaces, NULL);
- GNUNET_CONTAINER_multishortmap_iterate (topology->map_globals, &log_nodes,
- NULL);
- return GNUNET_YES;
-}
-
-
-static struct GNUNET_TESTING_NodeConnection *
-get_connections (unsigned int num, struct
- GNUNET_TESTING_NetjailTopology *topology)
-{
- struct GNUNET_TESTING_NetjailNode *node;
- struct GNUNET_ShortHashCode *hkey;
- struct GNUNET_HashCode hc;
- struct GNUNET_TESTING_NetjailNamespace *namespace;
- unsigned int namespace_n, node_m;
-
- log_topo (topology);
-
- hkey = GNUNET_new (struct GNUNET_ShortHashCode);
- if (topology->nodes_x >= num)
- {
-
- GNUNET_CRYPTO_hash (&num, sizeof(num), &hc);
- memcpy (hkey,
- &hc,
- sizeof (*hkey));
- node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals,
- hkey);
- }
- else
- {
- namespace_n = (unsigned int) floor ((num - topology->nodes_x)
- / topology->nodes_m);
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "num: %u nodes_x: %u nodes_m: %u namespace_n: %u\n",
- num,
- topology->nodes_x,
- topology->nodes_m,
- namespace_n);
- hkey = GNUNET_new (struct GNUNET_ShortHashCode);
- GNUNET_CRYPTO_hash (&namespace_n, sizeof(namespace_n), &hc);
- memcpy (hkey,
- &hc,
- sizeof (*hkey));
- namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces,
- hkey);
- node_m = num - topology->nodes_x - topology->nodes_m * (namespace_n - 1);
- hkey = GNUNET_new (struct GNUNET_ShortHashCode);
- GNUNET_CRYPTO_hash (&node_m, sizeof(node_m), &hc);
- memcpy (hkey,
- &hc,
- sizeof (*hkey));
- node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
- hkey);
- }
-
-
- return node->node_connections_head;
-}
-
-
-static unsigned int
-calculate_num (struct GNUNET_TESTING_NodeConnection *node_connection,
- struct GNUNET_TESTING_NetjailTopology *topology)
-{
- unsigned int n, m, num;
-
- n = node_connection->namespace_n;
- m = node_connection->node_n;
-
- if (0 == n)
- num = m;
- else
- num = (n - 1) * topology->nodes_m + m + topology->nodes_x;
-
- return num;
-}
-
-
-static char *
-get_address (struct GNUNET_TESTING_NodeConnection *connection,
- char *prefix)
-{
- struct GNUNET_TESTING_NetjailNode *node;
- char *addr;
-
- node = connection->node;
- if (connection->namespace_n == node->namespace_n)
- {
- if (0 == strcmp (PREFIX_TCP, prefix))
- {
-
- GNUNET_asprintf (&addr,
- CONNECT_ADDRESS_TEMPLATE_TCP,
- connection->node_n);
- }
- else if (0 == strcmp (PREFIX_UDP, prefix))
- {
- GNUNET_asprintf (&addr,
- CONNECT_ADDRESS_TEMPLATE_UDP,
- connection->node_n);
- }
- else
- {
- GNUNET_break (0);
- }
- }
- else
- {
- if (0 == strcmp (PREFIX_TCP, prefix))
- {
-
- GNUNET_asprintf (&addr,
- ROUTER_CONNECT_ADDRESS_TEMPLATE_TCP,
- connection->namespace_n);
- }
- else if (0 == strcmp (PREFIX_UDP, prefix))
- {
- GNUNET_asprintf (&addr,
- ROUTER_CONNECT_ADDRESS_TEMPLATE_UDP,
- connection->namespace_n);
- }
- else
- {
- GNUNET_break (0);
- }
- }
-
- return addr;
-}
-
-
/**
* The run method of this cmd will connect to peers.
*
@@ -292,7 +56,7 @@ connect_peers_run (void *cls,
enum GNUNET_NetworkType nt = 0;
uint32_t num;
struct GNUNET_TESTING_NodeConnection *pos_connection;
- struct GNUNET_TESTING_ADDRESS_PREFIX *pos_prefix;
+ struct GNUNET_TESTING_AddressPrefix *pos_prefix;
unsigned int con_num = 0;
cps->is = is;
@@ -308,13 +72,14 @@ connect_peers_run (void *cls,
cps->tl_system = tl_system;
- cps->node_connections_head = get_connections (cps->num, cps->topology);
+ cps->node_connections_head = GNUNET_TESTING_get_connections (cps->num,
+ cps->topology);
for (pos_connection = cps->node_connections_head; NULL != pos_connection;
pos_connection = pos_connection->next)
{
con_num++;
- num = calculate_num (pos_connection, cps->topology);
+ num = GNUNET_TESTING_calculate_num (pos_connection, cps->topology);
for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
pos_prefix =
pos_prefix->next)
@@ -324,9 +89,10 @@ connect_peers_run (void *cls,
"prefix: %s\n",
pos_prefix->address_prefix);
- addr = get_address (pos_connection, pos_prefix->address_prefix);
+ addr = GNUNET_TESTING_get_address (pos_connection,
+ pos_prefix->address_prefix);
- peer = get_pub_key (num, tl_system);
+ peer = GNUNET_TESTING_get_pub_key (num, tl_system);
LOG (GNUNET_ERROR_TYPE_ERROR,
"num: %u pub_key %s addr: %s\n",
@@ -365,8 +131,8 @@ notify_connect (void *cls,
for (pos_connection = cps->node_connections_head; NULL != pos_connection;
pos_connection = pos_connection->next)
{
- num = calculate_num (pos_connection, cps->topology);
- peer_connection = get_pub_key (num, cps->tl_system);
+ num = GNUNET_TESTING_calculate_num (pos_connection, cps->topology);
+ peer_connection = GNUNET_TESTING_get_pub_key (num, cps->tl_system);
if (0 == GNUNET_memcmp (peer,
peer_connection))
con_num++;
@@ -399,7 +165,7 @@ connect_peers_cleanup (void *cls)
* This function prepares an array with traits.
*
*/
-static int
+enum GNUNET_GenericReturnValue
connect_peers_traits (void *cls,
const void **ret,
const char *trait,
@@ -428,8 +194,8 @@ connect_peers_traits (void *cls,
* @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
*
*/
-int
-GNUNET_TESTING_get_trait_connect_peer_state (
+enum GNUNET_GenericReturnValue
+GNUNET_TRANSPORT_get_trait_connect_peer_state (
const struct GNUNET_TESTING_Command *cmd,
struct ConnectPeersState **cps)
{