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

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_allowed_to_send = CheckCandidateFilter(c);
juberti1 2015/08/06 23:43:21 I think the terminology here is confusing. |candid
guoweis_webrtc 2015/08/07 18:03:43 Done.
447 if (StringToProto(c.protocol().c_str(), &pvalue) && 446 bool port_bound_to_any_address =
juberti1 2015/08/06 23:43:21 I don't think this is right. The port can be bound
guoweis_webrtc 2015/08/07 18:03:43 Done.
448 data->sequence()->ProtocolEnabled(pvalue) && 447 c.address().IsAnyIP() && port->SharedSocket();
449 candidate_allowed_to_send) { 448 bool candidate_protocol_enabled =
449 StringToProto(c.protocol().c_str(), &pvalue) &&
450 data->sequence()->ProtocolEnabled(pvalue);
451
452 // These can't be true at the same time. The any address candidate shouldn't
453 // be allowed to send.
454 DCHECK(!candidate_allowed_to_send || !port_bound_to_any_address);
455
456 if (candidate_allowed_to_send && candidate_protocol_enabled) {
457 std::vector<Candidate> candidates;
450 candidates.push_back(c); 458 candidates.push_back(c);
451 }
452
453 if (!candidates.empty()) {
454 SignalCandidatesReady(this, candidates); 459 SignalCandidatesReady(this, candidates);
455 } 460 }
456 461
457 // Moving to READY state as we have atleast one candidate from the port. 462 // Port has been made ready. Nothing to do here.
458 // Since this port has atleast one candidate we should forward this port 463 if (data->ready()) {
459 // to listners, to allow connections from this port. 464 return;
460 // Also we should make sure that candidate gathered from this port is allowed 465 }
461 // to send outside. 466
462 if (!data->ready() && candidate_allowed_to_send) { 467 // Moving the port to READY state as we have at least one candidate from the
468 // port or the port is bound the any address. When this port has at least one
469 // candidate we should forward this port to listeners, to allow connections
470 // from this port. Also we should make sure that candidate gathered from this
471 // port is allowed to send outside. When the port address is bound to the any
472 // address, the any address candidate won't be allowed to send but we still
473 // need to move the port to READY such that connectivity is possible if the
474 // remote peer has a routable IP address on public Internet.
475 if (candidate_allowed_to_send || port_bound_to_any_address) {
juberti1 2015/08/06 23:43:21 Rewording: Move the port to the READY state, eith
guoweis_webrtc 2015/08/07 18:03:43 Done, thanks.
463 data->set_ready(); 476 data->set_ready();
464 SignalPortReady(this, port); 477 SignalPortReady(this, port);
465 } 478 }
466 } 479 }
467 480
468 void BasicPortAllocatorSession::OnPortComplete(Port* port) { 481 void BasicPortAllocatorSession::OnPortComplete(Port* port) {
469 ASSERT(rtc::Thread::Current() == network_thread_); 482 ASSERT(rtc::Thread::Current() == network_thread_);
470 PortData* data = FindPort(port); 483 PortData* data = FindPort(port);
471 ASSERT(data != NULL); 484 ASSERT(data != NULL);
472 485
(...skipping 28 matching lines...) Expand all
501 for (std::vector<PortData>::iterator it = ports_.begin(); 514 for (std::vector<PortData>::iterator it = ports_.begin();
502 it != ports_.end(); ++it) { 515 it != ports_.end(); ++it) {
503 if (it->sequence() != seq) 516 if (it->sequence() != seq)
504 continue; 517 continue;
505 518
506 const std::vector<Candidate>& potentials = it->port()->Candidates(); 519 const std::vector<Candidate>& potentials = it->port()->Candidates();
507 for (size_t i = 0; i < potentials.size(); ++i) { 520 for (size_t i = 0; i < potentials.size(); ++i) {
508 if (!CheckCandidateFilter(potentials[i])) 521 if (!CheckCandidateFilter(potentials[i]))
509 continue; 522 continue;
510 ProtocolType pvalue; 523 ProtocolType pvalue;
511 if (!StringToProto(potentials[i].protocol().c_str(), &pvalue)) 524 bool candidate_protocol_enabled =
512 continue; 525 StringToProto(potentials[i].protocol().c_str(), &pvalue) &&
513 if (pvalue == proto) { 526 pvalue == proto;
527 if (candidate_protocol_enabled) {
514 candidates.push_back(potentials[i]); 528 candidates.push_back(potentials[i]);
515 } 529 }
516 } 530 }
517 } 531 }
518 532
519 if (!candidates.empty()) { 533 if (!candidates.empty()) {
520 SignalCandidatesReady(this, candidates); 534 SignalCandidatesReady(this, candidates);
521 } 535 }
522 } 536 }
523 537
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 ServerAddresses servers; 1133 ServerAddresses servers;
1120 for (size_t i = 0; i < relays.size(); ++i) { 1134 for (size_t i = 0; i < relays.size(); ++i) {
1121 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { 1135 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) {
1122 servers.insert(relays[i].ports.front().address); 1136 servers.insert(relays[i].ports.front().address);
1123 } 1137 }
1124 } 1138 }
1125 return servers; 1139 return servers;
1126 } 1140 }
1127 1141
1128 } // namespace cricket 1142 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698