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

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

Issue 1274013002: Bug 4865: Enable connectivity when the remote peer is on public internet. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years, 4 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
11 #include "webrtc/p2p/client/basicportallocator.h" 11 #include "webrtc/p2p/client/basicportallocator.h"
12 12
13 #include <string> 13 #include <string>
14 #include <vector> 14 #include <vector>
15 15
16 #include "webrtc/p2p/base/basicpacketsocketfactory.h" 16 #include "webrtc/p2p/base/basicpacketsocketfactory.h"
17 #include "webrtc/p2p/base/common.h" 17 #include "webrtc/p2p/base/common.h"
18 #include "webrtc/p2p/base/port.h" 18 #include "webrtc/p2p/base/port.h"
19 #include "webrtc/p2p/base/relayport.h" 19 #include "webrtc/p2p/base/relayport.h"
20 #include "webrtc/p2p/base/stunport.h" 20 #include "webrtc/p2p/base/stunport.h"
21 #include "webrtc/p2p/base/tcpport.h" 21 #include "webrtc/p2p/base/tcpport.h"
22 #include "webrtc/p2p/base/turnport.h" 22 #include "webrtc/p2p/base/turnport.h"
23 #include "webrtc/p2p/base/udpport.h" 23 #include "webrtc/p2p/base/udpport.h"
24 #include "webrtc/base/checks.h"
24 #include "webrtc/base/common.h" 25 #include "webrtc/base/common.h"
25 #include "webrtc/base/helpers.h" 26 #include "webrtc/base/helpers.h"
26 #include "webrtc/base/logging.h" 27 #include "webrtc/base/logging.h"
27 28
28 using rtc::CreateRandomId; 29 using rtc::CreateRandomId;
29 using rtc::CreateRandomString; 30 using rtc::CreateRandomString;
30 31
31 namespace { 32 namespace {
32 33
33 enum { 34 enum {
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 void BasicPortAllocatorSession::OnCandidateReady( 434 void BasicPortAllocatorSession::OnCandidateReady(
434 Port* port, const Candidate& c) { 435 Port* port, const Candidate& c) {
435 ASSERT(rtc::Thread::Current() == network_thread_); 436 ASSERT(rtc::Thread::Current() == network_thread_);
436 PortData* data = FindPort(port); 437 PortData* data = FindPort(port);
437 ASSERT(data != NULL); 438 ASSERT(data != NULL);
438 // Discarding any candidate signal if port allocation status is 439 // Discarding any candidate signal if port allocation status is
439 // already in completed state. 440 // already in completed state.
440 if (data->complete()) 441 if (data->complete())
441 return; 442 return;
442 443
443 // Send candidates whose protocol is enabled.
444 std::vector<Candidate> candidates;
445 ProtocolType pvalue; 444 ProtocolType pvalue;
446 bool candidate_allowed_to_send = CheckCandidateFilter(c); 445 bool candidate_type_enabled = CheckCandidateFilter(c);
pthatcher1 2015/08/07 21:28:19 I think candidate_signalable would be a good name
guoweis_webrtc 2015/08/13 14:17:28 Done.
447 if (StringToProto(c.protocol().c_str(), &pvalue) && 446 bool candidate_is_any_address = c.address().IsAnyIP() && port->SharedSocket();
pthatcher1 2015/08/07 21:28:19 I think something like candidate_unsignalable_but_
guoweis_webrtc 2015/08/13 14:17:28 I don't mind the long name. I think candidate_pair
448 data->sequence()->ProtocolEnabled(pvalue) && 447 bool candidate_protocol_enabled =
449 candidate_allowed_to_send) { 448 StringToProto(c.protocol().c_str(), &pvalue) &&
449 data->sequence()->ProtocolEnabled(pvalue);
450
451 // These can't be true at the same time. The any address candidate shouldn't
452 // be allowed to send.
453 DCHECK(!candidate_type_enabled || !candidate_is_any_address);
pthatcher1 2015/08/07 21:28:19 DCHECK(!(candidate_type_enabled && candidate_is_an
guoweis_webrtc 2015/08/13 14:17:28 Done.
454
455 if (candidate_type_enabled && candidate_protocol_enabled) {
pthatcher1 2015/08/07 21:28:19 if (candidate_signalable && candidate_protocol_ena
guoweis_webrtc 2015/08/13 14:17:28 Done.
456 std::vector<Candidate> candidates;
450 candidates.push_back(c); 457 candidates.push_back(c);
451 }
452
453 if (!candidates.empty()) {
454 SignalCandidatesReady(this, candidates); 458 SignalCandidatesReady(this, candidates);
455 } 459 }
456 460
457 // Moving to READY state as we have atleast one candidate from the port. 461 // Port has been made ready. Nothing to do here.
458 // Since this port has atleast one candidate we should forward this port 462 if (data->ready()) {
459 // to listners, to allow connections from this port. 463 return;
460 // Also we should make sure that candidate gathered from this port is allowed 464 }
461 // to send outside. 465
462 if (!data->ready() && candidate_allowed_to_send) { 466 // Move the port to the READY state, either because we have a usable candidate
467 // from the port, or simply because the port is bound to the any address and
468 // therefore has no host candidate. This will trigger the port to start
469 // creating candidate pairs (connections) and issue connectivity checks.
470 if (candidate_type_enabled || candidate_is_any_address) {
pthatcher1 2015/08/07 21:28:19 if (candidate_pairable) { // ... } Would look n
463 data->set_ready(); 471 data->set_ready();
464 SignalPortReady(this, port); 472 SignalPortReady(this, port);
465 } 473 }
466 } 474 }
467 475
468 void BasicPortAllocatorSession::OnPortComplete(Port* port) { 476 void BasicPortAllocatorSession::OnPortComplete(Port* port) {
469 ASSERT(rtc::Thread::Current() == network_thread_); 477 ASSERT(rtc::Thread::Current() == network_thread_);
470 PortData* data = FindPort(port); 478 PortData* data = FindPort(port);
471 ASSERT(data != NULL); 479 ASSERT(data != NULL);
472 480
(...skipping 28 matching lines...) Expand all
501 for (std::vector<PortData>::iterator it = ports_.begin(); 509 for (std::vector<PortData>::iterator it = ports_.begin();
502 it != ports_.end(); ++it) { 510 it != ports_.end(); ++it) {
503 if (it->sequence() != seq) 511 if (it->sequence() != seq)
504 continue; 512 continue;
505 513
506 const std::vector<Candidate>& potentials = it->port()->Candidates(); 514 const std::vector<Candidate>& potentials = it->port()->Candidates();
507 for (size_t i = 0; i < potentials.size(); ++i) { 515 for (size_t i = 0; i < potentials.size(); ++i) {
508 if (!CheckCandidateFilter(potentials[i])) 516 if (!CheckCandidateFilter(potentials[i]))
509 continue; 517 continue;
510 ProtocolType pvalue; 518 ProtocolType pvalue;
511 if (!StringToProto(potentials[i].protocol().c_str(), &pvalue)) 519 bool candidate_protocol_enabled =
512 continue; 520 StringToProto(potentials[i].protocol().c_str(), &pvalue) &&
513 if (pvalue == proto) { 521 pvalue == proto;
522 if (candidate_protocol_enabled) {
514 candidates.push_back(potentials[i]); 523 candidates.push_back(potentials[i]);
515 } 524 }
516 } 525 }
517 } 526 }
518 527
519 if (!candidates.empty()) { 528 if (!candidates.empty()) {
520 SignalCandidatesReady(this, candidates); 529 SignalCandidatesReady(this, candidates);
521 } 530 }
522 } 531 }
523 532
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 ServerAddresses servers; 1128 ServerAddresses servers;
1120 for (size_t i = 0; i < relays.size(); ++i) { 1129 for (size_t i = 0; i < relays.size(); ++i) {
1121 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { 1130 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) {
1122 servers.insert(relays[i].ports.front().address); 1131 servers.insert(relays[i].ports.front().address);
1123 } 1132 }
1124 } 1133 }
1125 return servers; 1134 return servers;
1126 } 1135 }
1127 1136
1128 } // namespace cricket 1137 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698