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/base/base64.h" | 16 #include "webrtc/base/base64.h" |
17 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
18 #include "webrtc/base/crc32.h" | 18 #include "webrtc/base/crc32.h" |
19 #include "webrtc/base/helpers.h" | 19 #include "webrtc/base/helpers.h" |
20 #include "webrtc/base/logging.h" | 20 #include "webrtc/base/logging.h" |
21 #include "webrtc/base/messagedigest.h" | 21 #include "webrtc/base/messagedigest.h" |
22 #include "webrtc/base/network.h" | 22 #include "webrtc/base/network.h" |
23 #include "webrtc/base/ptr_util.h" | 23 #include "webrtc/base/ptr_util.h" |
| 24 #include "webrtc/base/safe_minmax.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 #include "webrtc/p2p/base/common.h" | 27 #include "webrtc/p2p/base/common.h" |
27 #include "webrtc/p2p/base/portallocator.h" | 28 #include "webrtc/p2p/base/portallocator.h" |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 // Determines whether we have seen at least the given maximum number of | 32 // Determines whether we have seen at least the given maximum number of |
32 // pings fail to have a response. | 33 // pings fail to have a response. |
33 inline bool TooManyFailures( | 34 inline bool TooManyFailures( |
(...skipping 28 matching lines...) Expand all Loading... |
62 // within a reasonable range. | 63 // within a reasonable range. |
63 const int MINIMUM_RTT = 100; // 0.1 seconds | 64 const int MINIMUM_RTT = 100; // 0.1 seconds |
64 const int MAXIMUM_RTT = 60000; // 60 seconds | 65 const int MAXIMUM_RTT = 60000; // 60 seconds |
65 | 66 |
66 // When we don't have any RTT data, we have to pick something reasonable. We | 67 // When we don't have any RTT data, we have to pick something reasonable. We |
67 // use a large value just in case the connection is really slow. | 68 // use a large value just in case the connection is really slow. |
68 const int DEFAULT_RTT = 3000; // 3 seconds | 69 const int DEFAULT_RTT = 3000; // 3 seconds |
69 | 70 |
70 // Computes our estimate of the RTT given the current estimate. | 71 // Computes our estimate of the RTT given the current estimate. |
71 inline int ConservativeRTTEstimate(int rtt) { | 72 inline int ConservativeRTTEstimate(int rtt) { |
72 return std::max(MINIMUM_RTT, std::min(MAXIMUM_RTT, 2 * rtt)); | 73 return rtc::SafeClamp(2 * rtt, MINIMUM_RTT, MAXIMUM_RTT); |
73 } | 74 } |
74 | 75 |
75 // Weighting of the old rtt value to new data. | 76 // Weighting of the old rtt value to new data. |
76 const int RTT_RATIO = 3; // 3 : 1 | 77 const int RTT_RATIO = 3; // 3 : 1 |
77 | 78 |
78 // The delay before we begin checking if this port is useless. We set | 79 // The delay before we begin checking if this port is useless. We set |
79 // it to a little higher than a total STUN timeout. | 80 // it to a little higher than a total STUN timeout. |
80 const int kPortTimeoutDelay = cricket::STUN_TOTAL_TIMEOUT + 5000; | 81 const int kPortTimeoutDelay = cricket::STUN_TOTAL_TIMEOUT + 5000; |
81 | 82 |
82 // For packet loss estimation. | 83 // For packet loss estimation. |
(...skipping 1542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1625 RTC_DCHECK(sent < 0); | 1626 RTC_DCHECK(sent < 0); |
1626 error_ = port_->GetError(); | 1627 error_ = port_->GetError(); |
1627 stats_.sent_discarded_packets++; | 1628 stats_.sent_discarded_packets++; |
1628 } else { | 1629 } else { |
1629 send_rate_tracker_.AddSamples(sent); | 1630 send_rate_tracker_.AddSamples(sent); |
1630 } | 1631 } |
1631 return sent; | 1632 return sent; |
1632 } | 1633 } |
1633 | 1634 |
1634 } // namespace cricket | 1635 } // namespace cricket |
OLD | NEW |