Chromium Code Reviews| 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 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 << "Received a remote ping with high retransmit count: " | 560 << "Received a remote ping with high retransmit count: " |
| 561 << retransmit_attr->value(); | 561 << retransmit_attr->value(); |
| 562 } | 562 } |
| 563 } | 563 } |
| 564 | 564 |
| 565 response.AddAttribute( | 565 response.AddAttribute( |
| 566 new StunXorAddressAttribute(STUN_ATTR_XOR_MAPPED_ADDRESS, addr)); | 566 new StunXorAddressAttribute(STUN_ATTR_XOR_MAPPED_ADDRESS, addr)); |
| 567 response.AddMessageIntegrity(password_); | 567 response.AddMessageIntegrity(password_); |
| 568 response.AddFingerprint(); | 568 response.AddFingerprint(); |
| 569 | 569 |
| 570 // The fact that we received a successful request means that this connection | |
| 571 // (if one exists) should now be receiving. | |
| 572 Connection* conn = GetConnection(addr); | |
| 573 | |
| 574 // Send the response message. | 570 // Send the response message. |
| 575 rtc::ByteBuffer buf; | 571 rtc::ByteBuffer buf; |
| 576 response.Write(&buf); | 572 response.Write(&buf); |
| 577 rtc::PacketOptions options(DefaultDscpValue()); | 573 rtc::PacketOptions options(DefaultDscpValue()); |
| 578 auto err = SendTo(buf.Data(), buf.Length(), addr, options, false); | 574 auto err = SendTo(buf.Data(), buf.Length(), addr, options, false); |
| 579 if (err < 0) { | 575 if (err < 0) { |
| 580 LOG_J(LS_ERROR, this) | 576 LOG_J(LS_ERROR, this) |
| 581 << "Failed to send STUN ping response" | 577 << "Failed to send STUN ping response" |
| 582 << ", to=" << addr.ToSensitiveString() | 578 << ", to=" << addr.ToSensitiveString() |
| 583 << ", err=" << err | 579 << ", err=" << err |
| 584 << ", id=" << rtc::hex_encode(response.transaction_id()); | 580 << ", id=" << rtc::hex_encode(response.transaction_id()); |
| 585 } else { | 581 } else { |
| 586 // Log at LS_INFO if we send a stun ping response on an unwritable | 582 // Log at LS_INFO if we send a stun ping response on an unwritable |
| 587 // connection. | 583 // connection. |
| 584 Connection* conn = GetConnection(addr); | |
| 588 rtc::LoggingSeverity sev = (conn && !conn->writable()) ? | 585 rtc::LoggingSeverity sev = (conn && !conn->writable()) ? |
| 589 rtc::LS_INFO : rtc::LS_VERBOSE; | 586 rtc::LS_INFO : rtc::LS_VERBOSE; |
| 590 LOG_JV(sev, this) | 587 LOG_JV(sev, this) |
| 591 << "Sent STUN ping response" | 588 << "Sent STUN ping response" |
| 592 << ", to=" << addr.ToSensitiveString() | 589 << ", to=" << addr.ToSensitiveString() |
| 593 << ", id=" << rtc::hex_encode(response.transaction_id()); | 590 << ", id=" << rtc::hex_encode(response.transaction_id()); |
| 594 } | 591 } |
| 595 | |
| 596 ASSERT(conn != NULL); | |
| 597 if (conn) | |
| 598 conn->ReceivedPing(); | |
| 599 } | 592 } |
| 600 | 593 |
| 601 void Port::SendBindingErrorResponse(StunMessage* request, | 594 void Port::SendBindingErrorResponse(StunMessage* request, |
| 602 const rtc::SocketAddress& addr, | 595 const rtc::SocketAddress& addr, |
| 603 int error_code, const std::string& reason) { | 596 int error_code, const std::string& reason) { |
| 604 ASSERT(request->type() == STUN_BINDING_REQUEST); | 597 ASSERT(request->type() == STUN_BINDING_REQUEST); |
| 605 | 598 |
| 606 // Fill in the response message. | 599 // Fill in the response message. |
| 607 StunMessage response; | 600 StunMessage response; |
| 608 response.SetType(STUN_BINDING_ERROR_RESPONSE); | 601 response.SetType(STUN_BINDING_ERROR_RESPONSE); |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 917 // If this is a STUN request, then update the receiving bit and respond. | 910 // If this is a STUN request, then update the receiving bit and respond. |
| 918 // If this is a STUN response, then update the writable bit. | 911 // If this is a STUN response, then update the writable bit. |
| 919 // Log at LS_INFO if we receive a ping on an unwritable connection. | 912 // Log at LS_INFO if we receive a ping on an unwritable connection. |
| 920 rtc::LoggingSeverity sev = (!writable() ? rtc::LS_INFO : rtc::LS_VERBOSE); | 913 rtc::LoggingSeverity sev = (!writable() ? rtc::LS_INFO : rtc::LS_VERBOSE); |
| 921 switch (msg->type()) { | 914 switch (msg->type()) { |
| 922 case STUN_BINDING_REQUEST: | 915 case STUN_BINDING_REQUEST: |
| 923 LOG_JV(sev, this) << "Received STUN ping" | 916 LOG_JV(sev, this) << "Received STUN ping" |
| 924 << ", id=" << rtc::hex_encode(msg->transaction_id()); | 917 << ", id=" << rtc::hex_encode(msg->transaction_id()); |
| 925 | 918 |
| 926 if (remote_ufrag == remote_candidate_.username()) { | 919 if (remote_ufrag == remote_candidate_.username()) { |
| 927 // Check for role conflicts. | 920 HandleBindingRequest(msg.get()); |
| 928 if (!port_->MaybeIceRoleConflict(addr, msg.get(), remote_ufrag)) { | |
| 929 // Received conflicting role from the peer. | |
| 930 LOG(LS_INFO) << "Received conflicting role from the peer."; | |
| 931 return; | |
| 932 } | |
| 933 | |
| 934 // Incoming, validated stun request from remote peer. | |
| 935 // This call will also set the connection receiving. | |
| 936 port_->SendBindingResponse(msg.get(), addr); | |
| 937 | |
| 938 // If timed out sending writability checks, start up again | |
| 939 if (!pruned_ && (write_state_ == STATE_WRITE_TIMEOUT)) | |
| 940 set_write_state(STATE_WRITE_INIT); | |
| 941 | |
| 942 if (port_->GetIceRole() == ICEROLE_CONTROLLED) { | |
| 943 const StunByteStringAttribute* use_candidate_attr = | |
| 944 msg->GetByteString(STUN_ATTR_USE_CANDIDATE); | |
| 945 if (use_candidate_attr) { | |
| 946 set_nominated(true); | |
| 947 SignalNominated(this); | |
| 948 } | |
| 949 } | |
| 950 } else { | 921 } else { |
| 951 // The packet had the right local username, but the remote username | 922 // The packet had the right local username, but the remote username |
| 952 // was not the right one for the remote address. | 923 // was not the right one for the remote address. |
| 953 LOG_J(LS_ERROR, this) | 924 LOG_J(LS_ERROR, this) |
| 954 << "Received STUN request with bad remote username " | 925 << "Received STUN request with bad remote username " |
| 955 << remote_ufrag; | 926 << remote_ufrag; |
| 956 port_->SendBindingErrorResponse(msg.get(), addr, | 927 port_->SendBindingErrorResponse(msg.get(), addr, |
| 957 STUN_ERROR_UNAUTHORIZED, | 928 STUN_ERROR_UNAUTHORIZED, |
| 958 STUN_ERROR_REASON_UNAUTHORIZED); | 929 STUN_ERROR_REASON_UNAUTHORIZED); |
| 959 | 930 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 979 ReceivedPing(); | 950 ReceivedPing(); |
| 980 break; | 951 break; |
| 981 | 952 |
| 982 default: | 953 default: |
| 983 ASSERT(false); | 954 ASSERT(false); |
| 984 break; | 955 break; |
| 985 } | 956 } |
| 986 } | 957 } |
| 987 } | 958 } |
| 988 | 959 |
| 960 void Connection::HandleBindingRequest(IceMessage* msg) { | |
| 961 // This connection should now be receiving. | |
| 962 ReceivedPing(); | |
| 963 | |
| 964 const rtc::SocketAddress& addr(remote_candidate_.address()); | |
| 965 const std::string& remote_ufrag = remote_candidate_.username(); | |
|
pthatcher1
2015/11/11 01:19:12
Nit: to be consistent, the first line should be:
honghaiz3
2015/11/11 19:28:09
Done. I kept the reference to avoid a copy.
| |
| 966 // Check for role conflicts. | |
| 967 if (!port_->MaybeIceRoleConflict(addr, msg, remote_ufrag)) { | |
| 968 // Received conflicting role from the peer. | |
| 969 LOG(LS_INFO) << "Received conflicting role from the peer."; | |
| 970 return; | |
| 971 } | |
| 972 | |
| 973 // This is a validated stun request from remote peer. | |
| 974 port_->SendBindingResponse(msg, addr); | |
| 975 | |
| 976 // If it timed out on writing check, start up again | |
| 977 if (!pruned_ && write_state_ == STATE_WRITE_TIMEOUT) { | |
| 978 set_write_state(STATE_WRITE_INIT); | |
| 979 } | |
| 980 | |
| 981 if (port_->GetIceRole() == ICEROLE_CONTROLLED) { | |
| 982 const StunByteStringAttribute* use_candidate_attr = | |
| 983 msg->GetByteString(STUN_ATTR_USE_CANDIDATE); | |
| 984 if (use_candidate_attr) { | |
| 985 set_nominated(true); | |
| 986 SignalNominated(this); | |
| 987 } | |
| 988 } | |
| 989 } | |
| 990 | |
| 989 void Connection::OnReadyToSend() { | 991 void Connection::OnReadyToSend() { |
| 990 if (write_state_ == STATE_WRITABLE) { | 992 if (write_state_ == STATE_WRITABLE) { |
| 991 SignalReadyToSend(this); | 993 SignalReadyToSend(this); |
| 992 } | 994 } |
| 993 } | 995 } |
| 994 | 996 |
| 995 void Connection::Prune() { | 997 void Connection::Prune() { |
| 996 if (!pruned_ || active()) { | 998 if (!pruned_ || active()) { |
| 997 LOG_J(LS_VERBOSE, this) << "Connection pruned"; | 999 LOG_J(LS_VERBOSE, this) << "Connection pruned"; |
| 998 pruned_ = true; | 1000 pruned_ = true; |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1414 ASSERT(sent < 0); | 1416 ASSERT(sent < 0); |
| 1415 error_ = port_->GetError(); | 1417 error_ = port_->GetError(); |
| 1416 sent_packets_discarded_++; | 1418 sent_packets_discarded_++; |
| 1417 } else { | 1419 } else { |
| 1418 send_rate_tracker_.AddSamples(sent); | 1420 send_rate_tracker_.AddSamples(sent); |
| 1419 } | 1421 } |
| 1420 return sent; | 1422 return sent; |
| 1421 } | 1423 } |
| 1422 | 1424 |
| 1423 } // namespace cricket | 1425 } // namespace cricket |
| OLD | NEW |