v29.4-roots.4 · Commit 3: [PATCH 03/37] 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. The two line-number columns refer to before and after.
src/test/net_tests.cpp
CHANGED
|
@@ -67,7 +67,8 @@ BOOST_AUTO_TEST_CASE(cnode_simple_test)
|
|
|
67
67
|
CAddress(),
|
|
68
68
|
pszDest,
|
|
69
69
|
ConnectionType::OUTBOUND_FULL_RELAY,
|
|
70
|
-
/*inbound_onion=*/false);
|
|
70
|
+
/*inbound_onion=*/false,
|
|
71
|
+
/*network_key=*/0);
|
|
71
72
|
BOOST_CHECK(pnode1->IsFullOutboundConn() == true);
|
|
72
73
|
BOOST_CHECK(pnode1->IsManualConn() == false);
|
|
73
74
|
BOOST_CHECK(pnode1->IsBlockOnlyConn() == false);
|
|
@@ -85,7 +86,8 @@ BOOST_AUTO_TEST_CASE(cnode_simple_test)
|
|
|
85
86
|
CAddress(),
|
|
86
87
|
pszDest,
|
|
87
88
|
ConnectionType::INBOUND,
|
|
88
|
-
/*inbound_onion=*/false);
|
|
89
|
+
/*inbound_onion=*/false,
|
|
90
|
+
/*network_key=*/1);
|
|
89
91
|
BOOST_CHECK(pnode2->IsFullOutboundConn() == false);
|
|
90
92
|
BOOST_CHECK(pnode2->IsManualConn() == false);
|
|
91
93
|
BOOST_CHECK(pnode2->IsBlockOnlyConn() == false);
|
|
@@ -103,7 +105,8 @@ BOOST_AUTO_TEST_CASE(cnode_simple_test)
|
|
|
103
105
|
CAddress(),
|
|
104
106
|
pszDest,
|
|
105
107
|
ConnectionType::OUTBOUND_FULL_RELAY,
|
|
106
|
-
/*inbound_onion=*/false);
|
|
108
|
+
/*inbound_onion=*/false,
|
|
109
|
+
/*network_key=*/2);
|
|
107
110
|
BOOST_CHECK(pnode3->IsFullOutboundConn() == true);
|
|
108
111
|
BOOST_CHECK(pnode3->IsManualConn() == false);
|
|
109
112
|
BOOST_CHECK(pnode3->IsBlockOnlyConn() == false);
|
|
@@ -121,7 +124,8 @@ BOOST_AUTO_TEST_CASE(cnode_simple_test)
|
|
|
121
124
|
CAddress(),
|
|
122
125
|
pszDest,
|
|
123
126
|
ConnectionType::INBOUND,
|
|
124
|
-
/*inbound_onion=*/true);
|
|
127
|
+
/*inbound_onion=*/true,
|
|
128
|
+
/*network_key=*/3);
|
|
125
129
|
BOOST_CHECK(pnode4->IsFullOutboundConn() == false);
|
|
126
130
|
BOOST_CHECK(pnode4->IsManualConn() == false);
|
|
127
131
|
BOOST_CHECK(pnode4->IsBlockOnlyConn() == false);
|
|
@@ -613,7 +617,8 @@ BOOST_AUTO_TEST_CASE(ipv4_peer_with_ipv6_addrMe_test)
|
|
|
613
617
|
CAddress{},
|
|
614
618
|
/*pszDest=*/std::string{},
|
|
615
619
|
ConnectionType::OUTBOUND_FULL_RELAY,
|
|
616
|
-
/*inbound_onion=*/false);
|
|
620
|
+
/*inbound_onion=*/false,
|
|
621
|
+
/*network_key=*/0);
|
|
617
622
|
pnode->fSuccessfullyConnected.store(true);
|
|
618
623
|
|
|
619
624
|
// the peer claims to be reaching us via IPv6
|
|
@@ -667,7 +672,8 @@ BOOST_AUTO_TEST_CASE(get_local_addr_for_peer_port)
|
|
|
667
672
|
/*addrBindIn=*/CService{},
|
|
668
673
|
/*addrNameIn=*/std::string{},
|
|
669
674
|
/*conn_type_in=*/ConnectionType::OUTBOUND_FULL_RELAY,
|
|
670
|
-
/*inbound_onion=*/false};
|
|
675
|
+
/*inbound_onion=*/false,
|
|
676
|
+
/*network_key=*/0};
|
|
671
677
|
peer_out.fSuccessfullyConnected = true;
|
|
672
678
|
peer_out.SetAddrLocal(peer_us);
|
|
673
679
|
|
|
@@ -688,7 +694,8 @@ BOOST_AUTO_TEST_CASE(get_local_addr_for_peer_port)
|
|
|
688
694
|
/*addrBindIn=*/CService{},
|
|
689
695
|
/*addrNameIn=*/std::string{},
|
|
690
696
|
/*conn_type_in=*/ConnectionType::INBOUND,
|
|
691
|
-
/*inbound_onion=*/false};
|
|
697
|
+
/*inbound_onion=*/false,
|
|
698
|
+
/*network_key=*/1};
|
|
692
699
|
peer_in.fSuccessfullyConnected = true;
|
|
693
700
|
peer_in.SetAddrLocal(peer_us);
|
|
694
701
|
|
|
@@ -792,6 +799,36 @@ BOOST_AUTO_TEST_CASE(LocalAddress_BasicLifecycle)
|
|
|
792
799
|
BOOST_CHECK(!IsLocal(addr));
|
|
793
800
|
}
|
|
794
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
|
+
|
|
795
832
|
BOOST_AUTO_TEST_CASE(initial_advertise_from_version_message)
|
|
796
833
|
{
|
|
797
834
|
LOCK(NetEventsInterface::g_msgproc_mutex);
|
|
@@ -807,7 +844,7 @@ BOOST_AUTO_TEST_CASE(initial_advertise_from_version_message)
|
|
|
807
844
|
// Pretend that we bound to this port.
|
|
808
845
|
const uint16_t bind_port = 20001;
|
|
809
846
|
m_node.args->ForceSetArg("-bind", strprintf("3.4.5.6:%u", bind_port));
|
|
810
|
-
m_node.args->ForceSetArg("-capturemessages", "1");
|
|
847
|
+
m_node.connman->SetCaptureMessages(true);
|
|
811
848
|
|
|
812
849
|
// Our address:port as seen from the peer - 2.3.4.5:20002 (different from the above).
|
|
813
850
|
in_addr peer_us_addr;
|
|
@@ -825,7 +862,8 @@ BOOST_AUTO_TEST_CASE(initial_advertise_from_version_message)
|
|
|
825
862
|
/*addrBindIn=*/CService{},
|
|
826
863
|
/*addrNameIn=*/std::string{},
|
|
827
864
|
/*conn_type_in=*/ConnectionType::OUTBOUND_FULL_RELAY,
|
|
828
|
-
/*inbound_onion=*/false};
|
|
865
|
+
/*inbound_onion=*/false,
|
|
866
|
+
/*network_key=*/2};
|
|
829
867
|
|
|
830
868
|
const uint64_t services{NODE_NETWORK | NODE_WITNESS};
|
|
831
869
|
const int64_t time{0};
|
|
@@ -884,7 +922,7 @@ BOOST_AUTO_TEST_CASE(initial_advertise_from_version_message)
|
|
|
884
922
|
|
|
885
923
|
CaptureMessage = CaptureMessageOrig;
|
|
886
924
|
chainman.ResetIbd();
|
|
887
|
-
m_node.args->ForceSetArg("-capturemessages", "0");
|
|
925
|
+
m_node.connman->SetCaptureMessages(false);
|
|
888
926
|
m_node.args->ForceSetArg("-bind", "");
|
|
889
927
|
}
|
|
890
928
|
|
|
@@ -900,7 +938,8 @@ BOOST_AUTO_TEST_CASE(advertise_local_address)
|
|
|
900
938
|
CAddress{},
|
|
901
939
|
/*pszDest=*/std::string{},
|
|
902
940
|
ConnectionType::OUTBOUND_FULL_RELAY,
|
|
903
|
-
/*inbound_onion=*/false);
|
|
941
|
+
/*inbound_onion=*/false,
|
|
942
|
+
/*network_key=*/0);
|
|
904
943
|
};
|
|
905
944
|
g_reachable_nets.Add(NET_CJDNS);
|
|
906
945
|
|