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 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 // downward_->Read(). | 74 // downward_->Read(). |
75 // | 75 // |
76 // - Data written to DtlsTransportChannelWrapper is passed either to | 76 // - Data written to DtlsTransportChannelWrapper is passed either to |
77 // downward_ or directly to channel_, depending on whether DTLS is | 77 // downward_ or directly to channel_, depending on whether DTLS is |
78 // negotiated and whether the flags include PF_SRTP_BYPASS | 78 // negotiated and whether the flags include PF_SRTP_BYPASS |
79 // | 79 // |
80 // - The SSLStreamAdapter writes to downward_->Write() | 80 // - The SSLStreamAdapter writes to downward_->Write() |
81 // which translates it into packet writes on channel_. | 81 // which translates it into packet writes on channel_. |
82 class DtlsTransportChannelWrapper : public TransportChannelImpl { | 82 class DtlsTransportChannelWrapper : public TransportChannelImpl { |
83 public: | 83 public: |
84 enum State { | |
85 STATE_NONE, // No state or rejected. | |
86 STATE_OFFERED, // Our identity has been set. | |
87 STATE_ACCEPTED, // The other side sent a fingerprint. | |
88 STATE_STARTED, // We are negotiating. | |
89 STATE_OPEN, // Negotiation complete. | |
90 STATE_CLOSED // Connection closed. | |
91 }; | |
92 | |
93 // The parameters here are: | 84 // The parameters here are: |
94 // transport -- the DtlsTransport that created us | 85 // transport -- the DtlsTransport that created us |
95 // channel -- the TransportChannel we are wrapping | 86 // channel -- the TransportChannel we are wrapping |
96 DtlsTransportChannelWrapper(Transport* transport, | 87 DtlsTransportChannelWrapper(Transport* transport, |
97 TransportChannelImpl* channel); | 88 TransportChannelImpl* channel); |
98 ~DtlsTransportChannelWrapper() override; | 89 ~DtlsTransportChannelWrapper() override; |
99 | 90 |
100 void SetIceRole(IceRole role) override { channel_->SetIceRole(role); } | 91 void SetIceRole(IceRole role) override { channel_->SetIceRole(role); } |
101 IceRole GetIceRole() const override { return channel_->GetIceRole(); } | 92 IceRole GetIceRole() const override { return channel_->GetIceRole(); } |
102 bool SetLocalCertificate( | 93 bool SetLocalCertificate( |
103 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override; | 94 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override; |
104 rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate() const override; | 95 rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate() const override; |
105 | 96 |
106 bool SetRemoteFingerprint(const std::string& digest_alg, | 97 bool SetRemoteFingerprint(const std::string& digest_alg, |
107 const uint8_t* digest, | 98 const uint8_t* digest, |
108 size_t digest_len) override; | 99 size_t digest_len) override; |
109 bool IsDtlsActive() const override { return dtls_state_ != STATE_NONE; } | 100 |
| 101 // Returns false if no local certificate was set, or if the peer doesn't |
| 102 // support DTLS. |
| 103 bool IsDtlsActive() const override { return dtls_active_; } |
110 | 104 |
111 // Called to send a packet (via DTLS, if turned on). | 105 // Called to send a packet (via DTLS, if turned on). |
112 int SendPacket(const char* data, | 106 int SendPacket(const char* data, |
113 size_t size, | 107 size_t size, |
114 const rtc::PacketOptions& options, | 108 const rtc::PacketOptions& options, |
115 int flags) override; | 109 int flags) override; |
116 | 110 |
117 // TransportChannel calls that we forward to the wrapped transport. | 111 // TransportChannel calls that we forward to the wrapped transport. |
118 int SetOption(rtc::Socket::Option opt, int value) override { | 112 int SetOption(rtc::Socket::Option opt, int value) override { |
119 return channel_->SetOption(opt, value); | 113 return channel_->SetOption(opt, value); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 void OnRouteChange(TransportChannel* channel, const Candidate& candidate); | 217 void OnRouteChange(TransportChannel* channel, const Candidate& candidate); |
224 void OnConnectionRemoved(TransportChannelImpl* channel); | 218 void OnConnectionRemoved(TransportChannelImpl* channel); |
225 | 219 |
226 Transport* transport_; // The transport_ that created us. | 220 Transport* transport_; // The transport_ that created us. |
227 rtc::Thread* worker_thread_; // Everything should occur on this thread. | 221 rtc::Thread* worker_thread_; // Everything should occur on this thread. |
228 // Underlying channel, owned by transport_. | 222 // Underlying channel, owned by transport_. |
229 TransportChannelImpl* const channel_; | 223 TransportChannelImpl* const channel_; |
230 rtc::scoped_ptr<rtc::SSLStreamAdapter> dtls_; // The DTLS stream | 224 rtc::scoped_ptr<rtc::SSLStreamAdapter> dtls_; // The DTLS stream |
231 StreamInterfaceChannel* downward_; // Wrapper for channel_, owned by dtls_. | 225 StreamInterfaceChannel* downward_; // Wrapper for channel_, owned by dtls_. |
232 std::vector<std::string> srtp_ciphers_; // SRTP ciphers to use with DTLS. | 226 std::vector<std::string> srtp_ciphers_; // SRTP ciphers to use with DTLS. |
233 State dtls_state_; | 227 bool dtls_active_ = false; |
234 rtc::scoped_refptr<rtc::RTCCertificate> local_certificate_; | 228 rtc::scoped_refptr<rtc::RTCCertificate> local_certificate_; |
235 rtc::SSLRole ssl_role_; | 229 rtc::SSLRole ssl_role_; |
236 rtc::SSLProtocolVersion ssl_max_version_; | 230 rtc::SSLProtocolVersion ssl_max_version_; |
237 rtc::Buffer remote_fingerprint_value_; | 231 rtc::Buffer remote_fingerprint_value_; |
238 std::string remote_fingerprint_algorithm_; | 232 std::string remote_fingerprint_algorithm_; |
239 | 233 |
240 RTC_DISALLOW_COPY_AND_ASSIGN(DtlsTransportChannelWrapper); | 234 RTC_DISALLOW_COPY_AND_ASSIGN(DtlsTransportChannelWrapper); |
241 }; | 235 }; |
242 | 236 |
243 } // namespace cricket | 237 } // namespace cricket |
244 | 238 |
245 #endif // WEBRTC_P2P_BASE_DTLSTRANSPORTCHANNEL_H_ | 239 #endif // WEBRTC_P2P_BASE_DTLSTRANSPORTCHANNEL_H_ |
OLD | NEW |