aboutsummaryrefslogtreecommitdiff
path: root/src/nat-auto/gnunet-service-nat-auto_legacy.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nat-auto/gnunet-service-nat-auto_legacy.c')
-rw-r--r--src/nat-auto/gnunet-service-nat-auto_legacy.c1009
1 files changed, 512 insertions, 497 deletions
diff --git a/src/nat-auto/gnunet-service-nat-auto_legacy.c b/src/nat-auto/gnunet-service-nat-auto_legacy.c
index 30f1f855d..1817c2270 100644
--- a/src/nat-auto/gnunet-service-nat-auto_legacy.c
+++ b/src/nat-auto/gnunet-service-nat-auto_legacy.c
@@ -30,20 +30,22 @@
30#include "gnunet_nat_lib.h" 30#include "gnunet_nat_lib.h"
31#include "nat.h" 31#include "nat.h"
32 32
33#define LOG(kind, ...) GNUNET_log_from(kind, "nat", __VA_ARGS__) 33#define LOG(kind, ...) GNUNET_log_from (kind, "nat", __VA_ARGS__)
34 34
35 35
36/** 36/**
37 * How long do we wait for the NAT test to report success? 37 * How long do we wait for the NAT test to report success?
38 */ 38 */
39#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) 39#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
40 40
41#define NAT_SERVER_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) 41#define NAT_SERVER_TIMEOUT GNUNET_TIME_relative_multiply ( \
42 GNUNET_TIME_UNIT_SECONDS, 10)
42 43
43/** 44/**
44 * Phases of the auto configuration. 45 * Phases of the auto configuration.
45 */ 46 */
46enum AutoPhase { 47enum AutoPhase
48{
47 /** 49 /**
48 * Initial start value. 50 * Initial start value.
49 */ 51 */
@@ -94,7 +96,8 @@ enum AutoPhase {
94/** 96/**
95 * Handle to auto-configuration in progress. 97 * Handle to auto-configuration in progress.
96 */ 98 */
97struct GNUNET_NAT_AutoHandle { 99struct GNUNET_NAT_AutoHandle
100{
98 /** 101 /**
99 * Handle to the active NAT test. 102 * Handle to the active NAT test.
100 */ 103 */
@@ -205,20 +208,20 @@ static unsigned int stun_port = 3478;
205 * @param ah auto test handle 208 * @param ah auto test handle
206 */ 209 */
207static void 210static void
208next_phase(struct GNUNET_NAT_AutoHandle *ah); 211next_phase (struct GNUNET_NAT_AutoHandle *ah);
209 212
210 213
211static void 214static void
212process_stun_reply(struct sockaddr_in *answer, 215process_stun_reply (struct sockaddr_in *answer,
213 struct GNUNET_NAT_AutoHandle *ah) 216 struct GNUNET_NAT_AutoHandle *ah)
214{ 217{
215 ah->stun_ip = inet_ntoa(answer->sin_addr); 218 ah->stun_ip = inet_ntoa (answer->sin_addr);
216 ah->stun_port = ntohs(answer->sin_port); 219 ah->stun_port = ntohs (answer->sin_port);
217 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 220 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
218 "External IP is: %s , with port %u\n", 221 "External IP is: %s , with port %u\n",
219 ah->stun_ip, 222 ah->stun_ip,
220 ah->stun_port); 223 ah->stun_port);
221 next_phase(ah); 224 next_phase (ah);
222} 225}
223 226
224 227
@@ -226,22 +229,22 @@ process_stun_reply(struct sockaddr_in *answer,
226 * Function that terminates the test. 229 * Function that terminates the test.
227 */ 230 */
228static void 231static void
229stop_stun() 232stop_stun ()
230{ 233{
231 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 234 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
232 "Stopping STUN and quitting...\n"); 235 "Stopping STUN and quitting...\n");
233 /* Clean task */ 236 /* Clean task */
234 if (NULL != ltask4) 237 if (NULL != ltask4)
235 { 238 {
236 GNUNET_SCHEDULER_cancel(ltask4); 239 GNUNET_SCHEDULER_cancel (ltask4);
237 ltask4 = NULL; 240 ltask4 = NULL;
238 } 241 }
239 /* Clean socket */ 242 /* Clean socket */
240 if (NULL != lsock4) 243 if (NULL != lsock4)
241 { 244 {
242 GNUNET_NETWORK_socket_close(lsock4); 245 GNUNET_NETWORK_socket_close (lsock4);
243 lsock4 = NULL; 246 lsock4 = NULL;
244 } 247 }
245} 248}
246 249
247 250
@@ -252,7 +255,7 @@ stop_stun()
252 * @param cls 255 * @param cls
253 */ 256 */
254static void 257static void
255do_udp_read(void *cls) 258do_udp_read (void *cls)
256{ 259{
257 struct GNUNET_NAT_AutoHandle *ah = cls; 260 struct GNUNET_NAT_AutoHandle *ah = cls;
258 unsigned char reply_buf[1024]; 261 unsigned char reply_buf[1024];
@@ -260,51 +263,51 @@ do_udp_read(void *cls)
260 struct sockaddr_in answer; 263 struct sockaddr_in answer;
261 const struct GNUNET_SCHEDULER_TaskContext *tc; 264 const struct GNUNET_SCHEDULER_TaskContext *tc;
262 265
263 tc = GNUNET_SCHEDULER_get_task_context(); 266 tc = GNUNET_SCHEDULER_get_task_context ();
264 if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) && 267 if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
265 (GNUNET_NETWORK_fdset_isset(tc->read_ready, 268 (GNUNET_NETWORK_fdset_isset (tc->read_ready,
266 lsock4))) 269 lsock4)))
270 {
271 rlen = GNUNET_NETWORK_socket_recv (lsock4,
272 reply_buf,
273 sizeof(reply_buf));
274
275 // Lets handle the packet
276 memset (&answer, 0, sizeof(struct sockaddr_in));
277 if (ah->phase == AUTO_NAT_PUNCHED)
267 { 278 {
268 rlen = GNUNET_NETWORK_socket_recv(lsock4, 279 // Destroy the connection
269 reply_buf, 280 GNUNET_NETWORK_socket_close (lsock4);
270 sizeof(reply_buf)); 281 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
271 282 "The external server was able to connect back");
272 //Lets handle the packet 283 ah->connected_back = GNUNET_YES;
273 memset(&answer, 0, sizeof(struct sockaddr_in)); 284 next_phase (ah);
274 if (ah->phase == AUTO_NAT_PUNCHED) 285 }
275 { 286 else
276 //Destroy the connection 287 {
277 GNUNET_NETWORK_socket_close(lsock4); 288 if (GNUNET_OK ==
278 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 289 GNUNET_NAT_stun_handle_packet (reply_buf, rlen, &answer))
279 "The external server was able to connect back"); 290 {
280 ah->connected_back = GNUNET_YES; 291 // Process the answer
281 next_phase(ah); 292 process_stun_reply (&answer, ah);
282 } 293 }
283 else 294 else
284 { 295 {
285 if (GNUNET_OK == 296 next_phase (ah);
286 GNUNET_NAT_stun_handle_packet(reply_buf, rlen, &answer)) 297 }
287 {
288 //Process the answer
289 process_stun_reply(&answer, ah);
290 }
291 else
292 {
293 next_phase(ah);
294 }
295 }
296 } 298 }
299 }
297 else 300 else
301 {
302 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
303 "TIMEOUT while waiting for an answer\n");
304 if (ah->phase == AUTO_NAT_PUNCHED)
298 { 305 {
299 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 306 stop_stun ();
300 "TIMEOUT while waiting for an answer\n");
301 if (ah->phase == AUTO_NAT_PUNCHED)
302 {
303 stop_stun();
304 }
305
306 next_phase(ah);
307 } 307 }
308
309 next_phase (ah);
310 }
308} 311}
309 312
310 313
@@ -314,45 +317,45 @@ do_udp_read(void *cls)
314 * @return NULL on error 317 * @return NULL on error
315 */ 318 */
316static struct GNUNET_NETWORK_Handle * 319static struct GNUNET_NETWORK_Handle *
317bind_v4() 320bind_v4 ()
318{ 321{
319 struct GNUNET_NETWORK_Handle *ls; 322 struct GNUNET_NETWORK_Handle *ls;
320 struct sockaddr_in sa4; 323 struct sockaddr_in sa4;
321 int eno; 324 int eno;
322 325
323 memset(&sa4, 0, sizeof(sa4)); 326 memset (&sa4, 0, sizeof(sa4));
324 sa4.sin_family = AF_INET; 327 sa4.sin_family = AF_INET;
325 sa4.sin_port = htons(port); 328 sa4.sin_port = htons (port);
326#if HAVE_SOCKADDR_IN_SIN_LEN 329#if HAVE_SOCKADDR_IN_SIN_LEN
327 sa4.sin_len = sizeof(sa4); 330 sa4.sin_len = sizeof(sa4);
328#endif 331#endif
329 ls = GNUNET_NETWORK_socket_create(AF_INET, 332 ls = GNUNET_NETWORK_socket_create (AF_INET,
330 SOCK_DGRAM, 333 SOCK_DGRAM,
331 0); 334 0);
332 if (NULL == ls) 335 if (NULL == ls)
333 return NULL; 336 return NULL;
334 if (GNUNET_OK != 337 if (GNUNET_OK !=
335 GNUNET_NETWORK_socket_bind(ls, (const struct sockaddr *)&sa4, 338 GNUNET_NETWORK_socket_bind (ls, (const struct sockaddr *) &sa4,
336 sizeof(sa4))) 339 sizeof(sa4)))
337 { 340 {
338 eno = errno; 341 eno = errno;
339 GNUNET_NETWORK_socket_close(ls); 342 GNUNET_NETWORK_socket_close (ls);
340 errno = eno; 343 errno = eno;
341 return NULL; 344 return NULL;
342 } 345 }
343 return ls; 346 return ls;
344} 347}
345 348
346 349
347static void 350static void
348request_callback(void *cls, 351request_callback (void *cls,
349 enum GNUNET_NAT_StatusCode result) 352 enum GNUNET_NAT_StatusCode result)
350{ 353{
351 // struct GNUNET_NAT_AutoHandle *ah = cls; 354 // struct GNUNET_NAT_AutoHandle *ah = cls;
352 355
353 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 356 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
354 "Request callback: stop and quit\n"); 357 "Request callback: stop and quit\n");
355 stop_stun(); 358 stop_stun ();
356 359
357 // next_phase (ah); FIXME this always will be NULL, as called in test_stun() 360 // next_phase (ah); FIXME this always will be NULL, as called in test_stun()
358} 361}
@@ -367,22 +370,23 @@ request_callback(void *cls,
367 * @param emsg NULL on success, otherwise an error message 370 * @param emsg NULL on success, otherwise an error message
368 */ 371 */
369static void 372static void
370result_callback(void *cls, 373result_callback (void *cls,
371 enum GNUNET_NAT_StatusCode ret) 374 enum GNUNET_NAT_StatusCode ret)
372{ 375{
373 struct GNUNET_NAT_AutoHandle *ah = cls; 376 struct GNUNET_NAT_AutoHandle *ah = cls;
374 377
375 if (GNUNET_NAT_ERROR_SUCCESS == ret) 378 if (GNUNET_NAT_ERROR_SUCCESS == ret)
376 GNUNET_NAT_test_stop(ah->tst); 379 GNUNET_NAT_test_stop (ah->tst);
377 ah->tst = NULL; 380 ah->tst = NULL;
378 ah->ret = ret; 381 ah->ret = ret;
379 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 382 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
380 GNUNET_NAT_ERROR_SUCCESS == ret 383 GNUNET_NAT_ERROR_SUCCESS == ret
381 ? _("NAT traversal with ICMP Server succeeded.\n") 384 ? _ ("NAT traversal with ICMP Server succeeded.\n")
382 : _("NAT traversal with ICMP Server failed.\n")); 385 : _ ("NAT traversal with ICMP Server failed.\n"));
383 GNUNET_CONFIGURATION_set_value_string(ah->cfg, "nat", "ENABLE_ICMP_SERVER", 386 GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "ENABLE_ICMP_SERVER",
384 GNUNET_NAT_ERROR_SUCCESS == ret ? "NO" : "YES"); 387 GNUNET_NAT_ERROR_SUCCESS == ret ?
385 next_phase(ah); 388 "NO" : "YES");
389 next_phase (ah);
386} 390}
387 391
388 392
@@ -392,16 +396,16 @@ result_callback(void *cls,
392 * @param cls the `struct GNUNET_NAT_AutoHandle` 396 * @param cls the `struct GNUNET_NAT_AutoHandle`
393 */ 397 */
394static void 398static void
395reversal_test(void *cls) 399reversal_test (void *cls)
396{ 400{
397 struct GNUNET_NAT_AutoHandle *ah = cls; 401 struct GNUNET_NAT_AutoHandle *ah = cls;
398 402
399 ah->task = NULL; 403 ah->task = NULL;
400 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 404 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
401 _("Testing connection reversal with ICMP server.\n")); 405 _ ("Testing connection reversal with ICMP server.\n"));
402 GNUNET_RESOLVER_connect(ah->cfg); 406 GNUNET_RESOLVER_connect (ah->cfg);
403 ah->tst = GNUNET_NAT_test_start(ah->cfg, GNUNET_YES, 0, 0, TIMEOUT, 407 ah->tst = GNUNET_NAT_test_start (ah->cfg, GNUNET_YES, 0, 0, TIMEOUT,
404 &result_callback, ah); 408 &result_callback, ah);
405} 409}
406 410
407 411
@@ -414,9 +418,9 @@ reversal_test(void *cls)
414 * @param emsg NULL on success, otherwise an error message 418 * @param emsg NULL on success, otherwise an error message
415 */ 419 */
416static void 420static void
417set_external_ipv4(void *cls, 421set_external_ipv4 (void *cls,
418 const struct in_addr *addr, 422 const struct in_addr *addr,
419 enum GNUNET_NAT_StatusCode ret) 423 enum GNUNET_NAT_StatusCode ret)
420{ 424{
421 struct GNUNET_NAT_AutoHandle *ah = cls; 425 struct GNUNET_NAT_AutoHandle *ah = cls;
422 char buf[INET_ADDRSTRLEN]; 426 char buf[INET_ADDRSTRLEN];
@@ -424,35 +428,35 @@ set_external_ipv4(void *cls,
424 ah->eh = NULL; 428 ah->eh = NULL;
425 ah->ret = ret; 429 ah->ret = ret;
426 if (GNUNET_NAT_ERROR_SUCCESS != ret) 430 if (GNUNET_NAT_ERROR_SUCCESS != ret)
427 { 431 {
428 next_phase(ah); 432 next_phase (ah);
429 return; 433 return;
430 } 434 }
431 /* enable 'behind nat' */ 435 /* enable 'behind nat' */
432 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 436 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
433 _("Detected external IP `%s'\n"), 437 _ ("Detected external IP `%s'\n"),
434 inet_ntop(AF_INET, 438 inet_ntop (AF_INET,
435 addr, 439 addr,
436 buf, 440 buf,
437 sizeof(buf))); 441 sizeof(buf)));
438 GNUNET_CONFIGURATION_set_value_string(ah->cfg, "nat", "BEHIND_NAT", "YES"); 442 GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "BEHIND_NAT", "YES");
439 443
440 /* set external IP address */ 444 /* set external IP address */
441 if (NULL == inet_ntop(AF_INET, addr, buf, sizeof(buf))) 445 if (NULL == inet_ntop (AF_INET, addr, buf, sizeof(buf)))
442 { 446 {
443 GNUNET_break(0); 447 GNUNET_break (0);
444 /* actually, this should never happen, as the caller already executed just 448 /* actually, this should never happen, as the caller already executed just
445 * this check, but for consistency (eg: future changes in the caller) 449 * this check, but for consistency (eg: future changes in the caller)
446 * we still need to report this error... 450 * we still need to report this error...
447 */ 451 */
448 ah->ret = GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID; 452 ah->ret = GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID;
449 next_phase(ah); 453 next_phase (ah);
450 return; 454 return;
451 } 455 }
452 GNUNET_CONFIGURATION_set_value_string(ah->cfg, "nat", "EXTERNAL_ADDRESS", 456 GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "EXTERNAL_ADDRESS",
453 buf); 457 buf);
454 ah->upnp_set_external_address = GNUNET_YES; 458 ah->upnp_set_external_address = GNUNET_YES;
455 next_phase(ah); 459 next_phase (ah);
456} 460}
457 461
458 462
@@ -462,15 +466,15 @@ set_external_ipv4(void *cls,
462 * @param ah auto setup context 466 * @param ah auto setup context
463 */ 467 */
464static void 468static void
465test_external_ip(struct GNUNET_NAT_AutoHandle *ah) 469test_external_ip (struct GNUNET_NAT_AutoHandle *ah)
466{ 470{
467 if (GNUNET_NAT_ERROR_SUCCESS != ah->ret) 471 if (GNUNET_NAT_ERROR_SUCCESS != ah->ret)
468 next_phase(ah); 472 next_phase (ah);
469 473
470 // FIXME: CPS? 474 // FIXME: CPS?
471 /* try to detect external IP */ 475 /* try to detect external IP */
472 ah->eh = GNUNET_NAT_mini_get_external_ipv4(TIMEOUT, 476 ah->eh = GNUNET_NAT_mini_get_external_ipv4 (TIMEOUT,
473 &set_external_ipv4, ah); 477 &set_external_ipv4, ah);
474} 478}
475 479
476 480
@@ -480,53 +484,53 @@ test_external_ip(struct GNUNET_NAT_AutoHandle *ah)
480 * @param ah auto setup context 484 * @param ah auto setup context
481 */ 485 */
482static void 486static void
483test_stun(struct GNUNET_NAT_AutoHandle *ah) 487test_stun (struct GNUNET_NAT_AutoHandle *ah)
484{ 488{
485 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Running STUN test\n"); 489 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Running STUN test\n");
486 490
487 /* Get port from the configuration */ 491 /* Get port from the configuration */
488 if (GNUNET_OK != 492 if (GNUNET_OK !=
489 GNUNET_CONFIGURATION_get_value_number(ah->cfg, 493 GNUNET_CONFIGURATION_get_value_number (ah->cfg,
490 "transport-udp", 494 "transport-udp",
491 "PORT", 495 "PORT",
492 &port)) 496 &port))
493 { 497 {
494 port = 2086; 498 port = 2086;
495 } 499 }
496 500
497 //Lets create the socket 501 // Lets create the socket
498 lsock4 = bind_v4(); 502 lsock4 = bind_v4 ();
499 if (NULL == lsock4) 503 if (NULL == lsock4)
500 { 504 {
501 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "bind"); 505 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
502 next_phase(ah); 506 next_phase (ah);
503 return; 507 return;
504 } 508 }
505 else 509 else
506 { 510 {
507 //Lets call our function now when it accepts 511 // Lets call our function now when it accepts
508 ltask4 = GNUNET_SCHEDULER_add_read_net(NAT_SERVER_TIMEOUT, 512 ltask4 = GNUNET_SCHEDULER_add_read_net (NAT_SERVER_TIMEOUT,
509 lsock4, 513 lsock4,
510 &do_udp_read, 514 &do_udp_read,
511 ah); 515 ah);
512 } 516 }
513 517
514 518
515 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 519 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
516 "STUN service listens on port %u\n", 520 "STUN service listens on port %u\n",
517 (unsigned int)port); 521 (unsigned int) port);
518 if (GNUNET_NO == 522 if (GNUNET_NO ==
519 GNUNET_NAT_stun_make_request(stun_server, 523 GNUNET_NAT_stun_make_request (stun_server,
520 stun_port, 524 stun_port,
521 lsock4, 525 lsock4,
522 &request_callback, 526 &request_callback,
523 NULL)) 527 NULL))
524 { 528 {
525 /*An error happened*/ 529 /*An error happened*/
526 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "STUN error, stopping\n"); 530 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "STUN error, stopping\n");
527 stop_stun(); 531 stop_stun ();
528 next_phase(ah); 532 next_phase (ah);
529 } 533 }
530} 534}
531 535
532 536
@@ -544,13 +548,13 @@ test_stun(struct GNUNET_NAT_AutoHandle *ah)
544 * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort 548 * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort
545 */ 549 */
546static int 550static int
547process_if(void *cls, 551process_if (void *cls,
548 const char *name, 552 const char *name,
549 int isDefault, 553 int isDefault,
550 const struct sockaddr *addr, 554 const struct sockaddr *addr,
551 const struct sockaddr *broadcast_addr, 555 const struct sockaddr *broadcast_addr,
552 const struct sockaddr *netmask, 556 const struct sockaddr *netmask,
553 socklen_t addrlen) 557 socklen_t addrlen)
554{ 558{
555 struct GNUNET_NAT_AutoHandle *ah = cls; 559 struct GNUNET_NAT_AutoHandle *ah = cls;
556 const struct sockaddr_in *in; 560 const struct sockaddr_in *in;
@@ -558,46 +562,51 @@ process_if(void *cls,
558 562
559 563
560 if ((sizeof(struct sockaddr_in6) == addrlen) && 564 if ((sizeof(struct sockaddr_in6) == addrlen) &&
561 (0 != GNUNET_memcmp(&in6addr_loopback, &((const struct sockaddr_in6 *)addr)->sin6_addr)) && 565 (0 != GNUNET_memcmp (&in6addr_loopback, &((const struct
562 (!IN6_IS_ADDR_LINKLOCAL(&((const struct sockaddr_in6 *)addr)->sin6_addr))) 566 sockaddr_in6 *) addr)->
563 { 567 sin6_addr)) &&
564 ah->have_v6 = GNUNET_YES; 568 (! IN6_IS_ADDR_LINKLOCAL (&((const struct
565 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 569 sockaddr_in6 *) addr)->sin6_addr)))
566 _("This system has a global IPv6 address, setting IPv6 to supported.\n")); 570 {
571 ah->have_v6 = GNUNET_YES;
572 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
573 _ (
574 "This system has a global IPv6 address, setting IPv6 to supported.\n"));
567 575
568 return GNUNET_OK; 576 return GNUNET_OK;
569 } 577 }
570 if (addrlen != sizeof(struct sockaddr_in)) 578 if (addrlen != sizeof(struct sockaddr_in))
571 return GNUNET_OK; 579 return GNUNET_OK;
572 in = (const struct sockaddr_in *)addr; 580 in = (const struct sockaddr_in *) addr;
573 581
574 582
575 /* set internal IP address */ 583 /* set internal IP address */
576 if (NULL == inet_ntop(AF_INET, &in->sin_addr, buf, sizeof(buf))) 584 if (NULL == inet_ntop (AF_INET, &in->sin_addr, buf, sizeof(buf)))
577 { 585 {
578 GNUNET_break(0); 586 GNUNET_break (0);
579 return GNUNET_OK; 587 return GNUNET_OK;
580 } 588 }
581 GNUNET_CONFIGURATION_set_value_string(ah->cfg, "nat", "INTERNAL_ADDRESS", 589 GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "INTERNAL_ADDRESS",
582 buf); 590 buf);
583 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 591 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
584 _("Detected internal network address `%s'.\n"), 592 _ ("Detected internal network address `%s'.\n"),
585 buf); 593 buf);
586 594
587 595
588 ah->ret = GNUNET_NAT_ERROR_SUCCESS; 596 ah->ret = GNUNET_NAT_ERROR_SUCCESS;
589 597
590 /* Check if our internal IP is the same as the External detect by STUN*/ 598 /* Check if our internal IP is the same as the External detect by STUN*/
591 if (ah->stun_ip && (strcmp(buf, ah->stun_ip) == 0)) 599 if (ah->stun_ip && (strcmp (buf, ah->stun_ip) == 0))
592 { 600 {
593 ah->internal_ip_is_public = GNUNET_YES; 601 ah->internal_ip_is_public = GNUNET_YES;
594 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "A internal IP is the sameas the external"); 602 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
595 /* No need to continue*/ 603 "A internal IP is the sameas the external");
596 return GNUNET_SYSERR; 604 /* No need to continue*/
597 } 605 return GNUNET_SYSERR;
606 }
598 607
599 /* no need to continue iteration if we found the default */ 608 /* no need to continue iteration if we found the default */
600 if (!isDefault) 609 if (! isDefault)
601 return GNUNET_OK; 610 return GNUNET_OK;
602 else 611 else
603 return GNUNET_SYSERR; 612 return GNUNET_SYSERR;
@@ -610,15 +619,16 @@ process_if(void *cls,
610 * @param ah auto setup context 619 * @param ah auto setup context
611 */ 620 */
612static void 621static void
613test_local_ip(struct GNUNET_NAT_AutoHandle *ah) 622test_local_ip (struct GNUNET_NAT_AutoHandle *ah)
614{ 623{
615 ah->have_v6 = GNUNET_NO; 624 ah->have_v6 = GNUNET_NO;
616 ah->ret = GNUNET_NAT_ERROR_NO_VALID_IF_IP_COMBO; // reset to success if any of the IFs in below iterator has a valid IP 625 ah->ret = GNUNET_NAT_ERROR_NO_VALID_IF_IP_COMBO; // reset to success if any of the IFs in below iterator has a valid IP
617 GNUNET_OS_network_interfaces_list(&process_if, ah); 626 GNUNET_OS_network_interfaces_list (&process_if, ah);
618 627
619 GNUNET_CONFIGURATION_set_value_string(ah->cfg, "nat", "DISABLEV6", 628 GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "DISABLEV6",
620 (GNUNET_YES == ah->have_v6) ? "NO" : "YES"); 629 (GNUNET_YES == ah->have_v6) ? "NO" :
621 next_phase(ah); 630 "YES");
631 next_phase (ah);
622} 632}
623 633
624 634
@@ -630,15 +640,15 @@ test_local_ip(struct GNUNET_NAT_AutoHandle *ah)
630 * @param error error code 640 * @param error error code
631 */ 641 */
632static void 642static void
633mq_error_handler(void *cls, 643mq_error_handler (void *cls,
634 enum GNUNET_MQ_Error error) 644 enum GNUNET_MQ_Error error)
635{ 645{
636 struct GNUNET_NAT_AutoHandle *ah = cls; 646 struct GNUNET_NAT_AutoHandle *ah = cls;
637 647
638 GNUNET_MQ_destroy(ah->mq); 648 GNUNET_MQ_destroy (ah->mq);
639 ah->mq = NULL; 649 ah->mq = NULL;
640 /* wait a bit first? */ 650 /* wait a bit first? */
641 next_phase(ah); 651 next_phase (ah);
642} 652}
643 653
644 654
@@ -648,50 +658,50 @@ mq_error_handler(void *cls,
648 * @param ah auto setup context 658 * @param ah auto setup context
649 */ 659 */
650static void 660static void
651test_nat_punched(struct GNUNET_NAT_AutoHandle *ah) 661test_nat_punched (struct GNUNET_NAT_AutoHandle *ah)
652{ 662{
653 struct GNUNET_NAT_TestMessage *msg; 663 struct GNUNET_NAT_TestMessage *msg;
654 struct GNUNET_MQ_Envelope *env; 664 struct GNUNET_MQ_Envelope *env;
655 665
656 if (!ah->stun_ip) 666 if (! ah->stun_ip)
657 { 667 {
658 LOG(GNUNET_ERROR_TYPE_INFO, 668 LOG (GNUNET_ERROR_TYPE_INFO,
659 "We don't have a STUN IP"); 669 "We don't have a STUN IP");
660 next_phase(ah); 670 next_phase (ah);
661 return; 671 return;
662 } 672 }
663 673
664 LOG(GNUNET_ERROR_TYPE_INFO, 674 LOG (GNUNET_ERROR_TYPE_INFO,
665 "Asking gnunet-nat-server to connect to `%s'\n", 675 "Asking gnunet-nat-server to connect to `%s'\n",
666 ah->stun_ip); 676 ah->stun_ip);
667 ah->mq = GNUNET_CLIENT_connect(ah->cfg, 677 ah->mq = GNUNET_CLIENT_connect (ah->cfg,
668 "gnunet-nat-server", 678 "gnunet-nat-server",
669 NULL, 679 NULL,
670 &mq_error_handler, 680 &mq_error_handler,
671 ah); 681 ah);
672 if (NULL == ah->mq) 682 if (NULL == ah->mq)
673 { 683 {
674 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 684 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
675 _("Failed to connect to `gnunet-nat-server'\n")); 685 _ ("Failed to connect to `gnunet-nat-server'\n"));
676 next_phase(ah); 686 next_phase (ah);
677 return; 687 return;
678 } 688 }
679 env = GNUNET_MQ_msg(msg, 689 env = GNUNET_MQ_msg (msg,
680 GNUNET_MESSAGE_TYPE_NAT_TEST); 690 GNUNET_MESSAGE_TYPE_NAT_TEST);
681 msg->dst_ipv4 = inet_addr(ah->stun_ip); 691 msg->dst_ipv4 = inet_addr (ah->stun_ip);
682 msg->dport = htons(ah->stun_port); 692 msg->dport = htons (ah->stun_port);
683 msg->data = port; 693 msg->data = port;
684 msg->is_tcp = htonl((uint32_t)GNUNET_NO); 694 msg->is_tcp = htonl ((uint32_t) GNUNET_NO);
685 GNUNET_MQ_send(ah->mq, 695 GNUNET_MQ_send (ah->mq,
686 env); 696 env);
687 if (NULL != ltask4) 697 if (NULL != ltask4)
688 { 698 {
689 GNUNET_SCHEDULER_cancel(ltask4); 699 GNUNET_SCHEDULER_cancel (ltask4);
690 ltask4 = GNUNET_SCHEDULER_add_read_net(NAT_SERVER_TIMEOUT, 700 ltask4 = GNUNET_SCHEDULER_add_read_net (NAT_SERVER_TIMEOUT,
691 lsock4, 701 lsock4,
692 &do_udp_read, 702 &do_udp_read,
693 ah); 703 ah);
694 } 704 }
695} 705}
696 706
697 707
@@ -701,24 +711,25 @@ test_nat_punched(struct GNUNET_NAT_AutoHandle *ah)
701 * @param ah auto setup context 711 * @param ah auto setup context
702 */ 712 */
703static void 713static void
704test_upnpc(struct GNUNET_NAT_AutoHandle *ah) 714test_upnpc (struct GNUNET_NAT_AutoHandle *ah)
705{ 715{
706 int have_upnpc; 716 int have_upnpc;
707 717
708 if (GNUNET_NAT_ERROR_SUCCESS != ah->ret) 718 if (GNUNET_NAT_ERROR_SUCCESS != ah->ret)
709 next_phase(ah); 719 next_phase (ah);
710 720
711 // test if upnpc is available 721 // test if upnpc is available
712 have_upnpc = (GNUNET_SYSERR != 722 have_upnpc = (GNUNET_SYSERR !=
713 GNUNET_OS_check_helper_binary("upnpc", GNUNET_NO, NULL)); 723 GNUNET_OS_check_helper_binary ("upnpc", GNUNET_NO, NULL));
714 //FIXME: test if upnpc is actually working, that is, if transports start to work once we use UPnP 724 // FIXME: test if upnpc is actually working, that is, if transports start to work once we use UPnP
715 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 725 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
716 (have_upnpc) 726 (have_upnpc)
717 ? _("upnpc found, enabling its use\n") 727 ? _ ("upnpc found, enabling its use\n")
718 : _("upnpc not found\n")); 728 : _ ("upnpc not found\n"));
719 GNUNET_CONFIGURATION_set_value_string(ah->cfg, "nat", "ENABLE_UPNP", 729 GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "ENABLE_UPNP",
720 (GNUNET_YES == have_upnpc) ? "YES" : "NO"); 730 (GNUNET_YES == have_upnpc) ? "YES" :
721 next_phase(ah); 731 "NO");
732 next_phase (ah);
722} 733}
723 734
724 735
@@ -728,7 +739,7 @@ test_upnpc(struct GNUNET_NAT_AutoHandle *ah)
728 * @param ah auto setup context 739 * @param ah auto setup context
729 */ 740 */
730static void 741static void
731test_icmp_server(struct GNUNET_NAT_AutoHandle *ah) 742test_icmp_server (struct GNUNET_NAT_AutoHandle *ah)
732{ 743{
733 int ext_ip; 744 int ext_ip;
734 int nated; 745 int nated;
@@ -741,53 +752,55 @@ test_icmp_server(struct GNUNET_NAT_AutoHandle *ah)
741 binary = GNUNET_NO; 752 binary = GNUNET_NO;
742 753
743 tmp = NULL; 754 tmp = NULL;
744 helper = GNUNET_OS_get_libexec_binary_path("gnunet-helper-nat-server"); 755 helper = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-server");
745 if ((GNUNET_OK == 756 if ((GNUNET_OK ==
746 GNUNET_CONFIGURATION_get_value_string(ah->cfg, 757 GNUNET_CONFIGURATION_get_value_string (ah->cfg,
747 "nat", 758 "nat",
748 "EXTERNAL_ADDRESS", 759 "EXTERNAL_ADDRESS",
749 &tmp)) && 760 &tmp)) &&
750 (0 < strlen(tmp))) 761 (0 < strlen (tmp)))
751 { 762 {
752 ext_ip = GNUNET_OK; 763 ext_ip = GNUNET_OK;
753 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 764 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
754 _("test_icmp_server not possible, as we have no public IPv4 address\n")); 765 _ (
755 } 766 "test_icmp_server not possible, as we have no public IPv4 address\n"));
767 }
756 else 768 else
757 goto err; 769 goto err;
758 770
759 if (GNUNET_YES == 771 if (GNUNET_YES ==
760 GNUNET_CONFIGURATION_get_value_yesno(ah->cfg, 772 GNUNET_CONFIGURATION_get_value_yesno (ah->cfg,
761 "nat", 773 "nat",
762 "BEHIND_NAT")) 774 "BEHIND_NAT"))
763 { 775 {
764 nated = GNUNET_YES; 776 nated = GNUNET_YES;
765 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 777 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
766 _("test_icmp_server not possible, as we are not behind NAT\n")); 778 _ (
767 } 779 "test_icmp_server not possible, as we are not behind NAT\n"));
780 }
768 else 781 else
769 goto err; 782 goto err;
770 783
771 if (GNUNET_YES == 784 if (GNUNET_YES ==
772 GNUNET_OS_check_helper_binary(helper, 785 GNUNET_OS_check_helper_binary (helper,
773 GNUNET_YES, 786 GNUNET_YES,
774 "-d 127.0.0.1")) 787 "-d 127.0.0.1"))
775 { 788 {
776 binary = GNUNET_OK; // use localhost as source for that one udp-port, ok for testing 789 binary = GNUNET_OK; // use localhost as source for that one udp-port, ok for testing
777 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 790 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
778 _("No working gnunet-helper-nat-server found\n")); 791 _ ("No working gnunet-helper-nat-server found\n"));
779 } 792 }
780err: 793err:
781 GNUNET_free_non_null(tmp); 794 GNUNET_free_non_null (tmp);
782 GNUNET_free(helper); 795 GNUNET_free (helper);
783 796
784 if ((GNUNET_OK == ext_ip) && 797 if ((GNUNET_OK == ext_ip) &&
785 (GNUNET_YES == nated) && 798 (GNUNET_YES == nated) &&
786 (GNUNET_OK == binary)) 799 (GNUNET_OK == binary))
787 ah->task = GNUNET_SCHEDULER_add_now(&reversal_test, 800 ah->task = GNUNET_SCHEDULER_add_now (&reversal_test,
788 ah); 801 ah);
789 else 802 else
790 next_phase(ah); 803 next_phase (ah);
791} 804}
792 805
793 806
@@ -797,51 +810,53 @@ err:
797 * @param ah auto setup context 810 * @param ah auto setup context
798 */ 811 */
799static void 812static void
800test_icmp_client(struct GNUNET_NAT_AutoHandle *ah) 813test_icmp_client (struct GNUNET_NAT_AutoHandle *ah)
801{ 814{
802 char *tmp; 815 char *tmp;
803 char *helper; 816 char *helper;
804 817
805 tmp = NULL; 818 tmp = NULL;
806 helper = GNUNET_OS_get_libexec_binary_path("gnunet-helper-nat-client"); 819 helper = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-client");
807 if ((GNUNET_OK == 820 if ((GNUNET_OK ==
808 GNUNET_CONFIGURATION_get_value_string(ah->cfg, 821 GNUNET_CONFIGURATION_get_value_string (ah->cfg,
809 "nat", 822 "nat",
810 "INTERNAL_ADDRESS", 823 "INTERNAL_ADDRESS",
811 &tmp)) && 824 &tmp)) &&
812 (0 < strlen(tmp))) 825 (0 < strlen (tmp)))
813 { 826 {
814 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 827 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
815 _("test_icmp_client not possible, as we have no internal IPv4 address\n")); 828 _ (
816 } 829 "test_icmp_client not possible, as we have no internal IPv4 address\n"));
830 }
817 else 831 else
818 goto err; 832 goto err;
819 833
820 if (GNUNET_YES != 834 if (GNUNET_YES !=
821 GNUNET_CONFIGURATION_get_value_yesno(ah->cfg, 835 GNUNET_CONFIGURATION_get_value_yesno (ah->cfg,
822 "nat", 836 "nat",
823 "BEHIND_NAT")) 837 "BEHIND_NAT"))
824 { 838 {
825 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 839 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
826 _("test_icmp_server not possible, as we are not behind NAT\n")); 840 _ (
827 } 841 "test_icmp_server not possible, as we are not behind NAT\n"));
842 }
828 else 843 else
829 goto err; 844 goto err;
830 845
831 if (GNUNET_YES == 846 if (GNUNET_YES ==
832 GNUNET_OS_check_helper_binary(helper, 847 GNUNET_OS_check_helper_binary (helper,
833 GNUNET_YES, 848 GNUNET_YES,
834 "-d 127.0.0.1 127.0.0.2 42")) 849 "-d 127.0.0.1 127.0.0.2 42"))
835 { 850 {
836 // none of these parameters are actually used in privilege testing mode 851 // none of these parameters are actually used in privilege testing mode
837 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 852 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
838 _("No working gnunet-helper-nat-server found\n")); 853 _ ("No working gnunet-helper-nat-server found\n"));
839 } 854 }
840err: 855err:
841 GNUNET_free_non_null(tmp); 856 GNUNET_free_non_null (tmp);
842 GNUNET_free(helper); 857 GNUNET_free (helper);
843 858
844 next_phase(ah); 859 next_phase (ah);
845} 860}
846 861
847 862
@@ -849,161 +864,161 @@ err:
849 * Run the next phase of the auto test. 864 * Run the next phase of the auto test.
850 */ 865 */
851static void 866static void
852next_phase(struct GNUNET_NAT_AutoHandle *ah) 867next_phase (struct GNUNET_NAT_AutoHandle *ah)
853{ 868{
854 struct GNUNET_CONFIGURATION_Handle *diff; 869 struct GNUNET_CONFIGURATION_Handle *diff;
855 870
856 ah->phase++; 871 ah->phase++;
857 switch (ah->phase) 872 switch (ah->phase)
873 {
874 case AUTO_INIT:
875 GNUNET_assert (0);
876 break;
877
878 case AUTO_EXTERNAL_IP:
879 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
880 "Will run AUTO_EXTERNAL_IP\n");
881 test_external_ip (ah);
882 break;
883
884 case AUTO_STUN:
885 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
886 "Will run AUTO_STUN\n");
887 test_stun (ah);
888 break;
889
890 case AUTO_LOCAL_IP:
891 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
892 "Will run AUTO_LOCAL_IP\n");
893 test_local_ip (ah);
894 break;
895
896 case AUTO_NAT_PUNCHED:
897 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
898 "Will run AUTO_NAT_PUNCHED\n");
899 test_nat_punched (ah);
900 break;
901
902 case AUTO_UPNPC:
903 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
904 "Will run AUTO_UPNPC\n");
905 test_upnpc (ah);
906 break;
907
908 case AUTO_ICMP_SERVER:
909 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
910 "Will run AUTO_ICMP_SERVER\n");
911 test_icmp_server (ah);
912 break;
913
914 case AUTO_ICMP_CLIENT:
915 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
916 "Will run AUTO_ICMP_CLIENT\n");
917 test_icmp_client (ah);
918 break;
919
920 case AUTO_DONE:
921 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
922 "Done with tests\n");
923 if (! ah->internal_ip_is_public)
858 { 924 {
859 case AUTO_INIT: 925 GNUNET_CONFIGURATION_set_value_string (ah->cfg,
860 GNUNET_assert(0); 926 "nat",
861 break; 927 "BEHIND_NAT",
862 928 "YES");
863 case AUTO_EXTERNAL_IP: 929
864 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 930 if (ah->connected_back)
865 "Will run AUTO_EXTERNAL_IP\n"); 931 {
866 test_external_ip(ah); 932 GNUNET_CONFIGURATION_set_value_string (ah->cfg,
867 break; 933 "nat",
868 934 "PUNCHED_NAT",
869 case AUTO_STUN: 935 "YES");
870 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 936 }
871 "Will run AUTO_STUN\n"); 937 else
872 test_stun(ah); 938 {
873 break; 939 GNUNET_CONFIGURATION_set_value_string (ah->cfg,
874 940 "nat",
875 case AUTO_LOCAL_IP: 941 "PUNCHED_NAT",
876 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 942 "NO");
877 "Will run AUTO_LOCAL_IP\n"); 943 }
878 test_local_ip(ah); 944
879 break; 945 if (ah->stun_ip)
880 946 {
881 case AUTO_NAT_PUNCHED: 947 GNUNET_CONFIGURATION_set_value_string (ah->cfg,
882 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 948 "nat",
883 "Will run AUTO_NAT_PUNCHED\n"); 949 "EXTERNAL_ADDRESS",
884 test_nat_punched(ah); 950 ah->stun_ip);
885 break; 951 if (ah->connected_back)
886 952 {
887 case AUTO_UPNPC: 953 ah->type = GNUNET_NAT_TYPE_STUN_PUNCHED_NAT;
888 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 954 GNUNET_CONFIGURATION_set_value_string (ah->cfg,
889 "Will run AUTO_UPNPC\n"); 955 "nat",
890 test_upnpc(ah); 956 "USE_STUN",
891 break; 957 "YES");
892 958 }
893 case AUTO_ICMP_SERVER: 959 else
894 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
895 "Will run AUTO_ICMP_SERVER\n");
896 test_icmp_server(ah);
897 break;
898
899 case AUTO_ICMP_CLIENT:
900 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
901 "Will run AUTO_ICMP_CLIENT\n");
902 test_icmp_client(ah);
903 break;
904
905 case AUTO_DONE:
906 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
907 "Done with tests\n");
908 if (!ah->internal_ip_is_public)
909 { 960 {
910 GNUNET_CONFIGURATION_set_value_string(ah->cfg, 961 ah->type = GNUNET_NAT_TYPE_UNREACHABLE_NAT;
911 "nat", 962 GNUNET_CONFIGURATION_set_value_string (ah->cfg,
912 "BEHIND_NAT", 963 "nat",
913 "YES"); 964 "USE_STUN",
914 965 "NO");
915 if (ah->connected_back)
916 {
917 GNUNET_CONFIGURATION_set_value_string(ah->cfg,
918 "nat",
919 "PUNCHED_NAT",
920 "YES");
921 }
922 else
923 {
924 GNUNET_CONFIGURATION_set_value_string(ah->cfg,
925 "nat",
926 "PUNCHED_NAT",
927 "NO");
928 }
929
930 if (ah->stun_ip)
931 {
932 GNUNET_CONFIGURATION_set_value_string(ah->cfg,
933 "nat",
934 "EXTERNAL_ADDRESS",
935 ah->stun_ip);
936 if (ah->connected_back)
937 {
938 ah->type = GNUNET_NAT_TYPE_STUN_PUNCHED_NAT;
939 GNUNET_CONFIGURATION_set_value_string(ah->cfg,
940 "nat",
941 "USE_STUN",
942 "YES");
943 }
944 else
945 {
946 ah->type = GNUNET_NAT_TYPE_UNREACHABLE_NAT;
947 GNUNET_CONFIGURATION_set_value_string(ah->cfg,
948 "nat",
949 "USE_STUN",
950 "NO");
951 }
952 }
953 if (0 != ah->stun_port)
954 {
955 GNUNET_CONFIGURATION_set_value_number(ah->cfg,
956 "transport-udp",
957 "ADVERTISED_PORT",
958 ah->stun_port);
959 }
960 } 966 }
967 }
968 if (0 != ah->stun_port)
969 {
970 GNUNET_CONFIGURATION_set_value_number (ah->cfg,
971 "transport-udp",
972 "ADVERTISED_PORT",
973 ah->stun_port);
974 }
975 }
976 else
977 {
978 // The internal IP is the same as public, but we didn't got a incoming connection
979 if (ah->connected_back)
980 {
981 ah->type = GNUNET_NAT_TYPE_NO_NAT;
982 GNUNET_CONFIGURATION_set_value_string (ah->cfg,
983 "nat",
984 "BEHIND_NAT",
985 "NO");
986 }
961 else 987 else
988 {
989 GNUNET_CONFIGURATION_set_value_string (ah->cfg,
990 "nat",
991 "BEHIND_NAT",
992 "YES");
993 ah->type = GNUNET_NAT_TYPE_UNREACHABLE_NAT;
994 if (ah->stun_ip)
995 {
996 GNUNET_CONFIGURATION_set_value_string (ah->cfg,
997 "nat",
998 "EXTERNAL_ADDRESS",
999 ah->stun_ip);
1000 }
1001 if (0 != ah->stun_port)
962 { 1002 {
963 //The internal IP is the same as public, but we didn't got a incoming connection 1003 GNUNET_CONFIGURATION_set_value_number (ah->cfg,
964 if (ah->connected_back) 1004 "transport-udp",
965 { 1005 "ADVERTISED_PORT",
966 ah->type = GNUNET_NAT_TYPE_NO_NAT; 1006 ah->stun_port);
967 GNUNET_CONFIGURATION_set_value_string(ah->cfg,
968 "nat",
969 "BEHIND_NAT",
970 "NO");
971 }
972 else
973 {
974 GNUNET_CONFIGURATION_set_value_string(ah->cfg,
975 "nat",
976 "BEHIND_NAT",
977 "YES");
978 ah->type = GNUNET_NAT_TYPE_UNREACHABLE_NAT;
979 if (ah->stun_ip)
980 {
981 GNUNET_CONFIGURATION_set_value_string(ah->cfg,
982 "nat",
983 "EXTERNAL_ADDRESS",
984 ah->stun_ip);
985 }
986 if (0 != ah->stun_port)
987 {
988 GNUNET_CONFIGURATION_set_value_number(ah->cfg,
989 "transport-udp",
990 "ADVERTISED_PORT",
991 ah->stun_port);
992 }
993 }
994 } 1007 }
1008 }
1009 }
995 1010
996 diff = GNUNET_CONFIGURATION_get_diff(ah->initial_cfg, 1011 diff = GNUNET_CONFIGURATION_get_diff (ah->initial_cfg,
997 ah->cfg); 1012 ah->cfg);
998 1013
999 1014
1000 ah->fin_cb(ah->fin_cb_cls, 1015 ah->fin_cb (ah->fin_cb_cls,
1001 diff, 1016 diff,
1002 ah->ret, 1017 ah->ret,
1003 ah->type); 1018 ah->type);
1004 GNUNET_CONFIGURATION_destroy(diff); 1019 GNUNET_CONFIGURATION_destroy (diff);
1005 GNUNET_NAT_autoconfig_cancel(ah); 1020 GNUNET_NAT_autoconfig_cancel (ah);
1006 } 1021 }
1007} 1022}
1008 1023
1009 1024
@@ -1017,26 +1032,26 @@ next_phase(struct GNUNET_NAT_AutoHandle *ah)
1017 * @return handle to cancel operation 1032 * @return handle to cancel operation
1018 */ 1033 */
1019struct GNUNET_NAT_AutoHandle * 1034struct GNUNET_NAT_AutoHandle *
1020GNUNET_NAT_autoconfig_start(const struct GNUNET_CONFIGURATION_Handle *cfg, 1035GNUNET_NAT_autoconfig_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
1021 GNUNET_NAT_AutoResultCallback cb, 1036 GNUNET_NAT_AutoResultCallback cb,
1022 void *cb_cls) 1037 void *cb_cls)
1023{ 1038{
1024 struct GNUNET_NAT_AutoHandle *ah; 1039 struct GNUNET_NAT_AutoHandle *ah;
1025 1040
1026 ah = GNUNET_new(struct GNUNET_NAT_AutoHandle); 1041 ah = GNUNET_new (struct GNUNET_NAT_AutoHandle);
1027 ah->fin_cb = cb; 1042 ah->fin_cb = cb;
1028 ah->fin_cb_cls = cb_cls; 1043 ah->fin_cb_cls = cb_cls;
1029 ah->ret = GNUNET_NAT_ERROR_SUCCESS; 1044 ah->ret = GNUNET_NAT_ERROR_SUCCESS;
1030 ah->cfg = GNUNET_CONFIGURATION_dup(cfg); 1045 ah->cfg = GNUNET_CONFIGURATION_dup (cfg);
1031 ah->initial_cfg = GNUNET_CONFIGURATION_dup(cfg); 1046 ah->initial_cfg = GNUNET_CONFIGURATION_dup (cfg);
1032 1047
1033 /* never use loopback addresses if user wanted autoconfiguration */ 1048 /* never use loopback addresses if user wanted autoconfiguration */
1034 GNUNET_CONFIGURATION_set_value_string(ah->cfg, 1049 GNUNET_CONFIGURATION_set_value_string (ah->cfg,
1035 "nat", 1050 "nat",
1036 "USE_LOCALADDR", 1051 "USE_LOCALADDR",
1037 "NO"); 1052 "NO");
1038 1053
1039 next_phase(ah); 1054 next_phase (ah);
1040 return ah; 1055 return ah;
1041} 1056}
1042 1057
@@ -1047,31 +1062,31 @@ GNUNET_NAT_autoconfig_start(const struct GNUNET_CONFIGURATION_Handle *cfg,
1047 * @param ah handle for operation to abort 1062 * @param ah handle for operation to abort
1048 */ 1063 */
1049void 1064void
1050GNUNET_NAT_autoconfig_cancel(struct GNUNET_NAT_AutoHandle *ah) 1065GNUNET_NAT_autoconfig_cancel (struct GNUNET_NAT_AutoHandle *ah)
1051{ 1066{
1052 if (NULL != ah->tst) 1067 if (NULL != ah->tst)
1053 { 1068 {
1054 GNUNET_NAT_test_stop(ah->tst); 1069 GNUNET_NAT_test_stop (ah->tst);
1055 ah->tst = NULL; 1070 ah->tst = NULL;
1056 } 1071 }
1057 if (NULL != ah->eh) 1072 if (NULL != ah->eh)
1058 { 1073 {
1059 GNUNET_NAT_mini_get_external_ipv4_cancel(ah->eh); 1074 GNUNET_NAT_mini_get_external_ipv4_cancel (ah->eh);
1060 ah->eh = NULL; 1075 ah->eh = NULL;
1061 } 1076 }
1062 if (NULL != ah->mq) 1077 if (NULL != ah->mq)
1063 { 1078 {
1064 GNUNET_MQ_destroy(ah->mq); 1079 GNUNET_MQ_destroy (ah->mq);
1065 ah->mq = NULL; 1080 ah->mq = NULL;
1066 } 1081 }
1067 if (NULL != ah->task) 1082 if (NULL != ah->task)
1068 { 1083 {
1069 GNUNET_SCHEDULER_cancel(ah->task); 1084 GNUNET_SCHEDULER_cancel (ah->task);
1070 ah->task = NULL; 1085 ah->task = NULL;
1071 } 1086 }
1072 GNUNET_CONFIGURATION_destroy(ah->cfg); 1087 GNUNET_CONFIGURATION_destroy (ah->cfg);
1073 GNUNET_CONFIGURATION_destroy(ah->initial_cfg); 1088 GNUNET_CONFIGURATION_destroy (ah->initial_cfg);
1074 GNUNET_free(ah); 1089 GNUNET_free (ah);
1075} 1090}
1076 1091
1077 1092