aboutsummaryrefslogtreecommitdiff
path: root/src/pt
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-07-02 20:00:00 +0000
committerChristian Grothoff <christian@grothoff.org>2016-07-02 20:00:00 +0000
commitf5578375b94757504d58994e4af829250d1330e6 (patch)
tree085667fc2801383a6f5ceeb7e9260b2797c00aa5 /src/pt
parent80a401db776bf42db639cb501a3214b1a71c50e6 (diff)
downloadgnunet-f5578375b94757504d58994e4af829250d1330e6.tar.gz
gnunet-f5578375b94757504d58994e4af829250d1330e6.zip
-fix testcase shutdown
Diffstat (limited to 'src/pt')
-rw-r--r--src/pt/test_gns_vpn.c30
-rw-r--r--src/pt/test_gnunet_vpn.c61
2 files changed, 63 insertions, 28 deletions
diff --git a/src/pt/test_gns_vpn.c b/src/pt/test_gns_vpn.c
index 7e5bb503d..467a15310 100644
--- a/src/pt/test_gns_vpn.c
+++ b/src/pt/test_gns_vpn.c
@@ -54,6 +54,8 @@ static struct GNUNET_SCHEDULER_Task *mhd_task_id;
54 54
55static struct GNUNET_SCHEDULER_Task *curl_task_id; 55static struct GNUNET_SCHEDULER_Task *curl_task_id;
56 56
57static struct GNUNET_SCHEDULER_Task *timeout_task;
58
57static struct GNUNET_IDENTITY_Handle *identity; 59static struct GNUNET_IDENTITY_Handle *identity;
58 60
59static struct GNUNET_NAMESTORE_QueueEntry *qe; 61static struct GNUNET_NAMESTORE_QueueEntry *qe;
@@ -142,16 +144,21 @@ mhd_ahc (void *cls,
142static void 144static void
143do_shutdown (void *cls) 145do_shutdown (void *cls)
144{ 146{
145 if (mhd_task_id != NULL) 147 if (NULL != mhd_task_id)
146 { 148 {
147 GNUNET_SCHEDULER_cancel (mhd_task_id); 149 GNUNET_SCHEDULER_cancel (mhd_task_id);
148 mhd_task_id = NULL; 150 mhd_task_id = NULL;
149 } 151 }
150 if (curl_task_id != NULL) 152 if (NULL != curl_task_id)
151 { 153 {
152 GNUNET_SCHEDULER_cancel (curl_task_id); 154 GNUNET_SCHEDULER_cancel (curl_task_id);
153 curl_task_id = NULL; 155 curl_task_id = NULL;
154 } 156 }
157 if (NULL != timeout_task)
158 {
159 GNUNET_SCHEDULER_cancel (timeout_task);
160 timeout_task = NULL;
161 }
155 if (NULL != mhd) 162 if (NULL != mhd)
156 { 163 {
157 MHD_stop_daemon (mhd); 164 MHD_stop_daemon (mhd);
@@ -172,6 +179,14 @@ do_shutdown (void *cls)
172} 179}
173 180
174 181
182static void
183do_timeout (void *cls)
184{
185 timeout_task = NULL;
186 GNUNET_SCHEDULER_shutdown ();
187}
188
189
175/** 190/**
176 * Function to run the HTTP client. 191 * Function to run the HTTP client.
177 */ 192 */
@@ -236,7 +251,8 @@ curl_main ()
236 GNUNET_break (0); 251 GNUNET_break (0);
237 global_ret = 3; 252 global_ret = 3;
238 } 253 }
239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download complete, shutting down!\n"); 254 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
255 "Download complete, shutting down!\n");
240 GNUNET_SCHEDULER_shutdown (); 256 GNUNET_SCHEDULER_shutdown ();
241 return; 257 return;
242 } 258 }
@@ -622,9 +638,11 @@ run (void *cls,
622 NULL 638 NULL
623 }; 639 };
624 GNUNET_TESTING_peer_get_identity (peer, &id); 640 GNUNET_TESTING_peer_get_identity (peer, &id);
625 GNUNET_SCHEDULER_add_delayed (TIMEOUT, 641 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
626 &do_shutdown, 642 NULL);
627 NULL); 643 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
644 &do_timeout,
645 NULL);
628 bin = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR); 646 bin = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR);
629 GNUNET_asprintf (&bin_identity, 647 GNUNET_asprintf (&bin_identity,
630 "%s/%s", 648 "%s/%s",
diff --git a/src/pt/test_gnunet_vpn.c b/src/pt/test_gnunet_vpn.c
index 206eb0f47..2e9dea627 100644
--- a/src/pt/test_gnunet_vpn.c
+++ b/src/pt/test_gnunet_vpn.c
@@ -47,11 +47,11 @@ static struct GNUNET_VPN_Handle *vpn;
47 47
48static struct MHD_Daemon *mhd; 48static struct MHD_Daemon *mhd;
49 49
50static struct GNUNET_SCHEDULER_Task * mhd_task_id; 50static struct GNUNET_SCHEDULER_Task *mhd_task_id;
51 51
52static struct GNUNET_SCHEDULER_Task * curl_task_id; 52static struct GNUNET_SCHEDULER_Task *curl_task_id;
53 53
54static struct GNUNET_SCHEDULER_Task * ctrl_c_task_id; 54static struct GNUNET_SCHEDULER_Task *timeout_task_id;
55 55
56static struct GNUNET_VPN_RedirectionRequest *rr; 56static struct GNUNET_VPN_RedirectionRequest *rr;
57 57
@@ -100,9 +100,14 @@ copy_buffer (void *ptr, size_t size, size_t nmemb, void *ctx)
100 100
101 101
102static int 102static int
103mhd_ahc (void *cls, struct MHD_Connection *connection, const char *url, 103mhd_ahc (void *cls,
104 const char *method, const char *version, const char *upload_data, 104 struct MHD_Connection *connection,
105 size_t * upload_data_size, void **unused) 105 const char *url,
106 const char *method,
107 const char *version,
108 const char *upload_data,
109 size_t * upload_data_size,
110 void **unused)
106{ 111{
107 static int ptr; 112 static int ptr;
108 struct MHD_Response *response; 113 struct MHD_Response *response;
@@ -130,22 +135,22 @@ mhd_ahc (void *cls, struct MHD_Connection *connection, const char *url,
130 135
131 136
132static void 137static void
133do_shutdown () 138do_shutdown (void *cls)
134{ 139{
135 if (mhd_task_id != NULL) 140 if (NULL != mhd_task_id)
136 { 141 {
137 GNUNET_SCHEDULER_cancel (mhd_task_id); 142 GNUNET_SCHEDULER_cancel (mhd_task_id);
138 mhd_task_id = NULL; 143 mhd_task_id = NULL;
139 } 144 }
140 if (curl_task_id != NULL) 145 if (NULL != curl_task_id)
141 { 146 {
142 GNUNET_SCHEDULER_cancel (curl_task_id); 147 GNUNET_SCHEDULER_cancel (curl_task_id);
143 curl_task_id = NULL; 148 curl_task_id = NULL;
144 } 149 }
145 if (ctrl_c_task_id != NULL) 150 if (NULL != timeout_task_id)
146 { 151 {
147 GNUNET_SCHEDULER_cancel (ctrl_c_task_id); 152 GNUNET_SCHEDULER_cancel (timeout_task_id);
148 ctrl_c_task_id = NULL; 153 timeout_task_id = NULL;
149 } 154 }
150 if (NULL != mhd) 155 if (NULL != mhd)
151 { 156 {
@@ -220,7 +225,7 @@ curl_main (void *cls)
220 global_ret = 3; 225 global_ret = 3;
221 } 226 }
222 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download complete, shutting down!\n"); 227 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download complete, shutting down!\n");
223 do_shutdown (); 228 GNUNET_SCHEDULER_shutdown ();
224 return; 229 return;
225 } 230 }
226 GNUNET_assert (CURLM_OK == curl_multi_fdset (multi, &rs, &ws, &es, &max)); 231 GNUNET_assert (CURLM_OK == curl_multi_fdset (multi, &rs, &ws, &es, &max));
@@ -259,19 +264,26 @@ allocation_cb (void *cls, int af, const void *address)
259 rr = NULL; 264 rr = NULL;
260 if (src_af != af) 265 if (src_af != af)
261 { 266 {
262 fprintf (stderr, "VPN failed to allocate appropriate address\n"); 267 fprintf (stderr,
268 "VPN failed to allocate appropriate address\n");
263 GNUNET_SCHEDULER_shutdown (); 269 GNUNET_SCHEDULER_shutdown ();
264 return; 270 return;
265 } 271 }
266 if (AF_INET6 == af) 272 if (AF_INET6 == af)
267 GNUNET_asprintf (&url, 273 GNUNET_asprintf (&url,
268 "http://[%s]:%u/hello_world", 274 "http://[%s]:%u/hello_world",
269 inet_ntop (af, address, ips, sizeof (ips)), 275 inet_ntop (af,
276 address,
277 ips,
278 sizeof (ips)),
270 (unsigned int) PORT); 279 (unsigned int) PORT);
271 else 280 else
272 GNUNET_asprintf (&url, 281 GNUNET_asprintf (&url,
273 "http://%s:%u/hello_world", 282 "http://%s:%u/hello_world",
274 inet_ntop (af, address, ips, sizeof (ips)), 283 inet_ntop (af,
284 address,
285 ips,
286 sizeof (ips)),
275 (unsigned int) PORT); 287 (unsigned int) PORT);
276 curl = curl_easy_init (); 288 curl = curl_easy_init ();
277 curl_easy_setopt (curl, CURLOPT_URL, url); 289 curl_easy_setopt (curl, CURLOPT_URL, url);
@@ -312,10 +324,10 @@ mhd_task (void *cls)
312 324
313 325
314static void 326static void
315ctrl_c_shutdown (void *cls) 327do_timeout (void *cls)
316{ 328{
317 ctrl_c_task_id = NULL; 329 timeout_task_id = NULL;
318 do_shutdown (); 330 GNUNET_SCHEDULER_shutdown ();
319 GNUNET_break (0); 331 GNUNET_break (0);
320 global_ret = 1; 332 global_ret = 1;
321} 333}
@@ -392,8 +404,12 @@ run (void *cls,
392 rr = GNUNET_VPN_redirect_to_ip (vpn, src_af, dest_af, addr, 404 rr = GNUNET_VPN_redirect_to_ip (vpn, src_af, dest_af, addr,
393 GNUNET_TIME_UNIT_FOREVER_ABS, &allocation_cb, 405 GNUNET_TIME_UNIT_FOREVER_ABS, &allocation_cb,
394 NULL); 406 NULL);
395 ctrl_c_task_id = 407 timeout_task_id =
396 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &ctrl_c_shutdown, NULL); 408 GNUNET_SCHEDULER_add_delayed (TIMEOUT,
409 &do_timeout,
410 NULL);
411 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
412 NULL);
397} 413}
398 414
399 415
@@ -409,7 +425,8 @@ main (int argc, char *const *argv)
409#ifndef MINGW 425#ifndef MINGW
410 if (0 != ACCESS ("/dev/net/tun", R_OK)) 426 if (0 != ACCESS ("/dev/net/tun", R_OK))
411 { 427 {
412 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "access", 428 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
429 "access",
413 "/dev/net/tun"); 430 "/dev/net/tun");
414 fprintf (stderr, 431 fprintf (stderr,
415 "WARNING: System unable to run test, skipping.\n"); 432 "WARNING: System unable to run test, skipping.\n");