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

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: . Created 4 years, 4 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::BecomeReady() {
649 // If it is pruned, we won't bring it up again.
pthatcher1 2016/07/28 19:35:05 We should probably RTC_DCHECK(state_ == State::INI
honghaiz3 2016/07/28 22:51:44 It may happen that it was pruned first then it bec
650 if (state_ == State::INIT) {
651 state_ = State::READY;
652 }
653 }
654
655 void Port::Prune() {
656 state_ = State::PRUNED;
657 thread_->Post(RTC_FROM_HERE, this, MSG_CHECK_DEAD);
658 }
659
647 void Port::OnMessage(rtc::Message *pmsg) { 660 void Port::OnMessage(rtc::Message *pmsg) {
648 ASSERT(pmsg->message_id == MSG_DEAD); 661 ASSERT(pmsg->message_id == MSG_CHECK_DEAD);
649 if (dead()) { 662 if (dead()) {
pthatcher1 2016/07/28 19:35:05 Since there is only one place calling dead() now,
honghaiz3 2016/07/28 22:51:44 Done.
650 Destroy(); 663 Destroy();
651 } 664 }
652 } 665 }
653 666
667 bool Port::dead() const {
668 return state_ != State::READY && connections_.empty();
pthatcher1 2016/07/28 19:35:05 I think (state_ == INIT || state_ == PRUNED) && co
honghaiz3 2016/07/28 22:51:44 Done.
669 }
670
654 void Port::OnNetworkTypeChanged(const rtc::Network* network) { 671 void Port::OnNetworkTypeChanged(const rtc::Network* network) {
655 ASSERT(network == network_); 672 ASSERT(network == network_);
656 673
657 UpdateNetworkCost(); 674 UpdateNetworkCost();
658 } 675 }
659 676
660 std::string Port::ToString() const { 677 std::string Port::ToString() const {
661 std::stringstream ss; 678 std::stringstream ss;
662 ss << "Port[" << std::hex << this << std::dec << ":" << content_name_ << ":" 679 ss << "Port[" << std::hex << this << std::dec << ":" << content_name_ << ":"
663 << component_ << ":" << generation_ << ":" << type_ << ":" 680 << component_ << ":" << generation_ << ":" << type_ << ":"
(...skipping 28 matching lines...) Expand all
692 enable_port_packets_ = true; 709 enable_port_packets_ = true;
693 } 710 }
694 711
695 void Port::OnConnectionDestroyed(Connection* conn) { 712 void Port::OnConnectionDestroyed(Connection* conn) {
696 AddressMap::iterator iter = 713 AddressMap::iterator iter =
697 connections_.find(conn->remote_candidate().address()); 714 connections_.find(conn->remote_candidate().address());
698 ASSERT(iter != connections_.end()); 715 ASSERT(iter != connections_.end());
699 connections_.erase(iter); 716 connections_.erase(iter);
700 HandleConnectionDestroyed(conn); 717 HandleConnectionDestroyed(conn);
701 718
702 // On the controlled side, ports time out after all connections fail. 719 // Ports time out after all connections fail if it is not ready.
703 // Note: If a new connection is added after this message is posted, but it 720 // 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 721 // fails and is removed before timeout_delay_, then this message will
705 // still cause the Port to be destroyed. 722 // still cause the Port to be destroyed.
706 if (dead()) { 723 if (connections_.empty()) {
707 thread_->PostDelayed(RTC_FROM_HERE, timeout_delay_, this, MSG_DEAD); 724 thread_->PostDelayed(RTC_FROM_HERE, timeout_delay_, this, MSG_CHECK_DEAD);
708 } 725 }
709 } 726 }
710 727
711 void Port::Destroy() { 728 void Port::Destroy() {
712 ASSERT(connections_.empty()); 729 ASSERT(connections_.empty());
713 LOG_J(LS_INFO, this) << "Port deleted"; 730 LOG_J(LS_INFO, this) << "Port deleted";
714 SignalDestroyed(this); 731 SignalDestroyed(this);
715 delete this; 732 delete this;
716 } 733 }
717 734
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after
1530 ASSERT(sent < 0); 1547 ASSERT(sent < 0);
1531 error_ = port_->GetError(); 1548 error_ = port_->GetError();
1532 stats_.sent_discarded_packets++; 1549 stats_.sent_discarded_packets++;
1533 } else { 1550 } else {
1534 send_rate_tracker_.AddSamples(sent); 1551 send_rate_tracker_.AddSamples(sent);
1535 } 1552 }
1536 return sent; 1553 return sent;
1537 } 1554 }
1538 1555
1539 } // namespace cricket 1556 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698