Repository: bitcoin/bitcoin
File: src/net.h (C/C++)

Code before:
    /**
     * Determine whether we're already connected to a given address.
     */
    bool AlreadyConnectedToAddress(const CNetAddr& addr) const;

    bool AttemptToEvictConnection();
    CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure, ConnectionType conn_type, bool use_v2transport) EXCLUSIVE_LOCKS_REQUIRED(!m_unused_i2p_sessions_mutex);
    void AddWhitelistPermissionFlags(NetPermissionFlags& flags, std::optional<CNetAddr> addr, const std::vector<NetWhitelistPermissions>& ranges) const;

    void DeleteNode(CNode* pnode);

    NodeId GetNewNodeId();

    /** (Try to) send data from node's vSendMsg. Returns (bytes_sent, data_left). */
    std::pair<size_t, bool> SocketSendData(CNode& node) const EXCLUSIVE_LOCKS_REQUIRED(node.cs_vSend);

    void DumpAddresses();

    // Network stats
    void RecordBytesRecv(uint64_t bytes);
    void RecordBytesSent(uint64_t bytes) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);

    /**
     Return reachable networks for which we have no addresses in addrman and therefore
     may require loading fixed seeds.
     */
    std::unordered_set<Network> GetReachableEmptyNetworks() const;

    /**
     * Return vector of current BLOCK_RELAY peers.
     */
    std::vector<CAddress> GetCurrentBlockRelayOnlyConns() const;

    /**
     * Search for a "preferred" network, a reachable network to which we
     * currently don't have any OUTBOUND_FULL_RELAY or MANUAL connections.
     * There needs to be at least one address in AddrMan for a preferred
     * network to be picked.
     *
     * @param[out]    network        Preferred network, if found.
     *
     * @return           bool        Whether a preferred network was found.
     */
    bool MaybePickPreferredNetwork(std::optional<Network>& network);

    // Whether the node should be passed out in ForEach* callbacks
    static bool NodeFullyConnected(const CNode* pnode);

    uint16_t GetDefaultPort(Network net) const;
    uint16_t GetDefaultPort(const std::string& addr) const;


Review comment (suggestion):
should be `proxy_arg` to be consistent with the definition (although maybe `proxy_override` would be better?)

Code after:

    uint64_t CalculateKeyedNetGroup(const CNetAddr& ad) const;

    /**
     * Determine whether we're already connected to a given "host:port".
     * Note that for inbound connections, the peer is likely using a random outbound
     * port on their side, so this will likely not match any inbound connections.
     * @param[in] host String of the form "host[:port]", e.g. "localhost" or "localhost:8333" or "1.2.3.4:8333".
     * @return true if connected to `host`.
     */
    bool AlreadyConnectedToHost(const std::string& host) const;

    /**
     * Determine whether we're already connected to a given address:port.
     * Note that for inbound connections, the peer is likely using a random outbound
     * port on their side, so this will likely not match any inbound connections.
     * @param[in] addr_port Address and port to check.
     * @return true if connected to addr_port.
     */
    bool AlreadyConnectedToAddressPort(const CService& addr_port) const;

    /**
     * Determine whether we're already connected to a given address.
     */
    bool AlreadyConnectedToAddress(const CNetAddr& addr) const;

    bool AttemptToEvictConnection();

    /**
     * Open a new P2P connection.
     * @param[in] addrConnect Address to connect to, if `pszDest` is `nullptr`.
     * @param[in] pszDest Address to resolve and connect to.
     * @param[in] fCountFailure Increment the number of connection attempts to this address in Addrman.
     * @param[in] conn_type Type of the connection to open, must not be `ConnectionType::INBOUND`.
     * @param[in] use_v2transport Use P2P encryption, (aka V2 transport, BIP324).
     * @param[in] proxy_override Optional proxy to use and override normal proxy selection.
     * @return Newly created CNode object or nullptr if the connection failed.
     */
    CNode* ConnectNode(CAddress addrConnect,
                       const char* pszDest,
                       bool fCountFailure,
                       ConnectionType conn_type,
                       bool use_v2transport,
                       const std::optional<Proxy>& proxy_override)
        EXCLUSIVE_LOCKS_REQUIRED(!m_unused_i2p_sessions_mutex);

    void AddWhitelistPermissionFlags(NetPermissionFlags& flags, std::optional<CNetAddr> addr, const std::vector<NetWhitelistPermissions>& ranges) const;

    void DeleteNode(CNode* pnode);

    NodeId GetNewNodeId();