| 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 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 last_ping_received_(0), | 790 last_ping_received_(0), |
| 791 last_data_received_(0), | 791 last_data_received_(0), |
| 792 last_ping_response_received_(0), | 792 last_ping_response_received_(0), |
| 793 recv_rate_tracker_(100u, 10u), | 793 recv_rate_tracker_(100u, 10u), |
| 794 send_rate_tracker_(100u, 10u), | 794 send_rate_tracker_(100u, 10u), |
| 795 sent_packets_discarded_(0), | 795 sent_packets_discarded_(0), |
| 796 sent_packets_total_(0), | 796 sent_packets_total_(0), |
| 797 reported_(false), | 797 reported_(false), |
| 798 state_(STATE_WAITING), | 798 state_(STATE_WAITING), |
| 799 receiving_timeout_(WEAK_CONNECTION_RECEIVE_TIMEOUT), | 799 receiving_timeout_(WEAK_CONNECTION_RECEIVE_TIMEOUT), |
| 800 time_created_ms_(rtc::Time64()) { | 800 time_created_ms_(rtc::TimeMillis()) { |
| 801 // All of our connections start in WAITING state. | 801 // All of our connections start in WAITING state. |
| 802 // TODO(mallinath) - Start connections from STATE_FROZEN. | 802 // TODO(mallinath) - Start connections from STATE_FROZEN. |
| 803 // Wire up to send stun packets | 803 // Wire up to send stun packets |
| 804 requests_.SignalSendPacket.connect(this, &Connection::OnSendStunPacket); | 804 requests_.SignalSendPacket.connect(this, &Connection::OnSendStunPacket); |
| 805 LOG_J(LS_INFO, this) << "Connection created"; | 805 LOG_J(LS_INFO, this) << "Connection created"; |
| 806 } | 806 } |
| 807 | 807 |
| 808 Connection::~Connection() { | 808 Connection::~Connection() { |
| 809 } | 809 } |
| 810 | 810 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 | 895 |
| 896 void Connection::OnReadPacket( | 896 void Connection::OnReadPacket( |
| 897 const char* data, size_t size, const rtc::PacketTime& packet_time) { | 897 const char* data, size_t size, const rtc::PacketTime& packet_time) { |
| 898 rtc::scoped_ptr<IceMessage> msg; | 898 rtc::scoped_ptr<IceMessage> msg; |
| 899 std::string remote_ufrag; | 899 std::string remote_ufrag; |
| 900 const rtc::SocketAddress& addr(remote_candidate_.address()); | 900 const rtc::SocketAddress& addr(remote_candidate_.address()); |
| 901 if (!port_->GetStunMessage(data, size, addr, &msg, &remote_ufrag)) { | 901 if (!port_->GetStunMessage(data, size, addr, &msg, &remote_ufrag)) { |
| 902 // The packet did not parse as a valid STUN message | 902 // The packet did not parse as a valid STUN message |
| 903 // This is a data packet, pass it along. | 903 // This is a data packet, pass it along. |
| 904 set_receiving(true); | 904 set_receiving(true); |
| 905 last_data_received_ = rtc::Time64(); | 905 last_data_received_ = rtc::TimeMillis(); |
| 906 recv_rate_tracker_.AddSamples(size); | 906 recv_rate_tracker_.AddSamples(size); |
| 907 SignalReadPacket(this, data, size, packet_time); | 907 SignalReadPacket(this, data, size, packet_time); |
| 908 | 908 |
| 909 // If timed out sending writability checks, start up again | 909 // If timed out sending writability checks, start up again |
| 910 if (!pruned_ && (write_state_ == STATE_WRITE_TIMEOUT)) { | 910 if (!pruned_ && (write_state_ == STATE_WRITE_TIMEOUT)) { |
| 911 LOG(LS_WARNING) << "Received a data packet on a timed-out Connection. " | 911 LOG(LS_WARNING) << "Received a data packet on a timed-out Connection. " |
| 912 << "Resetting state to STATE_WRITE_INIT."; | 912 << "Resetting state to STATE_WRITE_INIT."; |
| 913 set_write_state(STATE_WRITE_INIT); | 913 set_write_state(STATE_WRITE_INIT); |
| 914 } | 914 } |
| 915 } else if (!msg) { | 915 } else if (!msg) { |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1110 ConnectionRequest *req = new ConnectionRequest(this); | 1110 ConnectionRequest *req = new ConnectionRequest(this); |
| 1111 pings_since_last_response_.push_back(SentPing(req->id(), now)); | 1111 pings_since_last_response_.push_back(SentPing(req->id(), now)); |
| 1112 LOG_J(LS_VERBOSE, this) << "Sending STUN ping " | 1112 LOG_J(LS_VERBOSE, this) << "Sending STUN ping " |
| 1113 << ", id=" << rtc::hex_encode(req->id()); | 1113 << ", id=" << rtc::hex_encode(req->id()); |
| 1114 requests_.Send(req); | 1114 requests_.Send(req); |
| 1115 state_ = STATE_INPROGRESS; | 1115 state_ = STATE_INPROGRESS; |
| 1116 } | 1116 } |
| 1117 | 1117 |
| 1118 void Connection::ReceivedPing() { | 1118 void Connection::ReceivedPing() { |
| 1119 set_receiving(true); | 1119 set_receiving(true); |
| 1120 last_ping_received_ = rtc::Time64(); | 1120 last_ping_received_ = rtc::TimeMillis(); |
| 1121 } | 1121 } |
| 1122 | 1122 |
| 1123 void Connection::ReceivedPingResponse() { | 1123 void Connection::ReceivedPingResponse() { |
| 1124 // We've already validated that this is a STUN binding response with | 1124 // We've already validated that this is a STUN binding response with |
| 1125 // the correct local and remote username for this connection. | 1125 // the correct local and remote username for this connection. |
| 1126 // So if we're not already, become writable. We may be bringing a pruned | 1126 // So if we're not already, become writable. We may be bringing a pruned |
| 1127 // connection back to life, but if we don't really want it, we can always | 1127 // connection back to life, but if we don't really want it, we can always |
| 1128 // prune it again. | 1128 // prune it again. |
| 1129 set_receiving(true); | 1129 set_receiving(true); |
| 1130 set_write_state(STATE_WRITABLE); | 1130 set_write_state(STATE_WRITABLE); |
| 1131 set_state(STATE_SUCCEEDED); | 1131 set_state(STATE_SUCCEEDED); |
| 1132 pings_since_last_response_.clear(); | 1132 pings_since_last_response_.clear(); |
| 1133 last_ping_response_received_ = rtc::Time64(); | 1133 last_ping_response_received_ = rtc::TimeMillis(); |
| 1134 } | 1134 } |
| 1135 | 1135 |
| 1136 bool Connection::dead(int64_t now) const { | 1136 bool Connection::dead(int64_t now) const { |
| 1137 if (last_received() > 0) { | 1137 if (last_received() > 0) { |
| 1138 // If it has ever received anything, we keep it alive until it hasn't | 1138 // If it has ever received anything, we keep it alive until it hasn't |
| 1139 // received anything for DEAD_CONNECTION_RECEIVE_TIMEOUT. This covers the | 1139 // received anything for DEAD_CONNECTION_RECEIVE_TIMEOUT. This covers the |
| 1140 // normal case of a successfully used connection that stops working. This | 1140 // normal case of a successfully used connection that stops working. This |
| 1141 // also allows a remote peer to continue pinging over a locally inactive | 1141 // also allows a remote peer to continue pinging over a locally inactive |
| 1142 // (pruned) connection. | 1142 // (pruned) connection. |
| 1143 return (now > (last_received() + DEAD_CONNECTION_RECEIVE_TIMEOUT)); | 1143 return (now > (last_received() + DEAD_CONNECTION_RECEIVE_TIMEOUT)); |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1450 ASSERT(sent < 0); | 1450 ASSERT(sent < 0); |
| 1451 error_ = port_->GetError(); | 1451 error_ = port_->GetError(); |
| 1452 sent_packets_discarded_++; | 1452 sent_packets_discarded_++; |
| 1453 } else { | 1453 } else { |
| 1454 send_rate_tracker_.AddSamples(sent); | 1454 send_rate_tracker_.AddSamples(sent); |
| 1455 } | 1455 } |
| 1456 return sent; | 1456 return sent; |
| 1457 } | 1457 } |
| 1458 | 1458 |
| 1459 } // namespace cricket | 1459 } // namespace cricket |
| OLD | NEW |