Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 // of doing candidates) | 328 // of doing candidates) |
| 329 class FakeTransport : public Transport { | 329 class FakeTransport : public Transport { |
| 330 public: | 330 public: |
| 331 typedef std::map<int, FakeTransportChannel*> ChannelMap; | 331 typedef std::map<int, FakeTransportChannel*> ChannelMap; |
| 332 FakeTransport(rtc::Thread* signaling_thread, | 332 FakeTransport(rtc::Thread* signaling_thread, |
| 333 rtc::Thread* worker_thread, | 333 rtc::Thread* worker_thread, |
| 334 const std::string& content_name, | 334 const std::string& content_name, |
| 335 PortAllocator* alllocator = NULL) | 335 PortAllocator* alllocator = NULL) |
| 336 : Transport(signaling_thread, worker_thread, | 336 : Transport(signaling_thread, worker_thread, |
| 337 content_name, NULL), | 337 content_name, NULL), |
| 338 dest_(NULL), | 338 dest_(NULL), |
|
tommi
2015/08/25 10:28:08
nit: can you fix the indent here?
hbos
2015/08/25 15:45:44
Done.
| |
| 339 async_(false), | 339 async_(false) { |
| 340 identity_(NULL) { | |
| 341 } | 340 } |
| 342 ~FakeTransport() { | 341 ~FakeTransport() { |
| 343 DestroyAllChannels(); | 342 DestroyAllChannels(); |
| 344 } | 343 } |
| 345 | 344 |
| 346 const ChannelMap& channels() const { return channels_; } | 345 const ChannelMap& channels() const { return channels_; } |
| 347 | 346 |
| 348 void SetAsync(bool async) { async_ = async; } | 347 void SetAsync(bool async) { async_ = async; } |
| 349 void SetDestination(FakeTransport* dest) { | 348 void SetDestination(FakeTransport* dest) { |
| 350 dest_ = dest; | 349 dest_ = dest; |
| 351 for (ChannelMap::iterator it = channels_.begin(); it != channels_.end(); | 350 for (ChannelMap::iterator it = channels_.begin(); it != channels_.end(); |
| 352 ++it) { | 351 ++it) { |
| 353 it->second->SetLocalIdentity(identity_); | 352 // TODO(hbos): SetLocalCertificate |
| 353 it->second->SetLocalIdentity( | |
| 354 certificate_ ? certificate_->identity() : nullptr); | |
| 354 SetChannelDestination(it->first, it->second); | 355 SetChannelDestination(it->first, it->second); |
| 355 } | 356 } |
| 356 } | 357 } |
| 357 | 358 |
| 358 void SetWritable(bool writable) { | 359 void SetWritable(bool writable) { |
| 359 for (ChannelMap::iterator it = channels_.begin(); it != channels_.end(); | 360 for (ChannelMap::iterator it = channels_.begin(); it != channels_.end(); |
| 360 ++it) { | 361 ++it) { |
| 361 it->second->SetWritable(writable); | 362 it->second->SetWritable(writable); |
| 362 } | 363 } |
| 363 } | 364 } |
| 364 | 365 |
| 365 void set_identity(rtc::SSLIdentity* identity) { | 366 void set_certificate( |
| 366 identity_ = identity; | 367 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) { |
| 368 certificate_ = certificate; | |
| 367 } | 369 } |
| 368 | 370 |
| 369 using Transport::local_description; | 371 using Transport::local_description; |
| 370 using Transport::remote_description; | 372 using Transport::remote_description; |
| 371 | 373 |
| 372 protected: | 374 protected: |
| 373 virtual TransportChannelImpl* CreateTransportChannel(int component) { | 375 virtual TransportChannelImpl* CreateTransportChannel(int component) { |
| 374 if (channels_.find(component) != channels_.end()) { | 376 if (channels_.find(component) != channels_.end()) { |
| 375 return NULL; | 377 return NULL; |
| 376 } | 378 } |
| 377 FakeTransportChannel* channel = | 379 FakeTransportChannel* channel = |
| 378 new FakeTransportChannel(this, content_name(), component); | 380 new FakeTransportChannel(this, content_name(), component); |
| 379 channel->SetAsync(async_); | 381 channel->SetAsync(async_); |
| 380 SetChannelDestination(component, channel); | 382 SetChannelDestination(component, channel); |
| 381 channels_[component] = channel; | 383 channels_[component] = channel; |
| 382 return channel; | 384 return channel; |
| 383 } | 385 } |
| 384 virtual void DestroyTransportChannel(TransportChannelImpl* channel) { | 386 virtual void DestroyTransportChannel(TransportChannelImpl* channel) { |
| 385 channels_.erase(channel->component()); | 387 channels_.erase(channel->component()); |
| 386 delete channel; | 388 delete channel; |
| 387 } | 389 } |
| 388 virtual void SetIdentity_w(rtc::SSLIdentity* identity) { | 390 void SetCertificate_w( |
| 389 identity_ = identity; | 391 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override { |
| 392 certificate_ = certificate; | |
|
tommi
2015/08/25 10:28:08
there should be thread checks in this implementati
hbos
2015/08/25 15:45:44
Added a TODO.
| |
| 390 } | 393 } |
| 391 virtual bool GetIdentity_w(rtc::SSLIdentity** identity) { | 394 bool GetCertificate_w( |
| 392 if (!identity_) | 395 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) override { |
| 396 if (!certificate_) | |
| 393 return false; | 397 return false; |
| 394 | 398 |
| 395 *identity = identity_->GetReference(); | 399 *certificate = certificate_; |
| 396 return true; | 400 return true; |
| 397 } | 401 } |
| 398 | 402 |
| 399 private: | 403 private: |
| 400 FakeTransportChannel* GetFakeChannel(int component) { | 404 FakeTransportChannel* GetFakeChannel(int component) { |
| 401 ChannelMap::iterator it = channels_.find(component); | 405 ChannelMap::iterator it = channels_.find(component); |
| 402 return (it != channels_.end()) ? it->second : NULL; | 406 return (it != channels_.end()) ? it->second : NULL; |
| 403 } | 407 } |
| 404 void SetChannelDestination(int component, | 408 void SetChannelDestination(int component, |
| 405 FakeTransportChannel* channel) { | 409 FakeTransportChannel* channel) { |
| 406 FakeTransportChannel* dest_channel = NULL; | 410 FakeTransportChannel* dest_channel = NULL; |
| 407 if (dest_) { | 411 if (dest_) { |
| 408 dest_channel = dest_->GetFakeChannel(component); | 412 dest_channel = dest_->GetFakeChannel(component); |
| 409 if (dest_channel) { | 413 if (dest_channel) { |
| 410 dest_channel->SetLocalIdentity(dest_->identity_); | 414 // TODO(hbos): SetLocalCertificate |
| 415 dest_channel->SetLocalIdentity( | |
| 416 dest_->certificate_ ? dest_->certificate_->identity() : nullptr); | |
| 411 } | 417 } |
| 412 } | 418 } |
| 413 channel->SetDestination(dest_channel); | 419 channel->SetDestination(dest_channel); |
| 414 } | 420 } |
| 415 | 421 |
| 416 // Note, this is distinct from the Channel map owned by Transport. | 422 // Note, this is distinct from the Channel map owned by Transport. |
| 417 // This map just tracks the FakeTransportChannels created by this class. | 423 // This map just tracks the FakeTransportChannels created by this class. |
| 418 ChannelMap channels_; | 424 ChannelMap channels_; |
| 419 FakeTransport* dest_; | 425 FakeTransport* dest_; |
| 420 bool async_; | 426 bool async_; |
| 421 rtc::SSLIdentity* identity_; | 427 rtc::scoped_refptr<rtc::RTCCertificate> certificate_; |
| 422 }; | 428 }; |
| 423 | 429 |
| 424 // Fake session class, which can be passed into a BaseChannel object for | 430 // Fake session class, which can be passed into a BaseChannel object for |
| 425 // test purposes. Can be connected to other FakeSessions via Connect(). | 431 // test purposes. Can be connected to other FakeSessions via Connect(). |
| 426 class FakeSession : public BaseSession { | 432 class FakeSession : public BaseSession { |
| 427 public: | 433 public: |
| 428 explicit FakeSession() | 434 explicit FakeSession() |
| 429 : BaseSession(rtc::Thread::Current(), | 435 : BaseSession(rtc::Thread::Current(), |
| 430 rtc::Thread::Current(), | 436 rtc::Thread::Current(), |
| 431 NULL, "", "", true), | 437 NULL, "", "", true), |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 467 return NULL; | 473 return NULL; |
| 468 } | 474 } |
| 469 return BaseSession::CreateChannel(content_name, component); | 475 return BaseSession::CreateChannel(content_name, component); |
| 470 } | 476 } |
| 471 | 477 |
| 472 void set_fail_channel_creation(bool fail_channel_creation) { | 478 void set_fail_channel_creation(bool fail_channel_creation) { |
| 473 fail_create_channel_ = fail_channel_creation; | 479 fail_create_channel_ = fail_channel_creation; |
| 474 } | 480 } |
| 475 | 481 |
| 476 // TODO: Hoist this into Session when we re-work the Session code. | 482 // TODO: Hoist this into Session when we re-work the Session code. |
| 477 void set_ssl_identity(rtc::SSLIdentity* identity) { | 483 void set_ssl_rtccertificate( |
| 484 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) { | |
| 478 for (TransportMap::const_iterator it = transport_proxies().begin(); | 485 for (TransportMap::const_iterator it = transport_proxies().begin(); |
| 479 it != transport_proxies().end(); ++it) { | 486 it != transport_proxies().end(); ++it) { |
| 480 // We know that we have a FakeTransport* | 487 // We know that we have a FakeTransport* |
| 481 | 488 |
| 482 static_cast<FakeTransport*>(it->second->impl())->set_identity | 489 static_cast<FakeTransport*>(it->second->impl())->set_certificate |
| 483 (identity); | 490 (certificate); |
| 484 } | 491 } |
| 485 } | 492 } |
| 486 | 493 |
| 487 protected: | 494 protected: |
| 488 virtual Transport* CreateTransport(const std::string& content_name) { | 495 virtual Transport* CreateTransport(const std::string& content_name) { |
| 489 return new FakeTransport(signaling_thread(), worker_thread(), content_name); | 496 return new FakeTransport(signaling_thread(), worker_thread(), content_name); |
| 490 } | 497 } |
| 491 | 498 |
| 492 void CompleteNegotiation() { | 499 void CompleteNegotiation() { |
| 493 for (TransportMap::const_iterator it = transport_proxies().begin(); | 500 for (TransportMap::const_iterator it = transport_proxies().begin(); |
| 494 it != transport_proxies().end(); ++it) { | 501 it != transport_proxies().end(); ++it) { |
| 495 it->second->CompleteNegotiation(); | 502 it->second->CompleteNegotiation(); |
| 496 it->second->ConnectChannels(); | 503 it->second->ConnectChannels(); |
| 497 } | 504 } |
| 498 } | 505 } |
| 499 | 506 |
| 500 private: | 507 private: |
| 501 bool fail_create_channel_; | 508 bool fail_create_channel_; |
| 502 }; | 509 }; |
| 503 | 510 |
| 504 } // namespace cricket | 511 } // namespace cricket |
| 505 | 512 |
| 506 #endif // WEBRTC_P2P_BASE_FAKESESSION_H_ | 513 #endif // WEBRTC_P2P_BASE_FAKESESSION_H_ |
| OLD | NEW |