#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "services/network/p2p/socket_test_utils.h"
#include <stddef.h>
#include "base/check.h"
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/notreached.h"
#include "base/numerics/byte_conversions.h"
#include "base/numerics/safe_conversions.h"
#include "base/ranges/algorithm.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "net/base/io_buffer.h"
#include "net/base/ip_address.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
namespace network {
const int kStunHeaderSize = …;
const uint16_t kStunBindingRequest = …;
const uint16_t kStunBindingResponse = …;
const uint16_t kStunBindingError = …;
const uint32_t kStunMagicCookie = …;
FakeP2PSocketDelegate::FakeP2PSocketDelegate() = default;
FakeP2PSocketDelegate::~FakeP2PSocketDelegate() { … }
void FakeP2PSocketDelegate::DestroySocket(P2PSocket* socket) { … }
void FakeP2PSocketDelegate::DumpPacket(base::span<const uint8_t> data,
bool incoming) { … }
void FakeP2PSocketDelegate::AddAcceptedConnection(
std::unique_ptr<P2PSocket> accepted) { … }
void FakeP2PSocketDelegate::ExpectDestruction(
std::unique_ptr<P2PSocket> socket) { … }
std::unique_ptr<P2PSocket> FakeP2PSocketDelegate::pop_accepted_socket() { … }
FakeSocket::FakeSocket(std::string* written_data)
: … { … }
FakeSocket::~FakeSocket() { … }
void FakeSocket::AppendInputData(const char* data, int data_size) { … }
void FakeSocket::SetPeerAddress(const net::IPEndPoint& peer_address) { … }
void FakeSocket::SetLocalAddress(const net::IPEndPoint& local_address) { … }
int FakeSocket::Read(net::IOBuffer* buf,
int buf_len,
net::CompletionOnceCallback callback) { … }
int FakeSocket::Write(
net::IOBuffer* buf,
int buf_len,
net::CompletionOnceCallback callback,
const net::NetworkTrafficAnnotationTag& ) { … }
void FakeSocket::DoAsyncWrite(scoped_refptr<net::IOBuffer> buf,
int buf_len,
net::CompletionOnceCallback callback) { … }
int FakeSocket::SetReceiveBufferSize(int32_t size) { … }
int FakeSocket::SetSendBufferSize(int32_t size) { … }
int FakeSocket::Connect(net::CompletionOnceCallback callback) { … }
void FakeSocket::Disconnect() { … }
bool FakeSocket::IsConnected() const { … }
bool FakeSocket::IsConnectedAndIdle() const { … }
int FakeSocket::GetPeerAddress(net::IPEndPoint* address) const { … }
int FakeSocket::GetLocalAddress(net::IPEndPoint* address) const { … }
const net::NetLogWithSource& FakeSocket::NetLog() const { … }
bool FakeSocket::WasEverUsed() const { … }
net::NextProto FakeSocket::GetNegotiatedProtocol() const { … }
bool FakeSocket::GetSSLInfo(net::SSLInfo* ssl_info) { … }
int64_t FakeSocket::GetTotalReceivedBytes() const { … }
FakeSocketClient::FakeSocketClient(
mojo::PendingRemote<mojom::P2PSocket> socket,
mojo::PendingReceiver<mojom::P2PSocketClient> client_receiver)
: … { … }
FakeSocketClient::~FakeSocketClient() { … }
FakeNetworkNotificationClient::FakeNetworkNotificationClient(
base::OnceClosure closure,
mojo::PendingReceiver<mojom::P2PNetworkNotificationClient>
notification_client)
: … { … }
FakeNetworkNotificationClient::~FakeNetworkNotificationClient() = default;
void FakeNetworkNotificationClient::NetworkListChanged(
const std::vector<::net::NetworkInterface>& networks,
const ::net::IPAddress& default_ipv4_local_address,
const ::net::IPAddress& default_ipv6_local_address) { … }
void CreateRandomPacket(std::vector<uint8_t>* packet) { … }
static void CreateStunPacket(std::vector<uint8_t>* packet, uint16_t type) { … }
void CreateStunRequest(std::vector<uint8_t>* packet) { … }
void CreateStunResponse(std::vector<uint8_t>* packet) { … }
void CreateStunError(std::vector<uint8_t>* packet) { … }
net::IPEndPoint ParseAddress(const std::string& ip_str, uint16_t port) { … }
}