| 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 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 SendDelayed(request, 0); | 42 SendDelayed(request, 0); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void StunRequestManager::SendDelayed(StunRequest* request, int delay) { | 45 void StunRequestManager::SendDelayed(StunRequest* request, int delay) { |
| 46 request->set_manager(this); | 46 request->set_manager(this); |
| 47 ASSERT(requests_.find(request->id()) == requests_.end()); | 47 ASSERT(requests_.find(request->id()) == requests_.end()); |
| 48 request->set_origin(origin_); | 48 request->set_origin(origin_); |
| 49 request->Construct(); | 49 request->Construct(); |
| 50 requests_[request->id()] = request; | 50 requests_[request->id()] = request; |
| 51 if (delay > 0) { | 51 if (delay > 0) { |
| 52 thread_->PostDelayed(delay, request, MSG_STUN_SEND, NULL); | 52 thread_->PostDelayed(RTC_FROM_HERE, delay, request, MSG_STUN_SEND, NULL); |
| 53 } else { | 53 } else { |
| 54 thread_->Send(request, MSG_STUN_SEND, NULL); | 54 thread_->Send(RTC_FROM_HERE, request, MSG_STUN_SEND, NULL); |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 | 57 |
| 58 void StunRequestManager::Flush(int msg_type) { | 58 void StunRequestManager::Flush(int msg_type) { |
| 59 for (const auto kv : requests_) { | 59 for (const auto kv : requests_) { |
| 60 StunRequest* request = kv.second; | 60 StunRequest* request = kv.second; |
| 61 if (msg_type == kAllRequests || msg_type == request->type()) { | 61 if (msg_type == kAllRequests || msg_type == request->type()) { |
| 62 thread_->Clear(request, MSG_STUN_SEND); | 62 thread_->Clear(request, MSG_STUN_SEND); |
| 63 thread_->Send(request, MSG_STUN_SEND, NULL); | 63 thread_->Send(RTC_FROM_HERE, request, MSG_STUN_SEND, NULL); |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 | 67 |
| 68 bool StunRequestManager::HasRequest(int msg_type) { | 68 bool StunRequestManager::HasRequest(int msg_type) { |
| 69 for (const auto kv : requests_) { | 69 for (const auto kv : requests_) { |
| 70 StunRequest* request = kv.second; | 70 StunRequest* request = kv.second; |
| 71 if (msg_type == kAllRequests || msg_type == request->type()) { | 71 if (msg_type == kAllRequests || msg_type == request->type()) { |
| 72 return true; | 72 return true; |
| 73 } | 73 } |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 return; | 213 return; |
| 214 } | 214 } |
| 215 | 215 |
| 216 tstamp_ = rtc::TimeMillis(); | 216 tstamp_ = rtc::TimeMillis(); |
| 217 | 217 |
| 218 rtc::ByteBufferWriter buf; | 218 rtc::ByteBufferWriter buf; |
| 219 msg_->Write(&buf); | 219 msg_->Write(&buf); |
| 220 manager_->SignalSendPacket(buf.Data(), buf.Length(), this); | 220 manager_->SignalSendPacket(buf.Data(), buf.Length(), this); |
| 221 | 221 |
| 222 OnSent(); | 222 OnSent(); |
| 223 manager_->thread_->PostDelayed(resend_delay(), this, MSG_STUN_SEND, NULL); | 223 manager_->thread_->PostDelayed(RTC_FROM_HERE, resend_delay(), this, |
| 224 MSG_STUN_SEND, NULL); |
| 224 } | 225 } |
| 225 | 226 |
| 226 void StunRequest::OnSent() { | 227 void StunRequest::OnSent() { |
| 227 count_ += 1; | 228 count_ += 1; |
| 228 if (count_ == MAX_SENDS) { | 229 if (count_ == MAX_SENDS) { |
| 229 timeout_ = true; | 230 timeout_ = true; |
| 230 } | 231 } |
| 231 LOG(LS_VERBOSE) << "Sent STUN request " << count_ | 232 LOG(LS_VERBOSE) << "Sent STUN request " << count_ |
| 232 << "; resend delay = " << resend_delay(); | 233 << "; resend delay = " << resend_delay(); |
| 233 } | 234 } |
| 234 | 235 |
| 235 int StunRequest::resend_delay() { | 236 int StunRequest::resend_delay() { |
| 236 if (count_ == 0) { | 237 if (count_ == 0) { |
| 237 return 0; | 238 return 0; |
| 238 } | 239 } |
| 239 return DELAY_UNIT * std::min(1 << (count_-1), DELAY_MAX_FACTOR); | 240 return DELAY_UNIT * std::min(1 << (count_-1), DELAY_MAX_FACTOR); |
| 240 } | 241 } |
| 241 | 242 |
| 242 } // namespace cricket | 243 } // namespace cricket |
| OLD | NEW |