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 StreamInterfaceChannel(TransportChannel* channel); | 30 explicit 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 virtual rtc::StreamState GetState() const { return state_; } | 36 virtual rtc::StreamState GetState() const { return state_; } |
37 virtual void Close() { state_ = rtc::SS_CLOSED; } | 37 virtual void Close() { state_ = rtc::SS_CLOSED; } |
38 virtual rtc::StreamResult Read(void* buffer, size_t buffer_len, | 38 virtual rtc::StreamResult Read(void* buffer, size_t buffer_len, |
39 size_t* read, int* error); | 39 size_t* read, int* error); |
40 virtual rtc::StreamResult Write(const void* data, size_t data_len, | 40 virtual rtc::StreamResult Write(const void* data, size_t data_len, |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 virtual void SetRemoteIceCredentials(const std::string& ice_ufrag, | 190 virtual void SetRemoteIceCredentials(const std::string& ice_ufrag, |
191 const std::string& ice_pwd) { | 191 const std::string& ice_pwd) { |
192 channel_->SetRemoteIceCredentials(ice_ufrag, ice_pwd); | 192 channel_->SetRemoteIceCredentials(ice_ufrag, ice_pwd); |
193 } | 193 } |
194 virtual void SetRemoteIceMode(IceMode mode) { | 194 virtual void SetRemoteIceMode(IceMode mode) { |
195 channel_->SetRemoteIceMode(mode); | 195 channel_->SetRemoteIceMode(mode); |
196 } | 196 } |
197 | 197 |
198 virtual void Connect(); | 198 virtual void Connect(); |
199 | 199 |
200 virtual void OnSignalingReady() { | 200 virtual IceGatheringState gathering_state() const { |
201 channel_->OnSignalingReady(); | 201 return channel_->gathering_state(); |
202 } | 202 } |
| 203 |
203 virtual void OnCandidate(const Candidate& candidate) { | 204 virtual void OnCandidate(const Candidate& candidate) { |
204 channel_->OnCandidate(candidate); | 205 channel_->OnCandidate(candidate); |
205 } | 206 } |
206 | 207 |
207 void SetReceivingTimeout(int receiving_timeout_ms) { | 208 void SetReceivingTimeout(int receiving_timeout_ms) { |
208 channel_->SetReceivingTimeout(receiving_timeout_ms); | 209 channel_->SetReceivingTimeout(receiving_timeout_ms); |
209 } | 210 } |
210 | 211 |
211 // Needed by DtlsTransport. | 212 // Needed by DtlsTransport. |
212 TransportChannelImpl* channel() { return channel_; } | 213 TransportChannelImpl* channel() { return channel_; } |
213 | 214 |
214 private: | 215 private: |
215 void OnReadableState(TransportChannel* channel); | 216 void OnReadableState(TransportChannel* channel); |
216 void OnWritableState(TransportChannel* channel); | 217 void OnWritableState(TransportChannel* channel); |
217 void OnReadPacket(TransportChannel* channel, const char* data, size_t size, | 218 void OnReadPacket(TransportChannel* channel, const char* data, size_t size, |
218 const rtc::PacketTime& packet_time, int flags); | 219 const rtc::PacketTime& packet_time, int flags); |
219 void OnReadyToSend(TransportChannel* channel); | 220 void OnReadyToSend(TransportChannel* channel); |
220 void OnReceivingState(TransportChannel* channel); | 221 void OnReceivingState(TransportChannel* channel); |
221 void OnDtlsEvent(rtc::StreamInterface* stream_, int sig, int err); | 222 void OnDtlsEvent(rtc::StreamInterface* stream_, int sig, int err); |
222 bool SetupDtls(); | 223 bool SetupDtls(); |
223 bool MaybeStartDtls(); | 224 bool MaybeStartDtls(); |
224 bool HandleDtlsPacket(const char* data, size_t size); | 225 bool HandleDtlsPacket(const char* data, size_t size); |
225 void OnRequestSignaling(TransportChannelImpl* channel); | 226 void OnGatheringState(TransportChannelImpl* channel); |
226 void OnCandidateReady(TransportChannelImpl* channel, const Candidate& c); | 227 void OnCandidateGathered(TransportChannelImpl* channel, const Candidate& c); |
227 void OnCandidatesAllocationDone(TransportChannelImpl* channel); | |
228 void OnRoleConflict(TransportChannelImpl* channel); | 228 void OnRoleConflict(TransportChannelImpl* channel); |
229 void OnRouteChange(TransportChannel* channel, const Candidate& candidate); | 229 void OnRouteChange(TransportChannel* channel, const Candidate& candidate); |
230 void OnConnectionRemoved(TransportChannelImpl* channel); | 230 void OnConnectionRemoved(TransportChannelImpl* channel); |
231 | 231 |
232 Transport* transport_; // The transport_ that created us. | 232 Transport* transport_; // The transport_ that created us. |
233 rtc::Thread* worker_thread_; // Everything should occur on this thread. | 233 rtc::Thread* worker_thread_; // Everything should occur on this thread. |
234 TransportChannelImpl* channel_; // Underlying channel, owned by transport_. | 234 TransportChannelImpl* channel_; // Underlying channel, owned by transport_. |
235 rtc::scoped_ptr<rtc::SSLStreamAdapter> dtls_; // The DTLS stream | 235 rtc::scoped_ptr<rtc::SSLStreamAdapter> dtls_; // The DTLS stream |
236 StreamInterfaceChannel* downward_; // Wrapper for channel_, owned by dtls_. | 236 StreamInterfaceChannel* downward_; // Wrapper for channel_, owned by dtls_. |
237 std::vector<std::string> srtp_ciphers_; // SRTP ciphers to use with DTLS. | 237 std::vector<std::string> srtp_ciphers_; // SRTP ciphers to use with DTLS. |
238 State dtls_state_; | 238 State dtls_state_; |
239 rtc::SSLIdentity* local_identity_; | 239 rtc::SSLIdentity* local_identity_; |
240 rtc::SSLRole ssl_role_; | 240 rtc::SSLRole ssl_role_; |
241 rtc::SSLProtocolVersion ssl_max_version_; | 241 rtc::SSLProtocolVersion ssl_max_version_; |
242 rtc::Buffer remote_fingerprint_value_; | 242 rtc::Buffer remote_fingerprint_value_; |
243 std::string remote_fingerprint_algorithm_; | 243 std::string remote_fingerprint_algorithm_; |
244 | 244 |
245 DISALLOW_COPY_AND_ASSIGN(DtlsTransportChannelWrapper); | 245 DISALLOW_COPY_AND_ASSIGN(DtlsTransportChannelWrapper); |
246 }; | 246 }; |
247 | 247 |
248 } // namespace cricket | 248 } // namespace cricket |
249 | 249 |
250 #endif // WEBRTC_P2P_BASE_DTLSTRANSPORTCHANNEL_H_ | 250 #endif // WEBRTC_P2P_BASE_DTLSTRANSPORTCHANNEL_H_ |
OLD | NEW |