| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "webrtc/base/helpers.h" | 27 #include "webrtc/base/helpers.h" |
| 28 #include "webrtc/base/logging.h" | 28 #include "webrtc/base/logging.h" |
| 29 #include "webrtc/base/natserver.h" | 29 #include "webrtc/base/natserver.h" |
| 30 #include "webrtc/base/natsocketfactory.h" | 30 #include "webrtc/base/natsocketfactory.h" |
| 31 #include "webrtc/base/physicalsocketserver.h" | 31 #include "webrtc/base/physicalsocketserver.h" |
| 32 #include "webrtc/base/proxyserver.h" | 32 #include "webrtc/base/proxyserver.h" |
| 33 #include "webrtc/base/socketaddress.h" | 33 #include "webrtc/base/socketaddress.h" |
| 34 #include "webrtc/base/ssladapter.h" | 34 #include "webrtc/base/ssladapter.h" |
| 35 #include "webrtc/base/thread.h" | 35 #include "webrtc/base/thread.h" |
| 36 #include "webrtc/base/virtualsocketserver.h" | 36 #include "webrtc/base/virtualsocketserver.h" |
| 37 #include "webrtc/p2p/base/icetransportinternal.h" | |
| 38 | 37 |
| 39 namespace { | 38 namespace { |
| 40 | 39 |
| 41 using rtc::SocketAddress; | 40 using rtc::SocketAddress; |
| 42 | 41 |
| 43 // Default timeout for tests in this file. | 42 // Default timeout for tests in this file. |
| 44 // Should be large enough for slow buildbots to run the tests reliably. | 43 // Should be large enough for slow buildbots to run the tests reliably. |
| 45 static const int kDefaultTimeout = 10000; | 44 static const int kDefaultTimeout = 10000; |
| 46 static const int kMediumTimeout = 3000; | 45 static const int kMediumTimeout = 3000; |
| 47 static const int kShortTimeout = 1000; | 46 static const int kShortTimeout = 1000; |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 } | 264 } |
| 266 return ret; | 265 return ret; |
| 267 } | 266 } |
| 268 | 267 |
| 269 std::string name_; // TODO - Currently not used. | 268 std::string name_; // TODO - Currently not used. |
| 270 std::list<std::string> ch_packets_; | 269 std::list<std::string> ch_packets_; |
| 271 std::unique_ptr<P2PTransportChannel> ch_; | 270 std::unique_ptr<P2PTransportChannel> ch_; |
| 272 }; | 271 }; |
| 273 | 272 |
| 274 struct CandidatesData : public rtc::MessageData { | 273 struct CandidatesData : public rtc::MessageData { |
| 275 CandidatesData(IceTransportInternal* ch, const Candidate& c) | 274 CandidatesData(TransportChannel* ch, const Candidate& c) |
| 276 : channel(ch), candidates(1, c) {} | 275 : channel(ch), candidates(1, c) {} |
| 277 CandidatesData(IceTransportInternal* ch, const std::vector<Candidate>& cc) | 276 CandidatesData(TransportChannel* ch, const std::vector<Candidate>& cc) |
| 278 : channel(ch), candidates(cc) {} | 277 : channel(ch), candidates(cc) {} |
| 279 IceTransportInternal* channel; | 278 TransportChannel* channel; |
| 280 Candidates candidates; | 279 Candidates candidates; |
| 281 }; | 280 }; |
| 282 | 281 |
| 283 struct Endpoint { | 282 struct Endpoint { |
| 284 Endpoint() | 283 Endpoint() |
| 285 : role_(ICEROLE_UNKNOWN), | 284 : role_(ICEROLE_UNKNOWN), |
| 286 tiebreaker_(0), | 285 tiebreaker_(0), |
| 287 role_conflict_(false), | 286 role_conflict_(false), |
| 288 save_candidates_(false) {} | 287 save_candidates_(false) {} |
| 289 bool HasTransport(const rtc::PacketTransportInterface* transport) { | 288 bool HasTransport(const rtc::PacketTransportInterface* transport) { |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 ep2_ch1()->selected_connection()); | 678 ep2_ch1()->selected_connection()); |
| 680 | 679 |
| 681 TestSendRecv(clock); | 680 TestSendRecv(clock); |
| 682 } | 681 } |
| 683 | 682 |
| 684 void OnReadyToSend(rtc::PacketTransportInterface* transport) { | 683 void OnReadyToSend(rtc::PacketTransportInterface* transport) { |
| 685 GetEndpoint(transport)->ready_to_send_ = true; | 684 GetEndpoint(transport)->ready_to_send_ = true; |
| 686 } | 685 } |
| 687 | 686 |
| 688 // We pass the candidates directly to the other side. | 687 // We pass the candidates directly to the other side. |
| 689 void OnCandidateGathered(IceTransportInternal* ch, const Candidate& c) { | 688 void OnCandidateGathered(TransportChannelImpl* ch, const Candidate& c) { |
| 690 if (force_relay_ && c.type() != RELAY_PORT_TYPE) | 689 if (force_relay_ && c.type() != RELAY_PORT_TYPE) |
| 691 return; | 690 return; |
| 692 | 691 |
| 693 if (GetEndpoint(ch)->save_candidates_) { | 692 if (GetEndpoint(ch)->save_candidates_) { |
| 694 GetEndpoint(ch)->saved_candidates_.push_back( | 693 GetEndpoint(ch)->saved_candidates_.push_back( |
| 695 std::unique_ptr<CandidatesData>(new CandidatesData(ch, c))); | 694 std::unique_ptr<CandidatesData>(new CandidatesData(ch, c))); |
| 696 } else { | 695 } else { |
| 697 main_->Post(RTC_FROM_HERE, this, MSG_ADD_CANDIDATES, | 696 main_->Post(RTC_FROM_HERE, this, MSG_ADD_CANDIDATES, |
| 698 new CandidatesData(ch, c)); | 697 new CandidatesData(ch, c)); |
| 699 } | 698 } |
| 700 } | 699 } |
| 701 void OnSelectedCandidatePairChanged( | 700 void OnSelectedCandidatePairChanged( |
| 702 IceTransportInternal* transport_channel, | 701 TransportChannel* transport_channel, |
| 703 CandidatePairInterface* selected_candidate_pair, | 702 CandidatePairInterface* selected_candidate_pair, |
| 704 int last_sent_packet_id, | 703 int last_sent_packet_id, |
| 705 bool ready_to_send) { | 704 bool ready_to_send) { |
| 706 // Do not count if it switches to nullptr. This may happen if all | 705 // Do not count if it switches to nullptr. This may happen if all |
| 707 // connections timed out. | 706 // connections timed out. |
| 708 if (selected_candidate_pair != nullptr) { | 707 if (selected_candidate_pair != nullptr) { |
| 709 ++selected_candidate_pair_switches_; | 708 ++selected_candidate_pair_switches_; |
| 710 } | 709 } |
| 711 } | 710 } |
| 712 | 711 |
| 713 int reset_selected_candidate_pair_switches() { | 712 int reset_selected_candidate_pair_switches() { |
| 714 int switches = selected_candidate_pair_switches_; | 713 int switches = selected_candidate_pair_switches_; |
| 715 selected_candidate_pair_switches_ = 0; | 714 selected_candidate_pair_switches_ = 0; |
| 716 return switches; | 715 return switches; |
| 717 } | 716 } |
| 718 | 717 |
| 719 void PauseCandidates(int endpoint) { | 718 void PauseCandidates(int endpoint) { |
| 720 GetEndpoint(endpoint)->save_candidates_ = true; | 719 GetEndpoint(endpoint)->save_candidates_ = true; |
| 721 } | 720 } |
| 722 | 721 |
| 723 void OnCandidatesRemoved(IceTransportInternal* ch, | 722 void OnCandidatesRemoved(TransportChannelImpl* ch, |
| 724 const std::vector<Candidate>& candidates) { | 723 const std::vector<Candidate>& candidates) { |
| 725 // Candidate removals are not paused. | 724 // Candidate removals are not paused. |
| 726 CandidatesData* candidates_data = new CandidatesData(ch, candidates); | 725 CandidatesData* candidates_data = new CandidatesData(ch, candidates); |
| 727 main_->Post(RTC_FROM_HERE, this, MSG_REMOVE_CANDIDATES, candidates_data); | 726 main_->Post(RTC_FROM_HERE, this, MSG_REMOVE_CANDIDATES, candidates_data); |
| 728 } | 727 } |
| 729 | 728 |
| 730 // Tcp candidate verification has to be done when they are generated. | 729 // Tcp candidate verification has to be done when they are generated. |
| 731 void VerifySavedTcpCandidates(int endpoint, const std::string& tcptype) { | 730 void VerifySavedTcpCandidates(int endpoint, const std::string& tcptype) { |
| 732 for (auto& data : GetEndpoint(endpoint)->saved_candidates_) { | 731 for (auto& data : GetEndpoint(endpoint)->saved_candidates_) { |
| 733 for (auto& candidate : data->candidates) { | 732 for (auto& candidate : data->candidates) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 | 790 |
| 792 void OnReadPacket(rtc::PacketTransportInterface* transport, | 791 void OnReadPacket(rtc::PacketTransportInterface* transport, |
| 793 const char* data, | 792 const char* data, |
| 794 size_t len, | 793 size_t len, |
| 795 const rtc::PacketTime& packet_time, | 794 const rtc::PacketTime& packet_time, |
| 796 int flags) { | 795 int flags) { |
| 797 std::list<std::string>& packets = GetPacketList(transport); | 796 std::list<std::string>& packets = GetPacketList(transport); |
| 798 packets.push_front(std::string(data, len)); | 797 packets.push_front(std::string(data, len)); |
| 799 } | 798 } |
| 800 | 799 |
| 801 void OnRoleConflict(IceTransportInternal* channel) { | 800 void OnRoleConflict(TransportChannelImpl* channel) { |
| 802 GetEndpoint(channel)->OnRoleConflict(true); | 801 GetEndpoint(channel)->OnRoleConflict(true); |
| 803 IceRole new_role = GetEndpoint(channel)->ice_role() == ICEROLE_CONTROLLING | 802 IceRole new_role = GetEndpoint(channel)->ice_role() == ICEROLE_CONTROLLING |
| 804 ? ICEROLE_CONTROLLED | 803 ? ICEROLE_CONTROLLED |
| 805 : ICEROLE_CONTROLLING; | 804 : ICEROLE_CONTROLLING; |
| 806 channel->SetIceRole(new_role); | 805 channel->SetIceRole(new_role); |
| 807 } | 806 } |
| 808 | 807 |
| 809 int SendData(IceTransportInternal* channel, const char* data, size_t len) { | 808 int SendData(TransportChannel* channel, const char* data, size_t len) { |
| 810 rtc::PacketOptions options; | 809 rtc::PacketOptions options; |
| 811 return channel->SendPacket(data, len, options, 0); | 810 return channel->SendPacket(data, len, options, 0); |
| 812 } | 811 } |
| 813 bool CheckDataOnChannel(IceTransportInternal* channel, | 812 bool CheckDataOnChannel(TransportChannel* channel, |
| 814 const char* data, | 813 const char* data, |
| 815 int len) { | 814 int len) { |
| 816 return GetChannelData(channel)->CheckData(data, len); | 815 return GetChannelData(channel)->CheckData(data, len); |
| 817 } | 816 } |
| 818 static const Candidate* LocalCandidate(P2PTransportChannel* ch) { | 817 static const Candidate* LocalCandidate(P2PTransportChannel* ch) { |
| 819 return (ch && ch->selected_connection()) | 818 return (ch && ch->selected_connection()) |
| 820 ? &ch->selected_connection()->local_candidate() | 819 ? &ch->selected_connection()->local_candidate() |
| 821 : NULL; | 820 : NULL; |
| 822 } | 821 } |
| 823 static const Candidate* RemoteCandidate(P2PTransportChannel* ch) { | 822 static const Candidate* RemoteCandidate(P2PTransportChannel* ch) { |
| 824 return (ch && ch->selected_connection()) | 823 return (ch && ch->selected_connection()) |
| 825 ? &ch->selected_connection()->remote_candidate() | 824 ? &ch->selected_connection()->remote_candidate() |
| 826 : NULL; | 825 : NULL; |
| 827 } | 826 } |
| 828 Endpoint* GetEndpoint(rtc::PacketTransportInterface* transport) { | 827 Endpoint* GetEndpoint(rtc::PacketTransportInterface* transport) { |
| 829 if (ep1_.HasTransport(transport)) { | 828 if (ep1_.HasTransport(transport)) { |
| 830 return &ep1_; | 829 return &ep1_; |
| 831 } else if (ep2_.HasTransport(transport)) { | 830 } else if (ep2_.HasTransport(transport)) { |
| 832 return &ep2_; | 831 return &ep2_; |
| 833 } else { | 832 } else { |
| 834 return NULL; | 833 return NULL; |
| 835 } | 834 } |
| 836 } | 835 } |
| 837 P2PTransportChannel* GetRemoteChannel(IceTransportInternal* ch) { | 836 P2PTransportChannel* GetRemoteChannel(TransportChannel* ch) { |
| 838 if (ch == ep1_ch1()) | 837 if (ch == ep1_ch1()) |
| 839 return ep2_ch1(); | 838 return ep2_ch1(); |
| 840 else if (ch == ep1_ch2()) | 839 else if (ch == ep1_ch2()) |
| 841 return ep2_ch2(); | 840 return ep2_ch2(); |
| 842 else if (ch == ep2_ch1()) | 841 else if (ch == ep2_ch1()) |
| 843 return ep1_ch1(); | 842 return ep1_ch1(); |
| 844 else if (ch == ep2_ch2()) | 843 else if (ch == ep2_ch2()) |
| 845 return ep1_ch2(); | 844 return ep1_ch2(); |
| 846 else | 845 else |
| 847 return NULL; | 846 return NULL; |
| (...skipping 1802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2650 // Create channels and let them go writable, as usual. | 2649 // Create channels and let them go writable, as usual. |
| 2651 CreateChannels(); | 2650 CreateChannels(); |
| 2652 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 2651 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 2653 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 2652 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 2654 1000, 1000); | 2653 1000, 1000); |
| 2655 int backup_ping_interval = 2000; | 2654 int backup_ping_interval = 2000; |
| 2656 ep2_ch1()->SetIceConfig( | 2655 ep2_ch1()->SetIceConfig( |
| 2657 CreateIceConfig(2000, GATHER_ONCE, backup_ping_interval)); | 2656 CreateIceConfig(2000, GATHER_ONCE, backup_ping_interval)); |
| 2658 // After the state becomes COMPLETED, the backup connection will be pinged | 2657 // After the state becomes COMPLETED, the backup connection will be pinged |
| 2659 // once every |backup_ping_interval| milliseconds. | 2658 // once every |backup_ping_interval| milliseconds. |
| 2660 ASSERT_TRUE_WAIT(ep2_ch1()->GetState() == IceTransportState::STATE_COMPLETED, | 2659 ASSERT_TRUE_WAIT(ep2_ch1()->GetState() == STATE_COMPLETED, 1000); |
| 2661 1000); | |
| 2662 const std::vector<Connection*>& connections = ep2_ch1()->connections(); | 2660 const std::vector<Connection*>& connections = ep2_ch1()->connections(); |
| 2663 ASSERT_EQ(2U, connections.size()); | 2661 ASSERT_EQ(2U, connections.size()); |
| 2664 Connection* backup_conn = connections[1]; | 2662 Connection* backup_conn = connections[1]; |
| 2665 EXPECT_TRUE_WAIT(backup_conn->writable(), kMediumTimeout); | 2663 EXPECT_TRUE_WAIT(backup_conn->writable(), kMediumTimeout); |
| 2666 int64_t last_ping_response_ms = backup_conn->last_ping_response_received(); | 2664 int64_t last_ping_response_ms = backup_conn->last_ping_response_received(); |
| 2667 EXPECT_TRUE_WAIT( | 2665 EXPECT_TRUE_WAIT( |
| 2668 last_ping_response_ms < backup_conn->last_ping_response_received(), | 2666 last_ping_response_ms < backup_conn->last_ping_response_received(), |
| 2669 kDefaultTimeout); | 2667 kDefaultTimeout); |
| 2670 int time_elapsed = | 2668 int time_elapsed = |
| 2671 backup_conn->last_ping_response_received() - last_ping_response_ms; | 2669 backup_conn->last_ping_response_received() - last_ping_response_ms; |
| 2672 LOG(LS_INFO) << "Time elapsed: " << time_elapsed; | 2670 LOG(LS_INFO) << "Time elapsed: " << time_elapsed; |
| 2673 EXPECT_GE(time_elapsed, backup_ping_interval); | 2671 EXPECT_GE(time_elapsed, backup_ping_interval); |
| 2674 | 2672 |
| 2675 DestroyChannels(); | 2673 DestroyChannels(); |
| 2676 } | 2674 } |
| 2677 | 2675 |
| 2678 TEST_F(P2PTransportChannelMultihomedTest, TestGetState) { | 2676 TEST_F(P2PTransportChannelMultihomedTest, TestGetState) { |
| 2679 rtc::ScopedFakeClock clock; | 2677 rtc::ScopedFakeClock clock; |
| 2680 AddAddress(0, kAlternateAddrs[0]); | 2678 AddAddress(0, kAlternateAddrs[0]); |
| 2681 AddAddress(0, kPublicAddrs[0]); | 2679 AddAddress(0, kPublicAddrs[0]); |
| 2682 AddAddress(1, kPublicAddrs[1]); | 2680 AddAddress(1, kPublicAddrs[1]); |
| 2683 // Create channels and let them go writable, as usual. | 2681 // Create channels and let them go writable, as usual. |
| 2684 CreateChannels(); | 2682 CreateChannels(); |
| 2685 | 2683 |
| 2686 // Both transport channels will reach STATE_COMPLETED quickly. | 2684 // Both transport channels will reach STATE_COMPLETED quickly. |
| 2687 EXPECT_EQ_SIMULATED_WAIT(IceTransportState::STATE_COMPLETED, | 2685 EXPECT_EQ_SIMULATED_WAIT(TransportChannelState::STATE_COMPLETED, |
| 2688 ep1_ch1()->GetState(), kShortTimeout, clock); | 2686 ep1_ch1()->GetState(), kShortTimeout, clock); |
| 2689 EXPECT_EQ_SIMULATED_WAIT(IceTransportState::STATE_COMPLETED, | 2687 EXPECT_EQ_SIMULATED_WAIT(TransportChannelState::STATE_COMPLETED, |
| 2690 ep2_ch1()->GetState(), kShortTimeout, clock); | 2688 ep2_ch1()->GetState(), kShortTimeout, clock); |
| 2691 } | 2689 } |
| 2692 | 2690 |
| 2693 // Tests that when a network interface becomes inactive, if Continual Gathering | 2691 // Tests that when a network interface becomes inactive, if Continual Gathering |
| 2694 // policy is GATHER_CONTINUALLY, the ports associated with that network | 2692 // policy is GATHER_CONTINUALLY, the ports associated with that network |
| 2695 // will be removed from the port list of the channel, and the respective | 2693 // will be removed from the port list of the channel, and the respective |
| 2696 // remote candidates on the other participant will be removed eventually. | 2694 // remote candidates on the other participant will be removed eventually. |
| 2697 TEST_F(P2PTransportChannelMultihomedTest, TestNetworkBecomesInactive) { | 2695 TEST_F(P2PTransportChannelMultihomedTest, TestNetworkBecomesInactive) { |
| 2698 rtc::ScopedFakeClock clock; | 2696 rtc::ScopedFakeClock clock; |
| 2699 AddAddress(0, kPublicAddrs[0]); | 2697 AddAddress(0, kPublicAddrs[0]); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2761 conn->remote_candidate().address().EqualIPs(wifi[1]), | 2759 conn->remote_candidate().address().EqualIPs(wifi[1]), |
| 2762 kDefaultTimeout); | 2760 kDefaultTimeout); |
| 2763 EXPECT_TRUE_WAIT((conn = ep2_ch1()->selected_connection()) != nullptr && | 2761 EXPECT_TRUE_WAIT((conn = ep2_ch1()->selected_connection()) != nullptr && |
| 2764 conn->local_candidate().address().EqualIPs(wifi[1]), | 2762 conn->local_candidate().address().EqualIPs(wifi[1]), |
| 2765 kDefaultTimeout); | 2763 kDefaultTimeout); |
| 2766 | 2764 |
| 2767 // Add a new cellular interface on end point 1, we should expect a new | 2765 // Add a new cellular interface on end point 1, we should expect a new |
| 2768 // backup connection created using this new interface. | 2766 // backup connection created using this new interface. |
| 2769 AddAddress(0, cellular[0], "test_cellular0", rtc::ADAPTER_TYPE_CELLULAR); | 2767 AddAddress(0, cellular[0], "test_cellular0", rtc::ADAPTER_TYPE_CELLULAR); |
| 2770 EXPECT_TRUE_WAIT( | 2768 EXPECT_TRUE_WAIT( |
| 2771 ep1_ch1()->GetState() == IceTransportState::STATE_COMPLETED && | 2769 ep1_ch1()->GetState() == STATE_COMPLETED && |
| 2772 (conn = GetConnectionWithLocalAddress(ep1_ch1(), cellular[0])) != | 2770 (conn = GetConnectionWithLocalAddress(ep1_ch1(), cellular[0])) != |
| 2773 nullptr && | 2771 nullptr && |
| 2774 conn != ep1_ch1()->selected_connection() && conn->writable(), | 2772 conn != ep1_ch1()->selected_connection() && conn->writable(), |
| 2775 kDefaultTimeout); | 2773 kDefaultTimeout); |
| 2776 EXPECT_TRUE_WAIT( | 2774 EXPECT_TRUE_WAIT( |
| 2777 ep2_ch1()->GetState() == IceTransportState::STATE_COMPLETED && | 2775 ep2_ch1()->GetState() == STATE_COMPLETED && |
| 2778 (conn = GetConnectionWithRemoteAddress(ep2_ch1(), cellular[0])) != | 2776 (conn = GetConnectionWithRemoteAddress(ep2_ch1(), cellular[0])) != |
| 2779 nullptr && | 2777 nullptr && |
| 2780 conn != ep2_ch1()->selected_connection() && conn->receiving(), | 2778 conn != ep2_ch1()->selected_connection() && conn->receiving(), |
| 2781 kDefaultTimeout); | 2779 kDefaultTimeout); |
| 2782 | 2780 |
| 2783 DestroyChannels(); | 2781 DestroyChannels(); |
| 2784 } | 2782 } |
| 2785 | 2783 |
| 2786 // Tests that we can switch links via continual gathering. | 2784 // Tests that we can switch links via continual gathering. |
| 2787 TEST_F(P2PTransportChannelMultihomedTest, | 2785 TEST_F(P2PTransportChannelMultihomedTest, |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2983 } | 2981 } |
| 2984 | 2982 |
| 2985 Connection* FindNextPingableConnectionAndPingIt(P2PTransportChannel* ch) { | 2983 Connection* FindNextPingableConnectionAndPingIt(P2PTransportChannel* ch) { |
| 2986 Connection* conn = ch->FindNextPingableConnection(); | 2984 Connection* conn = ch->FindNextPingableConnection(); |
| 2987 if (conn) { | 2985 if (conn) { |
| 2988 ch->MarkConnectionPinged(conn); | 2986 ch->MarkConnectionPinged(conn); |
| 2989 } | 2987 } |
| 2990 return conn; | 2988 return conn; |
| 2991 } | 2989 } |
| 2992 | 2990 |
| 2993 int SendData(IceTransportInternal& channel, | 2991 int SendData(TransportChannel& channel, |
| 2994 const char* data, | 2992 const char* data, |
| 2995 size_t len, | 2993 size_t len, |
| 2996 int packet_id) { | 2994 int packet_id) { |
| 2997 rtc::PacketOptions options; | 2995 rtc::PacketOptions options; |
| 2998 options.packet_id = packet_id; | 2996 options.packet_id = packet_id; |
| 2999 return channel.SendPacket(data, len, options, 0); | 2997 return channel.SendPacket(data, len, options, 0); |
| 3000 } | 2998 } |
| 3001 | 2999 |
| 3002 Connection* CreateConnectionWithCandidate(P2PTransportChannel& channel, | 3000 Connection* CreateConnectionWithCandidate(P2PTransportChannel& channel, |
| 3003 rtc::ScopedFakeClock& clock, | 3001 rtc::ScopedFakeClock& clock, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3017 } | 3015 } |
| 3018 return conn; | 3016 return conn; |
| 3019 } | 3017 } |
| 3020 | 3018 |
| 3021 void NominateConnection(Connection* conn, uint32_t remote_nomination = 1U) { | 3019 void NominateConnection(Connection* conn, uint32_t remote_nomination = 1U) { |
| 3022 conn->set_remote_nomination(remote_nomination); | 3020 conn->set_remote_nomination(remote_nomination); |
| 3023 conn->SignalNominated(conn); | 3021 conn->SignalNominated(conn); |
| 3024 } | 3022 } |
| 3025 | 3023 |
| 3026 void OnSelectedCandidatePairChanged( | 3024 void OnSelectedCandidatePairChanged( |
| 3027 IceTransportInternal* transport_channel, | 3025 TransportChannel* transport_channel, |
| 3028 CandidatePairInterface* selected_candidate_pair, | 3026 CandidatePairInterface* selected_candidate_pair, |
| 3029 int last_sent_packet_id, | 3027 int last_sent_packet_id, |
| 3030 bool ready_to_send) { | 3028 bool ready_to_send) { |
| 3031 last_selected_candidate_pair_ = selected_candidate_pair; | 3029 last_selected_candidate_pair_ = selected_candidate_pair; |
| 3032 last_sent_packet_id_ = last_sent_packet_id; | 3030 last_sent_packet_id_ = last_sent_packet_id; |
| 3033 ++selected_candidate_pair_switches_; | 3031 ++selected_candidate_pair_switches_; |
| 3034 } | 3032 } |
| 3035 | 3033 |
| 3036 void ReceivePingOnConnection(Connection* conn, | 3034 void ReceivePingOnConnection(Connection* conn, |
| 3037 const std::string& remote_ufrag, | 3035 const std::string& remote_ufrag, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3051 msg.AddMessageIntegrity(conn->local_candidate().password()); | 3049 msg.AddMessageIntegrity(conn->local_candidate().password()); |
| 3052 msg.AddFingerprint(); | 3050 msg.AddFingerprint(); |
| 3053 rtc::ByteBufferWriter buf; | 3051 rtc::ByteBufferWriter buf; |
| 3054 msg.Write(&buf); | 3052 msg.Write(&buf); |
| 3055 conn->OnReadPacket(buf.Data(), buf.Length(), rtc::CreatePacketTime(0)); | 3053 conn->OnReadPacket(buf.Data(), buf.Length(), rtc::CreatePacketTime(0)); |
| 3056 } | 3054 } |
| 3057 | 3055 |
| 3058 void OnReadyToSend(rtc::PacketTransportInterface* transport) { | 3056 void OnReadyToSend(rtc::PacketTransportInterface* transport) { |
| 3059 channel_ready_to_send_ = true; | 3057 channel_ready_to_send_ = true; |
| 3060 } | 3058 } |
| 3061 void OnChannelStateChanged(IceTransportInternal* channel) { | 3059 void OnChannelStateChanged(TransportChannelImpl* channel) { |
| 3062 channel_state_ = channel->GetState(); | 3060 channel_state_ = channel->GetState(); |
| 3063 } | 3061 } |
| 3064 | 3062 |
| 3065 CandidatePairInterface* last_selected_candidate_pair() { | 3063 CandidatePairInterface* last_selected_candidate_pair() { |
| 3066 return last_selected_candidate_pair_; | 3064 return last_selected_candidate_pair_; |
| 3067 } | 3065 } |
| 3068 int last_sent_packet_id() { return last_sent_packet_id_; } | 3066 int last_sent_packet_id() { return last_sent_packet_id_; } |
| 3069 bool channel_ready_to_send() { return channel_ready_to_send_; } | 3067 bool channel_ready_to_send() { return channel_ready_to_send_; } |
| 3070 void reset_channel_ready_to_send() { channel_ready_to_send_ = false; } | 3068 void reset_channel_ready_to_send() { channel_ready_to_send_ = false; } |
| 3071 IceTransportState channel_state() { return channel_state_; } | 3069 TransportChannelState channel_state() { return channel_state_; } |
| 3072 int reset_selected_candidate_pair_switches() { | 3070 int reset_selected_candidate_pair_switches() { |
| 3073 int switches = selected_candidate_pair_switches_; | 3071 int switches = selected_candidate_pair_switches_; |
| 3074 selected_candidate_pair_switches_ = 0; | 3072 selected_candidate_pair_switches_ = 0; |
| 3075 return switches; | 3073 return switches; |
| 3076 } | 3074 } |
| 3077 | 3075 |
| 3078 private: | 3076 private: |
| 3079 std::unique_ptr<rtc::PhysicalSocketServer> pss_; | 3077 std::unique_ptr<rtc::PhysicalSocketServer> pss_; |
| 3080 std::unique_ptr<rtc::VirtualSocketServer> vss_; | 3078 std::unique_ptr<rtc::VirtualSocketServer> vss_; |
| 3081 rtc::SocketServerScope ss_scope_; | 3079 rtc::SocketServerScope ss_scope_; |
| 3082 CandidatePairInterface* last_selected_candidate_pair_ = nullptr; | 3080 CandidatePairInterface* last_selected_candidate_pair_ = nullptr; |
| 3083 int selected_candidate_pair_switches_ = 0; | 3081 int selected_candidate_pair_switches_ = 0; |
| 3084 int last_sent_packet_id_ = -1; | 3082 int last_sent_packet_id_ = -1; |
| 3085 bool channel_ready_to_send_ = false; | 3083 bool channel_ready_to_send_ = false; |
| 3086 IceTransportState channel_state_ = IceTransportState::STATE_INIT; | 3084 TransportChannelState channel_state_ = STATE_INIT; |
| 3087 }; | 3085 }; |
| 3088 | 3086 |
| 3089 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) { | 3087 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) { |
| 3090 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3088 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 3091 P2PTransportChannel ch("trigger checks", 1, &pa); | 3089 P2PTransportChannel ch("trigger checks", 1, &pa); |
| 3092 PrepareChannel(&ch); | 3090 PrepareChannel(&ch); |
| 3093 ch.MaybeStartGathering(); | 3091 ch.MaybeStartGathering(); |
| 3094 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); | 3092 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); |
| 3095 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); | 3093 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); |
| 3096 | 3094 |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3312 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3310 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 3313 P2PTransportChannel ch("state change", 1, &pa); | 3311 P2PTransportChannel ch("state change", 1, &pa); |
| 3314 PrepareChannel(&ch); | 3312 PrepareChannel(&ch); |
| 3315 ch.MaybeStartGathering(); | 3313 ch.MaybeStartGathering(); |
| 3316 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); | 3314 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); |
| 3317 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 3315 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 3318 ASSERT_TRUE(conn1 != nullptr); | 3316 ASSERT_TRUE(conn1 != nullptr); |
| 3319 // Pruning the connection reduces the set of active connections and changes | 3317 // Pruning the connection reduces the set of active connections and changes |
| 3320 // the channel state. | 3318 // the channel state. |
| 3321 conn1->Prune(); | 3319 conn1->Prune(); |
| 3322 EXPECT_EQ_WAIT(IceTransportState::STATE_FAILED, channel_state(), | 3320 EXPECT_EQ_WAIT(STATE_FAILED, channel_state(), kDefaultTimeout); |
| 3323 kDefaultTimeout); | |
| 3324 } | 3321 } |
| 3325 | 3322 |
| 3326 // Test adding remote candidates with different ufrags. If a remote candidate | 3323 // Test adding remote candidates with different ufrags. If a remote candidate |
| 3327 // is added with an old ufrag, it will be discarded. If it is added with a | 3324 // is added with an old ufrag, it will be discarded. If it is added with a |
| 3328 // ufrag that was not seen before, it will be used to create connections | 3325 // ufrag that was not seen before, it will be used to create connections |
| 3329 // although the ICE pwd in the remote candidate will be set when the ICE | 3326 // although the ICE pwd in the remote candidate will be set when the ICE |
| 3330 // parameters arrive. If a remote candidate is added with the current ICE | 3327 // parameters arrive. If a remote candidate is added with the current ICE |
| 3331 // ufrag, its pwd and generation will be set properly. | 3328 // ufrag, its pwd and generation will be set properly. |
| 3332 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) { | 3329 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) { |
| 3333 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3330 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| (...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3964 } | 3961 } |
| 3965 | 3962 |
| 3966 // Test that GetState returns the state correctly. | 3963 // Test that GetState returns the state correctly. |
| 3967 TEST_F(P2PTransportChannelPingTest, TestGetState) { | 3964 TEST_F(P2PTransportChannelPingTest, TestGetState) { |
| 3968 rtc::ScopedFakeClock clock; | 3965 rtc::ScopedFakeClock clock; |
| 3969 clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1)); | 3966 clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1)); |
| 3970 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3967 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 3971 P2PTransportChannel ch("test channel", 1, &pa); | 3968 P2PTransportChannel ch("test channel", 1, &pa); |
| 3972 PrepareChannel(&ch); | 3969 PrepareChannel(&ch); |
| 3973 ch.MaybeStartGathering(); | 3970 ch.MaybeStartGathering(); |
| 3974 EXPECT_EQ(IceTransportState::STATE_INIT, ch.GetState()); | 3971 EXPECT_EQ(TransportChannelState::STATE_INIT, ch.GetState()); |
| 3975 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); | 3972 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); |
| 3976 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); | 3973 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); |
| 3977 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1, &clock); | 3974 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1, &clock); |
| 3978 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2, &clock); | 3975 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2, &clock); |
| 3979 ASSERT_TRUE(conn1 != nullptr); | 3976 ASSERT_TRUE(conn1 != nullptr); |
| 3980 ASSERT_TRUE(conn2 != nullptr); | 3977 ASSERT_TRUE(conn2 != nullptr); |
| 3981 // Now there are two connections, so the transport channel is connecting. | 3978 // Now there are two connections, so the transport channel is connecting. |
| 3982 EXPECT_EQ(IceTransportState::STATE_CONNECTING, ch.GetState()); | 3979 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState()); |
| 3983 // |conn1| becomes writable and receiving; it then should prune |conn2|. | 3980 // |conn1| becomes writable and receiving; it then should prune |conn2|. |
| 3984 conn1->ReceivedPingResponse(LOW_RTT, "id"); | 3981 conn1->ReceivedPingResponse(LOW_RTT, "id"); |
| 3985 EXPECT_TRUE_SIMULATED_WAIT(conn2->pruned(), kShortTimeout, clock); | 3982 EXPECT_TRUE_SIMULATED_WAIT(conn2->pruned(), kShortTimeout, clock); |
| 3986 EXPECT_EQ(IceTransportState::STATE_COMPLETED, ch.GetState()); | 3983 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); |
| 3987 conn1->Prune(); // All connections are pruned. | 3984 conn1->Prune(); // All connections are pruned. |
| 3988 // Need to wait until the channel state is updated. | 3985 // Need to wait until the channel state is updated. |
| 3989 EXPECT_EQ_SIMULATED_WAIT(IceTransportState::STATE_FAILED, ch.GetState(), | 3986 EXPECT_EQ_SIMULATED_WAIT(TransportChannelState::STATE_FAILED, ch.GetState(), |
| 3990 kShortTimeout, clock); | 3987 kShortTimeout, clock); |
| 3991 } | 3988 } |
| 3992 | 3989 |
| 3993 // Test that when a low-priority connection is pruned, it is not deleted | 3990 // Test that when a low-priority connection is pruned, it is not deleted |
| 3994 // right away, and it can become active and be pruned again. | 3991 // right away, and it can become active and be pruned again. |
| 3995 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { | 3992 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { |
| 3996 rtc::ScopedFakeClock clock; | 3993 rtc::ScopedFakeClock clock; |
| 3997 clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1)); | 3994 clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1)); |
| 3998 | 3995 |
| 3999 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3996 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 4014 // Add a low-priority connection |conn2|, which will be pruned, but it will | 4011 // Add a low-priority connection |conn2|, which will be pruned, but it will |
| 4015 // not be deleted right away. Once the current selected connection becomes not | 4012 // not be deleted right away. Once the current selected connection becomes not |
| 4016 // receiving, |conn2| will start to ping and upon receiving the ping response, | 4013 // receiving, |conn2| will start to ping and upon receiving the ping response, |
| 4017 // it will become the selected connection. | 4014 // it will become the selected connection. |
| 4018 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); | 4015 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); |
| 4019 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2, &clock); | 4016 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2, &clock); |
| 4020 ASSERT_TRUE(conn2 != nullptr); | 4017 ASSERT_TRUE(conn2 != nullptr); |
| 4021 EXPECT_TRUE_SIMULATED_WAIT(!conn2->active(), kDefaultTimeout, clock); | 4018 EXPECT_TRUE_SIMULATED_WAIT(!conn2->active(), kDefaultTimeout, clock); |
| 4022 // |conn2| should not send a ping yet. | 4019 // |conn2| should not send a ping yet. |
| 4023 EXPECT_EQ(Connection::STATE_WAITING, conn2->state()); | 4020 EXPECT_EQ(Connection::STATE_WAITING, conn2->state()); |
| 4024 EXPECT_EQ(IceTransportState::STATE_COMPLETED, ch.GetState()); | 4021 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); |
| 4025 // Wait for |conn1| becoming not receiving. | 4022 // Wait for |conn1| becoming not receiving. |
| 4026 EXPECT_TRUE_SIMULATED_WAIT(!conn1->receiving(), kMediumTimeout, clock); | 4023 EXPECT_TRUE_SIMULATED_WAIT(!conn1->receiving(), kMediumTimeout, clock); |
| 4027 // Make sure conn2 is not deleted. | 4024 // Make sure conn2 is not deleted. |
| 4028 conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2, &clock); | 4025 conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2, &clock); |
| 4029 ASSERT_TRUE(conn2 != nullptr); | 4026 ASSERT_TRUE(conn2 != nullptr); |
| 4030 EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_INPROGRESS, conn2->state(), | 4027 EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_INPROGRESS, conn2->state(), |
| 4031 kDefaultTimeout, clock); | 4028 kDefaultTimeout, clock); |
| 4032 conn2->ReceivedPingResponse(LOW_RTT, "id"); | 4029 conn2->ReceivedPingResponse(LOW_RTT, "id"); |
| 4033 EXPECT_EQ_SIMULATED_WAIT(conn2, ch.selected_connection(), kDefaultTimeout, | 4030 EXPECT_EQ_SIMULATED_WAIT(conn2, ch.selected_connection(), kDefaultTimeout, |
| 4034 clock); | 4031 clock); |
| 4035 EXPECT_EQ(IceTransportState::STATE_CONNECTING, ch.GetState()); | 4032 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState()); |
| 4036 | 4033 |
| 4037 // When |conn1| comes back again, |conn2| will be pruned again. | 4034 // When |conn1| comes back again, |conn2| will be pruned again. |
| 4038 conn1->ReceivedPingResponse(LOW_RTT, "id"); | 4035 conn1->ReceivedPingResponse(LOW_RTT, "id"); |
| 4039 EXPECT_EQ_SIMULATED_WAIT(conn1, ch.selected_connection(), kDefaultTimeout, | 4036 EXPECT_EQ_SIMULATED_WAIT(conn1, ch.selected_connection(), kDefaultTimeout, |
| 4040 clock); | 4037 clock); |
| 4041 EXPECT_TRUE_SIMULATED_WAIT(!conn2->active(), kDefaultTimeout, clock); | 4038 EXPECT_TRUE_SIMULATED_WAIT(!conn2->active(), kDefaultTimeout, clock); |
| 4042 EXPECT_EQ(IceTransportState::STATE_COMPLETED, ch.GetState()); | 4039 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); |
| 4043 } | 4040 } |
| 4044 | 4041 |
| 4045 // Test that if all connections in a channel has timed out on writing, they | 4042 // Test that if all connections in a channel has timed out on writing, they |
| 4046 // will all be deleted. We use Prune to simulate write_time_out. | 4043 // will all be deleted. We use Prune to simulate write_time_out. |
| 4047 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { | 4044 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { |
| 4048 rtc::ScopedFakeClock clock; | 4045 rtc::ScopedFakeClock clock; |
| 4049 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 4046 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 4050 P2PTransportChannel ch("test channel", 1, &pa); | 4047 P2PTransportChannel ch("test channel", 1, &pa); |
| 4051 PrepareChannel(&ch); | 4048 PrepareChannel(&ch); |
| 4052 ch.MaybeStartGathering(); | 4049 ch.MaybeStartGathering(); |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4387 | 4384 |
| 4388 // TCP Relay/Relay is the next. | 4385 // TCP Relay/Relay is the next. |
| 4389 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, | 4386 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, |
| 4390 TCP_PROTOCOL_NAME); | 4387 TCP_PROTOCOL_NAME); |
| 4391 | 4388 |
| 4392 // Finally, Local/Relay will be pinged. | 4389 // Finally, Local/Relay will be pinged. |
| 4393 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); | 4390 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); |
| 4394 } | 4391 } |
| 4395 | 4392 |
| 4396 } // namespace cricket { | 4393 } // namespace cricket { |
| OLD | NEW |