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 30 matching lines...) Expand all Loading... |
41 using rtc::NATType; | 41 using rtc::NATType; |
42 using rtc::NAT_OPEN_CONE; | 42 using rtc::NAT_OPEN_CONE; |
43 using rtc::NAT_ADDR_RESTRICTED; | 43 using rtc::NAT_ADDR_RESTRICTED; |
44 using rtc::NAT_PORT_RESTRICTED; | 44 using rtc::NAT_PORT_RESTRICTED; |
45 using rtc::NAT_SYMMETRIC; | 45 using rtc::NAT_SYMMETRIC; |
46 using rtc::PacketSocketFactory; | 46 using rtc::PacketSocketFactory; |
47 using rtc::Socket; | 47 using rtc::Socket; |
48 using rtc::SocketAddress; | 48 using rtc::SocketAddress; |
49 using namespace cricket; | 49 using namespace cricket; |
50 | 50 |
51 static const int kTimeout = 1000; | 51 static const int kDefaultTimeout = 3000; |
| 52 static const int kShortTimeout = 1000; |
52 static const SocketAddress kLocalAddr1("192.168.1.2", 0); | 53 static const SocketAddress kLocalAddr1("192.168.1.2", 0); |
53 static const SocketAddress kLocalAddr2("192.168.1.3", 0); | 54 static const SocketAddress kLocalAddr2("192.168.1.3", 0); |
54 static const SocketAddress kNatAddr1("77.77.77.77", rtc::NAT_SERVER_UDP_PORT); | 55 static const SocketAddress kNatAddr1("77.77.77.77", rtc::NAT_SERVER_UDP_PORT); |
55 static const SocketAddress kNatAddr2("88.88.88.88", rtc::NAT_SERVER_UDP_PORT); | 56 static const SocketAddress kNatAddr2("88.88.88.88", rtc::NAT_SERVER_UDP_PORT); |
56 static const SocketAddress kStunAddr("99.99.99.1", STUN_SERVER_PORT); | 57 static const SocketAddress kStunAddr("99.99.99.1", STUN_SERVER_PORT); |
57 static const SocketAddress kRelayUdpIntAddr("99.99.99.2", 5000); | 58 static const SocketAddress kRelayUdpIntAddr("99.99.99.2", 5000); |
58 static const SocketAddress kRelayUdpExtAddr("99.99.99.3", 5001); | 59 static const SocketAddress kRelayUdpExtAddr("99.99.99.3", 5001); |
59 static const SocketAddress kRelayTcpIntAddr("99.99.99.2", 5002); | 60 static const SocketAddress kRelayTcpIntAddr("99.99.99.2", 5002); |
60 static const SocketAddress kRelayTcpExtAddr("99.99.99.3", 5003); | 61 static const SocketAddress kRelayTcpExtAddr("99.99.99.3", 5003); |
61 static const SocketAddress kRelaySslTcpIntAddr("99.99.99.2", 5004); | 62 static const SocketAddress kRelaySslTcpIntAddr("99.99.99.2", 5004); |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 void TestConnectivity(const char* name1, Port* port1, | 580 void TestConnectivity(const char* name1, Port* port1, |
580 const char* name2, Port* port2, | 581 const char* name2, Port* port2, |
581 bool accept, bool same_addr1, | 582 bool accept, bool same_addr1, |
582 bool same_addr2, bool possible); | 583 bool same_addr2, bool possible); |
583 | 584 |
584 // This connects the provided channels which have already started. |ch1| | 585 // This connects the provided channels which have already started. |ch1| |
585 // should have its Connection created (either through CreateConnection() or | 586 // should have its Connection created (either through CreateConnection() or |
586 // TCP reconnecting mechanism before entering this function. | 587 // TCP reconnecting mechanism before entering this function. |
587 void ConnectStartedChannels(TestChannel* ch1, TestChannel* ch2) { | 588 void ConnectStartedChannels(TestChannel* ch1, TestChannel* ch2) { |
588 ASSERT_TRUE(ch1->conn()); | 589 ASSERT_TRUE(ch1->conn()); |
589 EXPECT_TRUE_WAIT(ch1->conn()->connected(), kTimeout); // for TCP connect | 590 EXPECT_TRUE_WAIT(ch1->conn()->connected(), |
| 591 kDefaultTimeout); // for TCP connect |
590 ch1->Ping(); | 592 ch1->Ping(); |
591 WAIT(!ch2->remote_address().IsNil(), kTimeout); | 593 WAIT(!ch2->remote_address().IsNil(), kShortTimeout); |
592 | 594 |
593 // Send a ping from dst to src. | 595 // Send a ping from dst to src. |
594 ch2->AcceptConnection(GetCandidate(ch1->port())); | 596 ch2->AcceptConnection(GetCandidate(ch1->port())); |
595 ch2->Ping(); | 597 ch2->Ping(); |
596 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch2->conn()->write_state(), | 598 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch2->conn()->write_state(), |
597 kTimeout); | 599 kDefaultTimeout); |
598 } | 600 } |
599 | 601 |
600 // This connects and disconnects the provided channels in the same sequence as | 602 // This connects and disconnects the provided channels in the same sequence as |
601 // TestConnectivity with all options set to |true|. It does not delete either | 603 // TestConnectivity with all options set to |true|. It does not delete either |
602 // channel. | 604 // channel. |
603 void StartConnectAndStopChannels(TestChannel* ch1, TestChannel* ch2) { | 605 void StartConnectAndStopChannels(TestChannel* ch1, TestChannel* ch2) { |
604 // Acquire addresses. | 606 // Acquire addresses. |
605 ch1->Start(); | 607 ch1->Start(); |
606 ch2->Start(); | 608 ch2->Start(); |
607 | 609 |
608 ch1->CreateConnection(GetCandidate(ch2->port())); | 610 ch1->CreateConnection(GetCandidate(ch2->port())); |
609 ConnectStartedChannels(ch1, ch2); | 611 ConnectStartedChannels(ch1, ch2); |
610 | 612 |
611 // Destroy the connections. | 613 // Destroy the connections. |
612 ch1->Stop(); | 614 ch1->Stop(); |
613 ch2->Stop(); | 615 ch2->Stop(); |
614 } | 616 } |
615 | 617 |
616 // This disconnects both end's Connection and make sure ch2 ready for new | 618 // This disconnects both end's Connection and make sure ch2 ready for new |
617 // connection. | 619 // connection. |
618 void DisconnectTcpTestChannels(TestChannel* ch1, TestChannel* ch2) { | 620 void DisconnectTcpTestChannels(TestChannel* ch1, TestChannel* ch2) { |
619 TCPConnection* tcp_conn1 = static_cast<TCPConnection*>(ch1->conn()); | 621 TCPConnection* tcp_conn1 = static_cast<TCPConnection*>(ch1->conn()); |
620 TCPConnection* tcp_conn2 = static_cast<TCPConnection*>(ch2->conn()); | 622 TCPConnection* tcp_conn2 = static_cast<TCPConnection*>(ch2->conn()); |
621 ASSERT_TRUE( | 623 ASSERT_TRUE( |
622 ss_->CloseTcpConnections(tcp_conn1->socket()->GetLocalAddress(), | 624 ss_->CloseTcpConnections(tcp_conn1->socket()->GetLocalAddress(), |
623 tcp_conn2->socket()->GetLocalAddress())); | 625 tcp_conn2->socket()->GetLocalAddress())); |
624 | 626 |
625 // Wait for both OnClose are delivered. | 627 // Wait for both OnClose are delivered. |
626 EXPECT_TRUE_WAIT(!ch1->conn()->connected(), kTimeout); | 628 EXPECT_TRUE_WAIT(!ch1->conn()->connected(), kDefaultTimeout); |
627 EXPECT_TRUE_WAIT(!ch2->conn()->connected(), kTimeout); | 629 EXPECT_TRUE_WAIT(!ch2->conn()->connected(), kDefaultTimeout); |
628 | 630 |
629 // Ensure redundant SignalClose events on TcpConnection won't break tcp | 631 // Ensure redundant SignalClose events on TcpConnection won't break tcp |
630 // reconnection. Chromium will fire SignalClose for all outstanding IPC | 632 // reconnection. Chromium will fire SignalClose for all outstanding IPC |
631 // packets during reconnection. | 633 // packets during reconnection. |
632 tcp_conn1->socket()->SignalClose(tcp_conn1->socket(), 0); | 634 tcp_conn1->socket()->SignalClose(tcp_conn1->socket(), 0); |
633 tcp_conn2->socket()->SignalClose(tcp_conn2->socket(), 0); | 635 tcp_conn2->socket()->SignalClose(tcp_conn2->socket(), 0); |
634 | 636 |
635 // Speed up destroying ch2's connection such that the test is ready to | 637 // Speed up destroying ch2's connection such that the test is ready to |
636 // accept a new connection from ch1 before ch1's connection destroys itself. | 638 // accept a new connection from ch1 before ch1's connection destroys itself. |
637 ch2->conn()->Destroy(); | 639 ch2->conn()->Destroy(); |
638 EXPECT_TRUE_WAIT(ch2->conn() == NULL, kTimeout); | 640 EXPECT_TRUE_WAIT(ch2->conn() == NULL, kDefaultTimeout); |
639 } | 641 } |
640 | 642 |
641 void TestTcpReconnect(bool ping_after_disconnected, | 643 void TestTcpReconnect(bool ping_after_disconnected, |
642 bool send_after_disconnected) { | 644 bool send_after_disconnected) { |
643 Port* port1 = CreateTcpPort(kLocalAddr1); | 645 Port* port1 = CreateTcpPort(kLocalAddr1); |
644 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | 646 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
645 Port* port2 = CreateTcpPort(kLocalAddr2); | 647 Port* port2 = CreateTcpPort(kLocalAddr2); |
646 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); | 648 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); |
647 | 649 |
648 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); | 650 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); |
649 port2->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); | 651 port2->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); |
650 | 652 |
651 // Set up channels and ensure both ports will be deleted. | 653 // Set up channels and ensure both ports will be deleted. |
652 TestChannel ch1(port1); | 654 TestChannel ch1(port1); |
653 TestChannel ch2(port2); | 655 TestChannel ch2(port2); |
654 EXPECT_EQ(0, ch1.complete_count()); | 656 EXPECT_EQ(0, ch1.complete_count()); |
655 EXPECT_EQ(0, ch2.complete_count()); | 657 EXPECT_EQ(0, ch2.complete_count()); |
656 | 658 |
657 ch1.Start(); | 659 ch1.Start(); |
658 ch2.Start(); | 660 ch2.Start(); |
659 ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout); | 661 ASSERT_EQ_WAIT(1, ch1.complete_count(), kDefaultTimeout); |
660 ASSERT_EQ_WAIT(1, ch2.complete_count(), kTimeout); | 662 ASSERT_EQ_WAIT(1, ch2.complete_count(), kDefaultTimeout); |
661 | 663 |
662 // Initial connecting the channel, create connection on channel1. | 664 // Initial connecting the channel, create connection on channel1. |
663 ch1.CreateConnection(GetCandidate(port2)); | 665 ch1.CreateConnection(GetCandidate(port2)); |
664 ConnectStartedChannels(&ch1, &ch2); | 666 ConnectStartedChannels(&ch1, &ch2); |
665 | 667 |
666 // Shorten the timeout period. | 668 // Shorten the timeout period. |
667 const int kTcpReconnectTimeout = kTimeout; | 669 const int kTcpReconnectTimeout = kDefaultTimeout; |
668 static_cast<TCPConnection*>(ch1.conn()) | 670 static_cast<TCPConnection*>(ch1.conn()) |
669 ->set_reconnection_timeout(kTcpReconnectTimeout); | 671 ->set_reconnection_timeout(kTcpReconnectTimeout); |
670 static_cast<TCPConnection*>(ch2.conn()) | 672 static_cast<TCPConnection*>(ch2.conn()) |
671 ->set_reconnection_timeout(kTcpReconnectTimeout); | 673 ->set_reconnection_timeout(kTcpReconnectTimeout); |
672 | 674 |
673 EXPECT_FALSE(ch1.connection_ready_to_send()); | 675 EXPECT_FALSE(ch1.connection_ready_to_send()); |
674 EXPECT_FALSE(ch2.connection_ready_to_send()); | 676 EXPECT_FALSE(ch2.connection_ready_to_send()); |
675 | 677 |
676 // Once connected, disconnect them. | 678 // Once connected, disconnect them. |
677 DisconnectTcpTestChannels(&ch1, &ch2); | 679 DisconnectTcpTestChannels(&ch1, &ch2); |
678 | 680 |
679 if (send_after_disconnected || ping_after_disconnected) { | 681 if (send_after_disconnected || ping_after_disconnected) { |
680 if (send_after_disconnected) { | 682 if (send_after_disconnected) { |
681 // First SendData after disconnect should fail but will trigger | 683 // First SendData after disconnect should fail but will trigger |
682 // reconnect. | 684 // reconnect. |
683 EXPECT_EQ(-1, ch1.SendData(data, static_cast<int>(strlen(data)))); | 685 EXPECT_EQ(-1, ch1.SendData(data, static_cast<int>(strlen(data)))); |
684 } | 686 } |
685 | 687 |
686 if (ping_after_disconnected) { | 688 if (ping_after_disconnected) { |
687 // Ping should trigger reconnect. | 689 // Ping should trigger reconnect. |
688 ch1.Ping(); | 690 ch1.Ping(); |
689 } | 691 } |
690 | 692 |
691 // Wait for channel's outgoing TCPConnection connected. | 693 // Wait for channel's outgoing TCPConnection connected. |
692 EXPECT_TRUE_WAIT(ch1.conn()->connected(), kTimeout); | 694 EXPECT_TRUE_WAIT(ch1.conn()->connected(), kDefaultTimeout); |
693 | 695 |
694 // Verify that we could still connect channels. | 696 // Verify that we could still connect channels. |
695 ConnectStartedChannels(&ch1, &ch2); | 697 ConnectStartedChannels(&ch1, &ch2); |
696 EXPECT_TRUE_WAIT(ch1.connection_ready_to_send(), | 698 EXPECT_TRUE_WAIT(ch1.connection_ready_to_send(), |
697 kTcpReconnectTimeout); | 699 kTcpReconnectTimeout); |
698 // Channel2 is the passive one so a new connection is created during | 700 // Channel2 is the passive one so a new connection is created during |
699 // reconnect. This new connection should never have issued ENOTCONN | 701 // reconnect. This new connection should never have issued ENOTCONN |
700 // hence the connection_ready_to_send() should be false. | 702 // hence the connection_ready_to_send() should be false. |
701 EXPECT_FALSE(ch2.connection_ready_to_send()); | 703 EXPECT_FALSE(ch2.connection_ready_to_send()); |
702 } else { | 704 } else { |
703 EXPECT_EQ(ch1.conn()->write_state(), Connection::STATE_WRITABLE); | 705 EXPECT_EQ(ch1.conn()->write_state(), Connection::STATE_WRITABLE); |
704 // Since the reconnection never happens, the connections should have been | 706 // Since the reconnection never happens, the connections should have been |
705 // destroyed after the timeout. | 707 // destroyed after the timeout. |
706 EXPECT_TRUE_WAIT(!ch1.conn(), kTcpReconnectTimeout + kTimeout); | 708 EXPECT_TRUE_WAIT(!ch1.conn(), kTcpReconnectTimeout + kDefaultTimeout); |
707 EXPECT_TRUE(!ch2.conn()); | 709 EXPECT_TRUE(!ch2.conn()); |
708 } | 710 } |
709 | 711 |
710 // Tear down and ensure that goes smoothly. | 712 // Tear down and ensure that goes smoothly. |
711 ch1.Stop(); | 713 ch1.Stop(); |
712 ch2.Stop(); | 714 ch2.Stop(); |
713 EXPECT_TRUE_WAIT(ch1.conn() == NULL, kTimeout); | 715 EXPECT_TRUE_WAIT(ch1.conn() == NULL, kDefaultTimeout); |
714 EXPECT_TRUE_WAIT(ch2.conn() == NULL, kTimeout); | 716 EXPECT_TRUE_WAIT(ch2.conn() == NULL, kDefaultTimeout); |
715 } | 717 } |
716 | 718 |
717 IceMessage* CreateStunMessage(int type) { | 719 IceMessage* CreateStunMessage(int type) { |
718 IceMessage* msg = new IceMessage(); | 720 IceMessage* msg = new IceMessage(); |
719 msg->SetType(type); | 721 msg->SetType(type); |
720 msg->SetTransactionID("TESTTESTTEST"); | 722 msg->SetTransactionID("TESTTESTTEST"); |
721 return msg; | 723 return msg; |
722 } | 724 } |
723 IceMessage* CreateStunMessageWithUsername(int type, | 725 IceMessage* CreateStunMessageWithUsername(int type, |
724 const std::string& username) { | 726 const std::string& username) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 std::string username_; | 785 std::string username_; |
784 std::string password_; | 786 std::string password_; |
785 bool role_conflict_; | 787 bool role_conflict_; |
786 int ports_destroyed_; | 788 int ports_destroyed_; |
787 }; | 789 }; |
788 | 790 |
789 void PortTest::TestConnectivity(const char* name1, Port* port1, | 791 void PortTest::TestConnectivity(const char* name1, Port* port1, |
790 const char* name2, Port* port2, | 792 const char* name2, Port* port2, |
791 bool accept, bool same_addr1, | 793 bool accept, bool same_addr1, |
792 bool same_addr2, bool possible) { | 794 bool same_addr2, bool possible) { |
| 795 rtc::ScopedFakeClock clock; |
793 LOG(LS_INFO) << "Test: " << name1 << " to " << name2 << ": "; | 796 LOG(LS_INFO) << "Test: " << name1 << " to " << name2 << ": "; |
794 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); | 797 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); |
795 port2->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); | 798 port2->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); |
796 | 799 |
797 // Set up channels and ensure both ports will be deleted. | 800 // Set up channels and ensure both ports will be deleted. |
798 TestChannel ch1(port1); | 801 TestChannel ch1(port1); |
799 TestChannel ch2(port2); | 802 TestChannel ch2(port2); |
800 EXPECT_EQ(0, ch1.complete_count()); | 803 EXPECT_EQ(0, ch1.complete_count()); |
801 EXPECT_EQ(0, ch2.complete_count()); | 804 EXPECT_EQ(0, ch2.complete_count()); |
802 | 805 |
803 // Acquire addresses. | 806 // Acquire addresses. |
804 ch1.Start(); | 807 ch1.Start(); |
805 ch2.Start(); | 808 ch2.Start(); |
806 ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout); | 809 ASSERT_EQ_SIMULATED_WAIT(1, ch1.complete_count(), kDefaultTimeout, clock); |
807 ASSERT_EQ_WAIT(1, ch2.complete_count(), kTimeout); | 810 ASSERT_EQ_SIMULATED_WAIT(1, ch2.complete_count(), kDefaultTimeout, clock); |
808 | 811 |
809 // Send a ping from src to dst. This may or may not make it. | 812 // Send a ping from src to dst. This may or may not make it. |
810 ch1.CreateConnection(GetCandidate(port2)); | 813 ch1.CreateConnection(GetCandidate(port2)); |
811 ASSERT_TRUE(ch1.conn() != NULL); | 814 ASSERT_TRUE(ch1.conn() != NULL); |
812 EXPECT_TRUE_WAIT(ch1.conn()->connected(), kTimeout); // for TCP connect | 815 EXPECT_TRUE_SIMULATED_WAIT(ch1.conn()->connected(), kDefaultTimeout, |
| 816 clock); // for TCP connect |
813 ch1.Ping(); | 817 ch1.Ping(); |
814 WAIT(!ch2.remote_address().IsNil(), kTimeout); | 818 SIMULATED_WAIT(!ch2.remote_address().IsNil(), kShortTimeout, clock); |
815 | 819 |
816 if (accept) { | 820 if (accept) { |
817 // We are able to send a ping from src to dst. This is the case when | 821 // We are able to send a ping from src to dst. This is the case when |
818 // sending to UDP ports and cone NATs. | 822 // sending to UDP ports and cone NATs. |
819 EXPECT_TRUE(ch1.remote_address().IsNil()); | 823 EXPECT_TRUE(ch1.remote_address().IsNil()); |
820 EXPECT_EQ(ch2.remote_fragment(), port1->username_fragment()); | 824 EXPECT_EQ(ch2.remote_fragment(), port1->username_fragment()); |
821 | 825 |
822 // Ensure the ping came from the same address used for src. | 826 // Ensure the ping came from the same address used for src. |
823 // This is the case unless the source NAT was symmetric. | 827 // This is the case unless the source NAT was symmetric. |
824 if (same_addr1) EXPECT_EQ(ch2.remote_address(), GetAddress(port1)); | 828 if (same_addr1) EXPECT_EQ(ch2.remote_address(), GetAddress(port1)); |
825 EXPECT_TRUE(same_addr2); | 829 EXPECT_TRUE(same_addr2); |
826 | 830 |
827 // Send a ping from dst to src. | 831 // Send a ping from dst to src. |
828 ch2.AcceptConnection(GetCandidate(port1)); | 832 ch2.AcceptConnection(GetCandidate(port1)); |
829 ASSERT_TRUE(ch2.conn() != NULL); | 833 ASSERT_TRUE(ch2.conn() != NULL); |
830 ch2.Ping(); | 834 ch2.Ping(); |
831 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch2.conn()->write_state(), | 835 EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, |
832 kTimeout); | 836 ch2.conn()->write_state(), kDefaultTimeout, clock); |
833 } else { | 837 } else { |
834 // We can't send a ping from src to dst, so flip it around. This will happen | 838 // We can't send a ping from src to dst, so flip it around. This will happen |
835 // when the destination NAT is addr/port restricted or symmetric. | 839 // when the destination NAT is addr/port restricted or symmetric. |
836 EXPECT_TRUE(ch1.remote_address().IsNil()); | 840 EXPECT_TRUE(ch1.remote_address().IsNil()); |
837 EXPECT_TRUE(ch2.remote_address().IsNil()); | 841 EXPECT_TRUE(ch2.remote_address().IsNil()); |
838 | 842 |
839 // Send a ping from dst to src. Again, this may or may not make it. | 843 // Send a ping from dst to src. Again, this may or may not make it. |
840 ch2.CreateConnection(GetCandidate(port1)); | 844 ch2.CreateConnection(GetCandidate(port1)); |
841 ASSERT_TRUE(ch2.conn() != NULL); | 845 ASSERT_TRUE(ch2.conn() != NULL); |
842 ch2.Ping(); | 846 ch2.Ping(); |
843 WAIT(ch2.conn()->write_state() == Connection::STATE_WRITABLE, kTimeout); | 847 SIMULATED_WAIT(ch2.conn()->write_state() == Connection::STATE_WRITABLE, |
| 848 kShortTimeout, clock); |
844 | 849 |
845 if (same_addr1 && same_addr2) { | 850 if (same_addr1 && same_addr2) { |
846 // The new ping got back to the source. | 851 // The new ping got back to the source. |
847 EXPECT_TRUE(ch1.conn()->receiving()); | 852 EXPECT_TRUE(ch1.conn()->receiving()); |
848 EXPECT_EQ(Connection::STATE_WRITABLE, ch2.conn()->write_state()); | 853 EXPECT_EQ(Connection::STATE_WRITABLE, ch2.conn()->write_state()); |
849 | 854 |
850 // First connection may not be writable if the first ping did not get | 855 // First connection may not be writable if the first ping did not get |
851 // through. So we will have to do another. | 856 // through. So we will have to do another. |
852 if (ch1.conn()->write_state() == Connection::STATE_WRITE_INIT) { | 857 if (ch1.conn()->write_state() == Connection::STATE_WRITE_INIT) { |
853 ch1.Ping(); | 858 ch1.Ping(); |
854 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch1.conn()->write_state(), | 859 EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, |
855 kTimeout); | 860 ch1.conn()->write_state(), kDefaultTimeout, |
| 861 clock); |
856 } | 862 } |
857 } else if (!same_addr1 && possible) { | 863 } else if (!same_addr1 && possible) { |
858 // The new ping went to the candidate address, but that address was bad. | 864 // The new ping went to the candidate address, but that address was bad. |
859 // This will happen when the source NAT is symmetric. | 865 // This will happen when the source NAT is symmetric. |
860 EXPECT_TRUE(ch1.remote_address().IsNil()); | 866 EXPECT_TRUE(ch1.remote_address().IsNil()); |
861 EXPECT_TRUE(ch2.remote_address().IsNil()); | 867 EXPECT_TRUE(ch2.remote_address().IsNil()); |
862 | 868 |
863 // However, since we have now sent a ping to the source IP, we should be | 869 // However, since we have now sent a ping to the source IP, we should be |
864 // able to get a ping from it. This gives us the real source address. | 870 // able to get a ping from it. This gives us the real source address. |
865 ch1.Ping(); | 871 ch1.Ping(); |
866 EXPECT_TRUE_WAIT(!ch2.remote_address().IsNil(), kTimeout); | 872 EXPECT_TRUE_SIMULATED_WAIT(!ch2.remote_address().IsNil(), kDefaultTimeout, |
| 873 clock); |
867 EXPECT_FALSE(ch2.conn()->receiving()); | 874 EXPECT_FALSE(ch2.conn()->receiving()); |
868 EXPECT_TRUE(ch1.remote_address().IsNil()); | 875 EXPECT_TRUE(ch1.remote_address().IsNil()); |
869 | 876 |
870 // Pick up the actual address and establish the connection. | 877 // Pick up the actual address and establish the connection. |
871 ch2.AcceptConnection(GetCandidate(port1)); | 878 ch2.AcceptConnection(GetCandidate(port1)); |
872 ASSERT_TRUE(ch2.conn() != NULL); | 879 ASSERT_TRUE(ch2.conn() != NULL); |
873 ch2.Ping(); | 880 ch2.Ping(); |
874 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch2.conn()->write_state(), | 881 EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, |
875 kTimeout); | 882 ch2.conn()->write_state(), kDefaultTimeout, |
| 883 clock); |
876 } else if (!same_addr2 && possible) { | 884 } else if (!same_addr2 && possible) { |
877 // The new ping came in, but from an unexpected address. This will happen | 885 // The new ping came in, but from an unexpected address. This will happen |
878 // when the destination NAT is symmetric. | 886 // when the destination NAT is symmetric. |
879 EXPECT_FALSE(ch1.remote_address().IsNil()); | 887 EXPECT_FALSE(ch1.remote_address().IsNil()); |
880 EXPECT_FALSE(ch1.conn()->receiving()); | 888 EXPECT_FALSE(ch1.conn()->receiving()); |
881 | 889 |
882 // Update our address and complete the connection. | 890 // Update our address and complete the connection. |
883 ch1.AcceptConnection(GetCandidate(port2)); | 891 ch1.AcceptConnection(GetCandidate(port2)); |
884 ch1.Ping(); | 892 ch1.Ping(); |
885 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch1.conn()->write_state(), | 893 EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, |
886 kTimeout); | 894 ch1.conn()->write_state(), kDefaultTimeout, |
| 895 clock); |
887 } else { // (!possible) | 896 } else { // (!possible) |
888 // There should be s no way for the pings to reach each other. Check it. | 897 // There should be s no way for the pings to reach each other. Check it. |
889 EXPECT_TRUE(ch1.remote_address().IsNil()); | 898 EXPECT_TRUE(ch1.remote_address().IsNil()); |
890 EXPECT_TRUE(ch2.remote_address().IsNil()); | 899 EXPECT_TRUE(ch2.remote_address().IsNil()); |
891 ch1.Ping(); | 900 ch1.Ping(); |
892 WAIT(!ch2.remote_address().IsNil(), kTimeout); | 901 SIMULATED_WAIT(!ch2.remote_address().IsNil(), kShortTimeout, clock); |
893 EXPECT_TRUE(ch1.remote_address().IsNil()); | 902 EXPECT_TRUE(ch1.remote_address().IsNil()); |
894 EXPECT_TRUE(ch2.remote_address().IsNil()); | 903 EXPECT_TRUE(ch2.remote_address().IsNil()); |
895 } | 904 } |
896 } | 905 } |
897 | 906 |
898 // Everything should be good, unless we know the situation is impossible. | 907 // Everything should be good, unless we know the situation is impossible. |
899 ASSERT_TRUE(ch1.conn() != NULL); | 908 ASSERT_TRUE(ch1.conn() != NULL); |
900 ASSERT_TRUE(ch2.conn() != NULL); | 909 ASSERT_TRUE(ch2.conn() != NULL); |
901 if (possible) { | 910 if (possible) { |
902 EXPECT_TRUE(ch1.conn()->receiving()); | 911 EXPECT_TRUE(ch1.conn()->receiving()); |
903 EXPECT_EQ(Connection::STATE_WRITABLE, ch1.conn()->write_state()); | 912 EXPECT_EQ(Connection::STATE_WRITABLE, ch1.conn()->write_state()); |
904 EXPECT_TRUE(ch2.conn()->receiving()); | 913 EXPECT_TRUE(ch2.conn()->receiving()); |
905 EXPECT_EQ(Connection::STATE_WRITABLE, ch2.conn()->write_state()); | 914 EXPECT_EQ(Connection::STATE_WRITABLE, ch2.conn()->write_state()); |
906 } else { | 915 } else { |
907 EXPECT_FALSE(ch1.conn()->receiving()); | 916 EXPECT_FALSE(ch1.conn()->receiving()); |
908 EXPECT_NE(Connection::STATE_WRITABLE, ch1.conn()->write_state()); | 917 EXPECT_NE(Connection::STATE_WRITABLE, ch1.conn()->write_state()); |
909 EXPECT_FALSE(ch2.conn()->receiving()); | 918 EXPECT_FALSE(ch2.conn()->receiving()); |
910 EXPECT_NE(Connection::STATE_WRITABLE, ch2.conn()->write_state()); | 919 EXPECT_NE(Connection::STATE_WRITABLE, ch2.conn()->write_state()); |
911 } | 920 } |
912 | 921 |
913 // Tear down and ensure that goes smoothly. | 922 // Tear down and ensure that goes smoothly. |
914 ch1.Stop(); | 923 ch1.Stop(); |
915 ch2.Stop(); | 924 ch2.Stop(); |
916 EXPECT_TRUE_WAIT(ch1.conn() == NULL, kTimeout); | 925 EXPECT_TRUE_SIMULATED_WAIT(ch1.conn() == NULL, kDefaultTimeout, clock); |
917 EXPECT_TRUE_WAIT(ch2.conn() == NULL, kTimeout); | 926 EXPECT_TRUE_SIMULATED_WAIT(ch2.conn() == NULL, kDefaultTimeout, clock); |
918 } | 927 } |
919 | 928 |
920 class FakePacketSocketFactory : public rtc::PacketSocketFactory { | 929 class FakePacketSocketFactory : public rtc::PacketSocketFactory { |
921 public: | 930 public: |
922 FakePacketSocketFactory() | 931 FakePacketSocketFactory() |
923 : next_udp_socket_(NULL), | 932 : next_udp_socket_(NULL), |
924 next_server_tcp_socket_(NULL), | 933 next_server_tcp_socket_(NULL), |
925 next_client_tcp_socket_(NULL) { | 934 next_client_tcp_socket_(NULL) { |
926 } | 935 } |
927 ~FakePacketSocketFactory() override { } | 936 ~FakePacketSocketFactory() override { } |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1210 TEST_F(PortTest, TestTcpNeverConnect) { | 1219 TEST_F(PortTest, TestTcpNeverConnect) { |
1211 Port* port1 = CreateTcpPort(kLocalAddr1); | 1220 Port* port1 = CreateTcpPort(kLocalAddr1); |
1212 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1221 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
1213 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); | 1222 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); |
1214 | 1223 |
1215 // Set up a channel and ensure the port will be deleted. | 1224 // Set up a channel and ensure the port will be deleted. |
1216 TestChannel ch1(port1); | 1225 TestChannel ch1(port1); |
1217 EXPECT_EQ(0, ch1.complete_count()); | 1226 EXPECT_EQ(0, ch1.complete_count()); |
1218 | 1227 |
1219 ch1.Start(); | 1228 ch1.Start(); |
1220 ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout); | 1229 ASSERT_EQ_WAIT(1, ch1.complete_count(), kDefaultTimeout); |
1221 | 1230 |
1222 std::unique_ptr<rtc::AsyncSocket> server( | 1231 std::unique_ptr<rtc::AsyncSocket> server( |
1223 vss()->CreateAsyncSocket(kLocalAddr2.family(), SOCK_STREAM)); | 1232 vss()->CreateAsyncSocket(kLocalAddr2.family(), SOCK_STREAM)); |
1224 // Bind but not listen. | 1233 // Bind but not listen. |
1225 EXPECT_EQ(0, server->Bind(kLocalAddr2)); | 1234 EXPECT_EQ(0, server->Bind(kLocalAddr2)); |
1226 | 1235 |
1227 Candidate c = GetCandidate(port1); | 1236 Candidate c = GetCandidate(port1); |
1228 c.set_address(server->GetLocalAddress()); | 1237 c.set_address(server->GetLocalAddress()); |
1229 | 1238 |
1230 ch1.CreateConnection(c); | 1239 ch1.CreateConnection(c); |
1231 EXPECT_TRUE(ch1.conn()); | 1240 EXPECT_TRUE(ch1.conn()); |
1232 EXPECT_TRUE_WAIT(!ch1.conn(), kTimeout); // for TCP connect | 1241 EXPECT_TRUE_WAIT(!ch1.conn(), kDefaultTimeout); // for TCP connect |
1233 } | 1242 } |
1234 | 1243 |
1235 /* TODO: Enable these once testrelayserver can accept external TCP. | 1244 /* TODO: Enable these once testrelayserver can accept external TCP. |
1236 TEST_F(PortTest, TestTcpToTcpRelay) { | 1245 TEST_F(PortTest, TestTcpToTcpRelay) { |
1237 TestTcpToRelay(PROTO_TCP); | 1246 TestTcpToRelay(PROTO_TCP); |
1238 } | 1247 } |
1239 | 1248 |
1240 TEST_F(PortTest, TestTcpToSslTcpRelay) { | 1249 TEST_F(PortTest, TestTcpToSslTcpRelay) { |
1241 TestTcpToRelay(PROTO_SSLTCP); | 1250 TestTcpToRelay(PROTO_SSLTCP); |
1242 } | 1251 } |
(...skipping 16 matching lines...) Expand all Loading... |
1259 // ii) it has not received anything for DEAD_CONNECTION_RECEIVE_TIMEOUT | 1268 // ii) it has not received anything for DEAD_CONNECTION_RECEIVE_TIMEOUT |
1260 // milliseconds since last receiving. | 1269 // milliseconds since last receiving. |
1261 TEST_F(PortTest, TestConnectionDead) { | 1270 TEST_F(PortTest, TestConnectionDead) { |
1262 UDPPort* port1 = CreateUdpPort(kLocalAddr1); | 1271 UDPPort* port1 = CreateUdpPort(kLocalAddr1); |
1263 UDPPort* port2 = CreateUdpPort(kLocalAddr2); | 1272 UDPPort* port2 = CreateUdpPort(kLocalAddr2); |
1264 TestChannel ch1(port1); | 1273 TestChannel ch1(port1); |
1265 TestChannel ch2(port2); | 1274 TestChannel ch2(port2); |
1266 // Acquire address. | 1275 // Acquire address. |
1267 ch1.Start(); | 1276 ch1.Start(); |
1268 ch2.Start(); | 1277 ch2.Start(); |
1269 ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout); | 1278 ASSERT_EQ_WAIT(1, ch1.complete_count(), kDefaultTimeout); |
1270 ASSERT_EQ_WAIT(1, ch2.complete_count(), kTimeout); | 1279 ASSERT_EQ_WAIT(1, ch2.complete_count(), kDefaultTimeout); |
1271 | 1280 |
1272 // Test case that the connection has never received anything. | 1281 // Test case that the connection has never received anything. |
1273 int64_t before_created = rtc::TimeMillis(); | 1282 int64_t before_created = rtc::TimeMillis(); |
1274 ch1.CreateConnection(GetCandidate(port2)); | 1283 ch1.CreateConnection(GetCandidate(port2)); |
1275 int64_t after_created = rtc::TimeMillis(); | 1284 int64_t after_created = rtc::TimeMillis(); |
1276 Connection* conn = ch1.conn(); | 1285 Connection* conn = ch1.conn(); |
1277 ASSERT(conn != nullptr); | 1286 ASSERT(conn != nullptr); |
1278 // It is not dead if it is after MIN_CONNECTION_LIFETIME but not pruned. | 1287 // It is not dead if it is after MIN_CONNECTION_LIFETIME but not pruned. |
1279 conn->UpdateState(after_created + MIN_CONNECTION_LIFETIME + 1); | 1288 conn->UpdateState(after_created + MIN_CONNECTION_LIFETIME + 1); |
1280 rtc::Thread::Current()->ProcessMessages(0); | 1289 rtc::Thread::Current()->ProcessMessages(0); |
1281 EXPECT_TRUE(ch1.conn() != nullptr); | 1290 EXPECT_TRUE(ch1.conn() != nullptr); |
1282 // It is not dead if it is before MIN_CONNECTION_LIFETIME and pruned. | 1291 // It is not dead if it is before MIN_CONNECTION_LIFETIME and pruned. |
1283 conn->UpdateState(before_created + MIN_CONNECTION_LIFETIME - 1); | 1292 conn->UpdateState(before_created + MIN_CONNECTION_LIFETIME - 1); |
1284 conn->Prune(); | 1293 conn->Prune(); |
1285 rtc::Thread::Current()->ProcessMessages(0); | 1294 rtc::Thread::Current()->ProcessMessages(0); |
1286 EXPECT_TRUE(ch1.conn() != nullptr); | 1295 EXPECT_TRUE(ch1.conn() != nullptr); |
1287 // It will be dead after MIN_CONNECTION_LIFETIME and pruned. | 1296 // It will be dead after MIN_CONNECTION_LIFETIME and pruned. |
1288 conn->UpdateState(after_created + MIN_CONNECTION_LIFETIME + 1); | 1297 conn->UpdateState(after_created + MIN_CONNECTION_LIFETIME + 1); |
1289 EXPECT_TRUE_WAIT(ch1.conn() == nullptr, kTimeout); | 1298 EXPECT_TRUE_WAIT(ch1.conn() == nullptr, kDefaultTimeout); |
1290 | 1299 |
1291 // Test case that the connection has received something. | 1300 // Test case that the connection has received something. |
1292 // Create a connection again and receive a ping. | 1301 // Create a connection again and receive a ping. |
1293 ch1.CreateConnection(GetCandidate(port2)); | 1302 ch1.CreateConnection(GetCandidate(port2)); |
1294 conn = ch1.conn(); | 1303 conn = ch1.conn(); |
1295 ASSERT(conn != nullptr); | 1304 ASSERT(conn != nullptr); |
1296 int64_t before_last_receiving = rtc::TimeMillis(); | 1305 int64_t before_last_receiving = rtc::TimeMillis(); |
1297 conn->ReceivedPing(); | 1306 conn->ReceivedPing(); |
1298 int64_t after_last_receiving = rtc::TimeMillis(); | 1307 int64_t after_last_receiving = rtc::TimeMillis(); |
1299 // The connection will be dead after DEAD_CONNECTION_RECEIVE_TIMEOUT | 1308 // The connection will be dead after DEAD_CONNECTION_RECEIVE_TIMEOUT |
1300 conn->UpdateState( | 1309 conn->UpdateState( |
1301 before_last_receiving + DEAD_CONNECTION_RECEIVE_TIMEOUT - 1); | 1310 before_last_receiving + DEAD_CONNECTION_RECEIVE_TIMEOUT - 1); |
1302 rtc::Thread::Current()->ProcessMessages(100); | 1311 rtc::Thread::Current()->ProcessMessages(100); |
1303 EXPECT_TRUE(ch1.conn() != nullptr); | 1312 EXPECT_TRUE(ch1.conn() != nullptr); |
1304 conn->UpdateState(after_last_receiving + DEAD_CONNECTION_RECEIVE_TIMEOUT + 1); | 1313 conn->UpdateState(after_last_receiving + DEAD_CONNECTION_RECEIVE_TIMEOUT + 1); |
1305 EXPECT_TRUE_WAIT(ch1.conn() == nullptr, kTimeout); | 1314 EXPECT_TRUE_WAIT(ch1.conn() == nullptr, kDefaultTimeout); |
1306 } | 1315 } |
1307 | 1316 |
1308 // This test case verifies standard ICE features in STUN messages. Currently it | 1317 // This test case verifies standard ICE features in STUN messages. Currently it |
1309 // verifies Message Integrity attribute in STUN messages and username in STUN | 1318 // verifies Message Integrity attribute in STUN messages and username in STUN |
1310 // binding request will have colon (":") between remote and local username. | 1319 // binding request will have colon (":") between remote and local username. |
1311 TEST_F(PortTest, TestLocalToLocalStandard) { | 1320 TEST_F(PortTest, TestLocalToLocalStandard) { |
1312 UDPPort* port1 = CreateUdpPort(kLocalAddr1); | 1321 UDPPort* port1 = CreateUdpPort(kLocalAddr1); |
1313 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1322 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
1314 port1->SetIceTiebreaker(kTiebreaker1); | 1323 port1->SetIceTiebreaker(kTiebreaker1); |
1315 UDPPort* port2 = CreateUdpPort(kLocalAddr2); | 1324 UDPPort* port2 = CreateUdpPort(kLocalAddr2); |
1316 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); | 1325 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); |
1317 port2->SetIceTiebreaker(kTiebreaker2); | 1326 port2->SetIceTiebreaker(kTiebreaker2); |
1318 // Same parameters as TestLocalToLocal above. | 1327 // Same parameters as TestLocalToLocal above. |
1319 TestConnectivity("udp", port1, "udp", port2, true, true, true, true); | 1328 TestConnectivity("udp", port1, "udp", port2, true, true, true, true); |
1320 } | 1329 } |
1321 | 1330 |
1322 // This test is trying to validate a successful and failure scenario in a | 1331 // This test is trying to validate a successful and failure scenario in a |
1323 // loopback test when protocol is RFC5245. For success IceTiebreaker, username | 1332 // loopback test when protocol is RFC5245. For success IceTiebreaker, username |
1324 // should remain equal to the request generated by the port and role of port | 1333 // should remain equal to the request generated by the port and role of port |
1325 // must be in controlling. | 1334 // must be in controlling. |
1326 TEST_F(PortTest, TestLoopbackCal) { | 1335 TEST_F(PortTest, TestLoopbackCall) { |
1327 std::unique_ptr<TestPort> lport( | 1336 std::unique_ptr<TestPort> lport( |
1328 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); | 1337 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); |
1329 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1338 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); |
1330 lport->SetIceTiebreaker(kTiebreaker1); | 1339 lport->SetIceTiebreaker(kTiebreaker1); |
1331 lport->PrepareAddress(); | 1340 lport->PrepareAddress(); |
1332 ASSERT_FALSE(lport->Candidates().empty()); | 1341 ASSERT_FALSE(lport->Candidates().empty()); |
1333 Connection* conn = lport->CreateConnection(lport->Candidates()[0], | 1342 Connection* conn = lport->CreateConnection(lport->Candidates()[0], |
1334 Port::ORIGIN_MESSAGE); | 1343 Port::ORIGIN_MESSAGE); |
1335 conn->Ping(0); | 1344 conn->Ping(0); |
1336 | 1345 |
1337 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); | 1346 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout); |
1338 IceMessage* msg = lport->last_stun_msg(); | 1347 IceMessage* msg = lport->last_stun_msg(); |
1339 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); | 1348 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); |
1340 conn->OnReadPacket(lport->last_stun_buf()->data<char>(), | 1349 conn->OnReadPacket(lport->last_stun_buf()->data<char>(), |
1341 lport->last_stun_buf()->size(), | 1350 lport->last_stun_buf()->size(), |
1342 rtc::PacketTime()); | 1351 rtc::PacketTime()); |
1343 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); | 1352 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout); |
1344 msg = lport->last_stun_msg(); | 1353 msg = lport->last_stun_msg(); |
1345 EXPECT_EQ(STUN_BINDING_RESPONSE, msg->type()); | 1354 EXPECT_EQ(STUN_BINDING_RESPONSE, msg->type()); |
1346 | 1355 |
1347 // If the tiebreaker value is different from port, we expect a error | 1356 // If the tiebreaker value is different from port, we expect a error |
1348 // response. | 1357 // response. |
1349 lport->Reset(); | 1358 lport->Reset(); |
1350 lport->AddCandidateAddress(kLocalAddr2); | 1359 lport->AddCandidateAddress(kLocalAddr2); |
1351 // Creating a different connection as |conn| is receiving. | 1360 // Creating a different connection as |conn| is receiving. |
1352 Connection* conn1 = lport->CreateConnection(lport->Candidates()[1], | 1361 Connection* conn1 = lport->CreateConnection(lport->Candidates()[1], |
1353 Port::ORIGIN_MESSAGE); | 1362 Port::ORIGIN_MESSAGE); |
1354 conn1->Ping(0); | 1363 conn1->Ping(0); |
1355 | 1364 |
1356 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); | 1365 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout); |
1357 msg = lport->last_stun_msg(); | 1366 msg = lport->last_stun_msg(); |
1358 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); | 1367 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); |
1359 std::unique_ptr<IceMessage> modified_req( | 1368 std::unique_ptr<IceMessage> modified_req( |
1360 CreateStunMessage(STUN_BINDING_REQUEST)); | 1369 CreateStunMessage(STUN_BINDING_REQUEST)); |
1361 const StunByteStringAttribute* username_attr = msg->GetByteString( | 1370 const StunByteStringAttribute* username_attr = msg->GetByteString( |
1362 STUN_ATTR_USERNAME); | 1371 STUN_ATTR_USERNAME); |
1363 modified_req->AddAttribute(new StunByteStringAttribute( | 1372 modified_req->AddAttribute(new StunByteStringAttribute( |
1364 STUN_ATTR_USERNAME, username_attr->GetString())); | 1373 STUN_ATTR_USERNAME, username_attr->GetString())); |
1365 // To make sure we receive error response, adding tiebreaker less than | 1374 // To make sure we receive error response, adding tiebreaker less than |
1366 // what's present in request. | 1375 // what's present in request. |
1367 modified_req->AddAttribute(new StunUInt64Attribute( | 1376 modified_req->AddAttribute(new StunUInt64Attribute( |
1368 STUN_ATTR_ICE_CONTROLLING, kTiebreaker1 - 1)); | 1377 STUN_ATTR_ICE_CONTROLLING, kTiebreaker1 - 1)); |
1369 modified_req->AddMessageIntegrity("lpass"); | 1378 modified_req->AddMessageIntegrity("lpass"); |
1370 modified_req->AddFingerprint(); | 1379 modified_req->AddFingerprint(); |
1371 | 1380 |
1372 lport->Reset(); | 1381 lport->Reset(); |
1373 std::unique_ptr<ByteBufferWriter> buf(new ByteBufferWriter()); | 1382 std::unique_ptr<ByteBufferWriter> buf(new ByteBufferWriter()); |
1374 WriteStunMessage(modified_req.get(), buf.get()); | 1383 WriteStunMessage(modified_req.get(), buf.get()); |
1375 conn1->OnReadPacket(buf->Data(), buf->Length(), rtc::PacketTime()); | 1384 conn1->OnReadPacket(buf->Data(), buf->Length(), rtc::PacketTime()); |
1376 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); | 1385 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout); |
1377 msg = lport->last_stun_msg(); | 1386 msg = lport->last_stun_msg(); |
1378 EXPECT_EQ(STUN_BINDING_ERROR_RESPONSE, msg->type()); | 1387 EXPECT_EQ(STUN_BINDING_ERROR_RESPONSE, msg->type()); |
1379 } | 1388 } |
1380 | 1389 |
1381 // This test verifies role conflict signal is received when there is | 1390 // This test verifies role conflict signal is received when there is |
1382 // conflict in the role. In this case both ports are in controlling and | 1391 // conflict in the role. In this case both ports are in controlling and |
1383 // |rport| has higher tiebreaker value than |lport|. Since |lport| has lower | 1392 // |rport| has higher tiebreaker value than |lport|. Since |lport| has lower |
1384 // value of tiebreaker, when it receives ping request from |rport| it will | 1393 // value of tiebreaker, when it receives ping request from |rport| it will |
1385 // send role conflict signal. | 1394 // send role conflict signal. |
1386 TEST_F(PortTest, TestIceRoleConflict) { | 1395 TEST_F(PortTest, TestIceRoleConflict) { |
1387 std::unique_ptr<TestPort> lport( | 1396 std::unique_ptr<TestPort> lport( |
1388 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); | 1397 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); |
1389 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1398 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); |
1390 lport->SetIceTiebreaker(kTiebreaker1); | 1399 lport->SetIceTiebreaker(kTiebreaker1); |
1391 std::unique_ptr<TestPort> rport( | 1400 std::unique_ptr<TestPort> rport( |
1392 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 1401 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
1393 rport->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1402 rport->SetIceRole(cricket::ICEROLE_CONTROLLING); |
1394 rport->SetIceTiebreaker(kTiebreaker2); | 1403 rport->SetIceTiebreaker(kTiebreaker2); |
1395 | 1404 |
1396 lport->PrepareAddress(); | 1405 lport->PrepareAddress(); |
1397 rport->PrepareAddress(); | 1406 rport->PrepareAddress(); |
1398 ASSERT_FALSE(lport->Candidates().empty()); | 1407 ASSERT_FALSE(lport->Candidates().empty()); |
1399 ASSERT_FALSE(rport->Candidates().empty()); | 1408 ASSERT_FALSE(rport->Candidates().empty()); |
1400 Connection* lconn = lport->CreateConnection(rport->Candidates()[0], | 1409 Connection* lconn = lport->CreateConnection(rport->Candidates()[0], |
1401 Port::ORIGIN_MESSAGE); | 1410 Port::ORIGIN_MESSAGE); |
1402 Connection* rconn = rport->CreateConnection(lport->Candidates()[0], | 1411 Connection* rconn = rport->CreateConnection(lport->Candidates()[0], |
1403 Port::ORIGIN_MESSAGE); | 1412 Port::ORIGIN_MESSAGE); |
1404 rconn->Ping(0); | 1413 rconn->Ping(0); |
1405 | 1414 |
1406 ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, 1000); | 1415 ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, kDefaultTimeout); |
1407 IceMessage* msg = rport->last_stun_msg(); | 1416 IceMessage* msg = rport->last_stun_msg(); |
1408 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); | 1417 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); |
1409 // Send rport binding request to lport. | 1418 // Send rport binding request to lport. |
1410 lconn->OnReadPacket(rport->last_stun_buf()->data<char>(), | 1419 lconn->OnReadPacket(rport->last_stun_buf()->data<char>(), |
1411 rport->last_stun_buf()->size(), | 1420 rport->last_stun_buf()->size(), |
1412 rtc::PacketTime()); | 1421 rtc::PacketTime()); |
1413 | 1422 |
1414 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); | 1423 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout); |
1415 EXPECT_EQ(STUN_BINDING_RESPONSE, lport->last_stun_msg()->type()); | 1424 EXPECT_EQ(STUN_BINDING_RESPONSE, lport->last_stun_msg()->type()); |
1416 EXPECT_TRUE(role_conflict()); | 1425 EXPECT_TRUE(role_conflict()); |
1417 } | 1426 } |
1418 | 1427 |
1419 TEST_F(PortTest, TestTcpNoDelay) { | 1428 TEST_F(PortTest, TestTcpNoDelay) { |
1420 TCPPort* port1 = CreateTcpPort(kLocalAddr1); | 1429 TCPPort* port1 = CreateTcpPort(kLocalAddr1); |
1421 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1430 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
1422 int option_value = -1; | 1431 int option_value = -1; |
1423 int success = port1->GetOption(rtc::Socket::OPT_NODELAY, | 1432 int success = port1->GetOption(rtc::Socket::OPT_NODELAY, |
1424 &option_value); | 1433 &option_value); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1611 lport->PrepareAddress(); | 1620 lport->PrepareAddress(); |
1612 rport->PrepareAddress(); | 1621 rport->PrepareAddress(); |
1613 ASSERT_FALSE(rport->Candidates().empty()); | 1622 ASSERT_FALSE(rport->Candidates().empty()); |
1614 Connection* lconn = lport->CreateConnection( | 1623 Connection* lconn = lport->CreateConnection( |
1615 rport->Candidates()[0], Port::ORIGIN_MESSAGE); | 1624 rport->Candidates()[0], Port::ORIGIN_MESSAGE); |
1616 Connection* rconn = rport->CreateConnection( | 1625 Connection* rconn = rport->CreateConnection( |
1617 lport->Candidates()[0], Port::ORIGIN_MESSAGE); | 1626 lport->Candidates()[0], Port::ORIGIN_MESSAGE); |
1618 lconn->Ping(0); | 1627 lconn->Ping(0); |
1619 | 1628 |
1620 // Check that it's a proper BINDING-REQUEST. | 1629 // Check that it's a proper BINDING-REQUEST. |
1621 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); | 1630 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout); |
1622 IceMessage* msg = lport->last_stun_msg(); | 1631 IceMessage* msg = lport->last_stun_msg(); |
1623 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); | 1632 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); |
1624 EXPECT_FALSE(msg->IsLegacy()); | 1633 EXPECT_FALSE(msg->IsLegacy()); |
1625 const StunByteStringAttribute* username_attr = | 1634 const StunByteStringAttribute* username_attr = |
1626 msg->GetByteString(STUN_ATTR_USERNAME); | 1635 msg->GetByteString(STUN_ATTR_USERNAME); |
1627 ASSERT_TRUE(username_attr != NULL); | 1636 ASSERT_TRUE(username_attr != NULL); |
1628 const StunUInt32Attribute* priority_attr = msg->GetUInt32(STUN_ATTR_PRIORITY); | 1637 const StunUInt32Attribute* priority_attr = msg->GetUInt32(STUN_ATTR_PRIORITY); |
1629 ASSERT_TRUE(priority_attr != NULL); | 1638 ASSERT_TRUE(priority_attr != NULL); |
1630 EXPECT_EQ(kDefaultPrflxPriority, priority_attr->value()); | 1639 EXPECT_EQ(kDefaultPrflxPriority, priority_attr->value()); |
1631 EXPECT_EQ("rfrag:lfrag", username_attr->GetString()); | 1640 EXPECT_EQ("rfrag:lfrag", username_attr->GetString()); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1713 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_USERNAME) == NULL); | 1722 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_USERNAME) == NULL); |
1714 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_PRIORITY) == NULL); | 1723 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_PRIORITY) == NULL); |
1715 | 1724 |
1716 // Testing STUN binding requests from rport --> lport, having ICE_CONTROLLED | 1725 // Testing STUN binding requests from rport --> lport, having ICE_CONTROLLED |
1717 // and (incremented) RETRANSMIT_COUNT attributes. | 1726 // and (incremented) RETRANSMIT_COUNT attributes. |
1718 rport->Reset(); | 1727 rport->Reset(); |
1719 rport->set_send_retransmit_count_attribute(true); | 1728 rport->set_send_retransmit_count_attribute(true); |
1720 rconn->Ping(0); | 1729 rconn->Ping(0); |
1721 rconn->Ping(0); | 1730 rconn->Ping(0); |
1722 rconn->Ping(0); | 1731 rconn->Ping(0); |
1723 ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, 1000); | 1732 ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, kDefaultTimeout); |
1724 msg = rport->last_stun_msg(); | 1733 msg = rport->last_stun_msg(); |
1725 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); | 1734 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); |
1726 const StunUInt64Attribute* ice_controlled_attr = | 1735 const StunUInt64Attribute* ice_controlled_attr = |
1727 msg->GetUInt64(STUN_ATTR_ICE_CONTROLLED); | 1736 msg->GetUInt64(STUN_ATTR_ICE_CONTROLLED); |
1728 ASSERT_TRUE(ice_controlled_attr != NULL); | 1737 ASSERT_TRUE(ice_controlled_attr != NULL); |
1729 EXPECT_EQ(rport->IceTiebreaker(), ice_controlled_attr->value()); | 1738 EXPECT_EQ(rport->IceTiebreaker(), ice_controlled_attr->value()); |
1730 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_USE_CANDIDATE) == NULL); | 1739 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_USE_CANDIDATE) == NULL); |
1731 | 1740 |
1732 // Request should include ping count. | 1741 // Request should include ping count. |
1733 const StunUInt32Attribute* retransmit_attr = | 1742 const StunUInt32Attribute* retransmit_attr = |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1772 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); | 1781 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); |
1773 rport->SetIceTiebreaker(kTiebreaker2); | 1782 rport->SetIceTiebreaker(kTiebreaker2); |
1774 | 1783 |
1775 // Send a fake ping from lport to rport. | 1784 // Send a fake ping from lport to rport. |
1776 lport->PrepareAddress(); | 1785 lport->PrepareAddress(); |
1777 rport->PrepareAddress(); | 1786 rport->PrepareAddress(); |
1778 ASSERT_FALSE(rport->Candidates().empty()); | 1787 ASSERT_FALSE(rport->Candidates().empty()); |
1779 Connection* lconn = lport->CreateConnection( | 1788 Connection* lconn = lport->CreateConnection( |
1780 rport->Candidates()[0], Port::ORIGIN_MESSAGE); | 1789 rport->Candidates()[0], Port::ORIGIN_MESSAGE); |
1781 lconn->Ping(0); | 1790 lconn->Ping(0); |
1782 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); | 1791 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout); |
1783 IceMessage* msg = lport->last_stun_msg(); | 1792 IceMessage* msg = lport->last_stun_msg(); |
1784 const StunUInt64Attribute* ice_controlling_attr = | 1793 const StunUInt64Attribute* ice_controlling_attr = |
1785 msg->GetUInt64(STUN_ATTR_ICE_CONTROLLING); | 1794 msg->GetUInt64(STUN_ATTR_ICE_CONTROLLING); |
1786 ASSERT_TRUE(ice_controlling_attr != NULL); | 1795 ASSERT_TRUE(ice_controlling_attr != NULL); |
1787 const StunByteStringAttribute* use_candidate_attr = msg->GetByteString( | 1796 const StunByteStringAttribute* use_candidate_attr = msg->GetByteString( |
1788 STUN_ATTR_USE_CANDIDATE); | 1797 STUN_ATTR_USE_CANDIDATE); |
1789 ASSERT_TRUE(use_candidate_attr != NULL); | 1798 ASSERT_TRUE(use_candidate_attr != NULL); |
1790 } | 1799 } |
1791 | 1800 |
1792 // Tests that when the network type changes, the network cost of the port will | 1801 // Tests that when the network type changes, the network cost of the port will |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1831 SetNetworkType(rtc::ADAPTER_TYPE_WIFI); | 1840 SetNetworkType(rtc::ADAPTER_TYPE_WIFI); |
1832 Connection* rconn = | 1841 Connection* rconn = |
1833 rport->CreateConnection(lport->Candidates()[0], Port::ORIGIN_MESSAGE); | 1842 rport->CreateConnection(lport->Candidates()[0], Port::ORIGIN_MESSAGE); |
1834 SetNetworkType(rtc::ADAPTER_TYPE_CELLULAR); | 1843 SetNetworkType(rtc::ADAPTER_TYPE_CELLULAR); |
1835 lconn->Ping(0); | 1844 lconn->Ping(0); |
1836 // The rconn's remote candidate cost is rtc::kNetworkCostLow, but the ping | 1845 // The rconn's remote candidate cost is rtc::kNetworkCostLow, but the ping |
1837 // contains an attribute of network cost of rtc::kNetworkCostHigh. Once the | 1846 // contains an attribute of network cost of rtc::kNetworkCostHigh. Once the |
1838 // message is handled in rconn, The rconn's remote candidate will have cost | 1847 // message is handled in rconn, The rconn's remote candidate will have cost |
1839 // rtc::kNetworkCostHigh; | 1848 // rtc::kNetworkCostHigh; |
1840 EXPECT_EQ(rtc::kNetworkCostLow, rconn->remote_candidate().network_cost()); | 1849 EXPECT_EQ(rtc::kNetworkCostLow, rconn->remote_candidate().network_cost()); |
1841 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); | 1850 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout); |
1842 IceMessage* msg = lport->last_stun_msg(); | 1851 IceMessage* msg = lport->last_stun_msg(); |
1843 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); | 1852 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); |
1844 // Pass the binding request to rport. | 1853 // Pass the binding request to rport. |
1845 rconn->OnReadPacket(lport->last_stun_buf()->data<char>(), | 1854 rconn->OnReadPacket(lport->last_stun_buf()->data<char>(), |
1846 lport->last_stun_buf()->size(), rtc::PacketTime()); | 1855 lport->last_stun_buf()->size(), rtc::PacketTime()); |
1847 // Wait until rport sends the response and then check the remote network cost. | 1856 // Wait until rport sends the response and then check the remote network cost. |
1848 ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, 1000); | 1857 ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, kDefaultTimeout); |
1849 EXPECT_EQ(rtc::kNetworkCostHigh, rconn->remote_candidate().network_cost()); | 1858 EXPECT_EQ(rtc::kNetworkCostHigh, rconn->remote_candidate().network_cost()); |
1850 } | 1859 } |
1851 | 1860 |
1852 TEST_F(PortTest, TestNetworkInfoAttribute) { | 1861 TEST_F(PortTest, TestNetworkInfoAttribute) { |
1853 std::unique_ptr<TestPort> lport( | 1862 std::unique_ptr<TestPort> lport( |
1854 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); | 1863 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); |
1855 std::unique_ptr<TestPort> rport( | 1864 std::unique_ptr<TestPort> rport( |
1856 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 1865 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
1857 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1866 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); |
1858 lport->SetIceTiebreaker(kTiebreaker1); | 1867 lport->SetIceTiebreaker(kTiebreaker1); |
1859 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); | 1868 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); |
1860 rport->SetIceTiebreaker(kTiebreaker2); | 1869 rport->SetIceTiebreaker(kTiebreaker2); |
1861 | 1870 |
1862 uint16_t lnetwork_id = 9; | 1871 uint16_t lnetwork_id = 9; |
1863 lport->Network()->set_id(lnetwork_id); | 1872 lport->Network()->set_id(lnetwork_id); |
1864 // Send a fake ping from lport to rport. | 1873 // Send a fake ping from lport to rport. |
1865 lport->PrepareAddress(); | 1874 lport->PrepareAddress(); |
1866 rport->PrepareAddress(); | 1875 rport->PrepareAddress(); |
1867 Connection* lconn = | 1876 Connection* lconn = |
1868 lport->CreateConnection(rport->Candidates()[0], Port::ORIGIN_MESSAGE); | 1877 lport->CreateConnection(rport->Candidates()[0], Port::ORIGIN_MESSAGE); |
1869 lconn->Ping(0); | 1878 lconn->Ping(0); |
1870 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); | 1879 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout); |
1871 IceMessage* msg = lport->last_stun_msg(); | 1880 IceMessage* msg = lport->last_stun_msg(); |
1872 const StunUInt32Attribute* network_info_attr = | 1881 const StunUInt32Attribute* network_info_attr = |
1873 msg->GetUInt32(STUN_ATTR_NETWORK_INFO); | 1882 msg->GetUInt32(STUN_ATTR_NETWORK_INFO); |
1874 ASSERT_TRUE(network_info_attr != NULL); | 1883 ASSERT_TRUE(network_info_attr != NULL); |
1875 uint32_t network_info = network_info_attr->value(); | 1884 uint32_t network_info = network_info_attr->value(); |
1876 EXPECT_EQ(lnetwork_id, network_info >> 16); | 1885 EXPECT_EQ(lnetwork_id, network_info >> 16); |
1877 // Default network has unknown type and cost kNetworkCostUnknown. | 1886 // Default network has unknown type and cost kNetworkCostUnknown. |
1878 EXPECT_EQ(rtc::kNetworkCostUnknown, network_info & 0xFFFF); | 1887 EXPECT_EQ(rtc::kNetworkCostUnknown, network_info & 0xFFFF); |
1879 | 1888 |
1880 // Set the network type to be cellular so its cost will be kNetworkCostHigh. | 1889 // Set the network type to be cellular so its cost will be kNetworkCostHigh. |
1881 // Send a fake ping from rport to lport. | 1890 // Send a fake ping from rport to lport. |
1882 SetNetworkType(rtc::ADAPTER_TYPE_CELLULAR); | 1891 SetNetworkType(rtc::ADAPTER_TYPE_CELLULAR); |
1883 uint16_t rnetwork_id = 8; | 1892 uint16_t rnetwork_id = 8; |
1884 rport->Network()->set_id(rnetwork_id); | 1893 rport->Network()->set_id(rnetwork_id); |
1885 Connection* rconn = | 1894 Connection* rconn = |
1886 rport->CreateConnection(lport->Candidates()[0], Port::ORIGIN_MESSAGE); | 1895 rport->CreateConnection(lport->Candidates()[0], Port::ORIGIN_MESSAGE); |
1887 rconn->Ping(0); | 1896 rconn->Ping(0); |
1888 ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, 1000); | 1897 ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, kDefaultTimeout); |
1889 msg = rport->last_stun_msg(); | 1898 msg = rport->last_stun_msg(); |
1890 network_info_attr = msg->GetUInt32(STUN_ATTR_NETWORK_INFO); | 1899 network_info_attr = msg->GetUInt32(STUN_ATTR_NETWORK_INFO); |
1891 ASSERT_TRUE(network_info_attr != NULL); | 1900 ASSERT_TRUE(network_info_attr != NULL); |
1892 network_info = network_info_attr->value(); | 1901 network_info = network_info_attr->value(); |
1893 EXPECT_EQ(rnetwork_id, network_info >> 16); | 1902 EXPECT_EQ(rnetwork_id, network_info >> 16); |
1894 EXPECT_EQ(rtc::kNetworkCostHigh, network_info & 0xFFFF); | 1903 EXPECT_EQ(rtc::kNetworkCostHigh, network_info & 0xFFFF); |
1895 } | 1904 } |
1896 | 1905 |
1897 // Test handling STUN messages. | 1906 // Test handling STUN messages. |
1898 TEST_F(PortTest, TestHandleStunMessage) { | 1907 TEST_F(PortTest, TestHandleStunMessage) { |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2150 rport->PrepareAddress(); | 2159 rport->PrepareAddress(); |
2151 ASSERT_FALSE(lport->Candidates().empty()); | 2160 ASSERT_FALSE(lport->Candidates().empty()); |
2152 ASSERT_FALSE(rport->Candidates().empty()); | 2161 ASSERT_FALSE(rport->Candidates().empty()); |
2153 | 2162 |
2154 Connection* lconn = lport->CreateConnection(rport->Candidates()[0], | 2163 Connection* lconn = lport->CreateConnection(rport->Candidates()[0], |
2155 Port::ORIGIN_MESSAGE); | 2164 Port::ORIGIN_MESSAGE); |
2156 Connection* rconn = rport->CreateConnection(lport->Candidates()[0], | 2165 Connection* rconn = rport->CreateConnection(lport->Candidates()[0], |
2157 Port::ORIGIN_MESSAGE); | 2166 Port::ORIGIN_MESSAGE); |
2158 rconn->Ping(0); | 2167 rconn->Ping(0); |
2159 | 2168 |
2160 ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, 1000); | 2169 ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, kDefaultTimeout); |
2161 IceMessage* msg = rport->last_stun_msg(); | 2170 IceMessage* msg = rport->last_stun_msg(); |
2162 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); | 2171 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); |
2163 // Send rport binding request to lport. | 2172 // Send rport binding request to lport. |
2164 lconn->OnReadPacket(rport->last_stun_buf()->data<char>(), | 2173 lconn->OnReadPacket(rport->last_stun_buf()->data<char>(), |
2165 rport->last_stun_buf()->size(), | 2174 rport->last_stun_buf()->size(), |
2166 rtc::PacketTime()); | 2175 rtc::PacketTime()); |
2167 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); | 2176 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout); |
2168 EXPECT_EQ(STUN_BINDING_RESPONSE, lport->last_stun_msg()->type()); | 2177 EXPECT_EQ(STUN_BINDING_RESPONSE, lport->last_stun_msg()->type()); |
2169 int64_t last_ping_received1 = lconn->last_ping_received(); | 2178 int64_t last_ping_received1 = lconn->last_ping_received(); |
2170 | 2179 |
2171 // Adding a delay of 100ms. | 2180 // Adding a delay of 100ms. |
2172 rtc::Thread::Current()->ProcessMessages(100); | 2181 rtc::Thread::Current()->ProcessMessages(100); |
2173 // Pinging lconn using stun indication message. | 2182 // Pinging lconn using stun indication message. |
2174 lconn->OnReadPacket(buf->Data(), buf->Length(), rtc::PacketTime()); | 2183 lconn->OnReadPacket(buf->Data(), buf->Length(), rtc::PacketTime()); |
2175 int64_t last_ping_received2 = lconn->last_ping_received(); | 2184 int64_t last_ping_received2 = lconn->last_ping_received(); |
2176 EXPECT_GT(last_ping_received2, last_ping_received1); | 2185 EXPECT_GT(last_ping_received2, last_ping_received1); |
2177 } | 2186 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2238 udpport2->Candidates()[0].foundation()); | 2247 udpport2->Candidates()[0].foundation()); |
2239 std::unique_ptr<TCPPort> tcpport1(CreateTcpPort(kLocalAddr1)); | 2248 std::unique_ptr<TCPPort> tcpport1(CreateTcpPort(kLocalAddr1)); |
2240 tcpport1->PrepareAddress(); | 2249 tcpport1->PrepareAddress(); |
2241 std::unique_ptr<TCPPort> tcpport2(CreateTcpPort(kLocalAddr1)); | 2250 std::unique_ptr<TCPPort> tcpport2(CreateTcpPort(kLocalAddr1)); |
2242 tcpport2->PrepareAddress(); | 2251 tcpport2->PrepareAddress(); |
2243 EXPECT_EQ(tcpport1->Candidates()[0].foundation(), | 2252 EXPECT_EQ(tcpport1->Candidates()[0].foundation(), |
2244 tcpport2->Candidates()[0].foundation()); | 2253 tcpport2->Candidates()[0].foundation()); |
2245 std::unique_ptr<Port> stunport( | 2254 std::unique_ptr<Port> stunport( |
2246 CreateStunPort(kLocalAddr1, nat_socket_factory1())); | 2255 CreateStunPort(kLocalAddr1, nat_socket_factory1())); |
2247 stunport->PrepareAddress(); | 2256 stunport->PrepareAddress(); |
2248 ASSERT_EQ_WAIT(1U, stunport->Candidates().size(), kTimeout); | 2257 ASSERT_EQ_WAIT(1U, stunport->Candidates().size(), kDefaultTimeout); |
2249 EXPECT_NE(tcpport1->Candidates()[0].foundation(), | 2258 EXPECT_NE(tcpport1->Candidates()[0].foundation(), |
2250 stunport->Candidates()[0].foundation()); | 2259 stunport->Candidates()[0].foundation()); |
2251 EXPECT_NE(tcpport2->Candidates()[0].foundation(), | 2260 EXPECT_NE(tcpport2->Candidates()[0].foundation(), |
2252 stunport->Candidates()[0].foundation()); | 2261 stunport->Candidates()[0].foundation()); |
2253 EXPECT_NE(udpport1->Candidates()[0].foundation(), | 2262 EXPECT_NE(udpport1->Candidates()[0].foundation(), |
2254 stunport->Candidates()[0].foundation()); | 2263 stunport->Candidates()[0].foundation()); |
2255 EXPECT_NE(udpport2->Candidates()[0].foundation(), | 2264 EXPECT_NE(udpport2->Candidates()[0].foundation(), |
2256 stunport->Candidates()[0].foundation()); | 2265 stunport->Candidates()[0].foundation()); |
2257 // Verify GTURN candidate foundation. | 2266 // Verify GTURN candidate foundation. |
2258 std::unique_ptr<RelayPort> relayport(CreateGturnPort(kLocalAddr1)); | 2267 std::unique_ptr<RelayPort> relayport(CreateGturnPort(kLocalAddr1)); |
2259 relayport->AddServerAddress( | 2268 relayport->AddServerAddress( |
2260 cricket::ProtocolAddress(kRelayUdpIntAddr, cricket::PROTO_UDP)); | 2269 cricket::ProtocolAddress(kRelayUdpIntAddr, cricket::PROTO_UDP)); |
2261 relayport->PrepareAddress(); | 2270 relayport->PrepareAddress(); |
2262 ASSERT_EQ_WAIT(1U, relayport->Candidates().size(), kTimeout); | 2271 ASSERT_EQ_WAIT(1U, relayport->Candidates().size(), kDefaultTimeout); |
2263 EXPECT_NE(udpport1->Candidates()[0].foundation(), | 2272 EXPECT_NE(udpport1->Candidates()[0].foundation(), |
2264 relayport->Candidates()[0].foundation()); | 2273 relayport->Candidates()[0].foundation()); |
2265 EXPECT_NE(udpport2->Candidates()[0].foundation(), | 2274 EXPECT_NE(udpport2->Candidates()[0].foundation(), |
2266 relayport->Candidates()[0].foundation()); | 2275 relayport->Candidates()[0].foundation()); |
2267 // Verifying TURN candidate foundation. | 2276 // Verifying TURN candidate foundation. |
2268 std::unique_ptr<Port> turnport1( | 2277 std::unique_ptr<Port> turnport1( |
2269 CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP)); | 2278 CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP)); |
2270 turnport1->PrepareAddress(); | 2279 turnport1->PrepareAddress(); |
2271 ASSERT_EQ_WAIT(1U, turnport1->Candidates().size(), kTimeout); | 2280 ASSERT_EQ_WAIT(1U, turnport1->Candidates().size(), kDefaultTimeout); |
2272 EXPECT_NE(udpport1->Candidates()[0].foundation(), | 2281 EXPECT_NE(udpport1->Candidates()[0].foundation(), |
2273 turnport1->Candidates()[0].foundation()); | 2282 turnport1->Candidates()[0].foundation()); |
2274 EXPECT_NE(udpport2->Candidates()[0].foundation(), | 2283 EXPECT_NE(udpport2->Candidates()[0].foundation(), |
2275 turnport1->Candidates()[0].foundation()); | 2284 turnport1->Candidates()[0].foundation()); |
2276 EXPECT_NE(stunport->Candidates()[0].foundation(), | 2285 EXPECT_NE(stunport->Candidates()[0].foundation(), |
2277 turnport1->Candidates()[0].foundation()); | 2286 turnport1->Candidates()[0].foundation()); |
2278 std::unique_ptr<Port> turnport2( | 2287 std::unique_ptr<Port> turnport2( |
2279 CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP)); | 2288 CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP)); |
2280 turnport2->PrepareAddress(); | 2289 turnport2->PrepareAddress(); |
2281 ASSERT_EQ_WAIT(1U, turnport2->Candidates().size(), kTimeout); | 2290 ASSERT_EQ_WAIT(1U, turnport2->Candidates().size(), kDefaultTimeout); |
2282 EXPECT_EQ(turnport1->Candidates()[0].foundation(), | 2291 EXPECT_EQ(turnport1->Candidates()[0].foundation(), |
2283 turnport2->Candidates()[0].foundation()); | 2292 turnport2->Candidates()[0].foundation()); |
2284 | 2293 |
2285 // Running a second turn server, to get different base IP address. | 2294 // Running a second turn server, to get different base IP address. |
2286 SocketAddress kTurnUdpIntAddr2("99.99.98.4", STUN_SERVER_PORT); | 2295 SocketAddress kTurnUdpIntAddr2("99.99.98.4", STUN_SERVER_PORT); |
2287 SocketAddress kTurnUdpExtAddr2("99.99.98.5", 0); | 2296 SocketAddress kTurnUdpExtAddr2("99.99.98.5", 0); |
2288 TestTurnServer turn_server2( | 2297 TestTurnServer turn_server2( |
2289 rtc::Thread::Current(), kTurnUdpIntAddr2, kTurnUdpExtAddr2); | 2298 rtc::Thread::Current(), kTurnUdpIntAddr2, kTurnUdpExtAddr2); |
2290 std::unique_ptr<Port> turnport3( | 2299 std::unique_ptr<Port> turnport3( |
2291 CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP, | 2300 CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP, |
2292 kTurnUdpIntAddr2)); | 2301 kTurnUdpIntAddr2)); |
2293 turnport3->PrepareAddress(); | 2302 turnport3->PrepareAddress(); |
2294 ASSERT_EQ_WAIT(1U, turnport3->Candidates().size(), kTimeout); | 2303 ASSERT_EQ_WAIT(1U, turnport3->Candidates().size(), kDefaultTimeout); |
2295 EXPECT_NE(turnport3->Candidates()[0].foundation(), | 2304 EXPECT_NE(turnport3->Candidates()[0].foundation(), |
2296 turnport2->Candidates()[0].foundation()); | 2305 turnport2->Candidates()[0].foundation()); |
2297 | 2306 |
2298 // Start a TCP turn server, and check that two turn candidates have | 2307 // Start a TCP turn server, and check that two turn candidates have |
2299 // different foundations if their relay protocols are different. | 2308 // different foundations if their relay protocols are different. |
2300 TestTurnServer turn_server3(rtc::Thread::Current(), kTurnTcpIntAddr, | 2309 TestTurnServer turn_server3(rtc::Thread::Current(), kTurnTcpIntAddr, |
2301 kTurnUdpExtAddr, PROTO_TCP); | 2310 kTurnUdpExtAddr, PROTO_TCP); |
2302 std::unique_ptr<Port> turnport4( | 2311 std::unique_ptr<Port> turnport4( |
2303 CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_TCP, PROTO_UDP)); | 2312 CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_TCP, PROTO_UDP)); |
2304 turnport4->PrepareAddress(); | 2313 turnport4->PrepareAddress(); |
2305 ASSERT_EQ_WAIT(1U, turnport4->Candidates().size(), kTimeout); | 2314 ASSERT_EQ_WAIT(1U, turnport4->Candidates().size(), kDefaultTimeout); |
2306 EXPECT_NE(turnport2->Candidates()[0].foundation(), | 2315 EXPECT_NE(turnport2->Candidates()[0].foundation(), |
2307 turnport4->Candidates()[0].foundation()); | 2316 turnport4->Candidates()[0].foundation()); |
2308 } | 2317 } |
2309 | 2318 |
2310 // This test verifies the related addresses of different types of | 2319 // This test verifies the related addresses of different types of |
2311 // ICE candiates. | 2320 // ICE candiates. |
2312 TEST_F(PortTest, TestCandidateRelatedAddress) { | 2321 TEST_F(PortTest, TestCandidateRelatedAddress) { |
2313 std::unique_ptr<rtc::NATServer> nat_server( | 2322 std::unique_ptr<rtc::NATServer> nat_server( |
2314 CreateNatServer(kNatAddr1, NAT_OPEN_CONE)); | 2323 CreateNatServer(kNatAddr1, NAT_OPEN_CONE)); |
2315 std::unique_ptr<UDPPort> udpport(CreateUdpPort(kLocalAddr1)); | 2324 std::unique_ptr<UDPPort> udpport(CreateUdpPort(kLocalAddr1)); |
2316 udpport->PrepareAddress(); | 2325 udpport->PrepareAddress(); |
2317 // For UDPPort, related address will be empty. | 2326 // For UDPPort, related address will be empty. |
2318 EXPECT_TRUE(udpport->Candidates()[0].related_address().IsNil()); | 2327 EXPECT_TRUE(udpport->Candidates()[0].related_address().IsNil()); |
2319 // Testing related address for stun candidates. | 2328 // Testing related address for stun candidates. |
2320 // For stun candidate related address must be equal to the base | 2329 // For stun candidate related address must be equal to the base |
2321 // socket address. | 2330 // socket address. |
2322 std::unique_ptr<StunPort> stunport( | 2331 std::unique_ptr<StunPort> stunport( |
2323 CreateStunPort(kLocalAddr1, nat_socket_factory1())); | 2332 CreateStunPort(kLocalAddr1, nat_socket_factory1())); |
2324 stunport->PrepareAddress(); | 2333 stunport->PrepareAddress(); |
2325 ASSERT_EQ_WAIT(1U, stunport->Candidates().size(), kTimeout); | 2334 ASSERT_EQ_WAIT(1U, stunport->Candidates().size(), kDefaultTimeout); |
2326 // Check STUN candidate address. | 2335 // Check STUN candidate address. |
2327 EXPECT_EQ(stunport->Candidates()[0].address().ipaddr(), | 2336 EXPECT_EQ(stunport->Candidates()[0].address().ipaddr(), |
2328 kNatAddr1.ipaddr()); | 2337 kNatAddr1.ipaddr()); |
2329 // Check STUN candidate related address. | 2338 // Check STUN candidate related address. |
2330 EXPECT_EQ(stunport->Candidates()[0].related_address(), | 2339 EXPECT_EQ(stunport->Candidates()[0].related_address(), |
2331 stunport->GetLocalAddress()); | 2340 stunport->GetLocalAddress()); |
2332 // Verifying the related address for the GTURN candidates. | 2341 // Verifying the related address for the GTURN candidates. |
2333 // NOTE: In case of GTURN related address will be equal to the mapped | 2342 // NOTE: In case of GTURN related address will be equal to the mapped |
2334 // address, but address(mapped) will not be XOR. | 2343 // address, but address(mapped) will not be XOR. |
2335 std::unique_ptr<RelayPort> relayport(CreateGturnPort(kLocalAddr1)); | 2344 std::unique_ptr<RelayPort> relayport(CreateGturnPort(kLocalAddr1)); |
2336 relayport->AddServerAddress( | 2345 relayport->AddServerAddress( |
2337 cricket::ProtocolAddress(kRelayUdpIntAddr, cricket::PROTO_UDP)); | 2346 cricket::ProtocolAddress(kRelayUdpIntAddr, cricket::PROTO_UDP)); |
2338 relayport->PrepareAddress(); | 2347 relayport->PrepareAddress(); |
2339 ASSERT_EQ_WAIT(1U, relayport->Candidates().size(), kTimeout); | 2348 ASSERT_EQ_WAIT(1U, relayport->Candidates().size(), kDefaultTimeout); |
2340 // For Gturn related address is set to "0.0.0.0:0" | 2349 // For Gturn related address is set to "0.0.0.0:0" |
2341 EXPECT_EQ(rtc::SocketAddress(), | 2350 EXPECT_EQ(rtc::SocketAddress(), |
2342 relayport->Candidates()[0].related_address()); | 2351 relayport->Candidates()[0].related_address()); |
2343 // Verifying the related address for TURN candidate. | 2352 // Verifying the related address for TURN candidate. |
2344 // For TURN related address must be equal to the mapped address. | 2353 // For TURN related address must be equal to the mapped address. |
2345 std::unique_ptr<Port> turnport( | 2354 std::unique_ptr<Port> turnport( |
2346 CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP)); | 2355 CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP)); |
2347 turnport->PrepareAddress(); | 2356 turnport->PrepareAddress(); |
2348 ASSERT_EQ_WAIT(1U, turnport->Candidates().size(), kTimeout); | 2357 ASSERT_EQ_WAIT(1U, turnport->Candidates().size(), kDefaultTimeout); |
2349 EXPECT_EQ(kTurnUdpExtAddr.ipaddr(), | 2358 EXPECT_EQ(kTurnUdpExtAddr.ipaddr(), |
2350 turnport->Candidates()[0].address().ipaddr()); | 2359 turnport->Candidates()[0].address().ipaddr()); |
2351 EXPECT_EQ(kNatAddr1.ipaddr(), | 2360 EXPECT_EQ(kNatAddr1.ipaddr(), |
2352 turnport->Candidates()[0].related_address().ipaddr()); | 2361 turnport->Candidates()[0].related_address().ipaddr()); |
2353 } | 2362 } |
2354 | 2363 |
2355 // Test priority value overflow handling when preference is set to 3. | 2364 // Test priority value overflow handling when preference is set to 3. |
2356 TEST_F(PortTest, TestCandidatePriority) { | 2365 TEST_F(PortTest, TestCandidatePriority) { |
2357 cricket::Candidate cand1; | 2366 cricket::Candidate cand1; |
2358 cand1.set_priority(3); | 2367 cand1.set_priority(3); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2394 Connection* rconn = rport->CreateConnection( | 2403 Connection* rconn = rport->CreateConnection( |
2395 lport->Candidates()[0], Port::ORIGIN_MESSAGE); | 2404 lport->Candidates()[0], Port::ORIGIN_MESSAGE); |
2396 #if defined(WEBRTC_WIN) | 2405 #if defined(WEBRTC_WIN) |
2397 EXPECT_EQ(0x2001EE9FC003D0AU, rconn->priority()); | 2406 EXPECT_EQ(0x2001EE9FC003D0AU, rconn->priority()); |
2398 #else | 2407 #else |
2399 EXPECT_EQ(0x2001EE9FC003D0ALLU, rconn->priority()); | 2408 EXPECT_EQ(0x2001EE9FC003D0ALLU, rconn->priority()); |
2400 #endif | 2409 #endif |
2401 } | 2410 } |
2402 | 2411 |
2403 TEST_F(PortTest, TestWritableState) { | 2412 TEST_F(PortTest, TestWritableState) { |
| 2413 rtc::ScopedFakeClock clock; |
2404 UDPPort* port1 = CreateUdpPort(kLocalAddr1); | 2414 UDPPort* port1 = CreateUdpPort(kLocalAddr1); |
2405 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | 2415 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
2406 UDPPort* port2 = CreateUdpPort(kLocalAddr2); | 2416 UDPPort* port2 = CreateUdpPort(kLocalAddr2); |
2407 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); | 2417 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); |
2408 | 2418 |
2409 // Set up channels. | 2419 // Set up channels. |
2410 TestChannel ch1(port1); | 2420 TestChannel ch1(port1); |
2411 TestChannel ch2(port2); | 2421 TestChannel ch2(port2); |
2412 | 2422 |
2413 // Acquire addresses. | 2423 // Acquire addresses. |
2414 ch1.Start(); | 2424 ch1.Start(); |
2415 ch2.Start(); | 2425 ch2.Start(); |
2416 ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout); | 2426 ASSERT_EQ_SIMULATED_WAIT(1, ch1.complete_count(), kDefaultTimeout, clock); |
2417 ASSERT_EQ_WAIT(1, ch2.complete_count(), kTimeout); | 2427 ASSERT_EQ_SIMULATED_WAIT(1, ch2.complete_count(), kDefaultTimeout, clock); |
2418 | 2428 |
2419 // Send a ping from src to dst. | 2429 // Send a ping from src to dst. |
2420 ch1.CreateConnection(GetCandidate(port2)); | 2430 ch1.CreateConnection(GetCandidate(port2)); |
2421 ASSERT_TRUE(ch1.conn() != NULL); | 2431 ASSERT_TRUE(ch1.conn() != NULL); |
2422 EXPECT_EQ(Connection::STATE_WRITE_INIT, ch1.conn()->write_state()); | 2432 EXPECT_EQ(Connection::STATE_WRITE_INIT, ch1.conn()->write_state()); |
2423 EXPECT_TRUE_WAIT(ch1.conn()->connected(), kTimeout); // for TCP connect | 2433 // for TCP connect |
| 2434 EXPECT_TRUE_SIMULATED_WAIT(ch1.conn()->connected(), kDefaultTimeout, clock); |
2424 ch1.Ping(); | 2435 ch1.Ping(); |
2425 WAIT(!ch2.remote_address().IsNil(), kTimeout); | 2436 SIMULATED_WAIT(!ch2.remote_address().IsNil(), kShortTimeout, clock); |
2426 | 2437 |
2427 // Data should be sendable before the connection is accepted. | 2438 // Data should be sendable before the connection is accepted. |
2428 char data[] = "abcd"; | 2439 char data[] = "abcd"; |
2429 int data_size = arraysize(data); | 2440 int data_size = arraysize(data); |
2430 rtc::PacketOptions options; | 2441 rtc::PacketOptions options; |
2431 EXPECT_EQ(data_size, ch1.conn()->Send(data, data_size, options)); | 2442 EXPECT_EQ(data_size, ch1.conn()->Send(data, data_size, options)); |
2432 | 2443 |
2433 // Accept the connection to return the binding response, transition to | 2444 // Accept the connection to return the binding response, transition to |
2434 // writable, and allow data to be sent. | 2445 // writable, and allow data to be sent. |
2435 ch2.AcceptConnection(GetCandidate(port1)); | 2446 ch2.AcceptConnection(GetCandidate(port1)); |
2436 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch1.conn()->write_state(), | 2447 EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, |
2437 kTimeout); | 2448 ch1.conn()->write_state(), kDefaultTimeout, clock); |
2438 EXPECT_EQ(data_size, ch1.conn()->Send(data, data_size, options)); | 2449 EXPECT_EQ(data_size, ch1.conn()->Send(data, data_size, options)); |
2439 | 2450 |
2440 // Ask the connection to update state as if enough time has passed to lose | 2451 // Ask the connection to update state as if enough time has passed to lose |
2441 // full writability and 5 pings went unresponded to. We'll accomplish the | 2452 // full writability and 5 pings went unresponded to. We'll accomplish the |
2442 // latter by sending pings but not pumping messages. | 2453 // latter by sending pings but not pumping messages. |
2443 for (uint32_t i = 1; i <= CONNECTION_WRITE_CONNECT_FAILURES; ++i) { | 2454 for (uint32_t i = 1; i <= CONNECTION_WRITE_CONNECT_FAILURES; ++i) { |
2444 ch1.Ping(i); | 2455 ch1.Ping(i); |
2445 } | 2456 } |
2446 int unreliable_timeout_delay = CONNECTION_WRITE_CONNECT_TIMEOUT + 500; | 2457 int unreliable_timeout_delay = CONNECTION_WRITE_CONNECT_TIMEOUT + 500; |
2447 ch1.conn()->UpdateState(unreliable_timeout_delay); | 2458 ch1.conn()->UpdateState(unreliable_timeout_delay); |
2448 EXPECT_EQ(Connection::STATE_WRITE_UNRELIABLE, ch1.conn()->write_state()); | 2459 EXPECT_EQ(Connection::STATE_WRITE_UNRELIABLE, ch1.conn()->write_state()); |
2449 | 2460 |
2450 // Data should be able to be sent in this state. | 2461 // Data should be able to be sent in this state. |
2451 EXPECT_EQ(data_size, ch1.conn()->Send(data, data_size, options)); | 2462 EXPECT_EQ(data_size, ch1.conn()->Send(data, data_size, options)); |
2452 | 2463 |
2453 // And now allow the other side to process the pings and send binding | 2464 // And now allow the other side to process the pings and send binding |
2454 // responses. | 2465 // responses. |
2455 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch1.conn()->write_state(), | 2466 EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, |
2456 kTimeout); | 2467 ch1.conn()->write_state(), kDefaultTimeout, clock); |
2457 | 2468 |
2458 // Wait long enough for a full timeout (past however long we've already | 2469 // Wait long enough for a full timeout (past however long we've already |
2459 // waited). | 2470 // waited). |
2460 for (uint32_t i = 1; i <= CONNECTION_WRITE_CONNECT_FAILURES; ++i) { | 2471 for (uint32_t i = 1; i <= CONNECTION_WRITE_CONNECT_FAILURES; ++i) { |
2461 ch1.Ping(unreliable_timeout_delay + i); | 2472 ch1.Ping(unreliable_timeout_delay + i); |
2462 } | 2473 } |
2463 ch1.conn()->UpdateState(unreliable_timeout_delay + CONNECTION_WRITE_TIMEOUT + | 2474 ch1.conn()->UpdateState(unreliable_timeout_delay + CONNECTION_WRITE_TIMEOUT + |
2464 500u); | 2475 500u); |
2465 EXPECT_EQ(Connection::STATE_WRITE_TIMEOUT, ch1.conn()->write_state()); | 2476 EXPECT_EQ(Connection::STATE_WRITE_TIMEOUT, ch1.conn()->write_state()); |
2466 | 2477 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2511 CreateTestPort(kLocalAddr2, "rfrag", "rpass", cricket::ICEROLE_CONTROLLED, | 2522 CreateTestPort(kLocalAddr2, "rfrag", "rpass", cricket::ICEROLE_CONTROLLED, |
2512 kTiebreaker2)); | 2523 kTiebreaker2)); |
2513 // Setup TestChannel. This behaves like FULL mode client. | 2524 // Setup TestChannel. This behaves like FULL mode client. |
2514 TestChannel ch1(ice_full_port); | 2525 TestChannel ch1(ice_full_port); |
2515 ch1.SetIceMode(ICEMODE_FULL); | 2526 ch1.SetIceMode(ICEMODE_FULL); |
2516 | 2527 |
2517 // Start gathering candidates. | 2528 // Start gathering candidates. |
2518 ch1.Start(); | 2529 ch1.Start(); |
2519 ice_lite_port->PrepareAddress(); | 2530 ice_lite_port->PrepareAddress(); |
2520 | 2531 |
2521 ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout); | 2532 ASSERT_EQ_WAIT(1, ch1.complete_count(), kDefaultTimeout); |
2522 ASSERT_FALSE(ice_lite_port->Candidates().empty()); | 2533 ASSERT_FALSE(ice_lite_port->Candidates().empty()); |
2523 | 2534 |
2524 ch1.CreateConnection(GetCandidate(ice_lite_port.get())); | 2535 ch1.CreateConnection(GetCandidate(ice_lite_port.get())); |
2525 ASSERT_TRUE(ch1.conn() != NULL); | 2536 ASSERT_TRUE(ch1.conn() != NULL); |
2526 EXPECT_EQ(Connection::STATE_WRITE_INIT, ch1.conn()->write_state()); | 2537 EXPECT_EQ(Connection::STATE_WRITE_INIT, ch1.conn()->write_state()); |
2527 | 2538 |
2528 // Send ping from full mode client. | 2539 // Send ping from full mode client. |
2529 // This ping must not have USE_CANDIDATE_ATTR. | 2540 // This ping must not have USE_CANDIDATE_ATTR. |
2530 ch1.Ping(); | 2541 ch1.Ping(); |
2531 | 2542 |
2532 // Verify stun ping is without USE_CANDIDATE_ATTR. Getting message directly | 2543 // Verify stun ping is without USE_CANDIDATE_ATTR. Getting message directly |
2533 // from port. | 2544 // from port. |
2534 ASSERT_TRUE_WAIT(ice_full_port->last_stun_msg() != NULL, 1000); | 2545 ASSERT_TRUE_WAIT(ice_full_port->last_stun_msg() != NULL, kDefaultTimeout); |
2535 IceMessage* msg = ice_full_port->last_stun_msg(); | 2546 IceMessage* msg = ice_full_port->last_stun_msg(); |
2536 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_USE_CANDIDATE) == NULL); | 2547 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_USE_CANDIDATE) == NULL); |
2537 | 2548 |
2538 // Respond with a BINDING-RESPONSE from litemode client. | 2549 // Respond with a BINDING-RESPONSE from litemode client. |
2539 // NOTE: Ideally we should't create connection at this stage from lite | 2550 // NOTE: Ideally we should't create connection at this stage from lite |
2540 // port, as it should be done only after receiving ping with USE_CANDIDATE. | 2551 // port, as it should be done only after receiving ping with USE_CANDIDATE. |
2541 // But we need a connection to send a response message. | 2552 // But we need a connection to send a response message. |
2542 ice_lite_port->CreateConnection( | 2553 ice_lite_port->CreateConnection( |
2543 ice_full_port->Candidates()[0], cricket::Port::ORIGIN_MESSAGE); | 2554 ice_full_port->Candidates()[0], cricket::Port::ORIGIN_MESSAGE); |
2544 std::unique_ptr<IceMessage> request(CopyStunMessage(msg)); | 2555 std::unique_ptr<IceMessage> request(CopyStunMessage(msg)); |
2545 ice_lite_port->SendBindingResponse( | 2556 ice_lite_port->SendBindingResponse( |
2546 request.get(), ice_full_port->Candidates()[0].address()); | 2557 request.get(), ice_full_port->Candidates()[0].address()); |
2547 | 2558 |
2548 // Feeding the respone message from litemode to the full mode connection. | 2559 // Feeding the respone message from litemode to the full mode connection. |
2549 ch1.conn()->OnReadPacket(ice_lite_port->last_stun_buf()->data<char>(), | 2560 ch1.conn()->OnReadPacket(ice_lite_port->last_stun_buf()->data<char>(), |
2550 ice_lite_port->last_stun_buf()->size(), | 2561 ice_lite_port->last_stun_buf()->size(), |
2551 rtc::PacketTime()); | 2562 rtc::PacketTime()); |
2552 // Verifying full mode connection becomes writable from the response. | 2563 // Verifying full mode connection becomes writable from the response. |
2553 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch1.conn()->write_state(), | 2564 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch1.conn()->write_state(), |
2554 kTimeout); | 2565 kDefaultTimeout); |
2555 EXPECT_TRUE_WAIT(ch1.nominated(), kTimeout); | 2566 EXPECT_TRUE_WAIT(ch1.nominated(), kDefaultTimeout); |
2556 | 2567 |
2557 // Clear existing stun messsages. Otherwise we will process old stun | 2568 // Clear existing stun messsages. Otherwise we will process old stun |
2558 // message right after we send ping. | 2569 // message right after we send ping. |
2559 ice_full_port->Reset(); | 2570 ice_full_port->Reset(); |
2560 // Send ping. This must have USE_CANDIDATE_ATTR. | 2571 // Send ping. This must have USE_CANDIDATE_ATTR. |
2561 ch1.Ping(); | 2572 ch1.Ping(); |
2562 ASSERT_TRUE_WAIT(ice_full_port->last_stun_msg() != NULL, 1000); | 2573 ASSERT_TRUE_WAIT(ice_full_port->last_stun_msg() != NULL, kDefaultTimeout); |
2563 msg = ice_full_port->last_stun_msg(); | 2574 msg = ice_full_port->last_stun_msg(); |
2564 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_USE_CANDIDATE) != NULL); | 2575 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_USE_CANDIDATE) != NULL); |
2565 ch1.Stop(); | 2576 ch1.Stop(); |
2566 } | 2577 } |
2567 | 2578 |
2568 // This test case verifies that both the controlling port and the controlled | 2579 // This test case verifies that both the controlling port and the controlled |
2569 // port will time out after connectivity is lost, if they are not marked as | 2580 // port will time out after connectivity is lost, if they are not marked as |
2570 // "keep alive until pruned." | 2581 // "keep alive until pruned." |
2571 TEST_F(PortTest, TestPortTimeoutIfNotKeptAlive) { | 2582 TEST_F(PortTest, TestPortTimeoutIfNotKeptAlive) { |
2572 rtc::ScopedFakeClock clock; | 2583 rtc::ScopedFakeClock clock; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2734 port->CreateConnection(candidate, Port::ORIGIN_MESSAGE); | 2745 port->CreateConnection(candidate, Port::ORIGIN_MESSAGE); |
2735 EXPECT_NE(conn1, conn2); | 2746 EXPECT_NE(conn1, conn2); |
2736 conn_in_use = port->GetConnection(address); | 2747 conn_in_use = port->GetConnection(address); |
2737 EXPECT_EQ(conn2, conn_in_use); | 2748 EXPECT_EQ(conn2, conn_in_use); |
2738 EXPECT_EQ(2u, conn_in_use->remote_candidate().generation()); | 2749 EXPECT_EQ(2u, conn_in_use->remote_candidate().generation()); |
2739 | 2750 |
2740 // Make sure the new connection was not deleted. | 2751 // Make sure the new connection was not deleted. |
2741 rtc::Thread::Current()->ProcessMessages(300); | 2752 rtc::Thread::Current()->ProcessMessages(300); |
2742 EXPECT_TRUE(port->GetConnection(address) != nullptr); | 2753 EXPECT_TRUE(port->GetConnection(address) != nullptr); |
2743 } | 2754 } |
OLD | NEW |