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 |
11 #include "webrtc/p2p/base/port.h" | 11 #include "webrtc/p2p/base/port.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "webrtc/p2p/base/common.h" | 16 #include "webrtc/p2p/base/common.h" |
17 #include "webrtc/p2p/base/portallocator.h" | 17 #include "webrtc/p2p/base/portallocator.h" |
18 #include "webrtc/base/base64.h" | 18 #include "webrtc/base/base64.h" |
19 #include "webrtc/base/crc32.h" | 19 #include "webrtc/base/crc32.h" |
20 #include "webrtc/base/helpers.h" | 20 #include "webrtc/base/helpers.h" |
21 #include "webrtc/base/logging.h" | 21 #include "webrtc/base/logging.h" |
22 #include "webrtc/base/messagedigest.h" | 22 #include "webrtc/base/messagedigest.h" |
| 23 #include "webrtc/base/network.h" |
23 #include "webrtc/base/scoped_ptr.h" | 24 #include "webrtc/base/scoped_ptr.h" |
24 #include "webrtc/base/stringencode.h" | 25 #include "webrtc/base/stringencode.h" |
25 #include "webrtc/base/stringutils.h" | 26 #include "webrtc/base/stringutils.h" |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 // Determines whether we have seen at least the given maximum number of | 30 // Determines whether we have seen at least the given maximum number of |
30 // pings fail to have a response. | 31 // pings fail to have a response. |
31 inline bool TooManyFailures( | 32 inline bool TooManyFailures( |
32 const std::vector<cricket::Connection::SentPing>& pings_since_last_response, | 33 const std::vector<cricket::Connection::SentPing>& pings_since_last_response, |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 189 |
189 void Port::Construct() { | 190 void Port::Construct() { |
190 // TODO(pthatcher): Remove this old behavior once we're sure no one | 191 // TODO(pthatcher): Remove this old behavior once we're sure no one |
191 // relies on it. If the username_fragment and password are empty, | 192 // relies on it. If the username_fragment and password are empty, |
192 // we should just create one. | 193 // we should just create one. |
193 if (ice_username_fragment_.empty()) { | 194 if (ice_username_fragment_.empty()) { |
194 ASSERT(password_.empty()); | 195 ASSERT(password_.empty()); |
195 ice_username_fragment_ = rtc::CreateRandomString(ICE_UFRAG_LENGTH); | 196 ice_username_fragment_ = rtc::CreateRandomString(ICE_UFRAG_LENGTH); |
196 password_ = rtc::CreateRandomString(ICE_PWD_LENGTH); | 197 password_ = rtc::CreateRandomString(ICE_PWD_LENGTH); |
197 } | 198 } |
| 199 network_->SignalInactive.connect(this, &Port::OnNetworkInactive); |
198 // TODO(honghaiz): Make it configurable from user setting. | 200 // TODO(honghaiz): Make it configurable from user setting. |
199 network_cost_ = | 201 network_cost_ = |
200 (network_->type() == rtc::ADAPTER_TYPE_CELLULAR) ? kMaxNetworkCost : 0; | 202 (network_->type() == rtc::ADAPTER_TYPE_CELLULAR) ? kMaxNetworkCost : 0; |
201 | 203 |
202 LOG_J(LS_INFO, this) << "Port created"; | 204 LOG_J(LS_INFO, this) << "Port created"; |
203 } | 205 } |
204 | 206 |
205 Port::~Port() { | 207 Port::~Port() { |
206 // Delete all of the remaining connections. We copy the list up front | 208 // Delete all of the remaining connections. We copy the list up front |
207 // because each deletion will cause it to be modified. | 209 // because each deletion will cause it to be modified. |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 << " to " << addr.ToSensitiveString(); | 628 << " to " << addr.ToSensitiveString(); |
627 } | 629 } |
628 | 630 |
629 void Port::OnMessage(rtc::Message *pmsg) { | 631 void Port::OnMessage(rtc::Message *pmsg) { |
630 ASSERT(pmsg->message_id == MSG_DEAD); | 632 ASSERT(pmsg->message_id == MSG_DEAD); |
631 if (dead()) { | 633 if (dead()) { |
632 Destroy(); | 634 Destroy(); |
633 } | 635 } |
634 } | 636 } |
635 | 637 |
| 638 void Port::OnNetworkInactive(const rtc::Network* network) { |
| 639 ASSERT(network == network_); |
| 640 SignalNetworkInactive(this); |
| 641 } |
| 642 |
636 std::string Port::ToString() const { | 643 std::string Port::ToString() const { |
637 std::stringstream ss; | 644 std::stringstream ss; |
638 ss << "Port[" << content_name_ << ":" << component_ | 645 ss << "Port[" << std::hex << this << std::dec << ":" << content_name_ << ":" |
639 << ":" << generation_ << ":" << type_ | 646 << component_ << ":" << generation_ << ":" << type_ << ":" |
640 << ":" << network_->ToString() << "]"; | 647 << network_->ToString() << "]"; |
641 return ss.str(); | 648 return ss.str(); |
642 } | 649 } |
643 | 650 |
644 void Port::EnablePortPackets() { | 651 void Port::EnablePortPackets() { |
645 enable_port_packets_ = true; | 652 enable_port_packets_ = true; |
646 } | 653 } |
647 | 654 |
648 void Port::OnConnectionDestroyed(Connection* conn) { | 655 void Port::OnConnectionDestroyed(Connection* conn) { |
649 AddressMap::iterator iter = | 656 AddressMap::iterator iter = |
650 connections_.find(conn->remote_candidate().address()); | 657 connections_.find(conn->remote_candidate().address()); |
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1436 ASSERT(sent < 0); | 1443 ASSERT(sent < 0); |
1437 error_ = port_->GetError(); | 1444 error_ = port_->GetError(); |
1438 sent_packets_discarded_++; | 1445 sent_packets_discarded_++; |
1439 } else { | 1446 } else { |
1440 send_rate_tracker_.AddSamples(sent); | 1447 send_rate_tracker_.AddSamples(sent); |
1441 } | 1448 } |
1442 return sent; | 1449 return sent; |
1443 } | 1450 } |
1444 | 1451 |
1445 } // namespace cricket | 1452 } // namespace cricket |
OLD | NEW |