OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "webrtc/base/socketaddress.h" | 32 #include "webrtc/base/socketaddress.h" |
33 #include "webrtc/base/ssladapter.h" | 33 #include "webrtc/base/ssladapter.h" |
34 #include "webrtc/base/thread.h" | 34 #include "webrtc/base/thread.h" |
35 #include "webrtc/base/virtualsocketserver.h" | 35 #include "webrtc/base/virtualsocketserver.h" |
36 | 36 |
37 using rtc::IPAddress; | 37 using rtc::IPAddress; |
38 using rtc::SocketAddress; | 38 using rtc::SocketAddress; |
39 using rtc::Thread; | 39 using rtc::Thread; |
40 | 40 |
41 static const SocketAddress kClientAddr("11.11.11.11", 0); | 41 static const SocketAddress kClientAddr("11.11.11.11", 0); |
42 static const SocketAddress kClientAddr2("22.22.22.22", 0); | |
43 static const SocketAddress kLoopbackAddr("127.0.0.1", 0); | 42 static const SocketAddress kLoopbackAddr("127.0.0.1", 0); |
44 static const SocketAddress kPrivateAddr("192.168.1.11", 0); | 43 static const SocketAddress kPrivateAddr("192.168.1.11", 0); |
45 static const SocketAddress kPrivateAddr2("192.168.1.12", 0); | 44 static const SocketAddress kPrivateAddr2("192.168.1.12", 0); |
46 static const SocketAddress kClientIPv6Addr("2401:fa00:4:1000:be30:5bff:fee5:c3", | 45 static const SocketAddress kClientIPv6Addr("2401:fa00:4:1000:be30:5bff:fee5:c3", |
47 0); | 46 0); |
48 static const SocketAddress kClientIPv6Addr2( | 47 static const SocketAddress kClientAddr2("22.22.22.22", 0); |
49 "2401:fa00:4:2000:be30:5bff:fee5:c3", | |
50 0); | |
51 static const SocketAddress kNatUdpAddr("77.77.77.77", rtc::NAT_SERVER_UDP_PORT); | 48 static const SocketAddress kNatUdpAddr("77.77.77.77", rtc::NAT_SERVER_UDP_PORT); |
52 static const SocketAddress kNatTcpAddr("77.77.77.77", rtc::NAT_SERVER_TCP_PORT); | 49 static const SocketAddress kNatTcpAddr("77.77.77.77", rtc::NAT_SERVER_TCP_PORT); |
53 static const SocketAddress kRemoteClientAddr("22.22.22.22", 0); | 50 static const SocketAddress kRemoteClientAddr("22.22.22.22", 0); |
54 static const SocketAddress kStunAddr("99.99.99.1", cricket::STUN_SERVER_PORT); | 51 static const SocketAddress kStunAddr("99.99.99.1", cricket::STUN_SERVER_PORT); |
55 static const SocketAddress kRelayUdpIntAddr("99.99.99.2", 5000); | 52 static const SocketAddress kRelayUdpIntAddr("99.99.99.2", 5000); |
56 static const SocketAddress kRelayUdpExtAddr("99.99.99.3", 5001); | 53 static const SocketAddress kRelayUdpExtAddr("99.99.99.3", 5001); |
57 static const SocketAddress kRelayTcpIntAddr("99.99.99.2", 5002); | 54 static const SocketAddress kRelayTcpIntAddr("99.99.99.2", 5002); |
58 static const SocketAddress kRelayTcpExtAddr("99.99.99.3", 5003); | 55 static const SocketAddress kRelayTcpExtAddr("99.99.99.3", 5003); |
59 static const SocketAddress kRelaySslTcpIntAddr("99.99.99.2", 5004); | 56 static const SocketAddress kRelaySslTcpIntAddr("99.99.99.2", 5004); |
60 static const SocketAddress kRelaySslTcpExtAddr("99.99.99.3", 5005); | 57 static const SocketAddress kRelaySslTcpExtAddr("99.99.99.3", 5005); |
61 static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478); | 58 static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478); |
62 static const SocketAddress kTurnUdpIntIPv6Addr( | |
63 "2402:fb00:4:1000:be30:5bff:fee5:c3", | |
64 3479); | |
65 static const SocketAddress kTurnTcpIntAddr("99.99.99.5", 3478); | 59 static const SocketAddress kTurnTcpIntAddr("99.99.99.5", 3478); |
66 static const SocketAddress kTurnTcpIntIPv6Addr( | |
67 "2402:fb00:4:2000:be30:5bff:fee5:c3", | |
68 3479); | |
69 static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0); | 60 static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0); |
70 | 61 |
71 // Minimum and maximum port for port range tests. | 62 // Minimum and maximum port for port range tests. |
72 static const int kMinPort = 10000; | 63 static const int kMinPort = 10000; |
73 static const int kMaxPort = 10099; | 64 static const int kMaxPort = 10099; |
74 | 65 |
75 // Based on ICE_UFRAG_LENGTH | 66 // Based on ICE_UFRAG_LENGTH |
76 static const char kIceUfrag0[] = "UF00"; | 67 static const char kIceUfrag0[] = "UF00"; |
77 // Based on ICE_PWD_LENGTH | 68 // Based on ICE_PWD_LENGTH |
78 static const char kIcePwd0[] = "TESTICEPWD00000000000000"; | 69 static const char kIcePwd0[] = "TESTICEPWD00000000000000"; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 AddTurnServers(udp_turn, tcp_turn); | 177 AddTurnServers(udp_turn, tcp_turn); |
187 } | 178 } |
188 | 179 |
189 void AddTurnServers(const rtc::SocketAddress& udp_turn, | 180 void AddTurnServers(const rtc::SocketAddress& udp_turn, |
190 const rtc::SocketAddress& tcp_turn) { | 181 const rtc::SocketAddress& tcp_turn) { |
191 RelayServerConfig turn_server(RELAY_TURN); | 182 RelayServerConfig turn_server(RELAY_TURN); |
192 RelayCredentials credentials(kTurnUsername, kTurnPassword); | 183 RelayCredentials credentials(kTurnUsername, kTurnPassword); |
193 turn_server.credentials = credentials; | 184 turn_server.credentials = credentials; |
194 | 185 |
195 if (!udp_turn.IsNil()) { | 186 if (!udp_turn.IsNil()) { |
196 turn_server.ports.push_back(ProtocolAddress(udp_turn, PROTO_UDP, false)); | 187 turn_server.ports.push_back( |
| 188 ProtocolAddress(kTurnUdpIntAddr, PROTO_UDP, false)); |
197 } | 189 } |
198 if (!tcp_turn.IsNil()) { | 190 if (!tcp_turn.IsNil()) { |
199 turn_server.ports.push_back(ProtocolAddress(tcp_turn, PROTO_TCP, false)); | 191 turn_server.ports.push_back( |
| 192 ProtocolAddress(kTurnTcpIntAddr, PROTO_TCP, false)); |
200 } | 193 } |
201 allocator_->AddTurnServer(turn_server); | 194 allocator_->AddTurnServer(turn_server); |
202 } | 195 } |
203 | 196 |
204 bool CreateSession(int component) { | 197 bool CreateSession(int component) { |
205 session_ = CreateSession("session", component); | 198 session_ = CreateSession("session", component); |
206 if (!session_) { | 199 if (!session_) { |
207 return false; | 200 return false; |
208 } | 201 } |
209 return true; | 202 return true; |
(...skipping 22 matching lines...) Expand all Loading... |
232 std::unique_ptr<PortAllocatorSession> CreateSession( | 225 std::unique_ptr<PortAllocatorSession> CreateSession( |
233 const std::string& sid, | 226 const std::string& sid, |
234 const std::string& content_name, | 227 const std::string& content_name, |
235 int component, | 228 int component, |
236 const std::string& ice_ufrag, | 229 const std::string& ice_ufrag, |
237 const std::string& ice_pwd) { | 230 const std::string& ice_pwd) { |
238 std::unique_ptr<PortAllocatorSession> session = allocator_->CreateSession( | 231 std::unique_ptr<PortAllocatorSession> session = allocator_->CreateSession( |
239 sid, content_name, component, ice_ufrag, ice_pwd); | 232 sid, content_name, component, ice_ufrag, ice_pwd); |
240 session->SignalPortReady.connect(this, | 233 session->SignalPortReady.connect(this, |
241 &BasicPortAllocatorTest::OnPortReady); | 234 &BasicPortAllocatorTest::OnPortReady); |
242 session->SignalPortPruned.connect(this, | |
243 &BasicPortAllocatorTest::OnPortPruned); | |
244 session->SignalCandidatesReady.connect( | 235 session->SignalCandidatesReady.connect( |
245 this, &BasicPortAllocatorTest::OnCandidatesReady); | 236 this, &BasicPortAllocatorTest::OnCandidatesReady); |
246 session->SignalCandidatesAllocationDone.connect( | 237 session->SignalCandidatesAllocationDone.connect( |
247 this, &BasicPortAllocatorTest::OnCandidatesAllocationDone); | 238 this, &BasicPortAllocatorTest::OnCandidatesAllocationDone); |
248 return session; | 239 return session; |
249 } | 240 } |
250 | 241 |
251 // Return true if the addresses are the same, or the port is 0 in |pattern| | 242 // Return true if the addresses are the same, or the port is 0 in |pattern| |
252 // (acting as a wildcard) and the IPs are the same. | 243 // (acting as a wildcard) and the IPs are the same. |
253 // Even with a wildcard port, the port of the address should be nonzero if | 244 // Even with a wildcard port, the port of the address should be nonzero if |
254 // the IP is nonzero. | 245 // the IP is nonzero. |
255 static bool AddressMatch(const SocketAddress& address, | 246 static bool AddressMatch(const SocketAddress& address, |
256 const SocketAddress& pattern) { | 247 const SocketAddress& pattern) { |
257 return address.ipaddr() == pattern.ipaddr() && | 248 return address.ipaddr() == pattern.ipaddr() && |
258 ((pattern.port() == 0 && | 249 ((pattern.port() == 0 && |
259 (address.port() != 0 || IPIsAny(address.ipaddr()))) || | 250 (address.port() != 0 || IPIsAny(address.ipaddr()))) || |
260 (pattern.port() != 0 && address.port() == pattern.port())); | 251 (pattern.port() != 0 && address.port() == pattern.port())); |
261 } | 252 } |
262 | 253 |
263 // Returns the number of ports that have matching type, protocol and | |
264 // address. | |
265 static int CountPorts(const std::vector<PortInterface*>& ports, | |
266 const std::string& type, | |
267 ProtocolType protocol, | |
268 const SocketAddress& client_addr) { | |
269 return std::count_if( | |
270 ports.begin(), ports.end(), | |
271 [type, protocol, client_addr](PortInterface* port) { | |
272 return port->Type() == type && port->GetProtocol() == protocol && | |
273 port->Network()->GetBestIP() == client_addr.ipaddr(); | |
274 }); | |
275 } | |
276 | |
277 // Find a candidate and return it. | 254 // Find a candidate and return it. |
278 static bool FindCandidate(const std::vector<Candidate>& candidates, | 255 static bool FindCandidate(const std::vector<Candidate>& candidates, |
279 const std::string& type, | 256 const std::string& type, |
280 const std::string& proto, | 257 const std::string& proto, |
281 const SocketAddress& addr, | 258 const SocketAddress& addr, |
282 Candidate* found) { | 259 Candidate* found) { |
283 auto it = std::find_if(candidates.begin(), candidates.end(), | 260 auto it = std::find_if(candidates.begin(), candidates.end(), |
284 [type, proto, addr](const Candidate& c) { | 261 [type, proto, addr](const Candidate& c) { |
285 return c.type() == type && c.protocol() == proto && | 262 return c.type() == type && c.protocol() == proto && |
286 AddressMatch(c.address(), addr); | 263 AddressMatch(c.address(), addr); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 BasicPortAllocator& allocator() { return *allocator_; } | 385 BasicPortAllocator& allocator() { return *allocator_; } |
409 | 386 |
410 void OnPortReady(PortAllocatorSession* ses, PortInterface* port) { | 387 void OnPortReady(PortAllocatorSession* ses, PortInterface* port) { |
411 LOG(LS_INFO) << "OnPortReady: " << port->ToString(); | 388 LOG(LS_INFO) << "OnPortReady: " << port->ToString(); |
412 ports_.push_back(port); | 389 ports_.push_back(port); |
413 // Make sure the new port is added to ReadyPorts. | 390 // Make sure the new port is added to ReadyPorts. |
414 auto ready_ports = ses->ReadyPorts(); | 391 auto ready_ports = ses->ReadyPorts(); |
415 EXPECT_NE(ready_ports.end(), | 392 EXPECT_NE(ready_ports.end(), |
416 std::find(ready_ports.begin(), ready_ports.end(), port)); | 393 std::find(ready_ports.begin(), ready_ports.end(), port)); |
417 } | 394 } |
418 void OnPortPruned(PortAllocatorSession* ses, PortInterface* port) { | |
419 LOG(LS_INFO) << "OnPortPruned: " << port->ToString(); | |
420 ports_.erase(std::remove(ports_.begin(), ports_.end(), port), ports_.end()); | |
421 // Make sure the pruned port is not in ReadyPorts. | |
422 auto ready_ports = ses->ReadyPorts(); | |
423 EXPECT_EQ(ready_ports.end(), | |
424 std::find(ready_ports.begin(), ready_ports.end(), port)); | |
425 } | |
426 | |
427 void OnCandidatesReady(PortAllocatorSession* ses, | 395 void OnCandidatesReady(PortAllocatorSession* ses, |
428 const std::vector<Candidate>& candidates) { | 396 const std::vector<Candidate>& candidates) { |
429 for (const Candidate& candidate : candidates) { | 397 for (const Candidate& candidate : candidates) { |
430 LOG(LS_INFO) << "OnCandidatesReady: " << candidate.ToString(); | 398 LOG(LS_INFO) << "OnCandidatesReady: " << candidate.ToString(); |
431 // Sanity check that the ICE component is set. | 399 // Sanity check that the ICE component is set. |
432 EXPECT_EQ(ICE_CANDIDATE_COMPONENT_RTP, candidate.component()); | 400 EXPECT_EQ(ICE_CANDIDATE_COMPONENT_RTP, candidate.component()); |
433 candidates_.push_back(candidate); | 401 candidates_.push_back(candidate); |
434 } | 402 } |
435 // Make sure the new candidates are added to Candidates. | 403 // Make sure the new candidates are added to Candidates. |
436 auto ses_candidates = ses->ReadyCandidates(); | 404 auto ses_candidates = ses->ReadyCandidates(); |
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1199 ASSERT_EQ(3U, ports_.size()); | 1167 ASSERT_EQ(3U, ports_.size()); |
1200 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); | 1168 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); |
1201 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", | 1169 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", |
1202 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 1170 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
1203 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", | 1171 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", |
1204 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 1172 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
1205 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1173 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
1206 EXPECT_EQ(3U, candidates_.size()); | 1174 EXPECT_EQ(3U, candidates_.size()); |
1207 } | 1175 } |
1208 | 1176 |
1209 // Test that if prune_turn_ports is set, TCP TurnPort will not | |
1210 // be used if UDP TurnPort is used. | |
1211 TEST_F(BasicPortAllocatorTest, TestUdpTurnPortDisablesTcpTurnPorts) { | |
1212 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); | |
1213 AddInterface(kClientAddr); | |
1214 allocator_.reset(new BasicPortAllocator(&network_manager_)); | |
1215 allocator_->SetConfiguration(allocator_->stun_servers(), | |
1216 allocator_->turn_servers(), 0, true); | |
1217 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); | |
1218 allocator_->set_step_delay(kMinimumStepDelay); | |
1219 allocator_->set_flags(allocator().flags() | | |
1220 PORTALLOCATOR_ENABLE_SHARED_SOCKET | | |
1221 PORTALLOCATOR_DISABLE_TCP); | |
1222 | |
1223 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | |
1224 session_->StartGettingPorts(); | |
1225 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | |
1226 // Only 2 ports (one STUN and one TURN) are actually being used. | |
1227 EXPECT_EQ(2U, session_->ReadyPorts().size()); | |
1228 // We have verified that each port, when it is added to |ports_|, it is found | |
1229 // in |ready_ports|, and when it is pruned, it is not found in |ready_ports|, | |
1230 // so we only need to verify the content in one of them. | |
1231 EXPECT_EQ(2U, ports_.size()); | |
1232 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr)); | |
1233 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientAddr)); | |
1234 EXPECT_EQ(0, CountPorts(ports_, "relay", PROTO_TCP, kClientAddr)); | |
1235 | |
1236 // We don't remove candidates, so the size of |candidates_| will depend on | |
1237 // when the TCP TURN port becomes ready. If it is ready after the UDP TURN | |
1238 // port becomes ready, its candidates will be used there will be 3 candidates. | |
1239 // Otherwise there will be only 2 candidates. | |
1240 EXPECT_LE(2U, candidates_.size()); | |
1241 // There will only be 2 candidates in |ready_candidates| because it only | |
1242 // includes the candidates in the ready ports. | |
1243 const std::vector<Candidate>& ready_candidates = session_->ReadyCandidates(); | |
1244 EXPECT_EQ(2U, ready_candidates.size()); | |
1245 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientAddr); | |
1246 EXPECT_PRED4(HasCandidate, ready_candidates, "relay", "udp", | |
1247 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | |
1248 } | |
1249 | |
1250 // Tests that if prune_turn_ports is set, IPv4 TurnPort will not | |
1251 // be used if IPv6 TurnPort is used. | |
1252 TEST_F(BasicPortAllocatorTest, TestIPv6TurnPortDisablesIPv4TurnPorts) { | |
1253 turn_server_.AddInternalSocket(kTurnUdpIntIPv6Addr, PROTO_UDP); | |
1254 // Add two IP addresses on the same interface. | |
1255 AddInterface(kClientAddr, "net1"); | |
1256 AddInterface(kClientIPv6Addr, "net1"); | |
1257 allocator_.reset(new BasicPortAllocator(&network_manager_)); | |
1258 allocator_->SetConfiguration(allocator_->stun_servers(), | |
1259 allocator_->turn_servers(), 0, true); | |
1260 AddTurnServers(kTurnUdpIntIPv6Addr, rtc::SocketAddress()); | |
1261 | |
1262 allocator_->set_step_delay(kMinimumStepDelay); | |
1263 allocator_->set_flags(allocator().flags() | | |
1264 PORTALLOCATOR_ENABLE_SHARED_SOCKET | | |
1265 PORTALLOCATOR_ENABLE_IPV6 | PORTALLOCATOR_DISABLE_TCP); | |
1266 | |
1267 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | |
1268 session_->StartGettingPorts(); | |
1269 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | |
1270 rtc::Thread::Current()->ProcessMessages(1000); | |
1271 // Three ports (one IPv4 STUN, one IPv6 STUN and one TURN) will be ready. | |
1272 EXPECT_EQ(3U, session_->ReadyPorts().size()); | |
1273 EXPECT_EQ(3U, ports_.size()); | |
1274 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr)); | |
1275 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr)); | |
1276 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientIPv6Addr)); | |
1277 EXPECT_EQ(0, CountPorts(ports_, "relay", PROTO_UDP, kClientAddr)); | |
1278 | |
1279 // We don't remove candidates, so there may be more than 3 elemenets in | |
1280 // |candidates_|, although |ready_candidates| only includes the candidates | |
1281 // in |ready_ports|. | |
1282 EXPECT_LE(3U, candidates_.size()); | |
1283 const std::vector<Candidate>& ready_candidates = session_->ReadyCandidates(); | |
1284 EXPECT_EQ(3U, ready_candidates.size()); | |
1285 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientAddr); | |
1286 EXPECT_PRED4(HasCandidate, ready_candidates, "relay", "udp", | |
1287 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | |
1288 } | |
1289 | |
1290 // Tests that if prune_turn_ports is set, each network interface | |
1291 // will has its own set of TurnPorts based on their priorities. | |
1292 TEST_F(BasicPortAllocatorTest, TestEachInterfaceHasItsOwnTurnPorts) { | |
1293 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); | |
1294 turn_server_.AddInternalSocket(kTurnUdpIntIPv6Addr, PROTO_UDP); | |
1295 turn_server_.AddInternalSocket(kTurnTcpIntIPv6Addr, PROTO_TCP); | |
1296 // Add two interfaces both having IPv4 and IPv6 addresses. | |
1297 AddInterface(kClientAddr, "net1"); | |
1298 AddInterface(kClientIPv6Addr, "net1"); | |
1299 AddInterface(kClientAddr2, "net2"); | |
1300 AddInterface(kClientIPv6Addr2, "net2"); | |
1301 allocator_.reset(new BasicPortAllocator(&network_manager_)); | |
1302 allocator_->SetConfiguration(allocator_->stun_servers(), | |
1303 allocator_->turn_servers(), 0, true); | |
1304 // Have both UDP/TCP and IPv4/IPv6 TURN ports. | |
1305 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); | |
1306 AddTurnServers(kTurnUdpIntIPv6Addr, kTurnTcpIntIPv6Addr); | |
1307 | |
1308 allocator_->set_step_delay(kMinimumStepDelay); | |
1309 allocator_->set_flags(allocator().flags() | | |
1310 PORTALLOCATOR_ENABLE_SHARED_SOCKET | | |
1311 PORTALLOCATOR_ENABLE_IPV6); | |
1312 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | |
1313 session_->StartGettingPorts(); | |
1314 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | |
1315 // 10 ports (4 STUN and 1 TURN ports on each interface) will be ready to use. | |
1316 EXPECT_EQ(10U, session_->ReadyPorts().size()); | |
1317 EXPECT_EQ(10U, ports_.size()); | |
1318 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr)); | |
1319 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr2)); | |
1320 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr)); | |
1321 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr2)); | |
1322 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientAddr)); | |
1323 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientAddr2)); | |
1324 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientIPv6Addr)); | |
1325 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientIPv6Addr2)); | |
1326 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientIPv6Addr)); | |
1327 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientIPv6Addr2)); | |
1328 | |
1329 // We don't remove candidates, so there may be more than 10 candidates | |
1330 // in |candidates_|. | |
1331 EXPECT_LE(10U, candidates_.size()); | |
1332 const std::vector<Candidate>& ready_candidates = session_->ReadyCandidates(); | |
1333 EXPECT_EQ(10U, ready_candidates.size()); | |
1334 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientAddr); | |
1335 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientAddr2); | |
1336 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientIPv6Addr); | |
1337 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", | |
1338 kClientIPv6Addr2); | |
1339 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", kClientAddr); | |
1340 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", kClientAddr2); | |
1341 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", kClientIPv6Addr); | |
1342 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", | |
1343 kClientIPv6Addr2); | |
1344 EXPECT_PRED4(HasCandidate, ready_candidates, "relay", "udp", | |
1345 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | |
1346 } | |
1347 | |
1348 // Testing DNS resolve for the TURN server, this will test AllocationSequence | 1177 // Testing DNS resolve for the TURN server, this will test AllocationSequence |
1349 // handling the unresolved address signal from TurnPort. | 1178 // handling the unresolved address signal from TurnPort. |
1350 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithServerAddressResolve) { | 1179 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithServerAddressResolve) { |
1351 turn_server_.AddInternalSocket(rtc::SocketAddress("127.0.0.1", 3478), | 1180 turn_server_.AddInternalSocket(rtc::SocketAddress("127.0.0.1", 3478), |
1352 PROTO_UDP); | 1181 PROTO_UDP); |
1353 AddInterface(kClientAddr); | 1182 AddInterface(kClientAddr); |
1354 allocator_.reset(new BasicPortAllocator(&network_manager_)); | 1183 allocator_.reset(new BasicPortAllocator(&network_manager_)); |
1355 RelayServerConfig turn_server(RELAY_TURN); | 1184 RelayServerConfig turn_server(RELAY_TURN); |
1356 RelayCredentials credentials(kTurnUsername, kTurnPassword); | 1185 RelayCredentials credentials(kTurnUsername, kTurnPassword); |
1357 turn_server.credentials = credentials; | 1186 turn_server.credentials = credentials; |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1633 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); | 1462 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); |
1634 EXPECT_EQ(2U, ports_.size()); | 1463 EXPECT_EQ(2U, ports_.size()); |
1635 } | 1464 } |
1636 | 1465 |
1637 // Test that the ports and candidates are updated with new ufrag/pwd/etc. when | 1466 // Test that the ports and candidates are updated with new ufrag/pwd/etc. when |
1638 // a pooled session is taken out of the pool. | 1467 // a pooled session is taken out of the pool. |
1639 TEST_F(BasicPortAllocatorTest, TestTransportInformationUpdated) { | 1468 TEST_F(BasicPortAllocatorTest, TestTransportInformationUpdated) { |
1640 AddInterface(kClientAddr); | 1469 AddInterface(kClientAddr); |
1641 int pool_size = 1; | 1470 int pool_size = 1; |
1642 allocator_->SetConfiguration(allocator_->stun_servers(), | 1471 allocator_->SetConfiguration(allocator_->stun_servers(), |
1643 allocator_->turn_servers(), pool_size, false); | 1472 allocator_->turn_servers(), pool_size); |
1644 const PortAllocatorSession* peeked_session = allocator_->GetPooledSession(); | 1473 const PortAllocatorSession* peeked_session = allocator_->GetPooledSession(); |
1645 ASSERT_NE(nullptr, peeked_session); | 1474 ASSERT_NE(nullptr, peeked_session); |
1646 EXPECT_EQ_WAIT(true, peeked_session->CandidatesAllocationDone(), | 1475 EXPECT_EQ_WAIT(true, peeked_session->CandidatesAllocationDone(), |
1647 kDefaultAllocationTimeout); | 1476 kDefaultAllocationTimeout); |
1648 // Expect that when TakePooledSession is called, | 1477 // Expect that when TakePooledSession is called, |
1649 // UpdateTransportInformationInternal will be called and the | 1478 // UpdateTransportInformationInternal will be called and the |
1650 // BasicPortAllocatorSession will update the ufrag/pwd of ports and | 1479 // BasicPortAllocatorSession will update the ufrag/pwd of ports and |
1651 // candidates. | 1480 // candidates. |
1652 session_ = | 1481 session_ = |
1653 allocator_->TakePooledSession(kContentName, 1, kIceUfrag0, kIcePwd0); | 1482 allocator_->TakePooledSession(kContentName, 1, kIceUfrag0, kIcePwd0); |
(...skipping 15 matching lines...) Expand all Loading... |
1669 EXPECT_EQ(kIcePwd0, candidate.password()); | 1498 EXPECT_EQ(kIcePwd0, candidate.password()); |
1670 } | 1499 } |
1671 } | 1500 } |
1672 | 1501 |
1673 // Test that a new candidate filter takes effect even on already-gathered | 1502 // Test that a new candidate filter takes effect even on already-gathered |
1674 // candidates. | 1503 // candidates. |
1675 TEST_F(BasicPortAllocatorTest, TestSetCandidateFilterAfterCandidatesGathered) { | 1504 TEST_F(BasicPortAllocatorTest, TestSetCandidateFilterAfterCandidatesGathered) { |
1676 AddInterface(kClientAddr); | 1505 AddInterface(kClientAddr); |
1677 int pool_size = 1; | 1506 int pool_size = 1; |
1678 allocator_->SetConfiguration(allocator_->stun_servers(), | 1507 allocator_->SetConfiguration(allocator_->stun_servers(), |
1679 allocator_->turn_servers(), pool_size, false); | 1508 allocator_->turn_servers(), pool_size); |
1680 const PortAllocatorSession* peeked_session = allocator_->GetPooledSession(); | 1509 const PortAllocatorSession* peeked_session = allocator_->GetPooledSession(); |
1681 ASSERT_NE(nullptr, peeked_session); | 1510 ASSERT_NE(nullptr, peeked_session); |
1682 EXPECT_EQ_WAIT(true, peeked_session->CandidatesAllocationDone(), | 1511 EXPECT_EQ_WAIT(true, peeked_session->CandidatesAllocationDone(), |
1683 kDefaultAllocationTimeout); | 1512 kDefaultAllocationTimeout); |
1684 size_t initial_candidates_size = peeked_session->ReadyCandidates().size(); | 1513 size_t initial_candidates_size = peeked_session->ReadyCandidates().size(); |
1685 size_t initial_ports_size = peeked_session->ReadyPorts().size(); | 1514 size_t initial_ports_size = peeked_session->ReadyPorts().size(); |
1686 allocator_->set_candidate_filter(CF_RELAY); | 1515 allocator_->set_candidate_filter(CF_RELAY); |
1687 // Assume that when TakePooledSession is called, the candidate filter will be | 1516 // Assume that when TakePooledSession is called, the candidate filter will be |
1688 // applied to the pooled session. This is tested by PortAllocatorTest. | 1517 // applied to the pooled session. This is tested by PortAllocatorTest. |
1689 session_ = | 1518 session_ = |
(...skipping 11 matching lines...) Expand all Loading... |
1701 for (const Candidate& candidate : candidates) { | 1530 for (const Candidate& candidate : candidates) { |
1702 // Expect only relay candidates now that the filter is applied. | 1531 // Expect only relay candidates now that the filter is applied. |
1703 EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidate.type()); | 1532 EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidate.type()); |
1704 // Expect that the raddr is emptied due to the CF_RELAY filter. | 1533 // Expect that the raddr is emptied due to the CF_RELAY filter. |
1705 EXPECT_EQ(candidate.related_address(), | 1534 EXPECT_EQ(candidate.related_address(), |
1706 rtc::EmptySocketAddressWithFamily(candidate.address().family())); | 1535 rtc::EmptySocketAddressWithFamily(candidate.address().family())); |
1707 } | 1536 } |
1708 } | 1537 } |
1709 | 1538 |
1710 } // namespace cricket | 1539 } // namespace cricket |
OLD | NEW |