Chromium Code Reviews| 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/authenticated_channel_factory.h" | |
| 15 #include "remoting/protocol/authenticator.h" | 16 #include "remoting/protocol/authenticator.h" |
| 16 #include "remoting/protocol/channel_authenticator.h" | 17 #include "remoting/protocol/channel_authenticator.h" |
| 18 #include "remoting/protocol/channel_factory.h" | |
| 17 #include "remoting/protocol/channel_multiplexer.h" | 19 #include "remoting/protocol/channel_multiplexer.h" |
| 18 #include "remoting/protocol/content_description.h" | 20 #include "remoting/protocol/content_description.h" |
| 19 #include "remoting/protocol/jingle_messages.h" | 21 #include "remoting/protocol/jingle_messages.h" |
| 20 #include "remoting/protocol/jingle_session_manager.h" | 22 #include "remoting/protocol/jingle_session_manager.h" |
| 23 #include "remoting/protocol/pseudotcp_channel_factory.h" | |
| 21 #include "remoting/protocol/session_config.h" | 24 #include "remoting/protocol/session_config.h" |
| 22 #include "remoting/signaling/iq_sender.h" | 25 #include "remoting/signaling/iq_sender.h" |
| 23 #include "third_party/libjingle/source/talk/p2p/base/candidate.h" | 26 #include "third_party/libjingle/source/talk/p2p/base/candidate.h" |
| 24 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | 27 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
| 25 | 28 |
| 26 using buzz::XmlElement; | 29 using buzz::XmlElement; |
| 27 | 30 |
| 28 namespace remoting { | 31 namespace remoting { |
| 29 namespace protocol { | 32 namespace protocol { |
| 30 | 33 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 | 183 |
| 181 message.description.reset( | 184 message.description.reset( |
| 182 new ContentDescription(CandidateSessionConfig::CreateFrom(config_), | 185 new ContentDescription(CandidateSessionConfig::CreateFrom(config_), |
| 183 auth_message.Pass())); | 186 auth_message.Pass())); |
| 184 SendMessage(message); | 187 SendMessage(message); |
| 185 | 188 |
| 186 // Update state. | 189 // Update state. |
| 187 SetState(CONNECTED); | 190 SetState(CONNECTED); |
| 188 | 191 |
| 189 if (authenticator_->state() == Authenticator::ACCEPTED) { | 192 if (authenticator_->state() == Authenticator::ACCEPTED) { |
| 190 SetState(AUTHENTICATED); | 193 OnAuthenticated(); |
| 191 } else { | 194 } else { |
| 192 DCHECK_EQ(authenticator_->state(), Authenticator::WAITING_MESSAGE); | 195 DCHECK_EQ(authenticator_->state(), Authenticator::WAITING_MESSAGE); |
| 193 if (authenticator_->started()) { | 196 if (authenticator_->started()) { |
| 194 SetState(AUTHENTICATING); | 197 SetState(AUTHENTICATING); |
| 195 } | 198 } |
| 196 } | 199 } |
| 197 } | 200 } |
| 198 | 201 |
| 199 const std::string& JingleSession::jid() { | 202 const std::string& JingleSession::jid() { |
| 200 DCHECK(CalledOnValidThread()); | 203 DCHECK(CalledOnValidThread()); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 213 | 216 |
| 214 void JingleSession::set_config(const SessionConfig& config) { | 217 void JingleSession::set_config(const SessionConfig& config) { |
| 215 DCHECK(CalledOnValidThread()); | 218 DCHECK(CalledOnValidThread()); |
| 216 DCHECK(!config_is_set_); | 219 DCHECK(!config_is_set_); |
| 217 config_ = config; | 220 config_ = config; |
| 218 config_is_set_ = true; | 221 config_is_set_ = true; |
| 219 } | 222 } |
| 220 | 223 |
| 221 ChannelFactory* JingleSession::GetTransportChannelFactory() { | 224 ChannelFactory* JingleSession::GetTransportChannelFactory() { |
| 222 DCHECK(CalledOnValidThread()); | 225 DCHECK(CalledOnValidThread()); |
| 223 return this; | 226 return authenticated_channel_factory_.get(); |
| 224 } | 227 } |
| 225 | 228 |
| 226 ChannelFactory* JingleSession::GetMultiplexedChannelFactory() { | 229 ChannelFactory* JingleSession::GetMultiplexedChannelFactory() { |
| 227 DCHECK(CalledOnValidThread()); | 230 DCHECK(CalledOnValidThread()); |
| 228 if (!channel_multiplexer_.get()) | 231 if (!channel_multiplexer_.get()) { |
| 229 channel_multiplexer_.reset(new ChannelMultiplexer(this, kMuxChannelName)); | 232 channel_multiplexer_.reset( |
| 233 new ChannelMultiplexer(GetTransportChannelFactory(), kMuxChannelName)); | |
| 234 } | |
| 230 return channel_multiplexer_.get(); | 235 return channel_multiplexer_.get(); |
| 231 } | 236 } |
| 232 | 237 |
| 233 void JingleSession::Close() { | 238 void JingleSession::Close() { |
| 234 DCHECK(CalledOnValidThread()); | 239 DCHECK(CalledOnValidThread()); |
| 235 | 240 |
| 236 CloseInternal(OK); | 241 CloseInternal(OK); |
| 237 } | 242 } |
| 238 | 243 |
| 239 void JingleSession::AddPendingRemoteCandidates(Transport* channel, | 244 void JingleSession::AddPendingRemoteCandidates(Transport* channel, |
| 240 const std::string& name) { | 245 const std::string& name) { |
| 241 std::list<JingleMessage::NamedCandidate>::iterator it = | 246 std::list<JingleMessage::NamedCandidate>::iterator it = |
| 242 pending_remote_candidates_.begin(); | 247 pending_remote_candidates_.begin(); |
| 243 while(it != pending_remote_candidates_.end()) { | 248 while(it != pending_remote_candidates_.end()) { |
| 244 if (it->name == name) { | 249 if (it->name == name) { |
| 245 channel->AddRemoteCandidate(it->candidate); | 250 channel->AddRemoteCandidate(it->candidate); |
| 246 it = pending_remote_candidates_.erase(it); | 251 it = pending_remote_candidates_.erase(it); |
| 247 } else { | 252 } else { |
| 248 ++it; | 253 ++it; |
| 249 } | 254 } |
| 250 } | 255 } |
| 251 } | 256 } |
| 252 | 257 |
| 253 void JingleSession::CreateChannel(const std::string& name, | 258 void JingleSession::CreateChannel(const std::string& name, |
| 254 const ChannelCreatedCallback& callback) { | 259 const ChannelCreatedCallback& callback) { |
| 255 DCHECK(!channels_[name]); | 260 DCHECK(!channels_[name]); |
| 256 | 261 |
| 257 scoped_ptr<ChannelAuthenticator> channel_authenticator = | 262 scoped_ptr<Transport> channel = |
| 258 authenticator_->CreateChannelAuthenticator(); | 263 session_manager_->transport_factory_->CreateTransport(); |
| 259 scoped_ptr<StreamTransport> channel = | 264 channel->Initialize(name, this); |
| 260 session_manager_->transport_factory_->CreateStreamTransport(); | |
| 261 channel->Initialize(name, this, channel_authenticator.Pass()); | |
| 262 channel->Connect(callback); | 265 channel->Connect(callback); |
| 263 AddPendingRemoteCandidates(channel.get(), name); | 266 AddPendingRemoteCandidates(channel.get(), name); |
| 264 channels_[name] = channel.release(); | 267 channels_[name] = channel.release(); |
| 265 } | 268 } |
| 266 | 269 |
| 267 void JingleSession::CancelChannelCreation(const std::string& name) { | 270 void JingleSession::CancelChannelCreation(const std::string& name) { |
| 268 ChannelsMap::iterator it = channels_.find(name); | 271 ChannelsMap::iterator it = channels_.find(name); |
| 269 if (it != channels_.end() && !it->second->is_connected()) { | 272 if (it != channels_.end() && !it->second->is_connected()) { |
| 270 delete it->second; | 273 delete it->second; |
| 271 DCHECK(!channels_[name]); | 274 DCHECK(!channels_[name]); |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 591 base::Bind(&JingleSession::ContinueAuthenticationStep, | 594 base::Bind(&JingleSession::ContinueAuthenticationStep, |
| 592 weak_factory_.GetWeakPtr())); | 595 weak_factory_.GetWeakPtr())); |
| 593 | 596 |
| 594 if (authenticator_->started()) { | 597 if (authenticator_->started()) { |
| 595 SetState(AUTHENTICATING); | 598 SetState(AUTHENTICATING); |
| 596 } | 599 } |
| 597 } | 600 } |
| 598 | 601 |
| 599 void JingleSession::ContinueAuthenticationStep() { | 602 void JingleSession::ContinueAuthenticationStep() { |
| 600 if (authenticator_->state() == Authenticator::ACCEPTED) { | 603 if (authenticator_->state() == Authenticator::ACCEPTED) { |
| 601 SetState(AUTHENTICATED); | 604 OnAuthenticated(); |
| 602 } else if (authenticator_->state() == Authenticator::REJECTED) { | 605 } else if (authenticator_->state() == Authenticator::REJECTED) { |
| 603 CloseInternal(AuthRejectionReasonToErrorCode( | 606 CloseInternal(AuthRejectionReasonToErrorCode( |
| 604 authenticator_->rejection_reason())); | 607 authenticator_->rejection_reason())); |
| 605 } | 608 } |
| 606 } | 609 } |
| 607 | 610 |
| 611 void JingleSession::OnAuthenticated() { | |
| 612 pseudotcp_channel_factory_.reset(new PseudoTcpChannelFactory(this)); | |
| 613 authenticated_channel_factory_.reset(new AuthenticatedChannelFactory( | |
| 614 pseudotcp_channel_factory_.get(), authenticator_.get())); | |
|
Wez
2014/09/10 02:29:26
nit: Although it's an extra line, I'd suggest wrap
Sergey Ulanov
2014/09/10 21:50:58
Done.
| |
| 615 | |
| 616 SetState(AUTHENTICATED); | |
| 617 } | |
| 618 | |
| 608 void JingleSession::CloseInternal(ErrorCode error) { | 619 void JingleSession::CloseInternal(ErrorCode error) { |
| 609 DCHECK(CalledOnValidThread()); | 620 DCHECK(CalledOnValidThread()); |
| 610 | 621 |
| 611 if (is_session_active()) { | 622 if (is_session_active()) { |
| 612 // Send session-terminate message with the appropriate error code. | 623 // Send session-terminate message with the appropriate error code. |
| 613 JingleMessage::Reason reason; | 624 JingleMessage::Reason reason; |
| 614 switch (error) { | 625 switch (error) { |
| 615 case OK: | 626 case OK: |
| 616 reason = JingleMessage::SUCCESS; | 627 reason = JingleMessage::SUCCESS; |
| 617 break; | 628 break; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 659 } | 670 } |
| 660 } | 671 } |
| 661 | 672 |
| 662 bool JingleSession::is_session_active() { | 673 bool JingleSession::is_session_active() { |
| 663 return state_ == CONNECTING || state_ == ACCEPTING || state_ == CONNECTED || | 674 return state_ == CONNECTING || state_ == ACCEPTING || state_ == CONNECTED || |
| 664 state_ == AUTHENTICATING || state_ == AUTHENTICATED; | 675 state_ == AUTHENTICATING || state_ == AUTHENTICATED; |
| 665 } | 676 } |
| 666 | 677 |
| 667 } // namespace protocol | 678 } // namespace protocol |
| 668 } // namespace remoting | 679 } // namespace remoting |
| OLD | NEW |