summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-22 01:44:25 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-22 01:44:25 +0000
commit483414a22ae60ffcc24e0517be4a44c05375325e (patch)
tree7f6c729951b873205c676a6ed7fe85f88964ca73 /remoting
parent729c1e9326c854bc63acee30e0dff09061b46b26 (diff)
downloadchromium_src-483414a22ae60ffcc24e0517be4a44c05375325e.zip
chromium_src-483414a22ae60ffcc24e0517be4a44c05375325e.tar.gz
chromium_src-483414a22ae60ffcc24e0517be4a44c05375325e.tar.bz2
Switch host to the new signaling code.
BUG=110485 Review URL: http://codereview.chromium.org/9365025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@122943 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r--remoting/host/chromoting_host.cc7
-rw-r--r--remoting/jingle_glue/jingle_signaling_connector.cc111
-rw-r--r--remoting/jingle_glue/jingle_signaling_connector.h64
-rw-r--r--remoting/protocol/jingle_channel_connector.h42
-rw-r--r--remoting/protocol/jingle_datagram_connector.cc44
-rw-r--r--remoting/protocol/jingle_datagram_connector.h46
-rw-r--r--remoting/protocol/jingle_session.cc588
-rw-r--r--remoting/protocol/jingle_session.h166
-rw-r--r--remoting/protocol/jingle_session_manager.cc271
-rw-r--r--remoting/protocol/jingle_session_manager.h125
-rw-r--r--remoting/protocol/jingle_session_unittest.cc395
-rw-r--r--remoting/protocol/jingle_stream_connector.cc131
-rw-r--r--remoting/protocol/jingle_stream_connector.h73
-rw-r--r--remoting/remoting.gyp12
14 files changed, 5 insertions, 2070 deletions
diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc
index 8865e2d..920ad1e 100644
--- a/remoting/host/chromoting_host.cc
+++ b/remoting/host/chromoting_host.cc
@@ -22,7 +22,8 @@
#include "remoting/protocol/client_stub.h"
#include "remoting/protocol/host_stub.h"
#include "remoting/protocol/input_stub.h"
-#include "remoting/protocol/jingle_session_manager.h"
+#include "remoting/protocol/libjingle_transport_factory.h"
+#include "remoting/protocol/pepper_session_manager.h"
#include "remoting/protocol/session_config.h"
using remoting::protocol::ConnectionToClient;
@@ -67,8 +68,10 @@ void ChromotingHost::Start() {
state_ = kStarted;
// Create and start session manager.
+ scoped_ptr<protocol::TransportFactory> transport_factory(
+ new protocol::LibjingleTransportFactory());
session_manager_.reset(
- new protocol::JingleSessionManager(context_->network_message_loop()));
+ new protocol::PepperSessionManager(transport_factory.Pass()));
session_manager_->Init(signal_strategy_, this, network_settings_);
}
diff --git a/remoting/jingle_glue/jingle_signaling_connector.cc b/remoting/jingle_glue/jingle_signaling_connector.cc
deleted file mode 100644
index 913633a..0000000
--- a/remoting/jingle_glue/jingle_signaling_connector.cc
+++ /dev/null
@@ -1,111 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "remoting/jingle_glue/jingle_signaling_connector.h"
-
-#include "base/logging.h"
-#include "base/stl_util.h"
-#include "third_party/libjingle/source/talk/p2p/base/sessionmanager.h"
-#include "third_party/libjingle/source/talk/xmpp/constants.h"
-#include "third_party/libjingle/source/talk/xmpp/xmppclient.h"
-
-namespace remoting {
-
-namespace {
-
-// GTalk sometimes generates service-unavailable error messages with
-// incorrect namespace. This method fixes such messages.
-// TODO(sergeyu): Fix this on the server side.
-void FixErrorStanza(buzz::XmlElement* stanza) {
- if (!stanza->FirstNamed(buzz::QN_ERROR)) {
- buzz::XmlElement* error = stanza->FirstNamed(buzz::QName("", "error"));
- error->SetName(buzz::QN_ERROR);
- }
-}
-
-} // namespace
-
-JingleSignalingConnector::JingleSignalingConnector(
- SignalStrategy* signal_strategy,
- cricket::SessionManager* session_manager)
- : signal_strategy_(signal_strategy),
- session_manager_(session_manager) {
-
- session_manager_->SignalOutgoingMessage.connect(
- this, &JingleSignalingConnector::OnOutgoingMessage);
-
- signal_strategy_->AddListener(this);
-
- // Assume that signaling is ready from the beginning.
- session_manager_->SignalRequestSignaling.connect(
- session_manager_, &cricket::SessionManager::OnSignalingReady);
-}
-
-JingleSignalingConnector::~JingleSignalingConnector() {
- signal_strategy_->RemoveListener(this);
- STLDeleteContainerPairSecondPointers(pending_requests_.begin(),
- pending_requests_.end());
-}
-
-void JingleSignalingConnector::OnSignalStrategyStateChange(
- SignalStrategy::State state) {
-}
-
-bool JingleSignalingConnector::OnSignalStrategyIncomingStanza(
- const buzz::XmlElement* stanza) {
- if (session_manager_->IsSessionMessage(stanza)) {
- session_manager_->OnIncomingMessage(stanza);
- return true;
- }
-
- if (stanza->Name() == buzz::QN_IQ) {
- std::string type = stanza->Attr(buzz::QN_TYPE);
- std::string id = stanza->Attr(buzz::QN_ID);
- if ((type == "error" || type == "result") && !id.empty()) {
- IqRequestsMap::iterator it = pending_requests_.find(id);
- if (it != pending_requests_.end()) {
- if (type == "result") {
- session_manager_->OnIncomingResponse(it->second, stanza);
- } else {
- scoped_ptr<buzz::XmlElement> stanza_copy(
- new buzz::XmlElement(*stanza));
- FixErrorStanza(stanza_copy.get());
- session_manager_->OnFailedSend(it->second, stanza_copy.get());
- }
- delete it->second;
- pending_requests_.erase(it);
- return true;
- }
- }
- }
-
- return false;
-}
-
-void JingleSignalingConnector::OnOutgoingMessage(
- cricket::SessionManager* session_manager,
- const buzz::XmlElement* stanza) {
- DCHECK_EQ(session_manager, session_manager_);
- scoped_ptr<buzz::XmlElement> stanza_copy(new buzz::XmlElement(*stanza));
-
- if (stanza_copy->Name() == buzz::QN_IQ) {
- std::string type = stanza_copy->Attr(buzz::QN_TYPE);
- if (type == "set" || type == "get") {
- std::string id = stanza_copy->Attr(buzz::QN_ID);
-
- // Add ID attribute for set and get stanzas if it is not there.
- if (id.empty()) {
- id = signal_strategy_->GetNextId();
- stanza_copy->SetAttr(buzz::QN_ID, id);
- }
-
- // Save the outgoing request for OnIncomingResponse().
- pending_requests_[id] = new buzz::XmlElement(*stanza);
- }
- }
-
- signal_strategy_->SendStanza(stanza_copy.release());
-}
-
-} // namespace remoting
diff --git a/remoting/jingle_glue/jingle_signaling_connector.h b/remoting/jingle_glue/jingle_signaling_connector.h
deleted file mode 100644
index f26fb32..0000000
--- a/remoting/jingle_glue/jingle_signaling_connector.h
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef REMOTING_JINGLE_GLUE_JINGLE_SIGNALING_CONNECTOR_H_
-#define REMOTING_JINGLE_GLUE_JINGLE_SIGNALING_CONNECTOR_H_
-
-#include <map>
-
-#include "base/basictypes.h"
-#include "base/memory/scoped_ptr.h"
-#include "remoting/jingle_glue/signal_strategy.h"
-#include "third_party/libjingle/source/talk/base/sigslot.h"
-
-namespace buzz {
-class XmlElement;
-} // namespace buzz
-
-namespace cricket {
-class SessionManager;
-} // namespace cricket
-
-namespace remoting {
-
-class IqRequest;
-
-// This class handles proxying the Jingle establishment messages between the
-// client and the server when proxying XMPP through Javascript.
-//
-// The |request| object is used to send and receive IQ stanzas from the XMPP
-// network. The |session_manager| controls sending and receiving of stanzas
-// after Run() is invoked.
-//
-// This class is not threadsafe, and should only be used on the thread it is
-// created on.
-class JingleSignalingConnector : public SignalStrategy::Listener,
- public sigslot::has_slots<> {
- public:
- JingleSignalingConnector(SignalStrategy* signal_strategy,
- cricket::SessionManager* session_manager);
- virtual ~JingleSignalingConnector();
-
- // SignalStrategy::Listener interface.
- virtual void OnSignalStrategyStateChange(
- SignalStrategy::State state) OVERRIDE;
- virtual bool OnSignalStrategyIncomingStanza(
- const buzz::XmlElement* stanza) OVERRIDE;
-
- private:
- typedef std::map<std::string, buzz::XmlElement*> IqRequestsMap;
-
- void OnOutgoingMessage(cricket::SessionManager* manager,
- const buzz::XmlElement* stanza);
-
- SignalStrategy* signal_strategy_;
- cricket::SessionManager* session_manager_;
- IqRequestsMap pending_requests_;
-
- DISALLOW_COPY_AND_ASSIGN(JingleSignalingConnector);
-};
-
-} // namespace remoting
-
-#endif // REMOTING_JINGLE_GLUE_JINGLE_SIGNALING_CONNECTOR_H_
diff --git a/remoting/protocol/jingle_channel_connector.h b/remoting/protocol/jingle_channel_connector.h
deleted file mode 100644
index 41c3692..0000000
--- a/remoting/protocol/jingle_channel_connector.h
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef REMOTING_PROTOCOL_JINGLE_CHANNEL_CONNECTOR_H_
-#define REMOTING_PROTOCOL_JINGLE_CHANNEL_CONNECTOR_H_
-
-#include <string>
-
-#include "base/basictypes.h"
-#include "base/threading/non_thread_safe.h"
-
-namespace cricket {
-class TransportChannel;
-} // namespace cricket
-
-namespace crypto {
-class RSAPrivateKey;
-} // namespace crypto
-
-namespace remoting {
-namespace protocol {
-
-class ChannelAuthenticator;
-
-class JingleChannelConnector : public base::NonThreadSafe {
- public:
- JingleChannelConnector() { }
- virtual ~JingleChannelConnector() { }
-
- // Starts the connection process for the channel.
- virtual void Connect(scoped_ptr<ChannelAuthenticator> authenticator,
- cricket::TransportChannel* raw_channel) = 0;
-
- protected:
- DISALLOW_COPY_AND_ASSIGN(JingleChannelConnector);
-};
-
-} // namespace protocol
-} // namespace remoting
-
-#endif // REMOTING_PROTOCOL_JINGLE_CHANNEL_CONNECTOR_H_
diff --git a/remoting/protocol/jingle_datagram_connector.cc b/remoting/protocol/jingle_datagram_connector.cc
deleted file mode 100644
index 652bf0d2..0000000
--- a/remoting/protocol/jingle_datagram_connector.cc
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "remoting/protocol/jingle_datagram_connector.h"
-
-#include "jingle/glue/channel_socket_adapter.h"
-#include "remoting/protocol/channel_authenticator.h"
-#include "remoting/protocol/jingle_session.h"
-
-namespace remoting {
-namespace protocol {
-
-JingleDatagramConnector::JingleDatagramConnector(
- JingleSession* session,
- const std::string& name,
- const Session::DatagramChannelCallback& callback)
- : session_(session),
- name_(name),
- callback_(callback) {
-}
-
-JingleDatagramConnector::~JingleDatagramConnector() {
-}
-
-void JingleDatagramConnector::Connect(
- scoped_ptr<ChannelAuthenticator> authenticator,
- cricket::TransportChannel* raw_channel) {
- DCHECK(CalledOnValidThread());
-
- authenticator_ = authenticator.Pass();
-
- scoped_ptr<net::Socket> socket(
- new jingle_glue::TransportChannelSocketAdapter(raw_channel));
-
- // TODO(sergeyu): Implement encryption for datagram channels.
-
- session_->OnChannelConnectorFinished(name_, this);
- callback_.Run(socket.Pass());
- delete this;
-}
-
-} // namespace protocol
-} // namespace remoting
diff --git a/remoting/protocol/jingle_datagram_connector.h b/remoting/protocol/jingle_datagram_connector.h
deleted file mode 100644
index 7814e16..0000000
--- a/remoting/protocol/jingle_datagram_connector.h
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef REMOTING_PROTOCOL_JINGLE_DATAGRAM_CONNECTOR_H_
-#define REMOTING_PROTOCOL_JINGLE_DATAGRAM_CONNECTOR_H_
-
-#include <string>
-
-#include "net/base/completion_callback.h"
-#include "remoting/protocol/jingle_channel_connector.h"
-#include "remoting/protocol/session.h"
-
-namespace remoting {
-namespace protocol {
-
-class JingleSession;
-
-class JingleDatagramConnector : public JingleChannelConnector {
- public:
- JingleDatagramConnector(JingleSession* session,
- const std::string& name,
- const Session::DatagramChannelCallback& callback);
- virtual ~JingleDatagramConnector();
-
- // JingleChannelConnector implementation.
- // TODO(sergeyu): In the current implementation ChannelAuthenticator
- // cannot be used for datagram channels, so needs to be either
- // extended or replaced with something else here.
- virtual void Connect(scoped_ptr<ChannelAuthenticator> authenticator,
- cricket::TransportChannel* raw_channel) OVERRIDE;
-
- private:
- JingleSession* session_;
- std::string name_;
- Session::DatagramChannelCallback callback_;
-
- scoped_ptr<ChannelAuthenticator> authenticator_;
-
- DISALLOW_COPY_AND_ASSIGN(JingleDatagramConnector);
-};
-
-} // namespace protocol
-} // namespace remoting
-
-#endif // REMOTING_PROTOCOL_JINGLE_DATAGRAM_CONNECTOR_H_
diff --git a/remoting/protocol/jingle_session.cc b/remoting/protocol/jingle_session.cc
deleted file mode 100644
index a1123be..0000000
--- a/remoting/protocol/jingle_session.cc
+++ /dev/null
@@ -1,588 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "remoting/protocol/jingle_session.h"
-
-#include "base/base64.h"
-#include "base/bind.h"
-#include "base/location.h"
-#include "base/logging.h"
-#include "base/message_loop_proxy.h"
-#include "base/rand_util.h"
-#include "base/stl_util.h"
-#include "crypto/hmac.h"
-#include "jingle/glue/utils.h"
-#include "net/base/ip_endpoint.h"
-#include "net/base/net_errors.h"
-#include "net/base/net_util.h"
-#include "net/socket/stream_socket.h"
-#include "remoting/base/constants.h"
-#include "remoting/protocol/auth_util.h"
-#include "remoting/protocol/authenticator.h"
-#include "remoting/protocol/channel_authenticator.h"
-#include "remoting/protocol/jingle_datagram_connector.h"
-#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"
-
-using cricket::BaseSession;
-
-namespace remoting {
-namespace protocol {
-
-JingleSession::JingleSession(
- JingleSessionManager* jingle_session_manager,
- cricket::Session* cricket_session,
- scoped_ptr<Authenticator> authenticator)
- : jingle_session_manager_(jingle_session_manager),
- authenticator_(authenticator.Pass()),
- state_(INITIALIZING),
- error_(OK),
- closing_(false),
- cricket_session_(cricket_session),
- config_set_(false),
- ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
- jid_ = cricket_session_->remote_name();
- cricket_session_->SignalState.connect(this, &JingleSession::OnSessionState);
- cricket_session_->SignalError.connect(this, &JingleSession::OnSessionError);
- cricket_session_->SignalInfoMessage.connect(
- this, &JingleSession::OnSessionInfoMessage);
- cricket_session_->SignalReceivedTerminateReason.connect(
- this, &JingleSession::OnTerminateReason);
-}
-
-JingleSession::~JingleSession() {
- // Reset the callback so that it's not called from Close().
- state_change_callback_.Reset();
- Close();
- jingle_session_manager_->SessionDestroyed(this);
- DCHECK(channel_connectors_.empty());
-}
-
-void JingleSession::SendSessionInitiate() {
- DCHECK_EQ(authenticator_->state(), Authenticator::MESSAGE_READY);
- cricket_session_->Initiate(
- jid_, CreateSessionDescription(
- candidate_config()->Clone(),
- authenticator_->GetNextMessage()).release());
-}
-
-void JingleSession::CloseInternal(int result, Error error) {
- DCHECK(CalledOnValidThread());
-
- if (state_ != FAILED && state_ != CLOSED && !closing_) {
- closing_ = true;
-
- // Tear down the cricket session, including the cricket transport channels.
- if (cricket_session_) {
- std::string reason;
- switch (error) {
- case OK:
- reason = cricket::STR_TERMINATE_SUCCESS;
- break;
- case SESSION_REJECTED:
- case AUTHENTICATION_FAILED:
- reason = cricket::STR_TERMINATE_DECLINE;
- break;
- case INCOMPATIBLE_PROTOCOL:
- reason = cricket::STR_TERMINATE_INCOMPATIBLE_PARAMETERS;
- break;
- default:
- reason = cricket::STR_TERMINATE_ERROR;
- }
- cricket_session_->TerminateWithReason(reason);
- cricket_session_->SignalState.disconnect(this);
- }
-
- error_ = error;
-
- // Inform the StateChangeCallback, so calling code knows not to
- // touch any channels. Needs to be done in the end because the
- // session may be deleted in response to this event.
- if (error != OK) {
- SetState(FAILED);
- } else {
- SetState(CLOSED);
- }
- }
-}
-
-bool JingleSession::HasSession(cricket::Session* cricket_session) {
- DCHECK(CalledOnValidThread());
- return cricket_session_ == cricket_session;
-}
-
-cricket::Session* JingleSession::ReleaseSession() {
- DCHECK(CalledOnValidThread());
-
- // Session may be destroyed only after it is closed.
- DCHECK(state_ == FAILED || state_ == CLOSED);
-
- cricket::Session* session = cricket_session_;
- if (cricket_session_)
- cricket_session_->SignalState.disconnect(this);
- cricket_session_ = NULL;
- return session;
-}
-
-void JingleSession::SetStateChangeCallback(
- const StateChangeCallback& callback) {
- DCHECK(CalledOnValidThread());
- DCHECK(!callback.is_null());
- state_change_callback_ = callback;
-}
-
-void JingleSession::SetRouteChangeCallback(
- const RouteChangeCallback& callback) {
- DCHECK(CalledOnValidThread());
- route_change_callback_ = callback;
-}
-
-Session::Error JingleSession::error() {
- DCHECK(CalledOnValidThread());
- return error_;
-}
-
-void JingleSession::CreateStreamChannel(
- const std::string& name, const StreamChannelCallback& callback) {
- DCHECK(CalledOnValidThread());
-
- AddChannelConnector(
- name, new JingleStreamConnector(this, name, callback));
-}
-
-void JingleSession::CreateDatagramChannel(
- const std::string& name, const DatagramChannelCallback& callback) {
- DCHECK(CalledOnValidThread());
-
- AddChannelConnector(
- name, new JingleDatagramConnector(this, name, callback));
-}
-
-void JingleSession::CancelChannelCreation(const std::string& name) {
- ChannelConnectorsMap::iterator it = channel_connectors_.find(name);
- if (it != channel_connectors_.end()) {
- delete it->second;
- channel_connectors_.erase(it);
- }
-}
-
-const std::string& JingleSession::jid() {
- DCHECK(CalledOnValidThread());
- return jid_;
-}
-
-const CandidateSessionConfig* JingleSession::candidate_config() {
- DCHECK(CalledOnValidThread());
- DCHECK(candidate_config_.get());
- return candidate_config_.get();
-}
-
-void JingleSession::set_candidate_config(
- scoped_ptr<CandidateSessionConfig> candidate_config) {
- DCHECK(CalledOnValidThread());
- DCHECK(!candidate_config_.get());
- DCHECK(candidate_config.get());
- candidate_config_ = candidate_config.Pass();
-}
-
-const SessionConfig& JingleSession::config() {
- DCHECK(CalledOnValidThread());
- DCHECK(config_set_);
- return config_;
-}
-
-void JingleSession::set_config(const SessionConfig& config) {
- DCHECK(CalledOnValidThread());
- DCHECK(!config_set_);
- config_ = config;
- config_set_ = true;
-}
-
-void JingleSession::Close() {
- DCHECK(CalledOnValidThread());
-
- CloseInternal(net::ERR_CONNECTION_CLOSED, OK);
-}
-
-void JingleSession::OnSessionState(
- BaseSession* session, BaseSession::State state) {
- DCHECK(CalledOnValidThread());
- DCHECK_EQ(cricket_session_, session);
-
- if (state_ == FAILED || state_ == CLOSED) {
- // Don't do anything if we already closed.
- return;
- }
-
- switch (state) {
- case cricket::Session::STATE_SENTINITIATE:
- case cricket::Session::STATE_RECEIVEDINITIATE:
- OnInitiate();
- break;
-
- case cricket::Session::STATE_SENTACCEPT:
- case cricket::Session::STATE_RECEIVEDACCEPT:
- OnAccept();
- break;
-
- case cricket::Session::STATE_SENTTERMINATE:
- case cricket::Session::STATE_RECEIVEDTERMINATE:
- case cricket::Session::STATE_SENTREJECT:
- case cricket::Session::STATE_RECEIVEDREJECT:
- OnTerminate();
- break;
-
- case cricket::Session::STATE_DEINIT:
- // Close() must have been called before this.
- NOTREACHED();
- break;
-
- default:
- // We don't care about other steates.
- break;
- }
-}
-
-void JingleSession::OnSessionError(
- BaseSession* session, BaseSession::Error error) {
- DCHECK(CalledOnValidThread());
- DCHECK_EQ(cricket_session_, session);
-
- if (error != cricket::Session::ERROR_NONE) {
- // TODO(sergeyu): Report different errors depending on |error|.
- CloseInternal(net::ERR_CONNECTION_ABORTED, CHANNEL_CONNECTION_ERROR);
- }
-}
-
-void JingleSession::OnSessionInfoMessage(cricket::Session* session,
- const buzz::XmlElement* message) {
- DCHECK_EQ(cricket_session_,session);
-
- const buzz::XmlElement* auth_message =
- Authenticator::FindAuthenticatorMessage(message);
- if (auth_message) {
- if (state_ != CONNECTED ||
- authenticator_->state() != Authenticator::WAITING_MESSAGE) {
- LOG(WARNING) << "Received unexpected authenticator message "
- << auth_message->Str();
- return;
- }
-
- authenticator_->ProcessMessage(auth_message);
- ProcessAuthenticationStep();
- }
-}
-
-void JingleSession::OnTerminateReason(cricket::Session* session,
- const std::string& reason) {
- terminate_reason_ = reason;
-}
-
-void JingleSession::OnInitiate() {
- DCHECK(CalledOnValidThread());
- jid_ = cricket_session_->remote_name();
-
- if (cricket_session_->initiator()) {
- // Set state to CONNECTING if this is an outgoing message. We need
- // to post this task because channel creation works only after we
- // return from this method. This is because
- // JingleChannelConnector::Connect() needs to call
- // set_incoming_only() on P2PTransportChannel, but
- // P2PTransportChannel is created only after we return from this
- // method.
- // TODO(sergeyu): Add set_incoming_only() in TransportChannelProxy.
- jingle_session_manager_->message_loop_->PostTask(
- FROM_HERE,
- base::Bind(&JingleSession::SetState,
- weak_factory_.GetWeakPtr(),
- CONNECTING));
- } else {
- jingle_session_manager_->message_loop_->PostTask(
- FROM_HERE,
- base::Bind(&JingleSession::AcceptConnection,
- weak_factory_.GetWeakPtr()));
- }
-}
-
-bool JingleSession::InitializeConfigFromDescription(
- const cricket::SessionDescription* description) {
- // We should only be called after ParseContent has succeeded, in which
- // case there will always be a Chromoting session configuration.
- const cricket::ContentInfo* content =
- description->FirstContentByType(kChromotingXmlNamespace);
- CHECK(content);
- const protocol::ContentDescription* content_description =
- static_cast<const protocol::ContentDescription*>(content->description);
- CHECK(content_description);
-
- // Process authenticator message.
- const buzz::XmlElement* auth_message =
- content_description->authenticator_message();
- if (!auth_message) {
- DLOG(WARNING) << "Received session-accept without authentication message "
- << auth_message->Str();
- return false;
- }
-
- DCHECK_EQ(authenticator_->state(), Authenticator::WAITING_MESSAGE);
- authenticator_->ProcessMessage(auth_message);
-
- // Initialize session configuration.
- SessionConfig config;
- if (!content_description->config()->GetFinalConfig(&config)) {
- LOG(ERROR) << "Connection response does not specify configuration";
- return false;
- }
- if (!candidate_config()->IsSupported(config)) {
- LOG(ERROR) << "Connection response specifies an invalid configuration";
- return false;
- }
-
- set_config(config);
- return true;
-}
-
-void JingleSession::OnAccept() {
- DCHECK(CalledOnValidThread());
-
- // If we initiated the session, store the candidate configuration that the
- // host responded with, to refer to later.
- if (cricket_session_->initiator()) {
- if (!InitializeConfigFromDescription(
- cricket_session_->remote_description())) {
- CloseInternal(net::ERR_CONNECTION_FAILED, INCOMPATIBLE_PROTOCOL);
- return;
- }
- }
-
- SetState(CONNECTED);
-
- // Process authentication.
- if (authenticator_->state() == Authenticator::ACCEPTED) {
- SetState(AUTHENTICATED);
- } else {
- ProcessAuthenticationStep();
- }
-}
-
-void JingleSession::OnTerminate() {
- DCHECK(CalledOnValidThread());
-
- if (terminate_reason_ == "success") {
- CloseInternal(net::ERR_CONNECTION_ABORTED, OK);
- } else if (terminate_reason_ == "decline") {
- CloseInternal(net::ERR_CONNECTION_ABORTED, AUTHENTICATION_FAILED);
- } else if (terminate_reason_ == "incompatible-protocol") {
- CloseInternal(net::ERR_CONNECTION_ABORTED, INCOMPATIBLE_PROTOCOL);
- } else {
- CloseInternal(net::ERR_CONNECTION_ABORTED, UNKNOWN_ERROR);
- }
-}
-
-void JingleSession::AcceptConnection() {
- SetState(CONNECTING);
-
- const cricket::SessionDescription* session_description =
- cricket_session_->remote_description();
- const cricket::ContentInfo* content =
- session_description->FirstContentByType(kChromotingXmlNamespace);
-
- CHECK(content);
- const ContentDescription* content_description =
- static_cast<const ContentDescription*>(content->description);
- candidate_config_ = content_description->config()->Clone();
-
- SessionManager::IncomingSessionResponse response =
- jingle_session_manager_->AcceptConnection(this);
- if (response != SessionManager::ACCEPT) {
- if (response == SessionManager::INCOMPATIBLE) {
- cricket_session_->TerminateWithReason(
- cricket::STR_TERMINATE_INCOMPATIBLE_PARAMETERS);
- } else {
- cricket_session_->TerminateWithReason(cricket::STR_TERMINATE_DECLINE);
- }
- Close();
- // Release session so that JingleSessionManager::SessionDestroyed()
- // doesn't try to call cricket::SessionManager::DestroySession() for it.
- ReleaseSession();
- delete this;
- return;
- }
-
- const buzz::XmlElement* auth_message =
- content_description->authenticator_message();
- if (!auth_message) {
- DLOG(WARNING) << "Received session-initiate without authenticator message.";
- CloseInternal(net::ERR_CONNECTION_FAILED, INCOMPATIBLE_PROTOCOL);
- return;
- }
-
- authenticator_ =
- jingle_session_manager_->CreateAuthenticator(jid(), auth_message);
- if (!authenticator_.get()) {
- CloseInternal(net::ERR_CONNECTION_FAILED, INCOMPATIBLE_PROTOCOL);
- return;
- }
-
- DCHECK(authenticator_->state() == Authenticator::WAITING_MESSAGE);
- authenticator_->ProcessMessage(auth_message);
- if (authenticator_->state() == Authenticator::REJECTED) {
- CloseInternal(net::ERR_CONNECTION_FAILED,
- RejectionReasonToError(authenticator_->rejection_reason()));
- return;
- }
-
- // Connection must be configured by the AcceptConnection() callback.
- scoped_ptr<CandidateSessionConfig> candidate_config =
- CandidateSessionConfig::CreateFrom(config());
-
- scoped_ptr<buzz::XmlElement> auth_reply;
- if (authenticator_->state() == Authenticator::MESSAGE_READY)
- auth_reply = authenticator_->GetNextMessage();
- DCHECK_NE(authenticator_->state(), Authenticator::MESSAGE_READY);
- cricket_session_->Accept(
- CreateSessionDescription(candidate_config.Pass(),
- auth_reply.Pass()).release());
-}
-
-void JingleSession::ProcessAuthenticationStep() {
- DCHECK_EQ(state_, CONNECTED);
-
- if (authenticator_->state() == Authenticator::MESSAGE_READY) {
- scoped_ptr<buzz::XmlElement> auth_message =
- authenticator_->GetNextMessage();
- cricket::XmlElements message;
- message.push_back(auth_message.release());
- cricket_session_->SendInfoMessage(message);
- }
- DCHECK_NE(authenticator_->state(), Authenticator::MESSAGE_READY);
-
- if (authenticator_->state() == Authenticator::ACCEPTED) {
- SetState(AUTHENTICATED);
- } else if (authenticator_->state() == Authenticator::REJECTED) {
- CloseInternal(net::ERR_CONNECTION_FAILED,
- RejectionReasonToError(authenticator_->rejection_reason()));
- }
-}
-
-void JingleSession::AddChannelConnector(
- const std::string& name, JingleChannelConnector* connector) {
- DCHECK(channel_connectors_.find(name) == channel_connectors_.end());
-
- const std::string& content_name = GetContentInfo()->name;
- cricket::TransportChannel* raw_channel =
- cricket_session_->CreateChannel(content_name, name);
-
- raw_channel->SignalRouteChange.connect(this, &JingleSession::OnRouteChange);
-
- 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;
- scoped_ptr<ChannelAuthenticator> authenticator =
- authenticator_->CreateChannelAuthenticator();
- connector->Connect(authenticator.Pass(), raw_channel);
-
- // Workaround bug in libjingle - it doesn't connect channels if they
- // are created after the session is accepted. See crbug.com/89384.
- // TODO(sergeyu): Fix the bug and remove this line.
- cricket_session_->GetTransport(content_name)->ConnectChannels();
-}
-
-void JingleSession::OnChannelConnectorFinished(
- const std::string& name, JingleChannelConnector* connector) {
- DCHECK(CalledOnValidThread());
- DCHECK_EQ(channel_connectors_[name], connector);
- channel_connectors_.erase(name);
-}
-
-void JingleSession::OnRouteChange(cricket::TransportChannel* channel,
- const cricket::Candidate& candidate) {
- net::IPEndPoint remote_end_point;
- if (!jingle_glue::SocketAddressToIPEndPoint(candidate.address(),
- &remote_end_point)) {
- NOTREACHED();
- return;
- }
-
- DCHECK(channel->GetP2PChannel());
- DCHECK(channel->GetP2PChannel()->best_connection());
- const cricket::Candidate& local_candidate =
- channel->GetP2PChannel()->best_connection()->local_candidate();
- net::IPEndPoint local_end_point;
- if (!jingle_glue::SocketAddressToIPEndPoint(local_candidate.address(),
- &local_end_point)) {
- NOTREACHED();
- return;
- }
-
- if (!route_change_callback_.is_null()) {
- route_change_callback_.Run(channel->name(), remote_end_point,
- local_end_point);
- }
-}
-
-const cricket::ContentInfo* JingleSession::GetContentInfo() const {
- const cricket::SessionDescription* session_description;
- // If we initiate the session, we get to specify the content name. When
- // accepting one, the remote end specifies it.
- if (cricket_session_->initiator()) {
- session_description = cricket_session_->local_description();
- } else {
- session_description = cricket_session_->remote_description();
- }
- const cricket::ContentInfo* content =
- session_description->FirstContentByType(kChromotingXmlNamespace);
- CHECK(content);
- return content;
-}
-
-void JingleSession::SetState(State new_state) {
- DCHECK(CalledOnValidThread());
-
- if (new_state != state_) {
- DCHECK_NE(state_, CLOSED);
- DCHECK_NE(state_, FAILED);
-
- state_ = new_state;
- if (!state_change_callback_.is_null())
- state_change_callback_.Run(new_state);
- }
-}
-
-// static
-Session::Error JingleSession::RejectionReasonToError(
- Authenticator::RejectionReason reason) {
- switch (reason) {
- case Authenticator::INVALID_CREDENTIALS:
- return AUTHENTICATION_FAILED;
- case Authenticator::PROTOCOL_ERROR:
- return INCOMPATIBLE_PROTOCOL;
- }
- NOTREACHED();
- return UNKNOWN_ERROR;
-}
-
-// static
-scoped_ptr<cricket::SessionDescription> JingleSession::CreateSessionDescription(
- scoped_ptr<CandidateSessionConfig> config,
- scoped_ptr<buzz::XmlElement> authenticator_message) {
- scoped_ptr<cricket::SessionDescription> desc(
- new cricket::SessionDescription());
- desc->AddContent(
- ContentDescription::kChromotingContentName, kChromotingXmlNamespace,
- new ContentDescription(config.Pass(), authenticator_message.Pass()));
- return desc.Pass();
-}
-
-} // namespace protocol
-} // namespace remoting
diff --git a/remoting/protocol/jingle_session.h b/remoting/protocol/jingle_session.h
deleted file mode 100644
index e5e382e..0000000
--- a/remoting/protocol/jingle_session.h
+++ /dev/null
@@ -1,166 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef REMOTING_PROTOCOL_JINGLE_SESSION_H_
-#define REMOTING_PROTOCOL_JINGLE_SESSION_H_
-
-#include "base/memory/ref_counted.h"
-#include "base/memory/weak_ptr.h"
-#include "net/base/completion_callback.h"
-#include "remoting/protocol/authenticator.h"
-#include "remoting/protocol/session.h"
-#include "third_party/libjingle/source/talk/base/sigslot.h"
-#include "third_party/libjingle/source/talk/p2p/base/session.h"
-
-namespace remoting {
-namespace protocol {
-
-class JingleChannelConnector;
-class JingleSessionManager;
-
-// Implements protocol::Session that work over libjingle session (the
-// cricket::Session object is passed to Init() method). Created
-// by JingleSessionManager for incoming and outgoing connections.
-class JingleSession : public protocol::Session,
- public sigslot::has_slots<> {
- public:
- virtual ~JingleSession();
-
- // Session interface.
- virtual void SetStateChangeCallback(
- const StateChangeCallback& callback) OVERRIDE;
- virtual void SetRouteChangeCallback(
- const RouteChangeCallback& callback) OVERRIDE;
- virtual Error error() OVERRIDE;
- virtual void CreateStreamChannel(
- const std::string& name,
- const StreamChannelCallback& callback) OVERRIDE;
- virtual void CreateDatagramChannel(
- const std::string& name,
- const DatagramChannelCallback& callback) OVERRIDE;
- virtual void CancelChannelCreation(const std::string& name) OVERRIDE;
- virtual const std::string& jid() OVERRIDE;
- virtual const CandidateSessionConfig* candidate_config() OVERRIDE;
- virtual const SessionConfig& config() OVERRIDE;
- virtual void set_config(const SessionConfig& config) OVERRIDE;
- virtual void Close() OVERRIDE;
-
- private:
- friend class JingleDatagramConnector;
- friend class JingleSessionManager;
- friend class JingleStreamConnector;
-
- typedef std::map<std::string, JingleChannelConnector*> ChannelConnectorsMap;
-
- JingleSession(JingleSessionManager* jingle_session_manager,
- cricket::Session* cricket_session,
- scoped_ptr<Authenticator> authenticator);
-
- // Called by JingleSessionManager.
- void set_candidate_config(
- scoped_ptr<CandidateSessionConfig> candidate_config);
-
- // Sends session-initiate for new session.
- void SendSessionInitiate();
-
- // Close all the channels and terminate the session. |result|
- // defines error code that should returned to currently opened
- // channels. |error| specified new value for error().
- void CloseInternal(int result, Error error);
-
- bool HasSession(cricket::Session* cricket_session);
- cricket::Session* ReleaseSession();
-
- // Initialize the session configuration from a received connection response
- // stanza.
- bool InitializeConfigFromDescription(
- const cricket::SessionDescription* description);
-
- // Handlers for |cricket_session_| signals.
- void OnSessionState(cricket::BaseSession* session,
- cricket::BaseSession::State state);
- void OnSessionError(cricket::BaseSession* session,
- cricket::BaseSession::Error error);
- void OnSessionInfoMessage(cricket::Session* session,
- const buzz::XmlElement* message);
- void OnTerminateReason(cricket::Session* session,
- const std::string& reason);
-
- void OnInitiate();
- void OnAccept();
- void OnTerminate();
-
- // Notifies upper layer about incoming connection and
- // accepts/rejects connection.
- void AcceptConnection();
-
- void ProcessAuthenticationStep();
-
- void AddChannelConnector(const std::string& name,
- JingleChannelConnector* connector);
-
- // Called by JingleChannelConnector when it has finished connecting
- // the channel, to remove itself from the table of pending connectors. The
- // connector assumes responsibility for destroying itself after this call.
- void OnChannelConnectorFinished(const std::string& name,
- JingleChannelConnector* connector);
-
- void OnRouteChange(cricket::TransportChannel* channel,
- const cricket::Candidate& candidate);
-
- const cricket::ContentInfo* GetContentInfo() const;
-
- void SetState(State new_state);
-
- static Error RejectionReasonToError(Authenticator::RejectionReason reason);
-
- static scoped_ptr<cricket::SessionDescription> CreateSessionDescription(
- scoped_ptr<CandidateSessionConfig> candidate_config,
- scoped_ptr<buzz::XmlElement> authenticator_message);
-
- // JingleSessionManager that created this session. Guaranteed to
- // exist throughout the lifetime of the session.
- JingleSessionManager* jingle_session_manager_;
-
- scoped_ptr<Authenticator> authenticator_;
-
- State state_;
- StateChangeCallback state_change_callback_;
- RouteChangeCallback route_change_callback_;
-
- Error error_;
-
- bool closing_;
-
- // JID of the other side. Set when the connection is initialized,
- // and never changed after that.
- std::string jid_;
-
- // The corresponding libjingle session.
- cricket::Session* cricket_session_;
-
- SessionConfig config_;
- bool config_set_;
-
- // These data members are only set on the receiving side.
- scoped_ptr<const CandidateSessionConfig> candidate_config_;
-
- // Channels that are currently being connected.
- ChannelConnectorsMap channel_connectors_;
-
- // Termination reason. Needs to be stored because
- // SignalReceivedTerminateReason handler is not allowed to destroy
- // the object.
- std::string terminate_reason_;
-
- base::WeakPtrFactory<JingleSession> weak_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(JingleSession);
-};
-
-} // namespace protocol
-
-} // namespace remoting
-
-#endif // REMOTING_PROTOCOL_JINGLE_SESSION_H_
diff --git a/remoting/protocol/jingle_session_manager.cc b/remoting/protocol/jingle_session_manager.cc
deleted file mode 100644
index 8bc0533..0000000
--- a/remoting/protocol/jingle_session_manager.cc
+++ /dev/null
@@ -1,271 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "remoting/protocol/jingle_session_manager.h"
-
-#include <limits>
-
-#include "base/base64.h"
-#include "base/bind.h"
-#include "base/message_loop_proxy.h"
-#include "base/string_util.h"
-#include "remoting/base/constants.h"
-#include "remoting/jingle_glue/jingle_info_request.h"
-#include "remoting/jingle_glue/jingle_signaling_connector.h"
-#include "remoting/jingle_glue/signal_strategy.h"
-#include "remoting/protocol/authenticator.h"
-#include "third_party/libjingle/source/talk/base/basicpacketsocketfactory.h"
-#include "third_party/libjingle/source/talk/p2p/base/constants.h"
-#include "third_party/libjingle/source/talk/p2p/base/sessionmanager.h"
-#include "third_party/libjingle/source/talk/p2p/base/transport.h"
-#include "third_party/libjingle/source/talk/p2p/client/httpportallocator.h"
-#include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
-
-using buzz::XmlElement;
-
-namespace remoting {
-namespace protocol {
-
-JingleSessionManager::JingleSessionManager(
- base::MessageLoopProxy* message_loop)
- : message_loop_(message_loop),
- signal_strategy_(NULL),
- listener_(NULL),
- allow_nat_traversal_(false),
- ready_(false),
- http_port_allocator_(NULL),
- closed_(false) {
-}
-
-JingleSessionManager::~JingleSessionManager() {
- // Session manager can be destroyed only after all sessions are destroyed.
- DCHECK(sessions_.empty());
- Close();
-}
-
-void JingleSessionManager::Init(
- SignalStrategy* signal_strategy,
- SessionManager::Listener* listener,
- const NetworkSettings& network_settings) {
- DCHECK(CalledOnValidThread());
-
- DCHECK(signal_strategy);
- DCHECK(listener);
-
- signal_strategy_ = signal_strategy;
- listener_ = listener;
- allow_nat_traversal_ = network_settings.allow_nat_traversal;
-
- signal_strategy_->AddListener(this);
-
- if (!network_manager_.get()) {
- VLOG(1) << "Creating talk_base::NetworkManager.";
- network_manager_.reset(new talk_base::BasicNetworkManager());
- }
- if (!socket_factory_.get()) {
- VLOG(1) << "Creating talk_base::BasicPacketSocketFactory.";
- socket_factory_.reset(new talk_base::BasicPacketSocketFactory(
- talk_base::Thread::Current()));
- }
-
- // Initialize |port_allocator_|.
-
- // We always use PseudoTcp to provide a reliable channel. However
- // when it is used together with TCP the performance is very bad
- // so we explicitly disables TCP connections.
- int port_allocator_flags = cricket::PORTALLOCATOR_DISABLE_TCP;
-
- if (allow_nat_traversal_) {
- http_port_allocator_ = new cricket::HttpPortAllocator(
- network_manager_.get(), socket_factory_.get(), "transp2");
- port_allocator_.reset(http_port_allocator_);
- } else {
- port_allocator_flags |= cricket::PORTALLOCATOR_DISABLE_STUN |
- cricket::PORTALLOCATOR_DISABLE_RELAY;
- port_allocator_.reset(
- new cricket::BasicPortAllocator(
- network_manager_.get(), socket_factory_.get()));
- }
- port_allocator_->set_flags(port_allocator_flags);
-
- port_allocator_->SetPortRange(
- network_settings.min_port, network_settings.max_port);
-
- // Initialize |cricket_session_manager_|.
- cricket_session_manager_.reset(
- new cricket::SessionManager(port_allocator_.get()));
- cricket_session_manager_->AddClient(kChromotingXmlNamespace, this);
-
- jingle_signaling_connector_.reset(new JingleSignalingConnector(
- signal_strategy_, cricket_session_manager_.get()));
-
- OnSignalStrategyStateChange(signal_strategy_->GetState());
-}
-
-void JingleSessionManager::Close() {
- DCHECK(CalledOnValidThread());
-
- if (!closed_) {
- jingle_info_request_.reset();
- cricket_session_manager_->RemoveClient(kChromotingXmlNamespace);
- jingle_signaling_connector_.reset();
- signal_strategy_->RemoveListener(this);
- closed_ = true;
- }
-}
-
-void JingleSessionManager::set_authenticator_factory(
- scoped_ptr<AuthenticatorFactory> authenticator_factory) {
- DCHECK(CalledOnValidThread());
- DCHECK(authenticator_factory.get());
- DCHECK(!authenticator_factory_.get());
- authenticator_factory_ = authenticator_factory.Pass();
-}
-
-scoped_ptr<Session> JingleSessionManager::Connect(
- const std::string& host_jid,
- scoped_ptr<Authenticator> authenticator,
- scoped_ptr<CandidateSessionConfig> config,
- const Session::StateChangeCallback& state_change_callback) {
- DCHECK(CalledOnValidThread());
-
- cricket::Session* cricket_session = cricket_session_manager_->CreateSession(
- signal_strategy_->GetLocalJid(), kChromotingXmlNamespace);
- cricket_session->set_remote_name(host_jid);
-
- scoped_ptr<JingleSession> jingle_session(
- new JingleSession(this, cricket_session, authenticator.Pass()));
- jingle_session->set_candidate_config(config.Pass());
- jingle_session->SetStateChangeCallback(state_change_callback);
- sessions_.push_back(jingle_session.get());
-
- jingle_session->SendSessionInitiate();
-
- return jingle_session.PassAs<Session>();
-}
-
-void JingleSessionManager::OnSessionCreate(
- cricket::Session* cricket_session, bool incoming) {
- DCHECK(CalledOnValidThread());
-
- // Allow local connections.
- cricket_session->set_allow_local_ips(true);
-
- if (incoming) {
- JingleSession* jingle_session =
- new JingleSession(this, cricket_session, scoped_ptr<Authenticator>());
- sessions_.push_back(jingle_session);
- }
-}
-
-void JingleSessionManager::OnSessionDestroy(cricket::Session* cricket_session) {
- DCHECK(CalledOnValidThread());
-
- std::list<JingleSession*>::iterator it;
- for (it = sessions_.begin(); it != sessions_.end(); ++it) {
- if ((*it)->HasSession(cricket_session)) {
- (*it)->ReleaseSession();
- return;
- }
- }
-}
-
-void JingleSessionManager::OnSignalStrategyStateChange(
- SignalStrategy::State state) {
- if (state == SignalStrategy::CONNECTED) {
- // If NAT traversal is enabled then we need to request STUN/Relay info.
- if (allow_nat_traversal_) {
- jingle_info_request_.reset(new JingleInfoRequest(signal_strategy_));
- jingle_info_request_->Send(base::Bind(
- &JingleSessionManager::OnJingleInfo, base::Unretained(this)));
- } else if (!ready_) {
- ready_ = true;
- listener_->OnSessionManagerReady();
- }
- }
-}
-
-SessionManager::IncomingSessionResponse JingleSessionManager::AcceptConnection(
- JingleSession* jingle_session) {
- DCHECK(CalledOnValidThread());
-
- // Reject connection if we are closed.
- if (closed_)
- return SessionManager::DECLINE;
-
- IncomingSessionResponse response = SessionManager::DECLINE;
- listener_->OnIncomingSession(jingle_session, &response);
- return response;
-}
-
-scoped_ptr<Authenticator> JingleSessionManager::CreateAuthenticator(
- const std::string& jid, const buzz::XmlElement* auth_message) {
- DCHECK(CalledOnValidThread());
-
- if (!authenticator_factory_.get())
- return scoped_ptr<Authenticator>(NULL);
- return authenticator_factory_->CreateAuthenticator(jid, auth_message);
-}
-
-void JingleSessionManager::SessionDestroyed(JingleSession* jingle_session) {
- std::list<JingleSession*>::iterator it =
- std::find(sessions_.begin(), sessions_.end(), jingle_session);
- CHECK(it != sessions_.end());
- cricket::Session* cricket_session = jingle_session->ReleaseSession();
- cricket_session_manager_->DestroySession(cricket_session);
- sessions_.erase(it);
-}
-
-void JingleSessionManager::OnJingleInfo(
- const std::string& token,
- const std::vector<std::string>& relay_hosts,
- const std::vector<talk_base::SocketAddress>& stun_hosts) {
- DCHECK(CalledOnValidThread());
-
- if (http_port_allocator_) {
- // TODO(ajwong): Avoid string processing if log-level is low.
- std::string stun_servers;
- for (size_t i = 0; i < stun_hosts.size(); ++i) {
- stun_servers += stun_hosts[i].ToString() + "; ";
- }
- VLOG(1) << "Configuring with relay token: " << token
- << ", relays: " << JoinString(relay_hosts, ';')
- << ", stun: " << stun_servers;
- http_port_allocator_->SetRelayToken(token);
- http_port_allocator_->SetStunHosts(stun_hosts);
- http_port_allocator_->SetRelayHosts(relay_hosts);
- } else {
- LOG(WARNING) << "Jingle info found but no port allocator.";
- }
-
- if (!ready_) {
- ready_ = true;
- listener_->OnSessionManagerReady();
- }
-}
-
-// Parse content description generated by WriteContent().
-bool JingleSessionManager::ParseContent(
- cricket::SignalingProtocol protocol,
- const XmlElement* element,
- const cricket::ContentDescription** content,
- cricket::ParseError* error) {
- *content = ContentDescription::ParseXml(element);
- return *content != NULL;
-}
-
-bool JingleSessionManager::WriteContent(
- cricket::SignalingProtocol protocol,
- const cricket::ContentDescription* content,
- XmlElement** elem,
- cricket::WriteError* error) {
- const ContentDescription* desc =
- static_cast<const ContentDescription*>(content);
-
- *elem = desc->ToXml();
- return true;
-}
-
-} // namespace protocol
-} // namespace remoting
diff --git a/remoting/protocol/jingle_session_manager.h b/remoting/protocol/jingle_session_manager.h
deleted file mode 100644
index f56ee74..0000000
--- a/remoting/protocol/jingle_session_manager.h
+++ /dev/null
@@ -1,125 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef REMOTING_PROTOCOL_JINGLE_SESSION_MANAGER_H_
-#define REMOTING_PROTOCOL_JINGLE_SESSION_MANAGER_H_
-
-#include <list>
-#include <string>
-
-#include "base/memory/ref_counted.h"
-#include "remoting/jingle_glue/signal_strategy.h"
-#include "remoting/protocol/content_description.h"
-#include "remoting/protocol/jingle_session.h"
-#include "remoting/protocol/session_manager.h"
-#include "third_party/libjingle/source/talk/p2p/base/session.h"
-#include "third_party/libjingle/source/talk/p2p/base/sessionclient.h"
-
-namespace cricket {
-class HttpPortAllocator;
-class PortAllocator;
-class SessionManager;
-} // namespace cricket
-
-namespace remoting {
-
-class JingleInfoRequest;
-class JingleSignalingConnector;
-
-namespace protocol {
-
-// This class implements SessionClient for Chromoting sessions. It acts as a
-// server that accepts chromoting connections and can also make new connections
-// to other hosts.
-class JingleSessionManager : public SessionManager,
- public cricket::SessionClient,
- public SignalStrategy::Listener {
- public:
- virtual ~JingleSessionManager();
-
- JingleSessionManager(base::MessageLoopProxy* message_loop);
-
- // SessionManager interface.
- virtual void Init(SignalStrategy* signal_strategy,
- SessionManager::Listener* listener,
- const NetworkSettings& network_settings) OVERRIDE;
- virtual scoped_ptr<Session> Connect(
- const std::string& host_jid,
- scoped_ptr<Authenticator> authenticator,
- scoped_ptr<CandidateSessionConfig> config,
- const Session::StateChangeCallback& state_change_callback) OVERRIDE;
- virtual void Close() OVERRIDE;
- virtual void set_authenticator_factory(
- scoped_ptr<AuthenticatorFactory> authenticator_factory) OVERRIDE;
-
- // cricket::SessionClient interface.
- virtual void OnSessionCreate(cricket::Session* cricket_session,
- bool received_initiate) OVERRIDE;
- virtual void OnSessionDestroy(cricket::Session* cricket_session) OVERRIDE;
-
- virtual bool ParseContent(cricket::SignalingProtocol protocol,
- const buzz::XmlElement* elem,
- const cricket::ContentDescription** content,
- cricket::ParseError* error) OVERRIDE;
- virtual bool WriteContent(cricket::SignalingProtocol protocol,
- const cricket::ContentDescription* content,
- buzz::XmlElement** elem,
- cricket::WriteError* error) OVERRIDE;
-
- // SignalStrategy::Listener interface.
- virtual void OnSignalStrategyStateChange(
- SignalStrategy::State state) OVERRIDE;
-
- private:
- friend class JingleSession;
-
- // Called by JingleSession when a new connection is initiated.
- SessionManager::IncomingSessionResponse AcceptConnection(
- JingleSession* jingle_session);
-
- // Creates authenticator for incoming session. Returns NULL if
- // authenticator cannot be created, e.g. if |auth_message| is
- // invalid.
- scoped_ptr<Authenticator> CreateAuthenticator(
- const std::string& jid,
- const buzz::XmlElement* auth_message);
-
- // Called by JingleSession when it is being destroyed.
- void SessionDestroyed(JingleSession* jingle_session);
-
- // Callback for JingleInfoRequest.
- void OnJingleInfo(
- const std::string& token,
- const std::vector<std::string>& relay_hosts,
- const std::vector<talk_base::SocketAddress>& stun_hosts);
-
- scoped_refptr<base::MessageLoopProxy> message_loop_;
-
- scoped_ptr<talk_base::NetworkManager> network_manager_;
- scoped_ptr<talk_base::PacketSocketFactory> socket_factory_;
-
- SignalStrategy* signal_strategy_;
- scoped_ptr<AuthenticatorFactory> authenticator_factory_;
- SessionManager::Listener* listener_;
- bool allow_nat_traversal_;
-
- bool ready_;
-
- scoped_ptr<cricket::PortAllocator> port_allocator_;
- cricket::HttpPortAllocator* http_port_allocator_;
- scoped_ptr<cricket::SessionManager> cricket_session_manager_;
- scoped_ptr<JingleInfoRequest> jingle_info_request_;
- scoped_ptr<JingleSignalingConnector> jingle_signaling_connector_;
-
- bool closed_;
-
- std::list<JingleSession*> sessions_;
-
- DISALLOW_COPY_AND_ASSIGN(JingleSessionManager);
-};
-
-} // namespace protocol
-} // namespace remoting
-
-#endif // REMOTING_PROTOCOL_JINGLE_SESSION_MANAGER_H_
diff --git a/remoting/protocol/jingle_session_unittest.cc b/remoting/protocol/jingle_session_unittest.cc
deleted file mode 100644
index 5bc4e847..0000000
--- a/remoting/protocol/jingle_session_unittest.cc
+++ /dev/null
@@ -1,395 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/bind.h"
-#include "base/bind_helpers.h"
-#include "base/message_loop_proxy.h"
-#include "base/time.h"
-#include "net/socket/socket.h"
-#include "net/socket/stream_socket.h"
-#include "remoting/base/constants.h"
-#include "remoting/protocol/authenticator.h"
-#include "remoting/protocol/channel_authenticator.h"
-#include "remoting/protocol/connection_tester.h"
-#include "remoting/protocol/fake_authenticator.h"
-#include "remoting/protocol/jingle_session.h"
-#include "remoting/protocol/jingle_session_manager.h"
-#include "remoting/jingle_glue/jingle_thread.h"
-#include "remoting/jingle_glue/fake_signal_strategy.h"
-#include "testing/gmock/include/gmock/gmock.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-using testing::_;
-using testing::AtMost;
-using testing::DeleteArg;
-using testing::DoAll;
-using testing::InSequence;
-using testing::Invoke;
-using testing::InvokeWithoutArgs;
-using testing::Mock;
-using testing::Return;
-using testing::SaveArg;
-using testing::SetArgumentPointee;
-using testing::WithArg;
-
-namespace remoting {
-namespace protocol {
-
-namespace {
-
-// Send 100 messages 1024 bytes each. UDP messages are sent with 10ms delay
-// between messages (about 1 second for 100 messages).
-const int kMessageSize = 1024;
-const int kMessages = 100;
-const int kUdpWriteDelayMs = 10;
-const char kChannelName[] = "test_channel";
-
-const char kHostJid[] = "host1@gmail.com/123";
-const char kClientJid[] = "host2@gmail.com/321";
-
-void QuitCurrentThread() {
- MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
-}
-
-ACTION(QuitThread) {
- QuitCurrentThread();
-}
-
-ACTION_P(QuitThreadOnCounter, counter) {
- (*counter)--;
- EXPECT_GE(*counter, 0);
- if (*counter == 0)
- QuitCurrentThread();
-}
-
-class MockSessionManagerListener : public SessionManager::Listener {
- public:
- MOCK_METHOD0(OnSessionManagerReady, void());
- MOCK_METHOD2(OnIncomingSession,
- void(Session*,
- SessionManager::IncomingSessionResponse*));
-};
-
-class MockSessionCallback {
- public:
- MOCK_METHOD1(OnStateChange, void(Session::State));
-};
-
-class MockStreamChannelCallback {
- public:
- MOCK_METHOD1(OnDone, void(net::StreamSocket* socket));
-};
-
-class MockDatagramChannelCallback {
- public:
- MOCK_METHOD1(OnDone, void(net::Socket* socket));
-};
-
-} // namespace
-
-class JingleSessionTest : public testing::Test {
- public:
- JingleSessionTest()
- : message_loop_(talk_base::Thread::Current()) {
- }
-
- // Helper method that handles OnIncomingSession().
- void SetHostSession(Session* session) {
- DCHECK(session);
- host_session_.reset(session);
- host_session_->SetStateChangeCallback(
- base::Bind(&MockSessionCallback::OnStateChange,
- base::Unretained(&host_connection_callback_)));
-
- session->set_config(SessionConfig::GetDefault());
- }
-
- void OnClientChannelCreated(scoped_ptr<net::StreamSocket> socket) {
- client_channel_callback_.OnDone(socket.get());
- client_socket_ = socket.Pass();
- }
-
- void OnHostChannelCreated(scoped_ptr<net::StreamSocket> socket) {
- host_channel_callback_.OnDone(socket.get());
- host_socket_ = socket.Pass();
- }
-
- protected:
- virtual void SetUp() {
- }
-
- virtual void TearDown() {
- CloseSessions();
- CloseSessionManager();
- }
-
- void CloseSessions() {
- host_socket_.reset();
- client_socket_.reset();
- host_session_.reset();
- client_session_.reset();
- }
-
- void CreateSessionManagers(int auth_round_trips,
- FakeAuthenticator::Action auth_action) {
- host_signal_strategy_.reset(new FakeSignalStrategy(kHostJid));
- client_signal_strategy_.reset(new FakeSignalStrategy(kClientJid));
- FakeSignalStrategy::Connect(host_signal_strategy_.get(),
- client_signal_strategy_.get());
-
- EXPECT_CALL(host_server_listener_, OnSessionManagerReady())
- .Times(1);
- host_server_.reset(new JingleSessionManager(
- base::MessageLoopProxy::current()));
- host_server_->Init(host_signal_strategy_.get(), &host_server_listener_,
- NetworkSettings());
-
- scoped_ptr<AuthenticatorFactory> factory(
- new FakeHostAuthenticatorFactory(auth_round_trips, auth_action, true));
- host_server_->set_authenticator_factory(factory.Pass());
-
- EXPECT_CALL(client_server_listener_, OnSessionManagerReady())
- .Times(1);
- client_server_.reset(new JingleSessionManager(
- base::MessageLoopProxy::current()));
- client_server_->Init(client_signal_strategy_.get(),
- &client_server_listener_, NetworkSettings());
- }
-
- void CloseSessionManager() {
- if (host_server_.get()) {
- host_server_->Close();
- host_server_.reset();
- }
- if (client_server_.get()) {
- client_server_->Close();
- client_server_.reset();
- }
- host_signal_strategy_.reset();
- client_signal_strategy_.reset();
- }
-
- void InitiateConnection(int auth_round_trips,
- FakeAuthenticator::Action auth_action,
- bool expect_fail) {
- EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _))
- .WillOnce(DoAll(
- WithArg<0>(Invoke(
- this, &JingleSessionTest::SetHostSession)),
- SetArgumentPointee<1>(protocol::SessionManager::ACCEPT)));
-
- {
- InSequence dummy;
-
- EXPECT_CALL(host_connection_callback_,
- OnStateChange(Session::CONNECTED))
- .Times(AtMost(1));
- if (expect_fail) {
- EXPECT_CALL(host_connection_callback_,
- OnStateChange(Session::FAILED))
- .Times(1);
- } else {
- EXPECT_CALL(host_connection_callback_,
- OnStateChange(Session::AUTHENTICATED))
- .Times(1);
- }
- }
-
- {
- InSequence dummy;
-
- EXPECT_CALL(client_connection_callback_,
- OnStateChange(Session::CONNECTING))
- .Times(1);
- EXPECT_CALL(client_connection_callback_,
- OnStateChange(Session::CONNECTED))
- .Times(AtMost(1));
- if (expect_fail) {
- EXPECT_CALL(client_connection_callback_,
- OnStateChange(Session::FAILED))
- .Times(1);
- } else {
- EXPECT_CALL(client_connection_callback_,
- OnStateChange(Session::AUTHENTICATED))
- .Times(1);
- }
- }
-
- scoped_ptr<Authenticator> authenticator(new FakeAuthenticator(
- FakeAuthenticator::CLIENT, auth_round_trips, auth_action, true));
-
- client_session_ = client_server_->Connect(
- kHostJid, authenticator.Pass(),
- CandidateSessionConfig::CreateDefault(),
- base::Bind(&MockSessionCallback::OnStateChange,
- base::Unretained(&client_connection_callback_)));
-
- message_loop_.RunAllPending();
-
- Mock::VerifyAndClearExpectations(&host_connection_callback_);
- Mock::VerifyAndClearExpectations(&client_connection_callback_);
-
- if (!expect_fail) {
- // Expect that the connection will be closed eventually.
- EXPECT_CALL(host_connection_callback_,
- OnStateChange(Session::CLOSED))
- .Times(AtMost(1));
- }
-
- if (!expect_fail) {
- // Expect that the connection will be closed eventually.
- EXPECT_CALL(client_connection_callback_,
- OnStateChange(Session::CLOSED))
- .Times(AtMost(1));
- }
- }
-
- void CreateChannel() {
- client_session_->CreateStreamChannel(kChannelName, base::Bind(
- &JingleSessionTest::OnClientChannelCreated, base::Unretained(this)));
- host_session_->CreateStreamChannel(kChannelName, base::Bind(
- &JingleSessionTest::OnHostChannelCreated, base::Unretained(this)));
-
- int counter = 2;
- EXPECT_CALL(client_channel_callback_, OnDone(_))
- .WillOnce(QuitThreadOnCounter(&counter));
- EXPECT_CALL(host_channel_callback_, OnDone(_))
- .WillOnce(QuitThreadOnCounter(&counter));
- message_loop_.Run();
- }
-
- JingleThreadMessageLoop message_loop_;
-
- scoped_ptr<FakeSignalStrategy> host_signal_strategy_;
- scoped_ptr<FakeSignalStrategy> client_signal_strategy_;
-
- scoped_ptr<JingleSessionManager> host_server_;
- MockSessionManagerListener host_server_listener_;
- scoped_ptr<JingleSessionManager> client_server_;
- MockSessionManagerListener client_server_listener_;
-
- scoped_ptr<Session> host_session_;
- MockSessionCallback host_connection_callback_;
- scoped_ptr<Session> client_session_;
- MockSessionCallback client_connection_callback_;
-
- MockStreamChannelCallback client_channel_callback_;
- MockStreamChannelCallback host_channel_callback_;
-
- scoped_ptr<net::StreamSocket> client_socket_;
- scoped_ptr<net::StreamSocket> host_socket_;
-};
-
-// Verify that we can create and destory server objects without a connection.
-TEST_F(JingleSessionTest, CreateAndDestoy) {
- CreateSessionManagers(1, FakeAuthenticator::ACCEPT);
-}
-
-// Verify that incoming session can be rejected, and that the status
-// of the connection is set to FAILED in this case.
-TEST_F(JingleSessionTest, RejectConnection) {
- CreateSessionManagers(1, FakeAuthenticator::ACCEPT);
-
- // Reject incoming session.
- EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _))
- .WillOnce(SetArgumentPointee<1>(protocol::SessionManager::DECLINE));
-
- {
- InSequence dummy;
-
- EXPECT_CALL(client_connection_callback_,
- OnStateChange(Session::CONNECTING))
- .Times(1);
- EXPECT_CALL(client_connection_callback_,
- OnStateChange(Session::FAILED))
- .Times(1);
- }
-
- scoped_ptr<Authenticator> authenticator(new FakeAuthenticator(
- FakeAuthenticator::CLIENT, 1, FakeAuthenticator::ACCEPT, true));
- client_session_ = client_server_->Connect(
- kHostJid, authenticator.Pass(), CandidateSessionConfig::CreateDefault(),
- base::Bind(&MockSessionCallback::OnStateChange,
- base::Unretained(&client_connection_callback_)));
-
- message_loop_.RunAllPending();
-}
-
-// Verify that we can connect two endpoints with single-step authentication.
-TEST_F(JingleSessionTest, Connect) {
- CreateSessionManagers(1, FakeAuthenticator::ACCEPT);
- InitiateConnection(1, FakeAuthenticator::ACCEPT, false);
-}
-
-// Verify that we can connect two endpoints with multi-step authentication.
-TEST_F(JingleSessionTest, ConnectWithMultistep) {
- CreateSessionManagers(3, FakeAuthenticator::ACCEPT);
- InitiateConnection(3, FakeAuthenticator::ACCEPT, false);
-}
-
-// Verify that connection is terminated when single-step auth fails.
-TEST_F(JingleSessionTest, ConnectWithBadAuth) {
- CreateSessionManagers(1, FakeAuthenticator::REJECT);
- InitiateConnection(1, FakeAuthenticator::ACCEPT, true);
-}
-
-// Verify that connection is terminated when multi-step auth fails.
-TEST_F(JingleSessionTest, ConnectWithBadMultistepAuth) {
- CreateSessionManagers(3, FakeAuthenticator::REJECT);
- InitiateConnection(3, FakeAuthenticator::ACCEPT, true);
-}
-
-TEST_F(JingleSessionTest, ConnectWithBadChannelAuth) {
- CreateSessionManagers(1, FakeAuthenticator::REJECT_CHANNEL);
- ASSERT_NO_FATAL_FAILURE(
- InitiateConnection(1, FakeAuthenticator::ACCEPT, false));
-
- client_session_->CreateStreamChannel(kChannelName, base::Bind(
- &JingleSessionTest::OnClientChannelCreated, base::Unretained(this)));
- host_session_->CreateStreamChannel(kChannelName, base::Bind(
- &JingleSessionTest::OnHostChannelCreated, base::Unretained(this)));
-
- EXPECT_CALL(client_channel_callback_, OnDone(_))
- .Times(AtMost(1));
- EXPECT_CALL(host_channel_callback_, OnDone(NULL))
- .WillOnce(QuitThread());
-
- message_loop_.Run();
-
- client_session_->CancelChannelCreation(kChannelName);
- host_session_->CancelChannelCreation(kChannelName);
-}
-
-// Verify that data can be transmitted over the event channel.
-TEST_F(JingleSessionTest, TestTcpChannel) {
- CreateSessionManagers(1, FakeAuthenticator::ACCEPT);
- ASSERT_NO_FATAL_FAILURE(
- InitiateConnection(1, FakeAuthenticator::ACCEPT, false));
-
- ASSERT_NO_FATAL_FAILURE(CreateChannel());
-
- StreamConnectionTester tester(host_socket_.get(), client_socket_.get(),
- kMessageSize, kMessages);
- tester.Start();
- message_loop_.Run();
- tester.CheckResults();
-}
-
-// Verify that we can connect channels with multistep auth.
-TEST_F(JingleSessionTest, TestMultistepAuthTcpChannel) {
- CreateSessionManagers(3, FakeAuthenticator::ACCEPT);
- ASSERT_NO_FATAL_FAILURE(
- InitiateConnection(3, FakeAuthenticator::ACCEPT, false));
-
- ASSERT_NO_FATAL_FAILURE(CreateChannel());
-
- StreamConnectionTester tester(host_socket_.get(), client_socket_.get(),
- kMessageSize, kMessages);
- tester.Start();
- message_loop_.Run();
- tester.CheckResults();
-}
-
-} // namespace protocol
-} // namespace remoting
diff --git a/remoting/protocol/jingle_stream_connector.cc b/remoting/protocol/jingle_stream_connector.cc
deleted file mode 100644
index 7f733ba..0000000
--- a/remoting/protocol/jingle_stream_connector.cc
+++ /dev/null
@@ -1,131 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "remoting/protocol/jingle_stream_connector.h"
-
-#include "base/bind.h"
-#include "jingle/glue/channel_socket_adapter.h"
-#include "jingle/glue/pseudotcp_adapter.h"
-#include "net/base/cert_status_flags.h"
-#include "net/base/cert_verifier.h"
-#include "net/base/host_port_pair.h"
-#include "net/base/ssl_config_service.h"
-#include "net/base/x509_certificate.h"
-#include "net/socket/ssl_client_socket.h"
-#include "net/socket/ssl_server_socket.h"
-#include "net/socket/client_socket_factory.h"
-#include "remoting/protocol/content_description.h"
-#include "remoting/protocol/jingle_session.h"
-
-namespace remoting {
-namespace protocol {
-
-namespace {
-
-// Value is choosen to balance the extra latency against the reduced
-// load due to ACK traffic.
-const int kTcpAckDelayMilliseconds = 10;
-
-// Values for the TCP send and receive buffer size. This should be tuned to
-// accomodate high latency network but not backlog the decoding pipeline.
-const int kTcpReceiveBufferSize = 256 * 1024;
-const int kTcpSendBufferSize = kTcpReceiveBufferSize + 30 * 1024;
-
-} // namespace
-
-JingleStreamConnector::JingleStreamConnector(
- JingleSession* session,
- const std::string& name,
- const Session::StreamChannelCallback& callback)
- : session_(session),
- name_(name),
- callback_(callback),
- raw_channel_(NULL) {
-}
-
-JingleStreamConnector::~JingleStreamConnector() {
-}
-
-void JingleStreamConnector::Connect(
- scoped_ptr<ChannelAuthenticator> authenticator,
- cricket::TransportChannel* raw_channel) {
- DCHECK(CalledOnValidThread());
- DCHECK(!raw_channel_);
-
- authenticator_ = authenticator.Pass();
- raw_channel_ = raw_channel;
-
- net::Socket* socket =
- new jingle_glue::TransportChannelSocketAdapter(raw_channel_);
-
- if (!EstablishTCPConnection(socket))
- NotifyError();
-}
-
-bool JingleStreamConnector::EstablishTCPConnection(net::Socket* socket) {
- // Set options for the raw socket layer.
- // Send buffer size is set to match the PseudoTcp layer so that it can fit
- // all the data submitted by the PseudoTcp layer.
- socket->SetSendBufferSize(kTcpSendBufferSize);
- // TODO(hclam): We should also set the receive buffer size once we can detect
- // the underlying socket is a TCP socket. We should also investigate what
- // value would gurantee that Windows's UDP socket doesn't return a EWOULDBLOCK
- // error.
-
- // Set options for the TCP layer.
- jingle_glue::PseudoTcpAdapter* adapter =
- new jingle_glue::PseudoTcpAdapter(socket);
- adapter->SetAckDelay(kTcpAckDelayMilliseconds);
- adapter->SetNoDelay(true);
- adapter->SetReceiveBufferSize(kTcpReceiveBufferSize);
- adapter->SetSendBufferSize(kTcpSendBufferSize);
-
- tcp_socket_.reset(adapter);
- int result = tcp_socket_->Connect(
- base::Bind(&JingleStreamConnector::OnTCPConnect,
- base::Unretained(this)));
- if (result == net::ERR_IO_PENDING) {
- return true;
- } else if (result == net::OK) {
- OnTCPConnect(result);
- return true;
- }
-
- return false;
-}
-
-void JingleStreamConnector::OnTCPConnect(int result) {
- DCHECK(CalledOnValidThread());
-
- if (result != net::OK) {
- LOG(ERROR) << "PseudoTCP connection failed: " << result;
- NotifyError();
- return;
- }
-
- authenticator_->SecureAndAuthenticate(tcp_socket_.Pass(), base::Bind(
- &JingleStreamConnector::OnAuthenticationDone, base::Unretained(this)));
-}
-
-void JingleStreamConnector::OnAuthenticationDone(
- net::Error error, scoped_ptr<net::StreamSocket> socket) {
- if (error != net::OK) {
- NotifyError();
- } else {
- NotifyDone(socket.Pass());
- }
-}
-
-void JingleStreamConnector::NotifyDone(scoped_ptr<net::StreamSocket> socket) {
- session_->OnChannelConnectorFinished(name_, this);
- callback_.Run(socket.Pass());
- delete this;
-}
-
-void JingleStreamConnector::NotifyError() {
- NotifyDone(scoped_ptr<net::StreamSocket>(NULL));
-}
-
-} // namespace protocol
-} // namespace remoting
diff --git a/remoting/protocol/jingle_stream_connector.h b/remoting/protocol/jingle_stream_connector.h
deleted file mode 100644
index 33fa770..0000000
--- a/remoting/protocol/jingle_stream_connector.h
+++ /dev/null
@@ -1,73 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef REMOTING_PROTOCOL_JINGLE_STREAM_CONNECTOR_H_
-#define REMOTING_PROTOCOL_JINGLE_STREAM_CONNECTOR_H_
-
-#include <string>
-
-#include "base/memory/scoped_ptr.h"
-#include "net/base/completion_callback.h"
-#include "remoting/protocol/channel_authenticator.h"
-#include "remoting/protocol/jingle_channel_connector.h"
-#include "remoting/protocol/session.h"
-
-namespace cricket {
-class TransportChannel;
-} // namespace cricket
-
-namespace net {
-class CertVerifier;
-class StreamSocket;
-class SSLSocket;
-} // namespace net
-
-namespace remoting {
-namespace protocol {
-
-class JingleSession;
-
-// JingleStreamConnector creates the named datagram channel in the supplied
-// JingleSession, and uses PseudoTcp to turn it into a stream channel. Within
-// the stream channel SSL is used to secure the protocol stream. Finally, the
-// initiator authenticates the channel to the recipient by sending a digest
-// based on a secret shared by the two parties, and keying material derived
-// from the SSL session's master secret and nonces.
-class JingleStreamConnector : public JingleChannelConnector {
- public:
- JingleStreamConnector(JingleSession* session,
- const std::string& name,
- const Session::StreamChannelCallback& callback);
- virtual ~JingleStreamConnector();
-
- // JingleChannelConnector implementation.
- virtual void Connect(scoped_ptr<ChannelAuthenticator> authenticator,
- cricket::TransportChannel* raw_channel) OVERRIDE;
-
- private:
- bool EstablishTCPConnection(net::Socket* socket);
- void OnTCPConnect(int result);
- void OnAuthenticationDone(net::Error error,
- scoped_ptr<net::StreamSocket> socket);
-
- void NotifyDone(scoped_ptr<net::StreamSocket> socket);
- void NotifyError();
-
- JingleSession* session_;
- std::string name_;
- Session::StreamChannelCallback callback_;
-
- cricket::TransportChannel* raw_channel_;
- scoped_ptr<net::StreamSocket> tcp_socket_;
- scoped_ptr<net::SSLSocket> socket_;
-
- scoped_ptr<ChannelAuthenticator> authenticator_;
-
- DISALLOW_COPY_AND_ASSIGN(JingleStreamConnector);
-};
-
-} // namespace protocol
-} // namespace remoting
-
-#endif // REMOTING_PROTOCOL_JINGLE_STREAM_CONNECTOR_H_
diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp
index bd39bfb..0ac2b50 100644
--- a/remoting/remoting.gyp
+++ b/remoting/remoting.gyp
@@ -725,8 +725,6 @@
'jingle_glue/javascript_signal_strategy.h',
'jingle_glue/jingle_info_request.cc',
'jingle_glue/jingle_info_request.h',
- 'jingle_glue/jingle_signaling_connector.cc',
- 'jingle_glue/jingle_signaling_connector.h',
'jingle_glue/jingle_thread.cc',
'jingle_glue/jingle_thread.h',
'jingle_glue/signal_strategy.h',
@@ -789,17 +787,8 @@
'protocol/input_stub.h',
'protocol/it2me_host_authenticator_factory.cc',
'protocol/it2me_host_authenticator_factory.h',
- 'protocol/jingle_channel_connector.h',
- 'protocol/jingle_datagram_connector.cc',
- 'protocol/jingle_datagram_connector.h',
'protocol/jingle_messages.cc',
'protocol/jingle_messages.h',
- 'protocol/jingle_session.cc',
- 'protocol/jingle_session.h',
- 'protocol/jingle_session_manager.cc',
- 'protocol/jingle_session_manager.h',
- 'protocol/jingle_stream_connector.cc',
- 'protocol/jingle_stream_connector.h',
'protocol/key_event_tracker.cc',
'protocol/key_event_tracker.h',
'protocol/libjingle_transport_factory.cc',
@@ -952,7 +941,6 @@
'protocol/fake_session.cc',
'protocol/fake_session.h',
'protocol/jingle_messages_unittest.cc',
- 'protocol/jingle_session_unittest.cc',
'protocol/key_event_tracker_unittest.cc',
'protocol/message_decoder_unittest.cc',
'protocol/message_reader_unittest.cc',