diff options
author | Vasil Dimov <vd@FreeBSD.org> | 2021-01-20 11:54:17 +0100 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2021-04-02 18:33:45 +0200 |
commit | 81747b21719b3fa6b0fdfc3b084c0104d64903f9 (patch) | |
tree | 6c2bec5d768936348ef529b4acc2276d9232141b /src | |
parent | 637bb6da368b87711005b909f451f94909400092 (diff) |
test: make sure non-IP peers get discouraged and disconnected
Diffstat (limited to 'src')
-rw-r--r-- | src/test/denialofservice_tests.cpp | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/src/test/denialofservice_tests.cpp b/src/test/denialofservice_tests.cpp index f556585b42..e7cb12dbba 100644 --- a/src/test/denialofservice_tests.cpp +++ b/src/test/denialofservice_tests.cpp @@ -214,12 +214,18 @@ BOOST_AUTO_TEST_CASE(peer_discouragement) auto peerLogic = PeerManager::make(chainparams, *connman, *m_node.addrman, banman.get(), *m_node.scheduler, *m_node.chainman, *m_node.mempool, false); - const std::array<CAddress, 2> addr{CAddress{ip(0xa0b0c001), NODE_NONE}, - CAddress{ip(0xa0b0c002), NODE_NONE}}; + CNetAddr tor_netaddr; + BOOST_REQUIRE( + tor_netaddr.SetSpecial("pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion")); + const CService tor_service{tor_netaddr, Params().GetDefaultPort()}; + + const std::array<CAddress, 3> addr{CAddress{ip(0xa0b0c001), NODE_NONE}, + CAddress{ip(0xa0b0c002), NODE_NONE}, + CAddress{tor_service, NODE_NONE}}; const CNetAddr other_addr{ip(0xa0b0ff01)}; // Not any of addr[]. - std::array<CNode*, 2> nodes; + std::array<CNode*, 3> nodes; banman->ClearBanned(); nodes[0] = new CNode{id++, NODE_NETWORK, INVALID_SOCKET, addr[0], /* nKeyedNetGroupIn */ 0, @@ -267,6 +273,27 @@ BOOST_AUTO_TEST_CASE(peer_discouragement) BOOST_CHECK(banman->IsDiscouraged(addr[1])); BOOST_CHECK(nodes[1]->fDisconnect); + // Make sure non-IP peers are discouraged and disconnected properly. + + nodes[2] = new CNode{id++, NODE_NETWORK, INVALID_SOCKET, addr[2], /* nKeyedNetGroupIn */ 1, + /* nLocalHostNonceIn */ 1, CAddress(), /* pszDest */ "", + ConnectionType::OUTBOUND_FULL_RELAY, /* inbound_onion */ false}; + nodes[2]->SetCommonVersion(PROTOCOL_VERSION); + peerLogic->InitializeNode(nodes[2]); + nodes[2]->fSuccessfullyConnected = true; + connman->AddNode(*nodes[2]); + peerLogic->Misbehaving(nodes[2]->GetId(), DISCOURAGEMENT_THRESHOLD, /* message */ ""); + { + LOCK(nodes[2]->cs_sendProcessing); + BOOST_CHECK(peerLogic->SendMessages(nodes[2])); + } + BOOST_CHECK(banman->IsDiscouraged(addr[0])); + BOOST_CHECK(banman->IsDiscouraged(addr[1])); + BOOST_CHECK(banman->IsDiscouraged(addr[2])); + BOOST_CHECK(nodes[0]->fDisconnect); + BOOST_CHECK(nodes[1]->fDisconnect); + BOOST_CHECK(nodes[2]->fDisconnect); + for (CNode* node : nodes) { peerLogic->FinalizeNode(*node); } |