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 11 matching lines...) Expand all Loading... | |
| 22 #include "webrtc/p2p/base/transportcontroller.h" | 22 #include "webrtc/p2p/base/transportcontroller.h" |
| 23 #include "webrtc/p2p/base/transportchannelimpl.h" | 23 #include "webrtc/p2p/base/transportchannelimpl.h" |
| 24 #include "webrtc/base/bind.h" | 24 #include "webrtc/base/bind.h" |
| 25 #include "webrtc/base/buffer.h" | 25 #include "webrtc/base/buffer.h" |
| 26 #include "webrtc/base/fakesslidentity.h" | 26 #include "webrtc/base/fakesslidentity.h" |
| 27 #include "webrtc/base/messagequeue.h" | 27 #include "webrtc/base/messagequeue.h" |
| 28 #include "webrtc/base/sigslot.h" | 28 #include "webrtc/base/sigslot.h" |
| 29 #include "webrtc/base/sslfingerprint.h" | 29 #include "webrtc/base/sslfingerprint.h" |
| 30 #include "webrtc/base/thread.h" | 30 #include "webrtc/base/thread.h" |
| 31 | 31 |
| 32 #ifdef HAVE_QUIC | |
| 33 #include "webrtc/p2p/quic/quictransport.h" | |
| 34 #endif | |
| 35 | |
| 32 namespace cricket { | 36 namespace cricket { |
| 33 | 37 |
| 34 class FakeTransport; | 38 class FakeTransport; |
| 35 | 39 |
| 36 namespace { | 40 namespace { |
| 37 struct PacketMessageData : public rtc::MessageData { | 41 struct PacketMessageData : public rtc::MessageData { |
| 38 PacketMessageData(const char* data, size_t len) : packet(data, len) {} | 42 PacketMessageData(const char* data, size_t len) : packet(data, len) {} |
| 39 rtc::Buffer packet; | 43 rtc::Buffer packet; |
| 40 }; | 44 }; |
| 41 } // namespace | 45 } // namespace |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 446 // This map just tracks the FakeTransportChannels created by this class. | 450 // This map just tracks the FakeTransportChannels created by this class. |
| 447 // It's mainly needed so that we can access a FakeTransportChannel directly, | 451 // It's mainly needed so that we can access a FakeTransportChannel directly, |
| 448 // even if wrapped by a DtlsTransportChannelWrapper. | 452 // even if wrapped by a DtlsTransportChannelWrapper. |
| 449 ChannelMap channels_; | 453 ChannelMap channels_; |
| 450 FakeTransport* dest_ = nullptr; | 454 FakeTransport* dest_ = nullptr; |
| 451 bool async_ = false; | 455 bool async_ = false; |
| 452 rtc::scoped_refptr<rtc::RTCCertificate> certificate_; | 456 rtc::scoped_refptr<rtc::RTCCertificate> certificate_; |
| 453 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12; | 457 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12; |
| 454 }; | 458 }; |
| 455 | 459 |
| 460 #ifdef HAVE_QUIC | |
| 461 class FakeQuicTransport : public QuicTransport { | |
| 462 public: | |
| 463 FakeQuicTransport(const std::string& transport_name, | |
| 464 FakeTransportChannel* fake_ice_transport_channel) | |
| 465 : QuicTransport(transport_name, nullptr, nullptr), | |
| 466 fake_ice_transport_channel_(fake_ice_transport_channel) {} | |
| 467 | |
| 468 protected: | |
| 469 QuicTransportChannel* CreateTransportChannel(int component) override { | |
| 470 LOG(INFO) << "creating quic transport channel:" | |
| 471 << fake_ice_transport_channel_; | |
| 472 return new QuicTransportChannel(fake_ice_transport_channel_); | |
| 473 } | |
| 474 | |
| 475 private: | |
| 476 FakeTransportChannel* fake_ice_transport_channel_; | |
| 477 }; | |
| 478 #endif | |
| 479 | |
| 456 // Fake candidate pair class, which can be passed to BaseChannel for testing | 480 // Fake candidate pair class, which can be passed to BaseChannel for testing |
| 457 // purposes. | 481 // purposes. |
| 458 class FakeCandidatePair : public CandidatePairInterface { | 482 class FakeCandidatePair : public CandidatePairInterface { |
| 459 public: | 483 public: |
| 460 FakeCandidatePair(const Candidate& local_candidate, | 484 FakeCandidatePair(const Candidate& local_candidate, |
| 461 const Candidate& remote_candidate) | 485 const Candidate& remote_candidate) |
| 462 : local_candidate_(local_candidate), | 486 : local_candidate_(local_candidate), |
| 463 remote_candidate_(remote_candidate) {} | 487 remote_candidate_(remote_candidate) {} |
| 464 const Candidate& local_candidate() const override { return local_candidate_; } | 488 const Candidate& local_candidate() const override { return local_candidate_; } |
| 465 const Candidate& remote_candidate() const override { | 489 const Candidate& remote_candidate() const override { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 496 explicit FakeTransportController(rtc::Thread* worker_thread) | 520 explicit FakeTransportController(rtc::Thread* worker_thread) |
| 497 : TransportController(rtc::Thread::Current(), worker_thread, nullptr), | 521 : TransportController(rtc::Thread::Current(), worker_thread, nullptr), |
| 498 fail_create_channel_(false) {} | 522 fail_create_channel_(false) {} |
| 499 | 523 |
| 500 FakeTransportController(rtc::Thread* worker_thread, IceRole role) | 524 FakeTransportController(rtc::Thread* worker_thread, IceRole role) |
| 501 : TransportController(rtc::Thread::Current(), worker_thread, nullptr), | 525 : TransportController(rtc::Thread::Current(), worker_thread, nullptr), |
| 502 fail_create_channel_(false) { | 526 fail_create_channel_(false) { |
| 503 SetIceRole(role); | 527 SetIceRole(role); |
| 504 } | 528 } |
| 505 | 529 |
| 530 FakeTransportController(const std::string& transport_name) | |
| 531 : TransportController(rtc::Thread::Current(), | |
| 532 rtc::Thread::Current(), | |
| 533 nullptr), | |
| 534 fail_create_channel_(false), | |
| 535 fake_ice_transport_channel_( | |
| 536 new FakeTransportChannel(transport_name, 1)) {} | |
| 537 | |
| 506 FakeTransport* GetTransport_n(const std::string& transport_name) { | 538 FakeTransport* GetTransport_n(const std::string& transport_name) { |
| 507 return static_cast<FakeTransport*>( | 539 return static_cast<FakeTransport*>( |
| 508 TransportController::GetTransport_n(transport_name)); | 540 TransportController::GetTransport_n(transport_name)); |
| 509 } | 541 } |
| 510 | 542 |
| 511 void Connect(FakeTransportController* dest) { | 543 void Connect(FakeTransportController* dest) { |
| 512 network_thread()->Invoke<void>( | 544 network_thread()->Invoke<void>( |
| 513 RTC_FROM_HERE, | 545 RTC_FROM_HERE, |
| 514 rtc::Bind(&FakeTransportController::Connect_n, this, dest)); | 546 rtc::Bind(&FakeTransportController::Connect_n, this, dest)); |
| 515 } | 547 } |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 532 "foundation", local_network_id, 0); | 564 "foundation", local_network_id, 0); |
| 533 Candidate remote_candidate(0, "udp", remote_address, 0u, "", "", "local", 0, | 565 Candidate remote_candidate(0, "udp", remote_address, 0u, "", "", "local", 0, |
| 534 "foundation", remote_network_id, 0); | 566 "foundation", remote_network_id, 0); |
| 535 return new FakeCandidatePair(local_candidate, remote_candidate); | 567 return new FakeCandidatePair(local_candidate, remote_candidate); |
| 536 } | 568 } |
| 537 | 569 |
| 538 void set_fail_channel_creation(bool fail_channel_creation) { | 570 void set_fail_channel_creation(bool fail_channel_creation) { |
| 539 fail_create_channel_ = fail_channel_creation; | 571 fail_create_channel_ = fail_channel_creation; |
| 540 } | 572 } |
| 541 | 573 |
| 574 FakeTransportChannel* fake_ice_transport_channel() { | |
| 575 return fake_ice_transport_channel_; | |
| 576 } | |
| 577 | |
| 542 protected: | 578 protected: |
| 543 Transport* CreateTransport_n(const std::string& transport_name) override { | 579 Transport* CreateTransport_n(const std::string& transport_name) override { |
| 580 #ifdef HAVE_QUIC | |
| 581 if (quic()) { | |
| 582 LOG(INFO) << "creating quic transport."; | |
| 583 return new FakeQuicTransport(transport_name, fake_ice_transport_channel_); | |
| 584 } | |
| 585 #endif | |
| 544 return new FakeTransport(transport_name); | 586 return new FakeTransport(transport_name); |
| 545 } | 587 } |
| 546 | 588 |
| 547 void Connect_n(FakeTransportController* dest) { | 589 void Connect_n(FakeTransportController* dest) { |
| 548 // Simulate the exchange of candidates. | 590 // Simulate the exchange of candidates. |
| 549 ConnectChannels_n(); | 591 ConnectChannels_n(); |
| 550 dest->ConnectChannels_n(); | 592 dest->ConnectChannels_n(); |
| 551 for (auto& kv : transports()) { | 593 for (auto& kv : transports()) { |
| 552 FakeTransport* transport = static_cast<FakeTransport*>(kv.second); | 594 FakeTransport* transport = static_cast<FakeTransport*>(kv.second); |
| 553 transport->SetDestination(dest->GetTransport_n(kv.first)); | 595 transport->SetDestination(dest->GetTransport_n(kv.first)); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 567 if (!transport->local_description()) { | 609 if (!transport->local_description()) { |
| 568 transport->SetLocalTransportDescription(faketransport_desc, | 610 transport->SetLocalTransportDescription(faketransport_desc, |
| 569 cricket::CA_OFFER, nullptr); | 611 cricket::CA_OFFER, nullptr); |
| 570 } | 612 } |
| 571 transport->MaybeStartGathering(); | 613 transport->MaybeStartGathering(); |
| 572 } | 614 } |
| 573 } | 615 } |
| 574 | 616 |
| 575 private: | 617 private: |
| 576 bool fail_create_channel_; | 618 bool fail_create_channel_; |
| 619 FakeTransportChannel* fake_ice_transport_channel_; | |
|
Taylor Brandstetter
2016/08/01 18:05:03
I don't think having the FakeTransportController o
Zhi Huang
2016/08/01 23:56:22
This is a good point!
I like the idea to expose th
| |
| 577 }; | 620 }; |
| 578 | 621 |
| 579 } // namespace cricket | 622 } // namespace cricket |
| 580 | 623 |
| 581 #endif // WEBRTC_P2P_BASE_FAKETRANSPORTCONTROLLER_H_ | 624 #endif // WEBRTC_P2P_BASE_FAKETRANSPORTCONTROLLER_H_ |
| OLD | NEW |