Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: webrtc/p2p/base/fakesession.h

Issue 1304043008: Replacing SSLIdentity* with scoped_refptr<RTCCertificate> in TransportChannel layer (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2009 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 29 matching lines...) Expand all
40 // SetDestination. 40 // SetDestination.
41 // TODO(hbos): Move implementation to .cc file, this and other classes in file. 41 // TODO(hbos): Move implementation to .cc file, this and other classes in file.
42 class FakeTransportChannel : public TransportChannelImpl, 42 class FakeTransportChannel : public TransportChannelImpl,
43 public rtc::MessageHandler { 43 public rtc::MessageHandler {
44 public: 44 public:
45 explicit FakeTransportChannel(Transport* transport, 45 explicit FakeTransportChannel(Transport* transport,
46 const std::string& content_name, 46 const std::string& content_name,
47 int component) 47 int component)
48 : TransportChannelImpl(content_name, component), 48 : TransportChannelImpl(content_name, component),
49 transport_(transport), 49 transport_(transport),
50 dest_(NULL), 50 dest_(nullptr),
51 state_(STATE_INIT), 51 state_(STATE_INIT),
52 async_(false), 52 async_(false),
53 identity_(NULL), 53 certificate_(nullptr),
tommi 2015/09/03 20:06:04 no need to include in initializer list
hbos 2015/09/07 08:11:01 Done.
54 do_dtls_(false), 54 do_dtls_(false),
55 role_(ICEROLE_UNKNOWN), 55 role_(ICEROLE_UNKNOWN),
56 tiebreaker_(0), 56 tiebreaker_(0),
57 remote_ice_mode_(ICEMODE_FULL), 57 remote_ice_mode_(ICEMODE_FULL),
58 dtls_fingerprint_("", NULL, 0), 58 dtls_fingerprint_("", nullptr, 0),
59 ssl_role_(rtc::SSL_CLIENT), 59 ssl_role_(rtc::SSL_CLIENT),
60 connection_count_(0) { 60 connection_count_(0) {
61 } 61 }
62 ~FakeTransportChannel() { 62 ~FakeTransportChannel() {
63 Reset(); 63 Reset();
64 } 64 }
65 65
66 uint64 IceTiebreaker() const { return tiebreaker_; } 66 uint64 IceTiebreaker() const { return tiebreaker_; }
67 IceMode remote_ice_mode() const { return remote_ice_mode_; } 67 IceMode remote_ice_mode() const { return remote_ice_mode_; }
68 const std::string& ice_ufrag() const { return ice_ufrag_; } 68 const std::string& ice_ufrag() const { return ice_ufrag_; }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 140
141 void SetWritable(bool writable) { 141 void SetWritable(bool writable) {
142 set_writable(writable); 142 set_writable(writable);
143 } 143 }
144 144
145 void SetDestination(FakeTransportChannel* dest) { 145 void SetDestination(FakeTransportChannel* dest) {
146 if (state_ == STATE_CONNECTING && dest) { 146 if (state_ == STATE_CONNECTING && dest) {
147 // This simulates the delivery of candidates. 147 // This simulates the delivery of candidates.
148 dest_ = dest; 148 dest_ = dest;
149 dest_->dest_ = this; 149 dest_->dest_ = this;
150 if (identity_ && dest_->identity_) { 150 if (certificate_ && dest_->certificate_) {
151 do_dtls_ = true; 151 do_dtls_ = true;
152 dest_->do_dtls_ = true; 152 dest_->do_dtls_ = true;
153 NegotiateSrtpCiphers(); 153 NegotiateSrtpCiphers();
154 } 154 }
155 state_ = STATE_CONNECTED; 155 state_ = STATE_CONNECTED;
156 dest_->state_ = STATE_CONNECTED; 156 dest_->state_ = STATE_CONNECTED;
157 set_writable(true); 157 set_writable(true);
158 dest_->set_writable(true); 158 dest_->set_writable(true);
159 } else if (state_ == STATE_CONNECTED && !dest) { 159 } else if (state_ == STATE_CONNECTED && !dest) {
160 // Simulates loss of connectivity, by asymmetrically forgetting dest_. 160 // Simulates loss of connectivity, by asymmetrically forgetting dest_.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 } 211 }
212 212
213 virtual void OnMessage(rtc::Message* msg) { 213 virtual void OnMessage(rtc::Message* msg) {
214 PacketMessageData* data = static_cast<PacketMessageData*>( 214 PacketMessageData* data = static_cast<PacketMessageData*>(
215 msg->pdata); 215 msg->pdata);
216 dest_->SignalReadPacket(dest_, data->packet.data<char>(), 216 dest_->SignalReadPacket(dest_, data->packet.data<char>(),
217 data->packet.size(), rtc::CreatePacketTime(0), 0); 217 data->packet.size(), rtc::CreatePacketTime(0), 0);
218 delete data; 218 delete data;
219 } 219 }
220 220
221 bool SetLocalIdentity(rtc::SSLIdentity* identity) { 221 bool SetLocalCertificate(
222 identity_ = identity; 222 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override {
223 certificate_ = certificate;
223 return true; 224 return true;
224 } 225 }
225 226
226 227 void SetRemoteSSLCertificate(rtc::FakeSSLCertificate* cert) {
227 void SetRemoteCertificate(rtc::FakeSSLCertificate* cert) {
228 remote_cert_ = cert; 228 remote_cert_ = cert;
229 } 229 }
230 230
231 virtual bool IsDtlsActive() const { 231 virtual bool IsDtlsActive() const {
232 return do_dtls_; 232 return do_dtls_;
233 } 233 }
234 234
235 virtual bool SetSrtpCiphers(const std::vector<std::string>& ciphers) { 235 virtual bool SetSrtpCiphers(const std::vector<std::string>& ciphers) {
236 srtp_ciphers_ = ciphers; 236 srtp_ciphers_ = ciphers;
237 return true; 237 return true;
238 } 238 }
239 239
240 virtual bool GetSrtpCipher(std::string* cipher) { 240 virtual bool GetSrtpCipher(std::string* cipher) {
241 if (!chosen_srtp_cipher_.empty()) { 241 if (!chosen_srtp_cipher_.empty()) {
242 *cipher = chosen_srtp_cipher_; 242 *cipher = chosen_srtp_cipher_;
243 return true; 243 return true;
244 } 244 }
245 return false; 245 return false;
246 } 246 }
247 247
248 virtual bool GetSslCipher(std::string* cipher) { 248 virtual bool GetSslCipher(std::string* cipher) {
249 return false; 249 return false;
250 } 250 }
251 251
252 virtual bool GetLocalIdentity(rtc::SSLIdentity** identity) const { 252 bool GetLocalCertificate(
253 if (!identity_) 253 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) const override {
tommi 2015/09/03 20:06:04 I wonder if we should just change this method to r
hbos 2015/09/07 08:11:01 Done, except I made it (non-const non-ref) scoped_
254 if (!certificate_)
254 return false; 255 return false;
255 256
256 *identity = identity_->GetReference(); 257 *certificate = certificate_;
257 return true; 258 return true;
258 } 259 }
259 260
260 virtual bool GetRemoteCertificate(rtc::SSLCertificate** cert) const { 261 bool GetRemoteSSLCertificate(rtc::SSLCertificate** cert) const override {
261 if (!remote_cert_) 262 if (!remote_cert_)
262 return false; 263 return false;
263 264
264 *cert = remote_cert_->GetReference(); 265 *cert = remote_cert_->GetReference();
265 return true; 266 return true;
266 } 267 }
267 268
268 virtual bool ExportKeyingMaterial(const std::string& label, 269 virtual bool ExportKeyingMaterial(const std::string& label,
269 const uint8* context, 270 const uint8* context,
270 size_t context_len, 271 size_t context_len,
(...skipping 29 matching lines...) Expand all
300 infos->push_back(info); 301 infos->push_back(info);
301 return true; 302 return true;
302 } 303 }
303 304
304 private: 305 private:
305 enum State { STATE_INIT, STATE_CONNECTING, STATE_CONNECTED }; 306 enum State { STATE_INIT, STATE_CONNECTING, STATE_CONNECTED };
306 Transport* transport_; 307 Transport* transport_;
307 FakeTransportChannel* dest_; 308 FakeTransportChannel* dest_;
308 State state_; 309 State state_;
309 bool async_; 310 bool async_;
310 rtc::SSLIdentity* identity_; 311 rtc::scoped_refptr<rtc::RTCCertificate> certificate_;
311 rtc::FakeSSLCertificate* remote_cert_; 312 rtc::FakeSSLCertificate* remote_cert_;
312 bool do_dtls_; 313 bool do_dtls_;
313 std::vector<std::string> srtp_ciphers_; 314 std::vector<std::string> srtp_ciphers_;
314 std::string chosen_srtp_cipher_; 315 std::string chosen_srtp_cipher_;
315 IceRole role_; 316 IceRole role_;
316 uint64 tiebreaker_; 317 uint64 tiebreaker_;
317 std::string ice_ufrag_; 318 std::string ice_ufrag_;
318 std::string ice_pwd_; 319 std::string ice_pwd_;
319 std::string remote_ice_ufrag_; 320 std::string remote_ice_ufrag_;
320 std::string remote_ice_pwd_; 321 std::string remote_ice_pwd_;
(...skipping 22 matching lines...) Expand all
343 DestroyAllChannels(); 344 DestroyAllChannels();
344 } 345 }
345 346
346 const ChannelMap& channels() const { return channels_; } 347 const ChannelMap& channels() const { return channels_; }
347 348
348 void SetAsync(bool async) { async_ = async; } 349 void SetAsync(bool async) { async_ = async; }
349 void SetDestination(FakeTransport* dest) { 350 void SetDestination(FakeTransport* dest) {
350 dest_ = dest; 351 dest_ = dest;
351 for (ChannelMap::iterator it = channels_.begin(); it != channels_.end(); 352 for (ChannelMap::iterator it = channels_.begin(); it != channels_.end();
352 ++it) { 353 ++it) {
353 // TODO(hbos): SetLocalCertificate 354 it->second->SetLocalCertificate(certificate_);
354 it->second->SetLocalIdentity(
355 certificate_ ? certificate_->identity() : nullptr);
356 SetChannelDestination(it->first, it->second); 355 SetChannelDestination(it->first, it->second);
357 } 356 }
358 } 357 }
359 358
360 void SetWritable(bool writable) { 359 void SetWritable(bool writable) {
361 for (ChannelMap::iterator it = channels_.begin(); it != channels_.end(); 360 for (ChannelMap::iterator it = channels_.begin(); it != channels_.end();
362 ++it) { 361 ++it) {
363 it->second->SetWritable(writable); 362 it->second->SetWritable(writable);
364 } 363 }
365 } 364 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 private: 403 private:
405 FakeTransportChannel* GetFakeChannel(int component) { 404 FakeTransportChannel* GetFakeChannel(int component) {
406 ChannelMap::iterator it = channels_.find(component); 405 ChannelMap::iterator it = channels_.find(component);
407 return (it != channels_.end()) ? it->second : NULL; 406 return (it != channels_.end()) ? it->second : NULL;
408 } 407 }
409 void SetChannelDestination(int component, 408 void SetChannelDestination(int component,
410 FakeTransportChannel* channel) { 409 FakeTransportChannel* channel) {
411 FakeTransportChannel* dest_channel = NULL; 410 FakeTransportChannel* dest_channel = NULL;
412 if (dest_) { 411 if (dest_) {
413 dest_channel = dest_->GetFakeChannel(component); 412 dest_channel = dest_->GetFakeChannel(component);
414 if (dest_channel) { 413 if (dest_channel)
415 // TODO(hbos): SetLocalCertificate 414 dest_channel->SetLocalCertificate(dest_->certificate_);
416 dest_channel->SetLocalIdentity(
417 dest_->certificate_ ? dest_->certificate_->identity() : nullptr);
418 }
419 } 415 }
420 channel->SetDestination(dest_channel); 416 channel->SetDestination(dest_channel);
421 } 417 }
422 418
423 // Note, this is distinct from the Channel map owned by Transport. 419 // Note, this is distinct from the Channel map owned by Transport.
424 // This map just tracks the FakeTransportChannels created by this class. 420 // This map just tracks the FakeTransportChannels created by this class.
425 ChannelMap channels_; 421 ChannelMap channels_;
426 FakeTransport* dest_; 422 FakeTransport* dest_;
427 bool async_; 423 bool async_;
428 rtc::scoped_refptr<rtc::RTCCertificate> certificate_; 424 rtc::scoped_refptr<rtc::RTCCertificate> certificate_;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 } 501 }
506 } 502 }
507 503
508 private: 504 private:
509 bool fail_create_channel_; 505 bool fail_create_channel_;
510 }; 506 };
511 507
512 } // namespace cricket 508 } // namespace cricket
513 509
514 #endif // WEBRTC_P2P_BASE_FAKESESSION_H_ 510 #endif // WEBRTC_P2P_BASE_FAKESESSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698