@@ -26,7 +26,7 @@ class AddrManSerializationMock : public AddrMan
26
26
virtual void Serialize (CDataStream& s) const = 0;
27
27
28
28
AddrManSerializationMock ()
29
- : AddrMan(/* asmap */ std::vector<bool >(), /* deterministic */ true , /* consistency_check_ratio */ 100 )
29
+ : AddrMan(/* asmap */ std::vector<bool >(), /* deterministic */ true , /* consistency_check_ratio */ 100 , /* discriminate_ports */ true )
30
30
{}
31
31
};
32
32
@@ -82,8 +82,9 @@ class AddrManTest : public AddrMan
82
82
83
83
public:
84
84
explicit AddrManTest (bool makeDeterministic = true ,
85
- std::vector<bool > asmap = std::vector<bool >())
86
- : AddrMan(asmap, makeDeterministic, /* consistency_check_ratio */ 100 )
85
+ std::vector<bool > asmap = std::vector<bool >(),
86
+ bool discriminatePorts = true)
87
+ : AddrMan(asmap, makeDeterministic, /* consistency_check_ratio */ 100 , discriminatePorts)
87
88
{
88
89
deterministic = makeDeterministic;
89
90
}
@@ -221,15 +222,15 @@ BOOST_AUTO_TEST_CASE(addrman_ports)
221
222
BOOST_CHECK_EQUAL (addrman.size (), 1U );
222
223
223
224
CService addr1_port = ResolveService (" 250.1.1.1" , 8334 );
224
- BOOST_CHECK (! addrman.Add ({CAddress (addr1_port, NODE_NONE)}, source));
225
- BOOST_CHECK_EQUAL (addrman.size (), 1U );
225
+ BOOST_CHECK (addrman.Add ({CAddress (addr1_port, NODE_NONE)}, source));
226
+ BOOST_CHECK_EQUAL (addrman.size (), 2U );
226
227
auto addr_ret2 = addrman.Select ().first ;
227
- BOOST_CHECK_EQUAL (addr_ret2.ToString (), " 250.1.1.1:8333" );
228
+ BOOST_CHECK (addr_ret2.ToString () == " 250.1.1.1:8333" || addr_ret2. ToString () == " 250.1.1.1:8334 " );
228
229
229
- // Test: Add same IP but diff port to tried table, it doesn't get added.
230
- // Perhaps this is not ideal behavior but it is the current behavior .
230
+ // Test: Add same IP but diff port to tried table; this converts the entry with
231
+ // the specified port to tried, but not the other .
231
232
addrman.Good (CAddress (addr1_port, NODE_NONE));
232
- BOOST_CHECK_EQUAL (addrman.size (), 1U );
233
+ BOOST_CHECK_EQUAL (addrman.size (), 2U );
233
234
bool newOnly = true ;
234
235
auto addr_ret3 = addrman.Select (newOnly).first ;
235
236
BOOST_CHECK_EQUAL (addr_ret3.ToString (), " 250.1.1.1:8333" );
@@ -368,18 +369,18 @@ BOOST_AUTO_TEST_CASE(addrman_find)
368
369
CNetAddr source2 = ResolveIP (" 250.1.2.2" );
369
370
370
371
BOOST_CHECK (addrman.Add ({addr1}, source1));
371
- BOOST_CHECK (! addrman.Add ({addr2}, source2));
372
+ BOOST_CHECK (addrman.Add ({addr2}, source2));
372
373
BOOST_CHECK (addrman.Add ({addr3}, source1));
373
374
374
- // Test: ensure Find returns an IP matching what we searched on.
375
+ // Test: ensure Find returns an IP/port matching what we searched on.
375
376
AddrInfo* info1 = addrman.Find (addr1);
376
377
BOOST_REQUIRE (info1);
377
378
BOOST_CHECK_EQUAL (info1->ToString (), " 250.1.2.1:8333" );
378
379
379
- // Test 18 ; Find does not discriminate by port number.
380
+ // Test; Find discriminates by port number.
380
381
AddrInfo* info2 = addrman.Find (addr2);
381
382
BOOST_REQUIRE (info2);
382
- BOOST_CHECK_EQUAL (info2->ToString (), info1-> ToString () );
383
+ BOOST_CHECK_EQUAL (info2->ToString (), " 250.1.2.1:9999 " );
383
384
384
385
// Test: Find returns another IP matching what we searched on.
385
386
AddrInfo* info3 = addrman.Find (addr3);
0 commit comments