Spanify production code in services/network/p2p/
This largely involves migrating to the newer span-based net::IOBuffer APIs. Bug: 351564777 Change-Id: I88e9717ba51593e18d11f070b2ac9210a8dda01b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6506171 Commit-Queue: Harald Alvestrand <hta@chromium.org> Reviewed-by: Harald Alvestrand <hta@chromium.org> Cr-Commit-Position: refs/heads/main@{#1456966}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
f2a1313fb3
commit
167bb9f9e9
services/network/p2p
@ -2,11 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifdef UNSAFE_BUFFERS_BUILD
|
||||
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
|
||||
#pragma allow_unsafe_buffers
|
||||
#endif
|
||||
|
||||
#include "services/network/p2p/socket_manager.h"
|
||||
|
||||
#include <stddef.h>
|
||||
@ -270,8 +265,8 @@ void P2PSocketManager::DumpPacket(base::span<const uint8_t> packet,
|
||||
NOTREACHED();
|
||||
}
|
||||
|
||||
std::vector<uint8_t> header_buffer(rtp_packet.data(),
|
||||
rtp_packet.data() + header_size);
|
||||
std::vector<uint8_t> header_buffer(rtp_packet.begin(),
|
||||
rtp_packet.begin() + header_size);
|
||||
trusted_socket_manager_client_->DumpPacket(header_buffer, rtp_packet.size(),
|
||||
incoming);
|
||||
}
|
||||
|
@ -2,16 +2,12 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifdef UNSAFE_BUFFERS_BUILD
|
||||
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
|
||||
#pragma allow_unsafe_buffers
|
||||
#endif
|
||||
|
||||
#include "services/network/p2p/socket_tcp.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "base/containers/span.h"
|
||||
#include "base/containers/span_writer.h"
|
||||
@ -466,9 +462,10 @@ void P2PSocketTcp::DoSend(const net::IPEndPoint& to,
|
||||
CHECK_EQ(writer.remaining(), 0u);
|
||||
}
|
||||
|
||||
webrtc::ApplyPacketOptions(
|
||||
send_buffer.buffer->bytes() + kPacketHeaderSize,
|
||||
send_buffer.buffer->BytesRemaining() - kPacketHeaderSize,
|
||||
base::span<uint8_t> send_buffer_without_header =
|
||||
send_buffer.buffer->span().subspan(kPacketHeaderSize);
|
||||
webrtc::ApplyPacketOptions(send_buffer_without_header.data(),
|
||||
send_buffer_without_header.size(),
|
||||
options.packet_time_params, webrtc::TimeMicros());
|
||||
|
||||
WriteOrQueue(send_buffer);
|
||||
@ -527,28 +524,25 @@ void P2PSocketStunTcp::DoSend(const net::IPEndPoint& to,
|
||||
|
||||
// Add any pad bytes to the total size.
|
||||
int buffer_size = data.size() + pad_bytes;
|
||||
std::vector<uint8_t> buffer;
|
||||
buffer.reserve(buffer_size);
|
||||
buffer.assign(data.begin(), data.end());
|
||||
if (pad_bytes) {
|
||||
DCHECK_LE(pad_bytes, 4);
|
||||
buffer.insert(buffer.end(), pad_bytes, 0);
|
||||
}
|
||||
|
||||
SendBuffer send_buffer(
|
||||
options.packet_id,
|
||||
base::MakeRefCounted<net::DrainableIOBuffer>(
|
||||
base::MakeRefCounted<net::IOBufferWithSize>(buffer_size),
|
||||
base::MakeRefCounted<net::VectorIOBuffer>(std::move(buffer)),
|
||||
buffer_size));
|
||||
memcpy(send_buffer.buffer->data(), data.data(), data.size());
|
||||
|
||||
webrtc::ApplyPacketOptions(send_buffer.buffer->bytes(), data.size(),
|
||||
options.packet_time_params, webrtc::TimeMicros());
|
||||
|
||||
if (pad_bytes) {
|
||||
char padding[4] = {};
|
||||
DCHECK_LE(pad_bytes, 4);
|
||||
memcpy(send_buffer.buffer->data() + data.size(), padding, pad_bytes);
|
||||
}
|
||||
|
||||
// WriteOrQueue may free the memory, so dump it first.
|
||||
delegate_->DumpPacket(
|
||||
base::span(reinterpret_cast<const uint8_t*>(send_buffer.buffer->data()),
|
||||
data.size()),
|
||||
false);
|
||||
delegate_->DumpPacket(send_buffer.buffer->span(), false);
|
||||
|
||||
WriteOrQueue(send_buffer);
|
||||
}
|
||||
|
@ -2,11 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifdef UNSAFE_BUFFERS_BUILD
|
||||
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
|
||||
#pragma allow_unsafe_buffers
|
||||
#endif
|
||||
|
||||
#include "services/network/p2p/socket_udp.h"
|
||||
|
||||
#include <tuple>
|
||||
@ -115,12 +110,10 @@ P2PPendingPacket::P2PPendingPacket(
|
||||
const webrtc::AsyncSocketPacketOptions& options,
|
||||
uint64_t id)
|
||||
: to(to),
|
||||
data(base::MakeRefCounted<net::IOBufferWithSize>(content.size())),
|
||||
data(base::MakeRefCounted<net::VectorIOBuffer>(content)),
|
||||
size(content.size()),
|
||||
packet_options(options),
|
||||
id(id) {
|
||||
memcpy(data->data(), content.data(), content.size());
|
||||
}
|
||||
id(id) {}
|
||||
|
||||
P2PPendingPacket::P2PPendingPacket(const P2PPendingPacket& other) = default;
|
||||
P2PPendingPacket::~P2PPendingPacket() = default;
|
||||
@ -298,9 +291,7 @@ void P2PSocketUdp::MaybeDrainReceivedPackets(bool force) {
|
||||
|
||||
bool P2PSocketUdp::HandleReadResult(int result) {
|
||||
if (result > 0) {
|
||||
auto data =
|
||||
base::span(reinterpret_cast<const uint8_t*>(recv_buffer_->data()),
|
||||
static_cast<size_t>(result));
|
||||
auto data = recv_buffer_->first(static_cast<size_t>(result));
|
||||
|
||||
if (!base::Contains(connected_peers_, recv_address_)) {
|
||||
P2PSocket::StunMessageType type;
|
||||
@ -364,10 +355,7 @@ bool P2PSocketUdp::DoSend(const P2PPendingPacket& packet) {
|
||||
// messages are sent in correct order.
|
||||
if (!base::Contains(connected_peers_, packet.to)) {
|
||||
P2PSocket::StunMessageType type = P2PSocket::StunMessageType();
|
||||
bool stun = GetStunPacketType(
|
||||
base::span(reinterpret_cast<const uint8_t*>(packet.data->data()),
|
||||
packet.size),
|
||||
&type);
|
||||
bool stun = GetStunPacketType(packet.data->first(packet.size), &type);
|
||||
if (!stun || type == STUN_DATA_INDICATION) {
|
||||
LOG(ERROR) << "Page tried to send a data packet to "
|
||||
<< packet.to.ToString() << " before STUN binding is finished.";
|
||||
@ -437,10 +425,7 @@ bool P2PSocketUdp::DoSend(const P2PPendingPacket& packet) {
|
||||
}
|
||||
}
|
||||
|
||||
delegate_->DumpPacket(
|
||||
base::span(reinterpret_cast<const uint8_t*>(packet.data->data()),
|
||||
packet.size),
|
||||
false);
|
||||
delegate_->DumpPacket(packet.data->first(packet.size), false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user