From 6e599264ad13e8fc105493d74d7c11d46f8739ed Mon Sep 17 00:00:00 2001 From: ng0 Date: Fri, 6 Sep 2019 22:46:29 +0000 Subject: first step to remove plibc --- src/cadet/gnunet-cadet-profiler.c | 2 +- src/cadet/gnunet-cadet.c | 348 ++++++++++++++++---------------------- src/cadet/test_cadet.c | 10 +- src/cadet/test_cadet_flow.c | 10 +- 4 files changed, 156 insertions(+), 214 deletions(-) (limited to 'src/cadet') diff --git a/src/cadet/gnunet-cadet-profiler.c b/src/cadet/gnunet-cadet-profiler.c index 2de17dc9e..34ea53a57 100644 --- a/src/cadet/gnunet-cadet-profiler.c +++ b/src/cadet/gnunet-cadet-profiler.c @@ -305,7 +305,7 @@ show_end_data (void) for (j = 0; j < peers_pinging; j++) { peer = &peers[j]; - FPRINTF (stdout, + fprintf (stdout, "ROUND %3u PEER %3u: %10.2f / %10.2f, PINGS: %3u, PONGS: %3u\n", i, j, peer->mean[i], sqrt (peer->var[i] / (peer->pongs[i] - 1)), peer->pings[i], peer->pongs[i]); diff --git a/src/cadet/gnunet-cadet.c b/src/cadet/gnunet-cadet.c index 262cdf64d..4e81d52f2 100644 --- a/src/cadet/gnunet-cadet.c +++ b/src/cadet/gnunet-cadet.c @@ -29,7 +29,7 @@ #include "gnunet_cadet_service.h" #include "cadet.h" -#define STREAM_BUFFER_SIZE 1024 // Pakets +#define STREAM_BUFFER_SIZE 1024 // Pakets /** * Option -P. @@ -158,16 +158,16 @@ enc_2s (uint16_t status) { switch (status) { - case 0: - return "NULL "; - case 1: - return "KSENT"; - case 2: - return "KRECV"; - case 3: - return "READY"; - default: - return ""; + case 0: + return "NULL "; + case 1: + return "KSENT"; + case 2: + return "KRECV"; + case 3: + return "READY"; + default: + return ""; } } @@ -184,23 +184,22 @@ conn_2s (uint16_t status) { switch (status) { - case 0: - return "NEW "; - case 1: - return "SRCH "; - case 2: - return "WAIT "; - case 3: - return "READY"; - case 4: - return "SHUTD"; - default: - return ""; + case 0: + return "NEW "; + case 1: + return "SRCH "; + case 2: + return "WAIT "; + case 3: + return "READY"; + case 4: + return "SHUTD"; + default: + return ""; } } - /** * Task to shut down this application. * @@ -209,8 +208,7 @@ conn_2s (uint16_t status) static void shutdown_task (void *cls) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Shutdown\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n"); if (NULL != lp) { GNUNET_CADET_close_port (lp); @@ -259,7 +257,7 @@ shutdown_task (void *cls) } void -mq_cb(void *cls) +mq_cb (void *cls) { listen_stdio (); } @@ -279,27 +277,21 @@ read_stdio (void *cls) ssize_t data_size; rd_task = NULL; - data_size = read (0, - buf, - 60000); + data_size = read (0, buf, 60000); if (data_size < 1) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "read() returned %s\n", strerror(errno)); - GNUNET_SCHEDULER_shutdown(); + "read() returned %s\n", + strerror (errno)); + GNUNET_SCHEDULER_shutdown (); return; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Read %u bytes from stdio\n", (unsigned int) data_size); - env = GNUNET_MQ_msg_extra (msg, - data_size, - GNUNET_MESSAGE_TYPE_CADET_CLI); - GNUNET_memcpy (&msg[1], - buf, - data_size); - GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), - env); + env = GNUNET_MQ_msg_extra (msg, data_size, GNUNET_MESSAGE_TYPE_CADET_CLI); + GNUNET_memcpy (&msg[1], buf, data_size); + GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), env); sent_pkt++; @@ -333,8 +325,7 @@ listen_stdio () /* FIXME: why use 'rs' here, seems overly complicated... */ rs = GNUNET_NETWORK_fdset_create (); - GNUNET_NETWORK_fdset_set_native (rs, - 0); /* STDIN */ + GNUNET_NETWORK_fdset_set_native (rs, 0); /* STDIN */ rd_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, GNUNET_TIME_UNIT_FOREVER_REL, rs, @@ -355,11 +346,9 @@ listen_stdio () * @param channel connection to the other end (henceforth invalid) */ static void -channel_ended (void *cls, - const struct GNUNET_CADET_Channel *channel) +channel_ended (void *cls, const struct GNUNET_CADET_Channel *channel) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Channel ended!\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel ended!\n"); GNUNET_assert (channel == ch); ch = NULL; GNUNET_SCHEDULER_shutdown (); @@ -413,10 +402,8 @@ send_echo (void *cls) echo_task = NULL; if (NULL == ch) return; - env = GNUNET_MQ_msg (msg, - GNUNET_MESSAGE_TYPE_CADET_CLI); - GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), - env); + env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_CLI); + GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), env); } @@ -429,8 +416,7 @@ send_echo (void *cls) * #GNUNET_SYSERR to close it (signal serious error). */ static int -check_data (void *cls, - const struct GNUNET_MessageHeader *message) +check_data (void *cls, const struct GNUNET_MessageHeader *message) { return GNUNET_OK; /* all is well-formed */ } @@ -447,8 +433,7 @@ check_data (void *cls, * @param message The actual message. */ static void -handle_data (void *cls, - const struct GNUNET_MessageHeader *message) +handle_data (void *cls, const struct GNUNET_MessageHeader *message) { size_t payload_size = ntohs (message->size) - sizeof (*message); uint16_t len; @@ -464,14 +449,10 @@ handle_data (void *cls, struct GNUNET_MQ_Envelope *env; struct GNUNET_MessageHeader *msg; - env = GNUNET_MQ_msg_extra (msg, - payload_size, - GNUNET_MESSAGE_TYPE_CADET_CLI); - GNUNET_memcpy (&msg[1], - &message[1], - payload_size); - GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), - env); + env = + GNUNET_MQ_msg_extra (msg, payload_size, GNUNET_MESSAGE_TYPE_CADET_CLI); + GNUNET_memcpy (&msg[1], &message[1], payload_size); + GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), env); return; } else @@ -482,8 +463,7 @@ handle_data (void *cls, echo_time = GNUNET_TIME_UNIT_FOREVER_ABS; GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "time: %s\n", - GNUNET_STRINGS_relative_time_to_string (latency, - GNUNET_NO)); + GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_NO)); echo_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &send_echo, NULL); @@ -491,21 +471,16 @@ handle_data (void *cls, } len = ntohs (message->size) - sizeof (*message); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Got %u bytes\n", - len); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got %u bytes\n", len); buf = (const char *) &message[1]; off = 0; while (off < len) { - done = write (1, - &buf[off], - len - off); + done = write (1, &buf[off], len - off); if (done <= 0) { if (-1 == done) - GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, - "write"); + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "write"); GNUNET_SCHEDULER_shutdown (); return; } @@ -524,16 +499,15 @@ handle_data (void *cls, * @param ple information about peer, or NULL on "EOF". */ static void -peers_callback (void *cls, - const struct GNUNET_CADET_PeerListEntry *ple) +peers_callback (void *cls, const struct GNUNET_CADET_PeerListEntry *ple) { if (NULL == ple) { plo = NULL; - GNUNET_SCHEDULER_shutdown(); + GNUNET_SCHEDULER_shutdown (); return; } - FPRINTF (stdout, + fprintf (stdout, "%s tunnel: %c, paths: %u\n", GNUNET_i2s_full (&ple->peer), ple->have_tunnel ? 'Y' : 'N', @@ -549,24 +523,20 @@ peers_callback (void *cls, * @param ppd path detail */ static void -path_callback (void *cls, - const struct GNUNET_CADET_PeerPathDetail *ppd) +path_callback (void *cls, const struct GNUNET_CADET_PeerPathDetail *ppd) { if (NULL == ppd) { gpo = NULL; - GNUNET_SCHEDULER_shutdown(); + GNUNET_SCHEDULER_shutdown (); return; } - FPRINTF (stdout, - "Path of length %u: ", - ppd->path_length); + fprintf (stdout, "Path of length %u: ", ppd->path_length); for (unsigned int i = 0; i < ppd->path_length; i++) - FPRINTF (stdout, - (i == ppd->target_offset) ? "*%s* " : "%s ", - GNUNET_i2s (&ppd->path[i])); - FPRINTF (stdout, - "\n"); + fprintf (stdout, + (i == ppd->target_offset) ? "*%s* " : "%s ", + GNUNET_i2s (&ppd->path[i])); + fprintf (stdout, "\n"); } @@ -577,16 +547,15 @@ path_callback (void *cls, * @param td tunnel details */ static void -tunnels_callback (void *cls, - const struct GNUNET_CADET_TunnelDetails *td) +tunnels_callback (void *cls, const struct GNUNET_CADET_TunnelDetails *td) { if (NULL == td) { tio = NULL; - GNUNET_SCHEDULER_shutdown(); + GNUNET_SCHEDULER_shutdown (); return; } - FPRINTF (stdout, + fprintf (stdout, "%s [ENC: %s, CON: %s] CHs: %u, CONNs: %u\n", GNUNET_i2s_full (&td->peer), enc_2s (td->estate), @@ -605,9 +574,7 @@ static void get_peers (void *cls) { job = NULL; - plo = GNUNET_CADET_list_peers (my_cfg, - &peers_callback, - NULL); + plo = GNUNET_CADET_list_peers (my_cfg, &peers_callback, NULL); } @@ -622,21 +589,15 @@ show_peer (void *cls) struct GNUNET_PeerIdentity pid; job = NULL; - if (GNUNET_OK != - GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id, - strlen (peer_id), - &pid.public_key)) + if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id, + strlen (peer_id), + &pid.public_key)) { - fprintf (stderr, - _("Invalid peer ID `%s'\n"), - peer_id); - GNUNET_SCHEDULER_shutdown(); + fprintf (stderr, _ ("Invalid peer ID `%s'\n"), peer_id); + GNUNET_SCHEDULER_shutdown (); return; } - gpo = GNUNET_CADET_get_path (my_cfg, - &pid, - &path_callback, - NULL); + gpo = GNUNET_CADET_get_path (my_cfg, &pid, &path_callback, NULL); } @@ -649,9 +610,7 @@ static void get_tunnels (void *cls) { job = NULL; - tio = GNUNET_CADET_list_tunnels (my_cfg, - &tunnels_callback, - NULL); + tio = GNUNET_CADET_list_tunnels (my_cfg, &tunnels_callback, NULL); } @@ -695,13 +654,12 @@ run (void *cls, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { - struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_var_size (data, - GNUNET_MESSAGE_TYPE_CADET_CLI, - struct GNUNET_MessageHeader, - NULL), - GNUNET_MQ_handler_end () - }; + struct GNUNET_MQ_MessageHandler handlers[] = + {GNUNET_MQ_hd_var_size (data, + GNUNET_MESSAGE_TYPE_CADET_CLI, + struct GNUNET_MessageHeader, + NULL), + GNUNET_MQ_handler_end ()}; /* FIXME add option to monitor apps */ my_cfg = cfg; @@ -709,58 +667,45 @@ run (void *cls, if (target_id && args[1]) target_port = args[1]; - if ( (0 != (request_peers | request_tunnels) - || NULL != conn_id - || NULL != channel_id) - && target_id != NULL) + if ((0 != (request_peers | request_tunnels) || NULL != conn_id || + NULL != channel_id) && + target_id != NULL) { - FPRINTF (stderr, - _("Extra arguments are not applicable " - "in combination with this option.\n")); + fprintf (stderr, + _ ("Extra arguments are not applicable " + "in combination with this option.\n")); return; } if (NULL != peer_id) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Show peer\n"); - job = GNUNET_SCHEDULER_add_now (&show_peer, - NULL); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show peer\n"); + job = GNUNET_SCHEDULER_add_now (&show_peer, NULL); } else if (NULL != channel_id) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Show channel\n"); - job = GNUNET_SCHEDULER_add_now (&show_channel, - NULL); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show channel\n"); + job = GNUNET_SCHEDULER_add_now (&show_channel, NULL); } else if (NULL != conn_id) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Show connection\n"); - job = GNUNET_SCHEDULER_add_now (&show_connection, - NULL); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show connection\n"); + job = GNUNET_SCHEDULER_add_now (&show_connection, NULL); } else if (GNUNET_YES == request_peers) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Show all peers\n"); - job = GNUNET_SCHEDULER_add_now (&get_peers, - NULL); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all peers\n"); + job = GNUNET_SCHEDULER_add_now (&get_peers, NULL); } else if (GNUNET_YES == request_tunnels) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Show all tunnels\n"); - job = GNUNET_SCHEDULER_add_now (&get_tunnels, - NULL); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all tunnels\n"); + job = GNUNET_SCHEDULER_add_now (&get_tunnels, NULL); } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Connecting to CADET service\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to CADET service\n"); mh = GNUNET_CADET_connect (cfg); - GNUNET_SCHEDULER_add_shutdown (&shutdown_task, - NULL); + GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); if (NULL == mh) { GNUNET_SCHEDULER_shutdown (); @@ -768,11 +713,8 @@ run (void *cls, } if (NULL != listen_port) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Opening CADET listen port\n"); - GNUNET_CRYPTO_hash (listen_port, - strlen (listen_port), - &porthash); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Opening CADET listen port\n"); + GNUNET_CRYPTO_hash (listen_port, strlen (listen_port), &porthash); lp = GNUNET_CADET_open_port (mh, &porthash, &channel_incoming, @@ -791,7 +733,7 @@ run (void *cls, &pid.public_key)) { GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, - _("Invalid target `%s'\n"), + _ ("Invalid target `%s'\n"), target_id); GNUNET_SCHEDULER_shutdown (); return; @@ -800,9 +742,7 @@ run (void *cls, "Connecting to `%s:%s'\n", target_id, target_port); - GNUNET_CRYPTO_hash (target_port, - strlen(target_port), - &porthash); + GNUNET_CRYPTO_hash (target_port, strlen (target_port), &porthash); ch = GNUNET_CADET_channel_create (mh, NULL, &pid, @@ -812,8 +752,7 @@ run (void *cls, handlers); if (GNUNET_YES == echo) { - echo_task = GNUNET_SCHEDULER_add_now (&send_echo, - NULL); + echo_task = GNUNET_SCHEDULER_add_now (&send_echo, NULL); } else { @@ -821,12 +760,9 @@ run (void *cls, } } - if ( (NULL == lp) && - (NULL == job) && - (NULL == ch) ) + if ((NULL == lp) && (NULL == job) && (NULL == ch)) { - GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, - _("No action requested\n")); + GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, _ ("No action requested\n")); GNUNET_SCHEDULER_shutdown (); return; } @@ -841,52 +777,58 @@ run (void *cls, * @return 0 ok, 1 on error */ int -main (int argc, - char *const *argv) +main (int argc, char *const *argv) { int res; - const char helpstr[] = "Create tunnels and retrieve info about CADET's status."; - struct GNUNET_GETOPT_CommandLineOption options[] = { - /* I would use the terminology 'circuit' here... --lynX */ - GNUNET_GETOPT_option_string ('C', - "connection", - "CONNECTION_ID", - gettext_noop ("Provide information about a particular connection"), - &conn_id), - GNUNET_GETOPT_option_flag ('e', - "echo", - gettext_noop ("Activate echo mode"), - &echo), - GNUNET_GETOPT_option_string ('o', - "open-port", - "SHARED_SECRET", - gettext_noop ("Listen for connections using a shared secret among sender and recipient"), - &listen_port), - GNUNET_GETOPT_option_string ('p', - "peer", - "PEER_ID", - gettext_noop ("Provide information about a patricular peer"), - &peer_id), - GNUNET_GETOPT_option_flag ('P', - "peers", - gettext_noop ("Provide information about all peers"), - &request_peers), - GNUNET_GETOPT_option_flag ('T', - "tunnels", - gettext_noop ("Provide information about all tunnels"), - &request_tunnels), - GNUNET_GETOPT_OPTION_END - }; - - if (GNUNET_OK != - GNUNET_STRINGS_get_utf8_args (argc, argv, - &argc, &argv)) + const char helpstr[] = + "Create tunnels and retrieve info about CADET's status."; + struct GNUNET_GETOPT_CommandLineOption options[] = + {/* I would use the terminology 'circuit' here... --lynX */ + GNUNET_GETOPT_option_string ( + 'C', + "connection", + "CONNECTION_ID", + gettext_noop ("Provide information about a particular connection"), + &conn_id), + GNUNET_GETOPT_option_flag ('e', + "echo", + gettext_noop ("Activate echo mode"), + &echo), + GNUNET_GETOPT_option_string ( + 'o', + "open-port", + "SHARED_SECRET", + gettext_noop ( + "Listen for connections using a shared secret among sender and recipient"), + &listen_port), + GNUNET_GETOPT_option_string ('p', + "peer", + "PEER_ID", + gettext_noop ( + "Provide information about a patricular peer"), + &peer_id), + GNUNET_GETOPT_option_flag ('P', + "peers", + gettext_noop ( + "Provide information about all peers"), + &request_peers), + GNUNET_GETOPT_option_flag ('T', + "tunnels", + gettext_noop ( + "Provide information about all tunnels"), + &request_tunnels), + GNUNET_GETOPT_OPTION_END}; + + if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) return 2; - res = GNUNET_PROGRAM_run (argc, argv, + res = GNUNET_PROGRAM_run (argc, + argv, "gnunet-cadet (OPTIONS | PEER_ID SHARED_SECRET)", gettext_noop (helpstr), - options, &run, NULL); + options, + &run, + NULL); GNUNET_free ((void *) argv); diff --git a/src/cadet/test_cadet.c b/src/cadet/test_cadet.c index 80a6e8227..5a28b439e 100644 --- a/src/cadet/test_cadet.c +++ b/src/cadet/test_cadet.c @@ -280,16 +280,16 @@ show_end_data (void) end_time = GNUNET_TIME_absolute_get (); total_time = GNUNET_TIME_absolute_get_difference (start_time, end_time); - FPRINTF (stderr, + fprintf (stderr, "\nResults of test \"%s\"\n", test_name); - FPRINTF (stderr, + fprintf (stderr, "Test time %s\n", GNUNET_STRINGS_relative_time_to_string (total_time, GNUNET_YES)); - FPRINTF (stderr, + fprintf (stderr, "Test bandwidth: %f kb/s\n", 4 * total_packets * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms - FPRINTF (stderr, + fprintf (stderr, "Test throughput: %f packets/s\n\n", total_packets * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms GAUGER ("CADET", @@ -1171,7 +1171,7 @@ main (int argc, char *argv[]) short_time = SHORT_TIME; if (-1 == GNUNET_GETOPT_run (argv[0], options, argc, argv)) { - FPRINTF (stderr, "test failed: problem with CLI parameters\n"); + fprintf (stderr, "test failed: problem with CLI parameters\n"); exit (1); } diff --git a/src/cadet/test_cadet_flow.c b/src/cadet/test_cadet_flow.c index 552d0fdb3..87e7b9a03 100644 --- a/src/cadet/test_cadet_flow.c +++ b/src/cadet/test_cadet_flow.c @@ -216,16 +216,16 @@ show_end_data (void) end_time = GNUNET_TIME_absolute_get (); total_time = GNUNET_TIME_absolute_get_difference (start_time, end_time); - FPRINTF (stderr, + fprintf (stderr, "\nResults of test \"%s\"\n", test_name); - FPRINTF (stderr, + fprintf (stderr, "Test time %s\n", GNUNET_STRINGS_relative_time_to_string (total_time, GNUNET_YES)); - FPRINTF (stderr, + fprintf (stderr, "Test bandwidth: %f kb/s\n", 4 * total_packets * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms - FPRINTF (stderr, + fprintf (stderr, "Test throughput: %f packets/s\n\n", total_packets * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms GAUGER ("CADET", @@ -863,7 +863,7 @@ main (int argc, argc, argv)) { - FPRINTF (stderr, + fprintf (stderr, "test failed: problem with CLI parameters\n"); return 1; } -- cgit v1.2.3