TEST (peer_container, split) { nano::system system (24000, 1); auto now (std::chrono::steady_clock::now ()); nano::endpoint endpoint1 (boost::asio::ip::address_v6::loopback (), 100); nano::endpoint endpoint2 (boost::asio::ip::address_v6::loopback (), 101); auto channel1 (system.nodes[0]->network.udp_channels.insert (endpoint1, 0)); ASSERT_NE (nullptr, channel1); system.nodes[0]->network.udp_channels.modify (channel1, [&now](auto channel) { channel->set_last_packet_received (now - std::chrono::seconds (1)); }); auto channel2 (system.nodes[0]->network.udp_channels.insert (endpoint2, 0)); ASSERT_NE (nullptr, channel2); system.nodes[0]->network.udp_channels.modify (channel2, [&now](auto channel) { channel->set_last_packet_received (now + std::chrono::seconds (1)); }); ASSERT_EQ (2, system.nodes[0]->network.size ()); ASSERT_EQ (2, system.nodes[0]->network.udp_channels.size ()); system.nodes[0]->network.cleanup (now); ASSERT_EQ (1, system.nodes[0]->network.size ()); ASSERT_EQ (1, system.nodes[0]->network.udp_channels.size ()); auto list (system.nodes[0]->network.list (1)); ASSERT_EQ (endpoint2, list[0]->get_endpoint ()); }
int main() { // Unique endpoints. ip::udp::endpoint endpoint1(ip::address::from_string("11.11.11.11"), 1111); ip::udp::endpoint endpoint2(ip::address::from_string("22.22.22.22"), 2222); ip::udp::endpoint endpoint3(ip::address::from_string("33.33.33.33"), 3333); // Create a client for each endpoint. auto client1 = std::make_shared<client>(endpoint1); auto client2 = std::make_shared<client>(endpoint2); auto client3 = std::make_shared<client>(endpoint3); // Add the clients to the manager. client_manager manager; manager.add(client1); manager.add(client2); manager.add(client3); // Locate a client based on the endpoint. auto client_result = manager.get(endpoint2); assert(client1 != client_result); assert(client2 == client_result); assert(client3 != client_result); }