Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: remoting/protocol/jingle_session.cc

Issue 551173004: Move PseudoTCP and channel auth out of LibjingleTransportFactory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@clean_dgrams
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
22 #include "remoting/protocol/secure_channel_factory.h"
21 #include "remoting/protocol/session_config.h" 23 #include "remoting/protocol/session_config.h"
24 #include "remoting/protocol/stream_channel_factory.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/webrtc/libjingle/xmllite/xmlelement.h" 27 #include "third_party/webrtc/libjingle/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
31 namespace { 34 namespace {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 config_is_set_(false), 77 config_is_set_(false),
75 weak_factory_(this) { 78 weak_factory_(this) {
76 } 79 }
77 80
78 JingleSession::~JingleSession() { 81 JingleSession::~JingleSession() {
79 channel_multiplexer_.reset(); 82 channel_multiplexer_.reset();
80 STLDeleteContainerPointers(pending_requests_.begin(), 83 STLDeleteContainerPointers(pending_requests_.begin(),
81 pending_requests_.end()); 84 pending_requests_.end());
82 STLDeleteContainerPointers(transport_info_requests_.begin(), 85 STLDeleteContainerPointers(transport_info_requests_.begin(),
83 transport_info_requests_.end()); 86 transport_info_requests_.end());
84 STLDeleteContainerPairSecondPointers(channels_.begin(), channels_.end()); 87 DCHECK(channels_.empty());
85 session_manager_->SessionDestroyed(this); 88 session_manager_->SessionDestroyed(this);
86 } 89 }
87 90
88 void JingleSession::SetEventHandler(Session::EventHandler* event_handler) { 91 void JingleSession::SetEventHandler(Session::EventHandler* event_handler) {
89 DCHECK(CalledOnValidThread()); 92 DCHECK(CalledOnValidThread());
90 DCHECK(event_handler); 93 DCHECK(event_handler);
91 event_handler_ = event_handler; 94 event_handler_ = event_handler;
92 } 95 }
93 96
94 ErrorCode JingleSession::error() { 97 ErrorCode JingleSession::error() {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 10 matching lines...) Expand all
211 return config_; 214 return config_;
212 } 215 }
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 StreamChannelFactory* JingleSession::GetTransportChannelFactory() {
222 DCHECK(CalledOnValidThread()); 225 DCHECK(CalledOnValidThread());
223 return this; 226 return secure_channel_factory_.get();
224 } 227 }
225 228
226 ChannelFactory* JingleSession::GetMultiplexedChannelFactory() { 229 StreamChannelFactory* 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->Connect(name, this, callback);
260 session_manager_->transport_factory_->CreateStreamTransport();
261 channel->Initialize(name, this, channel_authenticator.Pass());
262 channel->Connect(callback);
263 AddPendingRemoteCandidates(channel.get(), name); 265 AddPendingRemoteCandidates(channel.get(), name);
264 channels_[name] = channel.release(); 266 channels_[name] = channel.release();
265 } 267 }
266 268
267 void JingleSession::CancelChannelCreation(const std::string& name) { 269 void JingleSession::CancelChannelCreation(const std::string& name) {
268 ChannelsMap::iterator it = channels_.find(name); 270 ChannelsMap::iterator it = channels_.find(name);
269 if (it != channels_.end() && !it->second->is_connected()) { 271 if (it != channels_.end()) {
272 DCHECK(!it->second->is_connected());
Wez 2014/09/10 22:19:42 Is there any possibility of a race condition here,
Sergey Ulanov 2014/09/10 22:49:31 I don't think so. Both events happen on the same t
270 delete it->second; 273 delete it->second;
271 DCHECK(!channels_[name]); 274 DCHECK(!channels_[name]);
272 } 275 }
273 } 276 }
274 277
275 void JingleSession::OnTransportCandidate(Transport* transport, 278 void JingleSession::OnTransportCandidate(Transport* transport,
276 const cricket::Candidate& candidate) { 279 const cricket::Candidate& candidate) {
277 pending_candidates_.push_back(JingleMessage::NamedCandidate( 280 pending_candidates_.push_back(JingleMessage::NamedCandidate(
278 transport->name(), candidate)); 281 transport->name(), candidate));
279 282
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 secure_channel_factory_.reset(
614 new SecureChannelFactory(pseudotcp_channel_factory_.get(),
615 authenticator_.get()));
616
617 SetState(AUTHENTICATED);
618 }
619
608 void JingleSession::CloseInternal(ErrorCode error) { 620 void JingleSession::CloseInternal(ErrorCode error) {
609 DCHECK(CalledOnValidThread()); 621 DCHECK(CalledOnValidThread());
610 622
611 if (is_session_active()) { 623 if (is_session_active()) {
612 // Send session-terminate message with the appropriate error code. 624 // Send session-terminate message with the appropriate error code.
613 JingleMessage::Reason reason; 625 JingleMessage::Reason reason;
614 switch (error) { 626 switch (error) {
615 case OK: 627 case OK:
616 reason = JingleMessage::SUCCESS; 628 reason = JingleMessage::SUCCESS;
617 break; 629 break;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 } 671 }
660 } 672 }
661 673
662 bool JingleSession::is_session_active() { 674 bool JingleSession::is_session_active() {
663 return state_ == CONNECTING || state_ == ACCEPTING || state_ == CONNECTED || 675 return state_ == CONNECTING || state_ == ACCEPTING || state_ == CONNECTED ||
664 state_ == AUTHENTICATING || state_ == AUTHENTICATED; 676 state_ == AUTHENTICATING || state_ == AUTHENTICATED;
665 } 677 }
666 678
667 } // namespace protocol 679 } // namespace protocol
668 } // namespace remoting 680 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698