OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2012 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 #if defined(WEBRTC_POSIX) | 10 #if defined(WEBRTC_POSIX) |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 Connection* connection_; | 136 Connection* connection_; |
137 }; | 137 }; |
138 | 138 |
139 // Note: This test uses a fake clock with a simulated network round trip | 139 // Note: This test uses a fake clock with a simulated network round trip |
140 // (between local port and TURN server) of kSimulatedRtt. | 140 // (between local port and TURN server) of kSimulatedRtt. |
141 class TurnPortTest : public testing::Test, | 141 class TurnPortTest : public testing::Test, |
142 public sigslot::has_slots<>, | 142 public sigslot::has_slots<>, |
143 public rtc::MessageHandler { | 143 public rtc::MessageHandler { |
144 public: | 144 public: |
145 TurnPortTest() | 145 TurnPortTest() |
146 : main_(rtc::Thread::Current()), | 146 : pss_(new rtc::PhysicalSocketServer), |
147 pss_(new rtc::PhysicalSocketServer), | |
148 ss_(new TurnPortTestVirtualSocketServer(pss_.get())), | 147 ss_(new TurnPortTestVirtualSocketServer(pss_.get())), |
149 ss_scope_(ss_.get()), | 148 main_(ss_.get()), |
150 network_("unittest", "unittest", rtc::IPAddress(INADDR_ANY), 32), | 149 network_("unittest", "unittest", rtc::IPAddress(INADDR_ANY), 32), |
151 socket_factory_(rtc::Thread::Current()), | 150 socket_factory_(rtc::Thread::Current()), |
152 turn_server_(main_, kTurnUdpIntAddr, kTurnUdpExtAddr), | 151 turn_server_(&main_, kTurnUdpIntAddr, kTurnUdpExtAddr), |
153 turn_ready_(false), | 152 turn_ready_(false), |
154 turn_error_(false), | 153 turn_error_(false), |
155 turn_unknown_address_(false), | 154 turn_unknown_address_(false), |
156 turn_create_permission_success_(false), | 155 turn_create_permission_success_(false), |
157 udp_ready_(false), | 156 udp_ready_(false), |
158 test_finish_(false) { | 157 test_finish_(false) { |
159 // Some code uses "last received time == 0" to represent "nothing received | 158 // Some code uses "last received time == 0" to represent "nothing received |
160 // so far", so we need to start the fake clock at a nonzero time... | 159 // so far", so we need to start the fake clock at a nonzero time... |
161 // TODO(deadbeef): Fix this. | 160 // TODO(deadbeef): Fix this. |
162 fake_clock_.AdvanceTime(rtc::TimeDelta::FromSeconds(1)); | 161 fake_clock_.AdvanceTime(rtc::TimeDelta::FromSeconds(1)); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 void CreateTurnPort(const std::string& username, | 235 void CreateTurnPort(const std::string& username, |
237 const std::string& password, | 236 const std::string& password, |
238 const ProtocolAddress& server_address) { | 237 const ProtocolAddress& server_address) { |
239 CreateTurnPort(kLocalAddr1, username, password, server_address); | 238 CreateTurnPort(kLocalAddr1, username, password, server_address); |
240 } | 239 } |
241 void CreateTurnPort(const rtc::SocketAddress& local_address, | 240 void CreateTurnPort(const rtc::SocketAddress& local_address, |
242 const std::string& username, | 241 const std::string& username, |
243 const std::string& password, | 242 const std::string& password, |
244 const ProtocolAddress& server_address) { | 243 const ProtocolAddress& server_address) { |
245 RelayCredentials credentials(username, password); | 244 RelayCredentials credentials(username, password); |
246 turn_port_.reset(TurnPort::Create(main_, &socket_factory_, &network_, | 245 turn_port_.reset(TurnPort::Create(&main_, &socket_factory_, &network_, |
247 local_address.ipaddr(), 0, 0, | 246 local_address.ipaddr(), 0, 0, |
248 kIceUfrag1, kIcePwd1, | 247 kIceUfrag1, kIcePwd1, |
249 server_address, credentials, 0, | 248 server_address, credentials, 0, |
250 std::string())); | 249 std::string())); |
251 // This TURN port will be the controlling. | 250 // This TURN port will be the controlling. |
252 turn_port_->SetIceRole(ICEROLE_CONTROLLING); | 251 turn_port_->SetIceRole(ICEROLE_CONTROLLING); |
253 ConnectSignals(); | 252 ConnectSignals(); |
254 } | 253 } |
255 | 254 |
256 // Should be identical to CreateTurnPort but specifies an origin value | 255 // Should be identical to CreateTurnPort but specifies an origin value |
257 // when creating the instance of TurnPort. | 256 // when creating the instance of TurnPort. |
258 void CreateTurnPortWithOrigin(const rtc::SocketAddress& local_address, | 257 void CreateTurnPortWithOrigin(const rtc::SocketAddress& local_address, |
259 const std::string& username, | 258 const std::string& username, |
260 const std::string& password, | 259 const std::string& password, |
261 const ProtocolAddress& server_address, | 260 const ProtocolAddress& server_address, |
262 const std::string& origin) { | 261 const std::string& origin) { |
263 RelayCredentials credentials(username, password); | 262 RelayCredentials credentials(username, password); |
264 turn_port_.reset(TurnPort::Create(main_, &socket_factory_, &network_, | 263 turn_port_.reset(TurnPort::Create(&main_, &socket_factory_, &network_, |
265 local_address.ipaddr(), 0, 0, | 264 local_address.ipaddr(), 0, 0, |
266 kIceUfrag1, kIcePwd1, | 265 kIceUfrag1, kIcePwd1, |
267 server_address, credentials, 0, | 266 server_address, credentials, 0, |
268 origin)); | 267 origin)); |
269 // This TURN port will be the controlling. | 268 // This TURN port will be the controlling. |
270 turn_port_->SetIceRole(ICEROLE_CONTROLLING); | 269 turn_port_->SetIceRole(ICEROLE_CONTROLLING); |
271 ConnectSignals(); | 270 ConnectSignals(); |
272 } | 271 } |
273 | 272 |
274 void CreateSharedTurnPort(const std::string& username, | 273 void CreateSharedTurnPort(const std::string& username, |
275 const std::string& password, | 274 const std::string& password, |
276 const ProtocolAddress& server_address) { | 275 const ProtocolAddress& server_address) { |
277 RTC_CHECK(server_address.proto == PROTO_UDP); | 276 RTC_CHECK(server_address.proto == PROTO_UDP); |
278 | 277 |
279 if (!socket_) { | 278 if (!socket_) { |
280 socket_.reset(socket_factory_.CreateUdpSocket( | 279 socket_.reset(socket_factory_.CreateUdpSocket( |
281 rtc::SocketAddress(kLocalAddr1.ipaddr(), 0), 0, 0)); | 280 rtc::SocketAddress(kLocalAddr1.ipaddr(), 0), 0, 0)); |
282 ASSERT_TRUE(socket_ != NULL); | 281 ASSERT_TRUE(socket_ != NULL); |
283 socket_->SignalReadPacket.connect( | 282 socket_->SignalReadPacket.connect( |
284 this, &TurnPortTest::OnSocketReadPacket); | 283 this, &TurnPortTest::OnSocketReadPacket); |
285 } | 284 } |
286 | 285 |
287 RelayCredentials credentials(username, password); | 286 RelayCredentials credentials(username, password); |
288 turn_port_.reset(TurnPort::Create( | 287 turn_port_.reset(TurnPort::Create( |
289 main_, &socket_factory_, &network_, socket_.get(), kIceUfrag1, kIcePwd1, | 288 &main_, &socket_factory_, &network_, socket_.get(), kIceUfrag1, |
290 server_address, credentials, 0, std::string())); | 289 kIcePwd1, server_address, credentials, 0, std::string())); |
291 // This TURN port will be the controlling. | 290 // This TURN port will be the controlling. |
292 turn_port_->SetIceRole(ICEROLE_CONTROLLING); | 291 turn_port_->SetIceRole(ICEROLE_CONTROLLING); |
293 ConnectSignals(); | 292 ConnectSignals(); |
294 } | 293 } |
295 | 294 |
296 void ConnectSignals() { | 295 void ConnectSignals() { |
297 turn_port_->SignalPortComplete.connect(this, | 296 turn_port_->SignalPortComplete.connect(this, |
298 &TurnPortTest::OnTurnPortComplete); | 297 &TurnPortTest::OnTurnPortComplete); |
299 turn_port_->SignalPortError.connect(this, | 298 turn_port_->SignalPortError.connect(this, |
300 &TurnPortTest::OnTurnPortError); | 299 &TurnPortTest::OnTurnPortError); |
301 turn_port_->SignalUnknownAddress.connect(this, | 300 turn_port_->SignalUnknownAddress.connect(this, |
302 &TurnPortTest::OnTurnUnknownAddress); | 301 &TurnPortTest::OnTurnUnknownAddress); |
303 turn_port_->SignalCreatePermissionResult.connect(this, | 302 turn_port_->SignalCreatePermissionResult.connect(this, |
304 &TurnPortTest::OnTurnCreatePermissionResult); | 303 &TurnPortTest::OnTurnCreatePermissionResult); |
305 turn_port_->SignalTurnRefreshResult.connect( | 304 turn_port_->SignalTurnRefreshResult.connect( |
306 this, &TurnPortTest::OnTurnRefreshResult); | 305 this, &TurnPortTest::OnTurnRefreshResult); |
307 } | 306 } |
308 | 307 |
309 void CreateUdpPort() { CreateUdpPort(kLocalAddr2); } | 308 void CreateUdpPort() { CreateUdpPort(kLocalAddr2); } |
310 | 309 |
311 void CreateUdpPort(const SocketAddress& address) { | 310 void CreateUdpPort(const SocketAddress& address) { |
312 udp_port_.reset(UDPPort::Create(main_, &socket_factory_, &network_, | 311 udp_port_.reset(UDPPort::Create(&main_, &socket_factory_, &network_, |
313 address.ipaddr(), 0, 0, kIceUfrag2, | 312 address.ipaddr(), 0, 0, kIceUfrag2, |
314 kIcePwd2, std::string(), false)); | 313 kIcePwd2, std::string(), false)); |
315 // UDP port will be controlled. | 314 // UDP port will be controlled. |
316 udp_port_->SetIceRole(ICEROLE_CONTROLLED); | 315 udp_port_->SetIceRole(ICEROLE_CONTROLLED); |
317 udp_port_->SignalPortComplete.connect( | 316 udp_port_->SignalPortComplete.connect( |
318 this, &TurnPortTest::OnUdpPortComplete); | 317 this, &TurnPortTest::OnUdpPortComplete); |
319 } | 318 } |
320 | 319 |
321 void PrepareTurnAndUdpPorts(ProtocolType protocol_type) { | 320 void PrepareTurnAndUdpPorts(ProtocolType protocol_type) { |
322 // turn_port_ should have been created. | 321 // turn_port_ should have been created. |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 ASSERT_EQ(num_packets, udp_packets_.size()); | 612 ASSERT_EQ(num_packets, udp_packets_.size()); |
614 for (size_t i = 0; i < num_packets; ++i) { | 613 for (size_t i = 0; i < num_packets; ++i) { |
615 EXPECT_EQ(i + 1, turn_packets_[i].size()); | 614 EXPECT_EQ(i + 1, turn_packets_[i].size()); |
616 EXPECT_EQ(i + 1, udp_packets_[i].size()); | 615 EXPECT_EQ(i + 1, udp_packets_[i].size()); |
617 EXPECT_EQ(turn_packets_[i], udp_packets_[i]); | 616 EXPECT_EQ(turn_packets_[i], udp_packets_[i]); |
618 } | 617 } |
619 } | 618 } |
620 | 619 |
621 protected: | 620 protected: |
622 rtc::ScopedFakeClock fake_clock_; | 621 rtc::ScopedFakeClock fake_clock_; |
623 rtc::Thread* main_; | |
624 std::unique_ptr<rtc::PhysicalSocketServer> pss_; | 622 std::unique_ptr<rtc::PhysicalSocketServer> pss_; |
625 std::unique_ptr<TurnPortTestVirtualSocketServer> ss_; | 623 std::unique_ptr<TurnPortTestVirtualSocketServer> ss_; |
626 rtc::SocketServerScope ss_scope_; | 624 rtc::AutoSocketServerThread main_; |
627 rtc::Network network_; | 625 rtc::Network network_; |
628 rtc::BasicPacketSocketFactory socket_factory_; | 626 rtc::BasicPacketSocketFactory socket_factory_; |
629 std::unique_ptr<rtc::AsyncPacketSocket> socket_; | 627 std::unique_ptr<rtc::AsyncPacketSocket> socket_; |
630 TestTurnServer turn_server_; | 628 TestTurnServer turn_server_; |
631 std::unique_ptr<TurnPort> turn_port_; | 629 std::unique_ptr<TurnPort> turn_port_; |
632 std::unique_ptr<UDPPort> udp_port_; | 630 std::unique_ptr<UDPPort> udp_port_; |
633 bool turn_ready_; | 631 bool turn_ready_; |
634 bool turn_error_; | 632 bool turn_error_; |
635 bool turn_unknown_address_; | 633 bool turn_unknown_address_; |
636 bool turn_create_permission_success_; | 634 bool turn_create_permission_success_; |
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1293 EXPECT_TRUE(turn_port_->Candidates().empty()); | 1291 EXPECT_TRUE(turn_port_->Candidates().empty()); |
1294 turn_port_.reset(); | 1292 turn_port_.reset(); |
1295 rtc::Thread::Current()->Post(RTC_FROM_HERE, this, MSG_TESTFINISH); | 1293 rtc::Thread::Current()->Post(RTC_FROM_HERE, this, MSG_TESTFINISH); |
1296 // Waiting for above message to be processed. | 1294 // Waiting for above message to be processed. |
1297 ASSERT_TRUE_SIMULATED_WAIT(test_finish_, 1, fake_clock_); | 1295 ASSERT_TRUE_SIMULATED_WAIT(test_finish_, 1, fake_clock_); |
1298 EXPECT_EQ(last_fd_count, GetFDCount()); | 1296 EXPECT_EQ(last_fd_count, GetFDCount()); |
1299 } | 1297 } |
1300 #endif | 1298 #endif |
1301 | 1299 |
1302 } // namespace cricket | 1300 } // namespace cricket |
OLD | NEW |