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