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 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 last_ping_sent_(0), | 794 last_ping_sent_(0), |
795 last_ping_received_(0), | 795 last_ping_received_(0), |
796 last_data_received_(0), | 796 last_data_received_(0), |
797 last_ping_response_received_(0), | 797 last_ping_response_received_(0), |
798 recv_rate_tracker_(100u, 10u), | 798 recv_rate_tracker_(100u, 10u), |
799 send_rate_tracker_(100u, 10u), | 799 send_rate_tracker_(100u, 10u), |
800 sent_packets_discarded_(0), | 800 sent_packets_discarded_(0), |
801 sent_packets_total_(0), | 801 sent_packets_total_(0), |
802 reported_(false), | 802 reported_(false), |
803 state_(STATE_WAITING), | 803 state_(STATE_WAITING), |
804 receiving_timeout_(WEAK_CONNECTION_RECEIVE_TIMEOUT) { | 804 receiving_timeout_(WEAK_CONNECTION_RECEIVE_TIMEOUT), |
| 805 time_created_ms_(rtc::Time()) { |
805 // All of our connections start in WAITING state. | 806 // All of our connections start in WAITING state. |
806 // TODO(mallinath) - Start connections from STATE_FROZEN. | 807 // TODO(mallinath) - Start connections from STATE_FROZEN. |
807 // Wire up to send stun packets | 808 // Wire up to send stun packets |
808 requests_.SignalSendPacket.connect(this, &Connection::OnSendStunPacket); | 809 requests_.SignalSendPacket.connect(this, &Connection::OnSendStunPacket); |
809 LOG_J(LS_INFO, this) << "Connection created"; | 810 LOG_J(LS_INFO, this) << "Connection created"; |
810 } | 811 } |
811 | 812 |
812 Connection::~Connection() { | 813 Connection::~Connection() { |
813 } | 814 } |
814 | 815 |
(...skipping 27 matching lines...) Expand all Loading... |
842 return priority; | 843 return priority; |
843 } | 844 } |
844 | 845 |
845 void Connection::set_write_state(WriteState value) { | 846 void Connection::set_write_state(WriteState value) { |
846 WriteState old_value = write_state_; | 847 WriteState old_value = write_state_; |
847 write_state_ = value; | 848 write_state_ = value; |
848 if (value != old_value) { | 849 if (value != old_value) { |
849 LOG_J(LS_VERBOSE, this) << "set_write_state from: " << old_value << " to " | 850 LOG_J(LS_VERBOSE, this) << "set_write_state from: " << old_value << " to " |
850 << value; | 851 << value; |
851 SignalStateChange(this); | 852 SignalStateChange(this); |
852 CheckTimeout(); | |
853 } | 853 } |
854 } | 854 } |
855 | 855 |
856 void Connection::set_receiving(bool value) { | 856 void Connection::set_receiving(bool value) { |
857 if (value != receiving_) { | 857 if (value != receiving_) { |
858 LOG_J(LS_VERBOSE, this) << "set_receiving to " << value; | 858 LOG_J(LS_VERBOSE, this) << "set_receiving to " << value; |
859 receiving_ = value; | 859 receiving_ = value; |
860 SignalStateChange(this); | 860 SignalStateChange(this); |
861 CheckTimeout(); | |
862 } | 861 } |
863 } | 862 } |
864 | 863 |
865 void Connection::set_state(State state) { | 864 void Connection::set_state(State state) { |
866 State old_state = state_; | 865 State old_state = state_; |
867 state_ = state; | 866 state_ = state; |
868 if (state != old_state) { | 867 if (state != old_state) { |
869 LOG_J(LS_VERBOSE, this) << "set_state"; | 868 LOG_J(LS_VERBOSE, this) << "set_state"; |
870 } | 869 } |
871 } | 870 } |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1082 << now - pings_since_last_response_[0].sent_time | 1081 << now - pings_since_last_response_[0].sent_time |
1083 << " ms without a response" | 1082 << " ms without a response" |
1084 << ", rtt=" << rtt; | 1083 << ", rtt=" << rtt; |
1085 set_write_state(STATE_WRITE_TIMEOUT); | 1084 set_write_state(STATE_WRITE_TIMEOUT); |
1086 } | 1085 } |
1087 | 1086 |
1088 // Check the receiving state. | 1087 // Check the receiving state. |
1089 uint32 last_recv_time = last_received(); | 1088 uint32 last_recv_time = last_received(); |
1090 bool receiving = now <= last_recv_time + receiving_timeout_; | 1089 bool receiving = now <= last_recv_time + receiving_timeout_; |
1091 set_receiving(receiving); | 1090 set_receiving(receiving); |
| 1091 if (Dead(now)) { |
| 1092 Destroy(); |
| 1093 } |
1092 } | 1094 } |
1093 | 1095 |
1094 void Connection::Ping(uint32 now) { | 1096 void Connection::Ping(uint32 now) { |
1095 last_ping_sent_ = now; | 1097 last_ping_sent_ = now; |
1096 ConnectionRequest *req = new ConnectionRequest(this); | 1098 ConnectionRequest *req = new ConnectionRequest(this); |
1097 pings_since_last_response_.push_back(SentPing(req->id(), now)); | 1099 pings_since_last_response_.push_back(SentPing(req->id(), now)); |
1098 LOG_J(LS_VERBOSE, this) << "Sending STUN ping " | 1100 LOG_J(LS_VERBOSE, this) << "Sending STUN ping " |
1099 << ", id=" << rtc::hex_encode(req->id()); | 1101 << ", id=" << rtc::hex_encode(req->id()); |
1100 requests_.Send(req); | 1102 requests_.Send(req); |
1101 state_ = STATE_INPROGRESS; | 1103 state_ = STATE_INPROGRESS; |
(...skipping 10 matching lines...) Expand all Loading... |
1112 // So if we're not already, become writable. We may be bringing a pruned | 1114 // So if we're not already, become writable. We may be bringing a pruned |
1113 // connection back to life, but if we don't really want it, we can always | 1115 // connection back to life, but if we don't really want it, we can always |
1114 // prune it again. | 1116 // prune it again. |
1115 set_receiving(true); | 1117 set_receiving(true); |
1116 set_write_state(STATE_WRITABLE); | 1118 set_write_state(STATE_WRITABLE); |
1117 set_state(STATE_SUCCEEDED); | 1119 set_state(STATE_SUCCEEDED); |
1118 pings_since_last_response_.clear(); | 1120 pings_since_last_response_.clear(); |
1119 last_ping_response_received_ = rtc::Time(); | 1121 last_ping_response_received_ = rtc::Time(); |
1120 } | 1122 } |
1121 | 1123 |
| 1124 bool Connection::Dead(uint32 now) const { |
| 1125 if (now < (time_created_ms_ + MIN_CONNECTION_LIFETIME)) { |
| 1126 // A connection that hasn't passed its minimum lifetime is still alive. |
| 1127 // We do this to prevent connections from being pruned too quickly |
| 1128 // during a network change event when two networks would be up |
| 1129 // simultaneously but only for a brief period. |
| 1130 return false; |
| 1131 } |
| 1132 |
| 1133 if (receiving_) { |
| 1134 // A connection that is receiving is alive. |
| 1135 return false; |
| 1136 } |
| 1137 |
| 1138 // A connection is alive until it is inactive. |
| 1139 return !Active(); |
| 1140 |
| 1141 // TODO(honghaiz): Move from using the write state to using the receiving |
| 1142 // state with something like the following: |
| 1143 // return (now > (last_received() + DEAD_CONNECTION_RECEIVE_TIMEOUT)); |
| 1144 } |
| 1145 |
1122 std::string Connection::ToDebugId() const { | 1146 std::string Connection::ToDebugId() const { |
1123 std::stringstream ss; | 1147 std::stringstream ss; |
1124 ss << std::hex << this; | 1148 ss << std::hex << this; |
1125 return ss.str(); | 1149 return ss.str(); |
1126 } | 1150 } |
1127 | 1151 |
1128 std::string Connection::ToString() const { | 1152 std::string Connection::ToString() const { |
1129 const char CONNECT_STATE_ABBREV[2] = { | 1153 const char CONNECT_STATE_ABBREV[2] = { |
1130 '-', // not connected (false) | 1154 '-', // not connected (false) |
1131 'C', // connected (true) | 1155 'C', // connected (true) |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1244 | 1268 |
1245 void Connection::OnConnectionRequestSent(ConnectionRequest* request) { | 1269 void Connection::OnConnectionRequestSent(ConnectionRequest* request) { |
1246 // Log at LS_INFO if we send a ping on an unwritable connection. | 1270 // Log at LS_INFO if we send a ping on an unwritable connection. |
1247 rtc::LoggingSeverity sev = !writable() ? rtc::LS_INFO : rtc::LS_VERBOSE; | 1271 rtc::LoggingSeverity sev = !writable() ? rtc::LS_INFO : rtc::LS_VERBOSE; |
1248 bool use_candidate = use_candidate_attr(); | 1272 bool use_candidate = use_candidate_attr(); |
1249 LOG_JV(sev, this) << "Sent STUN ping" | 1273 LOG_JV(sev, this) << "Sent STUN ping" |
1250 << ", id=" << rtc::hex_encode(request->id()) | 1274 << ", id=" << rtc::hex_encode(request->id()) |
1251 << ", use_candidate=" << use_candidate; | 1275 << ", use_candidate=" << use_candidate; |
1252 } | 1276 } |
1253 | 1277 |
1254 void Connection::CheckTimeout() { | |
1255 // If write has timed out and it is not receiving, remove the connection. | |
1256 if (!receiving_ && write_state_ == STATE_WRITE_TIMEOUT) { | |
1257 Destroy(); | |
1258 } | |
1259 } | |
1260 | |
1261 void Connection::HandleRoleConflictFromPeer() { | 1278 void Connection::HandleRoleConflictFromPeer() { |
1262 port_->SignalRoleConflict(port_); | 1279 port_->SignalRoleConflict(port_); |
1263 } | 1280 } |
1264 | 1281 |
1265 void Connection::MaybeSetRemoteIceCredentials(const std::string& ice_ufrag, | 1282 void Connection::MaybeSetRemoteIceCredentials(const std::string& ice_ufrag, |
1266 const std::string& ice_pwd) { | 1283 const std::string& ice_pwd) { |
1267 if (remote_candidate_.username() == ice_ufrag && | 1284 if (remote_candidate_.username() == ice_ufrag && |
1268 remote_candidate_.password().empty()) { | 1285 remote_candidate_.password().empty()) { |
1269 remote_candidate_.set_password(ice_pwd); | 1286 remote_candidate_.set_password(ice_pwd); |
1270 } | 1287 } |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1402 ASSERT(sent < 0); | 1419 ASSERT(sent < 0); |
1403 error_ = port_->GetError(); | 1420 error_ = port_->GetError(); |
1404 sent_packets_discarded_++; | 1421 sent_packets_discarded_++; |
1405 } else { | 1422 } else { |
1406 send_rate_tracker_.AddSamples(sent); | 1423 send_rate_tracker_.AddSamples(sent); |
1407 } | 1424 } |
1408 return sent; | 1425 return sent; |
1409 } | 1426 } |
1410 | 1427 |
1411 } // namespace cricket | 1428 } // namespace cricket |
OLD | NEW |