summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-26 17:35:30 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-26 17:35:30 +0000
commitec5ed95d919f26d71e1a8346fac834f55dc76ddf (patch)
tree84dbcbd238eb8dc91bba3c206012d93b2442fc9b /remoting
parentc42283689c77cf16b1ab2cf3b0d258d90d769c0c (diff)
downloadchromium_src-ec5ed95d919f26d71e1a8346fac834f55dc76ddf.zip
chromium_src-ec5ed95d919f26d71e1a8346fac834f55dc76ddf.tar.gz
chromium_src-ec5ed95d919f26d71e1a8346fac834f55dc76ddf.tar.bz2
Expose nat_traversal flag to host and client plugins.
BUG=90213 TEST=None Review URL: http://codereview.chromium.org/7471054 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@94119 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r--remoting/client/plugin/chromoting_instance.cc3
-rw-r--r--remoting/host/chromoting_host.cc21
-rw-r--r--remoting/host/chromoting_host.h47
-rw-r--r--remoting/host/chromoting_host_unittest.cc4
-rw-r--r--remoting/host/plugin/host_script_object.cc8
-rw-r--r--remoting/host/simple_host_process.cc14
-rw-r--r--remoting/protocol/connection_to_host.cc11
-rw-r--r--remoting/protocol/connection_to_host.h11
-rw-r--r--remoting/protocol/jingle_datagram_connector.cc6
-rw-r--r--remoting/protocol/jingle_session.cc8
-rw-r--r--remoting/protocol/jingle_session_manager.cc14
-rw-r--r--remoting/protocol/jingle_session_manager.h9
-rw-r--r--remoting/protocol/jingle_session_unittest.cc4
-rw-r--r--remoting/protocol/jingle_stream_connector.cc6
-rw-r--r--remoting/protocol/protocol_test_client.cc2
-rw-r--r--remoting/protocol/session_manager.h16
16 files changed, 91 insertions, 93 deletions
diff --git a/remoting/client/plugin/chromoting_instance.cc b/remoting/client/plugin/chromoting_instance.cc
index 352cb98..7ec07a4 100644
--- a/remoting/client/plugin/chromoting_instance.cc
+++ b/remoting/client/plugin/chromoting_instance.cc
@@ -107,9 +107,10 @@ bool ChromotingInstance::Init(uint32_t argc,
}
// Create the chromoting objects.
+ // TODO(sergeyu): Use firewall traversal policy settings here.
host_connection_.reset(new protocol::ConnectionToHost(
context_.network_message_loop(), network_manager, socket_factory,
- session_factory));
+ session_factory, false));
view_.reset(new PepperView(this, &context_));
view_proxy_ = new PepperViewProxy(this, view_.get());
rectangle_decoder_ = new RectangleUpdateDecoder(
diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc
index f951f60..ddd4f99 100644
--- a/remoting/host/chromoting_host.cc
+++ b/remoting/host/chromoting_host.cc
@@ -38,32 +38,26 @@ namespace remoting {
// static
ChromotingHost* ChromotingHost::Create(ChromotingHostContext* context,
MutableHostConfig* config,
- AccessVerifier* access_verifier,
- Logger* logger) {
- DesktopEnvironment* desktop_env = DesktopEnvironment::Create(context);
- return Create(context, config, desktop_env, access_verifier, logger);
-}
-
-// static
-ChromotingHost* ChromotingHost::Create(ChromotingHostContext* context,
- MutableHostConfig* config,
DesktopEnvironment* environment,
AccessVerifier* access_verifier,
- Logger* logger) {
+ Logger* logger,
+ bool allow_nat_traversal) {
return new ChromotingHost(context, config, environment, access_verifier,
- logger);
+ logger, allow_nat_traversal);
}
ChromotingHost::ChromotingHost(ChromotingHostContext* context,
MutableHostConfig* config,
DesktopEnvironment* environment,
AccessVerifier* access_verifier,
- Logger* logger)
+ Logger* logger,
+ bool allow_nat_traversal)
: context_(context),
config_(config),
desktop_environment_(environment),
access_verifier_(access_verifier),
logger_(logger),
+ allow_nat_traversal_(allow_nat_traversal),
state_(kInitial),
protocol_config_(protocol::CandidateSessionConfig::CreateDefault()),
is_curtained_(false),
@@ -228,7 +222,8 @@ void ChromotingHost::OnStateChange(
server->Init(local_jid_, signal_strategy_.get(),
NewCallback(this, &ChromotingHost::OnNewClientSession),
- key_pair.CopyPrivateKey(), key_pair.GenerateCertificate());
+ key_pair.CopyPrivateKey(), key_pair.GenerateCertificate(),
+ allow_nat_traversal_);
session_manager_.reset(server);
diff --git a/remoting/host/chromoting_host.h b/remoting/host/chromoting_host.h
index 45910ed..f280914 100644
--- a/remoting/host/chromoting_host.h
+++ b/remoting/host/chromoting_host.h
@@ -68,19 +68,16 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>,
public ClientSession::EventHandler,
public SignalStrategy::StatusObserver {
public:
- // Factory methods that must be used to create ChromotingHost instances.
- // Default capturer and input stub are used if it is not specified.
- // Returned instance takes ownership of |access_verifier| and |environment|,
- // and adds a reference to |config|. It does NOT take ownership of |context|.
- static ChromotingHost* Create(ChromotingHostContext* context,
- MutableHostConfig* config,
- AccessVerifier* access_verifier,
- Logger* logger);
+ // Factory methods that must be used to create ChromotingHost
+ // instances. Returned instance takes ownership of
+ // |access_verifier| and |environment|. It does NOT take ownership
+ // of |context| and |logger|.
static ChromotingHost* Create(ChromotingHostContext* context,
MutableHostConfig* config,
DesktopEnvironment* environment,
AccessVerifier* access_verifier,
- Logger* logger);
+ Logger* logger,
+ bool allow_nat_traversal);
// Asynchronously start the host process.
//
@@ -152,22 +149,23 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>,
typedef std::vector<HostStatusObserver*> StatusObserverList;
typedef std::vector<scoped_refptr<ClientSession> > ClientList;
+ enum State {
+ kInitial,
+ kStarted,
+ kStopping,
+ kStopped,
+ };
+
// Takes ownership of |access_verifier| and |environment|, and adds a
// reference to |config|. Does NOT take ownership of |context|.
ChromotingHost(ChromotingHostContext* context,
MutableHostConfig* config,
DesktopEnvironment* environment,
AccessVerifier* access_verifier,
- Logger* logger);
+ Logger* logger,
+ bool allow_nat_traversal);
virtual ~ChromotingHost();
- enum State {
- kInitial,
- kStarted,
- kStopping,
- kStopped,
- };
-
// This method is called if a client is disconnected from the host.
void OnClientDisconnected(protocol::ConnectionToClient* client);
@@ -188,26 +186,21 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>,
void ShutdownRecorder();
void ShutdownFinish();
- // The context that the chromoting host runs on.
+ // Parameters specified when the host was created.
ChromotingHostContext* context_;
-
scoped_refptr<MutableHostConfig> config_;
-
scoped_ptr<DesktopEnvironment> desktop_environment_;
+ scoped_ptr<AccessVerifier> access_verifier_;
+ Logger* logger_;
+ bool allow_nat_traversal_;
+ // Connection objects.
scoped_ptr<SignalStrategy> signal_strategy_;
-
std::string local_jid_;
-
scoped_ptr<protocol::SessionManager> session_manager_;
StatusObserverList status_observers_;
- scoped_ptr<AccessVerifier> access_verifier_;
-
- // Logger (owned by the HostNPScriptObject).
- Logger* logger_;
-
// The connections to remote clients.
ClientList clients_;
diff --git a/remoting/host/chromoting_host_unittest.cc b/remoting/host/chromoting_host_unittest.cc
index 9d238fa..453e4cc 100644
--- a/remoting/host/chromoting_host_unittest.cc
+++ b/remoting/host/chromoting_host_unittest.cc
@@ -106,8 +106,8 @@ class ChromotingHostTest : public testing::Test {
local_input_monitor_);
MockAccessVerifier* access_verifier = new MockAccessVerifier();
- host_ = ChromotingHost::Create(&context_, config_,
- desktop, access_verifier, logger_.get());
+ host_ = ChromotingHost::Create(&context_, config_, desktop,
+ access_verifier, logger_.get(), false);
credentials_.set_type(protocol::PASSWORD);
credentials_.set_username("user");
credentials_.set_credential("password");
diff --git a/remoting/host/plugin/host_script_object.cc b/remoting/host/plugin/host_script_object.cc
index afbf232..cfb3b9c 100644
--- a/remoting/host/plugin/host_script_object.cc
+++ b/remoting/host/plugin/host_script_object.cc
@@ -11,6 +11,7 @@
#include "remoting/base/auth_token_util.h"
#include "remoting/host/chromoting_host.h"
#include "remoting/host/chromoting_host_context.h"
+#include "remoting/host/desktop_environment.h"
#include "remoting/host/host_config.h"
#include "remoting/host/host_key_pair.h"
#include "remoting/host/in_memory_host_config.h"
@@ -374,9 +375,12 @@ void HostNPScriptObject::ConnectInternal(
}
// Create the Host.
+ DesktopEnvironment* desktop_environment =
+ DesktopEnvironment::Create(&host_context_);
+ // TODO(sergeyu): Use firewall traversal policy settings here.
scoped_refptr<ChromotingHost> host =
- ChromotingHost::Create(&host_context_, host_config,
- access_verifier.release(), logger_.get());
+ ChromotingHost::Create(&host_context_, host_config, desktop_environment,
+ access_verifier.release(), logger_.get(), false);
host->AddStatusObserver(this);
host->AddStatusObserver(register_request.get());
host->set_it2me(true);
diff --git a/remoting/host/simple_host_process.cc b/remoting/host/simple_host_process.cc
index a5664dd..e58fd59 100644
--- a/remoting/host/simple_host_process.cc
+++ b/remoting/host/simple_host_process.cc
@@ -178,6 +178,7 @@ class SimpleHost {
// Construct a chromoting host.
scoped_refptr<ChromotingHost> host;
logger_.reset(new remoting::Logger());
+ DesktopEnvironment* desktop_environment;
if (fake_) {
remoting::Capturer* capturer =
new remoting::CapturerFake();
@@ -191,16 +192,17 @@ class SimpleHost {
remoting::ContinueWindow::Create();
remoting::LocalInputMonitor* local_input_monitor =
remoting::LocalInputMonitor::Create();
- host = ChromotingHost::Create(
- &context, config,
+ desktop_environment =
new DesktopEnvironment(&context, capturer, event_executor, curtain,
disconnect_window, continue_window,
- local_input_monitor),
- access_verifier.release(), logger_.get());
+ local_input_monitor);
} else {
- host = ChromotingHost::Create(&context, config,
- access_verifier.release(), logger_.get());
+ desktop_environment = DesktopEnvironment::Create(&context);
}
+
+ host = ChromotingHost::Create(&context, config, desktop_environment,
+ access_verifier.release(), logger_.get(),
+ false);
host->set_it2me(is_it2me_);
if (protocol_config_.get()) {
diff --git a/remoting/protocol/connection_to_host.cc b/remoting/protocol/connection_to_host.cc
index 422f090..b82143b 100644
--- a/remoting/protocol/connection_to_host.cc
+++ b/remoting/protocol/connection_to_host.cc
@@ -28,12 +28,14 @@ ConnectionToHost::ConnectionToHost(
MessageLoop* message_loop,
talk_base::NetworkManager* network_manager,
talk_base::PacketSocketFactory* socket_factory,
- PortAllocatorSessionFactory* session_factory)
- : state_(STATE_EMPTY),
- message_loop_(message_loop),
+ PortAllocatorSessionFactory* session_factory,
+ bool allow_nat_traversal)
+ : message_loop_(message_loop),
network_manager_(network_manager),
socket_factory_(socket_factory),
port_allocator_session_factory_(session_factory),
+ allow_nat_traversal_(allow_nat_traversal),
+ state_(STATE_EMPTY),
event_callback_(NULL),
dispatcher_(new ClientMessageDispatcher()),
client_stub_(NULL),
@@ -111,7 +113,8 @@ void ConnectionToHost::InitSession() {
session_manager->set_allow_local_ips(true);
session_manager->Init(
local_jid_, signal_strategy_.get(),
- NewCallback(this, &ConnectionToHost::OnNewSession), NULL, "");
+ NewCallback(this, &ConnectionToHost::OnNewSession), NULL, "",
+ allow_nat_traversal_);
session_manager_.reset(session_manager);
CandidateSessionConfig* candidate_config =
diff --git a/remoting/protocol/connection_to_host.h b/remoting/protocol/connection_to_host.h
index e3d8c5c..64ecc4f 100644
--- a/remoting/protocol/connection_to_host.h
+++ b/remoting/protocol/connection_to_host.h
@@ -75,7 +75,8 @@ class ConnectionToHost : public SignalStrategy::StatusObserver {
ConnectionToHost(MessageLoop* network_message_loop,
talk_base::NetworkManager* network_manager,
talk_base::PacketSocketFactory* socket_factory,
- PortAllocatorSessionFactory* session_factory);
+ PortAllocatorSessionFactory* session_factory,
+ bool allow_nat_traversal);
virtual ~ConnectionToHost();
virtual void Connect(scoped_refptr<XmppProxy> xmpp_proxy,
@@ -125,14 +126,14 @@ class ConnectionToHost : public SignalStrategy::StatusObserver {
// Stops writing in the channels.
void CloseChannels();
- // Internal state of the connection.
- State state_;
-
MessageLoop* message_loop_;
-
scoped_ptr<talk_base::NetworkManager> network_manager_;
scoped_ptr<talk_base::PacketSocketFactory> socket_factory_;
scoped_ptr<PortAllocatorSessionFactory> port_allocator_session_factory_;
+ bool allow_nat_traversal_;
+
+ // Internal state of the connection.
+ State state_;
scoped_ptr<SignalStrategy> signal_strategy_;
std::string local_jid_;
diff --git a/remoting/protocol/jingle_datagram_connector.cc b/remoting/protocol/jingle_datagram_connector.cc
index ce40202..0a45425 100644
--- a/remoting/protocol/jingle_datagram_connector.cc
+++ b/remoting/protocol/jingle_datagram_connector.cc
@@ -6,7 +6,6 @@
#include "jingle/glue/channel_socket_adapter.h"
#include "remoting/protocol/jingle_session.h"
-#include "third_party/libjingle/source/talk/p2p/base/p2ptransportchannel.h"
namespace remoting {
namespace protocol {
@@ -31,11 +30,6 @@ void JingleDatagramConnector::Connect(
cricket::TransportChannel* raw_channel) {
DCHECK(CalledOnValidThread());
- if (!initiator) {
- // Don't make outgoing connections from the host to client.
- raw_channel->GetP2PChannel()->set_incoming_only(true);
- }
-
net::Socket* socket =
new jingle_glue::TransportChannelSocketAdapter(raw_channel);
diff --git a/remoting/protocol/jingle_session.cc b/remoting/protocol/jingle_session.cc
index 2d88ecd..3e08dca 100644
--- a/remoting/protocol/jingle_session.cc
+++ b/remoting/protocol/jingle_session.cc
@@ -17,6 +17,7 @@
#include "remoting/protocol/jingle_session_manager.h"
#include "remoting/protocol/jingle_stream_connector.h"
#include "third_party/libjingle/source/talk/base/thread.h"
+#include "third_party/libjingle/source/talk/p2p/base/p2ptransportchannel.h"
#include "third_party/libjingle/source/talk/p2p/base/session.h"
#include "third_party/libjingle/source/talk/p2p/base/transport.h"
@@ -469,6 +470,13 @@ void JingleSession::AddChannelConnector(
cricket::TransportChannel* raw_channel =
cricket_session_->CreateChannel(content_name, name);
+ if (!jingle_session_manager_->allow_nat_traversal_ &&
+ !cricket_session_->initiator()) {
+ // Don't make outgoing connections from the host to client when
+ // NAT traversal is disabled.
+ raw_channel->GetP2PChannel()->set_incoming_only(true);
+ }
+
channel_connectors_[name] = connector;
connector->Connect(cricket_session_->initiator(), local_cert_,
remote_cert_, local_private_key_.get(), raw_channel);
diff --git a/remoting/protocol/jingle_session_manager.cc b/remoting/protocol/jingle_session_manager.cc
index 44df56f..077c115 100644
--- a/remoting/protocol/jingle_session_manager.cc
+++ b/remoting/protocol/jingle_session_manager.cc
@@ -48,7 +48,7 @@ JingleSessionManager::JingleSessionManager(
socket_factory_(socket_factory),
port_allocator_session_factory_(port_allocator_session_factory),
signal_strategy_(NULL),
- enable_nat_traversing_(false),
+ allow_nat_traversal_(false),
allow_local_ips_(false),
http_port_allocator_(NULL),
closed_(false),
@@ -64,17 +64,19 @@ void JingleSessionManager::Init(
SignalStrategy* signal_strategy,
IncomingSessionCallback* incoming_session_callback,
crypto::RSAPrivateKey* private_key,
- const std::string& certificate) {
+ const std::string& certificate,
+ bool allow_nat_traversal) {
DCHECK(CalledOnValidThread());
DCHECK(signal_strategy);
DCHECK(incoming_session_callback);
local_jid_ = local_jid;
- certificate_ = certificate;
- private_key_.reset(private_key);
- incoming_session_callback_.reset(incoming_session_callback);
signal_strategy_ = signal_strategy;
+ incoming_session_callback_.reset(incoming_session_callback);
+ private_key_.reset(private_key);
+ certificate_ = certificate;
+ allow_nat_traversal_ = allow_nat_traversal;
if (!network_manager_.get()) {
VLOG(1) << "Creating talk_base::NetworkManager.";
@@ -91,7 +93,7 @@ void JingleSessionManager::Init(
// so we explicitly disables TCP connections.
int port_allocator_flags = cricket::PORTALLOCATOR_DISABLE_TCP;
- if (enable_nat_traversing_) {
+ if (allow_nat_traversal) {
http_port_allocator_ = new remoting::HttpPortAllocator(
network_manager_.get(), socket_factory_.get(),
port_allocator_session_factory_.get(), "transp2");
diff --git a/remoting/protocol/jingle_session_manager.h b/remoting/protocol/jingle_session_manager.h
index bde603f..4d7c3c9 100644
--- a/remoting/protocol/jingle_session_manager.h
+++ b/remoting/protocol/jingle_session_manager.h
@@ -49,7 +49,8 @@ class JingleSessionManager
SignalStrategy* signal_strategy,
IncomingSessionCallback* incoming_session_callback,
crypto::RSAPrivateKey* private_key,
- const std::string& certificate) OVERRIDE;
+ const std::string& certificate,
+ bool allow_nat_traversal) OVERRIDE;
virtual Session* Connect(
const std::string& host_jid,
const std::string& host_public_key,
@@ -118,12 +119,8 @@ class JingleSessionManager
scoped_ptr<IncomingSessionCallback> incoming_session_callback_;
std::string certificate_;
scoped_ptr<crypto::RSAPrivateKey> private_key_;
+ bool allow_nat_traversal_;
- // This must be set to true to enable NAT traversal. STUN/Relay
- // servers are not used when NAT traversal is disabled, so P2P
- // connection will works only when both peers are on the same
- // network.
- bool enable_nat_traversing_;
bool allow_local_ips_;
scoped_ptr<cricket::PortAllocator> port_allocator_;
diff --git a/remoting/protocol/jingle_session_unittest.cc b/remoting/protocol/jingle_session_unittest.cc
index 538ef05..d0f753e 100644
--- a/remoting/protocol/jingle_session_unittest.cc
+++ b/remoting/protocol/jingle_session_unittest.cc
@@ -177,7 +177,7 @@ class JingleSessionTest : public testing::Test {
NewCallback(&host_server_callback_,
&MockSessionManagerCallback::OnIncomingSession),
private_key.release(),
- cert_der);
+ cert_der, false);
client_server_.reset(JingleSessionManager::CreateNotSandboxed());
client_server_->set_allow_local_ips(true);
@@ -185,7 +185,7 @@ class JingleSessionTest : public testing::Test {
kClientJid, client_signal_strategy_.get(),
NewCallback(&client_server_callback_,
&MockSessionManagerCallback::OnIncomingSession),
- NULL, "");
+ NULL, "", false);
}
void CloseSessionManager() {
diff --git a/remoting/protocol/jingle_stream_connector.cc b/remoting/protocol/jingle_stream_connector.cc
index 98e907f..650c119 100644
--- a/remoting/protocol/jingle_stream_connector.cc
+++ b/remoting/protocol/jingle_stream_connector.cc
@@ -15,7 +15,6 @@
#include "net/socket/ssl_server_socket.h"
#include "net/socket/client_socket_factory.h"
#include "remoting/protocol/jingle_session.h"
-#include "third_party/libjingle/source/talk/p2p/base/p2ptransportchannel.h"
namespace remoting {
namespace protocol {
@@ -83,11 +82,6 @@ void JingleStreamConnector::Connect(bool initiator,
local_private_key_ = local_private_key;
raw_channel_ = raw_channel;
- if (!initiator_) {
- // Don't make outgoing connections from the host to client.
- raw_channel_->GetP2PChannel()->set_incoming_only(true);
- }
-
net::Socket* socket =
new jingle_glue::TransportChannelSocketAdapter(raw_channel_);
diff --git a/remoting/protocol/protocol_test_client.cc b/remoting/protocol/protocol_test_client.cc
index 39c3e9e..fd16e0b 100644
--- a/remoting/protocol/protocol_test_client.cc
+++ b/remoting/protocol/protocol_test_client.cc
@@ -276,7 +276,7 @@ void ProtocolTestClient::OnStateChange(
session_manager_->Init(
local_jid_, signal_strategy_.get(),
- NewCallback(this, &ProtocolTestClient::OnNewSession), NULL, NULL);
+ NewCallback(this, &ProtocolTestClient::OnNewSession), NULL, "", true);
session_manager_->set_allow_local_ips(true);
if (host_jid_ != "") {
diff --git a/remoting/protocol/session_manager.h b/remoting/protocol/session_manager.h
index 75b5591..ad65523 100644
--- a/remoting/protocol/session_manager.h
+++ b/remoting/protocol/session_manager.h
@@ -91,16 +91,20 @@ class SessionManager : public base::NonThreadSafe {
IncomingSessionCallback;
// Initializes the session client. Caller retains ownership of the
- // |signal_strategy|. If this object is used in server mode, then
- // |private_key| and |certificate| are used to establish a secured
- // communication with the client. It will also take ownership of
- // these objects. In case this is used in client mode, pass in NULL
- // for both private key and certificate.
+ // |signal_strategy|. |allow_nat_traversal| must be set to true to
+ // enable NAT traversal. STUN/Relay servers are not used when NAT
+ // traversal is disabled, so P2P connection will works only when
+ // both peers are on the same network. If this object is used in
+ // server mode, then |private_key| and |certificate| are used to
+ // establish a secured communication with the client. It will also
+ // take ownership of these objects. On the client side pass in NULL
+ // for |private_key| and empty string for |certificate|.
virtual void Init(const std::string& local_jid,
SignalStrategy* signal_strategy,
IncomingSessionCallback* incoming_session_callback,
crypto::RSAPrivateKey* private_key,
- const std::string& certificate) = 0;
+ const std::string& certificate,
+ bool allow_nat_traversal) = 0;
// Tries to create a session to the host |jid|.
//