OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_P2P_BASE_DTLSTRANSPORTCHANNEL_H_ | 11 #ifndef WEBRTC_P2P_BASE_DTLSTRANSPORTCHANNEL_H_ |
12 #define WEBRTC_P2P_BASE_DTLSTRANSPORTCHANNEL_H_ | 12 #define WEBRTC_P2P_BASE_DTLSTRANSPORTCHANNEL_H_ |
13 | 13 |
14 #include <string> | 14 #include <string> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "webrtc/p2p/base/transportchannelimpl.h" | 17 #include "webrtc/p2p/base/transportchannelimpl.h" |
18 #include "webrtc/base/buffer.h" | 18 #include "webrtc/base/buffer.h" |
19 #include "webrtc/base/bufferqueue.h" | 19 #include "webrtc/base/bufferqueue.h" |
20 #include "webrtc/base/scoped_ptr.h" | 20 #include "webrtc/base/scoped_ptr.h" |
21 #include "webrtc/base/sslstreamadapter.h" | 21 #include "webrtc/base/sslstreamadapter.h" |
22 #include "webrtc/base/stream.h" | 22 #include "webrtc/base/stream.h" |
23 | 23 |
24 namespace cricket { | 24 namespace cricket { |
25 | 25 |
26 // A bridge between a packet-oriented/channel-type interface on | 26 // A bridge between a packet-oriented/channel-type interface on |
27 // the bottom and a StreamInterface on the top. | 27 // the bottom and a StreamInterface on the top. |
28 class StreamInterfaceChannel : public rtc::StreamInterface { | 28 class StreamInterfaceChannel : public rtc::StreamInterface { |
29 public: | 29 public: |
30 explicit StreamInterfaceChannel(TransportChannel* channel); | 30 StreamInterfaceChannel(TransportChannel* channel); |
31 | 31 |
32 // Push in a packet; this gets pulled out from Read(). | 32 // Push in a packet; this gets pulled out from Read(). |
33 bool OnPacketReceived(const char* data, size_t size); | 33 bool OnPacketReceived(const char* data, size_t size); |
34 | 34 |
35 // Implementations of StreamInterface | 35 // Implementations of StreamInterface |
36 rtc::StreamState GetState() const override { return state_; } | 36 rtc::StreamState GetState() const override { return state_; } |
37 void Close() override { state_ = rtc::SS_CLOSED; } | 37 void Close() override { state_ = rtc::SS_CLOSED; } |
38 rtc::StreamResult Read(void* buffer, | 38 rtc::StreamResult Read(void* buffer, size_t buffer_len, |
39 size_t buffer_len, | 39 size_t* read, int* error) override; |
40 size_t* read, | 40 rtc::StreamResult Write(const void* data, size_t data_len, |
41 int* error) override; | 41 size_t* written, int* error) override; |
42 rtc::StreamResult Write(const void* data, | |
43 size_t data_len, | |
44 size_t* written, | |
45 int* error) override; | |
46 | 42 |
47 private: | 43 private: |
48 TransportChannel* channel_; // owned by DtlsTransportChannelWrapper | 44 TransportChannel* channel_; // owned by DtlsTransportChannelWrapper |
49 rtc::StreamState state_; | 45 rtc::StreamState state_; |
50 rtc::BufferQueue packets_; | 46 rtc::BufferQueue packets_; |
51 | 47 |
52 RTC_DISALLOW_COPY_AND_ASSIGN(StreamInterfaceChannel); | 48 RTC_DISALLOW_COPY_AND_ASSIGN(StreamInterfaceChannel); |
53 }; | 49 }; |
54 | 50 |
55 | 51 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 STATE_CLOSED // Connection closed. | 86 STATE_CLOSED // Connection closed. |
91 }; | 87 }; |
92 | 88 |
93 // The parameters here are: | 89 // The parameters here are: |
94 // transport -- the DtlsTransport that created us | 90 // transport -- the DtlsTransport that created us |
95 // channel -- the TransportChannel we are wrapping | 91 // channel -- the TransportChannel we are wrapping |
96 DtlsTransportChannelWrapper(Transport* transport, | 92 DtlsTransportChannelWrapper(Transport* transport, |
97 TransportChannelImpl* channel); | 93 TransportChannelImpl* channel); |
98 ~DtlsTransportChannelWrapper() override; | 94 ~DtlsTransportChannelWrapper() override; |
99 | 95 |
100 void SetIceRole(IceRole role) override { channel_->SetIceRole(role); } | 96 void SetIceRole(IceRole role) override { |
101 IceRole GetIceRole() const override { return channel_->GetIceRole(); } | 97 channel_->SetIceRole(role); |
| 98 } |
| 99 IceRole GetIceRole() const override { |
| 100 return channel_->GetIceRole(); |
| 101 } |
102 bool SetLocalCertificate( | 102 bool SetLocalCertificate( |
103 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override; | 103 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override; |
104 rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate() const override; | 104 rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate() const override; |
105 | 105 |
106 bool SetRemoteFingerprint(const std::string& digest_alg, | 106 bool SetRemoteFingerprint(const std::string& digest_alg, |
107 const uint8* digest, | 107 const uint8* digest, |
108 size_t digest_len) override; | 108 size_t digest_len) override; |
109 bool IsDtlsActive() const override { return dtls_state_ != STATE_NONE; } | 109 bool IsDtlsActive() const override { return dtls_state_ != STATE_NONE; } |
110 | 110 |
111 // Called to send a packet (via DTLS, if turned on). | 111 // Called to send a packet (via DTLS, if turned on). |
112 int SendPacket(const char* data, | 112 int SendPacket(const char* data, size_t size, |
113 size_t size, | |
114 const rtc::PacketOptions& options, | 113 const rtc::PacketOptions& options, |
115 int flags) override; | 114 int flags) override; |
116 | 115 |
117 // TransportChannel calls that we forward to the wrapped transport. | 116 // TransportChannel calls that we forward to the wrapped transport. |
118 int SetOption(rtc::Socket::Option opt, int value) override { | 117 int SetOption(rtc::Socket::Option opt, int value) override { |
119 return channel_->SetOption(opt, value); | 118 return channel_->SetOption(opt, value); |
120 } | 119 } |
121 bool GetOption(rtc::Socket::Option opt, int* value) override { | 120 bool GetOption(rtc::Socket::Option opt, int* value) override { |
122 return channel_->GetOption(opt, value); | 121 return channel_->GetOption(opt, value); |
123 } | 122 } |
124 int GetError() override { return channel_->GetError(); } | 123 int GetError() override { |
| 124 return channel_->GetError(); |
| 125 } |
125 bool GetStats(ConnectionInfos* infos) override { | 126 bool GetStats(ConnectionInfos* infos) override { |
126 return channel_->GetStats(infos); | 127 return channel_->GetStats(infos); |
127 } | 128 } |
128 const std::string SessionId() const override { return channel_->SessionId(); } | 129 const std::string SessionId() const override { |
| 130 return channel_->SessionId(); |
| 131 } |
129 | 132 |
130 virtual bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version); | 133 virtual bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version); |
131 | 134 |
132 // Set up the ciphers to use for DTLS-SRTP. If this method is not called | 135 // Set up the ciphers to use for DTLS-SRTP. If this method is not called |
133 // before DTLS starts, or |ciphers| is empty, SRTP keys won't be negotiated. | 136 // before DTLS starts, or |ciphers| is empty, SRTP keys won't be negotiated. |
134 // This method should be called before SetupDtls. | 137 // This method should be called before SetupDtls. |
135 bool SetSrtpCiphers(const std::vector<std::string>& ciphers) override; | 138 bool SetSrtpCiphers(const std::vector<std::string>& ciphers) override; |
136 | 139 |
137 // Find out which DTLS-SRTP cipher was negotiated | 140 // Find out which DTLS-SRTP cipher was negotiated |
138 bool GetSrtpCipher(std::string* cipher) override; | 141 bool GetSrtpCipher(std::string* cipher) override; |
(...skipping 19 matching lines...) Expand all Loading... |
158 uint8* result, | 161 uint8* result, |
159 size_t result_len) override { | 162 size_t result_len) override { |
160 return (dtls_.get()) ? dtls_->ExportKeyingMaterial(label, context, | 163 return (dtls_.get()) ? dtls_->ExportKeyingMaterial(label, context, |
161 context_len, | 164 context_len, |
162 use_context, | 165 use_context, |
163 result, result_len) | 166 result, result_len) |
164 : false; | 167 : false; |
165 } | 168 } |
166 | 169 |
167 // TransportChannelImpl calls. | 170 // TransportChannelImpl calls. |
168 Transport* GetTransport() override { return transport_; } | 171 Transport* GetTransport() override { |
| 172 return transport_; |
| 173 } |
169 | 174 |
170 TransportChannelState GetState() const override { | 175 TransportChannelState GetState() const override { |
171 return channel_->GetState(); | 176 return channel_->GetState(); |
172 } | 177 } |
173 void SetIceTiebreaker(uint64 tiebreaker) override { | 178 void SetIceTiebreaker(uint64 tiebreaker) override { |
174 channel_->SetIceTiebreaker(tiebreaker); | 179 channel_->SetIceTiebreaker(tiebreaker); |
175 } | 180 } |
176 void SetIceCredentials(const std::string& ice_ufrag, | 181 void SetIceCredentials(const std::string& ice_ufrag, |
177 const std::string& ice_pwd) override { | 182 const std::string& ice_pwd) override { |
178 channel_->SetIceCredentials(ice_ufrag, ice_pwd); | 183 channel_->SetIceCredentials(ice_ufrag, ice_pwd); |
179 } | 184 } |
180 void SetRemoteIceCredentials(const std::string& ice_ufrag, | 185 void SetRemoteIceCredentials(const std::string& ice_ufrag, |
181 const std::string& ice_pwd) override { | 186 const std::string& ice_pwd) override { |
182 channel_->SetRemoteIceCredentials(ice_ufrag, ice_pwd); | 187 channel_->SetRemoteIceCredentials(ice_ufrag, ice_pwd); |
183 } | 188 } |
184 void SetRemoteIceMode(IceMode mode) override { | 189 void SetRemoteIceMode(IceMode mode) override { |
185 channel_->SetRemoteIceMode(mode); | 190 channel_->SetRemoteIceMode(mode); |
186 } | 191 } |
187 | 192 |
188 void Connect() override; | 193 void Connect() override; |
189 | 194 |
190 void MaybeStartGathering() override { channel_->MaybeStartGathering(); } | 195 void OnSignalingReady() override { |
191 | 196 channel_->OnSignalingReady(); |
192 IceGatheringState gathering_state() const override { | |
193 return channel_->gathering_state(); | |
194 } | 197 } |
195 | 198 void OnCandidate(const Candidate& candidate) override { |
196 void AddRemoteCandidate(const Candidate& candidate) override { | 199 channel_->OnCandidate(candidate); |
197 channel_->AddRemoteCandidate(candidate); | |
198 } | 200 } |
199 | 201 |
200 void SetReceivingTimeout(int receiving_timeout_ms) override { | 202 void SetReceivingTimeout(int receiving_timeout_ms) override { |
201 channel_->SetReceivingTimeout(receiving_timeout_ms); | 203 channel_->SetReceivingTimeout(receiving_timeout_ms); |
202 } | 204 } |
203 | 205 |
204 // Needed by DtlsTransport. | 206 // Needed by DtlsTransport. |
205 TransportChannelImpl* channel() { return channel_; } | 207 TransportChannelImpl* channel() { return channel_; } |
206 | 208 |
207 private: | 209 private: |
208 void OnReadableState(TransportChannel* channel); | 210 void OnReadableState(TransportChannel* channel); |
209 void OnWritableState(TransportChannel* channel); | 211 void OnWritableState(TransportChannel* channel); |
210 void OnReadPacket(TransportChannel* channel, const char* data, size_t size, | 212 void OnReadPacket(TransportChannel* channel, const char* data, size_t size, |
211 const rtc::PacketTime& packet_time, int flags); | 213 const rtc::PacketTime& packet_time, int flags); |
212 void OnReadyToSend(TransportChannel* channel); | 214 void OnReadyToSend(TransportChannel* channel); |
213 void OnReceivingState(TransportChannel* channel); | 215 void OnReceivingState(TransportChannel* channel); |
214 void OnDtlsEvent(rtc::StreamInterface* stream_, int sig, int err); | 216 void OnDtlsEvent(rtc::StreamInterface* stream_, int sig, int err); |
215 bool SetupDtls(); | 217 bool SetupDtls(); |
216 bool MaybeStartDtls(); | 218 bool MaybeStartDtls(); |
217 bool HandleDtlsPacket(const char* data, size_t size); | 219 bool HandleDtlsPacket(const char* data, size_t size); |
218 void OnGatheringState(TransportChannelImpl* channel); | 220 void OnRequestSignaling(TransportChannelImpl* channel); |
219 void OnCandidateGathered(TransportChannelImpl* channel, const Candidate& c); | 221 void OnCandidateReady(TransportChannelImpl* channel, const Candidate& c); |
| 222 void OnCandidatesAllocationDone(TransportChannelImpl* channel); |
220 void OnRoleConflict(TransportChannelImpl* channel); | 223 void OnRoleConflict(TransportChannelImpl* channel); |
221 void OnRouteChange(TransportChannel* channel, const Candidate& candidate); | 224 void OnRouteChange(TransportChannel* channel, const Candidate& candidate); |
222 void OnConnectionRemoved(TransportChannelImpl* channel); | 225 void OnConnectionRemoved(TransportChannelImpl* channel); |
223 | 226 |
224 Transport* transport_; // The transport_ that created us. | 227 Transport* transport_; // The transport_ that created us. |
225 rtc::Thread* worker_thread_; // Everything should occur on this thread. | 228 rtc::Thread* worker_thread_; // Everything should occur on this thread. |
226 TransportChannelImpl* channel_; // Underlying channel, owned by transport_. | 229 TransportChannelImpl* channel_; // Underlying channel, owned by transport_. |
227 rtc::scoped_ptr<rtc::SSLStreamAdapter> dtls_; // The DTLS stream | 230 rtc::scoped_ptr<rtc::SSLStreamAdapter> dtls_; // The DTLS stream |
228 StreamInterfaceChannel* downward_; // Wrapper for channel_, owned by dtls_. | 231 StreamInterfaceChannel* downward_; // Wrapper for channel_, owned by dtls_. |
229 std::vector<std::string> srtp_ciphers_; // SRTP ciphers to use with DTLS. | 232 std::vector<std::string> srtp_ciphers_; // SRTP ciphers to use with DTLS. |
230 State dtls_state_; | 233 State dtls_state_; |
231 rtc::scoped_refptr<rtc::RTCCertificate> local_certificate_; | 234 rtc::scoped_refptr<rtc::RTCCertificate> local_certificate_; |
232 rtc::SSLRole ssl_role_; | 235 rtc::SSLRole ssl_role_; |
233 rtc::SSLProtocolVersion ssl_max_version_; | 236 rtc::SSLProtocolVersion ssl_max_version_; |
234 rtc::Buffer remote_fingerprint_value_; | 237 rtc::Buffer remote_fingerprint_value_; |
235 std::string remote_fingerprint_algorithm_; | 238 std::string remote_fingerprint_algorithm_; |
236 | 239 |
237 RTC_DISALLOW_COPY_AND_ASSIGN(DtlsTransportChannelWrapper); | 240 RTC_DISALLOW_COPY_AND_ASSIGN(DtlsTransportChannelWrapper); |
238 }; | 241 }; |
239 | 242 |
240 } // namespace cricket | 243 } // namespace cricket |
241 | 244 |
242 #endif // WEBRTC_P2P_BASE_DTLSTRANSPORTCHANNEL_H_ | 245 #endif // WEBRTC_P2P_BASE_DTLSTRANSPORTCHANNEL_H_ |
OLD | NEW |