Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1816)

Side by Side Diff: webrtc/p2p/client/basicportallocator.cc

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

Powered by Google App Engine
This is Rietveld 408576698