commit 441f2963a094063b06e8cca15236d4d1be67b9be parent 4c5d45bb55e2796024dfcb35069a6bb7d9f6041f Author: Martin Schanzenbach <schanzen@gnunet.org> Date: Fri, 7 Aug 2026 07:21:47 +0200 transport: reenable communicator tests Diffstat:
24 files changed, 479 insertions(+), 254 deletions(-)
diff --git a/src/service/transport/meson.build b/src/service/transport/meson.build @@ -122,6 +122,7 @@ libgnunettestingtransport = library( libgnunettransportcore_dep, libgnunettransportapplication_dep, libgnunetpeerstore_dep, + libgnunetpils_dep, libgnunettesting_dep, libgnunethello_dep, ], @@ -427,11 +428,67 @@ configure_file( copy: true, ) -# https://bugs.gnunet.org/view.php?id=10431 -if false - testcommunicator_basic_unix = executable( - 'test_communicator_basic-unix', +testcommunicator_basic_unix = executable( + 'test_communicator_basic-unix', + ['test_communicator_basic.c'], + install_rpath: rpath_option, + dependencies: [ + libgnunetutil_dep, + libgnunettransportapplication_dep, + libgnunettestingtransport_dep, + libgnunettransportcore_dep, + libgnunettesting_dep, + libgnunetpeerstore_dep, + libgnunetstatistics_dep, + libgnunethello_dep, + libgnunetarm_dep, + libgnunetutil_dep, + ], + include_directories: [incdir, configuration_inc], + install: false, +) +testcommunicator_basic_tcp = executable( + 'test_communicator_basic-tcp', + ['test_communicator_basic.c'], + install_rpath: rpath_option, + dependencies: [ + libgnunetutil_dep, + libgnunettransportapplication_dep, + libgnunettestingtransport_dep, + libgnunettransportcore_dep, + libgnunettesting_dep, + libgnunetpeerstore_dep, + libgnunetstatistics_dep, + libgnunethello_dep, + libgnunetarm_dep, + libgnunetutil_dep, + ], + include_directories: [incdir, configuration_inc], + install: false, +) +testcommunicator_basic_udp = executable( + 'test_communicator_basic-udp', + ['test_communicator_basic.c'], + install_rpath: rpath_option, + dependencies: [ + libgnunetutil_dep, + libgnunettransportapplication_dep, + libgnunettestingtransport_dep, + libgnunettransportcore_dep, + libgnunettesting_dep, + libgnunetpeerstore_dep, + libgnunetstatistics_dep, + libgnunethello_dep, + libgnunetarm_dep, + libgnunetutil_dep, + ], + include_directories: [incdir, configuration_inc], + install: false, +) +if quic_dep.found() and get_option('experimental') + testcommunicator_basic_quic = executable( + 'test_communicator_basic-quic', ['test_communicator_basic.c'], install_rpath: rpath_option, dependencies: [ @@ -449,34 +506,17 @@ if false include_directories: [incdir, configuration_inc], install: false, ) - testcommunicator_basic_tcp = executable( - 'test_communicator_basic-tcp', +endif +if http3_enabled + testcommunicator_basic_http3 = executable( + 'test_communicator_basic-http3', ['test_communicator_basic.c'], install_rpath: rpath_option, dependencies: [ libgnunetutil_dep, libgnunettransportapplication_dep, - libgnunettestingtransport_dep, libgnunettransportcore_dep, - libgnunettesting_dep, - libgnunetpeerstore_dep, - libgnunetstatistics_dep, - libgnunethello_dep, - libgnunetarm_dep, - libgnunetutil_dep, - ], - include_directories: [incdir, configuration_inc], - install: false, - ) - testcommunicator_basic_udp = executable( - 'test_communicator_basic-udp', - ['test_communicator_basic.c'], - install_rpath: rpath_option, - dependencies: [ - libgnunetutil_dep, - libgnunettransportapplication_dep, libgnunettestingtransport_dep, - libgnunettransportcore_dep, libgnunettesting_dep, libgnunetpeerstore_dep, libgnunetstatistics_dep, @@ -487,129 +527,87 @@ if false include_directories: [incdir, configuration_inc], install: false, ) - if quic_dep.found() and get_option('experimental') - testcommunicator_basic_quic = executable( - 'test_communicator_basic-quic', - ['test_communicator_basic.c'], - install_rpath: rpath_option, - dependencies: [ - libgnunetutil_dep, - libgnunettransportapplication_dep, - libgnunettestingtransport_dep, - libgnunettransportcore_dep, - libgnunettesting_dep, - libgnunetpeerstore_dep, - libgnunetstatistics_dep, - libgnunethello_dep, - libgnunetarm_dep, - libgnunetutil_dep, - ], - include_directories: [incdir, configuration_inc], - install: false, - ) - endif - if http3_enabled - testcommunicator_basic_http3 = executable( - 'test_communicator_basic-http3', - ['test_communicator_basic.c'], - install_rpath: rpath_option, - dependencies: [ - libgnunetutil_dep, - libgnunettransportapplication_dep, - libgnunettransportcore_dep, - libgnunettestingtransport_dep, - libgnunettesting_dep, - libgnunetpeerstore_dep, - libgnunetstatistics_dep, - libgnunethello_dep, - libgnunetarm_dep, - libgnunetutil_dep, - ], - include_directories: [incdir, configuration_inc], - install: false, - ) - endif +endif - testcommunicator_rekey_tcp = executable( - 'test_communicator_rekey-tcp', - ['test_communicator_basic.c'], - install_rpath: rpath_option, - dependencies: [ - libgnunetutil_dep, - libgnunettransportapplication_dep, - libgnunettestingtransport_dep, - libgnunettransportcore_dep, - libgnunettesting_dep, - libgnunetpeerstore_dep, - libgnunetstatistics_dep, - libgnunethello_dep, - libgnunetarm_dep, - libgnunetutil_dep, - ], - include_directories: [incdir, configuration_inc], - install: false, - ) +testcommunicator_rekey_tcp = executable( + 'test_communicator_rekey-tcp', + ['test_communicator_basic.c'], + install_rpath: rpath_option, + dependencies: [ + libgnunetutil_dep, + libgnunettransportapplication_dep, + libgnunettestingtransport_dep, + libgnunettransportcore_dep, + libgnunettesting_dep, + libgnunetpeerstore_dep, + libgnunetstatistics_dep, + libgnunethello_dep, + libgnunetarm_dep, + libgnunetutil_dep, + ], + include_directories: [incdir, configuration_inc], + install: false, +) - testcommunicator_rekey_udp = executable( - 'test_communicator_rekey-udp', - ['test_communicator_basic.c'], - install_rpath: rpath_option, - dependencies: [ - libgnunetutil_dep, - libgnunettransportapplication_dep, - libgnunettestingtransport_dep, - libgnunettransportcore_dep, - libgnunettesting_dep, - libgnunetpeerstore_dep, - libgnunetstatistics_dep, - libgnunethello_dep, - libgnunetarm_dep, - libgnunetutil_dep, - ], - include_directories: [incdir, configuration_inc], - install: false, - ) +testcommunicator_rekey_udp = executable( + 'test_communicator_rekey-udp', + ['test_communicator_basic.c'], + install_rpath: rpath_option, + dependencies: [ + libgnunetutil_dep, + libgnunettransportapplication_dep, + libgnunettestingtransport_dep, + libgnunettransportcore_dep, + libgnunettesting_dep, + libgnunetpeerstore_dep, + libgnunetstatistics_dep, + libgnunethello_dep, + libgnunetarm_dep, + libgnunetutil_dep, + ], + include_directories: [incdir, configuration_inc], + install: false, +) - testcommunicator_backchannel_udp = executable( - 'test_communicator_backchannel-udp', - ['test_communicator_basic.c'], - install_rpath: rpath_option, - dependencies: [ - libgnunetutil_dep, - libgnunettransportapplication_dep, - libgnunettestingtransport_dep, - libgnunettransportcore_dep, - libgnunettesting_dep, - libgnunetpeerstore_dep, - libgnunetstatistics_dep, - libgnunethello_dep, - libgnunetarm_dep, - libgnunetutil_dep, - ], - include_directories: [incdir, configuration_inc], - install: false, - ) +testcommunicator_backchannel_udp = executable( + 'test_communicator_backchannel-udp', + ['test_communicator_basic.c'], + install_rpath: rpath_option, + dependencies: [ + libgnunetutil_dep, + libgnunettransportapplication_dep, + libgnunettestingtransport_dep, + libgnunettransportcore_dep, + libgnunettesting_dep, + libgnunetpeerstore_dep, + libgnunetstatistics_dep, + libgnunethello_dep, + libgnunetarm_dep, + libgnunetutil_dep, + ], + include_directories: [incdir, configuration_inc], + install: false, +) - testcommunicator_bidirect_tcp = executable( - 'test_communicator_bidirect-tcp', - ['test_communicator_basic.c'], - install_rpath: rpath_option, - dependencies: [ - libgnunetutil_dep, - libgnunettransportapplication_dep, - libgnunettestingtransport_dep, - libgnunettransportcore_dep, - libgnunettesting_dep, - libgnunetpeerstore_dep, - libgnunetstatistics_dep, - libgnunethello_dep, - libgnunetarm_dep, - libgnunetutil_dep, - ], - include_directories: [incdir, configuration_inc], - install: false, - ) -endif +testcommunicator_bidirect_tcp = executable( + 'test_communicator_bidirect-tcp', + ['test_communicator_basic.c'], + install_rpath: rpath_option, + dependencies: [ + libgnunetutil_dep, + libgnunettransportapplication_dep, + libgnunettestingtransport_dep, + libgnunettransportcore_dep, + libgnunettesting_dep, + libgnunetpeerstore_dep, + libgnunetstatistics_dep, + libgnunethello_dep, + libgnunetarm_dep, + libgnunetutil_dep, + ], + include_directories: [incdir, configuration_inc], + install: false, +) if false testtransport_test_names = [ @@ -646,9 +644,13 @@ if false endforeach endif -# https://bugs.gnunet.org/view.php?id=10431 -if false +# Disabled: the UNIX communicator advertises an MTU of UINT16_MAX, which +# leaves no room for the `struct GNUNET_TRANSPORT_IncomingMessage' header +# that GNUNET_TRANSPORT_communicator_receive() prepends. The resulting +# 16-bit size overflow makes the receiving communicator write past its +# envelope in the PHASE_LONG part of this test. Unrelated to PILS. +if false test( 'test_communicator_basic-unix', testcommunicator_basic_unix, @@ -656,65 +658,65 @@ if false suite: ['transport', 'communicator'], is_parallel: false, ) +endif +test( + 'test_communicator_basic-tcp', + testcommunicator_basic_tcp, + workdir: meson.current_build_dir(), + suite: ['transport', 'communicator'], + is_parallel: false, +) +test( + 'test_communicator_basic-udp', + testcommunicator_basic_udp, + workdir: meson.current_build_dir(), + suite: ['transport', 'communicator'], + is_parallel: false, +) +if quic_dep.found() and get_option('experimental') test( - 'test_communicator_basic-tcp', - testcommunicator_basic_tcp, - workdir: meson.current_build_dir(), - suite: ['transport', 'communicator'], - is_parallel: false, - ) - test( - 'test_communicator_basic-udp', - testcommunicator_basic_udp, - workdir: meson.current_build_dir(), - suite: ['transport', 'communicator'], - is_parallel: false, - ) - if quic_dep.found() and get_option('experimental') - test( - 'test_communicator_basic-quic', - testcommunicator_basic_quic, - workdir: meson.current_build_dir(), - suite: ['transport', 'communicator'], - is_parallel: false, - ) - endif - if http3_enabled - test( - 'test_communicator_basic-http3', - testcommunicator_basic_http3, - workdir: meson.current_build_dir(), - suite: ['transport', 'communicator'], - is_parallel: false, - ) - endif - test( - 'test_communicator_rekey-tcp', - testcommunicator_rekey_tcp, - workdir: meson.current_build_dir(), - suite: ['transport', 'communicator'], - is_parallel: false, - ) - test( - 'test_communicator_rekey-udp', - testcommunicator_rekey_udp, - workdir: meson.current_build_dir(), - suite: ['transport', 'communicator'], - is_parallel: false, - ) - test( - 'test_communicator_backchannel-udp', - testcommunicator_backchannel_udp, + 'test_communicator_basic-quic', + testcommunicator_basic_quic, workdir: meson.current_build_dir(), suite: ['transport', 'communicator'], is_parallel: false, ) +endif +if http3_enabled test( - 'test_communicator_bidirect-tcp', - testcommunicator_bidirect_tcp, + 'test_communicator_basic-http3', + testcommunicator_basic_http3, workdir: meson.current_build_dir(), suite: ['transport', 'communicator'], is_parallel: false, ) - endif +test( + 'test_communicator_rekey-tcp', + testcommunicator_rekey_tcp, + workdir: meson.current_build_dir(), + suite: ['transport', 'communicator'], + is_parallel: false, +) +test( + 'test_communicator_rekey-udp', + testcommunicator_rekey_udp, + workdir: meson.current_build_dir(), + suite: ['transport', 'communicator'], + is_parallel: false, +) +test( + 'test_communicator_backchannel-udp', + testcommunicator_backchannel_udp, + workdir: meson.current_build_dir(), + suite: ['transport', 'communicator'], + is_parallel: false, +) +test( + 'test_communicator_bidirect-tcp', + testcommunicator_bidirect_tcp, + workdir: meson.current_build_dir(), + suite: ['transport', 'communicator'], + is_parallel: false, +) + diff --git a/src/service/transport/test_communicator_basic.c b/src/service/transport/test_communicator_basic.c @@ -45,6 +45,16 @@ static int queue_est = GNUNET_NO; static struct GNUNET_PeerIdentity peer_id[NUM_PEERS]; +/** + * #GNUNET_YES for a peer once PILS told us its peer identity. + */ +static int have_peer_id[NUM_PEERS]; + +/** + * Address peer B announced, remembered until we know B's peer identity. + */ +static char *peer_b_address; + static char *communicator_binary; static struct @@ -175,21 +185,21 @@ communicator_available_cb ( static void open_queue (void *cls) { - const char *address = cls; - - if (NULL != tc_hs[PEER_A]->c_mq) + (void) cls; + if ((NULL != tc_hs[PEER_A]->c_mq) && + (GNUNET_YES == have_peer_id[PEER_B])) { queue_est = GNUNET_YES; GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue (tc_hs[PEER_A], &peer_id[PEER_B] , - address); + peer_b_address); } else { GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &open_queue, - (void *) address); + NULL); } } @@ -212,9 +222,11 @@ add_address_cb ( (int) nt); // addresses[1] = GNUNET_strdup (address); if ((0 == strcmp ((char*) cls, cfg_peers_name[PEER_B])) && - (GNUNET_NO == queue_est)) + (GNUNET_NO == queue_est) && + (NULL == peer_b_address)) { - open_queue ((void *) address); + peer_b_address = GNUNET_strdup (address); + open_queue (NULL); } } @@ -326,6 +338,35 @@ get_peer_nr (void *cls, unsigned int get_the_other_one) } +/** + * @brief Callback called once PILS assigned a peer identity to one of our + * peers. + * + * The peer identity is only known at runtime, so the test cannot address a + * peer before this callback ran for it. + * + * @param cls Closure - name of the configuration file of that peer + * @param tc_h Communicator handle - unused + * @param pid the peer identity PILS assigned + */ +static void +peer_id_cb ( + void *cls, + struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, + const struct GNUNET_PeerIdentity *pid) +{ + unsigned int peer_nr = get_peer_nr (cls, GNUNET_NO); + + (void) tc_h; + LOG (GNUNET_ERROR_TYPE_INFO, + "Identity of peer %u is %s\n", + peer_nr, + GNUNET_i2s_full (pid)); + peer_id[peer_nr] = *pid; + have_peer_id[peer_nr] = GNUNET_YES; +} + + static void process_statistics_box_done (void *cls, int success) { @@ -902,34 +943,38 @@ update_avg_latency (const char *payload, unsigned int peer_nr) } -static void -load_phase_config () +/** + * @brief Whether the test phase @a option is enabled. + * + * Phases are run unless the configuration explicitly disables them. + * + * @param option name of the option in #TEST_SECTION + * @return #GNUNET_YES if the phase is to be run + */ +static unsigned int +phase_enabled (const char *option) { + if (GNUNET_NO == + GNUNET_CONFIGURATION_have_value (cfg_peers[0], + TEST_SECTION, + option)) + return GNUNET_YES; + return GNUNET_CONFIGURATION_get_value_yesno (cfg_peers[0], + TEST_SECTION, + option); +} - phase_short[0] = GNUNET_CONFIGURATION_get_value_yesno (cfg_peers[0], - TEST_SECTION, - "PHASE_SHORT"); - if (GNUNET_SYSERR == phase_short[0]) - phase_short[0] = GNUNET_YES; +static void +load_phase_config () +{ + phase_short[0] = phase_enabled ("PHASE_SHORT"); phase_short[1] = phase_short[0]; - phase_long[0] = GNUNET_CONFIGURATION_get_value_yesno (cfg_peers[0], - TEST_SECTION, - "PHASE_LONG"); - - if (GNUNET_SYSERR == phase_long[0]) - phase_long[0] = GNUNET_YES; - + phase_long[0] = phase_enabled ("PHASE_LONG"); phase_long[1] = phase_long[0]; - phase_size[0] = GNUNET_CONFIGURATION_get_value_yesno (cfg_peers[0], - TEST_SECTION, - "PHASE_SIZE"); - - if (GNUNET_SYSERR == phase_size[0]) - phase_size[0] = GNUNET_YES; - + phase_size[0] = phase_enabled ("PHASE_SIZE"); phase_size[1] = phase_size[0]; } @@ -1081,6 +1126,7 @@ do_shutdown (void *cls) GNUNET_STATISTICS_destroy (stats[i], GNUNET_YES); GNUNET_TRANSPORT_TESTING_transport_communicator_service_stop (tc_hs[i]); } + GNUNET_free (peer_b_address); } @@ -1101,7 +1147,7 @@ run (void *cls) "transport", communicator_binary, cfg_peers_name[i], - &peer_id[i], + &peer_id_cb, &communicator_available_cb, &add_address_cb, &queue_create_reply_cb, @@ -1140,7 +1186,6 @@ int main (int argc, char *const *argv) { - struct GNUNET_CRYPTO_EddsaPrivateKey *private_key; char *test_mode; char *cfg_peer; @@ -1201,21 +1246,9 @@ main (int argc, return 1; } } - private_key = - GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg_peers[i]); - if (NULL == private_key) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - "Unable to get peer ID\n"); - return 1; - } - GNUNET_CRYPTO_eddsa_key_get_public (private_key, - &peer_id[i].public_key); - GNUNET_free (private_key); - LOG (GNUNET_ERROR_TYPE_INFO, - "Identity of peer %u is %s\n", - i, - GNUNET_i2s_full (&peer_id[i])); + /* The peer identity is derived by PILS at runtime and reported to us + via #peer_id_cb(); it cannot be read from the configuration. */ + have_peer_id[i] = GNUNET_NO; } if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg_peers[0], diff --git a/src/service/transport/test_communicator_http3_basic_peer1.conf b/src/service/transport/test_communicator_http3_basic_peer1.conf @@ -6,6 +6,9 @@ GNUNET_TEST_HOME = $GNUNET_TMP/test-communicator-unix-1/ [PEER] PRIVATE_KEY = $GNUNET_TMP/test-communicator-unix-1/private.key +[pils] +UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-pils_test_1.sock + [transport-tcp] PORT = 52400 diff --git a/src/service/transport/test_communicator_http3_basic_peer2.conf b/src/service/transport/test_communicator_http3_basic_peer2.conf @@ -6,6 +6,9 @@ GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunetd-plugin-transport/ [PEER] PRIVATE_KEY = $GNUNET_TMP/test-communicator-unix-2/private.key +[pils] +UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-pils_test_2.sock + [transport-tcp] PORT = 52400 diff --git a/src/service/transport/test_communicator_http3_bidirect_peer1.conf b/src/service/transport/test_communicator_http3_bidirect_peer1.conf @@ -6,6 +6,9 @@ GNUNET_TEST_HOME = $GNUNET_TMP/test-communicator-unix-1/ [PEER] PRIVATE_KEY = $GNUNET_TMP/test-communicator-unix-1/private.key +[pils] +UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-pils_test_1.sock + [transport-tcp] PORT = 52400 diff --git a/src/service/transport/test_communicator_http3_bidirect_peer2.conf b/src/service/transport/test_communicator_http3_bidirect_peer2.conf @@ -6,6 +6,9 @@ GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunetd-plugin-transport/ [PEER] PRIVATE_KEY = $GNUNET_TMP/test-communicator-unix-2/private.key +[pils] +UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-pils_test_2.sock + [transport-tcp] PORT = 52400 diff --git a/src/service/transport/test_communicator_quic_basic_peer1.conf b/src/service/transport/test_communicator_quic_basic_peer1.conf @@ -6,6 +6,9 @@ GNUNET_TEST_HOME = $GNUNET_TMP/test-communicator-unix-1/ [PEER] PRIVATE_KEY = $GNUNET_TMP/test-communicator-unix-1/private.key +[pils] +UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-pils_test_1.sock + [transport-tcp] PORT = 52400 diff --git a/src/service/transport/test_communicator_quic_basic_peer2.conf b/src/service/transport/test_communicator_quic_basic_peer2.conf @@ -6,6 +6,9 @@ GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunetd-plugin-transport/ [PEER] PRIVATE_KEY = $GNUNET_TMP/test-communicator-unix-2/private.key +[pils] +UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-pils_test_2.sock + [transport-tcp] PORT = 52400 diff --git a/src/service/transport/test_communicator_tcp_basic_peer1.conf b/src/service/transport/test_communicator_tcp_basic_peer1.conf @@ -11,6 +11,9 @@ GNUNET_TEST_HOME = $GNUNET_TMP/test-communicator-unix-1/ [PEER] PRIVATE_KEY = $GNUNET_TMP/test-communicator-unix-1/private.key +[pils] +UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-pils_test_1.sock + [transport-tcp] PORT = 52400 diff --git a/src/service/transport/test_communicator_tcp_basic_peer2.conf b/src/service/transport/test_communicator_tcp_basic_peer2.conf @@ -6,6 +6,9 @@ GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunetd-plugin-transport/ [PEER] PRIVATE_KEY = $GNUNET_TMP/test-communicator-unix-2/private.key +[pils] +UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-pils_test_2.sock + [transport-tcp] PORT = 52400 diff --git a/src/service/transport/test_communicator_tcp_bidirect_peer1.conf b/src/service/transport/test_communicator_tcp_bidirect_peer1.conf @@ -11,6 +11,9 @@ GNUNET_TEST_HOME = $GNUNET_TMP/test-communicator-unix-1/ [PEER] PRIVATE_KEY = $GNUNET_TMP/test-communicator-unix-1/private.key +[pils] +UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-pils_test_1.sock + [transport-tcp] PORT = 52400 diff --git a/src/service/transport/test_communicator_tcp_bidirect_peer2.conf b/src/service/transport/test_communicator_tcp_bidirect_peer2.conf @@ -6,6 +6,9 @@ GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunetd-plugin-transport/ [PEER] PRIVATE_KEY = $GNUNET_TMP/test-communicator-unix-2/private.key +[pils] +UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-pils_test_2.sock + [transport-tcp] PORT = 52400 diff --git a/src/service/transport/test_communicator_tcp_rekey_peer1.conf b/src/service/transport/test_communicator_tcp_rekey_peer1.conf @@ -6,6 +6,9 @@ GNUNET_TEST_HOME = $GNUNET_TMP/test-communicator-unix-1/ [PEER] PRIVATE_KEY = $GNUNET_TMP/test-communicator-unix-1/private.key +[pils] +UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-pils_test_1.sock + [transport-tcp] PORT = 52400 diff --git a/src/service/transport/test_communicator_tcp_rekey_peer2.conf b/src/service/transport/test_communicator_tcp_rekey_peer2.conf @@ -6,6 +6,9 @@ GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunetd-plugin-transport/ [PEER] PRIVATE_KEY = $GNUNET_TMP/test-communicator-unix-2/private.key +[pils] +UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-pils_test_2.sock + [transport-tcp] PORT = 52400 diff --git a/src/service/transport/test_communicator_udp_backchannel_peer1.conf b/src/service/transport/test_communicator_udp_backchannel_peer1.conf @@ -6,6 +6,9 @@ GNUNET_TEST_HOME = $GNUNET_TMP/test-communicator-unix-1/ [PEER] PRIVATE_KEY = $GNUNET_TMP/test-communicator-unix-1/private.key +[pils] +UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-pils_test_1.sock + [transport-tcp] PORT = 52400 diff --git a/src/service/transport/test_communicator_udp_backchannel_peer2.conf b/src/service/transport/test_communicator_udp_backchannel_peer2.conf @@ -6,6 +6,9 @@ GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunetd-plugin-transport/ [PEER] PRIVATE_KEY = $GNUNET_TMP/test-communicator-unix-2/private.key +[pils] +UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-pils_test_2.sock + [transport-tcp] PORT = 52400 diff --git a/src/service/transport/test_communicator_udp_basic_peer1.conf b/src/service/transport/test_communicator_udp_basic_peer1.conf @@ -6,6 +6,9 @@ GNUNET_TEST_HOME = $GNUNET_TMP/test-communicator-unix-1/ [PEER] PRIVATE_KEY = $GNUNET_TMP/test-communicator-unix-1/private.key +[pils] +UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-pils_test_1.sock + [transport-tcp] PORT = 52400 diff --git a/src/service/transport/test_communicator_udp_basic_peer2.conf b/src/service/transport/test_communicator_udp_basic_peer2.conf @@ -6,6 +6,9 @@ GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunetd-plugin-transport/ [PEER] PRIVATE_KEY = $GNUNET_TMP/test-communicator-unix-2/private.key +[pils] +UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-pils_test_2.sock + [transport-tcp] PORT = 52400 diff --git a/src/service/transport/test_communicator_udp_rekey_peer1.conf b/src/service/transport/test_communicator_udp_rekey_peer1.conf @@ -6,6 +6,9 @@ GNUNET_TEST_HOME = $GNUNET_TMP/test-communicator-unix-1/ [PEER] PRIVATE_KEY = $GNUNET_TMP/test-communicator-unix-1/private.key +[pils] +UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-pils_test_1.sock + [transport-tcp] PORT = 52400 diff --git a/src/service/transport/test_communicator_udp_rekey_peer2.conf b/src/service/transport/test_communicator_udp_rekey_peer2.conf @@ -6,6 +6,9 @@ GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunetd-plugin-transport/ [PEER] PRIVATE_KEY = $GNUNET_TMP/test-communicator-unix-2/private.key +[pils] +UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-pils_test_2.sock + [transport-tcp] PORT = 52400 diff --git a/src/service/transport/test_communicator_unix_basic_peer1.conf b/src/service/transport/test_communicator_unix_basic_peer1.conf @@ -6,6 +6,9 @@ GNUNET_TEST_HOME = $GNUNET_TMP/test-communicator-unix-1/ [PEER] PRIVATE_KEY = $GNUNET_TMP/test-communicator-unix-1/private.key +[pils] +UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-pils_test_1.sock + [transport-tcp] PORT = 52400 diff --git a/src/service/transport/test_communicator_unix_basic_peer2.conf b/src/service/transport/test_communicator_unix_basic_peer2.conf @@ -6,6 +6,9 @@ GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunetd-plugin-transport/ [PEER] PRIVATE_KEY = $GNUNET_TMP/test-communicator-unix-2/private.key +[pils] +UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-pils_test_2.sock + [transport-tcp] PORT = 52400 diff --git a/src/service/transport/transport-testing-communicator.c b/src/service/transport/transport-testing-communicator.c @@ -819,6 +819,20 @@ shutdown_peerstore (void *cls) /** + * @brief Task run at shutdown to kill the PILS process + * + * @param cls Closure - Process of communicator + */ +static void +shutdown_pils (void *cls) +{ + struct GNUNET_Process *proc = cls; + + shutdown_process (proc); +} + + +/** * @brief Task run at shutdown to kill a communicator process * * @param cls Closure - Process of communicator @@ -845,6 +859,7 @@ communicator_start ( char *binary; char *loprefix; const char *section_name; + enum GNUNET_GenericReturnValue ok; LOG (GNUNET_ERROR_TYPE_DEBUG, "communicator_start\n"); @@ -863,15 +878,31 @@ communicator_start ( GNUNET_OS_project_data_gnunet (), binary_name); tc_h->c_proc = GNUNET_process_create (GNUNET_OS_INHERIT_STD_OUT_AND_ERR); - if (GNUNET_OK != - GNUNET_process_run_command_va ( - tc_h->c_proc, - loprefix, - binary, - binary_name, - "-c", - tc_h->cfg_filename, - NULL)) + if (0 != strlen (loprefix)) + { + /* Run the communicator under the debugging wrapper from PREFIX */ + char *cmd; + + GNUNET_asprintf (&cmd, + "%s %s -c %s", + loprefix, + binary, + tc_h->cfg_filename); + ok = GNUNET_process_run_command (tc_h->c_proc, + cmd); + GNUNET_free (cmd); + } + else + { + ok = GNUNET_process_run_command_va ( + tc_h->c_proc, + binary, + binary_name, + "-c", + tc_h->cfg_filename, + NULL); + } + if (GNUNET_OK != ok) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start communicator!"); @@ -960,10 +991,38 @@ service_start ( /** + * @brief Handler called by PILS once our peer identity is known or changed. + * + * @param cls Closure - communicator handle + * @param parser parsed HELLO representing the new peer identity + * @param hash hash of the addresses the peer identity is based on + */ +static void +pid_change_cb (void *cls, + const struct GNUNET_HELLO_Parser *parser, + const struct GNUNET_HashCode *hash) +{ + struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; + + tc_h->peer_id = *GNUNET_HELLO_parser_get_id (parser); + tc_h->have_peer_id = GNUNET_YES; + LOG (GNUNET_ERROR_TYPE_INFO, + "PILS assigned peer identity %s to `%s'\n", + GNUNET_i2s (&tc_h->peer_id), + tc_h->cfg_filename); + if (NULL != tc_h->peer_id_cb) + tc_h->peer_id_cb (tc_h->cb_cls, + tc_h, + &tc_h->peer_id); +} + + +/** * @brief Start communicator part of transport service and communicator * * @param service_name Name of the service * @param cfg Configuration handle + * @param peer_id_cb Callback that is called once PILS assigned a peer identity * @param communicator_available_cb Callback that is called when a new * @param add_address_cb Callback that is called when a new * communicator becomes available @@ -976,7 +1035,7 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( const char *service_name, const char *binary_name, const char *cfg_filename, - const struct GNUNET_PeerIdentity *peer_id, + GNUNET_TRANSPORT_TESTING_PeerIdCallback peer_id_cb, GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback communicator_available_cb, GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb, @@ -1010,13 +1069,14 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( tc_h->bc_enabled = GNUNET_CONFIGURATION_get_value_yesno (tc_h->cfg, "communicator-test", "BACKCHANNEL_ENABLED"); + tc_h->peer_id_cb = peer_id_cb; tc_h->communicator_available_cb = communicator_available_cb; tc_h->add_address_cb = add_address_cb; tc_h->queue_create_reply_cb = queue_create_reply_cb; tc_h->add_queue_cb = add_queue_cb; tc_h->incoming_msg_cb = incoming_message_cb; tc_h->bc_cb = bc_cb; - tc_h->peer_id = *peer_id; + tc_h->have_peer_id = GNUNET_NO; tc_h->cb_cls = cb_cls; /* Start communicator part of service */ @@ -1030,6 +1090,19 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( "gnunet-service-peerstore"); tc_h->stat_proc = service_start (tc_h, "gnunet-service-statistics"); + /* The peer identity is derived by PILS at runtime, so we have to run + PILS for this peer and wait for it to tell us who we are. */ + tc_h->pils_proc = service_start (tc_h, + "gnunet-service-pils"); + tc_h->pils = GNUNET_PILS_connect (tc_h->cfg, + &pid_change_cb, + tc_h); + if (NULL == tc_h->pils) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to connect to PILS!\n"); + GNUNET_break (0); + } /* Schedule start communicator */ communicator_start (tc_h, binary_name); @@ -1044,10 +1117,16 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_stop ( struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *queue; shutdown_communicator (tc_h->c_proc); shutdown_service (tc_h->sh); + if (NULL != tc_h->pils) + { + GNUNET_PILS_disconnect (tc_h->pils); + tc_h->pils = NULL; + } shutdown_nat (tc_h->nat_proc); shutdown_resolver (tc_h->resolver_proc); shutdown_peerstore (tc_h->ps_proc); shutdown_statistics (tc_h->stat_proc); + shutdown_pils (tc_h->pils_proc); GNUNET_CONFIGURATION_destroy (tc_h->cfg); while (NULL != (queue = tc_h->queue_head)) { diff --git a/src/service/transport/transport-testing-communicator.h b/src/service/transport/transport-testing-communicator.h @@ -26,6 +26,7 @@ */ #include "platform.h" #include "gnunet_util_lib.h" +#include "gnunet_pils_service.h" #include "gnunet_transport_communication_service.h" #include "transport.h" @@ -57,6 +58,27 @@ typedef struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle * /** + * @brief Function signature for callbacks that are called once the peer + * identity of the peer this communicator belongs to is known. + * + * The peer identity is derived at runtime by PILS, so it is not known + * when the communicator is started. It may also change later on, in + * which case this callback is invoked again. + * + * @param cls Closure + * @param tc_h Communicator handle + * @param peer_id the (new) peer identity of this peer + */ +typedef void +(*GNUNET_TRANSPORT_TESTING_PeerIdCallback)(void *cls, + struct + GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle + *tc_h, + const struct GNUNET_PeerIdentity * + peer_id); + + +/** * @brief Function signature for callbacks that are called when new * communicators become available * @@ -172,9 +194,29 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle */ char *cfg_filename; + /** + * @brief Our peer identity, as reported by PILS. + * + * Only valid once @e have_peer_id is #GNUNET_YES. + */ struct GNUNET_PeerIdentity peer_id; /** + * @brief #GNUNET_YES once PILS told us our @e peer_id + */ + int have_peer_id; + + /** + * @brief Handle to the PILS service of this peer + */ + struct GNUNET_PILS_Handle *pils; + + /** + * @brief PILS service process + */ + struct GNUNET_Process *pils_proc; + + /** * @brief Handle to the transport service */ struct GNUNET_SERVICE_Handle *tsh; @@ -243,6 +285,11 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle /* Callbacks + Closures */ /** + * @brief Callback called when PILS assigned us a peer identity + */ + GNUNET_TRANSPORT_TESTING_PeerIdCallback peer_id_cb; + + /** * @brief Callback called when a new communicator connects */ GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback @@ -302,8 +349,12 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle /** * @brief Start communicator part of transport service and communicator * + * Also starts the PILS service of that peer. The peer identity is not + * known when this function returns; it is reported via @a peer_id_cb. + * * @param service_name Name of the service * @param cfg Configuration handle + * @param peer_id_cb Callback handling the peer identity assigned by PILS * @param communicator_available Callback that is called when a new * communicator becomes available * @param add_address_cb Callback handling new addresses @@ -319,7 +370,7 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( const char *service_name, const char *binary_name, const char *cfg_filename, - const struct GNUNET_PeerIdentity *peer_id, + GNUNET_TRANSPORT_TESTING_PeerIdCallback peer_id_cb, GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback communicator_available_cb, GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb,