diff options
author | subtly <subtly@users.noreply.github.com> | 2015-01-31 09:53:27 +0800 |
---|---|---|
committer | subtly <subtly@users.noreply.github.com> | 2015-01-31 09:53:27 +0800 |
commit | f4233598c1f731a6c904450c4a003d8cf7561ee4 (patch) | |
tree | 38d360ac3ace42716a1d6cd7db3ac96cf24b2200 | |
parent | 29de01b458401615d56a8c9ebbda5e0c7805e9eb (diff) | |
download | dexon-solidity-f4233598c1f731a6c904450c4a003d8cf7561ee4.tar dexon-solidity-f4233598c1f731a6c904450c4a003d8cf7561ee4.tar.gz dexon-solidity-f4233598c1f731a6c904450c4a003d8cf7561ee4.tar.bz2 dexon-solidity-f4233598c1f731a6c904450c4a003d8cf7561ee4.tar.lz dexon-solidity-f4233598c1f731a6c904450c4a003d8cf7561ee4.tar.xz dexon-solidity-f4233598c1f731a6c904450c4a003d8cf7561ee4.tar.zst dexon-solidity-f4233598c1f731a6c904450c4a003d8cf7561ee4.zip |
import/export peers and nodes
-rw-r--r-- | net.cpp | 11 | ||||
-rw-r--r-- | peer.cpp | 37 |
2 files changed, 47 insertions, 1 deletions
@@ -30,7 +30,7 @@ using namespace dev::p2p; namespace ba = boost::asio; namespace bi = ba::ip; -BOOST_AUTO_TEST_SUITE(p2p) +BOOST_AUTO_TEST_SUITE(net) /** * Only used for testing. Not useful beyond tests. @@ -190,6 +190,9 @@ BOOST_AUTO_TEST_CASE(kademlia) node.populateAll(); clog << "NodeTable:\n" << *node.nodeTable.get() << endl; + auto nodes = node.nodeTable->nodes(); + nodes.sort(); + node.nodeTable->reset(); clog << "NodeTable:\n" << *node.nodeTable.get() << endl; @@ -199,6 +202,12 @@ BOOST_AUTO_TEST_CASE(kademlia) node.nodeTable->join(); this_thread::sleep_for(chrono::milliseconds(2000)); clog << "NodeTable:\n" << *node.nodeTable.get() << endl; + + BOOST_REQUIRE_EQUAL(node.nodeTable->size(), 8); + + auto netNodes = node.nodeTable->nodes(); + netNodes.sort(); + } BOOST_AUTO_TEST_CASE(test_udp_once) @@ -50,6 +50,43 @@ BOOST_AUTO_TEST_CASE(host) BOOST_REQUIRE_EQUAL(host2.peerCount(), host1.peerCount()); } +BOOST_AUTO_TEST_CASE(save_nodes) +{ + std::list<Host*> hosts; + for (auto i:{0,1,2,3,4,5}) + { + Host* h = new Host("Test", NetworkPreferences(30300 + i, "127.0.0.1", true, true)); + // starting host is required so listenport is available + h->start(); + while (!h->isStarted()) + this_thread::sleep_for(chrono::milliseconds(2)); + hosts.push_back(h); + } + + Host& host = *hosts.front(); + for (auto const& h: hosts) + host.addNode(h->id(), "127.0.0.1", h->listenPort(), h->listenPort()); + + Host& host2 = *hosts.back(); + for (auto const& h: hosts) + host2.addNode(h->id(), "127.0.0.1", h->listenPort(), h->listenPort()); + + this_thread::sleep_for(chrono::milliseconds(1000)); + bytes firstHostNetwork(host.saveNetwork()); + bytes secondHostNetwork(host.saveNetwork()); + + BOOST_REQUIRE_EQUAL(sha3(firstHostNetwork), sha3(secondHostNetwork)); + + BOOST_CHECK_EQUAL(host.peerCount(), 5); + BOOST_CHECK_EQUAL(host2.peerCount(), 5); + + RLP r(firstHostNetwork); + BOOST_REQUIRE(r.itemCount() == 3); + BOOST_REQUIRE(r[0].toInt<int>() == 1); + BOOST_REQUIRE_EQUAL(r[1].toBytes().size(), 32); // secret + BOOST_REQUIRE_EQUAL(r[2].itemCount(), 5); +} + BOOST_AUTO_TEST_SUITE_END() int peerTest(int argc, char** argv) |