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 15 matching lines...) Expand all Loading... |
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 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 rtc::StreamState GetState() const override { return state_; } |
37 virtual void Close() { state_ = rtc::SS_CLOSED; } | 37 void Close() override { state_ = rtc::SS_CLOSED; } |
38 virtual rtc::StreamResult Read(void* buffer, size_t buffer_len, | 38 rtc::StreamResult Read(void* buffer, size_t buffer_len, |
39 size_t* read, int* error); | 39 size_t* read, int* error) override; |
40 virtual rtc::StreamResult Write(const void* data, size_t data_len, | 40 rtc::StreamResult Write(const void* data, size_t data_len, |
41 size_t* written, int* error); | 41 size_t* written, int* error) override; |
42 | 42 |
43 private: | 43 private: |
44 TransportChannel* channel_; // owned by DtlsTransportChannelWrapper | 44 TransportChannel* channel_; // owned by DtlsTransportChannelWrapper |
45 rtc::StreamState state_; | 45 rtc::StreamState state_; |
46 rtc::BufferQueue packets_; | 46 rtc::BufferQueue packets_; |
47 | 47 |
48 DISALLOW_COPY_AND_ASSIGN(StreamInterfaceChannel); | 48 DISALLOW_COPY_AND_ASSIGN(StreamInterfaceChannel); |
49 }; | 49 }; |
50 | 50 |
51 | 51 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 STATE_STARTED, // We are negotiating. | 84 STATE_STARTED, // We are negotiating. |
85 STATE_OPEN, // Negotiation complete. | 85 STATE_OPEN, // Negotiation complete. |
86 STATE_CLOSED // Connection closed. | 86 STATE_CLOSED // Connection closed. |
87 }; | 87 }; |
88 | 88 |
89 // The parameters here are: | 89 // The parameters here are: |
90 // transport -- the DtlsTransport that created us | 90 // transport -- the DtlsTransport that created us |
91 // channel -- the TransportChannel we are wrapping | 91 // channel -- the TransportChannel we are wrapping |
92 DtlsTransportChannelWrapper(Transport* transport, | 92 DtlsTransportChannelWrapper(Transport* transport, |
93 TransportChannelImpl* channel); | 93 TransportChannelImpl* channel); |
94 virtual ~DtlsTransportChannelWrapper(); | 94 ~DtlsTransportChannelWrapper() override; |
95 | 95 |
96 virtual void SetIceRole(IceRole role) { | 96 void SetIceRole(IceRole role) override { |
97 channel_->SetIceRole(role); | 97 channel_->SetIceRole(role); |
98 } | 98 } |
99 virtual IceRole GetIceRole() const { | 99 IceRole GetIceRole() const override { |
100 return channel_->GetIceRole(); | 100 return channel_->GetIceRole(); |
101 } | 101 } |
102 virtual bool SetLocalIdentity(rtc::SSLIdentity *identity); | 102 bool SetLocalCertificate( |
103 virtual bool GetLocalIdentity(rtc::SSLIdentity** identity) const; | 103 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override; |
| 104 rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate() const override; |
104 | 105 |
105 virtual bool SetRemoteFingerprint(const std::string& digest_alg, | 106 bool SetRemoteFingerprint(const std::string& digest_alg, |
106 const uint8* digest, | 107 const uint8* digest, |
107 size_t digest_len); | 108 size_t digest_len) override; |
108 virtual bool IsDtlsActive() const { return dtls_state_ != STATE_NONE; } | 109 bool IsDtlsActive() const override { return dtls_state_ != STATE_NONE; } |
109 | 110 |
110 // Called to send a packet (via DTLS, if turned on). | 111 // Called to send a packet (via DTLS, if turned on). |
111 virtual int SendPacket(const char* data, size_t size, | 112 int SendPacket(const char* data, size_t size, |
112 const rtc::PacketOptions& options, | 113 const rtc::PacketOptions& options, |
113 int flags); | 114 int flags) override; |
114 | 115 |
115 // TransportChannel calls that we forward to the wrapped transport. | 116 // TransportChannel calls that we forward to the wrapped transport. |
116 virtual int SetOption(rtc::Socket::Option opt, int value) { | 117 int SetOption(rtc::Socket::Option opt, int value) override { |
117 return channel_->SetOption(opt, value); | 118 return channel_->SetOption(opt, value); |
118 } | 119 } |
119 virtual bool GetOption(rtc::Socket::Option opt, int* value) { | 120 bool GetOption(rtc::Socket::Option opt, int* value) override { |
120 return channel_->GetOption(opt, value); | 121 return channel_->GetOption(opt, value); |
121 } | 122 } |
122 virtual int GetError() { | 123 int GetError() override { |
123 return channel_->GetError(); | 124 return channel_->GetError(); |
124 } | 125 } |
125 virtual bool GetStats(ConnectionInfos* infos) { | 126 bool GetStats(ConnectionInfos* infos) override { |
126 return channel_->GetStats(infos); | 127 return channel_->GetStats(infos); |
127 } | 128 } |
128 virtual const std::string SessionId() const { | 129 const std::string SessionId() const override { |
129 return channel_->SessionId(); | 130 return channel_->SessionId(); |
130 } | 131 } |
131 | 132 |
132 virtual bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version); | 133 virtual bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version); |
133 | 134 |
134 // 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 |
135 // 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. |
136 // This method should be called before SetupDtls. | 137 // This method should be called before SetupDtls. |
137 virtual bool SetSrtpCiphers(const std::vector<std::string>& ciphers); | 138 bool SetSrtpCiphers(const std::vector<std::string>& ciphers) override; |
138 | 139 |
139 // Find out which DTLS-SRTP cipher was negotiated | 140 // Find out which DTLS-SRTP cipher was negotiated |
140 virtual bool GetSrtpCipher(std::string* cipher); | 141 bool GetSrtpCipher(std::string* cipher) override; |
141 | 142 |
142 virtual bool GetSslRole(rtc::SSLRole* role) const; | 143 bool GetSslRole(rtc::SSLRole* role) const override; |
143 virtual bool SetSslRole(rtc::SSLRole role); | 144 bool SetSslRole(rtc::SSLRole role) override; |
144 | 145 |
145 // Find out which DTLS cipher was negotiated | 146 // Find out which DTLS cipher was negotiated |
146 virtual bool GetSslCipher(std::string* cipher); | 147 bool GetSslCipher(std::string* cipher) override; |
147 | 148 |
148 // Once DTLS has been established, this method retrieves the certificate in | 149 // Once DTLS has been established, this method retrieves the certificate in |
149 // use by the remote peer, for use in external identity verification. | 150 // use by the remote peer, for use in external identity verification. |
150 virtual bool GetRemoteCertificate(rtc::SSLCertificate** cert) const; | 151 bool GetRemoteSSLCertificate(rtc::SSLCertificate** cert) const override; |
151 | 152 |
152 // Once DTLS has established (i.e., this channel is writable), this method | 153 // Once DTLS has established (i.e., this channel is writable), this method |
153 // extracts the keys negotiated during the DTLS handshake, for use in external | 154 // extracts the keys negotiated during the DTLS handshake, for use in external |
154 // encryption. DTLS-SRTP uses this to extract the needed SRTP keys. | 155 // encryption. DTLS-SRTP uses this to extract the needed SRTP keys. |
155 // See the SSLStreamAdapter documentation for info on the specific parameters. | 156 // See the SSLStreamAdapter documentation for info on the specific parameters. |
156 virtual bool ExportKeyingMaterial(const std::string& label, | 157 bool ExportKeyingMaterial(const std::string& label, |
157 const uint8* context, | 158 const uint8* context, |
158 size_t context_len, | 159 size_t context_len, |
159 bool use_context, | 160 bool use_context, |
160 uint8* result, | 161 uint8* result, |
161 size_t result_len) { | 162 size_t result_len) override { |
162 return (dtls_.get()) ? dtls_->ExportKeyingMaterial(label, context, | 163 return (dtls_.get()) ? dtls_->ExportKeyingMaterial(label, context, |
163 context_len, | 164 context_len, |
164 use_context, | 165 use_context, |
165 result, result_len) | 166 result, result_len) |
166 : false; | 167 : false; |
167 } | 168 } |
168 | 169 |
169 // TransportChannelImpl calls. | 170 // TransportChannelImpl calls. |
170 virtual Transport* GetTransport() { | 171 Transport* GetTransport() override { |
171 return transport_; | 172 return transport_; |
172 } | 173 } |
173 | 174 |
174 virtual TransportChannelState GetState() const { | 175 TransportChannelState GetState() const override { |
175 return channel_->GetState(); | 176 return channel_->GetState(); |
176 } | 177 } |
177 virtual void SetIceTiebreaker(uint64 tiebreaker) { | 178 void SetIceTiebreaker(uint64 tiebreaker) override { |
178 channel_->SetIceTiebreaker(tiebreaker); | 179 channel_->SetIceTiebreaker(tiebreaker); |
179 } | 180 } |
180 virtual void SetIceCredentials(const std::string& ice_ufrag, | 181 void SetIceCredentials(const std::string& ice_ufrag, |
181 const std::string& ice_pwd) { | 182 const std::string& ice_pwd) override { |
182 channel_->SetIceCredentials(ice_ufrag, ice_pwd); | 183 channel_->SetIceCredentials(ice_ufrag, ice_pwd); |
183 } | 184 } |
184 virtual void SetRemoteIceCredentials(const std::string& ice_ufrag, | 185 void SetRemoteIceCredentials(const std::string& ice_ufrag, |
185 const std::string& ice_pwd) { | 186 const std::string& ice_pwd) override { |
186 channel_->SetRemoteIceCredentials(ice_ufrag, ice_pwd); | 187 channel_->SetRemoteIceCredentials(ice_ufrag, ice_pwd); |
187 } | 188 } |
188 virtual void SetRemoteIceMode(IceMode mode) { | 189 void SetRemoteIceMode(IceMode mode) override { |
189 channel_->SetRemoteIceMode(mode); | 190 channel_->SetRemoteIceMode(mode); |
190 } | 191 } |
191 | 192 |
192 virtual void Connect(); | 193 void Connect() override; |
193 | 194 |
194 virtual void OnSignalingReady() { | 195 void OnSignalingReady() override { |
195 channel_->OnSignalingReady(); | 196 channel_->OnSignalingReady(); |
196 } | 197 } |
197 virtual void OnCandidate(const Candidate& candidate) { | 198 void OnCandidate(const Candidate& candidate) override { |
198 channel_->OnCandidate(candidate); | 199 channel_->OnCandidate(candidate); |
199 } | 200 } |
200 | 201 |
201 void SetReceivingTimeout(int receiving_timeout_ms) { | 202 void SetReceivingTimeout(int receiving_timeout_ms) { |
202 channel_->SetReceivingTimeout(receiving_timeout_ms); | 203 channel_->SetReceivingTimeout(receiving_timeout_ms); |
203 } | 204 } |
204 | 205 |
205 // Needed by DtlsTransport. | 206 // Needed by DtlsTransport. |
206 TransportChannelImpl* channel() { return channel_; } | 207 TransportChannelImpl* channel() { return channel_; } |
207 | 208 |
(...skipping 15 matching lines...) Expand all Loading... |
223 void OnRouteChange(TransportChannel* channel, const Candidate& candidate); | 224 void OnRouteChange(TransportChannel* channel, const Candidate& candidate); |
224 void OnConnectionRemoved(TransportChannelImpl* channel); | 225 void OnConnectionRemoved(TransportChannelImpl* channel); |
225 | 226 |
226 Transport* transport_; // The transport_ that created us. | 227 Transport* transport_; // The transport_ that created us. |
227 rtc::Thread* worker_thread_; // Everything should occur on this thread. | 228 rtc::Thread* worker_thread_; // Everything should occur on this thread. |
228 TransportChannelImpl* channel_; // Underlying channel, owned by transport_. | 229 TransportChannelImpl* channel_; // Underlying channel, owned by transport_. |
229 rtc::scoped_ptr<rtc::SSLStreamAdapter> dtls_; // The DTLS stream | 230 rtc::scoped_ptr<rtc::SSLStreamAdapter> dtls_; // The DTLS stream |
230 StreamInterfaceChannel* downward_; // Wrapper for channel_, owned by dtls_. | 231 StreamInterfaceChannel* downward_; // Wrapper for channel_, owned by dtls_. |
231 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. |
232 State dtls_state_; | 233 State dtls_state_; |
233 rtc::SSLIdentity* local_identity_; | 234 rtc::scoped_refptr<rtc::RTCCertificate> local_certificate_; |
234 rtc::SSLRole ssl_role_; | 235 rtc::SSLRole ssl_role_; |
235 rtc::SSLProtocolVersion ssl_max_version_; | 236 rtc::SSLProtocolVersion ssl_max_version_; |
236 rtc::Buffer remote_fingerprint_value_; | 237 rtc::Buffer remote_fingerprint_value_; |
237 std::string remote_fingerprint_algorithm_; | 238 std::string remote_fingerprint_algorithm_; |
238 | 239 |
239 DISALLOW_COPY_AND_ASSIGN(DtlsTransportChannelWrapper); | 240 DISALLOW_COPY_AND_ASSIGN(DtlsTransportChannelWrapper); |
240 }; | 241 }; |
241 | 242 |
242 } // namespace cricket | 243 } // namespace cricket |
243 | 244 |
244 #endif // WEBRTC_P2P_BASE_DTLSTRANSPORTCHANNEL_H_ | 245 #endif // WEBRTC_P2P_BASE_DTLSTRANSPORTCHANNEL_H_ |
OLD | NEW |