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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 } | 57 } |
58 | 58 |
59 } // namespace | 59 } // namespace |
60 | 60 |
61 namespace cricket { | 61 namespace cricket { |
62 const uint32_t 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(rtc::NetworkManager* network_manager, |
68 rtc::NetworkManager* network_manager, | 68 rtc::PacketSocketFactory* socket_factory) |
69 rtc::PacketSocketFactory* socket_factory) | 69 : network_manager_(network_manager), socket_factory_(socket_factory) { |
70 : network_manager_(network_manager), | |
71 socket_factory_(socket_factory), | |
72 stun_servers_() { | |
73 ASSERT(network_manager_ != nullptr); | 70 ASSERT(network_manager_ != nullptr); |
74 ASSERT(socket_factory_ != nullptr); | 71 ASSERT(socket_factory_ != nullptr); |
75 Construct(); | 72 Construct(); |
76 } | 73 } |
77 | 74 |
78 BasicPortAllocator::BasicPortAllocator(rtc::NetworkManager* network_manager) | 75 BasicPortAllocator::BasicPortAllocator(rtc::NetworkManager* network_manager) |
79 : network_manager_(network_manager), | 76 : network_manager_(network_manager), socket_factory_(nullptr) { |
80 socket_factory_(nullptr), | |
81 stun_servers_() { | |
82 ASSERT(network_manager_ != nullptr); | 77 ASSERT(network_manager_ != nullptr); |
83 Construct(); | 78 Construct(); |
84 } | 79 } |
85 | 80 |
86 BasicPortAllocator::BasicPortAllocator( | 81 BasicPortAllocator::BasicPortAllocator(rtc::NetworkManager* network_manager, |
87 rtc::NetworkManager* network_manager, | 82 rtc::PacketSocketFactory* socket_factory, |
88 rtc::PacketSocketFactory* socket_factory, | 83 const ServerAddresses& stun_servers) |
89 const ServerAddresses& stun_servers) | 84 : network_manager_(network_manager), socket_factory_(socket_factory) { |
90 : network_manager_(network_manager), | |
91 socket_factory_(socket_factory), | |
92 stun_servers_(stun_servers) { | |
93 ASSERT(socket_factory_ != NULL); | 85 ASSERT(socket_factory_ != NULL); |
86 SetConfiguration(stun_servers, std::vector<RelayServerConfig>(), 0); | |
94 Construct(); | 87 Construct(); |
95 } | 88 } |
96 | 89 |
97 BasicPortAllocator::BasicPortAllocator( | 90 BasicPortAllocator::BasicPortAllocator( |
98 rtc::NetworkManager* network_manager, | 91 rtc::NetworkManager* network_manager, |
99 const ServerAddresses& stun_servers, | 92 const ServerAddresses& stun_servers, |
100 const rtc::SocketAddress& relay_address_udp, | 93 const rtc::SocketAddress& relay_address_udp, |
101 const rtc::SocketAddress& relay_address_tcp, | 94 const rtc::SocketAddress& relay_address_tcp, |
102 const rtc::SocketAddress& relay_address_ssl) | 95 const rtc::SocketAddress& relay_address_ssl) |
103 : network_manager_(network_manager), | 96 : network_manager_(network_manager), socket_factory_(NULL) { |
104 socket_factory_(NULL), | 97 std::vector<RelayServerConfig> turn_servers; |
105 stun_servers_(stun_servers) { | |
106 | |
107 RelayServerConfig config(RELAY_GTURN); | 98 RelayServerConfig config(RELAY_GTURN); |
108 if (!relay_address_udp.IsNil()) { | 99 if (!relay_address_udp.IsNil()) { |
109 config.ports.push_back(ProtocolAddress(relay_address_udp, PROTO_UDP)); | 100 config.ports.push_back(ProtocolAddress(relay_address_udp, PROTO_UDP)); |
110 } | 101 } |
111 if (!relay_address_tcp.IsNil()) { | 102 if (!relay_address_tcp.IsNil()) { |
112 config.ports.push_back(ProtocolAddress(relay_address_tcp, PROTO_TCP)); | 103 config.ports.push_back(ProtocolAddress(relay_address_tcp, PROTO_TCP)); |
113 } | 104 } |
114 if (!relay_address_ssl.IsNil()) { | 105 if (!relay_address_ssl.IsNil()) { |
115 config.ports.push_back(ProtocolAddress(relay_address_ssl, PROTO_SSLTCP)); | 106 config.ports.push_back(ProtocolAddress(relay_address_ssl, PROTO_SSLTCP)); |
116 } | 107 } |
117 | 108 |
118 if (!config.ports.empty()) { | 109 if (!config.ports.empty()) { |
119 AddTurnServer(config); | 110 turn_servers.push_back(config); |
120 } | 111 } |
121 | 112 |
113 SetConfiguration(stun_servers, turn_servers, 0); | |
122 Construct(); | 114 Construct(); |
123 } | 115 } |
124 | 116 |
125 void BasicPortAllocator::Construct() { | 117 void BasicPortAllocator::Construct() { |
126 allow_tcp_listen_ = true; | 118 allow_tcp_listen_ = true; |
127 } | 119 } |
128 | 120 |
129 BasicPortAllocator::~BasicPortAllocator() { | 121 BasicPortAllocator::~BasicPortAllocator() { |
130 } | 122 } |
131 | 123 |
132 PortAllocatorSession* BasicPortAllocator::CreateSessionInternal( | 124 PortAllocatorSession* BasicPortAllocator::CreateSessionInternal( |
133 const std::string& content_name, int component, | 125 const std::string& content_name, int component, |
134 const std::string& ice_ufrag, const std::string& ice_pwd) { | 126 const std::string& ice_ufrag, const std::string& ice_pwd) { |
135 return new BasicPortAllocatorSession( | 127 return new BasicPortAllocatorSession( |
136 this, content_name, component, ice_ufrag, ice_pwd); | 128 this, content_name, component, ice_ufrag, ice_pwd); |
137 } | 129 } |
138 | 130 |
131 void BasicPortAllocator::AddTurnServer(const RelayServerConfig& turn_server) { | |
132 std::vector<RelayServerConfig> new_turn_servers = turn_servers(); | |
133 new_turn_servers.push_back(turn_server); | |
134 SetConfiguration(stun_servers(), new_turn_servers, candidate_pool_size()); | |
135 } | |
139 | 136 |
140 // BasicPortAllocatorSession | 137 // BasicPortAllocatorSession |
141 BasicPortAllocatorSession::BasicPortAllocatorSession( | 138 BasicPortAllocatorSession::BasicPortAllocatorSession( |
142 BasicPortAllocator *allocator, | 139 BasicPortAllocator *allocator, |
143 const std::string& content_name, | 140 const std::string& content_name, |
144 int component, | 141 int component, |
145 const std::string& ice_ufrag, | 142 const std::string& ice_ufrag, |
146 const std::string& ice_pwd) | 143 const std::string& ice_pwd) |
147 : PortAllocatorSession(content_name, component, | 144 : PortAllocatorSession(content_name, component, |
148 ice_ufrag, ice_pwd, allocator->flags()), | 145 ice_ufrag, ice_pwd, allocator->flags()), |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 network_thread_->Post(this, MSG_CONFIG_STOP); | 197 network_thread_->Post(this, MSG_CONFIG_STOP); |
201 ClearGettingPorts(); | 198 ClearGettingPorts(); |
202 } | 199 } |
203 | 200 |
204 void BasicPortAllocatorSession::ClearGettingPorts() { | 201 void BasicPortAllocatorSession::ClearGettingPorts() { |
205 network_thread_->Clear(this, MSG_ALLOCATE); | 202 network_thread_->Clear(this, MSG_ALLOCATE); |
206 for (uint32_t i = 0; i < sequences_.size(); ++i) | 203 for (uint32_t i = 0; i < sequences_.size(); ++i) |
207 sequences_[i]->Stop(); | 204 sequences_[i]->Stop(); |
208 } | 205 } |
209 | 206 |
207 std::vector<PortInterface*> BasicPortAllocatorSession::ReadyPorts() const { | |
pthatcher1
2016/05/05 21:51:25
Do we need to update the P2pPortAllocator in chrom
Taylor Brandstetter
2016/05/06 03:53:35
No, because at this point P2PPortAllocator just de
| |
208 std::vector<PortInterface*> ret; | |
209 for (const PortData& port : ports_) { | |
210 if (port.ready_or_complete()) { | |
211 ret.push_back(port.port()); | |
212 } | |
213 } | |
214 return ret; | |
215 } | |
216 | |
217 std::vector<Candidate> BasicPortAllocatorSession::ReadyCandidates() const { | |
218 std::vector<Candidate> candidates; | |
219 for (const PortData& data : ports_) { | |
220 for (const Candidate& candidate : data.port()->Candidates()) { | |
221 if (!CheckCandidateFilter(candidate)) { | |
222 continue; | |
223 } | |
224 ProtocolType pvalue; | |
225 if (!StringToProto(candidate.protocol().c_str(), &pvalue) || | |
226 !data.sequence()->ProtocolEnabled(pvalue)) { | |
227 continue; | |
228 } | |
229 candidates.push_back(candidate); | |
230 } | |
231 } | |
232 return candidates; | |
233 } | |
234 | |
235 bool BasicPortAllocatorSession::CandidatesAllocationDone() const { | |
236 // Done only if all required AllocationSequence objects | |
237 // are created. | |
238 if (!allocation_sequences_created_) { | |
239 return false; | |
240 } | |
241 | |
242 // Check that all port allocation sequences are complete. | |
243 for (AllocationSequence* sequence : sequences_) { | |
244 if (sequence->state() == AllocationSequence::kRunning) { | |
245 return false; | |
246 } | |
247 } | |
pthatcher1
2016/05/05 21:51:25
std::all_of might be handy here and below.
Taylor Brandstetter
2016/05/06 03:53:35
Done.
| |
248 | |
249 // If all allocated ports are in complete state, session must have got all | |
250 // expected candidates. Session will trigger candidates allocation complete | |
251 // signal. | |
252 for (const PortData& port : ports_) { | |
253 if (!port.complete_or_error()) { | |
254 return false; | |
255 } | |
256 } | |
257 | |
258 return true; | |
259 } | |
260 | |
210 void BasicPortAllocatorSession::OnMessage(rtc::Message *message) { | 261 void BasicPortAllocatorSession::OnMessage(rtc::Message *message) { |
211 switch (message->message_id) { | 262 switch (message->message_id) { |
212 case MSG_CONFIG_START: | 263 case MSG_CONFIG_START: |
213 ASSERT(rtc::Thread::Current() == network_thread_); | 264 ASSERT(rtc::Thread::Current() == network_thread_); |
214 GetPortConfigurations(); | 265 GetPortConfigurations(); |
215 break; | 266 break; |
216 | 267 |
217 case MSG_CONFIG_READY: | 268 case MSG_CONFIG_READY: |
218 ASSERT(rtc::Thread::Current() == network_thread_); | 269 ASSERT(rtc::Thread::Current() == network_thread_); |
219 OnConfigReady(static_cast<PortConfiguration*>(message->pdata)); | 270 OnConfigReady(static_cast<PortConfiguration*>(message->pdata)); |
(...skipping 14 matching lines...) Expand all Loading... | |
234 break; | 285 break; |
235 case MSG_CONFIG_STOP: | 286 case MSG_CONFIG_STOP: |
236 ASSERT(rtc::Thread::Current() == network_thread_); | 287 ASSERT(rtc::Thread::Current() == network_thread_); |
237 OnConfigStop(); | 288 OnConfigStop(); |
238 break; | 289 break; |
239 default: | 290 default: |
240 ASSERT(false); | 291 ASSERT(false); |
241 } | 292 } |
242 } | 293 } |
243 | 294 |
295 void BasicPortAllocatorSession::UpdateTransportInformationInternal() { | |
296 for (PortData& port : ports_) { | |
297 port.port()->set_content_name(content_name()); | |
298 port.port()->SetTransportInformation(component(), ice_ufrag(), ice_pwd()); | |
299 } | |
300 } | |
301 | |
244 void BasicPortAllocatorSession::GetPortConfigurations() { | 302 void BasicPortAllocatorSession::GetPortConfigurations() { |
245 PortConfiguration* config = new PortConfiguration(allocator_->stun_servers(), | 303 PortConfiguration* config = new PortConfiguration(allocator_->stun_servers(), |
246 username(), | 304 username(), |
247 password()); | 305 password()); |
248 | 306 |
249 for (const RelayServerConfig& turn_server : allocator_->turn_servers()) { | 307 for (const RelayServerConfig& turn_server : allocator_->turn_servers()) { |
250 config->AddRelay(turn_server); | 308 config->AddRelay(turn_server); |
251 } | 309 } |
252 ConfigReady(config); | 310 ConfigReady(config); |
253 } | 311 } |
(...skipping 13 matching lines...) Expand all Loading... | |
267 | 325 |
268 void BasicPortAllocatorSession::OnConfigStop() { | 326 void BasicPortAllocatorSession::OnConfigStop() { |
269 ASSERT(rtc::Thread::Current() == network_thread_); | 327 ASSERT(rtc::Thread::Current() == network_thread_); |
270 | 328 |
271 // If any of the allocated ports have not completed the candidates allocation, | 329 // If any of the allocated ports have not completed the candidates allocation, |
272 // mark those as error. Since session doesn't need any new candidates | 330 // mark those as error. Since session doesn't need any new candidates |
273 // at this stage of the allocation, it's safe to discard any new candidates. | 331 // at this stage of the allocation, it's safe to discard any new candidates. |
274 bool send_signal = false; | 332 bool send_signal = false; |
275 for (std::vector<PortData>::iterator it = ports_.begin(); | 333 for (std::vector<PortData>::iterator it = ports_.begin(); |
276 it != ports_.end(); ++it) { | 334 it != ports_.end(); ++it) { |
277 if (!it->complete()) { | 335 if (!it->complete_or_error()) { |
278 // Updating port state to error, which didn't finish allocating candidates | 336 // Updating port state to error, which didn't finish allocating candidates |
279 // yet. | 337 // yet. |
280 it->set_error(); | 338 it->set_error(); |
281 send_signal = true; | 339 send_signal = true; |
282 } | 340 } |
283 } | 341 } |
284 | 342 |
285 // Did we stop any running sequences? | 343 // Did we stop any running sequences? |
286 for (std::vector<AllocationSequence*>::iterator it = sequences_.begin(); | 344 for (std::vector<AllocationSequence*>::iterator it = sequences_.begin(); |
287 it != sequences_.end() && !send_signal; ++it) { | 345 it != sequences_.end() && !send_signal; ++it) { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
429 } | 487 } |
430 | 488 |
431 void BasicPortAllocatorSession::AddAllocatedPort(Port* port, | 489 void BasicPortAllocatorSession::AddAllocatedPort(Port* port, |
432 AllocationSequence * seq, | 490 AllocationSequence * seq, |
433 bool prepare_address) { | 491 bool prepare_address) { |
434 if (!port) | 492 if (!port) |
435 return; | 493 return; |
436 | 494 |
437 LOG(LS_INFO) << "Adding allocated port for " << content_name(); | 495 LOG(LS_INFO) << "Adding allocated port for " << content_name(); |
438 port->set_content_name(content_name()); | 496 port->set_content_name(content_name()); |
439 port->set_component(component_); | 497 port->set_component(component()); |
440 port->set_generation(generation()); | 498 port->set_generation(generation()); |
441 if (allocator_->proxy().type != rtc::PROXY_NONE) | 499 if (allocator_->proxy().type != rtc::PROXY_NONE) |
442 port->set_proxy(allocator_->user_agent(), allocator_->proxy()); | 500 port->set_proxy(allocator_->user_agent(), allocator_->proxy()); |
443 port->set_send_retransmit_count_attribute((allocator_->flags() & | 501 port->set_send_retransmit_count_attribute((allocator_->flags() & |
444 PORTALLOCATOR_ENABLE_STUN_RETRANSMIT_ATTRIBUTE) != 0); | 502 PORTALLOCATOR_ENABLE_STUN_RETRANSMIT_ATTRIBUTE) != 0); |
445 | 503 |
446 // Push down the candidate_filter to individual port. | 504 // Push down the candidate_filter to individual port. |
447 uint32_t candidate_filter = allocator_->candidate_filter(); | 505 uint32_t candidate_filter = allocator_->candidate_filter(); |
448 | 506 |
449 // When adapter enumeration is disabled, disable CF_HOST at port level so | 507 // When adapter enumeration is disabled, disable CF_HOST at port level so |
(...skipping 27 matching lines...) Expand all Loading... | |
477 MaybeSignalCandidatesAllocationDone(); | 535 MaybeSignalCandidatesAllocationDone(); |
478 } | 536 } |
479 | 537 |
480 void BasicPortAllocatorSession::OnCandidateReady( | 538 void BasicPortAllocatorSession::OnCandidateReady( |
481 Port* port, const Candidate& c) { | 539 Port* port, const Candidate& c) { |
482 ASSERT(rtc::Thread::Current() == network_thread_); | 540 ASSERT(rtc::Thread::Current() == network_thread_); |
483 PortData* data = FindPort(port); | 541 PortData* data = FindPort(port); |
484 ASSERT(data != NULL); | 542 ASSERT(data != NULL); |
485 // Discarding any candidate signal if port allocation status is | 543 // Discarding any candidate signal if port allocation status is |
486 // already in completed state. | 544 // already in completed state. |
487 if (data->complete()) | 545 if (data->complete_or_error()) { |
488 return; | 546 return; |
547 } | |
489 | 548 |
490 ProtocolType pvalue; | 549 ProtocolType pvalue; |
491 bool candidate_signalable = CheckCandidateFilter(c); | 550 bool candidate_signalable = CheckCandidateFilter(c); |
492 | 551 |
493 // When device enumeration is disabled (to prevent non-default IP addresses | 552 // When device enumeration is disabled (to prevent non-default IP addresses |
494 // from leaking), we ping from some local candidates even though we don't | 553 // from leaking), we ping from some local candidates even though we don't |
495 // signal them. However, if host candidates are also disabled (for example, to | 554 // signal them. However, if host candidates are also disabled (for example, to |
496 // prevent even default IP addresses from leaking), we still don't want to | 555 // prevent even default IP addresses from leaking), we still don't want to |
497 // ping from them, even if device enumeration is disabled. Thus, we check for | 556 // ping from them, even if device enumeration is disabled. Thus, we check for |
498 // both device enumeration and host candidates being disabled. | 557 // both device enumeration and host candidates being disabled. |
(...skipping 30 matching lines...) Expand all Loading... | |
529 SignalPortReady(this, port); | 588 SignalPortReady(this, port); |
530 } | 589 } |
531 } | 590 } |
532 | 591 |
533 void BasicPortAllocatorSession::OnPortComplete(Port* port) { | 592 void BasicPortAllocatorSession::OnPortComplete(Port* port) { |
534 ASSERT(rtc::Thread::Current() == network_thread_); | 593 ASSERT(rtc::Thread::Current() == network_thread_); |
535 PortData* data = FindPort(port); | 594 PortData* data = FindPort(port); |
536 ASSERT(data != NULL); | 595 ASSERT(data != NULL); |
537 | 596 |
538 // Ignore any late signals. | 597 // Ignore any late signals. |
539 if (data->complete()) | 598 if (data->complete_or_error()) { |
540 return; | 599 return; |
600 } | |
541 | 601 |
542 // Moving to COMPLETE state. | 602 // Moving to COMPLETE state. |
543 data->set_complete(); | 603 data->set_complete(); |
544 // Send candidate allocation complete signal if this was the last port. | 604 // Send candidate allocation complete signal if this was the last port. |
545 MaybeSignalCandidatesAllocationDone(); | 605 MaybeSignalCandidatesAllocationDone(); |
546 } | 606 } |
547 | 607 |
548 void BasicPortAllocatorSession::OnPortError(Port* port) { | 608 void BasicPortAllocatorSession::OnPortError(Port* port) { |
549 ASSERT(rtc::Thread::Current() == network_thread_); | 609 ASSERT(rtc::Thread::Current() == network_thread_); |
550 PortData* data = FindPort(port); | 610 PortData* data = FindPort(port); |
551 ASSERT(data != NULL); | 611 ASSERT(data != NULL); |
552 // We might have already given up on this port and stopped it. | 612 // We might have already given up on this port and stopped it. |
553 if (data->complete()) | 613 if (data->complete_or_error()) { |
554 return; | 614 return; |
615 } | |
555 | 616 |
556 // SignalAddressError is currently sent from StunPort/TurnPort. | 617 // SignalAddressError is currently sent from StunPort/TurnPort. |
557 // But this signal itself is generic. | 618 // But this signal itself is generic. |
558 data->set_error(); | 619 data->set_error(); |
559 // Send candidate allocation complete signal if this was the last port. | 620 // Send candidate allocation complete signal if this was the last port. |
560 MaybeSignalCandidatesAllocationDone(); | 621 MaybeSignalCandidatesAllocationDone(); |
561 } | 622 } |
562 | 623 |
563 void BasicPortAllocatorSession::OnProtocolEnabled(AllocationSequence* seq, | 624 void BasicPortAllocatorSession::OnProtocolEnabled(AllocationSequence* seq, |
564 ProtocolType proto) { | 625 ProtocolType proto) { |
(...skipping 15 matching lines...) Expand all Loading... | |
580 candidates.push_back(potentials[i]); | 641 candidates.push_back(potentials[i]); |
581 } | 642 } |
582 } | 643 } |
583 } | 644 } |
584 | 645 |
585 if (!candidates.empty()) { | 646 if (!candidates.empty()) { |
586 SignalCandidatesReady(this, candidates); | 647 SignalCandidatesReady(this, candidates); |
587 } | 648 } |
588 } | 649 } |
589 | 650 |
590 bool BasicPortAllocatorSession::CheckCandidateFilter(const Candidate& c) { | 651 bool BasicPortAllocatorSession::CheckCandidateFilter(const Candidate& c) const { |
591 uint32_t filter = allocator_->candidate_filter(); | 652 uint32_t filter = allocator_->candidate_filter(); |
592 | 653 |
593 // When binding to any address, before sending packets out, the getsockname | 654 // When binding to any address, before sending packets out, the getsockname |
594 // returns all 0s, but after sending packets, it'll be the NIC used to | 655 // returns all 0s, but after sending packets, it'll be the NIC used to |
595 // send. All 0s is not a valid ICE candidate address and should be filtered | 656 // send. All 0s is not a valid ICE candidate address and should be filtered |
596 // out. | 657 // out. |
597 if (c.address().IsAnyIP()) { | 658 if (c.address().IsAnyIP()) { |
598 return false; | 659 return false; |
599 } | 660 } |
600 | 661 |
(...skipping 17 matching lines...) Expand all Loading... | |
618 return false; | 679 return false; |
619 } | 680 } |
620 | 681 |
621 void BasicPortAllocatorSession::OnPortAllocationComplete( | 682 void BasicPortAllocatorSession::OnPortAllocationComplete( |
622 AllocationSequence* seq) { | 683 AllocationSequence* seq) { |
623 // Send candidate allocation complete signal if all ports are done. | 684 // Send candidate allocation complete signal if all ports are done. |
624 MaybeSignalCandidatesAllocationDone(); | 685 MaybeSignalCandidatesAllocationDone(); |
625 } | 686 } |
626 | 687 |
627 void BasicPortAllocatorSession::MaybeSignalCandidatesAllocationDone() { | 688 void BasicPortAllocatorSession::MaybeSignalCandidatesAllocationDone() { |
628 // Send signal only if all required AllocationSequence objects | 689 if (CandidatesAllocationDone()) { |
629 // are created. | 690 if (content_name().empty()) { |
pthatcher1
2016/05/05 21:51:25
Instead of having an implicit content_name().empty
Taylor Brandstetter
2016/05/06 03:53:35
Done.
| |
630 if (!allocation_sequences_created_) | 691 LOG(LS_INFO) << "All candidates gathered for pooled session."; |
631 return; | 692 } else { |
632 | 693 LOG(LS_INFO) << "All candidates gathered for " << content_name() << ":" |
633 // Check that all port allocation sequences are complete. | 694 << component() << ":" << generation(); |
634 for (std::vector<AllocationSequence*>::iterator it = sequences_.begin(); | 695 } |
635 it != sequences_.end(); ++it) { | 696 SignalCandidatesAllocationDone(this); |
636 if ((*it)->state() == AllocationSequence::kRunning) | |
637 return; | |
638 } | 697 } |
639 | |
640 // If all allocated ports are in complete state, session must have got all | |
641 // expected candidates. Session will trigger candidates allocation complete | |
642 // signal. | |
643 for (std::vector<PortData>::iterator it = ports_.begin(); | |
644 it != ports_.end(); ++it) { | |
645 if (!it->complete()) | |
646 return; | |
647 } | |
648 LOG(LS_INFO) << "All candidates gathered for " << content_name_ << ":" | |
649 << component_ << ":" << generation(); | |
650 SignalCandidatesAllocationDone(this); | |
651 } | 698 } |
652 | 699 |
653 void BasicPortAllocatorSession::OnPortDestroyed( | 700 void BasicPortAllocatorSession::OnPortDestroyed( |
654 PortInterface* port) { | 701 PortInterface* port) { |
655 ASSERT(rtc::Thread::Current() == network_thread_); | 702 ASSERT(rtc::Thread::Current() == network_thread_); |
656 for (std::vector<PortData>::iterator iter = ports_.begin(); | 703 for (std::vector<PortData>::iterator iter = ports_.begin(); |
657 iter != ports_.end(); ++iter) { | 704 iter != ports_.end(); ++iter) { |
658 if (port == iter->port()) { | 705 if (port == iter->port()) { |
659 ports_.erase(iter); | 706 ports_.erase(iter); |
660 LOG_J(LS_INFO, port) << "Removed port from allocator (" | 707 LOG_J(LS_INFO, port) << "Removed port from allocator (" |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1184 ServerAddresses servers; | 1231 ServerAddresses servers; |
1185 for (size_t i = 0; i < relays.size(); ++i) { | 1232 for (size_t i = 0; i < relays.size(); ++i) { |
1186 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { | 1233 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { |
1187 servers.insert(relays[i].ports.front().address); | 1234 servers.insert(relays[i].ports.front().address); |
1188 } | 1235 } |
1189 } | 1236 } |
1190 return servers; | 1237 return servers; |
1191 } | 1238 } |
1192 | 1239 |
1193 } // namespace cricket | 1240 } // namespace cricket |
OLD | NEW |