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

Code before:
         */
        std::optional<Network> PickNetwork(std::optional<Proxy>& proxy) const;

        /// Get the pending number of connections to open.
        size_t NumToOpen() const;

        /**
         * Increment the number of new connections of type `ConnectionType::PRIVATE_BROADCAST`
         * to be opened by `CConnman::ThreadPrivateBroadcast()`.
         * @param[in] n Increment by this number.
         */
        void NumToOpenAdd(size_t n);

        /**
         * Decrement the number of new connections of type `ConnectionType::PRIVATE_BROADCAST`
         * to be opened by `CConnman::ThreadPrivateBroadcast()`.
         * @param[in] n Decrement by this number.
         * @return The number of connections that remain to be opened after the operation.
         */
        size_t NumToOpenSub(size_t n);

        /// Wait for the number of needed connections to become greater than 0.
        void NumToOpenWait() const;

        /// Reset the state of this.
        void Reset();

    private:
        /**
         * Check if private broadcast can be done to IPv4 or IPv6 peers and if so via which proxy.
         * If private broadcast connections should not be opened to IPv4 or IPv6, then this will
         * return an empty optional.
         */
        std::optional<Proxy> ProxyForIPv4or6() const;

        /// Number of `ConnectionType::PRIVATE_BROADCAST` connections to open.
        std::atomic_size_t m_num_to_open{0};
    } m_private_broadcast;

    bool CheckIncomingNonce(uint64_t nonce);
    void ASMapHealthCheck();

    // alias for thread safety annotations only, not defined
    RecursiveMutex& GetNodesMutex() const LOCK_RETURNED(m_nodes_mutex);

    bool ForNode(NodeId id, std::function<bool(CNode* pnode)> func);

    void PushMessage(CNode* pnode, CSerializedNetMsg&& msg) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);

    using NodeFn = std::function<void(CNode*)>;
    void ForEachNode(const NodeFn& func)

Review comment (suggestion):
Not sure about adding test-only code to the real code. This can be fixed by changing the line below from `private` to `protected`. and then moving `PrivateBroadcast::Reset()` to `PrivateBroadcastTest::Reset()` (or so) in src/test/util/net.h

Code after:
         */
        std::optional<Network> PickNetwork(std::optional<Proxy>& proxy) const;

        /// Get the pending number of connections to open.
        size_t NumToOpen() const;

        /**
         * Increment the number of new connections of type `ConnectionType::PRIVATE_BROADCAST`
         * to be opened by `CConnman::ThreadPrivateBroadcast()`.
         * @param[in] n Increment by this number.
         */
        void NumToOpenAdd(size_t n);

        /**
         * Decrement the number of new connections of type `ConnectionType::PRIVATE_BROADCAST`
         * to be opened by `CConnman::ThreadPrivateBroadcast()`.
         * @param[in] n Decrement by this number.
         * @return The number of connections that remain to be opened after the operation.
         */
        size_t NumToOpenSub(size_t n);

        /// Wait for the number of needed connections to become greater than 0.
        void NumToOpenWait() const;

    protected:
        /**
         * Check if private broadcast can be done to IPv4 or IPv6 peers and if so via which proxy.
         * If private broadcast connections should not be opened to IPv4 or IPv6, then this will
         * return an empty optional.
         */
        std::optional<Proxy> ProxyForIPv4or6() const;

        /// Number of `ConnectionType::PRIVATE_BROADCAST` connections to open.
        std::atomic_size_t m_num_to_open{0};

        friend struct ConnmanTestMsg;
    } m_private_broadcast;

    bool CheckIncomingNonce(uint64_t nonce);
    void ASMapHealthCheck();

    // alias for thread safety annotations only, not defined
    RecursiveMutex& GetNodesMutex() const LOCK_RETURNED(m_nodes_mutex);

    bool ForNode(NodeId id, std::function<bool(CNode* pnode)> func);

    void PushMessage(CNode* pnode, CSerializedNetMsg&& msg) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);

    using NodeFn = std::function<void(CNode*)>;
    void ForEachNode(const NodeFn& func)
    {