OLD | NEW |
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 Loading... |
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, |
| 202 MSG_DESTROY_IF_DEAD); |
201 LOG_J(LS_INFO, this) << "Port created with network cost " << network_cost_; | 203 LOG_J(LS_INFO, this) << "Port created with network cost " << network_cost_; |
202 } | 204 } |
203 | 205 |
204 Port::~Port() { | 206 Port::~Port() { |
205 // Delete all of the remaining connections. We copy the list up front | 207 // Delete all of the remaining connections. We copy the list up front |
206 // because each deletion will cause it to be modified. | 208 // because each deletion will cause it to be modified. |
207 | 209 |
208 std::vector<Connection*> list; | 210 std::vector<Connection*> list; |
209 | 211 |
210 AddressMap::iterator iter = connections_.begin(); | 212 AddressMap::iterator iter = connections_.begin(); |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 | 639 |
638 // Send the response message. | 640 // Send the response message. |
639 rtc::ByteBufferWriter buf; | 641 rtc::ByteBufferWriter buf; |
640 response.Write(&buf); | 642 response.Write(&buf); |
641 rtc::PacketOptions options(DefaultDscpValue()); | 643 rtc::PacketOptions options(DefaultDscpValue()); |
642 SendTo(buf.Data(), buf.Length(), addr, options, false); | 644 SendTo(buf.Data(), buf.Length(), addr, options, false); |
643 LOG_J(LS_INFO, this) << "Sending STUN binding error: reason=" << reason | 645 LOG_J(LS_INFO, this) << "Sending STUN binding error: reason=" << reason |
644 << " to " << addr.ToSensitiveString(); | 646 << " to " << addr.ToSensitiveString(); |
645 } | 647 } |
646 | 648 |
| 649 void Port::KeepAliveUntilPruned() { |
| 650 // If it is pruned, we won't bring it up again. |
| 651 if (state_ == State::INIT) { |
| 652 state_ = State::KEEP_ALIVE_UNTIL_PRUNED; |
| 653 } |
| 654 } |
| 655 |
| 656 void Port::Prune() { |
| 657 state_ = State::PRUNED; |
| 658 thread_->Post(RTC_FROM_HERE, this, MSG_DESTROY_IF_DEAD); |
| 659 } |
| 660 |
647 void Port::OnMessage(rtc::Message *pmsg) { | 661 void Port::OnMessage(rtc::Message *pmsg) { |
648 ASSERT(pmsg->message_id == MSG_CHECK_DEAD); | 662 ASSERT(pmsg->message_id == MSG_DESTROY_IF_DEAD); |
649 if (dead()) { | 663 bool dead = |
| 664 (state_ == State::INIT || state_ == State::PRUNED) && |
| 665 connections_.empty() && |
| 666 rtc::TimeMillis() - last_time_all_connections_removed_ >= timeout_delay_; |
| 667 if (dead) { |
650 Destroy(); | 668 Destroy(); |
651 } | 669 } |
652 } | 670 } |
653 | 671 |
654 void Port::OnNetworkTypeChanged(const rtc::Network* network) { | 672 void Port::OnNetworkTypeChanged(const rtc::Network* network) { |
655 ASSERT(network == network_); | 673 ASSERT(network == network_); |
656 | 674 |
657 UpdateNetworkCost(); | 675 UpdateNetworkCost(); |
658 } | 676 } |
659 | 677 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 enable_port_packets_ = true; | 710 enable_port_packets_ = true; |
693 } | 711 } |
694 | 712 |
695 void Port::OnConnectionDestroyed(Connection* conn) { | 713 void Port::OnConnectionDestroyed(Connection* conn) { |
696 AddressMap::iterator iter = | 714 AddressMap::iterator iter = |
697 connections_.find(conn->remote_candidate().address()); | 715 connections_.find(conn->remote_candidate().address()); |
698 ASSERT(iter != connections_.end()); | 716 ASSERT(iter != connections_.end()); |
699 connections_.erase(iter); | 717 connections_.erase(iter); |
700 HandleConnectionDestroyed(conn); | 718 HandleConnectionDestroyed(conn); |
701 | 719 |
702 // On the controlled side, ports time out after all connections fail. | 720 // Ports time out after all connections fail if it is not marked as |
| 721 // "keep alive until pruned." |
703 // Note: If a new connection is added after this message is posted, but it | 722 // 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 | 723 // fails and is removed before kPortTimeoutDelay, then this message will |
705 // not cause the Port to be destroyed. | 724 // not cause the Port to be destroyed. |
706 if (ice_role_ == ICEROLE_CONTROLLED && connections_.empty()) { | 725 if (connections_.empty()) { |
707 last_time_all_connections_removed_ = rtc::TimeMillis(); | 726 last_time_all_connections_removed_ = rtc::TimeMillis(); |
708 thread_->PostDelayed(RTC_FROM_HERE, timeout_delay_, this, MSG_CHECK_DEAD); | 727 thread_->PostDelayed(RTC_FROM_HERE, timeout_delay_, this, |
| 728 MSG_DESTROY_IF_DEAD); |
709 } | 729 } |
710 } | 730 } |
711 | 731 |
712 bool Port::dead() const { | |
713 return ice_role_ == ICEROLE_CONTROLLED && connections_.empty() && | |
714 rtc::TimeMillis() - last_time_all_connections_removed_ >= | |
715 timeout_delay_; | |
716 } | |
717 | |
718 void Port::Destroy() { | 732 void Port::Destroy() { |
719 ASSERT(connections_.empty()); | 733 ASSERT(connections_.empty()); |
720 LOG_J(LS_INFO, this) << "Port deleted"; | 734 LOG_J(LS_INFO, this) << "Port deleted"; |
721 SignalDestroyed(this); | 735 SignalDestroyed(this); |
722 delete this; | 736 delete this; |
723 } | 737 } |
724 | 738 |
725 const std::string Port::username_fragment() const { | 739 const std::string Port::username_fragment() const { |
726 return ice_username_fragment_; | 740 return ice_username_fragment_; |
727 } | 741 } |
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1537 ASSERT(sent < 0); | 1551 ASSERT(sent < 0); |
1538 error_ = port_->GetError(); | 1552 error_ = port_->GetError(); |
1539 stats_.sent_discarded_packets++; | 1553 stats_.sent_discarded_packets++; |
1540 } else { | 1554 } else { |
1541 send_rate_tracker_.AddSamples(sent); | 1555 send_rate_tracker_.AddSamples(sent); |
1542 } | 1556 } |
1543 return sent; | 1557 return sent; |
1544 } | 1558 } |
1545 | 1559 |
1546 } // namespace cricket | 1560 } // namespace cricket |
OLD | NEW |