diff options
author | Gav Wood <g@ethdev.com> | 2015-03-05 05:49:47 +0800 |
---|---|---|
committer | Gav Wood <g@ethdev.com> | 2015-03-05 05:49:47 +0800 |
commit | 0c2a7fbe7d2283a2226cf693d94a087ddca56b04 (patch) | |
tree | a8bf8cf138f206f8d37dcc1429b0e4e65ab0e126 /net.cpp | |
parent | 713e5e5d1e9c467c612aded7a907951e6c3a4f9c (diff) | |
parent | e229b5d291eefbf05e77988149d3ba2dc0059575 (diff) | |
download | dexon-solidity-0c2a7fbe7d2283a2226cf693d94a087ddca56b04.tar dexon-solidity-0c2a7fbe7d2283a2226cf693d94a087ddca56b04.tar.gz dexon-solidity-0c2a7fbe7d2283a2226cf693d94a087ddca56b04.tar.bz2 dexon-solidity-0c2a7fbe7d2283a2226cf693d94a087ddca56b04.tar.lz dexon-solidity-0c2a7fbe7d2283a2226cf693d94a087ddca56b04.tar.xz dexon-solidity-0c2a7fbe7d2283a2226cf693d94a087ddca56b04.tar.zst dexon-solidity-0c2a7fbe7d2283a2226cf693d94a087ddca56b04.zip |
Merge pull request #1186 from onepremise/develop
Updates for Building all cpp-ethereum on MinGW(64)
Diffstat (limited to 'net.cpp')
-rw-r--r-- | net.cpp | 37 |
1 files changed, 19 insertions, 18 deletions
@@ -20,6 +20,7 @@ */ #include <boost/test/unit_test.hpp> + #include <libdevcore/Worker.h> #include <libdevcrypto/Common.h> #include <libp2p/UDP.h> @@ -43,7 +44,7 @@ public: 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,23 +53,23 @@ struct TestNodeTable: public NodeTable { /// Constructor TestNodeTable(ba::io_service& _io, KeyPair _alias, uint16_t _port = 30300): NodeTable(_io, _alias, _port) {} - + static std::vector<std::pair<KeyPair,unsigned>> createTestNodes(unsigned _count) { std::vector<std::pair<KeyPair,unsigned>> ret; asserts(_count < 1000); static uint16_t s_basePort = 30500; - + ret.clear(); for (unsigned i = 0; i < _count; i++) { KeyPair k = KeyPair::create(); ret.push_back(make_pair(k,s_basePort+i)); } - + return std::move(ret); } - + void pingTestNodes(std::vector<std::pair<KeyPair,unsigned>> const& _testNodes) { bi::address ourIp = bi::address::from_string("127.0.0.1"); @@ -78,7 +79,7 @@ struct TestNodeTable: public NodeTable this_thread::sleep_for(chrono::milliseconds(2)); } } - + void populateTestNodes(std::vector<std::pair<KeyPair,unsigned>> const& _testNodes, size_t _count = 0) { if (!_count) @@ -91,7 +92,7 @@ struct TestNodeTable: public NodeTable else break; } - + void reset() { Guard l(x_state); @@ -108,13 +109,13 @@ struct TestNodeTableHost: public TestHost ~TestNodeTableHost() { m_io.stop(); stopWorking(); } void setup() { for (auto n: testNodes) nodeTables.push_back(make_shared<TestNodeTable>(m_io,n.first,n.second)); } - + void pingAll() { for (auto& t: nodeTables) t->pingTestNodes(testNodes); } - + void populateAll(size_t _count = 0) { for (auto& t: nodeTables) t->populateTestNodes(testNodes, _count); } - + void populate(size_t _count = 0) { nodeTable->populateTestNodes(testNodes, _count); } - + KeyPair m_alias; shared_ptr<TestNodeTable> nodeTable; std::vector<std::pair<KeyPair,unsigned>> testNodes; // keypair and port @@ -130,7 +131,7 @@ public: void onReceived(UDPSocketFace*, bi::udp::endpoint const&, bytesConstRef _packet) { if (_packet.toString() == "AAAA") success = true; } shared_ptr<UDPSocket<TestUDPSocket, 1024>> m_socket; - + bool success = false; }; @@ -139,7 +140,7 @@ BOOST_AUTO_TEST_CASE(test_neighbours_packet) KeyPair k = KeyPair::create(); std::vector<std::pair<KeyPair,unsigned>> testNodes(TestNodeTable::createTestNodes(16)); bi::udp::endpoint to(boost::asio::ip::address::from_string("127.0.0.1"), 30000); - + Neighbours out(to); for (auto n: testNodes) { @@ -186,25 +187,25 @@ BOOST_AUTO_TEST_CASE(kademlia) node.setup(); node.populate(); clog << "NodeTable:\n" << *node.nodeTable.get() << endl; - + 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; node.populate(1); clog << "NodeTable:\n" << *node.nodeTable.get() << endl; - + node.nodeTable->discover(); this_thread::sleep_for(chrono::milliseconds(2000)); clog << "NodeTable:\n" << *node.nodeTable.get() << endl; BOOST_REQUIRE_EQUAL(node.nodeTable->count(), 8); - + auto netNodes = node.nodeTable->nodes(); netNodes.sort(); |