| 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 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 } else { | 587 } else { |
| 588 // Log at LS_INFO if we send a stun ping response on an unwritable | 588 // Log at LS_INFO if we send a stun ping response on an unwritable |
| 589 // connection. | 589 // connection. |
| 590 Connection* conn = GetConnection(addr); | 590 Connection* conn = GetConnection(addr); |
| 591 rtc::LoggingSeverity sev = (conn && !conn->writable()) ? | 591 rtc::LoggingSeverity sev = (conn && !conn->writable()) ? |
| 592 rtc::LS_INFO : rtc::LS_VERBOSE; | 592 rtc::LS_INFO : rtc::LS_VERBOSE; |
| 593 LOG_JV(sev, this) | 593 LOG_JV(sev, this) |
| 594 << "Sent STUN ping response" | 594 << "Sent STUN ping response" |
| 595 << ", to=" << addr.ToSensitiveString() | 595 << ", to=" << addr.ToSensitiveString() |
| 596 << ", id=" << rtc::hex_encode(response.transaction_id()); | 596 << ", id=" << rtc::hex_encode(response.transaction_id()); |
| 597 |
| 598 conn->stats_.sent_ping_responses++; |
| 597 } | 599 } |
| 598 } | 600 } |
| 599 | 601 |
| 600 void Port::SendBindingErrorResponse(StunMessage* request, | 602 void Port::SendBindingErrorResponse(StunMessage* request, |
| 601 const rtc::SocketAddress& addr, | 603 const rtc::SocketAddress& addr, |
| 602 int error_code, const std::string& reason) { | 604 int error_code, const std::string& reason) { |
| 603 ASSERT(request->type() == STUN_BINDING_REQUEST); | 605 ASSERT(request->type() == STUN_BINDING_REQUEST); |
| 604 | 606 |
| 605 // Fill in the response message. | 607 // Fill in the response message. |
| 606 StunMessage response; | 608 StunMessage response; |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 nominated_(false), | 825 nominated_(false), |
| 824 remote_ice_mode_(ICEMODE_FULL), | 826 remote_ice_mode_(ICEMODE_FULL), |
| 825 requests_(port->thread()), | 827 requests_(port->thread()), |
| 826 rtt_(DEFAULT_RTT), | 828 rtt_(DEFAULT_RTT), |
| 827 last_ping_sent_(0), | 829 last_ping_sent_(0), |
| 828 last_ping_received_(0), | 830 last_ping_received_(0), |
| 829 last_data_received_(0), | 831 last_data_received_(0), |
| 830 last_ping_response_received_(0), | 832 last_ping_response_received_(0), |
| 831 recv_rate_tracker_(100, 10u), | 833 recv_rate_tracker_(100, 10u), |
| 832 send_rate_tracker_(100, 10u), | 834 send_rate_tracker_(100, 10u), |
| 833 sent_packets_discarded_(0), | |
| 834 sent_packets_total_(0), | |
| 835 reported_(false), | 835 reported_(false), |
| 836 state_(STATE_WAITING), | 836 state_(STATE_WAITING), |
| 837 receiving_timeout_(WEAK_CONNECTION_RECEIVE_TIMEOUT), | 837 receiving_timeout_(WEAK_CONNECTION_RECEIVE_TIMEOUT), |
| 838 time_created_ms_(rtc::TimeMillis()) { | 838 time_created_ms_(rtc::TimeMillis()) { |
| 839 // All of our connections start in WAITING state. | 839 // All of our connections start in WAITING state. |
| 840 // TODO(mallinath) - Start connections from STATE_FROZEN. | 840 // TODO(mallinath) - Start connections from STATE_FROZEN. |
| 841 // Wire up to send stun packets | 841 // Wire up to send stun packets |
| 842 requests_.SignalSendPacket.connect(this, &Connection::OnSendStunPacket); | 842 requests_.SignalSendPacket.connect(this, &Connection::OnSendStunPacket); |
| 843 LOG_J(LS_INFO, this) << "Connection created"; | 843 LOG_J(LS_INFO, this) << "Connection created"; |
| 844 } | 844 } |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 | 1011 |
| 1012 const rtc::SocketAddress& remote_addr = remote_candidate_.address(); | 1012 const rtc::SocketAddress& remote_addr = remote_candidate_.address(); |
| 1013 const std::string& remote_ufrag = remote_candidate_.username(); | 1013 const std::string& remote_ufrag = remote_candidate_.username(); |
| 1014 // Check for role conflicts. | 1014 // Check for role conflicts. |
| 1015 if (!port_->MaybeIceRoleConflict(remote_addr, msg, remote_ufrag)) { | 1015 if (!port_->MaybeIceRoleConflict(remote_addr, msg, remote_ufrag)) { |
| 1016 // Received conflicting role from the peer. | 1016 // Received conflicting role from the peer. |
| 1017 LOG(LS_INFO) << "Received conflicting role from the peer."; | 1017 LOG(LS_INFO) << "Received conflicting role from the peer."; |
| 1018 return; | 1018 return; |
| 1019 } | 1019 } |
| 1020 | 1020 |
| 1021 stats_.recv_ping_requests++; |
| 1022 |
| 1021 // This is a validated stun request from remote peer. | 1023 // This is a validated stun request from remote peer. |
| 1022 port_->SendBindingResponse(msg, remote_addr); | 1024 port_->SendBindingResponse(msg, remote_addr); |
| 1023 | 1025 |
| 1024 // If it timed out on writing check, start up again | 1026 // If it timed out on writing check, start up again |
| 1025 if (!pruned_ && write_state_ == STATE_WRITE_TIMEOUT) { | 1027 if (!pruned_ && write_state_ == STATE_WRITE_TIMEOUT) { |
| 1026 set_write_state(STATE_WRITE_INIT); | 1028 set_write_state(STATE_WRITE_INIT); |
| 1027 } | 1029 } |
| 1028 | 1030 |
| 1029 if (port_->GetIceRole() == ICEROLE_CONTROLLED) { | 1031 if (port_->GetIceRole() == ICEROLE_CONTROLLED) { |
| 1030 const StunByteStringAttribute* use_candidate_attr = | 1032 const StunByteStringAttribute* use_candidate_attr = |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1291 PrintPingsSinceLastResponse(&pings, 5); | 1293 PrintPingsSinceLastResponse(&pings, 5); |
| 1292 LOG_JV(sev, this) << "Received STUN ping response" | 1294 LOG_JV(sev, this) << "Received STUN ping response" |
| 1293 << ", id=" << rtc::hex_encode(request->id()) | 1295 << ", id=" << rtc::hex_encode(request->id()) |
| 1294 << ", code=0" // Makes logging easier to parse. | 1296 << ", code=0" // Makes logging easier to parse. |
| 1295 << ", rtt=" << rtt | 1297 << ", rtt=" << rtt |
| 1296 << ", use_candidate=" << use_candidate | 1298 << ", use_candidate=" << use_candidate |
| 1297 << ", pings_since_last_response=" << pings; | 1299 << ", pings_since_last_response=" << pings; |
| 1298 } | 1300 } |
| 1299 | 1301 |
| 1300 rtt_ = (RTT_RATIO * rtt_ + rtt) / (RTT_RATIO + 1); | 1302 rtt_ = (RTT_RATIO * rtt_ + rtt) / (RTT_RATIO + 1); |
| 1303 stats_.recv_ping_responses++; |
| 1301 | 1304 |
| 1302 MaybeAddPrflxCandidate(request, response); | 1305 MaybeAddPrflxCandidate(request, response); |
| 1303 } | 1306 } |
| 1304 | 1307 |
| 1305 void Connection::OnConnectionRequestErrorResponse(ConnectionRequest* request, | 1308 void Connection::OnConnectionRequestErrorResponse(ConnectionRequest* request, |
| 1306 StunMessage* response) { | 1309 StunMessage* response) { |
| 1307 const StunErrorCodeAttribute* error_attr = response->GetErrorCode(); | 1310 const StunErrorCodeAttribute* error_attr = response->GetErrorCode(); |
| 1308 int error_code = STUN_ERROR_GLOBAL_FAILURE; | 1311 int error_code = STUN_ERROR_GLOBAL_FAILURE; |
| 1309 if (error_attr) { | 1312 if (error_attr) { |
| 1310 error_code = error_attr->code(); | 1313 error_code = error_attr->code(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1339 << " after " << request->Elapsed() << " ms"; | 1342 << " after " << request->Elapsed() << " ms"; |
| 1340 } | 1343 } |
| 1341 | 1344 |
| 1342 void Connection::OnConnectionRequestSent(ConnectionRequest* request) { | 1345 void Connection::OnConnectionRequestSent(ConnectionRequest* request) { |
| 1343 // Log at LS_INFO if we send a ping on an unwritable connection. | 1346 // Log at LS_INFO if we send a ping on an unwritable connection. |
| 1344 rtc::LoggingSeverity sev = !writable() ? rtc::LS_INFO : rtc::LS_VERBOSE; | 1347 rtc::LoggingSeverity sev = !writable() ? rtc::LS_INFO : rtc::LS_VERBOSE; |
| 1345 bool use_candidate = use_candidate_attr(); | 1348 bool use_candidate = use_candidate_attr(); |
| 1346 LOG_JV(sev, this) << "Sent STUN ping" | 1349 LOG_JV(sev, this) << "Sent STUN ping" |
| 1347 << ", id=" << rtc::hex_encode(request->id()) | 1350 << ", id=" << rtc::hex_encode(request->id()) |
| 1348 << ", use_candidate=" << use_candidate; | 1351 << ", use_candidate=" << use_candidate; |
| 1352 stats_.sent_ping_requests_total++; |
| 1353 if (stats_.recv_ping_responses == 0) { |
| 1354 stats_.sent_ping_requests_before_first_response++; |
| 1355 } |
| 1349 } | 1356 } |
| 1350 | 1357 |
| 1351 void Connection::HandleRoleConflictFromPeer() { | 1358 void Connection::HandleRoleConflictFromPeer() { |
| 1352 port_->SignalRoleConflict(port_); | 1359 port_->SignalRoleConflict(port_); |
| 1353 } | 1360 } |
| 1354 | 1361 |
| 1355 void Connection::MaybeSetRemoteIceCredentialsAndGeneration( | 1362 void Connection::MaybeSetRemoteIceCredentialsAndGeneration( |
| 1356 const std::string& ice_ufrag, | 1363 const std::string& ice_ufrag, |
| 1357 const std::string& ice_pwd, | 1364 const std::string& ice_pwd, |
| 1358 int generation) { | 1365 int generation) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1389 << num_pings_sent_; | 1396 << num_pings_sent_; |
| 1390 SignalDestroyed(this); | 1397 SignalDestroyed(this); |
| 1391 delete this; | 1398 delete this; |
| 1392 } | 1399 } |
| 1393 | 1400 |
| 1394 int64_t Connection::last_received() const { | 1401 int64_t Connection::last_received() const { |
| 1395 return std::max(last_data_received_, | 1402 return std::max(last_data_received_, |
| 1396 std::max(last_ping_received_, last_ping_response_received_)); | 1403 std::max(last_ping_received_, last_ping_response_received_)); |
| 1397 } | 1404 } |
| 1398 | 1405 |
| 1399 size_t Connection::recv_bytes_second() { | 1406 ConnectionInfo Connection::stats() { |
| 1400 return round(recv_rate_tracker_.ComputeRate()); | 1407 stats_.recv_bytes_second = round(recv_rate_tracker_.ComputeRate()); |
| 1401 } | 1408 stats_.recv_total_bytes = recv_rate_tracker_.TotalSampleCount(); |
| 1402 | 1409 stats_.sent_bytes_second = round(send_rate_tracker_.ComputeRate()); |
| 1403 size_t Connection::recv_total_bytes() { | 1410 stats_.sent_total_bytes = send_rate_tracker_.TotalSampleCount(); |
| 1404 return recv_rate_tracker_.TotalSampleCount(); | 1411 return stats_; |
| 1405 } | |
| 1406 | |
| 1407 size_t Connection::sent_bytes_second() { | |
| 1408 return round(send_rate_tracker_.ComputeRate()); | |
| 1409 } | |
| 1410 | |
| 1411 size_t Connection::sent_total_bytes() { | |
| 1412 return send_rate_tracker_.TotalSampleCount(); | |
| 1413 } | |
| 1414 | |
| 1415 size_t Connection::sent_discarded_packets() { | |
| 1416 return sent_packets_discarded_; | |
| 1417 } | |
| 1418 | |
| 1419 size_t Connection::sent_total_packets() { | |
| 1420 return sent_packets_total_; | |
| 1421 } | 1412 } |
| 1422 | 1413 |
| 1423 void Connection::MaybeAddPrflxCandidate(ConnectionRequest* request, | 1414 void Connection::MaybeAddPrflxCandidate(ConnectionRequest* request, |
| 1424 StunMessage* response) { | 1415 StunMessage* response) { |
| 1425 // RFC 5245 | 1416 // RFC 5245 |
| 1426 // The agent checks the mapped address from the STUN response. If the | 1417 // The agent checks the mapped address from the STUN response. If the |
| 1427 // transport address does not match any of the local candidates that the | 1418 // transport address does not match any of the local candidates that the |
| 1428 // agent knows about, the mapped address represents a new candidate -- a | 1419 // agent knows about, the mapped address represents a new candidate -- a |
| 1429 // peer reflexive candidate. | 1420 // peer reflexive candidate. |
| 1430 const StunAddressAttribute* addr = | 1421 const StunAddressAttribute* addr = |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1491 size_t index, | 1482 size_t index, |
| 1492 const Candidate& remote_candidate) | 1483 const Candidate& remote_candidate) |
| 1493 : Connection(port, index, remote_candidate) {} | 1484 : Connection(port, index, remote_candidate) {} |
| 1494 | 1485 |
| 1495 int ProxyConnection::Send(const void* data, size_t size, | 1486 int ProxyConnection::Send(const void* data, size_t size, |
| 1496 const rtc::PacketOptions& options) { | 1487 const rtc::PacketOptions& options) { |
| 1497 if (write_state_ == STATE_WRITE_INIT || write_state_ == STATE_WRITE_TIMEOUT) { | 1488 if (write_state_ == STATE_WRITE_INIT || write_state_ == STATE_WRITE_TIMEOUT) { |
| 1498 error_ = EWOULDBLOCK; | 1489 error_ = EWOULDBLOCK; |
| 1499 return SOCKET_ERROR; | 1490 return SOCKET_ERROR; |
| 1500 } | 1491 } |
| 1501 sent_packets_total_++; | 1492 stats_.sent_total_packets++; |
| 1502 int sent = port_->SendTo(data, size, remote_candidate_.address(), | 1493 int sent = port_->SendTo(data, size, remote_candidate_.address(), |
| 1503 options, true); | 1494 options, true); |
| 1504 if (sent <= 0) { | 1495 if (sent <= 0) { |
| 1505 ASSERT(sent < 0); | 1496 ASSERT(sent < 0); |
| 1506 error_ = port_->GetError(); | 1497 error_ = port_->GetError(); |
| 1507 sent_packets_discarded_++; | 1498 stats_.sent_discarded_packets++; |
| 1508 } else { | 1499 } else { |
| 1509 send_rate_tracker_.AddSamples(sent); | 1500 send_rate_tracker_.AddSamples(sent); |
| 1510 } | 1501 } |
| 1511 return sent; | 1502 return sent; |
| 1512 } | 1503 } |
| 1513 | 1504 |
| 1514 } // namespace cricket | 1505 } // namespace cricket |
| OLD | NEW |