Replace ArrayView with std::span in p2p/ Bug: webrtc:439801349 Change-Id: I8eba2062fae69944dab44afb6459c45427deafa3 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/454302 Reviewed-by: Evan Shrubsole <eshr@webrtc.org> Auto-Submit: Danil Chapovalov <danilchap@webrtc.org> Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/main@{#47090}
diff --git a/p2p/BUILD.gn b/p2p/BUILD.gn index f08c9eb..0b11310 100644 --- a/p2p/BUILD.gn +++ b/p2p/BUILD.gn
@@ -47,7 +47,6 @@ "base/async_stun_tcp_socket.h", ] deps = [ - "../api:array_view", "../api/environment", "../api/transport:stun_types", "../rtc_base:async_packet_socket", @@ -78,7 +77,6 @@ ":p2p_constants", ":p2p_transport_channel_ice_field_trials", ":transport_description", - "../api:array_view", "../api:candidate", "../api/environment", "../api/transport:enums", @@ -188,7 +186,6 @@ ":port_interface", ":stun_request", ":transport_description", - "../api:array_view", "../api:candidate", "../api:rtc_error", "../api:sequence_checker", @@ -267,7 +264,6 @@ ":dtls_utils", ":ice_transport_internal", ":packet_transport_internal", - "../api:array_view", "../api:dtls_transport_interface", "../api:field_trials_view", "../api:ice_transport_interface", @@ -345,7 +341,6 @@ ":connection", ":ice_switch_reason", ":transport_description", - "../api:array_view", "../api/units:timestamp", ] } @@ -360,7 +355,6 @@ ":ice_switch_reason", ":ice_transport_internal", ":transport_description", - "../api:array_view", "../api/units:time_delta", "../api/units:timestamp", "../rtc_base:checks", @@ -414,7 +408,6 @@ ":port", ":stun_dictionary", ":transport_description", - "../api:array_view", "../api:candidate", "../api:peer_connection_interface", "../api:rtc_error", @@ -468,7 +461,6 @@ ":stun_dictionary", ":transport_description", ":wrapping_active_ice_controller", - "../api:array_view", "../api:async_dns_resolver", "../api:candidate", "../api:field_trials_view", @@ -550,7 +542,6 @@ ":port_interface", ":stun_request", ":transport_description", - "../api:array_view", "../api:candidate", "../api:local_network_access_permission", "../api:packet_socket_factory", @@ -655,7 +646,6 @@ "dtls/dtls_utils.h", ] deps = [ - "../api:array_view", "../rtc_base:buffer", "../rtc_base:checks", "../rtc_base:crc32", @@ -671,7 +661,6 @@ ] deps = [ ":dtls_utils", - "../api:array_view", "../api:sequence_checker", "../api/transport:stun_types", "../rtc_base:checks", @@ -733,7 +722,6 @@ "base/stun_request.h", ] deps = [ - "../api:array_view", "../api:sequence_checker", "../api/environment", "../api/task_queue", @@ -840,7 +828,6 @@ ":port_interface", ":relay_port_factory_interface", ":stun_request", - "../api:array_view", "../api:async_dns_resolver", "../api:candidate", "../api:local_network_access_permission", @@ -944,7 +931,6 @@ ":ice_transport_internal", ":port", ":transport_description", - "../api:array_view", "../api:candidate", "../api:field_trials", "../api:ice_transport_interface", @@ -1047,7 +1033,6 @@ ":packet_transport_internal", ":port_interface", ":transport_description", - "../api:array_view", "../api:async_dns_resolver", "../api:candidate", "../api:dtls_transport_interface", @@ -1168,7 +1153,6 @@ ":transport_description_factory", ":turn_port", ":wrapping_active_ice_controller", - "../api:array_view", "../api:async_dns_resolver", "../api:candidate", "../api:create_network_emulation_manager", @@ -1325,7 +1309,6 @@ ":p2p_constants", ":port", ":port_interface", - "../api:array_view", "../api:candidate", "../api/transport:stun_types", "../rtc_base:async_packet_socket", @@ -1353,7 +1336,6 @@ ":async_stun_tcp_socket", ":port", ":port_interface", - "../api:array_view", "../api:packet_socket_factory", "../api:sequence_checker", "../api/environment",
diff --git a/p2p/base/async_stun_tcp_socket.cc b/p2p/base/async_stun_tcp_socket.cc index 3344f5a..9501b66 100644 --- a/p2p/base/async_stun_tcp_socket.cc +++ b/p2p/base/async_stun_tcp_socket.cc
@@ -14,10 +14,10 @@ #include <cstddef> #include <cstdint> #include <memory> +#include <span> #include <utility> #include "absl/base/nullability.h" -#include "api/array_view.h" #include "api/environment/environment.h" #include "api/transport/stun.h" #include "rtc_base/async_packet_socket.h" @@ -89,7 +89,7 @@ return static_cast<int>(cb); } -size_t AsyncStunTCPSocket::ProcessInput(ArrayView<const uint8_t> data) { +size_t AsyncStunTCPSocket::ProcessInput(std::span<const uint8_t> data) { SocketAddress remote_addr(GetRemoteAddress()); // STUN packet - First 4 bytes. Total header size is 20 bytes. // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -129,7 +129,7 @@ size_t len, int* pad_bytes) { *pad_bytes = 0; - ArrayView<const uint8_t> view(static_cast<const uint8_t*>(data), len); + std::span<const uint8_t> view(static_cast<const uint8_t*>(data), len); PacketLength pkt_len = GetBE16(view.subspan(kPacketLenOffset, 2)); size_t expected_pkt_len; uint16_t msg_type = GetBE16(view);
diff --git a/p2p/base/async_stun_tcp_socket.h b/p2p/base/async_stun_tcp_socket.h index e3bc0b9..c1e1924 100644 --- a/p2p/base/async_stun_tcp_socket.h +++ b/p2p/base/async_stun_tcp_socket.h
@@ -14,9 +14,9 @@ #include <cstddef> #include <cstdint> #include <memory> +#include <span> #include "absl/base/nullability.h" -#include "api/array_view.h" #include "api/environment/environment.h" #include "rtc_base/async_packet_socket.h" #include "rtc_base/async_tcp_socket.h" @@ -35,7 +35,7 @@ int Send(const void* pv, size_t cb, const AsyncSocketPacketOptions& options) override; - size_t ProcessInput(ArrayView<const uint8_t> data) override; + size_t ProcessInput(std::span<const uint8_t> data) override; private: // This method returns the message hdr + length written in the header.
diff --git a/p2p/base/async_stun_tcp_socket_unittest.cc b/p2p/base/async_stun_tcp_socket_unittest.cc index 25677c3..574561c 100644 --- a/p2p/base/async_stun_tcp_socket_unittest.cc +++ b/p2p/base/async_stun_tcp_socket_unittest.cc
@@ -18,7 +18,6 @@ #include <utility> #include "absl/memory/memory.h" -#include "api/array_view.h" #include "api/environment/environment.h" #include "rtc_base/async_packet_socket.h" #include "rtc_base/async_tcp_socket.h"
diff --git a/p2p/base/basic_ice_controller.h b/p2p/base/basic_ice_controller.h index 9e32c5b..d0120b4 100644 --- a/p2p/base/basic_ice_controller.h +++ b/p2p/base/basic_ice_controller.h
@@ -17,9 +17,9 @@ #include <map> #include <optional> #include <set> +#include <span> #include <vector> -#include "api/array_view.h" #include "api/environment/environment.h" #include "api/units/time_delta.h" #include "api/units/timestamp.h" @@ -45,7 +45,7 @@ void SetSelectedConnection(const Connection* selected_connection) override; void AddConnection(const Connection* connection) override; void OnConnectionDestroyed(const Connection* connection) override; - ArrayView<const Connection* const> GetConnections() const override { + std::span<const Connection* const> GetConnections() const override { return connections_; }
diff --git a/p2p/base/connection.cc b/p2p/base/connection.cc index 0e3b2a9..6bb2e57 100644 --- a/p2p/base/connection.cc +++ b/p2p/base/connection.cc
@@ -15,6 +15,7 @@ #include <cstdint> #include <memory> #include <optional> +#include <span> #include <string> #include <utility> #include <vector> @@ -22,7 +23,6 @@ #include "absl/algorithm/container.h" #include "absl/functional/any_invocable.h" #include "absl/strings/string_view.h" -#include "api/array_view.h" #include "api/candidate.h" #include "api/environment/environment.h" #include "api/rtc_error.h" @@ -653,7 +653,7 @@ 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; + std::optional<std::span<uint8_t>> piggyback_data; if (dtls_piggyback_attr != nullptr) { piggyback_data = dtls_piggyback_attr->array_view(); }
diff --git a/p2p/base/connection_unittest.cc b/p2p/base/connection_unittest.cc index 1e08606..02ce1f7 100644 --- a/p2p/base/connection_unittest.cc +++ b/p2p/base/connection_unittest.cc
@@ -22,7 +22,6 @@ #include "absl/memory/memory.h" #include "absl/strings/string_view.h" -#include "api/array_view.h" #include "api/environment/environment.h" #include "api/environment/environment_factory.h" #include "api/rtc_error.h"
diff --git a/p2p/base/ice_agent_interface.h b/p2p/base/ice_agent_interface.h index e2c3f96..2047be0 100644 --- a/p2p/base/ice_agent_interface.h +++ b/p2p/base/ice_agent_interface.h
@@ -11,7 +11,8 @@ #ifndef P2P_BASE_ICE_AGENT_INTERFACE_H_ #define P2P_BASE_ICE_AGENT_INTERFACE_H_ -#include "api/array_view.h" +#include <span> + #include "api/units/timestamp.h" #include "p2p/base/connection.h" #include "p2p/base/ice_switch_reason.h" @@ -62,7 +63,7 @@ // // SignalStateChange will not be triggered. virtual void ForgetLearnedStateForConnections( - ArrayView<const Connection* const> connections) = 0; + std::span<const Connection* const> connections) = 0; // Send a STUN ping request for the given connection. virtual void SendPingRequest(const Connection* connection) = 0; @@ -74,7 +75,7 @@ // Prune away the given connections. Returns true if pruning is permitted and // successfully performed. virtual bool PruneConnections( - ArrayView<const Connection* const> connections) = 0; + std::span<const Connection* const> connections) = 0; }; } // namespace webrtc
diff --git a/p2p/base/ice_controller_interface.h b/p2p/base/ice_controller_interface.h index 90e23a9..6aa5b60 100644 --- a/p2p/base/ice_controller_interface.h +++ b/p2p/base/ice_controller_interface.h
@@ -12,10 +12,10 @@ #define P2P_BASE_ICE_CONTROLLER_INTERFACE_H_ #include <optional> +#include <span> #include <string> #include <vector> -#include "api/array_view.h" #include "api/units/time_delta.h" #include "api/units/timestamp.h" #include "p2p/base/connection.h" @@ -111,7 +111,7 @@ virtual void OnConnectionDestroyed(const Connection* connection) = 0; // These are all connections that has been added and not destroyed. - virtual ArrayView<const Connection* const> GetConnections() const = 0; + virtual std::span<const Connection* const> GetConnections() const = 0; // Is there a pingable connection ? // This function is used to boot-strap pinging, after this returns true
diff --git a/p2p/base/ice_transport_internal.h b/p2p/base/ice_transport_internal.h index 1e3321e..a30db71 100644 --- a/p2p/base/ice_transport_internal.h +++ b/p2p/base/ice_transport_internal.h
@@ -14,12 +14,12 @@ #include <cstdint> #include <functional> #include <optional> +#include <span> #include <string> #include <utility> #include <vector> #include "absl/functional/any_invocable.h" -#include "api/array_view.h" #include "api/candidate.h" #include "api/peer_connection_interface.h" #include "api/rtc_error.h" @@ -410,7 +410,7 @@ CallbackList<IceTransportInternal*, const StunDictionaryView&, - ArrayView<uint16_t>> + std::span<uint16_t>> dictionary_view_updated_callback_list_; CallbackList<IceTransportInternal*, const StunDictionaryWriter&> dictionary_writer_synced_callback_list_;
diff --git a/p2p/base/p2p_transport_channel.cc b/p2p/base/p2p_transport_channel.cc index 0b5a6a5..76b5006 100644 --- a/p2p/base/p2p_transport_channel.cc +++ b/p2p/base/p2p_transport_channel.cc
@@ -19,6 +19,7 @@ #include <memory> #include <optional> #include <set> +#include <span> #include <string> #include <tuple> #include <utility> @@ -29,7 +30,6 @@ #include "absl/memory/memory.h" #include "absl/strings/match.h" #include "absl/strings/string_view.h" -#include "api/array_view.h" #include "api/async_dns_resolver.h" #include "api/candidate.h" #include "api/environment/environment.h" @@ -333,7 +333,7 @@ } void P2PTransportChannel::ForgetLearnedStateForConnections( - ArrayView<const Connection* const> connections) { + std::span<const Connection* const> connections) { for (const Connection* con : connections) { FromIceController(con)->ForgetLearnedState(); } @@ -1705,9 +1705,9 @@ return static_cast<DiffServCodePoint>(it->second); } -ArrayView<Connection* const> P2PTransportChannel::connections() const { +std::span<Connection* const> P2PTransportChannel::connections() const { RTC_DCHECK_RUN_ON(&network_thread_); - return ArrayView<Connection* const>(connections_.data(), connections_.size()); + return std::span<Connection* const>(connections_.data(), connections_.size()); } void P2PTransportChannel::RemoveConnectionForTest(Connection* connection) { @@ -1806,7 +1806,7 @@ } bool P2PTransportChannel::PruneConnections( - ArrayView<const Connection* const> connections) { + std::span<const Connection* const> connections) { RTC_DCHECK_RUN_ON(&network_thread_); if (!AllowedToPruneConnections()) { RTC_LOG(LS_WARNING) << "Not allowed to prune connections";
diff --git a/p2p/base/p2p_transport_channel.h b/p2p/base/p2p_transport_channel.h index e44b6ee..7339920 100644 --- a/p2p/base/p2p_transport_channel.h +++ b/p2p/base/p2p_transport_channel.h
@@ -26,11 +26,11 @@ #include <map> #include <memory> #include <optional> +#include <span> #include <string> #include <vector> #include "absl/strings/string_view.h" -#include "api/array_view.h" #include "api/async_dns_resolver.h" #include "api/candidate.h" #include "api/environment/environment.h" @@ -164,9 +164,9 @@ void SwitchSelectedConnection(const Connection* connection, IceSwitchReason reason) override; void ForgetLearnedStateForConnections( - ArrayView<const Connection* const> connections) override; + std::span<const Connection* const> connections) override; bool PruneConnections( - ArrayView<const Connection* const> connections) override; + std::span<const Connection* const> connections) override; // TODO(honghaiz): Remove this method once the reference of it in // Chromoting is removed. @@ -210,7 +210,7 @@ void MarkConnectionPinged(Connection* conn); // Public for unit tests. - ArrayView<Connection* const> connections() const; + std::span<Connection* const> connections() const; void RemoveConnectionForTest(Connection* connection); // Public for unit tests.
diff --git a/p2p/base/p2p_transport_channel_unittest.cc b/p2p/base/p2p_transport_channel_unittest.cc index f6eac83..4ec6d91 100644 --- a/p2p/base/p2p_transport_channel_unittest.cc +++ b/p2p/base/p2p_transport_channel_unittest.cc
@@ -17,6 +17,7 @@ #include <map> #include <memory> #include <optional> +#include <span> #include <string> #include <tuple> #include <utility> @@ -25,7 +26,6 @@ #include "absl/algorithm/container.h" #include "absl/functional/any_invocable.h" #include "absl/strings/string_view.h" -#include "api/array_view.h" #include "api/async_dns_resolver.h" #include "api/candidate.h" #include "api/environment/environment.h" @@ -2561,7 +2561,7 @@ } Connection* GetBestConnection(P2PTransportChannel* channel) { - ArrayView<Connection* const> connections = channel->connections(); + std::span<Connection* const> connections = channel->connections(); auto it = absl::c_find(connections, channel->selected_connection()); if (it == connections.end()) { return nullptr; @@ -2570,7 +2570,7 @@ } Connection* GetBackupConnection(P2PTransportChannel* channel) { - ArrayView<Connection* const> connections = channel->connections(); + std::span<Connection* const> connections = channel->connections(); auto it = absl::c_find_if_not(connections, [channel](Connection* conn) { return conn == channel->selected_connection(); }); @@ -2583,7 +2583,7 @@ void DestroyAllButBestConnection(P2PTransportChannel* channel) { const Connection* selected_connection = channel->selected_connection(); // Copy the list of connections since the original will be modified. - ArrayView<Connection* const> view = channel->connections(); + std::span<Connection* const> view = channel->connections(); std::vector<Connection*> connections(view.begin(), view.end()); for (Connection* conn : connections) { if (conn != selected_connection) @@ -3567,7 +3567,7 @@ CreateChannels(env); MockFunction<void(IceTransportInternal*, const StunDictionaryView&, - ArrayView<uint16_t>)> + std::span<uint16_t>)> view_updated_func; ep2_ch1()->AddDictionaryViewUpdatedCallback( "tag", view_updated_func.AsStdFunction()); @@ -7132,7 +7132,7 @@ return make_pair(absl::string_view(pending_packet_), std::nullopt); } - void piggyback_data_received(std::optional<ArrayView<uint8_t>> data, + void piggyback_data_received(std::optional<std::span<uint8_t>> data, std::optional<std::vector<uint32_t>> ack) {} ScopedFakeClock clock_;
diff --git a/p2p/base/port.cc b/p2p/base/port.cc index 932ff54..e7ef807 100644 --- a/p2p/base/port.cc +++ b/p2p/base/port.cc
@@ -15,6 +15,7 @@ #include <functional> #include <memory> #include <optional> +#include <span> #include <string> #include <utility> #include <vector> @@ -23,7 +24,6 @@ #include "absl/functional/any_invocable.h" #include "absl/memory/memory.h" #include "absl/strings/string_view.h" -#include "api/array_view.h" #include "api/candidate.h" #include "api/local_network_access_permission.h" #include "api/sequence_checker.h" @@ -468,8 +468,7 @@ // Parse the request message. If the packet is not a complete and correct // STUN message, then ignore it. std::unique_ptr<IceMessage> stun_msg(new IceMessage()); - ByteBufferReader buf( - MakeArrayView(reinterpret_cast<const uint8_t*>(data), size)); + ByteBufferReader buf(std::span(reinterpret_cast<const uint8_t*>(data), size)); if (!stun_msg->Read(&buf) || (buf.Length() > 0)) { return false; }
diff --git a/p2p/base/port_unittest.cc b/p2p/base/port_unittest.cc index a0ca85f..82b005c 100644 --- a/p2p/base/port_unittest.cc +++ b/p2p/base/port_unittest.cc
@@ -22,7 +22,6 @@ #include "absl/memory/memory.h" #include "absl/strings/string_view.h" -#include "api/array_view.h" #include "api/async_dns_resolver.h" #include "api/candidate.h" #include "api/environment/environment.h"
diff --git a/p2p/base/stun_request.cc b/p2p/base/stun_request.cc index c5867be..3afabe1 100644 --- a/p2p/base/stun_request.cc +++ b/p2p/base/stun_request.cc
@@ -15,12 +15,12 @@ #include <cstdint> #include <functional> #include <memory> +#include <span> #include <string> #include <utility> #include <vector> #include "absl/strings/string_view.h" -#include "api/array_view.h" #include "api/environment/environment.h" #include "api/sequence_checker.h" #include "api/task_queue/pending_task_safety_flag.h" @@ -191,7 +191,7 @@ return requests_.empty(); } -bool StunRequestManager::CheckResponse(ArrayView<const uint8_t> payload) { +bool StunRequestManager::CheckResponse(std::span<const uint8_t> payload) { RTC_DCHECK_RUN_ON(thread_); // Check the appropriate bytes of the stream to see if they match the // transaction ID of a response we are expecting.
diff --git a/p2p/base/stun_request.h b/p2p/base/stun_request.h index b16720d..ccd284a 100644 --- a/p2p/base/stun_request.h +++ b/p2p/base/stun_request.h
@@ -16,9 +16,9 @@ #include <functional> #include <map> #include <memory> +#include <span> #include <string> -#include "api/array_view.h" #include "api/environment/environment.h" #include "api/task_queue/pending_task_safety_flag.h" #include "api/task_queue/task_queue_base.h" @@ -70,7 +70,7 @@ // Determines whether the given message is a response to one of the // outstanding requests, and if so, processes it appropriately. bool CheckResponse(StunMessage* msg); - bool CheckResponse(ArrayView<const uint8_t> payload); + bool CheckResponse(std::span<const uint8_t> payload); // Called from a StunRequest when a timeout occurs. void OnRequestTimedOut(StunRequest* request);
diff --git a/p2p/base/turn_port.cc b/p2p/base/turn_port.cc index 9a22505..1a6f3a7 100644 --- a/p2p/base/turn_port.cc +++ b/p2p/base/turn_port.cc
@@ -15,6 +15,7 @@ #include <cstdint> #include <functional> #include <memory> +#include <span> #include <string> #include <utility> #include <vector> @@ -23,7 +24,6 @@ #include "absl/memory/memory.h" #include "absl/strings/match.h" #include "absl/strings/string_view.h" -#include "api/array_view.h" #include "api/candidate.h" #include "api/local_network_access_permission.h" #include "api/packet_socket_factory.h" @@ -1118,7 +1118,7 @@ // +-------------------------------+ // Extract header fields from the message. - ArrayView<const uint8_t> payload = packet.payload(); + std::span<const uint8_t> payload = packet.payload(); uint16_t len = GetBE16(payload.subspan(2, 2)); if (len > payload.size() - TURN_CHANNEL_HEADER_SIZE) { RTC_LOG(LS_WARNING) << ToString() @@ -1867,7 +1867,7 @@ buf.WriteUInt16(channel_id_); buf.WriteUInt16(static_cast<uint16_t>(size)); buf.Write( - ArrayView<const uint8_t>(reinterpret_cast<const uint8_t*>(data), size)); + std::span<const uint8_t>(reinterpret_cast<const uint8_t*>(data), size)); } AsyncSocketPacketOptions modified_options(options); modified_options.info_signaled_after_sent.turn_overhead_bytes =
diff --git a/p2p/base/turn_port_unittest.cc b/p2p/base/turn_port_unittest.cc index 99efabc..a5d7fd7 100644 --- a/p2p/base/turn_port_unittest.cc +++ b/p2p/base/turn_port_unittest.cc
@@ -14,13 +14,13 @@ #include <list> #include <memory> #include <optional> +#include <span> #include <string> #include <utility> #include <vector> #include "absl/functional/any_invocable.h" #include "absl/strings/string_view.h" -#include "api/array_view.h" #include "api/candidate.h" #include "api/environment/environment.h" #include "api/environment/environment_factory.h" @@ -1027,7 +1027,7 @@ } } } - void ReceivedChannelData(ArrayView<const uint8_t> packet) override {} + void ReceivedChannelData(std::span<const uint8_t> packet) override {} private: const char* expect_val_; @@ -1960,7 +1960,7 @@ } } - void ReceivedChannelData(ArrayView<const uint8_t> payload) override { + void ReceivedChannelData(std::span<const uint8_t> payload) override { if (channel_data_counter_ != nullptr) { (*channel_data_counter_)++; }
diff --git a/p2p/dtls/dtls_stun_piggyback_callbacks.h b/p2p/dtls/dtls_stun_piggyback_callbacks.h index 241d51e..e3cb33a 100644 --- a/p2p/dtls/dtls_stun_piggyback_callbacks.h +++ b/p2p/dtls/dtls_stun_piggyback_callbacks.h
@@ -13,12 +13,12 @@ #include <cstdint> #include <optional> +#include <span> #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" @@ -38,10 +38,10 @@ /* request-type */ StunMessageType)>&& send_data, // Function invoked when receiving a STUN_BINDING { REQUEST / RESPONSE } - // contains the optional ArrayView of the DTLS_IN_STUN attribute and the + // contains the optional std::span of the DTLS_IN_STUN attribute and the // optional uint32_t vector DTLS_IN_STUN_ACK attribute. absl::AnyInvocable<void( - std::optional<ArrayView<uint8_t>> /* recv_data */, + std::optional<std::span<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( @@ -58,7 +58,7 @@ return send_data_(request_type); } - void recv_data(std::optional<ArrayView<uint8_t>> data, + void recv_data(std::optional<std::span<uint8_t>> data, std::optional<std::vector<uint32_t>> acks) { RTC_DCHECK(recv_data_); return recv_data_(data, acks); @@ -75,7 +75,7 @@ std::optional<std::vector<uint32_t>>>( /* request-type */ StunMessageType)> send_data_; - absl::AnyInvocable<void(std::optional<ArrayView<uint8_t>> /* recv_data */, + absl::AnyInvocable<void(std::optional<std::span<uint8_t>> /* recv_data */, std::optional<std::vector<uint32_t>> /* recv_acks */)> recv_data_; };
diff --git a/p2p/dtls/dtls_stun_piggyback_controller.cc b/p2p/dtls/dtls_stun_piggyback_controller.cc index f0b84c6..cb7d0c4 100644 --- a/p2p/dtls/dtls_stun_piggyback_controller.cc +++ b/p2p/dtls/dtls_stun_piggyback_controller.cc
@@ -13,13 +13,13 @@ #include <algorithm> #include <cstdint> #include <optional> +#include <span> #include <utility> #include <vector> #include "absl/container/flat_hash_set.h" #include "absl/functional/any_invocable.h" #include "absl/strings/string_view.h" -#include "api/array_view.h" #include "api/sequence_checker.h" #include "api/transport/stun.h" #include "p2p/dtls/dtls_utils.h" @@ -31,7 +31,7 @@ namespace webrtc { DtlsStunPiggybackController::DtlsStunPiggybackController( - absl::AnyInvocable<void(ArrayView<const uint8_t>)> dtls_data_callback, + absl::AnyInvocable<void(std::span<const uint8_t>)> dtls_data_callback, // NOLINTNEXTLINE(readability/casting) - not a cast; false positive! absl::AnyInvocable<void(bool) &&> piggyback_complete_callback) : dtls_data_callback_(std::move(dtls_data_callback)), @@ -92,7 +92,7 @@ CallCompleteCallback(/*success=*/false); } -void DtlsStunPiggybackController::CapturePacket(ArrayView<const uint8_t> data) { +void DtlsStunPiggybackController::CapturePacket(std::span<const uint8_t> data) { RTC_DCHECK_RUN_ON(&sequence_checker_); if (!IsDtlsPacket(data)) { return; @@ -159,14 +159,14 @@ return handshake_messages_received_; } -std::vector<ArrayView<const uint8_t>> +std::vector<std::span<const uint8_t>> DtlsStunPiggybackController::GetPending() { RTC_DCHECK_RUN_ON(&sequence_checker_); return pending_packets_.GetAll(); } void DtlsStunPiggybackController::ReportDataPiggybacked( - std::optional<ArrayView<uint8_t>> data, + std::optional<std::span<uint8_t>> data, std::optional<std::vector<uint32_t>> acks) { RTC_DCHECK_RUN_ON(&sequence_checker_); @@ -234,7 +234,7 @@ } void DtlsStunPiggybackController::ReportDtlsPacket( - ArrayView<const uint8_t> data) { + std::span<const uint8_t> data) { RTC_DCHECK_RUN_ON(&sequence_checker_); if (state_ == State::OFF || state_ == State::COMPLETE) {
diff --git a/p2p/dtls/dtls_stun_piggyback_controller.h b/p2p/dtls/dtls_stun_piggyback_controller.h index 89cd27b..18af1bd 100644 --- a/p2p/dtls/dtls_stun_piggyback_controller.h +++ b/p2p/dtls/dtls_stun_piggyback_controller.h
@@ -13,11 +13,11 @@ #include <cstdint> #include <optional> +#include <span> #include <vector> #include "absl/functional/any_invocable.h" #include "absl/strings/string_view.h" -#include "api/array_view.h" #include "api/sequence_checker.h" #include "api/transport/stun.h" #include "p2p/dtls/dtls_utils.h" @@ -37,7 +37,7 @@ // dtls_data_callback will be called with any DTLS packets received // piggybacked. DtlsStunPiggybackController( - absl::AnyInvocable<void(ArrayView<const uint8_t>)> dtls_data_callback, + absl::AnyInvocable<void(std::span<const uint8_t>)> dtls_data_callback, // NOLINTNEXTLINE(readability/casting) - not a cast; false positive! absl::AnyInvocable<void(bool) &&> piggyback_complete_callback); @@ -79,7 +79,7 @@ // Intercepts DTLS packets which should go into the STUN packets during the // handshake. - void CapturePacket(ArrayView<const uint8_t> data); + void CapturePacket(std::span<const uint8_t> data); void ClearCachedPacketForTesting(); // Inform piggybackcontroller that a flight is complete. @@ -91,17 +91,17 @@ StunMessageType stun_message_type); std::optional<const std::vector<uint32_t>> GetAckToPiggyback( StunMessageType stun_message_type); - std::vector<ArrayView<const uint8_t>> GetPending(); + std::vector<std::span<const uint8_t>> GetPending(); // Called by Connection when receiving a STUN BINDING { REQUEST / RESPONSE }. - void ReportDataPiggybacked(std::optional<ArrayView<uint8_t>> data, + void ReportDataPiggybacked(std::optional<std::span<uint8_t>> data, std::optional<std::vector<uint32_t>> acks); // Called by // * DTLSTransport when receiving a DTLS packet (possibly after the packet // was emitted by this class). // * This class when processing a DTLS packet. - void ReportDtlsPacket(ArrayView<const uint8_t> data); + void ReportDtlsPacket(std::span<const uint8_t> data); int GetCountOfReceivedData() const { return data_recv_count_; } @@ -109,7 +109,7 @@ State state_ RTC_GUARDED_BY(sequence_checker_) = State::TENTATIVE; bool writing_packets_ RTC_GUARDED_BY(sequence_checker_) = false; PacketStash pending_packets_ RTC_GUARDED_BY(sequence_checker_); - absl::AnyInvocable<void(ArrayView<const uint8_t>)> dtls_data_callback_ + absl::AnyInvocable<void(std::span<const uint8_t>)> dtls_data_callback_ RTC_GUARDED_BY(sequence_checker_); // NOLINTNEXTLINE(readability/casting) - not a cast; false positive! absl::AnyInvocable<void(bool) &&> piggyback_complete_callback_
diff --git a/p2p/dtls/dtls_stun_piggyback_controller_unittest.cc b/p2p/dtls/dtls_stun_piggyback_controller_unittest.cc index 59e5299..7ff86af 100644 --- a/p2p/dtls/dtls_stun_piggyback_controller_unittest.cc +++ b/p2p/dtls/dtls_stun_piggyback_controller_unittest.cc
@@ -13,11 +13,11 @@ #include <cstdint> #include <memory> #include <optional> +#include <span> #include <string> #include <vector> #include "absl/strings/string_view.h" -#include "api/array_view.h" #include "api/transport/stun.h" #include "p2p/dtls/dtls_utils.h" #include "rtc_base/byte_buffer.h" @@ -63,7 +63,7 @@ const std::vector<uint8_t> kPayload = {0x1, 0x2, 0x3}; -std::vector<uint32_t> FromAckAttribute(ArrayView<uint8_t> attr) { +std::vector<uint32_t> FromAckAttribute(std::span<uint8_t> attr) { ByteBufferReader ack_reader(attr); std::vector<uint32_t> values; uint32_t value; @@ -110,10 +110,10 @@ protected: DtlsStunPiggybackControllerTest() : client_( - [this](ArrayView<const uint8_t> data) { ClientPacketSink(data); }, + [this](std::span<const uint8_t> data) { ClientPacketSink(data); }, [this](bool success) { ClientCompleteCallback(success); }), server_( - [this](ArrayView<const uint8_t> data) { ServerPacketSink(data); }, + [this](std::span<const uint8_t> data) { ServerPacketSink(data); }, [this](bool success) { ServerCompleteCallback(success); }), packet_(kPayload, SocketAddress(), std::nullopt) {} @@ -127,7 +127,7 @@ client_.ClearCachedPacketForTesting(); } std::unique_ptr<StunByteStringAttribute> attr_data; - std::optional<ArrayView<uint8_t>> view_data; + std::optional<std::span<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(); @@ -160,7 +160,7 @@ server_.ClearCachedPacketForTesting(); } std::unique_ptr<StunByteStringAttribute> attr_data; - std::optional<ArrayView<uint8_t>> view_data; + std::optional<std::span<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(); @@ -195,8 +195,8 @@ DtlsStunPiggybackController client_; DtlsStunPiggybackController server_; - MOCK_METHOD(void, ClientPacketSink, (ArrayView<const uint8_t>)); - MOCK_METHOD(void, ServerPacketSink, (ArrayView<const uint8_t>)); + MOCK_METHOD(void, ClientPacketSink, (std::span<const uint8_t>)); + MOCK_METHOD(void, ServerPacketSink, (std::span<const uint8_t>)); MOCK_METHOD(void, ClientCompleteCallback, (bool)); MOCK_METHOD(void, ServerCompleteCallback, (bool));
diff --git a/p2p/dtls/dtls_transport.cc b/p2p/dtls/dtls_transport.cc index ae516ad7..1796ddf 100644 --- a/p2p/dtls/dtls_transport.cc +++ b/p2p/dtls/dtls_transport.cc
@@ -15,13 +15,13 @@ #include <cstdint> #include <memory> #include <optional> +#include <span> #include <string> #include <utility> #include <vector> #include "absl/functional/any_invocable.h" #include "absl/strings/string_view.h" -#include "api/array_view.h" #include "api/crypto/crypto_options.h" #include "api/dtls_transport_interface.h" #include "api/environment/environment.h" @@ -128,7 +128,7 @@ constexpr uint32_t kMaxCachedClientHello = 4; -static bool IsRtpPacket(ArrayView<const uint8_t> payload) { +static bool IsRtpPacket(std::span<const uint8_t> payload) { const uint8_t* u = payload.data(); return (payload.size() >= kMinRtpPacketLen && (u[0] & 0xC0) == 0x80); } @@ -149,7 +149,7 @@ dtls_stun_piggyback_controller_ = dtls_stun_piggyback_controller; } -StreamResult StreamInterfaceChannel::Read(ArrayView<uint8_t> buffer, +StreamResult StreamInterfaceChannel::Read(std::span<uint8_t> buffer, size_t& read, int& /* error */) { RTC_DCHECK_RUN_ON(&callback_sequence_); @@ -177,7 +177,7 @@ next_packet_options_.reset(); } -StreamResult StreamInterfaceChannel::Write(ArrayView<const uint8_t> data, +StreamResult StreamInterfaceChannel::Write(std::span<const uint8_t> data, size_t& written, int& /* error */) { RTC_DCHECK_RUN_ON(&callback_sequence_); @@ -209,7 +209,7 @@ return false; } -bool StreamInterfaceChannel::OnPacketReceived(ArrayView<const uint8_t> data) { +bool StreamInterfaceChannel::OnPacketReceived(std::span<const uint8_t> data) { RTC_DCHECK_RUN_ON(&callback_sequence_); if (packets_.size() > 0) { RTC_LOG(LS_WARNING) << "Packet already in queue."; @@ -260,7 +260,7 @@ crypto_options.ephemeral_key_exchange_cipher_groups.GetEnabled()), ssl_max_version_(max_version), dtls_stun_piggyback_controller_( - [this](ArrayView<const uint8_t> piggybacked_dtls_packet) { + [this](std::span<const uint8_t> piggybacked_dtls_packet) { if (piggybacked_dtls_callback_ == nullptr) { return; } @@ -655,7 +655,7 @@ if (flags & PF_SRTP_BYPASS) { RTC_DCHECK(!srtp_ciphers_.empty()); if (!IsRtpPacket( - MakeArrayView(reinterpret_cast<const uint8_t*>(data), size))) { + std::span(reinterpret_cast<const uint8_t*>(data), size))) { return -1; } @@ -669,8 +669,8 @@ // StreamInterfaceChannel::Write function. Such change would remove the // need of the next_packet_options_. StreamResult result = dtls_->Write( - MakeArrayView(reinterpret_cast<const uint8_t*>(data), size), - written, error); + std::span(reinterpret_cast<const uint8_t*>(data), size), written, + error); if (result != SR_SUCCESS) { // Explicitly clear the next packet options, in case no packet was // sent. @@ -775,7 +775,7 @@ } return std::make_pair(data, ack); }, - [&](std::optional<ArrayView<uint8_t>> data, + [&](std::optional<std::span<uint8_t>> data, std::optional<std::vector<uint32_t>> acks) { if (!dtls_in_stun_) { return; @@ -1016,10 +1016,9 @@ // TODO(bugs.webrtc.org/15368): It should be possible to use information // from the original packet here to populate socket address and // timestamp. - NotifyPacketReceived( - ReceivedIpPacket(MakeArrayView(buf, read), SocketAddress(), - env_.clock().CurrentTime(), EcnMarking::kNotEct, - ReceivedIpPacket::kDtlsDecrypted)); + NotifyPacketReceived(ReceivedIpPacket( + std::span(buf, read), SocketAddress(), env_.clock().CurrentTime(), + EcnMarking::kNotEct, ReceivedIpPacket::kDtlsDecrypted)); } else if (ret == SR_EOS) { // Remote peer shut down the association with no error. RTC_LOG(LS_INFO) << ToString() << ": DTLS transport closed by remote"; @@ -1109,7 +1108,7 @@ // Called from OnReadPacket when a DTLS packet is received. bool DtlsTransportInternalImpl::HandleDtlsPacket( - ArrayView<const uint8_t> payload) { + std::span<const uint8_t> payload) { // Pass to the StreamInterfaceChannel which ends up being passed to the DTLS // stack. return downward_->OnPacketReceived(payload);
diff --git a/p2p/dtls/dtls_transport.h b/p2p/dtls/dtls_transport.h index 7176cce..9eed516 100644 --- a/p2p/dtls/dtls_transport.h +++ b/p2p/dtls/dtls_transport.h
@@ -16,12 +16,12 @@ #include <functional> #include <memory> #include <optional> +#include <span> #include <string> #include <vector> #include "absl/functional/any_invocable.h" #include "absl/strings/string_view.h" -#include "api/array_view.h" #include "api/crypto/crypto_options.h" #include "api/dtls_transport_interface.h" #include "api/environment/environment.h" @@ -76,7 +76,7 @@ StreamInterfaceChannel& operator=(const StreamInterfaceChannel&) = delete; // Push in a packet; this gets pulled out from Read(). - bool OnPacketReceived(ArrayView<const uint8_t> data); + bool OnPacketReceived(std::span<const uint8_t> data); // Sets the options for the next packet to be written to ice_transport, // corresponding to the next Write() call. Safe since BoringSSL guarantees @@ -89,10 +89,10 @@ // Implementations of StreamInterface StreamState GetState() const override; void Close() override; - StreamResult Read(ArrayView<uint8_t> buffer, + StreamResult Read(std::span<uint8_t> buffer, size_t& read, int& error) override; - StreamResult Write(ArrayView<const uint8_t> data, + StreamResult Write(std::span<const uint8_t> data, size_t& written, int& error) override; bool Flush() override; @@ -293,7 +293,7 @@ void OnNetworkRouteChanged(std::optional<NetworkRoute> network_route); bool SetupDtls(); void MaybeStartDtls(); - bool HandleDtlsPacket(ArrayView<const uint8_t> payload); + bool HandleDtlsPacket(std::span<const uint8_t> payload); void OnDtlsHandshakeError(SSLHandshakeError error); void ConfigureHandshakeTimeout(); void UpdateHandshakeTimeout();
diff --git a/p2p/dtls/dtls_transport_unittest.cc b/p2p/dtls/dtls_transport_unittest.cc index b73a0db..98b0ba5 100644 --- a/p2p/dtls/dtls_transport_unittest.cc +++ b/p2p/dtls/dtls_transport_unittest.cc
@@ -17,6 +17,7 @@ #include <memory> #include <optional> #include <set> +#include <span> #include <string> #include <tuple> #include <utility> @@ -25,7 +26,6 @@ #include "absl/functional/any_invocable.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" -#include "api/array_view.h" #include "api/crypto/crypto_options.h" #include "api/dtls_transport_interface.h" #include "api/field_trials.h" @@ -278,7 +278,7 @@ memset(packet.get(), sent & 0xff, size); packet[0] = (srtp) ? kRtpLeadByte : 0x00; SetBE32( - ArrayView<uint8_t>( + std::span<uint8_t>( reinterpret_cast<uint8_t*>(packet.get() + kPacketNumOffset), 4), static_cast<uint32_t>(sent)); @@ -312,7 +312,7 @@ size_t NumPacketsReceived() { return received_.size(); } // Inverse of SendPackets. - bool VerifyPacket(ArrayView<const uint8_t> payload, uint32_t* out_num) { + bool VerifyPacket(std::span<const uint8_t> payload, uint32_t* out_num) { const uint8_t* data = payload.data(); size_t size = payload.size(); @@ -320,7 +320,7 @@ return false; } uint32_t packet_num = - GetBE32(ArrayView<const uint8_t>(data + kPacketNumOffset, 4)); + GetBE32(std::span<const uint8_t>(data + kPacketNumOffset, 4)); for (size_t i = kPacketHeaderLen; i < size; ++i) { if (data[i] != (packet_num & 0xff)) { return false; @@ -338,7 +338,7 @@ return false; } uint32_t packet_num = - GetBE32(ArrayView<const uint8_t>(data + kPacketNumOffset, 4)); + GetBE32(std::span<const uint8_t>(data + kPacketNumOffset, 4)); int num_matches = 0; for (size_t i = kPacketNumOffset; i < size; ++i) { if (data[i] == (packet_num & 0xff)) { @@ -385,7 +385,7 @@ SentPacketInfo sent_packet() const { return sent_packet_; } - bool IsDtlsCiphertextPacket(ArrayView<const uint8_t> payload) { + bool IsDtlsCiphertextPacket(std::span<const uint8_t> payload) { return IsDtlsPacket(payload) && (payload.data()[0] > 31 && payload.data()[0] < 64); } @@ -477,7 +477,7 @@ int StartSSL() override { return impl_->StartSSL(); } SSLPeerCertificateDigestError SetPeerCertificateDigest( absl::string_view digest_alg, - ArrayView<const uint8_t> digest_val) override { + std::span<const uint8_t> digest_val) override { return impl_->SetPeerCertificateDigest(digest_alg, digest_val); } std::unique_ptr<SSLCertChain> GetPeerSSLCertChain() const override { @@ -521,12 +521,12 @@ // StreamInterface overrides. StreamState GetState() const override { return impl_->GetState(); } void Close() override { impl_->Close(); } - StreamResult Read(ArrayView<uint8_t> buffer, + StreamResult Read(std::span<uint8_t> buffer, size_t& read, int& error) override { return impl_->Read(buffer, read, error); } - StreamResult Write(ArrayView<const uint8_t> data, + StreamResult Write(std::span<const uint8_t> data, size_t& written, int& error) override { if (write_error_) { @@ -768,7 +768,7 @@ std::unique_ptr<char[]> packet(new char[size]); memset(packet.get(), 0, size); packet[0] = 0x00; - SetBE32(ArrayView<uint8_t>( + SetBE32(std::span<uint8_t>( reinterpret_cast<uint8_t*>(packet.get() + kPacketNumOffset), 4), 0); @@ -800,7 +800,7 @@ std::unique_ptr<char[]> packet(new char[size]); memset(packet.get(), 0, size); packet[0] = kRtpLeadByte; // Make it look like an SRTP packet. - SetBE32(ArrayView<uint8_t>( + SetBE32(std::span<uint8_t>( reinterpret_cast<uint8_t*>(packet.get() + kPacketNumOffset), 4), 0);
diff --git a/p2p/dtls/dtls_utils.cc b/p2p/dtls/dtls_utils.cc index a348fa1..87d188f 100644 --- a/p2p/dtls/dtls_utils.cc +++ b/p2p/dtls/dtls_utils.cc
@@ -13,10 +13,10 @@ #include <cstddef> #include <cstdint> #include <memory> +#include <span> #include <vector> #include "absl/container/flat_hash_set.h" -#include "api/array_view.h" #include "rtc_base/buffer.h" #include "rtc_base/checks.h" #include "rtc_base/crc32.h" @@ -30,12 +30,12 @@ } // namespace -bool IsDtlsPacket(ArrayView<const uint8_t> payload) { +bool IsDtlsPacket(std::span<const uint8_t> payload) { const uint8_t* u = payload.data(); return (payload.size() >= kDtlsRecordHeaderLen && (u[0] > 19 && u[0] < 64)); } -bool IsDtlsClientHelloPacket(ArrayView<const uint8_t> payload) { +bool IsDtlsClientHelloPacket(std::span<const uint8_t> payload) { if (!IsDtlsPacket(payload)) { return false; } @@ -43,7 +43,7 @@ return payload.size() > 17 && u[0] == kDtlsHandshakeRecord && u[13] == 1; } -bool IsDtlsHandshakePacket(ArrayView<const uint8_t> payload) { +bool IsDtlsHandshakePacket(std::span<const uint8_t> payload) { if (!IsDtlsPacket(payload)) { return false; } @@ -55,11 +55,11 @@ payload[0] == kDtlsChangeCipherSpecRecord); } -uint32_t ComputeDtlsPacketHash(ArrayView<const uint8_t> dtls_packet) { +uint32_t ComputeDtlsPacketHash(std::span<const uint8_t> dtls_packet) { return ComputeCrc32(dtls_packet.data(), dtls_packet.size()); } -bool PacketStash::AddIfUnique(ArrayView<const uint8_t> packet) { +bool PacketStash::AddIfUnique(std::span<const uint8_t> packet) { uint32_t h = ComputeDtlsPacketHash(packet); for (const auto& [hash, p] : packets_) { if (h == hash) { @@ -72,7 +72,7 @@ return true; } -void PacketStash::Add(ArrayView<const uint8_t> packet) { +void PacketStash::Add(std::span<const uint8_t> packet) { packets_.push_back( {.hash = ComputeDtlsPacketHash(packet), .buffer = std::make_unique<Buffer>(packet.data(), packet.size())}); @@ -110,20 +110,20 @@ } } -ArrayView<const uint8_t> PacketStash::GetNext() { +std::span<const uint8_t> PacketStash::GetNext() { RTC_DCHECK(!packets_.empty()); auto pos = pos_; pos_ = (pos + 1) % packets_.size(); const auto& buffer = packets_[pos].buffer; - return ArrayView<const uint8_t>(buffer->data(), buffer->size()); + return std::span<const uint8_t>(buffer->data(), buffer->size()); } -std::vector<ArrayView<const uint8_t>> PacketStash::GetAll() const { - std::vector<ArrayView<const uint8_t>> ret; +std::vector<std::span<const uint8_t>> PacketStash::GetAll() const { + std::vector<std::span<const uint8_t>> ret; ret.reserve(packets_.size()); for (const auto& buffer : packets_) { const uint8_t* ptr = buffer.buffer->data(); - ret.push_back(ArrayView<const uint8_t>(ptr, buffer.buffer->size())); + ret.push_back(std::span<const uint8_t>(ptr, buffer.buffer->size())); } return ret; }
diff --git a/p2p/dtls/dtls_utils.h b/p2p/dtls/dtls_utils.h index 3a60159..e2ed5dc 100644 --- a/p2p/dtls/dtls_utils.h +++ b/p2p/dtls/dtls_utils.h
@@ -14,10 +14,10 @@ #include <cstddef> #include <cstdint> #include <memory> +#include <span> #include <vector> #include "absl/container/flat_hash_set.h" -#include "api/array_view.h" #include "rtc_base/buffer.h" namespace webrtc { @@ -25,23 +25,23 @@ const size_t kDtlsRecordHeaderLen = 13; const size_t kMaxDtlsPacketLen = 2048; -bool IsDtlsPacket(ArrayView<const uint8_t> payload); -bool IsDtlsClientHelloPacket(ArrayView<const uint8_t> payload); -bool IsDtlsHandshakePacket(ArrayView<const uint8_t> payload); +bool IsDtlsPacket(std::span<const uint8_t> payload); +bool IsDtlsClientHelloPacket(std::span<const uint8_t> payload); +bool IsDtlsHandshakePacket(std::span<const uint8_t> payload); -uint32_t ComputeDtlsPacketHash(ArrayView<const uint8_t> dtls_packet); +uint32_t ComputeDtlsPacketHash(std::span<const uint8_t> dtls_packet); class PacketStash { public: PacketStash() {} - void Add(ArrayView<const uint8_t> packet); - bool AddIfUnique(ArrayView<const uint8_t> packet); + void Add(std::span<const uint8_t> packet); + bool AddIfUnique(std::span<const uint8_t> packet); // Returns number of elements that were removed. size_t Prune(const absl::flat_hash_set<uint32_t>& packet_hashes); void Prune(uint32_t max_size); - ArrayView<const uint8_t> GetNext(); - std::vector<ArrayView<const uint8_t>> GetAll() const; + std::span<const uint8_t> GetNext(); + std::vector<std::span<const uint8_t>> GetAll() const; void clear() { packets_.clear(); @@ -50,7 +50,7 @@ bool empty() const { return packets_.empty(); } int size() const { return packets_.size(); } - static uint32_t Hash(ArrayView<const uint8_t> packet) { + static uint32_t Hash(std::span<const uint8_t> packet) { return ComputeDtlsPacketHash(packet); }
diff --git a/p2p/dtls/dtls_utils_unittest.cc b/p2p/dtls/dtls_utils_unittest.cc index 5cd3011..8c3c771 100644 --- a/p2p/dtls/dtls_utils_unittest.cc +++ b/p2p/dtls/dtls_utils_unittest.cc
@@ -11,15 +11,15 @@ #include "p2p/dtls/dtls_utils.h" #include <cstdint> +#include <span> #include <vector> #include "absl/container/flat_hash_set.h" -#include "api/array_view.h" #include "test/gtest.h" namespace webrtc { -std::vector<uint8_t> ToVector(ArrayView<const uint8_t> array) { +std::vector<uint8_t> ToVector(std::span<const uint8_t> array) { return std::vector<uint8_t>(array.begin(), array.end()); }
diff --git a/p2p/dtls/fake_dtls_transport.h b/p2p/dtls/fake_dtls_transport.h index 6444bf7..0beb398 100644 --- a/p2p/dtls/fake_dtls_transport.h +++ b/p2p/dtls/fake_dtls_transport.h
@@ -15,12 +15,12 @@ #include <cstring> #include <memory> #include <optional> +#include <span> #include <string> #include <utility> #include <vector> #include "absl/strings/string_view.h" -#include "api/array_view.h" #include "api/dtls_transport_interface.h" #include "api/ice_transport_interface.h" #include "api/rtc_error.h" @@ -56,7 +56,7 @@ ice_transport_ref_->internal())), transport_name_(ice_transport_->transport_name()), component_(ice_transport_->component()), - dtls_fingerprint_("", ArrayView<const uint8_t>()) { + dtls_fingerprint_("", std::span<const uint8_t>()) { RTC_DCHECK(ice_transport_); ice_transport_->RegisterReceivedPacketCallback( this, [&](PacketTransportInternal* transport, @@ -72,7 +72,7 @@ : owned_ice_transport_(std::move(ice)), transport_name_(owned_ice_transport_->transport_name()), component_(owned_ice_transport_->component()), - dtls_fingerprint_("", ArrayView<const uint8_t>()) { + dtls_fingerprint_("", std::span<const uint8_t>()) { ice_transport_ = owned_ice_transport_.get(); ice_transport_->RegisterReceivedPacketCallback( this, [&](PacketTransportInternal* transport, @@ -187,7 +187,7 @@ bool SetRemoteFingerprint(absl::string_view alg, const uint8_t* digest, size_t digest_len) { - dtls_fingerprint_ = SSLFingerprint(alg, MakeArrayView(digest, digest_len)); + dtls_fingerprint_ = SSLFingerprint(alg, std::span(digest, digest_len)); return true; } bool SetDtlsRole(SSLRole role) override {
diff --git a/p2p/test/fake_ice_transport.h b/p2p/test/fake_ice_transport.h index f6cd168..864bd40 100644 --- a/p2p/test/fake_ice_transport.h +++ b/p2p/test/fake_ice_transport.h
@@ -16,13 +16,13 @@ #include <map> #include <memory> #include <optional> +#include <span> #include <string> #include <utility> #include <vector> #include "absl/functional/any_invocable.h" #include "absl/strings/string_view.h" -#include "api/array_view.h" #include "api/candidate.h" #include "api/field_trials.h" #include "api/ice_transport_interface.h" @@ -574,7 +574,7 @@ << " attr: " << (dtls_piggyback_attr != nullptr) << " ack: " << (dtls_piggyback_ack != nullptr); if (!dtls_stun_piggyback_callbacks_.empty()) { - std::optional<ArrayView<uint8_t>> piggyback_attr; + std::optional<std::span<uint8_t>> piggyback_attr; if (dtls_piggyback_attr) { piggyback_attr = dtls_piggyback_attr->array_view(); } @@ -614,7 +614,7 @@ } std::unique_ptr<IceMessage> stun_msg(new IceMessage()); - ByteBufferReader buf(MakeArrayView(packet.data(), packet.size())); + ByteBufferReader buf(std::span(packet.data(), packet.size())); RTC_CHECK(stun_msg->Read(&buf)); return stun_msg; }
diff --git a/p2p/test/mock_ice_agent.h b/p2p/test/mock_ice_agent.h index 7613a76..c555bf0 100644 --- a/p2p/test/mock_ice_agent.h +++ b/p2p/test/mock_ice_agent.h
@@ -11,7 +11,8 @@ #ifndef P2P_TEST_MOCK_ICE_AGENT_H_ #define P2P_TEST_MOCK_ICE_AGENT_H_ -#include "api/array_view.h" +#include <span> + #include "api/units/timestamp.h" #include "p2p/base/connection.h" #include "p2p/base/ice_agent_interface.h" @@ -32,7 +33,7 @@ MOCK_METHOD(void, UpdateState, (), (override)); MOCK_METHOD(void, ForgetLearnedStateForConnections, - (ArrayView<const Connection* const>), + (std::span<const Connection* const>), (override)); MOCK_METHOD(void, SendPingRequest, (const Connection*), (override)); MOCK_METHOD(void, @@ -41,7 +42,7 @@ (override)); MOCK_METHOD(bool, PruneConnections, - (ArrayView<const Connection* const>), + (std::span<const Connection* const>), (override)); };
diff --git a/p2p/test/mock_ice_controller.h b/p2p/test/mock_ice_controller.h index f654688..70adf88 100644 --- a/p2p/test/mock_ice_controller.h +++ b/p2p/test/mock_ice_controller.h
@@ -12,9 +12,9 @@ #define P2P_TEST_MOCK_ICE_CONTROLLER_H_ #include <memory> +#include <span> #include <vector> -#include "api/array_view.h" #include "api/units/timestamp.h" #include "p2p/base/connection.h" #include "p2p/base/ice_controller_factory_interface.h" @@ -36,7 +36,7 @@ MOCK_METHOD(void, SetSelectedConnection, (const Connection*), (override)); MOCK_METHOD(void, AddConnection, (const Connection*), (override)); MOCK_METHOD(void, OnConnectionDestroyed, (const Connection*), (override)); - MOCK_METHOD(ArrayView<const Connection* const>, + MOCK_METHOD(std::span<const Connection* const>, GetConnections, (), (const, override));
diff --git a/p2p/test/nat_server.cc b/p2p/test/nat_server.cc index 46ade7e..6a897b1 100644 --- a/p2p/test/nat_server.cc +++ b/p2p/test/nat_server.cc
@@ -14,9 +14,9 @@ #include <cstdint> #include <cstring> #include <memory> +#include <span> #include <utility> -#include "api/array_view.h" #include "api/environment/environment.h" #include "p2p/test/nat_socket_factory.h" #include "p2p/test/nat_types.h" @@ -116,8 +116,7 @@ SocketAddress dest_addr; size_t address_length = UnpackAddressFromNAT( - MakeArrayView(reinterpret_cast<const uint8_t*>(data), *len), - &dest_addr); + std::span(reinterpret_cast<const uint8_t*>(data), *len), &dest_addr); *len -= address_length; if (*len > 0) { memmove(data, data + address_length, *len);
diff --git a/p2p/test/nat_socket_factory.cc b/p2p/test/nat_socket_factory.cc index c0ba6d9..02abc96 100644 --- a/p2p/test/nat_socket_factory.cc +++ b/p2p/test/nat_socket_factory.cc
@@ -15,8 +15,8 @@ #include <cstring> #include <memory> #include <set> +#include <span> -#include "api/array_view.h" #include "api/environment/environment.h" #include "api/units/time_delta.h" #include "api/units/timestamp.h" @@ -64,7 +64,7 @@ // Decodes the remote address from a packet that has been encoded with the nat's // quasi-STUN format. Returns the length of the address (i.e., the offset into // data where the original packet starts). -size_t UnpackAddressFromNAT(ArrayView<const uint8_t> buf, +size_t UnpackAddressFromNAT(std::span<const uint8_t> buf, SocketAddress* remote_addr) { RTC_CHECK(buf.size() >= 8); RTC_DCHECK(buf.data()[0] == 0);
diff --git a/p2p/test/nat_socket_factory.h b/p2p/test/nat_socket_factory.h index b22d6eb..f1b388e 100644 --- a/p2p/test/nat_socket_factory.h +++ b/p2p/test/nat_socket_factory.h
@@ -16,8 +16,8 @@ #include <map> #include <memory> #include <set> +#include <span> -#include "api/array_view.h" #include "api/environment/environment.h" #include "api/units/time_delta.h" #include "p2p/test/nat_server.h" @@ -177,7 +177,7 @@ // Free-standing NAT helper functions. void PackAddressForNAT(const SocketAddress& remote_addr, Buffer& buf); -size_t UnpackAddressFromNAT(ArrayView<const uint8_t> buf, +size_t UnpackAddressFromNAT(std::span<const uint8_t> buf, SocketAddress* remote_addr); } // namespace webrtc
diff --git a/p2p/test/test_port.cc b/p2p/test/test_port.cc index fb0c998..eb4161c 100644 --- a/p2p/test/test_port.cc +++ b/p2p/test/test_port.cc
@@ -13,10 +13,10 @@ #include <cstddef> #include <cstdint> #include <memory> +#include <span> #include <utility> #include "absl/strings/string_view.h" -#include "api/array_view.h" #include "api/candidate.h" #include "api/transport/stun.h" #include "p2p/base/connection.h" @@ -39,9 +39,9 @@ : Port(args, IceCandidateType::kHost, min_port, max_port) {} TestPort::~TestPort() = default; -ArrayView<const uint8_t> TestPort::last_stun_buf() { +std::span<const uint8_t> TestPort::last_stun_buf() { if (!last_stun_buf_) - return ArrayView<const uint8_t>(); + return std::span<const uint8_t>(); return *last_stun_buf_; } IceMessage* TestPort::last_stun_msg() {
diff --git a/p2p/test/test_port.h b/p2p/test/test_port.h index b1ddcc9..8d10797 100644 --- a/p2p/test/test_port.h +++ b/p2p/test/test_port.h
@@ -14,9 +14,9 @@ #include <cstddef> #include <cstdint> #include <memory> +#include <span> #include "absl/strings/string_view.h" -#include "api/array_view.h" #include "api/candidate.h" #include "api/transport/stun.h" #include "p2p/base/connection.h" @@ -41,7 +41,7 @@ using Port::GetStunMessage; // The last StunMessage that was sent on this Port. - ArrayView<const uint8_t> last_stun_buf(); + std::span<const uint8_t> last_stun_buf(); IceMessage* last_stun_msg(); int last_stun_error_code();
diff --git a/p2p/test/turn_server.cc b/p2p/test/turn_server.cc index a4fc03b..5b59ebd 100644 --- a/p2p/test/turn_server.cc +++ b/p2p/test/turn_server.cc
@@ -14,6 +14,7 @@ #include <cstddef> #include <cstdint> #include <memory> +#include <span> #include <string> #include <tuple> // for std::tie #include <utility> @@ -21,7 +22,6 @@ #include "absl/algorithm/container.h" #include "absl/memory/memory.h" #include "absl/strings/string_view.h" -#include "api/array_view.h" #include "api/environment/environment.h" #include "api/packet_socket_factory.h" #include "api/sequence_checker.h" @@ -173,7 +173,7 @@ const ReceivedIpPacket& packet) { RTC_DCHECK_RUN_ON(thread_); // Fail if the packet is too small to even contain a channel header. - ArrayView<const uint8_t> payload = packet.payload(); + std::span<const uint8_t> payload = packet.payload(); if (payload.size() < TURN_CHANNEL_HEADER_SIZE) { return; } @@ -197,7 +197,7 @@ } void TurnServer::HandleStunMessage(TurnServerConnection* conn, - ArrayView<const uint8_t> payload, + std::span<const uint8_t> payload, EcnMarking ecn) { RTC_DCHECK_RUN_ON(thread_); TurnMessage msg; @@ -398,7 +398,7 @@ // Decode the timestamp. int64_t then; char* p = reinterpret_cast<char*>(&then); - size_t len = hex_decode(ArrayView<char>(p, sizeof(then)), + size_t len = hex_decode(std::span<char>(p, sizeof(then)), nonce.substr(0, sizeof(then) * 2)); if (len != sizeof(then)) { return false; @@ -784,7 +784,7 @@ SendResponse(&response); } -void TurnServerAllocation::HandleChannelData(ArrayView<const uint8_t> payload, +void TurnServerAllocation::HandleChannelData(std::span<const uint8_t> payload, EcnMarking ecn) { // Extract the channel number from the data. uint16_t channel_id = GetBE16(payload); @@ -809,7 +809,7 @@ ByteBufferWriter buf; buf.WriteUInt16(channel->id); buf.WriteUInt16(static_cast<uint16_t>(packet.payload().size())); - buf.Write(ArrayView<const uint8_t>(packet.payload())); + buf.Write(std::span<const uint8_t>(packet.payload())); server_->Send(&conn_, buf, packet.ecn()); } else if (!server_->enable_permission_checks_ || HasPermission(packet.source_address().ipaddr())) {
diff --git a/p2p/test/turn_server.h b/p2p/test/turn_server.h index 501bafe..1258682 100644 --- a/p2p/test/turn_server.h +++ b/p2p/test/turn_server.h
@@ -16,11 +16,11 @@ #include <list> #include <map> #include <memory> +#include <span> #include <string> #include <utility> #include "absl/strings/string_view.h" -#include "api/array_view.h" #include "api/environment/environment.h" #include "api/packet_socket_factory.h" #include "api/sequence_checker.h" @@ -97,7 +97,7 @@ std::string ToString() const; void HandleTurnMessage(const TurnMessage* msg, EcnMarking ecn); - void HandleChannelData(ArrayView<const uint8_t> payload, EcnMarking ecn); + void HandleChannelData(std::span<const uint8_t> payload, EcnMarking ecn); private: struct Channel { @@ -176,7 +176,7 @@ class StunMessageObserver { public: virtual void ReceivedMessage(const TurnMessage* msg) = 0; - virtual void ReceivedChannelData(ArrayView<const uint8_t> payload) = 0; + virtual void ReceivedChannelData(std::span<const uint8_t> payload) = 0; virtual ~StunMessageObserver() {} }; @@ -290,7 +290,7 @@ void OnInternalSocketClose(AsyncPacketSocket* socket, int err); void HandleStunMessage(TurnServerConnection* conn, - ArrayView<const uint8_t> payload, + std::span<const uint8_t> payload, EcnMarking ecn) RTC_RUN_ON(thread_); void HandleBindingRequest(TurnServerConnection* conn, const StunMessage* msg) RTC_RUN_ON(thread_);