OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/base64.h" | 7 #include "base/base64.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" |
10 #include "base/message_loop_proxy.h" | 11 #include "base/message_loop_proxy.h" |
11 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
12 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
13 #include "crypto/hmac.h" | 14 #include "crypto/hmac.h" |
| 15 #include "jingle/glue/utils.h" |
| 16 #include "net/base/ip_endpoint.h" |
14 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
| 18 #include "net/base/net_util.h" |
15 #include "net/socket/stream_socket.h" | 19 #include "net/socket/stream_socket.h" |
16 #include "remoting/base/constants.h" | 20 #include "remoting/base/constants.h" |
17 #include "remoting/protocol/auth_util.h" | 21 #include "remoting/protocol/auth_util.h" |
18 #include "remoting/protocol/authenticator.h" | 22 #include "remoting/protocol/authenticator.h" |
19 #include "remoting/protocol/channel_authenticator.h" | 23 #include "remoting/protocol/channel_authenticator.h" |
20 #include "remoting/protocol/jingle_datagram_connector.h" | 24 #include "remoting/protocol/jingle_datagram_connector.h" |
21 #include "remoting/protocol/jingle_session_manager.h" | 25 #include "remoting/protocol/jingle_session_manager.h" |
22 #include "remoting/protocol/jingle_stream_connector.h" | 26 #include "remoting/protocol/jingle_stream_connector.h" |
23 #include "third_party/libjingle/source/talk/base/thread.h" | 27 #include "third_party/libjingle/source/talk/base/thread.h" |
24 #include "third_party/libjingle/source/talk/p2p/base/p2ptransportchannel.h" | 28 #include "third_party/libjingle/source/talk/p2p/base/p2ptransportchannel.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 return session; | 129 return session; |
126 } | 130 } |
127 | 131 |
128 void JingleSession::SetStateChangeCallback( | 132 void JingleSession::SetStateChangeCallback( |
129 const StateChangeCallback& callback) { | 133 const StateChangeCallback& callback) { |
130 DCHECK(CalledOnValidThread()); | 134 DCHECK(CalledOnValidThread()); |
131 DCHECK(!callback.is_null()); | 135 DCHECK(!callback.is_null()); |
132 state_change_callback_ = callback; | 136 state_change_callback_ = callback; |
133 } | 137 } |
134 | 138 |
| 139 void JingleSession::SetRouteChangeCallback( |
| 140 const RouteChangeCallback& callback) { |
| 141 DCHECK(CalledOnValidThread()); |
| 142 route_change_callback_ = callback; |
| 143 } |
| 144 |
135 Session::Error JingleSession::error() { | 145 Session::Error JingleSession::error() { |
136 DCHECK(CalledOnValidThread()); | 146 DCHECK(CalledOnValidThread()); |
137 return error_; | 147 return error_; |
138 } | 148 } |
139 | 149 |
140 void JingleSession::CreateStreamChannel( | 150 void JingleSession::CreateStreamChannel( |
141 const std::string& name, const StreamChannelCallback& callback) { | 151 const std::string& name, const StreamChannelCallback& callback) { |
142 DCHECK(CalledOnValidThread()); | 152 DCHECK(CalledOnValidThread()); |
143 | 153 |
144 AddChannelConnector( | 154 AddChannelConnector( |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 } | 469 } |
460 | 470 |
461 void JingleSession::AddChannelConnector( | 471 void JingleSession::AddChannelConnector( |
462 const std::string& name, JingleChannelConnector* connector) { | 472 const std::string& name, JingleChannelConnector* connector) { |
463 DCHECK(channel_connectors_.find(name) == channel_connectors_.end()); | 473 DCHECK(channel_connectors_.find(name) == channel_connectors_.end()); |
464 | 474 |
465 const std::string& content_name = GetContentInfo()->name; | 475 const std::string& content_name = GetContentInfo()->name; |
466 cricket::TransportChannel* raw_channel = | 476 cricket::TransportChannel* raw_channel = |
467 cricket_session_->CreateChannel(content_name, name); | 477 cricket_session_->CreateChannel(content_name, name); |
468 | 478 |
| 479 raw_channel->SignalRouteChange.connect(this, &JingleSession::OnRouteChange); |
| 480 |
469 if (!jingle_session_manager_->allow_nat_traversal_ && | 481 if (!jingle_session_manager_->allow_nat_traversal_ && |
470 !cricket_session_->initiator()) { | 482 !cricket_session_->initiator()) { |
471 // Don't make outgoing connections from the host to client when | 483 // Don't make outgoing connections from the host to client when |
472 // NAT traversal is disabled. | 484 // NAT traversal is disabled. |
473 raw_channel->GetP2PChannel()->set_incoming_only(true); | 485 raw_channel->GetP2PChannel()->set_incoming_only(true); |
474 } | 486 } |
475 | 487 |
476 channel_connectors_[name] = connector; | 488 channel_connectors_[name] = connector; |
477 scoped_ptr<ChannelAuthenticator> authenticator = | 489 scoped_ptr<ChannelAuthenticator> authenticator = |
478 authenticator_->CreateChannelAuthenticator(); | 490 authenticator_->CreateChannelAuthenticator(); |
479 connector->Connect(authenticator.Pass(), raw_channel); | 491 connector->Connect(authenticator.Pass(), raw_channel); |
480 | 492 |
481 // Workaround bug in libjingle - it doesn't connect channels if they | 493 // Workaround bug in libjingle - it doesn't connect channels if they |
482 // are created after the session is accepted. See crbug.com/89384. | 494 // are created after the session is accepted. See crbug.com/89384. |
483 // TODO(sergeyu): Fix the bug and remove this line. | 495 // TODO(sergeyu): Fix the bug and remove this line. |
484 cricket_session_->GetTransport(content_name)->ConnectChannels(); | 496 cricket_session_->GetTransport(content_name)->ConnectChannels(); |
485 } | 497 } |
486 | 498 |
487 void JingleSession::OnChannelConnectorFinished( | 499 void JingleSession::OnChannelConnectorFinished( |
488 const std::string& name, JingleChannelConnector* connector) { | 500 const std::string& name, JingleChannelConnector* connector) { |
489 DCHECK(CalledOnValidThread()); | 501 DCHECK(CalledOnValidThread()); |
490 DCHECK_EQ(channel_connectors_[name], connector); | 502 DCHECK_EQ(channel_connectors_[name], connector); |
491 channel_connectors_.erase(name); | 503 channel_connectors_.erase(name); |
492 } | 504 } |
493 | 505 |
| 506 void JingleSession::OnRouteChange(cricket::TransportChannel* channel, |
| 507 const cricket::Candidate& candidate) { |
| 508 net::IPEndPoint end_point; |
| 509 if (!jingle_glue::SocketAddressToIPEndPoint(candidate.address(), |
| 510 &end_point)) { |
| 511 NOTREACHED(); |
| 512 return; |
| 513 } |
| 514 |
| 515 if (!route_change_callback_.is_null()) |
| 516 route_change_callback_.Run(channel->name(), end_point); |
| 517 } |
| 518 |
494 const cricket::ContentInfo* JingleSession::GetContentInfo() const { | 519 const cricket::ContentInfo* JingleSession::GetContentInfo() const { |
495 const cricket::SessionDescription* session_description; | 520 const cricket::SessionDescription* session_description; |
496 // If we initiate the session, we get to specify the content name. When | 521 // If we initiate the session, we get to specify the content name. When |
497 // accepting one, the remote end specifies it. | 522 // accepting one, the remote end specifies it. |
498 if (cricket_session_->initiator()) { | 523 if (cricket_session_->initiator()) { |
499 session_description = cricket_session_->local_description(); | 524 session_description = cricket_session_->local_description(); |
500 } else { | 525 } else { |
501 session_description = cricket_session_->remote_description(); | 526 session_description = cricket_session_->remote_description(); |
502 } | 527 } |
503 const cricket::ContentInfo* content = | 528 const cricket::ContentInfo* content = |
(...skipping 22 matching lines...) Expand all Loading... |
526 scoped_ptr<cricket::SessionDescription> desc( | 551 scoped_ptr<cricket::SessionDescription> desc( |
527 new cricket::SessionDescription()); | 552 new cricket::SessionDescription()); |
528 desc->AddContent( | 553 desc->AddContent( |
529 ContentDescription::kChromotingContentName, kChromotingXmlNamespace, | 554 ContentDescription::kChromotingContentName, kChromotingXmlNamespace, |
530 new ContentDescription(config.Pass(), authenticator_message.Pass())); | 555 new ContentDescription(config.Pass(), authenticator_message.Pass())); |
531 return desc.Pass(); | 556 return desc.Pass(); |
532 } | 557 } |
533 | 558 |
534 } // namespace protocol | 559 } // namespace protocol |
535 } // namespace remoting | 560 } // namespace remoting |
OLD | NEW |