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

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

Issue 2171183002: Remove ports that are not used by any channel after timeout (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: . Created 4 years, 4 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') | webrtc/p2p/base/port.h » ('j') | 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 2479 matching lines...) Expand 10 before | Expand all | Expand 10 after
2490 return GetConnectionTo(ch, ip, port_num); 2490 return GetConnectionTo(ch, ip, port_num);
2491 } 2491 }
2492 2492
2493 Port* GetPort(P2PTransportChannel* ch) { 2493 Port* GetPort(P2PTransportChannel* ch) {
2494 if (ch->ports().empty()) { 2494 if (ch->ports().empty()) {
2495 return nullptr; 2495 return nullptr;
2496 } 2496 }
2497 return static_cast<Port*>(ch->ports()[0]); 2497 return static_cast<Port*>(ch->ports()[0]);
2498 } 2498 }
2499 2499
2500 Port* GetPrunedPort(P2PTransportChannel* ch) {
2501 if (ch->pruned_ports().empty()) {
2502 return nullptr;
2503 }
2504 return static_cast<Port*>(ch->pruned_ports()[0]);
2505 }
2506
2500 Connection* GetConnectionTo(P2PTransportChannel* ch, 2507 Connection* GetConnectionTo(P2PTransportChannel* ch,
2501 const std::string& ip, 2508 const std::string& ip,
2502 int port_num) { 2509 int port_num) {
2503 Port* port = GetPort(ch); 2510 Port* port = GetPort(ch);
2504 if (!port) { 2511 if (!port) {
2505 return nullptr; 2512 return nullptr;
2506 } 2513 }
2507 return port->GetConnection(rtc::SocketAddress(ip, port_num)); 2514 return port->GetConnection(rtc::SocketAddress(ip, port_num));
2508 } 2515 }
2509 2516
(...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after
3572 3579
3573 // Do an ICE restart, change the role, and expect the old port to have its 3580 // Do an ICE restart, change the role, and expect the old port to have its
3574 // role updated. 3581 // role updated.
3575 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); 3582 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]);
3576 ch.MaybeStartGathering(); 3583 ch.MaybeStartGathering();
3577 ch.SetIceRole(ICEROLE_CONTROLLED); 3584 ch.SetIceRole(ICEROLE_CONTROLLED);
3578 EXPECT_EQ(ICEROLE_CONTROLLED, conn->port()->GetIceRole()); 3585 EXPECT_EQ(ICEROLE_CONTROLLED, conn->port()->GetIceRole());
3579 } 3586 }
3580 3587
3581 // Test that after some amount of time without receiving data, the connection 3588 // Test that after some amount of time without receiving data, the connection
3582 // and port are destroyed. 3589 // will be destroyed. The port will only be destroyed after it is marked as
3583 TEST_F(P2PTransportChannelPingTest, TestPortDestroyedAfterTimeout) { 3590 // "pruned."
3591 TEST_F(P2PTransportChannelPingTest, TestPortDestroyedAfterTimeoutAndPruned) {
3584 rtc::ScopedFakeClock fake_clock; 3592 rtc::ScopedFakeClock fake_clock;
3585 3593
3586 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3594 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3587 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa); 3595 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa);
3588 PrepareChannel(&ch); 3596 PrepareChannel(&ch);
3589 // Only a controlled channel should expect its ports to be destroyed.
3590 ch.SetIceRole(ICEROLE_CONTROLLED); 3597 ch.SetIceRole(ICEROLE_CONTROLLED);
3591 ch.MaybeStartGathering(); 3598 ch.MaybeStartGathering();
3592 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 3599 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
3593 3600
3594 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3601 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3595 ASSERT_TRUE(conn != nullptr); 3602 ASSERT_TRUE(conn != nullptr);
3596 3603
3597 // Simulate 2 minutes going by. This should be enough time for the port to 3604 // Simulate 2 minutes going by. This should be enough time for the port to
3598 // time out. 3605 // time out.
3599 for (int second = 0; second < 120; ++second) { 3606 for (int second = 0; second < 120; ++second) {
3600 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1)); 3607 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
3601 } 3608 }
3602 EXPECT_EQ(nullptr, GetConnectionTo(&ch, "1.1.1.1", 1)); 3609 EXPECT_EQ(nullptr, GetConnectionTo(&ch, "1.1.1.1", 1));
3603 EXPECT_EQ(nullptr, GetPort(&ch)); 3610 // Port will not be removed because it is not pruned yet.
3611 PortInterface* port = GetPort(&ch);
3612 ASSERT_NE(nullptr, port);
3613
3614 // If the session prunes all ports, the port will be destroyed.
3615 ch.allocator_session()->PruneAllPorts();
3616 EXPECT_EQ_SIMULATED_WAIT(nullptr, GetPort(&ch), 1, fake_clock);
3617 EXPECT_EQ_SIMULATED_WAIT(nullptr, GetPrunedPort(&ch), 1, fake_clock);
3604 } 3618 }
3605 3619
3606 class P2PTransportChannelMostLikelyToWorkFirstTest 3620 class P2PTransportChannelMostLikelyToWorkFirstTest
3607 : public P2PTransportChannelPingTest { 3621 : public P2PTransportChannelPingTest {
3608 public: 3622 public:
3609 P2PTransportChannelMostLikelyToWorkFirstTest() 3623 P2PTransportChannelMostLikelyToWorkFirstTest()
3610 : turn_server_(rtc::Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr) { 3624 : turn_server_(rtc::Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr) {
3611 network_manager_.AddInterface(kPublicAddrs[0]); 3625 network_manager_.AddInterface(kPublicAddrs[0]);
3612 allocator_.reset(new BasicPortAllocator( 3626 allocator_.reset(new BasicPortAllocator(
3613 &network_manager_, ServerAddresses(), rtc::SocketAddress(), 3627 &network_manager_, ServerAddresses(), rtc::SocketAddress(),
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
3808 3822
3809 // TCP Relay/Relay is the next. 3823 // TCP Relay/Relay is the next.
3810 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, 3824 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE,
3811 TCP_PROTOCOL_NAME); 3825 TCP_PROTOCOL_NAME);
3812 3826
3813 // Finally, Local/Relay will be pinged. 3827 // Finally, Local/Relay will be pinged.
3814 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); 3828 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE);
3815 } 3829 }
3816 3830
3817 } // namespace cricket { 3831 } // namespace cricket {
OLDNEW
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.cc ('k') | webrtc/p2p/base/port.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698