chromium/services/network/p2p/socket_manager.cc

// Copyright 2018 The Chromium Authors
// 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>

#include <optional>
#include <utility>

#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/not_fatal_until.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/thread_pool.h"
#include "net/base/address_family.h"
#include "net/base/address_list.h"
#include "net/base/net_errors.h"
#include "net/base/network_anonymization_key.h"
#include "net/base/network_interfaces.h"
#include "net/base/sys_addrinfo.h"
#include "net/dns/dns_util.h"
#include "net/dns/host_resolver.h"
#include "net/http/http_network_session.h"
#include "net/log/net_log_source.h"
#include "net/log/net_log_with_source.h"
#include "net/socket/client_socket_factory.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "services/network/p2p/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 "third_party/webrtc/media/base/turn_utils.h"

namespace network {

namespace {

// Used by GetDefaultLocalAddress as the target to connect to for getting the
// default local address. They are public DNS servers on the internet.
const uint8_t kPublicIPv4Host[] =;
const uint8_t kPublicIPv6Host[] =;
const int kPublicPort =;  // DNS port.

// Experimentation shows that creating too many sockets creates odd problems
// because of resource exhaustion in the Unix sockets domain.
// Trouble has been seen on Linux at 3479 sockets in test, so leave a margin.
const int kMaxSimultaneousSockets =;

const size_t kMinRtcpHeaderLength =;
const size_t kDtlsRecordHeaderLength =;

bool IsDtlsPacket(base::span<const uint8_t> data) {}

bool IsRtcpPacket(base::span<const uint8_t> data) {}

// Names ending in ".local." are link-local and used with Multicast DNS as
// described in RFC6762 (https://tools.ietf.org/html/rfc6762#section-3).
constexpr char kLocalTld[] =;

bool HasLocalTld(const std::string& host_name) {}

net::DnsQueryType FamilyToDnsQueryType(int family) {}

}  // namespace

DefaultLocalAddresses::DefaultLocalAddresses() = default;
DefaultLocalAddresses::~DefaultLocalAddresses() = default;

class P2PSocketManager::DnsRequest {};

P2PSocketManager::P2PSocketManager(
    const net::NetworkAnonymizationKey& network_anonymization_key,
    mojo::PendingRemote<mojom::P2PTrustedSocketManagerClient>
        trusted_socket_manager_client,
    mojo::PendingReceiver<mojom::P2PTrustedSocketManager>
        trusted_socket_manager_receiver,
    mojo::PendingReceiver<mojom::P2PSocketManager> socket_manager_receiver,
    DeleteCallback delete_callback,
    net::URLRequestContext* url_request_context)
    :{}

P2PSocketManager::~P2PSocketManager() {}

void P2PSocketManager::OnNetworkChanged(
    net::NetworkChangeNotifier::ConnectionType type) {}

void P2PSocketManager::PauseNetworkChangeNotifications() {}

void P2PSocketManager::ResumeNetworkChangeNotifications() {}

void P2PSocketManager::AddAcceptedConnection(
    std::unique_ptr<P2PSocket> accepted_connection) {}

void P2PSocketManager::DestroySocket(P2PSocket* socket) {}

void P2PSocketManager::DumpPacket(base::span<const uint8_t> packet,
                                  bool incoming) {}

net::NetworkInterfaceList P2PSocketManager::DoGetNetworkList() {}

void P2PSocketManager::DoGetDefaultLocalAddresses(
    net::NetworkInterfaceList list) {}

void P2PSocketManager::MaybeFinishDoGetDefaultLocalAddresses(
    DefaultLocalAddresses* default_local_addresses,
    net::NetworkInterfaceList list,
    int family,
    net::IPAddress addr) {}

void P2PSocketManager::GetDefaultLocalAddress(int family,
                                              GetDefaultCallback callback) {}

void P2PSocketManager::FinishGetDefaultLocalAddress(
    std::unique_ptr<net::DatagramClientSocket> socket,
    GetDefaultCallback callback,
    int result) {}

void P2PSocketManager::SendNetworkList(
    const net::NetworkInterfaceList& list,
    net::IPAddress default_ipv4_local_address,
    net::IPAddress default_ipv6_local_address) {}

void P2PSocketManager::StartNetworkNotifications(
    mojo::PendingRemote<mojom::P2PNetworkNotificationClient> client) {}

void P2PSocketManager::GetHostAddress(
    const std::string& host_name,
    bool enable_mdns,
    mojom::P2PSocketManager::GetHostAddressCallback callback) {}

void P2PSocketManager::GetHostAddressWithFamily(
    const std::string& host_name,
    int address_family,
    bool enable_mdns,
    mojom::P2PSocketManager::GetHostAddressCallback callback) {}

void P2PSocketManager::DoGetHostAddress(
    const std::string& host_name,
    std::optional<int> address_family,
    bool enable_mdns,
    mojom::P2PSocketManager::GetHostAddressCallback callback) {}

void P2PSocketManager::CreateSocket(
    P2PSocketType type,
    const net::IPEndPoint& local_address,
    const P2PPortRange& port_range,
    const P2PHostAndIPEndPoint& remote_address,
    const net::MutableNetworkTrafficAnnotationTag& traffic_annotation,
    const std::optional<base::UnguessableToken>& devtools_token,
    mojo::PendingRemote<mojom::P2PSocketClient> client,
    mojo::PendingReceiver<mojom::P2PSocket> receiver) {}

void P2PSocketManager::StartRtpDump(bool incoming, bool outgoing) {}

void P2PSocketManager::StopRtpDump(bool incoming, bool outgoing) {}

void P2PSocketManager::NetworkNotificationClientConnectionError() {}

void P2PSocketManager::OnAddressResolved(
    DnsRequest* request,
    mojom::P2PSocketManager::GetHostAddressCallback callback,
    const net::IPAddressList& addresses) {}

void P2PSocketManager::OnConnectionError() {}

}  // namespace network