| 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 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 // Otherwise, we must wrap the given data in a STUN SEND request so that we | 561 // Otherwise, we must wrap the given data in a STUN SEND request so that we |
| 562 // can communicate the destination address to the server. | 562 // can communicate the destination address to the server. |
| 563 // | 563 // |
| 564 // Note that we do not use a StunRequest here. This is because there is | 564 // Note that we do not use a StunRequest here. This is because there is |
| 565 // likely no reason to resend this packet. If it is late, we just drop it. | 565 // likely no reason to resend this packet. If it is late, we just drop it. |
| 566 // The next send to this address will try again. | 566 // The next send to this address will try again. |
| 567 | 567 |
| 568 RelayMessage request; | 568 RelayMessage request; |
| 569 request.SetType(STUN_SEND_REQUEST); | 569 request.SetType(STUN_SEND_REQUEST); |
| 570 | 570 |
| 571 StunByteStringAttribute* magic_cookie_attr = | 571 auto magic_cookie_attr = |
| 572 StunAttribute::CreateByteString(STUN_ATTR_MAGIC_COOKIE); | 572 StunAttribute::CreateByteString(STUN_ATTR_MAGIC_COOKIE); |
| 573 magic_cookie_attr->CopyBytes(TURN_MAGIC_COOKIE_VALUE, | 573 magic_cookie_attr->CopyBytes(TURN_MAGIC_COOKIE_VALUE, |
| 574 sizeof(TURN_MAGIC_COOKIE_VALUE)); | 574 sizeof(TURN_MAGIC_COOKIE_VALUE)); |
| 575 request.AddAttribute(magic_cookie_attr); | 575 request.AddAttribute(std::move(magic_cookie_attr)); |
| 576 | 576 |
| 577 StunByteStringAttribute* username_attr = | 577 auto username_attr = StunAttribute::CreateByteString(STUN_ATTR_USERNAME); |
| 578 StunAttribute::CreateByteString(STUN_ATTR_USERNAME); | |
| 579 username_attr->CopyBytes(port_->username_fragment().c_str(), | 578 username_attr->CopyBytes(port_->username_fragment().c_str(), |
| 580 port_->username_fragment().size()); | 579 port_->username_fragment().size()); |
| 581 request.AddAttribute(username_attr); | 580 request.AddAttribute(std::move(username_attr)); |
| 582 | 581 |
| 583 StunAddressAttribute* addr_attr = | 582 auto addr_attr = StunAttribute::CreateAddress(STUN_ATTR_DESTINATION_ADDRESS); |
| 584 StunAttribute::CreateAddress(STUN_ATTR_DESTINATION_ADDRESS); | |
| 585 addr_attr->SetIP(addr.ipaddr()); | 583 addr_attr->SetIP(addr.ipaddr()); |
| 586 addr_attr->SetPort(addr.port()); | 584 addr_attr->SetPort(addr.port()); |
| 587 request.AddAttribute(addr_attr); | 585 request.AddAttribute(std::move(addr_attr)); |
| 588 | 586 |
| 589 // Attempt to lock | 587 // Attempt to lock |
| 590 if (ext_addr_ == addr) { | 588 if (ext_addr_ == addr) { |
| 591 StunUInt32Attribute* options_attr = | 589 auto options_attr = StunAttribute::CreateUInt32(STUN_ATTR_OPTIONS); |
| 592 StunAttribute::CreateUInt32(STUN_ATTR_OPTIONS); | |
| 593 options_attr->SetValue(0x1); | 590 options_attr->SetValue(0x1); |
| 594 request.AddAttribute(options_attr); | 591 request.AddAttribute(std::move(options_attr)); |
| 595 } | 592 } |
| 596 | 593 |
| 597 StunByteStringAttribute* data_attr = | 594 auto data_attr = StunAttribute::CreateByteString(STUN_ATTR_DATA); |
| 598 StunAttribute::CreateByteString(STUN_ATTR_DATA); | |
| 599 data_attr->CopyBytes(data, size); | 595 data_attr->CopyBytes(data, size); |
| 600 request.AddAttribute(data_attr); | 596 request.AddAttribute(std::move(data_attr)); |
| 601 | 597 |
| 602 // TODO: compute the HMAC. | 598 // TODO: compute the HMAC. |
| 603 | 599 |
| 604 rtc::ByteBufferWriter buf; | 600 rtc::ByteBufferWriter buf; |
| 605 request.Write(&buf); | 601 request.Write(&buf); |
| 606 | 602 |
| 607 return SendPacket(buf.Data(), buf.Length(), options); | 603 return SendPacket(buf.Data(), buf.Length(), options); |
| 608 } | 604 } |
| 609 | 605 |
| 610 void RelayEntry::ScheduleKeepAlive() { | 606 void RelayEntry::ScheduleKeepAlive() { |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 RelayConnection* connection) | 768 RelayConnection* connection) |
| 773 : StunRequest(new RelayMessage()), | 769 : StunRequest(new RelayMessage()), |
| 774 entry_(entry), | 770 entry_(entry), |
| 775 connection_(connection) { | 771 connection_(connection) { |
| 776 start_time_ = rtc::TimeMillis(); | 772 start_time_ = rtc::TimeMillis(); |
| 777 } | 773 } |
| 778 | 774 |
| 779 void AllocateRequest::Prepare(StunMessage* request) { | 775 void AllocateRequest::Prepare(StunMessage* request) { |
| 780 request->SetType(STUN_ALLOCATE_REQUEST); | 776 request->SetType(STUN_ALLOCATE_REQUEST); |
| 781 | 777 |
| 782 StunByteStringAttribute* username_attr = | 778 auto username_attr = StunAttribute::CreateByteString(STUN_ATTR_USERNAME); |
| 783 StunAttribute::CreateByteString(STUN_ATTR_USERNAME); | |
| 784 username_attr->CopyBytes( | 779 username_attr->CopyBytes( |
| 785 entry_->port()->username_fragment().c_str(), | 780 entry_->port()->username_fragment().c_str(), |
| 786 entry_->port()->username_fragment().size()); | 781 entry_->port()->username_fragment().size()); |
| 787 request->AddAttribute(username_attr); | 782 request->AddAttribute(std::move(username_attr)); |
| 788 } | 783 } |
| 789 | 784 |
| 790 void AllocateRequest::OnSent() { | 785 void AllocateRequest::OnSent() { |
| 791 count_ += 1; | 786 count_ += 1; |
| 792 if (count_ == 5) | 787 if (count_ == 5) |
| 793 timeout_ = true; | 788 timeout_ = true; |
| 794 } | 789 } |
| 795 | 790 |
| 796 int AllocateRequest::resend_delay() { | 791 int AllocateRequest::resend_delay() { |
| 797 if (count_ == 0) { | 792 if (count_ == 0) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 if (rtc::TimeMillis() - start_time_ <= kRetryTimeout) | 826 if (rtc::TimeMillis() - start_time_ <= kRetryTimeout) |
| 832 entry_->ScheduleKeepAlive(); | 827 entry_->ScheduleKeepAlive(); |
| 833 } | 828 } |
| 834 | 829 |
| 835 void AllocateRequest::OnTimeout() { | 830 void AllocateRequest::OnTimeout() { |
| 836 LOG(INFO) << "Allocate request timed out"; | 831 LOG(INFO) << "Allocate request timed out"; |
| 837 entry_->HandleConnectFailure(connection_->socket()); | 832 entry_->HandleConnectFailure(connection_->socket()); |
| 838 } | 833 } |
| 839 | 834 |
| 840 } // namespace cricket | 835 } // namespace cricket |
| OLD | NEW |