mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-08-04 05:54:48 +02:00
Merge fix_cjdns_addnode_detect2-27+knots
This commit is contained in:
commit
ea949daca1
11
src/net.cpp
11
src/net.cpp
@ -3451,12 +3451,17 @@ std::vector<CAddress> CConnman::GetAddresses(CNode& requestor, size_t max_addres
|
|||||||
|
|
||||||
bool CConnman::AddNode(const AddedNodeParams& add)
|
bool CConnman::AddNode(const AddedNodeParams& add)
|
||||||
{
|
{
|
||||||
const CService resolved(LookupNumeric(add.m_added_node, GetDefaultPort(add.m_added_node)));
|
const CService resolved{MaybeFlipIPv6toCJDNS(LookupNumeric(add.m_added_node, GetDefaultPort(add.m_added_node)))};
|
||||||
const bool resolved_is_valid{resolved.IsValid()};
|
const bool resolved_invalid{!resolved.IsValid()};
|
||||||
|
|
||||||
LOCK(m_added_nodes_mutex);
|
LOCK(m_added_nodes_mutex);
|
||||||
for (const auto& it : m_added_node_params) {
|
for (const auto& it : m_added_node_params) {
|
||||||
if (add.m_added_node == it.m_added_node || (resolved_is_valid && resolved == LookupNumeric(it.m_added_node, GetDefaultPort(it.m_added_node)))) return false;
|
if (add.m_added_node == it.m_added_node) return false;
|
||||||
|
if (resolved_invalid) continue;
|
||||||
|
const CService service{MaybeFlipIPv6toCJDNS(LookupNumeric(it.m_added_node, GetDefaultPort(it.m_added_node)))};
|
||||||
|
if (resolved == service) return false;
|
||||||
|
// Check if CJDNS address matches regardless of port to detect already-connected inbound peers.
|
||||||
|
if (resolved.IsCJDNS() && static_cast<CNetAddr>(resolved) == static_cast<CNetAddr>(service)) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_added_node_params.push_back(add);
|
m_added_node_params.push_back(add);
|
||||||
|
@ -127,6 +127,15 @@ BOOST_AUTO_TEST_CASE(test_addnode_getaddednodeinfo_and_connection_detection)
|
|||||||
BOOST_CHECK(!connman->AddNode({/*m_added_node=*/"127.1", /*m_use_v2transport=*/true}));
|
BOOST_CHECK(!connman->AddNode({/*m_added_node=*/"127.1", /*m_use_v2transport=*/true}));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
BOOST_TEST_MESSAGE("\nCall AddNode() with a CJDNS service equal to an existing addnode entry; it should not be added");
|
||||||
|
BOOST_CHECK(!connman->AddNode({/*m_added_node=*/"[fc00:3344:5566:7788:9900:aabb:ccdd:eeff]:1234", /*m_use_v2transport=*/false}));
|
||||||
|
|
||||||
|
BOOST_TEST_MESSAGE("\nCall AddNode() with a CJDNS addr equal to an existing inbound one but with a different port specified; it should not be added");
|
||||||
|
BOOST_CHECK(!connman->AddNode({/*m_added_node=*/"[fc00:3344:5566:7788:9900:aabb:ccdd:eeff]:8333", /*m_use_v2transport=*/false}));
|
||||||
|
|
||||||
|
BOOST_TEST_MESSAGE("\nCall AddNode() with a CJDNS addr equal to an existing inbound one but resolving to a different port; it should not be added");
|
||||||
|
BOOST_CHECK(!connman->AddNode({/*m_added_node=*/"fc00:3344:5566:7788:9900:aabb:ccdd:eeff", /*m_use_v2transport=*/false}));
|
||||||
|
|
||||||
BOOST_TEST_MESSAGE("\nExpect GetAddedNodeInfo to return expected number of peers with `include_connected` true/false");
|
BOOST_TEST_MESSAGE("\nExpect GetAddedNodeInfo to return expected number of peers with `include_connected` true/false");
|
||||||
BOOST_CHECK_EQUAL(connman->GetAddedNodeInfo(/*include_connected=*/true).size(), nodes.size());
|
BOOST_CHECK_EQUAL(connman->GetAddedNodeInfo(/*include_connected=*/true).size(), nodes.size());
|
||||||
BOOST_CHECK(connman->GetAddedNodeInfo(/*include_connected=*/false).empty());
|
BOOST_CHECK(connman->GetAddedNodeInfo(/*include_connected=*/false).empty());
|
||||||
|
Loading…
Reference in New Issue
Block a user