| 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 // request timing could become too complicated. Callback is ignored by passing | 154 // request timing could become too complicated. Callback is ignored by passing |
| 155 // empty AsyncCallback. | 155 // empty AsyncCallback. |
| 156 rtc::PacketOptions options; | 156 rtc::PacketOptions options; |
| 157 int rv = socket_->SendTo(const_cast<char*>(request_packet->Data()), | 157 int rv = socket_->SendTo(const_cast<char*>(request_packet->Data()), |
| 158 request_packet->Length(), addr, options); | 158 request_packet->Length(), addr, options); |
| 159 if (rv < 0) { | 159 if (rv < 0) { |
| 160 prober_->ReportOnFinished(WRITE_FAILED); | 160 prober_->ReportOnFinished(WRITE_FAILED); |
| 161 return; | 161 return; |
| 162 } | 162 } |
| 163 | 163 |
| 164 request.sent_time_ms = rtc::Time(); | 164 request.sent_time_ms = rtc::Time64(); |
| 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_t now = rtc::Time(); | 172 int64_t now = rtc::Time64(); |
| 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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 requesters_.push_back(current_requester_); | 387 requesters_.push_back(current_requester_); |
| 388 } | 388 } |
| 389 if (!current_requester_) { | 389 if (!current_requester_) { |
| 390 return false; | 390 return false; |
| 391 } | 391 } |
| 392 current_requester_->SendStunRequest(); | 392 current_requester_->SendStunRequest(); |
| 393 num_request_sent_++; | 393 num_request_sent_++; |
| 394 return true; | 394 return true; |
| 395 } | 395 } |
| 396 | 396 |
| 397 bool StunProber::should_send_next_request(uint32_t now) { | 397 bool StunProber::should_send_next_request(int64_t now) { |
| 398 if (interval_ms_ < THREAD_WAKE_UP_INTERVAL_MS) { | 398 if (interval_ms_ < THREAD_WAKE_UP_INTERVAL_MS) { |
| 399 return now >= next_request_time_ms_; | 399 return now >= next_request_time_ms_; |
| 400 } else { | 400 } else { |
| 401 return (now + (THREAD_WAKE_UP_INTERVAL_MS / 2)) >= next_request_time_ms_; | 401 return (now + (THREAD_WAKE_UP_INTERVAL_MS / 2)) >= next_request_time_ms_; |
| 402 } | 402 } |
| 403 } | 403 } |
| 404 | 404 |
| 405 int StunProber::get_wake_up_interval_ms() { | 405 int StunProber::get_wake_up_interval_ms() { |
| 406 if (interval_ms_ < THREAD_WAKE_UP_INTERVAL_MS) { | 406 if (interval_ms_ < THREAD_WAKE_UP_INTERVAL_MS) { |
| 407 return 1; | 407 return 1; |
| 408 } else { | 408 } else { |
| 409 return THREAD_WAKE_UP_INTERVAL_MS; | 409 return THREAD_WAKE_UP_INTERVAL_MS; |
| 410 } | 410 } |
| 411 } | 411 } |
| 412 | 412 |
| 413 void StunProber::MaybeScheduleStunRequests() { | 413 void StunProber::MaybeScheduleStunRequests() { |
| 414 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 414 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 415 uint32_t now = rtc::Time(); | 415 int64_t now = rtc::Time64(); |
| 416 | 416 |
| 417 if (Done()) { | 417 if (Done()) { |
| 418 invoker_.AsyncInvokeDelayed<void>( | 418 invoker_.AsyncInvokeDelayed<void>( |
| 419 thread_, rtc::Bind(&StunProber::ReportOnFinished, this, SUCCESS), | 419 thread_, rtc::Bind(&StunProber::ReportOnFinished, this, SUCCESS), |
| 420 timeout_ms_); | 420 timeout_ms_); |
| 421 return; | 421 return; |
| 422 } | 422 } |
| 423 if (should_send_next_request(now)) { | 423 if (should_send_next_request(now)) { |
| 424 if (!SendNextRequest()) { | 424 if (!SendNextRequest()) { |
| 425 ReportOnFinished(GENERIC_FAILURE); | 425 ReportOnFinished(GENERIC_FAILURE); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 } | 561 } |
| 562 } | 562 } |
| 563 | 563 |
| 564 void StunProber::ReportOnFinished(StunProber::Status status) { | 564 void StunProber::ReportOnFinished(StunProber::Status status) { |
| 565 if (observer_) { | 565 if (observer_) { |
| 566 observer_->OnFinished(this, status); | 566 observer_->OnFinished(this, status); |
| 567 } | 567 } |
| 568 } | 568 } |
| 569 | 569 |
| 570 } // namespace stunprober | 570 } // namespace stunprober |
| OLD | NEW |