OLD | NEW |
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 "content/renderer/p2p/port_allocator.h" | 5 #include "content/renderer/p2p/port_allocator.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "content/public/common/content_switches.h" | 9 #include "content/public/common/content_switches.h" |
10 #include "content/renderer/p2p/socket_dispatcher.h" | 10 #include "content/renderer/p2p/socket_dispatcher.h" |
11 | 11 |
12 namespace content { | 12 namespace content { |
13 | 13 |
14 P2PPortAllocator::Config::Config() {} | |
15 | |
16 P2PPortAllocator::Config::~Config() { | |
17 } | |
18 | |
19 P2PPortAllocator::Config::RelayServerConfig::RelayServerConfig() | |
20 : port(0) { | |
21 } | |
22 | |
23 P2PPortAllocator::Config::RelayServerConfig::~RelayServerConfig() { | |
24 } | |
25 | |
26 P2PPortAllocator::P2PPortAllocator( | 14 P2PPortAllocator::P2PPortAllocator( |
27 const scoped_refptr<P2PSocketDispatcher>& socket_dispatcher, | 15 const scoped_refptr<P2PSocketDispatcher>& socket_dispatcher, |
28 scoped_ptr<rtc::NetworkManager> network_manager, | 16 scoped_ptr<rtc::NetworkManager> network_manager, |
29 rtc::PacketSocketFactory* socket_factory, | 17 rtc::PacketSocketFactory* socket_factory, |
30 const Config& config, | 18 const Config& config, |
31 const GURL& origin, | 19 const GURL& origin, |
32 const scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 20 const scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
33 : cricket::BasicPortAllocator(network_manager.get(), socket_factory), | 21 : cricket::BasicPortAllocator(network_manager.get(), socket_factory), |
34 network_manager_(network_manager.Pass()), | 22 network_manager_(network_manager.Pass()), |
35 socket_dispatcher_(socket_dispatcher), | 23 socket_dispatcher_(socket_dispatcher), |
36 config_(config), | 24 config_(config), |
37 origin_(origin), | 25 origin_(origin), |
38 network_manager_task_runner_(task_runner) { | 26 network_manager_task_runner_(task_runner) { |
39 uint32 flags = 0; | 27 uint32 flags = 0; |
40 if (!config_.enable_multiple_routes) | 28 if (!config_.enable_multiple_routes) { |
41 flags |= cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION; | 29 flags |= cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION; |
42 if (!config_.enable_default_local_candidate) | 30 } |
| 31 if (!config_.enable_default_local_candidate) { |
43 flags |= cricket::PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE; | 32 flags |= cricket::PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE; |
| 33 } |
44 if (!config_.enable_nonproxied_udp) { | 34 if (!config_.enable_nonproxied_udp) { |
45 flags |= cricket::PORTALLOCATOR_DISABLE_UDP | | 35 flags |= cricket::PORTALLOCATOR_DISABLE_UDP | |
46 cricket::PORTALLOCATOR_DISABLE_STUN | | 36 cricket::PORTALLOCATOR_DISABLE_STUN | |
47 cricket::PORTALLOCATOR_DISABLE_UDP_RELAY; | 37 cricket::PORTALLOCATOR_DISABLE_UDP_RELAY; |
48 } | 38 } |
49 set_flags(flags); | 39 set_flags(flags); |
50 set_allow_tcp_listen(false); | 40 set_allow_tcp_listen(false); |
51 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 41 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
52 bool enable_webrtc_stun_origin = | 42 bool enable_webrtc_stun_origin = |
53 cmd_line->HasSwitch(switches::kEnableWebRtcStunOrigin); | 43 cmd_line->HasSwitch(switches::kEnableWebRtcStunOrigin); |
54 if (enable_webrtc_stun_origin) { | 44 if (enable_webrtc_stun_origin) { |
55 set_origin(origin_.spec()); | 45 set_origin(origin_.spec()); |
56 } | 46 } |
57 } | 47 } |
58 | 48 |
59 // TODO(guoweis): P2PPortAllocator is also deleted in the wrong thread | 49 // TODO(guoweis): P2PPortAllocator is also deleted in the wrong thread |
60 // here. It's created in signaling thread, and held by webrtc::PeerConnection, | 50 // here. It's created in signaling thread, and held by webrtc::PeerConnection, |
61 // only used on worker thread. The destructor is invoked on signaling thread | 51 // only used on worker thread. The destructor is invoked on signaling thread |
62 // again. crbug.com/535761. DeleteSoon can be removed once the bug is fixed. | 52 // again. crbug.com/535761. DeleteSoon can be removed once the bug is fixed. |
63 P2PPortAllocator::~P2PPortAllocator() { | 53 P2PPortAllocator::~P2PPortAllocator() { |
64 network_manager_task_runner_->DeleteSoon(FROM_HERE, | 54 network_manager_task_runner_->DeleteSoon(FROM_HERE, |
65 network_manager_.release()); | 55 network_manager_.release()); |
66 } | 56 } |
67 | 57 |
68 cricket::PortAllocatorSession* P2PPortAllocator::CreateSessionInternal( | |
69 const std::string& content_name, | |
70 int component, | |
71 const std::string& ice_username_fragment, | |
72 const std::string& ice_password) { | |
73 return new P2PPortAllocatorSession( | |
74 this, content_name, component, ice_username_fragment, ice_password); | |
75 } | |
76 | |
77 P2PPortAllocatorSession::P2PPortAllocatorSession( | |
78 P2PPortAllocator* allocator, | |
79 const std::string& content_name, | |
80 int component, | |
81 const std::string& ice_username_fragment, | |
82 const std::string& ice_password) | |
83 : cricket::BasicPortAllocatorSession(allocator, | |
84 content_name, | |
85 component, | |
86 ice_username_fragment, | |
87 ice_password), | |
88 allocator_(allocator) { | |
89 } | |
90 | |
91 P2PPortAllocatorSession::~P2PPortAllocatorSession() { | |
92 } | |
93 | |
94 void P2PPortAllocatorSession::GetPortConfigurations() { | |
95 const P2PPortAllocator::Config& config = allocator_->config_; | |
96 cricket::PortConfiguration* port_config = new cricket::PortConfiguration( | |
97 config.stun_servers, std::string(), std::string()); | |
98 | |
99 for (size_t i = 0; i < config.relays.size(); ++i) { | |
100 cricket::RelayCredentials credentials(config.relays[i].username, | |
101 config.relays[i].password); | |
102 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN); | |
103 cricket::ProtocolType protocol; | |
104 if (!cricket::StringToProto(config.relays[i].transport_type.c_str(), | |
105 &protocol)) { | |
106 DLOG(WARNING) << "Ignoring TURN server " | |
107 << config.relays[i].server_address << ". " | |
108 << "Reason= Incorrect " | |
109 << config.relays[i].transport_type | |
110 << " transport parameter."; | |
111 continue; | |
112 } | |
113 | |
114 relay_server.ports.push_back(cricket::ProtocolAddress( | |
115 rtc::SocketAddress(config.relays[i].server_address, | |
116 config.relays[i].port), | |
117 protocol, | |
118 config.relays[i].secure)); | |
119 relay_server.credentials = credentials; | |
120 port_config->AddRelay(relay_server); | |
121 } | |
122 ConfigReady(port_config); | |
123 } | |
124 | |
125 } // namespace content | 58 } // namespace content |
OLD | NEW |