diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-21 23:23:11 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-21 23:23:11 +0000 |
commit | 0b52323dd1495f40ca5ded51dd02c006cc686340 (patch) | |
tree | 1768b1f50c66a1fe7c66847f5b2bb24d06450860 /remoting/protocol | |
parent | 69ddf85ced1124fd607399e0e341e4d0e0cb857d (diff) | |
download | chromium_src-0b52323dd1495f40ca5ded51dd02c006cc686340.zip chromium_src-0b52323dd1495f40ca5ded51dd02c006cc686340.tar.gz chromium_src-0b52323dd1495f40ca5ded51dd02c006cc686340.tar.bz2 |
Implement support for route change notifications in the Transport interface.
BUG=110485
Review URL: http://codereview.chromium.org/9366001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@122901 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/protocol')
-rw-r--r-- | remoting/protocol/jingle_session.cc | 3 | ||||
-rw-r--r-- | remoting/protocol/libjingle_transport_factory.cc | 37 | ||||
-rw-r--r-- | remoting/protocol/pepper_session.cc | 8 | ||||
-rw-r--r-- | remoting/protocol/pepper_session.h | 2 | ||||
-rw-r--r-- | remoting/protocol/transport.h | 18 |
5 files changed, 67 insertions, 1 deletions
diff --git a/remoting/protocol/jingle_session.cc b/remoting/protocol/jingle_session.cc index 6f856c0..a1123be 100644 --- a/remoting/protocol/jingle_session.cc +++ b/remoting/protocol/jingle_session.cc @@ -525,9 +525,10 @@ void JingleSession::OnRouteChange(cricket::TransportChannel* channel, return; } - if (!route_change_callback_.is_null()) + if (!route_change_callback_.is_null()) { route_change_callback_.Run(channel->name(), remote_end_point, local_end_point); + } } const cricket::ContentInfo* JingleSession::GetContentInfo() const { diff --git a/remoting/protocol/libjingle_transport_factory.cc b/remoting/protocol/libjingle_transport_factory.cc index 17195bd..c2665da 100644 --- a/remoting/protocol/libjingle_transport_factory.cc +++ b/remoting/protocol/libjingle_transport_factory.cc @@ -6,6 +6,7 @@ #include "jingle/glue/channel_socket_adapter.h" #include "jingle/glue/pseudotcp_adapter.h" +#include "jingle/glue/utils.h" #include "net/base/net_errors.h" #include "remoting/protocol/channel_authenticator.h" #include "remoting/protocol/transport_config.h" @@ -51,6 +52,8 @@ class LibjingleStreamTransport : public StreamTransport, void OnRequestSignaling(); void OnCandidateReady(cricket::TransportChannelImpl* channel, const cricket::Candidate& candidate); + void OnRouteChange(cricket::TransportChannel* channel, + const cricket::Candidate& candidate); void OnTcpConnected(int result); void OnAuthenticationDone(net::Error error, @@ -149,6 +152,8 @@ void LibjingleStreamTransport::Connect( this, &LibjingleStreamTransport::OnRequestSignaling); channel_->SignalCandidateReady.connect( this, &LibjingleStreamTransport::OnCandidateReady); + channel_->SignalRouteChange.connect( + this, &LibjingleStreamTransport::OnRouteChange); channel_->Connect(); @@ -201,6 +206,38 @@ void LibjingleStreamTransport::OnCandidateReady( event_handler_->OnTransportCandidate(this, candidate); } +void LibjingleStreamTransport::OnRouteChange( + cricket::TransportChannel* channel, + const cricket::Candidate& candidate) { + TransportRoute route; + + if (candidate.type() == "local") { + route.type = TransportRoute::DIRECT; + } else if (candidate.type() == "stun") { + route.type = TransportRoute::STUN; + } else if (candidate.type() == "relay") { + route.type = TransportRoute::RELAY; + } else { + LOG(FATAL) << "Unknown candidate type: " << candidate.type(); + } + + if (!jingle_glue::SocketAddressToIPEndPoint( + candidate.address(), &route.remote_address)) { + LOG(FATAL) << "Failed to convert peer IP address."; + } + + DCHECK(channel->GetP2PChannel()); + DCHECK(channel->GetP2PChannel()->best_connection()); + const cricket::Candidate& local_candidate = + channel->GetP2PChannel()->best_connection()->local_candidate(); + if (!jingle_glue::SocketAddressToIPEndPoint( + local_candidate.address(), &route.local_address)) { + LOG(FATAL) << "Failed to convert local IP address."; + } + + event_handler_->OnTransportRouteChange(this, route); +} + void LibjingleStreamTransport::OnTcpConnected(int result) { DCHECK(CalledOnValidThread()); diff --git a/remoting/protocol/pepper_session.cc b/remoting/protocol/pepper_session.cc index 09f312a..16b961d 100644 --- a/remoting/protocol/pepper_session.cc +++ b/remoting/protocol/pepper_session.cc @@ -268,6 +268,14 @@ void PepperSession::OnTransportCandidate(Transport* transport, } } +void PepperSession::OnTransportRouteChange(Transport* transport, + const TransportRoute& route) { + if (!route_change_callback_.is_null()) { + route_change_callback_.Run(transport->name(), route.remote_address, + route.local_address); + } +} + void PepperSession::OnTransportDeleted(Transport* transport) { ChannelsMap::iterator it = channels_.find(transport->name()); DCHECK_EQ(it->second, transport); diff --git a/remoting/protocol/pepper_session.h b/remoting/protocol/pepper_session.h index 8fc3248..33cd554 100644 --- a/remoting/protocol/pepper_session.h +++ b/remoting/protocol/pepper_session.h @@ -63,6 +63,8 @@ class PepperSession : public Session, virtual void OnTransportCandidate( Transport* transport, const cricket::Candidate& candidate) OVERRIDE; + virtual void OnTransportRouteChange(Transport* transport, + const TransportRoute& route) OVERRIDE; virtual void OnTransportDeleted(Transport* transport) OVERRIDE; private: diff --git a/remoting/protocol/transport.h b/remoting/protocol/transport.h index 3b4bc2a..e892404 100644 --- a/remoting/protocol/transport.h +++ b/remoting/protocol/transport.h @@ -28,6 +28,7 @@ #include "base/callback_forward.h" #include "base/memory/scoped_ptr.h" #include "base/threading/non_thread_safe.h" +#include "net/base/ip_endpoint.h" namespace cricket { class Candidate; @@ -44,6 +45,18 @@ namespace protocol { class ChannelAuthenticator; struct TransportConfig; +struct TransportRoute { + enum RouteType { + DIRECT, + STUN, + RELAY, + }; + + RouteType type; + net::IPEndPoint remote_address; + net::IPEndPoint local_address; +}; + class Transport : public base::NonThreadSafe { public: class EventHandler { @@ -57,6 +70,11 @@ class Transport : public base::NonThreadSafe { virtual void OnTransportCandidate(Transport* transport, const cricket::Candidate& candidate) = 0; + // Called when transport route changes. Can be called even before + // the transport is connected. + virtual void OnTransportRouteChange(Transport* transport, + const TransportRoute& route) = 0; + // Called when the transport is about to be deleted. virtual void OnTransportDeleted(Transport* transport) = 0; }; |