Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/protocol/jingle_session_manager.h" | 5 #include "remoting/protocol/jingle_session_manager.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/task.h" | 11 #include "base/task.h" |
| 12 #include "remoting/base/constants.h" | 12 #include "remoting/base/constants.h" |
| 13 #include "remoting/jingle_glue/http_port_allocator.h" | 13 #include "remoting/jingle_glue/http_port_allocator.h" |
| 14 #include "remoting/jingle_glue/jingle_info_request.h" | 14 #include "remoting/jingle_glue/jingle_info_request.h" |
| 15 #include "remoting/jingle_glue/jingle_signaling_connector.h" | 15 #include "remoting/jingle_glue/jingle_signaling_connector.h" |
| 16 #include "remoting/jingle_glue/signal_strategy.h" | 16 #include "remoting/jingle_glue/signal_strategy.h" |
| 17 #include "third_party/libjingle/source/talk/base/basicpacketsocketfactory.h" | 17 #include "third_party/libjingle/source/talk/base/basicpacketsocketfactory.h" |
| 18 #include "third_party/libjingle/source/talk/p2p/base/sessionmanager.h" | 18 #include "third_party/libjingle/source/talk/p2p/base/sessionmanager.h" |
| 19 #include "third_party/libjingle/source/talk/p2p/base/transport.h" | 19 #include "third_party/libjingle/source/talk/p2p/base/transport.h" |
| 20 #include "third_party/libjingle/source/talk/p2p/base/constants.h" | 20 #include "third_party/libjingle/source/talk/p2p/base/constants.h" |
| 21 #include "third_party/libjingle/source/talk/p2p/base/transport.h" | 21 #include "third_party/libjingle/source/talk/p2p/base/transport.h" |
| 22 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | 22 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
| 23 | 23 |
| 24 using buzz::XmlElement; | 24 using buzz::XmlElement; |
| 25 | 25 |
| 26 namespace remoting { | 26 namespace remoting { |
| 27 namespace protocol { | 27 namespace protocol { |
| 28 | 28 |
| 29 // static | |
| 30 JingleSessionManager* JingleSessionManager::Create() { | |
| 31 return JingleSessionManager::Create(); | |
|
Wez
2011/07/06 21:24:25
Eeep, recursion!
Sergey Ulanov
2011/07/06 23:15:01
Ouch.
| |
| 32 } | |
| 33 | |
| 34 // static | |
| 35 JingleSessionManager* JingleSessionManager::Create( | |
| 36 talk_base::NetworkManager* network_manager, | |
| 37 talk_base::PacketSocketFactory* socket_factory, | |
| 38 PortAllocatorSessionFactory* port_allocator_session_factory) { | |
| 39 return JingleSessionManager::Create(network_manager, socket_factory, | |
| 40 port_allocator_session_factory); | |
|
Wez
2011/07/06 21:24:25
Eeep, recursion!
Sergey Ulanov
2011/07/06 23:15:01
Done.
| |
| 41 } | |
| 42 | |
| 29 JingleSessionManager::JingleSessionManager( | 43 JingleSessionManager::JingleSessionManager( |
| 30 talk_base::NetworkManager* network_manager, | 44 talk_base::NetworkManager* network_manager, |
| 31 talk_base::PacketSocketFactory* socket_factory, | 45 talk_base::PacketSocketFactory* socket_factory, |
| 32 PortAllocatorSessionFactory* port_allocator_session_factory) | 46 PortAllocatorSessionFactory* port_allocator_session_factory) |
| 33 : network_manager_(network_manager), | 47 : network_manager_(network_manager), |
| 34 socket_factory_(socket_factory), | 48 socket_factory_(socket_factory), |
| 35 port_allocator_session_factory_(port_allocator_session_factory), | 49 port_allocator_session_factory_(port_allocator_session_factory), |
| 36 signal_strategy_(NULL), | 50 signal_strategy_(NULL), |
| 37 enable_nat_traversing_(false), | 51 enable_nat_traversing_(false), |
| 38 allow_local_ips_(false), | 52 allow_local_ips_(false), |
| 39 http_port_allocator_(NULL), | 53 http_port_allocator_(NULL), |
| 40 closed_(false), | 54 closed_(false), |
| 41 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { | 55 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { |
| 42 } | 56 } |
| 43 | 57 |
| 44 JingleSessionManager::~JingleSessionManager() { | 58 JingleSessionManager::~JingleSessionManager() { |
| 45 DCHECK(closed_); | 59 Close(); |
|
Wez
2011/07/06 21:24:25
Once we have removed ourself from |cricket_session
Sergey Ulanov
2011/07/06 23:15:01
No, it should not call us after that. We also dest
| |
| 46 } | 60 } |
| 47 | 61 |
| 48 void JingleSessionManager::Init( | 62 void JingleSessionManager::Init( |
| 49 const std::string& local_jid, | 63 const std::string& local_jid, |
| 50 SignalStrategy* signal_strategy, | 64 SignalStrategy* signal_strategy, |
| 51 IncomingSessionCallback* incoming_session_callback, | 65 IncomingSessionCallback* incoming_session_callback, |
| 52 crypto::RSAPrivateKey* private_key, | 66 crypto::RSAPrivateKey* private_key, |
| 53 scoped_refptr<net::X509Certificate> certificate) { | 67 scoped_refptr<net::X509Certificate> certificate) { |
| 54 DCHECK(CalledOnValidThread()); | 68 DCHECK(CalledOnValidThread()); |
| 55 | 69 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 CandidateSessionConfig* candidate_config, | 134 CandidateSessionConfig* candidate_config, |
| 121 Session::StateChangeCallback* state_change_callback) { | 135 Session::StateChangeCallback* state_change_callback) { |
| 122 DCHECK(CalledOnValidThread()); | 136 DCHECK(CalledOnValidThread()); |
| 123 | 137 |
| 124 // Can be called from any thread. | 138 // Can be called from any thread. |
| 125 JingleSession* jingle_session = | 139 JingleSession* jingle_session = |
| 126 JingleSession::CreateClientSession(this, host_public_key); | 140 JingleSession::CreateClientSession(this, host_public_key); |
| 127 jingle_session->set_candidate_config(candidate_config); | 141 jingle_session->set_candidate_config(candidate_config); |
| 128 jingle_session->set_receiver_token(receiver_token); | 142 jingle_session->set_receiver_token(receiver_token); |
| 129 | 143 |
| 130 // TODO(sergeyu): Does this need to be asynchronous? | |
| 131 MessageLoop::current()->PostTask(FROM_HERE, task_factory_.NewRunnableMethod( | |
| 132 &JingleSessionManager::DoConnect, jingle_session, host_jid, | |
| 133 host_public_key, receiver_token, state_change_callback)); | |
| 134 return jingle_session; | |
| 135 } | |
| 136 | |
| 137 void JingleSessionManager::DoConnect( | |
| 138 JingleSession* jingle_session, | |
| 139 const std::string& host_jid, | |
| 140 const std::string& host_public_key, | |
| 141 const std::string& receiver_token, | |
| 142 Session::StateChangeCallback* state_change_callback) { | |
| 143 DCHECK(CalledOnValidThread()); | |
| 144 | |
| 145 cricket::Session* cricket_session = cricket_session_manager_->CreateSession( | 144 cricket::Session* cricket_session = cricket_session_manager_->CreateSession( |
| 146 local_jid_, kChromotingXmlNamespace); | 145 local_jid_, kChromotingXmlNamespace); |
| 147 | 146 |
| 148 // Initialize connection object before we send initiate stanza. | 147 // Initialize connection object before we send initiate stanza. |
| 149 jingle_session->SetStateChangeCallback(state_change_callback); | 148 jingle_session->SetStateChangeCallback(state_change_callback); |
| 150 jingle_session->Init(cricket_session); | 149 jingle_session->Init(cricket_session); |
| 151 sessions_.push_back(jingle_session); | 150 sessions_.push_back(jingle_session); |
| 152 | 151 |
| 153 cricket_session->Initiate(host_jid, CreateClientSessionDescription( | 152 cricket_session->Initiate(host_jid, CreateClientSessionDescription( |
| 154 jingle_session->candidate_config()->Clone(), receiver_token, | 153 jingle_session->candidate_config()->Clone(), receiver_token, |
| 155 jingle_session->GetEncryptedMasterKey())); | 154 jingle_session->GetEncryptedMasterKey())); |
| 155 | |
| 156 return jingle_session; | |
| 156 } | 157 } |
| 157 | 158 |
| 158 void JingleSessionManager::OnSessionCreate( | 159 void JingleSessionManager::OnSessionCreate( |
| 159 cricket::Session* cricket_session, bool incoming) { | 160 cricket::Session* cricket_session, bool incoming) { |
| 160 DCHECK(CalledOnValidThread()); | 161 DCHECK(CalledOnValidThread()); |
| 161 | 162 |
| 162 // Allow local connections if neccessary. | 163 // Allow local connections if neccessary. |
| 163 cricket_session->set_allow_local_ips(allow_local_ips_); | 164 cricket_session->set_allow_local_ips(allow_local_ips_); |
| 164 | 165 |
| 165 // If this is an outcoming session the session object is already created. | 166 // If this is an outcoming session the session object is already created. |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 cricket_session_manager_->DestroySession(cricket_session); | 255 cricket_session_manager_->DestroySession(cricket_session); |
| 255 sessions_.erase(it); | 256 sessions_.erase(it); |
| 256 } | 257 } |
| 257 | 258 |
| 258 void JingleSessionManager::OnJingleInfo( | 259 void JingleSessionManager::OnJingleInfo( |
| 259 const std::string& token, | 260 const std::string& token, |
| 260 const std::vector<std::string>& relay_hosts, | 261 const std::vector<std::string>& relay_hosts, |
| 261 const std::vector<talk_base::SocketAddress>& stun_hosts) { | 262 const std::vector<talk_base::SocketAddress>& stun_hosts) { |
| 262 DCHECK(CalledOnValidThread()); | 263 DCHECK(CalledOnValidThread()); |
| 263 | 264 |
| 264 if (port_allocator_.get()) { | 265 if (http_port_allocator_) { |
| 265 // TODO(ajwong): Avoid string processing if log-level is low. | 266 // TODO(ajwong): Avoid string processing if log-level is low. |
| 266 std::string stun_servers; | 267 std::string stun_servers; |
| 267 for (size_t i = 0; i < stun_hosts.size(); ++i) { | 268 for (size_t i = 0; i < stun_hosts.size(); ++i) { |
| 268 stun_servers += stun_hosts[i].ToString() + "; "; | 269 stun_servers += stun_hosts[i].ToString() + "; "; |
| 269 } | 270 } |
| 270 LOG(INFO) << "Configuring with relay token: " << token | 271 LOG(INFO) << "Configuring with relay token: " << token |
| 271 << ", relays: " << JoinString(relay_hosts, ';') | 272 << ", relays: " << JoinString(relay_hosts, ';') |
| 272 << ", stun: " << stun_servers; | 273 << ", stun: " << stun_servers; |
| 273 http_port_allocator_->SetRelayToken(token); | 274 http_port_allocator_->SetRelayToken(token); |
| 274 http_port_allocator_->SetStunHosts(stun_hosts); | 275 http_port_allocator_->SetStunHosts(stun_hosts); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 scoped_refptr<net::X509Certificate> certificate) { | 331 scoped_refptr<net::X509Certificate> certificate) { |
| 331 cricket::SessionDescription* desc = new cricket::SessionDescription(); | 332 cricket::SessionDescription* desc = new cricket::SessionDescription(); |
| 332 desc->AddContent( | 333 desc->AddContent( |
| 333 JingleSession::kChromotingContentName, kChromotingXmlNamespace, | 334 JingleSession::kChromotingContentName, kChromotingXmlNamespace, |
| 334 new ContentDescription(config, "", "", certificate)); | 335 new ContentDescription(config, "", "", certificate)); |
| 335 return desc; | 336 return desc; |
| 336 } | 337 } |
| 337 | 338 |
| 338 } // namespace protocol | 339 } // namespace protocol |
| 339 } // namespace remoting | 340 } // namespace remoting |
| OLD | NEW |