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

Side by Side Diff: webrtc/p2p/stunprober/stunprober.h

Issue 1161463011: Non functional change: Move Requester to cc file (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « no previous file | webrtc/p2p/stunprober/stunprober.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 int timeout_ms, 185 int timeout_ms,
186 const AsyncCallback finish_callback); 186 const AsyncCallback finish_callback);
187 187
188 // Method to retrieve the Stats once |finish_callback| is invoked. Returning 188 // 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 189 // false when the result is inconclusive, for example, whether it's behind a
190 // NAT or not. 190 // NAT or not.
191 bool GetStats(Stats* stats); 191 bool GetStats(Stats* stats);
192 192
193 private: 193 private:
194 // A requester tracks the requests and responses from a single socket to many 194 // A requester tracks the requests and responses from a single socket to many
195 // STUN servers 195 // STUN servers.
196 class Requester { 196 class Requester;
197 public:
198 // Each Request maps to a request and response.
199 struct Request {
200 // Actual time the STUN bind request was sent.
201 int64 sent_time_ms = 0;
202 // Time the response was received.
203 int64 received_time_ms = 0;
204 197
205 // See whether the observed address returned matches the
206 // local address as in StunProber.local_addr_.
207 bool behind_nat = false;
208
209 // Server reflexive address from STUN response for this given request.
210 rtc::SocketAddress srflx_addr;
211
212 rtc::IPAddress server_addr;
213
214 int64 rtt() { return received_time_ms - sent_time_ms; }
215 void ProcessResponse(rtc::ByteBuffer* message,
216 int buf_len,
217 const rtc::IPAddress& local_addr);
218 };
219
220 // StunProber provides |server_ips| for Requester to probe. For shared
221 // socket mode, it'll be all the resolved IP addresses. For non-shared mode,
222 // it'll just be a single address.
223 Requester(StunProber* prober,
224 ServerSocketInterface* socket,
225 const std::vector<rtc::SocketAddress>& server_ips);
226 virtual ~Requester();
227
228 // There is no callback for SendStunRequest as the underneath socket send is
229 // expected to be completed immediately. Otherwise, it'll skip this request
230 // and move to the next one.
231 void SendStunRequest();
232
233 void ReadStunResponse();
234
235 // |result| is the positive return value from RecvFrom when data is
236 // available.
237 void OnStunResponseReceived(int result);
238
239 const std::vector<Request*>& requests() { return requests_; }
240
241 // Whether this Requester has completed all requests.
242 bool Done() {
243 return static_cast<size_t>(num_request_sent_) == server_ips_.size();
244 }
245
246 private:
247 Request* GetRequestByAddress(const rtc::IPAddress& ip);
248
249 StunProber* prober_;
250
251 // The socket for this session.
252 rtc::scoped_ptr<ServerSocketInterface> socket_;
253
254 // Temporary SocketAddress and buffer for RecvFrom.
255 rtc::SocketAddress addr_;
256 rtc::scoped_ptr<rtc::ByteBuffer> response_packet_;
257
258 std::vector<Request*> requests_;
259 std::vector<rtc::SocketAddress> server_ips_;
260 int16 num_request_sent_ = 0;
261 int16 num_response_received_ = 0;
262
263 rtc::ThreadChecker& thread_checker_;
264
265 DISALLOW_COPY_AND_ASSIGN(Requester);
266 };
267
268 private:
269 void OnServerResolved(int index, int result); 198 void OnServerResolved(int index, int result);
270 199
271 bool Done() { 200 bool Done() {
272 return num_request_sent_ >= requests_per_ip_ * all_servers_ips_.size(); 201 return num_request_sent_ >= requests_per_ip_ * all_servers_ips_.size();
273 } 202 }
274 203
275 int GetTotalClientSockets() { return 1; } 204 int GetTotalClientSockets() { return 1; }
276 int GetTotalServerSockets() { 205 int GetTotalServerSockets() {
277 return static_cast<int>( 206 return static_cast<int>(
278 (shared_socket_mode_ ? 1 : all_servers_ips_.size()) * requests_per_ip_); 207 (shared_socket_mode_ ? 1 : all_servers_ips_.size()) * requests_per_ip_);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 std::vector<Requester*> requesters_; 270 std::vector<Requester*> requesters_;
342 271
343 rtc::ThreadChecker thread_checker_; 272 rtc::ThreadChecker thread_checker_;
344 273
345 DISALLOW_COPY_AND_ASSIGN(StunProber); 274 DISALLOW_COPY_AND_ASSIGN(StunProber);
346 }; 275 };
347 276
348 } // namespace stunprober 277 } // namespace stunprober
349 278
350 #endif // WEBRTC_P2P_STUNPROBER_STUNPROBER_H_ 279 #endif // WEBRTC_P2P_STUNPROBER_STUNPROBER_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/p2p/stunprober/stunprober.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698