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/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 auth_message.Pass())); | 174 auth_message.Pass())); |
175 SendMessage(message); | 175 SendMessage(message); |
176 | 176 |
177 // Update state. | 177 // Update state. |
178 SetState(CONNECTED); | 178 SetState(CONNECTED); |
179 | 179 |
180 if (authenticator_->state() == Authenticator::ACCEPTED) { | 180 if (authenticator_->state() == Authenticator::ACCEPTED) { |
181 SetState(AUTHENTICATED); | 181 SetState(AUTHENTICATED); |
182 } else { | 182 } else { |
183 DCHECK_EQ(authenticator_->state(), Authenticator::WAITING_MESSAGE); | 183 DCHECK_EQ(authenticator_->state(), Authenticator::WAITING_MESSAGE); |
184 if (authenticator_->started()) { | |
rmsousa
2014/03/26 21:37:35
Do we want to ensure that we pass through the AUTH
kelvinp
2014/03/27 03:23:21
After talking to Sergey, I think we can allow swit
| |
185 SetState(AUTHENTICATING); | |
186 } | |
184 } | 187 } |
185 | 188 |
186 return; | 189 return; |
Sergey Ulanov
2014/03/26 01:49:16
while you are here, please remove this line
kelvinp
2014/03/27 03:23:21
Done.
| |
187 } | 190 } |
188 | 191 |
189 const std::string& JingleSession::jid() { | 192 const std::string& JingleSession::jid() { |
190 DCHECK(CalledOnValidThread()); | 193 DCHECK(CalledOnValidThread()); |
191 return peer_jid_; | 194 return peer_jid_; |
192 } | 195 } |
193 | 196 |
194 const CandidateSessionConfig* JingleSession::candidate_config() { | 197 const CandidateSessionConfig* JingleSession::candidate_config() { |
195 DCHECK(CalledOnValidThread()); | 198 DCHECK(CalledOnValidThread()); |
196 return candidate_config_.get(); | 199 return candidate_config_.get(); |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
478 } | 481 } |
479 | 482 |
480 void JingleSession::OnSessionInfo(const JingleMessage& message, | 483 void JingleSession::OnSessionInfo(const JingleMessage& message, |
481 const ReplyCallback& reply_callback) { | 484 const ReplyCallback& reply_callback) { |
482 if (!message.info.get() || | 485 if (!message.info.get() || |
483 !Authenticator::IsAuthenticatorMessage(message.info.get())) { | 486 !Authenticator::IsAuthenticatorMessage(message.info.get())) { |
484 reply_callback.Run(JingleMessageReply::UNSUPPORTED_INFO); | 487 reply_callback.Run(JingleMessageReply::UNSUPPORTED_INFO); |
485 return; | 488 return; |
486 } | 489 } |
487 | 490 |
488 if (state_ != CONNECTED || | 491 if ((state_ != CONNECTED && state_ != AUTHENTICATING) || |
489 authenticator_->state() != Authenticator::WAITING_MESSAGE) { | 492 authenticator_->state() != Authenticator::WAITING_MESSAGE) { |
490 LOG(WARNING) << "Received unexpected authenticator message " | 493 LOG(WARNING) << "Received unexpected authenticator message " |
491 << message.info->Str(); | 494 << message.info->Str(); |
492 reply_callback.Run(JingleMessageReply::UNEXPECTED_REQUEST); | 495 reply_callback.Run(JingleMessageReply::UNEXPECTED_REQUEST); |
493 CloseInternal(INCOMPATIBLE_PROTOCOL); | 496 CloseInternal(INCOMPATIBLE_PROTOCOL); |
494 return; | 497 return; |
495 } | 498 } |
496 | 499 |
497 reply_callback.Run(JingleMessageReply::NONE); | 500 reply_callback.Run(JingleMessageReply::NONE); |
498 | 501 |
(...skipping 12 matching lines...) Expand all Loading... | |
511 // Transport info was received before the channel was created. | 514 // Transport info was received before the channel was created. |
512 // This could happen due to messages being reordered on the wire. | 515 // This could happen due to messages being reordered on the wire. |
513 pending_remote_candidates_.push_back(*it); | 516 pending_remote_candidates_.push_back(*it); |
514 } | 517 } |
515 } | 518 } |
516 } | 519 } |
517 | 520 |
518 void JingleSession::OnTerminate(const JingleMessage& message, | 521 void JingleSession::OnTerminate(const JingleMessage& message, |
519 const ReplyCallback& reply_callback) { | 522 const ReplyCallback& reply_callback) { |
520 if (state_ != CONNECTING && state_ != ACCEPTING && state_ != CONNECTED && | 523 if (state_ != CONNECTING && state_ != ACCEPTING && state_ != CONNECTED && |
521 state_ != AUTHENTICATED) { | 524 state_ != AUTHENTICATING && state_ != AUTHENTICATED) { |
522 LOG(WARNING) << "Received unexpected session-terminate message."; | 525 LOG(WARNING) << "Received unexpected session-terminate message."; |
523 reply_callback.Run(JingleMessageReply::UNEXPECTED_REQUEST); | 526 reply_callback.Run(JingleMessageReply::UNEXPECTED_REQUEST); |
524 return; | 527 return; |
525 } | 528 } |
526 | 529 |
527 reply_callback.Run(JingleMessageReply::NONE); | 530 reply_callback.Run(JingleMessageReply::NONE); |
528 | 531 |
529 switch (message.reason) { | 532 switch (message.reason) { |
530 case JingleMessage::SUCCESS: | 533 case JingleMessage::SUCCESS: |
531 if (state_ == CONNECTING) { | 534 if (state_ == CONNECTING) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
570 return false; | 573 return false; |
571 } | 574 } |
572 | 575 |
573 return true; | 576 return true; |
574 } | 577 } |
575 | 578 |
576 void JingleSession::ProcessAuthenticationStep() { | 579 void JingleSession::ProcessAuthenticationStep() { |
577 DCHECK(CalledOnValidThread()); | 580 DCHECK(CalledOnValidThread()); |
578 DCHECK_NE(authenticator_->state(), Authenticator::PROCESSING_MESSAGE); | 581 DCHECK_NE(authenticator_->state(), Authenticator::PROCESSING_MESSAGE); |
579 | 582 |
580 if (state_ != CONNECTED) { | 583 if (state_ != CONNECTED && state_ != AUTHENTICATING) { |
581 DCHECK(state_ == FAILED || state_ == CLOSED); | 584 DCHECK(state_ == FAILED || state_ == CLOSED); |
582 // The remote host closed the connection while the authentication was being | 585 // The remote host closed the connection while the authentication was being |
583 // processed asynchronously, nothing to do. | 586 // processed asynchronously, nothing to do. |
584 return; | 587 return; |
585 } | 588 } |
586 | 589 |
590 if (authenticator_->started()) { | |
rmsousa
2014/03/26 21:37:35
authenticator may set the started bit in GetNextMe
Sergey Ulanov
2014/03/27 00:00:03
+1 I think it should be an else-if case in the end
kelvinp
2014/03/27 03:23:21
Done.
kelvinp
2014/03/27 03:23:21
Done.
| |
591 SetState(AUTHENTICATING); | |
Sergey Ulanov
2014/03/26 01:49:16
nit: 2-space indent relative to if
kelvinp
2014/03/27 03:23:21
My bad. Fixed
Done.
| |
592 } | |
593 | |
587 if (authenticator_->state() == Authenticator::MESSAGE_READY) { | 594 if (authenticator_->state() == Authenticator::MESSAGE_READY) { |
588 JingleMessage message(peer_jid_, JingleMessage::SESSION_INFO, session_id_); | 595 JingleMessage message(peer_jid_, JingleMessage::SESSION_INFO, session_id_); |
589 message.info = authenticator_->GetNextMessage(); | 596 message.info = authenticator_->GetNextMessage(); |
590 DCHECK(message.info.get()); | 597 DCHECK(message.info.get()); |
591 SendMessage(message); | 598 SendMessage(message); |
592 } | 599 } |
593 DCHECK_NE(authenticator_->state(), Authenticator::MESSAGE_READY); | 600 DCHECK_NE(authenticator_->state(), Authenticator::MESSAGE_READY); |
594 | 601 |
595 if (authenticator_->state() == Authenticator::ACCEPTED) { | 602 if (authenticator_->state() == Authenticator::ACCEPTED) { |
596 SetState(AUTHENTICATED); | 603 SetState(AUTHENTICATED); |
597 } else if (authenticator_->state() == Authenticator::REJECTED) { | 604 } else if (authenticator_->state() == Authenticator::REJECTED) { |
598 CloseInternal(AuthRejectionReasonToErrorCode( | 605 CloseInternal(AuthRejectionReasonToErrorCode( |
599 authenticator_->rejection_reason())); | 606 authenticator_->rejection_reason())); |
600 } | 607 } |
601 } | 608 } |
602 | 609 |
603 void JingleSession::CloseInternal(ErrorCode error) { | 610 void JingleSession::CloseInternal(ErrorCode error) { |
604 DCHECK(CalledOnValidThread()); | 611 DCHECK(CalledOnValidThread()); |
605 | 612 |
606 if (state_ == CONNECTING || state_ == ACCEPTING || state_ == CONNECTED || | 613 if (state_ == CONNECTING || state_ == ACCEPTING || state_ == CONNECTED || |
607 state_ == AUTHENTICATED) { | 614 state_ == AUTHENTICATING || state_ == AUTHENTICATED) { |
Sergey Ulanov
2014/03/26 01:49:16
this is duplicated in OnTerminate(). Maybe add is_
kelvinp
2014/03/27 03:23:21
Good Idea. Done.
| |
608 // Send session-terminate message with the appropriate error code. | 615 // Send session-terminate message with the appropriate error code. |
609 JingleMessage::Reason reason; | 616 JingleMessage::Reason reason; |
610 switch (error) { | 617 switch (error) { |
611 case OK: | 618 case OK: |
612 reason = JingleMessage::SUCCESS; | 619 reason = JingleMessage::SUCCESS; |
613 break; | 620 break; |
614 case SESSION_REJECTED: | 621 case SESSION_REJECTED: |
615 case AUTHENTICATION_FAILED: | 622 case AUTHENTICATION_FAILED: |
616 reason = JingleMessage::DECLINE; | 623 reason = JingleMessage::DECLINE; |
617 break; | 624 break; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
650 DCHECK_NE(state_, FAILED); | 657 DCHECK_NE(state_, FAILED); |
651 | 658 |
652 state_ = new_state; | 659 state_ = new_state; |
653 if (event_handler_) | 660 if (event_handler_) |
654 event_handler_->OnSessionStateChange(new_state); | 661 event_handler_->OnSessionStateChange(new_state); |
655 } | 662 } |
656 } | 663 } |
657 | 664 |
658 } // namespace protocol | 665 } // namespace protocol |
659 } // namespace remoting | 666 } // namespace remoting |
OLD | NEW |