| 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 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 using rtc::CreateRandomId; | 30 using rtc::CreateRandomId; |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 enum { | 34 enum { |
| 35 MSG_CONFIG_START, | 35 MSG_CONFIG_START, |
| 36 MSG_CONFIG_READY, | 36 MSG_CONFIG_READY, |
| 37 MSG_ALLOCATE, | 37 MSG_ALLOCATE, |
| 38 MSG_ALLOCATION_PHASE, | 38 MSG_ALLOCATION_PHASE, |
| 39 MSG_SHAKE, | |
| 40 MSG_SEQUENCEOBJECTS_CREATED, | 39 MSG_SEQUENCEOBJECTS_CREATED, |
| 41 MSG_CONFIG_STOP, | 40 MSG_CONFIG_STOP, |
| 42 }; | 41 }; |
| 43 | 42 |
| 44 const int PHASE_UDP = 0; | 43 const int PHASE_UDP = 0; |
| 45 const int PHASE_RELAY = 1; | 44 const int PHASE_RELAY = 1; |
| 46 const int PHASE_TCP = 2; | 45 const int PHASE_TCP = 2; |
| 47 const int PHASE_SSLTCP = 3; | 46 const int PHASE_SSLTCP = 3; |
| 48 | 47 |
| 49 const int kNumPhases = 4; | 48 const int kNumPhases = 4; |
| 50 | 49 |
| 51 const int SHAKE_MIN_DELAY = 45 * 1000; // 45 seconds | |
| 52 const int SHAKE_MAX_DELAY = 90 * 1000; // 90 seconds | |
| 53 | |
| 54 int ShakeDelay() { | |
| 55 int range = SHAKE_MAX_DELAY - SHAKE_MIN_DELAY + 1; | |
| 56 return SHAKE_MIN_DELAY + CreateRandomId() % range; | |
| 57 } | |
| 58 | |
| 59 } // namespace | 50 } // namespace |
| 60 | 51 |
| 61 namespace cricket { | 52 namespace cricket { |
| 62 const uint32_t DISABLE_ALL_PHASES = | 53 const uint32_t DISABLE_ALL_PHASES = |
| 63 PORTALLOCATOR_DISABLE_UDP | PORTALLOCATOR_DISABLE_TCP | | 54 PORTALLOCATOR_DISABLE_UDP | PORTALLOCATOR_DISABLE_TCP | |
| 64 PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY; | 55 PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY; |
| 65 | 56 |
| 66 // BasicPortAllocator | 57 // BasicPortAllocator |
| 67 BasicPortAllocator::BasicPortAllocator(rtc::NetworkManager* network_manager, | 58 BasicPortAllocator::BasicPortAllocator(rtc::NetworkManager* network_manager, |
| 68 rtc::PacketSocketFactory* socket_factory) | 59 rtc::PacketSocketFactory* socket_factory) |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 void BasicPortAllocatorSession::StartGettingPorts() { | 170 void BasicPortAllocatorSession::StartGettingPorts() { |
| 180 network_thread_ = rtc::Thread::Current(); | 171 network_thread_ = rtc::Thread::Current(); |
| 181 if (!socket_factory_) { | 172 if (!socket_factory_) { |
| 182 owned_socket_factory_.reset( | 173 owned_socket_factory_.reset( |
| 183 new rtc::BasicPacketSocketFactory(network_thread_)); | 174 new rtc::BasicPacketSocketFactory(network_thread_)); |
| 184 socket_factory_ = owned_socket_factory_.get(); | 175 socket_factory_ = owned_socket_factory_.get(); |
| 185 } | 176 } |
| 186 | 177 |
| 187 running_ = true; | 178 running_ = true; |
| 188 network_thread_->Post(this, MSG_CONFIG_START); | 179 network_thread_->Post(this, MSG_CONFIG_START); |
| 189 | |
| 190 if (flags() & PORTALLOCATOR_ENABLE_SHAKER) | |
| 191 network_thread_->PostDelayed(ShakeDelay(), this, MSG_SHAKE); | |
| 192 } | 180 } |
| 193 | 181 |
| 194 void BasicPortAllocatorSession::StopGettingPorts() { | 182 void BasicPortAllocatorSession::StopGettingPorts() { |
| 195 ASSERT(rtc::Thread::Current() == network_thread_); | 183 ASSERT(rtc::Thread::Current() == network_thread_); |
| 196 running_ = false; | 184 running_ = false; |
| 197 network_thread_->Post(this, MSG_CONFIG_STOP); | 185 network_thread_->Post(this, MSG_CONFIG_STOP); |
| 198 ClearGettingPorts(); | 186 ClearGettingPorts(); |
| 199 } | 187 } |
| 200 | 188 |
| 201 void BasicPortAllocatorSession::ClearGettingPorts() { | 189 void BasicPortAllocatorSession::ClearGettingPorts() { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 | 246 |
| 259 return true; | 247 return true; |
| 260 } | 248 } |
| 261 | 249 |
| 262 void BasicPortAllocatorSession::OnMessage(rtc::Message *message) { | 250 void BasicPortAllocatorSession::OnMessage(rtc::Message *message) { |
| 263 switch (message->message_id) { | 251 switch (message->message_id) { |
| 264 case MSG_CONFIG_START: | 252 case MSG_CONFIG_START: |
| 265 ASSERT(rtc::Thread::Current() == network_thread_); | 253 ASSERT(rtc::Thread::Current() == network_thread_); |
| 266 GetPortConfigurations(); | 254 GetPortConfigurations(); |
| 267 break; | 255 break; |
| 268 | |
| 269 case MSG_CONFIG_READY: | 256 case MSG_CONFIG_READY: |
| 270 ASSERT(rtc::Thread::Current() == network_thread_); | 257 ASSERT(rtc::Thread::Current() == network_thread_); |
| 271 OnConfigReady(static_cast<PortConfiguration*>(message->pdata)); | 258 OnConfigReady(static_cast<PortConfiguration*>(message->pdata)); |
| 272 break; | 259 break; |
| 273 | |
| 274 case MSG_ALLOCATE: | 260 case MSG_ALLOCATE: |
| 275 ASSERT(rtc::Thread::Current() == network_thread_); | 261 ASSERT(rtc::Thread::Current() == network_thread_); |
| 276 OnAllocate(); | 262 OnAllocate(); |
| 277 break; | 263 break; |
| 278 | |
| 279 case MSG_SHAKE: | |
| 280 ASSERT(rtc::Thread::Current() == network_thread_); | |
| 281 OnShake(); | |
| 282 break; | |
| 283 case MSG_SEQUENCEOBJECTS_CREATED: | 264 case MSG_SEQUENCEOBJECTS_CREATED: |
| 284 ASSERT(rtc::Thread::Current() == network_thread_); | 265 ASSERT(rtc::Thread::Current() == network_thread_); |
| 285 OnAllocationSequenceObjectsCreated(); | 266 OnAllocationSequenceObjectsCreated(); |
| 286 break; | 267 break; |
| 287 case MSG_CONFIG_STOP: | 268 case MSG_CONFIG_STOP: |
| 288 ASSERT(rtc::Thread::Current() == network_thread_); | 269 ASSERT(rtc::Thread::Current() == network_thread_); |
| 289 OnConfigStop(); | 270 OnConfigStop(); |
| 290 break; | 271 break; |
| 291 default: | 272 default: |
| 292 ASSERT(false); | 273 ASSERT(false); |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 if (port == iter->port()) { | 687 if (port == iter->port()) { |
| 707 ports_.erase(iter); | 688 ports_.erase(iter); |
| 708 LOG_J(LS_INFO, port) << "Removed port from allocator (" | 689 LOG_J(LS_INFO, port) << "Removed port from allocator (" |
| 709 << static_cast<int>(ports_.size()) << " remaining)"; | 690 << static_cast<int>(ports_.size()) << " remaining)"; |
| 710 return; | 691 return; |
| 711 } | 692 } |
| 712 } | 693 } |
| 713 ASSERT(false); | 694 ASSERT(false); |
| 714 } | 695 } |
| 715 | 696 |
| 716 void BasicPortAllocatorSession::OnShake() { | |
| 717 LOG(INFO) << ">>>>> SHAKE <<<<< >>>>> SHAKE <<<<< >>>>> SHAKE <<<<<"; | |
| 718 | |
| 719 std::vector<Port*> ports; | |
| 720 std::vector<Connection*> connections; | |
| 721 | |
| 722 for (size_t i = 0; i < ports_.size(); ++i) { | |
| 723 if (ports_[i].ready()) | |
| 724 ports.push_back(ports_[i].port()); | |
| 725 } | |
| 726 | |
| 727 for (size_t i = 0; i < ports.size(); ++i) { | |
| 728 Port::AddressMap::const_iterator iter; | |
| 729 for (iter = ports[i]->connections().begin(); | |
| 730 iter != ports[i]->connections().end(); | |
| 731 ++iter) { | |
| 732 connections.push_back(iter->second); | |
| 733 } | |
| 734 } | |
| 735 | |
| 736 LOG(INFO) << ">>>>> Destroying " << ports.size() << " ports and " | |
| 737 << connections.size() << " connections"; | |
| 738 | |
| 739 for (size_t i = 0; i < connections.size(); ++i) | |
| 740 connections[i]->Destroy(); | |
| 741 | |
| 742 if (running_ || (ports.size() > 0) || (connections.size() > 0)) | |
| 743 network_thread_->PostDelayed(ShakeDelay(), this, MSG_SHAKE); | |
| 744 } | |
| 745 | |
| 746 BasicPortAllocatorSession::PortData* BasicPortAllocatorSession::FindPort( | 697 BasicPortAllocatorSession::PortData* BasicPortAllocatorSession::FindPort( |
| 747 Port* port) { | 698 Port* port) { |
| 748 for (std::vector<PortData>::iterator it = ports_.begin(); | 699 for (std::vector<PortData>::iterator it = ports_.begin(); |
| 749 it != ports_.end(); ++it) { | 700 it != ports_.end(); ++it) { |
| 750 if (it->port() == port) { | 701 if (it->port() == port) { |
| 751 return &*it; | 702 return &*it; |
| 752 } | 703 } |
| 753 } | 704 } |
| 754 return NULL; | 705 return NULL; |
| 755 } | 706 } |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1233 ServerAddresses servers; | 1184 ServerAddresses servers; |
| 1234 for (size_t i = 0; i < relays.size(); ++i) { | 1185 for (size_t i = 0; i < relays.size(); ++i) { |
| 1235 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { | 1186 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { |
| 1236 servers.insert(relays[i].ports.front().address); | 1187 servers.insert(relays[i].ports.front().address); |
| 1237 } | 1188 } |
| 1238 } | 1189 } |
| 1239 return servers; | 1190 return servers; |
| 1240 } | 1191 } |
| 1241 | 1192 |
| 1242 } // namespace cricket | 1193 } // namespace cricket |
| OLD | NEW |