diff --git a/p2p/base/fake_ice_transport.h b/p2p/base/fake_ice_transport.h index 8bcd723aeb..45fe6f352c 100644 --- a/p2p/base/fake_ice_transport.h +++ b/p2p/base/fake_ice_transport.h @@ -191,6 +191,8 @@ class FakeIceTransport : public IceTransportInternal { remote_candidates_.erase(it); } + void RemoveAllRemoteCandidates() override { remote_candidates_.clear(); } + bool GetStats(ConnectionInfos* candidate_pair_stats_list, CandidateStatsList* candidate_stats_list) override { CandidateStats candidate_stats; @@ -204,6 +206,8 @@ class FakeIceTransport : public IceTransportInternal { absl::optional GetRttEstimate() override { return absl::nullopt; } + const Connection* selected_connection() const override { return nullptr; } + // Fake PacketTransportInternal implementation. bool writable() const override { return writable_; } bool receiving() const override { return receiving_; } diff --git a/p2p/base/ice_transport_internal.h b/p2p/base/ice_transport_internal.h index f3da45a787..8f2167316c 100644 --- a/p2p/base/ice_transport_internal.h +++ b/p2p/base/ice_transport_internal.h @@ -242,6 +242,8 @@ class RTC_EXPORT IceTransportInternal : public rtc::PacketTransportInternal { virtual void RemoveRemoteCandidate(const Candidate& candidate) = 0; + virtual void RemoveAllRemoteCandidates() = 0; + virtual IceGatheringState gathering_state() const = 0; // Returns the current stats for this connection. @@ -252,6 +254,8 @@ class RTC_EXPORT IceTransportInternal : public rtc::PacketTransportInternal { // absl::optional if there is none. virtual absl::optional GetRttEstimate() = 0; + virtual const Connection* selected_connection() const = 0; + sigslot::signal1 SignalGatheringState; // Handles sending and receiving of candidates. diff --git a/p2p/base/mock_ice_transport.h b/p2p/base/mock_ice_transport.h index e0ad1e2180..77716b2b67 100644 --- a/p2p/base/mock_ice_transport.h +++ b/p2p/base/mock_ice_transport.h @@ -62,9 +62,11 @@ class MockIceTransport : public IceTransportInternal { void SetRemoteIceMode(IceMode mode) override {} void SetIceConfig(const IceConfig& config) override {} absl::optional GetRttEstimate() override { return absl::nullopt; } + const Connection* selected_connection() const override { return nullptr; } void MaybeStartGathering() override {} void AddRemoteCandidate(const Candidate& candidate) override {} void RemoveRemoteCandidate(const Candidate& candidate) override {} + void RemoveAllRemoteCandidates() override {} IceGatheringState gathering_state() const override { return IceGatheringState::kIceGatheringComplete; } diff --git a/p2p/base/p2p_transport_channel.cc b/p2p/base/p2p_transport_channel.cc index b12bd0cccc..212ed30103 100644 --- a/p2p/base/p2p_transport_channel.cc +++ b/p2p/base/p2p_transport_channel.cc @@ -714,6 +714,10 @@ RTCError P2PTransportChannel::ValidateIceConfig(const IceConfig& config) { return RTCError::OK(); } +const Connection* P2PTransportChannel::selected_connection() const { + return selected_connection_; +} + int P2PTransportChannel::check_receiving_interval() const { return std::max(MIN_CHECK_RECEIVING_INTERVAL, config_.receiving_timeout_or_default() / 10); @@ -1180,6 +1184,10 @@ void P2PTransportChannel::RemoveRemoteCandidate( } } +void P2PTransportChannel::RemoveAllRemoteCandidates() { + remote_candidates_.clear(); +} + // Creates connections from all of the ports that we care about to the given // remote candidate. The return value is true if we created a connection from // the origin port. diff --git a/p2p/base/p2p_transport_channel.h b/p2p/base/p2p_transport_channel.h index f9b4c7dc93..467ef258b5 100644 --- a/p2p/base/p2p_transport_channel.h +++ b/p2p/base/p2p_transport_channel.h @@ -112,6 +112,7 @@ class RTC_EXPORT P2PTransportChannel : public IceTransportInternal { void ResolveHostnameCandidate(const Candidate& candidate); void AddRemoteCandidate(const Candidate& candidate) override; void RemoveRemoteCandidate(const Candidate& candidate) override; + void RemoveAllRemoteCandidates() override; // Sets the parameters in IceConfig. We do not set them blindly. Instead, we // only update the parameter if it is considered set in |config|. For example, // a negative value of receiving_timeout will be considered "not set" and we @@ -132,12 +133,12 @@ class RTC_EXPORT P2PTransportChannel : public IceTransportInternal { bool GetStats(std::vector* candidate_pair_stats_list, std::vector* candidate_stats_list) override; absl::optional GetRttEstimate() override; + const Connection* selected_connection() const override; // TODO(honghaiz): Remove this method once the reference of it in // Chromoting is removed. const Connection* best_connection() const { return selected_connection_; } - const Connection* selected_connection() const { return selected_connection_; } void set_incoming_only(bool value) { incoming_only_ = value; } // Note: These are only for testing purpose. diff --git a/pc/ice_transport_unittest.cc b/pc/ice_transport_unittest.cc new file mode 100644 index 0000000000..c299b2c115 --- /dev/null +++ b/pc/ice_transport_unittest.cc @@ -0,0 +1,26 @@ +/* + * Copyright 2019 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "pc/ice_transport.h" +#include "p2p/base/fake_port_allocator.h" + +#include "test/gtest.h" + +namespace webrtc { + +class IceTransportTest : public testing::Test {}; + +TEST_F(IceTransportTest, CreateStandaloneIceTransport) { + auto port_allocator = new cricket::FakePortAllocator(nullptr, nullptr); + auto transport = CreateIceTransport(port_allocator); + ASSERT_TRUE(transport->internal()); +} + +} // namespace webrtc