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

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

Issue 2171183002: Remove ports that are not used by any channel after timeout (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: fix a comment Created 4 years, 5 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 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 // relies on it. If the username_fragment and password are empty, 191 // relies on it. If the username_fragment and password are empty,
192 // we should just create one. 192 // we should just create one.
193 if (ice_username_fragment_.empty()) { 193 if (ice_username_fragment_.empty()) {
194 ASSERT(password_.empty()); 194 ASSERT(password_.empty());
195 ice_username_fragment_ = rtc::CreateRandomString(ICE_UFRAG_LENGTH); 195 ice_username_fragment_ = rtc::CreateRandomString(ICE_UFRAG_LENGTH);
196 password_ = rtc::CreateRandomString(ICE_PWD_LENGTH); 196 password_ = rtc::CreateRandomString(ICE_PWD_LENGTH);
197 } 197 }
198 network_->SignalTypeChanged.connect(this, &Port::OnNetworkTypeChanged); 198 network_->SignalTypeChanged.connect(this, &Port::OnNetworkTypeChanged);
199 network_cost_ = network_->GetCost(); 199 network_cost_ = network_->GetCost();
200 200
201 thread_->PostDelayed(RTC_FROM_HERE, timeout_delay_, this, MSG_CHECK_DEAD);
201 LOG_J(LS_INFO, this) << "Port created with network cost " << network_cost_; 202 LOG_J(LS_INFO, this) << "Port created with network cost " << network_cost_;
202 } 203 }
203 204
204 Port::~Port() { 205 Port::~Port() {
205 // Delete all of the remaining connections. We copy the list up front 206 // Delete all of the remaining connections. We copy the list up front
206 // because each deletion will cause it to be modified. 207 // because each deletion will cause it to be modified.
207 208
208 std::vector<Connection*> list; 209 std::vector<Connection*> list;
209 210
210 AddressMap::iterator iter = connections_.begin(); 211 AddressMap::iterator iter = connections_.begin();
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 638
638 // Send the response message. 639 // Send the response message.
639 rtc::ByteBufferWriter buf; 640 rtc::ByteBufferWriter buf;
640 response.Write(&buf); 641 response.Write(&buf);
641 rtc::PacketOptions options(DefaultDscpValue()); 642 rtc::PacketOptions options(DefaultDscpValue());
642 SendTo(buf.Data(), buf.Length(), addr, options, false); 643 SendTo(buf.Data(), buf.Length(), addr, options, false);
643 LOG_J(LS_INFO, this) << "Sending STUN binding error: reason=" << reason 644 LOG_J(LS_INFO, this) << "Sending STUN binding error: reason=" << reason
644 << " to " << addr.ToSensitiveString(); 645 << " to " << addr.ToSensitiveString();
645 } 646 }
646 647
648 void Port::StartBeingUsed() {
649 is_used_ = true;
650 }
651
652 void Port::StopBeingUsed() {
653 is_used_ = false;
654 thread_->Post(RTC_FROM_HERE, this, MSG_CHECK_DEAD);
655 }
656
647 void Port::OnMessage(rtc::Message *pmsg) { 657 void Port::OnMessage(rtc::Message *pmsg) {
648 ASSERT(pmsg->message_id == MSG_DEAD); 658 ASSERT(pmsg->message_id == MSG_CHECK_DEAD);
649 if (dead()) { 659 if (dead()) {
650 Destroy(); 660 Destroy();
651 } 661 }
652 } 662 }
653 663
664 bool Port::dead() const {
665 return !is_used_ && connections_.empty() &&
666 rtc::TimeMillis() - last_time_all_connections_removed_ >=
667 timeout_delay_;
668 }
669
654 void Port::OnNetworkTypeChanged(const rtc::Network* network) { 670 void Port::OnNetworkTypeChanged(const rtc::Network* network) {
655 ASSERT(network == network_); 671 ASSERT(network == network_);
656 672
657 UpdateNetworkCost(); 673 UpdateNetworkCost();
658 } 674 }
659 675
660 std::string Port::ToString() const { 676 std::string Port::ToString() const {
661 std::stringstream ss; 677 std::stringstream ss;
662 ss << "Port[" << std::hex << this << std::dec << ":" << content_name_ << ":" 678 ss << "Port[" << std::hex << this << std::dec << ":" << content_name_ << ":"
663 << component_ << ":" << generation_ << ":" << type_ << ":" 679 << component_ << ":" << generation_ << ":" << type_ << ":"
(...skipping 28 matching lines...) Expand all
692 enable_port_packets_ = true; 708 enable_port_packets_ = true;
693 } 709 }
694 710
695 void Port::OnConnectionDestroyed(Connection* conn) { 711 void Port::OnConnectionDestroyed(Connection* conn) {
696 AddressMap::iterator iter = 712 AddressMap::iterator iter =
697 connections_.find(conn->remote_candidate().address()); 713 connections_.find(conn->remote_candidate().address());
698 ASSERT(iter != connections_.end()); 714 ASSERT(iter != connections_.end());
699 connections_.erase(iter); 715 connections_.erase(iter);
700 HandleConnectionDestroyed(conn); 716 HandleConnectionDestroyed(conn);
701 717
702 // On the controlled side, ports time out after all connections fail. 718 // Ports time out after all connections fail if it is not used by any channel.
703 // Note: If a new connection is added after this message is posted, but it 719 // Note: If a new connection is added after this message is posted, but it
704 // fails and is removed before kPortTimeoutDelay, then this message will 720 // fails and is removed before kPortTimeoutDelay, then the port will not be
705 // still cause the Port to be destroyed. 721 // destroyed until kPortTimeoutDelay milliseconds after the new connection
706 if (dead()) { 722 // is removed.
707 thread_->PostDelayed(RTC_FROM_HERE, timeout_delay_, this, MSG_DEAD); 723 if (connections_.empty()) {
724 last_time_all_connections_removed_ = rtc::TimeMillis();
725 thread_->PostDelayed(RTC_FROM_HERE, timeout_delay_, this, MSG_CHECK_DEAD);
708 } 726 }
709 } 727 }
710 728
711 void Port::Destroy() { 729 void Port::Destroy() {
712 ASSERT(connections_.empty()); 730 ASSERT(connections_.empty());
713 LOG_J(LS_INFO, this) << "Port deleted"; 731 LOG_J(LS_INFO, this) << "Port deleted";
714 SignalDestroyed(this); 732 SignalDestroyed(this);
715 delete this; 733 delete this;
716 } 734 }
717 735
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after
1530 ASSERT(sent < 0); 1548 ASSERT(sent < 0);
1531 error_ = port_->GetError(); 1549 error_ = port_->GetError();
1532 stats_.sent_discarded_packets++; 1550 stats_.sent_discarded_packets++;
1533 } else { 1551 } else {
1534 send_rate_tracker_.AddSamples(sent); 1552 send_rate_tracker_.AddSamples(sent);
1535 } 1553 }
1536 return sent; 1554 return sent;
1537 } 1555 }
1538 1556
1539 } // namespace cricket 1557 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698