OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2015 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 12 matching lines...) Expand all Loading... |
23 #include "webrtc/base/socketaddress.h" | 23 #include "webrtc/base/socketaddress.h" |
24 #include "webrtc/base/thread_checker.h" | 24 #include "webrtc/base/thread_checker.h" |
25 #include "webrtc/typedefs.h" | 25 #include "webrtc/typedefs.h" |
26 | 26 |
27 namespace stunprober { | 27 namespace stunprober { |
28 | 28 |
29 static const int kMaxUdpBufferSize = 1200; | 29 static const int kMaxUdpBufferSize = 1200; |
30 | 30 |
31 typedef rtc::Callback1<void, int> AsyncCallback; | 31 typedef rtc::Callback1<void, int> AsyncCallback; |
32 | 32 |
| 33 enum NatType { |
| 34 NATTYPE_INVALID, |
| 35 NATTYPE_NONE, // Not behind a NAT. |
| 36 NATTYPE_UNKNOWN, // Behind a NAT but type can't be determine. |
| 37 NATTYPE_SYMMETRIC, // Behind a symmetric NAT. |
| 38 NATTYPE_NON_SYMMETRIC // Behind a non-symmetric NAT. |
| 39 }; |
| 40 |
33 class HostNameResolverInterface { | 41 class HostNameResolverInterface { |
34 public: | 42 public: |
35 HostNameResolverInterface() {} | 43 HostNameResolverInterface() {} |
36 | 44 |
37 // Resolve should allow re-entry as |callback| could trigger another | 45 // Resolve should allow re-entry as |callback| could trigger another |
38 // Resolve(). | 46 // Resolve(). |
39 virtual void Resolve(const rtc::SocketAddress& addr, | 47 virtual void Resolve(const rtc::SocketAddress& addr, |
40 std::vector<rtc::SocketAddress>* addresses, | 48 std::vector<rtc::SocketAddress>* addresses, |
41 AsyncCallback callback) = 0; | 49 AsyncCallback callback) = 0; |
42 | 50 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 enum Status { // Used in UMA_HISTOGRAM_ENUMERATION. | 140 enum Status { // Used in UMA_HISTOGRAM_ENUMERATION. |
133 SUCCESS, // Successfully received bytes from the server. | 141 SUCCESS, // Successfully received bytes from the server. |
134 GENERIC_FAILURE, // Generic failure. | 142 GENERIC_FAILURE, // Generic failure. |
135 RESOLVE_FAILED, // Host resolution failed. | 143 RESOLVE_FAILED, // Host resolution failed. |
136 WRITE_FAILED, // Sending a message to the server failed. | 144 WRITE_FAILED, // Sending a message to the server failed. |
137 READ_FAILED, // Reading the reply from the server failed. | 145 READ_FAILED, // Reading the reply from the server failed. |
138 }; | 146 }; |
139 | 147 |
140 struct Stats { | 148 struct Stats { |
141 Stats() {} | 149 Stats() {} |
| 150 |
142 int num_request_sent = 0; | 151 int num_request_sent = 0; |
143 int num_response_received = 0; | 152 int num_response_received = 0; |
144 bool behind_nat = false; | 153 NatType nat_type = NATTYPE_INVALID; |
145 bool symmetric_nat = false; | |
146 int average_rtt_ms = -1; | 154 int average_rtt_ms = -1; |
147 int success_percent = 0; | 155 int success_percent = 0; |
148 int target_request_interval_ns = 0; | 156 int target_request_interval_ns = 0; |
149 int actual_request_interval_ns = 0; | 157 int actual_request_interval_ns = 0; |
150 | 158 |
151 // Also report whether this trial can't be considered truly as shared | 159 // Also report whether this trial can't be considered truly as shared |
152 // mode. Share mode only makes sense when we have multiple IP resolved and | 160 // mode. Share mode only makes sense when we have multiple IP resolved and |
153 // successfully probed. | 161 // successfully probed. |
154 bool shared_socket_mode = false; | 162 bool shared_socket_mode = false; |
155 | 163 |
(...skipping 25 matching lines...) Expand all Loading... |
181 bool Start(const std::vector<rtc::SocketAddress>& servers, | 189 bool Start(const std::vector<rtc::SocketAddress>& servers, |
182 bool shared_socket_mode, | 190 bool shared_socket_mode, |
183 int stun_ta_interval_ms, | 191 int stun_ta_interval_ms, |
184 int requests_per_ip, | 192 int requests_per_ip, |
185 int timeout_ms, | 193 int timeout_ms, |
186 const AsyncCallback finish_callback); | 194 const AsyncCallback finish_callback); |
187 | 195 |
188 // Method to retrieve the Stats once |finish_callback| is invoked. Returning | 196 // Method to retrieve the Stats once |finish_callback| is invoked. Returning |
189 // false when the result is inconclusive, for example, whether it's behind a | 197 // false when the result is inconclusive, for example, whether it's behind a |
190 // NAT or not. | 198 // NAT or not. |
191 bool GetStats(Stats* stats); | 199 bool GetStats(Stats* stats) const; |
192 | 200 |
193 private: | 201 private: |
194 // A requester tracks the requests and responses from a single socket to many | 202 // A requester tracks the requests and responses from a single socket to many |
195 // STUN servers. | 203 // STUN servers. |
196 class Requester; | 204 class Requester; |
197 | 205 |
198 void OnServerResolved(int index, int result); | 206 void OnServerResolved(int index, int result); |
199 | 207 |
200 bool Done() { | 208 bool Done() { |
201 return num_request_sent_ >= requests_per_ip_ * all_servers_ips_.size(); | 209 return num_request_sent_ >= requests_per_ip_ * all_servers_ips_.size(); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 std::vector<Requester*> requesters_; | 278 std::vector<Requester*> requesters_; |
271 | 279 |
272 rtc::ThreadChecker thread_checker_; | 280 rtc::ThreadChecker thread_checker_; |
273 | 281 |
274 DISALLOW_COPY_AND_ASSIGN(StunProber); | 282 DISALLOW_COPY_AND_ASSIGN(StunProber); |
275 }; | 283 }; |
276 | 284 |
277 } // namespace stunprober | 285 } // namespace stunprober |
278 | 286 |
279 #endif // WEBRTC_P2P_STUNPROBER_STUNPROBER_H_ | 287 #endif // WEBRTC_P2P_STUNPROBER_STUNPROBER_H_ |
OLD | NEW |