5 #include <chainparams.h> 30 #include <boost/test/unit_test.hpp> 51 if (address.has_value()) {
53 }
else if (onion_peer) {
58 while (!addr.IsLocal() && !addr.IsRoutable()) {
62 BOOST_REQUIRE(addr.IsValid());
66 nodes.emplace_back(
new CNode{++id,
79 node.fSuccessfullyConnected =
true;
89 std::vector<CNode*> nodes;
95 BOOST_REQUIRE(nodes.back() !=
nullptr);
101 for (
int i = 0; i < 10; ++i) {
102 ASSERT_DEBUG_LOG(
"Not opening a connection to localhost, already connected to 127.0.0.1:8333");
113 "[fc00:3344:5566:7788:9900:aabb:ccdd:eeff]:1234");
117 BOOST_TEST_MESSAGE(
"Call AddNode() for all the peers");
118 for (
auto node : connman->TestNodes()) {
119 BOOST_CHECK(connman->AddNode({node->addr.ToStringAddrPort(), true}));
120 BOOST_TEST_MESSAGE(
strprintf(
"peer id=%s addr=%s",
node->GetId(),
node->addr.ToStringAddrPort()));
123 BOOST_TEST_MESSAGE(
"\nCall AddNode() with 2 addrs resolving to existing localhost addnode entry; neither should be added");
124 BOOST_CHECK(!connman->AddNode({
"127.0.0.1", true}));
126 #if !defined(__OpenBSD__) 130 BOOST_TEST_MESSAGE(
"\nExpect GetAddedNodeInfo to return expected number of peers with `include_connected` true/false");
132 BOOST_CHECK(connman->GetAddedNodeInfo(
false).empty());
135 for (
auto node : connman->TestNodes()) {
139 BOOST_CHECK(!connman->AddedNodesContain(nodes.back()->addr));
141 BOOST_TEST_MESSAGE(
"\nPrint GetAddedNodeInfo contents:");
142 for (
const auto& info : connman->GetAddedNodeInfo(
true)) {
143 BOOST_TEST_MESSAGE(
strprintf(
"\nadded node: %s", info.m_params.m_added_node));
144 BOOST_TEST_MESSAGE(
strprintf(
"connected: %s", info.fConnected));
145 if (info.fConnected) {
146 BOOST_TEST_MESSAGE(
strprintf(
"IP address: %s", info.resolvedAddress.ToStringAddrPort()));
147 BOOST_TEST_MESSAGE(
strprintf(
"direction: %s", info.fInbound ?
"inbound" :
"outbound"));
151 BOOST_TEST_MESSAGE(
"\nCheck that all connected peers are correctly detected as connected");
152 for (
auto node : connman->TestNodes()) {
157 for (
auto node : connman->TestNodes()) {
158 peerman->FinalizeNode(*
node);
160 connman->ClearTestNodes();
std::vector< B > randbytes(size_t len) noexcept
Generate random bytes.
BOOST_AUTO_TEST_CASE(test_addnode_getaddednodeinfo_and_connection_detection)
std::unique_ptr< node::Warnings > warnings
Manages all the node warnings.
ServiceFlags
nServices flags
Inbound connections are those initiated by a peer.
static constexpr size_t ADDR_TORV3_SIZE
Size of TORv3 address (in bytes).
static std::unique_ptr< PeerManager > make(CConnman &connman, AddrMan &addrman, BanMan *banman, ChainstateManager &chainman, CTxMemPool &pool, node::Warnings &warnings, Options opts)
std::unique_ptr< const NetGroupManager > netgroupman
std::unique_ptr< AddrMan > addrman
CService MaybeFlipIPv6toCJDNS(const CService &service)
If an IPv6 address belongs to the address range used by the CJDNS network and the CJDNS network is re...
CService LookupNumeric(const std::string &name, uint16_t portDefault, DNSLookupFn dns_lookup_function)
Resolve a service string with a numeric IP to its first corresponding service.
static void AddPeer(NodeId &id, std::vector< CNode *> &nodes, PeerManager &peerman, ConnmanTestMsg &connman, ConnectionType conn_type, bool onion_peer=false, std::optional< std::string > address=std::nullopt)
Create a peer and connect to it.
These are the default connections that we use to connect with the network.
uint16_t GetDefaultPort() const
std::unique_ptr< CTxMemPool > mempool
We open manual connections to addresses that users explicitly requested via the addnode RPC or the -a...
A combination of a network address (CNetAddr) and a (TCP) port.
BOOST_AUTO_TEST_SUITE_END()
A CService with information about it as peer.
static const int PROTOCOL_VERSION
network protocol versioning
#define ASSERT_DEBUG_LOG(message)
static CService ip(uint32_t i)
#define BOOST_CHECK_EQUAL(v1, v2)
const CChainParams & Params()
Return the currently selected parameters.
uint64_t randbits(int bits) noexcept
Generate a random (bits)-bit integer.
FastRandomContext g_insecure_rand_ctx
This global and the helpers that use it are not thread-safe.
ConnectionType
Different types of connections to a peer.
std::string OnionToString(Span< const uint8_t > addr)
Information about a peer.
virtual void InitializeNode(const CNode &node, ServiceFlags our_services)=0
Initialize a peer (setup state)
void AddTestNode(CNode &node)
std::unique_ptr< ChainstateManager > chainman
Testing setup that configures a complete environment.
We use block-relay-only connections to help prevent against partition attacks.
#define BOOST_CHECK(expr)