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

Side by Side Diff: webrtc/p2p/base/p2ptransportchannel.cc

Issue 2086793002: Set the generation on peer reflexive candidates when created. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Updating unit test. 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
« no previous file with comments | « no previous file | webrtc/p2p/base/p2ptransportchannel_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 PortInterface* port, 570 PortInterface* port,
571 const rtc::SocketAddress& address, ProtocolType proto, 571 const rtc::SocketAddress& address, ProtocolType proto,
572 IceMessage* stun_msg, const std::string &remote_username, 572 IceMessage* stun_msg, const std::string &remote_username,
573 bool port_muxed) { 573 bool port_muxed) {
574 ASSERT(worker_thread_ == rtc::Thread::Current()); 574 ASSERT(worker_thread_ == rtc::Thread::Current());
575 575
576 // Port has received a valid stun packet from an address that no Connection 576 // Port has received a valid stun packet from an address that no Connection
577 // is currently available for. See if we already have a candidate with the 577 // is currently available for. See if we already have a candidate with the
578 // address. If it isn't we need to create new candidate for it. 578 // address. If it isn't we need to create new candidate for it.
579 579
580 // Determine if the remote candidates use shared ufrag. 580 const Candidate* candidate = nullptr;
581 bool ufrag_per_port = false; 581 for (const Candidate& c : remote_candidates_) {
582 std::vector<RemoteCandidate>::iterator it; 582 if (c.username() == remote_username && c.address() == address &&
583 if (remote_candidates_.size() > 0) { 583 c.protocol() == ProtoToString(proto)) {
584 it = remote_candidates_.begin(); 584 candidate = &c;
585 std::string username = it->username(); 585 break;
586 for (; it != remote_candidates_.end(); ++it) {
587 if (it->username() != username) {
588 ufrag_per_port = true;
589 break;
590 }
591 }
592 }
593
594 const Candidate* candidate = NULL;
595 std::string remote_password;
596 for (it = remote_candidates_.begin(); it != remote_candidates_.end(); ++it) {
597 if (it->username() == remote_username) {
598 remote_password = it->password();
599 if (ufrag_per_port ||
600 (it->address() == address &&
601 it->protocol() == ProtoToString(proto))) {
602 candidate = &(*it);
603 break;
604 }
605 // We don't want to break here because we may find a match of the address
606 // later.
607 } 586 }
608 } 587 }
609 588
610 uint32_t remote_generation = 0; 589 uint32_t remote_generation = 0;
590 std::string remote_password;
611 // The STUN binding request may arrive after setRemoteDescription and before 591 // The STUN binding request may arrive after setRemoteDescription and before
612 // adding remote candidate, so we need to set the password to the shared 592 // adding remote candidate, so we need to set the password to the shared
613 // password if the user name matches. 593 // password and set the generation if the user name matches.
614 if (remote_password.empty()) { 594 const IceParameters* ice_param =
615 const IceParameters* ice_param = 595 FindRemoteIceFromUfrag(remote_username, &remote_generation);
616 FindRemoteIceFromUfrag(remote_username, &remote_generation); 596 // Note: if not found, the remote_generation will still be 0.
617 // Note: if not found, the remote_generation will still be 0. 597 if (ice_param != nullptr) {
618 if (ice_param != nullptr) { 598 remote_password = ice_param->pwd;
619 remote_password = ice_param->pwd;
620 }
621 } 599 }
622 600
623 Candidate remote_candidate; 601 Candidate remote_candidate;
624 bool remote_candidate_is_new = (candidate == nullptr); 602 bool remote_candidate_is_new = (candidate == nullptr);
625 if (!remote_candidate_is_new) { 603 if (!remote_candidate_is_new) {
626 remote_candidate = *candidate; 604 remote_candidate = *candidate;
627 if (ufrag_per_port) {
628 remote_candidate.set_address(address);
629 }
630 } else { 605 } else {
631 // Create a new candidate with this address. 606 // Create a new candidate with this address.
632 // The priority of the candidate is set to the PRIORITY attribute 607 // The priority of the candidate is set to the PRIORITY attribute
633 // from the request. 608 // from the request.
634 const StunUInt32Attribute* priority_attr = 609 const StunUInt32Attribute* priority_attr =
635 stun_msg->GetUInt32(STUN_ATTR_PRIORITY); 610 stun_msg->GetUInt32(STUN_ATTR_PRIORITY);
636 if (!priority_attr) { 611 if (!priority_attr) {
637 LOG(LS_WARNING) << "P2PTransportChannel::OnUnknownAddress - " 612 LOG(LS_WARNING) << "P2PTransportChannel::OnUnknownAddress - "
638 << "No STUN_ATTR_PRIORITY found in the " 613 << "No STUN_ATTR_PRIORITY found in the "
639 << "stun request message"; 614 << "stun request message";
(...skipping 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after
1735 1710
1736 // During the initial state when nothing has been pinged yet, return the first 1711 // During the initial state when nothing has been pinged yet, return the first
1737 // one in the ordered |connections_|. 1712 // one in the ordered |connections_|.
1738 return *(std::find_if(connections_.begin(), connections_.end(), 1713 return *(std::find_if(connections_.begin(), connections_.end(),
1739 [conn1, conn2](Connection* conn) { 1714 [conn1, conn2](Connection* conn) {
1740 return conn == conn1 || conn == conn2; 1715 return conn == conn1 || conn == conn2;
1741 })); 1716 }));
1742 } 1717 }
1743 1718
1744 } // namespace cricket 1719 } // namespace cricket
OLDNEW
« no previous file with comments | « no previous file | webrtc/p2p/base/p2ptransportchannel_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698