Ejemplo n.º 1
0
TEST (peer_container, no_recontact)
{
	nano::system system (24000, 1);
	nano::network & network (system.nodes[0]->network);
	auto observed_peer (0);
	auto observed_disconnect (false);
	nano::endpoint endpoint1 (boost::asio::ip::address_v6::loopback (), 10000);
	ASSERT_EQ (0, network.size ());
	network.channel_observer = [&observed_peer](std::shared_ptr<nano::transport::channel>) { ++observed_peer; };
	system.nodes[0]->network.disconnect_observer = [&observed_disconnect]() { observed_disconnect = true; };
	auto channel (network.udp_channels.insert (endpoint1, nano::protocol_version));
	ASSERT_EQ (1, network.size ());
	ASSERT_EQ (channel, network.udp_channels.insert (endpoint1, nano::protocol_version));
	system.nodes[0]->network.cleanup (std::chrono::steady_clock::now () + std::chrono::seconds (5));
	ASSERT_TRUE (network.empty ());
	ASSERT_EQ (1, observed_peer);
	ASSERT_TRUE (observed_disconnect);
}
Ejemplo n.º 2
0
// Test to make sure we don't repeatedly send keepalive messages to nodes that aren't responding
TEST (peer_container, reachout)
{
	nano::system system (24000, 1);
	nano::endpoint endpoint0 (boost::asio::ip::address_v6::loopback (), 24000);
	// Make sure having been contacted by them already indicates we shouldn't reach out
	system.nodes[0]->network.udp_channels.insert (endpoint0, nano::protocol_version);
	ASSERT_TRUE (system.nodes[0]->network.reachout (endpoint0));
	nano::endpoint endpoint1 (boost::asio::ip::address_v6::loopback (), 24001);
	ASSERT_FALSE (system.nodes[0]->network.reachout (endpoint1));
	// Reaching out to them once should signal we shouldn't reach out again.
	ASSERT_TRUE (system.nodes[0]->network.reachout (endpoint1));
	// Make sure we don't purge new items
	system.nodes[0]->network.cleanup (std::chrono::steady_clock::now () - std::chrono::seconds (10));
	ASSERT_TRUE (system.nodes[0]->network.reachout (endpoint1));
	// Make sure we purge old items
	system.nodes[0]->network.cleanup (std::chrono::steady_clock::now () + std::chrono::seconds (10));
	ASSERT_FALSE (system.nodes[0]->network.reachout (endpoint1));
}
Ejemplo n.º 3
0
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 ());
}
Ejemplo n.º 4
0
Archivo: main.cpp Proyecto: CCJY/coliru
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);
}