aboutsummaryrefslogtreecommitdiff
path: root/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/hostlist/test_gnunet_daemon_hostlist_reconnect.c')
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist_reconnect.c260
1 files changed, 130 insertions, 130 deletions
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
index 6aaa7ae2e..783da1d20 100644
--- a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
+++ b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
@@ -16,7 +16,7 @@
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 hostlist/test_gnunet_daemon_hostlist_reconnect.c 21 * @file hostlist/test_gnunet_daemon_hostlist_reconnect.c
22 * @brief test for gnunet-daemon-hostslist.c; tries to re-start the peers 22 * @brief test for gnunet-daemon-hostslist.c; tries to re-start the peers
@@ -32,14 +32,13 @@
32/** 32/**
33 * How long until we give up on transmitting the message? 33 * How long until we give up on transmitting the message?
34 */ 34 */
35#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 150) 35#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 150)
36 36
37static int ok; 37static int ok;
38 38
39static struct GNUNET_SCHEDULER_Task *timeout_task; 39static struct GNUNET_SCHEDULER_Task *timeout_task;
40 40
41struct PeerContext 41struct PeerContext {
42{
43 struct GNUNET_CONFIGURATION_Handle *cfg; 42 struct GNUNET_CONFIGURATION_Handle *cfg;
44 struct GNUNET_TRANSPORT_CoreHandle *th; 43 struct GNUNET_TRANSPORT_CoreHandle *th;
45 struct GNUNET_MessageHeader *hello; 44 struct GNUNET_MessageHeader *hello;
@@ -56,12 +55,12 @@ static struct PeerContext p2;
56 * Timeout, give up. 55 * Timeout, give up.
57 */ 56 */
58static void 57static void
59timeout_error (void *cls) 58timeout_error(void *cls)
60{ 59{
61 timeout_task = NULL; 60 timeout_task = NULL;
62 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 61 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
63 "Timeout trying to connect peers, test failed.\n"); 62 "Timeout trying to connect peers, test failed.\n");
64 GNUNET_SCHEDULER_shutdown (); 63 GNUNET_SCHEDULER_shutdown();
65} 64}
66 65
67 66
@@ -75,87 +74,87 @@ timeout_error (void *cls)
75 * @return NULL 74 * @return NULL
76 */ 75 */
77static void * 76static void *
78notify_connect (void *cls, 77notify_connect(void *cls,
79 const struct GNUNET_PeerIdentity *peer, 78 const struct GNUNET_PeerIdentity *peer,
80 struct GNUNET_MQ_Handle *mq) 79 struct GNUNET_MQ_Handle *mq)
81{ 80{
82 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n"); 81 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n");
83 ok = 0; 82 ok = 0;
84 GNUNET_SCHEDULER_shutdown (); 83 GNUNET_SCHEDULER_shutdown();
85 return NULL; 84 return NULL;
86} 85}
87 86
88 87
89static void 88static void
90process_hello (void *cls, const struct GNUNET_MessageHeader *message) 89process_hello(void *cls, const struct GNUNET_MessageHeader *message)
91{ 90{
92 struct PeerContext *p = cls; 91 struct PeerContext *p = cls;
93 92
94 GNUNET_TRANSPORT_hello_get_cancel (p->ghh); 93 GNUNET_TRANSPORT_hello_get_cancel(p->ghh);
95 p->ghh = NULL; 94 p->ghh = NULL;
96 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 95 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
97 "Received HELLO, starting hostlist service.\n"); 96 "Received HELLO, starting hostlist service.\n");
98} 97}
99 98
100 99
101static void 100static void
102setup_peer (struct PeerContext *p, const char *cfgname) 101setup_peer(struct PeerContext *p, const char *cfgname)
103{ 102{
104 char *binary; 103 char *binary;
105 104
106 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); 105 binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-arm");
107 p->cfg = GNUNET_CONFIGURATION_create (); 106 p->cfg = GNUNET_CONFIGURATION_create();
108 p->arm_proc = GNUNET_OS_start_process (GNUNET_YES, 107 p->arm_proc = GNUNET_OS_start_process(GNUNET_YES,
109 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 108 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
110 NULL, 109 NULL,
111 NULL, 110 NULL,
112 NULL, 111 NULL,
113 binary, 112 binary,
114 "gnunet-service-arm", 113 "gnunet-service-arm",
115 "-c", 114 "-c",
116 cfgname, 115 cfgname,
117 NULL); 116 NULL);
118 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 117 GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_load(p->cfg, cfgname));
119 p->th = GNUNET_TRANSPORT_core_connect (p->cfg, 118 p->th = GNUNET_TRANSPORT_core_connect(p->cfg,
120 NULL, 119 NULL,
121 NULL, 120 NULL,
122 p, 121 p,
123 &notify_connect, 122 &notify_connect,
124 NULL, 123 NULL,
125 NULL); 124 NULL);
126 GNUNET_assert (NULL != p->th); 125 GNUNET_assert(NULL != p->th);
127 p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg, 126 p->ghh = GNUNET_TRANSPORT_hello_get(p->cfg,
128 GNUNET_TRANSPORT_AC_ANY, 127 GNUNET_TRANSPORT_AC_ANY,
129 &process_hello, 128 &process_hello,
130 p); 129 p);
131 GNUNET_free (binary); 130 GNUNET_free(binary);
132} 131}
133 132
134 133
135static void 134static void
136waitpid_task (void *cls) 135waitpid_task(void *cls)
137{ 136{
138 struct PeerContext *p = cls; 137 struct PeerContext *p = cls;
139 138
140 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Killing ARM process.\n"); 139 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Killing ARM process.\n");
141 if (0 != GNUNET_OS_process_kill (p->arm_proc, GNUNET_TERM_SIG)) 140 if (0 != GNUNET_OS_process_kill(p->arm_proc, GNUNET_TERM_SIG))
142 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 141 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill");
143 if (GNUNET_OK != GNUNET_OS_process_wait (p->arm_proc)) 142 if (GNUNET_OK != GNUNET_OS_process_wait(p->arm_proc))
144 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 143 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "waitpid");
145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 144 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
146 "ARM process %u stopped\n", 145 "ARM process %u stopped\n",
147 GNUNET_OS_process_get_pid (p->arm_proc)); 146 GNUNET_OS_process_get_pid(p->arm_proc));
148 GNUNET_OS_process_destroy (p->arm_proc); 147 GNUNET_OS_process_destroy(p->arm_proc);
149 p->arm_proc = NULL; 148 p->arm_proc = NULL;
150 GNUNET_CONFIGURATION_destroy (p->cfg); 149 GNUNET_CONFIGURATION_destroy(p->cfg);
151} 150}
152 151
153 152
154static void 153static void
155stop_arm (struct PeerContext *p) 154stop_arm(struct PeerContext *p)
156{ 155{
157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n"); 156 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n");
158 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p); 157 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p);
159} 158}
160 159
161 160
@@ -163,98 +162,99 @@ stop_arm (struct PeerContext *p)
163 * Try again to connect to transport service. 162 * Try again to connect to transport service.
164 */ 163 */
165static void 164static void
166shutdown_task (void *cls) 165shutdown_task(void *cls)
167{ 166{
168 if (NULL != timeout_task) 167 if (NULL != timeout_task)
169 { 168 {
170 GNUNET_SCHEDULER_cancel (timeout_task); 169 GNUNET_SCHEDULER_cancel(timeout_task);
171 timeout_task = NULL; 170 timeout_task = NULL;
172 } 171 }
173 if (NULL != p1.ghh) 172 if (NULL != p1.ghh)
174 { 173 {
175 GNUNET_TRANSPORT_hello_get_cancel (p1.ghh); 174 GNUNET_TRANSPORT_hello_get_cancel(p1.ghh);
176 p1.ghh = NULL; 175 p1.ghh = NULL;
177 } 176 }
178 if (NULL != p1.th) 177 if (NULL != p1.th)
179 { 178 {
180 GNUNET_TRANSPORT_core_disconnect (p1.th); 179 GNUNET_TRANSPORT_core_disconnect(p1.th);
181 p1.th = NULL; 180 p1.th = NULL;
182 } 181 }
183 if (NULL != p2.ghh) 182 if (NULL != p2.ghh)
184 { 183 {
185 GNUNET_TRANSPORT_hello_get_cancel (p2.ghh); 184 GNUNET_TRANSPORT_hello_get_cancel(p2.ghh);
186 p2.ghh = NULL; 185 p2.ghh = NULL;
187 } 186 }
188 if (NULL != p2.th) 187 if (NULL != p2.th)
189 { 188 {
190 GNUNET_TRANSPORT_core_disconnect (p2.th); 189 GNUNET_TRANSPORT_core_disconnect(p2.th);
191 p2.th = NULL; 190 p2.th = NULL;
192 } 191 }
193 stop_arm (&p1); 192 stop_arm(&p1);
194 stop_arm (&p2); 193 stop_arm(&p2);
195} 194}
196 195
197 196
198static void 197static void
199run (void *cls, 198run(void *cls,
200 char *const *args, 199 char *const *args,
201 const char *cfgfile, 200 const char *cfgfile,
202 const struct GNUNET_CONFIGURATION_Handle *cfg) 201 const struct GNUNET_CONFIGURATION_Handle *cfg)
203{ 202{
204 GNUNET_assert (ok == 1); 203 GNUNET_assert(ok == 1);
205 ok++; 204 ok++;
206 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL); 205 timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &timeout_error, NULL);
207 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); 206 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL);
208 setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf"); 207 setup_peer(&p1, "test_gnunet_daemon_hostlist_peer1.conf");
209 setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf"); 208 setup_peer(&p2, "test_gnunet_daemon_hostlist_peer2.conf");
210} 209}
211 210
212 211
213int 212int
214main (int argcx, char *argvx[]) 213main(int argcx, char *argvx[])
215{ 214{
216 static char *const argv[] = {"test-gnunet-daemon-hostlist", 215 static char *const argv[] = { "test-gnunet-daemon-hostlist",
217 "-c", 216 "-c",
218 "test_gnunet_daemon_hostlist_data.conf", 217 "test_gnunet_daemon_hostlist_data.conf",
219 NULL}; 218 NULL };
220 static struct GNUNET_GETOPT_CommandLineOption options[] = { 219 static struct GNUNET_GETOPT_CommandLineOption options[] = {
221 GNUNET_GETOPT_OPTION_END}; 220 GNUNET_GETOPT_OPTION_END
222 221 };
223 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf", 222
224 "GNUNET_TEST_HOME"); 223 GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer1.conf",
225 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer2.conf", 224 "GNUNET_TEST_HOME");
226 "GNUNET_TEST_HOME"); 225 GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer2.conf",
227 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf", 226 "GNUNET_TEST_HOME");
228 "GNUNET_TEST_HOME"); 227 GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_data.conf",
229 GNUNET_log_setup ("test-gnunet-daemon-hostlist", "WARNING", NULL); 228 "GNUNET_TEST_HOME");
229 GNUNET_log_setup("test-gnunet-daemon-hostlist", "WARNING", NULL);
230 ok = 1; 230 ok = 1;
231 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 231 GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1,
232 argv, 232 argv,
233 "test-gnunet-daemon-hostlist", 233 "test-gnunet-daemon-hostlist",
234 "nohelp", 234 "nohelp",
235 options, 235 options,
236 &run, 236 &run,
237 &ok); 237 &ok);
238 if (0 == ok) 238 if (0 == ok)
239 { 239 {
240 fprintf (stderr, "%s", "."); 240 fprintf(stderr, "%s", ".");
241 /* now do it again */ 241 /* now do it again */
242 ok = 1; 242 ok = 1;
243 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 243 GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1,
244 argv, 244 argv,
245 "test-gnunet-daemon-hostlist", 245 "test-gnunet-daemon-hostlist",
246 "nohelp", 246 "nohelp",
247 options, 247 options,
248 &run, 248 &run,
249 &ok); 249 &ok);
250 fprintf (stderr, "%s", ".\n"); 250 fprintf(stderr, "%s", ".\n");
251 } 251 }
252 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf", 252 GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer1.conf",
253 "GNUNET_TEST_HOME"); 253 "GNUNET_TEST_HOME");
254 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer2.conf", 254 GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer2.conf",
255 "GNUNET_TEST_HOME"); 255 "GNUNET_TEST_HOME");
256 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf", 256 GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_data.conf",
257 "GNUNET_TEST_HOME"); 257 "GNUNET_TEST_HOME");
258 return ok; 258 return ok;
259} 259}
260 260