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 DCHECK(!callback.is_null()); | |
Sergey Ulanov
2012/01/23 20:33:37
I don't think we need this DCHECK. The caller may
Lambros
2012/01/24 19:50:50
Done.
| |
143 route_change_callback_ = callback; | |
144 } | |
145 | |
135 Session::Error JingleSession::error() { | 146 Session::Error JingleSession::error() { |
136 DCHECK(CalledOnValidThread()); | 147 DCHECK(CalledOnValidThread()); |
137 return error_; | 148 return error_; |
138 } | 149 } |
139 | 150 |
140 void JingleSession::CreateStreamChannel( | 151 void JingleSession::CreateStreamChannel( |
141 const std::string& name, const StreamChannelCallback& callback) { | 152 const std::string& name, const StreamChannelCallback& callback) { |
142 DCHECK(CalledOnValidThread()); | 153 DCHECK(CalledOnValidThread()); |
143 | 154 |
144 AddChannelConnector( | 155 AddChannelConnector( |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
459 } | 470 } |
460 | 471 |
461 void JingleSession::AddChannelConnector( | 472 void JingleSession::AddChannelConnector( |
462 const std::string& name, JingleChannelConnector* connector) { | 473 const std::string& name, JingleChannelConnector* connector) { |
463 DCHECK(channel_connectors_.find(name) == channel_connectors_.end()); | 474 DCHECK(channel_connectors_.find(name) == channel_connectors_.end()); |
464 | 475 |
465 const std::string& content_name = GetContentInfo()->name; | 476 const std::string& content_name = GetContentInfo()->name; |
466 cricket::TransportChannel* raw_channel = | 477 cricket::TransportChannel* raw_channel = |
467 cricket_session_->CreateChannel(content_name, name); | 478 cricket_session_->CreateChannel(content_name, name); |
468 | 479 |
480 raw_channel->SignalRouteChange.connect(this, &JingleSession::OnRouteChange); | |
481 | |
469 if (!jingle_session_manager_->allow_nat_traversal_ && | 482 if (!jingle_session_manager_->allow_nat_traversal_ && |
470 !cricket_session_->initiator()) { | 483 !cricket_session_->initiator()) { |
471 // Don't make outgoing connections from the host to client when | 484 // Don't make outgoing connections from the host to client when |
472 // NAT traversal is disabled. | 485 // NAT traversal is disabled. |
473 raw_channel->GetP2PChannel()->set_incoming_only(true); | 486 raw_channel->GetP2PChannel()->set_incoming_only(true); |
474 } | 487 } |
475 | 488 |
476 channel_connectors_[name] = connector; | 489 channel_connectors_[name] = connector; |
477 scoped_ptr<ChannelAuthenticator> authenticator = | 490 scoped_ptr<ChannelAuthenticator> authenticator = |
478 authenticator_->CreateChannelAuthenticator(); | 491 authenticator_->CreateChannelAuthenticator(); |
479 connector->Connect(authenticator.Pass(), raw_channel); | 492 connector->Connect(authenticator.Pass(), raw_channel); |
480 | 493 |
481 // Workaround bug in libjingle - it doesn't connect channels if they | 494 // Workaround bug in libjingle - it doesn't connect channels if they |
482 // are created after the session is accepted. See crbug.com/89384. | 495 // are created after the session is accepted. See crbug.com/89384. |
483 // TODO(sergeyu): Fix the bug and remove this line. | 496 // TODO(sergeyu): Fix the bug and remove this line. |
484 cricket_session_->GetTransport(content_name)->ConnectChannels(); | 497 cricket_session_->GetTransport(content_name)->ConnectChannels(); |
485 } | 498 } |
486 | 499 |
487 void JingleSession::OnChannelConnectorFinished( | 500 void JingleSession::OnChannelConnectorFinished( |
488 const std::string& name, JingleChannelConnector* connector) { | 501 const std::string& name, JingleChannelConnector* connector) { |
489 DCHECK(CalledOnValidThread()); | 502 DCHECK(CalledOnValidThread()); |
490 DCHECK_EQ(channel_connectors_[name], connector); | 503 DCHECK_EQ(channel_connectors_[name], connector); |
491 channel_connectors_.erase(name); | 504 channel_connectors_.erase(name); |
492 } | 505 } |
493 | 506 |
507 void JingleSession::OnRouteChange(cricket::TransportChannel* channel, | |
508 const cricket::Candidate& candidate) { | |
509 net::IPEndPoint end_point; | |
510 if (!jingle_glue::SocketAddressToIPEndPoint(candidate.address(), | |
511 &end_point)) { | |
512 NOTREACHED(); | |
513 return; | |
514 } | |
515 | |
516 if (!route_change_callback_.is_null()) | |
517 route_change_callback_.Run(channel->name(), end_point); | |
518 } | |
519 | |
494 const cricket::ContentInfo* JingleSession::GetContentInfo() const { | 520 const cricket::ContentInfo* JingleSession::GetContentInfo() const { |
495 const cricket::SessionDescription* session_description; | 521 const cricket::SessionDescription* session_description; |
496 // If we initiate the session, we get to specify the content name. When | 522 // If we initiate the session, we get to specify the content name. When |
497 // accepting one, the remote end specifies it. | 523 // accepting one, the remote end specifies it. |
498 if (cricket_session_->initiator()) { | 524 if (cricket_session_->initiator()) { |
499 session_description = cricket_session_->local_description(); | 525 session_description = cricket_session_->local_description(); |
500 } else { | 526 } else { |
501 session_description = cricket_session_->remote_description(); | 527 session_description = cricket_session_->remote_description(); |
502 } | 528 } |
503 const cricket::ContentInfo* content = | 529 const cricket::ContentInfo* content = |
(...skipping 22 matching lines...) Expand all Loading... | |
526 scoped_ptr<cricket::SessionDescription> desc( | 552 scoped_ptr<cricket::SessionDescription> desc( |
527 new cricket::SessionDescription()); | 553 new cricket::SessionDescription()); |
528 desc->AddContent( | 554 desc->AddContent( |
529 ContentDescription::kChromotingContentName, kChromotingXmlNamespace, | 555 ContentDescription::kChromotingContentName, kChromotingXmlNamespace, |
530 new ContentDescription(config.Pass(), authenticator_message.Pass())); | 556 new ContentDescription(config.Pass(), authenticator_message.Pass())); |
531 return desc.Pass(); | 557 return desc.Pass(); |
532 } | 558 } |
533 | 559 |
534 } // namespace protocol | 560 } // namespace protocol |
535 } // namespace remoting | 561 } // namespace remoting |
OLD | NEW |