diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-12 08:08:17 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-12 08:08:17 +0000 |
commit | a00afbdaae8de7fd752aab1ed5028833a85eeea7 (patch) | |
tree | 7f332838143653bf2bc7e4f3969ef9e8e43a03b7 | |
parent | 6bfa05291c469d0aba00e85456ceadf8b433601c (diff) |
more transport testing hacking
21 files changed, 316 insertions, 608 deletions
diff --git a/po/POTFILES.in b/po/POTFILES.in index 067d12f4d5..6c1eff093a 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -406,10 +406,15 @@ src/transport/plugin_transport_wlan.c src/transport/transport_api_address_to_string.c src/transport/transport_api_blacklist.c src/transport/transport_api.c +src/transport/transport_api_core.c +src/transport/transport_api_get_hello.c src/transport/transport_api_monitor_peers.c src/transport/transport_api_monitor_plugins.c -src/transport/transport_api_monitor_validation.c +src/transport/transport_api_offer_hello.c src/transport/transport-testing.c +src/transport/transport-testing-filenames.c +src/transport/transport-testing-loggers.c +src/transport/transport-testing-main.c src/tun/regex.c src/tun/tun.c src/util/bandwidth.c diff --git a/src/peerstore/gnunet-service-peerstore.c b/src/peerstore/gnunet-service-peerstore.c index af6438bb25..a074d132aa 100644 --- a/src/peerstore/gnunet-service-peerstore.c +++ b/src/peerstore/gnunet-service-peerstore.c @@ -472,10 +472,11 @@ handle_store (void *cls, struct GNUNET_SERVER_Client *client, return; } GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Received a store request (size: %lu).\n" " Sub system `%s'\n" - " Peer `%s'\n" " Key `%s'\n" " Value size %lu\n" - " Options: %d.\n", record->value_size, record->sub_system, - GNUNET_i2s (record->peer), record->key, record->value_size, + "Received a store request (size: %u). Sub system `%s' Peer `%s Key `%s' Options: %d.\n", + (unsigned int) record->value_size, + record->sub_system, + GNUNET_i2s (record->peer), + record->key, ntohl (srm->options)); record->client = client; if (GNUNET_OK != diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index 2c6c7dfd8a..767031e6f5 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am @@ -509,7 +509,6 @@ AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PAT TESTS = \ test_transport_testing_startstop \ test_transport_testing_restart \ - test_transport_testing \ test_plugin_tcp \ test_plugin_udp \ $(UNIX_TEST) \ @@ -1266,6 +1265,8 @@ test_transport_api_timeout_tcp_peer1.conf\ test_transport_api_timeout_tcp_peer2.conf\ test_transport_api_multi_peer1.conf\ test_transport_api_multi_peer2.conf\ +test_transport_api_restart_1peer_peer1.conf\ +test_transport_api_restart_1peer_peer2.conf\ test_transport_api_reliability_http_peer1.conf\ test_transport_api_reliability_http_peer2.conf\ test_transport_api_reliability_https_peer1.conf\ @@ -1284,6 +1285,10 @@ test_transport_api_manipulation_recv_tcp_peer1.conf\ test_transport_api_manipulation_recv_tcp_peer2.conf\ test_transport_api_manipulation_cfg_peer1.conf\ test_transport_api_manipulation_cfg_peer2.conf\ +test_transport_api_restart_1peer_peer1.conf\ +test_transport_api_restart_1peer_peer2.conf\ +test_transport_api_restart_2peers_peer1.conf\ +test_transport_api_restart_2peers_peer2.conf\ test_transport_api_tcp_nat_peer1.conf\ test_transport_api_tcp_nat_peer2.conf\ test_transport_api_tcp_peer1.conf\ diff --git a/src/transport/test_transport_address_switch.c b/src/transport/test_transport_address_switch.c index 96e11b7de9..198e82118c 100644 --- a/src/transport/test_transport_address_switch.c +++ b/src/transport/test_transport_address_switch.c @@ -486,7 +486,7 @@ main (int argc, { struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { .connect_continuation = &connected_cb, - .config_file = "test_transport_startonly.conf", + .config_file = "test_transport_api.conf", .rec = ¬ify_receive, .nc = &GNUNET_TRANSPORT_TESTING_log_connect, .nd = ¬ify_disconnect, diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c index ad078f5821..bc0061363a 100644 --- a/src/transport/test_transport_api.c +++ b/src/transport/test_transport_api.c @@ -72,7 +72,7 @@ notify_receive (void *cls, char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Peer %u (`%4s') received message of type %d and size %u size from peer %s!\n", + "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", receiver->no, ps, ntohs (message->type), diff --git a/src/transport/test_transport_api_limited_sockets.c b/src/transport/test_transport_api_limited_sockets.c index 6948d3e6a9..0b7fd645cc 100644 --- a/src/transport/test_transport_api_limited_sockets.c +++ b/src/transport/test_transport_api_limited_sockets.c @@ -254,6 +254,7 @@ run (void *cls, char *const *args, const char *cfgfile, ¬ify_receive, ¬ify_connect, ¬ify_disconnect, + NULL, &start_cb, NULL); p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, @@ -262,6 +263,7 @@ run (void *cls, char *const *args, const char *cfgfile, ¬ify_receive, ¬ify_connect, ¬ify_disconnect, + NULL, &start_cb, NULL); if ((p1 == NULL) || (p2 == NULL)) diff --git a/src/transport/test_transport_api_restart_1peer.c b/src/transport/test_transport_api_restart_1peer.c index e814ad8173..7a63ed16b3 100644 --- a/src/transport/test_transport_api_restart_1peer.c +++ b/src/transport/test_transport_api_restart_1peer.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2009, 2010, 2015 GNUnet e.V. + Copyright (C) 2009, 2010, 2015, 2016 GNUnet e.V. GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -37,116 +37,57 @@ /** * How long until we give up on transmitting the message? */ -#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) +#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) #define MTYPE 12345 -static char *test_name; -static int ok; - -static struct GNUNET_SCHEDULER_Task *die_task; - -static struct GNUNET_SCHEDULER_Task *send_task; +static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; static struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh; -static struct GNUNET_TRANSPORT_TESTING_PeerContext *p1; - static int p1_connected; -static struct GNUNET_TRANSPORT_TESTING_PeerContext *p2; - static int p2_connected; -static struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; - static struct GNUNET_TRANSPORT_TransmitHandle *th; -static struct GNUNET_TRANSPORT_TESTING_Handle *tth; - -static char *cfg_file_p1; - -static char *cfg_file_p2; +static struct GNUNET_SCHEDULER_Task *send_task; static int restarted; static void -end () +custom_shutdown (void *cls) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Stopping peers\n"); - - if (NULL != send_task) - { - GNUNET_SCHEDULER_cancel (send_task); - send_task = NULL; - } if (NULL != ats_sh) { GNUNET_ATS_connectivity_suggest_cancel (ats_sh); ats_sh = NULL; } - if (NULL != die_task) - { - GNUNET_SCHEDULER_cancel (die_task); - die_task = NULL; - } if (NULL != th) { GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); th = NULL; } - if (NULL != p1) - { - GNUNET_TRANSPORT_TESTING_stop_peer (p1); - p1 = NULL; - } - if (NULL != p2) - { - GNUNET_TRANSPORT_TESTING_stop_peer (p2); - p2 = NULL; - } -} - - -static void -end_badly (void *cls) -{ - die_task = NULL; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Fail! Stopping peers\n"); - - if (restarted == GNUNET_YES) - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Peer was restarted\n"); - - if (restarted == GNUNET_NO) - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Peer was NOT restarted\n"); - if (NULL != cc) + if (NULL != send_task) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Fail! Could not connect peers\n")); - GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); - cc = NULL; + GNUNET_SCHEDULER_cancel (send_task); + send_task = NULL; } - end (); - ok = GNUNET_SYSERR; } static void -restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, void *cls) +restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, + void *cls) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Restarted peer %u (`%4s'), issuing reconnect\n", + "Restarted peer %u (`%s'), issuing reconnect\n", p->no, GNUNET_i2s (&p->id)); ats_sh = GNUNET_ATS_connectivity_suggest (p->ats, - &p2->id, + &ccc->p[1]->id, 1); } @@ -155,81 +96,75 @@ static void restart (struct GNUNET_TRANSPORT_TESTING_PeerContext *p) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Restarting peer %u (`%4s')\n", + "Restarting peer %u (`%s')\n", p->no, GNUNET_i2s (&p->id)); - GNUNET_TRANSPORT_TESTING_restart_peer (p, - &restart_cb, - p); + GNUNET_assert (GNUNET_OK == + GNUNET_TRANSPORT_TESTING_restart_peer (p, + &restart_cb, + p)); } static void notify_receive (void *cls, - const struct GNUNET_PeerIdentity *peer, + struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, + const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *message) { - struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; - struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL; - - if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) - t = p1; - if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))) - t = p2; - GNUNET_assert (t != NULL); - - char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n", - p->no, ps, ntohs (message->type), ntohs (message->size), t->no, - GNUNET_i2s (&t->id)); - GNUNET_free (ps); + { + char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", + receiver->no, + ps, + ntohs (message->type), + ntohs (message->size), + GNUNET_i2s (sender)); + GNUNET_free (ps); + } if ((MTYPE == ntohs (message->type)) && (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) { - if (restarted == GNUNET_NO) + if (GNUNET_NO == restarted) { restarted = GNUNET_YES; - restart (p1); + restart (ccc->p[0]); return; } else { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Restarted peers connected and message was sent, stopping test...\n"); - ok = 0; - end (); + ccc->global_ret = GNUNET_OK; + GNUNET_SCHEDULER_shutdown (); } } else { GNUNET_break (0); - ok = 1; - if (die_task != NULL) - GNUNET_SCHEDULER_cancel (die_task); - die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); + ccc->global_ret = GNUNET_SYSERR; + GNUNET_SCHEDULER_shutdown (); } } static size_t -notify_ready (void *cls, size_t size, void *buf) +notify_ready (void *cls, + size_t size, + void *buf) { struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; struct GNUNET_MessageHeader *hdr; th = NULL; - if (NULL == buf) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Timeout occurred while waiting for transmit_ready\n"); - if (NULL != die_task) - GNUNET_SCHEDULER_cancel (die_task); - die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); - ok = 42; + GNUNET_SCHEDULER_shutdown (); + ccc->global_ret = 42; return 0; } @@ -239,11 +174,12 @@ notify_ready (void *cls, size_t size, void *buf) hdr->type = htons (MTYPE); { - char *ps = GNUNET_strdup (GNUNET_i2s (&p2->id)); + char *ps = GNUNET_strdup (GNUNET_i2s (&ccc->p[1]->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Peer %u (`%4s') sending message with type %u and size %u bytes to peer %u (`%4s')\n", - p2->no, + "Peer %u (`%s') sending message with type %u and size %u bytes to peer %u (`%s')\n", + ccc->p[1]->no, ps, ntohs (hdr->type), ntohs (hdr->size), @@ -259,212 +195,99 @@ static void sendtask (void *cls) { send_task = NULL; - char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id)); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", - p2->no, GNUNET_i2s (&p2->id), p1->no, receiver_s); - GNUNET_free (receiver_s); - - th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, - &p1->id, + { + char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id)); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", + ccc->p[1]->no, + GNUNET_i2s (&ccc->p[1]->id), + ccc->p[0]->no, + receiver_s); + GNUNET_free (receiver_s); + } + th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th, + &ccc->p[0]->id, 256, TIMEOUT_TRANSMIT, ¬ify_ready, - p1); + ccc->p[0]); } static void notify_connect (void *cls, - const struct GNUNET_PeerIdentity *peer) + struct GNUNET_TRANSPORT_TESTING_PeerContext *me, + const struct GNUNET_PeerIdentity *other) { - static int c; - - c++; - struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; - struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL; - - if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) - { + GNUNET_TRANSPORT_TESTING_log_connect (cls, + me, + other); + if (0 == memcmp (other, + &ccc->p[0]->id, + sizeof (struct GNUNET_PeerIdentity))) p1_connected = GNUNET_YES; - t = p1; - } - if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))) - { + if (0 == memcmp (other, + &ccc->p[1]->id, + sizeof (struct GNUNET_PeerIdentity))) p2_connected = GNUNET_YES; - t = p2; - } - GNUNET_assert (t != NULL); - char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", p->no, ps, - t->no, GNUNET_i2s (peer)); - GNUNET_free (ps); - - if ( (restarted == GNUNET_YES) && - (p1_connected == GNUNET_YES) && - (p2_connected == GNUNET_YES) ) + if ( (GNUNET_YES == restarted) && + (GNUNET_YES == p1_connected) && + (GNUNET_YES == p2_connected) ) { /* Peer was restarted and we received 3 connect messages (2 from first connect, 1 from reconnect) */ - send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL); + send_task = GNUNET_SCHEDULER_add_now (&sendtask, + NULL); } } static void -notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) +notify_disconnect (void *cls, + struct GNUNET_TRANSPORT_TESTING_PeerContext *me, + const struct GNUNET_PeerIdentity *other) { - struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; - - if ( (NULL != p1) && - (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity)))) - { + GNUNET_TRANSPORT_TESTING_log_disconnect (cls, + me, + other); + if (me == ccc->p[0]) p1_connected = GNUNET_NO; - } - if ( (NULL != p2) && - (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity)))) - { + if (me == ccc->p[1]) p2_connected = GNUNET_NO; - } - char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", p->no, ps, - GNUNET_i2s (peer)); - GNUNET_free (ps); - - if (th != NULL) + if (NULL != th) + { GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); - th = NULL; + th = NULL; + } if (NULL != send_task) - GNUNET_SCHEDULER_cancel (send_task); - send_task = NULL; -} - - -static void -testing_connect_cb (void *cls) -{ - cc = NULL; - char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Peers connected: %u (%s) <-> %u (%s)\n", - p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id)); - GNUNET_free (p1_c); - - send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL); -} - - - -static void -start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, void *cls) -{ - static int started; - - started++; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no, - GNUNET_i2s (&p->id)); - - if (started != 2) - return; - - char *sender_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", - p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id)); - GNUNET_free (sender_c); - - cc = GNUNET_TRANSPORT_TESTING_connect_peers (p1, - p2, - &testing_connect_cb, - NULL); - -} - -static void -run (void *cls, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) -{ - die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); - p1_connected = GNUNET_NO; - p2_connected = GNUNET_NO; - p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, - cfg_file_p1, - 1, - ¬ify_receive, - ¬ify_connect, - ¬ify_disconnect, - &start_cb, - NULL); - - p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, - cfg_file_p2, - 2, - ¬ify_receive, - ¬ify_connect, - ¬ify_disconnect, - &start_cb, - NULL); - - if ((p1 == NULL) || (p2 == NULL)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Fail! Could not start peers!\n"); - if (die_task != NULL) - GNUNET_SCHEDULER_cancel (die_task); - die_task = GNUNET_SCHEDULER_add_now (&end_badly, - NULL); - return; + GNUNET_SCHEDULER_cancel (send_task); + send_task = NULL; } } -static int -check () -{ - static char *const argv[] = { "test-transport-api", - "-c", - "test_transport_api_data.conf", - NULL - }; - static struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_OPTION_END - }; - - send_task = NULL; - - ok = 1; - GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, test_name, - "nohelp", options, &run, &ok); - - return ok; -} - int main (int argc, char *argv[]) { - int ret; - - test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv[0]); - GNUNET_log_setup (test_name, - "WARNING", - NULL); - tth = GNUNET_TRANSPORT_TESTING_init (); - GNUNET_asprintf (&cfg_file_p1, "test_transport_api_tcp_peer1.conf"); - GNUNET_asprintf (&cfg_file_p2, "test_transport_api_tcp_peer2.conf"); - ret = check (); - GNUNET_free (cfg_file_p1); - GNUNET_free (cfg_file_p2); - GNUNET_free (test_name); - GNUNET_TRANSPORT_TESTING_done (tth); - return ret; + struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { + .connect_continuation = &sendtask, + .config_file = "test_transport_api_data.conf", + .rec = ¬ify_receive, + .nc = ¬ify_connect, + .nd = ¬ify_disconnect, + .shutdown_task = &custom_shutdown, + .timeout = TIMEOUT + }; + + ccc = &my_ccc; + if (GNUNET_OK != + GNUNET_TRANSPORT_TESTING_main (2, + &GNUNET_TRANSPORT_TESTING_connect_check, + ccc)) + return 1; + return 0; } /* end of test_transport_api_restart_1peer.c */ diff --git a/src/transport/test_transport_api_restart_1peer_peer1.conf b/src/transport/test_transport_api_restart_1peer_peer1.conf new file mode 100644 index 0000000000..4bfe9b6ca9 --- /dev/null +++ b/src/transport/test_transport_api_restart_1peer_peer1.conf @@ -0,0 +1,9 @@ +@INLINE@ template_cfg_peer1.conf +[PATHS] +GNUNET_TEST_HOME = /tmp/test-transport/api-tcp-p1/ + +[transport] +PLUGINS = tcp + +#[transport] +#PREFIX = valgrind diff --git a/src/transport/test_transport_api_restart_1peer_peer2.conf b/src/transport/test_transport_api_restart_1peer_peer2.conf new file mode 100644 index 0000000000..e68cdbee4b --- /dev/null +++ b/src/transport/test_transport_api_restart_1peer_peer2.conf @@ -0,0 +1,9 @@ +@INLINE@ template_cfg_peer2.conf +[PATHS] +GNUNET_TEST_HOME = /tmp/test-transport/api-tcp-p2/ + +[transport] +PLUGINS = tcp + +#[transport] +#PREFIX = valgrind diff --git a/src/transport/test_transport_api_restart_2peers.c b/src/transport/test_transport_api_restart_2peers.c index 876b7209c7..40f2876239 100644 --- a/src/transport/test_transport_api_restart_2peers.c +++ b/src/transport/test_transport_api_restart_2peers.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2009, 2010, 2015 GNUnet e.V. + Copyright (C) 2009, 2010, 2015, 2016 GNUnet e.V. GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -18,11 +18,12 @@ Boston, MA 02110-1301, USA. */ /** - * @file transport/test_transport_api_restart_2peers.c + * @file transport/test_transport_api_restart_1peer.c * @brief base test case for transport implementations * * This test case starts 2 peers, connects and exchanges a message - * boths peer are restarted and tested if peers reconnect + * 1 peer is restarted and tested if peers reconnect + * C code apparently. */ #include "platform.h" #include "gnunet_transport_service.h" @@ -31,100 +32,49 @@ /** * How long until we give up on transmitting the message? */ -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 900) +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) /** * How long until we give up on transmitting the message? */ -#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) +#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) #define MTYPE 12345 -static char *test_name; -static int ok; - -static struct GNUNET_SCHEDULER_Task *die_task; - -static struct GNUNET_SCHEDULER_Task *send_task; +static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; static struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh; -static struct GNUNET_TRANSPORT_TESTING_PeerContext *p1; - -static struct GNUNET_TRANSPORT_TESTING_PeerContext *p2; +static int p1_connected; -static struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; +static int p2_connected; static struct GNUNET_TRANSPORT_TransmitHandle *th; -static struct GNUNET_TRANSPORT_TESTING_Handle *tth; - -static char *cfg_file_p1; - -static char *cfg_file_p2; +static struct GNUNET_SCHEDULER_Task *send_task; static int restarted; static void -end () +custom_shutdown (void *cls) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); - if (NULL != send_task) - { - GNUNET_SCHEDULER_cancel (send_task); - send_task = NULL; - } if (NULL != ats_sh) { GNUNET_ATS_connectivity_suggest_cancel (ats_sh); ats_sh = NULL; } - if (NULL != die_task) - { - GNUNET_SCHEDULER_cancel (die_task); - die_task = NULL; - } if (NULL != th) { GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); th = NULL; } - if (NULL != p1) - { - GNUNET_TRANSPORT_TESTING_stop_peer (p1); - p1 = NULL; - } - if (NULL != p2) - { - GNUNET_TRANSPORT_TESTING_stop_peer (p2); - p2 = NULL; - } -} - - -static void -end_badly (void *cls) -{ - die_task = NULL; - - if (restarted == GNUNET_YES) - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Peer was restarted, but communication did not resume\n"); - - if (restarted == GNUNET_NO) - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Peer was NOT (even) restarted\n"); - if (cc != NULL) + if (NULL != send_task) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Fail! Could not connect peers\n")); - GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); - cc = NULL; + GNUNET_SCHEDULER_cancel (send_task); + send_task = NULL; } - end (); - ok = GNUNET_SYSERR; } @@ -132,17 +82,17 @@ static void restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, void *cls) { - static int c; + static unsigned int c; c++; if (c != 2) return; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Restarted peer %u (`%4s'), issuing reconnect\n", + "Restarted peer %u (`%s'), issuing reconnect\n", p->no, GNUNET_i2s (&p->id)); - ats_sh = GNUNET_ATS_connectivity_suggest (p->ats, - &p2->id, + ats_sh = GNUNET_ATS_connectivity_suggest (ccc->p[0]->ats, + &ccc->p[1]->id, 1); } @@ -150,78 +100,66 @@ restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, static void restart (struct GNUNET_TRANSPORT_TESTING_PeerContext *p) { - GNUNET_assert (NULL != p); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Restarting peer %u (`%4s')\n", + "Restarting peer %u (`%s')\n", p->no, GNUNET_i2s (&p->id)); - GNUNET_TRANSPORT_TESTING_restart_peer (p, - &restart_cb, - p); + GNUNET_assert (GNUNET_OK == + GNUNET_TRANSPORT_TESTING_restart_peer (p, + &restart_cb, + p)); } static void notify_receive (void *cls, - const struct GNUNET_PeerIdentity *peer, + struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, + const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *message) { - struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; - struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL; - - if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) - t = p1; - if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))) - t = p2; - GNUNET_assert (t != NULL); - { - char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); + char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n", - p->no, + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", + receiver->no, ps, ntohs (message->type), ntohs (message->size), - t->no, - GNUNET_i2s (&t->id)); + GNUNET_i2s (sender)); GNUNET_free (ps); } - if ((MTYPE == ntohs (message->type)) && (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) { - if (restarted == GNUNET_NO) + if (GNUNET_NO == restarted) { restarted = GNUNET_YES; - restart (p1); - restart (p2); + restart (ccc->p[0]); + restart (ccc->p[1]); return; } else { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Restarted peers connected, stopping test...\n"); - ok = 0; - end (); + "Restarted peers connected and message was sent, stopping test...\n"); + ccc->global_ret = GNUNET_OK; + GNUNET_SCHEDULER_shutdown (); } } else { GNUNET_break (0); - ok = 1; - if (die_task != NULL) - GNUNET_SCHEDULER_cancel (die_task); - die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); + ccc->global_ret = GNUNET_SYSERR; + GNUNET_SCHEDULER_shutdown (); } } static size_t notify_ready (void *cls, - size_t size, - void *buf) + size_t size, + void *buf) { struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; struct GNUNET_MessageHeader *hdr; @@ -231,10 +169,8 @@ notify_ready (void *cls, { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Timeout occurred while waiting for transmit_ready\n"); - if (NULL != die_task) - GNUNET_SCHEDULER_cancel (die_task); - die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); - ok = 42; + GNUNET_SCHEDULER_shutdown (); + ccc->global_ret = 42; return 0; } @@ -244,11 +180,11 @@ notify_ready (void *cls, hdr->type = htons (MTYPE); { - char *ps = GNUNET_strdup (GNUNET_i2s (&p2->id)); + char *ps = GNUNET_strdup (GNUNET_i2s (&ccc->p[1]->id)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Peer %u (`%4s') sending message with type %u and size %u bytes to peer %u (`%4s')\n", - p2->no, + "Peer %u (`%s') sending message with type %u and size %u bytes to peer %u (`%s')\n", + ccc->p[1]->no, ps, ntohs (hdr->type), ntohs (hdr->size), @@ -256,7 +192,6 @@ notify_ready (void *cls, GNUNET_i2s (&p->id)); GNUNET_free (ps); } - return sizeof (struct GNUNET_MessageHeader); } @@ -266,82 +201,66 @@ sendtask (void *cls) { send_task = NULL; { - char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id)); - + char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", - p2->no, - GNUNET_i2s (&p2->id), - p1->no, - receiver_s); + "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", + ccc->p[1]->no, + GNUNET_i2s (&ccc->p[1]->id), + ccc->p[0]->no, + receiver_s); GNUNET_free (receiver_s); } - - th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, - &p1->id, + th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th, + &ccc->p[0]->id, 256, TIMEOUT_TRANSMIT, ¬ify_ready, - p1); + ccc->p[0]); } static void -notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) +notify_connect (void *cls, + struct GNUNET_TRANSPORT_TESTING_PeerContext *me, + const struct GNUNET_PeerIdentity *other) { - static int c; - struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; - struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL; - - c++; - if (0 == memcmp (peer, - &p1->id, - sizeof (struct GNUNET_PeerIdentity))) - t = p1; - if (0 == memcmp (peer, - &p2->id, - sizeof (struct GNUNET_PeerIdentity))) - t = p2; - GNUNET_assert (t != NULL); - - { - char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", - p->no, - ps, - t->no, - GNUNET_i2s (peer)); - GNUNET_free (ps); - } - - if ((restarted == GNUNET_YES) && (c == 4)) + GNUNET_TRANSPORT_TESTING_log_connect (cls, + me, + other); + if (0 == memcmp (other, + &ccc->p[0]->id, + sizeof (struct GNUNET_PeerIdentity))) + p1_connected = GNUNET_YES; + if (0 == memcmp (other, + &ccc->p[1]->id, + sizeof (struct GNUNET_PeerIdentity))) + p2_connected = GNUNET_YES; + + if ( (GNUNET_YES == restarted) && + (GNUNET_YES == p1_connected) && + (GNUNET_YES == p2_connected) ) { + /* Peer was restarted and we received 3 connect messages (2 from first connect, 1 from reconnect) */ send_task = GNUNET_SCHEDULER_add_now (&sendtask, - NULL); + NULL); } } static void notify_disconnect (void *cls, - const struct GNUNET_PeerIdentity *peer) + struct GNUNET_TRANSPORT_TESTING_PeerContext *me, + const struct GNUNET_PeerIdentity *other) { - struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; - - { - char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", - p->no, - ps, - GNUNET_i2s (peer)); - GNUNET_free (ps); - } - - if (th != NULL) + GNUNET_TRANSPORT_TESTING_log_disconnect (cls, + me, + other); + if (me == ccc->p[0]) + p1_connected = GNUNET_NO; + if (me == ccc->p[1]) + p2_connected = GNUNET_NO; + if (NULL != th) { GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); th = NULL; @@ -354,137 +273,26 @@ notify_disconnect (void *cls, } -static void -testing_connect_cb (void *cls) -{ - cc = NULL; - - { - char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Peers connected: %u (%s) <-> %u (%s)\n", - p1->no, - p1_c, - p2->no, - GNUNET_i2s (&p2->id)); - GNUNET_free (p1_c); - } - send_task = GNUNET_SCHEDULER_add_now (&sendtask, - NULL); -} - - -static void -start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, void *cls) -{ - static int started; - - started++; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Peer %u (`%s') started\n", - p->no, - GNUNET_i2s (&p->id)); - if (started != 2) - return; - - { - char *sender_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", - p1->no, - sender_c, - p2->no, - GNUNET_i2s (&p2->id)); - GNUNET_free (sender_c); - } - - cc = GNUNET_TRANSPORT_TESTING_connect_peers (p1, - p2, - &testing_connect_cb, - NULL); -} - - -static void -run (void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) -{ - die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, - &end_badly, - NULL); - p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, - cfg_file_p1, - 1, - ¬ify_receive, - ¬ify_connect, - ¬ify_disconnect, - &start_cb, - NULL); - - p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, - cfg_file_p2, - 2, - ¬ify_receive, - ¬ify_connect, - ¬ify_disconnect, - &start_cb, - NULL); - - if ((p1 == NULL) || (p2 == NULL)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n"); - if (die_task != NULL) - GNUNET_SCHEDULER_cancel (die_task); - die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); - return; - } -} - - -static int -check () -{ - static char *const argv[] = { "test-transport-api", - "-c", - "test_transport_api_data.conf", - NULL - }; - static struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_OPTION_END - }; - - send_task = NULL; - - ok = 1; - GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, test_name, - "nohelp", options, &run, NULL); - - return ok; -} - - int main (int argc, char *argv[]) { - int ret; - - test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv[0]); - GNUNET_log_setup (test_name, - "WARNING", - NULL); - tth = GNUNET_TRANSPORT_TESTING_init (); - GNUNET_asprintf (&cfg_file_p1, "test_transport_api_tcp_peer1.conf"); - GNUNET_asprintf (&cfg_file_p2, "test_transport_api_tcp_peer2.conf"); - ret = check (); - GNUNET_free (cfg_file_p1); - GNUNET_free (cfg_file_p2); - GNUNET_free (test_name); - GNUNET_TRANSPORT_TESTING_done (tth); - return ret; + struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { + .connect_continuation = &sendtask, + .config_file = "test_transport_api_data.conf", + .rec = ¬ify_receive, + .nc = ¬ify_connect, + .nd = ¬ify_disconnect, + .shutdown_task = &custom_shutdown, + .timeout = TIMEOUT + }; + + ccc = &my_ccc; + if (GNUNET_OK != + GNUNET_TRANSPORT_TESTING_main (2, + &GNUNET_TRANSPORT_TESTING_connect_check, + ccc)) + return 1; + return 0; } -/* end of test_transport_api_restart_2peers.c */ +/* end of test_transport_api_restart_1peer.c */ diff --git a/src/transport/test_transport_api_restart_2peers_peer1.conf b/src/transport/test_transport_api_restart_2peers_peer1.conf new file mode 100644 index 0000000000..4bfe9b6ca9 --- /dev/null +++ b/src/transport/test_transport_api_restart_2peers_peer1.conf @@ -0,0 +1,9 @@ +@INLINE@ template_cfg_peer1.conf +[PATHS] +GNUNET_TEST_HOME = /tmp/test-transport/api-tcp-p1/ + +[transport] +PLUGINS = tcp + +#[transport] +#PREFIX = valgrind diff --git a/src/transport/test_transport_api_restart_2peers_peer2.conf b/src/transport/test_transport_api_restart_2peers_peer2.conf new file mode 100644 index 0000000000..e68cdbee4b --- /dev/null +++ b/src/transport/test_transport_api_restart_2peers_peer2.conf @@ -0,0 +1,9 @@ +@INLINE@ template_cfg_peer2.conf +[PATHS] +GNUNET_TEST_HOME = /tmp/test-transport/api-tcp-p2/ + +[transport] +PLUGINS = tcp + +#[transport] +#PREFIX = valgrind diff --git a/src/transport/test_transport_api_timeout.c b/src/transport/test_transport_api_timeout.c index fcc0b044e3..29d69c879d 100644 --- a/src/transport/test_transport_api_timeout.c +++ b/src/transport/test_transport_api_timeout.c @@ -261,6 +261,7 @@ run (void *cls, char *const *args, const char *cfgfile, ¬ify_receive, ¬ify_connect, ¬ify_disconnect, + NULL, &start_cb, NULL); p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, @@ -269,6 +270,7 @@ run (void *cls, char *const *args, const char *cfgfile, ¬ify_receive, ¬ify_connect, ¬ify_disconnect, + NULL, &start_cb, NULL); diff --git a/src/transport/test_transport_blacklisting.c b/src/transport/test_transport_blacklisting.c index 3696dc71a1..4c1f73152d 100644 --- a/src/transport/test_transport_blacklisting.c +++ b/src/transport/test_transport_blacklisting.c @@ -275,6 +275,7 @@ run_stage (void *cls) 1, NULL, NULL, + NULL, NULL, &start_cb, NULL); @@ -284,6 +285,7 @@ run_stage (void *cls) 2, NULL, NULL, + NULL, NULL, &start_cb, NULL); @@ -297,10 +299,12 @@ run_stage (void *cls) p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_p1, 1, NULL, NULL, NULL, + NULL, &start_cb, NULL); p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_p2, 2, NULL, NULL, NULL, + NULL, &start_cb, NULL); /* check if configuration contain correct blacklist entries */ @@ -328,6 +332,7 @@ run_stage (void *cls) cfg_p1, 1, NULL, + NULL, NULL, NULL, &start_cb, @@ -337,6 +342,7 @@ run_stage (void *cls) cfg_p2, 2, NULL, NULL, + NULL, NULL, &start_cb, NULL); @@ -363,11 +369,13 @@ run_stage (void *cls) p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_p1, 1, + NULL, NULL, NULL, NULL, &start_cb, NULL); p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_p2, 2, + NULL, NULL, NULL, NULL, &start_cb, NULL); @@ -391,11 +399,13 @@ run_stage (void *cls) p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_p1, 1, + NULL, NULL, NULL, NULL, &start_cb, NULL); p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_p2, 2, + NULL, NULL, NULL, NULL, &start_cb, NULL); @@ -421,11 +431,13 @@ run_stage (void *cls) p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_p1, 1, + NULL, NULL, NULL, NULL, &start_cb, NULL); p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_p2, 2, + NULL, NULL, NULL, NULL, &start_cb, NULL); diff --git a/src/transport/test_transport_testing_restart.c b/src/transport/test_transport_testing_restart.c index 2d06bf6681..4d54337131 100644 --- a/src/transport/test_transport_testing_restart.c +++ b/src/transport/test_transport_testing_restart.c @@ -122,6 +122,7 @@ run (void *cls, NULL, /* receive cb */ NULL, /* connect cb */ NULL, /* disconnect cb */ + NULL, /* nc/nd closure */ start_cb, /* startup cb */ NULL); /* closure */ if (NULL == p) diff --git a/src/transport/test_transport_testing_startstop.c b/src/transport/test_transport_testing_startstop.c index c516d4277a..0846357e66 100644 --- a/src/transport/test_transport_testing_startstop.c +++ b/src/transport/test_transport_testing_startstop.c @@ -91,14 +91,15 @@ run (void *cls, &end_badly, NULL); - p = GNUNET_TRANSPORT_TESTING_start_peer(tth, - cfgfile, - 1, - NULL, /* receive cb */ - NULL, /* connect cb */ - NULL, /* disconnect cb */ - &start_cb, /* startup cb */ - NULL); /* closure */ + p = GNUNET_TRANSPORT_TESTING_start_peer (tth, + cfgfile, + 1, + NULL, /* receive cb */ + NULL, /* connect cb */ + NULL, /* disconnect cb */ + NULL, /* nc/nd closure */ + &start_cb, /* startup cb */ + NULL); /* closure */ if (NULL == p) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start peer\n"); diff --git a/src/transport/transport-testing-main.c b/src/transport/transport-testing-main.c index de2ec3d0c6..f196d586bf 100644 --- a/src/transport/transport-testing-main.c +++ b/src/transport/transport-testing-main.c @@ -383,6 +383,7 @@ connect_check_run (void *cls, &my_rec, &my_nc, &my_nd, + &ccc->ip[i], &start_cb, &ccc->ip[i]); if (NULL == ccc->p[i]) diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c index ae878a79e5..3226274591 100644 --- a/src/transport/transport-testing.c +++ b/src/transport/transport-testing.c @@ -186,7 +186,7 @@ get_hello (void *cb_cls, p->no, GNUNET_i2s (&p->id)); p->start_cb (p, - p->cb_cls); + p->start_cb_cls); p->start_cb = NULL; } } @@ -200,8 +200,9 @@ get_hello (void *cb_cls, * @param rec receive callback * @param nc connect callback * @param nd disconnect callback - * @param start_cb start callback * @param cb_cls closure for callback + * @param start_cb start callback + * @param start_cb_cls closure for callback * @return the peer context */ struct GNUNET_TRANSPORT_TESTING_PeerContext * @@ -211,8 +212,9 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth GNUNET_TRANSPORT_ReceiveCallback rec, GNUNET_TRANSPORT_NotifyConnect nc, GNUNET_TRANSPORT_NotifyDisconnect nd, + void *cb_cls, GNUNET_TRANSPORT_TESTING_StartCallback start_cb, - void *cb_cls) + void *start_cb_cls) { char *emsg = NULL; struct GNUNET_TRANSPORT_TESTING_PeerContext *p; @@ -231,11 +233,12 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth p->nc = nc; p->nd = nd; p->rec = rec; - p->start_cb = start_cb; - if (cb_cls != NULL) + if (NULL != cb_cls) p->cb_cls = cb_cls; else p->cb_cls = p; + p->start_cb = start_cb; + p->start_cb_cls = start_cb_cls; GNUNET_CONTAINER_DLL_insert (tth->p_head, tth->p_tail, p); @@ -341,13 +344,13 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth * * @param p the peer * @param restart_cb callback to call when restarted - * @param cb_cls callback closure + * @param restart_cb_cls callback closure * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR */ int GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, GNUNET_TRANSPORT_TESTING_StartCallback restart_cb, - void *cb_cls) + void *restart_cb_cls) { /* shutdown */ LOG (GNUNET_ERROR_TYPE_DEBUG, @@ -397,7 +400,7 @@ GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerConte GNUNET_assert (NULL == p->start_cb); p->start_cb = restart_cb; - p->cb_cls = cb_cls; + p->start_cb_cls = restart_cb_cls; p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h index b78d11dbe8..4be451d352 100644 --- a/src/transport/transport-testing.h +++ b/src/transport/transport-testing.h @@ -140,11 +140,16 @@ struct GNUNET_TRANSPORT_TESTING_PeerContext struct GNUNET_HELLO_Message *hello; /** - * Closure for the callbacks + * Closure for the @a nc and @a nd callbacks */ void *cb_cls; /** + * Closure for @e start_cb. + */ + void *start_cb_cls; + + /** * An unique number to identify the peer */ unsigned int no; @@ -266,8 +271,9 @@ GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_Handle *tth); * @param rec receive callback * @param nc connect callback * @param nd disconnect callback + * @param cb_cls closure for @a nc and @a nd callback * @param start_cb start callback - * @param cb_cls closure for callback + * @param start_cb_cls closure for @a start_cb * @return the peer context */ struct GNUNET_TRANSPORT_TESTING_PeerContext * @@ -277,8 +283,9 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth GNUNET_TRANSPORT_ReceiveCallback rec, GNUNET_TRANSPORT_NotifyConnect nc, GNUNET_TRANSPORT_NotifyDisconnect nd, + void *cb_cls, GNUNET_TRANSPORT_TESTING_StartCallback start_cb, - void *cb_cls); + void *start_cb_cls); /** @@ -295,13 +302,13 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext * * @param p the peer * @param restart_cb restart callback - * @param cb_cls callback closure + * @param restart_cb_cls callback closure * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR */ int GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, GNUNET_TRANSPORT_TESTING_StartCallback restart_cb, - void *cb_cls); + void *restart_cb_cls); diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c index e7db5493ea..83b7732e40 100644 --- a/src/transport/transport_api.c +++ b/src/transport/transport_api.c @@ -817,6 +817,7 @@ transmit_ready (struct GNUNET_TRANSPORT_Handle *h) GNUNET_MQ_discard (env); continue; } + obm->header.size = htons (mret + sizeof (*obm)); if (NULL != n->unready_warn_task) n->unready_warn_task = GNUNET_SCHEDULER_add_delayed (UNREADY_WARN_TIME, diff --git a/src/util/server_mst.c b/src/util/server_mst.c index 41b2e8ed98..89a25983c0 100644 --- a/src/util/server_mst.c +++ b/src/util/server_mst.c @@ -244,7 +244,7 @@ do_align: want = ntohs (hdr->size); if (want < sizeof (struct GNUNET_MessageHeader)) { - GNUNET_break_op (0); + GNUNET_break_op (0); mst->off = 0; return GNUNET_SYSERR; } |