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 29 matching lines...) Expand all Loading... | |
| 40 MSG_CONFIG_STOP, | 40 MSG_CONFIG_STOP, |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 const int PHASE_UDP = 0; | 43 const int PHASE_UDP = 0; |
| 44 const int PHASE_RELAY = 1; | 44 const int PHASE_RELAY = 1; |
| 45 const int PHASE_TCP = 2; | 45 const int PHASE_TCP = 2; |
| 46 const int PHASE_SSLTCP = 3; | 46 const int PHASE_SSLTCP = 3; |
| 47 | 47 |
| 48 const int kNumPhases = 4; | 48 const int kNumPhases = 4; |
| 49 | 49 |
| 50 enum class AddressFamily { UNSPEC, IPV4, IPV6 }; | |
| 51 | |
| 52 AddressFamily ToAddressFamily(int ip_family) { | |
| 53 switch (ip_family) { | |
| 54 case AF_UNSPEC: | |
| 55 return AddressFamily::UNSPEC; | |
| 56 case AF_INET: | |
| 57 return AddressFamily::IPV4; | |
| 58 case AF_INET6: | |
| 59 return AddressFamily::IPV6; | |
| 60 default: | |
| 61 RTC_DCHECK(false); | |
| 62 return AddressFamily::UNSPEC; | |
| 63 } | |
| 64 } | |
|
pthatcher1
2016/06/27 20:35:55
Is this just for sorting? If so, instead of makin
honghaiz3
2016/06/28 01:49:25
You are right. Make it return an integer.
| |
| 65 | |
| 66 // Returns positive if a is better, negative if b is better, and 0 otherwise. | |
| 67 int ComparePort(const cricket::Port* a, const cricket::Port* b) { | |
| 68 static constexpr int a_is_better = 1; | |
| 69 static constexpr int b_is_better = -1; | |
| 70 // Protocol type is defined as UDP = 0, TCP = 1, SSLTCP = 2. | |
| 71 if (a->GetProtocol() < b->GetProtocol()) { | |
| 72 return a_is_better; | |
| 73 } | |
| 74 if (a->GetProtocol() > b->GetProtocol()) { | |
| 75 return b_is_better; | |
| 76 } | |
| 77 | |
| 78 AddressFamily a_family = ToAddressFamily(a->Network()->GetBestIP().family()); | |
| 79 AddressFamily b_family = ToAddressFamily(b->Network()->GetBestIP().family()); | |
| 80 if (a_family > b_family) { | |
| 81 return a_is_better; | |
| 82 } | |
| 83 if (a_family < b_family) { | |
| 84 return b_is_better; | |
| 85 } | |
| 86 return 0; | |
| 87 } | |
| 88 | |
| 50 } // namespace | 89 } // namespace |
| 51 | 90 |
| 52 namespace cricket { | 91 namespace cricket { |
| 53 const uint32_t DISABLE_ALL_PHASES = | 92 const uint32_t DISABLE_ALL_PHASES = |
| 54 PORTALLOCATOR_DISABLE_UDP | PORTALLOCATOR_DISABLE_TCP | | 93 PORTALLOCATOR_DISABLE_UDP | PORTALLOCATOR_DISABLE_TCP | |
| 55 PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY; | 94 PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY; |
| 56 | 95 |
| 57 // BasicPortAllocator | 96 // BasicPortAllocator |
| 58 BasicPortAllocator::BasicPortAllocator(rtc::NetworkManager* network_manager, | 97 BasicPortAllocator::BasicPortAllocator(rtc::NetworkManager* network_manager, |
| 59 rtc::PacketSocketFactory* socket_factory) | 98 rtc::PacketSocketFactory* socket_factory) |
| 60 : network_manager_(network_manager), socket_factory_(socket_factory) { | 99 : network_manager_(network_manager), socket_factory_(socket_factory) { |
| 61 ASSERT(network_manager_ != nullptr); | 100 ASSERT(network_manager_ != nullptr); |
| 62 ASSERT(socket_factory_ != nullptr); | 101 ASSERT(socket_factory_ != nullptr); |
| 63 Construct(); | 102 Construct(); |
| 64 } | 103 } |
| 65 | 104 |
| 66 BasicPortAllocator::BasicPortAllocator(rtc::NetworkManager* network_manager) | 105 BasicPortAllocator::BasicPortAllocator(rtc::NetworkManager* network_manager) |
| 67 : network_manager_(network_manager), socket_factory_(nullptr) { | 106 : network_manager_(network_manager), socket_factory_(nullptr) { |
| 68 ASSERT(network_manager_ != nullptr); | 107 ASSERT(network_manager_ != nullptr); |
| 69 Construct(); | 108 Construct(); |
| 70 } | 109 } |
| 71 | 110 |
| 72 BasicPortAllocator::BasicPortAllocator(rtc::NetworkManager* network_manager, | 111 BasicPortAllocator::BasicPortAllocator(rtc::NetworkManager* network_manager, |
| 73 rtc::PacketSocketFactory* socket_factory, | 112 rtc::PacketSocketFactory* socket_factory, |
| 74 const ServerAddresses& stun_servers) | 113 const ServerAddresses& stun_servers) |
| 75 : network_manager_(network_manager), socket_factory_(socket_factory) { | 114 : network_manager_(network_manager), socket_factory_(socket_factory) { |
| 76 ASSERT(socket_factory_ != NULL); | 115 ASSERT(socket_factory_ != NULL); |
| 77 SetConfiguration(stun_servers, std::vector<RelayServerConfig>(), 0); | 116 SetConfiguration(stun_servers, std::vector<RelayServerConfig>(), 0, false); |
| 78 Construct(); | 117 Construct(); |
| 79 } | 118 } |
| 80 | 119 |
| 81 BasicPortAllocator::BasicPortAllocator( | 120 BasicPortAllocator::BasicPortAllocator( |
| 82 rtc::NetworkManager* network_manager, | 121 rtc::NetworkManager* network_manager, |
| 83 const ServerAddresses& stun_servers, | 122 const ServerAddresses& stun_servers, |
| 84 const rtc::SocketAddress& relay_address_udp, | 123 const rtc::SocketAddress& relay_address_udp, |
| 85 const rtc::SocketAddress& relay_address_tcp, | 124 const rtc::SocketAddress& relay_address_tcp, |
| 86 const rtc::SocketAddress& relay_address_ssl) | 125 const rtc::SocketAddress& relay_address_ssl) |
| 87 : network_manager_(network_manager), socket_factory_(NULL) { | 126 : network_manager_(network_manager), socket_factory_(NULL) { |
| 88 std::vector<RelayServerConfig> turn_servers; | 127 std::vector<RelayServerConfig> turn_servers; |
| 89 RelayServerConfig config(RELAY_GTURN); | 128 RelayServerConfig config(RELAY_GTURN); |
| 90 if (!relay_address_udp.IsNil()) { | 129 if (!relay_address_udp.IsNil()) { |
| 91 config.ports.push_back(ProtocolAddress(relay_address_udp, PROTO_UDP)); | 130 config.ports.push_back(ProtocolAddress(relay_address_udp, PROTO_UDP)); |
| 92 } | 131 } |
| 93 if (!relay_address_tcp.IsNil()) { | 132 if (!relay_address_tcp.IsNil()) { |
| 94 config.ports.push_back(ProtocolAddress(relay_address_tcp, PROTO_TCP)); | 133 config.ports.push_back(ProtocolAddress(relay_address_tcp, PROTO_TCP)); |
| 95 } | 134 } |
| 96 if (!relay_address_ssl.IsNil()) { | 135 if (!relay_address_ssl.IsNil()) { |
| 97 config.ports.push_back(ProtocolAddress(relay_address_ssl, PROTO_SSLTCP)); | 136 config.ports.push_back(ProtocolAddress(relay_address_ssl, PROTO_SSLTCP)); |
| 98 } | 137 } |
| 99 | 138 |
| 100 if (!config.ports.empty()) { | 139 if (!config.ports.empty()) { |
| 101 turn_servers.push_back(config); | 140 turn_servers.push_back(config); |
| 102 } | 141 } |
| 103 | 142 |
| 104 SetConfiguration(stun_servers, turn_servers, 0); | 143 SetConfiguration(stun_servers, turn_servers, 0, false); |
| 105 Construct(); | 144 Construct(); |
| 106 } | 145 } |
| 107 | 146 |
| 108 void BasicPortAllocator::Construct() { | 147 void BasicPortAllocator::Construct() { |
| 109 allow_tcp_listen_ = true; | 148 allow_tcp_listen_ = true; |
| 110 } | 149 } |
| 111 | 150 |
| 112 BasicPortAllocator::~BasicPortAllocator() { | 151 BasicPortAllocator::~BasicPortAllocator() { |
| 113 } | 152 } |
| 114 | 153 |
| 115 PortAllocatorSession* BasicPortAllocator::CreateSessionInternal( | 154 PortAllocatorSession* BasicPortAllocator::CreateSessionInternal( |
| 116 const std::string& content_name, int component, | 155 const std::string& content_name, int component, |
| 117 const std::string& ice_ufrag, const std::string& ice_pwd) { | 156 const std::string& ice_ufrag, const std::string& ice_pwd) { |
| 118 return new BasicPortAllocatorSession( | 157 return new BasicPortAllocatorSession( |
| 119 this, content_name, component, ice_ufrag, ice_pwd); | 158 this, content_name, component, ice_ufrag, ice_pwd); |
| 120 } | 159 } |
| 121 | 160 |
| 122 void BasicPortAllocator::AddTurnServer(const RelayServerConfig& turn_server) { | 161 void BasicPortAllocator::AddTurnServer(const RelayServerConfig& turn_server) { |
| 123 std::vector<RelayServerConfig> new_turn_servers = turn_servers(); | 162 std::vector<RelayServerConfig> new_turn_servers = turn_servers(); |
| 124 new_turn_servers.push_back(turn_server); | 163 new_turn_servers.push_back(turn_server); |
| 125 SetConfiguration(stun_servers(), new_turn_servers, candidate_pool_size()); | 164 SetConfiguration(stun_servers(), new_turn_servers, candidate_pool_size(), |
| 165 disable_low_priority_turn_ports()); | |
| 126 } | 166 } |
| 127 | 167 |
| 128 // BasicPortAllocatorSession | 168 // BasicPortAllocatorSession |
| 129 BasicPortAllocatorSession::BasicPortAllocatorSession( | 169 BasicPortAllocatorSession::BasicPortAllocatorSession( |
| 130 BasicPortAllocator *allocator, | 170 BasicPortAllocator *allocator, |
| 131 const std::string& content_name, | 171 const std::string& content_name, |
| 132 int component, | 172 int component, |
| 133 const std::string& ice_ufrag, | 173 const std::string& ice_ufrag, |
| 134 const std::string& ice_pwd) | 174 const std::string& ice_pwd) |
| 135 : PortAllocatorSession(content_name, component, | 175 : PortAllocatorSession(content_name, component, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 } | 250 } |
| 211 | 251 |
| 212 void BasicPortAllocatorSession::ClearGettingPorts() { | 252 void BasicPortAllocatorSession::ClearGettingPorts() { |
| 213 network_thread_->Clear(this, MSG_ALLOCATE); | 253 network_thread_->Clear(this, MSG_ALLOCATE); |
| 214 for (uint32_t i = 0; i < sequences_.size(); ++i) | 254 for (uint32_t i = 0; i < sequences_.size(); ++i) |
| 215 sequences_[i]->Stop(); | 255 sequences_[i]->Stop(); |
| 216 } | 256 } |
| 217 | 257 |
| 218 std::vector<PortInterface*> BasicPortAllocatorSession::ReadyPorts() const { | 258 std::vector<PortInterface*> BasicPortAllocatorSession::ReadyPorts() const { |
| 219 std::vector<PortInterface*> ret; | 259 std::vector<PortInterface*> ret; |
| 260 // Add all non-TURN ports. | |
| 220 for (const PortData& port : ports_) { | 261 for (const PortData& port : ports_) { |
| 221 if (port.has_pairable_candidate() && !port.error()) { | 262 if (IsPortInUse(port.port()) && port.has_pairable_candidate() && |
| 263 !port.error()) { | |
| 222 ret.push_back(port.port()); | 264 ret.push_back(port.port()); |
| 223 } | 265 } |
| 224 } | 266 } |
| 225 return ret; | 267 return ret; |
| 226 } | 268 } |
| 227 | 269 |
| 228 std::vector<Candidate> BasicPortAllocatorSession::ReadyCandidates() const { | 270 std::vector<Candidate> BasicPortAllocatorSession::ReadyCandidates() const { |
| 229 std::vector<Candidate> candidates; | 271 std::vector<Candidate> candidates; |
| 230 for (const PortData& data : ports_) { | 272 for (const PortData& data : ports_) { |
| 273 if (!IsPortInUse(data.port())) { | |
| 274 continue; | |
| 275 } | |
| 276 | |
| 231 for (const Candidate& candidate : data.port()->Candidates()) { | 277 for (const Candidate& candidate : data.port()->Candidates()) { |
| 232 if (!CheckCandidateFilter(candidate)) { | 278 if (!CheckCandidateFilter(candidate)) { |
| 233 continue; | 279 continue; |
| 234 } | 280 } |
| 235 ProtocolType pvalue; | 281 ProtocolType pvalue; |
| 236 if (!StringToProto(candidate.protocol().c_str(), &pvalue) || | 282 if (!StringToProto(candidate.protocol().c_str(), &pvalue) || |
| 237 !data.sequence()->ProtocolEnabled(pvalue)) { | 283 !data.sequence()->ProtocolEnabled(pvalue)) { |
| 238 continue; | 284 continue; |
| 239 } | 285 } |
| 240 candidates.push_back(SanitizeRelatedAddress(candidate)); | 286 candidates.push_back(SanitizeRelatedAddress(candidate)); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 431 networks->end()); | 477 networks->end()); |
| 432 } | 478 } |
| 433 } | 479 } |
| 434 | 480 |
| 435 // For each network, see if we have a sequence that covers it already. If not, | 481 // 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. | 482 // create a new sequence to create the appropriate ports. |
| 437 void BasicPortAllocatorSession::DoAllocate() { | 483 void BasicPortAllocatorSession::DoAllocate() { |
| 438 bool done_signal_needed = false; | 484 bool done_signal_needed = false; |
| 439 std::vector<rtc::Network*> networks; | 485 std::vector<rtc::Network*> networks; |
| 440 GetNetworks(&networks); | 486 GetNetworks(&networks); |
| 487 turn_ports_in_use_by_network_names_.clear(); | |
| 441 | 488 |
| 442 if (networks.empty()) { | 489 if (networks.empty()) { |
| 443 LOG(LS_WARNING) << "Machine has no networks; no ports will be allocated"; | 490 LOG(LS_WARNING) << "Machine has no networks; no ports will be allocated"; |
| 444 done_signal_needed = true; | 491 done_signal_needed = true; |
| 445 } else { | 492 } else { |
| 493 PortConfiguration* config = configs_.empty() ? nullptr : configs_.back(); | |
| 446 for (uint32_t i = 0; i < networks.size(); ++i) { | 494 for (uint32_t i = 0; i < networks.size(); ++i) { |
| 447 PortConfiguration* config = NULL; | |
| 448 if (configs_.size() > 0) | |
| 449 config = configs_.back(); | |
| 450 | |
| 451 uint32_t sequence_flags = flags(); | 495 uint32_t sequence_flags = flags(); |
| 452 if ((sequence_flags & DISABLE_ALL_PHASES) == DISABLE_ALL_PHASES) { | 496 if ((sequence_flags & DISABLE_ALL_PHASES) == DISABLE_ALL_PHASES) { |
| 453 // If all the ports are disabled we should just fire the allocation | 497 // If all the ports are disabled we should just fire the allocation |
| 454 // done event and return. | 498 // done event and return. |
| 455 done_signal_needed = true; | 499 done_signal_needed = true; |
| 456 break; | 500 break; |
| 457 } | 501 } |
| 458 | 502 |
| 459 if (!config || config->relays.empty()) { | 503 if (!config || config->relays.empty()) { |
| 460 // No relay ports specified in this config. | 504 // No relay ports specified in this config. |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 566 Port* port, const Candidate& c) { | 610 Port* port, const Candidate& c) { |
| 567 ASSERT(rtc::Thread::Current() == network_thread_); | 611 ASSERT(rtc::Thread::Current() == network_thread_); |
| 568 PortData* data = FindPort(port); | 612 PortData* data = FindPort(port); |
| 569 ASSERT(data != NULL); | 613 ASSERT(data != NULL); |
| 570 // Discarding any candidate signal if port allocation status is | 614 // Discarding any candidate signal if port allocation status is |
| 571 // already in completed state. | 615 // already in completed state. |
| 572 if (data->complete() || data->error()) { | 616 if (data->complete() || data->error()) { |
| 573 return; | 617 return; |
| 574 } | 618 } |
| 575 | 619 |
| 620 // Mark that the port has a pairable candidate, either because we have a | |
| 621 // usable candidate from the port, or simply because the port is bound to the | |
| 622 // any address and therefore has no host candidate. This will trigger the port | |
| 623 // to start creating candidate pairs (connections) and issue connectivity | |
| 624 // checks. If port has already been marked as having a pairable candidate, | |
| 625 // do nothing here. | |
| 626 // Note: Need to do MaybeSignalCandidateReady after this because we will | |
| 627 // check whether the candidate is generated by the port in use. | |
| 628 if (!data->has_pairable_candidate() && CandidatePairable(c, port)) { | |
| 629 data->set_has_pairable_candidate(true); | |
| 630 MaybeSignalPortReady(port); | |
|
pthatcher1
2016/06/27 20:35:55
If this is only called once, can we just inline it
honghaiz3
2016/06/28 01:49:25
A separate method will make it more readable here.
| |
| 631 } | |
| 632 | |
| 576 ProtocolType pvalue; | 633 ProtocolType pvalue; |
| 577 bool candidate_protocol_enabled = | 634 bool candidate_protocol_enabled = |
| 578 StringToProto(c.protocol().c_str(), &pvalue) && | 635 StringToProto(c.protocol().c_str(), &pvalue) && |
| 579 data->sequence()->ProtocolEnabled(pvalue); | 636 data->sequence()->ProtocolEnabled(pvalue); |
| 580 | 637 |
| 581 if (CheckCandidateFilter(c) && candidate_protocol_enabled) { | 638 if (CheckCandidateFilter(c) && candidate_protocol_enabled) { |
| 582 std::vector<Candidate> candidates; | 639 std::vector<Candidate> candidates; |
| 583 candidates.push_back(SanitizeRelatedAddress(c)); | 640 candidates.push_back(SanitizeRelatedAddress(c)); |
| 641 MaybeSignalCandidatesReady(port, candidates); | |
|
pthatcher1
2016/06/27 20:35:54
Since this is only called once, can you inline it?
honghaiz3
2016/06/28 01:49:25
Done.
| |
| 642 } | |
| 643 } | |
| 644 | |
| 645 void BasicPortAllocatorSession::MaybeSignalPortReady(Port* port) { | |
| 646 if (!allocator_->disable_low_priority_turn_ports() || | |
| 647 port->Type() != RELAY_PORT_TYPE) { | |
| 648 SignalPortReady(this, port); | |
| 649 return; | |
| 650 } | |
| 651 std::vector<Port*>& turn_ports = | |
| 652 turn_ports_in_use_by_network_names_[port->Network()->name()]; | |
|
pthatcher1
2016/06/27 20:35:55
Shouldn't we do a find() just in case it's not in
honghaiz3
2016/06/28 01:49:25
If it is not in the map, we create a new vector an
| |
| 653 | |
| 654 bool use_port = true; | |
| 655 auto iter = turn_ports.begin(); | |
| 656 while (iter != turn_ports.end()) { | |
| 657 int cmp = ComparePort(port, *iter); | |
| 658 if (cmp > 0) { | |
| 659 // The new port has higher precedence. Deprecate the existing port. | |
| 660 SignalPortDeprecated(this, *iter); | |
| 661 iter = turn_ports.erase(iter); | |
| 662 // TODO(honghaiz): Maybe also remove the candidates in the port. | |
| 663 } else { | |
| 664 ++iter; | |
| 665 if (cmp < 0) { | |
| 666 // If this new port has a lower precedence than any existing port, do | |
| 667 // not use it. | |
| 668 use_port = false; | |
| 669 } | |
| 670 } | |
| 671 } | |
|
pthatcher1
2016/06/27 20:35:54
Correct me if I'm wrong, but it looks like turn_po
honghaiz3
2016/06/28 01:49:25
You are right, although we have removed the map no
| |
| 672 if (use_port) { | |
|
pthatcher1
2016/06/27 20:35:55
Actually, if we just store all ports in ports_ and
honghaiz3
2016/06/28 01:49:25
Done. Did not use std::max as it is not really muc
| |
| 673 turn_ports.push_back(port); | |
| 674 SignalPortReady(this, port); | |
|
pthatcher1
2016/06/27 20:35:54
I think we need a better pair of names than Signal
honghaiz3
2016/06/28 01:49:25
SignalPortReady is used elsewhere by downstream co
| |
| 675 } | |
| 676 } | |
| 677 | |
| 678 void BasicPortAllocatorSession::MaybeSignalCandidatesReady( | |
| 679 Port* port, | |
| 680 const std::vector<Candidate>& candidates) { | |
| 681 if (IsPortInUse(port)) { | |
| 584 SignalCandidatesReady(this, candidates); | 682 SignalCandidatesReady(this, candidates); |
| 585 } | 683 } |
| 684 } | |
| 586 | 685 |
| 587 // Port has already been marked as having a pairable candidate. | 686 bool BasicPortAllocatorSession::IsPortInUse(Port* port) const { |
| 588 // Nothing to do here. | 687 // If the port is not disabling low priority ports, every port is in use. |
| 589 if (data->has_pairable_candidate()) { | 688 if (!allocator_->disable_low_priority_turn_ports()) { |
| 590 return; | 689 return true; |
| 591 } | 690 } |
| 592 | 691 // If it is not a turn port, it is in use. |
| 593 // Mark that the port has a pairable candidate, either because we have a | 692 if (port->Type() != RELAY_PORT_TYPE) { |
| 594 // usable candidate from the port, or simply because the port is bound to the | 693 return true; |
| 595 // any address and therefore has no host candidate. This will trigger the port | |
| 596 // to start creating candidate pairs (connections) and issue connectivity | |
| 597 // checks. | |
| 598 if (CandidatePairable(c, port)) { | |
| 599 data->set_has_pairable_candidate(true); | |
| 600 SignalPortReady(this, port); | |
| 601 } | 694 } |
| 695 // For TURN port, if it can be found in |turn_ports_in_use_by_network_name_|, | |
| 696 // it is in use. | |
| 697 const auto iter = | |
| 698 turn_ports_in_use_by_network_names_.find(port->Network()->name()); | |
| 699 if (iter == turn_ports_in_use_by_network_names_.end()) { | |
| 700 return false; | |
| 701 } | |
| 702 const std::vector<Port*>& turn_ports = iter->second; | |
| 703 return std::find(turn_ports.begin(), turn_ports.end(), port) != | |
| 704 turn_ports.end(); | |
|
pthatcher1
2016/06/27 20:35:54
If we store all port in ports_ and just mark them
honghaiz3
2016/06/28 01:49:26
Done.
| |
| 602 } | 705 } |
| 603 | 706 |
| 604 void BasicPortAllocatorSession::OnPortComplete(Port* port) { | 707 void BasicPortAllocatorSession::OnPortComplete(Port* port) { |
| 605 ASSERT(rtc::Thread::Current() == network_thread_); | 708 ASSERT(rtc::Thread::Current() == network_thread_); |
| 606 PortData* data = FindPort(port); | 709 PortData* data = FindPort(port); |
| 607 ASSERT(data != NULL); | 710 ASSERT(data != NULL); |
| 608 | 711 |
| 609 // Ignore any late signals. | 712 // Ignore any late signals. |
| 610 if (data->complete() || data->error()) { | 713 if (data->complete() || data->error()) { |
| 611 return; | 714 return; |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1021 | 1124 |
| 1022 // If BasicPortAllocatorSession::OnAllocate left relay ports enabled then we | 1125 // If BasicPortAllocatorSession::OnAllocate left relay ports enabled then we |
| 1023 // ought to have a relay list for them here. | 1126 // ought to have a relay list for them here. |
| 1024 ASSERT(config_ && !config_->relays.empty()); | 1127 ASSERT(config_ && !config_->relays.empty()); |
| 1025 if (!(config_ && !config_->relays.empty())) { | 1128 if (!(config_ && !config_->relays.empty())) { |
| 1026 LOG(LS_WARNING) | 1129 LOG(LS_WARNING) |
| 1027 << "AllocationSequence: No relay server configured, skipping."; | 1130 << "AllocationSequence: No relay server configured, skipping."; |
| 1028 return; | 1131 return; |
| 1029 } | 1132 } |
| 1030 | 1133 |
| 1031 PortConfiguration::RelayList::const_iterator relay; | 1134 for (RelayServerConfig& relay : config_->relays) { |
| 1032 for (relay = config_->relays.begin(); | 1135 if (relay.type == RELAY_GTURN) { |
| 1033 relay != config_->relays.end(); ++relay) { | 1136 CreateGturnPort(relay); |
| 1034 if (relay->type == RELAY_GTURN) { | 1137 } else if (relay.type == RELAY_TURN) { |
| 1035 CreateGturnPort(*relay); | 1138 CreateTurnPort(relay); |
| 1036 } else if (relay->type == RELAY_TURN) { | |
| 1037 CreateTurnPort(*relay); | |
| 1038 } else { | 1139 } else { |
| 1039 ASSERT(false); | 1140 ASSERT(false); |
| 1040 } | 1141 } |
| 1041 } | 1142 } |
| 1042 } | 1143 } |
| 1043 | 1144 |
| 1044 void AllocationSequence::CreateGturnPort(const RelayServerConfig& config) { | 1145 void AllocationSequence::CreateGturnPort(const RelayServerConfig& config) { |
| 1045 // TODO(mallinath) - Rename RelayPort to GTurnPort. | 1146 // TODO(mallinath) - Rename RelayPort to GTurnPort. |
| 1046 RelayPort* port = RelayPort::Create(session_->network_thread(), | 1147 RelayPort* port = RelayPort::Create(session_->network_thread(), |
| 1047 session_->socket_factory(), | 1148 session_->socket_factory(), |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 1077 for (relay_port = config.ports.begin(); | 1178 for (relay_port = config.ports.begin(); |
| 1078 relay_port != config.ports.end(); ++relay_port) { | 1179 relay_port != config.ports.end(); ++relay_port) { |
| 1079 TurnPort* port = NULL; | 1180 TurnPort* port = NULL; |
| 1080 | 1181 |
| 1081 // Skip UDP connections to relay servers if it's disallowed. | 1182 // Skip UDP connections to relay servers if it's disallowed. |
| 1082 if (IsFlagSet(PORTALLOCATOR_DISABLE_UDP_RELAY) && | 1183 if (IsFlagSet(PORTALLOCATOR_DISABLE_UDP_RELAY) && |
| 1083 relay_port->proto == PROTO_UDP) { | 1184 relay_port->proto == PROTO_UDP) { |
| 1084 continue; | 1185 continue; |
| 1085 } | 1186 } |
| 1086 | 1187 |
| 1188 // Do not create the port if the server address family is known and does | |
| 1189 // not match the local ip address family. | |
| 1190 int server_ip_family = relay_port->address.ipaddr().family(); | |
| 1191 int local_ip_family = network_->GetBestIP().family(); | |
| 1192 if (server_ip_family != AF_UNSPEC && server_ip_family != local_ip_family) { | |
| 1193 LOG(LS_INFO) << "Server and local address families are not compatible. " | |
| 1194 << "Server address: " | |
| 1195 << relay_port->address.ipaddr().ToString() | |
| 1196 << " Local address: " << network_->GetBestIP().ToString(); | |
| 1197 continue; | |
| 1198 } | |
|
pthatcher1
2016/06/27 20:35:54
Should this be a separate CL? It seems like a bug
honghaiz3
2016/06/28 01:49:26
Done.
| |
| 1199 | |
| 1087 // Shared socket mode must be enabled only for UDP based ports. Hence | 1200 // Shared socket mode must be enabled only for UDP based ports. Hence |
| 1088 // don't pass shared socket for ports which will create TCP sockets. | 1201 // don't pass shared socket for ports which will create TCP sockets. |
| 1089 // TODO(mallinath) - Enable shared socket mode for TURN ports. Disabled | 1202 // TODO(mallinath) - Enable shared socket mode for TURN ports. Disabled |
| 1090 // due to webrtc bug https://code.google.com/p/webrtc/issues/detail?id=3537 | 1203 // due to webrtc bug https://code.google.com/p/webrtc/issues/detail?id=3537 |
| 1091 if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET) && | 1204 if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET) && |
| 1092 relay_port->proto == PROTO_UDP && udp_socket_) { | 1205 relay_port->proto == PROTO_UDP && udp_socket_) { |
| 1093 port = TurnPort::Create(session_->network_thread(), | 1206 port = TurnPort::Create(session_->network_thread(), |
| 1094 session_->socket_factory(), | 1207 session_->socket_factory(), |
| 1095 network_, udp_socket_.get(), | 1208 network_, udp_socket_.get(), |
| 1096 session_->username(), session_->password(), | 1209 session_->username(), session_->password(), |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1235 ServerAddresses servers; | 1348 ServerAddresses servers; |
| 1236 for (size_t i = 0; i < relays.size(); ++i) { | 1349 for (size_t i = 0; i < relays.size(); ++i) { |
| 1237 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { | 1350 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { |
| 1238 servers.insert(relays[i].ports.front().address); | 1351 servers.insert(relays[i].ports.front().address); |
| 1239 } | 1352 } |
| 1240 } | 1353 } |
| 1241 return servers; | 1354 return servers; |
| 1242 } | 1355 } |
| 1243 | 1356 |
| 1244 } // namespace cricket | 1357 } // namespace cricket |
| OLD | NEW |