Skip to content

Commit 4b834f6

Browse files
jonatacksr-gi
authored andcommitted
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.
1 parent 34b9ef4 commit 4b834f6

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

src/test/util/net.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44

55
#include <test/util/net.h>
66

7-
#include <chainparams.h>
8-
#include <node/eviction.h>
97
#include <net.h>
108
#include <net_processing.h>
9+
#include <netaddress.h>
1110
#include <netmessagemaker.h>
11+
#include <node/connection_types.h>
12+
#include <node/eviction.h>
13+
#include <protocol.h>
14+
#include <random.h>
15+
#include <serialize.h>
1216
#include <span.h>
1317

1418
#include <vector>
@@ -98,6 +102,17 @@ bool ConnmanTestMsg::ReceiveMsgFrom(CNode& node, CSerializedNetMsg&& ser_msg) co
98102
return complete;
99103
}
100104

105+
CNode* ConnmanTestMsg::ConnectNodePublic(PeerManager& peerman, const char* pszDest, ConnectionType conn_type)
106+
{
107+
CNode* node = ConnectNode(CAddress{}, pszDest, /*fCountFailure=*/false, conn_type, /*use_v2transport=*/true);
108+
if (!node) return nullptr;
109+
node->SetCommonVersion(PROTOCOL_VERSION);
110+
peerman.InitializeNode(*node, ServiceFlags(NODE_NETWORK | NODE_WITNESS));
111+
node->fSuccessfullyConnected = true;
112+
AddTestNode(*node);
113+
return node;
114+
}
115+
101116
std::vector<NodeEvictionCandidate> GetRandomNodeEvictionCandidates(int n_candidates, FastRandomContext& random_context)
102117
{
103118
std::vector<NodeEvictionCandidate> candidates;

src/test/util/net.h

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,30 @@
66
#define BITCOIN_TEST_UTIL_NET_H
77

88
#include <compat/compat.h>
9-
#include <node/eviction.h>
10-
#include <netaddress.h>
119
#include <net.h>
10+
#include <net_permissions.h>
11+
#include <net_processing.h>
12+
#include <netaddress.h>
13+
#include <node/connection_types.h>
14+
#include <node/eviction.h>
15+
#include <sync.h>
1216
#include <util/sock.h>
1317

18+
#include <algorithm>
1419
#include <array>
1520
#include <cassert>
21+
#include <chrono>
22+
#include <cstdint>
1623
#include <cstring>
1724
#include <memory>
1825
#include <string>
26+
#include <unordered_map>
27+
#include <vector>
28+
29+
class FastRandomContext;
30+
31+
template <typename C>
32+
class Span;
1933

2034
struct ConnmanTestMsg : public CConnman {
2135
using CConnman::CConnman;
@@ -25,6 +39,12 @@ struct ConnmanTestMsg : public CConnman {
2539
m_peer_connect_timeout = timeout;
2640
}
2741

42+
std::vector<CNode*> TestNodes()
43+
{
44+
LOCK(m_nodes_mutex);
45+
return m_nodes;
46+
}
47+
2848
void AddTestNode(CNode& node)
2949
{
3050
LOCK(m_nodes_mutex);
@@ -56,6 +76,11 @@ struct ConnmanTestMsg : public CConnman {
5676

5777
bool ReceiveMsgFrom(CNode& node, CSerializedNetMsg&& ser_msg) const;
5878
void FlushSendBuffer(CNode& node) const;
79+
80+
bool AlreadyConnectedPublic(const CAddress& addr) { return AlreadyConnectedToAddress(addr); };
81+
82+
CNode* ConnectNodePublic(PeerManager& peerman, const char* pszDest, ConnectionType conn_type)
83+
EXCLUSIVE_LOCKS_REQUIRED(!m_unused_i2p_sessions_mutex);
5984
};
6085

6186
constexpr ServiceFlags ALL_SERVICE_FLAGS[]{

0 commit comments

Comments
 (0)