From 17bca33cca3c06668aa07c2750000a40a229c4a3 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 6 Nov 2015 23:28:30 +0000 Subject: -removing last uses of TRANSPORT_try_connect API --- src/transport/Makefile.am | 5 +- src/transport/test_transport_api_restart_1peer.c | 134 +++++---- src/transport/test_transport_api_restart_2peers.c | 337 +++++++++++++--------- src/transport/test_transport_testing_restart.c | 9 +- src/transport/transport-testing.c | 250 ++++++++++------ src/transport/transport-testing.h | 13 +- 6 files changed, 448 insertions(+), 300 deletions(-) diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index 7cd4596df..c4ce03bee 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am @@ -154,6 +154,7 @@ libgnunettransporttesting_la_SOURCES = \ libgnunettransporttesting_la_LIBADD = \ libgnunettransport.la \ $(top_builddir)/src/hello/libgnunethello.la \ + $(top_builddir)/src/ats/libgnunetats.la \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/testing/libgnunettesting.la \ $(GN_LIBINTL) @@ -791,6 +792,7 @@ test_transport_api_restart_1peer_SOURCES = \ test_transport_api_restart_1peer_LDADD = \ libgnunettransport.la \ $(top_builddir)/src/hello/libgnunethello.la \ + $(top_builddir)/src/ats/libgnunetats.la \ $(top_builddir)/src/statistics/libgnunetstatistics.la \ $(top_builddir)/src/util/libgnunetutil.la \ libgnunettransporttesting.la @@ -800,7 +802,8 @@ test_transport_api_restart_2peers_SOURCES = \ test_transport_api_restart_2peers_LDADD = \ libgnunettransport.la \ $(top_builddir)/src/hello/libgnunethello.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la \ + $(top_builddir)/src/ats/libgnunetats.la \ +$(top_builddir)/src/statistics/libgnunetstatistics.la \ $(top_builddir)/src/util/libgnunetutil.la \ libgnunettransporttesting.la diff --git a/src/transport/test_transport_api_restart_1peer.c b/src/transport/test_transport_api_restart_1peer.c index 0e91fa68f..2c4382e9c 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 Christian Grothoff (and other contributing authors) + Copyright (C) 2009, 2010, 2015 Christian Grothoff (and other contributing authors) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -45,11 +45,11 @@ static char *test_name; static int ok; -static struct GNUNET_SCHEDULER_Task * die_task; +static struct GNUNET_SCHEDULER_Task *die_task; -static struct GNUNET_SCHEDULER_Task * send_task; +static struct GNUNET_SCHEDULER_Task *send_task; -static struct GNUNET_SCHEDULER_Task * reconnect_task; +static struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh; static struct PeerContext *p1; @@ -59,7 +59,7 @@ static struct PeerContext *p2; static int p2_connected; -static struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc; +static struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; static struct GNUNET_TRANSPORT_TransmitHandle *th; @@ -75,105 +75,101 @@ static int restarted; static void end () { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Stopping peers\n"); - if (send_task != NULL) + if (NULL != send_task) + { GNUNET_SCHEDULER_cancel (send_task); - send_task = NULL; - - if (reconnect_task != NULL) - GNUNET_SCHEDULER_cancel (reconnect_task); - reconnect_task = NULL; - - if (die_task != NULL) + 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 (th != NULL) + die_task = NULL; + } + if (NULL != th) + { GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); - th = NULL; - - GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); - p1 = NULL; - GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); - p2 = NULL; + th = NULL; + } + if (NULL != p1) + { + GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); + p1 = NULL; + } + if (NULL != p2) + { + GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); + p2 = NULL; + } } + static void -end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +end_badly (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) { die_task = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Fail! Stopping peers\n"); if (restarted == GNUNET_YES) - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peer was restarted\n"); + 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 (reconnect_task != NULL) - GNUNET_SCHEDULER_cancel (reconnect_task); - reconnect_task = NULL; - - if (send_task != NULL) - GNUNET_SCHEDULER_cancel (send_task); - send_task = NULL; - - if (cc != NULL) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Peer was NOT restarted\n"); + if (NULL != cc) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Fail! Could not connect peers\n")); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Fail! Could not connect peers\n")); GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); cc = NULL; } - - if (th != NULL) - GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); - th = NULL; - - if (p1 != NULL) - GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); - if (p2 != NULL) - GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); - + end (); ok = GNUNET_SYSERR; } -static void -reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - struct PeerContext *p = cls; - - reconnect_task = NULL; - - GNUNET_TRANSPORT_try_connect (p->th, &p2->id, NULL, NULL); /*FIXME TRY_CONNECT change */ - reconnect_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect, p); -} static void restart_cb (struct PeerContext *p, void *cls) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Restarted peer %u (`%4s'), issuing reconnect\n", p->no, + "Restarted peer %u (`%4s'), issuing reconnect\n", + p->no, GNUNET_i2s (&p->id)); - - reconnect_task = GNUNET_SCHEDULER_add_now (&reconnect, p); + ats_sh = GNUNET_ATS_connectivity_suggest (p->ats, + &p2->id, + 1); } + static void -restart (struct PeerContext *p, char *cfg_file) +restart (struct PeerContext *p, + const char *cfg_file) { - GNUNET_assert (p != NULL); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Restarting peer %u (`%4s')\n", p->no, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Restarting peer %u (`%4s')\n", + p->no, GNUNET_i2s (&p->id)); - GNUNET_TRANSPORT_TESTING_restart_peer (tth, p, cfg_file, &restart_cb, p); - return; + GNUNET_TRANSPORT_TESTING_restart_peer (p, + cfg_file, + &restart_cb, + p); } + static void -notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, +notify_receive (void *cls, + const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message) { struct PeerContext *p = cls; diff --git a/src/transport/test_transport_api_restart_2peers.c b/src/transport/test_transport_api_restart_2peers.c index 5b47ee1d3..8d30ba15d 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 Christian Grothoff (and other contributing authors) + Copyright (C) 2009, 2010, 2015 Christian Grothoff (and other contributing authors) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -44,17 +44,17 @@ static char *test_name; static int ok; -static struct GNUNET_SCHEDULER_Task * die_task; +static struct GNUNET_SCHEDULER_Task *die_task; -static struct GNUNET_SCHEDULER_Task * send_task; +static struct GNUNET_SCHEDULER_Task *send_task; -static struct GNUNET_SCHEDULER_Task * reconnect_task; +static struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh; static struct PeerContext *p1; static struct PeerContext *p2; -static struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc; +static struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; static struct GNUNET_TRANSPORT_TransmitHandle *th; @@ -71,80 +71,67 @@ static void end () { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); - if (send_task != NULL) + if (NULL != send_task) + { GNUNET_SCHEDULER_cancel (send_task); - send_task = NULL; - - if (reconnect_task != NULL) - GNUNET_SCHEDULER_cancel (reconnect_task); - reconnect_task = NULL; - - if (die_task != NULL) + 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 (th != NULL) + die_task = NULL; + } + if (NULL != th) + { GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); - th = NULL; - - GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); - GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); + th = NULL; + } + if (NULL != p1) + { + GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); + p1 = NULL; + } + if (NULL != p2) + { + GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); + p2 = NULL; + } } static void -end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +end_badly (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) { die_task = NULL; if (restarted == GNUNET_YES) - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peer was restarted, but communication did not resume\n"); + 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 (reconnect_task != NULL) - GNUNET_SCHEDULER_cancel (reconnect_task); - reconnect_task = NULL; - - if (send_task != NULL) - GNUNET_SCHEDULER_cancel (send_task); - send_task = NULL; - + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Peer was NOT (even) restarted\n"); if (cc != NULL) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Fail! Could not connect peers\n")); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Fail! Could not connect peers\n")); GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); cc = NULL; } - - if (th != NULL) - GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); - th = NULL; - - if (p1 != NULL) - GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); - if (p2 != NULL) - GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); - + end (); ok = GNUNET_SYSERR; } static void -reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - struct PeerContext *p = cls; - - reconnect_task = NULL; - GNUNET_TRANSPORT_try_connect (p1->th, &p2->id, NULL, NULL); /*FIXME TRY_CONNECT change */ - reconnect_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect, p); -} - - -static void -restart_cb (struct PeerContext *p, void *cls) +restart_cb (struct PeerContext *p, + void *cls) { static int c; @@ -152,26 +139,34 @@ restart_cb (struct PeerContext *p, void *cls) if (c != 2) return; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Restarted peer %u (`%4s'), issuing reconnect\n", p->no, + "Restarted peer %u (`%4s'), issuing reconnect\n", + p->no, GNUNET_i2s (&p->id)); - reconnect_task = GNUNET_SCHEDULER_add_now (&reconnect, p); + ats_sh = GNUNET_ATS_connectivity_suggest (p->ats, + &p2->id, + 1); } static void -restart (struct PeerContext *p, char *cfg_file) +restart (struct PeerContext *p, + const char *cfg_file) { - GNUNET_assert (p != NULL); + GNUNET_assert (NULL != p); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Restarting peer %u (`%4s')\n", p->no, GNUNET_i2s (&p->id)); - GNUNET_TRANSPORT_TESTING_restart_peer (tth, p, cfg_file, &restart_cb, p); + GNUNET_TRANSPORT_TESTING_restart_peer (p, + cfg_file, + &restart_cb, + p); } static void -notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, +notify_receive (void *cls, + const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message) { struct PeerContext *p = cls; @@ -183,13 +178,19 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, 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 (&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); + } if ((MTYPE == ntohs (message->type)) && (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) @@ -221,13 +222,15 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, static size_t -notify_ready (void *cls, size_t size, void *buf) +notify_ready (void *cls, + size_t size, + void *buf) { struct PeerContext *p = cls; struct GNUNET_MessageHeader *hdr; th = NULL; - if (buf == NULL) + if (NULL == buf) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Timeout occurred while waiting for transmit_ready\n"); @@ -239,40 +242,54 @@ notify_ready (void *cls, size_t size, void *buf) } GNUNET_assert (size >= 256); + hdr = buf; + hdr->size = htons (sizeof (struct GNUNET_MessageHeader)); + hdr->type = htons (MTYPE); - if (buf != NULL) { - hdr = buf; - hdr->size = htons (sizeof (struct GNUNET_MessageHeader)); - hdr->type = htons (MTYPE); + char *ps = GNUNET_strdup (GNUNET_i2s (&p2->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, + ps, + ntohs (hdr->type), + ntohs (hdr->size), + p->no, + GNUNET_i2s (&p->id)); + GNUNET_free (ps); } - char *ps = GNUNET_strdup (GNUNET_i2s (&p2->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, ps, ntohs (hdr->type), ntohs (hdr->size), p->no, - GNUNET_i2s (&p->id)); - GNUNET_free (ps); return sizeof (struct GNUNET_MessageHeader); } static void -sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +sendtask (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) { send_task = NULL; if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) return; - 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); + { + 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, 256, - TIMEOUT_TRANSMIT, ¬ify_ready, + th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, + &p1->id, + 256, + TIMEOUT_TRANSMIT, + ¬ify_ready, p1); } @@ -281,64 +298,90 @@ static void notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) { static int c; - - c++; struct PeerContext *p = cls; struct PeerContext *t = NULL; - if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) + c++; + if (0 == memcmp (peer, + &p1->id, + sizeof (struct GNUNET_PeerIdentity))) t = p1; - if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))) + 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); + { + 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)) { - 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, + const struct GNUNET_PeerIdentity *peer) { struct 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); + { + 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_notify_transmit_ready_cancel (th); - th = NULL; - if (NULL != send_task) + th = NULL; + } + if (NULL != send_task) + { GNUNET_SCHEDULER_cancel (send_task); - send_task = NULL; + send_task = NULL; + } } static void -testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) +testing_connect_cb (struct PeerContext *p1, + struct PeerContext *p2, + 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); + { + 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); } @@ -348,40 +391,58 @@ start_cb (struct PeerContext *p, void *cls) static int started; started++; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no, + 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); + { + 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 (tth, p1, p2, &testing_connect_cb, + cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, + p1, + p2, + &testing_connect_cb, NULL); - } static void -run (void *cls, char *const *args, const char *cfgfile, +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, + 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, + 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)) diff --git a/src/transport/test_transport_testing_restart.c b/src/transport/test_transport_testing_restart.c index d2d0d4c9e..188cc20b5 100644 --- a/src/transport/test_transport_testing_restart.c +++ b/src/transport/test_transport_testing_restart.c @@ -82,12 +82,17 @@ restart_cb (struct PeerContext *p, void *cls) static void restart_task () { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') restarting, \n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peer %u (`%s') restarting, \n", p->no, GNUNET_i2s (&p->id)); - GNUNET_TRANSPORT_TESTING_restart_peer (tth, p, NULL, restart_cb, p); + GNUNET_TRANSPORT_TESTING_restart_peer (p, + NULL, + &restart_cb, + p); } + static void start_cb (struct PeerContext *p, void *cls) { diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c index 86c67a039..a55727539 100644 --- a/src/transport/transport-testing.c +++ b/src/transport/transport-testing.c @@ -34,7 +34,6 @@ static struct PeerContext * find_peer_context (struct GNUNET_TRANSPORT_TESTING_handle *tth, const struct GNUNET_PeerIdentity *peer) { - GNUNET_assert (tth != NULL); struct PeerContext *t = tth->p_head; while (t != NULL) @@ -183,7 +182,8 @@ get_hello (void *cb_cls, if (NULL != p->start_cb) { LOG (GNUNET_ERROR_TYPE_DEBUG, - "Peer %u (`%s') successfully started\n", p->no, + "Peer %u (`%s') successfully started\n", + p->no, GNUNET_i2s (&p->id)); p->start_cb (p, p->cb_cls); p->start_cb = NULL; @@ -191,8 +191,43 @@ get_hello (void *cb_cls, } +/** + * Offer the current HELLO of P2 to P1. + * + * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequest ` + * @param tc scheduler context + */ +static void +offer_hello (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc); + + +/** + * Function called after the HELLO was passed to the + * transport service. + */ +static void +hello_offered (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc = cls; + + cc->oh = NULL; + cc->tct = + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, + &offer_hello, + cc); +} + + +/** + * Offer the current HELLO of P2 to P1. + * + * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequest ` + * @param tc scheduler context + */ static void -try_connect (void *cls, +offer_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc = cls; @@ -202,26 +237,26 @@ try_connect (void *cls, cc->tct = NULL; if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) return; + { + char *p2_s = GNUNET_strdup (GNUNET_i2s (&p2->id)); - GNUNET_assert (cc != NULL); - GNUNET_assert (cc->p1 != NULL); - GNUNET_assert (cc->p2 != NULL); - - char *p2_s = GNUNET_strdup (GNUNET_i2s (&p2->id)); - - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Asking peer %u (`%s') to connect peer %u (`%s'), providing HELLO with %u bytes\n", - p1->no, GNUNET_i2s (&p1->id), p2->no, p2_s, - GNUNET_HELLO_size (cc->p2->hello)); - GNUNET_free (p2_s); - - GNUNET_TRANSPORT_offer_hello (cc->th_p1, - (const struct GNUNET_MessageHeader *) cc-> - p2->hello, NULL, NULL); - GNUNET_TRANSPORT_try_connect (cc->th_p1, &p2->id, NULL, NULL); /*FIXME TRY_CONNECT change */ + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Asking peer %u (`%s') to connect peer %u (`%s'), providing HELLO with %u bytes\n", + p1->no, + GNUNET_i2s (&p1->id), + p2->no, + p2_s, + GNUNET_HELLO_size (cc->p2->hello)); + GNUNET_free (p2_s); + } - cc->tct = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect, cc); + if (NULL != cc->oh) + GNUNET_TRANSPORT_offer_hello_cancel (cc->oh); + cc->oh = + GNUNET_TRANSPORT_offer_hello (cc->p1->th, + (const struct GNUNET_MessageHeader *) cc->p2->hello, + &hello_offered, + cc); } @@ -239,7 +274,8 @@ try_connect (void *cls, */ struct PeerContext * GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth, - const char *cfgname, int peer_id, + const char *cfgname, + int peer_id, GNUNET_TRANSPORT_ReceiveCallback rec, GNUNET_TRANSPORT_NotifyConnect nc, GNUNET_TRANSPORT_NotifyDisconnect nd, @@ -278,7 +314,8 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth p->no = peer_id; /* Configure peer with configuration */ - p->peer = GNUNET_TESTING_peer_configure (tth->tl_system, p->cfg, p->no, NULL, &emsg); + p->peer = GNUNET_TESTING_peer_configure (tth->tl_system, + p->cfg, p->no, NULL, &emsg); if (NULL == p->peer) { LOG (GNUNET_ERROR_TYPE_ERROR, @@ -329,41 +366,51 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, ¬ify_receive, - ¬ify_connect, ¬ify_disconnect); + ¬ify_connect, + ¬ify_disconnect); if (NULL == p->th) { LOG (GNUNET_ERROR_TYPE_ERROR, - "Failed to connect to transport service for peer `%s': `%s'\n", + "Failed to connect to transport service for peer `%s': `%s'\n", cfgname, emsg); GNUNET_TRANSPORT_TESTING_stop_peer (tth, p); return NULL; } - - p->ghh = GNUNET_TRANSPORT_get_hello (p->th, &get_hello, p); + p->ats = GNUNET_ATS_connectivity_init (p->cfg); + if (NULL == p->ats) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "Failed to connect to ATS service for peer `%s': `%s'\n", + cfgname, + emsg); + GNUNET_TRANSPORT_TESTING_stop_peer (tth, p); + return NULL; + } + p->ghh = GNUNET_TRANSPORT_get_hello (p->th, + &get_hello, + p); GNUNET_assert (p->ghh != NULL); return p; } + /** -* Restart the given peer -* @param tth testing handle -* @param p the peer -* @param cfgname the cfg file used to restart -* @param restart_cb callback to call when restarted -* @param cb_cls callback closure -* @return GNUNET_OK in success otherwise GNUNET_SYSERR -*/ + * Restart the given peer + * + * @param p the peer + * @param cfgname the cfg file used to restart + * @param restart_cb callback to call when restarted + * @param cb_cls callback closure + * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR + */ int -GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_handle - *tth, struct PeerContext *p, +GNUNET_TRANSPORT_TESTING_restart_peer (struct PeerContext *p, const char *cfgname, - GNUNET_TRANSPORT_TESTING_start_cb - restart_cb, void *cb_cls) + GNUNET_TRANSPORT_TESTING_start_cb restart_cb, + void *cb_cls) { - GNUNET_assert (tth != NULL); - GNUNET_assert (p != NULL); GNUNET_assert (NULL != p->peer); LOG (GNUNET_ERROR_TYPE_DEBUG, @@ -377,13 +424,22 @@ GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_handle p->no, GNUNET_i2s (&p->id)); if (NULL != p->ghh) + { GNUNET_TRANSPORT_get_hello_cancel (p->ghh); - p->ghh = NULL; - + p->ghh = NULL; + } if (NULL != p->th) + { GNUNET_TRANSPORT_disconnect (p->th); + p->th = NULL; + } + if (NULL != p->ats) + { + GNUNET_ATS_connectivity_done (p->ats); + p->ats = NULL; + } - if (GNUNET_SYSERR == GNUNET_TESTING_peer_stop(p->peer)) + if (GNUNET_SYSERR == GNUNET_TESTING_peer_stop (p->peer)) { LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to stop peer %u (`%s')\n", @@ -395,33 +451,38 @@ GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_handle sleep (5); // YUCK! /* restart */ - if (GNUNET_SYSERR == GNUNET_TESTING_peer_start(p->peer)) + if (GNUNET_SYSERR == GNUNET_TESTING_peer_start (p->peer)) { LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to restart peer %u (`%s')\n", - p->no, GNUNET_i2s (&p->id)); + p->no, + GNUNET_i2s (&p->id)); return GNUNET_SYSERR; } - GNUNET_assert (p->th != NULL); - GNUNET_assert (p->start_cb == NULL); + GNUNET_assert (NULL == p->start_cb); p->start_cb = restart_cb; p->cb_cls = cb_cls; - p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, + p->th = GNUNET_TRANSPORT_connect (p->cfg, + NULL, + p, ¬ify_receive, ¬ify_connect, ¬ify_disconnect); GNUNET_assert (NULL != p->th); - - p->ghh = GNUNET_TRANSPORT_get_hello (p->th, &get_hello, p); - GNUNET_assert (p->ghh != NULL); + p->ats = GNUNET_ATS_connectivity_init (p->cfg); + p->ghh = GNUNET_TRANSPORT_get_hello (p->th, + &get_hello, + p); + GNUNET_assert (NULL != p->ghh); return GNUNET_OK; } /** - * shutdown the given peer + * Shutdown the given peer + * * @param tth testing handle * @param p the peer */ @@ -429,19 +490,17 @@ void GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth, struct PeerContext *p) { - GNUNET_assert (p != NULL); - if (p->ghh != NULL) + if (NULL != p->ghh) { GNUNET_TRANSPORT_get_hello_cancel (p->ghh); p->ghh = NULL; } - if (p->th != NULL) + if (NULL != p->th) { GNUNET_TRANSPORT_disconnect (p->th); p->th = NULL; } - - if (p->peer != NULL) + if (NULL != p->peer) { if (GNUNET_OK != GNUNET_TESTING_peer_stop (p->peer)) { @@ -452,20 +511,27 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth, GNUNET_TESTING_peer_destroy (p->peer); p->peer = NULL; } - - if (p->hello != NULL) + if (NULL != p->ats) + { + GNUNET_ATS_connectivity_done (p->ats); + p->ats = NULL; + } + if (NULL != p->hello) { GNUNET_free (p->hello); p->hello = NULL; } - if (p->cfg != NULL) + if (NULL != p->cfg) { GNUNET_CONFIGURATION_destroy (p->cfg); p->cfg = NULL; } - GNUNET_CONTAINER_DLL_remove (tth->p_head, tth->p_tail, p); + GNUNET_CONTAINER_DLL_remove (tth->p_head, + tth->p_tail, + p); LOG (GNUNET_ERROR_TYPE_DEBUG, - "Peer %u (`%s') stopped \n", p->no, + "Peer %u (`%s') stopped \n", + p->no, GNUNET_i2s (&p->id)); GNUNET_free (p); } @@ -490,26 +556,25 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle * GNUNET_TRANSPORT_TESTING_connect_cb cb, void *cls) { - struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequest); + struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; - GNUNET_assert (tth != NULL); - GNUNET_assert (p1 != NULL); - GNUNET_assert (p2 != NULL); + cc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequest); cc->p1 = p1; cc->p2 = p2; cc->cb = cb; - if (cls != NULL) + if (NULL != cls) cc->cb_cls = cls; else cc->cb_cls = cc; - cc->th_p1 = p1->th; - cc->th_p2 = p2->th; - GNUNET_assert (cc->th_p1 != NULL); - GNUNET_assert (cc->th_p2 != NULL); GNUNET_CONTAINER_DLL_insert (tth->cc_head, tth->cc_tail, cc); - cc->tct = GNUNET_SCHEDULER_add_now (&try_connect, cc); + cc->tct = GNUNET_SCHEDULER_add_now (&offer_hello, + cc); + cc->ats_sh = GNUNET_ATS_connectivity_suggest (cc->p1->ats, + &p2->id, + 1); + LOG (GNUNET_ERROR_TYPE_DEBUG, "New connect request %p\n", cc); @@ -529,17 +594,28 @@ void GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct GNUNET_TRANSPORT_TESTING_handle *tth, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc) { - GNUNET_assert (tth != NULL); - LOG (GNUNET_ERROR_TYPE_DEBUG, "Canceling connect request %p!\n", cc); - - if (cc->tct != NULL) + if (NULL != cc->tct) + { GNUNET_SCHEDULER_cancel (cc->tct); - cc->tct = NULL; + cc->tct = NULL; + } + if (NULL != cc->oh) + { + GNUNET_TRANSPORT_offer_hello_cancel (cc->oh); + cc->oh = NULL; + } + if (NULL != cc->ats_sh) + { + GNUNET_ATS_connectivity_suggest_cancel (cc->ats_sh); + cc->ats_sh = NULL; + } - GNUNET_CONTAINER_DLL_remove (tth->cc_head, tth->cc_tail, cc); + GNUNET_CONTAINER_DLL_remove (tth->cc_head, + tth->cc_tail, + cc); GNUNET_free (cc); } @@ -556,19 +632,18 @@ GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle *tth) struct PeerContext *p = tth->p_head; struct PeerContext *t = NULL; - GNUNET_assert (tth != NULL); - while (cc != tth->cc_tail) { ct = cc->next; LOG (GNUNET_ERROR_TYPE_ERROR, "Developer forgot to cancel connect request %p!\n", cc); - GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); + GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, + cc); cc = ct; } - while (p != NULL) + while (NULL != p) { t = p->next; LOG (GNUNET_ERROR_TYPE_ERROR, @@ -577,7 +652,8 @@ GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle *tth) p = t; } - GNUNET_TESTING_system_destroy (tth->tl_system, GNUNET_YES); + GNUNET_TESTING_system_destroy (tth->tl_system, + GNUNET_YES); GNUNET_free (tth); tth = NULL; @@ -619,6 +695,7 @@ GNUNET_TRANSPORT_TESTING_init () /** * Removes all directory separators from absolute filename + * * @param file the absolute file name, e.g. as found in argv[0] * @return extracted file name, has to be freed by caller */ @@ -670,7 +747,9 @@ extract_filename (const char *file) /** - * Extracts the test filename from an absolute file name and removes the extension + * Extracts the test filename from an absolute file name and removes + * the extension + * * @param file absolute file name * @param dest where to store result */ @@ -709,6 +788,7 @@ suc: /** * Extracts the filename from an absolute file name and removes the extension + * * @param file absolute file name * @param dest where to store result */ diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h index dcac29185..69da1f99d 100644 --- a/src/transport/transport-testing.h +++ b/src/transport/transport-testing.h @@ -92,6 +92,11 @@ struct PeerContext */ struct GNUNET_TRANSPORT_Handle *th; + /** + * Peer's ATS handle. + */ + struct GNUNET_ATS_ConnectivityHandle *ats; + /** * Peer's transport get hello handle to retrieve peer's HELLO message */ @@ -156,10 +161,10 @@ struct GNUNET_TRANSPORT_TESTING_ConnectRequest struct PeerContext *p1; struct PeerContext *p2; struct GNUNET_SCHEDULER_Task *tct; + struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh; + struct GNUNET_TRANSPORT_OfferHelloHandle *oh; GNUNET_TRANSPORT_TESTING_connect_cb cb; void *cb_cls; - struct GNUNET_TRANSPORT_Handle *th_p1; - struct GNUNET_TRANSPORT_Handle *th_p2; int p1_c; int p2_c; }; @@ -231,7 +236,6 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth, /** * Restart the given peer * - * @param tth testing handle * @param p the peer * @param cfgname the cfg file used to restart * @param restart_cb restart callback @@ -239,8 +243,7 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth, * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR */ int -GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth, - struct PeerContext *p, +GNUNET_TRANSPORT_TESTING_restart_peer (struct PeerContext *p, const char *cfgname, GNUNET_TRANSPORT_TESTING_start_cb restart_cb, void *cb_cls); -- cgit v1.2.3