| Index: webrtc/p2p/base/faketransportcontroller.h
|
| diff --git a/webrtc/p2p/base/faketransportcontroller.h b/webrtc/p2p/base/faketransportcontroller.h
|
| index d42a93ddae9f95cf1558f9d32f3273f5e9a113c3..0e2d2113e2ff96fa61895853be4a9ec6f3355d7b 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,10 @@
|
| #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/dtlstransportinternal.h"
|
| +#include "webrtc/p2p/base/icetransportinternal.h"
|
| +#include "webrtc/p2p/base/transportcontroller.h"
|
|
|
| #ifdef HAVE_QUIC
|
| #include "webrtc/p2p/quic/quictransport.h"
|
| @@ -41,44 +41,38 @@ struct PacketMessageData : public rtc::MessageData {
|
| };
|
| } // namespace
|
|
|
| -// 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 FakeIceTransport : public IceTransportInternal,
|
| + public rtc::MessageHandler {
|
| public:
|
| - explicit FakeTransportChannel(const std::string& name, int component)
|
| - : TransportChannelImpl(name, component),
|
| - dtls_fingerprint_("", nullptr, 0) {}
|
| - ~FakeTransportChannel() { Reset(); }
|
| + 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_; }
|
| - const rtc::SSLFingerprint& dtls_fingerprint() const {
|
| - return dtls_fingerprint_;
|
| - }
|
|
|
| // 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; }
|
|
|
| - 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; }
|
| @@ -96,20 +90,6 @@ class FakeTransportChannel : public TransportChannelImpl,
|
| }
|
|
|
| void SetRemoteIceMode(IceMode mode) override { remote_ice_mode_ = mode; }
|
| - 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) {
|
| @@ -135,17 +115,26 @@ 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.
|
| + 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(FakeTransportChannel* dest, bool asymmetric = false) {
|
| + void SetDestination(FakeIceTransport* dest, bool asymmetric = false) {
|
| if (state_ == STATE_INIT && dest) {
|
| // This simulates the delivery of candidates.
|
| dest_ = dest;
|
| - if (local_cert_ && dest_->local_cert_) {
|
| - do_dtls_ = true;
|
| - NegotiateSrtpCiphers();
|
| - }
|
| state_ = STATE_CONNECTED;
|
| set_writable(true);
|
| if (!asymmetric) {
|
| @@ -179,6 +168,15 @@ class FakeTransportChannel : public TransportChannelImpl,
|
|
|
| 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; }
|
| @@ -230,6 +228,190 @@ class FakeTransportChannel : public TransportChannelImpl,
|
| 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;
|
| +};
|
| +
|
| +class FakeDtlsTransport : public DtlsTransportInternal {
|
| + public:
|
| + 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);
|
| + }
|
| +
|
| + explicit FakeDtlsTransport(const std::string& name, int component)
|
| + : ice_transport_(new FakeIceTransport(name, component)),
|
| + transport_name_(ice_transport_->transport_name()),
|
| + component_(ice_transport_->component()),
|
| + dtls_fingerprint_("", nullptr, 0) {
|
| + ice_transport_->SignalReadPacket.connect(
|
| + this, &FakeDtlsTransport::OnIceTransportReadPacket);
|
| + }
|
| +
|
| + ~FakeDtlsTransport() override { Reset(); }
|
| +
|
| + 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();
|
| + }
|
| +
|
| + DtlsTransportState dtls_state() const override { return dtls_state_; }
|
| +
|
| + const std::string& transport_name() const override { return transport_name_; }
|
| +
|
| + int component() const override { return component_; }
|
| +
|
| + const rtc::SSLFingerprint& dtls_fingerprint() const {
|
| + return dtls_fingerprint_;
|
| + }
|
| +
|
| + // 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;
|
| + }
|
| +
|
| + IceGatheringState gathering_state() const {
|
| + return ice_transport_->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); }
|
| +
|
| + // Simulates the two transport channels connecting to each other.
|
| + // If |asymmetric| is true this method only affects this FakeDtlsTransport.
|
| + // If false, it affects |dest| as well.
|
| + void SetDestination(FakeDtlsTransport* dest, bool asymmetric = false) {
|
| + if (state_ == STATE_INIT && dest) {
|
| + // This simulates the delivery of candidates.
|
| + dest_ = dest;
|
| + if (local_cert_ && dest_->local_cert_) {
|
| + do_dtls_ = true;
|
| + NegotiateSrtpCiphers();
|
| + }
|
| + state_ = STATE_CONNECTED;
|
| + 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;
|
| + SetWritable(false);
|
| + ice_transport_->SetDestination(nullptr, asymmetric);
|
| + }
|
| + }
|
| +
|
| + void SetConnectionCount(size_t connection_count) {
|
| + ice_transport_->SetConnectionCount(connection_count);
|
| + }
|
| +
|
| + void SetCandidatesGatheringComplete() {
|
| + ice_transport_->SetCandidatesGatheringComplete();
|
| + }
|
| +
|
| + void SetReceiving(bool receiving) {
|
| + ice_transport_->SetReceiving(receiving);
|
| + set_receiving(receiving);
|
| + }
|
| +
|
| + 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 {
|
| + return ice_transport_->SendPacket(data, len, options, flags);
|
| + }
|
| +
|
| + bool GetOption(rtc::Socket::Option opt, int* value) override { return true; }
|
| +
|
| + const Candidates& remote_candidates() const {
|
| + return ice_transport_->remote_candidates();
|
| + }
|
| +
|
| + void OnIceTransportReadPacket(PacketTransportInterface* ice_,
|
| + const char* data,
|
| + size_t len,
|
| + const rtc::PacketTime& time,
|
| + int flags) {
|
| + SignalReadPacket(this, data, len, time, flags);
|
| + }
|
| +
|
| bool SetLocalCertificate(
|
| const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override {
|
| local_cert_ = certificate;
|
| @@ -282,13 +464,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;
|
| }
|
| @@ -296,7 +471,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:
|
| @@ -313,31 +505,45 @@ 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::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
|
| @@ -392,10 +598,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));
|
| }
|
|
|
| @@ -447,24 +652,24 @@ 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;
|
| + return new FakeIceTransport(transport_name, component);
|
| }
|
|
|
| - TransportChannelImpl* CreateDtlsTransportChannel_n(
|
| + DtlsTransportInternal* CreateDtlsTransportChannel_n(
|
| const std::string& transport_name,
|
| int component,
|
| - TransportChannelImpl*) 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;
|
|
|