diff --git a/webrtc/BUILD.gn b/webrtc/BUILD.gn index 6a02fbcdd6..36d9f9e749 100644 --- a/webrtc/BUILD.gn +++ b/webrtc/BUILD.gn @@ -365,7 +365,6 @@ if (rtc_include_tests) { rtc_test("rtc_unittests") { testonly = true - deps = [ "base:rtc_analytics_unittests", "base:rtc_base_approved_unittests", diff --git a/webrtc/p2p/base/dtlstransportchannel.cc b/webrtc/p2p/base/dtlstransportchannel.cc index 912b90e80b..2b781d17fa 100644 --- a/webrtc/p2p/base/dtlstransportchannel.cc +++ b/webrtc/p2p/base/dtlstransportchannel.cc @@ -50,11 +50,10 @@ static bool IsRtpPacket(const char* data, size_t len) { return (len >= kMinRtpPacketLen && (u[0] & 0xC0) == 0x80); } -StreamInterfaceChannel::StreamInterfaceChannel(TransportChannel* channel) +StreamInterfaceChannel::StreamInterfaceChannel(IceTransportInternal* channel) : channel_(channel), state_(rtc::SS_OPEN), - packets_(kMaxPendingPackets, kMaxDtlsPacketLen) { -} + packets_(kMaxPendingPackets, kMaxDtlsPacketLen) {} rtc::StreamResult StreamInterfaceChannel::Read(void* buffer, size_t buffer_len, @@ -103,7 +102,7 @@ void StreamInterfaceChannel::Close() { } DtlsTransportChannelWrapper::DtlsTransportChannelWrapper( - TransportChannelImpl* channel) + IceTransportInternal* channel) : TransportChannelImpl(channel->transport_name(), channel->component()), network_thread_(rtc::Thread::Current()), channel_(channel), @@ -684,39 +683,39 @@ bool DtlsTransportChannelWrapper::HandleDtlsPacket(const char* data, } void DtlsTransportChannelWrapper::OnGatheringState( - TransportChannelImpl* channel) { + IceTransportInternal* channel) { RTC_DCHECK(channel == channel_); SignalGatheringState(this); } void DtlsTransportChannelWrapper::OnCandidateGathered( - TransportChannelImpl* channel, + IceTransportInternal* channel, const Candidate& c) { RTC_DCHECK(channel == channel_); SignalCandidateGathered(this, c); } void DtlsTransportChannelWrapper::OnCandidatesRemoved( - TransportChannelImpl* channel, + IceTransportInternal* channel, const Candidates& candidates) { RTC_DCHECK(channel == channel_); SignalCandidatesRemoved(this, candidates); } void DtlsTransportChannelWrapper::OnRoleConflict( - TransportChannelImpl* channel) { + IceTransportInternal* channel) { RTC_DCHECK(channel == channel_); SignalRoleConflict(this); } -void DtlsTransportChannelWrapper::OnRouteChange( - TransportChannel* channel, const Candidate& candidate) { +void DtlsTransportChannelWrapper::OnRouteChange(IceTransportInternal* channel, + const Candidate& candidate) { RTC_DCHECK(channel == channel_); SignalRouteChange(this, candidate); } void DtlsTransportChannelWrapper::OnSelectedCandidatePairChanged( - TransportChannel* channel, + IceTransportInternal* channel, CandidatePairInterface* selected_candidate_pair, int last_sent_packet_id, bool ready_to_send) { @@ -726,7 +725,7 @@ void DtlsTransportChannelWrapper::OnSelectedCandidatePairChanged( } void DtlsTransportChannelWrapper::OnChannelStateChanged( - TransportChannelImpl* channel) { + IceTransportInternal* channel) { RTC_DCHECK(channel == channel_); SignalStateChanged(this); } diff --git a/webrtc/p2p/base/dtlstransportchannel.h b/webrtc/p2p/base/dtlstransportchannel.h index 5850813fcd..a8d5d5bcfa 100644 --- a/webrtc/p2p/base/dtlstransportchannel.h +++ b/webrtc/p2p/base/dtlstransportchannel.h @@ -15,12 +15,13 @@ #include #include -#include "webrtc/p2p/base/transportchannelimpl.h" #include "webrtc/base/buffer.h" #include "webrtc/base/bufferqueue.h" #include "webrtc/base/constructormagic.h" #include "webrtc/base/sslstreamadapter.h" #include "webrtc/base/stream.h" +#include "webrtc/p2p/base/icetransportinternal.h" +#include "webrtc/p2p/base/transportchannelimpl.h" namespace rtc { class PacketTransportInterface; @@ -28,11 +29,11 @@ class PacketTransportInterface; namespace cricket { -// A bridge between a packet-oriented/channel-type interface on +// A bridge between a packet-oriented/transport-type interface on // the bottom and a StreamInterface on the top. class StreamInterfaceChannel : public rtc::StreamInterface { public: - explicit StreamInterfaceChannel(TransportChannel* channel); + explicit StreamInterfaceChannel(IceTransportInternal* channel); // Push in a packet; this gets pulled out from Read(). bool OnPacketReceived(const char* data, size_t size); @@ -50,7 +51,7 @@ class StreamInterfaceChannel : public rtc::StreamInterface { int* error) override; private: - TransportChannel* channel_; // owned by DtlsTransportChannelWrapper + IceTransportInternal* channel_; // owned by DtlsTransportChannelWrapper rtc::StreamState state_; rtc::BufferQueue packets_; @@ -88,7 +89,7 @@ class DtlsTransportChannelWrapper : public TransportChannelImpl { public: // The parameters here are: // channel -- the TransportChannel we are wrapping - explicit DtlsTransportChannelWrapper(TransportChannelImpl* channel); + explicit DtlsTransportChannelWrapper(IceTransportInternal* channel); ~DtlsTransportChannelWrapper() override; void SetIceRole(IceRole role) override { channel_->SetIceRole(role); } @@ -161,9 +162,7 @@ class DtlsTransportChannelWrapper : public TransportChannelImpl { } // TransportChannelImpl calls. - TransportChannelState GetState() const override { - return channel_->GetState(); - } + IceTransportState GetState() const override { return channel_->GetState(); } void SetIceTiebreaker(uint64_t tiebreaker) override { channel_->SetIceTiebreaker(tiebreaker); } @@ -199,7 +198,7 @@ class DtlsTransportChannelWrapper : public TransportChannelImpl { } // Needed by DtlsTransport. - TransportChannelImpl* channel() { return channel_; } + IceTransportInternal* channel() { return channel_; } // For informational purposes. Tells if the DTLS handshake has finished. // This may be true even if writable() is false, if the remote fingerprint @@ -221,23 +220,23 @@ class DtlsTransportChannelWrapper : public TransportChannelImpl { bool SetupDtls(); void MaybeStartDtls(); bool HandleDtlsPacket(const char* data, size_t size); - void OnGatheringState(TransportChannelImpl* channel); - void OnCandidateGathered(TransportChannelImpl* channel, const Candidate& c); - void OnCandidatesRemoved(TransportChannelImpl* channel, + void OnGatheringState(IceTransportInternal* channel); + void OnCandidateGathered(IceTransportInternal* channel, const Candidate& c); + void OnCandidatesRemoved(IceTransportInternal* channel, const Candidates& candidates); - void OnRoleConflict(TransportChannelImpl* channel); - void OnRouteChange(TransportChannel* channel, const Candidate& candidate); + void OnRoleConflict(IceTransportInternal* channel); + void OnRouteChange(IceTransportInternal* channel, const Candidate& candidate); void OnSelectedCandidatePairChanged( - TransportChannel* channel, + IceTransportInternal* channel, CandidatePairInterface* selected_candidate_pair, int last_sent_packet_id, bool ready_to_send); - void OnChannelStateChanged(TransportChannelImpl* channel); + void OnChannelStateChanged(IceTransportInternal* channel); void OnDtlsHandshakeError(rtc::SSLHandshakeError error); rtc::Thread* network_thread_; // Everything should occur on this thread. // Underlying channel, not owned by this class. - TransportChannelImpl* const channel_; + IceTransportInternal* const channel_; std::unique_ptr dtls_; // The DTLS stream StreamInterfaceChannel* downward_; // Wrapper for channel_, owned by dtls_. std::vector srtp_ciphers_; // SRTP ciphers to use with DTLS. diff --git a/webrtc/p2p/base/dtlstransportchannel_unittest.cc b/webrtc/p2p/base/dtlstransportchannel_unittest.cc index 3efc1e7df9..bff2e7da5d 100644 --- a/webrtc/p2p/base/dtlstransportchannel_unittest.cc +++ b/webrtc/p2p/base/dtlstransportchannel_unittest.cc @@ -88,8 +88,8 @@ class DtlsTestClient : public sigslot::has_slots<> { transport_.reset( new cricket::JsepTransport("dtls content name", certificate_)); for (int i = 0; i < count; ++i) { - cricket::FakeTransportChannel* fake_ice_channel = - new cricket::FakeTransportChannel(transport_->mid(), i); + cricket::FakeIceTransport* fake_ice_channel = + new cricket::FakeIceTransport(transport_->mid(), i); fake_ice_channel->SetAsync(true); fake_ice_channel->SetAsyncDelay(async_delay_ms); // Hook the raw packets so that we can verify they are encrypted. @@ -111,14 +111,14 @@ class DtlsTestClient : public sigslot::has_slots<> { channels_.push_back( std::unique_ptr(channel)); fake_channels_.push_back( - std::unique_ptr(fake_ice_channel)); + std::unique_ptr(fake_ice_channel)); transport_->AddChannel(channel, i); } } cricket::JsepTransport* transport() { return transport_.get(); } - cricket::FakeTransportChannel* GetFakeChannel(int component) { + cricket::FakeIceTransport* GetFakeChannel(int component) { for (const auto& ch : fake_channels_) { if (ch->component() == component) { return ch.get(); @@ -434,7 +434,7 @@ class DtlsTestClient : public sigslot::has_slots<> { private: std::string name_; rtc::scoped_refptr certificate_; - std::vector> fake_channels_; + std::vector> fake_channels_; std::vector> channels_; std::unique_ptr transport_; size_t packet_size_ = 0u; @@ -639,8 +639,8 @@ class DtlsTransportChannelTest : public DtlsTransportChannelTestBase, // Test that transport negotiation of ICE, no DTLS works properly. TEST_F(DtlsTransportChannelTest, TestChannelSetupIce) { Negotiate(); - cricket::FakeTransportChannel* channel1 = client1_.GetFakeChannel(0); - cricket::FakeTransportChannel* channel2 = client2_.GetFakeChannel(0); + cricket::FakeIceTransport* channel1 = client1_.GetFakeChannel(0); + cricket::FakeIceTransport* channel2 = client2_.GetFakeChannel(0); ASSERT_TRUE(channel1 != NULL); ASSERT_TRUE(channel2 != NULL); EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel1->GetIceRole()); diff --git a/webrtc/p2p/base/faketransportcontroller.h b/webrtc/p2p/base/faketransportcontroller.h index d42a93ddae..28eb86caca 100644 --- a/webrtc/p2p/base/faketransportcontroller.h +++ b/webrtc/p2p/base/faketransportcontroller.h @@ -16,10 +16,6 @@ #include #include -#include "webrtc/p2p/base/candidatepairinterface.h" -#include "webrtc/p2p/base/transportchannel.h" -#include "webrtc/p2p/base/transportcontroller.h" -#include "webrtc/p2p/base/transportchannelimpl.h" #include "webrtc/base/bind.h" #include "webrtc/base/buffer.h" #include "webrtc/base/fakesslidentity.h" @@ -27,6 +23,11 @@ #include "webrtc/base/sigslot.h" #include "webrtc/base/sslfingerprint.h" #include "webrtc/base/thread.h" +#include "webrtc/p2p/base/candidatepairinterface.h" +#include "webrtc/p2p/base/icetransportinternal.h" +#include "webrtc/p2p/base/transportchannel.h" +#include "webrtc/p2p/base/transportchannelimpl.h" +#include "webrtc/p2p/base/transportcontroller.h" #ifdef HAVE_QUIC #include "webrtc/p2p/quic/quictransport.h" @@ -41,6 +42,227 @@ struct PacketMessageData : public rtc::MessageData { }; } // namespace +class FakeIceTransport : public IceTransportInternal, + public rtc::MessageHandler { + public: + explicit FakeIceTransport(const std::string& name, int component) + : name_(name), component_(component) {} + ~FakeIceTransport() { Reset(); } + + const std::string& transport_name() const override { return name_; } + int component() const override { return component_; } + uint64_t IceTiebreaker() const { return tiebreaker_; } + IceMode remote_ice_mode() const { return remote_ice_mode_; } + const std::string& ice_ufrag() const { return ice_ufrag_; } + const std::string& ice_pwd() const { return ice_pwd_; } + const std::string& remote_ice_ufrag() const { return remote_ice_ufrag_; } + const std::string& remote_ice_pwd() const { return remote_ice_pwd_; } + + // If async, will send packets by "Post"-ing to message queue instead of + // synchronously "Send"-ing. + void SetAsync(bool async) { async_ = async; } + void SetAsyncDelay(int delay_ms) { async_delay_ms_ = delay_ms; } + + IceTransportState GetState() const override { + if (connection_count_ == 0) { + return had_connection_ ? IceTransportState::STATE_FAILED + : IceTransportState::STATE_INIT; + } + + if (connection_count_ == 1) { + return IceTransportState::STATE_COMPLETED; + } + + return IceTransportState::STATE_CONNECTING; + } + + void SetIceRole(IceRole role) override { role_ = role; } + IceRole GetIceRole() const override { return role_; } + void SetIceTiebreaker(uint64_t tiebreaker) override { + tiebreaker_ = tiebreaker; + } + void SetIceParameters(const IceParameters& ice_params) override { + ice_ufrag_ = ice_params.ufrag; + ice_pwd_ = ice_params.pwd; + } + void SetRemoteIceParameters(const IceParameters& params) override { + remote_ice_ufrag_ = params.ufrag; + remote_ice_pwd_ = params.pwd; + } + + void SetRemoteIceMode(IceMode mode) override { remote_ice_mode_ = mode; } + + void MaybeStartGathering() override { + if (gathering_state_ == kIceGatheringNew) { + gathering_state_ = kIceGatheringGathering; + SignalGatheringState(this); + } + } + + IceGatheringState gathering_state() const override { + return gathering_state_; + } + + void Reset() { + if (state_ != STATE_INIT) { + state_ = STATE_INIT; + if (dest_) { + dest_->state_ = STATE_INIT; + dest_->dest_ = nullptr; + dest_ = nullptr; + } + } + } + + void SetWritable(bool writable) { set_writable(writable); } + + void set_writable(bool writable) { + if (writable_ == writable) { + return; + } + LOG(INFO) << "set_writable from:" << writable_ << " to " << writable; + writable_ = writable; + if (writable_) { + SignalReadyToSend(this); + } + SignalWritableState(this); + } + bool writable() const override { return writable_; } + + // Simulates the two transports connecting to each other. + // If |asymmetric| is true this method only affects this FakeIceTransport. + // If false, it affects |dest| as well. + void SetDestination(FakeIceTransport* dest, bool asymmetric = false) { + if (state_ == STATE_INIT && dest) { + // This simulates the delivery of candidates. + dest_ = dest; + state_ = STATE_CONNECTED; + set_writable(true); + if (!asymmetric) { + dest->SetDestination(this, true); + } + } else if (state_ == STATE_CONNECTED && !dest) { + // Simulates loss of connectivity, by asymmetrically forgetting dest_. + dest_ = nullptr; + state_ = STATE_INIT; + set_writable(false); + } + } + + void SetConnectionCount(size_t connection_count) { + size_t old_connection_count = connection_count_; + connection_count_ = connection_count; + if (connection_count) + had_connection_ = true; + // In this fake transport channel, |connection_count_| determines the + // transport channel state. + if (connection_count_ < old_connection_count) + SignalStateChanged(this); + } + + void SetCandidatesGatheringComplete() { + if (gathering_state_ != kIceGatheringComplete) { + gathering_state_ = kIceGatheringComplete; + SignalGatheringState(this); + } + } + + void SetReceiving(bool receiving) { set_receiving(receiving); } + + void set_receiving(bool receiving) { + if (receiving_ == receiving) { + return; + } + receiving_ = receiving; + SignalReceivingState(this); + } + bool receiving() const override { return receiving_; } + + void SetIceConfig(const IceConfig& config) override { ice_config_ = config; } + + int receiving_timeout() const { return ice_config_.receiving_timeout; } + bool gather_continually() const { return ice_config_.gather_continually(); } + + int SendPacket(const char* data, + size_t len, + const rtc::PacketOptions& options, + int flags) override { + if (state_ != STATE_CONNECTED) { + return -1; + } + + if (flags != PF_SRTP_BYPASS && flags != 0) { + return -1; + } + + PacketMessageData* packet = new PacketMessageData(data, len); + if (async_) { + if (async_delay_ms_) { + rtc::Thread::Current()->PostDelayed(RTC_FROM_HERE, async_delay_ms_, + this, 0, packet); + } else { + rtc::Thread::Current()->Post(RTC_FROM_HERE, this, 0, packet); + } + } else { + rtc::Thread::Current()->Send(RTC_FROM_HERE, this, 0, packet); + } + rtc::SentPacket sent_packet(options.packet_id, rtc::TimeMillis()); + SignalSentPacket(this, sent_packet); + return static_cast(len); + } + int SetOption(rtc::Socket::Option opt, int value) override { return true; } + bool GetOption(rtc::Socket::Option opt, int* value) override { return true; } + int GetError() override { return 0; } + + void AddRemoteCandidate(const Candidate& candidate) override { + remote_candidates_.push_back(candidate); + } + + void RemoveRemoteCandidate(const Candidate& candidate) override {} + + const Candidates& remote_candidates() const { return remote_candidates_; } + + void OnMessage(rtc::Message* msg) override { + PacketMessageData* data = static_cast(msg->pdata); + dest_->SignalReadPacket(dest_, data->packet.data(), + data->packet.size(), rtc::CreatePacketTime(0), 0); + delete data; + } + + bool GetStats(ConnectionInfos* infos) override { + ConnectionInfo info; + infos->clear(); + infos->push_back(info); + return true; + } + + void SetMetricsObserver(webrtc::MetricsObserverInterface* observer) override { + } + + private: + std::string name_; + int component_; + enum State { STATE_INIT, STATE_CONNECTED }; + FakeIceTransport* dest_ = nullptr; + State state_ = STATE_INIT; + bool async_ = false; + int async_delay_ms_ = 0; + Candidates remote_candidates_; + IceConfig ice_config_; + IceRole role_ = ICEROLE_UNKNOWN; + uint64_t tiebreaker_ = 0; + std::string ice_ufrag_; + std::string ice_pwd_; + std::string remote_ice_ufrag_; + std::string remote_ice_pwd_; + IceMode remote_ice_mode_ = ICEMODE_FULL; + size_t connection_count_ = 0; + IceGatheringState gathering_state_ = kIceGatheringNew; + bool had_connection_ = false; + bool writable_ = false; + bool receiving_ = false; +}; + // Fake transport channel class, which can be passed to anything that needs a // transport channel. Can be informed of another FakeTransportChannel via // SetDestination. @@ -68,17 +290,17 @@ class FakeTransportChannel : public TransportChannelImpl, void SetAsync(bool async) { async_ = async; } void SetAsyncDelay(int delay_ms) { async_delay_ms_ = delay_ms; } - TransportChannelState GetState() const override { + IceTransportState GetState() const override { if (connection_count_ == 0) { - return had_connection_ ? TransportChannelState::STATE_FAILED - : TransportChannelState::STATE_INIT; + return had_connection_ ? IceTransportState::STATE_FAILED + : IceTransportState::STATE_INIT; } if (connection_count_ == 1) { - return TransportChannelState::STATE_COMPLETED; + return IceTransportState::STATE_COMPLETED; } - return TransportChannelState::STATE_CONNECTING; + return IceTransportState::STATE_CONNECTING; } void SetIceRole(IceRole role) override { role_ = role; } @@ -447,7 +669,7 @@ class FakeTransportController : public TransportController { // The ICE channel is never actually used by TransportController directly, // since (currently) the DTLS channel pretends to be both ICE + DTLS. This // will change when we get rid of TransportChannelImpl. - TransportChannelImpl* CreateIceTransportChannel_n( + IceTransportInternal* CreateIceTransportChannel_n( const std::string& transport_name, int component) override { return nullptr; @@ -456,7 +678,7 @@ class FakeTransportController : public TransportController { TransportChannelImpl* CreateDtlsTransportChannel_n( const std::string& transport_name, int component, - TransportChannelImpl*) override { + IceTransportInternal*) override { return new FakeTransportChannel(transport_name, component); } diff --git a/webrtc/p2p/base/icetransportinternal.h b/webrtc/p2p/base/icetransportinternal.h index d8e05d1663..bd3c78a770 100644 --- a/webrtc/p2p/base/icetransportinternal.h +++ b/webrtc/p2p/base/icetransportinternal.h @@ -11,16 +11,6 @@ #ifndef WEBRTC_P2P_BASE_ICETRANSPORTINTERNAL_H_ #define WEBRTC_P2P_BASE_ICETRANSPORTINTERNAL_H_ -#include "webrtc/p2p/base/transportchannelimpl.h" - -namespace cricket { - -typedef TransportChannel IceTransportInternal; -typedef TransportChannelImpl IceTransportInternal2; - -} // namespace cricket - -/* #include #include "webrtc/p2p/base/candidate.h" @@ -35,11 +25,15 @@ class MetricsObserverInterface; namespace cricket { -enum class TransportState { +class IceTransportInternal; +typedef IceTransportInternal IceTransportInternal2; + +// TODO(zhihuang): replace it with PeerConnectionInterface::IceConnectionState. +enum class IceTransportState { STATE_INIT, STATE_CONNECTING, // Will enter this state once a connection is created STATE_COMPLETED, - STATE_FAILEDs + STATE_FAILED }; // TODO(zhihuang): Remove this once it's no longer used in @@ -54,9 +48,9 @@ enum IceProtocolType { // the IceTransportInterface will be split from this class. class IceTransportInternal : public rtc::PacketTransportInterface { public: - virtual ~IceTransportInternal(); + virtual ~IceTransportInternal(){}; - virtual TransportState GetState() const = 0; + virtual IceTransportState GetState() const = 0; virtual const std::string& transport_name() const = 0; @@ -105,6 +99,9 @@ class IceTransportInternal : public rtc::PacketTransportInterface { virtual IceGatheringState gathering_state() const = 0; + // Returns the current stats for this connection. + virtual bool GetStats(ConnectionInfos* infos) = 0; + sigslot::signal1 SignalGatheringState; // Handles sending and receiving of candidates. @@ -129,13 +126,22 @@ class IceTransportInternal : public rtc::PacketTransportInterface { sigslot::signal4 SignalSelectedCandidatePairChanged; + // Invoked when there is conflict in the ICE role between local and remote + // agents. + sigslot::signal1 SignalRoleConflict; + + // Emitted whenever the transport state changed. + sigslot::signal1 SignalStateChanged; + // Invoked when the transport is being destroyed. sigslot::signal1 SignalDestroyed; // Debugging description of this transport. - std::string ToString() const; + const std::string debug_name() const override { + return transport_name() + " " + std::to_string(component()); + } }; } // namespace cricket -*/ + #endif // WEBRTC_P2P_BASE_ICETRANSPORTINTERNAL_H_ diff --git a/webrtc/p2p/base/jseptransport.h b/webrtc/p2p/base/jseptransport.h index ff0edebca6..1cb94e093e 100644 --- a/webrtc/p2p/base/jseptransport.h +++ b/webrtc/p2p/base/jseptransport.h @@ -17,15 +17,15 @@ #include #include "webrtc/base/constructormagic.h" +#include "webrtc/base/messagequeue.h" #include "webrtc/base/optional.h" +#include "webrtc/base/rtccertificate.h" +#include "webrtc/base/sigslot.h" +#include "webrtc/base/sslstreamadapter.h" #include "webrtc/p2p/base/candidate.h" #include "webrtc/p2p/base/p2pconstants.h" #include "webrtc/p2p/base/sessiondescription.h" #include "webrtc/p2p/base/transportinfo.h" -#include "webrtc/base/messagequeue.h" -#include "webrtc/base/rtccertificate.h" -#include "webrtc/base/sigslot.h" -#include "webrtc/base/sslstreamadapter.h" namespace cricket { @@ -322,8 +322,6 @@ class JsepTransport : public sigslot::has_slots<> { std::string* error_desc) const; private: - TransportChannelImpl* GetChannel(int component); - // Negotiates the transport parameters based on the current local and remote // transport description, such as the ICE role to use, and whether DTLS // should be activated. diff --git a/webrtc/p2p/base/mockicetransport.h b/webrtc/p2p/base/mockicetransport.h index 6b8b237529..0499c9f8b6 100644 --- a/webrtc/p2p/base/mockicetransport.h +++ b/webrtc/p2p/base/mockicetransport.h @@ -25,10 +25,11 @@ using testing::Return; namespace cricket { // Used in Chromium/remoting/protocol/channel_socket_adapter_unittest.cc -class MockIceTransport : public cricket::TransportChannel { +class MockIceTransport : public IceTransportInternal { public: - MockIceTransport() : cricket::TransportChannel(std::string(), 0) { - set_writable(true); + MockIceTransport() { + SignalReadyToSend(this); + SignalWritableState(this); } MOCK_METHOD4(SendPacket, @@ -42,27 +43,34 @@ class MockIceTransport : public cricket::TransportChannel { MOCK_METHOD1(GetStats, bool(cricket::ConnectionInfos* infos)); MOCK_CONST_METHOD0(IsDtlsActive, bool()); MOCK_CONST_METHOD1(GetSslRole, bool(rtc::SSLRole* role)); - MOCK_METHOD1(SetSrtpCiphers, bool(const std::vector& ciphers)); - MOCK_METHOD1(GetSrtpCipher, bool(std::string* cipher)); - MOCK_METHOD1(GetSslCipher, bool(std::string* cipher)); - MOCK_CONST_METHOD0(GetLocalCertificate, - rtc::scoped_refptr()); - // This can't be a real mock method because gmock doesn't support move-only - // return values. - std::unique_ptr GetRemoteSSLCertificate() - const override { - EXPECT_TRUE(false); // Never called. - return nullptr; + IceTransportState GetState() const override { + return IceTransportState::STATE_INIT; + } + const std::string& transport_name() const override { return transport_name_; } + int component() const override { return 0; } + void SetIceRole(IceRole role) override {} + void SetIceTiebreaker(uint64_t tiebreaker) override {} + // The ufrag and pwd in |ice_params| must be set + // before candidate gathering can start. + void SetIceParameters(const IceParameters& ice_params) override {} + void SetRemoteIceParameters(const IceParameters& ice_params) override {} + void SetRemoteIceMode(IceMode mode) override {} + void SetIceConfig(const IceConfig& config) override {} + void MaybeStartGathering() override {} + void SetMetricsObserver(webrtc::MetricsObserverInterface* observer) override { + } + void AddRemoteCandidate(const Candidate& candidate) override {} + void RemoveRemoteCandidate(const Candidate& candidate) override {} + IceGatheringState gathering_state() const override { + return IceGatheringState::kIceGatheringComplete; } - MOCK_METHOD6(ExportKeyingMaterial, - bool(const std::string& label, - const uint8_t* context, - size_t context_len, - bool use_context, - uint8_t* result, - size_t result_len)); + bool receiving() const override { return true; } + bool writable() const override { return true; } + + private: + std::string transport_name_; }; } // namespace cricket diff --git a/webrtc/p2p/base/p2ptransportchannel.cc b/webrtc/p2p/base/p2ptransportchannel.cc index 6e5be892f2..532d35cc54 100644 --- a/webrtc/p2p/base/p2ptransportchannel.cc +++ b/webrtc/p2p/base/p2ptransportchannel.cc @@ -101,7 +101,8 @@ static constexpr int b_is_better = -1; P2PTransportChannel::P2PTransportChannel(const std::string& transport_name, int component, PortAllocator* allocator) - : TransportChannelImpl(transport_name, component), + : transport_name_(transport_name), + component_(component), allocator_(allocator), network_thread_(rtc::Thread::Current()), incoming_only_(false), @@ -272,15 +273,15 @@ void P2PTransportChannel::SetIceTiebreaker(uint64_t tiebreaker) { tiebreaker_ = tiebreaker; } -TransportChannelState P2PTransportChannel::GetState() const { +IceTransportState P2PTransportChannel::GetState() const { return state_; } // A channel is considered ICE completed once there is at most one active // connection per network and at least one active connection. -TransportChannelState P2PTransportChannel::ComputeState() const { +IceTransportState P2PTransportChannel::ComputeState() const { if (!had_connection_) { - return TransportChannelState::STATE_INIT; + return IceTransportState::STATE_INIT; } std::vector active_connections; @@ -290,7 +291,7 @@ TransportChannelState P2PTransportChannel::ComputeState() const { } } if (active_connections.empty()) { - return TransportChannelState::STATE_FAILED; + return IceTransportState::STATE_FAILED; } std::set networks; @@ -302,11 +303,11 @@ TransportChannelState P2PTransportChannel::ComputeState() const { LOG_J(LS_VERBOSE, this) << "Ice not completed yet for this channel as " << network->ToString() << " has more than 1 connection."; - return TransportChannelState::STATE_CONNECTING; + return IceTransportState::STATE_CONNECTING; } } - return TransportChannelState::STATE_COMPLETED; + return IceTransportState::STATE_COMPLETED; } void P2PTransportChannel::SetIceParameters(const IceParameters& ice_params) { @@ -1391,33 +1392,38 @@ void P2PTransportChannel::SwitchSelectedConnection(Connection* conn) { // change, it should be called after all the connection states have changed. For // example, we call this at the end of SortConnectionsAndUpdateState. void P2PTransportChannel::UpdateState() { - TransportChannelState state = ComputeState(); + IceTransportState state = ComputeState(); if (state_ != state) { - LOG_J(LS_INFO, this) << "Transport channel state changed from " << state_ - << " to " << state; + LOG_J(LS_INFO, this) << "Transport channel state changed from " + << static_cast(state_) << " to " + << static_cast(state); // Check that the requested transition is allowed. Note that // P2PTransportChannel does not (yet) implement a direct mapping of the ICE // states from the standard; the difference is covered by // TransportController and PeerConnection. switch (state_) { - case STATE_INIT: + case IceTransportState::STATE_INIT: // TODO(deadbeef): Once we implement end-of-candidates signaling, // we shouldn't go from INIT to COMPLETED. - RTC_DCHECK(state == STATE_CONNECTING || state == STATE_COMPLETED); + RTC_DCHECK(state == IceTransportState::STATE_CONNECTING || + state == IceTransportState::STATE_COMPLETED); break; - case STATE_CONNECTING: - RTC_DCHECK(state == STATE_COMPLETED || state == STATE_FAILED); + case IceTransportState::STATE_CONNECTING: + RTC_DCHECK(state == IceTransportState::STATE_COMPLETED || + state == IceTransportState::STATE_FAILED); break; - case STATE_COMPLETED: + case IceTransportState::STATE_COMPLETED: // TODO(deadbeef): Once we implement end-of-candidates signaling, // we shouldn't go from COMPLETED to CONNECTING. // Though we *can* go from COMPlETED to FAILED, if consent expires. - RTC_DCHECK(state == STATE_CONNECTING || state == STATE_FAILED); + RTC_DCHECK(state == IceTransportState::STATE_CONNECTING || + state == IceTransportState::STATE_FAILED); break; - case STATE_FAILED: + case IceTransportState::STATE_FAILED: // TODO(deadbeef): Once we implement end-of-candidates signaling, // we shouldn't go from FAILED to CONNECTING or COMPLETED. - RTC_DCHECK(state == STATE_CONNECTING || state == STATE_COMPLETED); + RTC_DCHECK(state == IceTransportState::STATE_CONNECTING || + state == IceTransportState::STATE_COMPLETED); break; default: RTC_NOTREACHED(); @@ -1533,8 +1539,8 @@ void P2PTransportChannel::OnCheckAndPing() { // A connection is considered a backup connection if the channel state // is completed, the connection is not the selected connection and it is active. bool P2PTransportChannel::IsBackupConnection(const Connection* conn) const { - return state_ == STATE_COMPLETED && conn != selected_connection_ && - conn->active(); + return state_ == IceTransportState::STATE_COMPLETED && + conn != selected_connection_ && conn->active(); } // Is the connection in a state for us to even consider pinging the other side? @@ -2014,4 +2020,25 @@ Connection* P2PTransportChannel::MorePingable(Connection* conn1, })); } +void P2PTransportChannel::set_writable(bool writable) { + if (writable_ == writable) { + return; + } + LOG_J(LS_VERBOSE, this) << "set_writable from:" << writable_ << " to " + << writable; + writable_ = writable; + if (writable_) { + SignalReadyToSend(this); + } + SignalWritableState(this); +} + +void P2PTransportChannel::set_receiving(bool receiving) { + if (receiving_ == receiving) { + return; + } + receiving_ = receiving; + SignalReceivingState(this); +} + } // namespace cricket diff --git a/webrtc/p2p/base/p2ptransportchannel.h b/webrtc/p2p/base/p2ptransportchannel.h index e538dc2c97..2327b2d477 100644 --- a/webrtc/p2p/base/p2ptransportchannel.h +++ b/webrtc/p2p/base/p2ptransportchannel.h @@ -26,14 +26,14 @@ #include #include +#include "webrtc/base/asyncpacketsocket.h" #include "webrtc/base/constructormagic.h" +#include "webrtc/base/sigslot.h" #include "webrtc/p2p/base/candidate.h" #include "webrtc/p2p/base/candidatepairinterface.h" +#include "webrtc/p2p/base/icetransportinternal.h" #include "webrtc/p2p/base/portallocator.h" #include "webrtc/p2p/base/portinterface.h" -#include "webrtc/p2p/base/transportchannelimpl.h" -#include "webrtc/base/asyncpacketsocket.h" -#include "webrtc/base/sigslot.h" namespace cricket { @@ -60,7 +60,7 @@ class RemoteCandidate : public Candidate { // P2PTransportChannel manages the candidates and connection process to keep // two P2P clients connected to each other. -class P2PTransportChannel : public TransportChannelImpl, +class P2PTransportChannel : public IceTransportInternal, public rtc::MessageHandler { public: P2PTransportChannel(const std::string& transport_name, @@ -69,7 +69,11 @@ class P2PTransportChannel : public TransportChannelImpl, virtual ~P2PTransportChannel(); // From TransportChannelImpl: - TransportChannelState GetState() const override; + IceTransportState GetState() const override; + const std::string& transport_name() const override { return transport_name_; } + int component() const override { return component_; } + bool writable() const override { return writable_; } + bool receiving() const override { return receiving_; } void SetIceRole(IceRole role) override; IceRole GetIceRole() const override { return ice_role_; } void SetIceTiebreaker(uint64_t tiebreaker) override; @@ -118,57 +122,6 @@ class P2PTransportChannel : public TransportChannelImpl, IceMode remote_ice_mode() const { return remote_ice_mode_; } - // DTLS methods. - bool IsDtlsActive() const override { return false; } - - // Default implementation. - bool GetSslRole(rtc::SSLRole* role) const override { return false; } - - bool SetSslRole(rtc::SSLRole role) override { return false; } - - // Set up the ciphers to use for DTLS-SRTP. - bool SetSrtpCryptoSuites(const std::vector& ciphers) override { - return false; - } - - // Find out which DTLS-SRTP cipher was negotiated. - bool GetSrtpCryptoSuite(int* cipher) override { return false; } - - // Find out which DTLS cipher was negotiated. - bool GetSslCipherSuite(int* cipher) override { return false; } - - // Returns null because the channel is not encrypted by default. - rtc::scoped_refptr GetLocalCertificate() const override { - return nullptr; - } - - std::unique_ptr GetRemoteSSLCertificate() - const override { - return nullptr; - } - - // Allows key material to be extracted for external encryption. - bool ExportKeyingMaterial(const std::string& label, - const uint8_t* context, - size_t context_len, - bool use_context, - uint8_t* result, - size_t result_len) override { - return false; - } - - bool SetLocalCertificate( - const rtc::scoped_refptr& certificate) override { - return false; - } - - // Set DTLS Remote fingerprint. Must be after local identity set. - bool SetRemoteFingerprint(const std::string& digest_alg, - const uint8_t* digest, - size_t digest_len) override { - return false; - } - void PruneAllPorts(); int receiving_timeout() const { return config_.receiving_timeout; } int check_receiving_interval() const { return check_receiving_interval_; } @@ -193,6 +146,15 @@ class P2PTransportChannel : public TransportChannelImpl, return remote_candidates_; } + std::string ToString() const { + const char RECEIVING_ABBREV[2] = {'_', 'R'}; + const char WRITABLE_ABBREV[2] = {'_', 'W'}; + std::stringstream ss; + ss << "Channel[" << transport_name_ << "|" << component_ << "|" + << RECEIVING_ABBREV[receiving_] << WRITABLE_ABBREV[writable_] << "]"; + return ss.str(); + } + private: rtc::Thread* thread() const { return network_thread_; } bool IsGettingPorts() { return allocator_session()->IsGettingPorts(); } @@ -239,7 +201,7 @@ class P2PTransportChannel : public TransportChannelImpl, void UpdateState(); void HandleAllTimedOut(); void MaybeStopPortAllocatorSessions(); - TransportChannelState ComputeState() const; + IceTransportState ComputeState() const; Connection* GetBestConnectionOnNetwork(rtc::Network* network) const; bool CreateConnections(const Candidate& remote_candidate, @@ -347,6 +309,13 @@ class P2PTransportChannel : public TransportChannelImpl, : static_cast(remote_ice_parameters_.size() - 1); } + // Sets the writable state, signaling if necessary. + void set_writable(bool writable); + // Sets the receiving state, signaling if necessary. + void set_receiving(bool receiving); + + std::string transport_name_; + int component_; PortAllocator* allocator_; rtc::Thread* network_thread_; bool incoming_only_; @@ -387,13 +356,15 @@ class P2PTransportChannel : public TransportChannelImpl, int check_receiving_interval_; int64_t last_ping_sent_ms_ = 0; int weak_ping_interval_ = WEAK_PING_INTERVAL; - TransportChannelState state_ = TransportChannelState::STATE_INIT; + IceTransportState state_ = IceTransportState::STATE_INIT; IceConfig config_; int last_sent_packet_id_ = -1; // -1 indicates no packet was sent before. bool started_pinging_ = false; // The value put in the "nomination" attribute for the next nominated // connection. A zero-value indicates the connection will not be nominated. uint32_t nomination_ = 0; + bool receiving_ = false; + bool writable_ = false; webrtc::MetricsObserverInterface* metrics_observer_ = nullptr; diff --git a/webrtc/p2p/base/p2ptransportchannel_unittest.cc b/webrtc/p2p/base/p2ptransportchannel_unittest.cc index ae47fa6a28..1f262dbcc7 100644 --- a/webrtc/p2p/base/p2ptransportchannel_unittest.cc +++ b/webrtc/p2p/base/p2ptransportchannel_unittest.cc @@ -34,6 +34,7 @@ #include "webrtc/base/ssladapter.h" #include "webrtc/base/thread.h" #include "webrtc/base/virtualsocketserver.h" +#include "webrtc/p2p/base/icetransportinternal.h" namespace { @@ -271,11 +272,11 @@ class P2PTransportChannelTestBase : public testing::Test, }; struct CandidatesData : public rtc::MessageData { - CandidatesData(TransportChannel* ch, const Candidate& c) + CandidatesData(IceTransportInternal* ch, const Candidate& c) : channel(ch), candidates(1, c) {} - CandidatesData(TransportChannel* ch, const std::vector& cc) + CandidatesData(IceTransportInternal* ch, const std::vector& cc) : channel(ch), candidates(cc) {} - TransportChannel* channel; + IceTransportInternal* channel; Candidates candidates; }; @@ -685,7 +686,7 @@ class P2PTransportChannelTestBase : public testing::Test, } // We pass the candidates directly to the other side. - void OnCandidateGathered(TransportChannelImpl* ch, const Candidate& c) { + void OnCandidateGathered(IceTransportInternal* ch, const Candidate& c) { if (force_relay_ && c.type() != RELAY_PORT_TYPE) return; @@ -698,7 +699,7 @@ class P2PTransportChannelTestBase : public testing::Test, } } void OnSelectedCandidatePairChanged( - TransportChannel* transport_channel, + IceTransportInternal* transport_channel, CandidatePairInterface* selected_candidate_pair, int last_sent_packet_id, bool ready_to_send) { @@ -719,7 +720,7 @@ class P2PTransportChannelTestBase : public testing::Test, GetEndpoint(endpoint)->save_candidates_ = true; } - void OnCandidatesRemoved(TransportChannelImpl* ch, + void OnCandidatesRemoved(IceTransportInternal* ch, const std::vector& candidates) { // Candidate removals are not paused. CandidatesData* candidates_data = new CandidatesData(ch, candidates); @@ -797,7 +798,7 @@ class P2PTransportChannelTestBase : public testing::Test, packets.push_front(std::string(data, len)); } - void OnRoleConflict(TransportChannelImpl* channel) { + void OnRoleConflict(IceTransportInternal* channel) { GetEndpoint(channel)->OnRoleConflict(true); IceRole new_role = GetEndpoint(channel)->ice_role() == ICEROLE_CONTROLLING ? ICEROLE_CONTROLLED @@ -805,11 +806,11 @@ class P2PTransportChannelTestBase : public testing::Test, channel->SetIceRole(new_role); } - int SendData(TransportChannel* channel, const char* data, size_t len) { + int SendData(IceTransportInternal* channel, const char* data, size_t len) { rtc::PacketOptions options; return channel->SendPacket(data, len, options, 0); } - bool CheckDataOnChannel(TransportChannel* channel, + bool CheckDataOnChannel(IceTransportInternal* channel, const char* data, int len) { return GetChannelData(channel)->CheckData(data, len); @@ -833,7 +834,7 @@ class P2PTransportChannelTestBase : public testing::Test, return NULL; } } - P2PTransportChannel* GetRemoteChannel(TransportChannel* ch) { + P2PTransportChannel* GetRemoteChannel(IceTransportInternal* ch) { if (ch == ep1_ch1()) return ep2_ch1(); else if (ch == ep1_ch2()) @@ -2656,7 +2657,8 @@ TEST_F(P2PTransportChannelMultihomedTest, TestPingBackupConnectionRate) { CreateIceConfig(2000, GATHER_ONCE, backup_ping_interval)); // After the state becomes COMPLETED, the backup connection will be pinged // once every |backup_ping_interval| milliseconds. - ASSERT_TRUE_WAIT(ep2_ch1()->GetState() == STATE_COMPLETED, 1000); + ASSERT_TRUE_WAIT(ep2_ch1()->GetState() == IceTransportState::STATE_COMPLETED, + 1000); const std::vector& connections = ep2_ch1()->connections(); ASSERT_EQ(2U, connections.size()); Connection* backup_conn = connections[1]; @@ -2682,9 +2684,9 @@ TEST_F(P2PTransportChannelMultihomedTest, TestGetState) { CreateChannels(); // Both transport channels will reach STATE_COMPLETED quickly. - EXPECT_EQ_SIMULATED_WAIT(TransportChannelState::STATE_COMPLETED, + EXPECT_EQ_SIMULATED_WAIT(IceTransportState::STATE_COMPLETED, ep1_ch1()->GetState(), kShortTimeout, clock); - EXPECT_EQ_SIMULATED_WAIT(TransportChannelState::STATE_COMPLETED, + EXPECT_EQ_SIMULATED_WAIT(IceTransportState::STATE_COMPLETED, ep2_ch1()->GetState(), kShortTimeout, clock); } @@ -2766,13 +2768,13 @@ TEST_F(P2PTransportChannelMultihomedTest, // backup connection created using this new interface. AddAddress(0, cellular[0], "test_cellular0", rtc::ADAPTER_TYPE_CELLULAR); EXPECT_TRUE_WAIT( - ep1_ch1()->GetState() == STATE_COMPLETED && + ep1_ch1()->GetState() == IceTransportState::STATE_COMPLETED && (conn = GetConnectionWithLocalAddress(ep1_ch1(), cellular[0])) != nullptr && conn != ep1_ch1()->selected_connection() && conn->writable(), kDefaultTimeout); EXPECT_TRUE_WAIT( - ep2_ch1()->GetState() == STATE_COMPLETED && + ep2_ch1()->GetState() == IceTransportState::STATE_COMPLETED && (conn = GetConnectionWithRemoteAddress(ep2_ch1(), cellular[0])) != nullptr && conn != ep2_ch1()->selected_connection() && conn->receiving(), @@ -2988,7 +2990,7 @@ class P2PTransportChannelPingTest : public testing::Test, return conn; } - int SendData(TransportChannel& channel, + int SendData(IceTransportInternal& channel, const char* data, size_t len, int packet_id) { @@ -3022,7 +3024,7 @@ class P2PTransportChannelPingTest : public testing::Test, } void OnSelectedCandidatePairChanged( - TransportChannel* transport_channel, + IceTransportInternal* transport_channel, CandidatePairInterface* selected_candidate_pair, int last_sent_packet_id, bool ready_to_send) { @@ -3056,7 +3058,7 @@ class P2PTransportChannelPingTest : public testing::Test, void OnReadyToSend(rtc::PacketTransportInterface* transport) { channel_ready_to_send_ = true; } - void OnChannelStateChanged(TransportChannelImpl* channel) { + void OnChannelStateChanged(IceTransportInternal* channel) { channel_state_ = channel->GetState(); } @@ -3066,7 +3068,7 @@ class P2PTransportChannelPingTest : public testing::Test, int last_sent_packet_id() { return last_sent_packet_id_; } bool channel_ready_to_send() { return channel_ready_to_send_; } void reset_channel_ready_to_send() { channel_ready_to_send_ = false; } - TransportChannelState channel_state() { return channel_state_; } + IceTransportState channel_state() { return channel_state_; } int reset_selected_candidate_pair_switches() { int switches = selected_candidate_pair_switches_; selected_candidate_pair_switches_ = 0; @@ -3081,7 +3083,7 @@ class P2PTransportChannelPingTest : public testing::Test, int selected_candidate_pair_switches_ = 0; int last_sent_packet_id_ = -1; bool channel_ready_to_send_ = false; - TransportChannelState channel_state_ = STATE_INIT; + IceTransportState channel_state_ = IceTransportState::STATE_INIT; }; TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) { @@ -3317,7 +3319,8 @@ TEST_F(P2PTransportChannelPingTest, TestSignalStateChanged) { // Pruning the connection reduces the set of active connections and changes // the channel state. conn1->Prune(); - EXPECT_EQ_WAIT(STATE_FAILED, channel_state(), kDefaultTimeout); + EXPECT_EQ_WAIT(IceTransportState::STATE_FAILED, channel_state(), + kDefaultTimeout); } // Test adding remote candidates with different ufrags. If a remote candidate @@ -3968,7 +3971,7 @@ TEST_F(P2PTransportChannelPingTest, TestGetState) { P2PTransportChannel ch("test channel", 1, &pa); PrepareChannel(&ch); ch.MaybeStartGathering(); - EXPECT_EQ(TransportChannelState::STATE_INIT, ch.GetState()); + EXPECT_EQ(IceTransportState::STATE_INIT, ch.GetState()); ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1, &clock); @@ -3976,14 +3979,14 @@ TEST_F(P2PTransportChannelPingTest, TestGetState) { ASSERT_TRUE(conn1 != nullptr); ASSERT_TRUE(conn2 != nullptr); // Now there are two connections, so the transport channel is connecting. - EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState()); + EXPECT_EQ(IceTransportState::STATE_CONNECTING, ch.GetState()); // |conn1| becomes writable and receiving; it then should prune |conn2|. conn1->ReceivedPingResponse(LOW_RTT, "id"); EXPECT_TRUE_SIMULATED_WAIT(conn2->pruned(), kShortTimeout, clock); - EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); + EXPECT_EQ(IceTransportState::STATE_COMPLETED, ch.GetState()); conn1->Prune(); // All connections are pruned. // Need to wait until the channel state is updated. - EXPECT_EQ_SIMULATED_WAIT(TransportChannelState::STATE_FAILED, ch.GetState(), + EXPECT_EQ_SIMULATED_WAIT(IceTransportState::STATE_FAILED, ch.GetState(), kShortTimeout, clock); } @@ -4018,7 +4021,7 @@ TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { EXPECT_TRUE_SIMULATED_WAIT(!conn2->active(), kDefaultTimeout, clock); // |conn2| should not send a ping yet. EXPECT_EQ(IceCandidatePairState::WAITING, conn2->state()); - EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); + EXPECT_EQ(IceTransportState::STATE_COMPLETED, ch.GetState()); // Wait for |conn1| becoming not receiving. EXPECT_TRUE_SIMULATED_WAIT(!conn1->receiving(), kMediumTimeout, clock); // Make sure conn2 is not deleted. @@ -4029,14 +4032,14 @@ TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { conn2->ReceivedPingResponse(LOW_RTT, "id"); EXPECT_EQ_SIMULATED_WAIT(conn2, ch.selected_connection(), kDefaultTimeout, clock); - EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState()); + EXPECT_EQ(IceTransportState::STATE_CONNECTING, ch.GetState()); // When |conn1| comes back again, |conn2| will be pruned again. conn1->ReceivedPingResponse(LOW_RTT, "id"); EXPECT_EQ_SIMULATED_WAIT(conn1, ch.selected_connection(), kDefaultTimeout, clock); EXPECT_TRUE_SIMULATED_WAIT(!conn2->active(), kDefaultTimeout, clock); - EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); + EXPECT_EQ(IceTransportState::STATE_COMPLETED, ch.GetState()); } // Test that if all connections in a channel has timed out on writing, they diff --git a/webrtc/p2p/base/transportchannel.h b/webrtc/p2p/base/transportchannel.h index c7c3c755f3..7c13f92ee7 100644 --- a/webrtc/p2p/base/transportchannel.h +++ b/webrtc/p2p/base/transportchannel.h @@ -15,19 +15,20 @@ #include #include -#include "webrtc/base/constructormagic.h" -#include "webrtc/p2p/base/candidate.h" -#include "webrtc/p2p/base/candidatepairinterface.h" -#include "webrtc/p2p/base/packettransportinterface.h" -#include "webrtc/p2p/base/jseptransport.h" -#include "webrtc/p2p/base/transportdescription.h" #include "webrtc/base/asyncpacketsocket.h" #include "webrtc/base/basictypes.h" +#include "webrtc/base/constructormagic.h" #include "webrtc/base/dscp.h" #include "webrtc/base/sigslot.h" #include "webrtc/base/socket.h" #include "webrtc/base/sslidentity.h" #include "webrtc/base/sslstreamadapter.h" +#include "webrtc/p2p/base/candidate.h" +#include "webrtc/p2p/base/candidatepairinterface.h" +#include "webrtc/p2p/base/icetransportinternal.h" +#include "webrtc/p2p/base/jseptransport.h" +#include "webrtc/p2p/base/packettransportinterface.h" +#include "webrtc/p2p/base/transportdescription.h" namespace cricket { @@ -40,14 +41,6 @@ enum PacketFlags { // crypto provided by the transport (e.g. DTLS) }; -// Used to indicate channel's connection state. -enum TransportChannelState { - STATE_INIT, - STATE_CONNECTING, // Will enter this state once a connection is created - STATE_COMPLETED, - STATE_FAILED -}; - // A TransportChannel represents one logical stream of packets that are sent // between the two sides of a session. // TODO(deadbeef): This interface currently represents the unity of an ICE @@ -63,8 +56,8 @@ class TransportChannel : public rtc::PacketTransportInterface { // TODO(guoweis) - Make this pure virtual once all subclasses of // TransportChannel have this defined. - virtual TransportChannelState GetState() const { - return TransportChannelState::STATE_CONNECTING; + virtual IceTransportState GetState() const { + return IceTransportState::STATE_CONNECTING; } const std::string& transport_name() const { return transport_name_; } diff --git a/webrtc/p2p/base/transportchannelimpl.h b/webrtc/p2p/base/transportchannelimpl.h index 7592a3cbc8..f72cb2d1b0 100644 --- a/webrtc/p2p/base/transportchannelimpl.h +++ b/webrtc/p2p/base/transportchannelimpl.h @@ -14,6 +14,7 @@ #include #include "webrtc/base/constructormagic.h" +#include "webrtc/p2p/base/icetransportinternal.h" #include "webrtc/p2p/base/transportchannel.h" namespace webrtc { @@ -24,12 +25,6 @@ namespace cricket { class Candidate; -// TODO(pthatcher): Remove this once it's no longer used in -// remoting/protocol/libjingle_transport_factory.cc -enum IceProtocolType { - ICEPROTO_RFC5245 // Standard RFC 5245 version of ICE. -}; - // Base class for real implementations of TransportChannel. This includes some // methods called only by Transport, which do not need to be exposed to the // client. diff --git a/webrtc/p2p/base/transportcontroller.cc b/webrtc/p2p/base/transportcontroller.cc index c9ba9fdb3c..2781b0ba21 100644 --- a/webrtc/p2p/base/transportcontroller.cc +++ b/webrtc/p2p/base/transportcontroller.cc @@ -47,7 +47,7 @@ class TransportController::ChannelPair { // TODO(deadbeef): Change the types of |dtls| and |ice| to // DtlsTransportChannelWrapper and P2PTransportChannelWrapper, // once TransportChannelImpl is removed. - ChannelPair(TransportChannelImpl* dtls, TransportChannelImpl* ice) + ChannelPair(TransportChannelImpl* dtls, IceTransportInternal* ice) : ice_(ice), dtls_(dtls) {} // Currently, all ICE-related calls still go through this DTLS channel. But @@ -55,11 +55,11 @@ class TransportController::ChannelPair { // channel interface no longer includes ICE-specific methods. const TransportChannelImpl* dtls() const { return dtls_.get(); } TransportChannelImpl* dtls() { return dtls_.get(); } - const TransportChannelImpl* ice() const { return ice_.get(); } - TransportChannelImpl* ice() { return ice_.get(); } + const IceTransportInternal* ice() const { return ice_.get(); } + IceTransportInternal* ice() { return ice_.get(); } private: - std::unique_ptr ice_; + std::unique_ptr ice_; std::unique_ptr dtls_; RTC_DISALLOW_COPY_AND_ASSIGN(ChannelPair); @@ -243,7 +243,7 @@ TransportChannel* TransportController::CreateTransportChannel_n( JsepTransport* transport = GetOrCreateJsepTransport(transport_name); // Create DTLS channel wrapping ICE channel, and configure it. - TransportChannelImpl* ice = + IceTransportInternal* ice = CreateIceTransportChannel_n(transport_name, component); // TODO(deadbeef): To support QUIC, would need to create a // QuicTransportChannel here. What is "dtls" in this file would then become @@ -341,7 +341,7 @@ TransportChannelImpl* TransportController::get_channel_for_testing( return ch ? ch->dtls() : nullptr; } -TransportChannelImpl* TransportController::CreateIceTransportChannel_n( +IceTransportInternal* TransportController::CreateIceTransportChannel_n( const std::string& transport_name, int component) { return new P2PTransportChannel(transport_name, component, port_allocator_); @@ -350,7 +350,7 @@ TransportChannelImpl* TransportController::CreateIceTransportChannel_n( TransportChannelImpl* TransportController::CreateDtlsTransportChannel_n( const std::string&, int, - TransportChannelImpl* ice) { + IceTransportInternal* ice) { DtlsTransportChannelWrapper* dtls = new DtlsTransportChannelWrapper(ice); dtls->SetSslMaxProtocolVersion(ssl_max_version_); return dtls; @@ -822,13 +822,12 @@ void TransportController::UpdateAggregateStates_n() { bool all_done_gathering = !channels_.empty(); for (const auto& channel : channels_) { any_receiving = any_receiving || channel->dtls()->receiving(); - any_failed = - any_failed || - channel->dtls()->GetState() == TransportChannelState::STATE_FAILED; + any_failed = any_failed || + channel->dtls()->GetState() == IceTransportState::STATE_FAILED; all_connected = all_connected && channel->dtls()->writable(); all_completed = all_completed && channel->dtls()->writable() && - channel->dtls()->GetState() == TransportChannelState::STATE_COMPLETED && + channel->dtls()->GetState() == IceTransportState::STATE_COMPLETED && channel->dtls()->GetIceRole() == ICEROLE_CONTROLLING && channel->dtls()->gathering_state() == kIceGatheringComplete; any_gathering = diff --git a/webrtc/p2p/base/transportcontroller.h b/webrtc/p2p/base/transportcontroller.h index a46ce00dbc..7929cf0140 100644 --- a/webrtc/p2p/base/transportcontroller.h +++ b/webrtc/p2p/base/transportcontroller.h @@ -164,13 +164,13 @@ class TransportController : public sigslot::has_slots<>, // TODO(deadbeef): Get rid of these virtual methods. Used by // FakeTransportController currently, but FakeTransportController shouldn't // even be functioning by subclassing TransportController. - virtual TransportChannelImpl* CreateIceTransportChannel_n( + virtual IceTransportInternal* CreateIceTransportChannel_n( const std::string& transport_name, int component); virtual TransportChannelImpl* CreateDtlsTransportChannel_n( const std::string& transport_name, int component, - TransportChannelImpl* ice); + IceTransportInternal* ice); private: void OnMessage(rtc::Message* pmsg) override;