#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "services/network/p2p/socket_tcp.h"
#include <stddef.h>
#include <utility>
#include "base/containers/span.h"
#include "base/containers/span_writer.h"
#include "base/functional/bind.h"
#include "base/numerics/byte_conversions.h"
#include "base/time/time.h"
#include "components/webrtc/fake_ssl_client_socket.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/base/network_anonymization_key.h"
#include "net/socket/client_socket_factory.h"
#include "net/socket/client_socket_handle.h"
#include "net/socket/ssl_client_socket.h"
#include "net/socket/tcp_client_socket.h"
#include "services/network/proxy_resolving_client_socket.h"
#include "services/network/proxy_resolving_client_socket_factory.h"
#include "services/network/public/cpp/p2p_param_traits.h"
#include "third_party/webrtc/media/base/rtp_utils.h"
#include "url/gurl.h"
namespace network {
namespace {
PacketLength;
const int kPacketHeaderSize = …;
const int kTcpReadBufferSize = …;
const int kPacketLengthOffset = …;
const int kTurnChannelDataHeaderSize = …;
const int kTcpRecvSocketBufferSize = …;
const int kTcpSendSocketBufferSize = …;
bool IsTlsClientSocket(P2PSocketType type) { … }
bool IsPseudoTlsClientSocket(P2PSocketType type) { … }
}
P2PSocketTcp::SendBuffer::SendBuffer() : … { … }
P2PSocketTcp::SendBuffer::SendBuffer(
int32_t rtc_packet_id,
scoped_refptr<net::DrainableIOBuffer> buffer)
: … { … }
P2PSocketTcp::SendBuffer::SendBuffer(const SendBuffer& rhs) = default;
P2PSocketTcp::SendBuffer::~SendBuffer() = default;
P2PSocketTcpBase::P2PSocketTcpBase(
Delegate* delegate,
mojo::PendingRemote<mojom::P2PSocketClient> client,
mojo::PendingReceiver<mojom::P2PSocket> socket,
P2PSocketType type,
const net::NetworkTrafficAnnotationTag& traffic_annotation,
ProxyResolvingClientSocketFactory* proxy_resolving_socket_factory)
: … { … }
P2PSocketTcpBase::~P2PSocketTcpBase() = default;
void P2PSocketTcpBase::InitAccepted(const net::IPEndPoint& remote_address,
std::unique_ptr<net::StreamSocket> socket) { … }
void P2PSocketTcpBase::Init(
const net::IPEndPoint& local_address,
uint16_t min_port,
uint16_t max_port,
const P2PHostAndIPEndPoint& remote_address,
const net::NetworkAnonymizationKey& network_anonymization_key) { … }
void P2PSocketTcpBase::OnConnected(int result) { … }
void P2PSocketTcpBase::OnOpen() { … }
bool P2PSocketTcpBase::DoSendSocketCreateMsg() { … }
void P2PSocketTcpBase::DoRead() { … }
void P2PSocketTcpBase::OnRead(int result) { … }
bool P2PSocketTcpBase::OnPacket(base::span<const uint8_t> data) { … }
void P2PSocketTcpBase::WriteOrQueue(SendBuffer& send_buffer) { … }
void P2PSocketTcpBase::DoWrite() { … }
void P2PSocketTcpBase::OnWritten(int result) { … }
bool P2PSocketTcpBase::HandleWriteResult(int result) { … }
bool P2PSocketTcpBase::HandleReadResult(int result) { … }
bool P2PSocketTcpBase::SendPacket(base::span<const uint8_t> data,
const P2PPacketInfo& packet_info) { … }
void P2PSocketTcpBase::Send(base::span<const uint8_t> data,
const P2PPacketInfo& packet_info) { … }
void P2PSocketTcpBase::SendBatch(
std::vector<mojom::P2PSendPacketPtr> packet_batch) { … }
void P2PSocketTcpBase::SetOption(P2PSocketOption option, int32_t value) { … }
P2PSocketTcp::P2PSocketTcp(
Delegate* delegate,
mojo::PendingRemote<mojom::P2PSocketClient> client,
mojo::PendingReceiver<mojom::P2PSocket> socket,
P2PSocketType type,
const net::NetworkTrafficAnnotationTag& traffic_annotation,
ProxyResolvingClientSocketFactory* proxy_resolving_socket_factory)
: … { … }
P2PSocketTcp::~P2PSocketTcp() { … }
bool P2PSocketTcp::ProcessInput(base::span<const uint8_t> input,
size_t* bytes_consumed) { … }
void P2PSocketTcp::DoSend(const net::IPEndPoint& to,
base::span<const uint8_t> data,
const rtc::PacketOptions& options) { … }
P2PSocketStunTcp::P2PSocketStunTcp(
Delegate* delegate,
mojo::PendingRemote<mojom::P2PSocketClient> client,
mojo::PendingReceiver<mojom::P2PSocket> socket,
P2PSocketType type,
const net::NetworkTrafficAnnotationTag& traffic_annotation,
ProxyResolvingClientSocketFactory* proxy_resolving_socket_factory)
: … { … }
P2PSocketStunTcp::~P2PSocketStunTcp() { … }
bool P2PSocketStunTcp::ProcessInput(base::span<const uint8_t> input,
size_t* bytes_consumed) { … }
void P2PSocketStunTcp::DoSend(const net::IPEndPoint& to,
base::span<const uint8_t> data,
const rtc::PacketOptions& options) { … }
int P2PSocketStunTcp::GetExpectedPacketSize(base::span<const uint8_t> data,
int* pad_bytes) { … }
}