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

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

Issue 2053043003: Update ICE role on all ports, not just ones used for new connections. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing issue with call to `erase`. Adding test for port destruction. Created 4 years, 6 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
11 #include <algorithm> 11 #include <algorithm>
12 #include <memory> 12 #include <memory>
13 13
14 #include "webrtc/p2p/base/fakeportallocator.h" 14 #include "webrtc/p2p/base/fakeportallocator.h"
15 #include "webrtc/p2p/base/p2ptransportchannel.h" 15 #include "webrtc/p2p/base/p2ptransportchannel.h"
16 #include "webrtc/p2p/base/testrelayserver.h" 16 #include "webrtc/p2p/base/testrelayserver.h"
17 #include "webrtc/p2p/base/teststunserver.h" 17 #include "webrtc/p2p/base/teststunserver.h"
18 #include "webrtc/p2p/base/testturnserver.h" 18 #include "webrtc/p2p/base/testturnserver.h"
19 #include "webrtc/p2p/client/basicportallocator.h" 19 #include "webrtc/p2p/client/basicportallocator.h"
20 #include "webrtc/base/dscp.h" 20 #include "webrtc/base/dscp.h"
21 #include "webrtc/base/fakeclock.h"
21 #include "webrtc/base/fakenetwork.h" 22 #include "webrtc/base/fakenetwork.h"
22 #include "webrtc/base/firewallsocketserver.h" 23 #include "webrtc/base/firewallsocketserver.h"
23 #include "webrtc/base/gunit.h" 24 #include "webrtc/base/gunit.h"
24 #include "webrtc/base/helpers.h" 25 #include "webrtc/base/helpers.h"
25 #include "webrtc/base/logging.h" 26 #include "webrtc/base/logging.h"
26 #include "webrtc/base/natserver.h" 27 #include "webrtc/base/natserver.h"
27 #include "webrtc/base/natsocketfactory.h" 28 #include "webrtc/base/natsocketfactory.h"
28 #include "webrtc/base/physicalsocketserver.h" 29 #include "webrtc/base/physicalsocketserver.h"
29 #include "webrtc/base/proxyserver.h" 30 #include "webrtc/base/proxyserver.h"
30 #include "webrtc/base/socketaddress.h" 31 #include "webrtc/base/socketaddress.h"
(...skipping 2648 matching lines...) Expand 10 before | Expand all | Expand 10 after
2679 2680
2680 // But if a new connection created from the new session becomes writable, 2681 // But if a new connection created from the new session becomes writable,
2681 // it will stop the current session. 2682 // it will stop the current session.
2682 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 100)); 2683 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 100));
2683 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2684 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2684 ASSERT_TRUE(conn2 != nullptr); 2685 ASSERT_TRUE(conn2 != nullptr);
2685 conn2->ReceivedPingResponse(); // Becomes writable and receiving 2686 conn2->ReceivedPingResponse(); // Becomes writable and receiving
2686 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); 2687 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts());
2687 } 2688 }
2688 2689
2690 // Test that the ICE role is updated even on ports with inactive networks when
2691 // doing continual gathering. These ports may still have connections that need
2692 // a correct role, in case the network becomes active before the connection is
2693 // destroyed.
2694 TEST_F(P2PTransportChannelPingTest,
2695 TestIceRoleUpdatedOnPortAfterSignalNetworkInactive) {
2696 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2697 cricket::P2PTransportChannel ch(
2698 "test channel", cricket::ICE_CANDIDATE_COMPONENT_DEFAULT, &pa);
2699 // Starts with ICEROLE_CONTROLLING.
2700 PrepareChannel(&ch);
2701 cricket::IceConfig config = CreateIceConfig(1000, true);
2702 ch.SetIceConfig(config);
2703 ch.Connect();
2704 ch.MaybeStartGathering();
2705 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
2706
2707 cricket::Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2708 ASSERT_TRUE(conn != nullptr);
2709
2710 // Make the fake port signal that its network is inactive, then change the
2711 // ICE role and expect it to be updated.
2712 conn->port()->SignalNetworkInactive(conn->port());
2713 ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
2714 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, conn->port()->GetIceRole());
2715 }
2716
2717 // Test that the ICE role is updated even on ports with inactive networks.
2718 // These ports may still have connections that need a correct role, for the
2719 // pings sent by those connections until they're replaced by newer-generation
2720 // connections.
2721 TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnPortAfterIceRestart) {
2722 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2723 cricket::P2PTransportChannel ch(
2724 "test channel", cricket::ICE_CANDIDATE_COMPONENT_DEFAULT, &pa);
2725 // Starts with ICEROLE_CONTROLLING.
2726 PrepareChannel(&ch);
2727 ch.Connect();
2728 ch.MaybeStartGathering();
2729 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
2730
2731 cricket::Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2732 ASSERT_TRUE(conn != nullptr);
2733
2734 // Do an ICE restart, change the role, and expect the old port to have its
2735 // role updated.
2736 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]);
2737 ch.MaybeStartGathering();
2738 ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
2739 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, conn->port()->GetIceRole());
2740 }
2741
2742 // Test that after some amount of time without receiving data, the connection
2743 // and port are destroyed.
2744 TEST_F(P2PTransportChannelPingTest, TestPortDestroyedAfterTimeout) {
2745 rtc::ScopedFakeClock fake_clock;
2746
2747 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2748 cricket::P2PTransportChannel ch(
2749 "test channel", cricket::ICE_CANDIDATE_COMPONENT_DEFAULT, &pa);
2750 PrepareChannel(&ch);
2751 // Only a controlled channel should expect its ports to be destroyed.
2752 ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
2753 ch.Connect();
2754 ch.MaybeStartGathering();
2755 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
2756
2757 cricket::Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2758 ASSERT_TRUE(conn != nullptr);
2759
2760 // Simulate 2 minutes going by. This should be enough time for the port to
2761 // time out.
2762 for (int second = 0; second < 120; ++second) {
2763 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
2764 }
2765 EXPECT_EQ(nullptr, GetConnectionTo(&ch, "1.1.1.1", 1));
2766 EXPECT_EQ(nullptr, GetPort(&ch));
2767 }
2768
2689 class P2PTransportChannelMostLikelyToWorkFirstTest 2769 class P2PTransportChannelMostLikelyToWorkFirstTest
2690 : public P2PTransportChannelPingTest { 2770 : public P2PTransportChannelPingTest {
2691 public: 2771 public:
2692 P2PTransportChannelMostLikelyToWorkFirstTest() 2772 P2PTransportChannelMostLikelyToWorkFirstTest()
2693 : turn_server_(rtc::Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr) { 2773 : turn_server_(rtc::Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr) {
2694 network_manager_.AddInterface(kPublicAddrs[0]); 2774 network_manager_.AddInterface(kPublicAddrs[0]);
2695 allocator_.reset(new cricket::BasicPortAllocator( 2775 allocator_.reset(new cricket::BasicPortAllocator(
2696 &network_manager_, ServerAddresses(), rtc::SocketAddress(), 2776 &network_manager_, ServerAddresses(), rtc::SocketAddress(),
2697 rtc::SocketAddress(), rtc::SocketAddress())); 2777 rtc::SocketAddress(), rtc::SocketAddress()));
2698 allocator_->set_flags(allocator_->flags() | 2778 allocator_->set_flags(allocator_->flags() |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
2916 2996
2917 // TCP Relay/Relay is the next. 2997 // TCP Relay/Relay is the next.
2918 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, 2998 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
2919 cricket::RELAY_PORT_TYPE, 2999 cricket::RELAY_PORT_TYPE,
2920 cricket::TCP_PROTOCOL_NAME); 3000 cricket::TCP_PROTOCOL_NAME);
2921 3001
2922 // Finally, Local/Relay will be pinged. 3002 // Finally, Local/Relay will be pinged.
2923 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, 3003 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE,
2924 cricket::RELAY_PORT_TYPE); 3004 cricket::RELAY_PORT_TYPE);
2925 } 3005 }
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