From d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb Mon Sep 17 00:00:00 2001 From: ng0 Date: Sun, 8 Sep 2019 12:33:09 +0000 Subject: uncrustify as demanded. --- src/testbed/generate-underlay-topology.c | 375 ++-- src/testbed/gnunet-daemon-latency-logger.c | 264 ++- src/testbed/gnunet-daemon-testbed-blacklist.c | 170 +- src/testbed/gnunet-daemon-testbed-underlay.c | 366 ++-- src/testbed/gnunet-helper-testbed.c | 556 +++--- src/testbed/gnunet-service-test-barriers.c | 80 +- src/testbed/gnunet-service-testbed.c | 919 ++++----- src/testbed/gnunet-service-testbed.h | 223 +-- src/testbed/gnunet-service-testbed_barriers.c | 740 ++++--- src/testbed/gnunet-service-testbed_barriers.h | 60 +- src/testbed/gnunet-service-testbed_cache.c | 147 +- .../gnunet-service-testbed_connectionpool.c | 676 +++---- .../gnunet-service-testbed_connectionpool.h | 37 +- src/testbed/gnunet-service-testbed_cpustatus.c | 363 ++-- src/testbed/gnunet-service-testbed_links.c | 1147 ++++++----- src/testbed/gnunet-service-testbed_links.h | 61 +- src/testbed/gnunet-service-testbed_meminfo.c | 185 +- src/testbed/gnunet-service-testbed_meminfo.h | 4 +- src/testbed/gnunet-service-testbed_oc.c | 1658 ++++++++-------- src/testbed/gnunet-service-testbed_peers.c | 1630 ++++++++-------- src/testbed/gnunet-testbed-profiler.c | 222 +-- src/testbed/gnunet_mpi_test.c | 122 +- src/testbed/gnunet_testbed_mpi_spawn.c | 293 +-- src/testbed/test_gnunet_helper_testbed.c | 112 +- src/testbed/test_testbed_api.c | 359 ++-- src/testbed/test_testbed_api_2peers_1controller.c | 396 ++-- src/testbed/test_testbed_api_3peers_3controllers.c | 968 ++++----- src/testbed/test_testbed_api_barriers.c | 163 +- src/testbed/test_testbed_api_controllerlink.c | 770 ++++---- src/testbed/test_testbed_api_hosts.c | 155 +- src/testbed/test_testbed_api_operations.c | 469 ++--- .../test_testbed_api_peer_reconfiguration.c | 108 +- .../test_testbed_api_peers_manage_services.c | 133 +- src/testbed/test_testbed_api_sd.c | 76 +- src/testbed/test_testbed_api_statistics.c | 108 +- src/testbed/test_testbed_api_test.c | 173 +- src/testbed/test_testbed_api_test_timeout.c | 82 +- src/testbed/test_testbed_api_testbed_run.c | 181 +- src/testbed/test_testbed_api_topology.c | 150 +- src/testbed/test_testbed_api_topology_clique.c | 142 +- src/testbed/test_testbed_underlay.c | 106 +- src/testbed/testbed.h | 134 +- src/testbed/testbed_api.c | 2063 ++++++++++---------- src/testbed/testbed_api.h | 134 +- src/testbed/testbed_api_barriers.c | 236 +-- src/testbed/testbed_api_hosts.c | 1081 +++++----- src/testbed/testbed_api_hosts.h | 55 +- src/testbed/testbed_api_operations.c | 794 ++++---- src/testbed/testbed_api_operations.h | 41 +- src/testbed/testbed_api_peers.c | 727 +++---- src/testbed/testbed_api_peers.h | 65 +- src/testbed/testbed_api_sd.c | 82 +- src/testbed/testbed_api_sd.h | 12 +- src/testbed/testbed_api_services.c | 129 +- src/testbed/testbed_api_statistics.c | 207 +- src/testbed/testbed_api_test.c | 51 +- src/testbed/testbed_api_testbed.c | 1179 +++++------ src/testbed/testbed_api_topology.c | 1368 ++++++------- src/testbed/testbed_api_topology.h | 20 +- src/testbed/testbed_api_underlay.c | 105 +- src/testbed/testbed_helper.h | 8 +- 61 files changed, 11741 insertions(+), 11699 deletions(-) (limited to 'src/testbed') diff --git a/src/testbed/generate-underlay-topology.c b/src/testbed/generate-underlay-topology.c index 7857652e0..a463d384a 100644 --- a/src/testbed/generate-underlay-topology.c +++ b/src/testbed/generate-underlay-topology.c @@ -11,12 +11,12 @@ 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/generate-underlay-topology.c @@ -30,10 +30,10 @@ #include "testbed_api_topology.h" #include "sqlite3.h" -#define LOG(type, ...) GNUNET_log (type, __VA_ARGS__) +#define LOG(type, ...) GNUNET_log(type, __VA_ARGS__) -#define LOG_ERROR(...) LOG (GNUNET_ERROR_TYPE_ERROR, __VA_ARGS__) +#define LOG_ERROR(...) LOG(GNUNET_ERROR_TYPE_ERROR, __VA_ARGS__) /** * Log an error message at log-level 'level' that indicates @@ -42,22 +42,22 @@ */ #define LOG_SQLITE(db, msg, level, cmd) \ do \ - { \ - GNUNET_log_from (level, \ - "sqlite", \ - _ ("`%s' failed at %s:%d with error: %s\n"), \ - cmd, \ - __FILE__, \ - __LINE__, \ - sqlite3_errmsg (db)); \ - if (msg != NULL) \ + { \ + GNUNET_log_from(level, \ + "sqlite", \ + _("`%s' failed at %s:%d with error: %s\n"), \ + cmd, \ + __FILE__, \ + __LINE__, \ + sqlite3_errmsg(db)); \ + if (msg != NULL) \ GNUNET_asprintf (msg, \ - _ ("`%s' failed at %s:%u with error: %s"), \ + _("`%s' failed at %s:%u with error: %s"), \ cmd, \ __FILE__, \ __LINE__, \ - sqlite3_errmsg (db)); \ - } while (0) + sqlite3_errmsg(db)); \ + } while (0) /** @@ -98,43 +98,43 @@ static int exit_result; * @return GNUNET_OK to continue processing; GNUNET_SYSERR to abort */ static int -link_processor (void *cls, - unsigned int A, - unsigned int B, - unsigned int bandwidth, - unsigned int latency, - unsigned int loss) +link_processor(void *cls, + unsigned int A, + unsigned int B, + unsigned int bandwidth, + unsigned int latency, + unsigned int loss) { - if ((SQLITE_OK != sqlite3_bind_int (stmt_insert, 1, A)) || - (SQLITE_OK != sqlite3_bind_int (stmt_insert, 2, B)) || - (SQLITE_OK != sqlite3_bind_int (stmt_insert, 3, bandwidth)) || - (SQLITE_OK != sqlite3_bind_int (stmt_insert, 4, latency)) || - (SQLITE_OK != sqlite3_bind_int (stmt_insert, 5, loss))) - { - LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_bind_int"); - return GNUNET_SYSERR; - } - if (SQLITE_DONE != sqlite3_step (stmt_insert)) - { - LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_step"); - return GNUNET_SYSERR; - } - fprintf (stdout, "%u -> %u\n", A, B); - GNUNET_break (SQLITE_OK == sqlite3_reset (stmt_insert)); + if ((SQLITE_OK != sqlite3_bind_int(stmt_insert, 1, A)) || + (SQLITE_OK != sqlite3_bind_int(stmt_insert, 2, B)) || + (SQLITE_OK != sqlite3_bind_int(stmt_insert, 3, bandwidth)) || + (SQLITE_OK != sqlite3_bind_int(stmt_insert, 4, latency)) || + (SQLITE_OK != sqlite3_bind_int(stmt_insert, 5, loss))) + { + LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_bind_int"); + return GNUNET_SYSERR; + } + if (SQLITE_DONE != sqlite3_step(stmt_insert)) + { + LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_step"); + return GNUNET_SYSERR; + } + fprintf(stdout, "%u -> %u\n", A, B); + GNUNET_break(SQLITE_OK == sqlite3_reset(stmt_insert)); //GNUNET_break (SQLITE_OK == sqlite3_clear_bindings (stmt_insert)); - if ((SQLITE_OK != sqlite3_bind_int (stmt_insert, 1, B)) || - (SQLITE_OK != sqlite3_bind_int (stmt_insert, 2, A))) - { - LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_bind_int"); - return GNUNET_SYSERR; - } - if (SQLITE_DONE != sqlite3_step (stmt_insert)) - { - LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_step"); - return GNUNET_SYSERR; - } - fprintf (stdout, "%u -> %u\n", B, A); - GNUNET_break (SQLITE_OK == sqlite3_reset (stmt_insert)); + if ((SQLITE_OK != sqlite3_bind_int(stmt_insert, 1, B)) || + (SQLITE_OK != sqlite3_bind_int(stmt_insert, 2, A))) + { + LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_bind_int"); + return GNUNET_SYSERR; + } + if (SQLITE_DONE != sqlite3_step(stmt_insert)) + { + LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_step"); + return GNUNET_SYSERR; + } + fprintf(stdout, "%u -> %u\n", B, A); + GNUNET_break(SQLITE_OK == sqlite3_reset(stmt_insert)); return GNUNET_OK; } @@ -148,7 +148,7 @@ link_processor (void *cls, * to be printed) */ static int -setup_db (const char *dbfile) +setup_db(const char *dbfile) { const char *query_create = "CREATE TABLE whitelist (" "id INTEGER," @@ -176,28 +176,28 @@ setup_db (const char *dbfile) int ret; ret = GNUNET_SYSERR; - if (SQLITE_OK != sqlite3_open (dbfile, &db)) - { - LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_open"); - goto err_ret; - } - if (0 != sqlite3_exec (db, query_create, NULL, NULL, NULL)) - { - LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec"); - fprintf (stderr, - "Error: %d. Perhaps the database `%s' already exits.\n", - sqlite3_errcode (db), - dbfile); - goto err_ret; - } - GNUNET_break (0 == - sqlite3_exec (db, "PRAGMA synchronous = 0;", NULL, NULL, NULL)); + if (SQLITE_OK != sqlite3_open(dbfile, &db)) + { + LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_open"); + goto err_ret; + } + if (0 != sqlite3_exec(db, query_create, NULL, NULL, NULL)) + { + LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec"); + fprintf(stderr, + "Error: %d. Perhaps the database `%s' already exits.\n", + sqlite3_errcode(db), + dbfile); + goto err_ret; + } + GNUNET_break(0 == + sqlite3_exec(db, "PRAGMA synchronous = 0;", NULL, NULL, NULL)); if (SQLITE_OK != - sqlite3_prepare_v2 (db, query_insert, -1, &stmt_insert, NULL)) - { - LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_prepare_v2"); - goto err_ret; - } + sqlite3_prepare_v2(db, query_insert, -1, &stmt_insert, NULL)) + { + LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_prepare_v2"); + goto err_ret; + } ret = GNUNET_OK; err_ret: @@ -214,10 +214,10 @@ err_ret: * @param cfg the configuration file handle */ static void -run (void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *config) +run(void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *config) { const char *dbfile; const char *topology_string; @@ -231,118 +231,125 @@ run (void *cls, arg_uint1 = 0; /* make compilers happy */ arg_uint2 = 0; /* make compilers happy */ if (NULL == args) - { - LOG_ERROR (_ ("Need at least 2 arguments\n")); - return; - } + { + LOG_ERROR(_("Need at least 2 arguments\n")); + return; + } if (NULL == (dbfile = args[argc++])) - { - LOG_ERROR (_ ("Database filename missing\n")); - return; - } - if (GNUNET_OK != setup_db (dbfile)) - return; - if (NULL == (topology_string = args[argc++])) - { - LOG_ERROR (_ ("Topology string missing\n")); - return; - } - if (GNUNET_YES != GNUNET_TESTBED_topology_get_ (&topology, topology_string)) - { - LOG_ERROR (_ ("Invalid topology: %s\n"), topology_string); - return; - } - arg_str1 = NULL; - /* parse for first TOPOOPT. This can either be arg_uint1 or arg_str1 */ - switch (topology) - { - case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: - case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: - case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: - case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: - if (NULL == (value = args[argc++])) { - LOG_ERROR (_ ("An argument is missing for given topology `%s'\n"), - topology_string); + LOG_ERROR(_("Database filename missing\n")); return; } - if (-1 == sscanf (value, "%u", &arg_uint1)) + if (GNUNET_OK != setup_db(dbfile)) + return; + if (NULL == (topology_string = args[argc++])) { - LOG_ERROR (_ ("Invalid argument `%s' given as topology argument\n"), - value); + LOG_ERROR(_("Topology string missing\n")); return; } - break; - case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: - if (NULL == (arg_str1 = args[argc++])) + if (GNUNET_YES != GNUNET_TESTBED_topology_get_(&topology, topology_string)) { - LOG_ERROR (_ ("Filename argument missing for topology `%s'\n"), - topology_string); + LOG_ERROR(_("Invalid topology: %s\n"), topology_string); return; } - break; - default: - break; - } - /* parse for second TOPOOPT. Only required for SCALE_FREE topology */ + arg_str1 = NULL; + /* parse for first TOPOOPT. This can either be arg_uint1 or arg_str1 */ switch (topology) - { - case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: - if (NULL == (value = args[argc++])) { - LOG_ERROR (_ ("Second argument for topology `%s' is missing\n"), - topology_string); - return; + case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: + case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: + case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: + case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: + if (NULL == (value = args[argc++])) + { + LOG_ERROR(_("An argument is missing for given topology `%s'\n"), + topology_string); + return; + } + if (-1 == sscanf(value, "%u", &arg_uint1)) + { + LOG_ERROR(_("Invalid argument `%s' given as topology argument\n"), + value); + return; + } + break; + + case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: + if (NULL == (arg_str1 = args[argc++])) + { + LOG_ERROR(_("Filename argument missing for topology `%s'\n"), + topology_string); + return; + } + break; + + default: + break; } - if (-1 == sscanf (value, "%u", &arg_uint2)) + /* parse for second TOPOOPT. Only required for SCALE_FREE topology */ + switch (topology) { - LOG_ERROR (_ ("Invalid argument `%s'; expecting unsigned int\n"), value); - return; + case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: + if (NULL == (value = args[argc++])) + { + LOG_ERROR(_("Second argument for topology `%s' is missing\n"), + topology_string); + return; + } + if (-1 == sscanf(value, "%u", &arg_uint2)) + { + LOG_ERROR(_("Invalid argument `%s'; expecting unsigned int\n"), value); + return; + } + break; + + default: + break; } - break; - default: - break; - } /* contruct topologies */ switch (topology) - { - case GNUNET_TESTBED_TOPOLOGY_LINE: - case GNUNET_TESTBED_TOPOLOGY_RING: - case GNUNET_TESTBED_TOPOLOGY_STAR: - case GNUNET_TESTBED_TOPOLOGY_CLIQUE: - case GNUNET_TESTBED_TOPOLOGY_2D_TORUS: - GNUNET_TESTBED_underlay_construct_ (num_peers, - link_processor, - NULL, - topology); - break; - case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: - case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: - case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: - GNUNET_TESTBED_underlay_construct_ (num_peers, - link_processor, - NULL, - topology, - arg_uint1); - break; - case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: - GNUNET_TESTBED_underlay_construct_ (num_peers, - link_processor, - NULL, - topology, - arg_str1); - break; - case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: - GNUNET_TESTBED_underlay_construct_ (num_peers, - link_processor, - NULL, - topology, - arg_uint1, - arg_uint2); - break; - default: - GNUNET_assert (0); - } + { + case GNUNET_TESTBED_TOPOLOGY_LINE: + case GNUNET_TESTBED_TOPOLOGY_RING: + case GNUNET_TESTBED_TOPOLOGY_STAR: + case GNUNET_TESTBED_TOPOLOGY_CLIQUE: + case GNUNET_TESTBED_TOPOLOGY_2D_TORUS: + GNUNET_TESTBED_underlay_construct_(num_peers, + link_processor, + NULL, + topology); + break; + + case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: + case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: + case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: + GNUNET_TESTBED_underlay_construct_(num_peers, + link_processor, + NULL, + topology, + arg_uint1); + break; + + case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: + GNUNET_TESTBED_underlay_construct_(num_peers, + link_processor, + NULL, + topology, + arg_str1); + break; + + case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: + GNUNET_TESTBED_underlay_construct_(num_peers, + link_processor, + NULL, + topology, + arg_uint1, + arg_uint2); + break; + + default: + GNUNET_assert(0); + } } @@ -350,25 +357,25 @@ run (void *cls, * Main */ int -main (int argc, char *const argv[]) +main(int argc, char *const argv[]) { struct GNUNET_GETOPT_CommandLineOption option[] = { - - GNUNET_GETOPT_option_uint ('p', - "num-peers", - "COUNT", - gettext_noop ("create COUNT number of peers"), - &num_peers), - GNUNET_GETOPT_OPTION_END}; + GNUNET_GETOPT_option_uint('p', + "num-peers", + "COUNT", + gettext_noop("create COUNT number of peers"), + &num_peers), + GNUNET_GETOPT_OPTION_END + }; int ret; exit_result = GNUNET_SYSERR; - ret = GNUNET_PROGRAM_run ( + ret = GNUNET_PROGRAM_run( argc, argv, "gnunet-underlay-topology", - _ ( + _( "Generates SQLite3 database representing a given underlay topology.\n" "Usage: gnunet-underlay-topology [OPTIONS] db-filename TOPO [TOPOOPTS]\n" "The following options are available for TOPO followed by TOPOOPTS if applicable:\n" @@ -391,9 +398,9 @@ main (int argc, char *const argv[]) &run, NULL); if (NULL != stmt_insert) - sqlite3_finalize (stmt_insert); + sqlite3_finalize(stmt_insert); if (NULL != db) - GNUNET_break (SQLITE_OK == sqlite3_close (db)); + GNUNET_break(SQLITE_OK == sqlite3_close(db)); if ((GNUNET_OK != ret) || (GNUNET_OK != exit_result)) return 1; return 0; diff --git a/src/testbed/gnunet-daemon-latency-logger.c b/src/testbed/gnunet-daemon-latency-logger.c index a1685d849..5e0fffe2b 100644 --- a/src/testbed/gnunet-daemon-latency-logger.c +++ b/src/testbed/gnunet-daemon-latency-logger.c @@ -11,12 +11,12 @@ 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/gnunet-daemon-latency-logger.c @@ -33,14 +33,14 @@ /** * Logging shorthand */ -#define LOG(type,...) \ - GNUNET_log (type, __VA_ARGS__) +#define LOG(type, ...) \ + GNUNET_log(type, __VA_ARGS__) /** * Debug logging shorthand */ #define DEBUG(...) \ - LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) + LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) /** * Log an error message at log-level 'level' that indicates @@ -49,19 +49,18 @@ */ #define LOG_SQLITE(db, msg, level, cmd) \ do { \ - GNUNET_log_from (level, "sqlite", _("`%s' failed at %s:%d with error: %s\n"), \ - cmd, __FILE__,__LINE__, sqlite3_errmsg(db)); \ - if (msg != NULL) \ - GNUNET_asprintf(msg, _("`%s' failed at %s:%u with error: %s"), cmd, \ - __FILE__, __LINE__, sqlite3_errmsg(db)); \ - } while(0) + GNUNET_log_from(level, "sqlite", _("`%s' failed at %s:%d with error: %s\n"), \ + cmd, __FILE__, __LINE__, sqlite3_errmsg(db)); \ + if (msg != NULL) \ + GNUNET_asprintf (msg, _("`%s' failed at %s:%u with error: %s"), cmd, \ + __FILE__, __LINE__, sqlite3_errmsg(db)); \ + } while (0) /** * Entry type to be used in the map to store old latency values */ -struct Entry -{ +struct Entry { /** * The peer's identity */ @@ -72,7 +71,6 @@ struct Entry * FIXME: type! */ unsigned int latency; - }; @@ -109,15 +107,15 @@ static struct sqlite3_stmt *stmt_insert; * #GNUNET_NO if not. */ static int -free_iterator (void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +free_iterator(void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct Entry *e = cls; - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove (map, key, e)); - GNUNET_free (e); + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multipeermap_remove(map, key, e)); + GNUNET_free(e); return GNUNET_YES; } @@ -129,24 +127,24 @@ free_iterator (void *cls, * @return */ static void -do_shutdown (void *cls) +do_shutdown(void *cls) { - GNUNET_ATS_performance_done (ats); + GNUNET_ATS_performance_done(ats); ats = NULL; if (NULL != stmt_insert) - { - sqlite3_finalize (stmt_insert); - stmt_insert = NULL; - } - GNUNET_break (SQLITE_OK == sqlite3_close (db)); + { + sqlite3_finalize(stmt_insert); + stmt_insert = NULL; + } + GNUNET_break(SQLITE_OK == sqlite3_close(db)); db = NULL; if (NULL != map) - { - GNUNET_assert (GNUNET_SYSERR != - GNUNET_CONTAINER_multipeermap_iterate (map, free_iterator, NULL)); - GNUNET_CONTAINER_multipeermap_destroy (map); - map = NULL; - } + { + GNUNET_assert(GNUNET_SYSERR != + GNUNET_CONTAINER_multipeermap_iterate(map, free_iterator, NULL)); + GNUNET_CONTAINER_multipeermap_destroy(map); + map = NULL; + } } /** @@ -163,85 +161,85 @@ do_shutdown (void *cls) * @param prop performance data for the address (as far as known) */ static void -addr_info_cb (void *cls, - const struct GNUNET_HELLO_Address *address, - int address_active, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - const struct GNUNET_ATS_Properties *prop) +addr_info_cb(void *cls, + const struct GNUNET_HELLO_Address *address, + int address_active, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + const struct GNUNET_ATS_Properties *prop) { static const char *query_insert = - "INSERT INTO ats_info(" - " id," - " val," - " timestamp" - ") VALUES (" - " ?1," - " ?2," - " datetime('now')" - ");"; + "INSERT INTO ats_info(" + " id," + " val," + " timestamp" + ") VALUES (" + " ?1," + " ?2," + " datetime('now')" + ");"; struct Entry *entry; int latency; /* FIXME: type!? */ if (NULL == address) - { - /* ATS service temporarily disconnected */ - return; - } + { + /* ATS service temporarily disconnected */ + return; + } - GNUNET_assert (NULL != db); + GNUNET_assert(NULL != db); if (GNUNET_YES != address_active) return; - latency = (int) prop->delay.rel_value_us; + latency = (int)prop->delay.rel_value_us; entry = NULL; - if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (map, - &address->peer)) - { - entry = GNUNET_CONTAINER_multipeermap_get (map, &address->peer); - GNUNET_assert (NULL != entry); - if (latency == entry->latency) - return; - } + if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains(map, + &address->peer)) + { + entry = GNUNET_CONTAINER_multipeermap_get(map, &address->peer); + GNUNET_assert(NULL != entry); + if (latency == entry->latency) + return; + } if (NULL == stmt_insert) - { - if (SQLITE_OK != sqlite3_prepare_v2 (db, query_insert, -1, &stmt_insert, - NULL)) { - LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_prepare_v2"); + if (SQLITE_OK != sqlite3_prepare_v2(db, query_insert, -1, &stmt_insert, + NULL)) + { + LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_prepare_v2"); + goto err_shutdown; + } + } + if ((SQLITE_OK != sqlite3_bind_text(stmt_insert, 1, + GNUNET_i2s(&address->peer), -1, + SQLITE_STATIC)) || + (SQLITE_OK != sqlite3_bind_int(stmt_insert, 2, latency))) + { + LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_bind_text"); + goto err_shutdown; + } + if (SQLITE_DONE != sqlite3_step(stmt_insert)) + { + LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_step"); + goto err_shutdown; + } + if (SQLITE_OK != sqlite3_reset(stmt_insert)) + { + LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_insert"); goto err_shutdown; } - } - if ( (SQLITE_OK != sqlite3_bind_text (stmt_insert, 1, - GNUNET_i2s (&address->peer), -1, - SQLITE_STATIC)) || - (SQLITE_OK != sqlite3_bind_int (stmt_insert, 2, latency)) ) - { - LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_bind_text"); - goto err_shutdown; - } - if (SQLITE_DONE != sqlite3_step (stmt_insert)) - { - LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_step"); - goto err_shutdown; - } - if (SQLITE_OK != sqlite3_reset (stmt_insert)) - { - LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_insert"); - goto err_shutdown; - } if (NULL == entry) - { - entry = GNUNET_new (struct Entry); - entry->id = address->peer; - GNUNET_CONTAINER_multipeermap_put (map, - &entry->id, entry, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); - } + { + entry = GNUNET_new(struct Entry); + entry->id = address->peer; + GNUNET_CONTAINER_multipeermap_put(map, + &entry->id, entry, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); + } entry->latency = latency; return; - err_shutdown: - GNUNET_SCHEDULER_shutdown (); +err_shutdown: + GNUNET_SCHEDULER_shutdown(); } @@ -254,45 +252,45 @@ addr_info_cb (void *cls, * @param c configuration */ static void -run (void *cls, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *c) +run(void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *c) { const char *query_create = - "CREATE TABLE ats_info (" - "id TEXT," - "val INTEGER," - "timestamp NUMERIC" - ");"; + "CREATE TABLE ats_info (" + "id TEXT," + "val INTEGER," + "timestamp NUMERIC" + ");"; char *dbfile; - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, "LATENCY-LOGGER", - "DBFILE", - &dbfile)) - { - GNUNET_break (0); - return; - } - if (SQLITE_OK != sqlite3_open (dbfile, &db)) - { - if (NULL != db) + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(c, "LATENCY-LOGGER", + "DBFILE", + &dbfile)) { - LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite_open_v2"); - GNUNET_break (SQLITE_OK == sqlite3_close (db)); + GNUNET_break(0); + return; } - else - LOG (GNUNET_ERROR_TYPE_ERROR, "Cannot open sqlite file %s\n", dbfile); - GNUNET_free (dbfile); - return; - } - if (0 != sqlite3_exec (db, query_create, NULL, NULL, NULL)) - DEBUG ("SQLite Error: %d. Perhaps the database `%s' already exits.\n", - sqlite3_errcode (db), dbfile); - DEBUG ("Opened database %s\n", dbfile); - GNUNET_free (dbfile); + if (SQLITE_OK != sqlite3_open(dbfile, &db)) + { + if (NULL != db) + { + LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite_open_v2"); + GNUNET_break(SQLITE_OK == sqlite3_close(db)); + } + else + LOG(GNUNET_ERROR_TYPE_ERROR, "Cannot open sqlite file %s\n", dbfile); + GNUNET_free(dbfile); + return; + } + if (0 != sqlite3_exec(db, query_create, NULL, NULL, NULL)) + DEBUG("SQLite Error: %d. Perhaps the database `%s' already exits.\n", + sqlite3_errcode(db), dbfile); + DEBUG("Opened database %s\n", dbfile); + GNUNET_free(dbfile); dbfile = NULL; - ats = GNUNET_ATS_performance_init (c, &addr_info_cb, NULL); - map = GNUNET_CONTAINER_multipeermap_create (30, GNUNET_YES); - GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); + ats = GNUNET_ATS_performance_init(c, &addr_info_cb, NULL); + map = GNUNET_CONTAINER_multipeermap_create(30, GNUNET_YES); + GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); } @@ -300,20 +298,20 @@ run (void *cls, char *const *args, const char *cfgfile, * Execution entry point */ int -main (int argc, char * const *argv) +main(int argc, char * const *argv) { static const struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; int ret; - if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) + if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) return 2; ret = - (GNUNET_OK == - GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-latency-logger", - _("Daemon to log latency values of connections to neighbours"), - options, &run, NULL)) ? 0 : 1; - GNUNET_free ((void*) argv); + (GNUNET_OK == + GNUNET_PROGRAM_run(argc, argv, "gnunet-daemon-latency-logger", + _("Daemon to log latency values of connections to neighbours"), + options, &run, NULL)) ? 0 : 1; + GNUNET_free((void*)argv); return ret; } diff --git a/src/testbed/gnunet-daemon-testbed-blacklist.c b/src/testbed/gnunet-daemon-testbed-blacklist.c index a91c6a161..e894fb79d 100644 --- a/src/testbed/gnunet-daemon-testbed-blacklist.c +++ b/src/testbed/gnunet-daemon-testbed-blacklist.c @@ -11,12 +11,12 @@ 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 -*/ + */ /** @@ -34,14 +34,14 @@ /** * Logging shorthand */ -#define LOG(type,...) \ - GNUNET_log (type, __VA_ARGS__) +#define LOG(type, ...) \ + GNUNET_log(type, __VA_ARGS__) /** * Debug logging shorthand */ #define DEBUG(...) \ - LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) + LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) /** * Allow access from the peers read from the whitelist @@ -79,13 +79,13 @@ static int mode; * Cleaup and destroy the map */ static void -cleanup_map () +cleanup_map() { if (NULL != map) - { - GNUNET_CONTAINER_multipeermap_destroy (map); - map = NULL; - } + { + GNUNET_CONTAINER_multipeermap_destroy(map); + map = NULL; + } } @@ -95,11 +95,11 @@ cleanup_map () * @param cls NULL */ static void -do_shutdown (void *cls) +do_shutdown(void *cls) { - cleanup_map (); + cleanup_map(); if (NULL != bh) - GNUNET_TRANSPORT_blacklist_cancel (bh); + GNUNET_TRANSPORT_blacklist_cancel(bh); } @@ -111,12 +111,12 @@ do_shutdown (void *cls) * @return GNUNET_OK if the connection is allowed, GNUNET_SYSERR if not */ static int -check_access (void *cls, const struct GNUNET_PeerIdentity * pid) +check_access(void *cls, const struct GNUNET_PeerIdentity * pid) { int contains; if (NULL != map) - contains = GNUNET_CONTAINER_multipeermap_contains (map, pid); + contains = GNUNET_CONTAINER_multipeermap_contains(map, pid); else contains = GNUNET_NO; if (ACCESS_DENY == mode) @@ -133,42 +133,42 @@ check_access (void *cls, const struct GNUNET_PeerIdentity * pid) * @param cfg the configuration for connecting to the peer's transport service */ static void -setup_ac (const char *fname, - const struct GNUNET_CONFIGURATION_Handle *cfg) +setup_ac(const char *fname, + const struct GNUNET_CONFIGURATION_Handle *cfg) { uint64_t fsize; unsigned int npeers; unsigned int cnt; - GNUNET_assert (GNUNET_OK != - GNUNET_DISK_file_size (fname, &fsize, GNUNET_NO, - GNUNET_YES)); - if (0 != (fsize % sizeof (struct GNUNET_PeerIdentity))) - { - GNUNET_break (0); - return; - } - npeers = fsize / sizeof (struct GNUNET_PeerIdentity); + GNUNET_assert(GNUNET_OK != + GNUNET_DISK_file_size(fname, &fsize, GNUNET_NO, + GNUNET_YES)); + if (0 != (fsize % sizeof(struct GNUNET_PeerIdentity))) + { + GNUNET_break(0); + return; + } + npeers = fsize / sizeof(struct GNUNET_PeerIdentity); if (0 != npeers) - { - map = GNUNET_CONTAINER_multipeermap_create (npeers, GNUNET_YES); - ilist = GNUNET_malloc_large (fsize); - GNUNET_assert (fsize == GNUNET_DISK_fn_read (fname, ilist, fsize)); - } + { + map = GNUNET_CONTAINER_multipeermap_create(npeers, GNUNET_YES); + ilist = GNUNET_malloc_large(fsize); + GNUNET_assert(fsize == GNUNET_DISK_fn_read(fname, ilist, fsize)); + } for (cnt = 0; cnt < npeers; cnt++) - { - if (GNUNET_SYSERR == - GNUNET_CONTAINER_multipeermap_put (map, &ilist[cnt], - &ilist[cnt], - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) { - cleanup_map (); - GNUNET_free (ilist); - return; + if (GNUNET_SYSERR == + GNUNET_CONTAINER_multipeermap_put(map, &ilist[cnt], + &ilist[cnt], + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) + { + cleanup_map(); + GNUNET_free(ilist); + return; + } } - } - GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); - bh = GNUNET_TRANSPORT_blacklist (cfg, &check_access, NULL); + GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); + bh = GNUNET_TRANSPORT_blacklist(cfg, &check_access, NULL); } @@ -181,45 +181,45 @@ setup_ac (const char *fname, * @param c configuration */ static void -run (void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *c) +run(void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *c) { char *shome; char *fname; if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (c, - "PATHS", - "GNUNET_HOME", - &shome)) - { - GNUNET_break (0); - return; - } - GNUNET_asprintf (&fname, - "%s/whitelist", - shome); - if (GNUNET_YES == GNUNET_DISK_file_test (fname)) - { - mode = ACCESS_ALLOW; - setup_ac (fname, c); - GNUNET_free (shome); - GNUNET_free (fname); - return; - } - GNUNET_free (fname); - GNUNET_asprintf (&fname, - "%s/blacklist", - shome); - if (GNUNET_YES == GNUNET_DISK_file_test (fname)) - { - mode = ACCESS_DENY; - setup_ac (shome, c); - } - GNUNET_free (shome); - GNUNET_free (fname); + GNUNET_CONFIGURATION_get_value_filename(c, + "PATHS", + "GNUNET_HOME", + &shome)) + { + GNUNET_break(0); + return; + } + GNUNET_asprintf(&fname, + "%s/whitelist", + shome); + if (GNUNET_YES == GNUNET_DISK_file_test(fname)) + { + mode = ACCESS_ALLOW; + setup_ac(fname, c); + GNUNET_free(shome); + GNUNET_free(fname); + return; + } + GNUNET_free(fname); + GNUNET_asprintf(&fname, + "%s/blacklist", + shome); + if (GNUNET_YES == GNUNET_DISK_file_test(fname)) + { + mode = ACCESS_DENY; + setup_ac(shome, c); + } + GNUNET_free(shome); + GNUNET_free(fname); } @@ -231,7 +231,7 @@ run (void *cls, * @return 0 ok, 1 on error */ int -main (int argc, char *const *argv) +main(int argc, char *const *argv) { static const struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END @@ -239,15 +239,15 @@ main (int argc, char *const *argv) int ret; if (GNUNET_OK != - GNUNET_STRINGS_get_utf8_args (argc, argv, - &argc, &argv)) + GNUNET_STRINGS_get_utf8_args(argc, argv, + &argc, &argv)) return 2; ret = - (GNUNET_OK == - GNUNET_PROGRAM_run (argc, argv, - "gnunet-daemon-testbed-blacklist", - _("Daemon to restrict incoming transport layer connections during testbed deployments"), - options, &run, NULL)) ? 0 : 1; - GNUNET_free ((void*) argv); + (GNUNET_OK == + GNUNET_PROGRAM_run(argc, argv, + "gnunet-daemon-testbed-blacklist", + _("Daemon to restrict incoming transport layer connections during testbed deployments"), + options, &run, NULL)) ? 0 : 1; + GNUNET_free((void*)argv); return ret; } diff --git a/src/testbed/gnunet-daemon-testbed-underlay.c b/src/testbed/gnunet-daemon-testbed-underlay.c index f5f6899e9..0c6a3c3df 100644 --- a/src/testbed/gnunet-daemon-testbed-underlay.c +++ b/src/testbed/gnunet-daemon-testbed-underlay.c @@ -11,12 +11,12 @@ 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 -*/ + */ /** @@ -37,14 +37,14 @@ /** * Logging shorthand */ -#define LOG(type,...) \ - GNUNET_log (type, __VA_ARGS__) +#define LOG(type, ...) \ + GNUNET_log(type, __VA_ARGS__) /** * Debug logging shorthand */ #define DEBUG(...) \ - LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) + LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) /** * Log an error message at log-level 'level' that indicates @@ -53,12 +53,12 @@ */ #define LOG_SQLITE(db, msg, level, cmd) \ do { \ - GNUNET_log_from (level, "sqlite", _("`%s' failed at %s:%d with error: %s\n"), \ - cmd, __FILE__,__LINE__, sqlite3_errmsg(db)); \ - if (msg != NULL) \ - GNUNET_asprintf(msg, _("`%s' failed at %s:%u with error: %s"), cmd, \ - __FILE__, __LINE__, sqlite3_errmsg(db)); \ - } while(0) + GNUNET_log_from(level, "sqlite", _("`%s' failed at %s:%d with error: %s\n"), \ + cmd, __FILE__, __LINE__, sqlite3_errmsg(db)); \ + if (msg != NULL) \ + GNUNET_asprintf (msg, _("`%s' failed at %s:%u with error: %s"), cmd, \ + __FILE__, __LINE__, sqlite3_errmsg(db)); \ + } while (0) /** @@ -115,10 +115,10 @@ static unsigned int num_hostkeys; * #GNUNET_NO if not. */ static int -iterator (void *cls, const struct GNUNET_PeerIdentity *key, void *value) +iterator(void *cls, const struct GNUNET_PeerIdentity *key, void *value) { - GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (map, key, - value)); + GNUNET_assert(GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove(map, key, + value)); return GNUNET_YES; } @@ -127,16 +127,16 @@ iterator (void *cls, const struct GNUNET_PeerIdentity *key, void *value) * Cleaup and destroy the map */ static void -cleanup_map () +cleanup_map() { if (NULL != map) - { - GNUNET_assert (GNUNET_SYSERR != GNUNET_CONTAINER_multipeermap_iterate (map, + { + GNUNET_assert(GNUNET_SYSERR != GNUNET_CONTAINER_multipeermap_iterate(map, &iterator, NULL)); - GNUNET_CONTAINER_multipeermap_destroy (map); - map = NULL; - } + GNUNET_CONTAINER_multipeermap_destroy(map); + map = NULL; + } } @@ -148,35 +148,35 @@ cleanup_map () * @return GNUNET_OK if the connection is allowed, GNUNET_SYSERR if not */ static int -check_access (void *cls, const struct GNUNET_PeerIdentity * pid) +check_access(void *cls, const struct GNUNET_PeerIdentity * pid) { int contains; - GNUNET_assert (NULL != map); - contains = GNUNET_CONTAINER_multipeermap_contains (map, pid); + GNUNET_assert(NULL != map); + contains = GNUNET_CONTAINER_multipeermap_contains(map, pid); if (GNUNET_YES == contains) - { - DEBUG ("Permitting `%s'\n", GNUNET_i2s (pid)); - return GNUNET_OK; - } - DEBUG ("Not permitting `%s'\n", GNUNET_i2s (pid)); + { + DEBUG("Permitting `%s'\n", GNUNET_i2s(pid)); + return GNUNET_OK; + } + DEBUG("Not permitting `%s'\n", GNUNET_i2s(pid)); return GNUNET_SYSERR; } static int -get_identity (unsigned int offset, - struct GNUNET_PeerIdentity *id) +get_identity(unsigned int offset, + struct GNUNET_PeerIdentity *id) { struct GNUNET_CRYPTO_EddsaPrivateKey private_key; if (offset >= num_hostkeys) return GNUNET_SYSERR; - GNUNET_memcpy (&private_key, - hostkeys_data + (offset * GNUNET_TESTING_HOSTKEYFILESIZE), - GNUNET_TESTING_HOSTKEYFILESIZE); - GNUNET_CRYPTO_eddsa_key_get_public (&private_key, - &id->public_key); + GNUNET_memcpy(&private_key, + hostkeys_data + (offset * GNUNET_TESTING_HOSTKEYFILESIZE), + GNUNET_TESTING_HOSTKEYFILESIZE); + GNUNET_CRYPTO_eddsa_key_get_public(&private_key, + &id->public_key); return GNUNET_OK; } @@ -184,8 +184,7 @@ get_identity (unsigned int offset, /** * Whilelist entry */ -struct WhiteListRow -{ +struct WhiteListRow { /** * Next ptr */ @@ -200,7 +199,6 @@ struct WhiteListRow * Latency to be assigned to the link */ int latency; - }; @@ -208,7 +206,7 @@ struct WhiteListRow * Function to load keys */ static int -load_keys (const struct GNUNET_CONFIGURATION_Handle *c) +load_keys(const struct GNUNET_CONFIGURATION_Handle *c) { char *data_dir; char *idfile; @@ -217,43 +215,42 @@ load_keys (const struct GNUNET_CONFIGURATION_Handle *c) data_dir = NULL; idfile = NULL; fsize = 0; - data_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); - GNUNET_asprintf (&idfile, "%s/testing_hostkeys.ecc", data_dir); - GNUNET_free (data_dir); + data_dir = GNUNET_OS_installation_get_path(GNUNET_OS_IPK_DATADIR); + GNUNET_asprintf(&idfile, "%s/testing_hostkeys.ecc", data_dir); + GNUNET_free(data_dir); data_dir = NULL; if (GNUNET_OK != - GNUNET_DISK_file_size (idfile, &fsize, GNUNET_YES, GNUNET_YES)) - { - GNUNET_free (idfile); - return GNUNET_SYSERR; - } + GNUNET_DISK_file_size(idfile, &fsize, GNUNET_YES, GNUNET_YES)) + { + GNUNET_free(idfile); + return GNUNET_SYSERR; + } if (0 != (fsize % GNUNET_TESTING_HOSTKEYFILESIZE)) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Incorrect hostkey file format: %s\n"), idfile); - GNUNET_free (idfile); - return GNUNET_SYSERR; - } - hostkeys_fd = GNUNET_DISK_file_open (idfile, GNUNET_DISK_OPEN_READ, - GNUNET_DISK_PERM_NONE); + { + LOG(GNUNET_ERROR_TYPE_ERROR, + _("Incorrect hostkey file format: %s\n"), idfile); + GNUNET_free(idfile); + return GNUNET_SYSERR; + } + hostkeys_fd = GNUNET_DISK_file_open(idfile, GNUNET_DISK_OPEN_READ, + GNUNET_DISK_PERM_NONE); if (NULL == hostkeys_fd) - { - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", idfile); - GNUNET_free (idfile); - return GNUNET_SYSERR; - } - GNUNET_free (idfile); + { + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "open", idfile); + GNUNET_free(idfile); + return GNUNET_SYSERR; + } + GNUNET_free(idfile); idfile = NULL; - hostkeys_data = GNUNET_DISK_file_map (hostkeys_fd, - &hostkeys_map, - GNUNET_DISK_MAP_TYPE_READ, - fsize); + hostkeys_data = GNUNET_DISK_file_map(hostkeys_fd, + &hostkeys_map, + GNUNET_DISK_MAP_TYPE_READ, + fsize); if (NULL == hostkeys_data) - { - - GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "mmap"); - return GNUNET_SYSERR; - } + { + GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "mmap"); + return GNUNET_SYSERR; + } num_hostkeys = fsize / GNUNET_TESTING_HOSTKEYFILESIZE; return GNUNET_OK; } @@ -263,20 +260,20 @@ load_keys (const struct GNUNET_CONFIGURATION_Handle *c) * Function to unload keys */ static void -unload_keys () +unload_keys() { if (NULL != hostkeys_map) - { - GNUNET_assert (NULL != hostkeys_data); - GNUNET_DISK_file_unmap (hostkeys_map); - hostkeys_map = NULL; - hostkeys_data = NULL; - } + { + GNUNET_assert(NULL != hostkeys_data); + GNUNET_DISK_file_unmap(hostkeys_map); + hostkeys_map = NULL; + hostkeys_data = NULL; + } if (NULL != hostkeys_fd) - { - GNUNET_DISK_file_close (hostkeys_fd); - hostkeys_fd = NULL; - } + { + GNUNET_DISK_file_close(hostkeys_fd); + hostkeys_fd = NULL; + } } @@ -286,17 +283,17 @@ unload_keys () * @param cls NULL */ static void -do_shutdown (void *cls) +do_shutdown(void *cls) { if (NULL != transport) - { - GNUNET_TRANSPORT_manipulation_disconnect (transport); - transport = NULL; - } - cleanup_map (); - unload_keys (); + { + GNUNET_TRANSPORT_manipulation_disconnect(transport); + transport = NULL; + } + cleanup_map(); + unload_keys(); if (NULL != bh) - GNUNET_TRANSPORT_blacklist_cancel (bh); + GNUNET_TRANSPORT_blacklist_cancel(bh); } @@ -309,7 +306,7 @@ do_shutdown (void *cls) * @return GNUNET_SYSERR upon error OR the number of rows retrieved */ static int -db_read_whitelist (struct sqlite3 *db, int pid, struct WhiteListRow **wl_rows) +db_read_whitelist(struct sqlite3 *db, int pid, struct WhiteListRow **wl_rows) { static const char *query_wl = "SELECT oid, latency FROM whitelist WHERE (id == ?);"; struct sqlite3_stmt *stmt_wl; @@ -317,31 +314,32 @@ db_read_whitelist (struct sqlite3 *db, int pid, struct WhiteListRow **wl_rows) int nrows; int ret; - if (SQLITE_OK != (ret = sqlite3_prepare_v2 (db, query_wl, -1, &stmt_wl, NULL))) - { - LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_prepare_v2"); - return GNUNET_SYSERR; - } - if (SQLITE_OK != (ret = sqlite3_bind_int (stmt_wl, 1, pid))) - { - LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_bind_int"); - sqlite3_finalize (stmt_wl); - return GNUNET_SYSERR; - } + if (SQLITE_OK != (ret = sqlite3_prepare_v2(db, query_wl, -1, &stmt_wl, NULL))) + { + LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_prepare_v2"); + return GNUNET_SYSERR; + } + if (SQLITE_OK != (ret = sqlite3_bind_int(stmt_wl, 1, pid))) + { + LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_bind_int"); + sqlite3_finalize(stmt_wl); + return GNUNET_SYSERR; + } nrows = 0; do - { - ret = sqlite3_step (stmt_wl); - if (SQLITE_ROW != ret) - break; - nrows++; - lr = GNUNET_new (struct WhiteListRow); - lr->id = sqlite3_column_int (stmt_wl, 0); - lr->latency = sqlite3_column_int (stmt_wl, 1); - lr->next = *wl_rows; - *wl_rows = lr; - } while (1); - sqlite3_finalize (stmt_wl); + { + ret = sqlite3_step(stmt_wl); + if (SQLITE_ROW != ret) + break; + nrows++; + lr = GNUNET_new(struct WhiteListRow); + lr->id = sqlite3_column_int(stmt_wl, 0); + lr->latency = sqlite3_column_int(stmt_wl, 1); + lr->next = *wl_rows; + *wl_rows = lr; + } + while (1); + sqlite3_finalize(stmt_wl); return nrows; } @@ -355,8 +353,8 @@ db_read_whitelist (struct sqlite3 *db, int pid, struct WhiteListRow **wl_rows) * @param c configuration */ static void -run (void *cls, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *c) +run(void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *c) { char *dbfile; struct WhiteListRow *wl_head; @@ -369,78 +367,78 @@ run (void *cls, char *const *args, const char *cfgfile, int ret; if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (c, "TESTBED", - "PEERID", &pid)) - { - GNUNET_break (0); - return; - } - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, "TESTBED-UNDERLAY", - "DBFILE", - &dbfile)) - { - GNUNET_break (0); - return; - } - if (SQLITE_OK != (ret = sqlite3_open_v2 (dbfile, &db, SQLITE_OPEN_READONLY, NULL))) - { - if (NULL != db) + GNUNET_CONFIGURATION_get_value_number(c, "TESTBED", + "PEERID", &pid)) { - LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite_open_v2"); - GNUNET_break (SQLITE_OK == sqlite3_close (db)); + GNUNET_break(0); + return; } - else - LOG (GNUNET_ERROR_TYPE_ERROR, "Cannot open sqlite file %s\n", dbfile); - GNUNET_free (dbfile); - return; - } - DEBUG ("Opened database %s\n", dbfile); - GNUNET_free (dbfile); + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(c, "TESTBED-UNDERLAY", + "DBFILE", + &dbfile)) + { + GNUNET_break(0); + return; + } + if (SQLITE_OK != (ret = sqlite3_open_v2(dbfile, &db, SQLITE_OPEN_READONLY, NULL))) + { + if (NULL != db) + { + LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite_open_v2"); + GNUNET_break(SQLITE_OK == sqlite3_close(db)); + } + else + LOG(GNUNET_ERROR_TYPE_ERROR, "Cannot open sqlite file %s\n", dbfile); + GNUNET_free(dbfile); + return; + } + DEBUG("Opened database %s\n", dbfile); + GNUNET_free(dbfile); dbfile = NULL; wl_head = NULL; - if (GNUNET_OK != load_keys (c)) - goto close_db; + if (GNUNET_OK != load_keys(c)) + goto close_db; - transport = GNUNET_TRANSPORT_manipulation_connect (c); + transport = GNUNET_TRANSPORT_manipulation_connect(c); if (NULL == transport) - { - GNUNET_break (0); - return; - } + { + GNUNET_break(0); + return; + } /* read and process whitelist */ nrows = 0; wl_head = NULL; - nrows = db_read_whitelist (db, pid, &wl_head); + nrows = db_read_whitelist(db, pid, &wl_head); if ((GNUNET_SYSERR == nrows) || (0 == nrows)) - { - GNUNET_TRANSPORT_manipulation_disconnect (transport); - goto close_db; - } - map = GNUNET_CONTAINER_multipeermap_create (nrows, GNUNET_NO); + { + GNUNET_TRANSPORT_manipulation_disconnect(transport); + goto close_db; + } + map = GNUNET_CONTAINER_multipeermap_create(nrows, GNUNET_NO); while (NULL != (wl_entry = wl_head)) - { - wl_head = wl_entry->next; - delay.rel_value_us = wl_entry->latency; - memset (&prop, 0, sizeof (prop)); - GNUNET_assert (GNUNET_OK == get_identity (wl_entry->id, &identity)); - GNUNET_break (GNUNET_OK == - GNUNET_CONTAINER_multipeermap_put (map, &identity, &identity, + { + wl_head = wl_entry->next; + delay.rel_value_us = wl_entry->latency; + memset(&prop, 0, sizeof(prop)); + GNUNET_assert(GNUNET_OK == get_identity(wl_entry->id, &identity)); + GNUNET_break(GNUNET_OK == + GNUNET_CONTAINER_multipeermap_put(map, &identity, &identity, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); - DEBUG ("Setting %u ms latency to peer `%s'\n", - wl_entry->latency, - GNUNET_i2s (&identity)); - GNUNET_TRANSPORT_manipulation_set (transport, - &identity, - &prop, - delay, - delay); - GNUNET_free (wl_entry); - } - bh = GNUNET_TRANSPORT_blacklist (c, &check_access, NULL); - GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); - - close_db: - GNUNET_break (SQLITE_OK == sqlite3_close (db)); + DEBUG("Setting %u ms latency to peer `%s'\n", + wl_entry->latency, + GNUNET_i2s(&identity)); + GNUNET_TRANSPORT_manipulation_set(transport, + &identity, + &prop, + delay, + delay); + GNUNET_free(wl_entry); + } + bh = GNUNET_TRANSPORT_blacklist(c, &check_access, NULL); + GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); + +close_db: + GNUNET_break(SQLITE_OK == sqlite3_close(db)); } @@ -452,24 +450,24 @@ run (void *cls, char *const *args, const char *cfgfile, * @return 0 ok, 1 on error */ int -main (int argc, char *const *argv) +main(int argc, char *const *argv) { static const struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; int ret; - if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) + if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) return 2; #ifdef SQLITE_CONFIG_MMAP_SIZE - (void) sqlite3_config (SQLITE_CONFIG_MMAP_SIZE, 512000, 256000000); + (void)sqlite3_config(SQLITE_CONFIG_MMAP_SIZE, 512000, 256000000); #endif ret = - (GNUNET_OK == - GNUNET_PROGRAM_run (argc, argv, "testbed-underlay", - _ - ("Daemon to restrict underlay network in testbed deployments"), - options, &run, NULL)) ? 0 : 1; - GNUNET_free ((void*) argv); + (GNUNET_OK == + GNUNET_PROGRAM_run(argc, argv, "testbed-underlay", + _ + ("Daemon to restrict underlay network in testbed deployments"), + options, &run, NULL)) ? 0 : 1; + GNUNET_free((void*)argv); return ret; } diff --git a/src/testbed/gnunet-helper-testbed.c b/src/testbed/gnunet-helper-testbed.c index a45f8de03..979d6c38f 100644 --- a/src/testbed/gnunet-helper-testbed.c +++ b/src/testbed/gnunet-helper-testbed.c @@ -49,12 +49,12 @@ /** * Generic logging shortcut */ -#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log(kind, __VA_ARGS__) /** * Debug logging shorthand */ -#define LOG_DEBUG(...) LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) +#define LOG_DEBUG(...) LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) /** @@ -70,8 +70,7 @@ /** * Context for a single write on a chunk of memory */ -struct WriteContext -{ +struct WriteContext { /** * The data to write */ @@ -151,50 +150,50 @@ static int status; * @param cls NULL */ static void -shutdown_task (void *cls) +shutdown_task(void *cls) { - LOG_DEBUG ("Shutting down\n"); + LOG_DEBUG("Shutting down\n"); if (NULL != testbed) - { - LOG_DEBUG ("Killing testbed\n"); - GNUNET_break (0 == GNUNET_OS_process_kill (testbed, GNUNET_TERM_SIG)); - } + { + LOG_DEBUG("Killing testbed\n"); + GNUNET_break(0 == GNUNET_OS_process_kill(testbed, GNUNET_TERM_SIG)); + } if (NULL != read_task_id) - { - GNUNET_SCHEDULER_cancel (read_task_id); - read_task_id = NULL; - } + { + GNUNET_SCHEDULER_cancel(read_task_id); + read_task_id = NULL; + } if (NULL != write_task_id) - { - struct WriteContext *wc; + { + struct WriteContext *wc; - wc = GNUNET_SCHEDULER_cancel (write_task_id); - write_task_id = NULL; - GNUNET_free (wc->data); - GNUNET_free (wc); - } + wc = GNUNET_SCHEDULER_cancel(write_task_id); + write_task_id = NULL; + GNUNET_free(wc->data); + GNUNET_free(wc); + } if (NULL != child_death_task_id) - { - GNUNET_SCHEDULER_cancel (child_death_task_id); - child_death_task_id = NULL; - } + { + GNUNET_SCHEDULER_cancel(child_death_task_id); + child_death_task_id = NULL; + } if (NULL != stdin_fd) - (void) GNUNET_DISK_file_close (stdin_fd); + (void)GNUNET_DISK_file_close(stdin_fd); if (NULL != stdout_fd) - (void) GNUNET_DISK_file_close (stdout_fd); - GNUNET_MST_destroy (tokenizer); + (void)GNUNET_DISK_file_close(stdout_fd); + GNUNET_MST_destroy(tokenizer); tokenizer = NULL; if (NULL != testbed) - { - GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (testbed)); - GNUNET_OS_process_destroy (testbed); - testbed = NULL; - } + { + GNUNET_break(GNUNET_OK == GNUNET_OS_process_wait(testbed)); + GNUNET_OS_process_destroy(testbed); + testbed = NULL; + } if (NULL != test_system) - { - GNUNET_TESTING_system_destroy (test_system, GNUNET_YES); - test_system = NULL; - } + { + GNUNET_TESTING_system_destroy(test_system, GNUNET_YES); + test_system = NULL; + } } @@ -204,34 +203,34 @@ shutdown_task (void *cls) * @param cls the WriteContext */ static void -write_task (void *cls) +write_task(void *cls) { struct WriteContext *wc = cls; ssize_t bytes_wrote; - GNUNET_assert (NULL != wc); + GNUNET_assert(NULL != wc); write_task_id = NULL; - bytes_wrote = GNUNET_DISK_file_write (stdout_fd, - wc->data + wc->pos, - wc->length - wc->pos); + bytes_wrote = GNUNET_DISK_file_write(stdout_fd, + wc->data + wc->pos, + wc->length - wc->pos); if (GNUNET_SYSERR == bytes_wrote) - { - LOG (GNUNET_ERROR_TYPE_WARNING, "Cannot reply back configuration\n"); - GNUNET_free (wc->data); - GNUNET_free (wc); - return; - } + { + LOG(GNUNET_ERROR_TYPE_WARNING, "Cannot reply back configuration\n"); + GNUNET_free(wc->data); + GNUNET_free(wc); + return; + } wc->pos += bytes_wrote; if (wc->pos == wc->length) - { - GNUNET_free (wc->data); - GNUNET_free (wc); - return; - } - write_task_id = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, - stdout_fd, - &write_task, - wc); + { + GNUNET_free(wc->data); + GNUNET_free(wc); + return; + } + write_task_id = GNUNET_SCHEDULER_add_write_file(GNUNET_TIME_UNIT_FOREVER_REL, + stdout_fd, + &write_task, + wc); } @@ -242,7 +241,7 @@ write_task (void *cls) * @param cls closure, NULL if we need to self-restart */ static void -child_death_task (void *cls) +child_death_task(void *cls) { const struct GNUNET_DISK_FileHandle *pr; char c[16]; @@ -250,36 +249,36 @@ child_death_task (void *cls) unsigned long code; int ret; - pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ); + pr = GNUNET_DISK_pipe_handle(sigpipe, GNUNET_DISK_PIPE_END_READ); child_death_task_id = NULL; /* consume the signal */ - GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c))); - LOG_DEBUG ("Got SIGCHLD\n"); + GNUNET_break(0 < GNUNET_DISK_file_read(pr, &c, sizeof(c))); + LOG_DEBUG("Got SIGCHLD\n"); if (NULL == testbed) - { - GNUNET_break (0); - return; - } - GNUNET_break (GNUNET_SYSERR != - (ret = GNUNET_OS_process_status (testbed, &type, &code))); + { + GNUNET_break(0); + return; + } + GNUNET_break(GNUNET_SYSERR != + (ret = GNUNET_OS_process_status(testbed, &type, &code))); if (GNUNET_NO != ret) - { - GNUNET_OS_process_destroy (testbed); - testbed = NULL; - /* Send SIGTERM to our process group */ - if (0 != kill (0, GNUNET_TERM_SIG)) { - GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "signal"); - GNUNET_SCHEDULER_shutdown (); /* Couldn't send the signal, we shutdown frowning */ + GNUNET_OS_process_destroy(testbed); + testbed = NULL; + /* Send SIGTERM to our process group */ + if (0 != kill(0, GNUNET_TERM_SIG)) + { + GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "signal"); + GNUNET_SCHEDULER_shutdown(); /* Couldn't send the signal, we shutdown frowning */ + } + return; } - return; - } - LOG_DEBUG ("Child hasn't died. Resuming to monitor its status\n"); + LOG_DEBUG("Child hasn't died. Resuming to monitor its status\n"); child_death_task_id = - GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, - pr, - &child_death_task, - NULL); + GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, + pr, + &child_death_task, + NULL); } @@ -296,7 +295,7 @@ child_death_task (void *cls) * #GNUNET_SYSERR to stop further processing with error */ static int -tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message) +tokenizer_cb(void *cls, const struct GNUNET_MessageHeader *message) { const struct GNUNET_TESTBED_HelperInit *msg; struct GNUNET_TESTBED_HelperReply *reply; @@ -316,182 +315,185 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message) uint16_t hostname_size; uint16_t msize; - msize = ntohs (message->size); - if ((sizeof (struct GNUNET_TESTBED_HelperInit) >= msize) || - (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT != ntohs (message->type))) - { - LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n"); - goto error; - } - msg = (const struct GNUNET_TESTBED_HelperInit *) message; - trusted_ip_size = ntohs (msg->trusted_ip_size); - trusted_ip = (char *) &msg[1]; + msize = ntohs(message->size); + if ((sizeof(struct GNUNET_TESTBED_HelperInit) >= msize) || + (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT != ntohs(message->type))) + { + LOG(GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n"); + goto error; + } + msg = (const struct GNUNET_TESTBED_HelperInit *)message; + trusted_ip_size = ntohs(msg->trusted_ip_size); + trusted_ip = (char *)&msg[1]; if ('\0' != trusted_ip[trusted_ip_size]) - { - LOG (GNUNET_ERROR_TYPE_WARNING, "Trusted IP cannot be empty -- exiting\n"); - goto error; - } - hostname_size = ntohs (msg->hostname_size); - if ((sizeof (struct GNUNET_TESTBED_HelperInit) + trusted_ip_size + 1 + + { + LOG(GNUNET_ERROR_TYPE_WARNING, "Trusted IP cannot be empty -- exiting\n"); + goto error; + } + hostname_size = ntohs(msg->hostname_size); + if ((sizeof(struct GNUNET_TESTBED_HelperInit) + trusted_ip_size + 1 + hostname_size) >= msize) - { - GNUNET_break (0); - LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n"); - goto error; - } - ul_config_size = (uLongf) ntohs (msg->config_size); - config = GNUNET_malloc (ul_config_size); + { + GNUNET_break(0); + LOG(GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n"); + goto error; + } + ul_config_size = (uLongf)ntohs(msg->config_size); + config = GNUNET_malloc(ul_config_size); xconfig_size = msize - (trusted_ip_size + 1 + hostname_size + - sizeof (struct GNUNET_TESTBED_HelperInit)); - int ret = uncompress ((Bytef *) config, - &ul_config_size, - (const Bytef *) (trusted_ip + trusted_ip_size + 1 + - hostname_size), - (uLongf) xconfig_size); + sizeof(struct GNUNET_TESTBED_HelperInit)); + int ret = uncompress((Bytef *)config, + &ul_config_size, + (const Bytef *)(trusted_ip + trusted_ip_size + 1 + + hostname_size), + (uLongf)xconfig_size); if (Z_OK != ret) - { - switch (ret) { - case Z_MEM_ERROR: - LOG (GNUNET_ERROR_TYPE_ERROR, "Not enough memory for decompression\n"); - break; - case Z_BUF_ERROR: - LOG (GNUNET_ERROR_TYPE_ERROR, "Output buffer too small\n"); - break; - case Z_DATA_ERROR: - LOG (GNUNET_ERROR_TYPE_ERROR, "Data corrupted/incomplete\n"); - break; - default: - GNUNET_break (0); + switch (ret) + { + case Z_MEM_ERROR: + LOG(GNUNET_ERROR_TYPE_ERROR, "Not enough memory for decompression\n"); + break; + + case Z_BUF_ERROR: + LOG(GNUNET_ERROR_TYPE_ERROR, "Output buffer too small\n"); + break; + + case Z_DATA_ERROR: + LOG(GNUNET_ERROR_TYPE_ERROR, "Data corrupted/incomplete\n"); + break; + + default: + GNUNET_break(0); + } + LOG(GNUNET_ERROR_TYPE_ERROR, + "Error while uncompressing config -- exiting\n"); + GNUNET_free(config); + goto error; } - LOG (GNUNET_ERROR_TYPE_ERROR, - "Error while uncompressing config -- exiting\n"); - GNUNET_free (config); - goto error; - } - cfg = GNUNET_CONFIGURATION_create (); + cfg = GNUNET_CONFIGURATION_create(); if (GNUNET_OK != - GNUNET_CONFIGURATION_deserialize (cfg, config, ul_config_size, NULL)) - { - LOG (GNUNET_ERROR_TYPE_ERROR, "Unable to deserialize config -- exiting\n"); - GNUNET_free (config); - goto error; - } - GNUNET_free (config); + GNUNET_CONFIGURATION_deserialize(cfg, config, ul_config_size, NULL)) + { + LOG(GNUNET_ERROR_TYPE_ERROR, "Unable to deserialize config -- exiting\n"); + GNUNET_free(config); + goto error; + } + GNUNET_free(config); hostname = NULL; if (0 != hostname_size) - { - hostname = GNUNET_malloc (hostname_size + 1); - GNUNET_strlcpy (hostname, - ((char *) &msg[1]) + trusted_ip_size + 1, - hostname_size + 1); - } + { + hostname = GNUNET_malloc(hostname_size + 1); + GNUNET_strlcpy(hostname, + ((char *)&msg[1]) + trusted_ip_size + 1, + hostname_size + 1); + } /* unset GNUNET_TESTING_PREFIX if present as it is more relevant for testbed */ - evstr = getenv (GNUNET_TESTING_PREFIX); + evstr = getenv(GNUNET_TESTING_PREFIX); if (NULL != evstr) - { - /* unsetting the variable will invalidate the pointer! */ - evstr = GNUNET_strdup (evstr); + { + /* unsetting the variable will invalidate the pointer! */ + evstr = GNUNET_strdup(evstr); #ifdef WINDOWS - GNUNET_break (0 != SetEnvironmentVariable (GNUNET_TESTING_PREFIX, NULL)); + GNUNET_break(0 != SetEnvironmentVariable(GNUNET_TESTING_PREFIX, NULL)); #else - GNUNET_break (0 == unsetenv (GNUNET_TESTING_PREFIX)); + GNUNET_break(0 == unsetenv(GNUNET_TESTING_PREFIX)); #endif - } + } test_system = - GNUNET_TESTING_system_create ("testbed-helper", trusted_ip, hostname, NULL); + GNUNET_TESTING_system_create("testbed-helper", trusted_ip, hostname, NULL); if (NULL != evstr) - { + { #ifdef WINDOWS - GNUNET_assert (0 != SetEnvironmentVariable (GNUNET_TESTING_PREFIX, evstr)); + GNUNET_assert(0 != SetEnvironmentVariable(GNUNET_TESTING_PREFIX, evstr)); #else - char *evar; + char *evar; - GNUNET_asprintf (&evar, GNUNET_TESTING_PREFIX "=%s", evstr); - GNUNET_assert (0 == putenv (evar)); /* consumes 'evar', + GNUNET_asprintf(&evar, GNUNET_TESTING_PREFIX "=%s", evstr); + GNUNET_assert(0 == putenv(evar)); /* consumes 'evar', see putenv(): becomes part of envrionment! */ #endif - GNUNET_free (evstr); - evstr = NULL; - } - GNUNET_free_non_null (hostname); + GNUNET_free(evstr); + evstr = NULL; + } + GNUNET_free_non_null(hostname); hostname = NULL; - GNUNET_assert (NULL != test_system); - GNUNET_assert (GNUNET_OK == - GNUNET_TESTING_configuration_create (test_system, cfg)); - GNUNET_assert (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_filename (cfg, - "PATHS", - "DEFAULTCONFIG", - &config)); - if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config)) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - "Unable to write config file: %s -- exiting\n", - config); - GNUNET_CONFIGURATION_destroy (cfg); - GNUNET_free (config); - goto error; - } - LOG_DEBUG ("Staring testbed with config: %s\n", config); - binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-testbed"); + GNUNET_assert(NULL != test_system); + GNUNET_assert(GNUNET_OK == + GNUNET_TESTING_configuration_create(test_system, cfg)); + GNUNET_assert(GNUNET_OK == + GNUNET_CONFIGURATION_get_value_filename(cfg, + "PATHS", + "DEFAULTCONFIG", + &config)); + if (GNUNET_OK != GNUNET_CONFIGURATION_write(cfg, config)) + { + LOG(GNUNET_ERROR_TYPE_WARNING, + "Unable to write config file: %s -- exiting\n", + config); + GNUNET_CONFIGURATION_destroy(cfg); + GNUNET_free(config); + goto error; + } + LOG_DEBUG("Staring testbed with config: %s\n", config); + binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-testbed"); { char *evar; /* expose testbed configuration through env variable */ - GNUNET_asprintf (&evar, "%s=%s", ENV_TESTBED_CONFIG, config); - GNUNET_assert (0 == putenv (evar)); /* consumes 'evar', + GNUNET_asprintf(&evar, "%s=%s", ENV_TESTBED_CONFIG, config); + GNUNET_assert(0 == putenv(evar)); /* consumes 'evar', see putenv(): becomes part of envrionment! */ evstr = NULL; } - testbed = GNUNET_OS_start_process (PIPE_CONTROL, - GNUNET_OS_INHERIT_STD_ERR /*verbose? */, - NULL, - NULL, - NULL, - binary, - "gnunet-service-testbed", - "-c", - config, - NULL); - GNUNET_free (binary); - GNUNET_free (config); + testbed = GNUNET_OS_start_process(PIPE_CONTROL, + GNUNET_OS_INHERIT_STD_ERR /*verbose? */, + NULL, + NULL, + NULL, + binary, + "gnunet-service-testbed", + "-c", + config, + NULL); + GNUNET_free(binary); + GNUNET_free(config); if (NULL == testbed) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - "Error starting gnunet-service-testbed -- exiting\n"); - GNUNET_CONFIGURATION_destroy (cfg); - goto error; - } + { + LOG(GNUNET_ERROR_TYPE_WARNING, + "Error starting gnunet-service-testbed -- exiting\n"); + GNUNET_CONFIGURATION_destroy(cfg); + goto error; + } done_reading = GNUNET_YES; - config = GNUNET_CONFIGURATION_serialize (cfg, &config_size); - GNUNET_CONFIGURATION_destroy (cfg); + config = GNUNET_CONFIGURATION_serialize(cfg, &config_size); + GNUNET_CONFIGURATION_destroy(cfg); cfg = NULL; xconfig_size = - GNUNET_TESTBED_compress_config_ (config, config_size, &xconfig); - GNUNET_free (config); - wc = GNUNET_new (struct WriteContext); - wc->length = xconfig_size + sizeof (struct GNUNET_TESTBED_HelperReply); - reply = GNUNET_realloc (xconfig, wc->length); - memmove (&reply[1], reply, xconfig_size); - reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY); - reply->header.size = htons ((uint16_t) wc->length); - reply->config_size = htons ((uint16_t) config_size); + GNUNET_TESTBED_compress_config_(config, config_size, &xconfig); + GNUNET_free(config); + wc = GNUNET_new(struct WriteContext); + wc->length = xconfig_size + sizeof(struct GNUNET_TESTBED_HelperReply); + reply = GNUNET_realloc(xconfig, wc->length); + memmove(&reply[1], reply, xconfig_size); + reply->header.type = htons(GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY); + reply->header.size = htons((uint16_t)wc->length); + reply->config_size = htons((uint16_t)config_size); wc->data = reply; - write_task_id = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, - stdout_fd, - &write_task, - wc); - child_death_task_id = GNUNET_SCHEDULER_add_read_file ( + write_task_id = GNUNET_SCHEDULER_add_write_file(GNUNET_TIME_UNIT_FOREVER_REL, + stdout_fd, + &write_task, + wc); + child_death_task_id = GNUNET_SCHEDULER_add_read_file( GNUNET_TIME_UNIT_FOREVER_REL, - GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ), + GNUNET_DISK_pipe_handle(sigpipe, GNUNET_DISK_PIPE_END_READ), &child_death_task, NULL); return GNUNET_OK; error: status = GNUNET_SYSERR; - GNUNET_SCHEDULER_shutdown (); + GNUNET_SCHEDULER_shutdown(); return GNUNET_SYSERR; } @@ -502,41 +504,41 @@ error: * @param cls NULL */ static void -read_task (void *cls) +read_task(void *cls) { char buf[GNUNET_MAX_MESSAGE_SIZE]; ssize_t sread; read_task_id = NULL; - sread = GNUNET_DISK_file_read (stdin_fd, buf, sizeof (buf)); + sread = GNUNET_DISK_file_read(stdin_fd, buf, sizeof(buf)); if ((GNUNET_SYSERR == sread) || (0 == sread)) - { - LOG_DEBUG ("STDIN closed\n"); - GNUNET_SCHEDULER_shutdown (); - return; - } + { + LOG_DEBUG("STDIN closed\n"); + GNUNET_SCHEDULER_shutdown(); + return; + } if (GNUNET_YES == done_reading) - { - /* didn't expect any more data! */ - GNUNET_break_op (0); - GNUNET_SCHEDULER_shutdown (); - return; - } - LOG_DEBUG ("Read %u bytes\n", (unsigned int) sread); + { + /* didn't expect any more data! */ + GNUNET_break_op(0); + GNUNET_SCHEDULER_shutdown(); + return; + } + LOG_DEBUG("Read %u bytes\n", (unsigned int)sread); /* FIXME: could introduce a GNUNET_MST_read2 to read directly from 'stdin_fd' and save a memcpy() here */ if (GNUNET_OK != - GNUNET_MST_from_buffer (tokenizer, buf, sread, GNUNET_NO, GNUNET_NO)) - { - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - return; - } + GNUNET_MST_from_buffer(tokenizer, buf, sread, GNUNET_NO, GNUNET_NO)) + { + GNUNET_break(0); + GNUNET_SCHEDULER_shutdown(); + return; + } read_task_id /* No timeout while reading */ - = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, - stdin_fd, - &read_task, - NULL); + = GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, + stdin_fd, + &read_task, + NULL); } @@ -549,20 +551,20 @@ read_task (void *cls) * @param 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) { - LOG_DEBUG ("Starting testbed helper...\n"); - tokenizer = GNUNET_MST_create (&tokenizer_cb, NULL); - stdin_fd = GNUNET_DISK_get_handle_from_native (stdin); - stdout_fd = GNUNET_DISK_get_handle_from_native (stdout); - read_task_id = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, - stdin_fd, - &read_task, - NULL); - GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); + LOG_DEBUG("Starting testbed helper...\n"); + tokenizer = GNUNET_MST_create(&tokenizer_cb, NULL); + stdin_fd = GNUNET_DISK_get_handle_from_native(stdin); + stdout_fd = GNUNET_DISK_get_handle_from_native(stdout); + read_task_id = GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, + stdin_fd, + &read_task, + NULL); + GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); } @@ -570,18 +572,18 @@ run (void *cls, * Signal handler called for SIGCHLD. */ static void -sighandler_child_death () +sighandler_child_death() { static char c; int old_errno; /* back-up errno */ old_errno = errno; - GNUNET_break ( + GNUNET_break( 1 == - GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle (sigpipe, - GNUNET_DISK_PIPE_END_WRITE), - &c, - sizeof (c))); + GNUNET_DISK_file_write(GNUNET_DISK_pipe_handle(sigpipe, + GNUNET_DISK_PIPE_END_WRITE), + &c, + sizeof(c))); errno = old_errno; } @@ -594,31 +596,31 @@ sighandler_child_death () * @return return code */ int -main (int argc, char **argv) +main(int argc, char **argv) { struct GNUNET_SIGNAL_Context *shc_chld; - struct GNUNET_GETOPT_CommandLineOption options[] = {GNUNET_GETOPT_OPTION_END}; + struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; int ret; status = GNUNET_OK; if (NULL == - (sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO))) - { - GNUNET_break (0); - return 1; - } + (sigpipe = GNUNET_DISK_pipe(GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO))) + { + GNUNET_break(0); + return 1; + } shc_chld = - GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); - ret = GNUNET_PROGRAM_run (argc, - argv, - "gnunet-helper-testbed", - "Helper for starting gnunet-service-testbed", - options, - &run, - NULL); - GNUNET_SIGNAL_handler_uninstall (shc_chld); + GNUNET_SIGNAL_handler_install(GNUNET_SIGCHLD, &sighandler_child_death); + ret = GNUNET_PROGRAM_run(argc, + argv, + "gnunet-helper-testbed", + "Helper for starting gnunet-service-testbed", + options, + &run, + NULL); + GNUNET_SIGNAL_handler_uninstall(shc_chld); shc_chld = NULL; - GNUNET_DISK_pipe_close (sigpipe); + GNUNET_DISK_pipe_close(sigpipe); if (GNUNET_OK != ret) return 1; return (GNUNET_OK == status) ? 0 : 1; diff --git a/src/testbed/gnunet-service-test-barriers.c b/src/testbed/gnunet-service-test-barriers.c index 948daa633..5902a1576 100644 --- a/src/testbed/gnunet-service-test-barriers.c +++ b/src/testbed/gnunet-service-test-barriers.c @@ -11,7 +11,7 @@ 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 . @@ -33,8 +33,8 @@ /** * logging short hand */ -#define LOG(type,...) \ - GNUNET_log (type, __VA_ARGS__); +#define LOG(type, ...) \ + GNUNET_log(type, __VA_ARGS__); /** * Our barrier wait handle @@ -50,18 +50,18 @@ static struct GNUNET_SCHEDULER_Task *tt; * @param cls NULL */ static void -do_shutdown (void *cls) +do_shutdown(void *cls) { if (NULL != wh) - { - GNUNET_TESTBED_barrier_wait_cancel (wh); - wh = NULL; - } + { + GNUNET_TESTBED_barrier_wait_cancel(wh); + wh = NULL; + } if (NULL != tt) - { - GNUNET_SCHEDULER_cancel (tt); - tt = NULL; - } + { + GNUNET_SCHEDULER_cancel(tt); + tt = NULL; + } } @@ -76,13 +76,13 @@ do_shutdown (void *cls) * #GNUNET_OK if the barrier is crossed */ static void -barrier_wait_cb (void *cls, - const char *name, - int status) +barrier_wait_cb(void *cls, + const char *name, + int status) { - GNUNET_break (NULL == cls); + GNUNET_break(NULL == cls); wh = NULL; - GNUNET_break (GNUNET_OK == status); + GNUNET_break(GNUNET_OK == status); } @@ -93,13 +93,13 @@ barrier_wait_cb (void *cls, * @return */ static void -do_wait (void *cls) +do_wait(void *cls) { tt = NULL; - wh = GNUNET_TESTBED_barrier_wait (TEST_BARRIER_NAME, - &barrier_wait_cb, - NULL); - GNUNET_break (NULL != wh); + wh = GNUNET_TESTBED_barrier_wait(TEST_BARRIER_NAME, + &barrier_wait_cb, + NULL); + GNUNET_break(NULL != wh); } @@ -112,20 +112,20 @@ do_wait (void *cls) * @param config the configuration file handle */ static void -run (void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *config) +run(void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *config) { unsigned int rsec; - rsec = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, - 10); - tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, - rsec), - &do_wait, - NULL); - GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); + rsec = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, + 10); + tt = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, + rsec), + &do_wait, + NULL); + GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); } @@ -134,7 +134,7 @@ run (void *cls, * Main */ int -main (int argc, char **argv) +main(int argc, char **argv) { struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END @@ -142,11 +142,11 @@ main (int argc, char **argv) int ret; ret = - GNUNET_PROGRAM_run (argc, argv, - "test-barriers", - "nohelp", - options, - &run, - NULL); + GNUNET_PROGRAM_run(argc, argv, + "test-barriers", + "nohelp", + options, + &run, + NULL); return ret; } diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c index 8babeeb13..26f1a9c26 100644 --- a/src/testbed/gnunet-service-testbed.c +++ b/src/testbed/gnunet-service-testbed.c @@ -1,22 +1,22 @@ /* - This file is part of GNUnet. - Copyright (C) 2008--2013, 2016 GNUnet e.V. + This file is part of GNUnet. + Copyright (C) 2008--2013, 2016 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 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. + 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 . + 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/gnunet-service-testbed.c @@ -96,18 +96,18 @@ static char *hostname; * already in use */ static int -host_list_add (struct GNUNET_TESTBED_Host *host) +host_list_add(struct GNUNET_TESTBED_Host *host) { uint32_t host_id; - host_id = GNUNET_TESTBED_host_get_id_ (host); + host_id = GNUNET_TESTBED_host_get_id_(host); if (GST_host_list_size <= host_id) - GST_array_grow_large_enough (GST_host_list, GST_host_list_size, host_id); + GST_array_grow_large_enough(GST_host_list, GST_host_list_size, host_id); if (NULL != GST_host_list[host_id]) - { - LOG_DEBUG ("A host with id: %u already exists\n", host_id); - return GNUNET_SYSERR; - } + { + LOG_DEBUG("A host with id: %u already exists\n", host_id); + return GNUNET_SYSERR; + } GST_host_list[host_id] = host; return GNUNET_OK; } @@ -121,25 +121,25 @@ host_list_add (struct GNUNET_TESTBED_Host *host) * @param emsg the error message; can be NULL */ void -GST_send_operation_fail_msg (struct GNUNET_SERVICE_Client *client, - uint64_t operation_id, - const char *emsg) +GST_send_operation_fail_msg(struct GNUNET_SERVICE_Client *client, + uint64_t operation_id, + const char *emsg) { struct GNUNET_MQ_Envelope *env; struct GNUNET_TESTBED_OperationFailureEventMessage *msg; uint16_t emsg_len; - emsg_len = (NULL == emsg) ? 0 : strlen (emsg) + 1; - env = GNUNET_MQ_msg_extra (msg, - emsg_len, - GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT); - msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED); - msg->operation_id = GNUNET_htonll (operation_id); - GNUNET_memcpy (&msg[1], - emsg, - emsg_len); - GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), - env); + emsg_len = (NULL == emsg) ? 0 : strlen(emsg) + 1; + env = GNUNET_MQ_msg_extra(msg, + emsg_len, + GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT); + msg->event_type = htonl(GNUNET_TESTBED_ET_OPERATION_FINISHED); + msg->operation_id = GNUNET_htonll(operation_id); + GNUNET_memcpy(&msg[1], + emsg, + emsg_len); + GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), + env); } @@ -150,18 +150,18 @@ GST_send_operation_fail_msg (struct GNUNET_SERVICE_Client *client, * @param operation_id the id of the operation which was successful */ void -GST_send_operation_success_msg (struct GNUNET_SERVICE_Client *client, - uint64_t operation_id) +GST_send_operation_success_msg(struct GNUNET_SERVICE_Client *client, + uint64_t operation_id) { struct GNUNET_MQ_Envelope *env; struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg; - env = GNUNET_MQ_msg (msg, - GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS); - msg->operation_id = GNUNET_htonll (operation_id); - msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED); - GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), - env); + env = GNUNET_MQ_msg(msg, + GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS); + msg->operation_id = GNUNET_htonll(operation_id); + msg->event_type = htonl(GNUNET_TESTBED_ET_OPERATION_FINISHED); + GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), + env); } @@ -172,8 +172,8 @@ GST_send_operation_success_msg (struct GNUNET_SERVICE_Client *client, * @param emsg the error message; NULL if host registration is successful */ static void -hr_completion (void *cls, - const char *emsg); +hr_completion(void *cls, + const char *emsg); /** @@ -183,21 +183,21 @@ hr_completion (void *cls, * for host registrations */ static void -register_next_host (struct Slave *slave) +register_next_host(struct Slave *slave) { struct HostRegistration *hr; hr = slave->hr_dll_head; - GNUNET_assert (NULL != hr); - GNUNET_assert (NULL == slave->rhandle); - LOG (GNUNET_ERROR_TYPE_DEBUG, "Registering host %u at %u\n", - GNUNET_TESTBED_host_get_id_ (hr->host), - GNUNET_TESTBED_host_get_id_ (GST_host_list[slave->host_id])); + GNUNET_assert(NULL != hr); + GNUNET_assert(NULL == slave->rhandle); + LOG(GNUNET_ERROR_TYPE_DEBUG, "Registering host %u at %u\n", + GNUNET_TESTBED_host_get_id_(hr->host), + GNUNET_TESTBED_host_get_id_(GST_host_list[slave->host_id])); slave->rhandle - = GNUNET_TESTBED_register_host (slave->controller, - hr->host, - hr_completion, - slave); + = GNUNET_TESTBED_register_host(slave->controller, + hr->host, + hr_completion, + slave); } @@ -208,28 +208,28 @@ register_next_host (struct Slave *slave) * @param emsg the error message; NULL if host registration is successful */ static void -hr_completion (void *cls, - const char *emsg) +hr_completion(void *cls, + const char *emsg) { struct Slave *slave = cls; struct HostRegistration *hr; slave->rhandle = NULL; hr = slave->hr_dll_head; - GNUNET_assert (NULL != hr); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Registering host %u at %u successful\n", - GNUNET_TESTBED_host_get_id_ (hr->host), - GNUNET_TESTBED_host_get_id_ (GST_host_list[slave->host_id])); - GNUNET_CONTAINER_DLL_remove (slave->hr_dll_head, - slave->hr_dll_tail, - hr); + GNUNET_assert(NULL != hr); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Registering host %u at %u successful\n", + GNUNET_TESTBED_host_get_id_(hr->host), + GNUNET_TESTBED_host_get_id_(GST_host_list[slave->host_id])); + GNUNET_CONTAINER_DLL_remove(slave->hr_dll_head, + slave->hr_dll_tail, + hr); if (NULL != hr->cb) - hr->cb (hr->cb_cls, - emsg); - GNUNET_free (hr); + hr->cb(hr->cb_cls, + emsg); + GNUNET_free(hr); if (NULL != slave->hr_dll_head) - register_next_host (slave); + register_next_host(slave); } @@ -243,28 +243,28 @@ hr_completion (void *cls, * @param host the host which has to be registered */ void -GST_queue_host_registration (struct Slave *slave, - GNUNET_TESTBED_HostRegistrationCompletion cb, - void *cb_cls, - struct GNUNET_TESTBED_Host *host) +GST_queue_host_registration(struct Slave *slave, + GNUNET_TESTBED_HostRegistrationCompletion cb, + void *cb_cls, + struct GNUNET_TESTBED_Host *host) { struct HostRegistration *hr; int call_register; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Queueing host registration for host %u at %u\n", - GNUNET_TESTBED_host_get_id_ (host), - GNUNET_TESTBED_host_get_id_ (GST_host_list[slave->host_id])); - hr = GNUNET_new (struct HostRegistration); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Queueing host registration for host %u at %u\n", + GNUNET_TESTBED_host_get_id_(host), + GNUNET_TESTBED_host_get_id_(GST_host_list[slave->host_id])); + hr = GNUNET_new(struct HostRegistration); hr->cb = cb; hr->cb_cls = cb_cls; hr->host = host; call_register = (NULL == slave->hr_dll_head) ? GNUNET_YES : GNUNET_NO; - GNUNET_CONTAINER_DLL_insert_tail (slave->hr_dll_head, - slave->hr_dll_tail, - hr); + GNUNET_CONTAINER_DLL_insert_tail(slave->hr_dll_head, + slave->hr_dll_tail, + hr); if (GNUNET_YES == call_register) - register_next_host (slave); + register_next_host(slave); } @@ -275,23 +275,23 @@ GST_queue_host_registration (struct Slave *slave, * @param msg the message to relay */ void -GST_forwarded_operation_reply_relay (void *cls, - const struct GNUNET_MessageHeader *msg) +GST_forwarded_operation_reply_relay(void *cls, + const struct GNUNET_MessageHeader *msg) { struct ForwardedOperationContext *fopc = cls; struct GNUNET_MQ_Envelope *env; - LOG_DEBUG ("Relaying message with type: %u, size: %u\n", - ntohs (msg->type), - ntohs (msg->size)); - env = GNUNET_MQ_msg_copy (msg); - GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (fopc->client), - env); - GNUNET_SCHEDULER_cancel (fopc->timeout_task); - GNUNET_CONTAINER_DLL_remove (fopcq_head, - fopcq_tail, - fopc); - GNUNET_free (fopc); + LOG_DEBUG("Relaying message with type: %u, size: %u\n", + ntohs(msg->type), + ntohs(msg->size)); + env = GNUNET_MQ_msg_copy(msg); + GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(fopc->client), + env); + GNUNET_SCHEDULER_cancel(fopc->timeout_task); + GNUNET_CONTAINER_DLL_remove(fopcq_head, + fopcq_tail, + fopc); + GNUNET_free(fopc); } @@ -301,21 +301,21 @@ GST_forwarded_operation_reply_relay (void *cls, * @param cls the ForwardedOperationContext */ void -GST_forwarded_operation_timeout (void *cls) +GST_forwarded_operation_timeout(void *cls) { struct ForwardedOperationContext *fopc = cls; fopc->timeout_task = NULL; - GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "A forwarded operation has timed out\n"); - GST_send_operation_fail_msg (fopc->client, - fopc->operation_id, - "A forwarded operation has timed out"); - GNUNET_CONTAINER_DLL_remove (fopcq_head, - fopcq_tail, - fopc); - GNUNET_free (fopc); + GNUNET_TESTBED_forward_operation_msg_cancel_(fopc->opc); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "A forwarded operation has timed out\n"); + GST_send_operation_fail_msg(fopc->client, + fopc->operation_id, + "A forwarded operation has timed out"); + GNUNET_CONTAINER_DLL_remove(fopcq_head, + fopcq_tail, + fopc); + GNUNET_free(fopc); } @@ -329,51 +329,52 @@ GST_forwarded_operation_timeout (void *cls) * upon empty service sharing specification. */ static struct GNUNET_TESTING_SharedService * -parse_shared_services (char *ss_str, - struct GNUNET_CONFIGURATION_Handle *cfg) +parse_shared_services(char *ss_str, + struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_TESTING_SharedService ss; struct GNUNET_TESTING_SharedService *slist; char service[256]; char *arg; unsigned int n; + #define GROW_SS \ do { \ - GNUNET_array_grow (slist, n, n+1); \ - GNUNET_memcpy (&slist[n - 1], &ss, \ - sizeof (struct GNUNET_TESTING_SharedService)); \ - } while (0) + GNUNET_array_grow(slist, n, n + 1); \ + GNUNET_memcpy(&slist[n - 1], &ss, \ + sizeof(struct GNUNET_TESTING_SharedService)); \ + } while (0) slist = NULL; n = 0; ss.cfg = cfg; - for (; NULL != (arg = strtok (ss_str, " ")); ss_str = NULL) - { - ss.service = NULL; - ss.share = 0; - if (2 != sscanf (arg, "%255[^:]:%u", - service, - &ss.share)) + for (; NULL != (arg = strtok(ss_str, " ")); ss_str = NULL) { - LOG (GNUNET_ERROR_TYPE_WARNING, - "Ignoring shared service spec: %s", - arg); - continue; + ss.service = NULL; + ss.share = 0; + if (2 != sscanf(arg, "%255[^:]:%u", + service, + &ss.share)) + { + LOG(GNUNET_ERROR_TYPE_WARNING, + "Ignoring shared service spec: %s", + arg); + continue; + } + LOG_DEBUG("Will be sharing %s service among %u peers\n", + service, + ss.share); + ss.service = GNUNET_strdup(service); + GROW_SS; } - LOG_DEBUG ("Will be sharing %s service among %u peers\n", - service, - ss.share); - ss.service = GNUNET_strdup (service); - GROW_SS; - } if (NULL != slist) - { - /* Add trailing NULL block */ - (void) memset (&ss, + { + /* Add trailing NULL block */ + (void)memset(&ss, 0, - sizeof (struct GNUNET_TESTING_SharedService)); - GROW_SS; - } + sizeof(struct GNUNET_TESTING_SharedService)); + GROW_SS; + } return slist; #undef GROW_SS } @@ -387,19 +388,19 @@ parse_shared_services (char *ss_str, * @return #GNUNET_OK if @a message is well-formed */ static int -check_init (void *cls, - const struct GNUNET_TESTBED_InitMessage *msg) +check_init(void *cls, + const struct GNUNET_TESTBED_InitMessage *msg) { const char *controller_hostname; uint16_t msize; - msize = ntohs (msg->header.size) - sizeof (struct GNUNET_TESTBED_InitMessage); - controller_hostname = (const char *) &msg[1]; + msize = ntohs(msg->header.size) - sizeof(struct GNUNET_TESTBED_InitMessage); + controller_hostname = (const char *)&msg[1]; if ('\0' != controller_hostname[msize - 1]) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + { + GNUNET_break(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -411,8 +412,8 @@ check_init (void *cls, * @param message the actual message */ static void -handle_init (void *cls, - const struct GNUNET_TESTBED_InitMessage *msg) +handle_init(void *cls, + const struct GNUNET_TESTBED_InitMessage *msg) { struct GNUNET_SERVICE_Client *client = cls; struct GNUNET_TESTBED_Host *host; @@ -422,56 +423,56 @@ handle_init (void *cls, unsigned int cnt; if (NULL != GST_context) - { - LOG_DEBUG ("We are being connected to laterally\n"); - GNUNET_SERVICE_client_continue (client); - return; - } - controller_hostname = (const char *) &msg[1]; + { + LOG_DEBUG("We are being connected to laterally\n"); + GNUNET_SERVICE_client_continue(client); + return; + } + controller_hostname = (const char *)&msg[1]; ss_str = NULL; ss = NULL; if (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_string (GST_config, - "TESTBED", - "SHARED_SERVICES", - &ss_str)) - { - ss = parse_shared_services (ss_str, - GST_config); - GNUNET_free (ss_str); - ss_str = NULL; - } - GST_context = GNUNET_new (struct Context); + GNUNET_CONFIGURATION_get_value_string(GST_config, + "TESTBED", + "SHARED_SERVICES", + &ss_str)) + { + ss = parse_shared_services(ss_str, + GST_config); + GNUNET_free(ss_str); + ss_str = NULL; + } + GST_context = GNUNET_new(struct Context); GST_context->client = client; - GST_context->host_id = ntohl (msg->host_id); - GST_context->master_ip = GNUNET_strdup (controller_hostname); - LOG_DEBUG ("Our IP: %s\n", - GST_context->master_ip); + GST_context->host_id = ntohl(msg->host_id); + GST_context->master_ip = GNUNET_strdup(controller_hostname); + LOG_DEBUG("Our IP: %s\n", + GST_context->master_ip); GST_context->system - = GNUNET_TESTING_system_create ("testbed", - GST_context->master_ip, - hostname, - ss); + = GNUNET_TESTING_system_create("testbed", + GST_context->master_ip, + hostname, + ss); if (NULL != ss) - { - for (cnt = 0; NULL != ss[cnt].service; cnt++) { - ss_str = (char *) ss[cnt].service; - GNUNET_free (ss_str); + for (cnt = 0; NULL != ss[cnt].service; cnt++) + { + ss_str = (char *)ss[cnt].service; + GNUNET_free(ss_str); + } + GNUNET_free(ss); + ss = NULL; } - GNUNET_free (ss); - ss = NULL; - } host = - GNUNET_TESTBED_host_create_with_id (GST_context->host_id, - GST_context->master_ip, - NULL, - GST_config, - 0); - host_list_add (host); - LOG_DEBUG ("Created master context with host ID: %u\n", - GST_context->host_id); - GNUNET_SERVICE_client_continue (client); + GNUNET_TESTBED_host_create_with_id(GST_context->host_id, + GST_context->master_ip, + NULL, + GST_config, + 0); + host_list_add(host); + LOG_DEBUG("Created master context with host ID: %u\n", + GST_context->host_id); + GNUNET_SERVICE_client_continue(client); } @@ -483,29 +484,29 @@ handle_init (void *cls, * @return #GNUNET_OK if @a message is well-formed */ static int -check_add_host (void *cls, - const struct GNUNET_TESTBED_AddHostMessage *msg) +check_add_host(void *cls, + const struct GNUNET_TESTBED_AddHostMessage *msg) { uint16_t username_length; uint16_t hostname_length; uint16_t msize; - msize = ntohs (msg->header.size) - sizeof (struct GNUNET_TESTBED_AddHostMessage); - username_length = ntohs (msg->username_length); - hostname_length = ntohs (msg->hostname_length); + msize = ntohs(msg->header.size) - sizeof(struct GNUNET_TESTBED_AddHostMessage); + username_length = ntohs(msg->username_length); + hostname_length = ntohs(msg->hostname_length); /* msg must contain hostname */ - if ( (msize <= username_length) || - (0 == hostname_length) ) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + if ((msize <= username_length) || + (0 == hostname_length)) + { + GNUNET_break(0); + return GNUNET_SYSERR; + } /* msg must contain configuration */ if (msize <= username_length + hostname_length) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + { + GNUNET_break(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -517,8 +518,8 @@ check_add_host (void *cls, * @param msg the actual message */ static void -handle_add_host (void *cls, - const struct GNUNET_TESTBED_AddHostMessage *msg) +handle_add_host(void *cls, + const struct GNUNET_TESTBED_AddHostMessage *msg) { struct GNUNET_SERVICE_Client *client = cls; struct GNUNET_TESTBED_Host *host; @@ -533,77 +534,77 @@ handle_add_host (void *cls, uint16_t hostname_length; struct GNUNET_MQ_Envelope *env; - username_length = ntohs (msg->username_length); - hostname_length = ntohs (msg->hostname_length); + username_length = ntohs(msg->username_length); + hostname_length = ntohs(msg->hostname_length); username = NULL; hostname = NULL; ptr = &msg[1]; if (0 != username_length) - { - username = GNUNET_malloc (username_length + 1); - GNUNET_strlcpy (username, ptr, username_length + 1); - ptr += username_length; - } - hostname = GNUNET_malloc (hostname_length + 1); - GNUNET_strlcpy (hostname, ptr, hostname_length + 1); - if (NULL == (host_cfg = GNUNET_TESTBED_extract_config_ (&msg->header))) - { - GNUNET_free_non_null (username); - GNUNET_free_non_null (hostname); - GNUNET_break_op (0); - GNUNET_SERVICE_client_drop (client); - return; - } - host_id = ntohl (msg->host_id); - LOG_DEBUG ("Received ADDHOST %u message\n", host_id); - LOG_DEBUG ("-------host id: %u\n", host_id); - LOG_DEBUG ("-------hostname: %s\n", hostname); + { + username = GNUNET_malloc(username_length + 1); + GNUNET_strlcpy(username, ptr, username_length + 1); + ptr += username_length; + } + hostname = GNUNET_malloc(hostname_length + 1); + GNUNET_strlcpy(hostname, ptr, hostname_length + 1); + if (NULL == (host_cfg = GNUNET_TESTBED_extract_config_(&msg->header))) + { + GNUNET_free_non_null(username); + GNUNET_free_non_null(hostname); + GNUNET_break_op(0); + GNUNET_SERVICE_client_drop(client); + return; + } + host_id = ntohl(msg->host_id); + LOG_DEBUG("Received ADDHOST %u message\n", host_id); + LOG_DEBUG("-------host id: %u\n", host_id); + LOG_DEBUG("-------hostname: %s\n", hostname); if (NULL != username) - LOG_DEBUG ("-------username: %s\n", username); + LOG_DEBUG("-------username: %s\n", username); else - LOG_DEBUG ("-------username: \n"); - LOG_DEBUG ("-------ssh port: %u\n", ntohs (msg->ssh_port)); - host = GNUNET_TESTBED_host_create_with_id (host_id, - hostname, - username, - host_cfg, - ntohs (msg->ssh_port)); - GNUNET_free_non_null (username); - GNUNET_free (hostname); - GNUNET_CONFIGURATION_destroy (host_cfg); + LOG_DEBUG("-------username: \n"); + LOG_DEBUG("-------ssh port: %u\n", ntohs(msg->ssh_port)); + host = GNUNET_TESTBED_host_create_with_id(host_id, + hostname, + username, + host_cfg, + ntohs(msg->ssh_port)); + GNUNET_free_non_null(username); + GNUNET_free(hostname); + GNUNET_CONFIGURATION_destroy(host_cfg); if (NULL == host) - { - GNUNET_break_op (0); - GNUNET_SERVICE_client_drop (client); - return; - } - if (GNUNET_OK != host_list_add (host)) - { - /* We are unable to add a host */ - emsg = "A host exists with given host-id"; - LOG_DEBUG ("%s: %u", - emsg, - host_id); - GNUNET_TESTBED_host_destroy (host); - env = GNUNET_MQ_msg_extra (reply, - strlen (emsg) + 1, - GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS); - GNUNET_memcpy (&reply[1], - emsg, - strlen (emsg) + 1); - } + { + GNUNET_break_op(0); + GNUNET_SERVICE_client_drop(client); + return; + } + if (GNUNET_OK != host_list_add(host)) + { + /* We are unable to add a host */ + emsg = "A host exists with given host-id"; + LOG_DEBUG("%s: %u", + emsg, + host_id); + GNUNET_TESTBED_host_destroy(host); + env = GNUNET_MQ_msg_extra(reply, + strlen(emsg) + 1, + GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS); + GNUNET_memcpy(&reply[1], + emsg, + strlen(emsg) + 1); + } else - { - LOG_DEBUG ("Added host %u at %u\n", - host_id, - GST_context->host_id); - env = GNUNET_MQ_msg (reply, - GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS); - } - reply->host_id = htonl (host_id); - GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), - env); - GNUNET_SERVICE_client_continue (client); + { + LOG_DEBUG("Added host %u at %u\n", + host_id, + GST_context->host_id); + env = GNUNET_MQ_msg(reply, + GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS); + } + reply->host_id = htonl(host_id); + GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), + env); + GNUNET_SERVICE_client_continue(client); } @@ -614,8 +615,8 @@ handle_add_host (void *cls, * @param msg the actual message */ static void -handle_slave_get_config (void *cls, - const struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg) +handle_slave_get_config(void *cls, + const struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg) { struct GNUNET_SERVICE_Client *client = cls; struct Slave *slave; @@ -629,42 +630,42 @@ handle_slave_get_config (void *cls, uint64_t op_id; uint32_t slave_id; - slave_id = ntohl (msg->slave_id); - op_id = GNUNET_ntohll (msg->operation_id); - if ( (GST_slave_list_size <= slave_id) || - (NULL == GST_slave_list[slave_id]) ) - { - /* FIXME: Add forwardings for this type of message here.. */ - GST_send_operation_fail_msg (client, - op_id, - "Slave not found"); - GNUNET_SERVICE_client_continue (client); - return; - } + slave_id = ntohl(msg->slave_id); + op_id = GNUNET_ntohll(msg->operation_id); + if ((GST_slave_list_size <= slave_id) || + (NULL == GST_slave_list[slave_id])) + { + /* FIXME: Add forwardings for this type of message here.. */ + GST_send_operation_fail_msg(client, + op_id, + "Slave not found"); + GNUNET_SERVICE_client_continue(client); + return; + } slave = GST_slave_list[slave_id]; - GNUNET_assert (NULL != (cfg = GNUNET_TESTBED_host_get_cfg_ (GST_host_list[slave->host_id]))); - config = GNUNET_CONFIGURATION_serialize (cfg, - &config_size); + GNUNET_assert(NULL != (cfg = GNUNET_TESTBED_host_get_cfg_(GST_host_list[slave->host_id]))); + config = GNUNET_CONFIGURATION_serialize(cfg, + &config_size); /* FIXME: maybe we want to transmit the delta to the default here? */ - xconfig_size = GNUNET_TESTBED_compress_config_ (config, - config_size, - &xconfig); - GNUNET_free (config); - GNUNET_assert (xconfig_size + sizeof (struct GNUNET_TESTBED_SlaveConfiguration) <= UINT16_MAX); - GNUNET_assert (xconfig_size <= UINT16_MAX); - env = GNUNET_MQ_msg_extra (reply, - xconfig_size, - GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION); + xconfig_size = GNUNET_TESTBED_compress_config_(config, + config_size, + &xconfig); + GNUNET_free(config); + GNUNET_assert(xconfig_size + sizeof(struct GNUNET_TESTBED_SlaveConfiguration) <= UINT16_MAX); + GNUNET_assert(xconfig_size <= UINT16_MAX); + env = GNUNET_MQ_msg_extra(reply, + xconfig_size, + GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION); reply->slave_id = msg->slave_id; reply->operation_id = msg->operation_id; - reply->config_size = htons ((uint16_t) config_size); - GNUNET_memcpy (&reply[1], - xconfig, - xconfig_size); - GNUNET_free (xconfig); - GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), - env); - GNUNET_SERVICE_client_continue (client); + reply->config_size = htons((uint16_t)config_size); + GNUNET_memcpy(&reply[1], + xconfig, + xconfig_size); + GNUNET_free(xconfig); + GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), + env); + GNUNET_SERVICE_client_continue(client); } @@ -672,48 +673,52 @@ handle_slave_get_config (void *cls, * Clears the forwarded operations queue */ void -GST_clear_fopcq () +GST_clear_fopcq() { struct ForwardedOperationContext *fopc; while (NULL != (fopc = fopcq_head)) - { - GNUNET_CONTAINER_DLL_remove (fopcq_head, - fopcq_tail, - fopc); - GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc); - if (NULL != fopc->timeout_task) - GNUNET_SCHEDULER_cancel (fopc->timeout_task); - switch (fopc->type) { - case OP_PEER_CREATE: - GNUNET_free (fopc->cls); - break; - case OP_SHUTDOWN_PEERS: - { - struct HandlerContext_ShutdownPeers *hc = fopc->cls; - - GNUNET_assert (0 < hc->nslaves); - hc->nslaves--; - if (0 == hc->nslaves) - GNUNET_free (hc); - } - break; - case OP_PEER_START: - case OP_PEER_STOP: - case OP_PEER_DESTROY: - case OP_PEER_INFO: - case OP_OVERLAY_CONNECT: - case OP_LINK_CONTROLLERS: - case OP_GET_SLAVE_CONFIG: - case OP_MANAGE_SERVICE: - case OP_PEER_RECONFIGURE: - break; - case OP_FORWARDED: - GNUNET_assert (0); - }; - GNUNET_free (fopc); - } + GNUNET_CONTAINER_DLL_remove(fopcq_head, + fopcq_tail, + fopc); + GNUNET_TESTBED_forward_operation_msg_cancel_(fopc->opc); + if (NULL != fopc->timeout_task) + GNUNET_SCHEDULER_cancel(fopc->timeout_task); + switch (fopc->type) + { + case OP_PEER_CREATE: + GNUNET_free(fopc->cls); + break; + + case OP_SHUTDOWN_PEERS: + { + struct HandlerContext_ShutdownPeers *hc = fopc->cls; + + GNUNET_assert(0 < hc->nslaves); + hc->nslaves--; + if (0 == hc->nslaves) + GNUNET_free(hc); + } + break; + + case OP_PEER_START: + case OP_PEER_STOP: + case OP_PEER_DESTROY: + case OP_PEER_INFO: + case OP_OVERLAY_CONNECT: + case OP_LINK_CONTROLLERS: + case OP_GET_SLAVE_CONFIG: + case OP_MANAGE_SERVICE: + case OP_PEER_RECONFIGURE: + break; + + case OP_FORWARDED: + GNUNET_assert(0); + } + ; + GNUNET_free(fopc); + } } @@ -723,49 +728,49 @@ GST_clear_fopcq () * @param cls NULL */ static void -shutdown_task (void *cls) +shutdown_task(void *cls) { uint32_t id; - LOG_DEBUG ("Shutting down testbed service\n"); + LOG_DEBUG("Shutting down testbed service\n"); /* cleanup any remaining forwarded operations */ - GST_clear_fopcq (); - GST_free_lcf (); - GST_free_mctxq (); - GST_free_occq (); - GST_free_roccq (); - GST_free_nccq (); + GST_clear_fopcq(); + GST_free_lcf(); + GST_free_mctxq(); + GST_free_occq(); + GST_free_roccq(); + GST_free_nccq(); GST_neighbour_list_clean(); - GST_free_prcq (); + GST_free_prcq(); /* Clear peer list */ - GST_destroy_peers (); + GST_destroy_peers(); /* Clear route list */ - GST_route_list_clear (); + GST_route_list_clear(); /* Clear GST_slave_list */ - GST_slave_list_clear (); + GST_slave_list_clear(); /* Clear host list */ for (id = 0; id < GST_host_list_size; id++) if (NULL != GST_host_list[id]) - GNUNET_TESTBED_host_destroy (GST_host_list[id]); - GNUNET_free_non_null (GST_host_list); + GNUNET_TESTBED_host_destroy(GST_host_list[id]); + GNUNET_free_non_null(GST_host_list); if (NULL != GST_context) - { - GNUNET_free_non_null (GST_context->master_ip); - if (NULL != GST_context->system) - GNUNET_TESTING_system_destroy (GST_context->system, - GNUNET_YES); - GNUNET_free (GST_context); - GST_context = NULL; - } - GNUNET_free_non_null (hostname); + { + GNUNET_free_non_null(GST_context->master_ip); + if (NULL != GST_context->system) + GNUNET_TESTING_system_destroy(GST_context->system, + GNUNET_YES); + GNUNET_free(GST_context); + GST_context = NULL; + } + GNUNET_free_non_null(hostname); /* Free hello cache */ - GST_cache_clear (); - GST_connection_pool_destroy (); - GNUNET_TESTBED_operation_queue_destroy_ (GST_opq_openfds); + GST_cache_clear(); + GST_connection_pool_destroy(); + GNUNET_TESTBED_operation_queue_destroy_(GST_opq_openfds); GST_opq_openfds = NULL; - GST_stats_destroy (); - GST_barriers_destroy (); - GNUNET_CONFIGURATION_destroy (GST_config); + GST_stats_destroy(); + GST_barriers_destroy(); + GNUNET_CONFIGURATION_destroy(GST_config); } @@ -778,9 +783,9 @@ shutdown_task (void *cls) * @return @a client */ static void * -client_connect_cb (void *cls, - struct GNUNET_SERVICE_Client *client, - struct GNUNET_MQ_Handle *mq) +client_connect_cb(void *cls, + struct GNUNET_SERVICE_Client *client, + struct GNUNET_MQ_Handle *mq) { return client; } @@ -794,41 +799,41 @@ client_connect_cb (void *cls, * @param app_ctx should match @a client */ static void -client_disconnect_cb (void *cls, - struct GNUNET_SERVICE_Client *client, - void *app_ctx) +client_disconnect_cb(void *cls, + struct GNUNET_SERVICE_Client *client, + void *app_ctx) { struct ForwardedOperationContext *fopc; struct ForwardedOperationContext *fopcn; - GNUNET_assert (client == app_ctx); - GST_notify_client_disconnect_oc (client); - GST_link_notify_disconnect (client); - GST_notify_client_disconnect_peers (client); + GNUNET_assert(client == app_ctx); + GST_notify_client_disconnect_oc(client); + GST_link_notify_disconnect(client); + GST_notify_client_disconnect_peers(client); for (fopc = fopcq_head; NULL != fopc; fopc = fopcn) - { - fopcn = fopc->next; - if (fopc->client == client) { - /* handle as if it were a timeout */ - GNUNET_SCHEDULER_cancel (fopc->timeout_task); - GST_forwarded_operation_timeout (fopc); + fopcn = fopc->next; + if (fopc->client == client) + { + /* handle as if it were a timeout */ + GNUNET_SCHEDULER_cancel(fopc->timeout_task); + GST_forwarded_operation_timeout(fopc); + } } - } if (NULL == GST_context) return; if (client == GST_context->client) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Master client disconnected\n"); - GST_context->client = NULL; - /* should not be needed as we're terminated by failure to read - * from stdin, but if stdin fails for some reason, this shouldn't - * hurt for now --- might need to revise this later if we ever - * decide that master connections might be temporarily down - * for some reason */ - //GNUNET_SCHEDULER_shutdown (); - } + { + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Master client disconnected\n"); + GST_context->client = NULL; + /* should not be needed as we're terminated by failure to read + * from stdin, but if stdin fails for some reason, this shouldn't + * hurt for now --- might need to revise this later if we ever + * decide that master connections might be temporarily down + * for some reason */ + //GNUNET_SCHEDULER_shutdown (); + } } @@ -840,54 +845,54 @@ client_disconnect_cb (void *cls, * @param service the initialized server */ static void -testbed_run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_SERVICE_Handle *service) +testbed_run(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_SERVICE_Handle *service) { char *logfile; unsigned long long num; - LOG_DEBUG ("Starting testbed\n"); + LOG_DEBUG("Starting testbed\n"); if (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_filename (cfg, "TESTBED", "LOG_FILE", - &logfile)) - { - GNUNET_break (GNUNET_OK == - GNUNET_log_setup ("testbed", + GNUNET_CONFIGURATION_get_value_filename(cfg, "TESTBED", "LOG_FILE", + &logfile)) + { + GNUNET_break(GNUNET_OK == + GNUNET_log_setup("testbed", "DEBUG", logfile)); - GNUNET_free (logfile); - } - GNUNET_assert (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_number (cfg, - "testbed", - "CACHE_SIZE", - &num)); - GST_cache_init ((unsigned int) num); - GST_connection_pool_init ((unsigned int) num); - GNUNET_assert (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_number (cfg, - "testbed", - "MAX_OPEN_FDS", - &num)); - GST_opq_openfds = GNUNET_TESTBED_operation_queue_create_ (OPERATION_QUEUE_TYPE_FIXED, - (unsigned int) num); - GNUNET_assert (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_time (cfg, + GNUNET_free(logfile); + } + GNUNET_assert(GNUNET_OK == + GNUNET_CONFIGURATION_get_value_number(cfg, + "testbed", + "CACHE_SIZE", + &num)); + GST_cache_init((unsigned int)num); + GST_connection_pool_init((unsigned int)num); + GNUNET_assert(GNUNET_OK == + GNUNET_CONFIGURATION_get_value_number(cfg, + "testbed", + "MAX_OPEN_FDS", + &num)); + GST_opq_openfds = GNUNET_TESTBED_operation_queue_create_(OPERATION_QUEUE_TYPE_FIXED, + (unsigned int)num); + GNUNET_assert(GNUNET_OK == + GNUNET_CONFIGURATION_get_value_time(cfg, + "testbed", + "OPERATION_TIMEOUT", + &GST_timeout)); + GNUNET_assert(GNUNET_OK == + GNUNET_CONFIGURATION_get_value_string(cfg, "testbed", - "OPERATION_TIMEOUT", - &GST_timeout)); - GNUNET_assert (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_string (cfg, - "testbed", - "HOSTNAME", - &hostname)); - GST_config = GNUNET_CONFIGURATION_dup (cfg); - GNUNET_SCHEDULER_add_shutdown (&shutdown_task, - NULL); - LOG_DEBUG ("Testbed startup complete\n"); - GST_stats_init (GST_config); - GST_barriers_init (GST_config); + "HOSTNAME", + &hostname)); + GST_config = GNUNET_CONFIGURATION_dup(cfg); + GNUNET_SCHEDULER_add_shutdown(&shutdown_task, + NULL); + LOG_DEBUG("Testbed startup complete\n"); + GST_stats_init(GST_config); + GST_barriers_init(GST_config); } @@ -895,81 +900,81 @@ testbed_run (void *cls, * Define "main" method using service macro. */ GNUNET_SERVICE_MAIN -("testbed", - GNUNET_SERVICE_OPTION_NONE, - &testbed_run, - &client_connect_cb, - &client_disconnect_cb, - NULL, - GNUNET_MQ_hd_var_size (init, + ("testbed", + GNUNET_SERVICE_OPTION_NONE, + &testbed_run, + &client_connect_cb, + &client_disconnect_cb, + NULL, + GNUNET_MQ_hd_var_size(init, GNUNET_MESSAGE_TYPE_TESTBED_INIT, struct GNUNET_TESTBED_InitMessage, NULL), - GNUNET_MQ_hd_var_size (add_host, + GNUNET_MQ_hd_var_size(add_host, GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST, struct GNUNET_TESTBED_AddHostMessage, NULL), - GNUNET_MQ_hd_fixed_size (slave_get_config, + GNUNET_MQ_hd_fixed_size(slave_get_config, GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION, struct GNUNET_TESTBED_SlaveGetConfigurationMessage, NULL), - GNUNET_MQ_hd_fixed_size (link_controllers, + GNUNET_MQ_hd_fixed_size(link_controllers, GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS, struct GNUNET_TESTBED_ControllerLinkRequest, NULL), - GNUNET_MQ_hd_var_size (remote_overlay_connect, + GNUNET_MQ_hd_var_size(remote_overlay_connect, GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT, struct GNUNET_TESTBED_RemoteOverlayConnectMessage, NULL), - GNUNET_MQ_hd_fixed_size (overlay_connect, + GNUNET_MQ_hd_fixed_size(overlay_connect, GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT, struct GNUNET_TESTBED_OverlayConnectMessage, NULL), - GNUNET_MQ_hd_var_size (peer_create, + GNUNET_MQ_hd_var_size(peer_create, GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER, struct GNUNET_TESTBED_PeerCreateMessage, NULL), - GNUNET_MQ_hd_fixed_size (peer_destroy, + GNUNET_MQ_hd_fixed_size(peer_destroy, GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER, struct GNUNET_TESTBED_PeerDestroyMessage, NULL), - GNUNET_MQ_hd_fixed_size (peer_start, + GNUNET_MQ_hd_fixed_size(peer_start, GNUNET_MESSAGE_TYPE_TESTBED_START_PEER, struct GNUNET_TESTBED_PeerStartMessage, NULL), - GNUNET_MQ_hd_fixed_size (peer_stop, + GNUNET_MQ_hd_fixed_size(peer_stop, GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER, struct GNUNET_TESTBED_PeerStopMessage, NULL), - GNUNET_MQ_hd_fixed_size (peer_get_config, + GNUNET_MQ_hd_fixed_size(peer_get_config, GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION, struct GNUNET_TESTBED_PeerGetConfigurationMessage, NULL), - GNUNET_MQ_hd_var_size (manage_peer_service, + GNUNET_MQ_hd_var_size(manage_peer_service, GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE, struct GNUNET_TESTBED_ManagePeerServiceMessage, NULL), - GNUNET_MQ_hd_fixed_size (shutdown_peers, + GNUNET_MQ_hd_fixed_size(shutdown_peers, GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS, struct GNUNET_TESTBED_ShutdownPeersMessage, NULL), - GNUNET_MQ_hd_var_size (peer_reconfigure, + GNUNET_MQ_hd_var_size(peer_reconfigure, GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER, struct GNUNET_TESTBED_PeerReconfigureMessage, NULL), - GNUNET_MQ_hd_var_size (barrier_init, + GNUNET_MQ_hd_var_size(barrier_init, GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT, struct GNUNET_TESTBED_BarrierInit, NULL), - GNUNET_MQ_hd_var_size (barrier_cancel, + GNUNET_MQ_hd_var_size(barrier_cancel, GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL, struct GNUNET_TESTBED_BarrierCancel, NULL), - GNUNET_MQ_hd_var_size (barrier_status, + GNUNET_MQ_hd_var_size(barrier_status, GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS, struct GNUNET_TESTBED_BarrierStatusMsg, NULL), - GNUNET_MQ_handler_end ()); + GNUNET_MQ_handler_end()); /* end of gnunet-service-testbed.c */ diff --git a/src/testbed/gnunet-service-testbed.h b/src/testbed/gnunet-service-testbed.h index 5e835392b..d68f8a3e4 100644 --- a/src/testbed/gnunet-service-testbed.h +++ b/src/testbed/gnunet-service-testbed.h @@ -1,22 +1,22 @@ /* - This file is part of GNUnet. - Copyright (C) 2008--2013 GNUnet e.V. + This file is part of GNUnet. + Copyright (C) 2008--2013 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 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. + 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 . + 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/gnunet-service-testbed.h @@ -41,14 +41,14 @@ /** * Generic logging */ -#define LOG(kind,...) \ - GNUNET_log (kind, __VA_ARGS__) +#define LOG(kind, ...) \ + GNUNET_log(kind, __VA_ARGS__) /** * Debug logging */ #define LOG_DEBUG(...) \ - LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) + LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) /** * By how much should the arrays lists grow @@ -59,8 +59,7 @@ /** * A routing entry */ -struct Route -{ +struct Route { /** * destination host */ @@ -76,8 +75,7 @@ struct Route /** * Context information for operations forwarded to subcontrollers */ -struct ForwardedOperationContext -{ +struct ForwardedOperationContext { /** * The next pointer for DLL */ @@ -117,15 +115,13 @@ struct ForwardedOperationContext * The type of the operation which is forwarded */ enum OperationType type; - }; /** * A DLL of host registrations to be made */ -struct HostRegistration -{ +struct HostRegistration { /** * next registration in the DLL */ @@ -156,8 +152,7 @@ struct HostRegistration /** * Context information used while linking controllers */ -struct LinkControllersContext -{ +struct LinkControllersContext { /** * The client which initiated the link controller operation */ @@ -167,20 +162,15 @@ struct LinkControllersContext * The ID of the operation */ uint64_t operation_id; - }; /** * A peer */ -struct Peer -{ - - union - { - struct - { +struct Peer { + union { + struct { /** * The peer handle from testing API */ @@ -196,11 +186,9 @@ struct Peer * Is the peer running */ int is_running; - } local; - struct - { + struct { /** * The slave this peer is started through */ @@ -210,9 +198,7 @@ struct Peer * The id of the remote host this peer is running on */ uint32_t remote_host_id; - } remote; - } details; /** @@ -242,15 +228,13 @@ struct Peer * the peer */ uint32_t destroy_flag; - }; /** * The main context information associated with the client which started us */ -struct Context -{ +struct Context { /** * The client handle associated with this context */ @@ -276,8 +260,7 @@ struct Context /** * The structure for identifying a shared service */ -struct SharedService -{ +struct SharedService { /** * The name of the shared service */ @@ -302,8 +285,7 @@ struct RegisteredHostContext; * Context information to used during operations which forward the overlay * connect message */ -struct ForwardedOverlayConnectContext -{ +struct ForwardedOverlayConnectContext { /** * next ForwardedOverlayConnectContext in the DLL */ @@ -355,8 +337,7 @@ struct ForwardedOverlayConnectContext * This context information will be created for each host that is registered at * slave controllers during overlay connects. */ -struct RegisteredHostContext -{ +struct RegisteredHostContext { /** * The host which is being registered */ @@ -380,9 +361,7 @@ struct RegisteredHostContext /** * Enumeration of states for this context */ - enum RHCState - { - + enum RHCState { /** * The initial state */ @@ -393,15 +372,13 @@ struct RegisteredHostContext */ RHC_DONE } state; - }; /** * Context data for #GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS handler */ -struct HandlerContext_ShutdownPeers -{ +struct HandlerContext_ShutdownPeers { /** * The number of slave we expect to hear from since we forwarded the * #GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS message to them @@ -480,13 +457,13 @@ extern char *GST_stats_dir; * Condition to check if host id is valid */ #define VALID_HOST_ID(id) \ - ( ((id) < GST_host_list_size) && (NULL != GST_host_list[id]) ) + (((id) < GST_host_list_size) && (NULL != GST_host_list[id])) /** * Condition to check if peer id is valid */ #define VALID_PEER_ID(id) \ - ( ((id) < GST_peer_list_size) && (NULL != GST_peer_list[id]) ) + (((id) < GST_peer_list_size) && (NULL != GST_peer_list[id])) /** @@ -502,15 +479,15 @@ extern char *GST_stats_dir; */ #define GST_array_grow_large_enough(ptr, size, accommodate_size) \ do \ - { \ - unsigned int growth_size; \ - GNUNET_assert (size <= accommodate_size); \ - growth_size = size; \ - while (growth_size <= accommodate_size) \ + { \ + unsigned int growth_size; \ + GNUNET_assert(size <= accommodate_size); \ + growth_size = size; \ + while (growth_size <= accommodate_size) \ growth_size += LIST_GROW_STEP; \ - GNUNET_array_grow (ptr, size, growth_size); \ - GNUNET_assert (size > accommodate_size); \ - } while (0) + GNUNET_array_grow (ptr, size, growth_size); \ + GNUNET_assert(size > accommodate_size); \ + } while (0) /** @@ -519,14 +496,14 @@ extern char *GST_stats_dir; * @param peer the peer structure to destroy */ void -GST_destroy_peer (struct Peer *peer); +GST_destroy_peer(struct Peer *peer); /** * Stops and destroys all peers */ void -GST_destroy_peers (void); +GST_destroy_peers(void); /** @@ -538,7 +515,7 @@ GST_destroy_peers (void); * is found */ struct Route * -GST_find_dest_route (uint32_t host_id); +GST_find_dest_route(uint32_t host_id); /** @@ -548,8 +525,8 @@ GST_find_dest_route (uint32_t host_id); * @param msg the actual message */ void -handle_overlay_connect (void *cls, - const struct GNUNET_TESTBED_OverlayConnectMessage *msg); +handle_overlay_connect(void *cls, + const struct GNUNET_TESTBED_OverlayConnectMessage *msg); /** @@ -562,9 +539,9 @@ handle_overlay_connect (void *cls, * @param host the host which has to be registered */ void -GST_queue_host_registration (struct Slave *slave, - GNUNET_TESTBED_HostRegistrationCompletion cb, - void *cb_cls, struct GNUNET_TESTBED_Host *host); +GST_queue_host_registration(struct Slave *slave, + GNUNET_TESTBED_HostRegistrationCompletion cb, + void *cb_cls, struct GNUNET_TESTBED_Host *host); /** @@ -574,8 +551,8 @@ GST_queue_host_registration (struct Slave *slave, * @param msg the message to relay */ void -GST_forwarded_operation_reply_relay (void *cls, - const struct GNUNET_MessageHeader *msg); +GST_forwarded_operation_reply_relay(void *cls, + const struct GNUNET_MessageHeader *msg); /** @@ -585,14 +562,14 @@ GST_forwarded_operation_reply_relay (void *cls, * @param tc the task context from scheduler */ void -GST_forwarded_operation_timeout (void *cls); +GST_forwarded_operation_timeout(void *cls); /** * Clears the forwarded operations queue */ void -GST_clear_fopcq (void); +GST_clear_fopcq(void); /** @@ -603,9 +580,9 @@ GST_clear_fopcq (void); * @param emsg the error message; can be NULL */ void -GST_send_operation_fail_msg (struct GNUNET_SERVICE_Client *client, - uint64_t operation_id, - const char *emsg); +GST_send_operation_fail_msg(struct GNUNET_SERVICE_Client *client, + uint64_t operation_id, + const char *emsg); /** @@ -614,7 +591,7 @@ GST_send_operation_fail_msg (struct GNUNET_SERVICE_Client *client, * @param client the client that disconnected */ void -GST_notify_client_disconnect_oc (struct GNUNET_SERVICE_Client *client); +GST_notify_client_disconnect_oc(struct GNUNET_SERVICE_Client *client); /** @@ -623,7 +600,7 @@ GST_notify_client_disconnect_oc (struct GNUNET_SERVICE_Client *client); * @param client the client that disconnected */ void -GST_notify_client_disconnect_peers (struct GNUNET_SERVICE_Client *client); +GST_notify_client_disconnect_peers(struct GNUNET_SERVICE_Client *client); /** @@ -633,8 +610,8 @@ GST_notify_client_disconnect_peers (struct GNUNET_SERVICE_Client *client); * @param operation_id the id of the operation which was successful */ void -GST_send_operation_success_msg (struct GNUNET_SERVICE_Client *client, - uint64_t operation_id); +GST_send_operation_success_msg(struct GNUNET_SERVICE_Client *client, + uint64_t operation_id); /** @@ -645,8 +622,8 @@ GST_send_operation_success_msg (struct GNUNET_SERVICE_Client *client, * @return #GNUNET_OK if @a msg is well-formed */ int -check_remote_overlay_connect (void *cls, - const struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg); +check_remote_overlay_connect(void *cls, + const struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg); /** @@ -656,8 +633,8 @@ check_remote_overlay_connect (void *cls, * @param msg the actual message */ void -handle_remote_overlay_connect (void *cls, - const struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg); +handle_remote_overlay_connect(void *cls, + const struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg); /** @@ -668,8 +645,8 @@ handle_remote_overlay_connect (void *cls, * @return #GNUNET_OK if @a msg is well-formed */ int -check_peer_create (void *cls, - const struct GNUNET_TESTBED_PeerCreateMessage *msg); +check_peer_create(void *cls, + const struct GNUNET_TESTBED_PeerCreateMessage *msg); /** @@ -679,8 +656,8 @@ check_peer_create (void *cls, * @param message the actual message */ void -handle_peer_create (void *cls, - const struct GNUNET_TESTBED_PeerCreateMessage *msg); +handle_peer_create(void *cls, + const struct GNUNET_TESTBED_PeerCreateMessage *msg); /** @@ -690,8 +667,8 @@ handle_peer_create (void *cls, * @param msg the actual message */ void -handle_peer_destroy (void *cls, - const struct GNUNET_TESTBED_PeerDestroyMessage *msg); +handle_peer_destroy(void *cls, + const struct GNUNET_TESTBED_PeerDestroyMessage *msg); /** @@ -701,8 +678,8 @@ handle_peer_destroy (void *cls, * @param msg the actual message */ void -handle_peer_start (void *cls, - const struct GNUNET_TESTBED_PeerStartMessage *msg); +handle_peer_start(void *cls, + const struct GNUNET_TESTBED_PeerStartMessage *msg); /** @@ -712,8 +689,8 @@ handle_peer_start (void *cls, * @param message the actual message */ void -handle_peer_stop (void *cls, - const struct GNUNET_TESTBED_PeerStopMessage *msg); +handle_peer_stop(void *cls, + const struct GNUNET_TESTBED_PeerStopMessage *msg); /** @@ -723,8 +700,8 @@ handle_peer_stop (void *cls, * @param msg the actual message */ void -handle_peer_get_config (void *cls, - const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg); +handle_peer_get_config(void *cls, + const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg); /** @@ -734,8 +711,8 @@ handle_peer_get_config (void *cls, * @param msg the actual message */ void -handle_shutdown_peers (void *cls, - const struct GNUNET_TESTBED_ShutdownPeersMessage *msg); +handle_shutdown_peers(void *cls, + const struct GNUNET_TESTBED_ShutdownPeersMessage *msg); /** @@ -746,8 +723,8 @@ handle_shutdown_peers (void *cls, * @return #GNUNET_OK if @a msg is well-formed */ int -check_manage_peer_service (void *cls, - const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg); +check_manage_peer_service(void *cls, + const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg); /** @@ -757,8 +734,8 @@ check_manage_peer_service (void *cls, * @param msg the actual message */ void -handle_manage_peer_service (void *cls, - const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg); +handle_manage_peer_service(void *cls, + const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg); @@ -771,8 +748,8 @@ handle_manage_peer_service (void *cls, * @return #GNUNET_OK if @a msg is well-formed */ int -check_peer_reconfigure (void *cls, - const struct GNUNET_TESTBED_PeerReconfigureMessage *msg); +check_peer_reconfigure(void *cls, + const struct GNUNET_TESTBED_PeerReconfigureMessage *msg); /** @@ -784,29 +761,29 @@ check_peer_reconfigure (void *cls, * @param msg the actual message */ void -handle_peer_reconfigure (void *cls, - const struct GNUNET_TESTBED_PeerReconfigureMessage *msg); +handle_peer_reconfigure(void *cls, + const struct GNUNET_TESTBED_PeerReconfigureMessage *msg); /** * Frees the ManageServiceContext queue */ void -GST_free_mctxq (void); +GST_free_mctxq(void); /** * Cleans up the queue used for forwarding link controllers requests */ void -GST_free_lcf (void); +GST_free_lcf(void); /** * Cleans up the route list */ void -GST_route_list_clear (void); +GST_route_list_clear(void); /** @@ -815,7 +792,7 @@ GST_route_list_clear (void); * @param rhc the RegisteredHostContext */ void -GST_process_next_focc (struct RegisteredHostContext *rhc); +GST_process_next_focc(struct RegisteredHostContext *rhc); /** @@ -824,28 +801,28 @@ GST_process_next_focc (struct RegisteredHostContext *rhc); * @param focc the ForwardedOverlayConnectContext to cleanup */ void -GST_cleanup_focc (struct ForwardedOverlayConnectContext *focc); +GST_cleanup_focc(struct ForwardedOverlayConnectContext *focc); /** * Clears all pending overlay connect contexts in queue */ void -GST_free_occq (void); +GST_free_occq(void); /** * Clears all pending remote overlay connect contexts in queue */ void -GST_free_roccq (void); +GST_free_roccq(void); /** * Cleans up the Peer reconfigure context list */ void -GST_free_prcq (void); +GST_free_prcq(void); /** @@ -854,14 +831,14 @@ GST_free_prcq (void); * @param size the size of the cache */ void -GST_cache_init (unsigned int size); +GST_cache_init(unsigned int size); /** * Clear cache */ void -GST_cache_clear (void); +GST_cache_clear(void); /** @@ -871,7 +848,7 @@ GST_cache_clear (void); * @return the HELLO message; NULL if not found */ const struct GNUNET_MessageHeader * -GST_cache_lookup_hello (const unsigned int peer_id); +GST_cache_lookup_hello(const unsigned int peer_id); /** @@ -882,8 +859,8 @@ GST_cache_lookup_hello (const unsigned int peer_id); * @param hello the HELLO message */ void -GST_cache_add_hello (const unsigned int peer_id, - const struct GNUNET_MessageHeader *hello); +GST_cache_add_hello(const unsigned int peer_id, + const struct GNUNET_MessageHeader *hello); /** @@ -892,13 +869,13 @@ GST_cache_add_hello (const unsigned int peer_id, * generated from the hostname and the process's PID. */ void -GST_stats_init (const struct GNUNET_CONFIGURATION_Handle *cfg); +GST_stats_init(const struct GNUNET_CONFIGURATION_Handle *cfg); /** * Shutdown the status calls module. */ void -GST_stats_destroy (void); +GST_stats_destroy(void); /* End of gnunet-service-testbed.h */ diff --git a/src/testbed/gnunet-service-testbed_barriers.c b/src/testbed/gnunet-service-testbed_barriers.c index dbcf5ed69..c2cb9a99c 100644 --- a/src/testbed/gnunet-service-testbed_barriers.c +++ b/src/testbed/gnunet-service-testbed_barriers.c @@ -1,22 +1,22 @@ /* - This file is part of GNUnet. - Copyright (C) 2008--2016 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 . + This file is part of GNUnet. + Copyright (C) 2008--2016 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/gnunet-service-testbed_barriers.c @@ -33,7 +33,7 @@ * timeout for outgoing message transmissions in seconds */ #define MESSAGE_SEND_TIMEOUT(s) \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, s) + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, s) /** @@ -50,8 +50,8 @@ /** * Logging shorthand */ -#define LOG(kind,...) \ - GNUNET_log_from (kind, "testbed-barriers", __VA_ARGS__) +#define LOG(kind, ...) \ + GNUNET_log_from(kind, "testbed-barriers", __VA_ARGS__) /** @@ -63,8 +63,7 @@ struct Barrier; /** * Context to be associated with each client */ -struct ClientCtx -{ +struct ClientCtx { /** * The barrier this client is waiting for */ @@ -84,15 +83,13 @@ struct ClientCtx * The client handle */ struct GNUNET_SERVICE_Client *client; - }; /** * Wrapper around Barrier handle */ -struct WBarrier -{ +struct WBarrier { /** * DLL next pointer */ @@ -128,8 +125,7 @@ struct WBarrier /** * Barrier */ -struct Barrier -{ +struct Barrier { /** * The hashcode of the barrier name */ @@ -204,7 +200,6 @@ struct Barrier * Quorum percentage to be reached */ uint8_t quorum; - }; @@ -226,23 +221,23 @@ static struct GNUNET_SERVICE_Handle *ctx; * @param barrier the barrier handle */ static void -remove_barrier (struct Barrier *barrier) +remove_barrier(struct Barrier *barrier) { struct ClientCtx *ctx; - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (barrier_map, - &barrier->hash, - barrier)); + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove(barrier_map, + &barrier->hash, + barrier)); while (NULL != (ctx = barrier->head)) - { - GNUNET_CONTAINER_DLL_remove (barrier->head, - barrier->tail, - ctx); - ctx->barrier = NULL; - } - GNUNET_free (barrier->name); - GNUNET_free (barrier); + { + GNUNET_CONTAINER_DLL_remove(barrier->head, + barrier->tail, + ctx); + ctx->barrier = NULL; + } + GNUNET_free(barrier->name); + GNUNET_free(barrier); } @@ -252,18 +247,18 @@ remove_barrier (struct Barrier *barrier) * @param barrier the local barrier */ static void -cancel_wrappers (struct Barrier *barrier) +cancel_wrappers(struct Barrier *barrier) { struct WBarrier *wrapper; while (NULL != (wrapper = barrier->whead)) - { - GNUNET_TESTBED_barrier_cancel (wrapper->hbarrier); - GNUNET_CONTAINER_DLL_remove (barrier->whead, - barrier->wtail, - wrapper); - GNUNET_free (wrapper); - } + { + GNUNET_TESTBED_barrier_cancel(wrapper->hbarrier); + GNUNET_CONTAINER_DLL_remove(barrier->whead, + barrier->wtail, + wrapper); + GNUNET_free(wrapper); + } } @@ -277,33 +272,33 @@ cancel_wrappers (struct Barrier *barrier) * status=GNUNET_TESTBED_BARRIERSTATUS_ERROR */ static void -send_client_status_msg (struct GNUNET_SERVICE_Client *client, - const char *name, - enum GNUNET_TESTBED_BarrierStatus status, - const char *emsg) +send_client_status_msg(struct GNUNET_SERVICE_Client *client, + const char *name, + enum GNUNET_TESTBED_BarrierStatus status, + const char *emsg) { struct GNUNET_MQ_Envelope *env; struct GNUNET_TESTBED_BarrierStatusMsg *msg; size_t name_len; size_t err_len; - GNUNET_assert ( (NULL == emsg) || - (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status) ); - name_len = strlen (name) + 1; - err_len = ((NULL == emsg) ? 0 : (strlen (emsg) + 1)); - env = GNUNET_MQ_msg_extra (msg, - name_len + err_len, - GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS); - msg->status = htons (status); - msg->name_len = htons ((uint16_t) name_len - 1); - GNUNET_memcpy (msg->data, - name, - name_len); - GNUNET_memcpy (msg->data + name_len, - emsg, - err_len); - GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), - env); + GNUNET_assert((NULL == emsg) || + (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status)); + name_len = strlen(name) + 1; + err_len = ((NULL == emsg) ? 0 : (strlen(emsg) + 1)); + env = GNUNET_MQ_msg_extra(msg, + name_len + err_len, + GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS); + msg->status = htons(status); + msg->name_len = htons((uint16_t)name_len - 1); + GNUNET_memcpy(msg->data, + name, + name_len); + GNUNET_memcpy(msg->data + name_len, + emsg, + err_len); + GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), + env); } @@ -315,14 +310,14 @@ send_client_status_msg (struct GNUNET_SERVICE_Client *client, * status=GNUNET_TESTBED_BARRIERSTATUS_ERROR */ static void -send_barrier_status_msg (struct Barrier *barrier, - const char *emsg) +send_barrier_status_msg(struct Barrier *barrier, + const char *emsg) { - GNUNET_assert (0 != barrier->status); - send_client_status_msg (barrier->mc, - barrier->name, - barrier->status, - emsg); + GNUNET_assert(0 != barrier->status); + send_client_status_msg(barrier->mc, + barrier->name, + barrier->status, + emsg); } @@ -333,8 +328,8 @@ send_barrier_status_msg (struct Barrier *barrier, * @param message the actual message */ static int -check_barrier_wait (void *cls, - const struct GNUNET_TESTBED_BarrierWait *msg) +check_barrier_wait(void *cls, + const struct GNUNET_TESTBED_BarrierWait *msg) { return GNUNET_OK; /* always well-formed */ } @@ -352,8 +347,8 @@ check_barrier_wait (void *cls, * @param message the actual message */ static void -handle_barrier_wait (void *cls, - const struct GNUNET_TESTBED_BarrierWait *msg) +handle_barrier_wait(void *cls, + const struct GNUNET_TESTBED_BarrierWait *msg) { struct ClientCtx *client_ctx = cls; struct Barrier *barrier; @@ -362,50 +357,50 @@ handle_barrier_wait (void *cls, size_t name_len; uint16_t msize; - msize = ntohs (msg->header.size); + msize = ntohs(msg->header.size); if (NULL == barrier_map) - { - GNUNET_break (0); - GNUNET_SERVICE_client_drop (client_ctx->client); - return; - } - name_len = msize - sizeof (struct GNUNET_TESTBED_BarrierWait); - name = GNUNET_malloc (name_len + 1); + { + GNUNET_break(0); + GNUNET_SERVICE_client_drop(client_ctx->client); + return; + } + name_len = msize - sizeof(struct GNUNET_TESTBED_BarrierWait); + name = GNUNET_malloc(name_len + 1); name[name_len] = '\0'; - GNUNET_memcpy (name, - msg->name, - name_len); - LOG_DEBUG ("Received BARRIER_WAIT for barrier `%s'\n", - name); - GNUNET_CRYPTO_hash (name, - name_len, - &key); - GNUNET_free (name); - if (NULL == (barrier = GNUNET_CONTAINER_multihashmap_get (barrier_map, &key))) - { - GNUNET_break (0); - GNUNET_SERVICE_client_drop (client_ctx->client); - return; - } + GNUNET_memcpy(name, + msg->name, + name_len); + LOG_DEBUG("Received BARRIER_WAIT for barrier `%s'\n", + name); + GNUNET_CRYPTO_hash(name, + name_len, + &key); + GNUNET_free(name); + if (NULL == (barrier = GNUNET_CONTAINER_multihashmap_get(barrier_map, &key))) + { + GNUNET_break(0); + GNUNET_SERVICE_client_drop(client_ctx->client); + return; + } if (NULL != client_ctx->barrier) - { - GNUNET_break (0); - GNUNET_SERVICE_client_drop (client_ctx->client); - return; - } + { + GNUNET_break(0); + GNUNET_SERVICE_client_drop(client_ctx->client); + return; + } client_ctx->barrier = barrier; - GNUNET_CONTAINER_DLL_insert_tail (barrier->head, - barrier->tail, - client_ctx); + GNUNET_CONTAINER_DLL_insert_tail(barrier->head, + barrier->tail, + client_ctx); barrier->nreached++; - if ( (barrier->num_wbarriers_reached == barrier->num_wbarriers) && - (LOCAL_QUORUM_REACHED (barrier)) ) - { - barrier->status = GNUNET_TESTBED_BARRIERSTATUS_CROSSED; - send_barrier_status_msg (barrier, - NULL); - } - GNUNET_SERVICE_client_continue (client_ctx->client); + if ((barrier->num_wbarriers_reached == barrier->num_wbarriers) && + (LOCAL_QUORUM_REACHED(barrier))) + { + barrier->status = GNUNET_TESTBED_BARRIERSTATUS_CROSSED; + send_barrier_status_msg(barrier, + NULL); + } + GNUNET_SERVICE_client_continue(client_ctx->client); } @@ -418,14 +413,14 @@ handle_barrier_wait (void *cls, * @return our `struct ClientCtx` */ static void * -connect_cb (void *cls, - struct GNUNET_SERVICE_Client *client, - struct GNUNET_MQ_Handle *mq) +connect_cb(void *cls, + struct GNUNET_SERVICE_Client *client, + struct GNUNET_MQ_Handle *mq) { struct ClientCtx *client_ctx; - LOG_DEBUG ("Client connected to testbed-barrier service\n"); - client_ctx = GNUNET_new (struct ClientCtx); + LOG_DEBUG("Client connected to testbed-barrier service\n"); + client_ctx = GNUNET_new(struct ClientCtx); client_ctx->client = client; return client_ctx; } @@ -440,22 +435,22 @@ connect_cb (void *cls, * for the last call when the server is destroyed */ static void -disconnect_cb (void *cls, - struct GNUNET_SERVICE_Client *client, - void *app_ctx) +disconnect_cb(void *cls, + struct GNUNET_SERVICE_Client *client, + void *app_ctx) { struct ClientCtx *client_ctx = app_ctx; struct Barrier *barrier = client_ctx->barrier; if (NULL != barrier) - { - GNUNET_CONTAINER_DLL_remove (barrier->head, - barrier->tail, - client_ctx); - client_ctx->barrier = NULL; - } - GNUNET_free (client_ctx); - LOG_DEBUG ("Client disconnected from testbed-barrier service\n"); + { + GNUNET_CONTAINER_DLL_remove(barrier->head, + barrier->tail, + client_ctx); + client_ctx->barrier = NULL; + } + GNUNET_free(client_ctx); + LOG_DEBUG("Client disconnected from testbed-barrier service\n"); } @@ -465,25 +460,25 @@ disconnect_cb (void *cls, * @param cfg the configuration to use for initialisation */ void -GST_barriers_init (struct GNUNET_CONFIGURATION_Handle *cfg) +GST_barriers_init(struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_MQ_MessageHandler message_handlers[] = { - GNUNET_MQ_hd_var_size (barrier_wait, - GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT, - struct GNUNET_TESTBED_BarrierWait, - NULL), - GNUNET_MQ_handler_end () + GNUNET_MQ_hd_var_size(barrier_wait, + GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT, + struct GNUNET_TESTBED_BarrierWait, + NULL), + GNUNET_MQ_handler_end() }; - LOG_DEBUG ("Launching testbed-barrier service\n"); - barrier_map = GNUNET_CONTAINER_multihashmap_create (3, - GNUNET_YES); - ctx = GNUNET_SERVICE_start ("testbed-barrier", - cfg, - &connect_cb, - &disconnect_cb, - NULL, - message_handlers); + LOG_DEBUG("Launching testbed-barrier service\n"); + barrier_map = GNUNET_CONTAINER_multihashmap_create(3, + GNUNET_YES); + ctx = GNUNET_SERVICE_start("testbed-barrier", + cfg, + &connect_cb, + &disconnect_cb, + NULL, + message_handlers); } @@ -498,15 +493,15 @@ GST_barriers_init (struct GNUNET_CONFIGURATION_Handle *cfg) * #GNUNET_NO if not. */ static int -barrier_destroy_iterator (void *cls, - const struct GNUNET_HashCode *key, - void *value) +barrier_destroy_iterator(void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct Barrier *barrier = value; - GNUNET_assert (NULL != barrier); - cancel_wrappers (barrier); - remove_barrier (barrier); + GNUNET_assert(NULL != barrier); + cancel_wrappers(barrier); + remove_barrier(barrier); return GNUNET_YES; } @@ -515,16 +510,16 @@ barrier_destroy_iterator (void *cls, * Function to stop the barrier service */ void -GST_barriers_destroy () +GST_barriers_destroy() { - GNUNET_assert (NULL != barrier_map); - GNUNET_assert (GNUNET_SYSERR != - GNUNET_CONTAINER_multihashmap_iterate (barrier_map, - &barrier_destroy_iterator, - NULL)); - GNUNET_CONTAINER_multihashmap_destroy (barrier_map); - GNUNET_assert (NULL != ctx); - GNUNET_SERVICE_stop (ctx); + GNUNET_assert(NULL != barrier_map); + GNUNET_assert(GNUNET_SYSERR != + GNUNET_CONTAINER_multihashmap_iterate(barrier_map, + &barrier_destroy_iterator, + NULL)); + GNUNET_CONTAINER_multihashmap_destroy(barrier_map); + GNUNET_assert(NULL != ctx); + GNUNET_SERVICE_stop(ctx); } @@ -542,57 +537,59 @@ GST_barriers_destroy () * error messsage */ static void -wbarrier_status_cb (void *cls, - const char *name, - struct GNUNET_TESTBED_Barrier *b_, - enum GNUNET_TESTBED_BarrierStatus status, - const char *emsg) +wbarrier_status_cb(void *cls, + const char *name, + struct GNUNET_TESTBED_Barrier *b_, + enum GNUNET_TESTBED_BarrierStatus status, + const char *emsg) { struct WBarrier *wrapper = cls; struct Barrier *barrier = wrapper->barrier; - GNUNET_assert (b_ == wrapper->hbarrier); + GNUNET_assert(b_ == wrapper->hbarrier); switch (status) - { - case GNUNET_TESTBED_BARRIERSTATUS_ERROR: - LOG (GNUNET_ERROR_TYPE_ERROR, - "Initialising barrier `%s' failed at a sub-controller: %s\n", - barrier->name, - (NULL != emsg) ? emsg : "NULL"); - cancel_wrappers (barrier); - if (NULL == emsg) - emsg = "Initialisation failed at a sub-controller"; - barrier->status = GNUNET_TESTBED_BARRIERSTATUS_ERROR; - send_barrier_status_msg (barrier, emsg); - return; - case GNUNET_TESTBED_BARRIERSTATUS_CROSSED: - if (GNUNET_TESTBED_BARRIERSTATUS_INITIALISED != barrier->status) { - GNUNET_break_op (0); + case GNUNET_TESTBED_BARRIERSTATUS_ERROR: + LOG(GNUNET_ERROR_TYPE_ERROR, + "Initialising barrier `%s' failed at a sub-controller: %s\n", + barrier->name, + (NULL != emsg) ? emsg : "NULL"); + cancel_wrappers(barrier); + if (NULL == emsg) + emsg = "Initialisation failed at a sub-controller"; + barrier->status = GNUNET_TESTBED_BARRIERSTATUS_ERROR; + send_barrier_status_msg(barrier, emsg); return; - } - barrier->num_wbarriers_reached++; - if ((barrier->num_wbarriers_reached == barrier->num_wbarriers) - && (LOCAL_QUORUM_REACHED (barrier))) - { - barrier->status = GNUNET_TESTBED_BARRIERSTATUS_CROSSED; - send_barrier_status_msg (barrier, NULL); - } - return; - case GNUNET_TESTBED_BARRIERSTATUS_INITIALISED: - if (0 != barrier->status) - { - GNUNET_break_op (0); + + case GNUNET_TESTBED_BARRIERSTATUS_CROSSED: + if (GNUNET_TESTBED_BARRIERSTATUS_INITIALISED != barrier->status) + { + GNUNET_break_op(0); + return; + } + barrier->num_wbarriers_reached++; + if ((barrier->num_wbarriers_reached == barrier->num_wbarriers) + && (LOCAL_QUORUM_REACHED(barrier))) + { + barrier->status = GNUNET_TESTBED_BARRIERSTATUS_CROSSED; + send_barrier_status_msg(barrier, NULL); + } + return; + + case GNUNET_TESTBED_BARRIERSTATUS_INITIALISED: + if (0 != barrier->status) + { + GNUNET_break_op(0); + return; + } + barrier->num_wbarriers_inited++; + if (barrier->num_wbarriers_inited == barrier->num_wbarriers) + { + barrier->status = GNUNET_TESTBED_BARRIERSTATUS_INITIALISED; + send_barrier_status_msg(barrier, NULL); + } return; } - barrier->num_wbarriers_inited++; - if (barrier->num_wbarriers_inited == barrier->num_wbarriers) - { - barrier->status = GNUNET_TESTBED_BARRIERSTATUS_INITIALISED; - send_barrier_status_msg (barrier, NULL); - } - return; - } } @@ -603,15 +600,15 @@ wbarrier_status_cb (void *cls, * @param cls barrier */ static void -fwd_tout_barrier_init (void *cls) +fwd_tout_barrier_init(void *cls) { struct Barrier *barrier = cls; - cancel_wrappers (barrier); + cancel_wrappers(barrier); barrier->status = GNUNET_TESTBED_BARRIERSTATUS_ERROR; - send_barrier_status_msg (barrier, - "Timedout while propagating barrier initialisation\n"); - remove_barrier (barrier); + send_barrier_status_msg(barrier, + "Timedout while propagating barrier initialisation\n"); + remove_barrier(barrier); } @@ -624,8 +621,8 @@ fwd_tout_barrier_init (void *cls) * @return #GNUNET_OK if @a msg is well-formed */ int -check_barrier_init (void *cls, - const struct GNUNET_TESTBED_BarrierInit *msg) +check_barrier_init(void *cls, + const struct GNUNET_TESTBED_BarrierInit *msg) { return GNUNET_OK; /* always well-formed */ } @@ -643,8 +640,8 @@ check_barrier_init (void *cls, * @param msg the actual message */ void -handle_barrier_init (void *cls, - const struct GNUNET_TESTBED_BarrierInit *msg) +handle_barrier_init(void *cls, + const struct GNUNET_TESTBED_BarrierInit *msg) { struct GNUNET_SERVICE_Client *client = cls; char *name; @@ -657,81 +654,82 @@ handle_barrier_init (void *cls, uint16_t msize; if (NULL == GST_context) - { - GNUNET_break_op (0); - GNUNET_SERVICE_client_drop (client); - return; - } + { + GNUNET_break_op(0); + GNUNET_SERVICE_client_drop(client); + return; + } if (client != GST_context->client) - { - GNUNET_break_op (0); - GNUNET_SERVICE_client_drop (client); - return; - } - msize = ntohs (msg->header.size); - name_len = (size_t) msize - sizeof (struct GNUNET_TESTBED_BarrierInit); - name = GNUNET_malloc (name_len + 1); - GNUNET_memcpy (name, msg->name, name_len); - GNUNET_CRYPTO_hash (name, name_len, &hash); - LOG_DEBUG ("Received BARRIER_INIT for barrier `%s'\n", - name); + { + GNUNET_break_op(0); + GNUNET_SERVICE_client_drop(client); + return; + } + msize = ntohs(msg->header.size); + name_len = (size_t)msize - sizeof(struct GNUNET_TESTBED_BarrierInit); + name = GNUNET_malloc(name_len + 1); + GNUNET_memcpy(name, msg->name, name_len); + GNUNET_CRYPTO_hash(name, name_len, &hash); + LOG_DEBUG("Received BARRIER_INIT for barrier `%s'\n", + name); if (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_contains (barrier_map, - &hash)) - { - send_client_status_msg (client, - name, - GNUNET_TESTBED_BARRIERSTATUS_ERROR, - "A barrier with the same name already exists"); - GNUNET_free (name); - GNUNET_SERVICE_client_continue (client); - return; - } - barrier = GNUNET_new (struct Barrier); + GNUNET_CONTAINER_multihashmap_contains(barrier_map, + &hash)) + { + send_client_status_msg(client, + name, + GNUNET_TESTBED_BARRIERSTATUS_ERROR, + "A barrier with the same name already exists"); + GNUNET_free(name); + GNUNET_SERVICE_client_continue(client); + return; + } + barrier = GNUNET_new(struct Barrier); barrier->hash = hash; barrier->quorum = msg->quorum; barrier->name = name; barrier->mc = client; - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put (barrier_map, - &barrier->hash, - barrier, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); - GNUNET_SERVICE_client_continue (client); + GNUNET_assert(GNUNET_OK == + GNUNET_CONTAINER_multihashmap_put(barrier_map, + &barrier->hash, + barrier, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); + GNUNET_SERVICE_client_continue(client); /* Propagate barrier init to subcontrollers */ for (cnt = 0; cnt < GST_slave_list_size; cnt++) - { - if (NULL == (slave = GST_slave_list[cnt])) - continue; - if (NULL == slave->controller) { - GNUNET_break (0);/* May happen when we are connecting to the controller */ - continue; + if (NULL == (slave = GST_slave_list[cnt])) + continue; + if (NULL == slave->controller) + { + GNUNET_break(0);/* May happen when we are connecting to the controller */ + continue; + } + wrapper = GNUNET_new(struct WBarrier); + wrapper->barrier = barrier; + wrapper->controller = slave->controller; + GNUNET_CONTAINER_DLL_insert_tail(barrier->whead, + barrier->wtail, + wrapper); + barrier->num_wbarriers++; + wrapper->hbarrier = GNUNET_TESTBED_barrier_init_(wrapper->controller, + barrier->name, + barrier->quorum, + &wbarrier_status_cb, + wrapper, + GNUNET_NO); } - wrapper = GNUNET_new (struct WBarrier); - wrapper->barrier = barrier; - wrapper->controller = slave->controller; - GNUNET_CONTAINER_DLL_insert_tail (barrier->whead, - barrier->wtail, - wrapper); - barrier->num_wbarriers++; - wrapper->hbarrier = GNUNET_TESTBED_barrier_init_ (wrapper->controller, - barrier->name, - barrier->quorum, - &wbarrier_status_cb, - wrapper, - GNUNET_NO); - } if (NULL == barrier->whead) /* No further propagation */ - { - barrier->status = GNUNET_TESTBED_BARRIERSTATUS_INITIALISED; - LOG_DEBUG ("Sending GNUNET_TESTBED_BARRIERSTATUS_INITIALISED for barrier `%s'\n", - barrier->name); - send_barrier_status_msg (barrier, NULL); - }else - barrier->tout_task = GNUNET_SCHEDULER_add_delayed (MESSAGE_SEND_TIMEOUT (30), - &fwd_tout_barrier_init, - barrier); + { + barrier->status = GNUNET_TESTBED_BARRIERSTATUS_INITIALISED; + LOG_DEBUG("Sending GNUNET_TESTBED_BARRIERSTATUS_INITIALISED for barrier `%s'\n", + barrier->name); + send_barrier_status_msg(barrier, NULL); + } + else + barrier->tout_task = GNUNET_SCHEDULER_add_delayed(MESSAGE_SEND_TIMEOUT(30), + &fwd_tout_barrier_init, + barrier); } @@ -743,8 +741,8 @@ handle_barrier_init (void *cls, * @return #GNUNET_OK if @a msg is well-formed */ int -check_barrier_cancel (void *cls, - const struct GNUNET_TESTBED_BarrierCancel *msg) +check_barrier_cancel(void *cls, + const struct GNUNET_TESTBED_BarrierCancel *msg) { return GNUNET_OK; /* all are well-formed */ } @@ -762,8 +760,8 @@ check_barrier_cancel (void *cls, * @param msg the actual message */ void -handle_barrier_cancel (void *cls, - const struct GNUNET_TESTBED_BarrierCancel *msg) +handle_barrier_cancel(void *cls, + const struct GNUNET_TESTBED_BarrierCancel *msg) { struct GNUNET_SERVICE_Client *client = cls; char *name; @@ -773,42 +771,42 @@ handle_barrier_cancel (void *cls, uint16_t msize; if (NULL == GST_context) - { - GNUNET_break_op (0); - GNUNET_SERVICE_client_drop (client); - return; - } + { + GNUNET_break_op(0); + GNUNET_SERVICE_client_drop(client); + return; + } if (client != GST_context->client) - { - GNUNET_break_op (0); - GNUNET_SERVICE_client_drop (client); - return; - } - msize = ntohs (msg->header.size); - name_len = msize - sizeof (struct GNUNET_TESTBED_BarrierCancel); - name = GNUNET_malloc (name_len + 1); - GNUNET_memcpy (name, - msg->name, - name_len); - LOG_DEBUG ("Received BARRIER_CANCEL for barrier `%s'\n", - name); - GNUNET_CRYPTO_hash (name, - name_len, - &hash); + { + GNUNET_break_op(0); + GNUNET_SERVICE_client_drop(client); + return; + } + msize = ntohs(msg->header.size); + name_len = msize - sizeof(struct GNUNET_TESTBED_BarrierCancel); + name = GNUNET_malloc(name_len + 1); + GNUNET_memcpy(name, + msg->name, + name_len); + LOG_DEBUG("Received BARRIER_CANCEL for barrier `%s'\n", + name); + GNUNET_CRYPTO_hash(name, + name_len, + &hash); if (GNUNET_NO == - GNUNET_CONTAINER_multihashmap_contains (barrier_map, - &hash)) - { - GNUNET_break_op (0); - GNUNET_SERVICE_client_drop (client); - return; - } - barrier = GNUNET_CONTAINER_multihashmap_get (barrier_map, - &hash); - GNUNET_assert (NULL != barrier); - cancel_wrappers (barrier); - remove_barrier (barrier); - GNUNET_SERVICE_client_continue (client); + GNUNET_CONTAINER_multihashmap_contains(barrier_map, + &hash)) + { + GNUNET_break_op(0); + GNUNET_SERVICE_client_drop(client); + return; + } + barrier = GNUNET_CONTAINER_multihashmap_get(barrier_map, + &hash); + GNUNET_assert(NULL != barrier); + cancel_wrappers(barrier); + remove_barrier(barrier); + GNUNET_SERVICE_client_continue(client); } @@ -820,34 +818,34 @@ handle_barrier_cancel (void *cls, * @return #GNUNET_OK if @a msg is well-formed */ int -check_barrier_status (void *cls, - const struct GNUNET_TESTBED_BarrierStatusMsg *msg) +check_barrier_status(void *cls, + const struct GNUNET_TESTBED_BarrierStatusMsg *msg) { uint16_t msize; uint16_t name_len; const char *name; enum GNUNET_TESTBED_BarrierStatus status; - msize = ntohs (msg->header.size) - sizeof (*msg); - status = ntohs (msg->status); + msize = ntohs(msg->header.size) - sizeof(*msg); + status = ntohs(msg->status); if (GNUNET_TESTBED_BARRIERSTATUS_CROSSED != status) - { - GNUNET_break_op (0); /* current we only expect BARRIER_CROSSED + { + GNUNET_break_op(0); /* current we only expect BARRIER_CROSSED status message this way */ - return GNUNET_SYSERR; - } + return GNUNET_SYSERR; + } name = msg->data; - name_len = ntohs (msg->name_len); + name_len = ntohs(msg->name_len); if ((name_len + 1) != msize) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } if ('\0' != name[name_len]) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -861,8 +859,8 @@ check_barrier_status (void *cls, * @param msg the actual message */ void -handle_barrier_status (void *cls, - const struct GNUNET_TESTBED_BarrierStatusMsg *msg) +handle_barrier_status(void *cls, + const struct GNUNET_TESTBED_BarrierStatusMsg *msg) { struct GNUNET_SERVICE_Client *client = cls; struct Barrier *barrier; @@ -874,48 +872,48 @@ handle_barrier_status (void *cls, struct GNUNET_MQ_Envelope *env; if (NULL == GST_context) - { - GNUNET_break_op (0); - GNUNET_SERVICE_client_drop (client); - return; - } + { + GNUNET_break_op(0); + GNUNET_SERVICE_client_drop(client); + return; + } if (client != GST_context->client) - { - GNUNET_break_op (0); - GNUNET_SERVICE_client_drop (client); - return; - } + { + GNUNET_break_op(0); + GNUNET_SERVICE_client_drop(client); + return; + } name = msg->data; - name_len = ntohs (msg->name_len); - LOG_DEBUG ("Received BARRIER_STATUS for barrier `%s'\n", - name); - GNUNET_CRYPTO_hash (name, - name_len, - &key); - barrier = GNUNET_CONTAINER_multihashmap_get (barrier_map, - &key); + name_len = ntohs(msg->name_len); + LOG_DEBUG("Received BARRIER_STATUS for barrier `%s'\n", + name); + GNUNET_CRYPTO_hash(name, + name_len, + &key); + barrier = GNUNET_CONTAINER_multihashmap_get(barrier_map, + &key); if (NULL == barrier) - { - GNUNET_break_op (0); - GNUNET_SERVICE_client_drop (client); - return; - } - GNUNET_SERVICE_client_continue (client); - for(client_ctx = barrier->head; NULL != client_ctx; client_ctx = client_ctx->next) /* Notify peers */ - { - env = GNUNET_MQ_msg_copy (&msg->header); - GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client_ctx->client), - env); - } + { + GNUNET_break_op(0); + GNUNET_SERVICE_client_drop(client); + return; + } + GNUNET_SERVICE_client_continue(client); + for (client_ctx = barrier->head; NULL != client_ctx; client_ctx = client_ctx->next) /* Notify peers */ + { + env = GNUNET_MQ_msg_copy(&msg->header); + GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client_ctx->client), + env); + } /** * The wrapper barriers do not echo the barrier status, so we have to do it * here */ for (wrapper = barrier->whead; NULL != wrapper; wrapper = wrapper->next) - { - GNUNET_TESTBED_queue_message_ (wrapper->controller, - GNUNET_copy_message (&msg->header)); - } + { + GNUNET_TESTBED_queue_message_(wrapper->controller, + GNUNET_copy_message(&msg->header)); + } } /* end of gnunet-service-testbed_barriers.c */ diff --git a/src/testbed/gnunet-service-testbed_barriers.h b/src/testbed/gnunet-service-testbed_barriers.h index c5547867f..a16a4aa0d 100644 --- a/src/testbed/gnunet-service-testbed_barriers.h +++ b/src/testbed/gnunet-service-testbed_barriers.h @@ -1,22 +1,22 @@ /* - This file is part of GNUnet. - Copyright (C) 2008--2013 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 . + This file is part of GNUnet. + Copyright (C) 2008--2013 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/gnunet-service-testbed_barriers.h @@ -33,14 +33,14 @@ * @param cfg the configuration to use for initialisation */ void -GST_barriers_init (struct GNUNET_CONFIGURATION_Handle *cfg); +GST_barriers_init(struct GNUNET_CONFIGURATION_Handle *cfg); /** * Function to stop the barrier service */ void -GST_barriers_destroy (void); +GST_barriers_destroy(void); /** @@ -51,8 +51,8 @@ GST_barriers_destroy (void); * @return #GNUNET_OK if @a msg is well-formed */ int -check_barrier_init (void *cls, - const struct GNUNET_TESTBED_BarrierInit *msg); +check_barrier_init(void *cls, + const struct GNUNET_TESTBED_BarrierInit *msg); /** @@ -67,8 +67,8 @@ check_barrier_init (void *cls, * @param msg the actual message */ void -handle_barrier_init (void *cls, - const struct GNUNET_TESTBED_BarrierInit *msg); +handle_barrier_init(void *cls, + const struct GNUNET_TESTBED_BarrierInit *msg); /** @@ -79,8 +79,8 @@ handle_barrier_init (void *cls, * @return #GNUNET_OK if @a msg is well-formed */ int -check_barrier_cancel (void *cls, - const struct GNUNET_TESTBED_BarrierCancel *msg); +check_barrier_cancel(void *cls, + const struct GNUNET_TESTBED_BarrierCancel *msg); /** @@ -95,8 +95,8 @@ check_barrier_cancel (void *cls, * @param msg the actual message */ void -handle_barrier_cancel (void *cls, - const struct GNUNET_TESTBED_BarrierCancel *msg); +handle_barrier_cancel(void *cls, + const struct GNUNET_TESTBED_BarrierCancel *msg); /** @@ -107,8 +107,8 @@ handle_barrier_cancel (void *cls, * @return #GNUNET_OK if @a msg is well-formed */ int -check_barrier_status (void *cls, - const struct GNUNET_TESTBED_BarrierStatusMsg *msg); +check_barrier_status(void *cls, + const struct GNUNET_TESTBED_BarrierStatusMsg *msg); /** @@ -120,8 +120,8 @@ check_barrier_status (void *cls, * @param msg the actual message */ void -handle_barrier_status (void *cls, - const struct GNUNET_TESTBED_BarrierStatusMsg *msg); +handle_barrier_status(void *cls, + const struct GNUNET_TESTBED_BarrierStatusMsg *msg); #endif /* GNUNET_SERVER_TESTBED_BARRIERS_H_ */ diff --git a/src/testbed/gnunet-service-testbed_cache.c b/src/testbed/gnunet-service-testbed_cache.c index 80b0aed0c..901065da1 100644 --- a/src/testbed/gnunet-service-testbed_cache.c +++ b/src/testbed/gnunet-service-testbed_cache.c @@ -1,22 +1,22 @@ /* - This file is part of GNUnet. - Copyright (C) 2008--2013 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 . + This file is part of GNUnet. + Copyright (C) 2008--2013 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/gnunet-service-testbed_cache.c @@ -31,15 +31,14 @@ #ifdef LOG #undef LOG #endif -#define LOG(kind,...) \ - GNUNET_log_from (kind, "testbed-cache", __VA_ARGS__) +#define LOG(kind, ...) \ + GNUNET_log_from(kind, "testbed-cache", __VA_ARGS__) /** * Cache entry */ -struct CacheEntry -{ +struct CacheEntry { /** * DLL next ptr for least recently used cache entries */ @@ -97,16 +96,16 @@ static unsigned int cache_size; * @return the HELLO message; NULL if not found */ static struct CacheEntry * -cache_lookup (unsigned int peer_id) +cache_lookup(unsigned int peer_id) { struct CacheEntry *entry; - GNUNET_assert (NULL != cache); - entry = GNUNET_CONTAINER_multihashmap32_get (cache, peer_id); + GNUNET_assert(NULL != cache); + entry = GNUNET_CONTAINER_multihashmap32_get(cache, peer_id); if (NULL == entry) return NULL; - GNUNET_CONTAINER_DLL_remove (cache_head, cache_tail, entry); - GNUNET_CONTAINER_DLL_insert_tail (cache_head, cache_tail, entry); + GNUNET_CONTAINER_DLL_remove(cache_head, cache_tail, entry); + GNUNET_CONTAINER_DLL_insert_tail(cache_head, cache_tail, entry); return entry; } @@ -117,11 +116,11 @@ cache_lookup (unsigned int peer_id) * @param entry the cache entry to free */ static void -free_entry (struct CacheEntry *entry) +free_entry(struct CacheEntry *entry) { - GNUNET_CONTAINER_DLL_remove (cache_head, cache_tail, entry); - GNUNET_free_non_null (entry->hello); - GNUNET_free (entry); + GNUNET_CONTAINER_DLL_remove(cache_head, cache_tail, entry); + GNUNET_free_non_null(entry->hello); + GNUNET_free(entry); } @@ -132,29 +131,29 @@ free_entry (struct CacheEntry *entry) * @return the newly created entry */ static struct CacheEntry * -add_entry (unsigned int peer_id) +add_entry(unsigned int peer_id) { struct CacheEntry *entry; - GNUNET_assert (NULL != cache); - if (cache_size == GNUNET_CONTAINER_multihashmap32_size (cache)) - { - /* remove the LRU head */ - entry = cache_head; - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multihashmap32_remove (cache, (uint32_t) + GNUNET_assert(NULL != cache); + if (cache_size == GNUNET_CONTAINER_multihashmap32_size(cache)) + { + /* remove the LRU head */ + entry = cache_head; + GNUNET_assert(GNUNET_OK == + GNUNET_CONTAINER_multihashmap32_remove(cache, (uint32_t) entry->peer_id, entry)); - free_entry (entry); - } - entry = GNUNET_new (struct CacheEntry); + free_entry(entry); + } + entry = GNUNET_new(struct CacheEntry); entry->peer_id = peer_id; - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multihashmap32_put (cache, - (uint32_t) peer_id, - entry, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); - GNUNET_CONTAINER_DLL_insert_tail (cache_head, cache_tail, entry); + GNUNET_assert(GNUNET_OK == + GNUNET_CONTAINER_multihashmap32_put(cache, + (uint32_t)peer_id, + entry, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); + GNUNET_CONTAINER_DLL_insert_tail(cache_head, cache_tail, entry); return entry; } @@ -170,14 +169,14 @@ add_entry (unsigned int peer_id) * GNUNET_NO if not. */ static int -cache_clear_iterator (void *cls, uint32_t key, void *value) +cache_clear_iterator(void *cls, uint32_t key, void *value) { struct CacheEntry *entry = value; - GNUNET_assert (NULL != entry); - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap32_remove (cache, key, value)); - free_entry (entry); + GNUNET_assert(NULL != entry); + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multihashmap32_remove(cache, key, value)); + free_entry(entry); return GNUNET_YES; } @@ -186,15 +185,15 @@ cache_clear_iterator (void *cls, uint32_t key, void *value) * Clear cache */ void -GST_cache_clear () +GST_cache_clear() { if (NULL != cache) - { - GNUNET_CONTAINER_multihashmap32_iterate (cache, &cache_clear_iterator, NULL); - GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap32_size (cache)); - GNUNET_CONTAINER_multihashmap32_destroy (cache); - cache = NULL; - } + { + GNUNET_CONTAINER_multihashmap32_iterate(cache, &cache_clear_iterator, NULL); + GNUNET_assert(0 == GNUNET_CONTAINER_multihashmap32_size(cache)); + GNUNET_CONTAINER_multihashmap32_destroy(cache); + cache = NULL; + } cache_size = 0; cache_head = NULL; cache_tail = NULL; @@ -207,12 +206,12 @@ GST_cache_clear () * @param size the size of the cache */ void -GST_cache_init (unsigned int size) +GST_cache_init(unsigned int size) { if (0 == size) return; cache_size = size; - cache = GNUNET_CONTAINER_multihashmap32_create (cache_size); + cache = GNUNET_CONTAINER_multihashmap32_create(cache_size); } @@ -223,21 +222,21 @@ GST_cache_init (unsigned int size) * @return the HELLO message; NULL if not found */ const struct GNUNET_MessageHeader * -GST_cache_lookup_hello (const unsigned int peer_id) +GST_cache_lookup_hello(const unsigned int peer_id) { struct CacheEntry *entry; - LOG_DEBUG ("Looking up HELLO for peer %u\n", peer_id); + LOG_DEBUG("Looking up HELLO for peer %u\n", peer_id); if (NULL == cache) - { - LOG_DEBUG ("Caching disabled\n"); - return NULL; - } - entry = cache_lookup (peer_id); + { + LOG_DEBUG("Caching disabled\n"); + return NULL; + } + entry = cache_lookup(peer_id); if (NULL == entry) return NULL; if (NULL != entry->hello) - LOG_DEBUG ("HELLO found for peer %u\n", peer_id); + LOG_DEBUG("HELLO found for peer %u\n", peer_id); return entry->hello; } @@ -250,18 +249,18 @@ GST_cache_lookup_hello (const unsigned int peer_id) * @param hello the HELLO message */ void -GST_cache_add_hello (const unsigned int peer_id, - const struct GNUNET_MessageHeader *hello) +GST_cache_add_hello(const unsigned int peer_id, + const struct GNUNET_MessageHeader *hello) { struct CacheEntry *entry; if (NULL == cache) return; - entry = cache_lookup (peer_id); + entry = cache_lookup(peer_id); if (NULL == entry) - entry = add_entry (peer_id); - GNUNET_free_non_null (entry->hello); - entry->hello = GNUNET_copy_message (hello); + entry = add_entry(peer_id); + GNUNET_free_non_null(entry->hello); + entry->hello = GNUNET_copy_message(hello); } /* end of gnunet-service-testbed_hc.c */ diff --git a/src/testbed/gnunet-service-testbed_connectionpool.c b/src/testbed/gnunet-service-testbed_connectionpool.c index e173a2349..fdb10f987 100644 --- a/src/testbed/gnunet-service-testbed_connectionpool.c +++ b/src/testbed/gnunet-service-testbed_connectionpool.c @@ -1,22 +1,22 @@ /* - This file is part of GNUnet. - Copyright (C) 2008--2015 GNUnet e.V. + This file is part of GNUnet. + Copyright (C) 2008--2015 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 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. + 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 . + 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/gnunet-service-testbed_connectionpool.c @@ -36,14 +36,14 @@ #undef LOG #endif #define LOG(kind, ...) \ - GNUNET_log_from (kind, "testbed-connectionpool", __VA_ARGS__) + GNUNET_log_from(kind, "testbed-connectionpool", __VA_ARGS__) /** * Time to expire a cache entry */ #define CACHE_EXPIRY \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) /** @@ -55,8 +55,7 @@ struct GST_ConnectionPool_GetHandle; /** * A pooled connection */ -struct PooledConnection -{ +struct PooledConnection { /** * Next ptr for placing this object in the DLL of least recently used pooled * connections @@ -169,8 +168,7 @@ struct PooledConnection /** * The request handle for obtaining a pooled connection */ -struct GST_ConnectionPool_GetHandle -{ +struct GST_ConnectionPool_GetHandle { /** * The next ptr for inclusion in the notification DLLs. At first the object * is placed in the waiting DLL of the corresponding #PooledConnection @@ -274,7 +272,7 @@ static unsigned int max_size; * @param entry the #PooledConnection object */ static void -expire_task_cancel (struct PooledConnection *entry); +expire_task_cancel(struct PooledConnection *entry); /** @@ -283,49 +281,49 @@ expire_task_cancel (struct PooledConnection *entry); * @param entry the #PooledConnection object */ static void -destroy_pooled_connection (struct PooledConnection *entry) +destroy_pooled_connection(struct PooledConnection *entry) { - GNUNET_assert ((NULL == entry->head_notify) && (NULL == entry->tail_notify)); - GNUNET_assert ((NULL == entry->head_waiting) && - (NULL == entry->tail_waiting)); - GNUNET_assert (0 == entry->demand); - expire_task_cancel (entry); + GNUNET_assert((NULL == entry->head_notify) && (NULL == entry->tail_notify)); + GNUNET_assert((NULL == entry->head_waiting) && + (NULL == entry->tail_waiting)); + GNUNET_assert(0 == entry->demand); + expire_task_cancel(entry); if (entry->in_lru) - GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry); + GNUNET_CONTAINER_DLL_remove(head_lru, tail_lru, entry); if (entry->in_pool) - GNUNET_assert ( + GNUNET_assert( GNUNET_OK == - GNUNET_CONTAINER_multihashmap32_remove (map, entry->index, entry)); + GNUNET_CONTAINER_multihashmap32_remove(map, entry->index, entry)); if (NULL != entry->notify_task) - { - GNUNET_SCHEDULER_cancel (entry->notify_task); - entry->notify_task = NULL; - } - LOG_DEBUG ("Cleaning up handles of a pooled connection\n"); + { + GNUNET_SCHEDULER_cancel(entry->notify_task); + entry->notify_task = NULL; + } + LOG_DEBUG("Cleaning up handles of a pooled connection\n"); if (NULL != entry->handle_transport) - GNUNET_assert (NULL != entry->op_transport); + GNUNET_assert(NULL != entry->op_transport); if (NULL != entry->op_transport) - { - GNUNET_TESTBED_operation_done (entry->op_transport); - entry->op_transport = NULL; - } + { + GNUNET_TESTBED_operation_done(entry->op_transport); + entry->op_transport = NULL; + } if (NULL != entry->handle_ats_connectivity) - GNUNET_assert (NULL != entry->op_ats_connectivity); + GNUNET_assert(NULL != entry->op_ats_connectivity); if (NULL != entry->op_ats_connectivity) - { - GNUNET_TESTBED_operation_done (entry->op_ats_connectivity); - entry->op_ats_connectivity = NULL; - } + { + GNUNET_TESTBED_operation_done(entry->op_ats_connectivity); + entry->op_ats_connectivity = NULL; + } if (NULL != entry->op_core) - { - GNUNET_TESTBED_operation_done (entry->op_core); - entry->op_core = NULL; - } - GNUNET_assert (NULL == entry->handle_core); - GNUNET_assert (NULL == entry->handle_ats_connectivity); - GNUNET_assert (NULL == entry->handle_transport); - GNUNET_CONFIGURATION_destroy (entry->cfg); - GNUNET_free (entry); + { + GNUNET_TESTBED_operation_done(entry->op_core); + entry->op_core = NULL; + } + GNUNET_assert(NULL == entry->handle_core); + GNUNET_assert(NULL == entry->handle_ats_connectivity); + GNUNET_assert(NULL == entry->handle_transport); + GNUNET_CONFIGURATION_destroy(entry->cfg); + GNUNET_free(entry); } @@ -335,12 +333,12 @@ destroy_pooled_connection (struct PooledConnection *entry) * @param cls the #PooledConnection object */ static void -expire (void *cls) +expire(void *cls) { struct PooledConnection *entry = cls; entry->expire_task = NULL; - destroy_pooled_connection (entry); + destroy_pooled_connection(entry); } @@ -350,13 +348,13 @@ expire (void *cls) * @param entry the #PooledConnection object */ static void -expire_task_cancel (struct PooledConnection *entry) +expire_task_cancel(struct PooledConnection *entry) { if (NULL != entry->expire_task) - { - GNUNET_SCHEDULER_cancel (entry->expire_task); - entry->expire_task = NULL; - } + { + GNUNET_SCHEDULER_cancel(entry->expire_task); + entry->expire_task = NULL; + } } @@ -366,15 +364,15 @@ expire_task_cancel (struct PooledConnection *entry) * @param entry the #PooledConnection object */ static void -add_to_lru (struct PooledConnection *entry) +add_to_lru(struct PooledConnection *entry) { - GNUNET_assert (0 == entry->demand); - GNUNET_assert (! entry->in_lru); - GNUNET_CONTAINER_DLL_insert_tail (head_lru, tail_lru, entry); + GNUNET_assert(0 == entry->demand); + GNUNET_assert(!entry->in_lru); + GNUNET_CONTAINER_DLL_insert_tail(head_lru, tail_lru, entry); entry->in_lru = GNUNET_YES; - GNUNET_assert (NULL == entry->expire_task); + GNUNET_assert(NULL == entry->expire_task); entry->expire_task = - GNUNET_SCHEDULER_add_delayed (CACHE_EXPIRY, &expire, entry); + GNUNET_SCHEDULER_add_delayed(CACHE_EXPIRY, &expire, entry); } @@ -390,32 +388,34 @@ add_to_lru (struct PooledConnection *entry) * is found */ static struct GST_ConnectionPool_GetHandle * -search_waiting (const struct PooledConnection *entry, - struct GST_ConnectionPool_GetHandle *head) +search_waiting(const struct PooledConnection *entry, + struct GST_ConnectionPool_GetHandle *head) { struct GST_ConnectionPool_GetHandle *gh; for (gh = head; NULL != gh; gh = gh->next) - { - switch (gh->service) { - case GST_CONNECTIONPOOL_SERVICE_CORE: - if (NULL == entry->handle_core) - continue; - if (NULL == entry->peer_identity) - continue; /* CORE connection isn't ready yet */ - break; - case GST_CONNECTIONPOOL_SERVICE_TRANSPORT: - if (NULL == entry->handle_transport) - continue; - break; - case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY: - if (NULL == entry->handle_ats_connectivity) - continue; + switch (gh->service) + { + case GST_CONNECTIONPOOL_SERVICE_CORE: + if (NULL == entry->handle_core) + continue; + if (NULL == entry->peer_identity) + continue; /* CORE connection isn't ready yet */ + break; + + case GST_CONNECTIONPOOL_SERVICE_TRANSPORT: + if (NULL == entry->handle_transport) + continue; + break; + + case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY: + if (NULL == entry->handle_ats_connectivity) + continue; + break; + } break; } - break; - } return gh; } @@ -430,37 +430,37 @@ search_waiting (const struct PooledConnection *entry, * @param cls the #PooledConnection object */ static void -connection_ready (void *cls) +connection_ready(void *cls) { struct PooledConnection *entry = cls; struct GST_ConnectionPool_GetHandle *gh; struct GST_ConnectionPool_GetHandle *gh_next; - GNUNET_assert (NULL != entry->notify_task); + GNUNET_assert(NULL != entry->notify_task); entry->notify_task = NULL; - gh = search_waiting (entry, entry->head_waiting); - GNUNET_assert (NULL != gh); + gh = search_waiting(entry, entry->head_waiting); + GNUNET_assert(NULL != gh); gh_next = NULL; if (NULL != gh->next) - gh_next = search_waiting (entry, gh->next); - GNUNET_CONTAINER_DLL_remove (entry->head_waiting, entry->tail_waiting, gh); + gh_next = search_waiting(entry, gh->next); + GNUNET_CONTAINER_DLL_remove(entry->head_waiting, entry->tail_waiting, gh); gh->connection_ready_called = 1; if (NULL != gh_next) - entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready, entry); + entry->notify_task = GNUNET_SCHEDULER_add_now(&connection_ready, entry); if ((NULL != gh->target) && (NULL != gh->connect_notify_cb)) - { - GNUNET_CONTAINER_DLL_insert_tail (entry->head_notify, - entry->tail_notify, - gh); - gh->notify_waiting = 1; - } - LOG_DEBUG ("Connection ready for handle type %u\n", gh->service); - gh->cb (gh->cb_cls, - entry->handle_core, - entry->handle_transport, - entry->handle_ats_connectivity, - entry->peer_identity, - entry->cfg); + { + GNUNET_CONTAINER_DLL_insert_tail(entry->head_notify, + entry->tail_notify, + gh); + gh->notify_waiting = 1; + } + LOG_DEBUG("Connection ready for handle type %u\n", gh->service); + gh->cb(gh->cb_cls, + entry->handle_core, + entry->handle_transport, + entry->handle_ats_connectivity, + entry->peer_identity, + entry->cfg); } @@ -474,9 +474,9 @@ connection_ready (void *cls) * @param service the service where this notification has originated */ static void -peer_connect_notify_cb (void *cls, - const struct GNUNET_PeerIdentity *peer, - const enum GST_ConnectionPool_Service service) +peer_connect_notify_cb(void *cls, + const struct GNUNET_PeerIdentity *peer, + const enum GST_ConnectionPool_Service service) { struct PooledConnection *entry = cls; struct GST_ConnectionPool_GetHandle *gh; @@ -485,31 +485,31 @@ peer_connect_notify_cb (void *cls, void *cb_cls; for (gh = entry->head_notify; NULL != gh;) - { - GNUNET_assert (NULL != gh->target); - GNUNET_assert (NULL != gh->connect_notify_cb); - GNUNET_assert (gh->connection_ready_called); - if (service != gh->service) { - gh = gh->next; - continue; + GNUNET_assert(NULL != gh->target); + GNUNET_assert(NULL != gh->connect_notify_cb); + GNUNET_assert(gh->connection_ready_called); + if (service != gh->service) + { + gh = gh->next; + continue; + } + if (0 != memcmp(gh->target, peer, sizeof(struct GNUNET_PeerIdentity))) + { + gh = gh->next; + continue; + } + cb = gh->connect_notify_cb; + cb_cls = gh->connect_notify_cb_cls; + gh_next = gh->next; + GNUNET_CONTAINER_DLL_remove(entry->head_notify, entry->tail_notify, gh); + gh->notify_waiting = 0; + LOG_DEBUG("Peer connected to peer %u at service %u\n", + entry->index, + gh->service); + gh = gh_next; + cb(cb_cls, peer); } - if (0 != memcmp (gh->target, peer, sizeof (struct GNUNET_PeerIdentity))) - { - gh = gh->next; - continue; - } - cb = gh->connect_notify_cb; - cb_cls = gh->connect_notify_cb_cls; - gh_next = gh->next; - GNUNET_CONTAINER_DLL_remove (entry->head_notify, entry->tail_notify, gh); - gh->notify_waiting = 0; - LOG_DEBUG ("Peer connected to peer %u at service %u\n", - entry->index, - gh->service); - gh = gh_next; - cb (cb_cls, peer); - } } @@ -523,13 +523,13 @@ peer_connect_notify_cb (void *cls, * @return NULL */ static void * -transport_peer_connect_notify_cb (void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_MQ_Handle *mq) +transport_peer_connect_notify_cb(void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_MQ_Handle *mq) { struct PooledConnection *entry = cls; - peer_connect_notify_cb (entry, peer, GST_CONNECTIONPOOL_SERVICE_TRANSPORT); + peer_connect_notify_cb(entry, peer, GST_CONNECTIONPOOL_SERVICE_TRANSPORT); return NULL; } @@ -541,34 +541,34 @@ transport_peer_connect_notify_cb (void *cls, * @param cls the #PooledConnection object */ static void -opstart_get_handle_transport (void *cls) +opstart_get_handle_transport(void *cls) { struct PooledConnection *entry = cls; - GNUNET_assert (NULL != entry); - LOG_DEBUG ("Opening a transport connection to peer %u\n", entry->index); + GNUNET_assert(NULL != entry); + LOG_DEBUG("Opening a transport connection to peer %u\n", entry->index); entry->handle_transport = - GNUNET_TRANSPORT_core_connect (entry->cfg, - NULL, - NULL, - entry, - &transport_peer_connect_notify_cb, - NULL, - NULL); + GNUNET_TRANSPORT_core_connect(entry->cfg, + NULL, + NULL, + entry, + &transport_peer_connect_notify_cb, + NULL, + NULL); if (NULL == entry->handle_transport) - { - GNUNET_break (0); - return; - } + { + GNUNET_break(0); + return; + } if (0 == entry->demand) return; if (NULL != entry->notify_task) return; - if (NULL != search_waiting (entry, entry->head_waiting)) - { - entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready, entry); - return; - } + if (NULL != search_waiting(entry, entry->head_waiting)) + { + entry->notify_task = GNUNET_SCHEDULER_add_now(&connection_ready, entry); + return; + } } @@ -579,13 +579,13 @@ opstart_get_handle_transport (void *cls) * @param cls the cache entry */ static void -oprelease_get_handle_transport (void *cls) +oprelease_get_handle_transport(void *cls) { struct PooledConnection *entry = cls; if (NULL == entry->handle_transport) return; - GNUNET_TRANSPORT_core_disconnect (entry->handle_transport); + GNUNET_TRANSPORT_core_disconnect(entry->handle_transport); entry->handle_transport = NULL; } @@ -599,14 +599,14 @@ oprelease_get_handle_transport (void *cls) * @return peer */ static void * -core_peer_connect_cb (void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_MQ_Handle *mq) +core_peer_connect_cb(void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_MQ_Handle *mq) { struct PooledConnection *entry = cls; - peer_connect_notify_cb (entry, peer, GST_CONNECTIONPOOL_SERVICE_CORE); - return (void *) peer; + peer_connect_notify_cb(entry, peer, GST_CONNECTIONPOOL_SERVICE_CORE); + return (void *)peer; } @@ -623,27 +623,27 @@ core_peer_connect_cb (void *cls, * @param my_identity ID of this peer, NULL if we failed */ static void -core_startup_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity) +core_startup_cb(void *cls, const struct GNUNET_PeerIdentity *my_identity) { struct PooledConnection *entry = cls; if (NULL == my_identity) - { - GNUNET_break (0); - return; - } - GNUNET_assert (NULL == entry->peer_identity); - entry->peer_identity = GNUNET_new (struct GNUNET_PeerIdentity); + { + GNUNET_break(0); + return; + } + GNUNET_assert(NULL == entry->peer_identity); + entry->peer_identity = GNUNET_new(struct GNUNET_PeerIdentity); *entry->peer_identity = *my_identity; if (0 == entry->demand) return; if (NULL != entry->notify_task) return; - if (NULL != search_waiting (entry, entry->head_waiting)) - { - entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready, entry); - return; - } + if (NULL != search_waiting(entry, entry->head_waiting)) + { + entry->notify_task = GNUNET_SCHEDULER_add_now(&connection_ready, entry); + return; + } } @@ -654,19 +654,19 @@ core_startup_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity) * @param cls the #PooledConnection object */ static void -opstart_get_handle_core (void *cls) +opstart_get_handle_core(void *cls) { struct PooledConnection *entry = cls; - GNUNET_assert (NULL != entry); - LOG_DEBUG ("Opening a CORE connection to peer %u\n", entry->index); + GNUNET_assert(NULL != entry); + LOG_DEBUG("Opening a CORE connection to peer %u\n", entry->index); entry->handle_core = - GNUNET_CORE_connect (entry->cfg, - entry, /* closure */ - &core_startup_cb, /* core startup notify */ - &core_peer_connect_cb, /* peer connect notify */ - NULL, /* peer disconnect notify */ - NULL); + GNUNET_CORE_connect(entry->cfg, + entry, /* closure */ + &core_startup_cb, /* core startup notify */ + &core_peer_connect_cb, /* peer connect notify */ + NULL, /* peer disconnect notify */ + NULL); } @@ -677,15 +677,15 @@ opstart_get_handle_core (void *cls) * @param cls the #PooledConnection object */ static void -oprelease_get_handle_core (void *cls) +oprelease_get_handle_core(void *cls) { struct PooledConnection *entry = cls; if (NULL == entry->handle_core) return; - GNUNET_CORE_disconnect (entry->handle_core); + GNUNET_CORE_disconnect(entry->handle_core); entry->handle_core = NULL; - GNUNET_free_non_null (entry->peer_identity); + GNUNET_free_non_null(entry->peer_identity); entry->peer_identity = NULL; } @@ -697,11 +697,11 @@ oprelease_get_handle_core (void *cls) * @param cls the #PooledConnection object */ static void -opstart_get_handle_ats_connectivity (void *cls) +opstart_get_handle_ats_connectivity(void *cls) { struct PooledConnection *entry = cls; - entry->handle_ats_connectivity = GNUNET_ATS_connectivity_init (entry->cfg); + entry->handle_ats_connectivity = GNUNET_ATS_connectivity_init(entry->cfg); } @@ -712,13 +712,13 @@ opstart_get_handle_ats_connectivity (void *cls) * @param cls the #PooledConnection object */ static void -oprelease_get_handle_ats_connectivity (void *cls) +oprelease_get_handle_ats_connectivity(void *cls) { struct PooledConnection *entry = cls; if (NULL == entry->handle_ats_connectivity) return; - GNUNET_ATS_connectivity_done (entry->handle_ats_connectivity); + GNUNET_ATS_connectivity_done(entry->handle_ats_connectivity); entry->handle_ats_connectivity = NULL; } @@ -734,12 +734,12 @@ oprelease_get_handle_ats_connectivity (void *cls) * #GNUNET_NO if not. */ static int -cleanup_iterator (void *cls, uint32_t key, void *value) +cleanup_iterator(void *cls, uint32_t key, void *value) { struct PooledConnection *entry = value; - GNUNET_assert (NULL != entry); - destroy_pooled_connection (entry); + GNUNET_assert(NULL != entry); + destroy_pooled_connection(entry); return GNUNET_YES; } @@ -752,13 +752,13 @@ cleanup_iterator (void *cls, uint32_t key, void *value) * #GST_ConnectionPool_Service */ void -GST_connection_pool_init (unsigned int size) +GST_connection_pool_init(unsigned int size) { max_size = size; if (0 == max_size) return; - GNUNET_assert (NULL == map); - map = GNUNET_CONTAINER_multihashmap32_create (((size * 3) / 4) + 1); + GNUNET_assert(NULL == map); + map = GNUNET_CONTAINER_multihashmap32_create(((size * 3) / 4) + 1); } @@ -766,24 +766,24 @@ GST_connection_pool_init (unsigned int size) * Cleanup the connection pool */ void -GST_connection_pool_destroy () +GST_connection_pool_destroy() { struct PooledConnection *entry; if (NULL != map) - { - GNUNET_assert ( - GNUNET_SYSERR != - GNUNET_CONTAINER_multihashmap32_iterate (map, &cleanup_iterator, NULL)); - GNUNET_CONTAINER_multihashmap32_destroy (map); - map = NULL; - } + { + GNUNET_assert( + GNUNET_SYSERR != + GNUNET_CONTAINER_multihashmap32_iterate(map, &cleanup_iterator, NULL)); + GNUNET_CONTAINER_multihashmap32_destroy(map); + map = NULL; + } while (NULL != (entry = head_lru)) - { - GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry); - destroy_pooled_connection (entry); - } - GNUNET_assert (NULL == head_not_pooled); + { + GNUNET_CONTAINER_DLL_remove(head_lru, tail_lru, entry); + destroy_pooled_connection(entry); + } + GNUNET_assert(NULL == head_not_pooled); } @@ -820,7 +820,7 @@ GST_connection_pool_destroy () * longer being used */ struct GST_ConnectionPool_GetHandle * -GST_connection_pool_get_handle ( +GST_connection_pool_get_handle( unsigned int peer_id, const struct GNUNET_CONFIGURATION_Handle *cfg, enum GST_ConnectionPool_Service service, @@ -836,64 +836,66 @@ GST_connection_pool_get_handle ( void *handle; uint32_t peer_id32; - peer_id32 = (uint32_t) peer_id; + peer_id32 = (uint32_t)peer_id; handle = NULL; entry = NULL; if (NULL != map) - entry = GNUNET_CONTAINER_multihashmap32_get (map, peer_id32); + entry = GNUNET_CONTAINER_multihashmap32_get(map, peer_id32); if (NULL != entry) - { - if (entry->in_lru) { - GNUNET_assert (0 == entry->demand); - expire_task_cancel (entry); - GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry); - entry->in_lru = GNUNET_NO; + if (entry->in_lru) + { + GNUNET_assert(0 == entry->demand); + expire_task_cancel(entry); + GNUNET_CONTAINER_DLL_remove(head_lru, tail_lru, entry); + entry->in_lru = GNUNET_NO; + } + switch (service) + { + case GST_CONNECTIONPOOL_SERVICE_TRANSPORT: + handle = entry->handle_transport; + if (NULL != handle) + LOG_DEBUG("Found TRANSPORT handle for peer %u\n", entry->index); + break; + + case GST_CONNECTIONPOOL_SERVICE_CORE: + handle = entry->handle_core; + if (NULL != handle) + LOG_DEBUG("Found CORE handle for peer %u\n", entry->index); + break; + + case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY: + handle = entry->handle_ats_connectivity; + if (NULL != handle) + LOG_DEBUG("Found ATS CONNECTIVITY handle for peer %u\n", entry->index); + break; + } } - switch (service) - { - case GST_CONNECTIONPOOL_SERVICE_TRANSPORT: - handle = entry->handle_transport; - if (NULL != handle) - LOG_DEBUG ("Found TRANSPORT handle for peer %u\n", entry->index); - break; - case GST_CONNECTIONPOOL_SERVICE_CORE: - handle = entry->handle_core; - if (NULL != handle) - LOG_DEBUG ("Found CORE handle for peer %u\n", entry->index); - break; - case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY: - handle = entry->handle_ats_connectivity; - if (NULL != handle) - LOG_DEBUG ("Found ATS CONNECTIVITY handle for peer %u\n", entry->index); - break; - } - } else - { - entry = GNUNET_new (struct PooledConnection); - entry->index = peer_id32; - if ((NULL != map) && - (GNUNET_CONTAINER_multihashmap32_size (map) < max_size)) { - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multihashmap32_put ( - map, - entry->index, - entry, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); - entry->in_pool = GNUNET_YES; - } - else - { - GNUNET_CONTAINER_DLL_insert_tail (head_not_pooled, - tail_not_pooled, - entry); + entry = GNUNET_new(struct PooledConnection); + entry->index = peer_id32; + if ((NULL != map) && + (GNUNET_CONTAINER_multihashmap32_size(map) < max_size)) + { + GNUNET_assert(GNUNET_OK == + GNUNET_CONTAINER_multihashmap32_put( + map, + entry->index, + entry, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); + entry->in_pool = GNUNET_YES; + } + else + { + GNUNET_CONTAINER_DLL_insert_tail(head_not_pooled, + tail_not_pooled, + entry); + } + entry->cfg = GNUNET_CONFIGURATION_dup(cfg); } - entry->cfg = GNUNET_CONFIGURATION_dup (cfg); - } entry->demand++; - gh = GNUNET_new (struct GST_ConnectionPool_GetHandle); + gh = GNUNET_new(struct GST_ConnectionPool_GetHandle); gh->entry = entry; gh->cb = cb; gh->cb_cls = cb_cls; @@ -901,48 +903,50 @@ GST_connection_pool_get_handle ( gh->connect_notify_cb = connect_notify_cb; gh->connect_notify_cb_cls = connect_notify_cb_cls; gh->service = service; - GNUNET_CONTAINER_DLL_insert (entry->head_waiting, entry->tail_waiting, gh); + GNUNET_CONTAINER_DLL_insert(entry->head_waiting, entry->tail_waiting, gh); if (NULL != handle) - { - if (NULL == entry->notify_task) { - if (NULL != search_waiting (entry, entry->head_waiting)) - entry->notify_task = - GNUNET_SCHEDULER_add_now (&connection_ready, entry); + if (NULL == entry->notify_task) + { + if (NULL != search_waiting(entry, entry->head_waiting)) + entry->notify_task = + GNUNET_SCHEDULER_add_now(&connection_ready, entry); + } + return gh; } - return gh; - } op = NULL; switch (gh->service) - { - case GST_CONNECTIONPOOL_SERVICE_TRANSPORT: - if (NULL != entry->op_transport) - return gh; /* Operation pending */ - op = GNUNET_TESTBED_operation_create_ (entry, - &opstart_get_handle_transport, - &oprelease_get_handle_transport); - entry->op_transport = op; - break; - case GST_CONNECTIONPOOL_SERVICE_CORE: - if (NULL != entry->op_core) - return gh; /* Operation pending */ - op = GNUNET_TESTBED_operation_create_ (entry, - &opstart_get_handle_core, - &oprelease_get_handle_core); - entry->op_core = op; - break; - case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY: - if (NULL != entry->op_ats_connectivity) - return gh; /* Operation pending */ - op = - GNUNET_TESTBED_operation_create_ (entry, - &opstart_get_handle_ats_connectivity, - &oprelease_get_handle_ats_connectivity); - entry->op_ats_connectivity = op; - break; - } - GNUNET_TESTBED_operation_queue_insert_ (GST_opq_openfds, op); - GNUNET_TESTBED_operation_begin_wait_ (op); + { + case GST_CONNECTIONPOOL_SERVICE_TRANSPORT: + if (NULL != entry->op_transport) + return gh; /* Operation pending */ + op = GNUNET_TESTBED_operation_create_(entry, + &opstart_get_handle_transport, + &oprelease_get_handle_transport); + entry->op_transport = op; + break; + + case GST_CONNECTIONPOOL_SERVICE_CORE: + if (NULL != entry->op_core) + return gh; /* Operation pending */ + op = GNUNET_TESTBED_operation_create_(entry, + &opstart_get_handle_core, + &oprelease_get_handle_core); + entry->op_core = op; + break; + + case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY: + if (NULL != entry->op_ats_connectivity) + return gh; /* Operation pending */ + op = + GNUNET_TESTBED_operation_create_(entry, + &opstart_get_handle_ats_connectivity, + &oprelease_get_handle_ats_connectivity); + entry->op_ats_connectivity = op; + break; + } + GNUNET_TESTBED_operation_queue_insert_(GST_opq_openfds, op); + GNUNET_TESTBED_operation_begin_wait_(op); return gh; } @@ -960,66 +964,66 @@ GST_connection_pool_get_handle ( * @param gh the handle */ void -GST_connection_pool_get_handle_done (struct GST_ConnectionPool_GetHandle *gh) +GST_connection_pool_get_handle_done(struct GST_ConnectionPool_GetHandle *gh) { struct PooledConnection *entry; if (NULL == gh) return; entry = gh->entry; - LOG_DEBUG ("Cleaning up get handle %p for service %u, peer %u\n", - gh, - gh->service, - entry->index); - if (! gh->connection_ready_called) - { - GNUNET_CONTAINER_DLL_remove (entry->head_waiting, entry->tail_waiting, gh); - if ((NULL == search_waiting (entry, entry->head_waiting)) && - (NULL != entry->notify_task)) + LOG_DEBUG("Cleaning up get handle %p for service %u, peer %u\n", + gh, + gh->service, + entry->index); + if (!gh->connection_ready_called) { - GNUNET_SCHEDULER_cancel (entry->notify_task); - entry->notify_task = NULL; + GNUNET_CONTAINER_DLL_remove(entry->head_waiting, entry->tail_waiting, gh); + if ((NULL == search_waiting(entry, entry->head_waiting)) && + (NULL != entry->notify_task)) + { + GNUNET_SCHEDULER_cancel(entry->notify_task); + entry->notify_task = NULL; + } } - } if (gh->notify_waiting) - { - GNUNET_CONTAINER_DLL_remove (entry->head_notify, entry->tail_notify, gh); - gh->notify_waiting = 0; - } - GNUNET_free (gh); + { + GNUNET_CONTAINER_DLL_remove(entry->head_notify, entry->tail_notify, gh); + gh->notify_waiting = 0; + } + GNUNET_free(gh); gh = NULL; - GNUNET_assert (! entry->in_lru); - if (! entry->in_pool) - GNUNET_CONTAINER_DLL_remove (head_not_pooled, tail_not_pooled, entry); + GNUNET_assert(!entry->in_lru); + if (!entry->in_pool) + GNUNET_CONTAINER_DLL_remove(head_not_pooled, tail_not_pooled, entry); if (NULL != map) - { - if (GNUNET_YES == - GNUNET_CONTAINER_multihashmap32_contains (map, entry->index)) - goto unallocate; - if (GNUNET_CONTAINER_multihashmap32_size (map) == max_size) { - if (NULL == head_lru) + if (GNUNET_YES == + GNUNET_CONTAINER_multihashmap32_contains(map, entry->index)) goto unallocate; - destroy_pooled_connection (head_lru); + if (GNUNET_CONTAINER_multihashmap32_size(map) == max_size) + { + if (NULL == head_lru) + goto unallocate; + destroy_pooled_connection(head_lru); + } + GNUNET_assert(GNUNET_OK == + GNUNET_CONTAINER_multihashmap32_put( + map, + entry->index, + entry, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + entry->in_pool = GNUNET_YES; } - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multihashmap32_put ( - map, - entry->index, - entry, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - entry->in_pool = GNUNET_YES; - } unallocate: - GNUNET_assert (0 < entry->demand); + GNUNET_assert(0 < entry->demand); entry->demand--; if (0 != entry->demand) return; if (entry->in_pool) - { - add_to_lru (entry); - return; - } - destroy_pooled_connection (entry); + { + add_to_lru(entry); + return; + } + destroy_pooled_connection(entry); } diff --git a/src/testbed/gnunet-service-testbed_connectionpool.h b/src/testbed/gnunet-service-testbed_connectionpool.h index 558918c30..40c937353 100644 --- a/src/testbed/gnunet-service-testbed_connectionpool.h +++ b/src/testbed/gnunet-service-testbed_connectionpool.h @@ -1,22 +1,22 @@ /* - This file is part of GNUnet. - Copyright (C) 2008--2015 GNUnet e.V. + This file is part of GNUnet. + Copyright (C) 2008--2015 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 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. + 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 . + 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/gnunet-service-testbed_connectionpool.h @@ -36,8 +36,7 @@ struct GST_ConnectionPool_GetHandle; /** * The type of service */ -enum GST_ConnectionPool_Service -{ +enum GST_ConnectionPool_Service { /** * Transport service */ @@ -63,14 +62,14 @@ enum GST_ConnectionPool_Service * #GST_ConnectionPool_Service */ void -GST_connection_pool_init (unsigned int size); +GST_connection_pool_init(unsigned int size); /** * Cleanup the connection pool */ void -GST_connection_pool_destroy (void); +GST_connection_pool_destroy(void); /** * Functions of this type are called when the needed handle is available for @@ -142,7 +141,7 @@ typedef void (*GST_connection_pool_peer_connect_notify) ( * longer being used */ struct GST_ConnectionPool_GetHandle * -GST_connection_pool_get_handle ( +GST_connection_pool_get_handle( unsigned int peer_id, const struct GNUNET_CONFIGURATION_Handle *cfg, enum GST_ConnectionPool_Service service, @@ -166,7 +165,7 @@ GST_connection_pool_get_handle ( * @param gh the handle */ void -GST_connection_pool_get_handle_done (struct GST_ConnectionPool_GetHandle *gh); +GST_connection_pool_get_handle_done(struct GST_ConnectionPool_GetHandle *gh); /* End of gnunet-service-testbed_connectionpool.h */ diff --git a/src/testbed/gnunet-service-testbed_cpustatus.c b/src/testbed/gnunet-service-testbed_cpustatus.c index d715036c7..a8796ea11 100644 --- a/src/testbed/gnunet-service-testbed_cpustatus.c +++ b/src/testbed/gnunet-service-testbed_cpustatus.c @@ -11,12 +11,12 @@ 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/gnunet-service-testbed_cpustatus.c @@ -90,7 +90,7 @@ struct GNUNET_SCHEDULER_Task * sample_load_task_id; #ifdef OSX static int -initMachCpuStats () +initMachCpuStats() { unsigned int cpu_count; processor_cpu_load_info_t cpu_load; @@ -98,17 +98,17 @@ initMachCpuStats () kern_return_t kret; int i, j; - kret = host_processor_info (mach_host_self (), - PROCESSOR_CPU_LOAD_INFO, - &cpu_count, - (processor_info_array_t *) & cpu_load, - &cpu_msg_count); + kret = host_processor_info(mach_host_self(), + PROCESSOR_CPU_LOAD_INFO, + &cpu_count, + (processor_info_array_t *)&cpu_load, + &cpu_msg_count); if (kret != KERN_SUCCESS) { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "host_processor_info failed."); + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "host_processor_info failed."); return GNUNET_SYSERR; } - prev_cpu_load = GNUNET_malloc (cpu_count * sizeof (*prev_cpu_load)); + prev_cpu_load = GNUNET_malloc(cpu_count * sizeof(*prev_cpu_load)); for (i = 0; i < cpu_count; i++) { for (j = 0; j < CPU_STATE_MAX; j++) @@ -116,9 +116,9 @@ initMachCpuStats () prev_cpu_load[i].cpu_ticks[j] = cpu_load[i].cpu_ticks[j]; } } - vm_deallocate (mach_task_self (), - (vm_address_t) cpu_load, - (vm_size_t) (cpu_msg_count * sizeof (*cpu_load))); + vm_deallocate(mach_task_self(), + (vm_address_t)cpu_load, + (vm_size_t)(cpu_msg_count * sizeof(*cpu_load))); return GNUNET_OK; } #endif @@ -130,7 +130,7 @@ initMachCpuStats () * If there is an error the method returns -1. */ static int -updateUsage () +updateUsage() { currentIOLoad = -1; currentCPULoad = -1; @@ -145,30 +145,30 @@ updateUsage () int ret; char line[256]; unsigned long long user_read, system_read, nice_read, idle_read, - iowait_read; + iowait_read; unsigned long long user, system, nice, idle, iowait; unsigned long long usage_time = 0, total_time = 1; /* Get the first line with the data */ - rewind (proc_stat); - fflush (proc_stat); - if (NULL == fgets (line, 256, proc_stat)) + rewind(proc_stat); + fflush(proc_stat); + if (NULL == fgets(line, 256, proc_stat)) { - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, - "fgets", "/proc/stat"); + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, + "fgets", "/proc/stat"); proc_stat = NULL; /* don't try again */ } else { iowait_read = 0; - ret = sscanf (line, "%*s %llu %llu %llu %llu %llu", - &user_read, - &system_read, &nice_read, &idle_read, &iowait_read); + ret = sscanf(line, "%*s %llu %llu %llu %llu %llu", + &user_read, + &system_read, &nice_read, &idle_read, &iowait_read); if (ret < 4) { - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, - "fgets-sscanf", "/proc/stat"); - fclose (proc_stat); + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, + "fgets-sscanf", "/proc/stat"); + fclose(proc_stat); proc_stat = NULL; /* don't try again */ have_last_cpu = GNUNET_NO; } @@ -185,9 +185,9 @@ updateUsage () total_time = usage_time + idle + iowait; if ((total_time > 0) && (have_last_cpu == GNUNET_YES)) { - currentCPULoad = (int) (100L * usage_time / total_time); + currentCPULoad = (int)(100L * usage_time / total_time); if (ret > 4) - currentIOLoad = (int) (100L * iowait / total_time); + currentIOLoad = (int)(100L * iowait / total_time); else currentIOLoad = -1; /* 2.4 kernel */ } @@ -215,10 +215,10 @@ updateUsage () int i, j; t_idle_all = t_total_all = 0; - kret = host_processor_info (mach_host_self (), PROCESSOR_CPU_LOAD_INFO, - &cpu_count, - (processor_info_array_t *) & cpu_load, - &cpu_msg_count); + kret = host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, + &cpu_count, + (processor_info_array_t *)&cpu_load, + &cpu_msg_count); if (kret == KERN_SUCCESS) { for (i = 0; i < cpu_count; i++) @@ -227,52 +227,52 @@ updateUsage () prev_cpu_load[i].cpu_ticks[CPU_STATE_SYSTEM]) { t_sys = cpu_load[i].cpu_ticks[CPU_STATE_SYSTEM] - - prev_cpu_load[i].cpu_ticks[CPU_STATE_SYSTEM]; + prev_cpu_load[i].cpu_ticks[CPU_STATE_SYSTEM]; } else { t_sys = cpu_load[i].cpu_ticks[CPU_STATE_SYSTEM] + - (ULONG_MAX - prev_cpu_load[i].cpu_ticks[CPU_STATE_SYSTEM] + - 1); + (ULONG_MAX - prev_cpu_load[i].cpu_ticks[CPU_STATE_SYSTEM] + + 1); } if (cpu_load[i].cpu_ticks[CPU_STATE_USER] >= prev_cpu_load[i].cpu_ticks[CPU_STATE_USER]) { t_user = cpu_load[i].cpu_ticks[CPU_STATE_USER] - - prev_cpu_load[i].cpu_ticks[CPU_STATE_USER]; + prev_cpu_load[i].cpu_ticks[CPU_STATE_USER]; } else { t_user = cpu_load[i].cpu_ticks[CPU_STATE_USER] + - (ULONG_MAX - prev_cpu_load[i].cpu_ticks[CPU_STATE_USER] + - 1); + (ULONG_MAX - prev_cpu_load[i].cpu_ticks[CPU_STATE_USER] + + 1); } if (cpu_load[i].cpu_ticks[CPU_STATE_NICE] >= prev_cpu_load[i].cpu_ticks[CPU_STATE_NICE]) { t_nice = cpu_load[i].cpu_ticks[CPU_STATE_NICE] - - prev_cpu_load[i].cpu_ticks[CPU_STATE_NICE]; + prev_cpu_load[i].cpu_ticks[CPU_STATE_NICE]; } else { t_nice = cpu_load[i].cpu_ticks[CPU_STATE_NICE] + - (ULONG_MAX - prev_cpu_load[i].cpu_ticks[CPU_STATE_NICE] + - 1); + (ULONG_MAX - prev_cpu_load[i].cpu_ticks[CPU_STATE_NICE] + + 1); } if (cpu_load[i].cpu_ticks[CPU_STATE_IDLE] >= prev_cpu_load[i].cpu_ticks[CPU_STATE_IDLE]) { t_idle = cpu_load[i].cpu_ticks[CPU_STATE_IDLE] - - prev_cpu_load[i].cpu_ticks[CPU_STATE_IDLE]; + prev_cpu_load[i].cpu_ticks[CPU_STATE_IDLE]; } else { t_idle = cpu_load[i].cpu_ticks[CPU_STATE_IDLE] + - (ULONG_MAX - prev_cpu_load[i].cpu_ticks[CPU_STATE_IDLE] + - 1); + (ULONG_MAX - prev_cpu_load[i].cpu_ticks[CPU_STATE_IDLE] + + 1); } t_total = t_sys + t_user + t_nice + t_idle; t_idle_all += t_idle; @@ -289,15 +289,15 @@ updateUsage () currentCPULoad = 100 - (100 * t_idle_all) / t_total_all; else currentCPULoad = -1; - vm_deallocate (mach_task_self (), - (vm_address_t) cpu_load, - (vm_size_t) (cpu_msg_count * sizeof (*cpu_load))); + vm_deallocate(mach_task_self(), + (vm_address_t)cpu_load, + (vm_size_t)(cpu_msg_count * sizeof(*cpu_load))); currentIOLoad = -1; /* FIXME-OSX! */ return GNUNET_OK; } else { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "host_processor_info failed."); + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "host_processor_info failed."); return GNUNET_SYSERR; } } @@ -318,10 +318,10 @@ updateUsage () if (kstat_once == 1) goto ABORT_KSTAT; - kc = kstat_open (); + kc = kstat_open(); if (kc == NULL) { - GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kstat_close"); + GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kstat_close"); goto ABORT_KSTAT; } @@ -331,29 +331,29 @@ updateUsage () { cpu_stat_t stats; - if (0 != strncmp (khelper->ks_name, "cpu_stat", strlen ("cpu_stat"))) + if (0 != strncmp(khelper->ks_name, "cpu_stat", strlen("cpu_stat"))) continue; - if (khelper->ks_data_size > sizeof (cpu_stat_t)) + if (khelper->ks_data_size > sizeof(cpu_stat_t)) continue; /* better save then sorry! */ - if (-1 != kstat_read (kc, khelper, &stats)) + if (-1 != kstat_read(kc, khelper, &stats)) { idlecount += stats.cpu_sysinfo.cpu[CPU_IDLE]; totalcount += stats.cpu_sysinfo.cpu[CPU_IDLE] + - stats.cpu_sysinfo.cpu[CPU_USER] + - stats.cpu_sysinfo.cpu[CPU_KERNEL] + - stats.cpu_sysinfo.cpu[CPU_WAIT]; + stats.cpu_sysinfo.cpu[CPU_USER] + + stats.cpu_sysinfo.cpu[CPU_KERNEL] + + stats.cpu_sysinfo.cpu[CPU_WAIT]; } } - if (0 != kstat_close (kc)) - GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kstat_close"); + if (0 != kstat_close(kc)) + GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kstat_close"); if ((idlecount == 0) && (totalcount == 0)) goto ABORT_KSTAT; /* no stats found => abort */ deltaidle = idlecount - last_idlecount; deltatotal = totalcount - last_totalcount; if ((deltatotal > 0) && (last_totalcount > 0)) { - currentCPULoad = (unsigned int) (100.0 * deltaidle / deltatotal); + currentCPULoad = (unsigned int)(100.0 * deltaidle / deltatotal); if (currentCPULoad > 100) currentCPULoad = 100; /* odd */ if (currentCPULoad < 0) @@ -366,7 +366,7 @@ updateUsage () last_idlecount = idlecount; last_totalcount = totalcount; return GNUNET_OK; - ABORT_KSTAT: +ABORT_KSTAT: kstat_once = 1; /* failed, don't try again */ return GNUNET_SYSERR; } @@ -380,21 +380,21 @@ updateUsage () { static int warnOnce = 0; double loadavg; - if (1 != getloadavg (&loadavg, 1)) + if (1 != getloadavg(&loadavg, 1)) { /* only warn once, if there is a problem with getloadavg, we're going to hit it frequently... */ if (warnOnce == 0) { warnOnce = 1; - GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "getloadavg"); + GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "getloadavg"); } return GNUNET_SYSERR; } else { /* success with getloadavg */ - currentCPULoad = (int) (100 * loadavg); + currentCPULoad = (int)(100 * loadavg); currentIOLoad = -1; /* FIXME */ return GNUNET_OK; } @@ -416,14 +416,14 @@ updateUsage () double dDiffUser; SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION theInfo; - if (GNNtQuerySystemInformation (SystemProcessorPerformanceInformation, - &theInfo, - sizeof (theInfo), NULL) == NO_ERROR) + if (GNNtQuerySystemInformation(SystemProcessorPerformanceInformation, + &theInfo, + sizeof(theInfo), NULL) == NO_ERROR) { /* PORT-ME MINGW: Multi-processor? */ - dKernel = Li2Double (theInfo.KernelTime); - dIdle = Li2Double (theInfo.IdleTime); - dUser = Li2Double (theInfo.UserTime); + dKernel = Li2Double(theInfo.KernelTime); + dIdle = Li2Double(theInfo.IdleTime); + dUser = Li2Double(theInfo.UserTime); dDiffKernel = dKernel - dLastKernel; dDiffIdle = dIdle - dLastIdle; dDiffUser = dUser - dLastUser; @@ -450,8 +450,8 @@ updateUsage () if (once == 0) { once = 1; - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Cannot query the CPU usage (Windows NT).\n"); + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + "Cannot query the CPU usage (Windows NT).\n"); } return GNUNET_SYSERR; } @@ -462,48 +462,48 @@ updateUsage () DWORD dwDataSize, dwType, dwDummy; /* Start query */ - if (RegOpenKeyEx (HKEY_DYN_DATA, - "PerfStats\\StartSrv", - 0, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS) + if (RegOpenKeyEx(HKEY_DYN_DATA, + "PerfStats\\StartSrv", + 0, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS) { /* only warn once */ static int once = 0; if (once == 0) { once = 1; - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Cannot query the CPU usage (Win 9x)\n"); + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + "Cannot query the CPU usage (Win 9x)\n"); } } - RegOpenKeyEx (HKEY_DYN_DATA, - "PerfStats\\StartStat", 0, KEY_ALL_ACCESS, &hKey); - dwDataSize = sizeof (dwDummy); - RegQueryValueEx (hKey, - "KERNEL\\CPUUsage", - NULL, &dwType, (LPBYTE) & dwDummy, &dwDataSize); - RegCloseKey (hKey); + RegOpenKeyEx(HKEY_DYN_DATA, + "PerfStats\\StartStat", 0, KEY_ALL_ACCESS, &hKey); + dwDataSize = sizeof(dwDummy); + RegQueryValueEx(hKey, + "KERNEL\\CPUUsage", + NULL, &dwType, (LPBYTE)&dwDummy, &dwDataSize); + RegCloseKey(hKey); /* Get CPU usage */ - RegOpenKeyEx (HKEY_DYN_DATA, - "PerfStats\\StatData", 0, KEY_ALL_ACCESS, &hKey); - dwDataSize = sizeof (currentCPULoad); - RegQueryValueEx (hKey, - "KERNEL\\CPUUsage", - NULL, &dwType, (LPBYTE) & currentCPULoad, &dwDataSize); - RegCloseKey (hKey); + RegOpenKeyEx(HKEY_DYN_DATA, + "PerfStats\\StatData", 0, KEY_ALL_ACCESS, &hKey); + dwDataSize = sizeof(currentCPULoad); + RegQueryValueEx(hKey, + "KERNEL\\CPUUsage", + NULL, &dwType, (LPBYTE)¤tCPULoad, &dwDataSize); + RegCloseKey(hKey); currentIOLoad = -1; /* FIXME-MINGW! */ /* Stop query */ - RegOpenKeyEx (HKEY_DYN_DATA, - "PerfStats\\StopStat", 0, KEY_ALL_ACCESS, &hKey); - RegOpenKeyEx (HKEY_DYN_DATA, - "PerfStats\\StopSrv", 0, KEY_ALL_ACCESS, &hKey); - dwDataSize = sizeof (dwDummy); - RegQueryValueEx (hKey, - "KERNEL\\CPUUsage", - NULL, &dwType, (LPBYTE) & dwDummy, &dwDataSize); - RegCloseKey (hKey); + RegOpenKeyEx(HKEY_DYN_DATA, + "PerfStats\\StopStat", 0, KEY_ALL_ACCESS, &hKey); + RegOpenKeyEx(HKEY_DYN_DATA, + "PerfStats\\StopSrv", 0, KEY_ALL_ACCESS, &hKey); + dwDataSize = sizeof(dwDummy); + RegQueryValueEx(hKey, + "KERNEL\\CPUUsage", + NULL, &dwType, (LPBYTE)&dwDummy, &dwDataSize); + RegCloseKey(hKey); return GNUNET_OK; } @@ -523,21 +523,21 @@ updateUsage () * that lock has already been obtained. */ static void -updateAgedLoad () +updateAgedLoad() { static struct GNUNET_TIME_Absolute lastCall; struct GNUNET_TIME_Relative age; - age = GNUNET_TIME_absolute_get_duration (lastCall); - if ( (agedCPULoad == -1) - || (age.rel_value_us > 500000) ) + age = GNUNET_TIME_absolute_get_duration(lastCall); + if ((agedCPULoad == -1) + || (age.rel_value_us > 500000)) { /* use smoothing, but do NOT update lastRet at frequencies higher than 500ms; this makes the smoothing (mostly) independent from the frequency at which getCPULoad is called (and we don't spend more time measuring CPU than actually computing something). */ - lastCall = GNUNET_TIME_absolute_get (); - updateUsage (); + lastCall = GNUNET_TIME_absolute_get(); + updateUsage(); if (currentCPULoad == -1) { agedCPULoad = -1; @@ -581,10 +581,10 @@ updateAgedLoad () * (100 is equivalent to full load) */ static int -cpu_get_load () +cpu_get_load() { - updateAgedLoad (); - return (int) agedCPULoad; + updateAgedLoad(); + return (int)agedCPULoad; } @@ -594,10 +594,10 @@ cpu_get_load () * (100 is equivalent to full load) */ static int -disk_get_load () +disk_get_load() { - updateAgedLoad (); - return (int) agedIOLoad; + updateAgedLoad(); + return (int)agedIOLoad; } /** @@ -606,13 +606,13 @@ disk_get_load () * @return the percentage of memory used */ static unsigned int -mem_get_usage () +mem_get_usage() { double percentage; - meminfo (); - percentage = ( ((double) kb_main_used) / ((double) kb_main_total) * 100.0 ); - return (unsigned int) percentage; + meminfo(); + percentage = (((double)kb_main_used) / ((double)kb_main_total) * 100.0); + return (unsigned int)percentage; } @@ -624,29 +624,29 @@ mem_get_usage () * @return the number of processes */ static unsigned int -get_nproc () +get_nproc() { DIR *dir; struct dirent *ent; unsigned int nproc; - dir = opendir ("/proc"); + dir = opendir("/proc"); if (NULL == dir) return 0; nproc = 0; - while (NULL != (ent = readdir (dir))) - { - if((*ent->d_name > '0') && (*ent->d_name <= '9')) - nproc++; - } - closedir (dir); + while (NULL != (ent = readdir(dir))) + { + if ((*ent->d_name > '0') && (*ent->d_name <= '9')) + nproc++; + } + closedir(dir); return nproc; } #endif static void -sample_load_task (void *cls) +sample_load_task(void *cls) { struct GNUNET_TIME_Absolute now; char *str; @@ -657,31 +657,31 @@ sample_load_task (void *cls) unsigned int nproc; sample_load_task_id = NULL; - ld_cpu = cpu_get_load (); - ld_disk = disk_get_load (); - if ( (-1 == ld_cpu) || (-1 == ld_disk) ) + ld_cpu = cpu_get_load(); + ld_disk = disk_get_load(); + if ((-1 == ld_cpu) || (-1 == ld_disk)) goto reschedule; - mem_usage = mem_get_usage (); + mem_usage = mem_get_usage(); #ifdef LINUX - nproc = get_nproc (); + nproc = get_nproc(); #else nproc = 0; #endif - now = GNUNET_TIME_absolute_get (); - nbs = GNUNET_asprintf (&str, "%llu %d %d %u %u\n", now.abs_value_us / 1000LL / 1000LL, - ld_cpu, ld_disk, mem_usage, nproc); + now = GNUNET_TIME_absolute_get(); + nbs = GNUNET_asprintf(&str, "%llu %d %d %u %u\n", now.abs_value_us / 1000LL / 1000LL, + ld_cpu, ld_disk, mem_usage, nproc); if (0 < nbs) - { - GNUNET_BIO_write (bw, str, nbs); - } + { + GNUNET_BIO_write(bw, str, nbs); + } else - GNUNET_break (0); - GNUNET_free (str); + GNUNET_break(0); + GNUNET_free(str); - reschedule: +reschedule: sample_load_task_id = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, - &sample_load_task, NULL); + GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, + &sample_load_task, NULL); } @@ -691,7 +691,7 @@ sample_load_task (void *cls) * generated from the hostname and the process's PID. */ void -GST_stats_init (const struct GNUNET_CONFIGURATION_Handle *cfg) +GST_stats_init(const struct GNUNET_CONFIGURATION_Handle *cfg) { char *hostname; char *stats_dir; @@ -699,49 +699,48 @@ GST_stats_init (const struct GNUNET_CONFIGURATION_Handle *cfg) size_t len; #if MINGW - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Load statistics logging now available for windows\n"); + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + "Load statistics logging now available for windows\n"); return; /* No logging on windows for now :( */ #endif if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (cfg, "testbed", - "STATS_DIR", &stats_dir)) + GNUNET_CONFIGURATION_get_value_filename(cfg, "testbed", + "STATS_DIR", &stats_dir)) return; - len = GNUNET_OS_get_hostname_max_length (); - hostname = GNUNET_malloc (len); - if (0 != gethostname (hostname, len)) - { - GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "gethostname"); - GNUNET_free (stats_dir); - GNUNET_free (hostname); - return; - } + len = GNUNET_OS_get_hostname_max_length(); + hostname = GNUNET_malloc(len); + if (0 != gethostname(hostname, len)) + { + GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "gethostname"); + GNUNET_free(stats_dir); + GNUNET_free(hostname); + return; + } fn = NULL; - (void) GNUNET_asprintf (&fn, "%s/%.*s-%jd.dat", stats_dir, len, - hostname, (intmax_t) getpid()); - GNUNET_free (stats_dir); - GNUNET_free (hostname); - if (NULL == (bw = GNUNET_BIO_write_open (fn))) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Cannot open %s for writing load statistics. " - "Not logging load statistics\n"), fn); - GNUNET_free (fn); - return; - } - GNUNET_free (fn); - sample_load_task_id = GNUNET_SCHEDULER_add_now (&sample_load_task, NULL); + (void)GNUNET_asprintf(&fn, "%s/%.*s-%jd.dat", stats_dir, len, + hostname, (intmax_t)getpid()); + GNUNET_free(stats_dir); + GNUNET_free(hostname); + if (NULL == (bw = GNUNET_BIO_write_open(fn))) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Cannot open %s for writing load statistics. " + "Not logging load statistics\n"), fn); + GNUNET_free(fn); + return; + } + GNUNET_free(fn); + sample_load_task_id = GNUNET_SCHEDULER_add_now(&sample_load_task, NULL); #ifdef LINUX - proc_stat = fopen ("/proc/stat", "r"); + proc_stat = fopen("/proc/stat", "r"); if (NULL == proc_stat) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, - "fopen", "/proc/stat"); + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, + "fopen", "/proc/stat"); #elif OSX - initMachCpuStats (); + initMachCpuStats(); #endif - updateUsage (); /* initialize */ - + updateUsage(); /* initialize */ } @@ -749,7 +748,7 @@ GST_stats_init (const struct GNUNET_CONFIGURATION_Handle *cfg) * Shutdown the status calls module. */ void -GST_stats_destroy () +GST_stats_destroy() { #if MINGW return; @@ -759,18 +758,18 @@ GST_stats_destroy () #ifdef LINUX if (proc_stat != NULL) { - fclose (proc_stat); + fclose(proc_stat); proc_stat = NULL; } #elif OSX - GNUNET_free_non_null (prev_cpu_load); + GNUNET_free_non_null(prev_cpu_load); #endif if (NULL != sample_load_task_id) - { - GNUNET_SCHEDULER_cancel (sample_load_task_id); - sample_load_task_id = NULL; - } - GNUNET_break (GNUNET_OK == GNUNET_BIO_write_close (bw)); + { + GNUNET_SCHEDULER_cancel(sample_load_task_id); + sample_load_task_id = NULL; + } + GNUNET_break(GNUNET_OK == GNUNET_BIO_write_close(bw)); bw = NULL; } diff --git a/src/testbed/gnunet-service-testbed_links.c b/src/testbed/gnunet-service-testbed_links.c index 62f65387e..d7715a16e 100644 --- a/src/testbed/gnunet-service-testbed_links.c +++ b/src/testbed/gnunet-service-testbed_links.c @@ -1,22 +1,22 @@ /* - This file is part of GNUnet. - Copyright (C) 2008--2013 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 . + This file is part of GNUnet. + Copyright (C) 2008--2013 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/gnunet-service-testbed_links.c @@ -33,8 +33,8 @@ #ifdef LOG #undef LOG #endif -#define LOG(kind,...) \ - GNUNET_log_from (kind, "testbed-links", __VA_ARGS__) +#define LOG(kind, ...) \ + GNUNET_log_from(kind, "testbed-links", __VA_ARGS__) /** * The event mask for the events we listen from sub-controllers @@ -45,8 +45,7 @@ /** * States of LCFContext */ -enum LCFContextState -{ +enum LCFContextState { /** * The Context has been initialized; Nothing has been done on it */ @@ -72,8 +71,7 @@ enum LCFContextState /** * Link controllers request forwarding context */ -struct LCFContext -{ +struct LCFContext { /** * The LCFContext */ @@ -128,7 +126,6 @@ struct LCFContext * The slave host */ uint32_t slave_host_id; - }; @@ -136,8 +133,7 @@ struct LCFContext * Notification context to be used to notify when connection to the neighbour's * controller is opened */ -struct NeighbourConnectNotification -{ +struct NeighbourConnectNotification { /** * DLL next for inclusion in neighbour's list of notification requests */ @@ -168,8 +164,7 @@ struct NeighbourConnectNotification /** * A connected controller which is not our child */ -struct Neighbour -{ +struct Neighbour { /** * The controller handle */ @@ -228,8 +223,7 @@ static unsigned int neighbour_list_size; * Context information for establishing a link to neighbour (Used is * GST_handle_link_controllers() */ -struct NeighbourConnectCtxt -{ +struct NeighbourConnectCtxt { /** * DLL next for inclusion in the corresponding context list */ @@ -319,13 +313,13 @@ static unsigned int route_list_size; * @param slave the slave controller to add */ static void -slave_list_add (struct Slave *slave) +slave_list_add(struct Slave *slave) { if (slave->host_id >= GST_slave_list_size) - GST_array_grow_large_enough (GST_slave_list, - GST_slave_list_size, - slave->host_id); - GNUNET_assert (NULL == GST_slave_list[slave->host_id]); + GST_array_grow_large_enough(GST_slave_list, + GST_slave_list_size, + slave->host_id); + GNUNET_assert(NULL == GST_slave_list[slave->host_id]); GST_slave_list[slave->host_id] = slave; } @@ -340,9 +334,9 @@ slave_list_add (struct Slave *slave) * @return #GNUNET_OK (continue iterating) */ static int -drop_client_entries (void *cls, - const struct GNUNET_HashCode *key, - void *value) +drop_client_entries(void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_SERVICE_Client *client = cls; struct RegisteredHostContext *rhc = value; @@ -350,11 +344,11 @@ drop_client_entries (void *cls, struct ForwardedOverlayConnectContext *foccn; for (focc = rhc->focc_dll_head; NULL != focc; focc = foccn) - { - foccn = focc->next; - if (focc->client == client) - GST_cleanup_focc (focc); - } + { + foccn = focc->next; + if (focc->client == client) + GST_cleanup_focc(focc); + } return GNUNET_OK; } @@ -365,11 +359,11 @@ drop_client_entries (void *cls, * @param route the route to add */ static void -route_list_add (struct Route *route) +route_list_add(struct Route *route) { if (route->dest >= route_list_size) - GST_array_grow_large_enough (route_list, route_list_size, route->dest); - GNUNET_assert (NULL == route_list[route->dest]); + GST_array_grow_large_enough(route_list, route_list_size, route->dest); + GNUNET_assert(NULL == route_list[route->dest]); route_list[route->dest] = route; } @@ -381,11 +375,11 @@ route_list_add (struct Route *route) * @param n the neighbour to add */ static void -neighbour_list_add (struct Neighbour *n) +neighbour_list_add(struct Neighbour *n) { if (n->host_id >= neighbour_list_size) - GST_array_grow_large_enough (neighbour_list, neighbour_list_size, n->host_id); - GNUNET_assert (NULL == neighbour_list[n->host_id]); + GST_array_grow_large_enough(neighbour_list, neighbour_list_size, n->host_id); + GNUNET_assert(NULL == neighbour_list[n->host_id]); neighbour_list[n->host_id] = n; } @@ -394,14 +388,14 @@ neighbour_list_add (struct Neighbour *n) * Cleans up the route list */ void -GST_route_list_clear () +GST_route_list_clear() { unsigned int id; for (id = 0; id < route_list_size; id++) if (NULL != route_list[id]) - GNUNET_free (route_list[id]); - GNUNET_free_non_null (route_list); + GNUNET_free(route_list[id]); + GNUNET_free_non_null(route_list); route_list = NULL; } @@ -416,20 +410,20 @@ GST_route_list_clear () * #GNUNET_NO if not. */ static int -reghost_free_iterator (void *cls, - const struct GNUNET_HashCode *key, - void *value) +reghost_free_iterator(void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct Slave *slave = cls; struct RegisteredHostContext *rhc = value; struct ForwardedOverlayConnectContext *focc; - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (slave->reghost_map, key, - value)); + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove(slave->reghost_map, key, + value)); while (NULL != (focc = rhc->focc_dll_head)) - GST_cleanup_focc (focc); - GNUNET_free (value); + GST_cleanup_focc(focc); + GNUNET_free(value); return GNUNET_YES; } @@ -440,30 +434,30 @@ reghost_free_iterator (void *cls, * @param slave the #Slave object */ static void -kill_slave (struct Slave *slave) +kill_slave(struct Slave *slave) { struct HostRegistration *hr_entry; while (NULL != (hr_entry = slave->hr_dll_head)) - { - GNUNET_CONTAINER_DLL_remove (slave->hr_dll_head, slave->hr_dll_tail, - hr_entry); - GNUNET_free (hr_entry); - } + { + GNUNET_CONTAINER_DLL_remove(slave->hr_dll_head, slave->hr_dll_tail, + hr_entry); + GNUNET_free(hr_entry); + } if (NULL != slave->rhandle) - GNUNET_TESTBED_cancel_registration (slave->rhandle); - GNUNET_assert (GNUNET_SYSERR != - GNUNET_CONTAINER_multihashmap_iterate (slave->reghost_map, - reghost_free_iterator, - slave)); - GNUNET_CONTAINER_multihashmap_destroy (slave->reghost_map); + GNUNET_TESTBED_cancel_registration(slave->rhandle); + GNUNET_assert(GNUNET_SYSERR != + GNUNET_CONTAINER_multihashmap_iterate(slave->reghost_map, + reghost_free_iterator, + slave)); + GNUNET_CONTAINER_multihashmap_destroy(slave->reghost_map); if (NULL != slave->controller) - GNUNET_TESTBED_controller_disconnect (slave->controller); + GNUNET_TESTBED_controller_disconnect(slave->controller); if (NULL != slave->controller_proc) - { - LOG_DEBUG ("Stopping a slave\n"); - GNUNET_TESTBED_controller_kill_ (slave->controller_proc); - } + { + LOG_DEBUG("Stopping a slave\n"); + GNUNET_TESTBED_controller_kill_(slave->controller_proc); + } } @@ -473,15 +467,15 @@ kill_slave (struct Slave *slave) * @param slave the #Slave object */ static void -destroy_slave (struct Slave *slave) +destroy_slave(struct Slave *slave) { if (NULL != slave->controller_proc) - { - GNUNET_TESTBED_controller_destroy_ (slave->controller_proc); - LOG_DEBUG ("Slave stopped\n"); - } + { + GNUNET_TESTBED_controller_destroy_(slave->controller_proc); + LOG_DEBUG("Slave stopped\n"); + } GST_slave_list[slave->host_id] = NULL; - GNUNET_free (slave); + GNUNET_free(slave); } @@ -489,26 +483,26 @@ destroy_slave (struct Slave *slave) * Cleans up the slave list */ void -GST_slave_list_clear () +GST_slave_list_clear() { struct Slave *slave; unsigned int id; for (id = 0; id < GST_slave_list_size; id++) - { - slave = GST_slave_list[id]; - if (NULL == slave) - continue; - kill_slave (slave); - } + { + slave = GST_slave_list[id]; + if (NULL == slave) + continue; + kill_slave(slave); + } for (id = 0; id < GST_slave_list_size; id++) - { - slave = GST_slave_list[id]; - if (NULL == slave) - continue; - destroy_slave (slave); - } - GNUNET_free_non_null (GST_slave_list); + { + slave = GST_slave_list[id]; + if (NULL == slave) + continue; + destroy_slave(slave); + } + GNUNET_free_non_null(GST_slave_list); GST_slave_list = NULL; } @@ -522,18 +516,18 @@ GST_slave_list_clear () * is found */ struct Route * -GST_find_dest_route (uint32_t host_id) +GST_find_dest_route(uint32_t host_id) { struct Route *route; if (route_list_size <= host_id) return NULL; while (NULL != (route = route_list[host_id])) - { - if (route->thru == GST_context->host_id) - break; - host_id = route->thru; - } + { + if (route->thru == GST_context->host_id) + break; + host_id = route->thru; + } return route; } @@ -551,10 +545,10 @@ GST_find_dest_route (uint32_t host_id) * NULL if cfg is set! */ static void -send_controller_link_response (struct GNUNET_SERVICE_Client *client, - uint64_t operation_id, - const struct GNUNET_CONFIGURATION_Handle *cfg, - const char *emsg) +send_controller_link_response(struct GNUNET_SERVICE_Client *client, + uint64_t operation_id, + const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *emsg) { struct GNUNET_MQ_Envelope *env; struct GNUNET_TESTBED_ControllerLinkResponse *msg; @@ -563,40 +557,40 @@ send_controller_link_response (struct GNUNET_SERVICE_Client *client, size_t xconfig_size; uint16_t msize; - GNUNET_assert ((NULL == cfg) || (NULL == emsg)); + GNUNET_assert((NULL == cfg) || (NULL == emsg)); xconfig = NULL; xconfig_size = 0; config_size = 0; msize = 0; if (NULL != cfg) - { - xconfig = GNUNET_TESTBED_compress_cfg_ (cfg, - &config_size, - &xconfig_size); - msize += xconfig_size; - } + { + xconfig = GNUNET_TESTBED_compress_cfg_(cfg, + &config_size, + &xconfig_size); + msize += xconfig_size; + } if (NULL != emsg) - msize += strlen (emsg); - env = GNUNET_MQ_msg_extra (msg, - msize, - GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT); + msize += strlen(emsg); + env = GNUNET_MQ_msg_extra(msg, + msize, + GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT); if (NULL == emsg) - msg->success = htons (GNUNET_YES); - msg->operation_id = GNUNET_htonll (operation_id); - msg->config_size = htons ((uint16_t) config_size); + msg->success = htons(GNUNET_YES); + msg->operation_id = GNUNET_htonll(operation_id); + msg->config_size = htons((uint16_t)config_size); if (NULL != xconfig) - { - GNUNET_memcpy (&msg[1], - xconfig, - xconfig_size); - GNUNET_free (xconfig); - } + { + GNUNET_memcpy(&msg[1], + xconfig, + xconfig_size); + GNUNET_free(xconfig); + } if (NULL != emsg) - GNUNET_memcpy (&msg[1], - emsg, - strlen (emsg)); - GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), - env); + GNUNET_memcpy(&msg[1], + emsg, + strlen(emsg)); + GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), + env); } @@ -606,7 +600,7 @@ send_controller_link_response (struct GNUNET_SERVICE_Client *client, * @param cls the LCFContext */ static void -lcf_proc_task (void *cls); +lcf_proc_task(void *cls); /** @@ -616,38 +610,40 @@ lcf_proc_task (void *cls); * @param emsg the error message; NULL if host registration is successful */ static void -lcf_proc_cc (void *cls, - const char *emsg) +lcf_proc_cc(void *cls, + const char *emsg) { struct LCFContext *lcf = cls; - GNUNET_assert (NULL == lcf_proc_task_id); + GNUNET_assert(NULL == lcf_proc_task_id); switch (lcf->state) - { - case INIT: - if (NULL != emsg) - goto registration_error; - lcf->state = DELEGATED_HOST_REGISTERED; - lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf); - break; - case DELEGATED_HOST_REGISTERED: - if (NULL != emsg) - goto registration_error; - lcf->state = SLAVE_HOST_REGISTERED; - lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf); - break; - default: - GNUNET_assert (0); /* Shouldn't reach here */ - } + { + case INIT: + if (NULL != emsg) + goto registration_error; + lcf->state = DELEGATED_HOST_REGISTERED; + lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, lcf); + break; + + case DELEGATED_HOST_REGISTERED: + if (NULL != emsg) + goto registration_error; + lcf->state = SLAVE_HOST_REGISTERED; + lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, lcf); + break; + + default: + GNUNET_assert(0); /* Shouldn't reach here */ + } return; registration_error: - LOG (GNUNET_ERROR_TYPE_WARNING, - "Host registration failed with message: %s\n", - emsg); + LOG(GNUNET_ERROR_TYPE_WARNING, + "Host registration failed with message: %s\n", + emsg); lcf->state = FINISHED; - lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, - lcf); + lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, + lcf); } @@ -657,7 +653,7 @@ registration_error: * @param cls the LCFContext */ static void -lcf_proc_task (void *cls); +lcf_proc_task(void *cls); /** @@ -666,21 +662,21 @@ lcf_proc_task (void *cls); * @param cls the LCFContext */ static void -lcf_forwarded_operation_timeout (void *cls) +lcf_forwarded_operation_timeout(void *cls) { struct LCFContext *lcf = cls; lcf->timeout_task = NULL; // GST_forwarded_operation_timeout (lcf->fopc, tc); - LOG (GNUNET_ERROR_TYPE_WARNING, - "A forwarded controller link operation has timed out\n"); - send_controller_link_response (lcf->client, - lcf->operation_id, - NULL, - "A forwarded controller link operation has timed out\n"); - GNUNET_assert (NULL == lcf_proc_task_id); - lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, - lcf); + LOG(GNUNET_ERROR_TYPE_WARNING, + "A forwarded controller link operation has timed out\n"); + send_controller_link_response(lcf->client, + lcf->operation_id, + NULL, + "A forwarded controller link operation has timed out\n"); + GNUNET_assert(NULL == lcf_proc_task_id); + lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, + lcf); } @@ -690,65 +686,68 @@ lcf_forwarded_operation_timeout (void *cls) * @param cls the LCFContext */ static void -lcf_proc_task (void *cls) +lcf_proc_task(void *cls) { struct LCFContext *lcf = cls; lcf_proc_task_id = NULL; switch (lcf->state) - { - case INIT: - if (GNUNET_NO == - GNUNET_TESTBED_is_host_registered_ (GST_host_list - [lcf->delegated_host_id], - lcf->gateway->controller)) - { - GST_queue_host_registration (lcf->gateway, lcf_proc_cc, lcf, - GST_host_list[lcf->delegated_host_id]); - } - else - { - lcf->state = DELEGATED_HOST_REGISTERED; - lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf); - } - break; - case DELEGATED_HOST_REGISTERED: - if (GNUNET_NO == - GNUNET_TESTBED_is_host_registered_ (GST_host_list[lcf->slave_host_id], - lcf->gateway->controller)) - { - GST_queue_host_registration (lcf->gateway, lcf_proc_cc, lcf, - GST_host_list[lcf->slave_host_id]); - } - else { - lcf->state = SLAVE_HOST_REGISTERED; - lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf); + case INIT: + if (GNUNET_NO == + GNUNET_TESTBED_is_host_registered_(GST_host_list + [lcf->delegated_host_id], + lcf->gateway->controller)) + { + GST_queue_host_registration(lcf->gateway, lcf_proc_cc, lcf, + GST_host_list[lcf->delegated_host_id]); + } + else + { + lcf->state = DELEGATED_HOST_REGISTERED; + lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, lcf); + } + break; + + case DELEGATED_HOST_REGISTERED: + if (GNUNET_NO == + GNUNET_TESTBED_is_host_registered_(GST_host_list[lcf->slave_host_id], + lcf->gateway->controller)) + { + GST_queue_host_registration(lcf->gateway, lcf_proc_cc, lcf, + GST_host_list[lcf->slave_host_id]); + } + else + { + lcf->state = SLAVE_HOST_REGISTERED; + lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, lcf); + } + break; + + case SLAVE_HOST_REGISTERED: + lcf->op = GNUNET_TESTBED_controller_link(lcf, + lcf->gateway->controller, + GST_host_list[lcf->delegated_host_id], + GST_host_list[lcf->slave_host_id], + lcf->is_subordinate); + lcf->timeout_task = + GNUNET_SCHEDULER_add_delayed(GST_timeout, + &lcf_forwarded_operation_timeout, + lcf); + lcf->state = FINISHED; + break; + + case FINISHED: + if (NULL != lcf->op) + GNUNET_TESTBED_operation_done(lcf->op); + GNUNET_CONTAINER_DLL_remove(lcf_head, + lcf_tail, + lcf); + GNUNET_free(lcf); + if (NULL != lcf_head) + lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, + lcf_head); } - break; - case SLAVE_HOST_REGISTERED: - lcf->op = GNUNET_TESTBED_controller_link (lcf, - lcf->gateway->controller, - GST_host_list[lcf->delegated_host_id], - GST_host_list[lcf->slave_host_id], - lcf->is_subordinate); - lcf->timeout_task = - GNUNET_SCHEDULER_add_delayed (GST_timeout, - &lcf_forwarded_operation_timeout, - lcf); - lcf->state = FINISHED; - break; - case FINISHED: - if (NULL != lcf->op) - GNUNET_TESTBED_operation_done (lcf->op); - GNUNET_CONTAINER_DLL_remove (lcf_head, - lcf_tail, - lcf); - GNUNET_free (lcf); - if (NULL != lcf_head) - lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, - lcf_head); - } } @@ -759,30 +758,30 @@ lcf_proc_task (void *cls) * @param event information about the event */ static void -slave_event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) +slave_event_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event) { struct LCFContext *lcf; /* We currently only get here when working on LCFContexts */ - GNUNET_assert (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type); + GNUNET_assert(GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type); lcf = event->op_cls; - GNUNET_assert (lcf->op == event->op); - GNUNET_TESTBED_operation_done (lcf->op); + GNUNET_assert(lcf->op == event->op); + GNUNET_TESTBED_operation_done(lcf->op); lcf->op = NULL; - GNUNET_assert (FINISHED == lcf->state); - GNUNET_assert (NULL != lcf->timeout_task); - GNUNET_SCHEDULER_cancel (lcf->timeout_task); + GNUNET_assert(FINISHED == lcf->state); + GNUNET_assert(NULL != lcf->timeout_task); + GNUNET_SCHEDULER_cancel(lcf->timeout_task); if (NULL == event->details.operation_finished.emsg) - send_controller_link_response (lcf->client, lcf->operation_id, - GNUNET_TESTBED_host_get_cfg_ - (GST_host_list[lcf->delegated_host_id]), - NULL); + send_controller_link_response(lcf->client, lcf->operation_id, + GNUNET_TESTBED_host_get_cfg_ + (GST_host_list[lcf->delegated_host_id]), + NULL); else - send_controller_link_response (lcf->client, lcf->operation_id, - NULL, - event->details.operation_finished.emsg); - GNUNET_assert (NULL == lcf_proc_task_id); - lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf); + send_controller_link_response(lcf->client, lcf->operation_id, + NULL, + event->details.operation_finished.emsg); + GNUNET_assert(NULL == lcf_proc_task_id); + lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, lcf); return; } @@ -797,56 +796,56 @@ slave_event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) * GNUNET_TESTBED_controller_stop() shouldn't be called in this case */ static void -slave_status_cb (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - int status) +slave_status_cb(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + int status) { struct Slave *slave = cls; struct LinkControllersContext *lcc; lcc = slave->lcc; if (GNUNET_SYSERR == status) - { - slave->controller_proc = NULL; - /* Stop all link controller forwarding tasks since we shutdown here anyway - and as these tasks they depend on the operation queues which are created - through GNUNET_TESTBED_controller_connect() and in kill_slave() we call - the destructor function GNUNET_TESTBED_controller_disconnect() */ - GST_free_lcf (); - kill_slave (slave); - destroy_slave (slave); - slave = NULL; - LOG (GNUNET_ERROR_TYPE_WARNING, "Unexpected slave shutdown\n"); - GNUNET_SCHEDULER_shutdown (); /* We too shutdown */ - goto clean_lcc; - } + { + slave->controller_proc = NULL; + /* Stop all link controller forwarding tasks since we shutdown here anyway + and as these tasks they depend on the operation queues which are created + through GNUNET_TESTBED_controller_connect() and in kill_slave() we call + the destructor function GNUNET_TESTBED_controller_disconnect() */ + GST_free_lcf(); + kill_slave(slave); + destroy_slave(slave); + slave = NULL; + LOG(GNUNET_ERROR_TYPE_WARNING, "Unexpected slave shutdown\n"); + GNUNET_SCHEDULER_shutdown(); /* We too shutdown */ + goto clean_lcc; + } slave->controller = - GNUNET_TESTBED_controller_connect (GST_host_list[slave->host_id], - EVENT_MASK, &slave_event_cb, - slave); + GNUNET_TESTBED_controller_connect(GST_host_list[slave->host_id], + EVENT_MASK, &slave_event_cb, + slave); if (NULL != slave->controller) - { - send_controller_link_response (lcc->client, lcc->operation_id, cfg, NULL); - } + { + send_controller_link_response(lcc->client, lcc->operation_id, cfg, NULL); + } else - { - send_controller_link_response (lcc->client, lcc->operation_id, NULL, - "Could not connect to delegated controller"); - kill_slave (slave); - destroy_slave (slave); - slave = NULL; - } - - clean_lcc: + { + send_controller_link_response(lcc->client, lcc->operation_id, NULL, + "Could not connect to delegated controller"); + kill_slave(slave); + destroy_slave(slave); + slave = NULL; + } + +clean_lcc: if (NULL != lcc) - { - if (NULL != lcc->client) { - GNUNET_SERVICE_client_continue (lcc->client); - lcc->client = NULL; + if (NULL != lcc->client) + { + GNUNET_SERVICE_client_continue(lcc->client); + lcc->client = NULL; + } + GNUNET_free(lcc); } - GNUNET_free (lcc); - } if (NULL != slave) slave->lcc = NULL; } @@ -861,7 +860,7 @@ slave_status_cb (void *cls, * @param n the neighbour */ static void -trigger_notifications (struct Neighbour *n); +trigger_notifications(struct Neighbour *n); /** @@ -871,19 +870,19 @@ trigger_notifications (struct Neighbour *n); * @param cls the neighbour */ static void -neighbour_connect_notify_task (void *cls) +neighbour_connect_notify_task(void *cls) { struct Neighbour *n = cls; struct NeighbourConnectNotification *h; - GNUNET_assert (NULL != (h = n->nl_head)); - GNUNET_assert (NULL != n->notify_task); + GNUNET_assert(NULL != (h = n->nl_head)); + GNUNET_assert(NULL != n->notify_task); n->notify_task = NULL; - GNUNET_assert (NULL != n->controller); - GNUNET_CONTAINER_DLL_remove (n->nl_head, n->nl_tail, h); - trigger_notifications (n); - h->cb (h->cb_cls, n->controller); - GNUNET_free (h); + GNUNET_assert(NULL != n->controller); + GNUNET_CONTAINER_DLL_remove(n->nl_head, n->nl_tail, h); + trigger_notifications(n); + h->cb(h->cb_cls, n->controller); + GNUNET_free(h); } @@ -896,9 +895,9 @@ neighbour_connect_notify_task (void *cls) * @param n the neighbour */ static void -trigger_notifications (struct Neighbour *n) +trigger_notifications(struct Neighbour *n) { - GNUNET_assert (NULL != n->conn_op); + GNUNET_assert(NULL != n->conn_op); if (NULL == n->nl_head) return; if (NULL == n->controller) @@ -906,14 +905,14 @@ trigger_notifications (struct Neighbour *n) if (NULL != n->notify_task) return; if (1 == n->inactive) - { - GNUNET_assert (0 == n->reference_cnt); - GNUNET_TESTBED_operation_activate_ (n->conn_op); - n->inactive = 0; - } + { + GNUNET_assert(0 == n->reference_cnt); + GNUNET_TESTBED_operation_activate_(n->conn_op); + n->inactive = 0; + } n->reference_cnt++; n->notify_task = - GNUNET_SCHEDULER_add_now (&neighbour_connect_notify_task, n); + GNUNET_SCHEDULER_add_now(&neighbour_connect_notify_task, n); } @@ -925,18 +924,18 @@ trigger_notifications (struct Neighbour *n) * @param cls the neighbour */ static void -opstart_neighbour_conn (void *cls) +opstart_neighbour_conn(void *cls) { struct Neighbour *n = cls; - GNUNET_assert (NULL != n->conn_op); - GNUNET_assert (NULL == n->controller); - LOG_DEBUG ("Opening connection to controller on host %u\n", n->host_id); - n->controller = GNUNET_TESTBED_controller_connect (GST_host_list[n->host_id], - EVENT_MASK, - &slave_event_cb, - NULL); - trigger_notifications (n); + GNUNET_assert(NULL != n->conn_op); + GNUNET_assert(NULL == n->controller); + LOG_DEBUG("Opening connection to controller on host %u\n", n->host_id); + n->controller = GNUNET_TESTBED_controller_connect(GST_host_list[n->host_id], + EVENT_MASK, + &slave_event_cb, + NULL); + trigger_notifications(n); } @@ -946,21 +945,21 @@ opstart_neighbour_conn (void *cls) * @param cls the neighbour */ static void -oprelease_neighbour_conn (void *cls) +oprelease_neighbour_conn(void *cls) { - struct Neighbour *n = cls; - - GNUNET_assert (0 == n->reference_cnt); - GNUNET_assert (NULL == n->notify_task); - GNUNET_assert (NULL == n->nl_head); - if (NULL != n->controller) - { - LOG_DEBUG ("Closing connection to controller on host %u\n", n->host_id); - GNUNET_TESTBED_controller_disconnect (n->controller); - n->controller = NULL; - } - n->conn_op = NULL; - n->inactive = 0; + struct Neighbour *n = cls; + + GNUNET_assert(0 == n->reference_cnt); + GNUNET_assert(NULL == n->notify_task); + GNUNET_assert(NULL == n->nl_head); + if (NULL != n->controller) + { + LOG_DEBUG("Closing connection to controller on host %u\n", n->host_id); + GNUNET_TESTBED_controller_disconnect(n->controller); + n->controller = NULL; + } + n->conn_op = NULL; + n->inactive = 0; } @@ -976,30 +975,30 @@ oprelease_neighbour_conn (void *cls) * @param cb_cls the closure for the above callback */ struct NeighbourConnectNotification * -GST_neighbour_get_connection (struct Neighbour *n, - GST_NeigbourConnectNotifyCallback cb, - void *cb_cls) +GST_neighbour_get_connection(struct Neighbour *n, + GST_NeigbourConnectNotifyCallback cb, + void *cb_cls) { struct NeighbourConnectNotification *h; - GNUNET_assert (NULL != cb); - LOG_DEBUG ("Attempting to get connection to controller on host %u\n", - n->host_id); - h = GNUNET_new (struct NeighbourConnectNotification); + GNUNET_assert(NULL != cb); + LOG_DEBUG("Attempting to get connection to controller on host %u\n", + n->host_id); + h = GNUNET_new(struct NeighbourConnectNotification); h->n = n; - h->cb = cb; + h->cb = cb; h->cb_cls = cb_cls; - GNUNET_CONTAINER_DLL_insert_tail (n->nl_head, n->nl_tail, h); + GNUNET_CONTAINER_DLL_insert_tail(n->nl_head, n->nl_tail, h); if (NULL == n->conn_op) - { - GNUNET_assert (NULL == n->controller); - n->conn_op = GNUNET_TESTBED_operation_create_ (n, &opstart_neighbour_conn, - &oprelease_neighbour_conn); - GNUNET_TESTBED_operation_queue_insert_ (GST_opq_openfds, n->conn_op); - GNUNET_TESTBED_operation_begin_wait_ (n->conn_op); - return h; - } - trigger_notifications (n); + { + GNUNET_assert(NULL == n->controller); + n->conn_op = GNUNET_TESTBED_operation_create_(n, &opstart_neighbour_conn, + &oprelease_neighbour_conn); + GNUNET_TESTBED_operation_queue_insert_(GST_opq_openfds, n->conn_op); + GNUNET_TESTBED_operation_begin_wait_(n->conn_op); + return h; + } + trigger_notifications(n); return h; } @@ -1010,33 +1009,33 @@ GST_neighbour_get_connection (struct Neighbour *n, * @param h the notification handle */ void -GST_neighbour_get_connection_cancel (struct NeighbourConnectNotification *h) +GST_neighbour_get_connection_cancel(struct NeighbourConnectNotification *h) { struct Neighbour *n; int cleanup_task; n = h->n; cleanup_task = (h == n->nl_head) ? GNUNET_YES : GNUNET_NO; - GNUNET_CONTAINER_DLL_remove (n->nl_head, n->nl_tail, h); - GNUNET_free (h); + GNUNET_CONTAINER_DLL_remove(n->nl_head, n->nl_tail, h); + GNUNET_free(h); if (GNUNET_NO == cleanup_task) return; if (NULL == n->notify_task) return; - GNUNET_assert (0 < n->reference_cnt); + GNUNET_assert(0 < n->reference_cnt); n->reference_cnt--; - GNUNET_SCHEDULER_cancel (n->notify_task); + GNUNET_SCHEDULER_cancel(n->notify_task); n->notify_task = NULL; if (NULL == n->nl_head) - { - if ( (0 == n->reference_cnt) && (0 == n->inactive) ) { - n->inactive = 1; - GNUNET_TESTBED_operation_inactivate_ (n->conn_op); + if ((0 == n->reference_cnt) && (0 == n->inactive)) + { + n->inactive = 1; + GNUNET_TESTBED_operation_inactivate_(n->conn_op); + } + return; } - return; - } - trigger_notifications (n); + trigger_notifications(n); } @@ -1048,16 +1047,16 @@ GST_neighbour_get_connection_cancel (struct NeighbourConnectNotification *h) * @param n the neighbour whose connection can be closed */ void -GST_neighbour_release_connection (struct Neighbour *n) +GST_neighbour_release_connection(struct Neighbour *n) { - GNUNET_assert (0 == n->inactive); - GNUNET_assert (0 < n->reference_cnt); + GNUNET_assert(0 == n->inactive); + GNUNET_assert(0 < n->reference_cnt); n->reference_cnt--; if (0 == n->reference_cnt) - { - n->inactive = 1; - GNUNET_TESTBED_operation_inactivate_ (n->conn_op); - } + { + n->inactive = 1; + GNUNET_TESTBED_operation_inactivate_(n->conn_op); + } } @@ -1067,16 +1066,16 @@ GST_neighbour_release_connection (struct Neighbour *n) * @param ncc the neighbour connect context to cleanup */ static void -cleanup_ncc (struct NeighbourConnectCtxt *ncc) +cleanup_ncc(struct NeighbourConnectCtxt *ncc) { if (NULL != ncc->nh) - GST_neighbour_get_connection_cancel (ncc->nh); + GST_neighbour_get_connection_cancel(ncc->nh); if (NULL != ncc->timeout_task) - GNUNET_SCHEDULER_cancel (ncc->timeout_task); - GNUNET_CONTAINER_DLL_remove (ncc_head, - ncc_tail, - ncc); - GNUNET_free (ncc); + GNUNET_SCHEDULER_cancel(ncc->timeout_task); + GNUNET_CONTAINER_DLL_remove(ncc_head, + ncc_tail, + ncc); + GNUNET_free(ncc); } @@ -1084,21 +1083,21 @@ cleanup_ncc (struct NeighbourConnectCtxt *ncc) * Cleans up the neighbour list */ void -GST_neighbour_list_clean () +GST_neighbour_list_clean() { struct Neighbour *n; unsigned int id; for (id = 0; id < neighbour_list_size; id++) - { - if (NULL == (n = neighbour_list[id])) - continue; - if (NULL != n->conn_op) - GNUNET_TESTBED_operation_release_ (n->conn_op); - GNUNET_free (n); - neighbour_list[id] = NULL; - } - GNUNET_free_non_null (neighbour_list); + { + if (NULL == (n = neighbour_list[id])) + continue; + if (NULL != n->conn_op) + GNUNET_TESTBED_operation_release_(n->conn_op); + GNUNET_free(n); + neighbour_list[id] = NULL; + } + GNUNET_free_non_null(neighbour_list); } @@ -1110,7 +1109,7 @@ GST_neighbour_list_clean () * the list size or neighbour at that index is NULL) */ struct Neighbour * -GST_get_neighbour (uint32_t id) +GST_get_neighbour(uint32_t id) { if (neighbour_list_size <= id) return NULL; @@ -1122,10 +1121,10 @@ GST_get_neighbour (uint32_t id) * Function to cleanup the neighbour connect contexts */ void -GST_free_nccq () +GST_free_nccq() { while (NULL != ncc_head) - cleanup_ncc (ncc_head); + cleanup_ncc(ncc_head); } @@ -1135,16 +1134,16 @@ GST_free_nccq () * @param cls the NeighbourConnectCtxt created in GST_handle_link_controllers() */ static void -timeout_neighbour_connect (void *cls) +timeout_neighbour_connect(void *cls) { - struct NeighbourConnectCtxt *ncc = cls; + struct NeighbourConnectCtxt *ncc = cls; - ncc->timeout_task = NULL; - send_controller_link_response (ncc->client, + ncc->timeout_task = NULL; + send_controller_link_response(ncc->client, ncc->op_id, NULL, "Could not connect to delegated controller"); - cleanup_ncc (ncc); + cleanup_ncc(ncc); } @@ -1155,20 +1154,20 @@ timeout_neighbour_connect (void *cls) * @param c the handle the neighbour's controller */ static void -neighbour_connect_cb (void *cls, - struct GNUNET_TESTBED_Controller *c) +neighbour_connect_cb(void *cls, + struct GNUNET_TESTBED_Controller *c) { struct NeighbourConnectCtxt *ncc = cls; - GNUNET_SCHEDULER_cancel (ncc->timeout_task); + GNUNET_SCHEDULER_cancel(ncc->timeout_task); ncc->timeout_task = NULL; ncc->nh = NULL; - GST_neighbour_release_connection (ncc->n); - send_controller_link_response (ncc->client, - ncc->op_id, - NULL, - NULL); - cleanup_ncc (ncc); + GST_neighbour_release_connection(ncc->n); + send_controller_link_response(ncc->client, + ncc->op_id, + NULL, + NULL); + cleanup_ncc(ncc); } @@ -1178,13 +1177,13 @@ neighbour_connect_cb (void *cls, * @param host the host of the neighbour */ struct Neighbour * -GST_create_neighbour (struct GNUNET_TESTBED_Host *host) +GST_create_neighbour(struct GNUNET_TESTBED_Host *host) { struct Neighbour *n; - n = GNUNET_new (struct Neighbour); - n->host_id = GNUNET_TESTBED_host_get_id_ (host); - neighbour_list_add (n); /* just add; connect on-demand */ + n = GNUNET_new(struct Neighbour); + n->host_id = GNUNET_TESTBED_host_get_id_(host); + neighbour_list_add(n); /* just add; connect on-demand */ return n; } @@ -1196,8 +1195,8 @@ GST_create_neighbour (struct GNUNET_TESTBED_Host *host) * @param msg the actual message */ void -handle_link_controllers (void *cls, - const struct GNUNET_TESTBED_ControllerLinkRequest *msg) +handle_link_controllers(void *cls, + const struct GNUNET_TESTBED_ControllerLinkRequest *msg) { struct GNUNET_SERVICE_Client *client = cls; struct LCFContext *lcf; @@ -1208,169 +1207,169 @@ handle_link_controllers (void *cls, uint32_t slave_host_id; if (NULL == GST_context) - { - GNUNET_break (0); - GNUNET_SERVICE_client_drop (client); - return; - } - delegated_host_id = ntohl (msg->delegated_host_id); + { + GNUNET_break(0); + GNUNET_SERVICE_client_drop(client); + return; + } + delegated_host_id = ntohl(msg->delegated_host_id); if (delegated_host_id == GST_context->host_id) - { - GNUNET_break (0); - LOG (GNUNET_ERROR_TYPE_WARNING, - "Trying to link ourselves\n"); - GNUNET_SERVICE_client_drop (client); - return; - } + { + GNUNET_break(0); + LOG(GNUNET_ERROR_TYPE_WARNING, + "Trying to link ourselves\n"); + GNUNET_SERVICE_client_drop(client); + return; + } if ((delegated_host_id >= GST_host_list_size) || (NULL == GST_host_list[delegated_host_id])) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - "Delegated host %u not registered with us\n", - delegated_host_id); - GNUNET_SERVICE_client_drop (client); - return; - } - slave_host_id = ntohl (msg->slave_host_id); + { + LOG(GNUNET_ERROR_TYPE_WARNING, + "Delegated host %u not registered with us\n", + delegated_host_id); + GNUNET_SERVICE_client_drop(client); + return; + } + slave_host_id = ntohl(msg->slave_host_id); if ((slave_host_id >= GST_host_list_size) || (NULL == GST_host_list[slave_host_id])) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - "Slave host %u not registered with us\n", - slave_host_id); - GNUNET_SERVICE_client_drop (client); - return; - } + { + LOG(GNUNET_ERROR_TYPE_WARNING, + "Slave host %u not registered with us\n", + slave_host_id); + GNUNET_SERVICE_client_drop(client); + return; + } if (slave_host_id == delegated_host_id) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - "Slave and delegated host are same\n"); - GNUNET_SERVICE_client_drop (client); - return; - } - op_id = GNUNET_ntohll (msg->operation_id); - if (slave_host_id == GST_context->host_id) /* Link from us */ - { - struct Slave *slave; - struct LinkControllersContext *lcc; - - if (1 != msg->is_subordinate) { - struct Neighbour *n; - struct NeighbourConnectCtxt *ncc; - - if ((delegated_host_id < neighbour_list_size) && - (NULL != neighbour_list[delegated_host_id])) - { - GNUNET_break (0); - GNUNET_SERVICE_client_drop (client); - return; - } - LOG_DEBUG ("Received request to establish a link to host %u\n", - delegated_host_id); - n = GST_create_neighbour (GST_host_list[delegated_host_id]); - ncc = GNUNET_new (struct NeighbourConnectCtxt); - ncc->n = n; - ncc->op_id = op_id; - ncc->client = client; - ncc->nh = GST_neighbour_get_connection (n, - &neighbour_connect_cb, - ncc); - ncc->timeout_task - = GNUNET_SCHEDULER_add_delayed (GST_timeout, - &timeout_neighbour_connect, - ncc); - GNUNET_CONTAINER_DLL_insert_tail (ncc_head, - ncc_tail, - ncc); - GNUNET_SERVICE_client_continue (client); + LOG(GNUNET_ERROR_TYPE_WARNING, + "Slave and delegated host are same\n"); + GNUNET_SERVICE_client_drop(client); return; } - if ( (delegated_host_id < GST_slave_list_size) && - (NULL != GST_slave_list[delegated_host_id]) ) + op_id = GNUNET_ntohll(msg->operation_id); + if (slave_host_id == GST_context->host_id) /* Link from us */ { - GNUNET_break (0); - GNUNET_SERVICE_client_drop (client); + struct Slave *slave; + struct LinkControllersContext *lcc; + + if (1 != msg->is_subordinate) + { + struct Neighbour *n; + struct NeighbourConnectCtxt *ncc; + + if ((delegated_host_id < neighbour_list_size) && + (NULL != neighbour_list[delegated_host_id])) + { + GNUNET_break(0); + GNUNET_SERVICE_client_drop(client); + return; + } + LOG_DEBUG("Received request to establish a link to host %u\n", + delegated_host_id); + n = GST_create_neighbour(GST_host_list[delegated_host_id]); + ncc = GNUNET_new(struct NeighbourConnectCtxt); + ncc->n = n; + ncc->op_id = op_id; + ncc->client = client; + ncc->nh = GST_neighbour_get_connection(n, + &neighbour_connect_cb, + ncc); + ncc->timeout_task + = GNUNET_SCHEDULER_add_delayed(GST_timeout, + &timeout_neighbour_connect, + ncc); + GNUNET_CONTAINER_DLL_insert_tail(ncc_head, + ncc_tail, + ncc); + GNUNET_SERVICE_client_continue(client); + return; + } + if ((delegated_host_id < GST_slave_list_size) && + (NULL != GST_slave_list[delegated_host_id])) + { + GNUNET_break(0); + GNUNET_SERVICE_client_drop(client); + return; + } + LOG_DEBUG("Received request to start and establish a link to host %u\n", + delegated_host_id); + slave = GNUNET_new(struct Slave); + slave->host_id = delegated_host_id; + slave->reghost_map = GNUNET_CONTAINER_multihashmap_create(100, + GNUNET_NO); + slave_list_add(slave); + lcc = GNUNET_new(struct LinkControllersContext); + lcc->operation_id = op_id; + lcc->client = client; + slave->lcc = lcc; + slave->controller_proc + = GNUNET_TESTBED_controller_start(GST_context->master_ip, + GST_host_list[slave->host_id], + &slave_status_cb, + slave); + new_route = GNUNET_new(struct Route); + new_route->dest = delegated_host_id; + new_route->thru = GST_context->host_id; + route_list_add(new_route); return; } - LOG_DEBUG ("Received request to start and establish a link to host %u\n", - delegated_host_id); - slave = GNUNET_new (struct Slave); - slave->host_id = delegated_host_id; - slave->reghost_map = GNUNET_CONTAINER_multihashmap_create (100, - GNUNET_NO); - slave_list_add (slave); - lcc = GNUNET_new (struct LinkControllersContext); - lcc->operation_id = op_id; - lcc->client = client; - slave->lcc = lcc; - slave->controller_proc - = GNUNET_TESTBED_controller_start (GST_context->master_ip, - GST_host_list[slave->host_id], - &slave_status_cb, - slave); - new_route = GNUNET_new (struct Route); - new_route->dest = delegated_host_id; - new_route->thru = GST_context->host_id; - route_list_add (new_route); - return; - } /* Route the request */ if (slave_host_id >= route_list_size) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - "No route towards slave host"); - GNUNET_SERVICE_client_drop (client); - return; - } - lcf = GNUNET_new (struct LCFContext); + { + LOG(GNUNET_ERROR_TYPE_WARNING, + "No route towards slave host"); + GNUNET_SERVICE_client_drop(client); + return; + } + lcf = GNUNET_new(struct LCFContext); lcf->delegated_host_id = delegated_host_id; lcf->slave_host_id = slave_host_id; - route = GST_find_dest_route (slave_host_id); - GNUNET_assert (NULL != route); /* because we add routes carefully */ - GNUNET_assert (route->dest < GST_slave_list_size); - GNUNET_assert (NULL != GST_slave_list[route->dest]); + route = GST_find_dest_route(slave_host_id); + GNUNET_assert(NULL != route); /* because we add routes carefully */ + GNUNET_assert(route->dest < GST_slave_list_size); + GNUNET_assert(NULL != GST_slave_list[route->dest]); lcf->is_subordinate = msg->is_subordinate; lcf->state = INIT; lcf->operation_id = op_id; lcf->gateway = GST_slave_list[route->dest]; lcf->client = client; if (NULL == lcf_head) - { - GNUNET_assert (NULL == lcf_proc_task_id); - GNUNET_CONTAINER_DLL_insert_tail (lcf_head, - lcf_tail, - lcf); - lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, - lcf); - } + { + GNUNET_assert(NULL == lcf_proc_task_id); + GNUNET_CONTAINER_DLL_insert_tail(lcf_head, + lcf_tail, + lcf); + lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, + lcf); + } else - { - GNUNET_CONTAINER_DLL_insert_tail (lcf_head, - lcf_tail, - lcf); - } + { + GNUNET_CONTAINER_DLL_insert_tail(lcf_head, + lcf_tail, + lcf); + } /* FIXME: Adding a new route should happen after the controllers are linked * successfully */ if (1 != msg->is_subordinate) - { - GNUNET_SERVICE_client_continue (client); - return; - } - if ( (delegated_host_id < route_list_size) && - (NULL != route_list[delegated_host_id]) ) - { - GNUNET_break_op (0); /* Are you trying to link delegated host twice + { + GNUNET_SERVICE_client_continue(client); + return; + } + if ((delegated_host_id < route_list_size) && + (NULL != route_list[delegated_host_id])) + { + GNUNET_break_op(0); /* Are you trying to link delegated host twice * with is subordinate flag set to GNUNET_YES? */ - GNUNET_SERVICE_client_drop (client); - return; - } - new_route = GNUNET_new (struct Route); + GNUNET_SERVICE_client_drop(client); + return; + } + new_route = GNUNET_new(struct Route); new_route->dest = delegated_host_id; new_route->thru = route->dest; - route_list_add (new_route); - GNUNET_SERVICE_client_continue (client); + route_list_add(new_route); + GNUNET_SERVICE_client_continue(client); } @@ -1381,7 +1380,7 @@ handle_link_controllers (void *cls, * @param client the client that is history */ void -GST_link_notify_disconnect (struct GNUNET_SERVICE_Client *client) +GST_link_notify_disconnect(struct GNUNET_SERVICE_Client *client) { struct NeighbourConnectCtxt *ncc; struct NeighbourConnectCtxt *nccn; @@ -1389,44 +1388,44 @@ GST_link_notify_disconnect (struct GNUNET_SERVICE_Client *client) struct LCFContext *lcfn; for (ncc = ncc_head; NULL != ncc; ncc = nccn) - { - nccn = ncc->next; - if (ncc->client == client) - cleanup_ncc (ncc); - } - for (unsigned int i=0;ireghost_map, - &drop_client_entries, - client); - lcc = slave->lcc; - if (NULL == lcc) - continue; - if (lcc->client == client) { - slave->lcc = NULL; - GNUNET_free (lcc); + nccn = ncc->next; + if (ncc->client == client) + cleanup_ncc(ncc); + } + for (unsigned int i = 0; i < GST_slave_list_size; i++) + { + struct Slave *slave = GST_slave_list[i]; + struct LinkControllersContext *lcc; + + if (NULL == slave) + continue; + GNUNET_CONTAINER_multihashmap_iterate(slave->reghost_map, + &drop_client_entries, + client); + lcc = slave->lcc; + if (NULL == lcc) + continue; + if (lcc->client == client) + { + slave->lcc = NULL; + GNUNET_free(lcc); + } } - } for (lcf = lcf_head; NULL != lcf; lcf = lcfn) - { - lcfn = lcf->next; - if ( (NULL != lcf) && - (client == lcf->client) ) { - if (NULL != lcf->op) - GNUNET_TESTBED_operation_done (lcf->op); - GNUNET_CONTAINER_DLL_remove (lcf_head, - lcf_tail, - lcf); - GNUNET_free (lcf); + lcfn = lcf->next; + if ((NULL != lcf) && + (client == lcf->client)) + { + if (NULL != lcf->op) + GNUNET_TESTBED_operation_done(lcf->op); + GNUNET_CONTAINER_DLL_remove(lcf_head, + lcf_tail, + lcf); + GNUNET_free(lcf); + } } - } } @@ -1434,28 +1433,28 @@ GST_link_notify_disconnect (struct GNUNET_SERVICE_Client *client) * Cleans up the queue used for forwarding link controllers requests */ void -GST_free_lcf () +GST_free_lcf() { struct LCFContext *lcf; if (NULL != lcf_head) - { - if (NULL != lcf_proc_task_id) { - GNUNET_SCHEDULER_cancel (lcf_proc_task_id); - lcf_proc_task_id = NULL; + if (NULL != lcf_proc_task_id) + { + GNUNET_SCHEDULER_cancel(lcf_proc_task_id); + lcf_proc_task_id = NULL; + } } - } - GNUNET_assert (NULL == lcf_proc_task_id); + GNUNET_assert(NULL == lcf_proc_task_id); for (lcf = lcf_head; NULL != lcf; lcf = lcf_head) - { - if (NULL != lcf->op) - GNUNET_TESTBED_operation_done (lcf->op); - if (NULL != lcf->timeout_task) - GNUNET_SCHEDULER_cancel (lcf->timeout_task); - GNUNET_CONTAINER_DLL_remove (lcf_head, - lcf_tail, - lcf); - GNUNET_free (lcf); - } + { + if (NULL != lcf->op) + GNUNET_TESTBED_operation_done(lcf->op); + if (NULL != lcf->timeout_task) + GNUNET_SCHEDULER_cancel(lcf->timeout_task); + GNUNET_CONTAINER_DLL_remove(lcf_head, + lcf_tail, + lcf); + GNUNET_free(lcf); + } } diff --git a/src/testbed/gnunet-service-testbed_links.h b/src/testbed/gnunet-service-testbed_links.h index e4824ede9..594ef29dc 100644 --- a/src/testbed/gnunet-service-testbed_links.h +++ b/src/testbed/gnunet-service-testbed_links.h @@ -1,22 +1,22 @@ /* - This file is part of GNUnet. - Copyright (C) 2008--2013 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 . + This file is part of GNUnet. + Copyright (C) 2008--2013 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/gnunet-service-testbed_links.h @@ -35,8 +35,7 @@ struct Neighbour; /** * Structure representing a connected(directly-linked) controller */ -struct Slave -{ +struct Slave { /** * The controller process handle if we had started the controller */ @@ -94,7 +93,7 @@ extern unsigned int GST_slave_list_size; * Cleans up the neighbour list */ void -GST_neighbour_list_clean (void); +GST_neighbour_list_clean(void); /** @@ -105,14 +104,14 @@ GST_neighbour_list_clean (void); * the list size or neighbour at that index is NULL) */ struct Neighbour * -GST_get_neighbour (uint32_t id); +GST_get_neighbour(uint32_t id); /** * Function to cleanup the neighbour connect contexts */ void -GST_free_nccq (void); +GST_free_nccq(void); /** @@ -145,9 +144,9 @@ typedef void * @param cb_cls the closure for the above callback */ struct NeighbourConnectNotification * -GST_neighbour_get_connection (struct Neighbour *n, - GST_NeigbourConnectNotifyCallback cb, - void *cb_cls); +GST_neighbour_get_connection(struct Neighbour *n, + GST_NeigbourConnectNotifyCallback cb, + void *cb_cls); /** @@ -156,7 +155,7 @@ GST_neighbour_get_connection (struct Neighbour *n, * @param h the notification handle */ void -GST_neighbour_get_connection_cancel (struct NeighbourConnectNotification *h); +GST_neighbour_get_connection_cancel(struct NeighbourConnectNotification *h); /** @@ -167,7 +166,7 @@ GST_neighbour_get_connection_cancel (struct NeighbourConnectNotification *h); * @param n the neighbour whose connection can be closed */ void -GST_neighbour_release_connection (struct Neighbour *n); +GST_neighbour_release_connection(struct Neighbour *n); /** @@ -176,7 +175,7 @@ GST_neighbour_release_connection (struct Neighbour *n); * @param host the host of the neighbour */ struct Neighbour * -GST_create_neighbour (struct GNUNET_TESTBED_Host *host); +GST_create_neighbour(struct GNUNET_TESTBED_Host *host); /** @@ -186,8 +185,8 @@ GST_create_neighbour (struct GNUNET_TESTBED_Host *host); * @param msg the actual message */ void -handle_link_controllers (void *cls, - const struct GNUNET_TESTBED_ControllerLinkRequest *msg); +handle_link_controllers(void *cls, + const struct GNUNET_TESTBED_ControllerLinkRequest *msg); /** @@ -197,11 +196,11 @@ handle_link_controllers (void *cls, * @param client the client that is history */ void -GST_link_notify_disconnect (struct GNUNET_SERVICE_Client *client); +GST_link_notify_disconnect(struct GNUNET_SERVICE_Client *client); /** * Cleans up the slave list */ void -GST_slave_list_clear (void); +GST_slave_list_clear(void); diff --git a/src/testbed/gnunet-service-testbed_meminfo.c b/src/testbed/gnunet-service-testbed_meminfo.c index 7b42331b5..27778447c 100644 --- a/src/testbed/gnunet-service-testbed_meminfo.c +++ b/src/testbed/gnunet-service-testbed_meminfo.c @@ -11,12 +11,12 @@ 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 -*/ + */ #include "platform.h" #include "gnunet_util_lib.h" @@ -42,11 +42,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#define BAD_OPEN_MESSAGE \ -"Error: /proc must be mounted\n" \ -" To mount /proc at boot you need an /etc/fstab line like:\n" \ -" proc /proc proc defaults\n" \ -" In the meantime, run \"mount proc /proc -t proc\"\n" +#define BAD_OPEN_MESSAGE \ + "Error: /proc must be mounted\n" \ + " To mount /proc at boot you need an /etc/fstab line like:\n" \ + " proc /proc proc defaults\n" \ + " In the meantime, run \"mount proc /proc -t proc\"\n" #define STAT_FILE "/proc/stat" //static int stat_fd = -1; @@ -67,21 +67,21 @@ static char buf[2048]; * that successive calls to the functions are more efficient. * It also reads the current contents of the file into the global buf. */ -#define FILE_TO_BUF(filename, fd) do{ \ - static int local_n; \ - if (fd == -1 && (fd = open(filename, O_RDONLY)) == -1) { \ - fputs(BAD_OPEN_MESSAGE, stderr); \ - fflush(NULL); \ - _exit(102); \ - } \ - lseek(fd, 0L, SEEK_SET); \ - if ((local_n = read(fd, buf, sizeof buf - 1)) < 0) { \ - perror(filename); \ - fflush(NULL); \ - _exit(103); \ - } \ - buf[local_n] = '\0'; \ -}while(0) +#define FILE_TO_BUF(filename, fd) do { \ + static int local_n; \ + if (fd == -1 && (fd = open(filename, O_RDONLY)) == -1) { \ + fputs(BAD_OPEN_MESSAGE, stderr); \ + fflush(NULL); \ + _exit(102); \ + } \ + lseek(fd, 0L, SEEK_SET); \ + if ((local_n = read(fd, buf, sizeof buf - 1)) < 0) { \ + perror(filename); \ + fflush(NULL); \ + _exit(103); \ + } \ + buf[local_n] = '\0'; \ + } while (0) /***********************************************************************/ @@ -101,8 +101,9 @@ typedef struct mem_table_struct { unsigned long *slot; /* slot in return struct */ } mem_table_struct; -static int compare_mem_table_structs(const void *a, const void *b){ - return strcmp(((const mem_table_struct*)a)->name,((const mem_table_struct*)b)->name); +static int compare_mem_table_structs(const void *a, const void *b) +{ + return strcmp(((const mem_table_struct*)a)->name, ((const mem_table_struct*)b)->name); } /* example data, following junk, with comments added: @@ -182,82 +183,90 @@ static unsigned long kb_nfs_unstable; static unsigned long kb_swap_reclaimable; static unsigned long kb_swap_unreclaimable; -void meminfo(void){ +void meminfo(void) +{ char namebuf[16]; /* big enough to hold any row name */ - mem_table_struct findme = { namebuf, NULL}; + mem_table_struct findme = { namebuf, NULL }; mem_table_struct *found; char *head; char *tail; static const mem_table_struct mem_table[] = { - {"Active", &kb_active}, // important - {"AnonPages", &kb_anon_pages}, - {"Bounce", &kb_bounce}, - {"Buffers", &kb_main_buffers}, // important - {"Cached", &kb_main_cached}, // important - {"CommitLimit", &kb_commit_limit}, - {"Committed_AS", &kb_committed_as}, - {"Dirty", &kb_dirty}, // kB version of vmstat nr_dirty - {"HighFree", &kb_high_free}, - {"HighTotal", &kb_high_total}, - {"Inact_clean", &kb_inact_clean}, - {"Inact_dirty", &kb_inact_dirty}, - {"Inact_laundry",&kb_inact_laundry}, - {"Inact_target", &kb_inact_target}, - {"Inactive", &kb_inactive}, // important - {"LowFree", &kb_low_free}, - {"LowTotal", &kb_low_total}, - {"Mapped", &kb_mapped}, // kB version of vmstat nr_mapped - {"MemFree", &kb_main_free}, // important - {"MemShared", &kb_main_shared}, // important, but now gone! - {"MemTotal", &kb_main_total}, // important - {"NFS_Unstable", &kb_nfs_unstable}, - {"PageTables", &kb_pagetables}, // kB version of vmstat nr_page_table_pages - {"ReverseMaps", &nr_reversemaps}, // same as vmstat nr_page_table_pages - {"SReclaimable", &kb_swap_reclaimable}, // "swap reclaimable" (dentry and inode structures) - {"SUnreclaim", &kb_swap_unreclaimable}, - {"Slab", &kb_slab}, // kB version of vmstat nr_slab - {"SwapCached", &kb_swap_cached}, - {"SwapFree", &kb_swap_free}, // important - {"SwapTotal", &kb_swap_total}, // important - {"VmallocChunk", &kb_vmalloc_chunk}, - {"VmallocTotal", &kb_vmalloc_total}, - {"VmallocUsed", &kb_vmalloc_used}, - {"Writeback", &kb_writeback}, // kB version of vmstat nr_writeback + { "Active", &kb_active }, // important + { "AnonPages", &kb_anon_pages }, + { "Bounce", &kb_bounce }, + { "Buffers", &kb_main_buffers }, // important + { "Cached", &kb_main_cached }, // important + { "CommitLimit", &kb_commit_limit }, + { "Committed_AS", &kb_committed_as }, + { "Dirty", &kb_dirty }, // kB version of vmstat nr_dirty + { "HighFree", &kb_high_free }, + { "HighTotal", &kb_high_total }, + { "Inact_clean", &kb_inact_clean }, + { "Inact_dirty", &kb_inact_dirty }, + { "Inact_laundry", &kb_inact_laundry }, + { "Inact_target", &kb_inact_target }, + { "Inactive", &kb_inactive }, // important + { "LowFree", &kb_low_free }, + { "LowTotal", &kb_low_total }, + { "Mapped", &kb_mapped }, // kB version of vmstat nr_mapped + { "MemFree", &kb_main_free }, // important + { "MemShared", &kb_main_shared }, // important, but now gone! + { "MemTotal", &kb_main_total }, // important + { "NFS_Unstable", &kb_nfs_unstable }, + { "PageTables", &kb_pagetables }, // kB version of vmstat nr_page_table_pages + { "ReverseMaps", &nr_reversemaps }, // same as vmstat nr_page_table_pages + { "SReclaimable", &kb_swap_reclaimable }, // "swap reclaimable" (dentry and inode structures) + { "SUnreclaim", &kb_swap_unreclaimable }, + { "Slab", &kb_slab }, // kB version of vmstat nr_slab + { "SwapCached", &kb_swap_cached }, + { "SwapFree", &kb_swap_free }, // important + { "SwapTotal", &kb_swap_total }, // important + { "VmallocChunk", &kb_vmalloc_chunk }, + { "VmallocTotal", &kb_vmalloc_total }, + { "VmallocUsed", &kb_vmalloc_used }, + { "Writeback", &kb_writeback }, // kB version of vmstat nr_writeback }; - const int mem_table_count = sizeof(mem_table)/sizeof(mem_table_struct); + const int mem_table_count = sizeof(mem_table) / sizeof(mem_table_struct); - FILE_TO_BUF(MEMINFO_FILE,meminfo_fd); + FILE_TO_BUF(MEMINFO_FILE, meminfo_fd); kb_inactive = ~0UL; head = buf; - for(;;){ - tail = strchr(head, ':'); - if(!tail) break; - *tail = '\0'; - if(strlen(head) >= sizeof(namebuf)){ - head = tail+1; - goto nextline; - } - strcpy(namebuf,head); - found = bsearch(&findme, mem_table, mem_table_count, - sizeof(mem_table_struct), compare_mem_table_structs - ); - head = tail+1; - if(!found) goto nextline; - *(found->slot) = (unsigned long)strtoull(head,&tail,10); + for (;;) + { + tail = strchr(head, ':'); + if (!tail) + break; + *tail = '\0'; + if (strlen(head) >= sizeof(namebuf)) + { + head = tail + 1; + goto nextline; + } + strcpy(namebuf, head); + found = bsearch(&findme, mem_table, mem_table_count, + sizeof(mem_table_struct), compare_mem_table_structs + ); + head = tail + 1; + if (!found) + goto nextline; + *(found->slot) = (unsigned long)strtoull(head, &tail, 10); nextline: - tail = strchr(head, '\n'); - if(!tail) break; - head = tail+1; - } - if(!kb_low_total){ /* low==main except with large-memory support */ - kb_low_total = kb_main_total; - kb_low_free = kb_main_free; - } - if(kb_inactive==~0UL){ - kb_inactive = kb_inact_dirty + kb_inact_clean + kb_inact_laundry; - } + tail = strchr(head, '\n'); + if (!tail) + break; + head = tail + 1; + } + if (!kb_low_total) /* low==main except with large-memory support */ + { + kb_low_total = kb_main_total; + kb_low_free = kb_main_free; + } + if (kb_inactive == ~0UL) + { + kb_inactive = kb_inact_dirty + kb_inact_clean + kb_inact_laundry; + } kb_swap_used = kb_swap_total - kb_swap_free; kb_main_used = kb_main_total - kb_main_free; } diff --git a/src/testbed/gnunet-service-testbed_meminfo.h b/src/testbed/gnunet-service-testbed_meminfo.h index 6f51bdfb7..ceaae8999 100644 --- a/src/testbed/gnunet-service-testbed_meminfo.h +++ b/src/testbed/gnunet-service-testbed_meminfo.h @@ -11,12 +11,12 @@ 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 -*/ + */ /* obsolete */ extern unsigned long kb_main_shared; diff --git a/src/testbed/gnunet-service-testbed_oc.c b/src/testbed/gnunet-service-testbed_oc.c index 4d6a4d446..391b95b12 100644 --- a/src/testbed/gnunet-service-testbed_oc.c +++ b/src/testbed/gnunet-service-testbed_oc.c @@ -1,22 +1,22 @@ /* - This file is part of GNUnet. - Copyright (C) 2008--2016 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 . + This file is part of GNUnet. + Copyright (C) 2008--2016 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/gnunet-service-testbed_oc.c @@ -34,16 +34,14 @@ #ifdef LOG #undef LOG #endif -#define LOG(kind,...) \ - GNUNET_log_from (kind, "testbed-OC", __VA_ARGS__) +#define LOG(kind, ...) \ + GNUNET_log_from(kind, "testbed-OC", __VA_ARGS__) /** * Context information for requesting ATS to connect to a peer */ -struct ConnectivitySuggestContext -{ - +struct ConnectivitySuggestContext { /** * The transport handle obtained from cache. Do NOT close/disconnect. */ @@ -69,15 +67,13 @@ struct ConnectivitySuggestContext * The ATS handle for the connectivity suggestion. */ struct GNUNET_ATS_ConnectivitySuggestHandle *csh; - }; /** * Types for context information we create for overlay connect requests */ -enum OverlayConnectContextType -{ +enum OverlayConnectContextType { /** * This type is used if the overlay connection is local i.e. the connection * has to be made between local peers @@ -102,8 +98,7 @@ enum OverlayConnectContextType * Context data for operations on second peer in local overlay connection * contexts */ -struct LocalPeer2Context -{ +struct LocalPeer2Context { /** * The handle for offering the HELLO of the first peer to the second * peer. @@ -121,8 +116,7 @@ struct LocalPeer2Context * Context data for operations on second peer in remote overlay connection * contexts */ -struct RemotePeer2Context -{ +struct RemotePeer2Context { /** * Controller of peer 2; If #OCC_TYPE_REMOTE_LATERAL is the type of overlay * connection then this can be NULL until the connection to the controller is @@ -152,8 +146,7 @@ struct RemotePeer2Context /** * Context information for connecting 2 peers in overlay. */ -struct OverlayConnectContext -{ +struct OverlayConnectContext { /** * The next pointer for maintaining a DLL of all OverlayConnectContexts */ @@ -211,7 +204,6 @@ struct OverlayConnectContext * Context information for operations on the second peer */ union { - /** * Context information to be used if the second peer is local */ @@ -221,7 +213,6 @@ struct OverlayConnectContext * Context information to be used if the second peer is remote */ struct RemotePeer2Context remote; - } p2ctx; /** @@ -274,8 +265,7 @@ struct OverlayConnectContext * peer A to make peer B connect to peer A by sending the controller of peer B * the HELLO of peer A. */ -struct RemoteOverlayConnectCtx -{ +struct RemoteOverlayConnectCtx { /** * the next pointer for DLL */ @@ -356,15 +346,15 @@ static struct RemoteOverlayConnectCtx *roccq_tail; * @param focc the ForwardedOverlayConnectContext to cleanup */ void -GST_cleanup_focc (struct ForwardedOverlayConnectContext *focc) +GST_cleanup_focc(struct ForwardedOverlayConnectContext *focc) { struct RegisteredHostContext *rhc = focc->rhc; - GNUNET_CONTAINER_DLL_remove (rhc->focc_dll_head, - rhc->focc_dll_tail, - focc); - GNUNET_free_non_null (focc->orig_msg); - GNUNET_free (focc); + GNUNET_CONTAINER_DLL_remove(rhc->focc_dll_head, + rhc->focc_dll_tail, + focc); + GNUNET_free_non_null(focc->orig_msg); + GNUNET_free(focc); } @@ -374,7 +364,7 @@ GST_cleanup_focc (struct ForwardedOverlayConnectContext *focc) * @param cls the `struct ForwardedOperationContext` */ static void -forwarded_overlay_connect_timeout (void *cls) +forwarded_overlay_connect_timeout(void *cls) { struct ForwardedOperationContext *fopc = cls; struct RegisteredHostContext *rhc; @@ -383,13 +373,13 @@ forwarded_overlay_connect_timeout (void *cls) fopc->timeout_task = NULL; rhc = fopc->cls; focc = rhc->focc_dll_head; - LOG_DEBUG ("Overlay linking between peers %u and %u failed\n", - focc->peer1, - focc->peer2); - GST_cleanup_focc (focc); - GST_forwarded_operation_timeout (fopc); + LOG_DEBUG("Overlay linking between peers %u and %u failed\n", + focc->peer1, + focc->peer2); + GST_cleanup_focc(focc); + GST_forwarded_operation_timeout(fopc); if (NULL != rhc->focc_dll_head) - GST_process_next_focc (rhc); + GST_process_next_focc(rhc); } @@ -402,19 +392,19 @@ forwarded_overlay_connect_timeout (void *cls) * @param msg the peer create success message */ static void -forwarded_overlay_connect_listener (void *cls, - const struct GNUNET_MessageHeader *msg) +forwarded_overlay_connect_listener(void *cls, + const struct GNUNET_MessageHeader *msg) { struct ForwardedOperationContext *fopc = cls; struct RegisteredHostContext *rhc; struct ForwardedOverlayConnectContext *focc; rhc = fopc->cls; - GST_forwarded_operation_reply_relay (cls, msg); + GST_forwarded_operation_reply_relay(cls, msg); focc = rhc->focc_dll_head; - GST_cleanup_focc (focc); + GST_cleanup_focc(focc); if (NULL != rhc->focc_dll_head) - GST_process_next_focc (rhc); + GST_process_next_focc(rhc); } @@ -424,7 +414,7 @@ forwarded_overlay_connect_listener (void *cls, * @param rhc the RegisteredHostContext */ void -GST_process_next_focc (struct RegisteredHostContext *rhc) +GST_process_next_focc(struct RegisteredHostContext *rhc) { struct ForwardedOperationContext *fopc; struct ForwardedOverlayConnectContext *focc; @@ -432,31 +422,31 @@ GST_process_next_focc (struct RegisteredHostContext *rhc) struct Slave *slave; focc = rhc->focc_dll_head; - GNUNET_assert (NULL != focc); - GNUNET_assert (RHC_DONE == rhc->state); - GNUNET_assert (VALID_PEER_ID (focc->peer1)); + GNUNET_assert(NULL != focc); + GNUNET_assert(RHC_DONE == rhc->state); + GNUNET_assert(VALID_PEER_ID(focc->peer1)); peer = GST_peer_list[focc->peer1]; - GNUNET_assert (GNUNET_YES == peer->is_remote); - GNUNET_assert (NULL != (slave = peer->details.remote.slave)); - fopc = GNUNET_new (struct ForwardedOperationContext); + GNUNET_assert(GNUNET_YES == peer->is_remote); + GNUNET_assert(NULL != (slave = peer->details.remote.slave)); + fopc = GNUNET_new(struct ForwardedOperationContext); fopc->client = focc->client; fopc->operation_id = focc->operation_id; fopc->cls = rhc; fopc->type = OP_OVERLAY_CONNECT; fopc->opc = - GNUNET_TESTBED_forward_operation_msg_ (slave->controller, - focc->operation_id, - focc->orig_msg, - &forwarded_overlay_connect_listener, - fopc); - GNUNET_free (focc->orig_msg); + GNUNET_TESTBED_forward_operation_msg_(slave->controller, + focc->operation_id, + focc->orig_msg, + &forwarded_overlay_connect_listener, + fopc); + GNUNET_free(focc->orig_msg); focc->orig_msg = NULL; - fopc->timeout_task = GNUNET_SCHEDULER_add_delayed (GST_timeout, - &forwarded_overlay_connect_timeout, - fopc); - GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, - fopcq_tail, - fopc); + fopc->timeout_task = GNUNET_SCHEDULER_add_delayed(GST_timeout, + &forwarded_overlay_connect_timeout, + fopc); + GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, + fopcq_tail, + fopc); } @@ -466,28 +456,28 @@ GST_process_next_focc (struct RegisteredHostContext *rhc) * @param lp2c the local peer2 context information */ static void -cleanup_occ_lp2c (struct LocalPeer2Context *lp2c) +cleanup_occ_lp2c(struct LocalPeer2Context *lp2c) { if (NULL != lp2c->ohh) - { - GNUNET_TRANSPORT_offer_hello_cancel (lp2c->ohh); - lp2c->ohh = NULL; - } + { + GNUNET_TRANSPORT_offer_hello_cancel(lp2c->ohh); + lp2c->ohh = NULL; + } if (NULL != lp2c->tcc.cgh_p2_th) - { - GST_connection_pool_get_handle_done (lp2c->tcc.cgh_p2_th); - lp2c->tcc.cgh_p2_th = NULL; - } + { + GST_connection_pool_get_handle_done(lp2c->tcc.cgh_p2_th); + lp2c->tcc.cgh_p2_th = NULL; + } if (NULL != lp2c->tcc.cgh_p2_ats) - { - GST_connection_pool_get_handle_done (lp2c->tcc.cgh_p2_ats); - lp2c->tcc.cgh_p2_ats = NULL; - } + { + GST_connection_pool_get_handle_done(lp2c->tcc.cgh_p2_ats); + lp2c->tcc.cgh_p2_ats = NULL; + } if (NULL != lp2c->tcc.csh) - { - GNUNET_ATS_connectivity_suggest_cancel (lp2c->tcc.csh); - lp2c->tcc.csh = NULL; - } + { + GNUNET_ATS_connectivity_suggest_cancel(lp2c->tcc.csh); + lp2c->tcc.csh = NULL; + } } @@ -498,23 +488,23 @@ cleanup_occ_lp2c (struct LocalPeer2Context *lp2c) * @param rp2c the remote peer2 context information */ static void -cleanup_occ_rp2c (struct RemotePeer2Context *rp2c) +cleanup_occ_rp2c(struct RemotePeer2Context *rp2c) { if (NULL != rp2c->opc) - { - GNUNET_TESTBED_forward_operation_msg_cancel_ (rp2c->opc); - rp2c->opc = NULL; - } + { + GNUNET_TESTBED_forward_operation_msg_cancel_(rp2c->opc); + rp2c->opc = NULL; + } if (NULL != rp2c->ncn) - { - GST_neighbour_get_connection_cancel (rp2c->ncn); - rp2c->ncn = NULL; - } - if ( (NULL != rp2c->p2c) && (NULL != rp2c->p2n) ) - { - GST_neighbour_release_connection (rp2c->p2n); - rp2c->p2n = NULL; - } + { + GST_neighbour_get_connection_cancel(rp2c->ncn); + rp2c->ncn = NULL; + } + if ((NULL != rp2c->p2c) && (NULL != rp2c->p2n)) + { + GST_neighbour_release_connection(rp2c->p2n); + rp2c->p2n = NULL; + } } /** @@ -523,7 +513,7 @@ cleanup_occ_rp2c (struct RemotePeer2Context *rp2c) * @param peer the peer to check */ #define PEER_EXPIRED(peer) \ - ( (GNUNET_YES == peer->destroy_flag) && (0 == peer->reference_cnt) ) + ((GNUNET_YES == peer->destroy_flag) && (0 == peer->reference_cnt)) /** * Cleanup overlay connect context structure @@ -531,49 +521,50 @@ cleanup_occ_rp2c (struct RemotePeer2Context *rp2c) * @param occ the overlay connect context */ static void -cleanup_occ (struct OverlayConnectContext *occ) +cleanup_occ(struct OverlayConnectContext *occ) { struct Peer *peer2; - LOG_DEBUG ("0x%llx: Cleaning up occ\n", - occ->op_id); - GNUNET_free_non_null (occ->emsg); - GNUNET_free_non_null (occ->hello); + LOG_DEBUG("0x%llx: Cleaning up occ\n", + occ->op_id); + GNUNET_free_non_null(occ->emsg); + GNUNET_free_non_null(occ->hello); if (NULL != occ->send_hello_task) - GNUNET_SCHEDULER_cancel (occ->send_hello_task); + GNUNET_SCHEDULER_cancel(occ->send_hello_task); if (NULL != occ->cleanup_task) - GNUNET_SCHEDULER_cancel (occ->cleanup_task); + GNUNET_SCHEDULER_cancel(occ->cleanup_task); if (NULL != occ->timeout_task) - GNUNET_SCHEDULER_cancel (occ->timeout_task); + GNUNET_SCHEDULER_cancel(occ->timeout_task); if (NULL != occ->cgh_ch) - GST_connection_pool_get_handle_done (occ->cgh_ch); + GST_connection_pool_get_handle_done(occ->cgh_ch); if (NULL != occ->ghh) - GNUNET_TRANSPORT_hello_get_cancel (occ->ghh); - GST_connection_pool_get_handle_done (occ->cgh_p1th); - GNUNET_assert (NULL != GST_peer_list); - GNUNET_assert (occ->peer->reference_cnt > 0); + GNUNET_TRANSPORT_hello_get_cancel(occ->ghh); + GST_connection_pool_get_handle_done(occ->cgh_p1th); + GNUNET_assert(NULL != GST_peer_list); + GNUNET_assert(occ->peer->reference_cnt > 0); occ->peer->reference_cnt--; - if (PEER_EXPIRED (occ->peer)) - GST_destroy_peer (occ->peer); + if (PEER_EXPIRED(occ->peer)) + GST_destroy_peer(occ->peer); switch (occ->type) - { - case OCC_TYPE_LOCAL: - peer2 = GST_peer_list[occ->other_peer_id]; - GNUNET_assert (peer2->reference_cnt > 0); - peer2->reference_cnt--; - if (PEER_EXPIRED (peer2)) - GST_destroy_peer (peer2); - cleanup_occ_lp2c (&occ->p2ctx.local); - break; - case OCC_TYPE_REMOTE_SLAVE: - case OCC_TYPE_REMOTE_LATERAL: - cleanup_occ_rp2c (&occ->p2ctx.remote); - break; - } - GNUNET_CONTAINER_DLL_remove (occq_head, - occq_tail, - occ); - GNUNET_free (occ); + { + case OCC_TYPE_LOCAL: + peer2 = GST_peer_list[occ->other_peer_id]; + GNUNET_assert(peer2->reference_cnt > 0); + peer2->reference_cnt--; + if (PEER_EXPIRED(peer2)) + GST_destroy_peer(peer2); + cleanup_occ_lp2c(&occ->p2ctx.local); + break; + + case OCC_TYPE_REMOTE_SLAVE: + case OCC_TYPE_REMOTE_LATERAL: + cleanup_occ_rp2c(&occ->p2ctx.remote); + break; + } + GNUNET_CONTAINER_DLL_remove(occq_head, + occq_tail, + occ); + GNUNET_free(occ); } @@ -583,12 +574,12 @@ cleanup_occ (struct OverlayConnectContext *occ) * @param cls the overlay connect context */ static void -do_cleanup_occ (void *cls) +do_cleanup_occ(void *cls) { struct OverlayConnectContext *occ = cls; occ->cleanup_task = NULL; - cleanup_occ (occ); + cleanup_occ(occ); } @@ -598,19 +589,19 @@ do_cleanup_occ (void *cls) * @param cls the OverlayConnectContext */ static void -timeout_overlay_connect (void *cls) +timeout_overlay_connect(void *cls) { struct OverlayConnectContext *occ = cls; - GNUNET_assert (NULL != occ->timeout_task); + GNUNET_assert(NULL != occ->timeout_task); occ->timeout_task = NULL; /* LOG (GNUNET_ERROR_TYPE_WARNING, */ /* "0x%llx: Timeout while connecting peers %u and %u: %s\n", occ->op_id, */ /* occ->peer->id, occ->other_peer_id, occ->emsg); */ - GST_send_operation_fail_msg (occ->client, - occ->op_id, - occ->emsg); - cleanup_occ (occ); + GST_send_operation_fail_msg(occ->client, + occ->op_id, + occ->emsg); + cleanup_occ(occ); } @@ -620,7 +611,7 @@ timeout_overlay_connect (void *cls) * @param client the client that disconnected */ void -GST_notify_client_disconnect_oc (struct GNUNET_SERVICE_Client *client) +GST_notify_client_disconnect_oc(struct GNUNET_SERVICE_Client *client) { struct ForwardedOperationContext *fopc; struct ForwardedOperationContext *fopcn; @@ -628,20 +619,20 @@ GST_notify_client_disconnect_oc (struct GNUNET_SERVICE_Client *client) struct OverlayConnectContext *occn; for (fopc = fopcq_head; NULL != fopc; fopc = fopcn) - { - fopcn = fopc->next; - if (fopc->client == client) { - GNUNET_SCHEDULER_cancel (fopc->timeout_task); - GST_forwarded_operation_timeout (fopc); + fopcn = fopc->next; + if (fopc->client == client) + { + GNUNET_SCHEDULER_cancel(fopc->timeout_task); + GST_forwarded_operation_timeout(fopc); + } } - } for (occ = occq_head; NULL != occ; occ = occn) - { - occn = occ->next; - if (occ->client == client) - cleanup_occ (occ); - } + { + occn = occ->next; + if (occ->client == client) + cleanup_occ(occ); + } // FIXME: implement clean up for client_keep replacements! } @@ -652,21 +643,21 @@ GST_notify_client_disconnect_oc (struct GNUNET_SERVICE_Client *client) * FIXME. */ static void -send_overlay_connect_success_msg (struct OverlayConnectContext *occ) +send_overlay_connect_success_msg(struct OverlayConnectContext *occ) { struct GNUNET_MQ_Envelope *env; struct GNUNET_TESTBED_ConnectionEventMessage *msg; - LOG_DEBUG ("0x%llx: Peers connected - Sending overlay connect success\n", - occ->op_id); - env = GNUNET_MQ_msg (msg, - GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT); - msg->event_type = htonl (GNUNET_TESTBED_ET_CONNECT); - msg->peer1 = htonl (occ->peer->id); - msg->peer2 = htonl (occ->other_peer_id); - msg->operation_id = GNUNET_htonll (occ->op_id); - GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (occ->client), - env); + LOG_DEBUG("0x%llx: Peers connected - Sending overlay connect success\n", + occ->op_id); + env = GNUNET_MQ_msg(msg, + GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT); + msg->event_type = htonl(GNUNET_TESTBED_ET_CONNECT); + msg->peer1 = htonl(occ->peer->id); + msg->peer2 = htonl(occ->other_peer_id); + msg->operation_id = GNUNET_htonll(occ->op_id); + GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(occ->client), + env); } @@ -678,61 +669,62 @@ send_overlay_connect_success_msg (struct OverlayConnectContext *occ) * @param new_peer the peer that connected */ static void -overlay_connect_notify (void *cls, - const struct GNUNET_PeerIdentity *new_peer) +overlay_connect_notify(void *cls, + const struct GNUNET_PeerIdentity *new_peer) { struct OverlayConnectContext *occ = cls; char *new_peer_str; char *other_peer_str; - LOG_DEBUG ("Overlay connect notify\n"); + LOG_DEBUG("Overlay connect notify\n"); if (0 == - memcmp (new_peer, &occ->peer_identity, - sizeof (struct GNUNET_PeerIdentity))) + memcmp(new_peer, &occ->peer_identity, + sizeof(struct GNUNET_PeerIdentity))) return; - new_peer_str = GNUNET_strdup (GNUNET_i2s (new_peer)); - other_peer_str = GNUNET_strdup (GNUNET_i2s (&occ->other_peer_identity)); + new_peer_str = GNUNET_strdup(GNUNET_i2s(new_peer)); + other_peer_str = GNUNET_strdup(GNUNET_i2s(&occ->other_peer_identity)); if (0 != - memcmp (new_peer, - &occ->other_peer_identity, - sizeof (struct GNUNET_PeerIdentity))) - { - LOG_DEBUG ("Unexpected peer %s connected when expecting peer %s\n", - new_peer_str, - other_peer_str); - GNUNET_free (new_peer_str); - GNUNET_free (other_peer_str); - return; - } - GNUNET_free (new_peer_str); - LOG_DEBUG ("0x%llx: Peer %s connected to peer %s\n", - occ->op_id, - other_peer_str, - GNUNET_i2s (&occ->peer_identity)); - GNUNET_free (other_peer_str); + memcmp(new_peer, + &occ->other_peer_identity, + sizeof(struct GNUNET_PeerIdentity))) + { + LOG_DEBUG("Unexpected peer %s connected when expecting peer %s\n", + new_peer_str, + other_peer_str); + GNUNET_free(new_peer_str); + GNUNET_free(other_peer_str); + return; + } + GNUNET_free(new_peer_str); + LOG_DEBUG("0x%llx: Peer %s connected to peer %s\n", + occ->op_id, + other_peer_str, + GNUNET_i2s(&occ->peer_identity)); + GNUNET_free(other_peer_str); if (NULL != occ->send_hello_task) - { - GNUNET_SCHEDULER_cancel (occ->send_hello_task); - occ->send_hello_task = NULL; - } - GNUNET_assert (NULL != occ->timeout_task); - GNUNET_SCHEDULER_cancel (occ->timeout_task); + { + GNUNET_SCHEDULER_cancel(occ->send_hello_task); + occ->send_hello_task = NULL; + } + GNUNET_assert(NULL != occ->timeout_task); + GNUNET_SCHEDULER_cancel(occ->timeout_task); occ->timeout_task = NULL; switch (occ->type) - { - case OCC_TYPE_LOCAL: - cleanup_occ_lp2c (&occ->p2ctx.local); - break; - case OCC_TYPE_REMOTE_SLAVE: - case OCC_TYPE_REMOTE_LATERAL: - cleanup_occ_rp2c (&occ->p2ctx.remote); - break; - } - GNUNET_free_non_null (occ->emsg); + { + case OCC_TYPE_LOCAL: + cleanup_occ_lp2c(&occ->p2ctx.local); + break; + + case OCC_TYPE_REMOTE_SLAVE: + case OCC_TYPE_REMOTE_LATERAL: + cleanup_occ_rp2c(&occ->p2ctx.remote); + break; + } + GNUNET_free_non_null(occ->emsg); occ->emsg = NULL; - send_overlay_connect_success_msg (occ); - occ->cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup_occ, - occ); + send_overlay_connect_success_msg(occ); + occ->cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup_occ, + occ); } @@ -747,43 +739,43 @@ overlay_connect_notify (void *cls, * @param cfg configuration of the peer */ static void -occ_cache_get_handle_ats_occ_cb (void *cls, - struct GNUNET_CORE_Handle *ch, - struct GNUNET_TRANSPORT_CoreHandle *th, - struct GNUNET_ATS_ConnectivityHandle *ac, - const struct GNUNET_PeerIdentity *my_identity, - const struct GNUNET_CONFIGURATION_Handle *cfg) +occ_cache_get_handle_ats_occ_cb(void *cls, + struct GNUNET_CORE_Handle *ch, + struct GNUNET_TRANSPORT_CoreHandle *th, + struct GNUNET_ATS_ConnectivityHandle *ac, + const struct GNUNET_PeerIdentity *my_identity, + const struct GNUNET_CONFIGURATION_Handle *cfg) { struct OverlayConnectContext *occ = cls; struct LocalPeer2Context *lp2c; - GNUNET_assert (OCC_TYPE_LOCAL == occ->type); - GNUNET_assert (NULL != occ->timeout_task); - GNUNET_free_non_null (occ->emsg); + GNUNET_assert(OCC_TYPE_LOCAL == occ->type); + GNUNET_assert(NULL != occ->timeout_task); + GNUNET_free_non_null(occ->emsg); if (NULL == ac) - { - GNUNET_asprintf (&occ->emsg, - "0x%llx: Failed to connect to ATS of peer with id: %u", - occ->op_id, - occ->peer->id); - GNUNET_SCHEDULER_cancel (occ->timeout_task); - occ->timeout_task = - GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, - occ); - return; - } + { + GNUNET_asprintf(&occ->emsg, + "0x%llx: Failed to connect to ATS of peer with id: %u", + occ->op_id, + occ->peer->id); + GNUNET_SCHEDULER_cancel(occ->timeout_task); + occ->timeout_task = + GNUNET_SCHEDULER_add_now(&timeout_overlay_connect, + occ); + return; + } occ->emsg = NULL; - GNUNET_asprintf (&occ->emsg, - "0x%llx: Timeout during GNUNET_ATS_connectivity_suggest() at peer %s", - occ->op_id, - GNUNET_i2s (&occ->other_peer_identity)); + GNUNET_asprintf(&occ->emsg, + "0x%llx: Timeout during GNUNET_ATS_connectivity_suggest() at peer %s", + occ->op_id, + GNUNET_i2s(&occ->other_peer_identity)); lp2c = &occ->p2ctx.local; lp2c->tcc.csh = - GNUNET_ATS_connectivity_suggest (ac, - &occ->peer_identity, - 1); + GNUNET_ATS_connectivity_suggest(ac, + &occ->peer_identity, + 1); } @@ -797,19 +789,19 @@ occ_cache_get_handle_ats_occ_cb (void *cls, * @param my_identity the identity of our peer */ static void -occ_cache_get_handle_ats_rocc_cb (void *cls, - struct GNUNET_CORE_Handle *ch, - struct GNUNET_TRANSPORT_CoreHandle *th, - struct GNUNET_ATS_ConnectivityHandle *ac, - const struct GNUNET_PeerIdentity *my_identity, - const struct GNUNET_CONFIGURATION_Handle *cfg) +occ_cache_get_handle_ats_rocc_cb(void *cls, + struct GNUNET_CORE_Handle *ch, + struct GNUNET_TRANSPORT_CoreHandle *th, + struct GNUNET_ATS_ConnectivityHandle *ac, + const struct GNUNET_PeerIdentity *my_identity, + const struct GNUNET_CONFIGURATION_Handle *cfg) { struct RemoteOverlayConnectCtx *rocc = cls; rocc->tcc.csh = - GNUNET_ATS_connectivity_suggest (ac, - &rocc->a_id, - 1); + GNUNET_ATS_connectivity_suggest(ac, + &rocc->a_id, + 1); } @@ -820,7 +812,7 @@ occ_cache_get_handle_ats_rocc_cb (void *cls, * @param cls the OverlayConnectContext */ static void -send_hello (void *cls); +send_hello(void *cls); /** @@ -831,31 +823,31 @@ send_hello (void *cls); * @param cls the overlay connect context */ static void -occ_hello_sent_cb (void *cls) +occ_hello_sent_cb(void *cls) { struct OverlayConnectContext *occ = cls; struct LocalPeer2Context *lp2c; struct Peer *peer2; - GNUNET_assert (OCC_TYPE_LOCAL == occ->type); - GNUNET_assert (NULL != occ->timeout_task); + GNUNET_assert(OCC_TYPE_LOCAL == occ->type); + GNUNET_assert(NULL != occ->timeout_task); lp2c = &occ->p2ctx.local; lp2c->ohh = NULL; - GNUNET_assert (NULL == occ->send_hello_task); - GNUNET_free_non_null (occ->emsg); + GNUNET_assert(NULL == occ->send_hello_task); + GNUNET_free_non_null(occ->emsg); - GNUNET_asprintf (&occ->emsg, - "0x%llx: Timeout while acquiring ATS of %s from cache", - occ->op_id, - GNUNET_i2s (&occ->other_peer_identity)); - GNUNET_assert (NULL != (peer2 = GST_peer_list[occ->other_peer_id])); + GNUNET_asprintf(&occ->emsg, + "0x%llx: Timeout while acquiring ATS of %s from cache", + occ->op_id, + GNUNET_i2s(&occ->other_peer_identity)); + GNUNET_assert(NULL != (peer2 = GST_peer_list[occ->other_peer_id])); lp2c->tcc.cgh_p2_ats = - GST_connection_pool_get_handle (occ->other_peer_id, - peer2->details.local.cfg, - GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY, - &occ_cache_get_handle_ats_occ_cb, - occ, NULL, NULL, NULL); + GST_connection_pool_get_handle(occ->other_peer_id, + peer2->details.local.cfg, + GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY, + &occ_cache_get_handle_ats_occ_cb, + occ, NULL, NULL, NULL); } @@ -867,36 +859,36 @@ occ_hello_sent_cb (void *cls) * #OCC_TYPE_REMOTE_SLAVE or #OCC_TYPE_REMOTE_LATERAL */ static void -send_hello_thru_rocc (struct OverlayConnectContext *occ) +send_hello_thru_rocc(struct OverlayConnectContext *occ) { struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg; char *other_peer_str; uint16_t msize; uint16_t hello_size; - GNUNET_assert (OCC_TYPE_LOCAL != occ->type); - GNUNET_assert (NULL != occ->hello); - other_peer_str = GNUNET_strdup (GNUNET_i2s (&occ->other_peer_identity)); - LOG_DEBUG ("0x%llx: Offering HELLO of %s (size: %u) to %s via Remote Overlay Request\n", - occ->op_id, - GNUNET_i2s (&occ->peer_identity), - ntohs (occ->hello->size), - other_peer_str); - GNUNET_free (other_peer_str); - hello_size = ntohs (occ->hello->size); - msize = sizeof (struct GNUNET_TESTBED_RemoteOverlayConnectMessage) + hello_size; - msg = GNUNET_malloc (msize); + GNUNET_assert(OCC_TYPE_LOCAL != occ->type); + GNUNET_assert(NULL != occ->hello); + other_peer_str = GNUNET_strdup(GNUNET_i2s(&occ->other_peer_identity)); + LOG_DEBUG("0x%llx: Offering HELLO of %s (size: %u) to %s via Remote Overlay Request\n", + occ->op_id, + GNUNET_i2s(&occ->peer_identity), + ntohs(occ->hello->size), + other_peer_str); + GNUNET_free(other_peer_str); + hello_size = ntohs(occ->hello->size); + msize = sizeof(struct GNUNET_TESTBED_RemoteOverlayConnectMessage) + hello_size; + msg = GNUNET_malloc(msize); msg->header.type = - htons (GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT); - msg->header.size = htons (msize); - msg->peer = htonl (occ->other_peer_id); - msg->operation_id = GNUNET_htonll (occ->op_id); + htons(GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT); + msg->header.size = htons(msize); + msg->peer = htonl(occ->other_peer_id); + msg->operation_id = GNUNET_htonll(occ->op_id); msg->peer_identity = occ->peer_identity; - GNUNET_memcpy (msg->hello, - occ->hello, - hello_size); - GNUNET_TESTBED_queue_message_ (occ->p2ctx.remote.p2c, - &msg->header); + GNUNET_memcpy(msg->hello, + occ->hello, + hello_size); + GNUNET_TESTBED_queue_message_(occ->p2ctx.remote.p2c, + &msg->header); } @@ -908,43 +900,43 @@ send_hello_thru_rocc (struct OverlayConnectContext *occ) * @param cls the OverlayConnectContext */ static void -send_hello (void *cls) +send_hello(void *cls) { struct OverlayConnectContext *occ = cls; struct LocalPeer2Context *lp2c; char *other_peer_str; occ->send_hello_task = NULL; - GNUNET_assert (NULL != occ->timeout_task); - GNUNET_assert (NULL != occ->hello); + GNUNET_assert(NULL != occ->timeout_task); + GNUNET_assert(NULL != occ->hello); if (OCC_TYPE_LOCAL != occ->type) - { - send_hello_thru_rocc (occ); - return; - } + { + send_hello_thru_rocc(occ); + return; + } lp2c = &occ->p2ctx.local; - other_peer_str = GNUNET_strdup (GNUNET_i2s (&occ->other_peer_identity)); - LOG_DEBUG ("0x%llx: Offering HELLO of %s to %s\n", - occ->op_id, - GNUNET_i2s (&occ->peer_identity), - other_peer_str); - GNUNET_free (other_peer_str); + other_peer_str = GNUNET_strdup(GNUNET_i2s(&occ->other_peer_identity)); + LOG_DEBUG("0x%llx: Offering HELLO of %s to %s\n", + occ->op_id, + GNUNET_i2s(&occ->peer_identity), + other_peer_str); + GNUNET_free(other_peer_str); lp2c->ohh = - GNUNET_TRANSPORT_offer_hello (lp2c->tcc.cfg, - occ->hello, - &occ_hello_sent_cb, - occ); + GNUNET_TRANSPORT_offer_hello(lp2c->tcc.cfg, + occ->hello, + &occ_hello_sent_cb, + occ); if (NULL == lp2c->ohh) - { - GNUNET_break (0); - occ->send_hello_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_MILLISECONDS, + { + GNUNET_break(0); + occ->send_hello_task = + GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_MILLISECONDS, 100 + GNUNET_CRYPTO_random_u32 - (GNUNET_CRYPTO_QUALITY_WEAK, 500)), - &send_hello, occ); - } + (GNUNET_CRYPTO_QUALITY_WEAK, 500)), + &send_hello, occ); + } } @@ -957,36 +949,36 @@ send_hello (void *cls) * @param ac the handle to ATS. Can be NULL if it is not requested * @param ignore_ peer identity which is ignored in this callback * @param cfg configuration of the peer -*/ + */ static void -p2_transport_connect_cache_callback (void *cls, - struct GNUNET_CORE_Handle *ch, - struct GNUNET_TRANSPORT_CoreHandle *th, - struct GNUNET_ATS_ConnectivityHandle *ac, - const struct GNUNET_PeerIdentity *ignore_, - const struct GNUNET_CONFIGURATION_Handle *cfg) +p2_transport_connect_cache_callback(void *cls, + struct GNUNET_CORE_Handle *ch, + struct GNUNET_TRANSPORT_CoreHandle *th, + struct GNUNET_ATS_ConnectivityHandle *ac, + const struct GNUNET_PeerIdentity *ignore_, + const struct GNUNET_CONFIGURATION_Handle *cfg) { struct OverlayConnectContext *occ = cls; - GNUNET_assert (OCC_TYPE_LOCAL == occ->type); + GNUNET_assert(OCC_TYPE_LOCAL == occ->type); if (NULL == th) - { - GNUNET_asprintf (&occ->emsg, - "0x%llx: Cannot connect to TRANSPORT of %s", - occ->op_id, - GNUNET_i2s (&occ->other_peer_identity)); - GNUNET_SCHEDULER_cancel (occ->timeout_task); - occ->timeout_task = - GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ); - return; - } + { + GNUNET_asprintf(&occ->emsg, + "0x%llx: Cannot connect to TRANSPORT of %s", + occ->op_id, + GNUNET_i2s(&occ->other_peer_identity)); + GNUNET_SCHEDULER_cancel(occ->timeout_task); + occ->timeout_task = + GNUNET_SCHEDULER_add_now(&timeout_overlay_connect, occ); + return; + } occ->p2ctx.local.tcc.th_ = th; occ->p2ctx.local.tcc.cfg = cfg; - GNUNET_asprintf (&occ->emsg, - "0x%llx: Timeout while offering HELLO to %s", - occ->op_id, - GNUNET_i2s (&occ->other_peer_identity)); - occ->send_hello_task = GNUNET_SCHEDULER_add_now (&send_hello, occ); + GNUNET_asprintf(&occ->emsg, + "0x%llx: Timeout while offering HELLO to %s", + occ->op_id, + GNUNET_i2s(&occ->other_peer_identity)); + occ->send_hello_task = GNUNET_SCHEDULER_add_now(&send_hello, occ); } @@ -997,36 +989,36 @@ p2_transport_connect_cache_callback (void *cls, * @param occ the overlay connect context */ static void -p2_transport_connect (struct OverlayConnectContext *occ) +p2_transport_connect(struct OverlayConnectContext *occ) { struct Peer *peer2; /* HUH? Why to *obtain* HELLO? Seems we use this to *SEND* the HELLO! */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Connecting to transport of peer %s to obtain HELLO\n", - GNUNET_i2s (&occ->other_peer_identity)); - GNUNET_assert (NULL == occ->emsg); - GNUNET_assert (NULL != occ->hello); - GNUNET_assert (NULL == occ->ghh); - GNUNET_assert (NULL == occ->p1th_); - GNUNET_assert (NULL == occ->cgh_p1th); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Connecting to transport of peer %s to obtain HELLO\n", + GNUNET_i2s(&occ->other_peer_identity)); + GNUNET_assert(NULL == occ->emsg); + GNUNET_assert(NULL != occ->hello); + GNUNET_assert(NULL == occ->ghh); + GNUNET_assert(NULL == occ->p1th_); + GNUNET_assert(NULL == occ->cgh_p1th); if (OCC_TYPE_LOCAL == occ->type) - { - GNUNET_assert (NULL != (peer2 = GST_peer_list[occ->other_peer_id])); - occ->p2ctx.local.tcc.cgh_p2_th = - GST_connection_pool_get_handle (occ->other_peer_id, - peer2->details.local.cfg, - GST_CONNECTIONPOOL_SERVICE_TRANSPORT, - &p2_transport_connect_cache_callback, - occ, NULL, NULL, NULL); - return; - } - GNUNET_asprintf (&occ->emsg, - "0x%llx: Timeout while offering HELLO to %s", - occ->op_id, - GNUNET_i2s (&occ->other_peer_identity)); - occ->send_hello_task = GNUNET_SCHEDULER_add_now (&send_hello, occ); + { + GNUNET_assert(NULL != (peer2 = GST_peer_list[occ->other_peer_id])); + occ->p2ctx.local.tcc.cgh_p2_th = + GST_connection_pool_get_handle(occ->other_peer_id, + peer2->details.local.cfg, + GST_CONNECTIONPOOL_SERVICE_TRANSPORT, + &p2_transport_connect_cache_callback, + occ, NULL, NULL, NULL); + return; + } + GNUNET_asprintf(&occ->emsg, + "0x%llx: Timeout while offering HELLO to %s", + occ->op_id, + GNUNET_i2s(&occ->other_peer_identity)); + occ->send_hello_task = GNUNET_SCHEDULER_add_now(&send_hello, occ); } @@ -1039,9 +1031,9 @@ p2_transport_connect (struct OverlayConnectContext *occ) * @return #GNUNET_OK */ static int -test_address (void *cls, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_TIME_Absolute expiration) +test_address(void *cls, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Absolute expiration) { int *empty = cls; @@ -1059,40 +1051,40 @@ test_address (void *cls, * @param hello our updated HELLO */ static void -hello_update_cb (void *cls, - const struct GNUNET_MessageHeader *hello) +hello_update_cb(void *cls, + const struct GNUNET_MessageHeader *hello) { struct OverlayConnectContext *occ = cls; int empty; uint16_t msize; - msize = ntohs (hello->size); + msize = ntohs(hello->size); empty = GNUNET_YES; - (void) GNUNET_HELLO_iterate_addresses ((const struct GNUNET_HELLO_Message *) - hello, GNUNET_NO, - &test_address, - &empty); + (void)GNUNET_HELLO_iterate_addresses((const struct GNUNET_HELLO_Message *) + hello, GNUNET_NO, + &test_address, + &empty); if (GNUNET_YES == empty) - { - LOG_DEBUG ("0x%llx: HELLO of %s is empty\n", - occ->op_id, - GNUNET_i2s (&occ->peer_identity)); - return; - } - LOG_DEBUG ("0x%llx: Received HELLO of %s\n", - occ->op_id, - GNUNET_i2s (&occ->peer_identity)); - occ->hello = GNUNET_malloc (msize); - GST_cache_add_hello (occ->peer->id, hello); - GNUNET_memcpy (occ->hello, hello, msize); - GNUNET_TRANSPORT_hello_get_cancel (occ->ghh); + { + LOG_DEBUG("0x%llx: HELLO of %s is empty\n", + occ->op_id, + GNUNET_i2s(&occ->peer_identity)); + return; + } + LOG_DEBUG("0x%llx: Received HELLO of %s\n", + occ->op_id, + GNUNET_i2s(&occ->peer_identity)); + occ->hello = GNUNET_malloc(msize); + GST_cache_add_hello(occ->peer->id, hello); + GNUNET_memcpy(occ->hello, hello, msize); + GNUNET_TRANSPORT_hello_get_cancel(occ->ghh); occ->ghh = NULL; - GST_connection_pool_get_handle_done (occ->cgh_p1th); + GST_connection_pool_get_handle_done(occ->cgh_p1th); occ->cgh_p1th = NULL; occ->p1th_ = NULL; - GNUNET_free_non_null (occ->emsg); + GNUNET_free_non_null(occ->emsg); occ->emsg = NULL; - p2_transport_connect (occ); + p2_transport_connect(occ); } @@ -1106,39 +1098,39 @@ hello_update_cb (void *cls, * @param ignore_ peer identity which is ignored in this callback */ static void -p1_transport_connect_cache_callback (void *cls, - struct GNUNET_CORE_Handle *ch, - struct GNUNET_TRANSPORT_CoreHandle *th, - struct GNUNET_ATS_ConnectivityHandle *ac, - const struct GNUNET_PeerIdentity *ignore_, - const struct GNUNET_CONFIGURATION_Handle *cfg) +p1_transport_connect_cache_callback(void *cls, + struct GNUNET_CORE_Handle *ch, + struct GNUNET_TRANSPORT_CoreHandle *th, + struct GNUNET_ATS_ConnectivityHandle *ac, + const struct GNUNET_PeerIdentity *ignore_, + const struct GNUNET_CONFIGURATION_Handle *cfg) { struct OverlayConnectContext *occ = cls; - GNUNET_free_non_null (occ->emsg); + GNUNET_free_non_null(occ->emsg); occ->emsg = NULL; if (NULL == th) - { - GNUNET_asprintf (&occ->emsg, - "0x%llx: Cannot connect to TRANSPORT of %s", - occ->op_id, - GNUNET_i2s (&occ->peer_identity)); - GNUNET_SCHEDULER_cancel (occ->timeout_task); - occ->timeout_task = - GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ); - return; - } - GNUNET_assert (NULL == occ->p1th_); - GNUNET_assert (NULL != occ->cgh_p1th); + { + GNUNET_asprintf(&occ->emsg, + "0x%llx: Cannot connect to TRANSPORT of %s", + occ->op_id, + GNUNET_i2s(&occ->peer_identity)); + GNUNET_SCHEDULER_cancel(occ->timeout_task); + occ->timeout_task = + GNUNET_SCHEDULER_add_now(&timeout_overlay_connect, occ); + return; + } + GNUNET_assert(NULL == occ->p1th_); + GNUNET_assert(NULL != occ->cgh_p1th); occ->p1th_ = th; - GNUNET_asprintf (&occ->emsg, - "0x%llx: Timeout while acquiring HELLO of peer %s", - occ->op_id, - GNUNET_i2s (&occ->peer_identity)); - occ->ghh = GNUNET_TRANSPORT_hello_get (cfg, - GNUNET_TRANSPORT_AC_ANY, - &hello_update_cb, - occ); + GNUNET_asprintf(&occ->emsg, + "0x%llx: Timeout while acquiring HELLO of peer %s", + occ->op_id, + GNUNET_i2s(&occ->peer_identity)); + occ->ghh = GNUNET_TRANSPORT_hello_get(cfg, + GNUNET_TRANSPORT_AC_ANY, + &hello_update_cb, + occ); } @@ -1152,68 +1144,68 @@ p1_transport_connect_cache_callback (void *cls, * @param my_identity the identity of our peer */ static void -occ_cache_get_handle_core_cb (void *cls, - struct GNUNET_CORE_Handle *ch, - struct GNUNET_TRANSPORT_CoreHandle *th, - struct GNUNET_ATS_ConnectivityHandle *ac, - const struct GNUNET_PeerIdentity *my_identity, - const struct GNUNET_CONFIGURATION_Handle *cfg) +occ_cache_get_handle_core_cb(void *cls, + struct GNUNET_CORE_Handle *ch, + struct GNUNET_TRANSPORT_CoreHandle *th, + struct GNUNET_ATS_ConnectivityHandle *ac, + const struct GNUNET_PeerIdentity *my_identity, + const struct GNUNET_CONFIGURATION_Handle *cfg) { struct OverlayConnectContext *occ = cls; const struct GNUNET_MessageHeader *hello; - GNUNET_assert (NULL != occ->timeout_task); - GNUNET_free_non_null (occ->emsg); + GNUNET_assert(NULL != occ->timeout_task); + GNUNET_free_non_null(occ->emsg); if ((NULL == ch) || (NULL == my_identity)) - { - GNUNET_asprintf (&occ->emsg, - "0x%llx: Failed to connect to CORE of peer with " - "id: %u", - occ->op_id, - occ->peer->id); - GNUNET_SCHEDULER_cancel (occ->timeout_task); - occ->timeout_task = - GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ); - return; - } + { + GNUNET_asprintf(&occ->emsg, + "0x%llx: Failed to connect to CORE of peer with " + "id: %u", + occ->op_id, + occ->peer->id); + GNUNET_SCHEDULER_cancel(occ->timeout_task); + occ->timeout_task = + GNUNET_SCHEDULER_add_now(&timeout_overlay_connect, occ); + return; + } occ->emsg = NULL; if (NULL != - GNUNET_CORE_get_mq (ch, - &occ->other_peer_identity)) - { - LOG_DEBUG ("0x%llx: Target peer already connected\n", - occ->op_id); - GNUNET_SCHEDULER_cancel (occ->timeout_task); - occ->timeout_task = NULL; - send_overlay_connect_success_msg (occ); - occ->cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup_occ, occ); - return; - } + GNUNET_CORE_get_mq(ch, + &occ->other_peer_identity)) + { + LOG_DEBUG("0x%llx: Target peer already connected\n", + occ->op_id); + GNUNET_SCHEDULER_cancel(occ->timeout_task); + occ->timeout_task = NULL; + send_overlay_connect_success_msg(occ); + occ->cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup_occ, occ); + return; + } occ->peer_identity = *my_identity; - LOG_DEBUG ("0x%llx: Acquiring HELLO of peer %s\n", - occ->op_id, - GNUNET_i2s (&occ->peer_identity)); + LOG_DEBUG("0x%llx: Acquiring HELLO of peer %s\n", + occ->op_id, + GNUNET_i2s(&occ->peer_identity)); /* Lookup for HELLO in hello cache */ - if (NULL != (hello = GST_cache_lookup_hello (occ->peer->id))) - { - LOG_DEBUG ("0x%llx: HELLO of peer %s found in cache\n", - occ->op_id, - GNUNET_i2s (&occ->peer_identity)); - occ->hello = GNUNET_copy_message (hello); - p2_transport_connect (occ); - return; - } - GNUNET_asprintf (&occ->emsg, - "0x%llx: Timeout while acquiring TRANSPORT of %s from cache", - occ->op_id, - GNUNET_i2s (&occ->peer_identity)); + if (NULL != (hello = GST_cache_lookup_hello(occ->peer->id))) + { + LOG_DEBUG("0x%llx: HELLO of peer %s found in cache\n", + occ->op_id, + GNUNET_i2s(&occ->peer_identity)); + occ->hello = GNUNET_copy_message(hello); + p2_transport_connect(occ); + return; + } + GNUNET_asprintf(&occ->emsg, + "0x%llx: Timeout while acquiring TRANSPORT of %s from cache", + occ->op_id, + GNUNET_i2s(&occ->peer_identity)); occ->cgh_p1th = - GST_connection_pool_get_handle (occ->peer->id, - occ->peer->details.local.cfg, - GST_CONNECTIONPOOL_SERVICE_TRANSPORT, - p1_transport_connect_cache_callback, - occ, - NULL, NULL, NULL); + GST_connection_pool_get_handle(occ->peer->id, + occ->peer->details.local.cfg, + GST_CONNECTIONPOOL_SERVICE_TRANSPORT, + p1_transport_connect_cache_callback, + occ, + NULL, NULL, NULL); } @@ -1226,41 +1218,41 @@ occ_cache_get_handle_core_cb (void *cls, * @param msg the peer create success message */ static void -overlay_connect_get_config (void *cls, - const struct GNUNET_MessageHeader *msg) +overlay_connect_get_config(void *cls, + const struct GNUNET_MessageHeader *msg) { struct OverlayConnectContext *occ = cls; struct RemotePeer2Context *rp2c; const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *cmsg; - GNUNET_assert (OCC_TYPE_LOCAL != occ->type); + GNUNET_assert(OCC_TYPE_LOCAL != occ->type); rp2c = &occ->p2ctx.remote; rp2c->opc = NULL; - GNUNET_assert (NULL != occ->timeout_task); - if (GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION != ntohs (msg->type)) - { - GNUNET_SCHEDULER_cancel (occ->timeout_task); - occ->timeout_task = - GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ); - } + GNUNET_assert(NULL != occ->timeout_task); + if (GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION != ntohs(msg->type)) + { + GNUNET_SCHEDULER_cancel(occ->timeout_task); + occ->timeout_task = + GNUNET_SCHEDULER_add_now(&timeout_overlay_connect, occ); + } cmsg = - (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *) msg; + (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *)msg; occ->other_peer_identity = cmsg->peer_identity; - GNUNET_free_non_null (occ->emsg); - GNUNET_asprintf (&occ->emsg, - "0x%llx: Timeout while connecting to CORE of peer with " - "id: %u", - occ->op_id, - occ->peer->id); + GNUNET_free_non_null(occ->emsg); + GNUNET_asprintf(&occ->emsg, + "0x%llx: Timeout while connecting to CORE of peer with " + "id: %u", + occ->op_id, + occ->peer->id); occ->cgh_ch = - GST_connection_pool_get_handle (occ->peer->id, - occ->peer->details.local.cfg, - GST_CONNECTIONPOOL_SERVICE_CORE, - occ_cache_get_handle_core_cb, - occ, - &occ->other_peer_identity, - &overlay_connect_notify, - occ); + GST_connection_pool_get_handle(occ->peer->id, + occ->peer->details.local.cfg, + GST_CONNECTIONPOOL_SERVICE_CORE, + occ_cache_get_handle_core_cb, + occ, + &occ->other_peer_identity, + &overlay_connect_notify, + occ); return; } @@ -1272,12 +1264,12 @@ overlay_connect_get_config (void *cls, * @param emsg the error message; NULL if host registration is successful */ static void -host_registration_comp (void *cls, const char *emsg) +host_registration_comp(void *cls, const char *emsg) { struct RegisteredHostContext *rhc = cls; rhc->state = RHC_DONE; - GST_process_next_focc (rhc); + GST_process_next_focc(rhc); } @@ -1292,19 +1284,19 @@ host_registration_comp (void *cls, const char *emsg) * #GNUNET_NO if not. */ static int -reghost_match_iterator (void *cls, - const struct GNUNET_HashCode *key, - void *value) +reghost_match_iterator(void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct RegisteredHostContext **rh = cls; struct RegisteredHostContext *rh_val = value; if ((rh_val->host == (*rh)->host) && (rh_val->reg_host == (*rh)->reg_host)) - { - GNUNET_free (*rh); - *rh = rh_val; - return GNUNET_NO; - } + { + GNUNET_free(*rh); + *rh = rh_val; + return GNUNET_NO; + } return GNUNET_YES; } @@ -1317,15 +1309,15 @@ reghost_match_iterator (void *cls, * @return the hashcode */ static struct GNUNET_HashCode -hash_hosts (struct GNUNET_TESTBED_Host *reg_host, - struct GNUNET_TESTBED_Host *host) +hash_hosts(struct GNUNET_TESTBED_Host *reg_host, + struct GNUNET_TESTBED_Host *host) { struct GNUNET_HashCode hash; uint32_t host_ids[2]; - host_ids[0] = GNUNET_TESTBED_host_get_id_ (reg_host); - host_ids[1] = GNUNET_TESTBED_host_get_id_ (host); - GNUNET_CRYPTO_hash (host_ids, sizeof (host_ids), &hash); + host_ids[0] = GNUNET_TESTBED_host_get_id_(reg_host); + host_ids[1] = GNUNET_TESTBED_host_get_id_(host); + GNUNET_CRYPTO_hash(host_ids, sizeof(host_ids), &hash); return hash; } @@ -1344,48 +1336,48 @@ hash_hosts (struct GNUNET_TESTBED_Host *reg_host, * already registered, NULL is returned. */ static struct RegisteredHostContext * -register_host (struct Slave *slave, - struct GNUNET_TESTBED_Host *host) +register_host(struct Slave *slave, + struct GNUNET_TESTBED_Host *host) { struct GNUNET_HashCode hash; struct RegisteredHostContext *rhc; - rhc = GNUNET_new (struct RegisteredHostContext); + rhc = GNUNET_new(struct RegisteredHostContext); rhc->reg_host = host; rhc->host = GST_host_list[slave->host_id]; - GNUNET_assert (NULL != rhc->reg_host); - GNUNET_assert (NULL != rhc->host); + GNUNET_assert(NULL != rhc->reg_host); + GNUNET_assert(NULL != rhc->host); rhc->state = RHC_INIT; - hash = hash_hosts (rhc->reg_host, rhc->host); + hash = hash_hosts(rhc->reg_host, rhc->host); if ((GNUNET_NO == - GNUNET_CONTAINER_multihashmap_contains (slave->reghost_map, - &hash)) || + GNUNET_CONTAINER_multihashmap_contains(slave->reghost_map, + &hash)) || (GNUNET_SYSERR != - GNUNET_CONTAINER_multihashmap_get_multiple (slave->reghost_map, - &hash, - reghost_match_iterator, - &rhc))) - { - /* create and add a new registerd host context */ - /* add the focc to its queue */ - GNUNET_CONTAINER_multihashmap_put (slave->reghost_map, - &hash, - rhc, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); - GST_queue_host_registration (slave, - host_registration_comp, - rhc, - rhc->reg_host); - } + GNUNET_CONTAINER_multihashmap_get_multiple(slave->reghost_map, + &hash, + reghost_match_iterator, + &rhc))) + { + /* create and add a new registerd host context */ + /* add the focc to its queue */ + GNUNET_CONTAINER_multihashmap_put(slave->reghost_map, + &hash, + rhc, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); + GST_queue_host_registration(slave, + host_registration_comp, + rhc, + rhc->reg_host); + } else - { - /* rhc is now set to the existing one from the hash map by - * reghost_match_iterator() */ - /* if queue is empty then ignore creating focc and proceed with normal - * forwarding */ - if (RHC_DONE == rhc->state) - return NULL; - } + { + /* rhc is now set to the existing one from the hash map by + * reghost_match_iterator() */ + /* if queue is empty then ignore creating focc and proceed with normal + * forwarding */ + if (RHC_DONE == rhc->state) + return NULL; + } return rhc; } @@ -1400,8 +1392,8 @@ register_host (struct Slave *slave, * be notified */ static void -forward_overlay_connect (const struct GNUNET_TESTBED_OverlayConnectMessage *msg, - struct GNUNET_SERVICE_Client *client) +forward_overlay_connect(const struct GNUNET_TESTBED_OverlayConnectMessage *msg, + struct GNUNET_SERVICE_Client *client) { struct ForwardedOperationContext *fopc; struct Route *route_to_peer2_host; @@ -1414,61 +1406,61 @@ forward_overlay_connect (const struct GNUNET_TESTBED_OverlayConnectMessage *msg, uint32_t p1; uint32_t p2; - p1 = ntohl (msg->peer1); - p2 = ntohl (msg->peer2); - op_id = GNUNET_ntohll (msg->operation_id); - peer2_host_id = ntohl (msg->peer2_host_id); - GNUNET_assert (VALID_PEER_ID (p1)); - GNUNET_assert (VALID_HOST_ID (peer2_host_id)); + p1 = ntohl(msg->peer1); + p2 = ntohl(msg->peer2); + op_id = GNUNET_ntohll(msg->operation_id); + peer2_host_id = ntohl(msg->peer2_host_id); + GNUNET_assert(VALID_PEER_ID(p1)); + GNUNET_assert(VALID_HOST_ID(peer2_host_id)); peer = GST_peer_list[p1]; - GNUNET_assert (GNUNET_YES == peer->is_remote); - LOG_DEBUG ("0x%llx: Forwarding overlay connect\n", op_id); - route_to_peer2_host = GST_find_dest_route (peer2_host_id); + GNUNET_assert(GNUNET_YES == peer->is_remote); + LOG_DEBUG("0x%llx: Forwarding overlay connect\n", op_id); + route_to_peer2_host = GST_find_dest_route(peer2_host_id); route_to_peer1_host = GST_find_dest_route - (peer->details.remote.remote_host_id); - GNUNET_assert (NULL != route_to_peer1_host); + (peer->details.remote.remote_host_id); + GNUNET_assert(NULL != route_to_peer1_host); if ((NULL != route_to_peer2_host) && (route_to_peer1_host->dest == route_to_peer2_host->dest)) goto forward; /* Peer2 is either with us OR peer1 and peer2 can be reached through different subtrees OR peer2 is on a subtree unknown to us */ - if (NULL != (rhc = register_host (peer->details.remote.slave, - GST_host_list[peer2_host_id]))) - { - LOG_DEBUG ("Queueing forwarding FOCC for connecting peers %u and %u\n", p1, p2); - focc = GNUNET_new (struct ForwardedOverlayConnectContext); - focc->rhc = rhc; - focc->peer1 = p1; - focc->peer2 = p2; - focc->peer2_host_id = peer2_host_id; - focc->orig_msg = GNUNET_copy_message (&msg->header); - focc->operation_id = op_id; - focc->client = client; - GNUNET_CONTAINER_DLL_insert_tail (rhc->focc_dll_head, - rhc->focc_dll_tail, - focc); - return; - } + if (NULL != (rhc = register_host(peer->details.remote.slave, + GST_host_list[peer2_host_id]))) + { + LOG_DEBUG("Queueing forwarding FOCC for connecting peers %u and %u\n", p1, p2); + focc = GNUNET_new(struct ForwardedOverlayConnectContext); + focc->rhc = rhc; + focc->peer1 = p1; + focc->peer2 = p2; + focc->peer2_host_id = peer2_host_id; + focc->orig_msg = GNUNET_copy_message(&msg->header); + focc->operation_id = op_id; + focc->client = client; + GNUNET_CONTAINER_DLL_insert_tail(rhc->focc_dll_head, + rhc->focc_dll_tail, + focc); + return; + } - forward: - LOG_DEBUG ("Forwarding without FOCC for connecting peers %u and %u\n", p1, p2); - fopc = GNUNET_new (struct ForwardedOperationContext); +forward: + LOG_DEBUG("Forwarding without FOCC for connecting peers %u and %u\n", p1, p2); + fopc = GNUNET_new(struct ForwardedOperationContext); fopc->client = client; fopc->operation_id = op_id; fopc->type = OP_OVERLAY_CONNECT; fopc->opc = - GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote. - slave->controller, op_id, - &msg->header, - &GST_forwarded_operation_reply_relay, - fopc); + GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. + slave->controller, op_id, + &msg->header, + &GST_forwarded_operation_reply_relay, + fopc); fopc->timeout_task = - GNUNET_SCHEDULER_add_delayed (GST_timeout, - &GST_forwarded_operation_timeout, - fopc); - GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, - fopcq_tail, - fopc); + GNUNET_SCHEDULER_add_delayed(GST_timeout, + &GST_forwarded_operation_timeout, + fopc); + GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, + fopcq_tail, + fopc); } @@ -1480,35 +1472,35 @@ forward_overlay_connect (const struct GNUNET_TESTBED_OverlayConnectMessage *msg, * @param c handle to the controller connection */ static void -p2_controller_connect_cb (void *cls, - struct GNUNET_TESTBED_Controller *c) +p2_controller_connect_cb(void *cls, + struct GNUNET_TESTBED_Controller *c) { struct OverlayConnectContext *occ = cls; struct RemotePeer2Context *rp2c; struct GNUNET_TESTBED_PeerGetConfigurationMessage cmsg; - GNUNET_assert (OCC_TYPE_LOCAL != occ->type); + GNUNET_assert(OCC_TYPE_LOCAL != occ->type); rp2c = &occ->p2ctx.remote; rp2c->ncn = NULL; rp2c->p2c = c; cmsg.header.size = - htons (sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage)); + htons(sizeof(struct GNUNET_TESTBED_PeerGetConfigurationMessage)); cmsg.header.type = - htons (GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION); - cmsg.peer_id = htonl (occ->other_peer_id); - cmsg.operation_id = GNUNET_htonll (occ->op_id); + htons(GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION); + cmsg.peer_id = htonl(occ->other_peer_id); + cmsg.operation_id = GNUNET_htonll(occ->op_id); rp2c->opc = - GNUNET_TESTBED_forward_operation_msg_ (rp2c->p2c, - occ->op_id, - &cmsg.header, - &overlay_connect_get_config, - occ); - GNUNET_free_non_null (occ->emsg); - GNUNET_asprintf (&occ->emsg, - "0x%llx: Timeout while getting peer identity of peer " - "with id: %u", - occ->op_id, - occ->other_peer_id); + GNUNET_TESTBED_forward_operation_msg_(rp2c->p2c, + occ->op_id, + &cmsg.header, + &overlay_connect_get_config, + occ); + GNUNET_free_non_null(occ->emsg); + GNUNET_asprintf(&occ->emsg, + "0x%llx: Timeout while getting peer identity of peer " + "with id: %u", + occ->op_id, + occ->other_peer_id); } @@ -1519,8 +1511,8 @@ p2_controller_connect_cb (void *cls, * @param msg the actual message */ void -handle_overlay_connect (void *cls, - const struct GNUNET_TESTBED_OverlayConnectMessage *msg) +handle_overlay_connect(void *cls, + const struct GNUNET_TESTBED_OverlayConnectMessage *msg) { struct GNUNET_SERVICE_Client *client = cls; struct Peer *peer; @@ -1532,112 +1524,114 @@ handle_overlay_connect (void *cls, uint32_t p2; uint32_t peer2_host_id; - p1 = ntohl (msg->peer1); - p2 = ntohl (msg->peer2); - if (! VALID_PEER_ID (p1)) - { - GNUNET_break (0); - GNUNET_SERVICE_client_drop (client); - return; - } + p1 = ntohl(msg->peer1); + p2 = ntohl(msg->peer2); + if (!VALID_PEER_ID(p1)) + { + GNUNET_break(0); + GNUNET_SERVICE_client_drop(client); + return; + } peer = GST_peer_list[p1]; - operation_id = GNUNET_ntohll (msg->operation_id); + operation_id = GNUNET_ntohll(msg->operation_id); LOG_DEBUG - ("Received overlay connect for peers %u and %u with op id: 0x%llx\n", - p1, - p2, - operation_id); - peer2_host_id = ntohl (msg->peer2_host_id); + ("Received overlay connect for peers %u and %u with op id: 0x%llx\n", + p1, + p2, + operation_id); + peer2_host_id = ntohl(msg->peer2_host_id); if (GNUNET_YES == peer->is_remote) - { - if (! VALID_HOST_ID (peer2_host_id)) { - GNUNET_break (0); - GNUNET_SERVICE_client_drop (client); + if (!VALID_HOST_ID(peer2_host_id)) + { + GNUNET_break(0); + GNUNET_SERVICE_client_drop(client); + return; + } + forward_overlay_connect(msg, client); + GNUNET_SERVICE_client_continue(client); return; } - forward_overlay_connect (msg, client); - GNUNET_SERVICE_client_continue (client); - return; - } p2n = NULL; - occ = GNUNET_new (struct OverlayConnectContext); + occ = GNUNET_new(struct OverlayConnectContext); occ->type = OCC_TYPE_LOCAL; - if (! VALID_PEER_ID (p2)) /* May be peer2 is on a another controller */ - { - if (NULL == (p2n = GST_get_neighbour (peer2_host_id))) + if (!VALID_PEER_ID(p2)) /* May be peer2 is on a another controller */ { - if (! VALID_HOST_ID (peer2_host_id)) - { - GNUNET_break (0); - LOG (GNUNET_ERROR_TYPE_WARNING, - "0x%llx: Peer %u's host not in our neighbours list\n", - operation_id, p2); - GNUNET_SERVICE_client_drop (client); - GNUNET_free (occ); - return; - } - p2n = GST_create_neighbour (GST_host_list[peer2_host_id]); + if (NULL == (p2n = GST_get_neighbour(peer2_host_id))) + { + if (!VALID_HOST_ID(peer2_host_id)) + { + GNUNET_break(0); + LOG(GNUNET_ERROR_TYPE_WARNING, + "0x%llx: Peer %u's host not in our neighbours list\n", + operation_id, p2); + GNUNET_SERVICE_client_drop(client); + GNUNET_free(occ); + return; + } + p2n = GST_create_neighbour(GST_host_list[peer2_host_id]); + } + occ->type = OCC_TYPE_REMOTE_LATERAL; + occ->p2ctx.remote.p2n = p2n; } - occ->type = OCC_TYPE_REMOTE_LATERAL; - occ->p2ctx.remote.p2n = p2n; - } else if (GNUNET_YES == GST_peer_list[p2]->is_remote) - { - occ->type = OCC_TYPE_REMOTE_SLAVE; - occ->p2ctx.remote.p2c = GST_peer_list[p2]->details.remote.slave->controller; - } - GNUNET_CONTAINER_DLL_insert_tail (occq_head, - occq_tail, - occ); + { + occ->type = OCC_TYPE_REMOTE_SLAVE; + occ->p2ctx.remote.p2c = GST_peer_list[p2]->details.remote.slave->controller; + } + GNUNET_CONTAINER_DLL_insert_tail(occq_head, + occq_tail, + occ); occ->client = client; occ->other_peer_id = p2; GST_peer_list[p1]->reference_cnt++; occ->peer = GST_peer_list[p1]; occ->op_id = operation_id; - GNUNET_assert (NULL == occ->timeout_task); + GNUNET_assert(NULL == occ->timeout_task); occ->timeout_task = - GNUNET_SCHEDULER_add_delayed (GST_timeout, - &timeout_overlay_connect, - occ); + GNUNET_SCHEDULER_add_delayed(GST_timeout, + &timeout_overlay_connect, + occ); switch (occ->type) - { - case OCC_TYPE_REMOTE_LATERAL: - GNUNET_asprintf (&occ->emsg, - "0x%llx: Timeout while acquiring connection to peer %u's " - "host: %u\n", - occ->op_id, - occ->other_peer_id, - peer2_host_id); - occ->p2ctx.remote.ncn - = GST_neighbour_get_connection (p2n, - &p2_controller_connect_cb, - occ); - break; - case OCC_TYPE_REMOTE_SLAVE: - p2_controller_connect_cb (occ, - occ->p2ctx.remote.p2c); - break; - case OCC_TYPE_LOCAL: - peer2 = GST_peer_list[occ->other_peer_id]; - peer2->reference_cnt++; - GNUNET_TESTING_peer_get_identity (peer2->details.local.peer, - &occ->other_peer_identity); - GNUNET_asprintf (&occ->emsg, - "0x%llx: Timeout while connecting to CORE of peer with " - "id: %u", - occ->op_id, - occ->peer->id); - occ->cgh_ch = - GST_connection_pool_get_handle (occ->peer->id, - occ->peer->details.local.cfg, - GST_CONNECTIONPOOL_SERVICE_CORE, - occ_cache_get_handle_core_cb, occ, - &occ->other_peer_identity, - &overlay_connect_notify, occ); - break; - } - GNUNET_SERVICE_client_continue (client); + { + case OCC_TYPE_REMOTE_LATERAL: + GNUNET_asprintf(&occ->emsg, + "0x%llx: Timeout while acquiring connection to peer %u's " + "host: %u\n", + occ->op_id, + occ->other_peer_id, + peer2_host_id); + occ->p2ctx.remote.ncn + = GST_neighbour_get_connection(p2n, + &p2_controller_connect_cb, + occ); + break; + + case OCC_TYPE_REMOTE_SLAVE: + p2_controller_connect_cb(occ, + occ->p2ctx.remote.p2c); + break; + + case OCC_TYPE_LOCAL: + peer2 = GST_peer_list[occ->other_peer_id]; + peer2->reference_cnt++; + GNUNET_TESTING_peer_get_identity(peer2->details.local.peer, + &occ->other_peer_identity); + GNUNET_asprintf(&occ->emsg, + "0x%llx: Timeout while connecting to CORE of peer with " + "id: %u", + occ->op_id, + occ->peer->id); + occ->cgh_ch = + GST_connection_pool_get_handle(occ->peer->id, + occ->peer->details.local.cfg, + GST_CONNECTIONPOOL_SERVICE_CORE, + occ_cache_get_handle_core_cb, occ, + &occ->other_peer_identity, + &overlay_connect_notify, occ); + break; + } + GNUNET_SERVICE_client_continue(client); } @@ -1648,30 +1642,30 @@ handle_overlay_connect (void *cls, * @param rocc the RemoteOverlayConnectCtx */ static void -cleanup_rocc (struct RemoteOverlayConnectCtx *rocc) +cleanup_rocc(struct RemoteOverlayConnectCtx *rocc) { - LOG_DEBUG ("0x%llx: Cleaning up rocc\n", - rocc->op_id); + LOG_DEBUG("0x%llx: Cleaning up rocc\n", + rocc->op_id); if (NULL != rocc->attempt_connect_task_id) - GNUNET_SCHEDULER_cancel (rocc->attempt_connect_task_id); + GNUNET_SCHEDULER_cancel(rocc->attempt_connect_task_id); if (NULL != rocc->timeout_rocc_task_id) - GNUNET_SCHEDULER_cancel (rocc->timeout_rocc_task_id); + GNUNET_SCHEDULER_cancel(rocc->timeout_rocc_task_id); if (NULL != rocc->ohh) - GNUNET_TRANSPORT_offer_hello_cancel (rocc->ohh); + GNUNET_TRANSPORT_offer_hello_cancel(rocc->ohh); if (NULL != rocc->tcc.csh) - GNUNET_ATS_connectivity_suggest_cancel (rocc->tcc.csh); - GST_connection_pool_get_handle_done (rocc->tcc.cgh_p2_th); - GST_connection_pool_get_handle_done (rocc->tcc.cgh_p2_ats); - GNUNET_assert (rocc->peer->reference_cnt > 0); + GNUNET_ATS_connectivity_suggest_cancel(rocc->tcc.csh); + GST_connection_pool_get_handle_done(rocc->tcc.cgh_p2_th); + GST_connection_pool_get_handle_done(rocc->tcc.cgh_p2_ats); + GNUNET_assert(rocc->peer->reference_cnt > 0); rocc->peer->reference_cnt--; if ((GNUNET_YES == rocc->peer->destroy_flag) && (0 == rocc->peer->reference_cnt)) - GST_destroy_peer (rocc->peer); - GNUNET_free_non_null (rocc->hello); - GNUNET_CONTAINER_DLL_remove (roccq_head, - roccq_tail, - rocc); - GNUNET_free (rocc); + GST_destroy_peer(rocc->peer); + GNUNET_free_non_null(rocc->hello); + GNUNET_CONTAINER_DLL_remove(roccq_head, + roccq_tail, + rocc); + GNUNET_free(rocc); } @@ -1681,15 +1675,15 @@ cleanup_rocc (struct RemoteOverlayConnectCtx *rocc) * @param cls the RemoteOverlayConnectCtx */ static void -timeout_rocc_task (void *cls) +timeout_rocc_task(void *cls) { struct RemoteOverlayConnectCtx *rocc = cls; - GNUNET_assert (rocc->timeout_rocc_task_id != NULL); + GNUNET_assert(rocc->timeout_rocc_task_id != NULL); rocc->timeout_rocc_task_id = NULL; - LOG_DEBUG ("0x%llx: rocc timed out\n", - rocc->op_id); - cleanup_rocc (rocc); + LOG_DEBUG("0x%llx: rocc timed out\n", + rocc->op_id); + cleanup_rocc(rocc); } @@ -1701,20 +1695,20 @@ timeout_rocc_task (void *cls) * @param new_peer the peer that connected */ static void -cache_transport_peer_connect_notify (void *cls, - const struct GNUNET_PeerIdentity *new_peer) +cache_transport_peer_connect_notify(void *cls, + const struct GNUNET_PeerIdentity *new_peer) { struct RemoteOverlayConnectCtx *rocc = cls; - LOG_DEBUG ("0x%llx: Request Overlay connect notify\n", - rocc->op_id); - GNUNET_assert (0 == - memcmp (new_peer, &rocc->a_id, - sizeof (struct GNUNET_PeerIdentity))); - LOG_DEBUG ("0x%llx: Peer %s connected\n", - rocc->op_id, - GNUNET_i2s (&rocc->a_id)); - cleanup_rocc (rocc); + LOG_DEBUG("0x%llx: Request Overlay connect notify\n", + rocc->op_id); + GNUNET_assert(0 == + memcmp(new_peer, &rocc->a_id, + sizeof(struct GNUNET_PeerIdentity))); + LOG_DEBUG("0x%llx: Peer %s connected\n", + rocc->op_id, + GNUNET_i2s(&rocc->a_id)); + cleanup_rocc(rocc); } @@ -1725,7 +1719,7 @@ cache_transport_peer_connect_notify (void *cls, * @param cls the RemoteOverlayConnectCtx */ static void -attempt_connect_task (void *cls); +attempt_connect_task(void *cls); /** @@ -1736,22 +1730,22 @@ attempt_connect_task (void *cls); * @param cls the overlay connect context */ static void -rocc_hello_sent_cb (void *cls) +rocc_hello_sent_cb(void *cls) { struct RemoteOverlayConnectCtx *rocc = cls; rocc->ohh = NULL; - GNUNET_assert (NULL == rocc->attempt_connect_task_id); - LOG_DEBUG ("0x%llx: HELLO of peer %s delivered to local peer with id: %u\n", - rocc->op_id, - GNUNET_i2s (&rocc->a_id), - rocc->peer->id); + GNUNET_assert(NULL == rocc->attempt_connect_task_id); + LOG_DEBUG("0x%llx: HELLO of peer %s delivered to local peer with id: %u\n", + rocc->op_id, + GNUNET_i2s(&rocc->a_id), + rocc->peer->id); rocc->tcc.cgh_p2_ats = - GST_connection_pool_get_handle (rocc->peer->id, - rocc->peer->details.local.cfg, - GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY, - &occ_cache_get_handle_ats_rocc_cb, - rocc, NULL, NULL, NULL); + GST_connection_pool_get_handle(rocc->peer->id, + rocc->peer->details.local.cfg, + GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY, + &occ_cache_get_handle_ats_rocc_cb, + rocc, NULL, NULL, NULL); } @@ -1762,29 +1756,29 @@ rocc_hello_sent_cb (void *cls) * @param cls the RemoteOverlayConnectCtx */ static void -attempt_connect_task (void *cls) +attempt_connect_task(void *cls) { struct RemoteOverlayConnectCtx *rocc = cls; - GNUNET_assert (NULL != rocc->attempt_connect_task_id); + GNUNET_assert(NULL != rocc->attempt_connect_task_id); rocc->attempt_connect_task_id = NULL; - LOG_DEBUG ("0x%llx: Offering HELLO of peer %s to remote peer with id: %u\n", - rocc->op_id, - GNUNET_i2s (&rocc->a_id), - rocc->peer->id); + LOG_DEBUG("0x%llx: Offering HELLO of peer %s to remote peer with id: %u\n", + rocc->op_id, + GNUNET_i2s(&rocc->a_id), + rocc->peer->id); rocc->ohh = - GNUNET_TRANSPORT_offer_hello (rocc->tcc.cfg, - rocc->hello, - &rocc_hello_sent_cb, - rocc); + GNUNET_TRANSPORT_offer_hello(rocc->tcc.cfg, + rocc->hello, + &rocc_hello_sent_cb, + rocc); if (NULL == rocc->ohh) rocc->attempt_connect_task_id = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_MILLISECONDS, - 100 + - GNUNET_CRYPTO_random_u32 + GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_MILLISECONDS, + 100 + + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 500)), - &attempt_connect_task, rocc); + &attempt_connect_task, rocc); } @@ -1798,36 +1792,36 @@ attempt_connect_task (void *cls) * @param ignore_ peer identity which is ignored in this callback */ static void -rocc_cache_get_handle_transport_cb (void *cls, - struct GNUNET_CORE_Handle *ch, - struct GNUNET_TRANSPORT_CoreHandle *th, - struct GNUNET_ATS_ConnectivityHandle *ac, - const struct GNUNET_PeerIdentity *ignore_, - const struct GNUNET_CONFIGURATION_Handle *cfg) +rocc_cache_get_handle_transport_cb(void *cls, + struct GNUNET_CORE_Handle *ch, + struct GNUNET_TRANSPORT_CoreHandle *th, + struct GNUNET_ATS_ConnectivityHandle *ac, + const struct GNUNET_PeerIdentity *ignore_, + const struct GNUNET_CONFIGURATION_Handle *cfg) { struct RemoteOverlayConnectCtx *rocc = cls; if (NULL == th) - { - rocc->timeout_rocc_task_id = - GNUNET_SCHEDULER_add_now (&timeout_rocc_task, rocc); - return; - } + { + rocc->timeout_rocc_task_id = + GNUNET_SCHEDULER_add_now(&timeout_rocc_task, rocc); + return; + } rocc->tcc.th_ = th; rocc->tcc.cfg = cfg; if (NULL != - GNUNET_TRANSPORT_core_get_mq (rocc->tcc.th_, - &rocc->a_id)) - { - LOG_DEBUG ("0x%llx: Target peer %s already connected to local peer: %u\n", - rocc->op_id, - GNUNET_i2s (&rocc->a_id), - rocc->peer->id); - cleanup_rocc (rocc); - return; - } + GNUNET_TRANSPORT_core_get_mq(rocc->tcc.th_, + &rocc->a_id)) + { + LOG_DEBUG("0x%llx: Target peer %s already connected to local peer: %u\n", + rocc->op_id, + GNUNET_i2s(&rocc->a_id), + rocc->peer->id); + cleanup_rocc(rocc); + return; + } rocc->attempt_connect_task_id = - GNUNET_SCHEDULER_add_now (&attempt_connect_task, rocc); + GNUNET_SCHEDULER_add_now(&attempt_connect_task, rocc); } @@ -1839,32 +1833,32 @@ rocc_cache_get_handle_transport_cb (void *cls, * @return #GNUNET_OK if @a msg is well-formed */ int -check_remote_overlay_connect (void *cls, - const struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg) +check_remote_overlay_connect(void *cls, + const struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg) { uint32_t peer_id; uint16_t msize; uint16_t hsize; - msize = ntohs (msg->header.size); - if (GNUNET_MESSAGE_TYPE_HELLO != ntohs (msg->hello->type)) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - hsize = ntohs (msg->hello->size); - if ((sizeof (struct GNUNET_TESTBED_RemoteOverlayConnectMessage) + hsize) != msize) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - peer_id = ntohl (msg->peer); + msize = ntohs(msg->header.size); + if (GNUNET_MESSAGE_TYPE_HELLO != ntohs(msg->hello->type)) + { + GNUNET_break(0); + return GNUNET_SYSERR; + } + hsize = ntohs(msg->hello->size); + if ((sizeof(struct GNUNET_TESTBED_RemoteOverlayConnectMessage) + hsize) != msize) + { + GNUNET_break(0); + return GNUNET_SYSERR; + } + peer_id = ntohl(msg->peer); if ((peer_id >= GST_peer_list_size) || (NULL == GST_peer_list[peer_id])) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -1876,8 +1870,8 @@ check_remote_overlay_connect (void *cls, * @param msg the actual message */ void -handle_remote_overlay_connect (void *cls, - const struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg) +handle_remote_overlay_connect(void *cls, + const struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg) { struct GNUNET_SERVICE_Client *client = cls; struct RemoteOverlayConnectCtx *rocc; @@ -1887,55 +1881,55 @@ handle_remote_overlay_connect (void *cls, uint32_t peer_id; uint16_t hsize; - hsize = ntohs (msg->hello->size); - peer_id = ntohl (msg->peer); + hsize = ntohs(msg->hello->size); + peer_id = ntohl(msg->peer); peer = GST_peer_list[peer_id]; if (GNUNET_YES == peer->is_remote) - { - struct GNUNET_MessageHeader *msg2; + { + struct GNUNET_MessageHeader *msg2; - msg2 = GNUNET_copy_message (&msg->header); - GNUNET_TESTBED_queue_message_ (peer->details.remote.slave->controller, - msg2); - GNUNET_SERVICE_client_continue (client); - return; - } - rocc = GNUNET_new (struct RemoteOverlayConnectCtx); - rocc->op_id = GNUNET_ntohll (msg->operation_id); - GNUNET_CONTAINER_DLL_insert_tail (roccq_head, - roccq_tail, - rocc); + msg2 = GNUNET_copy_message(&msg->header); + GNUNET_TESTBED_queue_message_(peer->details.remote.slave->controller, + msg2); + GNUNET_SERVICE_client_continue(client); + return; + } + rocc = GNUNET_new(struct RemoteOverlayConnectCtx); + rocc->op_id = GNUNET_ntohll(msg->operation_id); + GNUNET_CONTAINER_DLL_insert_tail(roccq_head, + roccq_tail, + rocc); rocc->a_id = msg->peer_identity; - GNUNET_TESTING_peer_get_identity (peer->details.local.peer, - &pid); - (void) GNUNET_strlcpy (pid_str, - GNUNET_i2s (&pid), - sizeof (pid_str)); - LOG_DEBUG ("0x%llx: Remote overlay connect %s to peer %s with hello size: %u\n", - rocc->op_id, - pid_str, - GNUNET_i2s (&rocc->a_id), - hsize); + GNUNET_TESTING_peer_get_identity(peer->details.local.peer, + &pid); + (void)GNUNET_strlcpy(pid_str, + GNUNET_i2s(&pid), + sizeof(pid_str)); + LOG_DEBUG("0x%llx: Remote overlay connect %s to peer %s with hello size: %u\n", + rocc->op_id, + pid_str, + GNUNET_i2s(&rocc->a_id), + hsize); rocc->peer = peer; rocc->peer->reference_cnt++; - rocc->hello = GNUNET_malloc (hsize); - GNUNET_memcpy (rocc->hello, - msg->hello, - hsize); + rocc->hello = GNUNET_malloc(hsize); + GNUNET_memcpy(rocc->hello, + msg->hello, + hsize); rocc->tcc.cgh_p2_th = - GST_connection_pool_get_handle (peer_id, - rocc->peer->details.local.cfg, - GST_CONNECTIONPOOL_SERVICE_TRANSPORT, - &rocc_cache_get_handle_transport_cb, - rocc, - &rocc->a_id, - &cache_transport_peer_connect_notify, - rocc); + GST_connection_pool_get_handle(peer_id, + rocc->peer->details.local.cfg, + GST_CONNECTIONPOOL_SERVICE_TRANSPORT, + &rocc_cache_get_handle_transport_cb, + rocc, + &rocc->a_id, + &cache_transport_peer_connect_notify, + rocc); rocc->timeout_rocc_task_id = - GNUNET_SCHEDULER_add_delayed (GST_timeout, - &timeout_rocc_task, - rocc); - GNUNET_SERVICE_client_continue (client); + GNUNET_SCHEDULER_add_delayed(GST_timeout, + &timeout_rocc_task, + rocc); + GNUNET_SERVICE_client_continue(client); } @@ -1943,12 +1937,12 @@ handle_remote_overlay_connect (void *cls, * Clears all pending overlay connect contexts in queue */ void -GST_free_occq () +GST_free_occq() { struct OverlayConnectContext *occ; while (NULL != (occ = occq_head)) - cleanup_occ (occ); + cleanup_occ(occ); } @@ -1956,10 +1950,10 @@ GST_free_occq () * Clears all pending remote overlay connect contexts in queue */ void -GST_free_roccq () +GST_free_roccq() { struct RemoteOverlayConnectCtx *rocc; while (NULL != (rocc = roccq_head)) - cleanup_rocc (rocc); + cleanup_rocc(rocc); } diff --git a/src/testbed/gnunet-service-testbed_peers.c b/src/testbed/gnunet-service-testbed_peers.c index b88812e7e..743c7e849 100644 --- a/src/testbed/gnunet-service-testbed_peers.c +++ b/src/testbed/gnunet-service-testbed_peers.c @@ -1,22 +1,22 @@ /* - This file is part of GNUnet. - Copyright (C) 2008--2013, 2016 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 . + This file is part of GNUnet. + Copyright (C) 2008--2013, 2016 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 -*/ + */ /** @@ -44,8 +44,7 @@ unsigned int GST_num_local_peers; /** * Context information to manage peers' services */ -struct ManageServiceContext -{ +struct ManageServiceContext { /** * DLL next ptr */ @@ -97,8 +96,7 @@ struct ManageServiceContext /** * Context information for peer re-configure operations */ -struct PeerReconfigureContext -{ +struct PeerReconfigureContext { /** * DLL next for inclusoin in peer reconfigure operations list */ @@ -166,11 +164,11 @@ static struct ManageServiceContext *mctx_tail; * @param peer the peer to add */ static void -peer_list_add (struct Peer *peer) +peer_list_add(struct Peer *peer) { if (peer->id >= GST_peer_list_size) - GST_array_grow_large_enough (GST_peer_list, GST_peer_list_size, peer->id); - GNUNET_assert (NULL == GST_peer_list[peer->id]); + GST_array_grow_large_enough(GST_peer_list, GST_peer_list_size, peer->id); + GNUNET_assert(NULL == GST_peer_list[peer->id]); GST_peer_list[peer->id] = peer; if (GNUNET_NO == peer->is_remote) GST_num_local_peers++; @@ -183,7 +181,7 @@ peer_list_add (struct Peer *peer) * @param peer the peer to be removed */ static void -peer_list_remove (struct Peer *peer) +peer_list_remove(struct Peer *peer) { unsigned int orig_size; uint32_t id; @@ -193,21 +191,21 @@ peer_list_remove (struct Peer *peer) GST_peer_list[peer->id] = NULL; orig_size = GST_peer_list_size; while (GST_peer_list_size >= LIST_GROW_STEP) - { - for (id = GST_peer_list_size - 1; - (id >= GST_peer_list_size - LIST_GROW_STEP) && (id != UINT32_MAX); - id--) - if (NULL != GST_peer_list[id]) + { + for (id = GST_peer_list_size - 1; + (id >= GST_peer_list_size - LIST_GROW_STEP) && (id != UINT32_MAX); + id--) + if (NULL != GST_peer_list[id]) + break; + if (id != ((GST_peer_list_size - LIST_GROW_STEP) - 1)) break; - if (id != ((GST_peer_list_size - LIST_GROW_STEP) - 1)) - break; - GST_peer_list_size -= LIST_GROW_STEP; - } + GST_peer_list_size -= LIST_GROW_STEP; + } if (orig_size == GST_peer_list_size) return; GST_peer_list = - GNUNET_realloc (GST_peer_list, - sizeof (struct Peer *) * GST_peer_list_size); + GNUNET_realloc(GST_peer_list, + sizeof(struct Peer *) * GST_peer_list_size); } @@ -218,12 +216,12 @@ peer_list_remove (struct Peer *peer) * @param cls the FowardedOperationContext */ static void -peer_create_forward_timeout (void *cls) +peer_create_forward_timeout(void *cls) { struct ForwardedOperationContext *fopc = cls; - GNUNET_free (fopc->cls); - GST_forwarded_operation_timeout (fopc); + GNUNET_free(fopc->cls); + GST_forwarded_operation_timeout(fopc); } @@ -235,19 +233,19 @@ peer_create_forward_timeout (void *cls) * @param msg the peer create success message */ static void -peer_create_success_cb (void *cls, const struct GNUNET_MessageHeader *msg) +peer_create_success_cb(void *cls, const struct GNUNET_MessageHeader *msg) { struct ForwardedOperationContext *fopc = cls; struct Peer *remote_peer; - if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS) - { - GNUNET_assert (NULL != fopc->cls); - remote_peer = fopc->cls; - peer_list_add (remote_peer); - } - GST_forwarded_operation_reply_relay (fopc, - msg); + if (ntohs(msg->type) == GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS) + { + GNUNET_assert(NULL != fopc->cls); + remote_peer = fopc->cls; + peer_list_add(remote_peer); + } + GST_forwarded_operation_reply_relay(fopc, + msg); } @@ -257,24 +255,24 @@ peer_create_success_cb (void *cls, const struct GNUNET_MessageHeader *msg) * @param peer the peer structure to destroy */ void -GST_destroy_peer (struct Peer *peer) +GST_destroy_peer(struct Peer *peer) { - GNUNET_break (0 == peer->reference_cnt); + GNUNET_break(0 == peer->reference_cnt); if (GNUNET_YES == peer->is_remote) - { - peer_list_remove (peer); - GNUNET_free (peer); - return; - } + { + peer_list_remove(peer); + GNUNET_free(peer); + return; + } if (GNUNET_YES == peer->details.local.is_running) - { - GNUNET_TESTING_peer_stop (peer->details.local.peer); - peer->details.local.is_running = GNUNET_NO; - } - GNUNET_TESTING_peer_destroy (peer->details.local.peer); - GNUNET_CONFIGURATION_destroy (peer->details.local.cfg); - peer_list_remove (peer); - GNUNET_free (peer); + { + GNUNET_TESTING_peer_stop(peer->details.local.peer); + peer->details.local.is_running = GNUNET_NO; + } + GNUNET_TESTING_peer_destroy(peer->details.local.peer); + GNUNET_CONFIGURATION_destroy(peer->details.local.cfg); + peer_list_remove(peer); + GNUNET_free(peer); } @@ -284,20 +282,20 @@ GST_destroy_peer (struct Peer *peer) * @param mctx the ManageServiceContext */ static void -cleanup_mctx (struct ManageServiceContext *mctx) +cleanup_mctx(struct ManageServiceContext *mctx) { mctx->expired = GNUNET_YES; - GNUNET_CONTAINER_DLL_remove (mctx_head, - mctx_tail, - mctx); - GNUNET_ARM_disconnect (mctx->ah); - GNUNET_assert (0 < mctx->peer->reference_cnt); + GNUNET_CONTAINER_DLL_remove(mctx_head, + mctx_tail, + mctx); + GNUNET_ARM_disconnect(mctx->ah); + GNUNET_assert(0 < mctx->peer->reference_cnt); mctx->peer->reference_cnt--; - if ( (GNUNET_YES == mctx->peer->destroy_flag) && - (0 == mctx->peer->reference_cnt) ) - GST_destroy_peer (mctx->peer); - GNUNET_free (mctx->service); - GNUNET_free (mctx); + if ((GNUNET_YES == mctx->peer->destroy_flag) && + (0 == mctx->peer->reference_cnt)) + GST_destroy_peer(mctx->peer); + GNUNET_free(mctx->service); + GNUNET_free(mctx); } @@ -308,10 +306,10 @@ cleanup_mctx (struct ManageServiceContext *mctx) * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure */ static int -stop_peer (struct Peer *peer) +stop_peer(struct Peer *peer) { - GNUNET_assert (GNUNET_NO == peer->is_remote); - if (GNUNET_OK != GNUNET_TESTING_peer_kill (peer->details.local.peer)) + GNUNET_assert(GNUNET_NO == peer->is_remote); + if (GNUNET_OK != GNUNET_TESTING_peer_kill(peer->details.local.peer)) return GNUNET_SYSERR; peer->details.local.is_running = GNUNET_NO; return GNUNET_OK; @@ -324,25 +322,25 @@ stop_peer (struct Peer *peer) * @param prc the PeerReconfigureContext */ static void -cleanup_prc (struct PeerReconfigureContext *prc) +cleanup_prc(struct PeerReconfigureContext *prc) { struct Peer *peer; - if (VALID_PEER_ID (prc->peer_id)) - { - peer = GST_peer_list [prc->peer_id]; - if (1 != prc->stopped) + if (VALID_PEER_ID(prc->peer_id)) { - GNUNET_TESTING_peer_stop_async_cancel (peer->details.local.peer); - stop_peer (peer); /* Stop the peer synchronously */ + peer = GST_peer_list [prc->peer_id]; + if (1 != prc->stopped) + { + GNUNET_TESTING_peer_stop_async_cancel(peer->details.local.peer); + stop_peer(peer); /* Stop the peer synchronously */ + } } - } if (NULL != prc->cfg) - GNUNET_CONFIGURATION_destroy (prc->cfg); - GNUNET_CONTAINER_DLL_remove (prc_head, - prc_tail, - prc); - GNUNET_free (prc); + GNUNET_CONFIGURATION_destroy(prc->cfg); + GNUNET_CONTAINER_DLL_remove(prc_head, + prc_tail, + prc); + GNUNET_free(prc); } @@ -352,7 +350,7 @@ cleanup_prc (struct PeerReconfigureContext *prc) * @param client the client that disconnected */ void -GST_notify_client_disconnect_peers (struct GNUNET_SERVICE_Client *client) +GST_notify_client_disconnect_peers(struct GNUNET_SERVICE_Client *client) { struct ForwardedOperationContext *fopc; struct ForwardedOperationContext *fopcn; @@ -362,28 +360,28 @@ GST_notify_client_disconnect_peers (struct GNUNET_SERVICE_Client *client) struct PeerReconfigureContext *prcn; for (fopc = fopcq_head; NULL != fopc; fopc = fopcn) - { - fopcn = fopc->next; - if (client == fopc->client) { - if (OP_PEER_CREATE == fopc->type) - GNUNET_free (fopc->cls); - GNUNET_SCHEDULER_cancel (fopc->timeout_task); - GST_forwarded_operation_timeout (fopc); + fopcn = fopc->next; + if (client == fopc->client) + { + if (OP_PEER_CREATE == fopc->type) + GNUNET_free(fopc->cls); + GNUNET_SCHEDULER_cancel(fopc->timeout_task); + GST_forwarded_operation_timeout(fopc); + } } - } for (mctx = mctx_head; NULL != mctx; mctx = mctxn) - { - mctxn = mctx->next; - if (client == mctx->client) - cleanup_mctx (mctx); - } + { + mctxn = mctx->next; + if (client == mctx->client) + cleanup_mctx(mctx); + } for (prc = prc_head; NULL != prc; prc = prcn) - { - prcn = prc->next; - if (client == prc->client) - cleanup_prc (prc); - } + { + prcn = prc->next; + if (client == prc->client) + cleanup_prc(prc); + } } @@ -395,22 +393,22 @@ GST_notify_client_disconnect_peers (struct GNUNET_SERVICE_Client *client) * @param msg the peer create success message */ static void -peer_destroy_success_cb (void *cls, const struct GNUNET_MessageHeader *msg) +peer_destroy_success_cb(void *cls, const struct GNUNET_MessageHeader *msg) { struct ForwardedOperationContext *fopc = cls; struct Peer *remote_peer; if (GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS == - ntohs (msg->type)) - { - remote_peer = fopc->cls; - GNUNET_assert (NULL != remote_peer); - remote_peer->destroy_flag = GNUNET_YES; - if (0 == remote_peer->reference_cnt) - GST_destroy_peer (remote_peer); - } - GST_forwarded_operation_reply_relay (fopc, - msg); + ntohs(msg->type)) + { + remote_peer = fopc->cls; + GNUNET_assert(NULL != remote_peer); + remote_peer->destroy_flag = GNUNET_YES; + if (0 == remote_peer->reference_cnt) + GST_destroy_peer(remote_peer); + } + GST_forwarded_operation_reply_relay(fopc, + msg); } @@ -422,8 +420,8 @@ peer_destroy_success_cb (void *cls, const struct GNUNET_MessageHeader *msg) * @return #GNUNET_OK if @a msg is well-formed */ int -check_peer_create (void *cls, - const struct GNUNET_TESTBED_PeerCreateMessage *msg) +check_peer_create(void *cls, + const struct GNUNET_TESTBED_PeerCreateMessage *msg) { return GNUNET_OK; /* checked later */ } @@ -436,8 +434,8 @@ check_peer_create (void *cls, * @param msg the actual message */ void -handle_peer_create (void *cls, - const struct GNUNET_TESTBED_PeerCreateMessage *msg) +handle_peer_create(void *cls, + const struct GNUNET_TESTBED_PeerCreateMessage *msg) { struct GNUNET_SERVICE_Client *client = cls; struct GNUNET_MQ_Envelope *env; @@ -450,114 +448,114 @@ handle_peer_create (void *cls, uint32_t host_id; uint32_t peer_id; - host_id = ntohl (msg->host_id); - peer_id = ntohl (msg->peer_id); - if (VALID_PEER_ID (peer_id)) - { - (void) GNUNET_asprintf (&emsg, + host_id = ntohl(msg->host_id); + peer_id = ntohl(msg->peer_id); + if (VALID_PEER_ID(peer_id)) + { + (void)GNUNET_asprintf(&emsg, "Peer with ID %u already exists", peer_id); - GST_send_operation_fail_msg (client, - GNUNET_ntohll (msg->operation_id), - emsg); - GNUNET_free (emsg); - GNUNET_SERVICE_client_continue (client); - return; - } + GST_send_operation_fail_msg(client, + GNUNET_ntohll(msg->operation_id), + emsg); + GNUNET_free(emsg); + GNUNET_SERVICE_client_continue(client); + return; + } if (UINT32_MAX == peer_id) - { - GST_send_operation_fail_msg (client, - GNUNET_ntohll (msg->operation_id), - "Cannot create peer with given ID"); - GNUNET_SERVICE_client_continue (client); - return; - } - if (host_id == GST_context->host_id) - { - /* We are responsible for this peer */ - cfg = GNUNET_TESTBED_extract_config_ (&msg->header); - if (NULL == cfg) { - GNUNET_break (0); - GNUNET_SERVICE_client_drop (client); + GST_send_operation_fail_msg(client, + GNUNET_ntohll(msg->operation_id), + "Cannot create peer with given ID"); + GNUNET_SERVICE_client_continue(client); return; } - GNUNET_CONFIGURATION_set_value_number (cfg, - "TESTBED", - "PEERID", - (unsigned long long) peer_id); - - GNUNET_CONFIGURATION_set_value_number (cfg, - "PATHS", - "PEERID", - (unsigned long long) peer_id); - peer = GNUNET_new (struct Peer); - peer->is_remote = GNUNET_NO; - peer->details.local.cfg = cfg; - peer->id = peer_id; - LOG_DEBUG ("Creating peer with id: %u\n", - (unsigned int) peer->id); - peer->details.local.peer = - GNUNET_TESTING_peer_configure (GST_context->system, - peer->details.local.cfg, peer->id, - NULL /* Peer id */ , - &emsg); - if (NULL == peer->details.local.peer) + if (host_id == GST_context->host_id) { - LOG (GNUNET_ERROR_TYPE_WARNING, - "Configuring peer failed: %s\n", - emsg); - GNUNET_free (emsg); - GNUNET_free (peer); - GNUNET_break (0); - GNUNET_SERVICE_client_drop (client); + /* We are responsible for this peer */ + cfg = GNUNET_TESTBED_extract_config_(&msg->header); + if (NULL == cfg) + { + GNUNET_break(0); + GNUNET_SERVICE_client_drop(client); + return; + } + GNUNET_CONFIGURATION_set_value_number(cfg, + "TESTBED", + "PEERID", + (unsigned long long)peer_id); + + GNUNET_CONFIGURATION_set_value_number(cfg, + "PATHS", + "PEERID", + (unsigned long long)peer_id); + peer = GNUNET_new(struct Peer); + peer->is_remote = GNUNET_NO; + peer->details.local.cfg = cfg; + peer->id = peer_id; + LOG_DEBUG("Creating peer with id: %u\n", + (unsigned int)peer->id); + peer->details.local.peer = + GNUNET_TESTING_peer_configure(GST_context->system, + peer->details.local.cfg, peer->id, + NULL /* Peer id */, + &emsg); + if (NULL == peer->details.local.peer) + { + LOG(GNUNET_ERROR_TYPE_WARNING, + "Configuring peer failed: %s\n", + emsg); + GNUNET_free(emsg); + GNUNET_free(peer); + GNUNET_break(0); + GNUNET_SERVICE_client_drop(client); + return; + } + peer->details.local.is_running = GNUNET_NO; + peer_list_add(peer); + env = GNUNET_MQ_msg(reply, + GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS); + reply->peer_id = msg->peer_id; + reply->operation_id = msg->operation_id; + GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), + env); + GNUNET_SERVICE_client_continue(client); return; } - peer->details.local.is_running = GNUNET_NO; - peer_list_add (peer); - env = GNUNET_MQ_msg (reply, - GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS); - reply->peer_id = msg->peer_id; - reply->operation_id = msg->operation_id; - GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), - env); - GNUNET_SERVICE_client_continue (client); - return; - } /* Forward peer create request */ - route = GST_find_dest_route (host_id); + route = GST_find_dest_route(host_id); if (NULL == route) - { - GNUNET_break (0); - GNUNET_SERVICE_client_continue (client); // ? - return; - } - peer = GNUNET_new (struct Peer); + { + GNUNET_break(0); + GNUNET_SERVICE_client_continue(client); // ? + return; + } + peer = GNUNET_new(struct Peer); peer->is_remote = GNUNET_YES; peer->id = peer_id; peer->details.remote.slave = GST_slave_list[route->dest]; peer->details.remote.remote_host_id = host_id; - fo_ctxt = GNUNET_new (struct ForwardedOperationContext); + fo_ctxt = GNUNET_new(struct ForwardedOperationContext); fo_ctxt->client = client; - fo_ctxt->operation_id = GNUNET_ntohll (msg->operation_id); + fo_ctxt->operation_id = GNUNET_ntohll(msg->operation_id); fo_ctxt->cls = peer; fo_ctxt->type = OP_PEER_CREATE; fo_ctxt->opc = - GNUNET_TESTBED_forward_operation_msg_ (GST_slave_list - [route->dest]->controller, - fo_ctxt->operation_id, - &msg->header, - &peer_create_success_cb, - fo_ctxt); + GNUNET_TESTBED_forward_operation_msg_(GST_slave_list + [route->dest]->controller, + fo_ctxt->operation_id, + &msg->header, + &peer_create_success_cb, + fo_ctxt); fo_ctxt->timeout_task = - GNUNET_SCHEDULER_add_delayed (GST_timeout, - &peer_create_forward_timeout, - fo_ctxt); - GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, - fopcq_tail, - fo_ctxt); - GNUNET_SERVICE_client_continue (client); + GNUNET_SCHEDULER_add_delayed(GST_timeout, + &peer_create_forward_timeout, + fo_ctxt); + GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, + fopcq_tail, + fo_ctxt); + GNUNET_SERVICE_client_continue(client); } @@ -568,63 +566,63 @@ handle_peer_create (void *cls, * @param msg the actual message */ void -handle_peer_destroy (void *cls, - const struct GNUNET_TESTBED_PeerDestroyMessage *msg) +handle_peer_destroy(void *cls, + const struct GNUNET_TESTBED_PeerDestroyMessage *msg) { struct GNUNET_SERVICE_Client *client = cls; struct ForwardedOperationContext *fopc; struct Peer *peer; uint32_t peer_id; - peer_id = ntohl (msg->peer_id); - LOG_DEBUG ("Received peer destory on peer: %u and operation id: %llu\n", - (unsigned int) peer_id, - (unsigned long long) GNUNET_ntohll (msg->operation_id)); - if (!VALID_PEER_ID (peer_id)) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - "Asked to destroy a non existent peer with id: %u\n", peer_id); - GST_send_operation_fail_msg (client, - GNUNET_ntohll (msg->operation_id), - "Peer doesn't exist"); - GNUNET_SERVICE_client_continue (client); - return; - } + peer_id = ntohl(msg->peer_id); + LOG_DEBUG("Received peer destory on peer: %u and operation id: %llu\n", + (unsigned int)peer_id, + (unsigned long long)GNUNET_ntohll(msg->operation_id)); + if (!VALID_PEER_ID(peer_id)) + { + LOG(GNUNET_ERROR_TYPE_ERROR, + "Asked to destroy a non existent peer with id: %u\n", peer_id); + GST_send_operation_fail_msg(client, + GNUNET_ntohll(msg->operation_id), + "Peer doesn't exist"); + GNUNET_SERVICE_client_continue(client); + return; + } peer = GST_peer_list[peer_id]; if (GNUNET_YES == peer->is_remote) - { - /* Forward the destory message to sub controller */ - fopc = GNUNET_new (struct ForwardedOperationContext); - fopc->client = client; - fopc->cls = peer; - fopc->type = OP_PEER_DESTROY; - fopc->operation_id = GNUNET_ntohll (msg->operation_id); - fopc->opc = - GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote. - slave->controller, - fopc->operation_id, - &msg->header, - &peer_destroy_success_cb, - fopc); - fopc->timeout_task = - GNUNET_SCHEDULER_add_delayed (GST_timeout, - &GST_forwarded_operation_timeout, - fopc); - GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, - fopcq_tail, - fopc); - GNUNET_SERVICE_client_continue (client); - return; - } + { + /* Forward the destory message to sub controller */ + fopc = GNUNET_new(struct ForwardedOperationContext); + fopc->client = client; + fopc->cls = peer; + fopc->type = OP_PEER_DESTROY; + fopc->operation_id = GNUNET_ntohll(msg->operation_id); + fopc->opc = + GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. + slave->controller, + fopc->operation_id, + &msg->header, + &peer_destroy_success_cb, + fopc); + fopc->timeout_task = + GNUNET_SCHEDULER_add_delayed(GST_timeout, + &GST_forwarded_operation_timeout, + fopc); + GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, + fopcq_tail, + fopc); + GNUNET_SERVICE_client_continue(client); + return; + } peer->destroy_flag = GNUNET_YES; if (0 == peer->reference_cnt) - GST_destroy_peer (peer); + GST_destroy_peer(peer); else - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Delaying peer destroy as peer is currently in use\n"); - GST_send_operation_success_msg (client, - GNUNET_ntohll (msg->operation_id)); - GNUNET_SERVICE_client_continue (client); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Delaying peer destroy as peer is currently in use\n"); + GST_send_operation_success_msg(client, + GNUNET_ntohll(msg->operation_id)); + GNUNET_SERVICE_client_continue(client); } @@ -635,10 +633,10 @@ handle_peer_destroy (void *cls, * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure */ static int -start_peer (struct Peer *peer) +start_peer(struct Peer *peer) { - GNUNET_assert (GNUNET_NO == peer->is_remote); - if (GNUNET_OK != GNUNET_TESTING_peer_start (peer->details.local.peer)) + GNUNET_assert(GNUNET_NO == peer->is_remote); + if (GNUNET_OK != GNUNET_TESTING_peer_start(peer->details.local.peer)) return GNUNET_SYSERR; peer->details.local.is_running = GNUNET_YES; return GNUNET_OK; @@ -652,8 +650,8 @@ start_peer (struct Peer *peer) * @param msg the actual message */ void -handle_peer_start (void *cls, - const struct GNUNET_TESTBED_PeerStartMessage *msg) +handle_peer_start(void *cls, + const struct GNUNET_TESTBED_PeerStartMessage *msg) { struct GNUNET_SERVICE_Client *client = cls; struct GNUNET_MQ_Envelope *env; @@ -662,55 +660,55 @@ handle_peer_start (void *cls, struct Peer *peer; uint32_t peer_id; - peer_id = ntohl (msg->peer_id); - if (! VALID_PEER_ID (peer_id)) - { - GNUNET_break (0); - LOG (GNUNET_ERROR_TYPE_ERROR, - "Asked to start a non existent peer with id: %u\n", - peer_id); - GNUNET_SERVICE_client_continue (client); - return; - } + peer_id = ntohl(msg->peer_id); + if (!VALID_PEER_ID(peer_id)) + { + GNUNET_break(0); + LOG(GNUNET_ERROR_TYPE_ERROR, + "Asked to start a non existent peer with id: %u\n", + peer_id); + GNUNET_SERVICE_client_continue(client); + return; + } peer = GST_peer_list[peer_id]; if (GNUNET_YES == peer->is_remote) - { - fopc = GNUNET_new (struct ForwardedOperationContext); - fopc->client = client; - fopc->operation_id = GNUNET_ntohll (msg->operation_id); - fopc->type = OP_PEER_START; - fopc->opc = - GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote. - slave->controller, - fopc->operation_id, &msg->header, - &GST_forwarded_operation_reply_relay, - fopc); - fopc->timeout_task = - GNUNET_SCHEDULER_add_delayed (GST_timeout, - &GST_forwarded_operation_timeout, - fopc); - GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, - fopcq_tail, - fopc); - GNUNET_SERVICE_client_continue (client); - return; - } - if (GNUNET_OK != start_peer (peer)) - { - GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id), - "Failed to start"); - GNUNET_SERVICE_client_continue (client); - return; - } - env = GNUNET_MQ_msg (reply, - GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT); - reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_START); - reply->host_id = htonl (GST_context->host_id); + { + fopc = GNUNET_new(struct ForwardedOperationContext); + fopc->client = client; + fopc->operation_id = GNUNET_ntohll(msg->operation_id); + fopc->type = OP_PEER_START; + fopc->opc = + GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. + slave->controller, + fopc->operation_id, &msg->header, + &GST_forwarded_operation_reply_relay, + fopc); + fopc->timeout_task = + GNUNET_SCHEDULER_add_delayed(GST_timeout, + &GST_forwarded_operation_timeout, + fopc); + GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, + fopcq_tail, + fopc); + GNUNET_SERVICE_client_continue(client); + return; + } + if (GNUNET_OK != start_peer(peer)) + { + GST_send_operation_fail_msg(client, GNUNET_ntohll(msg->operation_id), + "Failed to start"); + GNUNET_SERVICE_client_continue(client); + return; + } + env = GNUNET_MQ_msg(reply, + GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT); + reply->event_type = htonl(GNUNET_TESTBED_ET_PEER_START); + reply->host_id = htonl(GST_context->host_id); reply->peer_id = msg->peer_id; reply->operation_id = msg->operation_id; - GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), - env); - GNUNET_SERVICE_client_continue (client); + GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), + env); + GNUNET_SERVICE_client_continue(client); } @@ -721,8 +719,8 @@ handle_peer_start (void *cls, * @param msg the actual message */ void -handle_peer_stop (void *cls, - const struct GNUNET_TESTBED_PeerStopMessage *msg) +handle_peer_stop(void *cls, + const struct GNUNET_TESTBED_PeerStopMessage *msg) { struct GNUNET_SERVICE_Client *client = cls; struct GNUNET_MQ_Envelope *env; @@ -731,69 +729,69 @@ handle_peer_stop (void *cls, struct Peer *peer; uint32_t peer_id; - peer_id = ntohl (msg->peer_id); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Received PEER_STOP for peer %u\n", - (unsigned int) peer_id); - if (! VALID_PEER_ID (peer_id)) - { - GST_send_operation_fail_msg (client, - GNUNET_ntohll (msg->operation_id), - "Peer not found"); - GNUNET_SERVICE_client_continue (client); - return; - } + peer_id = ntohl(msg->peer_id); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Received PEER_STOP for peer %u\n", + (unsigned int)peer_id); + if (!VALID_PEER_ID(peer_id)) + { + GST_send_operation_fail_msg(client, + GNUNET_ntohll(msg->operation_id), + "Peer not found"); + GNUNET_SERVICE_client_continue(client); + return; + } peer = GST_peer_list[peer_id]; if (GNUNET_YES == peer->is_remote) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Forwarding PEER_STOP for peer %u\n", - (unsigned int) peer_id); - fopc = GNUNET_new (struct ForwardedOperationContext); - fopc->client = client; - fopc->operation_id = GNUNET_ntohll (msg->operation_id); - fopc->type = OP_PEER_STOP; - fopc->opc = - GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote. - slave->controller, - fopc->operation_id, - &msg->header, - &GST_forwarded_operation_reply_relay, - fopc); - fopc->timeout_task = - GNUNET_SCHEDULER_add_delayed (GST_timeout, - &GST_forwarded_operation_timeout, - fopc); - GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, - fopcq_tail, - fopc); - GNUNET_SERVICE_client_continue (client); - return; - } - if (GNUNET_OK != stop_peer (peer)) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - "Stopping peer %u failed\n", - (unsigned int) peer_id); - GST_send_operation_fail_msg (client, - GNUNET_ntohll (msg->operation_id), - "Peer not running"); - GNUNET_SERVICE_client_continue (client); - return; - } - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Peer %u successfully stopped\n", - (unsigned int) peer_id); - env = GNUNET_MQ_msg (reply, - GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT); - reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_STOP); - reply->host_id = htonl (GST_context->host_id); + { + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Forwarding PEER_STOP for peer %u\n", + (unsigned int)peer_id); + fopc = GNUNET_new(struct ForwardedOperationContext); + fopc->client = client; + fopc->operation_id = GNUNET_ntohll(msg->operation_id); + fopc->type = OP_PEER_STOP; + fopc->opc = + GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. + slave->controller, + fopc->operation_id, + &msg->header, + &GST_forwarded_operation_reply_relay, + fopc); + fopc->timeout_task = + GNUNET_SCHEDULER_add_delayed(GST_timeout, + &GST_forwarded_operation_timeout, + fopc); + GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, + fopcq_tail, + fopc); + GNUNET_SERVICE_client_continue(client); + return; + } + if (GNUNET_OK != stop_peer(peer)) + { + LOG(GNUNET_ERROR_TYPE_WARNING, + "Stopping peer %u failed\n", + (unsigned int)peer_id); + GST_send_operation_fail_msg(client, + GNUNET_ntohll(msg->operation_id), + "Peer not running"); + GNUNET_SERVICE_client_continue(client); + return; + } + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Peer %u successfully stopped\n", + (unsigned int)peer_id); + env = GNUNET_MQ_msg(reply, + GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT); + reply->event_type = htonl(GNUNET_TESTBED_ET_PEER_STOP); + reply->host_id = htonl(GST_context->host_id); reply->peer_id = msg->peer_id; reply->operation_id = msg->operation_id; - GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), - env); - GNUNET_SERVICE_client_continue (client); - GNUNET_TESTING_peer_wait (peer->details.local.peer); + GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), + env); + GNUNET_SERVICE_client_continue(client); + GNUNET_TESTING_peer_wait(peer->details.local.peer); } @@ -804,8 +802,8 @@ handle_peer_stop (void *cls, * @param msg the actual message */ void -handle_peer_get_config (void *cls, - const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg) +handle_peer_get_config(void *cls, + const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg) { struct GNUNET_SERVICE_Client *client = cls; struct GNUNET_MQ_Envelope *env; @@ -818,67 +816,67 @@ handle_peer_get_config (void *cls, size_t xc_size; uint32_t peer_id; - peer_id = ntohl (msg->peer_id); - LOG_DEBUG ("Received GET_CONFIG for peer %u\n", - (unsigned int) peer_id); - if (!VALID_PEER_ID (peer_id)) - { - GST_send_operation_fail_msg (client, - GNUNET_ntohll (msg->operation_id), - "Peer not found"); - GNUNET_SERVICE_client_continue (client); - return; - } + peer_id = ntohl(msg->peer_id); + LOG_DEBUG("Received GET_CONFIG for peer %u\n", + (unsigned int)peer_id); + if (!VALID_PEER_ID(peer_id)) + { + GST_send_operation_fail_msg(client, + GNUNET_ntohll(msg->operation_id), + "Peer not found"); + GNUNET_SERVICE_client_continue(client); + return; + } peer = GST_peer_list[peer_id]; if (GNUNET_YES == peer->is_remote) - { - LOG_DEBUG ("Forwarding PEER_GET_CONFIG for peer: %u\n", - (unsigned int) peer_id); - fopc = GNUNET_new (struct ForwardedOperationContext); - fopc->client = client; - fopc->operation_id = GNUNET_ntohll (msg->operation_id); - fopc->type = OP_PEER_INFO; - fopc->opc = - GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote. - slave->controller, - fopc->operation_id, - &msg->header, - &GST_forwarded_operation_reply_relay, - fopc); - fopc->timeout_task = - GNUNET_SCHEDULER_add_delayed (GST_timeout, - &GST_forwarded_operation_timeout, - fopc); - GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, - fopcq_tail, - fopc); - GNUNET_SERVICE_client_continue (client); - return; - } - LOG_DEBUG ("Received PEER_GET_CONFIG for peer: %u\n", - peer_id); + { + LOG_DEBUG("Forwarding PEER_GET_CONFIG for peer: %u\n", + (unsigned int)peer_id); + fopc = GNUNET_new(struct ForwardedOperationContext); + fopc->client = client; + fopc->operation_id = GNUNET_ntohll(msg->operation_id); + fopc->type = OP_PEER_INFO; + fopc->opc = + GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. + slave->controller, + fopc->operation_id, + &msg->header, + &GST_forwarded_operation_reply_relay, + fopc); + fopc->timeout_task = + GNUNET_SCHEDULER_add_delayed(GST_timeout, + &GST_forwarded_operation_timeout, + fopc); + GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, + fopcq_tail, + fopc); + GNUNET_SERVICE_client_continue(client); + return; + } + LOG_DEBUG("Received PEER_GET_CONFIG for peer: %u\n", + peer_id); config = - GNUNET_CONFIGURATION_serialize (GST_peer_list[peer_id]->details.local.cfg, - &c_size); - xc_size = GNUNET_TESTBED_compress_config_ (config, - c_size, - &xconfig); - GNUNET_free (config); - env = GNUNET_MQ_msg_extra (reply, - xc_size, - GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION); + GNUNET_CONFIGURATION_serialize(GST_peer_list[peer_id]->details.local.cfg, + &c_size); + xc_size = GNUNET_TESTBED_compress_config_(config, + c_size, + &xconfig); + GNUNET_free(config); + env = GNUNET_MQ_msg_extra(reply, + xc_size, + GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION); reply->peer_id = msg->peer_id; reply->operation_id = msg->operation_id; - GNUNET_TESTING_peer_get_identity (GST_peer_list[peer_id]->details.local.peer, - &reply->peer_identity); - reply->config_size = htons ((uint16_t) c_size); - GNUNET_memcpy (&reply[1], - xconfig, - xc_size); - GNUNET_free (xconfig); - GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), - env); - GNUNET_SERVICE_client_continue (client); + GNUNET_TESTING_peer_get_identity(GST_peer_list[peer_id]->details.local.peer, + &reply->peer_identity); + reply->config_size = htons((uint16_t)c_size); + GNUNET_memcpy(&reply[1], + xconfig, + xc_size); + GNUNET_free(xconfig); + GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), + env); + GNUNET_SERVICE_client_continue(client); } @@ -886,10 +884,10 @@ handle_peer_get_config (void *cls, * Cleans up the Peer reconfigure context list */ void -GST_free_prcq () +GST_free_prcq() { while (NULL != prc_head) - cleanup_prc (prc_head); + cleanup_prc(prc_head); } @@ -901,21 +899,21 @@ GST_free_prcq () * @return error message (freshly allocated); NULL upon success */ static char * -update_peer_config (struct Peer *peer, - struct GNUNET_CONFIGURATION_Handle *cfg) +update_peer_config(struct Peer *peer, + struct GNUNET_CONFIGURATION_Handle *cfg) { char *emsg; - GNUNET_TESTING_peer_destroy (peer->details.local.peer); - GNUNET_CONFIGURATION_destroy (peer->details.local.cfg); + GNUNET_TESTING_peer_destroy(peer->details.local.peer); + GNUNET_CONFIGURATION_destroy(peer->details.local.cfg); peer->details.local.cfg = cfg; emsg = NULL; peer->details.local.peer - = GNUNET_TESTING_peer_configure (GST_context->system, - peer->details.local.cfg, - peer->id, - NULL /* Peer id */ , - &emsg); + = GNUNET_TESTING_peer_configure(GST_context->system, + peer->details.local.cfg, + peer->id, + NULL /* Peer id */, + &emsg); return emsg; } @@ -929,39 +927,39 @@ update_peer_config (struct Peer *peer, * error */ static void -prc_stop_cb (void *cls, - struct GNUNET_TESTING_Peer *p, - int success) +prc_stop_cb(void *cls, + struct GNUNET_TESTING_Peer *p, + int success) { struct PeerReconfigureContext *prc = cls; struct Peer *peer; char *emsg; - GNUNET_assert (VALID_PEER_ID (prc->peer_id)); + GNUNET_assert(VALID_PEER_ID(prc->peer_id)); peer = GST_peer_list [prc->peer_id]; - GNUNET_assert (GNUNET_NO == peer->is_remote); - emsg = update_peer_config (peer, prc->cfg); + GNUNET_assert(GNUNET_NO == peer->is_remote); + emsg = update_peer_config(peer, prc->cfg); prc->cfg = NULL; prc->stopped = 1; if (NULL != emsg) - { - GST_send_operation_fail_msg (prc->client, - prc->op_id, - emsg); - goto cleanup; - } - if (GNUNET_OK != start_peer (peer)) - { - GST_send_operation_fail_msg (prc->client, - prc->op_id, - "Failed to start reconfigured peer"); - goto cleanup; - } - GST_send_operation_success_msg (prc->client, - prc->op_id); - - cleanup: - cleanup_prc (prc); + { + GST_send_operation_fail_msg(prc->client, + prc->op_id, + emsg); + goto cleanup; + } + if (GNUNET_OK != start_peer(peer)) + { + GST_send_operation_fail_msg(prc->client, + prc->op_id, + "Failed to start reconfigured peer"); + goto cleanup; + } + GST_send_operation_success_msg(prc->client, + prc->op_id); + +cleanup: + cleanup_prc(prc); return; } @@ -974,8 +972,8 @@ prc_stop_cb (void *cls, * @return #GNUNET_OK if @a msg is well-formed */ int -check_peer_reconfigure (void *cls, - const struct GNUNET_TESTBED_PeerReconfigureMessage *msg) +check_peer_reconfigure(void *cls, + const struct GNUNET_TESTBED_PeerReconfigureMessage *msg) { return GNUNET_OK; /* checked later */ } @@ -990,8 +988,8 @@ check_peer_reconfigure (void *cls, * @param msg the actual message */ void -handle_peer_reconfigure (void *cls, - const struct GNUNET_TESTBED_PeerReconfigureMessage *msg) +handle_peer_reconfigure(void *cls, + const struct GNUNET_TESTBED_PeerReconfigureMessage *msg) { struct GNUNET_SERVICE_Client *client = cls; struct Peer *peer; @@ -1002,114 +1000,114 @@ handle_peer_reconfigure (void *cls, uint64_t op_id; uint32_t peer_id; - peer_id = ntohl (msg->peer_id); - op_id = GNUNET_ntohll (msg->operation_id); - if (! VALID_PEER_ID (peer_id)) - { - GNUNET_break (0); - GST_send_operation_fail_msg (client, - op_id, - "Peer not found"); - GNUNET_SERVICE_client_continue (client); - return; - } + peer_id = ntohl(msg->peer_id); + op_id = GNUNET_ntohll(msg->operation_id); + if (!VALID_PEER_ID(peer_id)) + { + GNUNET_break(0); + GST_send_operation_fail_msg(client, + op_id, + "Peer not found"); + GNUNET_SERVICE_client_continue(client); + return; + } peer = GST_peer_list[peer_id]; if (GNUNET_YES == peer->is_remote) - { - LOG_DEBUG ("Forwarding PEER_RECONFIGURE for peer: %u\n", peer_id); - fopc = GNUNET_new (struct ForwardedOperationContext); - fopc->client = client; - fopc->operation_id = op_id; - fopc->type = OP_PEER_RECONFIGURE; - fopc->opc = - GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote. - slave->controller, - fopc->operation_id, - &msg->header, - &GST_forwarded_operation_reply_relay, - fopc); - fopc->timeout_task = - GNUNET_SCHEDULER_add_delayed (GST_timeout, - &GST_forwarded_operation_timeout, - fopc); - GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, - fopcq_tail, - fopc); - GNUNET_SERVICE_client_continue (client); - return; - } - LOG_DEBUG ("Received PEER_RECONFIGURE for peer %u\n", - (unsigned int) peer_id); + { + LOG_DEBUG("Forwarding PEER_RECONFIGURE for peer: %u\n", peer_id); + fopc = GNUNET_new(struct ForwardedOperationContext); + fopc->client = client; + fopc->operation_id = op_id; + fopc->type = OP_PEER_RECONFIGURE; + fopc->opc = + GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. + slave->controller, + fopc->operation_id, + &msg->header, + &GST_forwarded_operation_reply_relay, + fopc); + fopc->timeout_task = + GNUNET_SCHEDULER_add_delayed(GST_timeout, + &GST_forwarded_operation_timeout, + fopc); + GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, + fopcq_tail, + fopc); + GNUNET_SERVICE_client_continue(client); + return; + } + LOG_DEBUG("Received PEER_RECONFIGURE for peer %u\n", + (unsigned int)peer_id); if (0 < peer->reference_cnt) - { - GNUNET_break (0); - GST_send_operation_fail_msg (client, - op_id, - "Peer in use"); - GNUNET_SERVICE_client_continue (client); - return; - } + { + GNUNET_break(0); + GST_send_operation_fail_msg(client, + op_id, + "Peer in use"); + GNUNET_SERVICE_client_continue(client); + return; + } if (GNUNET_YES == peer->destroy_flag) - { - GNUNET_break (0); - GST_send_operation_fail_msg (client, - op_id, - "Peer is being destroyed"); - GNUNET_SERVICE_client_continue (client); - return; - } - cfg = GNUNET_TESTBED_extract_config_ (&msg->header); + { + GNUNET_break(0); + GST_send_operation_fail_msg(client, + op_id, + "Peer is being destroyed"); + GNUNET_SERVICE_client_continue(client); + return; + } + cfg = GNUNET_TESTBED_extract_config_(&msg->header); if (NULL == cfg) - { - GNUNET_break (0); - GST_send_operation_fail_msg (client, - op_id, - "Compression error"); - GNUNET_SERVICE_client_continue (client); - return; - } + { + GNUNET_break(0); + GST_send_operation_fail_msg(client, + op_id, + "Compression error"); + GNUNET_SERVICE_client_continue(client); + return; + } if (GNUNET_NO == peer->details.local.is_running) - { - emsg = update_peer_config (peer, - cfg); - if (NULL != emsg) - GST_send_operation_fail_msg (client, - op_id, - emsg); - GST_send_operation_success_msg (client, - op_id); - GNUNET_SERVICE_client_continue (client); - GNUNET_free_non_null (emsg); - return; - } - prc = GNUNET_new (struct PeerReconfigureContext); + { + emsg = update_peer_config(peer, + cfg); + if (NULL != emsg) + GST_send_operation_fail_msg(client, + op_id, + emsg); + GST_send_operation_success_msg(client, + op_id); + GNUNET_SERVICE_client_continue(client); + GNUNET_free_non_null(emsg); + return; + } + prc = GNUNET_new(struct PeerReconfigureContext); if (GNUNET_OK != - GNUNET_TESTING_peer_stop_async (peer->details.local.peer, - &prc_stop_cb, - prc)) - { - GNUNET_assert (0 < GNUNET_asprintf (&emsg, + GNUNET_TESTING_peer_stop_async(peer->details.local.peer, + &prc_stop_cb, + prc)) + { + GNUNET_assert(0 < GNUNET_asprintf(&emsg, "Error trying to stop peer %u asynchronously\n", peer_id)); - LOG (GNUNET_ERROR_TYPE_ERROR, - "%s\n", - emsg); - GST_send_operation_fail_msg (client, - op_id, - emsg); - GNUNET_SERVICE_client_continue (client); - GNUNET_free (prc); - GNUNET_free (emsg); - return; - } + LOG(GNUNET_ERROR_TYPE_ERROR, + "%s\n", + emsg); + GST_send_operation_fail_msg(client, + op_id, + emsg); + GNUNET_SERVICE_client_continue(client); + GNUNET_free(prc); + GNUNET_free(emsg); + return; + } prc->cfg = cfg; prc->peer_id = peer_id; prc->op_id = op_id; prc->client = client; - GNUNET_CONTAINER_DLL_insert_tail (prc_head, - prc_tail, - prc); - GNUNET_SERVICE_client_continue (client); + GNUNET_CONTAINER_DLL_insert_tail(prc_head, + prc_tail, + prc); + GNUNET_SERVICE_client_continue(client); } @@ -1117,10 +1115,10 @@ handle_peer_reconfigure (void *cls, * Frees the ManageServiceContext queue */ void -GST_free_mctxq () +GST_free_mctxq() { while (NULL != mctx_head) - cleanup_mctx (mctx_head); + cleanup_mctx(mctx_head); } @@ -1131,15 +1129,16 @@ GST_free_mctxq () * @return a string interpretation of the request status */ static const char * -arm_req_string (enum GNUNET_ARM_RequestStatus rs) +arm_req_string(enum GNUNET_ARM_RequestStatus rs) { switch (rs) - { - case GNUNET_ARM_REQUEST_SENT_OK: - return _("Message was sent successfully"); - case GNUNET_ARM_REQUEST_DISCONNECTED: - return _("We disconnected from ARM before we could send a request"); - } + { + case GNUNET_ARM_REQUEST_SENT_OK: + return _("Message was sent successfully"); + + case GNUNET_ARM_REQUEST_DISCONNECTED: + return _("We disconnected from ARM before we could send a request"); + } return _("Unknown request status"); } @@ -1151,31 +1150,40 @@ arm_req_string (enum GNUNET_ARM_RequestStatus rs) * @return a string interpretation */ static const char * -arm_ret_string (enum GNUNET_ARM_Result result) +arm_ret_string(enum GNUNET_ARM_Result result) { switch (result) - { - case GNUNET_ARM_RESULT_STOPPED: - return _("%s is stopped"); - case GNUNET_ARM_RESULT_STARTING: - return _("%s is starting"); - case GNUNET_ARM_RESULT_STOPPING: - return _("%s is stopping"); - case GNUNET_ARM_RESULT_IS_STARTING_ALREADY: - return _("%s is starting already"); - case GNUNET_ARM_RESULT_IS_STOPPING_ALREADY: - return _("%s is stopping already"); - case GNUNET_ARM_RESULT_IS_STARTED_ALREADY: - return _("%s is started already"); - case GNUNET_ARM_RESULT_IS_STOPPED_ALREADY: - return _("%s is stopped already"); - case GNUNET_ARM_RESULT_IS_NOT_KNOWN: - return _("%s service is not known to ARM"); - case GNUNET_ARM_RESULT_START_FAILED: - return _("%s service failed to start"); - case GNUNET_ARM_RESULT_IN_SHUTDOWN: - return _("%s service can't be started because ARM is shutting down"); - } + { + case GNUNET_ARM_RESULT_STOPPED: + return _("%s is stopped"); + + case GNUNET_ARM_RESULT_STARTING: + return _("%s is starting"); + + case GNUNET_ARM_RESULT_STOPPING: + return _("%s is stopping"); + + case GNUNET_ARM_RESULT_IS_STARTING_ALREADY: + return _("%s is starting already"); + + case GNUNET_ARM_RESULT_IS_STOPPING_ALREADY: + return _("%s is stopping already"); + + case GNUNET_ARM_RESULT_IS_STARTED_ALREADY: + return _("%s is started already"); + + case GNUNET_ARM_RESULT_IS_STOPPED_ALREADY: + return _("%s is stopped already"); + + case GNUNET_ARM_RESULT_IS_NOT_KNOWN: + return _("%s service is not known to ARM"); + + case GNUNET_ARM_RESULT_START_FAILED: + return _("%s service failed to start"); + + case GNUNET_ARM_RESULT_IN_SHUTDOWN: + return _("%s service can't be started because ARM is shutting down"); + } return _("%.s Unknown result code."); } @@ -1191,9 +1199,9 @@ arm_ret_string (enum GNUNET_ARM_Result result) * @param result result of the operation */ static void -service_manage_result_cb (void *cls, - enum GNUNET_ARM_RequestStatus rs, - enum GNUNET_ARM_Result result) +service_manage_result_cb(void *cls, + enum GNUNET_ARM_RequestStatus rs, + enum GNUNET_ARM_Result result) { struct ManageServiceContext *mctx = cls; char *emsg; @@ -1202,55 +1210,55 @@ service_manage_result_cb (void *cls, if (GNUNET_YES == mctx->expired) return; if (GNUNET_ARM_REQUEST_SENT_OK != rs) - { - GNUNET_asprintf (&emsg, - "Error communicating with Peer %u's ARM: %s", - mctx->peer->id, - arm_req_string (rs)); - goto ret; - } + { + GNUNET_asprintf(&emsg, + "Error communicating with Peer %u's ARM: %s", + mctx->peer->id, + arm_req_string(rs)); + goto ret; + } if (1 == mctx->start) goto service_start_check; - if (! ((GNUNET_ARM_RESULT_STOPPED == result) - || (GNUNET_ARM_RESULT_STOPPING == result) - || (GNUNET_ARM_RESULT_IS_STOPPING_ALREADY == result) - || (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY == result)) ) - { - /* stopping a service failed */ - GNUNET_asprintf (&emsg, - arm_ret_string (result), - mctx->service); - goto ret; - } + if (!((GNUNET_ARM_RESULT_STOPPED == result) + || (GNUNET_ARM_RESULT_STOPPING == result) + || (GNUNET_ARM_RESULT_IS_STOPPING_ALREADY == result) + || (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY == result))) + { + /* stopping a service failed */ + GNUNET_asprintf(&emsg, + arm_ret_string(result), + mctx->service); + goto ret; + } /* service stopped successfully */ goto ret; - service_start_check: - if (! ((GNUNET_ARM_RESULT_STARTING == result) - || (GNUNET_ARM_RESULT_IS_STARTING_ALREADY == result) - || (GNUNET_ARM_RESULT_IS_STARTED_ALREADY == result)) ) - { - /* starting a service failed */ - GNUNET_asprintf (&emsg, - arm_ret_string (result), - mctx->service); - goto ret; - } +service_start_check: + if (!((GNUNET_ARM_RESULT_STARTING == result) + || (GNUNET_ARM_RESULT_IS_STARTING_ALREADY == result) + || (GNUNET_ARM_RESULT_IS_STARTED_ALREADY == result))) + { + /* starting a service failed */ + GNUNET_asprintf(&emsg, + arm_ret_string(result), + mctx->service); + goto ret; + } /* service started successfully */ - ret: +ret: if (NULL != emsg) - { - LOG_DEBUG ("%s\n", emsg); - GST_send_operation_fail_msg (mctx->client, - mctx->op_id, - emsg); - } + { + LOG_DEBUG("%s\n", emsg); + GST_send_operation_fail_msg(mctx->client, + mctx->op_id, + emsg); + } else - GST_send_operation_success_msg (mctx->client, - mctx->op_id); - GNUNET_free_non_null (emsg); - cleanup_mctx (mctx); + GST_send_operation_success_msg(mctx->client, + mctx->op_id); + GNUNET_free_non_null(emsg); + cleanup_mctx(mctx); } @@ -1262,25 +1270,25 @@ service_manage_result_cb (void *cls, * @return #GNUNET_OK if @a msg is well-formed */ int -check_manage_peer_service (void *cls, - const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg) +check_manage_peer_service(void *cls, + const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg) { uint16_t msize; const char* service; - msize = ntohs (msg->header.size); - service = (const char *) &msg[1]; + msize = ntohs(msg->header.size); + service = (const char *)&msg[1]; if ('\0' != service[msize - sizeof (struct GNUNET_TESTBED_ManagePeerServiceMessage) - 1]) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } if (1 < msg->start) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -1292,8 +1300,8 @@ check_manage_peer_service (void *cls, * @param msg the actual message */ void -handle_manage_peer_service (void *cls, - const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg) +handle_manage_peer_service(void *cls, + const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg) { struct GNUNET_SERVICE_Client *client = cls; const char* service; @@ -1305,100 +1313,100 @@ handle_manage_peer_service (void *cls, uint64_t op_id; uint32_t peer_id; - service = (const char *) &msg[1]; - peer_id = ntohl (msg->peer_id); - op_id = GNUNET_ntohll (msg->operation_id); - LOG_DEBUG ("Received request to manage service %s on peer %u\n", - service, (unsigned int) peer_id); + service = (const char *)&msg[1]; + peer_id = ntohl(msg->peer_id); + op_id = GNUNET_ntohll(msg->operation_id); + LOG_DEBUG("Received request to manage service %s on peer %u\n", + service, (unsigned int)peer_id); if ((GST_peer_list_size <= peer_id) || (NULL == (peer = GST_peer_list[peer_id]))) - { - GNUNET_asprintf (&emsg, "Asked to manage service of a non existent peer " - "with id: %u", peer_id); - goto err_ret; - } - if (0 == strcasecmp ("arm", service)) - { - emsg = GNUNET_strdup ("Cannot start/stop peer's ARM service. " - "Use peer start/stop for that"); - goto err_ret; - } + { + GNUNET_asprintf(&emsg, "Asked to manage service of a non existent peer " + "with id: %u", peer_id); + goto err_ret; + } + if (0 == strcasecmp("arm", service)) + { + emsg = GNUNET_strdup("Cannot start/stop peer's ARM service. " + "Use peer start/stop for that"); + goto err_ret; + } if (GNUNET_YES == peer->is_remote) - { - /* Forward the destory message to sub controller */ - fopc = GNUNET_new (struct ForwardedOperationContext); - fopc->client = client; - fopc->cls = peer; - fopc->type = OP_MANAGE_SERVICE; - fopc->operation_id = op_id; - fopc->opc = - GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote. - slave->controller, - fopc->operation_id, - &msg->header, - &GST_forwarded_operation_reply_relay, - fopc); - fopc->timeout_task = - GNUNET_SCHEDULER_add_delayed (GST_timeout, - &GST_forwarded_operation_timeout, - fopc); - GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, - fopcq_tail, - fopc); - GNUNET_SERVICE_client_continue (client); - return; - } + { + /* Forward the destory message to sub controller */ + fopc = GNUNET_new(struct ForwardedOperationContext); + fopc->client = client; + fopc->cls = peer; + fopc->type = OP_MANAGE_SERVICE; + fopc->operation_id = op_id; + fopc->opc = + GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. + slave->controller, + fopc->operation_id, + &msg->header, + &GST_forwarded_operation_reply_relay, + fopc); + fopc->timeout_task = + GNUNET_SCHEDULER_add_delayed(GST_timeout, + &GST_forwarded_operation_timeout, + fopc); + GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, + fopcq_tail, + fopc); + GNUNET_SERVICE_client_continue(client); + return; + } if (GNUNET_NO == peer->details.local.is_running) - { - emsg = GNUNET_strdup ("Peer not running\n"); - goto err_ret; - } + { + emsg = GNUNET_strdup("Peer not running\n"); + goto err_ret; + } if ((0 != peer->reference_cnt) - && ( (0 == strcasecmp ("core", service)) - || (0 == strcasecmp ("transport", service)) ) ) - { - GNUNET_asprintf (&emsg, "Cannot stop %s service of peer with id: %u " - "since it is required by existing operations", - service, peer_id); - goto err_ret; - } - ah = GNUNET_ARM_connect (peer->details.local.cfg, NULL, NULL); + && ((0 == strcasecmp("core", service)) + || (0 == strcasecmp("transport", service)))) + { + GNUNET_asprintf(&emsg, "Cannot stop %s service of peer with id: %u " + "since it is required by existing operations", + service, peer_id); + goto err_ret; + } + ah = GNUNET_ARM_connect(peer->details.local.cfg, NULL, NULL); if (NULL == ah) - { - GNUNET_asprintf (&emsg, - "Cannot connect to ARM service of peer with id: %u", - peer_id); - goto err_ret; - } - mctx = GNUNET_new (struct ManageServiceContext); + { + GNUNET_asprintf(&emsg, + "Cannot connect to ARM service of peer with id: %u", + peer_id); + goto err_ret; + } + mctx = GNUNET_new(struct ManageServiceContext); mctx->peer = peer; peer->reference_cnt++; mctx->op_id = op_id; mctx->ah = ah; mctx->client = client; mctx->start = msg->start; - mctx->service = GNUNET_strdup (service); - GNUNET_CONTAINER_DLL_insert_tail (mctx_head, - mctx_tail, - mctx); + mctx->service = GNUNET_strdup(service); + GNUNET_CONTAINER_DLL_insert_tail(mctx_head, + mctx_tail, + mctx); if (1 == mctx->start) - GNUNET_ARM_request_service_start (mctx->ah, - service, - GNUNET_OS_INHERIT_STD_ERR, - &service_manage_result_cb, - mctx); - else - GNUNET_ARM_request_service_stop (mctx->ah, service, + GNUNET_ARM_request_service_start(mctx->ah, + service, + GNUNET_OS_INHERIT_STD_ERR, &service_manage_result_cb, mctx); - GNUNET_SERVICE_client_continue (client); + else + GNUNET_ARM_request_service_stop(mctx->ah, service, + &service_manage_result_cb, + mctx); + GNUNET_SERVICE_client_continue(client); return; - err_ret: - LOG (GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg); - GST_send_operation_fail_msg (client, op_id, emsg); - GNUNET_free (emsg); - GNUNET_SERVICE_client_continue (client); +err_ret: + LOG(GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg); + GST_send_operation_fail_msg(client, op_id, emsg); + GNUNET_free(emsg); + GNUNET_SERVICE_client_continue(client); } @@ -1406,7 +1414,7 @@ handle_manage_peer_service (void *cls, * Stops and destroys all peers */ void -GST_destroy_peers () +GST_destroy_peers() { struct Peer *peer; unsigned int id; @@ -1414,34 +1422,34 @@ GST_destroy_peers () if (NULL == GST_peer_list) return; for (id = 0; id < GST_peer_list_size; id++) - { - peer = GST_peer_list[id]; - if (NULL == peer) - continue; - /* If destroy flag is set it means that this peer should have been - * destroyed by a context which we destroy before */ - GNUNET_break (GNUNET_NO == peer->destroy_flag); - /* counter should be zero as we free all contexts before */ - GNUNET_break (0 == peer->reference_cnt); - if ((GNUNET_NO == peer->is_remote) && - (GNUNET_YES == peer->details.local.is_running)) - GNUNET_TESTING_peer_kill (peer->details.local.peer); - } + { + peer = GST_peer_list[id]; + if (NULL == peer) + continue; + /* If destroy flag is set it means that this peer should have been + * destroyed by a context which we destroy before */ + GNUNET_break(GNUNET_NO == peer->destroy_flag); + /* counter should be zero as we free all contexts before */ + GNUNET_break(0 == peer->reference_cnt); + if ((GNUNET_NO == peer->is_remote) && + (GNUNET_YES == peer->details.local.is_running)) + GNUNET_TESTING_peer_kill(peer->details.local.peer); + } for (id = 0; id < GST_peer_list_size; id++) - { - peer = GST_peer_list[id]; - if (NULL == peer) - continue; - if (GNUNET_NO == peer->is_remote) { - if (GNUNET_YES == peer->details.local.is_running) - GNUNET_TESTING_peer_wait (peer->details.local.peer); - GNUNET_TESTING_peer_destroy (peer->details.local.peer); - GNUNET_CONFIGURATION_destroy (peer->details.local.cfg); + peer = GST_peer_list[id]; + if (NULL == peer) + continue; + if (GNUNET_NO == peer->is_remote) + { + if (GNUNET_YES == peer->details.local.is_running) + GNUNET_TESTING_peer_wait(peer->details.local.peer); + GNUNET_TESTING_peer_destroy(peer->details.local.peer); + GNUNET_CONFIGURATION_destroy(peer->details.local.cfg); + } + GNUNET_free(peer); } - GNUNET_free (peer); - } - GNUNET_free_non_null (GST_peer_list); + GNUNET_free_non_null(GST_peer_list); GST_peer_list = NULL; GST_peer_list_size = 0; } @@ -1456,34 +1464,34 @@ GST_destroy_peers () * @param msg the message to relay */ static void -shutdown_peers_reply_cb (void *cls, - const struct GNUNET_MessageHeader *msg) +shutdown_peers_reply_cb(void *cls, + const struct GNUNET_MessageHeader *msg) { struct ForwardedOperationContext *fo_ctxt = cls; struct HandlerContext_ShutdownPeers *hc; hc = fo_ctxt->cls; - GNUNET_assert (0 < hc->nslaves); + GNUNET_assert(0 < hc->nslaves); hc->nslaves--; if (GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS != - ntohs (msg->type)) + ntohs(msg->type)) hc->timeout = GNUNET_YES; if (0 == hc->nslaves) - { - if (GNUNET_YES == hc->timeout) - GST_send_operation_fail_msg (fo_ctxt->client, - fo_ctxt->operation_id, - "Timeout at a slave controller"); - else - GST_send_operation_success_msg (fo_ctxt->client, - fo_ctxt->operation_id); - GNUNET_free (hc); - hc = NULL; - } - GNUNET_CONTAINER_DLL_remove (fopcq_head, - fopcq_tail, - fo_ctxt); - GNUNET_free (fo_ctxt); + { + if (GNUNET_YES == hc->timeout) + GST_send_operation_fail_msg(fo_ctxt->client, + fo_ctxt->operation_id, + "Timeout at a slave controller"); + else + GST_send_operation_success_msg(fo_ctxt->client, + fo_ctxt->operation_id); + GNUNET_free(hc); + hc = NULL; + } + GNUNET_CONTAINER_DLL_remove(fopcq_head, + fopcq_tail, + fo_ctxt); + GNUNET_free(fo_ctxt); } @@ -1494,8 +1502,8 @@ shutdown_peers_reply_cb (void *cls, * @param msg the actual message */ void -handle_shutdown_peers (void *cls, - const struct GNUNET_TESTBED_ShutdownPeersMessage *msg) +handle_shutdown_peers(void *cls, + const struct GNUNET_TESTBED_ShutdownPeersMessage *msg) { struct GNUNET_SERVICE_Client *client = cls; struct HandlerContext_ShutdownPeers *hc; @@ -1504,48 +1512,48 @@ handle_shutdown_peers (void *cls, uint64_t op_id; unsigned int cnt; - LOG_DEBUG ("Received SHUTDOWN_PEERS\n"); - /* Stop and destroy all peers */ - GST_free_mctxq (); - GST_free_occq (); - GST_free_roccq (); - GST_clear_fopcq (); + LOG_DEBUG("Received SHUTDOWN_PEERS\n"); + /* Stop and destroy all peers */ + GST_free_mctxq(); + GST_free_occq(); + GST_free_roccq(); + GST_clear_fopcq(); /* Forward to all slaves which we have started */ - op_id = GNUNET_ntohll (msg->operation_id); - hc = GNUNET_new (struct HandlerContext_ShutdownPeers); + op_id = GNUNET_ntohll(msg->operation_id); + hc = GNUNET_new(struct HandlerContext_ShutdownPeers); /* FIXME: have a better implementation where we track which slaves are started by this controller */ for (cnt = 0; cnt < GST_slave_list_size; cnt++) - { - slave = GST_slave_list[cnt]; - if (NULL == slave) - continue; - if (NULL == slave->controller_proc) /* We didn't start the slave */ - continue; - LOG_DEBUG ("Forwarding SHUTDOWN_PEERS\n"); - hc->nslaves++; - fo_ctxt = GNUNET_new (struct ForwardedOperationContext); - fo_ctxt->client = client; - fo_ctxt->operation_id = op_id; - fo_ctxt->cls = hc; - fo_ctxt->type = OP_SHUTDOWN_PEERS; - fo_ctxt->opc = - GNUNET_TESTBED_forward_operation_msg_ (slave->controller, - fo_ctxt->operation_id, - &msg->header, - shutdown_peers_reply_cb, - fo_ctxt); - GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, - fopcq_tail, - fo_ctxt); - } - LOG_DEBUG ("Shutting down peers\n"); - GST_destroy_peers (); + { + slave = GST_slave_list[cnt]; + if (NULL == slave) + continue; + if (NULL == slave->controller_proc) /* We didn't start the slave */ + continue; + LOG_DEBUG("Forwarding SHUTDOWN_PEERS\n"); + hc->nslaves++; + fo_ctxt = GNUNET_new(struct ForwardedOperationContext); + fo_ctxt->client = client; + fo_ctxt->operation_id = op_id; + fo_ctxt->cls = hc; + fo_ctxt->type = OP_SHUTDOWN_PEERS; + fo_ctxt->opc = + GNUNET_TESTBED_forward_operation_msg_(slave->controller, + fo_ctxt->operation_id, + &msg->header, + shutdown_peers_reply_cb, + fo_ctxt); + GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, + fopcq_tail, + fo_ctxt); + } + LOG_DEBUG("Shutting down peers\n"); + GST_destroy_peers(); if (0 == hc->nslaves) - { - GST_send_operation_success_msg (client, - op_id); - GNUNET_free (hc); - } - GNUNET_SERVICE_client_continue (client); + { + GST_send_operation_success_msg(client, + op_id); + GNUNET_free(hc); + } + GNUNET_SERVICE_client_continue(client); } diff --git a/src/testbed/gnunet-testbed-profiler.c b/src/testbed/gnunet-testbed-profiler.c index d9401286c..e65ae6202 100644 --- a/src/testbed/gnunet-testbed-profiler.c +++ b/src/testbed/gnunet-testbed-profiler.c @@ -16,7 +16,7 @@ along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file testbed/gnunet-testbed-profiler.c @@ -32,8 +32,8 @@ /** * Generic loggins shorthand */ -#define LOG(kind,...) \ - GNUNET_log (kind, __VA_ARGS__) +#define LOG(kind, ...) \ + GNUNET_log(kind, __VA_ARGS__) /** @@ -104,18 +104,18 @@ static int noninteractive; * @param cls NULL */ static void -do_shutdown (void *cls) +do_shutdown(void *cls) { if (NULL != abort_task) - { - GNUNET_SCHEDULER_cancel (abort_task); - abort_task = NULL; - } + { + GNUNET_SCHEDULER_cancel(abort_task); + abort_task = NULL; + } if (NULL != cfg) - { - GNUNET_CONFIGURATION_destroy (cfg); - cfg = NULL; - } + { + GNUNET_CONFIGURATION_destroy(cfg); + cfg = NULL; + } } @@ -125,13 +125,13 @@ do_shutdown (void *cls) * @param cls NULL */ static void -do_abort (void *cls) +do_abort(void *cls) { abort_task = NULL; - LOG (GNUNET_ERROR_TYPE_WARNING, - "Aborting\n"); + LOG(GNUNET_ERROR_TYPE_WARNING, + "Aborting\n"); result = GNUNET_SYSERR; - GNUNET_SCHEDULER_shutdown (); + GNUNET_SCHEDULER_shutdown(); } @@ -140,15 +140,15 @@ do_abort (void *cls) * many failed */ static void -print_overlay_links_summary () +print_overlay_links_summary() { static int printed_already; if (GNUNET_YES == printed_already) return; printed_already = GNUNET_YES; - printf ("%u links succeeded\n", established_links); - printf ("%u links failed due to timeouts\n", failed_links); + printf("%u links succeeded\n", established_links); + printf("%u links failed due to timeouts\n", failed_links); } @@ -159,41 +159,43 @@ print_overlay_links_summary () * @param event the controller event */ static void -controller_event_cb (void *cls, - const struct GNUNET_TESTBED_EventInformation *event) +controller_event_cb(void *cls, + const struct GNUNET_TESTBED_EventInformation *event) { switch (event->type) - { - case GNUNET_TESTBED_ET_OPERATION_FINISHED: - /* Control reaches here when a peer linking operation fails */ - if (NULL != event->details.operation_finished.emsg) { - printf ("F"); - fflush (stdout); - failed_links++; - if (++cont_fails > num_cont_fails) - { - printf ("\nAborting due to very high failure rate\n"); - print_overlay_links_summary (); - GNUNET_SCHEDULER_shutdown (); - return; - } + case GNUNET_TESTBED_ET_OPERATION_FINISHED: + /* Control reaches here when a peer linking operation fails */ + if (NULL != event->details.operation_finished.emsg) + { + printf("F"); + fflush(stdout); + failed_links++; + if (++cont_fails > num_cont_fails) + { + printf("\nAborting due to very high failure rate\n"); + print_overlay_links_summary(); + GNUNET_SCHEDULER_shutdown(); + return; + } + } + break; + + case GNUNET_TESTBED_ET_CONNECT: + { + if (0 != cont_fails) + cont_fails--; + if (0 == established_links) + printf("Establishing links. Please wait\n"); + printf("."); + fflush(stdout); + established_links++; } break; - case GNUNET_TESTBED_ET_CONNECT: - { - if (0 != cont_fails) - cont_fails--; - if (0 == established_links) - printf ("Establishing links. Please wait\n"); - printf ("."); - fflush (stdout); - established_links++; - } - break; - default: - GNUNET_break (0); - } + + default: + GNUNET_break(0); + } } @@ -209,30 +211,30 @@ controller_event_cb (void *cls, * @param links_failed the number of overlay link */ static void -test_run (void *cls, - struct GNUNET_TESTBED_RunHandle *h, - unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers, - unsigned int links_succeeded, - unsigned int links_failed) +test_run(void *cls, + struct GNUNET_TESTBED_RunHandle *h, + unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers, + unsigned int links_succeeded, + unsigned int links_failed) { result = GNUNET_OK; - fprintf (stdout, "\n"); - print_overlay_links_summary (); - GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); + fprintf(stdout, "\n"); + print_overlay_links_summary(); + GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); if (noninteractive) - { - GNUNET_SCHEDULER_cancel (abort_task); - abort_task = NULL; - return; - } + { + GNUNET_SCHEDULER_cancel(abort_task); + abort_task = NULL; + return; + } #if (!ENABLE_SUPERMUC) - fprintf (stdout, "Testbed running, waiting for keystroke to shut down\n"); - fflush (stdout); - (void) getc (stdin); + 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 (); + fprintf(stdout, "Shutting down. Please wait\n"); + fflush(stdout); + GNUNET_SCHEDULER_shutdown(); } @@ -245,25 +247,25 @@ test_run (void *cls, * @param config configuration */ static void -run (void *cls, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *config) +run(void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *config) { if (0 == num_peers) - { - LOG (GNUNET_ERROR_TYPE_ERROR, _("Exiting as the number of peers is %u\n"), - num_peers); - return; - } - cfg = GNUNET_CONFIGURATION_dup (config); + { + LOG(GNUNET_ERROR_TYPE_ERROR, _("Exiting as the number of peers is %u\n"), + num_peers); + return; + } + cfg = GNUNET_CONFIGURATION_dup(config); event_mask = 0; event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); - GNUNET_TESTBED_run (hosts_file, cfg, num_peers, event_mask, - &controller_event_cb, NULL, - &test_run, NULL); + GNUNET_TESTBED_run(hosts_file, cfg, num_peers, event_mask, + &controller_event_cb, NULL, + &test_run, NULL); abort_task = - GNUNET_SCHEDULER_add_shutdown (&do_abort, - NULL); + GNUNET_SCHEDULER_add_shutdown(&do_abort, + NULL); } @@ -273,47 +275,47 @@ run (void *cls, char *const *args, const char *cfgfile, * @return 0 on success */ int -main (int argc, char *const *argv) +main(int argc, char *const *argv) { struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_option_uint ('p', - "num-peers", - "COUNT", - gettext_noop ("create COUNT number of peers"), - &num_peers), - GNUNET_GETOPT_option_uint ('e', - "num-errors", - "COUNT", - gettext_noop ("tolerate COUNT number of continious timeout failures"), - &num_cont_fails), - GNUNET_GETOPT_option_flag ('n', - "non-interactive", - gettext_noop ("run profiler in non-interactive mode where upon " - "testbed setup the profiler does not wait for a " - "keystroke but continues to run until a termination " - "signal is received"), - &noninteractive), + GNUNET_GETOPT_option_uint('p', + "num-peers", + "COUNT", + gettext_noop("create COUNT number of peers"), + &num_peers), + GNUNET_GETOPT_option_uint('e', + "num-errors", + "COUNT", + gettext_noop("tolerate COUNT number of continious timeout failures"), + &num_cont_fails), + GNUNET_GETOPT_option_flag('n', + "non-interactive", + gettext_noop("run profiler in non-interactive mode where upon " + "testbed setup the profiler does not wait for a " + "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), + 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]"; int ret; - unsetenv ("XDG_DATA_HOME"); - unsetenv ("XDG_CONFIG_HOME"); - if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) + unsetenv("XDG_DATA_HOME"); + unsetenv("XDG_CONFIG_HOME"); + if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) return 2; result = GNUNET_SYSERR; ret = - GNUNET_PROGRAM_run (argc, argv, "gnunet-testbed-profiler", binaryHelp, - options, &run, NULL); - GNUNET_free ((void *) argv); + GNUNET_PROGRAM_run(argc, argv, "gnunet-testbed-profiler", binaryHelp, + options, &run, NULL); + GNUNET_free((void *)argv); if (GNUNET_OK != ret) return ret; if (GNUNET_OK != result) diff --git a/src/testbed/gnunet_mpi_test.c b/src/testbed/gnunet_mpi_test.c index 7fe7a75d7..1c2696048 100644 --- a/src/testbed/gnunet_mpi_test.c +++ b/src/testbed/gnunet_mpi_test.c @@ -5,11 +5,11 @@ /** * Generic logging shorthand */ -#define LOG(kind,...) \ - GNUNET_log_from (kind, "gnunet-mpi-test", __VA_ARGS__) +#define LOG(kind, ...) \ + GNUNET_log_from(kind, "gnunet-mpi-test", __VA_ARGS__) int -main (int argc, char *argv[]) +main(int argc, char *argv[]) { char *msg; char *filename; @@ -26,82 +26,82 @@ main (int argc, char *argv[]) ret = GNUNET_SYSERR; if (argc < 2) - { - printf ("Need arguments: gnunet-mpi-test "); - return 1; - } - if (MPI_SUCCESS != MPI_Init (&argc, &argv)) - { - GNUNET_break (0); - return 1; - } - if (MPI_SUCCESS != MPI_Comm_size (MPI_COMM_WORLD, &ntasks)) - { - GNUNET_break (0); - goto finalize; - } - if (MPI_SUCCESS != MPI_Comm_rank (MPI_COMM_WORLD, &rank)) - { - GNUNET_break (0); - goto finalize; - } - pid = getpid (); - (void) GNUNET_asprintf (&filename, "%d-%d.mpiout", (int) pid, rank); - msg_size = GNUNET_asprintf (&msg, "My rank is: %d\n", rank); - printf ("%s", msg); + { + printf("Need arguments: gnunet-mpi-test "); + return 1; + } + if (MPI_SUCCESS != MPI_Init(&argc, &argv)) + { + GNUNET_break(0); + return 1; + } + if (MPI_SUCCESS != MPI_Comm_size(MPI_COMM_WORLD, &ntasks)) + { + GNUNET_break(0); + goto finalize; + } + if (MPI_SUCCESS != MPI_Comm_rank(MPI_COMM_WORLD, &rank)) + { + GNUNET_break(0); + goto finalize; + } + pid = getpid(); + (void)GNUNET_asprintf(&filename, "%d-%d.mpiout", (int)pid, rank); + msg_size = GNUNET_asprintf(&msg, "My rank is: %d\n", rank); + printf("%s", msg); if (msg_size == - GNUNET_DISK_fn_write (filename, msg, msg_size, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_GROUP_READ | - GNUNET_DISK_PERM_USER_WRITE | - GNUNET_DISK_PERM_GROUP_WRITE)) + GNUNET_DISK_fn_write(filename, msg, msg_size, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_GROUP_READ | + GNUNET_DISK_PERM_USER_WRITE | + GNUNET_DISK_PERM_GROUP_WRITE)) ret = GNUNET_OK; - GNUNET_free (filename); - GNUNET_free (msg); + GNUNET_free(filename); + GNUNET_free(msg); if (GNUNET_OK != ret) - { - GNUNET_break (0); - goto finalize; - } + { + GNUNET_break(0); + goto finalize; + } ret = GNUNET_SYSERR; - argv2 = GNUNET_malloc (sizeof (char *) * (argc)); + argv2 = GNUNET_malloc(sizeof(char *) * (argc)); for (cnt = 1; cnt < argc; cnt++) argv2[cnt - 1] = argv[cnt]; proc = - GNUNET_OS_start_process_vap (GNUNET_NO, GNUNET_OS_INHERIT_STD_ALL, NULL, - NULL, NULL, argv2[0], argv2); + GNUNET_OS_start_process_vap(GNUNET_NO, GNUNET_OS_INHERIT_STD_ALL, NULL, + NULL, NULL, argv2[0], argv2); if (NULL == proc) - { - printf ("Cannot exec\n"); - GNUNET_free (argv2); - goto finalize; - } + { + printf("Cannot exec\n"); + GNUNET_free(argv2); + goto finalize; + } do - { - (void) sleep (1); - ret = GNUNET_OS_process_status (proc, &proc_status, &code); - } + { + (void)sleep(1); + ret = GNUNET_OS_process_status(proc, &proc_status, &code); + } while (GNUNET_NO == ret); - GNUNET_free (argv2); - GNUNET_assert (GNUNET_NO != ret); + GNUNET_free(argv2); + GNUNET_assert(GNUNET_NO != ret); if (GNUNET_OK == ret) - { - if (0 != code) { - LOG (GNUNET_ERROR_TYPE_WARNING, "Child terminated abnormally\n"); - ret = GNUNET_SYSERR; - GNUNET_break (0); - goto finalize; + if (0 != code) + { + LOG(GNUNET_ERROR_TYPE_WARNING, "Child terminated abnormally\n"); + ret = GNUNET_SYSERR; + GNUNET_break(0); + goto finalize; + } } - } else - GNUNET_break (0); + GNUNET_break(0); finalize: - (void) MPI_Finalize (); + (void)MPI_Finalize(); if (GNUNET_OK == ret) return 0; - printf ("Something went wrong\n"); + printf("Something went wrong\n"); return 1; } diff --git a/src/testbed/gnunet_testbed_mpi_spawn.c b/src/testbed/gnunet_testbed_mpi_spawn.c index d69812cd2..b79c431c4 100644 --- a/src/testbed/gnunet_testbed_mpi_spawn.c +++ b/src/testbed/gnunet_testbed_mpi_spawn.c @@ -6,14 +6,14 @@ /** * Generic logging shorthand */ -#define LOG(kind,...) \ - GNUNET_log (kind, __VA_ARGS__) +#define LOG(kind, ...) \ + GNUNET_log(kind, __VA_ARGS__) /** * Debug logging shorthand */ #define LOG_DEBUG(...) \ - LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) + LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) /** * Global result @@ -69,53 +69,54 @@ static struct GNUNET_SCHEDULER_Task * child_death_task_id; * The shutdown task */ static void -shutdown_task (void *cls) +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; - } + { + 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; - } + { + 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) +terminate_task(void *cls) { static int hard_kill; - GNUNET_assert (NULL != child); + GNUNET_assert(NULL != child); terminate_task_id = - GNUNET_SCHEDULER_add_shutdown (&terminate_task, NULL); + 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; + 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")); + GNUNET_break(0 == GNUNET_OS_process_kill(child, GNUNET_TERM_SIG)); + LOG(GNUNET_ERROR_TYPE_INFO, _("Waiting for child to exit.\n")); } @@ -126,33 +127,33 @@ terminate_task (void *cls) * @param cls closure, NULL if we need to self-restart */ static void -child_death_task (void *cls) +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); + pr = GNUNET_DISK_pipe_handle(sigpipe, GNUNET_DISK_PIPE_END_READ); child_death_task_id = NULL; - tc = GNUNET_SCHEDULER_get_task_context (); + 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; - } + { + 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); + 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); + 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); + GNUNET_SCHEDULER_add_now(&shutdown_task, NULL); } @@ -161,11 +162,11 @@ destroy_hosts(struct GNUNET_TESTBED_Host **hosts, unsigned int nhosts) { unsigned int host; - GNUNET_assert (NULL != hosts); + GNUNET_assert(NULL != hosts); for (host = 0; host < nhosts; host++) if (NULL != hosts[host]) - GNUNET_TESTBED_host_destroy (hosts[host]); - GNUNET_free (hosts); + GNUNET_TESTBED_host_destroy(hosts[host]); + GNUNET_free(hosts); hosts = NULL; } @@ -176,7 +177,7 @@ destroy_hosts(struct GNUNET_TESTBED_Host **hosts, unsigned int nhosts) * @param cls NULL */ static void -run (void *cls) +run(void *cls) { struct GNUNET_TESTBED_Host **hosts; const struct GNUNET_CONFIGURATION_Handle *null_cfg; @@ -185,78 +186,78 @@ run (void *cls) size_t hostname_len; unsigned int nhosts; - null_cfg = GNUNET_CONFIGURATION_create (); - nhosts = GNUNET_TESTBED_hosts_load_from_loadleveler (null_cfg, &hosts); + 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"); + { + 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"); + tmpdir = getenv("TMP"); if (NULL == tmpdir) - tmpdir = getenv ("TEMP"); + tmpdir = getenv("TEMP"); if (NULL == tmpdir) tmpdir = "/tmp"; - (void) GNUNET_asprintf (&fn, "%s/gnunet-testbed-spawn.lock", tmpdir); + (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); + 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; + 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; } - 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); + 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; - } + { + 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); + 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); + GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_DISK_pipe_handle(sigpipe, + GNUNET_DISK_PIPE_END_READ), + &child_death_task, NULL); } @@ -264,16 +265,16 @@ run (void *cls) * Signal handler called for SIGCHLD. */ static void -sighandler_child_death () +sighandler_child_death() { static char c; - int old_errno = errno; /* back-up errno */ + 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 */ + 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 */ } @@ -281,45 +282,45 @@ sighandler_child_death () * Execution start point */ int -main (int argc, char *argv[]) +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_NO, GNUNET_NO, - GNUNET_NO, GNUNET_NO))) - { - GNUNET_break (0); - ret = GNUNET_SYSERR; - return 1; - } + { + 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_NO, GNUNET_NO, + GNUNET_NO, GNUNET_NO))) + { + GNUNET_break(0); + ret = GNUNET_SYSERR; + return 1; + } shc_chld = - GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); + 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); + { + 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); + GNUNET_SCHEDULER_run(run, NULL); + GNUNET_free(argv2); + GNUNET_SIGNAL_handler_uninstall(shc_chld); shc_chld = NULL; - GNUNET_DISK_pipe_close (sigpipe); - GNUNET_free_non_null (fn); + GNUNET_DISK_pipe_close(sigpipe); + GNUNET_free_non_null(fn); if (GNUNET_OK != ret) return ret; return 0; diff --git a/src/testbed/test_gnunet_helper_testbed.c b/src/testbed/test_gnunet_helper_testbed.c index 851375291..8bf1fd7ca 100644 --- a/src/testbed/test_gnunet_helper_testbed.c +++ b/src/testbed/test_gnunet_helper_testbed.c @@ -11,7 +11,7 @@ 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 . @@ -36,8 +36,8 @@ /** * Generic logging shortcut */ -#define LOG(kind,...) \ - GNUNET_log (kind, __VA_ARGS__) +#define LOG(kind, ...) \ + GNUNET_log(kind, __VA_ARGS__) /** @@ -82,15 +82,15 @@ static int result; * @param cls NULL */ static void -do_shutdown (void *cls) +do_shutdown(void *cls) { if (NULL != abort_task) - GNUNET_SCHEDULER_cancel (abort_task); + GNUNET_SCHEDULER_cancel(abort_task); if (NULL != helper) - GNUNET_HELPER_stop (helper, GNUNET_NO); - GNUNET_free_non_null (msg); + GNUNET_HELPER_stop(helper, GNUNET_NO); + GNUNET_free_non_null(msg); if (NULL != cfg) - GNUNET_CONFIGURATION_destroy (cfg); + GNUNET_CONFIGURATION_destroy(cfg); } @@ -100,15 +100,15 @@ do_shutdown (void *cls) * @param cls NULL */ static void -do_abort (void *cls) +do_abort(void *cls) { abort_task = NULL; - LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); + LOG(GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); result = GNUNET_SYSERR; if (NULL != shandle) - GNUNET_HELPER_send_cancel (shandle); + GNUNET_HELPER_send_cancel(shandle); if (NULL == shutdown_task) - shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); + shutdown_task = GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); } @@ -121,13 +121,13 @@ do_abort (void *cls) * #GNUNET_SYSERR during GNUNET_HELPER_stop() */ static void -cont_cb (void *cls, - int result) +cont_cb(void *cls, + int result) { shandle = NULL; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Message sent\n"); - GNUNET_assert (GNUNET_OK == result); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Message sent\n"); + GNUNET_assert(GNUNET_OK == result); } @@ -143,35 +143,35 @@ cont_cb (void *cls, * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing */ static int -mst_cb (void *cls, - const struct GNUNET_MessageHeader *message) +mst_cb(void *cls, + const struct GNUNET_MessageHeader *message) { const struct GNUNET_TESTBED_HelperReply *msg; char *config; uLongf config_size; uLongf xconfig_size; - msg = (const struct GNUNET_TESTBED_HelperReply *) message; + msg = (const struct GNUNET_TESTBED_HelperReply *)message; config_size = 0; xconfig_size = 0; - GNUNET_assert (sizeof (struct GNUNET_TESTBED_HelperReply) < - ntohs (msg->header.size)); - GNUNET_assert (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY == - ntohs (msg->header.type)); - config_size = (uLongf) ntohs (msg->config_size); + GNUNET_assert(sizeof(struct GNUNET_TESTBED_HelperReply) < + ntohs(msg->header.size)); + GNUNET_assert(GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY == + ntohs(msg->header.type)); + config_size = (uLongf)ntohs(msg->config_size); xconfig_size = - (uLongf) (ntohs (msg->header.size) - - sizeof (struct GNUNET_TESTBED_HelperReply)); - config = GNUNET_malloc (config_size); - GNUNET_assert (Z_OK == - uncompress ((Bytef *) config, &config_size, - (const Bytef *) &msg[1], xconfig_size)); - GNUNET_free (config); + (uLongf)(ntohs(msg->header.size) - + sizeof(struct GNUNET_TESTBED_HelperReply)); + config = GNUNET_malloc(config_size); + GNUNET_assert(Z_OK == + uncompress((Bytef *)config, &config_size, + (const Bytef *)&msg[1], xconfig_size)); + GNUNET_free(config); if (NULL == shutdown_task) shutdown_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_SECONDS, 1), - &do_shutdown, NULL); + GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, 1), + &do_shutdown, NULL); return GNUNET_OK; } @@ -183,7 +183,7 @@ mst_cb (void *cls, * @param cls the closure from GNUNET_HELPER_start() */ static void -exp_cb (void *cls) +exp_cb(void *cls) { helper = NULL; result = GNUNET_SYSERR; @@ -199,8 +199,8 @@ exp_cb (void *cls) * @param cfg configuration */ static void -run (void *cls, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg2) +run(void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg2) { static char *const binary_argv[] = { "gnunet-helper-testbed", @@ -209,22 +209,22 @@ run (void *cls, char *const *args, const char *cfgfile, const char *trusted_ip = "127.0.0.1"; helper = - GNUNET_HELPER_start (GNUNET_YES, - "gnunet-helper-testbed", - binary_argv, - &mst_cb, - &exp_cb, - NULL); - GNUNET_assert (NULL != helper); - cfg = GNUNET_CONFIGURATION_dup (cfg2); - msg = GNUNET_TESTBED_create_helper_init_msg_ (trusted_ip, NULL, cfg); + GNUNET_HELPER_start(GNUNET_YES, + "gnunet-helper-testbed", + binary_argv, + &mst_cb, + &exp_cb, + NULL); + GNUNET_assert(NULL != helper); + cfg = GNUNET_CONFIGURATION_dup(cfg2); + msg = GNUNET_TESTBED_create_helper_init_msg_(trusted_ip, NULL, cfg); shandle = - GNUNET_HELPER_send (helper, &msg->header, GNUNET_NO, &cont_cb, NULL); - GNUNET_assert (NULL != shandle); + GNUNET_HELPER_send(helper, &msg->header, GNUNET_NO, &cont_cb, NULL); + GNUNET_assert(NULL != shandle); abort_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_MINUTES, 1), &do_abort, - NULL); + GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_MINUTES, 1), &do_abort, + NULL); } @@ -236,7 +236,7 @@ run (void *cls, char *const *args, const char *cfgfile, * @return return code */ int -main (int argc, char **argv) +main(int argc, char **argv) { struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END @@ -244,9 +244,9 @@ main (int argc, char **argv) result = GNUNET_OK; if (GNUNET_OK != - GNUNET_PROGRAM_run (argc, argv, "test_gnunet_helper_testbed", - "Testcase for testing gnunet-helper-testbed.c", - options, &run, NULL)) + GNUNET_PROGRAM_run(argc, argv, "test_gnunet_helper_testbed", + "Testcase for testing gnunet-helper-testbed.c", + options, &run, NULL)) return 1; return (GNUNET_OK == result) ? 0 : 1; } diff --git a/src/testbed/test_testbed_api.c b/src/testbed/test_testbed_api.c index 00d53dc25..37dc362ea 100644 --- a/src/testbed/test_testbed_api.c +++ b/src/testbed/test_testbed_api.c @@ -11,7 +11,7 @@ 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 . @@ -33,14 +33,14 @@ /** * Generic logging shortcut */ -#define LOG(kind,...) \ - GNUNET_log (kind, __VA_ARGS__) +#define LOG(kind, ...) \ + GNUNET_log(kind, __VA_ARGS__) /** * Relative time seconds shorthand */ #define TIME_REL_SECS(sec) \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec) + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, sec) /** * Our localhost @@ -101,8 +101,7 @@ static int result; /** * Enumeration of sub testcases */ -enum Test -{ +enum Test { /** * Test cases which are not covered by the below ones */ @@ -136,23 +135,23 @@ static enum Test sub_test; * @param tc the task context */ static void -do_shutdown (void *cls) +do_shutdown(void *cls) { - LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down...\n"); + LOG(GNUNET_ERROR_TYPE_DEBUG, "Shutting down...\n"); if (NULL != abort_task) - GNUNET_SCHEDULER_cancel (abort_task); + GNUNET_SCHEDULER_cancel(abort_task); if (NULL != reg_handle) - GNUNET_TESTBED_cancel_registration (reg_handle); + GNUNET_TESTBED_cancel_registration(reg_handle); if (NULL != controller) - GNUNET_TESTBED_controller_disconnect (controller); + GNUNET_TESTBED_controller_disconnect(controller); if (NULL != cfg) - GNUNET_CONFIGURATION_destroy (cfg); + GNUNET_CONFIGURATION_destroy(cfg); if (NULL != cp) - GNUNET_TESTBED_controller_stop (cp); + GNUNET_TESTBED_controller_stop(cp); if (NULL != neighbour) - GNUNET_TESTBED_host_destroy (neighbour); + GNUNET_TESTBED_host_destroy(neighbour); if (NULL != host) - GNUNET_TESTBED_host_destroy (host); + GNUNET_TESTBED_host_destroy(host); } @@ -160,14 +159,14 @@ do_shutdown (void *cls) * shortcut to exit during failure */ #define FAIL_TEST(cond, ret) do { \ - if (!(cond)) { \ - GNUNET_break(0); \ - if (NULL != abort_task) \ - GNUNET_SCHEDULER_cancel (abort_task); \ - abort_task = NULL; \ - GNUNET_SCHEDULER_add_now (do_shutdown, NULL); \ - ret; \ - } \ + if (!(cond)) { \ + GNUNET_break(0); \ + if (NULL != abort_task) \ + GNUNET_SCHEDULER_cancel (abort_task); \ + abort_task = NULL; \ + GNUNET_SCHEDULER_add_now(do_shutdown, NULL); \ + ret; \ + } \ } while (0) @@ -178,11 +177,11 @@ do_shutdown (void *cls) * @param tc the task context */ static void -do_abort (void *cls) +do_abort(void *cls) { - LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); + LOG(GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); abort_task = NULL; - do_shutdown (cls); + do_shutdown(cls); } @@ -197,13 +196,13 @@ do_abort (void *cls) * @return service handle to return in 'op_result', NULL on error */ static void * -arm_connect_adapter (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg) +arm_connect_adapter(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg) { - FAIL_TEST (NULL == cls, return NULL); - FAIL_TEST (OTHER == sub_test, return NULL); + FAIL_TEST(NULL == cls, return NULL); + FAIL_TEST(OTHER == sub_test, return NULL); sub_test = PEER_SERVICE_CONNECT; - arm_handle = GNUNET_ARM_connect (cfg, NULL, NULL); + arm_handle = GNUNET_ARM_connect(cfg, NULL, NULL); return arm_handle; } @@ -216,17 +215,17 @@ arm_connect_adapter (void *cls, * @param op_result service handle returned from the connect adapter */ static void -arm_disconnect_adapter (void *cls, - void *op_result) +arm_disconnect_adapter(void *cls, + void *op_result) { - FAIL_TEST (NULL != op_result, return); - FAIL_TEST (op_result == arm_handle, return); - GNUNET_ARM_disconnect (arm_handle); + FAIL_TEST(NULL != op_result, return ); + FAIL_TEST(op_result == arm_handle, return ); + GNUNET_ARM_disconnect(arm_handle); arm_handle = NULL; - FAIL_TEST (PEER_SERVICE_CONNECT == sub_test, return); - FAIL_TEST (NULL != operation, return); - operation = GNUNET_TESTBED_peer_stop (NULL, peer, NULL, NULL); - FAIL_TEST (NULL != operation, return); + FAIL_TEST(PEER_SERVICE_CONNECT == sub_test, return ); + FAIL_TEST(NULL != operation, return ); + operation = GNUNET_TESTBED_peer_stop(NULL, peer, NULL, NULL); + FAIL_TEST(NULL != operation, return ); } @@ -240,24 +239,25 @@ arm_disconnect_adapter (void *cls, * operation has executed successfully. */ static void -service_connect_comp_cb (void *cls, - struct GNUNET_TESTBED_Operation *op, - void *ca_result, - const char *emsg) +service_connect_comp_cb(void *cls, + struct GNUNET_TESTBED_Operation *op, + void *ca_result, + const char *emsg) { switch (sub_test) - { - case PEER_SERVICE_CONNECT: - FAIL_TEST (operation == op, return); - FAIL_TEST (NULL == emsg, return); - FAIL_TEST (NULL == cls, return); - FAIL_TEST (ca_result == arm_handle, return); - GNUNET_TESTBED_operation_done (operation); /* This results in call to + { + case PEER_SERVICE_CONNECT: + FAIL_TEST(operation == op, return ); + FAIL_TEST(NULL == emsg, return ); + FAIL_TEST(NULL == cls, return ); + FAIL_TEST(ca_result == arm_handle, return ); + GNUNET_TESTBED_operation_done(operation); /* This results in call to * disconnect adapter */ - break; - default: - FAIL_TEST (0, return); - } + break; + + default: + FAIL_TEST(0, return ); + } } @@ -272,27 +272,28 @@ service_connect_comp_cb (void *cls, * operation is successfull */ static void -peerinfo_cb (void *cb_cls, - struct GNUNET_TESTBED_Operation *op, - const struct GNUNET_TESTBED_PeerInformation *pinfo, - const char *emsg) +peerinfo_cb(void *cb_cls, + struct GNUNET_TESTBED_Operation *op, + const struct GNUNET_TESTBED_PeerInformation *pinfo, + const char *emsg) { switch (sub_test) - { - case PEER_GETCONFIG: - FAIL_TEST (NULL != pinfo, return); - FAIL_TEST (NULL == emsg, return); - FAIL_TEST (NULL == cb_cls, return); - FAIL_TEST (operation == op, return); - FAIL_TEST (GNUNET_TESTBED_PIT_CONFIGURATION == pinfo->pit, return); - FAIL_TEST (NULL != pinfo->result.cfg, return); - sub_test = PEER_DESTROY; - GNUNET_TESTBED_operation_done (operation); - operation = GNUNET_TESTBED_peer_destroy (peer); - break; - default: - FAIL_TEST (0, return); - } + { + case PEER_GETCONFIG: + FAIL_TEST(NULL != pinfo, return ); + FAIL_TEST(NULL == emsg, return ); + FAIL_TEST(NULL == cb_cls, return ); + FAIL_TEST(operation == op, return ); + FAIL_TEST(GNUNET_TESTBED_PIT_CONFIGURATION == pinfo->pit, return ); + FAIL_TEST(NULL != pinfo->result.cfg, return ); + sub_test = PEER_DESTROY; + GNUNET_TESTBED_operation_done(operation); + operation = GNUNET_TESTBED_peer_destroy(peer); + break; + + default: + FAIL_TEST(0, return ); + } } @@ -304,60 +305,65 @@ peerinfo_cb (void *cb_cls, * @param event information about the event */ static void -controller_cb (void *cls, - const struct GNUNET_TESTBED_EventInformation *event) +controller_cb(void *cls, + const struct GNUNET_TESTBED_EventInformation *event) { switch (event->type) - { - case GNUNET_TESTBED_ET_OPERATION_FINISHED: - switch (sub_test) { - case PEER_DESTROY: - FAIL_TEST (event->op == operation, return); - FAIL_TEST (NULL == event->op_cls, return); - FAIL_TEST (NULL == event->details.operation_finished.emsg, return); - FAIL_TEST (NULL == event->details.operation_finished.generic, return); - GNUNET_TESTBED_operation_done (operation); - GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); + case GNUNET_TESTBED_ET_OPERATION_FINISHED: + switch (sub_test) + { + case PEER_DESTROY: + FAIL_TEST(event->op == operation, return ); + FAIL_TEST(NULL == event->op_cls, return ); + FAIL_TEST(NULL == event->details.operation_finished.emsg, return ); + FAIL_TEST(NULL == event->details.operation_finished.generic, return ); + GNUNET_TESTBED_operation_done(operation); + GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); + break; + + case PEER_SERVICE_CONNECT: + FAIL_TEST(event->op == operation, return ); + FAIL_TEST(NULL == event->op_cls, return ); + FAIL_TEST(NULL == event->details.operation_finished.emsg, return ); + FAIL_TEST(NULL != arm_handle, return ); + FAIL_TEST(event->details.operation_finished.generic == arm_handle, return ); + break; + + default: + FAIL_TEST(0, return ); + break; + } break; - case PEER_SERVICE_CONNECT: - FAIL_TEST (event->op == operation, return); - FAIL_TEST (NULL == event->op_cls, return); - FAIL_TEST (NULL == event->details.operation_finished.emsg, return); - FAIL_TEST (NULL != arm_handle, return); - FAIL_TEST (event->details.operation_finished.generic == arm_handle, return); + + case GNUNET_TESTBED_ET_PEER_START: + FAIL_TEST(event->details.peer_start.host == host, return ); + FAIL_TEST(event->details.peer_start.peer == peer, return ); + FAIL_TEST(OTHER == sub_test, return ); + GNUNET_TESTBED_operation_done(operation); + operation = + GNUNET_TESTBED_service_connect(NULL, peer, "dht", + &service_connect_comp_cb, NULL, + &arm_connect_adapter, + &arm_disconnect_adapter, NULL); + FAIL_TEST(NULL != operation, return ); break; - default: - FAIL_TEST (0, return); + + case GNUNET_TESTBED_ET_PEER_STOP: + FAIL_TEST(event->details.peer_stop.peer == peer, return ); + FAIL_TEST(PEER_SERVICE_CONNECT == sub_test, return ); + result = GNUNET_YES; + sub_test = PEER_GETCONFIG; + GNUNET_TESTBED_operation_done(operation); + operation = + GNUNET_TESTBED_peer_get_information(peer, + GNUNET_TESTBED_PIT_CONFIGURATION, + &peerinfo_cb, NULL); break; + + default: + FAIL_TEST(0, return ); /* We should never reach this state */ } - break; - case GNUNET_TESTBED_ET_PEER_START: - FAIL_TEST (event->details.peer_start.host == host, return); - FAIL_TEST (event->details.peer_start.peer == peer, return); - FAIL_TEST (OTHER == sub_test, return); - GNUNET_TESTBED_operation_done (operation); - operation = - GNUNET_TESTBED_service_connect (NULL, peer, "dht", - &service_connect_comp_cb, NULL, - &arm_connect_adapter, - &arm_disconnect_adapter, NULL); - FAIL_TEST (NULL != operation, return); - break; - case GNUNET_TESTBED_ET_PEER_STOP: - FAIL_TEST (event->details.peer_stop.peer == peer, return); - FAIL_TEST (PEER_SERVICE_CONNECT == sub_test, return); - result = GNUNET_YES; - sub_test = PEER_GETCONFIG; - GNUNET_TESTBED_operation_done (operation); - operation = - GNUNET_TESTBED_peer_get_information (peer, - GNUNET_TESTBED_PIT_CONFIGURATION, - &peerinfo_cb, NULL); - break; - default: - FAIL_TEST (0, return); /* We should never reach this state */ - } } @@ -371,22 +377,22 @@ controller_cb (void *cls, * @param emsg NULL if peer is not NULL; else MAY contain the error description */ static void -peer_create_cb (void *cls, - struct GNUNET_TESTBED_Peer *peer, - const char *emsg) +peer_create_cb(void *cls, + struct GNUNET_TESTBED_Peer *peer, + const char *emsg) { struct GNUNET_TESTBED_Peer **peer_ptr; peer_ptr = cls; - FAIL_TEST (NULL != peer, return); - FAIL_TEST (NULL != peer_ptr, return); + FAIL_TEST(NULL != peer, return ); + FAIL_TEST(NULL != peer_ptr, return ); *peer_ptr = peer; - GNUNET_TESTBED_operation_done (operation); - operation = GNUNET_TESTBED_peer_start (NULL, - peer, - NULL, - NULL); - FAIL_TEST (NULL != operation, return); + GNUNET_TESTBED_operation_done(operation); + operation = GNUNET_TESTBED_peer_start(NULL, + peer, + NULL, + NULL); + FAIL_TEST(NULL != operation, return ); } @@ -397,18 +403,18 @@ peer_create_cb (void *cls, * @param emsg the error message; NULL if host registration is successful */ static void -registration_comp (void *cls, - const char *emsg) +registration_comp(void *cls, + const char *emsg) { - FAIL_TEST (cls == neighbour, return); + FAIL_TEST(cls == neighbour, return ); reg_handle = NULL; operation = - GNUNET_TESTBED_peer_create (controller, - host, - cfg, - &peer_create_cb, - &peer); - FAIL_TEST (NULL != operation, return); + GNUNET_TESTBED_peer_create(controller, + host, + cfg, + &peer_create_cb, + &peer); + FAIL_TEST(NULL != operation, return ); } @@ -422,33 +428,33 @@ registration_comp (void *cls, * GNUNET_TESTBED_controller_stop() shouldn't be called in this case */ static void -status_cb (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg_, - int status) +status_cb(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg_, + int status) { uint64_t event_mask; if (GNUNET_OK != status) - { - cp = NULL; - FAIL_TEST (0, return); - return; - } + { + cp = NULL; + FAIL_TEST(0, return ); + return; + } event_mask = 0; event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START); event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED); controller = - GNUNET_TESTBED_controller_connect (host, event_mask, &controller_cb, - NULL); - FAIL_TEST (NULL != controller, return); - neighbour = GNUNET_TESTBED_host_create ("localhost", NULL, cfg, 0); - FAIL_TEST (NULL != neighbour, return); + GNUNET_TESTBED_controller_connect(host, event_mask, &controller_cb, + NULL); + FAIL_TEST(NULL != controller, return ); + neighbour = GNUNET_TESTBED_host_create("localhost", NULL, cfg, 0); + FAIL_TEST(NULL != neighbour, return ); reg_handle = - GNUNET_TESTBED_register_host (controller, neighbour, ®istration_comp, - neighbour); - FAIL_TEST (NULL != reg_handle, return); + GNUNET_TESTBED_register_host(controller, neighbour, ®istration_comp, + neighbour); + FAIL_TEST(NULL != reg_handle, return ); } @@ -462,22 +468,22 @@ status_cb (void *cls, * @param cfg the configuration file handle */ static void -run (void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *config) +run(void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *config) { - cfg = GNUNET_CONFIGURATION_dup (config); - host = GNUNET_TESTBED_host_create (NULL, NULL, cfg, 0); - FAIL_TEST (NULL != host, return); - cp = GNUNET_TESTBED_controller_start ("127.0.0.1", host, - &status_cb, - NULL); + cfg = GNUNET_CONFIGURATION_dup(config); + host = GNUNET_TESTBED_host_create(NULL, NULL, cfg, 0); + FAIL_TEST(NULL != host, return ); + cp = GNUNET_TESTBED_controller_start("127.0.0.1", host, + &status_cb, + NULL); abort_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_MINUTES, 5), - &do_abort, - NULL); + GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_MINUTES, 5), + &do_abort, + NULL); } @@ -485,22 +491,21 @@ run (void *cls, * Main function */ int -main (int argc, char **argv) +main(int argc, char **argv) { int ret; char *const argv2[] = { "test_testbed_api", - "-c", "test_testbed_api.conf", - NULL - }; + "-c", "test_testbed_api.conf", + NULL }; struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; result = GNUNET_SYSERR; ret = - GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, - "test_testbed_api", "nohelp", options, &run, NULL); + GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, argv2, + "test_testbed_api", "nohelp", options, &run, NULL); if ((GNUNET_OK != ret) || (GNUNET_OK != result)) return 1; return 0; diff --git a/src/testbed/test_testbed_api_2peers_1controller.c b/src/testbed/test_testbed_api_2peers_1controller.c index dcb6a174f..23d9823f5 100644 --- a/src/testbed/test_testbed_api_2peers_1controller.c +++ b/src/testbed/test_testbed_api_2peers_1controller.c @@ -11,7 +11,7 @@ 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 . @@ -34,20 +34,19 @@ /** * Generic logging shortcut */ -#define LOG(kind,...) \ - GNUNET_log (kind, __VA_ARGS__) +#define LOG(kind, ...) \ + GNUNET_log(kind, __VA_ARGS__) /** * Relative time seconds shorthand */ #define TIME_REL_SECS(sec) \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec) + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, sec) /** * Peer context */ -struct PeerContext -{ +struct PeerContext { /** * The peer handle */ @@ -122,9 +121,7 @@ static struct GNUNET_SCHEDULER_Task * delayed_connect_task; /** * Different stages in testing */ -enum Stage -{ - +enum Stage { /** * Initial stage */ @@ -171,14 +168,14 @@ static enum Stage result; * shortcut to exit during failure */ #define FAIL_TEST(cond) do { \ - if (!(cond)) { \ - GNUNET_break(0); \ - if (NULL != abort_task) \ - GNUNET_SCHEDULER_cancel (abort_task); \ - abort_task = NULL; \ - GNUNET_SCHEDULER_add_now (do_shutdown, NULL); \ - return; \ - } \ + if (!(cond)) { \ + GNUNET_break(0); \ + if (NULL != abort_task) \ + GNUNET_SCHEDULER_cancel (abort_task); \ + abort_task = NULL; \ + GNUNET_SCHEDULER_add_now(do_shutdown, NULL); \ + return; \ + } \ } while (0) @@ -188,20 +185,20 @@ static enum Stage result; * @param cls NULL */ static void -do_shutdown (void *cls) +do_shutdown(void *cls) { if (NULL != abort_task) - GNUNET_SCHEDULER_cancel (abort_task); + GNUNET_SCHEDULER_cancel(abort_task); if (NULL != delayed_connect_task) - GNUNET_SCHEDULER_cancel (delayed_connect_task); + GNUNET_SCHEDULER_cancel(delayed_connect_task); if (NULL != reg_handle) - GNUNET_TESTBED_cancel_registration (reg_handle); - GNUNET_TESTBED_controller_disconnect (controller); - GNUNET_CONFIGURATION_destroy (cfg); + GNUNET_TESTBED_cancel_registration(reg_handle); + GNUNET_TESTBED_controller_disconnect(controller); + GNUNET_CONFIGURATION_destroy(cfg); if (NULL != cp) - GNUNET_TESTBED_controller_stop (cp); - GNUNET_TESTBED_host_destroy (neighbour); - GNUNET_TESTBED_host_destroy (host); + GNUNET_TESTBED_controller_stop(cp); + GNUNET_TESTBED_host_destroy(neighbour); + GNUNET_TESTBED_host_destroy(host); } @@ -211,11 +208,11 @@ do_shutdown (void *cls) * @param cls NULL */ static void -do_abort (void *cls) +do_abort(void *cls) { - LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); + LOG(GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); abort_task = NULL; - do_shutdown (cls); + do_shutdown(cls); } @@ -228,7 +225,7 @@ do_abort (void *cls) * operation has executed successfully. */ static void -op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg); +op_comp_cb(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg); /** @@ -237,13 +234,13 @@ op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg); * @param cls NULL */ static void -do_delayed_connect (void *cls) +do_delayed_connect(void *cls) { delayed_connect_task = NULL; - FAIL_TEST (NULL == common_operation); + FAIL_TEST(NULL == common_operation); common_operation = - GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer1.peer, - peer2.peer); + GNUNET_TESTBED_overlay_connect(NULL, &op_comp_cb, NULL, peer1.peer, + peer2.peer); } @@ -256,24 +253,26 @@ do_delayed_connect (void *cls) * operation has executed successfully. */ static void -op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg) +op_comp_cb(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg) { - FAIL_TEST (common_operation == op); + FAIL_TEST(common_operation == op); switch (result) - { - case PEERS_STARTED: - FAIL_TEST (NULL == peer1.operation); - FAIL_TEST (NULL == peer2.operation); - FAIL_TEST (NULL != common_operation); - break; - case PEERS_CONNECTED: - FAIL_TEST (NULL == peer1.operation); - FAIL_TEST (NULL == peer2.operation); - FAIL_TEST (NULL != common_operation); - break; - default: - FAIL_TEST (0); - } + { + case PEERS_STARTED: + FAIL_TEST(NULL == peer1.operation); + FAIL_TEST(NULL == peer2.operation); + FAIL_TEST(NULL != common_operation); + break; + + case PEERS_CONNECTED: + FAIL_TEST(NULL == peer1.operation); + FAIL_TEST(NULL == peer2.operation); + FAIL_TEST(NULL != common_operation); + break; + + default: + FAIL_TEST(0); + } } @@ -285,114 +284,121 @@ op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg) * @param event information about the event */ static void -controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) +controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event) { switch (event->type) - { - case GNUNET_TESTBED_ET_OPERATION_FINISHED: /* Will be reached when we destroy peers */ - FAIL_TEST (PEERS_STOPPED == result); - FAIL_TEST (NULL == event->op_cls); - FAIL_TEST (NULL == event->details.operation_finished.emsg); - FAIL_TEST (NULL == event->details.operation_finished.generic); - if (event->op == peer1.operation) - { - GNUNET_TESTBED_operation_done (peer1.operation); - peer1.operation = NULL; - peer1.peer = NULL; - } - else if (event->op == peer2.operation) - { - GNUNET_TESTBED_operation_done (peer2.operation); - peer2.operation = NULL; - peer2.peer = NULL; - } - else - FAIL_TEST (0); - if ((NULL == peer1.peer) && (NULL == peer2.peer)) - { - result = SUCCESS; - GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); - } - break; - case GNUNET_TESTBED_ET_PEER_START: - FAIL_TEST (INIT == result); - FAIL_TEST (event->details.peer_start.host == host); - if (event->details.peer_start.peer == peer1.peer) - { - peer1.is_running = GNUNET_YES; - GNUNET_TESTBED_operation_done (peer1.operation); - peer1.operation = NULL; - } - else if (event->details.peer_start.peer == peer2.peer) - { - peer2.is_running = GNUNET_YES; - GNUNET_TESTBED_operation_done (peer2.operation); - peer2.operation = NULL; - } - else - FAIL_TEST (0); - if ((GNUNET_YES == peer1.is_running) && (GNUNET_YES == peer2.is_running)) - { - result = PEERS_STARTED; - common_operation = - GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer1.peer, - peer2.peer); - } - break; - case GNUNET_TESTBED_ET_PEER_STOP: - FAIL_TEST (PEERS_CONNECTED_2 == result); - if (event->details.peer_stop.peer == peer1.peer) { - peer1.is_running = GNUNET_NO; - GNUNET_TESTBED_operation_done (peer1.operation); - peer1.operation = GNUNET_TESTBED_peer_destroy (peer1.peer); - } - else if (event->details.peer_stop.peer == peer2.peer) - { - peer2.is_running = GNUNET_NO; - GNUNET_TESTBED_operation_done (peer2.operation); - peer2.operation = GNUNET_TESTBED_peer_destroy (peer2.peer); - } - else - FAIL_TEST (0); - if ((GNUNET_NO == peer1.is_running) && (GNUNET_NO == peer2.is_running)) - result = PEERS_STOPPED; - break; - case GNUNET_TESTBED_ET_CONNECT: - switch (result) - { - case PEERS_STARTED: - FAIL_TEST (NULL == peer1.operation); - FAIL_TEST (NULL == peer2.operation); - FAIL_TEST (NULL != common_operation); - FAIL_TEST ((event->details.peer_connect.peer1 == peer1.peer) && - (event->details.peer_connect.peer2 == peer2.peer)); - GNUNET_TESTBED_operation_done (common_operation); - common_operation = NULL; - result = PEERS_CONNECTED; - LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n"); - delayed_connect_task = - GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (3), &do_delayed_connect, - NULL); + case GNUNET_TESTBED_ET_OPERATION_FINISHED: /* Will be reached when we destroy peers */ + FAIL_TEST(PEERS_STOPPED == result); + FAIL_TEST(NULL == event->op_cls); + FAIL_TEST(NULL == event->details.operation_finished.emsg); + FAIL_TEST(NULL == event->details.operation_finished.generic); + if (event->op == peer1.operation) + { + GNUNET_TESTBED_operation_done(peer1.operation); + peer1.operation = NULL; + peer1.peer = NULL; + } + else if (event->op == peer2.operation) + { + GNUNET_TESTBED_operation_done(peer2.operation); + peer2.operation = NULL; + peer2.peer = NULL; + } + else + FAIL_TEST(0); + if ((NULL == peer1.peer) && (NULL == peer2.peer)) + { + result = SUCCESS; + GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); + } break; - case PEERS_CONNECTED: - FAIL_TEST (NULL == peer1.operation); - FAIL_TEST (NULL == peer2.operation); - FAIL_TEST (NULL != common_operation); - GNUNET_TESTBED_operation_done (common_operation); - common_operation = NULL; - result = PEERS_CONNECTED_2; - LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected again\n"); - peer1.operation = GNUNET_TESTBED_peer_stop (NULL, peer1.peer, NULL, NULL); - peer2.operation = GNUNET_TESTBED_peer_stop (NULL, peer2.peer, NULL, NULL); + + case GNUNET_TESTBED_ET_PEER_START: + FAIL_TEST(INIT == result); + FAIL_TEST(event->details.peer_start.host == host); + if (event->details.peer_start.peer == peer1.peer) + { + peer1.is_running = GNUNET_YES; + GNUNET_TESTBED_operation_done(peer1.operation); + peer1.operation = NULL; + } + else if (event->details.peer_start.peer == peer2.peer) + { + peer2.is_running = GNUNET_YES; + GNUNET_TESTBED_operation_done(peer2.operation); + peer2.operation = NULL; + } + else + FAIL_TEST(0); + if ((GNUNET_YES == peer1.is_running) && (GNUNET_YES == peer2.is_running)) + { + result = PEERS_STARTED; + common_operation = + GNUNET_TESTBED_overlay_connect(NULL, &op_comp_cb, NULL, peer1.peer, + peer2.peer); + } + break; + + case GNUNET_TESTBED_ET_PEER_STOP: + FAIL_TEST(PEERS_CONNECTED_2 == result); + if (event->details.peer_stop.peer == peer1.peer) + { + peer1.is_running = GNUNET_NO; + GNUNET_TESTBED_operation_done(peer1.operation); + peer1.operation = GNUNET_TESTBED_peer_destroy(peer1.peer); + } + else if (event->details.peer_stop.peer == peer2.peer) + { + peer2.is_running = GNUNET_NO; + GNUNET_TESTBED_operation_done(peer2.operation); + peer2.operation = GNUNET_TESTBED_peer_destroy(peer2.peer); + } + else + FAIL_TEST(0); + if ((GNUNET_NO == peer1.is_running) && (GNUNET_NO == peer2.is_running)) + result = PEERS_STOPPED; + break; + + case GNUNET_TESTBED_ET_CONNECT: + switch (result) + { + case PEERS_STARTED: + FAIL_TEST(NULL == peer1.operation); + FAIL_TEST(NULL == peer2.operation); + FAIL_TEST(NULL != common_operation); + FAIL_TEST((event->details.peer_connect.peer1 == peer1.peer) && + (event->details.peer_connect.peer2 == peer2.peer)); + GNUNET_TESTBED_operation_done(common_operation); + common_operation = NULL; + result = PEERS_CONNECTED; + LOG(GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n"); + delayed_connect_task = + GNUNET_SCHEDULER_add_delayed(TIME_REL_SECS(3), &do_delayed_connect, + NULL); + break; + + case PEERS_CONNECTED: + FAIL_TEST(NULL == peer1.operation); + FAIL_TEST(NULL == peer2.operation); + FAIL_TEST(NULL != common_operation); + GNUNET_TESTBED_operation_done(common_operation); + common_operation = NULL; + result = PEERS_CONNECTED_2; + LOG(GNUNET_ERROR_TYPE_DEBUG, "Peers connected again\n"); + peer1.operation = GNUNET_TESTBED_peer_stop(NULL, peer1.peer, NULL, NULL); + peer2.operation = GNUNET_TESTBED_peer_stop(NULL, peer2.peer, NULL, NULL); + break; + + default: + FAIL_TEST(0); + } break; + default: - FAIL_TEST (0); + FAIL_TEST(0); } - break; - default: - FAIL_TEST (0); - }; + ; } @@ -406,16 +412,16 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) * @param emsg NULL if peer is not NULL; else MAY contain the error description */ static void -peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) +peer_create_cb(void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) { struct PeerContext *pc = cls; - FAIL_TEST (NULL != pc->operation); - FAIL_TEST (NULL != peer); - FAIL_TEST (NULL == pc->peer); + FAIL_TEST(NULL != pc->operation); + FAIL_TEST(NULL != peer); + FAIL_TEST(NULL == pc->peer); pc->peer = peer; - GNUNET_TESTBED_operation_done (pc->operation); - pc->operation = GNUNET_TESTBED_peer_start (NULL, pc->peer, NULL, NULL); + GNUNET_TESTBED_operation_done(pc->operation); + pc->operation = GNUNET_TESTBED_peer_start(NULL, pc->peer, NULL, NULL); } @@ -426,18 +432,18 @@ peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) * @param emsg the error message; NULL if host registration is successful */ static void -registration_comp (void *cls, const char *emsg) +registration_comp(void *cls, const char *emsg) { - FAIL_TEST (cls == neighbour); + FAIL_TEST(cls == neighbour); reg_handle = NULL; peer1.operation = - GNUNET_TESTBED_peer_create (controller, host, cfg, &peer_create_cb, - &peer1); + GNUNET_TESTBED_peer_create(controller, host, cfg, &peer_create_cb, + &peer1); peer2.operation = - GNUNET_TESTBED_peer_create (controller, host, cfg, &peer_create_cb, - &peer2); - FAIL_TEST (NULL != peer1.operation); - FAIL_TEST (NULL != peer2.operation); + GNUNET_TESTBED_peer_create(controller, host, cfg, &peer_create_cb, + &peer2); + FAIL_TEST(NULL != peer1.operation); + FAIL_TEST(NULL != peer2.operation); } @@ -451,30 +457,30 @@ registration_comp (void *cls, const char *emsg) * GNUNET_TESTBED_controller_stop() shouldn't be called in this case */ static void -status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg_, int status) +status_cb(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg_, int status) { uint64_t event_mask; if (GNUNET_OK != status) - { - cp = NULL; - FAIL_TEST (0); - } + { + cp = NULL; + FAIL_TEST(0); + } event_mask = 0; event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START); event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED); controller = - GNUNET_TESTBED_controller_connect (host, event_mask, &controller_cb, - NULL); - FAIL_TEST (NULL != controller); - neighbour = GNUNET_TESTBED_host_create ("localhost", NULL, cfg, 0); - FAIL_TEST (NULL != neighbour); + GNUNET_TESTBED_controller_connect(host, event_mask, &controller_cb, + NULL); + FAIL_TEST(NULL != controller); + neighbour = GNUNET_TESTBED_host_create("localhost", NULL, cfg, 0); + FAIL_TEST(NULL != neighbour); reg_handle = - GNUNET_TESTBED_register_host (controller, neighbour, ®istration_comp, - neighbour); - FAIL_TEST (NULL != reg_handle); + GNUNET_TESTBED_register_host(controller, neighbour, ®istration_comp, + neighbour); + FAIL_TEST(NULL != reg_handle); } @@ -488,18 +494,18 @@ status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg_, int status * @param cfg the configuration file handle */ static void -run (void *cls, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *config) +run(void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *config) { - cfg = GNUNET_CONFIGURATION_dup (config); - host = GNUNET_TESTBED_host_create (NULL, NULL, cfg, 0); - FAIL_TEST (NULL != host); - cp = GNUNET_TESTBED_controller_start ("127.0.0.1", host, status_cb, - NULL); + cfg = GNUNET_CONFIGURATION_dup(config); + host = GNUNET_TESTBED_host_create(NULL, NULL, cfg, 0); + FAIL_TEST(NULL != host); + cp = GNUNET_TESTBED_controller_start("127.0.0.1", host, status_cb, + NULL); abort_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort, - NULL); + GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort, + NULL); } @@ -507,22 +513,22 @@ run (void *cls, char *const *args, const char *cfgfile, * Main function */ int -main (int argc, char **argv) +main(int argc, char **argv) { int ret; char *const argv2[] = { "test_testbed_api_2peers_1controller", - "-c", "test_testbed_api.conf", - NULL - }; + "-c", "test_testbed_api.conf", + NULL }; struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; + result = INIT; ret = - GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, - "test_testbed_api_2peers_1controller", "nohelp", - options, &run, NULL); + GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, argv2, + "test_testbed_api_2peers_1controller", "nohelp", + options, &run, NULL); if ((GNUNET_OK != ret) || (SUCCESS != result)) return 1; return 0; diff --git a/src/testbed/test_testbed_api_3peers_3controllers.c b/src/testbed/test_testbed_api_3peers_3controllers.c index 1d1d1ce44..ec396d6ca 100644 --- a/src/testbed/test_testbed_api_3peers_3controllers.c +++ b/src/testbed/test_testbed_api_3peers_3controllers.c @@ -11,7 +11,7 @@ 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 . @@ -51,21 +51,20 @@ /** * Generic logging shortcut */ -#define LOG(kind,...) \ - GNUNET_log (kind, __VA_ARGS__) +#define LOG(kind, ...) \ + GNUNET_log(kind, __VA_ARGS__) /** * Relative time seconds shorthand */ #define TIME_REL_SECS(sec) \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec) + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, sec) /** * Peer context */ -struct PeerContext -{ +struct PeerContext { /** * The peer handle */ @@ -161,9 +160,7 @@ static struct GNUNET_SCHEDULER_Task * delayed_connect_task; /** * Different stages in testing */ -enum Stage -{ - +enum Stage { /** * Initial stage */ @@ -256,30 +253,30 @@ static enum Stage result; * @param cls NULL */ static void -do_shutdown (void *cls) +do_shutdown(void *cls) { if (NULL != abort_task) - GNUNET_SCHEDULER_cancel (abort_task); + GNUNET_SCHEDULER_cancel(abort_task); if (NULL != hc_handle) - GNUNET_TESTBED_is_host_habitable_cancel (hc_handle); - GNUNET_assert (NULL == delayed_connect_task); + GNUNET_TESTBED_is_host_habitable_cancel(hc_handle); + GNUNET_assert(NULL == delayed_connect_task); if (NULL != common_operation) - GNUNET_TESTBED_operation_done (common_operation); + GNUNET_TESTBED_operation_done(common_operation); if (NULL != reg_handle) - GNUNET_TESTBED_cancel_registration (reg_handle); + GNUNET_TESTBED_cancel_registration(reg_handle); if (NULL != controller1) - GNUNET_TESTBED_controller_disconnect (controller1); - GNUNET_CONFIGURATION_destroy (cfg); + GNUNET_TESTBED_controller_disconnect(controller1); + GNUNET_CONFIGURATION_destroy(cfg); if (NULL != cfg2) - GNUNET_CONFIGURATION_destroy (cfg2); + GNUNET_CONFIGURATION_destroy(cfg2); if (NULL != cp1) - GNUNET_TESTBED_controller_stop (cp1); + GNUNET_TESTBED_controller_stop(cp1); if (NULL != host) - GNUNET_TESTBED_host_destroy (host); + GNUNET_TESTBED_host_destroy(host); if (NULL != neighbour1) - GNUNET_TESTBED_host_destroy (neighbour1); + GNUNET_TESTBED_host_destroy(neighbour1); if (NULL != neighbour2) - GNUNET_TESTBED_host_destroy (neighbour2); + GNUNET_TESTBED_host_destroy(neighbour2); } @@ -289,25 +286,25 @@ do_shutdown (void *cls) * @param cls NULL */ static void -do_abort (void *cls) +do_abort(void *cls) { - LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); + LOG(GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); abort_task = NULL; if (NULL != delayed_connect_task) - { - GNUNET_SCHEDULER_cancel (delayed_connect_task); - delayed_connect_task = NULL; - } - do_shutdown (cls); + { + GNUNET_SCHEDULER_cancel(delayed_connect_task); + delayed_connect_task = NULL; + } + do_shutdown(cls); } static void -abort_test () +abort_test() { if (NULL != abort_task) - GNUNET_SCHEDULER_cancel (abort_task); - abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); + GNUNET_SCHEDULER_cancel(abort_task); + abort_task = GNUNET_SCHEDULER_add_now(&do_abort, NULL); } @@ -320,7 +317,7 @@ abort_test () * operation has executed successfully. */ static void -op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg); +op_comp_cb(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg); /** @@ -329,18 +326,18 @@ op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg); * @param cls NULL */ static void -do_delayed_connect (void *cls) +do_delayed_connect(void *cls) { delayed_connect_task = NULL; if (NULL != common_operation) - { - GNUNET_break (0); - abort_test (); - return; - } + { + GNUNET_break(0); + abort_test(); + return; + } common_operation = - GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer1.peer, - peer2.peer); + GNUNET_TESTBED_overlay_connect(NULL, &op_comp_cb, NULL, peer1.peer, + peer2.peer); } @@ -353,33 +350,34 @@ do_delayed_connect (void *cls) * operation has executed successfully. */ static void -op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg) +op_comp_cb(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg) { if (common_operation != op) - { - GNUNET_break (0); - abort_test (); - return; - } + { + GNUNET_break(0); + abort_test(); + return; + } switch (result) - { - case PEER3_STARTED: - case PEERS_2_3_CONNECTED: - case PEERS_1_2_CONNECTED: - break; - default: - GNUNET_break (0); - abort_test (); - return; - } + { + case PEER3_STARTED: + case PEERS_2_3_CONNECTED: + case PEERS_1_2_CONNECTED: + break; + + default: + GNUNET_break(0); + abort_test(); + return; + } if ((NULL != peer1.operation) || (NULL != peer2.operation) || (NULL != peer3.operation)) - { - GNUNET_break (0); - abort_test (); - return; - } + { + GNUNET_break(0); + abort_test(); + return; + } } @@ -393,51 +391,54 @@ op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg) * @param emsg NULL if peer is not NULL; else MAY contain the error description */ static void -peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) +peer_create_cb(void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) { switch (result) - { - case CONTROLLER1_UP: - if ((NULL == peer1.operation) || (NULL == peer) || (NULL != peer1.peer)) - { - GNUNET_break (0); - abort_test (); - return; - } - peer1.peer = peer; - GNUNET_TESTBED_operation_done (peer1.operation); - result = PEER1_CREATED; - peer1.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL); - break; - case CONTROLLER2_UP: - if ((NULL == peer2.operation) || (NULL == peer) || (NULL != peer2.peer)) - { - GNUNET_break (0); - abort_test (); - return; - } - peer2.peer = peer; - GNUNET_TESTBED_operation_done (peer2.operation); - result = PEER2_CREATED; - peer2.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL); - break; - case CONTROLLER3_UP: - if ((NULL == peer3.operation) || (NULL == peer) || (NULL != peer3.peer)) { - GNUNET_break (0); - abort_test (); + case CONTROLLER1_UP: + if ((NULL == peer1.operation) || (NULL == peer) || (NULL != peer1.peer)) + { + GNUNET_break(0); + abort_test(); + return; + } + peer1.peer = peer; + GNUNET_TESTBED_operation_done(peer1.operation); + result = PEER1_CREATED; + peer1.operation = GNUNET_TESTBED_peer_start(NULL, peer, NULL, NULL); + break; + + case CONTROLLER2_UP: + if ((NULL == peer2.operation) || (NULL == peer) || (NULL != peer2.peer)) + { + GNUNET_break(0); + abort_test(); + return; + } + peer2.peer = peer; + GNUNET_TESTBED_operation_done(peer2.operation); + result = PEER2_CREATED; + peer2.operation = GNUNET_TESTBED_peer_start(NULL, peer, NULL, NULL); + break; + + case CONTROLLER3_UP: + if ((NULL == peer3.operation) || (NULL == peer) || (NULL != peer3.peer)) + { + GNUNET_break(0); + abort_test(); + return; + } + peer3.peer = peer; + GNUNET_TESTBED_operation_done(peer3.operation); + result = PEER3_CREATED; + peer3.operation = GNUNET_TESTBED_peer_start(NULL, peer, NULL, NULL); + break; + + default: + GNUNET_break(0); + abort_test(); return; } - peer3.peer = peer; - GNUNET_TESTBED_operation_done (peer3.operation); - result = PEER3_CREATED; - peer3.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL); - break; - default: - GNUNET_break (0); - abort_test (); - return; - } } @@ -449,276 +450,289 @@ peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) * @param event information about the event */ static void -controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) +controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event) { switch (event->type) - { - case GNUNET_TESTBED_ET_OPERATION_FINISHED: - if ((NULL != event->op_cls) || - (NULL != event->details.operation_finished.emsg)) - { - GNUNET_break (0); - abort_test (); - return; - } - switch (result) - { - case PEERS_STOPPED: - if (NULL != event->details.operation_finished.generic) - { - GNUNET_break (0); - abort_test (); - return; - } - if (event->op == peer1.operation) - { - GNUNET_TESTBED_operation_done (peer1.operation); - peer1.operation = NULL; - peer1.peer = NULL; - } - else if (event->op == peer2.operation) - { - GNUNET_TESTBED_operation_done (peer2.operation); - peer2.operation = NULL; - peer2.peer = NULL; - } - else if (event->op == peer3.operation) - { - GNUNET_TESTBED_operation_done (peer3.operation); - peer3.operation = NULL; - peer3.peer = NULL; - } - else - { - GNUNET_break (0); - abort_test (); - return; - } - if ((NULL == peer1.peer) && (NULL == peer2.peer) && (NULL == peer3.peer)) - { - result = SUCCESS; - GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); - } - break; - case PEER1_STARTED: - if ((NULL != event->details.operation_finished.generic) || - (NULL == common_operation)) - { - GNUNET_break (0); - abort_test (); - return; - } - GNUNET_TESTBED_operation_done (common_operation); - common_operation = NULL; - result = CONTROLLER2_UP; - peer2.operation = - GNUNET_TESTBED_peer_create (controller1, neighbour1, cfg, - &peer_create_cb, NULL); - if (NULL == peer2.operation) - { - GNUNET_break (0); - abort_test (); - return; - } - break; - case PEER2_STARTED: - if ((NULL != event->details.operation_finished.generic) || - (NULL == common_operation)) - { - GNUNET_break (0); - abort_test (); - return; - } - GNUNET_TESTBED_operation_done (common_operation); - common_operation = NULL; - result = CONTROLLER3_UP; - peer3.operation = - GNUNET_TESTBED_peer_create (controller1, neighbour2, cfg, - &peer_create_cb, NULL); - if (NULL == peer3.operation) - { - GNUNET_break (0); - abort_test (); - return; - } - break; - default: - GNUNET_break (0); - abort_test (); - return; - } - break; - case GNUNET_TESTBED_ET_PEER_START: - switch (result) { - case PEER1_CREATED: - if (event->details.peer_start.host != host) - { - GNUNET_break (0); - abort_test (); - return; - } - peer1.is_running = GNUNET_YES; - GNUNET_TESTBED_operation_done (peer1.operation); - peer1.operation = NULL; - result = PEER1_STARTED; - common_operation = - GNUNET_TESTBED_controller_link (NULL, controller1, neighbour1, NULL, - GNUNET_YES); - break; - case PEER2_CREATED: - if (event->details.peer_start.host != neighbour1) - { - GNUNET_break (0); - abort_test (); - return; - } - peer2.is_running = GNUNET_YES; - GNUNET_TESTBED_operation_done (peer2.operation); - peer2.operation = NULL; - result = PEER2_STARTED; - if (NULL != common_operation) - { - GNUNET_break (0); - abort_test (); - return; - } - common_operation = - GNUNET_TESTBED_controller_link (NULL, controller1, neighbour2, NULL, - GNUNET_YES); - if (NULL == common_operation) - { - GNUNET_break (0); - abort_test (); - return; - } + case GNUNET_TESTBED_ET_OPERATION_FINISHED: + if ((NULL != event->op_cls) || + (NULL != event->details.operation_finished.emsg)) + { + GNUNET_break(0); + abort_test(); + return; + } + switch (result) + { + case PEERS_STOPPED: + if (NULL != event->details.operation_finished.generic) + { + GNUNET_break(0); + abort_test(); + return; + } + if (event->op == peer1.operation) + { + GNUNET_TESTBED_operation_done(peer1.operation); + peer1.operation = NULL; + peer1.peer = NULL; + } + else if (event->op == peer2.operation) + { + GNUNET_TESTBED_operation_done(peer2.operation); + peer2.operation = NULL; + peer2.peer = NULL; + } + else if (event->op == peer3.operation) + { + GNUNET_TESTBED_operation_done(peer3.operation); + peer3.operation = NULL; + peer3.peer = NULL; + } + else + { + GNUNET_break(0); + abort_test(); + return; + } + if ((NULL == peer1.peer) && (NULL == peer2.peer) && (NULL == peer3.peer)) + { + result = SUCCESS; + GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); + } + break; + + case PEER1_STARTED: + if ((NULL != event->details.operation_finished.generic) || + (NULL == common_operation)) + { + GNUNET_break(0); + abort_test(); + return; + } + GNUNET_TESTBED_operation_done(common_operation); + common_operation = NULL; + result = CONTROLLER2_UP; + peer2.operation = + GNUNET_TESTBED_peer_create(controller1, neighbour1, cfg, + &peer_create_cb, NULL); + if (NULL == peer2.operation) + { + GNUNET_break(0); + abort_test(); + return; + } + break; + + case PEER2_STARTED: + if ((NULL != event->details.operation_finished.generic) || + (NULL == common_operation)) + { + GNUNET_break(0); + abort_test(); + return; + } + GNUNET_TESTBED_operation_done(common_operation); + common_operation = NULL; + result = CONTROLLER3_UP; + peer3.operation = + GNUNET_TESTBED_peer_create(controller1, neighbour2, cfg, + &peer_create_cb, NULL); + if (NULL == peer3.operation) + { + GNUNET_break(0); + abort_test(); + return; + } + break; + + default: + GNUNET_break(0); + abort_test(); + return; + } break; - case PEER3_CREATED: - if (event->details.peer_start.host != neighbour2) - { - GNUNET_break (0); - abort_test (); - return; - } - peer3.is_running = GNUNET_YES; - GNUNET_TESTBED_operation_done (peer3.operation); - peer3.operation = NULL; - result = PEER3_STARTED; - common_operation = - GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer2.peer, - peer1.peer); - break; - default: - GNUNET_break (0); - abort_test (); - return; - } - break; - case GNUNET_TESTBED_ET_PEER_STOP: - if (PEERS_CONNECTED_2 != result) - { - GNUNET_break (0); - abort_test (); - return; - } - if (event->details.peer_stop.peer == peer1.peer) - { - peer1.is_running = GNUNET_NO; - GNUNET_TESTBED_operation_done (peer1.operation); - } - else if (event->details.peer_stop.peer == peer2.peer) - { - peer2.is_running = GNUNET_NO; - GNUNET_TESTBED_operation_done (peer2.operation); - } - else if (event->details.peer_stop.peer == peer3.peer) - { - peer3.is_running = GNUNET_NO; - GNUNET_TESTBED_operation_done (peer3.operation); - } - else - { - GNUNET_break (0); - abort_test (); - return; - } - if ((GNUNET_NO == peer1.is_running) && (GNUNET_NO == peer2.is_running) && - (GNUNET_NO == peer3.is_running)) - { - result = PEERS_STOPPED; - peer1.operation = GNUNET_TESTBED_peer_destroy (peer1.peer); - peer2.operation = GNUNET_TESTBED_peer_destroy (peer2.peer); - peer3.operation = GNUNET_TESTBED_peer_destroy (peer3.peer); - } - break; - case GNUNET_TESTBED_ET_CONNECT: - if ((NULL != peer1.operation) || (NULL != peer2.operation) || - (NULL != peer3.operation) || (NULL == common_operation)) - { - GNUNET_break (0); - abort_test (); - return; - } - switch (result) - { - case PEER3_STARTED: - if ((event->details.peer_connect.peer1 != peer2.peer) || - (event->details.peer_connect.peer2 != peer1.peer)) - { - GNUNET_break (0); - abort_test (); - return; - } - GNUNET_TESTBED_operation_done (common_operation); - common_operation = NULL; - result = PEERS_1_2_CONNECTED; - LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n"); - common_operation = - GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer2.peer, - peer3.peer); + + case GNUNET_TESTBED_ET_PEER_START: + switch (result) + { + case PEER1_CREATED: + if (event->details.peer_start.host != host) + { + GNUNET_break(0); + abort_test(); + return; + } + peer1.is_running = GNUNET_YES; + GNUNET_TESTBED_operation_done(peer1.operation); + peer1.operation = NULL; + result = PEER1_STARTED; + common_operation = + GNUNET_TESTBED_controller_link(NULL, controller1, neighbour1, NULL, + GNUNET_YES); + break; + + case PEER2_CREATED: + if (event->details.peer_start.host != neighbour1) + { + GNUNET_break(0); + abort_test(); + return; + } + peer2.is_running = GNUNET_YES; + GNUNET_TESTBED_operation_done(peer2.operation); + peer2.operation = NULL; + result = PEER2_STARTED; + if (NULL != common_operation) + { + GNUNET_break(0); + abort_test(); + return; + } + common_operation = + GNUNET_TESTBED_controller_link(NULL, controller1, neighbour2, NULL, + GNUNET_YES); + if (NULL == common_operation) + { + GNUNET_break(0); + abort_test(); + return; + } + break; + + case PEER3_CREATED: + if (event->details.peer_start.host != neighbour2) + { + GNUNET_break(0); + abort_test(); + return; + } + peer3.is_running = GNUNET_YES; + GNUNET_TESTBED_operation_done(peer3.operation); + peer3.operation = NULL; + result = PEER3_STARTED; + common_operation = + GNUNET_TESTBED_overlay_connect(NULL, &op_comp_cb, NULL, peer2.peer, + peer1.peer); + break; + + default: + GNUNET_break(0); + abort_test(); + return; + } break; - case PEERS_1_2_CONNECTED: - if ((event->details.peer_connect.peer1 != peer2.peer) || - (event->details.peer_connect.peer2 != peer3.peer)) - { - GNUNET_break (0); - abort_test (); - return; - } - GNUNET_TESTBED_operation_done (common_operation); - common_operation = NULL; - result = PEERS_2_3_CONNECTED; - delayed_connect_task = - GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (3), &do_delayed_connect, - NULL); + + case GNUNET_TESTBED_ET_PEER_STOP: + if (PEERS_CONNECTED_2 != result) + { + GNUNET_break(0); + abort_test(); + return; + } + if (event->details.peer_stop.peer == peer1.peer) + { + peer1.is_running = GNUNET_NO; + GNUNET_TESTBED_operation_done(peer1.operation); + } + else if (event->details.peer_stop.peer == peer2.peer) + { + peer2.is_running = GNUNET_NO; + GNUNET_TESTBED_operation_done(peer2.operation); + } + else if (event->details.peer_stop.peer == peer3.peer) + { + peer3.is_running = GNUNET_NO; + GNUNET_TESTBED_operation_done(peer3.operation); + } + else + { + GNUNET_break(0); + abort_test(); + return; + } + if ((GNUNET_NO == peer1.is_running) && (GNUNET_NO == peer2.is_running) && + (GNUNET_NO == peer3.is_running)) + { + result = PEERS_STOPPED; + peer1.operation = GNUNET_TESTBED_peer_destroy(peer1.peer); + peer2.operation = GNUNET_TESTBED_peer_destroy(peer2.peer); + peer3.operation = GNUNET_TESTBED_peer_destroy(peer3.peer); + } break; - case PEERS_2_3_CONNECTED: - if ((event->details.peer_connect.peer1 != peer1.peer) || - (event->details.peer_connect.peer2 != peer2.peer)) - { - GNUNET_break (0); - abort_test (); - return; - } - GNUNET_TESTBED_operation_done (common_operation); - common_operation = NULL; - result = PEERS_CONNECTED_2; - LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected again\n"); - peer1.operation = GNUNET_TESTBED_peer_stop (NULL, peer1.peer, NULL, NULL); - peer2.operation = GNUNET_TESTBED_peer_stop (NULL, peer2.peer, NULL, NULL); - peer3.operation = GNUNET_TESTBED_peer_stop (NULL, peer3.peer, NULL, NULL); + + case GNUNET_TESTBED_ET_CONNECT: + if ((NULL != peer1.operation) || (NULL != peer2.operation) || + (NULL != peer3.operation) || (NULL == common_operation)) + { + GNUNET_break(0); + abort_test(); + return; + } + switch (result) + { + case PEER3_STARTED: + if ((event->details.peer_connect.peer1 != peer2.peer) || + (event->details.peer_connect.peer2 != peer1.peer)) + { + GNUNET_break(0); + abort_test(); + return; + } + GNUNET_TESTBED_operation_done(common_operation); + common_operation = NULL; + result = PEERS_1_2_CONNECTED; + LOG(GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n"); + common_operation = + GNUNET_TESTBED_overlay_connect(NULL, &op_comp_cb, NULL, peer2.peer, + peer3.peer); + break; + + case PEERS_1_2_CONNECTED: + if ((event->details.peer_connect.peer1 != peer2.peer) || + (event->details.peer_connect.peer2 != peer3.peer)) + { + GNUNET_break(0); + abort_test(); + return; + } + GNUNET_TESTBED_operation_done(common_operation); + common_operation = NULL; + result = PEERS_2_3_CONNECTED; + delayed_connect_task = + GNUNET_SCHEDULER_add_delayed(TIME_REL_SECS(3), &do_delayed_connect, + NULL); + break; + + case PEERS_2_3_CONNECTED: + if ((event->details.peer_connect.peer1 != peer1.peer) || + (event->details.peer_connect.peer2 != peer2.peer)) + { + GNUNET_break(0); + abort_test(); + return; + } + GNUNET_TESTBED_operation_done(common_operation); + common_operation = NULL; + result = PEERS_CONNECTED_2; + LOG(GNUNET_ERROR_TYPE_DEBUG, "Peers connected again\n"); + peer1.operation = GNUNET_TESTBED_peer_stop(NULL, peer1.peer, NULL, NULL); + peer2.operation = GNUNET_TESTBED_peer_stop(NULL, peer2.peer, NULL, NULL); + peer3.operation = GNUNET_TESTBED_peer_stop(NULL, peer3.peer, NULL, NULL); + break; + + default: + GNUNET_break(0); + abort_test(); + return; + } break; + default: - GNUNET_break (0); - abort_test (); + GNUNET_break(0); + abort_test(); return; } - break; - default: - GNUNET_break (0); - abort_test (); - return; - } } @@ -729,44 +743,44 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) * @param emsg the error message; NULL if host registration is successful */ static void -registration_comp (void *cls, const char *emsg) +registration_comp(void *cls, const char *emsg) { reg_handle = NULL; if (cls == neighbour1) - { - neighbour2 = GNUNET_TESTBED_host_create ("127.0.0.1", NULL, cfg, 0); - if (NULL == neighbour2) { - GNUNET_break (0); - abort_test (); + neighbour2 = GNUNET_TESTBED_host_create("127.0.0.1", NULL, cfg, 0); + if (NULL == neighbour2) + { + GNUNET_break(0); + abort_test(); + return; + } + reg_handle = + GNUNET_TESTBED_register_host(controller1, neighbour2, + ®istration_comp, neighbour2); + if (NULL == reg_handle) + { + GNUNET_break(0); + abort_test(); + return; + } return; } - reg_handle = - GNUNET_TESTBED_register_host (controller1, neighbour2, - ®istration_comp, neighbour2); - if (NULL == reg_handle) + if (cls != neighbour2) { - GNUNET_break (0); - abort_test (); + GNUNET_break(0); + abort_test(); return; } - return; - } - if (cls != neighbour2) - { - GNUNET_break (0); - abort_test (); - return; - } peer1.operation = - GNUNET_TESTBED_peer_create (controller1, host, cfg, &peer_create_cb, - &peer1); + GNUNET_TESTBED_peer_create(controller1, host, cfg, &peer_create_cb, + &peer1); if (NULL == peer1.operation) - { - GNUNET_break (0); - abort_test (); - return; - } + { + GNUNET_break(0); + abort_test(); + return; + } } @@ -780,58 +794,59 @@ registration_comp (void *cls, const char *emsg) * GNUNET_TESTBED_controller_stop() shouldn't be called in this case */ static void -status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, - int status) +status_cb(void *cls, const struct GNUNET_CONFIGURATION_Handle *config, + int status) { uint64_t event_mask; if (GNUNET_OK != status) - { - GNUNET_break (0); - cp1 = NULL; - abort_test (); - return; - } + { + GNUNET_break(0); + cp1 = NULL; + abort_test(); + return; + } event_mask = 0; event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START); event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED); switch (result) - { - case INIT: - controller1 = - GNUNET_TESTBED_controller_connect (host, event_mask, - &controller_cb, NULL); - if (NULL == controller1) - { - GNUNET_break (0); - abort_test (); - return; - } - result = CONTROLLER1_UP; - neighbour1 = GNUNET_TESTBED_host_create ("127.0.0.1", NULL, cfg, 0); - if (NULL == neighbour1) - { - GNUNET_break (0); - abort_test (); - return; - } - reg_handle = - GNUNET_TESTBED_register_host (controller1, neighbour1, - ®istration_comp, neighbour1); - if (NULL == reg_handle) { - GNUNET_break (0); - abort_test (); + case INIT: + controller1 = + GNUNET_TESTBED_controller_connect(host, event_mask, + &controller_cb, NULL); + if (NULL == controller1) + { + GNUNET_break(0); + abort_test(); + return; + } + result = CONTROLLER1_UP; + neighbour1 = GNUNET_TESTBED_host_create("127.0.0.1", NULL, cfg, 0); + if (NULL == neighbour1) + { + GNUNET_break(0); + abort_test(); + return; + } + reg_handle = + GNUNET_TESTBED_register_host(controller1, neighbour1, + ®istration_comp, neighbour1); + if (NULL == reg_handle) + { + GNUNET_break(0); + abort_test(); + return; + } + break; + + default: + GNUNET_break(0); + abort_test(); return; } - break; - default: - GNUNET_break (0); - abort_test (); - return; - } } @@ -846,25 +861,25 @@ status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, * @param status #GNUNET_YES if it is habitable; #GNUNET_NO if not */ static void -host_habitable_cb (void *cls, - const struct GNUNET_TESTBED_Host *_host, - int status) +host_habitable_cb(void *cls, + const struct GNUNET_TESTBED_Host *_host, + int status) { hc_handle = NULL; if (GNUNET_NO == status) - { - (void) printf ("%s", + { + (void)printf("%s", "Unable to run the test as this system is not configured " "to use password less SSH logins to localhost.\n" "Skipping test\n"); - GNUNET_SCHEDULER_cancel (abort_task); - abort_task = NULL; - GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); - result = SKIP; - return; - } + GNUNET_SCHEDULER_cancel(abort_task); + abort_task = NULL; + GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); + result = SKIP; + return; + } cp1 = - GNUNET_TESTBED_controller_start ("127.0.0.1", host, status_cb, NULL); + GNUNET_TESTBED_controller_start("127.0.0.1", host, status_cb, NULL); } @@ -877,35 +892,35 @@ host_habitable_cb (void *cls, * @param cfg the configuration file handle */ static void -run (void *cls, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *config) +run(void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *config) { - cfg = GNUNET_CONFIGURATION_dup (config); - host = GNUNET_TESTBED_host_create (NULL, NULL, cfg, 0); + cfg = GNUNET_CONFIGURATION_dup(config); + host = GNUNET_TESTBED_host_create(NULL, NULL, cfg, 0); if (NULL == host) - { - GNUNET_break (0); - abort_test (); - return; - } + { + GNUNET_break(0); + abort_test(); + return; + } if (NULL == (hc_handle = - GNUNET_TESTBED_is_host_habitable (host, config, &host_habitable_cb, - NULL))) - { - GNUNET_TESTBED_host_destroy (host); - host = NULL; - (void) printf ("%s", + GNUNET_TESTBED_is_host_habitable(host, config, &host_habitable_cb, + NULL))) + { + GNUNET_TESTBED_host_destroy(host); + host = NULL; + (void)printf("%s", "Unable to run the test as this system is not configured " "to use password less SSH logins to localhost.\n" "Skipping test\n"); - result = SKIP; - return; - } + result = SKIP; + return; + } abort_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort, - NULL); + GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort, + NULL); } @@ -913,12 +928,11 @@ run (void *cls, char *const *args, const char *cfgfile, * Main function */ int -main (int argc, char **argv) +main(int argc, char **argv) { char *const argv2[] = { "test_testbed_api_3peers_3controllers", - "-c", "test_testbed_api.conf", - NULL - }; + "-c", "test_testbed_api.conf", + NULL }; struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; @@ -926,20 +940,22 @@ main (int argc, char **argv) result = INIT; ret = - GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, - "test_testbed_api_3peers_3controllers", "nohelp", - options, &run, NULL); + GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, argv2, + "test_testbed_api_3peers_3controllers", "nohelp", + options, &run, NULL); if (GNUNET_OK != ret) return 1; switch (result) - { - case SUCCESS: - return 0; - case SKIP: - return 77; /* Mark test as skipped */ - default: - return 1; - } + { + case SUCCESS: + return 0; + + case SKIP: + return 77; /* Mark test as skipped */ + + default: + return 1; + } } /* end of test_testbed_api_3peers_3controllers.c */ diff --git a/src/testbed/test_testbed_api_barriers.c b/src/testbed/test_testbed_api_barriers.c index 9383ab85b..b07dd5339 100644 --- a/src/testbed/test_testbed_api_barriers.c +++ b/src/testbed/test_testbed_api_barriers.c @@ -11,7 +11,7 @@ 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 . @@ -33,8 +33,8 @@ /** * logging short hand */ -#define LOG(type,...) \ - GNUNET_log (type, __VA_ARGS__); +#define LOG(type, ...) \ + GNUNET_log(type, __VA_ARGS__); /** * Number of peers we start in this test case @@ -65,10 +65,10 @@ static void shutdown_handler(void *cls) { if (NULL != timeout_task) - { - GNUNET_SCHEDULER_cancel(timeout_task); - timeout_task = NULL; - } + { + GNUNET_SCHEDULER_cancel(timeout_task); + timeout_task = NULL; + } } @@ -78,12 +78,12 @@ shutdown_handler(void *cls) * @param cls NULL */ static void -do_timeout (void *cls) +do_timeout(void *cls) { timeout_task = NULL; if (barrier != NULL) - GNUNET_TESTBED_barrier_cancel (barrier); - GNUNET_SCHEDULER_shutdown (); + GNUNET_TESTBED_barrier_cancel(barrier); + GNUNET_SCHEDULER_shutdown(); } @@ -101,40 +101,43 @@ do_timeout (void *cls) * error messsage */ static void -barrier_cb (void *cls, - const char *name, - struct GNUNET_TESTBED_Barrier *_barrier, - enum GNUNET_TESTBED_BarrierStatus status, - const char *emsg) +barrier_cb(void *cls, + const char *name, + struct GNUNET_TESTBED_Barrier *_barrier, + enum GNUNET_TESTBED_BarrierStatus status, + const char *emsg) { static enum GNUNET_TESTBED_BarrierStatus old_status; - GNUNET_assert (NULL == cls); - GNUNET_assert (_barrier == barrier); + GNUNET_assert(NULL == cls); + GNUNET_assert(_barrier == barrier); switch (status) - { - case GNUNET_TESTBED_BARRIERSTATUS_INITIALISED: - LOG (GNUNET_ERROR_TYPE_INFO, - "Barrier initialised\n"); - old_status = status; - return; - case GNUNET_TESTBED_BARRIERSTATUS_ERROR: - LOG (GNUNET_ERROR_TYPE_ERROR, - "Barrier initialisation failed: %s", - (NULL == emsg) ? "unknown reason" : emsg); - break; - case GNUNET_TESTBED_BARRIERSTATUS_CROSSED: - LOG (GNUNET_ERROR_TYPE_INFO, - "Barrier crossed\n"); - if (old_status == GNUNET_TESTBED_BARRIERSTATUS_INITIALISED) - result = GNUNET_OK; - break; - default: - GNUNET_assert (0); - return; - } + { + case GNUNET_TESTBED_BARRIERSTATUS_INITIALISED: + LOG(GNUNET_ERROR_TYPE_INFO, + "Barrier initialised\n"); + old_status = status; + return; + + case GNUNET_TESTBED_BARRIERSTATUS_ERROR: + LOG(GNUNET_ERROR_TYPE_ERROR, + "Barrier initialisation failed: %s", + (NULL == emsg) ? "unknown reason" : emsg); + break; + + case GNUNET_TESTBED_BARRIERSTATUS_CROSSED: + LOG(GNUNET_ERROR_TYPE_INFO, + "Barrier crossed\n"); + if (old_status == GNUNET_TESTBED_BARRIERSTATUS_INITIALISED) + result = GNUNET_OK; + break; + + default: + GNUNET_assert(0); + return; + } barrier = NULL; - GNUNET_SCHEDULER_shutdown (); + GNUNET_SCHEDULER_shutdown(); } @@ -151,34 +154,34 @@ barrier_cb (void *cls, * failed */ static void -test_master (void *cls, - struct GNUNET_TESTBED_RunHandle *h, - unsigned int num_peers, - struct GNUNET_TESTBED_Peer **peers_, - unsigned int links_succeeded, - unsigned int links_failed) +test_master(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 GNUNET_TESTBED_Controller *c; - GNUNET_assert (NULL == cls); + GNUNET_assert(NULL == cls); if (NULL == peers_) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failing test due to timeout\n"); - return; - } - GNUNET_assert (NUM_PEERS == num_peers); - c = GNUNET_TESTBED_run_get_controller_handle (h); - barrier = GNUNET_TESTBED_barrier_init (c, - TEST_BARRIER_NAME, - 100, - &barrier_cb, - NULL); + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Failing test due to timeout\n"); + return; + } + GNUNET_assert(NUM_PEERS == num_peers); + c = GNUNET_TESTBED_run_get_controller_handle(h); + barrier = GNUNET_TESTBED_barrier_init(c, + TEST_BARRIER_NAME, + 100, + &barrier_cb, + NULL); timeout_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_SECONDS, - 10 * (NUM_PEERS + 1)), - &do_timeout, NULL); + GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, + 10 * (NUM_PEERS + 1)), + &do_timeout, NULL); GNUNET_SCHEDULER_add_shutdown(&shutdown_handler, NULL); } @@ -195,7 +198,7 @@ test_master (void *cls, * Main function */ int -main (int argc, char **argv) +main(int argc, char **argv) { struct GNUNET_CONFIGURATION_Handle *cfg; char pwd[PATH_MAX]; @@ -204,26 +207,26 @@ main (int argc, char **argv) result = GNUNET_SYSERR; event_mask = 0; - cfg = GNUNET_CONFIGURATION_create (); - GNUNET_assert (GNUNET_YES == - GNUNET_CONFIGURATION_parse (cfg, - "test_testbed_api_barriers.conf.in")); - if (NULL == getcwd (pwd, PATH_MAX)) + cfg = GNUNET_CONFIGURATION_create(); + GNUNET_assert(GNUNET_YES == + GNUNET_CONFIGURATION_parse(cfg, + "test_testbed_api_barriers.conf.in")); + if (NULL == getcwd(pwd, PATH_MAX)) return 1; - GNUNET_assert (0 < GNUNET_asprintf (&binary, "%s/%s", pwd, - "gnunet-service-test-barriers")); - GNUNET_CONFIGURATION_set_value_string (cfg, "test-barriers","BINARY", binary); - GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_write - (cfg, "test_testbed_api_barriers.conf")); - GNUNET_CONFIGURATION_destroy (cfg); + GNUNET_assert(0 < GNUNET_asprintf(&binary, "%s/%s", pwd, + "gnunet-service-test-barriers")); + GNUNET_CONFIGURATION_set_value_string(cfg, "test-barriers", "BINARY", binary); + GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_write + (cfg, "test_testbed_api_barriers.conf")); + GNUNET_CONFIGURATION_destroy(cfg); cfg = NULL; - GNUNET_free (binary); + GNUNET_free(binary); binary = NULL; - (void) GNUNET_TESTBED_test_run ("test_testbed_api_barriers", - "test_testbed_api_barriers.conf", NUM_PEERS, - event_mask, NULL, NULL, - &test_master, NULL); - (void) unlink ("test_testbed_api_barriers.conf"); + (void)GNUNET_TESTBED_test_run("test_testbed_api_barriers", + "test_testbed_api_barriers.conf", NUM_PEERS, + event_mask, NULL, NULL, + &test_master, NULL); + (void)unlink("test_testbed_api_barriers.conf"); if (GNUNET_OK != result) return 1; return 0; diff --git a/src/testbed/test_testbed_api_controllerlink.c b/src/testbed/test_testbed_api_controllerlink.c index 6c1a24f9c..ffcbebf00 100644 --- a/src/testbed/test_testbed_api_controllerlink.c +++ b/src/testbed/test_testbed_api_controllerlink.c @@ -11,7 +11,7 @@ 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 . @@ -45,19 +45,17 @@ /** * Generic logging shortcut */ -#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log(kind, __VA_ARGS__) /** * Debug logging shorthand */ -#define LOG_DEBUG(...) LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) +#define LOG_DEBUG(...) LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) /** * Different stages in testing */ -enum Stage -{ - +enum Stage { /** * Initial stage */ @@ -294,17 +292,17 @@ static enum Stage result; */ #define FAIL_TEST(cond) \ do \ - { \ - if (! (cond)) \ - { \ - GNUNET_break (0); \ - if (NULL != abort_task) \ - GNUNET_SCHEDULER_cancel (abort_task); \ - abort_task = NULL; \ - GNUNET_SCHEDULER_shutdown (); \ - return; \ - } \ - } while (0) + { \ + if (!(cond)) \ + { \ + GNUNET_break(0); \ + if (NULL != abort_task) \ + GNUNET_SCHEDULER_cancel (abort_task); \ + abort_task = NULL; \ + GNUNET_SCHEDULER_shutdown(); \ + return; \ + } \ + } while (0) /** @@ -313,40 +311,40 @@ static enum Stage result; * @param cls NULL */ static void -do_shutdown (void *cls) +do_shutdown(void *cls) { if (NULL != abort_task) - GNUNET_SCHEDULER_cancel (abort_task); + GNUNET_SCHEDULER_cancel(abort_task); if (NULL != delay_task_id) - { - GNUNET_SCHEDULER_cancel (delay_task_id); - delay_task_id = NULL; - } + { + GNUNET_SCHEDULER_cancel(delay_task_id); + delay_task_id = NULL; + } if (NULL != hc_handle) - GNUNET_TESTBED_is_host_habitable_cancel (hc_handle); + GNUNET_TESTBED_is_host_habitable_cancel(hc_handle); if (NULL != op) - { - GNUNET_TESTBED_operation_done (op); - op = NULL; - } + { + GNUNET_TESTBED_operation_done(op); + op = NULL; + } if (NULL != mc) - GNUNET_TESTBED_controller_disconnect (mc); + GNUNET_TESTBED_controller_disconnect(mc); if (NULL != cp) - GNUNET_TESTBED_controller_stop (cp); + GNUNET_TESTBED_controller_stop(cp); if (NULL != slave3) - GNUNET_TESTBED_host_destroy (slave3); + GNUNET_TESTBED_host_destroy(slave3); if (NULL != slave2) - GNUNET_TESTBED_host_destroy (slave2); + GNUNET_TESTBED_host_destroy(slave2); if (NULL != slave) - GNUNET_TESTBED_host_destroy (slave); + GNUNET_TESTBED_host_destroy(slave); if (NULL != host) - GNUNET_TESTBED_host_destroy (host); + GNUNET_TESTBED_host_destroy(host); if (NULL != cfg) - GNUNET_CONFIGURATION_destroy (cfg); + GNUNET_CONFIGURATION_destroy(cfg); if (NULL != cfg3) - GNUNET_CONFIGURATION_destroy (cfg3); + GNUNET_CONFIGURATION_destroy(cfg3); if (NULL != rh) - GNUNET_TESTBED_cancel_registration (rh); + GNUNET_TESTBED_cancel_registration(rh); } @@ -356,11 +354,11 @@ do_shutdown (void *cls) * @param cls NULL */ static void -do_abort (void *cls) +do_abort(void *cls) { - LOG (GNUNET_ERROR_TYPE_WARNING, "Aborting in stage %d\n", result); + LOG(GNUNET_ERROR_TYPE_WARNING, "Aborting in stage %d\n", result); abort_task = NULL; - GNUNET_SCHEDULER_shutdown (); + GNUNET_SCHEDULER_shutdown(); } @@ -371,11 +369,11 @@ do_abort (void *cls) * @return */ static void -do_abort_now (void *cls) +do_abort_now(void *cls) { if (NULL != abort_task) - GNUNET_SCHEDULER_cancel (abort_task); - abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); + GNUNET_SCHEDULER_cancel(abort_task); + abort_task = GNUNET_SCHEDULER_add_now(&do_abort, NULL); } @@ -386,7 +384,7 @@ do_abort_now (void *cls) * @param emsg the error message; NULL if host registration is successful */ static void -registration_cont (void *cls, const char *emsg); +registration_cont(void *cls, const char *emsg); /** @@ -396,26 +394,29 @@ registration_cont (void *cls, const char *emsg); * @return */ static void -delay_task (void *cls) +delay_task(void *cls) { delay_task_id = NULL; switch (result) - { - case SLAVE2_PEER_CREATE_SUCCESS: - op = GNUNET_TESTBED_peer_stop (NULL, slave1_peer, NULL, NULL); - FAIL_TEST (NULL != op); - break; - case MASTER_SLAVE2_PEERS_CONNECTED: - slave3 = GNUNET_TESTBED_host_create_with_id (3, "127.0.0.1", NULL, cfg, 0); - rh = GNUNET_TESTBED_register_host (mc, slave3, ®istration_cont, NULL); - break; - case SLAVE2_SLAVE3_PEERS_CONNECTED: - op = GNUNET_TESTBED_peer_stop (NULL, slave2_peer, NULL, NULL); - FAIL_TEST (NULL != op); - break; - default: - FAIL_TEST (0); - } + { + case SLAVE2_PEER_CREATE_SUCCESS: + op = GNUNET_TESTBED_peer_stop(NULL, slave1_peer, NULL, NULL); + FAIL_TEST(NULL != op); + break; + + case MASTER_SLAVE2_PEERS_CONNECTED: + slave3 = GNUNET_TESTBED_host_create_with_id(3, "127.0.0.1", NULL, cfg, 0); + rh = GNUNET_TESTBED_register_host(mc, slave3, ®istration_cont, NULL); + break; + + case SLAVE2_SLAVE3_PEERS_CONNECTED: + op = GNUNET_TESTBED_peer_stop(NULL, slave2_peer, NULL, NULL); + FAIL_TEST(NULL != op); + break; + + default: + FAIL_TEST(0); + } } @@ -429,44 +430,48 @@ delay_task (void *cls) * @param emsg NULL if peer is not NULL; else MAY contain the error description */ static void -peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) +peer_create_cb(void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) { - FAIL_TEST (NULL != peer); - FAIL_TEST (NULL == emsg); + FAIL_TEST(NULL != peer); + FAIL_TEST(NULL == emsg); switch (result) - { - case MASTER_STARTED: - result = MASTER_PEER_CREATE_SUCCESS; - master_peer = peer; - GNUNET_TESTBED_operation_done (op); - op = GNUNET_TESTBED_peer_start (NULL, master_peer, NULL, NULL); - break; - case SLAVE1_LINK_SUCCESS: - result = SLAVE1_PEER_CREATE_SUCCESS; - slave1_peer = peer; - GNUNET_TESTBED_operation_done (op); - op = GNUNET_TESTBED_peer_start (NULL, slave1_peer, NULL, NULL); - break; - case SLAVE2_LINK_SUCCESS: - result = SLAVE2_PEER_CREATE_SUCCESS; - slave2_peer = peer; - GNUNET_TESTBED_operation_done (op); - op = NULL; - delay_task_id = GNUNET_SCHEDULER_add_delayed ( - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), - &delay_task, - NULL); - return; - case SLAVE3_STARTED: - result = SLAVE3_PEER_CREATE_SUCCESS; - slave3_peer = peer; - GNUNET_TESTBED_operation_done (op); - op = GNUNET_TESTBED_peer_start (NULL, slave3_peer, NULL, NULL); - break; - default: - FAIL_TEST (0); - } - FAIL_TEST (NULL != op); + { + case MASTER_STARTED: + result = MASTER_PEER_CREATE_SUCCESS; + master_peer = peer; + GNUNET_TESTBED_operation_done(op); + op = GNUNET_TESTBED_peer_start(NULL, master_peer, NULL, NULL); + break; + + case SLAVE1_LINK_SUCCESS: + result = SLAVE1_PEER_CREATE_SUCCESS; + slave1_peer = peer; + GNUNET_TESTBED_operation_done(op); + op = GNUNET_TESTBED_peer_start(NULL, slave1_peer, NULL, NULL); + break; + + case SLAVE2_LINK_SUCCESS: + result = SLAVE2_PEER_CREATE_SUCCESS; + slave2_peer = peer; + GNUNET_TESTBED_operation_done(op); + op = NULL; + delay_task_id = GNUNET_SCHEDULER_add_delayed( + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), + &delay_task, + NULL); + return; + + case SLAVE3_STARTED: + result = SLAVE3_PEER_CREATE_SUCCESS; + slave3_peer = peer; + GNUNET_TESTBED_operation_done(op); + op = GNUNET_TESTBED_peer_start(NULL, slave3_peer, NULL, NULL); + break; + + default: + FAIL_TEST(0); + } + FAIL_TEST(NULL != op); } @@ -477,14 +482,14 @@ peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) * @param event the event information to check */ static void -check_operation_success (const struct GNUNET_TESTBED_EventInformation *event) +check_operation_success(const struct GNUNET_TESTBED_EventInformation *event) { - FAIL_TEST (NULL != event); - FAIL_TEST (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type); - FAIL_TEST (event->op == op); - FAIL_TEST (NULL == event->op_cls); - FAIL_TEST (NULL == event->details.operation_finished.emsg); - FAIL_TEST (NULL == event->details.operation_finished.generic); + FAIL_TEST(NULL != event); + FAIL_TEST(GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type); + FAIL_TEST(event->op == op); + FAIL_TEST(NULL == event->op_cls); + FAIL_TEST(NULL == event->details.operation_finished.emsg); + FAIL_TEST(NULL == event->details.operation_finished.generic); } @@ -496,163 +501,180 @@ check_operation_success (const struct GNUNET_TESTBED_EventInformation *event) * @param event information about the event */ static void -controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) +controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event) { switch (result) - { - case SLAVE2_REGISTERED: - check_operation_success (event); - GNUNET_TESTBED_operation_done (op); - op = NULL; - result = SLAVE1_LINK_SUCCESS; - FAIL_TEST (NULL != slave2); - FAIL_TEST (NULL != slave); - op = GNUNET_TESTBED_peer_create (mc, slave, cfg, peer_create_cb, NULL); - FAIL_TEST (NULL != op); - break; - case SLAVE1_PEER_START_SUCCESS: - check_operation_success (event); - GNUNET_TESTBED_operation_done (op); - result = SLAVE2_LINK_SUCCESS; - op = GNUNET_TESTBED_peer_create (mc, slave2, cfg, peer_create_cb, NULL); - FAIL_TEST (NULL != op); - break; - case MASTER_PEER_CREATE_SUCCESS: - FAIL_TEST (GNUNET_TESTBED_ET_PEER_START == event->type); - FAIL_TEST (event->details.peer_start.host == host); - FAIL_TEST (event->details.peer_start.peer == master_peer); - GNUNET_TESTBED_operation_done (op); - op = NULL; - result = MASTER_PEER_START_SUCCESS; - slave = GNUNET_TESTBED_host_create_with_id (1, "127.0.0.1", NULL, cfg, 0); - FAIL_TEST (NULL != slave); - rh = GNUNET_TESTBED_register_host (mc, slave, ®istration_cont, NULL); - FAIL_TEST (NULL != rh); - break; - case SLAVE1_PEER_CREATE_SUCCESS: - FAIL_TEST (GNUNET_TESTBED_ET_PEER_START == event->type); - FAIL_TEST (event->details.peer_start.host == slave); - FAIL_TEST (event->details.peer_start.peer == slave1_peer); - GNUNET_TESTBED_operation_done (op); - result = SLAVE1_PEER_START_SUCCESS; - op = GNUNET_TESTBED_controller_link (NULL, mc, slave2, slave, GNUNET_YES); - break; - case SLAVE2_PEER_CREATE_SUCCESS: - FAIL_TEST (GNUNET_TESTBED_ET_PEER_STOP == event->type); - FAIL_TEST (event->details.peer_stop.peer == slave1_peer); - GNUNET_TESTBED_operation_done (op); - result = SLAVE1_PEER_STOP_SUCCESS; - op = GNUNET_TESTBED_peer_start (NULL, slave2_peer, NULL, NULL); - FAIL_TEST (NULL != op); - break; - case SLAVE3_PEER_CREATE_SUCCESS: - FAIL_TEST (GNUNET_TESTBED_ET_PEER_START == event->type); - FAIL_TEST (event->details.peer_start.host == slave3); - FAIL_TEST (event->details.peer_start.peer == slave3_peer); - GNUNET_TESTBED_operation_done (op); - result = SLAVE3_PEER_START_SUCCESS; - sleep (1); - LOG_DEBUG ("**************************************\n"); - op = - GNUNET_TESTBED_overlay_connect (mc, NULL, NULL, slave2_peer, slave3_peer); - FAIL_TEST (NULL != op); - break; - case SLAVE3_PEER_START_SUCCESS: - FAIL_TEST (NULL != event); - FAIL_TEST (GNUNET_TESTBED_ET_CONNECT == event->type); - FAIL_TEST (event->details.peer_connect.peer1 == slave2_peer); - FAIL_TEST (event->details.peer_connect.peer2 == slave3_peer); - result = SLAVE2_SLAVE3_PEERS_CONNECTED; - GNUNET_TESTBED_operation_done (op); - op = NULL; - delay_task_id = GNUNET_SCHEDULER_add_delayed ( - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), - &delay_task, - NULL); - break; - case SLAVE1_PEER_STOP_SUCCESS: - FAIL_TEST (GNUNET_TESTBED_ET_PEER_START == event->type); - FAIL_TEST (event->details.peer_start.host == slave2); - FAIL_TEST (event->details.peer_start.peer == slave2_peer); - GNUNET_TESTBED_operation_done (op); - result = SLAVE2_PEER_START_SUCCESS; - op = - GNUNET_TESTBED_overlay_connect (mc, NULL, NULL, master_peer, slave2_peer); - break; - case SLAVE2_PEER_START_SUCCESS: - FAIL_TEST (NULL != event); - FAIL_TEST (GNUNET_TESTBED_ET_CONNECT == event->type); - FAIL_TEST (event->details.peer_connect.peer1 == master_peer); - FAIL_TEST (event->details.peer_connect.peer2 == slave2_peer); - result = MASTER_SLAVE2_PEERS_CONNECTED; - GNUNET_TESTBED_operation_done (op); - op = NULL; - delay_task_id = GNUNET_SCHEDULER_add_delayed ( - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), - &delay_task, - NULL); - break; - case SLAVE2_SLAVE3_PEERS_CONNECTED: - FAIL_TEST (GNUNET_TESTBED_ET_PEER_STOP == event->type); - FAIL_TEST (event->details.peer_stop.peer == slave2_peer); - GNUNET_TESTBED_operation_done (op); - result = SLAVE2_PEER_STOP_SUCCESS; - op = GNUNET_TESTBED_peer_destroy (slave1_peer); - FAIL_TEST (NULL != op); - break; - case SLAVE2_PEER_STOP_SUCCESS: - check_operation_success (event); - GNUNET_TESTBED_operation_done (op); - result = SLAVE1_PEER_DESTROY_SUCCESS; - op = GNUNET_TESTBED_peer_destroy (slave2_peer); - FAIL_TEST (NULL != op); - break; - case SLAVE1_PEER_DESTROY_SUCCESS: - check_operation_success (event); - GNUNET_TESTBED_operation_done (op); - op = NULL; - result = SLAVE2_PEER_DESTROY_SUCCESS; - op = GNUNET_TESTBED_get_slave_config (NULL, mc, slave3); - FAIL_TEST (NULL != op); - break; - case SLAVE2_PEER_DESTROY_SUCCESS: - FAIL_TEST (NULL != event); - FAIL_TEST (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type); - FAIL_TEST (event->op == op); - FAIL_TEST (NULL == event->op_cls); - FAIL_TEST (NULL == event->details.operation_finished.emsg); - cfg3 = GNUNET_CONFIGURATION_dup (event->details.operation_finished.generic); - GNUNET_TESTBED_operation_done (op); - result = SLAVE3_GET_CONFIG_SUCCESS; - op = GNUNET_TESTBED_controller_link (NULL, mc, slave3, slave, GNUNET_NO); - break; - case SLAVE3_REGISTERED: - check_operation_success (event); - GNUNET_TESTBED_operation_done (op); - result = SLAVE3_STARTED; - op = GNUNET_TESTBED_peer_create (mc, slave3, cfg, peer_create_cb, NULL); - FAIL_TEST (NULL != op); - break; - case SLAVE3_GET_CONFIG_SUCCESS: - result = SLAVE3_LINK_SUCCESS; - GNUNET_TESTBED_operation_done (op); - op = GNUNET_TESTBED_peer_destroy (master_peer); - break; - case SLAVE3_LINK_SUCCESS: - check_operation_success (event); - result = MASTER_PEER_DESTROY_SUCCESS; - GNUNET_TESTBED_operation_done (op); - op = GNUNET_TESTBED_peer_destroy (slave3_peer); - break; - case MASTER_PEER_DESTROY_SUCCESS: - result = SUCCESS; - GNUNET_TESTBED_operation_done (op); - op = NULL; - GNUNET_SCHEDULER_shutdown (); - break; - default: - FAIL_TEST (0); - } + { + case SLAVE2_REGISTERED: + check_operation_success(event); + GNUNET_TESTBED_operation_done(op); + op = NULL; + result = SLAVE1_LINK_SUCCESS; + FAIL_TEST(NULL != slave2); + FAIL_TEST(NULL != slave); + op = GNUNET_TESTBED_peer_create(mc, slave, cfg, peer_create_cb, NULL); + FAIL_TEST(NULL != op); + break; + + case SLAVE1_PEER_START_SUCCESS: + check_operation_success(event); + GNUNET_TESTBED_operation_done(op); + result = SLAVE2_LINK_SUCCESS; + op = GNUNET_TESTBED_peer_create(mc, slave2, cfg, peer_create_cb, NULL); + FAIL_TEST(NULL != op); + break; + + case MASTER_PEER_CREATE_SUCCESS: + FAIL_TEST(GNUNET_TESTBED_ET_PEER_START == event->type); + FAIL_TEST(event->details.peer_start.host == host); + FAIL_TEST(event->details.peer_start.peer == master_peer); + GNUNET_TESTBED_operation_done(op); + op = NULL; + result = MASTER_PEER_START_SUCCESS; + slave = GNUNET_TESTBED_host_create_with_id(1, "127.0.0.1", NULL, cfg, 0); + FAIL_TEST(NULL != slave); + rh = GNUNET_TESTBED_register_host(mc, slave, ®istration_cont, NULL); + FAIL_TEST(NULL != rh); + break; + + case SLAVE1_PEER_CREATE_SUCCESS: + FAIL_TEST(GNUNET_TESTBED_ET_PEER_START == event->type); + FAIL_TEST(event->details.peer_start.host == slave); + FAIL_TEST(event->details.peer_start.peer == slave1_peer); + GNUNET_TESTBED_operation_done(op); + result = SLAVE1_PEER_START_SUCCESS; + op = GNUNET_TESTBED_controller_link(NULL, mc, slave2, slave, GNUNET_YES); + break; + + case SLAVE2_PEER_CREATE_SUCCESS: + FAIL_TEST(GNUNET_TESTBED_ET_PEER_STOP == event->type); + FAIL_TEST(event->details.peer_stop.peer == slave1_peer); + GNUNET_TESTBED_operation_done(op); + result = SLAVE1_PEER_STOP_SUCCESS; + op = GNUNET_TESTBED_peer_start(NULL, slave2_peer, NULL, NULL); + FAIL_TEST(NULL != op); + break; + + case SLAVE3_PEER_CREATE_SUCCESS: + FAIL_TEST(GNUNET_TESTBED_ET_PEER_START == event->type); + FAIL_TEST(event->details.peer_start.host == slave3); + FAIL_TEST(event->details.peer_start.peer == slave3_peer); + GNUNET_TESTBED_operation_done(op); + result = SLAVE3_PEER_START_SUCCESS; + sleep(1); + LOG_DEBUG("**************************************\n"); + op = + GNUNET_TESTBED_overlay_connect(mc, NULL, NULL, slave2_peer, slave3_peer); + FAIL_TEST(NULL != op); + break; + + case SLAVE3_PEER_START_SUCCESS: + FAIL_TEST(NULL != event); + FAIL_TEST(GNUNET_TESTBED_ET_CONNECT == event->type); + FAIL_TEST(event->details.peer_connect.peer1 == slave2_peer); + FAIL_TEST(event->details.peer_connect.peer2 == slave3_peer); + result = SLAVE2_SLAVE3_PEERS_CONNECTED; + GNUNET_TESTBED_operation_done(op); + op = NULL; + delay_task_id = GNUNET_SCHEDULER_add_delayed( + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), + &delay_task, + NULL); + break; + + case SLAVE1_PEER_STOP_SUCCESS: + FAIL_TEST(GNUNET_TESTBED_ET_PEER_START == event->type); + FAIL_TEST(event->details.peer_start.host == slave2); + FAIL_TEST(event->details.peer_start.peer == slave2_peer); + GNUNET_TESTBED_operation_done(op); + result = SLAVE2_PEER_START_SUCCESS; + op = + GNUNET_TESTBED_overlay_connect(mc, NULL, NULL, master_peer, slave2_peer); + break; + + case SLAVE2_PEER_START_SUCCESS: + FAIL_TEST(NULL != event); + FAIL_TEST(GNUNET_TESTBED_ET_CONNECT == event->type); + FAIL_TEST(event->details.peer_connect.peer1 == master_peer); + FAIL_TEST(event->details.peer_connect.peer2 == slave2_peer); + result = MASTER_SLAVE2_PEERS_CONNECTED; + GNUNET_TESTBED_operation_done(op); + op = NULL; + delay_task_id = GNUNET_SCHEDULER_add_delayed( + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), + &delay_task, + NULL); + break; + + case SLAVE2_SLAVE3_PEERS_CONNECTED: + FAIL_TEST(GNUNET_TESTBED_ET_PEER_STOP == event->type); + FAIL_TEST(event->details.peer_stop.peer == slave2_peer); + GNUNET_TESTBED_operation_done(op); + result = SLAVE2_PEER_STOP_SUCCESS; + op = GNUNET_TESTBED_peer_destroy(slave1_peer); + FAIL_TEST(NULL != op); + break; + + case SLAVE2_PEER_STOP_SUCCESS: + check_operation_success(event); + GNUNET_TESTBED_operation_done(op); + result = SLAVE1_PEER_DESTROY_SUCCESS; + op = GNUNET_TESTBED_peer_destroy(slave2_peer); + FAIL_TEST(NULL != op); + break; + + case SLAVE1_PEER_DESTROY_SUCCESS: + check_operation_success(event); + GNUNET_TESTBED_operation_done(op); + op = NULL; + result = SLAVE2_PEER_DESTROY_SUCCESS; + op = GNUNET_TESTBED_get_slave_config(NULL, mc, slave3); + FAIL_TEST(NULL != op); + break; + + case SLAVE2_PEER_DESTROY_SUCCESS: + FAIL_TEST(NULL != event); + FAIL_TEST(GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type); + FAIL_TEST(event->op == op); + FAIL_TEST(NULL == event->op_cls); + FAIL_TEST(NULL == event->details.operation_finished.emsg); + cfg3 = GNUNET_CONFIGURATION_dup(event->details.operation_finished.generic); + GNUNET_TESTBED_operation_done(op); + result = SLAVE3_GET_CONFIG_SUCCESS; + op = GNUNET_TESTBED_controller_link(NULL, mc, slave3, slave, GNUNET_NO); + break; + + case SLAVE3_REGISTERED: + check_operation_success(event); + GNUNET_TESTBED_operation_done(op); + result = SLAVE3_STARTED; + op = GNUNET_TESTBED_peer_create(mc, slave3, cfg, peer_create_cb, NULL); + FAIL_TEST(NULL != op); + break; + + case SLAVE3_GET_CONFIG_SUCCESS: + result = SLAVE3_LINK_SUCCESS; + GNUNET_TESTBED_operation_done(op); + op = GNUNET_TESTBED_peer_destroy(master_peer); + break; + + case SLAVE3_LINK_SUCCESS: + check_operation_success(event); + result = MASTER_PEER_DESTROY_SUCCESS; + GNUNET_TESTBED_operation_done(op); + op = GNUNET_TESTBED_peer_destroy(slave3_peer); + break; + + case MASTER_PEER_DESTROY_SUCCESS: + result = SUCCESS; + GNUNET_TESTBED_operation_done(op); + op = NULL; + GNUNET_SCHEDULER_shutdown(); + break; + + default: + FAIL_TEST(0); + } } @@ -663,40 +685,43 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) * @param emsg the error message; NULL if host registration is successful */ static void -registration_cont (void *cls, const char *emsg) +registration_cont(void *cls, const char *emsg) { rh = NULL; switch (result) - { - case MASTER_PEER_START_SUCCESS: - FAIL_TEST (NULL == emsg); - FAIL_TEST (NULL != mc); - result = SLAVE1_REGISTERED; - slave2 = GNUNET_TESTBED_host_create_with_id (2, "127.0.0.1", NULL, cfg, 0); - FAIL_TEST (NULL != slave2); - rh = GNUNET_TESTBED_register_host (mc, slave2, ®istration_cont, NULL); - FAIL_TEST (NULL != rh); - break; - case SLAVE1_REGISTERED: - FAIL_TEST (NULL == emsg); - FAIL_TEST (NULL != mc); - result = SLAVE2_REGISTERED; - FAIL_TEST (NULL != cfg); - op = GNUNET_TESTBED_controller_link (NULL, mc, slave, NULL, GNUNET_YES); - FAIL_TEST (NULL != op); - break; - case MASTER_SLAVE2_PEERS_CONNECTED: - FAIL_TEST (NULL == emsg); - FAIL_TEST (NULL != mc); - FAIL_TEST (NULL == op); - result = SLAVE3_REGISTERED; - op = GNUNET_TESTBED_controller_link (NULL, mc, slave3, NULL, GNUNET_YES); - FAIL_TEST (NULL != op); - break; - default: - GNUNET_break (0); - do_abort_now (NULL); - } + { + case MASTER_PEER_START_SUCCESS: + FAIL_TEST(NULL == emsg); + FAIL_TEST(NULL != mc); + result = SLAVE1_REGISTERED; + slave2 = GNUNET_TESTBED_host_create_with_id(2, "127.0.0.1", NULL, cfg, 0); + FAIL_TEST(NULL != slave2); + rh = GNUNET_TESTBED_register_host(mc, slave2, ®istration_cont, NULL); + FAIL_TEST(NULL != rh); + break; + + case SLAVE1_REGISTERED: + FAIL_TEST(NULL == emsg); + FAIL_TEST(NULL != mc); + result = SLAVE2_REGISTERED; + FAIL_TEST(NULL != cfg); + op = GNUNET_TESTBED_controller_link(NULL, mc, slave, NULL, GNUNET_YES); + FAIL_TEST(NULL != op); + break; + + case MASTER_SLAVE2_PEERS_CONNECTED: + FAIL_TEST(NULL == emsg); + FAIL_TEST(NULL != mc); + FAIL_TEST(NULL == op); + result = SLAVE3_REGISTERED; + op = GNUNET_TESTBED_controller_link(NULL, mc, slave3, NULL, GNUNET_YES); + FAIL_TEST(NULL != op); + break; + + default: + GNUNET_break(0); + do_abort_now(NULL); + } } /** @@ -709,33 +734,34 @@ registration_cont (void *cls, const char *emsg) * GNUNET_TESTBED_controller_stop() shouldn't be called in this case */ static void -status_cb (void *cls, - const struct GNUNET_CONFIGURATION_Handle *config, - int status) +status_cb(void *cls, + const struct GNUNET_CONFIGURATION_Handle *config, + int status) { switch (result) - { - case INIT: - FAIL_TEST (GNUNET_OK == status); - event_mask = 0; - event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START); - event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); - event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); - event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED); - mc = GNUNET_TESTBED_controller_connect (host, - event_mask, - &controller_cb, - NULL); - FAIL_TEST (NULL != mc); - result = MASTER_STARTED; - op = GNUNET_TESTBED_peer_create (mc, host, cfg, peer_create_cb, NULL); - FAIL_TEST (NULL != op); - break; - default: - GNUNET_break (0); - cp = NULL; - do_abort_now (NULL); - } + { + case INIT: + FAIL_TEST(GNUNET_OK == status); + event_mask = 0; + event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START); + event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); + event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); + event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED); + mc = GNUNET_TESTBED_controller_connect(host, + event_mask, + &controller_cb, + NULL); + FAIL_TEST(NULL != mc); + result = MASTER_STARTED; + op = GNUNET_TESTBED_peer_create(mc, host, cfg, peer_create_cb, NULL); + FAIL_TEST(NULL != op); + break; + + default: + GNUNET_break(0); + cp = NULL; + do_abort_now(NULL); + } } @@ -750,24 +776,24 @@ status_cb (void *cls, * @param status #GNUNET_YES if it is habitable; #GNUNET_NO if not */ static void -host_habitable_cb (void *cls, - const struct GNUNET_TESTBED_Host *_host, - int status) +host_habitable_cb(void *cls, + const struct GNUNET_TESTBED_Host *_host, + int status) { hc_handle = NULL; if (GNUNET_NO == status) - { - (void) printf ("%s", + { + (void)printf("%s", "Unable to run the test as this system is not configured " "to use password less SSH logins to localhost.\n" "Skipping test\n"); - GNUNET_SCHEDULER_cancel (abort_task); - abort_task = NULL; - GNUNET_SCHEDULER_shutdown (); - result = SKIP; - return; - } - cp = GNUNET_TESTBED_controller_start ("127.0.0.1", host, status_cb, NULL); + GNUNET_SCHEDULER_cancel(abort_task); + abort_task = NULL; + GNUNET_SCHEDULER_shutdown(); + result = SKIP; + return; + } + cp = GNUNET_TESTBED_controller_start("127.0.0.1", host, status_cb, NULL); } @@ -780,35 +806,35 @@ host_habitable_cb (void *cls, * @param cfg the configuration file handle */ static void -run (void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *config) +run(void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *config) { - cfg = GNUNET_CONFIGURATION_dup (config); - host = GNUNET_TESTBED_host_create (NULL, NULL, cfg, 0); - FAIL_TEST (NULL != host); - if (NULL == (hc_handle = GNUNET_TESTBED_is_host_habitable (host, - config, - &host_habitable_cb, - NULL))) - { - GNUNET_TESTBED_host_destroy (host); - GNUNET_CONFIGURATION_destroy (cfg); - cfg = NULL; - host = NULL; - (void) printf ("%s", + cfg = GNUNET_CONFIGURATION_dup(config); + host = GNUNET_TESTBED_host_create(NULL, NULL, cfg, 0); + FAIL_TEST(NULL != host); + if (NULL == (hc_handle = GNUNET_TESTBED_is_host_habitable(host, + config, + &host_habitable_cb, + NULL))) + { + GNUNET_TESTBED_host_destroy(host); + GNUNET_CONFIGURATION_destroy(cfg); + cfg = NULL; + host = NULL; + (void)printf("%s", "Unable to run the test as this system is not configured " "to use password less SSH logins to localhost.\n" "Marking test as successful\n"); - result = SKIP; - return; - } - abort_task = GNUNET_SCHEDULER_add_delayed ( - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5), + result = SKIP; + return; + } + abort_task = GNUNET_SCHEDULER_add_delayed( + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5), &do_abort, NULL); - GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); + GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); } @@ -816,34 +842,36 @@ run (void *cls, * Main function */ int -main (int argc, char **argv) +main(int argc, char **argv) { - char *const argv2[] = {"test_testbed_api_controllerlink", - "-c", - "test_testbed_api.conf", - NULL}; - struct GNUNET_GETOPT_CommandLineOption options[] = {GNUNET_GETOPT_OPTION_END}; + char *const argv2[] = { "test_testbed_api_controllerlink", + "-c", + "test_testbed_api.conf", + NULL }; + struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; int ret; result = INIT; - ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, - argv2, - "test_testbed_api_controllerlink", - "nohelp", - options, - &run, - NULL); + ret = GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, + argv2, + "test_testbed_api_controllerlink", + "nohelp", + options, + &run, + NULL); if (GNUNET_OK != ret) return 1; switch (result) - { - case SUCCESS: - return 0; - case SKIP: - return 77; /* Mark test as skipped */ - default: - return 1; - } + { + case SUCCESS: + return 0; + + case SKIP: + return 77; /* Mark test as skipped */ + + default: + return 1; + } } /* end of test_testbed_api_controllerlink.c */ diff --git a/src/testbed/test_testbed_api_hosts.c b/src/testbed/test_testbed_api_hosts.c index c3f565949..f9656d17f 100644 --- a/src/testbed/test_testbed_api_hosts.c +++ b/src/testbed/test_testbed_api_hosts.c @@ -11,7 +11,7 @@ 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 . @@ -30,8 +30,8 @@ #include "testbed_api_hosts.h" -#define TIME_REL_SECS(sec) \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec) +#define TIME_REL_SECS(sec) \ + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, sec) /** * configuration handle to use as template configuration while creating hosts @@ -65,20 +65,20 @@ static int status; * @param cls NULL */ static void -do_shutdown (void *cls) +do_shutdown(void *cls) { - GNUNET_TESTBED_host_destroy (host); + GNUNET_TESTBED_host_destroy(host); while (0 != num_hosts) - { - GNUNET_TESTBED_host_destroy (hosts[num_hosts - 1]); - num_hosts--; - } - GNUNET_free (hosts); + { + GNUNET_TESTBED_host_destroy(hosts[num_hosts - 1]); + num_hosts--; + } + GNUNET_free(hosts); if (NULL != cfg) - { - GNUNET_CONFIGURATION_destroy (cfg); - cfg = NULL; - } + { + GNUNET_CONFIGURATION_destroy(cfg); + cfg = NULL; + } } @@ -91,90 +91,89 @@ do_shutdown (void *cls) * @param cfg the configuration file handle */ static void -run (void *cls, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *config) +run(void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *config) { unsigned int cnt; - cfg = GNUNET_CONFIGURATION_dup (config); - host = GNUNET_TESTBED_host_create ("localhost", NULL, cfg, 0); - GNUNET_assert (NULL != host); - GNUNET_assert (0 != GNUNET_TESTBED_host_get_id_ (host)); - GNUNET_TESTBED_host_destroy (host); - host = GNUNET_TESTBED_host_create (NULL, NULL, cfg, 0); - GNUNET_assert (NULL != host); - GNUNET_assert (0 == GNUNET_TESTBED_host_get_id_ (host)); - GNUNET_assert (host == GNUNET_TESTBED_host_lookup_by_id_ (0)); + cfg = GNUNET_CONFIGURATION_dup(config); + host = GNUNET_TESTBED_host_create("localhost", NULL, cfg, 0); + GNUNET_assert(NULL != host); + GNUNET_assert(0 != GNUNET_TESTBED_host_get_id_(host)); + GNUNET_TESTBED_host_destroy(host); + host = GNUNET_TESTBED_host_create(NULL, NULL, cfg, 0); + GNUNET_assert(NULL != host); + GNUNET_assert(0 == GNUNET_TESTBED_host_get_id_(host)); + GNUNET_assert(host == GNUNET_TESTBED_host_lookup_by_id_(0)); hosts = NULL; - num_hosts = GNUNET_TESTBED_hosts_load_from_file ("sample_hosts.txt", cfg, &hosts); - GNUNET_assert (7 == num_hosts); - GNUNET_assert (NULL != hosts); + num_hosts = GNUNET_TESTBED_hosts_load_from_file("sample_hosts.txt", cfg, &hosts); + GNUNET_assert(7 == num_hosts); + GNUNET_assert(NULL != hosts); for (cnt = 0; cnt < num_hosts; cnt++) - { - if (cnt < 3) - { - GNUNET_assert (0 == strcmp ("totakura", - GNUNET_TESTBED_host_get_username_ - (hosts[cnt]))); - GNUNET_assert (NULL != GNUNET_TESTBED_host_get_hostname (hosts[cnt])); - GNUNET_assert (22 == GNUNET_TESTBED_host_get_ssh_port_ (hosts[cnt])); - } - if (3 == cnt) { - GNUNET_assert (0 == strcmp ("totakura", - GNUNET_TESTBED_host_get_username_ - (hosts[cnt]))); - GNUNET_assert (NULL != GNUNET_TESTBED_host_get_hostname (hosts[cnt])); - GNUNET_assert (2022 == GNUNET_TESTBED_host_get_ssh_port_ (hosts[cnt])); + if (cnt < 3) + { + GNUNET_assert(0 == strcmp("totakura", + GNUNET_TESTBED_host_get_username_ + (hosts[cnt]))); + GNUNET_assert(NULL != GNUNET_TESTBED_host_get_hostname(hosts[cnt])); + GNUNET_assert(22 == GNUNET_TESTBED_host_get_ssh_port_(hosts[cnt])); + } + if (3 == cnt) + { + GNUNET_assert(0 == strcmp("totakura", + GNUNET_TESTBED_host_get_username_ + (hosts[cnt]))); + GNUNET_assert(NULL != GNUNET_TESTBED_host_get_hostname(hosts[cnt])); + GNUNET_assert(2022 == GNUNET_TESTBED_host_get_ssh_port_(hosts[cnt])); + } + if (4 == cnt) + { + GNUNET_assert(0 == strcmp("totakura", + GNUNET_TESTBED_host_get_username_ + (hosts[cnt]))); + GNUNET_assert(0 == strcmp("asgard.realm", + GNUNET_TESTBED_host_get_hostname + (hosts[cnt]))); + GNUNET_assert(22 == GNUNET_TESTBED_host_get_ssh_port_(hosts[cnt])); + } + if (5 == cnt) + { + GNUNET_assert(NULL == GNUNET_TESTBED_host_get_username_(hosts[cnt])); + GNUNET_assert(0 == strcmp("rivendal", + GNUNET_TESTBED_host_get_hostname + (hosts[cnt]))); + GNUNET_assert(22 == GNUNET_TESTBED_host_get_ssh_port_(hosts[cnt])); + } + if (6 == cnt) + { + GNUNET_assert(NULL == GNUNET_TESTBED_host_get_username_(hosts[cnt])); + GNUNET_assert(0 == strcmp("rohan", + GNUNET_TESTBED_host_get_hostname + (hosts[cnt]))); + GNUNET_assert(561 == GNUNET_TESTBED_host_get_ssh_port_(hosts[cnt])); + } } - if (4 == cnt) - { - GNUNET_assert (0 == strcmp ("totakura", - GNUNET_TESTBED_host_get_username_ - (hosts[cnt]))); - GNUNET_assert (0 == strcmp ("asgard.realm", - GNUNET_TESTBED_host_get_hostname - (hosts[cnt]))); - GNUNET_assert (22 == GNUNET_TESTBED_host_get_ssh_port_ (hosts[cnt])); - } - if (5 == cnt) - { - GNUNET_assert (NULL == GNUNET_TESTBED_host_get_username_ (hosts[cnt])); - GNUNET_assert (0 == strcmp ("rivendal", - GNUNET_TESTBED_host_get_hostname - (hosts[cnt]))); - GNUNET_assert (22 == GNUNET_TESTBED_host_get_ssh_port_ (hosts[cnt])); - } - if (6 == cnt) - { - GNUNET_assert (NULL == GNUNET_TESTBED_host_get_username_ (hosts[cnt])); - GNUNET_assert (0 == strcmp ("rohan", - GNUNET_TESTBED_host_get_hostname - (hosts[cnt]))); - GNUNET_assert (561 == GNUNET_TESTBED_host_get_ssh_port_ (hosts[cnt])); - } - } status = GNUNET_YES; - GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); + GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); } int -main (int argc, char **argv) +main(int argc, char **argv) { char *const argv2[] = { "test_testbed_api_hosts", - "-c", "test_testbed_api.conf", - NULL - }; + "-c", "test_testbed_api.conf", + NULL }; struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; status = GNUNET_SYSERR; if (GNUNET_OK != - GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, - "test_testbed_api_hosts", "nohelp", options, &run, - NULL)) + GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, argv2, + "test_testbed_api_hosts", "nohelp", options, &run, + NULL)) return 1; return (GNUNET_OK == status) ? 0 : 1; } diff --git a/src/testbed/test_testbed_api_operations.c b/src/testbed/test_testbed_api_operations.c index dfa8abc99..f88f85304 100644 --- a/src/testbed/test_testbed_api_operations.c +++ b/src/testbed/test_testbed_api_operations.c @@ -11,7 +11,7 @@ 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 . @@ -31,14 +31,14 @@ /** * Generic logging shortcut */ -#define LOG(kind,...) \ - GNUNET_log (kind, __VA_ARGS__) +#define LOG(kind, ...) \ + GNUNET_log(kind, __VA_ARGS__) /** * Delay to start step task */ #define STEP_DELAY \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500) + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500) /** * Queue A. Initially the max active is set to 2 and then reduced to 0 - this @@ -121,21 +121,20 @@ struct GNUNET_SCHEDULER_Task * step_task; /** * Enumeration of test stages */ -enum Test -{ - /** - * Initial stage - */ +enum Test { + /** + * Initial stage + */ TEST_INIT, - /** - * op1 has been started - */ + /** + * op1 has been started + */ TEST_OP1_STARTED, - /** - * op1 has been released - */ + /** + * op1 has been released + */ TEST_OP1_RELEASED, /** @@ -144,14 +143,14 @@ enum Test */ TEST_PAUSE, - /** - * op2 has started - */ + /** + * op2 has started + */ TEST_OP2_STARTED, - /** - * op2 released - */ + /** + * op2 released + */ TEST_OP2_RELEASED, /** @@ -242,7 +241,7 @@ enum Test result; * operation can be activated. */ static void -start_cb (void *cls); +start_cb(void *cls); /** @@ -255,7 +254,7 @@ start_cb (void *cls); * in 'cls' and release all resources associated with the operation. */ static void -release_cb (void *cls); +release_cb(void *cls); /** @@ -264,69 +263,79 @@ release_cb (void *cls); * @param cls NULL */ static void -step (void *cls) +step(void *cls) { - GNUNET_assert (NULL != step_task); + GNUNET_assert(NULL != step_task); step_task = NULL; switch (result) - { - case TEST_OP1_STARTED: - GNUNET_TESTBED_operation_release_ (op1); - GNUNET_TESTBED_operation_queue_reset_max_active_ (q1, 0); - op3 = GNUNET_TESTBED_operation_create_ (&op3, &start_cb, &release_cb); - GNUNET_TESTBED_operation_queue_insert2_ (q1, op3, 2); - GNUNET_TESTBED_operation_queue_insert2_ (q2, op3, 2); - GNUNET_TESTBED_operation_begin_wait_ (op3); - op4 = GNUNET_TESTBED_operation_create_ (&op4, &start_cb, &release_cb); - GNUNET_TESTBED_operation_queue_insert2_ (q1, op4, 2); - GNUNET_TESTBED_operation_queue_insert2_ (q2, op4, 2); - GNUNET_TESTBED_operation_begin_wait_ (op4); - break; - case TEST_OP1_RELEASED: - result = TEST_PAUSE; - GNUNET_TESTBED_operation_queue_reset_max_active_ (q1, 2); - break; - case TEST_OP2_STARTED: - GNUNET_TESTBED_operation_release_ (op2); - break; - case TEST_OP3_STARTED: - GNUNET_TESTBED_operation_release_ (op3); - break; - case TEST_OP4_STARTED: - GNUNET_TESTBED_operation_release_ (op4); - break; - case TEST_OP6_RELEASED: - op8 = GNUNET_TESTBED_operation_create_ (&op8, &start_cb, &release_cb); - GNUNET_TESTBED_operation_queue_insert2_ (q1, op8, 2); - GNUNET_TESTBED_operation_queue_insert2_ (q2, op8, 2); - result = TEST_OP8_WAITING; - GNUNET_TESTBED_operation_begin_wait_ (op8); - break; - case TEST_OP8_STARTED: - GNUNET_TESTBED_operation_inactivate_ (op8); - result = TEST_OP8_INACTIVE_1; - step_task = GNUNET_SCHEDULER_add_delayed (STEP_DELAY, &step, NULL); - break; - case TEST_OP8_INACTIVE_1: - GNUNET_TESTBED_operation_activate_ (op8); - result = TEST_OP8_ACTIVE; - op9 = GNUNET_TESTBED_operation_create_ (&op9, &start_cb, &release_cb); - GNUNET_TESTBED_operation_queue_insert2_ (q1, op9, 1); - GNUNET_TESTBED_operation_queue_insert2_ (q2, op9, 1); - GNUNET_TESTBED_operation_begin_wait_ (op9); - step_task = GNUNET_SCHEDULER_add_delayed (STEP_DELAY, &step, NULL); - break; - case TEST_OP8_ACTIVE: - GNUNET_TESTBED_operation_inactivate_ (op8); - /* op8 should be released by now due to above call */ - GNUNET_assert (TEST_OP8_RELEASED == result); - break; - case TEST_OP9_STARTED: - GNUNET_TESTBED_operation_release_ (op9); - break; - default: - GNUNET_assert (0); - } + { + case TEST_OP1_STARTED: + GNUNET_TESTBED_operation_release_(op1); + GNUNET_TESTBED_operation_queue_reset_max_active_(q1, 0); + op3 = GNUNET_TESTBED_operation_create_(&op3, &start_cb, &release_cb); + GNUNET_TESTBED_operation_queue_insert2_(q1, op3, 2); + GNUNET_TESTBED_operation_queue_insert2_(q2, op3, 2); + GNUNET_TESTBED_operation_begin_wait_(op3); + op4 = GNUNET_TESTBED_operation_create_(&op4, &start_cb, &release_cb); + GNUNET_TESTBED_operation_queue_insert2_(q1, op4, 2); + GNUNET_TESTBED_operation_queue_insert2_(q2, op4, 2); + GNUNET_TESTBED_operation_begin_wait_(op4); + break; + + case TEST_OP1_RELEASED: + result = TEST_PAUSE; + GNUNET_TESTBED_operation_queue_reset_max_active_(q1, 2); + break; + + case TEST_OP2_STARTED: + GNUNET_TESTBED_operation_release_(op2); + break; + + case TEST_OP3_STARTED: + GNUNET_TESTBED_operation_release_(op3); + break; + + case TEST_OP4_STARTED: + GNUNET_TESTBED_operation_release_(op4); + break; + + case TEST_OP6_RELEASED: + op8 = GNUNET_TESTBED_operation_create_(&op8, &start_cb, &release_cb); + GNUNET_TESTBED_operation_queue_insert2_(q1, op8, 2); + GNUNET_TESTBED_operation_queue_insert2_(q2, op8, 2); + result = TEST_OP8_WAITING; + GNUNET_TESTBED_operation_begin_wait_(op8); + break; + + case TEST_OP8_STARTED: + GNUNET_TESTBED_operation_inactivate_(op8); + result = TEST_OP8_INACTIVE_1; + step_task = GNUNET_SCHEDULER_add_delayed(STEP_DELAY, &step, NULL); + break; + + case TEST_OP8_INACTIVE_1: + GNUNET_TESTBED_operation_activate_(op8); + result = TEST_OP8_ACTIVE; + op9 = GNUNET_TESTBED_operation_create_(&op9, &start_cb, &release_cb); + GNUNET_TESTBED_operation_queue_insert2_(q1, op9, 1); + GNUNET_TESTBED_operation_queue_insert2_(q2, op9, 1); + GNUNET_TESTBED_operation_begin_wait_(op9); + step_task = GNUNET_SCHEDULER_add_delayed(STEP_DELAY, &step, NULL); + break; + + case TEST_OP8_ACTIVE: + GNUNET_TESTBED_operation_inactivate_(op8); + /* op8 should be released by now due to above call */ + GNUNET_assert(TEST_OP8_RELEASED == result); + break; + + case TEST_OP9_STARTED: + GNUNET_TESTBED_operation_release_(op9); + break; + + default: + GNUNET_assert(0); + } } @@ -336,64 +345,71 @@ step (void *cls) * operation can be activated. */ static void -start_cb (void *cls) +start_cb(void *cls) { switch (result) - { - case TEST_INIT: - GNUNET_assert (&op1 == cls); - result = TEST_OP1_STARTED; - GNUNET_assert (NULL == step_task); - step_task = - GNUNET_SCHEDULER_add_delayed (STEP_DELAY, &step, NULL); - break; - case TEST_PAUSE: - GNUNET_assert (&op2 == cls); - result = TEST_OP2_STARTED; - GNUNET_assert (NULL == step_task); - step_task = - GNUNET_SCHEDULER_add_delayed (STEP_DELAY, &step, NULL); - break; - case TEST_OP2_RELEASED: - GNUNET_assert (&op3 == cls); - result = TEST_OP3_STARTED; - GNUNET_assert (NULL == step_task); - step_task = - GNUNET_SCHEDULER_add_delayed (STEP_DELAY, &step, NULL); - break; - case TEST_OP3_RELEASED: - GNUNET_assert (&op4 == cls); - result = TEST_OP4_STARTED; - GNUNET_assert (NULL == step_task); - step_task = - GNUNET_SCHEDULER_add_delayed (STEP_DELAY, &step, NULL); - break; - case TEST_OP4_RELEASED: - { - static int nops; - - nops++; - if (nops == 3) { - result = TEST_OP5_6_7_STARTED; - GNUNET_TESTBED_operation_release_ (op5); - op5 = NULL; + case TEST_INIT: + GNUNET_assert(&op1 == cls); + result = TEST_OP1_STARTED; + GNUNET_assert(NULL == step_task); + step_task = + GNUNET_SCHEDULER_add_delayed(STEP_DELAY, &step, NULL); + break; + + case TEST_PAUSE: + GNUNET_assert(&op2 == cls); + result = TEST_OP2_STARTED; + GNUNET_assert(NULL == step_task); + step_task = + GNUNET_SCHEDULER_add_delayed(STEP_DELAY, &step, NULL); + break; + + case TEST_OP2_RELEASED: + GNUNET_assert(&op3 == cls); + result = TEST_OP3_STARTED; + GNUNET_assert(NULL == step_task); + step_task = + GNUNET_SCHEDULER_add_delayed(STEP_DELAY, &step, NULL); + break; + + case TEST_OP3_RELEASED: + GNUNET_assert(&op4 == cls); + result = TEST_OP4_STARTED; + GNUNET_assert(NULL == step_task); + step_task = + GNUNET_SCHEDULER_add_delayed(STEP_DELAY, &step, NULL); + break; + + case TEST_OP4_RELEASED: + { + static int nops; + + nops++; + if (nops == 3) + { + result = TEST_OP5_6_7_STARTED; + GNUNET_TESTBED_operation_release_(op5); + op5 = NULL; + } } - } break; - case TEST_OP7_RELEASED: - GNUNET_assert (&op8 == cls); - result = TEST_OP8_STARTED; - step_task = GNUNET_SCHEDULER_add_delayed (STEP_DELAY, &step, NULL); - break; - case TEST_OP8_RELEASED: - GNUNET_assert (&op9 == cls); - result = TEST_OP9_STARTED; - step_task = GNUNET_SCHEDULER_add_delayed (STEP_DELAY, &step, NULL); - break; - default: - GNUNET_assert (0); - } + + case TEST_OP7_RELEASED: + GNUNET_assert(&op8 == cls); + result = TEST_OP8_STARTED; + step_task = GNUNET_SCHEDULER_add_delayed(STEP_DELAY, &step, NULL); + break; + + case TEST_OP8_RELEASED: + GNUNET_assert(&op9 == cls); + result = TEST_OP9_STARTED; + step_task = GNUNET_SCHEDULER_add_delayed(STEP_DELAY, &step, NULL); + break; + + default: + GNUNET_assert(0); + } } @@ -407,73 +423,82 @@ start_cb (void *cls) * in 'cls' and release all resources associated with the operation. */ static void -release_cb (void *cls) +release_cb(void *cls) { switch (result) - { - case TEST_OP1_STARTED: - GNUNET_assert (&op1 == cls); - result = TEST_OP1_RELEASED; - op1 = NULL; - step_task = - GNUNET_SCHEDULER_add_delayed (STEP_DELAY, &step, NULL); - break; - case TEST_OP2_STARTED: - GNUNET_assert (&op2 == cls); - result = TEST_OP2_RELEASED; - GNUNET_assert (NULL == step_task); - break; - case TEST_OP3_STARTED: - GNUNET_assert (&op3 == cls); - result = TEST_OP3_RELEASED; - GNUNET_assert (NULL == step_task); - break; - case TEST_OP4_STARTED: - GNUNET_assert (&op4 == cls); - result = TEST_OP4_RELEASED; - GNUNET_assert (NULL == step_task); - op5 = GNUNET_TESTBED_operation_create_ (&op5, &start_cb, &release_cb); - GNUNET_TESTBED_operation_queue_insert2_ (q1, op5, 1); - GNUNET_TESTBED_operation_begin_wait_ (op5); - op6 = GNUNET_TESTBED_operation_create_ (&op6, &start_cb, &release_cb); - GNUNET_TESTBED_operation_queue_insert2_ (q2, op6, 1); - GNUNET_TESTBED_operation_begin_wait_ (op6); - op7 = GNUNET_TESTBED_operation_create_ (&op7, &start_cb, &release_cb); - GNUNET_TESTBED_operation_queue_insert2_ (q1, op7, 1); - GNUNET_TESTBED_operation_queue_insert2_ (q2, op7, 1); - GNUNET_TESTBED_operation_begin_wait_ (op7); - break; - case TEST_OP5_6_7_STARTED: - result = TEST_OP5_RELEASED; - op5 = NULL; - GNUNET_TESTBED_operation_release_ (op6); - break; - case TEST_OP5_RELEASED: - op6 = NULL; - result = TEST_OP6_RELEASED; - GNUNET_TESTBED_operation_inactivate_ (op7); - step_task = GNUNET_SCHEDULER_add_now (&step, NULL); - break; - case TEST_OP8_WAITING: - GNUNET_assert (&op7 == cls); - op7 = NULL; - result = TEST_OP7_RELEASED; - break; - case TEST_OP8_ACTIVE: - result = TEST_OP8_RELEASED; - op8 = NULL; - break; - case TEST_OP9_STARTED: - GNUNET_assert (&op9 == cls); - result = TEST_OP9_RELEASED; - GNUNET_TESTBED_operation_queue_destroy_ (q1); - GNUNET_TESTBED_operation_queue_destroy_ (q2); - q1 = NULL; - q2 = NULL; - break; - default: - GNUNET_assert (0); - } + { + case TEST_OP1_STARTED: + GNUNET_assert(&op1 == cls); + result = TEST_OP1_RELEASED; + op1 = NULL; + step_task = + GNUNET_SCHEDULER_add_delayed(STEP_DELAY, &step, NULL); + break; + + case TEST_OP2_STARTED: + GNUNET_assert(&op2 == cls); + result = TEST_OP2_RELEASED; + GNUNET_assert(NULL == step_task); + break; + + case TEST_OP3_STARTED: + GNUNET_assert(&op3 == cls); + result = TEST_OP3_RELEASED; + GNUNET_assert(NULL == step_task); + break; + + case TEST_OP4_STARTED: + GNUNET_assert(&op4 == cls); + result = TEST_OP4_RELEASED; + GNUNET_assert(NULL == step_task); + op5 = GNUNET_TESTBED_operation_create_(&op5, &start_cb, &release_cb); + GNUNET_TESTBED_operation_queue_insert2_(q1, op5, 1); + GNUNET_TESTBED_operation_begin_wait_(op5); + op6 = GNUNET_TESTBED_operation_create_(&op6, &start_cb, &release_cb); + GNUNET_TESTBED_operation_queue_insert2_(q2, op6, 1); + GNUNET_TESTBED_operation_begin_wait_(op6); + op7 = GNUNET_TESTBED_operation_create_(&op7, &start_cb, &release_cb); + GNUNET_TESTBED_operation_queue_insert2_(q1, op7, 1); + GNUNET_TESTBED_operation_queue_insert2_(q2, op7, 1); + GNUNET_TESTBED_operation_begin_wait_(op7); + break; + + case TEST_OP5_6_7_STARTED: + result = TEST_OP5_RELEASED; + op5 = NULL; + GNUNET_TESTBED_operation_release_(op6); + break; + + case TEST_OP5_RELEASED: + op6 = NULL; + result = TEST_OP6_RELEASED; + GNUNET_TESTBED_operation_inactivate_(op7); + step_task = GNUNET_SCHEDULER_add_now(&step, NULL); + break; + + case TEST_OP8_WAITING: + GNUNET_assert(&op7 == cls); + op7 = NULL; + result = TEST_OP7_RELEASED; + break; + + case TEST_OP8_ACTIVE: + result = TEST_OP8_RELEASED; + op8 = NULL; + break; + + case TEST_OP9_STARTED: + GNUNET_assert(&op9 == cls); + result = TEST_OP9_RELEASED; + GNUNET_TESTBED_operation_queue_destroy_(q1); + GNUNET_TESTBED_operation_queue_destroy_(q2); + q1 = NULL; + q2 = NULL; + break; + + default: + GNUNET_assert(0); + } } @@ -486,22 +511,22 @@ release_cb (void *cls) * @param cfg the configuration file handle */ static void -run (void *cls, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *config) +run(void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *config) { - q1 = GNUNET_TESTBED_operation_queue_create_ (OPERATION_QUEUE_TYPE_FIXED, 1); - GNUNET_assert (NULL != q1); - q2 = GNUNET_TESTBED_operation_queue_create_ (OPERATION_QUEUE_TYPE_FIXED, 2); - GNUNET_assert (NULL != q2); - op1 = GNUNET_TESTBED_operation_create_ (&op1, start_cb, release_cb); - GNUNET_assert (NULL != op1); - op2 = GNUNET_TESTBED_operation_create_ (&op2, start_cb, release_cb); - GNUNET_TESTBED_operation_queue_insert_ (q1, op1); - GNUNET_TESTBED_operation_queue_insert_ (q2, op1); - GNUNET_TESTBED_operation_begin_wait_ (op1); - GNUNET_TESTBED_operation_queue_insert_ (q1, op2); - GNUNET_TESTBED_operation_queue_insert_ (q2, op2); - GNUNET_TESTBED_operation_begin_wait_ (op2); + q1 = GNUNET_TESTBED_operation_queue_create_(OPERATION_QUEUE_TYPE_FIXED, 1); + GNUNET_assert(NULL != q1); + q2 = GNUNET_TESTBED_operation_queue_create_(OPERATION_QUEUE_TYPE_FIXED, 2); + GNUNET_assert(NULL != q2); + op1 = GNUNET_TESTBED_operation_create_(&op1, start_cb, release_cb); + GNUNET_assert(NULL != op1); + op2 = GNUNET_TESTBED_operation_create_(&op2, start_cb, release_cb); + GNUNET_TESTBED_operation_queue_insert_(q1, op1); + GNUNET_TESTBED_operation_queue_insert_(q2, op1); + GNUNET_TESTBED_operation_begin_wait_(op1); + GNUNET_TESTBED_operation_queue_insert_(q1, op2); + GNUNET_TESTBED_operation_queue_insert_(q2, op2); + GNUNET_TESTBED_operation_begin_wait_(op2); result = TEST_INIT; } @@ -510,18 +535,18 @@ run (void *cls, char *const *args, const char *cfgfile, * Main function */ int -main (int argc, char **argv) +main(int argc, char **argv) { int ret; char *const argv2[] = - { "test_testbed_api_operations", "-c", "test_testbed_api.conf", NULL }; + { "test_testbed_api_operations", "-c", "test_testbed_api.conf", NULL }; struct GNUNET_GETOPT_CommandLineOption options[] = - { GNUNET_GETOPT_OPTION_END }; + { GNUNET_GETOPT_OPTION_END }; ret = - GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, - "test_testbed_api_operations", "nohelp", options, - &run, NULL); + GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, argv2, + "test_testbed_api_operations", "nohelp", options, + &run, NULL); if ((GNUNET_OK != ret) || (TEST_OP9_RELEASED != result)) return 1; op1 = NULL; diff --git a/src/testbed/test_testbed_api_peer_reconfiguration.c b/src/testbed/test_testbed_api_peer_reconfiguration.c index e79876997..40791a9cc 100644 --- a/src/testbed/test_testbed_api_peer_reconfiguration.c +++ b/src/testbed/test_testbed_api_peer_reconfiguration.c @@ -11,7 +11,7 @@ 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 . @@ -53,7 +53,6 @@ static struct GNUNET_SCHEDULER_Task * abort_task; * States in this test */ enum { - /** * Test has just been initialized */ @@ -68,20 +67,19 @@ enum { * Peer has been reconfigured. Test completed successfully */ STATE_PEER_RECONFIGURED - } state; /** * Fail testcase */ #define FAIL_TEST(cond, ret) do { \ - if (!(cond)) { \ - GNUNET_break(0); \ - if (NULL != abort_task) \ - GNUNET_SCHEDULER_cancel (abort_task); \ - abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); \ - ret; \ - } \ + if (!(cond)) { \ + GNUNET_break(0); \ + if (NULL != abort_task) \ + GNUNET_SCHEDULER_cancel (abort_task); \ + abort_task = GNUNET_SCHEDULER_add_now(&do_abort, NULL); \ + ret; \ + } \ } while (0) @@ -91,15 +89,15 @@ enum { * @param cls NULL */ static void -do_abort (void *cls) +do_abort(void *cls) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Aborting\n"); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Aborting\n"); abort_task = NULL; if (NULL != op) - { - GNUNET_TESTBED_operation_done (op); - op = NULL; - } + { + GNUNET_TESTBED_operation_done(op); + op = NULL; + } GNUNET_SCHEDULER_shutdown(); } @@ -112,29 +110,29 @@ do_abort (void *cls) * @param event information about the event */ static void -controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) +controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event) { if (STATE_PEER_STARTED != state) return; if (GNUNET_TESTBED_ET_OPERATION_FINISHED != event->type) - { - GNUNET_TESTBED_operation_done (op); - op = NULL; - FAIL_TEST (0, return); - } + { + GNUNET_TESTBED_operation_done(op); + op = NULL; + FAIL_TEST(0, return ); + } if (NULL != event->details.operation_finished.emsg) - { - fprintf (stderr, "Operation failed: %s\n", - event->details.operation_finished.emsg); - GNUNET_TESTBED_operation_done (op); - op = NULL; - FAIL_TEST (0, return); - } - GNUNET_TESTBED_operation_done (op); + { + fprintf(stderr, "Operation failed: %s\n", + event->details.operation_finished.emsg); + GNUNET_TESTBED_operation_done(op); + op = NULL; + FAIL_TEST(0, return ); + } + GNUNET_TESTBED_operation_done(op); state = STATE_PEER_RECONFIGURED; - GNUNET_SCHEDULER_cancel (abort_task); + GNUNET_SCHEDULER_cancel(abort_task); abort_task = NULL; - GNUNET_SCHEDULER_shutdown (); + GNUNET_SCHEDULER_shutdown(); } @@ -151,27 +149,27 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) * failed */ static void -test_master (void *cls, - struct GNUNET_TESTBED_RunHandle *h, - unsigned int num_peers, - struct GNUNET_TESTBED_Peer **peers_, - unsigned int links_succeeded, - unsigned int links_failed) +test_master(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 GNUNET_CONFIGURATION_Handle *cfg; - FAIL_TEST (NUM_PEERS == num_peers, return); + FAIL_TEST(NUM_PEERS == num_peers, return ); state = STATE_PEER_STARTED; peers = peers_; - cfg = GNUNET_CONFIGURATION_create (); - FAIL_TEST (GNUNET_OK == GNUNET_CONFIGURATION_load - (cfg, "test_testbed_api_testbed_run_topologyrandom.conf"), return); - op = GNUNET_TESTBED_peer_update_configuration (peers[0], cfg); - GNUNET_CONFIGURATION_destroy (cfg); - FAIL_TEST (NULL != op, return); - abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_SECONDS, 30), - &do_abort, NULL); + cfg = GNUNET_CONFIGURATION_create(); + FAIL_TEST(GNUNET_OK == GNUNET_CONFIGURATION_load + (cfg, "test_testbed_api_testbed_run_topologyrandom.conf"), return ); + op = GNUNET_TESTBED_peer_update_configuration(peers[0], cfg); + GNUNET_CONFIGURATION_destroy(cfg); + FAIL_TEST(NULL != op, return ); + abort_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, 30), + &do_abort, NULL); } @@ -179,15 +177,15 @@ test_master (void *cls, * Main function */ int -main (int argc, char **argv) +main(int argc, char **argv) { state = STATE_INIT; - (void) GNUNET_TESTBED_test_run ("test_testbed_api_peer_reconfiguration", - "test_testbed_api.conf", - NUM_PEERS, - 1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED, - &controller_cb, NULL, - &test_master, NULL); + (void)GNUNET_TESTBED_test_run("test_testbed_api_peer_reconfiguration", + "test_testbed_api.conf", + NUM_PEERS, + 1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED, + &controller_cb, NULL, + &test_master, NULL); if (STATE_PEER_RECONFIGURED != state) return 1; return 0; diff --git a/src/testbed/test_testbed_api_peers_manage_services.c b/src/testbed/test_testbed_api_peers_manage_services.c index c5e2b2646..d6597890f 100644 --- a/src/testbed/test_testbed_api_peers_manage_services.c +++ b/src/testbed/test_testbed_api_peers_manage_services.c @@ -11,7 +11,7 @@ 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 . @@ -47,7 +47,7 @@ static struct GNUNET_TESTBED_Operation *op; /** * dummy pointer */ -static void *dummy_cls = (void *) 0xDEAD0001; +static void *dummy_cls = (void *)0xDEAD0001; /** * Abort task identifier @@ -58,7 +58,6 @@ static struct GNUNET_SCHEDULER_Task * abort_task; * States in this test */ enum { - /** * Test has just been initialized */ @@ -89,13 +88,13 @@ enum { * Fail testcase */ #define FAIL_TEST(cond, ret) do { \ - if (!(cond)) { \ - GNUNET_break(0); \ - if (NULL != abort_task) \ - GNUNET_SCHEDULER_cancel (abort_task); \ - abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); \ - ret; \ - } \ + if (!(cond)) { \ + GNUNET_break(0); \ + if (NULL != abort_task) \ + GNUNET_SCHEDULER_cancel (abort_task); \ + abort_task = GNUNET_SCHEDULER_add_now(&do_abort, NULL); \ + ret; \ + } \ } while (0) @@ -105,15 +104,15 @@ enum { * @param cls NULL */ static void -do_abort (void *cls) +do_abort(void *cls) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Aborting\n"); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Aborting\n"); abort_task = NULL; if (NULL != op) - { - GNUNET_TESTBED_operation_done (op); - op = NULL; - } + { + GNUNET_TESTBED_operation_done(op); + op = NULL; + } GNUNET_SCHEDULER_shutdown(); } @@ -127,36 +126,38 @@ do_abort (void *cls) * operation has executed successfully. */ static void -op_comp_cb (void *cls, - struct GNUNET_TESTBED_Operation *op, - const char *emsg) +op_comp_cb(void *cls, + struct GNUNET_TESTBED_Operation *op, + const char *emsg) { - FAIL_TEST (cls == dummy_cls, return); - FAIL_TEST (NULL == emsg, return); - GNUNET_TESTBED_operation_done (op); + FAIL_TEST(cls == dummy_cls, return ); + FAIL_TEST(NULL == emsg, return ); + GNUNET_TESTBED_operation_done(op); op = NULL; switch (state) - { - case STATE_PEERS_STARTED: - state = STATE_SERVICE_DOWN; - op = GNUNET_TESTBED_peer_manage_service (dummy_cls, - peers[1], - "topology", - op_comp_cb, - dummy_cls, - 0); - GNUNET_assert (NULL != op); - break; - case STATE_SERVICE_DOWN: - state = STATE_SERVICE_UP; - GNUNET_SCHEDULER_cancel (abort_task); - abort_task = NULL; - state = STATE_OK; - GNUNET_SCHEDULER_shutdown (); - break; - default: - FAIL_TEST (0, return); - } + { + case STATE_PEERS_STARTED: + state = STATE_SERVICE_DOWN; + op = GNUNET_TESTBED_peer_manage_service(dummy_cls, + peers[1], + "topology", + op_comp_cb, + dummy_cls, + 0); + GNUNET_assert(NULL != op); + break; + + case STATE_SERVICE_DOWN: + state = STATE_SERVICE_UP; + GNUNET_SCHEDULER_cancel(abort_task); + abort_task = NULL; + state = STATE_OK; + GNUNET_SCHEDULER_shutdown(); + break; + + default: + FAIL_TEST(0, return ); + } } @@ -173,26 +174,26 @@ op_comp_cb (void *cls, * failed */ static void -test_master (void *cls, - struct GNUNET_TESTBED_RunHandle *h, - unsigned int num_peers, - struct GNUNET_TESTBED_Peer **peers_, - unsigned int links_succeeded, - unsigned int links_failed) +test_master(void *cls, + struct GNUNET_TESTBED_RunHandle *h, + unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers_, + unsigned int links_succeeded, + unsigned int links_failed) { - FAIL_TEST (NUM_PEERS == num_peers, return); + FAIL_TEST(NUM_PEERS == num_peers, return ); state = STATE_PEERS_STARTED; peers = peers_; - op = GNUNET_TESTBED_peer_manage_service (dummy_cls, - peers[1], - "topology", - op_comp_cb, - dummy_cls, - 1); - FAIL_TEST (NULL != op, return); - abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_MINUTES, 1), - &do_abort, NULL); + op = GNUNET_TESTBED_peer_manage_service(dummy_cls, + peers[1], + "topology", + op_comp_cb, + dummy_cls, + 1); + FAIL_TEST(NULL != op, return ); + abort_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_MINUTES, 1), + &do_abort, NULL); } @@ -200,14 +201,14 @@ test_master (void *cls, * Main function */ int -main (int argc, char **argv) +main(int argc, char **argv) { state = STATE_INIT; - (void) GNUNET_TESTBED_test_run ("test_testbed_api_peers_manage_services", - "test_testbed_api.conf", - NUM_PEERS, - 1LL, NULL, NULL, - &test_master, NULL); + (void)GNUNET_TESTBED_test_run("test_testbed_api_peers_manage_services", + "test_testbed_api.conf", + NUM_PEERS, + 1LL, NULL, NULL, + &test_master, NULL); if (STATE_OK != state) return 1; return 0; diff --git a/src/testbed/test_testbed_api_sd.c b/src/testbed/test_testbed_api_sd.c index 1a7b4adbd..81b8dba41 100644 --- a/src/testbed/test_testbed_api_sd.c +++ b/src/testbed/test_testbed_api_sd.c @@ -11,7 +11,7 @@ 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 . @@ -43,47 +43,47 @@ static int ret; * @param cfg the configuration file handle */ static void -run (void *cls, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *config) +run(void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *config) { - struct SDHandle *h = GNUNET_TESTBED_SD_init_ (20); + struct SDHandle *h = GNUNET_TESTBED_SD_init_(20); int sd; ret = 0; - GNUNET_TESTBED_SD_add_data_ (h, 40); - if (GNUNET_SYSERR != GNUNET_TESTBED_SD_deviation_factor_ (h, 10, &sd)) - { - GNUNET_break (0); - ret = 1; - goto err; - } - GNUNET_TESTBED_SD_add_data_ (h, 30); - if (GNUNET_SYSERR == GNUNET_TESTBED_SD_deviation_factor_ (h, 80, &sd)) - { - GNUNET_break (0); - ret = 1; - goto err; - } - GNUNET_TESTBED_SD_add_data_ (h, 40); - if ((GNUNET_SYSERR == GNUNET_TESTBED_SD_deviation_factor_ (h, 30, &sd)) + GNUNET_TESTBED_SD_add_data_(h, 40); + if (GNUNET_SYSERR != GNUNET_TESTBED_SD_deviation_factor_(h, 10, &sd)) + { + GNUNET_break(0); + ret = 1; + goto err; + } + GNUNET_TESTBED_SD_add_data_(h, 30); + if (GNUNET_SYSERR == GNUNET_TESTBED_SD_deviation_factor_(h, 80, &sd)) + { + GNUNET_break(0); + ret = 1; + goto err; + } + GNUNET_TESTBED_SD_add_data_(h, 40); + if ((GNUNET_SYSERR == GNUNET_TESTBED_SD_deviation_factor_(h, 30, &sd)) || (-2 != sd)) - { - GNUNET_break (0); - ret = 1; - goto err; - } - GNUNET_TESTBED_SD_add_data_ (h, 10); - GNUNET_TESTBED_SD_add_data_ (h, 30); - if ((GNUNET_SYSERR == GNUNET_TESTBED_SD_deviation_factor_ (h, 60, &sd)) + { + GNUNET_break(0); + ret = 1; + goto err; + } + GNUNET_TESTBED_SD_add_data_(h, 10); + GNUNET_TESTBED_SD_add_data_(h, 30); + if ((GNUNET_SYSERR == GNUNET_TESTBED_SD_deviation_factor_(h, 60, &sd)) || (3 != sd)) - { - GNUNET_break (0); - ret = 1; - goto err; - } + { + GNUNET_break(0); + ret = 1; + goto err; + } - err: - GNUNET_TESTBED_SD_destroy_ (h); +err: + GNUNET_TESTBED_SD_destroy_(h); } @@ -91,7 +91,7 @@ run (void *cls, char *const *args, const char *cfgfile, * Main function */ int -main (int argc, char **argv) +main(int argc, char **argv) { struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END @@ -100,8 +100,8 @@ main (int argc, char **argv) result = GNUNET_SYSERR; result = - GNUNET_PROGRAM_run (argc, argv, - "test_testbed_api_sd", "nohelp", options, &run, NULL); + GNUNET_PROGRAM_run(argc, argv, + "test_testbed_api_sd", "nohelp", options, &run, NULL); if ((GNUNET_OK != result)) return 1; return ret; diff --git a/src/testbed/test_testbed_api_statistics.c b/src/testbed/test_testbed_api_statistics.c index 6d1673cef..26f90cfff 100644 --- a/src/testbed/test_testbed_api_statistics.c +++ b/src/testbed/test_testbed_api_statistics.c @@ -11,7 +11,7 @@ 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 . @@ -46,7 +46,7 @@ static struct GNUNET_TESTBED_Operation *op; /** * dummy pointer */ -static void *dummy_cls = (void *) 0xDEAD0001; +static void *dummy_cls = (void *)0xDEAD0001; /** * Abort task identifier @@ -73,13 +73,13 @@ static unsigned int num_seen_peers; * Fail testcase */ #define FAIL_TEST(cond, ret) do { \ - if (!(cond)) { \ - GNUNET_break(0); \ - if (NULL != abort_task) \ - GNUNET_SCHEDULER_cancel (abort_task); \ - abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); \ - ret; \ - } \ + if (!(cond)) { \ + GNUNET_break(0); \ + if (NULL != abort_task) \ + GNUNET_SCHEDULER_cancel (abort_task); \ + abort_task = GNUNET_SCHEDULER_add_now(&do_abort, NULL); \ + ret; \ + } \ } while (0) @@ -89,15 +89,15 @@ static unsigned int num_seen_peers; * @param cls NULL */ static void -do_abort (void *cls) +do_abort(void *cls) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test timed out -- Aborting\n"); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Test timed out -- Aborting\n"); abort_task = NULL; if (NULL != op) - { - GNUNET_TESTBED_operation_done (op); - op = NULL; - } + { + GNUNET_TESTBED_operation_done(op); + op = NULL; + } result = GNUNET_SYSERR; } @@ -114,20 +114,20 @@ do_abort (void *cls) * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration */ static int -stats_iterator (void *cls, - const struct GNUNET_TESTBED_Peer *peer, - const char *subsystem, const char *name, uint64_t value, - int is_persistent) +stats_iterator(void *cls, + const struct GNUNET_TESTBED_Peer *peer, + const char *subsystem, const char *name, uint64_t value, + int is_persistent) { unsigned int cnt; - FAIL_TEST (cls == dummy_cls, return GNUNET_SYSERR); + FAIL_TEST(cls == dummy_cls, return GNUNET_SYSERR); for (cnt = 0; cnt < num_seen_peers; cnt++) - FAIL_TEST (peer != seen_peers[cnt], return GNUNET_SYSERR); - FAIL_TEST (NULL != subsystem, return GNUNET_SYSERR); - FAIL_TEST (NULL != name, return GNUNET_SYSERR); - GNUNET_array_append (seen_peers, num_seen_peers, - (struct GNUNET_TESTBED_Peer *) peer); + FAIL_TEST(peer != seen_peers[cnt], return GNUNET_SYSERR); + FAIL_TEST(NULL != subsystem, return GNUNET_SYSERR); + FAIL_TEST(NULL != name, return GNUNET_SYSERR); + GNUNET_array_append(seen_peers, num_seen_peers, + (struct GNUNET_TESTBED_Peer *)peer); return GNUNET_SYSERR; } @@ -141,16 +141,16 @@ stats_iterator (void *cls, * operation has executed successfully. */ static void -op_comp_cb (void *cls, - struct GNUNET_TESTBED_Operation *op, - const char *emsg) +op_comp_cb(void *cls, + struct GNUNET_TESTBED_Operation *op, + const char *emsg) { - FAIL_TEST (cls == dummy_cls, return); + FAIL_TEST(cls == dummy_cls, return ); result = GNUNET_OK; - GNUNET_TESTBED_operation_done (op); + GNUNET_TESTBED_operation_done(op); op = NULL; - GNUNET_SCHEDULER_cancel (abort_task); - GNUNET_SCHEDULER_shutdown (); + GNUNET_SCHEDULER_cancel(abort_task); + GNUNET_SCHEDULER_shutdown(); } @@ -167,23 +167,23 @@ op_comp_cb (void *cls, * failed */ static void -test_master (void *cls, - struct GNUNET_TESTBED_RunHandle *h, - unsigned int num_peers, - struct GNUNET_TESTBED_Peer **peers_, - unsigned int links_succeeded, - unsigned int links_failed) +test_master(void *cls, + struct GNUNET_TESTBED_RunHandle *h, + unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers_, + unsigned int links_succeeded, + unsigned int links_failed) { - FAIL_TEST (NUM_PEERS == num_peers, return); + FAIL_TEST(NUM_PEERS == num_peers, return ); peers = peers_; - op = GNUNET_TESTBED_get_statistics (num_peers, peers, - NULL, NULL, - &stats_iterator, - &op_comp_cb, - dummy_cls); - abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_MINUTES, 1), - &do_abort, NULL); + op = GNUNET_TESTBED_get_statistics(num_peers, peers, + NULL, NULL, + &stats_iterator, + &op_comp_cb, + dummy_cls); + abort_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_MINUTES, 1), + &do_abort, NULL); } @@ -191,14 +191,14 @@ test_master (void *cls, * Main function */ int -main (int argc, char **argv) +main(int argc, char **argv) { - (void) GNUNET_TESTBED_test_run ("test_testbed_api_statistics", - "test_testbed_api_statistics.conf", - NUM_PEERS, - 1LL, NULL, NULL, - &test_master, NULL); - GNUNET_free_non_null (seen_peers); + (void)GNUNET_TESTBED_test_run("test_testbed_api_statistics", + "test_testbed_api_statistics.conf", + NUM_PEERS, + 1LL, NULL, NULL, + &test_master, NULL); + GNUNET_free_non_null(seen_peers); if (GNUNET_OK != result) return 1; return 0; diff --git a/src/testbed/test_testbed_api_test.c b/src/testbed/test_testbed_api_test.c index 372ac1ebe..3f8f536e7 100644 --- a/src/testbed/test_testbed_api_test.c +++ b/src/testbed/test_testbed_api_test.c @@ -1,22 +1,22 @@ /* - This file is part of GNUnet - Copyright (C) 2008--2013 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 . + This file is part of GNUnet + Copyright (C) 2008--2013 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 src/testbed/test_testbed_api_test.c @@ -32,8 +32,8 @@ /** * Generic logging shortcut */ -#define LOG(kind,...) \ - GNUNET_log (kind, __VA_ARGS__) +#define LOG(kind, ...) \ + GNUNET_log(kind, __VA_ARGS__) /** * Number of peers we want to start @@ -72,29 +72,29 @@ static int result; * @param cls NULL */ static void -do_shutdown (void *cls) +do_shutdown(void *cls) { shutdown_task = NULL; if (NULL != abort_task) - GNUNET_SCHEDULER_cancel (abort_task); + GNUNET_SCHEDULER_cancel(abort_task); if (NULL != op) - GNUNET_TESTBED_operation_done (op); - GNUNET_SCHEDULER_shutdown (); + GNUNET_TESTBED_operation_done(op); + GNUNET_SCHEDULER_shutdown(); } /** * shortcut to exit during failure */ #define FAIL_TEST(cond) do { \ - if (!(cond)) { \ - GNUNET_break(0); \ - if (NULL != abort_task) \ - GNUNET_SCHEDULER_cancel (abort_task); \ - abort_task = NULL; \ - if (NULL == shutdown_task) \ - shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); \ - return; \ - } \ + if (!(cond)) { \ + GNUNET_break(0); \ + if (NULL != abort_task) \ + GNUNET_SCHEDULER_cancel (abort_task); \ + abort_task = NULL; \ + if (NULL == shutdown_task) \ + shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); \ + return; \ + } \ } while (0) @@ -104,13 +104,13 @@ do_shutdown (void *cls) * @param cls NULL */ static void -do_abort (void *cls) +do_abort(void *cls) { - LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); + LOG(GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); abort_task = NULL; if (NULL != shutdown_task) - GNUNET_SCHEDULER_cancel (shutdown_task); - do_shutdown (cls); + GNUNET_SCHEDULER_cancel(shutdown_task); + do_shutdown(cls); } @@ -124,19 +124,19 @@ do_abort (void *cls) * operation is successfull */ static void -peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op_, - const struct GNUNET_TESTBED_PeerInformation *pinfo, - const char *emsg) +peerinfo_cb(void *cb_cls, struct GNUNET_TESTBED_Operation *op_, + const struct GNUNET_TESTBED_PeerInformation *pinfo, + const char *emsg) { - FAIL_TEST (op == op_); - FAIL_TEST (NULL == cb_cls); - FAIL_TEST (NULL == emsg); - FAIL_TEST (GNUNET_TESTBED_PIT_IDENTITY == pinfo->pit); - FAIL_TEST (NULL != pinfo->result.id); - GNUNET_TESTBED_operation_done (op); + FAIL_TEST(op == op_); + FAIL_TEST(NULL == cb_cls); + FAIL_TEST(NULL == emsg); + FAIL_TEST(GNUNET_TESTBED_PIT_IDENTITY == pinfo->pit); + FAIL_TEST(NULL != pinfo->result.id); + GNUNET_TESTBED_operation_done(op); op = NULL; result = GNUNET_OK; - shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); + shutdown_task = GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); } @@ -149,19 +149,19 @@ peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op_, * operation has executed successfully. */ static void -op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op_, const char *emsg) +op_comp_cb(void *cls, struct GNUNET_TESTBED_Operation *op_, const char *emsg) { - FAIL_TEST (NULL == cls); - FAIL_TEST (op == op_); + FAIL_TEST(NULL == cls); + FAIL_TEST(op == op_); if (NULL != emsg) - { - LOG (GNUNET_ERROR_TYPE_WARNING, "%s\n", emsg); - FAIL_TEST (0); - } - GNUNET_TESTBED_operation_done (op); - op = GNUNET_TESTBED_peer_get_information (peers[0], - GNUNET_TESTBED_PIT_IDENTITY, - &peerinfo_cb, NULL); + { + LOG(GNUNET_ERROR_TYPE_WARNING, "%s\n", emsg); + FAIL_TEST(0); + } + GNUNET_TESTBED_operation_done(op); + op = GNUNET_TESTBED_peer_get_information(peers[0], + GNUNET_TESTBED_PIT_IDENTITY, + &peerinfo_cb, NULL); } @@ -172,18 +172,19 @@ op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op_, const char *emsg) * @param event the controller event */ static void -controller_event_cb (void *cls, - const struct GNUNET_TESTBED_EventInformation *event) +controller_event_cb(void *cls, + const struct GNUNET_TESTBED_EventInformation *event) { switch (event->type) - { - case GNUNET_TESTBED_ET_CONNECT: - FAIL_TEST (event->details.peer_connect.peer1 == peers[0]); - FAIL_TEST (event->details.peer_connect.peer2 == peers[1]); - break; - default: - FAIL_TEST (0); - } + { + case GNUNET_TESTBED_ET_CONNECT: + FAIL_TEST(event->details.peer_connect.peer1 == peers[0]); + FAIL_TEST(event->details.peer_connect.peer2 == peers[1]); + break; + + default: + FAIL_TEST(0); + } } @@ -200,27 +201,27 @@ controller_event_cb (void *cls, * failed */ static void -test_master (void *cls, - struct GNUNET_TESTBED_RunHandle *h, - unsigned int num_peers, - struct GNUNET_TESTBED_Peer **peers_, - unsigned int links_succeeded, - unsigned int links_failed) +test_master(void *cls, + struct GNUNET_TESTBED_RunHandle *h, + unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers_, + unsigned int links_succeeded, + unsigned int links_failed) { unsigned int peer; - FAIL_TEST (NULL == cls); - FAIL_TEST (NUM_PEERS == num_peers); - FAIL_TEST (NULL != peers_); + FAIL_TEST(NULL == cls); + FAIL_TEST(NUM_PEERS == num_peers); + FAIL_TEST(NULL != peers_); for (peer = 0; peer < num_peers; peer++) - FAIL_TEST (NULL != peers_[peer]); + FAIL_TEST(NULL != peers_[peer]); peers = peers_; - op = GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peers[0], - peers[1]); + op = GNUNET_TESTBED_overlay_connect(NULL, &op_comp_cb, NULL, peers[0], + peers[1]); abort_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort, - NULL); + GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort, + NULL); } @@ -228,7 +229,7 @@ test_master (void *cls, * Main function */ int -main (int argc, char **argv) +main(int argc, char **argv) { uint64_t event_mask; @@ -236,10 +237,10 @@ main (int argc, char **argv) event_mask = 0; event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); - (void) GNUNET_TESTBED_test_run ("test_testbed_api_test", - "test_testbed_api.conf", NUM_PEERS, - event_mask, &controller_event_cb, NULL, - &test_master, NULL); + (void)GNUNET_TESTBED_test_run("test_testbed_api_test", + "test_testbed_api.conf", NUM_PEERS, + event_mask, &controller_event_cb, NULL, + &test_master, NULL); if (GNUNET_OK != result) return 1; return 0; diff --git a/src/testbed/test_testbed_api_test_timeout.c b/src/testbed/test_testbed_api_test_timeout.c index 68233e207..c5cfea7c0 100644 --- a/src/testbed/test_testbed_api_test_timeout.c +++ b/src/testbed/test_testbed_api_test_timeout.c @@ -1,22 +1,22 @@ /* - This file is part of GNUnet - Copyright (C) 2008--2013 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 . + This file is part of GNUnet + Copyright (C) 2008--2013 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 src/testbed/test_testbed_api_test.c @@ -34,8 +34,8 @@ /** * Generic logging shortcut */ -#define LOG(kind,...) \ - GNUNET_log (kind, __VA_ARGS__) +#define LOG(kind, ...) \ + GNUNET_log(kind, __VA_ARGS__) /** * Number of peers we want to start @@ -52,11 +52,11 @@ static int result; * shortcut to exit during failure */ #define FAIL_TEST(cond) do { \ - if (!(cond)) { \ - GNUNET_break(0); \ - GNUNET_SCHEDULER_shutdown (); \ - return; \ - } \ + if (!(cond)) { \ + GNUNET_break(0); \ + GNUNET_SCHEDULER_shutdown(); \ + return; \ + } \ } while (0) @@ -67,10 +67,10 @@ static int result; * @param event the controller event */ static void -controller_event_cb (void *cls, - const struct GNUNET_TESTBED_EventInformation *event) +controller_event_cb(void *cls, + const struct GNUNET_TESTBED_EventInformation *event) { - FAIL_TEST (0); + FAIL_TEST(0); } @@ -87,18 +87,18 @@ controller_event_cb (void *cls, * failed */ static void -test_master (void *cls, - struct GNUNET_TESTBED_RunHandle *h, - unsigned int num_peers, - struct GNUNET_TESTBED_Peer **peers_, - unsigned int links_succeeded, - unsigned int links_failed) +test_master(void *cls, + struct GNUNET_TESTBED_RunHandle *h, + unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers_, + unsigned int links_succeeded, + unsigned int links_failed) { - FAIL_TEST (NULL == cls); - FAIL_TEST (0 == num_peers); - FAIL_TEST (NULL == peers_); + FAIL_TEST(NULL == cls); + FAIL_TEST(0 == num_peers); + FAIL_TEST(NULL == peers_); result = GNUNET_OK; - GNUNET_SCHEDULER_shutdown (); + GNUNET_SCHEDULER_shutdown(); } @@ -106,16 +106,16 @@ test_master (void *cls, * Main function */ int -main (int argc, char **argv) +main(int argc, char **argv) { uint64_t event_mask; result = GNUNET_SYSERR; event_mask = 0; - (void) GNUNET_TESTBED_test_run ("test_testbed_api_test", - "test_testbed_api_test_timeout.conf", NUM_PEERS, - event_mask, &controller_event_cb, NULL, - &test_master, NULL); + (void)GNUNET_TESTBED_test_run("test_testbed_api_test", + "test_testbed_api_test_timeout.conf", NUM_PEERS, + event_mask, &controller_event_cb, NULL, + &test_master, NULL); if (GNUNET_OK != result) return 1; return 0; diff --git a/src/testbed/test_testbed_api_testbed_run.c b/src/testbed/test_testbed_api_testbed_run.c index 27f5b13e7..39bc9bfe7 100644 --- a/src/testbed/test_testbed_api_testbed_run.c +++ b/src/testbed/test_testbed_api_testbed_run.c @@ -1,22 +1,22 @@ /* - This file is part of GNUnet - Copyright (C) 2008--2013 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 . + This file is part of GNUnet + Copyright (C) 2008--2013 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/test_testbed_api_testbed_run.c @@ -70,11 +70,11 @@ static int wait_forever; * @param cls NULL */ static void -do_shutdown (void *cls) +do_shutdown(void *cls) { if (NULL != abort_task) - GNUNET_SCHEDULER_cancel (abort_task); - GNUNET_SCHEDULER_shutdown (); /* Stop scheduler to shutdown testbed run */ + GNUNET_SCHEDULER_cancel(abort_task); + GNUNET_SCHEDULER_shutdown(); /* Stop scheduler to shutdown testbed run */ } @@ -84,12 +84,12 @@ do_shutdown (void *cls) * @param cls NULL */ static void -do_abort (void *cls) +do_abort(void *cls) { abort_task = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Test timed out -- Aborting\n"); - GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + "Test timed out -- Aborting\n"); + GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); } @@ -106,26 +106,26 @@ do_abort (void *cls) * failed */ static void -test_master (void *cls, - struct GNUNET_TESTBED_RunHandle *h, - unsigned int num_peers, - struct GNUNET_TESTBED_Peer **peers_, - unsigned int links_succeeded, - unsigned int links_failed) +test_master(void *cls, + struct GNUNET_TESTBED_RunHandle *h, + unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers_, + unsigned int links_succeeded, + unsigned int links_failed) { result = GNUNET_OK; if (GNUNET_YES == wait_forever) - { - if (NULL == abort_task) - return; /* abort already scheduled */ - GNUNET_SCHEDULER_cancel (abort_task); - abort_task = NULL; - GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); - return; - } - GNUNET_assert (NULL != peers[0]); - op = GNUNET_TESTBED_peer_stop (NULL, peers[0], NULL, NULL); - GNUNET_assert (NULL != op); + { + if (NULL == abort_task) + return; /* abort already scheduled */ + GNUNET_SCHEDULER_cancel(abort_task); + abort_task = NULL; + GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); + return; + } + GNUNET_assert(NULL != peers[0]); + op = GNUNET_TESTBED_peer_stop(NULL, peers[0], NULL, NULL); + GNUNET_assert(NULL != op); } @@ -136,26 +136,27 @@ test_master (void *cls, * @param event the controller event */ static void -controller_event_cb (void *cls, - const struct GNUNET_TESTBED_EventInformation *event) +controller_event_cb(void *cls, + const struct GNUNET_TESTBED_EventInformation *event) { - switch (event->type) - { - case GNUNET_TESTBED_ET_PEER_START: - GNUNET_assert (NULL == peers[peer_id]); - GNUNET_assert (NULL != event->details.peer_start.peer); - peers[peer_id++] = event->details.peer_start.peer; - break; - case GNUNET_TESTBED_ET_PEER_STOP: - GNUNET_assert (NULL != op); - GNUNET_TESTBED_operation_done (op); - GNUNET_assert (peers[0] == event->details.peer_stop.peer); - GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); - break; - default: - GNUNET_assert (0); - } + { + case GNUNET_TESTBED_ET_PEER_START: + GNUNET_assert(NULL == peers[peer_id]); + GNUNET_assert(NULL != event->details.peer_start.peer); + peers[peer_id++] = event->details.peer_start.peer; + break; + + case GNUNET_TESTBED_ET_PEER_STOP: + GNUNET_assert(NULL != op); + GNUNET_TESTBED_operation_done(op); + GNUNET_assert(peers[0] == event->details.peer_stop.peer); + GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); + break; + + default: + GNUNET_assert(0); + } } @@ -168,24 +169,24 @@ controller_event_cb (void *cls, * @param cfg the configuration file handle */ static void -run (void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *config) +run(void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *config) { uint64_t event_mask; event_mask = 0; event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP); - GNUNET_TESTBED_run (NULL, config, NUM_PEERS, event_mask, - &controller_event_cb, NULL, - &test_master, NULL); + GNUNET_TESTBED_run(NULL, config, NUM_PEERS, event_mask, + &controller_event_cb, NULL, + &test_master, NULL); abort_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_SECONDS, 300), - &do_abort, - NULL); + GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, 300), + &do_abort, + NULL); } @@ -193,7 +194,7 @@ run (void *cls, * Main function */ int -main (int argc, char **argv) +main(int argc, char **argv) { char *argv2[] = { "test_testbed_api_testbed_run", @@ -207,42 +208,42 @@ main (int argc, char **argv) char *config_filename; int ret; - if (NULL == (testname = strrchr (argv[0], (int) '_'))) - { - GNUNET_break (0); - return 1; - } + if (NULL == (testname = strrchr(argv[0], (int)'_'))) + { + GNUNET_break(0); + return 1; + } testname++; - testname = GNUNET_strdup (testname); + testname = GNUNET_strdup(testname); #ifdef MINGW { char *period; /* check and remove .exe extension */ - period = strrchr (testname, (int) '.'); + period = strrchr(testname, (int)'.'); if (NULL != period) *period = '\0'; else - GNUNET_break (0); /* Windows with no .exe? */ + GNUNET_break(0); /* Windows with no .exe? */ } #endif - if (0 == strcmp ("waitforever", testname)) + if (0 == strcmp("waitforever", testname)) wait_forever = GNUNET_YES; - if ( (GNUNET_YES != wait_forever) && (0 != strcmp ("run", testname)) ) - { - GNUNET_asprintf (&config_filename, "test_testbed_api_testbed_run_%s.conf", - testname); - } + if ((GNUNET_YES != wait_forever) && (0 != strcmp("run", testname))) + { + GNUNET_asprintf(&config_filename, "test_testbed_api_testbed_run_%s.conf", + testname); + } else - config_filename = GNUNET_strdup ("test_testbed_api.conf"); - GNUNET_free (testname); + config_filename = GNUNET_strdup("test_testbed_api.conf"); + GNUNET_free(testname); argv2[2] = config_filename; result = GNUNET_SYSERR; ret = - GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, - "test_testbed_api_testbed_run", "nohelp", options, - &run, NULL); - GNUNET_free (config_filename); + GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, argv2, + "test_testbed_api_testbed_run", "nohelp", options, + &run, NULL); + GNUNET_free(config_filename); if ((GNUNET_OK != ret) || (GNUNET_OK != result)) return 1; return 0; diff --git a/src/testbed/test_testbed_api_topology.c b/src/testbed/test_testbed_api_topology.c index d1b8da31a..c6e25c656 100644 --- a/src/testbed/test_testbed_api_topology.c +++ b/src/testbed/test_testbed_api_topology.c @@ -1,22 +1,22 @@ /* - This file is part of GNUnet - Copyright (C) 2008--2013 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 . + This file is part of GNUnet + Copyright (C) 2008--2013 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 src/testbed/test_testbed_api_topology.c @@ -65,15 +65,15 @@ static unsigned int overlay_connects; * @param cls NULL */ static void -do_shutdown (void *cls) +do_shutdown(void *cls) { shutdown_task = NULL; if (NULL != op) - { - GNUNET_TESTBED_operation_done (op); - op = NULL; - } - GNUNET_SCHEDULER_shutdown (); + { + GNUNET_TESTBED_operation_done(op); + op = NULL; + } + GNUNET_SCHEDULER_shutdown(); } /** @@ -83,34 +83,36 @@ do_shutdown (void *cls) * @param event the controller event */ static void -controller_event_cb (void *cls, - const struct GNUNET_TESTBED_EventInformation *event) +controller_event_cb(void *cls, + const struct GNUNET_TESTBED_EventInformation *event) { switch (event->type) - { - case GNUNET_TESTBED_ET_CONNECT: - overlay_connects++; - if ((NUM_PEERS) == overlay_connects) { - result = GNUNET_OK; - GNUNET_SCHEDULER_cancel (shutdown_task); - shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); + case GNUNET_TESTBED_ET_CONNECT: + overlay_connects++; + if ((NUM_PEERS) == overlay_connects) + { + result = GNUNET_OK; + GNUNET_SCHEDULER_cancel(shutdown_task); + shutdown_task = GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); + } + break; + + case GNUNET_TESTBED_ET_OPERATION_FINISHED: + GNUNET_assert(NULL != event->details.operation_finished.emsg); + break; + + default: + GNUNET_break(0); + if ((GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type) && + (NULL != event->details.operation_finished.emsg)) + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "An operation failed with error: %s\n", + event->details.operation_finished.emsg); + result = GNUNET_SYSERR; + GNUNET_SCHEDULER_cancel(shutdown_task); + shutdown_task = GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); } - break; - case GNUNET_TESTBED_ET_OPERATION_FINISHED: - GNUNET_assert (NULL != event->details.operation_finished.emsg); - break; - default: - GNUNET_break (0); - if ((GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type) && - (NULL != event->details.operation_finished.emsg)) - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "An operation failed with error: %s\n", - event->details.operation_finished.emsg); - result = GNUNET_SYSERR; - GNUNET_SCHEDULER_cancel (shutdown_task); - shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); - } } @@ -127,37 +129,37 @@ controller_event_cb (void *cls, * failed */ static void -test_master (void *cls, - struct GNUNET_TESTBED_RunHandle *h, - unsigned int num_peers, - struct GNUNET_TESTBED_Peer **peers_, - unsigned int links_succeeded, - unsigned int links_failed) +test_master(void *cls, + struct GNUNET_TESTBED_RunHandle *h, + unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers_, + unsigned int links_succeeded, + unsigned int links_failed) { unsigned int peer; - GNUNET_assert (NULL == cls); + GNUNET_assert(NULL == cls); if (NULL == peers_) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failing test due to timeout\n"); - return; - } - GNUNET_assert (NUM_PEERS == num_peers); + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failing test due to timeout\n"); + return; + } + GNUNET_assert(NUM_PEERS == num_peers); for (peer = 0; peer < num_peers; peer++) - GNUNET_assert (NULL != peers_[peer]); + GNUNET_assert(NULL != peers_[peer]); peers = peers_; overlay_connects = 0; - op = GNUNET_TESTBED_overlay_configure_topology (NULL, NUM_PEERS, peers, NULL, - NULL, - NULL, - GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI, - NUM_PEERS, - GNUNET_TESTBED_TOPOLOGY_OPTION_END); - GNUNET_assert (NULL != op); + op = GNUNET_TESTBED_overlay_configure_topology(NULL, NUM_PEERS, peers, NULL, + NULL, + NULL, + GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI, + NUM_PEERS, + GNUNET_TESTBED_TOPOLOGY_OPTION_END); + GNUNET_assert(NULL != op); shutdown_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_SECONDS, 300), - do_shutdown, NULL); + GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, 300), + do_shutdown, NULL); } @@ -165,7 +167,7 @@ test_master (void *cls, * Main function */ int -main (int argc, char **argv) +main(int argc, char **argv) { uint64_t event_mask; @@ -173,10 +175,10 @@ main (int argc, char **argv) event_mask = 0; event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); - (void) GNUNET_TESTBED_test_run ("test_testbed_api_test", - "test_testbed_api.conf", NUM_PEERS, - event_mask, &controller_event_cb, NULL, - &test_master, NULL); + (void)GNUNET_TESTBED_test_run("test_testbed_api_test", + "test_testbed_api.conf", NUM_PEERS, + event_mask, &controller_event_cb, NULL, + &test_master, NULL); if (GNUNET_OK != result) return 1; return 0; diff --git a/src/testbed/test_testbed_api_topology_clique.c b/src/testbed/test_testbed_api_topology_clique.c index 4cc34dfaf..866ec83c5 100644 --- a/src/testbed/test_testbed_api_topology_clique.c +++ b/src/testbed/test_testbed_api_topology_clique.c @@ -1,22 +1,22 @@ /* - This file is part of GNUnet - Copyright (C) 2008--2013 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 . + This file is part of GNUnet + Copyright (C) 2008--2013 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 src/testbed/test_testbed_api_topology.c @@ -65,15 +65,15 @@ static unsigned int overlay_connects; * @param cls NULL */ static void -do_shutdown (void *cls) +do_shutdown(void *cls) { shutdown_task = NULL; if (NULL != op) - { - GNUNET_TESTBED_operation_done (op); - op = NULL; - } - GNUNET_SCHEDULER_shutdown (); + { + GNUNET_TESTBED_operation_done(op); + op = NULL; + } + GNUNET_SCHEDULER_shutdown(); } /** @@ -83,29 +83,31 @@ do_shutdown (void *cls) * @param event the controller event */ static void -controller_event_cb (void *cls, - const struct GNUNET_TESTBED_EventInformation *event) +controller_event_cb(void *cls, + const struct GNUNET_TESTBED_EventInformation *event) { switch (event->type) - { - case GNUNET_TESTBED_ET_CONNECT: - overlay_connects++; - if ((NUM_PEERS * (NUM_PEERS - 1)) == overlay_connects) { - result = GNUNET_OK; - GNUNET_SCHEDULER_cancel (shutdown_task); - shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); + case GNUNET_TESTBED_ET_CONNECT: + overlay_connects++; + if ((NUM_PEERS * (NUM_PEERS - 1)) == overlay_connects) + { + result = GNUNET_OK; + GNUNET_SCHEDULER_cancel(shutdown_task); + shutdown_task = GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); + } + break; + + case GNUNET_TESTBED_ET_OPERATION_FINISHED: + GNUNET_assert(NULL != event->details.operation_finished.emsg); + break; + + default: + GNUNET_break(0); + result = GNUNET_SYSERR; + GNUNET_SCHEDULER_cancel(shutdown_task); + shutdown_task = GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); } - break; - case GNUNET_TESTBED_ET_OPERATION_FINISHED: - GNUNET_assert (NULL != event->details.operation_finished.emsg); - break; - default: - GNUNET_break (0); - result = GNUNET_SYSERR; - GNUNET_SCHEDULER_cancel (shutdown_task); - shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); - } } @@ -122,38 +124,38 @@ controller_event_cb (void *cls, * failed */ static void -test_master (void *cls, - struct GNUNET_TESTBED_RunHandle *h, - unsigned int num_peers, - struct GNUNET_TESTBED_Peer **peers_, - unsigned int links_succeeded, - unsigned int links_failed) +test_master(void *cls, + struct GNUNET_TESTBED_RunHandle *h, + unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers_, + unsigned int links_succeeded, + unsigned int links_failed) { unsigned int peer; - GNUNET_assert (NULL == cls); + GNUNET_assert(NULL == cls); if (NULL == peers_) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failing test due to timeout\n"); - return; - } - GNUNET_assert (NUM_PEERS == num_peers); + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failing test due to timeout\n"); + return; + } + GNUNET_assert(NUM_PEERS == num_peers); for (peer = 0; peer < num_peers; peer++) - GNUNET_assert (NULL != peers_[peer]); + GNUNET_assert(NULL != peers_[peer]); peers = peers_; overlay_connects = 0; - op = GNUNET_TESTBED_overlay_configure_topology (NULL, NUM_PEERS, peers, NULL, - NULL, - NULL, - GNUNET_TESTBED_TOPOLOGY_CLIQUE, - /* GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI, */ - /* NUM_PEERS, */ - GNUNET_TESTBED_TOPOLOGY_OPTION_END); - GNUNET_assert (NULL != op); + op = GNUNET_TESTBED_overlay_configure_topology(NULL, NUM_PEERS, peers, NULL, + NULL, + NULL, + GNUNET_TESTBED_TOPOLOGY_CLIQUE, + /* GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI, */ + /* NUM_PEERS, */ + GNUNET_TESTBED_TOPOLOGY_OPTION_END); + GNUNET_assert(NULL != op); shutdown_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_SECONDS, 300), - do_shutdown, NULL); + GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, 300), + do_shutdown, NULL); } @@ -161,7 +163,7 @@ test_master (void *cls, * Main function */ int -main (int argc, char **argv) +main(int argc, char **argv) { uint64_t event_mask; @@ -169,10 +171,10 @@ main (int argc, char **argv) event_mask = 0; event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); - (void) GNUNET_TESTBED_test_run ("test_testbed_api_test", - "test_testbed_api.conf", NUM_PEERS, - event_mask, &controller_event_cb, NULL, - &test_master, NULL); + (void)GNUNET_TESTBED_test_run("test_testbed_api_test", + "test_testbed_api.conf", NUM_PEERS, + event_mask, &controller_event_cb, NULL, + &test_master, NULL); if (GNUNET_OK != result) return 1; return 0; diff --git a/src/testbed/test_testbed_underlay.c b/src/testbed/test_testbed_underlay.c index 41aa43ce5..fad4282d7 100644 --- a/src/testbed/test_testbed_underlay.c +++ b/src/testbed/test_testbed_underlay.c @@ -11,7 +11,7 @@ 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 . @@ -49,10 +49,10 @@ static struct GNUNET_TESTBED_Operation *op; * @param tc scheduler task context */ static void -do_shutdown (void *cls) +do_shutdown(void *cls) { if (NULL != op) - GNUNET_TESTBED_operation_done (op); + GNUNET_TESTBED_operation_done(op); op = NULL; } @@ -66,21 +66,21 @@ do_shutdown (void *cls) * operation has executed successfully. */ static void -overlay_connect_status (void *cls, - struct GNUNET_TESTBED_Operation *op_, - const char *emsg) +overlay_connect_status(void *cls, + struct GNUNET_TESTBED_Operation *op_, + const char *emsg) { - GNUNET_assert (op_ == op); - GNUNET_TESTBED_operation_done (op); + GNUNET_assert(op_ == op); + GNUNET_TESTBED_operation_done(op); op = NULL; if (NULL == emsg) - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Peers 0 and 2 should not get connected\n"); + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Peers 0 and 2 should not get connected\n"); else - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers 0 and 2 not connected: %s. Success!\n", emsg); - result = GNUNET_OK; - } - GNUNET_SCHEDULER_shutdown (); + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Peers 0 and 2 not connected: %s. Success!\n", emsg); + result = GNUNET_OK; + } + GNUNET_SCHEDULER_shutdown(); } @@ -98,29 +98,29 @@ overlay_connect_status (void *cls, * failed */ static void -test_master (void *cls, - struct GNUNET_TESTBED_RunHandle *h, - unsigned int num_peers, - struct GNUNET_TESTBED_Peer **peers_, - unsigned int links_succeeded, - unsigned int links_failed) +test_master(void *cls, + struct GNUNET_TESTBED_RunHandle *h, + unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers_, + unsigned int links_succeeded, + unsigned int links_failed) { - GNUNET_assert (NULL == cls); + GNUNET_assert(NULL == cls); if (NULL == peers_) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failing test due to timeout\n"); - GNUNET_SCHEDULER_shutdown (); - return; - } - GNUNET_assert (NUM_PEERS == num_peers); - op = GNUNET_TESTBED_overlay_connect (NULL, - &overlay_connect_status, - NULL, - peers_[0], - peers_[2]); - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, - 60), - &do_shutdown, NULL); + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failing test due to timeout\n"); + GNUNET_SCHEDULER_shutdown(); + return; + } + GNUNET_assert(NUM_PEERS == num_peers); + op = GNUNET_TESTBED_overlay_connect(NULL, + &overlay_connect_status, + NULL, + peers_[0], + peers_[2]); + GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, + 60), + &do_shutdown, NULL); } @@ -136,7 +136,7 @@ test_master (void *cls, * Main function */ int -main (int argc, char **argv) +main(int argc, char **argv) { struct GNUNET_CONFIGURATION_Handle *cfg; char pwd[PATH_MAX]; @@ -145,26 +145,26 @@ main (int argc, char **argv) result = GNUNET_SYSERR; event_mask = 0; - cfg = GNUNET_CONFIGURATION_create (); - GNUNET_assert (GNUNET_YES == - GNUNET_CONFIGURATION_parse (cfg, - "test_testbed_underlay.conf.in")); - if (NULL == getcwd (pwd, PATH_MAX)) + cfg = GNUNET_CONFIGURATION_create(); + GNUNET_assert(GNUNET_YES == + GNUNET_CONFIGURATION_parse(cfg, + "test_testbed_underlay.conf.in")); + if (NULL == getcwd(pwd, PATH_MAX)) return 1; - GNUNET_assert (0 < GNUNET_asprintf (&dbfile, "%s/%s", pwd, - "test-underlay.sqlite")); - GNUNET_CONFIGURATION_set_value_string (cfg, "TESTBED-UNDERLAY","DBFILE", dbfile); - GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_write - (cfg, "test_testbed_underlay.conf")); - GNUNET_CONFIGURATION_destroy (cfg); + GNUNET_assert(0 < GNUNET_asprintf(&dbfile, "%s/%s", pwd, + "test-underlay.sqlite")); + GNUNET_CONFIGURATION_set_value_string(cfg, "TESTBED-UNDERLAY", "DBFILE", dbfile); + GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_write + (cfg, "test_testbed_underlay.conf")); + GNUNET_CONFIGURATION_destroy(cfg); cfg = NULL; - GNUNET_free (dbfile); + GNUNET_free(dbfile); dbfile = NULL; - (void) GNUNET_TESTBED_test_run ("test_testbed_underlay", - "test_testbed_underlay.conf", NUM_PEERS, - event_mask, NULL, NULL, - &test_master, NULL); - (void) unlink ("test_testbed_underlay.conf"); + (void)GNUNET_TESTBED_test_run("test_testbed_underlay", + "test_testbed_underlay.conf", NUM_PEERS, + event_mask, NULL, NULL, + &test_master, NULL); + (void)unlink("test_testbed_underlay.conf"); if (GNUNET_OK != result) return 1; return 0; diff --git a/src/testbed/testbed.h b/src/testbed/testbed.h index b659a3408..8ab957b88 100644 --- a/src/testbed/testbed.h +++ b/src/testbed/testbed.h @@ -11,7 +11,7 @@ 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 . @@ -33,9 +33,7 @@ GNUNET_NETWORK_STRUCT_BEGIN /** * Initial message from a client to a testing control service. */ -struct GNUNET_TESTBED_InitMessage -{ - +struct GNUNET_TESTBED_InitMessage { /** * Type is #GNUNET_MESSAGE_TYPE_TESTBED_INIT */ @@ -62,9 +60,7 @@ struct GNUNET_TESTBED_InitMessage /** * Notify the service about a host that we intend to use. */ -struct GNUNET_TESTBED_AddHostMessage -{ - +struct GNUNET_TESTBED_AddHostMessage { /** * Type is #GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST */ @@ -105,7 +101,6 @@ struct GNUNET_TESTBED_AddHostMessage /* followed by gzip compressed configuration to start or connect to a controller on this host. While starting the controller this configuration is used as a template */ - }; @@ -114,9 +109,7 @@ struct GNUNET_TESTBED_AddHostMessage * worked (or failed). * FIXME: Where is this required? */ -struct GNUNET_TESTBED_HostConfirmedMessage -{ - +struct GNUNET_TESTBED_HostConfirmedMessage { /** * Type is GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS */ @@ -129,7 +122,6 @@ struct GNUNET_TESTBED_HostConfirmedMessage /* followed by the 0-terminated error message (on failure) * (typical errors include host-id already in use) */ - }; @@ -138,9 +130,7 @@ struct GNUNET_TESTBED_HostConfirmedMessage * requests for a particular client to a particular * sub-controller. */ -struct GNUNET_TESTBED_ControllerLinkRequest -{ - +struct GNUNET_TESTBED_ControllerLinkRequest { /** * Type is #GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS */ @@ -166,16 +156,13 @@ struct GNUNET_TESTBED_ControllerLinkRequest * the slave host (and thus responsible for starting it?). 0 if not */ uint8_t is_subordinate; - }; /** * Response message for ControllerLinkRequest message */ -struct GNUNET_TESTBED_ControllerLinkResponse -{ - +struct GNUNET_TESTBED_ControllerLinkResponse { /** * Type is #GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT */ @@ -202,7 +189,6 @@ struct GNUNET_TESTBED_ControllerLinkResponse * running at the delegate host */ /* In case of failure, here comes the error message (without \0 termination)*/ - }; @@ -210,9 +196,7 @@ struct GNUNET_TESTBED_ControllerLinkResponse * Message sent from client to testing service to * create (configure, but not start) a peer. */ -struct GNUNET_TESTBED_PeerCreateMessage -{ - +struct GNUNET_TESTBED_PeerCreateMessage { /** * Type is #GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER */ @@ -239,8 +223,7 @@ struct GNUNET_TESTBED_PeerCreateMessage uint16_t config_size GNUNET_PACKED; /* followed by serialized peer configuration; - * gzip'ed configuration file in INI format */ - + * gzip'ed configuration file in INI format */ }; @@ -248,9 +231,7 @@ struct GNUNET_TESTBED_PeerCreateMessage * Message sent from client to testing service to * reconfigure a (stopped) a peer. */ -struct GNUNET_TESTBED_PeerReconfigureMessage -{ - +struct GNUNET_TESTBED_PeerReconfigureMessage { /** * Type is #GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER */ @@ -272,8 +253,7 @@ struct GNUNET_TESTBED_PeerReconfigureMessage uint16_t config_size GNUNET_PACKED; /* followed by serialized peer configuration; - * gzip'ed configuration file in INI format */ - + * gzip'ed configuration file in INI format */ }; @@ -281,9 +261,7 @@ struct GNUNET_TESTBED_PeerReconfigureMessage * Message sent from client to testing service to * start a peer. */ -struct GNUNET_TESTBED_PeerStartMessage -{ - +struct GNUNET_TESTBED_PeerStartMessage { /** * Type is #GNUNET_MESSAGE_TYPE_TESTBED_START_PEER */ @@ -298,7 +276,6 @@ struct GNUNET_TESTBED_PeerStartMessage * Operation ID that is used to identify this operation. */ uint64_t operation_id GNUNET_PACKED; - }; @@ -306,9 +283,7 @@ struct GNUNET_TESTBED_PeerStartMessage * Message sent from client to testing service to * stop a peer. */ -struct GNUNET_TESTBED_PeerStopMessage -{ - +struct GNUNET_TESTBED_PeerStopMessage { /** * Type is #GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER */ @@ -323,7 +298,6 @@ struct GNUNET_TESTBED_PeerStopMessage * Operation ID that is used to identify this operation. */ uint64_t operation_id GNUNET_PACKED; - }; @@ -331,9 +305,7 @@ struct GNUNET_TESTBED_PeerStopMessage * Message sent from client to testing service to * destroy a (stopped) peer. */ -struct GNUNET_TESTBED_PeerDestroyMessage -{ - +struct GNUNET_TESTBED_PeerDestroyMessage { /** * Type is #GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER */ @@ -348,7 +320,6 @@ struct GNUNET_TESTBED_PeerDestroyMessage * Operation ID that is used to identify this operation. */ uint64_t operation_id GNUNET_PACKED; - }; @@ -356,9 +327,7 @@ struct GNUNET_TESTBED_PeerDestroyMessage * Message sent from client to testing service to * (re)configure a "physical" link between two peers. */ -struct GNUNET_TESTBED_ConfigureUnderlayLinkMessage -{ - +struct GNUNET_TESTBED_ConfigureUnderlayLinkMessage { /** * Type is #GNUNET_MESSAGE_TYPE_TESTBED_CONFIGURE_UNDERLAY_LINK */ @@ -385,7 +354,6 @@ struct GNUNET_TESTBED_ConfigureUnderlayLinkMessage uint64_t operation_id GNUNET_PACKED; /* followed by option-dependent variable-size values */ - }; @@ -393,9 +361,7 @@ struct GNUNET_TESTBED_ConfigureUnderlayLinkMessage * Message sent from client to testing service to * connect two peers. */ -struct GNUNET_TESTBED_OverlayConnectMessage -{ - +struct GNUNET_TESTBED_OverlayConnectMessage { /** * Type is #GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT */ @@ -420,7 +386,6 @@ struct GNUNET_TESTBED_OverlayConnectMessage * The ID of the host which runs peer2 */ uint32_t peer2_host_id GNUNET_PACKED; - }; @@ -428,8 +393,7 @@ struct GNUNET_TESTBED_OverlayConnectMessage * Message sent from host controller of a peer(A) to the host controller of * another peer(B) to request B to connect to A */ -struct GNUNET_TESTBED_RemoteOverlayConnectMessage -{ +struct GNUNET_TESTBED_RemoteOverlayConnectMessage { /** * Type is #GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT */ @@ -456,16 +420,13 @@ struct GNUNET_TESTBED_RemoteOverlayConnectMessage struct GNUNET_MessageHeader hello[0]; // FIXME: we usually do not use this gcc-hack as some // compilers / tools really get messed up by it... - }; /** * Event notification from a controller to a client. */ -struct GNUNET_TESTBED_PeerEventMessage -{ - +struct GNUNET_TESTBED_PeerEventMessage { /** * Type is #GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT */ @@ -491,16 +452,13 @@ struct GNUNET_TESTBED_PeerEventMessage * Operation ID that is used to identify this operation. */ uint64_t operation_id GNUNET_PACKED; - }; /** * Event notification from a controller to a client. */ -struct GNUNET_TESTBED_ConnectionEventMessage -{ - +struct GNUNET_TESTBED_ConnectionEventMessage { /** * Type is #GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT */ @@ -526,16 +484,13 @@ struct GNUNET_TESTBED_ConnectionEventMessage * Operation ID that is used to identify this operation. */ uint64_t operation_id GNUNET_PACKED; - }; /** * Event notification from a controller to a client. */ -struct GNUNET_TESTBED_OperationFailureEventMessage -{ - +struct GNUNET_TESTBED_OperationFailureEventMessage { /** * Type is #GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT */ @@ -553,16 +508,13 @@ struct GNUNET_TESTBED_OperationFailureEventMessage uint64_t operation_id GNUNET_PACKED; /* followed by 0-terminated error message */ - }; /** * Event notification from a controller to a client. */ -struct GNUNET_TESTBED_PeerCreateSuccessEventMessage -{ - +struct GNUNET_TESTBED_PeerCreateSuccessEventMessage { /** * Type is #GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS */ @@ -577,7 +529,6 @@ struct GNUNET_TESTBED_PeerCreateSuccessEventMessage * Operation ID of the operation that created this event. */ uint64_t operation_id GNUNET_PACKED; - }; @@ -586,9 +537,7 @@ struct GNUNET_TESTBED_PeerCreateSuccessEventMessage * a generic operational success where the operation does * not return any data. */ -struct GNUNET_TESTBED_GenericOperationSuccessEventMessage -{ - +struct GNUNET_TESTBED_GenericOperationSuccessEventMessage { /** * Type is #GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS */ @@ -604,7 +553,6 @@ struct GNUNET_TESTBED_GenericOperationSuccessEventMessage * Operation ID of the operation that created this event. */ uint64_t operation_id GNUNET_PACKED; - }; @@ -612,9 +560,7 @@ struct GNUNET_TESTBED_GenericOperationSuccessEventMessage * Message sent from client to testing service to * obtain the configuration of a peer. */ -struct GNUNET_TESTBED_PeerGetConfigurationMessage -{ - +struct GNUNET_TESTBED_PeerGetConfigurationMessage { /** * Type is #GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION */ @@ -629,16 +575,13 @@ struct GNUNET_TESTBED_PeerGetConfigurationMessage * Operation ID that is used to identify this operation. */ uint64_t operation_id GNUNET_PACKED; - }; /** * Peer configuration and identity reply from controller to a client. */ -struct GNUNET_TESTBED_PeerConfigurationInformationMessage -{ - +struct GNUNET_TESTBED_PeerConfigurationInformationMessage { /** * Type is #GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION */ @@ -665,15 +608,13 @@ struct GNUNET_TESTBED_PeerConfigurationInformationMessage uint16_t config_size GNUNET_PACKED; /* followed by gzip-compressed configuration of the peer */ - }; /** * Message to request configuration of a slave controller */ -struct GNUNET_TESTBED_SlaveGetConfigurationMessage -{ +struct GNUNET_TESTBED_SlaveGetConfigurationMessage { /** * Type is #GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION */ @@ -688,15 +629,13 @@ struct GNUNET_TESTBED_SlaveGetConfigurationMessage * Operation ID */ uint64_t operation_id GNUNET_PACKED; - }; /** * Reply to #GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION message */ -struct GNUNET_TESTBED_SlaveConfiguration -{ +struct GNUNET_TESTBED_SlaveConfiguration { /** * Type is #GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION */ @@ -718,15 +657,13 @@ struct GNUNET_TESTBED_SlaveConfiguration uint16_t config_size GNUNET_PACKED; /* followed by gzip-compressed configuration of the peer */ - }; /** * Shutdown peers message */ -struct GNUNET_TESTBED_ShutdownPeersMessage -{ +struct GNUNET_TESTBED_ShutdownPeersMessage { /** * Type is #GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS */ @@ -742,8 +679,7 @@ struct GNUNET_TESTBED_ShutdownPeersMessage /** * Message to start/stop services of a peer */ -struct GNUNET_TESTBED_ManagePeerServiceMessage -{ +struct GNUNET_TESTBED_ManagePeerServiceMessage { /** * Type is #GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS */ @@ -774,8 +710,7 @@ struct GNUNET_TESTBED_ManagePeerServiceMessage * Message to send underlay link model of a peer. This message will be * forwarded to the controller running the peer. */ -struct GNUNET_TESTBED_UnderlayLinkModelMsg -{ +struct GNUNET_TESTBED_UnderlayLinkModelMsg { /** * Type is #GNUNET_MESSAGE_TYPE_UNDERLAYLINKMODELMSG */ @@ -801,7 +736,6 @@ struct GNUNET_TESTBED_UnderlayLinkModelMsg * sequence of four integers of type uint32_t: peer_id, latency, loss and * bandwidth. */ - }; @@ -820,8 +754,7 @@ struct GNUNET_TESTBED_UnderlayLinkModelMsg /** * Message to initialise a barrier */ -struct GNUNET_TESTBED_BarrierInit -{ +struct GNUNET_TESTBED_BarrierInit { /** * Type is #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT */ @@ -842,8 +775,7 @@ struct GNUNET_TESTBED_BarrierInit /** * Message to cancel a barrier */ -struct GNUNET_TESTBED_BarrierCancel -{ +struct GNUNET_TESTBED_BarrierCancel { /** * Type is #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL */ @@ -859,8 +791,7 @@ struct GNUNET_TESTBED_BarrierCancel /** * Message for signalling status changes of a barrier */ -struct GNUNET_TESTBED_BarrierStatusMsg -{ +struct GNUNET_TESTBED_BarrierStatusMsg { /** * Type is #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS */ @@ -888,8 +819,7 @@ struct GNUNET_TESTBED_BarrierStatusMsg * Message sent from peers to the testbed-barrier service to indicate that they * have reached a barrier and are waiting for it to be crossed */ -struct GNUNET_TESTBED_BarrierWait -{ +struct GNUNET_TESTBED_BarrierWait { /** * Type is #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT */ diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index 7df5f1270..8ca96dcbe 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c @@ -44,32 +44,30 @@ /** * Generic logging shorthand */ -#define LOG(kind, ...) GNUNET_log_from (kind, "testbed-api", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from(kind, "testbed-api", __VA_ARGS__) /** * Debug logging */ -#define LOG_DEBUG(...) LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) +#define LOG_DEBUG(...) LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) /** * Relative time seconds shorthand */ #define TIME_REL_SECS(sec) \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec) + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, sec) /** * Default server message sending retry timeout */ -#define TIMEOUT_REL TIME_REL_SECS (1) +#define TIMEOUT_REL TIME_REL_SECS(1) /** * Context data for forwarded Operation */ -struct ForwardedOperationData -{ - +struct ForwardedOperationData { /** * The callback to call when reply is available */ @@ -85,8 +83,7 @@ struct ForwardedOperationData /** * Context data for get slave config operations */ -struct GetSlaveConfigData -{ +struct GetSlaveConfigData { /** * The id of the slave controller */ @@ -97,8 +94,7 @@ struct GetSlaveConfigData /** * Context data for controller link operations */ -struct ControllerLinkData -{ +struct ControllerLinkData { /** * The controller link message */ @@ -114,8 +110,7 @@ struct ControllerLinkData /** * Date context for OP_SHUTDOWN_PEERS operations */ -struct ShutdownPeersData -{ +struct ShutdownPeersData { /** * The operation completion callback to call */ @@ -131,8 +126,7 @@ struct ShutdownPeersData /** * An entry in the stack for keeping operations which are about to expire */ -struct ExpireOperationEntry -{ +struct ExpireOperationEntry { /** * DLL head; new entries are to be inserted here */ @@ -167,13 +161,13 @@ static struct ExpireOperationEntry *exop_tail; * @param op the operation to insert */ static void -exop_insert (struct GNUNET_TESTBED_Operation *op) +exop_insert(struct GNUNET_TESTBED_Operation *op) { struct ExpireOperationEntry *entry; - entry = GNUNET_new (struct ExpireOperationEntry); + entry = GNUNET_new(struct ExpireOperationEntry); entry->op = op; - GNUNET_CONTAINER_DLL_insert_tail (exop_head, exop_tail, entry); + GNUNET_CONTAINER_DLL_insert_tail(exop_head, exop_tail, entry); } @@ -189,7 +183,7 @@ exop_insert (struct GNUNET_TESTBED_Operation *op) * paramenter will return GNUNET_NO) */ static int -exop_check (const struct GNUNET_TESTBED_Operation *const op) +exop_check(const struct GNUNET_TESTBED_Operation *const op) { struct ExpireOperationEntry *entry; struct ExpireOperationEntry *entry2; @@ -198,24 +192,24 @@ exop_check (const struct GNUNET_TESTBED_Operation *const op) found = GNUNET_NO; entry = exop_head; while (NULL != entry) - { - if (op == entry->op) { - found = GNUNET_YES; - break; + if (op == entry->op) + { + found = GNUNET_YES; + break; + } + entry = entry->next; } - entry = entry->next; - } if (GNUNET_NO == found) return GNUNET_NO; /* Truncate the tail */ while (NULL != entry) - { - entry2 = entry->next; - GNUNET_CONTAINER_DLL_remove (exop_head, exop_tail, entry); - GNUNET_free (entry); - entry = entry2; - } + { + entry2 = entry->next; + GNUNET_CONTAINER_DLL_remove(exop_head, exop_tail, entry); + GNUNET_free(entry); + entry = entry2; + } return GNUNET_YES; } @@ -223,8 +217,7 @@ exop_check (const struct GNUNET_TESTBED_Operation *const op) /** * Context information to be used while searching for operation contexts */ -struct SearchContext -{ +struct SearchContext { /** * The result of the search */ @@ -247,13 +240,13 @@ struct SearchContext * #GNUNET_NO if not. */ static int -opc_search_iterator (void *cls, uint32_t key, void *value) +opc_search_iterator(void *cls, uint32_t key, void *value) { struct SearchContext *sc = cls; struct OperationContext *opc = value; - GNUNET_assert (NULL != opc); - GNUNET_assert (NULL == sc->opc); + GNUNET_assert(NULL != opc); + GNUNET_assert(NULL == sc->opc); if (opc->id != sc->id) return GNUNET_YES; sc->opc = opc; @@ -270,18 +263,18 @@ opc_search_iterator (void *cls, uint32_t key, void *value) * @return the matching operation context; NULL if no match found */ static struct OperationContext * -find_opc (const struct GNUNET_TESTBED_Controller *c, const uint64_t id) +find_opc(const struct GNUNET_TESTBED_Controller *c, const uint64_t id) { struct SearchContext sc; sc.id = id; sc.opc = NULL; - GNUNET_assert (NULL != c->opc_map); + GNUNET_assert(NULL != c->opc_map); if (GNUNET_SYSERR != - GNUNET_CONTAINER_multihashmap32_get_multiple (c->opc_map, - (uint32_t) id, - &opc_search_iterator, - &sc)) + GNUNET_CONTAINER_multihashmap32_get_multiple(c->opc_map, + (uint32_t)id, + &opc_search_iterator, + &sc)) return NULL; return sc.opc; } @@ -296,16 +289,16 @@ find_opc (const struct GNUNET_TESTBED_Controller *c, const uint64_t id) * @param opc the operation context to be inserted */ void -GNUNET_TESTBED_insert_opc_ (struct GNUNET_TESTBED_Controller *c, - struct OperationContext *opc) +GNUNET_TESTBED_insert_opc_(struct GNUNET_TESTBED_Controller *c, + struct OperationContext *opc) { if (NULL == c->opc_map) - c->opc_map = GNUNET_CONTAINER_multihashmap32_create (256); - GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap32_put ( - c->opc_map, - (uint32_t) opc->id, - opc, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); + c->opc_map = GNUNET_CONTAINER_multihashmap32_create(256); + GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multihashmap32_put( + c->opc_map, + (uint32_t)opc->id, + opc, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); } @@ -317,17 +310,17 @@ GNUNET_TESTBED_insert_opc_ (struct GNUNET_TESTBED_Controller *c, * @param opc the operation context to remove */ void -GNUNET_TESTBED_remove_opc_ (const struct GNUNET_TESTBED_Controller *c, - struct OperationContext *opc) +GNUNET_TESTBED_remove_opc_(const struct GNUNET_TESTBED_Controller *c, + struct OperationContext *opc) { - GNUNET_assert (NULL != c->opc_map); - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap32_remove (c->opc_map, - (uint32_t) opc->id, - opc)); - if ((0 == GNUNET_CONTAINER_multihashmap32_size (c->opc_map)) && + GNUNET_assert(NULL != c->opc_map); + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multihashmap32_remove(c->opc_map, + (uint32_t)opc->id, + opc)); + if ((0 == GNUNET_CONTAINER_multihashmap32_size(c->opc_map)) && (NULL != c->opcq_empty_cb)) - c->opcq_empty_cb (c->opcq_empty_cls); + c->opcq_empty_cb(c->opcq_empty_cls); } @@ -339,22 +332,22 @@ GNUNET_TESTBED_remove_opc_ (const struct GNUNET_TESTBED_Controller *c, * @return #GNUNET_OK if message is well-formed */ static int -check_add_host_confirm (void *cls, - const struct GNUNET_TESTBED_HostConfirmedMessage *msg) +check_add_host_confirm(void *cls, + const struct GNUNET_TESTBED_HostConfirmedMessage *msg) { const char *emsg; uint16_t msg_size; - msg_size = ntohs (msg->header.size) - sizeof (*msg); + msg_size = ntohs(msg->header.size) - sizeof(*msg); if (0 == msg_size) return GNUNET_OK; /* We have an error message */ - emsg = (const char *) &msg[1]; + emsg = (const char *)&msg[1]; if ('\0' != emsg[msg_size - 1]) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + { + GNUNET_break(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -367,8 +360,8 @@ check_add_host_confirm (void *cls, * @param msg message received */ static void -handle_add_host_confirm (void *cls, - const struct GNUNET_TESTBED_HostConfirmedMessage *msg) +handle_add_host_confirm(void *cls, + const struct GNUNET_TESTBED_HostConfirmedMessage *msg) { struct GNUNET_TESTBED_Controller *c = cls; struct GNUNET_TESTBED_HostRegistrationHandle *rh = c->rh; @@ -377,31 +370,31 @@ handle_add_host_confirm (void *cls, if (NULL == rh) return; - if (GNUNET_TESTBED_host_get_id_ (rh->host) != ntohl (msg->host_id)) - { - LOG_DEBUG ("Mismatch in host id's %u, %u of host confirm msg\n", - GNUNET_TESTBED_host_get_id_ (rh->host), - ntohl (msg->host_id)); - return; - } + if (GNUNET_TESTBED_host_get_id_(rh->host) != ntohl(msg->host_id)) + { + LOG_DEBUG("Mismatch in host id's %u, %u of host confirm msg\n", + GNUNET_TESTBED_host_get_id_(rh->host), + ntohl(msg->host_id)); + return; + } c->rh = NULL; - msg_size = ntohs (msg->header.size) - sizeof (*msg); + msg_size = ntohs(msg->header.size) - sizeof(*msg); if (0 == msg_size) - { - LOG_DEBUG ("Host %u successfully registered\n", ntohl (msg->host_id)); - GNUNET_TESTBED_mark_host_registered_at_ (rh->host, c); - rh->cc (rh->cc_cls, NULL); - GNUNET_free (rh); - return; - } + { + LOG_DEBUG("Host %u successfully registered\n", ntohl(msg->host_id)); + GNUNET_TESTBED_mark_host_registered_at_(rh->host, c); + rh->cc(rh->cc_cls, NULL); + GNUNET_free(rh); + return; + } /* We have an error message */ - emsg = (const char *) &msg[1]; - LOG (GNUNET_ERROR_TYPE_ERROR, - _ ("Adding host %u failed with error: %s\n"), - ntohl (msg->host_id), - emsg); - rh->cc (rh->cc_cls, emsg); - GNUNET_free (rh); + emsg = (const char *)&msg[1]; + LOG(GNUNET_ERROR_TYPE_ERROR, + _("Adding host %u failed with error: %s\n"), + ntohl(msg->host_id), + emsg); + rh->cc(rh->cc_cls, emsg); + GNUNET_free(rh); } @@ -413,19 +406,19 @@ handle_add_host_confirm (void *cls, * @param msg the message */ static void -handle_forwarded_operation_msg (void *cls, - struct OperationContext *opc, - const struct GNUNET_MessageHeader *msg) +handle_forwarded_operation_msg(void *cls, + struct OperationContext *opc, + const struct GNUNET_MessageHeader *msg) { struct GNUNET_TESTBED_Controller *c = cls; struct ForwardedOperationData *fo_data; fo_data = opc->data; if (NULL != fo_data->cc) - fo_data->cc (fo_data->cc_cls, msg); - GNUNET_TESTBED_remove_opc_ (c, opc); - GNUNET_free (fo_data); - GNUNET_free (opc); + fo_data->cc(fo_data->cc_cls, msg); + GNUNET_TESTBED_remove_opc_(c, opc); + GNUNET_free(fo_data); + GNUNET_free(opc); } @@ -437,7 +430,7 @@ handle_forwarded_operation_msg (void *cls, * @param msg message received */ static void -handle_opsuccess ( +handle_opsuccess( void *cls, const struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg) { @@ -448,13 +441,13 @@ handle_opsuccess ( struct GNUNET_TESTBED_EventInformation event; uint64_t op_id; - op_id = GNUNET_ntohll (msg->operation_id); - LOG_DEBUG ("Operation %lu successful\n", op_id); - if (NULL == (opc = find_opc (c, op_id))) - { - LOG_DEBUG ("Operation not found\n"); - return; - } + op_id = GNUNET_ntohll(msg->operation_id); + LOG_DEBUG("Operation %lu successful\n", op_id); + if (NULL == (opc = find_opc(c, op_id))) + { + LOG_DEBUG("Operation not found\n"); + return; + } event.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; event.op = opc->op; event.op_cls = opc->op_cls; @@ -463,66 +456,71 @@ handle_opsuccess ( op_comp_cb = NULL; op_comp_cb_cls = NULL; switch (opc->type) - { - case OP_FORWARDED: { - handle_forwarded_operation_msg (c, - opc, - (const struct GNUNET_MessageHeader *) msg); - return; - } - break; - case OP_PEER_DESTROY: { - struct GNUNET_TESTBED_Peer *peer; - - peer = opc->data; - GNUNET_TESTBED_peer_deregister_ (peer); - GNUNET_free (peer); - opc->data = NULL; - //PEERDESTROYDATA - } - break; - case OP_SHUTDOWN_PEERS: { - struct ShutdownPeersData *data; - - data = opc->data; - op_comp_cb = data->cb; - op_comp_cb_cls = data->cb_cls; - GNUNET_free (data); - opc->data = NULL; - GNUNET_TESTBED_cleanup_peers_ (); - } - break; - case OP_MANAGE_SERVICE: { - struct ManageServiceData *data; - - GNUNET_assert (NULL != (data = opc->data)); - op_comp_cb = data->cb; - op_comp_cb_cls = data->cb_cls; - GNUNET_free (data); - opc->data = NULL; - } - break; - case OP_PEER_RECONFIGURE: + { + case OP_FORWARDED: { + handle_forwarded_operation_msg(c, + opc, + (const struct GNUNET_MessageHeader *)msg); + return; + } + break; + + case OP_PEER_DESTROY: { + struct GNUNET_TESTBED_Peer *peer; + + peer = opc->data; + GNUNET_TESTBED_peer_deregister_(peer); + GNUNET_free(peer); + opc->data = NULL; + //PEERDESTROYDATA + } + break; + + case OP_SHUTDOWN_PEERS: { + struct ShutdownPeersData *data; + + data = opc->data; + op_comp_cb = data->cb; + op_comp_cb_cls = data->cb_cls; + GNUNET_free(data); + opc->data = NULL; + GNUNET_TESTBED_cleanup_peers_(); + } + break; + + case OP_MANAGE_SERVICE: { + struct ManageServiceData *data; + + GNUNET_assert(NULL != (data = opc->data)); + op_comp_cb = data->cb; + op_comp_cb_cls = data->cb_cls; + GNUNET_free(data); + opc->data = NULL; + } break; - default: - GNUNET_assert (0); - } - GNUNET_TESTBED_remove_opc_ (opc->c, opc); + + case OP_PEER_RECONFIGURE: + break; + + default: + GNUNET_assert(0); + } + GNUNET_TESTBED_remove_opc_(opc->c, opc); opc->state = OPC_STATE_FINISHED; - exop_insert (event.op); + exop_insert(event.op); if (0 != (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED))) - { - if (NULL != c->cc) - c->cc (c->cc_cls, &event); - if (GNUNET_NO == exop_check (event.op)) - return; - } + { + if (NULL != c->cc) + c->cc(c->cc_cls, &event); + if (GNUNET_NO == exop_check(event.op)) + return; + } else - LOG_DEBUG ("Not calling callback\n"); + LOG_DEBUG("Not calling callback\n"); if (NULL != op_comp_cb) - op_comp_cb (op_comp_cb_cls, event.op, NULL); + op_comp_cb(op_comp_cb_cls, event.op, NULL); /* You could have marked the operation as done by now */ - GNUNET_break (GNUNET_NO == exop_check (event.op)); + GNUNET_break(GNUNET_NO == exop_check(event.op)); } @@ -534,7 +532,7 @@ handle_opsuccess ( * @param msg message received */ static void -handle_peer_create_success ( +handle_peer_create_success( void *cls, const struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *msg) { @@ -547,40 +545,40 @@ handle_peer_create_success ( void *cb_cls; uint64_t op_id; - GNUNET_assert (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage) == - ntohs (msg->header.size)); - op_id = GNUNET_ntohll (msg->operation_id); - if (NULL == (opc = find_opc (c, op_id))) - { - LOG_DEBUG ("Operation context for PeerCreateSuccessEvent not found\n"); - return; - } + GNUNET_assert(sizeof(struct GNUNET_TESTBED_PeerCreateSuccessEventMessage) == + ntohs(msg->header.size)); + op_id = GNUNET_ntohll(msg->operation_id); + if (NULL == (opc = find_opc(c, op_id))) + { + LOG_DEBUG("Operation context for PeerCreateSuccessEvent not found\n"); + return; + } if (OP_FORWARDED == opc->type) - { - handle_forwarded_operation_msg (c, - opc, - (const struct GNUNET_MessageHeader *) msg); - return; - } - GNUNET_assert (OP_PEER_CREATE == opc->type); - GNUNET_assert (NULL != opc->data); + { + handle_forwarded_operation_msg(c, + opc, + (const struct GNUNET_MessageHeader *)msg); + return; + } + GNUNET_assert(OP_PEER_CREATE == opc->type); + GNUNET_assert(NULL != opc->data); data = opc->data; - GNUNET_assert (NULL != data->peer); + GNUNET_assert(NULL != data->peer); peer = data->peer; - GNUNET_assert (peer->unique_id == ntohl (msg->peer_id)); + GNUNET_assert(peer->unique_id == ntohl(msg->peer_id)); peer->state = TESTBED_PS_CREATED; - GNUNET_TESTBED_peer_register_ (peer); + GNUNET_TESTBED_peer_register_(peer); cb = data->cb; cb_cls = data->cls; op = opc->op; - GNUNET_free (opc->data); - GNUNET_TESTBED_remove_opc_ (opc->c, opc); + GNUNET_free(opc->data); + GNUNET_TESTBED_remove_opc_(opc->c, opc); opc->state = OPC_STATE_FINISHED; - exop_insert (op); + exop_insert(op); if (NULL != cb) - cb (cb_cls, peer, NULL); + cb(cb_cls, peer, NULL); /* You could have marked the operation as done by now */ - GNUNET_break (GNUNET_NO == exop_check (op)); + GNUNET_break(GNUNET_NO == exop_check(op)); } @@ -592,7 +590,7 @@ handle_peer_create_success ( * @param msg message received */ static void -handle_peer_event (void *cls, const struct GNUNET_TESTBED_PeerEventMessage *msg) +handle_peer_event(void *cls, const struct GNUNET_TESTBED_PeerEventMessage *msg) { struct GNUNET_TESTBED_Controller *c = cls; struct OperationContext *opc; @@ -604,62 +602,64 @@ handle_peer_event (void *cls, const struct GNUNET_TESTBED_PeerEventMessage *msg) uint64_t op_id; uint64_t mask; - GNUNET_assert (sizeof (struct GNUNET_TESTBED_PeerEventMessage) == - ntohs (msg->header.size)); - op_id = GNUNET_ntohll (msg->operation_id); - if (NULL == (opc = find_opc (c, op_id))) - { - LOG_DEBUG ("Operation not found\n"); - return; - } + GNUNET_assert(sizeof(struct GNUNET_TESTBED_PeerEventMessage) == + ntohs(msg->header.size)); + op_id = GNUNET_ntohll(msg->operation_id); + if (NULL == (opc = find_opc(c, op_id))) + { + LOG_DEBUG("Operation not found\n"); + return; + } if (OP_FORWARDED == opc->type) - { - handle_forwarded_operation_msg (c, - opc, - (const struct GNUNET_MessageHeader *) msg); - return; - } - GNUNET_assert ((OP_PEER_START == opc->type) || (OP_PEER_STOP == opc->type)); + { + handle_forwarded_operation_msg(c, + opc, + (const struct GNUNET_MessageHeader *)msg); + return; + } + GNUNET_assert((OP_PEER_START == opc->type) || (OP_PEER_STOP == opc->type)); data = opc->data; - GNUNET_assert (NULL != data); + GNUNET_assert(NULL != data); peer = data->peer; - GNUNET_assert (NULL != peer); - event.type = (enum GNUNET_TESTBED_EventType) ntohl (msg->event_type); + GNUNET_assert(NULL != peer); + event.type = (enum GNUNET_TESTBED_EventType)ntohl(msg->event_type); event.op = opc->op; event.op_cls = opc->op_cls; switch (event.type) - { - case GNUNET_TESTBED_ET_PEER_START: - peer->state = TESTBED_PS_STARTED; - event.details.peer_start.host = peer->host; - event.details.peer_start.peer = peer; - break; - case GNUNET_TESTBED_ET_PEER_STOP: - peer->state = TESTBED_PS_STOPPED; - event.details.peer_stop.peer = peer; - break; - default: - GNUNET_assert (0); /* We should never reach this state */ - } + { + case GNUNET_TESTBED_ET_PEER_START: + peer->state = TESTBED_PS_STARTED; + event.details.peer_start.host = peer->host; + event.details.peer_start.peer = peer; + break; + + case GNUNET_TESTBED_ET_PEER_STOP: + peer->state = TESTBED_PS_STOPPED; + event.details.peer_stop.peer = peer; + break; + + default: + GNUNET_assert(0); /* We should never reach this state */ + } pcc = data->pcc; pcc_cls = data->pcc_cls; - GNUNET_free (data); - GNUNET_TESTBED_remove_opc_ (opc->c, opc); + GNUNET_free(data); + GNUNET_TESTBED_remove_opc_(opc->c, opc); opc->state = OPC_STATE_FINISHED; - exop_insert (event.op); + exop_insert(event.op); mask = 1LL << GNUNET_TESTBED_ET_PEER_START; mask |= 1LL << GNUNET_TESTBED_ET_PEER_STOP; if (0 != (mask & c->event_mask)) - { - if (NULL != c->cc) - c->cc (c->cc_cls, &event); - if (GNUNET_NO == exop_check (event.op)) - return; - } + { + if (NULL != c->cc) + c->cc(c->cc_cls, &event); + if (GNUNET_NO == exop_check(event.op)) + return; + } if (NULL != pcc) - pcc (pcc_cls, NULL); + pcc(pcc_cls, NULL); /* You could have marked the operation as done by now */ - GNUNET_break (GNUNET_NO == exop_check (event.op)); + GNUNET_break(GNUNET_NO == exop_check(event.op)); } @@ -671,8 +671,8 @@ handle_peer_event (void *cls, const struct GNUNET_TESTBED_PeerEventMessage *msg) * @param msg message received */ static void -handle_peer_conevent (void *cls, - const struct GNUNET_TESTBED_ConnectionEventMessage *msg) +handle_peer_conevent(void *cls, + const struct GNUNET_TESTBED_ConnectionEventMessage *msg) { struct GNUNET_TESTBED_Controller *c = cls; struct OperationContext *opc; @@ -683,57 +683,59 @@ handle_peer_conevent (void *cls, uint64_t op_id; uint64_t mask; - op_id = GNUNET_ntohll (msg->operation_id); - if (NULL == (opc = find_opc (c, op_id))) - { - LOG_DEBUG ("Operation not found\n"); - return; - } + op_id = GNUNET_ntohll(msg->operation_id); + if (NULL == (opc = find_opc(c, op_id))) + { + LOG_DEBUG("Operation not found\n"); + return; + } if (OP_FORWARDED == opc->type) - { - handle_forwarded_operation_msg (c, - opc, - (const struct GNUNET_MessageHeader *) msg); - return; - } - GNUNET_assert (OP_OVERLAY_CONNECT == opc->type); - GNUNET_assert (NULL != (data = opc->data)); - GNUNET_assert ((ntohl (msg->peer1) == data->p1->unique_id) && - (ntohl (msg->peer2) == data->p2->unique_id)); - event.type = (enum GNUNET_TESTBED_EventType) ntohl (msg->event_type); + { + handle_forwarded_operation_msg(c, + opc, + (const struct GNUNET_MessageHeader *)msg); + return; + } + GNUNET_assert(OP_OVERLAY_CONNECT == opc->type); + GNUNET_assert(NULL != (data = opc->data)); + GNUNET_assert((ntohl(msg->peer1) == data->p1->unique_id) && + (ntohl(msg->peer2) == data->p2->unique_id)); + event.type = (enum GNUNET_TESTBED_EventType)ntohl(msg->event_type); event.op = opc->op; event.op_cls = opc->op_cls; switch (event.type) - { - case GNUNET_TESTBED_ET_CONNECT: - event.details.peer_connect.peer1 = data->p1; - event.details.peer_connect.peer2 = data->p2; - break; - case GNUNET_TESTBED_ET_DISCONNECT: - GNUNET_assert (0); /* FIXME: implement */ - break; - default: - GNUNET_assert (0); /* Should never reach here */ - break; - } + { + case GNUNET_TESTBED_ET_CONNECT: + event.details.peer_connect.peer1 = data->p1; + event.details.peer_connect.peer2 = data->p2; + break; + + case GNUNET_TESTBED_ET_DISCONNECT: + GNUNET_assert(0); /* FIXME: implement */ + break; + + default: + GNUNET_assert(0); /* Should never reach here */ + break; + } cb = data->cb; cb_cls = data->cb_cls; - GNUNET_TESTBED_remove_opc_ (opc->c, opc); + GNUNET_TESTBED_remove_opc_(opc->c, opc); opc->state = OPC_STATE_FINISHED; - exop_insert (event.op); + exop_insert(event.op); mask = 1LL << GNUNET_TESTBED_ET_CONNECT; mask |= 1LL << GNUNET_TESTBED_ET_DISCONNECT; if (0 != (mask & c->event_mask)) - { - if (NULL != c->cc) - c->cc (c->cc_cls, &event); - if (GNUNET_NO == exop_check (event.op)) - return; - } + { + if (NULL != c->cc) + c->cc(c->cc_cls, &event); + if (GNUNET_NO == exop_check(event.op)) + return; + } if (NULL != cb) - cb (cb_cls, opc->op, NULL); + cb(cb_cls, opc->op, NULL); /* You could have marked the operation as done by now */ - GNUNET_break (GNUNET_NO == exop_check (event.op)); + GNUNET_break(GNUNET_NO == exop_check(event.op)); } @@ -745,7 +747,7 @@ handle_peer_conevent (void *cls, * @param msg message received */ static int -check_peer_config ( +check_peer_config( void *cls, const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *msg) { @@ -762,7 +764,7 @@ check_peer_config ( * @param msg message received */ static void -handle_peer_config ( +handle_peer_config( void *cls, const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *msg) { @@ -775,52 +777,54 @@ handle_peer_config ( void *cb_cls; uint64_t op_id; - op_id = GNUNET_ntohll (msg->operation_id); - if (NULL == (opc = find_opc (c, op_id))) - { - LOG_DEBUG ("Operation not found\n"); - return; - } + op_id = GNUNET_ntohll(msg->operation_id); + if (NULL == (opc = find_opc(c, op_id))) + { + LOG_DEBUG("Operation not found\n"); + return; + } if (OP_FORWARDED == opc->type) - { - handle_forwarded_operation_msg (c, opc, &msg->header); - return; - } + { + handle_forwarded_operation_msg(c, opc, &msg->header); + return; + } data = opc->data; - GNUNET_assert (NULL != data); + GNUNET_assert(NULL != data); peer = data->peer; - GNUNET_assert (NULL != peer); - GNUNET_assert (ntohl (msg->peer_id) == peer->unique_id); - pinfo = GNUNET_new (struct GNUNET_TESTBED_PeerInformation); + GNUNET_assert(NULL != peer); + GNUNET_assert(ntohl(msg->peer_id) == peer->unique_id); + pinfo = GNUNET_new(struct GNUNET_TESTBED_PeerInformation); pinfo->pit = data->pit; cb = data->cb; cb_cls = data->cb_cls; - GNUNET_assert (NULL != cb); - GNUNET_free (data); + GNUNET_assert(NULL != cb); + GNUNET_free(data); opc->data = NULL; switch (pinfo->pit) - { - case GNUNET_TESTBED_PIT_IDENTITY: - pinfo->result.id = GNUNET_new (struct GNUNET_PeerIdentity); - GNUNET_memcpy (pinfo->result.id, - &msg->peer_identity, - sizeof (struct GNUNET_PeerIdentity)); - break; - case GNUNET_TESTBED_PIT_CONFIGURATION: - pinfo->result.cfg = /* Freed in oprelease_peer_getinfo */ - GNUNET_TESTBED_extract_config_ (&msg->header); - break; - case GNUNET_TESTBED_PIT_GENERIC: - GNUNET_assert (0); /* never reach here */ - break; - } + { + case GNUNET_TESTBED_PIT_IDENTITY: + pinfo->result.id = GNUNET_new(struct GNUNET_PeerIdentity); + GNUNET_memcpy(pinfo->result.id, + &msg->peer_identity, + sizeof(struct GNUNET_PeerIdentity)); + break; + + case GNUNET_TESTBED_PIT_CONFIGURATION: + pinfo->result.cfg = /* Freed in oprelease_peer_getinfo */ + GNUNET_TESTBED_extract_config_(&msg->header); + break; + + case GNUNET_TESTBED_PIT_GENERIC: + GNUNET_assert(0); /* never reach here */ + break; + } opc->data = pinfo; - GNUNET_TESTBED_remove_opc_ (opc->c, opc); + GNUNET_TESTBED_remove_opc_(opc->c, opc); opc->state = OPC_STATE_FINISHED; - cb (cb_cls, opc->op, pinfo, NULL); + cb(cb_cls, opc->op, pinfo, NULL); /* We dont check whether the operation is marked as done here as the operation contains data (cfg/identify) which will be freed at a later point - */ + */ } @@ -833,7 +837,7 @@ handle_peer_config ( * @return #GNUNET_OK if message is well-formed */ static int -check_op_fail_event ( +check_op_fail_event( void *cls, const struct GNUNET_TESTBED_OperationFailureEventMessage *msg) { @@ -850,7 +854,7 @@ check_op_fail_event ( * @param msg message received */ static void -handle_op_fail_event ( +handle_op_fail_event( void *cls, const struct GNUNET_TESTBED_OperationFailureEventMessage *msg) { @@ -861,34 +865,34 @@ handle_op_fail_event ( uint64_t mask; struct GNUNET_TESTBED_EventInformation event; - op_id = GNUNET_ntohll (msg->operation_id); - if (NULL == (opc = find_opc (c, op_id))) - { - LOG_DEBUG ("Operation not found\n"); - return; - } + op_id = GNUNET_ntohll(msg->operation_id); + if (NULL == (opc = find_opc(c, op_id))) + { + LOG_DEBUG("Operation not found\n"); + return; + } if (OP_FORWARDED == opc->type) - { - handle_forwarded_operation_msg (c, - opc, - (const struct GNUNET_MessageHeader *) msg); - return; - } - GNUNET_TESTBED_remove_opc_ (opc->c, opc); + { + handle_forwarded_operation_msg(c, + opc, + (const struct GNUNET_MessageHeader *)msg); + return; + } + GNUNET_TESTBED_remove_opc_(opc->c, opc); opc->state = OPC_STATE_FINISHED; - emsg = GNUNET_TESTBED_parse_error_string_ (msg); + emsg = GNUNET_TESTBED_parse_error_string_(msg); if (NULL == emsg) emsg = "Unknown error"; if (OP_PEER_INFO == opc->type) - { - struct PeerInfoData *data; - - data = opc->data; - if (NULL != data->cb) - data->cb (data->cb_cls, opc->op, NULL, emsg); - GNUNET_free (data); - return; /* We do not call controller callback for peer info */ - } + { + struct PeerInfoData *data; + + data = opc->data; + if (NULL != data->cb) + data->cb(data->cb_cls, opc->op, NULL, emsg); + GNUNET_free(data); + return; /* We do not call controller callback for peer info */ + } event.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; event.op = opc->op; event.op_cls = opc->op_cls; @@ -896,79 +900,88 @@ handle_op_fail_event ( event.details.operation_finished.generic = NULL; mask = (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); if ((0 != (mask & c->event_mask)) && (NULL != c->cc)) - { - exop_insert (event.op); - c->cc (c->cc_cls, &event); - if (GNUNET_NO == exop_check (event.op)) - return; - } + { + exop_insert(event.op); + c->cc(c->cc_cls, &event); + if (GNUNET_NO == exop_check(event.op)) + return; + } switch (opc->type) - { - case OP_PEER_CREATE: { - struct PeerCreateData *data; - - data = opc->data; - GNUNET_free (data->peer); - if (NULL != data->cb) - data->cb (data->cls, NULL, emsg); - GNUNET_free (data); - } - break; - case OP_PEER_START: - case OP_PEER_STOP: { - struct PeerEventData *data; - - data = opc->data; - if (NULL != data->pcc) - data->pcc (data->pcc_cls, emsg); - GNUNET_free (data); - } - break; - case OP_PEER_DESTROY: + { + case OP_PEER_CREATE: { + struct PeerCreateData *data; + + data = opc->data; + GNUNET_free(data->peer); + if (NULL != data->cb) + data->cb(data->cls, NULL, emsg); + GNUNET_free(data); + } break; - case OP_PEER_INFO: - GNUNET_assert (0); - case OP_OVERLAY_CONNECT: { - struct OverlayConnectData *data; - - data = opc->data; - GNUNET_TESTBED_operation_mark_failed (opc->op); - if (NULL != data->cb) - data->cb (data->cb_cls, opc->op, emsg); - } - break; - case OP_FORWARDED: - GNUNET_assert (0); - case OP_LINK_CONTROLLERS: /* No secondary callback */ + + case OP_PEER_START: + case OP_PEER_STOP: { + struct PeerEventData *data; + + data = opc->data; + if (NULL != data->pcc) + data->pcc(data->pcc_cls, emsg); + GNUNET_free(data); + } + break; + + case OP_PEER_DESTROY: + break; + + case OP_PEER_INFO: + GNUNET_assert(0); + + case OP_OVERLAY_CONNECT: { + struct OverlayConnectData *data; + + data = opc->data; + GNUNET_TESTBED_operation_mark_failed(opc->op); + if (NULL != data->cb) + data->cb(data->cb_cls, opc->op, emsg); + } break; - case OP_SHUTDOWN_PEERS: { - struct ShutdownPeersData *data; - - data = opc->data; - GNUNET_free (data); /* FIXME: Decide whether we call data->op_cb */ - opc->data = NULL; - } - break; - case OP_MANAGE_SERVICE: { - struct ManageServiceData *data = opc->data; - GNUNET_TESTBED_OperationCompletionCallback cb; - void *cb_cls; - - GNUNET_assert (NULL != data); - cb = data->cb; - cb_cls = data->cb_cls; - GNUNET_free (data); - opc->data = NULL; - exop_insert (event.op); - if (NULL != cb) - cb (cb_cls, opc->op, emsg); - /* You could have marked the operation as done by now */ - GNUNET_break (GNUNET_NO == exop_check (event.op)); - } - break; - default: - GNUNET_break (0); - } + + case OP_FORWARDED: + GNUNET_assert(0); + + case OP_LINK_CONTROLLERS: /* No secondary callback */ + break; + + case OP_SHUTDOWN_PEERS: { + struct ShutdownPeersData *data; + + data = opc->data; + GNUNET_free(data); /* FIXME: Decide whether we call data->op_cb */ + opc->data = NULL; + } + break; + + case OP_MANAGE_SERVICE: { + struct ManageServiceData *data = opc->data; + GNUNET_TESTBED_OperationCompletionCallback cb; + void *cb_cls; + + GNUNET_assert(NULL != data); + cb = data->cb; + cb_cls = data->cb_cls; + GNUNET_free(data); + opc->data = NULL; + exop_insert(event.op); + if (NULL != cb) + cb(cb_cls, opc->op, emsg); + /* You could have marked the operation as done by now */ + GNUNET_break(GNUNET_NO == exop_check(event.op)); + } + break; + + default: + GNUNET_break(0); + } } @@ -980,18 +993,18 @@ handle_op_fail_event ( * @return newly allocated SlaveGetConfigurationMessage */ static struct GNUNET_TESTBED_SlaveGetConfigurationMessage * -GNUNET_TESTBED_generate_slavegetconfig_msg_ (uint64_t op_id, uint32_t slave_id) +GNUNET_TESTBED_generate_slavegetconfig_msg_(uint64_t op_id, uint32_t slave_id) { struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg; uint16_t msize; - msize = sizeof (struct GNUNET_TESTBED_SlaveGetConfigurationMessage); - msg = GNUNET_malloc (msize); - msg->header.size = htons (msize); + msize = sizeof(struct GNUNET_TESTBED_SlaveGetConfigurationMessage); + msg = GNUNET_malloc(msize); + msg->header.size = htons(msize); msg->header.type = - htons (GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION); - msg->operation_id = GNUNET_htonll (op_id); - msg->slave_id = htonl (slave_id); + htons(GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION); + msg->operation_id = GNUNET_htonll(op_id); + msg->slave_id = htonl(slave_id); return msg; } @@ -1004,8 +1017,8 @@ GNUNET_TESTBED_generate_slavegetconfig_msg_ (uint64_t op_id, uint32_t slave_id) * @param msg message received */ static int -check_slave_config (void *cls, - const struct GNUNET_TESTBED_SlaveConfiguration *msg) +check_slave_config(void *cls, + const struct GNUNET_TESTBED_SlaveConfiguration *msg) { /* anything goes? */ return GNUNET_OK; @@ -1020,8 +1033,8 @@ check_slave_config (void *cls, * @param msg message received */ static void -handle_slave_config (void *cls, - const struct GNUNET_TESTBED_SlaveConfiguration *msg) +handle_slave_config(void *cls, + const struct GNUNET_TESTBED_SlaveConfiguration *msg) { struct GNUNET_TESTBED_Controller *c = cls; struct OperationContext *opc; @@ -1029,30 +1042,30 @@ handle_slave_config (void *cls, uint64_t mask; struct GNUNET_TESTBED_EventInformation event; - op_id = GNUNET_ntohll (msg->operation_id); - if (NULL == (opc = find_opc (c, op_id))) - { - LOG_DEBUG ("Operation not found\n"); - return; - } + op_id = GNUNET_ntohll(msg->operation_id); + if (NULL == (opc = find_opc(c, op_id))) + { + LOG_DEBUG("Operation not found\n"); + return; + } if (OP_GET_SLAVE_CONFIG != opc->type) - { - GNUNET_break (0); - return; - } + { + GNUNET_break(0); + return; + } opc->state = OPC_STATE_FINISHED; - GNUNET_TESTBED_remove_opc_ (opc->c, opc); + GNUNET_TESTBED_remove_opc_(opc->c, opc); mask = 1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED; if ((0 != (mask & c->event_mask)) && (NULL != c->cc)) - { - opc->data = GNUNET_TESTBED_extract_config_ (&msg->header); - event.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; - event.op = opc->op; - event.op_cls = opc->op_cls; - event.details.operation_finished.generic = opc->data; - event.details.operation_finished.emsg = NULL; - c->cc (c->cc_cls, &event); - } + { + opc->data = GNUNET_TESTBED_extract_config_(&msg->header); + event.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; + event.op = opc->op; + event.op_cls = opc->op_cls; + event.details.operation_finished.generic = opc->data; + event.details.operation_finished.emsg = NULL; + c->cc(c->cc_cls, &event); + } } @@ -1065,7 +1078,7 @@ handle_slave_config (void *cls, * @return #GNUNET_OK if @a msg is well-formed */ static int -check_link_controllers_result ( +check_link_controllers_result( void *cls, const struct GNUNET_TESTBED_ControllerLinkResponse *msg) { @@ -1082,7 +1095,7 @@ check_link_controllers_result ( * @param msg message received */ static void -handle_link_controllers_result ( +handle_link_controllers_result( void *cls, const struct GNUNET_TESTBED_ControllerLinkResponse *msg) { @@ -1095,31 +1108,31 @@ handle_link_controllers_result ( uint64_t op_id; struct GNUNET_TESTBED_EventInformation event; - op_id = GNUNET_ntohll (msg->operation_id); - if (NULL == (opc = find_opc (c, op_id))) - { - LOG_DEBUG ("Operation not found\n"); - return; - } + op_id = GNUNET_ntohll(msg->operation_id); + if (NULL == (opc = find_opc(c, op_id))) + { + LOG_DEBUG("Operation not found\n"); + return; + } if (OP_FORWARDED == opc->type) - { - handle_forwarded_operation_msg (c, - opc, - (const struct GNUNET_MessageHeader *) msg); - return; - } + { + handle_forwarded_operation_msg(c, + opc, + (const struct GNUNET_MessageHeader *)msg); + return; + } if (OP_LINK_CONTROLLERS != opc->type) - { - GNUNET_break (0); - return; - } - GNUNET_assert (NULL != (data = opc->data)); - host = GNUNET_TESTBED_host_lookup_by_id_ (data->host_id); - GNUNET_assert (NULL != host); - GNUNET_free (data); + { + GNUNET_break(0); + return; + } + GNUNET_assert(NULL != (data = opc->data)); + host = GNUNET_TESTBED_host_lookup_by_id_(data->host_id); + GNUNET_assert(NULL != host); + GNUNET_free(data); opc->data = NULL; opc->state = OPC_STATE_FINISHED; - GNUNET_TESTBED_remove_opc_ (opc->c, opc); + GNUNET_TESTBED_remove_opc_(opc->c, opc); event.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; event.op = opc->op; event.op_cls = opc->op_cls; @@ -1127,37 +1140,37 @@ handle_link_controllers_result ( event.details.operation_finished.generic = NULL; emsg = NULL; cfg = NULL; - if (GNUNET_NO == ntohs (msg->success)) - { - emsg = - GNUNET_malloc (ntohs (msg->header.size) - - sizeof (struct GNUNET_TESTBED_ControllerLinkResponse) + 1); - GNUNET_memcpy (emsg, - &msg[1], - ntohs (msg->header.size) - - sizeof (struct GNUNET_TESTBED_ControllerLinkResponse)); - event.details.operation_finished.emsg = emsg; - } + if (GNUNET_NO == ntohs(msg->success)) + { + emsg = + GNUNET_malloc(ntohs(msg->header.size) - + sizeof(struct GNUNET_TESTBED_ControllerLinkResponse) + 1); + GNUNET_memcpy(emsg, + &msg[1], + ntohs(msg->header.size) - + sizeof(struct GNUNET_TESTBED_ControllerLinkResponse)); + event.details.operation_finished.emsg = emsg; + } else - { - if (0 != ntohs (msg->config_size)) { - cfg = GNUNET_TESTBED_extract_config_ ( - (const struct GNUNET_MessageHeader *) msg); - GNUNET_assert (NULL != cfg); - GNUNET_TESTBED_host_replace_cfg_ (host, cfg); + if (0 != ntohs(msg->config_size)) + { + cfg = GNUNET_TESTBED_extract_config_( + (const struct GNUNET_MessageHeader *)msg); + GNUNET_assert(NULL != cfg); + GNUNET_TESTBED_host_replace_cfg_(host, cfg); + } } - } if (0 != (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED))) - { - if (NULL != c->cc) - c->cc (c->cc_cls, &event); - } + { + if (NULL != c->cc) + c->cc(c->cc_cls, &event); + } else - LOG_DEBUG ("Not calling callback\n"); + LOG_DEBUG("Not calling callback\n"); if (NULL != cfg) - GNUNET_CONFIGURATION_destroy (cfg); - GNUNET_free_non_null (emsg); + GNUNET_CONFIGURATION_destroy(cfg); + GNUNET_free_non_null(emsg); } @@ -1171,8 +1184,8 @@ handle_link_controllers_result ( * down signalling an error (message malformed) */ static int -check_barrier_status (void *cls, - const struct GNUNET_TESTBED_BarrierStatusMsg *msg) +check_barrier_status(void *cls, + const struct GNUNET_TESTBED_BarrierStatusMsg *msg) { uint16_t msize; uint16_t name_len; @@ -1180,31 +1193,31 @@ check_barrier_status (void *cls, const char *name; size_t emsg_len; - msize = ntohs (msg->header.size); + msize = ntohs(msg->header.size); name = msg->data; - name_len = ntohs (msg->name_len); + name_len = ntohs(msg->name_len); - if (sizeof (struct GNUNET_TESTBED_BarrierStatusMsg) + name_len + 1 > msize) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } + if (sizeof(struct GNUNET_TESTBED_BarrierStatusMsg) + name_len + 1 > msize) + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } if ('\0' != name[name_len]) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - status = ntohs (msg->status); - if (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status) - { - emsg_len = msize - (sizeof (struct GNUNET_TESTBED_BarrierStatusMsg) + - name_len + 1); /* +1!? */ - if (0 == emsg_len) { - GNUNET_break_op (0); + GNUNET_break_op(0); return GNUNET_SYSERR; } - } + status = ntohs(msg->status); + if (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status) + { + emsg_len = msize - (sizeof(struct GNUNET_TESTBED_BarrierStatusMsg) + + name_len + 1); /* +1!? */ + if (0 == emsg_len) + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } + } return GNUNET_OK; } @@ -1217,8 +1230,8 @@ check_barrier_status (void *cls, * @param msg the barrier status message */ static void -handle_barrier_status (void *cls, - const struct GNUNET_TESTBED_BarrierStatusMsg *msg) +handle_barrier_status(void *cls, + const struct GNUNET_TESTBED_BarrierStatusMsg *msg) { struct GNUNET_TESTBED_Controller *c = cls; struct GNUNET_TESTBED_Barrier *barrier; @@ -1232,68 +1245,68 @@ handle_barrier_status (void *cls, emsg = NULL; barrier = NULL; - msize = ntohs (msg->header.size); - if (msize <= sizeof (struct GNUNET_TESTBED_BarrierStatusMsg)) - { - GNUNET_break_op (0); - goto cleanup; - } + msize = ntohs(msg->header.size); + if (msize <= sizeof(struct GNUNET_TESTBED_BarrierStatusMsg)) + { + GNUNET_break_op(0); + goto cleanup; + } name = msg->data; - name_len = ntohs (msg->name_len); + name_len = ntohs(msg->name_len); if (name_len >= //name_len is strlen(barrier_name) - (msize - ((sizeof msg->header) + sizeof (msg->status)))) - { - GNUNET_break_op (0); - goto cleanup; - } - if ('\0' != name[name_len]) - { - GNUNET_break_op (0); - goto cleanup; - } - LOG_DEBUG ("Received BARRIER_STATUS msg\n"); - status = ntohs (msg->status); - if (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status) - { - status = -1; - //unlike name_len, emsg_len includes the trailing zero - emsg_len = msize - (sizeof (struct GNUNET_TESTBED_BarrierStatusMsg) + - (name_len + 1)); - if (0 == emsg_len) + (msize - ((sizeof msg->header) + sizeof(msg->status)))) { - GNUNET_break_op (0); + GNUNET_break_op(0); goto cleanup; } - if ('\0' != (msg->data[(name_len + 1) + (emsg_len - 1)])) + if ('\0' != name[name_len]) { - GNUNET_break_op (0); + GNUNET_break_op(0); goto cleanup; } - emsg = GNUNET_malloc (emsg_len); - GNUNET_memcpy (emsg, msg->data + name_len + 1, emsg_len); - } + LOG_DEBUG("Received BARRIER_STATUS msg\n"); + status = ntohs(msg->status); + if (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status) + { + status = -1; + //unlike name_len, emsg_len includes the trailing zero + emsg_len = msize - (sizeof(struct GNUNET_TESTBED_BarrierStatusMsg) + + (name_len + 1)); + if (0 == emsg_len) + { + GNUNET_break_op(0); + goto cleanup; + } + if ('\0' != (msg->data[(name_len + 1) + (emsg_len - 1)])) + { + GNUNET_break_op(0); + goto cleanup; + } + emsg = GNUNET_malloc(emsg_len); + GNUNET_memcpy(emsg, msg->data + name_len + 1, emsg_len); + } if (NULL == c->barrier_map) - { - GNUNET_break_op (0); - goto cleanup; - } - GNUNET_CRYPTO_hash (name, name_len, &key); - barrier = GNUNET_CONTAINER_multihashmap_get (c->barrier_map, &key); + { + GNUNET_break_op(0); + goto cleanup; + } + GNUNET_CRYPTO_hash(name, name_len, &key); + barrier = GNUNET_CONTAINER_multihashmap_get(c->barrier_map, &key); if (NULL == barrier) - { - GNUNET_break_op (0); - goto cleanup; - } - GNUNET_assert (NULL != barrier->cb); + { + GNUNET_break_op(0); + goto cleanup; + } + GNUNET_assert(NULL != barrier->cb); if ((GNUNET_YES == barrier->echo) && (GNUNET_TESTBED_BARRIERSTATUS_CROSSED == status)) - GNUNET_TESTBED_queue_message_ (c, GNUNET_copy_message (&msg->header)); - barrier->cb (barrier->cls, name, barrier, status, emsg); + GNUNET_TESTBED_queue_message_(c, GNUNET_copy_message(&msg->header)); + barrier->cb(barrier->cls, name, barrier, status, emsg); if (GNUNET_TESTBED_BARRIERSTATUS_INITIALISED == status) return; /* just initialised; skip cleanup */ cleanup: - GNUNET_free_non_null (emsg); + GNUNET_free_non_null(emsg); /** * Do not remove the barrier if we did not echo the status back; this is * required at the chained testbed controller setup to ensure the only the @@ -1301,7 +1314,7 @@ cleanup: * propagates the status. */ if ((NULL != barrier) && (GNUNET_YES == barrier->echo)) - GNUNET_TESTBED_barrier_remove_ (barrier); + GNUNET_TESTBED_barrier_remove_(barrier); } @@ -1312,22 +1325,22 @@ cleanup: * @param msg the message to queue */ void -GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller, - struct GNUNET_MessageHeader *msg) +GNUNET_TESTBED_queue_message_(struct GNUNET_TESTBED_Controller *controller, + struct GNUNET_MessageHeader *msg) { struct GNUNET_MQ_Envelope *env; struct GNUNET_MessageHeader *m2; uint16_t type; uint16_t size; - type = ntohs (msg->type); - size = ntohs (msg->size); - GNUNET_assert ((GNUNET_MESSAGE_TYPE_TESTBED_INIT <= type) && - (GNUNET_MESSAGE_TYPE_TESTBED_MAX > type)); - env = GNUNET_MQ_msg_extra (m2, size - sizeof (*m2), type); - GNUNET_memcpy (m2, msg, size); - GNUNET_free (msg); - GNUNET_MQ_send (controller->mq, env); + type = ntohs(msg->type); + size = ntohs(msg->size); + GNUNET_assert((GNUNET_MESSAGE_TYPE_TESTBED_INIT <= type) && + (GNUNET_MESSAGE_TYPE_TESTBED_MAX > type)); + env = GNUNET_MQ_msg_extra(m2, size - sizeof(*m2), type); + GNUNET_memcpy(m2, msg, size); + GNUNET_free(msg); + GNUNET_MQ_send(controller->mq, env); } @@ -1346,7 +1359,7 @@ GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller, * operation */ struct OperationContext * -GNUNET_TESTBED_forward_operation_msg_ ( +GNUNET_TESTBED_forward_operation_msg_( struct GNUNET_TESTBED_Controller *controller, uint64_t operation_id, const struct GNUNET_MessageHeader *msg, @@ -1357,21 +1370,21 @@ GNUNET_TESTBED_forward_operation_msg_ ( struct ForwardedOperationData *data; struct GNUNET_MQ_Envelope *env; struct GNUNET_MessageHeader *m2; - uint16_t type = ntohs (msg->type); - uint16_t size = ntohs (msg->size); + uint16_t type = ntohs(msg->type); + uint16_t size = ntohs(msg->size); - env = GNUNET_MQ_msg_extra (m2, size - sizeof (*m2), type); - GNUNET_memcpy (m2, msg, size); - GNUNET_MQ_send (controller->mq, env); - data = GNUNET_new (struct ForwardedOperationData); + env = GNUNET_MQ_msg_extra(m2, size - sizeof(*m2), type); + GNUNET_memcpy(m2, msg, size); + GNUNET_MQ_send(controller->mq, env); + data = GNUNET_new(struct ForwardedOperationData); data->cc = cc; data->cc_cls = cc_cls; - opc = GNUNET_new (struct OperationContext); + opc = GNUNET_new(struct OperationContext); opc->c = controller; opc->type = OP_FORWARDED; opc->data = data; opc->id = operation_id; - GNUNET_TESTBED_insert_opc_ (controller, opc); + GNUNET_TESTBED_insert_opc_(controller, opc); return opc; } @@ -1383,11 +1396,11 @@ GNUNET_TESTBED_forward_operation_msg_ ( * @param opc the operation context from GNUNET_TESTBED_forward_operation_msg_() */ void -GNUNET_TESTBED_forward_operation_msg_cancel_ (struct OperationContext *opc) +GNUNET_TESTBED_forward_operation_msg_cancel_(struct OperationContext *opc) { - GNUNET_TESTBED_remove_opc_ (opc->c, opc); - GNUNET_free (opc->data); - GNUNET_free (opc); + GNUNET_TESTBED_remove_opc_(opc->c, opc); + GNUNET_free(opc->data); + GNUNET_free(opc); } @@ -1398,19 +1411,19 @@ GNUNET_TESTBED_forward_operation_msg_cancel_ (struct OperationContext *opc) * @param cls the closure from GNUNET_TESTBED_operation_create_() */ static void -opstart_link_controllers (void *cls) +opstart_link_controllers(void *cls) { struct OperationContext *opc = cls; struct ControllerLinkData *data; struct GNUNET_TESTBED_ControllerLinkRequest *msg; - GNUNET_assert (NULL != opc->data); + GNUNET_assert(NULL != opc->data); data = opc->data; msg = data->msg; data->msg = NULL; opc->state = OPC_STATE_STARTED; - GNUNET_TESTBED_insert_opc_ (opc->c, opc); - GNUNET_TESTBED_queue_message_ (opc->c, &msg->header); + GNUNET_TESTBED_insert_opc_(opc->c, opc); + GNUNET_TESTBED_queue_message_(opc->c, &msg->header); } @@ -1420,25 +1433,27 @@ opstart_link_controllers (void *cls) * @param cls the closure from GNUNET_TESTBED_operation_create_() */ static void -oprelease_link_controllers (void *cls) +oprelease_link_controllers(void *cls) { struct OperationContext *opc = cls; struct ControllerLinkData *data; data = opc->data; switch (opc->state) - { - case OPC_STATE_INIT: - GNUNET_free (data->msg); - break; - case OPC_STATE_STARTED: - GNUNET_TESTBED_remove_opc_ (opc->c, opc); - break; - case OPC_STATE_FINISHED: - break; - } - GNUNET_free_non_null (data); - GNUNET_free (opc); + { + case OPC_STATE_INIT: + GNUNET_free(data->msg); + break; + + case OPC_STATE_STARTED: + GNUNET_TESTBED_remove_opc_(opc->c, opc); + break; + + case OPC_STATE_FINISHED: + break; + } + GNUNET_free_non_null(data); + GNUNET_free(opc); } @@ -1448,19 +1463,19 @@ oprelease_link_controllers (void *cls) * @param cls the OperationContext of type OP_GET_SLAVE_CONFIG */ static void -opstart_get_slave_config (void *cls) +opstart_get_slave_config(void *cls) { struct OperationContext *opc = cls; struct GetSlaveConfigData *data = opc->data; struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg; - GNUNET_assert (NULL != data); - msg = GNUNET_TESTBED_generate_slavegetconfig_msg_ (opc->id, data->slave_id); - GNUNET_free (opc->data); + GNUNET_assert(NULL != data); + msg = GNUNET_TESTBED_generate_slavegetconfig_msg_(opc->id, data->slave_id); + GNUNET_free(opc->data); data = NULL; opc->data = NULL; - GNUNET_TESTBED_insert_opc_ (opc->c, opc); - GNUNET_TESTBED_queue_message_ (opc->c, &msg->header); + GNUNET_TESTBED_insert_opc_(opc->c, opc); + GNUNET_TESTBED_queue_message_(opc->c, &msg->header); opc->state = OPC_STATE_STARTED; } @@ -1471,24 +1486,26 @@ opstart_get_slave_config (void *cls) * @param cls the OperationContext of type OP_GET_SLAVE_CONFIG */ static void -oprelease_get_slave_config (void *cls) +oprelease_get_slave_config(void *cls) { struct OperationContext *opc = cls; switch (opc->state) - { - case OPC_STATE_INIT: - GNUNET_free (opc->data); - break; - case OPC_STATE_STARTED: - GNUNET_TESTBED_remove_opc_ (opc->c, opc); - break; - case OPC_STATE_FINISHED: - if (NULL != opc->data) - GNUNET_CONFIGURATION_destroy (opc->data); - break; - } - GNUNET_free (opc); + { + case OPC_STATE_INIT: + GNUNET_free(opc->data); + break; + + case OPC_STATE_STARTED: + GNUNET_TESTBED_remove_opc_(opc->c, opc); + break; + + case OPC_STATE_FINISHED: + if (NULL != opc->data) + GNUNET_CONFIGURATION_destroy(opc->data); + break; + } + GNUNET_free(opc); } @@ -1501,13 +1518,13 @@ oprelease_get_slave_config (void *cls) * @param error error code */ static void -mq_error_handler (void *cls, enum GNUNET_MQ_Error error) +mq_error_handler(void *cls, enum GNUNET_MQ_Error error) { /* struct GNUNET_TESTBED_Controller *c = cls; */ - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Encountered MQ error: %d\n", error); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Encountered MQ error: %d\n", error); /* now what? */ - GNUNET_SCHEDULER_shutdown (); /* seems most reasonable */ + GNUNET_SCHEDULER_shutdown(); /* seems most reasonable */ } @@ -1527,58 +1544,58 @@ mq_error_handler (void *cls, enum GNUNET_MQ_Error error) * @return handle to the controller */ struct GNUNET_TESTBED_Controller * -GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host, - uint64_t event_mask, - GNUNET_TESTBED_ControllerCallback cc, - void *cc_cls) +GNUNET_TESTBED_controller_connect(struct GNUNET_TESTBED_Host *host, + uint64_t event_mask, + GNUNET_TESTBED_ControllerCallback cc, + void *cc_cls) { struct GNUNET_TESTBED_Controller *controller = - GNUNET_new (struct GNUNET_TESTBED_Controller); + GNUNET_new(struct GNUNET_TESTBED_Controller); struct GNUNET_MQ_MessageHandler handlers[] = - {GNUNET_MQ_hd_var_size (add_host_confirm, - GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS, - struct GNUNET_TESTBED_HostConfirmedMessage, - controller), - GNUNET_MQ_hd_fixed_size (peer_conevent, - GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT, - struct GNUNET_TESTBED_ConnectionEventMessage, - controller), - GNUNET_MQ_hd_fixed_size (opsuccess, - GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS, - struct - GNUNET_TESTBED_GenericOperationSuccessEventMessage, - controller), - GNUNET_MQ_hd_var_size (op_fail_event, - GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT, - struct GNUNET_TESTBED_OperationFailureEventMessage, + { GNUNET_MQ_hd_var_size(add_host_confirm, + GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS, + struct GNUNET_TESTBED_HostConfirmedMessage, + controller), + GNUNET_MQ_hd_fixed_size(peer_conevent, + GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT, + struct GNUNET_TESTBED_ConnectionEventMessage, controller), - GNUNET_MQ_hd_fixed_size (peer_create_success, - GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS, - struct - GNUNET_TESTBED_PeerCreateSuccessEventMessage, - controller), - GNUNET_MQ_hd_fixed_size (peer_event, - GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT, - struct GNUNET_TESTBED_PeerEventMessage, - controller), - GNUNET_MQ_hd_var_size (peer_config, - GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION, + GNUNET_MQ_hd_fixed_size(opsuccess, + GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS, struct - GNUNET_TESTBED_PeerConfigurationInformationMessage, + GNUNET_TESTBED_GenericOperationSuccessEventMessage, controller), - GNUNET_MQ_hd_var_size (slave_config, - GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION, - struct GNUNET_TESTBED_SlaveConfiguration, - controller), - GNUNET_MQ_hd_var_size (link_controllers_result, - GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT, - struct GNUNET_TESTBED_ControllerLinkResponse, + GNUNET_MQ_hd_var_size(op_fail_event, + GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT, + struct GNUNET_TESTBED_OperationFailureEventMessage, + controller), + GNUNET_MQ_hd_fixed_size(peer_create_success, + GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS, + struct + GNUNET_TESTBED_PeerCreateSuccessEventMessage, controller), - GNUNET_MQ_hd_var_size (barrier_status, - GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS, - struct GNUNET_TESTBED_BarrierStatusMsg, + GNUNET_MQ_hd_fixed_size(peer_event, + GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT, + struct GNUNET_TESTBED_PeerEventMessage, controller), - GNUNET_MQ_handler_end ()}; + GNUNET_MQ_hd_var_size(peer_config, + GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION, + struct + GNUNET_TESTBED_PeerConfigurationInformationMessage, + controller), + GNUNET_MQ_hd_var_size(slave_config, + GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION, + struct GNUNET_TESTBED_SlaveConfiguration, + controller), + GNUNET_MQ_hd_var_size(link_controllers_result, + GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT, + struct GNUNET_TESTBED_ControllerLinkResponse, + controller), + GNUNET_MQ_hd_var_size(barrier_status, + GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS, + struct GNUNET_TESTBED_BarrierStatusMsg, + controller), + GNUNET_MQ_handler_end() }; struct GNUNET_TESTBED_InitMessage *msg; struct GNUNET_MQ_Envelope *env; const struct GNUNET_CONFIGURATION_Handle *cfg; @@ -1588,75 +1605,75 @@ GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host, unsigned long long max_parallel_topology_config_operations; size_t slen; - GNUNET_assert (NULL != (cfg = GNUNET_TESTBED_host_get_cfg_ (host))); + GNUNET_assert(NULL != (cfg = GNUNET_TESTBED_host_get_cfg_(host))); if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (cfg, - "testbed", - "MAX_PARALLEL_OPERATIONS", - &max_parallel_operations)) - { - GNUNET_break (0); - GNUNET_free (controller); - return NULL; - } + GNUNET_CONFIGURATION_get_value_number(cfg, + "testbed", + "MAX_PARALLEL_OPERATIONS", + &max_parallel_operations)) + { + GNUNET_break(0); + GNUNET_free(controller); + return NULL; + } if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (cfg, - "testbed", - "MAX_PARALLEL_SERVICE_CONNECTIONS", - &max_parallel_service_connections)) - { - GNUNET_break (0); - GNUNET_free (controller); - return NULL; - } - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number ( - cfg, - "testbed", - "MAX_PARALLEL_TOPOLOGY_CONFIG_OPERATIONS", - &max_parallel_topology_config_operations)) - { - GNUNET_break (0); - GNUNET_free (controller); - return NULL; - } + GNUNET_CONFIGURATION_get_value_number(cfg, + "testbed", + "MAX_PARALLEL_SERVICE_CONNECTIONS", + &max_parallel_service_connections)) + { + GNUNET_break(0); + GNUNET_free(controller); + return NULL; + } + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number( + cfg, + "testbed", + "MAX_PARALLEL_TOPOLOGY_CONFIG_OPERATIONS", + &max_parallel_topology_config_operations)) + { + GNUNET_break(0); + GNUNET_free(controller); + return NULL; + } controller->cc = cc; controller->cc_cls = cc_cls; controller->event_mask = event_mask; - controller->cfg = GNUNET_CONFIGURATION_dup (cfg); - controller->mq = GNUNET_CLIENT_connect (controller->cfg, - "testbed", - handlers, - &mq_error_handler, - controller); + controller->cfg = GNUNET_CONFIGURATION_dup(cfg); + controller->mq = GNUNET_CLIENT_connect(controller->cfg, + "testbed", + handlers, + &mq_error_handler, + controller); if (NULL == controller->mq) - { - GNUNET_break (0); - GNUNET_TESTBED_controller_disconnect (controller); - return NULL; - } - GNUNET_TESTBED_mark_host_registered_at_ (host, controller); + { + GNUNET_break(0); + GNUNET_TESTBED_controller_disconnect(controller); + return NULL; + } + GNUNET_TESTBED_mark_host_registered_at_(host, controller); controller->host = host; controller->opq_parallel_operations = - GNUNET_TESTBED_operation_queue_create_ (OPERATION_QUEUE_TYPE_FIXED, - (unsigned int) - max_parallel_operations); + GNUNET_TESTBED_operation_queue_create_(OPERATION_QUEUE_TYPE_FIXED, + (unsigned int) + max_parallel_operations); controller->opq_parallel_service_connections = - GNUNET_TESTBED_operation_queue_create_ (OPERATION_QUEUE_TYPE_FIXED, - (unsigned int) - max_parallel_service_connections); + GNUNET_TESTBED_operation_queue_create_(OPERATION_QUEUE_TYPE_FIXED, + (unsigned int) + max_parallel_service_connections); controller->opq_parallel_topology_config_operations = - GNUNET_TESTBED_operation_queue_create_ ( + GNUNET_TESTBED_operation_queue_create_( OPERATION_QUEUE_TYPE_FIXED, - (unsigned int) max_parallel_topology_config_operations); - controller_hostname = GNUNET_TESTBED_host_get_hostname (host); + (unsigned int)max_parallel_topology_config_operations); + controller_hostname = GNUNET_TESTBED_host_get_hostname(host); if (NULL == controller_hostname) controller_hostname = "127.0.0.1"; - slen = strlen (controller_hostname) + 1; - env = GNUNET_MQ_msg_extra (msg, slen, GNUNET_MESSAGE_TYPE_TESTBED_INIT); - msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host)); - msg->event_mask = GNUNET_htonll (controller->event_mask); - GNUNET_memcpy (&msg[1], controller_hostname, slen); - GNUNET_MQ_send (controller->mq, env); + slen = strlen(controller_hostname) + 1; + env = GNUNET_MQ_msg_extra(msg, slen, GNUNET_MESSAGE_TYPE_TESTBED_INIT); + msg->host_id = htonl(GNUNET_TESTBED_host_get_id_(host)); + msg->event_mask = GNUNET_htonll(controller->event_mask); + GNUNET_memcpy(&msg[1], controller_hostname, slen); + GNUNET_MQ_send(controller->mq, env); return controller; } @@ -1671,16 +1688,16 @@ GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host, * #GNUNET_NO if not. */ static int -opc_free_iterator (void *cls, uint32_t key, void *value) +opc_free_iterator(void *cls, uint32_t key, void *value) { struct GNUNET_CONTAINER_MultiHashMap32 *map = cls; struct OperationContext *opc = value; - GNUNET_assert (NULL != opc); - GNUNET_break (0); - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap32_remove (map, key, value)); - GNUNET_free (opc); + GNUNET_assert(NULL != opc); + GNUNET_break(0); + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multihashmap32_remove(map, key, value)); + GNUNET_free(opc); return GNUNET_YES; } @@ -1693,30 +1710,30 @@ opc_free_iterator (void *cls, uint32_t key, void *value) * @param c handle to controller to stop */ void -GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *c) +GNUNET_TESTBED_controller_disconnect(struct GNUNET_TESTBED_Controller *c) { if (NULL != c->mq) - { - GNUNET_MQ_destroy (c->mq); - c->mq = NULL; - } + { + GNUNET_MQ_destroy(c->mq); + c->mq = NULL; + } if (NULL != c->host) - GNUNET_TESTBED_deregister_host_at_ (c->host, c); - GNUNET_CONFIGURATION_destroy (c->cfg); - GNUNET_TESTBED_operation_queue_destroy_ (c->opq_parallel_operations); - GNUNET_TESTBED_operation_queue_destroy_ (c->opq_parallel_service_connections); - GNUNET_TESTBED_operation_queue_destroy_ ( + GNUNET_TESTBED_deregister_host_at_(c->host, c); + GNUNET_CONFIGURATION_destroy(c->cfg); + GNUNET_TESTBED_operation_queue_destroy_(c->opq_parallel_operations); + GNUNET_TESTBED_operation_queue_destroy_(c->opq_parallel_service_connections); + GNUNET_TESTBED_operation_queue_destroy_( c->opq_parallel_topology_config_operations); if (NULL != c->opc_map) - { - GNUNET_assert (GNUNET_SYSERR != - GNUNET_CONTAINER_multihashmap32_iterate (c->opc_map, + { + GNUNET_assert(GNUNET_SYSERR != + GNUNET_CONTAINER_multihashmap32_iterate(c->opc_map, &opc_free_iterator, c->opc_map)); - GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap32_size (c->opc_map)); - GNUNET_CONTAINER_multihashmap32_destroy (c->opc_map); - } - GNUNET_free (c); + GNUNET_assert(0 == GNUNET_CONTAINER_multihashmap32_size(c->opc_map)); + GNUNET_CONTAINER_multihashmap32_destroy(c->opc_map); + } + GNUNET_free(c); } @@ -1730,19 +1747,19 @@ GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *c) * @return the size of the xconfig */ size_t -GNUNET_TESTBED_compress_config_ (const char *config, - size_t size, - char **xconfig) +GNUNET_TESTBED_compress_config_(const char *config, + size_t size, + char **xconfig) { size_t xsize; - xsize = compressBound ((uLong) size); - *xconfig = GNUNET_malloc (xsize); - GNUNET_assert (Z_OK == compress2 ((Bytef *) *xconfig, - (uLongf *) &xsize, - (const Bytef *) config, - (uLongf) size, - Z_BEST_SPEED)); + xsize = compressBound((uLong)size); + *xconfig = GNUNET_malloc(xsize); + GNUNET_assert(Z_OK == compress2((Bytef *)*xconfig, + (uLongf *)&xsize, + (const Bytef *)config, + (uLongf)size, + Z_BEST_SPEED)); return xsize; } @@ -1757,18 +1774,18 @@ GNUNET_TESTBED_compress_config_ (const char *config, * @return the serialized and compressed configuration */ char * -GNUNET_TESTBED_compress_cfg_ (const struct GNUNET_CONFIGURATION_Handle *cfg, - size_t *size, - size_t *xsize) +GNUNET_TESTBED_compress_cfg_(const struct GNUNET_CONFIGURATION_Handle *cfg, + size_t *size, + size_t *xsize) { char *config; char *xconfig; size_t size_; size_t xsize_; - config = GNUNET_CONFIGURATION_serialize (cfg, &size_); - xsize_ = GNUNET_TESTBED_compress_config_ (config, size_, &xconfig); - GNUNET_free (config); + config = GNUNET_CONFIGURATION_serialize(cfg, &size_); + xsize_ = GNUNET_TESTBED_compress_config_(config, size_, &xconfig); + GNUNET_free(config); *size = size_; *xsize = xsize_; return xconfig; @@ -1804,11 +1821,11 @@ GNUNET_TESTBED_compress_cfg_ (const struct GNUNET_CONFIGURATION_Handle *cfg, * @return the operation handle */ struct GNUNET_TESTBED_Operation * -GNUNET_TESTBED_controller_link (void *op_cls, - struct GNUNET_TESTBED_Controller *master, - struct GNUNET_TESTBED_Host *delegated_host, - struct GNUNET_TESTBED_Host *slave_host, - int is_subordinate) +GNUNET_TESTBED_controller_link(void *op_cls, + struct GNUNET_TESTBED_Controller *master, + struct GNUNET_TESTBED_Host *delegated_host, + struct GNUNET_TESTBED_Host *slave_host, + int is_subordinate) { struct OperationContext *opc; struct GNUNET_TESTBED_ControllerLinkRequest *msg; @@ -1817,38 +1834,38 @@ GNUNET_TESTBED_controller_link (void *op_cls, uint32_t delegated_host_id; uint16_t msg_size; - GNUNET_assert (GNUNET_YES == - GNUNET_TESTBED_is_host_registered_ (delegated_host, master)); - slave_host_id = GNUNET_TESTBED_host_get_id_ ( + GNUNET_assert(GNUNET_YES == + GNUNET_TESTBED_is_host_registered_(delegated_host, master)); + slave_host_id = GNUNET_TESTBED_host_get_id_( (NULL != slave_host) ? slave_host : master->host); - delegated_host_id = GNUNET_TESTBED_host_get_id_ (delegated_host); + delegated_host_id = GNUNET_TESTBED_host_get_id_(delegated_host); if ((NULL != slave_host) && (0 != slave_host_id)) - GNUNET_assert (GNUNET_YES == - GNUNET_TESTBED_is_host_registered_ (slave_host, master)); - msg_size = sizeof (struct GNUNET_TESTBED_ControllerLinkRequest); - msg = GNUNET_malloc (msg_size); - msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS); - msg->header.size = htons (msg_size); - msg->delegated_host_id = htonl (delegated_host_id); - msg->slave_host_id = htonl (slave_host_id); + GNUNET_assert(GNUNET_YES == + GNUNET_TESTBED_is_host_registered_(slave_host, master)); + msg_size = sizeof(struct GNUNET_TESTBED_ControllerLinkRequest); + msg = GNUNET_malloc(msg_size); + msg->header.type = htons(GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS); + msg->header.size = htons(msg_size); + msg->delegated_host_id = htonl(delegated_host_id); + msg->slave_host_id = htonl(slave_host_id); msg->is_subordinate = (GNUNET_YES == is_subordinate) ? 1 : 0; - data = GNUNET_new (struct ControllerLinkData); + data = GNUNET_new(struct ControllerLinkData); data->msg = msg; data->host_id = delegated_host_id; - opc = GNUNET_new (struct OperationContext); + opc = GNUNET_new(struct OperationContext); opc->c = master; opc->data = data; opc->type = OP_LINK_CONTROLLERS; - opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); + opc->id = GNUNET_TESTBED_get_next_op_id(opc->c); opc->state = OPC_STATE_INIT; opc->op_cls = op_cls; - msg->operation_id = GNUNET_htonll (opc->id); - opc->op = GNUNET_TESTBED_operation_create_ (opc, - &opstart_link_controllers, - &oprelease_link_controllers); - GNUNET_TESTBED_operation_queue_insert_ (master->opq_parallel_operations, - opc->op); - GNUNET_TESTBED_operation_begin_wait_ (opc->op); + msg->operation_id = GNUNET_htonll(opc->id); + opc->op = GNUNET_TESTBED_operation_create_(opc, + &opstart_link_controllers, + &oprelease_link_controllers); + GNUNET_TESTBED_operation_queue_insert_(master->opq_parallel_operations, + opc->op); + GNUNET_TESTBED_operation_begin_wait_(opc->op); return opc->op; } @@ -1866,28 +1883,28 @@ GNUNET_TESTBED_controller_link (void *op_cls, * @return the operation handle; */ struct GNUNET_TESTBED_Operation * -GNUNET_TESTBED_get_slave_config_ (void *op_cls, - struct GNUNET_TESTBED_Controller *master, - uint32_t slave_host_id) +GNUNET_TESTBED_get_slave_config_(void *op_cls, + struct GNUNET_TESTBED_Controller *master, + uint32_t slave_host_id) { struct OperationContext *opc; struct GetSlaveConfigData *data; - data = GNUNET_new (struct GetSlaveConfigData); + data = GNUNET_new(struct GetSlaveConfigData); data->slave_id = slave_host_id; - opc = GNUNET_new (struct OperationContext); + opc = GNUNET_new(struct OperationContext); opc->state = OPC_STATE_INIT; opc->c = master; - opc->id = GNUNET_TESTBED_get_next_op_id (master); + opc->id = GNUNET_TESTBED_get_next_op_id(master); opc->type = OP_GET_SLAVE_CONFIG; opc->data = data; opc->op_cls = op_cls; - opc->op = GNUNET_TESTBED_operation_create_ (opc, - &opstart_get_slave_config, - &oprelease_get_slave_config); - GNUNET_TESTBED_operation_queue_insert_ (master->opq_parallel_operations, - opc->op); - GNUNET_TESTBED_operation_begin_wait_ (opc->op); + opc->op = GNUNET_TESTBED_operation_create_(opc, + &opstart_get_slave_config, + &oprelease_get_slave_config); + GNUNET_TESTBED_operation_queue_insert_(master->opq_parallel_operations, + opc->op); + GNUNET_TESTBED_operation_begin_wait_(opc->op); return opc->op; } @@ -1908,16 +1925,16 @@ GNUNET_TESTBED_get_slave_config_ (void *op_cls, * master */ struct GNUNET_TESTBED_Operation * -GNUNET_TESTBED_get_slave_config (void *op_cls, - struct GNUNET_TESTBED_Controller *master, - struct GNUNET_TESTBED_Host *slave_host) +GNUNET_TESTBED_get_slave_config(void *op_cls, + struct GNUNET_TESTBED_Controller *master, + struct GNUNET_TESTBED_Host *slave_host) { - if (GNUNET_NO == GNUNET_TESTBED_is_host_registered_ (slave_host, master)) + if (GNUNET_NO == GNUNET_TESTBED_is_host_registered_(slave_host, master)) return NULL; - return GNUNET_TESTBED_get_slave_config_ (op_cls, - master, - GNUNET_TESTBED_host_get_id_ ( - slave_host)); + return GNUNET_TESTBED_get_slave_config_(op_cls, + master, + GNUNET_TESTBED_host_get_id_( + slave_host)); } @@ -1931,11 +1948,11 @@ GNUNET_TESTBED_get_slave_config (void *op_cls, * be written to. */ void -GNUNET_TESTBED_overlay_write_topology_to_file ( +GNUNET_TESTBED_overlay_write_topology_to_file( struct GNUNET_TESTBED_Controller *controller, const char *filename) { - GNUNET_break (0); + GNUNET_break(0); } @@ -1953,7 +1970,7 @@ GNUNET_TESTBED_overlay_write_topology_to_file ( * @return the initialization message */ struct GNUNET_TESTBED_HelperInit * -GNUNET_TESTBED_create_helper_init_msg_ ( +GNUNET_TESTBED_create_helper_init_msg_( const char *trusted_ip, const char *hostname, const struct GNUNET_CONFIGURATION_Handle *cfg) @@ -1967,30 +1984,30 @@ GNUNET_TESTBED_create_helper_init_msg_ ( uint16_t hostname_len; uint16_t msg_size; - config = GNUNET_CONFIGURATION_serialize (cfg, &config_size); - GNUNET_assert (NULL != config); + config = GNUNET_CONFIGURATION_serialize(cfg, &config_size); + GNUNET_assert(NULL != config); xconfig_size = - GNUNET_TESTBED_compress_config_ (config, config_size, &xconfig); - GNUNET_free (config); - trusted_ip_len = strlen (trusted_ip); - hostname_len = (NULL == hostname) ? 0 : strlen (hostname); + GNUNET_TESTBED_compress_config_(config, config_size, &xconfig); + GNUNET_free(config); + trusted_ip_len = strlen(trusted_ip); + hostname_len = (NULL == hostname) ? 0 : strlen(hostname); msg_size = xconfig_size + trusted_ip_len + 1 + - sizeof (struct GNUNET_TESTBED_HelperInit); + sizeof(struct GNUNET_TESTBED_HelperInit); msg_size += hostname_len; - msg = GNUNET_realloc (xconfig, msg_size); - (void) memmove (((void *) &msg[1]) + trusted_ip_len + 1 + hostname_len, - msg, - xconfig_size); - msg->header.size = htons (msg_size); - msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT); - msg->trusted_ip_size = htons (trusted_ip_len); - msg->hostname_size = htons (hostname_len); - msg->config_size = htons (config_size); - (void) strcpy ((char *) &msg[1], trusted_ip); + msg = GNUNET_realloc(xconfig, msg_size); + (void)memmove(((void *)&msg[1]) + trusted_ip_len + 1 + hostname_len, + msg, + xconfig_size); + msg->header.size = htons(msg_size); + msg->header.type = htons(GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT); + msg->trusted_ip_size = htons(trusted_ip_len); + msg->hostname_size = htons(hostname_len); + msg->config_size = htons(config_size); + (void)strcpy((char *)&msg[1], trusted_ip); if (0 != hostname_len) - GNUNET_memcpy ((char *) &msg[1] + trusted_ip_len + 1, - hostname, - hostname_len); + GNUNET_memcpy((char *)&msg[1] + trusted_ip_len + 1, + hostname, + hostname_len); return msg; } @@ -2017,10 +2034,10 @@ GNUNET_TESTBED_create_helper_init_msg_ ( * @param operation operation to signal completion or cancellation */ void -GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation) +GNUNET_TESTBED_operation_done(struct GNUNET_TESTBED_Operation *operation) { - (void) exop_check (operation); - GNUNET_TESTBED_operation_release_ (operation); + (void)exop_check(operation); + GNUNET_TESTBED_operation_release_(operation); } @@ -2039,7 +2056,7 @@ GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation) * @return handle to the parsed configuration; NULL upon error while parsing the message */ struct GNUNET_CONFIGURATION_Handle * -GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg) +GNUNET_TESTBED_extract_config_(const struct GNUNET_MessageHeader *msg) { struct GNUNET_CONFIGURATION_Handle *cfg; Bytef *data; @@ -2048,93 +2065,99 @@ GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg) uLong xdata_len; int ret; - switch (ntohs (msg->type)) - { - case GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION: { - const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *imsg; - - imsg = - (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *) msg; - data_len = (uLong) ntohs (imsg->config_size); - xdata_len = - ntohs (imsg->header.size) - - sizeof (struct GNUNET_TESTBED_PeerConfigurationInformationMessage); - xdata = (const Bytef *) &imsg[1]; - } - break; - case GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION: { - const struct GNUNET_TESTBED_SlaveConfiguration *imsg; - - imsg = (const struct GNUNET_TESTBED_SlaveConfiguration *) msg; - data_len = (uLong) ntohs (imsg->config_size); - xdata_len = ntohs (imsg->header.size) - - sizeof (struct GNUNET_TESTBED_SlaveConfiguration); - xdata = (const Bytef *) &imsg[1]; - } - break; - case GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST: { - const struct GNUNET_TESTBED_AddHostMessage *imsg; - uint16_t osize; - - imsg = (const struct GNUNET_TESTBED_AddHostMessage *) msg; - data_len = (uLong) ntohs (imsg->config_size); - osize = sizeof (struct GNUNET_TESTBED_AddHostMessage) + - ntohs (imsg->username_length) + ntohs (imsg->hostname_length); - xdata_len = ntohs (imsg->header.size) - osize; - xdata = (const Bytef *) ((const void *) imsg + osize); - } - break; - case GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT: { - const struct GNUNET_TESTBED_ControllerLinkResponse *imsg; - - imsg = (const struct GNUNET_TESTBED_ControllerLinkResponse *) msg; - data_len = ntohs (imsg->config_size); - xdata_len = ntohs (imsg->header.size) - - sizeof (const struct GNUNET_TESTBED_ControllerLinkResponse); - xdata = (const Bytef *) &imsg[1]; - } - break; - case GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER: { - const struct GNUNET_TESTBED_PeerCreateMessage *imsg; - - imsg = (const struct GNUNET_TESTBED_PeerCreateMessage *) msg; - data_len = ntohs (imsg->config_size); - xdata_len = ntohs (imsg->header.size) - - sizeof (struct GNUNET_TESTBED_PeerCreateMessage); - xdata = (const Bytef *) &imsg[1]; - } - break; - case GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER: { - const struct GNUNET_TESTBED_PeerReconfigureMessage *imsg; - - imsg = (const struct GNUNET_TESTBED_PeerReconfigureMessage *) msg; - data_len = ntohs (imsg->config_size); - xdata_len = ntohs (imsg->header.size) - - sizeof (struct GNUNET_TESTBED_PeerReconfigureMessage); - xdata = (const Bytef *) &imsg[1]; - } - break; - default: - GNUNET_assert (0); - } - data = GNUNET_malloc (data_len); - if (Z_OK != (ret = uncompress (data, &data_len, xdata, xdata_len))) - { - GNUNET_free (data); - GNUNET_break_op (0); /* Un-compression failure */ - return NULL; - } - cfg = GNUNET_CONFIGURATION_create (); - if (GNUNET_OK != GNUNET_CONFIGURATION_deserialize (cfg, - (const char *) data, - (size_t) data_len, - NULL)) - { - GNUNET_free (data); - GNUNET_break_op (0); /* De-serialization failure */ - return NULL; - } - GNUNET_free (data); + switch (ntohs(msg->type)) + { + case GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION: { + const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *imsg; + + imsg = + (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *)msg; + data_len = (uLong)ntohs(imsg->config_size); + xdata_len = + ntohs(imsg->header.size) - + sizeof(struct GNUNET_TESTBED_PeerConfigurationInformationMessage); + xdata = (const Bytef *)&imsg[1]; + } + break; + + case GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION: { + const struct GNUNET_TESTBED_SlaveConfiguration *imsg; + + imsg = (const struct GNUNET_TESTBED_SlaveConfiguration *)msg; + data_len = (uLong)ntohs(imsg->config_size); + xdata_len = ntohs(imsg->header.size) - + sizeof(struct GNUNET_TESTBED_SlaveConfiguration); + xdata = (const Bytef *)&imsg[1]; + } + break; + + case GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST: { + const struct GNUNET_TESTBED_AddHostMessage *imsg; + uint16_t osize; + + imsg = (const struct GNUNET_TESTBED_AddHostMessage *)msg; + data_len = (uLong)ntohs(imsg->config_size); + osize = sizeof(struct GNUNET_TESTBED_AddHostMessage) + + ntohs(imsg->username_length) + ntohs(imsg->hostname_length); + xdata_len = ntohs(imsg->header.size) - osize; + xdata = (const Bytef *)((const void *)imsg + osize); + } + break; + + case GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT: { + const struct GNUNET_TESTBED_ControllerLinkResponse *imsg; + + imsg = (const struct GNUNET_TESTBED_ControllerLinkResponse *)msg; + data_len = ntohs(imsg->config_size); + xdata_len = ntohs(imsg->header.size) - + sizeof(const struct GNUNET_TESTBED_ControllerLinkResponse); + xdata = (const Bytef *)&imsg[1]; + } + break; + + case GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER: { + const struct GNUNET_TESTBED_PeerCreateMessage *imsg; + + imsg = (const struct GNUNET_TESTBED_PeerCreateMessage *)msg; + data_len = ntohs(imsg->config_size); + xdata_len = ntohs(imsg->header.size) - + sizeof(struct GNUNET_TESTBED_PeerCreateMessage); + xdata = (const Bytef *)&imsg[1]; + } + break; + + case GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER: { + const struct GNUNET_TESTBED_PeerReconfigureMessage *imsg; + + imsg = (const struct GNUNET_TESTBED_PeerReconfigureMessage *)msg; + data_len = ntohs(imsg->config_size); + xdata_len = ntohs(imsg->header.size) - + sizeof(struct GNUNET_TESTBED_PeerReconfigureMessage); + xdata = (const Bytef *)&imsg[1]; + } + break; + + default: + GNUNET_assert(0); + } + data = GNUNET_malloc(data_len); + if (Z_OK != (ret = uncompress(data, &data_len, xdata, xdata_len))) + { + GNUNET_free(data); + GNUNET_break_op(0); /* Un-compression failure */ + return NULL; + } + cfg = GNUNET_CONFIGURATION_create(); + if (GNUNET_OK != GNUNET_CONFIGURATION_deserialize(cfg, + (const char *)data, + (size_t)data_len, + NULL)) + { + GNUNET_free(data); + GNUNET_break_op(0); /* De-serialization failure */ + return NULL; + } + GNUNET_free(data); return cfg; } @@ -2147,22 +2170,22 @@ GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg) * @return the error message */ const char * -GNUNET_TESTBED_parse_error_string_ ( +GNUNET_TESTBED_parse_error_string_( const struct GNUNET_TESTBED_OperationFailureEventMessage *msg) { uint16_t msize; const char *emsg; - msize = ntohs (msg->header.size); - if (sizeof (struct GNUNET_TESTBED_OperationFailureEventMessage) >= msize) + msize = ntohs(msg->header.size); + if (sizeof(struct GNUNET_TESTBED_OperationFailureEventMessage) >= msize) return NULL; - msize -= sizeof (struct GNUNET_TESTBED_OperationFailureEventMessage); - emsg = (const char *) &msg[1]; + msize -= sizeof(struct GNUNET_TESTBED_OperationFailureEventMessage); + emsg = (const char *)&msg[1]; if ('\0' != emsg[msize - 1]) - { - GNUNET_break (0); - return NULL; - } + { + GNUNET_break(0); + return NULL; + } return emsg; } @@ -2175,13 +2198,13 @@ GNUNET_TESTBED_parse_error_string_ ( * @return the incremented operation id. */ uint64_t -GNUNET_TESTBED_get_next_op_id (struct GNUNET_TESTBED_Controller *controller) +GNUNET_TESTBED_get_next_op_id(struct GNUNET_TESTBED_Controller *controller) { uint64_t op_id; - op_id = (uint64_t) GNUNET_TESTBED_host_get_id_ (controller->host); + op_id = (uint64_t)GNUNET_TESTBED_host_get_id_(controller->host); op_id = op_id << 32; - op_id |= (uint64_t) controller->operation_counter++; + op_id |= (uint64_t)controller->operation_counter++; return op_id; } @@ -2192,17 +2215,17 @@ GNUNET_TESTBED_get_next_op_id (struct GNUNET_TESTBED_Controller *controller) * @param cls the closure from GNUNET_TESTBED_operation_create_() */ static void -opstart_shutdown_peers (void *cls) +opstart_shutdown_peers(void *cls) { struct OperationContext *opc = cls; struct GNUNET_MQ_Envelope *env; struct GNUNET_TESTBED_ShutdownPeersMessage *msg; opc->state = OPC_STATE_STARTED; - env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS); - msg->operation_id = GNUNET_htonll (opc->id); - GNUNET_TESTBED_insert_opc_ (opc->c, opc); - GNUNET_MQ_send (opc->c->mq, env); + env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS); + msg->operation_id = GNUNET_htonll(opc->id); + GNUNET_TESTBED_insert_opc_(opc->c, opc); + GNUNET_MQ_send(opc->c->mq, env); } @@ -2212,22 +2235,24 @@ opstart_shutdown_peers (void *cls) * @param cls the closure from GNUNET_TESTBED_operation_create_() */ static void -oprelease_shutdown_peers (void *cls) +oprelease_shutdown_peers(void *cls) { struct OperationContext *opc = cls; switch (opc->state) - { - case OPC_STATE_STARTED: - GNUNET_TESTBED_remove_opc_ (opc->c, opc); + { + case OPC_STATE_STARTED: + GNUNET_TESTBED_remove_opc_(opc->c, opc); + /* no break; continue */ - case OPC_STATE_INIT: - GNUNET_free (opc->data); - break; - case OPC_STATE_FINISHED: - break; - } - GNUNET_free (opc); + case OPC_STATE_INIT: + GNUNET_free(opc->data); + break; + + case OPC_STATE_FINISHED: + break; + } + GNUNET_free(opc); } @@ -2247,32 +2272,32 @@ oprelease_shutdown_peers (void *cls) * present */ struct GNUNET_TESTBED_Operation * -GNUNET_TESTBED_shutdown_peers (struct GNUNET_TESTBED_Controller *c, - void *op_cls, - GNUNET_TESTBED_OperationCompletionCallback cb, - void *cb_cls) +GNUNET_TESTBED_shutdown_peers(struct GNUNET_TESTBED_Controller *c, + void *op_cls, + GNUNET_TESTBED_OperationCompletionCallback cb, + void *cb_cls) { struct OperationContext *opc; struct ShutdownPeersData *data; - if (0 != GNUNET_CONTAINER_multihashmap32_size (c->opc_map)) + if (0 != GNUNET_CONTAINER_multihashmap32_size(c->opc_map)) return NULL; - data = GNUNET_new (struct ShutdownPeersData); + data = GNUNET_new(struct ShutdownPeersData); data->cb = cb; data->cb_cls = cb_cls; - opc = GNUNET_new (struct OperationContext); + opc = GNUNET_new(struct OperationContext); opc->c = c; opc->op_cls = op_cls; opc->data = data; - opc->id = GNUNET_TESTBED_get_next_op_id (c); + opc->id = GNUNET_TESTBED_get_next_op_id(c); opc->type = OP_SHUTDOWN_PEERS; opc->state = OPC_STATE_INIT; - opc->op = GNUNET_TESTBED_operation_create_ (opc, - &opstart_shutdown_peers, - &oprelease_shutdown_peers); - GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, - opc->op); - GNUNET_TESTBED_operation_begin_wait_ (opc->op); + opc->op = GNUNET_TESTBED_operation_create_(opc, + &opstart_shutdown_peers, + &oprelease_shutdown_peers); + GNUNET_TESTBED_operation_queue_insert_(opc->c->opq_parallel_operations, + opc->op); + GNUNET_TESTBED_operation_begin_wait_(opc->op); return opc->op; } @@ -2286,7 +2311,7 @@ GNUNET_TESTBED_shutdown_peers (struct GNUNET_TESTBED_Controller *c, * @return The peer's unique ID. */ uint32_t -GNUNET_TESTBED_get_index (const struct GNUNET_TESTBED_Peer *peer) +GNUNET_TESTBED_get_index(const struct GNUNET_TESTBED_Peer *peer) { return peer->unique_id; } @@ -2299,22 +2324,22 @@ GNUNET_TESTBED_get_index (const struct GNUNET_TESTBED_Peer *peer) * @param barrier the barrier to remove */ void -GNUNET_TESTBED_barrier_remove_ (struct GNUNET_TESTBED_Barrier *barrier) +GNUNET_TESTBED_barrier_remove_(struct GNUNET_TESTBED_Barrier *barrier) { struct GNUNET_TESTBED_Controller *c = barrier->c; - GNUNET_assert (NULL != c->barrier_map); /* No barriers present */ - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_remove (c->barrier_map, - &barrier->key, - barrier)); - GNUNET_free (barrier->name); - GNUNET_free (barrier); - if (0 == GNUNET_CONTAINER_multihashmap_size (c->barrier_map)) - { - GNUNET_CONTAINER_multihashmap_destroy (c->barrier_map); - c->barrier_map = NULL; - } + GNUNET_assert(NULL != c->barrier_map); /* No barriers present */ + GNUNET_assert(GNUNET_OK == + GNUNET_CONTAINER_multihashmap_remove(c->barrier_map, + &barrier->key, + barrier)); + GNUNET_free(barrier->name); + GNUNET_free(barrier); + if (0 == GNUNET_CONTAINER_multihashmap_size(c->barrier_map)) + { + GNUNET_CONTAINER_multihashmap_destroy(c->barrier_map); + c->barrier_map = NULL; + } } @@ -2335,12 +2360,12 @@ GNUNET_TESTBED_barrier_remove_ (struct GNUNET_TESTBED_Barrier *barrier) * @return barrier handle; NULL upon error */ struct GNUNET_TESTBED_Barrier * -GNUNET_TESTBED_barrier_init_ (struct GNUNET_TESTBED_Controller *controller, - const char *name, - unsigned int quorum, - GNUNET_TESTBED_barrier_status_cb cb, - void *cls, - int echo) +GNUNET_TESTBED_barrier_init_(struct GNUNET_TESTBED_Controller *controller, + const char *name, + unsigned int quorum, + GNUNET_TESTBED_barrier_status_cb cb, + void *cls, + int echo) { struct GNUNET_TESTBED_BarrierInit *msg; struct GNUNET_MQ_Envelope *env; @@ -2348,41 +2373,41 @@ GNUNET_TESTBED_barrier_init_ (struct GNUNET_TESTBED_Controller *controller, struct GNUNET_HashCode key; size_t name_len; - GNUNET_assert (quorum <= 100); - GNUNET_assert (NULL != cb); - name_len = strlen (name); - GNUNET_assert (0 < name_len); - GNUNET_CRYPTO_hash (name, name_len, &key); + GNUNET_assert(quorum <= 100); + GNUNET_assert(NULL != cb); + name_len = strlen(name); + GNUNET_assert(0 < name_len); + GNUNET_CRYPTO_hash(name, name_len, &key); if (NULL == controller->barrier_map) controller->barrier_map = - GNUNET_CONTAINER_multihashmap_create (3, GNUNET_YES); + GNUNET_CONTAINER_multihashmap_create(3, GNUNET_YES); if (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_contains (controller->barrier_map, &key)) - { - GNUNET_break (0); - return NULL; - } - LOG_DEBUG ("Initialising barrier `%s'\n", name); - barrier = GNUNET_new (struct GNUNET_TESTBED_Barrier); + GNUNET_CONTAINER_multihashmap_contains(controller->barrier_map, &key)) + { + GNUNET_break(0); + return NULL; + } + LOG_DEBUG("Initialising barrier `%s'\n", name); + barrier = GNUNET_new(struct GNUNET_TESTBED_Barrier); barrier->c = controller; - barrier->name = GNUNET_strdup (name); + barrier->name = GNUNET_strdup(name); barrier->cb = cb; barrier->cls = cls; barrier->echo = echo; - GNUNET_memcpy (&barrier->key, &key, sizeof (struct GNUNET_HashCode)); - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put ( - controller->barrier_map, - &barrier->key, - barrier, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); - - env = GNUNET_MQ_msg_extra (msg, - name_len, - GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT); - msg->quorum = (uint8_t) quorum; - GNUNET_memcpy (msg->name, barrier->name, name_len); - GNUNET_MQ_send (barrier->c->mq, env); + GNUNET_memcpy(&barrier->key, &key, sizeof(struct GNUNET_HashCode)); + GNUNET_assert(GNUNET_OK == + GNUNET_CONTAINER_multihashmap_put( + controller->barrier_map, + &barrier->key, + barrier, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); + + env = GNUNET_MQ_msg_extra(msg, + name_len, + GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT); + msg->quorum = (uint8_t)quorum; + GNUNET_memcpy(msg->name, barrier->name, name_len); + GNUNET_MQ_send(barrier->c->mq, env); return barrier; } @@ -2402,18 +2427,18 @@ GNUNET_TESTBED_barrier_init_ (struct GNUNET_TESTBED_Controller *controller, * @return barrier handle; NULL upon error */ struct GNUNET_TESTBED_Barrier * -GNUNET_TESTBED_barrier_init (struct GNUNET_TESTBED_Controller *controller, - const char *name, - unsigned int quorum, - GNUNET_TESTBED_barrier_status_cb cb, - void *cls) +GNUNET_TESTBED_barrier_init(struct GNUNET_TESTBED_Controller *controller, + const char *name, + unsigned int quorum, + GNUNET_TESTBED_barrier_status_cb cb, + void *cls) { - return GNUNET_TESTBED_barrier_init_ (controller, - name, - quorum, - cb, - cls, - GNUNET_YES); + return GNUNET_TESTBED_barrier_init_(controller, + name, + quorum, + cb, + cls, + GNUNET_YES); } @@ -2423,18 +2448,18 @@ GNUNET_TESTBED_barrier_init (struct GNUNET_TESTBED_Controller *controller, * @param barrier the barrier handle */ void -GNUNET_TESTBED_barrier_cancel (struct GNUNET_TESTBED_Barrier *barrier) +GNUNET_TESTBED_barrier_cancel(struct GNUNET_TESTBED_Barrier *barrier) { struct GNUNET_MQ_Envelope *env; struct GNUNET_TESTBED_BarrierCancel *msg; size_t slen; - slen = strlen (barrier->name); + slen = strlen(barrier->name); env = - GNUNET_MQ_msg_extra (msg, slen, GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL); - GNUNET_memcpy (msg->name, barrier->name, slen); - GNUNET_MQ_send (barrier->c->mq, env); - GNUNET_TESTBED_barrier_remove_ (barrier); + GNUNET_MQ_msg_extra(msg, slen, GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL); + GNUNET_memcpy(msg->name, barrier->name, slen); + GNUNET_MQ_send(barrier->c->mq, env); + GNUNET_TESTBED_barrier_remove_(barrier); } diff --git a/src/testbed/testbed_api.h b/src/testbed/testbed_api.h index a9c2a0b71..c79c35a5e 100644 --- a/src/testbed/testbed_api.h +++ b/src/testbed/testbed_api.h @@ -11,7 +11,7 @@ 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 . @@ -41,31 +41,30 @@ /** * Enumeration of operations */ -enum OperationType -{ - /** - * Peer create operation - */ +enum OperationType { + /** + * Peer create operation + */ OP_PEER_CREATE, - /** - * Peer start operation - */ + /** + * Peer start operation + */ OP_PEER_START, - /** - * Peer stop operation - */ + /** + * Peer stop operation + */ OP_PEER_STOP, - /** - * Peer destroy operation - */ + /** + * Peer destroy operation + */ OP_PEER_DESTROY, - /** - * Get peer information operation - */ + /** + * Get peer information operation + */ OP_PEER_INFO, /** @@ -73,19 +72,19 @@ enum OperationType */ OP_PEER_RECONFIGURE, - /** - * Overlay connection operation - */ + /** + * Overlay connection operation + */ OP_OVERLAY_CONNECT, - /** - * Forwarded operation - */ + /** + * Forwarded operation + */ OP_FORWARDED, - /** - * Link controllers operation - */ + /** + * Link controllers operation + */ OP_LINK_CONTROLLERS, /** @@ -109,8 +108,7 @@ enum OperationType /** * Enumeration of states of OperationContext */ -enum OperationContextState -{ +enum OperationContextState { /** * The initial state where the associated operation has just been created * and is waiting in the operation queues to be started @@ -134,8 +132,7 @@ enum OperationContextState /** * Context information for GNUNET_TESTBED_Operation */ -struct OperationContext -{ +struct OperationContext { /** * The controller to which this operation context belongs to */ @@ -191,8 +188,7 @@ typedef void * controllers can interact with each other (in a P2P fashion); those * links are established via TCP/IP on the controller's service port. */ -struct GNUNET_TESTBED_Controller -{ +struct GNUNET_TESTBED_Controller { /** * The host where the controller is running */ @@ -269,15 +265,13 @@ struct GNUNET_TESTBED_Controller * The operation id counter. use current value and increment */ uint32_t operation_counter; - }; /** * Handle for barrier */ -struct GNUNET_TESTBED_Barrier -{ +struct GNUNET_TESTBED_Barrier { /** * hashcode identifying this barrier in the hashmap */ @@ -319,8 +313,8 @@ struct GNUNET_TESTBED_Barrier * @deprecated */ void -GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller, - struct GNUNET_MessageHeader *msg); +GNUNET_TESTBED_queue_message_(struct GNUNET_TESTBED_Controller *controller, + struct GNUNET_MessageHeader *msg); /** @@ -332,8 +326,8 @@ GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller, * @param opc the operation context to be inserted */ void -GNUNET_TESTBED_insert_opc_ (struct GNUNET_TESTBED_Controller *c, - struct OperationContext *opc); +GNUNET_TESTBED_insert_opc_(struct GNUNET_TESTBED_Controller *c, + struct OperationContext *opc); /** @@ -344,8 +338,8 @@ GNUNET_TESTBED_insert_opc_ (struct GNUNET_TESTBED_Controller *c, * @param opc the operation context to remove */ void -GNUNET_TESTBED_remove_opc_ (const struct GNUNET_TESTBED_Controller *c, - struct OperationContext *opc); +GNUNET_TESTBED_remove_opc_(const struct GNUNET_TESTBED_Controller *c, + struct OperationContext *opc); /** @@ -358,9 +352,9 @@ GNUNET_TESTBED_remove_opc_ (const struct GNUNET_TESTBED_Controller *c, * @return the size of the xconfig */ size_t -GNUNET_TESTBED_compress_config_ (const char *config, - size_t size, - char **xconfig); +GNUNET_TESTBED_compress_config_(const char *config, + size_t size, + char **xconfig); /** @@ -373,9 +367,9 @@ GNUNET_TESTBED_compress_config_ (const char *config, * @return the serialized and compressed configuration */ char * -GNUNET_TESTBED_compress_cfg_ (const struct GNUNET_CONFIGURATION_Handle *cfg, - size_t *size, - size_t *xsize); +GNUNET_TESTBED_compress_cfg_(const struct GNUNET_CONFIGURATION_Handle *cfg, + size_t *size, + size_t *xsize); /** @@ -392,9 +386,9 @@ GNUNET_TESTBED_compress_cfg_ (const struct GNUNET_CONFIGURATION_Handle *cfg, * @return the initialization message */ struct GNUNET_TESTBED_HelperInit * -GNUNET_TESTBED_create_helper_init_msg_ (const char *cname, - const char *hostname, - const struct GNUNET_CONFIGURATION_Handle *cfg); +GNUNET_TESTBED_create_helper_init_msg_(const char *cname, + const char *hostname, + const struct GNUNET_CONFIGURATION_Handle *cfg); /** @@ -412,11 +406,11 @@ GNUNET_TESTBED_create_helper_init_msg_ (const char *cname, * operation */ struct OperationContext * -GNUNET_TESTBED_forward_operation_msg_ (struct GNUNET_TESTBED_Controller *controller, - uint64_t operation_id, - const struct GNUNET_MessageHeader *msg, - GNUNET_MQ_MessageCallback cc, - void *cc_cls); +GNUNET_TESTBED_forward_operation_msg_(struct GNUNET_TESTBED_Controller *controller, + uint64_t operation_id, + const struct GNUNET_MessageHeader *msg, + GNUNET_MQ_MessageCallback cc, + void *cc_cls); /** * Function to cancel an operation created by simply forwarding an operation @@ -425,7 +419,7 @@ GNUNET_TESTBED_forward_operation_msg_ (struct GNUNET_TESTBED_Controller *control * @param opc the operation context from GNUNET_TESTBED_forward_operation_msg_() */ void -GNUNET_TESTBED_forward_operation_msg_cancel_ (struct OperationContext *opc); +GNUNET_TESTBED_forward_operation_msg_cancel_(struct OperationContext *opc); /** @@ -438,7 +432,7 @@ GNUNET_TESTBED_forward_operation_msg_cancel_ (struct OperationContext *opc); * @return handle to the parsed configuration */ struct GNUNET_CONFIGURATION_Handle * -GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg); +GNUNET_TESTBED_extract_config_(const struct GNUNET_MessageHeader *msg); /** @@ -449,7 +443,7 @@ GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg); * @return the error message */ const char * -GNUNET_TESTBED_parse_error_string_ (const struct GNUNET_TESTBED_OperationFailureEventMessage *msg); +GNUNET_TESTBED_parse_error_string_(const struct GNUNET_TESTBED_OperationFailureEventMessage *msg); /** @@ -460,7 +454,7 @@ GNUNET_TESTBED_parse_error_string_ (const struct GNUNET_TESTBED_OperationFailure * @return the incremented operation id. */ uint64_t -GNUNET_TESTBED_get_next_op_id (struct GNUNET_TESTBED_Controller *controller); +GNUNET_TESTBED_get_next_op_id(struct GNUNET_TESTBED_Controller *controller); /** @@ -476,9 +470,9 @@ GNUNET_TESTBED_get_next_op_id (struct GNUNET_TESTBED_Controller *controller); * @return the operation handle; */ struct GNUNET_TESTBED_Operation * -GNUNET_TESTBED_get_slave_config_ (void *op_cls, - struct GNUNET_TESTBED_Controller *master, - uint32_t slave_host_id); +GNUNET_TESTBED_get_slave_config_(void *op_cls, + struct GNUNET_TESTBED_Controller *master, + uint32_t slave_host_id); @@ -499,12 +493,12 @@ GNUNET_TESTBED_get_slave_config_ (void *op_cls, * @return barrier handle; NULL upon error */ struct GNUNET_TESTBED_Barrier * -GNUNET_TESTBED_barrier_init_ (struct GNUNET_TESTBED_Controller *controller, - const char *name, - unsigned int quorum, - GNUNET_TESTBED_barrier_status_cb cb, - void *cls, - int echo); +GNUNET_TESTBED_barrier_init_(struct GNUNET_TESTBED_Controller *controller, + const char *name, + unsigned int quorum, + GNUNET_TESTBED_barrier_status_cb cb, + void *cls, + int echo); /** @@ -514,7 +508,7 @@ GNUNET_TESTBED_barrier_init_ (struct GNUNET_TESTBED_Controller *controller, * @param barrier the barrier to remove */ void -GNUNET_TESTBED_barrier_remove_ (struct GNUNET_TESTBED_Barrier *barrier); +GNUNET_TESTBED_barrier_remove_(struct GNUNET_TESTBED_Barrier *barrier); diff --git a/src/testbed/testbed_api_barriers.c b/src/testbed/testbed_api_barriers.c index f811b6381..7e38b4297 100644 --- a/src/testbed/testbed_api_barriers.c +++ b/src/testbed/testbed_api_barriers.c @@ -1,22 +1,22 @@ /* - This file is part of GNUnet. - Copyright (C) 2008--2013, 2016 GNUnet e.V. + This file is part of GNUnet. + Copyright (C) 2008--2013, 2016 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 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 . + 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/testbed_api_barriers.c @@ -31,20 +31,19 @@ * Logging shorthand */ #define LOG(type, ...) \ - GNUNET_log_from (type, "testbed-api-barriers", __VA_ARGS__); + GNUNET_log_from(type, "testbed-api-barriers", __VA_ARGS__); /** * Debug logging shorthand */ #define LOG_DEBUG(...) \ - LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__); + LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__); /** * Barrier wait handle */ -struct GNUNET_TESTBED_BarrierWaitHandle -{ +struct GNUNET_TESTBED_BarrierWaitHandle { /** * The name of the barrier */ @@ -81,8 +80,8 @@ struct GNUNET_TESTBED_BarrierWaitHandle * @return #GNUNET_OK if the message is well-formed. */ static int -check_status (void *cls, - const struct GNUNET_TESTBED_BarrierStatusMsg *msg) +check_status(void *cls, + const struct GNUNET_TESTBED_BarrierStatusMsg *msg) { /* FIXME: this fails to actually check that the message follows the protocol spec (0-terminations!). However, @@ -100,40 +99,43 @@ check_status (void *cls, * @param msg received message */ static void -handle_status (void *cls, - const struct GNUNET_TESTBED_BarrierStatusMsg *msg) +handle_status(void *cls, + const struct GNUNET_TESTBED_BarrierStatusMsg *msg) { struct GNUNET_TESTBED_BarrierWaitHandle *h = cls; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Got barrier status %d\n", - (int) ntohs (msg->status)); - switch (ntohs (msg->status)) - { - case GNUNET_TESTBED_BARRIERSTATUS_ERROR: - h->cb (h->cb_cls, - h->name, - GNUNET_SYSERR); - break; - case GNUNET_TESTBED_BARRIERSTATUS_INITIALISED: - h->cb (h->cb_cls, - h->name, - GNUNET_SYSERR); - GNUNET_break (0); - break; - case GNUNET_TESTBED_BARRIERSTATUS_CROSSED: - h->cb (h->cb_cls, - h->name, - GNUNET_OK); - break; - default: - GNUNET_break_op (0); - h->cb (h->cb_cls, - h->name, - GNUNET_SYSERR); - break; - } - GNUNET_TESTBED_barrier_wait_cancel (h); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Got barrier status %d\n", + (int)ntohs(msg->status)); + switch (ntohs(msg->status)) + { + case GNUNET_TESTBED_BARRIERSTATUS_ERROR: + h->cb(h->cb_cls, + h->name, + GNUNET_SYSERR); + break; + + case GNUNET_TESTBED_BARRIERSTATUS_INITIALISED: + h->cb(h->cb_cls, + h->name, + GNUNET_SYSERR); + GNUNET_break(0); + break; + + case GNUNET_TESTBED_BARRIERSTATUS_CROSSED: + h->cb(h->cb_cls, + h->name, + GNUNET_OK); + break; + + default: + GNUNET_break_op(0); + h->cb(h->cb_cls, + h->name, + GNUNET_SYSERR); + break; + } + GNUNET_TESTBED_barrier_wait_cancel(h); } @@ -146,15 +148,15 @@ handle_status (void *cls, * @param error error code */ static void -mq_error_handler (void *cls, - enum GNUNET_MQ_Error error) +mq_error_handler(void *cls, + enum GNUNET_MQ_Error error) { struct GNUNET_TESTBED_BarrierWaitHandle *h = cls; - h->cb (h->cb_cls, - h->name, - GNUNET_SYSERR); - GNUNET_TESTBED_barrier_wait_cancel (h); + h->cb(h->cb_cls, + h->name, + GNUNET_SYSERR); + GNUNET_TESTBED_barrier_wait_cancel(h); } @@ -170,72 +172,72 @@ mq_error_handler (void *cls, * anytime before the callback is called. NULL upon error. */ struct GNUNET_TESTBED_BarrierWaitHandle * -GNUNET_TESTBED_barrier_wait (const char *name, - GNUNET_TESTBED_barrier_wait_cb cb, - void *cb_cls) +GNUNET_TESTBED_barrier_wait(const char *name, + GNUNET_TESTBED_barrier_wait_cb cb, + void *cb_cls) { struct GNUNET_TESTBED_BarrierWaitHandle *h - = GNUNET_new (struct GNUNET_TESTBED_BarrierWaitHandle); + = GNUNET_new(struct GNUNET_TESTBED_BarrierWaitHandle); struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_var_size (status, - GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS, - struct GNUNET_TESTBED_BarrierStatusMsg, - h), - GNUNET_MQ_handler_end () + GNUNET_MQ_hd_var_size(status, + GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS, + struct GNUNET_TESTBED_BarrierStatusMsg, + h), + GNUNET_MQ_handler_end() }; struct GNUNET_MQ_Envelope *env; struct GNUNET_TESTBED_BarrierWait *msg; const char *cfg_filename; size_t name_len; - GNUNET_assert (NULL != cb); - cfg_filename = getenv (ENV_TESTBED_CONFIG); + GNUNET_assert(NULL != cb); + cfg_filename = getenv(ENV_TESTBED_CONFIG); if (NULL == cfg_filename) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - "Are you running under testbed?\n"); - GNUNET_free (h); - return NULL; - } - h->cfg = GNUNET_CONFIGURATION_create (); + { + LOG(GNUNET_ERROR_TYPE_ERROR, + "Are you running under testbed?\n"); + GNUNET_free(h); + return NULL; + } + h->cfg = GNUNET_CONFIGURATION_create(); if (GNUNET_OK != - GNUNET_CONFIGURATION_load (h->cfg, - cfg_filename)) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - "Unable to load configuration from file `%s'\n", - cfg_filename); - GNUNET_CONFIGURATION_destroy (h->cfg); - GNUNET_free (h); - return NULL; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Waiting on barrier `%s'\n", - name); - h->name = GNUNET_strdup (name); + GNUNET_CONFIGURATION_load(h->cfg, + cfg_filename)) + { + LOG(GNUNET_ERROR_TYPE_ERROR, + "Unable to load configuration from file `%s'\n", + cfg_filename); + GNUNET_CONFIGURATION_destroy(h->cfg); + GNUNET_free(h); + return NULL; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Waiting on barrier `%s'\n", + name); + h->name = GNUNET_strdup(name); h->cb = cb; h->cb_cls = cb_cls; - h->mq = GNUNET_CLIENT_connect (h->cfg, - "testbed-barrier", - handlers, - &mq_error_handler, - h); + h->mq = GNUNET_CLIENT_connect(h->cfg, + "testbed-barrier", + handlers, + &mq_error_handler, + h); if (NULL == h->mq) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - "Unable to connect to local testbed-barrier service\n"); - GNUNET_TESTBED_barrier_wait_cancel (h); - return NULL; - } - name_len = strlen (name); /* NOTE: unusual to not have 0-termination, change? */ - env = GNUNET_MQ_msg_extra (msg, - name_len, - GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT); - GNUNET_memcpy (msg->name, - name, - name_len); - GNUNET_MQ_send (h->mq, - env); + { + LOG(GNUNET_ERROR_TYPE_ERROR, + "Unable to connect to local testbed-barrier service\n"); + GNUNET_TESTBED_barrier_wait_cancel(h); + return NULL; + } + name_len = strlen(name); /* NOTE: unusual to not have 0-termination, change? */ + env = GNUNET_MQ_msg_extra(msg, + name_len, + GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT); + GNUNET_memcpy(msg->name, + name, + name_len); + GNUNET_MQ_send(h->mq, + env); return h; } @@ -246,16 +248,16 @@ GNUNET_TESTBED_barrier_wait (const char *name, * @param h the barrier wait handle */ void -GNUNET_TESTBED_barrier_wait_cancel (struct GNUNET_TESTBED_BarrierWaitHandle *h) +GNUNET_TESTBED_barrier_wait_cancel(struct GNUNET_TESTBED_BarrierWaitHandle *h) { if (NULL != h->mq) - { - GNUNET_MQ_destroy (h->mq); - h->mq = NULL; - } - GNUNET_free (h->name); - GNUNET_CONFIGURATION_destroy (h->cfg); - GNUNET_free (h); + { + GNUNET_MQ_destroy(h->mq); + h->mq = NULL; + } + GNUNET_free(h->name); + GNUNET_CONFIGURATION_destroy(h->cfg); + GNUNET_free(h); } /* end of testbed_api_barriers.c */ diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c index e824a5f23..cbcfe1a18 100644 --- a/src/testbed/testbed_api_hosts.c +++ b/src/testbed/testbed_api_hosts.c @@ -11,7 +11,7 @@ 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 . @@ -42,24 +42,24 @@ /** * Generic logging shorthand */ -#define LOG(kind, ...) GNUNET_log_from (kind, "testbed-api-hosts", __VA_ARGS__); +#define LOG(kind, ...) GNUNET_log_from(kind, "testbed-api-hosts", __VA_ARGS__); /** * Debug logging shorthand */ -#define LOG_DEBUG(...) LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__); +#define LOG_DEBUG(...) LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__); /** * Prints API violation message */ #define API_VIOLATION(cond, errstr) \ do \ - { \ - if (cond) \ + { \ + if (cond) \ break; \ - LOG (GNUNET_ERROR_TYPE_ERROR, "API violation detected: %s\n", errstr); \ - GNUNET_assert (0); \ - } while (0) + LOG (GNUNET_ERROR_TYPE_ERROR, "API violation detected: %s\n", errstr); \ + GNUNET_assert(0); \ + } while (0) /** * Log an error message at log-level 'level' that indicates a failure of the @@ -67,14 +67,14 @@ */ #define LOG_GAI(level, cmd, rc) \ do \ - { \ - LOG (level, \ - _ ("`%s' failed at %s:%d with error: %s\n"), \ - cmd, \ - __FILE__, \ - __LINE__, \ - gai_strerror (rc)); \ - } while (0) + { \ + LOG(level, \ + _("`%s' failed at %s:%d with error: %s\n"), \ + cmd, \ + __FILE__, \ + __LINE__, \ + gai_strerror(rc)); \ + } while (0) /** * Number of extra elements we create space for when we grow host list @@ -85,8 +85,7 @@ /** * A list entry for registered controllers list */ -struct RegisteredController -{ +struct RegisteredController { /** * The controller at which this host is registered */ @@ -109,9 +108,7 @@ struct RegisteredController * The master process must be able to SSH to this host without password (via * ssh-agent). */ -struct GNUNET_TESTBED_Host -{ - +struct GNUNET_TESTBED_Host { /** * The hostname of the host; NULL for localhost */ @@ -187,7 +184,7 @@ static unsigned int host_list_size; * @return handle to the host, NULL if host not found */ struct GNUNET_TESTBED_Host * -GNUNET_TESTBED_host_lookup_by_id_ (uint32_t id) +GNUNET_TESTBED_host_lookup_by_id_(uint32_t id) { if (host_list_size <= id) return NULL; @@ -208,11 +205,11 @@ GNUNET_TESTBED_host_lookup_by_id_ (uint32_t id) * @return handle to the host, NULL on error */ struct GNUNET_TESTBED_Host * -GNUNET_TESTBED_host_create_by_id_ ( +GNUNET_TESTBED_host_create_by_id_( uint32_t id, const struct GNUNET_CONFIGURATION_Handle *cfg) { - return GNUNET_TESTBED_host_create_with_id (id, NULL, NULL, cfg, 0); + return GNUNET_TESTBED_host_create_with_id(id, NULL, NULL, cfg, 0); } @@ -224,7 +221,7 @@ GNUNET_TESTBED_host_create_by_id_ ( * 'localhost', but then obviously not globally unique) */ uint32_t -GNUNET_TESTBED_host_get_id_ (const struct GNUNET_TESTBED_Host *host) +GNUNET_TESTBED_host_get_id_(const struct GNUNET_TESTBED_Host *host) { return host->id; } @@ -237,7 +234,7 @@ GNUNET_TESTBED_host_get_id_ (const struct GNUNET_TESTBED_Host *host) * @return hostname of the host */ const char * -GNUNET_TESTBED_host_get_hostname (const struct GNUNET_TESTBED_Host *host) +GNUNET_TESTBED_host_get_hostname(const struct GNUNET_TESTBED_Host *host) { return host->hostname; } @@ -250,7 +247,7 @@ GNUNET_TESTBED_host_get_hostname (const struct GNUNET_TESTBED_Host *host) * @return username to login to the host */ const char * -GNUNET_TESTBED_host_get_username_ (const struct GNUNET_TESTBED_Host *host) +GNUNET_TESTBED_host_get_username_(const struct GNUNET_TESTBED_Host *host) { return host->username; } @@ -263,7 +260,7 @@ GNUNET_TESTBED_host_get_username_ (const struct GNUNET_TESTBED_Host *host) * @return username to login to the host */ uint16_t -GNUNET_TESTBED_host_get_ssh_port_ (const struct GNUNET_TESTBED_Host *host) +GNUNET_TESTBED_host_get_ssh_port_(const struct GNUNET_TESTBED_Host *host) { return host->port; } @@ -276,7 +273,7 @@ GNUNET_TESTBED_host_get_ssh_port_ (const struct GNUNET_TESTBED_Host *host) * @return GNUNET_YES if the controller is already started; GNUNET_NO if not */ int -GNUNET_TESTBED_host_controller_started (const struct GNUNET_TESTBED_Host *host) +GNUNET_TESTBED_host_controller_started(const struct GNUNET_TESTBED_Host *host) { return host->controller_started; } @@ -289,7 +286,7 @@ GNUNET_TESTBED_host_controller_started (const struct GNUNET_TESTBED_Host *host) * @return the host's configuration template */ const struct GNUNET_CONFIGURATION_Handle * -GNUNET_TESTBED_host_get_cfg_ (const struct GNUNET_TESTBED_Host *host) +GNUNET_TESTBED_host_get_cfg_(const struct GNUNET_TESTBED_Host *host) { return host->cfg; } @@ -302,12 +299,12 @@ GNUNET_TESTBED_host_get_cfg_ (const struct GNUNET_TESTBED_Host *host) * @param new_cfg the new configuration to replace the old one */ void -GNUNET_TESTBED_host_replace_cfg_ ( +GNUNET_TESTBED_host_replace_cfg_( struct GNUNET_TESTBED_Host *host, const struct GNUNET_CONFIGURATION_Handle *new_cfg) { - GNUNET_CONFIGURATION_destroy (host->cfg); - host->cfg = GNUNET_CONFIGURATION_dup (new_cfg); + GNUNET_CONFIGURATION_destroy(host->cfg); + host->cfg = GNUNET_CONFIGURATION_dup(new_cfg); } @@ -325,7 +322,7 @@ GNUNET_TESTBED_host_replace_cfg_ ( * @return handle to the host, NULL on error */ struct GNUNET_TESTBED_Host * -GNUNET_TESTBED_host_create_with_id ( +GNUNET_TESTBED_host_create_with_id( uint32_t id, const char *hostname, const char *username, @@ -336,26 +333,26 @@ GNUNET_TESTBED_host_create_with_id ( unsigned int new_size; if ((id < host_list_size) && (NULL != host_list[id])) - { - LOG (GNUNET_ERROR_TYPE_WARNING, "Host with id: %u already created\n", id); - return NULL; - } - host = GNUNET_new (struct GNUNET_TESTBED_Host); - host->hostname = (NULL != hostname) ? GNUNET_strdup (hostname) : NULL; - host->username = (NULL != username) ? GNUNET_strdup (username) : NULL; + { + LOG(GNUNET_ERROR_TYPE_WARNING, "Host with id: %u already created\n", id); + return NULL; + } + host = GNUNET_new(struct GNUNET_TESTBED_Host); + host->hostname = (NULL != hostname) ? GNUNET_strdup(hostname) : NULL; + host->username = (NULL != username) ? GNUNET_strdup(username) : NULL; host->id = id; host->port = (0 == port) ? 22 : port; - host->cfg = GNUNET_CONFIGURATION_dup (cfg); + host->cfg = GNUNET_CONFIGURATION_dup(cfg); host->opq_parallel_overlay_connect_operations = - GNUNET_TESTBED_operation_queue_create_ (OPERATION_QUEUE_TYPE_ADAPTIVE, - UINT_MAX); + GNUNET_TESTBED_operation_queue_create_(OPERATION_QUEUE_TYPE_ADAPTIVE, + UINT_MAX); new_size = host_list_size; while (id >= new_size) new_size += HOST_LIST_GROW_STEP; if (new_size != host_list_size) - GNUNET_array_grow (host_list, host_list_size, new_size); - GNUNET_assert (id < host_list_size); - LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding host with id: %u\n", host->id); + GNUNET_array_grow(host_list, host_list_size, new_size); + GNUNET_assert(id < host_list_size); + LOG(GNUNET_ERROR_TYPE_DEBUG, "Adding host with id: %u\n", host->id); host_list[id] = host; return host; } @@ -373,24 +370,24 @@ GNUNET_TESTBED_host_create_with_id ( * @return handle to the host, NULL on error */ struct GNUNET_TESTBED_Host * -GNUNET_TESTBED_host_create (const char *hostname, - const char *username, - const struct GNUNET_CONFIGURATION_Handle *cfg, - uint16_t port) +GNUNET_TESTBED_host_create(const char *hostname, + const char *username, + const struct GNUNET_CONFIGURATION_Handle *cfg, + uint16_t port) { static uint32_t uid_generator; if (NULL == hostname) - return GNUNET_TESTBED_host_create_with_id (0, - hostname, - username, - cfg, - port); - return GNUNET_TESTBED_host_create_with_id (++uid_generator, - hostname, - username, - cfg, - port); + return GNUNET_TESTBED_host_create_with_id(0, + hostname, + username, + cfg, + port); + return GNUNET_TESTBED_host_create_with_id(++uid_generator, + hostname, + username, + cfg, + port); } @@ -406,7 +403,7 @@ GNUNET_TESTBED_host_create (const char *hostname, * @return number of hosts returned in 'hosts', 0 on error */ unsigned int -GNUNET_TESTBED_hosts_load_from_file ( +GNUNET_TESTBED_hosts_load_from_file( const char *filename, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTBED_Host ***hosts) @@ -424,104 +421,104 @@ GNUNET_TESTBED_hosts_load_from_file ( unsigned int count; - GNUNET_assert (NULL != filename); - if (GNUNET_YES != GNUNET_DISK_file_test (filename)) - { - LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Hosts file %s not found\n"), filename); - return 0; - } + GNUNET_assert(NULL != filename); + if (GNUNET_YES != GNUNET_DISK_file_test(filename)) + { + LOG(GNUNET_ERROR_TYPE_WARNING, _("Hosts file %s not found\n"), filename); + return 0; + } if (GNUNET_OK != - GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES)) + GNUNET_DISK_file_size(filename, &fs, GNUNET_YES, GNUNET_YES)) fs = 0; if (0 == fs) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - _ ("Hosts file %s has no data\n"), - filename); - return 0; - } - data = GNUNET_malloc (fs); - if (fs != GNUNET_DISK_fn_read (filename, data, fs)) - { - GNUNET_free (data); - LOG (GNUNET_ERROR_TYPE_WARNING, - _ ("Hosts file %s cannot be read\n"), - filename); - return 0; - } + { + LOG(GNUNET_ERROR_TYPE_WARNING, + _("Hosts file %s has no data\n"), + filename); + return 0; + } + data = GNUNET_malloc(fs); + if (fs != GNUNET_DISK_fn_read(filename, data, fs)) + { + GNUNET_free(data); + LOG(GNUNET_ERROR_TYPE_WARNING, + _("Hosts file %s cannot be read\n"), + filename); + return 0; + } buf = data; offset = 0; starting_host = NULL; count = 0; /* refer RFC 952 and RFC 1123 for valid hostnames */ - GNUNET_assert (0 == regcomp (&rex, - "^(([[:alnum:]]+)@)?" /* username */ - "([[:alnum:]]+[-[:alnum:]_\\.]+)" /* hostname */ - "(:([[:digit:]]{1,5}))?", /* port */ - REG_EXTENDED | REG_ICASE)); + GNUNET_assert(0 == regcomp(&rex, + "^(([[:alnum:]]+)@)?" /* username */ + "([[:alnum:]]+[-[:alnum:]_\\.]+)" /* hostname */ + "(:([[:digit:]]{1,5}))?", /* port */ + REG_EXTENDED | REG_ICASE)); while (offset < (fs - 1)) - { - offset++; - if (((data[offset] == '\n')) && (buf != &data[offset])) { - unsigned int size; - - data[offset] = '\0'; - username = NULL; - hostname = NULL; - port = 0; - if ((REG_NOMATCH == regexec (&rex, buf, 6, pmatch, 0)) || - (-1 == pmatch[3].rm_so)) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Error reading line `%s' in hostfile\n", - buf); + offset++; + if (((data[offset] == '\n')) && (buf != &data[offset])) + { + unsigned int size; + + data[offset] = '\0'; + username = NULL; + hostname = NULL; + port = 0; + if ((REG_NOMATCH == regexec(&rex, buf, 6, pmatch, 0)) || + (-1 == pmatch[3].rm_so)) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + "Error reading line `%s' in hostfile\n", + buf); + buf = &data[offset + 1]; + continue; + } + if (-1 != pmatch[2].rm_so) + { + size = pmatch[2].rm_eo - pmatch[2].rm_so; + username = GNUNET_malloc(size + 1); + GNUNET_assert( + 0 != GNUNET_strlcpy(username, buf + pmatch[2].rm_so, size + 1)); + } + if (-1 != pmatch[5].rm_so) + { + (void)sscanf(buf + pmatch[5].rm_so, "%5hd", &port); + } + size = pmatch[3].rm_eo - pmatch[3].rm_so; + hostname = GNUNET_malloc(size + 1); + GNUNET_assert( + 0 != GNUNET_strlcpy(hostname, buf + pmatch[3].rm_so, size + 1)); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Successfully read host %s, port %d and user %s from file\n", + (NULL == hostname) ? "NULL" : hostname, + port, + (NULL == username) ? "NULL" : username); + /* We store hosts in a static list; hence we only require the starting + * host pointer in that list to access the newly created list of hosts */ + if (NULL == starting_host) + starting_host = + GNUNET_TESTBED_host_create(hostname, username, cfg, port); + else + (void)GNUNET_TESTBED_host_create(hostname, username, cfg, port); + count++; + GNUNET_free_non_null(username); + GNUNET_free(hostname); + buf = &data[offset + 1]; + } + else if ((data[offset] == '\n') || (data[offset] == '\0')) buf = &data[offset + 1]; - continue; - } - if (-1 != pmatch[2].rm_so) - { - size = pmatch[2].rm_eo - pmatch[2].rm_so; - username = GNUNET_malloc (size + 1); - GNUNET_assert ( - 0 != GNUNET_strlcpy (username, buf + pmatch[2].rm_so, size + 1)); - } - if (-1 != pmatch[5].rm_so) - { - (void) sscanf (buf + pmatch[5].rm_so, "%5hd", &port); - } - size = pmatch[3].rm_eo - pmatch[3].rm_so; - hostname = GNUNET_malloc (size + 1); - GNUNET_assert ( - 0 != GNUNET_strlcpy (hostname, buf + pmatch[3].rm_so, size + 1)); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Successfully read host %s, port %d and user %s from file\n", - (NULL == hostname) ? "NULL" : hostname, - port, - (NULL == username) ? "NULL" : username); - /* We store hosts in a static list; hence we only require the starting - * host pointer in that list to access the newly created list of hosts */ - if (NULL == starting_host) - starting_host = - GNUNET_TESTBED_host_create (hostname, username, cfg, port); - else - (void) GNUNET_TESTBED_host_create (hostname, username, cfg, port); - count++; - GNUNET_free_non_null (username); - GNUNET_free (hostname); - buf = &data[offset + 1]; } - else if ((data[offset] == '\n') || (data[offset] == '\0')) - buf = &data[offset + 1]; - } - regfree (&rex); - GNUNET_free (data); + regfree(&rex); + GNUNET_free(data); if (NULL == starting_host) return 0; - *hosts = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Host *) * count); - GNUNET_memcpy (*hosts, - &host_list[GNUNET_TESTBED_host_get_id_ (starting_host)], - sizeof (struct GNUNET_TESTBED_Host *) * count); + *hosts = GNUNET_malloc(sizeof(struct GNUNET_TESTBED_Host *) * count); + GNUNET_memcpy(*hosts, + &host_list[GNUNET_TESTBED_host_get_id_(starting_host)], + sizeof(struct GNUNET_TESTBED_Host *) * count); return count; } @@ -533,7 +530,7 @@ GNUNET_TESTBED_hosts_load_from_file ( * @return the string representing the IPv4 address of the given host; NULL upon error */ const char * -simple_resolve (const char *host) +simple_resolve(const char *host) { struct addrinfo *res; const struct sockaddr_in *in_addr; @@ -550,20 +547,20 @@ simple_resolve (const char *host) hint.ai_next = NULL; hint.ai_flags = AI_NUMERICSERV; res = NULL; - LOG_DEBUG ("Resolving [%s]\n", host); - if (0 != (rc = getaddrinfo (host, "22", &hint, &res))) - { - LOG_GAI (GNUNET_ERROR_TYPE_ERROR, "getaddrinfo", rc); - return NULL; - } - GNUNET_assert (NULL != res); - GNUNET_assert (NULL != res->ai_addr); - GNUNET_assert (sizeof (struct sockaddr_in) == res->ai_addrlen); - in_addr = (const struct sockaddr_in *) res->ai_addr; - hostip = inet_ntoa (in_addr->sin_addr); - GNUNET_assert (NULL != hostip); - freeaddrinfo (res); - LOG_DEBUG ("Resolved [%s] to [%s]\n", host, hostip); + LOG_DEBUG("Resolving [%s]\n", host); + if (0 != (rc = getaddrinfo(host, "22", &hint, &res))) + { + LOG_GAI(GNUNET_ERROR_TYPE_ERROR, "getaddrinfo", rc); + return NULL; + } + GNUNET_assert(NULL != res); + GNUNET_assert(NULL != res->ai_addr); + GNUNET_assert(sizeof(struct sockaddr_in) == res->ai_addrlen); + in_addr = (const struct sockaddr_in *)res->ai_addr; + hostip = inet_ntoa(in_addr->sin_addr); + GNUNET_assert(NULL != hostip); + freeaddrinfo(res); + LOG_DEBUG("Resolved [%s] to [%s]\n", host, hostip); return hostip; } @@ -581,24 +578,24 @@ simple_resolve (const char *host) * @return number of hosts returned in 'hosts', 0 on error */ unsigned int -GNUNET_TESTBED_hosts_load_from_loadleveler ( +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); +#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); + if (NULL == (hostfile = getenv("MP_SAVEHOSTFILE"))) + { + GNUNET_break(0); + return 0; + } + return GNUNET_TESTBED_hosts_load_from_file(hostfile, cfg, hosts); #endif } @@ -610,41 +607,41 @@ GNUNET_TESTBED_hosts_load_from_loadleveler ( * @param host handle to destroy */ void -GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host) +GNUNET_TESTBED_host_destroy(struct GNUNET_TESTBED_Host *host) { struct RegisteredController *rc; uint32_t id; - GNUNET_assert (host->id < host_list_size); - GNUNET_assert (host_list[host->id] == host); + GNUNET_assert(host->id < host_list_size); + GNUNET_assert(host_list[host->id] == host); host_list[host->id] = NULL; /* clear registered controllers list */ for (rc = host->rc_head; NULL != rc; rc = host->rc_head) - { - GNUNET_CONTAINER_DLL_remove (host->rc_head, host->rc_tail, rc); - GNUNET_free (rc); - } - GNUNET_free_non_null ((char *) host->username); - GNUNET_free_non_null ((char *) host->hostname); - GNUNET_TESTBED_operation_queue_destroy_ ( + { + GNUNET_CONTAINER_DLL_remove(host->rc_head, host->rc_tail, rc); + GNUNET_free(rc); + } + GNUNET_free_non_null((char *)host->username); + GNUNET_free_non_null((char *)host->hostname); + GNUNET_TESTBED_operation_queue_destroy_( host->opq_parallel_overlay_connect_operations); - GNUNET_CONFIGURATION_destroy (host->cfg); - GNUNET_free (host); + GNUNET_CONFIGURATION_destroy(host->cfg); + GNUNET_free(host); while (host_list_size >= HOST_LIST_GROW_STEP) - { - for (id = host_list_size - 1; id > host_list_size - HOST_LIST_GROW_STEP; - id--) + { + for (id = host_list_size - 1; id > host_list_size - HOST_LIST_GROW_STEP; + id--) + if (NULL != host_list[id]) + break; + if (id != host_list_size - HOST_LIST_GROW_STEP) + break; if (NULL != host_list[id]) break; - if (id != host_list_size - HOST_LIST_GROW_STEP) - break; - if (NULL != host_list[id]) - break; - host_list_size -= HOST_LIST_GROW_STEP; - } + host_list_size -= HOST_LIST_GROW_STEP; + } host_list = - GNUNET_realloc (host_list, - sizeof (struct GNUNET_TESTBED_Host *) * host_list_size); + GNUNET_realloc(host_list, + sizeof(struct GNUNET_TESTBED_Host *) * host_list_size); } @@ -655,23 +652,23 @@ GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host) * @param controller the controller at which this host is registered */ void -GNUNET_TESTBED_mark_host_registered_at_ ( +GNUNET_TESTBED_mark_host_registered_at_( struct GNUNET_TESTBED_Host *host, const struct GNUNET_TESTBED_Controller *const controller) { struct RegisteredController *rc; for (rc = host->rc_head; NULL != rc; rc = rc->next) - { - if (controller == rc->controller) /* already registered at controller */ { - GNUNET_break (0); - return; + if (controller == rc->controller) /* already registered at controller */ + { + GNUNET_break(0); + return; + } } - } - rc = GNUNET_new (struct RegisteredController); + rc = GNUNET_new(struct RegisteredController); rc->controller = controller; - GNUNET_CONTAINER_DLL_insert_tail (host->rc_head, host->rc_tail, rc); + GNUNET_CONTAINER_DLL_insert_tail(host->rc_head, host->rc_tail, rc); } @@ -682,7 +679,7 @@ GNUNET_TESTBED_mark_host_registered_at_ ( * @param controller the controller at which this host has to be unmarked */ void -GNUNET_TESTBED_deregister_host_at_ ( +GNUNET_TESTBED_deregister_host_at_( struct GNUNET_TESTBED_Host *host, const struct GNUNET_TESTBED_Controller *const controller) { @@ -692,12 +689,12 @@ GNUNET_TESTBED_deregister_host_at_ ( if (controller == rc->controller) break; if (NULL == rc) - { - GNUNET_break (0); - return; - } - GNUNET_CONTAINER_DLL_remove (host->rc_head, host->rc_tail, rc); - GNUNET_free (rc); + { + GNUNET_break(0); + return; + } + GNUNET_CONTAINER_DLL_remove(host->rc_head, host->rc_tail, rc); + GNUNET_free(rc); } @@ -709,19 +706,19 @@ GNUNET_TESTBED_deregister_host_at_ ( * @return GNUNET_YES if registered; GNUNET_NO if not */ int -GNUNET_TESTBED_is_host_registered_ ( +GNUNET_TESTBED_is_host_registered_( const struct GNUNET_TESTBED_Host *host, const struct GNUNET_TESTBED_Controller *const controller) { struct RegisteredController *rc; for (rc = host->rc_head; NULL != rc; rc = rc->next) - { - if (controller == rc->controller) /* already registered at controller */ { - return GNUNET_YES; + if (controller == rc->controller) /* already registered at controller */ + { + return GNUNET_YES; + } } - } return GNUNET_NO; } @@ -729,8 +726,7 @@ GNUNET_TESTBED_is_host_registered_ ( /** * Handle for controller process */ -struct GNUNET_TESTBED_ControllerProc -{ +struct GNUNET_TESTBED_ControllerProc { /** * The process handle */ @@ -775,17 +771,17 @@ struct GNUNET_TESTBED_ControllerProc * @return the copied NULL terminated arguments */ static char ** -copy_argv (const char *const *argv) +copy_argv(const char *const *argv) { char **argv_dup; unsigned int argp; - GNUNET_assert (NULL != argv); + GNUNET_assert(NULL != argv); for (argp = 0; NULL != argv[argp]; argp++) ; - argv_dup = GNUNET_malloc (sizeof (char *) * (argp + 1)); + argv_dup = GNUNET_malloc(sizeof(char *) * (argp + 1)); for (argp = 0; NULL != argv[argp]; argp++) - argv_dup[argp] = GNUNET_strdup (argv[argp]); + argv_dup[argp] = GNUNET_strdup(argv[argp]); return argv_dup; } @@ -798,7 +794,7 @@ copy_argv (const char *const *argv) * @return the joined NULL terminated arguments */ static char ** -join_argv (const char *const *argv1, const char *const *argv2) +join_argv(const char *const *argv1, const char *const *argv2) { char **argvj; char *argv; @@ -808,16 +804,16 @@ join_argv (const char *const *argv1, const char *const *argv2) carg = 0; argvj = NULL; for (cnt = 0; NULL != argv1[cnt]; cnt++) - { - argv = GNUNET_strdup (argv1[cnt]); - GNUNET_array_append (argvj, carg, argv); - } + { + argv = GNUNET_strdup(argv1[cnt]); + GNUNET_array_append(argvj, carg, argv); + } for (cnt = 0; NULL != argv2[cnt]; cnt++) - { - argv = GNUNET_strdup (argv2[cnt]); - GNUNET_array_append (argvj, carg, argv); - } - GNUNET_array_append (argvj, carg, NULL); + { + argv = GNUNET_strdup(argv2[cnt]); + GNUNET_array_append(argvj, carg, argv); + } + GNUNET_array_append(argvj, carg, NULL); return argvj; } @@ -828,13 +824,13 @@ join_argv (const char *const *argv1, const char *const *argv2) * @param argv the NULL terminated list of arguments */ static void -free_argv (char **argv) +free_argv(char **argv) { unsigned int argp; for (argp = 0; NULL != argv[argp]; argp++) - GNUNET_free (argv[argp]); - GNUNET_free (argv); + GNUNET_free(argv[argp]); + GNUNET_free(argv); } @@ -853,20 +849,20 @@ free_argv (char **argv) * @return NULL terminated list of arguments */ static char ** -gen_rsh_args (const char *port, const char *hostname, const char *username) +gen_rsh_args(const char *port, const char *hostname, const char *username) { static const char *default_ssh_args[] = - {"ssh", - "-o", - "BatchMode=yes", - "-o", - "NoHostAuthenticationForLocalhost=yes", - "-o", - "StrictHostKeyChecking=no", - "-o", - "PasswordAuthentication=no", - "%h", - NULL}; + { "ssh", + "-o", + "BatchMode=yes", + "-o", + "NoHostAuthenticationForLocalhost=yes", + "-o", + "StrictHostKeyChecking=no", + "-o", + "PasswordAuthentication=no", + "%h", + NULL }; char **ssh_args; char *ssh_cmd; char *ssh_cmd_cp; @@ -876,48 +872,48 @@ gen_rsh_args (const char *port, const char *hostname, const char *username) unsigned int cnt; ssh_args = NULL; - if (NULL != (ssh_cmd = getenv ("GNUNET_TESTBED_RSH_CMD"))) - { - ssh_cmd = GNUNET_strdup (ssh_cmd); - ssh_cmd_cp = ssh_cmd; - for (size = 0; NULL != (arg = strtok (ssh_cmd, " ")); ssh_cmd = NULL) - GNUNET_array_append (ssh_args, size, GNUNET_strdup (arg)); - GNUNET_free (ssh_cmd_cp); - } + if (NULL != (ssh_cmd = getenv("GNUNET_TESTBED_RSH_CMD"))) + { + ssh_cmd = GNUNET_strdup(ssh_cmd); + ssh_cmd_cp = ssh_cmd; + for (size = 0; NULL != (arg = strtok(ssh_cmd, " ")); ssh_cmd = NULL) + GNUNET_array_append(ssh_args, size, GNUNET_strdup(arg)); + GNUNET_free(ssh_cmd_cp); + } else - { - ssh_args = copy_argv (default_ssh_args); - size = (sizeof (default_ssh_args)) / (sizeof (const char *)); - GNUNET_array_grow (ssh_args, size, size - 1); - } + { + ssh_args = copy_argv(default_ssh_args); + size = (sizeof(default_ssh_args)) / (sizeof(const char *)); + GNUNET_array_grow(ssh_args, size, size - 1); + } for (cnt = 0; cnt < size; cnt++) - { - arg = ssh_args[cnt]; - if ('%' != arg[0]) - continue; - switch (arg[1]) { - case 'p': - new_arg = port; - break; - - case 'u': - new_arg = username; - break; - - case 'h': - new_arg = hostname; - break; - - default: - continue; + arg = ssh_args[cnt]; + if ('%' != arg[0]) + continue; + switch (arg[1]) + { + case 'p': + new_arg = port; + break; + + case 'u': + new_arg = username; + break; + + case 'h': + new_arg = hostname; + break; + + default: + continue; + } + if (NULL == new_arg) + continue; + GNUNET_free(arg); + ssh_args[cnt] = GNUNET_strdup(new_arg); } - if (NULL == new_arg) - continue; - GNUNET_free (arg); - ssh_args[cnt] = GNUNET_strdup (new_arg); - } - GNUNET_array_append (ssh_args, size, NULL); + GNUNET_array_append(ssh_args, size, NULL); return ssh_args; } @@ -933,7 +929,7 @@ gen_rsh_args (const char *port, const char *hostname, const char *username) * @return NULL-terminated args */ static char ** -gen_rsh_suffix_args (const char *const *append_args) +gen_rsh_suffix_args(const char *const *append_args) { char **rshell_args; char *rshell_cmd; @@ -944,22 +940,22 @@ gen_rsh_suffix_args (const char *const *append_args) rshell_args = NULL; cnt = 0; - if (NULL != (rshell_cmd = getenv ("GNUNET_TESTBED_RSH_CMD_SUFFIX"))) - { - rshell_cmd = GNUNET_strdup (rshell_cmd); - rshell_cmd_cp = rshell_cmd; - for (; NULL != (arg = strtok (rshell_cmd, " ")); rshell_cmd = NULL) - GNUNET_array_append (rshell_args, cnt, GNUNET_strdup (arg)); - GNUNET_free (rshell_cmd_cp); - } + if (NULL != (rshell_cmd = getenv("GNUNET_TESTBED_RSH_CMD_SUFFIX"))) + { + rshell_cmd = GNUNET_strdup(rshell_cmd); + rshell_cmd_cp = rshell_cmd; + for (; NULL != (arg = strtok(rshell_cmd, " ")); rshell_cmd = NULL) + GNUNET_array_append(rshell_args, cnt, GNUNET_strdup(arg)); + GNUNET_free(rshell_cmd_cp); + } if (NULL != append_args) - { - for (append_cnt = 0; NULL != append_args[append_cnt]; append_cnt++) - GNUNET_array_append (rshell_args, - cnt, - GNUNET_strdup (append_args[append_cnt])); - } - GNUNET_array_append (rshell_args, cnt, NULL); + { + for (append_cnt = 0; NULL != append_args[append_cnt]; append_cnt++) + GNUNET_array_append(rshell_args, + cnt, + GNUNET_strdup(append_args[append_cnt])); + } + GNUNET_array_append(rshell_args, cnt, NULL); return rshell_args; } @@ -977,7 +973,7 @@ gen_rsh_suffix_args (const char *const *append_args) * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing */ static int -helper_mst (void *cls, const struct GNUNET_MessageHeader *message) +helper_mst(void *cls, const struct GNUNET_MessageHeader *message) { struct GNUNET_TESTBED_ControllerProc *cp = cls; const struct GNUNET_TESTBED_HelperReply *msg; @@ -986,38 +982,38 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message) uLongf config_size; uLongf xconfig_size; - msg = (const struct GNUNET_TESTBED_HelperReply *) message; - GNUNET_assert (sizeof (struct GNUNET_TESTBED_HelperReply) < - ntohs (msg->header.size)); - GNUNET_assert (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY == - ntohs (msg->header.type)); - config_size = (uLongf) ntohs (msg->config_size); - xconfig_size = (uLongf) (ntohs (msg->header.size) - - sizeof (struct GNUNET_TESTBED_HelperReply)); - config = GNUNET_malloc (config_size); - GNUNET_assert (Z_OK == uncompress ((Bytef *) config, - &config_size, - (const Bytef *) &msg[1], - xconfig_size)); + msg = (const struct GNUNET_TESTBED_HelperReply *)message; + GNUNET_assert(sizeof(struct GNUNET_TESTBED_HelperReply) < + ntohs(msg->header.size)); + GNUNET_assert(GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY == + ntohs(msg->header.type)); + config_size = (uLongf)ntohs(msg->config_size); + xconfig_size = (uLongf)(ntohs(msg->header.size) - + sizeof(struct GNUNET_TESTBED_HelperReply)); + config = GNUNET_malloc(config_size); + GNUNET_assert(Z_OK == uncompress((Bytef *)config, + &config_size, + (const Bytef *)&msg[1], + xconfig_size)); /* Replace the configuration template present in the host with the controller's running configuration */ - GNUNET_CONFIGURATION_destroy (cp->host->cfg); - cp->host->cfg = GNUNET_CONFIGURATION_create (); - GNUNET_assert (GNUNET_CONFIGURATION_deserialize (cp->host->cfg, - config, - config_size, - NULL)); - GNUNET_free (config); - if (NULL == (hostname = GNUNET_TESTBED_host_get_hostname (cp->host))) + GNUNET_CONFIGURATION_destroy(cp->host->cfg); + cp->host->cfg = GNUNET_CONFIGURATION_create(); + GNUNET_assert(GNUNET_CONFIGURATION_deserialize(cp->host->cfg, + config, + config_size, + NULL)); + GNUNET_free(config); + if (NULL == (hostname = GNUNET_TESTBED_host_get_hostname(cp->host))) hostname = "localhost"; /* Change the hostname so that we can connect to it */ - GNUNET_CONFIGURATION_set_value_string (cp->host->cfg, - "testbed", - "hostname", - hostname); + GNUNET_CONFIGURATION_set_value_string(cp->host->cfg, + "testbed", + "hostname", + hostname); cp->host->locked = GNUNET_NO; cp->host->controller_started = GNUNET_YES; - cp->cb (cp->cls, cp->host->cfg, GNUNET_OK); + cp->cb(cp->cls, cp->host->cfg, GNUNET_OK); return GNUNET_OK; } @@ -1031,13 +1027,13 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message) * GNUNET_SYSERR during GNUNET_HELPER_stop */ static void -clear_msg (void *cls, int result) +clear_msg(void *cls, int result) { struct GNUNET_TESTBED_ControllerProc *cp = cls; - GNUNET_assert (NULL != cp->shandle); + GNUNET_assert(NULL != cp->shandle); cp->shandle = NULL; - GNUNET_free (cp->msg); + GNUNET_free(cp->msg); cp->msg = NULL; } @@ -1049,7 +1045,7 @@ clear_msg (void *cls, int result) * @param cls the closure from GNUNET_HELPER_start() */ static void -helper_exp_cb (void *cls) +helper_exp_cb(void *cls) { struct GNUNET_TESTBED_ControllerProc *cp = cls; GNUNET_TESTBED_ControllerStatusCallback cb; @@ -1058,9 +1054,9 @@ helper_exp_cb (void *cls) cb = cp->cb; cb_cls = cp->cls; cp->helper = NULL; - GNUNET_TESTBED_controller_stop (cp); + GNUNET_TESTBED_controller_stop(cp); if (NULL != cb) - cb (cb_cls, NULL, GNUNET_SYSERR); + cb(cb_cls, NULL, GNUNET_SYSERR); } @@ -1088,106 +1084,106 @@ helper_exp_cb (void *cls) * @return the controller process handle, NULL on errors */ struct GNUNET_TESTBED_ControllerProc * -GNUNET_TESTBED_controller_start (const char *trusted_ip, - struct GNUNET_TESTBED_Host *host, - GNUNET_TESTBED_ControllerStatusCallback cb, - void *cls) +GNUNET_TESTBED_controller_start(const char *trusted_ip, + struct GNUNET_TESTBED_Host *host, + GNUNET_TESTBED_ControllerStatusCallback cb, + void *cls) { struct GNUNET_TESTBED_ControllerProc *cp; struct GNUNET_TESTBED_HelperInit *msg; const struct GNUNET_CONFIGURATION_Handle *cfg; const char *hostname; - static char *const binary_argv[] = {HELPER_TESTBED_BINARY, NULL}; + static char *const binary_argv[] = { HELPER_TESTBED_BINARY, NULL }; - GNUNET_assert (NULL != host); - GNUNET_assert (NULL != (cfg = GNUNET_TESTBED_host_get_cfg_ (host))); + GNUNET_assert(NULL != host); + GNUNET_assert(NULL != (cfg = GNUNET_TESTBED_host_get_cfg_(host))); hostname = NULL; - API_VIOLATION ( + API_VIOLATION( GNUNET_NO == host->locked, "Host is already locked by a previous call to GNUNET_TESTBED_controller_start()"); host->locked = GNUNET_YES; - API_VIOLATION ( + API_VIOLATION( GNUNET_NO == host->controller_started, "Attempting to start a controller on a host which is already started a controller"); - cp = GNUNET_new (struct GNUNET_TESTBED_ControllerProc); - if (0 == GNUNET_TESTBED_host_get_id_ (host)) - { - cp->helper = GNUNET_HELPER_start (GNUNET_YES, - HELPER_TESTBED_BINARY, - binary_argv, - &helper_mst, - &helper_exp_cb, - cp); - } + cp = GNUNET_new(struct GNUNET_TESTBED_ControllerProc); + if (0 == GNUNET_TESTBED_host_get_id_(host)) + { + cp->helper = GNUNET_HELPER_start(GNUNET_YES, + HELPER_TESTBED_BINARY, + binary_argv, + &helper_mst, + &helper_exp_cb, + cp); + } else - { - char *helper_binary_path_args[2]; - char **rsh_args; - char **rsh_suffix_args; - const char *username; - char *port; - char *argstr; - char *aux; - unsigned int cnt; - - username = host->username; - hostname = host->hostname; - GNUNET_asprintf (&port, "%u", host->port); - LOG_DEBUG ("Starting remote connection to destination %s\n", hostname); - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (cfg, - "testbed", - "HELPER_BINARY_PATH", - &helper_binary_path_args[0])) - helper_binary_path_args[0] = - GNUNET_OS_get_libexec_binary_path (HELPER_TESTBED_BINARY); - helper_binary_path_args[1] = NULL; - rsh_args = gen_rsh_args (port, hostname, username); - rsh_suffix_args = - gen_rsh_suffix_args ((const char **) helper_binary_path_args); - cp->helper_argv = - join_argv ((const char **) rsh_args, (const char **) rsh_suffix_args); - free_argv (rsh_args); - free_argv (rsh_suffix_args); - GNUNET_free (port); - argstr = GNUNET_strdup (""); - for (cnt = 0; NULL != cp->helper_argv[cnt]; cnt++) { - aux = argstr; - GNUNET_assert ( - 0 < GNUNET_asprintf (&argstr, "%s %s", aux, cp->helper_argv[cnt])); - GNUNET_free (aux); + char *helper_binary_path_args[2]; + char **rsh_args; + char **rsh_suffix_args; + const char *username; + char *port; + char *argstr; + char *aux; + unsigned int cnt; + + username = host->username; + hostname = host->hostname; + GNUNET_asprintf(&port, "%u", host->port); + LOG_DEBUG("Starting remote connection to destination %s\n", hostname); + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_filename(cfg, + "testbed", + "HELPER_BINARY_PATH", + &helper_binary_path_args[0])) + helper_binary_path_args[0] = + GNUNET_OS_get_libexec_binary_path(HELPER_TESTBED_BINARY); + helper_binary_path_args[1] = NULL; + rsh_args = gen_rsh_args(port, hostname, username); + rsh_suffix_args = + gen_rsh_suffix_args((const char **)helper_binary_path_args); + cp->helper_argv = + join_argv((const char **)rsh_args, (const char **)rsh_suffix_args); + free_argv(rsh_args); + free_argv(rsh_suffix_args); + GNUNET_free(port); + argstr = GNUNET_strdup(""); + for (cnt = 0; NULL != cp->helper_argv[cnt]; cnt++) + { + aux = argstr; + GNUNET_assert( + 0 < GNUNET_asprintf(&argstr, "%s %s", aux, cp->helper_argv[cnt])); + GNUNET_free(aux); + } + LOG_DEBUG("Helper cmd str: %s\n", argstr); + GNUNET_free(argstr); + cp->helper = GNUNET_HELPER_start(GNUNET_NO, + cp->helper_argv[0], + cp->helper_argv, + &helper_mst, + &helper_exp_cb, + cp); + GNUNET_free(helper_binary_path_args[0]); } - LOG_DEBUG ("Helper cmd str: %s\n", argstr); - GNUNET_free (argstr); - cp->helper = GNUNET_HELPER_start (GNUNET_NO, - cp->helper_argv[0], - cp->helper_argv, - &helper_mst, - &helper_exp_cb, - cp); - GNUNET_free (helper_binary_path_args[0]); - } if (NULL == cp->helper) - { - if (NULL != cp->helper_argv) - free_argv (cp->helper_argv); - GNUNET_free (cp); - return NULL; - } + { + if (NULL != cp->helper_argv) + free_argv(cp->helper_argv); + GNUNET_free(cp); + return NULL; + } cp->host = host; cp->cb = cb; cp->cls = cls; - msg = GNUNET_TESTBED_create_helper_init_msg_ (trusted_ip, hostname, cfg); + msg = GNUNET_TESTBED_create_helper_init_msg_(trusted_ip, hostname, cfg); cp->msg = &msg->header; cp->shandle = - GNUNET_HELPER_send (cp->helper, &msg->header, GNUNET_NO, &clear_msg, cp); + GNUNET_HELPER_send(cp->helper, &msg->header, GNUNET_NO, &clear_msg, cp); if (NULL == cp->shandle) - { - GNUNET_free (msg); - GNUNET_TESTBED_controller_stop (cp); - return NULL; - } + { + GNUNET_free(msg); + GNUNET_TESTBED_controller_stop(cp); + return NULL; + } return cp; } @@ -1198,12 +1194,12 @@ GNUNET_TESTBED_controller_start (const char *trusted_ip, * @param cproc the handle to the controller's helper process */ void -GNUNET_TESTBED_controller_kill_ (struct GNUNET_TESTBED_ControllerProc *cproc) +GNUNET_TESTBED_controller_kill_(struct GNUNET_TESTBED_ControllerProc *cproc) { if (NULL != cproc->shandle) - GNUNET_HELPER_send_cancel (cproc->shandle); + GNUNET_HELPER_send_cancel(cproc->shandle); if (NULL != cproc->helper) - GNUNET_HELPER_kill (cproc->helper, GNUNET_YES); + GNUNET_HELPER_kill(cproc->helper, GNUNET_YES); } @@ -1213,19 +1209,19 @@ GNUNET_TESTBED_controller_kill_ (struct GNUNET_TESTBED_ControllerProc *cproc) * @param cproc the handle to the controller's helper process */ void -GNUNET_TESTBED_controller_destroy_ (struct GNUNET_TESTBED_ControllerProc *cproc) +GNUNET_TESTBED_controller_destroy_(struct GNUNET_TESTBED_ControllerProc *cproc) { if (NULL != cproc->helper) - { - GNUNET_break (GNUNET_OK == GNUNET_HELPER_wait (cproc->helper)); - GNUNET_HELPER_destroy (cproc->helper); - } + { + GNUNET_break(GNUNET_OK == GNUNET_HELPER_wait(cproc->helper)); + GNUNET_HELPER_destroy(cproc->helper); + } if (NULL != cproc->helper_argv) - free_argv (cproc->helper_argv); + free_argv(cproc->helper_argv); cproc->host->controller_started = GNUNET_NO; cproc->host->locked = GNUNET_NO; - GNUNET_free_non_null (cproc->msg); - GNUNET_free (cproc); + GNUNET_free_non_null(cproc->msg); + GNUNET_free(cproc); } @@ -1238,18 +1234,17 @@ GNUNET_TESTBED_controller_destroy_ (struct GNUNET_TESTBED_ControllerProc *cproc) * @param cproc the controller process handle */ void -GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_ControllerProc *cproc) +GNUNET_TESTBED_controller_stop(struct GNUNET_TESTBED_ControllerProc *cproc) { - GNUNET_TESTBED_controller_kill_ (cproc); - GNUNET_TESTBED_controller_destroy_ (cproc); + GNUNET_TESTBED_controller_kill_(cproc); + GNUNET_TESTBED_controller_destroy_(cproc); } /** * The handle for whether a host is habitable or not */ -struct GNUNET_TESTBED_HostHabitableCheckHandle -{ +struct GNUNET_TESTBED_HostHabitableCheckHandle { /** * The host to check */ @@ -1294,7 +1289,7 @@ struct GNUNET_TESTBED_HostHabitableCheckHandle * @param cls GNUNET_TESTBED_HostHabitableCheckHandle */ static void -habitability_check (void *cls) +habitability_check(void *cls) { struct GNUNET_TESTBED_HostHabitableCheckHandle *h = cls; void *cb_cls; @@ -1305,34 +1300,34 @@ habitability_check (void *cls) int ret; h->habitability_check_task = NULL; - ret = GNUNET_OS_process_status (h->auxp, &type, &code); + ret = GNUNET_OS_process_status(h->auxp, &type, &code); if (GNUNET_SYSERR == ret) - { - GNUNET_break (0); - ret = GNUNET_NO; - goto call_cb; - } + { + GNUNET_break(0); + ret = GNUNET_NO; + goto call_cb; + } if (GNUNET_NO == ret) - { - h->wait_time = GNUNET_TIME_STD_BACKOFF (h->wait_time); - h->habitability_check_task = - GNUNET_SCHEDULER_add_delayed (h->wait_time, &habitability_check, h); - return; - } - GNUNET_OS_process_destroy (h->auxp); + { + h->wait_time = GNUNET_TIME_STD_BACKOFF(h->wait_time); + h->habitability_check_task = + GNUNET_SCHEDULER_add_delayed(h->wait_time, &habitability_check, h); + return; + } + GNUNET_OS_process_destroy(h->auxp); h->auxp = NULL; ret = (0 != code) ? GNUNET_NO : GNUNET_YES; call_cb: if (NULL != h->auxp) - GNUNET_OS_process_destroy (h->auxp); + GNUNET_OS_process_destroy(h->auxp); cb = h->cb; cb_cls = h->cb_cls; host = h->host; - free_argv (h->helper_argv); - GNUNET_free (h); + free_argv(h->helper_argv); + GNUNET_free(h); if (NULL != cb) - cb (cb_cls, host, ret); + cb(cb_cls, host, ret); } @@ -1348,7 +1343,7 @@ call_cb: * GNUNET_TESTBED_is_host_habitable_cancel() */ struct GNUNET_TESTBED_HostHabitableCheckHandle * -GNUNET_TESTBED_is_host_habitable ( +GNUNET_TESTBED_is_host_habitable( const struct GNUNET_TESTBED_Host *host, const struct GNUNET_CONFIGURATION_Handle *config, GNUNET_TESTBED_HostHabitableCallback cb, @@ -1361,45 +1356,45 @@ GNUNET_TESTBED_is_host_habitable ( const char *hostname; char *port; - h = GNUNET_new (struct GNUNET_TESTBED_HostHabitableCheckHandle); + h = GNUNET_new(struct GNUNET_TESTBED_HostHabitableCheckHandle); h->cb = cb; h->cb_cls = cb_cls; h->host = host; hostname = (NULL == host->hostname) ? "127.0.0.1" : host->hostname; if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (config, - "testbed", - "HELPER_BINARY_PATH", - &stat_args[1])) - stat_args[1] = GNUNET_OS_get_libexec_binary_path (HELPER_TESTBED_BINARY); - GNUNET_asprintf (&port, "%u", host->port); - rsh_args = gen_rsh_args (port, hostname, host->username); - GNUNET_free (port); + GNUNET_CONFIGURATION_get_value_filename(config, + "testbed", + "HELPER_BINARY_PATH", + &stat_args[1])) + stat_args[1] = GNUNET_OS_get_libexec_binary_path(HELPER_TESTBED_BINARY); + GNUNET_asprintf(&port, "%u", host->port); + rsh_args = gen_rsh_args(port, hostname, host->username); + GNUNET_free(port); port = NULL; stat_args[0] = "stat"; stat_args[2] = NULL; - rsh_suffix_args = gen_rsh_suffix_args ((const char **) stat_args); - GNUNET_free (stat_args[1]); + rsh_suffix_args = gen_rsh_suffix_args((const char **)stat_args); + GNUNET_free(stat_args[1]); h->helper_argv = - join_argv ((const char **) rsh_args, (const char **) rsh_suffix_args); - free_argv (rsh_suffix_args); - free_argv (rsh_args); - h->auxp = GNUNET_OS_start_process_vap (GNUNET_NO, - GNUNET_OS_INHERIT_STD_ERR, - NULL, - NULL, - NULL, - h->helper_argv[0], - h->helper_argv); + join_argv((const char **)rsh_args, (const char **)rsh_suffix_args); + free_argv(rsh_suffix_args); + free_argv(rsh_args); + h->auxp = GNUNET_OS_start_process_vap(GNUNET_NO, + GNUNET_OS_INHERIT_STD_ERR, + NULL, + NULL, + NULL, + h->helper_argv[0], + h->helper_argv); if (NULL == h->auxp) - { - GNUNET_break (0); /* Cannot exec SSH? */ - GNUNET_free (h); - return NULL; - } - h->wait_time = GNUNET_TIME_STD_BACKOFF (h->wait_time); + { + GNUNET_break(0); /* Cannot exec SSH? */ + GNUNET_free(h); + return NULL; + } + h->wait_time = GNUNET_TIME_STD_BACKOFF(h->wait_time); h->habitability_check_task = - GNUNET_SCHEDULER_add_delayed (h->wait_time, &habitability_check, h); + GNUNET_SCHEDULER_add_delayed(h->wait_time, &habitability_check, h); return h; } @@ -1410,15 +1405,15 @@ GNUNET_TESTBED_is_host_habitable ( * @param handle the habitability check handle */ void -GNUNET_TESTBED_is_host_habitable_cancel ( +GNUNET_TESTBED_is_host_habitable_cancel( struct GNUNET_TESTBED_HostHabitableCheckHandle *handle) { - GNUNET_SCHEDULER_cancel (handle->habitability_check_task); - (void) GNUNET_OS_process_kill (handle->auxp, GNUNET_TERM_SIG); - (void) GNUNET_OS_process_wait (handle->auxp); - GNUNET_OS_process_destroy (handle->auxp); - free_argv (handle->helper_argv); - GNUNET_free (handle); + GNUNET_SCHEDULER_cancel(handle->habitability_check_task); + (void)GNUNET_OS_process_kill(handle->auxp, GNUNET_TERM_SIG); + (void)GNUNET_OS_process_wait(handle->auxp); + GNUNET_OS_process_destroy(handle->auxp); + free_argv(handle->helper_argv); + GNUNET_free(handle); } @@ -1435,10 +1430,10 @@ GNUNET_TESTBED_is_host_habitable_cancel ( * registration */ struct GNUNET_TESTBED_HostRegistrationHandle * -GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller, - struct GNUNET_TESTBED_Host *host, - GNUNET_TESTBED_HostRegistrationCompletion cc, - void *cc_cls) +GNUNET_TESTBED_register_host(struct GNUNET_TESTBED_Controller *controller, + struct GNUNET_TESTBED_Host *host, + GNUNET_TESTBED_HostRegistrationCompletion cc, + void *cc_cls) { struct GNUNET_TESTBED_HostRegistrationHandle *rh; struct GNUNET_TESTBED_AddHostMessage *msg; @@ -1455,57 +1450,57 @@ GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller, if (NULL != controller->rh) return NULL; - hostname = GNUNET_TESTBED_host_get_hostname (host); - if (GNUNET_YES == GNUNET_TESTBED_is_host_registered_ (host, controller)) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - "Host hostname: %s already registered\n", - (NULL == hostname) ? "localhost" : hostname); - return NULL; - } - rh = GNUNET_new (struct GNUNET_TESTBED_HostRegistrationHandle); + hostname = GNUNET_TESTBED_host_get_hostname(host); + if (GNUNET_YES == GNUNET_TESTBED_is_host_registered_(host, controller)) + { + LOG(GNUNET_ERROR_TYPE_WARNING, + "Host hostname: %s already registered\n", + (NULL == hostname) ? "localhost" : hostname); + return NULL; + } + rh = GNUNET_new(struct GNUNET_TESTBED_HostRegistrationHandle); rh->host = host; rh->c = controller; - GNUNET_assert (NULL != cc); + GNUNET_assert(NULL != cc); rh->cc = cc; rh->cc_cls = cc_cls; controller->rh = rh; - username = GNUNET_TESTBED_host_get_username_ (host); + username = GNUNET_TESTBED_host_get_username_(host); username_length = 0; if (NULL != username) - username_length = strlen (username); - GNUNET_assert (NULL != hostname); /* Hostname must be present */ - hostname_length = strlen (hostname); - GNUNET_assert (NULL != host->cfg); - config = GNUNET_CONFIGURATION_serialize (host->cfg, &config_size); - cc_size = GNUNET_TESTBED_compress_config_ (config, config_size, &cconfig); - GNUNET_free (config); - msg_size = (sizeof (struct GNUNET_TESTBED_AddHostMessage)); + username_length = strlen(username); + GNUNET_assert(NULL != hostname); /* Hostname must be present */ + hostname_length = strlen(hostname); + GNUNET_assert(NULL != host->cfg); + config = GNUNET_CONFIGURATION_serialize(host->cfg, &config_size); + cc_size = GNUNET_TESTBED_compress_config_(config, config_size, &cconfig); + GNUNET_free(config); + msg_size = (sizeof(struct GNUNET_TESTBED_AddHostMessage)); msg_size += username_length; msg_size += hostname_length; msg_size += cc_size; - msg = GNUNET_malloc (msg_size); - msg->header.size = htons (msg_size); - msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST); - msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host)); - msg->ssh_port = htons (GNUNET_TESTBED_host_get_ssh_port_ (host)); + msg = GNUNET_malloc(msg_size); + msg->header.size = htons(msg_size); + msg->header.type = htons(GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST); + msg->host_id = htonl(GNUNET_TESTBED_host_get_id_(host)); + msg->ssh_port = htons(GNUNET_TESTBED_host_get_ssh_port_(host)); ptr = &msg[1]; if (NULL != username) - { - msg->username_length = htons (username_length); - GNUNET_memcpy (ptr, username, username_length); - ptr += username_length; - } - msg->hostname_length = htons (hostname_length); - GNUNET_memcpy (ptr, hostname, hostname_length); + { + msg->username_length = htons(username_length); + GNUNET_memcpy(ptr, username, username_length); + ptr += username_length; + } + msg->hostname_length = htons(hostname_length); + GNUNET_memcpy(ptr, hostname, hostname_length); ptr += hostname_length; - msg->config_size = htons (config_size); - GNUNET_memcpy (ptr, cconfig, cc_size); + msg->config_size = htons(config_size); + GNUNET_memcpy(ptr, cconfig, cc_size); ptr += cc_size; - GNUNET_assert ((ptr - (void *) msg) == msg_size); - GNUNET_free (cconfig); - GNUNET_TESTBED_queue_message_ (controller, - (struct GNUNET_MessageHeader *) msg); + GNUNET_assert((ptr - (void *)msg) == msg_size); + GNUNET_free(cconfig); + GNUNET_TESTBED_queue_message_(controller, + (struct GNUNET_MessageHeader *)msg); return rh; } @@ -1518,16 +1513,16 @@ GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller, * @param handle the registration handle to cancel */ void -GNUNET_TESTBED_cancel_registration ( +GNUNET_TESTBED_cancel_registration( struct GNUNET_TESTBED_HostRegistrationHandle *handle) { if (handle != handle->c->rh) - { - GNUNET_break (0); - return; - } + { + GNUNET_break(0); + return; + } handle->c->rh = NULL; - GNUNET_free (handle); + GNUNET_free(handle); } @@ -1540,11 +1535,11 @@ GNUNET_TESTBED_cancel_registration ( * queue */ void -GNUNET_TESTBED_host_queue_oc_ (struct GNUNET_TESTBED_Host *h, - struct GNUNET_TESTBED_Operation *op) +GNUNET_TESTBED_host_queue_oc_(struct GNUNET_TESTBED_Host *h, + struct GNUNET_TESTBED_Operation *op) { - GNUNET_TESTBED_operation_queue_insert_ (h->opq_parallel_overlay_connect_operations, - op); + GNUNET_TESTBED_operation_queue_insert_(h->opq_parallel_overlay_connect_operations, + op); } @@ -1554,20 +1549,20 @@ GNUNET_TESTBED_host_queue_oc_ (struct GNUNET_TESTBED_Host *h, * @param host the host whose hostname is to be resolved */ void -GNUNET_TESTBED_host_resolve_ (struct GNUNET_TESTBED_Host *host) +GNUNET_TESTBED_host_resolve_(struct GNUNET_TESTBED_Host *host) { char *hostname; - hostname = (char *) host->hostname; - host->hostname = simple_resolve (hostname); + hostname = (char *)host->hostname; + host->hostname = simple_resolve(hostname); if (NULL == host->hostname) - { - GNUNET_break (0); - host->hostname = hostname; - return; - } - GNUNET_free (hostname); - host->hostname = GNUNET_strdup (host->hostname); + { + GNUNET_break(0); + host->hostname = hostname; + return; + } + GNUNET_free(hostname); + host->hostname = GNUNET_strdup(host->hostname); } /* end of testbed_api_hosts.c */ diff --git a/src/testbed/testbed_api_hosts.h b/src/testbed/testbed_api_hosts.h index bc5e988d3..369a6da1b 100644 --- a/src/testbed/testbed_api_hosts.h +++ b/src/testbed/testbed_api_hosts.h @@ -11,7 +11,7 @@ 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 . @@ -35,8 +35,7 @@ /** * handle for host registration */ -struct GNUNET_TESTBED_HostRegistrationHandle -{ +struct GNUNET_TESTBED_HostRegistrationHandle { /** * The host being registered */ @@ -67,7 +66,7 @@ struct GNUNET_TESTBED_HostRegistrationHandle * @return handle to the host, NULL on error */ struct GNUNET_TESTBED_Host * -GNUNET_TESTBED_host_lookup_by_id_ (uint32_t id); +GNUNET_TESTBED_host_lookup_by_id_(uint32_t id); /** @@ -83,9 +82,9 @@ GNUNET_TESTBED_host_lookup_by_id_ (uint32_t id); * @return handle to the host, NULL on error */ struct GNUNET_TESTBED_Host * -GNUNET_TESTBED_host_create_by_id_ (uint32_t id, - const struct GNUNET_CONFIGURATION_Handle - *cfg); +GNUNET_TESTBED_host_create_by_id_(uint32_t id, + const struct GNUNET_CONFIGURATION_Handle + *cfg); /** @@ -96,7 +95,7 @@ GNUNET_TESTBED_host_create_by_id_ (uint32_t id, * 'localhost', but then obviously not globally unique) */ uint32_t -GNUNET_TESTBED_host_get_id_ (const struct GNUNET_TESTBED_Host *host); +GNUNET_TESTBED_host_get_id_(const struct GNUNET_TESTBED_Host *host); /** @@ -106,7 +105,7 @@ GNUNET_TESTBED_host_get_id_ (const struct GNUNET_TESTBED_Host *host); * @return username to login to the host */ const char * -GNUNET_TESTBED_host_get_username_ (const struct GNUNET_TESTBED_Host *host); +GNUNET_TESTBED_host_get_username_(const struct GNUNET_TESTBED_Host *host); /** @@ -116,7 +115,7 @@ GNUNET_TESTBED_host_get_username_ (const struct GNUNET_TESTBED_Host *host); * @return username to login to the host */ uint16_t -GNUNET_TESTBED_host_get_ssh_port_ (const struct GNUNET_TESTBED_Host *host); +GNUNET_TESTBED_host_get_ssh_port_(const struct GNUNET_TESTBED_Host *host); /** @@ -126,7 +125,7 @@ GNUNET_TESTBED_host_get_ssh_port_ (const struct GNUNET_TESTBED_Host *host); * @return the host's configuration template */ const struct GNUNET_CONFIGURATION_Handle * -GNUNET_TESTBED_host_get_cfg_ (const struct GNUNET_TESTBED_Host *host); +GNUNET_TESTBED_host_get_cfg_(const struct GNUNET_TESTBED_Host *host); /** @@ -136,8 +135,8 @@ GNUNET_TESTBED_host_get_cfg_ (const struct GNUNET_TESTBED_Host *host); * @param new_cfg the new configuration to replace the old one */ void -GNUNET_TESTBED_host_replace_cfg_ (struct GNUNET_TESTBED_Host *host, - const struct GNUNET_CONFIGURATION_Handle *new_cfg); +GNUNET_TESTBED_host_replace_cfg_(struct GNUNET_TESTBED_Host *host, + const struct GNUNET_CONFIGURATION_Handle *new_cfg); /** @@ -147,9 +146,9 @@ GNUNET_TESTBED_host_replace_cfg_ (struct GNUNET_TESTBED_Host *host, * @param controller the controller at which this host is registered */ void -GNUNET_TESTBED_mark_host_registered_at_ (struct GNUNET_TESTBED_Host *host, - const struct GNUNET_TESTBED_Controller - *controller); +GNUNET_TESTBED_mark_host_registered_at_(struct GNUNET_TESTBED_Host *host, + const struct GNUNET_TESTBED_Controller + *controller); /** @@ -159,9 +158,9 @@ GNUNET_TESTBED_mark_host_registered_at_ (struct GNUNET_TESTBED_Host *host, * @param controller the controller at which this host has to be unmarked */ void -GNUNET_TESTBED_deregister_host_at_ (struct GNUNET_TESTBED_Host *host, - const struct GNUNET_TESTBED_Controller - *const controller); +GNUNET_TESTBED_deregister_host_at_(struct GNUNET_TESTBED_Host *host, + const struct GNUNET_TESTBED_Controller + *const controller); /** @@ -172,9 +171,9 @@ GNUNET_TESTBED_deregister_host_at_ (struct GNUNET_TESTBED_Host *host, * @return GNUNET_YES if registered; GNUNET_NO if not */ int -GNUNET_TESTBED_is_host_registered_ (const struct GNUNET_TESTBED_Host *host, - const struct GNUNET_TESTBED_Controller - *controller); +GNUNET_TESTBED_is_host_registered_(const struct GNUNET_TESTBED_Host *host, + const struct GNUNET_TESTBED_Controller + *controller); /** @@ -186,8 +185,8 @@ GNUNET_TESTBED_is_host_registered_ (const struct GNUNET_TESTBED_Host *host, * queue */ void -GNUNET_TESTBED_host_queue_oc_ (struct GNUNET_TESTBED_Host *h, - struct GNUNET_TESTBED_Operation *op); +GNUNET_TESTBED_host_queue_oc_(struct GNUNET_TESTBED_Host *h, + struct GNUNET_TESTBED_Operation *op); /** @@ -196,7 +195,7 @@ GNUNET_TESTBED_host_queue_oc_ (struct GNUNET_TESTBED_Host *h, * @param cproc the handle to the controller's helper process */ void -GNUNET_TESTBED_controller_kill_ (struct GNUNET_TESTBED_ControllerProc *cproc); +GNUNET_TESTBED_controller_kill_(struct GNUNET_TESTBED_ControllerProc *cproc); /** @@ -205,8 +204,8 @@ GNUNET_TESTBED_controller_kill_ (struct GNUNET_TESTBED_ControllerProc *cproc); * @param cproc the handle to the controller's helper process */ void -GNUNET_TESTBED_controller_destroy_ (struct GNUNET_TESTBED_ControllerProc - *cproc); +GNUNET_TESTBED_controller_destroy_(struct GNUNET_TESTBED_ControllerProc + *cproc); /** @@ -215,7 +214,7 @@ GNUNET_TESTBED_controller_destroy_ (struct GNUNET_TESTBED_ControllerProc * @param host the host whose hostname is to be resolved */ void -GNUNET_TESTBED_host_resolve_ (struct GNUNET_TESTBED_Host *host); +GNUNET_TESTBED_host_resolve_(struct GNUNET_TESTBED_Host *host); #endif diff --git a/src/testbed/testbed_api_operations.c b/src/testbed/testbed_api_operations.c index 167e1b833..194dc2655 100644 --- a/src/testbed/testbed_api_operations.c +++ b/src/testbed/testbed_api_operations.c @@ -11,7 +11,7 @@ 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 . @@ -44,8 +44,7 @@ /** * An entry in the operation queue */ -struct QueueEntry -{ +struct QueueEntry { /** * The next DLL pointer */ @@ -78,8 +77,7 @@ struct OperationQueue; /** * A slot to record time taken by an operation */ -struct TimeSlot -{ +struct TimeSlot { /** * DLL next pointer */ @@ -115,8 +113,7 @@ struct TimeSlot /** * Context for operation queues of type OPERATION_QUEUE_TYPE_ADAPTIVE */ -struct FeedbackCtx -{ +struct FeedbackCtx { /** * Handle for calculating standard deviation */ @@ -159,8 +156,7 @@ struct FeedbackCtx * Queue of operations where we can only support a certain * number of concurrent operations of a particular type. */ -struct OperationQueue -{ +struct OperationQueue { /** * DLL head for the wait queue. Operations which are waiting for this * operation queue are put here @@ -247,8 +243,7 @@ struct OperationQueue /** * Operation state */ -enum OperationState -{ +enum OperationState { /** * The operation is just created and is in initial state */ @@ -282,8 +277,7 @@ enum OperationState /** * An entry in the ready queue (implemented as DLL) */ -struct ReadyQueueEntry -{ +struct ReadyQueueEntry { /** * next ptr for DLL */ @@ -304,8 +298,7 @@ struct ReadyQueueEntry /** * Opaque handle to an abstract operation to be executed by the testing framework. */ -struct GNUNET_TESTBED_Operation -{ +struct GNUNET_TESTBED_Operation { /** * Function to call when we have the resources to begin the operation. */ @@ -374,7 +367,6 @@ struct GNUNET_TESTBED_Operation * Is this a failed operation? */ int failed; - }; /** @@ -411,17 +403,17 @@ struct GNUNET_SCHEDULER_Task *process_rq_task_id; * @return the timeslot */ static void -assign_timeslot (struct GNUNET_TESTBED_Operation *op, - struct OperationQueue *queue) +assign_timeslot(struct GNUNET_TESTBED_Operation *op, + struct OperationQueue *queue) { struct FeedbackCtx *fctx = queue->fctx; struct TimeSlot *tslot; - GNUNET_assert (OPERATION_QUEUE_TYPE_ADAPTIVE == queue->type); + GNUNET_assert(OPERATION_QUEUE_TYPE_ADAPTIVE == queue->type); tslot = fctx->alloc_head; - GNUNET_assert (NULL != tslot); - GNUNET_CONTAINER_DLL_remove (fctx->alloc_head, fctx->alloc_tail, tslot); - GNUNET_CONTAINER_DLL_insert_tail (op->tslots_head, op->tslots_tail, tslot); + GNUNET_assert(NULL != tslot); + GNUNET_CONTAINER_DLL_remove(fctx->alloc_head, fctx->alloc_tail, tslot); + GNUNET_CONTAINER_DLL_insert_tail(op->tslots_head, op->tslots_tail, tslot); tslot->op = op; } @@ -434,7 +426,7 @@ assign_timeslot (struct GNUNET_TESTBED_Operation *op, * @param index the index of the entry in the operation's array of queue entries */ static void -remove_queue_entry (struct GNUNET_TESTBED_Operation *op, unsigned int index) +remove_queue_entry(struct GNUNET_TESTBED_Operation *op, unsigned int index) { struct OperationQueue *opq; struct QueueEntry *entry; @@ -442,23 +434,27 @@ remove_queue_entry (struct GNUNET_TESTBED_Operation *op, unsigned int index) opq = op->queues[index]; entry = op->qentries[index]; switch (op->state) - { - case OP_STATE_INIT: - GNUNET_assert (0); - break; - case OP_STATE_WAITING: - GNUNET_CONTAINER_DLL_remove (opq->wq_head, opq->wq_tail, entry); - break; - case OP_STATE_READY: - GNUNET_CONTAINER_DLL_remove (opq->rq_head, opq->rq_tail, entry); - break; - case OP_STATE_ACTIVE: - GNUNET_CONTAINER_DLL_remove (opq->aq_head, opq->aq_tail, entry); - break; - case OP_STATE_INACTIVE: - GNUNET_CONTAINER_DLL_remove (opq->nq_head, opq->nq_tail, entry); - break; - } + { + case OP_STATE_INIT: + GNUNET_assert(0); + break; + + case OP_STATE_WAITING: + GNUNET_CONTAINER_DLL_remove(opq->wq_head, opq->wq_tail, entry); + break; + + case OP_STATE_READY: + GNUNET_CONTAINER_DLL_remove(opq->rq_head, opq->rq_tail, entry); + break; + + case OP_STATE_ACTIVE: + GNUNET_CONTAINER_DLL_remove(opq->aq_head, opq->aq_tail, entry); + break; + + case OP_STATE_INACTIVE: + GNUNET_CONTAINER_DLL_remove(opq->nq_head, opq->nq_tail, entry); + break; + } } @@ -470,53 +466,57 @@ remove_queue_entry (struct GNUNET_TESTBED_Operation *op, unsigned int index) * @param state the state the operation should have. It cannot be OP_STATE_INIT */ static void -change_state (struct GNUNET_TESTBED_Operation *op, enum OperationState state) +change_state(struct GNUNET_TESTBED_Operation *op, enum OperationState state) { struct QueueEntry *entry; struct OperationQueue *opq; unsigned int cnt; unsigned int s; - GNUNET_assert (OP_STATE_INIT != state); - GNUNET_assert (NULL != op->queues); - GNUNET_assert (NULL != op->nres); - GNUNET_assert ((OP_STATE_INIT == op->state) || (NULL != op->qentries)); - GNUNET_assert (op->state != state); + GNUNET_assert(OP_STATE_INIT != state); + GNUNET_assert(NULL != op->queues); + GNUNET_assert(NULL != op->nres); + GNUNET_assert((OP_STATE_INIT == op->state) || (NULL != op->qentries)); + GNUNET_assert(op->state != state); for (cnt = 0; cnt < op->nqueues; cnt++) - { - if (OP_STATE_INIT == op->state) - { - entry = GNUNET_new (struct QueueEntry); - entry->op = op; - entry->nres = op->nres[cnt]; - s = cnt; - GNUNET_array_append (op->qentries, s, entry); - } - else { - entry = op->qentries[cnt]; - remove_queue_entry (op, cnt); + if (OP_STATE_INIT == op->state) + { + entry = GNUNET_new(struct QueueEntry); + entry->op = op; + entry->nres = op->nres[cnt]; + s = cnt; + GNUNET_array_append(op->qentries, s, entry); + } + else + { + entry = op->qentries[cnt]; + remove_queue_entry(op, cnt); + } + opq = op->queues[cnt]; + switch (state) + { + case OP_STATE_INIT: + GNUNET_assert(0); + break; + + case OP_STATE_WAITING: + GNUNET_CONTAINER_DLL_insert_tail(opq->wq_head, opq->wq_tail, entry); + break; + + case OP_STATE_READY: + GNUNET_CONTAINER_DLL_insert_tail(opq->rq_head, opq->rq_tail, entry); + break; + + case OP_STATE_ACTIVE: + GNUNET_CONTAINER_DLL_insert_tail(opq->aq_head, opq->aq_tail, entry); + break; + + case OP_STATE_INACTIVE: + GNUNET_CONTAINER_DLL_insert_tail(opq->nq_head, opq->nq_tail, entry); + break; + } } - opq = op->queues[cnt]; - switch (state) - { - case OP_STATE_INIT: - GNUNET_assert (0); - break; - case OP_STATE_WAITING: - GNUNET_CONTAINER_DLL_insert_tail (opq->wq_head, opq->wq_tail, entry); - break; - case OP_STATE_READY: - GNUNET_CONTAINER_DLL_insert_tail (opq->rq_head, opq->rq_tail, entry); - break; - case OP_STATE_ACTIVE: - GNUNET_CONTAINER_DLL_insert_tail (opq->aq_head, opq->aq_tail, entry); - break; - case OP_STATE_INACTIVE: - GNUNET_CONTAINER_DLL_insert_tail (opq->nq_head, opq->nq_tail, entry); - break; - } - } op->state = state; } @@ -528,17 +528,17 @@ change_state (struct GNUNET_TESTBED_Operation *op, enum OperationState state) * @param op the operation to be removed */ static void -rq_remove (struct GNUNET_TESTBED_Operation *op) +rq_remove(struct GNUNET_TESTBED_Operation *op) { - GNUNET_assert (NULL != op->rq_entry); - GNUNET_CONTAINER_DLL_remove (rq_head, rq_tail, op->rq_entry); - GNUNET_free (op->rq_entry); + GNUNET_assert(NULL != op->rq_entry); + GNUNET_CONTAINER_DLL_remove(rq_head, rq_tail, op->rq_entry); + GNUNET_free(op->rq_entry); op->rq_entry = NULL; - if ( (NULL == rq_head) && (NULL != process_rq_task_id) ) - { - GNUNET_SCHEDULER_cancel (process_rq_task_id); - process_rq_task_id = NULL; - } + if ((NULL == rq_head) && (NULL != process_rq_task_id)) + { + GNUNET_SCHEDULER_cancel(process_rq_task_id); + process_rq_task_id = NULL; + } } @@ -551,28 +551,28 @@ rq_remove (struct GNUNET_TESTBED_Operation *op) * @param cls NULL */ static void -process_rq_task (void *cls) +process_rq_task(void *cls) { struct GNUNET_TESTBED_Operation *op; struct OperationQueue *queue; unsigned int cnt; process_rq_task_id = NULL; - GNUNET_assert (NULL != rq_head); - GNUNET_assert (NULL != (op = rq_head->op)); - rq_remove (op); + GNUNET_assert(NULL != rq_head); + GNUNET_assert(NULL != (op = rq_head->op)); + rq_remove(op); if (NULL != rq_head) - process_rq_task_id = GNUNET_SCHEDULER_add_now (&process_rq_task, NULL); - change_state (op, OP_STATE_ACTIVE); + process_rq_task_id = GNUNET_SCHEDULER_add_now(&process_rq_task, NULL); + change_state(op, OP_STATE_ACTIVE); for (cnt = 0; cnt < op->nqueues; cnt++) - { - queue = op->queues[cnt]; - if (OPERATION_QUEUE_TYPE_ADAPTIVE == queue->type) - assign_timeslot (op, queue); - } - op->tstart = GNUNET_TIME_absolute_get (); + { + queue = op->queues[cnt]; + if (OPERATION_QUEUE_TYPE_ADAPTIVE == queue->type) + assign_timeslot(op, queue); + } + op->tstart = GNUNET_TIME_absolute_get(); if (NULL != op->start) - op->start (op->cb_cls); + op->start(op->cb_cls); } @@ -582,17 +582,17 @@ process_rq_task (void *cls) * @param op the operation to be queued */ static void -rq_add (struct GNUNET_TESTBED_Operation *op) +rq_add(struct GNUNET_TESTBED_Operation *op) { struct ReadyQueueEntry *rq_entry; - GNUNET_assert (NULL == op->rq_entry); - rq_entry = GNUNET_new (struct ReadyQueueEntry); + GNUNET_assert(NULL == op->rq_entry); + rq_entry = GNUNET_new(struct ReadyQueueEntry); rq_entry->op = op; - GNUNET_CONTAINER_DLL_insert_tail (rq_head, rq_tail, rq_entry); + GNUNET_CONTAINER_DLL_insert_tail(rq_head, rq_tail, rq_entry); op->rq_entry = rq_entry; if (NULL == process_rq_task_id) - process_rq_task_id = GNUNET_SCHEDULER_add_now (&process_rq_task, NULL); + process_rq_task_id = GNUNET_SCHEDULER_add_now(&process_rq_task, NULL); } @@ -604,12 +604,12 @@ rq_add (struct GNUNET_TESTBED_Operation *op) * otherwise */ static int -is_queue_empty (struct OperationQueue *opq) +is_queue_empty(struct OperationQueue *opq) { - if ( (NULL != opq->wq_head) - || (NULL != opq->rq_head) - || (NULL != opq->aq_head) - || (NULL != opq->nq_head) ) + if ((NULL != opq->wq_head) + || (NULL != opq->rq_head) + || (NULL != opq->aq_head) + || (NULL != opq->nq_head)) return GNUNET_NO; return GNUNET_YES; } @@ -632,10 +632,10 @@ is_queue_empty (struct OperationQueue *opq) * be set to NULL and 0 respectively. */ static int -decide_capacity (struct OperationQueue *opq, - struct QueueEntry *entry, - struct GNUNET_TESTBED_Operation ***ops_, - unsigned int *n_ops_) +decide_capacity(struct OperationQueue *opq, + struct QueueEntry *entry, + struct GNUNET_TESTBED_Operation ***ops_, + unsigned int *n_ops_) { struct QueueEntry **evict_entries; struct GNUNET_TESTBED_Operation **ops; @@ -647,53 +647,53 @@ decide_capacity (struct OperationQueue *opq, int deficit; int rval; - GNUNET_assert (NULL != (op = entry->op)); - GNUNET_assert (0 < (need = entry->nres)); + GNUNET_assert(NULL != (op = entry->op)); + GNUNET_assert(0 < (need = entry->nres)); ops = NULL; n_ops = 0; evict_entries = NULL; n_evict_entries = 0; rval = GNUNET_YES; if (OPERATION_QUEUE_TYPE_ADAPTIVE == opq->type) - { - GNUNET_assert (NULL != opq->fctx); - GNUNET_assert (opq->max_active >= opq->overload); - max = opq->max_active - opq->overload; - } + { + GNUNET_assert(NULL != opq->fctx); + GNUNET_assert(opq->max_active >= opq->overload); + max = opq->max_active - opq->overload; + } else max = opq->max_active; if (opq->active > max) - { - rval = GNUNET_NO; - goto ret; - } + { + rval = GNUNET_NO; + goto ret; + } if ((opq->active + need) <= max) goto ret; deficit = need - (max - opq->active); for (entry = opq->nq_head; (0 < deficit) && (NULL != entry); entry = entry->next) - { - GNUNET_array_append (evict_entries, n_evict_entries, entry); - deficit -= entry->nres; - } + { + GNUNET_array_append(evict_entries, n_evict_entries, entry); + deficit -= entry->nres; + } if (0 < deficit) - { - rval = GNUNET_NO; - goto ret; - } + { + rval = GNUNET_NO; + goto ret; + } for (n_ops = 0; n_ops < n_evict_entries;) - { - op = evict_entries[n_ops]->op; - GNUNET_array_append (ops, n_ops, op); /* increments n-ops */ - } + { + op = evict_entries[n_ops]->op; + GNUNET_array_append(ops, n_ops, op); /* increments n-ops */ + } - ret: - GNUNET_free_non_null (evict_entries); +ret: + GNUNET_free_non_null(evict_entries); if (NULL != ops_) *ops_ = ops; else - GNUNET_free (ops); + GNUNET_free(ops); if (NULL != n_ops_) *n_ops_ = n_ops; return rval; @@ -710,30 +710,30 @@ decide_capacity (struct OperationQueue *opq, * @param n_new the number of operations in new array */ static void -merge_ops (struct GNUNET_TESTBED_Operation ***old, - unsigned int *n_old, - struct GNUNET_TESTBED_Operation **new, - unsigned int n_new) +merge_ops(struct GNUNET_TESTBED_Operation ***old, + unsigned int *n_old, + struct GNUNET_TESTBED_Operation **new, + unsigned int n_new) { struct GNUNET_TESTBED_Operation **cur; unsigned int i; unsigned int j; unsigned int n_cur; - GNUNET_assert (NULL != old); + GNUNET_assert(NULL != old); n_cur = *n_old; cur = *old; for (i = 0; i < n_new; i++) - { - for (j = 0; j < *n_old; j++) { - if (new[i] == cur[j]) - break; + for (j = 0; j < *n_old; j++) + { + if (new[i] == cur[j]) + break; + } + if (j < *n_old) + continue; + GNUNET_array_append(cur, n_cur, new[j]); } - if (j < *n_old) - continue; - GNUNET_array_append (cur, n_cur, new[j]); - } *old = cur; *n_old = n_cur; } @@ -746,7 +746,7 @@ merge_ops (struct GNUNET_TESTBED_Operation ***old, * @param op the operation */ static int -check_readiness (struct GNUNET_TESTBED_Operation *op) +check_readiness(struct GNUNET_TESTBED_Operation *op) { struct GNUNET_TESTBED_Operation **evict_ops; struct GNUNET_TESTBED_Operation **ops; @@ -754,39 +754,39 @@ check_readiness (struct GNUNET_TESTBED_Operation *op) unsigned int n_evict_ops; unsigned int i; - GNUNET_assert (NULL == op->rq_entry); - GNUNET_assert (OP_STATE_WAITING == op->state); + GNUNET_assert(NULL == op->rq_entry); + GNUNET_assert(OP_STATE_WAITING == op->state); evict_ops = NULL; n_evict_ops = 0; for (i = 0; i < op->nqueues; i++) - { - ops = NULL; - n_ops = 0; - if (GNUNET_NO == decide_capacity (op->queues[i], op->qentries[i], - &ops, &n_ops)) { - GNUNET_free_non_null (evict_ops); - return GNUNET_NO; + ops = NULL; + n_ops = 0; + if (GNUNET_NO == decide_capacity(op->queues[i], op->qentries[i], + &ops, &n_ops)) + { + GNUNET_free_non_null(evict_ops); + return GNUNET_NO; + } + if (NULL == ops) + continue; + merge_ops(&evict_ops, &n_evict_ops, ops, n_ops); + GNUNET_free(ops); } - if (NULL == ops) - continue; - merge_ops (&evict_ops, &n_evict_ops, ops, n_ops); - GNUNET_free (ops); - } if (NULL != evict_ops) - { - for (i = 0; i < n_evict_ops; i++) - GNUNET_TESTBED_operation_release_ (evict_ops[i]); - GNUNET_free (evict_ops); - evict_ops = NULL; - /* Evicting the operations should schedule this operation */ - GNUNET_assert (OP_STATE_READY == op->state); - return GNUNET_YES; - } + { + for (i = 0; i < n_evict_ops; i++) + GNUNET_TESTBED_operation_release_(evict_ops[i]); + GNUNET_free(evict_ops); + evict_ops = NULL; + /* Evicting the operations should schedule this operation */ + GNUNET_assert(OP_STATE_READY == op->state); + return GNUNET_YES; + } for (i = 0; i < op->nqueues; i++) op->queues[i]->active += op->nres[i]; - change_state (op, OP_STATE_READY); - rq_add (op); + change_state(op, OP_STATE_READY); + rq_add(op); return GNUNET_YES; } @@ -797,18 +797,18 @@ check_readiness (struct GNUNET_TESTBED_Operation *op) * @param op the operation to defer */ static void -defer (struct GNUNET_TESTBED_Operation *op) +defer(struct GNUNET_TESTBED_Operation *op) { unsigned int i; - GNUNET_assert (OP_STATE_READY == op->state); - rq_remove (op); + GNUNET_assert(OP_STATE_READY == op->state); + rq_remove(op); for (i = 0; i < op->nqueues; i++) - { - GNUNET_assert (op->queues[i]->active >= op->nres[i]); - op->queues[i]->active -= op->nres[i]; - } - change_state (op, OP_STATE_WAITING); + { + GNUNET_assert(op->queues[i]->active >= op->nres[i]); + op->queues[i]->active -= op->nres[i]; + } + change_state(op, OP_STATE_WAITING); } @@ -820,23 +820,23 @@ defer (struct GNUNET_TESTBED_Operation *op) * @param queue the operation queue */ static void -cleanup_tslots (struct OperationQueue *queue) +cleanup_tslots(struct OperationQueue *queue) { struct FeedbackCtx *fctx = queue->fctx; struct TimeSlot *tslot; struct GNUNET_TESTBED_Operation *op; unsigned int cnt; - GNUNET_assert (NULL != fctx); + GNUNET_assert(NULL != fctx); for (cnt = 0; cnt < queue->max_active; cnt++) - { - tslot = &fctx->tslots_freeptr[cnt]; - op = tslot->op; - if (NULL == op) - continue; - GNUNET_CONTAINER_DLL_remove (op->tslots_head, op->tslots_tail, tslot); - } - GNUNET_free_non_null (fctx->tslots_freeptr); + { + tslot = &fctx->tslots_freeptr[cnt]; + op = tslot->op; + if (NULL == op) + continue; + GNUNET_CONTAINER_DLL_remove(op->tslots_head, op->tslots_tail, tslot); + } + GNUNET_free_non_null(fctx->tslots_freeptr); fctx->tslots_freeptr = NULL; fctx->alloc_head = NULL; fctx->alloc_tail = NULL; @@ -854,23 +854,23 @@ cleanup_tslots (struct OperationQueue *queue) * will be selected as n */ static void -adaptive_queue_set_max_active (struct OperationQueue *queue, unsigned int n) +adaptive_queue_set_max_active(struct OperationQueue *queue, unsigned int n) { struct FeedbackCtx *fctx = queue->fctx; struct TimeSlot *tslot; unsigned int cnt; - cleanup_tslots (queue); - n = GNUNET_MIN (n ,fctx->max_active_bound); - fctx->tslots_freeptr = GNUNET_malloc (n * sizeof (struct TimeSlot)); + cleanup_tslots(queue); + n = GNUNET_MIN(n, fctx->max_active_bound); + fctx->tslots_freeptr = GNUNET_malloc(n * sizeof(struct TimeSlot)); fctx->nfailed = 0; for (cnt = 0; cnt < n; cnt++) - { - tslot = &fctx->tslots_freeptr[cnt]; - tslot->queue = queue; - GNUNET_CONTAINER_DLL_insert_tail (fctx->alloc_head, fctx->alloc_tail, tslot); - } - GNUNET_TESTBED_operation_queue_reset_max_active_ (queue, n); + { + tslot = &fctx->tslots_freeptr[cnt]; + tslot->queue = queue; + GNUNET_CONTAINER_DLL_insert_tail(fctx->alloc_head, fctx->alloc_tail, tslot); + } + GNUNET_TESTBED_operation_queue_reset_max_active_(queue, n); } @@ -881,7 +881,7 @@ adaptive_queue_set_max_active (struct OperationQueue *queue, unsigned int n) * @param queue the queue */ static void -adapt_parallelism (struct OperationQueue *queue) +adapt_parallelism(struct OperationQueue *queue) { struct GNUNET_TIME_Relative avg; struct FeedbackCtx *fctx; @@ -895,32 +895,32 @@ adapt_parallelism (struct OperationQueue *queue) nvals = 0; fctx = queue->fctx; for (cnt = 0; cnt < queue->max_active; cnt++) - { - tslot = &fctx->tslots_freeptr[cnt]; - avg = GNUNET_TIME_relative_add (avg, tslot->tsum); - nvals += tslot->nvals; - } - GNUNET_assert (nvals >= queue->max_active); - GNUNET_assert (fctx->nfailed <= nvals); + { + tslot = &fctx->tslots_freeptr[cnt]; + avg = GNUNET_TIME_relative_add(avg, tslot->tsum); + nvals += tslot->nvals; + } + GNUNET_assert(nvals >= queue->max_active); + GNUNET_assert(fctx->nfailed <= nvals); nvals -= fctx->nfailed; if (0 == nvals) - { - if (1 == queue->max_active) - adaptive_queue_set_max_active (queue, 1); - else - adaptive_queue_set_max_active (queue, queue->max_active / 2); - return; - } - avg = GNUNET_TIME_relative_divide (avg, nvals); - GNUNET_TESTBED_SD_add_data_ (fctx->sd, (unsigned int) avg.rel_value_us); + { + if (1 == queue->max_active) + adaptive_queue_set_max_active(queue, 1); + else + adaptive_queue_set_max_active(queue, queue->max_active / 2); + return; + } + avg = GNUNET_TIME_relative_divide(avg, nvals); + GNUNET_TESTBED_SD_add_data_(fctx->sd, (unsigned int)avg.rel_value_us); if (GNUNET_SYSERR == - GNUNET_TESTBED_SD_deviation_factor_ (fctx->sd, - (unsigned int) avg.rel_value_us, - &sd)) - { - adaptive_queue_set_max_active (queue, queue->max_active); /* no change */ - return; - } + GNUNET_TESTBED_SD_deviation_factor_(fctx->sd, + (unsigned int)avg.rel_value_us, + &sd)) + { + adaptive_queue_set_max_active(queue, queue->max_active); /* no change */ + return; + } parallelism = 0; if (-1 == sd) @@ -931,36 +931,36 @@ adapt_parallelism (struct OperationQueue *queue) parallelism = queue->max_active - 1; if (2 <= sd) parallelism = queue->max_active / 2; - parallelism = GNUNET_MAX (parallelism, ADAPTIVE_QUEUE_DEFAULT_MAX_ACTIVE); - adaptive_queue_set_max_active (queue, parallelism); + parallelism = GNUNET_MAX(parallelism, ADAPTIVE_QUEUE_DEFAULT_MAX_ACTIVE); + adaptive_queue_set_max_active(queue, parallelism); #if 0 /* old algorithm */ if (sd < 0) sd = 0; - GNUNET_assert (0 <= sd); + GNUNET_assert(0 <= sd); //GNUNET_TESTBED_SD_add_data_ (fctx->sd, (unsigned int) avg.rel_value_us); if (0 == sd) - { - adaptive_queue_set_max_active (queue, queue->max_active * 2); - return; - } + { + adaptive_queue_set_max_active(queue, queue->max_active * 2); + return; + } if (1 == sd) - { - adaptive_queue_set_max_active (queue, queue->max_active + 1); - return; - } + { + adaptive_queue_set_max_active(queue, queue->max_active + 1); + return; + } if (1 == queue->max_active) - { - adaptive_queue_set_max_active (queue, 1); - return; - } + { + adaptive_queue_set_max_active(queue, 1); + return; + } if (2 == sd) - { - adaptive_queue_set_max_active (queue, queue->max_active - 1); - return; - } - adaptive_queue_set_max_active (queue, queue->max_active / 2); + { + adaptive_queue_set_max_active(queue, queue->max_active - 1); + return; + } + adaptive_queue_set_max_active(queue, queue->max_active / 2); #endif } @@ -973,7 +973,7 @@ adapt_parallelism (struct OperationQueue *queue) * @param op the operation */ static void -update_tslots (struct GNUNET_TESTBED_Operation *op) +update_tslots(struct GNUNET_TESTBED_Operation *op) { struct OperationQueue *queue; struct GNUNET_TIME_Relative t; @@ -981,31 +981,31 @@ update_tslots (struct GNUNET_TESTBED_Operation *op) struct FeedbackCtx *fctx; unsigned int i; - t = GNUNET_TIME_absolute_get_duration (op->tstart); + t = GNUNET_TIME_absolute_get_duration(op->tstart); while (NULL != (tslot = op->tslots_head)) /* update time slots */ - { - queue = tslot->queue; - fctx = queue->fctx; - GNUNET_CONTAINER_DLL_remove (op->tslots_head, op->tslots_tail, tslot); - tslot->op = NULL; - GNUNET_CONTAINER_DLL_insert_tail (fctx->alloc_head, fctx->alloc_tail, - tslot); - if (op->failed) { - fctx->nfailed++; - for (i = 0; i < op->nqueues; i++) - if (queue == op->queues[i]) - break; - GNUNET_assert (i != op->nqueues); - op->queues[i]->overload += op->nres[i]; + queue = tslot->queue; + fctx = queue->fctx; + GNUNET_CONTAINER_DLL_remove(op->tslots_head, op->tslots_tail, tslot); + tslot->op = NULL; + GNUNET_CONTAINER_DLL_insert_tail(fctx->alloc_head, fctx->alloc_tail, + tslot); + if (op->failed) + { + fctx->nfailed++; + for (i = 0; i < op->nqueues; i++) + if (queue == op->queues[i]) + break; + GNUNET_assert(i != op->nqueues); + op->queues[i]->overload += op->nres[i]; + } + tslot->tsum = GNUNET_TIME_relative_add(tslot->tsum, t); + if (0 != tslot->nvals++) + continue; + fctx->tslots_filled++; + if (queue->max_active == fctx->tslots_filled) + adapt_parallelism(queue); } - tslot->tsum = GNUNET_TIME_relative_add (tslot->tsum, t); - if (0 != tslot->nvals++) - continue; - fctx->tslots_filled++; - if (queue->max_active == fctx->tslots_filled) - adapt_parallelism (queue); - } } @@ -1018,12 +1018,12 @@ update_tslots (struct GNUNET_TESTBED_Operation *op) * @return handle to the operation */ struct GNUNET_TESTBED_Operation * -GNUNET_TESTBED_operation_create_ (void *cls, OperationStart start, - OperationRelease release) +GNUNET_TESTBED_operation_create_(void *cls, OperationStart start, + OperationRelease release) { struct GNUNET_TESTBED_Operation *op; - op = GNUNET_new (struct GNUNET_TESTBED_Operation); + op = GNUNET_new(struct GNUNET_TESTBED_Operation); op->start = start; op->state = OP_STATE_INIT; op->release = release; @@ -1041,26 +1041,26 @@ GNUNET_TESTBED_operation_create_ (void *cls, OperationStart start, * @return handle to the queue */ struct OperationQueue * -GNUNET_TESTBED_operation_queue_create_ (enum OperationQueueType type, - unsigned int max_active) +GNUNET_TESTBED_operation_queue_create_(enum OperationQueueType type, + unsigned int max_active) { struct OperationQueue *queue; struct FeedbackCtx *fctx; - queue = GNUNET_new (struct OperationQueue); + queue = GNUNET_new(struct OperationQueue); queue->type = type; if (OPERATION_QUEUE_TYPE_FIXED == type) - { - queue->max_active = max_active; - } + { + queue->max_active = max_active; + } else - { - fctx = GNUNET_new (struct FeedbackCtx); - fctx->max_active_bound = max_active; - fctx->sd = GNUNET_TESTBED_SD_init_ (ADAPTIVE_QUEUE_DEFAULT_HISTORY); - queue->fctx = fctx; - adaptive_queue_set_max_active (queue, ADAPTIVE_QUEUE_DEFAULT_MAX_ACTIVE); - } + { + fctx = GNUNET_new(struct FeedbackCtx); + fctx->max_active_bound = max_active; + fctx->sd = GNUNET_TESTBED_SD_init_(ADAPTIVE_QUEUE_DEFAULT_HISTORY); + queue->fctx = fctx; + adaptive_queue_set_max_active(queue, ADAPTIVE_QUEUE_DEFAULT_MAX_ACTIVE); + } return queue; } @@ -1071,18 +1071,18 @@ GNUNET_TESTBED_operation_queue_create_ (enum OperationQueueType type, * @param queue the operation queue to destroy */ static void -queue_destroy (struct OperationQueue *queue) +queue_destroy(struct OperationQueue *queue) { struct FeedbackCtx *fctx; if (OPERATION_QUEUE_TYPE_ADAPTIVE == queue->type) - { - cleanup_tslots (queue); - fctx = queue->fctx; - GNUNET_TESTBED_SD_destroy_ (fctx->sd); - GNUNET_free (fctx); - } - GNUNET_free (queue); + { + cleanup_tslots(queue); + fctx = queue->fctx; + GNUNET_TESTBED_SD_destroy_(fctx->sd); + GNUNET_free(fctx); + } + GNUNET_free(queue); } @@ -1094,16 +1094,16 @@ queue_destroy (struct OperationQueue *queue) * @param queue queue to destroy */ void -GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue) +GNUNET_TESTBED_operation_queue_destroy_(struct OperationQueue *queue) { - if (GNUNET_YES != is_queue_empty (queue)) - { - GNUNET_assert (0 == queue->expired); /* Are you calling twice on same queue? */ - queue->expired = 1; - GNUNET_array_append (expired_opqs, n_expired_opqs, queue); - return; - } - queue_destroy (queue); + if (GNUNET_YES != is_queue_empty(queue)) + { + GNUNET_assert(0 == queue->expired); /* Are you calling twice on same queue? */ + queue->expired = 1; + GNUNET_array_append(expired_opqs, n_expired_opqs, queue); + return; + } + queue_destroy(queue); } @@ -1115,11 +1115,11 @@ GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue) * is not empty) */ int -GNUNET_TESTBED_operation_queue_destroy_empty_ (struct OperationQueue *queue) +GNUNET_TESTBED_operation_queue_destroy_empty_(struct OperationQueue *queue) { - if (GNUNET_NO == is_queue_empty (queue)) + if (GNUNET_NO == is_queue_empty(queue)) return GNUNET_NO; - GNUNET_TESTBED_operation_queue_destroy_ (queue); + GNUNET_TESTBED_operation_queue_destroy_(queue); return GNUNET_YES; } @@ -1131,19 +1131,19 @@ GNUNET_TESTBED_operation_queue_destroy_empty_ (struct OperationQueue *queue) * @param opq the operation queue */ static void -recheck_waiting (struct OperationQueue *opq) +recheck_waiting(struct OperationQueue *opq) { struct QueueEntry *entry; struct QueueEntry *entry2; entry = opq->wq_head; while (NULL != entry) - { - entry2 = entry->next; - if (GNUNET_NO == check_readiness (entry->op)) - break; - entry = entry2; - } + { + entry2 = entry->next; + if (GNUNET_NO == check_readiness(entry->op)) + break; + entry = entry2; + } } @@ -1156,17 +1156,17 @@ recheck_waiting (struct OperationQueue *opq) * @param max_active the new maximum number of active operations */ void -GNUNET_TESTBED_operation_queue_reset_max_active_ (struct OperationQueue *queue, - unsigned int max_active) +GNUNET_TESTBED_operation_queue_reset_max_active_(struct OperationQueue *queue, + unsigned int max_active) { struct QueueEntry *entry; queue->max_active = max_active; queue->overload = 0; - while ( (queue->active > queue->max_active) - && (NULL != (entry = queue->rq_head)) ) - defer (entry->op); - recheck_waiting (queue); + while ((queue->active > queue->max_active) + && (NULL != (entry = queue->rq_head))) + defer(entry->op); + recheck_waiting(queue); } @@ -1182,17 +1182,17 @@ GNUNET_TESTBED_operation_queue_reset_max_active_ (struct OperationQueue *queue, * operation. Should be greater than 0. */ void -GNUNET_TESTBED_operation_queue_insert2_ (struct OperationQueue *queue, - struct GNUNET_TESTBED_Operation *op, - unsigned int nres) +GNUNET_TESTBED_operation_queue_insert2_(struct OperationQueue *queue, + struct GNUNET_TESTBED_Operation *op, + unsigned int nres) { unsigned int qsize; - GNUNET_assert (0 < nres); + GNUNET_assert(0 < nres); qsize = op->nqueues; - GNUNET_array_append (op->queues, op->nqueues, queue); - GNUNET_array_append (op->nres, qsize, nres); - GNUNET_assert (qsize == op->nqueues); + GNUNET_array_append(op->queues, op->nqueues, queue); + GNUNET_array_append(op->nres, qsize, nres); + GNUNET_assert(qsize == op->nqueues); } @@ -1208,10 +1208,10 @@ GNUNET_TESTBED_operation_queue_insert2_ (struct OperationQueue *queue, * @param op operation to add to the queue */ void -GNUNET_TESTBED_operation_queue_insert_ (struct OperationQueue *queue, - struct GNUNET_TESTBED_Operation *op) +GNUNET_TESTBED_operation_queue_insert_(struct OperationQueue *queue, + struct GNUNET_TESTBED_Operation *op) { - return GNUNET_TESTBED_operation_queue_insert2_ (queue, op, 1); + return GNUNET_TESTBED_operation_queue_insert2_(queue, op, 1); } @@ -1225,11 +1225,11 @@ GNUNET_TESTBED_operation_queue_insert_ (struct OperationQueue *queue, * @param op the operation to marks as waiting */ void -GNUNET_TESTBED_operation_begin_wait_ (struct GNUNET_TESTBED_Operation *op) +GNUNET_TESTBED_operation_begin_wait_(struct GNUNET_TESTBED_Operation *op) { - GNUNET_assert (NULL == op->rq_entry); - change_state (op, OP_STATE_WAITING); - (void) check_readiness (op); + GNUNET_assert(NULL == op->rq_entry); + change_state(op, OP_STATE_WAITING); + (void)check_readiness(op); } @@ -1243,24 +1243,24 @@ GNUNET_TESTBED_operation_begin_wait_ (struct GNUNET_TESTBED_Operation *op) * it as inactive. */ void -GNUNET_TESTBED_operation_inactivate_ (struct GNUNET_TESTBED_Operation *op) +GNUNET_TESTBED_operation_inactivate_(struct GNUNET_TESTBED_Operation *op) { struct OperationQueue **queues; size_t ms; unsigned int nqueues; unsigned int i; - GNUNET_assert (OP_STATE_ACTIVE == op->state); - change_state (op, OP_STATE_INACTIVE); + GNUNET_assert(OP_STATE_ACTIVE == op->state); + change_state(op, OP_STATE_INACTIVE); nqueues = op->nqueues; - ms = sizeof (struct OperationQueue *) * nqueues; - queues = GNUNET_malloc (ms); + ms = sizeof(struct OperationQueue *) * nqueues; + queues = GNUNET_malloc(ms); /* Cloning is needed as the operation be released by waiting operations and hence its nqueues memory ptr will be freed */ - GNUNET_memcpy (queues, op->queues, ms); + GNUNET_memcpy(queues, op->queues, ms); for (i = 0; i < nqueues; i++) - recheck_waiting (queues[i]); - GNUNET_free (queues); + recheck_waiting(queues[i]); + GNUNET_free(queues); } @@ -1272,11 +1272,10 @@ GNUNET_TESTBED_operation_inactivate_ (struct GNUNET_TESTBED_Operation *op) * @param op the operation to be marked as active */ void -GNUNET_TESTBED_operation_activate_ (struct GNUNET_TESTBED_Operation *op) +GNUNET_TESTBED_operation_activate_(struct GNUNET_TESTBED_Operation *op) { - - GNUNET_assert (OP_STATE_INACTIVE == op->state); - change_state (op, OP_STATE_ACTIVE); + GNUNET_assert(OP_STATE_INACTIVE == op->state); + change_state(op, OP_STATE_ACTIVE); } @@ -1287,54 +1286,56 @@ GNUNET_TESTBED_operation_activate_ (struct GNUNET_TESTBED_Operation *op) * @param op operation that finished */ void -GNUNET_TESTBED_operation_release_ (struct GNUNET_TESTBED_Operation *op) +GNUNET_TESTBED_operation_release_(struct GNUNET_TESTBED_Operation *op) { struct QueueEntry *entry; struct OperationQueue *opq; unsigned int i; if (OP_STATE_INIT == op->state) - { - GNUNET_free (op); - return; - } + { + GNUNET_free(op); + return; + } if (OP_STATE_READY == op->state) - rq_remove (op); + rq_remove(op); if (OP_STATE_INACTIVE == op->state) /* Activate the operation if inactive */ - GNUNET_TESTBED_operation_activate_ (op); + GNUNET_TESTBED_operation_activate_(op); if (OP_STATE_ACTIVE == op->state) - update_tslots (op); - GNUNET_assert (NULL != op->queues); - GNUNET_assert (NULL != op->qentries); + update_tslots(op); + GNUNET_assert(NULL != op->queues); + GNUNET_assert(NULL != op->qentries); for (i = 0; i < op->nqueues; i++) - { - entry = op->qentries[i]; - remove_queue_entry (op, i); - opq = op->queues[i]; - switch (op->state) { - case OP_STATE_INIT: - case OP_STATE_INACTIVE: - GNUNET_assert (0); - break; - case OP_STATE_WAITING: - break; - case OP_STATE_ACTIVE: - case OP_STATE_READY: - GNUNET_assert (0 != opq->active); - GNUNET_assert (opq->active >= entry->nres); - opq->active -= entry->nres; - recheck_waiting (opq); - break; + entry = op->qentries[i]; + remove_queue_entry(op, i); + opq = op->queues[i]; + switch (op->state) + { + case OP_STATE_INIT: + case OP_STATE_INACTIVE: + GNUNET_assert(0); + break; + + case OP_STATE_WAITING: + break; + + case OP_STATE_ACTIVE: + case OP_STATE_READY: + GNUNET_assert(0 != opq->active); + GNUNET_assert(opq->active >= entry->nres); + opq->active -= entry->nres; + recheck_waiting(opq); + break; + } + GNUNET_free(entry); } - GNUNET_free (entry); - } - GNUNET_free_non_null (op->qentries); - GNUNET_free (op->queues); - GNUNET_free (op->nres); + GNUNET_free_non_null(op->qentries); + GNUNET_free(op->queues); + GNUNET_free(op->nres); if (NULL != op->release) - op->release (op->cb_cls); - GNUNET_free (op); + op->release(op->cb_cls); + GNUNET_free(op); } @@ -1344,7 +1345,7 @@ GNUNET_TESTBED_operation_release_ (struct GNUNET_TESTBED_Operation *op) * @param op the operation to be marked as failed */ void -GNUNET_TESTBED_operation_mark_failed (struct GNUNET_TESTBED_Operation *op) +GNUNET_TESTBED_operation_mark_failed(struct GNUNET_TESTBED_Operation *op) { op->failed = GNUNET_YES; } @@ -1355,24 +1356,23 @@ GNUNET_TESTBED_operation_mark_failed (struct GNUNET_TESTBED_Operation *op) * operations which are not completed and warn about them. */ void __attribute__ ((destructor)) -GNUNET_TESTBED_operations_fini () +GNUNET_TESTBED_operations_fini() { struct OperationQueue *queue; unsigned int i; int warn = 0; - for (i=0; i < n_expired_opqs; i++) - { - queue = expired_opqs[i]; - if (GNUNET_NO == is_queue_empty (queue)) - warn = 1; - queue_destroy (queue); - } - GNUNET_free_non_null (expired_opqs); + for (i = 0; i < n_expired_opqs; i++) + { + queue = expired_opqs[i]; + if (GNUNET_NO == is_queue_empty(queue)) + warn = 1; + queue_destroy(queue); + } + GNUNET_free_non_null(expired_opqs); n_expired_opqs = 0; if (warn) - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Be disciplined. Some operations were not marked as done.\n"); - + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + "Be disciplined. Some operations were not marked as done.\n"); } /* end of testbed_api_operations.c */ diff --git a/src/testbed/testbed_api_operations.h b/src/testbed/testbed_api_operations.h index 28d64e8bb..fec518077 100644 --- a/src/testbed/testbed_api_operations.h +++ b/src/testbed/testbed_api_operations.h @@ -11,7 +11,7 @@ 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 . @@ -40,8 +40,7 @@ struct OperationQueue; /** * The type of operation queue */ -enum OperationQueueType -{ +enum OperationQueueType { /** * Operation queue which permits a fixed maximum number of operations to be * active at any time @@ -65,8 +64,8 @@ enum OperationQueueType * @return handle to the queue */ struct OperationQueue * -GNUNET_TESTBED_operation_queue_create_ (enum OperationQueueType type, - unsigned int max_active); +GNUNET_TESTBED_operation_queue_create_(enum OperationQueueType type, + unsigned int max_active); /** @@ -76,7 +75,7 @@ GNUNET_TESTBED_operation_queue_create_ (enum OperationQueueType type, * @param queue queue to destroy */ void -GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue); +GNUNET_TESTBED_operation_queue_destroy_(struct OperationQueue *queue); /** @@ -87,7 +86,7 @@ GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue); * is not empty) */ int -GNUNET_TESTBED_operation_queue_destroy_empty_ (struct OperationQueue *queue); +GNUNET_TESTBED_operation_queue_destroy_empty_(struct OperationQueue *queue); /** @@ -99,8 +98,8 @@ GNUNET_TESTBED_operation_queue_destroy_empty_ (struct OperationQueue *queue); * @param max_active the new maximum number of active operations */ void -GNUNET_TESTBED_operation_queue_reset_max_active_ (struct OperationQueue *queue, - unsigned int max_active); +GNUNET_TESTBED_operation_queue_reset_max_active_(struct OperationQueue *queue, + unsigned int max_active); /** @@ -115,9 +114,9 @@ GNUNET_TESTBED_operation_queue_reset_max_active_ (struct OperationQueue *queue, * operation. Should be greater than 0. */ void -GNUNET_TESTBED_operation_queue_insert2_ (struct OperationQueue *queue, - struct GNUNET_TESTBED_Operation *op, - unsigned int nres); +GNUNET_TESTBED_operation_queue_insert2_(struct OperationQueue *queue, + struct GNUNET_TESTBED_Operation *op, + unsigned int nres); /** @@ -130,8 +129,8 @@ GNUNET_TESTBED_operation_queue_insert2_ (struct OperationQueue *queue, * @param op operation to add to the queue */ void -GNUNET_TESTBED_operation_queue_insert_ (struct OperationQueue *queue, - struct GNUNET_TESTBED_Operation *op); +GNUNET_TESTBED_operation_queue_insert_(struct OperationQueue *queue, + struct GNUNET_TESTBED_Operation *op); /** @@ -144,7 +143,7 @@ GNUNET_TESTBED_operation_queue_insert_ (struct OperationQueue *queue, * @param op the operation to marks as waiting */ void -GNUNET_TESTBED_operation_begin_wait_ (struct GNUNET_TESTBED_Operation *op); +GNUNET_TESTBED_operation_begin_wait_(struct GNUNET_TESTBED_Operation *op); /** @@ -182,8 +181,8 @@ typedef void (*OperationRelease) (void *cls); * @return handle to the operation */ struct GNUNET_TESTBED_Operation * -GNUNET_TESTBED_operation_create_ (void *cls, OperationStart start, - OperationRelease release); +GNUNET_TESTBED_operation_create_(void *cls, OperationStart start, + OperationRelease release); /** @@ -193,7 +192,7 @@ GNUNET_TESTBED_operation_create_ (void *cls, OperationStart start, * @param op operation that finished */ void -GNUNET_TESTBED_operation_release_ (struct GNUNET_TESTBED_Operation *op); +GNUNET_TESTBED_operation_release_(struct GNUNET_TESTBED_Operation *op); /** @@ -206,7 +205,7 @@ GNUNET_TESTBED_operation_release_ (struct GNUNET_TESTBED_Operation *op); * it as inactive. */ void -GNUNET_TESTBED_operation_inactivate_ (struct GNUNET_TESTBED_Operation *op); +GNUNET_TESTBED_operation_inactivate_(struct GNUNET_TESTBED_Operation *op); /** @@ -217,7 +216,7 @@ GNUNET_TESTBED_operation_inactivate_ (struct GNUNET_TESTBED_Operation *op); * @param op the operation to be marked as active */ void -GNUNET_TESTBED_operation_activate_ (struct GNUNET_TESTBED_Operation *op); +GNUNET_TESTBED_operation_activate_(struct GNUNET_TESTBED_Operation *op); /** @@ -226,7 +225,7 @@ GNUNET_TESTBED_operation_activate_ (struct GNUNET_TESTBED_Operation *op); * @param op the operation to be marked as failed */ void -GNUNET_TESTBED_operation_mark_failed (struct GNUNET_TESTBED_Operation *op); +GNUNET_TESTBED_operation_mark_failed(struct GNUNET_TESTBED_Operation *op); #endif diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c index 5b7820e39..78ed71a42 100644 --- a/src/testbed/testbed_api_peers.c +++ b/src/testbed/testbed_api_peers.c @@ -11,7 +11,7 @@ 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 . @@ -51,9 +51,9 @@ static struct GNUNET_TESTBED_Peer *peer_list_tail; * @param peer the peer to add to the peer list */ void -GNUNET_TESTBED_peer_register_ (struct GNUNET_TESTBED_Peer *peer) +GNUNET_TESTBED_peer_register_(struct GNUNET_TESTBED_Peer *peer) { - GNUNET_CONTAINER_DLL_insert_tail (peer_list_head, peer_list_tail, peer); + GNUNET_CONTAINER_DLL_insert_tail(peer_list_head, peer_list_tail, peer); } @@ -63,9 +63,9 @@ GNUNET_TESTBED_peer_register_ (struct GNUNET_TESTBED_Peer *peer) * @param peer the peer to remove */ void -GNUNET_TESTBED_peer_deregister_ (struct GNUNET_TESTBED_Peer *peer) +GNUNET_TESTBED_peer_deregister_(struct GNUNET_TESTBED_Peer *peer) { - GNUNET_CONTAINER_DLL_remove (peer_list_head, peer_list_tail, peer); + GNUNET_CONTAINER_DLL_remove(peer_list_head, peer_list_tail, peer); } @@ -73,15 +73,15 @@ GNUNET_TESTBED_peer_deregister_ (struct GNUNET_TESTBED_Peer *peer) * Frees all peers */ void -GNUNET_TESTBED_cleanup_peers_ (void) +GNUNET_TESTBED_cleanup_peers_(void) { struct GNUNET_TESTBED_Peer *peer; while (NULL != (peer = peer_list_head)) - { - GNUNET_TESTBED_peer_deregister_ (peer); - GNUNET_free (peer); - } + { + GNUNET_TESTBED_peer_deregister_(peer); + GNUNET_free(peer); + } } @@ -94,7 +94,7 @@ GNUNET_TESTBED_cleanup_peers_ (void) * @param cls the closure from GNUNET_TESTBED_operation_create_() */ static void -opstart_peer_create (void *cls) +opstart_peer_create(void *cls) { struct OperationContext *opc = cls; struct PeerCreateData *data = opc->data; @@ -105,30 +105,30 @@ opstart_peer_create (void *cls) size_t c_size; size_t xc_size; - GNUNET_assert (OP_PEER_CREATE == opc->type); - GNUNET_assert (NULL != data); - GNUNET_assert (NULL != data->peer); + GNUNET_assert(OP_PEER_CREATE == opc->type); + GNUNET_assert(NULL != data); + GNUNET_assert(NULL != data->peer); opc->state = OPC_STATE_STARTED; - config = GNUNET_CONFIGURATION_serialize (data->cfg, - &c_size); - xc_size = GNUNET_TESTBED_compress_config_ (config, - c_size, - &xconfig); - GNUNET_free (config); - env = GNUNET_MQ_msg_extra (msg, - xc_size, - GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER); - msg->operation_id = GNUNET_htonll (opc->id); - msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (data->peer->host)); - msg->peer_id = htonl (data->peer->unique_id); - msg->config_size = htons ((uint16_t) c_size); - GNUNET_memcpy (&msg[1], - xconfig, - xc_size); - GNUNET_MQ_send (opc->c->mq, - env); - GNUNET_free (xconfig); - GNUNET_TESTBED_insert_opc_ (opc->c, opc); + config = GNUNET_CONFIGURATION_serialize(data->cfg, + &c_size); + xc_size = GNUNET_TESTBED_compress_config_(config, + c_size, + &xconfig); + GNUNET_free(config); + env = GNUNET_MQ_msg_extra(msg, + xc_size, + GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER); + msg->operation_id = GNUNET_htonll(opc->id); + msg->host_id = htonl(GNUNET_TESTBED_host_get_id_(data->peer->host)); + msg->peer_id = htonl(data->peer->unique_id); + msg->config_size = htons((uint16_t)c_size); + GNUNET_memcpy(&msg[1], + xconfig, + xc_size); + GNUNET_MQ_send(opc->c->mq, + env); + GNUNET_free(xconfig); + GNUNET_TESTBED_insert_opc_(opc->c, opc); } @@ -138,23 +138,25 @@ opstart_peer_create (void *cls) * @param cls the closure from GNUNET_TESTBED_operation_create_() */ static void -oprelease_peer_create (void *cls) +oprelease_peer_create(void *cls) { struct OperationContext *opc = cls; switch (opc->state) - { - case OPC_STATE_STARTED: - GNUNET_TESTBED_remove_opc_ (opc->c, opc); + { + case OPC_STATE_STARTED: + GNUNET_TESTBED_remove_opc_(opc->c, opc); + /* No break we continue flow */ - case OPC_STATE_INIT: - GNUNET_free (((struct PeerCreateData *) opc->data)->peer); - GNUNET_free (opc->data); - break; - case OPC_STATE_FINISHED: - break; - } - GNUNET_free (opc); + case OPC_STATE_INIT: + GNUNET_free(((struct PeerCreateData *)opc->data)->peer); + GNUNET_free(opc->data); + break; + + case OPC_STATE_FINISHED: + break; + } + GNUNET_free(opc); } @@ -164,23 +166,23 @@ oprelease_peer_create (void *cls) * @param cls the closure from GNUNET_TESTBED_operation_create_() */ static void -opstart_peer_destroy (void *cls) +opstart_peer_destroy(void *cls) { struct OperationContext *opc = cls; struct GNUNET_TESTBED_Peer *peer = opc->data; struct GNUNET_TESTBED_PeerDestroyMessage *msg; struct GNUNET_MQ_Envelope *env; - GNUNET_assert (OP_PEER_DESTROY == opc->type); - GNUNET_assert (NULL != peer); + GNUNET_assert(OP_PEER_DESTROY == opc->type); + GNUNET_assert(NULL != peer); opc->state = OPC_STATE_STARTED; - env = GNUNET_MQ_msg (msg, - GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER); - msg->peer_id = htonl (peer->unique_id); - msg->operation_id = GNUNET_htonll (opc->id); - GNUNET_TESTBED_insert_opc_ (opc->c, opc); - GNUNET_MQ_send (peer->controller->mq, - env); + env = GNUNET_MQ_msg(msg, + GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER); + msg->peer_id = htonl(peer->unique_id); + msg->operation_id = GNUNET_htonll(opc->id); + GNUNET_TESTBED_insert_opc_(opc->c, opc); + GNUNET_MQ_send(peer->controller->mq, + env); } @@ -190,21 +192,23 @@ opstart_peer_destroy (void *cls) * @param cls the closure from GNUNET_TESTBED_operation_create_() */ static void -oprelease_peer_destroy (void *cls) +oprelease_peer_destroy(void *cls) { struct OperationContext *opc = cls; switch (opc->state) - { - case OPC_STATE_STARTED: - GNUNET_TESTBED_remove_opc_ (opc->c, opc); + { + case OPC_STATE_STARTED: + GNUNET_TESTBED_remove_opc_(opc->c, opc); + /* no break; continue */ - case OPC_STATE_INIT: - break; - case OPC_STATE_FINISHED: - break; - } - GNUNET_free (opc); + case OPC_STATE_INIT: + break; + + case OPC_STATE_FINISHED: + break; + } + GNUNET_free(opc); } @@ -214,7 +218,7 @@ oprelease_peer_destroy (void *cls) * @param cls the closure from GNUNET_TESTBED_operation_create_() */ static void -opstart_peer_start (void *cls) +opstart_peer_start(void *cls) { struct OperationContext *opc = cls; struct GNUNET_TESTBED_PeerStartMessage *msg; @@ -222,18 +226,18 @@ opstart_peer_start (void *cls) struct PeerEventData *data; struct GNUNET_TESTBED_Peer *peer; - GNUNET_assert (OP_PEER_START == opc->type); - GNUNET_assert (NULL != (data = opc->data)); - GNUNET_assert (NULL != (peer = data->peer)); - GNUNET_assert ((TESTBED_PS_CREATED == peer->state) || (TESTBED_PS_STOPPED == peer->state)); + GNUNET_assert(OP_PEER_START == opc->type); + GNUNET_assert(NULL != (data = opc->data)); + GNUNET_assert(NULL != (peer = data->peer)); + GNUNET_assert((TESTBED_PS_CREATED == peer->state) || (TESTBED_PS_STOPPED == peer->state)); opc->state = OPC_STATE_STARTED; - env = GNUNET_MQ_msg (msg, - GNUNET_MESSAGE_TYPE_TESTBED_START_PEER); - msg->peer_id = htonl (peer->unique_id); - msg->operation_id = GNUNET_htonll (opc->id); - GNUNET_TESTBED_insert_opc_ (opc->c, opc); - GNUNET_MQ_send (peer->controller->mq, - env); + env = GNUNET_MQ_msg(msg, + GNUNET_MESSAGE_TYPE_TESTBED_START_PEER); + msg->peer_id = htonl(peer->unique_id); + msg->operation_id = GNUNET_htonll(opc->id); + GNUNET_TESTBED_insert_opc_(opc->c, opc); + GNUNET_MQ_send(peer->controller->mq, + env); } @@ -243,22 +247,24 @@ opstart_peer_start (void *cls) * @param cls the closure from GNUNET_TESTBED_operation_create_() */ static void -oprelease_peer_start (void *cls) +oprelease_peer_start(void *cls) { struct OperationContext *opc = cls; switch (opc->state) - { - case OPC_STATE_STARTED: - GNUNET_TESTBED_remove_opc_ (opc->c, opc); + { + case OPC_STATE_STARTED: + GNUNET_TESTBED_remove_opc_(opc->c, opc); + /* no break; continue */ - case OPC_STATE_INIT: - GNUNET_free (opc->data); - break; - case OPC_STATE_FINISHED: - break; - } - GNUNET_free (opc); + case OPC_STATE_INIT: + GNUNET_free(opc->data); + break; + + case OPC_STATE_FINISHED: + break; + } + GNUNET_free(opc); } @@ -268,7 +274,7 @@ oprelease_peer_start (void *cls) * @param cls the closure from GNUNET_TESTBED_operation_create_() */ static void -opstart_peer_stop (void *cls) +opstart_peer_stop(void *cls) { struct OperationContext *opc = cls; struct GNUNET_TESTBED_PeerStopMessage *msg; @@ -276,17 +282,17 @@ opstart_peer_stop (void *cls) struct GNUNET_TESTBED_Peer *peer; struct GNUNET_MQ_Envelope *env; - GNUNET_assert (NULL != (data = opc->data)); - GNUNET_assert (NULL != (peer = data->peer)); - GNUNET_assert (TESTBED_PS_STARTED == peer->state); + GNUNET_assert(NULL != (data = opc->data)); + GNUNET_assert(NULL != (peer = data->peer)); + GNUNET_assert(TESTBED_PS_STARTED == peer->state); opc->state = OPC_STATE_STARTED; - env = GNUNET_MQ_msg (msg, - GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER); - msg->peer_id = htonl (peer->unique_id); - msg->operation_id = GNUNET_htonll (opc->id); - GNUNET_TESTBED_insert_opc_ (opc->c, opc); - GNUNET_MQ_send (peer->controller->mq, - env); + env = GNUNET_MQ_msg(msg, + GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER); + msg->peer_id = htonl(peer->unique_id); + msg->operation_id = GNUNET_htonll(opc->id); + GNUNET_TESTBED_insert_opc_(opc->c, opc); + GNUNET_MQ_send(peer->controller->mq, + env); } @@ -296,22 +302,24 @@ opstart_peer_stop (void *cls) * @param cls the closure from GNUNET_TESTBED_operation_create_() */ static void -oprelease_peer_stop (void *cls) +oprelease_peer_stop(void *cls) { struct OperationContext *opc = cls; switch (opc->state) - { - case OPC_STATE_STARTED: - GNUNET_TESTBED_remove_opc_ (opc->c, opc); + { + case OPC_STATE_STARTED: + GNUNET_TESTBED_remove_opc_(opc->c, opc); + /* no break; continue */ - case OPC_STATE_INIT: - GNUNET_free (opc->data); - break; - case OPC_STATE_FINISHED: - break; - } - GNUNET_free (opc); + case OPC_STATE_INIT: + GNUNET_free(opc->data); + break; + + case OPC_STATE_FINISHED: + break; + } + GNUNET_free(opc); } @@ -324,19 +332,19 @@ oprelease_peer_stop (void *cls) * @return the PeerGetConfigurationMessage */ struct GNUNET_TESTBED_PeerGetConfigurationMessage * -GNUNET_TESTBED_generate_peergetconfig_msg_ (uint32_t peer_id, - uint64_t operation_id) +GNUNET_TESTBED_generate_peergetconfig_msg_(uint32_t peer_id, + uint64_t operation_id) { struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg; msg = - GNUNET_malloc (sizeof - (struct GNUNET_TESTBED_PeerGetConfigurationMessage)); + GNUNET_malloc(sizeof + (struct GNUNET_TESTBED_PeerGetConfigurationMessage)); msg->header.size = - htons (sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage)); - msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION); - msg->peer_id = htonl (peer_id); - msg->operation_id = GNUNET_htonll (operation_id); + htons(sizeof(struct GNUNET_TESTBED_PeerGetConfigurationMessage)); + msg->header.type = htons(GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION); + msg->peer_id = htonl(peer_id); + msg->operation_id = GNUNET_htonll(operation_id); return msg; } @@ -347,19 +355,19 @@ GNUNET_TESTBED_generate_peergetconfig_msg_ (uint32_t peer_id, * @param cls the closure from GNUNET_TESTBED_operation_create_() */ static void -opstart_peer_getinfo (void *cls) +opstart_peer_getinfo(void *cls) { struct OperationContext *opc = cls; struct PeerInfoData *data = opc->data; struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg; - GNUNET_assert (NULL != data); + GNUNET_assert(NULL != data); opc->state = OPC_STATE_STARTED; msg = - GNUNET_TESTBED_generate_peergetconfig_msg_ (data->peer->unique_id, - opc->id); - GNUNET_TESTBED_insert_opc_ (opc->c, opc); - GNUNET_TESTBED_queue_message_ (opc->c, &msg->header); + GNUNET_TESTBED_generate_peergetconfig_msg_(data->peer->unique_id, + opc->id); + GNUNET_TESTBED_insert_opc_(opc->c, opc); + GNUNET_TESTBED_queue_message_(opc->c, &msg->header); } @@ -369,38 +377,42 @@ opstart_peer_getinfo (void *cls) * @param cls the closure from GNUNET_TESTBED_operation_create_() */ static void -oprelease_peer_getinfo (void *cls) +oprelease_peer_getinfo(void *cls) { struct OperationContext *opc = cls; struct GNUNET_TESTBED_PeerInformation *data; switch (opc->state) - { - case OPC_STATE_STARTED: - GNUNET_TESTBED_remove_opc_ (opc->c, opc); - /* no break; continue */ - case OPC_STATE_INIT: - GNUNET_free (opc->data); - break; - case OPC_STATE_FINISHED: - data = opc->data; - GNUNET_assert (NULL != data); - switch (data->pit) { - case GNUNET_TESTBED_PIT_CONFIGURATION: - if (NULL != data->result.cfg) - GNUNET_CONFIGURATION_destroy (data->result.cfg); + case OPC_STATE_STARTED: + GNUNET_TESTBED_remove_opc_(opc->c, opc); + + /* no break; continue */ + case OPC_STATE_INIT: + GNUNET_free(opc->data); break; - case GNUNET_TESTBED_PIT_IDENTITY: - GNUNET_free (data->result.id); + + case OPC_STATE_FINISHED: + data = opc->data; + GNUNET_assert(NULL != data); + switch (data->pit) + { + case GNUNET_TESTBED_PIT_CONFIGURATION: + if (NULL != data->result.cfg) + GNUNET_CONFIGURATION_destroy(data->result.cfg); + break; + + case GNUNET_TESTBED_PIT_IDENTITY: + GNUNET_free(data->result.id); + break; + + default: + GNUNET_assert(0); /* We should never reach here */ + } + GNUNET_free(data); break; - default: - GNUNET_assert (0); /* We should never reach here */ } - GNUNET_free (data); - break; - } - GNUNET_free (opc); + GNUNET_free(opc); } @@ -410,7 +422,7 @@ oprelease_peer_getinfo (void *cls) * @param cls the closure from GNUNET_TESTBED_operation_create_() */ static void -opstart_overlay_connect (void *cls) +opstart_overlay_connect(void *cls) { struct OperationContext *opc = cls; struct GNUNET_MQ_Envelope *env; @@ -419,17 +431,17 @@ opstart_overlay_connect (void *cls) opc->state = OPC_STATE_STARTED; data = opc->data; - GNUNET_assert (NULL != data); - env = GNUNET_MQ_msg (msg, - GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT); - msg->peer1 = htonl (data->p1->unique_id); - msg->peer2 = htonl (data->p2->unique_id); - msg->operation_id = GNUNET_htonll (opc->id); - msg->peer2_host_id = htonl (GNUNET_TESTBED_host_get_id_ (data->p2->host)); - GNUNET_TESTBED_insert_opc_ (opc->c, - opc); - GNUNET_MQ_send (opc->c->mq, - env); + GNUNET_assert(NULL != data); + env = GNUNET_MQ_msg(msg, + GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT); + msg->peer1 = htonl(data->p1->unique_id); + msg->peer2 = htonl(data->p2->unique_id); + msg->operation_id = GNUNET_htonll(opc->id); + msg->peer2_host_id = htonl(GNUNET_TESTBED_host_get_id_(data->p2->host)); + GNUNET_TESTBED_insert_opc_(opc->c, + opc); + GNUNET_MQ_send(opc->c->mq, + env); } @@ -439,24 +451,26 @@ opstart_overlay_connect (void *cls) * @param cls the closure from GNUNET_TESTBED_operation_create_() */ static void -oprelease_overlay_connect (void *cls) +oprelease_overlay_connect(void *cls) { struct OperationContext *opc = cls; struct OverlayConnectData *data; data = opc->data; switch (opc->state) - { - case OPC_STATE_INIT: - break; - case OPC_STATE_STARTED: - GNUNET_TESTBED_remove_opc_ (opc->c, opc); - break; - case OPC_STATE_FINISHED: - break; - } - GNUNET_free (data); - GNUNET_free (opc); + { + case OPC_STATE_INIT: + break; + + case OPC_STATE_STARTED: + GNUNET_TESTBED_remove_opc_(opc->c, opc); + break; + + case OPC_STATE_FINISHED: + break; + } + GNUNET_free(data); + GNUNET_free(opc); } @@ -466,7 +480,7 @@ oprelease_overlay_connect (void *cls) * @param cls the closure from GNUNET_TESTBED_operation_create_() */ static void -opstart_peer_reconfigure (void *cls) +opstart_peer_reconfigure(void *cls) { struct OperationContext *opc = cls; struct PeerReconfigureData *data = opc->data; @@ -476,28 +490,28 @@ opstart_peer_reconfigure (void *cls) size_t xc_size; opc->state = OPC_STATE_STARTED; - GNUNET_assert (NULL != data); - xc_size = GNUNET_TESTBED_compress_config_ (data->config, - data->cfg_size, - &xconfig); - GNUNET_free (data->config); + GNUNET_assert(NULL != data); + xc_size = GNUNET_TESTBED_compress_config_(data->config, + data->cfg_size, + &xconfig); + GNUNET_free(data->config); data->config = NULL; - GNUNET_assert (xc_size < UINT16_MAX - sizeof (*msg)); - env = GNUNET_MQ_msg_extra (msg, - xc_size, - GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER); - msg->peer_id = htonl (data->peer->unique_id); - msg->operation_id = GNUNET_htonll (opc->id); - msg->config_size = htons (data->cfg_size); - GNUNET_memcpy (&msg[1], - xconfig, - xc_size); - GNUNET_free (xconfig); - GNUNET_free (data); + GNUNET_assert(xc_size < UINT16_MAX - sizeof(*msg)); + env = GNUNET_MQ_msg_extra(msg, + xc_size, + GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER); + msg->peer_id = htonl(data->peer->unique_id); + msg->operation_id = GNUNET_htonll(opc->id); + msg->config_size = htons(data->cfg_size); + GNUNET_memcpy(&msg[1], + xconfig, + xc_size); + GNUNET_free(xconfig); + GNUNET_free(data); opc->data = NULL; - GNUNET_TESTBED_insert_opc_ (opc->c, opc); - GNUNET_MQ_send (opc->c->mq, - env); + GNUNET_TESTBED_insert_opc_(opc->c, opc); + GNUNET_MQ_send(opc->c->mq, + env); } @@ -507,24 +521,26 @@ opstart_peer_reconfigure (void *cls) * @param cls the closure from GNUNET_TESTBED_operation_create_() */ static void -oprelease_peer_reconfigure (void *cls) +oprelease_peer_reconfigure(void *cls) { struct OperationContext *opc = cls; struct PeerReconfigureData *data = opc->data; switch (opc->state) - { - case OPC_STATE_INIT: - GNUNET_free (data->config); - GNUNET_free (data); - break; - case OPC_STATE_STARTED: - GNUNET_TESTBED_remove_opc_ (opc->c, opc); - break; - case OPC_STATE_FINISHED: - break; - } - GNUNET_free (opc); + { + case OPC_STATE_INIT: + GNUNET_free(data->config); + GNUNET_free(data); + break; + + case OPC_STATE_STARTED: + GNUNET_TESTBED_remove_opc_(opc->c, opc); + break; + + case OPC_STATE_FINISHED: + break; + } + GNUNET_free(opc); } @@ -535,9 +551,9 @@ oprelease_peer_reconfigure (void *cls) * @return handle to the host, NULL on error */ struct GNUNET_TESTBED_Peer * -GNUNET_TESTBED_peer_lookup_by_id_ (uint32_t id) +GNUNET_TESTBED_peer_lookup_by_id_(uint32_t id) { - GNUNET_break (0); + GNUNET_break(0); return NULL; } @@ -572,39 +588,38 @@ GNUNET_TESTBED_peer_lookup_by_id_ (uint32_t id) * @return the operation handle */ struct GNUNET_TESTBED_Operation * -GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller, - struct GNUNET_TESTBED_Host *host, - const struct GNUNET_CONFIGURATION_Handle *cfg, - GNUNET_TESTBED_PeerCreateCallback cb, void *cls) +GNUNET_TESTBED_peer_create(struct GNUNET_TESTBED_Controller *controller, + struct GNUNET_TESTBED_Host *host, + const struct GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_TESTBED_PeerCreateCallback cb, void *cls) { - struct GNUNET_TESTBED_Peer *peer; struct PeerCreateData *data; struct OperationContext *opc; static uint32_t id_gen; - peer = GNUNET_new (struct GNUNET_TESTBED_Peer); + peer = GNUNET_new(struct GNUNET_TESTBED_Peer); peer->controller = controller; peer->host = host; peer->unique_id = id_gen++; peer->state = TESTBED_PS_INVALID; - data = GNUNET_new (struct PeerCreateData); + data = GNUNET_new(struct PeerCreateData); data->host = host; data->cfg = cfg; data->cb = cb; data->cls = cls; data->peer = peer; - opc = GNUNET_new (struct OperationContext); + opc = GNUNET_new(struct OperationContext); opc->c = controller; opc->data = data; - opc->id = GNUNET_TESTBED_get_next_op_id (controller); + opc->id = GNUNET_TESTBED_get_next_op_id(controller); opc->type = OP_PEER_CREATE; opc->op = - GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_create, - &oprelease_peer_create); - GNUNET_TESTBED_operation_queue_insert_ (controller->opq_parallel_operations, - opc->op); - GNUNET_TESTBED_operation_begin_wait_ (opc->op); + GNUNET_TESTBED_operation_create_(opc, &opstart_peer_create, + &oprelease_peer_create); + GNUNET_TESTBED_operation_queue_insert_(controller->opq_parallel_operations, + opc->op); + GNUNET_TESTBED_operation_begin_wait_(opc->op); return opc->op; } @@ -620,28 +635,28 @@ GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller, * @return handle to the operation */ struct GNUNET_TESTBED_Operation * -GNUNET_TESTBED_peer_start (void *op_cls, struct GNUNET_TESTBED_Peer *peer, - GNUNET_TESTBED_PeerChurnCallback pcc, void *pcc_cls) +GNUNET_TESTBED_peer_start(void *op_cls, struct GNUNET_TESTBED_Peer *peer, + GNUNET_TESTBED_PeerChurnCallback pcc, void *pcc_cls) { struct OperationContext *opc; struct PeerEventData *data; - data = GNUNET_new (struct PeerEventData); + data = GNUNET_new(struct PeerEventData); data->peer = peer; data->pcc = pcc; data->pcc_cls = pcc_cls; - opc = GNUNET_new (struct OperationContext); + opc = GNUNET_new(struct OperationContext); opc->c = peer->controller; opc->data = data; opc->op_cls = op_cls; - opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); + opc->id = GNUNET_TESTBED_get_next_op_id(opc->c); opc->type = OP_PEER_START; opc->op = - GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_start, - &oprelease_peer_start); - GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, - opc->op); - GNUNET_TESTBED_operation_begin_wait_ (opc->op); + GNUNET_TESTBED_operation_create_(opc, &opstart_peer_start, + &oprelease_peer_start); + GNUNET_TESTBED_operation_queue_insert_(opc->c->opq_parallel_operations, + opc->op); + GNUNET_TESTBED_operation_begin_wait_(opc->op); return opc->op; } @@ -659,29 +674,29 @@ GNUNET_TESTBED_peer_start (void *op_cls, struct GNUNET_TESTBED_Peer *peer, * @return handle to the operation */ struct GNUNET_TESTBED_Operation * -GNUNET_TESTBED_peer_stop (void *op_cls, - struct GNUNET_TESTBED_Peer *peer, - GNUNET_TESTBED_PeerChurnCallback pcc, void *pcc_cls) +GNUNET_TESTBED_peer_stop(void *op_cls, + struct GNUNET_TESTBED_Peer *peer, + GNUNET_TESTBED_PeerChurnCallback pcc, void *pcc_cls) { struct OperationContext *opc; struct PeerEventData *data; - data = GNUNET_new (struct PeerEventData); + data = GNUNET_new(struct PeerEventData); data->peer = peer; data->pcc = pcc; data->pcc_cls = pcc_cls; - opc = GNUNET_new (struct OperationContext); + opc = GNUNET_new(struct OperationContext); opc->c = peer->controller; opc->data = data; opc->op_cls = op_cls; - opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); + opc->id = GNUNET_TESTBED_get_next_op_id(opc->c); opc->type = OP_PEER_STOP; opc->op = - GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_stop, - &oprelease_peer_stop); - GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, - opc->op); - GNUNET_TESTBED_operation_begin_wait_ (opc->op); + GNUNET_TESTBED_operation_create_(opc, &opstart_peer_stop, + &oprelease_peer_stop); + GNUNET_TESTBED_operation_queue_insert_(opc->c->opq_parallel_operations, + opc->op); + GNUNET_TESTBED_operation_begin_wait_(opc->op); return opc->op; } @@ -701,32 +716,32 @@ GNUNET_TESTBED_peer_stop (void *op_cls, * @return handle to the operation */ struct GNUNET_TESTBED_Operation * -GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer, - enum GNUNET_TESTBED_PeerInformationType - pit, GNUNET_TESTBED_PeerInfoCallback cb, - void *cb_cls) +GNUNET_TESTBED_peer_get_information(struct GNUNET_TESTBED_Peer *peer, + enum GNUNET_TESTBED_PeerInformationType + pit, GNUNET_TESTBED_PeerInfoCallback cb, + void *cb_cls) { struct OperationContext *opc; struct PeerInfoData *data; - GNUNET_assert (GNUNET_TESTBED_PIT_GENERIC != pit); - GNUNET_assert (NULL != cb); - data = GNUNET_new (struct PeerInfoData); + GNUNET_assert(GNUNET_TESTBED_PIT_GENERIC != pit); + GNUNET_assert(NULL != cb); + data = GNUNET_new(struct PeerInfoData); data->peer = peer; data->pit = pit; data->cb = cb; data->cb_cls = cb_cls; - opc = GNUNET_new (struct OperationContext); + opc = GNUNET_new(struct OperationContext); opc->c = peer->controller; opc->data = data; opc->type = OP_PEER_INFO; - opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); + opc->id = GNUNET_TESTBED_get_next_op_id(opc->c); opc->op = - GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_getinfo, - &oprelease_peer_getinfo); - GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, - opc->op); - GNUNET_TESTBED_operation_begin_wait_ (opc->op); + GNUNET_TESTBED_operation_create_(opc, &opstart_peer_getinfo, + &oprelease_peer_getinfo); + GNUNET_TESTBED_operation_queue_insert_(opc->c->opq_parallel_operations, + opc->op); + GNUNET_TESTBED_operation_begin_wait_(opc->op); return opc->op; } @@ -742,41 +757,41 @@ GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer, * @return handle to the operation */ struct GNUNET_TESTBED_Operation * -GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer, - const struct - GNUNET_CONFIGURATION_Handle *cfg) +GNUNET_TESTBED_peer_update_configuration(struct GNUNET_TESTBED_Peer *peer, + const struct + GNUNET_CONFIGURATION_Handle *cfg) { struct OperationContext *opc; struct PeerReconfigureData *data; size_t csize; - data = GNUNET_new (struct PeerReconfigureData); + data = GNUNET_new(struct PeerReconfigureData); data->peer = peer; - data->config = GNUNET_CONFIGURATION_serialize (cfg, &csize); + data->config = GNUNET_CONFIGURATION_serialize(cfg, &csize); if (NULL == data->config) - { - GNUNET_free (data); - return NULL; - } + { + GNUNET_free(data); + return NULL; + } if (csize > UINT16_MAX) - { - GNUNET_break (0); - GNUNET_free (data->config); - GNUNET_free (data); - return NULL; - } - data->cfg_size = (uint16_t) csize; - opc = GNUNET_new (struct OperationContext); + { + GNUNET_break(0); + GNUNET_free(data->config); + GNUNET_free(data); + return NULL; + } + data->cfg_size = (uint16_t)csize; + opc = GNUNET_new(struct OperationContext); opc->c = peer->controller; opc->data = data; opc->type = OP_PEER_RECONFIGURE; - opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); + opc->id = GNUNET_TESTBED_get_next_op_id(opc->c); opc->op = - GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_reconfigure, - &oprelease_peer_reconfigure); - GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, - opc->op); - GNUNET_TESTBED_operation_begin_wait_ (opc->op); + GNUNET_TESTBED_operation_create_(opc, &opstart_peer_reconfigure, + &oprelease_peer_reconfigure); + GNUNET_TESTBED_operation_queue_insert_(opc->c->opq_parallel_operations, + opc->op); + GNUNET_TESTBED_operation_begin_wait_(opc->op); return opc->op; } @@ -789,21 +804,21 @@ GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer, * @return handle to the operation */ struct GNUNET_TESTBED_Operation * -GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer) +GNUNET_TESTBED_peer_destroy(struct GNUNET_TESTBED_Peer *peer) { struct OperationContext *opc; - opc = GNUNET_new (struct OperationContext); + opc = GNUNET_new(struct OperationContext); opc->data = peer; opc->c = peer->controller; - opc->id = GNUNET_TESTBED_get_next_op_id (peer->controller); + opc->id = GNUNET_TESTBED_get_next_op_id(peer->controller); opc->type = OP_PEER_DESTROY; opc->op = - GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_destroy, - &oprelease_peer_destroy); - GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, - opc->op); - GNUNET_TESTBED_operation_begin_wait_ (opc->op); + GNUNET_TESTBED_operation_create_(opc, &opstart_peer_destroy, + &oprelease_peer_destroy); + GNUNET_TESTBED_operation_queue_insert_(opc->c->opq_parallel_operations, + opc->op); + GNUNET_TESTBED_operation_begin_wait_(opc->op); return opc->op; } @@ -821,13 +836,13 @@ GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer) * time is not allowed */ struct GNUNET_TESTBED_Operation * -GNUNET_TESTBED_underlay_configure_link (void *op_cls, - struct GNUNET_TESTBED_Peer *p1, - struct GNUNET_TESTBED_Peer *p2, - enum GNUNET_TESTBED_ConnectOption co, - ...) +GNUNET_TESTBED_underlay_configure_link(void *op_cls, + struct GNUNET_TESTBED_Peer *p1, + struct GNUNET_TESTBED_Peer *p2, + enum GNUNET_TESTBED_ConnectOption co, + ...) { - GNUNET_break (0); + GNUNET_break(0); return NULL; } @@ -847,31 +862,31 @@ GNUNET_TESTBED_underlay_configure_link (void *op_cls, * not running or underlay disallows) */ struct GNUNET_TESTBED_Operation * -GNUNET_TESTBED_overlay_connect (void *op_cls, - GNUNET_TESTBED_OperationCompletionCallback cb, - void *cb_cls, struct GNUNET_TESTBED_Peer *p1, - struct GNUNET_TESTBED_Peer *p2) +GNUNET_TESTBED_overlay_connect(void *op_cls, + GNUNET_TESTBED_OperationCompletionCallback cb, + void *cb_cls, struct GNUNET_TESTBED_Peer *p1, + struct GNUNET_TESTBED_Peer *p2) { struct OperationContext *opc; struct OverlayConnectData *data; - GNUNET_assert ((TESTBED_PS_STARTED == p1->state) && (TESTBED_PS_STARTED == p2->state)); - data = GNUNET_new (struct OverlayConnectData); + GNUNET_assert((TESTBED_PS_STARTED == p1->state) && (TESTBED_PS_STARTED == p2->state)); + data = GNUNET_new(struct OverlayConnectData); data->p1 = p1; data->p2 = p2; data->cb = cb; data->cb_cls = cb_cls; - opc = GNUNET_new (struct OperationContext); + opc = GNUNET_new(struct OperationContext); opc->data = data; opc->c = p1->controller; - opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); + opc->id = GNUNET_TESTBED_get_next_op_id(opc->c); opc->type = OP_OVERLAY_CONNECT; opc->op_cls = op_cls; opc->op = - GNUNET_TESTBED_operation_create_ (opc, &opstart_overlay_connect, - &oprelease_overlay_connect); - GNUNET_TESTBED_host_queue_oc_ (p1->host, opc->op); - GNUNET_TESTBED_operation_begin_wait_ (opc->op); + GNUNET_TESTBED_operation_create_(opc, &opstart_overlay_connect, + &oprelease_overlay_connect); + GNUNET_TESTBED_host_queue_oc_(p1->host, opc->op); + GNUNET_TESTBED_operation_begin_wait_(opc->op); return opc->op; } @@ -882,7 +897,7 @@ GNUNET_TESTBED_overlay_connect (void *op_cls, * @param cls the closure from GNUNET_TESTBED_operation_create_() */ static void -opstart_manage_service (void *cls) +opstart_manage_service(void *cls) { struct OperationContext *opc = cls; struct ManageServiceData *data = opc->data; @@ -890,23 +905,23 @@ opstart_manage_service (void *cls) struct GNUNET_TESTBED_ManagePeerServiceMessage *msg; size_t xlen; - GNUNET_assert (NULL != data); - xlen = data->msize - sizeof (struct GNUNET_TESTBED_ManagePeerServiceMessage); - env = GNUNET_MQ_msg_extra (msg, - xlen, - GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE); - msg->peer_id = htonl (data->peer->unique_id); - msg->operation_id = GNUNET_htonll (opc->id); - msg->start = (uint8_t) data->start; - GNUNET_memcpy (&msg[1], - data->service_name, - xlen); - GNUNET_free (data->service_name); + GNUNET_assert(NULL != data); + xlen = data->msize - sizeof(struct GNUNET_TESTBED_ManagePeerServiceMessage); + env = GNUNET_MQ_msg_extra(msg, + xlen, + GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE); + msg->peer_id = htonl(data->peer->unique_id); + msg->operation_id = GNUNET_htonll(opc->id); + msg->start = (uint8_t)data->start; + GNUNET_memcpy(&msg[1], + data->service_name, + xlen); + GNUNET_free(data->service_name); data->service_name = NULL; opc->state = OPC_STATE_STARTED; - GNUNET_TESTBED_insert_opc_ (opc->c, opc); - GNUNET_MQ_send (opc->c->mq, - env); + GNUNET_TESTBED_insert_opc_(opc->c, opc); + GNUNET_MQ_send(opc->c->mq, + env); } @@ -916,26 +931,28 @@ opstart_manage_service (void *cls) * @param cls the closure from GNUNET_TESTBED_operation_create_() */ static void -oprelease_manage_service (void *cls) +oprelease_manage_service(void *cls) { struct OperationContext *opc = cls; struct ManageServiceData *data; data = opc->data; switch (opc->state) - { - case OPC_STATE_STARTED: - GNUNET_TESTBED_remove_opc_ (opc->c, opc); - break; - case OPC_STATE_INIT: - GNUNET_assert (NULL != data); - GNUNET_free (data->service_name); - break; - case OPC_STATE_FINISHED: - break; - } - GNUNET_free_non_null (data); - GNUNET_free (opc); + { + case OPC_STATE_STARTED: + GNUNET_TESTBED_remove_opc_(opc->c, opc); + break; + + case OPC_STATE_INIT: + GNUNET_assert(NULL != data); + GNUNET_free(data->service_name); + break; + + case OPC_STATE_FINISHED: + break; + } + GNUNET_free_non_null(data); + GNUNET_free(opc); } @@ -955,41 +972,41 @@ oprelease_manage_service (void *cls) * @return an operation handle; NULL upon error (peer not running) */ struct GNUNET_TESTBED_Operation * -GNUNET_TESTBED_peer_manage_service (void *op_cls, - struct GNUNET_TESTBED_Peer *peer, - const char *service_name, - GNUNET_TESTBED_OperationCompletionCallback cb, - void *cb_cls, - unsigned int start) +GNUNET_TESTBED_peer_manage_service(void *op_cls, + struct GNUNET_TESTBED_Peer *peer, + const char *service_name, + GNUNET_TESTBED_OperationCompletionCallback cb, + void *cb_cls, + unsigned int start) { struct ManageServiceData *data; struct OperationContext *opc; size_t msize; - GNUNET_assert (TESTBED_PS_STARTED == peer->state); /* peer is not running? */ - msize = strlen (service_name) + 1; - msize += sizeof (struct GNUNET_TESTBED_ManagePeerServiceMessage); + GNUNET_assert(TESTBED_PS_STARTED == peer->state); /* peer is not running? */ + msize = strlen(service_name) + 1; + msize += sizeof(struct GNUNET_TESTBED_ManagePeerServiceMessage); if (GNUNET_MAX_MESSAGE_SIZE < msize) return NULL; - data = GNUNET_new (struct ManageServiceData); + data = GNUNET_new(struct ManageServiceData); data->cb = cb; data->cb_cls = cb_cls; data->peer = peer; - data->service_name = GNUNET_strdup (service_name); + data->service_name = GNUNET_strdup(service_name); data->start = start; - data->msize = (uint16_t) msize; - opc = GNUNET_new (struct OperationContext); + data->msize = (uint16_t)msize; + opc = GNUNET_new(struct OperationContext); opc->data = data; opc->c = peer->controller; - opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); + opc->id = GNUNET_TESTBED_get_next_op_id(opc->c); opc->type = OP_MANAGE_SERVICE; opc->op_cls = op_cls; opc->op = - GNUNET_TESTBED_operation_create_ (opc, &opstart_manage_service, - &oprelease_manage_service); - GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, - opc->op); - GNUNET_TESTBED_operation_begin_wait_ (opc->op); + GNUNET_TESTBED_operation_create_(opc, &opstart_manage_service, + &oprelease_manage_service); + GNUNET_TESTBED_operation_queue_insert_(opc->c->opq_parallel_operations, + opc->op); + GNUNET_TESTBED_operation_begin_wait_(opc->op); return opc->op; } diff --git a/src/testbed/testbed_api_peers.h b/src/testbed/testbed_api_peers.h index cf0624eec..6a9b89e7c 100644 --- a/src/testbed/testbed_api_peers.h +++ b/src/testbed/testbed_api_peers.h @@ -11,7 +11,7 @@ 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 . @@ -35,26 +35,25 @@ /** * Enumeration of possible states a peer could be in */ -enum PeerState -{ - /** - * State to signify that this peer is invalid - */ +enum PeerState { + /** + * State to signify that this peer is invalid + */ TESTBED_PS_INVALID, - /** - * The peer has been created - */ + /** + * The peer has been created + */ TESTBED_PS_CREATED, - /** - * The peer is running - */ + /** + * The peer is running + */ TESTBED_PS_STARTED, - /** - * The peer is stopped - */ + /** + * The peer is stopped + */ TESTBED_PS_STOPPED, }; @@ -63,8 +62,7 @@ enum PeerState * A peer controlled by the testing framework. A peer runs * at a particular host. */ -struct GNUNET_TESTBED_Peer -{ +struct GNUNET_TESTBED_Peer { /** * peer list DLL */ @@ -106,8 +104,7 @@ struct GNUNET_TESTBED_Peer /** * Data for the OperationType OP_PEER_CREATE */ -struct PeerCreateData -{ +struct PeerCreateData { /** * The host where the peer has to be created */ @@ -132,15 +129,13 @@ struct PeerCreateData * The peer structure to return when we get success message */ struct GNUNET_TESTBED_Peer *peer; - }; /** * Data for OperationType OP_PEER_START and OP_PEER_STOP */ -struct PeerEventData -{ +struct PeerEventData { /** * The handle of the peer to start */ @@ -155,15 +150,13 @@ struct PeerEventData * Closure for the above callback */ void *pcc_cls; - }; /** * Data for the OperationType OP_PEER_DESTROY; */ -struct PeerDestroyData -{ +struct PeerDestroyData { /** * The peer structure */ @@ -176,8 +169,7 @@ struct PeerDestroyData /** * Data for the OperationType OP_PEER_INFO */ -struct PeerInfoData -{ +struct PeerInfoData { /** * The peer whose information has been requested */ @@ -203,8 +195,7 @@ struct PeerInfoData /** * Data for the operations of type OP_PEER_RECONFIGURE */ -struct PeerReconfigureData -{ +struct PeerReconfigureData { /** * The peer whose information has been requested */ @@ -225,9 +216,7 @@ struct PeerReconfigureData /** * Data structure for OperationType OP_OVERLAY_CONNECT */ -struct OverlayConnectData -{ - +struct OverlayConnectData { /** * Peer A to connect to peer B */ @@ -254,7 +243,6 @@ struct OverlayConnectData * overlay connection between peer 1 and peer 2. */ struct OperationContext *sub_opc; - }; @@ -270,7 +258,6 @@ struct ManageServiceData { unsigned int start; uint16_t msize; - }; @@ -283,8 +270,8 @@ struct ManageServiceData { * @return the PeerGetConfigurationMessage */ struct GNUNET_TESTBED_PeerGetConfigurationMessage * -GNUNET_TESTBED_generate_peergetconfig_msg_ (uint32_t peer_id, - uint64_t operation_id); +GNUNET_TESTBED_generate_peergetconfig_msg_(uint32_t peer_id, + uint64_t operation_id); /** @@ -293,7 +280,7 @@ GNUNET_TESTBED_generate_peergetconfig_msg_ (uint32_t peer_id, * @param peer the peer to add to the peer list */ void -GNUNET_TESTBED_peer_register_ (struct GNUNET_TESTBED_Peer *peer); +GNUNET_TESTBED_peer_register_(struct GNUNET_TESTBED_Peer *peer); /** @@ -302,14 +289,14 @@ GNUNET_TESTBED_peer_register_ (struct GNUNET_TESTBED_Peer *peer); * @param peer the peer to remove */ void -GNUNET_TESTBED_peer_deregister_ (struct GNUNET_TESTBED_Peer *peer); +GNUNET_TESTBED_peer_deregister_(struct GNUNET_TESTBED_Peer *peer); /** * Frees all peers */ void -GNUNET_TESTBED_cleanup_peers_ (void); +GNUNET_TESTBED_cleanup_peers_(void); #endif /* end of testbed_api_peers.h */ diff --git a/src/testbed/testbed_api_sd.c b/src/testbed/testbed_api_sd.c index c9cbb27a1..2bff246a7 100644 --- a/src/testbed/testbed_api_sd.c +++ b/src/testbed/testbed_api_sd.c @@ -11,7 +11,7 @@ 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 . @@ -31,8 +31,7 @@ /** * An entry to hold data which will be used to calculate SD */ -struct SDEntry -{ +struct SDEntry { /** * DLL next pointer */ @@ -53,8 +52,7 @@ struct SDEntry /** * Opaque handle for calculating SD */ -struct SDHandle -{ +struct SDHandle { /** * DLL head for storing entries */ @@ -104,12 +102,12 @@ struct SDHandle * @return the initialized handle */ struct SDHandle * -GNUNET_TESTBED_SD_init_ (unsigned int max_cnt) +GNUNET_TESTBED_SD_init_(unsigned int max_cnt) { struct SDHandle *h; - GNUNET_assert (1 < max_cnt); - h = GNUNET_new (struct SDHandle); + GNUNET_assert(1 < max_cnt); + h = GNUNET_new(struct SDHandle); h->max_cnt = max_cnt; return h; } @@ -121,16 +119,16 @@ GNUNET_TESTBED_SD_init_ (unsigned int max_cnt) * @param h the SD handle */ void -GNUNET_TESTBED_SD_destroy_ (struct SDHandle *h) +GNUNET_TESTBED_SD_destroy_(struct SDHandle *h) { struct SDEntry *entry; while (NULL != (entry = h->head)) - { - GNUNET_CONTAINER_DLL_remove (h->head, h->tail, entry); - GNUNET_free (entry); - } - GNUNET_free (h); + { + GNUNET_CONTAINER_DLL_remove(h->head, h->tail, entry); + GNUNET_free(entry); + } + GNUNET_free(h); } @@ -141,7 +139,7 @@ GNUNET_TESTBED_SD_destroy_ (struct SDHandle *h) * @param amount the reading value */ void -GNUNET_TESTBED_SD_add_data_ (struct SDHandle *h, unsigned int amount) +GNUNET_TESTBED_SD_add_data_(struct SDHandle *h, unsigned int amount) { struct SDEntry *entry; double sqavg; @@ -149,25 +147,25 @@ GNUNET_TESTBED_SD_add_data_ (struct SDHandle *h, unsigned int amount) entry = NULL; if (h->cnt == h->max_cnt) - { - entry = h->head; - GNUNET_CONTAINER_DLL_remove (h->head, h->tail, entry); - h->sum -= entry->amount; - h->sqsum -= - ((unsigned long) entry->amount) * ((unsigned long) entry->amount); - h->cnt--; - } - GNUNET_assert (h->cnt < h->max_cnt); + { + entry = h->head; + GNUNET_CONTAINER_DLL_remove(h->head, h->tail, entry); + h->sum -= entry->amount; + h->sqsum -= + ((unsigned long)entry->amount) * ((unsigned long)entry->amount); + h->cnt--; + } + GNUNET_assert(h->cnt < h->max_cnt); if (NULL == entry) - entry = GNUNET_new (struct SDEntry); + entry = GNUNET_new(struct SDEntry); entry->amount = amount; - GNUNET_CONTAINER_DLL_insert_tail (h->head, h->tail, entry); + GNUNET_CONTAINER_DLL_insert_tail(h->head, h->tail, entry); h->sum += amount; h->cnt++; - h->avg = ((float) h->sum) / ((float) h->cnt); - h->sqsum += ((unsigned long) amount) * ((unsigned long) amount); - sqsum_avg = ((double) h->sqsum) / ((double) h->cnt); - sqavg = ((double) h->avg) * ((double) h->avg); + h->avg = ((float)h->sum) / ((float)h->cnt); + h->sqsum += ((unsigned long)amount) * ((unsigned long)amount); + sqsum_avg = ((double)h->sqsum) / ((double)h->cnt); + sqavg = ((double)h->avg) * ((double)h->avg); h->vr = sqsum_avg - sqavg; } @@ -182,8 +180,8 @@ GNUNET_TESTBED_SD_add_data_ (struct SDHandle *h, unsigned int amount) * be calculated; GNUNET_OK if the deviation is returned through factor */ int -GNUNET_TESTBED_SD_deviation_factor_ (struct SDHandle *h, unsigned int amount, - int *factor) +GNUNET_TESTBED_SD_deviation_factor_(struct SDHandle *h, unsigned int amount, + int *factor) { double diff; int f; @@ -191,19 +189,19 @@ GNUNET_TESTBED_SD_deviation_factor_ (struct SDHandle *h, unsigned int amount, if (h->cnt < 2) return GNUNET_SYSERR; - if (((float) amount) > h->avg) - { - diff = ((float) amount) - h->avg; - f = 1; - } + if (((float)amount) > h->avg) + { + diff = ((float)amount) - h->avg; + f = 1; + } else - { - diff = h->avg - ((float) amount); - f = -1; - } + { + diff = h->avg - ((float)amount); + f = -1; + } diff *= diff; for (n = 1; n < 4; n++) - if (diff < (((double) (n * n)) * h->vr)) + if (diff < (((double)(n * n)) * h->vr)) break; *factor = f * n; return GNUNET_OK; diff --git a/src/testbed/testbed_api_sd.h b/src/testbed/testbed_api_sd.h index a924857bb..6e4cc621a 100644 --- a/src/testbed/testbed_api_sd.h +++ b/src/testbed/testbed_api_sd.h @@ -11,7 +11,7 @@ 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 . @@ -41,7 +41,7 @@ struct SDHandle; * @return the initialized handle */ struct SDHandle * -GNUNET_TESTBED_SD_init_ (unsigned int max_cnt); +GNUNET_TESTBED_SD_init_(unsigned int max_cnt); /** @@ -50,7 +50,7 @@ GNUNET_TESTBED_SD_init_ (unsigned int max_cnt); * @param h the SD handle */ void -GNUNET_TESTBED_SD_destroy_ (struct SDHandle *h); +GNUNET_TESTBED_SD_destroy_(struct SDHandle *h); /** @@ -60,7 +60,7 @@ GNUNET_TESTBED_SD_destroy_ (struct SDHandle *h); * @param amount the reading value */ void -GNUNET_TESTBED_SD_add_data_ (struct SDHandle *h, unsigned int amount); +GNUNET_TESTBED_SD_add_data_(struct SDHandle *h, unsigned int amount); /** @@ -74,8 +74,8 @@ GNUNET_TESTBED_SD_add_data_ (struct SDHandle *h, unsigned int amount); * maximum of 4 is returned for deviations equal to or larger than 4 */ int -GNUNET_TESTBED_SD_deviation_factor_ (struct SDHandle *h, unsigned int amount, - int *factor); +GNUNET_TESTBED_SD_deviation_factor_(struct SDHandle *h, unsigned int amount, + int *factor); #endif /* end of testbed_api.h */ diff --git a/src/testbed/testbed_api_services.c b/src/testbed/testbed_api_services.c index c2b74e580..ee4a65817 100644 --- a/src/testbed/testbed_api_services.c +++ b/src/testbed/testbed_api_services.c @@ -11,7 +11,7 @@ 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 . @@ -32,8 +32,7 @@ /** * States for Service connect operations */ -enum State -{ +enum State { /** * Initial state */ @@ -54,8 +53,7 @@ enum State /** * Data accessed during service connections */ -struct ServiceConnectData -{ +struct ServiceConnectData { /** * helper function callback to establish the connection */ @@ -120,7 +118,6 @@ struct ServiceConnectData * State information */ enum State state; - }; @@ -132,7 +129,7 @@ struct ServiceConnectData * @param msg message received, NULL on timeout or fatal error */ static void -configuration_receiver (void *cls, const struct GNUNET_MessageHeader *msg) +configuration_receiver(void *cls, const struct GNUNET_MessageHeader *msg) { struct ServiceConnectData *data = cls; struct GNUNET_TESTBED_Controller *c; @@ -141,26 +138,26 @@ configuration_receiver (void *cls, const struct GNUNET_MessageHeader *msg) uint16_t mtype; c = data->peer->controller; - mtype = ntohs (msg->type); + mtype = ntohs(msg->type); emsg = NULL; info.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; info.op = data->operation; info.op_cls = data->op_cls; if (GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT == mtype) - { - emsg = - GNUNET_TESTBED_parse_error_string_ ((const struct - GNUNET_TESTBED_OperationFailureEventMessage - *) msg); - if (NULL == emsg) - emsg = "Unknown error"; - info.details.operation_finished.emsg = emsg; - info.details.operation_finished.generic = NULL; - goto call_cb; - } - data->cfg = GNUNET_TESTBED_extract_config_ (msg); - GNUNET_assert (NULL == data->op_result); - data->op_result = data->ca (data->cada_cls, data->cfg); + { + emsg = + GNUNET_TESTBED_parse_error_string_((const struct + GNUNET_TESTBED_OperationFailureEventMessage + *)msg); + if (NULL == emsg) + emsg = "Unknown error"; + info.details.operation_finished.emsg = emsg; + info.details.operation_finished.generic = NULL; + goto call_cb; + } + data->cfg = GNUNET_TESTBED_extract_config_(msg); + GNUNET_assert(NULL == data->op_result); + data->op_result = data->ca(data->cada_cls, data->cfg); info.details.operation_finished.emsg = NULL; info.details.operation_finished.generic = data->op_result; data->state = SERVICE_CONNECTED; @@ -168,9 +165,9 @@ configuration_receiver (void *cls, const struct GNUNET_MessageHeader *msg) call_cb: if ((0 != (GNUNET_TESTBED_ET_OPERATION_FINISHED & c->event_mask)) && (NULL != c->cc)) - c->cc (c->cc_cls, &info); + c->cc(c->cc_cls, &info); if (NULL != data->cb) - data->cb (data->cb_cls, data->operation, data->op_result, emsg); + data->cb(data->cb_cls, data->operation, data->op_result, emsg); } @@ -180,23 +177,23 @@ call_cb: * @param cls the closure from GNUNET_TESTBED_operation_create_() */ static void -opstart_service_connect (void *cls) +opstart_service_connect(void *cls) { struct ServiceConnectData *data = cls; struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg; struct GNUNET_TESTBED_Controller *c; uint64_t op_id; - GNUNET_assert (NULL != data); - GNUNET_assert (NULL != data->peer); + GNUNET_assert(NULL != data); + GNUNET_assert(NULL != data->peer); c = data->peer->controller; - op_id = GNUNET_TESTBED_get_next_op_id (c); + op_id = GNUNET_TESTBED_get_next_op_id(c); msg = - GNUNET_TESTBED_generate_peergetconfig_msg_ (data->peer->unique_id, op_id); + GNUNET_TESTBED_generate_peergetconfig_msg_(data->peer->unique_id, op_id); data->opc = - GNUNET_TESTBED_forward_operation_msg_ (c, op_id, &msg->header, - &configuration_receiver, data); - GNUNET_free (msg); + GNUNET_TESTBED_forward_operation_msg_(c, op_id, &msg->header, + &configuration_receiver, data); + GNUNET_free(msg); data->state = CFG_REQUEST_QUEUED; } @@ -208,26 +205,28 @@ opstart_service_connect (void *cls) * @param cls the closure from GNUNET_TESTBED_operation_create_() */ static void -oprelease_service_connect (void *cls) +oprelease_service_connect(void *cls) { struct ServiceConnectData *data = cls; switch (data->state) - { - case INIT: - break; - case CFG_REQUEST_QUEUED: - GNUNET_assert (NULL != data->opc); - GNUNET_TESTBED_forward_operation_msg_cancel_ (data->opc); - break; - case SERVICE_CONNECTED: - GNUNET_assert (NULL != data->cfg); - GNUNET_CONFIGURATION_destroy (data->cfg); - if (NULL != data->da) - data->da (data->cada_cls, data->op_result); - break; - } - GNUNET_free (data); + { + case INIT: + break; + + case CFG_REQUEST_QUEUED: + GNUNET_assert(NULL != data->opc); + GNUNET_TESTBED_forward_operation_msg_cancel_(data->opc); + break; + + case SERVICE_CONNECTED: + GNUNET_assert(NULL != data->cfg); + GNUNET_CONFIGURATION_destroy(data->cfg); + if (NULL != data->da) + data->da(data->cada_cls, data->op_result); + break; + } + GNUNET_free(data); } @@ -253,17 +252,17 @@ oprelease_service_connect (void *cls) * @return handle for the operation */ struct GNUNET_TESTBED_Operation * -GNUNET_TESTBED_service_connect (void *op_cls, struct GNUNET_TESTBED_Peer *peer, - const char *service_name, - GNUNET_TESTBED_ServiceConnectCompletionCallback - cb, void *cb_cls, - GNUNET_TESTBED_ConnectAdapter ca, - GNUNET_TESTBED_DisconnectAdapter da, - void *cada_cls) +GNUNET_TESTBED_service_connect(void *op_cls, struct GNUNET_TESTBED_Peer *peer, + const char *service_name, + GNUNET_TESTBED_ServiceConnectCompletionCallback + cb, void *cb_cls, + GNUNET_TESTBED_ConnectAdapter ca, + GNUNET_TESTBED_DisconnectAdapter da, + void *cada_cls) { struct ServiceConnectData *data; - data = GNUNET_new (struct ServiceConnectData); + data = GNUNET_new(struct ServiceConnectData); data->ca = ca; data->da = da; data->cada_cls = cada_cls; @@ -273,15 +272,15 @@ GNUNET_TESTBED_service_connect (void *op_cls, struct GNUNET_TESTBED_Peer *peer, data->cb = cb; data->cb_cls = cb_cls; data->operation = - GNUNET_TESTBED_operation_create_ (data, &opstart_service_connect, - &oprelease_service_connect); - GNUNET_TESTBED_operation_queue_insert_ (peer-> - controller->opq_parallel_service_connections, - data->operation); - GNUNET_TESTBED_operation_queue_insert_ (peer-> - controller->opq_parallel_operations, - data->operation); - GNUNET_TESTBED_operation_begin_wait_ (data->operation); + GNUNET_TESTBED_operation_create_(data, &opstart_service_connect, + &oprelease_service_connect); + GNUNET_TESTBED_operation_queue_insert_(peer-> + controller->opq_parallel_service_connections, + data->operation); + GNUNET_TESTBED_operation_queue_insert_(peer-> + controller->opq_parallel_operations, + data->operation); + GNUNET_TESTBED_operation_begin_wait_(data->operation); return data->operation; } diff --git a/src/testbed/testbed_api_statistics.c b/src/testbed/testbed_api_statistics.c index 6115f6e61..e7440dfa1 100644 --- a/src/testbed/testbed_api_statistics.c +++ b/src/testbed/testbed_api_statistics.c @@ -11,7 +11,7 @@ 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 . @@ -34,21 +34,20 @@ /** * Generic logging shorthand */ -#define LOG(kind,...) \ - GNUNET_log_from (kind, "testbed-api-statistics", __VA_ARGS__) +#define LOG(kind, ...) \ + GNUNET_log_from(kind, "testbed-api-statistics", __VA_ARGS__) /** * Debug logging shorthand */ #define LOG_DEBUG(...) \ - LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) + LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) /** * Context information for use in GNUNET_TESTBED_get_statistics() */ -struct GetStatsContext -{ +struct GetStatsContext { /** * The main operation we generate while creating this context */ @@ -106,15 +105,13 @@ struct GetStatsContext * How many peers' statistics have we iterated through */ unsigned int num_completed; - }; /** * Context information with respect to a particular peer */ -struct PeerGetStatsContext -{ +struct PeerGetStatsContext { /** * The GetStatsContext which is associated with this context */ @@ -152,14 +149,14 @@ static struct OperationQueue *no_wait_queue; * @param cls the GetStatsContext */ static void -call_completion_task (void *cls) +call_completion_task(void *cls) { struct GetStatsContext *sc = cls; - GNUNET_assert (sc->call_completion_task_id != NULL); + GNUNET_assert(sc->call_completion_task_id != NULL); sc->call_completion_task_id = NULL; - LOG_DEBUG ("Calling get_statistics() continuation callback\n"); - sc->cont (sc->cb_cls, sc->main_op, NULL); + LOG_DEBUG("Calling get_statistics() continuation callback\n"); + sc->cont(sc->cb_cls, sc->main_op, NULL); } @@ -170,7 +167,7 @@ call_completion_task (void *cls) * @param cls the PeerGetStatsContext */ static void -op_done_task (void *cls) +op_done_task(void *cls) { struct PeerGetStatsContext *peer_sc = cls; struct GetStatsContext *sc; @@ -179,8 +176,8 @@ op_done_task (void *cls) sc = peer_sc->sc; peer_sc->op_done_task_id = NULL; op = &sc->ops[peer_sc->peer_index]; - GNUNET_assert (NULL != *op); - GNUNET_TESTBED_operation_done (*op); + GNUNET_assert(NULL != *op); + GNUNET_TESTBED_operation_done(*op); *op = NULL; } @@ -193,22 +190,22 @@ op_done_task (void *cls) * successfully obtained, GNUNET_SYSERR if not. */ static void -iteration_completion_cb (void *cls, int success) +iteration_completion_cb(void *cls, int success) { struct PeerGetStatsContext *peer_sc = cls; struct GetStatsContext *sc; - GNUNET_break (GNUNET_OK == success); + GNUNET_break(GNUNET_OK == success); sc = peer_sc->sc; peer_sc->get_handle = NULL; sc->num_completed++; - peer_sc->op_done_task_id = GNUNET_SCHEDULER_add_now (&op_done_task, peer_sc); + peer_sc->op_done_task_id = GNUNET_SCHEDULER_add_now(&op_done_task, peer_sc); if (sc->num_completed == sc->num_peers) - { - LOG_DEBUG ("Scheduling to call iteration completion callback\n"); - sc->call_completion_task_id = - GNUNET_SCHEDULER_add_now (&call_completion_task, sc); - } + { + LOG_DEBUG("Scheduling to call iteration completion callback\n"); + sc->call_completion_task_id = + GNUNET_SCHEDULER_add_now(&call_completion_task, sc); + } } @@ -223,9 +220,9 @@ iteration_completion_cb (void *cls, int success) * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration */ static int -iterator_cb (void *cls, const char *subsystem, - const char *name, uint64_t value, - int is_persistent) +iterator_cb(void *cls, const char *subsystem, + const char *name, uint64_t value, + int is_persistent) { struct PeerGetStatsContext *peer_sc = cls; struct GetStatsContext *sc; @@ -234,12 +231,12 @@ iterator_cb (void *cls, const char *subsystem, sc = peer_sc->sc; peer = sc->peers[peer_sc->peer_index]; - LOG_DEBUG ("Peer %u: [%s,%s] -> %lu\n", peer_sc->peer_index, - subsystem, name, (unsigned long) value); - ret = sc->proc (sc->cb_cls, peer, - subsystem, name, value, is_persistent); + LOG_DEBUG("Peer %u: [%s,%s] -> %lu\n", peer_sc->peer_index, + subsystem, name, (unsigned long)value); + ret = sc->proc(sc->cb_cls, peer, + subsystem, name, value, is_persistent); if (GNUNET_SYSERR == ret) - LOG_DEBUG ("Aborting iteration for peer %u\n", peer_sc->peer_index); + LOG_DEBUG("Aborting iteration for peer %u\n", peer_sc->peer_index); return ret; } @@ -254,21 +251,21 @@ iterator_cb (void *cls, const char *subsystem, * operation has executed successfully. */ static void -service_connect_comp (void *cls, - struct GNUNET_TESTBED_Operation *op, - void *ca_result, - const char *emsg) +service_connect_comp(void *cls, + struct GNUNET_TESTBED_Operation *op, + void *ca_result, + const char *emsg) { struct PeerGetStatsContext *peer_sc = cls; struct GNUNET_STATISTICS_Handle *h = ca_result; - LOG_DEBUG ("Retrieving statistics of peer %u\n", - peer_sc->peer_index); + LOG_DEBUG("Retrieving statistics of peer %u\n", + peer_sc->peer_index); peer_sc->get_handle = - GNUNET_STATISTICS_get (h, peer_sc->sc->subsystem, - peer_sc->sc->name, - &iteration_completion_cb, - iterator_cb, peer_sc); + GNUNET_STATISTICS_get(h, peer_sc->sc->subsystem, + peer_sc->sc->name, + &iteration_completion_cb, + iterator_cb, peer_sc); } @@ -283,13 +280,13 @@ service_connect_comp (void *cls, * @return service handle to return in 'op_result', NULL on error */ static void * -statistics_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) +statistics_ca(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) { struct PeerGetStatsContext *peer_sc = cls; - LOG_DEBUG ("Connecting to statistics service of peer %u\n", - peer_sc->peer_index); - return GNUNET_STATISTICS_create ("", cfg); + LOG_DEBUG("Connecting to statistics service of peer %u\n", + peer_sc->peer_index); + return GNUNET_STATISTICS_create("", cfg); } @@ -300,20 +297,20 @@ statistics_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) * @param op_result service handle returned from the connect adapter */ static void -statistics_da (void *cls, void *op_result) +statistics_da(void *cls, void *op_result) { struct PeerGetStatsContext *peer_sc = cls; struct GNUNET_STATISTICS_Handle *sh = op_result; if (NULL != peer_sc->get_handle) - { - GNUNET_STATISTICS_get_cancel (peer_sc->get_handle); - peer_sc->get_handle = NULL; - } - GNUNET_STATISTICS_destroy (sh, GNUNET_NO); + { + GNUNET_STATISTICS_get_cancel(peer_sc->get_handle); + peer_sc->get_handle = NULL; + } + GNUNET_STATISTICS_destroy(sh, GNUNET_NO); if (NULL != peer_sc->op_done_task_id) - GNUNET_SCHEDULER_cancel (peer_sc->op_done_task_id); - GNUNET_free (peer_sc); + GNUNET_SCHEDULER_cancel(peer_sc->op_done_task_id); + GNUNET_free(peer_sc); } @@ -323,33 +320,33 @@ statistics_da (void *cls, void *op_result) * @param cls the GetStatsContext */ static void -opstart_get_stats (void *cls) +opstart_get_stats(void *cls) { struct GetStatsContext *sc = cls; struct PeerGetStatsContext *peer_sc; unsigned int peer; - LOG_DEBUG ("Starting get_statistics operation\n"); - sc->ops = GNUNET_malloc (sc->num_peers * - sizeof (struct GNUNET_TESTBED_Operation *)); + LOG_DEBUG("Starting get_statistics operation\n"); + sc->ops = GNUNET_malloc(sc->num_peers * + sizeof(struct GNUNET_TESTBED_Operation *)); for (peer = 0; peer < sc->num_peers; peer++) - { - if (NULL == sc->peers[peer]) { - GNUNET_break (0); - continue; + if (NULL == sc->peers[peer]) + { + GNUNET_break(0); + continue; + } + peer_sc = GNUNET_new(struct PeerGetStatsContext); + peer_sc->sc = sc; + peer_sc->peer_index = peer; + sc->ops[peer] = + GNUNET_TESTBED_service_connect(sc, sc->peers[peer], "statistics", + &service_connect_comp, + peer_sc, + &statistics_ca, + &statistics_da, + peer_sc); } - peer_sc = GNUNET_new (struct PeerGetStatsContext); - peer_sc->sc = sc; - peer_sc->peer_index = peer; - sc->ops[peer] = - GNUNET_TESTBED_service_connect (sc, sc->peers[peer], "statistics", - &service_connect_comp, - peer_sc, - &statistics_ca, - &statistics_da, - peer_sc); - } } @@ -359,31 +356,31 @@ opstart_get_stats (void *cls) * @param cls the GetStatsContext */ static void -oprelease_get_stats (void *cls) +oprelease_get_stats(void *cls) { struct GetStatsContext *sc = cls; unsigned int peer; - LOG_DEBUG ("Cleaning up get_statistics operation\n"); + LOG_DEBUG("Cleaning up get_statistics operation\n"); if (NULL != sc->call_completion_task_id) - GNUNET_SCHEDULER_cancel (sc->call_completion_task_id); + GNUNET_SCHEDULER_cancel(sc->call_completion_task_id); if (NULL != sc->ops) - { - for (peer = 0; peer < sc->num_peers; peer++) { - if (NULL != sc->ops[peer]) - { - GNUNET_TESTBED_operation_done (sc->ops[peer]); - sc->ops[peer] = NULL; - } + for (peer = 0; peer < sc->num_peers; peer++) + { + if (NULL != sc->ops[peer]) + { + GNUNET_TESTBED_operation_done(sc->ops[peer]); + sc->ops[peer] = NULL; + } + } + GNUNET_free(sc->ops); } - GNUNET_free (sc->ops); - } - GNUNET_free_non_null (sc->subsystem); - GNUNET_free_non_null (sc->name); - GNUNET_free (sc); + GNUNET_free_non_null(sc->subsystem); + GNUNET_free_non_null(sc->name); + GNUNET_free(sc); if (GNUNET_YES == - GNUNET_TESTBED_operation_queue_destroy_empty_ (no_wait_queue)) + GNUNET_TESTBED_operation_queue_destroy_empty_(no_wait_queue)) no_wait_queue = NULL; } @@ -402,33 +399,33 @@ oprelease_get_stats (void *cls) * @return operation handle to cancel the operation */ struct GNUNET_TESTBED_Operation * -GNUNET_TESTBED_get_statistics (unsigned int num_peers, - struct GNUNET_TESTBED_Peer **peers, - const char *subsystem, const char *name, - GNUNET_TESTBED_StatisticsIterator proc, - GNUNET_TESTBED_OperationCompletionCallback cont, - void *cls) +GNUNET_TESTBED_get_statistics(unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers, + const char *subsystem, const char *name, + GNUNET_TESTBED_StatisticsIterator proc, + GNUNET_TESTBED_OperationCompletionCallback cont, + void *cls) { struct GetStatsContext *sc; - GNUNET_assert (NULL != proc); - GNUNET_assert (NULL != cont); + GNUNET_assert(NULL != proc); + GNUNET_assert(NULL != cont); if (NULL == no_wait_queue) no_wait_queue = GNUNET_TESTBED_operation_queue_create_ - (OPERATION_QUEUE_TYPE_FIXED, UINT_MAX); - sc = GNUNET_new (struct GetStatsContext); + (OPERATION_QUEUE_TYPE_FIXED, UINT_MAX); + sc = GNUNET_new(struct GetStatsContext); sc->peers = peers; - sc->subsystem = (NULL == subsystem) ? NULL : GNUNET_strdup (subsystem); - sc->name = (NULL == name) ? NULL : GNUNET_strdup (name); + sc->subsystem = (NULL == subsystem) ? NULL : GNUNET_strdup(subsystem); + sc->name = (NULL == name) ? NULL : GNUNET_strdup(name); sc->proc = proc; sc->cont = cont; sc->cb_cls = cls; sc->num_peers = num_peers; sc->main_op = - GNUNET_TESTBED_operation_create_ (sc, &opstart_get_stats, - &oprelease_get_stats); - GNUNET_TESTBED_operation_queue_insert_ (no_wait_queue, sc->main_op); - GNUNET_TESTBED_operation_begin_wait_ (sc->main_op); + GNUNET_TESTBED_operation_create_(sc, &opstart_get_stats, + &oprelease_get_stats); + GNUNET_TESTBED_operation_queue_insert_(no_wait_queue, sc->main_op); + GNUNET_TESTBED_operation_begin_wait_(sc->main_op); return sc->main_op; } diff --git a/src/testbed/testbed_api_test.c b/src/testbed/testbed_api_test.c index 3f9400bda..7294a137e 100644 --- a/src/testbed/testbed_api_test.c +++ b/src/testbed/testbed_api_test.c @@ -11,7 +11,7 @@ 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 . @@ -31,8 +31,7 @@ /** * Context information for test run */ -struct TestRunContext -{ +struct TestRunContext { /** * Test master callback */ @@ -74,13 +73,13 @@ struct TestRunContext * @param config the configuration file handle */ static void -run (void *cls, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *config) +run(void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *config) { struct TestRunContext *rc = cls; - GNUNET_TESTBED_run (NULL, config, rc->num_peers, rc->event_mask, rc->cc, - rc->cc_cls, rc->test_master, rc->test_master_cls); + GNUNET_TESTBED_run(NULL, config, rc->num_peers, rc->event_mask, rc->cc, + rc->cc_cls, rc->test_master, rc->test_master_cls); } @@ -118,14 +117,14 @@ run (void *cls, char *const *args, const char *cfgfile, * @return #GNUNET_SYSERR on error, #GNUNET_OK on success */ int -GNUNET_TESTBED_test_run (const char *testname, - const char *cfg_filename, - unsigned int num_peers, - uint64_t event_mask, - GNUNET_TESTBED_ControllerCallback cc, - void *cc_cls, - GNUNET_TESTBED_TestMaster test_master, - void *test_master_cls) +GNUNET_TESTBED_test_run(const char *testname, + const char *cfg_filename, + unsigned int num_peers, + uint64_t event_mask, + GNUNET_TESTBED_ControllerCallback cc, + void *cc_cls, + GNUNET_TESTBED_TestMaster test_master, + void *test_master_cls) { char *argv2[] = { NULL, @@ -139,23 +138,23 @@ GNUNET_TESTBED_test_run (const char *testname, struct TestRunContext *rc; int ret; - argv2[0] = GNUNET_strdup (testname); - argv2[2] = GNUNET_strdup (cfg_filename); - GNUNET_assert (NULL != test_master); - GNUNET_assert (num_peers > 0); - rc = GNUNET_malloc (sizeof (struct TestRunContext) + - (num_peers * sizeof (struct GNUNET_TESTBED_Peer *))); + argv2[0] = GNUNET_strdup(testname); + argv2[2] = GNUNET_strdup(cfg_filename); + GNUNET_assert(NULL != test_master); + GNUNET_assert(num_peers > 0); + rc = GNUNET_malloc(sizeof(struct TestRunContext) + + (num_peers * sizeof(struct GNUNET_TESTBED_Peer *))); rc->test_master = test_master; rc->test_master_cls = test_master_cls; rc->num_peers = num_peers; rc->event_mask = event_mask; rc->cc = cc; rc->cc_cls = cc_cls; - ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, - testname, "nohelp", options, &run, rc); - GNUNET_free (rc); - GNUNET_free (argv2[0]); - GNUNET_free (argv2[2]); + ret = GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, argv2, + testname, "nohelp", options, &run, rc); + GNUNET_free(rc); + GNUNET_free(argv2[0]); + GNUNET_free(argv2[2]); return ret; } diff --git a/src/testbed/testbed_api_testbed.c b/src/testbed/testbed_api_testbed.c index c61934a40..4615afca9 100644 --- a/src/testbed/testbed_api_testbed.c +++ b/src/testbed/testbed_api_testbed.c @@ -1,22 +1,22 @@ /* - This file is part of GNUnet - Copyright (C) 2008--2013 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 . + This file is part of GNUnet + Copyright (C) 2008--2013 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/testbed_api_testbed.c @@ -36,14 +36,14 @@ /** * Generic loggins shorthand */ -#define LOG(kind,...) \ - GNUNET_log_from (kind, "testbed-api-testbed", __VA_ARGS__) +#define LOG(kind, ...) \ + GNUNET_log_from(kind, "testbed-api-testbed", __VA_ARGS__) /** * Debug logging shortcut */ #define DEBUG(...) \ - LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) + LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) /** * The default setup timeout in seconds @@ -71,8 +71,7 @@ /** * Context information for the operation we start */ -struct RunContextOperation -{ +struct RunContextOperation { /** * The testbed operation handle */ @@ -87,15 +86,13 @@ struct RunContextOperation * Closure */ void *cls; - }; /** * States of RunContext */ -enum State -{ +enum State { /** * Initial state */ @@ -138,8 +135,7 @@ enum State /** * Context for host compability checks */ -struct CompatibilityCheckContext -{ +struct CompatibilityCheckContext { /** * The run context */ @@ -160,8 +156,7 @@ struct CompatibilityCheckContext /** * Testbed Run Handle */ -struct GNUNET_TESTBED_RunHandle -{ +struct GNUNET_TESTBED_RunHandle { /** * The controller handle */ @@ -326,7 +321,6 @@ struct GNUNET_TESTBED_RunHandle * the number of overlay link connection attempts that failed */ unsigned int links_failed; - }; @@ -337,17 +331,16 @@ struct GNUNET_TESTBED_RunHandle * @return 32-bit key */ static uint32_t -rcop_key (void *rcop) +rcop_key(void *rcop) { - return * ((uint32_t *) &rcop); + return *((uint32_t *)&rcop); } /** * Context information used for finding a pointer in the rcop_map */ -struct SearchContext -{ +struct SearchContext { /** * The operation pointer to look for */ @@ -369,18 +362,18 @@ struct SearchContext * @return GNUNET_YES to continue iteration; GNUNET_NO to cancel it */ static int -search_iterator (void *cls, uint32_t key, void *value) +search_iterator(void *cls, uint32_t key, void *value) { struct RunContextOperation *rcop = value; struct SearchContext *sc = cls; - GNUNET_assert (NULL != rcop); + GNUNET_assert(NULL != rcop); if (sc->query == rcop->op) - { - GNUNET_assert (NULL == sc->result); - sc->result = rcop; - return GNUNET_NO; - } + { + GNUNET_assert(NULL == sc->result); + sc->result = rcop; + return GNUNET_NO; + } return GNUNET_YES; } @@ -394,21 +387,21 @@ search_iterator (void *cls, uint32_t key, void *value) * @return the matching RunContextOperation if found; NULL if not */ static struct RunContextOperation * -search_rcop (struct GNUNET_TESTBED_RunHandle *rc, struct GNUNET_TESTBED_Operation *op) +search_rcop(struct GNUNET_TESTBED_RunHandle *rc, struct GNUNET_TESTBED_Operation *op) { struct SearchContext sc; sc.query = op; sc.result = NULL; if (GNUNET_SYSERR == - GNUNET_CONTAINER_multihashmap32_get_multiple (rc->rcop_map, - rcop_key (op), - &search_iterator, - &sc)) - { - GNUNET_assert (NULL != sc.result); - return sc.result; - } + GNUNET_CONTAINER_multihashmap32_get_multiple(rc->rcop_map, + rcop_key(op), + &search_iterator, + &sc)) + { + GNUNET_assert(NULL != sc.result); + return sc.result; + } return NULL; } @@ -420,12 +413,12 @@ search_rcop (struct GNUNET_TESTBED_RunHandle *rc, struct GNUNET_TESTBED_Operatio * @param rcop the RunContextOperation to insert */ static void -insert_rcop (struct GNUNET_TESTBED_RunHandle *rc, struct RunContextOperation *rcop) +insert_rcop(struct GNUNET_TESTBED_RunHandle *rc, struct RunContextOperation *rcop) { - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multihashmap32_put (rc->rcop_map, - rcop_key (rcop->op), rcop, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); + GNUNET_assert(GNUNET_OK == + GNUNET_CONTAINER_multihashmap32_put(rc->rcop_map, + rcop_key(rcop->op), rcop, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); } @@ -437,12 +430,12 @@ insert_rcop (struct GNUNET_TESTBED_RunHandle *rc, struct RunContextOperation *rc * @param rcop the RunContextOperation */ static void -remove_rcop (struct GNUNET_TESTBED_RunHandle *rc, struct RunContextOperation *rcop) +remove_rcop(struct GNUNET_TESTBED_RunHandle *rc, struct RunContextOperation *rcop) { - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap32_remove (rc->rcop_map, - rcop_key (rcop->op), - rcop)); + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multihashmap32_remove(rc->rcop_map, + rcop_key(rcop->op), + rcop)); } /** @@ -451,31 +444,31 @@ remove_rcop (struct GNUNET_TESTBED_RunHandle *rc, struct RunContextOperation *rc * @param rc the run context */ static void -cleanup (struct GNUNET_TESTBED_RunHandle *rc) +cleanup(struct GNUNET_TESTBED_RunHandle *rc) { unsigned int hid; - GNUNET_assert (NULL == rc->register_hosts_task); - GNUNET_assert (NULL == rc->reg_handle); - GNUNET_assert (NULL == rc->peers); - GNUNET_assert (NULL == rc->hclist); - GNUNET_assert (RC_PEERS_SHUTDOWN == rc->state); - GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap32_size (rc->rcop_map)); - GNUNET_CONTAINER_multihashmap32_destroy (rc->rcop_map); + GNUNET_assert(NULL == rc->register_hosts_task); + GNUNET_assert(NULL == rc->reg_handle); + GNUNET_assert(NULL == rc->peers); + GNUNET_assert(NULL == rc->hclist); + GNUNET_assert(RC_PEERS_SHUTDOWN == rc->state); + GNUNET_assert(0 == GNUNET_CONTAINER_multihashmap32_size(rc->rcop_map)); + GNUNET_CONTAINER_multihashmap32_destroy(rc->rcop_map); if (NULL != rc->c) - GNUNET_TESTBED_controller_disconnect (rc->c); + GNUNET_TESTBED_controller_disconnect(rc->c); if (NULL != rc->cproc) - GNUNET_TESTBED_controller_stop (rc->cproc); + GNUNET_TESTBED_controller_stop(rc->cproc); if (NULL != rc->h) - GNUNET_TESTBED_host_destroy (rc->h); + GNUNET_TESTBED_host_destroy(rc->h); for (hid = 0; hid < rc->num_hosts; hid++) - GNUNET_TESTBED_host_destroy (rc->hosts[hid]); - GNUNET_free_non_null (rc->hosts); + GNUNET_TESTBED_host_destroy(rc->hosts[hid]); + GNUNET_free_non_null(rc->hosts); if (NULL != rc->cfg) - GNUNET_CONFIGURATION_destroy (rc->cfg); - GNUNET_free_non_null (rc->topo_file); - GNUNET_free_non_null (rc->trusted_ip); - GNUNET_free (rc); + GNUNET_CONFIGURATION_destroy(rc->cfg); + GNUNET_free_non_null(rc->topo_file); + GNUNET_free_non_null(rc->trusted_ip); + GNUNET_free(rc); } @@ -488,15 +481,15 @@ cleanup (struct GNUNET_TESTBED_RunHandle *rc) * @return always GNUNET_YES */ static int -rcop_cleanup_iterator (void *cls, uint32_t key, void *value) +rcop_cleanup_iterator(void *cls, uint32_t key, void *value) { struct GNUNET_TESTBED_RunHandle *rc = cls; struct RunContextOperation *rcop = value; - GNUNET_assert (rc == rcop->rc); - remove_rcop (rc, rcop); - GNUNET_TESTBED_operation_done (rcop->op); - GNUNET_free (rcop); + GNUNET_assert(rc == rcop->rc); + remove_rcop(rc, rcop); + GNUNET_TESTBED_operation_done(rcop->op); + GNUNET_free(rcop); return GNUNET_YES; } @@ -507,48 +500,48 @@ rcop_cleanup_iterator (void *cls, uint32_t key, void *value) * @param rc the RunContext */ static void -rc_cleanup_operations (struct GNUNET_TESTBED_RunHandle *rc) +rc_cleanup_operations(struct GNUNET_TESTBED_RunHandle *rc) { struct CompatibilityCheckContext *hc; unsigned int nhost; if (NULL != rc->hclist) - { - for (nhost = 0; nhost < rc->num_hosts; nhost++) { - hc = &rc->hclist[nhost]; - if (NULL != hc->h) - GNUNET_TESTBED_is_host_habitable_cancel (hc->h); + for (nhost = 0; nhost < rc->num_hosts; nhost++) + { + hc = &rc->hclist[nhost]; + if (NULL != hc->h) + GNUNET_TESTBED_is_host_habitable_cancel(hc->h); + } + GNUNET_free(rc->hclist); + rc->hclist = NULL; } - GNUNET_free (rc->hclist); - rc->hclist = NULL; - } /* Stop register hosts task if it is running */ if (NULL != rc->register_hosts_task) - { - GNUNET_SCHEDULER_cancel (rc->register_hosts_task); - rc->register_hosts_task = NULL; - } + { + GNUNET_SCHEDULER_cancel(rc->register_hosts_task); + rc->register_hosts_task = NULL; + } if (NULL != rc->timeout_task) - { - GNUNET_SCHEDULER_cancel (rc->timeout_task); - rc->timeout_task = NULL; - } + { + GNUNET_SCHEDULER_cancel(rc->timeout_task); + rc->timeout_task = NULL; + } if (NULL != rc->reg_handle) - { - GNUNET_TESTBED_cancel_registration (rc->reg_handle); - rc->reg_handle = NULL; - } + { + GNUNET_TESTBED_cancel_registration(rc->reg_handle); + rc->reg_handle = NULL; + } if (NULL != rc->topology_operation) - { - GNUNET_TESTBED_operation_done (rc->topology_operation); - rc->topology_operation = NULL; - } + { + GNUNET_TESTBED_operation_done(rc->topology_operation); + rc->topology_operation = NULL; + } /* cancel any exiting operations */ - GNUNET_assert (GNUNET_SYSERR != - GNUNET_CONTAINER_multihashmap32_iterate (rc->rcop_map, - &rcop_cleanup_iterator, - rc)); + GNUNET_assert(GNUNET_SYSERR != + GNUNET_CONTAINER_multihashmap32_iterate(rc->rcop_map, + &rcop_cleanup_iterator, + rc)); } @@ -558,9 +551,9 @@ rc_cleanup_operations (struct GNUNET_TESTBED_RunHandle *rc) * @param rc the run context */ static void -cancel_interrupt_task (struct GNUNET_TESTBED_RunHandle *rc) +cancel_interrupt_task(struct GNUNET_TESTBED_RunHandle *rc) { - GNUNET_SCHEDULER_cancel (rc->interrupt_task); + GNUNET_SCHEDULER_cancel(rc->interrupt_task); rc->interrupt_task = NULL; } @@ -572,38 +565,38 @@ cancel_interrupt_task (struct GNUNET_TESTBED_RunHandle *rc) * @param cls run context */ static void -wait_op_completion (void *cls) +wait_op_completion(void *cls) { struct GNUNET_TESTBED_RunHandle *rc = cls; struct RunContextOperation *rcop; - if ( (NULL == rc->cproc) - || (NULL == rc->c) - || (GNUNET_YES == rc->shutdown) ) - { - if (NULL != rc->peers) + if ((NULL == rc->cproc) + || (NULL == rc->c) + || (GNUNET_YES == rc->shutdown)) { - GNUNET_free (rc->peers); - rc->peers = NULL; + if (NULL != rc->peers) + { + GNUNET_free(rc->peers); + rc->peers = NULL; + } + goto cleanup_; } - goto cleanup_; - } if (NULL == rc->peers) goto cleanup_; rc->shutdown = GNUNET_YES; - rcop = GNUNET_new (struct RunContextOperation); + rcop = GNUNET_new(struct RunContextOperation); rcop->rc = rc; - rcop->op = GNUNET_TESTBED_shutdown_peers (rc->c, rcop, NULL, NULL); - GNUNET_assert (NULL != rcop->op); - DEBUG ("Shutting down peers\n"); - rc->pstart_time = GNUNET_TIME_absolute_get (); - insert_rcop (rc, rcop); + rcop->op = GNUNET_TESTBED_shutdown_peers(rc->c, rcop, NULL, NULL); + GNUNET_assert(NULL != rcop->op); + DEBUG("Shutting down peers\n"); + rc->pstart_time = GNUNET_TIME_absolute_get(); + insert_rcop(rc, rcop); return; - cleanup_: +cleanup_: rc->state = RC_PEERS_SHUTDOWN; - cancel_interrupt_task (rc); - cleanup (rc); + cancel_interrupt_task(rc); + cleanup(rc); } @@ -613,28 +606,28 @@ wait_op_completion (void *cls) * @param cls the RunContext which has to be acted upon */ static void -interrupt (void *cls) +interrupt(void *cls) { struct GNUNET_TESTBED_RunHandle *rc = cls; struct GNUNET_TESTBED_Controller *c = rc->c; unsigned int size; /* reschedule */ - rc->interrupt_task = GNUNET_SCHEDULER_add_shutdown (&interrupt, rc); - rc_cleanup_operations (rc); - if ( (GNUNET_NO == rc->shutdown) && - (NULL != c) && - (NULL != c->opc_map) && - (0 != (size = GNUNET_CONTAINER_multihashmap32_size (c->opc_map)))) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - "Shutdown postponed as there are %u operations currently active\n", - size); - c->opcq_empty_cb = &wait_op_completion; - c->opcq_empty_cls = rc; - return; - } - wait_op_completion (rc); + rc->interrupt_task = GNUNET_SCHEDULER_add_shutdown(&interrupt, rc); + rc_cleanup_operations(rc); + if ((GNUNET_NO == rc->shutdown) && + (NULL != c) && + (NULL != c->opc_map) && + (0 != (size = GNUNET_CONTAINER_multihashmap32_size(c->opc_map)))) + { + LOG(GNUNET_ERROR_TYPE_WARNING, + "Shutdown postponed as there are %u operations currently active\n", + size); + c->opcq_empty_cb = &wait_op_completion; + c->opcq_empty_cls = rc; + return; + } + wait_op_completion(rc); } @@ -646,12 +639,12 @@ interrupt (void *cls) * @return the representation string; this is NOT reentrant */ static const char * -prof_time (struct GNUNET_TESTBED_RunHandle *rc) +prof_time(struct GNUNET_TESTBED_RunHandle *rc) { struct GNUNET_TIME_Relative ptime; - ptime = GNUNET_TIME_absolute_get_duration (rc->pstart_time); - return GNUNET_STRINGS_relative_time_to_string (ptime, GNUNET_YES); + ptime = GNUNET_TIME_absolute_get_duration(rc->pstart_time); + return GNUNET_STRINGS_relative_time_to_string(ptime, GNUNET_YES); } @@ -661,23 +654,23 @@ prof_time (struct GNUNET_TESTBED_RunHandle *rc) * @param cls the RunHandle */ static void -start_peers_task (void *cls) +start_peers_task(void *cls) { struct GNUNET_TESTBED_RunHandle *rc = cls; struct RunContextOperation *rcop; unsigned int peer; - DEBUG ("Starting Peers\n"); - rc->pstart_time = GNUNET_TIME_absolute_get (); + DEBUG("Starting Peers\n"); + rc->pstart_time = GNUNET_TIME_absolute_get(); for (peer = 0; peer < rc->num_peers; peer++) - { - rcop = GNUNET_new (struct RunContextOperation); - rcop->rc = rc; - rcop->op = GNUNET_TESTBED_peer_start (NULL, rc->peers[peer], NULL, NULL); - GNUNET_assert (NULL != rcop->op); - rcop->cls = rc->peers[peer]; - insert_rcop (rc, rcop); - } + { + rcop = GNUNET_new(struct RunContextOperation); + rcop->rc = rc; + rcop->op = GNUNET_TESTBED_peer_start(NULL, rc->peers[peer], NULL, NULL); + GNUNET_assert(NULL != rcop->op); + rcop->cls = rc->peers[peer]; + insert_rcop(rc, rcop); + } rc->peer_count = 0; } @@ -692,31 +685,31 @@ start_peers_task (void *cls) * @param emsg NULL if peer is not NULL; else MAY contain the error description */ static void -peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) +peer_create_cb(void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) { struct RunContextOperation *rcop = cls; struct GNUNET_TESTBED_RunHandle *rc; - GNUNET_assert (NULL != rcop); - GNUNET_assert (NULL != (rc = rcop->rc)); - remove_rcop (rc, rcop); - GNUNET_TESTBED_operation_done (rcop->op); - GNUNET_free (rcop); + GNUNET_assert(NULL != rcop); + GNUNET_assert(NULL != (rc = rcop->rc)); + remove_rcop(rc, rcop); + GNUNET_TESTBED_operation_done(rcop->op); + GNUNET_free(rcop); if (NULL == peer) - { - if (NULL != emsg) - LOG (GNUNET_ERROR_TYPE_ERROR, "Error while creating a peer: %s\n", - emsg); - GNUNET_SCHEDULER_shutdown (); - return; - } + { + if (NULL != emsg) + LOG(GNUNET_ERROR_TYPE_ERROR, "Error while creating a peer: %s\n", + emsg); + GNUNET_SCHEDULER_shutdown(); + return; + } rc->peers[rc->peer_count] = peer; rc->peer_count++; if (rc->peer_count < rc->num_peers) return; - DEBUG ("%u peers created in %s\n", rc->num_peers, prof_time (rc)); + DEBUG("%u peers created in %s\n", rc->num_peers, prof_time(rc)); rc->state = RC_PEERS_CREATED; - GNUNET_SCHEDULER_add_now (&start_peers_task, rc); + GNUNET_SCHEDULER_add_now(&start_peers_task, rc); } @@ -726,13 +719,13 @@ peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) * @param rc the RunContext */ static void -call_master (struct GNUNET_TESTBED_RunHandle *rc) +call_master(struct GNUNET_TESTBED_RunHandle *rc) { - GNUNET_SCHEDULER_cancel (rc->timeout_task); + GNUNET_SCHEDULER_cancel(rc->timeout_task); rc->timeout_task = NULL; if (NULL != rc->test_master) - rc->test_master (rc->test_master_cls, rc, rc->num_peers, rc->peers, - rc->links_succeeded, rc->links_failed); + rc->test_master(rc->test_master_cls, rc, rc->num_peers, rc->peers, + rc->links_succeeded, rc->links_failed); } @@ -746,18 +739,18 @@ call_master (struct GNUNET_TESTBED_RunHandle *rc) * @param nfailures the number of overlay connects which failed */ static void -topology_completion_callback (void *cls, unsigned int nsuccess, - unsigned int nfailures) +topology_completion_callback(void *cls, unsigned int nsuccess, + unsigned int nfailures) { struct GNUNET_TESTBED_RunHandle *rc = cls; - DEBUG ("Overlay topology generated in %s\n", prof_time (rc)); - GNUNET_TESTBED_operation_done (rc->topology_operation); + DEBUG("Overlay topology generated in %s\n", prof_time(rc)); + GNUNET_TESTBED_operation_done(rc->topology_operation); rc->topology_operation = NULL; rc->links_succeeded = nsuccess; rc->links_failed = nfailures; rc->state = RC_READY; - call_master (rc); + call_master(rc); } @@ -767,30 +760,30 @@ topology_completion_callback (void *cls, unsigned int nsuccess, * @param rc the RunContext */ static void -create_peers (struct GNUNET_TESTBED_RunHandle *rc) +create_peers(struct GNUNET_TESTBED_RunHandle *rc) { struct RunContextOperation *rcop; unsigned int peer; - DEBUG ("Creating peers\n"); - rc->pstart_time = GNUNET_TIME_absolute_get (); + DEBUG("Creating peers\n"); + rc->pstart_time = GNUNET_TIME_absolute_get(); rc->peers = - GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Peer *) * rc->num_peers); - GNUNET_assert (NULL != rc->c); + GNUNET_malloc(sizeof(struct GNUNET_TESTBED_Peer *) * rc->num_peers); + GNUNET_assert(NULL != rc->c); rc->peer_count = 0; for (peer = 0; peer < rc->num_peers; peer++) - { - rcop = GNUNET_new (struct RunContextOperation); - rcop->rc = rc; - rcop->op = - GNUNET_TESTBED_peer_create (rc->c, - (0 == - rc->num_hosts) ? rc->h : rc->hosts[peer % - rc->num_hosts], - rc->cfg, &peer_create_cb, rcop); - GNUNET_assert (NULL != rcop->op); - insert_rcop (rc, rcop); - } + { + rcop = GNUNET_new(struct RunContextOperation); + rcop->rc = rc; + rcop->op = + GNUNET_TESTBED_peer_create(rc->c, + (0 == + rc->num_hosts) ? rc->h : rc->hosts[peer % + rc->num_hosts], + rc->cfg, &peer_create_cb, rcop); + GNUNET_assert(NULL != rcop->op); + insert_rcop(rc, rcop); + } } @@ -802,160 +795,166 @@ create_peers (struct GNUNET_TESTBED_RunHandle *rc) * @param event information about the event */ static void -event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) +event_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event) { struct GNUNET_TESTBED_RunHandle *rc = cls; struct RunContextOperation *rcop; if (RC_INIT == rc->state) - { - switch (event->type) { - case GNUNET_TESTBED_ET_OPERATION_FINISHED: - rcop = event->op_cls; - if (NULL != event->details.operation_finished.emsg) - { - LOG (GNUNET_ERROR_TYPE_ERROR, _("Linking controllers failed. Exiting")); - GNUNET_SCHEDULER_shutdown (); - } - else - rc->reg_hosts++; - GNUNET_assert (event->op == rcop->op); - remove_rcop (rc, rcop); - GNUNET_TESTBED_operation_done (rcop->op); - GNUNET_free (rcop); - if (rc->reg_hosts == rc->num_hosts) - { - rc->state = RC_LINKED; - create_peers (rc); - } - return; - default: - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - return; + switch (event->type) + { + case GNUNET_TESTBED_ET_OPERATION_FINISHED: + rcop = event->op_cls; + if (NULL != event->details.operation_finished.emsg) + { + LOG(GNUNET_ERROR_TYPE_ERROR, _("Linking controllers failed. Exiting")); + GNUNET_SCHEDULER_shutdown(); + } + else + rc->reg_hosts++; + GNUNET_assert(event->op == rcop->op); + remove_rcop(rc, rcop); + GNUNET_TESTBED_operation_done(rcop->op); + GNUNET_free(rcop); + if (rc->reg_hosts == rc->num_hosts) + { + rc->state = RC_LINKED; + create_peers(rc); + } + return; + + default: + GNUNET_break(0); + GNUNET_SCHEDULER_shutdown(); + return; + } } - } if (GNUNET_TESTBED_ET_OPERATION_FINISHED != event->type) goto call_cc; - if (NULL == (rcop = search_rcop (rc, event->op))) + if (NULL == (rcop = search_rcop(rc, event->op))) goto call_cc; - remove_rcop (rc, rcop); - GNUNET_TESTBED_operation_done (rcop->op); - GNUNET_free (rcop); - if ( (GNUNET_NO == rc->shutdown) - && (NULL != event->details.operation_finished.emsg) ) - { - LOG (GNUNET_ERROR_TYPE_ERROR, "A operation has failed with error: %s\n", - event->details.operation_finished.emsg); - GNUNET_SCHEDULER_shutdown (); - return; - } - GNUNET_assert (GNUNET_YES == rc->shutdown); + remove_rcop(rc, rcop); + GNUNET_TESTBED_operation_done(rcop->op); + GNUNET_free(rcop); + if ((GNUNET_NO == rc->shutdown) + && (NULL != event->details.operation_finished.emsg)) + { + LOG(GNUNET_ERROR_TYPE_ERROR, "A operation has failed with error: %s\n", + event->details.operation_finished.emsg); + GNUNET_SCHEDULER_shutdown(); + return; + } + GNUNET_assert(GNUNET_YES == rc->shutdown); switch (rc->state) - { - case RC_LINKED: - case RC_PEERS_CREATED: - case RC_READY: - rc->state = RC_PEERS_SHUTDOWN; - GNUNET_free_non_null (rc->peers); - rc->peers = NULL; - DEBUG ("Peers shut down in %s\n", prof_time (rc)); - GNUNET_SCHEDULER_shutdown (); - break; - default: - GNUNET_assert (0); - } + { + case RC_LINKED: + case RC_PEERS_CREATED: + case RC_READY: + rc->state = RC_PEERS_SHUTDOWN; + GNUNET_free_non_null(rc->peers); + rc->peers = NULL; + DEBUG("Peers shut down in %s\n", prof_time(rc)); + GNUNET_SCHEDULER_shutdown(); + break; + + default: + GNUNET_assert(0); + } return; call_cc: if ((0 != (rc->event_mask & (1LL << event->type))) && (NULL != rc->cc)) - rc->cc (rc->cc_cls, event); + rc->cc(rc->cc_cls, event); if (GNUNET_TESTBED_ET_PEER_START != event->type) return; - if (NULL == (rcop = search_rcop (rc, event->op))) /* Not our operation */ + if (NULL == (rcop = search_rcop(rc, event->op))) /* Not our operation */ return; - remove_rcop (rc, rcop); - GNUNET_TESTBED_operation_done (rcop->op); - GNUNET_free (rcop); + remove_rcop(rc, rcop); + GNUNET_TESTBED_operation_done(rcop->op); + GNUNET_free(rcop); rc->peer_count++; if (rc->peer_count < rc->num_peers) return; - DEBUG ("%u peers started in %s\n", rc->num_peers, prof_time (rc)); + DEBUG("%u peers started in %s\n", rc->num_peers, prof_time(rc)); if (GNUNET_TESTBED_TOPOLOGY_NONE != rc->topology) - { - switch (rc->topology) { - case GNUNET_TESTBED_TOPOLOGY_NONE: - GNUNET_assert (0); - case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: - case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: - case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: - rc->topology_operation = - GNUNET_TESTBED_overlay_configure_topology (NULL, rc->num_peers, - rc->peers, &rc->num_oc, - &topology_completion_callback, - rc, - rc->topology, - rc->random_links, - GNUNET_TESTBED_TOPOLOGY_OPTION_END); - break; - case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: - GNUNET_assert (NULL != rc->topo_file); - rc->topology_operation = - GNUNET_TESTBED_overlay_configure_topology (NULL, rc->num_peers, - rc->peers, &rc->num_oc, - &topology_completion_callback, - rc, - rc->topology, - rc->topo_file, - GNUNET_TESTBED_TOPOLOGY_OPTION_END); - break; - case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: - { - unsigned long long number; - unsigned int cap; - GNUNET_assert (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_number (rc->cfg, TESTBED_CONFIG_SECTION, + switch (rc->topology) + { + case GNUNET_TESTBED_TOPOLOGY_NONE: + GNUNET_assert(0); + + case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: + case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: + case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: + rc->topology_operation = + GNUNET_TESTBED_overlay_configure_topology(NULL, rc->num_peers, + rc->peers, &rc->num_oc, + &topology_completion_callback, + rc, + rc->topology, + rc->random_links, + GNUNET_TESTBED_TOPOLOGY_OPTION_END); + break; + + case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: + GNUNET_assert(NULL != rc->topo_file); + rc->topology_operation = + GNUNET_TESTBED_overlay_configure_topology(NULL, rc->num_peers, + rc->peers, &rc->num_oc, + &topology_completion_callback, + rc, + rc->topology, + rc->topo_file, + GNUNET_TESTBED_TOPOLOGY_OPTION_END); + break; + + case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: + { + unsigned long long number; + unsigned int cap; + GNUNET_assert(GNUNET_OK == + GNUNET_CONFIGURATION_get_value_number(rc->cfg, TESTBED_CONFIG_SECTION, SCALE_FREE_CAP, &number)); - cap = (unsigned int) number; - GNUNET_assert (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_number (rc->cfg, TESTBED_CONFIG_SECTION, + cap = (unsigned int)number; + GNUNET_assert(GNUNET_OK == + GNUNET_CONFIGURATION_get_value_number(rc->cfg, TESTBED_CONFIG_SECTION, SCALE_FREE_M, &number)); - rc->topology_operation = - GNUNET_TESTBED_overlay_configure_topology (NULL, rc->num_peers, - rc->peers, &rc->num_oc, - &topology_completion_callback, - rc, - rc->topology, - cap, /* uint16_t */ - (unsigned int) number, /* uint8_t */ - GNUNET_TESTBED_TOPOLOGY_OPTION_END); - } - break; - default: - rc->topology_operation = - GNUNET_TESTBED_overlay_configure_topology (NULL, rc->num_peers, - rc->peers, &rc->num_oc, - &topology_completion_callback, - rc, - rc->topology, - GNUNET_TESTBED_TOPOLOGY_OPTION_END); - } - if (NULL == rc->topology_operation) - LOG (GNUNET_ERROR_TYPE_WARNING, - "Not generating a topology. Check number of peers\n"); - else - { - DEBUG ("Creating overlay topology\n"); - rc->pstart_time = GNUNET_TIME_absolute_get (); - return; + rc->topology_operation = + GNUNET_TESTBED_overlay_configure_topology(NULL, rc->num_peers, + rc->peers, &rc->num_oc, + &topology_completion_callback, + rc, + rc->topology, + cap, /* uint16_t */ + (unsigned int)number, /* uint8_t */ + GNUNET_TESTBED_TOPOLOGY_OPTION_END); + } + break; + + default: + rc->topology_operation = + GNUNET_TESTBED_overlay_configure_topology(NULL, rc->num_peers, + rc->peers, &rc->num_oc, + &topology_completion_callback, + rc, + rc->topology, + GNUNET_TESTBED_TOPOLOGY_OPTION_END); + } + if (NULL == rc->topology_operation) + LOG(GNUNET_ERROR_TYPE_WARNING, + "Not generating a topology. Check number of peers\n"); + else + { + DEBUG("Creating overlay topology\n"); + rc->pstart_time = GNUNET_TIME_absolute_get(); + return; + } } - } rc->state = RC_READY; - call_master (rc); + call_master(rc); } @@ -965,7 +964,7 @@ call_cc: * @param cls the RunContext */ static void -register_hosts (void *cls); +register_hosts(void *cls); /** @@ -975,20 +974,20 @@ register_hosts (void *cls); * @param emsg the error message; NULL if host registration is successful */ static void -host_registration_completion (void *cls, const char *emsg) +host_registration_completion(void *cls, const char *emsg) { struct GNUNET_TESTBED_RunHandle *rc = cls; rc->reg_handle = NULL; if (NULL != emsg) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - _("Host registration failed for a host. Error: %s\n"), emsg); - GNUNET_SCHEDULER_shutdown (); - return; - } - rc->register_hosts_task = GNUNET_SCHEDULER_add_now (®ister_hosts, - rc); + { + LOG(GNUNET_ERROR_TYPE_WARNING, + _("Host registration failed for a host. Error: %s\n"), emsg); + GNUNET_SCHEDULER_shutdown(); + return; + } + rc->register_hosts_task = GNUNET_SCHEDULER_add_now(®ister_hosts, + rc); } @@ -998,7 +997,7 @@ host_registration_completion (void *cls, const char *emsg) * @param cls RunContext */ static void -register_hosts (void *cls) +register_hosts(void *cls) { struct GNUNET_TESTBED_RunHandle *rc = cls; struct RunContextOperation *rcop; @@ -1006,25 +1005,25 @@ register_hosts (void *cls) rc->register_hosts_task = NULL; if (rc->reg_hosts == rc->num_hosts) - { - DEBUG ("All hosts successfully registered\n"); - /* Start slaves */ - for (slave = 0; slave < rc->num_hosts; slave++) { - rcop = GNUNET_new (struct RunContextOperation); - rcop->rc = rc; - rcop->op = - GNUNET_TESTBED_controller_link (rcop, rc->c, rc->hosts[slave], - rc->h, GNUNET_YES); - GNUNET_assert (NULL != rcop->op); - insert_rcop (rc, rcop); + DEBUG("All hosts successfully registered\n"); + /* Start slaves */ + for (slave = 0; slave < rc->num_hosts; slave++) + { + rcop = GNUNET_new(struct RunContextOperation); + rcop->rc = rc; + rcop->op = + GNUNET_TESTBED_controller_link(rcop, rc->c, rc->hosts[slave], + rc->h, GNUNET_YES); + GNUNET_assert(NULL != rcop->op); + insert_rcop(rc, rcop); + } + rc->reg_hosts = 0; + return; } - rc->reg_hosts = 0; - return; - } rc->reg_handle = - GNUNET_TESTBED_register_host (rc->c, rc->hosts[rc->reg_hosts], - host_registration_completion, rc); + GNUNET_TESTBED_register_host(rc->c, rc->hosts[rc->reg_hosts], + host_registration_completion, rc); rc->reg_hosts++; } @@ -1039,37 +1038,37 @@ register_hosts (void *cls) * GNUNET_TESTBED_controller_stop() shouldn't be called in this case */ static void -controller_status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, - int status) +controller_status_cb(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, + int status) { struct GNUNET_TESTBED_RunHandle *rc = cls; uint64_t event_mask; if (status != GNUNET_OK) - { - rc->cproc = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Controller crash detected. Shutting down.\n")); - GNUNET_SCHEDULER_shutdown (); - return; - } - GNUNET_CONFIGURATION_destroy (rc->cfg); - rc->cfg = GNUNET_CONFIGURATION_dup (cfg); + { + rc->cproc = NULL; + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + _("Controller crash detected. Shutting down.\n")); + GNUNET_SCHEDULER_shutdown(); + return; + } + GNUNET_CONFIGURATION_destroy(rc->cfg); + rc->cfg = GNUNET_CONFIGURATION_dup(cfg); event_mask = rc->event_mask; event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); if (rc->topology < GNUNET_TESTBED_TOPOLOGY_NONE) event_mask |= GNUNET_TESTBED_ET_CONNECT; rc->c = - GNUNET_TESTBED_controller_connect (rc->h, event_mask, &event_cb, rc); + GNUNET_TESTBED_controller_connect(rc->h, event_mask, &event_cb, rc); if (0 < rc->num_hosts) - { - rc->reg_hosts = 0; - rc->register_hosts_task = GNUNET_SCHEDULER_add_now (®ister_hosts, rc); - return; - } + { + rc->reg_hosts = 0; + rc->register_hosts_task = GNUNET_SCHEDULER_add_now(®ister_hosts, rc); + return; + } rc->state = RC_LINKED; - create_peers (rc); + create_peers(rc); } @@ -1086,26 +1085,26 @@ controller_status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort */ static int -netint_proc (void *cls, const char *name, int isDefault, - const struct sockaddr *addr, const struct sockaddr *broadcast_addr, - const struct sockaddr *netmask, socklen_t addrlen) +netint_proc(void *cls, const char *name, int isDefault, + const struct sockaddr *addr, const struct sockaddr *broadcast_addr, + const struct sockaddr *netmask, socklen_t addrlen) { struct GNUNET_TESTBED_RunHandle *rc = cls; char hostip[NI_MAXHOST]; char *buf; - if (sizeof (struct sockaddr_in) != addrlen) + if (sizeof(struct sockaddr_in) != addrlen) return GNUNET_OK; /* Only consider IPv4 for now */ if (0 != - getnameinfo (addr, addrlen, hostip, NI_MAXHOST, NULL, 0, NI_NUMERICHOST)) - GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "getnameinfo"); + getnameinfo(addr, addrlen, hostip, NI_MAXHOST, NULL, 0, NI_NUMERICHOST)) + GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "getnameinfo"); if (NULL == rc->trusted_ip) - { - rc->trusted_ip = GNUNET_strdup (hostip); - return GNUNET_YES; - } - (void) GNUNET_asprintf (&buf, "%s; %s", rc->trusted_ip, hostip); - GNUNET_free (rc->trusted_ip); + { + rc->trusted_ip = GNUNET_strdup(hostip); + return GNUNET_YES; + } + (void)GNUNET_asprintf(&buf, "%s; %s", rc->trusted_ip, hostip); + GNUNET_free(rc->trusted_ip); rc->trusted_ip = buf; return GNUNET_YES; } @@ -1122,67 +1121,67 @@ netint_proc (void *cls, const char *name, int isDefault, * @param status GNUNET_YES if it is habitable; GNUNET_NO if not */ static void -host_habitable_cb (void *cls, const struct GNUNET_TESTBED_Host *host, - int status) +host_habitable_cb(void *cls, const struct GNUNET_TESTBED_Host *host, + int status) { struct CompatibilityCheckContext *hc = cls; struct GNUNET_TESTBED_RunHandle *rc; struct GNUNET_TESTBED_Host **old_hosts; unsigned int nhost; - GNUNET_assert (NULL != (rc = hc->rc)); + GNUNET_assert(NULL != (rc = hc->rc)); nhost = hc->index; - GNUNET_assert (nhost <= rc->num_hosts); - GNUNET_assert (host == rc->hosts[nhost]); + GNUNET_assert(nhost <= rc->num_hosts); + GNUNET_assert(host == rc->hosts[nhost]); hc->h = NULL; if (GNUNET_NO == status) - { - if ((NULL != host) && (NULL != GNUNET_TESTBED_host_get_hostname (host))) - LOG (GNUNET_ERROR_TYPE_ERROR, _("Host %s cannot start testbed\n"), - GNUNET_TESTBED_host_get_hostname (host)); - else - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Testbed cannot be started on localhost\n")); - GNUNET_SCHEDULER_shutdown (); - return; - } + { + if ((NULL != host) && (NULL != GNUNET_TESTBED_host_get_hostname(host))) + LOG(GNUNET_ERROR_TYPE_ERROR, _("Host %s cannot start testbed\n"), + GNUNET_TESTBED_host_get_hostname(host)); + else + LOG(GNUNET_ERROR_TYPE_ERROR, + _("Testbed cannot be started on localhost\n")); + GNUNET_SCHEDULER_shutdown(); + return; + } rc->reg_hosts++; if (rc->reg_hosts < rc->num_hosts) return; - GNUNET_free (rc->hclist); + GNUNET_free(rc->hclist); rc->hclist = NULL; rc->h = rc->hosts[0]; rc->num_hosts--; if (0 < rc->num_hosts) - { - old_hosts = rc->hosts; - rc->hosts = - GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Host *) * rc->num_hosts); - GNUNET_memcpy (rc->hosts, &old_hosts[1], - (sizeof (struct GNUNET_TESTBED_Host *) * rc->num_hosts)); - GNUNET_free (old_hosts); - } + { + old_hosts = rc->hosts; + rc->hosts = + GNUNET_malloc(sizeof(struct GNUNET_TESTBED_Host *) * rc->num_hosts); + GNUNET_memcpy(rc->hosts, &old_hosts[1], + (sizeof(struct GNUNET_TESTBED_Host *) * rc->num_hosts)); + GNUNET_free(old_hosts); + } else - { - GNUNET_free (rc->hosts); - rc->hosts = NULL; - } - GNUNET_TESTBED_host_resolve_ (rc->h); + { + GNUNET_free(rc->hosts); + rc->hosts = NULL; + } + GNUNET_TESTBED_host_resolve_(rc->h); for (nhost = 0; nhost < rc->num_hosts; nhost++) - GNUNET_TESTBED_host_resolve_ (rc->hosts[nhost]); - GNUNET_OS_network_interfaces_list (netint_proc, rc); + GNUNET_TESTBED_host_resolve_(rc->hosts[nhost]); + GNUNET_OS_network_interfaces_list(netint_proc, rc); if (NULL == rc->trusted_ip) - rc->trusted_ip = GNUNET_strdup ("127.0.0.1"); + rc->trusted_ip = GNUNET_strdup("127.0.0.1"); rc->cproc = - GNUNET_TESTBED_controller_start (rc->trusted_ip, rc->h, - &controller_status_cb, rc); - GNUNET_free (rc->trusted_ip); + GNUNET_TESTBED_controller_start(rc->trusted_ip, rc->h, + &controller_status_cb, rc); + GNUNET_free(rc->trusted_ip); rc->trusted_ip = NULL; if (NULL == rc->cproc) - { - LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot start the master controller")); - GNUNET_SCHEDULER_shutdown (); - } + { + LOG(GNUNET_ERROR_TYPE_ERROR, _("Cannot start the master controller")); + GNUNET_SCHEDULER_shutdown(); + } } @@ -1192,17 +1191,17 @@ host_habitable_cb (void *cls, const struct GNUNET_TESTBED_Host *host, * @param cls the RunContext */ static void -timeout_task (void *cls) +timeout_task(void *cls) { struct GNUNET_TESTBED_RunHandle *rc = cls; rc->timeout_task = NULL; - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Shutting down testbed due to timeout while setup.\n")); - GNUNET_SCHEDULER_shutdown (); - if (NULL != rc->test_master) - rc->test_master (rc->test_master_cls, rc, 0, NULL, 0, 0); - rc->test_master = NULL; + LOG(GNUNET_ERROR_TYPE_ERROR, + _("Shutting down testbed due to timeout while setup.\n")); + GNUNET_SCHEDULER_shutdown(); + if (NULL != rc->test_master) + rc->test_master(rc->test_master_cls, rc, 0, NULL, 0, 0); + rc->test_master = NULL; } @@ -1234,12 +1233,12 @@ timeout_task (void *cls) * @param test_master_cls closure for 'test_master'. */ void -GNUNET_TESTBED_run (const char *host_filename, - const struct GNUNET_CONFIGURATION_Handle *cfg, - unsigned int num_peers, uint64_t event_mask, - GNUNET_TESTBED_ControllerCallback cc, void *cc_cls, - GNUNET_TESTBED_TestMaster test_master, - void *test_master_cls) +GNUNET_TESTBED_run(const char *host_filename, + const struct GNUNET_CONFIGURATION_Handle *cfg, + unsigned int num_peers, uint64_t event_mask, + GNUNET_TESTBED_ControllerCallback cc, void *cc_cls, + GNUNET_TESTBED_TestMaster test_master, + void *test_master_cls) { struct GNUNET_TESTBED_RunHandle *rc; char *topology; @@ -1249,33 +1248,33 @@ GNUNET_TESTBED_run (const char *host_filename, unsigned int hid; unsigned int nhost; - GNUNET_assert (num_peers > 0); - rc = GNUNET_new (struct GNUNET_TESTBED_RunHandle); - rc->cfg = GNUNET_CONFIGURATION_dup (cfg); + 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); + 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; - } + { + 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 = - GNUNET_TESTBED_hosts_load_from_file (host_filename, rc->cfg, - &rc->hosts); - if (0 == rc->num_hosts) { - LOG (GNUNET_ERROR_TYPE_WARNING, - _("No hosts loaded. Need at least one host\n")); - goto error_cleanup; + rc->num_hosts = + GNUNET_TESTBED_hosts_load_from_file(host_filename, rc->cfg, + &rc->hosts); + if (0 == rc->num_hosts) + { + LOG(GNUNET_ERROR_TYPE_WARNING, + _("No hosts loaded. Need at least one host\n")); + goto error_cleanup; + } } - } else - rc->h = GNUNET_TESTBED_host_create (NULL, NULL, rc->cfg, 0); + rc->h = GNUNET_TESTBED_host_create(NULL, NULL, rc->cfg, 0); #endif rc->num_peers = num_peers; rc->event_mask = event_mask; @@ -1286,158 +1285,162 @@ GNUNET_TESTBED_run (const char *host_filename, rc->state = RC_INIT; rc->topology = GNUNET_TESTBED_TOPOLOGY_NONE; if (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_string (rc->cfg, TESTBED_CONFIG_SECTION, - "OVERLAY_TOPOLOGY", &topology)) - { - if (GNUNET_NO == GNUNET_TESTBED_topology_get_ (&rc->topology, topology)) + GNUNET_CONFIGURATION_get_value_string(rc->cfg, TESTBED_CONFIG_SECTION, + "OVERLAY_TOPOLOGY", &topology)) { - GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, TESTBED_CONFIG_SECTION, - "OVERLAY_TOPLOGY", - _ - ("Specified topology must be supported by testbed")); + if (GNUNET_NO == GNUNET_TESTBED_topology_get_(&rc->topology, topology)) + { + GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, TESTBED_CONFIG_SECTION, + "OVERLAY_TOPLOGY", + _ + ("Specified topology must be supported by testbed")); + } + GNUNET_free(topology); } - GNUNET_free (topology); - } switch (rc->topology) - { - case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: - case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: - case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (rc->cfg, TESTBED_CONFIG_SECTION, - "OVERLAY_RANDOM_LINKS", - &number)) - { - /* OVERLAY option RANDOM & SMALL_WORLD_RING requires OVERLAY_RANDOM_LINKS - * option to be set to the number of random links to be established */ - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, TESTBED_CONFIG_SECTION, - "OVERLAY_RANDOM_LINKS"); - goto error_cleanup; - } - if (number > UINT32_MAX) { - GNUNET_break (0); /* Too big number */ - goto error_cleanup; - } - rc->random_links = (unsigned int) number; - break; - case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (rc->cfg, TESTBED_CONFIG_SECTION, - "OVERLAY_TOPOLOGY_FILE", - &rc->topo_file)) - { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, TESTBED_CONFIG_SECTION, - "OVERLAY_TOPOLOGY_FILE"); - goto error_cleanup; - } - goto warn_ignore; - case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (rc->cfg, TESTBED_CONFIG_SECTION, - SCALE_FREE_CAP, &number)) - { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, TESTBED_CONFIG_SECTION, - SCALE_FREE_CAP); - goto error_cleanup; - } - if (UINT16_MAX < number) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Maximum number of edges a peer can have in a scale free topology" - " cannot be more than %u. Given `%s = %llu'"), UINT16_MAX, - SCALE_FREE_CAP, number); - goto error_cleanup; - } - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (rc->cfg, TESTBED_CONFIG_SECTION, - SCALE_FREE_M, &number)) - { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, TESTBED_CONFIG_SECTION, - SCALE_FREE_M); - goto error_cleanup; - } - if (UINT8_MAX < number) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _("The number of edges that can established when adding a new node" - " to scale free topology cannot be more than %u. Given `%s = %llu'"), - UINT8_MAX, SCALE_FREE_M, number); - goto error_cleanup; + case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: + case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: + case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_number(rc->cfg, TESTBED_CONFIG_SECTION, + "OVERLAY_RANDOM_LINKS", + &number)) + { + /* OVERLAY option RANDOM & SMALL_WORLD_RING requires OVERLAY_RANDOM_LINKS + * option to be set to the number of random links to be established */ + GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, TESTBED_CONFIG_SECTION, + "OVERLAY_RANDOM_LINKS"); + goto error_cleanup; + } + if (number > UINT32_MAX) + { + GNUNET_break(0); /* Too big number */ + goto error_cleanup; + } + rc->random_links = (unsigned int)number; + break; + + case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_filename(rc->cfg, TESTBED_CONFIG_SECTION, + "OVERLAY_TOPOLOGY_FILE", + &rc->topo_file)) + { + GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, TESTBED_CONFIG_SECTION, + "OVERLAY_TOPOLOGY_FILE"); + goto error_cleanup; + } + goto warn_ignore; + + case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_number(rc->cfg, TESTBED_CONFIG_SECTION, + SCALE_FREE_CAP, &number)) + { + GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, TESTBED_CONFIG_SECTION, + SCALE_FREE_CAP); + goto error_cleanup; + } + if (UINT16_MAX < number) + { + LOG(GNUNET_ERROR_TYPE_ERROR, + _("Maximum number of edges a peer can have in a scale free topology" + " cannot be more than %u. Given `%s = %llu'"), UINT16_MAX, + SCALE_FREE_CAP, number); + goto error_cleanup; + } + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_number(rc->cfg, TESTBED_CONFIG_SECTION, + SCALE_FREE_M, &number)) + { + GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, TESTBED_CONFIG_SECTION, + SCALE_FREE_M); + goto error_cleanup; + } + if (UINT8_MAX < number) + { + LOG(GNUNET_ERROR_TYPE_ERROR, + _("The number of edges that can established when adding a new node" + " to scale free topology cannot be more than %u. Given `%s = %llu'"), + UINT8_MAX, SCALE_FREE_M, number); + goto error_cleanup; + } + goto warn_ignore; + + case GNUNET_TESTBED_TOPOLOGY_OPTION_END: + /* not allowed! */ + GNUNET_assert(0); + + default: +warn_ignore: + /* Warn if OVERLAY_RANDOM_LINKS is present that it will be ignored */ + if (GNUNET_YES == + GNUNET_CONFIGURATION_have_value(rc->cfg, TESTBED_CONFIG_SECTION, + "OVERLAY_RANDOM_LINKS")) + LOG(GNUNET_ERROR_TYPE_WARNING, + "Ignoring value of `OVERLAY_RANDOM_LINKS' in given configuration\n"); + break; } - goto warn_ignore; - case GNUNET_TESTBED_TOPOLOGY_OPTION_END: - /* not allowed! */ - GNUNET_assert (0); - default: - warn_ignore: - /* Warn if OVERLAY_RANDOM_LINKS is present that it will be ignored */ - if (GNUNET_YES == - GNUNET_CONFIGURATION_have_value (rc->cfg, TESTBED_CONFIG_SECTION, - "OVERLAY_RANDOM_LINKS")) - LOG (GNUNET_ERROR_TYPE_WARNING, - "Ignoring value of `OVERLAY_RANDOM_LINKS' in given configuration\n"); - break; - } if (0 != rc->num_hosts) - { - rc->hclist = GNUNET_malloc (sizeof (struct CompatibilityCheckContext) - * rc->num_hosts); - for (nhost = 0; nhost < rc->num_hosts; nhost++) { - hc = &rc->hclist[nhost]; - hc->index = nhost; - hc->rc = rc; - hc->h = GNUNET_TESTBED_is_host_habitable (rc->hosts[nhost], rc->cfg, - &host_habitable_cb, hc); - if (NULL == hc->h) - { - GNUNET_break (0); - for (nhost = 0; nhost < rc->num_hosts; nhost++) + rc->hclist = GNUNET_malloc(sizeof(struct CompatibilityCheckContext) + * rc->num_hosts); + for (nhost = 0; nhost < rc->num_hosts; nhost++) { hc = &rc->hclist[nhost]; - if (NULL != hc->h) - GNUNET_TESTBED_is_host_habitable_cancel (hc->h); + hc->index = nhost; + hc->rc = rc; + hc->h = GNUNET_TESTBED_is_host_habitable(rc->hosts[nhost], rc->cfg, + &host_habitable_cb, hc); + if (NULL == hc->h) + { + GNUNET_break(0); + for (nhost = 0; nhost < rc->num_hosts; nhost++) + { + hc = &rc->hclist[nhost]; + if (NULL != hc->h) + GNUNET_TESTBED_is_host_habitable_cancel(hc->h); + } + GNUNET_free(rc->hclist); + rc->hclist = NULL; + goto error_cleanup; + } } - GNUNET_free (rc->hclist); - rc->hclist = NULL; - goto error_cleanup; - } } - } else rc->cproc = - GNUNET_TESTBED_controller_start ("127.0.0.1", rc->h, - &controller_status_cb, rc); - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, TESTBED_CONFIG_SECTION, - "SETUP_TIMEOUT", - &timeout)) - { - timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, - DEFAULT_SETUP_TIMEOUT); - } - rc->rcop_map = GNUNET_CONTAINER_multihashmap32_create (256); + GNUNET_TESTBED_controller_start("127.0.0.1", rc->h, + &controller_status_cb, rc); + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(cfg, TESTBED_CONFIG_SECTION, + "SETUP_TIMEOUT", + &timeout)) + { + timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, + DEFAULT_SETUP_TIMEOUT); + } + rc->rcop_map = GNUNET_CONTAINER_multihashmap32_create(256); rc->timeout_task = - GNUNET_SCHEDULER_add_delayed (timeout, &timeout_task, rc); - GNUNET_assert (NULL == rc->interrupt_task); + GNUNET_SCHEDULER_add_delayed(timeout, &timeout_task, rc); + GNUNET_assert(NULL == rc->interrupt_task); rc->interrupt_task = - GNUNET_SCHEDULER_add_shutdown (&interrupt, - rc); + GNUNET_SCHEDULER_add_shutdown(&interrupt, + rc); return; error_cleanup: if (NULL != rc->h) - GNUNET_TESTBED_host_destroy (rc->h); + GNUNET_TESTBED_host_destroy(rc->h); if (NULL != rc->hosts) - { - for (hid = 0; hid < rc->num_hosts; hid++) - if (NULL != rc->hosts[hid]) - GNUNET_TESTBED_host_destroy (rc->hosts[hid]); - GNUNET_free (rc->hosts); - } + { + for (hid = 0; hid < rc->num_hosts; hid++) + if (NULL != rc->hosts[hid]) + GNUNET_TESTBED_host_destroy(rc->hosts[hid]); + GNUNET_free(rc->hosts); + } if (NULL != rc->cfg) - GNUNET_CONFIGURATION_destroy (rc->cfg); - GNUNET_free (rc); + GNUNET_CONFIGURATION_destroy(rc->cfg); + GNUNET_free(rc); } @@ -1449,7 +1452,7 @@ error_cleanup: * @return handle to the master controller */ struct GNUNET_TESTBED_Controller * -GNUNET_TESTBED_run_get_controller_handle (struct GNUNET_TESTBED_RunHandle *h) +GNUNET_TESTBED_run_get_controller_handle(struct GNUNET_TESTBED_RunHandle *h) { return h->c; } diff --git a/src/testbed/testbed_api_topology.c b/src/testbed/testbed_api_topology.c index 59512d59f..58ccf4580 100644 --- a/src/testbed/testbed_api_topology.c +++ b/src/testbed/testbed_api_topology.c @@ -11,7 +11,7 @@ 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 . @@ -33,8 +33,8 @@ /** * Generic loggins shorthand */ -#define LOG(kind,...) \ - GNUNET_log_from (kind, "testbed-api-topology", __VA_ARGS__) +#define LOG(kind, ...) \ + GNUNET_log_from(kind, "testbed-api-topology", __VA_ARGS__) /** @@ -52,9 +52,7 @@ struct TopologyContext; /** * Representation of an overlay link */ -struct OverlayLink -{ - +struct OverlayLink { /** * An operation corresponding to this link */ @@ -74,15 +72,13 @@ struct OverlayLink * position of peer B's handle in peers array */ uint32_t B; - }; /** * Representation of an underlay link */ -struct UnderlayLink -{ +struct UnderlayLink { /** * position of peer A's handle in peers array */ @@ -110,8 +106,7 @@ struct UnderlayLink }; -struct RetryListEntry -{ +struct RetryListEntry { /** * the next pointer for the DLL */ @@ -132,8 +127,7 @@ struct RetryListEntry /** * Context information for overlay topologies */ -struct TopologyContextOverlay -{ +struct TopologyContextOverlay { /** * The array of peers */ @@ -199,8 +193,7 @@ struct TopologyContextOverlay /** * Topology context information for underlay topologies */ -struct TopologyContextUnderlay -{ +struct TopologyContextUnderlay { /** * The link array */ @@ -211,13 +204,11 @@ struct TopologyContextUnderlay /** * Context information for topology operations */ -struct TopologyContext -{ +struct TopologyContext { /** * The type of this context */ enum { - /** * Type for underlay topology */ @@ -227,11 +218,9 @@ struct TopologyContext * Type for overlay topology */ TOPOLOGYCONTEXT_TYPE_OVERLAY - } type; union { - /** * Topology context information for overlay topology */ @@ -252,7 +241,6 @@ struct TopologyContext * The size of the link array */ unsigned int link_array_size; - }; @@ -261,78 +249,77 @@ struct TopologyContext * GNUNET_TESTBED_TopologyOption */ static const char *topology_strings[] = { - - /** - * A clique (everyone connected to everyone else). No options. If there are N - * peers this topology results in (N * (N -1)) connections. - */ + /** + * A clique (everyone connected to everyone else). No options. If there are N + * peers this topology results in (N * (N -1)) connections. + */ "CLIQUE", - /* - * Small-world network (2d torus plus random links). Followed - * by the number of random links to add (unsigned int). - */ + /* + * Small-world network (2d torus plus random links). Followed + * by the number of random links to add (unsigned int). + */ "SMALL_WORLD", - /** - * Small-world network (ring plus random links). Followed - * by the number of random links to add (unsigned int). - */ + /** + * Small-world network (ring plus random links). Followed + * by the number of random links to add (unsigned int). + */ "SMALL_WORLD_RING", - /** - * Ring topology. No options. - */ + /** + * Ring topology. No options. + */ "RING", - /** - * Star topology. No options. - */ + /** + * Star topology. No options. + */ "STAR", - /** - * 2-d torus. No options. - */ + /** + * 2-d torus. No options. + */ "2D_TORUS", - /** - * Random graph. Followed by the number of random links to be established - * (unsigned int) - */ + /** + * Random graph. Followed by the number of random links to be established + * (unsigned int) + */ "RANDOM", // GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI - /** - * Certain percentage of peers are unable to communicate directly - * replicating NAT conditions. Followed by the fraction of - * NAT'ed peers (float). - */ + /** + * Certain percentage of peers are unable to communicate directly + * replicating NAT conditions. Followed by the fraction of + * NAT'ed peers (float). + */ "INTERNAT", - /** - * Scale free topology. Followed by the maximum number of links a node can - * have (unsigned int); and the number of links a new node should have when - * it is added to the network (unsigned int) - */ + /** + * Scale free topology. Followed by the maximum number of links a node can + * have (unsigned int); and the number of links a new node should have when + * it is added to the network (unsigned int) + */ "SCALE_FREE", - /** - * Straight line topology. No options. - */ + /** + * Straight line topology. No options. + */ "LINE", - /** - * Read a topology from a given file. Followed by the name of the file (const char *). - */ + /** + * Read a topology from a given file. Followed by the name of the file (const char *). + */ "FROM_FILE", - /** - * All peers are disconnected. No options. - */ + /** + * All peers are disconnected. No options. + */ "NONE", - /** - * End of strings - */ + /** + * End of strings + */ NULL }; @@ -346,69 +333,69 @@ static const char *topology_strings[] = { * operation has executed successfully. */ static void -overlay_link_completed (void *cls, - struct GNUNET_TESTBED_Operation *op, - const char *emsg) +overlay_link_completed(void *cls, + struct GNUNET_TESTBED_Operation *op, + const char *emsg) { struct OverlayLink *link = cls; struct TopologyContext *tc; struct TopologyContextOverlay *overlay; struct RetryListEntry *retry_entry; - GNUNET_assert (op == link->op); - GNUNET_TESTBED_operation_done (op); + GNUNET_assert(op == link->op); + GNUNET_TESTBED_operation_done(op); link->op = NULL; tc = link->tc; - GNUNET_assert (TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type); + GNUNET_assert(TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type); overlay = &tc->u.overlay; if (NULL != emsg) - { - overlay->nfailures++; - if (0 != overlay->retry_cnt) { - LOG (GNUNET_ERROR_TYPE_WARNING, - "Error while establishing a link: %s -- Retrying\n", - emsg); - retry_entry = GNUNET_new (struct RetryListEntry); - retry_entry->link = link; - GNUNET_CONTAINER_DLL_insert_tail (overlay->rl_head, - overlay->rl_tail, - retry_entry); + overlay->nfailures++; + if (0 != overlay->retry_cnt) + { + LOG(GNUNET_ERROR_TYPE_WARNING, + "Error while establishing a link: %s -- Retrying\n", + emsg); + retry_entry = GNUNET_new(struct RetryListEntry); + retry_entry->link = link; + GNUNET_CONTAINER_DLL_insert_tail(overlay->rl_head, + overlay->rl_tail, + retry_entry); + } } - } else overlay->nsuccess++; overlay->ncompleted++; if (overlay->ncompleted < overlay->nlinks) return; if ((0 != overlay->retry_cnt) && (NULL != overlay->rl_head)) - { - overlay->retry_cnt--; - overlay->ncompleted = 0; - overlay->nlinks = 0; - while (NULL != (retry_entry = overlay->rl_head)) { - link = retry_entry->link; - link->op = - GNUNET_TESTBED_overlay_connect (overlay->op_cls, - &overlay_link_completed, - link, - overlay->peers[link->A], - overlay->peers[link->B]); - overlay->nlinks++; - GNUNET_CONTAINER_DLL_remove (overlay->rl_head, - overlay->rl_tail, - retry_entry); - GNUNET_free (retry_entry); + overlay->retry_cnt--; + overlay->ncompleted = 0; + overlay->nlinks = 0; + while (NULL != (retry_entry = overlay->rl_head)) + { + link = retry_entry->link; + link->op = + GNUNET_TESTBED_overlay_connect(overlay->op_cls, + &overlay_link_completed, + link, + overlay->peers[link->A], + overlay->peers[link->B]); + overlay->nlinks++; + GNUNET_CONTAINER_DLL_remove(overlay->rl_head, + overlay->rl_tail, + retry_entry); + GNUNET_free(retry_entry); + } + return; } - return; - } if (NULL != overlay->comp_cb) - { - overlay->comp_cb (overlay->comp_cb_cls, - overlay->nsuccess, - overlay->nfailures); - } + { + overlay->comp_cb(overlay->comp_cb_cls, + overlay->nsuccess, + overlay->nfailures); + } } @@ -419,24 +406,24 @@ overlay_link_completed (void *cls, * @param cls the Topology context */ static void -opstart_overlay_configure_topology (void *cls) +opstart_overlay_configure_topology(void *cls) { struct TopologyContext *tc = cls; struct TopologyContextOverlay *overlay; unsigned int p; - GNUNET_assert (TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type); + GNUNET_assert(TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type); overlay = &tc->u.overlay; overlay->nlinks = tc->link_array_size; for (p = 0; p < tc->link_array_size; p++) - { - overlay->link_array[p].op = - GNUNET_TESTBED_overlay_connect (overlay->op_cls, - &overlay_link_completed, - &overlay->link_array[p], - overlay->peers[overlay->link_array[p].A], - overlay->peers[overlay->link_array[p].B]); - } + { + overlay->link_array[p].op = + GNUNET_TESTBED_overlay_connect(overlay->op_cls, + &overlay_link_completed, + &overlay->link_array[p], + overlay->peers[overlay->link_array[p].A], + overlay->peers[overlay->link_array[p].B]); + } } @@ -446,28 +433,28 @@ opstart_overlay_configure_topology (void *cls) * @param cls the Topology context */ static void -oprelease_overlay_configure_topology (void *cls) +oprelease_overlay_configure_topology(void *cls) { struct TopologyContext *tc = cls; struct TopologyContextOverlay *overlay; struct RetryListEntry *retry_entry; unsigned int p; - GNUNET_assert (TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type); + GNUNET_assert(TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type); overlay = &tc->u.overlay; while (NULL != (retry_entry = overlay->rl_head)) - { - GNUNET_CONTAINER_DLL_remove (overlay->rl_head, overlay->rl_tail, retry_entry); - GNUNET_free (retry_entry); - } + { + GNUNET_CONTAINER_DLL_remove(overlay->rl_head, overlay->rl_tail, retry_entry); + GNUNET_free(retry_entry); + } if (NULL != overlay->link_array) - { - for (p = 0; p < tc->link_array_size; p++) - if (NULL != overlay->link_array[p].op) - GNUNET_TESTBED_operation_done (overlay->link_array[p].op); - GNUNET_free (overlay->link_array); - } - GNUNET_free (tc); + { + for (p = 0; p < tc->link_array_size; p++) + if (NULL != overlay->link_array[p].op) + GNUNET_TESTBED_operation_done(overlay->link_array[p].op); + GNUNET_free(overlay->link_array); + } + GNUNET_free(tc); } @@ -481,42 +468,43 @@ oprelease_overlay_configure_topology (void *cls) * @return */ static void -make_link (unsigned int offset, - uint32_t A, - uint32_t B, - struct TopologyContext *tc) +make_link(unsigned int offset, + uint32_t A, + uint32_t B, + struct TopologyContext *tc) { - GNUNET_assert (A != B); + GNUNET_assert(A != B); switch (tc->type) - { - case TOPOLOGYCONTEXT_TYPE_OVERLAY: + { + case TOPOLOGYCONTEXT_TYPE_OVERLAY: { struct TopologyContextOverlay *overlay; struct OverlayLink *olink; overlay = &tc->u.overlay; - GNUNET_assert (offset < tc->link_array_size); + GNUNET_assert(offset < tc->link_array_size); olink = &overlay->link_array[offset]; - LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer %u to %u\n", B, A); + LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting peer %u to %u\n", B, A); olink->A = A; olink->B = B; olink->op = NULL; olink->tc = tc; } break; - case TOPOLOGYCONTEXT_TYPE_UNDERLAY: + + case TOPOLOGYCONTEXT_TYPE_UNDERLAY: { struct TopologyContextUnderlay *underlay; struct UnderlayLink *ulink; underlay = &tc->u.underlay; - GNUNET_assert (offset < tc->link_array_size); + GNUNET_assert(offset < tc->link_array_size); ulink = &underlay->link_array[offset]; ulink->A = A; ulink->B = B; } break; - } + } } @@ -526,36 +514,37 @@ make_link (unsigned int offset, * @param tc the topology context */ static void -gen_topo_line (struct TopologyContext *tc) +gen_topo_line(struct TopologyContext *tc) { unsigned int cnt; tc->link_array_size = tc->num_peers - 1; switch (tc->type) - { - case TOPOLOGYCONTEXT_TYPE_OVERLAY: + { + case TOPOLOGYCONTEXT_TYPE_OVERLAY: { struct TopologyContextOverlay *overlay; overlay = &tc->u.overlay; overlay->link_array = - GNUNET_new_array (tc->link_array_size, - struct OverlayLink); + GNUNET_new_array(tc->link_array_size, + struct OverlayLink); } break; - case TOPOLOGYCONTEXT_TYPE_UNDERLAY: + + case TOPOLOGYCONTEXT_TYPE_UNDERLAY: { struct TopologyContextUnderlay *underlay; underlay = &tc->u.underlay; underlay->link_array = - GNUNET_new_array (tc->link_array_size, - struct UnderlayLink); + GNUNET_new_array(tc->link_array_size, + struct UnderlayLink); } break; - } + } for (cnt = 0; cnt < (tc->link_array_size); cnt++) - make_link (cnt, cnt, cnt + 1, tc); + make_link(cnt, cnt, cnt + 1, tc); } @@ -565,39 +554,40 @@ gen_topo_line (struct TopologyContext *tc) * @param tc the topology context */ static void -gen_topo_star (struct TopologyContext *tc) +gen_topo_star(struct TopologyContext *tc) { unsigned int cnt; tc->link_array_size = tc->num_peers - 1; switch (tc->type) - { - case TOPOLOGYCONTEXT_TYPE_OVERLAY: + { + case TOPOLOGYCONTEXT_TYPE_OVERLAY: { struct TopologyContextOverlay *overlay; overlay = &tc->u.overlay; overlay->link_array = - GNUNET_new_array (tc->link_array_size, - struct OverlayLink); + GNUNET_new_array(tc->link_array_size, + struct OverlayLink); } break; - case TOPOLOGYCONTEXT_TYPE_UNDERLAY: + + case TOPOLOGYCONTEXT_TYPE_UNDERLAY: { struct TopologyContextUnderlay *underlay; underlay = &tc->u.underlay; underlay->link_array = - GNUNET_new_array (tc->link_array_size, - struct UnderlayLink); + GNUNET_new_array(tc->link_array_size, + struct UnderlayLink); } break; - } + } for (cnt = tc->link_array_size; cnt; cnt--) - make_link (cnt - 1, - 0, - cnt, - tc); + make_link(cnt - 1, + 0, + cnt, + tc); } @@ -607,34 +597,35 @@ gen_topo_star (struct TopologyContext *tc) * @param tc the topology context */ static void -gen_topo_ring (struct TopologyContext *tc) +gen_topo_ring(struct TopologyContext *tc) { - gen_topo_line (tc); + gen_topo_line(tc); tc->link_array_size++; switch (tc->type) - { - case TOPOLOGYCONTEXT_TYPE_OVERLAY: + { + case TOPOLOGYCONTEXT_TYPE_OVERLAY: { struct TopologyContextOverlay *overlay; overlay = &tc->u.overlay; overlay->link_array = - GNUNET_realloc (overlay->link_array, sizeof (struct OverlayLink) * - tc->link_array_size); + GNUNET_realloc(overlay->link_array, sizeof(struct OverlayLink) * + tc->link_array_size); } break; - case TOPOLOGYCONTEXT_TYPE_UNDERLAY: + + case TOPOLOGYCONTEXT_TYPE_UNDERLAY: { struct TopologyContextUnderlay *underlay; underlay = &tc->u.underlay; underlay->link_array = - GNUNET_realloc (underlay->link_array, sizeof (struct UnderlayLink) * - tc->link_array_size); + GNUNET_realloc(underlay->link_array, sizeof(struct UnderlayLink) * + tc->link_array_size); } break; - } - make_link (tc->link_array_size - 1, tc->num_peers - 1, 0, tc); + } + make_link(tc->link_array_size - 1, tc->num_peers - 1, 0, tc); } @@ -651,8 +642,8 @@ gen_topo_ring (struct TopologyContext *tc) * given number of peers */ unsigned int -GNUNET_TESTBED_2dtorus_calc_links (unsigned int num_peers, unsigned int *rows, - unsigned int **rows_len) +GNUNET_TESTBED_2dtorus_calc_links(unsigned int num_peers, unsigned int *rows, + unsigned int **rows_len) { double sq; unsigned int sq_floor; @@ -663,11 +654,11 @@ GNUNET_TESTBED_2dtorus_calc_links (unsigned int num_peers, unsigned int *rows, unsigned int _num_peers; unsigned int cnt; - sq = sqrt (num_peers); - sq = floor (sq); - sq_floor = (unsigned int) sq; + sq = sqrt(num_peers); + sq = floor(sq); + sq_floor = (unsigned int)sq; _rows = (sq_floor + 1); - _rows_len = GNUNET_malloc (sizeof (unsigned int) * _rows); + _rows_len = GNUNET_malloc(sizeof(unsigned int) * _rows); for (y = 0; y < _rows - 1; y++) _rows_len[y] = sq_floor; _num_peers = sq_floor * sq_floor; @@ -675,13 +666,13 @@ GNUNET_TESTBED_2dtorus_calc_links (unsigned int num_peers, unsigned int *rows, x = 0; y = 0; while (_num_peers < num_peers) - { - if (x < y) - _rows_len[_rows - 1] = ++x; - else - _rows_len[y++]++; - _num_peers++; - } + { + if (x < y) + _rows_len[_rows - 1] = ++x; + else + _rows_len[y++]++; + _num_peers++; + } cnt += (x < 2) ? x : 2 * x; cnt += (y < 2) ? y : 2 * y; if (0 == _rows_len[_rows - 1]) @@ -691,7 +682,7 @@ GNUNET_TESTBED_2dtorus_calc_links (unsigned int num_peers, unsigned int *rows, if (NULL != rows_len) *rows_len = _rows_len; else - GNUNET_free (_rows_len); + GNUNET_free(_rows_len); return cnt; } @@ -702,7 +693,7 @@ GNUNET_TESTBED_2dtorus_calc_links (unsigned int num_peers, unsigned int *rows, * @param tc the topology context */ static void -gen_topo_2dtorus (struct TopologyContext *tc) +gen_topo_2dtorus(struct TopologyContext *tc) { unsigned int rows; unsigned int *rows_len; @@ -712,62 +703,63 @@ gen_topo_2dtorus (struct TopologyContext *tc) unsigned int offset; tc->link_array_size = - GNUNET_TESTBED_2dtorus_calc_links (tc->num_peers, &rows, &rows_len); + GNUNET_TESTBED_2dtorus_calc_links(tc->num_peers, &rows, &rows_len); switch (tc->type) - { - case TOPOLOGYCONTEXT_TYPE_OVERLAY: + { + case TOPOLOGYCONTEXT_TYPE_OVERLAY: { struct TopologyContextOverlay *overlay; overlay = &tc->u.overlay; overlay->link_array = - GNUNET_malloc (sizeof (struct OverlayLink) * tc->link_array_size); + GNUNET_malloc(sizeof(struct OverlayLink) * tc->link_array_size); } break; - case TOPOLOGYCONTEXT_TYPE_UNDERLAY: + + case TOPOLOGYCONTEXT_TYPE_UNDERLAY: { struct TopologyContextUnderlay *underlay; underlay = &tc->u.underlay; underlay->link_array = - GNUNET_malloc (sizeof (struct UnderlayLink) * tc->link_array_size); + GNUNET_malloc(sizeof(struct UnderlayLink) * tc->link_array_size); break; } - } + } cnt = 0; offset = 0; for (y = 0; y < rows; y++) - { - for (x = 0; x < rows_len[y] - 1; x++) { - make_link (cnt, offset + x, offset + x + 1, tc); + for (x = 0; x < rows_len[y] - 1; x++) + { + make_link(cnt, offset + x, offset + x + 1, tc); + cnt++; + } + if (0 == x) + break; + make_link(cnt, offset + x, offset, tc); cnt++; + offset += rows_len[y]; } - if (0 == x) - break; - make_link (cnt, offset + x, offset, tc); - cnt++; - offset += rows_len[y]; - } for (x = 0; x < rows_len[0]; x++) - { - offset = 0; - for (y = 0; y < rows - 1; y++) { - if (x >= rows_len[y + 1]) + offset = 0; + for (y = 0; y < rows - 1; y++) + { + if (x >= rows_len[y + 1]) + break; + GNUNET_assert(x < rows_len[y + 1]); + make_link(cnt, offset + x, offset + rows_len[y] + x, tc); + offset += rows_len[y]; + cnt++; + } + if (0 == offset) break; - GNUNET_assert (x < rows_len[y + 1]); - make_link (cnt, offset + x, offset + rows_len[y] + x, tc); - offset += rows_len[y]; + make_link(cnt, offset + x, x, tc); cnt++; } - if (0 == offset) - break; - make_link (cnt, offset + x, x, tc); - cnt++; - } - GNUNET_assert (cnt == tc->link_array_size); - GNUNET_free (rows_len); + GNUNET_assert(cnt == tc->link_array_size); + GNUNET_free(rows_len); } @@ -780,9 +772,9 @@ gen_topo_2dtorus (struct TopologyContext *tc) * create a new link array */ static void -gen_topo_random (struct TopologyContext *tc, - unsigned int links, - int append) +gen_topo_random(struct TopologyContext *tc, + unsigned int links, + int append) { unsigned int cnt; unsigned int index; @@ -792,66 +784,67 @@ gen_topo_random (struct TopologyContext *tc, if (1 == tc->num_peers) return; if (GNUNET_YES == append) - { - index = tc->link_array_size; - tc->link_array_size += links; - } + { + index = tc->link_array_size; + tc->link_array_size += links; + } else - { - index = 0; - tc->link_array_size = links; - } + { + index = 0; + tc->link_array_size = links; + } switch (tc->type) - { - case TOPOLOGYCONTEXT_TYPE_OVERLAY: + { + case TOPOLOGYCONTEXT_TYPE_OVERLAY: { struct TopologyContextOverlay *overlay; overlay = &tc->u.overlay; if (GNUNET_YES != append) - { - GNUNET_assert (NULL == overlay->link_array); - overlay->link_array = - GNUNET_malloc (sizeof (struct OverlayLink) * tc->link_array_size); - break; - } - GNUNET_assert ((0 < tc->link_array_size) && (NULL != overlay->link_array)); + { + GNUNET_assert(NULL == overlay->link_array); + overlay->link_array = + GNUNET_malloc(sizeof(struct OverlayLink) * tc->link_array_size); + break; + } + GNUNET_assert((0 < tc->link_array_size) && (NULL != overlay->link_array)); overlay->link_array = - GNUNET_realloc (overlay->link_array, - sizeof (struct OverlayLink) * tc->link_array_size); + GNUNET_realloc(overlay->link_array, + sizeof(struct OverlayLink) * tc->link_array_size); break; } - case TOPOLOGYCONTEXT_TYPE_UNDERLAY: + + case TOPOLOGYCONTEXT_TYPE_UNDERLAY: { struct TopologyContextUnderlay *underlay; underlay = &tc->u.underlay; if (GNUNET_YES != append) - { - GNUNET_assert (NULL == underlay->link_array); - underlay->link_array = - GNUNET_malloc (sizeof (struct UnderlayLink) * tc->link_array_size); - break; - } - GNUNET_assert ((0 < tc->link_array_size) && (NULL != underlay->link_array)); + { + GNUNET_assert(NULL == underlay->link_array); + underlay->link_array = + GNUNET_malloc(sizeof(struct UnderlayLink) * tc->link_array_size); + break; + } + GNUNET_assert((0 < tc->link_array_size) && (NULL != underlay->link_array)); underlay->link_array = - GNUNET_realloc (underlay->link_array, - sizeof (struct UnderlayLink) * tc->link_array_size); + GNUNET_realloc(underlay->link_array, + sizeof(struct UnderlayLink) * tc->link_array_size); break; } - } + } for (cnt = 0; cnt < links; cnt++) - { - do { - A_rand = - GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, tc->num_peers); - B_rand = - GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, tc->num_peers); + do + { + A_rand = + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, tc->num_peers); + B_rand = + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, tc->num_peers); + } + while (A_rand == B_rand); + make_link(index + cnt, A_rand, B_rand, tc); } - while (A_rand == B_rand); - make_link (index+cnt, A_rand, B_rand, tc); - } } @@ -866,9 +859,9 @@ gen_topo_random (struct TopologyContext *tc, * network */ static void -gen_topo_scale_free (struct TopologyContext *tc, - uint16_t cap, - uint8_t m) +gen_topo_scale_free(struct TopologyContext *tc, + uint16_t cap, + uint8_t m) { unsigned int *deg; unsigned int *etab; @@ -885,106 +878,108 @@ gen_topo_scale_free (struct TopologyContext *tc, etaboff = 0; tc->link_array_size = tc->num_peers * m; switch (tc->type) - { - case TOPOLOGYCONTEXT_TYPE_OVERLAY: + { + case TOPOLOGYCONTEXT_TYPE_OVERLAY: { struct TopologyContextOverlay *overlay; overlay = &tc->u.overlay; - overlay->link_array = GNUNET_malloc_large (sizeof (struct OverlayLink) * - tc->link_array_size); + overlay->link_array = GNUNET_malloc_large(sizeof(struct OverlayLink) * + tc->link_array_size); } break; - case TOPOLOGYCONTEXT_TYPE_UNDERLAY: + + case TOPOLOGYCONTEXT_TYPE_UNDERLAY: { struct TopologyContextUnderlay *underlay; underlay = &tc->u.underlay; - underlay->link_array = GNUNET_malloc_large (sizeof (struct UnderlayLink) * - tc->link_array_size); + underlay->link_array = GNUNET_malloc_large(sizeof(struct UnderlayLink) * + tc->link_array_size); } break; - } - etab = GNUNET_malloc_large (sizeof (unsigned int) * 2 * tc->link_array_size); - deg = GNUNET_malloc (sizeof (unsigned int) * tc->num_peers); - used = GNUNET_malloc (sizeof (unsigned int) * m); + } + etab = GNUNET_malloc_large(sizeof(unsigned int) * 2 * tc->link_array_size); + deg = GNUNET_malloc(sizeof(unsigned int) * tc->num_peers); + used = GNUNET_malloc(sizeof(unsigned int) * m); /* start by connecting peer 1 to peer 0 */ - make_link (0, 0, 1, tc); + make_link(0, 0, 1, tc); deg[0]++; deg[1]++; etab[etaboff++] = 0; etab[etaboff++] = 1; links = 1; for (peer = 2; peer < tc->num_peers; peer++) - { - if (cap < deg[peer]) - continue; - for (cnt = 0; cnt < GNUNET_MIN (peer, m); cnt++) { - redo_threshold = 0; - redo: - off = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, etaboff); - random_peer = etab[off]; - if (cap < deg[random_peer]) - { - if (++redo_threshold > GNUNET_MAX (1, cap / 2)) + if (cap < deg[peer]) + continue; + for (cnt = 0; cnt < GNUNET_MIN(peer, m); cnt++) { redo_threshold = 0; - off = 0; - for (cnt2 = 0; cnt2 < etaboff; cnt2++) - { - if (random_peer == etab[cnt2]) +redo: + off = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, etaboff); + random_peer = etab[off]; + if (cap < deg[random_peer]) { - off++; - continue; + if (++redo_threshold > GNUNET_MAX(1, cap / 2)) + { + redo_threshold = 0; + off = 0; + for (cnt2 = 0; cnt2 < etaboff; cnt2++) + { + if (random_peer == etab[cnt2]) + { + off++; + continue; + } + etab[cnt2 - off] = etab[cnt2]; + } + etaboff -= off; + } + goto redo; } - etab[cnt2 - off] = etab[cnt2]; - } - etaboff -= off; + for (cnt2 = 0; cnt2 < cnt; cnt2++) + if (random_peer == used[cnt2]) + goto redo; + make_link(links + cnt, random_peer, peer, tc); + deg[random_peer]++; + deg[peer]++; + used[cnt] = random_peer; } - goto redo; - } - for (cnt2 = 0; cnt2 < cnt; cnt2++) - if (random_peer == used[cnt2]) - goto redo; - make_link (links + cnt, random_peer, peer, tc); - deg[random_peer]++; - deg[peer]++; - used[cnt] = random_peer; - } - for (cnt = 0; cnt < GNUNET_MIN (peer, m); cnt++) - { - etab[etaboff++] = used[cnt]; - etab[etaboff++] = peer; + for (cnt = 0; cnt < GNUNET_MIN(peer, m); cnt++) + { + etab[etaboff++] = used[cnt]; + etab[etaboff++] = peer; + } + links += GNUNET_MIN(peer, m); } - links += GNUNET_MIN (peer, m); - } - GNUNET_free (etab); - GNUNET_free (used); - GNUNET_free (deg); - GNUNET_assert (links <= tc->link_array_size); + GNUNET_free(etab); + GNUNET_free(used); + GNUNET_free(deg); + GNUNET_assert(links <= tc->link_array_size); tc->link_array_size = links; switch (tc->type) - { - case TOPOLOGYCONTEXT_TYPE_OVERLAY: + { + case TOPOLOGYCONTEXT_TYPE_OVERLAY: { struct TopologyContextOverlay *overlay; overlay = &tc->u.overlay; overlay->link_array = - GNUNET_realloc (overlay->link_array, sizeof (struct OverlayLink) * tc->link_array_size); + GNUNET_realloc(overlay->link_array, sizeof(struct OverlayLink) * tc->link_array_size); } break; - case TOPOLOGYCONTEXT_TYPE_UNDERLAY: + + case TOPOLOGYCONTEXT_TYPE_UNDERLAY: { struct TopologyContextUnderlay *underlay; underlay = &tc->u.underlay; underlay->link_array = - GNUNET_realloc (underlay->link_array, sizeof (struct UnderlayLink) * tc->link_array_size); + GNUNET_realloc(underlay->link_array, sizeof(struct UnderlayLink) * tc->link_array_size); } break; - } + } } @@ -995,8 +990,8 @@ gen_topo_scale_free (struct TopologyContext *tc, * @param filename the filename of the file containing topology data */ static void -gen_topo_from_file (struct TopologyContext *tc, - const char *filename) +gen_topo_from_file(struct TopologyContext *tc, + const char *filename) { char *data; char *end; @@ -1005,9 +1000,7 @@ gen_topo_from_file (struct TopologyContext *tc, uint64_t offset; unsigned long int peer_id; unsigned long int other_peer_id; - enum ParseState - { - + enum ParseState { /** * We read the peer index */ @@ -1017,179 +1010,181 @@ gen_topo_from_file (struct TopologyContext *tc, * We read the other peer indices */ OTHER_PEER_INDEX, - } state; int status; status = GNUNET_SYSERR; - if (GNUNET_YES != GNUNET_DISK_file_test (filename)) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Topology file %s not found\n"), - filename); - return; - } + if (GNUNET_YES != GNUNET_DISK_file_test(filename)) + { + LOG(GNUNET_ERROR_TYPE_ERROR, + _("Topology file %s not found\n"), + filename); + return; + } if (GNUNET_OK != - GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES)) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Topology file %s has no data\n"), - filename); - return; - } - data = GNUNET_malloc (fs); - if (fs != GNUNET_DISK_fn_read (filename, data, fs)) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Topology file %s cannot be read\n"), - filename); - goto _exit; - } + GNUNET_DISK_file_size(filename, &fs, GNUNET_YES, GNUNET_YES)) + { + LOG(GNUNET_ERROR_TYPE_ERROR, + _("Topology file %s has no data\n"), + filename); + return; + } + data = GNUNET_malloc(fs); + if (fs != GNUNET_DISK_fn_read(filename, data, fs)) + { + LOG(GNUNET_ERROR_TYPE_ERROR, + _("Topology file %s cannot be read\n"), + filename); + goto _exit; + } offset = 0; peer_id = 0; state = PEER_INDEX; while (offset < fs) - { - if (0 != isspace ((unsigned char) data[offset])) - { - offset++; - continue; - } - switch (state) { - case PEER_INDEX: - buf = strchr (&data[offset], ':'); - if (NULL == buf) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Failed to read peer index from toology file: %s"), filename); - goto _exit; - } - *buf = '\0'; - errno = 0; - peer_id = (unsigned int) strtoul (&data[offset], &end, 10); - if (0 != errno) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Value in given topology file: %s out of range\n"), filename); - goto _exit; - } - if (&data[offset] == end) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Failed to read peer index from topology file: %s"), filename); - goto _exit; - } - if (tc->num_peers <= peer_id) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Topology file needs more peers than given ones\n"), filename); - goto _exit; - } - state = OTHER_PEER_INDEX; - offset += ((unsigned int) (buf - &data[offset])) + 1; - break; - case OTHER_PEER_INDEX: - errno = 0; - other_peer_id = (unsigned int) strtoul (&data[offset], &end, 10); - if (0 != errno) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Value in given topology file: %s out of range\n"), filename); - goto _exit; - } - if (&data[offset] == end) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Failed to read peer index from topology file: %s"), filename); - goto _exit; - } - if (tc->num_peers <= other_peer_id) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Topology file needs more peers than given ones\n"), filename); - goto _exit; - } - if (peer_id != other_peer_id) - { - tc->link_array_size++; - switch (tc->type) + if (0 != isspace((unsigned char)data[offset])) { - case TOPOLOGYCONTEXT_TYPE_OVERLAY: - { - struct TopologyContextOverlay *overlay; - - overlay = &tc->u.overlay; - overlay->link_array = - GNUNET_realloc (overlay->link_array, - sizeof (struct OverlayLink) * tc->link_array_size); - } + offset++; + continue; + } + switch (state) + { + case PEER_INDEX: + buf = strchr(&data[offset], ':'); + if (NULL == buf) + { + LOG(GNUNET_ERROR_TYPE_ERROR, + _("Failed to read peer index from toology file: %s"), filename); + goto _exit; + } + *buf = '\0'; + errno = 0; + peer_id = (unsigned int)strtoul(&data[offset], &end, 10); + if (0 != errno) + { + LOG(GNUNET_ERROR_TYPE_ERROR, + _("Value in given topology file: %s out of range\n"), filename); + goto _exit; + } + if (&data[offset] == end) + { + LOG(GNUNET_ERROR_TYPE_ERROR, + _("Failed to read peer index from topology file: %s"), filename); + goto _exit; + } + if (tc->num_peers <= peer_id) + { + LOG(GNUNET_ERROR_TYPE_ERROR, + _("Topology file needs more peers than given ones\n"), filename); + goto _exit; + } + state = OTHER_PEER_INDEX; + offset += ((unsigned int)(buf - &data[offset])) + 1; break; - case TOPOLOGYCONTEXT_TYPE_UNDERLAY: - { - struct TopologyContextUnderlay *underlay; - - underlay = &tc->u.underlay; - underlay->link_array = - GNUNET_realloc (underlay->link_array, - sizeof (struct UnderlayLink) * tc->link_array_size); - } + + case OTHER_PEER_INDEX: + errno = 0; + other_peer_id = (unsigned int)strtoul(&data[offset], &end, 10); + if (0 != errno) + { + LOG(GNUNET_ERROR_TYPE_ERROR, + _("Value in given topology file: %s out of range\n"), filename); + goto _exit; + } + if (&data[offset] == end) + { + LOG(GNUNET_ERROR_TYPE_ERROR, + _("Failed to read peer index from topology file: %s"), filename); + goto _exit; + } + if (tc->num_peers <= other_peer_id) + { + LOG(GNUNET_ERROR_TYPE_ERROR, + _("Topology file needs more peers than given ones\n"), filename); + goto _exit; + } + if (peer_id != other_peer_id) + { + tc->link_array_size++; + switch (tc->type) + { + case TOPOLOGYCONTEXT_TYPE_OVERLAY: + { + struct TopologyContextOverlay *overlay; + + overlay = &tc->u.overlay; + overlay->link_array = + GNUNET_realloc(overlay->link_array, + sizeof(struct OverlayLink) * tc->link_array_size); + } + break; + + case TOPOLOGYCONTEXT_TYPE_UNDERLAY: + { + struct TopologyContextUnderlay *underlay; + + underlay = &tc->u.underlay; + underlay->link_array = + GNUNET_realloc(underlay->link_array, + sizeof(struct UnderlayLink) * tc->link_array_size); + } + break; + } + offset += end - &data[offset]; + make_link(tc->link_array_size - 1, peer_id, other_peer_id, tc); + } + else + LOG(GNUNET_ERROR_TYPE_WARNING, + _("Ignoring to connect peer %u to peer %u\n"), + peer_id, + other_peer_id); + while (('\n' != data[offset]) && ('|' != data[offset]) && (offset < fs)) + offset++; + if ((offset < fs) && + ('\n' == data[offset])) + state = PEER_INDEX; + else if ((offset < fs) && + ('|' == data[offset])) + { + state = OTHER_PEER_INDEX; + offset++; + } break; } - offset += end - &data[offset]; - make_link (tc->link_array_size - 1, peer_id, other_peer_id, tc); - } - else - LOG (GNUNET_ERROR_TYPE_WARNING, - _("Ignoring to connect peer %u to peer %u\n"), - peer_id, - other_peer_id); - while (('\n' != data[offset]) && ('|' != data[offset]) && (offset < fs)) - offset++; - if ( (offset < fs) && - ('\n' == data[offset]) ) - state = PEER_INDEX; - else if ( (offset < fs) && - ('|' == data[offset]) ) - { - state = OTHER_PEER_INDEX; - offset++; - } - break; } - } status = GNUNET_OK; _exit: - GNUNET_free (data); + GNUNET_free(data); if (GNUNET_OK != status) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - "Removing link data read from the file\n"); - tc->link_array_size = 0; - switch (tc->type) { - case TOPOLOGYCONTEXT_TYPE_OVERLAY: - { - struct TopologyContextOverlay *overlay; + LOG(GNUNET_ERROR_TYPE_WARNING, + "Removing link data read from the file\n"); + tc->link_array_size = 0; + switch (tc->type) + { + case TOPOLOGYCONTEXT_TYPE_OVERLAY: + { + struct TopologyContextOverlay *overlay; - overlay = &tc->u.overlay; - GNUNET_free_non_null (overlay->link_array); - overlay->link_array = NULL; - } - break; - case TOPOLOGYCONTEXT_TYPE_UNDERLAY: - { - struct TopologyContextUnderlay *underlay; + overlay = &tc->u.overlay; + GNUNET_free_non_null(overlay->link_array); + overlay->link_array = NULL; + } + break; - underlay = &tc->u.underlay; - GNUNET_free_non_null (underlay->link_array); - underlay->link_array = NULL; - } - break; + case TOPOLOGYCONTEXT_TYPE_UNDERLAY: + { + struct TopologyContextUnderlay *underlay; + + underlay = &tc->u.underlay; + GNUNET_free_non_null(underlay->link_array); + underlay->link_array = NULL; + } + break; + } } - } } @@ -1199,7 +1194,7 @@ _exit: * @param tc the topology context */ static void -gen_topo_clique (struct TopologyContext *tc) +gen_topo_clique(struct TopologyContext *tc) { unsigned int cnt; unsigned int offset; @@ -1207,36 +1202,37 @@ gen_topo_clique (struct TopologyContext *tc) tc->link_array_size = tc->num_peers * (tc->num_peers - 1); switch (tc->type) - { - case TOPOLOGYCONTEXT_TYPE_OVERLAY: + { + case TOPOLOGYCONTEXT_TYPE_OVERLAY: { struct TopologyContextOverlay *overlay; overlay = &tc->u.overlay; - overlay->link_array = GNUNET_new_array (tc->link_array_size, - struct OverlayLink); + overlay->link_array = GNUNET_new_array(tc->link_array_size, + struct OverlayLink); } break; - case TOPOLOGYCONTEXT_TYPE_UNDERLAY: + + case TOPOLOGYCONTEXT_TYPE_UNDERLAY: { struct TopologyContextUnderlay *underlay; underlay = &tc->u.underlay; - underlay->link_array = GNUNET_new_array (tc->link_array_size, - struct UnderlayLink); + underlay->link_array = GNUNET_new_array(tc->link_array_size, + struct UnderlayLink); + } } - } offset = 0; for (cnt = 0; cnt < tc->num_peers; cnt++) - { - for (neighbour = 0; neighbour < tc->num_peers; neighbour++) { - if (neighbour == cnt) - continue; - make_link (offset, cnt, neighbour, tc); - offset++; + for (neighbour = 0; neighbour < tc->num_peers; neighbour++) + { + if (neighbour == cnt) + continue; + make_link(offset, cnt, neighbour, tc); + offset++; + } } - } } @@ -1252,15 +1248,15 @@ gen_topo_clique (struct TopologyContext *tc) * is not allowed at this time */ struct GNUNET_TESTBED_Operation * -GNUNET_TESTBED_underlay_configure_topology_va (void *op_cls, - unsigned int num_peers, - struct GNUNET_TESTBED_Peer - **peers, - enum - GNUNET_TESTBED_TopologyOption - topo, va_list ap) +GNUNET_TESTBED_underlay_configure_topology_va(void *op_cls, + unsigned int num_peers, + struct GNUNET_TESTBED_Peer + **peers, + enum + GNUNET_TESTBED_TopologyOption + topo, va_list ap) { - GNUNET_break (0); + GNUNET_break(0); return NULL; } @@ -1277,13 +1273,13 @@ GNUNET_TESTBED_underlay_configure_topology_va (void *op_cls, * is not allowed at this time */ struct GNUNET_TESTBED_Operation * -GNUNET_TESTBED_underlay_configure_topology (void *op_cls, - unsigned int num_peers, - struct GNUNET_TESTBED_Peer **peers, - enum GNUNET_TESTBED_TopologyOption - topo, ...) +GNUNET_TESTBED_underlay_configure_topology(void *op_cls, + unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers, + enum GNUNET_TESTBED_TopologyOption + topo, ...) { - GNUNET_break (0); + GNUNET_break(0); return NULL; } @@ -1309,15 +1305,15 @@ GNUNET_TESTBED_underlay_configure_topology (void *op_cls, * not running or underlay disallows) or if num_peers is less than 2 */ struct GNUNET_TESTBED_Operation * -GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls, - unsigned int num_peers, - struct GNUNET_TESTBED_Peer **peers, - unsigned int *max_connections, - GNUNET_TESTBED_TopologyCompletionCallback - comp_cb, - void *comp_cb_cls, - enum GNUNET_TESTBED_TopologyOption topo, - va_list va) +GNUNET_TESTBED_overlay_configure_topology_va(void *op_cls, + unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers, + unsigned int *max_connections, + GNUNET_TESTBED_TopologyCompletionCallback + comp_cb, + void *comp_cb_cls, + enum GNUNET_TESTBED_TopologyOption topo, + va_list va) { struct TopologyContext *tc; struct TopologyContextOverlay *overlay; @@ -1328,7 +1324,7 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls, if (num_peers < 2) return NULL; c = peers[0]->controller; - tc = GNUNET_new (struct TopologyContext); + tc = GNUNET_new(struct TopologyContext); tc->type = TOPOLOGYCONTEXT_TYPE_OVERLAY; overlay = &tc->u.overlay; overlay->peers = peers; @@ -1338,88 +1334,100 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls, overlay->comp_cb = comp_cb; overlay->comp_cb_cls = comp_cb_cls; switch (topo) - { - case GNUNET_TESTBED_TOPOLOGY_LINE: - gen_topo_line (tc); - break; - case GNUNET_TESTBED_TOPOLOGY_STAR: - gen_topo_star (tc); - break; - case GNUNET_TESTBED_TOPOLOGY_RING: - gen_topo_ring (tc); - break; - case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: - gen_topo_random (tc, va_arg (va, unsigned int), GNUNET_NO); - break; - case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: - gen_topo_ring (tc); - gen_topo_random (tc, va_arg (va, unsigned int), GNUNET_YES); - break; - case GNUNET_TESTBED_TOPOLOGY_CLIQUE: - gen_topo_clique (tc); - break; - case GNUNET_TESTBED_TOPOLOGY_2D_TORUS: - gen_topo_2dtorus (tc); - break; - case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: - gen_topo_2dtorus (tc); - gen_topo_random (tc, va_arg (va, unsigned int), GNUNET_YES); + { + case GNUNET_TESTBED_TOPOLOGY_LINE: + gen_topo_line(tc); + break; - break; - case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: + case GNUNET_TESTBED_TOPOLOGY_STAR: + gen_topo_star(tc); + break; + + case GNUNET_TESTBED_TOPOLOGY_RING: + gen_topo_ring(tc); + break; + + case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: + gen_topo_random(tc, va_arg(va, unsigned int), GNUNET_NO); + break; + + case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: + gen_topo_ring(tc); + gen_topo_random(tc, va_arg(va, unsigned int), GNUNET_YES); + break; + + case GNUNET_TESTBED_TOPOLOGY_CLIQUE: + gen_topo_clique(tc); + break; + + case GNUNET_TESTBED_TOPOLOGY_2D_TORUS: + gen_topo_2dtorus(tc); + break; + + case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: + gen_topo_2dtorus(tc); + gen_topo_random(tc, va_arg(va, unsigned int), GNUNET_YES); + + break; + + case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: { uint16_t cap; uint8_t m; - cap = (uint16_t) va_arg (va, unsigned int); - m = (uint8_t) va_arg (va, unsigned int); - gen_topo_scale_free (tc, cap, m); + cap = (uint16_t)va_arg(va, unsigned int); + m = (uint8_t)va_arg(va, unsigned int); + gen_topo_scale_free(tc, cap, m); } break; - case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: - { - const char *filename; - filename = va_arg (va, const char *); + case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: + { + const char *filename; + + filename = va_arg(va, const char *); - GNUNET_assert (NULL != filename); - gen_topo_from_file (tc, filename); - } + GNUNET_assert(NULL != filename); + gen_topo_from_file(tc, filename); + } break; - default: - GNUNET_break (0); - GNUNET_free (tc); - return NULL; - } - do - { - secondary_option = GNUNET_VA_ARG_ENUM (va, GNUNET_TESTBED_TopologyOption); - switch (secondary_option) - { - case GNUNET_TESTBED_TOPOLOGY_RETRY_CNT: - overlay->retry_cnt = va_arg (va, unsigned int); - break; - case GNUNET_TESTBED_TOPOLOGY_OPTION_END: - break; default: - GNUNET_break (0); /* Should not use any other option apart from - * the ones handled here */ - GNUNET_free_non_null (overlay->link_array); - GNUNET_free (tc); + GNUNET_break(0); + GNUNET_free(tc); return NULL; } - } + do + { + secondary_option = GNUNET_VA_ARG_ENUM(va, GNUNET_TESTBED_TopologyOption); + + switch (secondary_option) + { + case GNUNET_TESTBED_TOPOLOGY_RETRY_CNT: + overlay->retry_cnt = va_arg(va, unsigned int); + break; + + case GNUNET_TESTBED_TOPOLOGY_OPTION_END: + break; + + default: + GNUNET_break(0); /* Should not use any other option apart from + * the ones handled here */ + GNUNET_free_non_null(overlay->link_array); + GNUNET_free(tc); + return NULL; + } + } while (GNUNET_TESTBED_TOPOLOGY_OPTION_END != secondary_option); - op = GNUNET_TESTBED_operation_create_ (tc, - &opstart_overlay_configure_topology, - &oprelease_overlay_configure_topology); + op = GNUNET_TESTBED_operation_create_(tc, + &opstart_overlay_configure_topology, + &oprelease_overlay_configure_topology); GNUNET_TESTBED_operation_queue_insert_ - (c->opq_parallel_topology_config_operations, op); - GNUNET_TESTBED_operation_begin_wait_ (op); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Generated %u connections\n", - tc->link_array_size); + (c->opq_parallel_topology_config_operations, op); + GNUNET_TESTBED_operation_begin_wait_(op); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Generated %u connections\n", + tc->link_array_size); if (NULL != max_connections) *max_connections = tc->link_array_size; return op; @@ -1447,27 +1455,27 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls, * not running or underlay disallows) or if num_peers is less than 2 */ struct GNUNET_TESTBED_Operation * -GNUNET_TESTBED_overlay_configure_topology (void *op_cls, - unsigned int num_peers, - struct GNUNET_TESTBED_Peer **peers, - unsigned int *max_connections, - GNUNET_TESTBED_TopologyCompletionCallback - comp_cb, - void *comp_cb_cls, - enum GNUNET_TESTBED_TopologyOption topo, - ...) +GNUNET_TESTBED_overlay_configure_topology(void *op_cls, + unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers, + unsigned int *max_connections, + GNUNET_TESTBED_TopologyCompletionCallback + comp_cb, + void *comp_cb_cls, + enum GNUNET_TESTBED_TopologyOption topo, + ...) { struct GNUNET_TESTBED_Operation *op; va_list vargs; - GNUNET_assert (topo < GNUNET_TESTBED_TOPOLOGY_OPTION_END); - va_start (vargs, topo); - op = GNUNET_TESTBED_overlay_configure_topology_va (op_cls, num_peers, peers, - max_connections, - comp_cb, comp_cb_cls, - topo, - vargs); - va_end (vargs); + GNUNET_assert(topo < GNUNET_TESTBED_TOPOLOGY_OPTION_END); + va_start(vargs, topo); + op = GNUNET_TESTBED_overlay_configure_topology_va(op_cls, num_peers, peers, + max_connections, + comp_cb, comp_cb_cls, + topo, + vargs); + va_end(vargs); return op; } @@ -1482,21 +1490,21 @@ GNUNET_TESTBED_overlay_configure_topology (void *op_cls, * known topology, #GNUNET_NO if not */ int -GNUNET_TESTBED_topology_get_ (enum GNUNET_TESTBED_TopologyOption *topology, - const char *topology_string) +GNUNET_TESTBED_topology_get_(enum GNUNET_TESTBED_TopologyOption *topology, + const char *topology_string) { unsigned int cnt; for (cnt = 0; NULL != topology_strings[cnt]; cnt++) - { - if (0 == strcasecmp (topology_string, topology_strings[cnt])) { - if (NULL != topology) - *topology = (enum GNUNET_TESTBED_TopologyOption) cnt; - GNUNET_assert (GNUNET_TESTBED_TOPOLOGY_OPTION_END != (enum GNUNET_TESTBED_TopologyOption) cnt); - return GNUNET_YES; + if (0 == strcasecmp(topology_string, topology_strings[cnt])) + { + if (NULL != topology) + *topology = (enum GNUNET_TESTBED_TopologyOption)cnt; + GNUNET_assert(GNUNET_TESTBED_TOPOLOGY_OPTION_END != (enum GNUNET_TESTBED_TopologyOption)cnt); + return GNUNET_YES; + } } - } return GNUNET_NO; } @@ -1509,11 +1517,11 @@ GNUNET_TESTBED_topology_get_ (enum GNUNET_TESTBED_TopologyOption *topology, * expressed as a string */ char * -GNUNET_TESTBED_topology_to_str_ (enum GNUNET_TESTBED_TopologyOption topology) +GNUNET_TESTBED_topology_to_str_(enum GNUNET_TESTBED_TopologyOption topology) { if (GNUNET_TESTBED_TOPOLOGY_OPTION_END <= topology) return NULL; - return GNUNET_strdup (topology_strings[topology]); + return GNUNET_strdup(topology_strings[topology]); } @@ -1534,10 +1542,10 @@ GNUNET_TESTBED_topology_to_str_ (enum GNUNET_TESTBED_TopologyOption topology) * underlay link processor returned #GNUNET_SYSERR */ int -GNUNET_TESTBED_underlay_construct_ (int num_peers, - underlay_link_processor proc, - void *cls, - ...) +GNUNET_TESTBED_underlay_construct_(int num_peers, + underlay_link_processor proc, + void *cls, + ...) { struct TopologyContext tc; struct TopologyContextUnderlay *underlay; @@ -1547,78 +1555,88 @@ GNUNET_TESTBED_underlay_construct_ (int num_peers, unsigned int cnt; int ret; - GNUNET_assert (NULL != proc); + GNUNET_assert(NULL != proc); ret = GNUNET_OK; - memset (&tc, 0, sizeof (tc)); + memset(&tc, 0, sizeof(tc)); tc.num_peers = num_peers; tc.type = TOPOLOGYCONTEXT_TYPE_UNDERLAY; underlay = &tc.u.underlay; - va_start (vargs, cls); - topology = GNUNET_VA_ARG_ENUM (vargs, GNUNET_TESTBED_TopologyOption); + va_start(vargs, cls); + topology = GNUNET_VA_ARG_ENUM(vargs, GNUNET_TESTBED_TopologyOption); switch (topology) - { - case GNUNET_TESTBED_TOPOLOGY_LINE: - gen_topo_line (&tc); - break; - case GNUNET_TESTBED_TOPOLOGY_STAR: - gen_topo_star (&tc); - break; - case GNUNET_TESTBED_TOPOLOGY_RING: - gen_topo_ring (&tc); - break; - case GNUNET_TESTBED_TOPOLOGY_CLIQUE: - gen_topo_clique (&tc); - break; - case GNUNET_TESTBED_TOPOLOGY_2D_TORUS: - gen_topo_2dtorus (&tc); - break; - case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: - gen_topo_random (&tc, va_arg (vargs, unsigned int), GNUNET_NO); - break; - case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: - gen_topo_ring (&tc); - gen_topo_random (&tc, va_arg (vargs, unsigned int), GNUNET_YES); - break; - case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: - gen_topo_2dtorus (&tc); - gen_topo_random (&tc, va_arg (vargs, unsigned int), GNUNET_YES); - break; - case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: + { + case GNUNET_TESTBED_TOPOLOGY_LINE: + gen_topo_line(&tc); + break; + + case GNUNET_TESTBED_TOPOLOGY_STAR: + gen_topo_star(&tc); + break; + + case GNUNET_TESTBED_TOPOLOGY_RING: + gen_topo_ring(&tc); + break; + + case GNUNET_TESTBED_TOPOLOGY_CLIQUE: + gen_topo_clique(&tc); + break; + + case GNUNET_TESTBED_TOPOLOGY_2D_TORUS: + gen_topo_2dtorus(&tc); + break; + + case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: + gen_topo_random(&tc, va_arg(vargs, unsigned int), GNUNET_NO); + break; + + case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: + gen_topo_ring(&tc); + gen_topo_random(&tc, va_arg(vargs, unsigned int), GNUNET_YES); + break; + + case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: + gen_topo_2dtorus(&tc); + gen_topo_random(&tc, va_arg(vargs, unsigned int), GNUNET_YES); + break; + + case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: { const char *filename; - filename = va_arg (vargs, char *); - GNUNET_assert (NULL != filename); - gen_topo_from_file (&tc, filename); + filename = va_arg(vargs, char *); + GNUNET_assert(NULL != filename); + gen_topo_from_file(&tc, filename); } break; - case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: + + case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: { uint16_t cap; uint8_t m; - cap = (uint16_t) va_arg (vargs, unsigned int); - m = (uint8_t) va_arg (vargs, unsigned int); - gen_topo_scale_free (&tc, cap, m); + cap = (uint16_t)va_arg(vargs, unsigned int); + m = (uint8_t)va_arg(vargs, unsigned int); + gen_topo_scale_free(&tc, cap, m); } break; - default: - GNUNET_assert (0); - } - va_end (vargs); + + default: + GNUNET_assert(0); + } + va_end(vargs); for (cnt = 0; cnt < tc.link_array_size; cnt++) - { - ulink = &underlay->link_array[cnt]; - if (GNUNET_SYSERR == proc (cls, - ulink->A, - ulink->B, - ulink->bandwidth, - ulink->latency, - ulink->loss)) { - ret = GNUNET_SYSERR; - break; + ulink = &underlay->link_array[cnt]; + if (GNUNET_SYSERR == proc(cls, + ulink->A, + ulink->B, + ulink->bandwidth, + ulink->latency, + ulink->loss)) + { + ret = GNUNET_SYSERR; + break; + } } - } - GNUNET_free_non_null (underlay->link_array); + GNUNET_free_non_null(underlay->link_array); return ret; } diff --git a/src/testbed/testbed_api_topology.h b/src/testbed/testbed_api_topology.h index 7feec5f75..c2b00e094 100644 --- a/src/testbed/testbed_api_topology.h +++ b/src/testbed/testbed_api_topology.h @@ -11,7 +11,7 @@ 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 . @@ -38,8 +38,8 @@ * fresh. The caller should free it. Can be NULL. */ unsigned int -GNUNET_TESTBED_2dtorus_calc_links (unsigned int num_peers, unsigned int *rows, - unsigned int **rows_len); +GNUNET_TESTBED_2dtorus_calc_links(unsigned int num_peers, unsigned int *rows, + unsigned int **rows_len); /** @@ -52,8 +52,8 @@ GNUNET_TESTBED_2dtorus_calc_links (unsigned int num_peers, unsigned int *rows, * known topology, GNUNET_NO if not */ int -GNUNET_TESTBED_topology_get_ (enum GNUNET_TESTBED_TopologyOption *topology, - const char *topology_string); +GNUNET_TESTBED_topology_get_(enum GNUNET_TESTBED_TopologyOption *topology, + const char *topology_string); /** @@ -64,7 +64,7 @@ GNUNET_TESTBED_topology_get_ (enum GNUNET_TESTBED_TopologyOption *topology, * expressed as a string */ char * -GNUNET_TESTBED_topology_to_str_ (enum GNUNET_TESTBED_TopologyOption topology); +GNUNET_TESTBED_topology_to_str_(enum GNUNET_TESTBED_TopologyOption topology); /** @@ -104,10 +104,10 @@ typedef int (*underlay_link_processor) (void *cls, * underlay link processor returned GNUNET_SYSERR */ int -GNUNET_TESTBED_underlay_construct_ (int num_peers, - underlay_link_processor proc, - void *cls, - ...); +GNUNET_TESTBED_underlay_construct_(int num_peers, + underlay_link_processor proc, + void *cls, + ...); #endif /* end of testbed_api_topology.h */ diff --git a/src/testbed/testbed_api_underlay.c b/src/testbed/testbed_api_underlay.c index 5cc8d8597..b0c712ca6 100644 --- a/src/testbed/testbed_api_underlay.c +++ b/src/testbed/testbed_api_underlay.c @@ -1,22 +1,22 @@ /* - This file is part of GNUnet. - Copyright (C) 2008--2013 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 . + This file is part of GNUnet. + Copyright (C) 2008--2013 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/testbed_api_underlay.c @@ -30,8 +30,7 @@ /** * An underlay link */ -struct LinkProperty -{ +struct LinkProperty { /** * next pointer for list */ @@ -62,8 +61,7 @@ struct LinkProperty /** * Container for holding a peer in whitelist/blacklist */ -struct ListEntry -{ +struct ListEntry { /** * the next pointer */ @@ -80,8 +78,7 @@ struct ListEntry * Model for configuring underlay links of a peer * @ingroup underlay */ -struct GNUNET_TESTBED_UnderlayLinkModel -{ +struct GNUNET_TESTBED_UnderlayLinkModel { /** * The peer associated with this model */ @@ -110,15 +107,15 @@ struct GNUNET_TESTBED_UnderlayLinkModel * @param model the model */ static void -free_entries (struct GNUNET_TESTBED_UnderlayLinkModel *model) +free_entries(struct GNUNET_TESTBED_UnderlayLinkModel *model) { struct ListEntry *e; while (NULL != (e = model->entries)) - { - model->entries = e->next; - GNUNET_free (e); - } + { + model->entries = e->next; + GNUNET_free(e); + } } @@ -128,15 +125,15 @@ free_entries (struct GNUNET_TESTBED_UnderlayLinkModel *model) * @param model the model */ static void -free_link_properties (struct GNUNET_TESTBED_UnderlayLinkModel *model) +free_link_properties(struct GNUNET_TESTBED_UnderlayLinkModel *model) { struct LinkProperty *p; while (NULL != (p = model->props)) - { - model->props = p->next; - GNUNET_free (p); - } + { + model->props = p->next; + GNUNET_free(p); + } } @@ -150,13 +147,13 @@ free_link_properties (struct GNUNET_TESTBED_UnderlayLinkModel *model) * @return the model */ struct GNUNET_TESTBED_UnderlayLinkModel * -GNUNET_TESTBED_underlaylinkmodel_create (struct GNUNET_TESTBED_Peer *peer, - enum GNUNET_TESTBED_UnderlayLinkModelType type) +GNUNET_TESTBED_underlaylinkmodel_create(struct GNUNET_TESTBED_Peer *peer, + enum GNUNET_TESTBED_UnderlayLinkModelType type) { struct GNUNET_TESTBED_UnderlayLinkModel *m; - GNUNET_assert (0 == peer->underlay_model_exists); - m = GNUNET_new (struct GNUNET_TESTBED_UnderlayLinkModel); + GNUNET_assert(0 == peer->underlay_model_exists); + m = GNUNET_new(struct GNUNET_TESTBED_UnderlayLinkModel); peer->underlay_model_exists = 1; m->type = type; return m; @@ -173,12 +170,12 @@ GNUNET_TESTBED_underlaylinkmodel_create (struct GNUNET_TESTBED_Peer *peer, * @param peer the peer to add */ void -GNUNET_TESTBED_underlaylinkmodel_add_peer (struct GNUNET_TESTBED_UnderlayLinkModel *model, - struct GNUNET_TESTBED_Peer *peer) +GNUNET_TESTBED_underlaylinkmodel_add_peer(struct GNUNET_TESTBED_UnderlayLinkModel *model, + struct GNUNET_TESTBED_Peer *peer) { struct ListEntry *entry; - entry = GNUNET_new (struct ListEntry); + entry = GNUNET_new(struct ListEntry); entry->peer = peer; entry->next = model->entries; model->entries = entry; @@ -197,15 +194,15 @@ GNUNET_TESTBED_underlaylinkmodel_add_peer (struct GNUNET_TESTBED_UnderlayLinkMod * @param bandwidth bandwidth of the link in kilobytes per second [kB/s] */ void -GNUNET_TESTBED_underlaylinkmodel_set_link (struct GNUNET_TESTBED_UnderlayLinkModel *model, - struct GNUNET_TESTBED_Peer *peer, - uint32_t latency, - uint32_t loss, - uint32_t bandwidth) +GNUNET_TESTBED_underlaylinkmodel_set_link(struct GNUNET_TESTBED_UnderlayLinkModel *model, + struct GNUNET_TESTBED_Peer *peer, + uint32_t latency, + uint32_t loss, + uint32_t bandwidth) { struct LinkProperty *prop; - prop = GNUNET_new (struct LinkProperty); + prop = GNUNET_new(struct LinkProperty); prop->peer = peer; prop->latency = latency; prop->loss = loss; @@ -224,12 +221,12 @@ GNUNET_TESTBED_underlaylinkmodel_set_link (struct GNUNET_TESTBED_UnderlayLinkMod * @param model the model to unallocate */ void -GNUNET_TESTBED_underlaylinkmodel_free (struct GNUNET_TESTBED_UnderlayLinkModel *model) +GNUNET_TESTBED_underlaylinkmodel_free(struct GNUNET_TESTBED_UnderlayLinkModel *model) { model->peer->underlay_model_exists = 0; - free_entries (model); - free_link_properties (model); - gnunet_free (model); + free_entries(model); + free_link_properties(model); + gnunet_free(model); } @@ -240,12 +237,12 @@ GNUNET_TESTBED_underlaylinkmodel_free (struct GNUNET_TESTBED_UnderlayLinkModel * * @param model the model to commit */ void -GNUNET_TESTBED_underlaylinkmodel_commit (struct GNUNET_TESTBED_UnderlayLinkModel *model) +GNUNET_TESTBED_underlaylinkmodel_commit(struct GNUNET_TESTBED_UnderlayLinkModel *model) { /* FIXME: Marshal the model into a message */ - GNUNET_break (0); + GNUNET_break(0); /* do not reset the value of model->peer->underlay_model_exists */ - free_entries (model); - free_link_properties (model); - GNUNET_free (model); + free_entries(model); + free_link_properties(model); + GNUNET_free(model); } diff --git a/src/testbed/testbed_helper.h b/src/testbed/testbed_helper.h index 472d07271..304c4f6b6 100644 --- a/src/testbed/testbed_helper.h +++ b/src/testbed/testbed_helper.h @@ -11,7 +11,7 @@ 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 . @@ -32,8 +32,7 @@ GNUNET_NETWORK_STRUCT_BEGIN /** * Initialization message for gnunet-helper-testbed to start testbed service */ -struct GNUNET_TESTBED_HelperInit -{ +struct GNUNET_TESTBED_HelperInit { /** * Type is GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT */ @@ -68,8 +67,7 @@ struct GNUNET_TESTBED_HelperInit /** * Reply message from helper process */ -struct GNUNET_TESTBED_HelperReply -{ +struct GNUNET_TESTBED_HelperReply { /** * Type is GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY */ -- cgit v1.2.3