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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 const int SHAKE_MAX_DELAY = 90 * 1000; // 90 seconds | 52 const int SHAKE_MAX_DELAY = 90 * 1000; // 90 seconds |
53 | 53 |
54 int ShakeDelay() { | 54 int ShakeDelay() { |
55 int range = SHAKE_MAX_DELAY - SHAKE_MIN_DELAY + 1; | 55 int range = SHAKE_MAX_DELAY - SHAKE_MIN_DELAY + 1; |
56 return SHAKE_MIN_DELAY + CreateRandomId() % range; | 56 return SHAKE_MIN_DELAY + CreateRandomId() % range; |
57 } | 57 } |
58 | 58 |
59 } // namespace | 59 } // namespace |
60 | 60 |
61 namespace cricket { | 61 namespace cricket { |
62 const uint32 DISABLE_ALL_PHASES = | 62 const uint32_t DISABLE_ALL_PHASES = |
63 PORTALLOCATOR_DISABLE_UDP | PORTALLOCATOR_DISABLE_TCP | | 63 PORTALLOCATOR_DISABLE_UDP | PORTALLOCATOR_DISABLE_TCP | |
64 PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY; | 64 PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY; |
65 | 65 |
66 // BasicPortAllocator | 66 // BasicPortAllocator |
67 BasicPortAllocator::BasicPortAllocator( | 67 BasicPortAllocator::BasicPortAllocator( |
68 rtc::NetworkManager* network_manager, | 68 rtc::NetworkManager* network_manager, |
69 rtc::PacketSocketFactory* socket_factory) | 69 rtc::PacketSocketFactory* socket_factory) |
70 : network_manager_(network_manager), | 70 : network_manager_(network_manager), |
71 socket_factory_(socket_factory), | 71 socket_factory_(socket_factory), |
72 stun_servers_() { | 72 stun_servers_() { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 allocator_->network_manager()->SignalNetworksChanged.connect( | 150 allocator_->network_manager()->SignalNetworksChanged.connect( |
151 this, &BasicPortAllocatorSession::OnNetworksChanged); | 151 this, &BasicPortAllocatorSession::OnNetworksChanged); |
152 allocator_->network_manager()->StartUpdating(); | 152 allocator_->network_manager()->StartUpdating(); |
153 } | 153 } |
154 | 154 |
155 BasicPortAllocatorSession::~BasicPortAllocatorSession() { | 155 BasicPortAllocatorSession::~BasicPortAllocatorSession() { |
156 allocator_->network_manager()->StopUpdating(); | 156 allocator_->network_manager()->StopUpdating(); |
157 if (network_thread_ != NULL) | 157 if (network_thread_ != NULL) |
158 network_thread_->Clear(this); | 158 network_thread_->Clear(this); |
159 | 159 |
160 for (uint32 i = 0; i < sequences_.size(); ++i) { | 160 for (uint32_t i = 0; i < sequences_.size(); ++i) { |
161 // AllocationSequence should clear it's map entry for turn ports before | 161 // AllocationSequence should clear it's map entry for turn ports before |
162 // ports are destroyed. | 162 // ports are destroyed. |
163 sequences_[i]->Clear(); | 163 sequences_[i]->Clear(); |
164 } | 164 } |
165 | 165 |
166 std::vector<PortData>::iterator it; | 166 std::vector<PortData>::iterator it; |
167 for (it = ports_.begin(); it != ports_.end(); it++) | 167 for (it = ports_.begin(); it != ports_.end(); it++) |
168 delete it->port(); | 168 delete it->port(); |
169 | 169 |
170 for (uint32 i = 0; i < configs_.size(); ++i) | 170 for (uint32_t i = 0; i < configs_.size(); ++i) |
171 delete configs_[i]; | 171 delete configs_[i]; |
172 | 172 |
173 for (uint32 i = 0; i < sequences_.size(); ++i) | 173 for (uint32_t i = 0; i < sequences_.size(); ++i) |
174 delete sequences_[i]; | 174 delete sequences_[i]; |
175 } | 175 } |
176 | 176 |
177 void BasicPortAllocatorSession::StartGettingPorts() { | 177 void BasicPortAllocatorSession::StartGettingPorts() { |
178 network_thread_ = rtc::Thread::Current(); | 178 network_thread_ = rtc::Thread::Current(); |
179 if (!socket_factory_) { | 179 if (!socket_factory_) { |
180 owned_socket_factory_.reset( | 180 owned_socket_factory_.reset( |
181 new rtc::BasicPacketSocketFactory(network_thread_)); | 181 new rtc::BasicPacketSocketFactory(network_thread_)); |
182 socket_factory_ = owned_socket_factory_.get(); | 182 socket_factory_ = owned_socket_factory_.get(); |
183 } | 183 } |
184 | 184 |
185 running_ = true; | 185 running_ = true; |
186 network_thread_->Post(this, MSG_CONFIG_START); | 186 network_thread_->Post(this, MSG_CONFIG_START); |
187 | 187 |
188 if (flags() & PORTALLOCATOR_ENABLE_SHAKER) | 188 if (flags() & PORTALLOCATOR_ENABLE_SHAKER) |
189 network_thread_->PostDelayed(ShakeDelay(), this, MSG_SHAKE); | 189 network_thread_->PostDelayed(ShakeDelay(), this, MSG_SHAKE); |
190 } | 190 } |
191 | 191 |
192 void BasicPortAllocatorSession::StopGettingPorts() { | 192 void BasicPortAllocatorSession::StopGettingPorts() { |
193 ASSERT(rtc::Thread::Current() == network_thread_); | 193 ASSERT(rtc::Thread::Current() == network_thread_); |
194 running_ = false; | 194 running_ = false; |
195 network_thread_->Post(this, MSG_CONFIG_STOP); | 195 network_thread_->Post(this, MSG_CONFIG_STOP); |
196 ClearGettingPorts(); | 196 ClearGettingPorts(); |
197 } | 197 } |
198 | 198 |
199 void BasicPortAllocatorSession::ClearGettingPorts() { | 199 void BasicPortAllocatorSession::ClearGettingPorts() { |
200 network_thread_->Clear(this, MSG_ALLOCATE); | 200 network_thread_->Clear(this, MSG_ALLOCATE); |
201 for (uint32 i = 0; i < sequences_.size(); ++i) | 201 for (uint32_t i = 0; i < sequences_.size(); ++i) |
202 sequences_[i]->Stop(); | 202 sequences_[i]->Stop(); |
203 } | 203 } |
204 | 204 |
205 void BasicPortAllocatorSession::OnMessage(rtc::Message *message) { | 205 void BasicPortAllocatorSession::OnMessage(rtc::Message *message) { |
206 switch (message->message_id) { | 206 switch (message->message_id) { |
207 case MSG_CONFIG_START: | 207 case MSG_CONFIG_START: |
208 ASSERT(rtc::Thread::Current() == network_thread_); | 208 ASSERT(rtc::Thread::Current() == network_thread_); |
209 GetPortConfigurations(); | 209 GetPortConfigurations(); |
210 break; | 210 break; |
211 | 211 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 // create a new sequence to create the appropriate ports. | 328 // create a new sequence to create the appropriate ports. |
329 void BasicPortAllocatorSession::DoAllocate() { | 329 void BasicPortAllocatorSession::DoAllocate() { |
330 bool done_signal_needed = false; | 330 bool done_signal_needed = false; |
331 std::vector<rtc::Network*> networks; | 331 std::vector<rtc::Network*> networks; |
332 GetNetworks(&networks); | 332 GetNetworks(&networks); |
333 | 333 |
334 if (networks.empty()) { | 334 if (networks.empty()) { |
335 LOG(LS_WARNING) << "Machine has no networks; no ports will be allocated"; | 335 LOG(LS_WARNING) << "Machine has no networks; no ports will be allocated"; |
336 done_signal_needed = true; | 336 done_signal_needed = true; |
337 } else { | 337 } else { |
338 for (uint32 i = 0; i < networks.size(); ++i) { | 338 for (uint32_t i = 0; i < networks.size(); ++i) { |
339 PortConfiguration* config = NULL; | 339 PortConfiguration* config = NULL; |
340 if (configs_.size() > 0) | 340 if (configs_.size() > 0) |
341 config = configs_.back(); | 341 config = configs_.back(); |
342 | 342 |
343 uint32 sequence_flags = flags(); | 343 uint32_t sequence_flags = flags(); |
344 if ((sequence_flags & DISABLE_ALL_PHASES) == DISABLE_ALL_PHASES) { | 344 if ((sequence_flags & DISABLE_ALL_PHASES) == DISABLE_ALL_PHASES) { |
345 // If all the ports are disabled we should just fire the allocation | 345 // If all the ports are disabled we should just fire the allocation |
346 // done event and return. | 346 // done event and return. |
347 done_signal_needed = true; | 347 done_signal_needed = true; |
348 break; | 348 break; |
349 } | 349 } |
350 | 350 |
351 if (!config || config->relays.empty()) { | 351 if (!config || config->relays.empty()) { |
352 // No relay ports specified in this config. | 352 // No relay ports specified in this config. |
353 sequence_flags |= PORTALLOCATOR_DISABLE_RELAY; | 353 sequence_flags |= PORTALLOCATOR_DISABLE_RELAY; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 sequence->OnNetworkRemoved(); | 399 sequence->OnNetworkRemoved(); |
400 } | 400 } |
401 } | 401 } |
402 | 402 |
403 network_manager_started_ = true; | 403 network_manager_started_ = true; |
404 if (allocation_started_) | 404 if (allocation_started_) |
405 DoAllocate(); | 405 DoAllocate(); |
406 } | 406 } |
407 | 407 |
408 void BasicPortAllocatorSession::DisableEquivalentPhases( | 408 void BasicPortAllocatorSession::DisableEquivalentPhases( |
409 rtc::Network* network, PortConfiguration* config, uint32* flags) { | 409 rtc::Network* network, |
410 for (uint32 i = 0; i < sequences_.size() && | 410 PortConfiguration* config, |
411 (*flags & DISABLE_ALL_PHASES) != DISABLE_ALL_PHASES; ++i) { | 411 uint32_t* flags) { |
| 412 for (uint32_t i = 0; i < sequences_.size() && |
| 413 (*flags & DISABLE_ALL_PHASES) != DISABLE_ALL_PHASES; |
| 414 ++i) { |
412 sequences_[i]->DisableEquivalentPhases(network, config, flags); | 415 sequences_[i]->DisableEquivalentPhases(network, config, flags); |
413 } | 416 } |
414 } | 417 } |
415 | 418 |
416 void BasicPortAllocatorSession::AddAllocatedPort(Port* port, | 419 void BasicPortAllocatorSession::AddAllocatedPort(Port* port, |
417 AllocationSequence * seq, | 420 AllocationSequence * seq, |
418 bool prepare_address) { | 421 bool prepare_address) { |
419 if (!port) | 422 if (!port) |
420 return; | 423 return; |
421 | 424 |
422 LOG(LS_INFO) << "Adding allocated port for " << content_name(); | 425 LOG(LS_INFO) << "Adding allocated port for " << content_name(); |
423 port->set_content_name(content_name()); | 426 port->set_content_name(content_name()); |
424 port->set_component(component_); | 427 port->set_component(component_); |
425 port->set_generation(generation()); | 428 port->set_generation(generation()); |
426 if (allocator_->proxy().type != rtc::PROXY_NONE) | 429 if (allocator_->proxy().type != rtc::PROXY_NONE) |
427 port->set_proxy(allocator_->user_agent(), allocator_->proxy()); | 430 port->set_proxy(allocator_->user_agent(), allocator_->proxy()); |
428 port->set_send_retransmit_count_attribute((allocator_->flags() & | 431 port->set_send_retransmit_count_attribute((allocator_->flags() & |
429 PORTALLOCATOR_ENABLE_STUN_RETRANSMIT_ATTRIBUTE) != 0); | 432 PORTALLOCATOR_ENABLE_STUN_RETRANSMIT_ATTRIBUTE) != 0); |
430 | 433 |
431 // Push down the candidate_filter to individual port. | 434 // Push down the candidate_filter to individual port. |
432 uint32 candidate_filter = allocator_->candidate_filter(); | 435 uint32_t candidate_filter = allocator_->candidate_filter(); |
433 | 436 |
434 // When adapter enumeration is disabled, disable CF_HOST at port level so | 437 // When adapter enumeration is disabled, disable CF_HOST at port level so |
435 // local address is not leaked by stunport in the candidate's related address. | 438 // local address is not leaked by stunport in the candidate's related address. |
436 if (flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION) { | 439 if (flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION) { |
437 candidate_filter &= ~CF_HOST; | 440 candidate_filter &= ~CF_HOST; |
438 } | 441 } |
439 port->set_candidate_filter(candidate_filter); | 442 port->set_candidate_filter(candidate_filter); |
440 | 443 |
441 PortData data(port, seq); | 444 PortData data(port, seq); |
442 ports_.push_back(data); | 445 ports_.push_back(data); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 } | 568 } |
566 } | 569 } |
567 } | 570 } |
568 | 571 |
569 if (!candidates.empty()) { | 572 if (!candidates.empty()) { |
570 SignalCandidatesReady(this, candidates); | 573 SignalCandidatesReady(this, candidates); |
571 } | 574 } |
572 } | 575 } |
573 | 576 |
574 bool BasicPortAllocatorSession::CheckCandidateFilter(const Candidate& c) { | 577 bool BasicPortAllocatorSession::CheckCandidateFilter(const Candidate& c) { |
575 uint32 filter = allocator_->candidate_filter(); | 578 uint32_t filter = allocator_->candidate_filter(); |
576 | 579 |
577 // When binding to any address, before sending packets out, the getsockname | 580 // When binding to any address, before sending packets out, the getsockname |
578 // returns all 0s, but after sending packets, it'll be the NIC used to | 581 // returns all 0s, but after sending packets, it'll be the NIC used to |
579 // send. All 0s is not a valid ICE candidate address and should be filtered | 582 // send. All 0s is not a valid ICE candidate address and should be filtered |
580 // out. | 583 // out. |
581 if (c.address().IsAnyIP()) { | 584 if (c.address().IsAnyIP()) { |
582 return false; | 585 return false; |
583 } | 586 } |
584 | 587 |
585 if (c.type() == RELAY_PORT_TYPE) { | 588 if (c.type() == RELAY_PORT_TYPE) { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 } | 710 } |
708 } | 711 } |
709 return NULL; | 712 return NULL; |
710 } | 713 } |
711 | 714 |
712 // AllocationSequence | 715 // AllocationSequence |
713 | 716 |
714 AllocationSequence::AllocationSequence(BasicPortAllocatorSession* session, | 717 AllocationSequence::AllocationSequence(BasicPortAllocatorSession* session, |
715 rtc::Network* network, | 718 rtc::Network* network, |
716 PortConfiguration* config, | 719 PortConfiguration* config, |
717 uint32 flags) | 720 uint32_t flags) |
718 : session_(session), | 721 : session_(session), |
719 network_(network), | 722 network_(network), |
720 ip_(network->GetBestIP()), | 723 ip_(network->GetBestIP()), |
721 config_(config), | 724 config_(config), |
722 state_(kInit), | 725 state_(kInit), |
723 flags_(flags), | 726 flags_(flags), |
724 udp_socket_(), | 727 udp_socket_(), |
725 udp_port_(NULL), | 728 udp_port_(NULL), |
726 phase_(0) { | 729 phase_(0) { |
727 } | 730 } |
(...skipping 22 matching lines...) Expand all Loading... |
750 // Stop the allocation sequence if its network is gone. | 753 // Stop the allocation sequence if its network is gone. |
751 Stop(); | 754 Stop(); |
752 network_removed_ = true; | 755 network_removed_ = true; |
753 } | 756 } |
754 | 757 |
755 AllocationSequence::~AllocationSequence() { | 758 AllocationSequence::~AllocationSequence() { |
756 session_->network_thread()->Clear(this); | 759 session_->network_thread()->Clear(this); |
757 } | 760 } |
758 | 761 |
759 void AllocationSequence::DisableEquivalentPhases(rtc::Network* network, | 762 void AllocationSequence::DisableEquivalentPhases(rtc::Network* network, |
760 PortConfiguration* config, uint32* flags) { | 763 PortConfiguration* config, uint32_t* flags) { |
761 if (network_removed_) { | 764 if (network_removed_) { |
762 // If the network of this allocation sequence has ever gone away, | 765 // If the network of this allocation sequence has ever gone away, |
763 // it won't be equivalent to the new network. | 766 // it won't be equivalent to the new network. |
764 return; | 767 return; |
765 } | 768 } |
766 | 769 |
767 if (!((network == network_) && (ip_ == network->GetBestIP()))) { | 770 if (!((network == network_) && (ip_ == network->GetBestIP()))) { |
768 // Different network setup; nothing is equivalent. | 771 // Different network setup; nothing is equivalent. |
769 return; | 772 return; |
770 } | 773 } |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1187 ServerAddresses servers; | 1190 ServerAddresses servers; |
1188 for (size_t i = 0; i < relays.size(); ++i) { | 1191 for (size_t i = 0; i < relays.size(); ++i) { |
1189 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { | 1192 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { |
1190 servers.insert(relays[i].ports.front().address); | 1193 servers.insert(relays[i].ports.front().address); |
1191 } | 1194 } |
1192 } | 1195 } |
1193 return servers; | 1196 return servers; |
1194 } | 1197 } |
1195 | 1198 |
1196 } // namespace cricket | 1199 } // namespace cricket |
OLD | NEW |