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 CheckTimeout(now); | |
1092 } | 1092 } |
1093 | 1093 |
1094 void Connection::Ping(uint32 now) { | 1094 void Connection::Ping(uint32 now) { |
1095 last_ping_sent_ = now; | 1095 last_ping_sent_ = now; |
1096 ConnectionRequest *req = new ConnectionRequest(this); | 1096 ConnectionRequest *req = new ConnectionRequest(this); |
1097 pings_since_last_response_.push_back(SentPing(req->id(), now)); | 1097 pings_since_last_response_.push_back(SentPing(req->id(), now)); |
1098 LOG_J(LS_VERBOSE, this) << "Sending STUN ping " | 1098 LOG_J(LS_VERBOSE, this) << "Sending STUN ping " |
1099 << ", id=" << rtc::hex_encode(req->id()); | 1099 << ", id=" << rtc::hex_encode(req->id()); |
1100 requests_.Send(req); | 1100 requests_.Send(req); |
1101 state_ = STATE_INPROGRESS; | 1101 state_ = STATE_INPROGRESS; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1223 // Recoverable error, retry | 1223 // Recoverable error, retry |
1224 } else if (error_code == STUN_ERROR_STALE_CREDENTIALS) { | 1224 } else if (error_code == STUN_ERROR_STALE_CREDENTIALS) { |
1225 // Race failure, retry | 1225 // Race failure, retry |
1226 } else if (error_code == STUN_ERROR_ROLE_CONFLICT) { | 1226 } else if (error_code == STUN_ERROR_ROLE_CONFLICT) { |
1227 HandleRoleConflictFromPeer(); | 1227 HandleRoleConflictFromPeer(); |
1228 } else { | 1228 } else { |
1229 // This is not a valid connection. | 1229 // This is not a valid connection. |
1230 LOG_J(LS_ERROR, this) << "Received STUN error response, code=" | 1230 LOG_J(LS_ERROR, this) << "Received STUN error response, code=" |
1231 << error_code << "; killing connection"; | 1231 << error_code << "; killing connection"; |
1232 set_state(STATE_FAILED); | 1232 set_state(STATE_FAILED); |
1233 set_write_state(STATE_WRITE_TIMEOUT); | 1233 set_write_state(STATE_WRITE_TIMEOUT); |
pthatcher1
2015/09/28 23:07:27
Should just Destroy here? We probably don't want
pthatcher1
2015/09/29 19:51:32
?
honghaiz3
2015/09/29 20:40:42
Ah. can destroy here.
| |
1234 } | 1234 } |
1235 } | 1235 } |
1236 | 1236 |
1237 void Connection::OnConnectionRequestTimeout(ConnectionRequest* request) { | 1237 void Connection::OnConnectionRequestTimeout(ConnectionRequest* request) { |
1238 // Log at LS_INFO if we miss a ping on a writable connection. | 1238 // Log at LS_INFO if we miss a ping on a writable connection. |
1239 rtc::LoggingSeverity sev = writable() ? rtc::LS_INFO : rtc::LS_VERBOSE; | 1239 rtc::LoggingSeverity sev = writable() ? rtc::LS_INFO : rtc::LS_VERBOSE; |
1240 LOG_JV(sev, this) << "Timing-out STUN ping " | 1240 LOG_JV(sev, this) << "Timing-out STUN ping " |
1241 << rtc::hex_encode(request->id()) | 1241 << rtc::hex_encode(request->id()) |
1242 << " after " << request->Elapsed() << " ms"; | 1242 << " after " << request->Elapsed() << " ms"; |
1243 } | 1243 } |
1244 | 1244 |
1245 void Connection::OnConnectionRequestSent(ConnectionRequest* request) { | 1245 void Connection::OnConnectionRequestSent(ConnectionRequest* request) { |
1246 // Log at LS_INFO if we send a ping on an unwritable connection. | 1246 // Log at LS_INFO if we send a ping on an unwritable connection. |
1247 rtc::LoggingSeverity sev = !writable() ? rtc::LS_INFO : rtc::LS_VERBOSE; | 1247 rtc::LoggingSeverity sev = !writable() ? rtc::LS_INFO : rtc::LS_VERBOSE; |
1248 bool use_candidate = use_candidate_attr(); | 1248 bool use_candidate = use_candidate_attr(); |
1249 LOG_JV(sev, this) << "Sent STUN ping" | 1249 LOG_JV(sev, this) << "Sent STUN ping" |
1250 << ", id=" << rtc::hex_encode(request->id()) | 1250 << ", id=" << rtc::hex_encode(request->id()) |
1251 << ", use_candidate=" << use_candidate; | 1251 << ", use_candidate=" << use_candidate; |
1252 } | 1252 } |
1253 | 1253 |
1254 void Connection::CheckTimeout() { | 1254 void Connection::CheckTimeout(uint32 now) { |
pthatcher1
2015/09/28 23:07:27
If this is now called in only one place, why not r
honghaiz3
2015/09/29 18:47:50
Done.
| |
1255 // If write has timed out and it is not receiving, remove the connection. | |
1256 if (!receiving_ && write_state_ == STATE_WRITE_TIMEOUT) { | 1255 if (!receiving_ && write_state_ == STATE_WRITE_TIMEOUT) { |
1257 Destroy(); | 1256 // Remove the connection only if it has timed out on writing and it has |
1257 // not received anything for a long time. If the connection has never | |
1258 // received anything before, |last_received()| will return 0. In this case, | |
1259 // use the connection creation time as the base to compute the timeout. | |
pthatcher1
2015/09/28 23:07:27
I think this comment ought to say something more l
honghaiz3
2015/09/29 18:47:49
Done.
| |
1260 uint32 base_for_timeout = std::max(time_created_ms_, last_received()); | |
pthatcher1
2015/09/28 23:07:27
I think call this "receiving_deadline" would be a
honghaiz3
2015/09/29 18:47:50
Done.
| |
1261 if (now > base_for_timeout + DEAD_CONNECTION_RECEIVE_TIMEOUT) { | |
1262 Destroy(); | |
1263 } | |
1258 } | 1264 } |
pthatcher1
2015/09/28 23:07:27
This would be more clear with early returns.
honghaiz3
2015/09/29 18:47:49
Done.
| |
1259 } | 1265 } |
pthatcher1
2015/09/28 23:07:27
I think this would be more clear with a helper met
honghaiz3
2015/09/29 18:47:50
Done.
| |
1260 | 1266 |
1261 void Connection::HandleRoleConflictFromPeer() { | 1267 void Connection::HandleRoleConflictFromPeer() { |
1262 port_->SignalRoleConflict(port_); | 1268 port_->SignalRoleConflict(port_); |
1263 } | 1269 } |
1264 | 1270 |
1265 void Connection::MaybeSetRemoteIceCredentials(const std::string& ice_ufrag, | 1271 void Connection::MaybeSetRemoteIceCredentials(const std::string& ice_ufrag, |
1266 const std::string& ice_pwd) { | 1272 const std::string& ice_pwd) { |
1267 if (remote_candidate_.username() == ice_ufrag && | 1273 if (remote_candidate_.username() == ice_ufrag && |
1268 remote_candidate_.password().empty()) { | 1274 remote_candidate_.password().empty()) { |
1269 remote_candidate_.set_password(ice_pwd); | 1275 remote_candidate_.set_password(ice_pwd); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1402 ASSERT(sent < 0); | 1408 ASSERT(sent < 0); |
1403 error_ = port_->GetError(); | 1409 error_ = port_->GetError(); |
1404 sent_packets_discarded_++; | 1410 sent_packets_discarded_++; |
1405 } else { | 1411 } else { |
1406 send_rate_tracker_.AddSamples(sent); | 1412 send_rate_tracker_.AddSamples(sent); |
1407 } | 1413 } |
1408 return sent; | 1414 return sent; |
1409 } | 1415 } |
1410 | 1416 |
1411 } // namespace cricket | 1417 } // namespace cricket |
OLD | NEW |