aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_transport_testing_restart.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/test_transport_testing_restart.c')
-rw-r--r--src/transport/test_transport_testing_restart.c133
1 files changed, 66 insertions, 67 deletions
diff --git a/src/transport/test_transport_testing_restart.c b/src/transport/test_transport_testing_restart.c
index 4df8b2d6d..d47696018 100644
--- a/src/transport/test_transport_testing_restart.c
+++ b/src/transport/test_transport_testing_restart.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_restart.c 21 * @file transport/test_transport_testing_restart.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,124 +39,123 @@ 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
67restart_cb (void *cls) 67restart_cb(void *cls)
68{ 68{
69 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 69 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
70 "Peer %u (`%s') successfully restarted\n", 70 "Peer %u (`%s') successfully restarted\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
80restart_task () 80restart_task()
81{ 81{
82 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 82 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
83 "Peer %u (`%s') restarting\n", 83 "Peer %u (`%s') restarting\n",
84 p->no, 84 p->no,
85 GNUNET_i2s (&p->id)); 85 GNUNET_i2s(&p->id));
86 GNUNET_TRANSPORT_TESTING_restart_peer (p, 86 GNUNET_TRANSPORT_TESTING_restart_peer(p,
87 &restart_cb, 87 &restart_cb,
88 p); 88 p);
89} 89}
90 90
91 91
92static void 92static void
93start_cb (void *cls) 93start_cb(void *cls)
94{ 94{
95 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 95 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
96 "Peer %u (`%s') successfully started\n", 96 "Peer %u (`%s') successfully started\n",
97 p->no, 97 p->no,
98 GNUNET_i2s (&p->id)); 98 GNUNET_i2s(&p->id));
99 GNUNET_SCHEDULER_add_now (&restart_task, 99 GNUNET_SCHEDULER_add_now(&restart_task,
100 NULL); 100 NULL);
101} 101}
102 102
103 103
104static void 104static void
105run (void *cls, 105run(void *cls,
106 char *const *args, 106 char *const *args,
107 const char *cfgfile, 107 const char *cfgfile,
108 const struct GNUNET_CONFIGURATION_Handle *cfg) 108 const struct GNUNET_CONFIGURATION_Handle *cfg)
109{ 109{
110 ret = 1; 110 ret = 1;
111 tth = GNUNET_TRANSPORT_TESTING_init (); 111 tth = GNUNET_TRANSPORT_TESTING_init();
112 GNUNET_assert (NULL != tth); 112 GNUNET_assert(NULL != tth);
113 113
114 timeout_task 114 timeout_task
115 = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 115 = GNUNET_SCHEDULER_add_delayed(TIMEOUT,
116 &end_badly, 116 &end_badly,
117 NULL); 117 NULL);
118 p = GNUNET_TRANSPORT_TESTING_start_peer(tth, 118 p = GNUNET_TRANSPORT_TESTING_start_peer(tth,
119 cfgfile, 119 cfgfile,
120 1, 120 1,
121 NULL, /* receive cb */ 121 NULL, /* receive cb */
122 NULL, /* connect cb */ 122 NULL, /* connect cb */
123 NULL, /* disconnect cb */ 123 NULL, /* disconnect cb */
124 NULL, /* nc/nd closure */ 124 NULL, /* nc/nd closure */
125 start_cb, /* startup cb */ 125 start_cb, /* startup cb */
126 NULL); /* closure */ 126 NULL); /* closure */
127 if (NULL == p) 127 if (NULL == p)
128 { 128 {
129 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 129 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
130 "Failed to start peer\n"); 130 "Failed to start peer\n");
131 end (); 131 end();
132 ret = 1; 132 ret = 1;
133 } 133 }
134} 134}
135 135
136 136
137int 137int
138main (int argc, 138main(int argc,
139 char *argv[]) 139 char *argv[])
140{ 140{
141 char *const argv_1[] = { "test_transport_testing_restart", 141 char *const argv_1[] = { "test_transport_testing_restart",
142 "-c", 142 "-c",
143 "test_transport_api_data.conf", 143 "test_transport_api_data.conf",
144 NULL 144 NULL };
145 };
146 struct GNUNET_GETOPT_CommandLineOption options[] = { 145 struct GNUNET_GETOPT_CommandLineOption options[] = {
147 GNUNET_GETOPT_OPTION_END 146 GNUNET_GETOPT_OPTION_END
148 }; 147 };
149 148
150 GNUNET_log_setup ("test_transport_testing_restart", 149 GNUNET_log_setup("test_transport_testing_restart",
151 "WARNING", 150 "WARNING",
152 NULL); 151 NULL);
153 GNUNET_PROGRAM_run ((sizeof (argv_1) / sizeof (char *)) - 1, 152 GNUNET_PROGRAM_run((sizeof(argv_1) / sizeof(char *)) - 1,
154 argv_1, 153 argv_1,
155 "test_transport_testing_restart", 154 "test_transport_testing_restart",
156 "nohelp", 155 "nohelp",
157 options, 156 options,
158 &run, 157 &run,
159 NULL); 158 NULL);
160 return ret; 159 return ret;
161} 160}
162 161