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

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

Issue 1312643004: Replaces SSLIdentity* with scoped_refptr<RTCCertificate> in cricket::Transport layer. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: certificate_for_testing() 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
« no previous file with comments | « webrtc/p2p/base/dtlstransportchannel_unittest.cc ('k') | webrtc/p2p/base/session.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 20 matching lines...) Expand all
31 31
32 struct PacketMessageData : public rtc::MessageData { 32 struct PacketMessageData : public rtc::MessageData {
33 PacketMessageData(const char* data, size_t len) : packet(data, len) { 33 PacketMessageData(const char* data, size_t len) : packet(data, len) {
34 } 34 }
35 rtc::Buffer packet; 35 rtc::Buffer packet;
36 }; 36 };
37 37
38 // Fake transport channel class, which can be passed to anything that needs a 38 // Fake transport channel class, which can be passed to anything that needs a
39 // transport channel. Can be informed of another FakeTransportChannel via 39 // transport channel. Can be informed of another FakeTransportChannel via
40 // SetDestination. 40 // SetDestination.
41 // TODO(hbos): Move implementation to .cc file, this and other classes in file.
41 class FakeTransportChannel : public TransportChannelImpl, 42 class FakeTransportChannel : public TransportChannelImpl,
42 public rtc::MessageHandler { 43 public rtc::MessageHandler {
43 public: 44 public:
44 explicit FakeTransportChannel(Transport* transport, 45 explicit FakeTransportChannel(Transport* transport,
45 const std::string& content_name, 46 const std::string& content_name,
46 int component) 47 int component)
47 : TransportChannelImpl(content_name, component), 48 : TransportChannelImpl(content_name, component),
48 transport_(transport), 49 transport_(transport),
49 dest_(NULL), 50 dest_(NULL),
50 state_(STATE_INIT), 51 state_(STATE_INIT),
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 326
326 // Fake transport class, which can be passed to anything that needs a Transport. 327 // Fake transport class, which can be passed to anything that needs a Transport.
327 // Can be informed of another FakeTransport via SetDestination (low-tech way 328 // Can be informed of another FakeTransport via SetDestination (low-tech way
328 // of doing candidates) 329 // of doing candidates)
329 class FakeTransport : public Transport { 330 class FakeTransport : public Transport {
330 public: 331 public:
331 typedef std::map<int, FakeTransportChannel*> ChannelMap; 332 typedef std::map<int, FakeTransportChannel*> ChannelMap;
332 FakeTransport(rtc::Thread* signaling_thread, 333 FakeTransport(rtc::Thread* signaling_thread,
333 rtc::Thread* worker_thread, 334 rtc::Thread* worker_thread,
334 const std::string& content_name, 335 const std::string& content_name,
335 PortAllocator* alllocator = NULL) 336 PortAllocator* alllocator = nullptr)
336 : Transport(signaling_thread, worker_thread, 337 : Transport(signaling_thread, worker_thread,
337 content_name, NULL), 338 content_name, nullptr),
338 dest_(NULL), 339 dest_(nullptr),
339 async_(false), 340 async_(false) {
340 identity_(NULL) {
341 } 341 }
342 ~FakeTransport() { 342 ~FakeTransport() {
343 DestroyAllChannels(); 343 DestroyAllChannels();
344 } 344 }
345 345
346 const ChannelMap& channels() const { return channels_; } 346 const ChannelMap& channels() const { return channels_; }
347 347
348 void SetAsync(bool async) { async_ = async; } 348 void SetAsync(bool async) { async_ = async; }
349 void SetDestination(FakeTransport* dest) { 349 void SetDestination(FakeTransport* dest) {
350 dest_ = dest; 350 dest_ = dest;
351 for (ChannelMap::iterator it = channels_.begin(); it != channels_.end(); 351 for (ChannelMap::iterator it = channels_.begin(); it != channels_.end();
352 ++it) { 352 ++it) {
353 it->second->SetLocalIdentity(identity_); 353 // TODO(hbos): SetLocalCertificate
354 it->second->SetLocalIdentity(
355 certificate_ ? certificate_->identity() : nullptr);
354 SetChannelDestination(it->first, it->second); 356 SetChannelDestination(it->first, it->second);
355 } 357 }
356 } 358 }
357 359
358 void SetWritable(bool writable) { 360 void SetWritable(bool writable) {
359 for (ChannelMap::iterator it = channels_.begin(); it != channels_.end(); 361 for (ChannelMap::iterator it = channels_.begin(); it != channels_.end();
360 ++it) { 362 ++it) {
361 it->second->SetWritable(writable); 363 it->second->SetWritable(writable);
362 } 364 }
363 } 365 }
364 366
365 void set_identity(rtc::SSLIdentity* identity) { 367 void set_certificate(
366 identity_ = identity; 368 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) {
369 certificate_ = certificate;
367 } 370 }
368 371
369 using Transport::local_description; 372 using Transport::local_description;
370 using Transport::remote_description; 373 using Transport::remote_description;
371 374
372 protected: 375 protected:
373 virtual TransportChannelImpl* CreateTransportChannel(int component) { 376 virtual TransportChannelImpl* CreateTransportChannel(int component) {
374 if (channels_.find(component) != channels_.end()) { 377 if (channels_.find(component) != channels_.end()) {
375 return NULL; 378 return NULL;
376 } 379 }
377 FakeTransportChannel* channel = 380 FakeTransportChannel* channel =
378 new FakeTransportChannel(this, content_name(), component); 381 new FakeTransportChannel(this, content_name(), component);
379 channel->SetAsync(async_); 382 channel->SetAsync(async_);
380 SetChannelDestination(component, channel); 383 SetChannelDestination(component, channel);
381 channels_[component] = channel; 384 channels_[component] = channel;
382 return channel; 385 return channel;
383 } 386 }
384 virtual void DestroyTransportChannel(TransportChannelImpl* channel) { 387 virtual void DestroyTransportChannel(TransportChannelImpl* channel) {
385 channels_.erase(channel->component()); 388 channels_.erase(channel->component());
386 delete channel; 389 delete channel;
387 } 390 }
388 virtual void SetIdentity_w(rtc::SSLIdentity* identity) { 391 void SetCertificate_w(
389 identity_ = identity; 392 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override {
393 certificate_ = certificate;
390 } 394 }
391 virtual bool GetIdentity_w(rtc::SSLIdentity** identity) { 395 bool GetCertificate_w(
392 if (!identity_) 396 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) override {
397 if (!certificate_)
393 return false; 398 return false;
394 399
395 *identity = identity_->GetReference(); 400 *certificate = certificate_;
396 return true; 401 return true;
397 } 402 }
398 403
399 private: 404 private:
400 FakeTransportChannel* GetFakeChannel(int component) { 405 FakeTransportChannel* GetFakeChannel(int component) {
401 ChannelMap::iterator it = channels_.find(component); 406 ChannelMap::iterator it = channels_.find(component);
402 return (it != channels_.end()) ? it->second : NULL; 407 return (it != channels_.end()) ? it->second : NULL;
403 } 408 }
404 void SetChannelDestination(int component, 409 void SetChannelDestination(int component,
405 FakeTransportChannel* channel) { 410 FakeTransportChannel* channel) {
406 FakeTransportChannel* dest_channel = NULL; 411 FakeTransportChannel* dest_channel = NULL;
407 if (dest_) { 412 if (dest_) {
408 dest_channel = dest_->GetFakeChannel(component); 413 dest_channel = dest_->GetFakeChannel(component);
409 if (dest_channel) { 414 if (dest_channel) {
410 dest_channel->SetLocalIdentity(dest_->identity_); 415 // TODO(hbos): SetLocalCertificate
416 dest_channel->SetLocalIdentity(
417 dest_->certificate_ ? dest_->certificate_->identity() : nullptr);
411 } 418 }
412 } 419 }
413 channel->SetDestination(dest_channel); 420 channel->SetDestination(dest_channel);
414 } 421 }
415 422
416 // Note, this is distinct from the Channel map owned by Transport. 423 // Note, this is distinct from the Channel map owned by Transport.
417 // This map just tracks the FakeTransportChannels created by this class. 424 // This map just tracks the FakeTransportChannels created by this class.
418 ChannelMap channels_; 425 ChannelMap channels_;
419 FakeTransport* dest_; 426 FakeTransport* dest_;
420 bool async_; 427 bool async_;
421 rtc::SSLIdentity* identity_; 428 rtc::scoped_refptr<rtc::RTCCertificate> certificate_;
422 }; 429 };
423 430
424 // Fake session class, which can be passed into a BaseChannel object for 431 // Fake session class, which can be passed into a BaseChannel object for
425 // test purposes. Can be connected to other FakeSessions via Connect(). 432 // test purposes. Can be connected to other FakeSessions via Connect().
426 class FakeSession : public BaseSession { 433 class FakeSession : public BaseSession {
427 public: 434 public:
428 explicit FakeSession() 435 explicit FakeSession()
429 : BaseSession(rtc::Thread::Current(), 436 : BaseSession(rtc::Thread::Current(),
430 rtc::Thread::Current(), 437 rtc::Thread::Current(),
431 NULL, "", "", true), 438 NULL, "", "", true),
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 return NULL; 474 return NULL;
468 } 475 }
469 return BaseSession::CreateChannel(content_name, component); 476 return BaseSession::CreateChannel(content_name, component);
470 } 477 }
471 478
472 void set_fail_channel_creation(bool fail_channel_creation) { 479 void set_fail_channel_creation(bool fail_channel_creation) {
473 fail_create_channel_ = fail_channel_creation; 480 fail_create_channel_ = fail_channel_creation;
474 } 481 }
475 482
476 // TODO: Hoist this into Session when we re-work the Session code. 483 // TODO: Hoist this into Session when we re-work the Session code.
477 void set_ssl_identity(rtc::SSLIdentity* identity) { 484 void set_ssl_rtccertificate(
485 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) {
478 for (TransportMap::const_iterator it = transport_proxies().begin(); 486 for (TransportMap::const_iterator it = transport_proxies().begin();
479 it != transport_proxies().end(); ++it) { 487 it != transport_proxies().end(); ++it) {
480 // We know that we have a FakeTransport* 488 // We know that we have a FakeTransport*
481 489
482 static_cast<FakeTransport*>(it->second->impl())->set_identity 490 static_cast<FakeTransport*>(it->second->impl())->set_certificate
483 (identity); 491 (certificate);
484 } 492 }
485 } 493 }
486 494
487 protected: 495 protected:
488 virtual Transport* CreateTransport(const std::string& content_name) { 496 virtual Transport* CreateTransport(const std::string& content_name) {
489 return new FakeTransport(signaling_thread(), worker_thread(), content_name); 497 return new FakeTransport(signaling_thread(), worker_thread(), content_name);
490 } 498 }
491 499
492 void CompleteNegotiation() { 500 void CompleteNegotiation() {
493 for (TransportMap::const_iterator it = transport_proxies().begin(); 501 for (TransportMap::const_iterator it = transport_proxies().begin();
494 it != transport_proxies().end(); ++it) { 502 it != transport_proxies().end(); ++it) {
495 it->second->CompleteNegotiation(); 503 it->second->CompleteNegotiation();
496 it->second->ConnectChannels(); 504 it->second->ConnectChannels();
497 } 505 }
498 } 506 }
499 507
500 private: 508 private:
501 bool fail_create_channel_; 509 bool fail_create_channel_;
502 }; 510 };
503 511
504 } // namespace cricket 512 } // namespace cricket
505 513
506 #endif // WEBRTC_P2P_BASE_FAKESESSION_H_ 514 #endif // WEBRTC_P2P_BASE_FAKESESSION_H_
OLDNEW
« no previous file with comments | « webrtc/p2p/base/dtlstransportchannel_unittest.cc ('k') | webrtc/p2p/base/session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698