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 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
943 void Connection::OnReadPacket( | 943 void Connection::OnReadPacket( |
944 const char* data, size_t size, const rtc::PacketTime& packet_time) { | 944 const char* data, size_t size, const rtc::PacketTime& packet_time) { |
945 std::unique_ptr<IceMessage> msg; | 945 std::unique_ptr<IceMessage> msg; |
946 std::string remote_ufrag; | 946 std::string remote_ufrag; |
947 const rtc::SocketAddress& addr(remote_candidate_.address()); | 947 const rtc::SocketAddress& addr(remote_candidate_.address()); |
948 if (!port_->GetStunMessage(data, size, addr, &msg, &remote_ufrag)) { | 948 if (!port_->GetStunMessage(data, size, addr, &msg, &remote_ufrag)) { |
949 // The packet did not parse as a valid STUN message | 949 // The packet did not parse as a valid STUN message |
950 // This is a data packet, pass it along. | 950 // This is a data packet, pass it along. |
951 set_receiving(true); | 951 set_receiving(true); |
952 last_data_received_ = rtc::TimeMillis(); | 952 last_data_received_ = rtc::TimeMillis(); |
953 if (first_received_since_channel_weak_ == 0) { | |
954 first_received_since_channel_weak_ = last_data_received_; | |
955 } | |
953 recv_rate_tracker_.AddSamples(size); | 956 recv_rate_tracker_.AddSamples(size); |
954 SignalReadPacket(this, data, size, packet_time); | 957 SignalReadPacket(this, data, size, packet_time); |
955 | 958 |
956 // If timed out sending writability checks, start up again | 959 // If timed out sending writability checks, start up again |
957 if (!pruned_ && (write_state_ == STATE_WRITE_TIMEOUT)) { | 960 if (!pruned_ && (write_state_ == STATE_WRITE_TIMEOUT)) { |
958 LOG(LS_WARNING) << "Received a data packet on a timed-out Connection. " | 961 LOG(LS_WARNING) << "Received a data packet on a timed-out Connection. " |
959 << "Resetting state to STATE_WRITE_INIT."; | 962 << "Resetting state to STATE_WRITE_INIT."; |
960 set_write_state(STATE_WRITE_INIT); | 963 set_write_state(STATE_WRITE_INIT); |
961 } | 964 } |
962 } else if (!msg) { | 965 } else if (!msg) { |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1181 LOG_J(LS_VERBOSE, this) << "Sending STUN ping " | 1184 LOG_J(LS_VERBOSE, this) << "Sending STUN ping " |
1182 << ", id=" << rtc::hex_encode(req->id()); | 1185 << ", id=" << rtc::hex_encode(req->id()); |
1183 requests_.Send(req); | 1186 requests_.Send(req); |
1184 state_ = STATE_INPROGRESS; | 1187 state_ = STATE_INPROGRESS; |
1185 num_pings_sent_++; | 1188 num_pings_sent_++; |
1186 } | 1189 } |
1187 | 1190 |
1188 void Connection::ReceivedPing() { | 1191 void Connection::ReceivedPing() { |
1189 set_receiving(true); | 1192 set_receiving(true); |
1190 last_ping_received_ = rtc::TimeMillis(); | 1193 last_ping_received_ = rtc::TimeMillis(); |
1194 if (first_received_since_channel_weak_ == 0) { | |
1195 first_received_since_channel_weak_ = last_ping_received_; | |
1196 } | |
1191 } | 1197 } |
1192 | 1198 |
1193 void Connection::ReceivedPingResponse(int rtt) { | 1199 void Connection::ReceivedPingResponse(int rtt) { |
1194 // We've already validated that this is a STUN binding response with | 1200 // We've already validated that this is a STUN binding response with |
1195 // the correct local and remote username for this connection. | 1201 // the correct local and remote username for this connection. |
1196 // So if we're not already, become writable. We may be bringing a pruned | 1202 // So if we're not already, become writable. We may be bringing a pruned |
1197 // connection back to life, but if we don't really want it, we can always | 1203 // connection back to life, but if we don't really want it, we can always |
1198 // prune it again. | 1204 // prune it again. |
1199 set_receiving(true); | 1205 set_receiving(true); |
1200 set_write_state(STATE_WRITABLE); | 1206 set_write_state(STATE_WRITABLE); |
1201 set_state(STATE_SUCCEEDED); | 1207 set_state(STATE_SUCCEEDED); |
1202 pings_since_last_response_.clear(); | 1208 pings_since_last_response_.clear(); |
1203 last_ping_response_received_ = rtc::TimeMillis(); | 1209 last_ping_response_received_ = rtc::TimeMillis(); |
1204 rtt_samples_++; | 1210 rtt_samples_++; |
1205 rtt_ = (RTT_RATIO * rtt_ + rtt) / (RTT_RATIO + 1); | 1211 rtt_ = (RTT_RATIO * rtt_ + rtt) / (RTT_RATIO + 1); |
1212 if (first_received_since_channel_weak_ == 0) { | |
1213 first_received_since_channel_weak_ = last_ping_response_received_; | |
1214 } | |
pthatcher1
2016/07/13 21:17:22
I think this would be more clear if we had a metho
honghaiz3
2016/07/14 04:54:20
Done. I think it does not matter what value is set
| |
1206 } | 1215 } |
1207 | 1216 |
1208 bool Connection::dead(int64_t now) const { | 1217 bool Connection::dead(int64_t now) const { |
1209 if (last_received() > 0) { | 1218 if (last_received() > 0) { |
1210 // If it has ever received anything, we keep it alive until it hasn't | 1219 // If it has ever received anything, we keep it alive until it hasn't |
1211 // received anything for DEAD_CONNECTION_RECEIVE_TIMEOUT. This covers the | 1220 // received anything for DEAD_CONNECTION_RECEIVE_TIMEOUT. This covers the |
1212 // normal case of a successfully used connection that stops working. This | 1221 // normal case of a successfully used connection that stops working. This |
1213 // also allows a remote peer to continue pinging over a locally inactive | 1222 // also allows a remote peer to continue pinging over a locally inactive |
1214 // (pruned) connection. | 1223 // (pruned) connection. |
1215 return (now > (last_received() + DEAD_CONNECTION_RECEIVE_TIMEOUT)); | 1224 return (now > (last_received() + DEAD_CONNECTION_RECEIVE_TIMEOUT)); |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1529 ASSERT(sent < 0); | 1538 ASSERT(sent < 0); |
1530 error_ = port_->GetError(); | 1539 error_ = port_->GetError(); |
1531 stats_.sent_discarded_packets++; | 1540 stats_.sent_discarded_packets++; |
1532 } else { | 1541 } else { |
1533 send_rate_tracker_.AddSamples(sent); | 1542 send_rate_tracker_.AddSamples(sent); |
1534 } | 1543 } |
1535 return sent; | 1544 return sent; |
1536 } | 1545 } |
1537 | 1546 |
1538 } // namespace cricket | 1547 } // namespace cricket |
OLD | NEW |