Changeset View
Changeset View
Standalone View
Standalone View
src/test/net_tests.cpp
| Show First 20 Lines • Show All 239 Lines • ▼ Show 20 Lines | bool checkContiguousAddressesConnection( | ||||
| groups.insert(pnode->addr.GetGroup({})); | groups.insert(pnode->addr.GetGroup({})); | ||||
| } | } | ||||
| }); | }); | ||||
| BOOST_CHECK_EQUAL(groups.size(), expectedOutboundFullRelayCount); | BOOST_CHECK_EQUAL(groups.size(), expectedOutboundFullRelayCount); | ||||
| return ret; | return ret; | ||||
| } | } | ||||
| /** | |||||
| * Wait until at least minTotalConnections outbound peers are connected, | |||||
| * including at least one avalanche and one full-relay outbound. Requires | |||||
| * quorum to be established so both connection types are opened. | |||||
| */ | |||||
| bool | |||||
| waitForMixedOutboundPeers(const std::vector<TestAddresses> &testAddresses, | |||||
| size_t minTotalConnections) | |||||
| EXCLUSIVE_LOCKS_REQUIRED(!cs) { | |||||
| { | |||||
| LOCK(cs); | |||||
| outboundFullRelayCount = 0; | |||||
| avalancheOutboundsCount = 0; | |||||
| } | |||||
| ClearNodes(); | |||||
| struct IpGen { | |||||
| uint32_t baseIp; | |||||
| uint32_t offset; | |||||
| }; | |||||
| std::vector<IpGen> ipGroups{ | |||||
| {0x00010101, 1}, {0x00010164, 1}, {0x000101c8, 1}, {0x00010201, 1}, | |||||
| {0x00010264, 1}, {0x000102c8, 1}, {0x00010301, 1}, {0x00010364, 1}, | |||||
| {0x000103c8, 1}, {0x00010401, 1}, {0x00010464, 1}, {0x000104c8, 1}}; | |||||
| auto getAddrGroup = [&](size_t group, uint64_t services) { | |||||
| CNetAddr addr = | |||||
| ip(ipGroups[group].baseIp + (ipGroups[group].offset++ << 24)); | |||||
| return CAddress(CService(addr, Params().GetDefaultPort()), | |||||
| ServiceFlags(services)); | |||||
| }; | |||||
| size_t addressCount = 0; | |||||
| for (const TestAddresses &addresses : testAddresses) { | |||||
| assert(addresses.group < ipGroups.size()); | |||||
| addressCount += addresses.quantity; | |||||
| do { | |||||
| addrman.Add({getAddrGroup(addresses.group, | |||||
| ServiceFlags(addresses.services))}, | |||||
| CNetAddr()); | |||||
| } while (addrman.size() < addressCount); | |||||
| } | |||||
| interruptNet.reset(); | |||||
| std::vector<std::string> empty; | |||||
| threadOpenConnections = std::thread( | |||||
| &CConnman::ThreadOpenConnections, this, empty, | |||||
| std::bind(&CConnmanTest::openNetworkConnection, this, | |||||
| std::placeholders::_1, std::placeholders::_2)); | |||||
| Mutex mutex; | |||||
| WAIT_LOCK(mutex, lock); | |||||
| bool ret = cvar.wait_for(lock, 60s, [&]() { | |||||
| LOCK(cs); | |||||
| return (avalancheOutboundsCount + outboundFullRelayCount >= | |||||
| minTotalConnections) && | |||||
| avalancheOutboundsCount > 0 && outboundFullRelayCount > 0; | |||||
| }); | |||||
| interruptNet(); | |||||
| if (threadOpenConnections.joinable()) { | |||||
| threadOpenConnections.join(); | |||||
| } | |||||
| return ret; | |||||
| } | |||||
| bool AlreadyConnectedToAddress(const CAddress &addr) { | bool AlreadyConnectedToAddress(const CAddress &addr) { | ||||
| return CConnman::AlreadyConnectedToAddress(addr); | return CConnman::AlreadyConnectedToAddress(addr); | ||||
| } | } | ||||
| }; | }; | ||||
| } // namespace | } // namespace | ||||
| class NetTestConfig : public DummyConfig { | class NetTestConfig : public DummyConfig { | ||||
| public: | public: | ||||
| ▲ Show 20 Lines • Show All 977 Lines • ▼ Show 20 Lines | BOOST_CHECK(freshConnman()->checkContiguousAddressesConnection( | ||||
| {9, NODE_NETWORK, 1}, | {9, NODE_NETWORK, 1}, | ||||
| {10, NODE_NETWORK, 1}, | {10, NODE_NETWORK, 1}, | ||||
| {11, NODE_NETWORK, 1}, | {11, NODE_NETWORK, 1}, | ||||
| }, | }, | ||||
| options.m_max_outbound_full_relay, // Expected full-relay outbound count | options.m_max_outbound_full_relay, // Expected full-relay outbound count | ||||
| 0 // Expected avalanche outbound count | 0 // Expected avalanche outbound count | ||||
| )); | )); | ||||
| // Avalanche outbounds are prioritized, so contiguous full relay outbounds | // Without a quorum, avalanche outbounds are prioritized, so contiguous full | ||||
| // will fail due to network group limitation | // relay outbounds will fail due to network group limitation | ||||
| BOOST_CHECK(freshConnman()->checkContiguousAddressesConnection( | BOOST_CHECK(freshConnman()->checkContiguousAddressesConnection( | ||||
| { | { | ||||
| // group, services, quantity | // group, services, quantity | ||||
| {0, NODE_NETWORK | NODE_AVALANCHE, 1}, | {0, NODE_NETWORK | NODE_AVALANCHE, 1}, | ||||
| {0, NODE_NETWORK, 3}, | {0, NODE_NETWORK, 3}, | ||||
| }, | }, | ||||
| 0, // Expected full-relay outbound count | 0, // Expected full-relay outbound count | ||||
| 1 // Expected avalanche outbound count | 1 // Expected avalanche outbound count | ||||
| Show All 26 Lines | BOOST_CHECK(freshConnman()->checkContiguousAddressesConnection( | ||||
| {8, NODE_NETWORK, 10}, | {8, NODE_NETWORK, 10}, | ||||
| {9, NODE_NETWORK, 10}, | {9, NODE_NETWORK, 10}, | ||||
| {10, NODE_NETWORK, 10}, | {10, NODE_NETWORK, 10}, | ||||
| {11, NODE_NETWORK, 10}, | {11, NODE_NETWORK, 10}, | ||||
| }, | }, | ||||
| options.m_max_outbound_full_relay, // Expected full-relay outbound count | options.m_max_outbound_full_relay, // Expected full-relay outbound count | ||||
| 50 // Expected avalanche outbound count | 50 // Expected avalanche outbound count | ||||
| )); | )); | ||||
| freshConnman()->SetQuorumEstablished(true); | |||||
| // After quorum is established, avalanche and full-relay outbounds are | |||||
| // opened in parallel when both slots are available. | |||||
| BOOST_CHECK(freshConnman()->waitForMixedOutboundPeers( | |||||
| { | |||||
| // group, services, quantity | |||||
| {0, NODE_NETWORK | NODE_AVALANCHE, 10}, | |||||
| {1, NODE_NETWORK, 10}, | |||||
| {2, NODE_NETWORK | NODE_AVALANCHE, 10}, | |||||
| {3, NODE_NETWORK, 10}, | |||||
| {4, NODE_NETWORK | NODE_AVALANCHE, 10}, | |||||
| {5, NODE_NETWORK, 10}, | |||||
| {6, NODE_NETWORK | NODE_AVALANCHE, 10}, | |||||
| {7, NODE_NETWORK, 10}, | |||||
| {8, NODE_NETWORK | NODE_AVALANCHE, 10}, | |||||
| {9, NODE_NETWORK, 10}, | |||||
| {10, NODE_NETWORK | NODE_AVALANCHE, 10}, | |||||
| {11, NODE_NETWORK, 10}, | |||||
| }, | |||||
| // Minimum total outbound count (both types must be represented) | |||||
| 10)); | |||||
| } | } | ||||
| BOOST_AUTO_TEST_CASE(initial_advertise_from_version_message) { | BOOST_AUTO_TEST_CASE(initial_advertise_from_version_message) { | ||||
| LOCK(NetEventsInterface::g_msgproc_mutex); | LOCK(NetEventsInterface::g_msgproc_mutex); | ||||
| // Tests the following scenario: | // Tests the following scenario: | ||||
| // * -bind=3.4.5.6:20001 is specified | // * -bind=3.4.5.6:20001 is specified | ||||
| // * we make an outbound connection to a peer | // * we make an outbound connection to a peer | ||||
| ▲ Show 20 Lines • Show All 280 Lines • Show Last 20 Lines | |||||