| Index: webrtc/p2p/base/transportcontroller.h
|
| diff --git a/webrtc/p2p/base/transportcontroller.h b/webrtc/p2p/base/transportcontroller.h
|
| index a408421ffbddeeb6b60c41adc992b906d03231c2..cdac4b6dcb5e72a08761a593b02d2f5fae9812c5 100644
|
| --- a/webrtc/p2p/base/transportcontroller.h
|
| +++ b/webrtc/p2p/base/transportcontroller.h
|
| @@ -20,7 +20,9 @@
|
| #include "webrtc/base/sigslot.h"
|
| #include "webrtc/base/sslstreamadapter.h"
|
| #include "webrtc/p2p/base/candidate.h"
|
| -#include "webrtc/p2p/base/transport.h"
|
| +#include "webrtc/p2p/base/dtlstransportchannel.h"
|
| +#include "webrtc/p2p/base/jseptransport.h"
|
| +#include "webrtc/p2p/base/p2ptransportchannel.h"
|
|
|
| namespace rtc {
|
| class Thread;
|
| @@ -62,7 +64,7 @@ class TransportController : public sigslot::has_slots<>,
|
| void SetIceConfig(const IceConfig& config);
|
| void SetIceRole(IceRole ice_role);
|
|
|
| - bool GetSslRole(const std::string& transport_name, rtc::SSLRole* role);
|
| + bool GetSslRole(const std::string& transport_name, rtc::SSLRole* role) const;
|
|
|
| // Specifies the identity to use in this session.
|
| // Can only be called once.
|
| @@ -70,10 +72,11 @@ class TransportController : public sigslot::has_slots<>,
|
| const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
|
| bool GetLocalCertificate(
|
| const std::string& transport_name,
|
| - rtc::scoped_refptr<rtc::RTCCertificate>* certificate);
|
| - // Caller owns returned certificate
|
| + rtc::scoped_refptr<rtc::RTCCertificate>* certificate) const;
|
| + // Caller owns returned certificate. This method mainly exists for stats
|
| + // reporting.
|
| std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate(
|
| - const std::string& transport_name);
|
| + const std::string& transport_name) const;
|
| bool SetLocalTransportDescription(const std::string& transport_name,
|
| const TransportDescription& tdesc,
|
| ContentAction action,
|
| @@ -89,8 +92,12 @@ class TransportController : public sigslot::has_slots<>,
|
| const Candidates& candidates,
|
| std::string* err);
|
| bool RemoveRemoteCandidates(const Candidates& candidates, std::string* err);
|
| - bool ReadyForRemoteCandidates(const std::string& transport_name);
|
| + bool ReadyForRemoteCandidates(const std::string& transport_name) const;
|
| + // TODO(deadbeef): GetStats isn't const because all the way down to
|
| + // OpenSSLStreamAdapter,
|
| + // GetSslCipherSuite and GetDtlsSrtpCryptoSuite are not const. Fix this.
|
| bool GetStats(const std::string& transport_name, TransportStats* stats);
|
| + void SetMetricsObserver(webrtc::MetricsObserverInterface* metrics_observer);
|
|
|
| // Creates a channel if it doesn't exist. Otherwise, increments a reference
|
| // count and returns an existing channel.
|
| @@ -106,6 +113,17 @@ class TransportController : public sigslot::has_slots<>,
|
| void use_quic() { quic_ = true; }
|
| bool quic() const { return quic_; }
|
|
|
| + // TODO(deadbeef): Remove all for_testing methods!
|
| + const rtc::scoped_refptr<rtc::RTCCertificate>& certificate_for_testing()
|
| + const {
|
| + return certificate_;
|
| + }
|
| + std::vector<std::string> transport_names_for_testing();
|
| + std::vector<TransportChannelImpl*> channels_for_testing();
|
| + TransportChannelImpl* get_channel_for_testing(
|
| + const std::string& transport_name,
|
| + int component);
|
| +
|
| // All of these signals are fired on the signalling thread.
|
|
|
| // If any transport failed => failed,
|
| @@ -128,31 +146,33 @@ class TransportController : public sigslot::has_slots<>,
|
|
|
| sigslot::signal1<const Candidates&> SignalCandidatesRemoved;
|
|
|
| - // for unit test
|
| - const rtc::scoped_refptr<rtc::RTCCertificate>& certificate_for_testing();
|
| -
|
| sigslot::signal1<rtc::SSLHandshakeError> SignalDtlsHandshakeError;
|
|
|
| - void SetMetricsObserver(webrtc::MetricsObserverInterface* metrics_observer);
|
| -
|
| protected:
|
| - // Protected and virtual so we can override it in unit tests.
|
| - virtual Transport* CreateTransport_n(const std::string& transport_name);
|
| -
|
| - // For unit tests
|
| - const std::map<std::string, Transport*>& transports() { return transports_; }
|
| - Transport* GetTransport_n(const std::string& transport_name);
|
| + // 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(
|
| + const std::string& transport_name,
|
| + int component);
|
| + virtual TransportChannelImpl* CreateDtlsTransportChannel_n(
|
| + const std::string& transport_name,
|
| + int component,
|
| + TransportChannelImpl* ice);
|
|
|
| private:
|
| void OnMessage(rtc::Message* pmsg) override;
|
|
|
| - // It's the Transport that's currently responsible for creating/destroying
|
| - // channels, but the TransportController keeps track of how many external
|
| - // objects (BaseChannels) reference each channel.
|
| + // This structure groups the DTLS and ICE channels, and helps keep track of
|
| + // how many external objects (BaseChannels) reference each channel.
|
| struct RefCountedChannel {
|
| - RefCountedChannel() : impl_(nullptr), ref_(0) {}
|
| - explicit RefCountedChannel(TransportChannelImpl* impl)
|
| - : impl_(impl), ref_(0) {}
|
| + RefCountedChannel() = default;
|
| + // TODO(deadbeef): Change the types of |dtls| and |ice| to
|
| + // DtlsTransportChannelWrapper and P2PTransportChannelWrapper,
|
| + // once TransportChannelImpl is removed.
|
| + explicit RefCountedChannel(TransportChannelImpl* dtls,
|
| + TransportChannelImpl* ice)
|
| + : ice_(ice), dtls_(dtls), ref_(0) {}
|
|
|
| void AddRef() { ++ref_; }
|
| void DecRef() {
|
| @@ -161,33 +181,51 @@ class TransportController : public sigslot::has_slots<>,
|
| }
|
| int ref() const { return ref_; }
|
|
|
| - TransportChannelImpl* get() const { return impl_; }
|
| - TransportChannelImpl* operator->() const { return impl_; }
|
| + // Currently, all ICE-related calls still go through this DTLS channel. But
|
| + // that will change once we get rid of TransportChannelImpl, and the DTLS
|
| + // 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(); }
|
|
|
| private:
|
| - TransportChannelImpl* impl_;
|
| - int ref_;
|
| + std::unique_ptr<TransportChannelImpl> ice_;
|
| + std::unique_ptr<TransportChannelImpl> dtls_;
|
| + int ref_ = 0;
|
| };
|
|
|
| - std::vector<RefCountedChannel>::iterator FindChannel_n(
|
| + // Helper functions to get a channel or transport, or iterator to it (in case
|
| + // it needs to be erased).
|
| + std::vector<RefCountedChannel>::iterator GetChannelIterator_n(
|
| const std::string& transport_name,
|
| int component);
|
| -
|
| - Transport* GetOrCreateTransport_n(const std::string& transport_name);
|
| - void DestroyTransport_n(const std::string& transport_name);
|
| - void DestroyAllTransports_n();
|
| + std::vector<RefCountedChannel>::const_iterator GetChannelIterator_n(
|
| + const std::string& transport_name,
|
| + int component) const;
|
| + const JsepTransport* GetJsepTransport_n(
|
| + const std::string& transport_name) const;
|
| + JsepTransport* GetJsepTransport_n(const std::string& transport_name);
|
| + const RefCountedChannel* GetChannel_n(const std::string& transport_name,
|
| + int component) const;
|
| + RefCountedChannel* GetChannel_n(const std::string& transport_name,
|
| + int component);
|
| +
|
| + JsepTransport* GetOrCreateJsepTransport_n(const std::string& transport_name);
|
| + void DestroyAllChannels_n();
|
|
|
| bool SetSslMaxProtocolVersion_n(rtc::SSLProtocolVersion version);
|
| void SetIceConfig_n(const IceConfig& config);
|
| void SetIceRole_n(IceRole ice_role);
|
| - bool GetSslRole_n(const std::string& transport_name, rtc::SSLRole* role);
|
| + bool GetSslRole_n(const std::string& transport_name,
|
| + rtc::SSLRole* role) const;
|
| bool SetLocalCertificate_n(
|
| const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
|
| bool GetLocalCertificate_n(
|
| const std::string& transport_name,
|
| - rtc::scoped_refptr<rtc::RTCCertificate>* certificate);
|
| + rtc::scoped_refptr<rtc::RTCCertificate>* certificate) const;
|
| std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate_n(
|
| - const std::string& transport_name);
|
| + const std::string& transport_name) const;
|
| bool SetLocalTransportDescription_n(const std::string& transport_name,
|
| const TransportDescription& tdesc,
|
| ContentAction action,
|
| @@ -201,8 +239,9 @@ class TransportController : public sigslot::has_slots<>,
|
| const Candidates& candidates,
|
| std::string* err);
|
| bool RemoveRemoteCandidates_n(const Candidates& candidates, std::string* err);
|
| - bool ReadyForRemoteCandidates_n(const std::string& transport_name);
|
| + bool ReadyForRemoteCandidates_n(const std::string& transport_name) const;
|
| bool GetStats_n(const std::string& transport_name, TransportStats* stats);
|
| + void SetMetricsObserver_n(webrtc::MetricsObserverInterface* metrics_observer);
|
|
|
| // Handlers for signals from Transport.
|
| void OnChannelWritableState_n(rtc::PacketTransportInterface* transport);
|
| @@ -222,24 +261,21 @@ class TransportController : public sigslot::has_slots<>,
|
|
|
| rtc::Thread* const signaling_thread_ = nullptr;
|
| rtc::Thread* const network_thread_ = nullptr;
|
| - typedef std::map<std::string, Transport*> TransportMap;
|
| - TransportMap transports_;
|
| + PortAllocator* const port_allocator_ = nullptr;
|
|
|
| + std::map<std::string, std::unique_ptr<JsepTransport>> transports_;
|
| std::vector<RefCountedChannel> channels_;
|
|
|
| - PortAllocator* const port_allocator_ = nullptr;
|
| - rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12;
|
| -
|
| // Aggregate state for TransportChannelImpls.
|
| IceConnectionState connection_state_ = kIceConnectionConnecting;
|
| bool receiving_ = false;
|
| IceGatheringState gathering_state_ = kIceGatheringNew;
|
|
|
| - // TODO(deadbeef): Move the fields below down to the transports themselves
|
| IceConfig ice_config_;
|
| IceRole ice_role_ = ICEROLE_CONTROLLING;
|
| bool redetermine_role_on_ice_restart_;
|
| uint64_t ice_tiebreaker_ = rtc::CreateRandomId64();
|
| + rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12;
|
| rtc::scoped_refptr<rtc::RTCCertificate> certificate_;
|
| rtc::AsyncInvoker invoker_;
|
| // True if QUIC is used instead of DTLS.
|
|
|