| 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 |
| 11 #include "webrtc/p2p/base/stunrequest.h" | 11 #include "webrtc/p2p/base/stunrequest.h" |
| 12 | 12 |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 #include "webrtc/base/common.h" | 14 #include "webrtc/base/common.h" |
| 15 #include "webrtc/base/helpers.h" | 15 #include "webrtc/base/helpers.h" |
| 16 #include "webrtc/base/logging.h" | 16 #include "webrtc/base/logging.h" |
| 17 #include "webrtc/base/stringencode.h" | 17 #include "webrtc/base/stringencode.h" |
| 18 | 18 |
| 19 namespace cricket { | 19 namespace cricket { |
| 20 | 20 |
| 21 const uint32 MSG_STUN_SEND = 1; | 21 const uint32_t MSG_STUN_SEND = 1; |
| 22 | 22 |
| 23 const int MAX_SENDS = 9; | 23 const int MAX_SENDS = 9; |
| 24 const int DELAY_UNIT = 100; // 100 milliseconds | 24 const int DELAY_UNIT = 100; // 100 milliseconds |
| 25 const int DELAY_MAX_FACTOR = 16; | 25 const int DELAY_MAX_FACTOR = 16; |
| 26 | 26 |
| 27 StunRequestManager::StunRequestManager(rtc::Thread* thread) | 27 StunRequestManager::StunRequestManager(rtc::Thread* thread) |
| 28 : thread_(thread) { | 28 : thread_(thread) { |
| 29 } | 29 } |
| 30 | 30 |
| 31 StunRequestManager::~StunRequestManager() { | 31 StunRequestManager::~StunRequestManager() { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 61 requests_.erase(iter); | 61 requests_.erase(iter); |
| 62 thread_->Clear(request); | 62 thread_->Clear(request); |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 | 65 |
| 66 void StunRequestManager::Clear() { | 66 void StunRequestManager::Clear() { |
| 67 std::vector<StunRequest*> requests; | 67 std::vector<StunRequest*> requests; |
| 68 for (RequestMap::iterator i = requests_.begin(); i != requests_.end(); ++i) | 68 for (RequestMap::iterator i = requests_.begin(); i != requests_.end(); ++i) |
| 69 requests.push_back(i->second); | 69 requests.push_back(i->second); |
| 70 | 70 |
| 71 for (uint32 i = 0; i < requests.size(); ++i) { | 71 for (uint32_t i = 0; i < requests.size(); ++i) { |
| 72 // StunRequest destructor calls Remove() which deletes requests | 72 // StunRequest destructor calls Remove() which deletes requests |
| 73 // from |requests_|. | 73 // from |requests_|. |
| 74 delete requests[i]; | 74 delete requests[i]; |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 | 77 |
| 78 bool StunRequestManager::CheckResponse(StunMessage* msg) { | 78 bool StunRequestManager::CheckResponse(StunMessage* msg) { |
| 79 RequestMap::iterator iter = requests_.find(msg->transaction_id()); | 79 RequestMap::iterator iter = requests_.find(msg->transaction_id()); |
| 80 if (iter == requests_.end()) { | 80 if (iter == requests_.end()) { |
| 81 // TODO(pthatcher): Log unknown responses without being too spammy | 81 // TODO(pthatcher): Log unknown responses without being too spammy |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 | 164 |
| 165 int StunRequest::type() { | 165 int StunRequest::type() { |
| 166 ASSERT(msg_ != NULL); | 166 ASSERT(msg_ != NULL); |
| 167 return msg_->type(); | 167 return msg_->type(); |
| 168 } | 168 } |
| 169 | 169 |
| 170 const StunMessage* StunRequest::msg() const { | 170 const StunMessage* StunRequest::msg() const { |
| 171 return msg_; | 171 return msg_; |
| 172 } | 172 } |
| 173 | 173 |
| 174 uint32 StunRequest::Elapsed() const { | 174 uint32_t StunRequest::Elapsed() const { |
| 175 return rtc::TimeSince(tstamp_); | 175 return rtc::TimeSince(tstamp_); |
| 176 } | 176 } |
| 177 | 177 |
| 178 | 178 |
| 179 void StunRequest::set_manager(StunRequestManager* manager) { | 179 void StunRequest::set_manager(StunRequestManager* manager) { |
| 180 ASSERT(!manager_); | 180 ASSERT(!manager_); |
| 181 manager_ = manager; | 181 manager_ = manager; |
| 182 } | 182 } |
| 183 | 183 |
| 184 void StunRequest::OnMessage(rtc::Message* pmsg) { | 184 void StunRequest::OnMessage(rtc::Message* pmsg) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 208 } | 208 } |
| 209 | 209 |
| 210 int StunRequest::resend_delay() { | 210 int StunRequest::resend_delay() { |
| 211 if (count_ == 0) { | 211 if (count_ == 0) { |
| 212 return 0; | 212 return 0; |
| 213 } | 213 } |
| 214 return DELAY_UNIT * std::min(1 << (count_-1), DELAY_MAX_FACTOR); | 214 return DELAY_UNIT * std::min(1 << (count_-1), DELAY_MAX_FACTOR); |
| 215 } | 215 } |
| 216 | 216 |
| 217 } // namespace cricket | 217 } // namespace cricket |
| OLD | NEW |