OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "base/string_split.h" | 9 #include "base/string_split.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "content/renderer/p2p/host_address_request.h" | 11 #include "content/renderer/p2p/host_address_request.h" |
12 #include "jingle/glue/utils.h" | 12 #include "jingle/glue/utils.h" |
13 #include "net/base/ip_endpoint.h" | 13 #include "net/base/ip_endpoint.h" |
14 #include "ppapi/c/dev/ppb_transport_dev.h" | |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoader.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoader.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderOptions.h " | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderOptions.h " |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" |
20 | 21 |
21 using WebKit::WebString; | 22 using WebKit::WebString; |
22 using WebKit::WebURL; | 23 using WebKit::WebURL; |
23 using WebKit::WebURLLoader; | 24 using WebKit::WebURLLoader; |
(...skipping 28 matching lines...) Expand all Loading... | |
52 P2PPortAllocator::P2PPortAllocator( | 53 P2PPortAllocator::P2PPortAllocator( |
53 WebKit::WebFrame* web_frame, | 54 WebKit::WebFrame* web_frame, |
54 P2PSocketDispatcher* socket_dispatcher, | 55 P2PSocketDispatcher* socket_dispatcher, |
55 talk_base::NetworkManager* network_manager, | 56 talk_base::NetworkManager* network_manager, |
56 talk_base::PacketSocketFactory* socket_factory, | 57 talk_base::PacketSocketFactory* socket_factory, |
57 const webkit_glue::P2PTransport::Config& config) | 58 const webkit_glue::P2PTransport::Config& config) |
58 : cricket::BasicPortAllocator(network_manager, socket_factory), | 59 : cricket::BasicPortAllocator(network_manager, socket_factory), |
59 web_frame_(web_frame), | 60 web_frame_(web_frame), |
60 socket_dispatcher_(socket_dispatcher), | 61 socket_dispatcher_(socket_dispatcher), |
61 config_(config) { | 62 config_(config) { |
63 uint32 flags = 0; | |
64 if (config_.protocols & PP_TRANSPORTPROTOCOL_UDP) | |
65 flags |= cricket::PORTALLOCATOR_DISABLE_UDP; | |
66 if (config_.protocols & PP_TRANSPORTPROTOCOL_TCP) | |
67 flags |= cricket::PORTALLOCATOR_DISABLE_TCP; | |
68 if (config_.protocols & PP_TRANSPORTPROTOCOL_STUN) | |
69 flags |= cricket::PORTALLOCATOR_DISABLE_STUN; | |
70 if ((config_.protocols & PP_TRANSPORTPROTOCOL_RELAY_UDP) && | |
71 (config_.protocols & PP_TRANSPORTPROTOCOL_RELAY_TCP) && | |
72 (config_.protocols & PP_TRANSPORTPROTOCOL_RELAY_SSLTCP)) { | |
73 flags |= cricket::PORTALLOCATOR_DISABLE_RELAY; | |
74 } | |
75 set_flags(flags); | |
62 } | 76 } |
63 | 77 |
64 P2PPortAllocator::~P2PPortAllocator() { | 78 P2PPortAllocator::~P2PPortAllocator() { |
65 } | 79 } |
66 | 80 |
67 cricket::PortAllocatorSession* P2PPortAllocator::CreateSession( | 81 cricket::PortAllocatorSession* P2PPortAllocator::CreateSession( |
68 const std::string& name, | 82 const std::string& name, |
69 const std::string& session_type) { | 83 const std::string& session_type) { |
70 return new P2PPortAllocatorSession(this, name, session_type); | 84 return new P2PPortAllocatorSession(this, name, session_type); |
71 } | 85 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 talk_base::SocketAddress(), "", "", "")); | 133 talk_base::SocketAddress(), "", "", "")); |
120 | 134 |
121 ResolveStunServerAddress(); | 135 ResolveStunServerAddress(); |
122 AllocateRelaySession(); | 136 AllocateRelaySession(); |
123 } | 137 } |
124 | 138 |
125 void P2PPortAllocatorSession::ResolveStunServerAddress() { | 139 void P2PPortAllocatorSession::ResolveStunServerAddress() { |
126 if (allocator_->config_.stun_server.empty()) | 140 if (allocator_->config_.stun_server.empty()) |
127 return; | 141 return; |
128 | 142 |
143 if (allocator_->config_.protocols & PP_TRANSPORTPROTOCOL_STUN) | |
144 return; | |
145 | |
129 DCHECK(!stun_address_request_); | 146 DCHECK(!stun_address_request_); |
130 stun_address_request_ = | 147 stun_address_request_ = |
131 new P2PHostAddressRequest(allocator_->socket_dispatcher_); | 148 new P2PHostAddressRequest(allocator_->socket_dispatcher_); |
132 stun_address_request_->Request(allocator_->config_.stun_server, base::Bind( | 149 stun_address_request_->Request(allocator_->config_.stun_server, base::Bind( |
133 &P2PPortAllocatorSession::OnStunServerAddress, | 150 &P2PPortAllocatorSession::OnStunServerAddress, |
134 base::Unretained(this))); | 151 base::Unretained(this))); |
135 } | 152 } |
136 | 153 |
137 void P2PPortAllocatorSession::OnStunServerAddress( | 154 void P2PPortAllocatorSession::OnStunServerAddress( |
138 const net::IPAddressNumber& address) { | 155 const net::IPAddressNumber& address) { |
139 if (address.empty()) { | 156 if (address.empty()) { |
140 LOG(ERROR) << "Failed to resolve STUN server address " | 157 LOG(ERROR) << "Failed to resolve STUN server address " |
141 << allocator_->config_.stun_server; | 158 << allocator_->config_.stun_server; |
142 return; | 159 return; |
143 } | 160 } |
144 | 161 |
145 if (!jingle_glue::IPEndPointToSocketAddress( | 162 if (!jingle_glue::IPEndPointToSocketAddress( |
146 net::IPEndPoint(address, allocator_->config_.stun_server_port), | 163 net::IPEndPoint(address, allocator_->config_.stun_server_port), |
147 &stun_server_address_)) { | 164 &stun_server_address_)) { |
148 return; | 165 return; |
149 } | 166 } |
150 | 167 |
151 AddConfig(); | 168 AddConfig(); |
152 } | 169 } |
153 | 170 |
154 void P2PPortAllocatorSession::AllocateRelaySession() { | 171 void P2PPortAllocatorSession::AllocateRelaySession() { |
155 if (allocator_->config_.relay_server.empty()) | 172 if (allocator_->config_.relay_server.empty()) |
156 return; | 173 return; |
157 | 174 |
175 if ((allocator_->config_.protocols & PP_TRANSPORTPROTOCOL_RELAY_UDP) && | |
176 (allocator_->config_.protocols & PP_TRANSPORTPROTOCOL_RELAY_TCP) && | |
177 (allocator_->config_.protocols & PP_TRANSPORTPROTOCOL_RELAY_SSLTCP)) { | |
178 return; | |
179 } | |
180 | |
158 if (!allocator_->config_.legacy_relay) { | 181 if (!allocator_->config_.legacy_relay) { |
159 NOTIMPLEMENTED() << " TURN support is not implemented yet."; | 182 NOTIMPLEMENTED() << " TURN support is not implemented yet."; |
160 return; | 183 return; |
161 } | 184 } |
162 | 185 |
163 if (relay_session_attemtps_ > kRelaySessionRetries) | 186 if (relay_session_attemtps_ > kRelaySessionRetries) |
164 return; | 187 return; |
165 relay_session_attemtps_++; | 188 relay_session_attemtps_++; |
166 | 189 |
167 relay_session_response_.clear(); | 190 relay_session_response_.clear(); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 AddConfig(); | 269 AddConfig(); |
247 } | 270 } |
248 | 271 |
249 void P2PPortAllocatorSession::AddConfig() { | 272 void P2PPortAllocatorSession::AddConfig() { |
250 cricket::PortConfiguration* config = | 273 cricket::PortConfiguration* config = |
251 new cricket::PortConfiguration(stun_server_address_, | 274 new cricket::PortConfiguration(stun_server_address_, |
252 relay_username_, relay_password_, ""); | 275 relay_username_, relay_password_, ""); |
253 | 276 |
254 cricket::PortConfiguration::PortList ports; | 277 cricket::PortConfiguration::PortList ports; |
255 if (relay_ip_.ip() != 0) { | 278 if (relay_ip_.ip() != 0) { |
256 if (relay_udp_port_ > 0) { | 279 if (relay_udp_port_ > 0 && |
280 (allocator_->config_.protocols & PP_TRANSPORTPROTOCOL_RELAY_UDP)) { | |
juberti
2011/09/13 21:14:19
Why do we care what protocol the remote side uses
Sergey Ulanov
2011/09/13 21:55:49
For chromoting we disable TCP ports because they p
| |
257 talk_base::SocketAddress address(relay_ip_.ip(), relay_udp_port_); | 281 talk_base::SocketAddress address(relay_ip_.ip(), relay_udp_port_); |
258 ports.push_back(cricket::ProtocolAddress(address, cricket::PROTO_UDP)); | 282 ports.push_back(cricket::ProtocolAddress(address, cricket::PROTO_UDP)); |
259 } | 283 } |
260 if (relay_tcp_port_ > 0) { | 284 if (relay_tcp_port_ > 0 && |
285 (allocator_->config_.protocols & PP_TRANSPORTPROTOCOL_RELAY_TCP)) { | |
261 talk_base::SocketAddress address(relay_ip_.ip(), relay_tcp_port_); | 286 talk_base::SocketAddress address(relay_ip_.ip(), relay_tcp_port_); |
262 ports.push_back(cricket::ProtocolAddress(address, cricket::PROTO_TCP)); | 287 ports.push_back(cricket::ProtocolAddress(address, cricket::PROTO_TCP)); |
263 } | 288 } |
264 if (relay_ssltcp_port_ > 0) { | 289 if (relay_ssltcp_port_ > 0 && |
290 (allocator_->config_.protocols & PP_TRANSPORTPROTOCOL_RELAY_SSLTCP)) { | |
265 talk_base::SocketAddress address(relay_ip_.ip(), relay_ssltcp_port_); | 291 talk_base::SocketAddress address(relay_ip_.ip(), relay_ssltcp_port_); |
266 ports.push_back(cricket::ProtocolAddress(address, cricket::PROTO_SSLTCP)); | 292 ports.push_back(cricket::ProtocolAddress(address, cricket::PROTO_SSLTCP)); |
267 } | 293 } |
268 } | 294 } |
269 config->AddRelay(ports, 0.0f); | 295 config->AddRelay(ports, 0.0f); |
270 ConfigReady(config); | 296 ConfigReady(config); |
271 } | 297 } |
272 | 298 |
273 } // namespace content | 299 } // namespace content |
OLD | NEW |