diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-06-04 11:07:47 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-06-04 11:07:47 +0000 |
commit | abeea06e65fcfb549605bdc3c7bcb24cb5b0756e (patch) | |
tree | 79a9a65f81ce373198612d48b853eb59d725f106 /src/pt | |
parent | a960f943c1d0bc9b5f5986c1d29835b63bf3e2ef (diff) | |
download | gnunet-abeea06e65fcfb549605bdc3c7bcb24cb5b0756e.tar.gz gnunet-abeea06e65fcfb549605bdc3c7bcb24cb5b0756e.zip |
-fix
Diffstat (limited to 'src/pt')
-rw-r--r-- | src/pt/test_gns_vpn.c | 1 | ||||
-rw-r--r-- | src/pt/test_gnunet_vpn.c | 983 |
2 files changed, 491 insertions, 493 deletions
diff --git a/src/pt/test_gns_vpn.c b/src/pt/test_gns_vpn.c index 7eed31ceb..c61960237 100644 --- a/src/pt/test_gns_vpn.c +++ b/src/pt/test_gns_vpn.c | |||
@@ -561,7 +561,6 @@ main (int argc, char *const *argv) | |||
561 | GNUNET_free (bin_vpn); | 561 | GNUNET_free (bin_vpn); |
562 | GNUNET_free (bin_exit); | 562 | GNUNET_free (bin_exit); |
563 | GNUNET_free (bin_dns); | 563 | GNUNET_free (bin_dns); |
564 | GNUNET_CRYPTO_ecc_setup_hostkey ("test_gns_vpn.conf"); | ||
565 | 564 | ||
566 | dest_ip = "169.254.86.1"; | 565 | dest_ip = "169.254.86.1"; |
567 | dest_af = AF_INET; | 566 | dest_af = AF_INET; |
diff --git a/src/pt/test_gnunet_vpn.c b/src/pt/test_gnunet_vpn.c index 3a675654d..1de098ec8 100644 --- a/src/pt/test_gnunet_vpn.c +++ b/src/pt/test_gnunet_vpn.c | |||
@@ -1,492 +1,491 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | (C) 2007, 2009, 2011, 2012 Christian Grothoff | 3 | (C) 2007, 2009, 2011, 2012 Christian Grothoff |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
7 | by the Free Software Foundation; either version 2, or (at your | 7 | by the Free Software Foundation; either version 2, or (at your |
8 | option) any later version. | 8 | option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
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 | General Public License for more details. | 13 | General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with GNUnet; see the file COPYING. If not, write to the |
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file test_gnunet_vpn.c | 22 | * @file test_gnunet_vpn.c |
23 | * @brief testcase for tunneling HTTP over the GNUnet VPN | 23 | * @brief testcase for tunneling HTTP over the GNUnet VPN |
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include <curl/curl.h> | 27 | #include <curl/curl.h> |
28 | #include <microhttpd.h> | 28 | #include <microhttpd.h> |
29 | #include "gnunet_vpn_service.h" | 29 | #include "gnunet_vpn_service.h" |
30 | #include "gnunet_testing_lib.h" | 30 | #include "gnunet_testing_lib.h" |
31 | 31 | ||
32 | #define PORT 48080 | 32 | #define PORT 48080 |
33 | 33 | ||
34 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) | 34 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) |
35 | 35 | ||
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Return value for 'main'. | 38 | * Return value for 'main'. |
39 | */ | 39 | */ |
40 | static int global_ret; | 40 | static int global_ret; |
41 | 41 | ||
42 | static struct GNUNET_VPN_Handle *vpn; | 42 | static struct GNUNET_VPN_Handle *vpn; |
43 | 43 | ||
44 | static struct MHD_Daemon *mhd; | 44 | static struct MHD_Daemon *mhd; |
45 | 45 | ||
46 | static GNUNET_SCHEDULER_TaskIdentifier mhd_task_id; | 46 | static GNUNET_SCHEDULER_TaskIdentifier mhd_task_id; |
47 | 47 | ||
48 | static GNUNET_SCHEDULER_TaskIdentifier curl_task_id; | 48 | static GNUNET_SCHEDULER_TaskIdentifier curl_task_id; |
49 | 49 | ||
50 | static GNUNET_SCHEDULER_TaskIdentifier ctrl_c_task_id; | 50 | static GNUNET_SCHEDULER_TaskIdentifier ctrl_c_task_id; |
51 | 51 | ||
52 | static struct GNUNET_VPN_RedirectionRequest *rr; | 52 | static struct GNUNET_VPN_RedirectionRequest *rr; |
53 | 53 | ||
54 | static CURL *curl; | 54 | static CURL *curl; |
55 | 55 | ||
56 | static CURLM *multi; | 56 | static CURLM *multi; |
57 | 57 | ||
58 | static char *url; | 58 | static char *url; |
59 | 59 | ||
60 | /** | 60 | /** |
61 | * IP address of the ultimate destination. | 61 | * IP address of the ultimate destination. |
62 | */ | 62 | */ |
63 | static const char *dest_ip; | 63 | static const char *dest_ip; |
64 | 64 | ||
65 | /** | 65 | /** |
66 | * Address family of the dest_ip. | 66 | * Address family of the dest_ip. |
67 | */ | 67 | */ |
68 | static int dest_af; | 68 | static int dest_af; |
69 | 69 | ||
70 | /** | 70 | /** |
71 | * Address family to use by the curl client. | 71 | * Address family to use by the curl client. |
72 | */ | 72 | */ |
73 | static int src_af; | 73 | static int src_af; |
74 | 74 | ||
75 | 75 | ||
76 | struct CBC | 76 | struct CBC |
77 | { | 77 | { |
78 | char buf[1024]; | 78 | char buf[1024]; |
79 | size_t pos; | 79 | size_t pos; |
80 | }; | 80 | }; |
81 | 81 | ||
82 | static struct CBC cbc; | 82 | static struct CBC cbc; |
83 | 83 | ||
84 | 84 | ||
85 | static size_t | 85 | static size_t |
86 | copy_buffer (void *ptr, size_t size, size_t nmemb, void *ctx) | 86 | copy_buffer (void *ptr, size_t size, size_t nmemb, void *ctx) |
87 | { | 87 | { |
88 | struct CBC *cbc = ctx; | 88 | struct CBC *cbc = ctx; |
89 | 89 | ||
90 | if (cbc->pos + size * nmemb > sizeof (cbc->buf)) | 90 | if (cbc->pos + size * nmemb > sizeof (cbc->buf)) |
91 | return 0; /* overflow */ | 91 | return 0; /* overflow */ |
92 | memcpy (&cbc->buf[cbc->pos], ptr, size * nmemb); | 92 | memcpy (&cbc->buf[cbc->pos], ptr, size * nmemb); |
93 | cbc->pos += size * nmemb; | 93 | cbc->pos += size * nmemb; |
94 | return size * nmemb; | 94 | return size * nmemb; |
95 | } | 95 | } |
96 | 96 | ||
97 | 97 | ||
98 | static int | 98 | static int |
99 | mhd_ahc (void *cls, struct MHD_Connection *connection, const char *url, | 99 | mhd_ahc (void *cls, struct MHD_Connection *connection, const char *url, |
100 | const char *method, const char *version, const char *upload_data, | 100 | const char *method, const char *version, const char *upload_data, |
101 | size_t * upload_data_size, void **unused) | 101 | size_t * upload_data_size, void **unused) |
102 | { | 102 | { |
103 | static int ptr; | 103 | static int ptr; |
104 | struct MHD_Response *response; | 104 | struct MHD_Response *response; |
105 | int ret; | 105 | int ret; |
106 | 106 | ||
107 | if (0 != strcmp ("GET", method)) | 107 | if (0 != strcmp ("GET", method)) |
108 | return MHD_NO; /* unexpected method */ | 108 | return MHD_NO; /* unexpected method */ |
109 | if (&ptr != *unused) | 109 | if (&ptr != *unused) |
110 | { | 110 | { |
111 | *unused = &ptr; | 111 | *unused = &ptr; |
112 | return MHD_YES; | 112 | return MHD_YES; |
113 | } | 113 | } |
114 | *unused = NULL; | 114 | *unused = NULL; |
115 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 115 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
116 | "MHD sends respose for request to URL `%s'\n", url); | 116 | "MHD sends respose for request to URL `%s'\n", url); |
117 | response = | 117 | response = |
118 | MHD_create_response_from_buffer (strlen (url), (void *) url, | 118 | MHD_create_response_from_buffer (strlen (url), (void *) url, |
119 | MHD_RESPMEM_MUST_COPY); | 119 | MHD_RESPMEM_MUST_COPY); |
120 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 120 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
121 | MHD_destroy_response (response); | 121 | MHD_destroy_response (response); |
122 | if (ret == MHD_NO) | 122 | if (ret == MHD_NO) |
123 | abort (); | 123 | abort (); |
124 | return ret; | 124 | return ret; |
125 | } | 125 | } |
126 | 126 | ||
127 | 127 | ||
128 | static void | 128 | static void |
129 | do_shutdown () | 129 | do_shutdown () |
130 | { | 130 | { |
131 | if (mhd_task_id != GNUNET_SCHEDULER_NO_TASK) | 131 | if (mhd_task_id != GNUNET_SCHEDULER_NO_TASK) |
132 | { | 132 | { |
133 | GNUNET_SCHEDULER_cancel (mhd_task_id); | 133 | GNUNET_SCHEDULER_cancel (mhd_task_id); |
134 | mhd_task_id = GNUNET_SCHEDULER_NO_TASK; | 134 | mhd_task_id = GNUNET_SCHEDULER_NO_TASK; |
135 | } | 135 | } |
136 | if (curl_task_id != GNUNET_SCHEDULER_NO_TASK) | 136 | if (curl_task_id != GNUNET_SCHEDULER_NO_TASK) |
137 | { | 137 | { |
138 | GNUNET_SCHEDULER_cancel (curl_task_id); | 138 | GNUNET_SCHEDULER_cancel (curl_task_id); |
139 | curl_task_id = GNUNET_SCHEDULER_NO_TASK; | 139 | curl_task_id = GNUNET_SCHEDULER_NO_TASK; |
140 | } | 140 | } |
141 | if (ctrl_c_task_id != GNUNET_SCHEDULER_NO_TASK) | 141 | if (ctrl_c_task_id != GNUNET_SCHEDULER_NO_TASK) |
142 | { | 142 | { |
143 | GNUNET_SCHEDULER_cancel (ctrl_c_task_id); | 143 | GNUNET_SCHEDULER_cancel (ctrl_c_task_id); |
144 | ctrl_c_task_id = GNUNET_SCHEDULER_NO_TASK; | 144 | ctrl_c_task_id = GNUNET_SCHEDULER_NO_TASK; |
145 | } | 145 | } |
146 | if (NULL != mhd) | 146 | if (NULL != mhd) |
147 | { | 147 | { |
148 | MHD_stop_daemon (mhd); | 148 | MHD_stop_daemon (mhd); |
149 | mhd = NULL; | 149 | mhd = NULL; |
150 | } | 150 | } |
151 | if (NULL != rr) | 151 | if (NULL != rr) |
152 | { | 152 | { |
153 | GNUNET_VPN_cancel_request (rr); | 153 | GNUNET_VPN_cancel_request (rr); |
154 | rr = NULL; | 154 | rr = NULL; |
155 | } | 155 | } |
156 | if (NULL != vpn) | 156 | if (NULL != vpn) |
157 | { | 157 | { |
158 | GNUNET_VPN_disconnect (vpn); | 158 | GNUNET_VPN_disconnect (vpn); |
159 | vpn = NULL; | 159 | vpn = NULL; |
160 | } | 160 | } |
161 | GNUNET_free_non_null (url); | 161 | GNUNET_free_non_null (url); |
162 | url = NULL; | 162 | url = NULL; |
163 | } | 163 | } |
164 | 164 | ||
165 | 165 | ||
166 | /** | 166 | /** |
167 | * Function to run the HTTP client. | 167 | * Function to run the HTTP client. |
168 | */ | 168 | */ |
169 | static void | 169 | static void |
170 | curl_main (void); | 170 | curl_main (void); |
171 | 171 | ||
172 | 172 | ||
173 | static void | 173 | static void |
174 | curl_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 174 | curl_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
175 | { | 175 | { |
176 | curl_task_id = GNUNET_SCHEDULER_NO_TASK; | 176 | curl_task_id = GNUNET_SCHEDULER_NO_TASK; |
177 | curl_main (); | 177 | curl_main (); |
178 | } | 178 | } |
179 | 179 | ||
180 | 180 | ||
181 | static void | 181 | static void |
182 | curl_main () | 182 | curl_main () |
183 | { | 183 | { |
184 | fd_set rs; | 184 | fd_set rs; |
185 | fd_set ws; | 185 | fd_set ws; |
186 | fd_set es; | 186 | fd_set es; |
187 | int max; | 187 | int max; |
188 | struct GNUNET_NETWORK_FDSet nrs; | 188 | struct GNUNET_NETWORK_FDSet nrs; |
189 | struct GNUNET_NETWORK_FDSet nws; | 189 | struct GNUNET_NETWORK_FDSet nws; |
190 | struct GNUNET_TIME_Relative delay; | 190 | struct GNUNET_TIME_Relative delay; |
191 | long timeout; | 191 | long timeout; |
192 | int running; | 192 | int running; |
193 | struct CURLMsg *msg; | 193 | struct CURLMsg *msg; |
194 | 194 | ||
195 | max = 0; | 195 | max = 0; |
196 | FD_ZERO (&rs); | 196 | FD_ZERO (&rs); |
197 | FD_ZERO (&ws); | 197 | FD_ZERO (&ws); |
198 | FD_ZERO (&es); | 198 | FD_ZERO (&es); |
199 | curl_multi_perform (multi, &running); | 199 | curl_multi_perform (multi, &running); |
200 | if (running == 0) | 200 | if (running == 0) |
201 | { | 201 | { |
202 | GNUNET_assert (NULL != (msg = curl_multi_info_read (multi, &running))); | 202 | GNUNET_assert (NULL != (msg = curl_multi_info_read (multi, &running))); |
203 | if (msg->msg == CURLMSG_DONE) | 203 | if (msg->msg == CURLMSG_DONE) |
204 | { | 204 | { |
205 | if (msg->data.result != CURLE_OK) | 205 | if (msg->data.result != CURLE_OK) |
206 | { | 206 | { |
207 | fprintf (stderr, "%s failed at %s:%d: `%s'\n", "curl_multi_perform", | 207 | fprintf (stderr, "%s failed at %s:%d: `%s'\n", "curl_multi_perform", |
208 | __FILE__, __LINE__, curl_easy_strerror (msg->data.result)); | 208 | __FILE__, __LINE__, curl_easy_strerror (msg->data.result)); |
209 | global_ret = 1; | 209 | global_ret = 1; |
210 | } | 210 | } |
211 | } | 211 | } |
212 | curl_multi_remove_handle (multi, curl); | 212 | curl_multi_remove_handle (multi, curl); |
213 | curl_multi_cleanup (multi); | 213 | curl_multi_cleanup (multi); |
214 | curl_easy_cleanup (curl); | 214 | curl_easy_cleanup (curl); |
215 | curl = NULL; | 215 | curl = NULL; |
216 | multi = NULL; | 216 | multi = NULL; |
217 | if (cbc.pos != strlen ("/hello_world")) | 217 | if (cbc.pos != strlen ("/hello_world")) |
218 | { | 218 | { |
219 | GNUNET_break (0); | 219 | GNUNET_break (0); |
220 | global_ret = 2; | 220 | global_ret = 2; |
221 | } | 221 | } |
222 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) | 222 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) |
223 | { | 223 | { |
224 | GNUNET_break (0); | 224 | GNUNET_break (0); |
225 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 225 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
226 | "You might want to check if your host-based firewall is blocking the connections.\n"); | 226 | "You might want to check if your host-based firewall is blocking the connections.\n"); |
227 | global_ret = 3; | 227 | global_ret = 3; |
228 | } | 228 | } |
229 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download complete, shutting down!\n"); | 229 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download complete, shutting down!\n"); |
230 | do_shutdown (); | 230 | do_shutdown (); |
231 | return; | 231 | return; |
232 | } | 232 | } |
233 | GNUNET_assert (CURLM_OK == curl_multi_fdset (multi, &rs, &ws, &es, &max)); | 233 | GNUNET_assert (CURLM_OK == curl_multi_fdset (multi, &rs, &ws, &es, &max)); |
234 | if ((CURLM_OK != curl_multi_timeout (multi, &timeout)) || (-1 == timeout)) | 234 | if ((CURLM_OK != curl_multi_timeout (multi, &timeout)) || (-1 == timeout)) |
235 | delay = GNUNET_TIME_UNIT_SECONDS; | 235 | delay = GNUNET_TIME_UNIT_SECONDS; |
236 | else | 236 | else |
237 | delay = | 237 | delay = |
238 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, | 238 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, |
239 | (unsigned int) timeout); | 239 | (unsigned int) timeout); |
240 | GNUNET_NETWORK_fdset_copy_native (&nrs, &rs, max + 1); | 240 | GNUNET_NETWORK_fdset_copy_native (&nrs, &rs, max + 1); |
241 | GNUNET_NETWORK_fdset_copy_native (&nws, &ws, max + 1); | 241 | GNUNET_NETWORK_fdset_copy_native (&nws, &ws, max + 1); |
242 | curl_task_id = | 242 | curl_task_id = |
243 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, delay, | 243 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, delay, |
244 | &nrs, &nws, &curl_task, NULL); | 244 | &nrs, &nws, &curl_task, NULL); |
245 | } | 245 | } |
246 | 246 | ||
247 | 247 | ||
248 | /** | 248 | /** |
249 | * Callback invoked from the VPN service once a redirection is | 249 | * Callback invoked from the VPN service once a redirection is |
250 | * available. Provides the IP address that can now be used to | 250 | * available. Provides the IP address that can now be used to |
251 | * reach the requested destination (in our case, the MHD server) | 251 | * reach the requested destination (in our case, the MHD server) |
252 | * | 252 | * |
253 | * @param cls closure | 253 | * @param cls closure |
254 | * @param af address family, AF_INET or AF_INET6; AF_UNSPEC on error; | 254 | * @param af address family, AF_INET or AF_INET6; AF_UNSPEC on error; |
255 | * will match 'result_af' from the request | 255 | * will match 'result_af' from the request |
256 | * @param address IP address (struct in_addr or struct in_addr6, depending on 'af') | 256 | * @param address IP address (struct in_addr or struct in_addr6, depending on 'af') |
257 | * that the VPN allocated for the redirection; | 257 | * that the VPN allocated for the redirection; |
258 | * traffic to this IP will now be redirected to the | 258 | * traffic to this IP will now be redirected to the |
259 | * specified target peer; NULL on error | 259 | * specified target peer; NULL on error |
260 | */ | 260 | */ |
261 | static void | 261 | static void |
262 | allocation_cb (void *cls, int af, const void *address) | 262 | allocation_cb (void *cls, int af, const void *address) |
263 | { | 263 | { |
264 | char ips[INET6_ADDRSTRLEN]; | 264 | char ips[INET6_ADDRSTRLEN]; |
265 | 265 | ||
266 | rr = NULL; | 266 | rr = NULL; |
267 | if (src_af != af) | 267 | if (src_af != af) |
268 | { | 268 | { |
269 | fprintf (stderr, "VPN failed to allocate appropriate address\n"); | 269 | fprintf (stderr, "VPN failed to allocate appropriate address\n"); |
270 | GNUNET_SCHEDULER_shutdown (); | 270 | GNUNET_SCHEDULER_shutdown (); |
271 | return; | 271 | return; |
272 | } | 272 | } |
273 | GNUNET_asprintf (&url, "http://%s:%u/hello_world", | 273 | GNUNET_asprintf (&url, "http://%s:%u/hello_world", |
274 | inet_ntop (af, address, ips, sizeof (ips)), | 274 | inet_ntop (af, address, ips, sizeof (ips)), |
275 | (unsigned int) PORT); | 275 | (unsigned int) PORT); |
276 | curl = curl_easy_init (); | 276 | curl = curl_easy_init (); |
277 | curl_easy_setopt (curl, CURLOPT_URL, url); | 277 | curl_easy_setopt (curl, CURLOPT_URL, url); |
278 | curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, ©_buffer); | 278 | curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, ©_buffer); |
279 | curl_easy_setopt (curl, CURLOPT_WRITEDATA, &cbc); | 279 | curl_easy_setopt (curl, CURLOPT_WRITEDATA, &cbc); |
280 | curl_easy_setopt (curl, CURLOPT_FAILONERROR, 1); | 280 | curl_easy_setopt (curl, CURLOPT_FAILONERROR, 1); |
281 | curl_easy_setopt (curl, CURLOPT_TIMEOUT, 150L); | 281 | curl_easy_setopt (curl, CURLOPT_TIMEOUT, 150L); |
282 | curl_easy_setopt (curl, CURLOPT_CONNECTTIMEOUT, 15L); | 282 | curl_easy_setopt (curl, CURLOPT_CONNECTTIMEOUT, 15L); |
283 | curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1); | 283 | curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1); |
284 | 284 | ||
285 | multi = curl_multi_init (); | 285 | multi = curl_multi_init (); |
286 | GNUNET_assert (multi != NULL); | 286 | GNUNET_assert (multi != NULL); |
287 | GNUNET_assert (CURLM_OK == curl_multi_add_handle (multi, curl)); | 287 | GNUNET_assert (CURLM_OK == curl_multi_add_handle (multi, curl)); |
288 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Beginning HTTP download from `%s'\n", | 288 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Beginning HTTP download from `%s'\n", |
289 | url); | 289 | url); |
290 | curl_main (); | 290 | curl_main (); |
291 | } | 291 | } |
292 | 292 | ||
293 | 293 | ||
294 | /** | 294 | /** |
295 | * Function to keep the HTTP server running. | 295 | * Function to keep the HTTP server running. |
296 | */ | 296 | */ |
297 | static void | 297 | static void |
298 | mhd_main (void); | 298 | mhd_main (void); |
299 | 299 | ||
300 | 300 | ||
301 | static void | 301 | static void |
302 | mhd_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 302 | mhd_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
303 | { | 303 | { |
304 | mhd_task_id = GNUNET_SCHEDULER_NO_TASK; | 304 | mhd_task_id = GNUNET_SCHEDULER_NO_TASK; |
305 | MHD_run (mhd); | 305 | MHD_run (mhd); |
306 | mhd_main (); | 306 | mhd_main (); |
307 | } | 307 | } |
308 | 308 | ||
309 | 309 | ||
310 | static void | 310 | static void |
311 | ctrl_c_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 311 | ctrl_c_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
312 | { | 312 | { |
313 | ctrl_c_task_id = GNUNET_SCHEDULER_NO_TASK; | 313 | ctrl_c_task_id = GNUNET_SCHEDULER_NO_TASK; |
314 | do_shutdown (); | 314 | do_shutdown (); |
315 | GNUNET_break (0); | 315 | GNUNET_break (0); |
316 | global_ret = 1; | 316 | global_ret = 1; |
317 | } | 317 | } |
318 | 318 | ||
319 | 319 | ||
320 | static void | 320 | static void |
321 | mhd_main () | 321 | mhd_main () |
322 | { | 322 | { |
323 | struct GNUNET_NETWORK_FDSet nrs; | 323 | struct GNUNET_NETWORK_FDSet nrs; |
324 | struct GNUNET_NETWORK_FDSet nws; | 324 | struct GNUNET_NETWORK_FDSet nws; |
325 | fd_set rs; | 325 | fd_set rs; |
326 | fd_set ws; | 326 | fd_set ws; |
327 | fd_set es; | 327 | fd_set es; |
328 | int max_fd; | 328 | int max_fd; |
329 | unsigned MHD_LONG_LONG timeout; | 329 | unsigned MHD_LONG_LONG timeout; |
330 | struct GNUNET_TIME_Relative delay; | 330 | struct GNUNET_TIME_Relative delay; |
331 | 331 | ||
332 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == mhd_task_id); | 332 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == mhd_task_id); |
333 | FD_ZERO (&rs); | 333 | FD_ZERO (&rs); |
334 | FD_ZERO (&ws); | 334 | FD_ZERO (&ws); |
335 | FD_ZERO (&es); | 335 | FD_ZERO (&es); |
336 | max_fd = -1; | 336 | max_fd = -1; |
337 | GNUNET_assert (MHD_YES == MHD_get_fdset (mhd, &rs, &ws, &es, &max_fd)); | 337 | GNUNET_assert (MHD_YES == MHD_get_fdset (mhd, &rs, &ws, &es, &max_fd)); |
338 | if (MHD_YES == MHD_get_timeout (mhd, &timeout)) | 338 | if (MHD_YES == MHD_get_timeout (mhd, &timeout)) |
339 | delay = | 339 | delay = |
340 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, | 340 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, |
341 | (unsigned int) timeout); | 341 | (unsigned int) timeout); |
342 | else | 342 | else |
343 | delay = GNUNET_TIME_UNIT_FOREVER_REL; | 343 | delay = GNUNET_TIME_UNIT_FOREVER_REL; |
344 | GNUNET_NETWORK_fdset_copy_native (&nrs, &rs, max_fd + 1); | 344 | GNUNET_NETWORK_fdset_copy_native (&nrs, &rs, max_fd + 1); |
345 | GNUNET_NETWORK_fdset_copy_native (&nws, &ws, max_fd + 1); | 345 | GNUNET_NETWORK_fdset_copy_native (&nws, &ws, max_fd + 1); |
346 | mhd_task_id = | 346 | mhd_task_id = |
347 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, delay, | 347 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, delay, |
348 | &nrs, &nws, &mhd_task, NULL); | 348 | &nrs, &nws, &mhd_task, NULL); |
349 | } | 349 | } |
350 | 350 | ||
351 | 351 | ||
352 | static void | 352 | static void |
353 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, | 353 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, |
354 | struct GNUNET_TESTING_Peer *peer) | 354 | struct GNUNET_TESTING_Peer *peer) |
355 | { | 355 | { |
356 | struct in_addr v4; | 356 | struct in_addr v4; |
357 | struct in6_addr v6; | 357 | struct in6_addr v6; |
358 | void *addr; | 358 | void *addr; |
359 | enum MHD_FLAG flags; | 359 | enum MHD_FLAG flags; |
360 | 360 | ||
361 | vpn = GNUNET_VPN_connect (cfg); | 361 | vpn = GNUNET_VPN_connect (cfg); |
362 | GNUNET_assert (NULL != vpn); | 362 | GNUNET_assert (NULL != vpn); |
363 | flags = MHD_USE_DEBUG; | 363 | flags = MHD_USE_DEBUG; |
364 | if (AF_INET6 == dest_af) | 364 | if (AF_INET6 == dest_af) |
365 | flags |= MHD_USE_IPv6; | 365 | flags |= MHD_USE_IPv6; |
366 | mhd = | 366 | mhd = |
367 | MHD_start_daemon (flags, PORT, NULL, NULL, &mhd_ahc, NULL, | 367 | MHD_start_daemon (flags, PORT, NULL, NULL, &mhd_ahc, NULL, |
368 | MHD_OPTION_END); | 368 | MHD_OPTION_END); |
369 | 369 | ||
370 | 370 | ||
371 | GNUNET_assert (NULL != mhd); | 371 | GNUNET_assert (NULL != mhd); |
372 | mhd_main (); | 372 | mhd_main (); |
373 | addr = NULL; | 373 | addr = NULL; |
374 | switch (dest_af) | 374 | switch (dest_af) |
375 | { | 375 | { |
376 | case AF_INET: | 376 | case AF_INET: |
377 | GNUNET_assert (1 == inet_pton (dest_af, dest_ip, &v4)); | 377 | GNUNET_assert (1 == inet_pton (dest_af, dest_ip, &v4)); |
378 | addr = &v4; | 378 | addr = &v4; |
379 | break; | 379 | break; |
380 | case AF_INET6: | 380 | case AF_INET6: |
381 | GNUNET_assert (1 == inet_pton (dest_af, dest_ip, &v6)); | 381 | GNUNET_assert (1 == inet_pton (dest_af, dest_ip, &v6)); |
382 | addr = &v6; | 382 | addr = &v6; |
383 | break; | 383 | break; |
384 | default: | 384 | default: |
385 | GNUNET_assert (0); | 385 | GNUNET_assert (0); |
386 | } | 386 | } |
387 | rr = GNUNET_VPN_redirect_to_ip (vpn, src_af, dest_af, addr, GNUNET_YES, | 387 | rr = GNUNET_VPN_redirect_to_ip (vpn, src_af, dest_af, addr, GNUNET_YES, |
388 | GNUNET_TIME_UNIT_FOREVER_ABS, &allocation_cb, | 388 | GNUNET_TIME_UNIT_FOREVER_ABS, &allocation_cb, |
389 | NULL); | 389 | NULL); |
390 | ctrl_c_task_id = | 390 | ctrl_c_task_id = |
391 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &ctrl_c_shutdown, NULL); | 391 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &ctrl_c_shutdown, NULL); |
392 | } | 392 | } |
393 | 393 | ||
394 | 394 | ||
395 | int | 395 | int |
396 | main (int argc, char *const *argv) | 396 | main (int argc, char *const *argv) |
397 | { | 397 | { |
398 | const char *type; | 398 | const char *type; |
399 | const char *bin; | 399 | const char *bin; |
400 | char *vpn_binary; | 400 | char *vpn_binary; |
401 | char *exit_binary; | 401 | char *exit_binary; |
402 | int ret=0; | 402 | int ret=0; |
403 | 403 | ||
404 | #ifndef MINGW | 404 | #ifndef MINGW |
405 | if (0 != ACCESS ("/dev/net/tun", R_OK)) | 405 | if (0 != ACCESS ("/dev/net/tun", R_OK)) |
406 | { | 406 | { |
407 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "access", | 407 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "access", |
408 | "/dev/net/tun"); | 408 | "/dev/net/tun"); |
409 | fprintf (stderr, "WARNING: System unable to run test, skipping.\n"); | 409 | fprintf (stderr, "WARNING: System unable to run test, skipping.\n"); |
410 | return 0; | 410 | return 0; |
411 | } | 411 | } |
412 | #endif | 412 | #endif |
413 | vpn_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-vpn"); | 413 | vpn_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-vpn"); |
414 | exit_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-exit"); | 414 | exit_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-exit"); |
415 | fprintf (stderr,"%s\n", vpn_binary); | 415 | fprintf (stderr,"%s\n", vpn_binary); |
416 | fprintf (stderr,"%s\n", exit_binary); | 416 | fprintf (stderr,"%s\n", exit_binary); |
417 | if ((GNUNET_YES != (ret = GNUNET_OS_check_helper_binary (vpn_binary, GNUNET_YES, "-d gnunet-vpn - - 169.1.3.3.7 255.255.255.0"))) || //ipv4 only please! | 417 | if ((GNUNET_YES != (ret = GNUNET_OS_check_helper_binary (vpn_binary, GNUNET_YES, "-d gnunet-vpn - - 169.1.3.3.7 255.255.255.0"))) || //ipv4 only please! |
418 | (GNUNET_YES != (ret = GNUNET_OS_check_helper_binary (exit_binary, GNUNET_YES, "-d gnunet-vpn - - - 169.1.3.3.7 255.255.255.0")))) //no nat, ipv4 only | 418 | (GNUNET_YES != (ret = GNUNET_OS_check_helper_binary (exit_binary, GNUNET_YES, "-d gnunet-vpn - - - 169.1.3.3.7 255.255.255.0")))) //no nat, ipv4 only |
419 | { | 419 | { |
420 | GNUNET_free (vpn_binary); | 420 | GNUNET_free (vpn_binary); |
421 | GNUNET_free (exit_binary); | 421 | GNUNET_free (exit_binary); |
422 | fprintf (stderr, | 422 | fprintf (stderr, |
423 | "WARNING: gnunet-helper-{exit,vpn} binaries are not SUID, refusing to run test (as it would have to fail). %d\n", ret); | 423 | "WARNING: gnunet-helper-{exit,vpn} binaries are not SUID, refusing to run test (as it would have to fail). %d\n", ret); |
424 | return 0; | 424 | return 0; |
425 | } | 425 | } |
426 | 426 | ||
427 | GNUNET_free (vpn_binary); | 427 | GNUNET_free (vpn_binary); |
428 | GNUNET_free (exit_binary); | 428 | GNUNET_free (exit_binary); |
429 | GNUNET_CRYPTO_ecc_setup_hostkey ("test_gnunet_vpn.conf"); | 429 | bin = argv[0]; |
430 | bin = argv[0]; | 430 | if (NULL != strstr (bin, "lt-")) |
431 | if (NULL != strstr (bin, "lt-")) | 431 | bin = strstr (bin, "lt-") + 4; |
432 | bin = strstr (bin, "lt-") + 4; | 432 | type = strstr (bin, "-"); |
433 | type = strstr (bin, "-"); | 433 | if (NULL == type) |
434 | if (NULL == type) | 434 | { |
435 | { | 435 | fprintf (stderr, "invalid binary name\n"); |
436 | fprintf (stderr, "invalid binary name\n"); | 436 | return 1; |
437 | return 1; | 437 | } |
438 | } | 438 | type++; |
439 | type++; | 439 | /* on Windows, .exe is suffixed to these binaries, |
440 | /* on Windows, .exe is suffixed to these binaries, | 440 | * thus cease comparison after the 6th char. |
441 | * thus cease comparison after the 6th char. | 441 | */ |
442 | */ | 442 | if (0 == strncmp (type, "4_to_6",6)) |
443 | if (0 == strncmp (type, "4_to_6",6)) | 443 | { |
444 | { | 444 | dest_ip = "FC5A:04E1:C2BA::1"; |
445 | dest_ip = "FC5A:04E1:C2BA::1"; | 445 | dest_af = AF_INET6; |
446 | dest_af = AF_INET6; | 446 | src_af = AF_INET; |
447 | src_af = AF_INET; | 447 | } |
448 | } | 448 | else if (0 == strncmp (type, "6_to_4",6)) |
449 | else if (0 == strncmp (type, "6_to_4",6)) | 449 | { |
450 | { | 450 | dest_ip = "169.254.86.1"; |
451 | dest_ip = "169.254.86.1"; | 451 | dest_af = AF_INET; |
452 | dest_af = AF_INET; | 452 | src_af = AF_INET6; |
453 | src_af = AF_INET6; | 453 | } |
454 | } | 454 | else if (0 == strncmp (type, "4_over",6)) |
455 | else if (0 == strncmp (type, "4_over",6)) | 455 | { |
456 | { | 456 | dest_ip = "169.254.86.1"; |
457 | dest_ip = "169.254.86.1"; | 457 | dest_af = AF_INET; |
458 | dest_af = AF_INET; | 458 | src_af = AF_INET; |
459 | src_af = AF_INET; | 459 | } |
460 | } | 460 | else if (0 == strncmp (type, "6_over",6)) |
461 | else if (0 == strncmp (type, "6_over",6)) | 461 | { |
462 | { | 462 | dest_ip = "FC5A:04E1:C2BA::1"; |
463 | dest_ip = "FC5A:04E1:C2BA::1"; | 463 | dest_af = AF_INET6; |
464 | dest_af = AF_INET6; | 464 | src_af = AF_INET6; |
465 | src_af = AF_INET6; | 465 | } |
466 | } | 466 | else |
467 | else | 467 | { |
468 | { | 468 | fprintf (stderr, "invalid binary suffix `%s'\n", type); |
469 | fprintf (stderr, "invalid binary suffix `%s'\n", type); | 469 | return 1; |
470 | return 1; | 470 | } |
471 | } | 471 | if ((GNUNET_OK != GNUNET_NETWORK_test_pf (src_af)) || |
472 | if ((GNUNET_OK != GNUNET_NETWORK_test_pf (src_af)) || | 472 | (GNUNET_OK != GNUNET_NETWORK_test_pf (dest_af))) |
473 | (GNUNET_OK != GNUNET_NETWORK_test_pf (dest_af))) | 473 | { |
474 | { | 474 | fprintf (stderr, |
475 | fprintf (stderr, | 475 | "Required address families not supported by this system, skipping test.\n"); |
476 | "Required address families not supported by this system, skipping test.\n"); | 476 | return 0; |
477 | return 0; | 477 | } |
478 | } | 478 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
479 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 479 | { |
480 | { | 480 | fprintf (stderr, "failed to initialize curl\n"); |
481 | fprintf (stderr, "failed to initialize curl\n"); | 481 | return 2; |
482 | return 2; | 482 | } |
483 | } | 483 | if (0 != |
484 | if (0 != | 484 | GNUNET_TESTING_peer_run ("test-gnunet-vpn", "test_gnunet_vpn.conf", &run, |
485 | GNUNET_TESTING_peer_run ("test-gnunet-vpn", "test_gnunet_vpn.conf", &run, | 485 | NULL)) |
486 | NULL)) | 486 | return 1; |
487 | return 1; | 487 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-vpn"); |
488 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-vpn"); | 488 | return global_ret; |
489 | return global_ret; | 489 | } |
490 | } | 490 | |
491 | 491 | /* end of test_gnunet_vpn.c */ | |
492 | /* end of test_gnunet_vpn.c */ | ||