| 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_->Clear(this, MSG_ALLOCATE); | 195 network_thread_->Clear(this, MSG_ALLOCATE); |
| 196 for (uint32 i = 0; i < sequences_.size(); ++i) | 196 for (uint32_t i = 0; i < sequences_.size(); ++i) |
| 197 sequences_[i]->Stop(); | 197 sequences_[i]->Stop(); |
| 198 network_thread_->Post(this, MSG_CONFIG_STOP); | 198 network_thread_->Post(this, MSG_CONFIG_STOP); |
| 199 } | 199 } |
| 200 | 200 |
| 201 void BasicPortAllocatorSession::OnMessage(rtc::Message *message) { | 201 void BasicPortAllocatorSession::OnMessage(rtc::Message *message) { |
| 202 switch (message->message_id) { | 202 switch (message->message_id) { |
| 203 case MSG_CONFIG_START: | 203 case MSG_CONFIG_START: |
| 204 ASSERT(rtc::Thread::Current() == network_thread_); | 204 ASSERT(rtc::Thread::Current() == network_thread_); |
| 205 GetPortConfigurations(); | 205 GetPortConfigurations(); |
| 206 break; | 206 break; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 // during stun process. | 317 // during stun process. |
| 318 if (flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION) { | 318 if (flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION) { |
| 319 allocator_->network_manager()->GetAnyAddressNetworks(&networks); | 319 allocator_->network_manager()->GetAnyAddressNetworks(&networks); |
| 320 } else { | 320 } else { |
| 321 allocator_->network_manager()->GetNetworks(&networks); | 321 allocator_->network_manager()->GetNetworks(&networks); |
| 322 } | 322 } |
| 323 if (networks.empty()) { | 323 if (networks.empty()) { |
| 324 LOG(LS_WARNING) << "Machine has no networks; no ports will be allocated"; | 324 LOG(LS_WARNING) << "Machine has no networks; no ports will be allocated"; |
| 325 done_signal_needed = true; | 325 done_signal_needed = true; |
| 326 } else { | 326 } else { |
| 327 for (uint32 i = 0; i < networks.size(); ++i) { | 327 for (uint32_t i = 0; i < networks.size(); ++i) { |
| 328 PortConfiguration* config = NULL; | 328 PortConfiguration* config = NULL; |
| 329 if (configs_.size() > 0) | 329 if (configs_.size() > 0) |
| 330 config = configs_.back(); | 330 config = configs_.back(); |
| 331 | 331 |
| 332 uint32 sequence_flags = flags(); | 332 uint32_t sequence_flags = flags(); |
| 333 if ((sequence_flags & DISABLE_ALL_PHASES) == DISABLE_ALL_PHASES) { | 333 if ((sequence_flags & DISABLE_ALL_PHASES) == DISABLE_ALL_PHASES) { |
| 334 // If all the ports are disabled we should just fire the allocation | 334 // If all the ports are disabled we should just fire the allocation |
| 335 // done event and return. | 335 // done event and return. |
| 336 done_signal_needed = true; | 336 done_signal_needed = true; |
| 337 break; | 337 break; |
| 338 } | 338 } |
| 339 | 339 |
| 340 if (!config || config->relays.empty()) { | 340 if (!config || config->relays.empty()) { |
| 341 // No relay ports specified in this config. | 341 // No relay ports specified in this config. |
| 342 sequence_flags |= PORTALLOCATOR_DISABLE_RELAY; | 342 sequence_flags |= PORTALLOCATOR_DISABLE_RELAY; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 } | 376 } |
| 377 } | 377 } |
| 378 | 378 |
| 379 void BasicPortAllocatorSession::OnNetworksChanged() { | 379 void BasicPortAllocatorSession::OnNetworksChanged() { |
| 380 network_manager_started_ = true; | 380 network_manager_started_ = true; |
| 381 if (allocation_started_) | 381 if (allocation_started_) |
| 382 DoAllocate(); | 382 DoAllocate(); |
| 383 } | 383 } |
| 384 | 384 |
| 385 void BasicPortAllocatorSession::DisableEquivalentPhases( | 385 void BasicPortAllocatorSession::DisableEquivalentPhases( |
| 386 rtc::Network* network, PortConfiguration* config, uint32* flags) { | 386 rtc::Network* network, |
| 387 for (uint32 i = 0; i < sequences_.size() && | 387 PortConfiguration* config, |
| 388 (*flags & DISABLE_ALL_PHASES) != DISABLE_ALL_PHASES; ++i) { | 388 uint32_t* flags) { |
| 389 for (uint32_t i = 0; i < sequences_.size() && |
| 390 (*flags & DISABLE_ALL_PHASES) != DISABLE_ALL_PHASES; |
| 391 ++i) { |
| 389 sequences_[i]->DisableEquivalentPhases(network, config, flags); | 392 sequences_[i]->DisableEquivalentPhases(network, config, flags); |
| 390 } | 393 } |
| 391 } | 394 } |
| 392 | 395 |
| 393 void BasicPortAllocatorSession::AddAllocatedPort(Port* port, | 396 void BasicPortAllocatorSession::AddAllocatedPort(Port* port, |
| 394 AllocationSequence * seq, | 397 AllocationSequence * seq, |
| 395 bool prepare_address) { | 398 bool prepare_address) { |
| 396 if (!port) | 399 if (!port) |
| 397 return; | 400 return; |
| 398 | 401 |
| 399 LOG(LS_INFO) << "Adding allocated port for " << content_name(); | 402 LOG(LS_INFO) << "Adding allocated port for " << content_name(); |
| 400 port->set_content_name(content_name()); | 403 port->set_content_name(content_name()); |
| 401 port->set_component(component_); | 404 port->set_component(component_); |
| 402 port->set_generation(generation()); | 405 port->set_generation(generation()); |
| 403 if (allocator_->proxy().type != rtc::PROXY_NONE) | 406 if (allocator_->proxy().type != rtc::PROXY_NONE) |
| 404 port->set_proxy(allocator_->user_agent(), allocator_->proxy()); | 407 port->set_proxy(allocator_->user_agent(), allocator_->proxy()); |
| 405 port->set_send_retransmit_count_attribute((allocator_->flags() & | 408 port->set_send_retransmit_count_attribute((allocator_->flags() & |
| 406 PORTALLOCATOR_ENABLE_STUN_RETRANSMIT_ATTRIBUTE) != 0); | 409 PORTALLOCATOR_ENABLE_STUN_RETRANSMIT_ATTRIBUTE) != 0); |
| 407 | 410 |
| 408 // Push down the candidate_filter to individual port. | 411 // Push down the candidate_filter to individual port. |
| 409 uint32 candidate_filter = allocator_->candidate_filter(); | 412 uint32_t candidate_filter = allocator_->candidate_filter(); |
| 410 | 413 |
| 411 // When adapter enumeration is disabled, disable CF_HOST at port level so | 414 // When adapter enumeration is disabled, disable CF_HOST at port level so |
| 412 // local address is not leaked by stunport in the candidate's related address. | 415 // local address is not leaked by stunport in the candidate's related address. |
| 413 if (flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION) { | 416 if (flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION) { |
| 414 candidate_filter &= ~CF_HOST; | 417 candidate_filter &= ~CF_HOST; |
| 415 } | 418 } |
| 416 port->set_candidate_filter(candidate_filter); | 419 port->set_candidate_filter(candidate_filter); |
| 417 | 420 |
| 418 PortData data(port, seq); | 421 PortData data(port, seq); |
| 419 ports_.push_back(data); | 422 ports_.push_back(data); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 } | 533 } |
| 531 } | 534 } |
| 532 } | 535 } |
| 533 | 536 |
| 534 if (!candidates.empty()) { | 537 if (!candidates.empty()) { |
| 535 SignalCandidatesReady(this, candidates); | 538 SignalCandidatesReady(this, candidates); |
| 536 } | 539 } |
| 537 } | 540 } |
| 538 | 541 |
| 539 bool BasicPortAllocatorSession::CheckCandidateFilter(const Candidate& c) { | 542 bool BasicPortAllocatorSession::CheckCandidateFilter(const Candidate& c) { |
| 540 uint32 filter = allocator_->candidate_filter(); | 543 uint32_t filter = allocator_->candidate_filter(); |
| 541 | 544 |
| 542 // When binding to any address, before sending packets out, the getsockname | 545 // When binding to any address, before sending packets out, the getsockname |
| 543 // returns all 0s, but after sending packets, it'll be the NIC used to | 546 // returns all 0s, but after sending packets, it'll be the NIC used to |
| 544 // send. All 0s is not a valid ICE candidate address and should be filtered | 547 // send. All 0s is not a valid ICE candidate address and should be filtered |
| 545 // out. | 548 // out. |
| 546 if (c.address().IsAnyIP()) { | 549 if (c.address().IsAnyIP()) { |
| 547 return false; | 550 return false; |
| 548 } | 551 } |
| 549 | 552 |
| 550 if (c.type() == RELAY_PORT_TYPE) { | 553 if (c.type() == RELAY_PORT_TYPE) { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 } | 675 } |
| 673 } | 676 } |
| 674 return NULL; | 677 return NULL; |
| 675 } | 678 } |
| 676 | 679 |
| 677 // AllocationSequence | 680 // AllocationSequence |
| 678 | 681 |
| 679 AllocationSequence::AllocationSequence(BasicPortAllocatorSession* session, | 682 AllocationSequence::AllocationSequence(BasicPortAllocatorSession* session, |
| 680 rtc::Network* network, | 683 rtc::Network* network, |
| 681 PortConfiguration* config, | 684 PortConfiguration* config, |
| 682 uint32 flags) | 685 uint32_t flags) |
| 683 : session_(session), | 686 : session_(session), |
| 684 network_(network), | 687 network_(network), |
| 685 ip_(network->GetBestIP()), | 688 ip_(network->GetBestIP()), |
| 686 config_(config), | 689 config_(config), |
| 687 state_(kInit), | 690 state_(kInit), |
| 688 flags_(flags), | 691 flags_(flags), |
| 689 udp_socket_(), | 692 udp_socket_(), |
| 690 udp_port_(NULL), | 693 udp_port_(NULL), |
| 691 phase_(0) { | 694 phase_(0) { |
| 692 } | 695 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 709 void AllocationSequence::Clear() { | 712 void AllocationSequence::Clear() { |
| 710 udp_port_ = NULL; | 713 udp_port_ = NULL; |
| 711 turn_ports_.clear(); | 714 turn_ports_.clear(); |
| 712 } | 715 } |
| 713 | 716 |
| 714 AllocationSequence::~AllocationSequence() { | 717 AllocationSequence::~AllocationSequence() { |
| 715 session_->network_thread()->Clear(this); | 718 session_->network_thread()->Clear(this); |
| 716 } | 719 } |
| 717 | 720 |
| 718 void AllocationSequence::DisableEquivalentPhases(rtc::Network* network, | 721 void AllocationSequence::DisableEquivalentPhases(rtc::Network* network, |
| 719 PortConfiguration* config, uint32* flags) { | 722 PortConfiguration* config, |
| 723 uint32_t* flags) { |
| 720 if (!((network == network_) && (ip_ == network->GetBestIP()))) { | 724 if (!((network == network_) && (ip_ == network->GetBestIP()))) { |
| 721 // Different network setup; nothing is equivalent. | 725 // Different network setup; nothing is equivalent. |
| 722 return; | 726 return; |
| 723 } | 727 } |
| 724 | 728 |
| 725 // Else turn off the stuff that we've already got covered. | 729 // Else turn off the stuff that we've already got covered. |
| 726 | 730 |
| 727 // Every config implicitly specifies local, so turn that off right away. | 731 // Every config implicitly specifies local, so turn that off right away. |
| 728 *flags |= PORTALLOCATOR_DISABLE_UDP; | 732 *flags |= PORTALLOCATOR_DISABLE_UDP; |
| 729 *flags |= PORTALLOCATOR_DISABLE_TCP; | 733 *flags |= PORTALLOCATOR_DISABLE_TCP; |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1140 ServerAddresses servers; | 1144 ServerAddresses servers; |
| 1141 for (size_t i = 0; i < relays.size(); ++i) { | 1145 for (size_t i = 0; i < relays.size(); ++i) { |
| 1142 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { | 1146 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { |
| 1143 servers.insert(relays[i].ports.front().address); | 1147 servers.insert(relays[i].ports.front().address); |
| 1144 } | 1148 } |
| 1145 } | 1149 } |
| 1146 return servers; | 1150 return servers; |
| 1147 } | 1151 } |
| 1148 | 1152 |
| 1149 } // namespace cricket | 1153 } // namespace cricket |
| OLD | NEW |