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

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

Issue 10160012: Pass TransportConfig to TransportFactory instead of Transport. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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
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 "base/message_loop_proxy.h" 7 #include "base/message_loop_proxy.h"
8 #include "jingle/glue/channel_socket_adapter.h" 8 #include "jingle/glue/channel_socket_adapter.h"
9 #include "jingle/glue/pseudotcp_adapter.h" 9 #include "jingle/glue/pseudotcp_adapter.h"
10 #include "jingle/glue/utils.h" 10 #include "jingle/glue/utils.h"
11 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
12 #include "remoting/base/constants.h" 12 #include "remoting/base/constants.h"
13 #include "remoting/protocol/channel_authenticator.h" 13 #include "remoting/protocol/channel_authenticator.h"
14 #include "remoting/protocol/transport_config.h" 14 #include "remoting/protocol/transport_config.h"
15 #include "third_party/libjingle/source/talk/base/basicpacketsocketfactory.h" 15 #include "third_party/libjingle/source/talk/base/basicpacketsocketfactory.h"
16 #include "third_party/libjingle/source/talk/base/network.h" 16 #include "third_party/libjingle/source/talk/base/network.h"
17 #include "third_party/libjingle/source/talk/p2p/base/p2ptransportchannel.h" 17 #include "third_party/libjingle/source/talk/p2p/base/p2ptransportchannel.h"
18 #include "third_party/libjingle/source/talk/p2p/client/basicportallocator.h" 18 #include "third_party/libjingle/source/talk/p2p/client/basicportallocator.h"
19 #include "third_party/libjingle/source/talk/p2p/client/httpportallocator.h"
19 20
20 namespace remoting { 21 namespace remoting {
21 namespace protocol { 22 namespace protocol {
22 23
23 namespace { 24 namespace {
24 25
25 // Value is choosen to balance the extra latency against the reduced 26 // Value is choosen to balance the extra latency against the reduced
26 // load due to ACK traffic. 27 // load due to ACK traffic.
27 const int kTcpAckDelayMilliseconds = 10; 28 const int kTcpAckDelayMilliseconds = 10;
28 29
29 // Values for the TCP send and receive buffer size. This should be tuned to 30 // Values for the TCP send and receive buffer size. This should be tuned to
30 // accomodate high latency network but not backlog the decoding pipeline. 31 // accomodate high latency network but not backlog the decoding pipeline.
31 const int kTcpReceiveBufferSize = 256 * 1024; 32 const int kTcpReceiveBufferSize = 256 * 1024;
32 const int kTcpSendBufferSize = kTcpReceiveBufferSize + 30 * 1024; 33 const int kTcpSendBufferSize = kTcpReceiveBufferSize + 30 * 1024;
33 34
34 class LibjingleStreamTransport : public StreamTransport, 35 class LibjingleStreamTransport : public StreamTransport,
35 public sigslot::has_slots<> { 36 public sigslot::has_slots<> {
36 public: 37 public:
37 LibjingleStreamTransport(cricket::PortAllocator* port_allocator, 38 LibjingleStreamTransport(cricket::PortAllocator* port_allocator,
38 bool incoming_only); 39 bool incoming_only);
39 virtual ~LibjingleStreamTransport(); 40 virtual ~LibjingleStreamTransport();
40 41
41 // StreamTransport interface. 42 // StreamTransport interface.
42 virtual void Initialize( 43 virtual void Initialize(
43 const std::string& name, 44 const std::string& name,
44 const TransportConfig& config,
45 Transport::EventHandler* event_handler, 45 Transport::EventHandler* event_handler,
46 scoped_ptr<ChannelAuthenticator> authenticator) OVERRIDE; 46 scoped_ptr<ChannelAuthenticator> authenticator) OVERRIDE;
47 virtual void Connect( 47 virtual void Connect(
48 const StreamTransport::ConnectedCallback& callback) OVERRIDE; 48 const StreamTransport::ConnectedCallback& callback) OVERRIDE;
49 virtual void AddRemoteCandidate(const cricket::Candidate& candidate) OVERRIDE; 49 virtual void AddRemoteCandidate(const cricket::Candidate& candidate) OVERRIDE;
50 virtual const std::string& name() const OVERRIDE; 50 virtual const std::string& name() const OVERRIDE;
51 virtual bool is_connected() const OVERRIDE; 51 virtual bool is_connected() const OVERRIDE;
52 52
53 private: 53 private:
54 void OnRequestSignaling(cricket::TransportChannelImpl* channel); 54 void OnRequestSignaling(cricket::TransportChannelImpl* channel);
55 void OnCandidateReady(cricket::TransportChannelImpl* channel, 55 void OnCandidateReady(cricket::TransportChannelImpl* channel,
56 const cricket::Candidate& candidate); 56 const cricket::Candidate& candidate);
57 void OnRouteChange(cricket::TransportChannel* channel, 57 void OnRouteChange(cricket::TransportChannel* channel,
58 const cricket::Candidate& candidate); 58 const cricket::Candidate& candidate);
59 59
60 void OnTcpConnected(int result); 60 void OnTcpConnected(int result);
61 void OnAuthenticationDone(net::Error error, 61 void OnAuthenticationDone(net::Error error,
62 scoped_ptr<net::StreamSocket> socket); 62 scoped_ptr<net::StreamSocket> socket);
63 63
64 void OnChannelDestroyed(); 64 void OnChannelDestroyed();
65 65
66 void NotifyConnected(scoped_ptr<net::StreamSocket> socket); 66 void NotifyConnected(scoped_ptr<net::StreamSocket> socket);
67 void NotifyConnectFailed(); 67 void NotifyConnectFailed();
68 68
69 cricket::PortAllocator* port_allocator_; 69 cricket::PortAllocator* port_allocator_;
70 bool incoming_only_; 70 bool incoming_only_;
71 71
72 std::string name_; 72 std::string name_;
73 TransportConfig config_;
74 EventHandler* event_handler_; 73 EventHandler* event_handler_;
75 StreamTransport::ConnectedCallback callback_; 74 StreamTransport::ConnectedCallback callback_;
76 scoped_ptr<ChannelAuthenticator> authenticator_; 75 scoped_ptr<ChannelAuthenticator> authenticator_;
77 76
78 scoped_ptr<cricket::P2PTransportChannel> channel_; 77 scoped_ptr<cricket::P2PTransportChannel> channel_;
79 78
80 // We own |socket_| until it is connected. 79 // We own |socket_| until it is connected.
81 scoped_ptr<jingle_glue::PseudoTcpAdapter> socket_; 80 scoped_ptr<jingle_glue::PseudoTcpAdapter> socket_;
82 81
83 DISALLOW_COPY_AND_ASSIGN(LibjingleStreamTransport); 82 DISALLOW_COPY_AND_ASSIGN(LibjingleStreamTransport);
(...skipping 14 matching lines...) Expand all
98 DCHECK(!is_connected() || socket_.get() == NULL); 97 DCHECK(!is_connected() || socket_.get() == NULL);
99 98
100 if (channel_.get()) { 99 if (channel_.get()) {
101 base::MessageLoopProxy::current()->DeleteSoon( 100 base::MessageLoopProxy::current()->DeleteSoon(
102 FROM_HERE, channel_.release()); 101 FROM_HERE, channel_.release());
103 } 102 }
104 } 103 }
105 104
106 void LibjingleStreamTransport::Initialize( 105 void LibjingleStreamTransport::Initialize(
107 const std::string& name, 106 const std::string& name,
108 const TransportConfig& config,
109 Transport::EventHandler* event_handler, 107 Transport::EventHandler* event_handler,
110 scoped_ptr<ChannelAuthenticator> authenticator) { 108 scoped_ptr<ChannelAuthenticator> authenticator) {
111 DCHECK(CalledOnValidThread()); 109 DCHECK(CalledOnValidThread());
112 110
113 DCHECK(!name.empty()); 111 DCHECK(!name.empty());
114 DCHECK(event_handler); 112 DCHECK(event_handler);
115 113
116 // Can be initialized only once. 114 // Can be initialized only once.
117 DCHECK(name_.empty()); 115 DCHECK(name_.empty());
118 116
119 name_ = name; 117 name_ = name;
120 config_ = config;
121 event_handler_ = event_handler; 118 event_handler_ = event_handler;
122 authenticator_ = authenticator.Pass(); 119 authenticator_ = authenticator.Pass();
123 } 120 }
124 121
125 void LibjingleStreamTransport::Connect( 122 void LibjingleStreamTransport::Connect(
126 const StreamTransport::ConnectedCallback& callback) { 123 const StreamTransport::ConnectedCallback& callback) {
127 DCHECK(CalledOnValidThread()); 124 DCHECK(CalledOnValidThread());
128 125
129 callback_ = callback; 126 callback_ = callback;
130 127
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 authenticator_.reset(); 284 authenticator_.reset();
288 285
289 NotifyConnected(scoped_ptr<net::StreamSocket>(NULL)); 286 NotifyConnected(scoped_ptr<net::StreamSocket>(NULL));
290 } 287 }
291 288
292 } // namespace 289 } // namespace
293 290
294 LibjingleTransportFactory::LibjingleTransportFactory( 291 LibjingleTransportFactory::LibjingleTransportFactory(
295 scoped_ptr<talk_base::NetworkManager> network_manager, 292 scoped_ptr<talk_base::NetworkManager> network_manager,
296 scoped_ptr<talk_base::PacketSocketFactory> socket_factory, 293 scoped_ptr<talk_base::PacketSocketFactory> socket_factory,
297 scoped_ptr<cricket::PortAllocator> port_allocator, 294 scoped_ptr<cricket::HttpPortAllocatorBase> port_allocator,
298 bool incoming_only) 295 bool incoming_only)
299 : network_manager_(network_manager.Pass()), 296 : network_manager_(network_manager.Pass()),
300 socket_factory_(socket_factory.Pass()), 297 socket_factory_(socket_factory.Pass()),
298 http_port_allocator_(port_allocator.get()),
301 port_allocator_(port_allocator.Pass()), 299 port_allocator_(port_allocator.Pass()),
302 incoming_only_(incoming_only) { 300 incoming_only_(incoming_only) {
303 } 301 }
304 302
305 LibjingleTransportFactory::LibjingleTransportFactory() 303 LibjingleTransportFactory::LibjingleTransportFactory()
306 : network_manager_(new talk_base::BasicNetworkManager()), 304 : network_manager_(new talk_base::BasicNetworkManager()),
307 socket_factory_(new talk_base::BasicPacketSocketFactory()), 305 socket_factory_(new talk_base::BasicPacketSocketFactory()),
306 http_port_allocator_(NULL),
308 port_allocator_(new cricket::BasicPortAllocator( 307 port_allocator_(new cricket::BasicPortAllocator(
309 network_manager_.get(), socket_factory_.get())), 308 network_manager_.get(), socket_factory_.get())),
310 incoming_only_(false) { 309 incoming_only_(false) {
311 } 310 }
312 311
313 LibjingleTransportFactory::~LibjingleTransportFactory() { 312 LibjingleTransportFactory::~LibjingleTransportFactory() {
314 // This method may be called in response to a libjingle signal, so 313 // This method may be called in response to a libjingle signal, so
315 // libjingle objects must be deleted asynchronously. 314 // libjingle objects must be deleted asynchronously.
316 base::MessageLoopProxy::current()->DeleteSoon( 315 base::MessageLoopProxy::current()->DeleteSoon(
317 FROM_HERE, port_allocator_.release()); 316 FROM_HERE, port_allocator_.release());
318 base::MessageLoopProxy::current()->DeleteSoon( 317 base::MessageLoopProxy::current()->DeleteSoon(
319 FROM_HERE, socket_factory_.release()); 318 FROM_HERE, socket_factory_.release());
320 base::MessageLoopProxy::current()->DeleteSoon( 319 base::MessageLoopProxy::current()->DeleteSoon(
321 FROM_HERE, network_manager_.release()); 320 FROM_HERE, network_manager_.release());
322 } 321 }
323 322
323 void LibjingleTransportFactory::SetTransportConfig(
324 const TransportConfig& config) {
325 if (http_port_allocator_) {
326 std::vector<talk_base::SocketAddress> stun_hosts;
327 talk_base::SocketAddress stun_address;
328 if (stun_address.FromString(config.stun_server)) {
329 stun_hosts.push_back(stun_address);
330 http_port_allocator_->SetStunHosts(stun_hosts);
331 } else {
332 LOG(ERROR) << "Failed to parse stun server address: "
333 << config.stun_server;
334 }
335
336 std::vector<std::string> relay_hosts;
337 relay_hosts.push_back(config.relay_server);
338 http_port_allocator_->SetRelayHosts(relay_hosts);
339 http_port_allocator_->SetRelayToken(config.relay_token);
340 }
341 }
342
324 scoped_ptr<StreamTransport> LibjingleTransportFactory::CreateStreamTransport() { 343 scoped_ptr<StreamTransport> LibjingleTransportFactory::CreateStreamTransport() {
325 return scoped_ptr<StreamTransport>( 344 return scoped_ptr<StreamTransport>(
326 new LibjingleStreamTransport(port_allocator_.get(), incoming_only_)); 345 new LibjingleStreamTransport(port_allocator_.get(), incoming_only_));
327 } 346 }
328 347
329 scoped_ptr<DatagramTransport> 348 scoped_ptr<DatagramTransport>
330 LibjingleTransportFactory::CreateDatagramTransport() { 349 LibjingleTransportFactory::CreateDatagramTransport() {
331 NOTIMPLEMENTED(); 350 NOTIMPLEMENTED();
332 return scoped_ptr<DatagramTransport>(NULL); 351 return scoped_ptr<DatagramTransport>(NULL);
333 } 352 }
334 353
335 } // namespace protocol 354 } // namespace protocol
336 } // namespace remoting 355 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/libjingle_transport_factory.h ('k') | remoting/protocol/pepper_transport_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698