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

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

Issue 2125823004: Fixing problems with ICE candidate pair prioritization. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing comment formatting. 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 758 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 } else { 769 } else {
770 ASSERT(false); 770 ASSERT(false);
771 } 771 }
772 772
773 // Adding PRIORITY Attribute. 773 // Adding PRIORITY Attribute.
774 // Changing the type preference to Peer Reflexive and local preference 774 // Changing the type preference to Peer Reflexive and local preference
775 // and component id information is unchanged from the original priority. 775 // and component id information is unchanged from the original priority.
776 // priority = (2^24)*(type preference) + 776 // priority = (2^24)*(type preference) +
777 // (2^8)*(local preference) + 777 // (2^8)*(local preference) +
778 // (2^0)*(256 - component ID) 778 // (2^0)*(256 - component ID)
779 uint32_t type_preference =
780 (connection_->local_candidate().protocol() == TCP_PROTOCOL_NAME)
781 ? ICE_TYPE_PREFERENCE_PRFLX_TCP
782 : ICE_TYPE_PREFERENCE_PRFLX;
pthatcher1 2016/08/08 22:20:30 It seems like it would make sense to make this fix
779 uint32_t prflx_priority = 783 uint32_t prflx_priority =
780 ICE_TYPE_PREFERENCE_PRFLX << 24 | 784 type_preference << 24 |
781 (connection_->local_candidate().priority() & 0x00FFFFFF); 785 (connection_->local_candidate().priority() & 0x00FFFFFF);
782 request->AddAttribute( 786 request->AddAttribute(
783 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); 787 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority));
784 788
785 // Adding Message Integrity attribute. 789 // Adding Message Integrity attribute.
786 request->AddMessageIntegrity(connection_->remote_candidate().password()); 790 request->AddMessageIntegrity(connection_->remote_candidate().password());
787 // Adding Fingerprint. 791 // Adding Fingerprint.
788 request->AddFingerprint(); 792 request->AddFingerprint();
789 } 793 }
790 794
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
1318 LOG_JV(sev, this) << "Received STUN ping response" 1322 LOG_JV(sev, this) << "Received STUN ping response"
1319 << ", id=" << rtc::hex_encode(request->id()) 1323 << ", id=" << rtc::hex_encode(request->id())
1320 << ", code=0" // Makes logging easier to parse. 1324 << ", code=0" // Makes logging easier to parse.
1321 << ", rtt=" << rtt 1325 << ", rtt=" << rtt
1322 << ", use_candidate=" << use_candidate 1326 << ", use_candidate=" << use_candidate
1323 << ", pings_since_last_response=" << pings; 1327 << ", pings_since_last_response=" << pings;
1324 } 1328 }
1325 1329
1326 stats_.recv_ping_responses++; 1330 stats_.recv_ping_responses++;
1327 1331
1328 MaybeAddPrflxCandidate(request, response); 1332 MaybeUpdateLocalCandidate(request, response);
1329 } 1333 }
1330 1334
1331 void Connection::OnConnectionRequestErrorResponse(ConnectionRequest* request, 1335 void Connection::OnConnectionRequestErrorResponse(ConnectionRequest* request,
1332 StunMessage* response) { 1336 StunMessage* response) {
1333 const StunErrorCodeAttribute* error_attr = response->GetErrorCode(); 1337 const StunErrorCodeAttribute* error_attr = response->GetErrorCode();
1334 int error_code = STUN_ERROR_GLOBAL_FAILURE; 1338 int error_code = STUN_ERROR_GLOBAL_FAILURE;
1335 if (error_attr) { 1339 if (error_attr) {
1336 error_code = error_attr->code(); 1340 error_code = error_attr->code();
1337 } 1341 }
1338 1342
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1427 } 1431 }
1428 1432
1429 ConnectionInfo Connection::stats() { 1433 ConnectionInfo Connection::stats() {
1430 stats_.recv_bytes_second = round(recv_rate_tracker_.ComputeRate()); 1434 stats_.recv_bytes_second = round(recv_rate_tracker_.ComputeRate());
1431 stats_.recv_total_bytes = recv_rate_tracker_.TotalSampleCount(); 1435 stats_.recv_total_bytes = recv_rate_tracker_.TotalSampleCount();
1432 stats_.sent_bytes_second = round(send_rate_tracker_.ComputeRate()); 1436 stats_.sent_bytes_second = round(send_rate_tracker_.ComputeRate());
1433 stats_.sent_total_bytes = send_rate_tracker_.TotalSampleCount(); 1437 stats_.sent_total_bytes = send_rate_tracker_.TotalSampleCount();
1434 return stats_; 1438 return stats_;
1435 } 1439 }
1436 1440
1437 void Connection::MaybeAddPrflxCandidate(ConnectionRequest* request, 1441 void Connection::MaybeUpdateLocalCandidate(ConnectionRequest* request,
1438 StunMessage* response) { 1442 StunMessage* response) {
1439 // RFC 5245 1443 // RFC 5245
1440 // The agent checks the mapped address from the STUN response. If the 1444 // The agent checks the mapped address from the STUN response. If the
1441 // transport address does not match any of the local candidates that the 1445 // transport address does not match any of the local candidates that the
1442 // agent knows about, the mapped address represents a new candidate -- a 1446 // agent knows about, the mapped address represents a new candidate -- a
1443 // peer reflexive candidate. 1447 // peer reflexive candidate.
1444 const StunAddressAttribute* addr = 1448 const StunAddressAttribute* addr =
1445 response->GetAddress(STUN_ATTR_XOR_MAPPED_ADDRESS); 1449 response->GetAddress(STUN_ATTR_XOR_MAPPED_ADDRESS);
1446 if (!addr) { 1450 if (!addr) {
1447 LOG(LS_WARNING) << "Connection::OnConnectionRequestResponse - " 1451 LOG(LS_WARNING) << "Connection::OnConnectionRequestResponse - "
1448 << "No MAPPED-ADDRESS or XOR-MAPPED-ADDRESS found in the " 1452 << "No MAPPED-ADDRESS or XOR-MAPPED-ADDRESS found in the "
1449 << "stun response message"; 1453 << "stun response message";
1450 return; 1454 return;
1451 } 1455 }
1452 1456
1453 bool known_addr = false;
1454 for (size_t i = 0; i < port_->Candidates().size(); ++i) { 1457 for (size_t i = 0; i < port_->Candidates().size(); ++i) {
1455 if (port_->Candidates()[i].address() == addr->GetAddress()) { 1458 if (port_->Candidates()[i].address() == addr->GetAddress()) {
1456 known_addr = true; 1459 if (local_candidate_index_ != i) {
1457 break; 1460 LOG_J(LS_INFO, this) << "Updating local candidate type to srflx.";
1461 local_candidate_index_ = i;
1462 // SignalStateChange to force a re-sort in P2PTransportChannel as this
1463 // Connection's local candidate has changed.
1464 SignalStateChange(this);
1465 }
1466 return;
1458 } 1467 }
1459 } 1468 }
1460 if (known_addr) {
1461 return;
1462 }
1463 1469
1464 // RFC 5245 1470 // RFC 5245
1465 // Its priority is set equal to the value of the PRIORITY attribute 1471 // Its priority is set equal to the value of the PRIORITY attribute
1466 // in the Binding request. 1472 // in the Binding request.
1467 const StunUInt32Attribute* priority_attr = 1473 const StunUInt32Attribute* priority_attr =
1468 request->msg()->GetUInt32(STUN_ATTR_PRIORITY); 1474 request->msg()->GetUInt32(STUN_ATTR_PRIORITY);
1469 if (!priority_attr) { 1475 if (!priority_attr) {
1470 LOG(LS_WARNING) << "Connection::OnConnectionRequestResponse - " 1476 LOG(LS_WARNING) << "Connection::OnConnectionRequestResponse - "
1471 << "No STUN_ATTR_PRIORITY found in the " 1477 << "No STUN_ATTR_PRIORITY found in the "
1472 << "stun response message"; 1478 << "stun response message";
(...skipping 15 matching lines...) Expand all
1488 new_local_candidate.set_network_type(local_candidate().network_type()); 1494 new_local_candidate.set_network_type(local_candidate().network_type());
1489 new_local_candidate.set_related_address(local_candidate().address()); 1495 new_local_candidate.set_related_address(local_candidate().address());
1490 new_local_candidate.set_generation(local_candidate().generation()); 1496 new_local_candidate.set_generation(local_candidate().generation());
1491 new_local_candidate.set_foundation(ComputeFoundation( 1497 new_local_candidate.set_foundation(ComputeFoundation(
1492 PRFLX_PORT_TYPE, local_candidate().protocol(), 1498 PRFLX_PORT_TYPE, local_candidate().protocol(),
1493 local_candidate().relay_protocol(), local_candidate().address())); 1499 local_candidate().relay_protocol(), local_candidate().address()));
1494 new_local_candidate.set_network_id(local_candidate().network_id()); 1500 new_local_candidate.set_network_id(local_candidate().network_id());
1495 new_local_candidate.set_network_cost(local_candidate().network_cost()); 1501 new_local_candidate.set_network_cost(local_candidate().network_cost());
1496 1502
1497 // Change the local candidate of this Connection to the new prflx candidate. 1503 // Change the local candidate of this Connection to the new prflx candidate.
1504 LOG_J(LS_INFO, this) << "Updating local candidate type to prflx.";
1498 local_candidate_index_ = port_->AddPrflxCandidate(new_local_candidate); 1505 local_candidate_index_ = port_->AddPrflxCandidate(new_local_candidate);
1499 1506
1500 // SignalStateChange to force a re-sort in P2PTransportChannel as this 1507 // SignalStateChange to force a re-sort in P2PTransportChannel as this
1501 // Connection's local candidate has changed. 1508 // Connection's local candidate has changed.
1502 SignalStateChange(this); 1509 SignalStateChange(this);
1503 } 1510 }
1504 1511
1505 bool Connection::rtt_converged() const { 1512 bool Connection::rtt_converged() const {
1506 return rtt_samples_ > (RTT_RATIO + 1); 1513 return rtt_samples_ > (RTT_RATIO + 1);
1507 } 1514 }
(...skipping 21 matching lines...) Expand all
1529 ASSERT(sent < 0); 1536 ASSERT(sent < 0);
1530 error_ = port_->GetError(); 1537 error_ = port_->GetError();
1531 stats_.sent_discarded_packets++; 1538 stats_.sent_discarded_packets++;
1532 } else { 1539 } else {
1533 send_rate_tracker_.AddSamples(sent); 1540 send_rate_tracker_.AddSamples(sent);
1534 } 1541 }
1535 return sent; 1542 return sent;
1536 } 1543 }
1537 1544
1538 } // namespace cricket 1545 } // namespace cricket
OLDNEW
« webrtc/p2p/base/p2ptransportchannel_unittest.cc ('K') | « webrtc/p2p/base/port.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698