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

Unified Diff: webrtc/p2p/base/faketransportcontroller.h

Issue 2606123002: Remove the dependency of TransportChannel and TransportChannelImpl. (Closed)
Patch Set: Fix the memory leak. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/p2p/base/dtlstransportinternal.h ('k') | webrtc/p2p/base/icetransportinternal.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/p2p/base/faketransportcontroller.h
diff --git a/webrtc/p2p/base/faketransportcontroller.h b/webrtc/p2p/base/faketransportcontroller.h
index a73d464ece548bc05d3b0b1fcaf0cac7c24dfc0e..fd476829c41d05491094e5b184d623d9ca0c05bb 100644
--- a/webrtc/p2p/base/faketransportcontroller.h
+++ b/webrtc/p2p/base/faketransportcontroller.h
@@ -24,9 +24,9 @@
#include "webrtc/base/sslfingerprint.h"
#include "webrtc/base/thread.h"
#include "webrtc/p2p/base/candidatepairinterface.h"
+#include "webrtc/p2p/base/dtlstransportinternal.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
@@ -263,85 +263,78 @@ class FakeIceTransport : public IceTransportInternal,
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.
-// TODO(hbos): Move implementation to .cc file, this and other classes in file.
-class FakeTransportChannel : public TransportChannelImpl,
- public rtc::MessageHandler {
+class FakeDtlsTransport : public DtlsTransportInternal {
public:
- explicit FakeTransportChannel(const std::string& name, int component)
- : TransportChannelImpl(name, component),
- dtls_fingerprint_("", nullptr, 0) {}
- ~FakeTransportChannel() { Reset(); }
+ explicit FakeDtlsTransport(FakeIceTransport* ice_transport)
+ : ice_transport_(ice_transport),
+ transport_name_(ice_transport->transport_name()),
+ component_(ice_transport->component()),
+ dtls_fingerprint_("", nullptr, 0) {
+ ice_transport_->SignalReadPacket.connect(
+ this, &FakeDtlsTransport::OnIceTransportReadPacket);
+ }
- 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_; }
- const rtc::SSLFingerprint& dtls_fingerprint() const {
- return dtls_fingerprint_;
+ // If this constructor is called, a new fake ice transport will be created,
+ // and this FakeDtlsTransport will take the ownership.
+ explicit FakeDtlsTransport(const std::string& name, int component)
+ : owned_ice_transport_(new FakeIceTransport(name, component)),
+ transport_name_(owned_ice_transport_->transport_name()),
+ component_(owned_ice_transport_->component()),
+ dtls_fingerprint_("", nullptr, 0) {
+ ice_transport_ = owned_ice_transport_.get();
+ ice_transport_->SignalReadPacket.connect(
+ this, &FakeDtlsTransport::OnIceTransportReadPacket);
}
- // 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; }
+ ~FakeDtlsTransport() override { Reset(); }
- IceTransportState GetState() const override {
- if (connection_count_ == 0) {
- return had_connection_ ? IceTransportState::STATE_FAILED
- : IceTransportState::STATE_INIT;
- }
+ uint64_t IceTiebreaker() const { return ice_transport_->IceTiebreaker(); }
+ IceMode remote_ice_mode() const { return ice_transport_->remote_ice_mode(); }
+ const std::string& ice_ufrag() const { return ice_transport_->ice_ufrag(); }
+ const std::string& ice_pwd() const { return ice_transport_->ice_pwd(); }
+ const std::string& remote_ice_ufrag() const {
+ return ice_transport_->remote_ice_ufrag();
+ }
+ const std::string& remote_ice_pwd() const {
+ return ice_transport_->remote_ice_pwd();
+ }
- if (connection_count_ == 1) {
- return IceTransportState::STATE_COMPLETED;
- }
+ DtlsTransportState dtls_state() const override { return dtls_state_; }
- return IceTransportState::STATE_CONNECTING;
- }
+ const std::string& transport_name() const override { return transport_name_; }
- 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;
+ int component() const override { return component_; }
+
+ const rtc::SSLFingerprint& dtls_fingerprint() const {
+ return dtls_fingerprint_;
}
- void SetRemoteIceMode(IceMode mode) override { remote_ice_mode_ = mode; }
+ // If async, will send packets by "Post"-ing to message queue instead of
+ // synchronously "Send"-ing.
+ void SetAsync(bool async) { ice_transport_->SetAsync(async); }
+ void SetAsyncDelay(int delay_ms) { ice_transport_->SetAsyncDelay(delay_ms); }
+
+ IceRole GetIceRole() const { return ice_transport_->GetIceRole(); }
+
bool SetRemoteFingerprint(const std::string& alg,
const uint8_t* digest,
size_t digest_len) override {
dtls_fingerprint_ = rtc::SSLFingerprint(alg, digest, digest_len);
return true;
}
+
bool SetSslRole(rtc::SSLRole role) override {
ssl_role_ = role;
return true;
}
+
bool GetSslRole(rtc::SSLRole* role) const override {
*role = ssl_role_;
return true;
}
- void MaybeStartGathering() override {
- if (gathering_state_ == kIceGatheringNew) {
- gathering_state_ = kIceGatheringGathering;
- SignalGatheringState(this);
- }
- }
-
- IceGatheringState gathering_state() const override {
- return gathering_state_;
+ IceGatheringState gathering_state() const {
+ return ice_transport_->gathering_state();
}
void Reset() {
@@ -358,9 +351,9 @@ class FakeTransportChannel : public TransportChannelImpl,
void SetWritable(bool writable) { set_writable(writable); }
// Simulates the two transport channels connecting to each other.
- // If |asymmetric| is true this method only affects this FakeTransportChannel.
+ // If |asymmetric| is true this method only affects this FakeDtlsTransport.
// If false, it affects |dest| as well.
- void SetDestination(FakeTransportChannel* dest, bool asymmetric = false) {
+ void SetDestination(FakeDtlsTransport* dest, bool asymmetric = false) {
if (state_ == STATE_INIT && dest) {
// This simulates the delivery of candidates.
dest_ = dest;
@@ -369,87 +362,58 @@ class FakeTransportChannel : public TransportChannelImpl,
NegotiateSrtpCiphers();
}
state_ = STATE_CONNECTED;
- set_writable(true);
+ SetWritable(true);
if (!asymmetric) {
dest->SetDestination(this, true);
}
+ ice_transport_->SetDestination(
+ static_cast<FakeIceTransport*>(dest->ice_transport()), asymmetric);
} else if (state_ == STATE_CONNECTED && !dest) {
// Simulates loss of connectivity, by asymmetrically forgetting dest_.
dest_ = nullptr;
state_ = STATE_INIT;
- set_writable(false);
+ SetWritable(false);
+ ice_transport_->SetDestination(nullptr, asymmetric);
}
}
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);
+ ice_transport_->SetConnectionCount(connection_count);
}
void SetCandidatesGatheringComplete() {
- if (gathering_state_ != kIceGatheringComplete) {
- gathering_state_ = kIceGatheringComplete;
- SignalGatheringState(this);
- }
+ ice_transport_->SetCandidatesGatheringComplete();
}
- void SetReceiving(bool receiving) { set_receiving(receiving); }
-
- void SetIceConfig(const IceConfig& config) override { ice_config_ = config; }
+ void SetReceiving(bool receiving) {
+ ice_transport_->SetReceiving(receiving);
+ set_receiving(receiving);
+ }
- int receiving_timeout() const { return ice_config_.receiving_timeout; }
- bool gather_continually() const { return ice_config_.gather_continually(); }
+ int receiving_timeout() const { return ice_transport_->receiving_timeout(); }
+ bool gather_continually() const {
+ return ice_transport_->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);
+ return ice_transport_->SendPacket(data, len, options, flags);
}
- 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);
+ const Candidates& remote_candidates() const {
+ return ice_transport_->remote_candidates();
}
- 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;
+ void OnIceTransportReadPacket(PacketTransportInterface* ice_,
+ const char* data,
+ size_t len,
+ const rtc::PacketTime& time,
+ int flags) {
+ SignalReadPacket(this, data, len, time, flags);
}
bool SetLocalCertificate(
@@ -504,13 +468,6 @@ class FakeTransportChannel : public TransportChannelImpl,
return false;
}
- bool GetStats(ConnectionInfos* infos) override {
- ConnectionInfo info;
- infos->clear();
- infos->push_back(info);
- return true;
- }
-
void set_ssl_max_protocol_version(rtc::SSLProtocolVersion version) {
ssl_max_version_ = version;
}
@@ -518,7 +475,24 @@ class FakeTransportChannel : public TransportChannelImpl,
return ssl_max_version_;
}
- void SetMetricsObserver(webrtc::MetricsObserverInterface* observer) override {
+ IceTransportInternal* ice_transport() override { return ice_transport_; }
+
+ bool writable() const override { return writable_; }
+
+ bool receiving() const override { return receiving_; }
+
+ int GetError() override { return ice_transport_->GetError(); }
+
+ int SetOption(rtc::Socket::Option opt, int value) override {
+ return ice_transport_->SetOption(opt, value);
+ }
+
+ bool SetSrtpCiphers(const std::vector<std::string>& ciphers) override {
+ std::vector<int> crypto_suites;
+ for (const auto cipher : ciphers) {
+ crypto_suites.push_back(rtc::SrtpCryptoSuiteFromName(cipher));
+ }
+ return SetSrtpCryptoSuites(crypto_suites);
}
private:
@@ -535,31 +509,46 @@ class FakeTransportChannel : public TransportChannelImpl,
}
}
+ void set_receiving(bool receiving) {
+ if (receiving_ == receiving) {
+ return;
+ }
+ receiving_ = receiving;
+ SignalReceivingState(this);
+ }
+
+ void set_writable(bool writable) {
+ if (writable_ == writable) {
+ return;
+ }
+ writable_ = writable;
+ if (writable_) {
+ SignalReadyToSend(this);
+ }
+ SignalWritableState(this);
+ }
+
enum State { STATE_INIT, STATE_CONNECTED };
- FakeTransportChannel* dest_ = nullptr;
+ FakeIceTransport* ice_transport_;
+ std::unique_ptr<FakeIceTransport> owned_ice_transport_;
+ std::string transport_name_;
+ int component_;
+ FakeDtlsTransport* dest_ = nullptr;
State state_ = STATE_INIT;
- bool async_ = false;
- int async_delay_ms_ = 0;
Candidates remote_candidates_;
rtc::scoped_refptr<rtc::RTCCertificate> local_cert_;
rtc::FakeSSLCertificate* remote_cert_ = nullptr;
bool do_dtls_ = false;
std::vector<int> srtp_ciphers_;
int chosen_crypto_suite_ = rtc::SRTP_INVALID_CRYPTO_SUITE;
- 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;
rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12;
rtc::SSLFingerprint dtls_fingerprint_;
rtc::SSLRole ssl_role_ = rtc::SSL_CLIENT;
- size_t connection_count_ = 0;
- IceGatheringState gathering_state_ = kIceGatheringNew;
- bool had_connection_ = false;
+
+ DtlsTransportState dtls_state_ = DTLS_TRANSPORT_NEW;
+
+ bool receiving_ = false;
+ bool writable_ = false;
};
// Fake candidate pair class, which can be passed to BaseChannel for testing
@@ -614,10 +603,9 @@ class FakeTransportController : public TransportController {
SetIceRole(role);
}
- FakeTransportChannel* GetFakeTransportChannel_n(
- const std::string& transport_name,
- int component) {
- return static_cast<FakeTransportChannel*>(
+ FakeDtlsTransport* GetFakeDtlsTransport_n(const std::string& transport_name,
+ int component) {
+ return static_cast<FakeDtlsTransport*>(
get_channel_for_testing(transport_name, component));
}
@@ -666,8 +654,8 @@ class FakeTransportController : public TransportController {
}
void DestroyRtcpTransport(const std::string& transport_name) {
- DestroyTransportChannel_n(transport_name,
- cricket::ICE_CANDIDATE_COMPONENT_RTCP);
+ DestroyDtlsTransport_n(transport_name,
+ cricket::ICE_CANDIDATE_COMPONENT_RTCP);
}
protected:
@@ -677,21 +665,21 @@ class FakeTransportController : public TransportController {
IceTransportInternal* CreateIceTransportChannel_n(
const std::string& transport_name,
int component) override {
- return nullptr;
+ return new FakeIceTransport(transport_name, component);
}
- TransportChannelImpl* CreateDtlsTransportChannel_n(
+ DtlsTransportInternal* CreateDtlsTransportChannel_n(
const std::string& transport_name,
int component,
- IceTransportInternal*) override {
- return new FakeTransportChannel(transport_name, component);
+ IceTransportInternal* ice) override {
+ return new FakeDtlsTransport(static_cast<FakeIceTransport*>(ice));
}
private:
void SetChannelDestinations_n(FakeTransportController* dest) {
- for (TransportChannelImpl* tc : channels_for_testing()) {
- FakeTransportChannel* local = static_cast<FakeTransportChannel*>(tc);
- FakeTransportChannel* remote = dest->GetFakeTransportChannel_n(
+ for (DtlsTransportInternal* tc : channels_for_testing()) {
+ FakeDtlsTransport* local = static_cast<FakeDtlsTransport*>(tc);
+ FakeDtlsTransport* remote = dest->GetFakeDtlsTransport_n(
local->transport_name(), local->component());
if (remote) {
bool asymmetric = false;
« no previous file with comments | « webrtc/p2p/base/dtlstransportinternal.h ('k') | webrtc/p2p/base/icetransportinternal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698