tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit b7bf11d7e4480fdee2c60e0eaa01cf8b9efdbda1
parent 1eb23b43d9c3532906e2e8185e98950ff5aaf7ae
Author: Michael Froman <mfroman@mozilla.com>
Date:   Wed,  8 Oct 2025 17:37:36 -0500

Bug 1993083 - Vendor libwebrtc from 6dc30b361c

Upstream commit: https://webrtc.googlesource.com/src/+/6dc30b361cd87b93f2477ef205167673bd3da933
    dtls-in-stun: change API to take take a vector of uint32_t for acks

    which hides details of the STUN implementation from the piggybacking
    controller.

    Bug: webrtc:367395350
    Change-Id: I234bdef1d472b2cb2d2dc21ecd84a2f60a8967aa
    Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/394140
    Reviewed-by: Harald Alvestrand <hta@webrtc.org>
    Reviewed-by: Jonas Oreland <jonaso@webrtc.org>
    Commit-Queue: Jonas Oreland <jonaso@webrtc.org>
    Cr-Commit-Position: refs/heads/main@{#45052}

Diffstat:
Mthird_party/libwebrtc/README.mozilla.last-vendor | 4++--
Mthird_party/libwebrtc/api/transport/stun.cc | 17+++++++++++++++--
Mthird_party/libwebrtc/api/transport/stun.h | 8+++++---
Mthird_party/libwebrtc/api/transport/stun_unittest.cc | 215+++++++++++++++++++++++++++++++++++++++++++++----------------------------------
Mthird_party/libwebrtc/p2p/base/connection.cc | 48++++++++++++++++++++++++++----------------------
Mthird_party/libwebrtc/p2p/base/connection.h | 1+
Mthird_party/libwebrtc/p2p/base/p2p_transport_channel_unittest.cc | 4++--
Mthird_party/libwebrtc/p2p/dtls/dtls_stun_piggyback_callbacks.h | 21++++++++++++---------
Mthird_party/libwebrtc/p2p/dtls/dtls_stun_piggyback_controller.cc | 28++++++++++++----------------
Mthird_party/libwebrtc/p2p/dtls/dtls_stun_piggyback_controller.h | 4++--
Mthird_party/libwebrtc/p2p/dtls/dtls_stun_piggyback_controller_unittest.cc | 88++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------
Mthird_party/libwebrtc/p2p/dtls/dtls_transport.cc | 6++++--
Mthird_party/libwebrtc/p2p/dtls/dtls_utils.h | 5-----
Mthird_party/libwebrtc/p2p/test/fake_ice_transport.h | 12++++++++++--
14 files changed, 270 insertions(+), 191 deletions(-)

diff --git a/third_party/libwebrtc/README.mozilla.last-vendor b/third_party/libwebrtc/README.mozilla.last-vendor @@ -1,4 +1,4 @@ # ./mach python dom/media/webrtc/third_party_build/vendor-libwebrtc.py --from-local /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc --commit mozpatches libwebrtc -libwebrtc updated from /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-10-08T22:36:21.078956+00:00. +libwebrtc updated from /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-10-08T22:37:27.034223+00:00. # base of lastest vendoring -38964c475e +6dc30b361c diff --git a/third_party/libwebrtc/api/transport/stun.cc b/third_party/libwebrtc/api/transport/stun.cc @@ -10,14 +10,13 @@ #include "api/transport/stun.h" -#include <string.h> - #include <algorithm> // IWYU pragma: keep #include <cstdint> #include <cstring> #include <functional> #include <iterator> #include <memory> +#include <optional> #include <string> #include <utility> #include <vector> @@ -1122,6 +1121,20 @@ StunAttributeValueType StunByteStringAttribute::value_type() const { return STUN_VALUE_BYTE_STRING; } +std::optional<std::vector<uint32_t>> StunByteStringAttribute::GetUInt32Vector() + const { + if (length() % 4 != 0) { + return std::nullopt; + } + std::vector<uint32_t> values; + ByteBufferReader reader(array_view()); + uint32_t value; + while (reader.ReadUInt32(&value)) { + values.push_back(value); + } + return values; +} + void StunByteStringAttribute::CopyBytes(absl::string_view bytes) { uint8_t* new_bytes = new uint8_t[bytes.size()]; memcpy(new_bytes, bytes.data(), bytes.size()); diff --git a/third_party/libwebrtc/api/transport/stun.h b/third_party/libwebrtc/api/transport/stun.h @@ -14,11 +14,11 @@ // This file contains classes for dealing with the STUN protocol, as specified // in RFC 5389, and its descendants. -#include <stddef.h> -#include <stdint.h> - +#include <cstddef> +#include <cstdint> #include <functional> #include <memory> +#include <optional> #include <string> #include <vector> @@ -530,6 +530,8 @@ class StunByteStringAttribute : public StunAttribute { return std::string(reinterpret_cast<const char*>(bytes_), length()); } + std::optional<std::vector<uint32_t>> GetUInt32Vector() const; + void CopyBytes(const void* bytes, size_t length); void CopyBytes(absl::string_view bytes); diff --git a/third_party/libwebrtc/api/transport/stun_unittest.cc b/third_party/libwebrtc/api/transport/stun_unittest.cc @@ -10,12 +10,13 @@ #include "api/transport/stun.h" -#include <string.h> - #include <cstdint> +#include <cstring> #include <memory> +#include <optional> #include <string> #include <utility> +#include <vector> #include "api/array_view.h" #include "rtc_base/byte_buffer.h" @@ -23,62 +24,12 @@ #include "rtc_base/ip_address.h" #include "rtc_base/socket_address.h" #include "system_wrappers/include/metrics.h" +#include "test/gmock.h" #include "test/gtest.h" namespace webrtc { -class StunTest : public ::testing::Test { - protected: - void CheckStunHeader(const StunMessage& msg, - StunMessageType expected_type, - size_t expected_length) { - ASSERT_EQ(expected_type, msg.type()); - ASSERT_EQ(expected_length, msg.length()); - } - - void CheckStunTransactionID(const StunMessage& msg, - const uint8_t* expectedID, - size_t length) { - ASSERT_EQ(length, msg.transaction_id().size()); - ASSERT_EQ(length == kStunTransactionIdLength + 4, msg.IsLegacy()); - ASSERT_EQ(length == kStunTransactionIdLength, !msg.IsLegacy()); - ASSERT_EQ(0, memcmp(msg.transaction_id().c_str(), expectedID, length)); - } - - void CheckStunAddressAttribute(const StunAddressAttribute* addr, - StunAddressFamily expected_family, - int expected_port, - const IPAddress& expected_address) { - ASSERT_EQ(expected_family, addr->family()); - ASSERT_EQ(expected_port, addr->port()); - - if (addr->family() == STUN_ADDRESS_IPV4) { - in_addr v4_address = expected_address.ipv4_address(); - in_addr stun_address = addr->ipaddr().ipv4_address(); - ASSERT_EQ(0, memcmp(&v4_address, &stun_address, sizeof(stun_address))); - } else if (addr->family() == STUN_ADDRESS_IPV6) { - in6_addr v6_address = expected_address.ipv6_address(); - in6_addr stun_address = addr->ipaddr().ipv6_address(); - ASSERT_EQ(0, memcmp(&v6_address, &stun_address, sizeof(stun_address))); - } else { - ASSERT_TRUE(addr->family() == STUN_ADDRESS_IPV6 || - addr->family() == STUN_ADDRESS_IPV4); - } - } - - size_t ReadStunMessageTestCase(StunMessage* msg, - const uint8_t* testcase, - size_t size) { - ByteBufferReader buf(MakeArrayView(testcase, size)); - if (msg->Read(&buf)) { - // Returns the size the stun message should report itself as being - return (size - 20); - } else { - return 0; - } - } -}; - +namespace { // Sample STUN packets with various attributes // Gathered by wiresharking pjproject's pjnath test programs // pjproject available at www.pjsip.org @@ -86,7 +37,7 @@ class StunTest : public ::testing::Test { // clang-format off // clang formatting doesn't respect inline comments. -static const uint8_t kStunMessageWithIPv6MappedAddress[] = { +const uint8_t kStunMessageWithIPv6MappedAddress[] = { 0x00, 0x01, 0x00, 0x18, // message header 0x21, 0x12, 0xa4, 0x42, // transaction id 0x29, 0x1f, 0xcd, 0x7c, @@ -100,7 +51,7 @@ static const uint8_t kStunMessageWithIPv6MappedAddress[] = { 0xfe, 0xe5, 0x00, 0xc3 }; -static const uint8_t kStunMessageWithIPv4MappedAddress[] = { +const uint8_t kStunMessageWithIPv4MappedAddress[] = { 0x01, 0x01, 0x00, 0x0c, // binding response, length 12 0x21, 0x12, 0xa4, 0x42, // magic cookie 0x29, 0x1f, 0xcd, 0x7c, // transaction ID @@ -112,7 +63,7 @@ static const uint8_t kStunMessageWithIPv4MappedAddress[] = { }; // Test XOR-mapped IP addresses: -static const uint8_t kStunMessageWithIPv6XorMappedAddress[] = { +const uint8_t kStunMessageWithIPv6XorMappedAddress[] = { 0x01, 0x01, 0x00, 0x18, // message header (binding response) 0x21, 0x12, 0xa4, 0x42, // magic cookie (rfc5389) 0xe3, 0xa9, 0x46, 0xe1, // transaction ID @@ -126,7 +77,7 @@ static const uint8_t kStunMessageWithIPv6XorMappedAddress[] = { 0xaa, 0xed, 0x01, 0xc3 }; -static const uint8_t kStunMessageWithIPv4XorMappedAddress[] = { +const uint8_t kStunMessageWithIPv4XorMappedAddress[] = { 0x01, 0x01, 0x00, 0x0c, // message header (binding response) 0x21, 0x12, 0xa4, 0x42, // magic cookie 0x29, 0x1f, 0xcd, 0x7c, // transaction ID @@ -138,7 +89,7 @@ static const uint8_t kStunMessageWithIPv4XorMappedAddress[] = { }; // ByteString Attribute (username) -static const uint8_t kStunMessageWithByteStringAttribute[] = { +const uint8_t kStunMessageWithByteStringAttribute[] = { 0x00, 0x01, 0x00, 0x0c, 0x21, 0x12, 0xa4, 0x42, 0xe3, 0xa9, 0x46, 0xe1, @@ -151,7 +102,7 @@ static const uint8_t kStunMessageWithByteStringAttribute[] = { // Message with an unknown but comprehensible optional attribute. // Parsing should succeed despite this unknown attribute. -static const uint8_t kStunMessageWithUnknownAttribute[] = { +const uint8_t kStunMessageWithUnknownAttribute[] = { 0x00, 0x01, 0x00, 0x14, 0x21, 0x12, 0xa4, 0x42, 0xe3, 0xa9, 0x46, 0xe1, @@ -165,7 +116,7 @@ static const uint8_t kStunMessageWithUnknownAttribute[] = { }; // ByteString Attribute (username) with padding byte -static const uint8_t kStunMessageWithPaddedByteStringAttribute[] = { +const uint8_t kStunMessageWithPaddedByteStringAttribute[] = { 0x00, 0x01, 0x00, 0x08, 0x21, 0x12, 0xa4, 0x42, 0xe3, 0xa9, 0x46, 0xe1, @@ -176,7 +127,7 @@ static const uint8_t kStunMessageWithPaddedByteStringAttribute[] = { }; // Message with an Unknown Attributes (uint16_t list) attribute. -static const uint8_t kStunMessageWithUInt16ListAttribute[] = { +const uint8_t kStunMessageWithUInt16ListAttribute[] = { 0x00, 0x01, 0x00, 0x0c, 0x21, 0x12, 0xa4, 0x42, 0xe3, 0xa9, 0x46, 0xe1, @@ -188,7 +139,7 @@ static const uint8_t kStunMessageWithUInt16ListAttribute[] = { }; // Error response message (unauthorized) -static const uint8_t kStunMessageWithErrorAttribute[] = { +const uint8_t kStunMessageWithErrorAttribute[] = { 0x01, 0x11, 0x00, 0x14, 0x21, 0x12, 0xa4, 0x42, 0x29, 0x1f, 0xcd, 0x7c, @@ -204,9 +155,9 @@ static const uint8_t kStunMessageWithErrorAttribute[] = { // Sample messages with an invalid length Field // The actual length in bytes of the invalid messages (including STUN header) -static const int kRealLengthOfInvalidLengthTestCases = 32; +const int kRealLengthOfInvalidLengthTestCases = 32; -static const uint8_t kStunMessageWithZeroLength[] = { +const uint8_t kStunMessageWithZeroLength[] = { 0x00, 0x01, 0x00, 0x00, // length of 0 (last 2 bytes) 0x21, 0x12, 0xA4, 0x42, // magic cookie '0', '1', '2', '3', // transaction id @@ -217,7 +168,7 @@ static const uint8_t kStunMessageWithZeroLength[] = { 0x21, 0x12, 0xA4, 0x53, }; -static const uint8_t kStunMessageWithExcessLength[] = { +const uint8_t kStunMessageWithExcessLength[] = { 0x00, 0x01, 0x00, 0x55, // length of 85 0x21, 0x12, 0xA4, 0x42, // magic cookie '0', '1', '2', '3', // transaction id @@ -228,7 +179,7 @@ static const uint8_t kStunMessageWithExcessLength[] = { 0x21, 0x12, 0xA4, 0x53, }; -static const uint8_t kStunMessageWithSmallLength[] = { +const uint8_t kStunMessageWithSmallLength[] = { 0x00, 0x01, 0x00, 0x03, // length of 3 0x21, 0x12, 0xA4, 0x42, // magic cookie '0', '1', '2', '3', // transaction id @@ -239,7 +190,7 @@ static const uint8_t kStunMessageWithSmallLength[] = { 0x21, 0x12, 0xA4, 0x53, }; -static const uint8_t kStunMessageWithBadHmacAtEnd[] = { +const uint8_t kStunMessageWithBadHmacAtEnd[] = { 0x00, 0x01, 0x00, 0x14, // message length exactly 20 0x21, 0x12, 0xA4, 0x42, // magic cookie '0', '1', '2', '3', // transaction ID @@ -254,7 +205,7 @@ static const uint8_t kStunMessageWithBadHmacAtEnd[] = { // RTCP packet, for testing we correctly ignore non stun packet types. // V=2, P=false, RC=0, Type=200, Len=6, Sender-SSRC=85, etc -static const uint8_t kRtcpPacket[] = { +const uint8_t kRtcpPacket[] = { 0x80, 0xc8, 0x00, 0x06, 0x00, 0x00, 0x00, 0x55, 0xce, 0xa5, 0x18, 0x3a, 0x39, 0xcc, 0x7d, 0x09, 0x23, 0xed, 0x19, 0x07, 0x00, 0x00, 0x01, 0x56, @@ -267,30 +218,30 @@ static const uint8_t kRtcpPacket[] = { // Software name (response): "test vector" (without quotes) // Username: "evtj:h6vY" (without quotes) // Password: "VOkJxbRl1RmTxUk/WvJxBt" (without quotes) -static const uint8_t kRfc5769SampleMsgTransactionId[] = { +const uint8_t kRfc5769SampleMsgTransactionId[] = { 0xb7, 0xe7, 0xa7, 0x01, 0xbc, 0x34, 0xd6, 0x86, 0xfa, 0x87, 0xdf, 0xae }; -static const char kRfc5769SampleMsgClientSoftware[] = "STUN test client"; -static const char kRfc5769SampleMsgServerSoftware[] = "test vector"; -static const char kRfc5769SampleMsgUsername[] = "evtj:h6vY"; -static const char kRfc5769SampleMsgPassword[] = "VOkJxbRl1RmTxUk/WvJxBt"; -static const SocketAddress kRfc5769SampleMsgMappedAddress( +const char kRfc5769SampleMsgClientSoftware[] = "STUN test client"; +const char kRfc5769SampleMsgServerSoftware[] = "test vector"; +const char kRfc5769SampleMsgUsername[] = "evtj:h6vY"; +const char kRfc5769SampleMsgPassword[] = "VOkJxbRl1RmTxUk/WvJxBt"; +const SocketAddress kRfc5769SampleMsgMappedAddress( "192.0.2.1", 32853); -static const SocketAddress kRfc5769SampleMsgIPv6MappedAddress( +const SocketAddress kRfc5769SampleMsgIPv6MappedAddress( "2001:db8:1234:5678:11:2233:4455:6677", 32853); -static const uint8_t kRfc5769SampleMsgWithAuthTransactionId[] = { +const uint8_t kRfc5769SampleMsgWithAuthTransactionId[] = { 0x78, 0xad, 0x34, 0x33, 0xc6, 0xad, 0x72, 0xc0, 0x29, 0xda, 0x41, 0x2e }; -static const char kRfc5769SampleMsgWithAuthUsername[] = +const char kRfc5769SampleMsgWithAuthUsername[] = "\xe3\x83\x9e\xe3\x83\x88\xe3\x83\xaa\xe3\x83\x83\xe3\x82\xaf\xe3\x82\xb9"; -static const char kRfc5769SampleMsgWithAuthPassword[] = "TheMatrIX"; -static const char kRfc5769SampleMsgWithAuthNonce[] = +const char kRfc5769SampleMsgWithAuthPassword[] = "TheMatrIX"; +const char kRfc5769SampleMsgWithAuthNonce[] = "f//499k954d6OL34oL9FSTvy64sA"; -static const char kRfc5769SampleMsgWithAuthRealm[] = "example.org"; +const char kRfc5769SampleMsgWithAuthRealm[] = "example.org"; // 2.1. Sample Request -static const uint8_t kRfc5769SampleRequest[] = { +const uint8_t kRfc5769SampleRequest[] = { 0x00, 0x01, 0x00, 0x58, // Request type and message length 0x21, 0x12, 0xa4, 0x42, // Magic cookie 0xb7, 0xe7, 0xa7, 0x01, // } @@ -321,7 +272,7 @@ static const uint8_t kRfc5769SampleRequest[] = { }; // 2.1. Sample Request -static const uint8_t kSampleRequestMI32[] = { +const uint8_t kSampleRequestMI32[] = { 0x00, 0x01, 0x00, 0x48, // Request type and message length 0x21, 0x12, 0xa4, 0x42, // Magic cookie 0xb7, 0xe7, 0xa7, 0x01, // } @@ -348,7 +299,7 @@ static const uint8_t kSampleRequestMI32[] = { }; // 2.2. Sample IPv4 Response -static const uint8_t kRfc5769SampleResponse[] = { +const uint8_t kRfc5769SampleResponse[] = { 0x01, 0x01, 0x00, 0x3c, // Response type and message length 0x21, 0x12, 0xa4, 0x42, // Magic cookie 0xb7, 0xe7, 0xa7, 0x01, // } @@ -372,7 +323,7 @@ static const uint8_t kRfc5769SampleResponse[] = { }; // 2.3. Sample IPv6 Response -static const uint8_t kRfc5769SampleResponseIPv6[] = { +const uint8_t kRfc5769SampleResponseIPv6[] = { 0x01, 0x01, 0x00, 0x48, // Response type and message length 0x21, 0x12, 0xa4, 0x42, // Magic cookie 0xb7, 0xe7, 0xa7, 0x01, // } @@ -399,7 +350,7 @@ static const uint8_t kRfc5769SampleResponseIPv6[] = { }; // 2.4. Sample Request with Long-Term Authentication -static const uint8_t kRfc5769SampleRequestLongTermAuth[] = { +const uint8_t kRfc5769SampleRequestLongTermAuth[] = { 0x00, 0x01, 0x00, 0x60, // Request type and message length 0x21, 0x12, 0xa4, 0x42, // Magic cookie 0x78, 0xad, 0x34, 0x33, // } @@ -434,7 +385,7 @@ static const uint8_t kRfc5769SampleRequestLongTermAuth[] = { // Length parameter is changed to 0x38 from 0x58. // AddMessageIntegrity will add MI information and update the length param // accordingly. -static const uint8_t kRfc5769SampleRequestWithoutMI[] = { +const uint8_t kRfc5769SampleRequestWithoutMI[] = { 0x00, 0x01, 0x00, 0x38, // Request type and message length 0x21, 0x12, 0xa4, 0x42, // Magic cookie 0xb7, 0xe7, 0xa7, 0x01, // } @@ -458,7 +409,7 @@ static const uint8_t kRfc5769SampleRequestWithoutMI[] = { // This HMAC differs from the RFC 5769 SampleRequest message. This differs // because spec uses 0x20 for the padding where as our implementation uses 0. -static const uint8_t kCalculatedHmac1[] = { +const uint8_t kCalculatedHmac1[] = { 0x79, 0x07, 0xc2, 0xd2, // } 0xed, 0xbf, 0xea, 0x48, // } 0x0e, 0x4c, 0x76, 0xd8, // } HMAC-SHA1 fingerprint @@ -470,14 +421,14 @@ static const uint8_t kCalculatedHmac1[] = { // above since the sum is computed including header // and the header is different since the message is shorter // than when MESSAGE-INTEGRITY is used. -static const uint8_t kCalculatedHmac1_32[] = { +const uint8_t kCalculatedHmac1_32[] = { 0xda, 0x39, 0xde, 0x5d, // } }; // Length parameter is changed to 0x1c from 0x3c. // AddMessageIntegrity will add MI information and update the length param // accordingly. -static const uint8_t kRfc5769SampleResponseWithoutMI[] = { +const uint8_t kRfc5769SampleResponseWithoutMI[] = { 0x01, 0x01, 0x00, 0x1c, // Response type and message length 0x21, 0x12, 0xa4, 0x42, // Magic cookie 0xb7, 0xe7, 0xa7, 0x01, // } @@ -494,7 +445,7 @@ static const uint8_t kRfc5769SampleResponseWithoutMI[] = { // This HMAC differs from the RFC 5769 SampleResponse message. This differs // because spec uses 0x20 for the padding where as our implementation uses 0. -static const uint8_t kCalculatedHmac2[] = { +const uint8_t kCalculatedHmac2[] = { 0x5d, 0x6b, 0x58, 0xbe, // } 0xad, 0x94, 0xe0, 0x7e, // } 0xef, 0x0d, 0xfc, 0x12, // } HMAC-SHA1 fingerprint @@ -506,7 +457,7 @@ static const uint8_t kCalculatedHmac2[] = { // above since the sum is computed including header // and the header is different since the message is shorter // than when MESSAGE-INTEGRITY is used. -static const uint8_t kCalculatedHmac2_32[] = { +const uint8_t kCalculatedHmac2_32[] = { 0xe7, 0x5c, 0xd3, 0x16, // } }; @@ -547,6 +498,59 @@ const int kTestMessagePort1 = 59977; const int kTestMessagePort2 = 47233; const int kTestMessagePort3 = 56743; const int kTestMessagePort4 = 40444; +} // namespace + +class StunTest : public ::testing::Test { + protected: + void CheckStunHeader(const StunMessage& msg, + StunMessageType expected_type, + size_t expected_length) { + ASSERT_EQ(expected_type, msg.type()); + ASSERT_EQ(expected_length, msg.length()); + } + + void CheckStunTransactionID(const StunMessage& msg, + const uint8_t* expectedID, + size_t length) { + ASSERT_EQ(length, msg.transaction_id().size()); + ASSERT_EQ(length == kStunTransactionIdLength + 4, msg.IsLegacy()); + ASSERT_EQ(length == kStunTransactionIdLength, !msg.IsLegacy()); + ASSERT_EQ(0, memcmp(msg.transaction_id().c_str(), expectedID, length)); + } + + void CheckStunAddressAttribute(const StunAddressAttribute* addr, + StunAddressFamily expected_family, + int expected_port, + const IPAddress& expected_address) { + ASSERT_EQ(expected_family, addr->family()); + ASSERT_EQ(expected_port, addr->port()); + + if (addr->family() == STUN_ADDRESS_IPV4) { + in_addr v4_address = expected_address.ipv4_address(); + in_addr stun_address = addr->ipaddr().ipv4_address(); + ASSERT_EQ(0, memcmp(&v4_address, &stun_address, sizeof(stun_address))); + } else if (addr->family() == STUN_ADDRESS_IPV6) { + in6_addr v6_address = expected_address.ipv6_address(); + in6_addr stun_address = addr->ipaddr().ipv6_address(); + ASSERT_EQ(0, memcmp(&v6_address, &stun_address, sizeof(stun_address))); + } else { + ASSERT_TRUE(addr->family() == STUN_ADDRESS_IPV6 || + addr->family() == STUN_ADDRESS_IPV4); + } + } + + size_t ReadStunMessageTestCase(StunMessage* msg, + const uint8_t* testcase, + size_t size) { + ByteBufferReader buf(MakeArrayView(testcase, size)); + if (msg->Read(&buf)) { + // Returns the size the stun message should report itself as being + return (size - 20); + } else { + return 0; + } + } +}; #define ReadStunMessage(X, Y) ReadStunMessageTestCase(X, Y, sizeof(Y)); @@ -1725,4 +1729,31 @@ TEST_F(StunTest, ValidateMessageIntegrityWithParser) { EXPECT_EQ(metrics::NumSamples("WebRTC.Stun.Integrity.Request"), 2); } +TEST_F(StunTest, ByteStringAsVectorOfUint32) { + StunMessage message; + ByteBufferReader reader(kRfc5769SampleRequest); + EXPECT_TRUE(message.Read(&reader)); + + // The username attribute has a length which is not a multiple of 4 + // so getting a uint32_t vector from it should fail. + const StunByteStringAttribute* username = + message.GetByteString(STUN_ATTR_USERNAME); + ASSERT_TRUE(username); + EXPECT_FALSE(username->GetUInt32Vector()); + + // message-integrity is 20 bytes which makes it usable as a test case. + const StunByteStringAttribute* integrity = + message.GetByteString(STUN_ATTR_MESSAGE_INTEGRITY); + ASSERT_TRUE(integrity); + std::optional<std::vector<uint32_t>> integrity_vector = + integrity->GetUInt32Vector(); + ASSERT_TRUE(integrity_vector); + EXPECT_EQ(5U, integrity_vector->size()); + // Taken from the RFC 5769 sample request. + std::vector<uint32_t> expected_integrity_vector = { + 0x9aeaa70c, 0xbfd8cb56, 0x781ef2b5, 0xb2d3f249, 0xc1b571a2}; + EXPECT_THAT(*integrity_vector, + ::testing::ElementsAreArray(expected_integrity_vector)); +} + } // namespace webrtc diff --git a/third_party/libwebrtc/p2p/base/connection.cc b/third_party/libwebrtc/p2p/base/connection.cc @@ -629,6 +629,25 @@ void Connection::MaybeAddDtlsPiggybackingAttributes(StunMessage* msg) { } } +void Connection::MaybeHandleDtlsPiggybackingAttributes(const StunMessage* msg) { + if (dtls_stun_piggyback_callbacks_.empty()) { + return; + } + const StunByteStringAttribute* dtls_piggyback_attr = + msg->GetByteString(STUN_ATTR_META_DTLS_IN_STUN); + const StunByteStringAttribute* dtls_piggyback_ack = + msg->GetByteString(STUN_ATTR_META_DTLS_IN_STUN_ACK); + std::optional<ArrayView<uint8_t>> piggyback_data; + if (dtls_piggyback_attr != nullptr) { + piggyback_data = dtls_piggyback_attr->array_view(); + } + std::optional<std::vector<uint32_t>> piggyback_acks; + if (dtls_piggyback_ack != nullptr) { + piggyback_acks = dtls_piggyback_ack->GetUInt32Vector(); + } + dtls_stun_piggyback_callbacks_.recv_data(piggyback_data, piggyback_acks); +} + void Connection::HandleStunBindingOrGoogPingRequest(IceMessage* msg) { RTC_DCHECK_RUN_ON(network_thread_); // This connection should now be receiving. @@ -671,14 +690,7 @@ void Connection::HandleStunBindingOrGoogPingRequest(IceMessage* msg) { // This is a validated stun request from remote peer. if (msg->type() == STUN_BINDING_REQUEST) { - if (!dtls_stun_piggyback_callbacks_.empty()) { - const StunByteStringAttribute* dtls_piggyback_attribute = - msg->GetByteString(STUN_ATTR_META_DTLS_IN_STUN); - const StunByteStringAttribute* dtls_piggyback_ack = - msg->GetByteString(STUN_ATTR_META_DTLS_IN_STUN_ACK); - dtls_stun_piggyback_callbacks_.recv_data(dtls_piggyback_attribute, - dtls_piggyback_ack); - } + MaybeHandleDtlsPiggybackingAttributes(msg); SendStunBindingResponse(msg); } else { RTC_DCHECK(msg->type() == GOOG_PING_REQUEST); @@ -1541,20 +1553,12 @@ void Connection::OnConnectionRequestResponse(StunRequest* request, RTC_LOG(LS_ERROR) << "Discard GOOG_DELTA_ACK, no consumer"; } - if (!dtls_stun_piggyback_callbacks_.empty()) { - const bool sent_dtls_piggyback = - request->msg()->GetByteString(STUN_ATTR_META_DTLS_IN_STUN) != nullptr; - const bool sent_dtls_piggyback_ack = - request->msg()->GetByteString(STUN_ATTR_META_DTLS_IN_STUN_ACK) != - nullptr; - const StunByteStringAttribute* dtls_piggyback_attr = - response->GetByteString(STUN_ATTR_META_DTLS_IN_STUN); - const StunByteStringAttribute* dtls_piggyback_ack = - response->GetByteString(STUN_ATTR_META_DTLS_IN_STUN_ACK); - if (sent_dtls_piggyback || sent_dtls_piggyback_ack) { - dtls_stun_piggyback_callbacks_.recv_data(dtls_piggyback_attr, - dtls_piggyback_ack); - } + const bool sent_dtls_piggyback = + request->msg()->GetByteString(STUN_ATTR_META_DTLS_IN_STUN) != nullptr; + const bool sent_dtls_piggyback_ack = + request->msg()->GetByteString(STUN_ATTR_META_DTLS_IN_STUN_ACK) != nullptr; + if (sent_dtls_piggyback || sent_dtls_piggyback_ack) { + MaybeHandleDtlsPiggybackingAttributes(response); } } diff --git a/third_party/libwebrtc/p2p/base/connection.h b/third_party/libwebrtc/p2p/base/connection.h @@ -519,6 +519,7 @@ class RTC_EXPORT Connection : public CandidatePairInterface { received_packet_callback_; void MaybeAddDtlsPiggybackingAttributes(StunMessage* msg); + void MaybeHandleDtlsPiggybackingAttributes(const StunMessage* msg); DtlsStunPiggybackCallbacks dtls_stun_piggyback_callbacks_; }; diff --git a/third_party/libwebrtc/p2p/base/p2p_transport_channel_unittest.cc b/third_party/libwebrtc/p2p/base/p2p_transport_channel_unittest.cc @@ -7575,8 +7575,8 @@ class P2PTransportChannelTestDtlsInStun : public P2PTransportChannelTestBase { return make_pair(absl::string_view(pending_packet_), std::nullopt); } - void piggyback_data_received(const StunByteStringAttribute* data, - const StunByteStringAttribute* ack) {} + void piggyback_data_received(std::optional<ArrayView<uint8_t>> data, + std::optional<std::vector<uint32_t>> ack) {} ScopedFakeClock clock_; Buffer pending_packet_; diff --git a/third_party/libwebrtc/p2p/dtls/dtls_stun_piggyback_callbacks.h b/third_party/libwebrtc/p2p/dtls/dtls_stun_piggyback_callbacks.h @@ -11,11 +11,14 @@ #ifndef P2P_DTLS_DTLS_STUN_PIGGYBACK_CALLBACKS_H_ #define P2P_DTLS_DTLS_STUN_PIGGYBACK_CALLBACKS_H_ +#include <cstdint> #include <optional> #include <utility> +#include <vector> #include "absl/functional/any_invocable.h" #include "absl/strings/string_view.h" +#include "api/array_view.h" #include "api/transport/stun.h" #include "rtc_base/checks.h" @@ -35,10 +38,11 @@ class DtlsStunPiggybackCallbacks { /* request-type */ StunMessageType)>&& send_data, // Function invoked when receiving a STUN_BINDING { REQUEST / RESPONSE } - // contains the (nullable) DTLS_IN_STUN and DTLS_IN_STUN_ACK attributes. + // contains the optional ArrayViews of the DTLS_IN_STUN and + // DTLS_IN_STUN_ACK attributes. absl::AnyInvocable<void( - const StunByteStringAttribute* /* DTLS_IN_STUN */, - const StunByteStringAttribute* /* DTLS_IN_STUN_ACK */)>&& recv_data) + std::optional<ArrayView<uint8_t>> /* recv_data */, + std::optional<std::vector<uint32_t>> /* recv_acks */)>&& recv_data) : send_data_(std::move(send_data)), recv_data_(std::move(recv_data)) { RTC_DCHECK( // either all set @@ -53,10 +57,10 @@ class DtlsStunPiggybackCallbacks { return send_data_(request_type); } - void recv_data(const StunByteStringAttribute* data, - const StunByteStringAttribute* ack) { + void recv_data(std::optional<ArrayView<uint8_t>> data, + std::optional<std::vector<uint32_t>> acks) { RTC_DCHECK(recv_data_); - return recv_data_(data, ack); + return recv_data_(data, acks); } bool empty() const { return send_data_ == nullptr; } @@ -70,9 +74,8 @@ class DtlsStunPiggybackCallbacks { std::optional<absl::string_view>>( /* request-type */ StunMessageType)> send_data_; - absl::AnyInvocable<void( - const StunByteStringAttribute* /* DTLS_IN_STUN */, - const StunByteStringAttribute* /* DTLS_IN_STUN_ACK */)> + absl::AnyInvocable<void(std::optional<ArrayView<uint8_t>> /* recv_data */, + std::optional<std::vector<uint32_t>> /* recv_acks */)> recv_data_; }; diff --git a/third_party/libwebrtc/p2p/dtls/dtls_stun_piggyback_controller.cc b/third_party/libwebrtc/p2p/dtls/dtls_stun_piggyback_controller.cc @@ -139,8 +139,8 @@ std::optional<absl::string_view> DtlsStunPiggybackController::GetAckToPiggyback( } void DtlsStunPiggybackController::ReportDataPiggybacked( - const StunByteStringAttribute* data, - const StunByteStringAttribute* ack) { + std::optional<ArrayView<uint8_t>> data, + std::optional<std::vector<uint32_t>> acks) { RTC_DCHECK_RUN_ON(&sequence_checker_); // Drop silently when receiving acked data when the peer previously did not @@ -152,7 +152,7 @@ void DtlsStunPiggybackController::ReportDataPiggybacked( // We sent dtls piggybacked but got nothing in return or // we received a stun request with neither attribute set // => peer does not support. - if (state_ == State::TENTATIVE && data == nullptr && ack == nullptr) { + if (state_ == State::TENTATIVE && !data.has_value() && !acks.has_value()) { RTC_LOG(LS_INFO) << "DTLS-STUN piggybacking not supported by peer."; state_ = State::OFF; return; @@ -160,7 +160,7 @@ void DtlsStunPiggybackController::ReportDataPiggybacked( // In PENDING state the peer may have stopped sending the ack // when it moved to the COMPLETE state. Move to the same state. - if (state_ == State::PENDING && data == nullptr && ack == nullptr) { + if (state_ == State::PENDING && !data.has_value() && !acks.has_value()) { RTC_LOG(LS_INFO) << "DTLS-STUN piggybacking complete."; state_ = State::COMPLETE; pending_packets_.clear(); @@ -174,16 +174,12 @@ void DtlsStunPiggybackController::ReportDataPiggybacked( state_ = State::CONFIRMED; } - if (ack != nullptr) { + if (acks.has_value()) { if (!pending_packets_.empty()) { // Unpack the ACK attribute (a list of uint32_t) absl::flat_hash_set<uint32_t> acked_packets; - { - ByteBufferReader ack_reader(ack->array_view()); - uint32_t packet_hash; - while (ack_reader.ReadUInt32(&packet_hash)) { - acked_packets.insert(packet_hash); - } + for (const auto& ack : *acks) { + acked_packets.insert(ack); } RTC_LOG(LS_VERBOSE) << "DTLS-STUN piggybacking ACK: " << StrJoin(acked_packets, ","); @@ -197,7 +193,7 @@ void DtlsStunPiggybackController::ReportDataPiggybacked( // the DTLS data but will contain an ack. // Must not happen on the initial server to client packet which // has no DTLS data yet. - if (data == nullptr && ack != nullptr && state_ == State::PENDING) { + if (!data.has_value() && acks.has_value() && state_ == State::PENDING) { RTC_LOG(LS_INFO) << "DTLS-STUN piggybacking complete."; state_ = State::COMPLETE; pending_packets_.clear(); @@ -206,12 +202,12 @@ void DtlsStunPiggybackController::ReportDataPiggybacked( return; } - if (!data || data->length() == 0) { + if (!data.has_value() || data->size() == 0) { return; } // Drop non-DTLS packets. - if (!IsDtlsPacket(data->array_view())) { + if (!IsDtlsPacket(*data)) { RTC_LOG(LS_WARNING) << "Dropping non-DTLS data."; return; } @@ -219,7 +215,7 @@ void DtlsStunPiggybackController::ReportDataPiggybacked( // Extract the received message id of the handshake // from the packet and prepare the ack to be sent. - uint32_t hash = ComputeDtlsPacketHash(data->array_view()); + uint32_t hash = ComputeDtlsPacketHash(*data); // Check if we already received this packet. if (std::find(handshake_messages_received_.begin(), @@ -240,7 +236,7 @@ void DtlsStunPiggybackController::ReportDataPiggybacked( RTC_DCHECK(handshake_ack_writer_.Length() <= kMaxAckSize); } - dtls_data_callback_(data->array_view()); + dtls_data_callback_(*data); } } // namespace webrtc diff --git a/third_party/libwebrtc/p2p/dtls/dtls_stun_piggyback_controller.h b/third_party/libwebrtc/p2p/dtls/dtls_stun_piggyback_controller.h @@ -82,8 +82,8 @@ class DtlsStunPiggybackController { StunMessageType stun_message_type); // Called by Connection when receiving a STUN BINDING { REQUEST / RESPONSE }. - void ReportDataPiggybacked(const StunByteStringAttribute* data, - const StunByteStringAttribute* ack); + void ReportDataPiggybacked(std::optional<ArrayView<uint8_t>> data, + std::optional<std::vector<uint32_t>> acks); int GetCountOfReceivedData() const { return data_recv_count_; } diff --git a/third_party/libwebrtc/p2p/dtls/dtls_stun_piggyback_controller_unittest.cc b/third_party/libwebrtc/p2p/dtls/dtls_stun_piggyback_controller_unittest.cc @@ -21,6 +21,7 @@ #include "api/transport/stun.h" #include "p2p/dtls/dtls_utils.h" #include "rtc_base/byte_buffer.h" +#include "rtc_base/checks.h" #include "test/gmock.h" #include "test/gtest.h" @@ -64,6 +65,17 @@ std::string AsAckAttribute(const std::vector<uint32_t>& list) { return std::string(writer.DataAsStringView()); } +std::vector<uint32_t> FromAckAttribute(webrtc::ArrayView<uint8_t> attr) { + webrtc::ByteBufferReader ack_reader(attr); + std::vector<uint32_t> values; + uint32_t value; + while (ack_reader.ReadUInt32(&value)) { + values.push_back(value); + } + RTC_DCHECK_EQ(ack_reader.Length(), 0); + return values; +} + std::vector<uint8_t> FakeDtlsPacket(uint16_t packet_number) { auto packet = dtls_flight1; packet[17] = static_cast<uint8_t>(packet_number >> 8); @@ -71,6 +83,19 @@ std::vector<uint8_t> FakeDtlsPacket(uint16_t packet_number) { return packet; } +std::unique_ptr<webrtc::StunByteStringAttribute> WrapInStun( + webrtc::IceAttributeType type, + absl::string_view data) { + return std::make_unique<webrtc::StunByteStringAttribute>(type, data); +} + +std::unique_ptr<webrtc::StunByteStringAttribute> WrapInStun( + webrtc::IceAttributeType type, + const std::vector<uint8_t>& data) { + return std::make_unique<webrtc::StunByteStringAttribute>(type, data.data(), + data.size()); +} + } // namespace namespace webrtc { @@ -87,7 +112,7 @@ class DtlsStunPiggybackControllerTest : public ::testing::Test { ServerPacketSink(data); }) {} - void SendClientToServer(const std::vector<uint8_t> packet, + void SendClientToServer(const std::vector<uint8_t>& packet, StunMessageType type) { if (!packet.empty()) { client_.CapturePacket(packet); @@ -96,16 +121,20 @@ class DtlsStunPiggybackControllerTest : public ::testing::Test { client_.ClearCachedPacketForTesting(); } std::unique_ptr<StunByteStringAttribute> attr_data; + std::optional<ArrayView<uint8_t>> view_data; if (auto data = client_.GetDataToPiggyback(type)) { attr_data = WrapInStun(STUN_ATTR_META_DTLS_IN_STUN, *data); + view_data = attr_data->array_view(); } std::unique_ptr<StunByteStringAttribute> attr_ack; + std::optional<std::vector<uint32_t>> view_acks; if (auto ack = client_.GetAckToPiggyback(type)) { attr_ack = WrapInStun(STUN_ATTR_META_DTLS_IN_STUN_ACK, *ack); + view_acks = FromAckAttribute(attr_ack->array_view()); } - server_.ReportDataPiggybacked(attr_data.get(), attr_ack.get()); + server_.ReportDataPiggybacked(view_data, view_acks); } - void SendServerToClient(const std::vector<uint8_t> packet, + void SendServerToClient(const std::vector<uint8_t>& packet, StunMessageType type) { if (!packet.empty()) { server_.CapturePacket(packet); @@ -114,14 +143,18 @@ class DtlsStunPiggybackControllerTest : public ::testing::Test { server_.ClearCachedPacketForTesting(); } std::unique_ptr<StunByteStringAttribute> attr_data; + std::optional<ArrayView<uint8_t>> view_data; if (auto data = server_.GetDataToPiggyback(type)) { attr_data = WrapInStun(STUN_ATTR_META_DTLS_IN_STUN, *data); + view_data = attr_data->array_view(); } std::unique_ptr<StunByteStringAttribute> attr_ack; + std::optional<std::vector<uint32_t>> view_acks; if (auto ack = server_.GetAckToPiggyback(type)) { attr_ack = WrapInStun(STUN_ATTR_META_DTLS_IN_STUN_ACK, *ack); + view_acks = FromAckAttribute(attr_ack->array_view()); } - client_.ReportDataPiggybacked(attr_data.get(), attr_ack.get()); + client_.ReportDataPiggybacked(view_data, view_acks); if (packet == dtls_flight4) { // After sending flight 4, the server handshake is complete. server_.SetDtlsHandshakeComplete(/*is_client=*/false, @@ -131,21 +164,9 @@ class DtlsStunPiggybackControllerTest : public ::testing::Test { } } - std::unique_ptr<StunByteStringAttribute> WrapInStun(IceAttributeType type, - absl::string_view data) { - return std::make_unique<StunByteStringAttribute>(type, data); - } - - std::unique_ptr<StunByteStringAttribute> WrapInStun( - IceAttributeType type, - const std::vector<uint8_t>& data) { - return std::make_unique<StunByteStringAttribute>(type, data.data(), - data.size()); - } - void DisableSupport(DtlsStunPiggybackController& client_or_server) { ASSERT_EQ(client_or_server.state(), State::TENTATIVE); - client_or_server.ReportDataPiggybacked(nullptr, nullptr); + client_or_server.ReportDataPiggybacked(std::nullopt, std::nullopt); ASSERT_EQ(client_or_server.state(), State::OFF); } @@ -346,7 +367,8 @@ TEST_F(DtlsStunPiggybackControllerTest, IgnoresNonDtlsData) { EXPECT_CALL(*this, ServerPacketSink).Times(0); server_.ReportDataPiggybacked( - WrapInStun(STUN_ATTR_META_DTLS_IN_STUN, ascii).get(), nullptr); + WrapInStun(STUN_ATTR_META_DTLS_IN_STUN, ascii)->array_view(), + std::nullopt); EXPECT_EQ(0, server_.GetCountOfReceivedData()); } @@ -355,9 +377,8 @@ TEST_F(DtlsStunPiggybackControllerTest, DontSendAckedPackets) { server_.Flush(); EXPECT_TRUE(server_.GetDataToPiggyback(STUN_BINDING_REQUEST).has_value()); server_.ReportDataPiggybacked( - nullptr, WrapInStun(STUN_ATTR_META_DTLS_IN_STUN_ACK, - AsAckAttribute({ComputeDtlsPacketHash(dtls_flight1)})) - .get()); + std::nullopt, + std::vector<uint32_t>({ComputeDtlsPacketHash(dtls_flight1)})); // No unacked packet exists. EXPECT_FALSE(server_.GetDataToPiggyback(STUN_BINDING_REQUEST).has_value()); } @@ -366,21 +387,26 @@ TEST_F(DtlsStunPiggybackControllerTest, LimitAckSize) { std::vector<uint8_t> dtls_flight5 = FakeDtlsPacket(0x5487); server_.ReportDataPiggybacked( - WrapInStun(STUN_ATTR_META_DTLS_IN_STUN, dtls_flight1).get(), nullptr); + WrapInStun(STUN_ATTR_META_DTLS_IN_STUN, dtls_flight1)->array_view(), + std::nullopt); EXPECT_EQ(server_.GetAckToPiggyback(STUN_BINDING_REQUEST)->size(), 4u); server_.ReportDataPiggybacked( - WrapInStun(STUN_ATTR_META_DTLS_IN_STUN, dtls_flight2).get(), nullptr); + WrapInStun(STUN_ATTR_META_DTLS_IN_STUN, dtls_flight2)->array_view(), + std::nullopt); EXPECT_EQ(server_.GetAckToPiggyback(STUN_BINDING_REQUEST)->size(), 8u); server_.ReportDataPiggybacked( - WrapInStun(STUN_ATTR_META_DTLS_IN_STUN, dtls_flight3).get(), nullptr); + WrapInStun(STUN_ATTR_META_DTLS_IN_STUN, dtls_flight3)->array_view(), + std::nullopt); EXPECT_EQ(server_.GetAckToPiggyback(STUN_BINDING_REQUEST)->size(), 12u); server_.ReportDataPiggybacked( - WrapInStun(STUN_ATTR_META_DTLS_IN_STUN, dtls_flight4).get(), nullptr); + WrapInStun(STUN_ATTR_META_DTLS_IN_STUN, dtls_flight4)->array_view(), + std::nullopt); EXPECT_EQ(server_.GetAckToPiggyback(STUN_BINDING_REQUEST)->size(), 16u); // Limit size of ack so that it does not grow unbounded. server_.ReportDataPiggybacked( - WrapInStun(STUN_ATTR_META_DTLS_IN_STUN, dtls_flight5).get(), nullptr); + WrapInStun(STUN_ATTR_META_DTLS_IN_STUN, dtls_flight5)->array_view(), + std::nullopt); EXPECT_EQ(server_.GetAckToPiggyback(STUN_BINDING_REQUEST)->size(), DtlsStunPiggybackController::kMaxAckSize); EXPECT_EQ(server_.GetAckToPiggyback(STUN_BINDING_REQUEST), @@ -406,9 +432,8 @@ TEST_F(DtlsStunPiggybackControllerTest, MultiPacketRoundRobin) { std::string(dtls_flight3.begin(), dtls_flight3.end())); server_.ReportDataPiggybacked( - nullptr, WrapInStun(STUN_ATTR_META_DTLS_IN_STUN_ACK, - AsAckAttribute({ComputeDtlsPacketHash(dtls_flight1)})) - .get()); + std::nullopt, + std::vector<uint32_t>({ComputeDtlsPacketHash(dtls_flight1)})); EXPECT_EQ(server_.GetDataToPiggyback(STUN_BINDING_REQUEST), std::string(dtls_flight2.begin(), dtls_flight2.end())); @@ -416,9 +441,8 @@ TEST_F(DtlsStunPiggybackControllerTest, MultiPacketRoundRobin) { std::string(dtls_flight3.begin(), dtls_flight3.end())); server_.ReportDataPiggybacked( - nullptr, WrapInStun(STUN_ATTR_META_DTLS_IN_STUN_ACK, - AsAckAttribute({ComputeDtlsPacketHash(dtls_flight3)})) - .get()); + std::nullopt, + std::vector<uint32_t>({ComputeDtlsPacketHash(dtls_flight3)})); EXPECT_EQ(server_.GetDataToPiggyback(STUN_BINDING_REQUEST), std::string(dtls_flight2.begin(), dtls_flight2.end())); diff --git a/third_party/libwebrtc/p2p/dtls/dtls_transport.cc b/third_party/libwebrtc/p2p/dtls/dtls_transport.cc @@ -17,6 +17,7 @@ #include <optional> #include <string> #include <utility> +#include <vector> #include "absl/functional/any_invocable.h" #include "absl/strings/string_view.h" @@ -648,11 +649,12 @@ void DtlsTransportInternalImpl::ConnectToIceTransport() { } return std::make_pair(data, ack); }, - [&](auto data, auto ack) { + [&](std::optional<ArrayView<uint8_t>> data, + std::optional<std::vector<uint32_t>> acks) { if (!dtls_in_stun_) { return; } - dtls_stun_piggyback_controller_.ReportDataPiggybacked(data, ack); + dtls_stun_piggyback_controller_.ReportDataPiggybacked(data, acks); })); SetPiggybackDtlsDataCallback([this](PacketTransportInternal* transport, const ReceivedIpPacket& packet) { diff --git a/third_party/libwebrtc/p2p/dtls/dtls_utils.h b/third_party/libwebrtc/p2p/dtls/dtls_utils.h @@ -14,7 +14,6 @@ #include <cstddef> #include <cstdint> #include <memory> -#include <optional> #include <vector> #include "absl/container/flat_hash_set.h" @@ -30,9 +29,6 @@ bool IsDtlsPacket(ArrayView<const uint8_t> payload); bool IsDtlsClientHelloPacket(ArrayView<const uint8_t> payload); bool IsDtlsHandshakePacket(ArrayView<const uint8_t> payload); -std::optional<std::vector<uint16_t>> GetDtlsHandshakeAcks( - ArrayView<const uint8_t> dtls_packet); - uint32_t ComputeDtlsPacketHash(ArrayView<const uint8_t> dtls_packet); class PacketStash { @@ -75,7 +71,6 @@ class PacketStash { // TODO(bugs.webrtc.org/4222596): Remove once all references are updated. #ifdef WEBRTC_ALLOW_DEPRECATED_NAMESPACES namespace cricket { -using ::webrtc::GetDtlsHandshakeAcks; using ::webrtc::IsDtlsClientHelloPacket; using ::webrtc::IsDtlsHandshakePacket; using ::webrtc::IsDtlsPacket; diff --git a/third_party/libwebrtc/p2p/test/fake_ice_transport.h b/third_party/libwebrtc/p2p/test/fake_ice_transport.h @@ -19,6 +19,7 @@ #include <optional> #include <string> #include <utility> +#include <vector> #include "absl/functional/any_invocable.h" #include "absl/strings/string_view.h" @@ -579,8 +580,15 @@ class FakeIceTransport : public IceTransportInternal { << " attr: " << (dtls_piggyback_attr != nullptr) << " ack: " << (dtls_piggyback_ack != nullptr); if (!dtls_stun_piggyback_callbacks_.empty()) { - dtls_stun_piggyback_callbacks_.recv_data(dtls_piggyback_attr, - dtls_piggyback_ack); + std::optional<ArrayView<uint8_t>> piggyback_attr; + if (dtls_piggyback_attr) { + piggyback_attr = dtls_piggyback_attr->array_view(); + } + std::optional<std::vector<uint32_t>> piggyback_ack; + if (dtls_piggyback_ack) { + piggyback_ack = dtls_piggyback_ack->GetUInt32Vector(); + } + dtls_stun_piggyback_callbacks_.recv_data(piggyback_attr, piggyback_ack); } if (msg->type() == STUN_BINDING_RESPONSE) {