From 6a043a9228022fcce97fd50739db74abdabde055 Mon Sep 17 00:00:00 2001 From: t3sserakt Date: Fri, 19 Nov 2021 15:18:24 +0100 Subject: - Fixed header, fixed log level, changed block until connect logic, fixed memory issues. --- src/transport/Makefile.am | 3 +- src/transport/gnunet-communicator-tcp.c | 17 +++++-- .../test_communicator_tcp_basic_peer1.conf | 2 +- src/transport/test_transport_api2_tcp_node1.conf | 1 + .../test_transport_plugin_cmd_simple_send.c | 22 +++++---- ...st_transport_plugin_cmd_simple_send_broadcast.c | 56 ++++++++++++++++------ .../test_transport_plugin_cmd_udp_backchannel.c | 17 ++++--- src/transport/test_transport_simple_send.sh | 5 +- .../test_transport_simple_send_broadcast.sh | 6 ++- src/transport/test_transport_simple_send_string.sh | 7 ++- src/transport/test_transport_udp_backchannel.sh | 5 +- src/transport/transport-testing-cmds.h | 11 +++-- src/transport/transport_api_cmd_connecting_peers.c | 13 +++-- src/transport/transport_api_cmd_start_peer.c | 17 +++---- 14 files changed, 120 insertions(+), 62 deletions(-) (limited to 'src/transport') diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index f17be359e..a53f17fe6 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am @@ -123,6 +123,7 @@ endif noinst_PROGRAMS = \ + test_transport_start_with_config \ gnunet-transport-profiler \ gnunet-communicator-udp \ $(WLAN_BIN_SENDER) \ @@ -589,7 +590,6 @@ libgnunet_plugin_transport_https_server_la_CFLAGS = \ $(MHD_CFLAGS) $(AM_CFLAGS) -DBUILD_HTTPS check_PROGRAMS = \ - test_transport_start_with_config \ test_transport_address_switch_tcp \ test_transport_testing_startstop \ test_transport_testing_restart \ @@ -766,7 +766,6 @@ test_transport_start_with_config_SOURCES = \ test_transport_start_with_config_LDADD = \ $(top_builddir)/src/testing/libgnunettesting.la \ $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testbed/libgnunettestbed.la \ $(top_builddir)/src/hello/libgnunethello.la \ libgnunettransportcore.la \ libgnunettransporttesting2.la diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c index 0bf919787..07eb6db3a 100644 --- a/src/transport/gnunet-communicator-tcp.c +++ b/src/transport/gnunet-communicator-tcp.c @@ -3264,7 +3264,7 @@ init_socket (struct sockaddr *addr, return GNUNET_SYSERR; } - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "address %s\n", GNUNET_a2s (addr, in_len)); @@ -3403,15 +3403,17 @@ nat_register () socklen_t *saddr_lens; int i; struct Addresses *pos; + size_t len; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "starting nat register!\n"); + len = 0; i = 0; - saddrs = GNUNET_malloc ((addrs_lens + 1) * sizeof(struct sockaddr *)); + saddrs = GNUNET_malloc ((addrs_lens) * sizeof(struct sockaddr *)); - saddr_lens = GNUNET_malloc ((addrs_lens + 1) * sizeof(socklen_t)); + saddr_lens = GNUNET_malloc ((addrs_lens) * sizeof(socklen_t)); for (pos = addrs_head; NULL != pos; pos = pos->next) { @@ -3421,12 +3423,19 @@ nat_register () GNUNET_a2s (addrs_head->addr, addrs_head->addr_len)); saddr_lens[i] = addrs_head->addr_len; + len += saddr_lens[i]; saddrs[i] = GNUNET_memdup (addrs_head->addr, saddr_lens[i]); i++; } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "registering addresses %lu %lu %lu %lu\n", + (addrs_lens) * sizeof(struct sockaddr *), + (addrs_lens) * sizeof(socklen_t), + len, + sizeof(COMMUNICATOR_CONFIG_SECTION)); nat = GNUNET_NAT_register (cfg, COMMUNICATOR_CONFIG_SECTION, IPPROTO_TCP, @@ -3437,7 +3446,7 @@ nat_register () NULL /* FIXME: support reversal: #5529 */, NULL /* closure */); - i = 0; + // i = 0; for (i = addrs_lens - 1; i >= 0; i--) GNUNET_free (saddrs[i]); diff --git a/src/transport/test_communicator_tcp_basic_peer1.conf b/src/transport/test_communicator_tcp_basic_peer1.conf index dbc227ac6..d9fff8bbb 100644 --- a/src/transport/test_communicator_tcp_basic_peer1.conf +++ b/src/transport/test_communicator_tcp_basic_peer1.conf @@ -36,7 +36,7 @@ UNIXPATH = $GNUNET_RUNTIME_DIR/test_gnunet-communicator-unix_1.sock [communicator-tcp] #PREFIX = xterm -geometry 100x85 -T peer1 -e gdb --args -#PREFIX = valgrind --leak-check=full --track-origins=yes +PREFIX = valgrind --leak-check=full --track-origins=yes BINDTO = 60002 DISABLE_V6 = YES diff --git a/src/transport/test_transport_api2_tcp_node1.conf b/src/transport/test_transport_api2_tcp_node1.conf index 807a9360a..d6932b1b9 100644 --- a/src/transport/test_transport_api2_tcp_node1.conf +++ b/src/transport/test_transport_api2_tcp_node1.conf @@ -15,6 +15,7 @@ DISABLE_V6 = YES IMMEDIATE_START = YES UNIXPATH = $GNUNET_RUNTIME_DIR/tcp-comm-p1.sock #PREFIX = valgrind --log-file=/tmp/vg_cpeer1-%p +PREFIX = xterm -geometry 100x85 -T peer1 -e gdb --args [communicator-udp] BINARY = gnunet-communicator-udp diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c b/src/transport/test_transport_plugin_cmd_simple_send.c index 6829daf84..476fbdf4f 100644 --- a/src/transport/test_transport_plugin_cmd_simple_send.c +++ b/src/transport/test_transport_plugin_cmd_simple_send.c @@ -164,19 +164,20 @@ handle_result (void *cls, * */ static void * -notify_connect (void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_MQ_Handle *mq) +notify_connect (struct GNUNET_TESTING_Interpreter *is, + const struct GNUNET_PeerIdentity *peer) { struct ConnectPeersState *cps; + const struct GNUNET_TESTING_Command *cmd; - GNUNET_TRANSPORT_get_trait_connect_peer_state (&connect_peers, + cmd = GNUNET_TESTING_interpreter_lookup_command (is, + "connect-peers"); + GNUNET_TRANSPORT_get_trait_connect_peer_state (cmd, &cps); void *ret = NULL; - cps->notify_connect (cps, - peer, - mq); + cps->notify_connect (is, + peer); return ret; } @@ -246,7 +247,8 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, else num = (n_int - 1) * local_m_int + m_int + topology->nodes_x; - block_send = GNUNET_TESTING_cmd_block_until_external_trigger ("block"); + block_send = GNUNET_TESTING_cmd_block_until_external_trigger ( + "block"); block_receive = GNUNET_TESTING_cmd_block_until_external_trigger ( "block-receive"); connect_peers = GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers", @@ -262,11 +264,11 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, GNUNET_asprintf (&ts->cfgname, "test_transport_api2_tcp_node1.conf"); - LOG (GNUNET_ERROR_TYPE_ERROR, + LOG (GNUNET_ERROR_TYPE_DEBUG, "plugin cfgname: %s\n", ts->cfgname); - LOG (GNUNET_ERROR_TYPE_ERROR, + LOG (GNUNET_ERROR_TYPE_DEBUG, "node ip: %s\n", node_ip); diff --git a/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c b/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c index 986fe6014..e2757671b 100644 --- a/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c +++ b/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c @@ -74,7 +74,6 @@ static struct GNUNET_TESTING_Command connect_peers; static struct GNUNET_TESTING_Command local_prepared; - /** * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being * received. @@ -164,25 +163,50 @@ handle_result (void *cls, * */ static void * -notify_connect (void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_MQ_Handle *mq) +notify_connect (struct GNUNET_TESTING_Interpreter *is, + const struct GNUNET_PeerIdentity *peer) { struct GNUNET_TESTING_AsyncContext *ac; + void *ret = NULL; + const struct GNUNET_TESTING_Command *cmd; + struct BlockState *bs; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "notify_connect\n"); GNUNET_TESTING_get_trait_async_context (&connect_peers, - &ac); - void *ret = NULL; + &ac); - GNUNET_assert (NULL != ac); - if (NULL == ac->cont) - GNUNET_TESTING_async_fail (ac); + if (NULL != ac->is) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "notify_connect running\n"); + GNUNET_assert (NULL != ac); + if (NULL == ac->cont) + GNUNET_TESTING_async_fail (ac); + else + GNUNET_TESTING_async_finish (ac); + } else - GNUNET_TESTING_async_finish (ac); - + { + cmd = GNUNET_TESTING_interpreter_lookup_future_command (is, + "connect-peers"); + + LOG (GNUNET_ERROR_TYPE_DEBUG, + "block state %s\n", + cmd->label); + GNUNET_TESTING_get_trait_block_state (cmd,&bs); + + LOG (GNUNET_ERROR_TYPE_DEBUG, + "block state %u\n", + bs->asynchronous_finish); + bs->asynchronous_finish = GNUNET_YES; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "block state %u\n", + bs->asynchronous_finish); + } + return ret; } @@ -224,7 +248,6 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, char *topology_data, unsigned int *read_file) { - unsigned int n_int; unsigned int m_int; unsigned int local_m_int; @@ -232,6 +255,8 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, struct TestState *ts = GNUNET_new (struct TestState); struct GNUNET_TESTING_NetjailTopology *topology; + + if (GNUNET_YES == *read_file) { LOG (GNUNET_ERROR_TYPE_DEBUG, @@ -255,7 +280,8 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, block_send = GNUNET_TESTING_cmd_block_until_external_trigger ("block"); block_receive = GNUNET_TESTING_cmd_block_until_external_trigger ( "block-receive"); - connect_peers = GNUNET_TESTING_cmd_block_until_external_trigger ("connect-peers"); + connect_peers = GNUNET_TESTING_cmd_block_until_external_trigger ( + "connect-peers"); local_prepared = GNUNET_TESTING_cmd_local_test_prepared ( "local-test-prepared", write_message); @@ -264,11 +290,11 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, GNUNET_asprintf (&ts->cfgname, "test_transport_api2_tcp_node1.conf"); - LOG (GNUNET_ERROR_TYPE_ERROR, + LOG (GNUNET_ERROR_TYPE_DEBUG, "plugin cfgname: %s\n", ts->cfgname); - LOG (GNUNET_ERROR_TYPE_ERROR, + LOG (GNUNET_ERROR_TYPE_DEBUG, "node ip: %s\n", node_ip); diff --git a/src/transport/test_transport_plugin_cmd_udp_backchannel.c b/src/transport/test_transport_plugin_cmd_udp_backchannel.c index 11cd177c4..c98a3075d 100644 --- a/src/transport/test_transport_plugin_cmd_udp_backchannel.c +++ b/src/transport/test_transport_plugin_cmd_udp_backchannel.c @@ -160,9 +160,8 @@ handle_result (void *cls, * */ static void * -notify_connect (void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_MQ_Handle *mq) +notify_connect (struct GNUNET_TESTING_Interpreter *is, + const struct GNUNET_PeerIdentity *peer) { struct ConnectPeersState *cps; @@ -170,9 +169,8 @@ notify_connect (void *cls, &cps); void *ret = NULL; - cps->notify_connect (cps, - peer, - mq); + cps->notify_connect (is, + peer); return ret; } @@ -238,7 +236,8 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, else num = (n_int - 1) * local_m_int + m_int + topology->nodes_x; - block_send = GNUNET_TESTING_cmd_block_until_external_trigger ("block"); + block_send = GNUNET_TESTING_cmd_block_until_external_trigger ( + "block"); connect_peers = GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers", "start-peer", "system-create", @@ -251,11 +250,11 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, GNUNET_asprintf (&ts->cfgname, "test_transport_api2_tcp_node1.conf"); - LOG (GNUNET_ERROR_TYPE_ERROR, + LOG (GNUNET_ERROR_TYPE_DEBUG, "plugin cfgname: %s\n", ts->cfgname); - LOG (GNUNET_ERROR_TYPE_ERROR, + LOG (GNUNET_ERROR_TYPE_DEBUG, "node ip: %s\n", node_ip); diff --git a/src/transport/test_transport_simple_send.sh b/src/transport/test_transport_simple_send.sh index 7e3ee032f..e7da65ff7 100755 --- a/src/transport/test_transport_simple_send.sh +++ b/src/transport/test_transport_simple_send.sh @@ -1,5 +1,8 @@ #!/bin/bash -if [ "$(sysctl -n kernel.unprivileged_userns_clone)" == 1 ]; then +if ! [ -d "/run/netns" ]; then + echo You have to create the directory /run/netns. +fi +if [ "$(cat /proc/sys/kernel/core_uses_pid)" == 1 ]; then exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_start_with_config test_transport_simple_send_topo.conf" else echo -e "Error during test setup: The kernel parameter kernel.unprivileged_userns_clone has to be set to 1! One has to execute\n\n sysctl kernel.unprivileged_userns_clone=1\n" diff --git a/src/transport/test_transport_simple_send_broadcast.sh b/src/transport/test_transport_simple_send_broadcast.sh index 6e455f0d5..93572327b 100755 --- a/src/transport/test_transport_simple_send_broadcast.sh +++ b/src/transport/test_transport_simple_send_broadcast.sh @@ -1,5 +1,9 @@ #!/bin/bash -if [ "$(sysctl -n kernel.unprivileged_userns_clone)" == 1 ]; then +if ! [ -d "/run/netns" ]; then + echo You have to create the directory /run/netns. +fi +if [ "$(cat /proc/sys/kernel/core_uses_pid)" == 1 ]; then + # exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; valgrind --leak-check=full --track-origins=yes --trace-children=yes --trace-children-skip=/usr/bin/awk,/usr/bin/cut,/usr/bin/seq,/sbin/ip/sed/bash ./test_transport_start_with_config test_transport_simple_send_broadcast_topo.conf" exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_start_with_config test_transport_simple_send_broadcast_topo.conf" else echo -e "Error during test setup: The kernel parameter kernel.unprivileged_userns_clone has to be set to 1! One has to execute\n\n sysctl kernel.unprivileged_userns_clone=1\n" diff --git a/src/transport/test_transport_simple_send_string.sh b/src/transport/test_transport_simple_send_string.sh index 018ea55e8..f9510e6b6 100755 --- a/src/transport/test_transport_simple_send_string.sh +++ b/src/transport/test_transport_simple_send_string.sh @@ -7,8 +7,11 @@ T:libgnunet_test_transport_plugin_cmd_simple_send P:1:1|{connect:{P:1:2:tcp}} P:1:2|{connect:{P:1:1:tcp}} EOF -) -if [ "$(sysctl -n kernel.unprivileged_userns_clone)" == 1 ]; then + ) +if ! [ -d "/run/netns" ]; then + echo You have to create the directory /run/netns. +fi +if [ "$(cat /proc/sys/kernel/core_uses_pid)" == 1 ]; then exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_start_with_config -s '$string'" else echo -e "Error during test setup: The kernel parameter kernel.unprivileged_userns_clone has to be set to 1! One has to execute\n\n sysctl kernel.unprivileged_userns_clone=1\n" diff --git a/src/transport/test_transport_udp_backchannel.sh b/src/transport/test_transport_udp_backchannel.sh index 9c0b11fad..f93aef7ff 100755 --- a/src/transport/test_transport_udp_backchannel.sh +++ b/src/transport/test_transport_udp_backchannel.sh @@ -1,5 +1,8 @@ #!/bin/bash -if [ "$(sysctl -n kernel.unprivileged_userns_clone)" == 1 ]; then +if ! [ -d "/run/netns" ]; then + echo You have to create the directory /run/netns. +fi +if [ "$(cat /proc/sys/kernel/core_uses_pid)" == 1 ]; then #exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; valgrind --leak-check=full --track-origins=yes --trace-children=yes --trace-children-skip=/usr/bin/awk,/usr/bin/cut,/usr/bin/seq,/sbin/ip ./test_transport_start_with_config test_transport_udp_backchannel_topo.conf" exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_start_with_config test_transport_udp_backchannel_topo.conf" # exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; valgrind --leak-check=full --track-origins=yes ./test_transport_start_with_config test_transport_udp_backchannel_topo.conf" diff --git a/src/transport/transport-testing-cmds.h b/src/transport/transport-testing-cmds.h index 5d0b902f6..d2e49c0d3 100644 --- a/src/transport/transport-testing-cmds.h +++ b/src/transport/transport-testing-cmds.h @@ -29,6 +29,10 @@ #include "gnunet_testing_lib.h" +typedef void * +(*GNUNET_TRANSPORT_notify_connect_cb) (struct GNUNET_TESTING_Interpreter *is, + const struct GNUNET_PeerIdentity *peer); + /** * Struct to store information needed in callbacks. * @@ -40,7 +44,7 @@ struct ConnectPeersState */ struct GNUNET_TESTING_AsyncContext ac; - GNUNET_TRANSPORT_NotifyConnect notify_connect; + GNUNET_TRANSPORT_notify_connect_cb notify_connect; /** * The testing system of this node. @@ -163,7 +167,7 @@ struct StartPeerState struct GNUNET_TESTING_System *tl_system; - GNUNET_TRANSPORT_NotifyConnect notify_connect; + GNUNET_TRANSPORT_notify_connect_cb notify_connect; /** * Flag indicating, if udp broadcast should be switched on. @@ -213,7 +217,8 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label, char *node_ip, struct GNUNET_MQ_MessageHandler *handlers, const char *cfgname, - GNUNET_TRANSPORT_NotifyConnect notify_connect, + GNUNET_TRANSPORT_notify_connect_cb + notify_connect, unsigned int broadcast); diff --git a/src/transport/transport_api_cmd_connecting_peers.c b/src/transport/transport_api_cmd_connecting_peers.c index b50b63c62..3fef7d687 100644 --- a/src/transport/transport_api_cmd_connecting_peers.c +++ b/src/transport/transport_api_cmd_connecting_peers.c @@ -113,17 +113,20 @@ connect_peers_run (void *cls, * */ static void * -notify_connect (void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_MQ_Handle *mq) +notify_connect (struct GNUNET_TESTING_Interpreter *is, + const struct GNUNET_PeerIdentity *peer) { - struct ConnectPeersState *cps = cls; + const struct GNUNET_TESTING_Command *cmd; + struct ConnectPeersState *cps; struct GNUNET_PeerIdentity *peer_connection; unsigned int con_num = 0; struct GNUNET_TESTING_NodeConnection *pos_connection; unsigned int num; void *ret = NULL; + cmd = GNUNET_TESTING_interpreter_lookup_command (is, + "connect-peers"); + cps = cmd->cls; for (pos_connection = cps->node_connections_head; NULL != pos_connection; pos_connection = pos_connection->next) { @@ -217,7 +220,7 @@ GNUNET_TRANSPORT_cmd_connect_peers (const char *label, cps->num = num; cps->create_label = create_label; cps->topology = topology; - cps->notify_connect = ¬ify_connect; + cps->notify_connect = notify_connect; { struct GNUNET_TESTING_Command cmd = { diff --git a/src/transport/transport_api_cmd_start_peer.c b/src/transport/transport_api_cmd_start_peer.c index da833f1b1..52eacabb2 100644 --- a/src/transport/transport_api_cmd_start_peer.c +++ b/src/transport/transport_api_cmd_start_peer.c @@ -147,9 +147,8 @@ notify_connect (void *cls, GNUNET_free (key); - sps->notify_connect (cls, - peer, - mq); + sps->notify_connect (sps->ac.is, + peer); // TODO what does the handler function need? return ret; @@ -213,11 +212,11 @@ start_peer_run (void *cls, GNUNET_asprintf (&bindto_udp, "2086"); - LOG (GNUNET_ERROR_TYPE_ERROR, + LOG (GNUNET_ERROR_TYPE_DEBUG, "node_ip %s\n", bindto); - LOG (GNUNET_ERROR_TYPE_ERROR, + LOG (GNUNET_ERROR_TYPE_DEBUG, "bind_udp %s\n", GNUNET_YES == sps->broadcast ? bindto_udp : bindto); @@ -247,7 +246,7 @@ start_peer_run (void *cls, sps->tl_system = tl_system; - LOG (GNUNET_ERROR_TYPE_ERROR, + LOG (GNUNET_ERROR_TYPE_DEBUG, "Creating testing library with key number %u\n", sps->no); @@ -255,7 +254,7 @@ start_peer_run (void *cls, GNUNET_TESTING_configuration_create (tl_system, sps->cfg)) { - LOG (GNUNET_ERROR_TYPE_ERROR, + LOG (GNUNET_ERROR_TYPE_DEBUG, "Testing library failed to create unique configuration based on `%s'\n", sps->cfgname); GNUNET_CONFIGURATION_destroy (sps->cfg); @@ -359,6 +358,7 @@ start_peer_run (void *cls, GNUNET_free (tcp_communicator_unix_path); GNUNET_free (udp_communicator_unix_path); GNUNET_free (bindto); + GNUNET_free (bindto_udp); } @@ -589,7 +589,8 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label, char *node_ip, struct GNUNET_MQ_MessageHandler *handlers, const char *cfgname, - GNUNET_TRANSPORT_NotifyConnect notify_connect, + GNUNET_TRANSPORT_notify_connect_cb + notify_connect, unsigned int broadcast) { struct StartPeerState *sps; -- cgit v1.2.3