45
45
serverListenAddr = flag .String ("server-listen-addr" , "" , "The address to listen on for the server" )
46
46
47
47
// Role: stun
48
+ stunNumber = flag .Int ("stun-number" , 0 , "The number of the STUN server" )
48
49
stunListenAddr = flag .String ("stun-listen-addr" , "" , "The address to listen on for the STUN server" )
49
50
50
51
// Role: client
@@ -88,24 +89,31 @@ var topologies = []integration.TestTopology{
88
89
},
89
90
{
90
91
// Test that DERP over "easy" NAT works. The server, client 1 and client
91
- // 2 are on different networks with a shared router, and the router
92
- // masquerades the traffic .
92
+ // 2 are on different networks with their own routers, which are joined
93
+ // by a bridge .
93
94
Name : "EasyNATDERP" ,
94
95
SetupNetworking : integration .SetupNetworkingEasyNAT ,
95
96
Server : integration.SimpleServerOptions {},
96
97
StartClient : integration .StartClientDERP ,
97
98
RunTests : integration .TestSuite ,
98
99
},
99
100
{
100
- // Test that direct over "easy" NAT works. This should use local
101
- // endpoints to connect as routing is enabled between client 1 and
102
- // client 2.
101
+ // Test that direct over "easy" NAT works with IP/ports grabbed from
102
+ // STUN.
103
103
Name : "EasyNATDirect" ,
104
104
SetupNetworking : integration .SetupNetworkingEasyNATWithSTUN ,
105
105
Server : integration.SimpleServerOptions {},
106
106
StartClient : integration .StartClientDirect ,
107
107
RunTests : integration .TestSuite ,
108
108
},
109
+ {
110
+ // Test that direct over hard NAT <=> easy NAT works.
111
+ Name : "HardNATEasyNATDirect" ,
112
+ SetupNetworking : integration .SetupNetworkingHardNATEasyNATDirect ,
113
+ Server : integration.SimpleServerOptions {},
114
+ StartClient : integration .StartClientDirect ,
115
+ RunTests : integration .TestSuite ,
116
+ },
109
117
{
110
118
// Test that DERP over WebSocket (as well as DERPForceWebSockets works).
111
119
// This does not test the actual DERP failure detection code and
@@ -164,9 +172,9 @@ func TestIntegration(t *testing.T) {
164
172
165
173
closeServer := startServerSubprocess (t , topo .Name , networking )
166
174
167
- closeSTUN := func () error { return nil }
168
- if networking . STUN . ListenAddr != "" {
169
- closeSTUN = startSTUNSubprocess (t , topo .Name , networking )
175
+ stunClosers := make ([] func () error , len ( networking . STUNs ))
176
+ for i , stun := range networking . STUNs {
177
+ stunClosers [ i ] = startSTUNSubprocess (t , topo .Name , i , stun )
170
178
}
171
179
172
180
// Write the DERP maps to a file.
@@ -191,7 +199,9 @@ func TestIntegration(t *testing.T) {
191
199
192
200
// Close client2 and the server.
193
201
require .NoError (t , closeClient2 (), "client 2 exited" )
194
- require .NoError (t , closeSTUN (), "stun exited" )
202
+ for i , closeSTUN := range stunClosers {
203
+ require .NoErrorf (t , closeSTUN (), "stun %v exited" , i )
204
+ }
195
205
require .NoError (t , closeServer (), "server exited" )
196
206
})
197
207
}
@@ -210,10 +220,15 @@ func handleTestSubprocess(t *testing.T) {
210
220
require .Contains (t , []string {"server" , "stun" , "client" }, * role , "unknown role %q" , * role )
211
221
212
222
testName := topo .Name + "/"
213
- if * role == "server" || * role == "stun" {
214
- testName += * role
215
- } else {
223
+ switch * role {
224
+ case "server" :
225
+ testName += "server"
226
+ case "stun" :
227
+ testName += fmt .Sprintf ("stun%d" , * stunNumber )
228
+ case "client" :
216
229
testName += * clientName
230
+ default :
231
+ t .Fatalf ("unknown role %q" , * role )
217
232
}
218
233
219
234
t .Run (testName , func (t * testing.T ) {
@@ -328,12 +343,13 @@ func startServerSubprocess(t *testing.T, topologyName string, networking integra
328
343
return closeFn
329
344
}
330
345
331
- func startSTUNSubprocess (t * testing.T , topologyName string , networking integration.TestNetworking ) func () error {
332
- _ , closeFn := startSubprocess (t , "stun" , networking . STUN .Process .NetNS , []string {
346
+ func startSTUNSubprocess (t * testing.T , topologyName string , number int , stun integration.TestNetworkingSTUN ) func () error {
347
+ _ , closeFn := startSubprocess (t , "stun" , stun .Process .NetNS , []string {
333
348
"--subprocess" ,
334
349
"--test-name=" + topologyName ,
335
350
"--role=stun" ,
336
- "--stun-listen-addr=" + networking .STUN .ListenAddr ,
351
+ "--stun-number=" + strconv .Itoa (number ),
352
+ "--stun-listen-addr=" + stun .ListenAddr ,
337
353
})
338
354
return closeFn
339
355
}
0 commit comments