diff options
author | subtly <subtly@users.noreply.github.com> | 2014-12-24 17:22:27 +0800 |
---|---|---|
committer | subtly <subtly@users.noreply.github.com> | 2014-12-24 17:22:27 +0800 |
commit | aad7141f0af696ec386f58e41fa9ecc862f116d7 (patch) | |
tree | c7b2966a5e7165292064237efa653b73bb1127d5 | |
parent | 25a905b740892831f07c3d54f465ddaaf83441a6 (diff) | |
download | dexon-solidity-aad7141f0af696ec386f58e41fa9ecc862f116d7.tar.gz dexon-solidity-aad7141f0af696ec386f58e41fa9ecc862f116d7.tar.zst dexon-solidity-aad7141f0af696ec386f58e41fa9ecc862f116d7.zip |
message signing and verification. shutdown io/thread before dealloc in nodetable/testnodetables.
-rw-r--r-- | net.cpp | 34 |
1 files changed, 25 insertions, 9 deletions
@@ -42,6 +42,7 @@ public: virtual ~TestHost() { m_io.stop(); stopWorking(); } void start() { startWorking(); } void doWork() { m_io.run(); } + void doneWorking() { m_io.reset(); m_io.poll(); m_io.reset(); } protected: ba::io_service m_io; @@ -52,18 +53,20 @@ struct TestNodeTable: public NodeTable /// Constructor using NodeTable::NodeTable; - void setup(std::vector<std::pair<KeyPair,unsigned>> const& _testNodes) + void pingAll(std::vector<std::pair<KeyPair,unsigned>> const& _testNodes) { - /// Phase 2 test: pre-populate *expected* ping-responses, send pings - bi::address ourIp = bi::address::from_string("127.0.0.1"); - uint16_t ourPort = 30300; - bi::udp::endpoint ourEndpoint(ourIp, ourPort); - for (auto& n: _testNodes) ping(bi::udp::endpoint(ourIp, n.second)); } + void populate(std::vector<std::pair<KeyPair,unsigned>> const& _testNodes) + { + bi::address ourIp = bi::address::from_string("127.0.0.1"); + for (auto& n: _testNodes) + noteNode(n.first.pub(), bi::udp::endpoint(ourIp, n.second)); + } + void reset() { Guard l(x_state); @@ -77,8 +80,9 @@ struct TestNodeTable: public NodeTable struct TestNodeTableHost: public TestHost { TestNodeTableHost(): m_alias(KeyPair::create()), nodeTable(new TestNodeTable(m_io, m_alias)) {}; + ~TestNodeTableHost() { m_io.stop(); stopWorking(); } - void generateTestNodes(int _count = 10) + void generateTestNodes(int _count = 30) { asserts(_count < 1000); static uint16_t s_basePort = 30500; @@ -96,7 +100,16 @@ struct TestNodeTableHost: public TestHost void setup() { generateTestNodes(); - nodeTable->setup(m_testNodes); + } + + void pingAll() + { + nodeTable->pingAll(m_testNodes); + } + + void populate() + { + nodeTable->populate(m_testNodes); } KeyPair m_alias; @@ -123,7 +136,10 @@ BOOST_AUTO_TEST_CASE(kademlia) node.start(); node.nodeTable->join(); // ideally, joining with empty node table logs warning we can check for node.setup(); - sleep(1); + node.pingAll(); + this_thread::sleep_for(chrono::milliseconds(500)); + + cout << "NodeTable:\n" << *node.nodeTable.get() << endl; } BOOST_AUTO_TEST_CASE(test_txrx_one) |