OLD | NEW |
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 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 } else { | 792 } else { |
793 ASSERT(false); | 793 ASSERT(false); |
794 } | 794 } |
795 | 795 |
796 // Adding PRIORITY Attribute. | 796 // Adding PRIORITY Attribute. |
797 // Changing the type preference to Peer Reflexive and local preference | 797 // Changing the type preference to Peer Reflexive and local preference |
798 // and component id information is unchanged from the original priority. | 798 // and component id information is unchanged from the original priority. |
799 // priority = (2^24)*(type preference) + | 799 // priority = (2^24)*(type preference) + |
800 // (2^8)*(local preference) + | 800 // (2^8)*(local preference) + |
801 // (2^0)*(256 - component ID) | 801 // (2^0)*(256 - component ID) |
| 802 uint32_t type_preference = |
| 803 (connection_->local_candidate().protocol() == TCP_PROTOCOL_NAME) |
| 804 ? ICE_TYPE_PREFERENCE_PRFLX_TCP |
| 805 : ICE_TYPE_PREFERENCE_PRFLX; |
802 uint32_t prflx_priority = | 806 uint32_t prflx_priority = |
803 ICE_TYPE_PREFERENCE_PRFLX << 24 | | 807 type_preference << 24 | |
804 (connection_->local_candidate().priority() & 0x00FFFFFF); | 808 (connection_->local_candidate().priority() & 0x00FFFFFF); |
805 request->AddAttribute( | 809 request->AddAttribute( |
806 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); | 810 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); |
807 | 811 |
808 // Adding Message Integrity attribute. | 812 // Adding Message Integrity attribute. |
809 request->AddMessageIntegrity(connection_->remote_candidate().password()); | 813 request->AddMessageIntegrity(connection_->remote_candidate().password()); |
810 // Adding Fingerprint. | 814 // Adding Fingerprint. |
811 request->AddFingerprint(); | 815 request->AddFingerprint(); |
812 } | 816 } |
813 | 817 |
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1355 LOG_JV(sev, this) << "Received STUN ping response" | 1359 LOG_JV(sev, this) << "Received STUN ping response" |
1356 << ", id=" << rtc::hex_encode(request->id()) | 1360 << ", id=" << rtc::hex_encode(request->id()) |
1357 << ", code=0" // Makes logging easier to parse. | 1361 << ", code=0" // Makes logging easier to parse. |
1358 << ", rtt=" << rtt | 1362 << ", rtt=" << rtt |
1359 << ", pings_since_last_response=" << pings; | 1363 << ", pings_since_last_response=" << pings; |
1360 } | 1364 } |
1361 ReceivedPingResponse(rtt, request->id()); | 1365 ReceivedPingResponse(rtt, request->id()); |
1362 | 1366 |
1363 stats_.recv_ping_responses++; | 1367 stats_.recv_ping_responses++; |
1364 | 1368 |
1365 MaybeAddPrflxCandidate(request, response); | 1369 MaybeUpdateLocalCandidate(request, response); |
1366 } | 1370 } |
1367 | 1371 |
1368 void Connection::OnConnectionRequestErrorResponse(ConnectionRequest* request, | 1372 void Connection::OnConnectionRequestErrorResponse(ConnectionRequest* request, |
1369 StunMessage* response) { | 1373 StunMessage* response) { |
1370 const StunErrorCodeAttribute* error_attr = response->GetErrorCode(); | 1374 const StunErrorCodeAttribute* error_attr = response->GetErrorCode(); |
1371 int error_code = STUN_ERROR_GLOBAL_FAILURE; | 1375 int error_code = STUN_ERROR_GLOBAL_FAILURE; |
1372 if (error_attr) { | 1376 if (error_attr) { |
1373 error_code = error_attr->code(); | 1377 error_code = error_attr->code(); |
1374 } | 1378 } |
1375 | 1379 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1464 } | 1468 } |
1465 | 1469 |
1466 ConnectionInfo Connection::stats() { | 1470 ConnectionInfo Connection::stats() { |
1467 stats_.recv_bytes_second = round(recv_rate_tracker_.ComputeRate()); | 1471 stats_.recv_bytes_second = round(recv_rate_tracker_.ComputeRate()); |
1468 stats_.recv_total_bytes = recv_rate_tracker_.TotalSampleCount(); | 1472 stats_.recv_total_bytes = recv_rate_tracker_.TotalSampleCount(); |
1469 stats_.sent_bytes_second = round(send_rate_tracker_.ComputeRate()); | 1473 stats_.sent_bytes_second = round(send_rate_tracker_.ComputeRate()); |
1470 stats_.sent_total_bytes = send_rate_tracker_.TotalSampleCount(); | 1474 stats_.sent_total_bytes = send_rate_tracker_.TotalSampleCount(); |
1471 return stats_; | 1475 return stats_; |
1472 } | 1476 } |
1473 | 1477 |
1474 void Connection::MaybeAddPrflxCandidate(ConnectionRequest* request, | 1478 void Connection::MaybeUpdateLocalCandidate(ConnectionRequest* request, |
1475 StunMessage* response) { | 1479 StunMessage* response) { |
1476 // RFC 5245 | 1480 // RFC 5245 |
1477 // The agent checks the mapped address from the STUN response. If the | 1481 // The agent checks the mapped address from the STUN response. If the |
1478 // transport address does not match any of the local candidates that the | 1482 // transport address does not match any of the local candidates that the |
1479 // agent knows about, the mapped address represents a new candidate -- a | 1483 // agent knows about, the mapped address represents a new candidate -- a |
1480 // peer reflexive candidate. | 1484 // peer reflexive candidate. |
1481 const StunAddressAttribute* addr = | 1485 const StunAddressAttribute* addr = |
1482 response->GetAddress(STUN_ATTR_XOR_MAPPED_ADDRESS); | 1486 response->GetAddress(STUN_ATTR_XOR_MAPPED_ADDRESS); |
1483 if (!addr) { | 1487 if (!addr) { |
1484 LOG(LS_WARNING) << "Connection::OnConnectionRequestResponse - " | 1488 LOG(LS_WARNING) << "Connection::OnConnectionRequestResponse - " |
1485 << "No MAPPED-ADDRESS or XOR-MAPPED-ADDRESS found in the " | 1489 << "No MAPPED-ADDRESS or XOR-MAPPED-ADDRESS found in the " |
1486 << "stun response message"; | 1490 << "stun response message"; |
1487 return; | 1491 return; |
1488 } | 1492 } |
1489 | 1493 |
1490 bool known_addr = false; | |
1491 for (size_t i = 0; i < port_->Candidates().size(); ++i) { | 1494 for (size_t i = 0; i < port_->Candidates().size(); ++i) { |
1492 if (port_->Candidates()[i].address() == addr->GetAddress()) { | 1495 if (port_->Candidates()[i].address() == addr->GetAddress()) { |
1493 known_addr = true; | 1496 if (local_candidate_index_ != i) { |
1494 break; | 1497 LOG_J(LS_INFO, this) << "Updating local candidate type to srflx."; |
| 1498 local_candidate_index_ = i; |
| 1499 // SignalStateChange to force a re-sort in P2PTransportChannel as this |
| 1500 // Connection's local candidate has changed. |
| 1501 SignalStateChange(this); |
| 1502 } |
| 1503 return; |
1495 } | 1504 } |
1496 } | 1505 } |
1497 if (known_addr) { | |
1498 return; | |
1499 } | |
1500 | 1506 |
1501 // RFC 5245 | 1507 // RFC 5245 |
1502 // Its priority is set equal to the value of the PRIORITY attribute | 1508 // Its priority is set equal to the value of the PRIORITY attribute |
1503 // in the Binding request. | 1509 // in the Binding request. |
1504 const StunUInt32Attribute* priority_attr = | 1510 const StunUInt32Attribute* priority_attr = |
1505 request->msg()->GetUInt32(STUN_ATTR_PRIORITY); | 1511 request->msg()->GetUInt32(STUN_ATTR_PRIORITY); |
1506 if (!priority_attr) { | 1512 if (!priority_attr) { |
1507 LOG(LS_WARNING) << "Connection::OnConnectionRequestResponse - " | 1513 LOG(LS_WARNING) << "Connection::OnConnectionRequestResponse - " |
1508 << "No STUN_ATTR_PRIORITY found in the " | 1514 << "No STUN_ATTR_PRIORITY found in the " |
1509 << "stun response message"; | 1515 << "stun response message"; |
(...skipping 15 matching lines...) Expand all Loading... |
1525 new_local_candidate.set_network_type(local_candidate().network_type()); | 1531 new_local_candidate.set_network_type(local_candidate().network_type()); |
1526 new_local_candidate.set_related_address(local_candidate().address()); | 1532 new_local_candidate.set_related_address(local_candidate().address()); |
1527 new_local_candidate.set_generation(local_candidate().generation()); | 1533 new_local_candidate.set_generation(local_candidate().generation()); |
1528 new_local_candidate.set_foundation(ComputeFoundation( | 1534 new_local_candidate.set_foundation(ComputeFoundation( |
1529 PRFLX_PORT_TYPE, local_candidate().protocol(), | 1535 PRFLX_PORT_TYPE, local_candidate().protocol(), |
1530 local_candidate().relay_protocol(), local_candidate().address())); | 1536 local_candidate().relay_protocol(), local_candidate().address())); |
1531 new_local_candidate.set_network_id(local_candidate().network_id()); | 1537 new_local_candidate.set_network_id(local_candidate().network_id()); |
1532 new_local_candidate.set_network_cost(local_candidate().network_cost()); | 1538 new_local_candidate.set_network_cost(local_candidate().network_cost()); |
1533 | 1539 |
1534 // Change the local candidate of this Connection to the new prflx candidate. | 1540 // Change the local candidate of this Connection to the new prflx candidate. |
| 1541 LOG_J(LS_INFO, this) << "Updating local candidate type to prflx."; |
1535 local_candidate_index_ = port_->AddPrflxCandidate(new_local_candidate); | 1542 local_candidate_index_ = port_->AddPrflxCandidate(new_local_candidate); |
1536 | 1543 |
1537 // SignalStateChange to force a re-sort in P2PTransportChannel as this | 1544 // SignalStateChange to force a re-sort in P2PTransportChannel as this |
1538 // Connection's local candidate has changed. | 1545 // Connection's local candidate has changed. |
1539 SignalStateChange(this); | 1546 SignalStateChange(this); |
1540 } | 1547 } |
1541 | 1548 |
1542 bool Connection::rtt_converged() const { | 1549 bool Connection::rtt_converged() const { |
1543 return rtt_samples_ > (RTT_RATIO + 1); | 1550 return rtt_samples_ > (RTT_RATIO + 1); |
1544 } | 1551 } |
(...skipping 21 matching lines...) Expand all Loading... |
1566 ASSERT(sent < 0); | 1573 ASSERT(sent < 0); |
1567 error_ = port_->GetError(); | 1574 error_ = port_->GetError(); |
1568 stats_.sent_discarded_packets++; | 1575 stats_.sent_discarded_packets++; |
1569 } else { | 1576 } else { |
1570 send_rate_tracker_.AddSamples(sent); | 1577 send_rate_tracker_.AddSamples(sent); |
1571 } | 1578 } |
1572 return sent; | 1579 return sent; |
1573 } | 1580 } |
1574 | 1581 |
1575 } // namespace cricket | 1582 } // namespace cricket |
OLD | NEW |