Create a peer and connect to it. If the optional `address` (IP/CJDNS only) isn't passed, a random address is created. */
| 46 | struct PeerTest : LogIPsTestingSetup { |
| 47 | /** Create a peer and connect to it. If the optional `address` (IP/CJDNS only) isn't passed, a random address is created. */ |
| 48 | 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) |
| 49 | { |
| 50 | CAddress addr{}; |
| 51 | |
| 52 | if (address.has_value()) { |
| 53 | addr = CAddress{MaybeFlipIPv6toCJDNS(LookupNumeric(address.value(), Params().GetDefaultPort())), NODE_NONE}; |
| 54 | } else if (onion_peer) { |
| 55 | auto tor_addr{m_rng.randbytes(ADDR_TORV3_SIZE)}; |
| 56 | BOOST_REQUIRE(addr.SetSpecial(OnionToString(tor_addr))); |
| 57 | } |
| 58 | |
| 59 | while (!addr.IsLocal() && !addr.IsRoutable()) { |
| 60 | addr = CAddress{ip(m_rng.randbits(32)), NODE_NONE}; |
| 61 | } |
| 62 | |
| 63 | BOOST_REQUIRE(addr.IsValid()); |
| 64 | |
| 65 | const bool inbound_onion{onion_peer && conn_type == ConnectionType::INBOUND}; |
| 66 | |
| 67 | nodes.emplace_back(new CNode{++id, |
| 68 | /*sock=*/nullptr, |
| 69 | addr, |
| 70 | /*nKeyedNetGroupIn=*/0, |
| 71 | /*nLocalHostNonceIn=*/0, |
| 72 | CAddress{}, |
| 73 | /*addrNameIn=*/"", |
| 74 | conn_type, |
| 75 | /*inbound_onion=*/inbound_onion, |
| 76 | /*network_key=*/0}); |
| 77 | CNode& node = *nodes.back(); |
| 78 | node.SetCommonVersion(PROTOCOL_VERSION); |
| 79 | |
| 80 | peerman.InitializeNode(node, ServiceFlags(NODE_NETWORK | NODE_WITNESS)); |
| 81 | node.fSuccessfullyConnected = true; |
| 82 | |
| 83 | connman.AddTestNode(node); |
| 84 | } |
| 85 | }; // struct PeerTest |
| 86 | |
| 87 | BOOST_FIXTURE_TEST_CASE(test_addnode_getaddednodeinfo_and_connection_detection, PeerTest) |
nothing calls this directly
no test coverage detected