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 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 StunByteStringAttribute* 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 VERIFY(request.AddAttribute(magic_cookie_attr)); | 583 request.AddAttribute(magic_cookie_attr); |
584 | 584 |
585 StunByteStringAttribute* username_attr = | 585 StunByteStringAttribute* username_attr = |
586 StunAttribute::CreateByteString(STUN_ATTR_USERNAME); | 586 StunAttribute::CreateByteString(STUN_ATTR_USERNAME); |
587 username_attr->CopyBytes(port_->username_fragment().c_str(), | 587 username_attr->CopyBytes(port_->username_fragment().c_str(), |
588 port_->username_fragment().size()); | 588 port_->username_fragment().size()); |
589 VERIFY(request.AddAttribute(username_attr)); | 589 request.AddAttribute(username_attr); |
590 | 590 |
591 StunAddressAttribute* addr_attr = | 591 StunAddressAttribute* addr_attr = |
592 StunAttribute::CreateAddress(STUN_ATTR_DESTINATION_ADDRESS); | 592 StunAttribute::CreateAddress(STUN_ATTR_DESTINATION_ADDRESS); |
593 addr_attr->SetIP(addr.ipaddr()); | 593 addr_attr->SetIP(addr.ipaddr()); |
594 addr_attr->SetPort(addr.port()); | 594 addr_attr->SetPort(addr.port()); |
595 VERIFY(request.AddAttribute(addr_attr)); | 595 request.AddAttribute(addr_attr); |
596 | 596 |
597 // Attempt to lock | 597 // Attempt to lock |
598 if (ext_addr_ == addr) { | 598 if (ext_addr_ == addr) { |
599 StunUInt32Attribute* options_attr = | 599 StunUInt32Attribute* options_attr = |
600 StunAttribute::CreateUInt32(STUN_ATTR_OPTIONS); | 600 StunAttribute::CreateUInt32(STUN_ATTR_OPTIONS); |
601 options_attr->SetValue(0x1); | 601 options_attr->SetValue(0x1); |
602 VERIFY(request.AddAttribute(options_attr)); | 602 request.AddAttribute(options_attr); |
603 } | 603 } |
604 | 604 |
605 StunByteStringAttribute* data_attr = | 605 StunByteStringAttribute* data_attr = |
606 StunAttribute::CreateByteString(STUN_ATTR_DATA); | 606 StunAttribute::CreateByteString(STUN_ATTR_DATA); |
607 data_attr->CopyBytes(data, size); | 607 data_attr->CopyBytes(data, size); |
608 VERIFY(request.AddAttribute(data_attr)); | 608 request.AddAttribute(data_attr); |
609 | 609 |
610 // TODO: compute the HMAC. | 610 // TODO: compute the HMAC. |
611 | 611 |
612 rtc::ByteBufferWriter buf; | 612 rtc::ByteBufferWriter buf; |
613 request.Write(&buf); | 613 request.Write(&buf); |
614 | 614 |
615 return SendPacket(buf.Data(), buf.Length(), options); | 615 return SendPacket(buf.Data(), buf.Length(), options); |
616 } | 616 } |
617 | 617 |
618 void RelayEntry::ScheduleKeepAlive() { | 618 void RelayEntry::ScheduleKeepAlive() { |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 } | 785 } |
786 | 786 |
787 void AllocateRequest::Prepare(StunMessage* request) { | 787 void AllocateRequest::Prepare(StunMessage* request) { |
788 request->SetType(STUN_ALLOCATE_REQUEST); | 788 request->SetType(STUN_ALLOCATE_REQUEST); |
789 | 789 |
790 StunByteStringAttribute* username_attr = | 790 StunByteStringAttribute* username_attr = |
791 StunAttribute::CreateByteString(STUN_ATTR_USERNAME); | 791 StunAttribute::CreateByteString(STUN_ATTR_USERNAME); |
792 username_attr->CopyBytes( | 792 username_attr->CopyBytes( |
793 entry_->port()->username_fragment().c_str(), | 793 entry_->port()->username_fragment().c_str(), |
794 entry_->port()->username_fragment().size()); | 794 entry_->port()->username_fragment().size()); |
795 VERIFY(request->AddAttribute(username_attr)); | 795 request->AddAttribute(username_attr); |
796 } | 796 } |
797 | 797 |
798 void AllocateRequest::OnSent() { | 798 void AllocateRequest::OnSent() { |
799 count_ += 1; | 799 count_ += 1; |
800 if (count_ == 5) | 800 if (count_ == 5) |
801 timeout_ = true; | 801 timeout_ = true; |
802 } | 802 } |
803 | 803 |
804 int AllocateRequest::resend_delay() { | 804 int AllocateRequest::resend_delay() { |
805 if (count_ == 0) { | 805 if (count_ == 0) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 if (rtc::TimeMillis() - start_time_ <= kRetryTimeout) | 839 if (rtc::TimeMillis() - start_time_ <= kRetryTimeout) |
840 entry_->ScheduleKeepAlive(); | 840 entry_->ScheduleKeepAlive(); |
841 } | 841 } |
842 | 842 |
843 void AllocateRequest::OnTimeout() { | 843 void AllocateRequest::OnTimeout() { |
844 LOG(INFO) << "Allocate request timed out"; | 844 LOG(INFO) << "Allocate request timed out"; |
845 entry_->HandleConnectFailure(connection_->socket()); | 845 entry_->HandleConnectFailure(connection_->socket()); |
846 } | 846 } |
847 | 847 |
848 } // namespace cricket | 848 } // namespace cricket |
OLD | NEW |