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

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

Issue 1362503003: Use suffixed {uint,int}{8,16,32,64}_t types. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase + revert basictypes.h (to be landed separately just in case of a revert due to unexpected us… Created 5 years, 2 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 | « webrtc/p2p/stunprober/stunprober.h ('k') | webrtc/p2p/stunprober/stunprober_unittest.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 26 matching lines...) Expand all
37 37
38 } // namespace 38 } // namespace
39 39
40 // A requester tracks the requests and responses from a single socket to many 40 // A requester tracks the requests and responses from a single socket to many
41 // STUN servers 41 // STUN servers
42 class StunProber::Requester : public sigslot::has_slots<> { 42 class StunProber::Requester : public sigslot::has_slots<> {
43 public: 43 public:
44 // Each Request maps to a request and response. 44 // Each Request maps to a request and response.
45 struct Request { 45 struct Request {
46 // Actual time the STUN bind request was sent. 46 // Actual time the STUN bind request was sent.
47 int64 sent_time_ms = 0; 47 int64_t sent_time_ms = 0;
48 // Time the response was received. 48 // Time the response was received.
49 int64 received_time_ms = 0; 49 int64_t received_time_ms = 0;
50 50
51 // Server reflexive address from STUN response for this given request. 51 // Server reflexive address from STUN response for this given request.
52 rtc::SocketAddress srflx_addr; 52 rtc::SocketAddress srflx_addr;
53 53
54 rtc::IPAddress server_addr; 54 rtc::IPAddress server_addr;
55 55
56 int64 rtt() { return received_time_ms - sent_time_ms; } 56 int64_t rtt() { return received_time_ms - sent_time_ms; }
57 void ProcessResponse(const char* buf, size_t buf_len); 57 void ProcessResponse(const char* buf, size_t buf_len);
58 }; 58 };
59 59
60 // StunProber provides |server_ips| for Requester to probe. For shared 60 // StunProber provides |server_ips| for Requester to probe. For shared
61 // socket mode, it'll be all the resolved IP addresses. For non-shared mode, 61 // socket mode, it'll be all the resolved IP addresses. For non-shared mode,
62 // it'll just be a single address. 62 // it'll just be a single address.
63 Requester(StunProber* prober, 63 Requester(StunProber* prober,
64 rtc::AsyncPacketSocket* socket, 64 rtc::AsyncPacketSocket* socket,
65 const std::vector<rtc::SocketAddress>& server_ips); 65 const std::vector<rtc::SocketAddress>& server_ips);
66 virtual ~Requester(); 66 virtual ~Requester();
(...skipping 23 matching lines...) Expand all
90 90
91 // The socket for this session. 91 // The socket for this session.
92 rtc::scoped_ptr<rtc::AsyncPacketSocket> socket_; 92 rtc::scoped_ptr<rtc::AsyncPacketSocket> socket_;
93 93
94 // Temporary SocketAddress and buffer for RecvFrom. 94 // Temporary SocketAddress and buffer for RecvFrom.
95 rtc::SocketAddress addr_; 95 rtc::SocketAddress addr_;
96 rtc::scoped_ptr<rtc::ByteBuffer> response_packet_; 96 rtc::scoped_ptr<rtc::ByteBuffer> response_packet_;
97 97
98 std::vector<Request*> requests_; 98 std::vector<Request*> requests_;
99 std::vector<rtc::SocketAddress> server_ips_; 99 std::vector<rtc::SocketAddress> server_ips_;
100 int16 num_request_sent_ = 0; 100 int16_t num_request_sent_ = 0;
101 int16 num_response_received_ = 0; 101 int16_t num_response_received_ = 0;
102 102
103 rtc::ThreadChecker& thread_checker_; 103 rtc::ThreadChecker& thread_checker_;
104 104
105 RTC_DISALLOW_COPY_AND_ASSIGN(Requester); 105 RTC_DISALLOW_COPY_AND_ASSIGN(Requester);
106 }; 106 };
107 107
108 StunProber::Requester::Requester( 108 StunProber::Requester::Requester(
109 StunProber* prober, 109 StunProber* prober,
110 rtc::AsyncPacketSocket* socket, 110 rtc::AsyncPacketSocket* socket,
111 const std::vector<rtc::SocketAddress>& server_ips) 111 const std::vector<rtc::SocketAddress>& server_ips)
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 } 162 }
163 163
164 request.sent_time_ms = rtc::Time(); 164 request.sent_time_ms = rtc::Time();
165 165
166 num_request_sent_++; 166 num_request_sent_++;
167 RTC_DCHECK(static_cast<size_t>(num_request_sent_) <= server_ips_.size()); 167 RTC_DCHECK(static_cast<size_t>(num_request_sent_) <= server_ips_.size());
168 } 168 }
169 169
170 void StunProber::Requester::Request::ProcessResponse(const char* buf, 170 void StunProber::Requester::Request::ProcessResponse(const char* buf,
171 size_t buf_len) { 171 size_t buf_len) {
172 int64 now = rtc::Time(); 172 int64_t now = rtc::Time();
173 rtc::ByteBuffer message(buf, buf_len); 173 rtc::ByteBuffer message(buf, buf_len);
174 cricket::StunMessage stun_response; 174 cricket::StunMessage stun_response;
175 if (!stun_response.Read(&message)) { 175 if (!stun_response.Read(&message)) {
176 // Invalid or incomplete STUN packet. 176 // Invalid or incomplete STUN packet.
177 received_time_ms = 0; 177 received_time_ms = 0;
178 return; 178 return;
179 } 179 }
180 180
181 // Get external address of the socket. 181 // Get external address of the socket.
182 const cricket::StunAddressAttribute* addr_attr = 182 const cricket::StunAddressAttribute* addr_attr =
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 if (!current_requester_) { 369 if (!current_requester_) {
370 return false; 370 return false;
371 } 371 }
372 current_requester_->SendStunRequest(); 372 current_requester_->SendStunRequest();
373 num_request_sent_++; 373 num_request_sent_++;
374 return true; 374 return true;
375 } 375 }
376 376
377 void StunProber::MaybeScheduleStunRequests() { 377 void StunProber::MaybeScheduleStunRequests() {
378 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 378 RTC_DCHECK(thread_checker_.CalledOnValidThread());
379 uint32 now = rtc::Time(); 379 uint32_t now = rtc::Time();
380 380
381 if (Done()) { 381 if (Done()) {
382 invoker_.AsyncInvokeDelayed<void>( 382 invoker_.AsyncInvokeDelayed<void>(
383 thread_, rtc::Bind(&StunProber::End, this, SUCCESS), timeout_ms_); 383 thread_, rtc::Bind(&StunProber::End, this, SUCCESS), timeout_ms_);
384 return; 384 return;
385 } 385 }
386 if ((now + (thread_wake_up_interval_ms / 2)) >= next_request_time_ms_) { 386 if ((now + (thread_wake_up_interval_ms / 2)) >= next_request_time_ms_) {
387 if (!SendNextRequest()) { 387 if (!SendNextRequest()) {
388 End(GENERIC_FAILURE); 388 End(GENERIC_FAILURE);
389 return; 389 return;
390 } 390 }
391 next_request_time_ms_ = now + interval_ms_; 391 next_request_time_ms_ = now + interval_ms_;
392 } 392 }
393 invoker_.AsyncInvokeDelayed<void>( 393 invoker_.AsyncInvokeDelayed<void>(
394 thread_, rtc::Bind(&StunProber::MaybeScheduleStunRequests, this), 394 thread_, rtc::Bind(&StunProber::MaybeScheduleStunRequests, this),
395 thread_wake_up_interval_ms /* ms */); 395 thread_wake_up_interval_ms /* ms */);
396 } 396 }
397 397
398 bool StunProber::GetStats(StunProber::Stats* prob_stats) const { 398 bool StunProber::GetStats(StunProber::Stats* prob_stats) const {
399 // No need to be on the same thread. 399 // No need to be on the same thread.
400 if (!prob_stats) { 400 if (!prob_stats) {
401 return false; 401 return false;
402 } 402 }
403 403
404 StunProber::Stats stats; 404 StunProber::Stats stats;
405 405
406 int rtt_sum = 0; 406 int rtt_sum = 0;
407 int64 first_sent_time = 0; 407 int64_t first_sent_time = 0;
408 int64 last_sent_time = 0; 408 int64_t last_sent_time = 0;
409 NatType nat_type = NATTYPE_INVALID; 409 NatType nat_type = NATTYPE_INVALID;
410 410
411 // Track of how many srflx IP that we have seen. 411 // Track of how many srflx IP that we have seen.
412 std::set<rtc::IPAddress> srflx_ips; 412 std::set<rtc::IPAddress> srflx_ips;
413 413
414 // If we're not receiving any response on a given IP, all requests sent to 414 // If we're not receiving any response on a given IP, all requests sent to
415 // that IP should be ignored as this could just be an DNS error. 415 // that IP should be ignored as this could just be an DNS error.
416 std::map<rtc::IPAddress, int> num_response_per_server; 416 std::map<rtc::IPAddress, int> num_response_per_server;
417 std::map<rtc::IPAddress, int> num_request_per_server; 417 std::map<rtc::IPAddress, int> num_request_per_server;
418 418
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 if (!finished_callback_.empty()) { 525 if (!finished_callback_.empty()) {
526 AsyncCallback callback = finished_callback_; 526 AsyncCallback callback = finished_callback_;
527 finished_callback_ = AsyncCallback(); 527 finished_callback_ = AsyncCallback();
528 528
529 // Callback at the last since the prober might be deleted in the callback. 529 // Callback at the last since the prober might be deleted in the callback.
530 callback(this, status); 530 callback(this, status);
531 } 531 }
532 } 532 }
533 533
534 } // namespace stunprober 534 } // namespace stunprober
OLDNEW
« no previous file with comments | « webrtc/p2p/stunprober/stunprober.h ('k') | webrtc/p2p/stunprober/stunprober_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698