44#include <pthread.h>
55#include <stdbool.h>
66#include <stdint.h>
7+ #include <string.h>
78
89#include "auto_test_support.h"
910
@@ -16,32 +17,36 @@ static void *proxy_routine(void *arg)
1617 return nullptr ;
1718}
1819
19- static bool try_bootstrap (Tox * tox1 , Tox * tox2 , Tox * tox3 , Tox * tox4 )
20+ static bool try_bootstrap (Tox * tox1 , Tox * tox2 , Tox * tox3 , Tox * tox4 , Tox * tox5 )
2021{
2122 for (uint32_t i = 0 ; i < 400 ; ++ i ) {
2223 if (tox_self_get_connection_status (tox1 ) != TOX_CONNECTION_NONE &&
2324 tox_self_get_connection_status (tox2 ) != TOX_CONNECTION_NONE &&
2425 tox_self_get_connection_status (tox3 ) != TOX_CONNECTION_NONE &&
25- tox_self_get_connection_status (tox4 ) != TOX_CONNECTION_NONE ) {
26- printf ("%d %d %d %d\n" ,
26+ tox_self_get_connection_status (tox4 ) != TOX_CONNECTION_NONE &&
27+ tox_self_get_connection_status (tox5 ) != TOX_CONNECTION_NONE ) {
28+ printf ("%d %d %d %d %d\n" ,
2729 tox_self_get_connection_status (tox1 ),
2830 tox_self_get_connection_status (tox2 ),
2931 tox_self_get_connection_status (tox3 ),
30- tox_self_get_connection_status (tox4 ));
32+ tox_self_get_connection_status (tox4 ),
33+ tox_self_get_connection_status (tox5 ));
3134 return true;
3235 }
3336
3437 tox_iterate (tox1 , nullptr );
3538 tox_iterate (tox2 , nullptr );
3639 tox_iterate (tox3 , nullptr );
3740 tox_iterate (tox4 , nullptr );
41+ tox_iterate (tox5 , nullptr );
3842
3943 if (i % 10 == 0 ) {
40- printf ("%d %d %d %d\n" ,
44+ printf ("%d %d %d %d %d \n" ,
4145 tox_self_get_connection_status (tox1 ),
4246 tox_self_get_connection_status (tox2 ),
4347 tox_self_get_connection_status (tox3 ),
44- tox_self_get_connection_status (tox4 ));
48+ tox_self_get_connection_status (tox4 ),
49+ tox_self_get_connection_status (tox5 ));
4550 }
4651
4752 c_sleep (tox_iteration_interval (tox1 ));
@@ -60,15 +65,16 @@ int main(int argc, char **argv)
6065 c_sleep (100 );
6166 }
6267
63- const uint16_t tcp_port = 8082 ;
64- uint32_t index [] = { 1 , 2 , 3 , 4 };
68+ const uint16_t tcp_port = 8083 ;
69+ uint32_t index [] = { 1 , 2 , 3 , 4 , 5 };
6570
6671 struct Tox_Options * tox_options = tox_options_new (nullptr );
6772 ck_assert (tox_options != nullptr );
6873
6974 // tox1 is a TCP server and has UDP enabled.
7075 tox_options_set_udp_enabled (tox_options , true);
7176 tox_options_set_tcp_port (tox_options , tcp_port );
77+ tox_options_set_local_discovery_enabled (tox_options , false);
7278
7379 Tox * tox1 = tox_new_log (tox_options , nullptr , & index [0 ]);
7480 ck_assert (tox1 != nullptr );
@@ -80,8 +86,10 @@ int main(int argc, char **argv)
8086 ck_assert (dht_port != 0 );
8187
8288 // tox2 is a regular DHT node bootstrapping against tox1.
89+ tox_options_default (tox_options );
8390 tox_options_set_udp_enabled (tox_options , true);
8491 tox_options_set_tcp_port (tox_options , 0 );
92+ tox_options_set_local_discovery_enabled (tox_options , false);
8593
8694 Tox * tox2 = tox_new_log (tox_options , nullptr , & index [1 ]);
8795 ck_assert (tox2 != nullptr );
@@ -90,36 +98,57 @@ int main(int argc, char **argv)
9098 ck_assert (tox_bootstrap (tox2 , "127.0.0.1" , dht_port , dht_pk , nullptr ));
9199
92100 // tox3 has UDP disabled and connects to tox1 via an HTTP proxy
101+ tox_options_default (tox_options );
93102 tox_options_set_udp_enabled (tox_options , false);
94103 tox_options_set_proxy_host (tox_options , "127.0.0.1" );
95104 tox_options_set_proxy_port (tox_options , 8080 );
96105 tox_options_set_proxy_type (tox_options , TOX_PROXY_TYPE_HTTP );
106+ tox_options_set_local_discovery_enabled (tox_options , false);
97107
98108 Tox * tox3 = tox_new_log (tox_options , nullptr , & index [2 ]);
99109 ck_assert (tox3 != nullptr );
100110
101- // tox4 has UDP disabled and connects to tox1 via a SOCKS5 proxy
111+ // tox4 has UDP disabled and connects to tox1 via a SOCKS5 proxy with no auth
112+ tox_options_default (tox_options );
102113 tox_options_set_udp_enabled (tox_options , false);
103114 tox_options_set_proxy_host (tox_options , "127.0.0.1" );
104115 tox_options_set_proxy_port (tox_options , 8081 );
105116 tox_options_set_proxy_type (tox_options , TOX_PROXY_TYPE_SOCKS5 );
117+ tox_options_set_local_discovery_enabled (tox_options , false);
106118
107119 Tox * tox4 = tox_new_log (tox_options , nullptr , & index [3 ]);
108120 ck_assert (tox4 != nullptr );
109121
110- // tox3 and tox4 bootstrap against tox1 and add it as a TCP relay
122+ // tox5 has UDP disabled and connects to tox1 via a SOCKS5 proxy with username/password auth
123+ tox_options_default (tox_options );
124+ tox_options_set_udp_enabled (tox_options , false);
125+ tox_options_set_proxy_host (tox_options , "127.0.0.1" );
126+ tox_options_set_proxy_port (tox_options , 8082 );
127+ tox_options_set_proxy_type (tox_options , TOX_PROXY_TYPE_SOCKS5 );
128+ tox_options_set_proxy_socks5_username (tox_options , (const uint8_t * ) "nurupo" , strlen ("nurupo" ));
129+ tox_options_set_proxy_socks5_password (tox_options , (const uint8_t * ) "hunter2" , strlen ("hunter2" ));
130+ tox_options_set_local_discovery_enabled (tox_options , false);
131+
132+ Tox * tox5 = tox_new_log (tox_options , nullptr , & index [4 ]);
133+ ck_assert (tox5 != nullptr );
134+
135+ // tox3, tox4 and tox5 bootstrap against tox1 and add it as a TCP relay
111136 ck_assert (tox_bootstrap (tox3 , "127.0.0.1" , dht_port , dht_pk , nullptr ));
112137 ck_assert (tox_add_tcp_relay (tox3 , "127.0.0.1" , tcp_port , dht_pk , nullptr ));
113138
114139 ck_assert (tox_bootstrap (tox4 , "127.0.0.1" , dht_port , dht_pk , nullptr ));
115140 ck_assert (tox_add_tcp_relay (tox4 , "127.0.0.1" , tcp_port , dht_pk , nullptr ));
116141
142+ ck_assert (tox_bootstrap (tox5 , "127.0.0.1" , dht_port , dht_pk , nullptr ));
143+ ck_assert (tox_add_tcp_relay (tox5 , "127.0.0.1" , tcp_port , dht_pk , nullptr ));
144+
117145 int ret = 1 ;
118- if (try_bootstrap (tox1 , tox2 , tox3 , tox4 )) {
146+ if (try_bootstrap (tox1 , tox2 , tox3 , tox4 , tox5 )) {
119147 ret = 0 ;
120148 }
121149
122150 tox_options_free (tox_options );
151+ tox_kill (tox5 );
123152 tox_kill (tox4 );
124153 tox_kill (tox3 );
125154 tox_kill (tox2 );
0 commit comments