diff options
author | sergeyu <sergeyu@chromium.org> | 2016-03-16 13:40:59 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-16 20:42:08 +0000 |
commit | e8e7cb43534bb63ce2972cc0a51f614cda15db3f (patch) | |
tree | 9984c03a77bc0d6502a9e14df95d913339249734 /remoting | |
parent | b5022da0db55451ec2f7f77230a385ca0ff4bd81 (diff) | |
download | chromium_src-e8e7cb43534bb63ce2972cc0a51f614cda15db3f.zip chromium_src-e8e7cb43534bb63ce2972cc0a51f614cda15db3f.tar.gz chromium_src-e8e7cb43534bb63ce2972cc0a51f614cda15db3f.tar.bz2 |
Enable TURN on the host when using WebRTC.
BUG=577954
Review URL: https://codereview.chromium.org/1800893002
Cr-Commit-Position: refs/heads/master@{#381520}
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/base/BUILD.gn | 1 | ||||
-rw-r--r-- | remoting/base/service_urls.cc | 46 | ||||
-rw-r--r-- | remoting/base/service_urls.h | 26 | ||||
-rw-r--r-- | remoting/host/it2me/it2me_host.cc | 3 | ||||
-rw-r--r-- | remoting/host/remoting_me2me_host.cc | 2 | ||||
-rw-r--r-- | remoting/protocol/ice_transport.cc | 1 | ||||
-rw-r--r-- | remoting/protocol/transport_context.cc | 59 | ||||
-rw-r--r-- | remoting/protocol/transport_context.h | 31 | ||||
-rw-r--r-- | remoting/protocol/webrtc_transport.cc | 4 | ||||
-rw-r--r-- | remoting/test/test_chromoting_client.cc | 3 |
10 files changed, 99 insertions, 77 deletions
diff --git a/remoting/base/BUILD.gn b/remoting/base/BUILD.gn index 8a039e1..97dc3aa 100644 --- a/remoting/base/BUILD.gn +++ b/remoting/base/BUILD.gn @@ -26,6 +26,7 @@ source_set("base") { if (is_nacl) { sources -= [ "chromium_url_request.cc", + "service_urls.cc", "url_request_context_getter.cc", ] } diff --git a/remoting/base/service_urls.cc b/remoting/base/service_urls.cc index e235958..3ba940b 100644 --- a/remoting/base/service_urls.cc +++ b/remoting/base/service_urls.cc @@ -6,6 +6,7 @@ #include "base/command_line.h" #include "base/logging.h" +#include "google_apis/google_api_keys.h" // Configurable service data. const char kDirectoryBaseUrl[] = "https://www.googleapis.com/chromoting/v1"; @@ -15,6 +16,8 @@ const char kXmppServerAddressForMe2MeHost[] = "talk.google.com:5222"; const bool kXmppServerUseTls = true; const char kDirectoryBotJid[] = "remoting@bot.talk.google.com"; const char kGcdJid[] = "clouddevices.gserviceaccount.com"; +const char kNetworkTraversalApiUrlBase[] = + "https://networktraversal.googleapis.com/v1alpha/iceconfig?key="; // Command line switches. #if !defined(NDEBUG) @@ -24,6 +27,7 @@ const char kXmppServerAddressSwitch[] = "xmpp-server-address"; const char kXmppServerDisableTlsSwitch[] = "disable-xmpp-server-tls"; const char kDirectoryBotJidSwitch[] = "directory-bot-jid"; const char kGcdJidSwitch[] = "gcd-jid"; +const char kIceConfigUrl[] = "ice_config_url"; #endif // !defined(NDEBUG) // Non-configurable service paths. @@ -38,7 +42,9 @@ ServiceUrls::ServiceUrls() xmpp_server_address_for_me2me_host_(kXmppServerAddressForMe2MeHost), xmpp_server_use_tls_(kXmppServerUseTls), directory_bot_jid_(kDirectoryBotJid), - gcd_jid_(kGcdJid) { + gcd_jid_(kGcdJid), + ice_config_url_(kNetworkTraversalApiUrlBase + + google_apis::GetRemotingAPIKey()) { #if !defined(NDEBUG) // Allow debug builds to override urls via command line. base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); @@ -65,48 +71,18 @@ ServiceUrls::ServiceUrls() if (command_line->HasSwitch(kGcdJidSwitch)) { gcd_jid_ = command_line->GetSwitchValueASCII(kGcdJidSwitch); } + if (command_line->HasSwitch(kIceConfigUrl)) { + ice_config_url_ = command_line->GetSwitchValueASCII(kIceConfigUrl); + } #endif // !defined(NDEBUG) directory_hosts_url_ = directory_base_url_ + kDirectoryHostsSuffix; } -ServiceUrls::~ServiceUrls() { -} +ServiceUrls::~ServiceUrls() {} ServiceUrls* remoting::ServiceUrls::GetInstance() { return base::Singleton<ServiceUrls>::get(); } -const std::string& ServiceUrls::directory_base_url() const { - return directory_base_url_; -} - -const std::string& ServiceUrls::directory_hosts_url() const { - return directory_hosts_url_; -} - -const std::string& ServiceUrls::gcd_base_url() const { - return gcd_base_url_; -} - -const std::string& ServiceUrls::xmpp_server_address() const { - return xmpp_server_address_; -} - -const std::string& ServiceUrls::xmpp_server_address_for_me2me_host() const { - return xmpp_server_address_for_me2me_host_; -} - -bool ServiceUrls::xmpp_server_use_tls() const { - return xmpp_server_use_tls_; -} - -const std::string& ServiceUrls::directory_bot_jid() const { - return directory_bot_jid_; -} - -const std::string& ServiceUrls::gcd_jid() const { - return directory_bot_jid_; -} - } // namespace remoting diff --git a/remoting/base/service_urls.h b/remoting/base/service_urls.h index 74f1911..5c47d65 100644 --- a/remoting/base/service_urls.h +++ b/remoting/base/service_urls.h @@ -21,20 +21,29 @@ class ServiceUrls { static ServiceUrls* GetInstance(); // Remoting directory REST API URLs. - const std::string& directory_base_url() const; - const std::string& directory_hosts_url() const; - const std::string& gcd_base_url() const; + const std::string& directory_base_url() const { return directory_base_url_; } + const std::string& directory_hosts_url() const { + return directory_hosts_url_; + } + const std::string& gcd_base_url() const { return gcd_base_url_; } // XMPP Server configuration. - const std::string& xmpp_server_address() const; - const std::string& xmpp_server_address_for_me2me_host() const; - bool xmpp_server_use_tls() const; + const std::string& xmpp_server_address() const { + return xmpp_server_address_; + } + const std::string& xmpp_server_address_for_me2me_host() const { + return xmpp_server_address_for_me2me_host_; + } + bool xmpp_server_use_tls() const { return xmpp_server_use_tls_; } // Remoting directory bot JID (for registering hosts, logging, heartbeats). - const std::string& directory_bot_jid() const; + const std::string& directory_bot_jid() const { return directory_bot_jid_; } // JID for communicating with GCD. - const std::string& gcd_jid() const; + const std::string& gcd_jid() const { return gcd_jid_; } + + // ICE config URL. + const std::string& ice_config_url() const { return ice_config_url_; } private: friend struct base::DefaultSingletonTraits<ServiceUrls>; @@ -50,6 +59,7 @@ class ServiceUrls { bool xmpp_server_use_tls_; std::string directory_bot_jid_; std::string gcd_jid_; + std::string ice_config_url_; DISALLOW_COPY_AND_ASSIGN(ServiceUrls); }; diff --git a/remoting/host/it2me/it2me_host.cc b/remoting/host/it2me/it2me_host.cc index f3a32a2..059f210 100644 --- a/remoting/host/it2me/it2me_host.cc +++ b/remoting/host/it2me/it2me_host.cc @@ -19,6 +19,7 @@ #include "remoting/base/chromium_url_request.h" #include "remoting/base/logging.h" #include "remoting/base/rsa_key_pair.h" +#include "remoting/base/service_urls.h" #include "remoting/host/chromoting_host.h" #include "remoting/host/chromoting_host_context.h" #include "remoting/host/host_event_logger.h" @@ -243,6 +244,8 @@ void It2MeHost::FinishConnect() { make_scoped_ptr(new ChromiumUrlRequestFactory( host_context_->url_request_context_getter())), network_settings, protocol::TransportRole::SERVER); + transport_context->set_ice_config_url( + ServiceUrls::GetInstance()->ice_config_url()); scoped_ptr<protocol::SessionManager> session_manager( new protocol::JingleSessionManager(signal_strategy_.get())); diff --git a/remoting/host/remoting_me2me_host.cc b/remoting/host/remoting_me2me_host.cc index e9245cf..a1030dd 100644 --- a/remoting/host/remoting_me2me_host.cc +++ b/remoting/host/remoting_me2me_host.cc @@ -1517,6 +1517,8 @@ void HostProcess::StartHost() { make_scoped_ptr(new ChromiumUrlRequestFactory( context_->url_request_context_getter())), network_settings, protocol::TransportRole::SERVER); + transport_context->set_ice_config_url( + ServiceUrls::GetInstance()->ice_config_url()); scoped_ptr<protocol::SessionManager> session_manager( new protocol::JingleSessionManager(signal_strategy_.get())); diff --git a/remoting/protocol/ice_transport.cc b/remoting/protocol/ice_transport.cc index 4d243b4..94ceee7 100644 --- a/remoting/protocol/ice_transport.cc +++ b/remoting/protocol/ice_transport.cc @@ -29,6 +29,7 @@ IceTransport::IceTransport(scoped_refptr<TransportContext> transport_context, : transport_context_(transport_context), event_handler_(event_handler), weak_factory_(this) { + transport_context_->set_relay_mode(TransportContext::RelayMode::GTURN); transport_context->Prepare(); } diff --git a/remoting/protocol/transport_context.cc b/remoting/protocol/transport_context.cc index 70c8b96..c10953f 100644 --- a/remoting/protocol/transport_context.cc +++ b/remoting/protocol/transport_context.cc @@ -52,24 +52,24 @@ TransportContext::TransportContext( TransportContext::~TransportContext() {} void TransportContext::Prepare() { - EnsureFreshJingleInfo(); + EnsureFreshIceConfig(); } void TransportContext::GetIceConfig(const GetIceConfigCallback& callback) { - EnsureFreshJingleInfo(); + EnsureFreshIceConfig(); - // If there is a pending |ice_config_request_| delay the callback until the - // request is finished. - if (ice_config_request_) { - pending_ice_config_callbacks_.push_back(callback); + // If there is a pending |ice_config_request_| for the current |relay_mode_| + // then delay the callback until the request is finished. + if (ice_config_request_[relay_mode_]) { + pending_ice_config_callbacks_[relay_mode_].push_back(callback); } else { - callback.Run(ice_config_); + callback.Run(ice_config_[relay_mode_]); } } -void TransportContext::EnsureFreshJingleInfo() { +void TransportContext::EnsureFreshIceConfig() { // Check if request is already pending. - if (ice_config_request_) + if (ice_config_request_[relay_mode_]) return; // Don't need to make jingleinfo request if both STUN and Relay are disabled. @@ -78,26 +78,37 @@ void TransportContext::EnsureFreshJingleInfo() { return; } - if (ice_config_.is_null() || - base::Time::Now() > ice_config_.expiration_time) { - if (!ice_config_url_.empty()) { - ice_config_request_.reset(new HttpIceConfigRequest( - url_request_factory_.get(), ice_config_url_)); - } else { - ice_config_request_.reset(new JingleInfoRequest(signal_strategy_)); + if (ice_config_[relay_mode_].is_null() || + base::Time::Now() > ice_config_[relay_mode_].expiration_time) { + scoped_ptr<IceConfigRequest> request; + switch (relay_mode_) { + case RelayMode::TURN: + if (ice_config_url_.empty()) { + LOG(WARNING) << "ice_config_url isn't set."; + return; + } + request.reset(new HttpIceConfigRequest(url_request_factory_.get(), + ice_config_url_)); + break; + case RelayMode::GTURN: + request.reset(new JingleInfoRequest(signal_strategy_)); + break; } - ice_config_request_->Send(base::Bind( - &TransportContext::OnIceConfig, base::Unretained(this))); + ice_config_request_[relay_mode_] = std::move(request); + ice_config_request_[relay_mode_]->Send(base::Bind( + &TransportContext::OnIceConfig, base::Unretained(this), relay_mode_)); } } -void TransportContext::OnIceConfig(const IceConfig& ice_config) { - ice_config_ = ice_config; - ice_config_request_.reset(); +void TransportContext::OnIceConfig(RelayMode relay_mode, + const IceConfig& ice_config) { + ice_config_[relay_mode] = ice_config; + ice_config_request_[relay_mode].reset(); - while (!pending_ice_config_callbacks_.empty()) { - pending_ice_config_callbacks_.begin()->Run(ice_config_); - pending_ice_config_callbacks_.pop_front(); + auto& callback_list = pending_ice_config_callbacks_[relay_mode]; + while (!callback_list.empty()) { + callback_list.begin()->Run(ice_config); + callback_list.pop_front(); } } diff --git a/remoting/protocol/transport_context.h b/remoting/protocol/transport_context.h index 0cc6241..1c434f6 100644 --- a/remoting/protocol/transport_context.h +++ b/remoting/protocol/transport_context.h @@ -5,6 +5,7 @@ #ifndef REMOTING_PROTOCOL_TRANSPORT_CONTEXT_H_ #define REMOTING_PROTOCOL_TRANSPORT_CONTEXT_H_ +#include <array> #include <list> #include <string> #include <vector> @@ -31,6 +32,14 @@ class IceConfigRequest; // TURN configuration. class TransportContext : public base::RefCountedThreadSafe<TransportContext> { public: + enum RelayMode { + GTURN, + TURN, + + LAST_RELAYMODE = TURN + }; + static const int kNumRelayModes = RelayMode::LAST_RELAYMODE + 1; + typedef base::Callback<void(const IceConfig& ice_config)> GetIceConfigCallback; @@ -42,11 +51,14 @@ class TransportContext : public base::RefCountedThreadSafe<TransportContext> { const NetworkSettings& network_settings, TransportRole role); - // Enables standard TURN servers. - void UseTurn(const std::string& ice_config_url) { + void set_ice_config_url(const std::string& ice_config_url) { ice_config_url_ = ice_config_url; } + // Sets relay mode for all future calls of GetIceConfig(). Doesn't affect + // previous GetIceConfig() requests. + void set_relay_mode(RelayMode relay_mode) { relay_mode_ = relay_mode; } + // Prepares fresh JingleInfo. It may be called while connection is being // negotiated to minimize the chance that the following GetIceConfig() will // be blocking. @@ -69,8 +81,8 @@ class TransportContext : public base::RefCountedThreadSafe<TransportContext> { ~TransportContext(); - void EnsureFreshJingleInfo(); - void OnIceConfig(const IceConfig& ice_config); + void EnsureFreshIceConfig(); + void OnIceConfig(RelayMode relay_mode, const IceConfig& ice_config); SignalStrategy* signal_strategy_; scoped_ptr<PortAllocatorFactory> port_allocator_factory_; @@ -79,14 +91,15 @@ class TransportContext : public base::RefCountedThreadSafe<TransportContext> { TransportRole role_; std::string ice_config_url_; + RelayMode relay_mode_ = RelayMode::GTURN; - scoped_ptr<IceConfigRequest> ice_config_request_; - - IceConfig ice_config_; + std::array<scoped_ptr<IceConfigRequest>, kNumRelayModes> ice_config_request_; + std::array<IceConfig, kNumRelayModes> ice_config_; - // When there is an active |jingle_info_request_| stores list of callbacks to + // When there is an active |ice_config_request_| stores list of callbacks to // be called once the request is finished. - std::list<GetIceConfigCallback> pending_ice_config_callbacks_; + std::array<std::list<GetIceConfigCallback>, kNumRelayModes> + pending_ice_config_callbacks_; DISALLOW_COPY_AND_ASSIGN(TransportContext); }; diff --git a/remoting/protocol/webrtc_transport.cc b/remoting/protocol/webrtc_transport.cc index c342a12..c1b7035 100644 --- a/remoting/protocol/webrtc_transport.cc +++ b/remoting/protocol/webrtc_transport.cc @@ -119,7 +119,9 @@ WebrtcTransport::WebrtcTransport( incoming_data_stream_adapter_( false, base::Bind(&WebrtcTransport::Close, base::Unretained(this))), - weak_factory_(this) {} + weak_factory_(this) { + transport_context_->set_relay_mode(TransportContext::RelayMode::TURN); +} WebrtcTransport::~WebrtcTransport() {} diff --git a/remoting/test/test_chromoting_client.cc b/remoting/test/test_chromoting_client.cc index 9bc33ca..d4d8c29 100644 --- a/remoting/test/test_chromoting_client.cc +++ b/remoting/test/test_chromoting_client.cc @@ -14,6 +14,7 @@ #include "net/base/request_priority.h" #include "net/socket/client_socket_factory.h" #include "remoting/base/chromium_url_request.h" +#include "remoting/base/service_urls.h" #include "remoting/base/url_request_context_getter.h" #include "remoting/client/audio_player.h" #include "remoting/client/chromoting_client.h" @@ -125,6 +126,8 @@ void TestChromotingClient::StartConnection( make_scoped_ptr( new ChromiumUrlRequestFactory(request_context_getter)), network_settings, protocol::TransportRole::CLIENT)); + transport_context->set_ice_config_url( + ServiceUrls::GetInstance()->ice_config_url()); protocol::ClientAuthenticationConfig client_auth_config; client_auth_config.host_id = connection_setup_info.host_id; |