Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 | 193 |
| 194 private: | 194 private: |
| 195 rtc::scoped_ptr<ByteBuffer> last_stun_buf_; | 195 rtc::scoped_ptr<ByteBuffer> last_stun_buf_; |
| 196 rtc::scoped_ptr<IceMessage> last_stun_msg_; | 196 rtc::scoped_ptr<IceMessage> last_stun_msg_; |
| 197 int type_preference_; | 197 int type_preference_; |
| 198 }; | 198 }; |
| 199 | 199 |
| 200 class TestChannel : public sigslot::has_slots<> { | 200 class TestChannel : public sigslot::has_slots<> { |
| 201 public: | 201 public: |
| 202 // Takes ownership of |p1| (but not |p2|). | 202 // Takes ownership of |p1| (but not |p2|). |
| 203 TestChannel(Port* p1, Port* p2) | 203 TestChannel(Port* p1) |
| 204 : ice_mode_(ICEMODE_FULL), src_(p1), dst_(p2), complete_count_(0), | 204 : ice_mode_(ICEMODE_FULL), |
| 205 conn_(NULL), remote_request_(), nominated_(false) { | 205 port_(p1), |
| 206 src_->SignalPortComplete.connect( | 206 complete_count_(0), |
| 207 this, &TestChannel::OnPortComplete); | 207 conn_(NULL), |
| 208 src_->SignalUnknownAddress.connect(this, &TestChannel::OnUnknownAddress); | 208 remote_request_(), |
| 209 src_->SignalDestroyed.connect(this, &TestChannel::OnSrcPortDestroyed); | 209 nominated_(false) { |
| 210 port_->SignalPortComplete.connect(this, &TestChannel::OnPortComplete); | |
| 211 port_->SignalUnknownAddress.connect(this, &TestChannel::OnUnknownAddress); | |
| 212 port_->SignalDestroyed.connect(this, &TestChannel::OnSrcPortDestroyed); | |
| 210 } | 213 } |
| 211 | 214 |
| 212 int complete_count() { return complete_count_; } | 215 int complete_count() { return complete_count_; } |
| 213 Connection* conn() { return conn_; } | 216 Connection* conn() { return conn_; } |
| 214 const SocketAddress& remote_address() { return remote_address_; } | 217 const SocketAddress& remote_address() { return remote_address_; } |
| 215 const std::string remote_fragment() { return remote_frag_; } | 218 const std::string remote_fragment() { return remote_frag_; } |
| 216 | 219 |
| 217 void Start() { | 220 void Start() { port_->PrepareAddress(); } |
| 218 src_->PrepareAddress(); | 221 void CreateConnection(const Candidate& remote_candidate) { |
| 219 } | 222 conn_ = port_->CreateConnection(remote_candidate, Port::ORIGIN_MESSAGE); |
| 220 void CreateConnection() { | |
| 221 conn_ = src_->CreateConnection(GetCandidate(dst_), Port::ORIGIN_MESSAGE); | |
| 222 IceMode remote_ice_mode = | 223 IceMode remote_ice_mode = |
| 223 (ice_mode_ == ICEMODE_FULL) ? ICEMODE_LITE : ICEMODE_FULL; | 224 (ice_mode_ == ICEMODE_FULL) ? ICEMODE_LITE : ICEMODE_FULL; |
| 224 conn_->set_remote_ice_mode(remote_ice_mode); | 225 conn_->set_remote_ice_mode(remote_ice_mode); |
| 225 conn_->set_use_candidate_attr(remote_ice_mode == ICEMODE_FULL); | 226 conn_->set_use_candidate_attr(remote_ice_mode == ICEMODE_FULL); |
| 226 conn_->SignalStateChange.connect( | 227 conn_->SignalStateChange.connect( |
| 227 this, &TestChannel::OnConnectionStateChange); | 228 this, &TestChannel::OnConnectionStateChange); |
| 228 conn_->SignalDestroyed.connect(this, &TestChannel::OnDestroyed); | 229 conn_->SignalDestroyed.connect(this, &TestChannel::OnDestroyed); |
| 229 conn_->SignalReadyToSend.connect(this, | 230 conn_->SignalReadyToSend.connect(this, |
| 230 &TestChannel::OnConnectionReadyToSend); | 231 &TestChannel::OnConnectionReadyToSend); |
| 231 connection_ready_to_send_ = false; | 232 connection_ready_to_send_ = false; |
| 232 } | 233 } |
| 233 void OnConnectionStateChange(Connection* conn) { | 234 void OnConnectionStateChange(Connection* conn) { |
| 234 if (conn->write_state() == Connection::STATE_WRITABLE) { | 235 if (conn->write_state() == Connection::STATE_WRITABLE) { |
| 235 conn->set_use_candidate_attr(true); | 236 conn->set_use_candidate_attr(true); |
| 236 nominated_ = true; | 237 nominated_ = true; |
| 237 } | 238 } |
| 238 } | 239 } |
| 239 void AcceptConnection() { | 240 void AcceptConnection(const Candidate& remote_candidate) { |
| 240 ASSERT_TRUE(remote_request_.get() != NULL); | 241 ASSERT_TRUE(remote_request_.get() != NULL); |
| 241 Candidate c = GetCandidate(dst_); | 242 Candidate c = remote_candidate; |
| 242 c.set_address(remote_address_); | 243 c.set_address(remote_address_); |
| 243 conn_ = src_->CreateConnection(c, Port::ORIGIN_MESSAGE); | 244 conn_ = port_->CreateConnection(c, Port::ORIGIN_MESSAGE); |
| 244 conn_->SignalDestroyed.connect(this, &TestChannel::OnDestroyed); | 245 conn_->SignalDestroyed.connect(this, &TestChannel::OnDestroyed); |
| 245 src_->SendBindingResponse(remote_request_.get(), remote_address_); | 246 port_->SendBindingResponse(remote_request_.get(), remote_address_); |
| 246 remote_request_.reset(); | 247 remote_request_.reset(); |
| 247 } | 248 } |
| 248 void Ping() { | 249 void Ping() { |
| 249 Ping(0); | 250 Ping(0); |
| 250 } | 251 } |
| 251 void Ping(uint32 now) { | 252 void Ping(uint32 now) { |
| 252 conn_->Ping(now); | 253 conn_->Ping(now); |
| 253 } | 254 } |
| 254 void Stop() { | 255 void Stop() { |
| 255 if (conn_) { | 256 if (conn_) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 266 | 267 |
| 267 int SendData(const char* data, size_t len) { | 268 int SendData(const char* data, size_t len) { |
| 268 rtc::PacketOptions options; | 269 rtc::PacketOptions options; |
| 269 return conn_->Send(data, len, options); | 270 return conn_->Send(data, len, options); |
| 270 } | 271 } |
| 271 | 272 |
| 272 void OnUnknownAddress(PortInterface* port, const SocketAddress& addr, | 273 void OnUnknownAddress(PortInterface* port, const SocketAddress& addr, |
| 273 ProtocolType proto, | 274 ProtocolType proto, |
| 274 IceMessage* msg, const std::string& rf, | 275 IceMessage* msg, const std::string& rf, |
| 275 bool /*port_muxed*/) { | 276 bool /*port_muxed*/) { |
| 276 ASSERT_EQ(src_.get(), port); | 277 ASSERT_EQ(port_.get(), port); |
| 277 if (!remote_address_.IsNil()) { | 278 if (!remote_address_.IsNil()) { |
| 278 ASSERT_EQ(remote_address_, addr); | 279 ASSERT_EQ(remote_address_, addr); |
| 279 } | 280 } |
| 280 const cricket::StunUInt32Attribute* priority_attr = | 281 const cricket::StunUInt32Attribute* priority_attr = |
| 281 msg->GetUInt32(STUN_ATTR_PRIORITY); | 282 msg->GetUInt32(STUN_ATTR_PRIORITY); |
| 282 const cricket::StunByteStringAttribute* mi_attr = | 283 const cricket::StunByteStringAttribute* mi_attr = |
| 283 msg->GetByteString(STUN_ATTR_MESSAGE_INTEGRITY); | 284 msg->GetByteString(STUN_ATTR_MESSAGE_INTEGRITY); |
| 284 const cricket::StunUInt32Attribute* fingerprint_attr = | 285 const cricket::StunUInt32Attribute* fingerprint_attr = |
| 285 msg->GetUInt32(STUN_ATTR_FINGERPRINT); | 286 msg->GetUInt32(STUN_ATTR_FINGERPRINT); |
| 286 EXPECT_TRUE(priority_attr != NULL); | 287 EXPECT_TRUE(priority_attr != NULL); |
| 287 EXPECT_TRUE(mi_attr != NULL); | 288 EXPECT_TRUE(mi_attr != NULL); |
| 288 EXPECT_TRUE(fingerprint_attr != NULL); | 289 EXPECT_TRUE(fingerprint_attr != NULL); |
| 289 remote_address_ = addr; | 290 remote_address_ = addr; |
| 290 remote_request_.reset(CopyStunMessage(msg)); | 291 remote_request_.reset(CopyStunMessage(msg)); |
| 291 remote_frag_ = rf; | 292 remote_frag_ = rf; |
| 292 } | 293 } |
| 293 | 294 |
| 294 void OnDestroyed(Connection* conn) { | 295 void OnDestroyed(Connection* conn) { |
| 295 ASSERT_EQ(conn_, conn); | 296 ASSERT_EQ(conn_, conn); |
| 296 LOG(INFO) << "OnDestroy connection " << conn << " deleted"; | 297 LOG(INFO) << "OnDestroy connection " << conn << " deleted"; |
| 297 conn_ = NULL; | 298 conn_ = NULL; |
| 298 // When the connection is destroyed, also clear these fields so future | 299 // When the connection is destroyed, also clear these fields so future |
| 299 // connections are possible. | 300 // connections are possible. |
| 300 remote_request_.reset(); | 301 remote_request_.reset(); |
| 301 remote_address_.Clear(); | 302 remote_address_.Clear(); |
| 302 } | 303 } |
| 303 | 304 |
| 304 void OnSrcPortDestroyed(PortInterface* port) { | 305 void OnSrcPortDestroyed(PortInterface* port) { |
| 305 Port* destroyed_src = src_.release(); | 306 Port* destroyed_src = port_.release(); |
| 306 ASSERT_EQ(destroyed_src, port); | 307 ASSERT_EQ(destroyed_src, port); |
| 307 } | 308 } |
| 308 | 309 |
| 309 Port* src_port() { return src_.get(); } | 310 Port* port() { return port_.get(); } |
| 310 | 311 |
| 311 bool nominated() const { return nominated_; } | 312 bool nominated() const { return nominated_; } |
| 312 | 313 |
| 313 void set_connection_ready_to_send(bool ready) { | 314 void set_connection_ready_to_send(bool ready) { |
| 314 connection_ready_to_send_ = ready; | 315 connection_ready_to_send_ = ready; |
| 315 } | 316 } |
| 316 bool connection_ready_to_send() const { | 317 bool connection_ready_to_send() const { |
| 317 return connection_ready_to_send_; | 318 return connection_ready_to_send_; |
| 318 } | 319 } |
| 319 | 320 |
| 320 private: | 321 private: |
| 321 // ReadyToSend will only issue after a Connection recovers from EWOULDBLOCK. | 322 // ReadyToSend will only issue after a Connection recovers from EWOULDBLOCK. |
| 322 void OnConnectionReadyToSend(Connection* conn) { | 323 void OnConnectionReadyToSend(Connection* conn) { |
| 323 ASSERT_EQ(conn, conn_); | 324 ASSERT_EQ(conn, conn_); |
| 324 connection_ready_to_send_ = true; | 325 connection_ready_to_send_ = true; |
| 325 } | 326 } |
| 326 | 327 |
| 327 IceMode ice_mode_; | 328 IceMode ice_mode_; |
| 328 rtc::scoped_ptr<Port> src_; | 329 rtc::scoped_ptr<Port> port_; |
| 329 Port* dst_; | |
| 330 | 330 |
| 331 int complete_count_; | 331 int complete_count_; |
| 332 Connection* conn_; | 332 Connection* conn_; |
| 333 SocketAddress remote_address_; | 333 SocketAddress remote_address_; |
| 334 rtc::scoped_ptr<StunMessage> remote_request_; | 334 rtc::scoped_ptr<StunMessage> remote_request_; |
| 335 std::string remote_frag_; | 335 std::string remote_frag_; |
| 336 bool nominated_; | 336 bool nominated_; |
| 337 bool connection_ready_to_send_ = false; | 337 bool connection_ready_to_send_ = false; |
| 338 }; | 338 }; |
| 339 | 339 |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 558 // This connects the provided channels which have already started. |ch1| | 558 // This connects the provided channels which have already started. |ch1| |
| 559 // should have its Connection created (either through CreateConnection() or | 559 // should have its Connection created (either through CreateConnection() or |
| 560 // TCP reconnecting mechanism before entering this function. | 560 // TCP reconnecting mechanism before entering this function. |
| 561 void ConnectStartedChannels(TestChannel* ch1, TestChannel* ch2) { | 561 void ConnectStartedChannels(TestChannel* ch1, TestChannel* ch2) { |
| 562 ASSERT_TRUE(ch1->conn()); | 562 ASSERT_TRUE(ch1->conn()); |
| 563 EXPECT_TRUE_WAIT(ch1->conn()->connected(), kTimeout); // for TCP connect | 563 EXPECT_TRUE_WAIT(ch1->conn()->connected(), kTimeout); // for TCP connect |
| 564 ch1->Ping(); | 564 ch1->Ping(); |
| 565 WAIT(!ch2->remote_address().IsNil(), kTimeout); | 565 WAIT(!ch2->remote_address().IsNil(), kTimeout); |
| 566 | 566 |
| 567 // Send a ping from dst to src. | 567 // Send a ping from dst to src. |
| 568 ch2->AcceptConnection(); | 568 ch2->AcceptConnection(GetCandidate(ch1->port())); |
| 569 ch2->Ping(); | 569 ch2->Ping(); |
| 570 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch2->conn()->write_state(), | 570 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch2->conn()->write_state(), |
| 571 kTimeout); | 571 kTimeout); |
| 572 } | 572 } |
| 573 | 573 |
| 574 // This connects and disconnects the provided channels in the same sequence as | 574 // This connects and disconnects the provided channels in the same sequence as |
| 575 // TestConnectivity with all options set to |true|. It does not delete either | 575 // TestConnectivity with all options set to |true|. It does not delete either |
| 576 // channel. | 576 // channel. |
| 577 void StartConnectAndStopChannels(TestChannel* ch1, TestChannel* ch2) { | 577 void StartConnectAndStopChannels(TestChannel* ch1, TestChannel* ch2) { |
| 578 // Acquire addresses. | 578 // Acquire addresses. |
| 579 ch1->Start(); | 579 ch1->Start(); |
| 580 ch2->Start(); | 580 ch2->Start(); |
| 581 | 581 |
| 582 ch1->CreateConnection(); | 582 ch1->CreateConnection(GetCandidate(ch2->port())); |
| 583 ConnectStartedChannels(ch1, ch2); | 583 ConnectStartedChannels(ch1, ch2); |
| 584 | 584 |
| 585 // Destroy the connections. | 585 // Destroy the connections. |
| 586 ch1->Stop(); | 586 ch1->Stop(); |
| 587 ch2->Stop(); | 587 ch2->Stop(); |
| 588 } | 588 } |
| 589 | 589 |
| 590 // This disconnects both end's Connection and make sure ch2 ready for new | 590 // This disconnects both end's Connection and make sure ch2 ready for new |
| 591 // connection. | 591 // connection. |
| 592 void DisconnectTcpTestChannels(TestChannel* ch1, TestChannel* ch2) { | 592 void DisconnectTcpTestChannels(TestChannel* ch1, TestChannel* ch2) { |
| 593 ASSERT_TRUE(ss_->CloseTcpConnections( | 593 TCPConnection* tcp_conn1 = static_cast<TCPConnection*>(ch1->conn()); |
| 594 static_cast<TCPConnection*>(ch1->conn())->socket()->GetLocalAddress(), | 594 TCPConnection* tcp_conn2 = static_cast<TCPConnection*>(ch2->conn()); |
| 595 static_cast<TCPConnection*>(ch2->conn())->socket()->GetLocalAddress())); | 595 ASSERT_TRUE( |
| 596 ss_->CloseTcpConnections(tcp_conn1->socket()->GetLocalAddress(), | |
| 597 tcp_conn2->socket()->GetLocalAddress())); | |
| 596 | 598 |
| 597 // Wait for both OnClose are delivered. | 599 // Wait for both OnClose are delivered. |
| 598 EXPECT_TRUE_WAIT(!ch1->conn()->connected(), kTimeout); | 600 EXPECT_TRUE_WAIT(!ch1->conn()->connected(), kTimeout); |
| 599 EXPECT_TRUE_WAIT(!ch2->conn()->connected(), kTimeout); | 601 EXPECT_TRUE_WAIT(!ch2->conn()->connected(), kTimeout); |
| 600 | 602 |
| 601 // Destroy channel2 connection to get ready for new incoming TCPConnection. | 603 // Ensure redundant of OnClose on TcpConnection won't break tcp |
|
pthatcher1
2015/08/25 17:58:41
redundant of OnClose on TcpConnection => redundant
guoweis_webrtc
2015/08/25 18:04:14
Done.
| |
| 604 // reconnection. Chromium will call OnClose for all outstanding IPC packets | |
| 605 // during reconnection. | |
|
pthatcher1
2015/08/25 17:58:41
Chromium calls OnClose or fires SignalClose? OnCl
guoweis_webrtc
2015/08/25 18:04:14
Done.
| |
| 606 tcp_conn1->socket()->SignalClose(tcp_conn1->socket(), 0); | |
| 607 tcp_conn2->socket()->SignalClose(tcp_conn2->socket(), 0); | |
| 608 | |
| 609 // Speed up destroying ch2's connection such that the test is ready to | |
| 610 // accept a new connection from ch1 before ch1's connection destroys itself. | |
| 602 ch2->conn()->Destroy(); | 611 ch2->conn()->Destroy(); |
| 603 EXPECT_TRUE_WAIT(ch2->conn() == NULL, kTimeout); | 612 EXPECT_TRUE_WAIT(ch2->conn() == NULL, kTimeout); |
| 604 } | 613 } |
| 605 | 614 |
| 606 void TestTcpReconnect(bool ping_after_disconnected, | 615 void TestTcpReconnect(bool ping_after_disconnected, |
| 607 bool send_after_disconnected) { | 616 bool send_after_disconnected) { |
| 608 Port* port1 = CreateTcpPort(kLocalAddr1); | 617 Port* port1 = CreateTcpPort(kLocalAddr1); |
| 609 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | 618 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 610 Port* port2 = CreateTcpPort(kLocalAddr2); | 619 Port* port2 = CreateTcpPort(kLocalAddr2); |
| 611 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); | 620 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 612 | 621 |
| 613 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); | 622 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); |
| 614 port2->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); | 623 port2->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); |
| 615 | 624 |
| 616 // Set up channels and ensure both ports will be deleted. | 625 // Set up channels and ensure both ports will be deleted. |
| 617 TestChannel ch1(port1, port2); | 626 TestChannel ch1(port1); |
| 618 TestChannel ch2(port2, port1); | 627 TestChannel ch2(port2); |
| 619 EXPECT_EQ(0, ch1.complete_count()); | 628 EXPECT_EQ(0, ch1.complete_count()); |
| 620 EXPECT_EQ(0, ch2.complete_count()); | 629 EXPECT_EQ(0, ch2.complete_count()); |
| 621 | 630 |
| 622 ch1.Start(); | 631 ch1.Start(); |
| 623 ch2.Start(); | 632 ch2.Start(); |
| 624 ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout); | 633 ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout); |
| 625 ASSERT_EQ_WAIT(1, ch2.complete_count(), kTimeout); | 634 ASSERT_EQ_WAIT(1, ch2.complete_count(), kTimeout); |
| 626 | 635 |
| 627 // Initial connecting the channel, create connection on channel1. | 636 // Initial connecting the channel, create connection on channel1. |
| 628 ch1.CreateConnection(); | 637 ch1.CreateConnection(GetCandidate(port2)); |
| 629 ConnectStartedChannels(&ch1, &ch2); | 638 ConnectStartedChannels(&ch1, &ch2); |
| 630 | 639 |
| 631 // Shorten the timeout period. | 640 // Shorten the timeout period. |
| 632 const int kTcpReconnectTimeout = kTimeout; | 641 const int kTcpReconnectTimeout = kTimeout; |
| 633 static_cast<TCPConnection*>(ch1.conn()) | 642 static_cast<TCPConnection*>(ch1.conn()) |
| 634 ->set_reconnection_timeout(kTcpReconnectTimeout); | 643 ->set_reconnection_timeout(kTcpReconnectTimeout); |
| 635 static_cast<TCPConnection*>(ch2.conn()) | 644 static_cast<TCPConnection*>(ch2.conn()) |
| 636 ->set_reconnection_timeout(kTcpReconnectTimeout); | 645 ->set_reconnection_timeout(kTcpReconnectTimeout); |
| 637 | 646 |
| 638 EXPECT_FALSE(ch1.connection_ready_to_send()); | 647 EXPECT_FALSE(ch1.connection_ready_to_send()); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 659 // Verify that we could still connect channels. | 668 // Verify that we could still connect channels. |
| 660 ConnectStartedChannels(&ch1, &ch2); | 669 ConnectStartedChannels(&ch1, &ch2); |
| 661 EXPECT_TRUE_WAIT(ch1.connection_ready_to_send(), | 670 EXPECT_TRUE_WAIT(ch1.connection_ready_to_send(), |
| 662 kTcpReconnectTimeout); | 671 kTcpReconnectTimeout); |
| 663 // Channel2 is the passive one so a new connection is created during | 672 // Channel2 is the passive one so a new connection is created during |
| 664 // reconnect. This new connection should never have issued EWOULDBLOCK | 673 // reconnect. This new connection should never have issued EWOULDBLOCK |
| 665 // hence the connection_ready_to_send() should be false. | 674 // hence the connection_ready_to_send() should be false. |
| 666 EXPECT_FALSE(ch2.connection_ready_to_send()); | 675 EXPECT_FALSE(ch2.connection_ready_to_send()); |
| 667 } else { | 676 } else { |
| 668 EXPECT_EQ(ch1.conn()->write_state(), Connection::STATE_WRITABLE); | 677 EXPECT_EQ(ch1.conn()->write_state(), Connection::STATE_WRITABLE); |
| 669 EXPECT_TRUE_WAIT( | 678 // Since the reconnection never happens, the connections should have been |
| 670 ch1.conn()->write_state() == Connection::STATE_WRITE_TIMEOUT, | 679 // destroyed after the timeout. |
| 671 kTcpReconnectTimeout + kTimeout); | 680 EXPECT_TRUE_WAIT(!ch1.conn(), kTcpReconnectTimeout + kTimeout); |
| 672 EXPECT_FALSE(ch1.connection_ready_to_send()); | 681 EXPECT_TRUE(!ch2.conn()); |
| 673 EXPECT_FALSE(ch2.connection_ready_to_send()); | |
| 674 } | 682 } |
| 675 | 683 |
| 676 // Tear down and ensure that goes smoothly. | 684 // Tear down and ensure that goes smoothly. |
| 677 ch1.Stop(); | 685 ch1.Stop(); |
| 678 ch2.Stop(); | 686 ch2.Stop(); |
| 679 EXPECT_TRUE_WAIT(ch1.conn() == NULL, kTimeout); | 687 EXPECT_TRUE_WAIT(ch1.conn() == NULL, kTimeout); |
| 680 EXPECT_TRUE_WAIT(ch2.conn() == NULL, kTimeout); | 688 EXPECT_TRUE_WAIT(ch2.conn() == NULL, kTimeout); |
| 681 } | 689 } |
| 682 | 690 |
| 683 IceMessage* CreateStunMessage(int type) { | 691 IceMessage* CreateStunMessage(int type) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 723 | 731 |
| 724 void OnDestroyed(PortInterface* port) { | 732 void OnDestroyed(PortInterface* port) { |
| 725 destroyed_ = true; | 733 destroyed_ = true; |
| 726 } | 734 } |
| 727 bool destroyed() const { return destroyed_; } | 735 bool destroyed() const { return destroyed_; } |
| 728 | 736 |
| 729 rtc::BasicPacketSocketFactory* nat_socket_factory1() { | 737 rtc::BasicPacketSocketFactory* nat_socket_factory1() { |
| 730 return &nat_socket_factory1_; | 738 return &nat_socket_factory1_; |
| 731 } | 739 } |
| 732 | 740 |
| 741 protected: | |
| 742 rtc::VirtualSocketServer* vss() { return ss_.get(); } | |
| 743 | |
| 733 private: | 744 private: |
| 734 rtc::Thread* main_; | 745 rtc::Thread* main_; |
| 735 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; | 746 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; |
| 736 rtc::scoped_ptr<rtc::VirtualSocketServer> ss_; | 747 rtc::scoped_ptr<rtc::VirtualSocketServer> ss_; |
| 737 rtc::SocketServerScope ss_scope_; | 748 rtc::SocketServerScope ss_scope_; |
| 738 rtc::Network network_; | 749 rtc::Network network_; |
| 739 rtc::BasicPacketSocketFactory socket_factory_; | 750 rtc::BasicPacketSocketFactory socket_factory_; |
| 740 rtc::scoped_ptr<rtc::NATServer> nat_server1_; | 751 rtc::scoped_ptr<rtc::NATServer> nat_server1_; |
| 741 rtc::scoped_ptr<rtc::NATServer> nat_server2_; | 752 rtc::scoped_ptr<rtc::NATServer> nat_server2_; |
| 742 rtc::NATSocketFactory nat_factory1_; | 753 rtc::NATSocketFactory nat_factory1_; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 754 | 765 |
| 755 void PortTest::TestConnectivity(const char* name1, Port* port1, | 766 void PortTest::TestConnectivity(const char* name1, Port* port1, |
| 756 const char* name2, Port* port2, | 767 const char* name2, Port* port2, |
| 757 bool accept, bool same_addr1, | 768 bool accept, bool same_addr1, |
| 758 bool same_addr2, bool possible) { | 769 bool same_addr2, bool possible) { |
| 759 LOG(LS_INFO) << "Test: " << name1 << " to " << name2 << ": "; | 770 LOG(LS_INFO) << "Test: " << name1 << " to " << name2 << ": "; |
| 760 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); | 771 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); |
| 761 port2->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); | 772 port2->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); |
| 762 | 773 |
| 763 // Set up channels and ensure both ports will be deleted. | 774 // Set up channels and ensure both ports will be deleted. |
| 764 TestChannel ch1(port1, port2); | 775 TestChannel ch1(port1); |
| 765 TestChannel ch2(port2, port1); | 776 TestChannel ch2(port2); |
| 766 EXPECT_EQ(0, ch1.complete_count()); | 777 EXPECT_EQ(0, ch1.complete_count()); |
| 767 EXPECT_EQ(0, ch2.complete_count()); | 778 EXPECT_EQ(0, ch2.complete_count()); |
| 768 | 779 |
| 769 // Acquire addresses. | 780 // Acquire addresses. |
| 770 ch1.Start(); | 781 ch1.Start(); |
| 771 ch2.Start(); | 782 ch2.Start(); |
| 772 ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout); | 783 ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout); |
| 773 ASSERT_EQ_WAIT(1, ch2.complete_count(), kTimeout); | 784 ASSERT_EQ_WAIT(1, ch2.complete_count(), kTimeout); |
| 774 | 785 |
| 775 // Send a ping from src to dst. This may or may not make it. | 786 // Send a ping from src to dst. This may or may not make it. |
| 776 ch1.CreateConnection(); | 787 ch1.CreateConnection(GetCandidate(port2)); |
| 777 ASSERT_TRUE(ch1.conn() != NULL); | 788 ASSERT_TRUE(ch1.conn() != NULL); |
| 778 EXPECT_TRUE_WAIT(ch1.conn()->connected(), kTimeout); // for TCP connect | 789 EXPECT_TRUE_WAIT(ch1.conn()->connected(), kTimeout); // for TCP connect |
| 779 ch1.Ping(); | 790 ch1.Ping(); |
| 780 WAIT(!ch2.remote_address().IsNil(), kTimeout); | 791 WAIT(!ch2.remote_address().IsNil(), kTimeout); |
| 781 | 792 |
| 782 if (accept) { | 793 if (accept) { |
| 783 // We are able to send a ping from src to dst. This is the case when | 794 // We are able to send a ping from src to dst. This is the case when |
| 784 // sending to UDP ports and cone NATs. | 795 // sending to UDP ports and cone NATs. |
| 785 EXPECT_TRUE(ch1.remote_address().IsNil()); | 796 EXPECT_TRUE(ch1.remote_address().IsNil()); |
| 786 EXPECT_EQ(ch2.remote_fragment(), port1->username_fragment()); | 797 EXPECT_EQ(ch2.remote_fragment(), port1->username_fragment()); |
| 787 | 798 |
| 788 // Ensure the ping came from the same address used for src. | 799 // Ensure the ping came from the same address used for src. |
| 789 // This is the case unless the source NAT was symmetric. | 800 // This is the case unless the source NAT was symmetric. |
| 790 if (same_addr1) EXPECT_EQ(ch2.remote_address(), GetAddress(port1)); | 801 if (same_addr1) EXPECT_EQ(ch2.remote_address(), GetAddress(port1)); |
| 791 EXPECT_TRUE(same_addr2); | 802 EXPECT_TRUE(same_addr2); |
| 792 | 803 |
| 793 // Send a ping from dst to src. | 804 // Send a ping from dst to src. |
| 794 ch2.AcceptConnection(); | 805 ch2.AcceptConnection(GetCandidate(port1)); |
| 795 ASSERT_TRUE(ch2.conn() != NULL); | 806 ASSERT_TRUE(ch2.conn() != NULL); |
| 796 ch2.Ping(); | 807 ch2.Ping(); |
| 797 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch2.conn()->write_state(), | 808 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch2.conn()->write_state(), |
| 798 kTimeout); | 809 kTimeout); |
| 799 } else { | 810 } else { |
| 800 // We can't send a ping from src to dst, so flip it around. This will happen | 811 // We can't send a ping from src to dst, so flip it around. This will happen |
| 801 // when the destination NAT is addr/port restricted or symmetric. | 812 // when the destination NAT is addr/port restricted or symmetric. |
| 802 EXPECT_TRUE(ch1.remote_address().IsNil()); | 813 EXPECT_TRUE(ch1.remote_address().IsNil()); |
| 803 EXPECT_TRUE(ch2.remote_address().IsNil()); | 814 EXPECT_TRUE(ch2.remote_address().IsNil()); |
| 804 | 815 |
| 805 // Send a ping from dst to src. Again, this may or may not make it. | 816 // Send a ping from dst to src. Again, this may or may not make it. |
| 806 ch2.CreateConnection(); | 817 ch2.CreateConnection(GetCandidate(port1)); |
| 807 ASSERT_TRUE(ch2.conn() != NULL); | 818 ASSERT_TRUE(ch2.conn() != NULL); |
| 808 ch2.Ping(); | 819 ch2.Ping(); |
| 809 WAIT(ch2.conn()->write_state() == Connection::STATE_WRITABLE, kTimeout); | 820 WAIT(ch2.conn()->write_state() == Connection::STATE_WRITABLE, kTimeout); |
| 810 | 821 |
| 811 if (same_addr1 && same_addr2) { | 822 if (same_addr1 && same_addr2) { |
| 812 // The new ping got back to the source. | 823 // The new ping got back to the source. |
| 813 EXPECT_EQ(Connection::STATE_READABLE, ch1.conn()->read_state()); | 824 EXPECT_EQ(Connection::STATE_READABLE, ch1.conn()->read_state()); |
| 814 EXPECT_EQ(Connection::STATE_WRITABLE, ch2.conn()->write_state()); | 825 EXPECT_EQ(Connection::STATE_WRITABLE, ch2.conn()->write_state()); |
| 815 | 826 |
| 816 // First connection may not be writable if the first ping did not get | 827 // First connection may not be writable if the first ping did not get |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 827 EXPECT_TRUE(ch2.remote_address().IsNil()); | 838 EXPECT_TRUE(ch2.remote_address().IsNil()); |
| 828 | 839 |
| 829 // However, since we have now sent a ping to the source IP, we should be | 840 // However, since we have now sent a ping to the source IP, we should be |
| 830 // able to get a ping from it. This gives us the real source address. | 841 // able to get a ping from it. This gives us the real source address. |
| 831 ch1.Ping(); | 842 ch1.Ping(); |
| 832 EXPECT_TRUE_WAIT(!ch2.remote_address().IsNil(), kTimeout); | 843 EXPECT_TRUE_WAIT(!ch2.remote_address().IsNil(), kTimeout); |
| 833 EXPECT_EQ(Connection::STATE_READ_INIT, ch2.conn()->read_state()); | 844 EXPECT_EQ(Connection::STATE_READ_INIT, ch2.conn()->read_state()); |
| 834 EXPECT_TRUE(ch1.remote_address().IsNil()); | 845 EXPECT_TRUE(ch1.remote_address().IsNil()); |
| 835 | 846 |
| 836 // Pick up the actual address and establish the connection. | 847 // Pick up the actual address and establish the connection. |
| 837 ch2.AcceptConnection(); | 848 ch2.AcceptConnection(GetCandidate(port1)); |
| 838 ASSERT_TRUE(ch2.conn() != NULL); | 849 ASSERT_TRUE(ch2.conn() != NULL); |
| 839 ch2.Ping(); | 850 ch2.Ping(); |
| 840 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch2.conn()->write_state(), | 851 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch2.conn()->write_state(), |
| 841 kTimeout); | 852 kTimeout); |
| 842 } else if (!same_addr2 && possible) { | 853 } else if (!same_addr2 && possible) { |
| 843 // The new ping came in, but from an unexpected address. This will happen | 854 // The new ping came in, but from an unexpected address. This will happen |
| 844 // when the destination NAT is symmetric. | 855 // when the destination NAT is symmetric. |
| 845 EXPECT_FALSE(ch1.remote_address().IsNil()); | 856 EXPECT_FALSE(ch1.remote_address().IsNil()); |
| 846 EXPECT_EQ(Connection::STATE_READ_INIT, ch1.conn()->read_state()); | 857 EXPECT_EQ(Connection::STATE_READ_INIT, ch1.conn()->read_state()); |
| 847 | 858 |
| 848 // Update our address and complete the connection. | 859 // Update our address and complete the connection. |
| 849 ch1.AcceptConnection(); | 860 ch1.AcceptConnection(GetCandidate(port2)); |
| 850 ch1.Ping(); | 861 ch1.Ping(); |
| 851 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch1.conn()->write_state(), | 862 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch1.conn()->write_state(), |
| 852 kTimeout); | 863 kTimeout); |
| 853 } else { // (!possible) | 864 } else { // (!possible) |
| 854 // There should be s no way for the pings to reach each other. Check it. | 865 // There should be s no way for the pings to reach each other. Check it. |
| 855 EXPECT_TRUE(ch1.remote_address().IsNil()); | 866 EXPECT_TRUE(ch1.remote_address().IsNil()); |
| 856 EXPECT_TRUE(ch2.remote_address().IsNil()); | 867 EXPECT_TRUE(ch2.remote_address().IsNil()); |
| 857 ch1.Ping(); | 868 ch1.Ping(); |
| 858 WAIT(!ch2.remote_address().IsNil(), kTimeout); | 869 WAIT(!ch2.remote_address().IsNil(), kTimeout); |
| 859 EXPECT_TRUE(ch1.remote_address().IsNil()); | 870 EXPECT_TRUE(ch1.remote_address().IsNil()); |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1164 } | 1175 } |
| 1165 | 1176 |
| 1166 TEST_F(PortTest, TestTcpReconnectOnPing) { | 1177 TEST_F(PortTest, TestTcpReconnectOnPing) { |
| 1167 TestTcpReconnect(true /* ping */, false /* send */); | 1178 TestTcpReconnect(true /* ping */, false /* send */); |
| 1168 } | 1179 } |
| 1169 | 1180 |
| 1170 TEST_F(PortTest, TestTcpReconnectTimeout) { | 1181 TEST_F(PortTest, TestTcpReconnectTimeout) { |
| 1171 TestTcpReconnect(false /* ping */, false /* send */); | 1182 TestTcpReconnect(false /* ping */, false /* send */); |
| 1172 } | 1183 } |
| 1173 | 1184 |
| 1185 // Test when TcpConnection never connects, the OnClose() will be called to | |
| 1186 // destroy the connection. | |
| 1187 TEST_F(PortTest, TestTcpNeverConnect) { | |
| 1188 Port* port1 = CreateTcpPort(kLocalAddr1); | |
| 1189 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | |
| 1190 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); | |
| 1191 | |
| 1192 // Set up a channel and ensure the port will be deleted. | |
| 1193 TestChannel ch1(port1); | |
| 1194 EXPECT_EQ(0, ch1.complete_count()); | |
| 1195 | |
| 1196 ch1.Start(); | |
| 1197 ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout); | |
| 1198 | |
| 1199 rtc::scoped_ptr<rtc::AsyncSocket> server( | |
| 1200 vss()->CreateAsyncSocket(kLocalAddr2.family(), SOCK_STREAM)); | |
| 1201 // Bind but not listen. | |
| 1202 EXPECT_EQ(0, server->Bind(kLocalAddr2)); | |
| 1203 | |
| 1204 Candidate c = GetCandidate(port1); | |
| 1205 c.set_address(server->GetLocalAddress()); | |
| 1206 | |
| 1207 ch1.CreateConnection(c); | |
| 1208 EXPECT_TRUE(ch1.conn()); | |
| 1209 EXPECT_TRUE_WAIT(!ch1.conn(), kTimeout); // for TCP connect | |
| 1210 } | |
| 1211 | |
| 1174 /* TODO: Enable these once testrelayserver can accept external TCP. | 1212 /* TODO: Enable these once testrelayserver can accept external TCP. |
| 1175 TEST_F(PortTest, TestTcpToTcpRelay) { | 1213 TEST_F(PortTest, TestTcpToTcpRelay) { |
| 1176 TestTcpToRelay(PROTO_TCP); | 1214 TestTcpToRelay(PROTO_TCP); |
| 1177 } | 1215 } |
| 1178 | 1216 |
| 1179 TEST_F(PortTest, TestTcpToSslTcpRelay) { | 1217 TEST_F(PortTest, TestTcpToSslTcpRelay) { |
| 1180 TestTcpToRelay(PROTO_SSLTCP); | 1218 TestTcpToRelay(PROTO_SSLTCP); |
| 1181 } | 1219 } |
| 1182 */ | 1220 */ |
| 1183 | 1221 |
| (...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2155 #endif | 2193 #endif |
| 2156 } | 2194 } |
| 2157 | 2195 |
| 2158 TEST_F(PortTest, TestWritableState) { | 2196 TEST_F(PortTest, TestWritableState) { |
| 2159 UDPPort* port1 = CreateUdpPort(kLocalAddr1); | 2197 UDPPort* port1 = CreateUdpPort(kLocalAddr1); |
| 2160 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | 2198 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 2161 UDPPort* port2 = CreateUdpPort(kLocalAddr2); | 2199 UDPPort* port2 = CreateUdpPort(kLocalAddr2); |
| 2162 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); | 2200 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 2163 | 2201 |
| 2164 // Set up channels. | 2202 // Set up channels. |
| 2165 TestChannel ch1(port1, port2); | 2203 TestChannel ch1(port1); |
| 2166 TestChannel ch2(port2, port1); | 2204 TestChannel ch2(port2); |
| 2167 | 2205 |
| 2168 // Acquire addresses. | 2206 // Acquire addresses. |
| 2169 ch1.Start(); | 2207 ch1.Start(); |
| 2170 ch2.Start(); | 2208 ch2.Start(); |
| 2171 ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout); | 2209 ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout); |
| 2172 ASSERT_EQ_WAIT(1, ch2.complete_count(), kTimeout); | 2210 ASSERT_EQ_WAIT(1, ch2.complete_count(), kTimeout); |
| 2173 | 2211 |
| 2174 // Send a ping from src to dst. | 2212 // Send a ping from src to dst. |
| 2175 ch1.CreateConnection(); | 2213 ch1.CreateConnection(GetCandidate(port2)); |
| 2176 ASSERT_TRUE(ch1.conn() != NULL); | 2214 ASSERT_TRUE(ch1.conn() != NULL); |
| 2177 EXPECT_EQ(Connection::STATE_WRITE_INIT, ch1.conn()->write_state()); | 2215 EXPECT_EQ(Connection::STATE_WRITE_INIT, ch1.conn()->write_state()); |
| 2178 EXPECT_TRUE_WAIT(ch1.conn()->connected(), kTimeout); // for TCP connect | 2216 EXPECT_TRUE_WAIT(ch1.conn()->connected(), kTimeout); // for TCP connect |
| 2179 ch1.Ping(); | 2217 ch1.Ping(); |
| 2180 WAIT(!ch2.remote_address().IsNil(), kTimeout); | 2218 WAIT(!ch2.remote_address().IsNil(), kTimeout); |
| 2181 | 2219 |
| 2182 // Data should be unsendable until the connection is accepted. | 2220 // Data should be unsendable until the connection is accepted. |
| 2183 char data[] = "abcd"; | 2221 char data[] = "abcd"; |
| 2184 int data_size = ARRAY_SIZE(data); | 2222 int data_size = ARRAY_SIZE(data); |
| 2185 rtc::PacketOptions options; | 2223 rtc::PacketOptions options; |
| 2186 EXPECT_EQ(SOCKET_ERROR, ch1.conn()->Send(data, data_size, options)); | 2224 EXPECT_EQ(SOCKET_ERROR, ch1.conn()->Send(data, data_size, options)); |
| 2187 | 2225 |
| 2188 // Accept the connection to return the binding response, transition to | 2226 // Accept the connection to return the binding response, transition to |
| 2189 // writable, and allow data to be sent. | 2227 // writable, and allow data to be sent. |
| 2190 ch2.AcceptConnection(); | 2228 ch2.AcceptConnection(GetCandidate(port1)); |
| 2191 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch1.conn()->write_state(), | 2229 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch1.conn()->write_state(), |
| 2192 kTimeout); | 2230 kTimeout); |
| 2193 EXPECT_EQ(data_size, ch1.conn()->Send(data, data_size, options)); | 2231 EXPECT_EQ(data_size, ch1.conn()->Send(data, data_size, options)); |
| 2194 | 2232 |
| 2195 // Ask the connection to update state as if enough time has passed to lose | 2233 // Ask the connection to update state as if enough time has passed to lose |
| 2196 // full writability and 5 pings went unresponded to. We'll accomplish the | 2234 // full writability and 5 pings went unresponded to. We'll accomplish the |
| 2197 // latter by sending pings but not pumping messages. | 2235 // latter by sending pings but not pumping messages. |
| 2198 for (uint32 i = 1; i <= CONNECTION_WRITE_CONNECT_FAILURES; ++i) { | 2236 for (uint32 i = 1; i <= CONNECTION_WRITE_CONNECT_FAILURES; ++i) { |
| 2199 ch1.Ping(i); | 2237 ch1.Ping(i); |
| 2200 } | 2238 } |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 2226 ch2.Stop(); | 2264 ch2.Stop(); |
| 2227 } | 2265 } |
| 2228 | 2266 |
| 2229 TEST_F(PortTest, TestTimeoutForNeverWritable) { | 2267 TEST_F(PortTest, TestTimeoutForNeverWritable) { |
| 2230 UDPPort* port1 = CreateUdpPort(kLocalAddr1); | 2268 UDPPort* port1 = CreateUdpPort(kLocalAddr1); |
| 2231 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | 2269 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 2232 UDPPort* port2 = CreateUdpPort(kLocalAddr2); | 2270 UDPPort* port2 = CreateUdpPort(kLocalAddr2); |
| 2233 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); | 2271 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 2234 | 2272 |
| 2235 // Set up channels. | 2273 // Set up channels. |
| 2236 TestChannel ch1(port1, port2); | 2274 TestChannel ch1(port1); |
| 2237 TestChannel ch2(port2, port1); | 2275 TestChannel ch2(port2); |
| 2238 | 2276 |
| 2239 // Acquire addresses. | 2277 // Acquire addresses. |
| 2240 ch1.Start(); | 2278 ch1.Start(); |
| 2241 ch2.Start(); | 2279 ch2.Start(); |
| 2242 | 2280 |
| 2243 ch1.CreateConnection(); | 2281 ch1.CreateConnection(GetCandidate(port2)); |
| 2244 ASSERT_TRUE(ch1.conn() != NULL); | 2282 ASSERT_TRUE(ch1.conn() != NULL); |
| 2245 EXPECT_EQ(Connection::STATE_WRITE_INIT, ch1.conn()->write_state()); | 2283 EXPECT_EQ(Connection::STATE_WRITE_INIT, ch1.conn()->write_state()); |
| 2246 | 2284 |
| 2247 // Attempt to go directly to write timeout. | 2285 // Attempt to go directly to write timeout. |
| 2248 for (uint32 i = 1; i <= CONNECTION_WRITE_CONNECT_FAILURES; ++i) { | 2286 for (uint32 i = 1; i <= CONNECTION_WRITE_CONNECT_FAILURES; ++i) { |
| 2249 ch1.Ping(i); | 2287 ch1.Ping(i); |
| 2250 } | 2288 } |
| 2251 ch1.conn()->UpdateState(CONNECTION_WRITE_TIMEOUT + 500u); | 2289 ch1.conn()->UpdateState(CONNECTION_WRITE_TIMEOUT + 500u); |
| 2252 EXPECT_EQ(Connection::STATE_WRITE_TIMEOUT, ch1.conn()->write_state()); | 2290 EXPECT_EQ(Connection::STATE_WRITE_TIMEOUT, ch1.conn()->write_state()); |
| 2253 } | 2291 } |
| 2254 | 2292 |
| 2255 // This test verifies the connection setup between ICEMODE_FULL | 2293 // This test verifies the connection setup between ICEMODE_FULL |
| 2256 // and ICEMODE_LITE. | 2294 // and ICEMODE_LITE. |
| 2257 // In this test |ch1| behaves like FULL mode client and we have created | 2295 // In this test |ch1| behaves like FULL mode client and we have created |
| 2258 // port which responds to the ping message just like LITE client. | 2296 // port which responds to the ping message just like LITE client. |
| 2259 TEST_F(PortTest, TestIceLiteConnectivity) { | 2297 TEST_F(PortTest, TestIceLiteConnectivity) { |
| 2260 TestPort* ice_full_port = CreateTestPort( | 2298 TestPort* ice_full_port = CreateTestPort( |
| 2261 kLocalAddr1, "lfrag", "lpass", | 2299 kLocalAddr1, "lfrag", "lpass", |
| 2262 cricket::ICEROLE_CONTROLLING, kTiebreaker1); | 2300 cricket::ICEROLE_CONTROLLING, kTiebreaker1); |
| 2263 | 2301 |
| 2264 rtc::scoped_ptr<TestPort> ice_lite_port(CreateTestPort( | 2302 rtc::scoped_ptr<TestPort> ice_lite_port(CreateTestPort( |
| 2265 kLocalAddr2, "rfrag", "rpass", | 2303 kLocalAddr2, "rfrag", "rpass", |
| 2266 cricket::ICEROLE_CONTROLLED, kTiebreaker2)); | 2304 cricket::ICEROLE_CONTROLLED, kTiebreaker2)); |
| 2267 // Setup TestChannel. This behaves like FULL mode client. | 2305 // Setup TestChannel. This behaves like FULL mode client. |
| 2268 TestChannel ch1(ice_full_port, ice_lite_port.get()); | 2306 TestChannel ch1(ice_full_port); |
| 2269 ch1.SetIceMode(ICEMODE_FULL); | 2307 ch1.SetIceMode(ICEMODE_FULL); |
| 2270 | 2308 |
| 2271 // Start gathering candidates. | 2309 // Start gathering candidates. |
| 2272 ch1.Start(); | 2310 ch1.Start(); |
| 2273 ice_lite_port->PrepareAddress(); | 2311 ice_lite_port->PrepareAddress(); |
| 2274 | 2312 |
| 2275 ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout); | 2313 ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout); |
| 2276 ASSERT_FALSE(ice_lite_port->Candidates().empty()); | 2314 ASSERT_FALSE(ice_lite_port->Candidates().empty()); |
| 2277 | 2315 |
| 2278 ch1.CreateConnection(); | 2316 ch1.CreateConnection(GetCandidate(ice_lite_port.get())); |
| 2279 ASSERT_TRUE(ch1.conn() != NULL); | 2317 ASSERT_TRUE(ch1.conn() != NULL); |
| 2280 EXPECT_EQ(Connection::STATE_WRITE_INIT, ch1.conn()->write_state()); | 2318 EXPECT_EQ(Connection::STATE_WRITE_INIT, ch1.conn()->write_state()); |
| 2281 | 2319 |
| 2282 // Send ping from full mode client. | 2320 // Send ping from full mode client. |
| 2283 // This ping must not have USE_CANDIDATE_ATTR. | 2321 // This ping must not have USE_CANDIDATE_ATTR. |
| 2284 ch1.Ping(); | 2322 ch1.Ping(); |
| 2285 | 2323 |
| 2286 // Verify stun ping is without USE_CANDIDATE_ATTR. Getting message directly | 2324 // Verify stun ping is without USE_CANDIDATE_ATTR. Getting message directly |
| 2287 // from port. | 2325 // from port. |
| 2288 ASSERT_TRUE_WAIT(ice_full_port->last_stun_msg() != NULL, 1000); | 2326 ASSERT_TRUE_WAIT(ice_full_port->last_stun_msg() != NULL, 1000); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2325 ConnectToSignalDestroyed(port1); | 2363 ConnectToSignalDestroyed(port1); |
| 2326 port1->set_timeout_delay(10); // milliseconds | 2364 port1->set_timeout_delay(10); // milliseconds |
| 2327 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | 2365 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 2328 port1->SetIceTiebreaker(kTiebreaker1); | 2366 port1->SetIceTiebreaker(kTiebreaker1); |
| 2329 | 2367 |
| 2330 UDPPort* port2 = CreateUdpPort(kLocalAddr2); | 2368 UDPPort* port2 = CreateUdpPort(kLocalAddr2); |
| 2331 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); | 2369 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 2332 port2->SetIceTiebreaker(kTiebreaker2); | 2370 port2->SetIceTiebreaker(kTiebreaker2); |
| 2333 | 2371 |
| 2334 // Set up channels and ensure both ports will be deleted. | 2372 // Set up channels and ensure both ports will be deleted. |
| 2335 TestChannel ch1(port1, port2); | 2373 TestChannel ch1(port1); |
| 2336 TestChannel ch2(port2, port1); | 2374 TestChannel ch2(port2); |
| 2337 | 2375 |
| 2338 // Simulate a connection that succeeds, and then is destroyed. | 2376 // Simulate a connection that succeeds, and then is destroyed. |
| 2339 StartConnectAndStopChannels(&ch1, &ch2); | 2377 StartConnectAndStopChannels(&ch1, &ch2); |
| 2340 | 2378 |
| 2341 // After the connection is destroyed, the port should not be destroyed. | 2379 // After the connection is destroyed, the port should not be destroyed. |
| 2342 rtc::Thread::Current()->ProcessMessages(kTimeout); | 2380 rtc::Thread::Current()->ProcessMessages(kTimeout); |
| 2343 EXPECT_FALSE(destroyed()); | 2381 EXPECT_FALSE(destroyed()); |
| 2344 } | 2382 } |
| 2345 | 2383 |
| 2346 // This test case verifies that the CONTROLLED port does time out, but only | 2384 // This test case verifies that the CONTROLLED port does time out, but only |
| 2347 // after connectivity is lost. | 2385 // after connectivity is lost. |
| 2348 TEST_F(PortTest, TestControlledTimeout) { | 2386 TEST_F(PortTest, TestControlledTimeout) { |
| 2349 UDPPort* port1 = CreateUdpPort(kLocalAddr1); | 2387 UDPPort* port1 = CreateUdpPort(kLocalAddr1); |
| 2350 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | 2388 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 2351 port1->SetIceTiebreaker(kTiebreaker1); | 2389 port1->SetIceTiebreaker(kTiebreaker1); |
| 2352 | 2390 |
| 2353 UDPPort* port2 = CreateUdpPort(kLocalAddr2); | 2391 UDPPort* port2 = CreateUdpPort(kLocalAddr2); |
| 2354 ConnectToSignalDestroyed(port2); | 2392 ConnectToSignalDestroyed(port2); |
| 2355 port2->set_timeout_delay(10); // milliseconds | 2393 port2->set_timeout_delay(10); // milliseconds |
| 2356 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); | 2394 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 2357 port2->SetIceTiebreaker(kTiebreaker2); | 2395 port2->SetIceTiebreaker(kTiebreaker2); |
| 2358 | 2396 |
| 2359 // The connection must not be destroyed before a connection is attempted. | 2397 // The connection must not be destroyed before a connection is attempted. |
| 2360 EXPECT_FALSE(destroyed()); | 2398 EXPECT_FALSE(destroyed()); |
| 2361 | 2399 |
| 2362 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); | 2400 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); |
| 2363 port2->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); | 2401 port2->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); |
| 2364 | 2402 |
| 2365 // Set up channels and ensure both ports will be deleted. | 2403 // Set up channels and ensure both ports will be deleted. |
| 2366 TestChannel ch1(port1, port2); | 2404 TestChannel ch1(port1); |
| 2367 TestChannel ch2(port2, port1); | 2405 TestChannel ch2(port2); |
| 2368 | 2406 |
| 2369 // Simulate a connection that succeeds, and then is destroyed. | 2407 // Simulate a connection that succeeds, and then is destroyed. |
| 2370 StartConnectAndStopChannels(&ch1, &ch2); | 2408 StartConnectAndStopChannels(&ch1, &ch2); |
| 2371 | 2409 |
| 2372 // The controlled port should be destroyed after 10 milliseconds. | 2410 // The controlled port should be destroyed after 10 milliseconds. |
| 2373 EXPECT_TRUE_WAIT(destroyed(), kTimeout); | 2411 EXPECT_TRUE_WAIT(destroyed(), kTimeout); |
| 2374 } | 2412 } |
| OLD | NEW |