summaryrefslogtreecommitdiffstats
path: root/remoting/protocol
diff options
context:
space:
mode:
authorsergeyu <sergeyu@chromium.org>2016-03-16 13:40:59 -0700
committerCommit bot <commit-bot@chromium.org>2016-03-16 20:42:08 +0000
commite8e7cb43534bb63ce2972cc0a51f614cda15db3f (patch)
tree9984c03a77bc0d6502a9e14df95d913339249734 /remoting/protocol
parentb5022da0db55451ec2f7f77230a385ca0ff4bd81 (diff)
downloadchromium_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/protocol')
-rw-r--r--remoting/protocol/ice_transport.cc1
-rw-r--r--remoting/protocol/transport_context.cc59
-rw-r--r--remoting/protocol/transport_context.h31
-rw-r--r--remoting/protocol/webrtc_transport.cc4
4 files changed, 61 insertions, 34 deletions
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() {}