diff options
author | sergeyu <sergeyu@chromium.org> | 2016-01-11 15:07:39 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-11 23:08:43 +0000 |
commit | 33312d6d01ec88fb6e686f03c886e2448ee238bd (patch) | |
tree | d5f932ff85c187f4950ca09b0933dc4912eeba57 /remoting | |
parent | ef3618f034f6049d11c1e66df2ba2fa7e592954b (diff) | |
download | chromium_src-33312d6d01ec88fb6e686f03c886e2448ee238bd.zip chromium_src-33312d6d01ec88fb6e686f03c886e2448ee238bd.tar.gz chromium_src-33312d6d01ec88fb6e686f03c886e2448ee238bd.tar.bz2 |
Simplify PortAllocatorBase and make PortAllocator creation synchronous.
Previously PortAllocator instances were created asynchronously in
TransportContext. Making PortAllocator synchronous allows to simplify
logic in other places, particularly in WebrtcTransport. Also simplified
PortAllocatorBase - it no longer stores STUN and Relay information and
instead instances of PortAllocatorSessionBase call TransportContext
to request fresh information when allocating ports.
Also removed duplicate logic from PepperPortAllocator and
ChromiumPortAllocator. Specifically they were filtering TCP-based relay
configs, but that's not longer necessary because PortAllocatorBase
is responsible for that now.
BUG=547158
Review URL: https://codereview.chromium.org/1571943002
Cr-Commit-Position: refs/heads/master@{#368701}
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/client/plugin/pepper_port_allocator.cc | 99 | ||||
-rw-r--r-- | remoting/client/plugin/pepper_port_allocator.h | 21 | ||||
-rw-r--r-- | remoting/host/cast_extension.cc | 19 | ||||
-rw-r--r-- | remoting/host/cast_extension.h | 19 | ||||
-rw-r--r-- | remoting/host/cast_extension_session.cc | 29 | ||||
-rw-r--r-- | remoting/host/cast_extension_session.h | 19 | ||||
-rw-r--r-- | remoting/protocol/chromium_port_allocator.cc | 91 | ||||
-rw-r--r-- | remoting/protocol/chromium_port_allocator.h | 22 | ||||
-rw-r--r-- | remoting/protocol/ice_transport_channel.cc | 14 | ||||
-rw-r--r-- | remoting/protocol/port_allocator_base.cc | 77 | ||||
-rw-r--r-- | remoting/protocol/port_allocator_base.h | 54 | ||||
-rw-r--r-- | remoting/protocol/port_allocator_factory.h | 9 | ||||
-rw-r--r-- | remoting/protocol/transport_context.cc | 64 | ||||
-rw-r--r-- | remoting/protocol/transport_context.h | 45 | ||||
-rw-r--r-- | remoting/protocol/webrtc_transport.cc | 17 | ||||
-rw-r--r-- | remoting/protocol/webrtc_transport.h | 3 | ||||
-rw-r--r-- | remoting/test/fake_port_allocator.cc | 84 | ||||
-rw-r--r-- | remoting/test/fake_port_allocator.h | 13 |
18 files changed, 265 insertions, 434 deletions
diff --git a/remoting/client/plugin/pepper_port_allocator.cc b/remoting/client/plugin/pepper_port_allocator.cc index f855492..6f2e27a 100644 --- a/remoting/client/plugin/pepper_port_allocator.cc +++ b/remoting/client/plugin/pepper_port_allocator.cc @@ -20,6 +20,7 @@ #include "remoting/client/plugin/pepper_network_manager.h" #include "remoting/client/plugin/pepper_packet_socket_factory.h" #include "remoting/client/plugin/pepper_util.h" +#include "remoting/protocol/transport_context.h" namespace remoting { @@ -32,20 +33,14 @@ const int kReadSize = 1024; class PepperPortAllocatorSession : public protocol::PortAllocatorSessionBase { public: PepperPortAllocatorSession( - protocol::PortAllocatorBase* allocator, + PepperPortAllocator* allocator, const std::string& content_name, int component, const std::string& ice_username_fragment, - const std::string& ice_password, - const std::vector<rtc::SocketAddress>& stun_hosts, - const std::vector<std::string>& relay_hosts, - const std::string& relay_token, - const pp::InstanceHandle& instance); + const std::string& ice_password); ~PepperPortAllocatorSession() override; // PortAllocatorBase overrides. - void ConfigReady(cricket::PortConfiguration* config) override; - void GetPortConfigurations() override; void SendSessionRequest(const std::string& host) override; private: @@ -53,7 +48,7 @@ class PepperPortAllocatorSession : public protocol::PortAllocatorSessionBase { void ReadResponseBody(); void OnResponseBodyRead(int32_t result); - pp::InstanceHandle instance_; + pp::InstanceHandle pp_instance_; cricket::ServerAddresses stun_hosts_; @@ -67,58 +62,23 @@ class PepperPortAllocatorSession : public protocol::PortAllocatorSessionBase { }; PepperPortAllocatorSession::PepperPortAllocatorSession( - protocol::PortAllocatorBase* allocator, + PepperPortAllocator* allocator, const std::string& content_name, int component, const std::string& ice_username_fragment, - const std::string& ice_password, - const std::vector<rtc::SocketAddress>& stun_hosts, - const std::vector<std::string>& relay_hosts, - const std::string& relay_token, - const pp::InstanceHandle& instance) + const std::string& ice_password) : PortAllocatorSessionBase(allocator, content_name, component, ice_username_fragment, - ice_password, - stun_hosts, - relay_hosts, - relay_token), - instance_(instance), - stun_hosts_(stun_hosts.begin(), stun_hosts.end()), - callback_factory_(this) {} + ice_password), + pp_instance_(allocator->pp_instance()) {} PepperPortAllocatorSession::~PepperPortAllocatorSession() {} -void PepperPortAllocatorSession::ConfigReady( - cricket::PortConfiguration* config) { - // Filter out non-UDP relay ports, so that we don't try using TCP. - for (cricket::PortConfiguration::RelayList::iterator relay = - config->relays.begin(); relay != config->relays.end(); ++relay) { - cricket::PortList filtered_ports; - for (cricket::PortList::iterator port = - relay->ports.begin(); port != relay->ports.end(); ++port) { - if (port->proto == cricket::PROTO_UDP) { - filtered_ports.push_back(*port); - } - } - relay->ports = filtered_ports; - } - cricket::BasicPortAllocatorSession::ConfigReady(config); -} - -void PepperPortAllocatorSession::GetPortConfigurations() { - // Add a configuration without relay response first so local and STUN - // candidates can be allocated without waiting for the relay response. - ConfigReady(new cricket::PortConfiguration( - stun_hosts_, std::string(), std::string())); - - TryCreateRelaySession(); -} - void PepperPortAllocatorSession::SendSessionRequest(const std::string& host) { - relay_url_loader_.reset(new pp::URLLoader(instance_)); - pp::URLRequestInfo request_info(instance_); + relay_url_loader_.reset(new pp::URLLoader(pp_instance_)); + pp::URLRequestInfo request_info(pp_instance_); std::string url = "https://" + host + GetSessionRequestUrl() + "&sn=1"; request_info.SetURL(url); request_info.SetMethod("GET"); @@ -200,22 +160,14 @@ void PepperPortAllocatorSession::OnResponseBodyRead(int32_t result) { } // namespace -// static -scoped_ptr<PepperPortAllocator> PepperPortAllocator::Create( - const pp::InstanceHandle& instance) { - return make_scoped_ptr(new PepperPortAllocator( - instance, make_scoped_ptr(new PepperNetworkManager(instance)), - make_scoped_ptr(new PepperPacketSocketFactory(instance)))); -} - PepperPortAllocator::PepperPortAllocator( - const pp::InstanceHandle& instance, - scoped_ptr<rtc::NetworkManager> network_manager, - scoped_ptr<rtc::PacketSocketFactory> socket_factory) - : PortAllocatorBase(network_manager.get(), socket_factory.get()), - instance_(instance), - network_manager_(std::move(network_manager)), - socket_factory_(std::move(socket_factory)) {} + scoped_refptr<protocol::TransportContext> transport_context, + pp::InstanceHandle pp_instance) + : PortAllocatorBase( + make_scoped_ptr(new PepperNetworkManager(pp_instance)), + make_scoped_ptr(new PepperPacketSocketFactory(pp_instance)), + transport_context), + pp_instance_(pp_instance) {} PepperPortAllocator::~PepperPortAllocator() {} @@ -224,20 +176,21 @@ cricket::PortAllocatorSession* PepperPortAllocator::CreateSessionInternal( int component, const std::string& ice_username_fragment, const std::string& ice_password) { - return new PepperPortAllocatorSession( - this, content_name, component, ice_username_fragment, ice_password, - stun_hosts(), relay_hosts(), relay_token(), instance_); + return new PepperPortAllocatorSession(this, content_name, component, + ice_username_fragment, ice_password); } PepperPortAllocatorFactory::PepperPortAllocatorFactory( - const pp::InstanceHandle& instance) - : instance_(instance) {} + pp::InstanceHandle pp_instance) + : pp_instance_(pp_instance) {} PepperPortAllocatorFactory::~PepperPortAllocatorFactory() {} -scoped_ptr<protocol::PortAllocatorBase> -PepperPortAllocatorFactory::CreatePortAllocator() { - return PepperPortAllocator::Create(instance_); +scoped_ptr<cricket::PortAllocator> +PepperPortAllocatorFactory::CreatePortAllocator( + scoped_refptr<protocol::TransportContext> transport_context) { + return make_scoped_ptr( + new PepperPortAllocator(transport_context, pp_instance_)); } } // namespace remoting diff --git a/remoting/client/plugin/pepper_port_allocator.h b/remoting/client/plugin/pepper_port_allocator.h index 19fb03d..a254977 100644 --- a/remoting/client/plugin/pepper_port_allocator.h +++ b/remoting/client/plugin/pepper_port_allocator.h @@ -18,10 +18,13 @@ namespace remoting { // client plugin. It uses Pepper URLLoader API when creating relay sessions. class PepperPortAllocator : public protocol::PortAllocatorBase { public: - static scoped_ptr<PepperPortAllocator> Create( - const pp::InstanceHandle& instance); + PepperPortAllocator( + scoped_refptr<protocol::TransportContext> transport_context, + pp::InstanceHandle pp_instance); ~PepperPortAllocator() override; + pp::InstanceHandle pp_instance() { return pp_instance_; } + // PortAllocatorBase overrides. cricket::PortAllocatorSession* CreateSessionInternal( const std::string& content_name, @@ -30,12 +33,7 @@ class PepperPortAllocator : public protocol::PortAllocatorBase { const std::string& ice_password) override; private: - PepperPortAllocator( - const pp::InstanceHandle& instance, - scoped_ptr<rtc::NetworkManager> network_manager, - scoped_ptr<rtc::PacketSocketFactory> socket_factory); - - pp::InstanceHandle instance_; + pp::InstanceHandle pp_instance_; scoped_ptr<rtc::NetworkManager> network_manager_; scoped_ptr<rtc::PacketSocketFactory> socket_factory_; @@ -44,14 +42,15 @@ class PepperPortAllocator : public protocol::PortAllocatorBase { class PepperPortAllocatorFactory : public protocol::PortAllocatorFactory { public: - PepperPortAllocatorFactory(const pp::InstanceHandle& instance); + PepperPortAllocatorFactory(pp::InstanceHandle pp_instance); ~PepperPortAllocatorFactory() override; // PortAllocatorFactory interface. - scoped_ptr<protocol::PortAllocatorBase> CreatePortAllocator() override; + scoped_ptr<cricket::PortAllocator> CreatePortAllocator( + scoped_refptr<protocol::TransportContext> transport_context) override; private: - pp::InstanceHandle instance_; + pp::InstanceHandle pp_instance_; DISALLOW_COPY_AND_ASSIGN(PepperPortAllocatorFactory); }; diff --git a/remoting/host/cast_extension.cc b/remoting/host/cast_extension.cc index cf2d51c..b31844c 100644 --- a/remoting/host/cast_extension.cc +++ b/remoting/host/cast_extension.cc @@ -6,23 +6,17 @@ #include "net/url_request/url_request_context_getter.h" #include "remoting/host/cast_extension_session.h" -#include "remoting/protocol/network_settings.h" +#include "remoting/protocol/transport_context.h" namespace remoting { const char kCapability[] = "casting"; CastExtension::CastExtension( - scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, - scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, - const protocol::NetworkSettings& network_settings) - : network_task_runner_(network_task_runner), - url_request_context_getter_(url_request_context_getter), - network_settings_(network_settings) { -} + scoped_refptr<protocol::TransportContext> transport_context) + : transport_context_(transport_context) {} -CastExtension::~CastExtension() { -} +CastExtension::~CastExtension() {} std::string CastExtension::capability() const { return kCapability; @@ -31,9 +25,8 @@ std::string CastExtension::capability() const { scoped_ptr<HostExtensionSession> CastExtension::CreateExtensionSession( ClientSessionControl* client_session_control, protocol::ClientStub* client_stub) { - return CastExtensionSession::Create( - network_task_runner_, url_request_context_getter_, network_settings_, - client_session_control, client_stub); + return CastExtensionSession::Create(transport_context_, + client_session_control, client_stub); } } // namespace remoting diff --git a/remoting/host/cast_extension.h b/remoting/host/cast_extension.h index fdd35a4..1c1c6d3 100644 --- a/remoting/host/cast_extension.h +++ b/remoting/host/cast_extension.h @@ -12,27 +12,16 @@ #include "base/memory/scoped_ptr.h" #include "remoting/host/host_extension.h" -namespace base { -class SingleThreadTaskRunner; -} // namespace base - -namespace net { -class URLRequestContextGetter; -} // namespace net - namespace remoting { namespace protocol { -struct NetworkSettings; +class TransportContext; } // namespace protocol // CastExtension extends HostExtension to enable WebRTC support. class CastExtension : public HostExtension { public: - CastExtension( - scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, - scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, - const protocol::NetworkSettings& network_settings); + CastExtension(scoped_refptr<protocol::TransportContext> transport_context); ~CastExtension() override; // HostExtension interface. @@ -42,9 +31,7 @@ class CastExtension : public HostExtension { protocol::ClientStub* client_stub) override; private: - scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; - scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; - const protocol::NetworkSettings& network_settings_; + scoped_refptr<protocol::TransportContext> transport_context_; DISALLOW_COPY_AND_ASSIGN(CastExtension); }; diff --git a/remoting/host/cast_extension_session.cc b/remoting/host/cast_extension_session.cc index 87efb70..4cd3dc4 100644 --- a/remoting/host/cast_extension_session.cc +++ b/remoting/host/cast_extension_session.cc @@ -12,11 +12,12 @@ #include "base/logging.h" #include "base/macros.h" #include "base/synchronization/waitable_event.h" -#include "net/url_request/url_request_context_getter.h" +#include "base/thread_task_runner_handle.h" #include "remoting/host/client_session.h" #include "remoting/proto/control.pb.h" -#include "remoting/protocol/chromium_port_allocator.h" #include "remoting/protocol/client_stub.h" +#include "remoting/protocol/port_allocator_factory.h" +#include "remoting/protocol/transport_context.h" #include "remoting/protocol/webrtc_video_capturer_adapter.h" #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" #include "third_party/libjingle/source/talk/app/webrtc/test/fakeconstraints.h" @@ -169,17 +170,12 @@ CastExtensionSession::~CastExtensionSession() { // static scoped_ptr<CastExtensionSession> CastExtensionSession::Create( - scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, - scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, - const protocol::NetworkSettings& network_settings, + scoped_refptr<protocol::TransportContext> transport_context, ClientSessionControl* client_session_control, protocol::ClientStub* client_stub) { scoped_ptr<CastExtensionSession> cast_extension_session( - new CastExtensionSession(caller_task_runner, - url_request_context_getter, - network_settings, - client_session_control, - client_stub)); + new CastExtensionSession(transport_context, + client_session_control, client_stub)); if (!cast_extension_session->WrapTasksAndSave() || !cast_extension_session->InitializePeerConnection()) { return nullptr; @@ -300,14 +296,11 @@ bool CastExtensionSession::OnExtensionMessage( // Private methods ------------------------------------------------------------ CastExtensionSession::CastExtensionSession( - scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, - scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, - const protocol::NetworkSettings& network_settings, + scoped_refptr<protocol::TransportContext> transport_context, ClientSessionControl* client_session_control, protocol::ClientStub* client_stub) - : caller_task_runner_(caller_task_runner), - url_request_context_getter_(url_request_context_getter), - network_settings_(network_settings), + : caller_task_runner_(base::ThreadTaskRunnerHandle::Get()), + transport_context_(transport_context), client_session_control_(client_session_control), client_stub_(client_stub), stats_observer_(CastStatsObserver::Create()), @@ -317,7 +310,6 @@ CastExtensionSession::CastExtensionSession( worker_thread_wrapper_(nullptr), worker_thread_(kWorkerThreadName) { DCHECK(caller_task_runner_->BelongsToCurrentThread()); - DCHECK(url_request_context_getter_.get()); DCHECK(client_session_control_); DCHECK(client_stub_); @@ -490,7 +482,8 @@ bool CastExtensionSession::InitializePeerConnection() { webrtc::MediaConstraintsInterface::kValueTrue); scoped_ptr<cricket::PortAllocator> port_allocator = - protocol::ChromiumPortAllocator::Create(url_request_context_getter_); + transport_context_->port_allocator_factory()->CreatePortAllocator( + transport_context_); webrtc::PeerConnectionInterface::RTCConfiguration rtc_config; peer_connection_ = peer_conn_factory_->CreatePeerConnection( diff --git a/remoting/host/cast_extension_session.h b/remoting/host/cast_extension_session.h index 8a10b4d..a035ec0 100644 --- a/remoting/host/cast_extension_session.h +++ b/remoting/host/cast_extension_session.h @@ -24,10 +24,6 @@ class SingleThreadTaskRunner; class WaitableEvent; } // namespace base -namespace net { -class URLRequestContextGetter; -} // namespace net - namespace webrtc { class MediaStreamInterface; } // namespace webrtc @@ -37,7 +33,7 @@ namespace remoting { class CastCreateSessionDescriptionObserver; namespace protocol { -struct NetworkSettings; +class TransportContext; } // namespace protocol // A HostExtensionSession implementation that enables WebRTC support using @@ -51,9 +47,7 @@ class CastExtensionSession : public HostExtensionSession, // initialization steps on it. The caller must take ownership of the returned // object. static scoped_ptr<CastExtensionSession> Create( - scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, - scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, - const protocol::NetworkSettings& network_settings, + scoped_refptr<protocol::TransportContext> transport_context, ClientSessionControl* client_session_control, protocol::ClientStub* client_stub); @@ -87,9 +81,7 @@ class CastExtensionSession : public HostExtensionSession, private: CastExtensionSession( - scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, - scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, - const protocol::NetworkSettings& network_settings, + scoped_refptr<protocol::TransportContext> transport_context, ClientSessionControl* client_session_control, protocol::ClientStub* client_stub); @@ -199,9 +191,8 @@ class CastExtensionSession : public HostExtensionSession, rtc::scoped_refptr<CastCreateSessionDescriptionObserver> create_session_desc_observer_; - // Parameters passed to ChromiumPortAllocator on creation. - scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; - const protocol::NetworkSettings& network_settings_; + // TransportContext for P2P transport. + scoped_refptr<protocol::TransportContext> transport_context_; // Interface to interact with ClientSession. ClientSessionControl* client_session_control_; diff --git a/remoting/protocol/chromium_port_allocator.cc b/remoting/protocol/chromium_port_allocator.cc index cf656f0..607fc22 100644 --- a/remoting/protocol/chromium_port_allocator.cc +++ b/remoting/protocol/chromium_port_allocator.cc @@ -15,6 +15,7 @@ #include "net/url_request/url_fetcher_delegate.h" #include "net/url_request/url_request_context_getter.h" #include "remoting/protocol/chromium_socket_factory.h" +#include "remoting/protocol/transport_context.h" #include "url/gurl.h" namespace remoting { @@ -25,20 +26,14 @@ namespace { class ChromiumPortAllocatorSession : public PortAllocatorSessionBase, public net::URLFetcherDelegate { public: - ChromiumPortAllocatorSession( - PortAllocatorBase* allocator, - const std::string& content_name, - int component, - const std::string& ice_username_fragment, - const std::string& ice_password, - const std::vector<rtc::SocketAddress>& stun_hosts, - const std::vector<std::string>& relay_hosts, - const std::string& relay, - const scoped_refptr<net::URLRequestContextGetter>& url_context); + ChromiumPortAllocatorSession(ChromiumPortAllocator* allocator, + const std::string& content_name, + int component, + const std::string& ice_username_fragment, + const std::string& ice_password); ~ChromiumPortAllocatorSession() override; // PortAllocatorBase overrides. - void ConfigReady(cricket::PortConfiguration* config) override; void SendSessionRequest(const std::string& host) override; // net::URLFetcherDelegate interface. @@ -52,46 +47,22 @@ class ChromiumPortAllocatorSession : public PortAllocatorSessionBase, }; ChromiumPortAllocatorSession::ChromiumPortAllocatorSession( - PortAllocatorBase* allocator, + ChromiumPortAllocator* allocator, const std::string& content_name, int component, const std::string& ice_username_fragment, - const std::string& ice_password, - const std::vector<rtc::SocketAddress>& stun_hosts, - const std::vector<std::string>& relay_hosts, - const std::string& relay, - const scoped_refptr<net::URLRequestContextGetter>& url_context) + const std::string& ice_password) : PortAllocatorSessionBase(allocator, content_name, component, ice_username_fragment, - ice_password, - stun_hosts, - relay_hosts, - relay), - url_context_(url_context) {} + ice_password), + url_context_(allocator->url_context()) {} ChromiumPortAllocatorSession::~ChromiumPortAllocatorSession() { STLDeleteElements(&url_fetchers_); } -void ChromiumPortAllocatorSession::ConfigReady( - cricket::PortConfiguration* config) { - // Filter out non-UDP relay ports, so that we don't try using TCP. - for (cricket::PortConfiguration::RelayList::iterator relay = - config->relays.begin(); relay != config->relays.end(); ++relay) { - cricket::PortList filtered_ports; - for (cricket::PortList::iterator port = - relay->ports.begin(); port != relay->ports.end(); ++port) { - if (port->proto == cricket::PROTO_UDP) { - filtered_ports.push_back(*port); - } - } - relay->ports = filtered_ports; - } - cricket::BasicPortAllocatorSession::ConfigReady(config); -} - void ChromiumPortAllocatorSession::SendSessionRequest(const std::string& host) { GURL url("https://" + host + GetSessionRequestUrl() + "&sn=1"); scoped_ptr<net::URLFetcher> url_fetcher = @@ -126,25 +97,15 @@ void ChromiumPortAllocatorSession::OnURLFetchComplete( } // namespace -// static -scoped_ptr<ChromiumPortAllocator> ChromiumPortAllocator::Create( - const scoped_refptr<net::URLRequestContextGetter>& url_context) { - scoped_ptr<rtc::NetworkManager> network_manager( - new rtc::BasicNetworkManager()); - scoped_ptr<rtc::PacketSocketFactory> socket_factory( - new ChromiumPacketSocketFactory()); - return make_scoped_ptr(new ChromiumPortAllocator( - url_context, std::move(network_manager), std::move(socket_factory))); -} - ChromiumPortAllocator::ChromiumPortAllocator( - const scoped_refptr<net::URLRequestContextGetter>& url_context, scoped_ptr<rtc::NetworkManager> network_manager, - scoped_ptr<rtc::PacketSocketFactory> socket_factory) - : PortAllocatorBase(network_manager.get(), socket_factory.get()), - url_context_(url_context), - network_manager_(std::move(network_manager)), - socket_factory_(std::move(socket_factory)) {} + scoped_ptr<rtc::PacketSocketFactory> socket_factory, + scoped_refptr<TransportContext> transport_context, + scoped_refptr<net::URLRequestContextGetter> url_context) + : PortAllocatorBase(std::move(network_manager), + std::move(socket_factory), + transport_context), + url_context_(url_context) {} ChromiumPortAllocator::~ChromiumPortAllocator() {} @@ -153,9 +114,8 @@ cricket::PortAllocatorSession* ChromiumPortAllocator::CreateSessionInternal( int component, const std::string& ice_username_fragment, const std::string& ice_password) { - return new ChromiumPortAllocatorSession( - this, content_name, component, ice_username_fragment, ice_password, - stun_hosts(), relay_hosts(), relay_token(), url_context_); + return new ChromiumPortAllocatorSession(this, content_name, component, + ice_username_fragment, ice_password); } ChromiumPortAllocatorFactory::ChromiumPortAllocatorFactory( @@ -164,9 +124,16 @@ ChromiumPortAllocatorFactory::ChromiumPortAllocatorFactory( ChromiumPortAllocatorFactory::~ChromiumPortAllocatorFactory() {} -scoped_ptr<PortAllocatorBase> -ChromiumPortAllocatorFactory::CreatePortAllocator() { - return ChromiumPortAllocator::Create(url_request_context_getter_); +scoped_ptr<cricket::PortAllocator> +ChromiumPortAllocatorFactory::CreatePortAllocator( + scoped_refptr<TransportContext> transport_context) { + scoped_ptr<rtc::NetworkManager> network_manager( + new rtc::BasicNetworkManager()); + scoped_ptr<rtc::PacketSocketFactory> socket_factory( + new ChromiumPacketSocketFactory()); + return make_scoped_ptr(new ChromiumPortAllocator( + std::move(network_manager), std::move(socket_factory), transport_context, + url_request_context_getter_)); } } // namespace protocol diff --git a/remoting/protocol/chromium_port_allocator.h b/remoting/protocol/chromium_port_allocator.h index 63d6e57..d01497a 100644 --- a/remoting/protocol/chromium_port_allocator.h +++ b/remoting/protocol/chromium_port_allocator.h @@ -26,11 +26,17 @@ struct NetworkSettings; // stack. class ChromiumPortAllocator : public PortAllocatorBase { public: - static scoped_ptr<ChromiumPortAllocator> Create( - const scoped_refptr<net::URLRequestContextGetter>& url_context); - + ChromiumPortAllocator( + scoped_ptr<rtc::NetworkManager> network_manager, + scoped_ptr<rtc::PacketSocketFactory> socket_factory, + scoped_refptr<TransportContext> transport_context, + scoped_refptr<net::URLRequestContextGetter> url_context); ~ChromiumPortAllocator() override; + scoped_refptr<net::URLRequestContextGetter> url_context() { + return url_context_; + } + // PortAllocatorBase overrides. cricket::PortAllocatorSession* CreateSessionInternal( const std::string& content_name, @@ -39,14 +45,7 @@ class ChromiumPortAllocator : public PortAllocatorBase { const std::string& ice_password) override; private: - ChromiumPortAllocator( - const scoped_refptr<net::URLRequestContextGetter>& url_context, - scoped_ptr<rtc::NetworkManager> network_manager, - scoped_ptr<rtc::PacketSocketFactory> socket_factory); - scoped_refptr<net::URLRequestContextGetter> url_context_; - scoped_ptr<rtc::NetworkManager> network_manager_; - scoped_ptr<rtc::PacketSocketFactory> socket_factory_; DISALLOW_COPY_AND_ASSIGN(ChromiumPortAllocator); }; @@ -58,7 +57,8 @@ class ChromiumPortAllocatorFactory : public PortAllocatorFactory { ~ChromiumPortAllocatorFactory() override; // PortAllocatorFactory interface. - scoped_ptr<PortAllocatorBase> CreatePortAllocator() override; + scoped_ptr<cricket::PortAllocator> CreatePortAllocator( + scoped_refptr<TransportContext> transport_context) override; private: scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; diff --git a/remoting/protocol/ice_transport_channel.cc b/remoting/protocol/ice_transport_channel.cc index 75413d7..a7ab222 100644 --- a/remoting/protocol/ice_transport_channel.cc +++ b/remoting/protocol/ice_transport_channel.cc @@ -14,6 +14,7 @@ #include "jingle/glue/utils.h" #include "net/base/net_errors.h" #include "remoting/protocol/channel_socket_adapter.h" +#include "remoting/protocol/port_allocator_factory.h" #include "remoting/protocol/transport_context.h" #include "third_party/webrtc/base/network.h" #include "third_party/webrtc/p2p/base/constants.h" @@ -83,16 +84,9 @@ void IceTransportChannel::Connect(const std::string& name, delegate_ = delegate; callback_ = callback; - transport_context_->CreatePortAllocator( - base::Bind(&IceTransportChannel::OnPortAllocatorCreated, - weak_factory_.GetWeakPtr())); -} - -void IceTransportChannel::OnPortAllocatorCreated( - scoped_ptr<cricket::PortAllocator> port_allocator){ - DCHECK(!channel_.get()); - - port_allocator_ = std::move(port_allocator); + port_allocator_ = + transport_context_->port_allocator_factory()->CreatePortAllocator( + transport_context_); // Create P2PTransportChannel, attach signal handlers and connect it. // TODO(sergeyu): Specify correct component ID for the channel. diff --git a/remoting/protocol/port_allocator_base.cc b/remoting/protocol/port_allocator_base.cc index a62d528..3f2b64e 100644 --- a/remoting/protocol/port_allocator_base.cc +++ b/remoting/protocol/port_allocator_base.cc @@ -7,10 +7,13 @@ #include <algorithm> #include <map> +#include "base/bind.h" #include "base/logging.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_split.h" #include "net/base/escape.h" +#include "remoting/protocol/network_settings.h" +#include "remoting/protocol/transport_context.h" namespace { @@ -36,47 +39,66 @@ namespace protocol { const int PortAllocatorBase::kNumRetries = 5; -PortAllocatorBase::PortAllocatorBase(rtc::NetworkManager* network_manager, - rtc::PacketSocketFactory* socket_factory) - : BasicPortAllocator(network_manager, socket_factory) {} - -PortAllocatorBase::~PortAllocatorBase() {} - -void PortAllocatorBase::SetStunHosts( - const std::vector<rtc::SocketAddress>& hosts) { - stun_hosts_ = hosts; +PortAllocatorBase::PortAllocatorBase( + scoped_ptr<rtc::NetworkManager> network_manager, + scoped_ptr<rtc::PacketSocketFactory> socket_factory, + scoped_refptr<TransportContext> transport_context) + : BasicPortAllocator(network_manager.get(), socket_factory.get()), + network_manager_(std::move(network_manager)), + socket_factory_(std::move(socket_factory)), + transport_context_(transport_context) { + // We always use PseudoTcp to provide a reliable channel. It provides poor + // performance when combined with TCP-based transport, so we have to disable + // TCP ports. ENABLE_SHARED_UFRAG flag is specified so that the same username + // fragment is shared between all candidates. + int flags = cricket::PORTALLOCATOR_DISABLE_TCP | + cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | + cricket::PORTALLOCATOR_ENABLE_IPV6; + + NetworkSettings network_settings = transport_context_->network_settings(); + + if (!(network_settings.flags & NetworkSettings::NAT_TRAVERSAL_STUN)) + flags |= cricket::PORTALLOCATOR_DISABLE_STUN; + + if (!(network_settings.flags & NetworkSettings::NAT_TRAVERSAL_RELAY)) + flags |= cricket::PORTALLOCATOR_DISABLE_RELAY; + + set_flags(flags); + SetPortRange(network_settings.port_range.min_port, + network_settings.port_range.max_port); } -void PortAllocatorBase::SetRelayHosts(const std::vector<std::string>& hosts) { - relay_hosts_ = hosts; -} - -void PortAllocatorBase::SetRelayToken(const std::string& relay) { - relay_token_ = relay; -} +PortAllocatorBase::~PortAllocatorBase() {} PortAllocatorSessionBase::PortAllocatorSessionBase( PortAllocatorBase* allocator, const std::string& content_name, int component, const std::string& ice_ufrag, - const std::string& ice_pwd, - const std::vector<rtc::SocketAddress>& stun_hosts, - const std::vector<std::string>& relay_hosts, - const std::string& relay_token) + const std::string& ice_pwd) : BasicPortAllocatorSession(allocator, content_name, component, ice_ufrag, ice_pwd), - relay_hosts_(relay_hosts), - stun_hosts_(stun_hosts), - relay_token_(relay_token), - attempts_(0) {} + transport_context_(allocator->transport_context()), + weak_factory_(this) {} PortAllocatorSessionBase::~PortAllocatorSessionBase() {} void PortAllocatorSessionBase::GetPortConfigurations() { + transport_context_->GetJingleInfo(base::Bind( + &PortAllocatorSessionBase::OnJingleInfo, weak_factory_.GetWeakPtr())); +} + +void PortAllocatorSessionBase::OnJingleInfo( + std::vector<rtc::SocketAddress> stun_hosts, + std::vector<std::string> relay_hosts, + std::string relay_token) { + stun_hosts_ = stun_hosts; + relay_hosts_ = relay_hosts; + relay_token_ = relay_token; + // Creating relay sessions can take time and is done asynchronously. // Creating stun sessions could also take time and could be done aysnc also, // but for now is done here and added to the initial config. Note any later @@ -94,7 +116,7 @@ void PortAllocatorSessionBase::GetPortConfigurations() { } void PortAllocatorSessionBase::TryCreateRelaySession() { - if (allocator()->flags() & cricket::PORTALLOCATOR_DISABLE_RELAY) + if (flags() & cricket::PORTALLOCATOR_DISABLE_RELAY) return; if (attempts_ == PortAllocatorBase::kNumRetries) { @@ -119,11 +141,6 @@ void PortAllocatorSessionBase::TryCreateRelaySession() { SendSessionRequest(host); } -PortAllocatorBase* PortAllocatorSessionBase::allocator() { - return static_cast<PortAllocatorBase*>( - BasicPortAllocatorSession::allocator()); -} - std::string PortAllocatorSessionBase::GetSessionRequestUrl() { ASSERT(!username().empty()); ASSERT(!password().empty()); diff --git a/remoting/protocol/port_allocator_base.h b/remoting/protocol/port_allocator_base.h index ee3f68c..1ad080f 100644 --- a/remoting/protocol/port_allocator_base.h +++ b/remoting/protocol/port_allocator_base.h @@ -8,20 +8,28 @@ #include <string> #include <vector> +#include "base/memory/weak_ptr.h" #include "third_party/webrtc/p2p/client/basicportallocator.h" namespace remoting { namespace protocol { +class TransportContext; + class PortAllocatorBase : public cricket::BasicPortAllocator { public: // The number of HTTP requests we should attempt before giving up. static const int kNumRetries; - PortAllocatorBase(rtc::NetworkManager* network_manager, - rtc::PacketSocketFactory* socket_factory); + PortAllocatorBase(scoped_ptr<rtc::NetworkManager> network_manager, + scoped_ptr<rtc::PacketSocketFactory> socket_factory, + scoped_refptr<TransportContext> transport_context); ~PortAllocatorBase() override; + scoped_refptr<TransportContext> transport_context() { + return transport_context_; + } + // CreateSession is defined in cricket::BasicPortAllocator but is // redefined here as pure virtual. cricket::PortAllocatorSession* CreateSessionInternal( @@ -30,21 +38,10 @@ class PortAllocatorBase : public cricket::BasicPortAllocator { const std::string& ice_ufrag, const std::string& ice_pwd) override = 0; - void SetStunHosts(const std::vector<rtc::SocketAddress>& hosts); - void SetRelayHosts(const std::vector<std::string>& hosts); - void SetRelayToken(const std::string& relay); - - const std::vector<rtc::SocketAddress>& stun_hosts() const { - return stun_hosts_; - } - - const std::vector<std::string>& relay_hosts() const { return relay_hosts_; } - const std::string& relay_token() const { return relay_token_; } - private: - std::vector<rtc::SocketAddress> stun_hosts_; - std::vector<std::string> relay_hosts_; - std::string relay_token_; + scoped_ptr<rtc::NetworkManager> network_manager_; + scoped_ptr<rtc::PacketSocketFactory> socket_factory_; + scoped_refptr<TransportContext> transport_context_; }; class PortAllocatorSessionBase : public cricket::BasicPortAllocatorSession { @@ -53,28 +50,33 @@ class PortAllocatorSessionBase : public cricket::BasicPortAllocatorSession { const std::string& content_name, int component, const std::string& ice_ufrag, - const std::string& ice_pwd, - const std::vector<rtc::SocketAddress>& stun_hosts, - const std::vector<std::string>& relay_hosts, - const std::string& relay); + const std::string& ice_pwd); ~PortAllocatorSessionBase() override; - const std::string& relay_token() const { return relay_token_; } - virtual void SendSessionRequest(const std::string& host) = 0; - virtual void ReceiveSessionResponse(const std::string& response); + void ReceiveSessionResponse(const std::string& response); protected: std::string GetSessionRequestUrl(); + void GetPortConfigurations() override; + void OnJingleInfo(std::vector<rtc::SocketAddress> stun_hosts, + std::vector<std::string> relay_hosts, + std::string relay_token); void TryCreateRelaySession(); - PortAllocatorBase* allocator() override; + + const std::string& relay_token() const { return relay_token_; } private: - std::vector<std::string> relay_hosts_; + scoped_refptr<TransportContext> transport_context_; + std::vector<rtc::SocketAddress> stun_hosts_; + std::vector<std::string> relay_hosts_; std::string relay_token_; - int attempts_; + + int attempts_ = 0; + + base::WeakPtrFactory<PortAllocatorSessionBase> weak_factory_; }; } // namespace protocol diff --git a/remoting/protocol/port_allocator_factory.h b/remoting/protocol/port_allocator_factory.h index f563cb5..907b6b5 100644 --- a/remoting/protocol/port_allocator_factory.h +++ b/remoting/protocol/port_allocator_factory.h @@ -7,10 +7,14 @@ #include "base/memory/scoped_ptr.h" +namespace cricket { +class PortAllocator; +} // namespace cricket + namespace remoting { namespace protocol { -class PortAllocatorBase; +class TransportContext; // Factory class used for creating cricket::PortAllocator that is used // to allocate ICE candidates. @@ -18,7 +22,8 @@ class PortAllocatorFactory { public: virtual ~PortAllocatorFactory() {} - virtual scoped_ptr<PortAllocatorBase> CreatePortAllocator() = 0; + virtual scoped_ptr<cricket::PortAllocator> CreatePortAllocator( + scoped_refptr<TransportContext> transport_context) = 0; }; } // namespace protocol diff --git a/remoting/protocol/transport_context.cc b/remoting/protocol/transport_context.cc index 95f1358..62b1df2 100644 --- a/remoting/protocol/transport_context.cc +++ b/remoting/protocol/transport_context.cc @@ -10,8 +10,8 @@ #include "base/location.h" #include "base/single_thread_task_runner.h" #include "base/thread_task_runner_handle.h" -#include "remoting/protocol/port_allocator_base.h" #include "remoting/protocol/port_allocator_factory.h" +#include "third_party/webrtc/base/socketaddress.h" #if !defined(OS_NACL) #include "jingle/glue/thread_wrapper.h" @@ -30,11 +30,11 @@ static const int kJingleInfoUpdatePeriodSeconds = 3600; scoped_refptr<TransportContext> TransportContext::ForTests(TransportRole role) { jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); return new protocol::TransportContext( - nullptr, make_scoped_ptr( - new protocol::ChromiumPortAllocatorFactory(nullptr)), - protocol::NetworkSettings( - protocol::NetworkSettings::NAT_TRAVERSAL_OUTGOING), - role); + nullptr, + make_scoped_ptr(new protocol::ChromiumPortAllocatorFactory(nullptr)), + protocol::NetworkSettings( + protocol::NetworkSettings::NAT_TRAVERSAL_OUTGOING), + role); } #endif // !defined(OS_NACL) @@ -54,16 +54,15 @@ void TransportContext::Prepare() { EnsureFreshJingleInfo(); } -void TransportContext::CreatePortAllocator( - const CreatePortAllocatorCallback& callback) { +void TransportContext::GetJingleInfo(const GetJingleInfoCallback& callback) { EnsureFreshJingleInfo(); - // If there is a pending |jingle_info_request_| delay starting the new - // transport until the request is finished. + // If there is a pending |jingle_info_request_| delay the callback until the + // request is finished. if (jingle_info_request_) { - pending_port_allocator_requests_.push_back(callback); + pending_jingle_info_callbacks_.push_back(callback); } else { - callback.Run(CreatePortAllocatorInternal()); + callback.Run(stun_hosts_, relay_hosts_, relay_token_); } } @@ -99,45 +98,12 @@ void TransportContext::OnJingleInfo( if ((!relay_token.empty() && !relay_hosts.empty()) || !stun_hosts.empty()) last_jingle_info_update_time_ = base::TimeTicks::Now(); - while (!pending_port_allocator_requests_.empty()) { - pending_port_allocator_requests_.begin()->Run( - CreatePortAllocatorInternal()); - pending_port_allocator_requests_.pop_front(); + while (!pending_jingle_info_callbacks_.empty()) { + pending_jingle_info_callbacks_.begin()->Run(stun_hosts_, relay_hosts_, + relay_token_); + pending_jingle_info_callbacks_.pop_front(); } } -scoped_ptr<cricket::PortAllocator> -TransportContext::CreatePortAllocatorInternal() { - scoped_ptr<PortAllocatorBase> result = - port_allocator_factory_->CreatePortAllocator(); - - if (!relay_token_.empty() && !relay_hosts_.empty()) { - result->SetRelayHosts(relay_hosts_); - result->SetRelayToken(relay_token_); - } - if (!stun_hosts_.empty()) - result->SetStunHosts(stun_hosts_); - - // We always use PseudoTcp to provide a reliable channel. It provides poor - // performance when combined with TCP-based transport, so we have to disable - // TCP ports. ENABLE_SHARED_UFRAG flag is specified so that the same username - // fragment is shared between all candidates. - int flags = cricket::PORTALLOCATOR_DISABLE_TCP | - cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | - cricket::PORTALLOCATOR_ENABLE_IPV6; - - if (!(network_settings_.flags & NetworkSettings::NAT_TRAVERSAL_STUN)) - flags |= cricket::PORTALLOCATOR_DISABLE_STUN; - - if (!(network_settings_.flags & NetworkSettings::NAT_TRAVERSAL_RELAY)) - flags |= cricket::PORTALLOCATOR_DISABLE_RELAY; - - result->set_flags(flags); - result->SetPortRange(network_settings_.port_range.min_port, - network_settings_.port_range.max_port); - - return std::move(result); -} - } // namespace protocol } // namespace remoting diff --git a/remoting/protocol/transport_context.h b/remoting/protocol/transport_context.h index 12a6c3d..fbe0b37 100644 --- a/remoting/protocol/transport_context.h +++ b/remoting/protocol/transport_context.h @@ -30,32 +30,33 @@ class PortAllocatorFactory; // TransportContext is responsible for storing all parameters required for // P2P transport initialization. It's also responsible for making JingleInfo -// request and creation of PortAllocators configured according to the JingleInfo -// result. +// request. class TransportContext : public base::RefCountedThreadSafe<TransportContext> { public: - typedef base::Callback<void(scoped_ptr<cricket::PortAllocator> - port_allocator)> CreatePortAllocatorCallback; + typedef base::Callback<void(std::vector<rtc::SocketAddress> stun_hosts, + std::vector<std::string> relay_hosts, + std::string relay_token)> GetJingleInfoCallback; static scoped_refptr<TransportContext> ForTests(TransportRole role); - TransportContext( - SignalStrategy* signal_strategy, - scoped_ptr<PortAllocatorFactory> port_allocator_factory, - const NetworkSettings& network_settings, - TransportRole role); + TransportContext(SignalStrategy* signal_strategy, + scoped_ptr<PortAllocatorFactory> port_allocator_factory, + const NetworkSettings& network_settings, + TransportRole role); - // Prepares to create new PortAllocator instances. It may be called while - // connection is being negotiated to minimize the chance that the following - // CreatePortAllocator() will be blocking. + // Prepares fresh JingleInfo. It may be called while connection is being + // negotiated to minimize the chance that the following GetJingleInfo() will + // be blocking. void Prepare(); - // Creates new PortAllocator making sure that it has correct STUN and TURN - // information. - void CreatePortAllocator(const CreatePortAllocatorCallback& callback); + // Requests fresh STUN and TURN information. + void GetJingleInfo(const GetJingleInfoCallback& callback); - const NetworkSettings& network_settings() { return network_settings_; } - TransportRole role() { return role_; } + PortAllocatorFactory* port_allocator_factory() { + return port_allocator_factory_.get(); + } + const NetworkSettings& network_settings() const { return network_settings_; } + TransportRole role() const { return role_; } private: friend class base::RefCountedThreadSafe<TransportContext>; @@ -67,8 +68,6 @@ class TransportContext : public base::RefCountedThreadSafe<TransportContext> { const std::vector<std::string>& relay_hosts, const std::vector<rtc::SocketAddress>& stun_hosts); - scoped_ptr<cricket::PortAllocator> CreatePortAllocatorInternal(); - SignalStrategy* signal_strategy_; scoped_ptr<PortAllocatorFactory> port_allocator_factory_; NetworkSettings network_settings_; @@ -77,13 +76,13 @@ class TransportContext : public base::RefCountedThreadSafe<TransportContext> { base::TimeTicks last_jingle_info_update_time_; scoped_ptr<JingleInfoRequest> jingle_info_request_; - std::string relay_token_; - std::vector<std::string> relay_hosts_; std::vector<rtc::SocketAddress> stun_hosts_; + std::vector<std::string> relay_hosts_; + std::string relay_token_; // When there is an active |jingle_info_request_| stores list of callbacks to - // be called once the |jingle_info_request_| is finished. - std::list<CreatePortAllocatorCallback> pending_port_allocator_requests_; + // be called once the request is finished. + std::list<GetJingleInfoCallback> pending_jingle_info_callbacks_; DISALLOW_COPY_AND_ASSIGN(TransportContext); }; diff --git a/remoting/protocol/webrtc_transport.cc b/remoting/protocol/webrtc_transport.cc index 0950e7c..cf3235e 100644 --- a/remoting/protocol/webrtc_transport.cc +++ b/remoting/protocol/webrtc_transport.cc @@ -122,21 +122,15 @@ void WebrtcTransport::Start( DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(send_transport_info_callback_.is_null()); - send_transport_info_callback_ = std::move(send_transport_info_callback); - - // TODO(sergeyu): Use the |authenticator| to authenticate PeerConnection. - - transport_context_->CreatePortAllocator(base::Bind( - &WebrtcTransport::OnPortAllocatorCreated, weak_factory_.GetWeakPtr())); -} - -void WebrtcTransport::OnPortAllocatorCreated( - scoped_ptr<cricket::PortAllocator> port_allocator) { jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); // TODO(sergeyu): Investigate if it's possible to avoid Send(). jingle_glue::JingleThreadWrapper::current()->set_send_allowed(true); + send_transport_info_callback_ = std::move(send_transport_info_callback); + + // TODO(sergeyu): Use the |authenticator| to authenticate PeerConnection. + fake_audio_device_module_.reset(new webrtc::FakeAudioDeviceModule()); peer_connection_factory_ = webrtc::CreatePeerConnectionFactory( @@ -152,6 +146,9 @@ void WebrtcTransport::OnPortAllocatorCreated( constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, webrtc::MediaConstraintsInterface::kValueTrue); + scoped_ptr<cricket::PortAllocator> port_allocator = + transport_context_->port_allocator_factory()->CreatePortAllocator( + transport_context_); peer_connection_ = peer_connection_factory_->CreatePeerConnection( rtc_config, &constraints, rtc::scoped_ptr<cricket::PortAllocator>(port_allocator.release()), diff --git a/remoting/protocol/webrtc_transport.h b/remoting/protocol/webrtc_transport.h index d11bfa7..a54be6e 100644 --- a/remoting/protocol/webrtc_transport.h +++ b/remoting/protocol/webrtc_transport.h @@ -74,9 +74,6 @@ class WebrtcTransport : public Transport, bool ProcessTransportInfo(buzz::XmlElement* transport_info) override; private: - void OnPortAllocatorCreated( - scoped_ptr<cricket::PortAllocator> port_allocator); - void OnLocalSessionDescriptionCreated( scoped_ptr<webrtc::SessionDescriptionInterface> description, const std::string& error); diff --git a/remoting/test/fake_port_allocator.cc b/remoting/test/fake_port_allocator.cc index 6fcc33f..65d9047 100644 --- a/remoting/test/fake_port_allocator.cc +++ b/remoting/test/fake_port_allocator.cc @@ -5,6 +5,7 @@ #include "remoting/test/fake_port_allocator.h" #include "base/macros.h" +#include "remoting/protocol/transport_context.h" #include "remoting/test/fake_network_dispatcher.h" #include "remoting/test/fake_network_manager.h" #include "remoting/test/fake_socket_factory.h" @@ -14,73 +15,46 @@ namespace remoting { namespace { -class FakePortAllocatorSession : public protocol::PortAllocatorSessionBase { +class FakePortAllocatorSession : public cricket::BasicPortAllocatorSession { public: - FakePortAllocatorSession( - protocol::PortAllocatorBase* allocator, - const std::string& content_name, - int component, - const std::string& ice_username_fragment, - const std::string& ice_password, - const std::vector<rtc::SocketAddress>& stun_hosts, - const std::vector<std::string>& relay_hosts, - const std::string& relay); + FakePortAllocatorSession(FakePortAllocator* allocator, + const std::string& content_name, + int component, + const std::string& ice_username_fragment, + const std::string& ice_password); ~FakePortAllocatorSession() override; - // protocol::PortAllocatorBase overrides. - void ConfigReady(cricket::PortConfiguration* config) override; - void SendSessionRequest(const std::string& host) override; - private: DISALLOW_COPY_AND_ASSIGN(FakePortAllocatorSession); }; FakePortAllocatorSession::FakePortAllocatorSession( - protocol::PortAllocatorBase* allocator, + FakePortAllocator* allocator, const std::string& content_name, int component, const std::string& ice_username_fragment, - const std::string& ice_password, - const std::vector<rtc::SocketAddress>& stun_hosts, - const std::vector<std::string>& relay_hosts, - const std::string& relay) - : PortAllocatorSessionBase(allocator, - content_name, - component, - ice_username_fragment, - ice_password, - stun_hosts, - relay_hosts, - relay) {} + const std::string& ice_password) + : BasicPortAllocatorSession(allocator, + content_name, + component, + ice_username_fragment, + ice_password) {} FakePortAllocatorSession::~FakePortAllocatorSession() {} -void FakePortAllocatorSession::ConfigReady( - cricket::PortConfiguration* config) { - // Filter out non-UDP relay ports, so that we don't try using TCP. - for (cricket::PortConfiguration::RelayList::iterator relay = - config->relays.begin(); relay != config->relays.end(); ++relay) { - cricket::PortList filtered_ports; - for (cricket::PortList::iterator port = - relay->ports.begin(); port != relay->ports.end(); ++port) { - if (port->proto == cricket::PROTO_UDP) { - filtered_ports.push_back(*port); - } - } - relay->ports = filtered_ports; - } - cricket::BasicPortAllocatorSession::ConfigReady(config); -} +} // namespace -void FakePortAllocatorSession::SendSessionRequest(const std::string& host) { - ReceiveSessionResponse(std::string()); +FakePortAllocator::FakePortAllocator( + rtc::NetworkManager* network_manager, + rtc::PacketSocketFactory* socket_factory) + : BasicPortAllocator(network_manager, socket_factory) { + set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | + cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | + cricket::PORTALLOCATOR_ENABLE_IPV6 | + cricket::PORTALLOCATOR_DISABLE_STUN | + cricket::PORTALLOCATOR_DISABLE_RELAY); } -} // namespace - -FakePortAllocator::FakePortAllocator(rtc::NetworkManager* network_manager, - FakePacketSocketFactory* socket_factory) - : PortAllocatorBase(network_manager, socket_factory) {} FakePortAllocator::~FakePortAllocator() {} cricket::PortAllocatorSession* FakePortAllocator::CreateSessionInternal( @@ -88,9 +62,8 @@ cricket::PortAllocatorSession* FakePortAllocator::CreateSessionInternal( int component, const std::string& ice_username_fragment, const std::string& ice_password) { - return new FakePortAllocatorSession( - this, content_name, component, ice_username_fragment, ice_password, - stun_hosts(), relay_hosts(), relay_token()); + return new FakePortAllocatorSession(this, content_name, component, + ice_username_fragment, ice_password); } FakePortAllocatorFactory::FakePortAllocatorFactory( @@ -102,8 +75,9 @@ FakePortAllocatorFactory::FakePortAllocatorFactory( FakePortAllocatorFactory::~FakePortAllocatorFactory() {} -scoped_ptr<protocol::PortAllocatorBase> -FakePortAllocatorFactory::CreatePortAllocator() { +scoped_ptr<cricket::PortAllocator> +FakePortAllocatorFactory::CreatePortAllocator( + scoped_refptr<protocol::TransportContext> transport_context) { return make_scoped_ptr( new FakePortAllocator(network_manager_.get(), socket_factory_.get())); } diff --git a/remoting/test/fake_port_allocator.h b/remoting/test/fake_port_allocator.h index 636e7a3..ed2e095 100644 --- a/remoting/test/fake_port_allocator.h +++ b/remoting/test/fake_port_allocator.h @@ -10,22 +10,18 @@ #include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" -#include "remoting/protocol/port_allocator_base.h" #include "remoting/protocol/port_allocator_factory.h" - -namespace rtc { -class NetworkManager; -} // namespace rtc +#include "third_party/webrtc/p2p/client/basicportallocator.h" namespace remoting { class FakeNetworkDispatcher; class FakePacketSocketFactory; -class FakePortAllocator : public protocol::PortAllocatorBase { +class FakePortAllocator : public cricket::BasicPortAllocator { public: FakePortAllocator(rtc::NetworkManager* network_manager, - FakePacketSocketFactory* socket_factory); + rtc::PacketSocketFactory* socket_factory); ~FakePortAllocator() override; // cricket::BasicPortAllocator overrides. @@ -48,7 +44,8 @@ class FakePortAllocatorFactory : public protocol::PortAllocatorFactory { FakePacketSocketFactory* socket_factory() { return socket_factory_.get(); } // PortAllocatorFactory interface. - scoped_ptr<protocol::PortAllocatorBase> CreatePortAllocator() override; + scoped_ptr<cricket::PortAllocator> CreatePortAllocator( + scoped_refptr<protocol::TransportContext> transport_context) override; private: scoped_ptr<rtc::NetworkManager> network_manager_; |