diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-12-12 21:45:00 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-12-12 21:45:00 +0000 |
commit | a33a6a8017dfdd912a8b22354d9d4dc97200daff (patch) | |
tree | 88b55256073461837277c81f55ded69203356735 /src/nat | |
parent | 997b729e8cbd05f51bac7dcd795ca7b35aa5e551 (diff) | |
download | gnunet-a33a6a8017dfdd912a8b22354d9d4dc97200daff.tar.gz gnunet-a33a6a8017dfdd912a8b22354d9d4dc97200daff.zip |
nat auto code from gnunet-gtk now compiles as part of libgnunetnat
Diffstat (limited to 'src/nat')
-rw-r--r-- | src/nat/Makefile.am | 3 | ||||
-rw-r--r-- | src/nat/nat_auto.c | 270 |
2 files changed, 145 insertions, 128 deletions
diff --git a/src/nat/Makefile.am b/src/nat/Makefile.am index 00d72ebba..3a40340a8 100644 --- a/src/nat/Makefile.am +++ b/src/nat/Makefile.am | |||
@@ -54,8 +54,9 @@ lib_LTLIBRARIES = libgnunetnat.la | |||
54 | 54 | ||
55 | libgnunetnat_la_SOURCES = \ | 55 | libgnunetnat_la_SOURCES = \ |
56 | nat.c nat.h \ | 56 | nat.c nat.h \ |
57 | nat_auto.c \ | ||
57 | nat_test.c \ | 58 | nat_test.c \ |
58 | nat_mini.c | 59 | nat_mini.c |
59 | 60 | ||
60 | libgnunetnat_la_LIBADD = \ | 61 | libgnunetnat_la_LIBADD = \ |
61 | $(top_builddir)/src/util/libgnunetutil.la \ | 62 | $(top_builddir)/src/util/libgnunetutil.la \ |
diff --git a/src/nat/nat_auto.c b/src/nat/nat_auto.c index 50c6c1121..d1ca940a0 100644 --- a/src/nat/nat_auto.c +++ b/src/nat/nat_auto.c | |||
@@ -25,6 +25,7 @@ | |||
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
28 | #include "gnunet_resolver_service.h" | ||
28 | #include "gnunet_nat_lib.h" | 29 | #include "gnunet_nat_lib.h" |
29 | #include "nat.h" | 30 | #include "nat.h" |
30 | 31 | ||
@@ -49,7 +50,7 @@ enum AutoPhase | |||
49 | /** | 50 | /** |
50 | * Test if we are online. | 51 | * Test if we are online. |
51 | */ | 52 | */ |
52 | AUTO_ONLINE = 1, | 53 | AUTO_ONLINE, |
53 | 54 | ||
54 | /** | 55 | /** |
55 | * Test our external IP. | 56 | * Test our external IP. |
@@ -128,32 +129,28 @@ struct GNUNET_NAT_AutoHandle | |||
128 | /** | 129 | /** |
129 | * Task identifier for the timeout. | 130 | * Task identifier for the timeout. |
130 | */ | 131 | */ |
131 | GNUNET_SCHEDULER_TaskIdentifier tsk; | 132 | GNUNET_SCHEDULER_TaskIdentifier task; |
132 | 133 | ||
133 | /** | 134 | /** |
134 | * Where are we in the test? | 135 | * Where are we in the test? |
135 | */ | 136 | */ |
136 | enum AutoPhase phase; | 137 | enum AutoPhase phase; |
137 | 138 | ||
139 | /** | ||
140 | * Do we have IPv6? | ||
141 | */ | ||
142 | int have_v6; | ||
143 | |||
138 | }; | 144 | }; |
139 | 145 | ||
140 | 146 | ||
141 | /** | 147 | /** |
142 | * Run the next phase of the auto test. | 148 | * Run the next phase of the auto test. |
143 | * | 149 | * |
144 | * @param ac auto test handle | 150 | * @param ah auto test handle |
145 | */ | 151 | */ |
146 | static void | 152 | static void |
147 | next_phase (struct GNUNET_NAT_AutoHandle *ac); | 153 | next_phase (struct GNUNET_NAT_AutoHandle *ah); |
148 | |||
149 | |||
150 | |||
151 | GNUNET_break (0); | ||
152 | return; | ||
153 | } | ||
154 | gtk_toggle_button_set_active (button, on ? TRUE : FALSE); | ||
155 | } | ||
156 | |||
157 | 154 | ||
158 | 155 | ||
159 | /** | 156 | /** |
@@ -166,22 +163,47 @@ next_phase (struct GNUNET_NAT_AutoHandle *ac); | |||
166 | static void | 163 | static void |
167 | fail_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 164 | fail_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
168 | { | 165 | { |
169 | struct GNUNET_NAT_AutoHandle *ac = cls; | 166 | struct GNUNET_NAT_AutoHandle *ah = cls; |
170 | 167 | ||
171 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 168 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
172 | _("NAT traversal with ICMP Server timed out.\n")); | 169 | _("NAT traversal with ICMP Server timed out.\n")); |
173 | GNUNET_assert (NULL != ac->tst); | 170 | GNUNET_assert (NULL != ah->tst); |
174 | ac->tsk = GNUNET_SCHEDULER_NO_TASK; | 171 | ah->task = GNUNET_SCHEDULER_NO_TASK; |
175 | GNUNET_NAT_test_stop (ac->tst); | 172 | GNUNET_NAT_test_stop (ah->tst); |
176 | ac->tst = NULL; | 173 | ah->tst = NULL; |
177 | update_icmp_server_enable_button (GNUNET_NO); | 174 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", |
178 | if (NULL != cfg) | 175 | "ENABLE_ICMP_SERVER", |
179 | GNUNET_CONFIGURATION_set_value_string (cfg, "nat", "ENABLE_ICMP_SERVER", "NO"); | 176 | "NO"); |
180 | next_phase (ac); | 177 | next_phase (ah); |
181 | } | 178 | } |
182 | 179 | ||
183 | 180 | ||
184 | /** | 181 | /** |
182 | * Function called by NAT on success. | ||
183 | * Clean up and update GUI (with success). | ||
184 | * | ||
185 | * @param cls the auto handle | ||
186 | * @param success currently always GNUNET_OK | ||
187 | */ | ||
188 | static void | ||
189 | result_callback (void *cls, int success) | ||
190 | { | ||
191 | struct GNUNET_NAT_AutoHandle *ah = cls; | ||
192 | |||
193 | GNUNET_SCHEDULER_cancel (ah->task); | ||
194 | ah->task = GNUNET_SCHEDULER_NO_TASK; | ||
195 | GNUNET_NAT_test_stop (ah->tst); | ||
196 | ah->tst = NULL; | ||
197 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
198 | success | ||
199 | ? _("NAT traversal with ICMP Server succeeded.\n") | ||
200 | : _("NAT traversal with ICMP Server failed.\n")); | ||
201 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "ENABLE_ICMP_SERVER", | ||
202 | success ? "YES": "NO"); | ||
203 | next_phase (ah); | ||
204 | } | ||
205 | |||
206 | /** | ||
185 | * Main function for the connection reversal test. | 207 | * Main function for the connection reversal test. |
186 | * | 208 | * |
187 | * @param cls the 'int*' for the result | 209 | * @param cls the 'int*' for the result |
@@ -190,32 +212,33 @@ fail_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
190 | static void | 212 | static void |
191 | reversal_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 213 | reversal_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
192 | { | 214 | { |
193 | struct GNUNET_NAT_AutoHandle *ac = cls; | 215 | struct GNUNET_NAT_AutoHandle *ah = cls; |
194 | 216 | ||
217 | ah->task = GNUNET_SCHEDULER_NO_TASK; | ||
195 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 218 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
196 | _("Testing connection reversal with ICMP server.\n")); | 219 | _("Testing connection reversal with ICMP server.\n")); |
197 | GNUNET_assert (NULL != cfg); | 220 | GNUNET_RESOLVER_connect (ah->cfg); |
198 | GNUNET_RESOLVER_connect (cfg); | 221 | ah->tst = GNUNET_NAT_test_start (ah->cfg, GNUNET_YES, 0, 0, |
199 | ac->tst = GNUNET_NAT_test_start (cfg, GNUNET_YES, 0, 0, &result_callback, ac); | 222 | &result_callback, ah); |
200 | if (NULL == ac->tst) | 223 | if (NULL == ah->tst) |
201 | { | 224 | { |
202 | next_phase (ac); | 225 | next_phase (ah); |
203 | return; | 226 | return; |
204 | } | 227 | } |
205 | ac->tsk = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &fail_timeout, ac); | 228 | ah->task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &fail_timeout, ah); |
206 | } | 229 | } |
207 | 230 | ||
208 | 231 | ||
209 | /** | 232 | /** |
210 | * Test if we are online at all. | 233 | * Test if we are online at all. |
211 | * | 234 | * |
212 | * @param ac auto setup context | 235 | * @param ah auto setup context |
213 | */ | 236 | */ |
214 | static void | 237 | static void |
215 | test_online (struct GNUNET_NAT_AutoHandle *ac) | 238 | test_online (struct GNUNET_NAT_AutoHandle *ah) |
216 | { | 239 | { |
217 | // FIXME: not implemented | 240 | // FIXME: not implemented |
218 | next_phase (ac); | 241 | next_phase (ah); |
219 | } | 242 | } |
220 | 243 | ||
221 | 244 | ||
@@ -228,14 +251,13 @@ test_online (struct GNUNET_NAT_AutoHandle *ac) | |||
228 | static void | 251 | static void |
229 | set_external_ipv4 (void *cls, const struct in_addr *addr) | 252 | set_external_ipv4 (void *cls, const struct in_addr *addr) |
230 | { | 253 | { |
231 | struct GNUNET_NAT_AutoHandle *ac = cls; | 254 | struct GNUNET_NAT_AutoHandle *ah = cls; |
232 | char buf[INET_ADDRSTRLEN]; | 255 | char buf[INET_ADDRSTRLEN]; |
233 | GObject *o; | ||
234 | 256 | ||
235 | ac->eh = NULL; | 257 | ah->eh = NULL; |
236 | if (NULL == addr) | 258 | if (NULL == addr) |
237 | { | 259 | { |
238 | next_phase (ac); | 260 | next_phase (ah); |
239 | return; | 261 | return; |
240 | } | 262 | } |
241 | /* enable 'behind nat' */ | 263 | /* enable 'behind nat' */ |
@@ -245,39 +267,33 @@ set_external_ipv4 (void *cls, const struct in_addr *addr) | |||
245 | addr, | 267 | addr, |
246 | buf, | 268 | buf, |
247 | sizeof (buf))); | 269 | sizeof (buf))); |
248 | if (NULL != cfg) | 270 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "BEHIND_NAT", "YES"); |
249 | GNUNET_CONFIGURATION_set_value_string (cfg, "nat", "BEHIND_NAT", "YES"); | ||
250 | o = GNUNET_SETUP_get_object ("GNUNET_setup_transport_nat_checkbutton"); | ||
251 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (o), TRUE); | ||
252 | 271 | ||
253 | /* set external IP address */ | 272 | /* set external IP address */ |
254 | if (NULL == inet_ntop (AF_INET, addr, buf, sizeof (buf))) | 273 | if (NULL == inet_ntop (AF_INET, addr, buf, sizeof (buf))) |
255 | { | 274 | { |
256 | GNUNET_break (0); | 275 | GNUNET_break (0); |
257 | next_phase (ac); | 276 | next_phase (ah); |
258 | return; | 277 | return; |
259 | } | 278 | } |
260 | if (NULL != cfg) | 279 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "EXTERNAL_ADDRESS", |
261 | GNUNET_CONFIGURATION_set_value_string (cfg, "nat", "EXTERNAL_ADDRESS", | 280 | buf); |
262 | buf); | 281 | next_phase (ah); |
263 | o = GNUNET_SETUP_get_object ("GNUNET_setup_transport_external_ip_address_entry"); | ||
264 | gtk_entry_set_text (GTK_ENTRY (o), buf); | ||
265 | next_phase (ac); | ||
266 | } | 282 | } |
267 | 283 | ||
268 | 284 | ||
269 | /** | 285 | /** |
270 | * Determine our external IPv4 address. | 286 | * Determine our external IPv4 address. |
271 | * | 287 | * |
272 | * @param ac auto setup context | 288 | * @param ah auto setup context |
273 | */ | 289 | */ |
274 | static void | 290 | static void |
275 | test_external_ip (struct GNUNET_NAT_AutoHandle *ac) | 291 | test_external_ip (struct GNUNET_NAT_AutoHandle *ah) |
276 | { | 292 | { |
277 | // FIXME: CPS? | 293 | // FIXME: CPS? |
278 | /* try to detect external IP */ | 294 | /* try to detect external IP */ |
279 | ac->eh = GNUNET_NAT_mini_get_external_ipv4 (TIMEOUT, | 295 | ah->eh = GNUNET_NAT_mini_get_external_ipv4 (TIMEOUT, |
280 | &set_external_ipv4, ac); | 296 | &set_external_ipv4, ah); |
281 | } | 297 | } |
282 | 298 | ||
283 | 299 | ||
@@ -285,7 +301,7 @@ test_external_ip (struct GNUNET_NAT_AutoHandle *ac) | |||
285 | * Process list of local IP addresses. Find and set the | 301 | * Process list of local IP addresses. Find and set the |
286 | * one of the default interface. | 302 | * one of the default interface. |
287 | * | 303 | * |
288 | * @param cls pointer to int to store if we have a non-local IPv6 address | 304 | * @param cls our NAT auto handle |
289 | * @param name name of the interface (can be NULL for unknown) | 305 | * @param name name of the interface (can be NULL for unknown) |
290 | * @param isDefault is this presumably the default interface | 306 | * @param isDefault is this presumably the default interface |
291 | * @param addr address of this interface (can be NULL for unknown or unassigned) | 307 | * @param addr address of this interface (can be NULL for unknown or unassigned) |
@@ -299,10 +315,9 @@ nipo (void *cls, const char *name, int isDefault, const struct sockaddr *addr, | |||
299 | const struct sockaddr *broadcast_addr, const struct sockaddr *netmask, | 315 | const struct sockaddr *broadcast_addr, const struct sockaddr *netmask, |
300 | socklen_t addrlen) | 316 | socklen_t addrlen) |
301 | { | 317 | { |
302 | int *have_v6 = cls; | 318 | struct GNUNET_NAT_AutoHandle *ah = cls; |
303 | const struct sockaddr_in *in; | 319 | const struct sockaddr_in *in; |
304 | char buf[INET_ADDRSTRLEN]; | 320 | char buf[INET_ADDRSTRLEN]; |
305 | GtkEntry *entry; | ||
306 | 321 | ||
307 | if (!isDefault) | 322 | if (!isDefault) |
308 | return GNUNET_OK; | 323 | return GNUNET_OK; |
@@ -311,7 +326,7 @@ nipo (void *cls, const char *name, int isDefault, const struct sockaddr *addr, | |||
311 | addrlen)) && | 326 | addrlen)) && |
312 | (! IN6_IS_ADDR_LINKLOCAL(addr)) ) | 327 | (! IN6_IS_ADDR_LINKLOCAL(addr)) ) |
313 | { | 328 | { |
314 | *have_v6 = GNUNET_YES; | 329 | ah->have_v6 = GNUNET_YES; |
315 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 330 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
316 | _("This system has a global IPv6 address, setting IPv6 to supported.\n")); | 331 | _("This system has a global IPv6 address, setting IPv6 to supported.\n")); |
317 | return GNUNET_OK; | 332 | return GNUNET_OK; |
@@ -326,14 +341,11 @@ nipo (void *cls, const char *name, int isDefault, const struct sockaddr *addr, | |||
326 | GNUNET_break (0); | 341 | GNUNET_break (0); |
327 | return GNUNET_OK; | 342 | return GNUNET_OK; |
328 | } | 343 | } |
329 | GNUNET_CONFIGURATION_set_value_string (cfg, "nat", "INTERNAL_ADDRESS", buf); | 344 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "INTERNAL_ADDRESS", |
345 | buf); | ||
330 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 346 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
331 | _("Detected internal network address `%s'.\n"), | 347 | _("Detected internal network address `%s'.\n"), |
332 | buf); | 348 | buf); |
333 | entry = | ||
334 | GTK_ENTRY (GNUNET_SETUP_get_object | ||
335 | ("GNUNET_setup_transport_internal_ip_entry")); | ||
336 | gtk_entry_set_text (entry, buf); | ||
337 | /* no need to continue iteration */ | 349 | /* no need to continue iteration */ |
338 | return GNUNET_SYSERR; | 350 | return GNUNET_SYSERR; |
339 | } | 351 | } |
@@ -342,52 +354,43 @@ nipo (void *cls, const char *name, int isDefault, const struct sockaddr *addr, | |||
342 | /** | 354 | /** |
343 | * Determine our local IP addresses; detect internal IP & IPv6-support | 355 | * Determine our local IP addresses; detect internal IP & IPv6-support |
344 | * | 356 | * |
345 | * @param ac auto setup context | 357 | * @param ah auto setup context |
346 | */ | 358 | */ |
347 | static void | 359 | static void |
348 | test_local_ip (struct GNUNET_NAT_AutoHandle *ac) | 360 | test_local_ip (struct GNUNET_NAT_AutoHandle *ah) |
349 | { | 361 | { |
350 | GtkToggleButton *button; | 362 | ah->have_v6 = GNUNET_NO; |
351 | int have_v6; | 363 | GNUNET_OS_network_interfaces_list (&nipo, ah); |
352 | 364 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "DISABLEV6", | |
353 | have_v6 = GNUNET_NO; | 365 | (GNUNET_YES == ah->have_v6) ? "NO" : "YES"); |
354 | GNUNET_OS_network_interfaces_list (&nipo, &have_v6); | 366 | next_phase (ah); |
355 | button = GTK_TOGGLE_BUTTON (GNUNET_SETUP_get_object ("GNUNET_setup_transport_disable_ipv6_checkbutton")); | ||
356 | gtk_toggle_button_set_active (button, | ||
357 | (GNUNET_YES == have_v6) ? FALSE : TRUE); | ||
358 | if (NULL != cfg) | ||
359 | GNUNET_CONFIGURATION_set_value_string (cfg, "nat", "DISABLEV6", | ||
360 | (GNUNET_YES == have_v6) ? "NO" : "YES"); | ||
361 | next_phase (ac); | ||
362 | } | 367 | } |
363 | 368 | ||
364 | 369 | ||
365 | /** | 370 | /** |
366 | * Test if NAT has been punched | 371 | * Test if NAT has been punched |
367 | * | 372 | * |
368 | * @param ac auto setup context | 373 | * @param ah auto setup context |
369 | */ | 374 | */ |
370 | static void | 375 | static void |
371 | test_nat_punched (struct GNUNET_NAT_AutoHandle *ac) | 376 | test_nat_punched (struct GNUNET_NAT_AutoHandle *ah) |
372 | { | 377 | { |
373 | // FIXME: not implemented | 378 | // FIXME: not implemented |
374 | next_phase (ac); | 379 | next_phase (ah); |
375 | } | 380 | } |
376 | 381 | ||
377 | 382 | ||
378 | /** | 383 | /** |
379 | * Test if UPnPC works. | 384 | * Test if UPnPC works. |
380 | * | 385 | * |
381 | * @param ac auto setup context | 386 | * @param ah auto setup context |
382 | */ | 387 | */ |
383 | static void | 388 | static void |
384 | test_upnpc (struct GNUNET_NAT_AutoHandle *ac) | 389 | test_upnpc (struct GNUNET_NAT_AutoHandle *ah) |
385 | { | 390 | { |
386 | int have_upnpc; | 391 | int have_upnpc; |
387 | GtkToggleButton *button; | ||
388 | 392 | ||
389 | /* test if upnpc is available */ | 393 | /* test if upnpc is available */ |
390 | button = GTK_TOGGLE_BUTTON (GNUNET_SETUP_get_object ("GNUNET_setup_transport_upnp_enable_checkbutton")); | ||
391 | have_upnpc = (GNUNET_SYSERR != | 394 | have_upnpc = (GNUNET_SYSERR != |
392 | GNUNET_OS_check_helper_binary ("upnpc")); | 395 | GNUNET_OS_check_helper_binary ("upnpc")); |
393 | /* FIXME: test if upnpc is actually working, that is, if transports | 396 | /* FIXME: test if upnpc is actually working, that is, if transports |
@@ -396,24 +399,19 @@ test_upnpc (struct GNUNET_NAT_AutoHandle *ac) | |||
396 | (have_upnpc) | 399 | (have_upnpc) |
397 | ? _("upnpc found, enabling its use\n") | 400 | ? _("upnpc found, enabling its use\n") |
398 | : _("upnpc not found\n")); | 401 | : _("upnpc not found\n")); |
399 | gtk_toggle_button_set_active (button, | 402 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "ENABLE_UPNP", |
400 | have_upnpc | 403 | (GNUNET_YES == have_upnpc) ? "YES" : "NO"); |
401 | ? TRUE | 404 | next_phase (ah); |
402 | : FALSE); | ||
403 | if (NULL != cfg) | ||
404 | GNUNET_CONFIGURATION_set_value_string (cfg, "nat", "ENABLE_UPNP", | ||
405 | (GNUNET_YES == have_upnpc) ? "YES" : "NO"); | ||
406 | next_phase (ac); | ||
407 | } | 405 | } |
408 | 406 | ||
409 | 407 | ||
410 | /** | 408 | /** |
411 | * Test if ICMP server is working | 409 | * Test if ICMP server is working |
412 | * | 410 | * |
413 | * @param ac auto setup context | 411 | * @param ah auto setup context |
414 | */ | 412 | */ |
415 | static void | 413 | static void |
416 | test_icmp_server (struct GNUNET_NAT_AutoHandle *ac) | 414 | test_icmp_server (struct GNUNET_NAT_AutoHandle *ah) |
417 | { | 415 | { |
418 | int hns; | 416 | int hns; |
419 | char *tmp; | 417 | char *tmp; |
@@ -423,10 +421,10 @@ test_icmp_server (struct GNUNET_NAT_AutoHandle *ac) | |||
423 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-server"); | 421 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-server"); |
424 | hns = | 422 | hns = |
425 | ((GNUNET_OK == | 423 | ((GNUNET_OK == |
426 | GNUNET_CONFIGURATION_get_value_string (cfg, "nat", "EXTERNAL_ADDRESS", | 424 | GNUNET_CONFIGURATION_get_value_string (ah->cfg, "nat", "EXTERNAL_ADDRESS", |
427 | &tmp)) && (0 < strlen (tmp)) && | 425 | &tmp)) && (0 < strlen (tmp)) && |
428 | (GNUNET_YES == | 426 | (GNUNET_YES == |
429 | GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat", "BEHIND_NAT")) && | 427 | GNUNET_CONFIGURATION_get_value_yesno (ah->cfg, "nat", "BEHIND_NAT")) && |
430 | (GNUNET_YES == | 428 | (GNUNET_YES == |
431 | GNUNET_OS_check_helper_binary (binary))); | 429 | GNUNET_OS_check_helper_binary (binary))); |
432 | GNUNET_free_non_null (tmp); | 430 | GNUNET_free_non_null (tmp); |
@@ -436,21 +434,20 @@ test_icmp_server (struct GNUNET_NAT_AutoHandle *ac) | |||
436 | ? _("gnunet-helper-nat-server found, testing it\n") | 434 | ? _("gnunet-helper-nat-server found, testing it\n") |
437 | : _("No working gnunet-helper-nat-server found\n")); | 435 | : _("No working gnunet-helper-nat-server found\n")); |
438 | if (hns) | 436 | if (hns) |
439 | GNUNET_SCHEDULER_add_now (&reversal_test, ac); | 437 | ah->task = GNUNET_SCHEDULER_add_now (&reversal_test, ah); |
440 | else | 438 | else |
441 | next_phase (ac); | 439 | next_phase (ah); |
442 | } | 440 | } |
443 | 441 | ||
444 | 442 | ||
445 | /** | 443 | /** |
446 | * Test if ICMP client is working | 444 | * Test if ICMP client is working |
447 | * | 445 | * |
448 | * @param ac auto setup context | 446 | * @param ah auto setup context |
449 | */ | 447 | */ |
450 | static void | 448 | static void |
451 | test_icmp_client (struct GNUNET_NAT_AutoHandle *ac) | 449 | test_icmp_client (struct GNUNET_NAT_AutoHandle *ah) |
452 | { | 450 | { |
453 | GtkToggleButton *button; | ||
454 | int hnc; | 451 | int hnc; |
455 | char *tmp; | 452 | char *tmp; |
456 | char *binary; | 453 | char *binary; |
@@ -459,10 +456,10 @@ test_icmp_client (struct GNUNET_NAT_AutoHandle *ac) | |||
459 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-client"); | 456 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-client"); |
460 | hnc = | 457 | hnc = |
461 | ((GNUNET_OK == | 458 | ((GNUNET_OK == |
462 | GNUNET_CONFIGURATION_get_value_string (cfg, "nat", "INTERNAL_ADDRESS", | 459 | GNUNET_CONFIGURATION_get_value_string (ah->cfg, "nat", "INTERNAL_ADDRESS", |
463 | &tmp)) && (0 < strlen (tmp)) && | 460 | &tmp)) && (0 < strlen (tmp)) && |
464 | (GNUNET_YES != | 461 | (GNUNET_YES != |
465 | GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat", "BEHIND_NAT")) && | 462 | GNUNET_CONFIGURATION_get_value_yesno (ah->cfg, "nat", "BEHIND_NAT")) && |
466 | (GNUNET_YES == | 463 | (GNUNET_YES == |
467 | GNUNET_OS_check_helper_binary (binary))); | 464 | GNUNET_OS_check_helper_binary (binary))); |
468 | GNUNET_free_non_null (tmp); | 465 | GNUNET_free_non_null (tmp); |
@@ -471,11 +468,7 @@ test_icmp_client (struct GNUNET_NAT_AutoHandle *ac) | |||
471 | (hnc) | 468 | (hnc) |
472 | ? _("gnunet-helper-nat-client found, enabling it\n") | 469 | ? _("gnunet-helper-nat-client found, enabling it\n") |
473 | : _("gnunet-helper-nat-client not found or behind NAT, disabling it\n")); | 470 | : _("gnunet-helper-nat-client not found or behind NAT, disabling it\n")); |
474 | button = | 471 | next_phase (ah); |
475 | GTK_TOGGLE_BUTTON (GNUNET_SETUP_get_object | ||
476 | ("GNUNET_setup_transport_icmp_client_enable_checkbutton")); | ||
477 | gtk_toggle_button_set_active (button, hnc ? TRUE : FALSE); | ||
478 | next_phase (ac); | ||
479 | } | 472 | } |
480 | 473 | ||
481 | 474 | ||
@@ -483,38 +476,44 @@ test_icmp_client (struct GNUNET_NAT_AutoHandle *ac) | |||
483 | * Run the next phase of the auto test. | 476 | * Run the next phase of the auto test. |
484 | */ | 477 | */ |
485 | static void | 478 | static void |
486 | next_phase (struct GNUNET_NAT_AutoHandle *ac) | 479 | next_phase (struct GNUNET_NAT_AutoHandle *ah) |
487 | { | 480 | { |
488 | ac->phase++; | 481 | struct GNUNET_CONFIGURATION_Handle *diff; |
489 | switch (ac->phase) | 482 | |
483 | ah->phase++; | ||
484 | switch (ah->phase) | ||
490 | { | 485 | { |
491 | case AUTO_INIT: | 486 | case AUTO_INIT: |
492 | GNUNET_assert (0); | 487 | GNUNET_assert (0); |
493 | break; | 488 | break; |
494 | case AUTO_ONLINE: | 489 | case AUTO_ONLINE: |
495 | test_online (ac); | 490 | test_online (ah); |
496 | break; | 491 | break; |
497 | case AUTO_EXTERNAL_IP: | 492 | case AUTO_EXTERNAL_IP: |
498 | test_external_ip (ac); | 493 | test_external_ip (ah); |
499 | break; | 494 | break; |
500 | case AUTO_LOCAL_IP: | 495 | case AUTO_LOCAL_IP: |
501 | test_local_ip (ac); | 496 | test_local_ip (ah); |
502 | break; | 497 | break; |
503 | case AUTO_NAT_PUNCHED: | 498 | case AUTO_NAT_PUNCHED: |
504 | test_nat_punched (ac); | 499 | test_nat_punched (ah); |
505 | break; | 500 | break; |
506 | case AUTO_UPNPC: | 501 | case AUTO_UPNPC: |
507 | test_upnpc (ac); | 502 | test_upnpc (ah); |
508 | break; | 503 | break; |
509 | case AUTO_ICMP_SERVER: | 504 | case AUTO_ICMP_SERVER: |
510 | test_icmp_server (ac); | 505 | test_icmp_server (ah); |
511 | break; | 506 | break; |
512 | case AUTO_ICMP_CLIENT: | 507 | case AUTO_ICMP_CLIENT: |
513 | test_icmp_client (ac); | 508 | test_icmp_client (ah); |
514 | break; | 509 | break; |
515 | case AUTO_DONE: | 510 | case AUTO_DONE: |
516 | ac->fin_cb (ac->fin_cb_cls); | 511 | diff = GNUNET_CONFIGURATION_get_diff (ah->initial_cfg, |
517 | GNUNET_free (ac); | 512 | ah->cfg); |
513 | ah->fin_cb (ah->fin_cb_cls, | ||
514 | diff); | ||
515 | GNUNET_CONFIGURATION_destroy (diff); | ||
516 | GNUNET_NAT_autoconfig_cancel (ah); | ||
518 | return; | 517 | return; |
519 | } | 518 | } |
520 | } | 519 | } |
@@ -535,24 +534,23 @@ GNUNET_NAT_autoconfig_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
535 | GNUNET_NAT_AutoResultCallback cb, | 534 | GNUNET_NAT_AutoResultCallback cb, |
536 | void *cb_cls) | 535 | void *cb_cls) |
537 | { | 536 | { |
538 | struct GNUNET_NAT_AutoHandle *ac; | 537 | struct GNUNET_NAT_AutoHandle *ah; |
539 | 538 | ||
540 | ac = GNUNET_malloc (sizeof (struct GNUNET_NAT_AutoHandle)); | 539 | ah = GNUNET_malloc (sizeof (struct GNUNET_NAT_AutoHandle)); |
541 | ac->fin_cb = cb; | 540 | ah->fin_cb = cb; |
542 | ac->fin_cb_cls = cb_cls; | 541 | ah->fin_cb_cls = cb_cls; |
543 | ac->cfg = GNUNET_CONFIGURATION_dup (cfg); | 542 | ah->cfg = GNUNET_CONFIGURATION_dup (cfg); |
544 | ac->init_cfg = GNUNET_CONFIGURATION_dup (cfg); | 543 | ah->initial_cfg = GNUNET_CONFIGURATION_dup (cfg); |
545 | 544 | ||
546 | /* never use loopback addresses if user wanted autoconfiguration */ | 545 | /* never use loopback addresses if user wanted autoconfiguration */ |
547 | GNUNET_CONFIGURATION_set_value_string (ac->cfg, "nat", | 546 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", |
548 | "USE_LOCALADDR", | 547 | "USE_LOCALADDR", |
549 | "NO"); | 548 | "NO"); |
550 | next_phase (ac); | 549 | next_phase (ah); |
551 | return ac; | 550 | return ah; |
552 | } | 551 | } |
553 | 552 | ||
554 | 553 | ||
555 | |||
556 | /** | 554 | /** |
557 | * Abort autoconfiguration. | 555 | * Abort autoconfiguration. |
558 | * | 556 | * |
@@ -561,6 +559,24 @@ GNUNET_NAT_autoconfig_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
561 | void | 559 | void |
562 | GNUNET_NAT_autoconfig_cancel (struct GNUNET_NAT_AutoHandle *ah) | 560 | GNUNET_NAT_autoconfig_cancel (struct GNUNET_NAT_AutoHandle *ah) |
563 | { | 561 | { |
562 | if (NULL != ah->tst) | ||
563 | { | ||
564 | GNUNET_NAT_test_stop (ah->tst); | ||
565 | ah->tst = NULL; | ||
566 | } | ||
567 | if (NULL != ah->eh) | ||
568 | { | ||
569 | GNUNET_NAT_mini_get_external_ipv4_cancel (ah->eh); | ||
570 | ah->eh = NULL; | ||
571 | } | ||
572 | if (GNUNET_SCHEDULER_NO_TASK != ah->task) | ||
573 | { | ||
574 | GNUNET_SCHEDULER_cancel (ah->task); | ||
575 | ah->task = GNUNET_SCHEDULER_NO_TASK; | ||
576 | } | ||
577 | GNUNET_CONFIGURATION_destroy (ah->cfg); | ||
578 | GNUNET_CONFIGURATION_destroy (ah->initial_cfg); | ||
579 | GNUNET_free (ah); | ||
564 | } | 580 | } |
565 | 581 | ||
566 | 582 | ||