| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.h" | 5 #include "remoting/protocol/jingle_session.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "remoting/base/constants.h" | 14 #include "remoting/base/constants.h" |
| 15 #include "remoting/protocol/authenticator.h" | 15 #include "remoting/protocol/authenticator.h" |
| 16 #include "remoting/protocol/channel_authenticator.h" | 16 #include "remoting/protocol/channel_authenticator.h" |
| 17 #include "remoting/protocol/channel_multiplexer.h" | 17 #include "remoting/protocol/channel_multiplexer.h" |
| 18 #include "remoting/protocol/content_description.h" | 18 #include "remoting/protocol/content_description.h" |
| 19 #include "remoting/protocol/jingle_messages.h" | 19 #include "remoting/protocol/jingle_messages.h" |
| 20 #include "remoting/protocol/jingle_session_manager.h" | 20 #include "remoting/protocol/jingle_session_manager.h" |
| 21 #include "remoting/protocol/pseudotcp_channel_factory.h" | 21 #include "remoting/protocol/pseudotcp_channel_factory.h" |
| 22 #include "remoting/protocol/quic_channel_factory.h" |
| 22 #include "remoting/protocol/secure_channel_factory.h" | 23 #include "remoting/protocol/secure_channel_factory.h" |
| 23 #include "remoting/protocol/session_config.h" | 24 #include "remoting/protocol/session_config.h" |
| 24 #include "remoting/protocol/stream_channel_factory.h" | 25 #include "remoting/protocol/stream_channel_factory.h" |
| 25 #include "remoting/signaling/iq_sender.h" | 26 #include "remoting/signaling/iq_sender.h" |
| 26 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" | 27 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" |
| 27 #include "third_party/webrtc/p2p/base/candidate.h" | 28 #include "third_party/webrtc/p2p/base/candidate.h" |
| 28 | 29 |
| 29 using buzz::XmlElement; | 30 using buzz::XmlElement; |
| 30 | 31 |
| 31 namespace remoting { | 32 namespace remoting { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 JingleSession::JingleSession(JingleSessionManager* session_manager) | 72 JingleSession::JingleSession(JingleSessionManager* session_manager) |
| 72 : session_manager_(session_manager), | 73 : session_manager_(session_manager), |
| 73 event_handler_(nullptr), | 74 event_handler_(nullptr), |
| 74 state_(INITIALIZING), | 75 state_(INITIALIZING), |
| 75 error_(OK), | 76 error_(OK), |
| 76 weak_factory_(this) { | 77 weak_factory_(this) { |
| 77 } | 78 } |
| 78 | 79 |
| 79 JingleSession::~JingleSession() { | 80 JingleSession::~JingleSession() { |
| 80 channel_multiplexer_.reset(); | 81 channel_multiplexer_.reset(); |
| 82 quic_channel_factory_.reset(); |
| 81 STLDeleteContainerPointers(pending_requests_.begin(), | 83 STLDeleteContainerPointers(pending_requests_.begin(), |
| 82 pending_requests_.end()); | 84 pending_requests_.end()); |
| 83 STLDeleteContainerPointers(transport_info_requests_.begin(), | 85 STLDeleteContainerPointers(transport_info_requests_.begin(), |
| 84 transport_info_requests_.end()); | 86 transport_info_requests_.end()); |
| 85 | 87 |
| 86 DCHECK(channels_.empty()); | 88 DCHECK(channels_.empty()); |
| 87 | 89 |
| 88 session_manager_->SessionDestroyed(this); | 90 session_manager_->SessionDestroyed(this); |
| 89 } | 91 } |
| 90 | 92 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 107 | 109 |
| 108 peer_jid_ = peer_jid; | 110 peer_jid_ = peer_jid; |
| 109 authenticator_ = authenticator.Pass(); | 111 authenticator_ = authenticator.Pass(); |
| 110 | 112 |
| 111 // Generate random session ID. There are usually not more than 1 | 113 // Generate random session ID. There are usually not more than 1 |
| 112 // concurrent session per host, so a random 64-bit integer provides | 114 // concurrent session per host, so a random 64-bit integer provides |
| 113 // enough entropy. In the worst case connection will fail when two | 115 // enough entropy. In the worst case connection will fail when two |
| 114 // clients generate the same session ID concurrently. | 116 // clients generate the same session ID concurrently. |
| 115 session_id_ = base::Int64ToString(base::RandGenerator(kint64max)); | 117 session_id_ = base::Int64ToString(base::RandGenerator(kint64max)); |
| 116 | 118 |
| 119 quic_channel_factory_.reset(new QuicChannelFactory(session_id_, false)); |
| 120 |
| 117 // Send session-initiate message. | 121 // Send session-initiate message. |
| 118 JingleMessage message(peer_jid_, JingleMessage::SESSION_INITIATE, | 122 JingleMessage message(peer_jid_, JingleMessage::SESSION_INITIATE, |
| 119 session_id_); | 123 session_id_); |
| 120 message.initiator = session_manager_->signal_strategy_->GetLocalJid(); | 124 message.initiator = session_manager_->signal_strategy_->GetLocalJid(); |
| 121 message.description.reset( | 125 message.description.reset(new ContentDescription( |
| 122 new ContentDescription(session_manager_->protocol_config_->Clone(), | 126 session_manager_->protocol_config_->Clone(), |
| 123 authenticator_->GetNextMessage())); | 127 authenticator_->GetNextMessage(), |
| 128 quic_channel_factory_->CreateSessionInitiateConfigMessage())); |
| 124 SendMessage(message); | 129 SendMessage(message); |
| 125 | 130 |
| 126 SetState(CONNECTING); | 131 SetState(CONNECTING); |
| 127 } | 132 } |
| 128 | 133 |
| 129 void JingleSession::InitializeIncomingConnection( | 134 void JingleSession::InitializeIncomingConnection( |
| 130 const JingleMessage& initiate_message, | 135 const JingleMessage& initiate_message, |
| 131 scoped_ptr<Authenticator> authenticator) { | 136 scoped_ptr<Authenticator> authenticator) { |
| 132 DCHECK(CalledOnValidThread()); | 137 DCHECK(CalledOnValidThread()); |
| 133 DCHECK(initiate_message.description.get()); | 138 DCHECK(initiate_message.description.get()); |
| 134 DCHECK(authenticator.get()); | 139 DCHECK(authenticator.get()); |
| 135 DCHECK_EQ(authenticator->state(), Authenticator::WAITING_MESSAGE); | 140 DCHECK_EQ(authenticator->state(), Authenticator::WAITING_MESSAGE); |
| 136 | 141 |
| 137 peer_jid_ = initiate_message.from; | 142 peer_jid_ = initiate_message.from; |
| 138 authenticator_ = authenticator.Pass(); | 143 authenticator_ = authenticator.Pass(); |
| 139 session_id_ = initiate_message.sid; | 144 session_id_ = initiate_message.sid; |
| 140 | 145 |
| 141 SetState(ACCEPTING); | 146 SetState(ACCEPTING); |
| 142 | 147 |
| 143 config_ = | 148 config_ = |
| 144 SessionConfig::SelectCommon(initiate_message.description->config(), | 149 SessionConfig::SelectCommon(initiate_message.description->config(), |
| 145 session_manager_->protocol_config_.get()); | 150 session_manager_->protocol_config_.get()); |
| 146 if (!config_) { | 151 if (!config_) { |
| 147 LOG(WARNING) << "Rejecting connection from " << peer_jid_ | 152 LOG(WARNING) << "Rejecting connection from " << peer_jid_ |
| 148 << " because no compatible configuration has been found."; | 153 << " because no compatible configuration has been found."; |
| 149 CloseInternal(INCOMPATIBLE_PROTOCOL); | 154 CloseInternal(INCOMPATIBLE_PROTOCOL); |
| 155 return; |
| 156 } |
| 157 |
| 158 if (config_->is_using_quic()) { |
| 159 quic_channel_factory_.reset(new QuicChannelFactory(session_id_, true)); |
| 160 if (!quic_channel_factory_->ProcessSessionInitiateConfigMessage( |
| 161 initiate_message.description->quic_config_message())) { |
| 162 CloseInternal(INCOMPATIBLE_PROTOCOL); |
| 163 } |
| 150 } | 164 } |
| 151 } | 165 } |
| 152 | 166 |
| 153 void JingleSession::AcceptIncomingConnection( | 167 void JingleSession::AcceptIncomingConnection( |
| 154 const JingleMessage& initiate_message) { | 168 const JingleMessage& initiate_message) { |
| 155 DCHECK(config_); | 169 DCHECK(config_); |
| 156 | 170 |
| 157 // Process the first authentication message. | 171 // Process the first authentication message. |
| 158 const buzz::XmlElement* first_auth_message = | 172 const buzz::XmlElement* first_auth_message = |
| 159 initiate_message.description->authenticator_message(); | 173 initiate_message.description->authenticator_message(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 179 } | 193 } |
| 180 | 194 |
| 181 // Send the session-accept message. | 195 // Send the session-accept message. |
| 182 JingleMessage message(peer_jid_, JingleMessage::SESSION_ACCEPT, | 196 JingleMessage message(peer_jid_, JingleMessage::SESSION_ACCEPT, |
| 183 session_id_); | 197 session_id_); |
| 184 | 198 |
| 185 scoped_ptr<buzz::XmlElement> auth_message; | 199 scoped_ptr<buzz::XmlElement> auth_message; |
| 186 if (authenticator_->state() == Authenticator::MESSAGE_READY) | 200 if (authenticator_->state() == Authenticator::MESSAGE_READY) |
| 187 auth_message = authenticator_->GetNextMessage(); | 201 auth_message = authenticator_->GetNextMessage(); |
| 188 | 202 |
| 203 std::string quic_config; |
| 204 if (config_->is_using_quic()) |
| 205 quic_config = quic_channel_factory_->CreateSessionAcceptConfigMessage(); |
| 189 message.description.reset( | 206 message.description.reset( |
| 190 new ContentDescription(CandidateSessionConfig::CreateFrom(*config_), | 207 new ContentDescription(CandidateSessionConfig::CreateFrom(*config_), |
| 191 auth_message.Pass())); | 208 auth_message.Pass(), quic_config)); |
| 192 SendMessage(message); | 209 SendMessage(message); |
| 193 | 210 |
| 194 // Update state. | 211 // Update state. |
| 195 SetState(CONNECTED); | 212 SetState(CONNECTED); |
| 196 | 213 |
| 197 if (authenticator_->state() == Authenticator::ACCEPTED) { | 214 if (authenticator_->state() == Authenticator::ACCEPTED) { |
| 198 OnAuthenticated(); | 215 OnAuthenticated(); |
| 199 } else { | 216 } else { |
| 200 DCHECK_EQ(authenticator_->state(), Authenticator::WAITING_MESSAGE); | 217 DCHECK_EQ(authenticator_->state(), Authenticator::WAITING_MESSAGE); |
| 201 if (authenticator_->started()) { | 218 if (authenticator_->started()) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 221 | 238 |
| 222 StreamChannelFactory* JingleSession::GetMultiplexedChannelFactory() { | 239 StreamChannelFactory* JingleSession::GetMultiplexedChannelFactory() { |
| 223 DCHECK(CalledOnValidThread()); | 240 DCHECK(CalledOnValidThread()); |
| 224 if (!channel_multiplexer_.get()) { | 241 if (!channel_multiplexer_.get()) { |
| 225 channel_multiplexer_.reset( | 242 channel_multiplexer_.reset( |
| 226 new ChannelMultiplexer(GetTransportChannelFactory(), kMuxChannelName)); | 243 new ChannelMultiplexer(GetTransportChannelFactory(), kMuxChannelName)); |
| 227 } | 244 } |
| 228 return channel_multiplexer_.get(); | 245 return channel_multiplexer_.get(); |
| 229 } | 246 } |
| 230 | 247 |
| 248 StreamChannelFactory* JingleSession::GetQuicChannelFactory() { |
| 249 DCHECK(CalledOnValidThread()); |
| 250 return quic_channel_factory_.get(); |
| 251 } |
| 252 |
| 231 void JingleSession::Close() { | 253 void JingleSession::Close() { |
| 232 DCHECK(CalledOnValidThread()); | 254 DCHECK(CalledOnValidThread()); |
| 233 | 255 |
| 234 CloseInternal(OK); | 256 CloseInternal(OK); |
| 235 } | 257 } |
| 236 | 258 |
| 237 void JingleSession::AddPendingRemoteTransportInfo(Transport* channel) { | 259 void JingleSession::AddPendingRemoteTransportInfo(Transport* channel) { |
| 238 std::list<JingleMessage::IceCredentials>::iterator credentials = | 260 std::list<JingleMessage::IceCredentials>::iterator credentials = |
| 239 pending_remote_ice_credentials_.begin(); | 261 pending_remote_ice_credentials_.begin(); |
| 240 while (credentials != pending_remote_ice_credentials_.end()) { | 262 while (credentials != pending_remote_ice_credentials_.end()) { |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 DLOG(WARNING) << "Received session-accept without authentication message "; | 497 DLOG(WARNING) << "Received session-accept without authentication message "; |
| 476 CloseInternal(INCOMPATIBLE_PROTOCOL); | 498 CloseInternal(INCOMPATIBLE_PROTOCOL); |
| 477 return; | 499 return; |
| 478 } | 500 } |
| 479 | 501 |
| 480 if (!InitializeConfigFromDescription(message.description.get())) { | 502 if (!InitializeConfigFromDescription(message.description.get())) { |
| 481 CloseInternal(INCOMPATIBLE_PROTOCOL); | 503 CloseInternal(INCOMPATIBLE_PROTOCOL); |
| 482 return; | 504 return; |
| 483 } | 505 } |
| 484 | 506 |
| 507 if (config_->is_using_quic()) { |
| 508 if (!quic_channel_factory_->ProcessSessionAcceptConfigMessage( |
| 509 message.description->quic_config_message())) { |
| 510 CloseInternal(INCOMPATIBLE_PROTOCOL); |
| 511 return; |
| 512 } |
| 513 } else { |
| 514 quic_channel_factory_.reset(); |
| 515 } |
| 516 |
| 485 SetState(CONNECTED); | 517 SetState(CONNECTED); |
| 486 | 518 |
| 487 DCHECK(authenticator_->state() == Authenticator::WAITING_MESSAGE); | 519 DCHECK(authenticator_->state() == Authenticator::WAITING_MESSAGE); |
| 488 authenticator_->ProcessMessage(auth_message, base::Bind( | 520 authenticator_->ProcessMessage(auth_message, base::Bind( |
| 489 &JingleSession::ProcessAuthenticationStep,base::Unretained(this))); | 521 &JingleSession::ProcessAuthenticationStep,base::Unretained(this))); |
| 490 } | 522 } |
| 491 | 523 |
| 492 void JingleSession::OnSessionInfo(const JingleMessage& message, | 524 void JingleSession::OnSessionInfo(const JingleMessage& message, |
| 493 const ReplyCallback& reply_callback) { | 525 const ReplyCallback& reply_callback) { |
| 494 if (!message.info.get() || | 526 if (!message.info.get() || |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 authenticator_->rejection_reason())); | 670 authenticator_->rejection_reason())); |
| 639 } | 671 } |
| 640 } | 672 } |
| 641 | 673 |
| 642 void JingleSession::OnAuthenticated() { | 674 void JingleSession::OnAuthenticated() { |
| 643 pseudotcp_channel_factory_.reset(new PseudoTcpChannelFactory(this)); | 675 pseudotcp_channel_factory_.reset(new PseudoTcpChannelFactory(this)); |
| 644 secure_channel_factory_.reset( | 676 secure_channel_factory_.reset( |
| 645 new SecureChannelFactory(pseudotcp_channel_factory_.get(), | 677 new SecureChannelFactory(pseudotcp_channel_factory_.get(), |
| 646 authenticator_.get())); | 678 authenticator_.get())); |
| 647 | 679 |
| 680 if (quic_channel_factory_) |
| 681 quic_channel_factory_->Start(this, authenticator_->GetAuthKey()); |
| 682 |
| 648 SetState(AUTHENTICATED); | 683 SetState(AUTHENTICATED); |
| 649 } | 684 } |
| 650 | 685 |
| 651 void JingleSession::CloseInternal(ErrorCode error) { | 686 void JingleSession::CloseInternal(ErrorCode error) { |
| 652 DCHECK(CalledOnValidThread()); | 687 DCHECK(CalledOnValidThread()); |
| 653 | 688 |
| 654 if (is_session_active()) { | 689 if (is_session_active()) { |
| 655 // Send session-terminate message with the appropriate error code. | 690 // Send session-terminate message with the appropriate error code. |
| 656 JingleMessage::Reason reason; | 691 JingleMessage::Reason reason; |
| 657 switch (error) { | 692 switch (error) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 } | 737 } |
| 703 } | 738 } |
| 704 | 739 |
| 705 bool JingleSession::is_session_active() { | 740 bool JingleSession::is_session_active() { |
| 706 return state_ == CONNECTING || state_ == ACCEPTING || state_ == CONNECTED || | 741 return state_ == CONNECTING || state_ == ACCEPTING || state_ == CONNECTED || |
| 707 state_ == AUTHENTICATING || state_ == AUTHENTICATED; | 742 state_ == AUTHENTICATING || state_ == AUTHENTICATED; |
| 708 } | 743 } |
| 709 | 744 |
| 710 } // namespace protocol | 745 } // namespace protocol |
| 711 } // namespace remoting | 746 } // namespace remoting |
| OLD | NEW |