| 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/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" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 uint32 flags = 0; | 64 uint32 flags = 0; |
| 65 if (config_.disable_tcp_transport) | 65 if (config_.disable_tcp_transport) |
| 66 flags |= cricket::PORTALLOCATOR_DISABLE_TCP; | 66 flags |= cricket::PORTALLOCATOR_DISABLE_TCP; |
| 67 set_flags(flags); | 67 set_flags(flags); |
| 68 } | 68 } |
| 69 | 69 |
| 70 P2PPortAllocator::~P2PPortAllocator() { | 70 P2PPortAllocator::~P2PPortAllocator() { |
| 71 } | 71 } |
| 72 | 72 |
| 73 cricket::PortAllocatorSession* P2PPortAllocator::CreateSession( | 73 cricket::PortAllocatorSession* P2PPortAllocator::CreateSession( |
| 74 const std::string& name, | 74 const std::string& channel_name, |
| 75 const std::string& session_type) { | 75 int component) { |
| 76 return new P2PPortAllocatorSession(this, name, session_type); | 76 return new P2PPortAllocatorSession(this, channel_name, component); |
| 77 } | 77 } |
| 78 | 78 |
| 79 P2PPortAllocatorSession::P2PPortAllocatorSession( | 79 P2PPortAllocatorSession::P2PPortAllocatorSession( |
| 80 P2PPortAllocator* allocator, | 80 P2PPortAllocator* allocator, |
| 81 const std::string& name, | 81 const std::string& channel_name, |
| 82 const std::string& session_type) | 82 int component) |
| 83 : cricket::BasicPortAllocatorSession(allocator, name, session_type), | 83 : cricket::BasicPortAllocatorSession(allocator, channel_name, component), |
| 84 allocator_(allocator), | 84 allocator_(allocator), |
| 85 relay_session_attempts_(0), | 85 relay_session_attempts_(0), |
| 86 relay_udp_port_(0), | 86 relay_udp_port_(0), |
| 87 relay_tcp_port_(0), | 87 relay_tcp_port_(0), |
| 88 relay_ssltcp_port_(0) { | 88 relay_ssltcp_port_(0) { |
| 89 } | 89 } |
| 90 | 90 |
| 91 P2PPortAllocatorSession::~P2PPortAllocatorSession() { | 91 P2PPortAllocatorSession::~P2PPortAllocatorSession() { |
| 92 if (stun_address_request_) | 92 if (stun_address_request_) |
| 93 stun_address_request_->Cancel(); | 93 stun_address_request_->Cancel(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 118 | 118 |
| 119 LOG(ERROR) << "Relay session request failed."; | 119 LOG(ERROR) << "Relay session request failed."; |
| 120 | 120 |
| 121 // Retry the request. | 121 // Retry the request. |
| 122 AllocateRelaySession(); | 122 AllocateRelaySession(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void P2PPortAllocatorSession::GetPortConfigurations() { | 125 void P2PPortAllocatorSession::GetPortConfigurations() { |
| 126 // Add an empty configuration synchronously, so a local connection | 126 // Add an empty configuration synchronously, so a local connection |
| 127 // can be started immediately. | 127 // can be started immediately. |
| 128 ConfigReady(new cricket::PortConfiguration( | 128 ConfigReady(new cricket::PortConfiguration(talk_base::SocketAddress())); |
| 129 talk_base::SocketAddress(), username(), password(), "")); | |
| 130 | 129 |
| 131 ResolveStunServerAddress(); | 130 ResolveStunServerAddress(); |
| 132 AllocateRelaySession(); | 131 AllocateRelaySession(); |
| 133 } | 132 } |
| 134 | 133 |
| 135 void P2PPortAllocatorSession::ResolveStunServerAddress() { | 134 void P2PPortAllocatorSession::ResolveStunServerAddress() { |
| 136 if (allocator_->config_.stun_server.empty()) | 135 if (allocator_->config_.stun_server.empty()) |
| 137 return; | 136 return; |
| 138 | 137 |
| 139 DCHECK(!stun_address_request_); | 138 DCHECK(!stun_address_request_); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 request.setURL(WebURL(GURL(url))); | 213 request.setURL(WebURL(GURL(url))); |
| 215 request.setAllowStoredCredentials(false); | 214 request.setAllowStoredCredentials(false); |
| 216 request.setCachePolicy(WebURLRequest::ReloadIgnoringCacheData); | 215 request.setCachePolicy(WebURLRequest::ReloadIgnoringCacheData); |
| 217 request.setHTTPMethod("GET"); | 216 request.setHTTPMethod("GET"); |
| 218 request.addHTTPHeaderField( | 217 request.addHTTPHeaderField( |
| 219 WebString::fromUTF8("X-Talk-Google-Relay-Auth"), | 218 WebString::fromUTF8("X-Talk-Google-Relay-Auth"), |
| 220 WebString::fromUTF8(allocator_->config_.relay_password)); | 219 WebString::fromUTF8(allocator_->config_.relay_password)); |
| 221 request.addHTTPHeaderField( | 220 request.addHTTPHeaderField( |
| 222 WebString::fromUTF8("X-Google-Relay-Auth"), | 221 WebString::fromUTF8("X-Google-Relay-Auth"), |
| 223 WebString::fromUTF8(allocator_->config_.relay_password)); | 222 WebString::fromUTF8(allocator_->config_.relay_password)); |
| 224 request.addHTTPHeaderField(WebString::fromUTF8("X-Session-Type"), | |
| 225 WebString::fromUTF8(session_type())); | |
| 226 request.addHTTPHeaderField(WebString::fromUTF8("X-Stream-Type"), | 223 request.addHTTPHeaderField(WebString::fromUTF8("X-Stream-Type"), |
| 227 WebString::fromUTF8(name())); | 224 WebString::fromUTF8(channel_name())); |
| 228 | 225 |
| 229 relay_session_request_->loadAsynchronously(request, this); | 226 relay_session_request_->loadAsynchronously(request, this); |
| 230 } | 227 } |
| 231 | 228 |
| 232 void P2PPortAllocatorSession::ParseRelayResponse() { | 229 void P2PPortAllocatorSession::ParseRelayResponse() { |
| 233 std::vector<std::pair<std::string, std::string> > value_pairs; | 230 std::vector<std::pair<std::string, std::string> > value_pairs; |
| 234 if (!base::SplitStringIntoKeyValuePairs(relay_session_response_, '=', '\n', | 231 if (!base::SplitStringIntoKeyValuePairs(relay_session_response_, '=', '\n', |
| 235 &value_pairs)) { | 232 &value_pairs)) { |
| 236 LOG(ERROR) << "Received invalid response from relay server"; | 233 LOG(ERROR) << "Received invalid response from relay server"; |
| 237 return; | 234 return; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 if (!ParsePortNumber(value, &relay_ssltcp_port_)) | 275 if (!ParsePortNumber(value, &relay_ssltcp_port_)) |
| 279 return; | 276 return; |
| 280 } | 277 } |
| 281 } | 278 } |
| 282 | 279 |
| 283 AddConfig(); | 280 AddConfig(); |
| 284 } | 281 } |
| 285 | 282 |
| 286 void P2PPortAllocatorSession::AddConfig() { | 283 void P2PPortAllocatorSession::AddConfig() { |
| 287 cricket::PortConfiguration* config = | 284 cricket::PortConfiguration* config = |
| 288 new cricket::PortConfiguration(stun_server_address_, | 285 new cricket::PortConfiguration(stun_server_address_); |
| 289 username(), password(), ""); | |
| 290 | 286 |
| 291 if (relay_ip_.ip() != 0) { | 287 if (relay_ip_.ip() != 0) { |
| 292 cricket::PortConfiguration::PortList ports; | 288 cricket::PortConfiguration::PortList ports; |
| 293 if (relay_udp_port_ > 0) { | 289 if (relay_udp_port_ > 0) { |
| 294 talk_base::SocketAddress address(relay_ip_.ip(), relay_udp_port_); | 290 talk_base::SocketAddress address(relay_ip_.ip(), relay_udp_port_); |
| 295 ports.push_back(cricket::ProtocolAddress(address, cricket::PROTO_UDP)); | 291 ports.push_back(cricket::ProtocolAddress(address, cricket::PROTO_UDP)); |
| 296 } | 292 } |
| 297 if (relay_tcp_port_ > 0 && !allocator_->config_.disable_tcp_transport) { | 293 if (relay_tcp_port_ > 0 && !allocator_->config_.disable_tcp_transport) { |
| 298 talk_base::SocketAddress address(relay_ip_.ip(), relay_tcp_port_); | 294 talk_base::SocketAddress address(relay_ip_.ip(), relay_tcp_port_); |
| 299 ports.push_back(cricket::ProtocolAddress(address, cricket::PROTO_TCP)); | 295 ports.push_back(cricket::ProtocolAddress(address, cricket::PROTO_TCP)); |
| 300 } | 296 } |
| 301 if (relay_ssltcp_port_ > 0 && !allocator_->config_.disable_tcp_transport) { | 297 if (relay_ssltcp_port_ > 0 && !allocator_->config_.disable_tcp_transport) { |
| 302 talk_base::SocketAddress address(relay_ip_.ip(), relay_ssltcp_port_); | 298 talk_base::SocketAddress address(relay_ip_.ip(), relay_ssltcp_port_); |
| 303 ports.push_back(cricket::ProtocolAddress(address, cricket::PROTO_SSLTCP)); | 299 ports.push_back(cricket::ProtocolAddress(address, cricket::PROTO_SSLTCP)); |
| 304 } | 300 } |
| 305 if (!ports.empty()) | 301 if (!ports.empty()) |
| 306 config->AddRelay(ports, 0.0f); | 302 config->AddRelay(ports, 0.0f); |
| 307 } | 303 } |
| 308 ConfigReady(config); | 304 ConfigReady(config); |
| 309 } | 305 } |
| 310 | 306 |
| 311 } // namespace content | 307 } // namespace content |
| OLD | NEW |