Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 284 server_address_.address.SetPort(TURN_DEFAULT_PORT); | 284 server_address_.address.SetPort(TURN_DEFAULT_PORT); |
| 285 } | 285 } |
| 286 | 286 |
| 287 if (server_address_.address.IsUnresolvedIP()) { | 287 if (server_address_.address.IsUnresolvedIP()) { |
| 288 ResolveTurnAddress(server_address_.address); | 288 ResolveTurnAddress(server_address_.address); |
| 289 } else { | 289 } else { |
| 290 // If protocol family of server address doesn't match with local, return. | 290 // If protocol family of server address doesn't match with local, return. |
| 291 if (!IsCompatibleAddress(server_address_.address)) { | 291 if (!IsCompatibleAddress(server_address_.address)) { |
| 292 LOG(LS_ERROR) << "IP address family does not match: " | 292 LOG(LS_ERROR) << "IP address family does not match: " |
| 293 << "server: " << server_address_.address.family() | 293 << "server: " << server_address_.address.family() |
| 294 << "local: " << ip().family(); | 294 << " local: " << ip().family(); |
| 295 OnAllocateError(); | 295 OnAllocateError(); |
| 296 return; | 296 return; |
| 297 } | 297 } |
| 298 | 298 |
| 299 // Insert the current address to prevent redirection pingpong. | 299 // Insert the current address to prevent redirection pingpong. |
| 300 attempted_server_addresses_.insert(server_address_.address); | 300 attempted_server_addresses_.insert(server_address_.address); |
| 301 | 301 |
| 302 LOG_J(LS_INFO, this) << "Trying to connect to TURN server via " | 302 LOG_J(LS_INFO, this) << "Trying to connect to TURN server via " |
| 303 << ProtoToString(server_address_.proto) << " @ " | 303 << ProtoToString(server_address_.proto) << " @ " |
| 304 << server_address_.address.ToSensitiveString(); | 304 << server_address_.address.ToSensitiveString(); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 431 } else { | 431 } else { |
| 432 delete socket_; | 432 delete socket_; |
| 433 } | 433 } |
| 434 socket_ = NULL; | 434 socket_ = NULL; |
| 435 | 435 |
| 436 ResetNonce(); | 436 ResetNonce(); |
| 437 PrepareAddress(); | 437 PrepareAddress(); |
| 438 ++allocate_mismatch_retries_; | 438 ++allocate_mismatch_retries_; |
| 439 } | 439 } |
| 440 | 440 |
| 441 Connection* TurnPort::CreateConnection(const Candidate& address, | 441 Connection* TurnPort::CreateConnection(const Candidate& remote_candidate, |
| 442 CandidateOrigin origin) { | 442 CandidateOrigin origin) { |
| 443 // TURN-UDP can only connect to UDP candidates. | 443 // TURN-UDP can only connect to UDP candidates. |
| 444 if (!SupportsProtocol(address.protocol())) { | 444 if (!SupportsProtocol(remote_candidate.protocol())) { |
| 445 return NULL; | 445 return NULL; |
| 446 } | 446 } |
| 447 | 447 |
| 448 if (!IsCompatibleAddress(address.address())) { | |
| 449 return NULL; | |
| 450 } | |
| 451 | |
| 452 if (state_ == STATE_DISCONNECTED) { | 448 if (state_ == STATE_DISCONNECTED) { |
| 453 return NULL; | 449 return NULL; |
| 454 } | 450 } |
| 455 | 451 |
| 456 // Create an entry, if needed, so we can get our permissions set up correctly. | 452 // Create an entry, if needed, so we can get our permissions set up correctly. |
| 457 CreateOrRefreshEntry(address.address()); | 453 CreateOrRefreshEntry(remote_candidate.address()); |
| 458 | 454 |
| 459 // A TURN port will have two candiates, STUN and TURN. STUN may not | 455 // A TURN port will have two candiates, STUN and TURN. STUN may not |
| 460 // present in all cases. If present stun candidate will be added first | 456 // present in all cases. If present stun candidate will be added first |
| 461 // and TURN candidate later. | 457 // and TURN candidate later. |
| 462 for (size_t index = 0; index < Candidates().size(); ++index) { | 458 for (size_t index = 0; index < Candidates().size(); ++index) { |
| 463 if (Candidates()[index].type() == RELAY_PORT_TYPE) { | 459 const Candidate& local_candidate = Candidates()[index]; |
| 464 ProxyConnection* conn = new ProxyConnection(this, index, address); | 460 if (local_candidate.type() == RELAY_PORT_TYPE && |
| 461 AddressFamilyMatch(local_candidate, remote_candidate)) { | |
| 462 ProxyConnection* conn = | |
| 463 new ProxyConnection(this, index, remote_candidate); | |
| 465 AddOrReplaceConnection(conn); | 464 AddOrReplaceConnection(conn); |
| 466 return conn; | 465 return conn; |
| 467 } | 466 } |
| 468 } | 467 } |
| 469 return NULL; | 468 return NULL; |
| 470 } | 469 } |
| 471 | 470 |
| 472 bool TurnPort::DestroyConnection(const rtc::SocketAddress& address) { | 471 bool TurnPort::DestroyConnection(const rtc::SocketAddress& address) { |
| 473 Connection* conn = GetConnection(address); | 472 Connection* conn = GetConnection(address); |
| 474 if (conn != nullptr) { | 473 if (conn != nullptr) { |
| 475 conn->Destroy(); | 474 conn->Destroy(); |
| 476 return true; | 475 return true; |
| 477 } | 476 } |
| 478 return false; | 477 return false; |
| 479 } | 478 } |
| 480 | 479 |
| 480 bool TurnPort::AddressFamilyMatch(const Candidate& local_candidate, | |
| 481 const Candidate& remote_candidate) const { | |
|
pthatcher1
2016/06/21 05:26:54
This can just be a static function. It doesn't ne
honghaiz3
2016/06/21 18:36:06
Just inlined it.
| |
| 482 return local_candidate.address().family() == | |
| 483 remote_candidate.address().family(); | |
| 484 } | |
| 485 | |
| 481 int TurnPort::SetOption(rtc::Socket::Option opt, int value) { | 486 int TurnPort::SetOption(rtc::Socket::Option opt, int value) { |
| 482 if (!socket_) { | 487 if (!socket_) { |
| 483 // If socket is not created yet, these options will be applied during socket | 488 // If socket is not created yet, these options will be applied during socket |
| 484 // creation. | 489 // creation. |
| 485 socket_options_[opt] = value; | 490 socket_options_[opt] = value; |
| 486 return 0; | 491 return 0; |
| 487 } | 492 } |
| 488 return socket_->SetOption(opt, value); | 493 return socket_->SetOption(opt, value); |
| 489 } | 494 } |
| 490 | 495 |
| (...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1526 } else { | 1531 } else { |
| 1527 state_ = STATE_UNBOUND; | 1532 state_ = STATE_UNBOUND; |
| 1528 port_->DestroyConnection(ext_addr_); | 1533 port_->DestroyConnection(ext_addr_); |
| 1529 } | 1534 } |
| 1530 } | 1535 } |
| 1531 void TurnEntry::OnChannelBindTimeout() { | 1536 void TurnEntry::OnChannelBindTimeout() { |
| 1532 state_ = STATE_UNBOUND; | 1537 state_ = STATE_UNBOUND; |
| 1533 port_->DestroyConnection(ext_addr_); | 1538 port_->DestroyConnection(ext_addr_); |
| 1534 } | 1539 } |
| 1535 } // namespace cricket | 1540 } // namespace cricket |
| OLD | NEW |