mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-18 16:42:54 +01:00
Allow unit tests to access additional CConnman members
that are otherwise private: - CConnman::m_nodes - CConnman::ConnectNodes() - CConnman::AlreadyConnectedToAddress() and update the #include headers per iwyu.
This commit is contained in:
committed by
Sergi Delgado Segura
parent
34b9ef443b
commit
4b834f6499
@@ -4,11 +4,15 @@
|
|||||||
|
|
||||||
#include <test/util/net.h>
|
#include <test/util/net.h>
|
||||||
|
|
||||||
#include <chainparams.h>
|
|
||||||
#include <node/eviction.h>
|
|
||||||
#include <net.h>
|
#include <net.h>
|
||||||
#include <net_processing.h>
|
#include <net_processing.h>
|
||||||
|
#include <netaddress.h>
|
||||||
#include <netmessagemaker.h>
|
#include <netmessagemaker.h>
|
||||||
|
#include <node/connection_types.h>
|
||||||
|
#include <node/eviction.h>
|
||||||
|
#include <protocol.h>
|
||||||
|
#include <random.h>
|
||||||
|
#include <serialize.h>
|
||||||
#include <span.h>
|
#include <span.h>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -98,6 +102,17 @@ bool ConnmanTestMsg::ReceiveMsgFrom(CNode& node, CSerializedNetMsg&& ser_msg) co
|
|||||||
return complete;
|
return complete;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CNode* ConnmanTestMsg::ConnectNodePublic(PeerManager& peerman, const char* pszDest, ConnectionType conn_type)
|
||||||
|
{
|
||||||
|
CNode* node = ConnectNode(CAddress{}, pszDest, /*fCountFailure=*/false, conn_type, /*use_v2transport=*/true);
|
||||||
|
if (!node) return nullptr;
|
||||||
|
node->SetCommonVersion(PROTOCOL_VERSION);
|
||||||
|
peerman.InitializeNode(*node, ServiceFlags(NODE_NETWORK | NODE_WITNESS));
|
||||||
|
node->fSuccessfullyConnected = true;
|
||||||
|
AddTestNode(*node);
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<NodeEvictionCandidate> GetRandomNodeEvictionCandidates(int n_candidates, FastRandomContext& random_context)
|
std::vector<NodeEvictionCandidate> GetRandomNodeEvictionCandidates(int n_candidates, FastRandomContext& random_context)
|
||||||
{
|
{
|
||||||
std::vector<NodeEvictionCandidate> candidates;
|
std::vector<NodeEvictionCandidate> candidates;
|
||||||
|
|||||||
@@ -6,16 +6,30 @@
|
|||||||
#define BITCOIN_TEST_UTIL_NET_H
|
#define BITCOIN_TEST_UTIL_NET_H
|
||||||
|
|
||||||
#include <compat/compat.h>
|
#include <compat/compat.h>
|
||||||
#include <node/eviction.h>
|
|
||||||
#include <netaddress.h>
|
|
||||||
#include <net.h>
|
#include <net.h>
|
||||||
|
#include <net_permissions.h>
|
||||||
|
#include <net_processing.h>
|
||||||
|
#include <netaddress.h>
|
||||||
|
#include <node/connection_types.h>
|
||||||
|
#include <node/eviction.h>
|
||||||
|
#include <sync.h>
|
||||||
#include <util/sock.h>
|
#include <util/sock.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <chrono>
|
||||||
|
#include <cstdint>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class FastRandomContext;
|
||||||
|
|
||||||
|
template <typename C>
|
||||||
|
class Span;
|
||||||
|
|
||||||
struct ConnmanTestMsg : public CConnman {
|
struct ConnmanTestMsg : public CConnman {
|
||||||
using CConnman::CConnman;
|
using CConnman::CConnman;
|
||||||
@@ -25,6 +39,12 @@ struct ConnmanTestMsg : public CConnman {
|
|||||||
m_peer_connect_timeout = timeout;
|
m_peer_connect_timeout = timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<CNode*> TestNodes()
|
||||||
|
{
|
||||||
|
LOCK(m_nodes_mutex);
|
||||||
|
return m_nodes;
|
||||||
|
}
|
||||||
|
|
||||||
void AddTestNode(CNode& node)
|
void AddTestNode(CNode& node)
|
||||||
{
|
{
|
||||||
LOCK(m_nodes_mutex);
|
LOCK(m_nodes_mutex);
|
||||||
@@ -56,6 +76,11 @@ struct ConnmanTestMsg : public CConnman {
|
|||||||
|
|
||||||
bool ReceiveMsgFrom(CNode& node, CSerializedNetMsg&& ser_msg) const;
|
bool ReceiveMsgFrom(CNode& node, CSerializedNetMsg&& ser_msg) const;
|
||||||
void FlushSendBuffer(CNode& node) const;
|
void FlushSendBuffer(CNode& node) const;
|
||||||
|
|
||||||
|
bool AlreadyConnectedPublic(const CAddress& addr) { return AlreadyConnectedToAddress(addr); };
|
||||||
|
|
||||||
|
CNode* ConnectNodePublic(PeerManager& peerman, const char* pszDest, ConnectionType conn_type)
|
||||||
|
EXCLUSIVE_LOCKS_REQUIRED(!m_unused_i2p_sessions_mutex);
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr ServiceFlags ALL_SERVICE_FLAGS[]{
|
constexpr ServiceFlags ALL_SERVICE_FLAGS[]{
|
||||||
|
|||||||
Reference in New Issue
Block a user