| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 DCHECK(thread_checker_.CalledOnValidThread()); | 82 DCHECK(thread_checker_.CalledOnValidThread()); |
| 83 DCHECK(event_handler); | 83 DCHECK(event_handler); |
| 84 event_handler_ = event_handler; | 84 event_handler_ = event_handler; |
| 85 } | 85 } |
| 86 | 86 |
| 87 ErrorCode JingleSession::error() { | 87 ErrorCode JingleSession::error() { |
| 88 DCHECK(thread_checker_.CalledOnValidThread()); | 88 DCHECK(thread_checker_.CalledOnValidThread()); |
| 89 return error_; | 89 return error_; |
| 90 } | 90 } |
| 91 | 91 |
| 92 void JingleSession::StartConnection(const std::string& peer_jid, | 92 void JingleSession::StartConnection( |
| 93 scoped_ptr<Authenticator> authenticator) { | 93 const std::string& peer_jid, |
| 94 std::unique_ptr<Authenticator> authenticator) { |
| 94 DCHECK(thread_checker_.CalledOnValidThread()); | 95 DCHECK(thread_checker_.CalledOnValidThread()); |
| 95 DCHECK(authenticator.get()); | 96 DCHECK(authenticator.get()); |
| 96 DCHECK_EQ(authenticator->state(), Authenticator::MESSAGE_READY); | 97 DCHECK_EQ(authenticator->state(), Authenticator::MESSAGE_READY); |
| 97 | 98 |
| 98 peer_jid_ = peer_jid; | 99 peer_jid_ = peer_jid; |
| 99 authenticator_ = std::move(authenticator); | 100 authenticator_ = std::move(authenticator); |
| 100 | 101 |
| 101 // Generate random session ID. There are usually not more than 1 | 102 // Generate random session ID. There are usually not more than 1 |
| 102 // concurrent session per host, so a random 64-bit integer provides | 103 // concurrent session per host, so a random 64-bit integer provides |
| 103 // enough entropy. In the worst case connection will fail when two | 104 // enough entropy. In the worst case connection will fail when two |
| 104 // clients generate the same session ID concurrently. | 105 // clients generate the same session ID concurrently. |
| 105 session_id_ = base::Uint64ToString( | 106 session_id_ = base::Uint64ToString( |
| 106 base::RandGenerator(std::numeric_limits<uint64_t>::max())); | 107 base::RandGenerator(std::numeric_limits<uint64_t>::max())); |
| 107 | 108 |
| 108 // Send session-initiate message. | 109 // Send session-initiate message. |
| 109 JingleMessage message(peer_jid_, JingleMessage::SESSION_INITIATE, | 110 JingleMessage message(peer_jid_, JingleMessage::SESSION_INITIATE, |
| 110 session_id_); | 111 session_id_); |
| 111 message.initiator = session_manager_->signal_strategy_->GetLocalJid(); | 112 message.initiator = session_manager_->signal_strategy_->GetLocalJid(); |
| 112 message.description.reset(new ContentDescription( | 113 message.description.reset(new ContentDescription( |
| 113 session_manager_->protocol_config_->Clone(), | 114 session_manager_->protocol_config_->Clone(), |
| 114 authenticator_->GetNextMessage())); | 115 authenticator_->GetNextMessage())); |
| 115 SendMessage(message); | 116 SendMessage(message); |
| 116 | 117 |
| 117 SetState(CONNECTING); | 118 SetState(CONNECTING); |
| 118 } | 119 } |
| 119 | 120 |
| 120 void JingleSession::InitializeIncomingConnection( | 121 void JingleSession::InitializeIncomingConnection( |
| 121 const JingleMessage& initiate_message, | 122 const JingleMessage& initiate_message, |
| 122 scoped_ptr<Authenticator> authenticator) { | 123 std::unique_ptr<Authenticator> authenticator) { |
| 123 DCHECK(thread_checker_.CalledOnValidThread()); | 124 DCHECK(thread_checker_.CalledOnValidThread()); |
| 124 DCHECK(initiate_message.description.get()); | 125 DCHECK(initiate_message.description.get()); |
| 125 DCHECK(authenticator.get()); | 126 DCHECK(authenticator.get()); |
| 126 DCHECK_EQ(authenticator->state(), Authenticator::WAITING_MESSAGE); | 127 DCHECK_EQ(authenticator->state(), Authenticator::WAITING_MESSAGE); |
| 127 | 128 |
| 128 peer_jid_ = initiate_message.from; | 129 peer_jid_ = initiate_message.from; |
| 129 authenticator_ = std::move(authenticator); | 130 authenticator_ = std::move(authenticator); |
| 130 session_id_ = initiate_message.sid; | 131 session_id_ = initiate_message.sid; |
| 131 | 132 |
| 132 SetState(ACCEPTING); | 133 SetState(ACCEPTING); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 DCHECK_NE(authenticator_->state(), Authenticator::PROCESSING_MESSAGE); | 167 DCHECK_NE(authenticator_->state(), Authenticator::PROCESSING_MESSAGE); |
| 167 if (authenticator_->state() == Authenticator::REJECTED) { | 168 if (authenticator_->state() == Authenticator::REJECTED) { |
| 168 Close(AuthRejectionReasonToErrorCode(authenticator_->rejection_reason())); | 169 Close(AuthRejectionReasonToErrorCode(authenticator_->rejection_reason())); |
| 169 return; | 170 return; |
| 170 } | 171 } |
| 171 | 172 |
| 172 // Send the session-accept message. | 173 // Send the session-accept message. |
| 173 JingleMessage message(peer_jid_, JingleMessage::SESSION_ACCEPT, | 174 JingleMessage message(peer_jid_, JingleMessage::SESSION_ACCEPT, |
| 174 session_id_); | 175 session_id_); |
| 175 | 176 |
| 176 scoped_ptr<buzz::XmlElement> auth_message; | 177 std::unique_ptr<buzz::XmlElement> auth_message; |
| 177 if (authenticator_->state() == Authenticator::MESSAGE_READY) | 178 if (authenticator_->state() == Authenticator::MESSAGE_READY) |
| 178 auth_message = authenticator_->GetNextMessage(); | 179 auth_message = authenticator_->GetNextMessage(); |
| 179 | 180 |
| 180 message.description.reset(new ContentDescription( | 181 message.description.reset(new ContentDescription( |
| 181 CandidateSessionConfig::CreateFrom(*config_), std::move(auth_message))); | 182 CandidateSessionConfig::CreateFrom(*config_), std::move(auth_message))); |
| 182 SendMessage(message); | 183 SendMessage(message); |
| 183 | 184 |
| 184 // Update state. | 185 // Update state. |
| 185 SetState(ACCEPTED); | 186 SetState(ACCEPTED); |
| 186 | 187 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 205 } | 206 } |
| 206 | 207 |
| 207 void JingleSession::SetTransport(Transport* transport) { | 208 void JingleSession::SetTransport(Transport* transport) { |
| 208 DCHECK(thread_checker_.CalledOnValidThread()); | 209 DCHECK(thread_checker_.CalledOnValidThread()); |
| 209 DCHECK(!transport_); | 210 DCHECK(!transport_); |
| 210 DCHECK(transport); | 211 DCHECK(transport); |
| 211 transport_ = transport; | 212 transport_ = transport; |
| 212 } | 213 } |
| 213 | 214 |
| 214 void JingleSession::SendTransportInfo( | 215 void JingleSession::SendTransportInfo( |
| 215 scoped_ptr<buzz::XmlElement> transport_info) { | 216 std::unique_ptr<buzz::XmlElement> transport_info) { |
| 216 DCHECK(thread_checker_.CalledOnValidThread()); | 217 DCHECK(thread_checker_.CalledOnValidThread()); |
| 217 DCHECK_EQ(state_, AUTHENTICATED); | 218 DCHECK_EQ(state_, AUTHENTICATED); |
| 218 | 219 |
| 219 JingleMessage message(peer_jid_, JingleMessage::TRANSPORT_INFO, session_id_); | 220 JingleMessage message(peer_jid_, JingleMessage::TRANSPORT_INFO, session_id_); |
| 220 message.transport_info = std::move(transport_info); | 221 message.transport_info = std::move(transport_info); |
| 221 | 222 |
| 222 scoped_ptr<IqRequest> request = session_manager_->iq_sender()->SendIq( | 223 std::unique_ptr<IqRequest> request = session_manager_->iq_sender()->SendIq( |
| 223 message.ToXml(), base::Bind(&JingleSession::OnTransportInfoResponse, | 224 message.ToXml(), base::Bind(&JingleSession::OnTransportInfoResponse, |
| 224 base::Unretained(this))); | 225 base::Unretained(this))); |
| 225 if (request) { | 226 if (request) { |
| 226 request->SetTimeout(base::TimeDelta::FromSeconds(kTransportInfoTimeout)); | 227 request->SetTimeout(base::TimeDelta::FromSeconds(kTransportInfoTimeout)); |
| 227 transport_info_requests_.push_back(request.release()); | 228 transport_info_requests_.push_back(request.release()); |
| 228 } else { | 229 } else { |
| 229 LOG(ERROR) << "Failed to send a transport-info message"; | 230 LOG(ERROR) << "Failed to send a transport-info message"; |
| 230 } | 231 } |
| 231 } | 232 } |
| 232 | 233 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 SetState(FAILED); | 274 SetState(FAILED); |
| 274 } else { | 275 } else { |
| 275 SetState(CLOSED); | 276 SetState(CLOSED); |
| 276 } | 277 } |
| 277 } | 278 } |
| 278 } | 279 } |
| 279 | 280 |
| 280 void JingleSession::SendMessage(const JingleMessage& message) { | 281 void JingleSession::SendMessage(const JingleMessage& message) { |
| 281 DCHECK(thread_checker_.CalledOnValidThread()); | 282 DCHECK(thread_checker_.CalledOnValidThread()); |
| 282 | 283 |
| 283 scoped_ptr<IqRequest> request = session_manager_->iq_sender()->SendIq( | 284 std::unique_ptr<IqRequest> request = session_manager_->iq_sender()->SendIq( |
| 284 message.ToXml(), | 285 message.ToXml(), base::Bind(&JingleSession::OnMessageResponse, |
| 285 base::Bind(&JingleSession::OnMessageResponse, | 286 base::Unretained(this), message.action)); |
| 286 base::Unretained(this), | |
| 287 message.action)); | |
| 288 | 287 |
| 289 int timeout = kDefaultMessageTimeout; | 288 int timeout = kDefaultMessageTimeout; |
| 290 if (message.action == JingleMessage::SESSION_INITIATE || | 289 if (message.action == JingleMessage::SESSION_INITIATE || |
| 291 message.action == JingleMessage::SESSION_ACCEPT) { | 290 message.action == JingleMessage::SESSION_ACCEPT) { |
| 292 timeout = kSessionInitiateAndAcceptTimeout; | 291 timeout = kSessionInitiateAndAcceptTimeout; |
| 293 } | 292 } |
| 294 if (request) { | 293 if (request) { |
| 295 request->SetTimeout(base::TimeDelta::FromSeconds(timeout)); | 294 request->SetTimeout(base::TimeDelta::FromSeconds(timeout)); |
| 296 pending_requests_.insert(request.release()); | 295 pending_requests_.insert(request.release()); |
| 297 } else { | 296 } else { |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 } | 589 } |
| 591 } | 590 } |
| 592 | 591 |
| 593 bool JingleSession::is_session_active() { | 592 bool JingleSession::is_session_active() { |
| 594 return state_ == CONNECTING || state_ == ACCEPTING || state_ == ACCEPTED || | 593 return state_ == CONNECTING || state_ == ACCEPTING || state_ == ACCEPTED || |
| 595 state_ == AUTHENTICATING || state_ == AUTHENTICATED; | 594 state_ == AUTHENTICATING || state_ == AUTHENTICATED; |
| 596 } | 595 } |
| 597 | 596 |
| 598 } // namespace protocol | 597 } // namespace protocol |
| 599 } // namespace remoting | 598 } // namespace remoting |
| OLD | NEW |