v29.4-roots.3 · Commit 3: [PATCH 03/30] policy: restore conservative relay and network controls
src/test/net_tests.cpp
Before: src/test/net_tests.cpp · After: src/test/net_tests.cpp
File metadata
index 62e541b5b392f3bc9739c1134cdf2fac39680504..69e9e887e66d19a625abc830f0395f258b78caff 100644
Download original patch · Release notes
Diff rows 1–133 of 133. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. Before is on the left; after is on the right. Unified view fits narrow screens more easily.
src/test/net_tests.cpp
CHANGED
|
@@ -67,7 +67,8 @@ BOOST_AUTO_TEST_CASE(cnode_simple_test)
|
|
| 67 |
CAddress(),
|
| 68 |
pszDest,
|
| 69 |
ConnectionType::OUTBOUND_FULL_RELAY,
|
| 70 |
-
/*inbound_onion=*/false);
|
|
|
|
| 71 |
BOOST_CHECK(pnode1->IsFullOutboundConn() == true);
|
| 72 |
BOOST_CHECK(pnode1->IsManualConn() == false);
|
| 73 |
BOOST_CHECK(pnode1->IsBlockOnlyConn() == false);
|
|
@@ -85,7 +86,8 @@ BOOST_AUTO_TEST_CASE(cnode_simple_test)
|
|
| 85 |
CAddress(),
|
| 86 |
pszDest,
|
| 87 |
ConnectionType::INBOUND,
|
| 88 |
-
/*inbound_onion=*/false);
|
|
|
|
| 89 |
BOOST_CHECK(pnode2->IsFullOutboundConn() == false);
|
| 90 |
BOOST_CHECK(pnode2->IsManualConn() == false);
|
| 91 |
BOOST_CHECK(pnode2->IsBlockOnlyConn() == false);
|
|
@@ -103,7 +105,8 @@ BOOST_AUTO_TEST_CASE(cnode_simple_test)
|
|
| 103 |
CAddress(),
|
| 104 |
pszDest,
|
| 105 |
ConnectionType::OUTBOUND_FULL_RELAY,
|
| 106 |
-
/*inbound_onion=*/false);
|
|
|
|
| 107 |
BOOST_CHECK(pnode3->IsFullOutboundConn() == true);
|
| 108 |
BOOST_CHECK(pnode3->IsManualConn() == false);
|
| 109 |
BOOST_CHECK(pnode3->IsBlockOnlyConn() == false);
|
|
@@ -121,7 +124,8 @@ BOOST_AUTO_TEST_CASE(cnode_simple_test)
|
|
| 121 |
CAddress(),
|
| 122 |
pszDest,
|
| 123 |
ConnectionType::INBOUND,
|
| 124 |
-
/*inbound_onion=*/true);
|
|
|
|
| 125 |
BOOST_CHECK(pnode4->IsFullOutboundConn() == false);
|
| 126 |
BOOST_CHECK(pnode4->IsManualConn() == false);
|
| 127 |
BOOST_CHECK(pnode4->IsBlockOnlyConn() == false);
|
|
@@ -613,7 +617,8 @@ BOOST_AUTO_TEST_CASE(ipv4_peer_with_ipv6_addrMe_test)
|
|
| 613 |
CAddress{},
|
| 614 |
/*pszDest=*/std::string{},
|
| 615 |
ConnectionType::OUTBOUND_FULL_RELAY,
|
| 616 |
-
/*inbound_onion=*/false);
|
|
|
|
| 617 |
pnode->fSuccessfullyConnected.store(true);
|
| 618 |
|
| 619 |
// the peer claims to be reaching us via IPv6
|
|
@@ -667,7 +672,8 @@ BOOST_AUTO_TEST_CASE(get_local_addr_for_peer_port)
|
|
| 667 |
/*addrBindIn=*/CService{},
|
| 668 |
/*addrNameIn=*/std::string{},
|
| 669 |
/*conn_type_in=*/ConnectionType::OUTBOUND_FULL_RELAY,
|
| 670 |
-
/*inbound_onion=*/false};
|
|
|
|
| 671 |
peer_out.fSuccessfullyConnected = true;
|
| 672 |
peer_out.SetAddrLocal(peer_us);
|
| 673 |
|
|
@@ -688,7 +694,8 @@ BOOST_AUTO_TEST_CASE(get_local_addr_for_peer_port)
|
|
| 688 |
/*addrBindIn=*/CService{},
|
| 689 |
/*addrNameIn=*/std::string{},
|
| 690 |
/*conn_type_in=*/ConnectionType::INBOUND,
|
| 691 |
-
/*inbound_onion=*/false};
|
|
|
|
| 692 |
peer_in.fSuccessfullyConnected = true;
|
| 693 |
peer_in.SetAddrLocal(peer_us);
|
| 694 |
|
|
@@ -792,6 +799,36 @@ BOOST_AUTO_TEST_CASE(LocalAddress_BasicLifecycle)
|
|
| 792 |
BOOST_CHECK(!IsLocal(addr));
|
| 793 |
}
|
| 794 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 795 |
BOOST_AUTO_TEST_CASE(initial_advertise_from_version_message)
|
| 796 |
{
|
| 797 |
LOCK(NetEventsInterface::g_msgproc_mutex);
|
|
@@ -807,7 +844,7 @@ BOOST_AUTO_TEST_CASE(initial_advertise_from_version_message)
|
|
| 807 |
// Pretend that we bound to this port.
|
| 808 |
const uint16_t bind_port = 20001;
|
| 809 |
m_node.args->ForceSetArg("-bind", strprintf("3.4.5.6:%u", bind_port));
|
| 810 |
-
m_node.args->ForceSetArg("-capturemessages", "1");
|
| 811 |
|
| 812 |
// Our address:port as seen from the peer - 2.3.4.5:20002 (different from the above).
|
| 813 |
in_addr peer_us_addr;
|
|
@@ -825,7 +862,8 @@ BOOST_AUTO_TEST_CASE(initial_advertise_from_version_message)
|
|
| 825 |
/*addrBindIn=*/CService{},
|
| 826 |
/*addrNameIn=*/std::string{},
|
| 827 |
/*conn_type_in=*/ConnectionType::OUTBOUND_FULL_RELAY,
|
| 828 |
-
/*inbound_onion=*/false};
|
|
|
|
| 829 |
|
| 830 |
const uint64_t services{NODE_NETWORK | NODE_WITNESS};
|
| 831 |
const int64_t time{0};
|
|
@@ -884,7 +922,7 @@ BOOST_AUTO_TEST_CASE(initial_advertise_from_version_message)
|
|
| 884 |
|
| 885 |
CaptureMessage = CaptureMessageOrig;
|
| 886 |
chainman.ResetIbd();
|
| 887 |
-
m_node.args->ForceSetArg("-capturemessages", "0");
|
| 888 |
m_node.args->ForceSetArg("-bind", "");
|
| 889 |
}
|
| 890 |
|
|
@@ -900,7 +938,8 @@ BOOST_AUTO_TEST_CASE(advertise_local_address)
|
|
| 900 |
CAddress{},
|
| 901 |
/*pszDest=*/std::string{},
|
| 902 |
ConnectionType::OUTBOUND_FULL_RELAY,
|
| 903 |
-
/*inbound_onion=*/false);
|
|
|
|
| 904 |
};
|
| 905 |
g_reachable_nets.Add(NET_CJDNS);
|
| 906 |
|
|
|
|
| 67 |
CAddress(),
|
| 68 |
pszDest,
|
| 69 |
ConnectionType::OUTBOUND_FULL_RELAY,
|
| 70 |
+
/*inbound_onion=*/false,
|
| 71 |
+
/*network_key=*/0);
|
| 72 |
BOOST_CHECK(pnode1->IsFullOutboundConn() == true);
|
| 73 |
BOOST_CHECK(pnode1->IsManualConn() == false);
|
| 74 |
BOOST_CHECK(pnode1->IsBlockOnlyConn() == false);
|
|
|
|
| 86 |
CAddress(),
|
| 87 |
pszDest,
|
| 88 |
ConnectionType::INBOUND,
|
| 89 |
+
/*inbound_onion=*/false,
|
| 90 |
+
/*network_key=*/1);
|
| 91 |
BOOST_CHECK(pnode2->IsFullOutboundConn() == false);
|
| 92 |
BOOST_CHECK(pnode2->IsManualConn() == false);
|
| 93 |
BOOST_CHECK(pnode2->IsBlockOnlyConn() == false);
|
|
|
|
| 105 |
CAddress(),
|
| 106 |
pszDest,
|
| 107 |
ConnectionType::OUTBOUND_FULL_RELAY,
|
| 108 |
+
/*inbound_onion=*/false,
|
| 109 |
+
/*network_key=*/2);
|
| 110 |
BOOST_CHECK(pnode3->IsFullOutboundConn() == true);
|
| 111 |
BOOST_CHECK(pnode3->IsManualConn() == false);
|
| 112 |
BOOST_CHECK(pnode3->IsBlockOnlyConn() == false);
|
|
|
|
| 124 |
CAddress(),
|
| 125 |
pszDest,
|
| 126 |
ConnectionType::INBOUND,
|
| 127 |
+
/*inbound_onion=*/true,
|
| 128 |
+
/*network_key=*/3);
|
| 129 |
BOOST_CHECK(pnode4->IsFullOutboundConn() == false);
|
| 130 |
BOOST_CHECK(pnode4->IsManualConn() == false);
|
| 131 |
BOOST_CHECK(pnode4->IsBlockOnlyConn() == false);
|
|
|
|
| 617 |
CAddress{},
|
| 618 |
/*pszDest=*/std::string{},
|
| 619 |
ConnectionType::OUTBOUND_FULL_RELAY,
|
| 620 |
+
/*inbound_onion=*/false,
|
| 621 |
+
/*network_key=*/0);
|
| 622 |
pnode->fSuccessfullyConnected.store(true);
|
| 623 |
|
| 624 |
// the peer claims to be reaching us via IPv6
|
|
|
|
| 672 |
/*addrBindIn=*/CService{},
|
| 673 |
/*addrNameIn=*/std::string{},
|
| 674 |
/*conn_type_in=*/ConnectionType::OUTBOUND_FULL_RELAY,
|
| 675 |
+
/*inbound_onion=*/false,
|
| 676 |
+
/*network_key=*/0};
|
| 677 |
peer_out.fSuccessfullyConnected = true;
|
| 678 |
peer_out.SetAddrLocal(peer_us);
|
| 679 |
|
|
|
|
| 694 |
/*addrBindIn=*/CService{},
|
| 695 |
/*addrNameIn=*/std::string{},
|
| 696 |
/*conn_type_in=*/ConnectionType::INBOUND,
|
| 697 |
+
/*inbound_onion=*/false,
|
| 698 |
+
/*network_key=*/1};
|
| 699 |
peer_in.fSuccessfullyConnected = true;
|
| 700 |
peer_in.SetAddrLocal(peer_us);
|
| 701 |
|
|
|
|
| 799 |
BOOST_CHECK(!IsLocal(addr));
|
| 800 |
}
|
| 801 |
|
| 802 |
+
BOOST_AUTO_TEST_CASE(LocalAddress_nScore_Overflow)
|
| 803 |
+
{
|
| 804 |
+
g_reachable_nets.Add(NET_IPV4);
|
| 805 |
+
CService addr{UtilBuildAddress(0x002, 0x001, 0x001, 0x001), 1000}; // 2.1.1.1:1000
|
| 806 |
+
|
| 807 |
+
// SeenLocal increments when nScore is below max
|
| 808 |
+
const int initial_score = 1000;
|
| 809 |
+
BOOST_REQUIRE(AddLocal(addr, initial_score));
|
| 810 |
+
BOOST_REQUIRE(IsLocal(addr));
|
| 811 |
+
BOOST_CHECK_EQUAL(GetnScore(addr), initial_score);
|
| 812 |
+
|
| 813 |
+
// SeenLocal increments the score
|
| 814 |
+
BOOST_CHECK(SeenLocal(addr));
|
| 815 |
+
BOOST_CHECK_EQUAL(GetnScore(addr), initial_score + 1);
|
| 816 |
+
|
| 817 |
+
// SeenLocal saturates at max
|
| 818 |
+
RemoveLocal(addr);
|
| 819 |
+
BOOST_REQUIRE(AddLocal(addr, std::numeric_limits<int>::max()));
|
| 820 |
+
BOOST_CHECK_EQUAL(GetnScore(addr), std::numeric_limits<int>::max());
|
| 821 |
+
|
| 822 |
+
// a couple increments should saturate
|
| 823 |
+
for (int i = 0; i < 2; ++i) {
|
| 824 |
+
BOOST_CHECK(SeenLocal(addr));
|
| 825 |
+
BOOST_CHECK_EQUAL(GetnScore(addr), std::numeric_limits<int>::max());
|
| 826 |
+
}
|
| 827 |
+
|
| 828 |
+
RemoveLocal(addr);
|
| 829 |
+
BOOST_CHECK(!IsLocal(addr));
|
| 830 |
+
}
|
| 831 |
+
|
| 832 |
BOOST_AUTO_TEST_CASE(initial_advertise_from_version_message)
|
| 833 |
{
|
| 834 |
LOCK(NetEventsInterface::g_msgproc_mutex);
|
|
|
|
| 844 |
// Pretend that we bound to this port.
|
| 845 |
const uint16_t bind_port = 20001;
|
| 846 |
m_node.args->ForceSetArg("-bind", strprintf("3.4.5.6:%u", bind_port));
|
| 847 |
+
m_node.connman->SetCaptureMessages(true);
|
| 848 |
|
| 849 |
// Our address:port as seen from the peer - 2.3.4.5:20002 (different from the above).
|
| 850 |
in_addr peer_us_addr;
|
|
|
|
| 862 |
/*addrBindIn=*/CService{},
|
| 863 |
/*addrNameIn=*/std::string{},
|
| 864 |
/*conn_type_in=*/ConnectionType::OUTBOUND_FULL_RELAY,
|
| 865 |
+
/*inbound_onion=*/false,
|
| 866 |
+
/*network_key=*/2};
|
| 867 |
|
| 868 |
const uint64_t services{NODE_NETWORK | NODE_WITNESS};
|
| 869 |
const int64_t time{0};
|
|
|
|
| 922 |
|
| 923 |
CaptureMessage = CaptureMessageOrig;
|
| 924 |
chainman.ResetIbd();
|
| 925 |
+
m_node.connman->SetCaptureMessages(false);
|
| 926 |
m_node.args->ForceSetArg("-bind", "");
|
| 927 |
}
|
| 928 |
|
|
|
|
| 938 |
CAddress{},
|
| 939 |
/*pszDest=*/std::string{},
|
| 940 |
ConnectionType::OUTBOUND_FULL_RELAY,
|
| 941 |
+
/*inbound_onion=*/false,
|
| 942 |
+
/*network_key=*/0);
|
| 943 |
};
|
| 944 |
g_reachable_nets.Add(NET_CJDNS);
|
| 945 |
|