From 7bf37b7ea24929c277cd915de3eac24e728a6a1f Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 22 Sep 2021 11:35:46 +0200 Subject: NSE: return INF, not NaN (fixes #7021) --- src/nse/gnunet-service-nse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c index 8e9cd0c9d..45ebae34c 100644 --- a/src/nse/gnunet-service-nse.c +++ b/src/nse/gnunet-service-nse.c @@ -390,7 +390,7 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em) if (variance >= 0) std_dev = sqrt (variance); else - std_dev = variance; /* must be infinity due to estimate_count == 0 */ + std_dev = 1.0 / 0.0; /* return infinity due to estimate_count == 0 */ current_std_dev = std_dev; current_size_estimate = mean; -- cgit v1.2.3 From 81d9255872ce90c057b01ef2a15a9aa9b27c4fe1 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 22 Sep 2021 11:39:25 +0200 Subject: NSE: return NaN (see #7021) --- src/nse/gnunet-service-nse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c index 45ebae34c..972b3a79d 100644 --- a/src/nse/gnunet-service-nse.c +++ b/src/nse/gnunet-service-nse.c @@ -390,7 +390,7 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em) if (variance >= 0) std_dev = sqrt (variance); else - std_dev = 1.0 / 0.0; /* return infinity due to estimate_count == 0 */ + std_dev = variance; /* return NaN (due to estimate_count == 0 causing 0.0/0.0) */ current_std_dev = std_dev; current_size_estimate = mean; -- cgit v1.2.3 From b2cf59bdd77a76cdbeade6e948ca39e1085def35 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 22 Sep 2021 22:41:52 +0200 Subject: -finish first draft implementation of dhtu over GNUnet (old, not TNG) --- src/dhtu/Makefile.am | 3 + src/dhtu/plugin_dhtu_gnunet.c | 215 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 178 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/dhtu/Makefile.am b/src/dhtu/Makefile.am index 67810e8cc..33c31dd6c 100644 --- a/src/dhtu/Makefile.am +++ b/src/dhtu/Makefile.am @@ -30,6 +30,9 @@ libgnunet_plugin_dhtu_gnunet_la_SOURCES = \ libgnunet_plugin_dhtu_gnunet_la_LIBADD = \ $(top_builddir)/src/ats/libgnunetats.la \ $(top_builddir)/src/core/libgnunetcore.la \ + $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ + $(top_builddir)/src/transport/libgnunettransport.la \ + $(top_builddir)/src/hello/libgnunethello.la \ $(top_builddir)/src/nse/libgnunetnse.la \ $(top_builddir)/src/util/libgnunetutil.la \ $(XLIBS) \ diff --git a/src/dhtu/plugin_dhtu_gnunet.c b/src/dhtu/plugin_dhtu_gnunet.c index 9cc14361d..ee78858c8 100644 --- a/src/dhtu/plugin_dhtu_gnunet.c +++ b/src/dhtu/plugin_dhtu_gnunet.c @@ -28,6 +28,9 @@ #include "gnunet_dhtu_plugin.h" #include "gnunet_ats_service.h" #include "gnunet_core_service.h" +#include "gnunet_transport_service.h" +#include "gnunet_hello_lib.h" +#include "gnunet_peerinfo_service.h" #include "gnunet_nse_service.h" @@ -66,6 +69,35 @@ struct PublicKey GNUNET_NETWORK_STRUCT_END + +/** + * Handle for a HELLO we're offering the transport. + */ +struct HelloHandle +{ + /** + * Kept in a DLL. + */ + struct HelloHandle *next; + + /** + * Kept in a DLL. + */ + struct HelloHandle *prev; + + /** + * Our plugin. + */ + struct Plugin *plugin; + + /** + * Offer handle. + */ + struct GNUNET_TRANSPORT_OfferHelloHandle *ohh; + +}; + + /** * Opaque handle that the underlay offers for our address to be used when * sending messages to another peer. @@ -77,7 +109,7 @@ struct GNUNET_DHTU_Source * Application context for this source. */ void *app_ctx; - + /** * Hash position of this peer in the DHT. */ @@ -107,7 +139,7 @@ struct GNUNET_DHTU_Target * Our plugin with its environment. */ struct Plugin *plugin; - + /** * CORE MQ to send messages to this peer. */ @@ -117,7 +149,7 @@ struct GNUNET_DHTU_Target * Public key of the peer. */ struct PublicKey pk; - + /** * Hash of the @a pk to identify position of the peer * in the DHT. @@ -146,6 +178,7 @@ struct GNUNET_DHTU_Target }; + /** * Opaque handle expressing a preference of the DHT to * keep a particular target connected. @@ -174,6 +207,18 @@ struct GNUNET_DHTU_PreferenceHandle */ struct Plugin { + + /** + * Our "source" address. Traditional CORE API does not tell us which source + * it is, so they are all identical. + */ + struct GNUNET_DHTU_Source src; + + /** + * My identity. + */ + struct GNUNET_PeerIdentity my_identity; + /** * Callbacks into the DHT. */ @@ -188,18 +233,26 @@ struct Plugin * Handle to ATS service. */ struct GNUNET_ATS_ConnectivityHandle *ats; - - /** - * Our "source" address. Traditional CORE API does not tell us which source - * it is, so they are all identical. - */ - struct GNUNET_DHTU_Source src; - + /** * Handle to the NSE service. */ struct GNUNET_NSE_Handle *nse; - + + /** + * Watching for our address to change. + */ + struct GNUNET_PEERINFO_NotifyContext *nc; + + /** + * Hellos we are offering to transport. + */ + struct HelloHandle *hh_head; + + /** + * Hellos we are offering to transport. + */ + struct HelloHandle *hh_tail; }; @@ -272,6 +325,27 @@ ip_verify (void *cls, } +/** + * Function called once a hello offer is completed. + * + * @param cls a `struct HelloHandle` + */ +static void +hello_offered_cb (void *cls) +{ + struct HelloHandle *hh = cls; + struct Plugin *plugin = hh->plugin; + + GNUNET_CONTAINER_DLL_remove (plugin->hh_head, + plugin->hh_tail, + hh); + GNUNET_free (hh); +} + + +#include "../peerinfo-tool/gnunet-peerinfo_plugins.c" + + /** * Request creation of a session with a peer at the given @a address. * @@ -283,10 +357,30 @@ ip_try_connect (void *cls, const char *address) { struct Plugin *plugin = cls; + struct GNUNET_HELLO_Message *hello = NULL; + struct HelloHandle *hh; + struct GNUNET_CRYPTO_EddsaPublicKey pubkey; + + if (GNUNET_OK != + GNUNET_HELLO_parse_uri (address, + &pubkey, + &hello, + &GPI_plugins_find)) + { + GNUNET_break (0); + return; + } - // FIXME: ask ATS/TRANSPORT to 'connect' - // => needs HELLO! - GNUNET_break (0); + hh = GNUNET_new (struct HelloHandle); + hh->plugin = plugin; + GNUNET_CONTAINER_DLL_insert (plugin->hh_head, + plugin->hh_tail, + hh); + hh->ohh = GNUNET_TRANSPORT_offer_hello (plugin->env->cfg, + &hello->header, + &hello_offered_cb, + hh); + GNUNET_free (hello); } @@ -332,7 +426,7 @@ ip_drop (struct GNUNET_DHTU_PreferenceHandle *ph) { struct GNUNET_DHTU_Target *target = ph->target; struct Plugin *plugin = target->plugin; - + GNUNET_CONTAINER_DLL_remove (target->ph_head, target->ph_tail, ph); @@ -390,7 +484,6 @@ ip_send (void *cls, } - /** * Method called whenever a given peer connects. * @@ -447,6 +540,52 @@ core_disconnect_cb (void *cls, } +/** + * Find the @a hello for our identity and then pass + * it to the DHT as a URL. Note that we only + * add addresses, never remove them, due to limitations + * of the current peerinfo/core/transport APIs. + * This will change with TNG. + * + * @param cls a `struct Plugin` + * @param peer id of the peer, NULL for last call + * @param hello hello message for the peer (can be NULL) + * @param error message + */ +static void +peerinfo_cb (void *cls, + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_HELLO_Message *hello, + const char *err_msg) +{ + struct Plugin *plugin = cls; + char *addr; + + if (NULL == hello) + return; + if (NULL == peer) + return; + if (0 != + GNUNET_memcmp (peer, + &plugin->my_identity)) + return; + addr = GNUNET_HELLO_compose_uri (hello, + &GPI_plugins_find); + if (NULL == addr) + return; + GNUNET_CRYPTO_hash (&plugin->my_identity, + sizeof (struct GNUNET_PeerIdentity), + &plugin->src.my_id.hc); + plugin->env->address_add_cb (plugin->env->cls, + &plugin->src.my_id, + &plugin->src.pk, + addr, + &plugin->src, + &plugin->src.app_ctx); + GNUNET_free (addr); +} + + /** * Function called after #GNUNET_CORE_connect has succeeded (or failed * for good). Note that the private key of the peer is intentionally @@ -464,27 +603,12 @@ core_init_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity) { struct Plugin *plugin = cls; - char *addr; - char *pid; - - // FIXME: to later ask ATS/TRANSPORT to 'connect' we need a HELLO, - // not merely a vanilla PID... - pid = GNUNET_STRINGS_data_to_string_alloc (my_identity, - sizeof (struct GNUNET_PeerIdentity)); - GNUNET_asprintf (&addr, - "gnunet-core-v15://%s/", - pid); - GNUNET_free (pid); - GNUNET_CRYPTO_hash (my_identity, - sizeof (struct GNUNET_PeerIdentity), - &plugin->src.my_id.hc); - plugin->env->address_add_cb (plugin->env->cls, - &plugin->src.my_id, - &plugin->src.pk, - addr, - &plugin->src, - &plugin->src.app_ctx); - GNUNET_free (addr); + + plugin->my_identity = *my_identity; + plugin->nc = GNUNET_PEERINFO_notify (plugin->env->cfg, + GNUNET_NO, + &peerinfo_cb, + plugin); } @@ -561,13 +685,25 @@ libgnunet_plugin_dhtu_gnunet_done (void *cls) { struct GNUNET_DHTU_PluginFunctions *api = cls; struct Plugin *plugin = api->cls; + struct HelloHandle *hh; + while (NULL != (hh = plugin->hh_head)) + { + GNUNET_CONTAINER_DLL_remove (plugin->hh_head, + plugin->hh_tail, + hh); + GNUNET_TRANSPORT_offer_hello_cancel (hh->ohh); + GNUNET_free (hh); + } if (NULL != plugin->nse) GNUNET_NSE_disconnect (plugin->nse); if (NULL != plugin->core) GNUNET_CORE_disconnect (plugin->core); if (NULL != plugin->ats) GNUNET_ATS_connectivity_done (plugin->ats); + if (NULL != plugin->nc) + GNUNET_PEERINFO_notify_cancel (plugin->nc); + GPI_plugins_unload (); GNUNET_free (plugin); GNUNET_free (api); return NULL; @@ -594,7 +730,7 @@ libgnunet_plugin_dhtu_ip_init (void *cls) GNUNET_MQ_handler_end () }; struct GNUNET_CRYPTO_EddsaPrivateKey *pk; - + pk = GNUNET_CRYPTO_eddsa_key_create_from_configuration (env->cfg); if (NULL == pk) { @@ -631,7 +767,6 @@ libgnunet_plugin_dhtu_ip_init (void *cls) libgnunet_plugin_dhtu_gnunet_done (plugin); return NULL; } + GPI_plugins_load (env->cfg); return api; } - - -- cgit v1.2.3 From 8f18cbcaf6025d40fa1d400f5a4e702ad957809a Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 23 Sep 2021 22:52:20 +0200 Subject: -add first dhtu test skeleton --- src/dhtu/Makefile.am | 16 ++++++++++ src/dhtu/test_dhtu_ip.c | 77 +++++++++++++++++++++++++++++++++++++++++++++ src/util/child_management.c | 47 +++++++++++---------------- 3 files changed, 111 insertions(+), 29 deletions(-) create mode 100644 src/dhtu/test_dhtu_ip.c (limited to 'src') diff --git a/src/dhtu/Makefile.am b/src/dhtu/Makefile.am index 33c31dd6c..61ca84ee3 100644 --- a/src/dhtu/Makefile.am +++ b/src/dhtu/Makefile.am @@ -39,3 +39,19 @@ libgnunet_plugin_dhtu_gnunet_la_LIBADD = \ $(LTLIBINTL) libgnunet_plugin_dhtu_gnunet_la_LDFLAGS = \ $(GN_PLUGIN_LDFLAGS) + + +test_dhtu_ip_SOURCES = \ + test_dhtu_ip.c +test_dhtu_ip_LDADD = \ + $(top_builddir)/src/testing/libgnunettesting.la \ + $(top_builddir)/src/util/libgnunetutil.la + +check_PROGRAMS = \ + test_dhtu_ip + +if ENABLE_TEST_RUN +AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; +TESTS = \ + $(check_PROGRAMS) +endif diff --git a/src/dhtu/test_dhtu_ip.c b/src/dhtu/test_dhtu_ip.c new file mode 100644 index 000000000..f350905b8 --- /dev/null +++ b/src/dhtu/test_dhtu_ip.c @@ -0,0 +1,77 @@ +/* + 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 dhtu/test_dhtu_ip.c + * @brief Test case for the DHTU implementation for IP + * @author Christian Grothoff + */ +#include "platform.h" +#include "gnunet_testing_ng_lib.h" +#include "gnunet_util_lib.h" + +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) + +#define CONFIG_FILE "test_dhtu_ip.conf" + + +/** + * Return value of the test. + * + */ +static int rv; + + +/** + * Main function to run the test cases. + * + * @param cls not used. + */ +static void +run (void *cls) +{ + struct GNUNET_TESTING_Command commands[] = { + GNUNET_TESTING_cmd_netjail_start_v2 ("netjail-start", + CONFIG_FILE), + GNUNET_TESTING_cmd_netjail_stop_v2 ("netjail-stop", + CONFIG_FILE), + GNUNET_TESTING_cmd_end () + }; + + (void) cls; + if (GNUNET_OK != + GNUNET_TESTING_run (NULL, /* config file */ + commands, + TIMEOUT)) + { + GNUNET_break (0); + rv = EXIT_FAILURE; + } +} + + +int +main (int argc, + char *const *argv) +{ + GNUNET_SCHEDULER_run (&run, + NULL); + return rv; +} diff --git a/src/util/child_management.c b/src/util/child_management.c index 3afd682b9..4ef42dba2 100644 --- a/src/util/child_management.c +++ b/src/util/child_management.c @@ -91,15 +91,10 @@ maint_child_death (void *cls) (void) cls; sig_task = NULL; - - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Received SIGCHLD.\n"); - /* drain pipe */ pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ); GNUNET_assert (! GNUNET_DISK_handle_invalid (pr)); - (void) GNUNET_DISK_file_read (pr, buf, sizeof(buf)); @@ -159,9 +154,8 @@ sighandler_child_death (void) } -// void __attribute__ ((constructor)) static void -child_management_start () +child_management_start (void) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Trying to start child management.\n"); @@ -170,19 +164,24 @@ child_management_start () sigpipe = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE); GNUNET_assert (sigpipe != NULL); shc_chld = - GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); + GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, + &sighandler_child_death); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Child management started.\n"); } + /** * Clean up. */ -// void __attribute__ ((destructor)) static void -child_management_done () +child_management_done (void) { - GNUNET_assert (NULL == sig_task); + if (NULL != sig_task) + { + GNUNET_SCHEDULER_cancel (sig_task); + sig_task = NULL; + } GNUNET_SIGNAL_handler_uninstall (shc_chld); shc_chld = NULL; GNUNET_DISK_pipe_close (sigpipe); @@ -191,6 +190,7 @@ child_management_done () "Child management stopped.\n"); } + struct GNUNET_ChildWaitHandle * GNUNET_wait_child (struct GNUNET_OS_Process *proc, GNUNET_ChildCompletedCallback cb, @@ -198,9 +198,6 @@ GNUNET_wait_child (struct GNUNET_OS_Process *proc, { struct GNUNET_ChildWaitHandle *cwh; - LOG (GNUNET_ERROR_TYPE_ERROR, - "Adding child!\n"); - child_management_start (); cwh = GNUNET_new (struct GNUNET_ChildWaitHandle); cwh->proc = proc; @@ -221,23 +218,15 @@ GNUNET_wait_child (struct GNUNET_OS_Process *proc, return cwh; } + void GNUNET_wait_child_cancel (struct GNUNET_ChildWaitHandle *cwh) { - if ((NULL != cwh_head)) - { - GNUNET_CONTAINER_DLL_remove (cwh_head, - cwh_tail, - cwh); - } - if (NULL == cwh_head) - { - child_management_done (); - } - if (NULL != sig_task) - { - GNUNET_SCHEDULER_cancel (sig_task); - sig_task = NULL; - } + GNUNET_CONTAINER_DLL_remove (cwh_head, + cwh_tail, + cwh); GNUNET_free (cwh); + if (NULL != cwh_head) + return; + child_management_done (); } -- cgit v1.2.3 From 1aa0d5f3421d8598f12005ea1138c9eb24ddfd2c Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 23 Sep 2021 22:52:44 +0200 Subject: PQ: implementing #7014: support testing database version is current --- src/include/gnunet_pq_lib.h | 102 +++++++++++++++++++++++++--- src/pq/pq.h | 5 ++ src/pq/pq_connect.c | 158 ++++++++++++++++++++++++++++---------------- src/pq/pq_exec.c | 2 +- 4 files changed, 201 insertions(+), 66 deletions(-) (limited to 'src') diff --git a/src/include/gnunet_pq_lib.h b/src/include/gnunet_pq_lib.h index fe3fabbea..6a2227581 100644 --- a/src/include/gnunet_pq_lib.h +++ b/src/include/gnunet_pq_lib.h @@ -470,7 +470,8 @@ GNUNET_PQ_result_spec_absolute_time_nbo (const char *name, * @return array entry for the result specification to use */ struct GNUNET_PQ_ResultSpec -GNUNET_PQ_result_spec_uint16 (const char *name, uint16_t *u16); +GNUNET_PQ_result_spec_uint16 (const char *name, + uint16_t *u16); /** @@ -481,7 +482,8 @@ GNUNET_PQ_result_spec_uint16 (const char *name, uint16_t *u16); * @return array entry for the result specification to use */ struct GNUNET_PQ_ResultSpec -GNUNET_PQ_result_spec_uint32 (const char *name, uint32_t *u32); +GNUNET_PQ_result_spec_uint32 (const char *name, + uint32_t *u32); /** @@ -492,7 +494,8 @@ GNUNET_PQ_result_spec_uint32 (const char *name, uint32_t *u32); * @return array entry for the result specification to use */ struct GNUNET_PQ_ResultSpec -GNUNET_PQ_result_spec_uint64 (const char *name, uint64_t *u64); +GNUNET_PQ_result_spec_uint64 (const char *name, + uint64_t *u64); /* ************************* pq.c functions ************************ */ @@ -641,11 +644,11 @@ GNUNET_PQ_eval_prepared_multi_select (struct GNUNET_PQ_Context *db, * codes to `enum GNUNET_DB_QueryStatus`. */ enum GNUNET_DB_QueryStatus -GNUNET_PQ_eval_prepared_singleton_select (struct GNUNET_PQ_Context *db, - const char *statement_name, - const struct - GNUNET_PQ_QueryParam *params, - struct GNUNET_PQ_ResultSpec *rs); +GNUNET_PQ_eval_prepared_singleton_select ( + struct GNUNET_PQ_Context *db, + const char *statement_name, + const struct GNUNET_PQ_QueryParam *params, + struct GNUNET_PQ_ResultSpec *rs); /* ******************** pq_prepare.c functions ************** */ @@ -772,7 +775,7 @@ GNUNET_PQ_make_try_execute (const char *sql); * @return #GNUNET_OK on success (modulo statements where errors can be ignored) * #GNUNET_SYSERR on error */ -int +enum GNUNET_GenericReturnValue GNUNET_PQ_exec_statements (struct GNUNET_PQ_Context *db, const struct GNUNET_PQ_ExecuteStatement *es); @@ -780,6 +783,29 @@ GNUNET_PQ_exec_statements (struct GNUNET_PQ_Context *db, /* ******************** pq_connect.c functions ************** */ +/** + * Flags to control PQ operation. + */ +enum GNUNET_PQ_Options +{ + /** + * Traditional default. Do nothing special. + */ + GNUNET_PQ_FLAG_NONE = 0, + + /** + * Dropping database. Do not attempt to initialize + * versioning schema if not present. + */ + GNUNET_PQ_FLAG_DROP = 1, + + /** + * Check database version is current. Fail to connect if it is not. + */ + GNUNET_PQ_FLAG_CHECK_CURRENT = 2 +}; + + /** * Create a connection to the Postgres database using @a config_str for the * configuration. Initialize logging via GNUnet's log routines and disable @@ -809,6 +835,37 @@ GNUNET_PQ_connect (const char *config_str, const struct GNUNET_PQ_PreparedStatement *ps); +/** + * Create a connection to the Postgres database using @a config_str for the + * configuration. Initialize logging via GNUnet's log routines and disable + * Postgres's logger. Also ensures that the statements in @a load_path and @a + * es are executed whenever we (re)connect to the database, and that the + * prepared statements in @a ps are "ready". If statements in @es fail that + * were created with #GNUNET_PQ_make_execute(), then the entire operation + * fails. + * + * In @a load_path, a list of "$XXXX.sql" files is expected where $XXXX + * must be a sequence of contiguous integer values starting at 0000. + * These files are then loaded in sequence using "psql $config_str" before + * running statements from @e es. The directory is inspected again on + * reconnect. + * + * @param config_str configuration to use + * @param load_path path to directory with SQL transactions to run, can be NULL + * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated + * array of statements to execute upon EACH connection, can be NULL + * @param ps array of prepared statements to prepare, can be NULL + * @param flags connection flags + * @return NULL on error + */ +struct GNUNET_PQ_Context * +GNUNET_PQ_connect2 (const char *config_str, + const char *load_path, + const struct GNUNET_PQ_ExecuteStatement *es, + const struct GNUNET_PQ_PreparedStatement *ps, + enum GNUNET_PQ_Options flags); + + /** * Connect to a postgres database using the configuration * option "CONFIG" in @a section. Also ensures that the @@ -834,6 +891,33 @@ GNUNET_PQ_connect_with_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_PQ_PreparedStatement *ps); +/** + * Connect to a postgres database using the configuration + * option "CONFIG" in @a section. Also ensures that the + * statements in @a es are executed whenever we (re)connect to the + * database, and that the prepared statements in @a ps are "ready". + * + * The caller does not have to ensure that @a es and @a ps remain allocated + * and initialized in memory until #GNUNET_PQ_disconnect() is called, as a copy will be made. + * + * @param cfg configuration + * @param section configuration section to use to get Postgres configuration options + * @param load_path_suffix suffix to append to the SQL_DIR in the configuration + * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated + * array of statements to execute upon EACH connection, can be NULL + * @param ps array of prepared statements to prepare, can be NULL + * @param flags connection flags + * @return the postgres handle, NULL on error + */ +struct GNUNET_PQ_Context * +GNUNET_PQ_connect_with_cfg2 (const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *section, + const char *load_path_suffix, + const struct GNUNET_PQ_ExecuteStatement *es, + const struct GNUNET_PQ_PreparedStatement *ps, + enum GNUNET_PQ_Options flags); + + /** * Reinitialize the database @a db if the connection is down. * diff --git a/src/pq/pq.h b/src/pq/pq.h index d10931d99..354d85a9f 100644 --- a/src/pq/pq.h +++ b/src/pq/pq.h @@ -73,6 +73,11 @@ struct GNUNET_PQ_Context * File descriptor wrapper for @e event_task. */ struct GNUNET_NETWORK_Handle *rfd; + + /** + * Flags controlling the connection. + */ + enum GNUNET_PQ_Options flags; }; diff --git a/src/pq/pq_connect.c b/src/pq/pq_connect.c index a2dce3fb0..a63d5f14e 100644 --- a/src/pq/pq_connect.c +++ b/src/pq/pq_connect.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet - Copyright (C) 2017, 2019, 2020 GNUnet e.V. + Copyright (C) 2017, 2019, 2020, 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 @@ -69,6 +69,21 @@ GNUNET_PQ_connect (const char *config_str, const char *load_path, const struct GNUNET_PQ_ExecuteStatement *es, const struct GNUNET_PQ_PreparedStatement *ps) +{ + return GNUNET_PQ_connect2 (config_str, + load_path, + es, + ps, + GNUNET_PQ_FLAG_NONE); +} + + +struct GNUNET_PQ_Context * +GNUNET_PQ_connect2 (const char *config_str, + const char *load_path, + const struct GNUNET_PQ_ExecuteStatement *es, + const struct GNUNET_PQ_PreparedStatement *ps, + enum GNUNET_PQ_Options flags) { struct GNUNET_PQ_Context *db; unsigned int elen = 0; @@ -82,6 +97,7 @@ GNUNET_PQ_connect (const char *config_str, plen++; db = GNUNET_new (struct GNUNET_PQ_Context); + db->flags = flags; db->config_str = GNUNET_strdup (config_str); if (NULL != load_path) db->load_path = GNUNET_strdup (load_path); @@ -200,68 +216,72 @@ GNUNET_PQ_run_sql (struct GNUNET_PQ_Context *db, load_path); for (unsigned int i = 1; i<10000; i++) { + char patch_name[slen]; + char buf[slen]; enum GNUNET_DB_QueryStatus qs; - { - char buf[slen]; - - /* First, check patch actually exists */ - GNUNET_snprintf (buf, - sizeof (buf), - "%s%04u.sql", - load_path, - i); - if (GNUNET_YES != - GNUNET_DISK_file_test (buf)) - return GNUNET_OK; /* We are done */ - } + + /* First, check patch actually exists */ + GNUNET_snprintf (buf, + sizeof (buf), + "%s%04u.sql", + load_path, + i); + if (GNUNET_YES != + GNUNET_DISK_file_test (buf)) + return GNUNET_OK; /* We are done */ /* Second, check with DB versioning schema if this patch was already applied, if so, skip it. */ + GNUNET_snprintf (patch_name, + sizeof (patch_name), + "%s%04u", + load_path_suffix, + i); { - char patch_name[slen]; - - GNUNET_snprintf (patch_name, - sizeof (patch_name), - "%s%04u", - load_path_suffix, - i); + char *applied_by; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (patch_name), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("applied_by", + &applied_by), + GNUNET_PQ_result_spec_end + }; + + qs = GNUNET_PQ_eval_prepared_singleton_select (db, + "gnunet_pq_check_patch", + params, + rs); + if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Database version %s already applied by %s, skipping\n", + patch_name, + applied_by); + GNUNET_PQ_cleanup_result (rs); + } + if (GNUNET_DB_STATUS_HARD_ERROR == qs) { - char *applied_by; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (patch_name), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("applied_by", - &applied_by), - GNUNET_PQ_result_spec_end - }; - - qs = GNUNET_PQ_eval_prepared_singleton_select (db, - "gnunet_pq_check_patch", - params, - rs); - if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Database version %s already applied by %s, skipping\n", - patch_name, - applied_by); - GNUNET_PQ_cleanup_result (rs); - } - if (GNUNET_DB_STATUS_HARD_ERROR == qs) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + GNUNET_break (0); + return GNUNET_SYSERR; } } if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) continue; /* patch already applied, skip it */ - /* patch not yet applied, run it! */ + if (0 != (GNUNET_PQ_FLAG_CHECK_CURRENT & db->flags)) { - int ret; + /* We are only checking, found unapplied patch, bad! */ + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Database outdated, patch %s missing. Aborting!\n", + patch_name); + return GNUNET_SYSERR; + } + else + { + /* patch not yet applied, run it! */ + enum GNUNET_GenericReturnValue ret; ret = apply_patch (db, load_path, @@ -334,9 +354,17 @@ GNUNET_PQ_reconnect (struct GNUNET_PQ_Context *db) NULL); if (PGRES_COMMAND_OK != PQresultStatus (res)) { - int ret; + enum GNUNET_GenericReturnValue ret; PQclear (res); + if (0 != (db->flags & GNUNET_PQ_FLAG_DROP)) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Failed to prepare statement to check patch level. Likely versioning schema does not exist yet. Not attempting drop!\n"); + PQfinish (db->conn); + db->conn = NULL; + return; + } GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Failed to prepare statement to check patch level. Likely versioning schema does not exist yet, loading patch level 0000!\n"); ret = apply_patch (db, @@ -423,6 +451,23 @@ GNUNET_PQ_connect_with_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *load_path_suffix, const struct GNUNET_PQ_ExecuteStatement *es, const struct GNUNET_PQ_PreparedStatement *ps) +{ + return GNUNET_PQ_connect_with_cfg2 (cfg, + section, + load_path_suffix, + es, + ps, + GNUNET_PQ_FLAG_NONE); +} + + +struct GNUNET_PQ_Context * +GNUNET_PQ_connect_with_cfg2 (const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *section, + const char *load_path_suffix, + const struct GNUNET_PQ_ExecuteStatement *es, + const struct GNUNET_PQ_PreparedStatement *ps, + enum GNUNET_PQ_Options flags) { struct GNUNET_PQ_Context *db; char *conninfo; @@ -447,10 +492,11 @@ GNUNET_PQ_connect_with_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg, "%s%s", sp, load_path_suffix); - db = GNUNET_PQ_connect (conninfo == NULL ? "" : conninfo, - load_path, - es, - ps); + db = GNUNET_PQ_connect2 (conninfo == NULL ? "" : conninfo, + load_path, + es, + ps, + flags); GNUNET_free (load_path); GNUNET_free (sp); GNUNET_free (conninfo); diff --git a/src/pq/pq_exec.c b/src/pq/pq_exec.c index fd4feae53..464fff4b4 100644 --- a/src/pq/pq_exec.c +++ b/src/pq/pq_exec.c @@ -72,7 +72,7 @@ GNUNET_PQ_make_try_execute (const char *sql) * @return #GNUNET_OK on success (modulo statements where errors can be ignored) * #GNUNET_SYSERR on error */ -int +enum GNUNET_GenericReturnValue GNUNET_PQ_exec_statements (struct GNUNET_PQ_Context *db, const struct GNUNET_PQ_ExecuteStatement *es) { -- cgit v1.2.3 From 8d5876b0e1726a04bdd150571dd4075664f4f287 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 24 Sep 2021 09:51:50 +0200 Subject: -bugfixes and FIXMEs for t3ss --- src/testing/testing_api_cmd_netjail_start_v2.c | 86 ++++++++++++++++---------- 1 file changed, 53 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/testing/testing_api_cmd_netjail_start_v2.c b/src/testing/testing_api_cmd_netjail_start_v2.c index 36fbb0e10..9123148a7 100644 --- a/src/testing/testing_api_cmd_netjail_start_v2.c +++ b/src/testing/testing_api_cmd_netjail_start_v2.c @@ -49,7 +49,8 @@ struct NetJailState struct GNUNET_OS_Process *start_proc; // Flag indication if the script finished. - unsigned int finished; + // FIXME: document 3 values + enum GNUNET_GenericReturnValue finished; }; @@ -116,6 +117,7 @@ child_completed_callback (void *cls, } else { + // FIXME: log status code GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Child completed with an error!\n"); ns->finished = GNUNET_SYSERR; @@ -139,15 +141,13 @@ netjail_start_run (void *cls, struct GNUNET_TESTING_Interpreter *is) { struct NetJailState *ns = cls; - char *pid; - GNUNET_asprintf (&pid, - "%u", - getpid ()); - char *const script_argv[] = {NETJAIL_START_SCRIPT, - ns->topology_config, - pid, - NULL}; - unsigned int helper_check = GNUNET_OS_check_helper_binary ( + char pid[15]; + enum GNUNET_GenericReturnValue helper_check; + + // FIXME: NETJAIL_START_SCRIPT like this is bad, + // use location from share/gnunet/ of installed + // binary in case libgnunettesting is used as a lib! + helper_check = GNUNET_OS_check_helper_binary ( NETJAIL_START_SCRIPT, GNUNET_YES, NULL); @@ -158,22 +158,37 @@ netjail_start_run (void *cls, "No SUID for %s!\n", NETJAIL_START_SCRIPT); GNUNET_TESTING_interpreter_fail (); + return; } - else if (GNUNET_NO == helper_check) + if (GNUNET_SYSERR == helper_check) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s not found!\n", NETJAIL_START_SCRIPT); GNUNET_TESTING_interpreter_fail (); + return; } - ns->start_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR, - NULL, - NULL, - NULL, - NETJAIL_START_SCRIPT, - script_argv); - + GNUNET_snprintf (pid, + sizeof (pid), + "%u", + getpid ()); + { + char *const script_argv[] = { + NETJAIL_START_SCRIPT, + ns->topology_config, + pid, + NULL + }; + + ns->start_proc + = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR, + NULL, + NULL, + NULL, + NETJAIL_START_SCRIPT, + script_argv); + } ns->cwh = GNUNET_wait_child (ns->start_proc, &child_completed_callback, ns); @@ -182,23 +197,28 @@ netjail_start_run (void *cls, /** - * This function checks the flag NetJailState#finished, if this cmd finished. + * This function checks the flag NetJailState + * + * FIXME: fix comment! + * #finished, if this cmd finished. * */ -static int +static enum GNUNET_GenericReturnValue netjail_start_finish (void *cls, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls) { struct NetJailState *ns = cls; - if (ns->finished) + if (GNUNET_NO != ns->finished) { cont (cont_cls); } + // FIXME: cont should be called later in the else case! return ns->finished; } + /** * Create command. * @@ -213,17 +233,17 @@ GNUNET_TESTING_cmd_netjail_start_v2 (const char *label, struct NetJailState *ns; ns = GNUNET_new (struct NetJailState); - ns->finished = GNUNET_NO; ns->topology_config = topology_config; - - struct GNUNET_TESTING_Command cmd = { - .cls = ns, - .label = label, - .run = &netjail_start_run, - .finish = &netjail_start_finish, - .cleanup = &netjail_start_cleanup, - .traits = &netjail_start_traits - }; - - return cmd; + { + struct GNUNET_TESTING_Command cmd = { + .cls = ns, + .label = label, + .run = &netjail_start_run, + .finish = &netjail_start_finish, + .cleanup = &netjail_start_cleanup, + .traits = &netjail_start_traits + }; + + return cmd; + } } -- cgit v1.2.3 From 1fef34e55a00816bdb237e87ff14d54e6575f763 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 27 Sep 2021 09:00:59 +0200 Subject: -indent --- src/include/gnunet_crypto_lib.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index ae73c9d40..e754756e5 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h @@ -821,7 +821,8 @@ GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key, * @param cls closure * @param res resulting hash, NULL on error */ -typedef void (*GNUNET_CRYPTO_HashCompletedCallback) ( +typedef void +(*GNUNET_CRYPTO_HashCompletedCallback) ( void *cls, const struct GNUNET_HashCode *res); -- cgit v1.2.3 From 7ecc3a03a0670a1620c603502c9958b95e6dc1d0 Mon Sep 17 00:00:00 2001 From: TheJackiMonster Date: Mon, 27 Sep 2021 11:02:56 +0200 Subject: -indentation of parameters Signed-off-by: TheJackiMonster --- src/include/gnunet_messenger_service.h | 47 ++++--- src/messenger/gnunet-messenger.c | 21 ++- src/messenger/gnunet-service-messenger.c | 51 +++++--- src/messenger/gnunet-service-messenger_basement.c | 8 +- src/messenger/gnunet-service-messenger_basement.h | 8 +- src/messenger/gnunet-service-messenger_ego_store.c | 37 ++++-- src/messenger/gnunet-service-messenger_ego_store.h | 21 ++- src/messenger/gnunet-service-messenger_handle.c | 79 ++++++++---- src/messenger/gnunet-service-messenger_handle.h | 40 ++++-- .../gnunet-service-messenger_list_handles.c | 9 +- .../gnunet-service-messenger_list_handles.h | 9 +- .../gnunet-service-messenger_list_messages.c | 15 ++- .../gnunet-service-messenger_list_messages.h | 15 ++- src/messenger/gnunet-service-messenger_member.c | 61 ++++++--- src/messenger/gnunet-service-messenger_member.h | 28 ++-- .../gnunet-service-messenger_member_session.c | 26 ++-- .../gnunet-service-messenger_member_session.h | 12 +- .../gnunet-service-messenger_member_store.c | 44 +++++-- .../gnunet-service-messenger_member_store.h | 21 ++- .../gnunet-service-messenger_message_handle.c | 51 +++++--- .../gnunet-service-messenger_message_handle.h | 48 ++++--- .../gnunet-service-messenger_message_kind.c | 6 +- .../gnunet-service-messenger_message_kind.h | 6 +- .../gnunet-service-messenger_message_recv.c | 32 +++-- .../gnunet-service-messenger_message_recv.h | 18 ++- .../gnunet-service-messenger_message_send.c | 24 ++-- .../gnunet-service-messenger_message_send.h | 24 ++-- .../gnunet-service-messenger_message_state.c | 12 +- .../gnunet-service-messenger_message_state.h | 12 +- .../gnunet-service-messenger_message_store.c | 54 +++++--- .../gnunet-service-messenger_message_store.h | 21 ++- src/messenger/gnunet-service-messenger_operation.c | 6 +- src/messenger/gnunet-service-messenger_operation.h | 6 +- .../gnunet-service-messenger_operation_store.c | 20 ++- .../gnunet-service-messenger_operation_store.h | 3 +- src/messenger/gnunet-service-messenger_room.c | 142 ++++++++++++++------- src/messenger/gnunet-service-messenger_room.h | 55 +++++--- src/messenger/gnunet-service-messenger_service.c | 37 ++++-- src/messenger/gnunet-service-messenger_service.h | 33 +++-- src/messenger/gnunet-service-messenger_tunnel.c | 49 ++++--- src/messenger/gnunet-service-messenger_tunnel.h | 22 +++- src/messenger/messenger_api.c | 90 ++++++++----- src/messenger/messenger_api_contact.c | 6 +- src/messenger/messenger_api_contact.h | 6 +- src/messenger/messenger_api_contact_store.c | 22 +++- src/messenger/messenger_api_contact_store.h | 15 ++- src/messenger/messenger_api_handle.c | 29 +++-- src/messenger/messenger_api_handle.h | 25 ++-- src/messenger/messenger_api_list_tunnels.c | 22 +++- src/messenger/messenger_api_list_tunnels.h | 19 ++- src/messenger/messenger_api_message.c | 74 +++++++---- src/messenger/messenger_api_message.h | 37 ++++-- src/messenger/messenger_api_room.c | 75 +++++++---- src/messenger/messenger_api_room.h | 21 ++- src/messenger/messenger_api_util.c | 6 +- src/messenger/messenger_api_util.h | 6 +- src/messenger/test_messenger.c | 10 +- src/messenger/test_messenger_adapt.c | 3 +- src/messenger/test_messenger_anonymous.c | 10 +- src/messenger/test_messenger_async_client.c | 3 +- src/messenger/test_messenger_async_p2p.c | 3 +- src/messenger/test_messenger_growth.c | 3 +- src/messenger/test_messenger_ring.c | 3 +- src/messenger/test_messenger_server.c | 3 +- src/messenger/test_messenger_sync_client.c | 3 +- src/messenger/test_messenger_sync_p2p.c | 3 +- src/messenger/test_messenger_worst_client.c | 3 +- src/messenger/test_messenger_worst_p2p.c | 3 +- src/messenger/testing_messenger_barrier.c | 6 +- src/messenger/testing_messenger_setup.c | 41 ++++-- src/messenger/testing_messenger_setup.h | 3 +- 71 files changed, 1219 insertions(+), 567 deletions(-) (limited to 'src') diff --git a/src/include/gnunet_messenger_service.h b/src/include/gnunet_messenger_service.h index 5d7155a3d..b54567aa7 100644 --- a/src/include/gnunet_messenger_service.h +++ b/src/include/gnunet_messenger_service.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2020 GNUnet e.V. + Copyright (C) 2020--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 @@ -527,7 +527,8 @@ enum GNUNET_MESSENGER_MessageFlags * @param[in/out] handle Messenger handle */ typedef void -(*GNUNET_MESSENGER_IdentityCallback) (void *cls, struct GNUNET_MESSENGER_Handle *handle); +(*GNUNET_MESSENGER_IdentityCallback) (void *cls, + struct GNUNET_MESSENGER_Handle *handle); /** * Method called whenever a message is sent or received from a room. @@ -543,7 +544,8 @@ typedef void * @param[in] flags Flags of the message */ typedef void -(*GNUNET_MESSENGER_MessageCallback) (void *cls, struct GNUNET_MESSENGER_Room *room, +(*GNUNET_MESSENGER_MessageCallback) (void *cls, + struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *sender, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, @@ -558,7 +560,8 @@ typedef void * @param[in] contact Contact handle */ typedef int -(*GNUNET_MESSENGER_MemberCallback) (void* cls, struct GNUNET_MESSENGER_Room *room, +(*GNUNET_MESSENGER_MemberCallback) (void* cls, + struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *contact); /** @@ -574,9 +577,12 @@ typedef int * @return Messenger handle to use, NULL on error */ struct GNUNET_MESSENGER_Handle* -GNUNET_MESSENGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *name, - GNUNET_MESSENGER_IdentityCallback identity_callback, void *identity_cls, - GNUNET_MESSENGER_MessageCallback msg_callback, void *msg_cls); +GNUNET_MESSENGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *name, + GNUNET_MESSENGER_IdentityCallback identity_callback, + void *identity_cls, + GNUNET_MESSENGER_MessageCallback msg_callback, + void *msg_cls); /** * Update a handle of the messenger to use a different ego key and replace the old one with a newly generated one. All @@ -619,7 +625,8 @@ GNUNET_MESSENGER_get_name (const struct GNUNET_MESSENGER_Handle *handle); * @return #GNUNET_YES on success, #GNUNET_NO on failure and #GNUNET_SYSERR if handle is NULL */ int -GNUNET_MESSENGER_set_name (struct GNUNET_MESSENGER_Handle *handle, const char *name); +GNUNET_MESSENGER_set_name (struct GNUNET_MESSENGER_Handle *handle, + const char *name); /** * Get the public key used by the messenger or NULL if the anonymous key was used. @@ -647,7 +654,8 @@ GNUNET_MESSENGER_get_key (const struct GNUNET_MESSENGER_Handle *handle); * @return Room handle, NULL on error */ struct GNUNET_MESSENGER_Room* -GNUNET_MESSENGER_open_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key); +GNUNET_MESSENGER_open_room (struct GNUNET_MESSENGER_Handle *handle, + const struct GNUNET_HashCode *key); /** * Enter a room to send and receive messages through a door opened using #GNUNET_MESSENGER_open_room. @@ -668,7 +676,8 @@ GNUNET_MESSENGER_open_room (struct GNUNET_MESSENGER_Handle *handle, const struct * @return Room handle, NULL on error */ struct GNUNET_MESSENGER_Room* -GNUNET_MESSENGER_enter_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_PeerIdentity *door, +GNUNET_MESSENGER_enter_room (struct GNUNET_MESSENGER_Handle *handle, + const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key); /** @@ -695,8 +704,10 @@ GNUNET_MESSENGER_close_room (struct GNUNET_MESSENGER_Room *room); * @return Amount of rooms iterated */ int -GNUNET_MESSENGER_find_rooms (const struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_MESSENGER_Contact *contact, - GNUNET_MESSENGER_MemberCallback callback, void *cls); +GNUNET_MESSENGER_find_rooms (const struct GNUNET_MESSENGER_Handle *handle, + const struct GNUNET_MESSENGER_Contact *contact, + GNUNET_MESSENGER_MemberCallback callback, + void *cls); /** * Get the key of a given room. @@ -717,7 +728,8 @@ GNUNET_MESSENGER_room_get_key (const struct GNUNET_MESSENGER_Room *room); * @return Contact handle, NULL otherwise */ const struct GNUNET_MESSENGER_Contact* -GNUNET_MESSENGER_get_sender (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash); +GNUNET_MESSENGER_get_sender (const struct GNUNET_MESSENGER_Room *room, + const struct GNUNET_HashCode *hash); /** * Get the name used by the contact. @@ -756,7 +768,8 @@ GNUNET_MESSENGER_contact_get_key (const struct GNUNET_MESSENGER_Contact *contact * @param[in] contact Contact or NULL */ void -GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, +GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room, + const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_MESSENGER_Contact* contact); /** @@ -767,7 +780,8 @@ GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room, const struct * @return Message struct or NULL if no message with that hash is known */ const struct GNUNET_MESSENGER_Message* -GNUNET_MESSENGER_get_message (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash); +GNUNET_MESSENGER_get_message (const struct GNUNET_MESSENGER_Room *room, + const struct GNUNET_HashCode *hash); /** * Iterates through all members of a given room and calls a selected callback @@ -780,7 +794,8 @@ GNUNET_MESSENGER_get_message (const struct GNUNET_MESSENGER_Room *room, const st * @return Amount of members iterated */ int -GNUNET_MESSENGER_iterate_members (struct GNUNET_MESSENGER_Room *room, GNUNET_MESSENGER_MemberCallback callback, +GNUNET_MESSENGER_iterate_members (struct GNUNET_MESSENGER_Room *room, + GNUNET_MESSENGER_MemberCallback callback, void* cls); #if 0 /* keep Emacsens' auto-indent happy */ diff --git a/src/messenger/gnunet-messenger.c b/src/messenger/gnunet-messenger.c index 28fa4b147..e2d106be8 100644 --- a/src/messenger/gnunet-messenger.c +++ b/src/messenger/gnunet-messenger.c @@ -42,8 +42,11 @@ struct GNUNET_MESSENGER_Handle *messenger; * @param[in] flags Flags of message */ void -on_message (void *cls, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *sender, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, +on_message (void *cls, + struct GNUNET_MESSENGER_Room *room, + const struct GNUNET_MESSENGER_Contact *sender, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash, enum GNUNET_MESSENGER_MessageFlags flags) { const char *sender_name = GNUNET_MESSENGER_contact_get_name (sender); @@ -124,7 +127,8 @@ listen_stdio (void *cls); #define MAX_BUFFER_SIZE 60000 static int -iterate_send_private_message (void *cls, struct GNUNET_MESSENGER_Room *room, +iterate_send_private_message (void *cls, + struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *contact) { struct GNUNET_MESSENGER_Message *message = cls; @@ -226,7 +230,8 @@ struct GNUNET_SCHEDULER_Task *shutdown_task; * @param[in/out] handle Handle of messenger service */ static void -on_identity (void *cls, struct GNUNET_MESSENGER_Handle *handle) +on_identity (void *cls, + struct GNUNET_MESSENGER_Handle *handle) { struct GNUNET_HashCode key; memset (&key, 0, sizeof(key)); @@ -292,7 +297,10 @@ on_identity (void *cls, struct GNUNET_MESSENGER_Handle *handle) * @param[in] cfg configuration */ static void -run (void *cls, char *const*args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) +run (void *cls, + char *const*args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { messenger = GNUNET_MESSENGER_connect (cfg, ego_name, &on_identity, NULL, &on_message, NULL); @@ -307,7 +315,8 @@ run (void *cls, char *const*args, const char *cfgfile, const struct GNUNET_CONFI * @return #EXIT_SUCCESS ok, #EXIT_FAILURE on error */ int -main (int argc, char **argv) +main (int argc, + char **argv) { const char *description = "Open and connect to rooms using the MESSENGER to chat."; diff --git a/src/messenger/gnunet-service-messenger.c b/src/messenger/gnunet-service-messenger.c index 7edd76d32..989157ceb 100644 --- a/src/messenger/gnunet-service-messenger.c +++ b/src/messenger/gnunet-service-messenger.c @@ -39,14 +39,16 @@ struct GNUNET_MESSENGER_Client struct GNUNET_MESSENGER_Service *messenger; static int -check_create (void *cls, const struct GNUNET_MESSENGER_CreateMessage *msg) +check_create (void *cls, + const struct GNUNET_MESSENGER_CreateMessage *msg) { GNUNET_MQ_check_zero_termination(msg); return GNUNET_OK; } static void -handle_create (void *cls, const struct GNUNET_MESSENGER_CreateMessage *msg) +handle_create (void *cls, + const struct GNUNET_MESSENGER_CreateMessage *msg) { struct GNUNET_MESSENGER_Client *msg_client = cls; @@ -60,7 +62,8 @@ handle_create (void *cls, const struct GNUNET_MESSENGER_CreateMessage *msg) } static void -handle_update (void *cls, const struct GNUNET_MESSENGER_UpdateMessage *msg) +handle_update (void *cls, + const struct GNUNET_MESSENGER_UpdateMessage *msg) { struct GNUNET_MESSENGER_Client *msg_client = cls; @@ -70,7 +73,8 @@ handle_update (void *cls, const struct GNUNET_MESSENGER_UpdateMessage *msg) } static void -handle_destroy (void *cls, const struct GNUNET_MESSENGER_DestroyMessage *msg) +handle_destroy (void *cls, + const struct GNUNET_MESSENGER_DestroyMessage *msg) { struct GNUNET_MESSENGER_Client *msg_client = cls; @@ -78,14 +82,16 @@ handle_destroy (void *cls, const struct GNUNET_MESSENGER_DestroyMessage *msg) } static int -check_set_name (void *cls, const struct GNUNET_MESSENGER_NameMessage *msg) +check_set_name (void *cls, + const struct GNUNET_MESSENGER_NameMessage *msg) { GNUNET_MQ_check_zero_termination(msg); return GNUNET_OK; } static void -handle_set_name (void *cls, const struct GNUNET_MESSENGER_NameMessage *msg) +handle_set_name (void *cls, + const struct GNUNET_MESSENGER_NameMessage *msg) { struct GNUNET_MESSENGER_Client *msg_client = cls; @@ -99,7 +105,8 @@ handle_set_name (void *cls, const struct GNUNET_MESSENGER_NameMessage *msg) } static void -handle_room_open (void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg) +handle_room_open (void *cls, + const struct GNUNET_MESSENGER_RoomMessage *msg) { struct GNUNET_MESSENGER_Client *msg_client = cls; @@ -125,7 +132,8 @@ handle_room_open (void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg) } static void -handle_room_entry (void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg) +handle_room_entry (void *cls, + const struct GNUNET_MESSENGER_RoomMessage *msg) { struct GNUNET_MESSENGER_Client *msg_client = cls; @@ -153,7 +161,8 @@ handle_room_entry (void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg) } static void -handle_room_close (void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg) +handle_room_close (void *cls, + const struct GNUNET_MESSENGER_RoomMessage *msg) { struct GNUNET_MESSENGER_Client *msg_client = cls; @@ -179,7 +188,8 @@ handle_room_close (void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg) } static int -check_send_message (void *cls, const struct GNUNET_MESSENGER_SendMessage *msg) +check_send_message (void *cls, + const struct GNUNET_MESSENGER_SendMessage *msg) { const uint16_t full_length = ntohs (msg->header.size); @@ -224,7 +234,8 @@ check_for_message: } static void -handle_send_message (void *cls, const struct GNUNET_MESSENGER_SendMessage *msg) +handle_send_message (void *cls, + const struct GNUNET_MESSENGER_SendMessage *msg) { struct GNUNET_MESSENGER_Client *msg_client = cls; @@ -271,7 +282,8 @@ end_handling: } static void -callback_found_message (void *cls, struct GNUNET_MESSENGER_SrvRoom *room, +callback_found_message (void *cls, + struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) { @@ -300,7 +312,8 @@ callback_found_message (void *cls, struct GNUNET_MESSENGER_SrvRoom *room, } static void -handle_get_message (void *cls, const struct GNUNET_MESSENGER_GetMessage *msg) +handle_get_message (void *cls, + const struct GNUNET_MESSENGER_GetMessage *msg) { struct GNUNET_MESSENGER_Client *msg_client = cls; @@ -341,7 +354,9 @@ end_handling: } static void* -callback_client_connect (void *cls, struct GNUNET_SERVICE_Client *client, struct GNUNET_MQ_Handle *mq) +callback_client_connect (void *cls, + struct GNUNET_SERVICE_Client *client, + struct GNUNET_MQ_Handle *mq) { struct GNUNET_MESSENGER_Client *msg_client = GNUNET_new(struct GNUNET_MESSENGER_Client); @@ -352,7 +367,9 @@ callback_client_connect (void *cls, struct GNUNET_SERVICE_Client *client, struct } static void -callback_client_disconnect (void *cls, struct GNUNET_SERVICE_Client *client, void *internal_cls) +callback_client_disconnect (void *cls, + struct GNUNET_SERVICE_Client *client, + void *internal_cls) { struct GNUNET_MESSENGER_Client *msg_client = internal_cls; @@ -369,7 +386,9 @@ callback_client_disconnect (void *cls, struct GNUNET_SERVICE_Client *client, voi * @param[in/out] service the initialized service */ static void -run (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, struct GNUNET_SERVICE_Handle *service) +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *config, + struct GNUNET_SERVICE_Handle *service) { messenger = create_service (config, service); diff --git a/src/messenger/gnunet-service-messenger_basement.c b/src/messenger/gnunet-service-messenger_basement.c index f302c8d66..89aa103ee 100644 --- a/src/messenger/gnunet-service-messenger_basement.c +++ b/src/messenger/gnunet-service-messenger_basement.c @@ -40,7 +40,9 @@ count_of_tunnels (const struct GNUNET_MESSENGER_ListTunnels *tunnels) } int -should_connect_tunnel_to (size_t count, size_t src, size_t dst) +should_connect_tunnel_to (size_t count, + size_t src, + size_t dst) { if ((src + 1) % count == dst % count) return GNUNET_YES; @@ -49,7 +51,9 @@ should_connect_tunnel_to (size_t count, size_t src, size_t dst) } int -required_connection_between (size_t count, size_t src, size_t dst) +required_connection_between (size_t count, + size_t src, + size_t dst) { if (GNUNET_YES == should_connect_tunnel_to (count, src, dst)) return GNUNET_YES; diff --git a/src/messenger/gnunet-service-messenger_basement.h b/src/messenger/gnunet-service-messenger_basement.h index b19aec405..a097b482f 100644 --- a/src/messenger/gnunet-service-messenger_basement.h +++ b/src/messenger/gnunet-service-messenger_basement.h @@ -48,7 +48,9 @@ count_of_tunnels (const struct GNUNET_MESSENGER_ListTunnels *tunnels); * @return #GNUNET_YES or #GNUNET_NO based on topologic requirement */ int -should_connect_tunnel_to (size_t count, size_t src, size_t dst); +should_connect_tunnel_to (size_t count, + size_t src, + size_t dst); /** * Returns #GNUNET_YES or #GNUNET_NO to determine if the peers of index src and @@ -61,6 +63,8 @@ should_connect_tunnel_to (size_t count, size_t src, size_t dst); * @return #GNUNET_YES or #GNUNET_NO based on topologic requirement */ int -required_connection_between (size_t count, size_t src, size_t dst); +required_connection_between (size_t count, + size_t src, + size_t dst); #endif //GNUNET_SERVICE_MESSENGER_BASEMENT_H diff --git a/src/messenger/gnunet-service-messenger_ego_store.c b/src/messenger/gnunet-service-messenger_ego_store.c index 3b069fcf5..c460ac1c7 100644 --- a/src/messenger/gnunet-service-messenger_ego_store.c +++ b/src/messenger/gnunet-service-messenger_ego_store.c @@ -28,7 +28,10 @@ #include "gnunet-service-messenger_handle.h" static void -callback_update_ego (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *identifier) +callback_update_ego (void *cls, + struct GNUNET_IDENTITY_Ego *ego, + void **ctx, + const char *identifier) { if ((!ego) || (!identifier)) return; @@ -41,7 +44,8 @@ callback_update_ego (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, con } void -init_ego_store(struct GNUNET_MESSENGER_EgoStore *store, const struct GNUNET_CONFIGURATION_Handle *config) +init_ego_store(struct GNUNET_MESSENGER_EgoStore *store, + const struct GNUNET_CONFIGURATION_Handle *config) { GNUNET_assert ((store) && (config)); @@ -58,7 +62,9 @@ init_ego_store(struct GNUNET_MESSENGER_EgoStore *store, const struct GNUNET_CONF static int -iterate_destroy_egos (void *cls, const struct GNUNET_HashCode *key, void *value) +iterate_destroy_egos (void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_MESSENGER_Ego *ego = value; GNUNET_free(ego); @@ -112,7 +118,9 @@ clear_ego_store(struct GNUNET_MESSENGER_EgoStore *store) } static void -callback_ego_create (void *cls, const struct GNUNET_IDENTITY_PrivateKey *key, const char *emsg) +callback_ego_create (void *cls, + const struct GNUNET_IDENTITY_PrivateKey *key, + const char *emsg) { struct GNUNET_MESSENGER_EgoOperation *element = cls; struct GNUNET_MESSENGER_EgoStore *store = element->store; @@ -139,7 +147,8 @@ callback_ego_create (void *cls, const struct GNUNET_IDENTITY_PrivateKey *key, co } void -create_store_ego (struct GNUNET_MESSENGER_EgoStore *store, const char *identifier, +create_store_ego (struct GNUNET_MESSENGER_EgoStore *store, + const char *identifier, void *handle) { GNUNET_assert ((store) && (identifier)); @@ -158,7 +167,8 @@ create_store_ego (struct GNUNET_MESSENGER_EgoStore *store, const char *identifie } static void -callback_ego_lookup (void *cls, struct GNUNET_IDENTITY_Ego *ego) +callback_ego_lookup (void *cls, + struct GNUNET_IDENTITY_Ego *ego) { struct GNUNET_MESSENGER_EgoLookup *element = cls; struct GNUNET_MESSENGER_EgoStore *store = element->store; @@ -183,8 +193,10 @@ callback_ego_lookup (void *cls, struct GNUNET_IDENTITY_Ego *ego) } void -lookup_store_ego(struct GNUNET_MESSENGER_EgoStore *store, const char *identifier, - GNUNET_MESSENGER_EgoLookupCallback lookup, void *cls) +lookup_store_ego(struct GNUNET_MESSENGER_EgoStore *store, + const char *identifier, + GNUNET_MESSENGER_EgoLookupCallback lookup, + void *cls) { GNUNET_assert (store); @@ -219,7 +231,8 @@ lookup_store_ego(struct GNUNET_MESSENGER_EgoStore *store, const char *identifier } struct GNUNET_MESSENGER_Ego* -update_store_ego(struct GNUNET_MESSENGER_EgoStore *store, const char *identifier, +update_store_ego(struct GNUNET_MESSENGER_EgoStore *store, + const char *identifier, const struct GNUNET_IDENTITY_PrivateKey *key) { GNUNET_assert ((store) && (identifier) && (key)); @@ -244,7 +257,8 @@ update_store_ego(struct GNUNET_MESSENGER_EgoStore *store, const char *identifier } static void -callback_ego_rename (void *cls, const char *emsg) +callback_ego_rename (void *cls, + const char *emsg) { struct GNUNET_MESSENGER_EgoOperation *element = cls; struct GNUNET_MESSENGER_EgoStore *store = element->store; @@ -277,7 +291,8 @@ callback_ego_rename (void *cls, const char *emsg) } void -rename_store_ego (struct GNUNET_MESSENGER_EgoStore *store, const char *old_identifier, +rename_store_ego (struct GNUNET_MESSENGER_EgoStore *store, + const char *old_identifier, const char *new_identifier) { GNUNET_assert ((store) && (old_identifier) && (new_identifier)); diff --git a/src/messenger/gnunet-service-messenger_ego_store.h b/src/messenger/gnunet-service-messenger_ego_store.h index 41f14fff2..4222a4e91 100644 --- a/src/messenger/gnunet-service-messenger_ego_store.h +++ b/src/messenger/gnunet-service-messenger_ego_store.h @@ -35,7 +35,8 @@ struct GNUNET_MESSENGER_Ego; struct GNUNET_MESSENGER_EgoStore; typedef void -(*GNUNET_MESSENGER_EgoLookupCallback) (void *cls, const char *identifier, +(*GNUNET_MESSENGER_EgoLookupCallback) (void *cls, + const char *identifier, const struct GNUNET_MESSENGER_Ego *ego); struct GNUNET_MESSENGER_EgoLookup @@ -87,7 +88,8 @@ struct GNUNET_MESSENGER_EgoStore * @param[in] config Configuration handle */ void -init_ego_store (struct GNUNET_MESSENGER_EgoStore *store, const struct GNUNET_CONFIGURATION_Handle *config); +init_ego_store (struct GNUNET_MESSENGER_EgoStore *store, + const struct GNUNET_CONFIGURATION_Handle *config); /** * Clears an EGO-store, wipes its content and deallocates its memory. @@ -107,7 +109,8 @@ clear_ego_store (struct GNUNET_MESSENGER_EgoStore *store); * @param[in/out] handle Handle or NULL */ void -create_store_ego (struct GNUNET_MESSENGER_EgoStore *store, const char *identifier, +create_store_ego (struct GNUNET_MESSENGER_EgoStore *store, + const char *identifier, void *handle); /** @@ -120,8 +123,10 @@ create_store_ego (struct GNUNET_MESSENGER_EgoStore *store, const char *identifie * @param[in] cls Closure */ void -lookup_store_ego (struct GNUNET_MESSENGER_EgoStore *store, const char *identifier, - GNUNET_MESSENGER_EgoLookupCallback lookup, void *cls); +lookup_store_ego (struct GNUNET_MESSENGER_EgoStore *store, + const char *identifier, + GNUNET_MESSENGER_EgoLookupCallback lookup, + void *cls); /** * Updates the registration of an EGO to a store under @@ -133,7 +138,8 @@ lookup_store_ego (struct GNUNET_MESSENGER_EgoStore *store, const char *identifie * @return Updated EGO */ struct GNUNET_MESSENGER_Ego* -update_store_ego (struct GNUNET_MESSENGER_EgoStore *store, const char *identifier, +update_store_ego (struct GNUNET_MESSENGER_EgoStore *store, + const char *identifier, const struct GNUNET_IDENTITY_PrivateKey *key); /** @@ -146,7 +152,8 @@ update_store_ego (struct GNUNET_MESSENGER_EgoStore *store, const char *identifie * @param[in] new_identifier New identifier string */ void -rename_store_ego (struct GNUNET_MESSENGER_EgoStore *store, const char *old_identifier, +rename_store_ego (struct GNUNET_MESSENGER_EgoStore *store, + const char *old_identifier, const char *new_identifier); #endif //GNUNET_SERVICE_MESSENGER_EGO_STORE_H diff --git a/src/messenger/gnunet-service-messenger_handle.c b/src/messenger/gnunet-service-messenger_handle.c index d7007dbf6..2095f8b29 100644 --- a/src/messenger/gnunet-service-messenger_handle.c +++ b/src/messenger/gnunet-service-messenger_handle.c @@ -31,7 +31,8 @@ #include "messenger_api_util.h" struct GNUNET_MESSENGER_SrvHandle* -create_handle (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MQ_Handle *mq) +create_handle (struct GNUNET_MESSENGER_Service *service, + struct GNUNET_MQ_Handle *mq) { GNUNET_assert((service) && (mq)); @@ -49,7 +50,9 @@ create_handle (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MQ_Handle } int -iterate_free_member_ids (void *cls, const struct GNUNET_HashCode *key, void *value) +iterate_free_member_ids (void *cls, + const struct GNUNET_HashCode *key, + void *value) { GNUNET_free(value); @@ -74,7 +77,9 @@ destroy_handle (struct GNUNET_MESSENGER_SrvHandle *handle) } void -get_handle_data_subdir (const struct GNUNET_MESSENGER_SrvHandle *handle, const char *name, char **dir) +get_handle_data_subdir (const struct GNUNET_MESSENGER_SrvHandle *handle, + const char *name, + char **dir) { GNUNET_assert((handle) && (dir)); @@ -87,7 +92,8 @@ get_handle_data_subdir (const struct GNUNET_MESSENGER_SrvHandle *handle, const c } static int -create_handle_member_id (const struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key) +create_handle_member_id (const struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_HashCode *key) { GNUNET_assert((handle) && (key)); @@ -112,7 +118,8 @@ create_handle_member_id (const struct GNUNET_MESSENGER_SrvHandle *handle, const } const struct GNUNET_ShortHashCode* -get_handle_member_id (const struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key) +get_handle_member_id (const struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_HashCode *key) { GNUNET_assert((handle) && (key)); @@ -120,7 +127,8 @@ get_handle_member_id (const struct GNUNET_MESSENGER_SrvHandle *handle, const str } int -change_handle_member_id (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key, +change_handle_member_id (struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_HashCode *key, const struct GNUNET_ShortHashCode *unique_id) { GNUNET_assert((handle) && (key) && (unique_id)); @@ -165,7 +173,8 @@ send_message_to_client: } static void -change_handle_name (struct GNUNET_MESSENGER_SrvHandle *handle, const char *name) +change_handle_name (struct GNUNET_MESSENGER_SrvHandle *handle, + const char *name) { GNUNET_assert(handle); @@ -192,7 +201,8 @@ change_handle_name (struct GNUNET_MESSENGER_SrvHandle *handle, const char *name) } static void -change_handle_ego (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_MESSENGER_Ego *ego) +change_handle_ego (struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_MESSENGER_Ego *ego) { GNUNET_assert(handle); @@ -222,7 +232,9 @@ struct GNUNET_MESSENGER_MessageHandle }; static int -iterate_send_message (void *cls, const struct GNUNET_HashCode *key, void *value) +iterate_send_message (void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_MESSENGER_MessageHandle *msg_handle = cls; @@ -232,7 +244,8 @@ iterate_send_message (void *cls, const struct GNUNET_HashCode *key, void *value) } void -set_handle_ego (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_MESSENGER_Ego *ego) +set_handle_ego (struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_MESSENGER_Ego *ego) { GNUNET_assert((handle) && (ego)); @@ -271,7 +284,9 @@ get_handle_ego (const struct GNUNET_MESSENGER_SrvHandle *handle) } static void -callback_setup_handle_name (void *cls, const char *name, const struct GNUNET_MESSENGER_Ego *ego) +callback_setup_handle_name (void *cls, + const char *name, + const struct GNUNET_MESSENGER_Ego *ego) { struct GNUNET_MESSENGER_SrvHandle *handle = cls; @@ -285,7 +300,8 @@ callback_setup_handle_name (void *cls, const char *name, const struct GNUNET_MES } void -setup_handle_name (struct GNUNET_MESSENGER_SrvHandle *handle, const char *name) +setup_handle_name (struct GNUNET_MESSENGER_SrvHandle *handle, + const char *name) { GNUNET_assert(handle); @@ -295,7 +311,9 @@ setup_handle_name (struct GNUNET_MESSENGER_SrvHandle *handle, const char *name) } static void -callback_update_handle (void *cls, const char *name, const struct GNUNET_MESSENGER_Ego *ego) +callback_update_handle (void *cls, + const char *name, + const struct GNUNET_MESSENGER_Ego *ego) { struct GNUNET_MESSENGER_SrvHandle *handle = cls; @@ -326,7 +344,9 @@ update_handle (struct GNUNET_MESSENGER_SrvHandle *handle) } static void -callback_set_handle_name (void *cls, const char *name, const struct GNUNET_MESSENGER_Ego *ego) +callback_set_handle_name (void *cls, + const char *name, + const struct GNUNET_MESSENGER_Ego *ego) { struct GNUNET_MESSENGER_SrvHandle *handle = cls; @@ -383,7 +403,8 @@ callback_set_handle_name (void *cls, const char *name, const struct GNUNET_MESSE } void -set_handle_name (struct GNUNET_MESSENGER_SrvHandle *handle, const char *name) +set_handle_name (struct GNUNET_MESSENGER_SrvHandle *handle, + const char *name) { GNUNET_assert(handle); @@ -403,7 +424,8 @@ set_handle_name (struct GNUNET_MESSENGER_SrvHandle *handle, const char *name) } int -open_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key) +open_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_HashCode *key) { GNUNET_assert((handle) && (key)); @@ -414,7 +436,8 @@ open_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET } int -entry_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_PeerIdentity *door, +entry_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key) { GNUNET_assert((handle) && (door) && (key)); @@ -426,7 +449,8 @@ entry_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNE } int -close_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key) +close_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_HashCode *key) { GNUNET_assert((handle) && (key)); @@ -437,7 +461,8 @@ close_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNE } int -send_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key, +send_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_HashCode *key, const struct GNUNET_MESSENGER_Message *message) { GNUNET_assert((handle) && (key) && (message)); @@ -475,7 +500,8 @@ get_next_member_session_contect(const struct GNUNET_MESSENGER_MemberSession *ses } static const struct GNUNET_MESSENGER_MemberSession* -get_handle_member_session (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key) +get_handle_member_session (struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_HashCode *key) { GNUNET_assert((handle) && (key) && (handle->service)); @@ -497,9 +523,11 @@ get_handle_member_session (struct GNUNET_MESSENGER_SrvHandle *handle, const stru } void -notify_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key, +notify_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_HashCode *key, const struct GNUNET_MESSENGER_MemberSession *session, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash) { GNUNET_assert((handle) && (key) && (session) && (message) && (hash)); @@ -563,7 +591,8 @@ notify_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, const struct G } static int -callback_scan_for_rooms (void *cls, const char *filename) +callback_scan_for_rooms (void *cls, + const char *filename) { struct GNUNET_MESSENGER_SrvHandle *handle = cls; @@ -606,7 +635,9 @@ load_handle_configuration (struct GNUNET_MESSENGER_SrvHandle *handle) } static int -iterate_save_rooms (void *cls, const struct GNUNET_HashCode *key, void *value) +iterate_save_rooms (void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_MESSENGER_SrvHandle *handle = cls; struct GNUNET_ShortHashCode *member_id = value; diff --git a/src/messenger/gnunet-service-messenger_handle.h b/src/messenger/gnunet-service-messenger_handle.h index d8ff3aaa8..97a984721 100644 --- a/src/messenger/gnunet-service-messenger_handle.h +++ b/src/messenger/gnunet-service-messenger_handle.h @@ -60,7 +60,8 @@ struct GNUNET_MESSENGER_SrvHandle * @return New handle */ struct GNUNET_MESSENGER_SrvHandle* -create_handle (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MQ_Handle *mq); +create_handle (struct GNUNET_MESSENGER_Service *service, + struct GNUNET_MQ_Handle *mq); /** * Destroys a handle and frees its memory fully. @@ -79,7 +80,9 @@ destroy_handle (struct GNUNET_MESSENGER_SrvHandle *handle); * @param[out] dir Path to store data */ void -get_handle_data_subdir (const struct GNUNET_MESSENGER_SrvHandle *handle, const char *name, char **dir); +get_handle_data_subdir (const struct GNUNET_MESSENGER_SrvHandle *handle, + const char *name, + char **dir); /** * Returns the member id of a given handle in a specific room. @@ -91,7 +94,8 @@ get_handle_data_subdir (const struct GNUNET_MESSENGER_SrvHandle *handle, const c * @return Member id or NULL */ const struct GNUNET_ShortHashCode* -get_handle_member_id (const struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key); +get_handle_member_id (const struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_HashCode *key); /** * Changes the member id of a given handle in a specific room to match a unique_id @@ -105,7 +109,8 @@ get_handle_member_id (const struct GNUNET_MESSENGER_SrvHandle *handle, const str * @return GNUNET_OK on success, otherwise GNUNET_SYSERR */ int -change_handle_member_id (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key, +change_handle_member_id (struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_HashCode *key, const struct GNUNET_ShortHashCode *unique_id); /** @@ -115,7 +120,8 @@ change_handle_member_id (struct GNUNET_MESSENGER_SrvHandle *handle, const struct * @param[in] ego EGO key pair */ void -set_handle_ego (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_MESSENGER_Ego *ego); +set_handle_ego (struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_MESSENGER_Ego *ego); /** * Returns the EGO used by a given handle. @@ -133,7 +139,8 @@ get_handle_ego (const struct GNUNET_MESSENGER_SrvHandle *handle); * @param[in] name Name (optionally: valid EGO name) */ void -setup_handle_name (struct GNUNET_MESSENGER_SrvHandle *handle, const char *name); +setup_handle_name (struct GNUNET_MESSENGER_SrvHandle *handle, + const char *name); /** * Tries to change the key pair of an EGO of a handle under the same name and informs all rooms @@ -154,7 +161,8 @@ update_handle (struct GNUNET_MESSENGER_SrvHandle *handle); * @param[in] name New name */ void -set_handle_name (struct GNUNET_MESSENGER_SrvHandle *handle, const char *name); +set_handle_name (struct GNUNET_MESSENGER_SrvHandle *handle, + const char *name); /** * Makes a given handle a member of the room using a specific key and opens the @@ -165,7 +173,8 @@ set_handle_name (struct GNUNET_MESSENGER_SrvHandle *handle, const char *name); * @return #GNUNET_YES on success, otherwise #GNUNET_NO */ int -open_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key); +open_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_HashCode *key); /** * Makes a given handle a member of the room using a specific key and enters the room @@ -177,7 +186,8 @@ open_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET * @return #GNUNET_YES on success, otherwise #GNUNET_NO */ int -entry_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_PeerIdentity *door, +entry_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key); /** @@ -189,7 +199,8 @@ entry_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNE * @return #GNUNET_YES on success, otherwise #GNUNET_NO */ int -close_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key); +close_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_HashCode *key); /** * Sends a message from a given handle to the room using a specific key. @@ -200,7 +211,8 @@ close_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNE * @return #GNUNET_YES on success, #GNUNET_NO or #GNUNET_SYSERR otherwise. */ int -send_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key, +send_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_HashCode *key, const struct GNUNET_MESSENGER_Message *message); /** @@ -213,9 +225,11 @@ send_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNU * @param[in] hash Hash of message */ void -notify_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key, +notify_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_HashCode *key, const struct GNUNET_MESSENGER_MemberSession *session, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash); /** * Loads member ids and other potential configuration from a given handle which diff --git a/src/messenger/gnunet-service-messenger_list_handles.c b/src/messenger/gnunet-service-messenger_list_handles.c index adcbf6a42..c0ae18716 100644 --- a/src/messenger/gnunet-service-messenger_list_handles.c +++ b/src/messenger/gnunet-service-messenger_list_handles.c @@ -55,7 +55,8 @@ clear_list_handles (struct GNUNET_MESSENGER_ListHandles *handles) } void -add_list_handle (struct GNUNET_MESSENGER_ListHandles *handles, struct GNUNET_MESSENGER_SrvHandle *handle) +add_list_handle (struct GNUNET_MESSENGER_ListHandles *handles, + struct GNUNET_MESSENGER_SrvHandle *handle) { GNUNET_assert((handles) && (handle)); @@ -67,7 +68,8 @@ add_list_handle (struct GNUNET_MESSENGER_ListHandles *handles, struct GNUNET_MES } int -remove_list_handle (struct GNUNET_MESSENGER_ListHandles *handles, struct GNUNET_MESSENGER_SrvHandle *handle) +remove_list_handle (struct GNUNET_MESSENGER_ListHandles *handles, + struct GNUNET_MESSENGER_SrvHandle *handle) { GNUNET_assert((handles) && (handle)); @@ -87,7 +89,8 @@ remove_list_handle (struct GNUNET_MESSENGER_ListHandles *handles, struct GNUNET_ } struct GNUNET_MESSENGER_SrvHandle* -find_list_handle_by_member (const struct GNUNET_MESSENGER_ListHandles *handles, const struct GNUNET_HashCode *key) +find_list_handle_by_member (const struct GNUNET_MESSENGER_ListHandles *handles, + const struct GNUNET_HashCode *key) { GNUNET_assert((handles) && (key)); diff --git a/src/messenger/gnunet-service-messenger_list_handles.h b/src/messenger/gnunet-service-messenger_list_handles.h index 9f7ca725f..f4d7ca5c0 100644 --- a/src/messenger/gnunet-service-messenger_list_handles.h +++ b/src/messenger/gnunet-service-messenger_list_handles.h @@ -69,7 +69,8 @@ clear_list_handles (struct GNUNET_MESSENGER_ListHandles *handles); * @param[in/out] handle Handle */ void -add_list_handle (struct GNUNET_MESSENGER_ListHandles *handles, struct GNUNET_MESSENGER_SrvHandle *handle); +add_list_handle (struct GNUNET_MESSENGER_ListHandles *handles, + struct GNUNET_MESSENGER_SrvHandle *handle); /** * Removes the first entry matching with a specific handle from the list of @@ -80,7 +81,8 @@ add_list_handle (struct GNUNET_MESSENGER_ListHandles *handles, struct GNUNET_MES * @return #GNUNET_YES on success, otherwise #GNUNET_NO */ int -remove_list_handle (struct GNUNET_MESSENGER_ListHandles *handles, struct GNUNET_MESSENGER_SrvHandle *handle); +remove_list_handle (struct GNUNET_MESSENGER_ListHandles *handles, + struct GNUNET_MESSENGER_SrvHandle *handle); /** * Searches linearly through the list of handles for members of a specific room @@ -93,6 +95,7 @@ remove_list_handle (struct GNUNET_MESSENGER_ListHandles *handles, struct GNUNET_ * @return First handle which is a current member */ struct GNUNET_MESSENGER_SrvHandle* -find_list_handle_by_member (const struct GNUNET_MESSENGER_ListHandles *handles, const struct GNUNET_HashCode *key); +find_list_handle_by_member (const struct GNUNET_MESSENGER_ListHandles *handles, + const struct GNUNET_HashCode *key); #endif //GNUNET_SERVICE_MESSENGER_LIST_HANDLES_H diff --git a/src/messenger/gnunet-service-messenger_list_messages.c b/src/messenger/gnunet-service-messenger_list_messages.c index 2666ccdab..7092dc76f 100644 --- a/src/messenger/gnunet-service-messenger_list_messages.c +++ b/src/messenger/gnunet-service-messenger_list_messages.c @@ -52,7 +52,8 @@ clear_list_messages (struct GNUNET_MESSENGER_ListMessages *messages) } void -add_to_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, const struct GNUNET_HashCode *hash) +add_to_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, + const struct GNUNET_HashCode *hash) { GNUNET_assert((messages) && (hash)); @@ -64,7 +65,8 @@ add_to_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, const stru } void -copy_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, const struct GNUNET_MESSENGER_ListMessages *origin) +copy_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, + const struct GNUNET_MESSENGER_ListMessages *origin) { GNUNET_assert((messages) && (origin)); @@ -75,7 +77,8 @@ copy_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, const struct } void -remove_from_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, const struct GNUNET_HashCode *hash) +remove_from_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, + const struct GNUNET_HashCode *hash) { GNUNET_assert((messages) && (hash)); @@ -91,7 +94,8 @@ remove_from_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, const } void -load_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, const char *path) +load_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, + const char *path) { GNUNET_assert((messages) && (path)); @@ -125,7 +129,8 @@ load_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, const char * } void -save_list_messages (const struct GNUNET_MESSENGER_ListMessages *messages, const char *path) +save_list_messages (const struct GNUNET_MESSENGER_ListMessages *messages, + const char *path) { GNUNET_assert((messages) && (path)); diff --git a/src/messenger/gnunet-service-messenger_list_messages.h b/src/messenger/gnunet-service-messenger_list_messages.h index 93ec203ea..7abc8c00f 100644 --- a/src/messenger/gnunet-service-messenger_list_messages.h +++ b/src/messenger/gnunet-service-messenger_list_messages.h @@ -68,7 +68,8 @@ clear_list_messages (struct GNUNET_MESSENGER_ListMessages *messages); * @param[in] hash Hash of message */ void -add_to_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, const struct GNUNET_HashCode *hash); +add_to_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, + const struct GNUNET_HashCode *hash); /** * Copies all message hashes from an origin to another list. @@ -77,7 +78,8 @@ add_to_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, const stru * @param[in] origin Source list of hashes */ void -copy_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, const struct GNUNET_MESSENGER_ListMessages *origin); +copy_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, + const struct GNUNET_MESSENGER_ListMessages *origin); /** * Removes the first entry with a matching hash from the list. @@ -86,7 +88,8 @@ copy_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, const struct * @param[in] hash Hash of message */ void -remove_from_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, const struct GNUNET_HashCode *hash); +remove_from_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, + const struct GNUNET_HashCode *hash); /** * Loads the list of message hashes from a file under a given path. @@ -95,7 +98,8 @@ remove_from_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, const * @param[in] path Path of file */ void -load_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, const char *path); +load_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, + const char *path); /** * Saves the list of message hashes to a file under a given path. @@ -104,6 +108,7 @@ load_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, const char * * @param[in] path Path of file */ void -save_list_messages (const struct GNUNET_MESSENGER_ListMessages *messages, const char *path); +save_list_messages (const struct GNUNET_MESSENGER_ListMessages *messages, + const char *path); #endif //GNUNET_SERVICE_MESSENGER_LIST_MESSAGES_H diff --git a/src/messenger/gnunet-service-messenger_member.c b/src/messenger/gnunet-service-messenger_member.c index b0a735dbe..def57aef9 100644 --- a/src/messenger/gnunet-service-messenger_member.c +++ b/src/messenger/gnunet-service-messenger_member.c @@ -28,7 +28,8 @@ #include "gnunet-service-messenger_member_session.h" struct GNUNET_MESSENGER_Member* -create_member (struct GNUNET_MESSENGER_MemberStore *store, const struct GNUNET_ShortHashCode *id) +create_member (struct GNUNET_MESSENGER_MemberStore *store, + const struct GNUNET_ShortHashCode *id) { GNUNET_assert (store); @@ -50,7 +51,9 @@ create_member (struct GNUNET_MESSENGER_MemberStore *store, const struct GNUNET_S } static int -iterate_destroy_session (void *cls, const struct GNUNET_HashCode *key, void *value) +iterate_destroy_session (void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_MESSENGER_MemberSession *session = value; destroy_member_session(session); @@ -77,7 +80,8 @@ get_member_id (const struct GNUNET_MESSENGER_Member *member) } static int -callback_scan_for_sessions (void *cls, const char *filename) +callback_scan_for_sessions (void *cls, + const char *filename) { struct GNUNET_MESSENGER_Member *member = cls; @@ -95,7 +99,8 @@ callback_scan_for_sessions (void *cls, const char *filename) } void -load_member (struct GNUNET_MESSENGER_MemberStore *store, const char *directory) +load_member (struct GNUNET_MESSENGER_MemberStore *store, + const char *directory) { GNUNET_assert ((store) && (directory)); @@ -139,7 +144,9 @@ free_config: } static int -iterate_load_next_session (void *cls, const struct GNUNET_HashCode *key, void *value) +iterate_load_next_session (void *cls, + const struct GNUNET_HashCode *key, + void *value) { const char* sessions_directory = cls; @@ -156,7 +163,8 @@ iterate_load_next_session (void *cls, const struct GNUNET_HashCode *key, void *v } void -load_member_next_sessions (const struct GNUNET_MESSENGER_Member *member, const char *directory) +load_member_next_sessions (const struct GNUNET_MESSENGER_Member *member, + const char *directory) { GNUNET_assert ((member) && (directory)); @@ -169,7 +177,9 @@ load_member_next_sessions (const struct GNUNET_MESSENGER_Member *member, const c } static int -iterate_save_session (void *cls, const struct GNUNET_HashCode *key, void *value) +iterate_save_session (void *cls, + const struct GNUNET_HashCode *key, + void *value) { const char* sessions_directory = cls; @@ -187,7 +197,8 @@ iterate_save_session (void *cls, const struct GNUNET_HashCode *key, void *value) } void -save_member (struct GNUNET_MESSENGER_Member *member, const char *directory) +save_member (struct GNUNET_MESSENGER_Member *member, + const char *directory) { GNUNET_assert ((member) && (directory)); @@ -221,7 +232,8 @@ save_member (struct GNUNET_MESSENGER_Member *member, const char *directory) } static void -sync_session_contact_from_next (struct GNUNET_MESSENGER_MemberSession *session, struct GNUNET_MESSENGER_MemberSession *next) +sync_session_contact_from_next (struct GNUNET_MESSENGER_MemberSession *session, + struct GNUNET_MESSENGER_MemberSession *next) { GNUNET_assert((session) && (next)); @@ -235,7 +247,9 @@ sync_session_contact_from_next (struct GNUNET_MESSENGER_MemberSession *session, } static int -iterate_sync_session_contact (void *cls, const struct GNUNET_HashCode *key, void *value) +iterate_sync_session_contact (void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_MESSENGER_MemberSession *session = value; @@ -254,7 +268,8 @@ sync_member_contacts (struct GNUNET_MESSENGER_Member *member) } struct GNUNET_MESSENGER_MemberSession* -get_member_session (const struct GNUNET_MESSENGER_Member *member, const struct GNUNET_IDENTITY_PublicKey *public_key) +get_member_session (const struct GNUNET_MESSENGER_Member *member, + const struct GNUNET_IDENTITY_PublicKey *public_key) { GNUNET_assert ((member) && (public_key)); @@ -272,7 +287,9 @@ struct GNUNET_MESSENGER_ClosureSearchSession { }; static int -iterate_search_session (void *cls, const struct GNUNET_HashCode *key, void *value) +iterate_search_session (void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_MESSENGER_ClosureSearchSession* search = cls; struct GNUNET_MESSENGER_MemberSession *session = value; @@ -285,7 +302,8 @@ iterate_search_session (void *cls, const struct GNUNET_HashCode *key, void *valu } static struct GNUNET_MESSENGER_MemberSession* -try_member_session (struct GNUNET_MESSENGER_Member *member, const struct GNUNET_IDENTITY_PublicKey *public_key) +try_member_session (struct GNUNET_MESSENGER_Member *member, + const struct GNUNET_IDENTITY_PublicKey *public_key) { struct GNUNET_MESSENGER_MemberSession* session = get_member_session(member, public_key); @@ -301,7 +319,8 @@ try_member_session (struct GNUNET_MESSENGER_Member *member, const struct GNUNET_ } struct GNUNET_MESSENGER_MemberSession* -get_member_session_of (struct GNUNET_MESSENGER_Member *member, const struct GNUNET_MESSENGER_Message *message, +get_member_session_of (struct GNUNET_MESSENGER_Member *member, + const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) { GNUNET_assert ((member) && (message) && (hash) && @@ -324,7 +343,8 @@ get_member_session_of (struct GNUNET_MESSENGER_Member *member, const struct GNUN } void -add_member_session (struct GNUNET_MESSENGER_Member *member, struct GNUNET_MESSENGER_MemberSession *session) +add_member_session (struct GNUNET_MESSENGER_Member *member, + struct GNUNET_MESSENGER_MemberSession *session) { if (!session) return; @@ -344,7 +364,8 @@ add_member_session (struct GNUNET_MESSENGER_Member *member, struct GNUNET_MESSEN } void -remove_member_session (struct GNUNET_MESSENGER_Member *member, struct GNUNET_MESSENGER_MemberSession *session) +remove_member_session (struct GNUNET_MESSENGER_Member *member, + struct GNUNET_MESSENGER_MemberSession *session) { GNUNET_assert ((member) && (session) && (session->member == member)); @@ -364,7 +385,9 @@ struct GNUNET_MESSENGER_ClosureIterateSessions { }; static int -iterate_member_sessions_it (void *cls, const struct GNUNET_HashCode *key, void *value) +iterate_member_sessions_it (void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_MESSENGER_ClosureIterateSessions *iterate = cls; struct GNUNET_MESSENGER_MemberSession *session = value; @@ -373,7 +396,9 @@ iterate_member_sessions_it (void *cls, const struct GNUNET_HashCode *key, void * } int -iterate_member_sessions (struct GNUNET_MESSENGER_Member *member, GNUNET_MESSENGER_MemberIteratorCallback it, void *cls) +iterate_member_sessions (struct GNUNET_MESSENGER_Member *member, + GNUNET_MESSENGER_MemberIteratorCallback it, + void *cls) { GNUNET_assert ((member) && (member->sessions) && (it)); diff --git a/src/messenger/gnunet-service-messenger_member.h b/src/messenger/gnunet-service-messenger_member.h index fb2e57cfb..46269315a 100644 --- a/src/messenger/gnunet-service-messenger_member.h +++ b/src/messenger/gnunet-service-messenger_member.h @@ -52,7 +52,8 @@ struct GNUNET_MESSENGER_Member * @return New member or NULL */ struct GNUNET_MESSENGER_Member* -create_member (struct GNUNET_MESSENGER_MemberStore *store, const struct GNUNET_ShortHashCode *id); +create_member (struct GNUNET_MESSENGER_MemberStore *store, + const struct GNUNET_ShortHashCode *id); /** * Destroys a member and frees its memory fully. @@ -80,7 +81,8 @@ get_member_id (const struct GNUNET_MESSENGER_Member *member); * @param[in] directory Path to a directory */ void -load_member (struct GNUNET_MESSENGER_MemberStore *store, const char *directory); +load_member (struct GNUNET_MESSENGER_MemberStore *store, + const char *directory); /** * Loads data about next sessions from a directory into an empty loaded @@ -90,7 +92,8 @@ load_member (struct GNUNET_MESSENGER_MemberStore *store, const char *directory); * @param[in] directory Path to a directory */ void -load_member_next_sessions (const struct GNUNET_MESSENGER_Member *member, const char *directory); +load_member_next_sessions (const struct GNUNET_MESSENGER_Member *member, + const char *directory); /** * Saves data from a member into a directory which @@ -100,7 +103,8 @@ load_member_next_sessions (const struct GNUNET_MESSENGER_Member *member, const c * @param[in] directory Path to a directory */ void -save_member (struct GNUNET_MESSENGER_Member *member, const char *directory); +save_member (struct GNUNET_MESSENGER_Member *member, + const char *directory); /** * Synchronizes contacts between all sessions from a given member @@ -120,7 +124,8 @@ sync_member_contacts (struct GNUNET_MESSENGER_Member *member); * @return Member session */ struct GNUNET_MESSENGER_MemberSession* -get_member_session (const struct GNUNET_MESSENGER_Member *member, const struct GNUNET_IDENTITY_PublicKey *public_key); +get_member_session (const struct GNUNET_MESSENGER_Member *member, + const struct GNUNET_IDENTITY_PublicKey *public_key); /** * Returns the member session of a member using a public key which can verify @@ -133,7 +138,8 @@ get_member_session (const struct GNUNET_MESSENGER_Member *member, const struct G * @return Member session */ struct GNUNET_MESSENGER_MemberSession* -get_member_session_of (struct GNUNET_MESSENGER_Member *member, const struct GNUNET_MESSENGER_Message *message, +get_member_session_of (struct GNUNET_MESSENGER_Member *member, + const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); /** @@ -143,7 +149,8 @@ get_member_session_of (struct GNUNET_MESSENGER_Member *member, const struct GNUN * @param[in/out] session Member session */ void -add_member_session (struct GNUNET_MESSENGER_Member *member, struct GNUNET_MESSENGER_MemberSession *session); +add_member_session (struct GNUNET_MESSENGER_Member *member, + struct GNUNET_MESSENGER_MemberSession *session); /** * Removes a given member session from its member. @@ -152,7 +159,8 @@ add_member_session (struct GNUNET_MESSENGER_Member *member, struct GNUNET_MESSEN * @param[in/out] session Member session */ void -remove_member_session (struct GNUNET_MESSENGER_Member *member, struct GNUNET_MESSENGER_MemberSession *session); +remove_member_session (struct GNUNET_MESSENGER_Member *member, + struct GNUNET_MESSENGER_MemberSession *session); /** * Iterate through all member sessions currently connected to a given member @@ -165,6 +173,8 @@ remove_member_session (struct GNUNET_MESSENGER_Member *member, struct GNUNET_MES * @return Amount of sessions iterated through */ int -iterate_member_sessions (struct GNUNET_MESSENGER_Member *member, GNUNET_MESSENGER_MemberIteratorCallback it, void* cls); +iterate_member_sessions (struct GNUNET_MESSENGER_Member *member, + GNUNET_MESSENGER_MemberIteratorCallback it, + void* cls); #endif //GNUNET_SERVICE_MESSENGER_MEMBER_H diff --git a/src/messenger/gnunet-service-messenger_member_session.c b/src/messenger/gnunet-service-messenger_member_session.c index 690c703b2..03736941f 100644 --- a/src/messenger/gnunet-service-messenger_member_session.c +++ b/src/messenger/gnunet-service-messenger_member_session.c @@ -158,7 +158,9 @@ completion: } static int -iterate_copy_history (void *cls, const struct GNUNET_HashCode *key, void *value) +iterate_copy_history (void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_MESSENGER_MemberSession *next = cls; @@ -460,7 +462,8 @@ struct GNUNET_MESSENGER_MemberSessionHistoryEntry }; static void -load_member_session_history (struct GNUNET_MESSENGER_MemberSession *session, const char *path) +load_member_session_history (struct GNUNET_MESSENGER_MemberSession *session, + const char *path) { GNUNET_assert((session) && (path)); @@ -502,7 +505,8 @@ load_member_session_history (struct GNUNET_MESSENGER_MemberSession *session, con } void -load_member_session (struct GNUNET_MESSENGER_Member *member, const char *directory) +load_member_session (struct GNUNET_MESSENGER_Member *member, + const char *directory) { GNUNET_assert ((member) && (directory)); @@ -571,7 +575,8 @@ free_config: } static struct GNUNET_MESSENGER_MemberSession* -get_cycle_safe_next_session (struct GNUNET_MESSENGER_MemberSession *session, struct GNUNET_MESSENGER_MemberSession *next) +get_cycle_safe_next_session (struct GNUNET_MESSENGER_MemberSession *session, + struct GNUNET_MESSENGER_MemberSession *next) { if (!next) return NULL; @@ -589,7 +594,8 @@ get_cycle_safe_next_session (struct GNUNET_MESSENGER_MemberSession *session, str } void -load_member_session_next (struct GNUNET_MESSENGER_MemberSession *session, const char *directory) +load_member_session_next (struct GNUNET_MESSENGER_MemberSession *session, + const char *directory) { GNUNET_assert ((session) && (directory)); @@ -640,7 +646,9 @@ free_config: } static int -iterate_save_member_session_history_hentries (void *cls, const struct GNUNET_HashCode *key, void *value) +iterate_save_member_session_history_hentries (void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_DISK_FileHandle *handle = cls; unsigned char ownership = value? GNUNET_YES : GNUNET_NO; @@ -652,7 +660,8 @@ iterate_save_member_session_history_hentries (void *cls, const struct GNUNET_Has } static void -save_member_session_history (struct GNUNET_MESSENGER_MemberSession *session, const char *path) +save_member_session_history (struct GNUNET_MESSENGER_MemberSession *session, + const char *path) { GNUNET_assert((session) && (path)); @@ -678,7 +687,8 @@ save_member_session_history (struct GNUNET_MESSENGER_MemberSession *session, con } void -save_member_session (struct GNUNET_MESSENGER_MemberSession *session, const char *directory) +save_member_session (struct GNUNET_MESSENGER_MemberSession *session, + const char *directory) { GNUNET_assert ((session) && (directory)); diff --git a/src/messenger/gnunet-service-messenger_member_session.h b/src/messenger/gnunet-service-messenger_member_session.h index bf4d10f67..9ba801776 100644 --- a/src/messenger/gnunet-service-messenger_member_session.h +++ b/src/messenger/gnunet-service-messenger_member_session.h @@ -225,7 +225,8 @@ verify_member_session_as_sender (const struct GNUNET_MESSENGER_MemberSession *se */ int check_member_session_history (const struct GNUNET_MESSENGER_MemberSession *session, - const struct GNUNET_HashCode *hash, int ownership); + const struct GNUNET_HashCode *hash, + int ownership); /** * Adds a given message to the history of a session using the messages @@ -262,7 +263,8 @@ clear_member_session_history (struct GNUNET_MESSENGER_MemberSession *session, * @param[in] directory Path to a directory */ void -load_member_session (struct GNUNET_MESSENGER_Member *member, const char *directory); +load_member_session (struct GNUNET_MESSENGER_Member *member, + const char *directory); /** * Loads the connection from one session to another through the @@ -273,7 +275,8 @@ load_member_session (struct GNUNET_MESSENGER_Member *member, const char *directo * @param[in] directory Path to a directory */ void -load_member_session_next (struct GNUNET_MESSENGER_MemberSession *session, const char *directory); +load_member_session_next (struct GNUNET_MESSENGER_MemberSession *session, + const char *directory); /** * Saves data from a member session into a directory which can be @@ -283,6 +286,7 @@ load_member_session_next (struct GNUNET_MESSENGER_MemberSession *session, const * @param[in] directory Path to a directory */ void -save_member_session (struct GNUNET_MESSENGER_MemberSession *session, const char *directory); +save_member_session (struct GNUNET_MESSENGER_MemberSession *session, + const char *directory); #endif //GNUNET_SERVICE_MESSENGER_MEMBER_SESSION_H diff --git a/src/messenger/gnunet-service-messenger_member_store.c b/src/messenger/gnunet-service-messenger_member_store.c index 2925965d4..e96ee3883 100644 --- a/src/messenger/gnunet-service-messenger_member_store.c +++ b/src/messenger/gnunet-service-messenger_member_store.c @@ -30,7 +30,8 @@ #include "gnunet-service-messenger_room.h" void -init_member_store (struct GNUNET_MESSENGER_MemberStore *store, struct GNUNET_MESSENGER_SrvRoom *room) +init_member_store (struct GNUNET_MESSENGER_MemberStore *store, + struct GNUNET_MESSENGER_SrvRoom *room) { GNUNET_assert ((store) && (room)); @@ -39,7 +40,9 @@ init_member_store (struct GNUNET_MESSENGER_MemberStore *store, struct GNUNET_MES } static int -iterate_destroy_members (void *cls, const struct GNUNET_ShortHashCode *key, void *value) +iterate_destroy_members (void *cls, + const struct GNUNET_ShortHashCode *key, + void *value) { struct GNUNET_MESSENGER_Member *member = value; destroy_member(member); @@ -75,7 +78,8 @@ get_member_store_key (const struct GNUNET_MESSENGER_MemberStore *store) } static int -callback_scan_for_members (void *cls, const char *filename) +callback_scan_for_members (void *cls, + const char *filename) { struct GNUNET_MESSENGER_MemberStore *store = cls; @@ -94,7 +98,9 @@ callback_scan_for_members (void *cls, const char *filename) } static int -iterate_load_next_member_sessions (void *cls, const struct GNUNET_ShortHashCode *id, void *value) +iterate_load_next_member_sessions (void *cls, + const struct GNUNET_ShortHashCode *id, + void *value) { const char *sync_dir = cls; @@ -114,7 +120,9 @@ iterate_load_next_member_sessions (void *cls, const struct GNUNET_ShortHashCode } static int -iterate_sync_member_contacts (void *cls, const struct GNUNET_ShortHashCode *id, void *value) +iterate_sync_member_contacts (void *cls, + const struct GNUNET_ShortHashCode *id, + void *value) { struct GNUNET_MESSENGER_Member *member = value; @@ -126,7 +134,8 @@ iterate_sync_member_contacts (void *cls, const struct GNUNET_ShortHashCode *id, } void -load_member_store (struct GNUNET_MESSENGER_MemberStore *store, const char *directory) +load_member_store (struct GNUNET_MESSENGER_MemberStore *store, + const char *directory) { GNUNET_assert ((store) && (directory)); @@ -143,7 +152,9 @@ load_member_store (struct GNUNET_MESSENGER_MemberStore *store, const char *direc } static int -iterate_save_members (void *cls, const struct GNUNET_ShortHashCode *id, void *value) +iterate_save_members (void *cls, + const struct GNUNET_ShortHashCode *id, + void *value) { const char *save_dir = cls; @@ -164,7 +175,8 @@ iterate_save_members (void *cls, const struct GNUNET_ShortHashCode *id, void *va } void -save_member_store (struct GNUNET_MESSENGER_MemberStore *store, const char *directory) +save_member_store (struct GNUNET_MESSENGER_MemberStore *store, + const char *directory) { GNUNET_assert ((store) && (directory)); @@ -179,7 +191,8 @@ save_member_store (struct GNUNET_MESSENGER_MemberStore *store, const char *direc } struct GNUNET_MESSENGER_Member* -get_store_member (const struct GNUNET_MESSENGER_MemberStore *store, const struct GNUNET_ShortHashCode *id) +get_store_member (const struct GNUNET_MESSENGER_MemberStore *store, + const struct GNUNET_ShortHashCode *id) { GNUNET_assert ((store) && (store->members) && (id)); @@ -187,7 +200,8 @@ get_store_member (const struct GNUNET_MESSENGER_MemberStore *store, const struct } struct GNUNET_MESSENGER_Member* -get_store_member_of (struct GNUNET_MESSENGER_MemberStore *store, const struct GNUNET_MESSENGER_Message *message) +get_store_member_of (struct GNUNET_MESSENGER_MemberStore *store, + const struct GNUNET_MESSENGER_Message *message) { if ((GNUNET_MESSENGER_KIND_INFO == message->header.kind) || (GNUNET_MESSENGER_KIND_JOIN == message->header.kind)) @@ -197,7 +211,8 @@ get_store_member_of (struct GNUNET_MESSENGER_MemberStore *store, const struct GN } struct GNUNET_MESSENGER_Member* -add_store_member (struct GNUNET_MESSENGER_MemberStore *store, const struct GNUNET_ShortHashCode *id) +add_store_member (struct GNUNET_MESSENGER_MemberStore *store, + const struct GNUNET_ShortHashCode *id) { GNUNET_assert ((store) && (store->members)); @@ -227,7 +242,9 @@ struct GNUNET_MESSENGER_ClosureIterateMembers { }; static int -iterate_store_members_it (void *cls, const struct GNUNET_ShortHashCode *key, void *value) +iterate_store_members_it (void *cls, + const struct GNUNET_ShortHashCode *key, + void *value) { struct GNUNET_MESSENGER_ClosureIterateMembers *iterate = cls; struct GNUNET_MESSENGER_Member *member = value; @@ -236,7 +253,8 @@ iterate_store_members_it (void *cls, const struct GNUNET_ShortHashCode *key, voi } int -iterate_store_members (struct GNUNET_MESSENGER_MemberStore *store, GNUNET_MESSENGER_MemberIteratorCallback it, +iterate_store_members (struct GNUNET_MESSENGER_MemberStore *store, + GNUNET_MESSENGER_MemberIteratorCallback it, void* cls) { GNUNET_assert ((store) && (store->members) && (it)); diff --git a/src/messenger/gnunet-service-messenger_member_store.h b/src/messenger/gnunet-service-messenger_member_store.h index 859e4683d..af50f0d36 100644 --- a/src/messenger/gnunet-service-messenger_member_store.h +++ b/src/messenger/gnunet-service-messenger_member_store.h @@ -56,7 +56,8 @@ typedef int (*GNUNET_MESSENGER_MemberIteratorCallback) ( * @param room Room */ void -init_member_store (struct GNUNET_MESSENGER_MemberStore *store, struct GNUNET_MESSENGER_SrvRoom *room); +init_member_store (struct GNUNET_MESSENGER_MemberStore *store, + struct GNUNET_MESSENGER_SrvRoom *room); /** * Clears a member store, wipes its content and deallocates its memory. @@ -91,7 +92,8 @@ get_member_store_key (const struct GNUNET_MESSENGER_MemberStore *store); * @param[in] directory Path to a directory */ void -load_member_store (struct GNUNET_MESSENGER_MemberStore *store, const char *directory); +load_member_store (struct GNUNET_MESSENGER_MemberStore *store, + const char *directory); /** * Saves members from a member store into a directory. @@ -100,7 +102,8 @@ load_member_store (struct GNUNET_MESSENGER_MemberStore *store, const char *direc * @param[in] directory Path to a directory */ void -save_member_store (struct GNUNET_MESSENGER_MemberStore *store, const char *directory); +save_member_store (struct GNUNET_MESSENGER_MemberStore *store, + const char *directory); /** * Returns the member in a store identified by a given id. If the store @@ -111,7 +114,8 @@ save_member_store (struct GNUNET_MESSENGER_MemberStore *store, const char *direc * @return Member or NULL */ struct GNUNET_MESSENGER_Member* -get_store_member (const struct GNUNET_MESSENGER_MemberStore *store, const struct GNUNET_ShortHashCode *id); +get_store_member (const struct GNUNET_MESSENGER_MemberStore *store, + const struct GNUNET_ShortHashCode *id); /** * Returns the member of a store using a sender id of a given message. @@ -122,7 +126,8 @@ get_store_member (const struct GNUNET_MESSENGER_MemberStore *store, const struct * @return Member or NULL */ struct GNUNET_MESSENGER_Member* -get_store_member_of (struct GNUNET_MESSENGER_MemberStore *store, const struct GNUNET_MESSENGER_Message *message); +get_store_member_of (struct GNUNET_MESSENGER_MemberStore *store, + const struct GNUNET_MESSENGER_Message *message); /** * Adds a member to a store under a specific id and returns it on success. @@ -132,7 +137,8 @@ get_store_member_of (struct GNUNET_MESSENGER_MemberStore *store, const struct GN * @return Member or NULL */ struct GNUNET_MESSENGER_Member* -add_store_member (struct GNUNET_MESSENGER_MemberStore *store, const struct GNUNET_ShortHashCode *id); +add_store_member (struct GNUNET_MESSENGER_MemberStore *store, + const struct GNUNET_ShortHashCode *id); /** * Iterate through all member sessions currently connected to the members of the given @@ -145,7 +151,8 @@ add_store_member (struct GNUNET_MESSENGER_MemberStore *store, const struct GNUNE * @return Amount of members iterated through */ int -iterate_store_members (struct GNUNET_MESSENGER_MemberStore *store, GNUNET_MESSENGER_MemberIteratorCallback it, +iterate_store_members (struct GNUNET_MESSENGER_MemberStore *store, + GNUNET_MESSENGER_MemberIteratorCallback it, void* cls); #endif //GNUNET_SERVICE_MESSENGER_MEMBER_STORE_H diff --git a/src/messenger/gnunet-service-messenger_message_handle.c b/src/messenger/gnunet-service-messenger_message_handle.c index 86f2b901a..701d78c89 100644 --- a/src/messenger/gnunet-service-messenger_message_handle.c +++ b/src/messenger/gnunet-service-messenger_message_handle.c @@ -27,7 +27,8 @@ static void handle_session_switch (struct GNUNET_MESSENGER_MemberSession *session, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash) { struct GNUNET_MESSENGER_MemberSession *next = switch_member_session(session, message, hash); @@ -36,8 +37,10 @@ handle_session_switch (struct GNUNET_MESSENGER_MemberSession *session, } void -handle_message_join (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) +handle_message_join (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_MemberSession *session, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash) { GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Member (%s) joins room (%s).\n", GNUNET_sh2s (&(message->header.sender_id)), GNUNET_h2s(get_room_key(room))); @@ -54,8 +57,10 @@ handle_message_join (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSEN } void -handle_message_leave (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) +handle_message_leave (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_MemberSession *session, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash) { GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Member (%s) leaves room (%s).\n", GNUNET_sh2s (&(message->header.sender_id)), GNUNET_h2s(get_room_key(room))); @@ -64,8 +69,10 @@ handle_message_leave (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSE } void -handle_message_name (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) +handle_message_name (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_MemberSession *session, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash) { struct GNUNET_MESSENGER_Contact *contact = get_member_session_contact(session); @@ -76,15 +83,19 @@ handle_message_name (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSEN } void -handle_message_key (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) +handle_message_key (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_MemberSession *session, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash) { handle_session_switch (session, message, hash); } void -handle_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) +handle_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_MemberSession *session, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash) { if (GNUNET_NO == contains_list_tunnels (&(room->basement), &(message->body.peer.peer))) add_to_list_tunnels (&(room->basement), &(message->body.peer.peer)); @@ -94,8 +105,10 @@ handle_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSEN } void -handle_message_id (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) +handle_message_id (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_MemberSession *session, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash) { handle_session_switch (session, message, hash); @@ -108,8 +121,10 @@ handle_message_id (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGE } void -handle_message_miss (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) +handle_message_miss (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_MemberSession *session, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash) { struct GNUNET_MESSENGER_ListTunnel *element = find_list_tunnels (&(room->basement), &(message->body.peer.peer), NULL); @@ -123,8 +138,10 @@ handle_message_miss (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSEN } void -handle_message_delete (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) +handle_message_delete (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_MemberSession *session, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash) { struct GNUNET_TIME_Relative delay = GNUNET_TIME_relative_ntoh (message->body.deletion.delay); struct GNUNET_TIME_Absolute action = GNUNET_TIME_absolute_ntoh (message->header.timestamp); diff --git a/src/messenger/gnunet-service-messenger_message_handle.h b/src/messenger/gnunet-service-messenger_message_handle.h index 844142b77..0e5be3408 100644 --- a/src/messenger/gnunet-service-messenger_message_handle.h +++ b/src/messenger/gnunet-service-messenger_message_handle.h @@ -45,8 +45,10 @@ * @param[in] hash Hash of the message */ void -handle_message_join (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); +handle_message_join (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_MemberSession *session, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash); /** * Handles a received or sent leave message to make changes of current member information. @@ -58,8 +60,10 @@ handle_message_join (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSEN * @param[in] hash Hash of the message */ void -handle_message_leave (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); +handle_message_leave (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_MemberSession *session, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash); /** * Handles a received or sent name message to rename a current member. @@ -71,8 +75,10 @@ handle_message_leave (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSE * @param[in] hash Hash of the message */ void -handle_message_name (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); +handle_message_name (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_MemberSession *session, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash); /** * Handles a received or sent key message to change the key of a member and rearrange the contacts accordingly. @@ -84,8 +90,10 @@ handle_message_name (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSEN * @param[in] hash Hash of the message */ void -handle_message_key (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); +handle_message_key (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_MemberSession *session, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash); /** * Handles a received or sent peer message to make changes of the basement in the room. @@ -97,8 +105,10 @@ handle_message_key (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENG * @param[in] hash Hash of the message */ void -handle_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); +handle_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_MemberSession *session, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash); /** * Handles a received or sent id message to change a members id. @@ -110,8 +120,10 @@ handle_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSEN * @param[in] hash Hash of the message */ void -handle_message_id (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); +handle_message_id (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_MemberSession *session, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash); /** * Handles a received or sent miss message to drop a peer from the basement in the room. @@ -123,8 +135,10 @@ handle_message_id (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGE * @param[in] hash Hash of the message */ void -handle_message_miss (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); +handle_message_miss (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_MemberSession *session, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash); /** * Handles a received or sent delete message to delete a specific message from the store. @@ -136,7 +150,9 @@ handle_message_miss (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSEN * @param[in] hash Hash of the message */ void -handle_message_delete (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); +handle_message_delete (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_MemberSession *session, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash); #endif //GNUNET_SERVICE_MESSENGER_MESSAGE_HANDLE_H diff --git a/src/messenger/gnunet-service-messenger_message_kind.c b/src/messenger/gnunet-service-messenger_message_kind.c index 3edcade91..2449b9230 100644 --- a/src/messenger/gnunet-service-messenger_message_kind.c +++ b/src/messenger/gnunet-service-messenger_message_kind.c @@ -190,7 +190,8 @@ create_message_request (const struct GNUNET_HashCode *hash) } struct GNUNET_MESSENGER_Message* -create_message_invite (const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key) +create_message_invite (const struct GNUNET_PeerIdentity *door, + const struct GNUNET_HashCode *key) { if ((!door) || (!key)) return NULL; @@ -222,7 +223,8 @@ create_message_text (const char *text) } struct GNUNET_MESSENGER_Message* -create_message_delete (const struct GNUNET_HashCode *hash, const struct GNUNET_TIME_Relative delay) +create_message_delete (const struct GNUNET_HashCode *hash, + const struct GNUNET_TIME_Relative delay) { if (!hash) return NULL; diff --git a/src/messenger/gnunet-service-messenger_message_kind.h b/src/messenger/gnunet-service-messenger_message_kind.h index c098868c0..508f19074 100644 --- a/src/messenger/gnunet-service-messenger_message_kind.h +++ b/src/messenger/gnunet-service-messenger_message_kind.h @@ -146,7 +146,8 @@ create_message_request (const struct GNUNET_HashCode *hash); * @return New message */ struct GNUNET_MESSENGER_Message* -create_message_invite (const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key); +create_message_invite (const struct GNUNET_PeerIdentity *door, + const struct GNUNET_HashCode *key); /** * Creates and allocates a new text message containing a string representing text. @@ -167,6 +168,7 @@ create_message_text (const char *text); * @return New message */ struct GNUNET_MESSENGER_Message* -create_message_delete (const struct GNUNET_HashCode *hash, const struct GNUNET_TIME_Relative delay); +create_message_delete (const struct GNUNET_HashCode *hash, + const struct GNUNET_TIME_Relative delay); #endif //GNUNET_SERVICE_MESSENGER_MESSAGE_KIND_H diff --git a/src/messenger/gnunet-service-messenger_message_recv.c b/src/messenger/gnunet-service-messenger_message_recv.c index b2a5052d2..bb6ee6f17 100644 --- a/src/messenger/gnunet-service-messenger_message_recv.c +++ b/src/messenger/gnunet-service-messenger_message_recv.c @@ -28,8 +28,10 @@ #include "gnunet-service-messenger_operation.h" static void -forward_about_members (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, - struct GNUNET_MESSENGER_MemberSession *session, struct GNUNET_CONTAINER_MultiHashMap *map) +forward_about_members (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvTunnel *tunnel, + struct GNUNET_MESSENGER_MemberSession *session, + struct GNUNET_CONTAINER_MultiHashMap *map) { if (session->prev) forward_about_members (room, tunnel, session->prev, map); @@ -54,8 +56,9 @@ forward_about_members (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESS } static int -iterate_forward_members (void *cls, const struct GNUNET_IDENTITY_PublicKey *public_key, - struct GNUNET_MESSENGER_MemberSession *session) +iterate_forward_members (void *cls, + const struct GNUNET_IDENTITY_PublicKey *public_key, + struct GNUNET_MESSENGER_MemberSession *session) { struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls; @@ -71,8 +74,10 @@ iterate_forward_members (void *cls, const struct GNUNET_IDENTITY_PublicKey *publ } int -recv_message_info (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) +recv_message_info (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvTunnel *tunnel, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash) { const uint32_t version = get_tunnel_messenger_version(tunnel); @@ -108,8 +113,10 @@ recv_message_info (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGE } int -recv_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) +recv_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvTunnel *tunnel, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash) { struct GNUNET_PeerIdentity peer; GNUNET_PEER_resolve (tunnel->peer, &peer); @@ -126,7 +133,8 @@ recv_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGE } static void -callback_found_message (void *cls, struct GNUNET_MESSENGER_SrvRoom *room, +callback_found_message (void *cls, + struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) { @@ -152,8 +160,10 @@ callback_found_message (void *cls, struct GNUNET_MESSENGER_SrvRoom *room, * It will only be forwarded if it can't be answered! */ int -recv_message_request (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) +recv_message_request (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvTunnel *tunnel, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash) { struct GNUNET_MESSENGER_MemberStore *member_store = get_room_member_store(room); struct GNUNET_MESSENGER_Member *member = get_store_member_of(member_store, message); diff --git a/src/messenger/gnunet-service-messenger_message_recv.h b/src/messenger/gnunet-service-messenger_message_recv.h index 9cb36c466..400c10245 100644 --- a/src/messenger/gnunet-service-messenger_message_recv.h +++ b/src/messenger/gnunet-service-messenger_message_recv.h @@ -46,8 +46,10 @@ * @return #GNUNET_NO to not forward the message */ int -recv_message_info (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); +recv_message_info (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvTunnel *tunnel, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash); /** * Handles a received peer message to link it to its origin tunnel if the peer identity matches. @@ -60,8 +62,10 @@ recv_message_info (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGE * @return #GNUNET_YES to forward the message */ int -recv_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); +recv_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvTunnel *tunnel, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash); /** * Handles a received request message by checking for the requested message and forwarding it back @@ -75,7 +79,9 @@ recv_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGE * @return #GNUNET_YES or #GNUNET_NO depending on required forwarding */ int -recv_message_request (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); +recv_message_request (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvTunnel *tunnel, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash); #endif //GNUNET_SERVICE_MESSENGER_MESSAGE_RECV_H diff --git a/src/messenger/gnunet-service-messenger_message_send.c b/src/messenger/gnunet-service-messenger_message_send.c index a59a178cc..8cc2466d7 100644 --- a/src/messenger/gnunet-service-messenger_message_send.c +++ b/src/messenger/gnunet-service-messenger_message_send.c @@ -30,15 +30,19 @@ #include "gnunet-service-messenger_operation.h" void -send_message_join (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) +send_message_join (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash) { check_room_peer_status(room, NULL); } void -send_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) +send_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash) { if (!room->peer_message) room->peer_message = GNUNET_new(struct GNUNET_HashCode); @@ -47,15 +51,19 @@ send_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGE } void -send_message_id (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) +send_message_id (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash) { change_handle_member_id (handle, get_room_key(room), &(message->body.id.id)); } void -send_message_request (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) +send_message_request (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash) { struct GNUNET_MESSENGER_OperationStore *operation_store = get_room_operation_store(room); diff --git a/src/messenger/gnunet-service-messenger_message_send.h b/src/messenger/gnunet-service-messenger_message_send.h index 63320ab17..232355c41 100644 --- a/src/messenger/gnunet-service-messenger_message_send.h +++ b/src/messenger/gnunet-service-messenger_message_send.h @@ -44,8 +44,10 @@ * @param[in] hash Hash of the message */ void -send_message_join (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); +send_message_join (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash); /** * Handles a sent peer message to update the rooms peer message of this service. @@ -57,8 +59,10 @@ send_message_join (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGE * @param[in] hash Hash of the message */ void -send_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); +send_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash); /** * Handles a sent id message to update the handles member id in the room. @@ -70,8 +74,10 @@ send_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGE * @param[in] hash Hash of the message */ void -send_message_id (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); +send_message_id (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash); /** * Handles a sent request message to trigger the request operation for this service. @@ -83,7 +89,9 @@ send_message_id (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_ * @param[in] hash Hash of the message */ void -send_message_request (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); +send_message_request (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash); #endif //GNUNET_SERVICE_MESSENGER_MESSAGE_SEND_H diff --git a/src/messenger/gnunet-service-messenger_message_state.c b/src/messenger/gnunet-service-messenger_message_state.c index cdd2d9712..344962d11 100644 --- a/src/messenger/gnunet-service-messenger_message_state.c +++ b/src/messenger/gnunet-service-messenger_message_state.c @@ -65,8 +65,10 @@ get_message_state_merge_hash (const struct GNUNET_MESSENGER_MessageState *state) } void -update_message_state (struct GNUNET_MESSENGER_MessageState *state, int requested, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) +update_message_state (struct GNUNET_MESSENGER_MessageState *state, + int requested, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash) { GNUNET_assert((state) && (message) && (hash)); @@ -83,7 +85,8 @@ update_message_state (struct GNUNET_MESSENGER_MessageState *state, int requested } void -load_message_state (struct GNUNET_MESSENGER_MessageState *state, const char *path) +load_message_state (struct GNUNET_MESSENGER_MessageState *state, + const char *path) { GNUNET_assert((state) && (path)); @@ -95,7 +98,8 @@ load_message_state (struct GNUNET_MESSENGER_MessageState *state, const char *pat } void -save_message_state (const struct GNUNET_MESSENGER_MessageState *state, const char *path) +save_message_state (const struct GNUNET_MESSENGER_MessageState *state, + const char *path) { GNUNET_assert((state) && (path)); diff --git a/src/messenger/gnunet-service-messenger_message_state.h b/src/messenger/gnunet-service-messenger_message_state.h index dc8671df4..af52b26b6 100644 --- a/src/messenger/gnunet-service-messenger_message_state.h +++ b/src/messenger/gnunet-service-messenger_message_state.h @@ -51,13 +51,17 @@ const struct GNUNET_HashCode* get_message_state_merge_hash (const struct GNUNET_MESSENGER_MessageState *state); void -update_message_state (struct GNUNET_MESSENGER_MessageState *state, int requested, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); +update_message_state (struct GNUNET_MESSENGER_MessageState *state, + int requested, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash); void -load_message_state (struct GNUNET_MESSENGER_MessageState *state, const char *path); +load_message_state (struct GNUNET_MESSENGER_MessageState *state, + const char *path); void -save_message_state (const struct GNUNET_MESSENGER_MessageState *state, const char *path); +save_message_state (const struct GNUNET_MESSENGER_MessageState *state, + const char *path); #endif //GNUNET_SERVICE_MESSENGER_MESSAGE_STATE_H diff --git a/src/messenger/gnunet-service-messenger_message_store.c b/src/messenger/gnunet-service-messenger_message_store.c index 1984eba21..56448997a 100644 --- a/src/messenger/gnunet-service-messenger_message_store.c +++ b/src/messenger/gnunet-service-messenger_message_store.c @@ -42,7 +42,9 @@ init_message_store (struct GNUNET_MESSENGER_MessageStore *store) } static int -iterate_destroy_entries (void *cls, const struct GNUNET_HashCode *key, void *value) +iterate_destroy_entries (void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_MESSENGER_MessageEntry *entry = value; @@ -52,7 +54,9 @@ iterate_destroy_entries (void *cls, const struct GNUNET_HashCode *key, void *val } static int -iterate_destroy_messages (void *cls, const struct GNUNET_HashCode *key, void *value) +iterate_destroy_messages (void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_MESSENGER_Message *message = value; @@ -62,7 +66,9 @@ iterate_destroy_messages (void *cls, const struct GNUNET_HashCode *key, void *va } static int -iterate_destroy_links (void *cls, const struct GNUNET_HashCode *key, void *value) +iterate_destroy_links (void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_HashCode *previous = value; @@ -99,7 +105,8 @@ struct GNUNET_MESSENGER_MessageEntryStorage }; static void -load_message_store_entries (struct GNUNET_MESSENGER_MessageStore *store, const char *filename) +load_message_store_entries (struct GNUNET_MESSENGER_MessageStore *store, + const char *filename) { enum GNUNET_DISK_AccessPermissions permission = (GNUNET_DISK_PERM_USER_READ); @@ -146,7 +153,8 @@ struct GNUNET_MESSENGER_MessageLinkStorage }; static void -load_message_store_links (struct GNUNET_MESSENGER_MessageStore *store, const char *filename) +load_message_store_links (struct GNUNET_MESSENGER_MessageStore *store, + const char *filename) { enum GNUNET_DISK_AccessPermissions permission = (GNUNET_DISK_PERM_USER_READ); @@ -187,7 +195,8 @@ load_message_store_links (struct GNUNET_MESSENGER_MessageStore *store, const cha } void -load_message_store (struct GNUNET_MESSENGER_MessageStore *store, const char *directory) +load_message_store (struct GNUNET_MESSENGER_MessageStore *store, + const char *directory) { GNUNET_assert((store) && (directory)); @@ -232,7 +241,9 @@ struct GNUNET_MESSENGER_ClosureMessageSave }; static int -iterate_save_entries (void *cls, const struct GNUNET_HashCode *key, void *value) +iterate_save_entries (void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_MESSENGER_ClosureMessageSave *save = cls; struct GNUNET_MESSENGER_MessageEntry *entry = value; @@ -248,7 +259,9 @@ iterate_save_entries (void *cls, const struct GNUNET_HashCode *key, void *value) } static int -iterate_save_messages (void *cls, const struct GNUNET_HashCode *key, void *value) +iterate_save_messages (void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_MESSENGER_ClosureMessageSave *save = cls; @@ -279,7 +292,9 @@ iterate_save_messages (void *cls, const struct GNUNET_HashCode *key, void *value } static int -iterate_save_links (void *cls, const struct GNUNET_HashCode *key, void *value) +iterate_save_links (void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_MESSENGER_ClosureMessageSave *save = cls; struct GNUNET_MESSENGER_MessageLink *link = value; @@ -295,7 +310,8 @@ iterate_save_links (void *cls, const struct GNUNET_HashCode *key, void *value) } void -save_message_store (struct GNUNET_MESSENGER_MessageStore *store, const char *directory) +save_message_store (struct GNUNET_MESSENGER_MessageStore *store, + const char *directory) { GNUNET_assert((store) && (directory)); @@ -372,7 +388,8 @@ close_entries: } int -contains_store_message (const struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash) +contains_store_message (const struct GNUNET_MESSENGER_MessageStore *store, + const struct GNUNET_HashCode *hash) { GNUNET_assert((store) && (hash)); @@ -383,7 +400,8 @@ contains_store_message (const struct GNUNET_MESSENGER_MessageStore *store, const } const struct GNUNET_MESSENGER_Message* -get_store_message (struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash) +get_store_message (struct GNUNET_MESSENGER_MessageStore *store, + const struct GNUNET_HashCode *hash) { GNUNET_assert((store) && (hash)); @@ -444,7 +462,8 @@ free_buffer: } const struct GNUNET_MESSENGER_MessageLink* -get_store_message_link (struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash, +get_store_message_link (struct GNUNET_MESSENGER_MessageStore *store, + const struct GNUNET_HashCode *hash, int deleted_only) { if (deleted_only) @@ -473,7 +492,8 @@ get_link: } int -put_store_message (struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash, +put_store_message (struct GNUNET_MESSENGER_MessageStore *store, + const struct GNUNET_HashCode *hash, struct GNUNET_MESSENGER_Message *message) { GNUNET_assert((store) && (hash) && (message)); @@ -483,7 +503,8 @@ put_store_message (struct GNUNET_MESSENGER_MessageStore *store, const struct GNU } static void -add_link (struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash, +add_link (struct GNUNET_MESSENGER_MessageStore *store, + const struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_Message *message) { struct GNUNET_MESSENGER_MessageLink *link = GNUNET_new(struct GNUNET_MESSENGER_MessageLink); @@ -503,7 +524,8 @@ add_link (struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashC } int -delete_store_message (struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash) +delete_store_message (struct GNUNET_MESSENGER_MessageStore *store, + const struct GNUNET_HashCode *hash) { GNUNET_assert((store) && (hash)); diff --git a/src/messenger/gnunet-service-messenger_message_store.h b/src/messenger/gnunet-service-messenger_message_store.h index 87305826a..476d98dd5 100644 --- a/src/messenger/gnunet-service-messenger_message_store.h +++ b/src/messenger/gnunet-service-messenger_message_store.h @@ -81,7 +81,8 @@ clear_message_store (struct GNUNET_MESSENGER_MessageStore *store); * @param[in] directory Path to a directory */ void -load_message_store (struct GNUNET_MESSENGER_MessageStore *store, const char *directory); +load_message_store (struct GNUNET_MESSENGER_MessageStore *store, + const char *directory); /** * Saves messages from a message store into a directory. @@ -90,7 +91,8 @@ load_message_store (struct GNUNET_MESSENGER_MessageStore *store, const char *dir * @param[in] directory Path to a directory */ void -save_message_store (struct GNUNET_MESSENGER_MessageStore *store, const char *directory); +save_message_store (struct GNUNET_MESSENGER_MessageStore *store, + const char *directory); /** * Checks if a message matching a given hash is stored in a message store. @@ -103,7 +105,8 @@ save_message_store (struct GNUNET_MESSENGER_MessageStore *store, const char *dir * @return #GNUNET_YES on match, otherwise #GNUNET_NO */ int -contains_store_message (const struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash); +contains_store_message (const struct GNUNET_MESSENGER_MessageStore *store, + const struct GNUNET_HashCode *hash); /** * Returns the message from a message store matching a given hash. If no matching @@ -117,7 +120,8 @@ contains_store_message (const struct GNUNET_MESSENGER_MessageStore *store, const * @return Message or NULL */ const struct GNUNET_MESSENGER_Message* -get_store_message (struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash); +get_store_message (struct GNUNET_MESSENGER_MessageStore *store, + const struct GNUNET_HashCode *hash); /** * Returns the message link from a message store matching a given hash. If the @@ -133,7 +137,8 @@ get_store_message (struct GNUNET_MESSENGER_MessageStore *store, const struct GNU * @return Message link or NULL */ const struct GNUNET_MESSENGER_MessageLink* -get_store_message_link (struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash, +get_store_message_link (struct GNUNET_MESSENGER_MessageStore *store, + const struct GNUNET_HashCode *hash, int deleted_only); /** @@ -145,7 +150,8 @@ get_store_message_link (struct GNUNET_MESSENGER_MessageStore *store, const struc * @return #GNUNET_OK on success, otherwise #GNUNET_NO */ int -put_store_message (struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash, +put_store_message (struct GNUNET_MESSENGER_MessageStore *store, + const struct GNUNET_HashCode *hash, struct GNUNET_MESSENGER_Message *message); /** @@ -157,6 +163,7 @@ put_store_message (struct GNUNET_MESSENGER_MessageStore *store, const struct GNU * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure */ int -delete_store_message (struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash); +delete_store_message (struct GNUNET_MESSENGER_MessageStore *store, + const struct GNUNET_HashCode *hash); #endif //GNUNET_SERVICE_MESSENGER_MESSAGE_STORE_H diff --git a/src/messenger/gnunet-service-messenger_operation.c b/src/messenger/gnunet-service-messenger_operation.c index d0c378699..a8744e577 100644 --- a/src/messenger/gnunet-service-messenger_operation.c +++ b/src/messenger/gnunet-service-messenger_operation.c @@ -58,7 +58,8 @@ static void callback_operation (void *cls); struct GNUNET_MESSENGER_Operation* -load_operation (struct GNUNET_MESSENGER_OperationStore *store, const char *path) +load_operation (struct GNUNET_MESSENGER_OperationStore *store, + const char *path) { GNUNET_assert((store) && (path)); @@ -118,7 +119,8 @@ destroy_config: } void -save_operation (const struct GNUNET_MESSENGER_Operation *op, const char *path) +save_operation (const struct GNUNET_MESSENGER_Operation *op, + const char *path) { GNUNET_assert((path) && (op)); diff --git a/src/messenger/gnunet-service-messenger_operation.h b/src/messenger/gnunet-service-messenger_operation.h index f1e06f4a7..485668548 100644 --- a/src/messenger/gnunet-service-messenger_operation.h +++ b/src/messenger/gnunet-service-messenger_operation.h @@ -86,7 +86,8 @@ destroy_operation (struct GNUNET_MESSENGER_Operation *op); * @param[in] path Path of a configuration file */ struct GNUNET_MESSENGER_Operation* -load_operation (struct GNUNET_MESSENGER_OperationStore *store, const char *path); +load_operation (struct GNUNET_MESSENGER_OperationStore *store, + const char *path); /** * Saves data from an operation into a configuration file at a @@ -97,7 +98,8 @@ load_operation (struct GNUNET_MESSENGER_OperationStore *store, const char *path) * @param[in] path Path of a configuration file */ void -save_operation (const struct GNUNET_MESSENGER_Operation *op, const char *path); +save_operation (const struct GNUNET_MESSENGER_Operation *op, + const char *path); /** * Starts an inactive operation with a given delay in a diff --git a/src/messenger/gnunet-service-messenger_operation_store.c b/src/messenger/gnunet-service-messenger_operation_store.c index a32fbad2c..4f8419daa 100644 --- a/src/messenger/gnunet-service-messenger_operation_store.c +++ b/src/messenger/gnunet-service-messenger_operation_store.c @@ -29,7 +29,8 @@ #include "gnunet-service-messenger_room.h" void -init_operation_store (struct GNUNET_MESSENGER_OperationStore *store, struct GNUNET_MESSENGER_SrvRoom *room) +init_operation_store (struct GNUNET_MESSENGER_OperationStore *store, + struct GNUNET_MESSENGER_SrvRoom *room) { GNUNET_assert((store) && (room)); @@ -38,7 +39,9 @@ init_operation_store (struct GNUNET_MESSENGER_OperationStore *store, struct GNUN } static int -iterate_destroy_operations (void *cls, const struct GNUNET_HashCode *key, void *value) +iterate_destroy_operations (void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_MESSENGER_Operation *op = value; @@ -57,7 +60,8 @@ clear_operation_store (struct GNUNET_MESSENGER_OperationStore *store) } static int -callback_scan_for_operations (void *cls, const char *filename) +callback_scan_for_operations (void *cls, + const char *filename) { struct GNUNET_MESSENGER_OperationStore *store = cls; @@ -94,7 +98,9 @@ load_operation_store (struct GNUNET_MESSENGER_OperationStore *store, } static int -iterate_save_operations (void *cls, const struct GNUNET_HashCode *key, void *value) +iterate_save_operations (void *cls, + const struct GNUNET_HashCode *key, + void *value) { const char *save_dir = cls; @@ -192,10 +198,12 @@ cancel_store_operation (struct GNUNET_MESSENGER_OperationStore *store, } extern void -callback_room_deletion (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_HashCode *hash); +callback_room_deletion (struct GNUNET_MESSENGER_SrvRoom *room, + const struct GNUNET_HashCode *hash); extern void -callback_room_merge (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_HashCode *hash); +callback_room_merge (struct GNUNET_MESSENGER_SrvRoom *room, + const struct GNUNET_HashCode *hash); void callback_store_operation (struct GNUNET_MESSENGER_OperationStore *store, diff --git a/src/messenger/gnunet-service-messenger_operation_store.h b/src/messenger/gnunet-service-messenger_operation_store.h index 4c613437c..18eb7f8a1 100644 --- a/src/messenger/gnunet-service-messenger_operation_store.h +++ b/src/messenger/gnunet-service-messenger_operation_store.h @@ -48,7 +48,8 @@ struct GNUNET_MESSENGER_OperationStore * @param[in/out] room Room */ void -init_operation_store (struct GNUNET_MESSENGER_OperationStore *store, struct GNUNET_MESSENGER_SrvRoom *room); +init_operation_store (struct GNUNET_MESSENGER_OperationStore *store, + struct GNUNET_MESSENGER_SrvRoom *room); /** * Clears an operation store, stops all operations and deallocates its memory. diff --git a/src/messenger/gnunet-service-messenger_room.c b/src/messenger/gnunet-service-messenger_room.c index 73e94908f..920abb10e 100644 --- a/src/messenger/gnunet-service-messenger_room.c +++ b/src/messenger/gnunet-service-messenger_room.c @@ -43,7 +43,8 @@ static void idle_request_room_messages (void *cls); struct GNUNET_MESSENGER_SrvRoom* -create_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key) +create_room (struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_HashCode *key) { GNUNET_assert((handle) && (key)); @@ -78,7 +79,9 @@ create_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_Hash } static int -iterate_destroy_tunnels (void *cls, const struct GNUNET_PeerIdentity *key, void *value) +iterate_destroy_tunnels (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct GNUNET_MESSENGER_SrvTunnel *tunnel = value; destroy_tunnel (tunnel); @@ -150,7 +153,8 @@ get_room_operation_store (struct GNUNET_MESSENGER_SrvRoom *room) } static int -send_room_info (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, +send_room_info (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_SrvTunnel *tunnel) { if ((!handle) || (!is_tunnel_connected (tunnel))) @@ -160,7 +164,9 @@ send_room_info (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_S } static void* -callback_room_connect (void *cls, struct GNUNET_CADET_Channel *channel, const struct GNUNET_PeerIdentity *source) +callback_room_connect (void *cls, + struct GNUNET_CADET_Channel *channel, + const struct GNUNET_PeerIdentity *source) { struct GNUNET_MESSENGER_SrvRoom *room = cls; @@ -197,7 +203,8 @@ callback_room_connect (void *cls, struct GNUNET_CADET_Channel *channel, const st } static int -join_room (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, +join_room (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Member *member) { GNUNET_assert((room) && (handle) && (member)); @@ -228,8 +235,10 @@ struct GNUNET_MESSENGER_MemberNotify }; static void -notify_about_members (struct GNUNET_MESSENGER_MemberNotify *notify, struct GNUNET_MESSENGER_MemberSession *session, - struct GNUNET_CONTAINER_MultiHashMap *map, int check_permission) +notify_about_members (struct GNUNET_MESSENGER_MemberNotify *notify, + struct GNUNET_MESSENGER_MemberSession *session, + struct GNUNET_CONTAINER_MultiHashMap *map, + int check_permission) { if (session->prev) notify_about_members (notify, session->prev, map, GNUNET_YES); @@ -258,7 +267,8 @@ notify_about_members (struct GNUNET_MESSENGER_MemberNotify *notify, struct GNUNE } static int -iterate_notify_about_members (void *cls, const struct GNUNET_IDENTITY_PublicKey *public_key, +iterate_notify_about_members (void *cls, + const struct GNUNET_IDENTITY_PublicKey *public_key, struct GNUNET_MESSENGER_MemberSession *session) { struct GNUNET_MESSENGER_MemberNotify *notify = cls; @@ -275,7 +285,8 @@ iterate_notify_about_members (void *cls, const struct GNUNET_IDENTITY_PublicKey } static int -join_room_locally (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle) +join_room_locally (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvHandle *handle) { const struct GNUNET_ShortHashCode *member_id = get_handle_member_id (handle, get_room_key(room)); @@ -306,16 +317,20 @@ join_room_locally (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGE } extern int -check_tunnel_message (void *cls, const struct GNUNET_MessageHeader *header); +check_tunnel_message (void *cls, + const struct GNUNET_MessageHeader *header); extern void -handle_tunnel_message (void *cls, const struct GNUNET_MessageHeader *header); +handle_tunnel_message (void *cls, + const struct GNUNET_MessageHeader *header); extern void -callback_tunnel_disconnect (void *cls, const struct GNUNET_CADET_Channel *channel); +callback_tunnel_disconnect (void *cls, + const struct GNUNET_CADET_Channel *channel); int -open_room (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle) +open_room (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvHandle *handle) { GNUNET_assert((room) && (handle)); @@ -366,7 +381,8 @@ exit_open_room: } int -enter_room_at (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, +enter_room_at (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_PeerIdentity *door) { GNUNET_assert((room) && (handle) && (door)); @@ -404,8 +420,11 @@ enter_room_at (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_Sr } struct GNUNET_MQ_Envelope* -pack_room_message (const struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_SrvHandle *handle, - struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, int mode) +pack_room_message (const struct GNUNET_MESSENGER_SrvRoom *room, + const struct GNUNET_MESSENGER_SrvHandle *handle, + struct GNUNET_MESSENGER_Message *message, + struct GNUNET_HashCode *hash, + int mode) { GNUNET_assert((room) && (handle) && (message) && (hash)); @@ -432,7 +451,9 @@ struct GNUNET_MESSENGER_ClosureSendRoom }; static int -iterate_send_room_message (void *cls, const struct GNUNET_PeerIdentity *key, void *value) +iterate_send_room_message (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct GNUNET_MESSENGER_SrvTunnel *tunnel = value; @@ -466,14 +487,18 @@ iterate_send_room_message (void *cls, const struct GNUNET_PeerIdentity *key, voi int update_room_message (struct GNUNET_MESSENGER_SrvRoom *room, - struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); + struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash); void -callback_room_handle_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); +callback_room_handle_message (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash); int -send_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, +send_room_message (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Message *message) { GNUNET_assert((room) && (handle)); @@ -530,8 +555,10 @@ send_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGE } void -forward_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, - struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) +forward_room_message (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvTunnel *tunnel, + struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash) { GNUNET_assert((room) && (tunnel)); @@ -554,7 +581,8 @@ forward_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSE } void -check_room_peer_status (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel) +check_room_peer_status (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvTunnel *tunnel) { if (!room->peer_message) return; @@ -592,7 +620,8 @@ resend_peer_message: } void -merge_room_last_messages (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle) +merge_room_last_messages (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvHandle *handle) { GNUNET_assert(room); @@ -612,7 +641,8 @@ merge_next: } void -callback_room_deletion (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_HashCode *hash) +callback_room_deletion (struct GNUNET_MESSENGER_SrvRoom *room, + const struct GNUNET_HashCode *hash) { if (GNUNET_OK != delete_store_message (get_room_message_store(room), hash)) { @@ -622,7 +652,8 @@ callback_room_deletion (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUN } void -callback_room_merge (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_HashCode *hash) +callback_room_merge (struct GNUNET_MESSENGER_SrvRoom *room, + const struct GNUNET_HashCode *hash) { if (!room->host) return; @@ -631,8 +662,10 @@ callback_room_merge (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ } int -delete_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, - const struct GNUNET_HashCode *hash, const struct GNUNET_TIME_Relative delay) +delete_room_message (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_MemberSession *session, + const struct GNUNET_HashCode *hash, + const struct GNUNET_TIME_Relative delay) { GNUNET_assert((room) && (session) && (hash)); @@ -687,7 +720,8 @@ get_room_key (const struct GNUNET_MESSENGER_SrvRoom *room) } const struct GNUNET_MESSENGER_SrvTunnel* -get_room_tunnel (const struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_PeerIdentity *peer) +get_room_tunnel (const struct GNUNET_MESSENGER_SrvRoom *room, + const struct GNUNET_PeerIdentity *peer) { GNUNET_assert((room) && (peer)); @@ -695,9 +729,11 @@ get_room_tunnel (const struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNE } static int -request_room_message_step (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_HashCode *hash, +request_room_message_step (struct GNUNET_MESSENGER_SrvRoom *room, + const struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_MemberSession *session, - GNUNET_MESSENGER_MessageRequestCallback callback, void* cls) + GNUNET_MESSENGER_MessageRequestCallback callback, + void* cls) { struct GNUNET_MESSENGER_MessageStore *message_store = get_room_message_store(room); @@ -732,9 +768,11 @@ forward: } int -request_room_message (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_HashCode *hash, +request_room_message (struct GNUNET_MESSENGER_SrvRoom *room, + const struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_MemberSession *session, - GNUNET_MESSENGER_MessageRequestCallback callback, void* cls) + GNUNET_MESSENGER_MessageRequestCallback callback, + void* cls) { GNUNET_assert((room) && (hash)); @@ -747,7 +785,8 @@ request_room_message (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET } void -callback_room_disconnect (struct GNUNET_MESSENGER_SrvRoom *room, void *cls) +callback_room_disconnect (struct GNUNET_MESSENGER_SrvRoom *room, + void *cls) { struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls; @@ -766,8 +805,10 @@ callback_room_disconnect (struct GNUNET_MESSENGER_SrvRoom *room, void *cls) } int -callback_verify_room_message (struct GNUNET_MESSENGER_SrvRoom *room, void *cls, - struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash) +callback_verify_room_message (struct GNUNET_MESSENGER_SrvRoom *room, + void *cls, + struct GNUNET_MESSENGER_Message *message, + struct GNUNET_HashCode *hash) { if (GNUNET_MESSENGER_KIND_UNKNOWN == message->header.kind) { @@ -826,8 +867,10 @@ idle_request_room_messages (void *cls) } void -solve_room_member_collisions (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_IDENTITY_PublicKey *public_key, - const struct GNUNET_ShortHashCode *member_id, struct GNUNET_TIME_Absolute timestamp) +solve_room_member_collisions (struct GNUNET_MESSENGER_SrvRoom *room, + const struct GNUNET_IDENTITY_PublicKey *public_key, + const struct GNUNET_ShortHashCode *member_id, + struct GNUNET_TIME_Absolute timestamp) { GNUNET_assert ((room) && (public_key) && (member_id)); @@ -945,7 +988,8 @@ finish_handling: int update_room_message (struct GNUNET_MESSENGER_SrvRoom *room, - struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) + struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash) { GNUNET_assert((room) && (message) && (hash)); @@ -1008,7 +1052,8 @@ struct GNUNET_MESSENGER_MemberUpdate }; static int -iterate_update_member_sessions (void *cls, const struct GNUNET_IDENTITY_PublicKey *public_key, +iterate_update_member_sessions (void *cls, + const struct GNUNET_IDENTITY_PublicKey *public_key, struct GNUNET_MESSENGER_MemberSession *session) { struct GNUNET_MESSENGER_MemberUpdate *update = cls; @@ -1030,11 +1075,14 @@ iterate_update_member_sessions (void *cls, const struct GNUNET_IDENTITY_PublicKe } static void -remove_room_member_session (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session); +remove_room_member_session (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_MemberSession *session); void -callback_room_handle_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) +callback_room_handle_message (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash) { struct GNUNET_MESSENGER_MemberStore *member_store = get_room_member_store(room); struct GNUNET_MESSENGER_Member *member = get_store_member_of(member_store, message); @@ -1113,7 +1161,8 @@ callback_room_handle_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUN } static void -get_room_data_subdir (struct GNUNET_MESSENGER_SrvRoom *room, char **dir) +get_room_data_subdir (struct GNUNET_MESSENGER_SrvRoom *room, + char **dir) { GNUNET_assert((room) && (dir)); @@ -1178,7 +1227,8 @@ save_room (struct GNUNET_MESSENGER_SrvRoom *room) } static void -remove_room_member_session (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session) +remove_room_member_session (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_MemberSession *session) { GNUNET_assert ((room) && (session)); diff --git a/src/messenger/gnunet-service-messenger_room.h b/src/messenger/gnunet-service-messenger_room.h index 31ec877af..4b3811104 100644 --- a/src/messenger/gnunet-service-messenger_room.h +++ b/src/messenger/gnunet-service-messenger_room.h @@ -89,7 +89,8 @@ struct GNUNET_MESSENGER_SrvRoom * @return New room */ struct GNUNET_MESSENGER_SrvRoom* -create_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key); +create_room (struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_HashCode *key); /** * Destroys a room and frees its memory fully. @@ -139,7 +140,8 @@ get_room_operation_store (struct GNUNET_MESSENGER_SrvRoom *room); * @return #GNUNET_YES on success, #GNUNET_NO on failure. */ int -open_room (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle); +open_room (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvHandle *handle); /** * Connects a tunnel to a hosting peer of a room through a so called door which is represented by @@ -152,7 +154,8 @@ open_room (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHan * @return #GNUNET_YES on success, #GNUNET_NO on failure. */ int -enter_room_at (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, +enter_room_at (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_PeerIdentity *door); /** @@ -173,8 +176,11 @@ enter_room_at (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_Sr * @return New envelope or NULL */ struct GNUNET_MQ_Envelope* -pack_room_message (const struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_SrvHandle *handle, - struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, int mode); +pack_room_message (const struct GNUNET_MESSENGER_SrvRoom *room, + const struct GNUNET_MESSENGER_SrvHandle *handle, + struct GNUNET_MESSENGER_Message *message, + struct GNUNET_HashCode *hash, + int mode); /** * Sends a message from a given handle into a room. The hash parameter will be @@ -192,7 +198,8 @@ pack_room_message (const struct GNUNET_MESSENGER_SrvRoom *room, const struct GNU * @return #GNUNET_YES on success, #GNUNET_NO or #GNUNET_SYSERR otherwise. */ int -send_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, +send_room_message (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Message *message); /** @@ -204,8 +211,10 @@ send_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGE * @param[in] hash Hash of message */ void -forward_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, - struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); +forward_room_message (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvTunnel *tunnel, + struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash); /** * Checks the current state of opening a given room from this peer and re-publishes it @@ -216,7 +225,8 @@ forward_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSE * @param[in/out] tunnel Tunnel */ void -check_room_peer_status (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel); +check_room_peer_status (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvTunnel *tunnel); /** * Reduces all current forks inside of the message history of a room to one remaining last message @@ -226,7 +236,8 @@ check_room_peer_status (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MES * @param[in/out] handle Handle */ void -merge_room_last_messages (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle); +merge_room_last_messages (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvHandle *handle); /** * Deletes a message from the room with a given hash in a specific delay if @@ -239,8 +250,10 @@ merge_room_last_messages (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_M * @return #GNUNET_YES on success, #GNUNET_NO if permission gets denied, #GNUNET_SYSERR on operation failure */ int -delete_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, - const struct GNUNET_HashCode *hash, const struct GNUNET_TIME_Relative delay); +delete_room_message (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_MemberSession *session, + const struct GNUNET_HashCode *hash, + const struct GNUNET_TIME_Relative delay); /** * Returns the CADET handle from a rooms service. @@ -269,7 +282,8 @@ get_room_key (const struct GNUNET_MESSENGER_SrvRoom *room); * @return Tunnel or NULL */ const struct GNUNET_MESSENGER_SrvTunnel* -get_room_tunnel (const struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_PeerIdentity *peer); +get_room_tunnel (const struct GNUNET_MESSENGER_SrvRoom *room, + const struct GNUNET_PeerIdentity *peer); /** * Method called whenever a message is found during a request in a room. @@ -280,7 +294,8 @@ get_room_tunnel (const struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNE * @param[in] hash Hash of message */ typedef void (GNUNET_MESSENGER_MessageRequestCallback) ( - void *cls, struct GNUNET_MESSENGER_SrvRoom *room, + void *cls, + struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash ); @@ -301,9 +316,11 @@ typedef void (GNUNET_MESSENGER_MessageRequestCallback) ( * @return #GNUNET_YES if the request could be processed, otherwise #GNUNET_NO */ int -request_room_message (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_HashCode *hash, +request_room_message (struct GNUNET_MESSENGER_SrvRoom *room, + const struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_MemberSession *session, - GNUNET_MESSENGER_MessageRequestCallback callback, void* cls); + GNUNET_MESSENGER_MessageRequestCallback callback, + void* cls); /** * Checks for potential collisions with member ids and solves them changing active handles ids if they @@ -315,8 +332,10 @@ request_room_message (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET * @param[in] timestamp Timestamp */ void -solve_room_member_collisions (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_IDENTITY_PublicKey *public_key, - const struct GNUNET_ShortHashCode *member_id, struct GNUNET_TIME_Absolute timestamp); +solve_room_member_collisions (struct GNUNET_MESSENGER_SrvRoom *room, + const struct GNUNET_IDENTITY_PublicKey *public_key, + const struct GNUNET_ShortHashCode *member_id, + struct GNUNET_TIME_Absolute timestamp); /** * Rebuilds the decentralized structure for a room by ensuring all required connections are made diff --git a/src/messenger/gnunet-service-messenger_service.c b/src/messenger/gnunet-service-messenger_service.c index 8c63e9bf4..91165cf63 100644 --- a/src/messenger/gnunet-service-messenger_service.c +++ b/src/messenger/gnunet-service-messenger_service.c @@ -41,7 +41,8 @@ callback_shutdown_service (void *cls) } struct GNUNET_MESSENGER_Service* -create_service (const struct GNUNET_CONFIGURATION_Handle *config, struct GNUNET_SERVICE_Handle *service_handle) +create_service (const struct GNUNET_CONFIGURATION_Handle *config, + struct GNUNET_SERVICE_Handle *service_handle) { GNUNET_assert((config) && (service_handle)); @@ -88,7 +89,9 @@ create_service (const struct GNUNET_CONFIGURATION_Handle *config, struct GNUNET_ } static int -iterate_destroy_rooms (void *cls, const struct GNUNET_HashCode *key, void *value) +iterate_destroy_rooms (void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_MESSENGER_SrvRoom *room = value; destroy_room (room); @@ -151,7 +154,8 @@ get_service_contact_store (struct GNUNET_MESSENGER_Service *service) } struct GNUNET_MESSENGER_SrvHandle* -add_service_handle (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MQ_Handle *mq) +add_service_handle (struct GNUNET_MESSENGER_Service *service, + struct GNUNET_MQ_Handle *mq) { GNUNET_assert((service) && (mq)); @@ -166,7 +170,8 @@ add_service_handle (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MQ_H } void -remove_service_handle (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle) +remove_service_handle (struct GNUNET_MESSENGER_Service *service, + struct GNUNET_MESSENGER_SrvHandle *handle) { GNUNET_assert((service) && (handle)); @@ -178,7 +183,8 @@ remove_service_handle (struct GNUNET_MESSENGER_Service *service, struct GNUNET_M } int -get_service_peer_identity (const struct GNUNET_MESSENGER_Service *service, struct GNUNET_PeerIdentity *peer) +get_service_peer_identity (const struct GNUNET_MESSENGER_Service *service, + struct GNUNET_PeerIdentity *peer) { GNUNET_assert((service) && (peer)); @@ -186,7 +192,8 @@ get_service_peer_identity (const struct GNUNET_MESSENGER_Service *service, struc } struct GNUNET_MESSENGER_SrvRoom* -get_service_room (const struct GNUNET_MESSENGER_Service *service, const struct GNUNET_HashCode *key) +get_service_room (const struct GNUNET_MESSENGER_Service *service, + const struct GNUNET_HashCode *key) { GNUNET_assert((service) && (key)); @@ -194,7 +201,8 @@ get_service_room (const struct GNUNET_MESSENGER_Service *service, const struct G } int -open_service_room (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle, +open_service_room (struct GNUNET_MESSENGER_Service *service, + struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key) { GNUNET_assert((service) && (handle) && (key)); @@ -217,8 +225,10 @@ open_service_room (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSE } int -entry_service_room (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle, - const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key) +entry_service_room (struct GNUNET_MESSENGER_Service *service, + struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_PeerIdentity *door, + const struct GNUNET_HashCode *key) { GNUNET_assert((service) && (handle) && (door) && (key)); @@ -250,7 +260,8 @@ entry_service_room (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESS } int -close_service_room (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle, +close_service_room (struct GNUNET_MESSENGER_Service *service, + struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key) { GNUNET_assert((service) && (handle) && (key)); @@ -290,9 +301,11 @@ close_service_room (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESS } void -handle_service_message (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvRoom *room, +handle_service_message (struct GNUNET_MESSENGER_Service *service, + struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_MemberSession *session, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash) { GNUNET_assert((service) && (room) && (session) && (message) && (hash)); diff --git a/src/messenger/gnunet-service-messenger_service.h b/src/messenger/gnunet-service-messenger_service.h index aa43fa457..d364a93c0 100644 --- a/src/messenger/gnunet-service-messenger_service.h +++ b/src/messenger/gnunet-service-messenger_service.h @@ -68,7 +68,8 @@ struct GNUNET_MESSENGER_Service * @return New service */ struct GNUNET_MESSENGER_Service* -create_service (const struct GNUNET_CONFIGURATION_Handle *config, struct GNUNET_SERVICE_Handle *service_handle); +create_service (const struct GNUNET_CONFIGURATION_Handle *config, + struct GNUNET_SERVICE_Handle *service_handle); /** * Destroys a service and frees its memory fully. @@ -104,7 +105,8 @@ get_service_contact_store (struct GNUNET_MESSENGER_Service *service); * @return New handle */ struct GNUNET_MESSENGER_SrvHandle* -add_service_handle (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MQ_Handle *mq); +add_service_handle (struct GNUNET_MESSENGER_Service *service, + struct GNUNET_MQ_Handle *mq); /** * Removes a handle from a service and destroys it. @@ -113,7 +115,8 @@ add_service_handle (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MQ_H * @param[in/out] handle Handle */ void -remove_service_handle (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle); +remove_service_handle (struct GNUNET_MESSENGER_Service *service, + struct GNUNET_MESSENGER_SrvHandle *handle); /** * Tries to write the peer identity of the peer running a service on to the peer @@ -124,7 +127,8 @@ remove_service_handle (struct GNUNET_MESSENGER_Service *service, struct GNUNET_M * @return #GNUNET_OK on success, otherwise #GNUNET_SYSERR */ int -get_service_peer_identity (const struct GNUNET_MESSENGER_Service *service, struct GNUNET_PeerIdentity *peer); +get_service_peer_identity (const struct GNUNET_MESSENGER_Service *service, + struct GNUNET_PeerIdentity *peer); /** * Returns the room identified by a given key for a service. If the service doesn't know any room @@ -135,7 +139,8 @@ get_service_peer_identity (const struct GNUNET_MESSENGER_Service *service, struc * @return Room or NULL */ struct GNUNET_MESSENGER_SrvRoom* -get_service_room (const struct GNUNET_MESSENGER_Service *service, const struct GNUNET_HashCode *key); +get_service_room (const struct GNUNET_MESSENGER_Service *service, + const struct GNUNET_HashCode *key); /** * Tries to open a room using a given key for a service by a specific handle. The room will be @@ -147,7 +152,8 @@ get_service_room (const struct GNUNET_MESSENGER_Service *service, const struct G * @return #GNUNET_YES on success, otherwise #GNUNET_NO */ int -open_service_room (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle, +open_service_room (struct GNUNET_MESSENGER_Service *service, + struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key); /** @@ -164,8 +170,10 @@ open_service_room (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSE * @return #GNUNET_YES on success, otherwise #GNUNET_NO */ int -entry_service_room (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle, - const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key); +entry_service_room (struct GNUNET_MESSENGER_Service *service, + struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_PeerIdentity *door, + const struct GNUNET_HashCode *key); /** * Tries to close a room using a given key for a service by a specific handle. The room will @@ -180,7 +188,8 @@ entry_service_room (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESS * @return #GNUNET_YES on success, otherwise #GNUNET_NO */ int -close_service_room (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle, +close_service_room (struct GNUNET_MESSENGER_Service *service, + struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key); /** @@ -194,8 +203,10 @@ close_service_room (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESS * @param[in] hash Hash of message */ void -handle_service_message (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvRoom *room, +handle_service_message (struct GNUNET_MESSENGER_Service *service, + struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_MemberSession *session, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash); #endif //GNUNET_SERVICE_MESSENGER_SERVICE_H diff --git a/src/messenger/gnunet-service-messenger_tunnel.c b/src/messenger/gnunet-service-messenger_tunnel.c index b9d063813..fdd6429e6 100644 --- a/src/messenger/gnunet-service-messenger_tunnel.c +++ b/src/messenger/gnunet-service-messenger_tunnel.c @@ -33,7 +33,8 @@ #include "messenger_api_util.h" struct GNUNET_MESSENGER_SrvTunnel* -create_tunnel (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_PeerIdentity *door) +create_tunnel (struct GNUNET_MESSENGER_SrvRoom *room, + const struct GNUNET_PeerIdentity *door) { GNUNET_assert((room) && (door)); @@ -72,7 +73,8 @@ destroy_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel) } void -bind_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_CADET_Channel *channel) +bind_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel, + struct GNUNET_CADET_Channel *channel) { GNUNET_assert(tunnel); @@ -83,10 +85,12 @@ bind_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_CADET_Chan } extern void -callback_room_disconnect (struct GNUNET_MESSENGER_SrvRoom *room, void *cls); +callback_room_disconnect (struct GNUNET_MESSENGER_SrvRoom *room, + void *cls); void -callback_tunnel_disconnect (void *cls, const struct GNUNET_CADET_Channel *channel) +callback_tunnel_disconnect (void *cls, + const struct GNUNET_CADET_Channel *channel) { struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls; @@ -99,11 +103,14 @@ callback_tunnel_disconnect (void *cls, const struct GNUNET_CADET_Channel *channe } extern int -callback_verify_room_message (struct GNUNET_MESSENGER_SrvRoom *room, void *cls, - struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash); +callback_verify_room_message (struct GNUNET_MESSENGER_SrvRoom *room, + void *cls, + struct GNUNET_MESSENGER_Message *message, + struct GNUNET_HashCode *hash); int -check_tunnel_message (void *cls, const struct GNUNET_MessageHeader *header) +check_tunnel_message (void *cls, + const struct GNUNET_MessageHeader *header) { struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls; @@ -137,14 +144,18 @@ check_tunnel_message (void *cls, const struct GNUNET_MessageHeader *header) extern int update_room_message (struct GNUNET_MESSENGER_SrvRoom *room, - struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); + struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash); extern void -callback_room_handle_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); +callback_room_handle_message (struct GNUNET_MESSENGER_SrvRoom *room, + struct GNUNET_MESSENGER_SrvHandle *handle, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash); static void -update_tunnel_last_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, const struct GNUNET_HashCode *hash) +update_tunnel_last_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, + const struct GNUNET_HashCode *hash) { struct GNUNET_MESSENGER_OperationStore *operation_store = get_room_operation_store(tunnel->room); @@ -281,7 +292,8 @@ callback_tunnel_sent (void *cls) } void -send_tunnel_envelope (struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MQ_Envelope *env, +send_tunnel_envelope (struct GNUNET_MESSENGER_SrvTunnel *tunnel, + struct GNUNET_MQ_Envelope *env, const struct GNUNET_HashCode *hash) { GNUNET_assert((tunnel) && (env) && (hash)); @@ -299,7 +311,9 @@ send_tunnel_envelope (struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_M } int -send_tunnel_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, void *handle, struct GNUNET_MESSENGER_Message *message) +send_tunnel_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, + void *handle, + struct GNUNET_MESSENGER_Message *message) { GNUNET_assert((tunnel) && (handle)); @@ -325,7 +339,8 @@ send_tunnel_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, void *handle, st } void -forward_tunnel_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, const struct GNUNET_MESSENGER_Message *message, +forward_tunnel_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, + const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) { GNUNET_assert((tunnel) && (message) && (hash)); @@ -353,7 +368,8 @@ get_tunnel_peer_message (const struct GNUNET_MESSENGER_SrvTunnel *tunnel) } void -get_tunnel_peer_identity (const struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_PeerIdentity *peer) +get_tunnel_peer_identity (const struct GNUNET_MESSENGER_SrvTunnel *tunnel, + struct GNUNET_PeerIdentity *peer) { GNUNET_assert(tunnel); @@ -369,7 +385,8 @@ get_tunnel_messenger_version (const struct GNUNET_MESSENGER_SrvTunnel *tunnel) } int -update_tunnel_messenger_version (struct GNUNET_MESSENGER_SrvTunnel *tunnel, uint32_t version) +update_tunnel_messenger_version (struct GNUNET_MESSENGER_SrvTunnel *tunnel, + uint32_t version) { GNUNET_assert(tunnel); diff --git a/src/messenger/gnunet-service-messenger_tunnel.h b/src/messenger/gnunet-service-messenger_tunnel.h index 96d98546d..7bd749281 100644 --- a/src/messenger/gnunet-service-messenger_tunnel.h +++ b/src/messenger/gnunet-service-messenger_tunnel.h @@ -55,7 +55,8 @@ struct GNUNET_MESSENGER_SrvTunnel * @return New tunnel */ struct GNUNET_MESSENGER_SrvTunnel* -create_tunnel (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_PeerIdentity *door); +create_tunnel (struct GNUNET_MESSENGER_SrvRoom *room, + const struct GNUNET_PeerIdentity *door); /** * Destroys a tunnel and frees its memory fully. @@ -73,7 +74,8 @@ destroy_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel); * @param[in/out] channel CADET channel */ void -bind_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_CADET_Channel *channel); +bind_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel, + struct GNUNET_CADET_Channel *channel); /** * Tries to connect a tunnel by creating a new CADET channel and binding it. @@ -112,7 +114,8 @@ is_tunnel_connected (const struct GNUNET_MESSENGER_SrvTunnel *tunnel); * @param[in] hash Hash of message */ void -send_tunnel_envelope (struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MQ_Envelope *env, +send_tunnel_envelope (struct GNUNET_MESSENGER_SrvTunnel *tunnel, + struct GNUNET_MQ_Envelope *env, const struct GNUNET_HashCode *hash); /** @@ -126,7 +129,9 @@ send_tunnel_envelope (struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_M * @return #GNUNET_YES on success, GNUNET_NO otherwise */ int -send_tunnel_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, void *handle, struct GNUNET_MESSENGER_Message *message); +send_tunnel_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, + void *handle, + struct GNUNET_MESSENGER_Message *message); /** * Forwards a given message with a known hash through a tunnel. @@ -136,7 +141,8 @@ send_tunnel_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, void *handle, st * @param[in] hash Hash of message */ void -forward_tunnel_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, const struct GNUNET_MESSENGER_Message *message, +forward_tunnel_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, + const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); /** @@ -158,7 +164,8 @@ get_tunnel_peer_message (const struct GNUNET_MESSENGER_SrvTunnel *tunnel); * @param[out] peer Peer identity */ void -get_tunnel_peer_identity (const struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_PeerIdentity *peer); +get_tunnel_peer_identity (const struct GNUNET_MESSENGER_SrvTunnel *tunnel, + struct GNUNET_PeerIdentity *peer); /** * Returns the current messenger version the peer connected via a given tunnel @@ -181,6 +188,7 @@ get_tunnel_messenger_version (const struct GNUNET_MESSENGER_SrvTunnel *tunnel); * @param[in] version Version of messenger */ int -update_tunnel_messenger_version (struct GNUNET_MESSENGER_SrvTunnel *tunnel, uint32_t version); +update_tunnel_messenger_version (struct GNUNET_MESSENGER_SrvTunnel *tunnel, + uint32_t version); #endif //GNUNET_SERVICE_MESSENGER_TUNNEL_H diff --git a/src/messenger/messenger_api.c b/src/messenger/messenger_api.c index f7c73f769..ef6244e19 100644 --- a/src/messenger/messenger_api.c +++ b/src/messenger/messenger_api.c @@ -70,14 +70,16 @@ GNUNET_MESSENGER_name_of_kind (enum GNUNET_MESSENGER_MessageKind kind) } static int -check_get_name (void *cls, const struct GNUNET_MESSENGER_NameMessage *msg) +check_get_name (void *cls, + const struct GNUNET_MESSENGER_NameMessage *msg) { GNUNET_MQ_check_zero_termination(msg); return GNUNET_OK; } static void -handle_get_name (void *cls, const struct GNUNET_MESSENGER_NameMessage *msg) +handle_get_name (void *cls, + const struct GNUNET_MESSENGER_NameMessage *msg) { struct GNUNET_MESSENGER_Handle *handle = cls; @@ -89,7 +91,8 @@ handle_get_name (void *cls, const struct GNUNET_MESSENGER_NameMessage *msg) } static int -check_get_key (void *cls, const struct GNUNET_MESSENGER_KeyMessage *msg) +check_get_key (void *cls, + const struct GNUNET_MESSENGER_KeyMessage *msg) { const uint16_t full_length = ntohs (msg->header.size); @@ -107,7 +110,8 @@ check_get_key (void *cls, const struct GNUNET_MESSENGER_KeyMessage *msg) } static void -handle_get_key (void *cls, const struct GNUNET_MESSENGER_KeyMessage *msg) +handle_get_key (void *cls, + const struct GNUNET_MESSENGER_KeyMessage *msg) { struct GNUNET_MESSENGER_Handle *handle = cls; @@ -129,7 +133,8 @@ handle_get_key (void *cls, const struct GNUNET_MESSENGER_KeyMessage *msg) } static void -handle_member_id (void *cls, const struct GNUNET_MESSENGER_MemberMessage *msg) +handle_member_id (void *cls, + const struct GNUNET_MESSENGER_MemberMessage *msg) { struct GNUNET_MESSENGER_Handle *handle = cls; @@ -150,7 +155,8 @@ handle_member_id (void *cls, const struct GNUNET_MESSENGER_MemberMessage *msg) } static void -handle_room_open (void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg) +handle_room_open (void *cls, + const struct GNUNET_MESSENGER_RoomMessage *msg) { struct GNUNET_MESSENGER_Handle *handle = cls; @@ -162,7 +168,8 @@ handle_room_open (void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg) } static void -handle_room_entry (void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg) +handle_room_entry (void *cls, + const struct GNUNET_MESSENGER_RoomMessage *msg) { struct GNUNET_MESSENGER_Handle *handle = cls; @@ -175,7 +182,8 @@ handle_room_entry (void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg) } static void -handle_room_close (void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg) +handle_room_close (void *cls, + const struct GNUNET_MESSENGER_RoomMessage *msg) { struct GNUNET_MESSENGER_Handle *handle = cls; @@ -187,7 +195,8 @@ handle_room_close (void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg) } static int -check_recv_message (void *cls, const struct GNUNET_MESSENGER_RecvMessage *msg) +check_recv_message (void *cls, + const struct GNUNET_MESSENGER_RecvMessage *msg) { const uint16_t full_length = ntohs (msg->header.size); @@ -209,7 +218,8 @@ check_recv_message (void *cls, const struct GNUNET_MESSENGER_RecvMessage *msg) } static void -handle_recv_message (void *cls, const struct GNUNET_MESSENGER_RecvMessage *msg) +handle_recv_message (void *cls, + const struct GNUNET_MESSENGER_RecvMessage *msg) { struct GNUNET_MESSENGER_Handle *handle = cls; @@ -255,7 +265,8 @@ static void reconnect (struct GNUNET_MESSENGER_Handle *handle); static void -send_open_room (struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room) +send_open_room (struct GNUNET_MESSENGER_Handle *handle, + struct GNUNET_MESSENGER_Room *room) { struct GNUNET_MESSENGER_RoomMessage *msg; struct GNUNET_MQ_Envelope *env; @@ -266,7 +277,8 @@ send_open_room (struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_ } static void -send_enter_room (struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room, +send_enter_room (struct GNUNET_MESSENGER_Handle *handle, + struct GNUNET_MESSENGER_Room *room, const struct GNUNET_PeerIdentity *door) { struct GNUNET_MESSENGER_RoomMessage *msg; @@ -279,7 +291,8 @@ send_enter_room (struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER } static void -send_close_room (struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room) +send_close_room (struct GNUNET_MESSENGER_Handle *handle, + struct GNUNET_MESSENGER_Room *room) { struct GNUNET_MESSENGER_RoomMessage *msg; struct GNUNET_MQ_Envelope *env; @@ -290,7 +303,9 @@ send_close_room (struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER } static int -iterate_reset_room (void *cls, const struct GNUNET_HashCode *key, void *value) +iterate_reset_room (void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_MESSENGER_Handle *handle = cls; struct GNUNET_MESSENGER_Room *room = value; @@ -329,7 +344,9 @@ callback_reconnect (void *cls) } static int -iterate_close_room (void *cls, const struct GNUNET_HashCode *key, void *value) +iterate_close_room (void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_MESSENGER_Handle *handle = cls; struct GNUNET_MESSENGER_Room *room = value; @@ -340,7 +357,8 @@ iterate_close_room (void *cls, const struct GNUNET_HashCode *key, void *value) } static void -callback_mq_error (void *cls, enum GNUNET_MQ_Error error) +callback_mq_error (void *cls, + enum GNUNET_MQ_Error error) { struct GNUNET_MESSENGER_Handle *handle = cls; @@ -402,9 +420,12 @@ reconnect (struct GNUNET_MESSENGER_Handle *handle) } struct GNUNET_MESSENGER_Handle* -GNUNET_MESSENGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *name, - GNUNET_MESSENGER_IdentityCallback identity_callback, void *identity_cls, - GNUNET_MESSENGER_MessageCallback msg_callback, void *msg_cls) +GNUNET_MESSENGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *name, + GNUNET_MESSENGER_IdentityCallback identity_callback, + void *identity_cls, + GNUNET_MESSENGER_MessageCallback msg_callback, + void *msg_cls) { struct GNUNET_MESSENGER_Handle *handle = create_handle (cfg, identity_callback, identity_cls, msg_callback, msg_cls); @@ -475,7 +496,8 @@ GNUNET_MESSENGER_get_name (const struct GNUNET_MESSENGER_Handle *handle) } int -GNUNET_MESSENGER_set_name (struct GNUNET_MESSENGER_Handle *handle, const char *name) +GNUNET_MESSENGER_set_name (struct GNUNET_MESSENGER_Handle *handle, + const char *name) { if (!handle) return GNUNET_SYSERR; @@ -517,7 +539,8 @@ GNUNET_MESSENGER_get_key (const struct GNUNET_MESSENGER_Handle *handle) } struct GNUNET_MESSENGER_Room* -GNUNET_MESSENGER_open_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key) +GNUNET_MESSENGER_open_room (struct GNUNET_MESSENGER_Handle *handle, + const struct GNUNET_HashCode *key) { if ((!handle) || (!key)) return NULL; @@ -541,7 +564,8 @@ GNUNET_MESSENGER_open_room (struct GNUNET_MESSENGER_Handle *handle, const struct } struct GNUNET_MESSENGER_Room* -GNUNET_MESSENGER_enter_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_PeerIdentity *door, +GNUNET_MESSENGER_enter_room (struct GNUNET_MESSENGER_Handle *handle, + const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key) { if ((!handle) || (!door) || (!key)) @@ -583,7 +607,9 @@ struct GNUNET_MESSENGER_RoomFind }; static int -iterate_find_room (void* cls, const struct GNUNET_HashCode *key, void *value) +iterate_find_room (void* cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_MESSENGER_RoomFind *find = cls; struct GNUNET_MESSENGER_Room *room = value; @@ -602,8 +628,10 @@ iterate_find_room (void* cls, const struct GNUNET_HashCode *key, void *value) } int -GNUNET_MESSENGER_find_rooms (const struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_MESSENGER_Contact *contact, - GNUNET_MESSENGER_MemberCallback callback, void *cls) +GNUNET_MESSENGER_find_rooms (const struct GNUNET_MESSENGER_Handle *handle, + const struct GNUNET_MESSENGER_Contact *contact, + GNUNET_MESSENGER_MemberCallback callback, + void *cls) { if (!handle) return GNUNET_SYSERR; @@ -628,7 +656,8 @@ GNUNET_MESSENGER_room_get_key (const struct GNUNET_MESSENGER_Room *room) } const struct GNUNET_MESSENGER_Contact* -GNUNET_MESSENGER_get_sender (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash) +GNUNET_MESSENGER_get_sender (const struct GNUNET_MESSENGER_Room *room, + const struct GNUNET_HashCode *hash) { if ((!room) || (!hash)) return NULL; @@ -655,7 +684,8 @@ GNUNET_MESSENGER_contact_get_key (const struct GNUNET_MESSENGER_Contact *contact } void -GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, +GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room, + const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_MESSENGER_Contact *contact) { if ((!room) || (!message)) @@ -723,7 +753,8 @@ GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room, const struct } const struct GNUNET_MESSENGER_Message* -GNUNET_MESSENGER_get_message (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash) +GNUNET_MESSENGER_get_message (const struct GNUNET_MESSENGER_Room *room, + const struct GNUNET_HashCode *hash) { if ((!room) || (!hash)) return NULL; @@ -745,7 +776,8 @@ GNUNET_MESSENGER_get_message (const struct GNUNET_MESSENGER_Room *room, const st } int -GNUNET_MESSENGER_iterate_members (struct GNUNET_MESSENGER_Room *room, GNUNET_MESSENGER_MemberCallback callback, +GNUNET_MESSENGER_iterate_members (struct GNUNET_MESSENGER_Room *room, + GNUNET_MESSENGER_MemberCallback callback, void *cls) { if (!room) diff --git a/src/messenger/messenger_api_contact.c b/src/messenger/messenger_api_contact.c index 04e1f60c1..cbca17640 100644 --- a/src/messenger/messenger_api_contact.c +++ b/src/messenger/messenger_api_contact.c @@ -60,7 +60,8 @@ get_contact_name (const struct GNUNET_MESSENGER_Contact *contact) } void -set_contact_name (struct GNUNET_MESSENGER_Contact *contact, const char *name) +set_contact_name (struct GNUNET_MESSENGER_Contact *contact, + const char *name) { GNUNET_assert(contact); @@ -98,7 +99,8 @@ decrease_contact_rc (struct GNUNET_MESSENGER_Contact *contact) } void -get_context_from_member (const struct GNUNET_HashCode *key, const struct GNUNET_ShortHashCode *id, +get_context_from_member (const struct GNUNET_HashCode *key, + const struct GNUNET_ShortHashCode *id, struct GNUNET_HashCode *context) { GNUNET_assert((key) && (id) && (context)); diff --git a/src/messenger/messenger_api_contact.h b/src/messenger/messenger_api_contact.h index e94d1fcd0..b5410f998 100644 --- a/src/messenger/messenger_api_contact.h +++ b/src/messenger/messenger_api_contact.h @@ -71,7 +71,8 @@ get_contact_name (const struct GNUNET_MESSENGER_Contact *contact); * @param[in] name Name */ void -set_contact_name (struct GNUNET_MESSENGER_Contact *contact, const char *name); +set_contact_name (struct GNUNET_MESSENGER_Contact *contact, + const char *name); /** * Returns the public key of a given contact. @@ -108,7 +109,8 @@ decrease_contact_rc (struct GNUNET_MESSENGER_Contact *contact); * @param[out] hash Member context */ void -get_context_from_member (const struct GNUNET_HashCode *key, const struct GNUNET_ShortHashCode *id, +get_context_from_member (const struct GNUNET_HashCode *key, + const struct GNUNET_ShortHashCode *id, struct GNUNET_HashCode *context); #endif //GNUNET_MESSENGER_API_CONTACT_H diff --git a/src/messenger/messenger_api_contact_store.c b/src/messenger/messenger_api_contact_store.c index 6a517c2e0..1c10a8fbf 100644 --- a/src/messenger/messenger_api_contact_store.c +++ b/src/messenger/messenger_api_contact_store.c @@ -38,7 +38,9 @@ init_contact_store (struct GNUNET_MESSENGER_ContactStore *store) } static int -iterate_destroy_contacts (void *cls, const struct GNUNET_HashCode *key, void *value) +iterate_destroy_contacts (void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_MESSENGER_Contact *contact = value; destroy_contact (contact); @@ -58,7 +60,8 @@ clear_contact_store (struct GNUNET_MESSENGER_ContactStore *store) } static struct GNUNET_CONTAINER_MultiHashMap* -select_store_contact_map (struct GNUNET_MESSENGER_ContactStore *store, const struct GNUNET_HashCode *context, +select_store_contact_map (struct GNUNET_MESSENGER_ContactStore *store, + const struct GNUNET_HashCode *context, struct GNUNET_HashCode *hash) { const struct GNUNET_IDENTITY_PublicKey *anonymous = get_anonymous_public_key (); @@ -76,7 +79,8 @@ select_store_contact_map (struct GNUNET_MESSENGER_ContactStore *store, const str } struct GNUNET_MESSENGER_Contact* -get_store_contact_raw (struct GNUNET_MESSENGER_ContactStore *store, const struct GNUNET_HashCode *context, +get_store_contact_raw (struct GNUNET_MESSENGER_ContactStore *store, + const struct GNUNET_HashCode *context, const struct GNUNET_HashCode *key_hash) { GNUNET_assert ((store) && (store->contacts) && (context) && (key_hash)); @@ -92,7 +96,8 @@ get_store_contact_raw (struct GNUNET_MESSENGER_ContactStore *store, const struct } struct GNUNET_MESSENGER_Contact* -get_store_contact (struct GNUNET_MESSENGER_ContactStore *store, const struct GNUNET_HashCode *context, +get_store_contact (struct GNUNET_MESSENGER_ContactStore *store, + const struct GNUNET_HashCode *context, const struct GNUNET_IDENTITY_PublicKey *pubkey) { GNUNET_assert ((store) && (store->contacts) && (context) && (pubkey)); @@ -130,8 +135,10 @@ get_store_contact (struct GNUNET_MESSENGER_ContactStore *store, const struct GNU } void -update_store_contact (struct GNUNET_MESSENGER_ContactStore *store, struct GNUNET_MESSENGER_Contact* contact, - const struct GNUNET_HashCode *context, const struct GNUNET_HashCode *next_context, +update_store_contact (struct GNUNET_MESSENGER_ContactStore *store, + struct GNUNET_MESSENGER_Contact* contact, + const struct GNUNET_HashCode *context, + const struct GNUNET_HashCode *next_context, const struct GNUNET_IDENTITY_PublicKey *pubkey) { GNUNET_assert ((store) && (store->contacts) && (contact) && (pubkey)); @@ -163,7 +170,8 @@ update_store_contact (struct GNUNET_MESSENGER_ContactStore *store, struct GNUNET } void -remove_store_contact (struct GNUNET_MESSENGER_ContactStore *store, struct GNUNET_MESSENGER_Contact* contact, +remove_store_contact (struct GNUNET_MESSENGER_ContactStore *store, + struct GNUNET_MESSENGER_Contact* contact, const struct GNUNET_HashCode *context) { GNUNET_assert ((store) && (store->contacts) && (contact)); diff --git a/src/messenger/messenger_api_contact_store.h b/src/messenger/messenger_api_contact_store.h index f2dad9f84..bdab2ceeb 100644 --- a/src/messenger/messenger_api_contact_store.h +++ b/src/messenger/messenger_api_contact_store.h @@ -68,7 +68,8 @@ clear_contact_store (struct GNUNET_MESSENGER_ContactStore *store); * @param[in] key_hash Hash of public key */ struct GNUNET_MESSENGER_Contact* -get_store_contact_raw (struct GNUNET_MESSENGER_ContactStore *store, const struct GNUNET_HashCode *context, +get_store_contact_raw (struct GNUNET_MESSENGER_ContactStore *store, + const struct GNUNET_HashCode *context, const struct GNUNET_HashCode *key_hash); /** @@ -87,7 +88,8 @@ get_store_contact_raw (struct GNUNET_MESSENGER_ContactStore *store, const struct * @param[in] pubkey Public key of EGO */ struct GNUNET_MESSENGER_Contact* -get_store_contact (struct GNUNET_MESSENGER_ContactStore *store, const struct GNUNET_HashCode *context, +get_store_contact (struct GNUNET_MESSENGER_ContactStore *store, + const struct GNUNET_HashCode *context, const struct GNUNET_IDENTITY_PublicKey *pubkey); /** @@ -103,8 +105,10 @@ get_store_contact (struct GNUNET_MESSENGER_ContactStore *store, const struct GNU * @param[in] pubkey Public key of EGO */ void -update_store_contact (struct GNUNET_MESSENGER_ContactStore *store, struct GNUNET_MESSENGER_Contact* contact, - const struct GNUNET_HashCode *context, const struct GNUNET_HashCode *next_context, +update_store_contact (struct GNUNET_MESSENGER_ContactStore *store, + struct GNUNET_MESSENGER_Contact* contact, + const struct GNUNET_HashCode *context, + const struct GNUNET_HashCode *next_context, const struct GNUNET_IDENTITY_PublicKey *pubkey); /** @@ -116,7 +120,8 @@ update_store_contact (struct GNUNET_MESSENGER_ContactStore *store, struct GNUNET * @param[in] context Member context */ void -remove_store_contact (struct GNUNET_MESSENGER_ContactStore *store, struct GNUNET_MESSENGER_Contact* contact, +remove_store_contact (struct GNUNET_MESSENGER_ContactStore *store, + struct GNUNET_MESSENGER_Contact* contact, const struct GNUNET_HashCode *context); #endif //GNUNET_MESSENGER_API_CONTACT_STORE_H diff --git a/src/messenger/messenger_api_handle.c b/src/messenger/messenger_api_handle.c index ab57f82cc..516807e13 100644 --- a/src/messenger/messenger_api_handle.c +++ b/src/messenger/messenger_api_handle.c @@ -28,8 +28,11 @@ #include "messenger_api_util.h" struct GNUNET_MESSENGER_Handle* -create_handle (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_MESSENGER_IdentityCallback identity_callback, - void *identity_cls, GNUNET_MESSENGER_MessageCallback msg_callback, void *msg_cls) +create_handle (const struct GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_MESSENGER_IdentityCallback identity_callback, + void *identity_cls, + GNUNET_MESSENGER_MessageCallback msg_callback, + void *msg_cls) { GNUNET_assert(cfg); @@ -58,7 +61,9 @@ create_handle (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_MESSENGER_I } static int -iterate_destroy_room (void *cls, const struct GNUNET_HashCode *key, void *value) +iterate_destroy_room (void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_MESSENGER_Room *room = value; @@ -97,7 +102,8 @@ destroy_handle (struct GNUNET_MESSENGER_Handle *handle) } void -set_handle_name (struct GNUNET_MESSENGER_Handle *handle, const char *name) +set_handle_name (struct GNUNET_MESSENGER_Handle *handle, + const char *name) { GNUNET_assert(handle); @@ -116,7 +122,8 @@ get_handle_name (const struct GNUNET_MESSENGER_Handle *handle) } void -set_handle_key (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_IDENTITY_PublicKey *pubkey) +set_handle_key (struct GNUNET_MESSENGER_Handle *handle, + const struct GNUNET_IDENTITY_PublicKey *pubkey) { GNUNET_assert(handle); @@ -146,7 +153,8 @@ get_handle_contact_store (struct GNUNET_MESSENGER_Handle *handle) } struct GNUNET_MESSENGER_Contact* -get_handle_contact (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key) +get_handle_contact (struct GNUNET_MESSENGER_Handle *handle, + const struct GNUNET_HashCode *key) { GNUNET_assert((handle) && (key)); @@ -162,7 +170,8 @@ get_handle_contact (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_ } void -open_handle_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key) +open_handle_room (struct GNUNET_MESSENGER_Handle *handle, + const struct GNUNET_HashCode *key) { GNUNET_assert((handle) && (key)); @@ -173,7 +182,8 @@ open_handle_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_Ha } void -entry_handle_room_at (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_PeerIdentity *door, +entry_handle_room_at (struct GNUNET_MESSENGER_Handle *handle, + const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key) { GNUNET_assert((handle) && (door) && (key)); @@ -185,7 +195,8 @@ entry_handle_room_at (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNE } void -close_handle_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key) +close_handle_room (struct GNUNET_MESSENGER_Handle *handle, + const struct GNUNET_HashCode *key) { GNUNET_assert((handle) && (key)); diff --git a/src/messenger/messenger_api_handle.h b/src/messenger/messenger_api_handle.h index e6ca474f2..6a43f13a6 100644 --- a/src/messenger/messenger_api_handle.h +++ b/src/messenger/messenger_api_handle.h @@ -71,8 +71,11 @@ struct GNUNET_MESSENGER_Handle * @return New handle */ struct GNUNET_MESSENGER_Handle* -create_handle (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_MESSENGER_IdentityCallback identity_callback, - void *identity_cls, GNUNET_MESSENGER_MessageCallback msg_callback, void *msg_cls); +create_handle (const struct GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_MESSENGER_IdentityCallback identity_callback, + void *identity_cls, + GNUNET_MESSENGER_MessageCallback msg_callback, + void *msg_cls); /** * Destroys a handle and frees its memory fully from the client API. @@ -89,7 +92,8 @@ destroy_handle (struct GNUNET_MESSENGER_Handle *handle); * @param[in] name New name */ void -set_handle_name (struct GNUNET_MESSENGER_Handle *handle, const char *name); +set_handle_name (struct GNUNET_MESSENGER_Handle *handle, + const char *name); /** * Returns the current name of a given handle or NULL if no valid name was assigned yet. @@ -107,7 +111,8 @@ get_handle_name (const struct GNUNET_MESSENGER_Handle *handle); * @param[in] pubkey Public key */ void -set_handle_key (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_IDENTITY_PublicKey *pubkey); +set_handle_key (struct GNUNET_MESSENGER_Handle *handle, + const struct GNUNET_IDENTITY_PublicKey *pubkey); /** * Returns the public key of a given handle. @@ -136,7 +141,8 @@ get_handle_contact_store (struct GNUNET_MESSENGER_Handle *handle); * @return Contact */ struct GNUNET_MESSENGER_Contact* -get_handle_contact (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key); +get_handle_contact (struct GNUNET_MESSENGER_Handle *handle, + const struct GNUNET_HashCode *key); /** * Marks a room known to a handle identified by a given key as open. @@ -145,7 +151,8 @@ get_handle_contact (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_ * @param[in] key Key of room */ void -open_handle_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key); +open_handle_room (struct GNUNET_MESSENGER_Handle *handle, + const struct GNUNET_HashCode *key); /** * Adds a tunnel for a room known to a handle identified by a given key to a @@ -156,7 +163,8 @@ open_handle_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_Ha * @param[in] key Key of room */ void -entry_handle_room_at (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_PeerIdentity *door, +entry_handle_room_at (struct GNUNET_MESSENGER_Handle *handle, + const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key); /** @@ -166,6 +174,7 @@ entry_handle_room_at (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNE * @param[in] key Key of room */ void -close_handle_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key); +close_handle_room (struct GNUNET_MESSENGER_Handle *handle, + const struct GNUNET_HashCode *key); #endif //GNUNET_MESSENGER_API_HANDLE_H diff --git a/src/messenger/messenger_api_list_tunnels.c b/src/messenger/messenger_api_list_tunnels.c index 990e36878..7e77d8f2f 100644 --- a/src/messenger/messenger_api_list_tunnels.c +++ b/src/messenger/messenger_api_list_tunnels.c @@ -53,14 +53,16 @@ clear_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels) } static int -compare_list_tunnels (void *cls, struct GNUNET_MESSENGER_ListTunnel *element0, +compare_list_tunnels (void *cls, + struct GNUNET_MESSENGER_ListTunnel *element0, struct GNUNET_MESSENGER_ListTunnel *element1) { return ((int) element0->peer) - ((int) element1->peer); } void -add_to_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer) +add_to_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, + const struct GNUNET_PeerIdentity *peer) { GNUNET_assert((tunnels) && (peer)); @@ -73,7 +75,9 @@ add_to_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct } struct GNUNET_MESSENGER_ListTunnel* -find_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer, size_t *index) +find_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, + const struct GNUNET_PeerIdentity *peer, + size_t *index) { GNUNET_assert((tunnels) && (peer)); @@ -98,7 +102,8 @@ find_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GN } int -contains_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer) +contains_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, + const struct GNUNET_PeerIdentity *peer) { GNUNET_assert((tunnels) && (peer)); @@ -106,7 +111,8 @@ contains_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const struc } struct GNUNET_MESSENGER_ListTunnel* -remove_from_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, struct GNUNET_MESSENGER_ListTunnel *element) +remove_from_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, + struct GNUNET_MESSENGER_ListTunnel *element) { GNUNET_assert((tunnels) && (element)); @@ -120,7 +126,8 @@ remove_from_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, struct G } void -load_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const char *path) +load_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, + const char *path) { GNUNET_assert((tunnels) && (path)); @@ -154,7 +161,8 @@ load_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const char *pat } void -save_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const char *path) +save_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, + const char *path) { GNUNET_assert((tunnels) && (path)); diff --git a/src/messenger/messenger_api_list_tunnels.h b/src/messenger/messenger_api_list_tunnels.h index c952da3c2..0e086ee5e 100644 --- a/src/messenger/messenger_api_list_tunnels.h +++ b/src/messenger/messenger_api_list_tunnels.h @@ -67,7 +67,8 @@ clear_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels); * @param[in] peer Peer identity of tunnel */ void -add_to_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer); +add_to_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, + const struct GNUNET_PeerIdentity *peer); /** * Searches linearly through the list of tunnels peer identities for matching a @@ -85,7 +86,9 @@ add_to_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct * @return Element in the list with matching peer identity */ struct GNUNET_MESSENGER_ListTunnel* -find_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer, size_t *index); +find_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, + const struct GNUNET_PeerIdentity *peer, + size_t *index); /** * Tests linearly if the list of tunnels peer identities contains a specific @@ -96,7 +99,8 @@ find_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GN * @return #GNUNET_YES on success, otherwise #GNUNET_NO */ int -contains_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer); +contains_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, + const struct GNUNET_PeerIdentity *peer); /** * Removes a specific element from the list of tunnels peer identities and returns @@ -107,7 +111,8 @@ contains_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const struc * @return Next element in the list */ struct GNUNET_MESSENGER_ListTunnel* -remove_from_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, struct GNUNET_MESSENGER_ListTunnel *element); +remove_from_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, + struct GNUNET_MESSENGER_ListTunnel *element); /** * Loads the list of tunnels peer identities from a file under a given path. @@ -116,7 +121,8 @@ remove_from_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, struct G * @param[in] path Path of file */ void -load_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const char *path); +load_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, + const char *path); /** * Saves the list of tunnels peer identities to a file under a given path. @@ -125,6 +131,7 @@ load_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const char *pat * @param[in] path Path of file */ void -save_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const char *path); +save_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, + const char *path); #endif //GNUNET_MESSENGER_API_LIST_TUNNELS_H diff --git a/src/messenger/messenger_api_message.c b/src/messenger/messenger_api_message.c index c7364d51c..05bf654fb 100644 --- a/src/messenger/messenger_api_message.c +++ b/src/messenger/messenger_api_message.c @@ -103,7 +103,8 @@ copy_message (const struct GNUNET_MESSENGER_Message *message) } static void -destroy_message_body (enum GNUNET_MESSENGER_MessageKind kind, struct GNUNET_MESSENGER_MessageBody *body) +destroy_message_body (enum GNUNET_MESSENGER_MessageKind kind, + struct GNUNET_MESSENGER_MessageBody *body) { switch (kind) { @@ -150,7 +151,8 @@ is_message_session_bound (const struct GNUNET_MESSENGER_Message *message) } static void -fold_short_message (const struct GNUNET_MESSENGER_Message *message, struct GNUNET_MESSENGER_ShortMessage *shortened) +fold_short_message (const struct GNUNET_MESSENGER_Message *message, + struct GNUNET_MESSENGER_ShortMessage *shortened) { shortened->kind = message->header.kind; @@ -158,7 +160,8 @@ fold_short_message (const struct GNUNET_MESSENGER_Message *message, struct GNUNE } static void -unfold_short_message (struct GNUNET_MESSENGER_ShortMessage *shortened, struct GNUNET_MESSENGER_Message *message) +unfold_short_message (struct GNUNET_MESSENGER_ShortMessage *shortened, + struct GNUNET_MESSENGER_Message *message) { destroy_message_body (message->header.kind, &(message->body)); @@ -231,7 +234,8 @@ get_message_kind_size (enum GNUNET_MESSENGER_MessageKind kind) } static uint16_t -get_message_body_size (enum GNUNET_MESSENGER_MessageKind kind, const struct GNUNET_MESSENGER_MessageBody *body) +get_message_body_size (enum GNUNET_MESSENGER_MessageKind kind, + const struct GNUNET_MESSENGER_MessageBody *body) { uint16_t length = 0; @@ -283,7 +287,8 @@ get_message_size (const struct GNUNET_MESSENGER_Message *message, } static uint16_t -get_short_message_size (const struct GNUNET_MESSENGER_ShortMessage *message, int include_body) +get_short_message_size (const struct GNUNET_MESSENGER_ShortMessage *message, + int include_body) { const uint16_t minimum_size = sizeof(struct GNUNET_HashCode) + sizeof(kind_t); @@ -370,8 +375,11 @@ calc_padded_length (uint16_t length) } while (0) static void -encode_message_body (enum GNUNET_MESSENGER_MessageKind kind, const struct GNUNET_MESSENGER_MessageBody *body, - uint16_t length, char *buffer, uint16_t offset) +encode_message_body (enum GNUNET_MESSENGER_MessageKind kind, + const struct GNUNET_MESSENGER_MessageBody *body, + uint16_t length, + char *buffer, + uint16_t offset) { uint32_t version; switch (kind) @@ -445,7 +453,9 @@ encode_message_body (enum GNUNET_MESSENGER_MessageKind kind, const struct GNUNET } void -encode_message (const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, +encode_message (const struct GNUNET_MESSENGER_Message *message, + uint16_t length, + char *buffer, int include_signature) { GNUNET_assert((message) && (buffer)); @@ -466,7 +476,9 @@ encode_message (const struct GNUNET_MESSENGER_Message *message, uint16_t length, } static void -encode_short_message (const struct GNUNET_MESSENGER_ShortMessage *message, uint16_t length, char *buffer) +encode_short_message (const struct GNUNET_MESSENGER_ShortMessage *message, + uint16_t length, + char *buffer) { struct GNUNET_HashCode hash; uint16_t offset = sizeof(hash); @@ -512,8 +524,11 @@ encode_short_message (const struct GNUNET_MESSENGER_ShortMessage *message, uint1 } while (0) static uint16_t -decode_message_body (enum GNUNET_MESSENGER_MessageKind *kind, struct GNUNET_MESSENGER_MessageBody *body, - uint16_t length, const char *buffer, uint16_t offset) +decode_message_body (enum GNUNET_MESSENGER_MessageKind *kind, + struct GNUNET_MESSENGER_MessageBody *body, + uint16_t length, + const char *buffer, + uint16_t offset) { uint16_t padding = 0; @@ -593,8 +608,11 @@ decode_message_body (enum GNUNET_MESSENGER_MessageKind *kind, struct GNUNET_MESS } int -decode_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, - int include_signature, uint16_t *padding) +decode_message (struct GNUNET_MESSENGER_Message *message, + uint16_t length, + const char *buffer, + int include_signature, + uint16_t *padding) { GNUNET_assert((message) && (buffer) && (length >= get_message_kind_size(GNUNET_MESSENGER_KIND_UNKNOWN))); @@ -638,7 +656,9 @@ decode_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, const } static int -decode_short_message (struct GNUNET_MESSENGER_ShortMessage *message, uint16_t length, const char *buffer) +decode_short_message (struct GNUNET_MESSENGER_ShortMessage *message, + uint16_t length, + const char *buffer) { struct GNUNET_HashCode expected, hash; uint16_t offset = sizeof(hash); @@ -675,7 +695,9 @@ decode_short_message (struct GNUNET_MESSENGER_ShortMessage *message, uint16_t le } void -hash_message (const struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, +hash_message (const struct GNUNET_MESSENGER_Message *message, + uint16_t length, + const char *buffer, struct GNUNET_HashCode *hash) { GNUNET_assert((message) && (buffer) && (hash)); @@ -688,8 +710,11 @@ hash_message (const struct GNUNET_MESSENGER_Message *message, uint16_t length, c } void -sign_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, - const struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_Ego *ego) +sign_message (struct GNUNET_MESSENGER_Message *message, + uint16_t length, + char *buffer, + const struct GNUNET_HashCode *hash, + const struct GNUNET_MESSENGER_Ego *ego) { GNUNET_assert((message) && (buffer) && (hash) && (ego)); @@ -706,7 +731,8 @@ sign_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, char *b } int -verify_message (const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, +verify_message (const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash, const struct GNUNET_IDENTITY_PublicKey *key) { GNUNET_assert((message) && (hash) && (key)); @@ -726,7 +752,8 @@ verify_message (const struct GNUNET_MESSENGER_Message *message, const struct GNU } int -encrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_IDENTITY_PublicKey *key) +encrypt_message (struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_IDENTITY_PublicKey *key) { GNUNET_assert((message) && (key)); @@ -760,7 +787,8 @@ encrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_I } int -decrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_IDENTITY_PrivateKey *key) +decrypt_message (struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_IDENTITY_PrivateKey *key) { GNUNET_assert((message) && (key)); @@ -788,8 +816,10 @@ decrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_I } struct GNUNET_MQ_Envelope* -pack_message (struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, - const struct GNUNET_MESSENGER_Ego *ego, int mode) +pack_message (struct GNUNET_MESSENGER_Message *message, + struct GNUNET_HashCode *hash, + const struct GNUNET_MESSENGER_Ego *ego, + int mode) { GNUNET_assert(message); diff --git a/src/messenger/messenger_api_message.h b/src/messenger/messenger_api_message.h index 7ce30dc92..6aebf4014 100644 --- a/src/messenger/messenger_api_message.h +++ b/src/messenger/messenger_api_message.h @@ -107,7 +107,9 @@ get_message_size (const struct GNUNET_MESSENGER_Message *message, * @param[in] encode_signature Flag to include signature */ void -encode_message (const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, +encode_message (const struct GNUNET_MESSENGER_Message *message, + uint16_t length, + char *buffer, int include_signature); /** @@ -125,8 +127,11 @@ encode_message (const struct GNUNET_MESSENGER_Message *message, uint16_t length, * @return #GNUNET_YES on success, otherwise #GNUNET_NO */ int -decode_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, - int include_signature, uint16_t *padding); +decode_message (struct GNUNET_MESSENGER_Message *message, + uint16_t length, + const char *buffer, + int include_signature, + uint16_t *padding); /** * Calculates a hash of a given buffer with a length in bytes @@ -138,7 +143,9 @@ decode_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, const * @param[out] hash Hash */ void -hash_message (const struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, +hash_message (const struct GNUNET_MESSENGER_Message *message, + uint16_t length, + const char *buffer, struct GNUNET_HashCode *hash); /** @@ -152,8 +159,11 @@ hash_message (const struct GNUNET_MESSENGER_Message *message, uint16_t length, c * @param[in] ego EGO */ void -sign_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, - const struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_Ego *ego); +sign_message (struct GNUNET_MESSENGER_Message *message, + uint16_t length, + char *buffer, + const struct GNUNET_HashCode *hash, + const struct GNUNET_MESSENGER_Ego *ego); /** * Verifies the signature of a given message and its hash with a specific @@ -166,7 +176,8 @@ sign_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, char *b * @return #GNUNET_OK on success, otherwise #GNUNET_SYSERR */ int -verify_message (const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, +verify_message (const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash, const struct GNUNET_IDENTITY_PublicKey *key); /** @@ -179,7 +190,8 @@ verify_message (const struct GNUNET_MESSENGER_Message *message, const struct GNU * @return #GNUNET_YES on success, otherwise #GNUNET_NO */ int -encrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_IDENTITY_PublicKey *key); +encrypt_message (struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_IDENTITY_PublicKey *key); /** * Decrypts a private message using a given private key and replaces its body @@ -191,7 +203,8 @@ encrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_I * @return #GNUNET_YES on success, otherwise #GNUNET_NO */ int -decrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_IDENTITY_PrivateKey *key); +decrypt_message (struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_IDENTITY_PrivateKey *key); #define GNUNET_MESSENGER_PACK_MODE_ENVELOPE 0x1 #define GNUNET_MESSENGER_PACK_MODE_UNKNOWN 0x0 @@ -209,8 +222,10 @@ decrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_I * @return Envelope or NULL */ struct GNUNET_MQ_Envelope* -pack_message (struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, - const struct GNUNET_MESSENGER_Ego *ego, int mode); +pack_message (struct GNUNET_MESSENGER_Message *message, + struct GNUNET_HashCode *hash, + const struct GNUNET_MESSENGER_Ego *ego, + int mode); /** * Returns if a specific kind of message should be sent by a client. The function returns diff --git a/src/messenger/messenger_api_room.c b/src/messenger/messenger_api_room.c index 0d9237a2e..6e2d33f48 100644 --- a/src/messenger/messenger_api_room.c +++ b/src/messenger/messenger_api_room.c @@ -28,7 +28,8 @@ #include "messenger_api_handle.h" struct GNUNET_MESSENGER_Room* -create_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key) +create_room (struct GNUNET_MESSENGER_Handle *handle, + const struct GNUNET_HashCode *key) { GNUNET_assert((handle) && (key)); @@ -49,7 +50,9 @@ create_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCod } static int -iterate_destroy_message (void *cls, const struct GNUNET_HashCode *key, void *value) +iterate_destroy_message (void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_MESSENGER_RoomMessageEntry *entry = value; @@ -83,7 +86,8 @@ destroy_room (struct GNUNET_MESSENGER_Room *room) } const struct GNUNET_MESSENGER_Message* -get_room_message (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash) +get_room_message (const struct GNUNET_MESSENGER_Room *room, + const struct GNUNET_HashCode *hash) { GNUNET_assert((room) && (hash)); @@ -95,7 +99,8 @@ get_room_message (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_ } struct GNUNET_MESSENGER_Contact* -get_room_sender (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash) +get_room_sender (const struct GNUNET_MESSENGER_Room *room, + const struct GNUNET_HashCode *hash) { GNUNET_assert((room) && (hash)); @@ -107,8 +112,10 @@ get_room_sender (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_H } static struct GNUNET_MESSENGER_Contact* -handle_join_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) +handle_join_message (struct GNUNET_MESSENGER_Room *room, + struct GNUNET_MESSENGER_Contact *sender, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash) { if (!sender) { @@ -129,8 +136,10 @@ handle_join_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER } static void -handle_leave_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) +handle_leave_message (struct GNUNET_MESSENGER_Room *room, + struct GNUNET_MESSENGER_Contact *sender, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash) { if ((!sender) || (GNUNET_YES != GNUNET_CONTAINER_multishortmap_remove(room->members, &(message->header.sender_id), sender))) @@ -144,8 +153,10 @@ handle_leave_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGE } static void -handle_name_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) +handle_name_message (struct GNUNET_MESSENGER_Room *room, + struct GNUNET_MESSENGER_Contact *sender, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash) { if (!sender) return; @@ -154,8 +165,10 @@ handle_name_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER } static void -handle_key_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) +handle_key_message (struct GNUNET_MESSENGER_Room *room, + struct GNUNET_MESSENGER_Contact *sender, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash) { if (!sender) return; @@ -169,8 +182,10 @@ handle_key_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_ } static void -handle_id_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) +handle_id_message (struct GNUNET_MESSENGER_Room *room, + struct GNUNET_MESSENGER_Contact *sender, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash) { if ((!sender) || (GNUNET_YES != GNUNET_CONTAINER_multishortmap_remove(room->members, &(message->header.sender_id), sender)) || @@ -188,8 +203,10 @@ handle_id_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_C } static void -handle_miss_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) +handle_miss_message (struct GNUNET_MESSENGER_Room *room, + struct GNUNET_MESSENGER_Contact *sender, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash) { if ((room->contact_id) && (0 == GNUNET_memcmp(&(message->header.sender_id), room->contact_id))) { @@ -201,8 +218,10 @@ handle_miss_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER } static void -handle_delete_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) +handle_delete_message (struct GNUNET_MESSENGER_Room *room, + struct GNUNET_MESSENGER_Contact *sender, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash) { struct GNUNET_MESSENGER_RoomMessageEntry *entry = GNUNET_CONTAINER_multihashmap_get ( room->messages, &(message->body.deletion.hash) @@ -217,8 +236,10 @@ handle_delete_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENG } struct GNUNET_MESSENGER_Contact* -handle_room_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) +handle_room_message (struct GNUNET_MESSENGER_Room *room, + struct GNUNET_MESSENGER_Contact *sender, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash) { if (GNUNET_NO != GNUNET_CONTAINER_multihashmap_contains (room->messages, hash)) return sender; @@ -276,7 +297,9 @@ struct GNUNET_MESSENGER_MemberCall }; static int -iterate_local_members (void* cls, const struct GNUNET_ShortHashCode *key, void *value) +iterate_local_members (void* cls, + const struct GNUNET_ShortHashCode *key, + void *value) { struct GNUNET_MESSENGER_MemberCall *call = cls; struct GNUNET_MESSENGER_Contact *contact = value; @@ -285,7 +308,8 @@ iterate_local_members (void* cls, const struct GNUNET_ShortHashCode *key, void * } int -iterate_room_members (struct GNUNET_MESSENGER_Room *room, GNUNET_MESSENGER_MemberCallback callback, +iterate_room_members (struct GNUNET_MESSENGER_Room *room, + GNUNET_MESSENGER_MemberCallback callback, void* cls) { GNUNET_assert(room); @@ -311,7 +335,9 @@ struct GNUNET_MESSENGER_MemberFind }; static int -iterate_find_member (void* cls, const struct GNUNET_ShortHashCode *key, void *value) +iterate_find_member (void* cls, + const struct GNUNET_ShortHashCode *key, + void *value) { struct GNUNET_MESSENGER_MemberFind *find = cls; struct GNUNET_MESSENGER_Contact *contact = value; @@ -326,7 +352,8 @@ iterate_find_member (void* cls, const struct GNUNET_ShortHashCode *key, void *va } int -find_room_member (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *contact) +find_room_member (const struct GNUNET_MESSENGER_Room *room, + const struct GNUNET_MESSENGER_Contact *contact) { GNUNET_assert(room); diff --git a/src/messenger/messenger_api_room.h b/src/messenger/messenger_api_room.h index 634052272..320312f0c 100644 --- a/src/messenger/messenger_api_room.h +++ b/src/messenger/messenger_api_room.h @@ -64,7 +64,8 @@ struct GNUNET_MESSENGER_Room * @return New room */ struct GNUNET_MESSENGER_Room* -create_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key); +create_room (struct GNUNET_MESSENGER_Handle *handle, + const struct GNUNET_HashCode *key); /** * Destroys a room and frees its memory fully from the client API. @@ -83,7 +84,8 @@ destroy_room (struct GNUNET_MESSENGER_Room *room); * @return Message or NULL */ const struct GNUNET_MESSENGER_Message* -get_room_message (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash); +get_room_message (const struct GNUNET_MESSENGER_Room *room, + const struct GNUNET_HashCode *hash); /** * Returns a messages sender locally stored from a map for a given hash in a room. If no @@ -94,7 +96,8 @@ get_room_message (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_ * @return Contact of sender or NULL */ struct GNUNET_MESSENGER_Contact* -get_room_sender (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash); +get_room_sender (const struct GNUNET_MESSENGER_Room *room, + const struct GNUNET_HashCode *hash); /** * Handles a message with a given hash in a room for the client API to update @@ -110,8 +113,10 @@ get_room_sender (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_H * @return Contact of sender */ struct GNUNET_MESSENGER_Contact* -handle_room_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); +handle_room_message (struct GNUNET_MESSENGER_Room *room, + struct GNUNET_MESSENGER_Contact *sender, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash); /** * Iterates through all members of a given room to forward each of them to a selected @@ -123,7 +128,8 @@ handle_room_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER * @return Amount of members iterated */ int -iterate_room_members (struct GNUNET_MESSENGER_Room *room, GNUNET_MESSENGER_MemberCallback callback, +iterate_room_members (struct GNUNET_MESSENGER_Room *room, + GNUNET_MESSENGER_MemberCallback callback, void* cls); /** @@ -135,6 +141,7 @@ iterate_room_members (struct GNUNET_MESSENGER_Room *room, GNUNET_MESSENGER_Membe * @return #GNUNET_YES if found, otherwise #GNUNET_NO */ int -find_room_member (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *contact); +find_room_member (const struct GNUNET_MESSENGER_Room *room, + const struct GNUNET_MESSENGER_Contact *contact); #endif //GNUNET_MESSENGER_API_ROOM_H diff --git a/src/messenger/messenger_api_util.c b/src/messenger/messenger_api_util.c index 4ad00c45e..52b4e934a 100644 --- a/src/messenger/messenger_api_util.c +++ b/src/messenger/messenger_api_util.c @@ -45,7 +45,8 @@ delayed_disconnect_channel (struct GNUNET_CADET_Channel *channel) } int -generate_free_member_id (struct GNUNET_ShortHashCode *id, const struct GNUNET_CONTAINER_MultiShortmap *members) +generate_free_member_id (struct GNUNET_ShortHashCode *id, + const struct GNUNET_CONTAINER_MultiShortmap *members) { GNUNET_assert(id); @@ -84,7 +85,8 @@ get_anonymous_public_key () } void -convert_messenger_key_to_port(const struct GNUNET_HashCode *key, struct GNUNET_HashCode *port) +convert_messenger_key_to_port(const struct GNUNET_HashCode *key, + struct GNUNET_HashCode *port) { static uint32_t version_value = 0; static struct GNUNET_HashCode version; diff --git a/src/messenger/messenger_api_util.h b/src/messenger/messenger_api_util.h index af562a1e8..af64790b6 100644 --- a/src/messenger/messenger_api_util.h +++ b/src/messenger/messenger_api_util.h @@ -51,7 +51,8 @@ delayed_disconnect_channel (struct GNUNET_CADET_Channel *channel); * @return #GNUNET_YES on success, #GNUNET_NO on failure */ int -generate_free_member_id (struct GNUNET_ShortHashCode *id, const struct GNUNET_CONTAINER_MultiShortmap *members); +generate_free_member_id (struct GNUNET_ShortHashCode *id, + const struct GNUNET_CONTAINER_MultiShortmap *members); /** * Returns the public identity key of #GNUNET_IDENTITY_ego_get_anonymous() without @@ -73,6 +74,7 @@ get_anonymous_public_key (); * @param[out] port CADET service port */ void -convert_messenger_key_to_port(const struct GNUNET_HashCode *key, struct GNUNET_HashCode *port); +convert_messenger_key_to_port(const struct GNUNET_HashCode *key, + struct GNUNET_HashCode *port); #endif //GNUNET_SERVICE_MESSENGER_UTIL_H diff --git a/src/messenger/test_messenger.c b/src/messenger/test_messenger.c index fb3e3e1bc..5784dfd82 100644 --- a/src/messenger/test_messenger.c +++ b/src/messenger/test_messenger.c @@ -100,7 +100,8 @@ static int identity_counter = 0; * @param handle Handle of messenger service */ static void -on_identity (void *cls, struct GNUNET_MESSENGER_Handle *handle) +on_identity (void *cls, + struct GNUNET_MESSENGER_Handle *handle) { if (op_task) { @@ -150,7 +151,9 @@ on_identity (void *cls, struct GNUNET_MESSENGER_Handle *handle) * @param peer Peer for testing */ static void -run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer) +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) { die_task = GNUNET_SCHEDULER_add_delayed (TOTAL_TIMEOUT, &end_badly, NULL); @@ -168,7 +171,8 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TES * @return 0 ok, 1 on error */ int -main (int argc, char **argv) +main (int argc, + char **argv) { if (0 != GNUNET_TESTING_peer_run ("test-messenger", "test_messenger_api.conf", &run, NULL)) return 1; diff --git a/src/messenger/test_messenger_adapt.c b/src/messenger/test_messenger_adapt.c index 90e8ac28d..3230af6b7 100644 --- a/src/messenger/test_messenger_adapt.c +++ b/src/messenger/test_messenger_adapt.c @@ -33,7 +33,8 @@ * @return 0 ok, 1 on error */ int -main (int argc, char **argv) +main (int argc, + char **argv) { unsigned int doors [] = { 5, 1, 2, 3, 6, 7, 8, 4 }; unsigned int stages [] = { 0x21, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x21 }; diff --git a/src/messenger/test_messenger_anonymous.c b/src/messenger/test_messenger_anonymous.c index a70121a30..8cb339f0e 100644 --- a/src/messenger/test_messenger_anonymous.c +++ b/src/messenger/test_messenger_anonymous.c @@ -96,7 +96,8 @@ end_operation (void *cls) * @param handle Handle of messenger service */ static void -on_identity (void *cls, struct GNUNET_MESSENGER_Handle *handle) +on_identity (void *cls, + struct GNUNET_MESSENGER_Handle *handle) { if (op_task) { @@ -144,7 +145,9 @@ on_identity (void *cls, struct GNUNET_MESSENGER_Handle *handle) * @param peer Peer for testing */ static void -run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer) +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) { die_task = GNUNET_SCHEDULER_add_delayed (TOTAL_TIMEOUT, &end_badly, NULL); @@ -160,7 +163,8 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TES * @return 0 ok, 1 on error */ int -main (int argc, char **argv) +main (int argc, + char **argv) { if (0 != GNUNET_TESTING_peer_run ("test-messenger", "test_messenger_api.conf", &run, NULL)) return 1; diff --git a/src/messenger/test_messenger_async_client.c b/src/messenger/test_messenger_async_client.c index 1067b9a6d..8404195dc 100644 --- a/src/messenger/test_messenger_async_client.c +++ b/src/messenger/test_messenger_async_client.c @@ -33,7 +33,8 @@ * @return 0 ok, 1 on error */ int -main (int argc, char **argv) +main (int argc, + char **argv) { unsigned int doors [] = { 0, 1 }; unsigned int stages [] = { 0x10, 0x20 }; diff --git a/src/messenger/test_messenger_async_p2p.c b/src/messenger/test_messenger_async_p2p.c index d827aae16..25746f7ff 100644 --- a/src/messenger/test_messenger_async_p2p.c +++ b/src/messenger/test_messenger_async_p2p.c @@ -33,7 +33,8 @@ * @return 0 ok, 1 on error */ int -main (int argc, char **argv) +main (int argc, + char **argv) { unsigned int doors [] = { 2, 1 }; unsigned int stages [] = { 0x30, 0x30 }; diff --git a/src/messenger/test_messenger_growth.c b/src/messenger/test_messenger_growth.c index 3781f3ee5..c3f243cbf 100644 --- a/src/messenger/test_messenger_growth.c +++ b/src/messenger/test_messenger_growth.c @@ -33,7 +33,8 @@ * @return 0 ok, 1 on error */ int -main (int argc, char **argv) +main (int argc, + char **argv) { unsigned int doors [] = { 0, 1, 1, 1, 1, 1, 1, 1 }; unsigned int stages [] = { 0x01, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21 }; diff --git a/src/messenger/test_messenger_ring.c b/src/messenger/test_messenger_ring.c index 07cfd0c47..777d79eb8 100644 --- a/src/messenger/test_messenger_ring.c +++ b/src/messenger/test_messenger_ring.c @@ -33,7 +33,8 @@ * @return 0 ok, 1 on error */ int -main (int argc, char **argv) +main (int argc, + char **argv) { unsigned int doors [] = { 8, 1, 2, 3, 4, 5, 6, 7 }; unsigned int stages [] = { 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21 }; diff --git a/src/messenger/test_messenger_server.c b/src/messenger/test_messenger_server.c index 1cf2fcc27..61e96e879 100644 --- a/src/messenger/test_messenger_server.c +++ b/src/messenger/test_messenger_server.c @@ -33,7 +33,8 @@ * @return 0 ok, 1 on error */ int -main (int argc, char **argv) +main (int argc, + char **argv) { unsigned int doors [] = { 0, 1, 1, 1, 1, 1, 1, 1 }; unsigned int stages [] = { 0x01, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }; diff --git a/src/messenger/test_messenger_sync_client.c b/src/messenger/test_messenger_sync_client.c index 99f26b018..02d90a61d 100644 --- a/src/messenger/test_messenger_sync_client.c +++ b/src/messenger/test_messenger_sync_client.c @@ -33,7 +33,8 @@ * @return 0 ok, 1 on error */ int -main (int argc, char **argv) +main (int argc, + char **argv) { unsigned int doors [] = { 0, 1 }; unsigned int stages [] = { 0x01, 0x20 }; diff --git a/src/messenger/test_messenger_sync_p2p.c b/src/messenger/test_messenger_sync_p2p.c index 77ce280a1..0a900a39e 100644 --- a/src/messenger/test_messenger_sync_p2p.c +++ b/src/messenger/test_messenger_sync_p2p.c @@ -33,7 +33,8 @@ * @return 0 ok, 1 on error */ int -main (int argc, char **argv) +main (int argc, + char **argv) { unsigned int doors [] = { 2, 1 }; unsigned int stages [] = { 0x21, 0x21 }; diff --git a/src/messenger/test_messenger_worst_client.c b/src/messenger/test_messenger_worst_client.c index 63826631c..a3d5aafec 100644 --- a/src/messenger/test_messenger_worst_client.c +++ b/src/messenger/test_messenger_worst_client.c @@ -33,7 +33,8 @@ * @return 0 ok, 1 on error */ int -main (int argc, char **argv) +main (int argc, + char **argv) { unsigned int doors [] = { 0, 1 }; unsigned int stages [] = { 0x10, 0x02 }; diff --git a/src/messenger/test_messenger_worst_p2p.c b/src/messenger/test_messenger_worst_p2p.c index c89288eea..89e54cfbd 100644 --- a/src/messenger/test_messenger_worst_p2p.c +++ b/src/messenger/test_messenger_worst_p2p.c @@ -33,7 +33,8 @@ * @return 0 ok, 1 on error */ int -main (int argc, char **argv) +main (int argc, + char **argv) { unsigned int doors [] = { 2, 1 }; unsigned int stages [] = { 0x12, 0x12 }; diff --git a/src/messenger/testing_messenger_barrier.c b/src/messenger/testing_messenger_barrier.c index 618d255b7..a95ea9ef1 100644 --- a/src/messenger/testing_messenger_barrier.c +++ b/src/messenger/testing_messenger_barrier.c @@ -61,7 +61,8 @@ GNUNET_init_barrier (unsigned int requirement, } static void -exit_status (struct GNUNET_BarrierHandle *barrier, int status); +exit_status (struct GNUNET_BarrierHandle *barrier, + int status); static void cancel_barrier (void *cls) @@ -96,7 +97,8 @@ struct GNUNET_BarrierWaitHandle }; static void -exit_status (struct GNUNET_BarrierHandle *barrier, int status) +exit_status (struct GNUNET_BarrierHandle *barrier, + int status) { struct GNUNET_BarrierWaitHandle *waiting = barrier->head; while (waiting) diff --git a/src/messenger/testing_messenger_setup.c b/src/messenger/testing_messenger_setup.c index 98241fa08..3cde8c9bb 100644 --- a/src/messenger/testing_messenger_setup.c +++ b/src/messenger/testing_messenger_setup.c @@ -204,7 +204,9 @@ end_error_cb (void *cls) } static void -barrier2_wait_cb (void *cls, struct GNUNET_BarrierWaitHandle *waiting, int status) +barrier2_wait_cb (void *cls, + struct GNUNET_BarrierWaitHandle *waiting, + int status) { struct test_peer *peer = cls; @@ -215,7 +217,9 @@ barrier2_wait_cb (void *cls, struct GNUNET_BarrierWaitHandle *waiting, int statu } static void -barrier_wait_cb (void *cls, struct GNUNET_BarrierWaitHandle *waiting, int status) +barrier_wait_cb (void *cls, + struct GNUNET_BarrierWaitHandle *waiting, + int status) { struct test_peer *peer = cls; @@ -259,8 +263,11 @@ barrier_wait_cb (void *cls, struct GNUNET_BarrierWaitHandle *waiting, int status * @param flags Flags of message */ static void -on_message (void *cls, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *sender, - const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, +on_message (void *cls, + struct GNUNET_MESSENGER_Room *room, + const struct GNUNET_MESSENGER_Contact *sender, + const struct GNUNET_MESSENGER_Message *message, + const struct GNUNET_HashCode *hash, enum GNUNET_MESSENGER_MessageFlags flags) { struct test_peer *peer = cls; @@ -340,7 +347,9 @@ second_stage (void *cls) } static void -on_peer (void *cb_cls, struct GNUNET_TESTBED_Operation *op, const struct GNUNET_TESTBED_PeerInformation *pinfo, +on_peer (void *cb_cls, + struct GNUNET_TESTBED_Operation *op, + const struct GNUNET_TESTBED_PeerInformation *pinfo, const char *emsg) { struct test_peer *peer = cb_cls; @@ -396,7 +405,8 @@ on_peer (void *cb_cls, struct GNUNET_TESTBED_Operation *op, const struct GNUNET_ * @param event Information about the event */ static void -run (void *cls, const struct GNUNET_TESTBED_EventInformation *event) +run (void *cls, + const struct GNUNET_TESTBED_EventInformation *event) { struct test_properties *properties = cls; @@ -420,7 +430,9 @@ run (void *cls, const struct GNUNET_TESTBED_EventInformation *event) } static void -barrier2_cb (void *cls, struct GNUNET_BarrierHandle *barrier, int status) +barrier2_cb (void *cls, + struct GNUNET_BarrierHandle *barrier, + int status) { struct test_properties *properties = cls; @@ -449,7 +461,9 @@ barrier2_cb (void *cls, struct GNUNET_BarrierHandle *barrier, int status) } static void -barrier_cb (void *cls, struct GNUNET_BarrierHandle *barrier, int status) +barrier_cb (void *cls, + struct GNUNET_BarrierHandle *barrier, + int status) { struct test_properties *properties = cls; @@ -485,8 +499,12 @@ barrier_cb (void *cls, struct GNUNET_BarrierHandle *barrier, int status) } static void -init (void *cls, struct GNUNET_TESTBED_RunHandle *h, unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers, - unsigned int links_succeeded, unsigned int links_failed) +init (void *cls, + struct GNUNET_TESTBED_RunHandle *h, + unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers, + unsigned int links_succeeded, + unsigned int links_failed) { struct test_properties *properties = cls; @@ -500,7 +518,8 @@ init (void *cls, struct GNUNET_TESTBED_RunHandle *h, unsigned int num_peers, str } int -GNUNET_run_messenger_setup (const char* test_name, const struct test_configuration *cfg) +GNUNET_run_messenger_setup (const char* test_name, + const struct test_configuration *cfg) { struct test_properties properties; memset(&properties, 0, sizeof(properties)); diff --git a/src/messenger/testing_messenger_setup.h b/src/messenger/testing_messenger_setup.h index 5e6b5d461..e5ae0c151 100644 --- a/src/messenger/testing_messenger_setup.h +++ b/src/messenger/testing_messenger_setup.h @@ -34,6 +34,7 @@ struct test_configuration }; int -GNUNET_run_messenger_setup (const char* test_name, const struct test_configuration *cfg); +GNUNET_run_messenger_setup (const char* test_name, + const struct test_configuration *cfg); #endif /* GNUNET_TESTING_MESSENGER_SETUP_H_ */ -- cgit v1.2.3 From f146e80752e73247acb9d6c7463188a82d26a774 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 4 Oct 2021 12:15:43 +0200 Subject: -taking a first stab at cleaning up the testing mess --- src/dhtu/Makefile.am | 15 + src/dhtu/test_dhtu_ip.c | 39 +-- src/dhtu/testing_dhtu_cmd_send.c | 170 +++++++++ src/include/gnunet_testing_ng_lib.h | 100 +++--- src/testing/Makefile.am | 1 + src/testing/testing_api_cmd_batch.c | 22 +- ...testing_api_cmd_block_until_all_peers_started.c | 4 +- .../testing_api_cmd_block_until_external_trigger.c | 6 +- src/testing/testing_api_cmd_hello_world.c | 65 ++-- src/testing/testing_api_cmd_hello_world_birth.c | 10 +- src/testing/testing_api_cmd_local_test_finished.c | 49 +-- src/testing/testing_api_cmd_netjail_start.c | 47 ++- .../testing_api_cmd_netjail_start_testsystem.c | 5 +- .../testing_api_cmd_netjail_start_testsystem_v2.c | 5 +- src/testing/testing_api_cmd_netjail_start_v2.c | 20 +- src/testing/testing_api_cmd_netjail_stop.c | 49 +-- .../testing_api_cmd_netjail_stop_testsystem.c | 35 +- .../testing_api_cmd_netjail_stop_testsystem_v2.c | 32 +- src/testing/testing_api_cmd_netjail_stop_v2.c | 42 ++- src/testing/testing_api_cmd_send_peer_ready.c | 29 +- src/testing/testing_api_cmd_system_create.c | 4 +- src/testing/testing_api_cmd_system_destroy.c | 33 +- src/testing/testing_api_loop.c | 388 ++++++--------------- src/testing/testing_api_trait_cmd.c | 2 +- src/testing/testing_api_traits.c | 2 +- 25 files changed, 555 insertions(+), 619 deletions(-) create mode 100644 src/dhtu/testing_dhtu_cmd_send.c (limited to 'src') diff --git a/src/dhtu/Makefile.am b/src/dhtu/Makefile.am index 61ca84ee3..772bee60a 100644 --- a/src/dhtu/Makefile.am +++ b/src/dhtu/Makefile.am @@ -41,6 +41,21 @@ libgnunet_plugin_dhtu_gnunet_la_LDFLAGS = \ $(GN_PLUGIN_LDFLAGS) +lib_LTLIBRARIES = \ + libgnunettestingdhtu.la + +libgnunettestingdhtu_la_SOURCES = \ + testing_dhtu_cmd_send.c +libgnunettestingdhtu_la_LIBADD = \ + $(top_builddir)/src/testing/libgnunettesting.la \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(LTLIBINTL) +libgnunettestingdhtu_la_LDFLAGS = \ + $(GN_LIB_LDFLAGS) \ + -version-info 0:0:0 + + + test_dhtu_ip_SOURCES = \ test_dhtu_ip.c test_dhtu_ip_LDADD = \ diff --git a/src/dhtu/test_dhtu_ip.c b/src/dhtu/test_dhtu_ip.c index f350905b8..eb886e994 100644 --- a/src/dhtu/test_dhtu_ip.c +++ b/src/dhtu/test_dhtu_ip.c @@ -32,20 +32,9 @@ #define CONFIG_FILE "test_dhtu_ip.conf" -/** - * Return value of the test. - * - */ -static int rv; - - -/** - * Main function to run the test cases. - * - * @param cls not used. - */ -static void -run (void *cls) +int +main (int argc, + char *const *argv) { struct GNUNET_TESTING_Command commands[] = { GNUNET_TESTING_cmd_netjail_start_v2 ("netjail-start", @@ -55,23 +44,7 @@ run (void *cls) GNUNET_TESTING_cmd_end () }; - (void) cls; - if (GNUNET_OK != - GNUNET_TESTING_run (NULL, /* config file */ - commands, - TIMEOUT)) - { - GNUNET_break (0); - rv = EXIT_FAILURE; - } -} - - -int -main (int argc, - char *const *argv) -{ - GNUNET_SCHEDULER_run (&run, - NULL); - return rv; + return GNUNET_TESTING_main (NULL, + commands, + TIMEOUT); } diff --git a/src/dhtu/testing_dhtu_cmd_send.c b/src/dhtu/testing_dhtu_cmd_send.c new file mode 100644 index 000000000..129a31205 --- /dev/null +++ b/src/dhtu/testing_dhtu_cmd_send.c @@ -0,0 +1,170 @@ +/* + 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_dhtu_cmd_send.c + * @brief use DHTU to send a message + * @author Christian Grothoff + */ +#include "platform.h" +#include "gnunet_testing_ng_lib.h" + + +/** + * State for the 'send' command. + */ +struct SendState +{ + + /** + * Function to call when done. + */ + GNUNET_SCHEDULER_TaskCallback cont; + + /** + * Closure for @e cont. + */ + void *cont_cls; + + enum GNUNET_GenericReturnValue finished; +}; + + +/** + * + * + * @param cls a `struct SendState` + */ +static void +send_cleanup (void *cls) +{ + struct SendState *ss = cls; + + GNUNET_free (ss); +} + + +/** + * Return trains of the ``send`` command. + * + * @param cls closure. + * @param[out] ret result + * @param trait name of the trait. + * @param index index number of the object to offer. + * @return #GNUNET_OK on success. + * #GNUNET_NO if no trait was found + */ +static enum GNUNET_GenericReturnValue +send_traits (void *cls, + const void **ret, + const char *trait, + unsigned int index) +{ + return GNUNET_NO; +} + + +/** + * Run the 'send' command. + * + * @param cls closure. + * @param is interpreter state. + */ +static void +send_run (void *cls, + struct GNUNET_TESTING_Interpreter *is) +{ + struct SendState *ss = cls; + +#if 0 + other_cmd = GNUNET_TESTING_interpreter_lookup_command (ss->other_label); + GNUNET_TESTING_get_trait_XXX (other_cmd, + &data); +#endif + ss->finished = GNUNET_OK; +} + + +/** + * This function checks the flag NetJailState#finished, if this cmd finished. + * + * @param cls a `struct SendState` + * @param cont function to call upon completion, can be NULL + * @param cont_cls closure for @a cont + * @return + * #GNUNET_NO if the command is still running and @a cont will be called later + * #GNUNET_OK if the command completed successfully and @a cont was called + * #GNUNET_SYSERR if the operation @a cont was NOT called + */ +static enum GNUNET_GenericReturnValue +send_finish (void *cls, + GNUNET_SCHEDULER_TaskCallback cont, + void *cont_cls) +{ + struct SendState *ss = cls; + + switch (ss->finished) + { + case GNUNET_OK: + cont (cont_cls); + break; + case GNUNET_SYSERR: + GNUNET_break (0); + break; + case GNUNET_NO: + if (NULL != ss->cont) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + ss->cont = cont; + ss->cont_cls = cont_cls; + break; + } + return ss->finished; +} + + +/** + * Create 'send' command. + * + * @param label name for command. + * @return command. + */ +struct GNUNET_TESTING_Command +GNUNET_TESTING_DHTU_cmd_send (const char *label) +{ + struct SendState *ss; + + ss = GNUNET_new (struct SendState); + + { + struct GNUNET_TESTING_Command cmd = { + .cls = ss, + .label = label, + .run = &send_run, + .finish = &send_finish, + .cleanup = &send_cleanup, + .traits = &send_traits + }; + + return cmd; + } +} diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h index 31665f8f7..363c7ff0c 100644 --- a/src/include/gnunet_testing_ng_lib.h +++ b/src/include/gnunet_testing_ng_lib.h @@ -279,15 +279,16 @@ struct GNUNET_TESTING_Command * the asynchronous activity to terminate. * * @param cls closure - * @param cmd command being run - * @param i interpreter state + * @param is interpreter state */ void (*run)(void *cls, - const struct GNUNET_TESTING_Command *cmd, - struct GNUNET_TESTING_Interpreter *i); + struct GNUNET_TESTING_Interpreter *is); /** + * FIXME: logic is basically always the same! + * => Refactor API to avoid duplication! + * * Wait for any asynchronous execution of @e run to conclude, * then call finish_cont. Finish may only be called once per command. * @@ -297,27 +298,24 @@ struct GNUNET_TESTING_Command * @param cls closure * @param cont function to call upon completion, can be NULL * @param cont_cls closure for @a cont + * @return + * #GNUNET_NO if the command is still running and @a cont will be called later + * #GNUNET_OK if the command completed successfully and @a cont was called + * #GNUNET_SYSERR if the operation @a cont was NOT called */ - int + enum GNUNET_GenericReturnValue (*finish)(void *cls, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls); - /** - * Task for running the finish function. - */ - struct GNUNET_SCHEDULER_Task *finish_task; - /** * Clean up after the command. Run during forced termination * (CTRL-C) or test failure or test success. * * @param cls closure - * @param cmd command being cleaned up */ void - (*cleanup)(void *cls, - const struct GNUNET_TESTING_Command *cmd); + (*cleanup)(void *cls); /** * Extract information from a command that is useful for other @@ -327,9 +325,10 @@ struct GNUNET_TESTING_Command * @param[out] ret result (could be anything) * @param trait name of the trait * @param index index number of the object to extract. - * @return #GNUNET_OK on success + * @return #GNUNET_OK on success, + * #GNUNET_NO if no trait was found */ - int + enum GNUNET_GenericReturnValue (*traits)(void *cls, const void **ret, const char *trait, @@ -382,41 +381,16 @@ struct GNUNET_TESTING_Command }; -/** - * Struct to use for command-specific context information closure of a command waiting - * for another command. - */ -struct SyncState -{ - /** - * Closure for all commands with command-specific context information. - */ - void *cls; - - /** - * The asynchronous command the synchronous command of this closure waits for. - */ - const struct GNUNET_TESTING_Command *async_cmd; - - /** - * Task for running the finish method of the asynchronous task the command is waiting for. - */ - struct GNUNET_SCHEDULER_Task *finish_task; - - /** - * When did the execution of this commands finish function start? - */ - struct GNUNET_TIME_Absolute start_finish_time; -}; - /** * Lookup command by label. * + * @param is interpreter to lookup command in * @param label label of the command to lookup. * @return the command, if it is found, or NULL. */ const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command ( + struct GNUNET_TESTING_Interpreter *is, const char *label); @@ -437,7 +411,7 @@ GNUNET_TESTING_interpreter_get_current_label ( * @param is interpreter state. */ void -GNUNET_TESTING_interpreter_fail (); +GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is); /** @@ -455,8 +429,8 @@ GNUNET_TESTING_cmd_end (void); * @param cmd command to make synchronous. * @return a finish-command. */ -const struct GNUNET_TESTING_Command -GNUNET_TESTING_cmd_make_unblocking (const struct GNUNET_TESTING_Command cmd); +struct GNUNET_TESTING_Command +GNUNET_TESTING_cmd_make_unblocking (struct GNUNET_TESTING_Command cmd); /** @@ -492,19 +466,10 @@ GNUNET_TESTING_cmd_rewind_ip (const char *label, /** - * Wait until we receive SIGCHLD signal. Then obtain the process trait of the - * current command, wait on the the zombie and continue with the next command. - * - * @param is interpreter state. - */ -// void -// GNUNET_TESTING_wait_for_sigchld (struct GNUNET_TESTING_Interpreter *is); -// => replace with child_management.c - - -/** - * Start scheduling loop with signal handlers and run the - * test suite with the @a commands. + * Run the testsuite. Note, CMDs are copied into + * the interpreter state because they are _usually_ + * defined into the "run" method that returns after + * having scheduled the test interpreter. * * @param cfg_name name of configuration file to use * @param commands the list of command to execute @@ -513,12 +478,28 @@ GNUNET_TESTING_cmd_rewind_ip (const char *label, * non-GNUNET_OK codes are #GNUNET_SYSERR most of the * times. */ -int +enum GNUNET_GenericReturnValue GNUNET_TESTING_run (const char *cfg_filename, struct GNUNET_TESTING_Command *commands, struct GNUNET_TIME_Relative timeout); +/** + * Start a GNUnet scheduler event loop and + * run the testsuite. Return 0 upon success. + * Expected to be called directly from main(). + * + * @param cfg_name name of configuration file to use + * @param commands the list of command to execute + * @param timeout how long to wait for each command to execute + * @return EXIT_SUCCESS on success, EXIT_FAILURE on failure + */ +int +GNUNET_TESTING_main (const char *cfg_filename, + struct GNUNET_TESTING_Command *commands, + struct GNUNET_TIME_Relative timeout); + + /** * Look for substring in a programs' name. * @@ -1191,4 +1172,5 @@ struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_local_test_finished (const char *label, TESTING_CMD_HELPER_write_cb write_message); + #endif diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am index efb22b279..3e0d4d443 100644 --- a/src/testing/Makefile.am +++ b/src/testing/Makefile.am @@ -44,6 +44,7 @@ libgnunet_test_testing_plugin_testcmd_la_LDFLAGS = \ libgnunettesting_la_SOURCES = \ testing_api_cmd_local_test_finished.c \ + testing_api_cmd_finish.c \ testing_api_cmd_send_peer_ready.c \ testing_api_cmd_block_until_all_peers_started.c \ testing_api_cmd_block_until_external_trigger.c \ diff --git a/src/testing/testing_api_cmd_batch.c b/src/testing/testing_api_cmd_batch.c index af260f80d..e39489616 100644 --- a/src/testing/testing_api_cmd_batch.c +++ b/src/testing/testing_api_cmd_batch.c @@ -38,6 +38,11 @@ struct BatchState */ struct GNUNET_TESTING_Command *batch; + /** + * Our label. + */ + const char *label; + /** * Internal command pointer. */ @@ -49,12 +54,10 @@ struct BatchState * Run the command. * * @param cls closure. - * @param cmd the command being executed. * @param is the interpreter state. */ static void batch_run (void *cls, - const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is) { struct BatchState *bs = cls; @@ -69,7 +72,7 @@ batch_run (void *cls, { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Exiting from batch: %s\n", - cmd->label); + bs->label); return; } bs->batch[bs->batch_ip].start_time @@ -77,7 +80,6 @@ batch_run (void *cls, = GNUNET_TIME_absolute_get (); bs->batch[bs->batch_ip].num_tries = 1; bs->batch[bs->batch_ip].run (bs->batch[bs->batch_ip].cls, - &bs->batch[bs->batch_ip], is); } @@ -87,20 +89,16 @@ batch_run (void *cls, * cancel a pending operation thereof. * * @param cls closure. - * @param cmd the command which is being cleaned up. */ static void -batch_cleanup (void *cls, - const struct GNUNET_TESTING_Command *cmd) +batch_cleanup (void *cls) { struct BatchState *bs = cls; - (void) cmd; for (unsigned int i = 0; NULL != bs->batch[i].label; i++) - bs->batch[i].cleanup (bs->batch[i].cls, - &bs->batch[i]); + bs->batch[i].cleanup (bs->batch[i].cls); GNUNET_free (bs->batch); GNUNET_free (bs); } @@ -115,7 +113,7 @@ batch_cleanup (void *cls, * @param index index number of the object to offer. * @return #GNUNET_OK on success. */ -static int +static enum GNUNET_GenericReturnValue batch_traits (void *cls, const void **ret, const char *trait, @@ -162,7 +160,7 @@ GNUNET_TESTING_cmd_batch (const char *label, unsigned int i; bs = GNUNET_new (struct BatchState); - + bs->label = label; /* Get number of commands. */ for (i = 0; NULL != batch[i].label; i++) /* noop */ diff --git a/src/testing/testing_api_cmd_block_until_all_peers_started.c b/src/testing/testing_api_cmd_block_until_all_peers_started.c index e9d3f0ed3..fb51c1066 100644 --- a/src/testing/testing_api_cmd_block_until_all_peers_started.c +++ b/src/testing/testing_api_cmd_block_until_all_peers_started.c @@ -65,8 +65,7 @@ block_until_all_peers_started_traits (void *cls, * */ static void -block_until_all_peers_started_cleanup (void *cls, - const struct GNUNET_TESTING_Command *cmd) +block_until_all_peers_started_cleanup (void *cls) { struct BlockState *bs = cls; @@ -80,7 +79,6 @@ block_until_all_peers_started_cleanup (void *cls, */ static void block_until_all_peers_started_run (void *cls, - const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is) { LOG (GNUNET_ERROR_TYPE_DEBUG, 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 2439afeaf..d69040b75 100644 --- a/src/testing/testing_api_cmd_block_until_external_trigger.c +++ b/src/testing/testing_api_cmd_block_until_external_trigger.c @@ -56,7 +56,7 @@ block_until_all_peers_started_traits (void *cls, const char *trait, unsigned int index) { - return GNUNET_OK; + return GNUNET_NO; } @@ -65,8 +65,7 @@ block_until_all_peers_started_traits (void *cls, * */ static void -block_until_all_peers_started_cleanup (void *cls, - const struct GNUNET_TESTING_Command *cmd) +block_until_all_peers_started_cleanup (void *cls) { struct BlockState *bs = cls; @@ -80,7 +79,6 @@ block_until_all_peers_started_cleanup (void *cls, */ static void block_until_all_peers_started_run (void *cls, - const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is) { LOG (GNUNET_ERROR_TYPE_DEBUG, diff --git a/src/testing/testing_api_cmd_hello_world.c b/src/testing/testing_api_cmd_hello_world.c index 4347ac818..73dcd6dff 100644 --- a/src/testing/testing_api_cmd_hello_world.c +++ b/src/testing/testing_api_cmd_hello_world.c @@ -32,50 +32,51 @@ struct HelloWorldState const char *birthLabel; }; + /** -* -* -* @param cls closure -* @param cmd current CMD being cleaned up. -*/ + * + * + * @param cls closure + */ static void -hello_world_cleanup (void *cls, - const struct GNUNET_TESTING_Command *cmd) +hello_world_cleanup (void *cls) { struct HelloWorldState *hs = cls; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Cleaning up message %s\n", hs->message); + GNUNET_free (hs); } + /** -* -* -* @param cls closure. -* @param[out] ret result -* @param trait name of the trait. -* @param index index number of the object to offer. -* @return #GNUNET_OK on success. -*/ -static int + * + * + * @param cls closure. + * @param[out] ret result + * @param trait name of the trait. + * @param index index number of the object to offer. + * @return #GNUNET_OK on success. + */ +static enum GNUNET_GenericReturnValue hello_world_traits (void *cls, const void **ret, const char *trait, unsigned int index) { - return GNUNET_OK; + return GNUNET_NO; } + /** * Run the "hello world" CMD. * * @param cls closure. -* @param cmd CMD being run. * @param is interpreter state. */ static void hello_world_run (void *cls, - const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is) { struct HelloWorldState *hs = cls; @@ -84,13 +85,16 @@ hello_world_run (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", hs->message); - birth_cmd = GNUNET_TESTING_interpreter_lookup_command (hs->birthLabel); - GNUNET_TESTING_get_trait_what_am_i (birth_cmd, &hs->message); + birth_cmd = GNUNET_TESTING_interpreter_lookup_command (is, + hs->birthLabel); + GNUNET_TESTING_get_trait_what_am_i (birth_cmd, + &hs->message); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Now I am a %s\n", hs->message); } + /** * Create command. * @@ -108,14 +112,15 @@ GNUNET_TESTING_cmd_hello_world (const char *label, hs = GNUNET_new (struct HelloWorldState); hs->message = "Hello World, I was nobody!"; hs->birthLabel = birthLabel; + { + struct GNUNET_TESTING_Command cmd = { + .cls = hs, + .label = label, + .run = &hello_world_run, + .cleanup = &hello_world_cleanup, + .traits = &hello_world_traits + }; - struct GNUNET_TESTING_Command cmd = { - .cls = hs, - .label = label, - .run = &hello_world_run, - .cleanup = &hello_world_cleanup, - .traits = &hello_world_traits - }; - - return cmd; + return cmd; + } } diff --git a/src/testing/testing_api_cmd_hello_world_birth.c b/src/testing/testing_api_cmd_hello_world_birth.c index 9d60059a5..8415b99f0 100644 --- a/src/testing/testing_api_cmd_hello_world_birth.c +++ b/src/testing/testing_api_cmd_hello_world_birth.c @@ -40,8 +40,7 @@ struct HelloWorldBirthState * @param cmd current CMD being cleaned up. */ static void -hello_world_birth_cleanup (void *cls, - const struct GNUNET_TESTING_Command *cmd) +hello_world_birth_cleanup (void *cls) { struct HelloWorldBirthState *hbs = cls; GNUNET_log (GNUNET_ERROR_TYPE_INFO, @@ -49,6 +48,7 @@ hello_world_birth_cleanup (void *cls, hbs->what_am_i); } + /** * * @@ -82,6 +82,7 @@ hello_world_birth_traits (void *cls, index); } + /** * Run the "hello world" CMD. * @@ -91,14 +92,13 @@ hello_world_birth_traits (void *cls, */ static void hello_world_birth_run (void *cls, - const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is) { struct HelloWorldBirthState *hbs = cls; struct GNUNET_TIME_Relative relative; relative = GNUNET_TIME_absolute_get_difference (*hbs->date, - GNUNET_TIME_absolute_get ()); + GNUNET_TIME_absolute_get ()); if (0 == relative.rel_value_us % 10) { @@ -114,6 +114,7 @@ hello_world_birth_run (void *cls, } } + /** * Offer data from trait * @@ -131,6 +132,7 @@ GNUNET_TESTING_get_trait_what_am_i (const struct GNUNET_TESTING_Command *cmd, (unsigned int) 0); } + /** * Create command. * diff --git a/src/testing/testing_api_cmd_local_test_finished.c b/src/testing/testing_api_cmd_local_test_finished.c index 383de4c10..da4aff80f 100644 --- a/src/testing/testing_api_cmd_local_test_finished.c +++ b/src/testing/testing_api_cmd_local_test_finished.c @@ -19,7 +19,7 @@ */ /** - * @file testing_api_cmd_block_until_all_peers_started.c + * @file testing_api_cmd_local_test_finished.c * @brief cmd to block the interpreter loop until all peers started. * @author t3sserakt */ @@ -58,13 +58,13 @@ struct LocalFinishedState * Trait function of this cmd does nothing. * */ -static int +static enum GNUNET_GenericReturnValue local_test_finished_traits (void *cls, const void **ret, const char *trait, unsigned int index) { - return GNUNET_OK; + return GNUNET_NO; } @@ -73,8 +73,7 @@ local_test_finished_traits (void *cls, * */ static void -local_test_finished_cleanup (void *cls, - const struct GNUNET_TESTING_Command *cmd) +local_test_finished_cleanup (void *cls) { struct LocalFinishedState *lfs = cls; @@ -89,11 +88,9 @@ local_test_finished_cleanup (void *cls, */ static void local_test_finished_run (void *cls, - const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is) { struct LocalFinishedState *lfs = cls; - struct GNUNET_CMDS_LOCAL_FINISHED *reply; size_t msg_length; @@ -102,15 +99,18 @@ local_test_finished_run (void *cls, reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED); reply->header.size = htons ((uint16_t) msg_length); lfs->reply = reply; - lfs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length); + 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. + * 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 +static enum GNUNET_GenericReturnValue local_test_finished_finish (void *cls, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls) @@ -129,23 +129,24 @@ local_test_finished_finish (void *cls, * @return command. */ struct GNUNET_TESTING_Command -GNUNET_TESTING_cmd_local_test_finished (const char *label, - TESTING_CMD_HELPER_write_cb - write_message) +GNUNET_TESTING_cmd_local_test_finished ( + const char *label, + TESTING_CMD_HELPER_write_cb write_message) { struct LocalFinishedState *lfs; lfs = GNUNET_new (struct LocalFinishedState); lfs->write_message = write_message; - - struct GNUNET_TESTING_Command cmd = { - .cls = lfs, - .label = label, - .run = &local_test_finished_run, - .finish = &local_test_finished_finish, - .cleanup = &local_test_finished_cleanup, - .traits = &local_test_finished_traits - }; - - return cmd; + { + struct GNUNET_TESTING_Command cmd = { + .cls = lfs, + .label = label, + .run = &local_test_finished_run, + .finish = &local_test_finished_finish, + .cleanup = &local_test_finished_cleanup, + .traits = &local_test_finished_traits + }; + + return cmd; + } } diff --git a/src/testing/testing_api_cmd_netjail_start.c b/src/testing/testing_api_cmd_netjail_start.c index 536b356a6..1815b64d2 100644 --- a/src/testing/testing_api_cmd_netjail_start.c +++ b/src/testing/testing_api_cmd_netjail_start.c @@ -49,8 +49,10 @@ struct NetJailState */ struct GNUNET_OS_Process *start_proc; - // Flag indication if the script finished. - unsigned int finished; + /** + * Flag indication if the script finished. + */ + enum GNUNET_GenericReturnValue finished; }; @@ -59,8 +61,7 @@ struct NetJailState * */ static void -netjail_start_cleanup (void *cls, - const struct GNUNET_TESTING_Command *cmd) +netjail_start_cleanup (void *cls) { struct NetJailState *ns = cls; @@ -90,13 +91,13 @@ netjail_start_cleanup (void *cls, * Trait function of this cmd does nothing. * */ -static int +static enum GNUNET_GenericReturnValue netjail_start_traits (void *cls, const void **ret, const char *trait, unsigned int index) { - return GNUNET_OK; + return GNUNET_NO; } @@ -126,17 +127,14 @@ child_completed_callback (void *cls, } - /** * The run method starts the script which setup the network namespaces. * * @param cls closure. -* @param cmd CMD being run. * @param is interpreter state. */ static void netjail_start_run (void *cls, - const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is) { struct NetJailState *ns = cls; @@ -154,14 +152,14 @@ netjail_start_run (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No SUID for %s!\n", NETJAIL_START_SCRIPT); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); } else if (GNUNET_NO == helper_check) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s not found!\n", NETJAIL_START_SCRIPT); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); } ns->start_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR, @@ -182,7 +180,7 @@ netjail_start_run (void *cls, * This function checks the flag NetJailState#finished, if this cmd finished. * */ -static int +static enum GNUNET_GenericReturnValue netjail_start_finish (void *cls, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls) @@ -196,6 +194,7 @@ netjail_start_finish (void *cls, return ns->finished; } + /** * Create command. * @@ -214,16 +213,16 @@ GNUNET_TESTING_cmd_netjail_start (const char *label, ns = GNUNET_new (struct NetJailState); ns->local_m = local_m; ns->global_n = global_n; - ns->finished = GNUNET_NO; - - struct GNUNET_TESTING_Command cmd = { - .cls = ns, - .label = label, - .run = &netjail_start_run, - .finish = &netjail_start_finish, - .cleanup = &netjail_start_cleanup, - .traits = &netjail_start_traits - }; - - return cmd; + { + struct GNUNET_TESTING_Command cmd = { + .cls = ns, + .label = label, + .run = &netjail_start_run, + .finish = &netjail_start_finish, + .cleanup = &netjail_start_cleanup, + .traits = &netjail_start_traits + }; + + return cmd; + } } diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem.c b/src/testing/testing_api_cmd_netjail_start_testsystem.c index 531621eb5..1222ae54b 100644 --- a/src/testing/testing_api_cmd_netjail_start_testsystem.c +++ b/src/testing/testing_api_cmd_netjail_start_testsystem.c @@ -194,11 +194,9 @@ struct TestingSystemCount * Code to clean up resource this cmd used. * * @param cls closure -* @param cmd current CMD being cleaned up. */ static void -netjail_exec_cleanup (void *cls, - const struct GNUNET_TESTING_Command *cmd) +netjail_exec_cleanup (void *cls) { struct NetJailState *ns = cls; struct HelperMessage *message_pos; @@ -480,7 +478,6 @@ start_helper (struct NetJailState *ns, struct */ static void netjail_exec_run (void *cls, - const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is) { char str_m[12]; diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c b/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c index ccb3f5ae8..bb9421aa7 100644 --- a/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c +++ b/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c @@ -205,11 +205,9 @@ struct TestingSystemCount * Code to clean up resource this cmd used. * * @param cls closure -* @param cmd current CMD being cleaned up. */ static void -netjail_exec_cleanup (void *cls, - const struct GNUNET_TESTING_Command *cmd) +netjail_exec_cleanup (void *cls) { struct NetJailState *ns = cls; struct HelperMessage *message_pos; @@ -568,7 +566,6 @@ start_helper (struct NetJailState *ns, struct */ static void netjail_exec_run (void *cls, - const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is) { struct NetJailState *ns = cls; diff --git a/src/testing/testing_api_cmd_netjail_start_v2.c b/src/testing/testing_api_cmd_netjail_start_v2.c index 9123148a7..faabed98e 100644 --- a/src/testing/testing_api_cmd_netjail_start_v2.c +++ b/src/testing/testing_api_cmd_netjail_start_v2.c @@ -19,7 +19,7 @@ */ /** - * @file testing/testing_api_cmd_hello_world.c + * @file testing/testing_api_cmd_netjail_start_v2.c * @brief Command to start the netjail script. * @author t3sserakt */ @@ -59,8 +59,7 @@ struct NetJailState * */ static void -netjail_start_cleanup (void *cls, - const struct GNUNET_TESTING_Command *cmd) +netjail_start_cleanup (void *cls) { struct NetJailState *ns = cls; @@ -90,13 +89,13 @@ netjail_start_cleanup (void *cls, * Trait function of this cmd does nothing. * */ -static int +static enum GNUNET_GenericReturnValue netjail_start_traits (void *cls, const void **ret, const char *trait, unsigned int index) { - return GNUNET_OK; + return GNUNET_NO; } @@ -127,17 +126,14 @@ child_completed_callback (void *cls, } - /** * The run method starts the script which setup the network namespaces. * * @param cls closure. -* @param cmd CMD being run. * @param is interpreter state. */ static void netjail_start_run (void *cls, - const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is) { struct NetJailState *ns = cls; @@ -157,7 +153,7 @@ netjail_start_run (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No SUID for %s!\n", NETJAIL_START_SCRIPT); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); return; } if (GNUNET_SYSERR == helper_check) @@ -165,7 +161,7 @@ netjail_start_run (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s not found!\n", NETJAIL_START_SCRIPT); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); return; } @@ -180,7 +176,7 @@ netjail_start_run (void *cls, pid, NULL }; - + ns->start_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR, NULL, @@ -198,7 +194,7 @@ netjail_start_run (void *cls, /** * This function checks the flag NetJailState - * + * * FIXME: fix comment! * #finished, if this cmd finished. * diff --git a/src/testing/testing_api_cmd_netjail_stop.c b/src/testing/testing_api_cmd_netjail_stop.c index 99084d9af..c93e5cca3 100644 --- a/src/testing/testing_api_cmd_netjail_stop.c +++ b/src/testing/testing_api_cmd_netjail_stop.c @@ -19,7 +19,7 @@ */ /** - * @file testing/testing_api_cmd_hello_world.c + * @file testing/testing_api_cmd_netjail_stop.c * @brief Command to stop the netjail script. * @author t3sserakt */ @@ -60,8 +60,7 @@ struct NetJailState * */ static void -netjail_stop_cleanup (void *cls, - const struct GNUNET_TESTING_Command *cmd) +netjail_stop_cleanup (void *cls) { struct NetJailState *ns = cls; @@ -87,13 +86,13 @@ netjail_stop_cleanup (void *cls, * Trait function of this cmd does nothing. * */ -static int +static enum GNUNET_GenericReturnValue netjail_stop_traits (void *cls, const void **ret, const char *trait, unsigned int index) { - return GNUNET_OK; + return GNUNET_NO; } @@ -131,14 +130,15 @@ child_completed_callback (void *cls, */ static void netjail_stop_run (void *cls, - const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is) { struct NetJailState *ns = cls; - char *const script_argv[] = {NETJAIL_STOP_SCRIPT, - ns->local_m, - ns->global_n, - NULL}; + char *const script_argv[] = { + NETJAIL_STOP_SCRIPT, + ns->local_m, + ns->global_n, + NULL + }; unsigned int helper_check = GNUNET_OS_check_helper_binary ( NETJAIL_STOP_SCRIPT, GNUNET_YES, @@ -149,14 +149,14 @@ netjail_stop_run (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No SUID for %s!\n", NETJAIL_STOP_SCRIPT); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); } else if (GNUNET_NO == helper_check) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s not found!\n", NETJAIL_STOP_SCRIPT); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); } ns->stop_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR, @@ -178,7 +178,7 @@ netjail_stop_run (void *cls, * This function checks the flag NetJailState#finished, if this cmd finished. * */ -static int +static enum GNUNET_GenericReturnValue netjail_stop_finish (void *cls, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls) @@ -211,15 +211,16 @@ GNUNET_TESTING_cmd_netjail_stop (const char *label, ns = GNUNET_new (struct NetJailState); ns->local_m = local_m; ns->global_n = global_n; - - struct GNUNET_TESTING_Command cmd = { - .cls = ns, - .label = label, - .run = &netjail_stop_run, - .finish = &netjail_stop_finish, - .cleanup = &netjail_stop_cleanup, - .traits = &netjail_stop_traits - }; - - return cmd; + { + struct GNUNET_TESTING_Command cmd = { + .cls = ns, + .label = label, + .run = &netjail_stop_run, + .finish = &netjail_stop_finish, + .cleanup = &netjail_stop_cleanup, + .traits = &netjail_stop_traits + }; + + return cmd; + } } diff --git a/src/testing/testing_api_cmd_netjail_stop_testsystem.c b/src/testing/testing_api_cmd_netjail_stop_testsystem.c index 0ae82a26a..04b0e4e94 100644 --- a/src/testing/testing_api_cmd_netjail_stop_testsystem.c +++ b/src/testing/testing_api_cmd_netjail_stop_testsystem.c @@ -55,10 +55,8 @@ struct StopHelperState * @param cmd current CMD being cleaned up. */ static void -stop_testing_system_cleanup (void *cls, - const struct GNUNET_TESTING_Command *cmd) +stop_testing_system_cleanup (void *cls) { - } @@ -66,13 +64,13 @@ stop_testing_system_cleanup (void *cls, * Trait function of this cmd does nothing. * */ -static int +static enum GNUNET_GenericReturnValue stop_testing_system_traits (void *cls, const void **ret, const char *trait, unsigned int index) { - return GNUNET_OK; + return GNUNET_NO; } @@ -80,12 +78,10 @@ stop_testing_system_traits (void *cls, * This function stops the helper process for each node. * * @param cls closure. -* @param cmd CMD being run. * @param is interpreter state. */ static void stop_testing_system_run (void *cls, - const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is) { struct StopHelperState *shs = cls; @@ -93,6 +89,7 @@ stop_testing_system_run (void *cls, const struct GNUNET_TESTING_Command *start_helper_cmd; start_helper_cmd = GNUNET_TESTING_interpreter_lookup_command ( + is, shs->helper_start_label); GNUNET_TESTING_get_trait_helper_handles (start_helper_cmd, &helper); @@ -121,8 +118,7 @@ struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_stop_testing_system (const char *label, const char *helper_start_label, char *local_m, - char *global_n - ) + char *global_n) { struct StopHelperState *shs; @@ -130,14 +126,15 @@ GNUNET_TESTING_cmd_stop_testing_system (const char *label, shs->helper_start_label = helper_start_label; shs->local_m = local_m; shs->global_n = global_n; - - struct GNUNET_TESTING_Command cmd = { - .cls = shs, - .label = label, - .run = &stop_testing_system_run, - .cleanup = &stop_testing_system_cleanup, - .traits = &stop_testing_system_traits - }; - - return cmd; + { + struct GNUNET_TESTING_Command cmd = { + .cls = shs, + .label = label, + .run = &stop_testing_system_run, + .cleanup = &stop_testing_system_cleanup, + .traits = &stop_testing_system_traits + }; + + return cmd; + } } diff --git a/src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c b/src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c index 8eccc5764..65eb85d9a 100644 --- a/src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c +++ b/src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c @@ -52,11 +52,9 @@ struct StopHelperState * Code to clean up resource this cmd used. * * @param cls closure -* @param cmd current CMD being cleaned up. */ static void -stop_testing_system_cleanup (void *cls, - const struct GNUNET_TESTING_Command *cmd) +stop_testing_system_cleanup (void *cls) { } @@ -66,13 +64,13 @@ stop_testing_system_cleanup (void *cls, * Trait function of this cmd does nothing. * */ -static int +static enum GNUNET_GenericReturnValue stop_testing_system_traits (void *cls, const void **ret, const char *trait, unsigned int index) { - return GNUNET_OK; + return GNUNET_NO; } @@ -80,12 +78,10 @@ stop_testing_system_traits (void *cls, * This function stops the helper process for each node. * * @param cls closure. -* @param cmd CMD being run. * @param is interpreter state. */ static void stop_testing_system_run (void *cls, - const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is) { struct StopHelperState *shs = cls; @@ -93,6 +89,7 @@ stop_testing_system_run (void *cls, const struct GNUNET_TESTING_Command *start_helper_cmd; start_helper_cmd = GNUNET_TESTING_interpreter_lookup_command ( + is, shs->helper_start_label); GNUNET_TESTING_get_trait_helper_handles (start_helper_cmd, &helper); @@ -130,14 +127,15 @@ GNUNET_TESTING_cmd_stop_testing_system_v2 (const char *label, shs->helper_start_label = helper_start_label; shs->local_m = topology->nodes_m; shs->global_n = topology->namespaces_n; - - struct GNUNET_TESTING_Command cmd = { - .cls = shs, - .label = label, - .run = &stop_testing_system_run, - .cleanup = &stop_testing_system_cleanup, - .traits = &stop_testing_system_traits - }; - - return cmd; + { + struct GNUNET_TESTING_Command cmd = { + .cls = shs, + .label = label, + .run = &stop_testing_system_run, + .cleanup = &stop_testing_system_cleanup, + .traits = &stop_testing_system_traits + }; + + return cmd; + } } diff --git a/src/testing/testing_api_cmd_netjail_stop_v2.c b/src/testing/testing_api_cmd_netjail_stop_v2.c index 8c1f3cedd..348e8c9f7 100644 --- a/src/testing/testing_api_cmd_netjail_stop_v2.c +++ b/src/testing/testing_api_cmd_netjail_stop_v2.c @@ -19,7 +19,7 @@ */ /** - * @file testing/testing_api_cmd_hello_world.c + * @file testing/testing_api_cmd_netjail_stop_v2.c * @brief Command to stop the netjail script. * @author t3sserakt */ @@ -50,7 +50,7 @@ struct NetJailState struct GNUNET_OS_Process *stop_proc; // Flag indication if the script finished. - unsigned int finished; + enum GNUNET_GenericReturnValue finished; }; @@ -59,8 +59,7 @@ struct NetJailState * */ static void -netjail_stop_cleanup (void *cls, - const struct GNUNET_TESTING_Command *cmd) +netjail_stop_cleanup (void *cls) { struct NetJailState *ns = cls; @@ -86,13 +85,13 @@ netjail_stop_cleanup (void *cls, * Trait function of this cmd does nothing. * */ -static int +static enum GNUNET_GenericReturnValue netjail_stop_traits (void *cls, const void **ret, const char *trait, unsigned int index) { - return GNUNET_OK; + return GNUNET_NO; } @@ -125,12 +124,10 @@ child_completed_callback (void *cls, * The run method starts the script which deletes the network namespaces. * * @param cls closure. -* @param cmd CMD being run. * @param is interpreter state. */ static void netjail_stop_run (void *cls, - const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is) { struct NetJailState *ns = cls; @@ -152,14 +149,14 @@ netjail_stop_run (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No SUID for %s!\n", NETJAIL_STOP_SCRIPT); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); } else if (GNUNET_NO == helper_check) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s not found!\n", NETJAIL_STOP_SCRIPT); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); } ns->stop_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR, @@ -181,7 +178,7 @@ netjail_stop_run (void *cls, * This function checks the flag NetJailState#finished, if this cmd finished. * */ -static int +static enum GNUNET_GenericReturnValue netjail_stop_finish (void *cls, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls) @@ -211,15 +208,16 @@ GNUNET_TESTING_cmd_netjail_stop_v2 (const char *label, ns = GNUNET_new (struct NetJailState); ns->topology_config = topology_config; - - struct GNUNET_TESTING_Command cmd = { - .cls = ns, - .label = label, - .run = &netjail_stop_run, - .finish = &netjail_stop_finish, - .cleanup = &netjail_stop_cleanup, - .traits = &netjail_stop_traits - }; - - return cmd; + { + struct GNUNET_TESTING_Command cmd = { + .cls = ns, + .label = label, + .run = &netjail_stop_run, + .finish = &netjail_stop_finish, + .cleanup = &netjail_stop_cleanup, + .traits = &netjail_stop_traits + }; + + return cmd; + } } diff --git a/src/testing/testing_api_cmd_send_peer_ready.c b/src/testing/testing_api_cmd_send_peer_ready.c index 016837214..8b4c11deb 100644 --- a/src/testing/testing_api_cmd_send_peer_ready.c +++ b/src/testing/testing_api_cmd_send_peer_ready.c @@ -53,13 +53,13 @@ struct SendPeerReadyState * Trait function of this cmd does nothing. * */ -static int +static enum GNUNET_GenericReturnValue send_peer_ready_traits (void *cls, const void **ret, const char *trait, unsigned int index) { - return GNUNET_OK; + return GNUNET_NO; } @@ -68,8 +68,7 @@ send_peer_ready_traits (void *cls, * */ static void -send_peer_ready_cleanup (void *cls, - const struct GNUNET_TESTING_Command *cmd) +send_peer_ready_cleanup (void *cls) { struct SendPeerReadyState *sprs = cls; @@ -84,7 +83,6 @@ send_peer_ready_cleanup (void *cls, */ static void send_peer_ready_run (void *cls, - const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is) { struct SendPeerReadyState *sprs = cls; @@ -115,14 +113,15 @@ GNUNET_TESTING_cmd_send_peer_ready (const char *label, sprs = GNUNET_new (struct SendPeerReadyState); sprs->write_message = write_message; - - struct GNUNET_TESTING_Command cmd = { - .cls = sprs, - .label = label, - .run = &send_peer_ready_run, - .cleanup = &send_peer_ready_cleanup, - .traits = &send_peer_ready_traits - }; - - return cmd; + { + struct GNUNET_TESTING_Command cmd = { + .cls = sprs, + .label = label, + .run = &send_peer_ready_run, + .cleanup = &send_peer_ready_cleanup, + .traits = &send_peer_ready_traits + }; + + return cmd; + } } diff --git a/src/testing/testing_api_cmd_system_create.c b/src/testing/testing_api_cmd_system_create.c index f3a0b1a4c..820adf1bd 100644 --- a/src/testing/testing_api_cmd_system_create.c +++ b/src/testing/testing_api_cmd_system_create.c @@ -46,7 +46,6 @@ struct TestSystemState */ static void system_create_run (void *cls, - const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is) { struct TestSystemState *tss = cls; @@ -115,8 +114,7 @@ GNUNET_TESTING_get_trait_test_system (const struct * */ static void -system_create_cleanup (void *cls, - const struct GNUNET_TESTING_Command *cmd) +system_create_cleanup (void *cls) { struct TestSystemState *tss = cls; diff --git a/src/testing/testing_api_cmd_system_destroy.c b/src/testing/testing_api_cmd_system_destroy.c index 5ed0c2fd2..338123d91 100644 --- a/src/testing/testing_api_cmd_system_destroy.c +++ b/src/testing/testing_api_cmd_system_destroy.c @@ -46,17 +46,18 @@ struct TestSystemState */ static void system_destroy_run (void *cls, - const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is) { struct TestSystemState *tss = cls; const struct GNUNET_TESTING_Command *system_cmd; struct GNUNET_TESTING_System *tl_system; - system_cmd = GNUNET_TESTING_interpreter_lookup_command (tss->create_label); + 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_YES); + GNUNET_TESTING_system_destroy (tl_system, + GNUNET_YES); } @@ -65,8 +66,7 @@ system_destroy_run (void *cls, * */ static void -system_destroy_cleanup (void *cls, - const struct GNUNET_TESTING_Command *cmd) +system_destroy_cleanup (void *cls) { struct TestSystemState *tss = cls; @@ -78,7 +78,7 @@ system_destroy_cleanup (void *cls, * Trait function of this cmd does nothing. * */ -static int +static enum GNUNET_GenericReturnValue system_destroy_traits (void *cls, const void **ret, const char *trait, @@ -103,14 +103,15 @@ GNUNET_TESTING_cmd_system_destroy (const char *label, tss = GNUNET_new (struct TestSystemState); tss->create_label = create_label; - - struct GNUNET_TESTING_Command cmd = { - .cls = tss, - .label = label, - .run = &system_destroy_run, - .cleanup = &system_destroy_cleanup, - .traits = &system_destroy_traits - }; - - return cmd; + { + struct GNUNET_TESTING_Command cmd = { + .cls = tss, + .label = label, + .run = &system_destroy_run, + .cleanup = &system_destroy_cleanup, + .traits = &system_destroy_traits + }; + + return cmd; + } } diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c index 0c24c0e26..1c8eb1db6 100644 --- a/src/testing/testing_api_loop.c +++ b/src/testing/testing_api_loop.c @@ -24,67 +24,29 @@ * @author Christian Grothoff (GNU Taler testing) * @author Marcello Stanisci (GNU Taler testing) * @author t3sserakt -*/ + * + * FIXME: + * - interpreter failure is NOT returned properly yet! + * - abuse of shutdown logic for interpreter termination + * => API design flaw to be fixed! + */ #include "platform.h" #include "gnunet_util_lib.h" #include "gnunet_testing_ng_lib.h" #include "testing.h" -#define CHECK_FINISHED_PERIOD \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) - -struct GNUNET_TESTING_Interpreter *is; - - -/** - * Closure used to sync an asynchronous with an synchronous command. - */ -struct SyncTaskClosure -{ - - /** - * The asynchronous command the synchronous command waits for. - */ - const struct GNUNET_TESTING_Command *async_cmd; - - /** - * The synchronous command that waits for the asynchronous command. - */ - const struct GNUNET_TESTING_Command *sync_cmd; - - /** - * The interpreter of the test. - */ - struct GNUNET_TESTING_Interpreter *is; -}; - - -/** -* Closure used to run the finish task. -*/ -struct FinishTaskClosure -{ - - /** - * The asynchronous command the synchronous command waits for. - */ - const struct GNUNET_TESTING_Command *cmd; - - /** - * The interpreter of the test. - */ - struct GNUNET_TESTING_Interpreter *is; -}; - /** * Lookup command by label. * + * @param is interpreter to lookup command in * @param label label to look for * @return NULL if command was not found */ const struct GNUNET_TESTING_Command * -GNUNET_TESTING_interpreter_lookup_command (const char *label) +GNUNET_TESTING_interpreter_lookup_command ( + struct GNUNET_TESTING_Interpreter *is, + const char *label) { if (NULL == label) { @@ -188,211 +150,36 @@ interpreter_next (void *cls) } -/** - * This function checks if the finish function of a command returns GNUNET_YES, when the command is finished. In this case the finish function might have called interpreter_next. IF GNUNET_NO was returned this function is added to the scheduler again. In case of an error interpreter_fail is called. - * - */ -static void -run_finish_task_next (void *cls) -{ - struct FinishTaskClosure *ftc = cls; - const struct GNUNET_TESTING_Command *cmd = ftc->cmd; - struct GNUNET_TESTING_Interpreter *is = ftc->is; - unsigned int finished = cmd->finish (cmd->cls, &interpreter_next, is); - - if (GNUNET_YES == finished) - { - is->finish_task = NULL; - } - else if (GNUNET_NO == finished) - { - is->finish_task = GNUNET_SCHEDULER_add_delayed (CHECK_FINISHED_PERIOD, - &run_finish_task_next, ftc); - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Next task finished with an error.\n"); - GNUNET_TESTING_interpreter_fail (); - } - -} - - -/** - * This function checks if the finish function of an asynchronous command returns GNUNET_YES, when the command is finished. In this case the finish function might have called interpreter_next. IF GNUNET_NO was returned this function is added to the scheduler again. In case of an error interpreter_fail is called. - * - * //TODO run_finish_task_next and this function can be merged. - * - */ -static void -run_finish_task_sync (void *cls) -{ - struct SyncTaskClosure *stc = cls; - const struct GNUNET_TESTING_Command *cmd = stc->async_cmd; - const struct GNUNET_TESTING_Command *sync_cmd = stc->sync_cmd; - struct FinishTaskClosure *ftc; - struct SyncState *sync_state = sync_cmd->cls; - struct GNUNET_SCHEDULER_Task *finish_task = sync_state->finish_task; - unsigned int finished = cmd->finish (cmd->cls, &interpreter_next, is); - - GNUNET_assert (NULL != finish_task); - ftc = GNUNET_new (struct FinishTaskClosure); - ftc->cmd = stc->sync_cmd; - ftc->is = stc->is; - struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); - if (cmd->default_timeout.rel_value_us < now.abs_value_us - - sync_state->start_finish_time.abs_value_us) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "The command with label %s did not finish its asynchronous task in time.\n", - cmd->label); - GNUNET_TESTING_interpreter_fail (); - } - - if (GNUNET_YES == finished) - { - finish_task = NULL; - } - else if (GNUNET_NO == finished) - { - finish_task = GNUNET_SCHEDULER_add_delayed (CHECK_FINISHED_PERIOD, - &run_finish_task_sync, stc); - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Sync task finished with an error.\n"); - GNUNET_TESTING_interpreter_fail (); - } -} - - -/** - * run method of the command created by the interpreter to wait for another command to finish. - * - */ -static void -start_finish_on_ref (void *cls, - const struct GNUNET_TESTING_Command *cmd, - struct GNUNET_TESTING_Interpreter *is) -{ - struct SyncState *sync_state = cls; - struct SyncTaskClosure *stc; - const struct GNUNET_TESTING_Command *async_cmd; - - async_cmd = sync_state->async_cmd; - stc = GNUNET_new (struct SyncTaskClosure); - stc->async_cmd = async_cmd; - stc->sync_cmd = cmd; - stc->is = is; - sync_state->start_finish_time = GNUNET_TIME_absolute_get (); - sync_state->finish_task = GNUNET_SCHEDULER_add_delayed ( - CHECK_FINISHED_PERIOD, - &run_finish_task_sync, - stc); -} - - -/** - * Create (synchronous) command that waits for another command to finish. - * If @a cmd_ref did not finish after @a timeout, this command will fail - * the test case. - * - * @param finish_label label for this command - * @param cmd_ref reference to a previous command which we should - * wait for (call `finish()` on) - * @param timeout how long to wait at most for @a cmd_ref to finish - * @return a finish-command. - */ -const struct GNUNET_TESTING_Command -GNUNET_TESTING_cmd_finish (const char *finish_label, - const char *cmd_ref, - struct GNUNET_TIME_Relative timeout) -{ - const struct GNUNET_TESTING_Command *async_cmd; - struct SyncState *sync_state; - - async_cmd = GNUNET_TESTING_interpreter_lookup_command (cmd_ref); - sync_state = GNUNET_new (struct SyncState); - sync_state->async_cmd = async_cmd; - - struct GNUNET_TESTING_Command cmd = { - .cls = sync_state, - .label = finish_label, - .run = &start_finish_on_ref, - .asynchronous_finish = GNUNET_NO - }; - - return cmd; -} - - -const struct GNUNET_TESTING_Command -GNUNET_TESTING_cmd_make_unblocking (const struct GNUNET_TESTING_Command cmd) -{ - - GNUNET_assert (NULL != cmd.finish); - const struct GNUNET_TESTING_Command async_cmd = { - .cls = cmd.cls, - .label = cmd.label, - .run = cmd.run, - .cleanup = cmd.cleanup, - .traits = cmd.traits, - .finish = cmd.finish, - .asynchronous_finish = GNUNET_YES - }; - - return async_cmd; -} - - /** * Current command failed, clean up and fail the test case. * * @param is interpreter of the test */ void -GNUNET_TESTING_interpreter_fail () +GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is) { struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip]; if (GNUNET_SYSERR == is->result) return; /* ignore, we already failed! */ - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "interpreter_fail!\n"); - if (NULL != cmd) { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed at command `%s'\n", + cmd->label); while (GNUNET_TESTING_cmd_is_batch (cmd)) { cmd = GNUNET_TESTING_cmd_batch_get_current (cmd); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Batch is at command `%s'\n", + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed in batch at command `%s'\n", cmd->label); } - } else { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "cmd is NULL.\n"); - } - - if (NULL == cmd->label) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Failed at command `%s'\n", - cmd->label); - - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "cmd->label is NULL.\n"); + "Failed with CMD being NULL!\n"); } - is->result = GNUNET_SYSERR; GNUNET_SCHEDULER_shutdown (); } @@ -406,8 +193,9 @@ GNUNET_TESTING_interpreter_fail () struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_end (void) { - static struct GNUNET_TESTING_Command cmd; - cmd.label = NULL; + static struct GNUNET_TESTING_Command cmd = { + .label = NULL + }; return cmd; } @@ -417,8 +205,8 @@ GNUNET_TESTING_cmd_end (void) * Obtain current label. */ const char * -GNUNET_TESTING_interpreter_get_current_label (struct - GNUNET_TESTING_Interpreter *is) +GNUNET_TESTING_interpreter_get_current_label ( + struct GNUNET_TESTING_Interpreter *is) { struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip]; @@ -434,46 +222,36 @@ GNUNET_TESTING_interpreter_get_current_label (struct static void interpreter_run (void *cls) { - struct FinishTaskClosure *ftc; struct GNUNET_TESTING_Interpreter *is = cls; struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip]; is->task = NULL; - if (NULL == cmd->label) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Running command END %p\n", - is); + "Running command END\n"); is->result = GNUNET_OK; GNUNET_SCHEDULER_shutdown (); return; } - else if (NULL != cmd) + if (NULL != cmd) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Running command `%s' %p\n", - cmd->label, - is); + "Running command `%s'\n", + cmd->label); } cmd->start_time = cmd->last_req_time = GNUNET_TIME_absolute_get (); cmd->num_tries = 1; cmd->run (cmd->cls, - cmd, is); - if ((NULL != cmd->finish) && (GNUNET_NO == cmd->asynchronous_finish)) + if ( (NULL != cmd->finish) && + (! cmd->asynchronous_finish) ) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Next task will not be called directly!\n"); - ftc = GNUNET_new (struct FinishTaskClosure); - ftc->cmd = cmd; - ftc->is = is; - is->finish_task = GNUNET_SCHEDULER_add_delayed (CHECK_FINISHED_PERIOD, - &run_finish_task_next, - ftc); + cmd->finish (cmd->cls, + &interpreter_next, + is); } else { @@ -491,37 +269,33 @@ interpreter_run (void *cls) static void do_shutdown (void *cls) { - (void) cls; + struct GNUNET_TESTING_Interpreter *is = cls; struct GNUNET_TESTING_Command *cmd; const char *label; label = is->commands[is->ip].label; if (NULL == label) label = "END"; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Executing shutdown at `%s'\n", label); - for (unsigned int j = 0; NULL != (cmd = &is->commands[j])->label; - j++) { + j++) + { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up cmd %s\n", cmd->label); - cmd->cleanup (cmd->cls, - cmd); + cmd->cleanup (cmd->cls); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaned up cmd %s\n", cmd->label); } - if (NULL != is->finish_task) { GNUNET_SCHEDULER_cancel (is->finish_task); - cmd->finish_task = NULL; + is->finish_task = NULL; } - if (NULL != is->task) { GNUNET_SCHEDULER_cancel (is->task); @@ -533,18 +307,19 @@ do_shutdown (void *cls) is->timeout_task = NULL; } GNUNET_free (is->commands); + GNUNET_free (is); } /** * Function run when the test terminates (good or bad) with timeout. * - * @param cls NULL + * @param cls the interpreter state */ static void do_timeout (void *cls) { - (void) cls; + struct GNUNET_TESTING_Interpreter *is = cls; is->timeout_task = NULL; GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -553,30 +328,15 @@ do_timeout (void *cls) } -/** - * Run the testsuite. Note, CMDs are copied into - * the interpreter state because they are _usually_ - * defined into the "run" method that returns after - * having scheduled the test interpreter. - * - * @param is the interpreter state - * @param commands the list of command to execute - * @param timeout how long to wait - */ -int +enum GNUNET_GenericReturnValue GNUNET_TESTING_run (const char *cfg_filename, struct GNUNET_TESTING_Command *commands, struct GNUNET_TIME_Relative timeout) { + struct GNUNET_TESTING_Interpreter *is; unsigned int i; is = GNUNET_new (struct GNUNET_TESTING_Interpreter); - - if (NULL != is->timeout_task) - { - GNUNET_SCHEDULER_cancel (is->timeout_task); - is->timeout_task = NULL; - } /* get the number of commands */ for (i = 0; NULL != commands[i].label; i++) ; @@ -585,15 +345,67 @@ GNUNET_TESTING_run (const char *cfg_filename, memcpy (is->commands, commands, sizeof (struct GNUNET_TESTING_Command) * i); - - is->timeout_task = GNUNET_SCHEDULER_add_delayed - (timeout, - &do_timeout, - is); - GNUNET_SCHEDULER_add_shutdown (&do_shutdown, is); - is->task = GNUNET_SCHEDULER_add_now (&interpreter_run, is); + is->timeout_task + = GNUNET_SCHEDULER_add_delayed (timeout, + &do_timeout, + is); + GNUNET_SCHEDULER_add_shutdown (&do_shutdown, + is); + is->task = GNUNET_SCHEDULER_add_now (&interpreter_run, + is); return GNUNET_OK; } +/** + * Closure for #loop_run(). + */ +struct MainParams +{ + const char *cfg_filename; + struct GNUNET_TESTING_Command *commands; + struct GNUNET_TIME_Relative timeout; + int rv; +}; + + +/** + * Main function to run the test cases. + * + * @param cls a `struct MainParams *` + */ +static void +loop_run (void *cls) +{ + struct MainParams *mp = cls; + + if (GNUNET_OK != + GNUNET_TESTING_run (mp->cfg_filename, + mp->commands, + mp->timeout)) + { + GNUNET_break (0); + mp->rv = EXIT_FAILURE; + } +} + + +int +GNUNET_TESTING_main (const char *cfg_filename, + struct GNUNET_TESTING_Command *commands, + struct GNUNET_TIME_Relative timeout) +{ + struct MainParams mp = { + .cfg_filename = cfg_filename, + .commands = commands, + .timeout = timeout, + .rv = EXIT_SUCCESS + }; + + GNUNET_SCHEDULER_run (&loop_run, + &mp); + return mp.rv; +} + + /* end of testing_api_loop.c */ diff --git a/src/testing/testing_api_trait_cmd.c b/src/testing/testing_api_trait_cmd.c index 886baee5b..7afa8b264 100644 --- a/src/testing/testing_api_trait_cmd.c +++ b/src/testing/testing_api_trait_cmd.c @@ -41,7 +41,7 @@ * @param[out] _cmd where to write the wire details. * @return #GNUNET_OK on success. */ -int +enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_cmd (const struct GNUNET_TESTING_Command *cmd, unsigned int index, struct GNUNET_TESTING_Command **_cmd) diff --git a/src/testing/testing_api_traits.c b/src/testing/testing_api_traits.c index 66626833d..2f836ddfa 100644 --- a/src/testing/testing_api_traits.c +++ b/src/testing/testing_api_traits.c @@ -55,7 +55,7 @@ GNUNET_TESTING_trait_end () * @param index index number of the object to extract. * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. */ -int +enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait *traits, const void **ret, const char *trait, -- cgit v1.2.3 From 23b5cf23674d557864284eff81d876ee1b5631bf Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 4 Oct 2021 18:15:21 +0200 Subject: -basic santiy for testing API, breaks transport/ build --- src/include/gnunet_testing_ng_lib.h | 196 ++++++++++---------- src/testing/Makefile.am | 6 +- src/testing/test_testing_plugin_testcmd.c | 19 +- src/testing/testing.h | 94 +++++----- src/testing/testing_api_cmd_batch.c | 64 +++---- src/testing/testing_api_cmd_end.c | 39 ++++ src/testing/testing_api_loop.c | 290 +++++++++++++++++------------- 7 files changed, 376 insertions(+), 332 deletions(-) create mode 100644 src/testing/testing_api_cmd_end.c (limited to 'src') diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h index 363c7ff0c..4ef9aac18 100644 --- a/src/include/gnunet_testing_ng_lib.h +++ b/src/include/gnunet_testing_ng_lib.h @@ -17,7 +17,6 @@ SPDX-License-Identifier: AGPL3.0-or-later */ - /** * @brief API for writing an interpreter to test GNUnet components * @author Christian Grothoff @@ -49,6 +48,7 @@ /** * Router of a network namespace. + * // FIXME: this does not belong here! */ struct GNUNET_TESTING_NetjailRouter { @@ -63,8 +63,10 @@ struct GNUNET_TESTING_NetjailRouter unsigned int udp_port; }; + /** * Enum for the different types of nodes. + * // FIXME: this does not belong here! */ enum GNUNET_TESTING_NODE_TYPE { @@ -79,6 +81,8 @@ enum GNUNET_TESTING_NODE_TYPE GNUNET_TESTING_GLOBAL_NODE }; + + // FIXME: this does not belong here! struct GNUNET_TESTING_ADDRESS_PREFIX { /** @@ -97,10 +101,13 @@ struct GNUNET_TESTING_ADDRESS_PREFIX char *address_prefix; }; + +// FIXME: this does not belong here! struct GNUNET_TESTING_NetjailNode; /** * Connection to another node. + * // FIXME: this does not belong here! */ struct GNUNET_TESTING_NodeConnection { @@ -148,6 +155,7 @@ struct GNUNET_TESTING_NodeConnection /** * Node in the netjail topology. + * // FIXME: this does not belong here! */ struct GNUNET_TESTING_NetjailNode { @@ -185,6 +193,7 @@ struct GNUNET_TESTING_NetjailNode /** * Namespace in a topology. + * // FIXME: this does not belong here! */ struct GNUNET_TESTING_NetjailNamespace { @@ -206,6 +215,7 @@ struct GNUNET_TESTING_NetjailNamespace /** * Toplogy of our netjail setup. + * // FIXME: this does not belong here! */ struct GNUNET_TESTING_NetjailTopology { @@ -318,6 +328,9 @@ struct GNUNET_TESTING_Command (*cleanup)(void *cls); /** + * FIXME: logic is often the same! + * => Think about refactoring API to reduce duplication! + * * Extract information from a command that is useful for other * commands. * @@ -355,13 +368,6 @@ struct GNUNET_TESTING_Command */ struct GNUNET_TIME_Absolute last_req_time; - /** - * How often did we try to execute this command? (In case it is a request - * that is repated.) Note that a command must have some built-in retry - * mechanism for this value to be useful. - */ - unsigned int num_tries; - /** * In case @e asynchronous_finish is true, how long should we wait for this * command to complete? If @e finish did not complete after this amount of @@ -370,6 +376,13 @@ struct GNUNET_TESTING_Command */ struct GNUNET_TIME_Relative default_timeout; + /** + * How often did we try to execute this command? (In case it is a request + * that is repated.) Note that a command must have some built-in retry + * mechanism for this value to be useful. + */ + unsigned int num_tries; + /** * If "true", the interpreter should not immediately call * @e finish, even if @e finish is non-NULL. Otherwise, @@ -465,23 +478,33 @@ GNUNET_TESTING_cmd_rewind_ip (const char *label, unsigned int counter); +/** + * Function called with the final result of the test. + * + * @param cls closure + * @param rv #GNUNET_OK if the test passed + */ +typedef void +(*GNUNET_TESTING_ResultCallback)(void *cls, + enum GNUNET_GenericReturnValue rv); + + /** * Run the testsuite. Note, CMDs are copied into * the interpreter state because they are _usually_ * defined into the "run" method that returns after * having scheduled the test interpreter. * - * @param cfg_name name of configuration file to use * @param commands the list of command to execute * @param timeout how long to wait for each command to execute - * @return #GNUNET_OK if all is okay, != #GNUNET_OK otherwise. - * non-GNUNET_OK codes are #GNUNET_SYSERR most of the - * times. + * @param rc function to call with the final result + * @param rc_cls closure for @a rc */ -enum GNUNET_GenericReturnValue -GNUNET_TESTING_run (const char *cfg_filename, - struct GNUNET_TESTING_Command *commands, - struct GNUNET_TIME_Relative timeout); +void +GNUNET_TESTING_run (struct GNUNET_TESTING_Command *commands, + struct GNUNET_TIME_Relative timeout, + GNUNET_TESTING_ResultCallback rc, + void *rc_cls); /** @@ -489,14 +512,12 @@ GNUNET_TESTING_run (const char *cfg_filename, * run the testsuite. Return 0 upon success. * Expected to be called directly from main(). * - * @param cfg_name name of configuration file to use * @param commands the list of command to execute * @param timeout how long to wait for each command to execute * @return EXIT_SUCCESS on success, EXIT_FAILURE on failure */ int -GNUNET_TESTING_main (const char *cfg_filename, - struct GNUNET_TESTING_Command *commands, +GNUNET_TESTING_main (struct GNUNET_TESTING_Command *commands, struct GNUNET_TIME_Relative timeout); @@ -505,6 +526,8 @@ GNUNET_TESTING_main (const char *cfg_filename, * * @param prog program's name to look into * @param marker chunk to find in @a prog + * // FIXME: this does not belong here! => libgnunetutil, maybe? + * // FIXME: return bool? document return value! */ int GNUNET_TESTING_has_in_name (const char *prog, @@ -518,7 +541,7 @@ GNUNET_TESTING_has_in_name (const char *prog, * * @param label command label. * @param process_label label of a command that has a process trait - * @param process_index index of the process trait at @a process_label + * @param process_index index of the process trait at @a process_label // FIXME: enum? needed? * @param signal signal to send to @a process. * @return the command. */ @@ -556,50 +579,9 @@ GNUNET_TESTING_cmd_batch (const char *label, struct GNUNET_TESTING_Command *batch); -/** - * Test if this command is a batch command. - * - * @return false if not, true if it is a batch command - */ -// TODO: figure out if this needs to be exposed in the public API. -int -GNUNET_TESTING_cmd_is_batch (const struct GNUNET_TESTING_Command *cmd); - - -/** - * Advance internal pointer to next command. - * - * @param is interpreter state. - */ -// TODO: figure out if this needs to be exposed in the public API. -void -GNUNET_TESTING_cmd_batch_next (struct GNUNET_TESTING_Interpreter *is); - - -/** - * Obtain what command the batch is at. - * - * @return cmd current batch command - */ -// TODO: figure out if this needs to be exposed in the public API. -struct GNUNET_TESTING_Command * -GNUNET_TESTING_cmd_batch_get_current (const struct GNUNET_TESTING_Command *cmd); - - -/** - * Set what command the batch should be at. - * - * @param cmd current batch command - * @param new_ip where to move the IP - */ -// TODO: figure out if this needs to be exposed in the public API. -void -GNUNET_TESTING_cmd_batch_set_current (const struct GNUNET_TESTING_Command *cmd, - unsigned int new_ip); - - /** * Performance counter. + * // FIXME: this might not belong here! */ struct GNUNET_TESTING_Timer { @@ -695,7 +677,7 @@ GNUNET_TESTING_trait_end (void); * @param index index number of the trait to extract. * @return #GNUNET_OK when the trait is found. */ -int +enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait *traits, const void **ret, const char *trait, @@ -709,12 +691,12 @@ GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait *traits, * * @param cmd command to extract trait from. * @param index which process to pick if @a cmd - * has multiple on offer. + * has multiple on offer. -- FIXME: remove? * @param[out] processp set to the address of the pointer to the * process. * @return #GNUNET_OK on success. */ -int +enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_process (const struct GNUNET_TESTING_Command *cmd, unsigned int index, struct GNUNET_OS_Process ***processp); @@ -724,7 +706,7 @@ GNUNET_TESTING_get_trait_process (const struct GNUNET_TESTING_Command *cmd, * Offer location where a command stores a pointer to a process. * * @param index offered location index number, in case there are - * multiple on offer. + * multiple on offer. // FIXME: remove? * @param processp process location to offer. * @return the trait. */ @@ -736,7 +718,7 @@ GNUNET_TESTING_make_trait_process (unsigned int index, /** * Offer number trait, 32-bit version. * - * @param index the number's index number. + * @param index the number's index number. // FIXME: introduce enum? * @param n number to offer. */ struct GNUNET_TESTING_Trait @@ -748,11 +730,11 @@ GNUNET_TESTING_make_trait_uint32 (unsigned int index, * 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. + * @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. */ -int +enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_uint32 (const struct GNUNET_TESTING_Command *cmd, unsigned int index, const uint32_t **n); @@ -761,7 +743,7 @@ GNUNET_TESTING_get_trait_uint32 (const struct GNUNET_TESTING_Command *cmd, /** * Offer number trait, 64-bit version. * - * @param index the number's index number. + * @param index the number's index number. // FIXME: introduce enum? * @param n number to offer. */ struct GNUNET_TESTING_Trait @@ -773,11 +755,11 @@ GNUNET_TESTING_make_trait_uint64 (unsigned int index, * 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. + * @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. */ -int +enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_uint64 (const struct GNUNET_TESTING_Command *cmd, unsigned int index, const uint64_t **n); @@ -786,7 +768,7 @@ GNUNET_TESTING_get_trait_uint64 (const struct GNUNET_TESTING_Command *cmd, /** * Offer number trait, 64-bit signed version. * - * @param index the number's index number. + * @param index the number's index number. // FIXME: introduce enum? * @param n number to offer. */ struct GNUNET_TESTING_Trait @@ -798,11 +780,11 @@ GNUNET_TESTING_make_trait_int64 (unsigned int index, * 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. + * @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. */ -int +enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_int64 (const struct GNUNET_TESTING_Command *cmd, unsigned int index, const int64_t **n); @@ -812,7 +794,7 @@ GNUNET_TESTING_get_trait_int64 (const struct GNUNET_TESTING_Command *cmd, * Offer a number. * * @param index the number's index number. - * @param n the number to offer. + * @param n the number to offer. // FIXME: introduce enum? * @return #GNUNET_OK on success. */ struct GNUNET_TESTING_Trait @@ -824,11 +806,11 @@ GNUNET_TESTING_make_trait_uint (unsigned int index, * Obtain a number from @a cmd. * * @param cmd command to extract the number from. - * @param index the number's index number. + * @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. */ -int +enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_uint (const struct GNUNET_TESTING_Command *cmd, unsigned int index, const unsigned int **n); @@ -838,12 +820,12 @@ GNUNET_TESTING_get_trait_uint (const struct GNUNET_TESTING_Command *cmd, * * @param cmd command to extract the subject from. * @param index index number associated with the transfer - * subject to offer. + * subject to offer. // FIXME: introduce enum? * @param[out] s where to write the offered * string. * @return #GNUNET_OK on success. */ -int +enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_string ( const struct GNUNET_TESTING_Command *cmd, unsigned int index, @@ -854,7 +836,7 @@ GNUNET_TESTING_get_trait_string ( * Offer string subject. * * @param index index number associated with the transfer - * subject being offered. + * subject being offered. // FIXME: introduce enum? * @param s string to offer. * @return the trait. */ @@ -868,9 +850,8 @@ GNUNET_TESTING_make_trait_string (unsigned int index, * @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. + * CMD currently being executed. FIXME: remove! * @param cmd wire details to offer. - * * @return the trait. */ struct GNUNET_TESTING_Trait @@ -885,11 +866,11 @@ GNUNET_TESTING_make_trait_cmd (unsigned int index, * @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. + * CMD currently being executed. FIXME: remove! * @param[out] _cmd where to write the wire details. * @return #GNUNET_OK on success. */ -int +enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_cmd (const struct GNUNET_TESTING_Command *cmd, unsigned int index, struct GNUNET_TESTING_Command **_cmd); @@ -900,11 +881,11 @@ GNUNET_TESTING_get_trait_cmd (const struct GNUNET_TESTING_Command *cmd, * * @param cmd command to extract the uuid from. * @param index which amount to pick if @a cmd has multiple - * on offer + * on offer // FIXME: introduce enum? * @param[out] uuid where to write the uuid. * @return #GNUNET_OK on success. */ -int +enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_uuid (const struct GNUNET_TESTING_Command *cmd, unsigned int index, struct GNUNET_Uuid **uuid); @@ -914,9 +895,8 @@ GNUNET_TESTING_get_trait_uuid (const struct GNUNET_TESTING_Command *cmd, * Offer a uuid in a trait. * * @param index which uuid to offer, in case there are - * multiple available. + * multiple available. // FIXME: introduce enum? * @param uuid the uuid to offer. - * * @return the trait. */ struct GNUNET_TESTING_Trait @@ -929,11 +909,11 @@ GNUNET_TESTING_make_trait_uuid (unsigned int index, * * @param cmd command to extract trait from * @param index which time stamp to pick if - * @a cmd has multiple on offer. + * @a cmd has multiple on offer // FIXME: introduce enum? * @param[out] time set to the wanted WTID. * @return #GNUNET_OK on success */ -int +enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_absolute_time ( const struct GNUNET_TESTING_Command *cmd, unsigned int index, @@ -982,6 +962,9 @@ GNUNET_TESTING_make_trait_relative_time ( const struct GNUNET_TIME_Relative *time); +// FIXME: move these commands into a separate libgnunetestingnetjail lib or so! + + /** * Create command. * @@ -1133,7 +1116,9 @@ GNUNET_TESTING_cmd_stop_testing_system_v2 (const char *label, const char *topology_config); -int + +// FIXME: document! +enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_helper_handles (const struct GNUNET_TESTING_Command *cmd, struct GNUNET_HELPER_Handle ***helper); @@ -1146,31 +1131,30 @@ GNUNET_TESTING_get_trait_helper_handles (const struct * @param pt pointer to message. * @return #GNUNET_OK on success. */ -int -GNUNET_TESTING_get_trait_helper_handles_v2 (const struct - GNUNET_TESTING_Command *cmd, - struct GNUNET_HELPER_Handle *** - helper); +enum GNUNET_GenericReturnValue +GNUNET_TESTING_get_trait_helper_handles_v2 ( + const struct GNUNET_TESTING_Command *cmd, + struct GNUNET_HELPER_Handle ***helper); struct GNUNET_TESTING_Command -GNUNET_TESTING_cmd_block_until_all_peers_started (const char *label, - unsigned int * - all_peers_started); +GNUNET_TESTING_cmd_block_until_all_peers_started ( + const char *label, + unsigned int *all_peers_started); struct GNUNET_TESTING_Command -GNUNET_TESTING_cmd_block_until_external_trigger (const char *label, - unsigned int * - stop_blocking); +GNUNET_TESTING_cmd_block_until_external_trigger ( + const char *label, + unsigned int *stop_blocking); struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_send_peer_ready (const char *label, TESTING_CMD_HELPER_write_cb write_message); struct GNUNET_TESTING_Command -GNUNET_TESTING_cmd_local_test_finished (const char *label, - TESTING_CMD_HELPER_write_cb - write_message); +GNUNET_TESTING_cmd_local_test_finished ( + const char *label, + TESTING_CMD_HELPER_write_cb write_message); #endif diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am index 3e0d4d443..2bb03d157 100644 --- a/src/testing/Makefile.am +++ b/src/testing/Makefile.am @@ -42,9 +42,11 @@ libgnunet_test_testing_plugin_testcmd_la_LIBADD = \ libgnunet_test_testing_plugin_testcmd_la_LDFLAGS = \ $(GN_PLUGIN_LDFLAGS) +# testing_api_cmd_finish.c + libgnunettesting_la_SOURCES = \ + testing_api_cmd_end.c \ testing_api_cmd_local_test_finished.c \ - testing_api_cmd_finish.c \ testing_api_cmd_send_peer_ready.c \ testing_api_cmd_block_until_all_peers_started.c \ testing_api_cmd_block_until_external_trigger.c \ @@ -56,7 +58,7 @@ libgnunettesting_la_SOURCES = \ testing_api_cmd_netjail_stop_testsystem_v2.c \ testing_api_cmd_netjail_stop.c \ testing_api_cmd_netjail_stop_v2.c \ - testing.c testing.h \ + testing.c \ testing_api_cmd_system_create.c \ testing_api_cmd_system_destroy.c \ testing_api_cmd_batch.c \ diff --git a/src/testing/test_testing_plugin_testcmd.c b/src/testing/test_testing_plugin_testcmd.c index 444272fcd..32e2b38a7 100644 --- a/src/testing/test_testing_plugin_testcmd.c +++ b/src/testing/test_testing_plugin_testcmd.c @@ -17,11 +17,12 @@ SPDX-License-Identifier: AGPL3.0-or-later */ - /** * @file testbed/plugin_testcmd.c * @brief a plugin to provide the API for running test cases. * @author t3sserakt + * + * // FIXME: too verbose, no logic to return final status, will segv! */ #include "platform.h" #include "gnunet_testing_ng_lib.h" @@ -33,8 +34,11 @@ */ #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) + +// FIXME: bad global! unsigned int are_all_peers_started; + static void all_peers_started () { @@ -44,8 +48,10 @@ all_peers_started () are_all_peers_started); } + static void -start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, +start_testcase (TESTING_CMD_HELPER_write_cb write_message, + char *router_ip, char *node_ip, char *n, char *m, @@ -70,9 +76,10 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, write_message) }; - GNUNET_TESTING_run (NULL, - commands, - GNUNET_TIME_UNIT_FOREVER_REL); + GNUNET_TESTING_run (commands, + GNUNET_TIME_UNIT_FOREVER_REL, + NULL, /* FIXME: pass continuation! */ + NULL); LOG (GNUNET_ERROR_TYPE_ERROR, "We got here 7!\n"); @@ -113,4 +120,4 @@ libgnunet_plugin_testcmd_done (void *cls) } -/* end of plugin_testcmd.c */ + diff --git a/src/testing/testing.h b/src/testing/testing.h index b12466530..8aba09e4b 100644 --- a/src/testing/testing.h +++ b/src/testing/testing.h @@ -21,54 +21,54 @@ /** * @author t3sserakt */ - +#ifndef TESTING_H +#define TESTING_H #include "gnunet_util_lib.h" + +/** + * Advance internal pointer to next command. + * + * @param cls batch internal state + * @return true if we could advance, false if the batch + * has completed and cannot advance anymore + */ +bool +GNUNET_TESTING_cmd_batch_next_ (void *cls); + + +/** + * Test if this command is a batch command. + * + * @return false if not, true if it is a batch command + */ +bool +GNUNET_TESTING_cmd_is_batch_ (const struct GNUNET_TESTING_Command *cmd); + + +/** + * Obtain what command the batch is at. + * + * @return cmd current batch command + */ +struct GNUNET_TESTING_Command * +GNUNET_TESTING_cmd_batch_get_current_ (const struct GNUNET_TESTING_Command *cmd); + + /** - * Global state of the interpreter, used by a command - * to access information about other commands. + * Set what command the batch should be at. Needed for + * loops. We may want to change this to take a label + * and/or expose it in the public API in the future. + * Not used for now. + * + * @param cmd current batch command + * @param new_ip where to move the IP */ -// SUGGESTION: consider making this struct opaque (only known inside of libgnunettesting, -// say main loop and a few select commands, like next/fail/batch); + helper -// function to access 'cfg'? -struct GNUNET_TESTING_Interpreter -{ - - /** - * Commands the interpreter will run. - */ - struct GNUNET_TESTING_Command *commands; - - /** - * Interpreter task (if one is scheduled). - */ - struct GNUNET_SCHEDULER_Task *task; - - /** - * Finish task of a blocking call to a commands finish method. - */ - struct GNUNET_SCHEDULER_Task *finish_task; - - /** - * Our configuration. - */ - const struct GNUNET_CONFIGURATION_Handle *cfg; - - /** - * Task run on timeout. - */ - struct GNUNET_SCHEDULER_Task *timeout_task; - - /** - * Instruction pointer. Tells #interpreter_run() which instruction to run - * next. Need (signed) int because it gets -1 when rewinding the - * interpreter to the first CMD. - */ - int ip; - - /** - * Result of the testcases, #GNUNET_OK on success - */ - int result; - -}; +void +GNUNET_TESTING_cmd_batch_set_current_ (const struct GNUNET_TESTING_Command *cmd, + unsigned int new_ip); + + + + +#endif diff --git a/src/testing/testing_api_cmd_batch.c b/src/testing/testing_api_cmd_batch.c index e39489616..080a4880d 100644 --- a/src/testing/testing_api_cmd_batch.c +++ b/src/testing/testing_api_cmd_batch.c @@ -119,16 +119,15 @@ batch_traits (void *cls, const char *trait, unsigned int index) { + struct BatchState *bs = cls; + // FIXME: these constants should be more global! #define CURRENT_CMD_INDEX 0 #define BATCH_INDEX 1 - - struct BatchState *bs = cls; - struct GNUNET_TESTING_Trait traits[] = { - GNUNET_TESTING_make_trait_cmd - (CURRENT_CMD_INDEX, &bs->batch[bs->batch_ip]), - GNUNET_TESTING_make_trait_cmd - (BATCH_INDEX, bs->batch), + GNUNET_TESTING_make_trait_cmd (CURRENT_CMD_INDEX, + &bs->batch[bs->batch_ip]), + GNUNET_TESTING_make_trait_cmd (BATCH_INDEX, + bs->batch), GNUNET_TESTING_trait_end () }; @@ -185,68 +184,45 @@ GNUNET_TESTING_cmd_batch (const char *label, } -/** - * Advance internal pointer to next command. - * - * @param is interpreter state. - */ -void -GNUNET_TESTING_cmd_batch_next (struct GNUNET_TESTING_Interpreter *is) +bool +GNUNET_TESTING_cmd_batch_next_ (void *cls) { - struct BatchState *bs = is->commands[is->ip].cls; + struct BatchState *bs = cls; if (NULL == bs->batch[bs->batch_ip].label) - { - is->commands[is->ip].finish_time = GNUNET_TIME_absolute_get (); - is->ip++; - return; - } - bs->batch[bs->batch_ip].finish_time = GNUNET_TIME_absolute_get (); + return false; + bs->batch[bs->batch_ip].finish_time + = GNUNET_TIME_absolute_get (); bs->batch_ip++; + return true; } -/** - * Test if this command is a batch command. - * - * @return false if not, true if it is a batch command - */ -int -GNUNET_TESTING_cmd_is_batch (const struct GNUNET_TESTING_Command *cmd) +bool +GNUNET_TESTING_cmd_is_batch_ (const struct GNUNET_TESTING_Command *cmd) { return cmd->run == &batch_run; } -/** - * Obtain what command the batch is at. - * - * @return cmd current batch command - */ struct GNUNET_TESTING_Command * -GNUNET_TESTING_cmd_batch_get_current (const struct GNUNET_TESTING_Command *cmd) +GNUNET_TESTING_cmd_batch_get_current_ (const struct GNUNET_TESTING_Command *cmd) { struct BatchState *bs = cmd->cls; - GNUNET_assert (cmd->run == &batch_run); + GNUNET_assert (GNUNET_TESTING_cmd_is_batch_ (cmd)); return &bs->batch[bs->batch_ip]; } -/** - * Set what command the batch should be at. - * - * @param cmd current batch command - * @param new_ip where to move the IP - */ void -GNUNET_TESTING_cmd_batch_set_current (const struct GNUNET_TESTING_Command *cmd, - unsigned int new_ip) +GNUNET_TESTING_cmd_batch_set_current_ (const struct GNUNET_TESTING_Command *cmd, + unsigned int new_ip) { struct BatchState *bs = cmd->cls; /* sanity checks */ - GNUNET_assert (cmd->run == &batch_run); + GNUNET_assert (GNUNET_TESTING_cmd_is_batch_ (cmd)); for (unsigned int i = 0; i < new_ip; i++) GNUNET_assert (NULL != bs->batch[i].label); /* actual logic */ diff --git a/src/testing/testing_api_cmd_end.c b/src/testing/testing_api_cmd_end.c new file mode 100644 index 000000000..f0f036429 --- /dev/null +++ b/src/testing/testing_api_cmd_end.c @@ -0,0 +1,39 @@ +/* + 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_cmd_end.c + * @brief command to end a command array + */ +#include "platform.h" +#include "gnunet_util_lib.h" +#include "gnunet_testing_ng_lib.h" + + +struct GNUNET_TESTING_Command +GNUNET_TESTING_cmd_end (void) +{ + static struct GNUNET_TESTING_Command cmd = { + .label = NULL + }; + + return cmd; +} + + diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c index 1c8eb1db6..b21e01fcc 100644 --- a/src/testing/testing_api_loop.c +++ b/src/testing/testing_api_loop.c @@ -24,25 +24,64 @@ * @author Christian Grothoff (GNU Taler testing) * @author Marcello Stanisci (GNU Taler testing) * @author t3sserakt - * - * FIXME: - * - interpreter failure is NOT returned properly yet! - * - abuse of shutdown logic for interpreter termination - * => API design flaw to be fixed! */ #include "platform.h" #include "gnunet_util_lib.h" #include "gnunet_testing_ng_lib.h" #include "testing.h" - /** - * Lookup command by label. - * - * @param is interpreter to lookup command in - * @param label label to look for - * @return NULL if command was not found + * Global state of the interpreter, used by a command + * to access information about other commands. */ +struct GNUNET_TESTING_Interpreter +{ + + /** + * Function to call with the test result. + */ + GNUNET_TESTING_ResultCallback rc; + + /** + * Closure for @e rc. + */ + void *rc_cls; + + /** + * Commands the interpreter will run. + */ + struct GNUNET_TESTING_Command *commands; + + /** + * Interpreter task (if one is scheduled). + */ + struct GNUNET_SCHEDULER_Task *task; + + /** + * Final task that returns the result. + */ + struct GNUNET_SCHEDULER_Task *final_task; + + /** + * Task run on timeout. + */ + struct GNUNET_SCHEDULER_Task *timeout_task; + + /** + * Instruction pointer. Tells #interpreter_run() which instruction to run + * next. Need (signed) int because it gets -1 when rewinding the + * interpreter to the first CMD. + */ + int ip; + + /** + * Result of the testcases, #GNUNET_OK on success + */ + enum GNUNET_GenericReturnValue result; + +}; + + const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command ( struct GNUNET_TESTING_Interpreter *is, @@ -65,7 +104,7 @@ GNUNET_TESTING_interpreter_lookup_command ( label)) ) return cmd; - if (GNUNET_TESTING_cmd_is_batch (cmd)) + if (GNUNET_TESTING_cmd_is_batch_ (cmd)) { #define BATCH_INDEX 1 struct GNUNET_TESTING_Command *batch; @@ -73,7 +112,7 @@ GNUNET_TESTING_interpreter_lookup_command ( struct GNUNET_TESTING_Command *icmd; const struct GNUNET_TESTING_Command *match; - current = GNUNET_TESTING_cmd_batch_get_current (cmd); + current = GNUNET_TESTING_cmd_batch_get_current_ (cmd); GNUNET_assert (GNUNET_OK == GNUNET_TESTING_get_trait_cmd (cmd, BATCH_INDEX, @@ -96,10 +135,58 @@ GNUNET_TESTING_interpreter_lookup_command ( } } GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Command not found: %s\n", + "Command `%s' not found\n", label); return NULL; +} + + +/** + * Finish the test run, return the final result. + * + * @param cls the `struct GNUNET_TESTING_Interpreter` + */ +static void +finish_test (void *cls) +{ + struct GNUNET_TESTING_Interpreter *is = cls; + struct GNUNET_TESTING_Command *cmd; + const char *label; + is->final_task = NULL; + label = is->commands[is->ip].label; + if (NULL == label) + label = "END"; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Interpreter finishes at `%s' with status %d\n", + label, + is->result); + for (unsigned int j = 0; + NULL != (cmd = &is->commands[j])->label; + j++) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Cleaning up cmd %s\n", + cmd->label); + cmd->cleanup (cmd->cls); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Cleaned up cmd %s\n", + cmd->label); + } + if (NULL != is->task) + { + GNUNET_SCHEDULER_cancel (is->task); + is->task = NULL; + } + if (NULL != is->timeout_task) + { + GNUNET_SCHEDULER_cancel (is->timeout_task); + is->timeout_task = NULL; + } + GNUNET_free (is->commands); + is->rc (is->rc_cls, + is->result); + GNUNET_free (is); } @@ -125,15 +212,10 @@ interpreter_next (void *cls) if (GNUNET_SYSERR == is->result) return; /* ignore, we already failed! */ - if (GNUNET_TESTING_cmd_is_batch (cmd)) - { - GNUNET_TESTING_cmd_batch_next (is); - } - else - { - cmd->finish_time = GNUNET_TIME_absolute_get (); + cmd->finish_time = GNUNET_TIME_absolute_get (); + if ( (! GNUNET_TESTING_cmd_is_batch_ (cmd)) || + (! GNUNET_TESTING_cmd_batch_next_ (cmd->cls)) ) is->ip++; - } if (0 == (ipc % 1000)) { if (0 != ipc) @@ -150,26 +232,24 @@ interpreter_next (void *cls) } -/** - * Current command failed, clean up and fail the test case. - * - * @param is interpreter of the test - */ void GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is) { struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip]; if (GNUNET_SYSERR == is->result) + { + GNUNET_break (0); return; /* ignore, we already failed! */ + } if (NULL != cmd) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed at command `%s'\n", cmd->label); - while (GNUNET_TESTING_cmd_is_batch (cmd)) + while (GNUNET_TESTING_cmd_is_batch_ (cmd)) { - cmd = GNUNET_TESTING_cmd_batch_get_current (cmd); + cmd = GNUNET_TESTING_cmd_batch_get_current_ (cmd); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed in batch at command `%s'\n", cmd->label); @@ -181,29 +261,12 @@ GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is) "Failed with CMD being NULL!\n"); } is->result = GNUNET_SYSERR; - GNUNET_SCHEDULER_shutdown (); -} - - -/** - * Create command array terminator. - * - * @return a end-command. - */ -struct GNUNET_TESTING_Command -GNUNET_TESTING_cmd_end (void) -{ - static struct GNUNET_TESTING_Command cmd = { - .label = NULL - }; - - return cmd; + GNUNET_assert (NULL == is->final_task); + is->final_task = GNUNET_SCHEDULER_add_now (&finish_test, + is); } -/** - * Obtain current label. - */ const char * GNUNET_TESTING_interpreter_get_current_label ( struct GNUNET_TESTING_Interpreter *is) @@ -234,12 +297,9 @@ interpreter_run (void *cls) GNUNET_SCHEDULER_shutdown (); return; } - if (NULL != cmd) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Running command `%s'\n", - cmd->label); - } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Running command `%s'\n", + cmd->label); cmd->start_time = cmd->last_req_time = GNUNET_TIME_absolute_get (); @@ -260,57 +320,6 @@ interpreter_run (void *cls) } -/** - * Function run when the test terminates (good or bad). - * Cleans up our state. - * - * @param cls the interpreter state. - */ -static void -do_shutdown (void *cls) -{ - struct GNUNET_TESTING_Interpreter *is = cls; - struct GNUNET_TESTING_Command *cmd; - const char *label; - - label = is->commands[is->ip].label; - if (NULL == label) - label = "END"; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Executing shutdown at `%s'\n", - label); - for (unsigned int j = 0; - NULL != (cmd = &is->commands[j])->label; - j++) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Cleaning up cmd %s\n", - cmd->label); - cmd->cleanup (cmd->cls); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Cleaned up cmd %s\n", - cmd->label); - } - if (NULL != is->finish_task) - { - GNUNET_SCHEDULER_cancel (is->finish_task); - is->finish_task = NULL; - } - if (NULL != is->task) - { - GNUNET_SCHEDULER_cancel (is->task); - is->task = NULL; - } - if (NULL != is->timeout_task) - { - GNUNET_SCHEDULER_cancel (is->timeout_task); - is->timeout_task = NULL; - } - GNUNET_free (is->commands); - GNUNET_free (is); -} - - /** * Function run when the test terminates (good or bad) with timeout. * @@ -323,20 +332,24 @@ do_timeout (void *cls) is->timeout_task = NULL; GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Terminating test due to timeout\n"); - GNUNET_SCHEDULER_shutdown (); + "Terminating test due to global timeout\n"); + is->result = GNUNET_SYSERR; + finish_test (is); } -enum GNUNET_GenericReturnValue -GNUNET_TESTING_run (const char *cfg_filename, - struct GNUNET_TESTING_Command *commands, - struct GNUNET_TIME_Relative timeout) +void +GNUNET_TESTING_run (struct GNUNET_TESTING_Command *commands, + struct GNUNET_TIME_Relative timeout, + GNUNET_TESTING_ResultCallback rc, + void *rc_cls) { struct GNUNET_TESTING_Interpreter *is; unsigned int i; is = GNUNET_new (struct GNUNET_TESTING_Interpreter); + is->rc = rc; + is->rc_cls = rc_cls; /* get the number of commands */ for (i = 0; NULL != commands[i].label; i++) ; @@ -349,11 +362,8 @@ GNUNET_TESTING_run (const char *cfg_filename, = GNUNET_SCHEDULER_add_delayed (timeout, &do_timeout, is); - GNUNET_SCHEDULER_add_shutdown (&do_shutdown, - is); is->task = GNUNET_SCHEDULER_add_now (&interpreter_run, is); - return GNUNET_OK; } @@ -362,13 +372,45 @@ GNUNET_TESTING_run (const char *cfg_filename, */ struct MainParams { - const char *cfg_filename; + + /** + * NULL-label terminated array of commands. + */ struct GNUNET_TESTING_Command *commands; + + /** + * Global timeout for the test. + */ struct GNUNET_TIME_Relative timeout; + + /** + * Set to #EXIT_FAILURE on error. + */ int rv; }; +/** + * Function called with the final result of the test. + * + * @param cls the `struct MainParams` + * @param rv #GNUNET_OK if the test passed + */ +static void +handle_result (void *cls, + enum GNUNET_GenericReturnValue rv) +{ + struct MainParams *mp = cls; + + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Test exits with status %d\n", + rv); + if (GNUNET_OK != rv) + mp->rv = EXIT_FAILURE; + GNUNET_SCHEDULER_shutdown (); +} + + /** * Main function to run the test cases. * @@ -379,24 +421,18 @@ loop_run (void *cls) { struct MainParams *mp = cls; - if (GNUNET_OK != - GNUNET_TESTING_run (mp->cfg_filename, - mp->commands, - mp->timeout)) - { - GNUNET_break (0); - mp->rv = EXIT_FAILURE; - } + GNUNET_TESTING_run (mp->commands, + mp->timeout, + &handle_result, + mp); } int -GNUNET_TESTING_main (const char *cfg_filename, - struct GNUNET_TESTING_Command *commands, +GNUNET_TESTING_main (struct GNUNET_TESTING_Command *commands, struct GNUNET_TIME_Relative timeout) { struct MainParams mp = { - .cfg_filename = cfg_filename, .commands = commands, .timeout = timeout, .rv = EXIT_SUCCESS -- cgit v1.2.3 From 961685fab53555a7b62301982927432988b8fdc2 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 4 Oct 2021 22:30:21 +0200 Subject: add missing finish cmd --- src/testing/Makefile.am | 2 +- src/testing/testing_api_cmd_finish.c | 240 +++++++++++++++++++++++++++++++++++ 2 files changed, 241 insertions(+), 1 deletion(-) create mode 100644 src/testing/testing_api_cmd_finish.c (limited to 'src') diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am index 2bb03d157..386fcd041 100644 --- a/src/testing/Makefile.am +++ b/src/testing/Makefile.am @@ -42,10 +42,10 @@ libgnunet_test_testing_plugin_testcmd_la_LIBADD = \ libgnunet_test_testing_plugin_testcmd_la_LDFLAGS = \ $(GN_PLUGIN_LDFLAGS) -# testing_api_cmd_finish.c libgnunettesting_la_SOURCES = \ testing_api_cmd_end.c \ + testing_api_cmd_finish.c \ testing_api_cmd_local_test_finished.c \ testing_api_cmd_send_peer_ready.c \ testing_api_cmd_block_until_all_peers_started.c \ diff --git a/src/testing/testing_api_cmd_finish.c b/src/testing/testing_api_cmd_finish.c new file mode 100644 index 000000000..2bcefd803 --- /dev/null +++ b/src/testing/testing_api_cmd_finish.c @@ -0,0 +1,240 @@ +/* + 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_cmd_finish.c + * @brief command to wait for completion of async command + * @author Christian Grothoff + */ +#include "platform.h" +#include "gnunet_util_lib.h" +#include "gnunet_testing_ng_lib.h" + +/** + * Struct to use for command-specific context information closure of a command waiting + * for another command. + */ +struct FinishState +{ + /** + * Closure for all commands with command-specific context information. + */ + void *cls; + + /** + * Label of the asynchronous command the synchronous command of this closure waits for. + */ + const char *async_label; + + /** + * Task for running the finish method of the asynchronous task the command is waiting for. + */ + struct GNUNET_SCHEDULER_Task *finish_task; + + /** + * Interpreter we are part of. + */ + struct GNUNET_TESTING_Interpreter *is; + + /** + * Function to call when done. + */ + GNUNET_SCHEDULER_TaskCallback cont; + + /** + * Closure for @e cont. + */ + void *cont_cls; + + /** + * How long to wait until finish fails hard? + */ + struct GNUNET_TIME_Relative timeout; + + /** + * Set to #GNUNET_OK if the @a async_label command finished on time + */ + enum GNUNET_GenericReturnValue finished; + +}; + + +/** + */ +static void +done_finish (void *cls) +{ + struct FinishState *finish_state = cls; + + GNUNET_SCHEDULER_cancel (finish_state->finish_task); + finish_state->finish_task = NULL; + finish_state->finished = GNUNET_YES; + if (NULL != finish_state->cont) + { + finish_state->cont (finish_state->cont_cls); + } +} + + +/** + */ +static void +timeout_finish (void *cls) +{ + struct FinishState *finish_state = cls; + + finish_state->finish_task = NULL; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Timeout waiting for command `%s' to finish\n", + finish_state->async_label); + finish_state->finished = GNUNET_SYSERR; + GNUNET_TESTING_interpreter_fail (finish_state->is); +} + + +/** + * Run method of the command created by the interpreter to wait for another + * command to finish. + * + */ +static void +run_finish_on_ref (void *cls, + struct GNUNET_TESTING_Interpreter *is) +{ + struct FinishState *finish_state = cls; + const struct GNUNET_TESTING_Command *async_cmd; + + finish_state->is = is; + async_cmd + = GNUNET_TESTING_interpreter_lookup_command (is, + finish_state->async_label); + if (NULL == async_cmd) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Did not find command `%s'\n", + finish_state->async_label); + GNUNET_TESTING_interpreter_fail (is); + return; + } + if ( (NULL == async_cmd->finish) || + (! async_cmd->asynchronous_finish) ) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Cannot finish `%s': not asynchronous\n", + finish_state->async_label); + GNUNET_TESTING_interpreter_fail (is); + return; + } + finish_state->finish_task + = GNUNET_SCHEDULER_add_delayed (finish_state->timeout, + &timeout_finish, + finish_state); + async_cmd->finish (async_cmd->cls, + &done_finish, + finish_state); +} + + +/** + * Wait for any asynchronous execution of @e run to conclude, + * then call finish_cont. Finish may only be called once per command. + * + * This member may be NULL if this command is a synchronous command, + * and also should be set to NULL once the command has finished. + * + * @param cls closure + * @param cont function to call upon completion, can be NULL + * @param cont_cls closure for @a cont + * @return + * #GNUNET_NO if the command is still running and @a cont will be called later + * #GNUNET_OK if the command completed successfully and @a cont was called + * #GNUNET_SYSERR if the operation @a cont was NOT called + */ +static enum GNUNET_GenericReturnValue +finish_finish_on_ref (void *cls, + GNUNET_SCHEDULER_TaskCallback cont, + void *cont_cls) +{ + struct FinishState *finish_state = cls; + + switch (finish_state->finished) + { + case GNUNET_OK: + cont (cont_cls); + break; + case GNUNET_SYSERR: + GNUNET_break (0); + break; + case GNUNET_NO: + if (NULL != finish_state->cont) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + finish_state->cont = cont; + finish_state->cont_cls = cont_cls; + break; + } + return finish_state->finished; +} + + +/** + * Create (synchronous) command that waits for another command to finish. + * If @a cmd_ref did not finish after @a timeout, this command will fail + * the test case. + * + * @param finish_label label for this command + * @param cmd_ref reference to a previous command which we should + * wait for (call `finish()` on) + * @param timeout how long to wait at most for @a cmd_ref to finish + * @return a finish-command. + */ +const struct GNUNET_TESTING_Command +GNUNET_TESTING_cmd_finish (const char *finish_label, + const char *cmd_ref, + struct GNUNET_TIME_Relative timeout) +{ + struct FinishState *finish_state; + + finish_state = GNUNET_new (struct FinishState); + finish_state->async_label = cmd_ref; + finish_state->timeout = timeout; + { + struct GNUNET_TESTING_Command cmd = { + .cls = finish_state, + .label = finish_label, + .run = &run_finish_on_ref, + .finish = &finish_finish_on_ref + }; + + return cmd; + } +} + + +struct GNUNET_TESTING_Command +GNUNET_TESTING_cmd_make_unblocking (struct GNUNET_TESTING_Command cmd) +{ + /* do not permit this function to be used on + a finish command! */ + GNUNET_assert (cmd.run != &run_finish_on_ref); + cmd.asynchronous_finish = true; + return cmd; +} -- cgit v1.2.3 From ffa7a0ab292b190ed10cd54645593fe31c5796bc Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 6 Oct 2021 09:34:19 +0200 Subject: -fix FTBFS --- .../test_transport_plugin_cmd_simple_send.c | 7 ++-- .../test_transport_plugin_cmd_simple_send_v2.c | 7 ++-- .../test_transport_plugin_cmd_udp_backchannel.c | 7 ++-- src/transport/transport_api_cmd_connecting_peers.c | 18 +++++----- .../transport_api_cmd_connecting_peers_v2.c | 39 ++++++++++++---------- .../transport_api_cmd_connecting_peers_v3.c | 18 ++++++---- src/transport/transport_api_cmd_send_simple.c | 28 ++++++++-------- src/transport/transport_api_cmd_send_simple_v2.c | 28 ++++++++-------- src/transport/transport_api_cmd_start_peer.c | 23 ++++++------- src/transport/transport_api_cmd_start_peer_v2.c | 23 ++++++------- src/transport/transport_api_cmd_start_peer_v3.c | 23 ++++++------- src/transport/transport_api_cmd_stop_peer.c | 27 ++++++++------- 12 files changed, 129 insertions(+), 119 deletions(-) (limited to 'src') diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c b/src/transport/test_transport_plugin_cmd_simple_send.c index 07255a1a5..21167415d 100644 --- a/src/transport/test_transport_plugin_cmd_simple_send.c +++ b/src/transport/test_transport_plugin_cmd_simple_send.c @@ -183,9 +183,10 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, write_message) }; - GNUNET_TESTING_run (NULL, - commands, - GNUNET_TIME_UNIT_FOREVER_REL); + GNUNET_TESTING_run (commands, + GNUNET_TIME_UNIT_FOREVER_REL, + NULL, /* FIXME: will crash */ + NULL); } diff --git a/src/transport/test_transport_plugin_cmd_simple_send_v2.c b/src/transport/test_transport_plugin_cmd_simple_send_v2.c index c79b5c7e2..98e9d5fca 100644 --- a/src/transport/test_transport_plugin_cmd_simple_send_v2.c +++ b/src/transport/test_transport_plugin_cmd_simple_send_v2.c @@ -188,9 +188,10 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, write_message) }; - GNUNET_TESTING_run (NULL, - commands, - GNUNET_TIME_UNIT_FOREVER_REL); + GNUNET_TESTING_run (commands, + GNUNET_TIME_UNIT_FOREVER_REL, + NULL, /* FIXME: will crash */ + NULL); } diff --git a/src/transport/test_transport_plugin_cmd_udp_backchannel.c b/src/transport/test_transport_plugin_cmd_udp_backchannel.c index 90e474aea..6b0342e51 100644 --- a/src/transport/test_transport_plugin_cmd_udp_backchannel.c +++ b/src/transport/test_transport_plugin_cmd_udp_backchannel.c @@ -192,9 +192,10 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, write_message) }; - GNUNET_TESTING_run (NULL, - commands, - GNUNET_TIME_UNIT_FOREVER_REL); + GNUNET_TESTING_run (commands, + GNUNET_TIME_UNIT_FOREVER_REL, + NULL, /* FIMXE: will crash */ + NULL); } diff --git a/src/transport/transport_api_cmd_connecting_peers.c b/src/transport/transport_api_cmd_connecting_peers.c index 09ca9e54c..ddf1c3872 100644 --- a/src/transport/transport_api_cmd_connecting_peers.c +++ b/src/transport/transport_api_cmd_connecting_peers.c @@ -62,6 +62,8 @@ struct ConnectPeersState * */ struct GNUNET_PeerIdentity *id; + + struct GNUNET_TESTING_Interpreter *is; }; @@ -71,7 +73,6 @@ struct ConnectPeersState */ static void connect_peers_run (void *cls, - const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is) { struct ConnectPeersState *cps = cls; @@ -96,7 +97,9 @@ connect_peers_run (void *cls, struct GNUNET_PeerIdentity *other = GNUNET_new (struct GNUNET_PeerIdentity); uint32_t num; - peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label); + cps->is = is; + peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is, + cps->start_peer_label); GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd, &ah); @@ -106,7 +109,8 @@ connect_peers_run (void *cls, GNUNET_TRANSPORT_get_trait_peer_id (peer1_cmd, &id); - system_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->create_label); + system_cmd = GNUNET_TESTING_interpreter_lookup_command (is, + cps->create_label); GNUNET_TESTING_get_trait_test_system (system_cmd, &tl_system); @@ -116,8 +120,6 @@ connect_peers_run (void *cls, num = 2; - - // if (strstr (hello, "60002") != NULL) if (2 == num) { @@ -194,7 +196,8 @@ connect_peers_finish (void *cls, struct GNUNET_HashCode hc; int node_number; - peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label); + peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->is, + cps->start_peer_label); GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd, &connected_peers_map); @@ -237,8 +240,7 @@ connect_peers_traits (void *cls, * */ static void -connect_peers_cleanup (void *cls, - const struct GNUNET_TESTING_Command *cmd) +connect_peers_cleanup (void *cls) { struct ConnectPeersState *cps = cls; diff --git a/src/transport/transport_api_cmd_connecting_peers_v2.c b/src/transport/transport_api_cmd_connecting_peers_v2.c index 0d286b714..8ef556946 100644 --- a/src/transport/transport_api_cmd_connecting_peers_v2.c +++ b/src/transport/transport_api_cmd_connecting_peers_v2.c @@ -64,6 +64,8 @@ struct ConnectPeersState * */ struct GNUNET_PeerIdentity *id; + + struct GNUNET_TESTING_Interpreter *is; }; @@ -73,7 +75,6 @@ struct ConnectPeersState */ static void connect_peers_run (void *cls, - const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is) { struct ConnectPeersState *cps = cls; @@ -91,11 +92,14 @@ connect_peers_run (void *cls, struct GNUNET_PeerIdentity *other = GNUNET_new (struct GNUNET_PeerIdentity); uint32_t num; - peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label); + cps->is = is; + peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is, + cps->start_peer_label); GNUNET_TRANSPORT_get_trait_application_handle_v2 (peer1_cmd, &ah); - system_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->create_label); + system_cmd = GNUNET_TESTING_interpreter_lookup_command (is, + cps->create_label); GNUNET_TESTING_get_trait_test_system (system_cmd, &tl_system); @@ -155,7 +159,8 @@ connect_peers_finish (void *cls, struct GNUNET_HashCode hc; int node_number; - peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label); + peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->is, + cps->start_peer_label); GNUNET_TRANSPORT_get_trait_connected_peers_map_v2 (peer1_cmd, &connected_peers_map); @@ -198,8 +203,7 @@ connect_peers_traits (void *cls, * */ static void -connect_peers_cleanup (void *cls, - const struct GNUNET_TESTING_Command *cmd) +connect_peers_cleanup (void *cls) { struct ConnectPeersState *cps = cls; @@ -228,15 +232,16 @@ GNUNET_TRANSPORT_cmd_connect_peers_v2 (const char *label, cps->num = num; cps->create_label = create_label; - - struct GNUNET_TESTING_Command cmd = { - .cls = cps, - .label = label, - .run = &connect_peers_run, - .finish = &connect_peers_finish, - .cleanup = &connect_peers_cleanup, - .traits = &connect_peers_traits - }; - - return cmd; + { + struct GNUNET_TESTING_Command cmd = { + .cls = cps, + .label = label, + .run = &connect_peers_run, + .finish = &connect_peers_finish, + .cleanup = &connect_peers_cleanup, + .traits = &connect_peers_traits + }; + + return cmd; + } } diff --git a/src/transport/transport_api_cmd_connecting_peers_v3.c b/src/transport/transport_api_cmd_connecting_peers_v3.c index e90781637..a73d81064 100644 --- a/src/transport/transport_api_cmd_connecting_peers_v3.c +++ b/src/transport/transport_api_cmd_connecting_peers_v3.c @@ -94,6 +94,8 @@ struct ConnectPeersState */ struct GNUNET_TESTING_NodeConnection *node_connections_head; + struct GNUNET_TESTING_Interpreter *is; + /** * Number of connections. */ @@ -264,6 +266,7 @@ calculate_num (struct GNUNET_TESTING_NodeConnection *node_connection, return num; } + static char * get_address (struct GNUNET_TESTING_NodeConnection *connection, char *prefix) @@ -323,7 +326,6 @@ get_address (struct GNUNET_TESTING_NodeConnection *connection, */ static void connect_peers_run (void *cls, - const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is) { struct ConnectPeersState *cps = cls; @@ -341,11 +343,14 @@ connect_peers_run (void *cls, struct GNUNET_TESTING_ADDRESS_PREFIX *pos_prefix; unsigned int con_num = 0; - peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label); + cps->is = is; + peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is, + cps->start_peer_label); GNUNET_TRANSPORT_get_trait_application_handle_v2 (peer1_cmd, &ah); - system_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->create_label); + system_cmd = GNUNET_TESTING_interpreter_lookup_command (is, + cps->create_label); GNUNET_TESTING_get_trait_test_system (system_cmd, &tl_system); @@ -410,7 +415,8 @@ connect_peers_finish (void *cls, struct GNUNET_TESTING_NodeConnection *pos_connection; unsigned int num; - peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label); + peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->is, + cps->start_peer_label); GNUNET_TRANSPORT_get_trait_connected_peers_map_v2 (peer1_cmd, &connected_peers_map); @@ -430,7 +436,6 @@ connect_peers_finish (void *cls, } - if (cps->con_num == con_num) { cont (cont_cls); @@ -461,8 +466,7 @@ connect_peers_traits (void *cls, * */ static void -connect_peers_cleanup (void *cls, - const struct GNUNET_TESTING_Command *cmd) +connect_peers_cleanup (void *cls) { struct ConnectPeersState *cps = cls; diff --git a/src/transport/transport_api_cmd_send_simple.c b/src/transport/transport_api_cmd_send_simple.c index f9e515c0f..1599dfe97 100644 --- a/src/transport/transport_api_cmd_send_simple.c +++ b/src/transport/transport_api_cmd_send_simple.c @@ -80,8 +80,7 @@ send_simple_traits (void *cls, * */ static void -send_simple_cleanup (void *cls, - const struct GNUNET_TESTING_Command *cmd) +send_simple_cleanup (void *cls) { struct SendSimpleState *sss = cls; @@ -95,7 +94,6 @@ send_simple_cleanup (void *cls, */ static void send_simple_run (void *cls, - const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is) { struct SendSimpleState *sss = cls; @@ -108,7 +106,8 @@ send_simple_run (void *cls, struct GNUNET_HashCode hc; int node_number; - peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->start_peer_label); + peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is, + sss->start_peer_label); GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd, &connected_peers_map); @@ -159,14 +158,15 @@ GNUNET_TRANSPORT_cmd_send_simple (const char *label, sss->n = n; sss->num = num; sss->start_peer_label = start_peer_label; - - struct GNUNET_TESTING_Command cmd = { - .cls = sss, - .label = label, - .run = &send_simple_run, - .cleanup = &send_simple_cleanup, - .traits = &send_simple_traits - }; - - return cmd; + { + struct GNUNET_TESTING_Command cmd = { + .cls = sss, + .label = label, + .run = &send_simple_run, + .cleanup = &send_simple_cleanup, + .traits = &send_simple_traits + }; + + return cmd; + } } diff --git a/src/transport/transport_api_cmd_send_simple_v2.c b/src/transport/transport_api_cmd_send_simple_v2.c index d43c0b425..8d65eb684 100644 --- a/src/transport/transport_api_cmd_send_simple_v2.c +++ b/src/transport/transport_api_cmd_send_simple_v2.c @@ -68,8 +68,7 @@ send_simple_traits (void *cls, * */ static void -send_simple_cleanup (void *cls, - const struct GNUNET_TESTING_Command *cmd) +send_simple_cleanup (void *cls) { struct SendSimpleState *sss = cls; @@ -83,7 +82,6 @@ send_simple_cleanup (void *cls, */ static void send_simple_run (void *cls, - const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is) { struct SendSimpleState *sss = cls; @@ -96,7 +94,8 @@ send_simple_run (void *cls, struct GNUNET_HashCode hc; int node_number; - peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->start_peer_label); + peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is, + sss->start_peer_label); GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd, &connected_peers_map); @@ -143,14 +142,15 @@ GNUNET_TRANSPORT_cmd_send_simple_v2 (const char *label, sss = GNUNET_new (struct SendSimpleState); sss->num = num; sss->start_peer_label = start_peer_label; - - struct GNUNET_TESTING_Command cmd = { - .cls = sss, - .label = label, - .run = &send_simple_run, - .cleanup = &send_simple_cleanup, - .traits = &send_simple_traits - }; - - return cmd; + { + struct GNUNET_TESTING_Command cmd = { + .cls = sss, + .label = label, + .run = &send_simple_run, + .cleanup = &send_simple_cleanup, + .traits = &send_simple_traits + }; + + return cmd; + } } diff --git a/src/transport/transport_api_cmd_start_peer.c b/src/transport/transport_api_cmd_start_peer.c index f4e92944b..8a53ed22c 100644 --- a/src/transport/transport_api_cmd_start_peer.c +++ b/src/transport/transport_api_cmd_start_peer.c @@ -177,7 +177,6 @@ notify_connect (void *cls, */ static void start_peer_run (void *cls, - const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is) { struct StartPeerState *sps = cls; @@ -195,7 +194,7 @@ start_peer_run (void *cls, LOG (GNUNET_ERROR_TYPE_ERROR, "File not found: `%s'\n", sps->cfgname); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); return; } @@ -232,7 +231,8 @@ start_peer_run (void *cls, "UNIXPATH", communicator_unix_path); - system_cmd = GNUNET_TESTING_interpreter_lookup_command (sps->system_label); + system_cmd = GNUNET_TESTING_interpreter_lookup_command (is, + sps->system_label); GNUNET_TESTING_get_trait_test_system (system_cmd, &tl_system); @@ -246,7 +246,7 @@ start_peer_run (void *cls, "Testing library failed to create unique configuration based on `%s'\n", sps->cfgname); GNUNET_CONFIGURATION_destroy (sps->cfg); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); return; } @@ -262,7 +262,7 @@ start_peer_run (void *cls, sps->cfgname, emsg); GNUNET_free (emsg); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); return; } @@ -272,7 +272,7 @@ start_peer_run (void *cls, "Testing library failed to create unique configuration based on `%s'\n", sps->cfgname); GNUNET_free (emsg); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); return; } @@ -291,7 +291,7 @@ start_peer_run (void *cls, "Testing library failed to obtain peer identity for peer %u\n", sps->no); GNUNET_free (emsg); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); return; } LOG (GNUNET_ERROR_TYPE_DEBUG, @@ -312,7 +312,7 @@ start_peer_run (void *cls, sps->cfgname, emsg); GNUNET_free (emsg); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); return; } @@ -324,7 +324,7 @@ start_peer_run (void *cls, sps->cfgname, emsg); GNUNET_free (emsg); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); return; } @@ -336,7 +336,7 @@ start_peer_run (void *cls, sps->cfgname, emsg); GNUNET_free (emsg); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); return; } sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps); @@ -348,8 +348,7 @@ start_peer_run (void *cls, * */ static void -start_peer_cleanup (void *cls, - const struct GNUNET_TESTING_Command *cmd) +start_peer_cleanup (void *cls) { struct StartPeerState *sps = cls; diff --git a/src/transport/transport_api_cmd_start_peer_v2.c b/src/transport/transport_api_cmd_start_peer_v2.c index 0e39bd915..2ab58574a 100644 --- a/src/transport/transport_api_cmd_start_peer_v2.c +++ b/src/transport/transport_api_cmd_start_peer_v2.c @@ -177,7 +177,6 @@ notify_connect (void *cls, */ static void start_peer_run (void *cls, - const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is) { struct StartPeerState_v2 *sps = cls; @@ -195,7 +194,7 @@ start_peer_run (void *cls, LOG (GNUNET_ERROR_TYPE_ERROR, "File not found: `%s'\n", sps->cfgname); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); return; } @@ -232,7 +231,8 @@ start_peer_run (void *cls, "UNIXPATH", communicator_unix_path); - system_cmd = GNUNET_TESTING_interpreter_lookup_command (sps->system_label); + system_cmd = GNUNET_TESTING_interpreter_lookup_command (is, + sps->system_label); GNUNET_TESTING_get_trait_test_system (system_cmd, &tl_system); @@ -246,7 +246,7 @@ start_peer_run (void *cls, "Testing library failed to create unique configuration based on `%s'\n", sps->cfgname); GNUNET_CONFIGURATION_destroy (sps->cfg); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); return; } @@ -262,7 +262,7 @@ start_peer_run (void *cls, sps->cfgname, emsg); GNUNET_free (emsg); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); return; } @@ -272,7 +272,7 @@ start_peer_run (void *cls, "Testing library failed to create unique configuration based on `%s'\n", sps->cfgname); GNUNET_free (emsg); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); return; } @@ -291,7 +291,7 @@ start_peer_run (void *cls, "Testing library failed to obtain peer identity for peer %u\n", sps->no); GNUNET_free (emsg); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); return; } LOG (GNUNET_ERROR_TYPE_DEBUG, @@ -312,7 +312,7 @@ start_peer_run (void *cls, sps->cfgname, emsg); GNUNET_free (emsg); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); return; } @@ -324,7 +324,7 @@ start_peer_run (void *cls, sps->cfgname, emsg); GNUNET_free (emsg); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); return; } @@ -336,7 +336,7 @@ start_peer_run (void *cls, sps->cfgname, emsg); GNUNET_free (emsg); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); return; } sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps); @@ -348,8 +348,7 @@ start_peer_run (void *cls, * */ static void -start_peer_cleanup (void *cls, - const struct GNUNET_TESTING_Command *cmd) +start_peer_cleanup (void *cls) { struct StartPeerState_v2 *sps = cls; diff --git a/src/transport/transport_api_cmd_start_peer_v3.c b/src/transport/transport_api_cmd_start_peer_v3.c index b5cefecc8..fa6300ef5 100644 --- a/src/transport/transport_api_cmd_start_peer_v3.c +++ b/src/transport/transport_api_cmd_start_peer_v3.c @@ -175,7 +175,6 @@ notify_connect (void *cls, */ static void start_peer_run (void *cls, - const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is) { struct StartPeerState_v2 *sps = cls; @@ -194,7 +193,7 @@ start_peer_run (void *cls, LOG (GNUNET_ERROR_TYPE_ERROR, "File not found: `%s'\n", sps->cfgname); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); return; } @@ -244,7 +243,8 @@ start_peer_run (void *cls, "UNIXPATH", udp_communicator_unix_path); - system_cmd = GNUNET_TESTING_interpreter_lookup_command (sps->system_label); + system_cmd = GNUNET_TESTING_interpreter_lookup_command (is, + sps->system_label); GNUNET_TESTING_get_trait_test_system (system_cmd, &tl_system); @@ -258,7 +258,7 @@ start_peer_run (void *cls, "Testing library failed to create unique configuration based on `%s'\n", sps->cfgname); GNUNET_CONFIGURATION_destroy (sps->cfg); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); return; } @@ -274,7 +274,7 @@ start_peer_run (void *cls, sps->cfgname, emsg); GNUNET_free (emsg); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); return; } @@ -284,7 +284,7 @@ start_peer_run (void *cls, "Testing library failed to create unique configuration based on `%s'\n", sps->cfgname); GNUNET_free (emsg); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); return; } @@ -303,7 +303,7 @@ start_peer_run (void *cls, "Testing library failed to obtain peer identity for peer %u\n", sps->no); GNUNET_free (emsg); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); return; } LOG (GNUNET_ERROR_TYPE_DEBUG, @@ -324,7 +324,7 @@ start_peer_run (void *cls, sps->cfgname, emsg); GNUNET_free (emsg); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); return; } @@ -336,7 +336,7 @@ start_peer_run (void *cls, sps->cfgname, emsg); GNUNET_free (emsg); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); return; } @@ -348,7 +348,7 @@ start_peer_run (void *cls, sps->cfgname, emsg); GNUNET_free (emsg); - GNUNET_TESTING_interpreter_fail (); + GNUNET_TESTING_interpreter_fail (is); return; } sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps); @@ -360,8 +360,7 @@ start_peer_run (void *cls, * */ static void -start_peer_cleanup (void *cls, - const struct GNUNET_TESTING_Command *cmd) +start_peer_cleanup (void *cls) { struct StartPeerState_v2 *sps = cls; diff --git a/src/transport/transport_api_cmd_stop_peer.c b/src/transport/transport_api_cmd_stop_peer.c index 4d7228378..dcb982a65 100644 --- a/src/transport/transport_api_cmd_stop_peer.c +++ b/src/transport/transport_api_cmd_stop_peer.c @@ -54,14 +54,14 @@ struct StopPeerState */ static void stop_peer_run (void *cls, - const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is) { struct StopPeerState *stop_ps = cls; struct StartPeerState *sps; const struct GNUNET_TESTING_Command *start_cmd; - start_cmd = GNUNET_TESTING_interpreter_lookup_command (stop_ps->start_label); + start_cmd = GNUNET_TESTING_interpreter_lookup_command (is, + stop_ps->start_label); GNUNET_TRANSPORT_get_trait_state (start_cmd, &sps); @@ -112,8 +112,7 @@ stop_peer_run (void *cls, * */ static void -stop_peer_cleanup (void *cls, - const struct GNUNET_TESTING_Command *cmd) +stop_peer_cleanup (void *cls) { struct StopPeerState *sps = cls; @@ -150,14 +149,14 @@ GNUNET_TRANSPORT_cmd_stop_peer (const char *label, sps = GNUNET_new (struct StopPeerState); sps->start_label = start_label; - - struct GNUNET_TESTING_Command cmd = { - .cls = sps, - .label = label, - .run = &stop_peer_run, - .cleanup = &stop_peer_cleanup, - .traits = &stop_peer_traits - }; - - return cmd; + { + struct GNUNET_TESTING_Command cmd = { + .cls = sps, + .label = label, + .run = &stop_peer_run, + .cleanup = &stop_peer_cleanup, + .traits = &stop_peer_traits + }; + return cmd; + } } -- cgit v1.2.3 From 6ef071b8ccea72da6a9e1eee6483c326b6ebc082 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 6 Oct 2021 18:53:37 +0200 Subject: fix #7029 --- src/dht/gnunet-service-dht_neighbours.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index ca255310c..6465d8d57 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c @@ -844,6 +844,10 @@ get_forward_count (uint32_t hop_count, uint32_t forward_count; float target_value; + if (0 == target_replication) + target_replication = 1; /* 0 is verboten */ + if (target_replication > MAXIMUM_REPLICATION_LEVEL) + target_replication = MAXIMUM_REPLICATION_LEVEL; if (hop_count > GDS_NSE_get () * 4.0) { /* forcefully terminate */ @@ -864,6 +868,8 @@ get_forward_count (uint32_t hop_count, 1 + (target_replication - 1.0) / (GDS_NSE_get () + ((float) (target_replication - 1.0) * hop_count)); + + /* Set forward count to floor of target_value */ forward_count = (uint32_t) target_value; /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */ @@ -872,7 +878,8 @@ get_forward_count (uint32_t hop_count, GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); if (random_value < (target_value * UINT32_MAX)) forward_count++; - return forward_count; + return GNUNET_MIN (forward_count, + MAXIMUM_REPLICATION_LEVEL); } -- cgit v1.2.3 From bd8f79f628b254f4f02c08284ba65d23486d6127 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 8 Oct 2021 21:50:34 +0200 Subject: -clean up testing-NG finish logic --- src/dhtu/testing_dhtu_cmd_send.c | 60 +---------- src/include/gnunet_testing_ng_lib.h | 81 ++++++++++----- ...testing_api_cmd_block_until_all_peers_started.c | 56 ++--------- .../testing_api_cmd_block_until_external_trigger.c | 57 ++--------- src/testing/testing_api_cmd_finish.c | 112 +++++++-------------- src/testing/testing_api_cmd_local_test_finished.c | 34 +------ src/testing/testing_api_cmd_netjail_start.c | 62 ++++-------- .../testing_api_cmd_netjail_start_testsystem.c | 31 ++++-- .../testing_api_cmd_netjail_start_testsystem_v2.c | 8 +- src/testing/testing_api_cmd_netjail_start_v2.c | 55 ++-------- src/testing/testing_api_cmd_netjail_stop.c | 45 ++------- src/testing/testing_api_cmd_netjail_stop_v2.c | 64 +++--------- src/testing/testing_api_loop.c | 53 +++++++--- src/transport/transport_api_cmd_connecting_peers.c | 49 ++++----- .../transport_api_cmd_connecting_peers_v2.c | 24 ++--- .../transport_api_cmd_connecting_peers_v3.c | 48 +++------ src/transport/transport_api_cmd_start_peer.c | 42 +++----- src/transport/transport_api_cmd_start_peer_v2.c | 1 - src/transport/transport_api_cmd_start_peer_v3.c | 1 - 19 files changed, 288 insertions(+), 595 deletions(-) (limited to 'src') diff --git a/src/dhtu/testing_dhtu_cmd_send.c b/src/dhtu/testing_dhtu_cmd_send.c index 129a31205..e620e329e 100644 --- a/src/dhtu/testing_dhtu_cmd_send.c +++ b/src/dhtu/testing_dhtu_cmd_send.c @@ -34,16 +34,10 @@ struct SendState { /** - * Function to call when done. + * Mandatory context for async commands. */ - GNUNET_SCHEDULER_TaskCallback cont; + struct GNUNET_TESTING_AsyncContext ac; - /** - * Closure for @e cont. - */ - void *cont_cls; - - enum GNUNET_GenericReturnValue finished; }; @@ -98,56 +92,10 @@ send_run (void *cls, GNUNET_TESTING_get_trait_XXX (other_cmd, &data); #endif - ss->finished = GNUNET_OK; + GNUNET_TESTING_async_finish (&ss->ac); } -/** - * This function checks the flag NetJailState#finished, if this cmd finished. - * - * @param cls a `struct SendState` - * @param cont function to call upon completion, can be NULL - * @param cont_cls closure for @a cont - * @return - * #GNUNET_NO if the command is still running and @a cont will be called later - * #GNUNET_OK if the command completed successfully and @a cont was called - * #GNUNET_SYSERR if the operation @a cont was NOT called - */ -static enum GNUNET_GenericReturnValue -send_finish (void *cls, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls) -{ - struct SendState *ss = cls; - - switch (ss->finished) - { - case GNUNET_OK: - cont (cont_cls); - break; - case GNUNET_SYSERR: - GNUNET_break (0); - break; - case GNUNET_NO: - if (NULL != ss->cont) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - ss->cont = cont; - ss->cont_cls = cont_cls; - break; - } - return ss->finished; -} - - -/** - * Create 'send' command. - * - * @param label name for command. - * @return command. - */ struct GNUNET_TESTING_Command GNUNET_TESTING_DHTU_cmd_send (const char *label) { @@ -160,7 +108,7 @@ GNUNET_TESTING_DHTU_cmd_send (const char *label) .cls = ss, .label = label, .run = &send_run, - .finish = &send_finish, + .ac = &ss->ac, .cleanup = &send_cleanup, .traits = &send_traits }; diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h index 4ef9aac18..0cab64504 100644 --- a/src/include/gnunet_testing_ng_lib.h +++ b/src/include/gnunet_testing_ng_lib.h @@ -82,7 +82,7 @@ enum GNUNET_TESTING_NODE_TYPE }; - // FIXME: this does not belong here! +// FIXME: this does not belong here! struct GNUNET_TESTING_ADDRESS_PREFIX { /** @@ -260,6 +260,36 @@ struct GNUNET_TESTING_NetjailTopology */ struct GNUNET_TESTING_Interpreter; +/** + * State each asynchronous command must have in its closure. + */ +struct GNUNET_TESTING_AsyncContext +{ + + /** + * Interpreter we are part of. + */ + struct GNUNET_TESTING_Interpreter *is; + + /** + * Function to call when done. + */ + GNUNET_SCHEDULER_TaskCallback cont; + + /** + * Closure for @e cont. + */ + void *cont_cls; + + /** + * Indication if the command finished (#GNUNET_OK). + * #GNUNET_NO if it is still running, + * #GNUNET_SYSERR if it failed. + */ + enum GNUNET_GenericReturnValue finished; +}; + + /** * A command to be run by the interpreter. */ @@ -296,27 +326,14 @@ struct GNUNET_TESTING_Command struct GNUNET_TESTING_Interpreter *is); /** - * FIXME: logic is basically always the same! - * => Refactor API to avoid duplication! + * Pointer to the asynchronous context in the command's + * closure. Used by the + * #GNUNET_TESTING_async_finish() and + * #GNUNET_TESTING_async_fail() functions. * - * Wait for any asynchronous execution of @e run to conclude, - * then call finish_cont. Finish may only be called once per command. - * - * This member may be NULL if this command is a synchronous command, - * and also should be set to NULL once the command has finished. - * - * @param cls closure - * @param cont function to call upon completion, can be NULL - * @param cont_cls closure for @a cont - * @return - * #GNUNET_NO if the command is still running and @a cont will be called later - * #GNUNET_OK if the command completed successfully and @a cont was called - * #GNUNET_SYSERR if the operation @a cont was NOT called + * Must be NULL if a command is synchronous. */ - enum GNUNET_GenericReturnValue - (*finish)(void *cls, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls); + struct GNUNET_TESTING_AsyncContext *ac; /** * Clean up after the command. Run during forced termination @@ -328,11 +345,8 @@ struct GNUNET_TESTING_Command (*cleanup)(void *cls); /** - * FIXME: logic is often the same! - * => Think about refactoring API to reduce duplication! - * * Extract information from a command that is useful for other - * commands. + * commands. Can be NULL if a command has no traits. * * @param cls closure * @param[out] ret result (could be anything) @@ -427,6 +441,24 @@ void GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is); +/** + * The asynchronous command of @a ac has failed. + * + * @param ac command-specific context + */ +void +GNUNET_TESTING_async_fail (struct GNUNET_TESTING_AsyncContext *ac); + + +/** + * The asynchronous command of @a ac has finished. + * + * @param ac command-specific context + */ +void +GNUNET_TESTING_async_finish (struct GNUNET_TESTING_AsyncContext *ac); + + /** * Create command array terminator. * @@ -1116,7 +1148,6 @@ GNUNET_TESTING_cmd_stop_testing_system_v2 (const char *label, const char *topology_config); - // FIXME: document! enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_helper_handles (const struct diff --git a/src/testing/testing_api_cmd_block_until_all_peers_started.c b/src/testing/testing_api_cmd_block_until_all_peers_started.c index fb51c1066..8a47a7ce0 100644 --- a/src/testing/testing_api_cmd_block_until_all_peers_started.c +++ b/src/testing/testing_api_cmd_block_until_all_peers_started.c @@ -46,20 +46,6 @@ struct BlockState }; -/** - * Trait function of this cmd does nothing. - * - */ -static int -block_until_all_peers_started_traits (void *cls, - const void **ret, - const char *trait, - unsigned int index) -{ - return GNUNET_OK; -} - - /** * The cleanup function of this cmd frees resources the cmd allocated. * @@ -86,27 +72,6 @@ block_until_all_peers_started_run (void *cls, } -/** - * Function to check if BlockState#all_peers_started is GNUNET_YES. In that case interpreter_next will be called. - * - */ -static int -block_until_all_peers_started_finish (void *cls, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls) -{ - struct BlockState *bs = cls; - unsigned int *ret = bs->all_peers_started; - - if (GNUNET_YES == *ret) - { - cont (cont_cls); - } - - return *ret; -} - - /** * Create command. * @@ -123,15 +88,14 @@ GNUNET_TESTING_cmd_block_until_all_peers_started (const char *label, bs = GNUNET_new (struct BlockState); bs->all_peers_started = all_peers_started; - - struct GNUNET_TESTING_Command cmd = { - .cls = bs, - .label = label, - .run = &block_until_all_peers_started_run, - .finish = &block_until_all_peers_started_finish, - .cleanup = &block_until_all_peers_started_cleanup, - .traits = &block_until_all_peers_started_traits - }; - - return cmd; + { + struct GNUNET_TESTING_Command cmd = { + .cls = bs, + .label = label, + .run = &block_until_all_peers_started_run, + .cleanup = &block_until_all_peers_started_cleanup + }; + + return cmd; + } } 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 d69040b75..b416fa595 100644 --- a/src/testing/testing_api_cmd_block_until_external_trigger.c +++ b/src/testing/testing_api_cmd_block_until_external_trigger.c @@ -40,26 +40,11 @@ struct BlockState { /** * Flag to indicate if all peers have started. - * */ unsigned int *stop_blocking; }; -/** - * Trait function of this cmd does nothing. - * - */ -static int -block_until_all_peers_started_traits (void *cls, - const void **ret, - const char *trait, - unsigned int index) -{ - return GNUNET_NO; -} - - /** * The cleanup function of this cmd frees resources the cmd allocated. * @@ -86,27 +71,6 @@ block_until_all_peers_started_run (void *cls, } -/** - * Function to check if BlockState#all_peers_started is GNUNET_YES. In that case interpreter_next will be called. - * - */ -static int -block_until_all_peers_started_finish (void *cls, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls) -{ - struct BlockState *bs = cls; - unsigned int *ret = bs->stop_blocking; - - if (GNUNET_YES == *ret) - { - cont (cont_cls); - } - - return *ret; -} - - /** * Create command. * @@ -123,15 +87,14 @@ GNUNET_TESTING_cmd_block_until_external_trigger (const char *label, bs = GNUNET_new (struct BlockState); bs->stop_blocking = stop_blocking; - - struct GNUNET_TESTING_Command cmd = { - .cls = bs, - .label = label, - .run = &block_until_all_peers_started_run, - .finish = &block_until_all_peers_started_finish, - .cleanup = &block_until_all_peers_started_cleanup, - .traits = &block_until_all_peers_started_traits - }; - - return cmd; + { + struct GNUNET_TESTING_Command cmd = { + .cls = bs, + .label = label, + .run = &block_until_all_peers_started_run, + .cleanup = &block_until_all_peers_started_cleanup, + }; + + return cmd; + } } diff --git a/src/testing/testing_api_cmd_finish.c b/src/testing/testing_api_cmd_finish.c index 2bcefd803..3ac0871a5 100644 --- a/src/testing/testing_api_cmd_finish.c +++ b/src/testing/testing_api_cmd_finish.c @@ -47,35 +47,24 @@ struct FinishState */ struct GNUNET_SCHEDULER_Task *finish_task; - /** - * Interpreter we are part of. - */ - struct GNUNET_TESTING_Interpreter *is; - /** * Function to call when done. */ - GNUNET_SCHEDULER_TaskCallback cont; - - /** - * Closure for @e cont. - */ - void *cont_cls; + struct GNUNET_TESTING_AsyncContext ac; /** * How long to wait until finish fails hard? */ struct GNUNET_TIME_Relative timeout; - /** - * Set to #GNUNET_OK if the @a async_label command finished on time - */ - enum GNUNET_GenericReturnValue finished; - }; /** + * Function called when the command we are waiting on + * is finished. Hence we are finished, too. + * + * @param cls a `struct FinishState` being notified */ static void done_finish (void *cls) @@ -84,15 +73,15 @@ done_finish (void *cls) GNUNET_SCHEDULER_cancel (finish_state->finish_task); finish_state->finish_task = NULL; - finish_state->finished = GNUNET_YES; - if (NULL != finish_state->cont) - { - finish_state->cont (finish_state->cont_cls); - } + GNUNET_TESTING_async_finish (&finish_state->ac); } /** + * Function triggered if the command we are waiting + * for did not complete on time. + * + * @param cls our `struct FinishState` */ static void timeout_finish (void *cls) @@ -103,8 +92,7 @@ timeout_finish (void *cls) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Timeout waiting for command `%s' to finish\n", finish_state->async_label); - finish_state->finished = GNUNET_SYSERR; - GNUNET_TESTING_interpreter_fail (finish_state->is); + GNUNET_TESTING_async_fail (&finish_state->ac); } @@ -114,13 +102,13 @@ timeout_finish (void *cls) * */ static void -run_finish_on_ref (void *cls, - struct GNUNET_TESTING_Interpreter *is) +run_finish (void *cls, + struct GNUNET_TESTING_Interpreter *is) { struct FinishState *finish_state = cls; const struct GNUNET_TESTING_Command *async_cmd; + struct GNUNET_TESTING_AsyncContext *aac; - finish_state->is = is; async_cmd = GNUNET_TESTING_interpreter_lookup_command (is, finish_state->async_label); @@ -132,7 +120,7 @@ run_finish_on_ref (void *cls, GNUNET_TESTING_interpreter_fail (is); return; } - if ( (NULL == async_cmd->finish) || + if ( (NULL == (aac = async_cmd->ac)) || (! async_cmd->asynchronous_finish) ) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -141,71 +129,40 @@ run_finish_on_ref (void *cls, GNUNET_TESTING_interpreter_fail (is); return; } + if (GNUNET_NO != aac->finished) + { + /* Command is already finished, so are we! */ + GNUNET_TESTING_async_finish (&finish_state->ac); + return; + } finish_state->finish_task = GNUNET_SCHEDULER_add_delayed (finish_state->timeout, &timeout_finish, finish_state); - async_cmd->finish (async_cmd->cls, - &done_finish, - finish_state); + aac->cont = &done_finish; + aac->cont_cls = finish_state; } /** - * Wait for any asynchronous execution of @e run to conclude, - * then call finish_cont. Finish may only be called once per command. + * Cleanup state of a finish command. * - * This member may be NULL if this command is a synchronous command, - * and also should be set to NULL once the command has finished. - * - * @param cls closure - * @param cont function to call upon completion, can be NULL - * @param cont_cls closure for @a cont - * @return - * #GNUNET_NO if the command is still running and @a cont will be called later - * #GNUNET_OK if the command completed successfully and @a cont was called - * #GNUNET_SYSERR if the operation @a cont was NOT called + * @param cls a `struct FinishState` to clean up */ -static enum GNUNET_GenericReturnValue -finish_finish_on_ref (void *cls, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls) +static void +cleanup_finish (void *cls) { struct FinishState *finish_state = cls; - switch (finish_state->finished) + if (NULL != finish_state->finish_task) { - case GNUNET_OK: - cont (cont_cls); - break; - case GNUNET_SYSERR: - GNUNET_break (0); - break; - case GNUNET_NO: - if (NULL != finish_state->cont) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - finish_state->cont = cont; - finish_state->cont_cls = cont_cls; - break; + GNUNET_SCHEDULER_cancel (finish_state->finish_task); + finish_state->finish_task = NULL; } - return finish_state->finished; + GNUNET_free (finish_state); } -/** - * Create (synchronous) command that waits for another command to finish. - * If @a cmd_ref did not finish after @a timeout, this command will fail - * the test case. - * - * @param finish_label label for this command - * @param cmd_ref reference to a previous command which we should - * wait for (call `finish()` on) - * @param timeout how long to wait at most for @a cmd_ref to finish - * @return a finish-command. - */ const struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_finish (const char *finish_label, const char *cmd_ref, @@ -220,8 +177,9 @@ GNUNET_TESTING_cmd_finish (const char *finish_label, struct GNUNET_TESTING_Command cmd = { .cls = finish_state, .label = finish_label, - .run = &run_finish_on_ref, - .finish = &finish_finish_on_ref + .run = &run_finish, + .ac = &finish_state->ac, + .cleanup = &cleanup_finish }; return cmd; @@ -234,7 +192,7 @@ GNUNET_TESTING_cmd_make_unblocking (struct GNUNET_TESTING_Command cmd) { /* do not permit this function to be used on a finish command! */ - GNUNET_assert (cmd.run != &run_finish_on_ref); + GNUNET_assert (cmd.run != &run_finish); cmd.asynchronous_finish = true; return cmd; } diff --git a/src/testing/testing_api_cmd_local_test_finished.c b/src/testing/testing_api_cmd_local_test_finished.c index da4aff80f..0e7e214dc 100644 --- a/src/testing/testing_api_cmd_local_test_finished.c +++ b/src/testing/testing_api_cmd_local_test_finished.c @@ -40,6 +40,7 @@ */ struct LocalFinishedState { + /** * Callback to write messages to the master loop. * @@ -54,20 +55,6 @@ struct LocalFinishedState }; -/** - * Trait function of this cmd does nothing. - * - */ -static enum GNUNET_GenericReturnValue -local_test_finished_traits (void *cls, - const void **ret, - const char *trait, - unsigned int index) -{ - return GNUNET_NO; -} - - /** * The cleanup function of this cmd frees resources the cmd allocated. * @@ -104,23 +91,6 @@ local_test_finished_run (void *cls, } -/** - * 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 enum GNUNET_GenericReturnValue -local_test_finished_finish (void *cls, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls) -{ - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Stopping local loop\n"); - return GNUNET_YES; -} - - /** * Create command. * @@ -142,9 +112,7 @@ GNUNET_TESTING_cmd_local_test_finished ( .cls = lfs, .label = label, .run = &local_test_finished_run, - .finish = &local_test_finished_finish, .cleanup = &local_test_finished_cleanup, - .traits = &local_test_finished_traits }; return cmd; diff --git a/src/testing/testing_api_cmd_netjail_start.c b/src/testing/testing_api_cmd_netjail_start.c index 1815b64d2..4b5592524 100644 --- a/src/testing/testing_api_cmd_netjail_start.c +++ b/src/testing/testing_api_cmd_netjail_start.c @@ -35,6 +35,11 @@ */ struct NetJailState { + /** + * Context for our asynchronous completion. + */ + struct GNUNET_TESTING_AsyncContext ac; + // Child Wait handle struct GNUNET_ChildWaitHandle *cwh; @@ -67,7 +72,6 @@ netjail_start_cleanup (void *cls) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "netjail_start_cleanup!\n"); - if (NULL != ns->cwh) { GNUNET_wait_child_cancel (ns->cwh); @@ -87,20 +91,6 @@ netjail_start_cleanup (void *cls) } -/** - * Trait function of this cmd does nothing. - * - */ -static enum GNUNET_GenericReturnValue -netjail_start_traits (void *cls, - const void **ret, - const char *trait, - unsigned int index) -{ - return GNUNET_NO; -} - - /** * Callback which will be called if the setup script finished. * @@ -112,18 +102,18 @@ child_completed_callback (void *cls, { struct NetJailState *ns = cls; + GNUNET_OS_process_destroy (ns->start_proc); + ns->start_proc = NULL; if (0 == exit_code) { - ns->finished = GNUNET_YES; + GNUNET_TESTING_async_finish (&ns->ac); } else { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Child completed with an error!\n"); - ns->finished = GNUNET_SYSERR; + GNUNET_TESTING_async_fail (&ns->ac); } - GNUNET_OS_process_destroy (ns->start_proc); - ns->start_proc = NULL; } @@ -138,10 +128,12 @@ netjail_start_run (void *cls, struct GNUNET_TESTING_Interpreter *is) { struct NetJailState *ns = cls; - char *const script_argv[] = {NETJAIL_START_SCRIPT, - ns->local_m, - ns->global_n, - NULL}; + char *const script_argv[] = { + NETJAIL_START_SCRIPT, + ns->local_m, + ns->global_n, + NULL + }; unsigned int helper_check = GNUNET_OS_check_helper_binary ( NETJAIL_START_SCRIPT, GNUNET_YES, @@ -176,25 +168,6 @@ netjail_start_run (void *cls, } -/** - * This function checks the flag NetJailState#finished, if this cmd finished. - * - */ -static enum GNUNET_GenericReturnValue -netjail_start_finish (void *cls, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls) -{ - struct NetJailState *ns = cls; - - if (ns->finished) - { - cont (cont_cls); - } - return ns->finished; -} - - /** * Create command. * @@ -218,9 +191,8 @@ GNUNET_TESTING_cmd_netjail_start (const char *label, .cls = ns, .label = label, .run = &netjail_start_run, - .finish = &netjail_start_finish, - .cleanup = &netjail_start_cleanup, - .traits = &netjail_start_traits + .ac = &ns->ac, + .cleanup = &netjail_start_cleanup }; return cmd; diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem.c b/src/testing/testing_api_cmd_netjail_start_testsystem.c index 1222ae54b..4224a5736 100644 --- a/src/testing/testing_api_cmd_netjail_start_testsystem.c +++ b/src/testing/testing_api_cmd_netjail_start_testsystem.c @@ -61,6 +61,11 @@ struct HelperMessage */ struct NetJailState { + /** + * Context for our asynchronous completion. + */ + struct GNUNET_TESTING_AsyncContext ac; + /** * Pointer to the return value of the test. * @@ -399,14 +404,16 @@ start_helper (struct NetJailState *ns, struct struct GNUNET_HELPER_Handle *helper; struct GNUNET_CMDS_HelperInit *msg; struct TestingSystemCount *tbc; - char *const script_argv[] = {NETJAIL_EXEC_SCRIPT, - m_char, - n_char, - GNUNET_OS_get_libexec_binary_path ( - HELPER_CMDS_BINARY), - ns->global_n, - ns->local_m, - NULL}; + char *const script_argv[] = { + NETJAIL_EXEC_SCRIPT, + m_char, + n_char, + GNUNET_OS_get_libexec_binary_path ( + HELPER_CMDS_BINARY), + ns->global_n, + ns->local_m, + NULL + }; unsigned int m = atoi (m_char); unsigned int n = atoi (n_char); unsigned int helper_check = GNUNET_OS_check_helper_binary ( @@ -436,8 +443,9 @@ start_helper (struct NetJailState *ns, struct NETJAIL_EXEC_SCRIPT); *ns->rv = 1; } - - GNUNET_array_append (ns->helper, ns->n_helper, GNUNET_HELPER_start ( + GNUNET_array_append (ns->helper, + ns->n_helper, + GNUNET_HELPER_start ( GNUNET_YES, NETJAIL_EXEC_SCRIPT, script_argv, @@ -508,6 +516,7 @@ netjail_exec_run (void *cls, * In this case a GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED is send to all peers. * 3. Did all peers finished the test case. In this case interpreter_next will be called. * + * => FIXME: must change _completely_. */ static int netjail_start_finish (void *cls, @@ -598,7 +607,7 @@ GNUNET_TESTING_cmd_netjail_start_testing_system (const char *label, .cls = ns, .label = label, .run = &netjail_exec_run, - .finish = &netjail_start_finish, + .ac = &ns->ac, .cleanup = &netjail_exec_cleanup, .traits = &netjail_exec_traits }; diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c b/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c index bb9421aa7..d319b73b4 100644 --- a/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c +++ b/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c @@ -61,6 +61,11 @@ struct HelperMessage */ struct NetJailState { + /** + * Context for our asynchronous completion. + */ + struct GNUNET_TESTING_AsyncContext ac; + /** * The complete topology information. */ @@ -637,6 +642,7 @@ send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns) * 3. Did all peers finished the test case. In this case interpreter_next will be called. * */ +// FIXME: must change completely! static int netjail_start_finish (void *cls, GNUNET_SCHEDULER_TaskCallback cont, @@ -708,7 +714,7 @@ GNUNET_TESTING_cmd_netjail_start_testing_system_v2 (const char *label, .cls = ns, .label = label, .run = &netjail_exec_run, - .finish = &netjail_start_finish, + .ac = &ns->ac, .cleanup = &netjail_exec_cleanup, .traits = &netjail_exec_traits }; diff --git a/src/testing/testing_api_cmd_netjail_start_v2.c b/src/testing/testing_api_cmd_netjail_start_v2.c index faabed98e..69d5e6a45 100644 --- a/src/testing/testing_api_cmd_netjail_start_v2.c +++ b/src/testing/testing_api_cmd_netjail_start_v2.c @@ -35,6 +35,11 @@ */ struct NetJailState { + /** + * Context for our asynchronous completion. + */ + struct GNUNET_TESTING_AsyncContext ac; + // Child Wait handle struct GNUNET_ChildWaitHandle *cwh; @@ -85,20 +90,6 @@ netjail_start_cleanup (void *cls) } -/** - * Trait function of this cmd does nothing. - * - */ -static enum GNUNET_GenericReturnValue -netjail_start_traits (void *cls, - const void **ret, - const char *trait, - unsigned int index) -{ - return GNUNET_NO; -} - - /** * Callback which will be called if the setup script finished. * @@ -110,19 +101,19 @@ child_completed_callback (void *cls, { struct NetJailState *ns = cls; + GNUNET_OS_process_destroy (ns->start_proc); + ns->start_proc = NULL; if (0 == exit_code) { - ns->finished = GNUNET_YES; + GNUNET_TESTING_async_finish (&ns->ac); } else { // FIXME: log status code GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Child completed with an error!\n"); - ns->finished = GNUNET_SYSERR; + GNUNET_TESTING_async_fail (&ns->ac); } - GNUNET_OS_process_destroy (ns->start_proc); - ns->start_proc = NULL; } @@ -192,29 +183,6 @@ netjail_start_run (void *cls, } -/** - * This function checks the flag NetJailState - * - * FIXME: fix comment! - * #finished, if this cmd finished. - * - */ -static enum GNUNET_GenericReturnValue -netjail_start_finish (void *cls, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls) -{ - struct NetJailState *ns = cls; - - if (GNUNET_NO != ns->finished) - { - cont (cont_cls); - } - // FIXME: cont should be called later in the else case! - return ns->finished; -} - - /** * Create command. * @@ -235,9 +203,8 @@ GNUNET_TESTING_cmd_netjail_start_v2 (const char *label, .cls = ns, .label = label, .run = &netjail_start_run, - .finish = &netjail_start_finish, - .cleanup = &netjail_start_cleanup, - .traits = &netjail_start_traits + .ac = &ns->ac, + .cleanup = &netjail_start_cleanup }; return cmd; diff --git a/src/testing/testing_api_cmd_netjail_stop.c b/src/testing/testing_api_cmd_netjail_stop.c index c93e5cca3..8c78b5e93 100644 --- a/src/testing/testing_api_cmd_netjail_stop.c +++ b/src/testing/testing_api_cmd_netjail_stop.c @@ -39,6 +39,11 @@ struct GNUNET_ChildWaitHandle *cwh; */ struct NetJailState { + /** + * Context for our asynchronous completion. + */ + struct GNUNET_TESTING_AsyncContext ac; + // Number of local nodes in each namespace. char *local_m; @@ -50,8 +55,6 @@ struct NetJailState */ struct GNUNET_OS_Process *stop_proc; - // Flag indication if the script finished. - unsigned int finished; }; @@ -108,16 +111,17 @@ child_completed_callback (void *cls, struct NetJailState *ns = cls; cwh = NULL; + GNUNET_OS_process_destroy (ns->stop_proc); + ns->stop_proc = NULL; if (0 == exit_code) { - ns->finished = GNUNET_YES; + GNUNET_TESTING_async_finish (&ns->ac); } else { - ns->finished = GNUNET_SYSERR; + // FIXME: log exit code! + GNUNET_TESTING_async_fail (&ns->ac); } - GNUNET_OS_process_destroy (ns->stop_proc); - ns->stop_proc = NULL; } @@ -174,33 +178,6 @@ netjail_stop_run (void *cls, } -/** - * This function checks the flag NetJailState#finished, if this cmd finished. - * - */ -static enum GNUNET_GenericReturnValue -netjail_stop_finish (void *cls, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls) -{ - struct NetJailState *ns = cls; - - if (ns->finished) - { - cont (cont_cls); - } - return ns->finished; -} - - -/** - * Create command. - * - * @param label name for command. - * @param local_m Number of local nodes in each namespace. - * @param global_n The number of namespaces. - * @return command. - */ struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_netjail_stop (const char *label, char *local_m, @@ -216,7 +193,7 @@ GNUNET_TESTING_cmd_netjail_stop (const char *label, .cls = ns, .label = label, .run = &netjail_stop_run, - .finish = &netjail_stop_finish, + .ac = &ns->ac, .cleanup = &netjail_stop_cleanup, .traits = &netjail_stop_traits }; diff --git a/src/testing/testing_api_cmd_netjail_stop_v2.c b/src/testing/testing_api_cmd_netjail_stop_v2.c index 348e8c9f7..a0e2657cb 100644 --- a/src/testing/testing_api_cmd_netjail_stop_v2.c +++ b/src/testing/testing_api_cmd_netjail_stop_v2.c @@ -39,6 +39,11 @@ static struct GNUNET_ChildWaitHandle *cwh; */ struct NetJailState { + /** + * Context for our asynchronous completion. + */ + struct GNUNET_TESTING_AsyncContext ac; + /** * Configuration file for the test topology. */ @@ -49,8 +54,6 @@ struct NetJailState */ struct GNUNET_OS_Process *stop_proc; - // Flag indication if the script finished. - enum GNUNET_GenericReturnValue finished; }; @@ -81,20 +84,6 @@ netjail_stop_cleanup (void *cls) } -/** - * Trait function of this cmd does nothing. - * - */ -static enum GNUNET_GenericReturnValue -netjail_stop_traits (void *cls, - const void **ret, - const char *trait, - unsigned int index) -{ - return GNUNET_NO; -} - - /** * Callback which will be called if the setup script finished. * @@ -106,17 +95,17 @@ child_completed_callback (void *cls, { struct NetJailState *ns = cls; - cwh = NULL; + cwh = NULL; // WTF? globals!?!?! + GNUNET_OS_process_destroy (ns->stop_proc); + ns->stop_proc = NULL; if (0 == exit_code) { - ns->finished = GNUNET_YES; + GNUNET_TESTING_async_finish (&ns->ac); } else { - ns->finished = GNUNET_SYSERR; + GNUNET_TESTING_async_fail (&ns->ac); } - GNUNET_OS_process_destroy (ns->stop_proc); - ns->stop_proc = NULL; } @@ -132,6 +121,7 @@ netjail_stop_run (void *cls, { struct NetJailState *ns = cls; char *pid; + GNUNET_asprintf (&pid, "%u", getpid ()); @@ -170,36 +160,9 @@ netjail_stop_run (void *cls, &child_completed_callback, ns); GNUNET_break (NULL != cwh); - } -/** - * This function checks the flag NetJailState#finished, if this cmd finished. - * - */ -static enum GNUNET_GenericReturnValue -netjail_stop_finish (void *cls, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls) -{ - struct NetJailState *ns = cls; - - if (ns->finished) - { - cont (cont_cls); - } - return ns->finished; -} - - -/** - * Create command. - * - * @param label name for command. - * @param topology_config Configuration file for the test topology. - * @return command. - */ struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_netjail_stop_v2 (const char *label, char *topology_config) @@ -213,9 +176,8 @@ GNUNET_TESTING_cmd_netjail_stop_v2 (const char *label, .cls = ns, .label = label, .run = &netjail_stop_run, - .finish = &netjail_stop_finish, - .cleanup = &netjail_stop_cleanup, - .traits = &netjail_stop_traits + .ac = &ns->ac, + .cleanup = &netjail_stop_cleanup }; return cmd; diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c index b21e01fcc..e0cb3fcda 100644 --- a/src/testing/testing_api_loop.c +++ b/src/testing/testing_api_loop.c @@ -46,7 +46,7 @@ struct GNUNET_TESTING_Interpreter * Closure for @e rc. */ void *rc_cls; - + /** * Commands the interpreter will run. */ @@ -294,7 +294,7 @@ interpreter_run (void *cls) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running command END\n"); is->result = GNUNET_OK; - GNUNET_SCHEDULER_shutdown (); + finish_test (is); return; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -304,17 +304,19 @@ interpreter_run (void *cls) = cmd->last_req_time = GNUNET_TIME_absolute_get (); cmd->num_tries = 1; - cmd->run (cmd->cls, - is); - if ( (NULL != cmd->finish) && - (! cmd->asynchronous_finish) ) + if (NULL != cmd->ac) { - cmd->finish (cmd->cls, - &interpreter_next, - is); + cmd->ac->is = is; + cmd->ac->cont = &interpreter_next; + cmd->ac->cont_cls = is; + cmd->ac->finished = GNUNET_NO; } - else + cmd->run (cmd->cls, + is); + if ( (cmd->asynchronous_finish) && + (NULL != cmd->ac->cont) ) { + cmd->ac->cont = NULL; interpreter_next (is); } } @@ -380,12 +382,12 @@ struct MainParams /** * Global timeout for the test. - */ + */ struct GNUNET_TIME_Relative timeout; /** * Set to #EXIT_FAILURE on error. - */ + */ int rv; }; @@ -444,4 +446,31 @@ GNUNET_TESTING_main (struct GNUNET_TESTING_Command *commands, } +void +GNUNET_TESTING_async_fail (struct GNUNET_TESTING_AsyncContext *ac) +{ + GNUNET_assert (GNUNET_NO == ac->finished); + ac->finished = GNUNET_SYSERR; + GNUNET_TESTING_interpreter_fail (ac->is); + if (NULL != ac->cont) + { + ac->cont (ac->cont_cls); + ac->cont = NULL; + } +} + + +void +GNUNET_TESTING_async_finish (struct GNUNET_TESTING_AsyncContext *ac) +{ + GNUNET_assert (GNUNET_NO == ac->finished); + ac->finished = GNUNET_OK; + if (NULL != ac->cont) + { + ac->cont (ac->cont_cls); + ac->cont = NULL; + } +} + + /* end of testing_api_loop.c */ diff --git a/src/transport/transport_api_cmd_connecting_peers.c b/src/transport/transport_api_cmd_connecting_peers.c index ddf1c3872..82194ff15 100644 --- a/src/transport/transport_api_cmd_connecting_peers.c +++ b/src/transport/transport_api_cmd_connecting_peers.c @@ -42,6 +42,11 @@ */ struct ConnectPeersState { + /** + * Context for our asynchronous completion. + */ + struct GNUNET_TESTING_AsyncContext ac; + // Label of the cmd which started the test system. const char *create_label; @@ -183,6 +188,7 @@ connect_peers_run (void *cls, * The finish function of this cmd will check if the peer we are trying to connect to is in the connected peers map of the start peer cmd for this peer. * */ +// FIXME: this needs a complete rewrite! static int connect_peers_finish (void *cls, GNUNET_SCHEDULER_TaskCallback cont, @@ -221,20 +227,6 @@ connect_peers_finish (void *cls, } -/** - * Trait function of this cmd does nothing. - * - */ -static int -connect_peers_traits (void *cls, - const void **ret, - const char *trait, - unsigned int index) -{ - return GNUNET_OK; -} - - /** * The cleanup function of this cmd frees resources the cmd allocated. * @@ -249,13 +241,6 @@ connect_peers_cleanup (void *cls) } -/** - * Create command. - * - * @param label name for command. - * @param start_peer_label Label of the cmd to start a peer. - * @return command. - */ struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_connect_peers (const char *label, const char *start_peer_label, @@ -269,15 +254,15 @@ GNUNET_TRANSPORT_cmd_connect_peers (const char *label, cps->num = num; cps->create_label = create_label; - - struct GNUNET_TESTING_Command cmd = { - .cls = cps, - .label = label, - .run = &connect_peers_run, - .finish = &connect_peers_finish, - .cleanup = &connect_peers_cleanup, - .traits = &connect_peers_traits - }; - - return cmd; + { + struct GNUNET_TESTING_Command cmd = { + .cls = cps, + .label = label, + .run = &connect_peers_run, + .ac = &cps->ac, + .cleanup = &connect_peers_cleanup + }; + + return cmd; + } } diff --git a/src/transport/transport_api_cmd_connecting_peers_v2.c b/src/transport/transport_api_cmd_connecting_peers_v2.c index 8ef556946..8d0f74916 100644 --- a/src/transport/transport_api_cmd_connecting_peers_v2.c +++ b/src/transport/transport_api_cmd_connecting_peers_v2.c @@ -44,6 +44,11 @@ */ struct ConnectPeersState { + /** + * Context for our asynchronous completion. + */ + struct GNUNET_TESTING_AsyncContext ac; + // Label of the cmd which started the test system. const char *create_label; @@ -184,20 +189,6 @@ connect_peers_finish (void *cls, } -/** - * Trait function of this cmd does nothing. - * - */ -static int -connect_peers_traits (void *cls, - const void **ret, - const char *trait, - unsigned int index) -{ - return GNUNET_OK; -} - - /** * The cleanup function of this cmd frees resources the cmd allocated. * @@ -237,9 +228,8 @@ GNUNET_TRANSPORT_cmd_connect_peers_v2 (const char *label, .cls = cps, .label = label, .run = &connect_peers_run, - .finish = &connect_peers_finish, - .cleanup = &connect_peers_cleanup, - .traits = &connect_peers_traits + .ac = &cps->ac, + .cleanup = &connect_peers_cleanup }; return cmd; diff --git a/src/transport/transport_api_cmd_connecting_peers_v3.c b/src/transport/transport_api_cmd_connecting_peers_v3.c index a73d81064..ae32a087a 100644 --- a/src/transport/transport_api_cmd_connecting_peers_v3.c +++ b/src/transport/transport_api_cmd_connecting_peers_v3.c @@ -58,6 +58,11 @@ */ struct ConnectPeersState { + /** + * Context for our asynchronous completion. + */ + struct GNUNET_TESTING_AsyncContext ac; + /** * The testing system of this node. */ @@ -447,20 +452,6 @@ connect_peers_finish (void *cls, } -/** - * Trait function of this cmd does nothing. - * - */ -static int -connect_peers_traits (void *cls, - const void **ret, - const char *trait, - unsigned int index) -{ - return GNUNET_OK; -} - - /** * The cleanup function of this cmd frees resources the cmd allocated. * @@ -475,13 +466,6 @@ connect_peers_cleanup (void *cls) } -/** - * Create command. - * - * @param label name for command. - * @param start_peer_label Label of the cmd to start a peer. - * @return command. - */ struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_connect_peers_v3 (const char *label, const char *start_peer_label, @@ -498,15 +482,15 @@ GNUNET_TRANSPORT_cmd_connect_peers_v3 (const char *label, cps->create_label = create_label; cps->topology = topology; - - struct GNUNET_TESTING_Command cmd = { - .cls = cps, - .label = label, - .run = &connect_peers_run, - .finish = &connect_peers_finish, - .cleanup = &connect_peers_cleanup, - .traits = &connect_peers_traits - }; - - return cmd; + { + struct GNUNET_TESTING_Command cmd = { + .cls = cps, + .label = label, + .run = &connect_peers_run, + .ac = &cps->ac, + .cleanup = &connect_peers_cleanup + }; + + return cmd; + } } diff --git a/src/transport/transport_api_cmd_start_peer.c b/src/transport/transport_api_cmd_start_peer.c index 8a53ed22c..44fc68807 100644 --- a/src/transport/transport_api_cmd_start_peer.c +++ b/src/transport/transport_api_cmd_start_peer.c @@ -51,6 +51,7 @@ hello_iter_cb (void *cb_cls, const char *emsg) { struct StartPeerState *sps = cb_cls; + if (NULL == record) { sps->pic = NULL; @@ -89,26 +90,6 @@ retrieve_hello (void *cls) } -/** - * This function checks StartPeerState#finished, which is set when the hello was retrieved. - * - */ -static int -start_peer_finish (void *cls, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls) -{ - struct StartPeerState *sps = cls; - - if (GNUNET_YES == sps->finished) - { - cont (cont_cls); - } - - return sps->finished; -} - - /** * Disconnect callback for the connection to the core service. * @@ -597,14 +578,15 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label, i * sizeof(struct GNUNET_MQ_MessageHandler)); } - struct GNUNET_TESTING_Command cmd = { - .cls = sps, - .label = label, - .run = &start_peer_run, - .finish = &start_peer_finish, - .cleanup = &start_peer_cleanup, - .traits = &start_peer_traits - }; - - return cmd; + { + struct GNUNET_TESTING_Command cmd = { + .cls = sps, + .label = label, + .run = &start_peer_run, + .cleanup = &start_peer_cleanup, + .traits = &start_peer_traits + }; + + return cmd; + } } diff --git a/src/transport/transport_api_cmd_start_peer_v2.c b/src/transport/transport_api_cmd_start_peer_v2.c index 2ab58574a..94799eddd 100644 --- a/src/transport/transport_api_cmd_start_peer_v2.c +++ b/src/transport/transport_api_cmd_start_peer_v2.c @@ -597,7 +597,6 @@ GNUNET_TRANSPORT_cmd_start_peer_v2 (const char *label, .cls = sps, .label = label, .run = &start_peer_run, - .finish = &start_peer_finish, .cleanup = &start_peer_cleanup, .traits = &start_peer_traits }; diff --git a/src/transport/transport_api_cmd_start_peer_v3.c b/src/transport/transport_api_cmd_start_peer_v3.c index fa6300ef5..1a19ce60e 100644 --- a/src/transport/transport_api_cmd_start_peer_v3.c +++ b/src/transport/transport_api_cmd_start_peer_v3.c @@ -609,7 +609,6 @@ GNUNET_TRANSPORT_cmd_start_peer_v3 (const char *label, .cls = sps, .label = label, .run = &start_peer_run, - .finish = &start_peer_finish, .cleanup = &start_peer_cleanup, .traits = &start_peer_traits }; -- cgit v1.2.3 From 0506cc074484d48d38dcca9972010f981eb58727 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 8 Oct 2021 21:50:57 +0200 Subject: -dce --- src/testing/testing_api_cmd_netjail_start.c | 6 +----- src/testing/testing_api_cmd_netjail_start_v2.c | 3 --- 2 files changed, 1 insertion(+), 8 deletions(-) (limited to 'src') diff --git a/src/testing/testing_api_cmd_netjail_start.c b/src/testing/testing_api_cmd_netjail_start.c index 4b5592524..9cd84cb4f 100644 --- a/src/testing/testing_api_cmd_netjail_start.c +++ b/src/testing/testing_api_cmd_netjail_start.c @@ -53,11 +53,6 @@ struct NetJailState * The process id of the start script. */ struct GNUNET_OS_Process *start_proc; - - /** - * Flag indication if the script finished. - */ - enum GNUNET_GenericReturnValue finished; }; @@ -110,6 +105,7 @@ child_completed_callback (void *cls, } else { + // FIXME: log status code GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Child completed with an error!\n"); GNUNET_TESTING_async_fail (&ns->ac); diff --git a/src/testing/testing_api_cmd_netjail_start_v2.c b/src/testing/testing_api_cmd_netjail_start_v2.c index 69d5e6a45..7567c2981 100644 --- a/src/testing/testing_api_cmd_netjail_start_v2.c +++ b/src/testing/testing_api_cmd_netjail_start_v2.c @@ -53,9 +53,6 @@ struct NetJailState */ struct GNUNET_OS_Process *start_proc; - // Flag indication if the script finished. - // FIXME: document 3 values - enum GNUNET_GenericReturnValue finished; }; -- cgit v1.2.3 From 03ec948c7615cf364a095a609eac61a109b630ce Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Sun, 10 Oct 2021 18:09:22 +0200 Subject: -make check/dist ftbfs fix. needs file --- src/testing/Makefile.am | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am index 386fcd041..2145858c4 100644 --- a/src/testing/Makefile.am +++ b/src/testing/Makefile.am @@ -97,7 +97,6 @@ list_keys_LDADD = \ check_PROGRAMS = \ - test_testing_topology \ test_testing_api_cmd_netjail \ test_testing_hello_world \ test_testing_portreservation \ @@ -109,7 +108,6 @@ check_PROGRAMS = \ if ENABLE_TEST_RUN AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; TESTS = \ - test_testing_topology \ test_testing_api_cmd_netjail \ test_testing_hello_world \ test_testing_portreservation \ @@ -118,11 +116,11 @@ TESTS = \ test_testing_servicestartup endif -test_testing_topology_SOURCES = \ - test_testing_topology.c -test_testing_topology_LDADD = \ - libgnunettesting.la \ - $(top_builddir)/src/util/libgnunetutil.la +#test_testing_topology_SOURCES = \ +# test_testing_topology.c +#test_testing_topology_LDADD = \ +# libgnunettesting.la \ +# $(top_builddir)/src/util/libgnunetutil.la test_testing_api_cmd_netjail_SOURCES = \ test_testing_api_cmd_netjail.c -- cgit v1.2.3 From 7ee114251b2a512153011e5475c7a15ca0b73eb3 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 10 Oct 2021 20:05:52 +0200 Subject: -add testing.h to make dist --- src/testing/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am index 2145858c4..e9389a876 100644 --- a/src/testing/Makefile.am +++ b/src/testing/Makefile.am @@ -58,7 +58,7 @@ libgnunettesting_la_SOURCES = \ testing_api_cmd_netjail_stop_testsystem_v2.c \ testing_api_cmd_netjail_stop.c \ testing_api_cmd_netjail_stop_v2.c \ - testing.c \ + testing.c testing.h \ testing_api_cmd_system_create.c \ testing_api_cmd_system_destroy.c \ testing_api_cmd_batch.c \ -- cgit v1.2.3 From 62ca5edd03630e388d7c4bb0c93e5952d55e5b11 Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Mon, 11 Oct 2021 16:30:12 +0200 Subject: BUILD: Remove SuperMUC code. Issue #7033 --- configure.ac | 14 -- po/POTFILES.in | 1 - src/include/gnunet_testbed_service.h | 18 -- src/testbed/gnunet-testbed-profiler.c | 4 - src/testbed/gnunet_testbed_mpi_spawn.c | 327 --------------------------------- src/testbed/testbed_api_hosts.c | 35 ---- src/testbed/testbed_api_testbed.c | 11 -- 7 files changed, 410 deletions(-) delete mode 100644 src/testbed/gnunet_testbed_mpi_spawn.c (limited to 'src') diff --git a/configure.ac b/configure.ac index fec1069fc..6936e7067 100644 --- a/configure.ac +++ b/configure.ac @@ -1686,20 +1686,6 @@ AC_DEFINE_UNQUOTED([HAVE_GNUTLS_DANE], $gnutls_dane, [We have GnuTLS with DANE s -# Test if we are building for superMUC -AC_MSG_CHECKING(if GNUnet is being configured to run on the SuperMUC) -AC_ARG_ENABLE([supermuc], - [AS_HELP_STRING([--enable-supermuc], - [build GNUnet with support to run on the SuperMUC (default is NO)])], - [AS_IF([test "x$enable_supermuc" = "xno"], - [supermuc=0], - [supermuc=1])], - [supermuc=0 - enable_supermuc=no]) -AC_MSG_RESULT($enable_SUPERMUC) -AM_CONDITIONAL([ENABLE_SUPERMUC], [test "x$supermuc" = "x1"]) -AC_DEFINE_UNQUOTED([ENABLE_SUPERMUC], [$supermuc], [Build with support for SuperMUC]) - # Check if NSE has to send timestamp information to testbed logger for # generating histogram of messages received AC_MSG_CHECKING(if NSE has to send timestamp information to testbed logger) diff --git a/po/POTFILES.in b/po/POTFILES.in index 232416684..e34cb25f4 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -406,7 +406,6 @@ src/testbed/gnunet-service-testbed_oc.c src/testbed/gnunet-service-testbed_peers.c src/testbed/gnunet-testbed-profiler.c src/testbed/gnunet_mpi_test.c -src/testbed/gnunet_testbed_mpi_spawn.c src/testbed/testbed_api.c src/testbed/testbed_api_barriers.c src/testbed/testbed_api_hosts.c diff --git a/src/include/gnunet_testbed_service.h b/src/include/gnunet_testbed_service.h index acb444de4..888c6e391 100644 --- a/src/include/gnunet_testbed_service.h +++ b/src/include/gnunet_testbed_service.h @@ -138,24 +138,6 @@ GNUNET_TESTBED_hosts_load_from_file (const char *filename, struct GNUNET_TESTBED_Host ***hosts); -/** - * Loads the set of host allocated by the LoadLeveler Job Scheduler. This - * function is only available when compiled with support for LoadLeveler and is - * used for running on the SuperMUC - * - * @param cfg the configuration to use as a template while starting a controller - * on any of the loaded hosts. Operation queue sizes specific to a host - * are also read from this configuration handle - * @param hosts set to the hosts found in the file; caller must free this if - * number of hosts returned is greater than 0 - * @return number of hosts returned in 'hosts', 0 on error - */ -unsigned int -GNUNET_TESTBED_hosts_load_from_loadleveler (const struct - GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTBED_Host - ***hosts); - /** * Destroy a host handle. Must only be called once everything * running on that host has been stopped. diff --git a/src/testbed/gnunet-testbed-profiler.c b/src/testbed/gnunet-testbed-profiler.c index b07c725a3..49d975119 100644 --- a/src/testbed/gnunet-testbed-profiler.c +++ b/src/testbed/gnunet-testbed-profiler.c @@ -227,11 +227,9 @@ test_run (void *cls, abort_task = NULL; return; } -#if (! ENABLE_SUPERMUC) fprintf (stdout, "Testbed running, waiting for keystroke to shut down\n"); fflush (stdout); (void) getc (stdin); -#endif fprintf (stdout, "Shutting down. Please wait\n"); fflush (stdout); GNUNET_SCHEDULER_shutdown (); @@ -297,14 +295,12 @@ main (int argc, char *const *argv) "keystroke but continues to run until a termination " "signal is received"), &noninteractive), -#if ! ENABLE_SUPERMUC GNUNET_GETOPT_option_string ('H', "hosts", "FILENAME", gettext_noop ( "name of the file with the login information for the testbed"), &hosts_file), -#endif GNUNET_GETOPT_OPTION_END }; const char *binaryHelp = "gnunet-testbed-profiler [OPTIONS]"; diff --git a/src/testbed/gnunet_testbed_mpi_spawn.c b/src/testbed/gnunet_testbed_mpi_spawn.c deleted file mode 100644 index 577ffbeba..000000000 --- a/src/testbed/gnunet_testbed_mpi_spawn.c +++ /dev/null @@ -1,327 +0,0 @@ -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_testbed_service.h" - - -/** - * Generic logging shorthand - */ -#define LOG(kind, ...) \ - GNUNET_log (kind, __VA_ARGS__) - -/** - * Debug logging shorthand - */ -#define LOG_DEBUG(...) \ - LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) - -/** - * Global result - */ -static int ret; - -/** - * The child process we spawn - */ -static struct GNUNET_OS_Process *child; - -/** - * The arguments including the binary to spawn - */ -static char **argv2; - -/** - * Pipe used to communicate shutdown via signal. - */ -static struct GNUNET_DISK_PipeHandle *sigpipe; - -/** - * Filename of the unique file - */ -static char *fn; - -/** - * Handle to the unique file - */ -static int fh; - -/** - * The return code of the binary - */ -static unsigned long child_exit_code; - -/** - * The process status of the child - */ -static enum GNUNET_OS_ProcessStatusType child_status; - -/** - * Task to kill the child - */ -static struct GNUNET_SCHEDULER_Task *terminate_task_id; - -/** - * Task to kill the child - */ -static struct GNUNET_SCHEDULER_Task *child_death_task_id; - -/** - * The shutdown task - */ -static void -shutdown_task (void *cls) -{ - if (0 != child_exit_code) - { - LOG (GNUNET_ERROR_TYPE_WARNING, "Child exited with error code: %lu\n", - child_exit_code); - ret = 128 + (int) child_exit_code; - } - if (0 != fh) - { - close (fh); - } - if ((NULL != fn) && (0 != unlink (fn))) - { - GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "open"); - ret = GNUNET_SYSERR; - } -} - - -static void -terminate_task (void *cls) -{ - static int hard_kill; - - GNUNET_assert (NULL != child); - terminate_task_id = - GNUNET_SCHEDULER_add_shutdown (&terminate_task, NULL); - if (0 != hard_kill) - { - switch (hard_kill) - { - case 1: - case 2: - LOG (GNUNET_ERROR_TYPE_WARNING, - "%d more interrupts needed to send SIGKILL to the child\n", - 3 - hard_kill); - hard_kill++; - return; - - case 3: - GNUNET_break (0 == GNUNET_OS_process_kill (child, SIGKILL)); - return; - } - } - hard_kill++; - GNUNET_break (0 == GNUNET_OS_process_kill (child, GNUNET_TERM_SIG)); - LOG (GNUNET_ERROR_TYPE_INFO, _ ("Waiting for child to exit.\n")); -} - - -/** - * Task triggered whenever we receive a SIGCHLD (child - * process died). - * - * @param cls closure, NULL if we need to self-restart - */ -static void -child_death_task (void *cls) -{ - const struct GNUNET_DISK_FileHandle *pr; - char c[16]; - const struct GNUNET_SCHEDULER_TaskContext *tc; - - - pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ); - child_death_task_id = NULL; - tc = GNUNET_SCHEDULER_get_task_context (); - if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) - { - child_death_task_id = - GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, - pr, &child_death_task, NULL); - return; - } - /* consume the signal */ - GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof(c))); - LOG_DEBUG ("Child died\n"); - GNUNET_SCHEDULER_cancel (terminate_task_id); - terminate_task_id = NULL; - GNUNET_assert (GNUNET_OK == GNUNET_OS_process_status (child, &child_status, - &child_exit_code)); - GNUNET_OS_process_destroy (child); - child = NULL; - GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); -} - - -static void -destroy_hosts (struct GNUNET_TESTBED_Host **hosts, unsigned int nhosts) -{ - unsigned int host; - - GNUNET_assert (NULL != hosts); - for (host = 0; host < nhosts; host++) - if (NULL != hosts[host]) - GNUNET_TESTBED_host_destroy (hosts[host]); - GNUNET_free (hosts); - hosts = NULL; -} - - -/** - * The main scheduler run task - * - * @param cls NULL - */ -static void -run (void *cls) -{ - struct GNUNET_TESTBED_Host **hosts; - const struct GNUNET_CONFIGURATION_Handle *null_cfg; - char *tmpdir; - char *hostname; - size_t hostname_len; - unsigned int nhosts; - - null_cfg = GNUNET_CONFIGURATION_create (); - nhosts = GNUNET_TESTBED_hosts_load_from_loadleveler (null_cfg, &hosts); - if (0 == nhosts) - { - GNUNET_break (0); - ret = GNUNET_SYSERR; - return; - } - hostname_len = GNUNET_OS_get_hostname_max_length (); - hostname = GNUNET_malloc (hostname_len); - if (0 != gethostname (hostname, hostname_len)) - { - LOG (GNUNET_ERROR_TYPE_ERROR, "Cannot get hostname. Exiting\n"); - GNUNET_free (hostname); - destroy_hosts (hosts, nhosts); - ret = GNUNET_SYSERR; - return; - } - if (NULL == strstr (GNUNET_TESTBED_host_get_hostname (hosts[0]), hostname)) - { - LOG_DEBUG ("Exiting as `%s' is not the lowest host\n", hostname); - GNUNET_free (hostname); - ret = GNUNET_OK; - return; - } - LOG_DEBUG ("Will be executing `%s' on host `%s'\n", argv2[0], hostname); - GNUNET_free (hostname); - destroy_hosts (hosts, nhosts); - tmpdir = getenv ("TMPDIR"); - if (NULL == tmpdir) - tmpdir = getenv ("TMP"); - if (NULL == tmpdir) - tmpdir = getenv ("TEMP"); - if (NULL == tmpdir) - tmpdir = "/tmp"; - (void) GNUNET_asprintf (&fn, "%s/gnunet-testbed-spawn.lock", tmpdir); - /* Open the unique file; we can create it then we can spawn the child process - else we exit */ - fh = open (fn, O_CREAT | O_EXCL | O_CLOEXEC, - S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); - if (-1 == fh) - { - if (EEXIST == errno) - { - LOG_DEBUG ("Lock file already created by other process. Exiting\n"); - ret = GNUNET_OK; - return; - } - GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "open"); - ret = GNUNET_SYSERR; - return; - } - /* Spawn the new process here */ - LOG (GNUNET_ERROR_TYPE_INFO, _ ("Spawning process `%s'\n"), argv2[0]); - child = GNUNET_OS_start_process_vap (GNUNET_NO, GNUNET_OS_INHERIT_STD_ALL, - NULL, - NULL, NULL, - argv2[0], argv2); - if (NULL == child) - { - GNUNET_break (0); - ret = GNUNET_SYSERR; - GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); - return; - } - ret = GNUNET_OK; - terminate_task_id = - GNUNET_SCHEDULER_add_shutdown (&terminate_task, NULL); - child_death_task_id = - GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, - GNUNET_DISK_pipe_handle (sigpipe, - GNUNET_DISK_PIPE_END_READ), - &child_death_task, NULL); -} - - -/** - * Signal handler called for SIGCHLD. - */ -static void -sighandler_child_death () -{ - static char c; - int old_errno = errno; /* back-up errno */ - - GNUNET_break (1 == - GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle - (sigpipe, GNUNET_DISK_PIPE_END_WRITE), - &c, sizeof(c))); - errno = old_errno; /* restore errno */ -} - - -/** - * Execution start point - */ -int -main (int argc, char *argv[]) -{ - struct GNUNET_SIGNAL_Context *shc_chld; - unsigned int cnt; - - ret = -1; - if (argc < 2) - { - printf ("Need arguments: gnunet-testbed-mpi-spawn "); - return 1; - } - if (GNUNET_OK != GNUNET_log_setup ("gnunet-testbed-spawn", NULL, NULL)) - { - GNUNET_break (0); - return 1; - } - if (NULL == (sigpipe = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE))) - { - GNUNET_break (0); - ret = GNUNET_SYSERR; - return 1; - } - shc_chld = - GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); - if (NULL == shc_chld) - { - LOG (GNUNET_ERROR_TYPE_ERROR, "Cannot install a signal handler\n"); - return 1; - } - argv2 = GNUNET_malloc (sizeof(char *) * argc); - for (cnt = 1; cnt < argc; cnt++) - argv2[cnt - 1] = argv[cnt]; - GNUNET_SCHEDULER_run (run, NULL); - GNUNET_free (argv2); - GNUNET_SIGNAL_handler_uninstall (shc_chld); - shc_chld = NULL; - GNUNET_DISK_pipe_close (sigpipe); - GNUNET_free (fn); - if (GNUNET_OK != ret) - return ret; - return 0; -} diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c index 1a8d9976d..8dd0a4893 100644 --- a/src/testbed/testbed_api_hosts.c +++ b/src/testbed/testbed_api_hosts.c @@ -567,41 +567,6 @@ simple_resolve (const char *host) } -/** - * Loads the set of host allocated by the LoadLeveler Job Scheduler. This - * function is only available when compiled with support for LoadLeveler and is - * used for running on the SuperMUC - * - * @param cfg the configuration to use as a template while starting a controller - * on any of the loaded hosts. Operation queue sizes specific to a host - * are also read from this configuration handle - * @param hosts set to the hosts found in the file; caller must free this if - * number of hosts returned is greater than 0 - * @return number of hosts returned in 'hosts', 0 on error - */ -unsigned int -GNUNET_TESTBED_hosts_load_from_loadleveler ( - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTBED_Host ***hosts) -{ -#if ! ENABLE_SUPERMUC - LOG (GNUNET_ERROR_TYPE_ERROR, - _ ("The function %s is only available when compiled with (--with-ll)\n"), - __func__); - GNUNET_assert (0); -#else - const char *hostfile; - - if (NULL == (hostfile = getenv ("MP_SAVEHOSTFILE"))) - { - GNUNET_break (0); - return 0; - } - return GNUNET_TESTBED_hosts_load_from_file (hostfile, cfg, hosts); -#endif -} - - /** * Destroy a host handle. Must only be called once everything * running on that host has been stopped. diff --git a/src/testbed/testbed_api_testbed.c b/src/testbed/testbed_api_testbed.c index e9b9979ce..e0b76ad78 100644 --- a/src/testbed/testbed_api_testbed.c +++ b/src/testbed/testbed_api_testbed.c @@ -1265,16 +1265,6 @@ GNUNET_TESTBED_run (const char *host_filename, GNUNET_assert (num_peers > 0); rc = GNUNET_new (struct GNUNET_TESTBED_RunHandle); rc->cfg = GNUNET_CONFIGURATION_dup (cfg); -#if ENABLE_SUPERMUC - rc->num_hosts = GNUNET_TESTBED_hosts_load_from_loadleveler (rc->cfg, - &rc->hosts); - if (0 == rc->num_hosts) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - _ ("No hosts loaded from LoadLeveler. Need at least one host\n")); - goto error_cleanup; - } -#else if (NULL != host_filename) { rc->num_hosts = @@ -1289,7 +1279,6 @@ GNUNET_TESTBED_run (const char *host_filename, } else rc->h = GNUNET_TESTBED_host_create (NULL, NULL, rc->cfg, 0); -#endif rc->num_peers = num_peers; rc->event_mask = event_mask; rc->cc = cc; -- cgit v1.2.3 From 65554324abf7e83e3f0f51c3b059e621934afb9d Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Mon, 11 Oct 2021 23:28:17 +0200 Subject: BUILD: Remove W32 ifdef --- src/util/common_allocation.c | 40 ---------------------------------------- 1 file changed, 40 deletions(-) (limited to 'src') diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c index 308488131..f48f87167 100644 --- a/src/util/common_allocation.c +++ b/src/util/common_allocation.c @@ -42,13 +42,6 @@ #define INT_MAX 0x7FFFFFFF #endif -#if 0 -#define W32_MEM_LIMIT 200000000 -#endif - -#ifdef W32_MEM_LIMIT -static LONG mem_used = 0; -#endif /** * Allocate memory. Checks the return value, aborts if no more @@ -184,11 +177,6 @@ GNUNET_xmemdup_ (const void *buf, /* As a security precaution, we generally do not allow very large * allocations here */ GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, filename, linenumber); -#ifdef W32_MEM_LIMIT - size += sizeof(size_t); - if (mem_used + size > W32_MEM_LIMIT) - return NULL; -#endif GNUNET_assert_at (size < INT_MAX, filename, linenumber); ret = malloc (size); if (ret == NULL) @@ -196,11 +184,6 @@ GNUNET_xmemdup_ (const void *buf, LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "malloc"); GNUNET_assert (0); } -#ifdef W32_MEM_LIMIT - *((size_t *) ret) = size; - ret = &((size_t *) ret)[1]; - mem_used += size; -#endif GNUNET_memcpy (ret, buf, size); return ret; } @@ -222,23 +205,12 @@ GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber) (void) filename; (void) linenumber; -#ifdef W32_MEM_LIMIT - size += sizeof(size_t); - if (mem_used + size > W32_MEM_LIMIT) - return NULL; -#endif result = malloc (size); if (NULL == result) return NULL; memset (result, 0, size); -#ifdef W32_MEM_LIMIT - *((size_t *) result) = size; - result = &((size_t *) result)[1]; - mem_used += size; -#endif - return result; } @@ -260,11 +232,6 @@ GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber) (void) filename; (void) linenumber; -#ifdef W32_MEM_LIMIT - n += sizeof(size_t); - ptr = &((size_t *) ptr)[-1]; - mem_used = mem_used - *((size_t *) ptr) + n; -#endif #if defined(M_SIZE) #if ENABLE_POISONING { @@ -295,9 +262,6 @@ GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber) LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "realloc"); GNUNET_assert (0); } -#ifdef W32_MEM_LIMIT - ptr = &((size_t *) ptr)[1]; -#endif return ptr; } @@ -333,10 +297,6 @@ GNUNET_xfree_ (void *ptr, { if (NULL == ptr) return; -#ifdef W32_MEM_LIMIT - ptr = &((size_t *) ptr)[-1]; - mem_used -= *((size_t *) ptr); -#endif #if defined(M_SIZE) #if ENABLE_POISONING { -- cgit v1.2.3 From 4e7e81f4d1305df169d3f7623948a142aa47936b Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Mon, 11 Oct 2021 23:43:04 +0200 Subject: BUILD: Remove --disable-testing. Issue #7033 --- configure.ac | 9 --------- src/Makefile.am | 6 ++---- src/ats/Makefile.am | 2 -- src/cadet/Makefile.am | 4 ---- src/consensus/Makefile.am | 2 -- src/core/Makefile.am | 6 ++---- src/datacache/Makefile.am | 2 -- src/datastore/Makefile.am | 6 ------ src/dht/Makefile.am | 6 ------ src/fs/Makefile.am | 6 ------ src/identity/Makefile.am | 2 -- src/namecache/Makefile.am | 8 -------- src/namestore/Makefile.am | 6 ------ src/nse/Makefile.am | 4 ---- src/peerinfo/Makefile.am | 2 -- src/peerstore/Makefile.am | 2 -- src/pt/Makefile.am | 4 ---- src/regex/Makefile.am | 2 -- src/rps/Makefile.am | 4 ---- src/secretsharing/Makefile.am | 2 -- src/set/Makefile.am | 4 ---- src/seti/Makefile.am | 4 ---- src/setu/Makefile.am | 4 ---- src/topology/Makefile.am | 2 -- src/transport/Makefile.am | 4 ---- src/util/Makefile.am | 6 ++---- 26 files changed, 6 insertions(+), 103 deletions(-) (limited to 'src') diff --git a/configure.ac b/configure.ac index a3e206301..5e9e3d275 100644 --- a/configure.ac +++ b/configure.ac @@ -1746,15 +1746,6 @@ AC_ARG_ENABLE([benchmarks], AC_MSG_RESULT($enable_benchmarks) AM_CONDITIONAL([HAVE_BENCHMARKS], [test "x$enable_benchmarks" = "xyes"]) -# should gnunet-testing be compiled -AC_MSG_CHECKING(whether to compile gnunet-testing) -AC_ARG_ENABLE([testing], - [AS_HELP_STRING([--disable-testing], [do not build gnunet-testing])], - [enable_testing=${enableval}], - [enable_testing=yes]) -AC_MSG_RESULT($enable_testing) -AM_CONDITIONAL([HAVE_TESTING], [test "x$enable_testing" = "xyes"]) - # should experimental code be compiled (code that may not yet compile)? AC_MSG_CHECKING(whether to compile experimental code) AC_ARG_ENABLE([experimental], diff --git a/src/Makefile.am b/src/Makefile.am index ef8c5b110..31215c6d0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,9 +1,7 @@ # This Makefile.am is in the public domain -if HAVE_TESTING - TESTING = testing - TESTBED = testbed-logger testbed -endif +TESTING = testing +TESTBED = testbed-logger testbed if HAVE_EXPERIMENTAL EXP_DIR = \ diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am index 0b8e7309a..85a2bb555 100644 --- a/src/ats/Makefile.am +++ b/src/ats/Makefile.am @@ -65,11 +65,9 @@ gnunet_service_ats_LDADD = \ libgnunetats.la \ $(GN_LIBINTL) -if HAVE_TESTING TESTING_TESTS = \ test_ats_api_proportional \ test_ats_reservation_api_proportional -endif check_PROGRAMS = \ $(TESTING_TESTS) diff --git a/src/cadet/Makefile.am b/src/cadet/Makefile.am index 2289a2d96..d942c6495 100644 --- a/src/cadet/Makefile.am +++ b/src/cadet/Makefile.am @@ -78,12 +78,9 @@ if LINUX endif -if HAVE_TESTING noinst_LTLIBRARIES = libgnunetcadettest.la $(noinst_LIB_EXP) # noinst_PROGRAMS = gnunet-cadet-profiler -endif -if HAVE_TESTING check_PROGRAMS = \ test_cadet_local_mq \ test_cadet_2_forward \ @@ -106,7 +103,6 @@ check_PROGRAMS = \ test_cadet_5_speed_reliable_backwards \ test_cadet_5_speed_backwards \ test_cadet_5_reopen -endif #gnunet_cadet_profiler_SOURCES = \ diff --git a/src/consensus/Makefile.am b/src/consensus/Makefile.am index cf1d32e74..d7b23e7c6 100644 --- a/src/consensus/Makefile.am +++ b/src/consensus/Makefile.am @@ -89,7 +89,6 @@ libgnunet_plugin_block_consensus_la_LDFLAGS = \ -if HAVE_TESTING bin_PROGRAMS = \ gnunet-consensus-profiler @@ -100,7 +99,6 @@ if ENABLE_TEST_RUN AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; TESTS = $(check_PROGRAMS) endif -endif test_consensus_api_SOURCES = \ test_consensus_api.c diff --git a/src/core/Makefile.am b/src/core/Makefile.am index d2d3a2d7f..e51247e18 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -54,10 +54,8 @@ gnunet_core_LDADD = \ gnunet_core_LDFLAGS = \ $(GN_LIBINTL) -if HAVE_TESTING - TESTING_TESTS = \ - test_core_api_send_to_self -endif +TESTING_TESTS = \ + test_core_api_send_to_self check_PROGRAMS = \ test_core_api_start_only \ diff --git a/src/datacache/Makefile.am b/src/datacache/Makefile.am index ecb02d1c3..4789706ff 100644 --- a/src/datacache/Makefile.am +++ b/src/datacache/Makefile.am @@ -85,7 +85,6 @@ libgnunet_plugin_datacache_template_la_LDFLAGS = \ $(GN_PLUGIN_LDFLAGS) -if HAVE_TESTING if HAVE_SQLITE if HAVE_BENCHMARKS SQLITE_BENCHMARKS = \ @@ -95,7 +94,6 @@ SQLITE_TESTS = \ test_datacache_sqlite \ test_datacache_quota_sqlite \ $(SQLITE_BENCHMARKS) -endif if HAVE_BENCHMARKS HEAP_BENCHMARKS = \ diff --git a/src/datastore/Makefile.am b/src/datastore/Makefile.am index cd1df4e5e..07ae004b3 100644 --- a/src/datastore/Makefile.am +++ b/src/datastore/Makefile.am @@ -52,7 +52,6 @@ gnunet_datastore_LDADD = \ if HAVE_MYSQL MYSQL_PLUGIN = libgnunet_plugin_datastore_mysql.la -if HAVE_TESTING if HAVE_BENCHMARKS MYSQL_BENCHMARKS = \ perf_datastore_api_mysql \ @@ -64,10 +63,8 @@ endif test_plugin_datastore_mysql \ $(MYSQL_BENCHMARKS) endif -endif if HAVE_SQLITE SQLITE_PLUGIN = libgnunet_plugin_datastore_sqlite.la -if HAVE_TESTING if HAVE_BENCHMARKS SQLITE_BENCHMARKS = \ perf_datastore_api_sqlite \ @@ -79,10 +76,8 @@ endif test_plugin_datastore_sqlite \ $(SQLITE_BENCHMARKS) endif -endif if HAVE_POSTGRESQL POSTGRES_PLUGIN = libgnunet_plugin_datastore_postgres.la -if HAVE_TESTING if HAVE_BENCHMARKS POSTGRES_BENCHMARKS = \ perf_datastore_api_postgres \ @@ -94,7 +89,6 @@ endif test_plugin_datastore_postgres \ $(POSTGRES_BENCHMARKS) endif -endif plugin_LTLIBRARIES = \ $(SQLITE_PLUGIN) \ diff --git a/src/dht/Makefile.am b/src/dht/Makefile.am index 919eca438..69e34000c 100644 --- a/src/dht/Makefile.am +++ b/src/dht/Makefile.am @@ -52,10 +52,8 @@ bin_PROGRAMS = \ gnunet-dht-get \ gnunet-dht-put -if HAVE_TESTING noinst_PROGRAMS = \ gnunet-dht-profiler -endif gnunet_service_dht_SOURCES = \ gnunet-service-dht.c gnunet-service-dht.h \ @@ -117,9 +115,7 @@ gnunet_dht_profiler_LDADD = \ gnunet_dht_profiler_LDFLAGS = \ $(GN_LIBINTL) -if HAVE_TESTING noinst_LIBRARIES = libgnunetdhttest.a -endif libgnunetdhttest_a_SOURCES = \ dht_test_lib.c dht_test_lib.h @@ -128,7 +124,6 @@ libgnunetdhttest_a_LIBADD = \ $(top_builddir)/src/testbed/libgnunettestbed.la \ libgnunetdht.la -if HAVE_TESTING check_PROGRAMS = \ test_dht_api \ test_dht_twopeer \ @@ -136,7 +131,6 @@ check_PROGRAMS = \ test_dht_line \ test_dht_2dtorus \ test_dht_monitor -endif if HAVE_EXPERIMENTAL # These tests still do not work as testbed does diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am index 5b6ba2376..3d8ec2bac 100644 --- a/src/fs/Makefile.am +++ b/src/fs/Makefile.am @@ -21,9 +21,7 @@ lib_LTLIBRARIES = libgnunetfs.la plugin_LTLIBRARIES = \ libgnunet_plugin_block_fs.la -if HAVE_TESTING noinst_LIBRARIES = libgnunetfstest.a -endif libgnunetfs_la_SOURCES = \ fs_api.c fs_api.h fs.h \ @@ -71,11 +69,9 @@ libexec_PROGRAMS = \ gnunet-helper-fs-publish \ gnunet-service-fs -if HAVE_TESTING noinst_PROGRAMS = \ gnunet-fs-profiler \ gnunet-daemon-fsprofiler -endif bin_PROGRAMS = \ gnunet-auto-share \ @@ -230,7 +226,6 @@ if HAVE_BENCHMARKS perf_gnunet_service_fs_p2p_respect endif -if HAVE_TESTING check_PROGRAMS = \ test_plugin_block_fs \ test_fs_directory \ @@ -258,7 +253,6 @@ check_PROGRAMS = \ test_gnunet_service_fs_p2p \ test_gnunet_service_fs_p2p_cadet \ $(FS_BENCHMARKS) -endif test_plugin_block_fs_SOURCES = \ test_plugin_block_fs.c diff --git a/src/identity/Makefile.am b/src/identity/Makefile.am index e806f0059..59ace6c41 100644 --- a/src/identity/Makefile.am +++ b/src/identity/Makefile.am @@ -67,11 +67,9 @@ gnunet_identity_LDADD = \ $(top_builddir)/src/util/libgnunetutil.la \ $(GN_LIBINTL) -if HAVE_TESTING check_PROGRAMS = \ test_identity \ test_identity_defaults -endif if ENABLE_TEST_RUN AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; diff --git a/src/namecache/Makefile.am b/src/namecache/Makefile.am index 8ffa85ddb..272f16b77 100644 --- a/src/namecache/Makefile.am +++ b/src/namecache/Makefile.am @@ -17,30 +17,22 @@ endif if HAVE_EXPERIMENTAL FLAT_PLUGIN = libgnunet_plugin_namecache_flat.la -if HAVE_TESTING FLAT_TESTS = test_plugin_namecache_flat endif -endif if HAVE_SQLITE SQLITE_PLUGIN = libgnunet_plugin_namecache_sqlite.la -if HAVE_TESTING SQLITE_TESTS = test_plugin_namecache_sqlite endif -endif if HAVE_POSTGRESQL POSTGRES_PLUGIN = libgnunet_plugin_namecache_postgres.la -if HAVE_TESTING POSTGRES_TESTS = test_plugin_namecache_postgres endif -endif # testcases do not even build yet; thus: experimental! -if HAVE_TESTING TESTING_TESTS = \ test_namecache_api_cache_block -endif if HAVE_SQLITE check_PROGRAMS = \ diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am index 18e6a196b..51708dd67 100644 --- a/src/namestore/Makefile.am +++ b/src/namestore/Makefile.am @@ -16,7 +16,6 @@ if USE_COVERAGE endif HEAP_PLUGIN = libgnunet_plugin_namestore_flat.la -if HAVE_TESTING HEAP_TESTS = test_plugin_namestore_flat \ test_namestore_api_store_flat \ test_namestore_api_store_update_flat \ @@ -35,11 +34,9 @@ HEAP_TESTS = test_plugin_namestore_flat \ test_namestore_api_monitoring_existing_flat \ test_namestore_api_zone_to_name_flat \ perf_namestore_api_zone_iteration_flat -endif if HAVE_SQLITE SQLITE_PLUGIN = libgnunet_plugin_namestore_sqlite.la -if HAVE_TESTING SQLITE_TESTS = test_plugin_namestore_sqlite \ test_namestore_api_store_sqlite \ test_namestore_api_store_update_sqlite \ @@ -59,11 +56,9 @@ SQLITE_TESTS = test_plugin_namestore_sqlite \ test_namestore_api_zone_to_name_sqlite \ perf_namestore_api_zone_iteration_sqlite endif -endif if HAVE_POSTGRESQL POSTGRES_PLUGIN = libgnunet_plugin_namestore_postgres.la -if HAVE_TESTING POSTGRES_TESTS = test_plugin_namestore_postgres \ test_namestore_api_store_postgres \ test_namestore_api_store_update_postgres \ @@ -83,7 +78,6 @@ POSTGRES_TESTS = test_plugin_namestore_postgres \ test_namestore_api_zone_to_name_postgres \ perf_namestore_api_zone_iteration_postgres endif -endif if HAVE_SQLITE check_PROGRAMS = \ diff --git a/src/nse/Makefile.am b/src/nse/Makefile.am index 824aa10d4..0c6182e61 100644 --- a/src/nse/Makefile.am +++ b/src/nse/Makefile.am @@ -36,10 +36,8 @@ libgnunetnse_la_LDFLAGS = \ libexec_PROGRAMS = \ gnunet-service-nse -if HAVE_TESTING noinst_PROGRAMS = \ gnunet-nse-profiler -endif gnunet_nse_profiler_SOURCES = \ gnunet-nse-profiler.c @@ -71,12 +69,10 @@ if HAVE_BENCHMARKS MULTIPEER_TEST = test_nse_multipeer endif -if HAVE_TESTING check_PROGRAMS = \ test_nse_api \ perf_kdf \ $(MULTIPEER_TEST) -endif if ENABLE_TEST_RUN AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; diff --git a/src/peerinfo/Makefile.am b/src/peerinfo/Makefile.am index e61e5a13d..cdab22a9d 100644 --- a/src/peerinfo/Makefile.am +++ b/src/peerinfo/Makefile.am @@ -48,14 +48,12 @@ if HAVE_BENCHMARKS perf_peerinfo_api endif -if HAVE_TESTING check_PROGRAMS = \ test_peerinfo_shipped_hellos \ test_peerinfo_api \ test_peerinfo_api_friend_only \ test_peerinfo_api_notify_friend_only \ $(PEERINFO_BENCHMARKS) -endif if ENABLE_TEST_RUN diff --git a/src/peerstore/Makefile.am b/src/peerstore/Makefile.am index babf40654..d9904e59d 100644 --- a/src/peerstore/Makefile.am +++ b/src/peerstore/Makefile.am @@ -63,9 +63,7 @@ endif if HAVE_SQLITE SQLITE_PLUGIN = libgnunet_plugin_peerstore_sqlite.la -if HAVE_TESTING SQLITE_TESTS = test_plugin_peerstore_sqlite -endif libgnunet_plugin_peerstore_sqlite_la_SOURCES = \ plugin_peerstore_sqlite.c libgnunet_plugin_peerstore_sqlite_la_LIBADD = \ diff --git a/src/pt/Makefile.am b/src/pt/Makefile.am index 10ae04931..fc2cb592c 100644 --- a/src/pt/Makefile.am +++ b/src/pt/Makefile.am @@ -28,8 +28,6 @@ gnunet_daemon_pt_LDADD = \ $(top_builddir)/src/util/libgnunetutil.la \ $(GN_LIBINTL) -if HAVE_TESTING - if HAVE_LIBGNURL LIB_GNURL=@LIBGNURL@ CPP_GNURL=@LIBGNURL_CPPFLAGS@ @@ -56,8 +54,6 @@ endif endif endif -endif - check_PROGRAMS = $(VPN_TEST) if ENABLE_TEST_RUN diff --git a/src/regex/Makefile.am b/src/regex/Makefile.am index 9a7466cb2..2dbf3a3f9 100644 --- a/src/regex/Makefile.am +++ b/src/regex/Makefile.am @@ -102,11 +102,9 @@ libgnunetregextest_a_LIBADD = \ $(top_builddir)/src/util/libgnunetutil.la \ libgnunetregex_internal.a -if HAVE_TESTING noinst_PROGRAMS = $(noinst_mysql_progs) \ perf-regex \ gnunet-regex-profiler -endif perf_regex_SOURCES = \ perf-regex.c diff --git a/src/rps/Makefile.am b/src/rps/Makefile.am index b9de6b5e3..b5e8c0617 100644 --- a/src/rps/Makefile.am +++ b/src/rps/Makefile.am @@ -45,10 +45,8 @@ libgnunetrps_la_CFLAGS = $(AM_CFLAGS) libexec_PROGRAMS = \ gnunet-service-rps -if HAVE_TESTING noinst_PROGRAMS = \ gnunet-rps-profiler -endif gnunet_service_rps_SOURCES = \ @@ -74,7 +72,6 @@ gnunet_service_rps_LDADD = \ $(GN_LIBINTL) -if HAVE_TESTING check_PROGRAMS = \ test_service_rps_view \ test_service_rps_custommap \ @@ -91,7 +88,6 @@ check_PROGRAMS += \ test_rps_malicious_2 \ test_rps_malicious_3 endif -endif rps_test_src = \ test_rps.c \ diff --git a/src/secretsharing/Makefile.am b/src/secretsharing/Makefile.am index 9ae6e7892..13dd0bd8d 100644 --- a/src/secretsharing/Makefile.am +++ b/src/secretsharing/Makefile.am @@ -51,7 +51,6 @@ libgnunetsecretsharing_la_LIBADD = \ libgnunetsecretsharing_la_LDFLAGS = \ $(GN_LIB_LDFLAGS) -if HAVE_TESTING bin_PROGRAMS = \ gnunet-secretsharing-profiler @@ -62,7 +61,6 @@ if ENABLE_TEST_RUN AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; TESTS = $(check_PROGRAMS) endif -endif test_secretsharing_api_SOURCES = \ test_secretsharing_api.c diff --git a/src/set/Makefile.am b/src/set/Makefile.am index d6b10a1f8..837d42ff5 100644 --- a/src/set/Makefile.am +++ b/src/set/Makefile.am @@ -14,13 +14,11 @@ if USE_COVERAGE AM_CFLAGS = -fprofile-arcs -ftest-coverage endif -if HAVE_TESTING bin_PROGRAMS = \ gnunet-set-profiler noinst_PROGRAMS = \ gnunet-set-ibf-profiler -endif libexec_PROGRAMS = \ gnunet-service-set @@ -69,13 +67,11 @@ libgnunetset_la_LIBADD = \ libgnunetset_la_LDFLAGS = \ $(GN_LIB_LDFLAGS) -if HAVE_TESTING check_PROGRAMS = \ test_set_api \ test_set_union_result_symmetric \ test_set_intersection_result_full \ test_set_union_copy -endif if ENABLE_TEST_RUN AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; diff --git a/src/seti/Makefile.am b/src/seti/Makefile.am index 522f33ece..8441c5060 100644 --- a/src/seti/Makefile.am +++ b/src/seti/Makefile.am @@ -14,10 +14,8 @@ if USE_COVERAGE AM_CFLAGS = -fprofile-arcs -ftest-coverage endif -if HAVE_TESTING bin_PROGRAMS = \ gnunet-seti-profiler -endif libexec_PROGRAMS = \ gnunet-service-seti @@ -55,10 +53,8 @@ libgnunetseti_la_LIBADD = \ libgnunetseti_la_LDFLAGS = \ $(GN_LIB_LDFLAGS) -if HAVE_TESTING check_PROGRAMS = \ test_seti_api -endif if ENABLE_TEST_RUN AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; diff --git a/src/setu/Makefile.am b/src/setu/Makefile.am index 77d048add..897bf3f86 100644 --- a/src/setu/Makefile.am +++ b/src/setu/Makefile.am @@ -14,13 +14,11 @@ if USE_COVERAGE AM_CFLAGS = -fprofile-arcs -ftest-coverage endif -if HAVE_TESTING bin_PROGRAMS = \ gnunet-setu-profiler noinst_PROGRAMS = \ gnunet-setu-ibf-profiler -endif libexec_PROGRAMS = \ gnunet-service-setu @@ -67,11 +65,9 @@ libgnunetsetu_la_LIBADD = \ libgnunetsetu_la_LDFLAGS = \ $(GN_LIB_LDFLAGS) -if HAVE_TESTING check_PROGRAMS = \ test_setu_api \ perf_setu_api -endif if ENABLE_TEST_RUN AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; diff --git a/src/topology/Makefile.am b/src/topology/Makefile.am index 8580d200c..e5920116b 100644 --- a/src/topology/Makefile.am +++ b/src/topology/Makefile.am @@ -42,10 +42,8 @@ gnunet_daemon_topology_LDADD = \ $(GN_LIBINTL) -if HAVE_TESTING check_PROGRAMS = \ test_gnunet_daemon_topology -endif if ENABLE_TEST_RUN AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index 32075ee16..a539f3f25 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am @@ -128,11 +128,9 @@ noinst_PROGRAMS = \ $(WLAN_BIN_SENDER) \ $(WLAN_BIN_RECEIVER) -if HAVE_TESTING TESTING_LIBS = \ libgnunettransporttesting.la \ libgnunettransporttesting2.la -endif lib_LTLIBRARIES = \ libgnunettransport.la \ @@ -594,7 +592,6 @@ libgnunet_plugin_transport_https_server_la_LDFLAGS = \ libgnunet_plugin_transport_https_server_la_CFLAGS = \ $(MHD_CFLAGS) $(AM_CFLAGS) -DBUILD_HTTPS -if HAVE_TESTING check_PROGRAMS = \ test_transport_simple_send \ test_transport_simple_send_v2 \ @@ -682,7 +679,6 @@ check_PROGRAMS += \ test_communicator_backchannel-udp \ test_communicator_bidirect-tcp endif -endif if ENABLE_TEST_RUN AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; diff --git a/src/util/Makefile.am b/src/util/Makefile.am index a3a77073e..c3a0feccc 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -145,10 +145,8 @@ libgnunetutil_la_LDFLAGS = \ $(GN_LIB_LDFLAGS) \ -version-info 14:0:0 -if HAVE_TESTING - GNUNET_ECC = gnunet-ecc - GNUNET_SCRYPT = gnunet-scrypt -endif +GNUNET_ECC = gnunet-ecc +GNUNET_SCRYPT = gnunet-scrypt lib_LTLIBRARIES = libgnunetutil.la -- cgit v1.2.3 From d64ac269856744b9bab170964e1d6f36896ecc55 Mon Sep 17 00:00:00 2001 From: t3sserakt Date: Thu, 14 Oct 2021 16:39:24 +0200 Subject: removed versioned artefacts with v2 and v3. changes to reflect the changes in testing_api_loop.c --- src/dhtu/test_dhtu_ip.c | 8 +- src/include/gnunet_testing_ng_lib.h | 86 +-- src/testing/Makefile.am | 4 - src/testing/netjail_core.sh | 190 +++++- src/testing/netjail_core_v2.sh | 260 -------- src/testing/netjail_exec.sh | 6 +- src/testing/netjail_exec_v2.sh | 14 - src/testing/netjail_start.sh | 70 +- src/testing/netjail_start_v2.sh | 74 --- src/testing/netjail_stop.sh | 49 +- src/testing/netjail_stop_v2.sh | 59 -- src/testing/testing.c | 30 +- ...testing_api_cmd_block_until_all_peers_started.c | 6 + .../testing_api_cmd_block_until_external_trigger.c | 63 +- src/testing/testing_api_cmd_netjail_start.c | 71 +- .../testing_api_cmd_netjail_start_testsystem.c | 327 ++++++---- .../testing_api_cmd_netjail_start_testsystem_v2.c | 723 --------------------- src/testing/testing_api_cmd_netjail_start_v2.c | 209 ------ src/testing/testing_api_cmd_netjail_stop.c | 54 +- .../testing_api_cmd_netjail_stop_testsystem.c | 79 ++- .../testing_api_cmd_netjail_stop_testsystem_v2.c | 141 ---- src/testing/testing_api_cmd_netjail_stop_v2.c | 185 ------ src/testing/testing_api_loop.c | 8 +- src/testing/testing_cmds.h | 2 + src/transport/Makefile.am | 48 -- .../test_transport_plugin_cmd_simple_send.c | 192 ++++-- .../test_transport_plugin_cmd_simple_send_v2.c | 235 ------- .../test_transport_plugin_cmd_udp_backchannel.c | 175 +++-- src/transport/test_transport_port_forward.c | 85 --- src/transport/test_transport_simple_send.c | 86 --- src/transport/test_transport_simple_send.sh | 2 +- src/transport/test_transport_simple_send_v2.c | 83 --- src/transport/test_transport_simple_send_v2.sh | 2 - src/transport/test_transport_start_with_config.c | 59 +- src/transport/transport-testing-cmds.h | 201 ++---- src/transport/transport_api_cmd_connecting_peers.c | 482 ++++++++++---- .../transport_api_cmd_connecting_peers_v2.c | 237 ------- .../transport_api_cmd_connecting_peers_v3.c | 496 -------------- src/transport/transport_api_cmd_send_simple.c | 20 +- src/transport/transport_api_cmd_send_simple_v2.c | 156 ----- src/transport/transport_api_cmd_start_peer.c | 78 ++- src/transport/transport_api_cmd_start_peer_v2.c | 605 ----------------- src/transport/transport_api_cmd_start_peer_v3.c | 617 ------------------ src/util/child_management.c | 19 +- 44 files changed, 1441 insertions(+), 5155 deletions(-) delete mode 100755 src/testing/netjail_core_v2.sh delete mode 100755 src/testing/netjail_exec_v2.sh delete mode 100755 src/testing/netjail_start_v2.sh delete mode 100755 src/testing/netjail_stop_v2.sh delete mode 100644 src/testing/testing_api_cmd_netjail_start_testsystem_v2.c delete mode 100644 src/testing/testing_api_cmd_netjail_start_v2.c delete mode 100644 src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c delete mode 100644 src/testing/testing_api_cmd_netjail_stop_v2.c delete mode 100644 src/transport/test_transport_plugin_cmd_simple_send_v2.c delete mode 100644 src/transport/test_transport_port_forward.c delete mode 100644 src/transport/test_transport_simple_send.c delete mode 100644 src/transport/test_transport_simple_send_v2.c delete mode 100755 src/transport/test_transport_simple_send_v2.sh delete mode 100644 src/transport/transport_api_cmd_connecting_peers_v2.c delete mode 100644 src/transport/transport_api_cmd_connecting_peers_v3.c delete mode 100644 src/transport/transport_api_cmd_send_simple_v2.c delete mode 100644 src/transport/transport_api_cmd_start_peer_v2.c delete mode 100644 src/transport/transport_api_cmd_start_peer_v3.c (limited to 'src') diff --git a/src/dhtu/test_dhtu_ip.c b/src/dhtu/test_dhtu_ip.c index eb886e994..c9528053f 100644 --- a/src/dhtu/test_dhtu_ip.c +++ b/src/dhtu/test_dhtu_ip.c @@ -37,10 +37,10 @@ main (int argc, char *const *argv) { struct GNUNET_TESTING_Command commands[] = { - GNUNET_TESTING_cmd_netjail_start_v2 ("netjail-start", - CONFIG_FILE), - GNUNET_TESTING_cmd_netjail_stop_v2 ("netjail-stop", - CONFIG_FILE), + GNUNET_TESTING_cmd_netjail_start ("netjail-start", + CONFIG_FILE), + GNUNET_TESTING_cmd_netjail_stop ("netjail-stop", + CONFIG_FILE), GNUNET_TESTING_cmd_end () }; diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h index 0cab64504..adf5453e1 100644 --- a/src/include/gnunet_testing_ng_lib.h +++ b/src/include/gnunet_testing_ng_lib.h @@ -1050,19 +1050,6 @@ GNUNET_TESTING_cmd_system_destroy (const char *label, const char *create_label); -/** - * Create command. - * - * @param label name for command. - * @param local_m Number of local nodes in each namespace. - * @param global_n The number of namespaces. - * @return command. - */ -struct GNUNET_TESTING_Command -GNUNET_TESTING_cmd_netjail_start (const char *label, - char *local_m, - char *global_n); - /** * Create command. * @@ -1071,23 +1058,8 @@ GNUNET_TESTING_cmd_netjail_start (const char *label, * @return command. */ struct GNUNET_TESTING_Command -GNUNET_TESTING_cmd_netjail_start_v2 (const char *label, - char *topology_config); - - -/** - * Create command. - * - * @param label name for command. - * @param binaryname to exec. - * @return command. - */ -struct GNUNET_TESTING_Command -GNUNET_TESTING_cmd_netjail_start_testing_system (const char *label, - char *local_m, - char *global_n, - char *plugin_name, - unsigned int *rv); +GNUNET_TESTING_cmd_netjail_start (const char *label, + char *topology_config); /** @@ -1099,22 +1071,20 @@ GNUNET_TESTING_cmd_netjail_start_testing_system (const char *label, * @return command. */ struct GNUNET_TESTING_Command -GNUNET_TESTING_cmd_netjail_start_testing_system_v2 (const char *label, - const char *topology_config, - unsigned int *rv); +GNUNET_TESTING_cmd_netjail_start_testing_system (const char *label, + const char *topology_config); /** * Create command. * * @param label name for command. - * @param binaryname to stop. + * @param topology_config Configuration file for the test topology. * @return command. */ struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_netjail_stop (const char *label, - char *local_m, - char *global_n); + char *topology_config); /** @@ -1124,35 +1094,32 @@ GNUNET_TESTING_cmd_netjail_stop (const char *label, * @param topology_config Configuration file for the test topology. * @return command. */ -struct GNUNET_TESTING_Command -GNUNET_TESTING_cmd_netjail_stop_v2 (const char *label, - char *topology_config); - - struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_stop_testing_system (const char *label, const char *helper_start_label, - char *local_m, - char *global_n); + const char *topology_config); + /** - * Create command. + * Create a GNUNET_CMDS_LOCAL_FINISHED message. * - * @param label name for command. - * @param topology_config Configuration file for the test topology. - * @return command. - */ -struct GNUNET_TESTING_Command -GNUNET_TESTING_cmd_stop_testing_system_v2 (const char *label, - const char *helper_start_label, - const char *topology_config); + * @param rv The result of the local test as GNUNET_GenericReturnValue. + * @return The GNUNET_CMDS_LOCAL_FINISHED message. +*/ +struct GNUNET_MessageHeader * +GNUNET_TESTING_send_local_test_finished_msg (enum GNUNET_GenericReturnValue rv); -// FIXME: document! -enum GNUNET_GenericReturnValue -GNUNET_TESTING_get_trait_helper_handles (const struct - GNUNET_TESTING_Command *cmd, - struct GNUNET_HELPER_Handle ***helper); +/** + * 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); /** @@ -1163,7 +1130,7 @@ GNUNET_TESTING_get_trait_helper_handles (const struct * @return #GNUNET_OK on success. */ enum GNUNET_GenericReturnValue -GNUNET_TESTING_get_trait_helper_handles_v2 ( +GNUNET_TESTING_get_trait_helper_handles ( const struct GNUNET_TESTING_Command *cmd, struct GNUNET_HELPER_Handle ***helper); @@ -1176,8 +1143,7 @@ GNUNET_TESTING_cmd_block_until_all_peers_started ( struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_block_until_external_trigger ( - const char *label, - unsigned int *stop_blocking); + const char *label); struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_send_peer_ready (const char *label, diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am index e9389a876..39e85c4ac 100644 --- a/src/testing/Makefile.am +++ b/src/testing/Makefile.am @@ -51,13 +51,9 @@ libgnunettesting_la_SOURCES = \ testing_api_cmd_block_until_all_peers_started.c \ testing_api_cmd_block_until_external_trigger.c \ testing_api_cmd_netjail_start.c \ - testing_api_cmd_netjail_start_v2.c \ testing_api_cmd_netjail_start_testsystem.c \ - testing_api_cmd_netjail_start_testsystem_v2.c \ testing_api_cmd_netjail_stop_testsystem.c \ - testing_api_cmd_netjail_stop_testsystem_v2.c \ testing_api_cmd_netjail_stop.c \ - testing_api_cmd_netjail_stop_v2.c \ testing.c testing.h \ testing_api_cmd_system_create.c \ testing_api_cmd_system_destroy.c \ diff --git a/src/testing/netjail_core.sh b/src/testing/netjail_core.sh index cf350d3fa..ef0a54a5e 100755 --- a/src/testing/netjail_core.sh +++ b/src/testing/netjail_core.sh @@ -2,6 +2,7 @@ # +PREFIX=${PPID:?must run from a parent process} # running with `sudo` is required to be # able running the actual commands as the @@ -9,10 +10,61 @@ export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" -netjail_check() { - NODE_COUNT=$1 +export RESULT= +export NAMESPACE_NUM=0 +export INTERFACE_NUM=0 + +netjail_next_namespace() { + local NUM=$NAMESPACE_NUM + NAMESPACE_NUM=$(($NAMESPACE_NUM + 1)) + RESULT=$NUM +} + +netjail_next_interface() { + local NUM=$INTERFACE_NUM + INTERFACE_NUM=$(($INTERFACE_NUM + 1)) + RESULT=$NUM +} + +netjail_opt() { + local OPT=$1 + shift 1 + + INDEX=1 + + while [ $# -gt 0 ]; do + if [ "$1" = "$OPT" ]; then + RESULT=$INDEX + return + fi + + INDEX=$(($INDEX + 1)) + shift 1 + done + + RESULT=0 +} + +netjail_opts() { + local OPT=$1 + local DEF=$2 + shift 2 + + while [ $# -gt 0 ]; do + if [ "$1" = "$OPT" ]; then + printf "$2" + return + fi + + shift 1 + done + + RESULT="$DEF" +} - FD_COUNT=$(($(ls /proc/self/fd | wc -w) - 4)) +netjail_check() { + local NODE_COUNT=$1 + local FD_COUNT=$(($(ls /proc/self/fd | wc -w) - 4)) # quit if `$FD_COUNT < ($LOCAL_M * $GLOBAL_N * 2)`: # the script also requires `sudo -C ($FD_COUNT + 4)` @@ -25,43 +77,81 @@ netjail_check() { fi } -netjail_print_name() { - printf "%s%02x%02x" $1 $2 ${3:-0} +netjail_check_bin() { + local PROGRAM=$1 + local MATCH=$(ls $(echo $PATH | tr ":" "\n") | grep "^$PROGRAM\$" | tr "\n" " " | awk '{ print $1 }') + + # quit if the required binary $PROGRAM can not be + # found in the used $PATH. + + if [ "$MATCH" != "$PROGRAM" ]; then + echo "Required binary not found: $PROGRAM" >&2 + exit 1 + fi } netjail_bridge() { - BRIDGE=$1 + netjail_next_interface + local NUM=$RESULT + local BRIDGE=$(printf "%06x-%08x" $PREFIX $NUM) ip link add $BRIDGE type bridge ip link set dev $BRIDGE up + + RESULT=$BRIDGE +} + +netjail_bridge_name() { + netjail_next_interface + local NUM=$RESULT + local BRIDGE=$(printf "%06x-%08x" $PREFIX $NUM) + + RESULT=$BRIDGE } netjail_bridge_clear() { - BRIDGE=$1 + local BRIDGE=$1 ip link delete $BRIDGE } netjail_node() { - NODE=$1 + netjail_next_namespace + local NUM=$RESULT + local NODE=$(printf "%06x-%08x" $PREFIX $NUM) ip netns add $NODE + + RESULT=$NODE +} + +netjail_node_name() { + netjail_next_namespace + local NUM=$RESULT + local NODE=$(printf "%06x-%08x" $PREFIX $NUM) + + RESULT=$NODE } netjail_node_clear() { - NODE=$1 + local NODE=$1 ip netns delete $NODE } netjail_node_link_bridge() { - NODE=$1 - BRIDGE=$2 - ADDRESS=$3 - MASK=$4 + local NODE=$1 + local BRIDGE=$2 + local ADDRESS=$3 + local MASK=$4 - LINK_IF="$NODE-$BRIDGE-0" - LINK_BR="$NODE-$BRIDGE-1" + netjail_next_interface + local NUM_IF=$RESULT + netjail_next_interface + local NUM_BR=$RESULT + + local LINK_IF=$(printf "%06x-%08x" $PREFIX $NUM_IF) + local LINK_BR=$(printf "%06x-%08x" $PREFIX $NUM_BR) ip link add $LINK_IF type veth peer name $LINK_BR ip link set $LINK_IF netns $NODE @@ -72,28 +162,47 @@ netjail_node_link_bridge() { ip -n $NODE link set up dev lo ip link set $LINK_BR up + + RESULT=$LINK_BR +} + +netjail_node_link_bridge_name() { + + netjail_next_interface + netjail_next_interface + local NUM_BR=$RESULT + + local LINK_BR=$(printf "%06x-%08x" $PREFIX $NUM_BR) + + RESULT=$LINK_BR +} + +netjail_node_unlink_bridge() { + local LINK_BR=$1 + + ip link delete $LINK_BR } netjail_node_add_nat() { - NODE=$1 - ADDRESS=$2 - MASK=$3 + local NODE=$1 + local ADDRESS=$2 + local MASK=$3 ip netns exec $NODE iptables -t nat -A POSTROUTING -s "$ADDRESS/$MASK" -j MASQUERADE } netjail_node_add_default() { - NODE=$1 - ADDRESS=$2 + local NODE=$1 + local ADDRESS=$2 ip -n $NODE route add default via $ADDRESS } netjail_node_exec() { JAILOR=${SUDO_USER:?must run in sudo} - NODE=$1 - FD_IN=$2 - FD_OUT=$3 + local NODE=$1 + local FD_IN=$2 + local FD_OUT=$3 shift 3 ip netns exec $NODE sudo -u $JAILOR -- $@ 1>& $FD_OUT 0<& $FD_IN @@ -114,3 +223,38 @@ netjail_node_exec_without_fds_and_sudo() { ip netns exec $NODE $@ } +netjail_kill() { + local PID=$1 + local MATCH=$(ps --pid $PID | awk "{ if ( \$1 == $PID ) { print \$1 } }" | wc -l) + + if [ $MATCH -gt 0 ]; then + kill -n 19 $PID + + for CHILD in $(ps -o pid,ppid -ax | awk "{ if ( \$2 == $PID ) { print \$1 } }"); do + netjail_kill $CHILD + done + + kill $PID + fi +} + +netjail_killall() { + if [ $# -gt 0 ]; then + local PIDS=$1 + + for PID in $PIDS; do + netjail_kill $PID + done + fi +} + +netjail_waitall() { + if [ $# -gt 0 ]; then + local PIDS=$1 + + for PID in $PIDS; do + wait $PID + done + fi +} + diff --git a/src/testing/netjail_core_v2.sh b/src/testing/netjail_core_v2.sh deleted file mode 100755 index ef0a54a5e..000000000 --- a/src/testing/netjail_core_v2.sh +++ /dev/null @@ -1,260 +0,0 @@ -#!/bin/sh -# - - -PREFIX=${PPID:?must run from a parent process} - -# running with `sudo` is required to be -# able running the actual commands as the -# original user. - -export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - -export RESULT= -export NAMESPACE_NUM=0 -export INTERFACE_NUM=0 - -netjail_next_namespace() { - local NUM=$NAMESPACE_NUM - NAMESPACE_NUM=$(($NAMESPACE_NUM + 1)) - RESULT=$NUM -} - -netjail_next_interface() { - local NUM=$INTERFACE_NUM - INTERFACE_NUM=$(($INTERFACE_NUM + 1)) - RESULT=$NUM -} - -netjail_opt() { - local OPT=$1 - shift 1 - - INDEX=1 - - while [ $# -gt 0 ]; do - if [ "$1" = "$OPT" ]; then - RESULT=$INDEX - return - fi - - INDEX=$(($INDEX + 1)) - shift 1 - done - - RESULT=0 -} - -netjail_opts() { - local OPT=$1 - local DEF=$2 - shift 2 - - while [ $# -gt 0 ]; do - if [ "$1" = "$OPT" ]; then - printf "$2" - return - fi - - shift 1 - done - - RESULT="$DEF" -} - -netjail_check() { - local NODE_COUNT=$1 - local FD_COUNT=$(($(ls /proc/self/fd | wc -w) - 4)) - - # quit if `$FD_COUNT < ($LOCAL_M * $GLOBAL_N * 2)`: - # the script also requires `sudo -C ($FD_COUNT + 4)` - # so you need 'Defaults closefrom_override' in the - # sudoers file. - - if [ $FD_COUNT -lt $(($NODE_COUNT * 2)) ]; then - echo "File descriptors do not match requirements!" >&2 - exit 1 - fi -} - -netjail_check_bin() { - local PROGRAM=$1 - local MATCH=$(ls $(echo $PATH | tr ":" "\n") | grep "^$PROGRAM\$" | tr "\n" " " | awk '{ print $1 }') - - # quit if the required binary $PROGRAM can not be - # found in the used $PATH. - - if [ "$MATCH" != "$PROGRAM" ]; then - echo "Required binary not found: $PROGRAM" >&2 - exit 1 - fi -} - -netjail_bridge() { - netjail_next_interface - local NUM=$RESULT - local BRIDGE=$(printf "%06x-%08x" $PREFIX $NUM) - - ip link add $BRIDGE type bridge - ip link set dev $BRIDGE up - - RESULT=$BRIDGE -} - -netjail_bridge_name() { - netjail_next_interface - local NUM=$RESULT - local BRIDGE=$(printf "%06x-%08x" $PREFIX $NUM) - - RESULT=$BRIDGE -} - -netjail_bridge_clear() { - local BRIDGE=$1 - - ip link delete $BRIDGE -} - -netjail_node() { - netjail_next_namespace - local NUM=$RESULT - local NODE=$(printf "%06x-%08x" $PREFIX $NUM) - - ip netns add $NODE - - RESULT=$NODE -} - -netjail_node_name() { - netjail_next_namespace - local NUM=$RESULT - local NODE=$(printf "%06x-%08x" $PREFIX $NUM) - - RESULT=$NODE -} - -netjail_node_clear() { - local NODE=$1 - - ip netns delete $NODE -} - -netjail_node_link_bridge() { - local NODE=$1 - local BRIDGE=$2 - local ADDRESS=$3 - local MASK=$4 - - netjail_next_interface - local NUM_IF=$RESULT - netjail_next_interface - local NUM_BR=$RESULT - - local LINK_IF=$(printf "%06x-%08x" $PREFIX $NUM_IF) - local LINK_BR=$(printf "%06x-%08x" $PREFIX $NUM_BR) - - ip link add $LINK_IF type veth peer name $LINK_BR - ip link set $LINK_IF netns $NODE - ip link set $LINK_BR master $BRIDGE - - ip -n $NODE addr add "$ADDRESS/$MASK" dev $LINK_IF - ip -n $NODE link set $LINK_IF up - ip -n $NODE link set up dev lo - - ip link set $LINK_BR up - - RESULT=$LINK_BR -} - -netjail_node_link_bridge_name() { - - netjail_next_interface - netjail_next_interface - local NUM_BR=$RESULT - - local LINK_BR=$(printf "%06x-%08x" $PREFIX $NUM_BR) - - RESULT=$LINK_BR -} - -netjail_node_unlink_bridge() { - local LINK_BR=$1 - - ip link delete $LINK_BR -} - -netjail_node_add_nat() { - local NODE=$1 - local ADDRESS=$2 - local MASK=$3 - - ip netns exec $NODE iptables -t nat -A POSTROUTING -s "$ADDRESS/$MASK" -j MASQUERADE -} - -netjail_node_add_default() { - local NODE=$1 - local ADDRESS=$2 - - ip -n $NODE route add default via $ADDRESS -} - -netjail_node_exec() { - JAILOR=${SUDO_USER:?must run in sudo} - local NODE=$1 - local FD_IN=$2 - local FD_OUT=$3 - shift 3 - - ip netns exec $NODE sudo -u $JAILOR -- $@ 1>& $FD_OUT 0<& $FD_IN -} - -netjail_node_exec_without_fds() { - JAILOR=${SUDO_USER:?must run in sudo} - NODE=$1 - shift 1 - - ip netns exec $NODE sudo -u $JAILOR -- $@ -} - -netjail_node_exec_without_fds_and_sudo() { - NODE=$1 - shift 1 - - ip netns exec $NODE $@ -} - -netjail_kill() { - local PID=$1 - local MATCH=$(ps --pid $PID | awk "{ if ( \$1 == $PID ) { print \$1 } }" | wc -l) - - if [ $MATCH -gt 0 ]; then - kill -n 19 $PID - - for CHILD in $(ps -o pid,ppid -ax | awk "{ if ( \$2 == $PID ) { print \$1 } }"); do - netjail_kill $CHILD - done - - kill $PID - fi -} - -netjail_killall() { - if [ $# -gt 0 ]; then - local PIDS=$1 - - for PID in $PIDS; do - netjail_kill $PID - done - fi -} - -netjail_waitall() { - if [ $# -gt 0 ]; then - local PIDS=$1 - - for PID in $PIDS; do - wait $PID - done - fi -} - diff --git a/src/testing/netjail_exec.sh b/src/testing/netjail_exec.sh index 17a7caaac..cd993a39b 100755 --- a/src/testing/netjail_exec.sh +++ b/src/testing/netjail_exec.sh @@ -9,8 +9,6 @@ export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" M=$1 N=$2 -NODE=$(netjail_print_name "N" $N $M) +NODE=$6 - - -netjail_node_exec_without_fds_and_sudo $NODE $3 $4 $5 $1 $2 +netjail_node_exec_without_fds_and_sudo $NODE $3 $4 $5 $1 $2 diff --git a/src/testing/netjail_exec_v2.sh b/src/testing/netjail_exec_v2.sh deleted file mode 100755 index 597baad20..000000000 --- a/src/testing/netjail_exec_v2.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh -. "./../testing/netjail_core_v2.sh" - -set -eu -set -x - -export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - -M=$1 -N=$2 - -NODE=$6 - -netjail_node_exec_without_fds_and_sudo $NODE $3 $4 $5 $1 $2 diff --git a/src/testing/netjail_start.sh b/src/testing/netjail_start.sh index 0984a3c42..1dfe1dfdf 100755 --- a/src/testing/netjail_start.sh +++ b/src/testing/netjail_start.sh @@ -1,52 +1,74 @@ -#!/bin/sh +#!/bin/bash . "./../testing/netjail_core.sh" +. "./../testing/topo.sh" set -eu set -x export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" -LOCAL_M=$1 -GLOBAL_N=$2 +filename=$1 +PREFIX=$2 -# TODO: stunserver? ..and globally known peer? +read_topology $filename shift 2 LOCAL_GROUP="192.168.15" GLOBAL_GROUP="92.68.150" +KNOWN_GROUP="92.68.151" -NETWORK_NET=$(netjail_print_name "n" $GLOBAL_N $LOCAL_M) -netjail_bridge $NETWORK_NET +echo "Start [local: $LOCAL_GROUP.0/24, global: $GLOBAL_GROUP.0/16]" -for N in $(seq $GLOBAL_N); do - ROUTER=$(netjail_print_name "R" $N) +netjail_bridge +NETWORK_NET=$RESULT - netjail_node $ROUTER - netjail_node_link_bridge $ROUTER $NETWORK_NET "$GLOBAL_GROUP.$N" 24 +for X in $(seq $KNOWN); do + netjail_node + KNOWN_NODES[$X]=$RESULT + netjail_node_link_bridge ${KNOWN_NODES[$X]} $NETWORK_NET "$KNOWN_GROUP.$X" 16 + KNOWN_LINKS[$X]=$RESULT +done - ROUTER_NET=$(netjail_print_name "r" $N) +declare -A NODES +declare -A NODE_LINKS - netjail_bridge $ROUTER_NET +for N in $(seq $GLOBAL_N); do + netjail_node + ROUTERS[$N]=$RESULT + netjail_node_link_bridge ${ROUTERS[$N]} $NETWORK_NET "$GLOBAL_GROUP.$N" 16 + NETWORK_LINKS[$N]=$RESULT + netjail_bridge + ROUTER_NETS[$N]=$RESULT for M in $(seq $LOCAL_M); do - NODE=$(netjail_print_name "N" $N $M) - - netjail_node $NODE - netjail_node_link_bridge $NODE $ROUTER_NET "$LOCAL_GROUP.$M" 24 + netjail_node + NODES[$N,$M]=$RESULT + netjail_node_link_bridge ${NODES[$N,$M]} ${ROUTER_NETS[$N]} "$LOCAL_GROUP.$M" 24 + NODE_LINKS[$N,$M]=$RESULT done ROUTER_ADDR="$LOCAL_GROUP.$(($LOCAL_M+1))" - - netjail_node_link_bridge $ROUTER $ROUTER_NET $ROUTER_ADDR 24 - netjail_node_add_nat $ROUTER $ROUTER_ADDR 24 + netjail_node_link_bridge ${ROUTERS[$N]} ${ROUTER_NETS[$N]} $ROUTER_ADDR 24 + ROUTER_LINKS[$N]=$RESULT + + netjail_node_add_nat ${ROUTERS[$N]} $ROUTER_ADDR 24 for M in $(seq $LOCAL_M); do - NODE=$(netjail_print_name "N" $N $M) - - netjail_node_add_default $NODE $ROUTER_ADDR + netjail_node_add_default ${NODES[$N,$M]} $ROUTER_ADDR done -done - + # TODO Topology configuration must be enhanced to configure forwarding to more than one subnet node via different ports. + + if [ "1" == "${R_TCP[$N]}" ] + then + ip netns exec ${ROUTERS[$N]} iptables -t nat -A PREROUTING -p tcp -d $GLOBAL_GROUP.$N --dport 60002 -j DNAT --to $LOCAL_GROUP.1 + ip netns exec ${ROUTERS[$N]} iptables -A FORWARD -d $LOCAL_GROUP.1 -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT + fi + if [ "1" == "${R_UDP[$N]}" ] + then + ip netns exec ${ROUTERS[$N]} iptables -t nat -A PREROUTING -p udp -d $GLOBAL_GROUP.$N --dport 60002 -j DNAT --to $LOCAL_GROUP.1 + ip netns exec ${ROUTERS[$N]} iptables -A FORWARD -d $LOCAL_GROUP.1 -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT + fi +done diff --git a/src/testing/netjail_start_v2.sh b/src/testing/netjail_start_v2.sh deleted file mode 100755 index dd1f2ad93..000000000 --- a/src/testing/netjail_start_v2.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/bash -. "./../testing/netjail_core_v2.sh" -. "./../testing/topo.sh" - -set -eu -set -x - -export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - -filename=$1 -PREFIX=$2 - -read_topology $filename - -shift 2 - -LOCAL_GROUP="192.168.15" -GLOBAL_GROUP="92.68.150" -KNOWN_GROUP="92.68.151" - - -echo "Start [local: $LOCAL_GROUP.0/24, global: $GLOBAL_GROUP.0/16]" - -netjail_bridge -NETWORK_NET=$RESULT - -for X in $(seq $KNOWN); do - netjail_node - KNOWN_NODES[$X]=$RESULT - netjail_node_link_bridge ${KNOWN_NODES[$X]} $NETWORK_NET "$KNOWN_GROUP.$X" 16 - KNOWN_LINKS[$X]=$RESULT -done - -declare -A NODES -declare -A NODE_LINKS - -for N in $(seq $GLOBAL_N); do - netjail_node - ROUTERS[$N]=$RESULT - netjail_node_link_bridge ${ROUTERS[$N]} $NETWORK_NET "$GLOBAL_GROUP.$N" 16 - NETWORK_LINKS[$N]=$RESULT - netjail_bridge - ROUTER_NETS[$N]=$RESULT - - for M in $(seq $LOCAL_M); do - netjail_node - NODES[$N,$M]=$RESULT - netjail_node_link_bridge ${NODES[$N,$M]} ${ROUTER_NETS[$N]} "$LOCAL_GROUP.$M" 24 - NODE_LINKS[$N,$M]=$RESULT - done - - ROUTER_ADDR="$LOCAL_GROUP.$(($LOCAL_M+1))" - netjail_node_link_bridge ${ROUTERS[$N]} ${ROUTER_NETS[$N]} $ROUTER_ADDR 24 - ROUTER_LINKS[$N]=$RESULT - - netjail_node_add_nat ${ROUTERS[$N]} $ROUTER_ADDR 24 - - for M in $(seq $LOCAL_M); do - netjail_node_add_default ${NODES[$N,$M]} $ROUTER_ADDR - done - - # TODO Topology configuration must be enhanced to configure forwarding to more than one subnet node via different ports. - - if [ "1" == "${R_TCP[$N]}" ] - then - ip netns exec ${ROUTERS[$N]} iptables -t nat -A PREROUTING -p tcp -d $GLOBAL_GROUP.$N --dport 60002 -j DNAT --to $LOCAL_GROUP.1 - ip netns exec ${ROUTERS[$N]} iptables -A FORWARD -d $LOCAL_GROUP.1 -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT - fi - if [ "1" == "${R_UDP[$N]}" ] - then - ip netns exec ${ROUTERS[$N]} iptables -t nat -A PREROUTING -p udp -d $GLOBAL_GROUP.$N --dport 60002 -j DNAT --to $LOCAL_GROUP.1 - ip netns exec ${ROUTERS[$N]} iptables -A FORWARD -d $LOCAL_GROUP.1 -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT - fi -done diff --git a/src/testing/netjail_stop.sh b/src/testing/netjail_stop.sh index 08f68cf7f..abfaf3acf 100755 --- a/src/testing/netjail_stop.sh +++ b/src/testing/netjail_stop.sh @@ -1,24 +1,57 @@ -#!/bin/sh +#!/bin/bash . "./../testing/netjail_core.sh" +. "./../testing/topo.sh" set -eu set -x export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" -LOCAL_M=$1 -GLOBAL_N=$2 -NETWORK_NET=$(netjail_print_name "n" $GLOBAL_N $LOCAL_M) +filename=$1 +PREFIX=$2 -shift 2 +read_topology $filename + +declare -A NODES +declare -A NODE_LINKS + +netjail_bridge_name +NETWORK_NET=$RESULT + +for X in $(seq $KNOWN); do + netjail_node_name + KNOWN_NODES[$X]=$RESULT + netjail_node_link_bridge_name + KNOWN_LINKS[$X]=$RESULT + netjail_node_unlink_bridge ${KNOWN_LINKS[$X]} + netjail_node_clear ${KNOWN_NODES[$X]} +done for N in $(seq $GLOBAL_N); do + netjail_node_name + ROUTERS[$N]=$RESULT + netjail_node_link_bridge_name + NETWORK_LINKS[$N]=$RESULT + netjail_bridge_name + ROUTER_NETS[$N]=$RESULT + netjail_node_link_bridge_name + ROUTER_LINKS[$N]=$RESULT + + netjail_node_unlink_bridge ${ROUTER_LINKS[$N]} + for M in $(seq $LOCAL_M); do - netjail_node_clear $(netjail_print_name "N" $N $M) + netjail_node_name + NODES[$N,$M]=$RESULT + netjail_node_link_bridge_name + NODE_LINKS[$N,$M]=$RESULT + netjail_node_unlink_bridge ${NODE_LINKS[$N,$M]} + netjail_node_clear ${NODES[$N,$M]} done + - netjail_bridge_clear $(netjail_print_name "r" $N) - netjail_node_clear $(netjail_print_name "R" $N) + netjail_bridge_clear ${ROUTER_NETS[$N]} + netjail_node_unlink_bridge ${NETWORK_LINKS[$N]} + netjail_node_clear ${ROUTERS[$N]} done netjail_bridge_clear $NETWORK_NET diff --git a/src/testing/netjail_stop_v2.sh b/src/testing/netjail_stop_v2.sh deleted file mode 100755 index 6e9fd1ccc..000000000 --- a/src/testing/netjail_stop_v2.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash -. "./../testing/netjail_core_v2.sh" -. "./../testing/topo.sh" - -set -eu -set -x - -export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - -filename=$1 -PREFIX=$2 - -read_topology $filename - -declare -A NODES -declare -A NODE_LINKS - -netjail_bridge_name -NETWORK_NET=$RESULT - -for X in $(seq $KNOWN); do - netjail_node_name - KNOWN_NODES[$X]=$RESULT - netjail_node_link_bridge_name - KNOWN_LINKS[$X]=$RESULT - netjail_node_unlink_bridge ${KNOWN_LINKS[$X]} - netjail_node_clear ${KNOWN_NODES[$X]} -done - -for N in $(seq $GLOBAL_N); do - netjail_node_name - ROUTERS[$N]=$RESULT - netjail_node_link_bridge_name - NETWORK_LINKS[$N]=$RESULT - netjail_bridge_name - ROUTER_NETS[$N]=$RESULT - netjail_node_link_bridge_name - ROUTER_LINKS[$N]=$RESULT - - netjail_node_unlink_bridge ${ROUTER_LINKS[$N]} - - for M in $(seq $LOCAL_M); do - netjail_node_name - NODES[$N,$M]=$RESULT - netjail_node_link_bridge_name - NODE_LINKS[$N,$M]=$RESULT - netjail_node_unlink_bridge ${NODE_LINKS[$N,$M]} - netjail_node_clear ${NODES[$N,$M]} - done - - - netjail_bridge_clear ${ROUTER_NETS[$N]} - netjail_node_unlink_bridge ${NETWORK_LINKS[$N]} - netjail_node_clear ${ROUTERS[$N]} -done - -netjail_bridge_clear $NETWORK_NET - -echo "Done" diff --git a/src/testing/testing.c b/src/testing/testing.c index a11d404a5..766c7b084 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c @@ -34,6 +34,7 @@ #include "gnunet_arm_service.h" #include "gnunet_testing_lib.h" #include "gnunet_testing_ng_lib.h" +#include "testing_cmds.h" #define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__) @@ -1961,10 +1962,6 @@ get_connect_value (char *line, struct GNUNET_TESTING_NetjailNode *node) } GNUNET_free (copy); - LOG (GNUNET_ERROR_TYPE_ERROR, - "address_prefix %s\n", - prefix->address_prefix); - return node_connection; } @@ -2006,6 +2003,31 @@ node_connections (char *line, struct GNUNET_TESTING_NetjailNode *node) } +/** + * Create a GNUNET_CMDS_LOCAL_FINISHED message. + * + * @param rv The result of the local test as GNUNET_GenericReturnValue. + * @return The GNUNET_CMDS_LOCAL_FINISHED message. +*/ +struct GNUNET_MessageHeader * +GNUNET_TESTING_send_local_test_finished_msg (enum GNUNET_GenericReturnValue rv) +{ + struct GNUNET_CMDS_LOCAL_FINISHED *reply; + size_t msg_length; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Local test exits with status %d\n", + rv); + msg_length = sizeof(struct GNUNET_CMDS_LOCAL_FINISHED); + reply = GNUNET_new (struct GNUNET_CMDS_LOCAL_FINISHED); + reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED); + reply->header.size = htons ((uint16_t) msg_length); + reply->result = htons (rv); + + return (struct GNUNET_MessageHeader *) reply; +} + + /** * Getting the topology from file. * diff --git a/src/testing/testing_api_cmd_block_until_all_peers_started.c b/src/testing/testing_api_cmd_block_until_all_peers_started.c index 8a47a7ce0..763713e15 100644 --- a/src/testing/testing_api_cmd_block_until_all_peers_started.c +++ b/src/testing/testing_api_cmd_block_until_all_peers_started.c @@ -38,6 +38,11 @@ */ struct BlockState { + /** + * Context for our asynchronous completion. + */ + struct GNUNET_TESTING_AsyncContext ac; + /** * Flag to indicate if all peers have started. * @@ -93,6 +98,7 @@ GNUNET_TESTING_cmd_block_until_all_peers_started (const char *label, .cls = bs, .label = label, .run = &block_until_all_peers_started_run, + .ac = &bs->ac, .cleanup = &block_until_all_peers_started_cleanup }; 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 b416fa595..aeb9ffda3 100644 --- a/src/testing/testing_api_cmd_block_until_external_trigger.c +++ b/src/testing/testing_api_cmd_block_until_external_trigger.c @@ -39,9 +39,14 @@ struct BlockState { /** - * Flag to indicate if all peers have started. + * Context for our asynchronous completion. */ - unsigned int *stop_blocking; + struct GNUNET_TESTING_AsyncContext ac; + + /** + * The label of this command. + */ + const char *label; }; @@ -57,6 +62,47 @@ block_until_all_peers_started_cleanup (void *cls) GNUNET_free (bs); } +static int +block_until_external_trigger_traits (void *cls, + const void **ret, + const char *trait, + unsigned int index) +{ + 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, + }, + GNUNET_TESTING_trait_end () + }; + + return GNUNET_TESTING_get_trait (traits, + ret, + trait, + index); +} + + +/** + * 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) +{ + return cmd->traits (cmd->cls, + (const void **) ac, + "async_context", + (unsigned int) 0); +} + /** * This function does nothing but to start the cmd. @@ -66,8 +112,11 @@ static void block_until_all_peers_started_run (void *cls, struct GNUNET_TESTING_Interpreter *is) { + struct BlockState *bs = cls; + LOG (GNUNET_ERROR_TYPE_DEBUG, - "block_until_all_peers_started_run!\n"); + "block %s running!\n", + bs->label); } @@ -79,20 +128,20 @@ block_until_all_peers_started_run (void *cls, * @return command. */ struct GNUNET_TESTING_Command -GNUNET_TESTING_cmd_block_until_external_trigger (const char *label, - unsigned int * - stop_blocking) +GNUNET_TESTING_cmd_block_until_external_trigger (const char *label) { struct BlockState *bs; bs = GNUNET_new (struct BlockState); - bs->stop_blocking = stop_blocking; + bs->label = label; { struct GNUNET_TESTING_Command cmd = { .cls = bs, .label = label, .run = &block_until_all_peers_started_run, + .ac = &bs->ac, .cleanup = &block_until_all_peers_started_cleanup, + .traits = block_until_external_trigger_traits }; return cmd; diff --git a/src/testing/testing_api_cmd_netjail_start.c b/src/testing/testing_api_cmd_netjail_start.c index 9cd84cb4f..35fb90f3c 100644 --- a/src/testing/testing_api_cmd_netjail_start.c +++ b/src/testing/testing_api_cmd_netjail_start.c @@ -19,7 +19,7 @@ */ /** - * @file testing/testing_api_cmd_hello_world.c + * @file testing/testing_api_cmd_netjail_start.c * @brief Command to start the netjail script. * @author t3sserakt */ @@ -43,16 +43,16 @@ struct NetJailState // Child Wait handle struct GNUNET_ChildWaitHandle *cwh; - // Number of local nodes in each namespace. - char *local_m; - - // The number of namespaces. - char *global_n; - /** * The process id of the start script. */ struct GNUNET_OS_Process *start_proc; + + /** + * Configuration file for the test topology. + */ + char *topology_config; + }; @@ -67,6 +67,7 @@ netjail_start_cleanup (void *cls) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "netjail_start_cleanup!\n"); + if (NULL != ns->cwh) { GNUNET_wait_child_cancel (ns->cwh); @@ -105,9 +106,9 @@ child_completed_callback (void *cls, } else { - // FIXME: log status code GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Child completed with an error!\n"); + "Child failed with error %lu!\n", + exit_code); GNUNET_TESTING_async_fail (&ns->ac); } } @@ -124,13 +125,13 @@ netjail_start_run (void *cls, struct GNUNET_TESTING_Interpreter *is) { struct NetJailState *ns = cls; - char *const script_argv[] = { - NETJAIL_START_SCRIPT, - ns->local_m, - ns->global_n, - NULL - }; - unsigned int helper_check = GNUNET_OS_check_helper_binary ( + char pid[15]; + enum GNUNET_GenericReturnValue helper_check; + + // FIXME: NETJAIL_START_SCRIPT like this is bad, + // use location from share/gnunet/ of installed + // binary in case libgnunettesting is used as a lib! + helper_check = GNUNET_OS_check_helper_binary ( NETJAIL_START_SCRIPT, GNUNET_YES, NULL); @@ -141,22 +142,37 @@ netjail_start_run (void *cls, "No SUID for %s!\n", NETJAIL_START_SCRIPT); GNUNET_TESTING_interpreter_fail (is); + return; } - else if (GNUNET_NO == helper_check) + if (GNUNET_SYSERR == helper_check) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s not found!\n", NETJAIL_START_SCRIPT); GNUNET_TESTING_interpreter_fail (is); + return; } - ns->start_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR, - NULL, - NULL, - NULL, - NETJAIL_START_SCRIPT, - script_argv); + GNUNET_snprintf (pid, + sizeof (pid), + "%u", + getpid ()); + { + char *const script_argv[] = { + NETJAIL_START_SCRIPT, + ns->topology_config, + pid, + NULL + }; + ns->start_proc + = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR, + NULL, + NULL, + NULL, + NETJAIL_START_SCRIPT, + script_argv); + } ns->cwh = GNUNET_wait_child (ns->start_proc, &child_completed_callback, ns); @@ -168,20 +184,17 @@ netjail_start_run (void *cls, * Create command. * * @param label name for command. - * @param local_m Number of local nodes in each namespace. - * @param global_n The number of namespaces. + * @param topology_config Configuration file for the test topology. * @return command. */ struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_netjail_start (const char *label, - char *local_m, - char *global_n) + char *topology_config) { struct NetJailState *ns; ns = GNUNET_new (struct NetJailState); - ns->local_m = local_m; - ns->global_n = global_n; + ns->topology_config = topology_config; { struct GNUNET_TESTING_Command cmd = { .cls = ns, diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem.c b/src/testing/testing_api_cmd_netjail_start_testsystem.c index 4224a5736..a1d71c436 100644 --- a/src/testing/testing_api_cmd_netjail_start_testsystem.c +++ b/src/testing/testing_api_cmd_netjail_start_testsystem.c @@ -66,6 +66,11 @@ struct NetJailState */ struct GNUNET_TESTING_AsyncContext ac; + /** + * The complete topology information. + */ + struct GNUNET_TESTING_NetjailTopology *topology; + /** * Pointer to the return value of the test. * @@ -96,16 +101,22 @@ struct NetJailState unsigned int n_helper; /** - * Number of nodes in a network namespace. //TODO make this a unsigned int + * Number of nodes in a natted subnet. + * + */ + unsigned int local_m; + + /** + * Number of natted subnets. * */ - char *local_m; + unsigned int global_n; /** - * Number of network namespaces. //TODO make this a unsigned int + * Number of global known nodes. * */ - char *global_n; + unsigned int known; /** * The send handle for the helper @@ -271,7 +282,8 @@ netjail_exec_traits (void *cls, int GNUNET_TESTING_get_trait_helper_handles (const struct GNUNET_TESTING_Command *cmd, - struct GNUNET_HELPER_Handle ***helper) + struct GNUNET_HELPER_Handle *** + helper) { return cmd->traits (cmd->cls, (const void **) helper, @@ -301,6 +313,43 @@ clear_msg (void *cls, int result) } +static void +send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns) +{ + unsigned int total_number = ns->local_m * ns->global_n + ns->known; + struct GNUNET_CMDS_ALL_PEERS_STARTED *reply; + size_t msg_length; + struct GNUNET_HELPER_Handle *helper; + struct TestingSystemCount *tbc; + + 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; + else + tbc->count = (i - 1) * ns->local_m + j + total_number + ns->known; + + 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); + + GNUNET_array_append (ns->msg, ns->n_msg, &reply->header); + + struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send ( + helper, + &reply->header, + GNUNET_NO, + &clear_msg, + tbc); + + GNUNET_array_append (ns->shandle, ns->n_shandle, sh); +} + + /** * Functions with this signature are called whenever a * complete message is received by the tokenizer. @@ -319,6 +368,7 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message) struct TestingSystemCount *tbc = cls; struct NetJailState *ns = tbc->ns; struct HelperMessage *hp_msg; + unsigned int total_number = ns->local_m * ns->global_n + ns->known; if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type)) { @@ -328,11 +378,31 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message) message->type)) { ns->number_of_peers_started++; + if (ns->number_of_peers_started == total_number) + { + for (int i = 1; i <= ns->known; i++) + { + send_all_peers_started (0,i, ns); + } + + for (int i = 1; i <= ns->global_n; i++) + { + for (int j = 1; j <= ns->local_m; j++) + { + send_all_peers_started (i,j, ns); + } + } + ns->number_of_peers_started = 0; + } } 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) + { + GNUNET_TESTING_async_finish (&ns->ac); + } } else { @@ -343,6 +413,12 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message) hp_msg); } + + + + + + return GNUNET_OK; } @@ -354,24 +430,21 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message) static void exp_cb (void *cls) { - struct NetJailState *ns = cls; + struct TestingSystemCount *tbc = cls; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called exp_cb.\n"); - *ns->rv = 1; + GNUNET_TESTING_interpreter_fail (tbc->ns->ac.is); } /** * Function to initialize a init message for the helper. * - * @param m_char The actual node in a namespace. //TODO Change this to unsigned int - * @param n_char The actual namespace. //TODO Change this to unsigned int * @param plugin_name Name of the test case plugin the helper will load. * */ static struct GNUNET_CMDS_HelperInit * -create_helper_init_msg_ (char *m_char, - char *n_char, - const char *plugin_name) +create_helper_init_msg_ (const char *plugin_name) { struct GNUNET_CMDS_HelperInit *msg; uint16_t plugin_name_len; @@ -398,24 +471,49 @@ create_helper_init_msg_ (char *m_char, static void start_helper (struct NetJailState *ns, struct GNUNET_CONFIGURATION_Handle *config, - char *m_char, - char *n_char) + unsigned int m, + unsigned int n) { struct GNUNET_HELPER_Handle *helper; struct GNUNET_CMDS_HelperInit *msg; struct TestingSystemCount *tbc; - char *const script_argv[] = { - NETJAIL_EXEC_SCRIPT, - m_char, - n_char, - GNUNET_OS_get_libexec_binary_path ( - HELPER_CMDS_BINARY), - ns->global_n, - ns->local_m, - NULL - }; - unsigned int m = atoi (m_char); - unsigned int n = atoi (n_char); + char *m_char, *n_char, *global_n_char, *local_m_char, *known_char, *node_id, + *plugin; + pid_t pid; + unsigned int script_num; + struct GNUNET_ShortHashCode *hkey; + struct GNUNET_HashCode hc; + struct GNUNET_TESTING_NetjailTopology *topology = ns->topology; + struct GNUNET_TESTING_NetjailNode *node; + struct GNUNET_TESTING_NetjailNamespace *namespace; + + + if (0 == n) + script_num = m - 1; + else + script_num = n - 1 + (n - 1) * ns->local_m + m + ns->known; + pid = getpid (); + + GNUNET_asprintf (&m_char, "%u", m); + GNUNET_asprintf (&n_char, "%u", n); + GNUNET_asprintf (&local_m_char, "%u", ns->local_m); + GNUNET_asprintf (&global_n_char, "%u",ns->global_n); + GNUNET_asprintf (&known_char, "%u",ns->known); + GNUNET_asprintf (&node_id, "%06x-%08x\n", + pid, + script_num); + + + char *const script_argv[] = {NETJAIL_EXEC_SCRIPT, + m_char, + n_char, + GNUNET_OS_get_libexec_binary_path ( + HELPER_CMDS_BINARY), + global_n_char, + local_m_char, + node_id, + NULL}; + unsigned int helper_check = GNUNET_OS_check_helper_binary ( NETJAIL_EXEC_SCRIPT, GNUNET_YES, @@ -423,7 +521,10 @@ start_helper (struct NetJailState *ns, struct tbc = GNUNET_new (struct TestingSystemCount); tbc->ns = ns; - tbc->count = (n - 1) * atoi (ns->local_m) + m; + if (0 == n) + tbc->count = m; + else + tbc->count = (n - 1) * ns->local_m + m + ns->known; GNUNET_CONTAINER_DLL_insert (ns->tbcs_head, ns->tbcs_tail, tbc); @@ -434,18 +535,17 @@ start_helper (struct NetJailState *ns, struct GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No SUID for %s!\n", NETJAIL_EXEC_SCRIPT); - *ns->rv = 1; + GNUNET_TESTING_interpreter_fail (ns->ac.is); } else if (GNUNET_NO == helper_check) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s not found!\n", NETJAIL_EXEC_SCRIPT); - *ns->rv = 1; + GNUNET_TESTING_interpreter_fail (ns->ac.is); } - GNUNET_array_append (ns->helper, - ns->n_helper, - GNUNET_HELPER_start ( + + GNUNET_array_append (ns->helper, ns->n_helper, GNUNET_HELPER_start ( GNUNET_YES, NETJAIL_EXEC_SCRIPT, script_argv, @@ -455,9 +555,57 @@ start_helper (struct NetJailState *ns, struct helper = ns->helper[tbc->count - 1]; - msg = create_helper_init_msg_ (m_char, - n_char, - ns->plugin_name); + hkey = GNUNET_new (struct GNUNET_ShortHashCode); + + plugin = topology->plugin; + + if (0 == m) + { + + GNUNET_CRYPTO_hash (&n, sizeof(n), &hc); + memcpy (hkey, + &hc, + sizeof (*hkey)); + if (1 == GNUNET_CONTAINER_multishortmap_contains (topology->map_globals, + hkey)) + { + node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals, + hkey); + if (NULL != node->plugin) + plugin = node->plugin; + } + + } + else + { + GNUNET_CRYPTO_hash (&m, sizeof(m), &hc); + memcpy (hkey, + &hc, + sizeof (*hkey)); + if (1 == GNUNET_CONTAINER_multishortmap_contains (topology->map_namespaces, + hkey)) + { + namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces, + hkey); + GNUNET_CRYPTO_hash (&n, sizeof(n), &hc); + memcpy (hkey, + &hc, + sizeof (*hkey)); + if (1 == GNUNET_CONTAINER_multishortmap_contains (namespace->nodes, + hkey)) + { + node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes, + hkey); + if (NULL != node->plugin) + plugin = node->plugin; + } + } + + + } + + msg = create_helper_init_msg_ (plugin); + GNUNET_array_append (ns->msg, ns->n_msg, &msg->header); GNUNET_array_append (ns->shandle, ns->n_shandle, GNUNET_HELPER_send ( @@ -472,7 +620,7 @@ start_helper (struct NetJailState *ns, struct GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Send handle is NULL!\n"); GNUNET_free (msg); - *ns->rv = 1; + GNUNET_TESTING_interpreter_fail (ns->ac.is); } } @@ -488,93 +636,26 @@ static void netjail_exec_run (void *cls, struct GNUNET_TESTING_Interpreter *is) { - char str_m[12]; - char str_n[12]; struct NetJailState *ns = cls; struct GNUNET_CONFIGURATION_Handle *config = GNUNET_CONFIGURATION_create (); - for (int i = 1; i <= atoi (ns->global_n); i++) + for (int i = 1; i <= ns->known; i++) { - for (int j = 1; j <= atoi (ns->local_m); j++) - { - sprintf (str_n, "%d", i); - sprintf (str_m, "%d", j); - start_helper (ns, config, - str_m, - str_n); - } + start_helper (ns, config, + i, + 0); } -} - -/** - * This function checks on three different information. - * - * 1. Did all helpers start. This is only logged. - * 2. Did all peer start. - * In this case a GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED is send to all peers. - * 3. Did all peers finished the test case. In this case interpreter_next will be called. - * - * => FIXME: must change _completely_. - */ -static int -netjail_start_finish (void *cls, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls) -{ - unsigned int ret = GNUNET_NO; - struct NetJailState *ns = cls; - unsigned int total_number = atoi (ns->local_m) * atoi (ns->global_n); - struct GNUNET_CMDS_ALL_PEERS_STARTED *reply; - size_t msg_length; - struct GNUNET_HELPER_Handle *helper; - struct TestingSystemCount *tbc; - - if (ns->number_of_local_test_finished == total_number) + for (int i = 1; i <= ns->global_n; i++) { - ret = GNUNET_YES; - cont (cont_cls); - } - - if (ns->number_of_testsystems_started == total_number) - { - ns->number_of_testsystems_started = 0; - } - - if (ns->number_of_peers_started == total_number) - { - for (int i = 1; i <= atoi (ns->global_n); i++) + for (int j = 1; j <= ns->local_m; j++) { - for (int j = 1; j <= atoi (ns->local_m); j++) - { - 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. - tbc->count = (i - 1) * atoi (ns->local_m) + j + 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); - - GNUNET_array_append (ns->msg, ns->n_msg, &reply->header); - - struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send ( - helper, - &reply->header, - GNUNET_NO, - &clear_msg, - tbc); - - GNUNET_array_append (ns->shandle, ns->n_shandle, sh); - } + start_helper (ns, config, + j, + i); } - ns->number_of_peers_started = 0; } - return ret; } @@ -582,26 +663,24 @@ netjail_start_finish (void *cls, * Create command. * * @param label Name for the command. - * @param local_m Number of nodes in a network namespace. //TODO make this a unsigned int - * @param global_n Number of network namespaces. //TODO make this a unsigned int - * @param plugin_name Name of the test case plugin the helper will load. - * @param rv Pointer to the return value of the test. + * @param topology_config Configuration file for the test topology. * @return command. */ struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_netjail_start_testing_system (const char *label, - char *local_m, - char *global_n, - char *plugin_name, - unsigned int *rv) + const char *topology_config) { struct NetJailState *ns; + struct GNUNET_TESTING_NetjailTopology *topology = + GNUNET_TESTING_get_topo_from_file (topology_config); + ns = GNUNET_new (struct NetJailState); - ns->local_m = local_m; - ns->global_n = global_n; - ns->plugin_name = plugin_name; - ns->rv = rv; + ns->local_m = topology->nodes_m; + ns->global_n = topology->namespaces_n; + ns->known = topology->nodes_x; + ns->plugin_name = topology->plugin; + ns->topology = topology; struct GNUNET_TESTING_Command cmd = { .cls = ns, diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c b/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c deleted file mode 100644 index d319b73b4..000000000 --- a/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c +++ /dev/null @@ -1,723 +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_cmd_hello_world.c - * @brief Command to start the netjail peers. - * @author t3sserakt - */ -#include "platform.h" -#include "gnunet_testing_ng_lib.h" -#include "testing_cmds.h" - -#define NETJAIL_EXEC_SCRIPT "./../testing/netjail_exec_v2.sh" - -/** - * Struct to store messages send/received by the helper into a DLL - * - */ -struct HelperMessage -{ - - /** - * Kept in a DLL. - */ - struct HelperMessage *next; - - /** - * Kept in a DLL. - */ - struct HelperMessage *prev; - - /** - * Size of the original message. - */ - uint16_t bytes_msg; - - /* Followed by @e bytes_msg of msg.*/ -}; - - -/** - * Struct to store information handed over to callbacks. - * - */ -struct NetJailState -{ - /** - * Context for our asynchronous completion. - */ - struct GNUNET_TESTING_AsyncContext ac; - - /** - * The complete topology information. - */ - struct GNUNET_TESTING_NetjailTopology *topology; - - /** - * Pointer to the return value of the test. - * - */ - unsigned int *rv; - - /** - * Head of the DLL which stores messages received by the helper. - * - */ - struct HelperMessage *hp_messages_head; - - /** - * Tail of the DLL which stores messages received by the helper. - * - */ - struct HelperMessage *hp_messages_tail; - - /** - * Array with handles of helper processes. - */ - struct GNUNET_HELPER_Handle **helper; - - /** - * Size of the array NetJailState#helper. - * - */ - unsigned int n_helper; - - /** - * Number of nodes in a natted subnet. - * - */ - unsigned int local_m; - - /** - * Number of natted subnets. - * - */ - unsigned int global_n; - - /** - * Number of global known nodes. - * - */ - unsigned int known; - - /** - * The send handle for the helper - */ - struct GNUNET_HELPER_SendHandle **shandle; - - /** - * Size of the array NetJailState#shandle. - * - */ - unsigned int n_shandle; - - /** - * The messages send to the helper. - */ - struct GNUNET_MessageHeader **msg; - - /** - * Size of the array NetJailState#msg. - * - */ - unsigned int n_msg; - - /** - * Number of test environments started. - * - */ - unsigned int number_of_testsystems_started; - - /** - * Number of peers started. - * - */ - unsigned int number_of_peers_started; - - /** - * Number of local tests finished. - * - */ - unsigned int number_of_local_test_finished; - - /** - * Name of the test case plugin the helper will load. - * - */ - char *plugin_name; - - /** - * HEAD of the DLL containing TestingSystemCount. - * - */ - struct TestingSystemCount *tbcs_head; - - /** - * TAIL of the DLL containing TestingSystemCount. - * - */ - struct TestingSystemCount *tbcs_tail; -}; - -/** - * Struct containing the number of the test environment and the NetJailState which - * will be handed to callbacks specific to a test environment. - */ -struct TestingSystemCount -{ - /** - * Kept in a DLL. - */ - struct TestingSystemCount *next; - - /** - * Kept in a DLL. - */ - struct TestingSystemCount *prev; - - /** - * The number of the test environment. - * - */ - unsigned int count; - - /** - * Struct to store information handed over to callbacks. - * - */ - struct NetJailState *ns; -}; - -/** -* Code to clean up resource this cmd used. -* -* @param cls closure -*/ -static void -netjail_exec_cleanup (void *cls) -{ - struct NetJailState *ns = cls; - struct HelperMessage *message_pos; - struct TestingSystemCount *tbc_pos; - - while (NULL != (message_pos = ns->hp_messages_head)) - { - GNUNET_CONTAINER_DLL_remove (ns->hp_messages_head, - ns->hp_messages_tail, - message_pos); - GNUNET_free (message_pos); - } - while (NULL != (tbc_pos = ns->tbcs_head)) - { - GNUNET_CONTAINER_DLL_remove (ns->tbcs_head, - ns->tbcs_tail, - tbc_pos); - GNUNET_free (tbc_pos); - } - GNUNET_free (ns); -} - - -/** - * This function prepares an array with traits. - * - */ -static int -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; - struct HelperMessage *hp_messages_head = ns->hp_messages_head; - - - struct GNUNET_TESTING_Trait traits[] = { - { - .index = 0, - .trait_name = "helper_handles", - .ptr = (const void *) helper, - }, - { - .index = 1, - .trait_name = "hp_msgs_head", - .ptr = (const void *) hp_messages_head, - }, - GNUNET_TESTING_trait_end () - }; - - return GNUNET_TESTING_get_trait (traits, - ret, - trait, - index); -} - - -/** - * 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_v2 (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() - * - * @param cls closure - * @param result GNUNET_OK on success, - * GNUNET_NO if helper process died - * GNUNET_SYSERR during GNUNET_HELPER_stop - */ -static void -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_free (ns->msg[tbc->count - 1]); - ns->msg[tbc->count - 1] = NULL; -} - - -/** - * Functions with this signature are called whenever a - * complete message is received by the tokenizer. - * - * Do not call GNUNET_SERVER_mst_destroy in callback - * - * @param cls closure - * @param client identification of the client - * @param message the actual message - * - * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing - */ -static int -helper_mst (void *cls, const struct GNUNET_MessageHeader *message) -{ - struct TestingSystemCount *tbc = cls; - struct NetJailState *ns = tbc->ns; - struct HelperMessage *hp_msg; - - if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type)) - { - ns->number_of_testsystems_started++; - } - else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED == ntohs ( - message->type)) - { - ns->number_of_peers_started++; - } - else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED == ntohs ( - message->type)) - { - ns->number_of_local_test_finished++; - } - else - { - hp_msg = GNUNET_new (struct HelperMessage); - hp_msg->bytes_msg = message->size; - memcpy (&hp_msg[1], message, message->size); - GNUNET_CONTAINER_DLL_insert (ns->hp_messages_head, ns->hp_messages_tail, - hp_msg); - } - - return GNUNET_OK; -} - - -/** - * Callback called if there was an exception during execution of the helper. - * - */ -static void -exp_cb (void *cls) -{ - struct NetJailState *ns = cls; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called exp_cb.\n"); - *ns->rv = 1; -} - - -/** - * Function to initialize a init message for the helper. - * - * @param m_char The actual node in a namespace. //TODO Change this to unsigned int - * @param n_char The actual namespace. //TODO Change this to unsigned int - * @param plugin_name Name of the test case plugin the helper will load. - * - */ -static struct GNUNET_CMDS_HelperInit * -create_helper_init_msg_ (const char *plugin_name) -{ - struct GNUNET_CMDS_HelperInit *msg; - uint16_t plugin_name_len; - uint16_t msg_size; - - GNUNET_assert (NULL != plugin_name); - plugin_name_len = strlen (plugin_name); - msg_size = sizeof(struct GNUNET_CMDS_HelperInit) + plugin_name_len; - msg = GNUNET_malloc (msg_size); - msg->header.size = htons (msg_size); - msg->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT); - msg->plugin_name_size = htons (plugin_name_len); - GNUNET_memcpy ((char *) &msg[1], - plugin_name, - plugin_name_len); - return msg; -} - - -/** - * Function which start a single helper process. - * - */ -static void -start_helper (struct NetJailState *ns, struct - GNUNET_CONFIGURATION_Handle *config, - unsigned int m, - unsigned int n) -{ - 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; - pid_t pid; - unsigned int script_num; - struct GNUNET_ShortHashCode *hkey; - struct GNUNET_HashCode hc; - struct GNUNET_TESTING_NetjailTopology *topology = ns->topology; - struct GNUNET_TESTING_NetjailNode *node; - struct GNUNET_TESTING_NetjailNamespace *namespace; - - - if (0 == n) - script_num = m - 1; - else - script_num = n - 1 + (n - 1) * ns->local_m + m + ns->known; - pid = getpid (); - - GNUNET_asprintf (&m_char, "%u", m); - GNUNET_asprintf (&n_char, "%u", n); - GNUNET_asprintf (&local_m_char, "%u", ns->local_m); - GNUNET_asprintf (&global_n_char, "%u",ns->global_n); - GNUNET_asprintf (&known_char, "%u",ns->known); - GNUNET_asprintf (&node_id, "%06x-%08x\n", - pid, - script_num); - - - char *const script_argv[] = {NETJAIL_EXEC_SCRIPT, - m_char, - n_char, - GNUNET_OS_get_libexec_binary_path ( - HELPER_CMDS_BINARY), - global_n_char, - local_m_char, - node_id, - NULL}; - - unsigned int helper_check = GNUNET_OS_check_helper_binary ( - NETJAIL_EXEC_SCRIPT, - GNUNET_YES, - NULL); - - tbc = GNUNET_new (struct TestingSystemCount); - tbc->ns = ns; - if (0 == n) - tbc->count = m; - else - tbc->count = (n - 1) * ns->local_m + m + ns->known; - - GNUNET_CONTAINER_DLL_insert (ns->tbcs_head, ns->tbcs_tail, - tbc); - - - if (GNUNET_NO == helper_check) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "No SUID for %s!\n", - NETJAIL_EXEC_SCRIPT); - *ns->rv = 1; - } - else if (GNUNET_NO == helper_check) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "%s not found!\n", - NETJAIL_EXEC_SCRIPT); - *ns->rv = 1; - } - - GNUNET_array_append (ns->helper, ns->n_helper, GNUNET_HELPER_start ( - GNUNET_YES, - NETJAIL_EXEC_SCRIPT, - script_argv, - &helper_mst, - &exp_cb, - tbc)); - - helper = ns->helper[tbc->count - 1]; - - hkey = GNUNET_new (struct GNUNET_ShortHashCode); - - plugin = topology->plugin; - - if (0 == m) - { - - GNUNET_CRYPTO_hash (&n, sizeof(n), &hc); - memcpy (hkey, - &hc, - sizeof (*hkey)); - if (1 == GNUNET_CONTAINER_multishortmap_contains (topology->map_globals, - hkey)) - { - node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals, - hkey); - if (NULL != node->plugin) - plugin = node->plugin; - } - - } - else - { - GNUNET_CRYPTO_hash (&m, sizeof(m), &hc); - memcpy (hkey, - &hc, - sizeof (*hkey)); - if (1 == GNUNET_CONTAINER_multishortmap_contains (topology->map_namespaces, - hkey)) - { - namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces, - hkey); - GNUNET_CRYPTO_hash (&n, sizeof(n), &hc); - memcpy (hkey, - &hc, - sizeof (*hkey)); - if (1 == GNUNET_CONTAINER_multishortmap_contains (namespace->nodes, - hkey)) - { - node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes, - hkey); - if (NULL != node->plugin) - plugin = node->plugin; - } - } - - - } - - msg = create_helper_init_msg_ (plugin); - - 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)); - - if (NULL == ns->shandle[tbc->count - 1]) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Send handle is NULL!\n"); - GNUNET_free (msg); - *ns->rv = 1; - } -} - - -/** -* This function starts a helper process for each node. -* -* @param cls closure. -* @param cmd CMD being run. -* @param is interpreter state. -*/ -static void -netjail_exec_run (void *cls, - struct GNUNET_TESTING_Interpreter *is) -{ - struct NetJailState *ns = cls; - struct GNUNET_CONFIGURATION_Handle *config = - GNUNET_CONFIGURATION_create (); - - for (int i = 1; i <= ns->known; i++) - { - start_helper (ns, config, - i, - 0); - } - - for (int i = 1; i <= ns->global_n; i++) - { - for (int j = 1; j <= ns->local_m; j++) - { - start_helper (ns, config, - j, - i); - } - } -} - - -static void -send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns) -{ - unsigned int total_number = ns->local_m * ns->global_n + ns->known; - struct GNUNET_CMDS_ALL_PEERS_STARTED *reply; - size_t msg_length; - struct GNUNET_HELPER_Handle *helper; - struct TestingSystemCount *tbc; - - 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; - else - tbc->count = (i - 1) * ns->local_m + j + total_number + ns->known; - - 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); - - GNUNET_array_append (ns->msg, ns->n_msg, &reply->header); - - struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send ( - helper, - &reply->header, - GNUNET_NO, - &clear_msg, - tbc); - - GNUNET_array_append (ns->shandle, ns->n_shandle, sh); -} - - -/** - * This function checks on three different information. - * - * 1. Did all helpers start. This is only logged. - * 2. Did all peer start. - * In this case a GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED is send to all peers. - * 3. Did all peers finished the test case. In this case interpreter_next will be called. - * - */ -// FIXME: must change completely! -static int -netjail_start_finish (void *cls, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls) -{ - unsigned int ret = GNUNET_NO; - struct NetJailState *ns = cls; - unsigned int total_number = ns->local_m * ns->global_n + ns->known; - - - if (ns->number_of_local_test_finished == total_number) - { - ret = GNUNET_YES; - cont (cont_cls); - } - - if (ns->number_of_testsystems_started == total_number) - { - ns->number_of_testsystems_started = 0; - } - - if (ns->number_of_peers_started == total_number) - { - for (int i = 1; i <= ns->known; i++) - { - send_all_peers_started (0,i, ns); - } - - for (int i = 1; i <= ns->global_n; i++) - { - for (int j = 1; j <= ns->local_m; j++) - { - send_all_peers_started (i,j, ns); - } - } - ns->number_of_peers_started = 0; - } - return ret; -} - - -/** - * Create command. - * - * @param label Name for the command. - * @param topology_config Configuration file for the test topology. - * @param rv Pointer to the return value of the test. - * @return command. - */ -struct GNUNET_TESTING_Command -GNUNET_TESTING_cmd_netjail_start_testing_system_v2 (const char *label, - const char *topology_config, - unsigned int *rv) -{ - struct NetJailState *ns; - - struct GNUNET_TESTING_NetjailTopology *topology = - GNUNET_TESTING_get_topo_from_file (topology_config); - - ns = GNUNET_new (struct NetJailState); - ns->rv = rv; - ns->local_m = topology->nodes_m; - ns->global_n = topology->namespaces_n; - ns->known = topology->nodes_x; - ns->plugin_name = topology->plugin; - ns->topology = topology; - - struct GNUNET_TESTING_Command cmd = { - .cls = ns, - .label = label, - .run = &netjail_exec_run, - .ac = &ns->ac, - .cleanup = &netjail_exec_cleanup, - .traits = &netjail_exec_traits - }; - - return cmd; -} diff --git a/src/testing/testing_api_cmd_netjail_start_v2.c b/src/testing/testing_api_cmd_netjail_start_v2.c deleted file mode 100644 index 7567c2981..000000000 --- a/src/testing/testing_api_cmd_netjail_start_v2.c +++ /dev/null @@ -1,209 +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_cmd_netjail_start_v2.c - * @brief Command to start the netjail script. - * @author t3sserakt - */ -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_testing_ng_lib.h" - -#define NETJAIL_START_SCRIPT "./../testing/netjail_start_v2.sh" - -/** - * Struct to hold information for callbacks. - * - */ -struct NetJailState -{ - /** - * Context for our asynchronous completion. - */ - struct GNUNET_TESTING_AsyncContext ac; - - // Child Wait handle - struct GNUNET_ChildWaitHandle *cwh; - - /** - * Configuration file for the test topology. - */ - char *topology_config; - - /** - * The process id of the start script. - */ - struct GNUNET_OS_Process *start_proc; - -}; - - -/** - * The cleanup function of this cmd frees resources the cmd allocated. - * - */ -static void -netjail_start_cleanup (void *cls) -{ - struct NetJailState *ns = cls; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "netjail_start_cleanup!\n"); - - if (NULL != ns->cwh) - { - GNUNET_wait_child_cancel (ns->cwh); - ns->cwh = NULL; - } - if (NULL != ns->start_proc) - { - GNUNET_assert (0 == - GNUNET_OS_process_kill (ns->start_proc, - SIGKILL)); - GNUNET_assert (GNUNET_OK == - GNUNET_OS_process_wait (ns->start_proc)); - GNUNET_OS_process_destroy (ns->start_proc); - ns->start_proc = NULL; - } - GNUNET_free (ns); -} - - -/** - * Callback which will be called if the setup script finished. - * - */ -static void -child_completed_callback (void *cls, - enum GNUNET_OS_ProcessStatusType type, - long unsigned int exit_code) -{ - struct NetJailState *ns = cls; - - GNUNET_OS_process_destroy (ns->start_proc); - ns->start_proc = NULL; - if (0 == exit_code) - { - GNUNET_TESTING_async_finish (&ns->ac); - } - else - { - // FIXME: log status code - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Child completed with an error!\n"); - GNUNET_TESTING_async_fail (&ns->ac); - } -} - - -/** -* The run method starts the script which setup the network namespaces. -* -* @param cls closure. -* @param is interpreter state. -*/ -static void -netjail_start_run (void *cls, - struct GNUNET_TESTING_Interpreter *is) -{ - struct NetJailState *ns = cls; - char pid[15]; - enum GNUNET_GenericReturnValue helper_check; - - // FIXME: NETJAIL_START_SCRIPT like this is bad, - // use location from share/gnunet/ of installed - // binary in case libgnunettesting is used as a lib! - helper_check = GNUNET_OS_check_helper_binary ( - NETJAIL_START_SCRIPT, - GNUNET_YES, - NULL); - - if (GNUNET_NO == helper_check) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "No SUID for %s!\n", - NETJAIL_START_SCRIPT); - GNUNET_TESTING_interpreter_fail (is); - return; - } - if (GNUNET_SYSERR == helper_check) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "%s not found!\n", - NETJAIL_START_SCRIPT); - GNUNET_TESTING_interpreter_fail (is); - return; - } - - GNUNET_snprintf (pid, - sizeof (pid), - "%u", - getpid ()); - { - char *const script_argv[] = { - NETJAIL_START_SCRIPT, - ns->topology_config, - pid, - NULL - }; - - ns->start_proc - = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR, - NULL, - NULL, - NULL, - NETJAIL_START_SCRIPT, - script_argv); - } - ns->cwh = GNUNET_wait_child (ns->start_proc, - &child_completed_callback, - ns); - GNUNET_break (NULL != ns->cwh); -} - - -/** - * Create command. - * - * @param label name for command. - * @param topology_config Configuration file for the test topology. - * @return command. - */ -struct GNUNET_TESTING_Command -GNUNET_TESTING_cmd_netjail_start_v2 (const char *label, - char *topology_config) -{ - struct NetJailState *ns; - - ns = GNUNET_new (struct NetJailState); - ns->topology_config = topology_config; - { - struct GNUNET_TESTING_Command cmd = { - .cls = ns, - .label = label, - .run = &netjail_start_run, - .ac = &ns->ac, - .cleanup = &netjail_start_cleanup - }; - - return cmd; - } -} diff --git a/src/testing/testing_api_cmd_netjail_stop.c b/src/testing/testing_api_cmd_netjail_stop.c index 8c78b5e93..5033272a3 100644 --- a/src/testing/testing_api_cmd_netjail_stop.c +++ b/src/testing/testing_api_cmd_netjail_stop.c @@ -31,7 +31,7 @@ #define NETJAIL_STOP_SCRIPT "./../testing/netjail_stop.sh" // Child Wait handle -struct GNUNET_ChildWaitHandle *cwh; +static struct GNUNET_ChildWaitHandle *cwh; /** * Struct to hold information for callbacks. @@ -44,11 +44,10 @@ struct NetJailState */ struct GNUNET_TESTING_AsyncContext ac; - // Number of local nodes in each namespace. - char *local_m; - - // The number of namespaces. - char *global_n; + /** + * Configuration file for the test topology. + */ + char *topology_config; /** * The process id of the start script. @@ -85,20 +84,6 @@ netjail_stop_cleanup (void *cls) } -/** - * Trait function of this cmd does nothing. - * - */ -static enum GNUNET_GenericReturnValue -netjail_stop_traits (void *cls, - const void **ret, - const char *trait, - unsigned int index) -{ - return GNUNET_NO; -} - - /** * Callback which will be called if the setup script finished. * @@ -110,7 +95,7 @@ child_completed_callback (void *cls, { struct NetJailState *ns = cls; - cwh = NULL; + cwh = NULL; // WTF? globals!?!?! GNUNET_OS_process_destroy (ns->stop_proc); ns->stop_proc = NULL; if (0 == exit_code) @@ -119,7 +104,6 @@ child_completed_callback (void *cls, } else { - // FIXME: log exit code! GNUNET_TESTING_async_fail (&ns->ac); } } @@ -129,7 +113,6 @@ child_completed_callback (void *cls, * The run method starts the script which deletes the network namespaces. * * @param cls closure. -* @param cmd CMD being run. * @param is interpreter state. */ static void @@ -137,12 +120,15 @@ netjail_stop_run (void *cls, struct GNUNET_TESTING_Interpreter *is) { struct NetJailState *ns = cls; - char *const script_argv[] = { - NETJAIL_STOP_SCRIPT, - ns->local_m, - ns->global_n, - NULL - }; + char *pid; + + GNUNET_asprintf (&pid, + "%u", + getpid ()); + char *const script_argv[] = {NETJAIL_STOP_SCRIPT, + ns->topology_config, + pid, + NULL}; unsigned int helper_check = GNUNET_OS_check_helper_binary ( NETJAIL_STOP_SCRIPT, GNUNET_YES, @@ -174,28 +160,24 @@ netjail_stop_run (void *cls, &child_completed_callback, ns); GNUNET_break (NULL != cwh); - } struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_netjail_stop (const char *label, - char *local_m, - char *global_n) + char *topology_config) { struct NetJailState *ns; ns = GNUNET_new (struct NetJailState); - ns->local_m = local_m; - ns->global_n = global_n; + ns->topology_config = topology_config; { struct GNUNET_TESTING_Command cmd = { .cls = ns, .label = label, .run = &netjail_stop_run, .ac = &ns->ac, - .cleanup = &netjail_stop_cleanup, - .traits = &netjail_stop_traits + .cleanup = &netjail_stop_cleanup }; return cmd; diff --git a/src/testing/testing_api_cmd_netjail_stop_testsystem.c b/src/testing/testing_api_cmd_netjail_stop_testsystem.c index 04b0e4e94..d3754153d 100644 --- a/src/testing/testing_api_cmd_netjail_stop_testsystem.c +++ b/src/testing/testing_api_cmd_netjail_stop_testsystem.c @@ -42,9 +42,15 @@ struct StopHelperState */ struct GNUNET_HELPER_Handle **helper; - char *local_m; + unsigned int local_m; - char *global_n; + unsigned int global_n; + + /** + * Number of global known nodes. + * + */ + unsigned int known; }; @@ -57,6 +63,7 @@ struct StopHelperState static void stop_testing_system_cleanup (void *cls) { + } @@ -64,13 +71,13 @@ stop_testing_system_cleanup (void *cls) * Trait function of this cmd does nothing. * */ -static enum GNUNET_GenericReturnValue +static int stop_testing_system_traits (void *cls, const void **ret, const char *trait, unsigned int index) { - return GNUNET_NO; + return GNUNET_OK; } @@ -88,17 +95,30 @@ 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 ( - is, - shs->helper_start_label); + start_helper_cmd = GNUNET_TESTING_interpreter_lookup_command (NULL, + shs-> + helper_start_label); GNUNET_TESTING_get_trait_helper_handles (start_helper_cmd, &helper); - for (int i = 1; i <= atoi (shs->global_n); i++) + for (int i = 1; i <= shs->known; i++) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "i: %u\n", + i); + GNUNET_HELPER_stop (helper[i - 1], + GNUNET_YES); + } + + for (int i = 1; i <= shs->global_n; i++) { - for (int j = 1; j <= atoi (shs->local_m); j++) + for (int j = 1; j <= shs->local_m; j++) { - GNUNET_HELPER_stop (helper[(i - 1) * atoi (shs->local_m) + j - 1], + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "i: %u j: %u\n", + i, + j); + GNUNET_HELPER_stop (helper[(i - 1) * shs->local_m + j + shs->known - 1], GNUNET_YES); } } @@ -107,34 +127,35 @@ stop_testing_system_run (void *cls, /** * Create command. - * @param helper_start_label label of the cmd to start the test system. + * * @param label name for command. - * @param . - * @param local_m Number of nodes in a network namespace. //TODO make this a unsigned int - * @param global_n Number of network namespaces. //TODO make this a unsigned int + * @param helper_start_label label of the cmd to start the test system. + * @param topology_config Configuration file for the test topology. * @return command. */ struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_stop_testing_system (const char *label, const char *helper_start_label, - char *local_m, - char *global_n) + const char *topology_config) { struct StopHelperState *shs; + struct GNUNET_TESTING_NetjailTopology *topology = + GNUNET_TESTING_get_topo_from_file (topology_config); + shs = GNUNET_new (struct StopHelperState); shs->helper_start_label = helper_start_label; - shs->local_m = local_m; - shs->global_n = global_n; - { - struct GNUNET_TESTING_Command cmd = { - .cls = shs, - .label = label, - .run = &stop_testing_system_run, - .cleanup = &stop_testing_system_cleanup, - .traits = &stop_testing_system_traits - }; - - return cmd; - } + shs->local_m = topology->nodes_m; + shs->global_n = topology->namespaces_n; + shs->known = topology->nodes_x; + + struct GNUNET_TESTING_Command cmd = { + .cls = shs, + .label = label, + .run = &stop_testing_system_run, + .cleanup = &stop_testing_system_cleanup, + .traits = &stop_testing_system_traits + }; + + return cmd; } diff --git a/src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c b/src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c deleted file mode 100644 index 65eb85d9a..000000000 --- a/src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c +++ /dev/null @@ -1,141 +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_cmd_hello_world.c - * @brief Command to start the netjail peers. - * @author t3sserakt - */ -#include "platform.h" -#include "gnunet_testing_ng_lib.h" -#include "testing_cmds.h" - - -/** - * Struct to store information handed over to callbacks. - * - */ -struct StopHelperState -{ - - const char *helper_start_label; - - /** - * The process handle - */ - struct GNUNET_HELPER_Handle **helper; - - unsigned int local_m; - - unsigned int global_n; -}; - - -/** -* Code to clean up resource this cmd used. -* -* @param cls closure -*/ -static void -stop_testing_system_cleanup (void *cls) -{ - -} - - -/** - * Trait function of this cmd does nothing. - * - */ -static enum GNUNET_GenericReturnValue -stop_testing_system_traits (void *cls, - const void **ret, - const char *trait, - unsigned int index) -{ - return GNUNET_NO; -} - - -/** -* This function stops the helper process for each node. -* -* @param cls closure. -* @param is interpreter state. -*/ -static void -stop_testing_system_run (void *cls, - struct GNUNET_TESTING_Interpreter *is) -{ - struct StopHelperState *shs = cls; - struct GNUNET_HELPER_Handle **helper; - const struct GNUNET_TESTING_Command *start_helper_cmd; - - start_helper_cmd = GNUNET_TESTING_interpreter_lookup_command ( - is, - shs->helper_start_label); - GNUNET_TESTING_get_trait_helper_handles (start_helper_cmd, - &helper); - - for (int i = 1; i <= shs->global_n; i++) - { - for (int j = 1; j <= shs->local_m; j++) - { - GNUNET_HELPER_stop (helper[(i - 1) * shs->local_m + j - 1], - GNUNET_YES); - } - } -} - - -/** - * Create command. - * - * @param label name for command. - * @param helper_start_label label of the cmd to start the test system. - * @param topology_config Configuration file for the test topology. - * @return command. - */ -struct GNUNET_TESTING_Command -GNUNET_TESTING_cmd_stop_testing_system_v2 (const char *label, - const char *helper_start_label, - const char *topology_config) -{ - struct StopHelperState *shs; - - struct GNUNET_TESTING_NetjailTopology *topology = - GNUNET_TESTING_get_topo_from_file (topology_config); - - shs = GNUNET_new (struct StopHelperState); - shs->helper_start_label = helper_start_label; - shs->local_m = topology->nodes_m; - shs->global_n = topology->namespaces_n; - { - struct GNUNET_TESTING_Command cmd = { - .cls = shs, - .label = label, - .run = &stop_testing_system_run, - .cleanup = &stop_testing_system_cleanup, - .traits = &stop_testing_system_traits - }; - - return cmd; - } -} diff --git a/src/testing/testing_api_cmd_netjail_stop_v2.c b/src/testing/testing_api_cmd_netjail_stop_v2.c deleted file mode 100644 index a0e2657cb..000000000 --- a/src/testing/testing_api_cmd_netjail_stop_v2.c +++ /dev/null @@ -1,185 +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_cmd_netjail_stop_v2.c - * @brief Command to stop the netjail script. - * @author t3sserakt - */ -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_testing_ng_lib.h" - - -#define NETJAIL_STOP_SCRIPT "./../testing/netjail_stop_v2.sh" - -// Child Wait handle -static struct GNUNET_ChildWaitHandle *cwh; - -/** - * Struct to hold information for callbacks. - * - */ -struct NetJailState -{ - /** - * Context for our asynchronous completion. - */ - struct GNUNET_TESTING_AsyncContext ac; - - /** - * Configuration file for the test topology. - */ - char *topology_config; - - /** - * The process id of the start script. - */ - struct GNUNET_OS_Process *stop_proc; - -}; - - -/** - * The cleanup function of this cmd frees resources the cmd allocated. - * - */ -static void -netjail_stop_cleanup (void *cls) -{ - struct NetJailState *ns = cls; - - if (NULL != cwh) - { - GNUNET_wait_child_cancel (cwh); - cwh = NULL; - } - if (NULL != ns->stop_proc) - { - GNUNET_assert (0 == - GNUNET_OS_process_kill (ns->stop_proc, - SIGKILL)); - GNUNET_assert (GNUNET_OK == - GNUNET_OS_process_wait (ns->stop_proc)); - GNUNET_OS_process_destroy (ns->stop_proc); - ns->stop_proc = NULL; - } -} - - -/** - * Callback which will be called if the setup script finished. - * - */ -static void -child_completed_callback (void *cls, - enum GNUNET_OS_ProcessStatusType type, - long unsigned int exit_code) -{ - struct NetJailState *ns = cls; - - cwh = NULL; // WTF? globals!?!?! - GNUNET_OS_process_destroy (ns->stop_proc); - ns->stop_proc = NULL; - if (0 == exit_code) - { - GNUNET_TESTING_async_finish (&ns->ac); - } - else - { - GNUNET_TESTING_async_fail (&ns->ac); - } -} - - -/** -* The run method starts the script which deletes the network namespaces. -* -* @param cls closure. -* @param is interpreter state. -*/ -static void -netjail_stop_run (void *cls, - struct GNUNET_TESTING_Interpreter *is) -{ - struct NetJailState *ns = cls; - char *pid; - - GNUNET_asprintf (&pid, - "%u", - getpid ()); - char *const script_argv[] = {NETJAIL_STOP_SCRIPT, - ns->topology_config, - pid, - NULL}; - unsigned int helper_check = GNUNET_OS_check_helper_binary ( - NETJAIL_STOP_SCRIPT, - GNUNET_YES, - NULL); - - if (GNUNET_NO == helper_check) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "No SUID for %s!\n", - NETJAIL_STOP_SCRIPT); - GNUNET_TESTING_interpreter_fail (is); - } - else if (GNUNET_NO == helper_check) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "%s not found!\n", - NETJAIL_STOP_SCRIPT); - GNUNET_TESTING_interpreter_fail (is); - } - - ns->stop_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR, - NULL, - NULL, - NULL, - NETJAIL_STOP_SCRIPT, - script_argv); - - cwh = GNUNET_wait_child (ns->stop_proc, - &child_completed_callback, - ns); - GNUNET_break (NULL != cwh); -} - - -struct GNUNET_TESTING_Command -GNUNET_TESTING_cmd_netjail_stop_v2 (const char *label, - char *topology_config) -{ - struct NetJailState *ns; - - ns = GNUNET_new (struct NetJailState); - ns->topology_config = topology_config; - { - struct GNUNET_TESTING_Command cmd = { - .cls = ns, - .label = label, - .run = &netjail_stop_run, - .ac = &ns->ac, - .cleanup = &netjail_stop_cleanup - }; - - return cmd; - } -} diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c index e0cb3fcda..3727d2543 100644 --- a/src/testing/testing_api_loop.c +++ b/src/testing/testing_api_loop.c @@ -313,8 +313,12 @@ interpreter_run (void *cls) } cmd->run (cmd->cls, is); - if ( (cmd->asynchronous_finish) && - (NULL != cmd->ac->cont) ) + if (NULL == cmd->ac) + { + interpreter_next (is); + } + else if ( (cmd->asynchronous_finish) && + (NULL != cmd->ac->cont) ) { cmd->ac->cont = NULL; interpreter_next (is); diff --git a/src/testing/testing_cmds.h b/src/testing/testing_cmds.h index 7a5860aea..09e4f2dcb 100644 --- a/src/testing/testing_cmds.h +++ b/src/testing/testing_cmds.h @@ -83,6 +83,8 @@ struct GNUNET_CMDS_LOCAL_FINISHED * Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED */ struct GNUNET_MessageHeader header; + + enum GNUNET_GenericReturnValue result; }; GNUNET_NETWORK_STRUCT_END diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index a539f3f25..0df422976 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am @@ -159,14 +159,9 @@ libgnunettransporttesting_la_LDFLAGS = \ libgnunettransporttesting2_la_SOURCES = \ transport_api_cmd_connecting_peers.c \ - transport_api_cmd_connecting_peers_v2.c \ - transport_api_cmd_connecting_peers_v3.c \ transport_api_cmd_start_peer.c \ - transport_api_cmd_start_peer_v2.c \ - transport_api_cmd_start_peer_v3.c \ transport_api_cmd_stop_peer.c \ transport_api_cmd_send_simple.c \ - transport_api_cmd_send_simple_v2.c \ transport-testing2.c transport-testing2.h \ transport-testing-cmds.h \ transport-testing-filenames2.c \ @@ -394,7 +389,6 @@ plugin_LTLIBRARIES = \ $(WLAN_PLUGIN_LA) \ $(BT_PLUGIN_LA) \ libgnunet_test_transport_plugin_cmd_simple_send.la \ - libgnunet_test_transport_plugin_cmd_simple_send_v2.la \ libgnunet_test_transport_plugin_cmd_udp_backchannel.la libgnunet_test_transport_plugin_cmd_udp_backchannel_la_SOURCES = \ @@ -431,23 +425,6 @@ libgnunet_test_transport_plugin_cmd_simple_send_la_LIBADD = \ libgnunet_test_transport_plugin_cmd_simple_send_la_LDFLAGS = \ $(GN_PLUGIN_LDFLAGS) -libgnunet_test_transport_plugin_cmd_simple_send_v2_la_SOURCES = \ - test_transport_plugin_cmd_simple_send_v2.c -libgnunet_test_transport_plugin_cmd_simple_send_v2_la_LIBADD = \ - libgnunettransporttesting2.la \ - libgnunettransportapplication.la \ - libgnunettransportcore.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - $(top_builddir)/src/peerstore/libgnunetpeerstore.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la \ - $(top_builddir)/src/hello/libgnunethello.la \ - $(top_builddir)/src/ats/libgnunetats.la \ - $(top_builddir)/src/arm/libgnunetarm.la \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(LTLIBINTL) -libgnunet_test_transport_plugin_cmd_simple_send_v2_la_LDFLAGS = \ - $(GN_PLUGIN_LDFLAGS) - if HAVE_EXPERIMENTAL plugin_LTLIBRARIES += \ libgnunet_plugin_transport_udp.la @@ -593,8 +570,6 @@ libgnunet_plugin_transport_https_server_la_CFLAGS = \ $(MHD_CFLAGS) $(AM_CFLAGS) -DBUILD_HTTPS check_PROGRAMS = \ - test_transport_simple_send \ - test_transport_simple_send_v2 \ test_transport_start_with_config \ test_transport_address_switch_tcp \ test_transport_testing_startstop \ @@ -743,8 +718,6 @@ test_transport_api_slow_ats endif if HAVE_EXPERIMENTAL TESTS += \ - test_transport_simple_send \ - test_transport_simple_send_v2 \ test_transport_start_with_config \ test_transport_address_switch_udp \ test_plugin_udp \ @@ -765,7 +738,6 @@ endif check_SCRIPTS= \ test_transport_simple_send.sh \ - test_transport_simple_send_v2.sh \ test_transport_udp_backchannel.sh test_transport_start_with_config_SOURCES = \ @@ -778,26 +750,6 @@ test_transport_start_with_config_LDADD = \ libgnunettransportcore.la \ libgnunettransporttesting2.la -test_transport_simple_send_SOURCES = \ - test_transport_simple_send.c -test_transport_simple_send_LDADD = \ - $(top_builddir)/src/testing/libgnunettesting.la \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testbed/libgnunettestbed.la \ - $(top_builddir)/src/hello/libgnunethello.la \ - libgnunettransportcore.la \ - libgnunettransporttesting2.la - -test_transport_simple_send_v2_SOURCES = \ - test_transport_simple_send_v2.c -test_transport_simple_send_v2_LDADD = \ - $(top_builddir)/src/testing/libgnunettesting.la \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testbed/libgnunettestbed.la \ - $(top_builddir)/src/hello/libgnunethello.la \ - libgnunettransportcore.la \ - libgnunettransporttesting2.la - test_transport_testing_startstop_SOURCES = \ test_transport_testing_startstop.c test_transport_testing_startstop_LDADD = \ diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c b/src/transport/test_transport_plugin_cmd_simple_send.c index 21167415d..5384bf24d 100644 --- a/src/transport/test_transport_plugin_cmd_simple_send.c +++ b/src/transport/test_transport_plugin_cmd_simple_send.c @@ -37,28 +37,34 @@ #define BASE_DIR "testdir" -/** - * The name for a specific test environment directory. - * - */ -char *testdir; +#define TOPOLOGY_CONFIG "test_transport_simple_send_topo.conf" -/** - * The name for the configuration file of the specific node. - * - */ -char *cfgname; +struct TestState +{ + /** + * Callback to write messages to the master loop. + * + */ + TESTING_CMD_HELPER_write_cb write_message; -/** - * Flag indicating if all peers have been started. - * - */ -unsigned int are_all_peers_started; + /** + * The name for a specific test environment directory. + * + */ + char *testdir; -/** - * Flag indicating a received message. - */ -unsigned int message_received; + /** + * The name for the configuration file of the specific node. + * + */ + char *cfgname; +}; + +static struct GNUNET_TESTING_Command block_send; + +static struct GNUNET_TESTING_Command block_receive; + +static struct GNUNET_TESTING_Command connect_peers; /** @@ -83,7 +89,14 @@ static void handle_test (void *cls, const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) { - message_received = GNUNET_YES; + struct GNUNET_TESTING_AsyncContext *ac; + + 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); } @@ -94,7 +107,62 @@ handle_test (void *cls, static void all_peers_started () { - are_all_peers_started = GNUNET_YES; + struct GNUNET_TESTING_AsyncContext *ac; + + GNUNET_TESTING_get_trait_async_context (&block_send, + &ac); + if ((NULL == ac) || (NULL == ac->cont)) + GNUNET_TESTING_async_fail (ac); + else + GNUNET_TESTING_async_finish (ac); +} + + +/** + * Function called with the final result of the test. + * + * @param cls the `struct MainParams` + * @param rv #GNUNET_OK if the test passed + */ +static void +handle_result (void *cls, + enum GNUNET_GenericReturnValue rv) +{ + struct TestState *ts = cls; + struct GNUNET_MessageHeader *reply; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Local test exits with status %d\n", + rv); + reply = GNUNET_TESTING_send_local_test_finished_msg (rv); + + ts->write_message (reply, + ntohs (reply->size)); + GNUNET_free (ts->testdir); + GNUNET_free (ts->cfgname); + GNUNET_free (ts); +} + + +/** + * Callback from start peer cmd for signaling a peer got connected. + * + */ +static void * +notify_connect (void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_MQ_Handle *mq) +{ + struct ConnectPeersState *cps; + + GNUNET_TESTING_get_trait_connect_peer_state (&connect_peers, + &cps); + void *ret = NULL; + + cps->notify_connect (cps, + peer, + mq); + return ret; } @@ -116,24 +184,46 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, char *local_m) { - GNUNET_asprintf (&cfgname, - "test_transport_api2_tcp_node%s.conf", - "1"); + unsigned int n_int; + unsigned int m_int; + unsigned int local_m_int; + unsigned int num; + struct TestState *ts = GNUNET_new (struct TestState); + struct GNUNET_TESTING_NetjailTopology *topology = + GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG); + + if (0 == m_int) + num = n_int; + else + 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); + + + + sscanf (m, "%u", &m_int); + sscanf (n, "%u", &n_int); + sscanf (local_m, "%u", &local_m_int); + + GNUNET_asprintf (&ts->cfgname, + "test_transport_api2_tcp_node1.conf"); LOG (GNUNET_ERROR_TYPE_ERROR, "plugin cfgname: %s\n", - cfgname); + ts->cfgname); LOG (GNUNET_ERROR_TYPE_ERROR, "node ip: %s\n", node_ip); - LOG (GNUNET_ERROR_TYPE_ERROR, - "m: %s n: %s\n", - m, - n); - - GNUNET_asprintf (&testdir, + GNUNET_asprintf (&ts->testdir, "%s%s%s", BASE_DIR, m, @@ -143,50 +233,38 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, GNUNET_MQ_hd_var_size (test, GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, struct GNUNET_TRANSPORT_TESTING_TestMessage, - NULL), + ts), GNUNET_MQ_handler_end () }; struct GNUNET_TESTING_Command commands[] = { GNUNET_TESTING_cmd_system_create ("system-create", - testdir), + ts->testdir), GNUNET_TRANSPORT_cmd_start_peer ("start-peer", "system-create", - m, - n, - local_m, + num, node_ip, handlers, - cfgname), + ts->cfgname, + notify_connect), GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready", write_message), - GNUNET_TESTING_cmd_block_until_all_peers_started ("block", - &are_all_peers_started), - GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers", - "start-peer", - "system-create", - (atoi (n) - 1) * atoi (local_m) + atoi ( - m)), + block_send, + connect_peers, GNUNET_TRANSPORT_cmd_send_simple ("send-simple", - m, - n, - (atoi (n) - 1) * atoi (local_m) + atoi ( - m), - "start-peer"), - GNUNET_TESTING_cmd_block_until_external_trigger ("block-receive", - &message_received), + "start-peer", + num), + block_receive, GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer", "start-peer"), GNUNET_TESTING_cmd_system_destroy ("system-destroy", - "system-create"), - GNUNET_TESTING_cmd_local_test_finished ("local-test-finished", - write_message) + "system-create") }; GNUNET_TESTING_run (commands, GNUNET_TIME_UNIT_FOREVER_REL, - NULL, /* FIXME: will crash */ - NULL); + &handle_result, + ts); } @@ -221,8 +299,6 @@ libgnunet_test_transport_plugin_cmd_simple_send_done (void *cls) struct GNUNET_TESTING_PluginFunctions *api = cls; GNUNET_free (api); - GNUNET_free (testdir); - GNUNET_free (cfgname); return NULL; } diff --git a/src/transport/test_transport_plugin_cmd_simple_send_v2.c b/src/transport/test_transport_plugin_cmd_simple_send_v2.c deleted file mode 100644 index 98e9d5fca..000000000 --- a/src/transport/test_transport_plugin_cmd_simple_send_v2.c +++ /dev/null @@ -1,235 +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 testbed/plugin_cmd_simple_send.c - * @brief a plugin to provide the API for running test cases. - * @author t3sserakt - */ -#include "platform.h" -#include "gnunet_testing_ng_lib.h" -#include "gnunet_util_lib.h" -#include "gnunet_transport_application_service.h" -#include "transport-testing2.h" -#include "transport-testing-cmds.h" - -/** - * Generic logging shortcut - */ -#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) - -#define BASE_DIR "testdir" - -#define TOPOLOGY_CONFIG "test_transport_simple_send_topo.conf" - -/** - * The name for a specific test environment directory. - * - */ -char *testdir; - -/** - * The name for the configuration file of the specific node. - * - */ -char *cfgname; - -/** - * Flag indicating if all peers have been started. - * - */ -unsigned int are_all_peers_started; - -/** - * Flag indicating a received message. - */ -unsigned int message_received; - - -/** - * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being - * received. - * - */ -static int -check_test (void *cls, - const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) -{ - return GNUNET_OK; -} - - -/** - * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE - * being received. - * - */ -static void -handle_test (void *cls, - const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) -{ - message_received = GNUNET_YES; -} - - -/** - * Callback to set the flag indicating all peers started. Will be called via the plugin api. - * - */ -static void -all_peers_started () -{ - are_all_peers_started = GNUNET_YES; -} - - -/** - * Function to start a local test case. - * - * @param write_message Callback to send a message to the master loop. - * @param router_ip Global address of the network namespace. - * @param node_ip Local address of a node i a network namespace. - * @param m The number of the node in a network namespace. - * @param n The number of the network namespace. - * @param local_m The number of nodes in a network namespace. - */ -static void -start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, - char *node_ip, - char *m, - char *n, - char *local_m) -{ - - unsigned int n_int, m_int, local_m_int, num; - - struct GNUNET_TESTING_NetjailTopology *topology = - GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG); - - sscanf (m, "%u", &m_int); - sscanf (n, "%u", &n_int); - sscanf (local_m, "%u", &local_m_int); - - - if (0 == m_int) - num = n_int; - else - num = (n_int - 1) * local_m_int + m_int + topology->nodes_x; - - GNUNET_asprintf (&cfgname, - "test_transport_api2_tcp_node1.conf"); - - LOG (GNUNET_ERROR_TYPE_ERROR, - "plugin cfgname: %s\n", - cfgname); - - LOG (GNUNET_ERROR_TYPE_ERROR, - "node ip: %s\n", - node_ip); - - GNUNET_asprintf (&testdir, - "%s%s%s", - BASE_DIR, - m, - n); - - struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_var_size (test, - GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, - struct GNUNET_TRANSPORT_TESTING_TestMessage, - NULL), - GNUNET_MQ_handler_end () - }; - - struct GNUNET_TESTING_Command commands[] = { - GNUNET_TESTING_cmd_system_create ("system-create", - testdir), - GNUNET_TRANSPORT_cmd_start_peer_v2 ("start-peer", - "system-create", - num, - node_ip, - handlers, - cfgname), - GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready", - write_message), - GNUNET_TESTING_cmd_block_until_all_peers_started ("block", - &are_all_peers_started), - GNUNET_TRANSPORT_cmd_connect_peers_v2 ("connect-peers", - "start-peer", - "system-create", - num), - GNUNET_TRANSPORT_cmd_send_simple_v2 ("send-simple", - "start-peer", - num), - GNUNET_TESTING_cmd_block_until_external_trigger ("block-receive", - &message_received), - GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer", - "start-peer"), - GNUNET_TESTING_cmd_system_destroy ("system-destroy", - "system-create"), - GNUNET_TESTING_cmd_local_test_finished ("local-test-finished", - write_message) - }; - - GNUNET_TESTING_run (commands, - GNUNET_TIME_UNIT_FOREVER_REL, - NULL, /* FIXME: will crash */ - NULL); - -} - - -/** - * Entry point for the plugin. - * - * @param cls NULL - * @return the exported block API - */ -void * -libgnunet_test_transport_plugin_cmd_simple_send_init (void *cls) -{ - struct GNUNET_TESTING_PluginFunctions *api; - - api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions); - api->start_testcase = &start_testcase; - api->all_peers_started = &all_peers_started; - return api; -} - - -/** - * Exit point from the plugin. - * - * @param cls the return value from #libgnunet_test_transport_plugin_block_test_init - * @return NULL - */ -void * -libgnunet_test_transport_plugin_cmd_simple_send_done (void *cls) -{ - struct GNUNET_TESTING_PluginFunctions *api = cls; - - GNUNET_free (api); - GNUNET_free (testdir); - GNUNET_free (cfgname); - return NULL; -} - - -/* end of plugin_cmd_simple_send.c */ diff --git a/src/transport/test_transport_plugin_cmd_udp_backchannel.c b/src/transport/test_transport_plugin_cmd_udp_backchannel.c index 6b0342e51..108e1ac09 100644 --- a/src/transport/test_transport_plugin_cmd_udp_backchannel.c +++ b/src/transport/test_transport_plugin_cmd_udp_backchannel.c @@ -39,28 +39,32 @@ #define TOPOLOGY_CONFIG "test_transport_udp_backchannel_topo.conf" -/** - * The name for a specific test environment directory. - * - */ -char *testdir; +struct TestState +{ + /** + * Callback to write messages to the master loop. + * + */ + TESTING_CMD_HELPER_write_cb write_message; -/** - * The name for the configuration file of the specific node. - * - */ -char *cfgname; + /** + * The name for a specific test environment directory. + * + */ + char *testdir; -/** - * Flag indicating if all peers have been started. - * - */ -unsigned int are_all_peers_started; + /** + * The name for the configuration file of the specific node. + * + */ + char *cfgname; +}; -/** - * Flag indicating a received message. - */ -unsigned int message_received; +static struct GNUNET_TESTING_Command block_send; + +static struct GNUNET_TESTING_Command block_receive; + +static struct GNUNET_TESTING_Command connect_peers; /** @@ -85,7 +89,14 @@ static void handle_test (void *cls, const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) { - message_received = GNUNET_YES; + struct GNUNET_TESTING_AsyncContext *ac; + + 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); } @@ -96,10 +107,62 @@ handle_test (void *cls, static void all_peers_started () { - are_all_peers_started = GNUNET_YES; - LOG (GNUNET_ERROR_TYPE_ERROR, - "setting are_all_peers_started: %d\n", - are_all_peers_started); + struct GNUNET_TESTING_AsyncContext *ac; + + GNUNET_TESTING_get_trait_async_context (&block_send, + &ac); + if ((NULL == ac) || (NULL == ac->cont)) + GNUNET_TESTING_async_fail (ac); + else + GNUNET_TESTING_async_finish (ac); +} + + +/** +* Function called with the final result of the test. +* +* @param cls the `struct MainParams` +* @param rv #GNUNET_OK if the test passed +*/ +static void +handle_result (void *cls, + enum GNUNET_GenericReturnValue rv) +{ + struct TestState *ts = cls; + struct GNUNET_MessageHeader *reply; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Local test exits with status %d\n", + rv); + reply = GNUNET_TESTING_send_local_test_finished_msg (rv); + + ts->write_message (reply, + ntohs (reply->size)); + GNUNET_free (ts->testdir); + GNUNET_free (ts->cfgname); + GNUNET_free (ts); +} + + +/** + * Callback from start peer cmd for signaling a peer got connected. + * + */ +static void * +notify_connect (void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_MQ_Handle *mq) +{ + struct ConnectPeersState *cps; + + GNUNET_TESTING_get_trait_connect_peer_state (&connect_peers, + &cps); + void *ret = NULL; + + cps->notify_connect (cps, + peer, + mq); + return ret; } @@ -121,7 +184,11 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, char *local_m) { - unsigned int n_int, m_int, local_m_int, num; + unsigned int n_int; + unsigned int m_int; + unsigned int local_m_int; + unsigned int num; + struct TestState *ts = GNUNET_new (struct TestState); struct GNUNET_TESTING_NetjailTopology *topology = GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG); @@ -136,18 +203,27 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, else num = (n_int - 1) * local_m_int + m_int + topology->nodes_x; - GNUNET_asprintf (&cfgname, + 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); + + GNUNET_asprintf (&ts->cfgname, "test_transport_api2_tcp_node1.conf"); LOG (GNUNET_ERROR_TYPE_ERROR, "plugin cfgname: %s\n", - cfgname); + ts->cfgname); LOG (GNUNET_ERROR_TYPE_ERROR, "node ip: %s\n", node_ip); - GNUNET_asprintf (&testdir, + GNUNET_asprintf (&ts->testdir, "%s%s%s", BASE_DIR, m, @@ -163,39 +239,32 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, struct GNUNET_TESTING_Command commands[] = { GNUNET_TESTING_cmd_system_create ("system-create", - testdir), - GNUNET_TRANSPORT_cmd_start_peer_v3 ("start-peer", - "system-create", - num, - node_ip, - handlers, - cfgname), + ts->testdir), + GNUNET_TRANSPORT_cmd_start_peer ("start-peer", + "system-create", + num, + node_ip, + handlers, + ts->cfgname, + notify_connect), GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready", write_message), - GNUNET_TESTING_cmd_block_until_all_peers_started ("block", - &are_all_peers_started), - GNUNET_TRANSPORT_cmd_connect_peers_v3 ("connect-peers", - "start-peer", - "system-create", - num, - topology), - GNUNET_TRANSPORT_cmd_send_simple_v2 ("send-simple", - "start-peer", - num), - GNUNET_TESTING_cmd_block_until_external_trigger ("block-receive", - &message_received), + block_send, + connect_peers, + GNUNET_TRANSPORT_cmd_send_simple ("send-simple", + "start-peer", + num), + block_receive, GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer", "start-peer"), GNUNET_TESTING_cmd_system_destroy ("system-destroy", - "system-create"), - GNUNET_TESTING_cmd_local_test_finished ("local-test-finished", - write_message) + "system-create") }; GNUNET_TESTING_run (commands, GNUNET_TIME_UNIT_FOREVER_REL, - NULL, /* FIMXE: will crash */ - NULL); + &handle_result, + ts); } @@ -234,8 +303,6 @@ libgnunet_test_transport_plugin_cmd_udp_backchannel_done (void *cls) struct GNUNET_TESTING_PluginFunctions *api = cls; GNUNET_free (api); - GNUNET_free (testdir); - GNUNET_free (cfgname); return NULL; } diff --git a/src/transport/test_transport_port_forward.c b/src/transport/test_transport_port_forward.c deleted file mode 100644 index d3233c2da..000000000 --- a/src/transport/test_transport_port_forward.c +++ /dev/null @@ -1,85 +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 transport/test_transport_port_forward.c - * @brief Test case executing a script which sends a test UDP message from a nated peer - * to a global known peer. There is a tcp port forwarding in place towards the - * natted peer to test the backchannel functionality of the TNG service. - * @author t3sserakt - */ -#include "platform.h" -#include "gnunet_testing_ng_lib.h" -#include "gnunet_util_lib.h" - -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) - -/** - * Return value of the test. - * - */ -static unsigned int rv = 0; - - -/** - * Main function to run the test cases. - * - * @param cls not used. - * - */ -static void -run (void *cls) -{ - const char *topology_config = "test_topology_port_forward.conf"; - - struct GNUNET_TESTING_Command commands[] = { - GNUNET_TESTING_cmd_netjail_start_v2 ("netjail-start", - topology_config), - GNUNET_TESTING_cmd_netjail_start_testing_system_v2 ("netjail-start-testbed", - topology_config, - &rv), - GNUNET_TESTING_cmd_stop_testing_system_v2 ("stop-testbed", - "netjail-start-testbed", - topology_config), - GNUNET_TESTING_cmd_netjail_stop_v2 ("netjail-stop", - topology_config), - GNUNET_TESTING_cmd_end () - }; - - GNUNET_TESTING_run (NULL, - commands, - TIMEOUT); -} - - -int -main (int argc, - char *const *argv) -{ - GNUNET_log_setup ("test-netjail", - "DEBUG", - NULL); - GNUNET_SCHEDULER_run (&run, - NULL); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Test finished!\n"); - return rv; -} diff --git a/src/transport/test_transport_simple_send.c b/src/transport/test_transport_simple_send.c deleted file mode 100644 index 924990d0a..000000000 --- a/src/transport/test_transport_simple_send.c +++ /dev/null @@ -1,86 +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 transport/test_transport_api_cmd_simple_send.c - * @brief Test case executing a script which sends a test message between two peers. - * @author t3sserakt - */ -#include "platform.h" -#include "gnunet_testing_ng_lib.h" -#include "gnunet_util_lib.h" - -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) - -/** - * Return value of the test. - * - */ -static unsigned int rv = 0; - - -/** - * Main function to run the test cases. - * - * @param cls not used. - * - */ -static void -run (void *cls) -{ - struct GNUNET_TESTING_Command commands[] = { - GNUNET_TESTING_cmd_netjail_start ("netjail-start", - "2", - "1"), - GNUNET_TESTING_cmd_netjail_start_testing_system ("netjail-start-testbed", - "2", - "1", - "libgnunet_test_transport_plugin_cmd_simple_send", - &rv), - GNUNET_TESTING_cmd_stop_testing_system ("stop-testbed", - "netjail-start-testbed", - "2", - "1"), - GNUNET_TESTING_cmd_netjail_stop ("netjail-stop", - "2", - "1"), - GNUNET_TESTING_cmd_end () - }; - - GNUNET_TESTING_run (NULL, - commands, - TIMEOUT); -} - - -int -main (int argc, - char *const *argv) -{ - GNUNET_log_setup ("test-netjail", - "DEBUG", - NULL); - GNUNET_SCHEDULER_run (&run, - NULL); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Test finished!\n"); - return rv; -} diff --git a/src/transport/test_transport_simple_send.sh b/src/transport/test_transport_simple_send.sh index 25d5b6797..2dd269fcc 100755 --- a/src/transport/test_transport_simple_send.sh +++ b/src/transport/test_transport_simple_send.sh @@ -1,2 +1,2 @@ #!/bin/bash -exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_simple_send" +exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_start_with_config test_transport_simple_send_topo.conf" diff --git a/src/transport/test_transport_simple_send_v2.c b/src/transport/test_transport_simple_send_v2.c deleted file mode 100644 index aeac1bfb6..000000000 --- a/src/transport/test_transport_simple_send_v2.c +++ /dev/null @@ -1,83 +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 transport/test_transport_api_cmd_simple_send.c - * @brief Test case executing a script which sends a test message between two peers. - * @author t3sserakt - */ -#include "platform.h" -#include "gnunet_testing_ng_lib.h" -#include "gnunet_util_lib.h" - -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) - -#define TOPOLOGY_CONFIG "test_transport_simple_send_topo.conf" - -/** - * Return value of the test. - * - */ -static unsigned int rv = 0; - - -/** - * Main function to run the test cases. - * - * @param cls not used. - * - */ -static void -run (void *cls) -{ - struct GNUNET_TESTING_Command commands[] = { - GNUNET_TESTING_cmd_netjail_start_v2 ("netjail-start", - TOPOLOGY_CONFIG), - GNUNET_TESTING_cmd_netjail_start_testing_system_v2 ("netjail-start-testbed", - TOPOLOGY_CONFIG, - &rv), - GNUNET_TESTING_cmd_stop_testing_system_v2 ("stop-testbed", - "netjail-start-testbed", - TOPOLOGY_CONFIG), - GNUNET_TESTING_cmd_netjail_stop_v2 ("netjail-stop", - TOPOLOGY_CONFIG), - GNUNET_TESTING_cmd_end () - }; - - GNUNET_TESTING_run (NULL, - commands, - TIMEOUT); -} - - -int -main (int argc, - char *const *argv) -{ - GNUNET_log_setup ("test-netjail", - "DEBUG", - NULL); - GNUNET_SCHEDULER_run (&run, - NULL); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Test finished!\n"); - return rv; -} diff --git a/src/transport/test_transport_simple_send_v2.sh b/src/transport/test_transport_simple_send_v2.sh deleted file mode 100755 index 8462d1849..000000000 --- a/src/transport/test_transport_simple_send_v2.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_simple_send_v2" diff --git a/src/transport/test_transport_start_with_config.c b/src/transport/test_transport_start_with_config.c index 795c157d7..932b0e583 100644 --- a/src/transport/test_transport_start_with_config.c +++ b/src/transport/test_transport_start_with_config.c @@ -20,7 +20,7 @@ /** * @file transport/test_transport_start_with_config.c - * @brief Test case executing a script which sends a test message between two peers. + * @brief Generic program to start testcases in an configurable topology. * @author t3sserakt */ #include "platform.h" @@ -29,57 +29,32 @@ #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) -/** - * Return value of the test. - * - */ -static unsigned int rv = 0; - -static char *topology_config; - -/** - * Main function to run the test cases. - * - * @param cls not used. - * - */ -static void -run (void *cls) -{ - struct GNUNET_TESTING_Command commands[] = { - GNUNET_TESTING_cmd_netjail_start_v2 ("netjail-start", - topology_config), - GNUNET_TESTING_cmd_netjail_start_testing_system_v2 ("netjail-start-testbed", - topology_config, - &rv), - GNUNET_TESTING_cmd_stop_testing_system_v2 ("stop-testbed", - "netjail-start-testbed", - topology_config), - GNUNET_TESTING_cmd_netjail_stop_v2 ("netjail-stop", - topology_config), - GNUNET_TESTING_cmd_end () - }; - - GNUNET_TESTING_run (NULL, - commands, - TIMEOUT); -} - int main (int argc, char *const *argv) { + char *topology_config; + GNUNET_log_setup ("test-netjail", "DEBUG", NULL); topology_config = argv[1]; - GNUNET_SCHEDULER_run (&run, - NULL); + struct GNUNET_TESTING_Command commands[] = { + GNUNET_TESTING_cmd_netjail_start ("netjail-start", + topology_config), + GNUNET_TESTING_cmd_netjail_start_testing_system ("netjail-start-testbed", + topology_config), + GNUNET_TESTING_cmd_stop_testing_system ("stop-testbed", + "netjail-start-testbed", + topology_config), + GNUNET_TESTING_cmd_netjail_stop ("netjail-stop", + topology_config), + GNUNET_TESTING_cmd_end () + }; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Test finished!\n"); - return rv; + return GNUNET_TESTING_main (commands, + TIMEOUT); } diff --git a/src/transport/transport-testing-cmds.h b/src/transport/transport-testing-cmds.h index ecdabd35f..f6e34df62 100644 --- a/src/transport/transport-testing-cmds.h +++ b/src/transport/transport-testing-cmds.h @@ -29,91 +29,70 @@ #include "gnunet_testing_lib.h" -struct StartPeerState_v2 +/** + * Struct to store information needed in callbacks. + * + */ +struct ConnectPeersState { /** - * The ip of a node. - */ - char *node_ip; - - /** - * Receive callback + * Context for our asynchronous completion. */ - struct GNUNET_MQ_MessageHandler *handlers; + struct GNUNET_TESTING_AsyncContext ac; - const char *cfgname; + GNUNET_TRANSPORT_NotifyConnect notify_connect; /** - * Peer's configuration + * The testing system of this node. */ - struct GNUNET_CONFIGURATION_Handle *cfg; - - struct GNUNET_TESTING_Peer *peer; + struct GNUNET_TESTING_System *tl_system; - /** - * Peer identity - */ - struct GNUNET_PeerIdentity id; + // Label of the cmd which started the test system. + const char *create_label; /** - * Peer's transport service handle + * Number globally identifying the node. + * */ - struct GNUNET_TRANSPORT_CoreHandle *th; + uint32_t num; /** - * Application handle + * Label of the cmd to start a peer. + * */ - struct GNUNET_TRANSPORT_ApplicationHandle *ah; + const char *start_peer_label; /** - * Peer's PEERSTORE Handle + * The peer identity of this peer. + * */ - struct GNUNET_PEERSTORE_Handle *ph; + struct GNUNET_PeerIdentity *id; /** - * Hello get task + * The topology of the test setup. */ - struct GNUNET_SCHEDULER_Task *rh_task; + struct GNUNET_TESTING_NetjailTopology *topology; /** - * Peer's transport get hello handle to retrieve peer's HELLO message + * Connections to other peers. */ - struct GNUNET_PEERSTORE_IterateContext *pic; + struct GNUNET_TESTING_NodeConnection *node_connections_head; - /** - * Hello - */ - char *hello; + struct GNUNET_TESTING_Interpreter *is; /** - * Hello size + * Number of connections. */ - size_t hello_size; - - char *m; - - char *n; - - char *local_m; - - unsigned int finished; - - const char *system_label; - - /** - * An unique number to identify the peer - */ - unsigned int no; - - struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map; - - struct GNUNET_TESTING_System *tl_system; - + unsigned int con_num; }; - struct StartPeerState { + /** + * Context for our asynchronous completion. + */ + struct GNUNET_TESTING_AsyncContext ac; + /** * The ip of a node. */ @@ -179,8 +158,6 @@ struct StartPeerState char *local_m; - unsigned int finished; - const char *system_label; /** @@ -192,9 +169,24 @@ struct StartPeerState struct GNUNET_TESTING_System *tl_system; + GNUNET_TRANSPORT_NotifyConnect notify_connect; + }; +/** + * 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_TESTING_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 @@ -202,62 +194,29 @@ GNUNET_TRANSPORT_get_trait_state (const struct struct StartPeerState **sps); -struct GNUNET_TESTING_Command -GNUNET_TRANSPORT_cmd_start_peer_v2 (const char *label, - const char *system_label, - uint32_t no, - char *node_ip, - struct GNUNET_MQ_MessageHandler *handlers, - const char *cfgname); - -struct GNUNET_TESTING_Command -GNUNET_TRANSPORT_cmd_start_peer_v3 (const char *label, - const char *system_label, - uint32_t no, - char *node_ip, - struct GNUNET_MQ_MessageHandler *handlers, - const char *cfgname); - struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_start_peer (const char *label, const char *system_label, - char *m, - char *n, - char *local_m, + uint32_t no, char *node_ip, struct GNUNET_MQ_MessageHandler *handlers, - const char *cfgname); + const char *cfgname, + GNUNET_TRANSPORT_NotifyConnect notify_connect); + struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_stop_peer (const char *label, const char *start_label); + struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_connect_peers (const char *label, const char *start_peer_label, const char *create_label, - uint32_t num); - -struct GNUNET_TESTING_Command -GNUNET_TRANSPORT_cmd_connect_peers_v2 (const char *label, - const char *start_peer_label, - const char *create_label, - uint32_t num); - -struct GNUNET_TESTING_Command -GNUNET_TRANSPORT_cmd_connect_peers_v3 (const char *label, - const char *start_peer_label, - const char *create_label, - uint32_t num, - struct GNUNET_TESTING_NetjailTopology * - topology); + uint32_t num, + struct GNUNET_TESTING_NetjailTopology * + topology); -struct GNUNET_TESTING_Command -GNUNET_TRANSPORT_cmd_send_simple (const char *label, - char *m, - char *n, - uint32_t num, - const char *start_peer_label); /** * Create command. @@ -270,43 +229,29 @@ GNUNET_TRANSPORT_cmd_send_simple (const char *label, * @return command. */ struct GNUNET_TESTING_Command -GNUNET_TRANSPORT_cmd_send_simple_v2 (const char *label, - const char *start_peer_label, - uint32_t num); +GNUNET_TRANSPORT_cmd_send_simple (const char *label, + const char *start_peer_label, + uint32_t num); + + + + 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 * + GNUNET_CONTAINER_MultiShortmap + * * connected_peers_map); - -int -GNUNET_TRANSPORT_get_trait_connected_peers_map_v2 (const struct - GNUNET_TESTING_Command - *cmd, - struct - GNUNET_CONTAINER_MultiShortmap - * - * - connected_peers_map); - -int -GNUNET_TRANSPORT_get_trait_connected_peers_map_v3 (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 @@ -327,19 +272,5 @@ GNUNET_TRANSPORT_get_trait_application_handle (const struct GNUNET_TRANSPORT_ApplicationHandle **ah); -int -GNUNET_TRANSPORT_get_trait_application_handle_v2 (const struct - GNUNET_TESTING_Command *cmd, - struct - GNUNET_TRANSPORT_ApplicationHandle - **ah); - -int -GNUNET_TRANSPORT_get_trait_application_handle_v3 (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_connecting_peers.c b/src/transport/transport_api_cmd_connecting_peers.c index 82194ff15..2e51363f6 100644 --- a/src/transport/transport_api_cmd_connecting_peers.c +++ b/src/transport/transport_api_cmd_connecting_peers.c @@ -36,40 +36,240 @@ */ #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) -/** - * Struct to store information needed in callbacks. - * - */ -struct ConnectPeersState +#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) { - /** - * Context for our asynchronous completion. - */ - struct GNUNET_TESTING_AsyncContext ac; - - // Label of the cmd which started the test system. - const char *create_label; - - /** - * Number globally identifying the node. - * - */ - uint32_t num; + 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; +} - /** - * Label of the cmd to start a peer. - * - */ - const char *start_peer_label; - /** - * The peer identity of this peer. - * - */ - struct GNUNET_PeerIdentity *id; +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; - struct GNUNET_TESTING_Interpreter *is; -}; + 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; +} /** @@ -83,24 +283,17 @@ connect_peers_run (void *cls, struct ConnectPeersState *cps = cls; const struct GNUNET_TESTING_Command *system_cmd; struct GNUNET_TESTING_System *tl_system; - struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct - GNUNET_CRYPTO_EddsaPrivateKey); - struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct - GNUNET_CRYPTO_EddsaPublicKey); - ; + + const struct GNUNET_TESTING_Command *peer1_cmd; - // const struct GNUNET_TESTING_Command *peer2_cmd; struct GNUNET_TRANSPORT_ApplicationHandle *ah; - struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity); + struct GNUNET_PeerIdentity *peer; char *addr; - // struct GNUNET_TIME_Absolute t; - char *hello; - // size_t *hello_size; enum GNUNET_NetworkType nt = 0; - char *peer_id; - struct GNUNET_PeerIdentity *id; - struct GNUNET_PeerIdentity *other = GNUNET_new (struct GNUNET_PeerIdentity); uint32_t num; + struct GNUNET_TESTING_NodeConnection *pos_connection; + struct GNUNET_TESTING_ADDRESS_PREFIX *pos_prefix; + unsigned int con_num = 0; cps->is = is; peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is, @@ -108,121 +301,82 @@ connect_peers_run (void *cls, GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd, &ah); - GNUNET_TRANSPORT_get_trait_hello (peer1_cmd, - &hello); - - GNUNET_TRANSPORT_get_trait_peer_id (peer1_cmd, - &id); - system_cmd = GNUNET_TESTING_interpreter_lookup_command (is, cps->create_label); GNUNET_TESTING_get_trait_test_system (system_cmd, &tl_system); - if (2 == cps->num) - num = 1; - else - num = 2; + cps->tl_system = tl_system; + cps->node_connections_head = get_connections (cps->num, cps->topology); - // if (strstr (hello, "60002") != NULL) - if (2 == num) - { - addr = "tcp-192.168.15.2:60002"; - peer_id = "F2F3X9G1YNCTXKK7A4J6M4ZM4BBSKC9DEXZVHCWQ475M0C7PNWCG"; - } - else + for (pos_connection = cps->node_connections_head; NULL != pos_connection; + pos_connection = pos_connection->next) { - addr = "tcp-192.168.15.1:60002"; - peer_id = "4TTC9WBSVP9RJT6DVEZ7E0TDW7TQXC11NR1EMR2F8ARS87WZ2730"; + con_num++; + num = calculate_num (pos_connection, cps->topology); + 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); + + addr = get_address (pos_connection, pos_prefix->address_prefix); + + peer = get_pub_key (num, tl_system); + + LOG (GNUNET_ERROR_TYPE_ERROR, + "num: %u pub_key %s addr: %s\n", + num, + GNUNET_CRYPTO_eddsa_public_key_to_string (&(peer->public_key)), + addr); + + cps->id = peer; + + GNUNET_TRANSPORT_application_validate (ah, + peer, + nt, + addr); + } } - - priv_key = GNUNET_TESTING_hostkey_get (tl_system, - num, - other); - - GNUNET_CRYPTO_eddsa_key_get_public (priv_key, - pub_key); - - GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id, - strlen (peer_id), - &peer->public_key); - - peer->public_key = *pub_key; - - LOG (GNUNET_ERROR_TYPE_ERROR, - "\nnum: %u\n peer_id: %s\n pub_key %s\n", - num, - peer_id, - GNUNET_CRYPTO_eddsa_public_key_to_string (pub_key)); - - cps->id = peer; - - // TODO This does not work, because the other peer is running in another local loop. We need to message between different local loops. For now we will create the hello manually with the known information about the other local peers. - // --------------------------------------------- - /*peer2_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer2_label); - GNUNET_TRANSPORT_get_trait_peer_id (peer2_cmd, - &id); - GNUNET_TRANSPORT_get_trait_hello (peer2_cmd, - &hello); - GNUNET_TRANSPORT_get_trait_hello_size (peer2_cmd, - &hello_size); - - addr = GNUNET_HELLO_extract_address (hello, - *hello_size, - id, - &nt, - &t);*/ - - // ---------------------------------------------- - - - GNUNET_TRANSPORT_application_validate (ah, - peer, - nt, - addr); + cps->con_num = con_num; } /** - * The finish function of this cmd will check if the peer we are trying to connect to is in the connected peers map of the start peer cmd for this peer. + * Callback from start peer cmd for signaling a peer got connected. * */ -// FIXME: this needs a complete rewrite! -static int -connect_peers_finish (void *cls, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls) +static void * +notify_connect (void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_MQ_Handle *mq) { struct ConnectPeersState *cps = cls; - const struct GNUNET_TESTING_Command *peer1_cmd; - struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map; - unsigned int ret; - struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode); - struct GNUNET_HashCode hc; - int node_number; - - peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->is, - cps->start_peer_label); - GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd, - &connected_peers_map); - - node_number = 1; - GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc); + struct GNUNET_PeerIdentity *peer_connection; + unsigned int con_num = 0; + struct GNUNET_TESTING_NodeConnection *pos_connection; + unsigned int num; + void *ret = NULL; + + 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); + if (0 == GNUNET_memcmp (peer, + peer_connection)) + con_num++; + } - // TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node. - memcpy (key, - &hc, - sizeof (*key)); - ret = GNUNET_CONTAINER_multishortmap_contains (connected_peers_map, - key); - if (GNUNET_YES == ret) + if (cps->con_num == con_num) { - cont (cont_cls); + GNUNET_TESTING_async_finish (&cps->ac); } - - GNUNET_free (key); return ret; } @@ -241,11 +395,58 @@ connect_peers_cleanup (void *cls) } +/** + * This function prepares an array with traits. + * + */ +static int +connect_peers_traits (void *cls, + const void **ret, + const char *trait, + unsigned int index) +{ + struct StartPeerState *cps = cls; + struct GNUNET_TESTING_Trait traits[] = { + { + .index = 0, + .trait_name = "state", + .ptr = (const void *) cps, + }, + GNUNET_TESTING_trait_end () + }; + return GNUNET_TESTING_get_trait (traits, + ret, + trait, + index); +} + + +/** + * 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_TESTING_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); +} + + struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_connect_peers (const char *label, const char *start_peer_label, const char *create_label, - uint32_t num) + uint32_t num, + struct GNUNET_TESTING_NetjailTopology * + topology) { struct ConnectPeersState *cps; @@ -253,6 +454,8 @@ GNUNET_TRANSPORT_cmd_connect_peers (const char *label, cps->start_peer_label = start_peer_label; cps->num = num; cps->create_label = create_label; + cps->topology = topology; + cps->notify_connect = ¬ify_connect; { struct GNUNET_TESTING_Command cmd = { @@ -260,7 +463,8 @@ GNUNET_TRANSPORT_cmd_connect_peers (const char *label, .label = label, .run = &connect_peers_run, .ac = &cps->ac, - .cleanup = &connect_peers_cleanup + .cleanup = &connect_peers_cleanup, + .traits = &connect_peers_traits }; return cmd; diff --git a/src/transport/transport_api_cmd_connecting_peers_v2.c b/src/transport/transport_api_cmd_connecting_peers_v2.c deleted file mode 100644 index 8d0f74916..000000000 --- a/src/transport/transport_api_cmd_connecting_peers_v2.c +++ /dev/null @@ -1,237 +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_api_cmd_start_peer.c - * @brief cmd to start a peer. - * @author t3sserakt - */ -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_testing_ng_lib.h" -#include "gnunet_transport_application_service.h" -#include "gnunet_hello_lib.h" -#include "gnunet_transport_service.h" -#include "transport-testing-cmds.h" - -/** - * Generic logging shortcut - */ -#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) - -#define CONNECT_ADDRESS_TEMPLATE "tcp-192.168.15.%u:60002" - -/** - * Struct to store information needed in callbacks. - * - */ -struct ConnectPeersState -{ - /** - * Context for our asynchronous completion. - */ - struct GNUNET_TESTING_AsyncContext ac; - - // Label of the cmd which started the test system. - const char *create_label; - - /** - * Number globally identifying the node. - * - */ - uint32_t num; - - /** - * Label of the cmd to start a peer. - * - */ - const char *start_peer_label; - - /** - * The peer identity of this peer. - * - */ - struct GNUNET_PeerIdentity *id; - - struct GNUNET_TESTING_Interpreter *is; -}; - - -/** - * The run method of this cmd will connect to peers. - * - */ -static void -connect_peers_run (void *cls, - struct GNUNET_TESTING_Interpreter *is) -{ - struct ConnectPeersState *cps = cls; - const struct GNUNET_TESTING_Command *system_cmd; - struct GNUNET_TESTING_System *tl_system; - struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct - GNUNET_CRYPTO_EddsaPrivateKey); - struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct - GNUNET_CRYPTO_EddsaPublicKey); - const struct GNUNET_TESTING_Command *peer1_cmd; - struct GNUNET_TRANSPORT_ApplicationHandle *ah; - struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity); - char *addr; - enum GNUNET_NetworkType nt = 0; - struct GNUNET_PeerIdentity *other = GNUNET_new (struct GNUNET_PeerIdentity); - uint32_t num; - - cps->is = is; - peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is, - cps->start_peer_label); - GNUNET_TRANSPORT_get_trait_application_handle_v2 (peer1_cmd, - &ah); - - system_cmd = GNUNET_TESTING_interpreter_lookup_command (is, - cps->create_label); - GNUNET_TESTING_get_trait_test_system (system_cmd, - &tl_system); - - if (1 == cps->num) - { - num = 2; - // addr = "tcp-192.168.15.2:60002"; - } - else - { - num = 1; - // addr = "tcp-192.168.15.1:60002"; - } - - GNUNET_asprintf (&addr, - CONNECT_ADDRESS_TEMPLATE, - num); - - priv_key = GNUNET_TESTING_hostkey_get (tl_system, - num, - other); - - GNUNET_CRYPTO_eddsa_key_get_public (priv_key, - pub_key); - - - peer->public_key = *pub_key; - - LOG (GNUNET_ERROR_TYPE_ERROR, - "num: %u pub_key %s\n", - num, - GNUNET_CRYPTO_eddsa_public_key_to_string (pub_key)); - - cps->id = peer; - - GNUNET_TRANSPORT_application_validate (ah, - peer, - nt, - addr); -} - - -/** - * The finish function of this cmd will check if the peer we are trying to connect to is in the connected peers map of the start peer cmd for this peer. - * - */ -static int -connect_peers_finish (void *cls, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls) -{ - struct ConnectPeersState *cps = cls; - const struct GNUNET_TESTING_Command *peer1_cmd; - struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map; - unsigned int ret; - struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode); - struct GNUNET_HashCode hc; - int node_number; - - peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->is, - cps->start_peer_label); - GNUNET_TRANSPORT_get_trait_connected_peers_map_v2 (peer1_cmd, - &connected_peers_map); - - node_number = 1; - GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc); - - // TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node. - memcpy (key, - &hc, - sizeof (*key)); - ret = GNUNET_CONTAINER_multishortmap_contains (connected_peers_map, - key); - - if (GNUNET_YES == ret) - { - cont (cont_cls); - } - - GNUNET_free (key); - return ret; -} - - -/** - * The cleanup function of this cmd frees resources the cmd allocated. - * - */ -static void -connect_peers_cleanup (void *cls) -{ - struct ConnectPeersState *cps = cls; - - GNUNET_free (cps->id); - GNUNET_free (cps); -} - - -/** - * Create command. - * - * @param label name for command. - * @param start_peer_label Label of the cmd to start a peer. - * @return command. - */ -struct GNUNET_TESTING_Command -GNUNET_TRANSPORT_cmd_connect_peers_v2 (const char *label, - const char *start_peer_label, - const char *create_label, - uint32_t num) -{ - struct ConnectPeersState *cps; - - cps = GNUNET_new (struct ConnectPeersState); - cps->start_peer_label = start_peer_label; - cps->num = num; - cps->create_label = create_label; - - { - struct GNUNET_TESTING_Command cmd = { - .cls = cps, - .label = label, - .run = &connect_peers_run, - .ac = &cps->ac, - .cleanup = &connect_peers_cleanup - }; - - return cmd; - } -} diff --git a/src/transport/transport_api_cmd_connecting_peers_v3.c b/src/transport/transport_api_cmd_connecting_peers_v3.c deleted file mode 100644 index ae32a087a..000000000 --- a/src/transport/transport_api_cmd_connecting_peers_v3.c +++ /dev/null @@ -1,496 +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_api_cmd_start_peer.c - * @brief cmd to start a peer. - * @author t3sserakt - */ -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_testing_ng_lib.h" -#include "gnunet_transport_application_service.h" -#include "gnunet_hello_lib.h" -#include "gnunet_transport_service.h" -#include "transport-testing-cmds.h" - -/** - * Generic logging shortcut - */ -#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" - -/** - * Struct to store information needed in callbacks. - * - */ -struct ConnectPeersState -{ - /** - * Context for our asynchronous completion. - */ - struct GNUNET_TESTING_AsyncContext ac; - - /** - * The testing system of this node. - */ - struct GNUNET_TESTING_System *tl_system; - - // Label of the cmd which started the test system. - const char *create_label; - - /** - * Number globally identifying the node. - * - */ - uint32_t num; - - /** - * Label of the cmd to start a peer. - * - */ - const char *start_peer_label; - - /** - * The peer identity of this peer. - * - */ - struct GNUNET_PeerIdentity *id; - - /** - * The topology of the test setup. - */ - struct GNUNET_TESTING_NetjailTopology *topology; - - /** - * Connections to other peers. - */ - struct GNUNET_TESTING_NodeConnection *node_connections_head; - - struct GNUNET_TESTING_Interpreter *is; - - /** - * Number of connections. - */ - unsigned int con_num; -}; - - -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. - * - */ -static void -connect_peers_run (void *cls, - struct GNUNET_TESTING_Interpreter *is) -{ - struct ConnectPeersState *cps = cls; - const struct GNUNET_TESTING_Command *system_cmd; - struct GNUNET_TESTING_System *tl_system; - - - const struct GNUNET_TESTING_Command *peer1_cmd; - struct GNUNET_TRANSPORT_ApplicationHandle *ah; - struct GNUNET_PeerIdentity *peer; - char *addr; - enum GNUNET_NetworkType nt = 0; - uint32_t num; - struct GNUNET_TESTING_NodeConnection *pos_connection; - struct GNUNET_TESTING_ADDRESS_PREFIX *pos_prefix; - unsigned int con_num = 0; - - cps->is = is; - peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is, - cps->start_peer_label); - GNUNET_TRANSPORT_get_trait_application_handle_v2 (peer1_cmd, - &ah); - - system_cmd = GNUNET_TESTING_interpreter_lookup_command (is, - cps->create_label); - GNUNET_TESTING_get_trait_test_system (system_cmd, - &tl_system); - - cps->tl_system = tl_system; - - cps->node_connections_head = 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); - 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); - - addr = get_address (pos_connection, pos_prefix->address_prefix); - - peer = get_pub_key (num, tl_system); - - LOG (GNUNET_ERROR_TYPE_ERROR, - "num: %u pub_key %s addr: %s\n", - num, - GNUNET_CRYPTO_eddsa_public_key_to_string (&(peer->public_key)), - addr); - - cps->id = peer; - - GNUNET_TRANSPORT_application_validate (ah, - peer, - nt, - addr); - } - } - cps->con_num = con_num; -} - - -/** - * 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 -connect_peers_finish (void *cls, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls) -{ - struct ConnectPeersState *cps = cls; - const struct GNUNET_TESTING_Command *peer1_cmd; - struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map; - unsigned int ret; - struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode); - struct GNUNET_HashCode hc; - struct GNUNET_PeerIdentity *peer; - unsigned int con_num = 0; - struct GNUNET_TESTING_NodeConnection *pos_connection; - unsigned int num; - - peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->is, - cps->start_peer_label); - GNUNET_TRANSPORT_get_trait_connected_peers_map_v2 (peer1_cmd, - &connected_peers_map); - - for (pos_connection = cps->node_connections_head; NULL != pos_connection; - pos_connection = pos_connection->next) - { - num = calculate_num (pos_connection, cps->topology); - peer = get_pub_key (num, cps->tl_system); - GNUNET_CRYPTO_hash (&(peer->public_key), sizeof(peer->public_key), &hc); - memcpy (key, - &hc, - sizeof (*key)); - if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains ( - connected_peers_map, - key)) - con_num++; - } - - - if (cps->con_num == con_num) - { - cont (cont_cls); - ret = GNUNET_YES; - } - - GNUNET_free (key); - return ret; -} - - -/** - * The cleanup function of this cmd frees resources the cmd allocated. - * - */ -static void -connect_peers_cleanup (void *cls) -{ - struct ConnectPeersState *cps = cls; - - GNUNET_free (cps->id); - GNUNET_free (cps); -} - - -struct GNUNET_TESTING_Command -GNUNET_TRANSPORT_cmd_connect_peers_v3 (const char *label, - const char *start_peer_label, - const char *create_label, - uint32_t num, - struct GNUNET_TESTING_NetjailTopology * - topology) -{ - struct ConnectPeersState *cps; - - cps = GNUNET_new (struct ConnectPeersState); - cps->start_peer_label = start_peer_label; - cps->num = num; - cps->create_label = create_label; - cps->topology = topology; - - { - struct GNUNET_TESTING_Command cmd = { - .cls = cps, - .label = label, - .run = &connect_peers_run, - .ac = &cps->ac, - .cleanup = &connect_peers_cleanup - }; - - return cmd; - } -} diff --git a/src/transport/transport_api_cmd_send_simple.c b/src/transport/transport_api_cmd_send_simple.c index 1599dfe97..0631f7051 100644 --- a/src/transport/transport_api_cmd_send_simple.c +++ b/src/transport/transport_api_cmd_send_simple.c @@ -35,18 +35,6 @@ */ struct SendSimpleState { - /** - * The number of the local node of the actual network namespace. - * - */ - char *m; - - /** - * The number of the actual namespace. - * - */ - char *n; - /** * Number globally identifying the node. * @@ -146,16 +134,12 @@ send_simple_run (void *cls, */ struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_send_simple (const char *label, - char *m, - char *n, - uint32_t num, - const char *start_peer_label) + const char *start_peer_label, + uint32_t num) { struct SendSimpleState *sss; sss = GNUNET_new (struct SendSimpleState); - sss->m = m; - sss->n = n; sss->num = num; sss->start_peer_label = start_peer_label; { diff --git a/src/transport/transport_api_cmd_send_simple_v2.c b/src/transport/transport_api_cmd_send_simple_v2.c deleted file mode 100644 index 8d65eb684..000000000 --- a/src/transport/transport_api_cmd_send_simple_v2.c +++ /dev/null @@ -1,156 +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_api_cmd_start_peer.c - * @brief cmd to start a peer. - * @author t3sserakt - */ -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_testing_ng_lib.h" -#include "transport-testing2.h" -#include "transport-testing-cmds.h" - -/** - * Struct to hold information for callbacks. - * - */ -struct SendSimpleState -{ - /** - * Number globally identifying the node. - * - */ - uint32_t num; - - /** - * Label of the cmd to start a peer. - * - */ - const char *start_peer_label; -}; - - -/** - * Trait function of this cmd does nothing. - * - */ -static int -send_simple_traits (void *cls, - const void **ret, - const char *trait, - unsigned int index) -{ - return GNUNET_OK; -} - - -/** - * The cleanup function of this cmd frees resources the cmd allocated. - * - */ -static void -send_simple_cleanup (void *cls) -{ - struct SendSimpleState *sss = cls; - - GNUNET_free (sss); -} - - -/** - * The run method of this cmd will send a simple message to the connected peer. - * - */ -static void -send_simple_run (void *cls, - struct GNUNET_TESTING_Interpreter *is) -{ - struct SendSimpleState *sss = cls; - struct GNUNET_MQ_Envelope *env; - struct GNUNET_TRANSPORT_TESTING_TestMessage *test; - struct GNUNET_MQ_Handle *mq; - 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; - int node_number; - - peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is, - sss->start_peer_label); - GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd, - &connected_peers_map); - - node_number = 1; - GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc); - memcpy (key, - &hc, - sizeof (*key)); - - mq = GNUNET_CONTAINER_multishortmap_get (connected_peers_map, - key); - - env = GNUNET_MQ_msg_extra (test, - 2600 - sizeof(*test), - GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE); - test->num = htonl (sss->num); - memset (&test[1], - sss->num, - 2600 - sizeof(*test)); - GNUNET_MQ_send (mq, - env); - GNUNET_free (key); - -} - - -/** - * Create command. - * - * @param label name for command. - * @param m The number of the local node of the actual network namespace. - * @param n The number of the actual namespace. - * @param num Number globally identifying the node. - * @param start_peer_label Label of the cmd to start a peer. - * @return command. - */ -struct GNUNET_TESTING_Command -GNUNET_TRANSPORT_cmd_send_simple_v2 (const char *label, - const char *start_peer_label, - uint32_t num) -{ - struct SendSimpleState *sss; - - sss = GNUNET_new (struct SendSimpleState); - sss->num = num; - sss->start_peer_label = start_peer_label; - { - struct GNUNET_TESTING_Command cmd = { - .cls = sss, - .label = label, - .run = &send_simple_run, - .cleanup = &send_simple_cleanup, - .traits = &send_simple_traits - }; - - return cmd; - } -} diff --git a/src/transport/transport_api_cmd_start_peer.c b/src/transport/transport_api_cmd_start_peer.c index 44fc68807..dc19f10eb 100644 --- a/src/transport/transport_api_cmd_start_peer.c +++ b/src/transport/transport_api_cmd_start_peer.c @@ -51,7 +51,6 @@ hello_iter_cb (void *cb_cls, const char *emsg) { struct StartPeerState *sps = cb_cls; - if (NULL == record) { sps->pic = NULL; @@ -66,7 +65,7 @@ hello_iter_cb (void *cb_cls, GNUNET_PEERSTORE_iterate_cancel (sps->pic); sps->pic = NULL; - sps->finished = GNUNET_YES; + GNUNET_TESTING_async_finish (&sps->ac); } @@ -122,7 +121,7 @@ notify_connect (void *cls, struct StartPeerState *sps = cls; struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode); struct GNUNET_HashCode hc; - int node_number; + struct GNUNET_CRYPTO_EddsaPublicKey public_key = peer->public_key; void *ret = NULL; @@ -133,9 +132,7 @@ notify_connect (void *cls, sps->no, GNUNET_i2s (&sps->id)); - // TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node. - node_number = 1; - GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc); + GNUNET_CRYPTO_hash (&public_key, sizeof(public_key), &hc); memcpy (key, @@ -147,6 +144,11 @@ notify_connect (void *cls, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); GNUNET_free (key); + + sps->notify_connect (cls, + peer, + mq); + // TODO what does the handler function need? return ret; } @@ -167,7 +169,8 @@ start_peer_run (void *cls, struct GNUNET_TESTING_System *tl_system; char *home; char *transport_unix_path; - char *communicator_unix_path; + char *tcp_communicator_unix_path; + char *udp_communicator_unix_path; char *bindto; if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname)) @@ -192,7 +195,11 @@ start_peer_run (void *cls, "$GNUNET_RUNTIME_DIR/tng-p%u.sock", sps->no); - GNUNET_asprintf (&communicator_unix_path, + GNUNET_asprintf (&tcp_communicator_unix_path, + "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock", + sps->no); + + GNUNET_asprintf (&udp_communicator_unix_path, "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock", sps->no); @@ -200,6 +207,9 @@ start_peer_run (void *cls, "%s:60002", sps->node_ip); + LOG (GNUNET_ERROR_TYPE_ERROR, + "node_ip %s\n", + bindto); GNUNET_CONFIGURATION_set_value_string (sps->cfg, "PATHS", "GNUNET_TEST_HOME", home); @@ -208,9 +218,15 @@ start_peer_run (void *cls, GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp", "BINDTO", bindto); + GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-udp", + "BINDTO", + bindto); GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp", "UNIXPATH", - communicator_unix_path); + tcp_communicator_unix_path); + GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-udp", + "UNIXPATH", + udp_communicator_unix_path); system_cmd = GNUNET_TESTING_interpreter_lookup_command (is, sps->system_label); @@ -417,10 +433,9 @@ start_peer_traits (void *cls, * */ int -GNUNET_TRANSPORT_get_trait_state (const struct - GNUNET_TESTING_Command - *cmd, - struct StartPeerState **sps) +GNUNET_TRANSPORT_get_trait_state ( + const struct GNUNET_TESTING_Command *cmd, + struct StartPeerState **sps) { return cmd->traits (cmd->cls, (const void **) sps, @@ -481,7 +496,8 @@ GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct GNUNET_TESTING_Command *cmd, struct - GNUNET_CONTAINER_MultiShortmap * + GNUNET_CONTAINER_MultiShortmap + * * connected_peers_map) { @@ -545,12 +561,11 @@ GNUNET_TRANSPORT_get_trait_peer_id (const struct struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_start_peer (const char *label, const char *system_label, - char *m, - char *n, - char *local_m, + uint32_t no, char *node_ip, struct GNUNET_MQ_MessageHandler *handlers, - const char *cfgname) + const char *cfgname, + GNUNET_TRANSPORT_NotifyConnect notify_connect) { struct StartPeerState *sps; struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map = @@ -558,14 +573,12 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label, unsigned int i; sps = GNUNET_new (struct StartPeerState); - sps->m = m; - sps->n = n; - sps->local_m = local_m; - sps->no = (atoi (n) - 1) * atoi (sps->local_m) + atoi (m); + sps->no = no; sps->system_label = system_label; sps->connected_peers_map = connected_peers_map; sps->cfgname = cfgname; sps->node_ip = node_ip; + sps->notify_connect = notify_connect; if (NULL != handlers) { @@ -578,15 +591,14 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label, i * sizeof(struct GNUNET_MQ_MessageHandler)); } - { - struct GNUNET_TESTING_Command cmd = { - .cls = sps, - .label = label, - .run = &start_peer_run, - .cleanup = &start_peer_cleanup, - .traits = &start_peer_traits - }; - - return cmd; - } + struct GNUNET_TESTING_Command cmd = { + .cls = sps, + .label = label, + .run = &start_peer_run, + .ac = &sps->ac, + .cleanup = &start_peer_cleanup, + .traits = &start_peer_traits + }; + + return cmd; } diff --git a/src/transport/transport_api_cmd_start_peer_v2.c b/src/transport/transport_api_cmd_start_peer_v2.c deleted file mode 100644 index 94799eddd..000000000 --- a/src/transport/transport_api_cmd_start_peer_v2.c +++ /dev/null @@ -1,605 +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_api_cmd_start_peer.c - * @brief cmd to start a peer. - * @author t3sserakt - */ -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_testing_ng_lib.h" -#include "gnunet_peerstore_service.h" -#include "gnunet_transport_core_service.h" -#include "gnunet_transport_application_service.h" -#include "transport-testing-cmds.h" - -/** - * Generic logging shortcut - */ -#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) - - -static void -retrieve_hello (void *cls); - - -/** - * Callback delivering the hello of this peer from peerstore. - * - */ -static void -hello_iter_cb (void *cb_cls, - const struct GNUNET_PEERSTORE_Record *record, - const char *emsg) -{ - struct StartPeerState_v2 *sps = cb_cls; - if (NULL == record) - { - sps->pic = NULL; - sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps); - return; - } - // Check record type et al? - sps->hello_size = record->value_size; - sps->hello = GNUNET_malloc (sps->hello_size); - memcpy (sps->hello, record->value, sps->hello_size); - sps->hello[sps->hello_size - 1] = '\0'; - - GNUNET_PEERSTORE_iterate_cancel (sps->pic); - sps->pic = NULL; - sps->finished = GNUNET_YES; -} - - -/** - * Function to start the retrieval task to retrieve the hello of this peer - * from the peerstore. - * - */ -static void -retrieve_hello (void *cls) -{ - struct StartPeerState_v2 *sps = cls; - sps->rh_task = NULL; - sps->pic = GNUNET_PEERSTORE_iterate (sps->ph, - "transport", - &sps->id, - GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY, - hello_iter_cb, - sps); - -} - - -/** - * This function checks StartPeerState_v2#finished, which is set when the hello was retrieved. - * - */ -static int -start_peer_finish (void *cls, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls) -{ - struct StartPeerState_v2 *sps = cls; - - if (GNUNET_YES == sps->finished) - { - cont (cont_cls); - } - - return sps->finished; -} - - -/** - * Disconnect callback for the connection to the core service. - * - */ -static void -notify_disconnect (void *cls, - const struct GNUNET_PeerIdentity *peer, - void *handler_cls) -{ - struct StartPeerState_v2 *sps = cls; - - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Peer %s disconnected from peer %u (`%s')\n", - GNUNET_i2s (peer), - sps->no, - GNUNET_i2s (&sps->id)); - -} - - -/** - * Connect callback for the connection to the core service. - * - */ -static void * -notify_connect (void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_MQ_Handle *mq) -{ - struct StartPeerState_v2 *sps = cls; - struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode); - struct GNUNET_HashCode hc; - int node_number; - - void *ret = NULL; - - - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Peer %s connected to peer %u (`%s')\n", - GNUNET_i2s (peer), - sps->no, - GNUNET_i2s (&sps->id)); - - // TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node. - node_number = 1; - GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc); - - - memcpy (key, - &hc, - sizeof (*key)); - GNUNET_CONTAINER_multishortmap_put (sps->connected_peers_map, - key, - mq, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); - - GNUNET_free (key); - // TODO what does the handler function need? - return ret; -} - - -/** - * The run method of this cmd will start all services of a peer to test the transport service. - * - */ -static void -start_peer_run (void *cls, - struct GNUNET_TESTING_Interpreter *is) -{ - struct StartPeerState_v2 *sps = cls; - char *emsg = NULL; - struct GNUNET_PeerIdentity dummy; - const struct GNUNET_TESTING_Command *system_cmd; - struct GNUNET_TESTING_System *tl_system; - char *home; - char *transport_unix_path; - char *communicator_unix_path; - char *bindto; - - if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname)) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - "File not found: `%s'\n", - sps->cfgname); - GNUNET_TESTING_interpreter_fail (is); - return; - } - - - sps->cfg = GNUNET_CONFIGURATION_create (); - GNUNET_assert (GNUNET_OK == - GNUNET_CONFIGURATION_load (sps->cfg, sps->cfgname)); - - GNUNET_asprintf (&home, - "$GNUNET_TMP/test-transport/api-tcp-p%u", - sps->no); - - GNUNET_asprintf (&transport_unix_path, - "$GNUNET_RUNTIME_DIR/tng-p%u.sock", - sps->no); - - GNUNET_asprintf (&communicator_unix_path, - "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock", - sps->no); - - GNUNET_asprintf (&bindto, - "%s:60002", - sps->node_ip); - - - GNUNET_CONFIGURATION_set_value_string (sps->cfg, "PATHS", "GNUNET_TEST_HOME", - home); - GNUNET_CONFIGURATION_set_value_string (sps->cfg, "transport", "UNIXPATH", - transport_unix_path); - GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp", - "BINDTO", - bindto); - GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp", - "UNIXPATH", - communicator_unix_path); - - system_cmd = GNUNET_TESTING_interpreter_lookup_command (is, - sps->system_label); - GNUNET_TESTING_get_trait_test_system (system_cmd, - &tl_system); - - sps->tl_system = tl_system; - - if (GNUNET_SYSERR == - GNUNET_TESTING_configuration_create (tl_system, - sps->cfg)) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - "Testing library failed to create unique configuration based on `%s'\n", - sps->cfgname); - GNUNET_CONFIGURATION_destroy (sps->cfg); - GNUNET_TESTING_interpreter_fail (is); - return; - } - - sps->peer = GNUNET_TESTING_peer_configure (sps->tl_system, - sps->cfg, - sps->no, - NULL, - &emsg); - if (NULL == sps->peer) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - "Testing library failed to create unique configuration based on `%s': `%s'\n", - sps->cfgname, - emsg); - GNUNET_free (emsg); - GNUNET_TESTING_interpreter_fail (is); - return; - } - - if (GNUNET_OK != GNUNET_TESTING_peer_start (sps->peer)) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - "Testing library failed to create unique configuration based on `%s'\n", - sps->cfgname); - GNUNET_free (emsg); - GNUNET_TESTING_interpreter_fail (is); - return; - } - - memset (&dummy, - '\0', - sizeof(dummy)); - - GNUNET_TESTING_peer_get_identity (sps->peer, - &sps->id); - - if (0 == memcmp (&dummy, - &sps->id, - sizeof(struct GNUNET_PeerIdentity))) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - "Testing library failed to obtain peer identity for peer %u\n", - sps->no); - GNUNET_free (emsg); - GNUNET_TESTING_interpreter_fail (is); - return; - } - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Peer %u configured with identity `%s'\n", - sps->no, - GNUNET_i2s_full (&sps->id)); - - sps->th = GNUNET_TRANSPORT_core_connect (sps->cfg, - NULL, - sps->handlers, - sps, - ¬ify_connect, - ¬ify_disconnect); - if (NULL == sps->th) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - "Failed to connect to transport service for peer `%s': `%s'\n", - sps->cfgname, - emsg); - GNUNET_free (emsg); - GNUNET_TESTING_interpreter_fail (is); - return; - } - - sps->ph = GNUNET_PEERSTORE_connect (sps->cfg); - if (NULL == sps->th) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - "Failed to connect to peerstore service for peer `%s': `%s'\n", - sps->cfgname, - emsg); - GNUNET_free (emsg); - GNUNET_TESTING_interpreter_fail (is); - return; - } - - sps->ah = GNUNET_TRANSPORT_application_init (sps->cfg); - if (NULL == sps->ah) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - "Failed to initialize the TRANSPORT application suggestion client handle for peer `%s': `%s'\n", - sps->cfgname, - emsg); - GNUNET_free (emsg); - GNUNET_TESTING_interpreter_fail (is); - return; - } - sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps); -} - - -/** - * The cleanup function of this cmd frees resources the cmd allocated. - * - */ -static void -start_peer_cleanup (void *cls) -{ - struct StartPeerState_v2 *sps = cls; - - if (NULL != sps->handlers) - { - GNUNET_free (sps->handlers); - sps->handlers = NULL; - } - if (NULL != sps->cfg) - { - GNUNET_CONFIGURATION_destroy (sps->cfg); - sps->cfg = NULL; - } - GNUNET_free (sps->hello); - GNUNET_free (sps->connected_peers_map); - GNUNET_free (sps); -} - - -/** - * This function prepares an array with traits. - * - */ -static int -start_peer_traits (void *cls, - const void **ret, - const char *trait, - unsigned int index) -{ - struct StartPeerState_v2 *sps = cls; - struct GNUNET_TRANSPORT_ApplicationHandle *ah = sps->ah; - struct GNUNET_PeerIdentity *id = &sps->id; - struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map = - sps->connected_peers_map; - char *hello = sps->hello; - size_t hello_size = sps->hello_size; - - - 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_TESTING_trait_end () - }; - - return GNUNET_TESTING_get_trait (traits, - ret, - trait, - index); -} - - -/** - * Function to get the trait with the struct StartPeerState_v2. - * - * @param[out] sps struct StartPeerState_v2. - * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. - * - */ -int -GNUNET_TRANSPORT_get_trait_state_v2 (const struct - GNUNET_TESTING_Command - *cmd, - struct StartPeerState_v2 **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_v2 (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_v2 (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_v2 (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_v2 (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_v2 (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. - * - * @param label name for command. - * @param system_label Label of the cmd to setup a test environment. - * @param m The number of the local node of the actual network namespace. - * @param n The number of the actual namespace. - * @param local_m Number of local nodes in each namespace. - * @param handlers Handler for messages received by this peer. - * @param cfgname Configuration file name for this peer. - * @return command. - */ -struct GNUNET_TESTING_Command -GNUNET_TRANSPORT_cmd_start_peer_v2 (const char *label, - const char *system_label, - uint32_t no, - char *node_ip, - struct GNUNET_MQ_MessageHandler *handlers, - const char *cfgname) -{ - struct StartPeerState_v2 *sps; - struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map = - GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO); - unsigned int i; - - sps = GNUNET_new (struct StartPeerState_v2); - sps->no = no; - sps->system_label = system_label; - sps->connected_peers_map = connected_peers_map; - sps->cfgname = cfgname; - sps->node_ip = node_ip; - - if (NULL != handlers) - { - for (i = 0; NULL != handlers[i].cb; i++) - ; - sps->handlers = GNUNET_new_array (i + 1, - struct GNUNET_MQ_MessageHandler); - GNUNET_memcpy (sps->handlers, - handlers, - i * sizeof(struct GNUNET_MQ_MessageHandler)); - } - - struct GNUNET_TESTING_Command cmd = { - .cls = sps, - .label = label, - .run = &start_peer_run, - .cleanup = &start_peer_cleanup, - .traits = &start_peer_traits - }; - - return cmd; -} diff --git a/src/transport/transport_api_cmd_start_peer_v3.c b/src/transport/transport_api_cmd_start_peer_v3.c deleted file mode 100644 index 1a19ce60e..000000000 --- a/src/transport/transport_api_cmd_start_peer_v3.c +++ /dev/null @@ -1,617 +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_api_cmd_start_peer.c - * @brief cmd to start a peer. - * @author t3sserakt - */ -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_testing_ng_lib.h" -#include "gnunet_peerstore_service.h" -#include "gnunet_transport_core_service.h" -#include "gnunet_transport_application_service.h" -#include "transport-testing-cmds.h" - -/** - * Generic logging shortcut - */ -#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) - - -static void -retrieve_hello (void *cls); - - -/** - * Callback delivering the hello of this peer from peerstore. - * - */ -static void -hello_iter_cb (void *cb_cls, - const struct GNUNET_PEERSTORE_Record *record, - const char *emsg) -{ - struct StartPeerState_v2 *sps = cb_cls; - if (NULL == record) - { - sps->pic = NULL; - sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps); - return; - } - // Check record type et al? - sps->hello_size = record->value_size; - sps->hello = GNUNET_malloc (sps->hello_size); - memcpy (sps->hello, record->value, sps->hello_size); - sps->hello[sps->hello_size - 1] = '\0'; - - GNUNET_PEERSTORE_iterate_cancel (sps->pic); - sps->pic = NULL; - sps->finished = GNUNET_YES; -} - - -/** - * Function to start the retrieval task to retrieve the hello of this peer - * from the peerstore. - * - */ -static void -retrieve_hello (void *cls) -{ - struct StartPeerState_v2 *sps = cls; - sps->rh_task = NULL; - sps->pic = GNUNET_PEERSTORE_iterate (sps->ph, - "transport", - &sps->id, - GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY, - hello_iter_cb, - sps); - -} - - -/** - * This function checks StartPeerState_v2#finished, which is set when the hello was retrieved. - * - */ -static int -start_peer_finish (void *cls, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls) -{ - struct StartPeerState_v2 *sps = cls; - - if (GNUNET_YES == sps->finished) - { - cont (cont_cls); - } - - return sps->finished; -} - - -/** - * Disconnect callback for the connection to the core service. - * - */ -static void -notify_disconnect (void *cls, - const struct GNUNET_PeerIdentity *peer, - void *handler_cls) -{ - struct StartPeerState_v2 *sps = cls; - - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Peer %s disconnected from peer %u (`%s')\n", - GNUNET_i2s (peer), - sps->no, - GNUNET_i2s (&sps->id)); - -} - - -/** - * Connect callback for the connection to the core service. - * - */ -static void * -notify_connect (void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_MQ_Handle *mq) -{ - struct StartPeerState_v2 *sps = cls; - struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode); - struct GNUNET_HashCode hc; - struct GNUNET_CRYPTO_EddsaPublicKey public_key = peer->public_key; - - void *ret = NULL; - - - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Peer %s connected to peer %u (`%s')\n", - GNUNET_i2s (peer), - sps->no, - GNUNET_i2s (&sps->id)); - - GNUNET_CRYPTO_hash (&public_key, sizeof(public_key), &hc); - - - memcpy (key, - &hc, - sizeof (*key)); - GNUNET_CONTAINER_multishortmap_put (sps->connected_peers_map, - key, - mq, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); - - GNUNET_free (key); - // TODO what does the handler function need? - return ret; -} - - -/** - * The run method of this cmd will start all services of a peer to test the transport service. - * - */ -static void -start_peer_run (void *cls, - struct GNUNET_TESTING_Interpreter *is) -{ - struct StartPeerState_v2 *sps = cls; - char *emsg = NULL; - struct GNUNET_PeerIdentity dummy; - const struct GNUNET_TESTING_Command *system_cmd; - struct GNUNET_TESTING_System *tl_system; - char *home; - char *transport_unix_path; - char *tcp_communicator_unix_path; - char *udp_communicator_unix_path; - char *bindto; - - if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname)) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - "File not found: `%s'\n", - sps->cfgname); - GNUNET_TESTING_interpreter_fail (is); - return; - } - - - sps->cfg = GNUNET_CONFIGURATION_create (); - GNUNET_assert (GNUNET_OK == - GNUNET_CONFIGURATION_load (sps->cfg, sps->cfgname)); - - GNUNET_asprintf (&home, - "$GNUNET_TMP/test-transport/api-tcp-p%u", - sps->no); - - GNUNET_asprintf (&transport_unix_path, - "$GNUNET_RUNTIME_DIR/tng-p%u.sock", - sps->no); - - GNUNET_asprintf (&tcp_communicator_unix_path, - "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock", - sps->no); - - GNUNET_asprintf (&udp_communicator_unix_path, - "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock", - sps->no); - - GNUNET_asprintf (&bindto, - "%s:60002", - sps->node_ip); - - LOG (GNUNET_ERROR_TYPE_ERROR, - "node_ip %s\n", - bindto); - - GNUNET_CONFIGURATION_set_value_string (sps->cfg, "PATHS", "GNUNET_TEST_HOME", - home); - GNUNET_CONFIGURATION_set_value_string (sps->cfg, "transport", "UNIXPATH", - transport_unix_path); - GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp", - "BINDTO", - bindto); - GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-udp", - "BINDTO", - bindto); - GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp", - "UNIXPATH", - tcp_communicator_unix_path); - GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-udp", - "UNIXPATH", - udp_communicator_unix_path); - - system_cmd = GNUNET_TESTING_interpreter_lookup_command (is, - sps->system_label); - GNUNET_TESTING_get_trait_test_system (system_cmd, - &tl_system); - - sps->tl_system = tl_system; - - if (GNUNET_SYSERR == - GNUNET_TESTING_configuration_create (tl_system, - sps->cfg)) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - "Testing library failed to create unique configuration based on `%s'\n", - sps->cfgname); - GNUNET_CONFIGURATION_destroy (sps->cfg); - GNUNET_TESTING_interpreter_fail (is); - return; - } - - sps->peer = GNUNET_TESTING_peer_configure (sps->tl_system, - sps->cfg, - sps->no, - NULL, - &emsg); - if (NULL == sps->peer) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - "Testing library failed to create unique configuration based on `%s': `%s'\n", - sps->cfgname, - emsg); - GNUNET_free (emsg); - GNUNET_TESTING_interpreter_fail (is); - return; - } - - if (GNUNET_OK != GNUNET_TESTING_peer_start (sps->peer)) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - "Testing library failed to create unique configuration based on `%s'\n", - sps->cfgname); - GNUNET_free (emsg); - GNUNET_TESTING_interpreter_fail (is); - return; - } - - memset (&dummy, - '\0', - sizeof(dummy)); - - GNUNET_TESTING_peer_get_identity (sps->peer, - &sps->id); - - if (0 == memcmp (&dummy, - &sps->id, - sizeof(struct GNUNET_PeerIdentity))) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - "Testing library failed to obtain peer identity for peer %u\n", - sps->no); - GNUNET_free (emsg); - GNUNET_TESTING_interpreter_fail (is); - return; - } - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Peer %u configured with identity `%s'\n", - sps->no, - GNUNET_i2s_full (&sps->id)); - - sps->th = GNUNET_TRANSPORT_core_connect (sps->cfg, - NULL, - sps->handlers, - sps, - ¬ify_connect, - ¬ify_disconnect); - if (NULL == sps->th) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - "Failed to connect to transport service for peer `%s': `%s'\n", - sps->cfgname, - emsg); - GNUNET_free (emsg); - GNUNET_TESTING_interpreter_fail (is); - return; - } - - sps->ph = GNUNET_PEERSTORE_connect (sps->cfg); - if (NULL == sps->th) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - "Failed to connect to peerstore service for peer `%s': `%s'\n", - sps->cfgname, - emsg); - GNUNET_free (emsg); - GNUNET_TESTING_interpreter_fail (is); - return; - } - - sps->ah = GNUNET_TRANSPORT_application_init (sps->cfg); - if (NULL == sps->ah) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - "Failed to initialize the TRANSPORT application suggestion client handle for peer `%s': `%s'\n", - sps->cfgname, - emsg); - GNUNET_free (emsg); - GNUNET_TESTING_interpreter_fail (is); - return; - } - sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps); -} - - -/** - * The cleanup function of this cmd frees resources the cmd allocated. - * - */ -static void -start_peer_cleanup (void *cls) -{ - struct StartPeerState_v2 *sps = cls; - - if (NULL != sps->handlers) - { - GNUNET_free (sps->handlers); - sps->handlers = NULL; - } - if (NULL != sps->cfg) - { - GNUNET_CONFIGURATION_destroy (sps->cfg); - sps->cfg = NULL; - } - GNUNET_free (sps->hello); - GNUNET_free (sps->connected_peers_map); - GNUNET_free (sps); -} - - -/** - * This function prepares an array with traits. - * - */ -static int -start_peer_traits (void *cls, - const void **ret, - const char *trait, - unsigned int index) -{ - struct StartPeerState_v2 *sps = cls; - struct GNUNET_TRANSPORT_ApplicationHandle *ah = sps->ah; - struct GNUNET_PeerIdentity *id = &sps->id; - struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map = - sps->connected_peers_map; - char *hello = sps->hello; - size_t hello_size = sps->hello_size; - - - 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_TESTING_trait_end () - }; - - return GNUNET_TESTING_get_trait (traits, - ret, - trait, - index); -} - - -/** - * Function to get the trait with the struct StartPeerState_v2. - * - * @param[out] sps struct StartPeerState_v2. - * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. - * - */ -int -GNUNET_TRANSPORT_get_trait_state_v3 (const struct - GNUNET_TESTING_Command - *cmd, - struct StartPeerState_v2 **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_v3 (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_v3 (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_v3 (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_v3 (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_v3 (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. - * - * @param label name for command. - * @param system_label Label of the cmd to setup a test environment. - * @param m The number of the local node of the actual network namespace. - * @param n The number of the actual namespace. - * @param local_m Number of local nodes in each namespace. - * @param handlers Handler for messages received by this peer. - * @param cfgname Configuration file name for this peer. - * @return command. - */ -struct GNUNET_TESTING_Command -GNUNET_TRANSPORT_cmd_start_peer_v3 (const char *label, - const char *system_label, - uint32_t no, - char *node_ip, - struct GNUNET_MQ_MessageHandler *handlers, - const char *cfgname) -{ - struct StartPeerState_v2 *sps; - struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map = - GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO); - unsigned int i; - - sps = GNUNET_new (struct StartPeerState_v2); - sps->no = no; - sps->system_label = system_label; - sps->connected_peers_map = connected_peers_map; - sps->cfgname = cfgname; - sps->node_ip = node_ip; - - if (NULL != handlers) - { - for (i = 0; NULL != handlers[i].cb; i++) - ; - sps->handlers = GNUNET_new_array (i + 1, - struct GNUNET_MQ_MessageHandler); - GNUNET_memcpy (sps->handlers, - handlers, - i * sizeof(struct GNUNET_MQ_MessageHandler)); - } - - struct GNUNET_TESTING_Command cmd = { - .cls = sps, - .label = label, - .run = &start_peer_run, - .cleanup = &start_peer_cleanup, - .traits = &start_peer_traits - }; - - return cmd; -} diff --git a/src/util/child_management.c b/src/util/child_management.c index 4ef42dba2..832e05ece 100644 --- a/src/util/child_management.c +++ b/src/util/child_management.c @@ -19,7 +19,7 @@ */ /** - * @file testing/child_management.c + * @file util/child_management.c * @brief Handling of child processes in GNUnet. * @author Christian Grothoff (ANASTASIS) * @author Dominik Meister (ANASTASIS) @@ -153,7 +153,9 @@ sighandler_child_death (void) errno = old_errno; /* restore errno */ } - +/** + * Initializing the signal pipe for child handling. + */ static void child_management_start (void) { @@ -191,6 +193,14 @@ child_management_done (void) } +/** + * Adding a child process to be monitored by the child management. + * + * @param proc The child process to be monitored. + * @param cp The callback to be called, when the child process completed. + * @param cb_cls The closure for the callback. + * @return An handle for the the child being monitored. + */ struct GNUNET_ChildWaitHandle * GNUNET_wait_child (struct GNUNET_OS_Process *proc, GNUNET_ChildCompletedCallback cb, @@ -219,6 +229,11 @@ GNUNET_wait_child (struct GNUNET_OS_Process *proc, } +/** + * Removing child handle. + * + * @param cwh The handle to be removed. + */ void GNUNET_wait_child_cancel (struct GNUNET_ChildWaitHandle *cwh) { -- cgit v1.2.3