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

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

Issue 9366001: Implement support for route change notifications in the Transport interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 8 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « remoting/protocol/jingle_session.cc ('k') | remoting/protocol/pepper_session.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/libjingle_transport_factory.h" 5 #include "remoting/protocol/libjingle_transport_factory.h"
6 6
7 #include "jingle/glue/channel_socket_adapter.h" 7 #include "jingle/glue/channel_socket_adapter.h"
8 #include "jingle/glue/pseudotcp_adapter.h" 8 #include "jingle/glue/pseudotcp_adapter.h"
9 #include "jingle/glue/utils.h"
9 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
10 #include "remoting/protocol/channel_authenticator.h" 11 #include "remoting/protocol/channel_authenticator.h"
11 #include "remoting/protocol/transport_config.h" 12 #include "remoting/protocol/transport_config.h"
12 #include "third_party/libjingle/source/talk/base/basicpacketsocketfactory.h" 13 #include "third_party/libjingle/source/talk/base/basicpacketsocketfactory.h"
13 #include "third_party/libjingle/source/talk/base/network.h" 14 #include "third_party/libjingle/source/talk/base/network.h"
14 #include "third_party/libjingle/source/talk/p2p/base/p2ptransportchannel.h" 15 #include "third_party/libjingle/source/talk/p2p/base/p2ptransportchannel.h"
15 #include "third_party/libjingle/source/talk/p2p/client/httpportallocator.h" 16 #include "third_party/libjingle/source/talk/p2p/client/httpportallocator.h"
16 17
17 namespace remoting { 18 namespace remoting {
18 namespace protocol { 19 namespace protocol {
(...skipping 25 matching lines...) Expand all
44 virtual void Connect( 45 virtual void Connect(
45 const StreamTransport::ConnectedCallback& callback) OVERRIDE; 46 const StreamTransport::ConnectedCallback& callback) OVERRIDE;
46 virtual void AddRemoteCandidate(const cricket::Candidate& candidate) OVERRIDE; 47 virtual void AddRemoteCandidate(const cricket::Candidate& candidate) OVERRIDE;
47 virtual const std::string& name() const OVERRIDE; 48 virtual const std::string& name() const OVERRIDE;
48 virtual bool is_connected() const OVERRIDE; 49 virtual bool is_connected() const OVERRIDE;
49 50
50 private: 51 private:
51 void OnRequestSignaling(); 52 void OnRequestSignaling();
52 void OnCandidateReady(cricket::TransportChannelImpl* channel, 53 void OnCandidateReady(cricket::TransportChannelImpl* channel,
53 const cricket::Candidate& candidate); 54 const cricket::Candidate& candidate);
55 void OnRouteChange(cricket::TransportChannel* channel,
56 const cricket::Candidate& candidate);
54 57
55 void OnTcpConnected(int result); 58 void OnTcpConnected(int result);
56 void OnAuthenticationDone(net::Error error, 59 void OnAuthenticationDone(net::Error error,
57 scoped_ptr<net::StreamSocket> socket); 60 scoped_ptr<net::StreamSocket> socket);
58 61
59 void OnChannelDestroyed(); 62 void OnChannelDestroyed();
60 63
61 void NotifyConnected(scoped_ptr<net::StreamSocket> socket); 64 void NotifyConnected(scoped_ptr<net::StreamSocket> socket);
62 void NotifyConnectFailed(); 65 void NotifyConnectFailed();
63 66
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 port_allocator_->SetPortRange(config_.min_port, config_.max_port); 145 port_allocator_->SetPortRange(config_.min_port, config_.max_port);
143 146
144 // Create P2PTransportChannel, attach signal handlers and connect it. 147 // Create P2PTransportChannel, attach signal handlers and connect it.
145 DCHECK(!channel_.get()); 148 DCHECK(!channel_.get());
146 channel_.reset(new cricket::P2PTransportChannel( 149 channel_.reset(new cricket::P2PTransportChannel(
147 name_, "", NULL, port_allocator_.get())); 150 name_, "", NULL, port_allocator_.get()));
148 channel_->SignalRequestSignaling.connect( 151 channel_->SignalRequestSignaling.connect(
149 this, &LibjingleStreamTransport::OnRequestSignaling); 152 this, &LibjingleStreamTransport::OnRequestSignaling);
150 channel_->SignalCandidateReady.connect( 153 channel_->SignalCandidateReady.connect(
151 this, &LibjingleStreamTransport::OnCandidateReady); 154 this, &LibjingleStreamTransport::OnCandidateReady);
155 channel_->SignalRouteChange.connect(
156 this, &LibjingleStreamTransport::OnRouteChange);
152 157
153 channel_->Connect(); 158 channel_->Connect();
154 159
155 // Create net::Socket adapter for the P2PTransportChannel. 160 // Create net::Socket adapter for the P2PTransportChannel.
156 scoped_ptr<jingle_glue::TransportChannelSocketAdapter> channel_adapter( 161 scoped_ptr<jingle_glue::TransportChannelSocketAdapter> channel_adapter(
157 new jingle_glue::TransportChannelSocketAdapter(channel_.get())); 162 new jingle_glue::TransportChannelSocketAdapter(channel_.get()));
158 channel_adapter->SetOnDestroyedCallback(base::Bind( 163 channel_adapter->SetOnDestroyedCallback(base::Bind(
159 &LibjingleStreamTransport::OnChannelDestroyed, base::Unretained(this))); 164 &LibjingleStreamTransport::OnChannelDestroyed, base::Unretained(this)));
160 165
161 // Configure and connect PseudoTCP adapter. 166 // Configure and connect PseudoTCP adapter.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 channel_->OnSignalingReady(); 199 channel_->OnSignalingReady();
195 } 200 }
196 201
197 void LibjingleStreamTransport::OnCandidateReady( 202 void LibjingleStreamTransport::OnCandidateReady(
198 cricket::TransportChannelImpl* channel, 203 cricket::TransportChannelImpl* channel,
199 const cricket::Candidate& candidate) { 204 const cricket::Candidate& candidate) {
200 DCHECK(CalledOnValidThread()); 205 DCHECK(CalledOnValidThread());
201 event_handler_->OnTransportCandidate(this, candidate); 206 event_handler_->OnTransportCandidate(this, candidate);
202 } 207 }
203 208
209 void LibjingleStreamTransport::OnRouteChange(
210 cricket::TransportChannel* channel,
211 const cricket::Candidate& candidate) {
212 TransportRoute route;
213
214 if (candidate.type() == "local") {
215 route.type = TransportRoute::DIRECT;
216 } else if (candidate.type() == "stun") {
217 route.type = TransportRoute::STUN;
218 } else if (candidate.type() == "relay") {
219 route.type = TransportRoute::RELAY;
220 } else {
221 LOG(FATAL) << "Unknown candidate type: " << candidate.type();
222 }
223
224 if (!jingle_glue::SocketAddressToIPEndPoint(
225 candidate.address(), &route.remote_address)) {
226 LOG(FATAL) << "Failed to convert peer IP address.";
227 }
228
229 DCHECK(channel->GetP2PChannel());
230 DCHECK(channel->GetP2PChannel()->best_connection());
231 const cricket::Candidate& local_candidate =
232 channel->GetP2PChannel()->best_connection()->local_candidate();
233 if (!jingle_glue::SocketAddressToIPEndPoint(
234 local_candidate.address(), &route.local_address)) {
235 LOG(FATAL) << "Failed to convert local IP address.";
236 }
237
238 event_handler_->OnTransportRouteChange(this, route);
239 }
240
204 void LibjingleStreamTransport::OnTcpConnected(int result) { 241 void LibjingleStreamTransport::OnTcpConnected(int result) {
205 DCHECK(CalledOnValidThread()); 242 DCHECK(CalledOnValidThread());
206 243
207 if (result != net::OK) { 244 if (result != net::OK) {
208 NotifyConnectFailed(); 245 NotifyConnectFailed();
209 return; 246 return;
210 } 247 }
211 248
212 authenticator_->SecureAndAuthenticate( 249 authenticator_->SecureAndAuthenticate(
213 socket_.PassAs<net::StreamSocket>(), 250 socket_.PassAs<net::StreamSocket>(),
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 304
268 scoped_ptr<DatagramTransport> 305 scoped_ptr<DatagramTransport>
269 LibjingleTransportFactory::CreateDatagramTransport() { 306 LibjingleTransportFactory::CreateDatagramTransport() {
270 NOTIMPLEMENTED(); 307 NOTIMPLEMENTED();
271 return scoped_ptr<DatagramTransport>(NULL); 308 return scoped_ptr<DatagramTransport>(NULL);
272 } 309 }
273 310
274 311
275 } // namespace protocol 312 } // namespace protocol
276 } // namespace remoting 313 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/jingle_session.cc ('k') | remoting/protocol/pepper_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698