| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/test/fake_port_allocator.h" | 5 #include "remoting/test/fake_port_allocator.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "remoting/test/fake_network_dispatcher.h" | 8 #include "remoting/test/fake_network_dispatcher.h" |
| 9 #include "remoting/test/fake_network_manager.h" | 9 #include "remoting/test/fake_network_manager.h" |
| 10 #include "remoting/test/fake_socket_factory.h" | 10 #include "remoting/test/fake_socket_factory.h" |
| 11 #include "third_party/webrtc/p2p/client/basicportallocator.h" | 11 #include "third_party/webrtc/p2p/client/basicportallocator.h" |
| 12 | 12 |
| 13 namespace remoting { | 13 namespace remoting { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 class FakePortAllocatorSession : public protocol::PortAllocatorSessionBase { | 17 class FakePortAllocatorSession : public cricket::BasicPortAllocatorSession { |
| 18 public: | 18 public: |
| 19 FakePortAllocatorSession( | 19 FakePortAllocatorSession(FakePortAllocator* allocator, |
| 20 protocol::PortAllocatorBase* allocator, | 20 const std::string& content_name, |
| 21 const std::string& content_name, | 21 int component, |
| 22 int component, | 22 const std::string& ice_username_fragment, |
| 23 const std::string& ice_username_fragment, | 23 const std::string& ice_password); |
| 24 const std::string& ice_password, | |
| 25 const std::vector<rtc::SocketAddress>& stun_hosts, | |
| 26 const std::vector<std::string>& relay_hosts, | |
| 27 const std::string& relay); | |
| 28 ~FakePortAllocatorSession() override; | 24 ~FakePortAllocatorSession() override; |
| 29 | 25 |
| 30 // protocol::PortAllocatorBase overrides. | |
| 31 void ConfigReady(cricket::PortConfiguration* config) override; | |
| 32 void SendSessionRequest(const std::string& host) override; | |
| 33 | |
| 34 private: | 26 private: |
| 35 DISALLOW_COPY_AND_ASSIGN(FakePortAllocatorSession); | 27 DISALLOW_COPY_AND_ASSIGN(FakePortAllocatorSession); |
| 36 }; | 28 }; |
| 37 | 29 |
| 38 FakePortAllocatorSession::FakePortAllocatorSession( | 30 FakePortAllocatorSession::FakePortAllocatorSession( |
| 39 protocol::PortAllocatorBase* allocator, | 31 FakePortAllocator* allocator, |
| 40 const std::string& content_name, | 32 const std::string& content_name, |
| 41 int component, | 33 int component, |
| 42 const std::string& ice_username_fragment, | 34 const std::string& ice_username_fragment, |
| 43 const std::string& ice_password, | 35 const std::string& ice_password) |
| 44 const std::vector<rtc::SocketAddress>& stun_hosts, | 36 : BasicPortAllocatorSession(allocator, |
| 45 const std::vector<std::string>& relay_hosts, | 37 content_name, |
| 46 const std::string& relay) | 38 component, |
| 47 : PortAllocatorSessionBase(allocator, | 39 ice_username_fragment, |
| 48 content_name, | 40 ice_password) {} |
| 49 component, | |
| 50 ice_username_fragment, | |
| 51 ice_password, | |
| 52 stun_hosts, | |
| 53 relay_hosts, | |
| 54 relay) {} | |
| 55 | 41 |
| 56 FakePortAllocatorSession::~FakePortAllocatorSession() {} | 42 FakePortAllocatorSession::~FakePortAllocatorSession() {} |
| 57 | 43 |
| 58 void FakePortAllocatorSession::ConfigReady( | 44 } // namespace |
| 59 cricket::PortConfiguration* config) { | 45 |
| 60 // Filter out non-UDP relay ports, so that we don't try using TCP. | 46 FakePortAllocator::FakePortAllocator( |
| 61 for (cricket::PortConfiguration::RelayList::iterator relay = | 47 rtc::NetworkManager* network_manager, |
| 62 config->relays.begin(); relay != config->relays.end(); ++relay) { | 48 rtc::PacketSocketFactory* socket_factory) |
| 63 cricket::PortList filtered_ports; | 49 : BasicPortAllocator(network_manager, socket_factory) { |
| 64 for (cricket::PortList::iterator port = | 50 set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | |
| 65 relay->ports.begin(); port != relay->ports.end(); ++port) { | 51 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | |
| 66 if (port->proto == cricket::PROTO_UDP) { | 52 cricket::PORTALLOCATOR_ENABLE_IPV6 | |
| 67 filtered_ports.push_back(*port); | 53 cricket::PORTALLOCATOR_DISABLE_STUN | |
| 68 } | 54 cricket::PORTALLOCATOR_DISABLE_RELAY); |
| 69 } | |
| 70 relay->ports = filtered_ports; | |
| 71 } | |
| 72 cricket::BasicPortAllocatorSession::ConfigReady(config); | |
| 73 } | 55 } |
| 74 | 56 |
| 75 void FakePortAllocatorSession::SendSessionRequest(const std::string& host) { | |
| 76 ReceiveSessionResponse(std::string()); | |
| 77 } | |
| 78 | |
| 79 } // namespace | |
| 80 | |
| 81 FakePortAllocator::FakePortAllocator(rtc::NetworkManager* network_manager, | |
| 82 FakePacketSocketFactory* socket_factory) | |
| 83 : PortAllocatorBase(network_manager, socket_factory) {} | |
| 84 FakePortAllocator::~FakePortAllocator() {} | 57 FakePortAllocator::~FakePortAllocator() {} |
| 85 | 58 |
| 86 cricket::PortAllocatorSession* FakePortAllocator::CreateSessionInternal( | 59 cricket::PortAllocatorSession* FakePortAllocator::CreateSessionInternal( |
| 87 const std::string& content_name, | 60 const std::string& content_name, |
| 88 int component, | 61 int component, |
| 89 const std::string& ice_username_fragment, | 62 const std::string& ice_username_fragment, |
| 90 const std::string& ice_password) { | 63 const std::string& ice_password) { |
| 91 return new FakePortAllocatorSession( | 64 return new FakePortAllocatorSession(this, content_name, component, |
| 92 this, content_name, component, ice_username_fragment, ice_password, | 65 ice_username_fragment, ice_password); |
| 93 stun_hosts(), relay_hosts(), relay_token()); | |
| 94 } | 66 } |
| 95 | 67 |
| 96 FakePortAllocatorFactory::FakePortAllocatorFactory( | 68 FakePortAllocatorFactory::FakePortAllocatorFactory( |
| 97 scoped_refptr<FakeNetworkDispatcher> fake_network_dispatcher) { | 69 scoped_refptr<FakeNetworkDispatcher> fake_network_dispatcher) { |
| 98 socket_factory_.reset( | 70 socket_factory_.reset( |
| 99 new FakePacketSocketFactory(fake_network_dispatcher.get())); | 71 new FakePacketSocketFactory(fake_network_dispatcher.get())); |
| 100 network_manager_.reset(new FakeNetworkManager(socket_factory_->GetAddress())); | 72 network_manager_.reset(new FakeNetworkManager(socket_factory_->GetAddress())); |
| 101 } | 73 } |
| 102 | 74 |
| 103 FakePortAllocatorFactory::~FakePortAllocatorFactory() {} | 75 FakePortAllocatorFactory::~FakePortAllocatorFactory() {} |
| 104 | 76 |
| 105 scoped_ptr<protocol::PortAllocatorBase> | 77 scoped_ptr<cricket::PortAllocator> |
| 106 FakePortAllocatorFactory::CreatePortAllocator() { | 78 FakePortAllocatorFactory::CreatePortAllocator( |
| 79 scoped_refptr<protocol::TransportContext> transport_context) { |
| 107 return make_scoped_ptr( | 80 return make_scoped_ptr( |
| 108 new FakePortAllocator(network_manager_.get(), socket_factory_.get())); | 81 new FakePortAllocator(network_manager_.get(), socket_factory_.get())); |
| 109 } | 82 } |
| 110 | 83 |
| 111 } // namespace remoting | 84 } // namespace remoting |
| OLD | NEW |