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

Side by Side Diff: webrtc/p2p/base/turnport.cc

Issue 2068263003: Do not delete a connection in the turn port with permission error or refresh error. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: . Created 4 years, 6 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
OLDNEW
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 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 for (size_t index = 0; index < Candidates().size(); ++index) { 462 for (size_t index = 0; index < Candidates().size(); ++index) {
463 if (Candidates()[index].type() == RELAY_PORT_TYPE) { 463 if (Candidates()[index].type() == RELAY_PORT_TYPE) {
464 ProxyConnection* conn = new ProxyConnection(this, index, address); 464 ProxyConnection* conn = new ProxyConnection(this, index, address);
465 AddOrReplaceConnection(conn); 465 AddOrReplaceConnection(conn);
466 return conn; 466 return conn;
467 } 467 }
468 } 468 }
469 return NULL; 469 return NULL;
470 } 470 }
471 471
472 bool TurnPort::DestroyConnection(const rtc::SocketAddress& address) { 472 bool TurnPort::FailAndPruneConnection(const rtc::SocketAddress& address) {
473 Connection* conn = GetConnection(address); 473 Connection* conn = GetConnection(address);
474 if (conn != nullptr) { 474 if (conn != nullptr) {
475 conn->Destroy(); 475 conn->FailAndPrune();
476 return true; 476 return true;
477 } 477 }
478 return false; 478 return false;
479 } 479 }
480 480
481 int TurnPort::SetOption(rtc::Socket::Option opt, int value) { 481 int TurnPort::SetOption(rtc::Socket::Option opt, int value) {
482 if (!socket_) { 482 if (!socket_) {
483 // If socket is not created yet, these options will be applied during socket 483 // If socket is not created yet, these options will be applied during socket
484 // creation. 484 // creation.
485 socket_options_[opt] = value; 485 socket_options_[opt] = value;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 } 554 }
555 555
556 // The message must be at least the size of a channel header. 556 // The message must be at least the size of a channel header.
557 if (size < TURN_CHANNEL_HEADER_SIZE) { 557 if (size < TURN_CHANNEL_HEADER_SIZE) {
558 LOG_J(LS_WARNING, this) << "Received TURN message that was too short"; 558 LOG_J(LS_WARNING, this) << "Received TURN message that was too short";
559 return false; 559 return false;
560 } 560 }
561 561
562 if (state_ == STATE_DISCONNECTED) { 562 if (state_ == STATE_DISCONNECTED) {
563 LOG_J(LS_WARNING, this) 563 LOG_J(LS_WARNING, this)
564 << "Received TURN message while the Turn port is disconnected"; 564 << "Received TURN message while the Turn port is disconnected";
pthatcher1 2016/06/16 22:34:21 Why would we still process packets if we're STATE_
honghaiz3 2016/06/16 23:22:53 Turn port becomes disconnected if there is a refre
pthatcher1 2016/06/21 06:58:26 See my comment blow about making a refresh error n
honghaiz3 2016/06/22 01:50:40 Changed it back.
565 return false;
566 } 565 }
567 566
568 // Check the message type, to see if is a Channel Data message. 567 // Check the message type, to see if is a Channel Data message.
569 // The message will either be channel data, a TURN data indication, or 568 // The message will either be channel data, a TURN data indication, or
570 // a response to a previous request. 569 // a response to a previous request.
571 uint16_t msg_type = rtc::GetBE16(data); 570 uint16_t msg_type = rtc::GetBE16(data);
572 if (IsTurnChannelData(msg_type)) { 571 if (IsTurnChannelData(msg_type)) {
573 HandleChannelData(msg_type, data, size, packet_time); 572 HandleChannelData(msg_type, data, size, packet_time);
574 return true; 573 return true;
575 574
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 747
749 void TurnPort::Close() { 748 void TurnPort::Close() {
750 if (!ready()) { 749 if (!ready()) {
751 OnAllocateError(); 750 OnAllocateError();
752 } 751 }
753 request_manager_.Clear(); 752 request_manager_.Clear();
754 // Stop the port from creating new connections. 753 // Stop the port from creating new connections.
755 state_ = STATE_DISCONNECTED; 754 state_ = STATE_DISCONNECTED;
756 // Delete all existing connections; stop sending data. 755 // Delete all existing connections; stop sending data.
757 for (auto kv : connections()) { 756 for (auto kv : connections()) {
758 kv.second->Destroy(); 757 kv.second->FailAndPrune();
pthatcher1 2016/06/16 22:34:21 Shouldn't this Destroy() still, since the whole Po
honghaiz3 2016/06/16 23:22:53 We may enter this in two cases: 1. Socket error,
pthatcher1 2016/06/21 06:58:26 Yes. A socket close is fatal. A refresh is perha
honghaiz3 2016/06/22 01:50:40 Done.
759 } 758 }
760 } 759 }
761 760
762 void TurnPort::OnMessage(rtc::Message* message) { 761 void TurnPort::OnMessage(rtc::Message* message) {
763 switch (message->message_id) { 762 switch (message->message_id) {
764 case MSG_ALLOCATE_ERROR: 763 case MSG_ALLOCATE_ERROR:
765 SignalPortError(this); 764 SignalPortError(this);
766 break; 765 break;
767 case MSG_ALLOCATE_MISMATCH: 766 case MSG_ALLOCATE_MISMATCH:
768 OnAllocateMismatch(); 767 OnAllocateMismatch();
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after
1484 << delay << "ms."; 1483 << delay << "ms.";
1485 } 1484 }
1486 } 1485 }
1487 1486
1488 void TurnEntry::OnCreatePermissionError(StunMessage* response, int code) { 1487 void TurnEntry::OnCreatePermissionError(StunMessage* response, int code) {
1489 if (code == STUN_ERROR_STALE_NONCE) { 1488 if (code == STUN_ERROR_STALE_NONCE) {
1490 if (port_->UpdateNonce(response)) { 1489 if (port_->UpdateNonce(response)) {
1491 SendCreatePermissionRequest(0); 1490 SendCreatePermissionRequest(0);
1492 } 1491 }
1493 } else { 1492 } else {
1494 port_->DestroyConnection(ext_addr_); 1493 bool found = port_->FailAndPruneConnection(ext_addr_);
1494 if (found) {
1495 LOG(LS_ERROR) << "Received TURN CreatePermission error response, "
1496 << "code=" << code << "; pruned connection.";
1497 }
1495 // Send signal with error code. 1498 // Send signal with error code.
1496 port_->SignalCreatePermissionResult(port_, ext_addr_, code); 1499 port_->SignalCreatePermissionResult(port_, ext_addr_, code);
1497 Connection* c = port_->GetConnection(ext_addr_);
1498 if (c) {
1499 LOG_J(LS_ERROR, c) << "Received TURN CreatePermission error response, "
1500 << "code=" << code << "; killing connection.";
1501 c->FailAndDestroy();
1502 }
1503 } 1500 }
1504 } 1501 }
1505 1502
1506 void TurnEntry::OnCreatePermissionTimeout() { 1503 void TurnEntry::OnCreatePermissionTimeout() {
1507 port_->DestroyConnection(ext_addr_); 1504 port_->FailAndPruneConnection(ext_addr_);
1508 } 1505 }
1509 1506
1510 void TurnEntry::OnChannelBindSuccess() { 1507 void TurnEntry::OnChannelBindSuccess() {
1511 LOG_J(LS_INFO, port_) << "Channel bind for " << ext_addr_.ToSensitiveString() 1508 LOG_J(LS_INFO, port_) << "Channel bind for " << ext_addr_.ToSensitiveString()
1512 << " succeeded"; 1509 << " succeeded";
1513 ASSERT(state_ == STATE_BINDING || state_ == STATE_BOUND); 1510 ASSERT(state_ == STATE_BINDING || state_ == STATE_BOUND);
1514 state_ = STATE_BOUND; 1511 state_ = STATE_BOUND;
1515 } 1512 }
1516 1513
1517 void TurnEntry::OnChannelBindError(StunMessage* response, int code) { 1514 void TurnEntry::OnChannelBindError(StunMessage* response, int code) {
1518 // If the channel bind fails due to errors other than STATE_NONCE, 1515 // If the channel bind fails due to errors other than STATE_NONCE,
1519 // we just destroy the connection and rely on ICE restart to re-establish 1516 // we will fail and prune the connection and rely on ICE restart to
1520 // the connection. 1517 // re-establish a new connection if needed.
1521 if (code == STUN_ERROR_STALE_NONCE) { 1518 if (code == STUN_ERROR_STALE_NONCE) {
1522 if (port_->UpdateNonce(response)) { 1519 if (port_->UpdateNonce(response)) {
1523 // Send channel bind request with fresh nonce. 1520 // Send channel bind request with fresh nonce.
1524 SendChannelBindRequest(0); 1521 SendChannelBindRequest(0);
1525 } 1522 }
1526 } else { 1523 } else {
1527 state_ = STATE_UNBOUND; 1524 state_ = STATE_UNBOUND;
1528 port_->DestroyConnection(ext_addr_); 1525 port_->FailAndPruneConnection(ext_addr_);
pthatcher1 2016/06/16 22:34:21 Shouldn't we differentiate between different error
honghaiz3 2016/06/16 23:22:53 I guess the question is if there is a binding erro
pthatcher1 2016/06/21 06:58:26 Good point. These all seem non-fatal. But the so
honghaiz3 2016/06/22 01:50:40 Acknowledged.
1529 } 1526 }
1530 } 1527 }
1531 void TurnEntry::OnChannelBindTimeout() { 1528 void TurnEntry::OnChannelBindTimeout() {
1532 state_ = STATE_UNBOUND; 1529 state_ = STATE_UNBOUND;
1533 port_->DestroyConnection(ext_addr_); 1530 port_->FailAndPruneConnection(ext_addr_);
1534 } 1531 }
1535 } // namespace cricket 1532 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698