| Index: webrtc/p2p/base/dtlstransportchannel.h
|
| diff --git a/webrtc/p2p/base/dtlstransportchannel.h b/webrtc/p2p/base/dtlstransportchannel.h
|
| index a8d5d5bcfab720080f91830ab407a5f073724d13..0ab9a9270371e8677943a56268782c73896be2e4 100644
|
| --- a/webrtc/p2p/base/dtlstransportchannel.h
|
| +++ b/webrtc/p2p/base/dtlstransportchannel.h
|
| @@ -20,8 +20,8 @@
|
| #include "webrtc/base/constructormagic.h"
|
| #include "webrtc/base/sslstreamadapter.h"
|
| #include "webrtc/base/stream.h"
|
| +#include "webrtc/p2p/base/dtlstransportinternal.h"
|
| #include "webrtc/p2p/base/icetransportinternal.h"
|
| -#include "webrtc/p2p/base/transportchannelimpl.h"
|
|
|
| namespace rtc {
|
| class PacketTransportInterface;
|
| @@ -33,7 +33,7 @@ namespace cricket {
|
| // the bottom and a StreamInterface on the top.
|
| class StreamInterfaceChannel : public rtc::StreamInterface {
|
| public:
|
| - explicit StreamInterfaceChannel(IceTransportInternal* channel);
|
| + explicit StreamInterfaceChannel(IceTransportInternal* ice_transport);
|
|
|
| // Push in a packet; this gets pulled out from Read().
|
| bool OnPacketReceived(const char* data, size_t size);
|
| @@ -51,7 +51,7 @@ class StreamInterfaceChannel : public rtc::StreamInterface {
|
| int* error) override;
|
|
|
| private:
|
| - IceTransportInternal* channel_; // owned by DtlsTransportChannelWrapper
|
| + IceTransportInternal* ice_transport_; // owned by DtlsTransport
|
| rtc::StreamState state_;
|
| rtc::BufferQueue packets_;
|
|
|
| @@ -64,36 +64,43 @@ class StreamInterfaceChannel : public rtc::StreamInterface {
|
| // (e.g a P2PTransportChannel)
|
| // Here's the way this works:
|
| //
|
| -// DtlsTransportChannelWrapper {
|
| +// DtlsTransport {
|
| // SSLStreamAdapter* dtls_ {
|
| // StreamInterfaceChannel downward_ {
|
| -// TransportChannelImpl* channel_;
|
| +// IceTransportInternal* ice_transport_;
|
| // }
|
| // }
|
| // }
|
| //
|
| -// - Data which comes into DtlsTransportChannelWrapper from the underlying
|
| -// channel_ via OnReadPacket() is checked for whether it is DTLS
|
| -// or not, and if it is, is passed to DtlsTransportChannelWrapper::
|
| -// HandleDtlsPacket, which pushes it into to downward_.
|
| -// dtls_ is listening for events on downward_, so it immediately calls
|
| -// downward_->Read().
|
| +// - Data which comes into DtlsTransport from the underlying
|
| +// ice_transport_ via OnReadPacket() is checked for whether it is DTLS
|
| +// or not, and if it is, is passed to DtlsTransport::HandleDtlsPacket,
|
| +// which pushes it into to downward_. dtls_ is listening for events on
|
| +// downward_, so it immediately calls downward_->Read().
|
| //
|
| -// - Data written to DtlsTransportChannelWrapper is passed either to
|
| -// downward_ or directly to channel_, depending on whether DTLS is
|
| -// negotiated and whether the flags include PF_SRTP_BYPASS
|
| +// - Data written to DtlsTransport is passed either to downward_ or directly
|
| +// to ice_transport_, depending on whether DTLS is negotiated and whether
|
| +// the flags include PF_SRTP_BYPASS
|
| //
|
| -// - The SSLStreamAdapter writes to downward_->Write()
|
| -// which translates it into packet writes on channel_.
|
| -class DtlsTransportChannelWrapper : public TransportChannelImpl {
|
| +// - The SSLStreamAdapter writes to downward_->Write() which translates it
|
| +// into packet writes on ice_transport_.
|
| +class DtlsTransport : public DtlsTransportInternal {
|
| public:
|
| - // The parameters here are:
|
| - // channel -- the TransportChannel we are wrapping
|
| - explicit DtlsTransportChannelWrapper(IceTransportInternal* channel);
|
| - ~DtlsTransportChannelWrapper() override;
|
| + // The parameters here is:
|
| + // ice_transport -- the ice transport we are wrapping
|
| + explicit DtlsTransport(IceTransportInternal* ice_transport);
|
| + ~DtlsTransport() override;
|
| +
|
| + DtlsTransportState dtls_state() const override { return dtls_state_; }
|
| +
|
| + const std::string& transport_name() const override { return transport_name_; }
|
| +
|
| + int component() const override { return component_; }
|
| +
|
| + // Returns false if no local certificate was set, or if the peer doesn't
|
| + // support DTLS.
|
| + bool IsDtlsActive() const override { return dtls_active_; }
|
|
|
| - void SetIceRole(IceRole role) override { channel_->SetIceRole(role); }
|
| - IceRole GetIceRole() const override { return channel_->GetIceRole(); }
|
| bool SetLocalCertificate(
|
| const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override;
|
| rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate() const override;
|
| @@ -102,9 +109,6 @@ class DtlsTransportChannelWrapper : public TransportChannelImpl {
|
| const uint8_t* digest,
|
| size_t digest_len) override;
|
|
|
| - // Returns false if no local certificate was set, or if the peer doesn't
|
| - // support DTLS.
|
| - bool IsDtlsActive() const override { return dtls_active_; }
|
|
|
| // Called to send a packet (via DTLS, if turned on).
|
| int SendPacket(const char* data,
|
| @@ -112,16 +116,8 @@ class DtlsTransportChannelWrapper : public TransportChannelImpl {
|
| const rtc::PacketOptions& options,
|
| int flags) override;
|
|
|
| - // TransportChannel calls that we forward to the wrapped transport.
|
| - int SetOption(rtc::Socket::Option opt, int value) override {
|
| - return channel_->SetOption(opt, value);
|
| - }
|
| bool GetOption(rtc::Socket::Option opt, int* value) override {
|
| - return channel_->GetOption(opt, value);
|
| - }
|
| - int GetError() override { return channel_->GetError(); }
|
| - bool GetStats(ConnectionInfos* infos) override {
|
| - return channel_->GetStats(infos);
|
| + return ice_transport_->GetOption(opt, value);
|
| }
|
|
|
| virtual bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version);
|
| @@ -144,9 +140,9 @@ class DtlsTransportChannelWrapper : public TransportChannelImpl {
|
| // use by the remote peer, for use in external identity verification.
|
| std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate() const override;
|
|
|
| - // Once DTLS has established (i.e., this channel is writable), this method
|
| - // extracts the keys negotiated during the DTLS handshake, for use in external
|
| - // encryption. DTLS-SRTP uses this to extract the needed SRTP keys.
|
| + // Once DTLS has established (i.e., this ice_transport is writable), this
|
| + // method extracts the keys negotiated during the DTLS handshake, for use in
|
| + // external encryption. DTLS-SRTP uses this to extract the needed SRTP keys.
|
| // See the SSLStreamAdapter documentation for info on the specific parameters.
|
| bool ExportKeyingMaterial(const std::string& label,
|
| const uint8_t* context,
|
| @@ -161,49 +157,39 @@ class DtlsTransportChannelWrapper : public TransportChannelImpl {
|
| : false;
|
| }
|
|
|
| - // TransportChannelImpl calls.
|
| - IceTransportState GetState() const override { return channel_->GetState(); }
|
| - void SetIceTiebreaker(uint64_t tiebreaker) override {
|
| - channel_->SetIceTiebreaker(tiebreaker);
|
| - }
|
| - void SetIceParameters(const IceParameters& ice_params) override {
|
| - channel_->SetIceParameters(ice_params);
|
| - }
|
| - void SetRemoteIceParameters(const IceParameters& ice_params) override {
|
| - channel_->SetRemoteIceParameters(ice_params);
|
| - }
|
| - void SetRemoteIceMode(IceMode mode) override {
|
| - channel_->SetRemoteIceMode(mode);
|
| - }
|
| + IceTransportInternal* ice_transport() override { return ice_transport_; }
|
|
|
| - void MaybeStartGathering() override { channel_->MaybeStartGathering(); }
|
| + // For informational purposes. Tells if the DTLS handshake has finished.
|
| + // This may be true even if writable() is false, if the remote fingerprint
|
| + // has not yet been verified.
|
| + bool IsDtlsConnected();
|
|
|
| - IceGatheringState gathering_state() const override {
|
| - return channel_->gathering_state();
|
| - }
|
| + bool receiving() const override { return receiving_; }
|
|
|
| - void AddRemoteCandidate(const Candidate& candidate) override {
|
| - channel_->AddRemoteCandidate(candidate);
|
| - }
|
| - void RemoveRemoteCandidate(const Candidate& candidate) override {
|
| - channel_->RemoveRemoteCandidate(candidate);
|
| - }
|
| + bool writable() const override { return writable_; }
|
|
|
| - void SetMetricsObserver(webrtc::MetricsObserverInterface* observer) override {
|
| - channel_->SetMetricsObserver(observer);
|
| - }
|
| + int GetError() override { return ice_transport_->GetError(); }
|
|
|
| - void SetIceConfig(const IceConfig& config) override {
|
| - channel_->SetIceConfig(config);
|
| + int SetOption(rtc::Socket::Option opt, int value) override {
|
| + return ice_transport_->SetOption(opt, value);
|
| }
|
|
|
| - // Needed by DtlsTransport.
|
| - IceTransportInternal* channel() { return channel_; }
|
| + 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);
|
| + }
|
|
|
| - // For informational purposes. Tells if the DTLS handshake has finished.
|
| - // This may be true even if writable() is false, if the remote fingerprint
|
| - // has not yet been verified.
|
| - bool IsDtlsConnected();
|
| + std::string ToString() const {
|
| + const char RECEIVING_ABBREV[2] = {'_', 'R'};
|
| + const char WRITABLE_ABBREV[2] = {'_', 'W'};
|
| + std::stringstream ss;
|
| + ss << "DtlsTransport[" << transport_name_ << "|" << component_ << "|"
|
| + << RECEIVING_ABBREV[receiving()] << WRITABLE_ABBREV[writable()] << "]";
|
| + return ss.str();
|
| + }
|
|
|
| private:
|
| void OnWritableState(rtc::PacketTransportInterface* transport);
|
| @@ -220,25 +206,22 @@ class DtlsTransportChannelWrapper : public TransportChannelImpl {
|
| bool SetupDtls();
|
| void MaybeStartDtls();
|
| bool HandleDtlsPacket(const char* data, size_t size);
|
| - void OnGatheringState(IceTransportInternal* channel);
|
| - void OnCandidateGathered(IceTransportInternal* channel, const Candidate& c);
|
| - void OnCandidatesRemoved(IceTransportInternal* channel,
|
| - const Candidates& candidates);
|
| - void OnRoleConflict(IceTransportInternal* channel);
|
| - void OnRouteChange(IceTransportInternal* channel, const Candidate& candidate);
|
| - void OnSelectedCandidatePairChanged(
|
| - IceTransportInternal* channel,
|
| - CandidatePairInterface* selected_candidate_pair,
|
| - int last_sent_packet_id,
|
| - bool ready_to_send);
|
| - void OnChannelStateChanged(IceTransportInternal* channel);
|
| void OnDtlsHandshakeError(rtc::SSLHandshakeError error);
|
|
|
| + void set_receiving(bool receiving);
|
| + void set_writable(bool writable);
|
| + // Sets the DTLS state, signaling if necessary.
|
| + void set_dtls_state(DtlsTransportState state);
|
| +
|
| + std::string transport_name_;
|
| + int component_;
|
| + DtlsTransportState dtls_state_ = DTLS_TRANSPORT_NEW;
|
| rtc::Thread* network_thread_; // Everything should occur on this thread.
|
| - // Underlying channel, not owned by this class.
|
| - IceTransportInternal* const channel_;
|
| + // Underlying ice_transport, not owned by this class.
|
| + IceTransportInternal* const ice_transport_;
|
| std::unique_ptr<rtc::SSLStreamAdapter> dtls_; // The DTLS stream
|
| - StreamInterfaceChannel* downward_; // Wrapper for channel_, owned by dtls_.
|
| + StreamInterfaceChannel*
|
| + downward_; // Wrapper for ice_transport_, owned by dtls_.
|
| std::vector<int> srtp_ciphers_; // SRTP ciphers to use with DTLS.
|
| bool dtls_active_ = false;
|
| rtc::scoped_refptr<rtc::RTCCertificate> local_certificate_;
|
| @@ -249,11 +232,13 @@ class DtlsTransportChannelWrapper : public TransportChannelImpl {
|
|
|
| // Cached DTLS ClientHello packet that was received before we started the
|
| // DTLS handshake. This could happen if the hello was received before the
|
| - // transport channel became writable, or before a remote fingerprint was
|
| - // received.
|
| + // ice transport became writable, or before a remote fingerprint was received.
|
| rtc::Buffer cached_client_hello_;
|
|
|
| - RTC_DISALLOW_COPY_AND_ASSIGN(DtlsTransportChannelWrapper);
|
| + bool receiving_ = false;
|
| + bool writable_ = false;
|
| +
|
| + RTC_DISALLOW_COPY_AND_ASSIGN(DtlsTransport);
|
| };
|
|
|
| } // namespace cricket
|
|
|