Index: webrtc/p2p/base/dtlstransportchannel.h |
diff --git a/webrtc/p2p/base/dtlstransportchannel.h b/webrtc/p2p/base/dtlstransportchannel.h |
index 5850813fcd6002d36b556572b31e9e1ead0b765d..3387c16198db65a55b844483fa307e7167552374 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/dtlstransportinternal.h" |
+#include "webrtc/p2p/base/icetransportinternal.h" |
namespace rtc { |
class PacketTransportInterface; |
@@ -28,11 +29,11 @@ class PacketTransportInterface; |
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 @@ class StreamInterfaceChannel : public rtc::StreamInterface { |
int* error) override; |
private: |
- TransportChannel* channel_; // owned by DtlsTransportChannelWrapper |
+ IceTransportInternal* channel_; // owned by DtlsTransportChannelWrapper |
pthatcher1
2017/01/13 22:41:16
We should rename the variable ice_transport_, or m
Zhi Huang
2017/01/16 10:38:24
Done.
|
rtc::StreamState state_; |
rtc::BufferQueue packets_; |
@@ -66,7 +67,7 @@ class StreamInterfaceChannel : public rtc::StreamInterface { |
// DtlsTransportChannelWrapper { |
// SSLStreamAdapter* dtls_ { |
// StreamInterfaceChannel downward_ { |
-// TransportChannelImpl* channel_; |
+// IceTransportInternal* channel_; |
// } |
// } |
// } |
@@ -84,15 +85,23 @@ class StreamInterfaceChannel : public rtc::StreamInterface { |
// |
// - The SSLStreamAdapter writes to downward_->Write() |
// which translates it into packet writes on channel_. |
-class DtlsTransportChannelWrapper : public TransportChannelImpl { |
+class DtlsTransportChannelWrapper : public DtlsTransportInternal { |
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); } |
- IceRole GetIceRole() const override { return channel_->GetIceRole(); } |
+ 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_; } |
+ |
bool SetLocalCertificate( |
const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override; |
rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate() const override; |
@@ -101,9 +110,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, |
@@ -111,17 +117,9 @@ 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); |
- } |
virtual bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version); |
@@ -160,51 +158,39 @@ class DtlsTransportChannelWrapper : public TransportChannelImpl { |
: false; |
} |
- // TransportChannelImpl calls. |
- TransportChannelState 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 channel_; } |
- 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 channel_->GetError(); } |
- void SetIceConfig(const IceConfig& config) override { |
- channel_->SetIceConfig(config); |
+ int SetOption(rtc::Socket::Option opt, int value) override { |
+ return channel_->SetOption(opt, value); |
} |
- // Needed by DtlsTransport. |
- TransportChannelImpl* 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); |
@@ -221,23 +207,19 @@ class DtlsTransportChannelWrapper : public TransportChannelImpl { |
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, |
- const Candidates& candidates); |
- void OnRoleConflict(TransportChannelImpl* channel); |
- void OnRouteChange(TransportChannel* channel, const Candidate& candidate); |
- void OnSelectedCandidatePairChanged( |
- TransportChannel* channel, |
- CandidatePairInterface* selected_candidate_pair, |
- int last_sent_packet_id, |
- bool ready_to_send); |
- void OnChannelStateChanged(TransportChannelImpl* 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. |
- 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. |
@@ -254,6 +236,9 @@ class DtlsTransportChannelWrapper : public TransportChannelImpl { |
// received. |
rtc::Buffer cached_client_hello_; |
+ bool receiving_ = false; |
+ bool writable_ = false; |
+ |
RTC_DISALLOW_COPY_AND_ASSIGN(DtlsTransportChannelWrapper); |
}; |