You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

addrman_tests.cpp 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. // Copyright (c) 2012-2016 The Starwels developers
  2. // Distributed under the MIT software license, see the accompanying
  3. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  4. #include "addrman.h"
  5. #include "test/test_starwels.h"
  6. #include <string>
  7. #include <boost/test/unit_test.hpp>
  8. #include "hash.h"
  9. #include "netbase.h"
  10. #include "random.h"
  11. class CAddrManTest : public CAddrMan
  12. {
  13. uint64_t state;
  14. public:
  15. CAddrManTest(bool makeDeterministic = true)
  16. {
  17. state = 1;
  18. if (makeDeterministic) {
  19. // Set addrman addr placement to be deterministic.
  20. MakeDeterministic();
  21. }
  22. }
  23. //! Ensure that bucket placement is always the same for testing purposes.
  24. void MakeDeterministic()
  25. {
  26. nKey.SetNull();
  27. insecure_rand = FastRandomContext(true);
  28. }
  29. int RandomInt(int nMax) override
  30. {
  31. state = (CHashWriter(SER_GETHASH, 0) << state).GetHash().GetCheapHash();
  32. return (unsigned int)(state % nMax);
  33. }
  34. CAddrInfo* Find(const CNetAddr& addr, int* pnId = nullptr)
  35. {
  36. return CAddrMan::Find(addr, pnId);
  37. }
  38. CAddrInfo* Create(const CAddress& addr, const CNetAddr& addrSource, int* pnId = nullptr)
  39. {
  40. return CAddrMan::Create(addr, addrSource, pnId);
  41. }
  42. void Delete(int nId)
  43. {
  44. CAddrMan::Delete(nId);
  45. }
  46. };
  47. static CNetAddr ResolveIP(const char* ip)
  48. {
  49. CNetAddr addr;
  50. BOOST_CHECK_MESSAGE(LookupHost(ip, addr, false), strprintf("failed to resolve: %s", ip));
  51. return addr;
  52. }
  53. static CNetAddr ResolveIP(std::string ip)
  54. {
  55. return ResolveIP(ip.c_str());
  56. }
  57. static CService ResolveService(const char* ip, int port = 0)
  58. {
  59. CService serv;
  60. BOOST_CHECK_MESSAGE(Lookup(ip, serv, port, false), strprintf("failed to resolve: %s:%i", ip, port));
  61. return serv;
  62. }
  63. static CService ResolveService(std::string ip, int port = 0)
  64. {
  65. return ResolveService(ip.c_str(), port);
  66. }
  67. BOOST_FIXTURE_TEST_SUITE(addrman_tests, BasicTestingSetup)
  68. BOOST_AUTO_TEST_CASE(addrman_simple)
  69. {
  70. CAddrManTest addrman;
  71. CNetAddr source = ResolveIP("252.2.2.2");
  72. // Test: Does Addrman respond correctly when empty.
  73. BOOST_CHECK_EQUAL(addrman.size(), 0);
  74. CAddrInfo addr_null = addrman.Select();
  75. BOOST_CHECK_EQUAL(addr_null.ToString(), "[::]:0");
  76. // Test: Does Addrman::Add work as expected.
  77. CService addr1 = ResolveService("250.1.1.1", 8343);
  78. BOOST_CHECK(addrman.Add(CAddress(addr1, NODE_NONE), source));
  79. BOOST_CHECK_EQUAL(addrman.size(), 1);
  80. CAddrInfo addr_ret1 = addrman.Select();
  81. BOOST_CHECK_EQUAL(addr_ret1.ToString(), "250.1.1.1:8343");
  82. // Test: Does IP address deduplication work correctly.
  83. // Expected dup IP should not be added.
  84. CService addr1_dup = ResolveService("250.1.1.1", 8343);
  85. BOOST_CHECK(!addrman.Add(CAddress(addr1_dup, NODE_NONE), source));
  86. BOOST_CHECK_EQUAL(addrman.size(), 1);
  87. // Test: New table has one addr and we add a diff addr we should
  88. // have at least one addr.
  89. // Note that addrman's size cannot be tested reliably after insertion, as
  90. // hash collisions may occur. But we can always be sure of at least one
  91. // success.
  92. CService addr2 = ResolveService("250.1.1.2", 8343);
  93. BOOST_CHECK(addrman.Add(CAddress(addr2, NODE_NONE), source));
  94. BOOST_CHECK(addrman.size() >= 1);
  95. // Test: AddrMan::Clear() should empty the new table.
  96. addrman.Clear();
  97. BOOST_CHECK_EQUAL(addrman.size(), 0);
  98. CAddrInfo addr_null2 = addrman.Select();
  99. BOOST_CHECK_EQUAL(addr_null2.ToString(), "[::]:0");
  100. // Test: AddrMan::Add multiple addresses works as expected
  101. std::vector<CAddress> vAddr;
  102. vAddr.push_back(CAddress(ResolveService("250.1.1.3", 8343), NODE_NONE));
  103. vAddr.push_back(CAddress(ResolveService("250.1.1.4", 8343), NODE_NONE));
  104. BOOST_CHECK(addrman.Add(vAddr, source));
  105. BOOST_CHECK(addrman.size() >= 1);
  106. }
  107. BOOST_AUTO_TEST_CASE(addrman_ports)
  108. {
  109. CAddrManTest addrman;
  110. CNetAddr source = ResolveIP("252.2.2.2");
  111. BOOST_CHECK_EQUAL(addrman.size(), 0);
  112. // Test 7; Addr with same IP but diff port does not replace existing addr.
  113. CService addr1 = ResolveService("250.1.1.1", 8343);
  114. addrman.Add(CAddress(addr1, NODE_NONE), source);
  115. BOOST_CHECK_EQUAL(addrman.size(), 1);
  116. CService addr1_port = ResolveService("250.1.1.1", 8334);
  117. addrman.Add(CAddress(addr1_port, NODE_NONE), source);
  118. BOOST_CHECK_EQUAL(addrman.size(), 1);
  119. CAddrInfo addr_ret2 = addrman.Select();
  120. BOOST_CHECK_EQUAL(addr_ret2.ToString(), "250.1.1.1:8343");
  121. // Test: Add same IP but diff port to tried table, it doesn't get added.
  122. // Perhaps this is not ideal behavior but it is the current behavior.
  123. addrman.Good(CAddress(addr1_port, NODE_NONE));
  124. BOOST_CHECK_EQUAL(addrman.size(), 1);
  125. bool newOnly = true;
  126. CAddrInfo addr_ret3 = addrman.Select(newOnly);
  127. BOOST_CHECK_EQUAL(addr_ret3.ToString(), "250.1.1.1:8343");
  128. }
  129. BOOST_AUTO_TEST_CASE(addrman_select)
  130. {
  131. CAddrManTest addrman;
  132. CNetAddr source = ResolveIP("252.2.2.2");
  133. // Test: Select from new with 1 addr in new.
  134. CService addr1 = ResolveService("250.1.1.1", 8343);
  135. addrman.Add(CAddress(addr1, NODE_NONE), source);
  136. BOOST_CHECK_EQUAL(addrman.size(), 1);
  137. bool newOnly = true;
  138. CAddrInfo addr_ret1 = addrman.Select(newOnly);
  139. BOOST_CHECK_EQUAL(addr_ret1.ToString(), "250.1.1.1:8343");
  140. // Test: move addr to tried, select from new expected nothing returned.
  141. addrman.Good(CAddress(addr1, NODE_NONE));
  142. BOOST_CHECK_EQUAL(addrman.size(), 1);
  143. CAddrInfo addr_ret2 = addrman.Select(newOnly);
  144. BOOST_CHECK_EQUAL(addr_ret2.ToString(), "[::]:0");
  145. CAddrInfo addr_ret3 = addrman.Select();
  146. BOOST_CHECK_EQUAL(addr_ret3.ToString(), "250.1.1.1:8343");
  147. BOOST_CHECK_EQUAL(addrman.size(), 1);
  148. // Add three addresses to new table.
  149. CService addr2 = ResolveService("250.3.1.1", 8343);
  150. CService addr3 = ResolveService("250.3.2.2", 9999);
  151. CService addr4 = ResolveService("250.3.3.3", 9999);
  152. addrman.Add(CAddress(addr2, NODE_NONE), ResolveService("250.3.1.1", 8343));
  153. addrman.Add(CAddress(addr3, NODE_NONE), ResolveService("250.3.1.1", 8343));
  154. addrman.Add(CAddress(addr4, NODE_NONE), ResolveService("250.4.1.1", 8343));
  155. // Add three addresses to tried table.
  156. CService addr5 = ResolveService("250.4.4.4", 8343);
  157. CService addr6 = ResolveService("250.4.5.5", 7777);
  158. CService addr7 = ResolveService("250.4.6.6", 8343);
  159. addrman.Add(CAddress(addr5, NODE_NONE), ResolveService("250.3.1.1", 8343));
  160. addrman.Good(CAddress(addr5, NODE_NONE));
  161. addrman.Add(CAddress(addr6, NODE_NONE), ResolveService("250.3.1.1", 8343));
  162. addrman.Good(CAddress(addr6, NODE_NONE));
  163. addrman.Add(CAddress(addr7, NODE_NONE), ResolveService("250.1.1.3", 8343));
  164. addrman.Good(CAddress(addr7, NODE_NONE));
  165. // Test: 6 addrs + 1 addr from last test = 7.
  166. BOOST_CHECK_EQUAL(addrman.size(), 7);
  167. // Test: Select pulls from new and tried regardless of port number.
  168. std::set<uint16_t> ports;
  169. for (int i = 0; i < 20; ++i) {
  170. ports.insert(addrman.Select().GetPort());
  171. }
  172. BOOST_CHECK_EQUAL(ports.size(), 3);
  173. }
  174. BOOST_AUTO_TEST_CASE(addrman_new_collisions)
  175. {
  176. CAddrManTest addrman;
  177. CNetAddr source = ResolveIP("252.2.2.2");
  178. BOOST_CHECK_EQUAL(addrman.size(), 0);
  179. for (unsigned int i = 1; i < 18; i++) {
  180. CService addr = ResolveService("250.1.1." + boost::to_string(i));
  181. addrman.Add(CAddress(addr, NODE_NONE), source);
  182. //Test: No collision in new table yet.
  183. BOOST_CHECK_EQUAL(addrman.size(), i);
  184. }
  185. //Test: new table collision!
  186. CService addr1 = ResolveService("250.1.1.18");
  187. addrman.Add(CAddress(addr1, NODE_NONE), source);
  188. BOOST_CHECK_EQUAL(addrman.size(), 17);
  189. CService addr2 = ResolveService("250.1.1.19");
  190. addrman.Add(CAddress(addr2, NODE_NONE), source);
  191. BOOST_CHECK_EQUAL(addrman.size(), 18);
  192. }
  193. BOOST_AUTO_TEST_CASE(addrman_tried_collisions)
  194. {
  195. CAddrManTest addrman;
  196. CNetAddr source = ResolveIP("252.2.2.2");
  197. BOOST_CHECK_EQUAL(addrman.size(), 0);
  198. for (unsigned int i = 1; i < 80; i++) {
  199. CService addr = ResolveService("250.1.1." + boost::to_string(i));
  200. addrman.Add(CAddress(addr, NODE_NONE), source);
  201. addrman.Good(CAddress(addr, NODE_NONE));
  202. //Test: No collision in tried table yet.
  203. BOOST_CHECK_EQUAL(addrman.size(), i);
  204. }
  205. //Test: tried table collision!
  206. CService addr1 = ResolveService("250.1.1.80");
  207. addrman.Add(CAddress(addr1, NODE_NONE), source);
  208. BOOST_CHECK_EQUAL(addrman.size(), 79);
  209. CService addr2 = ResolveService("250.1.1.81");
  210. addrman.Add(CAddress(addr2, NODE_NONE), source);
  211. BOOST_CHECK_EQUAL(addrman.size(), 80);
  212. }
  213. BOOST_AUTO_TEST_CASE(addrman_find)
  214. {
  215. CAddrManTest addrman;
  216. BOOST_CHECK_EQUAL(addrman.size(), 0);
  217. CAddress addr1 = CAddress(ResolveService("250.1.2.1", 8343), NODE_NONE);
  218. CAddress addr2 = CAddress(ResolveService("250.1.2.1", 9999), NODE_NONE);
  219. CAddress addr3 = CAddress(ResolveService("251.255.2.1", 8343), NODE_NONE);
  220. CNetAddr source1 = ResolveIP("250.1.2.1");
  221. CNetAddr source2 = ResolveIP("250.1.2.2");
  222. addrman.Add(addr1, source1);
  223. addrman.Add(addr2, source2);
  224. addrman.Add(addr3, source1);
  225. // Test: ensure Find returns an IP matching what we searched on.
  226. CAddrInfo* info1 = addrman.Find(addr1);
  227. BOOST_REQUIRE(info1);
  228. BOOST_CHECK_EQUAL(info1->ToString(), "250.1.2.1:8343");
  229. // Test 18; Find does not discriminate by port number.
  230. CAddrInfo* info2 = addrman.Find(addr2);
  231. BOOST_REQUIRE(info2);
  232. BOOST_CHECK_EQUAL(info2->ToString(), info1->ToString());
  233. // Test: Find returns another IP matching what we searched on.
  234. CAddrInfo* info3 = addrman.Find(addr3);
  235. BOOST_REQUIRE(info3);
  236. BOOST_CHECK_EQUAL(info3->ToString(), "251.255.2.1:8343");
  237. }
  238. BOOST_AUTO_TEST_CASE(addrman_create)
  239. {
  240. CAddrManTest addrman;
  241. BOOST_CHECK_EQUAL(addrman.size(), 0);
  242. CAddress addr1 = CAddress(ResolveService("250.1.2.1", 8343), NODE_NONE);
  243. CNetAddr source1 = ResolveIP("250.1.2.1");
  244. int nId;
  245. CAddrInfo* pinfo = addrman.Create(addr1, source1, &nId);
  246. // Test: The result should be the same as the input addr.
  247. BOOST_CHECK_EQUAL(pinfo->ToString(), "250.1.2.1:8343");
  248. CAddrInfo* info2 = addrman.Find(addr1);
  249. BOOST_CHECK_EQUAL(info2->ToString(), "250.1.2.1:8343");
  250. }
  251. BOOST_AUTO_TEST_CASE(addrman_delete)
  252. {
  253. CAddrManTest addrman;
  254. BOOST_CHECK_EQUAL(addrman.size(), 0);
  255. CAddress addr1 = CAddress(ResolveService("250.1.2.1", 8343), NODE_NONE);
  256. CNetAddr source1 = ResolveIP("250.1.2.1");
  257. int nId;
  258. addrman.Create(addr1, source1, &nId);
  259. // Test: Delete should actually delete the addr.
  260. BOOST_CHECK_EQUAL(addrman.size(), 1);
  261. addrman.Delete(nId);
  262. BOOST_CHECK_EQUAL(addrman.size(), 0);
  263. CAddrInfo* info2 = addrman.Find(addr1);
  264. BOOST_CHECK(info2 == nullptr);
  265. }
  266. BOOST_AUTO_TEST_CASE(addrman_getaddr)
  267. {
  268. CAddrManTest addrman;
  269. // Test: Sanity check, GetAddr should never return anything if addrman
  270. // is empty.
  271. BOOST_CHECK_EQUAL(addrman.size(), 0);
  272. std::vector<CAddress> vAddr1 = addrman.GetAddr();
  273. BOOST_CHECK_EQUAL(vAddr1.size(), 0);
  274. CAddress addr1 = CAddress(ResolveService("250.250.2.1", 8343), NODE_NONE);
  275. addr1.nTime = GetAdjustedTime(); // Set time so isTerrible = false
  276. CAddress addr2 = CAddress(ResolveService("250.251.2.2", 9999), NODE_NONE);
  277. addr2.nTime = GetAdjustedTime();
  278. CAddress addr3 = CAddress(ResolveService("251.252.2.3", 8343), NODE_NONE);
  279. addr3.nTime = GetAdjustedTime();
  280. CAddress addr4 = CAddress(ResolveService("252.253.3.4", 8343), NODE_NONE);
  281. addr4.nTime = GetAdjustedTime();
  282. CAddress addr5 = CAddress(ResolveService("252.254.4.5", 8343), NODE_NONE);
  283. addr5.nTime = GetAdjustedTime();
  284. CNetAddr source1 = ResolveIP("250.1.2.1");
  285. CNetAddr source2 = ResolveIP("250.2.3.3");
  286. // Test: Ensure GetAddr works with new addresses.
  287. addrman.Add(addr1, source1);
  288. addrman.Add(addr2, source2);
  289. addrman.Add(addr3, source1);
  290. addrman.Add(addr4, source2);
  291. addrman.Add(addr5, source1);
  292. // GetAddr returns 23% of addresses, 23% of 5 is 1 rounded down.
  293. BOOST_CHECK_EQUAL(addrman.GetAddr().size(), 1);
  294. // Test: Ensure GetAddr works with new and tried addresses.
  295. addrman.Good(CAddress(addr1, NODE_NONE));
  296. addrman.Good(CAddress(addr2, NODE_NONE));
  297. BOOST_CHECK_EQUAL(addrman.GetAddr().size(), 1);
  298. // Test: Ensure GetAddr still returns 23% when addrman has many addrs.
  299. for (unsigned int i = 1; i < (8 * 256); i++) {
  300. int octet1 = i % 256;
  301. int octet2 = i >> 8 % 256;
  302. std::string strAddr = boost::to_string(octet1) + "." + boost::to_string(octet2) + ".1.23";
  303. CAddress addr = CAddress(ResolveService(strAddr), NODE_NONE);
  304. // Ensure that for all addrs in addrman, isTerrible == false.
  305. addr.nTime = GetAdjustedTime();
  306. addrman.Add(addr, ResolveIP(strAddr));
  307. if (i % 8 == 0)
  308. addrman.Good(addr);
  309. }
  310. std::vector<CAddress> vAddr = addrman.GetAddr();
  311. size_t percent23 = (addrman.size() * 23) / 100;
  312. BOOST_CHECK_EQUAL(vAddr.size(), percent23);
  313. BOOST_CHECK_EQUAL(vAddr.size(), 461);
  314. // (Addrman.size() < number of addresses added) due to address collisions.
  315. BOOST_CHECK_EQUAL(addrman.size(), 2006);
  316. }
  317. BOOST_AUTO_TEST_CASE(caddrinfo_get_tried_bucket)
  318. {
  319. CAddrManTest addrman;
  320. CAddress addr1 = CAddress(ResolveService("250.1.1.1", 8343), NODE_NONE);
  321. CAddress addr2 = CAddress(ResolveService("250.1.1.1", 9999), NODE_NONE);
  322. CNetAddr source1 = ResolveIP("250.1.1.1");
  323. CAddrInfo info1 = CAddrInfo(addr1, source1);
  324. uint256 nKey1 = (uint256)(CHashWriter(SER_GETHASH, 0) << 1).GetHash();
  325. uint256 nKey2 = (uint256)(CHashWriter(SER_GETHASH, 0) << 2).GetHash();
  326. BOOST_CHECK_EQUAL(info1.GetTriedBucket(nKey1), 40);
  327. // Test: Make sure key actually randomizes bucket placement. A fail on
  328. // this test could be a security issue.
  329. BOOST_CHECK(info1.GetTriedBucket(nKey1) != info1.GetTriedBucket(nKey2));
  330. // Test: Two addresses with same IP but different ports can map to
  331. // different buckets because they have different keys.
  332. CAddrInfo info2 = CAddrInfo(addr2, source1);
  333. BOOST_CHECK(info1.GetKey() != info2.GetKey());
  334. BOOST_CHECK(info1.GetTriedBucket(nKey1) != info2.GetTriedBucket(nKey1));
  335. std::set<int> buckets;
  336. for (int i = 0; i < 255; i++) {
  337. CAddrInfo infoi = CAddrInfo(
  338. CAddress(ResolveService("250.1.1." + boost::to_string(i)), NODE_NONE),
  339. ResolveIP("250.1.1." + boost::to_string(i)));
  340. int bucket = infoi.GetTriedBucket(nKey1);
  341. buckets.insert(bucket);
  342. }
  343. // Test: IP addresses in the same group (\16 prefix for IPv4) should
  344. // never get more than 8 buckets
  345. BOOST_CHECK_EQUAL(buckets.size(), 8);
  346. buckets.clear();
  347. for (int j = 0; j < 255; j++) {
  348. CAddrInfo infoj = CAddrInfo(
  349. CAddress(ResolveService("250." + boost::to_string(j) + ".1.1"), NODE_NONE),
  350. ResolveIP("250." + boost::to_string(j) + ".1.1"));
  351. int bucket = infoj.GetTriedBucket(nKey1);
  352. buckets.insert(bucket);
  353. }
  354. // Test: IP addresses in the different groups should map to more than
  355. // 8 buckets.
  356. BOOST_CHECK_EQUAL(buckets.size(), 160);
  357. }
  358. BOOST_AUTO_TEST_CASE(caddrinfo_get_new_bucket)
  359. {
  360. CAddrManTest addrman;
  361. CAddress addr1 = CAddress(ResolveService("250.1.2.1", 8343), NODE_NONE);
  362. CAddress addr2 = CAddress(ResolveService("250.1.2.1", 9999), NODE_NONE);
  363. CNetAddr source1 = ResolveIP("250.1.2.1");
  364. CAddrInfo info1 = CAddrInfo(addr1, source1);
  365. uint256 nKey1 = (uint256)(CHashWriter(SER_GETHASH, 0) << 1).GetHash();
  366. uint256 nKey2 = (uint256)(CHashWriter(SER_GETHASH, 0) << 2).GetHash();
  367. // Test: Make sure the buckets are what we expect
  368. BOOST_CHECK_EQUAL(info1.GetNewBucket(nKey1), 786);
  369. BOOST_CHECK_EQUAL(info1.GetNewBucket(nKey1, source1), 786);
  370. // Test: Make sure key actually randomizes bucket placement. A fail on
  371. // this test could be a security issue.
  372. BOOST_CHECK(info1.GetNewBucket(nKey1) != info1.GetNewBucket(nKey2));
  373. // Test: Ports should not effect bucket placement in the addr
  374. CAddrInfo info2 = CAddrInfo(addr2, source1);
  375. BOOST_CHECK(info1.GetKey() != info2.GetKey());
  376. BOOST_CHECK_EQUAL(info1.GetNewBucket(nKey1), info2.GetNewBucket(nKey1));
  377. std::set<int> buckets;
  378. for (int i = 0; i < 255; i++) {
  379. CAddrInfo infoi = CAddrInfo(
  380. CAddress(ResolveService("250.1.1." + boost::to_string(i)), NODE_NONE),
  381. ResolveIP("250.1.1." + boost::to_string(i)));
  382. int bucket = infoi.GetNewBucket(nKey1);
  383. buckets.insert(bucket);
  384. }
  385. // Test: IP addresses in the same group (\16 prefix for IPv4) should
  386. // always map to the same bucket.
  387. BOOST_CHECK_EQUAL(buckets.size(), 1);
  388. buckets.clear();
  389. for (int j = 0; j < 4 * 255; j++) {
  390. CAddrInfo infoj = CAddrInfo(CAddress(
  391. ResolveService(
  392. boost::to_string(250 + (j / 255)) + "." + boost::to_string(j % 256) + ".1.1"), NODE_NONE),
  393. ResolveIP("251.4.1.1"));
  394. int bucket = infoj.GetNewBucket(nKey1);
  395. buckets.insert(bucket);
  396. }
  397. // Test: IP addresses in the same source groups should map to no more
  398. // than 64 buckets.
  399. BOOST_CHECK(buckets.size() <= 64);
  400. buckets.clear();
  401. for (int p = 0; p < 255; p++) {
  402. CAddrInfo infoj = CAddrInfo(
  403. CAddress(ResolveService("250.1.1.1"), NODE_NONE),
  404. ResolveIP("250." + boost::to_string(p) + ".1.1"));
  405. int bucket = infoj.GetNewBucket(nKey1);
  406. buckets.insert(bucket);
  407. }
  408. // Test: IP addresses in the different source groups should map to more
  409. // than 64 buckets.
  410. BOOST_CHECK(buckets.size() > 64);
  411. }
  412. BOOST_AUTO_TEST_SUITE_END()