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

Side by Side Diff: content/renderer/p2p/port_allocator.cc

Issue 10069046: Libjingle roll 129:132. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 "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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(
129 talk_base::SocketAddress(), "", "", "")); 129 talk_base::SocketAddress(), username(), password(), ""));
130 130
131 ResolveStunServerAddress(); 131 ResolveStunServerAddress();
132 AllocateRelaySession(); 132 AllocateRelaySession();
133 } 133 }
134 134
135 void P2PPortAllocatorSession::ResolveStunServerAddress() { 135 void P2PPortAllocatorSession::ResolveStunServerAddress() {
136 if (allocator_->config_.stun_server.empty()) 136 if (allocator_->config_.stun_server.empty())
137 return; 137 return;
138 138
139 DCHECK(!stun_address_request_); 139 DCHECK(!stun_address_request_);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 WebURLLoaderOptions::CrossOriginRequestPolicyAllow; 186 WebURLLoaderOptions::CrossOriginRequestPolicyAllow;
187 187
188 relay_session_request_.reset( 188 relay_session_request_.reset(
189 allocator_->web_frame_->createAssociatedURLLoader(options)); 189 allocator_->web_frame_->createAssociatedURLLoader(options));
190 if (!relay_session_request_.get()) { 190 if (!relay_session_request_.get()) {
191 LOG(ERROR) << "Failed to create URL loader."; 191 LOG(ERROR) << "Failed to create URL loader.";
192 return; 192 return;
193 } 193 }
194 194
195 std::string url = "https://" + allocator_->config_.relay_server + 195 std::string url = "https://" + allocator_->config_.relay_server +
196 kCreateRelaySessionURL; 196 kCreateRelaySessionURL + "?username=" + username() +
197 "&password=" + password();
Wez 2012/04/13 02:49:49 Are username() and password() URL-escaped, or guar
Sergey Ulanov 2012/04/13 19:50:38 That's a good catch! PortAllocator uses Base64 alp
197 198
198 // Use |relay_username| parameter to identify type of client for the 199 // Use |relay_username| parameter to identify type of client for the
199 // relay session. 200 // relay session.
200 // 201 //
201 // TODO(sergeyu): Username is not used for legacy non-TURN relay 202 // TODO(sergeyu): Username is not used for legacy non-TURN relay
202 // servers, so we reuse it here to identify relay client type. This 203 // servers, so we reuse it here to identify relay client type. This
203 // is currently used for Chromoting only. This code should be removed 204 // is currently used for Chromoting only. This code should be removed
204 // once Chromoting stops using Transport API and the API is removed. 205 // once Chromoting stops using Transport API and the API is removed.
205 if (!allocator_->config_.relay_username.empty()) { 206 if (!allocator_->config_.relay_username.empty()) {
206 url += "?sn=" + 207 url += "?sn=" +
(...skipping 21 matching lines...) Expand all
228 } 229 }
229 230
230 void P2PPortAllocatorSession::ParseRelayResponse() { 231 void P2PPortAllocatorSession::ParseRelayResponse() {
231 std::vector<std::pair<std::string, std::string> > value_pairs; 232 std::vector<std::pair<std::string, std::string> > value_pairs;
232 if (!base::SplitStringIntoKeyValuePairs(relay_session_response_, '=', '\n', 233 if (!base::SplitStringIntoKeyValuePairs(relay_session_response_, '=', '\n',
233 &value_pairs)) { 234 &value_pairs)) {
234 LOG(ERROR) << "Received invalid response from relay server"; 235 LOG(ERROR) << "Received invalid response from relay server";
235 return; 236 return;
236 } 237 }
237 238
238 relay_username_.clear();
239 relay_password_.clear();
240 relay_ip_.Clear(); 239 relay_ip_.Clear();
241 relay_udp_port_ = 0; 240 relay_udp_port_ = 0;
242 relay_tcp_port_ = 0; 241 relay_tcp_port_ = 0;
243 relay_ssltcp_port_ = 0; 242 relay_ssltcp_port_ = 0;
244 243
245 for (std::vector<std::pair<std::string, std::string> >::iterator 244 for (std::vector<std::pair<std::string, std::string> >::iterator
246 it = value_pairs.begin(); 245 it = value_pairs.begin();
247 it != value_pairs.end(); ++it) { 246 it != value_pairs.end(); ++it) {
248 std::string key; 247 std::string key;
249 std::string value; 248 std::string value;
250 TrimWhitespaceASCII(it->first, TRIM_ALL, &key); 249 TrimWhitespaceASCII(it->first, TRIM_ALL, &key);
251 TrimWhitespaceASCII(it->second, TRIM_ALL, &value); 250 TrimWhitespaceASCII(it->second, TRIM_ALL, &value);
252 251
253 if (key == "username") { 252 if (key == "username") {
254 relay_username_ = value; 253 if (value != username()) {
254 LOG(WARNING) << "When creating relay session received "
255 " user name that was specified in the query";
Wez 2012/04/13 02:49:49 I don't understand this error message. This is th
Sergey Ulanov 2012/04/13 19:50:38 Right. Previously username/password were generated
Wez 2012/04/13 22:26:04 In that case, should we fail this port allocator i
Sergey Ulanov 2012/04/13 22:30:28 Done.
256 }
255 } else if (key == "password") { 257 } else if (key == "password") {
256 relay_password_ = value; 258 if (value != password()) {
259 LOG(WARNING) << "When creating relay session received "
260 " user name that was specified in the query";
Wez 2012/04/13 02:49:49 typo: "user name" -> "password"
Sergey Ulanov 2012/04/13 19:50:38 Done.
261 }
257 } else if (key == "relay.ip") { 262 } else if (key == "relay.ip") {
258 relay_ip_.SetIP(value); 263 relay_ip_.SetIP(value);
259 if (relay_ip_.ip() == 0) { 264 if (relay_ip_.ip() == 0) {
260 LOG(ERROR) << "Received unresolved relay server address: " << value; 265 LOG(ERROR) << "Received unresolved relay server address: " << value;
261 return; 266 return;
262 } 267 }
263 } else if (key == "relay.udp_port") { 268 } else if (key == "relay.udp_port") {
264 if (!ParsePortNumber(value, &relay_udp_port_)) 269 if (!ParsePortNumber(value, &relay_udp_port_))
265 return; 270 return;
266 } else if (key == "relay.tcp_port") { 271 } else if (key == "relay.tcp_port") {
267 if (!ParsePortNumber(value, &relay_tcp_port_)) 272 if (!ParsePortNumber(value, &relay_tcp_port_))
268 return; 273 return;
269 } else if (key == "relay.ssltcp_port") { 274 } else if (key == "relay.ssltcp_port") {
270 if (!ParsePortNumber(value, &relay_ssltcp_port_)) 275 if (!ParsePortNumber(value, &relay_ssltcp_port_))
271 return; 276 return;
272 } 277 }
273 } 278 }
274 279
275 AddConfig(); 280 AddConfig();
276 } 281 }
277 282
278 void P2PPortAllocatorSession::AddConfig() { 283 void P2PPortAllocatorSession::AddConfig() {
279 cricket::PortConfiguration* config = 284 cricket::PortConfiguration* config =
280 new cricket::PortConfiguration(stun_server_address_, 285 new cricket::PortConfiguration(stun_server_address_,
281 relay_username_, relay_password_, ""); 286 username(), password(), "");
282 287
283 if (relay_ip_.ip() != 0) { 288 if (relay_ip_.ip() != 0) {
284 cricket::PortConfiguration::PortList ports; 289 cricket::PortConfiguration::PortList ports;
285 if (relay_udp_port_ > 0) { 290 if (relay_udp_port_ > 0) {
286 talk_base::SocketAddress address(relay_ip_.ip(), relay_udp_port_); 291 talk_base::SocketAddress address(relay_ip_.ip(), relay_udp_port_);
287 ports.push_back(cricket::ProtocolAddress(address, cricket::PROTO_UDP)); 292 ports.push_back(cricket::ProtocolAddress(address, cricket::PROTO_UDP));
288 } 293 }
289 if (relay_tcp_port_ > 0 && !allocator_->config_.disable_tcp_transport) { 294 if (relay_tcp_port_ > 0 && !allocator_->config_.disable_tcp_transport) {
290 talk_base::SocketAddress address(relay_ip_.ip(), relay_tcp_port_); 295 talk_base::SocketAddress address(relay_ip_.ip(), relay_tcp_port_);
291 ports.push_back(cricket::ProtocolAddress(address, cricket::PROTO_TCP)); 296 ports.push_back(cricket::ProtocolAddress(address, cricket::PROTO_TCP));
292 } 297 }
293 if (relay_ssltcp_port_ > 0 && !allocator_->config_.disable_tcp_transport) { 298 if (relay_ssltcp_port_ > 0 && !allocator_->config_.disable_tcp_transport) {
294 talk_base::SocketAddress address(relay_ip_.ip(), relay_ssltcp_port_); 299 talk_base::SocketAddress address(relay_ip_.ip(), relay_ssltcp_port_);
295 ports.push_back(cricket::ProtocolAddress(address, cricket::PROTO_SSLTCP)); 300 ports.push_back(cricket::ProtocolAddress(address, cricket::PROTO_SSLTCP));
296 } 301 }
297 if (!ports.empty()) 302 if (!ports.empty())
298 config->AddRelay(ports, 0.0f); 303 config->AddRelay(ports, 0.0f);
299 } 304 }
300 ConfigReady(config); 305 ConfigReady(config);
301 } 306 }
302 307
303 } // namespace content 308 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698