| 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 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 } else { | 590 } else { |
| 591 // Log at LS_INFO if we send a stun ping response on an unwritable | 591 // Log at LS_INFO if we send a stun ping response on an unwritable |
| 592 // connection. | 592 // connection. |
| 593 Connection* conn = GetConnection(addr); | 593 Connection* conn = GetConnection(addr); |
| 594 rtc::LoggingSeverity sev = (conn && !conn->writable()) ? | 594 rtc::LoggingSeverity sev = (conn && !conn->writable()) ? |
| 595 rtc::LS_INFO : rtc::LS_VERBOSE; | 595 rtc::LS_INFO : rtc::LS_VERBOSE; |
| 596 LOG_JV(sev, this) | 596 LOG_JV(sev, this) |
| 597 << "Sent STUN ping response" | 597 << "Sent STUN ping response" |
| 598 << ", to=" << addr.ToSensitiveString() | 598 << ", to=" << addr.ToSensitiveString() |
| 599 << ", id=" << rtc::hex_encode(response.transaction_id()); | 599 << ", id=" << rtc::hex_encode(response.transaction_id()); |
| 600 |
| 601 // Update the stats of corresponding connection. |
| 602 conn->sent_ping_responses_++; |
| 600 } | 603 } |
| 601 } | 604 } |
| 602 | 605 |
| 603 void Port::SendBindingErrorResponse(StunMessage* request, | 606 void Port::SendBindingErrorResponse(StunMessage* request, |
| 604 const rtc::SocketAddress& addr, | 607 const rtc::SocketAddress& addr, |
| 605 int error_code, const std::string& reason) { | 608 int error_code, const std::string& reason) { |
| 606 ASSERT(request->type() == STUN_BINDING_REQUEST); | 609 ASSERT(request->type() == STUN_BINDING_REQUEST); |
| 607 | 610 |
| 608 // Fill in the response message. | 611 // Fill in the response message. |
| 609 StunMessage response; | 612 StunMessage response; |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 requests_(port->thread()), | 802 requests_(port->thread()), |
| 800 rtt_(DEFAULT_RTT), | 803 rtt_(DEFAULT_RTT), |
| 801 last_ping_sent_(0), | 804 last_ping_sent_(0), |
| 802 last_ping_received_(0), | 805 last_ping_received_(0), |
| 803 last_data_received_(0), | 806 last_data_received_(0), |
| 804 last_ping_response_received_(0), | 807 last_ping_response_received_(0), |
| 805 recv_rate_tracker_(100, 10u), | 808 recv_rate_tracker_(100, 10u), |
| 806 send_rate_tracker_(100, 10u), | 809 send_rate_tracker_(100, 10u), |
| 807 sent_packets_discarded_(0), | 810 sent_packets_discarded_(0), |
| 808 sent_packets_total_(0), | 811 sent_packets_total_(0), |
| 812 sent_ping_requests_total_(0), |
| 813 sent_ping_requests_before_first_response_(0), |
| 814 sent_ping_responses_(0), |
| 815 recv_ping_requests_(0), |
| 816 recv_ping_responses_(0), |
| 809 reported_(false), | 817 reported_(false), |
| 810 state_(STATE_WAITING), | 818 state_(STATE_WAITING), |
| 811 receiving_timeout_(WEAK_CONNECTION_RECEIVE_TIMEOUT), | 819 receiving_timeout_(WEAK_CONNECTION_RECEIVE_TIMEOUT), |
| 812 time_created_ms_(rtc::TimeMillis()) { | 820 time_created_ms_(rtc::TimeMillis()), |
| 821 received_first_response_(false) { |
| 813 // All of our connections start in WAITING state. | 822 // All of our connections start in WAITING state. |
| 814 // TODO(mallinath) - Start connections from STATE_FROZEN. | 823 // TODO(mallinath) - Start connections from STATE_FROZEN. |
| 815 // Wire up to send stun packets | 824 // Wire up to send stun packets |
| 816 requests_.SignalSendPacket.connect(this, &Connection::OnSendStunPacket); | 825 requests_.SignalSendPacket.connect(this, &Connection::OnSendStunPacket); |
| 817 LOG_J(LS_INFO, this) << "Connection created"; | 826 LOG_J(LS_INFO, this) << "Connection created"; |
| 818 } | 827 } |
| 819 | 828 |
| 820 Connection::~Connection() { | 829 Connection::~Connection() { |
| 821 } | 830 } |
| 822 | 831 |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 985 | 994 |
| 986 const rtc::SocketAddress& remote_addr = remote_candidate_.address(); | 995 const rtc::SocketAddress& remote_addr = remote_candidate_.address(); |
| 987 const std::string& remote_ufrag = remote_candidate_.username(); | 996 const std::string& remote_ufrag = remote_candidate_.username(); |
| 988 // Check for role conflicts. | 997 // Check for role conflicts. |
| 989 if (!port_->MaybeIceRoleConflict(remote_addr, msg, remote_ufrag)) { | 998 if (!port_->MaybeIceRoleConflict(remote_addr, msg, remote_ufrag)) { |
| 990 // Received conflicting role from the peer. | 999 // Received conflicting role from the peer. |
| 991 LOG(LS_INFO) << "Received conflicting role from the peer."; | 1000 LOG(LS_INFO) << "Received conflicting role from the peer."; |
| 992 return; | 1001 return; |
| 993 } | 1002 } |
| 994 | 1003 |
| 1004 recv_ping_requests_++; |
| 1005 |
| 995 // This is a validated stun request from remote peer. | 1006 // This is a validated stun request from remote peer. |
| 996 port_->SendBindingResponse(msg, remote_addr); | 1007 port_->SendBindingResponse(msg, remote_addr); |
| 997 | 1008 |
| 998 // If it timed out on writing check, start up again | 1009 // If it timed out on writing check, start up again |
| 999 if (!pruned_ && write_state_ == STATE_WRITE_TIMEOUT) { | 1010 if (!pruned_ && write_state_ == STATE_WRITE_TIMEOUT) { |
| 1000 set_write_state(STATE_WRITE_INIT); | 1011 set_write_state(STATE_WRITE_INIT); |
| 1001 } | 1012 } |
| 1002 | 1013 |
| 1003 if (port_->GetIceRole() == ICEROLE_CONTROLLED) { | 1014 if (port_->GetIceRole() == ICEROLE_CONTROLLED) { |
| 1004 const StunByteStringAttribute* use_candidate_attr = | 1015 const StunByteStringAttribute* use_candidate_attr = |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1249 PrintPingsSinceLastResponse(&pings, 5); | 1260 PrintPingsSinceLastResponse(&pings, 5); |
| 1250 LOG_JV(sev, this) << "Received STUN ping response" | 1261 LOG_JV(sev, this) << "Received STUN ping response" |
| 1251 << ", id=" << rtc::hex_encode(request->id()) | 1262 << ", id=" << rtc::hex_encode(request->id()) |
| 1252 << ", code=0" // Makes logging easier to parse. | 1263 << ", code=0" // Makes logging easier to parse. |
| 1253 << ", rtt=" << rtt | 1264 << ", rtt=" << rtt |
| 1254 << ", use_candidate=" << use_candidate | 1265 << ", use_candidate=" << use_candidate |
| 1255 << ", pings_since_last_response=" << pings; | 1266 << ", pings_since_last_response=" << pings; |
| 1256 } | 1267 } |
| 1257 | 1268 |
| 1258 rtt_ = (RTT_RATIO * rtt_ + rtt) / (RTT_RATIO + 1); | 1269 rtt_ = (RTT_RATIO * rtt_ + rtt) / (RTT_RATIO + 1); |
| 1270 recv_ping_responses_++; |
| 1271 if (!received_first_response_) { |
| 1272 received_first_response_ = true; |
| 1273 } |
| 1259 | 1274 |
| 1260 MaybeAddPrflxCandidate(request, response); | 1275 MaybeAddPrflxCandidate(request, response); |
| 1261 } | 1276 } |
| 1262 | 1277 |
| 1263 void Connection::OnConnectionRequestErrorResponse(ConnectionRequest* request, | 1278 void Connection::OnConnectionRequestErrorResponse(ConnectionRequest* request, |
| 1264 StunMessage* response) { | 1279 StunMessage* response) { |
| 1265 const StunErrorCodeAttribute* error_attr = response->GetErrorCode(); | 1280 const StunErrorCodeAttribute* error_attr = response->GetErrorCode(); |
| 1266 int error_code = STUN_ERROR_GLOBAL_FAILURE; | 1281 int error_code = STUN_ERROR_GLOBAL_FAILURE; |
| 1267 if (error_attr) { | 1282 if (error_attr) { |
| 1268 error_code = error_attr->code(); | 1283 error_code = error_attr->code(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1297 << " after " << request->Elapsed() << " ms"; | 1312 << " after " << request->Elapsed() << " ms"; |
| 1298 } | 1313 } |
| 1299 | 1314 |
| 1300 void Connection::OnConnectionRequestSent(ConnectionRequest* request) { | 1315 void Connection::OnConnectionRequestSent(ConnectionRequest* request) { |
| 1301 // Log at LS_INFO if we send a ping on an unwritable connection. | 1316 // Log at LS_INFO if we send a ping on an unwritable connection. |
| 1302 rtc::LoggingSeverity sev = !writable() ? rtc::LS_INFO : rtc::LS_VERBOSE; | 1317 rtc::LoggingSeverity sev = !writable() ? rtc::LS_INFO : rtc::LS_VERBOSE; |
| 1303 bool use_candidate = use_candidate_attr(); | 1318 bool use_candidate = use_candidate_attr(); |
| 1304 LOG_JV(sev, this) << "Sent STUN ping" | 1319 LOG_JV(sev, this) << "Sent STUN ping" |
| 1305 << ", id=" << rtc::hex_encode(request->id()) | 1320 << ", id=" << rtc::hex_encode(request->id()) |
| 1306 << ", use_candidate=" << use_candidate; | 1321 << ", use_candidate=" << use_candidate; |
| 1322 sent_ping_requests_total_++; |
| 1323 if (!received_first_response_) { |
| 1324 sent_ping_requests_before_first_response_++; |
| 1325 } |
| 1307 } | 1326 } |
| 1308 | 1327 |
| 1309 void Connection::HandleRoleConflictFromPeer() { | 1328 void Connection::HandleRoleConflictFromPeer() { |
| 1310 port_->SignalRoleConflict(port_); | 1329 port_->SignalRoleConflict(port_); |
| 1311 } | 1330 } |
| 1312 | 1331 |
| 1313 void Connection::MaybeSetRemoteIceCredentialsAndGeneration( | 1332 void Connection::MaybeSetRemoteIceCredentialsAndGeneration( |
| 1314 const std::string& ice_ufrag, | 1333 const std::string& ice_ufrag, |
| 1315 const std::string& ice_pwd, | 1334 const std::string& ice_pwd, |
| 1316 int generation) { | 1335 int generation) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1370 } | 1389 } |
| 1371 | 1390 |
| 1372 size_t Connection::sent_discarded_packets() { | 1391 size_t Connection::sent_discarded_packets() { |
| 1373 return sent_packets_discarded_; | 1392 return sent_packets_discarded_; |
| 1374 } | 1393 } |
| 1375 | 1394 |
| 1376 size_t Connection::sent_total_packets() { | 1395 size_t Connection::sent_total_packets() { |
| 1377 return sent_packets_total_; | 1396 return sent_packets_total_; |
| 1378 } | 1397 } |
| 1379 | 1398 |
| 1399 size_t Connection::sent_ping_requests_total() { |
| 1400 return sent_ping_requests_total_; |
| 1401 } |
| 1402 |
| 1403 size_t Connection::sent_ping_requests_before_first_response() { |
| 1404 return sent_ping_requests_before_first_response_; |
| 1405 } |
| 1406 |
| 1407 size_t Connection::sent_ping_responses() { |
| 1408 return sent_ping_responses_; |
| 1409 } |
| 1410 |
| 1411 size_t Connection::recv_ping_responses() { |
| 1412 return recv_ping_responses_; |
| 1413 } |
| 1414 |
| 1415 size_t Connection::recv_ping_requests() { |
| 1416 return recv_ping_requests_; |
| 1417 } |
| 1418 |
| 1380 void Connection::MaybeAddPrflxCandidate(ConnectionRequest* request, | 1419 void Connection::MaybeAddPrflxCandidate(ConnectionRequest* request, |
| 1381 StunMessage* response) { | 1420 StunMessage* response) { |
| 1382 // RFC 5245 | 1421 // RFC 5245 |
| 1383 // The agent checks the mapped address from the STUN response. If the | 1422 // The agent checks the mapped address from the STUN response. If the |
| 1384 // transport address does not match any of the local candidates that the | 1423 // transport address does not match any of the local candidates that the |
| 1385 // agent knows about, the mapped address represents a new candidate -- a | 1424 // agent knows about, the mapped address represents a new candidate -- a |
| 1386 // peer reflexive candidate. | 1425 // peer reflexive candidate. |
| 1387 const StunAddressAttribute* addr = | 1426 const StunAddressAttribute* addr = |
| 1388 response->GetAddress(STUN_ATTR_XOR_MAPPED_ADDRESS); | 1427 response->GetAddress(STUN_ATTR_XOR_MAPPED_ADDRESS); |
| 1389 if (!addr) { | 1428 if (!addr) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1462 ASSERT(sent < 0); | 1501 ASSERT(sent < 0); |
| 1463 error_ = port_->GetError(); | 1502 error_ = port_->GetError(); |
| 1464 sent_packets_discarded_++; | 1503 sent_packets_discarded_++; |
| 1465 } else { | 1504 } else { |
| 1466 send_rate_tracker_.AddSamples(sent); | 1505 send_rate_tracker_.AddSamples(sent); |
| 1467 } | 1506 } |
| 1468 return sent; | 1507 return sent; |
| 1469 } | 1508 } |
| 1470 | 1509 |
| 1471 } // namespace cricket | 1510 } // namespace cricket |
| OLD | NEW |