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 |
14 P2PPortAllocator::P2PPortAllocator( | 26 P2PPortAllocator::P2PPortAllocator( |
15 const scoped_refptr<P2PSocketDispatcher>& socket_dispatcher, | 27 const scoped_refptr<P2PSocketDispatcher>& socket_dispatcher, |
16 scoped_ptr<rtc::NetworkManager> network_manager, | 28 scoped_ptr<rtc::NetworkManager> network_manager, |
17 rtc::PacketSocketFactory* socket_factory, | 29 rtc::PacketSocketFactory* socket_factory, |
18 const Config& config, | 30 const Config& config, |
19 const GURL& origin, | 31 const GURL& origin, |
20 const scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 32 const scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
21 : cricket::BasicPortAllocator(network_manager.get(), socket_factory), | 33 : cricket::BasicPortAllocator(network_manager.get(), socket_factory), |
22 network_manager_(network_manager.Pass()), | 34 network_manager_(network_manager.Pass()), |
23 socket_dispatcher_(socket_dispatcher), | 35 socket_dispatcher_(socket_dispatcher), |
24 config_(config), | 36 config_(config), |
25 origin_(origin), | 37 origin_(origin), |
26 network_manager_task_runner_(task_runner) { | 38 network_manager_task_runner_(task_runner) { |
27 uint32 flags = 0; | 39 uint32 flags = 0; |
28 if (!config_.enable_multiple_routes) { | 40 if (!config_.enable_multiple_routes) |
29 flags |= cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION; | 41 flags |= cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION; |
30 } | 42 if (!config_.enable_default_local_candidate) |
31 if (!config_.enable_default_local_candidate) { | |
32 flags |= cricket::PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE; | 43 flags |= cricket::PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE; |
33 } | |
34 if (!config_.enable_nonproxied_udp) { | 44 if (!config_.enable_nonproxied_udp) { |
35 flags |= cricket::PORTALLOCATOR_DISABLE_UDP | | 45 flags |= cricket::PORTALLOCATOR_DISABLE_UDP | |
36 cricket::PORTALLOCATOR_DISABLE_STUN | | 46 cricket::PORTALLOCATOR_DISABLE_STUN | |
37 cricket::PORTALLOCATOR_DISABLE_UDP_RELAY; | 47 cricket::PORTALLOCATOR_DISABLE_UDP_RELAY; |
38 } | 48 } |
39 set_flags(flags); | 49 set_flags(flags); |
40 set_allow_tcp_listen(false); | 50 set_allow_tcp_listen(false); |
41 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 51 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
42 bool enable_webrtc_stun_origin = | 52 bool enable_webrtc_stun_origin = |
43 cmd_line->HasSwitch(switches::kEnableWebRtcStunOrigin); | 53 cmd_line->HasSwitch(switches::kEnableWebRtcStunOrigin); |
44 if (enable_webrtc_stun_origin) { | 54 if (enable_webrtc_stun_origin) { |
45 set_origin(origin_.spec()); | 55 set_origin(origin_.spec()); |
46 } | 56 } |
47 } | 57 } |
48 | 58 |
49 // TODO(guoweis): P2PPortAllocator is also deleted in the wrong thread | 59 // TODO(guoweis): P2PPortAllocator is also deleted in the wrong thread |
50 // here. It's created in signaling thread, and held by webrtc::PeerConnection, | 60 // here. It's created in signaling thread, and held by webrtc::PeerConnection, |
51 // only used on worker thread. The destructor is invoked on signaling thread | 61 // only used on worker thread. The destructor is invoked on signaling thread |
52 // again. crbug.com/535761. DeleteSoon can be removed once the bug is fixed. | 62 // again. crbug.com/535761. DeleteSoon can be removed once the bug is fixed. |
53 P2PPortAllocator::~P2PPortAllocator() { | 63 P2PPortAllocator::~P2PPortAllocator() { |
54 network_manager_task_runner_->DeleteSoon(FROM_HERE, | 64 network_manager_task_runner_->DeleteSoon(FROM_HERE, |
55 network_manager_.release()); | 65 network_manager_.release()); |
56 } | 66 } |
57 | 67 |
| 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 |
58 } // namespace content | 125 } // namespace content |
OLD | NEW |