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 938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
949 std::string remote_ufrag; | 949 std::string remote_ufrag; |
950 const rtc::SocketAddress& addr(remote_candidate_.address()); | 950 const rtc::SocketAddress& addr(remote_candidate_.address()); |
951 if (!port_->GetStunMessage(data, size, addr, &msg, &remote_ufrag)) { | 951 if (!port_->GetStunMessage(data, size, addr, &msg, &remote_ufrag)) { |
952 // The packet did not parse as a valid STUN message | 952 // The packet did not parse as a valid STUN message |
953 // This is a data packet, pass it along. | 953 // This is a data packet, pass it along. |
954 set_receiving(true); | 954 set_receiving(true); |
955 last_data_received_ = rtc::TimeMillis(); | 955 last_data_received_ = rtc::TimeMillis(); |
956 recv_rate_tracker_.AddSamples(size); | 956 recv_rate_tracker_.AddSamples(size); |
957 SignalReadPacket(this, data, size, packet_time); | 957 SignalReadPacket(this, data, size, packet_time); |
958 | 958 |
959 // If timed out sending writability checks, start up again | 959 // If the connection has timed out, it might be because it was pruned or |
960 if (!pruned_ && (write_state_ == STATE_WRITE_TIMEOUT)) { | 960 // it failed the writability check. Start it up again if it was not pruned |
961 // (so it is due to writability check failure), or it was pruned but it has | |
962 // been nominated by the controlling side. | |
pthatcher1
2016/06/22 19:18:37
Perhaps the wording could be thus:
If writability
honghaiz3
2016/06/22 20:01:24
All changes here are removed.
Acknowledged.
| |
963 if (write_state_ == STATE_WRITE_TIMEOUT && (nominated() || !pruned_)) { | |
961 LOG(LS_WARNING) << "Received a data packet on a timed-out Connection. " | 964 LOG(LS_WARNING) << "Received a data packet on a timed-out Connection. " |
962 << "Resetting state to STATE_WRITE_INIT."; | 965 << "Resetting state to STATE_WRITE_INIT."; |
963 set_write_state(STATE_WRITE_INIT); | 966 ResetWriteStateAndUnprune(); |
pthatcher1
2016/06/22 19:18:37
Even though I corrected the comment, I don't under
honghaiz3
2016/06/22 20:01:24
Acknowledged.
| |
964 } | 967 } |
965 } else if (!msg) { | 968 } else if (!msg) { |
966 // The packet was STUN, but failed a check and was handled internally. | 969 // The packet was STUN, but failed a check and was handled internally. |
967 } else { | 970 } else { |
968 // The packet is STUN and passed the Port checks. | 971 // The packet is STUN and passed the Port checks. |
969 // Perform our own checks to ensure this packet is valid. | 972 // Perform our own checks to ensure this packet is valid. |
970 // If this is a STUN request, then update the receiving bit and respond. | 973 // If this is a STUN request, then update the receiving bit and respond. |
971 // If this is a STUN response, then update the writable bit. | 974 // If this is a STUN response, then update the writable bit. |
972 // Log at LS_INFO if we receive a ping on an unwritable connection. | 975 // Log at LS_INFO if we receive a ping on an unwritable connection. |
973 rtc::LoggingSeverity sev = (!writable() ? rtc::LS_INFO : rtc::LS_VERBOSE); | 976 rtc::LoggingSeverity sev = (!writable() ? rtc::LS_INFO : rtc::LS_VERBOSE); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1028 // Received conflicting role from the peer. | 1031 // Received conflicting role from the peer. |
1029 LOG(LS_INFO) << "Received conflicting role from the peer."; | 1032 LOG(LS_INFO) << "Received conflicting role from the peer."; |
1030 return; | 1033 return; |
1031 } | 1034 } |
1032 | 1035 |
1033 stats_.recv_ping_requests++; | 1036 stats_.recv_ping_requests++; |
1034 | 1037 |
1035 // This is a validated stun request from remote peer. | 1038 // This is a validated stun request from remote peer. |
1036 port_->SendBindingResponse(msg, remote_addr); | 1039 port_->SendBindingResponse(msg, remote_addr); |
1037 | 1040 |
1038 // If it timed out on writing check, start up again | 1041 bool nominated = false; |
1039 if (!pruned_ && write_state_ == STATE_WRITE_TIMEOUT) { | |
1040 set_write_state(STATE_WRITE_INIT); | |
1041 } | |
1042 | |
1043 if (port_->GetIceRole() == ICEROLE_CONTROLLED) { | 1042 if (port_->GetIceRole() == ICEROLE_CONTROLLED) { |
1044 const StunByteStringAttribute* use_candidate_attr = | 1043 bool nominated = msg->GetByteString(STUN_ATTR_USE_CANDIDATE) != nullptr; |
pthatcher1
2016/06/22 19:18:37
You are making the variable, so the outer |nominat
honghaiz3
2016/06/22 20:01:24
Sorry for the mistake.
That means the Unprune is
| |
1045 msg->GetByteString(STUN_ATTR_USE_CANDIDATE); | 1044 if (nominated) { |
1046 if (use_candidate_attr) { | |
1047 set_nominated(true); | 1045 set_nominated(true); |
1048 SignalNominated(this); | 1046 SignalNominated(this); |
1049 } | 1047 } |
1050 } | 1048 } |
1049 // If it timed out on writing check, start up again if it is not pruned or | |
1050 // it is just nominated now, because the nomination may increase its priority | |
1051 // in the pruning process. | |
1052 if (write_state_ == STATE_WRITE_TIMEOUT && (nominated || !pruned_)) { | |
1053 ResetWriteStateAndUnprune(); | |
1054 } | |
pthatcher1
2016/06/22 19:18:37
When the controlling side is aggressive *all* the
honghaiz3
2016/06/22 20:01:24
Acknowledged.
| |
1055 | |
1051 // Set the remote cost if the network_info attribute is available. | 1056 // Set the remote cost if the network_info attribute is available. |
1052 // Note: If packets are re-ordered, we may get incorrect network cost | 1057 // Note: If packets are re-ordered, we may get incorrect network cost |
1053 // temporarily, but it should get the correct value shortly after that. | 1058 // temporarily, but it should get the correct value shortly after that. |
1054 const StunUInt32Attribute* network_attr = | 1059 const StunUInt32Attribute* network_attr = |
1055 msg->GetUInt32(STUN_ATTR_NETWORK_INFO); | 1060 msg->GetUInt32(STUN_ATTR_NETWORK_INFO); |
1056 if (network_attr) { | 1061 if (network_attr) { |
1057 uint32_t network_info = network_attr->value(); | 1062 uint32_t network_info = network_attr->value(); |
1058 uint16_t network_cost = static_cast<uint16_t>(network_info); | 1063 uint16_t network_cost = static_cast<uint16_t>(network_info); |
1059 if (network_cost != remote_candidate_.network_cost()) { | 1064 if (network_cost != remote_candidate_.network_cost()) { |
1060 remote_candidate_.set_network_cost(network_cost); | 1065 remote_candidate_.set_network_cost(network_cost); |
(...skipping 13 matching lines...) Expand all Loading... | |
1074 void Connection::Prune() { | 1079 void Connection::Prune() { |
1075 if (!pruned_ || active()) { | 1080 if (!pruned_ || active()) { |
1076 LOG_J(LS_INFO, this) << "Connection pruned"; | 1081 LOG_J(LS_INFO, this) << "Connection pruned"; |
1077 pruned_ = true; | 1082 pruned_ = true; |
1078 requests_.Clear(); | 1083 requests_.Clear(); |
1079 set_write_state(STATE_WRITE_TIMEOUT); | 1084 set_write_state(STATE_WRITE_TIMEOUT); |
1080 } | 1085 } |
1081 } | 1086 } |
1082 | 1087 |
1083 void Connection::Destroy() { | 1088 void Connection::Destroy() { |
1084 LOG_J(LS_VERBOSE, this) << "Connection destroyed"; | |
1085 port_->thread()->Post(RTC_FROM_HERE, this, MSG_DELETE); | 1089 port_->thread()->Post(RTC_FROM_HERE, this, MSG_DELETE); |
1086 } | 1090 } |
1087 | 1091 |
1088 void Connection::FailAndDestroy() { | 1092 void Connection::FailAndDestroy() { |
1089 set_state(Connection::STATE_FAILED); | 1093 set_state(Connection::STATE_FAILED); |
1090 Destroy(); | 1094 Destroy(); |
1091 } | 1095 } |
1092 | 1096 |
1093 void Connection::PrintPingsSinceLastResponse(std::string* s, size_t max) { | 1097 void Connection::PrintPingsSinceLastResponse(std::string* s, size_t max) { |
1094 std::ostringstream oss; | 1098 std::ostringstream oss; |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1417 << num_pings_sent_; | 1421 << num_pings_sent_; |
1418 SignalDestroyed(this); | 1422 SignalDestroyed(this); |
1419 delete this; | 1423 delete this; |
1420 } | 1424 } |
1421 | 1425 |
1422 int64_t Connection::last_received() const { | 1426 int64_t Connection::last_received() const { |
1423 return std::max(last_data_received_, | 1427 return std::max(last_data_received_, |
1424 std::max(last_ping_received_, last_ping_response_received_)); | 1428 std::max(last_ping_received_, last_ping_response_received_)); |
1425 } | 1429 } |
1426 | 1430 |
1431 void Connection::ResetWriteStateAndUnprune() { | |
1432 write_state_ = STATE_WRITE_INIT; | |
1433 LOG_J(INFO, this) << "Connection unpruned"; | |
1434 if (pruned_) { | |
1435 pruned_ = false; | |
1436 } | |
1437 } | |
1438 | |
1427 ConnectionInfo Connection::stats() { | 1439 ConnectionInfo Connection::stats() { |
1428 stats_.recv_bytes_second = round(recv_rate_tracker_.ComputeRate()); | 1440 stats_.recv_bytes_second = round(recv_rate_tracker_.ComputeRate()); |
1429 stats_.recv_total_bytes = recv_rate_tracker_.TotalSampleCount(); | 1441 stats_.recv_total_bytes = recv_rate_tracker_.TotalSampleCount(); |
1430 stats_.sent_bytes_second = round(send_rate_tracker_.ComputeRate()); | 1442 stats_.sent_bytes_second = round(send_rate_tracker_.ComputeRate()); |
1431 stats_.sent_total_bytes = send_rate_tracker_.TotalSampleCount(); | 1443 stats_.sent_total_bytes = send_rate_tracker_.TotalSampleCount(); |
1432 return stats_; | 1444 return stats_; |
1433 } | 1445 } |
1434 | 1446 |
1435 void Connection::MaybeAddPrflxCandidate(ConnectionRequest* request, | 1447 void Connection::MaybeAddPrflxCandidate(ConnectionRequest* request, |
1436 StunMessage* response) { | 1448 StunMessage* response) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1530 ASSERT(sent < 0); | 1542 ASSERT(sent < 0); |
1531 error_ = port_->GetError(); | 1543 error_ = port_->GetError(); |
1532 stats_.sent_discarded_packets++; | 1544 stats_.sent_discarded_packets++; |
1533 } else { | 1545 } else { |
1534 send_rate_tracker_.AddSamples(sent); | 1546 send_rate_tracker_.AddSamples(sent); |
1535 } | 1547 } |
1536 return sent; | 1548 return sent; |
1537 } | 1549 } |
1538 | 1550 |
1539 } // namespace cricket | 1551 } // namespace cricket |
OLD | NEW |