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

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

Issue 1376983002: Do not time out a port if its role switched from controlled to controlling. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « webrtc/p2p/base/port.h ('k') | webrtc/p2p/base/port_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 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 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 << retransmit_attr->value(); 559 << retransmit_attr->value();
560 } 560 }
561 } 561 }
562 562
563 response.AddAttribute( 563 response.AddAttribute(
564 new StunXorAddressAttribute(STUN_ATTR_XOR_MAPPED_ADDRESS, addr)); 564 new StunXorAddressAttribute(STUN_ATTR_XOR_MAPPED_ADDRESS, addr));
565 response.AddMessageIntegrity(password_); 565 response.AddMessageIntegrity(password_);
566 response.AddFingerprint(); 566 response.AddFingerprint();
567 567
568 // The fact that we received a successful request means that this connection 568 // The fact that we received a successful request means that this connection
569 // (if one exists) should now be readable. 569 // (if one exists) should now be receiving.
570 Connection* conn = GetConnection(addr); 570 Connection* conn = GetConnection(addr);
571 571
572 // Send the response message. 572 // Send the response message.
573 rtc::ByteBuffer buf; 573 rtc::ByteBuffer buf;
574 response.Write(&buf); 574 response.Write(&buf);
575 rtc::PacketOptions options(DefaultDscpValue()); 575 rtc::PacketOptions options(DefaultDscpValue());
576 auto err = SendTo(buf.Data(), buf.Length(), addr, options, false); 576 auto err = SendTo(buf.Data(), buf.Length(), addr, options, false);
577 if (err < 0) { 577 if (err < 0) {
578 LOG_J(LS_ERROR, this) 578 LOG_J(LS_ERROR, this)
579 << "Failed to send STUN ping response" 579 << "Failed to send STUN ping response"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 // Send the response message. 623 // Send the response message.
624 rtc::ByteBuffer buf; 624 rtc::ByteBuffer buf;
625 response.Write(&buf); 625 response.Write(&buf);
626 rtc::PacketOptions options(DefaultDscpValue()); 626 rtc::PacketOptions options(DefaultDscpValue());
627 SendTo(buf.Data(), buf.Length(), addr, options, false); 627 SendTo(buf.Data(), buf.Length(), addr, options, false);
628 LOG_J(LS_INFO, this) << "Sending STUN binding error: reason=" << reason 628 LOG_J(LS_INFO, this) << "Sending STUN binding error: reason=" << reason
629 << " to " << addr.ToSensitiveString(); 629 << " to " << addr.ToSensitiveString();
630 } 630 }
631 631
632 void Port::OnMessage(rtc::Message *pmsg) { 632 void Port::OnMessage(rtc::Message *pmsg) {
633 ASSERT(pmsg->message_id == MSG_CHECKTIMEOUT); 633 ASSERT(pmsg->message_id == MSG_DEAD);
634 CheckTimeout(); 634 if (dead()) {
635 Destroy();
636 }
635 } 637 }
636 638
637 std::string Port::ToString() const { 639 std::string Port::ToString() const {
638 std::stringstream ss; 640 std::stringstream ss;
639 ss << "Port[" << content_name_ << ":" << component_ 641 ss << "Port[" << content_name_ << ":" << component_
640 << ":" << generation_ << ":" << type_ 642 << ":" << generation_ << ":" << type_
641 << ":" << network_->ToString() << "]"; 643 << ":" << network_->ToString() << "]";
642 return ss.str(); 644 return ss.str();
643 } 645 }
644 646
645 void Port::EnablePortPackets() { 647 void Port::EnablePortPackets() {
646 enable_port_packets_ = true; 648 enable_port_packets_ = true;
647 } 649 }
648 650
649 void Port::OnConnectionDestroyed(Connection* conn) { 651 void Port::OnConnectionDestroyed(Connection* conn) {
650 AddressMap::iterator iter = 652 AddressMap::iterator iter =
651 connections_.find(conn->remote_candidate().address()); 653 connections_.find(conn->remote_candidate().address());
652 ASSERT(iter != connections_.end()); 654 ASSERT(iter != connections_.end());
653 connections_.erase(iter); 655 connections_.erase(iter);
654 656
655 // On the controlled side, ports time out, but only after all connections 657 // On the controlled side, ports time out after all connections fail.
656 // fail. Note: If a new connection is added after this message is posted, 658 // Note: If a new connection is added after this message is posted, but it
657 // but it fails and is removed before kPortTimeoutDelay, then this message 659 // fails and is removed before kPortTimeoutDelay, then this message will
658 // will still cause the Port to be destroyed. 660 // still cause the Port to be destroyed.
659 if (ice_role_ == ICEROLE_CONTROLLED) 661 if (dead()) {
660 thread_->PostDelayed(timeout_delay_, this, MSG_CHECKTIMEOUT); 662 thread_->PostDelayed(timeout_delay_, this, MSG_DEAD);
663 }
661 } 664 }
662 665
663 void Port::Destroy() { 666 void Port::Destroy() {
664 ASSERT(connections_.empty()); 667 ASSERT(connections_.empty());
665 LOG_J(LS_INFO, this) << "Port deleted"; 668 LOG_J(LS_INFO, this) << "Port deleted";
666 SignalDestroyed(this); 669 SignalDestroyed(this);
667 delete this; 670 delete this;
668 } 671 }
669 672
670 void Port::CheckTimeout() {
671 ASSERT(ice_role_ == ICEROLE_CONTROLLED);
672 // If this port has no connections, then there's no reason to keep it around.
673 // When the connections time out (both read and write), they will delete
674 // themselves, so if we have any connections, they are either readable or
675 // writable (or still connecting).
676 if (connections_.empty())
677 Destroy();
678 }
679
680 const std::string Port::username_fragment() const { 673 const std::string Port::username_fragment() const {
681 return ice_username_fragment_; 674 return ice_username_fragment_;
682 } 675 }
683 676
684 // A ConnectionRequest is a simple STUN ping used to determine writability. 677 // A ConnectionRequest is a simple STUN ping used to determine writability.
685 class ConnectionRequest : public StunRequest { 678 class ConnectionRequest : public StunRequest {
686 public: 679 public:
687 explicit ConnectionRequest(Connection* connection) 680 explicit ConnectionRequest(Connection* connection)
688 : StunRequest(new IceMessage()), 681 : StunRequest(new IceMessage()),
689 connection_(connection) { 682 connection_(connection) {
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 if (!pruned_ && (write_state_ == STATE_WRITE_TIMEOUT)) { 904 if (!pruned_ && (write_state_ == STATE_WRITE_TIMEOUT)) {
912 LOG(LS_WARNING) << "Received a data packet on a timed-out Connection. " 905 LOG(LS_WARNING) << "Received a data packet on a timed-out Connection. "
913 << "Resetting state to STATE_WRITE_INIT."; 906 << "Resetting state to STATE_WRITE_INIT.";
914 set_write_state(STATE_WRITE_INIT); 907 set_write_state(STATE_WRITE_INIT);
915 } 908 }
916 } else if (!msg) { 909 } else if (!msg) {
917 // The packet was STUN, but failed a check and was handled internally. 910 // The packet was STUN, but failed a check and was handled internally.
918 } else { 911 } else {
919 // The packet is STUN and passed the Port checks. 912 // The packet is STUN and passed the Port checks.
920 // Perform our own checks to ensure this packet is valid. 913 // Perform our own checks to ensure this packet is valid.
921 // If this is a STUN request, then update the readable bit and respond. 914 // If this is a STUN request, then update the receiving bit and respond.
922 // If this is a STUN response, then update the writable bit. 915 // If this is a STUN response, then update the writable bit.
923 // Log at LS_INFO if we receive a ping on an unwritable connection. 916 // Log at LS_INFO if we receive a ping on an unwritable connection.
924 rtc::LoggingSeverity sev = (!writable() ? rtc::LS_INFO : rtc::LS_VERBOSE); 917 rtc::LoggingSeverity sev = (!writable() ? rtc::LS_INFO : rtc::LS_VERBOSE);
925 switch (msg->type()) { 918 switch (msg->type()) {
926 case STUN_BINDING_REQUEST: 919 case STUN_BINDING_REQUEST:
927 LOG_JV(sev, this) << "Received STUN ping" 920 LOG_JV(sev, this) << "Received STUN ping"
928 << ", id=" << rtc::hex_encode(msg->transaction_id()); 921 << ", id=" << rtc::hex_encode(msg->transaction_id());
929 922
930 if (remote_ufrag == remote_candidate_.username()) { 923 if (remote_ufrag == remote_candidate_.username()) {
931 // Check for role conflicts. 924 // Check for role conflicts.
932 if (!port_->MaybeIceRoleConflict(addr, msg.get(), remote_ufrag)) { 925 if (!port_->MaybeIceRoleConflict(addr, msg.get(), remote_ufrag)) {
933 // Received conflicting role from the peer. 926 // Received conflicting role from the peer.
934 LOG(LS_INFO) << "Received conflicting role from the peer."; 927 LOG(LS_INFO) << "Received conflicting role from the peer.";
935 return; 928 return;
936 } 929 }
937 930
938 // Incoming, validated stun request from remote peer. 931 // Incoming, validated stun request from remote peer.
939 // This call will also set the connection readable. 932 // This call will also set the connection receiving.
940 port_->SendBindingResponse(msg.get(), addr); 933 port_->SendBindingResponse(msg.get(), addr);
941 934
942 // If timed out sending writability checks, start up again 935 // If timed out sending writability checks, start up again
943 if (!pruned_ && (write_state_ == STATE_WRITE_TIMEOUT)) 936 if (!pruned_ && (write_state_ == STATE_WRITE_TIMEOUT))
944 set_write_state(STATE_WRITE_INIT); 937 set_write_state(STATE_WRITE_INIT);
945 938
946 if (port_->GetIceRole() == ICEROLE_CONTROLLED) { 939 if (port_->GetIceRole() == ICEROLE_CONTROLLED) {
947 const StunByteStringAttribute* use_candidate_attr = 940 const StunByteStringAttribute* use_candidate_attr =
948 msg->GetByteString(STUN_ATTR_USE_CANDIDATE); 941 msg->GetByteString(STUN_ATTR_USE_CANDIDATE);
949 if (use_candidate_attr) { 942 if (use_candidate_attr) {
(...skipping 19 matching lines...) Expand all
969 // id's match. 962 // id's match.
970 case STUN_BINDING_RESPONSE: 963 case STUN_BINDING_RESPONSE:
971 case STUN_BINDING_ERROR_RESPONSE: 964 case STUN_BINDING_ERROR_RESPONSE:
972 if (msg->ValidateMessageIntegrity( 965 if (msg->ValidateMessageIntegrity(
973 data, size, remote_candidate().password())) { 966 data, size, remote_candidate().password())) {
974 requests_.CheckResponse(msg.get()); 967 requests_.CheckResponse(msg.get());
975 } 968 }
976 // Otherwise silently discard the response message. 969 // Otherwise silently discard the response message.
977 break; 970 break;
978 971
979 // Remote end point sent an STUN indication instead of regular 972 // Remote end point sent an STUN indication instead of regular binding
980 // binding request. In this case |last_ping_received_| will be updated. 973 // request. In this case |last_ping_received_| will be updated but no
981 // Otherwise we can mark connection to read timeout. No response will be 974 // response will be sent.
982 // sent in this scenario.
983 case STUN_BINDING_INDICATION: 975 case STUN_BINDING_INDICATION:
984 ReceivedPing(); 976 ReceivedPing();
985 break; 977 break;
986 978
987 default: 979 default:
988 ASSERT(false); 980 ASSERT(false);
989 break; 981 break;
990 } 982 }
991 } 983 }
992 } 984 }
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
1295 remote_candidate_.address() == new_candidate.address() && 1287 remote_candidate_.address() == new_candidate.address() &&
1296 remote_candidate_.username() == new_candidate.username() && 1288 remote_candidate_.username() == new_candidate.username() &&
1297 remote_candidate_.password() == new_candidate.password() && 1289 remote_candidate_.password() == new_candidate.password() &&
1298 remote_candidate_.generation() == new_candidate.generation()) { 1290 remote_candidate_.generation() == new_candidate.generation()) {
1299 remote_candidate_ = new_candidate; 1291 remote_candidate_ = new_candidate;
1300 } 1292 }
1301 } 1293 }
1302 1294
1303 void Connection::OnMessage(rtc::Message *pmsg) { 1295 void Connection::OnMessage(rtc::Message *pmsg) {
1304 ASSERT(pmsg->message_id == MSG_DELETE); 1296 ASSERT(pmsg->message_id == MSG_DELETE);
1305 LOG_J(LS_INFO, this) << "Connection deleted due to read or write timeout"; 1297 LOG_J(LS_INFO, this) << "Connection deleted";
1306 SignalDestroyed(this); 1298 SignalDestroyed(this);
1307 delete this; 1299 delete this;
1308 } 1300 }
1309 1301
1310 uint32 Connection::last_received() { 1302 uint32 Connection::last_received() {
1311 return std::max(last_data_received_, 1303 return std::max(last_data_received_,
1312 std::max(last_ping_received_, last_ping_response_received_)); 1304 std::max(last_ping_received_, last_ping_response_received_));
1313 } 1305 }
1314 1306
1315 size_t Connection::recv_bytes_second() { 1307 size_t Connection::recv_bytes_second() {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1419 ASSERT(sent < 0); 1411 ASSERT(sent < 0);
1420 error_ = port_->GetError(); 1412 error_ = port_->GetError();
1421 sent_packets_discarded_++; 1413 sent_packets_discarded_++;
1422 } else { 1414 } else {
1423 send_rate_tracker_.AddSamples(sent); 1415 send_rate_tracker_.AddSamples(sent);
1424 } 1416 }
1425 return sent; 1417 return sent;
1426 } 1418 }
1427 1419
1428 } // namespace cricket 1420 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/base/port.h ('k') | webrtc/p2p/base/port_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698