Chromium Code Reviews| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 const std::string& content_name, | 131 const std::string& content_name, |
| 132 int component, | 132 int component, |
| 133 const std::string& ice_ufrag, | 133 const std::string& ice_ufrag, |
| 134 const std::string& ice_pwd) | 134 const std::string& ice_pwd) |
| 135 : PortAllocatorSession(content_name, component, | 135 : PortAllocatorSession(content_name, component, |
| 136 ice_ufrag, ice_pwd, allocator->flags()), | 136 ice_ufrag, ice_pwd, allocator->flags()), |
| 137 allocator_(allocator), network_thread_(NULL), | 137 allocator_(allocator), network_thread_(NULL), |
| 138 socket_factory_(allocator->socket_factory()), | 138 socket_factory_(allocator->socket_factory()), |
| 139 allocation_started_(false), | 139 allocation_started_(false), |
| 140 network_manager_started_(false), | 140 network_manager_started_(false), |
| 141 running_(false), | |
| 142 allocation_sequences_created_(false) { | 141 allocation_sequences_created_(false) { |
| 143 allocator_->network_manager()->SignalNetworksChanged.connect( | 142 allocator_->network_manager()->SignalNetworksChanged.connect( |
| 144 this, &BasicPortAllocatorSession::OnNetworksChanged); | 143 this, &BasicPortAllocatorSession::OnNetworksChanged); |
| 145 allocator_->network_manager()->StartUpdating(); | 144 allocator_->network_manager()->StartUpdating(); |
| 146 } | 145 } |
| 147 | 146 |
| 148 BasicPortAllocatorSession::~BasicPortAllocatorSession() { | 147 BasicPortAllocatorSession::~BasicPortAllocatorSession() { |
| 149 allocator_->network_manager()->StopUpdating(); | 148 allocator_->network_manager()->StopUpdating(); |
| 150 if (network_thread_ != NULL) | 149 if (network_thread_ != NULL) |
| 151 network_thread_->Clear(this); | 150 network_thread_->Clear(this); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 } | 190 } |
| 192 | 191 |
| 193 void BasicPortAllocatorSession::StartGettingPorts() { | 192 void BasicPortAllocatorSession::StartGettingPorts() { |
| 194 network_thread_ = rtc::Thread::Current(); | 193 network_thread_ = rtc::Thread::Current(); |
| 195 if (!socket_factory_) { | 194 if (!socket_factory_) { |
| 196 owned_socket_factory_.reset( | 195 owned_socket_factory_.reset( |
| 197 new rtc::BasicPacketSocketFactory(network_thread_)); | 196 new rtc::BasicPacketSocketFactory(network_thread_)); |
| 198 socket_factory_ = owned_socket_factory_.get(); | 197 socket_factory_ = owned_socket_factory_.get(); |
| 199 } | 198 } |
| 200 | 199 |
| 201 running_ = true; | 200 running_ = STATE_RUNNING; |
|
Taylor Brandstetter
2016/06/21 23:36:12
Should be "state_ = STATE_RUNNING"? Also can "runn
| |
| 202 network_thread_->Post(RTC_FROM_HERE, this, MSG_CONFIG_START); | 201 network_thread_->Post(RTC_FROM_HERE, this, MSG_CONFIG_START); |
| 203 } | 202 } |
| 204 | 203 |
| 205 void BasicPortAllocatorSession::StopGettingPorts() { | 204 void BasicPortAllocatorSession::StopGettingPorts() { |
| 206 ASSERT(rtc::Thread::Current() == network_thread_); | 205 ASSERT(rtc::Thread::Current() == network_thread_); |
| 207 running_ = false; | 206 state_ = STATE_STOPPED; |
| 208 network_thread_->Post(RTC_FROM_HERE, this, MSG_CONFIG_STOP); | 207 network_thread_->Post(RTC_FROM_HERE, this, MSG_CONFIG_STOP); |
| 209 ClearGettingPorts(); | 208 ClearGettingPorts(); |
| 210 } | 209 } |
| 211 | 210 |
| 212 void BasicPortAllocatorSession::ClearGettingPorts() { | 211 void BasicPortAllocatorSession::ClearGettingPorts() { |
| 212 state_ = STATE_CLEARED; | |
| 213 network_thread_->Clear(this, MSG_ALLOCATE); | 213 network_thread_->Clear(this, MSG_ALLOCATE); |
| 214 for (uint32_t i = 0; i < sequences_.size(); ++i) | 214 for (uint32_t i = 0; i < sequences_.size(); ++i) |
| 215 sequences_[i]->Stop(); | 215 sequences_[i]->Stop(); |
| 216 } | 216 } |
| 217 | 217 |
| 218 std::vector<rtc::Network*> BasicPortAllocatorSession::GetFailedNetworks() { | |
| 219 rtc::NetworkManager::NetworkList networks = GetNetworks(); | |
| 220 | |
| 221 // Whether a network has at least one connection, keyed by interface name. | |
| 222 // So if an adapter interface has both IPv4 and IPv6 networks, they will | |
| 223 // be considered as one network. | |
| 224 std::map<std::string, bool> network_has_connection; | |
| 225 for (const PortData& data : ports_) { | |
| 226 PortInterface* port = data.port(); | |
| 227 if (!port->connections().empty()) { | |
| 228 network_has_connection[port->Network()->name()] = true; | |
| 229 } | |
| 230 } | |
| 231 | |
| 232 networks.erase( | |
| 233 std::remove_if(networks.begin(), networks.end(), | |
| 234 [network_has_connection](rtc::Network* network) { | |
| 235 // If a network does not have any connection, it is | |
| 236 // considered failed. | |
| 237 return network_has_connection[network->name()]; | |
| 238 }), | |
| 239 networks.end()); | |
| 240 return networks; | |
| 241 } | |
| 242 | |
| 243 void BasicPortAllocatorSession::RegatherOnFailedNetworks() { | |
| 244 // Find the list of networks that have no connection. | |
| 245 rtc::NetworkManager::NetworkList networks = GetFailedNetworks(); | |
| 246 if (networks.empty()) { | |
| 247 return; | |
| 248 } | |
| 249 | |
| 250 // Inactivate sequences whose networks are in failed |networks|, | |
| 251 // so that they won't be considered as duplicates when the session | |
| 252 // regathers ports and candidates. | |
| 253 for (AllocationSequence* sequence : sequences_) { | |
| 254 if (!sequence->network_inactive() && | |
| 255 std::find(networks->begin(), networks->end(), sequence->network()) != | |
| 256 networks->end()) { | |
| 257 sequence->set_network_inactive(true); | |
| 258 // Close ports and signal candidate removals. | |
| 259 sequence->ClosePorts(); | |
| 260 } | |
| 261 } | |
| 262 | |
| 263 StartGettingPorts(); | |
| 264 } | |
| 265 | |
| 218 std::vector<PortInterface*> BasicPortAllocatorSession::ReadyPorts() const { | 266 std::vector<PortInterface*> BasicPortAllocatorSession::ReadyPorts() const { |
| 219 std::vector<PortInterface*> ret; | 267 std::vector<PortInterface*> ret; |
| 220 for (const PortData& port : ports_) { | 268 for (const PortData& port : ports_) { |
| 221 if (port.has_pairable_candidate() && !port.error()) { | 269 if (port.has_pairable_candidate() && !port.error()) { |
| 222 ret.push_back(port.port()); | 270 ret.push_back(port.port()); |
| 223 } | 271 } |
| 224 } | 272 } |
| 225 return ret; | 273 return ret; |
| 226 } | 274 } |
| 227 | 275 |
| 228 std::vector<Candidate> BasicPortAllocatorSession::ReadyCandidates() const { | 276 std::vector<Candidate> BasicPortAllocatorSession::ReadyCandidates() const { |
| 229 std::vector<Candidate> candidates; | 277 std::vector<Candidate> candidates; |
| 230 for (const PortData& data : ports_) { | 278 for (const PortData& data : ports_) { |
| 231 for (const Candidate& candidate : data.port()->Candidates()) { | 279 for (const Candidate& candidate : data.port()->Candidates()) { |
| 232 if (!CheckCandidateFilter(candidate)) { | 280 if (!CheckCandidateFilter(candidate)) { |
| 233 continue; | 281 continue; |
| 234 } | 282 } |
| 235 ProtocolType pvalue; | 283 ProtocolType pvalue; |
| 236 if (!StringToProto(candidate.protocol().c_str(), &pvalue) || | 284 if (!StringToProto(candidate.protocol().c_str(), &pvalue) || |
| 237 !data.sequence()->ProtocolEnabled(pvalue)) { | 285 !data.sequence()->ProtocolEnabled(pvalue)) { |
| 238 continue; | 286 continue; |
| 239 } | 287 } |
| 240 candidates.push_back(SanitizeRelatedAddress(candidate)); | 288 candidates.push_back(SanitizeRelatedAddress(candidate)); |
| 241 } | 289 } |
| 242 } | 290 } |
| 243 return candidates; | 291 return candidates; |
| 244 } | 292 } |
| 245 | 293 |
| 294 std::vector<Candidate> BasicPortAllocatorSession::ReadyCandidates( | |
| 295 PortInterface* port) const { | |
| 296 std::vector<Candidate> candidates; | |
| 297 for (const Candidate& candidate : port->Candidates()) { | |
| 298 if (!CheckCandidateFilter(candidate)) { | |
| 299 continue; | |
| 300 } | |
| 301 candidates.push_back(SanitizeRelatedAddress(candidate)); | |
| 302 } | |
| 303 return candidates; | |
| 304 } | |
| 305 | |
| 246 Candidate BasicPortAllocatorSession::SanitizeRelatedAddress( | 306 Candidate BasicPortAllocatorSession::SanitizeRelatedAddress( |
| 247 const Candidate& c) const { | 307 const Candidate& c) const { |
| 248 Candidate copy = c; | 308 Candidate copy = c; |
| 249 // If adapter enumeration is disabled or host candidates are disabled, | 309 // If adapter enumeration is disabled or host candidates are disabled, |
| 250 // clear the raddr of STUN candidates to avoid local address leakage. | 310 // clear the raddr of STUN candidates to avoid local address leakage. |
| 251 bool filter_stun_related_address = | 311 bool filter_stun_related_address = |
| 252 ((flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION) && | 312 ((flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION) && |
| 253 (flags() & PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE)) || | 313 (flags() & PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE)) || |
| 254 !(candidate_filter_ & CF_HOST); | 314 !(candidate_filter_ & CF_HOST); |
| 255 // If the candidate filter doesn't allow reflexive addresses, empty TURN raddr | 315 // If the candidate filter doesn't allow reflexive addresses, empty TURN raddr |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 384 network_thread_->Post(RTC_FROM_HERE, this, MSG_ALLOCATE); | 444 network_thread_->Post(RTC_FROM_HERE, this, MSG_ALLOCATE); |
| 385 } | 445 } |
| 386 | 446 |
| 387 void BasicPortAllocatorSession::OnAllocate() { | 447 void BasicPortAllocatorSession::OnAllocate() { |
| 388 if (network_manager_started_) | 448 if (network_manager_started_) |
| 389 DoAllocate(); | 449 DoAllocate(); |
| 390 | 450 |
| 391 allocation_started_ = true; | 451 allocation_started_ = true; |
| 392 } | 452 } |
| 393 | 453 |
| 394 void BasicPortAllocatorSession::GetNetworks( | 454 std::vector<rtc::Network*> BasicPortAllocatorSession::GetNetworks() const { |
| 395 std::vector<rtc::Network*>* networks) { | 455 std::vector<rtc::Network*> networks; |
| 396 networks->clear(); | |
| 397 rtc::NetworkManager* network_manager = allocator_->network_manager(); | 456 rtc::NetworkManager* network_manager = allocator_->network_manager(); |
| 398 ASSERT(network_manager != nullptr); | 457 ASSERT(network_manager != nullptr); |
| 399 // If the network permission state is BLOCKED, we just act as if the flag has | 458 // If the network permission state is BLOCKED, we just act as if the flag has |
| 400 // been passed in. | 459 // been passed in. |
| 401 if (network_manager->enumeration_permission() == | 460 if (network_manager->enumeration_permission() == |
| 402 rtc::NetworkManager::ENUMERATION_BLOCKED) { | 461 rtc::NetworkManager::ENUMERATION_BLOCKED) { |
| 403 set_flags(flags() | PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); | 462 set_flags(flags() | PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); |
| 404 } | 463 } |
| 405 // If the adapter enumeration is disabled, we'll just bind to any address | 464 // If the adapter enumeration is disabled, we'll just bind to any address |
| 406 // instead of specific NIC. This is to ensure the same routing for http | 465 // instead of specific NIC. This is to ensure the same routing for http |
| 407 // traffic by OS is also used here to avoid any local or public IP leakage | 466 // traffic by OS is also used here to avoid any local or public IP leakage |
| 408 // during stun process. | 467 // during stun process. |
| 409 if (flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION) { | 468 if (flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION) { |
| 410 network_manager->GetAnyAddressNetworks(networks); | 469 network_manager->GetAnyAddressNetworks(&networks); |
| 411 } else { | 470 } else { |
| 412 network_manager->GetNetworks(networks); | 471 network_manager->GetNetworks(&networks); |
| 413 } | 472 } |
| 414 networks->erase(std::remove_if(networks->begin(), networks->end(), | 473 networks->erase(std::remove_if(networks->begin(), networks->end(), |
| 415 [this](rtc::Network* network) { | 474 [this](rtc::Network* network) { |
| 416 return allocator_->network_ignore_mask() & | 475 return allocator_->network_ignore_mask() & |
| 417 network->type(); | 476 network->type(); |
| 418 }), | 477 }), |
| 419 networks->end()); | 478 networks->end()); |
| 420 | 479 |
| 421 if (flags() & PORTALLOCATOR_DISABLE_COSTLY_NETWORKS) { | 480 if (flags() & PORTALLOCATOR_DISABLE_COSTLY_NETWORKS) { |
| 422 uint16_t lowest_cost = rtc::kNetworkCostMax; | 481 uint16_t lowest_cost = rtc::kNetworkCostMax; |
| 423 for (rtc::Network* network : *networks) { | 482 for (rtc::Network* network : *networks) { |
| 424 lowest_cost = std::min<uint16_t>(lowest_cost, network->GetCost()); | 483 lowest_cost = std::min<uint16_t>(lowest_cost, network->GetCost()); |
| 425 } | 484 } |
| 426 networks->erase(std::remove_if(networks->begin(), networks->end(), | 485 networks->erase(std::remove_if(networks->begin(), networks->end(), |
| 427 [lowest_cost](rtc::Network* network) { | 486 [lowest_cost](rtc::Network* network) { |
| 428 return network->GetCost() > | 487 return network->GetCost() > |
| 429 lowest_cost + rtc::kNetworkCostLow; | 488 lowest_cost + rtc::kNetworkCostLow; |
| 430 }), | 489 }), |
| 431 networks->end()); | 490 networks->end()); |
| 432 } | 491 } |
| 492 return networks; | |
| 433 } | 493 } |
| 434 | 494 |
| 435 // For each network, see if we have a sequence that covers it already. If not, | 495 // For each network, see if we have a sequence that covers it already. If not, |
| 436 // create a new sequence to create the appropriate ports. | 496 // create a new sequence to create the appropriate ports. |
| 437 void BasicPortAllocatorSession::DoAllocate() { | 497 void BasicPortAllocatorSession::DoAllocate() { |
| 438 bool done_signal_needed = false; | 498 bool done_signal_needed = false; |
| 439 std::vector<rtc::Network*> networks; | 499 std::vector<rtc::Network*> networks = GetNetworks(); |
| 440 GetNetworks(&networks); | |
| 441 | 500 |
| 442 if (networks.empty()) { | 501 if (networks.empty()) { |
| 443 LOG(LS_WARNING) << "Machine has no networks; no ports will be allocated"; | 502 LOG(LS_WARNING) << "Machine has no networks; no ports will be allocated"; |
| 444 done_signal_needed = true; | 503 done_signal_needed = true; |
| 445 } else { | 504 } else { |
| 446 for (uint32_t i = 0; i < networks.size(); ++i) { | 505 for (uint32_t i = 0; i < networks.size(); ++i) { |
| 447 PortConfiguration* config = NULL; | 506 PortConfiguration* config = NULL; |
| 448 if (configs_.size() > 0) | 507 if (configs_.size() > 0) |
| 449 config = configs_.back(); | 508 config = configs_.back(); |
| 450 | 509 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 478 | 537 |
| 479 AllocationSequence* sequence = | 538 AllocationSequence* sequence = |
| 480 new AllocationSequence(this, networks[i], config, sequence_flags); | 539 new AllocationSequence(this, networks[i], config, sequence_flags); |
| 481 if (!sequence->Init()) { | 540 if (!sequence->Init()) { |
| 482 delete sequence; | 541 delete sequence; |
| 483 continue; | 542 continue; |
| 484 } | 543 } |
| 485 done_signal_needed = true; | 544 done_signal_needed = true; |
| 486 sequence->SignalPortAllocationComplete.connect( | 545 sequence->SignalPortAllocationComplete.connect( |
| 487 this, &BasicPortAllocatorSession::OnPortAllocationComplete); | 546 this, &BasicPortAllocatorSession::OnPortAllocationComplete); |
| 488 if (running_) | 547 // TODO(honghaiz): Move this check at the beginning of the method. I do |
| 548 // not see the point of creating a sequence without starting it. Will | |
| 549 // do this in a separate CL. | |
| 550 if (CanGetPorts()) { | |
| 489 sequence->Start(); | 551 sequence->Start(); |
| 552 } | |
| 490 sequences_.push_back(sequence); | 553 sequences_.push_back(sequence); |
| 491 } | 554 } |
| 492 } | 555 } |
| 493 if (done_signal_needed) { | 556 if (done_signal_needed) { |
| 494 network_thread_->Post(RTC_FROM_HERE, this, MSG_SEQUENCEOBJECTS_CREATED); | 557 network_thread_->Post(RTC_FROM_HERE, this, MSG_SEQUENCEOBJECTS_CREATED); |
| 495 } | 558 } |
| 496 } | 559 } |
| 497 | 560 |
| 498 void BasicPortAllocatorSession::OnNetworksChanged() { | 561 void BasicPortAllocatorSession::OnNetworksChanged() { |
| 499 std::vector<rtc::Network*> networks; | 562 std::vector<rtc::Network*> networks = GetNetworks(); |
| 500 GetNetworks(&networks); | |
| 501 for (AllocationSequence* sequence : sequences_) { | 563 for (AllocationSequence* sequence : sequences_) { |
| 502 // Remove the network from the allocation sequence if it is not in | 564 // Remove the network from the allocation sequence if it is not in |
| 503 // |networks|. | 565 // |networks|. |
| 504 if (!sequence->network_removed() && | 566 if (!sequence->network_inactive() && |
| 505 std::find(networks.begin(), networks.end(), sequence->network()) == | 567 std::find(networks.begin(), networks.end(), sequence->network()) == |
| 506 networks.end()) { | 568 networks.end()) { |
| 507 sequence->OnNetworkRemoved(); | 569 sequence->OnNetworkInactivated(); |
| 508 } | 570 } |
| 509 } | 571 } |
| 510 | 572 |
| 511 network_manager_started_ = true; | 573 network_manager_started_ = true; |
| 512 if (allocation_started_) | 574 if (allocation_started_) |
| 513 DoAllocate(); | 575 DoAllocate(); |
| 514 } | 576 } |
| 515 | 577 |
| 516 void BasicPortAllocatorSession::DisableEquivalentPhases( | 578 void BasicPortAllocatorSession::DisableEquivalentPhases( |
| 517 rtc::Network* network, | 579 rtc::Network* network, |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 537 if (allocator_->proxy().type != rtc::PROXY_NONE) | 599 if (allocator_->proxy().type != rtc::PROXY_NONE) |
| 538 port->set_proxy(allocator_->user_agent(), allocator_->proxy()); | 600 port->set_proxy(allocator_->user_agent(), allocator_->proxy()); |
| 539 port->set_send_retransmit_count_attribute( | 601 port->set_send_retransmit_count_attribute( |
| 540 (flags() & PORTALLOCATOR_ENABLE_STUN_RETRANSMIT_ATTRIBUTE) != 0); | 602 (flags() & PORTALLOCATOR_ENABLE_STUN_RETRANSMIT_ATTRIBUTE) != 0); |
| 541 | 603 |
| 542 PortData data(port, seq); | 604 PortData data(port, seq); |
| 543 ports_.push_back(data); | 605 ports_.push_back(data); |
| 544 | 606 |
| 545 port->SignalCandidateReady.connect( | 607 port->SignalCandidateReady.connect( |
| 546 this, &BasicPortAllocatorSession::OnCandidateReady); | 608 this, &BasicPortAllocatorSession::OnCandidateReady); |
| 609 port->SignalCandidatesRemoved.connect( | |
| 610 this, &BasicPortAllocatorSession::OnCandidatesRemoved); | |
| 547 port->SignalPortComplete.connect(this, | 611 port->SignalPortComplete.connect(this, |
| 548 &BasicPortAllocatorSession::OnPortComplete); | 612 &BasicPortAllocatorSession::OnPortComplete); |
| 549 port->SignalDestroyed.connect(this, | 613 port->SignalDestroyed.connect(this, |
| 550 &BasicPortAllocatorSession::OnPortDestroyed); | 614 &BasicPortAllocatorSession::OnPortDestroyed); |
| 551 port->SignalPortError.connect( | 615 port->SignalPortError.connect( |
| 552 this, &BasicPortAllocatorSession::OnPortError); | 616 this, &BasicPortAllocatorSession::OnPortError); |
| 553 LOG_J(LS_INFO, port) << "Added port to allocator"; | 617 LOG_J(LS_INFO, port) << "Added port to allocator"; |
| 554 | 618 |
| 555 if (prepare_address) | 619 if (prepare_address) |
| 556 port->PrepareAddress(); | 620 port->PrepareAddress(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 594 // usable candidate from the port, or simply because the port is bound to the | 658 // usable candidate from the port, or simply because the port is bound to the |
| 595 // any address and therefore has no host candidate. This will trigger the port | 659 // any address and therefore has no host candidate. This will trigger the port |
| 596 // to start creating candidate pairs (connections) and issue connectivity | 660 // to start creating candidate pairs (connections) and issue connectivity |
| 597 // checks. | 661 // checks. |
| 598 if (CandidatePairable(c, port)) { | 662 if (CandidatePairable(c, port)) { |
| 599 data->set_has_pairable_candidate(true); | 663 data->set_has_pairable_candidate(true); |
| 600 SignalPortReady(this, port); | 664 SignalPortReady(this, port); |
| 601 } | 665 } |
| 602 } | 666 } |
| 603 | 667 |
| 668 void BasicPortAllocatorSession::OnCandidatesRemoved( | |
| 669 Port* port, | |
| 670 const std::vector<Candidate>& candidates) { | |
| 671 ASSERT(rtc::Thread::Current() == network_thread_); | |
| 672 PortData* data = FindPort(port); | |
| 673 ASSERT(data != NULL); | |
| 674 | |
| 675 std::vector<Candidate> filtered_candidates; | |
| 676 for (Candidate c : candidates) { | |
| 677 ProtocolType pvalue; | |
| 678 bool candidate_protocol_enabled = | |
| 679 StringToProto(c.protocol().c_str(), &pvalue) && | |
| 680 data->sequence()->ProtocolEnabled(pvalue); | |
| 681 if (candidate_protocol_enabled && CheckCandidateFilter(c)) { | |
| 682 filtered_candidates.push_back(SanitizeRelatedAddress(c)); | |
| 683 } | |
| 684 } | |
| 685 if (!filtered_candidates.empty()) { | |
| 686 SignalCandidatesRemoved(this, filtered_candidates); | |
| 687 } | |
| 688 } | |
| 689 | |
| 604 void BasicPortAllocatorSession::OnPortComplete(Port* port) { | 690 void BasicPortAllocatorSession::OnPortComplete(Port* port) { |
| 605 ASSERT(rtc::Thread::Current() == network_thread_); | 691 ASSERT(rtc::Thread::Current() == network_thread_); |
| 606 PortData* data = FindPort(port); | 692 PortData* data = FindPort(port); |
| 607 ASSERT(data != NULL); | 693 ASSERT(data != NULL); |
| 608 | 694 |
| 609 // Ignore any late signals. | 695 // Ignore any late signals. |
| 610 if (data->complete() || data->error()) { | 696 if (data->complete() || data->error()) { |
| 611 return; | 697 return; |
| 612 } | 698 } |
| 613 | 699 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 786 // are next available options to setup a communication channel. | 872 // are next available options to setup a communication channel. |
| 787 } | 873 } |
| 788 return true; | 874 return true; |
| 789 } | 875 } |
| 790 | 876 |
| 791 void AllocationSequence::Clear() { | 877 void AllocationSequence::Clear() { |
| 792 udp_port_ = NULL; | 878 udp_port_ = NULL; |
| 793 turn_ports_.clear(); | 879 turn_ports_.clear(); |
| 794 } | 880 } |
| 795 | 881 |
| 796 void AllocationSequence::OnNetworkRemoved() { | 882 void AllocationSequence::OnNetworkInactivated() { |
| 797 // Stop the allocation sequence if its network is gone. | 883 // Stop the allocation sequence if its network is gone. |
| 884 network_inactive_ = true; | |
|
Taylor Brandstetter
2016/06/21 23:36:12
nit: Would be better to store this bool as "networ
| |
| 798 Stop(); | 885 Stop(); |
| 799 network_removed_ = true; | |
| 800 } | 886 } |
| 801 | 887 |
| 802 AllocationSequence::~AllocationSequence() { | 888 AllocationSequence::~AllocationSequence() { |
| 803 session_->network_thread()->Clear(this); | 889 session_->network_thread()->Clear(this); |
| 804 } | 890 } |
| 805 | 891 |
| 806 void AllocationSequence::DisableEquivalentPhases(rtc::Network* network, | 892 void AllocationSequence::DisableEquivalentPhases(rtc::Network* network, |
| 807 PortConfiguration* config, uint32_t* flags) { | 893 PortConfiguration* config, uint32_t* flags) { |
| 808 if (network_removed_) { | 894 if (network_inactive_) { |
| 809 // If the network of this allocation sequence has ever gone away, | 895 // If the network of this allocation sequence has ever become inactive, |
| 810 // it won't be equivalent to the new network. | 896 // it won't be equivalent to the new network. |
| 811 return; | 897 return; |
| 812 } | 898 } |
| 813 | 899 |
| 814 if (!((network == network_) && (ip_ == network->GetBestIP()))) { | 900 if (!((network == network_) && (ip_ == network->GetBestIP()))) { |
| 815 // Different network setup; nothing is equivalent. | 901 // Different network setup; nothing is equivalent. |
| 816 return; | 902 return; |
| 817 } | 903 } |
| 818 | 904 |
| 819 // Else turn off the stuff that we've already got covered. | 905 // Else turn off the stuff that we've already got covered. |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 844 } | 930 } |
| 845 | 931 |
| 846 void AllocationSequence::Stop() { | 932 void AllocationSequence::Stop() { |
| 847 // If the port is completed, don't set it to stopped. | 933 // If the port is completed, don't set it to stopped. |
| 848 if (state_ == kRunning) { | 934 if (state_ == kRunning) { |
| 849 state_ = kStopped; | 935 state_ = kStopped; |
| 850 session_->network_thread()->Clear(this, MSG_ALLOCATION_PHASE); | 936 session_->network_thread()->Clear(this, MSG_ALLOCATION_PHASE); |
| 851 } | 937 } |
| 852 } | 938 } |
| 853 | 939 |
| 940 void AllocationSequence::ClosePorts() { | |
| 941 if (udp_port_) { | |
| 942 udp_port_->CloseAndSignalCandidateRemovals(); | |
| 943 } | |
| 944 for (Port& port : turn_ports_) { | |
| 945 port.CloseAndSignalCandidateRemovals(); | |
| 946 } | |
| 947 } | |
| 948 | |
| 854 void AllocationSequence::OnMessage(rtc::Message* msg) { | 949 void AllocationSequence::OnMessage(rtc::Message* msg) { |
| 855 ASSERT(rtc::Thread::Current() == session_->network_thread()); | 950 ASSERT(rtc::Thread::Current() == session_->network_thread()); |
| 856 ASSERT(msg->message_id == MSG_ALLOCATION_PHASE); | 951 ASSERT(msg->message_id == MSG_ALLOCATION_PHASE); |
| 857 | 952 |
| 858 const char* const PHASE_NAMES[kNumPhases] = { | 953 const char* const PHASE_NAMES[kNumPhases] = { |
| 859 "Udp", "Relay", "Tcp", "SslTcp" | 954 "Udp", "Relay", "Tcp", "SslTcp" |
| 860 }; | 955 }; |
| 861 | 956 |
| 862 // Perform all of the phases in the current step. | 957 // Perform all of the phases in the current step. |
| 863 LOG_J(LS_INFO, network_) << "Allocation Phase=" | 958 LOG_J(LS_INFO, network_) << "Allocation Phase=" |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1235 ServerAddresses servers; | 1330 ServerAddresses servers; |
| 1236 for (size_t i = 0; i < relays.size(); ++i) { | 1331 for (size_t i = 0; i < relays.size(); ++i) { |
| 1237 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { | 1332 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { |
| 1238 servers.insert(relays[i].ports.front().address); | 1333 servers.insert(relays[i].ports.front().address); |
| 1239 } | 1334 } |
| 1240 } | 1335 } |
| 1241 return servers; | 1336 return servers; |
| 1242 } | 1337 } |
| 1243 | 1338 |
| 1244 } // namespace cricket | 1339 } // namespace cricket |
| OLD | NEW |