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 // Gets address family priority: IPv6 > IPv4 > Unspecified. | |
51 int GetAddressFamilyPriority(int ip_family) { | |
52 switch (ip_family) { | |
53 case AF_INET6: | |
54 return 2; | |
55 case AF_INET: | |
56 return 1; | |
57 default: | |
58 RTC_DCHECK(false); | |
59 return 0; | |
60 } | |
61 } | |
62 | |
63 // Returns positive if a is better, negative if b is better, and 0 otherwise. | |
64 int ComparePort(const cricket::Port* a, const cricket::Port* b) { | |
65 static constexpr int a_is_better = 1; | |
66 static constexpr int b_is_better = -1; | |
67 // Protocol type is defined as UDP = 0, TCP = 1, SSLTCP = 2. | |
68 if (a->GetProtocol() < b->GetProtocol()) { | |
69 return a_is_better; | |
70 } | |
71 if (a->GetProtocol() > b->GetProtocol()) { | |
72 return b_is_better; | |
73 } | |
74 | |
75 int a_family = GetAddressFamilyPriority(a->Network()->GetBestIP().family()); | |
76 int b_family = GetAddressFamilyPriority(b->Network()->GetBestIP().family()); | |
77 return a_family - b_family; | |
78 } | |
79 | |
50 } // namespace | 80 } // namespace |
51 | 81 |
52 namespace cricket { | 82 namespace cricket { |
53 const uint32_t DISABLE_ALL_PHASES = | 83 const uint32_t DISABLE_ALL_PHASES = |
54 PORTALLOCATOR_DISABLE_UDP | PORTALLOCATOR_DISABLE_TCP | | 84 PORTALLOCATOR_DISABLE_UDP | PORTALLOCATOR_DISABLE_TCP | |
55 PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY; | 85 PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY; |
56 | 86 |
57 // BasicPortAllocator | 87 // BasicPortAllocator |
58 BasicPortAllocator::BasicPortAllocator(rtc::NetworkManager* network_manager, | 88 BasicPortAllocator::BasicPortAllocator(rtc::NetworkManager* network_manager, |
59 rtc::PacketSocketFactory* socket_factory) | 89 rtc::PacketSocketFactory* socket_factory) |
60 : network_manager_(network_manager), socket_factory_(socket_factory) { | 90 : network_manager_(network_manager), socket_factory_(socket_factory) { |
61 ASSERT(network_manager_ != nullptr); | 91 ASSERT(network_manager_ != nullptr); |
62 ASSERT(socket_factory_ != nullptr); | 92 ASSERT(socket_factory_ != nullptr); |
63 Construct(); | 93 Construct(); |
64 } | 94 } |
65 | 95 |
66 BasicPortAllocator::BasicPortAllocator(rtc::NetworkManager* network_manager) | 96 BasicPortAllocator::BasicPortAllocator(rtc::NetworkManager* network_manager) |
67 : network_manager_(network_manager), socket_factory_(nullptr) { | 97 : network_manager_(network_manager), socket_factory_(nullptr) { |
68 ASSERT(network_manager_ != nullptr); | 98 ASSERT(network_manager_ != nullptr); |
69 Construct(); | 99 Construct(); |
70 } | 100 } |
71 | 101 |
72 BasicPortAllocator::BasicPortAllocator(rtc::NetworkManager* network_manager, | 102 BasicPortAllocator::BasicPortAllocator(rtc::NetworkManager* network_manager, |
73 rtc::PacketSocketFactory* socket_factory, | 103 rtc::PacketSocketFactory* socket_factory, |
74 const ServerAddresses& stun_servers) | 104 const ServerAddresses& stun_servers) |
75 : network_manager_(network_manager), socket_factory_(socket_factory) { | 105 : network_manager_(network_manager), socket_factory_(socket_factory) { |
76 ASSERT(socket_factory_ != NULL); | 106 ASSERT(socket_factory_ != NULL); |
77 SetConfiguration(stun_servers, std::vector<RelayServerConfig>(), 0); | 107 SetConfiguration(stun_servers, std::vector<RelayServerConfig>(), 0, false); |
78 Construct(); | 108 Construct(); |
79 } | 109 } |
80 | 110 |
81 BasicPortAllocator::BasicPortAllocator( | 111 BasicPortAllocator::BasicPortAllocator( |
82 rtc::NetworkManager* network_manager, | 112 rtc::NetworkManager* network_manager, |
83 const ServerAddresses& stun_servers, | 113 const ServerAddresses& stun_servers, |
84 const rtc::SocketAddress& relay_address_udp, | 114 const rtc::SocketAddress& relay_address_udp, |
85 const rtc::SocketAddress& relay_address_tcp, | 115 const rtc::SocketAddress& relay_address_tcp, |
86 const rtc::SocketAddress& relay_address_ssl) | 116 const rtc::SocketAddress& relay_address_ssl) |
87 : network_manager_(network_manager), socket_factory_(NULL) { | 117 : network_manager_(network_manager), socket_factory_(NULL) { |
88 std::vector<RelayServerConfig> turn_servers; | 118 std::vector<RelayServerConfig> turn_servers; |
89 RelayServerConfig config(RELAY_GTURN); | 119 RelayServerConfig config(RELAY_GTURN); |
90 if (!relay_address_udp.IsNil()) { | 120 if (!relay_address_udp.IsNil()) { |
91 config.ports.push_back(ProtocolAddress(relay_address_udp, PROTO_UDP)); | 121 config.ports.push_back(ProtocolAddress(relay_address_udp, PROTO_UDP)); |
92 } | 122 } |
93 if (!relay_address_tcp.IsNil()) { | 123 if (!relay_address_tcp.IsNil()) { |
94 config.ports.push_back(ProtocolAddress(relay_address_tcp, PROTO_TCP)); | 124 config.ports.push_back(ProtocolAddress(relay_address_tcp, PROTO_TCP)); |
95 } | 125 } |
96 if (!relay_address_ssl.IsNil()) { | 126 if (!relay_address_ssl.IsNil()) { |
97 config.ports.push_back(ProtocolAddress(relay_address_ssl, PROTO_SSLTCP)); | 127 config.ports.push_back(ProtocolAddress(relay_address_ssl, PROTO_SSLTCP)); |
98 } | 128 } |
99 | 129 |
100 if (!config.ports.empty()) { | 130 if (!config.ports.empty()) { |
101 turn_servers.push_back(config); | 131 turn_servers.push_back(config); |
102 } | 132 } |
103 | 133 |
104 SetConfiguration(stun_servers, turn_servers, 0); | 134 SetConfiguration(stun_servers, turn_servers, 0, false); |
105 Construct(); | 135 Construct(); |
106 } | 136 } |
107 | 137 |
108 void BasicPortAllocator::Construct() { | 138 void BasicPortAllocator::Construct() { |
109 allow_tcp_listen_ = true; | 139 allow_tcp_listen_ = true; |
110 } | 140 } |
111 | 141 |
112 BasicPortAllocator::~BasicPortAllocator() { | 142 BasicPortAllocator::~BasicPortAllocator() { |
113 } | 143 } |
114 | 144 |
115 PortAllocatorSession* BasicPortAllocator::CreateSessionInternal( | 145 PortAllocatorSession* BasicPortAllocator::CreateSessionInternal( |
116 const std::string& content_name, int component, | 146 const std::string& content_name, int component, |
117 const std::string& ice_ufrag, const std::string& ice_pwd) { | 147 const std::string& ice_ufrag, const std::string& ice_pwd) { |
118 return new BasicPortAllocatorSession( | 148 return new BasicPortAllocatorSession( |
119 this, content_name, component, ice_ufrag, ice_pwd); | 149 this, content_name, component, ice_ufrag, ice_pwd); |
120 } | 150 } |
121 | 151 |
122 void BasicPortAllocator::AddTurnServer(const RelayServerConfig& turn_server) { | 152 void BasicPortAllocator::AddTurnServer(const RelayServerConfig& turn_server) { |
123 std::vector<RelayServerConfig> new_turn_servers = turn_servers(); | 153 std::vector<RelayServerConfig> new_turn_servers = turn_servers(); |
124 new_turn_servers.push_back(turn_server); | 154 new_turn_servers.push_back(turn_server); |
125 SetConfiguration(stun_servers(), new_turn_servers, candidate_pool_size()); | 155 SetConfiguration(stun_servers(), new_turn_servers, candidate_pool_size(), |
156 prune_turn_ports()); | |
126 } | 157 } |
127 | 158 |
128 // BasicPortAllocatorSession | 159 // BasicPortAllocatorSession |
129 BasicPortAllocatorSession::BasicPortAllocatorSession( | 160 BasicPortAllocatorSession::BasicPortAllocatorSession( |
130 BasicPortAllocator *allocator, | 161 BasicPortAllocator *allocator, |
131 const std::string& content_name, | 162 const std::string& content_name, |
132 int component, | 163 int component, |
133 const std::string& ice_ufrag, | 164 const std::string& ice_ufrag, |
134 const std::string& ice_pwd) | 165 const std::string& ice_pwd) |
135 : PortAllocatorSession(content_name, component, | 166 : PortAllocatorSession(content_name, component, |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 } | 241 } |
211 | 242 |
212 void BasicPortAllocatorSession::ClearGettingPorts() { | 243 void BasicPortAllocatorSession::ClearGettingPorts() { |
213 network_thread_->Clear(this, MSG_ALLOCATE); | 244 network_thread_->Clear(this, MSG_ALLOCATE); |
214 for (uint32_t i = 0; i < sequences_.size(); ++i) | 245 for (uint32_t i = 0; i < sequences_.size(); ++i) |
215 sequences_[i]->Stop(); | 246 sequences_[i]->Stop(); |
216 } | 247 } |
217 | 248 |
218 std::vector<PortInterface*> BasicPortAllocatorSession::ReadyPorts() const { | 249 std::vector<PortInterface*> BasicPortAllocatorSession::ReadyPorts() const { |
219 std::vector<PortInterface*> ret; | 250 std::vector<PortInterface*> ret; |
220 for (const PortData& port : ports_) { | 251 for (const PortData& data : ports_) { |
221 if (port.has_pairable_candidate() && !port.error()) { | 252 if (data.ready()) { |
222 ret.push_back(port.port()); | 253 ret.push_back(data.port()); |
223 } | 254 } |
224 } | 255 } |
225 return ret; | 256 return ret; |
226 } | 257 } |
227 | 258 |
228 std::vector<Candidate> BasicPortAllocatorSession::ReadyCandidates() const { | 259 std::vector<Candidate> BasicPortAllocatorSession::ReadyCandidates() const { |
229 std::vector<Candidate> candidates; | 260 std::vector<Candidate> candidates; |
230 for (const PortData& data : ports_) { | 261 for (const PortData& data : ports_) { |
262 if (!data.ready()) { | |
263 continue; | |
264 } | |
265 | |
231 for (const Candidate& candidate : data.port()->Candidates()) { | 266 for (const Candidate& candidate : data.port()->Candidates()) { |
232 if (!CheckCandidateFilter(candidate)) { | 267 if (!CheckCandidateFilter(candidate)) { |
233 continue; | 268 continue; |
234 } | 269 } |
235 ProtocolType pvalue; | 270 ProtocolType pvalue; |
236 if (!StringToProto(candidate.protocol().c_str(), &pvalue) || | 271 if (!StringToProto(candidate.protocol().c_str(), &pvalue) || |
237 !data.sequence()->ProtocolEnabled(pvalue)) { | 272 !data.sequence()->ProtocolEnabled(pvalue)) { |
238 continue; | 273 continue; |
239 } | 274 } |
240 candidates.push_back(SanitizeRelatedAddress(candidate)); | 275 candidates.push_back(SanitizeRelatedAddress(candidate)); |
(...skipping 30 matching lines...) Expand all Loading... | |
271 } | 306 } |
272 | 307 |
273 // Check that all port allocation sequences are complete (not running). | 308 // Check that all port allocation sequences are complete (not running). |
274 if (std::any_of(sequences_.begin(), sequences_.end(), | 309 if (std::any_of(sequences_.begin(), sequences_.end(), |
275 [](const AllocationSequence* sequence) { | 310 [](const AllocationSequence* sequence) { |
276 return sequence->state() == AllocationSequence::kRunning; | 311 return sequence->state() == AllocationSequence::kRunning; |
277 })) { | 312 })) { |
278 return false; | 313 return false; |
279 } | 314 } |
280 | 315 |
281 // If all allocated ports are in complete state, session must have got all | 316 // If all allocated ports are no longer gathering, session must have got all |
282 // expected candidates. Session will trigger candidates allocation complete | 317 // expected candidates. Session will trigger candidates allocation complete |
283 // signal. | 318 // signal. |
284 if (!std::all_of(ports_.begin(), ports_.end(), [](const PortData& port) { | 319 return std::none_of(ports_.begin(), ports_.end(), |
285 return (port.complete() || port.error()); | 320 [](const PortData& port) { return port.inprogress(); }); |
286 })) { | |
287 return false; | |
288 } | |
289 | |
290 return true; | |
291 } | 321 } |
292 | 322 |
293 void BasicPortAllocatorSession::OnMessage(rtc::Message *message) { | 323 void BasicPortAllocatorSession::OnMessage(rtc::Message *message) { |
294 switch (message->message_id) { | 324 switch (message->message_id) { |
295 case MSG_CONFIG_START: | 325 case MSG_CONFIG_START: |
296 ASSERT(rtc::Thread::Current() == network_thread_); | 326 ASSERT(rtc::Thread::Current() == network_thread_); |
297 GetPortConfigurations(); | 327 GetPortConfigurations(); |
298 break; | 328 break; |
299 case MSG_CONFIG_READY: | 329 case MSG_CONFIG_READY: |
300 ASSERT(rtc::Thread::Current() == network_thread_); | 330 ASSERT(rtc::Thread::Current() == network_thread_); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
350 | 380 |
351 void BasicPortAllocatorSession::OnConfigStop() { | 381 void BasicPortAllocatorSession::OnConfigStop() { |
352 ASSERT(rtc::Thread::Current() == network_thread_); | 382 ASSERT(rtc::Thread::Current() == network_thread_); |
353 | 383 |
354 // If any of the allocated ports have not completed the candidates allocation, | 384 // If any of the allocated ports have not completed the candidates allocation, |
355 // mark those as error. Since session doesn't need any new candidates | 385 // mark those as error. Since session doesn't need any new candidates |
356 // at this stage of the allocation, it's safe to discard any new candidates. | 386 // at this stage of the allocation, it's safe to discard any new candidates. |
357 bool send_signal = false; | 387 bool send_signal = false; |
358 for (std::vector<PortData>::iterator it = ports_.begin(); | 388 for (std::vector<PortData>::iterator it = ports_.begin(); |
359 it != ports_.end(); ++it) { | 389 it != ports_.end(); ++it) { |
360 if (!it->complete() && !it->error()) { | 390 if (it->inprogress()) { |
361 // Updating port state to error, which didn't finish allocating candidates | 391 // Updating port state to error, which didn't finish allocating candidates |
362 // yet. | 392 // yet. |
363 it->set_error(); | 393 it->set_error(); |
364 send_signal = true; | 394 send_signal = true; |
365 } | 395 } |
366 } | 396 } |
367 | 397 |
368 // Did we stop any running sequences? | 398 // Did we stop any running sequences? |
369 for (std::vector<AllocationSequence*>::iterator it = sequences_.begin(); | 399 for (std::vector<AllocationSequence*>::iterator it = sequences_.begin(); |
370 it != sequences_.end() && !send_signal; ++it) { | 400 it != sequences_.end() && !send_signal; ++it) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
436 // create a new sequence to create the appropriate ports. | 466 // create a new sequence to create the appropriate ports. |
437 void BasicPortAllocatorSession::DoAllocate() { | 467 void BasicPortAllocatorSession::DoAllocate() { |
438 bool done_signal_needed = false; | 468 bool done_signal_needed = false; |
439 std::vector<rtc::Network*> networks; | 469 std::vector<rtc::Network*> networks; |
440 GetNetworks(&networks); | 470 GetNetworks(&networks); |
441 | 471 |
442 if (networks.empty()) { | 472 if (networks.empty()) { |
443 LOG(LS_WARNING) << "Machine has no networks; no ports will be allocated"; | 473 LOG(LS_WARNING) << "Machine has no networks; no ports will be allocated"; |
444 done_signal_needed = true; | 474 done_signal_needed = true; |
445 } else { | 475 } else { |
476 PortConfiguration* config = configs_.empty() ? nullptr : configs_.back(); | |
446 for (uint32_t i = 0; i < networks.size(); ++i) { | 477 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(); | 478 uint32_t sequence_flags = flags(); |
452 if ((sequence_flags & DISABLE_ALL_PHASES) == DISABLE_ALL_PHASES) { | 479 if ((sequence_flags & DISABLE_ALL_PHASES) == DISABLE_ALL_PHASES) { |
453 // If all the ports are disabled we should just fire the allocation | 480 // If all the ports are disabled we should just fire the allocation |
454 // done event and return. | 481 // done event and return. |
455 done_signal_needed = true; | 482 done_signal_needed = true; |
456 break; | 483 break; |
457 } | 484 } |
458 | 485 |
459 if (!config || config->relays.empty()) { | 486 if (!config || config->relays.empty()) { |
460 // No relay ports specified in this config. | 487 // No relay ports specified in this config. |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
561 // Send candidate allocation complete signal if we have no sequences. | 588 // Send candidate allocation complete signal if we have no sequences. |
562 MaybeSignalCandidatesAllocationDone(); | 589 MaybeSignalCandidatesAllocationDone(); |
563 } | 590 } |
564 | 591 |
565 void BasicPortAllocatorSession::OnCandidateReady( | 592 void BasicPortAllocatorSession::OnCandidateReady( |
566 Port* port, const Candidate& c) { | 593 Port* port, const Candidate& c) { |
567 ASSERT(rtc::Thread::Current() == network_thread_); | 594 ASSERT(rtc::Thread::Current() == network_thread_); |
568 PortData* data = FindPort(port); | 595 PortData* data = FindPort(port); |
569 ASSERT(data != NULL); | 596 ASSERT(data != NULL); |
570 // Discarding any candidate signal if port allocation status is | 597 // Discarding any candidate signal if port allocation status is |
571 // already in completed state. | 598 // already done with gathering. |
572 if (data->complete() || data->error()) { | 599 if (!data->inprogress()) { |
573 return; | 600 return; |
574 } | 601 } |
575 | 602 |
603 // Mark that the port has a pairable candidate, either because we have a | |
604 // usable candidate from the port, or simply because the port is bound to the | |
605 // any address and therefore has no host candidate. This will trigger the port | |
606 // to start creating candidate pairs (connections) and issue connectivity | |
607 // checks. If port has already been marked as having a pairable candidate, | |
608 // do nothing here. | |
609 // Note: We should check whether any candidates may become ready after this | |
610 // because there we will check whether the candidate is generated by the ready | |
611 // ports, which may include this port. | |
612 if (CandidatePairable(c, port) && !data->has_pairable_candidate()) { | |
613 data->set_has_pairable_candidate(true); | |
614 | |
615 bool pruned_port = PruneTurnPortsWith(port); | |
pthatcher1
2016/06/29 17:36:14
Can you move the "if (!allocator_->prune_turn_port
honghaiz3
2016/06/29 18:11:45
Done.
| |
616 // If the current port is not pruned yet, SignalPortReady. | |
617 if (!data->pruned()) { | |
618 SignalPortReady(this, port); | |
619 } | |
620 // If we have pruned any port, maybe need to signal port allocation done. | |
621 if (pruned_port) { | |
622 MaybeSignalCandidatesAllocationDone(); | |
623 } | |
624 } | |
625 | |
576 ProtocolType pvalue; | 626 ProtocolType pvalue; |
577 bool candidate_protocol_enabled = | 627 bool candidate_protocol_enabled = |
578 StringToProto(c.protocol().c_str(), &pvalue) && | 628 StringToProto(c.protocol().c_str(), &pvalue) && |
579 data->sequence()->ProtocolEnabled(pvalue); | 629 data->sequence()->ProtocolEnabled(pvalue); |
580 | 630 |
581 if (CheckCandidateFilter(c) && candidate_protocol_enabled) { | 631 if (data->ready() && CheckCandidateFilter(c) && candidate_protocol_enabled) { |
582 std::vector<Candidate> candidates; | 632 std::vector<Candidate> candidates; |
583 candidates.push_back(SanitizeRelatedAddress(c)); | 633 candidates.push_back(SanitizeRelatedAddress(c)); |
584 SignalCandidatesReady(this, candidates); | 634 SignalCandidatesReady(this, candidates); |
585 } | 635 } |
636 } | |
586 | 637 |
587 // Port has already been marked as having a pairable candidate. | 638 Port* BasicPortAllocatorSession::GetBestTurnPortForNetwork( |
588 // Nothing to do here. | 639 const std::string& network_name) const { |
589 if (data->has_pairable_candidate()) { | 640 Port* best_turn_port = nullptr; |
590 return; | 641 for (const PortData& data : ports_) { |
642 if (data.port()->Network()->name() == network_name && | |
643 data.port()->Type() == RELAY_PORT_TYPE && data.ready() && | |
644 (!best_turn_port || ComparePort(data.port(), best_turn_port) > 0)) { | |
645 best_turn_port = data.port(); | |
646 } | |
591 } | 647 } |
648 return best_turn_port; | |
649 } | |
592 | 650 |
593 // Mark that the port has a pairable candidate, either because we have a | 651 bool BasicPortAllocatorSession::PruneTurnPortsWith(Port* port) { |
pthatcher1
2016/06/29 17:36:14
I'd suggest calling this PruneTurnPorts and callin
honghaiz3
2016/06/29 18:11:45
Done.
| |
594 // usable candidate from the port, or simply because the port is bound to the | 652 if (!allocator_->prune_turn_ports() || port->Type() != RELAY_PORT_TYPE) { |
595 // any address and therefore has no host candidate. This will trigger the port | 653 return false; |
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 } | 654 } |
655 bool pruned_port = false; | |
656 // Note: We determine the same network based only on their network names. So | |
657 // if an IPv4 address and an IPv6 address have the same network name, they | |
658 // are considered the same network here. | |
659 const std::string& network_name = port->Network()->name(); | |
660 Port* best_turn_port = GetBestTurnPortForNetwork(network_name); | |
661 // |port| is already in the list of ports, so the best port cannot be nullptr. | |
662 RTC_CHECK(best_turn_port != nullptr); | |
663 | |
664 for (PortData& data : ports_) { | |
665 if (data.port()->Network()->name() == network_name && | |
666 data.port()->Type() == RELAY_PORT_TYPE && !data.pruned() && | |
667 ComparePort(data.port(), best_turn_port) < 0) { | |
668 data.set_pruned(); | |
669 pruned_port = true; | |
670 if (data.port() != port) { | |
671 SignalPortPruned(this, data.port()); | |
672 } | |
673 } | |
674 } | |
675 return pruned_port; | |
602 } | 676 } |
603 | 677 |
604 void BasicPortAllocatorSession::OnPortComplete(Port* port) { | 678 void BasicPortAllocatorSession::OnPortComplete(Port* port) { |
605 ASSERT(rtc::Thread::Current() == network_thread_); | 679 ASSERT(rtc::Thread::Current() == network_thread_); |
606 PortData* data = FindPort(port); | 680 PortData* data = FindPort(port); |
607 ASSERT(data != NULL); | 681 ASSERT(data != NULL); |
608 | 682 |
609 // Ignore any late signals. | 683 // Ignore any late signals. |
610 if (data->complete() || data->error()) { | 684 if (!data->inprogress()) { |
611 return; | 685 return; |
612 } | 686 } |
613 | 687 |
614 // Moving to COMPLETE state. | 688 // Moving to COMPLETE state. |
615 data->set_complete(); | 689 data->set_complete(); |
616 // Send candidate allocation complete signal if this was the last port. | 690 // Send candidate allocation complete signal if this was the last port. |
617 MaybeSignalCandidatesAllocationDone(); | 691 MaybeSignalCandidatesAllocationDone(); |
618 } | 692 } |
619 | 693 |
620 void BasicPortAllocatorSession::OnPortError(Port* port) { | 694 void BasicPortAllocatorSession::OnPortError(Port* port) { |
621 ASSERT(rtc::Thread::Current() == network_thread_); | 695 ASSERT(rtc::Thread::Current() == network_thread_); |
622 PortData* data = FindPort(port); | 696 PortData* data = FindPort(port); |
623 ASSERT(data != NULL); | 697 ASSERT(data != NULL); |
624 // We might have already given up on this port and stopped it. | 698 // We might have already given up on this port and stopped it. |
625 if (data->complete() || data->error()) { | 699 if (!data->inprogress()) { |
626 return; | 700 return; |
627 } | 701 } |
628 | 702 |
629 // SignalAddressError is currently sent from StunPort/TurnPort. | 703 // SignalAddressError is currently sent from StunPort/TurnPort. |
630 // But this signal itself is generic. | 704 // But this signal itself is generic. |
631 data->set_error(); | 705 data->set_error(); |
632 // Send candidate allocation complete signal if this was the last port. | 706 // Send candidate allocation complete signal if this was the last port. |
633 MaybeSignalCandidatesAllocationDone(); | 707 MaybeSignalCandidatesAllocationDone(); |
634 } | 708 } |
635 | 709 |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1021 | 1095 |
1022 // If BasicPortAllocatorSession::OnAllocate left relay ports enabled then we | 1096 // If BasicPortAllocatorSession::OnAllocate left relay ports enabled then we |
1023 // ought to have a relay list for them here. | 1097 // ought to have a relay list for them here. |
1024 ASSERT(config_ && !config_->relays.empty()); | 1098 ASSERT(config_ && !config_->relays.empty()); |
1025 if (!(config_ && !config_->relays.empty())) { | 1099 if (!(config_ && !config_->relays.empty())) { |
1026 LOG(LS_WARNING) | 1100 LOG(LS_WARNING) |
1027 << "AllocationSequence: No relay server configured, skipping."; | 1101 << "AllocationSequence: No relay server configured, skipping."; |
1028 return; | 1102 return; |
1029 } | 1103 } |
1030 | 1104 |
1031 PortConfiguration::RelayList::const_iterator relay; | 1105 for (RelayServerConfig& relay : config_->relays) { |
1032 for (relay = config_->relays.begin(); | 1106 if (relay.type == RELAY_GTURN) { |
1033 relay != config_->relays.end(); ++relay) { | 1107 CreateGturnPort(relay); |
1034 if (relay->type == RELAY_GTURN) { | 1108 } else if (relay.type == RELAY_TURN) { |
1035 CreateGturnPort(*relay); | 1109 CreateTurnPort(relay); |
1036 } else if (relay->type == RELAY_TURN) { | |
1037 CreateTurnPort(*relay); | |
1038 } else { | 1110 } else { |
1039 ASSERT(false); | 1111 ASSERT(false); |
1040 } | 1112 } |
1041 } | 1113 } |
1042 } | 1114 } |
1043 | 1115 |
1044 void AllocationSequence::CreateGturnPort(const RelayServerConfig& config) { | 1116 void AllocationSequence::CreateGturnPort(const RelayServerConfig& config) { |
1045 // TODO(mallinath) - Rename RelayPort to GTurnPort. | 1117 // TODO(mallinath) - Rename RelayPort to GTurnPort. |
1046 RelayPort* port = RelayPort::Create(session_->network_thread(), | 1118 RelayPort* port = RelayPort::Create(session_->network_thread(), |
1047 session_->socket_factory(), | 1119 session_->socket_factory(), |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1235 ServerAddresses servers; | 1307 ServerAddresses servers; |
1236 for (size_t i = 0; i < relays.size(); ++i) { | 1308 for (size_t i = 0; i < relays.size(); ++i) { |
1237 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { | 1309 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { |
1238 servers.insert(relays[i].ports.front().address); | 1310 servers.insert(relays[i].ports.front().address); |
1239 } | 1311 } |
1240 } | 1312 } |
1241 return servers; | 1313 return servers; |
1242 } | 1314 } |
1243 | 1315 |
1244 } // namespace cricket | 1316 } // namespace cricket |
OLD | NEW |