summaryrefslogtreecommitdiff
path: root/src/transport/test_transport_testing_startstop.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/test_transport_testing_startstop.c')
-rw-r--r--src/transport/test_transport_testing_startstop.c117
1 files changed, 58 insertions, 59 deletions
diff --git a/src/transport/test_transport_testing_startstop.c b/src/transport/test_transport_testing_startstop.c
index 57b6840a5..c57b24054 100644
--- a/src/transport/test_transport_testing_startstop.c
+++ b/src/transport/test_transport_testing_startstop.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file transport/test_transport_testing_startstop.c 21 * @file transport/test_transport_testing_startstop.c
22 * @brief test case for transport testing library: 22 * @brief test case for transport testing library:
@@ -26,7 +26,7 @@
26#include "gnunet_transport_service.h" 26#include "gnunet_transport_service.h"
27#include "transport-testing.h" 27#include "transport-testing.h"
28 28
29#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 29#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30)
30 30
31 31
32static struct GNUNET_SCHEDULER_Task *timeout_task; 32static struct GNUNET_SCHEDULER_Task *timeout_task;
@@ -39,98 +39,97 @@ static int ret;
39 39
40 40
41static void 41static void
42end () 42end()
43{ 43{
44 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 44 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
45 "Stopping peers\n"); 45 "Stopping peers\n");
46 if (NULL != timeout_task) 46 if (NULL != timeout_task)
47 GNUNET_SCHEDULER_cancel (timeout_task); 47 GNUNET_SCHEDULER_cancel(timeout_task);
48 if (NULL != p) 48 if (NULL != p)
49 GNUNET_TRANSPORT_TESTING_stop_peer (p); 49 GNUNET_TRANSPORT_TESTING_stop_peer(p);
50 if (NULL != tth) 50 if (NULL != tth)
51 GNUNET_TRANSPORT_TESTING_done (tth); 51 GNUNET_TRANSPORT_TESTING_done(tth);
52} 52}
53 53
54 54
55static void 55static void
56end_badly () 56end_badly()
57{ 57{
58 timeout_task = NULL; 58 timeout_task = NULL;
59 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 59 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
60 "Timeout!\n"); 60 "Timeout!\n");
61 end (); 61 end();
62 ret = GNUNET_SYSERR; 62 ret = GNUNET_SYSERR;
63} 63}
64 64
65 65
66static void 66static void
67start_cb (void *cls) 67start_cb(void *cls)
68{ 68{
69 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 69 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
70 "Peer %u (`%s') successfully started\n", 70 "Peer %u (`%s') successfully started\n",
71 p->no, 71 p->no,
72 GNUNET_i2s (&p->id)); 72 GNUNET_i2s(&p->id));
73 ret = 0; 73 ret = 0;
74 GNUNET_SCHEDULER_add_now (&end, 74 GNUNET_SCHEDULER_add_now(&end,
75 NULL); 75 NULL);
76} 76}
77 77
78 78
79static void 79static void
80run (void *cls, 80run(void *cls,
81 char *const *args, 81 char *const *args,
82 const char *cfgfile, 82 const char *cfgfile,
83 const struct GNUNET_CONFIGURATION_Handle *cfg) 83 const struct GNUNET_CONFIGURATION_Handle *cfg)
84{ 84{
85 ret = 1; 85 ret = 1;
86 tth = GNUNET_TRANSPORT_TESTING_init (); 86 tth = GNUNET_TRANSPORT_TESTING_init();
87 GNUNET_assert (NULL != tth); 87 GNUNET_assert(NULL != tth);
88 88
89 timeout_task = 89 timeout_task =
90 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 90 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES,
91 &end_badly, 91 &end_badly,
92 NULL); 92 NULL);
93 93
94 p = GNUNET_TRANSPORT_TESTING_start_peer (tth, 94 p = GNUNET_TRANSPORT_TESTING_start_peer(tth,
95 cfgfile, 95 cfgfile,
96 1, 96 1,
97 NULL, /* receive cb */ 97 NULL, /* receive cb */
98 NULL, /* connect cb */ 98 NULL, /* connect cb */
99 NULL, /* disconnect cb */ 99 NULL, /* disconnect cb */
100 NULL, /* nc/nd closure */ 100 NULL, /* nc/nd closure */
101 &start_cb, /* startup cb */ 101 &start_cb, /* startup cb */
102 NULL); /* closure */ 102 NULL); /* closure */
103 if (NULL == p) 103 if (NULL == p)
104 { 104 {
105 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start peer\n"); 105 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Failed to start peer\n");
106 if (timeout_task != NULL) 106 if (timeout_task != NULL)
107 GNUNET_SCHEDULER_cancel (timeout_task); 107 GNUNET_SCHEDULER_cancel(timeout_task);
108 timeout_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); 108 timeout_task = GNUNET_SCHEDULER_add_now(&end_badly, NULL);
109 } 109 }
110} 110}
111 111
112 112
113int 113int
114main (int argc, char *argv[]) 114main(int argc, char *argv[])
115{ 115{
116 char *const argv_1[] = { "test_transport_testing", 116 char *const argv_1[] = { "test_transport_testing",
117 "-c", 117 "-c",
118 "test_transport_api_data.conf", 118 "test_transport_api_data.conf",
119 NULL 119 NULL };
120 };
121 struct GNUNET_GETOPT_CommandLineOption options[] = { 120 struct GNUNET_GETOPT_CommandLineOption options[] = {
122 GNUNET_GETOPT_OPTION_END 121 GNUNET_GETOPT_OPTION_END
123 }; 122 };
124 123
125 GNUNET_log_setup ("test_transport_testing_startstop", 124 GNUNET_log_setup("test_transport_testing_startstop",
126 "WARNING", 125 "WARNING",
127 NULL); 126 NULL);
128 GNUNET_PROGRAM_run ((sizeof (argv_1) / sizeof (char *)) - 1, 127 GNUNET_PROGRAM_run((sizeof(argv_1) / sizeof(char *)) - 1,
129 argv_1, 128 argv_1,
130 "test_transport_testing_startstop", "nohelp", 129 "test_transport_testing_startstop", "nohelp",
131 options, 130 options,
132 &run, 131 &run,
133 &ret); 132 &ret);
134 133
135 return ret; 134 return ret;
136} 135}