diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-16 18:23:01 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-16 18:23:01 +0000 |
commit | 3e0d61e2bb88eb80058b63ac6a8b9ebff64cc4eb (patch) | |
tree | c3da626825f9fe83079a9a1f248c6cf47db1ff21 | |
parent | e824b9a645d86c8a75020f21cd9bb641c19d995f (diff) | |
download | chromium_src-3e0d61e2bb88eb80058b63ac6a8b9ebff64cc4eb.zip chromium_src-3e0d61e2bb88eb80058b63ac6a8b9ebff64cc4eb.tar.gz chromium_src-3e0d61e2bb88eb80058b63ac6a8b9ebff64cc4eb.tar.bz2 |
Revert 240926 "Fix LibjingleTransportFactory to refresh STUN/Relay."
> Fix LibjingleTransportFactory to refresh STUN/Relay.
>
> Previously chromoting host would get relay info only when started. Relay
> token expires within several hours, which means relay session creation would
> always fail from the host running for longer than several hours, and that
> makes connection impossible in some configurations. Moved code that
> gets Jingle info to LibjingleTransportFactory and it's responsible for
> refreshing relay token every hour.
>
> BUG=318897
> R=rmsousa@chromium.org
>
> Review URL: https://codereview.chromium.org/98173006
TBR=sergeyu@chromium.org
Review URL: https://codereview.chromium.org/116123003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@240936 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | remoting/client/jni/chromoting_jni_instance.cc | 3 | ||||
-rw-r--r-- | remoting/client/plugin/chromoting_instance.cc | 4 | ||||
-rw-r--r-- | remoting/host/it2me/it2me_host.cc | 2 | ||||
-rw-r--r-- | remoting/host/remoting_me2me_host.cc | 2 | ||||
-rw-r--r-- | remoting/host/session_manager_factory.cc | 15 | ||||
-rw-r--r-- | remoting/host/session_manager_factory.h | 4 | ||||
-rw-r--r-- | remoting/jingle_glue/jingle_info_request.cc | 30 | ||||
-rw-r--r-- | remoting/jingle_glue/jingle_info_request.h | 18 | ||||
-rw-r--r-- | remoting/protocol/connection_to_host.cc | 3 | ||||
-rw-r--r-- | remoting/protocol/jingle_session_manager.cc | 51 | ||||
-rw-r--r-- | remoting/protocol/jingle_session_manager.h | 13 | ||||
-rw-r--r-- | remoting/protocol/jingle_session_unittest.cc | 12 | ||||
-rw-r--r-- | remoting/protocol/libjingle_transport_factory.cc | 143 | ||||
-rw-r--r-- | remoting/protocol/libjingle_transport_factory.h | 35 | ||||
-rw-r--r-- | remoting/protocol/session_manager.h | 1 | ||||
-rw-r--r-- | remoting/protocol/transport.h | 8 | ||||
-rw-r--r-- | remoting/protocol/transport_config.cc | 17 | ||||
-rw-r--r-- | remoting/protocol/transport_config.h | 25 | ||||
-rw-r--r-- | remoting/remoting.gyp | 2 |
19 files changed, 179 insertions, 209 deletions
diff --git a/remoting/client/jni/chromoting_jni_instance.cc b/remoting/client/jni/chromoting_jni_instance.cc index 25398a8..339cea8 100644 --- a/remoting/client/jni/chromoting_jni_instance.cc +++ b/remoting/client/jni/chromoting_jni_instance.cc @@ -309,8 +309,7 @@ void ChromotingJniInstance::ConnectToHostOnNetworkThread() { scoped_ptr<protocol::TransportFactory> transport_factory( new protocol::LibjingleTransportFactory( - port_allocator.PassAs<cricket::HttpPortAllocatorBase>(), - network_settings)); + port_allocator.PassAs<cricket::HttpPortAllocatorBase>(), false)); client_->Start(signaling_.get(), transport_factory.Pass()); } diff --git a/remoting/client/plugin/chromoting_instance.cc b/remoting/client/plugin/chromoting_instance.cc index 46e30f5..ba69267 100644 --- a/remoting/client/plugin/chromoting_instance.cc +++ b/remoting/client/plugin/chromoting_instance.cc @@ -658,9 +658,7 @@ void ChromotingInstance::ConnectWithConfig(const ClientConfig& config, scoped_ptr<cricket::HttpPortAllocatorBase> port_allocator( PepperPortAllocator::Create(this)); scoped_ptr<protocol::TransportFactory> transport_factory( - new protocol::LibjingleTransportFactory( - signal_strategy_.get(), port_allocator.Pass(), - NetworkSettings(NetworkSettings::NAT_TRAVERSAL_ENABLED))); + new protocol::LibjingleTransportFactory(port_allocator.Pass(), false)); // Kick off the connection. client_->Start(signal_strategy_.get(), transport_factory.Pass()); diff --git a/remoting/host/it2me/it2me_host.cc b/remoting/host/it2me/it2me_host.cc index fec201f..9aa88fe 100644 --- a/remoting/host/it2me/it2me_host.cc +++ b/remoting/host/it2me/it2me_host.cc @@ -195,7 +195,7 @@ void It2MeHost::FinishConnect() { host_.reset(new ChromotingHost( signal_strategy_.get(), desktop_environment_factory_.get(), - CreateHostSessionManager(signal_strategy_.get(), network_settings, + CreateHostSessionManager(network_settings, host_context_->url_request_context_getter()), host_context_->audio_task_runner(), host_context_->input_task_runner(), diff --git a/remoting/host/remoting_me2me_host.cc b/remoting/host/remoting_me2me_host.cc index 7a0faba..bc7e8a7 100644 --- a/remoting/host/remoting_me2me_host.cc +++ b/remoting/host/remoting_me2me_host.cc @@ -998,7 +998,7 @@ void HostProcess::StartHost() { host_.reset(new ChromotingHost( signal_strategy_.get(), desktop_environment_factory_.get(), - CreateHostSessionManager(signal_strategy_.get(), network_settings, + CreateHostSessionManager(network_settings, context_->url_request_context_getter()), context_->audio_task_runner(), context_->input_task_runner(), diff --git a/remoting/host/session_manager_factory.cc b/remoting/host/session_manager_factory.cc index a055df2..cd5befc 100644 --- a/remoting/host/session_manager_factory.cc +++ b/remoting/host/session_manager_factory.cc @@ -14,7 +14,6 @@ namespace remoting { scoped_ptr<protocol::SessionManager> CreateHostSessionManager( - SignalStrategy* signal_strategy, const NetworkSettings& network_settings, const scoped_refptr<net::URLRequestContextGetter>& url_request_context_getter) { @@ -23,14 +22,22 @@ scoped_ptr<protocol::SessionManager> CreateHostSessionManager( ChromiumPortAllocator::Create(url_request_context_getter, network_settings)); + bool incoming_only = network_settings.nat_traversal_mode == + NetworkSettings::NAT_TRAVERSAL_DISABLED; + scoped_ptr<protocol::TransportFactory> transport_factory( new protocol::LibjingleTransportFactory( - signal_strategy, port_allocator.PassAs<cricket::HttpPortAllocatorBase>(), - network_settings)); + incoming_only)); + + // Use the Jingle protocol for channel-negotiation signalling between + // peer TransportFactories. + bool fetch_stun_relay_info = network_settings.nat_traversal_mode == + NetworkSettings::NAT_TRAVERSAL_ENABLED; scoped_ptr<protocol::JingleSessionManager> session_manager( - new protocol::JingleSessionManager(transport_factory.Pass())); + new protocol::JingleSessionManager( + transport_factory.Pass(), fetch_stun_relay_info)); return session_manager.PassAs<protocol::SessionManager>(); } diff --git a/remoting/host/session_manager_factory.h b/remoting/host/session_manager_factory.h index ce2a53d..2c0a1b6 100644 --- a/remoting/host/session_manager_factory.h +++ b/remoting/host/session_manager_factory.h @@ -15,14 +15,12 @@ class URLRequestContextGetter; namespace remoting { struct NetworkSettings; -class SignalStrategy; namespace protocol { -class SessionManager; + class SessionManager; } // namespace protocol scoped_ptr<protocol::SessionManager> CreateHostSessionManager( - SignalStrategy* signal_strategy, const NetworkSettings& network_settings, const scoped_refptr<net::URLRequestContextGetter>& url_request_context_getter); diff --git a/remoting/jingle_glue/jingle_info_request.cc b/remoting/jingle_glue/jingle_info_request.cc index d41f18a..e75b89f 100644 --- a/remoting/jingle_glue/jingle_info_request.cc +++ b/remoting/jingle_glue/jingle_info_request.cc @@ -8,7 +8,6 @@ #include "base/message_loop/message_loop.h" #include "base/stl_util.h" #include "base/strings/string_number_conversions.h" -#include "base/time/time.h" #include "net/base/net_util.h" #include "remoting/jingle_glue/iq_sender.h" #include "third_party/libjingle/source/talk/base/socketaddress.h" @@ -17,13 +16,12 @@ namespace remoting { -const int kRequestTimeoutSeconds = 5; - JingleInfoRequest::JingleInfoRequest(SignalStrategy* signal_strategy) : iq_sender_(signal_strategy) { } -JingleInfoRequest::~JingleInfoRequest() {} +JingleInfoRequest::~JingleInfoRequest() { +} void JingleInfoRequest::Send(const OnJingleInfoCallback& callback) { on_jingle_info_cb_ = callback; @@ -32,39 +30,19 @@ void JingleInfoRequest::Send(const OnJingleInfoCallback& callback) { request_ = iq_sender_.SendIq( buzz::STR_GET, buzz::STR_EMPTY, iq_body.Pass(), base::Bind(&JingleInfoRequest::OnResponse, base::Unretained(this))); - if (!request_) { - // If we failed to send IqRequest it means that SignalStrategy is - // disconnected. Notify the caller. - std::vector<talk_base::SocketAddress> stun_hosts; - std::vector<std::string> relay_hosts; - std::string relay_token; - on_jingle_info_cb_.Run(relay_token, relay_hosts, stun_hosts); - return; - } - request_->SetTimeout(base::TimeDelta::FromSeconds(kRequestTimeoutSeconds)); } void JingleInfoRequest::OnResponse(IqRequest* request, const buzz::XmlElement* stanza) { - std::vector<talk_base::SocketAddress> stun_hosts; - std::vector<std::string> relay_hosts; - std::string relay_token; - - if (!stanza) { - LOG(WARNING) << "Jingle info request has timed out."; - on_jingle_info_cb_.Run(relay_token, relay_hosts, stun_hosts); - return; - } - const buzz::XmlElement* query = stanza->FirstNamed(buzz::QN_JINGLE_INFO_QUERY); if (query == NULL) { LOG(WARNING) << "No Jingle info found in Jingle Info query response." << stanza->Str(); - on_jingle_info_cb_.Run(relay_token, relay_hosts, stun_hosts); return; } + std::vector<talk_base::SocketAddress> stun_hosts; const buzz::XmlElement* stun = query->FirstNamed(buzz::QN_JINGLE_INFO_STUN); if (stun) { for (const buzz::XmlElement* server = @@ -85,6 +63,8 @@ void JingleInfoRequest::OnResponse(IqRequest* request, } } + std::vector<std::string> relay_hosts; + std::string relay_token; const buzz::XmlElement* relay = query->FirstNamed(buzz::QN_JINGLE_INFO_RELAY); if (relay) { relay_token = relay->TextNamed(buzz::QN_JINGLE_INFO_TOKEN); diff --git a/remoting/jingle_glue/jingle_info_request.h b/remoting/jingle_glue/jingle_info_request.h index 118aa4a..a1b10de 100644 --- a/remoting/jingle_glue/jingle_info_request.h +++ b/remoting/jingle_glue/jingle_info_request.h @@ -13,6 +13,7 @@ #include "base/callback.h" #include "base/memory/scoped_ptr.h" #include "remoting/jingle_glue/iq_sender.h" +#include "third_party/libjingle/source/talk/base/sigslot.h" namespace buzz { class XmlElement; @@ -33,14 +34,17 @@ class SignalStrategy; // // This class is not threadsafe and should be used on the same thread it is // created on. -class JingleInfoRequest { +// +// TODO(ajwong): Add support for a timeout. +class JingleInfoRequest : public sigslot::has_slots<> { public: - // Callback to receive the Jingle configuration settings. All fields are empty - // if the request has timed out. - typedef base::Callback<void(const std::string& relay_token, - const std::vector<std::string>& relay_servers, - const std::vector<talk_base::SocketAddress>& - stun_servers)> OnJingleInfoCallback; + // Callback to receive the Jingle configuration settings. The arguments are + // passed by pointer so the receive may call swap on them. The receiver does + // NOT own the arguments, which are guaranteed only to be alive for the + // duration of the callback. + typedef base::Callback<void ( + const std::string&, const std::vector<std::string>&, + const std::vector<talk_base::SocketAddress>&)> OnJingleInfoCallback; explicit JingleInfoRequest(SignalStrategy* signal_strategy); virtual ~JingleInfoRequest(); diff --git a/remoting/protocol/connection_to_host.cc b/remoting/protocol/connection_to_host.cc index e35ba22..bcd77e5 100644 --- a/remoting/protocol/connection_to_host.cc +++ b/remoting/protocol/connection_to_host.cc @@ -92,7 +92,8 @@ void ConnectionToHost::Connect(SignalStrategy* signal_strategy, signal_strategy_->AddListener(this); signal_strategy_->Connect(); - session_manager_.reset(new JingleSessionManager(transport_factory.Pass())); + session_manager_.reset(new JingleSessionManager( + transport_factory.Pass(), allow_nat_traversal_)); session_manager_->Init(signal_strategy_, this); SetState(CONNECTING, OK); diff --git a/remoting/protocol/jingle_session_manager.cc b/remoting/protocol/jingle_session_manager.cc index 58bcd4d..7cb1586 100644 --- a/remoting/protocol/jingle_session_manager.cc +++ b/remoting/protocol/jingle_session_manager.cc @@ -6,12 +6,14 @@ #include "base/bind.h" #include "remoting/jingle_glue/iq_sender.h" +#include "remoting/jingle_glue/jingle_info_request.h" #include "remoting/jingle_glue/signal_strategy.h" #include "remoting/protocol/authenticator.h" #include "remoting/protocol/content_description.h" #include "remoting/protocol/jingle_messages.h" #include "remoting/protocol/jingle_session.h" #include "remoting/protocol/transport.h" +#include "remoting/protocol/transport_config.h" #include "third_party/libjingle/source/talk/base/socketaddress.h" #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" @@ -21,8 +23,10 @@ namespace remoting { namespace protocol { JingleSessionManager::JingleSessionManager( - scoped_ptr<TransportFactory> transport_factory) + scoped_ptr<TransportFactory> transport_factory, + bool fetch_stun_relay_config) : transport_factory_(transport_factory.Pass()), + fetch_stun_relay_config_(fetch_stun_relay_config), signal_strategy_(NULL), listener_(NULL), ready_(false) { @@ -44,13 +48,35 @@ void JingleSessionManager::Init( OnSignalStrategyStateChange(signal_strategy_->GetState()); } +void JingleSessionManager::OnJingleInfo( + const std::string& relay_token, + const std::vector<std::string>& relay_hosts, + const std::vector<talk_base::SocketAddress>& stun_hosts) { + DCHECK(CalledOnValidThread()); + + // TODO(sergeyu): Add support for multiple STUN/relay servers when + // it's implemented in libjingle and P2P Transport API. + TransportConfig config; + config.stun_server = stun_hosts[0].ToString(); + config.relay_server = relay_hosts[0]; + config.relay_token = relay_token; + transport_factory_->SetTransportConfig(config); + + VLOG(1) << "STUN server: " << config.stun_server + << " Relay server: " << config.relay_server + << " Relay token: " << config.relay_token; + + + if (!ready_) { + ready_ = true; + listener_->OnSessionManagerReady(); + } +} + scoped_ptr<Session> JingleSessionManager::Connect( const std::string& host_jid, scoped_ptr<Authenticator> authenticator, scoped_ptr<CandidateSessionConfig> config) { - // Notify |transport_factory_| that it may be used soon. - transport_factory_->PrepareTokens(); - scoped_ptr<JingleSession> session(new JingleSession(this)); session->StartConnection(host_jid, authenticator.Pass(), config.Pass()); sessions_[session->session_id_] = session.get(); @@ -64,6 +90,7 @@ void JingleSessionManager::Close() { DCHECK(sessions_.empty()); listener_ = NULL; + jingle_info_request_.reset(); if (signal_strategy_) { signal_strategy_->RemoveListener(this); @@ -79,9 +106,16 @@ void JingleSessionManager::set_authenticator_factory( void JingleSessionManager::OnSignalStrategyStateChange( SignalStrategy::State state) { - if (state == SignalStrategy::CONNECTED && !ready_) { - ready_ = true; - listener_->OnSessionManagerReady(); + if (state == SignalStrategy::CONNECTED) { + // Request STUN/Relay info if necessary. + if (fetch_stun_relay_config_) { + 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(); + } } } @@ -103,9 +137,6 @@ bool JingleSessionManager::OnSignalStrategyIncomingStanza( SendReply(stanza, JingleMessageReply::NONE); - // Notify |transport_factory_| that it may be used soon. - transport_factory_->PrepareTokens(); - scoped_ptr<Authenticator> authenticator = authenticator_factory_->CreateAuthenticator( signal_strategy_->GetLocalJid(), message.from, diff --git a/remoting/protocol/jingle_session_manager.h b/remoting/protocol/jingle_session_manager.h index e808ad2..7130f3f 100644 --- a/remoting/protocol/jingle_session_manager.h +++ b/remoting/protocol/jingle_session_manager.h @@ -30,6 +30,7 @@ class SocketAddress; namespace remoting { class IqSender; +class JingleInfoRequest; namespace protocol { @@ -43,7 +44,15 @@ class TransportFactory; class JingleSessionManager : public SessionManager, public SignalStrategy::Listener { public: - explicit JingleSessionManager(scoped_ptr<TransportFactory> transport_factory); + // When |fetch_stun_relay_config| is set to true then + // JingleSessionManager will also try to query configuration of STUN + // and Relay servers from the signaling server. + // + // TODO(sergeyu): Move NAT-traversal config fetching to a separate + // class. + explicit JingleSessionManager( + scoped_ptr<TransportFactory> transport_factory, + bool fetch_stun_relay_config); virtual ~JingleSessionManager(); // SessionManager interface. @@ -90,6 +99,8 @@ class JingleSessionManager : public SessionManager, bool ready_; + scoped_ptr<JingleInfoRequest> jingle_info_request_; + SessionsMap sessions_; DISALLOW_COPY_AND_ASSIGN(JingleSessionManager); diff --git a/remoting/protocol/jingle_session_unittest.cc b/remoting/protocol/jingle_session_unittest.cc index 62e4d40..34e09d6 100644 --- a/remoting/protocol/jingle_session_unittest.cc +++ b/remoting/protocol/jingle_session_unittest.cc @@ -141,14 +141,13 @@ class JingleSessionTest : public testing::Test { EXPECT_CALL(host_server_listener_, OnSessionManagerReady()) .Times(1); - NetworkSettings network_settings(NetworkSettings::NAT_TRAVERSAL_OUTGOING); + NetworkSettings network_settings; scoped_ptr<TransportFactory> host_transport(new LibjingleTransportFactory( - NULL, ChromiumPortAllocator::Create(NULL, network_settings) .PassAs<cricket::HttpPortAllocatorBase>(), - network_settings)); - host_server_.reset(new JingleSessionManager(host_transport.Pass())); + false)); + host_server_.reset(new JingleSessionManager(host_transport.Pass(), false)); host_server_->Init(host_signal_strategy_.get(), &host_server_listener_); scoped_ptr<AuthenticatorFactory> factory( @@ -158,12 +157,11 @@ class JingleSessionTest : public testing::Test { EXPECT_CALL(client_server_listener_, OnSessionManagerReady()) .Times(1); scoped_ptr<TransportFactory> client_transport(new LibjingleTransportFactory( - NULL, ChromiumPortAllocator::Create(NULL, network_settings) .PassAs<cricket::HttpPortAllocatorBase>(), - network_settings)); + false)); client_server_.reset( - new JingleSessionManager(client_transport.Pass())); + new JingleSessionManager(client_transport.Pass(), false)); client_server_->Init(client_signal_strategy_.get(), &client_server_listener_); } diff --git a/remoting/protocol/libjingle_transport_factory.cc b/remoting/protocol/libjingle_transport_factory.cc index ef22f2a..76c3507 100644 --- a/remoting/protocol/libjingle_transport_factory.cc +++ b/remoting/protocol/libjingle_transport_factory.cc @@ -4,7 +4,6 @@ #include "remoting/protocol/libjingle_transport_factory.h" -#include "base/callback.h" #include "base/single_thread_task_runner.h" #include "base/thread_task_runner_handle.h" #include "base/timer/timer.h" @@ -14,9 +13,9 @@ #include "jingle/glue/utils.h" #include "net/base/net_errors.h" #include "remoting/base/constants.h" -#include "remoting/jingle_glue/jingle_info_request.h" #include "remoting/jingle_glue/network_settings.h" #include "remoting/protocol/channel_authenticator.h" +#include "remoting/protocol/transport_config.h" #include "third_party/libjingle/source/talk/base/network.h" #include "third_party/libjingle/source/talk/p2p/base/constants.h" #include "third_party/libjingle/source/talk/p2p/base/p2ptransportchannel.h" @@ -41,21 +40,13 @@ const int kTcpSendBufferSize = kTcpReceiveBufferSize + 30 * 1024; const int kMaxReconnectAttempts = 2; const int kReconnectDelaySeconds = 15; -// Get fresh STUN/Relay configuration every hour. -const int kJingleInfoUpdatePeriodSeconds = 3600; - -class LibjingleStreamTransport - : public StreamTransport, - public base::SupportsWeakPtr<LibjingleStreamTransport>, - public sigslot::has_slots<> { +class LibjingleStreamTransport : public StreamTransport, + public sigslot::has_slots<> { public: LibjingleStreamTransport(cricket::PortAllocator* port_allocator, - const NetworkSettings& network_settings); + bool incoming_only); virtual ~LibjingleStreamTransport(); - // Called by JingleTransportFactory when it has fresh Jingle info. - void OnCanStart(); - // StreamTransport interface. virtual void Initialize( const std::string& name, @@ -68,8 +59,6 @@ class LibjingleStreamTransport virtual bool is_connected() const OVERRIDE; private: - void DoStart(); - // Signal handlers for cricket::TransportChannel. void OnRequestSignaling(cricket::TransportChannelImpl* channel); void OnCandidateReady(cricket::TransportChannelImpl* channel, @@ -97,7 +86,7 @@ class LibjingleStreamTransport void NotifyConnectFailed(); cricket::PortAllocator* port_allocator_; - NetworkSettings network_settings_; + bool incoming_only_; std::string name_; EventHandler* event_handler_; @@ -106,9 +95,6 @@ class LibjingleStreamTransport std::string ice_username_fragment_; std::string ice_password_; - bool can_start_; - - std::list<cricket::Candidate> pending_candidates_; scoped_ptr<cricket::P2PTransportChannel> channel_; bool channel_was_writable_; int connect_attempts_left_; @@ -122,14 +108,13 @@ class LibjingleStreamTransport LibjingleStreamTransport::LibjingleStreamTransport( cricket::PortAllocator* port_allocator, - const NetworkSettings& network_settings) + bool incoming_only) : port_allocator_(port_allocator), - network_settings_(network_settings), + incoming_only_(incoming_only), event_handler_(NULL), ice_username_fragment_( talk_base::CreateRandomString(cricket::ICE_UFRAG_LENGTH)), ice_password_(talk_base::CreateRandomString(cricket::ICE_PWD_LENGTH)), - can_start_(false), channel_was_writable_(false), connect_attempts_left_(kMaxReconnectAttempts) { } @@ -146,22 +131,6 @@ LibjingleStreamTransport::~LibjingleStreamTransport() { } } -void LibjingleStreamTransport::OnCanStart() { - DCHECK(CalledOnValidThread()); - - DCHECK(!can_start_); - can_start_ = true; - - // If Connect() has been called then start connection. - if (!callback_.is_null()) - DoStart(); - - while (!pending_candidates_.empty()) { - channel_->OnCandidate(pending_candidates_.front()); - pending_candidates_.pop_front(); - } -} - void LibjingleStreamTransport::Initialize( const std::string& name, Transport::EventHandler* event_handler, @@ -182,13 +151,9 @@ void LibjingleStreamTransport::Initialize( void LibjingleStreamTransport::Connect( const StreamTransport::ConnectedCallback& callback) { DCHECK(CalledOnValidThread()); - callback_ = callback; - if (can_start_) - DoStart(); -} + callback_ = callback; -void LibjingleStreamTransport::DoStart() { DCHECK(!channel_.get()); // Create P2PTransportChannel, attach signal handlers and connect it. @@ -204,10 +169,7 @@ void LibjingleStreamTransport::DoStart() { this, &LibjingleStreamTransport::OnRouteChange); channel_->SignalWritableState.connect( this, &LibjingleStreamTransport::OnWritableState); - if (network_settings_.nat_traversal_mode == - NetworkSettings::NAT_TRAVERSAL_DISABLED) { - channel_->set_incoming_only(true); - } + channel_->set_incoming_only(incoming_only_); channel_->Connect(); @@ -249,11 +211,7 @@ void LibjingleStreamTransport::DoStart() { void LibjingleStreamTransport::AddRemoteCandidate( const cricket::Candidate& candidate) { DCHECK(CalledOnValidThread()); - if (channel_) { - channel_->OnCandidate(candidate); - } else { - pending_candidates_.push_back(candidate); - } + channel_->OnCandidate(candidate); } const std::string& LibjingleStreamTransport::name() const { @@ -404,12 +362,10 @@ void LibjingleStreamTransport::NotifyConnectFailed() { } // namespace LibjingleTransportFactory::LibjingleTransportFactory( - SignalStrategy* signal_strategy, scoped_ptr<cricket::HttpPortAllocatorBase> port_allocator, - const NetworkSettings& network_settings) - : signal_strategy_(signal_strategy), - port_allocator_(port_allocator.Pass()), - network_settings_(network_settings) { + bool incoming_only) + : port_allocator_(port_allocator.Pass()), + incoming_only_(incoming_only) { jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); } @@ -421,27 +377,27 @@ LibjingleTransportFactory::~LibjingleTransportFactory() { task_runner->DeleteSoon(FROM_HERE, port_allocator_.release()); } -void LibjingleTransportFactory::PrepareTokens() { - EnsureFreshJingleInfo(); -} - -scoped_ptr<StreamTransport> LibjingleTransportFactory::CreateStreamTransport() { - scoped_ptr<LibjingleStreamTransport> result( - new LibjingleStreamTransport(port_allocator_.get(), network_settings_)); - - EnsureFreshJingleInfo(); - - // If there is a pending |jingle_info_request_| delay starting the new - // transport until the request is finished. - if (jingle_info_request_) { - on_jingle_info_callbacks_.push_back( - base::Bind(&LibjingleStreamTransport::OnCanStart, - result->AsWeakPtr())); +void LibjingleTransportFactory::SetTransportConfig( + const TransportConfig& config) { + std::vector<talk_base::SocketAddress> stun_hosts; + talk_base::SocketAddress stun_address; + if (stun_address.FromString(config.stun_server)) { + stun_hosts.push_back(stun_address); + port_allocator_->SetStunHosts(stun_hosts); } else { - result->OnCanStart(); + LOG(ERROR) << "Failed to parse stun server address: " + << config.stun_server; } - return result.PassAs<StreamTransport>(); + std::vector<std::string> relay_hosts; + relay_hosts.push_back(config.relay_server); + port_allocator_->SetRelayHosts(relay_hosts); + port_allocator_->SetRelayToken(config.relay_token); +} + +scoped_ptr<StreamTransport> LibjingleTransportFactory::CreateStreamTransport() { + return scoped_ptr<StreamTransport>( + new LibjingleStreamTransport(port_allocator_.get(), incoming_only_)); } scoped_ptr<DatagramTransport> @@ -450,42 +406,5 @@ LibjingleTransportFactory::CreateDatagramTransport() { return scoped_ptr<DatagramTransport>(); } -void LibjingleTransportFactory::EnsureFreshJingleInfo() { - if (network_settings_.nat_traversal_mode != - NetworkSettings::NAT_TRAVERSAL_ENABLED || - jingle_info_request_) { - return; - } - - if (base::TimeTicks::Now() - last_jingle_info_update_time_ > - base::TimeDelta::FromSeconds(kJingleInfoUpdatePeriodSeconds)) { - jingle_info_request_.reset(new JingleInfoRequest(signal_strategy_)); - jingle_info_request_->Send(base::Bind( - &LibjingleTransportFactory::OnJingleInfo, base::Unretained(this))); - } -} - -void LibjingleTransportFactory::OnJingleInfo( - const std::string& relay_token, - const std::vector<std::string>& relay_hosts, - const std::vector<talk_base::SocketAddress>& stun_hosts) { - if (!relay_token.empty() && !relay_hosts.empty()) { - port_allocator_->SetRelayHosts(relay_hosts); - port_allocator_->SetRelayToken(relay_token); - } - if (!stun_hosts.empty()) { - port_allocator_->SetStunHosts(stun_hosts); - } - - jingle_info_request_.reset(); - if ((!relay_token.empty() && !relay_hosts.empty()) || !stun_hosts.empty()) - last_jingle_info_update_time_ = base::TimeTicks::Now(); - - while (!on_jingle_info_callbacks_.empty()) { - on_jingle_info_callbacks_.begin()->Run(); - on_jingle_info_callbacks_.pop_front(); - } -} - } // namespace protocol } // namespace remoting diff --git a/remoting/protocol/libjingle_transport_factory.h b/remoting/protocol/libjingle_transport_factory.h index 637410c..dfa0ab1 100644 --- a/remoting/protocol/libjingle_transport_factory.h +++ b/remoting/protocol/libjingle_transport_factory.h @@ -5,10 +5,6 @@ #ifndef REMOTING_PROTOCOL_LIBJINGLE_TRANSPORT_FACTORY_H_ #define REMOTING_PROTOCOL_LIBJINGLE_TRANSPORT_FACTORY_H_ -#include <list> - -#include "base/callback_forward.h" -#include "remoting/jingle_glue/network_settings.h" #include "remoting/protocol/transport.h" namespace cricket { @@ -23,49 +19,34 @@ class URLRequestContextGetter; namespace talk_base { class NetworkManager; class PacketSocketFactory; -class SocketAddress; } // namespace talk_base namespace remoting { -class SignalStrategy; -class JingleInfoRequest; +struct NetworkSettings; namespace protocol { class LibjingleTransportFactory : public TransportFactory { public: - // |signal_strategy| must outlive LibjingleTransportFactory. Need to use - // cricket::HttpPortAllocatorBase pointer for the |port_allocator|, so that it - // is possible to configure |port_allocator| with STUN/Relay addresses. + // Need to use cricket::HttpPortAllocatorBase pointer for the + // |port_allocator|, so that it is possible to configure + // |port_allocator| with STUN/Relay addresses. + // TODO(sergeyu): Reconsider this design. LibjingleTransportFactory( - SignalStrategy* signal_strategy, scoped_ptr<cricket::HttpPortAllocatorBase> port_allocator, - const NetworkSettings& network_settings); + bool incoming_only); virtual ~LibjingleTransportFactory(); // TransportFactory interface. - virtual void PrepareTokens() OVERRIDE; + virtual void SetTransportConfig(const TransportConfig& config) OVERRIDE; virtual scoped_ptr<StreamTransport> CreateStreamTransport() OVERRIDE; virtual scoped_ptr<DatagramTransport> CreateDatagramTransport() OVERRIDE; private: - void EnsureFreshJingleInfo(); - void OnJingleInfo(const std::string& relay_token, - const std::vector<std::string>& relay_hosts, - const std::vector<talk_base::SocketAddress>& stun_hosts); - - SignalStrategy* signal_strategy_; scoped_ptr<cricket::HttpPortAllocatorBase> port_allocator_; - NetworkSettings network_settings_; - - base::TimeTicks last_jingle_info_update_time_; - scoped_ptr<JingleInfoRequest> jingle_info_request_; - - // When there is an active |jingle_info_request_| stores list of callbacks to - // be called once the |jingle_info_request_| is finished. - std::list<base::Closure> on_jingle_info_callbacks_; + bool incoming_only_; DISALLOW_COPY_AND_ASSIGN(LibjingleTransportFactory); }; diff --git a/remoting/protocol/session_manager.h b/remoting/protocol/session_manager.h index 8ac484d..37b9599 100644 --- a/remoting/protocol/session_manager.h +++ b/remoting/protocol/session_manager.h @@ -59,6 +59,7 @@ #include "base/memory/ref_counted.h" #include "base/threading/non_thread_safe.h" #include "remoting/protocol/session.h" +#include "remoting/protocol/transport_config.h" namespace remoting { diff --git a/remoting/protocol/transport.h b/remoting/protocol/transport.h index 196b9d2..fe2f4e1 100644 --- a/remoting/protocol/transport.h +++ b/remoting/protocol/transport.h @@ -43,6 +43,7 @@ namespace remoting { namespace protocol { class ChannelAuthenticator; +struct TransportConfig; struct TransportRoute { enum RouteType { @@ -150,11 +151,8 @@ class TransportFactory { TransportFactory() { } virtual ~TransportFactory() { } - // Called to notify transport factory that a new transport might be created - // soon, e.g. when a new session is being created. Implementation may use it - // to start asynchronous preparation, e.g. fetch a new relay token if - // necessary while the session is being authenticated. - virtual void PrepareTokens() = 0; + // Sets configuration for the transports created by this factory. + virtual void SetTransportConfig(const TransportConfig& config) = 0; virtual scoped_ptr<StreamTransport> CreateStreamTransport() = 0; virtual scoped_ptr<DatagramTransport> CreateDatagramTransport() = 0; diff --git a/remoting/protocol/transport_config.cc b/remoting/protocol/transport_config.cc new file mode 100644 index 0000000..093e1b1 --- /dev/null +++ b/remoting/protocol/transport_config.cc @@ -0,0 +1,17 @@ +// 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/transport_config.h" + +namespace remoting { +namespace protocol { + +TransportConfig::TransportConfig() { +} + +TransportConfig::~TransportConfig() { +} + +} // namespace protocol +} // namespace remoting diff --git a/remoting/protocol/transport_config.h b/remoting/protocol/transport_config.h new file mode 100644 index 0000000..d996bd5 --- /dev/null +++ b/remoting/protocol/transport_config.h @@ -0,0 +1,25 @@ +// 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_TRANSPORT_CONFIG_H_ +#define REMOTING_PROTOCOL_TRANSPORT_CONFIG_H_ + +#include <string> + +namespace remoting { +namespace protocol { + +struct TransportConfig { + TransportConfig(); + ~TransportConfig(); + + std::string stun_server; + std::string relay_server; + std::string relay_token; +}; + +} // namespace protocol +} // namespace remoting + +#endif // REMOTING_PROTOCOL_TRANSPORT_CONFIG_H_ diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp index ed93d2b..c4f6fde 100644 --- a/remoting/remoting.gyp +++ b/remoting/remoting.gyp @@ -2767,6 +2767,8 @@ 'protocol/ssl_hmac_channel_authenticator.h', 'protocol/transport.cc', 'protocol/transport.h', + 'protocol/transport_config.cc', + 'protocol/transport_config.h', 'protocol/util.cc', 'protocol/util.h', 'protocol/third_party_authenticator_base.cc', |