4
4
#include <pthread.h>
5
5
#include <stdbool.h>
6
6
#include <stdint.h>
7
+ #include <string.h>
7
8
8
9
#include "auto_test_support.h"
9
10
@@ -16,32 +17,36 @@ static void *proxy_routine(void *arg)
16
17
return nullptr ;
17
18
}
18
19
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 )
20
21
{
21
22
for (uint32_t i = 0 ; i < 400 ; ++ i ) {
22
23
if (tox_self_get_connection_status (tox1 ) != TOX_CONNECTION_NONE &&
23
24
tox_self_get_connection_status (tox2 ) != TOX_CONNECTION_NONE &&
24
25
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" ,
27
29
tox_self_get_connection_status (tox1 ),
28
30
tox_self_get_connection_status (tox2 ),
29
31
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 ));
31
34
return true;
32
35
}
33
36
34
37
tox_iterate (tox1 , nullptr );
35
38
tox_iterate (tox2 , nullptr );
36
39
tox_iterate (tox3 , nullptr );
37
40
tox_iterate (tox4 , nullptr );
41
+ tox_iterate (tox5 , nullptr );
38
42
39
43
if (i % 10 == 0 ) {
40
- printf ("%d %d %d %d\n" ,
44
+ printf ("%d %d %d %d %d \n" ,
41
45
tox_self_get_connection_status (tox1 ),
42
46
tox_self_get_connection_status (tox2 ),
43
47
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 ));
45
50
}
46
51
47
52
c_sleep (tox_iteration_interval (tox1 ));
@@ -60,15 +65,16 @@ int main(int argc, char **argv)
60
65
c_sleep (100 );
61
66
}
62
67
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 };
65
70
66
71
struct Tox_Options * tox_options = tox_options_new (nullptr );
67
72
ck_assert (tox_options != nullptr );
68
73
69
74
// tox1 is a TCP server and has UDP enabled.
70
75
tox_options_set_udp_enabled (tox_options , true);
71
76
tox_options_set_tcp_port (tox_options , tcp_port );
77
+ tox_options_set_local_discovery_enabled (tox_options , false);
72
78
73
79
Tox * tox1 = tox_new_log (tox_options , nullptr , & index [0 ]);
74
80
ck_assert (tox1 != nullptr );
@@ -80,8 +86,10 @@ int main(int argc, char **argv)
80
86
ck_assert (dht_port != 0 );
81
87
82
88
// tox2 is a regular DHT node bootstrapping against tox1.
89
+ tox_options_default (tox_options );
83
90
tox_options_set_udp_enabled (tox_options , true);
84
91
tox_options_set_tcp_port (tox_options , 0 );
92
+ tox_options_set_local_discovery_enabled (tox_options , false);
85
93
86
94
Tox * tox2 = tox_new_log (tox_options , nullptr , & index [1 ]);
87
95
ck_assert (tox2 != nullptr );
@@ -90,36 +98,57 @@ int main(int argc, char **argv)
90
98
ck_assert (tox_bootstrap (tox2 , "127.0.0.1" , dht_port , dht_pk , nullptr ));
91
99
92
100
// tox3 has UDP disabled and connects to tox1 via an HTTP proxy
101
+ tox_options_default (tox_options );
93
102
tox_options_set_udp_enabled (tox_options , false);
94
103
tox_options_set_proxy_host (tox_options , "127.0.0.1" );
95
104
tox_options_set_proxy_port (tox_options , 8080 );
96
105
tox_options_set_proxy_type (tox_options , TOX_PROXY_TYPE_HTTP );
106
+ tox_options_set_local_discovery_enabled (tox_options , false);
97
107
98
108
Tox * tox3 = tox_new_log (tox_options , nullptr , & index [2 ]);
99
109
ck_assert (tox3 != nullptr );
100
110
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 );
102
113
tox_options_set_udp_enabled (tox_options , false);
103
114
tox_options_set_proxy_host (tox_options , "127.0.0.1" );
104
115
tox_options_set_proxy_port (tox_options , 8081 );
105
116
tox_options_set_proxy_type (tox_options , TOX_PROXY_TYPE_SOCKS5 );
117
+ tox_options_set_local_discovery_enabled (tox_options , false);
106
118
107
119
Tox * tox4 = tox_new_log (tox_options , nullptr , & index [3 ]);
108
120
ck_assert (tox4 != nullptr );
109
121
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
111
136
ck_assert (tox_bootstrap (tox3 , "127.0.0.1" , dht_port , dht_pk , nullptr ));
112
137
ck_assert (tox_add_tcp_relay (tox3 , "127.0.0.1" , tcp_port , dht_pk , nullptr ));
113
138
114
139
ck_assert (tox_bootstrap (tox4 , "127.0.0.1" , dht_port , dht_pk , nullptr ));
115
140
ck_assert (tox_add_tcp_relay (tox4 , "127.0.0.1" , tcp_port , dht_pk , nullptr ));
116
141
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
+
117
145
int ret = 1 ;
118
- if (try_bootstrap (tox1 , tox2 , tox3 , tox4 )) {
146
+ if (try_bootstrap (tox1 , tox2 , tox3 , tox4 , tox5 )) {
119
147
ret = 0 ;
120
148
}
121
149
122
150
tox_options_free (tox_options );
151
+ tox_kill (tox5 );
123
152
tox_kill (tox4 );
124
153
tox_kill (tox3 );
125
154
tox_kill (tox2 );
0 commit comments