diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-06-24 15:31:56 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-06-24 15:31:56 +0000 |
commit | 2e564787f3d59329e25a5f7d3de1097a97139c74 (patch) | |
tree | a8470a5e140c50a14be8a28fdd7abd3fe74ccbb4 /src | |
parent | 6fd39b3338a843f91246305ae442ec18d296a0d1 (diff) | |
download | gnunet-2e564787f3d59329e25a5f7d3de1097a97139c74.tar.gz gnunet-2e564787f3d59329e25a5f7d3de1097a97139c74.zip |
migrate nat_auto to MQ
Diffstat (limited to 'src')
-rw-r--r-- | src/nat/nat_auto.c | 305 |
1 files changed, 193 insertions, 112 deletions
diff --git a/src/nat/nat_auto.c b/src/nat/nat_auto.c index 6d5b82cc9..061d0cbe6 100644 --- a/src/nat/nat_auto.c +++ b/src/nat/nat_auto.c | |||
@@ -132,14 +132,18 @@ struct GNUNET_NAT_AutoHandle | |||
132 | /** | 132 | /** |
133 | * Task identifier for the timeout. | 133 | * Task identifier for the timeout. |
134 | */ | 134 | */ |
135 | struct GNUNET_SCHEDULER_Task * task; | 135 | struct GNUNET_SCHEDULER_Task *task; |
136 | |||
137 | /** | ||
138 | * Message queue to the gnunet-nat-server. | ||
139 | */ | ||
140 | struct GNUNET_MQ_Handle *mq; | ||
136 | 141 | ||
137 | /** | 142 | /** |
138 | * Where are we in the test? | 143 | * Where are we in the test? |
139 | */ | 144 | */ |
140 | enum AutoPhase phase; | 145 | enum AutoPhase phase; |
141 | 146 | ||
142 | |||
143 | /** | 147 | /** |
144 | * Situation of the NAT | 148 | * Situation of the NAT |
145 | */ | 149 | */ |
@@ -161,10 +165,11 @@ struct GNUNET_NAT_AutoHandle | |||
161 | int connected_back; | 165 | int connected_back; |
162 | 166 | ||
163 | /** | 167 | /** |
164 | * Address detected by STUN | 168 | * Address detected by STUN |
165 | */ | 169 | */ |
166 | char* stun_ip; | 170 | char *stun_ip; |
167 | int stun_port; | 171 | |
172 | unsigned int stun_port; | ||
168 | 173 | ||
169 | /** | 174 | /** |
170 | * Internal IP is the same as the public one ? | 175 | * Internal IP is the same as the public one ? |
@@ -178,23 +183,15 @@ struct GNUNET_NAT_AutoHandle | |||
178 | }; | 183 | }; |
179 | 184 | ||
180 | 185 | ||
181 | |||
182 | |||
183 | |||
184 | |||
185 | /** | 186 | /** |
186 | * The listen socket of the service for IPv4 | 187 | * The listen socket of the service for IPv4 |
187 | */ | 188 | */ |
188 | static struct GNUNET_NETWORK_Handle *lsock4; | 189 | static struct GNUNET_NETWORK_Handle *lsock4; |
189 | 190 | ||
190 | |||
191 | /** | 191 | /** |
192 | * The listen task ID for IPv4 | 192 | * The listen task ID for IPv4 |
193 | */ | 193 | */ |
194 | static struct GNUNET_SCHEDULER_Task * ltask4; | 194 | static struct GNUNET_SCHEDULER_Task *ltask4; |
195 | |||
196 | |||
197 | |||
198 | 195 | ||
199 | /** | 196 | /** |
200 | * The port the test service is running on (default 7895) | 197 | * The port the test service is running on (default 7895) |
@@ -202,8 +199,8 @@ static struct GNUNET_SCHEDULER_Task * ltask4; | |||
202 | static unsigned long long port = 7895; | 199 | static unsigned long long port = 7895; |
203 | 200 | ||
204 | static char *stun_server = "stun.ekiga.net"; | 201 | static char *stun_server = "stun.ekiga.net"; |
205 | static int stun_port = 3478; | ||
206 | 202 | ||
203 | static unsigned int stun_port = 3478; | ||
207 | 204 | ||
208 | 205 | ||
209 | /** | 206 | /** |
@@ -212,47 +209,46 @@ static int stun_port = 3478; | |||
212 | * @param ah auto test handle | 209 | * @param ah auto test handle |
213 | */ | 210 | */ |
214 | static void | 211 | static void |
215 | next_phase (struct GNUNET_NAT_AutoHandle *ah); | 212 | next_phase (struct GNUNET_NAT_AutoHandle *ah); |
216 | |||
217 | |||
218 | 213 | ||
219 | 214 | ||
220 | static void | 215 | static void |
221 | process_stun_reply(struct sockaddr_in* answer, struct GNUNET_NAT_AutoHandle *ah) | 216 | process_stun_reply(struct sockaddr_in *answer, |
217 | struct GNUNET_NAT_AutoHandle *ah) | ||
222 | { | 218 | { |
223 | |||
224 | ah->stun_ip = inet_ntoa(answer->sin_addr); | 219 | ah->stun_ip = inet_ntoa(answer->sin_addr); |
225 | ah->stun_port = ntohs(answer->sin_port); | 220 | ah->stun_port = ntohs (answer->sin_port); |
226 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "External IP is: %s , with port %d\n", ah->stun_ip, ah->stun_port); | 221 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
227 | 222 | "External IP is: %s , with port %u\n", | |
228 | 223 | ah->stun_ip, | |
224 | ah->stun_port); | ||
229 | next_phase (ah); | 225 | next_phase (ah); |
230 | |||
231 | } | 226 | } |
232 | 227 | ||
228 | |||
233 | /** | 229 | /** |
234 | * Function that terminates the test. | 230 | * Function that terminates the test. |
235 | */ | 231 | */ |
236 | static void | 232 | static void |
237 | stop_stun () | 233 | stop_stun () |
238 | { | 234 | { |
239 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stopping STUN and quitting...\n"); | 235 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
240 | 236 | "Stopping STUN and quitting...\n"); | |
241 | /* Clean task */ | 237 | /* Clean task */ |
242 | if(NULL != ltask4) | 238 | if (NULL != ltask4) |
243 | { | 239 | { |
244 | GNUNET_SCHEDULER_cancel (ltask4); | 240 | GNUNET_SCHEDULER_cancel (ltask4); |
245 | ltask4 = NULL; | 241 | ltask4 = NULL; |
246 | } | 242 | } |
247 | |||
248 | /* Clean socket */ | 243 | /* Clean socket */ |
249 | if(NULL != lsock4) | 244 | if (NULL != lsock4) |
250 | { | 245 | { |
251 | GNUNET_NETWORK_socket_close (lsock4); | 246 | GNUNET_NETWORK_socket_close (lsock4); |
252 | lsock4 = NULL; | 247 | lsock4 = NULL; |
253 | } | 248 | } |
254 | } | 249 | } |
255 | 250 | ||
251 | |||
256 | /** | 252 | /** |
257 | * Activity on our incoming socket. Read data from the | 253 | * Activity on our incoming socket. Read data from the |
258 | * incoming connection. | 254 | * incoming connection. |
@@ -278,8 +274,8 @@ do_udp_read (void *cls) | |||
278 | sizeof (reply_buf)); | 274 | sizeof (reply_buf)); |
279 | 275 | ||
280 | //Lets handle the packet | 276 | //Lets handle the packet |
281 | memset(&answer, 0, sizeof(struct sockaddr_in)); | 277 | memset (&answer, 0, sizeof(struct sockaddr_in)); |
282 | if(ah->phase == AUTO_NAT_PUNCHED) | 278 | if (ah->phase == AUTO_NAT_PUNCHED) |
283 | { | 279 | { |
284 | //Destroy the connection | 280 | //Destroy the connection |
285 | GNUNET_NETWORK_socket_close (lsock4); | 281 | GNUNET_NETWORK_socket_close (lsock4); |
@@ -358,7 +354,8 @@ request_callback (void *cls, | |||
358 | { | 354 | { |
359 | // struct GNUNET_NAT_AutoHandle *ah = cls; | 355 | // struct GNUNET_NAT_AutoHandle *ah = cls; |
360 | 356 | ||
361 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Request callback: stop and quit\n"); | 357 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
358 | "Request callback: stop and quit\n"); | ||
362 | stop_stun (); | 359 | stop_stun (); |
363 | 360 | ||
364 | // next_phase (ah); FIXME this always will be NULL, as called in test_stun() | 361 | // next_phase (ah); FIXME this always will be NULL, as called in test_stun() |
@@ -524,7 +521,8 @@ test_stun (struct GNUNET_NAT_AutoHandle *ah) | |||
524 | "STUN service listens on port %u\n", | 521 | "STUN service listens on port %u\n", |
525 | (unsigned int) port); | 522 | (unsigned int) port); |
526 | if (GNUNET_NO == | 523 | if (GNUNET_NO == |
527 | GNUNET_NAT_stun_make_request (stun_server, stun_port, | 524 | GNUNET_NAT_stun_make_request (stun_server, |
525 | stun_port, | ||
528 | lsock4, | 526 | lsock4, |
529 | &request_callback, | 527 | &request_callback, |
530 | NULL)) | 528 | NULL)) |
@@ -631,6 +629,26 @@ test_local_ip (struct GNUNET_NAT_AutoHandle *ah) | |||
631 | 629 | ||
632 | 630 | ||
633 | /** | 631 | /** |
632 | * We got disconnected from the NAT server. Stop | ||
633 | * waiting for a reply. | ||
634 | * | ||
635 | * @param cls the `struct GNUNET_NAT_AutoHandle` | ||
636 | * @param error error code | ||
637 | */ | ||
638 | static void | ||
639 | mq_error_handler (void *cls, | ||
640 | enum GNUNET_MQ_Error error) | ||
641 | { | ||
642 | struct GNUNET_NAT_AutoHandle *ah = cls; | ||
643 | |||
644 | GNUNET_MQ_destroy (ah->mq); | ||
645 | ah->mq = NULL; | ||
646 | /* wait a bit first? */ | ||
647 | next_phase (ah); | ||
648 | } | ||
649 | |||
650 | |||
651 | /** | ||
634 | * Test if NAT has been punched | 652 | * Test if NAT has been punched |
635 | * | 653 | * |
636 | * @param ah auto setup context | 654 | * @param ah auto setup context |
@@ -638,50 +656,47 @@ test_local_ip (struct GNUNET_NAT_AutoHandle *ah) | |||
638 | static void | 656 | static void |
639 | test_nat_punched (struct GNUNET_NAT_AutoHandle *ah) | 657 | test_nat_punched (struct GNUNET_NAT_AutoHandle *ah) |
640 | { | 658 | { |
641 | struct GNUNET_CLIENT_Connection *client; | 659 | struct GNUNET_NAT_TestMessage *msg; |
642 | struct GNUNET_NAT_TestMessage msg; | 660 | struct GNUNET_MQ_Envelope *env; |
643 | 661 | ||
644 | if (ah->stun_ip) | 662 | if (! ah->stun_ip) |
645 | { | 663 | { |
646 | LOG (GNUNET_ERROR_TYPE_INFO, | 664 | LOG (GNUNET_ERROR_TYPE_INFO, |
647 | "Asking gnunet-nat-server to connect to `%s'\n", | 665 | "We don't have a STUN IP"); |
648 | ah->stun_ip); | 666 | next_phase (ah); |
649 | 667 | return; | |
650 | 668 | } | |
651 | msg.header.size = htons (sizeof (struct GNUNET_NAT_TestMessage)); | ||
652 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAT_TEST); | ||
653 | msg.dst_ipv4 = inet_addr(ah->stun_ip); | ||
654 | msg.dport = htons(ah->stun_port); | ||
655 | msg.data = port; | ||
656 | msg.is_tcp = htonl ((uint32_t) GNUNET_NO); | ||
657 | |||
658 | client = GNUNET_CLIENT_connect ("gnunet-nat-server", ah->cfg); | ||
659 | if (NULL == client) | ||
660 | { | ||
661 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
662 | _("Failed to connect to `gnunet-nat-server'\n")); | ||
663 | return; | ||
664 | } | ||
665 | 669 | ||
666 | GNUNET_break (GNUNET_OK == | 670 | LOG (GNUNET_ERROR_TYPE_INFO, |
667 | GNUNET_CLIENT_transmit_and_get_response (client, &msg.header, | 671 | "Asking gnunet-nat-server to connect to `%s'\n", |
668 | NAT_SERVER_TIMEOUT, | 672 | ah->stun_ip); |
669 | GNUNET_YES, NULL, | 673 | ah->mq = GNUNET_CLIENT_connecT (ah->cfg, |
670 | NULL)); | 674 | "gnunet-nat-server", |
671 | if (NULL != ltask4) | 675 | NULL, |
672 | { | 676 | &mq_error_handler, |
673 | GNUNET_SCHEDULER_cancel (ltask4); | 677 | ah); |
674 | ltask4 = GNUNET_SCHEDULER_add_read_net (NAT_SERVER_TIMEOUT, | 678 | if (NULL == ah->mq) |
675 | lsock4, | 679 | { |
676 | &do_udp_read, | 680 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
677 | ah); | 681 | _("Failed to connect to `gnunet-nat-server'\n")); |
678 | } | 682 | next_phase (ah); |
683 | return; | ||
679 | } | 684 | } |
680 | else | 685 | env = GNUNET_MQ_msg (msg, |
686 | GNUNET_MESSAGE_TYPE_NAT_TEST); | ||
687 | msg->dst_ipv4 = inet_addr (ah->stun_ip); | ||
688 | msg->dport = htons (ah->stun_port); | ||
689 | msg->data = port; | ||
690 | msg->is_tcp = htonl ((uint32_t) GNUNET_NO); | ||
691 | GNUNET_MQ_send (ah->mq, | ||
692 | env); | ||
693 | if (NULL != ltask4) | ||
681 | { | 694 | { |
682 | LOG (GNUNET_ERROR_TYPE_INFO, | 695 | GNUNET_SCHEDULER_cancel (ltask4); |
683 | "We don't have a STUN IP"); | 696 | ltask4 = GNUNET_SCHEDULER_add_read_net (NAT_SERVER_TIMEOUT, |
684 | next_phase(ah); | 697 | lsock4, |
698 | &do_udp_read, | ||
699 | ah); | ||
685 | } | 700 | } |
686 | } | 701 | } |
687 | 702 | ||
@@ -735,34 +750,50 @@ test_icmp_server (struct GNUNET_NAT_AutoHandle *ah) | |||
735 | 750 | ||
736 | tmp = NULL; | 751 | tmp = NULL; |
737 | helper = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-server"); | 752 | helper = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-server"); |
738 | if ((GNUNET_OK == | 753 | if ( (GNUNET_OK == |
739 | GNUNET_CONFIGURATION_get_value_string (ah->cfg, "nat", "EXTERNAL_ADDRESS", | 754 | GNUNET_CONFIGURATION_get_value_string (ah->cfg, |
740 | &tmp)) && (0 < strlen (tmp))){ | 755 | "nat", |
756 | "EXTERNAL_ADDRESS", | ||
757 | &tmp)) && | ||
758 | (0 < strlen (tmp)) ) | ||
759 | { | ||
741 | ext_ip = GNUNET_OK; | 760 | ext_ip = GNUNET_OK; |
742 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("test_icmp_server not possible, as we have no public IPv4 address\n")); | 761 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
762 | _("test_icmp_server not possible, as we have no public IPv4 address\n")); | ||
743 | } | 763 | } |
744 | else | 764 | else |
745 | goto err; | 765 | goto err; |
746 | 766 | ||
747 | if (GNUNET_YES == | 767 | if (GNUNET_YES == |
748 | GNUNET_CONFIGURATION_get_value_yesno (ah->cfg, "nat", "BEHIND_NAT")){ | 768 | GNUNET_CONFIGURATION_get_value_yesno (ah->cfg, |
769 | "nat", | ||
770 | "BEHIND_NAT")) | ||
771 | { | ||
749 | nated = GNUNET_YES; | 772 | nated = GNUNET_YES; |
750 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("test_icmp_server not possible, as we are not behind NAT\n")); | 773 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
774 | _("test_icmp_server not possible, as we are not behind NAT\n")); | ||
751 | } | 775 | } |
752 | else | 776 | else |
753 | goto err; | 777 | goto err; |
754 | 778 | ||
755 | if (GNUNET_YES == | 779 | if (GNUNET_YES == |
756 | GNUNET_OS_check_helper_binary (helper, GNUNET_YES, "-d 127.0.0.1" )){ | 780 | GNUNET_OS_check_helper_binary (helper, |
781 | GNUNET_YES, | ||
782 | "-d 127.0.0.1" )) | ||
783 | { | ||
757 | binary = GNUNET_OK; // use localhost as source for that one udp-port, ok for testing | 784 | binary = GNUNET_OK; // use localhost as source for that one udp-port, ok for testing |
758 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("No working gnunet-helper-nat-server found\n")); | 785 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
786 | _("No working gnunet-helper-nat-server found\n")); | ||
759 | } | 787 | } |
760 | err: | 788 | err: |
761 | GNUNET_free_non_null (tmp); | 789 | GNUNET_free_non_null (tmp); |
762 | GNUNET_free (helper); | 790 | GNUNET_free (helper); |
763 | 791 | ||
764 | if (GNUNET_OK == ext_ip && GNUNET_YES == nated && GNUNET_OK == binary) | 792 | if ( (GNUNET_OK == ext_ip) && |
765 | ah->task = GNUNET_SCHEDULER_add_now (&reversal_test, ah); | 793 | (GNUNET_YES == nated) && |
794 | (GNUNET_OK == binary) ) | ||
795 | ah->task = GNUNET_SCHEDULER_add_now (&reversal_test, | ||
796 | ah); | ||
766 | else | 797 | else |
767 | next_phase (ah); | 798 | next_phase (ah); |
768 | } | 799 | } |
@@ -781,17 +812,24 @@ test_icmp_client (struct GNUNET_NAT_AutoHandle *ah) | |||
781 | 812 | ||
782 | tmp = NULL; | 813 | tmp = NULL; |
783 | helper = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-client"); | 814 | helper = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-client"); |
784 | if ((GNUNET_OK == | 815 | if ( (GNUNET_OK == |
785 | GNUNET_CONFIGURATION_get_value_string (ah->cfg, "nat", "INTERNAL_ADDRESS", | 816 | GNUNET_CONFIGURATION_get_value_string (ah->cfg, |
786 | &tmp)) && (0 < strlen (tmp))) | 817 | "nat", |
818 | "INTERNAL_ADDRESS", | ||
819 | &tmp)) && | ||
820 | (0 < strlen (tmp)) ) | ||
787 | { | 821 | { |
788 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("test_icmp_client not possible, as we have no internal IPv4 address\n")); | 822 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
823 | _("test_icmp_client not possible, as we have no internal IPv4 address\n")); | ||
789 | } | 824 | } |
790 | else | 825 | else |
791 | goto err; | 826 | goto err; |
792 | 827 | ||
793 | if (GNUNET_YES != | 828 | if (GNUNET_YES != |
794 | GNUNET_CONFIGURATION_get_value_yesno (ah->cfg, "nat", "BEHIND_NAT")){ | 829 | GNUNET_CONFIGURATION_get_value_yesno (ah->cfg, |
830 | "nat", | ||
831 | "BEHIND_NAT")) | ||
832 | { | ||
795 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 833 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
796 | _("test_icmp_server not possible, as we are not behind NAT\n")); | 834 | _("test_icmp_server not possible, as we are not behind NAT\n")); |
797 | } | 835 | } |
@@ -799,8 +837,11 @@ test_icmp_client (struct GNUNET_NAT_AutoHandle *ah) | |||
799 | goto err; | 837 | goto err; |
800 | 838 | ||
801 | if (GNUNET_YES == | 839 | if (GNUNET_YES == |
802 | GNUNET_OS_check_helper_binary (helper, GNUNET_YES, "-d 127.0.0.1 127.0.0.2 42")){ | 840 | GNUNET_OS_check_helper_binary (helper, |
803 | // none of these parameters are actually used in privilege testing mode | 841 | GNUNET_YES, |
842 | "-d 127.0.0.1 127.0.0.2 42")) | ||
843 | { | ||
844 | // none of these parameters are actually used in privilege testing mode | ||
804 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 845 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
805 | _("No working gnunet-helper-nat-server found\n")); | 846 | _("No working gnunet-helper-nat-server found\n")); |
806 | } | 847 | } |
@@ -827,67 +868,93 @@ next_phase (struct GNUNET_NAT_AutoHandle *ah) | |||
827 | GNUNET_assert (0); | 868 | GNUNET_assert (0); |
828 | break; | 869 | break; |
829 | case AUTO_EXTERNAL_IP: | 870 | case AUTO_EXTERNAL_IP: |
830 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Will run AUTO_EXTERNAL_IP\n"); | 871 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
872 | "Will run AUTO_EXTERNAL_IP\n"); | ||
831 | test_external_ip (ah); | 873 | test_external_ip (ah); |
832 | break; | 874 | break; |
833 | case AUTO_STUN: | 875 | case AUTO_STUN: |
834 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Will run AUTO_STUN\n"); | 876 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
877 | "Will run AUTO_STUN\n"); | ||
835 | test_stun (ah); | 878 | test_stun (ah); |
836 | break; | 879 | break; |
837 | case AUTO_LOCAL_IP: | 880 | case AUTO_LOCAL_IP: |
838 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Will run AUTO_LOCAL_IP\n"); | 881 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
882 | "Will run AUTO_LOCAL_IP\n"); | ||
839 | test_local_ip (ah); | 883 | test_local_ip (ah); |
840 | break; | 884 | break; |
841 | case AUTO_NAT_PUNCHED: | 885 | case AUTO_NAT_PUNCHED: |
842 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Will run AUTO_NAT_PUNCHED\n"); | 886 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
887 | "Will run AUTO_NAT_PUNCHED\n"); | ||
843 | test_nat_punched (ah); | 888 | test_nat_punched (ah); |
844 | break; | 889 | break; |
845 | case AUTO_UPNPC: | 890 | case AUTO_UPNPC: |
846 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Will run AUTO_UPNPC\n"); | 891 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
892 | "Will run AUTO_UPNPC\n"); | ||
847 | test_upnpc (ah); | 893 | test_upnpc (ah); |
848 | break; | 894 | break; |
849 | case AUTO_ICMP_SERVER: | 895 | case AUTO_ICMP_SERVER: |
850 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Will run AUTO_ICMP_SERVER\n"); | 896 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
897 | "Will run AUTO_ICMP_SERVER\n"); | ||
851 | test_icmp_server (ah); | 898 | test_icmp_server (ah); |
852 | break; | 899 | break; |
853 | case AUTO_ICMP_CLIENT: | 900 | case AUTO_ICMP_CLIENT: |
854 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Will run AUTO_ICMP_CLIENT\n"); | 901 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
902 | "Will run AUTO_ICMP_CLIENT\n"); | ||
855 | test_icmp_client (ah); | 903 | test_icmp_client (ah); |
856 | break; | 904 | break; |
857 | case AUTO_DONE: | 905 | case AUTO_DONE: |
858 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Done with tests\n"); | 906 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
907 | "Done with tests\n"); | ||
859 | if (!ah->internal_ip_is_public) | 908 | if (!ah->internal_ip_is_public) |
860 | { | 909 | { |
861 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "BEHIND_NAT", "YES"); | 910 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, |
911 | "nat", | ||
912 | "BEHIND_NAT", | ||
913 | "YES"); | ||
862 | 914 | ||
863 | if (ah->connected_back) | 915 | if (ah->connected_back) |
864 | { | 916 | { |
865 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "PUNCHED_NAT", "YES"); | 917 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, |
918 | "nat", | ||
919 | "PUNCHED_NAT", | ||
920 | "YES"); | ||
866 | } | 921 | } |
867 | else | 922 | else |
868 | { | 923 | { |
869 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "PUNCHED_NAT", "NO"); | 924 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, |
925 | "nat", | ||
926 | "PUNCHED_NAT", | ||
927 | "NO"); | ||
870 | } | 928 | } |
871 | 929 | ||
872 | if (ah->stun_ip) | 930 | if (ah->stun_ip) |
873 | { | 931 | { |
874 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "EXTERNAL_ADDRESS", | 932 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, |
933 | "nat", | ||
934 | "EXTERNAL_ADDRESS", | ||
875 | ah->stun_ip); | 935 | ah->stun_ip); |
876 | if (ah->connected_back) | 936 | if (ah->connected_back) |
877 | { | 937 | { |
878 | ah->type = GNUNET_NAT_TYPE_STUN_PUNCHED_NAT; | 938 | ah->type = GNUNET_NAT_TYPE_STUN_PUNCHED_NAT; |
879 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "USE_STUN", "YES"); | 939 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, |
940 | "nat", | ||
941 | "USE_STUN", | ||
942 | "YES"); | ||
880 | } | 943 | } |
881 | else | 944 | else |
882 | { | 945 | { |
883 | ah->type = GNUNET_NAT_TYPE_UNREACHABLE_NAT; | 946 | ah->type = GNUNET_NAT_TYPE_UNREACHABLE_NAT; |
884 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "USE_STUN", "NO"); | 947 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, |
948 | "nat", | ||
949 | "USE_STUN", | ||
950 | "NO"); | ||
885 | } | 951 | } |
886 | 952 | ||
887 | } | 953 | } |
888 | if (ah->stun_port) | 954 | if (0 != ah->stun_port) |
889 | { | 955 | { |
890 | GNUNET_CONFIGURATION_set_value_number (ah->cfg, "transport-udp", | 956 | GNUNET_CONFIGURATION_set_value_number (ah->cfg, |
957 | "transport-udp", | ||
891 | "ADVERTISED_PORT", | 958 | "ADVERTISED_PORT", |
892 | ah->stun_port); | 959 | ah->stun_port); |
893 | } | 960 | } |
@@ -899,20 +966,29 @@ next_phase (struct GNUNET_NAT_AutoHandle *ah) | |||
899 | if (ah->connected_back) | 966 | if (ah->connected_back) |
900 | { | 967 | { |
901 | ah->type = GNUNET_NAT_TYPE_NO_NAT; | 968 | ah->type = GNUNET_NAT_TYPE_NO_NAT; |
902 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "BEHIND_NAT", "NO"); | 969 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, |
970 | "nat", | ||
971 | "BEHIND_NAT", | ||
972 | "NO"); | ||
903 | } | 973 | } |
904 | else | 974 | else |
905 | { | 975 | { |
906 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "BEHIND_NAT", "YES"); | 976 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, |
977 | "nat", | ||
978 | "BEHIND_NAT", | ||
979 | "YES"); | ||
907 | ah->type = GNUNET_NAT_TYPE_UNREACHABLE_NAT; | 980 | ah->type = GNUNET_NAT_TYPE_UNREACHABLE_NAT; |
908 | if (ah->stun_ip) | 981 | if (ah->stun_ip) |
909 | { | 982 | { |
910 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "EXTERNAL_ADDRESS", | 983 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, |
984 | "nat", | ||
985 | "EXTERNAL_ADDRESS", | ||
911 | ah->stun_ip); | 986 | ah->stun_ip); |
912 | } | 987 | } |
913 | if (ah->stun_port) | 988 | if (0 != ah->stun_port) |
914 | { | 989 | { |
915 | GNUNET_CONFIGURATION_set_value_number (ah->cfg, "transport-udp", | 990 | GNUNET_CONFIGURATION_set_value_number (ah->cfg, |
991 | "transport-udp", | ||
916 | "ADVERTISED_PORT", | 992 | "ADVERTISED_PORT", |
917 | ah->stun_port); | 993 | ah->stun_port); |
918 | 994 | ||
@@ -930,7 +1006,6 @@ next_phase (struct GNUNET_NAT_AutoHandle *ah) | |||
930 | ah->type); | 1006 | ah->type); |
931 | GNUNET_CONFIGURATION_destroy (diff); | 1007 | GNUNET_CONFIGURATION_destroy (diff); |
932 | GNUNET_NAT_autoconfig_cancel (ah); | 1008 | GNUNET_NAT_autoconfig_cancel (ah); |
933 | return; | ||
934 | } | 1009 | } |
935 | } | 1010 | } |
936 | 1011 | ||
@@ -959,7 +1034,8 @@ GNUNET_NAT_autoconfig_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
959 | ah->initial_cfg = GNUNET_CONFIGURATION_dup (cfg); | 1034 | ah->initial_cfg = GNUNET_CONFIGURATION_dup (cfg); |
960 | 1035 | ||
961 | /* never use loopback addresses if user wanted autoconfiguration */ | 1036 | /* never use loopback addresses if user wanted autoconfiguration */ |
962 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", | 1037 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, |
1038 | "nat", | ||
963 | "USE_LOCALADDR", | 1039 | "USE_LOCALADDR", |
964 | "NO"); | 1040 | "NO"); |
965 | 1041 | ||
@@ -986,6 +1062,11 @@ GNUNET_NAT_autoconfig_cancel (struct GNUNET_NAT_AutoHandle *ah) | |||
986 | GNUNET_NAT_mini_get_external_ipv4_cancel (ah->eh); | 1062 | GNUNET_NAT_mini_get_external_ipv4_cancel (ah->eh); |
987 | ah->eh = NULL; | 1063 | ah->eh = NULL; |
988 | } | 1064 | } |
1065 | if (NULL != ah->mq) | ||
1066 | { | ||
1067 | GNUNET_MQ_destroy (ah->mq); | ||
1068 | ah->mq = NULL; | ||
1069 | } | ||
989 | if (NULL != ah->task) | 1070 | if (NULL != ah->task) |
990 | { | 1071 | { |
991 | GNUNET_SCHEDULER_cancel (ah->task); | 1072 | GNUNET_SCHEDULER_cancel (ah->task); |