Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: webrtc/p2p/base/p2ptransportchannel_unittest.cc

Issue 2412433003: Revert of Prune connections based on network name. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2795 matching lines...) Expand 10 before | Expand all | Expand 10 after
2806 rtc::FakeClock* clock = nullptr) { 2806 rtc::FakeClock* clock = nullptr) {
2807 if (clock == nullptr) { 2807 if (clock == nullptr) {
2808 EXPECT_TRUE_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, 3000); 2808 EXPECT_TRUE_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, 3000);
2809 } else { 2809 } else {
2810 EXPECT_TRUE_SIMULATED_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, 2810 EXPECT_TRUE_SIMULATED_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr,
2811 3000, *clock); 2811 3000, *clock);
2812 } 2812 }
2813 return GetConnectionTo(ch, ip, port_num); 2813 return GetConnectionTo(ch, ip, port_num);
2814 } 2814 }
2815 2815
2816 Port* GetFirstPort(P2PTransportChannel* ch) { 2816 Port* GetPort(P2PTransportChannel* ch) {
2817 if (ch->ports().empty()) { 2817 if (ch->ports().empty()) {
2818 return nullptr; 2818 return nullptr;
2819 } 2819 }
2820 return static_cast<Port*>(ch->ports()[0]); 2820 return static_cast<Port*>(ch->ports()[0]);
2821 } 2821 }
2822 2822
2823 Port* GetPrunedPort(P2PTransportChannel* ch) { 2823 Port* GetPrunedPort(P2PTransportChannel* ch) {
2824 if (ch->pruned_ports().empty()) { 2824 if (ch->pruned_ports().empty()) {
2825 return nullptr; 2825 return nullptr;
2826 } 2826 }
2827 return static_cast<Port*>(ch->pruned_ports()[0]); 2827 return static_cast<Port*>(ch->pruned_ports()[0]);
2828 } 2828 }
2829 2829
2830 Connection* GetConnectionTo(P2PTransportChannel* ch, 2830 Connection* GetConnectionTo(P2PTransportChannel* ch,
2831 const std::string& ip, 2831 const std::string& ip,
2832 int port_num) { 2832 int port_num) {
2833 for (PortInterface* port : ch->ports()) { 2833 Port* port = GetPort(ch);
2834 Connection* conn = port->GetConnection(rtc::SocketAddress(ip, port_num)); 2834 if (!port) {
2835 if (conn != nullptr) { 2835 return nullptr;
2836 return conn;
2837 }
2838 } 2836 }
2839 return nullptr; 2837 return port->GetConnection(rtc::SocketAddress(ip, port_num));
2840 } 2838 }
2841 2839
2842 Connection* FindNextPingableConnectionAndPingIt(P2PTransportChannel* ch) { 2840 Connection* FindNextPingableConnectionAndPingIt(P2PTransportChannel* ch) {
2843 Connection* conn = ch->FindNextPingableConnection(); 2841 Connection* conn = ch->FindNextPingableConnection();
2844 if (conn) { 2842 if (conn) {
2845 ch->MarkConnectionPinged(conn); 2843 ch->MarkConnectionPinged(conn);
2846 } 2844 }
2847 return conn; 2845 return conn;
2848 } 2846 }
2849 2847
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
3086 3084
3087 // Simulate a binding request being received, creating a peer reflexive 3085 // Simulate a binding request being received, creating a peer reflexive
3088 // candidate pair while we still don't have remote ICE parameters. 3086 // candidate pair while we still don't have remote ICE parameters.
3089 IceMessage request; 3087 IceMessage request;
3090 request.SetType(STUN_BINDING_REQUEST); 3088 request.SetType(STUN_BINDING_REQUEST);
3091 request.AddAttribute( 3089 request.AddAttribute(
3092 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); 3090 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1]));
3093 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; 3091 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
3094 request.AddAttribute( 3092 request.AddAttribute(
3095 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); 3093 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority));
3096 Port* port = GetFirstPort(&ch); 3094 Port* port = GetPort(&ch);
3097 ASSERT_NE(nullptr, port); 3095 ASSERT_NE(nullptr, port);
3098 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP, 3096 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP,
3099 &request, kIceUfrag[1], false); 3097 &request, kIceUfrag[1], false);
3100 Connection* conn = GetConnectionTo(&ch, "1.1.1.1", 1); 3098 Connection* conn = GetConnectionTo(&ch, "1.1.1.1", 1);
3101 ASSERT_NE(nullptr, conn); 3099 ASSERT_NE(nullptr, conn);
3102 3100
3103 // Simulate waiting for a second (and change) and verify that no pings were 3101 // Simulate waiting for a second (and change) and verify that no pings were
3104 // sent, since we don't yet have remote ICE parameters. 3102 // sent, since we don't yet have remote ICE parameters.
3105 SIMULATED_WAIT(conn->num_pings_sent() > 0, 1025, clock); 3103 SIMULATED_WAIT(conn->num_pings_sent() > 0, 1025, clock);
3106 EXPECT_EQ(0, conn->num_pings_sent()); 3104 EXPECT_EQ(0, conn->num_pings_sent());
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
3255 // Create a minimal STUN message with prflx priority. 3253 // Create a minimal STUN message with prflx priority.
3256 IceMessage request; 3254 IceMessage request;
3257 request.SetType(STUN_BINDING_REQUEST); 3255 request.SetType(STUN_BINDING_REQUEST);
3258 request.AddAttribute( 3256 request.AddAttribute(
3259 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); 3257 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1]));
3260 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; 3258 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
3261 request.AddAttribute( 3259 request.AddAttribute(
3262 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); 3260 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority));
3263 EXPECT_NE(prflx_priority, remote_priority); 3261 EXPECT_NE(prflx_priority, remote_priority);
3264 3262
3265 Port* port = GetFirstPort(&ch); 3263 Port* port = GetPort(&ch);
3266 // conn1 should be resurrected with original priority. 3264 // conn1 should be resurrected with original priority.
3267 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP, 3265 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP,
3268 &request, kIceUfrag[1], false); 3266 &request, kIceUfrag[1], false);
3269 conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3267 conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3270 ASSERT_TRUE(conn1 != nullptr); 3268 ASSERT_TRUE(conn1 != nullptr);
3271 EXPECT_EQ(conn1->remote_candidate().priority(), remote_priority); 3269 EXPECT_EQ(conn1->remote_candidate().priority(), remote_priority);
3272 3270
3273 // conn3, a real prflx connection, should have prflx priority. 3271 // conn3, a real prflx connection, should have prflx priority.
3274 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 1), PROTO_UDP, 3272 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 1), PROTO_UDP,
3275 &request, kIceUfrag[1], false); 3273 &request, kIceUfrag[1], false);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
3394 ch.SetIceRole(ICEROLE_CONTROLLED); 3392 ch.SetIceRole(ICEROLE_CONTROLLED);
3395 ch.MaybeStartGathering(); 3393 ch.MaybeStartGathering();
3396 // A minimal STUN message with prflx priority. 3394 // A minimal STUN message with prflx priority.
3397 IceMessage request; 3395 IceMessage request;
3398 request.SetType(STUN_BINDING_REQUEST); 3396 request.SetType(STUN_BINDING_REQUEST);
3399 request.AddAttribute( 3397 request.AddAttribute(
3400 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); 3398 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1]));
3401 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; 3399 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
3402 request.AddAttribute( 3400 request.AddAttribute(
3403 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); 3401 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority));
3404 TestUDPPort* port = static_cast<TestUDPPort*>(GetFirstPort(&ch)); 3402 TestUDPPort* port = static_cast<TestUDPPort*>(GetPort(&ch));
3405 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP, 3403 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP,
3406 &request, kIceUfrag[1], false); 3404 &request, kIceUfrag[1], false);
3407 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3405 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3408 ASSERT_TRUE(conn1 != nullptr); 3406 ASSERT_TRUE(conn1 != nullptr);
3409 EXPECT_TRUE(port->sent_binding_response()); 3407 EXPECT_TRUE(port->sent_binding_response());
3410 EXPECT_NE(conn1, ch.selected_connection()); 3408 EXPECT_NE(conn1, ch.selected_connection());
3411 conn1->ReceivedPingResponse(LOW_RTT, "id"); 3409 conn1->ReceivedPingResponse(LOW_RTT, "id");
3412 EXPECT_EQ_WAIT(conn1, ch.selected_connection(), kDefaultTimeout); 3410 EXPECT_EQ_WAIT(conn1, ch.selected_connection(), kDefaultTimeout);
3413 port->set_sent_binding_response(false); 3411 port->set_sent_binding_response(false);
3414 3412
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
3492 // Now another STUN message with an unknown address and use_candidate will 3490 // Now another STUN message with an unknown address and use_candidate will
3493 // nominate the selected connection. 3491 // nominate the selected connection.
3494 IceMessage request; 3492 IceMessage request;
3495 request.SetType(STUN_BINDING_REQUEST); 3493 request.SetType(STUN_BINDING_REQUEST);
3496 request.AddAttribute( 3494 request.AddAttribute(
3497 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); 3495 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1]));
3498 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; 3496 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
3499 request.AddAttribute( 3497 request.AddAttribute(
3500 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); 3498 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority));
3501 request.AddAttribute(new StunByteStringAttribute(STUN_ATTR_USE_CANDIDATE)); 3499 request.AddAttribute(new StunByteStringAttribute(STUN_ATTR_USE_CANDIDATE));
3502 Port* port = GetFirstPort(&ch); 3500 Port* port = GetPort(&ch);
3503 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), PROTO_UDP, 3501 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), PROTO_UDP,
3504 &request, kIceUfrag[1], false); 3502 &request, kIceUfrag[1], false);
3505 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); 3503 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
3506 ASSERT_TRUE(conn3 != nullptr); 3504 ASSERT_TRUE(conn3 != nullptr);
3507 EXPECT_EQ(conn2, ch.selected_connection()); // Not writable yet. 3505 EXPECT_EQ(conn2, ch.selected_connection()); // Not writable yet.
3508 conn3->ReceivedPingResponse(LOW_RTT, "id"); // Become writable. 3506 conn3->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
3509 EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout); 3507 EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout);
3510 3508
3511 // Now another data packet will not switch the selected connection because the 3509 // Now another data packet will not switch the selected connection because the
3512 // selected connection was nominated by the controlling side. 3510 // selected connection was nominated by the controlling side.
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
3867 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState()); 3865 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState());
3868 3866
3869 // When |conn1| comes back again, |conn2| will be pruned again. 3867 // When |conn1| comes back again, |conn2| will be pruned again.
3870 conn1->ReceivedPingResponse(LOW_RTT, "id"); 3868 conn1->ReceivedPingResponse(LOW_RTT, "id");
3871 EXPECT_EQ_SIMULATED_WAIT(conn1, ch.selected_connection(), kDefaultTimeout, 3869 EXPECT_EQ_SIMULATED_WAIT(conn1, ch.selected_connection(), kDefaultTimeout,
3872 clock); 3870 clock);
3873 EXPECT_TRUE_SIMULATED_WAIT(!conn2->active(), kDefaultTimeout, clock); 3871 EXPECT_TRUE_SIMULATED_WAIT(!conn2->active(), kDefaultTimeout, clock);
3874 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); 3872 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState());
3875 } 3873 }
3876 3874
3877 TEST_F(P2PTransportChannelPingTest, TestPruneConnectionsByNetworkName) {
3878 std::string ipv4_addr("1.1.1.1");
3879 std::string ipv6_addr("2400:1:2:3:4:5:6:7");
3880 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3881 pa.set_ipv6_enabled(true);
3882 pa.set_flags(PORTALLOCATOR_ENABLE_IPV6);
3883 P2PTransportChannel ch("test channel", 1, &pa);
3884 PrepareChannel(&ch);
3885 ch.MaybeStartGathering();
3886 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, ipv4_addr, 1, 100));
3887 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, ipv6_addr, 1, 100));
3888 Connection* conn1 = WaitForConnectionTo(&ch, ipv4_addr, 1);
3889 ASSERT_TRUE(conn1 != nullptr);
3890 Connection* conn2 = WaitForConnectionTo(&ch, ipv6_addr, 1);
3891 ASSERT_TRUE(conn2 != nullptr);
3892 conn1->ReceivedPingResponse(LOW_RTT, "id");
3893 EXPECT_EQ_WAIT(conn1, ch.selected_connection(), kDefaultTimeout);
3894 conn2->ReceivedPingResponse(LOW_RTT, "id");
3895 // IPv6 connection has higher priority.
3896 EXPECT_EQ_WAIT(conn2, ch.selected_connection(), kDefaultTimeout);
3897 // Since conn1 and conn2 are on networks with the same network name,
3898 // conn1 will be pruned when conn2 becomes writable and receiving.
3899 EXPECT_FALSE(conn1->writable());
3900 }
3901
3902 // Test that if all connections in a channel has timed out on writing, they 3875 // Test that if all connections in a channel has timed out on writing, they
3903 // will all be deleted. We use Prune to simulate write_time_out. 3876 // will all be deleted. We use Prune to simulate write_time_out.
3904 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { 3877 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) {
3905 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3878 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3906 P2PTransportChannel ch("test channel", 1, &pa); 3879 P2PTransportChannel ch("test channel", 1, &pa);
3907 PrepareChannel(&ch); 3880 PrepareChannel(&ch);
3908 ch.MaybeStartGathering(); 3881 ch.MaybeStartGathering();
3909 // Have one connection only but later becomes write-time-out. 3882 // Have one connection only but later becomes write-time-out.
3910 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 3883 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
3911 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3884 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
4026 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3999 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
4027 ASSERT_TRUE(conn != nullptr); 4000 ASSERT_TRUE(conn != nullptr);
4028 4001
4029 // Simulate 2 minutes going by. This should be enough time for the port to 4002 // Simulate 2 minutes going by. This should be enough time for the port to
4030 // time out. 4003 // time out.
4031 for (int second = 0; second < 120; ++second) { 4004 for (int second = 0; second < 120; ++second) {
4032 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1)); 4005 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
4033 } 4006 }
4034 EXPECT_EQ(nullptr, GetConnectionTo(&ch, "1.1.1.1", 1)); 4007 EXPECT_EQ(nullptr, GetConnectionTo(&ch, "1.1.1.1", 1));
4035 // Port will not be removed because it is not pruned yet. 4008 // Port will not be removed because it is not pruned yet.
4036 PortInterface* port = GetFirstPort(&ch); 4009 PortInterface* port = GetPort(&ch);
4037 ASSERT_NE(nullptr, port); 4010 ASSERT_NE(nullptr, port);
4038 4011
4039 // If the session prunes all ports, the port will be destroyed. 4012 // If the session prunes all ports, the port will be destroyed.
4040 ch.allocator_session()->PruneAllPorts(); 4013 ch.allocator_session()->PruneAllPorts();
4041 EXPECT_EQ_SIMULATED_WAIT(nullptr, GetFirstPort(&ch), 1, fake_clock); 4014 EXPECT_EQ_SIMULATED_WAIT(nullptr, GetPort(&ch), 1, fake_clock);
4042 EXPECT_EQ_SIMULATED_WAIT(nullptr, GetPrunedPort(&ch), 1, fake_clock); 4015 EXPECT_EQ_SIMULATED_WAIT(nullptr, GetPrunedPort(&ch), 1, fake_clock);
4043 } 4016 }
4044 4017
4045 class P2PTransportChannelMostLikelyToWorkFirstTest 4018 class P2PTransportChannelMostLikelyToWorkFirstTest
4046 : public P2PTransportChannelPingTest { 4019 : public P2PTransportChannelPingTest {
4047 public: 4020 public:
4048 P2PTransportChannelMostLikelyToWorkFirstTest() 4021 P2PTransportChannelMostLikelyToWorkFirstTest()
4049 : turn_server_(rtc::Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr) { 4022 : turn_server_(rtc::Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr) {
4050 network_manager_.AddInterface(kPublicAddrs[0]); 4023 network_manager_.AddInterface(kPublicAddrs[0]);
4051 allocator_.reset( 4024 allocator_.reset(
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
4243 4216
4244 // TCP Relay/Relay is the next. 4217 // TCP Relay/Relay is the next.
4245 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, 4218 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE,
4246 TCP_PROTOCOL_NAME); 4219 TCP_PROTOCOL_NAME);
4247 4220
4248 // Finally, Local/Relay will be pinged. 4221 // Finally, Local/Relay will be pinged.
4249 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); 4222 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE);
4250 } 4223 }
4251 4224
4252 } // namespace cricket { 4225 } // namespace cricket {
OLDNEW
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698