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

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

Issue 2025573002: Use continual gathering to restore backup connections (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Address Taylor comments Created 4 years, 6 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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 network_thread_->Post(this, MSG_CONFIG_STOP); 208 network_thread_->Post(this, MSG_CONFIG_STOP);
209 ClearGettingPorts(); 209 ClearGettingPorts();
210 } 210 }
211 211
212 void BasicPortAllocatorSession::ClearGettingPorts() { 212 void BasicPortAllocatorSession::ClearGettingPorts() {
213 network_thread_->Clear(this, MSG_ALLOCATE); 213 network_thread_->Clear(this, MSG_ALLOCATE);
214 for (uint32_t i = 0; i < sequences_.size(); ++i) 214 for (uint32_t i = 0; i < sequences_.size(); ++i)
215 sequences_[i]->Stop(); 215 sequences_[i]->Stop();
216 } 216 }
217 217
218 void BasicPortAllocatorSession::GetPortsOnNetworks(
219 const std::vector<rtc::Network*>* networks) {
220 // Mark the networks on existing allocation sequences as inactive so that
221 // ports will always be allocated on the given networks.
222 for (AllocationSequence* sequence : sequences_) {
223 if (!sequence->network_inactive() &&
224 (!networks ||
225 std::find(networks->begin(), networks->end(), sequence->network()) !=
226 networks->end())) {
227 sequence->OnNetworkInactivated();
pthatcher1 2016/06/07 18:54:34 It feels like we are confounding two separate thin
228 }
229 }
230
231 StartGettingPorts();
pthatcher1 2016/06/07 18:54:34 And the Restart() above would mean we don't need t
232 }
233
218 std::vector<PortInterface*> BasicPortAllocatorSession::ReadyPorts() const { 234 std::vector<PortInterface*> BasicPortAllocatorSession::ReadyPorts() const {
219 std::vector<PortInterface*> ret; 235 std::vector<PortInterface*> ret;
220 for (const PortData& port : ports_) { 236 for (const PortData& port : ports_) {
221 if (port.has_pairable_candidate() && !port.error()) { 237 if (port.has_pairable_candidate() && !port.error()) {
222 ret.push_back(port.port()); 238 ret.push_back(port.port());
223 } 239 }
224 } 240 }
225 return ret; 241 return ret;
226 } 242 }
227 243
228 std::vector<Candidate> BasicPortAllocatorSession::ReadyCandidates() const { 244 std::vector<Candidate> BasicPortAllocatorSession::ReadyCandidates() const {
229 std::vector<Candidate> candidates; 245 std::vector<Candidate> candidates;
230 for (const PortData& data : ports_) { 246 for (const PortData& data : ports_) {
231 for (const Candidate& candidate : data.port()->Candidates()) { 247 for (const Candidate& candidate : data.port()->Candidates()) {
232 if (!CheckCandidateFilter(candidate)) { 248 if (!CheckCandidateFilter(candidate)) {
233 continue; 249 continue;
234 } 250 }
235 ProtocolType pvalue; 251 ProtocolType pvalue;
236 if (!StringToProto(candidate.protocol().c_str(), &pvalue) || 252 if (!StringToProto(candidate.protocol().c_str(), &pvalue) ||
237 !data.sequence()->ProtocolEnabled(pvalue)) { 253 !data.sequence()->ProtocolEnabled(pvalue)) {
238 continue; 254 continue;
239 } 255 }
240 candidates.push_back(SanitizeRelatedAddress(candidate)); 256 candidates.push_back(SanitizeRelatedAddress(candidate));
241 } 257 }
242 } 258 }
243 return candidates; 259 return candidates;
244 } 260 }
245 261
262 std::vector<Candidate> BasicPortAllocatorSession::ReadyCandidates(
pthatcher1 2016/06/07 18:54:34 Is it really so bad if the caller calls ReadyCandi
263 PortInterface* port) const {
264 std::vector<Candidate> candidates;
265 for (const Candidate& candidate : port->Candidates()) {
266 if (!CheckCandidateFilter(candidate)) {
267 continue;
268 }
269 candidates.push_back(SanitizeRelatedAddress(candidate));
270 }
271 return candidates;
272 }
273
246 Candidate BasicPortAllocatorSession::SanitizeRelatedAddress( 274 Candidate BasicPortAllocatorSession::SanitizeRelatedAddress(
247 const Candidate& c) const { 275 const Candidate& c) const {
248 Candidate copy = c; 276 Candidate copy = c;
249 // If adapter enumeration is disabled or host candidates are disabled, 277 // If adapter enumeration is disabled or host candidates are disabled,
250 // clear the raddr of STUN candidates to avoid local address leakage. 278 // clear the raddr of STUN candidates to avoid local address leakage.
251 bool filter_stun_related_address = 279 bool filter_stun_related_address =
252 ((flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION) && 280 ((flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION) &&
253 (flags() & PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE)) || 281 (flags() & PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE)) ||
254 !(candidate_filter_ & CF_HOST); 282 !(candidate_filter_ & CF_HOST);
255 // If the candidate filter doesn't allow reflexive addresses, empty TURN raddr 283 // If the candidate filter doesn't allow reflexive addresses, empty TURN raddr
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 network_thread_->Post(this, MSG_SEQUENCEOBJECTS_CREATED); 522 network_thread_->Post(this, MSG_SEQUENCEOBJECTS_CREATED);
495 } 523 }
496 } 524 }
497 525
498 void BasicPortAllocatorSession::OnNetworksChanged() { 526 void BasicPortAllocatorSession::OnNetworksChanged() {
499 std::vector<rtc::Network*> networks; 527 std::vector<rtc::Network*> networks;
500 GetNetworks(&networks); 528 GetNetworks(&networks);
501 for (AllocationSequence* sequence : sequences_) { 529 for (AllocationSequence* sequence : sequences_) {
502 // Remove the network from the allocation sequence if it is not in 530 // Remove the network from the allocation sequence if it is not in
503 // |networks|. 531 // |networks|.
504 if (!sequence->network_removed() && 532 if (!sequence->network_inactive() &&
pthatcher1 2016/06/07 18:54:34 I liked calling this removed before and I'd like t
505 std::find(networks.begin(), networks.end(), sequence->network()) == 533 std::find(networks.begin(), networks.end(), sequence->network()) ==
506 networks.end()) { 534 networks.end()) {
507 sequence->OnNetworkRemoved(); 535 sequence->OnNetworkInactivated();
508 } 536 }
509 } 537 }
510 538
511 network_manager_started_ = true; 539 network_manager_started_ = true;
512 if (allocation_started_) 540 if (allocation_started_)
513 DoAllocate(); 541 DoAllocate();
514 } 542 }
515 543
516 void BasicPortAllocatorSession::DisableEquivalentPhases( 544 void BasicPortAllocatorSession::DisableEquivalentPhases(
517 rtc::Network* network, 545 rtc::Network* network,
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 // are next available options to setup a communication channel. 814 // are next available options to setup a communication channel.
787 } 815 }
788 return true; 816 return true;
789 } 817 }
790 818
791 void AllocationSequence::Clear() { 819 void AllocationSequence::Clear() {
792 udp_port_ = NULL; 820 udp_port_ = NULL;
793 turn_ports_.clear(); 821 turn_ports_.clear();
794 } 822 }
795 823
796 void AllocationSequence::OnNetworkRemoved() { 824 void AllocationSequence::OnNetworkInactivated() {
797 // Stop the allocation sequence if its network is gone. 825 // Stop the allocation sequence if its network is gone.
826 network_inactive_ = true;
798 Stop(); 827 Stop();
799 network_removed_ = true;
800 } 828 }
801 829
802 AllocationSequence::~AllocationSequence() { 830 AllocationSequence::~AllocationSequence() {
803 session_->network_thread()->Clear(this); 831 session_->network_thread()->Clear(this);
804 } 832 }
805 833
806 void AllocationSequence::DisableEquivalentPhases(rtc::Network* network, 834 void AllocationSequence::DisableEquivalentPhases(rtc::Network* network,
807 PortConfiguration* config, uint32_t* flags) { 835 PortConfiguration* config, uint32_t* flags) {
808 if (network_removed_) { 836 if (network_inactive_) {
809 // If the network of this allocation sequence has ever gone away, 837 // If the network of this allocation sequence has ever become inactive,
810 // it won't be equivalent to the new network. 838 // it won't be equivalent to the new network.
811 return; 839 return;
812 } 840 }
813 841
814 if (!((network == network_) && (ip_ == network->GetBestIP()))) { 842 if (!((network == network_) && (ip_ == network->GetBestIP()))) {
815 // Different network setup; nothing is equivalent. 843 // Different network setup; nothing is equivalent.
816 return; 844 return;
817 } 845 }
818 846
819 // Else turn off the stuff that we've already got covered. 847 // Else turn off the stuff that we've already got covered.
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 ServerAddresses servers; 1263 ServerAddresses servers;
1236 for (size_t i = 0; i < relays.size(); ++i) { 1264 for (size_t i = 0; i < relays.size(); ++i) {
1237 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { 1265 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) {
1238 servers.insert(relays[i].ports.front().address); 1266 servers.insert(relays[i].ports.front().address);
1239 } 1267 }
1240 } 1268 }
1241 return servers; 1269 return servers;
1242 } 1270 }
1243 1271
1244 } // namespace cricket 1272 } // namespace cricket
OLDNEW
« webrtc/p2p/base/portinterface.h ('K') | « webrtc/p2p/client/basicportallocator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698