Make P2PTransportChannel inherit from IceTransportInternal.
Make P2PTransportChannel inherit from IceTransportInternal instead of
TransportChannelImpl and TransportChannel, so that the DTLS-related methods can
be separated from P2PTransportChannel.
BUG=none
Review-Url: https://codereview.webrtc.org/2590063002
Cr-Commit-Position: refs/heads/master@{#15743}
diff --git a/webrtc/p2p/base/dtlstransportchannel.cc b/webrtc/p2p/base/dtlstransportchannel.cc
index 6221057..56bd1e5 100644
--- a/webrtc/p2p/base/dtlstransportchannel.cc
+++ b/webrtc/p2p/base/dtlstransportchannel.cc
@@ -50,11 +50,10 @@
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 @@
}
DtlsTransportChannelWrapper::DtlsTransportChannelWrapper(
- TransportChannelImpl* channel)
+ IceTransportInternal* channel)
: TransportChannelImpl(channel->transport_name(), channel->component()),
network_thread_(rtc::Thread::Current()),
channel_(channel),
@@ -684,39 +683,39 @@
}
void DtlsTransportChannelWrapper::OnGatheringState(
- TransportChannelImpl* channel) {
+ IceTransportInternal* channel) {
ASSERT(channel == channel_);
SignalGatheringState(this);
}
void DtlsTransportChannelWrapper::OnCandidateGathered(
- TransportChannelImpl* channel,
+ IceTransportInternal* channel,
const Candidate& c) {
ASSERT(channel == channel_);
SignalCandidateGathered(this, c);
}
void DtlsTransportChannelWrapper::OnCandidatesRemoved(
- TransportChannelImpl* channel,
+ IceTransportInternal* channel,
const Candidates& candidates) {
ASSERT(channel == channel_);
SignalCandidatesRemoved(this, candidates);
}
void DtlsTransportChannelWrapper::OnRoleConflict(
- TransportChannelImpl* channel) {
+ IceTransportInternal* channel) {
ASSERT(channel == channel_);
SignalRoleConflict(this);
}
-void DtlsTransportChannelWrapper::OnRouteChange(
- TransportChannel* channel, const Candidate& candidate) {
+void DtlsTransportChannelWrapper::OnRouteChange(IceTransportInternal* channel,
+ const Candidate& candidate) {
ASSERT(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::OnChannelStateChanged(
- TransportChannelImpl* channel) {
+ IceTransportInternal* channel) {
ASSERT(channel == channel_);
SignalStateChanged(this);
}
diff --git a/webrtc/p2p/base/dtlstransportchannel.h b/webrtc/p2p/base/dtlstransportchannel.h
index 5850813..a8d5d5b 100644
--- a/webrtc/p2p/base/dtlstransportchannel.h
+++ b/webrtc/p2p/base/dtlstransportchannel.h
@@ -15,12 +15,13 @@
#include <string>
#include <vector>
-#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 @@
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 @@
int* error) override;
private:
- TransportChannel* channel_; // owned by DtlsTransportChannelWrapper
+ IceTransportInternal* channel_; // owned by DtlsTransportChannelWrapper
rtc::StreamState state_;
rtc::BufferQueue packets_;
@@ -88,7 +89,7 @@
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 @@
}
// 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 @@
}
// 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 @@
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<rtc::SSLStreamAdapter> dtls_; // The DTLS stream
StreamInterfaceChannel* downward_; // Wrapper for channel_, owned by dtls_.
std::vector<int> 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 3efc1e7..bff2e7d 100644
--- a/webrtc/p2p/base/dtlstransportchannel_unittest.cc
+++ b/webrtc/p2p/base/dtlstransportchannel_unittest.cc
@@ -88,8 +88,8 @@
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 @@
channels_.push_back(
std::unique_ptr<cricket::DtlsTransportChannelWrapper>(channel));
fake_channels_.push_back(
- std::unique_ptr<cricket::FakeTransportChannel>(fake_ice_channel));
+ std::unique_ptr<cricket::FakeIceTransport>(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 @@
private:
std::string name_;
rtc::scoped_refptr<rtc::RTCCertificate> certificate_;
- std::vector<std::unique_ptr<cricket::FakeTransportChannel>> fake_channels_;
+ std::vector<std::unique_ptr<cricket::FakeIceTransport>> fake_channels_;
std::vector<std::unique_ptr<cricket::DtlsTransportChannelWrapper>> channels_;
std::unique_ptr<cricket::JsepTransport> transport_;
size_t packet_size_ = 0u;
@@ -639,8 +639,8 @@
// 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 d42a93d..28eb86c 100644
--- a/webrtc/p2p/base/faketransportcontroller.h
+++ b/webrtc/p2p/base/faketransportcontroller.h
@@ -16,10 +16,6 @@
#include <string>
#include <vector>
-#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 @@
};
} // 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<int>(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<PacketMessageData*>(msg->pdata);
+ dest_->SignalReadPacket(dest_, data->packet.data<char>(),
+ 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 @@
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 @@
// 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 @@
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 4c47a14..e48b36a 100644
--- a/webrtc/p2p/base/icetransportinternal.h
+++ b/webrtc/p2p/base/icetransportinternal.h
@@ -25,11 +25,12 @@
namespace cricket {
-enum class TransportState {
+// 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
@@ -44,9 +45,9 @@
// 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;
@@ -95,6 +96,9 @@
virtual IceGatheringState gathering_state() const = 0;
+ // Returns the current stats for this connection.
+ virtual bool GetStats(ConnectionInfos* infos) = 0;
+
sigslot::signal1<IceTransportInternal*> SignalGatheringState;
// Handles sending and receiving of candidates.
@@ -119,11 +123,20 @@
sigslot::signal4<IceTransportInternal*, CandidatePairInterface*, int, bool>
SignalSelectedCandidatePairChanged;
+ // Invoked when there is conflict in the ICE role between local and remote
+ // agents.
+ sigslot::signal1<IceTransportInternal*> SignalRoleConflict;
+
+ // Emitted whenever the transport state changed.
+ sigslot::signal1<IceTransportInternal*> SignalStateChanged;
+
// Invoked when the transport is being destroyed.
sigslot::signal1<IceTransportInternal*> SignalDestroyed;
// Debugging description of this transport.
- std::string ToString() const;
+ std::string debug_name() const override {
+ return transport_name() + " " + std::to_string(component());
+ }
};
} // namespace cricket
diff --git a/webrtc/p2p/base/jseptransport.h b/webrtc/p2p/base/jseptransport.h
index cc05ec0..44ae049 100644
--- a/webrtc/p2p/base/jseptransport.h
+++ b/webrtc/p2p/base/jseptransport.h
@@ -17,15 +17,15 @@
#include <vector>
#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 {
@@ -335,8 +335,6 @@
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/p2ptransportchannel.cc b/webrtc/p2p/base/p2ptransportchannel.cc
index 5f858c4..517f596 100644
--- a/webrtc/p2p/base/p2ptransportchannel.cc
+++ b/webrtc/p2p/base/p2ptransportchannel.cc
@@ -100,7 +100,8 @@
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),
@@ -271,15 +272,15 @@
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<Connection*> active_connections;
@@ -289,7 +290,7 @@
}
}
if (active_connections.empty()) {
- return TransportChannelState::STATE_FAILED;
+ return IceTransportState::STATE_FAILED;
}
std::set<rtc::Network*> networks;
@@ -301,11 +302,11 @@
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) {
@@ -1399,33 +1400,38 @@
// 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<int>(state_) << " to "
+ << static_cast<int>(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_DCHECK(false);
@@ -1541,8 +1547,8 @@
// 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?
@@ -2022,4 +2028,25 @@
}));
}
+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 e538dc2..2327b2d 100644
--- a/webrtc/p2p/base/p2ptransportchannel.h
+++ b/webrtc/p2p/base/p2ptransportchannel.h
@@ -26,14 +26,14 @@
#include <string>
#include <vector>
+#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 @@
// 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 @@
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 @@
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<int>& 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<rtc::RTCCertificate> GetLocalCertificate() const override {
- return nullptr;
- }
-
- std::unique_ptr<rtc::SSLCertificate> 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<rtc::RTCCertificate>& 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 @@
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 @@
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 @@
: static_cast<uint32_t>(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 @@
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 3a9ec18..7ac70a1 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 @@
};
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<Candidate>& cc)
+ CandidatesData(IceTransportInternal* ch, const std::vector<Candidate>& cc)
: channel(ch), candidates(cc) {}
- TransportChannel* channel;
+ IceTransportInternal* channel;
Candidates candidates;
};
@@ -685,7 +686,7 @@
}
// 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 @@
}
}
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 @@
GetEndpoint(endpoint)->save_candidates_ = true;
}
- void OnCandidatesRemoved(TransportChannelImpl* ch,
+ void OnCandidatesRemoved(IceTransportInternal* ch,
const std::vector<Candidate>& candidates) {
// Candidate removals are not paused.
CandidatesData* candidates_data = new CandidatesData(ch, candidates);
@@ -797,7 +798,7 @@
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 @@
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 @@
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 @@
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<Connection*>& connections = ep2_ch1()->connections();
ASSERT_EQ(2U, connections.size());
Connection* backup_conn = connections[1];
@@ -2682,9 +2684,9 @@
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 @@
// 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 @@
return conn;
}
- int SendData(TransportChannel& channel,
+ int SendData(IceTransportInternal& channel,
const char* data,
size_t len,
int packet_id) {
@@ -3022,7 +3024,7 @@
}
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 @@
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 @@
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 @@
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 @@
// 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 @@
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 @@
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 @@
EXPECT_TRUE_SIMULATED_WAIT(!conn2->active(), kDefaultTimeout, clock);
// |conn2| should not send a ping yet.
EXPECT_EQ(Connection::STATE_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 @@
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/packettransportinterface.h b/webrtc/p2p/base/packettransportinterface.h
index d0665bc..9a2b32a 100644
--- a/webrtc/p2p/base/packettransportinterface.h
+++ b/webrtc/p2p/base/packettransportinterface.h
@@ -31,7 +31,7 @@
virtual ~PacketTransportInterface() {}
// Identify the object for logging and debug purpose.
- virtual const std::string debug_name() const = 0;
+ virtual std::string debug_name() const = 0;
// The transport has been established.
virtual bool writable() const = 0;
diff --git a/webrtc/p2p/base/transportchannel.h b/webrtc/p2p/base/transportchannel.h
index c7c3c75..6415545 100644
--- a/webrtc/p2p/base/transportchannel.h
+++ b/webrtc/p2p/base/transportchannel.h
@@ -15,19 +15,20 @@
#include <string>
#include <vector>
-#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/jseptransport.h"
+#include "webrtc/p2p/base/icetransportinternal.h"
+#include "webrtc/p2p/base/packettransportinterface.h"
+#include "webrtc/p2p/base/transportdescription.h"
namespace cricket {
@@ -40,14 +41,6 @@
// 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,13 +56,13 @@
// 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_; }
int component() const { return component_; }
- const std::string debug_name() const override {
+ std::string debug_name() const override {
return transport_name() + " " + std::to_string(component());
}
diff --git a/webrtc/p2p/base/transportchannelimpl.h b/webrtc/p2p/base/transportchannelimpl.h
index 1d43e54..01af286 100644
--- a/webrtc/p2p/base/transportchannelimpl.h
+++ b/webrtc/p2p/base/transportchannelimpl.h
@@ -14,6 +14,7 @@
#include <string>
#include "webrtc/base/constructormagic.h"
+#include "webrtc/p2p/base/icetransportinternal.h"
#include "webrtc/p2p/base/transportchannel.h"
namespace buzz { class XmlElement; }
@@ -26,12 +27,6 @@
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 4a3a00e..968de0b 100644
--- a/webrtc/p2p/base/transportcontroller.cc
+++ b/webrtc/p2p/base/transportcontroller.cc
@@ -47,7 +47,7 @@
// 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 @@
// 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<TransportChannelImpl> ice_;
+ std::unique_ptr<IceTransportInternal> ice_;
std::unique_ptr<TransportChannelImpl> dtls_;
RTC_DISALLOW_COPY_AND_ASSIGN(ChannelPair);
@@ -243,7 +243,7 @@
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 @@
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::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 @@
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 a46ce00..7929cf0 100644
--- a/webrtc/p2p/base/transportcontroller.h
+++ b/webrtc/p2p/base/transportcontroller.h
@@ -164,13 +164,13 @@
// 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;
diff --git a/webrtc/p2p/base/udptransportchannel.h b/webrtc/p2p/base/udptransportchannel.h
index 2152fb7..cbe2579 100644
--- a/webrtc/p2p/base/udptransportchannel.h
+++ b/webrtc/p2p/base/udptransportchannel.h
@@ -35,7 +35,7 @@
UdpTransportChannel(const std::string& transport_name, rtc::SocketServer* ss);
~UdpTransportChannel();
- const std::string debug_name() const override { return transport_name_; }
+ std::string debug_name() const override { return transport_name_; }
bool receiving() const override {
// TODO(johan): Implement method and signal.