5#include <chainparams.h>
30#include <boost/test/unit_test.hpp>
52 if (address.has_value()) {
54 }
else if (onion_peer) {
59 while (!addr.IsLocal() && !addr.IsRoutable()) {
63 BOOST_REQUIRE(addr.IsValid());
67 nodes.emplace_back(
new CNode{++id,
80 node.fSuccessfullyConnected =
true;
91 std::vector<CNode*> nodes;
97 BOOST_REQUIRE(nodes.back() !=
nullptr);
103 for (
int i = 0; i < 10; ++i) {
104 ASSERT_DEBUG_LOG(
"Not opening a connection to localhost, already connected to 127.0.0.1:8333");
115 "[fc00:3344:5566:7788:9900:aabb:ccdd:eeff]:1234");
119 BOOST_TEST_MESSAGE(
"Call AddNode() for all the peers");
120 for (
auto node : connman->TestNodes()) {
121 BOOST_CHECK(connman->AddNode({node->addr.ToStringAddrPort(), true}));
122 BOOST_TEST_MESSAGE(
strprintf(
"peer id=%s addr=%s",
node->GetId(),
node->addr.ToStringAddrPort()));
125 BOOST_TEST_MESSAGE(
"\nCall AddNode() with 2 addrs resolving to existing localhost addnode entry; neither should be added");
126 BOOST_CHECK(!connman->AddNode({
"127.0.0.1", true}));
128#if !defined(__OpenBSD__)
132 BOOST_TEST_MESSAGE(
"\nExpect GetAddedNodeInfo to return expected number of peers with `include_connected` true/false");
134 BOOST_CHECK(connman->GetAddedNodeInfo(
false).empty());
137 for (
auto node : connman->TestNodes()) {
141 BOOST_CHECK(!connman->AddedNodesContain(nodes.back()->addr));
143 BOOST_TEST_MESSAGE(
"\nPrint GetAddedNodeInfo contents:");
144 for (
const auto& info : connman->GetAddedNodeInfo(
true)) {
145 BOOST_TEST_MESSAGE(
strprintf(
"\nadded node: %s", info.m_params.m_added_node));
146 BOOST_TEST_MESSAGE(
strprintf(
"connected: %s", info.fConnected));
147 if (info.fConnected) {
148 BOOST_TEST_MESSAGE(
strprintf(
"IP address: %s", info.resolvedAddress.ToStringAddrPort()));
149 BOOST_TEST_MESSAGE(
strprintf(
"direction: %s", info.fInbound ?
"inbound" :
"outbound"));
153 BOOST_TEST_MESSAGE(
"\nCheck that all connected peers are correctly detected as connected");
154 for (
auto node : connman->TestNodes()) {
159 for (
auto node : connman->TestNodes()) {
160 peerman->FinalizeNode(*
node);
162 connman->ClearTestNodes();
const CChainParams & Params()
Return the currently selected parameters.
A CService with information about it as peer.
uint16_t GetDefaultPort() const
Information about a peer.
A combination of a network address (CNetAddr) and a (TCP) port.
virtual void InitializeNode(const CNode &node, ServiceFlags our_services)=0
Initialize a peer (setup state)
static std::unique_ptr< PeerManager > make(CConnman &connman, AddrMan &addrman, BanMan *banman, ChainstateManager &chainman, CTxMemPool &pool, node::Warnings &warnings, Options opts)
std::vector< B > randbytes(size_t len) noexcept
Generate random bytes.
uint64_t randbits(int bits) noexcept
Generate a random (bits)-bit integer.
ConnectionType
Different types of connections to a peer.
@ BLOCK_RELAY
We use block-relay-only connections to help prevent against partition attacks.
@ MANUAL
We open manual connections to addresses that users explicitly requested via the addnode RPC or the -a...
@ OUTBOUND_FULL_RELAY
These are the default connections that we use to connect with the network.
@ INBOUND
Inbound connections are those initiated by a peer.
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
BOOST_FIXTURE_TEST_CASE(test_addnode_getaddednodeinfo_and_connection_detection, PeerTest)
static CService ip(uint32_t i)
std::string OnionToString(Span< const uint8_t > addr)
static constexpr size_t ADDR_TORV3_SIZE
Size of TORv3 address (in bytes).
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.
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
ServiceFlags
nServices flags
static const int PROTOCOL_VERSION
network protocol versioning
void AddTestNode(CNode &node)
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.
Testing setup that configures a complete environment.
std::unique_ptr< CTxMemPool > mempool
std::unique_ptr< AddrMan > addrman
std::unique_ptr< ChainstateManager > chainman
std::unique_ptr< node::Warnings > warnings
Manages all the node warnings.
std::unique_ptr< const NetGroupManager > netgroupman
#define ASSERT_DEBUG_LOG(message)