diff options
Diffstat (limited to 'src/nat/nat_auto.c')
-rw-r--r-- | src/nat/nat_auto.c | 74 |
1 files changed, 39 insertions, 35 deletions
diff --git a/src/nat/nat_auto.c b/src/nat/nat_auto.c index a76bb0d1d..9d0ee5516 100644 --- a/src/nat/nat_auto.c +++ b/src/nat/nat_auto.c | |||
@@ -236,16 +236,21 @@ process_stun_reply(struct sockaddr_in* answer, struct GNUNET_NAT_AutoHandle *ah) | |||
236 | static void | 236 | static void |
237 | stop_stun () | 237 | stop_stun () |
238 | { | 238 | { |
239 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stopping NAT and quitting...\n"); | 239 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stopping STUN and quitting...\n"); |
240 | 240 | ||
241 | //Clean task | 241 | /* Clean task */ |
242 | if(NULL != ltask4) | 242 | if(NULL != ltask4) |
243 | { | ||
243 | GNUNET_SCHEDULER_cancel (ltask4); | 244 | GNUNET_SCHEDULER_cancel (ltask4); |
245 | ltask4 = NULL; | ||
246 | } | ||
244 | 247 | ||
245 | //Clean socket | 248 | /* Clean socket */ |
246 | if(NULL != lsock4) | 249 | if(NULL != lsock4) |
250 | { | ||
247 | GNUNET_NETWORK_socket_close (lsock4); | 251 | GNUNET_NETWORK_socket_close (lsock4); |
248 | 252 | lsock4 = NULL; | |
253 | } | ||
249 | } | 254 | } |
250 | 255 | ||
251 | /** | 256 | /** |
@@ -271,47 +276,40 @@ do_udp_read (void *cls, | |||
271 | { | 276 | { |
272 | rlen = GNUNET_NETWORK_socket_recv (lsock4, reply_buf, sizeof (reply_buf)); | 277 | rlen = GNUNET_NETWORK_socket_recv (lsock4, reply_buf, sizeof (reply_buf)); |
273 | 278 | ||
274 | |||
275 | //Lets handle the packet | 279 | //Lets handle the packet |
276 | memset(&answer, 0, sizeof(struct sockaddr_in)); | 280 | memset(&answer, 0, sizeof(struct sockaddr_in)); |
277 | |||
278 | |||
279 | |||
280 | |||
281 | |||
282 | if(ah->phase == AUTO_NAT_PUNCHED) | 281 | if(ah->phase == AUTO_NAT_PUNCHED) |
283 | { | 282 | { |
284 | //Destroy the connection | 283 | //Destroy the connection |
285 | GNUNET_NETWORK_socket_close (lsock4); | 284 | GNUNET_NETWORK_socket_close (lsock4); |
286 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "The external server was able to connect back"); | 285 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
286 | "The external server was able to connect back"); | ||
287 | ah->connected_back = GNUNET_YES; | 287 | ah->connected_back = GNUNET_YES; |
288 | next_phase (ah); | 288 | next_phase (ah); |
289 | } | 289 | } |
290 | else | 290 | else |
291 | { | 291 | { |
292 | if(GNUNET_OK == GNUNET_NAT_stun_handle_packet(reply_buf,rlen, &answer)) | 292 | if (GNUNET_OK == GNUNET_NAT_stun_handle_packet (reply_buf, rlen, &answer)) |
293 | { | 293 | { |
294 | //Process the answer | 294 | //Process the answer |
295 | process_stun_reply(&answer, ah); | 295 | process_stun_reply (&answer, ah); |
296 | |||
297 | } | 296 | } |
298 | else | 297 | else |
299 | { | 298 | { |
300 | next_phase (ah); | 299 | next_phase (ah); |
301 | } | 300 | } |
302 | } | 301 | } |
303 | |||
304 | |||
305 | } | 302 | } |
306 | else | 303 | else |
307 | { | 304 | { |
308 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "TIMEOUT while aiting for an answer"); | 305 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
309 | if(ah->phase == AUTO_NAT_PUNCHED) | 306 | "TIMEOUT while waiting for an answer\n"); |
307 | if (ah->phase == AUTO_NAT_PUNCHED) | ||
310 | { | 308 | { |
311 | stop_stun(); | 309 | stop_stun(); |
312 | } | 310 | } |
313 | 311 | ||
314 | next_phase(ah); | 312 | next_phase (ah); |
315 | } | 313 | } |
316 | 314 | ||
317 | 315 | ||
@@ -357,14 +355,15 @@ bind_v4 () | |||
357 | 355 | ||
358 | 356 | ||
359 | 357 | ||
360 | static void request_callback(void *cls, | 358 | static void request_callback (void *cls, |
361 | enum GNUNET_NAT_StatusCode result) | 359 | enum GNUNET_NAT_StatusCode result) |
362 | { | 360 | { |
363 | struct GNUNET_NAT_AutoHandle *ah = cls; | 361 | // struct GNUNET_NAT_AutoHandle *ah = cls; |
364 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stopping NAT and quitting...\n"); | 362 | |
365 | stop_stun(); | 363 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Request callback: stop and quit\n"); |
364 | stop_stun (); | ||
366 | 365 | ||
367 | next_phase(ah); | 366 | // next_phase (ah); FIXME this always will be NULL, as called in test_stun() |
368 | }; | 367 | }; |
369 | 368 | ||
370 | 369 | ||
@@ -498,7 +497,7 @@ static void | |||
498 | test_stun (struct GNUNET_NAT_AutoHandle *ah) | 497 | test_stun (struct GNUNET_NAT_AutoHandle *ah) |
499 | { | 498 | { |
500 | 499 | ||
501 | GNUNET_log (GNUNET_ERROR_TYPE_INFO,"Running STUN test"); | 500 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Running STUN test\n"); |
502 | 501 | ||
503 | /* Get port from the configuration */ | 502 | /* Get port from the configuration */ |
504 | if (GNUNET_OK != | 503 | if (GNUNET_OK != |
@@ -530,14 +529,15 @@ test_stun (struct GNUNET_NAT_AutoHandle *ah) | |||
530 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 529 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
531 | "STUN service listens on port %u\n", | 530 | "STUN service listens on port %u\n", |
532 | port); | 531 | port); |
533 | if( GNUNET_NO == GNUNET_NAT_stun_make_request(stun_server, stun_port, lsock4, &request_callback, NULL)) | 532 | if (GNUNET_NO == GNUNET_NAT_stun_make_request (stun_server, stun_port, |
533 | lsock4, &request_callback, | ||
534 | NULL)) | ||
534 | { | 535 | { |
535 | /*An error happened*/ | 536 | /*An error happened*/ |
536 | stop_stun(); | 537 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "STUN error, stopping\n"); |
537 | next_phase(ah); | 538 | stop_stun (); |
539 | next_phase (ah); | ||
538 | } | 540 | } |
539 | |||
540 | |||
541 | } | 541 | } |
542 | 542 | ||
543 | 543 | ||
@@ -648,7 +648,7 @@ test_nat_punched (struct GNUNET_NAT_AutoHandle *ah) | |||
648 | struct GNUNET_NAT_TestMessage msg; | 648 | struct GNUNET_NAT_TestMessage msg; |
649 | 649 | ||
650 | 650 | ||
651 | if(ah->stun_ip) | 651 | if (ah->stun_ip) |
652 | { | 652 | { |
653 | LOG (GNUNET_ERROR_TYPE_INFO, | 653 | LOG (GNUNET_ERROR_TYPE_INFO, |
654 | "Asking gnunet-nat-server to connect to `%s'\n", | 654 | "Asking gnunet-nat-server to connect to `%s'\n", |
@@ -675,8 +675,12 @@ test_nat_punched (struct GNUNET_NAT_AutoHandle *ah) | |||
675 | NAT_SERVER_TIMEOUT, | 675 | NAT_SERVER_TIMEOUT, |
676 | GNUNET_YES, NULL, | 676 | GNUNET_YES, NULL, |
677 | NULL)); | 677 | NULL)); |
678 | ltask4 = GNUNET_SCHEDULER_add_read_net (NAT_SERVER_TIMEOUT, | 678 | if (NULL != ltask4) |
679 | lsock4, &do_udp_read, ah); | 679 | { |
680 | GNUNET_SCHEDULER_cancel (ltask4); | ||
681 | ltask4 = GNUNET_SCHEDULER_add_read_net (NAT_SERVER_TIMEOUT, | ||
682 | lsock4, &do_udp_read, ah); | ||
683 | } | ||
680 | 684 | ||
681 | } | 685 | } |
682 | else | 686 | else |
@@ -847,7 +851,7 @@ next_phase (struct GNUNET_NAT_AutoHandle *ah) | |||
847 | test_local_ip (ah); | 851 | test_local_ip (ah); |
848 | break; | 852 | break; |
849 | case AUTO_NAT_PUNCHED: | 853 | case AUTO_NAT_PUNCHED: |
850 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Will run GNUNET_ERROR_TYPE_DEBUG\n"); | 854 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Will run AUTO_NAT_PUNCHED\n"); |
851 | test_nat_punched (ah); | 855 | test_nat_punched (ah); |
852 | break; | 856 | break; |
853 | case AUTO_UPNPC: | 857 | case AUTO_UPNPC: |