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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 178 |
179 void BasicPortAllocatorSession::StartGettingPorts() { | 179 void BasicPortAllocatorSession::StartGettingPorts() { |
180 network_thread_ = rtc::Thread::Current(); | 180 network_thread_ = rtc::Thread::Current(); |
181 if (!socket_factory_) { | 181 if (!socket_factory_) { |
182 owned_socket_factory_.reset( | 182 owned_socket_factory_.reset( |
183 new rtc::BasicPacketSocketFactory(network_thread_)); | 183 new rtc::BasicPacketSocketFactory(network_thread_)); |
184 socket_factory_ = owned_socket_factory_.get(); | 184 socket_factory_ = owned_socket_factory_.get(); |
185 } | 185 } |
186 | 186 |
187 running_ = true; | 187 running_ = true; |
188 network_thread_->Post(this, MSG_CONFIG_START); | 188 network_thread_->Post(FROM_HERE, this, MSG_CONFIG_START); |
189 | 189 |
190 if (flags() & PORTALLOCATOR_ENABLE_SHAKER) | 190 if (flags() & PORTALLOCATOR_ENABLE_SHAKER) |
191 network_thread_->PostDelayed(ShakeDelay(), this, MSG_SHAKE); | 191 network_thread_->PostDelayed(FROM_HERE, ShakeDelay(), this, MSG_SHAKE); |
192 } | 192 } |
193 | 193 |
194 void BasicPortAllocatorSession::StopGettingPorts() { | 194 void BasicPortAllocatorSession::StopGettingPorts() { |
195 ASSERT(rtc::Thread::Current() == network_thread_); | 195 ASSERT(rtc::Thread::Current() == network_thread_); |
196 running_ = false; | 196 running_ = false; |
197 network_thread_->Post(this, MSG_CONFIG_STOP); | 197 network_thread_->Post(FROM_HERE, this, MSG_CONFIG_STOP); |
198 ClearGettingPorts(); | 198 ClearGettingPorts(); |
199 } | 199 } |
200 | 200 |
201 void BasicPortAllocatorSession::ClearGettingPorts() { | 201 void BasicPortAllocatorSession::ClearGettingPorts() { |
202 network_thread_->Clear(this, MSG_ALLOCATE); | 202 network_thread_->Clear(this, MSG_ALLOCATE); |
203 for (uint32_t i = 0; i < sequences_.size(); ++i) | 203 for (uint32_t i = 0; i < sequences_.size(); ++i) |
204 sequences_[i]->Stop(); | 204 sequences_[i]->Stop(); |
205 } | 205 } |
206 | 206 |
207 std::vector<PortInterface*> BasicPortAllocatorSession::ReadyPorts() const { | 207 std::vector<PortInterface*> BasicPortAllocatorSession::ReadyPorts() const { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 username(), | 305 username(), |
306 password()); | 306 password()); |
307 | 307 |
308 for (const RelayServerConfig& turn_server : allocator_->turn_servers()) { | 308 for (const RelayServerConfig& turn_server : allocator_->turn_servers()) { |
309 config->AddRelay(turn_server); | 309 config->AddRelay(turn_server); |
310 } | 310 } |
311 ConfigReady(config); | 311 ConfigReady(config); |
312 } | 312 } |
313 | 313 |
314 void BasicPortAllocatorSession::ConfigReady(PortConfiguration* config) { | 314 void BasicPortAllocatorSession::ConfigReady(PortConfiguration* config) { |
315 network_thread_->Post(this, MSG_CONFIG_READY, config); | 315 network_thread_->Post(FROM_HERE, this, MSG_CONFIG_READY, config); |
316 } | 316 } |
317 | 317 |
318 // Adds a configuration to the list. | 318 // Adds a configuration to the list. |
319 void BasicPortAllocatorSession::OnConfigReady(PortConfiguration* config) { | 319 void BasicPortAllocatorSession::OnConfigReady(PortConfiguration* config) { |
320 if (config) { | 320 if (config) { |
321 configs_.push_back(config); | 321 configs_.push_back(config); |
322 } | 322 } |
323 | 323 |
324 AllocatePorts(); | 324 AllocatePorts(); |
325 } | 325 } |
(...skipping 24 matching lines...) Expand all Loading... |
350 } | 350 } |
351 | 351 |
352 // If we stopped anything that was running, send a done signal now. | 352 // If we stopped anything that was running, send a done signal now. |
353 if (send_signal) { | 353 if (send_signal) { |
354 MaybeSignalCandidatesAllocationDone(); | 354 MaybeSignalCandidatesAllocationDone(); |
355 } | 355 } |
356 } | 356 } |
357 | 357 |
358 void BasicPortAllocatorSession::AllocatePorts() { | 358 void BasicPortAllocatorSession::AllocatePorts() { |
359 ASSERT(rtc::Thread::Current() == network_thread_); | 359 ASSERT(rtc::Thread::Current() == network_thread_); |
360 network_thread_->Post(this, MSG_ALLOCATE); | 360 network_thread_->Post(FROM_HERE, this, MSG_ALLOCATE); |
361 } | 361 } |
362 | 362 |
363 void BasicPortAllocatorSession::OnAllocate() { | 363 void BasicPortAllocatorSession::OnAllocate() { |
364 if (network_manager_started_) | 364 if (network_manager_started_) |
365 DoAllocate(); | 365 DoAllocate(); |
366 | 366 |
367 allocation_started_ = true; | 367 allocation_started_ = true; |
368 } | 368 } |
369 | 369 |
370 void BasicPortAllocatorSession::GetNetworks( | 370 void BasicPortAllocatorSession::GetNetworks( |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 } | 447 } |
448 done_signal_needed = true; | 448 done_signal_needed = true; |
449 sequence->SignalPortAllocationComplete.connect( | 449 sequence->SignalPortAllocationComplete.connect( |
450 this, &BasicPortAllocatorSession::OnPortAllocationComplete); | 450 this, &BasicPortAllocatorSession::OnPortAllocationComplete); |
451 if (running_) | 451 if (running_) |
452 sequence->Start(); | 452 sequence->Start(); |
453 sequences_.push_back(sequence); | 453 sequences_.push_back(sequence); |
454 } | 454 } |
455 } | 455 } |
456 if (done_signal_needed) { | 456 if (done_signal_needed) { |
457 network_thread_->Post(this, MSG_SEQUENCEOBJECTS_CREATED); | 457 network_thread_->Post(FROM_HERE, this, MSG_SEQUENCEOBJECTS_CREATED); |
458 } | 458 } |
459 } | 459 } |
460 | 460 |
461 void BasicPortAllocatorSession::OnNetworksChanged() { | 461 void BasicPortAllocatorSession::OnNetworksChanged() { |
462 std::vector<rtc::Network*> networks; | 462 std::vector<rtc::Network*> networks; |
463 GetNetworks(&networks); | 463 GetNetworks(&networks); |
464 for (AllocationSequence* sequence : sequences_) { | 464 for (AllocationSequence* sequence : sequences_) { |
465 // Remove the network from the allocation sequence if it is not in | 465 // Remove the network from the allocation sequence if it is not in |
466 // |networks|. | 466 // |networks|. |
467 if (!sequence->network_removed() && | 467 if (!sequence->network_removed() && |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 } | 733 } |
734 } | 734 } |
735 | 735 |
736 LOG(INFO) << ">>>>> Destroying " << ports.size() << " ports and " | 736 LOG(INFO) << ">>>>> Destroying " << ports.size() << " ports and " |
737 << connections.size() << " connections"; | 737 << connections.size() << " connections"; |
738 | 738 |
739 for (size_t i = 0; i < connections.size(); ++i) | 739 for (size_t i = 0; i < connections.size(); ++i) |
740 connections[i]->Destroy(); | 740 connections[i]->Destroy(); |
741 | 741 |
742 if (running_ || (ports.size() > 0) || (connections.size() > 0)) | 742 if (running_ || (ports.size() > 0) || (connections.size() > 0)) |
743 network_thread_->PostDelayed(ShakeDelay(), this, MSG_SHAKE); | 743 network_thread_->PostDelayed(FROM_HERE, ShakeDelay(), this, MSG_SHAKE); |
744 } | 744 } |
745 | 745 |
746 BasicPortAllocatorSession::PortData* BasicPortAllocatorSession::FindPort( | 746 BasicPortAllocatorSession::PortData* BasicPortAllocatorSession::FindPort( |
747 Port* port) { | 747 Port* port) { |
748 for (std::vector<PortData>::iterator it = ports_.begin(); | 748 for (std::vector<PortData>::iterator it = ports_.begin(); |
749 it != ports_.end(); ++it) { | 749 it != ports_.end(); ++it) { |
750 if (it->port() == port) { | 750 if (it->port() == port) { |
751 return &*it; | 751 return &*it; |
752 } | 752 } |
753 } | 753 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 // were to be given one, but that never happens in our codebase. Should | 831 // were to be given one, but that never happens in our codebase. Should |
832 // probably get rid of the list in PortConfiguration and just keep a | 832 // probably get rid of the list in PortConfiguration and just keep a |
833 // single relay server in each one. | 833 // single relay server in each one. |
834 *flags |= PORTALLOCATOR_DISABLE_RELAY; | 834 *flags |= PORTALLOCATOR_DISABLE_RELAY; |
835 } | 835 } |
836 } | 836 } |
837 } | 837 } |
838 | 838 |
839 void AllocationSequence::Start() { | 839 void AllocationSequence::Start() { |
840 state_ = kRunning; | 840 state_ = kRunning; |
841 session_->network_thread()->Post(this, MSG_ALLOCATION_PHASE); | 841 session_->network_thread()->Post(FROM_HERE, this, MSG_ALLOCATION_PHASE); |
842 } | 842 } |
843 | 843 |
844 void AllocationSequence::Stop() { | 844 void AllocationSequence::Stop() { |
845 // If the port is completed, don't set it to stopped. | 845 // If the port is completed, don't set it to stopped. |
846 if (state_ == kRunning) { | 846 if (state_ == kRunning) { |
847 state_ = kStopped; | 847 state_ = kStopped; |
848 session_->network_thread()->Clear(this, MSG_ALLOCATION_PHASE); | 848 session_->network_thread()->Clear(this, MSG_ALLOCATION_PHASE); |
849 } | 849 } |
850 } | 850 } |
851 | 851 |
(...skipping 29 matching lines...) Expand all Loading... |
881 state_ = kCompleted; | 881 state_ = kCompleted; |
882 EnableProtocol(PROTO_SSLTCP); | 882 EnableProtocol(PROTO_SSLTCP); |
883 break; | 883 break; |
884 | 884 |
885 default: | 885 default: |
886 ASSERT(false); | 886 ASSERT(false); |
887 } | 887 } |
888 | 888 |
889 if (state() == kRunning) { | 889 if (state() == kRunning) { |
890 ++phase_; | 890 ++phase_; |
891 session_->network_thread()->PostDelayed( | 891 session_->network_thread()->PostDelayed(FROM_HERE, |
892 session_->allocator()->step_delay(), | 892 session_->allocator()->step_delay(), |
893 this, MSG_ALLOCATION_PHASE); | 893 this, MSG_ALLOCATION_PHASE); |
894 } else { | 894 } else { |
895 // If all phases in AllocationSequence are completed, no allocation | 895 // If all phases in AllocationSequence are completed, no allocation |
896 // steps needed further. Canceling pending signal. | 896 // steps needed further. Canceling pending signal. |
897 session_->network_thread()->Clear(this, MSG_ALLOCATION_PHASE); | 897 session_->network_thread()->Clear(this, MSG_ALLOCATION_PHASE); |
898 SignalPortAllocationComplete(this); | 898 SignalPortAllocationComplete(this); |
899 } | 899 } |
900 } | 900 } |
901 | 901 |
902 void AllocationSequence::EnableProtocol(ProtocolType proto) { | 902 void AllocationSequence::EnableProtocol(ProtocolType proto) { |
903 if (!ProtocolEnabled(proto)) { | 903 if (!ProtocolEnabled(proto)) { |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1233 ServerAddresses servers; | 1233 ServerAddresses servers; |
1234 for (size_t i = 0; i < relays.size(); ++i) { | 1234 for (size_t i = 0; i < relays.size(); ++i) { |
1235 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { | 1235 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { |
1236 servers.insert(relays[i].ports.front().address); | 1236 servers.insert(relays[i].ports.front().address); |
1237 } | 1237 } |
1238 } | 1238 } |
1239 return servers; | 1239 return servers; |
1240 } | 1240 } |
1241 | 1241 |
1242 } // namespace cricket | 1242 } // namespace cricket |
OLD | NEW |