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 2479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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* GetRemovedPort(P2PTransportChannel* ch) { | |
2501 if (ch->removed_ports().empty()) { | |
2502 return nullptr; | |
2503 } | |
2504 return static_cast<Port*>(ch->removed_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 Loading... | |
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 removed |
3583 TEST_F(P2PTransportChannelPingTest, TestPortDestroyedAfterTimeout) { | 3590 // from usage. |
3591 TEST_F(P2PTransportChannelPingTest, TestPortDestroyedAfterTimeoutAndRemoved) { | |
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. | 3597 // Only a controlled channel should expect its ports to be destroyed. |
3590 ch.SetIceRole(ICEROLE_CONTROLLED); | 3598 ch.SetIceRole(ICEROLE_CONTROLLED); |
3591 ch.MaybeStartGathering(); | 3599 ch.MaybeStartGathering(); |
3592 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); | 3600 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); |
3593 | 3601 |
3594 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 3602 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
3595 ASSERT_TRUE(conn != nullptr); | 3603 ASSERT_TRUE(conn != nullptr); |
3596 | 3604 |
3597 // Simulate 2 minutes going by. This should be enough time for the port to | 3605 // Simulate 2 minutes going by. This should be enough time for the port to |
3598 // time out. | 3606 // time out. |
3599 for (int second = 0; second < 120; ++second) { | 3607 for (int second = 0; second < 120; ++second) { |
3600 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1)); | 3608 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1)); |
3601 } | 3609 } |
3602 EXPECT_EQ(nullptr, GetConnectionTo(&ch, "1.1.1.1", 1)); | 3610 EXPECT_EQ(nullptr, GetConnectionTo(&ch, "1.1.1.1", 1)); |
3603 EXPECT_EQ(nullptr, GetPort(&ch)); | 3611 // Port will not be removed because it is still used by the channel. |
3612 PortInterface* port = GetPort(&ch); | |
3613 ASSERT_NE(nullptr, port); | |
3614 | |
3615 // If the session signals removing the port, the port will be destroyed. | |
3616 std::vector<PortInterface*> ports_to_remove(1, port); | |
3617 ch.allocator_session()->SignalPortsRemoved(ch.allocator_session(), | |
3618 ports_to_remove); | |
3619 EXPECT_EQ_SIMULATED_WAIT(nullptr, GetPort(&ch), 1, fake_clock); | |
3620 EXPECT_EQ_SIMULATED_WAIT(nullptr, GetRemovedPort(&ch), 1, fake_clock); | |
pthatcher1
2016/07/27 18:33:15
If we move the logic to be between the session and
honghaiz3
2016/07/28 01:22:49
This is an extra test here. There are tests in Por
| |
3604 } | 3621 } |
3605 | 3622 |
3606 class P2PTransportChannelMostLikelyToWorkFirstTest | 3623 class P2PTransportChannelMostLikelyToWorkFirstTest |
3607 : public P2PTransportChannelPingTest { | 3624 : public P2PTransportChannelPingTest { |
3608 public: | 3625 public: |
3609 P2PTransportChannelMostLikelyToWorkFirstTest() | 3626 P2PTransportChannelMostLikelyToWorkFirstTest() |
3610 : turn_server_(rtc::Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr) { | 3627 : turn_server_(rtc::Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr) { |
3611 network_manager_.AddInterface(kPublicAddrs[0]); | 3628 network_manager_.AddInterface(kPublicAddrs[0]); |
3612 allocator_.reset(new BasicPortAllocator( | 3629 allocator_.reset(new BasicPortAllocator( |
3613 &network_manager_, ServerAddresses(), rtc::SocketAddress(), | 3630 &network_manager_, ServerAddresses(), rtc::SocketAddress(), |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3808 | 3825 |
3809 // TCP Relay/Relay is the next. | 3826 // TCP Relay/Relay is the next. |
3810 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, | 3827 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, |
3811 TCP_PROTOCOL_NAME); | 3828 TCP_PROTOCOL_NAME); |
3812 | 3829 |
3813 // Finally, Local/Relay will be pinged. | 3830 // Finally, Local/Relay will be pinged. |
3814 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); | 3831 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); |
3815 } | 3832 } |
3816 | 3833 |
3817 } // namespace cricket { | 3834 } // namespace cricket { |
OLD | NEW |