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

Code before:
         */
        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;

    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)
    {
        LOCK(m_nodes_mutex);
        for (auto&& node : m_nodes) {
            if (NodeFullyConnected(node))
                func(node);
        }
    };

    void ForEachNode(const NodeFn& func) const
    {
        LOCK(m_nodes_mutex);
        for (auto&& node : m_nodes) {
            if (NodeFullyConnected(node))

Review comment (suggestion):
Not sure about adding test-only code to real code. This can be avoided by defining a

```cpp
struct PrivateBroadcastTest : public PrivateBroadcast {
void Reset(){
m_outbound_tor_ok_at_least_once.store(false);
    m_num_to_open.store(0);
}
};
```

And then calling `static_cast<PrivateBroadcastTest&>(m_private_broadcast).Reset()` in the `ConnmanTestMsg::Reset()`.

Code after:
         */
        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)
    {
        LOCK(m_nodes_mutex);
        for (auto&& node : m_nodes) {
            if (NodeFullyConnected(node))
                func(node);
        }
    };

    void ForEachNode(const NodeFn& func) const
    {
        LOCK(m_nodes_mutex);