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 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
861 pruned_(false), | 861 pruned_(false), |
862 use_candidate_attr_(false), | 862 use_candidate_attr_(false), |
863 remote_ice_mode_(ICEMODE_FULL), | 863 remote_ice_mode_(ICEMODE_FULL), |
864 requests_(port->thread()), | 864 requests_(port->thread()), |
865 rtt_(DEFAULT_RTT), | 865 rtt_(DEFAULT_RTT), |
866 last_ping_sent_(0), | 866 last_ping_sent_(0), |
867 last_ping_received_(0), | 867 last_ping_received_(0), |
868 last_data_received_(0), | 868 last_data_received_(0), |
869 last_ping_response_received_(0), | 869 last_ping_response_received_(0), |
870 reported_(false), | 870 reported_(false), |
871 state_(STATE_WAITING), | 871 state_(IceCandidatePairState::WAITING), |
872 receiving_timeout_(WEAK_CONNECTION_RECEIVE_TIMEOUT), | 872 receiving_timeout_(WEAK_CONNECTION_RECEIVE_TIMEOUT), |
873 time_created_ms_(rtc::TimeMillis()) { | 873 time_created_ms_(rtc::TimeMillis()) { |
874 // All of our connections start in WAITING state. | 874 // All of our connections start in WAITING state. |
875 // TODO(mallinath) - Start connections from STATE_FROZEN. | 875 // TODO(mallinath) - Start connections from STATE_FROZEN. |
876 // Wire up to send stun packets | 876 // Wire up to send stun packets |
877 requests_.SignalSendPacket.connect(this, &Connection::OnSendStunPacket); | 877 requests_.SignalSendPacket.connect(this, &Connection::OnSendStunPacket); |
878 LOG_J(LS_INFO, this) << "Connection created"; | 878 LOG_J(LS_INFO, this) << "Connection created"; |
879 } | 879 } |
880 | 880 |
881 Connection::~Connection() { | 881 Connection::~Connection() { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
930 last_received() > 0 && now <= last_received() + receiving_timeout_; | 930 last_received() > 0 && now <= last_received() + receiving_timeout_; |
931 if (receiving_ == receiving) { | 931 if (receiving_ == receiving) { |
932 return; | 932 return; |
933 } | 933 } |
934 LOG_J(LS_VERBOSE, this) << "set_receiving to " << receiving; | 934 LOG_J(LS_VERBOSE, this) << "set_receiving to " << receiving; |
935 receiving_ = receiving; | 935 receiving_ = receiving; |
936 receiving_unchanged_since_ = now; | 936 receiving_unchanged_since_ = now; |
937 SignalStateChange(this); | 937 SignalStateChange(this); |
938 } | 938 } |
939 | 939 |
940 void Connection::set_state(State state) { | 940 void Connection::set_state(IceCandidatePairState state) { |
941 State old_state = state_; | 941 IceCandidatePairState old_state = state_; |
942 state_ = state; | 942 state_ = state; |
943 if (state != old_state) { | 943 if (state != old_state) { |
944 LOG_J(LS_VERBOSE, this) << "set_state"; | 944 LOG_J(LS_VERBOSE, this) << "set_state"; |
945 } | 945 } |
946 } | 946 } |
947 | 947 |
948 void Connection::set_connected(bool value) { | 948 void Connection::set_connected(bool value) { |
949 bool old_value = connected_; | 949 bool old_value = connected_; |
950 connected_ = value; | 950 connected_ = value; |
951 if (value != old_value) { | 951 if (value != old_value) { |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1119 set_write_state(STATE_WRITE_TIMEOUT); | 1119 set_write_state(STATE_WRITE_TIMEOUT); |
1120 } | 1120 } |
1121 } | 1121 } |
1122 | 1122 |
1123 void Connection::Destroy() { | 1123 void Connection::Destroy() { |
1124 LOG_J(LS_VERBOSE, this) << "Connection destroyed"; | 1124 LOG_J(LS_VERBOSE, this) << "Connection destroyed"; |
1125 port_->thread()->Post(RTC_FROM_HERE, this, MSG_DELETE); | 1125 port_->thread()->Post(RTC_FROM_HERE, this, MSG_DELETE); |
1126 } | 1126 } |
1127 | 1127 |
1128 void Connection::FailAndDestroy() { | 1128 void Connection::FailAndDestroy() { |
1129 set_state(Connection::STATE_FAILED); | 1129 set_state(IceCandidatePairState::FAILED); |
1130 Destroy(); | 1130 Destroy(); |
1131 } | 1131 } |
1132 | 1132 |
1133 void Connection::FailAndPrune() { | 1133 void Connection::FailAndPrune() { |
1134 set_state(Connection::STATE_FAILED); | 1134 set_state(IceCandidatePairState::FAILED); |
1135 Prune(); | 1135 Prune(); |
1136 } | 1136 } |
1137 | 1137 |
1138 void Connection::PrintPingsSinceLastResponse(std::string* s, size_t max) { | 1138 void Connection::PrintPingsSinceLastResponse(std::string* s, size_t max) { |
1139 std::ostringstream oss; | 1139 std::ostringstream oss; |
1140 oss << std::boolalpha; | 1140 oss << std::boolalpha; |
1141 if (pings_since_last_response_.size() > max) { | 1141 if (pings_since_last_response_.size() > max) { |
1142 for (size_t i = 0; i < max; i++) { | 1142 for (size_t i = 0; i < max; i++) { |
1143 const SentPing& ping = pings_since_last_response_[i]; | 1143 const SentPing& ping = pings_since_last_response_[i]; |
1144 oss << rtc::hex_encode(ping.id) << " "; | 1144 oss << rtc::hex_encode(ping.id) << " "; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1216 } | 1216 } |
1217 | 1217 |
1218 void Connection::Ping(int64_t now) { | 1218 void Connection::Ping(int64_t now) { |
1219 last_ping_sent_ = now; | 1219 last_ping_sent_ = now; |
1220 ConnectionRequest *req = new ConnectionRequest(this); | 1220 ConnectionRequest *req = new ConnectionRequest(this); |
1221 pings_since_last_response_.push_back(SentPing(req->id(), now, nomination_)); | 1221 pings_since_last_response_.push_back(SentPing(req->id(), now, nomination_)); |
1222 LOG_J(LS_VERBOSE, this) << "Sending STUN ping " | 1222 LOG_J(LS_VERBOSE, this) << "Sending STUN ping " |
1223 << ", id=" << rtc::hex_encode(req->id()) | 1223 << ", id=" << rtc::hex_encode(req->id()) |
1224 << ", nomination=" << nomination_; | 1224 << ", nomination=" << nomination_; |
1225 requests_.Send(req); | 1225 requests_.Send(req); |
1226 state_ = STATE_INPROGRESS; | 1226 state_ = IceCandidatePairState::IN_PROGRESS; |
1227 num_pings_sent_++; | 1227 num_pings_sent_++; |
1228 } | 1228 } |
1229 | 1229 |
1230 void Connection::ReceivedPing() { | 1230 void Connection::ReceivedPing() { |
1231 last_ping_received_ = rtc::TimeMillis(); | 1231 last_ping_received_ = rtc::TimeMillis(); |
1232 UpdateReceiving(last_ping_received_); | 1232 UpdateReceiving(last_ping_received_); |
1233 } | 1233 } |
1234 | 1234 |
1235 void Connection::ReceivedPingResponse(int rtt, const std::string& request_id) { | 1235 void Connection::ReceivedPingResponse(int rtt, const std::string& request_id) { |
1236 // We've already validated that this is a STUN binding response with | 1236 // We've already validated that this is a STUN binding response with |
1237 // the correct local and remote username for this connection. | 1237 // the correct local and remote username for this connection. |
1238 // So if we're not already, become writable. We may be bringing a pruned | 1238 // So if we're not already, become writable. We may be bringing a pruned |
1239 // connection back to life, but if we don't really want it, we can always | 1239 // connection back to life, but if we don't really want it, we can always |
1240 // prune it again. | 1240 // prune it again. |
1241 auto iter = std::find_if( | 1241 auto iter = std::find_if( |
1242 pings_since_last_response_.begin(), pings_since_last_response_.end(), | 1242 pings_since_last_response_.begin(), pings_since_last_response_.end(), |
1243 [request_id](const SentPing& ping) { return ping.id == request_id; }); | 1243 [request_id](const SentPing& ping) { return ping.id == request_id; }); |
1244 if (iter != pings_since_last_response_.end() && | 1244 if (iter != pings_since_last_response_.end() && |
1245 iter->nomination > acked_nomination_) { | 1245 iter->nomination > acked_nomination_) { |
1246 acked_nomination_ = iter->nomination; | 1246 acked_nomination_ = iter->nomination; |
1247 } | 1247 } |
1248 | 1248 |
1249 pings_since_last_response_.clear(); | 1249 pings_since_last_response_.clear(); |
1250 last_ping_response_received_ = rtc::TimeMillis(); | 1250 last_ping_response_received_ = rtc::TimeMillis(); |
1251 UpdateReceiving(last_ping_response_received_); | 1251 UpdateReceiving(last_ping_response_received_); |
1252 set_write_state(STATE_WRITABLE); | 1252 set_write_state(STATE_WRITABLE); |
1253 set_state(STATE_SUCCEEDED); | 1253 set_state(IceCandidatePairState::SUCCEEDED); |
1254 rtt_samples_++; | 1254 rtt_samples_++; |
1255 rtt_ = (RTT_RATIO * rtt_ + rtt) / (RTT_RATIO + 1); | 1255 rtt_ = (RTT_RATIO * rtt_ + rtt) / (RTT_RATIO + 1); |
1256 } | 1256 } |
1257 | 1257 |
1258 bool Connection::dead(int64_t now) const { | 1258 bool Connection::dead(int64_t now) const { |
1259 if (last_received() > 0) { | 1259 if (last_received() > 0) { |
1260 // If it has ever received anything, we keep it alive until it hasn't | 1260 // If it has ever received anything, we keep it alive until it hasn't |
1261 // received anything for DEAD_CONNECTION_RECEIVE_TIMEOUT. This covers the | 1261 // received anything for DEAD_CONNECTION_RECEIVE_TIMEOUT. This covers the |
1262 // normal case of a successfully used connection that stops working. This | 1262 // normal case of a successfully used connection that stops working. This |
1263 // also allows a remote peer to continue pinging over a locally inactive | 1263 // also allows a remote peer to continue pinging over a locally inactive |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1324 const Candidate& remote = remote_candidate(); | 1324 const Candidate& remote = remote_candidate(); |
1325 std::stringstream ss; | 1325 std::stringstream ss; |
1326 ss << "Conn[" << ToDebugId() << ":" << port_->content_name() << ":" | 1326 ss << "Conn[" << ToDebugId() << ":" << port_->content_name() << ":" |
1327 << local.id() << ":" << local.component() << ":" << local.generation() | 1327 << local.id() << ":" << local.component() << ":" << local.generation() |
1328 << ":" << local.type() << ":" << local.protocol() << ":" | 1328 << ":" << local.type() << ":" << local.protocol() << ":" |
1329 << local.address().ToSensitiveString() << "->" << remote.id() << ":" | 1329 << local.address().ToSensitiveString() << "->" << remote.id() << ":" |
1330 << remote.component() << ":" << remote.priority() << ":" << remote.type() | 1330 << remote.component() << ":" << remote.priority() << ":" << remote.type() |
1331 << ":" << remote.protocol() << ":" << remote.address().ToSensitiveString() | 1331 << ":" << remote.protocol() << ":" << remote.address().ToSensitiveString() |
1332 << "|" << CONNECT_STATE_ABBREV[connected()] | 1332 << "|" << CONNECT_STATE_ABBREV[connected()] |
1333 << RECEIVE_STATE_ABBREV[receiving()] << WRITE_STATE_ABBREV[write_state()] | 1333 << RECEIVE_STATE_ABBREV[receiving()] << WRITE_STATE_ABBREV[write_state()] |
1334 << ICESTATE[state()] << "|" << remote_nomination() << "|" << nomination() | 1334 << ICESTATE[static_cast<int>(state())] << "|" << remote_nomination() << "|" |
1335 << "|" << priority() << "|"; | 1335 << nomination() << "|" << priority() << "|"; |
1336 if (rtt_ < DEFAULT_RTT) { | 1336 if (rtt_ < DEFAULT_RTT) { |
1337 ss << rtt_ << "]"; | 1337 ss << rtt_ << "]"; |
1338 } else { | 1338 } else { |
1339 ss << "-]"; | 1339 ss << "-]"; |
1340 } | 1340 } |
1341 return ss.str(); | 1341 return ss.str(); |
1342 } | 1342 } |
1343 | 1343 |
1344 std::string Connection::ToSensitiveString() const { | 1344 std::string Connection::ToSensitiveString() const { |
1345 return ToString(); | 1345 return ToString(); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1459 << num_pings_sent_; | 1459 << num_pings_sent_; |
1460 SignalDestroyed(this); | 1460 SignalDestroyed(this); |
1461 delete this; | 1461 delete this; |
1462 } | 1462 } |
1463 | 1463 |
1464 int64_t Connection::last_received() const { | 1464 int64_t Connection::last_received() const { |
1465 return std::max(last_data_received_, | 1465 return std::max(last_data_received_, |
1466 std::max(last_ping_received_, last_ping_response_received_)); | 1466 std::max(last_ping_received_, last_ping_response_received_)); |
1467 } | 1467 } |
1468 | 1468 |
1469 ConnectionInfo Connection::stats() { | 1469 ConnectionInfo Connection::stats(bool is_best_connection) { |
1470 stats_.recv_bytes_second = round(recv_rate_tracker_.ComputeRate()); | 1470 stats_.recv_bytes_second = round(recv_rate_tracker_.ComputeRate()); |
1471 stats_.recv_total_bytes = recv_rate_tracker_.TotalSampleCount(); | 1471 stats_.recv_total_bytes = recv_rate_tracker_.TotalSampleCount(); |
1472 stats_.sent_bytes_second = round(send_rate_tracker_.ComputeRate()); | 1472 stats_.sent_bytes_second = round(send_rate_tracker_.ComputeRate()); |
1473 stats_.sent_total_bytes = send_rate_tracker_.TotalSampleCount(); | 1473 stats_.sent_total_bytes = send_rate_tracker_.TotalSampleCount(); |
1474 stats_.best_connection = is_best_connection; | |
1475 stats_.receiving = receiving_; | |
1476 stats_.writable = write_state_ == STATE_WRITABLE; | |
1477 stats_.timeout = write_state_ == STATE_WRITE_TIMEOUT; | |
1478 stats_.new_connection = !reported_; | |
1479 stats_.rtt = rtt_; | |
1480 stats_.local_candidate = local_candidate(); | |
1481 stats_.remote_candidate = remote_candidate(); | |
1482 stats_.key = this; | |
1483 stats_.state = state_; | |
1484 stats_.priority = priority(); | |
hbos
2016/12/23 13:45:34
state + priority are the new ones, the rest was mo
| |
1474 return stats_; | 1485 return stats_; |
1475 } | 1486 } |
1476 | 1487 |
1477 void Connection::MaybeUpdateLocalCandidate(ConnectionRequest* request, | 1488 void Connection::MaybeUpdateLocalCandidate(ConnectionRequest* request, |
1478 StunMessage* response) { | 1489 StunMessage* response) { |
1479 // RFC 5245 | 1490 // RFC 5245 |
1480 // The agent checks the mapped address from the STUN response. If the | 1491 // The agent checks the mapped address from the STUN response. If the |
1481 // transport address does not match any of the local candidates that the | 1492 // transport address does not match any of the local candidates that the |
1482 // agent knows about, the mapped address represents a new candidate -- a | 1493 // agent knows about, the mapped address represents a new candidate -- a |
1483 // peer reflexive candidate. | 1494 // peer reflexive candidate. |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1572 ASSERT(sent < 0); | 1583 ASSERT(sent < 0); |
1573 error_ = port_->GetError(); | 1584 error_ = port_->GetError(); |
1574 stats_.sent_discarded_packets++; | 1585 stats_.sent_discarded_packets++; |
1575 } else { | 1586 } else { |
1576 send_rate_tracker_.AddSamples(sent); | 1587 send_rate_tracker_.AddSamples(sent); |
1577 } | 1588 } |
1578 return sent; | 1589 return sent; |
1579 } | 1590 } |
1580 | 1591 |
1581 } // namespace cricket | 1592 } // namespace cricket |
OLD | NEW |