X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Ftestbed%2Fgenerate-underlay-topology.c;h=726bed1798e492272638516cdbcfb84b7f295a4e;hb=d17a17ea785f91c18b5694eab3372c4e4564d95e;hp=a463d384a9c7b8e4977f0b16fd9ffe2f4efa8065;hpb=d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb;p=oweals%2Fgnunet.git diff --git a/src/testbed/generate-underlay-topology.c b/src/testbed/generate-underlay-topology.c index a463d384a..726bed179 100644 --- a/src/testbed/generate-underlay-topology.c +++ b/src/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)); - //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, 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)); 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,125 +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)) + { + 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(_("Topology string missing\n")); + LOG_ERROR (_ ("An argument is missing for given topology `%s'\n"), + topology_string); return; } - if (GNUNET_YES != GNUNET_TESTBED_topology_get_(&topology, topology_string)) + if (-1 == sscanf (value, "%u", &arg_uint1)) { - LOG_ERROR(_("Invalid topology: %s\n"), topology_string); + LOG_ERROR (_ ("Invalid argument `%s' given as topology argument\n"), + value); return; } - arg_str1 = NULL; - /* parse for first TOPOOPT. This can either be arg_uint1 or arg_str1 */ - switch (topology) + break; + + case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: + if (NULL == (arg_str1 = args[argc++])) { - 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; + LOG_ERROR (_ ("Filename argument missing for topology `%s'\n"), + topology_string); + return; } + break; + + default: + break; + } /* parse for second TOPOOPT. Only required for SCALE_FREE topology */ switch (topology) + { + case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: + if (NULL == (value = args[argc++])) { - 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; + LOG_ERROR (_ ("Second argument for topology `%s' is missing\n"), + topology_string); + return; } - /* contruct topologies */ - switch (topology) + if (-1 == sscanf (value, "%u", &arg_uint2)) { - 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); + LOG_ERROR (_ ("Invalid argument `%s'; expecting unsigned int\n"), value); + return; } + 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); + } } @@ -357,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_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" @@ -398,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;