diff options
author | chriseth <c@ethdev.com> | 2015-04-15 23:43:23 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2015-04-15 23:43:23 +0800 |
commit | 6753e0a8e6796e99ee826c28c7bcbde55348b07d (patch) | |
tree | fdcb51c9c0b26aab635680ff2f2cb330cf4f4bd2 /net.cpp | |
parent | c19d10321a116bec4ed08aabf3b3c8d74bf61608 (diff) | |
parent | c5f08fe6dff58f973da8b888d25afa3ef967936e (diff) | |
download | dexon-solidity-6753e0a8e6796e99ee826c28c7bcbde55348b07d.tar dexon-solidity-6753e0a8e6796e99ee826c28c7bcbde55348b07d.tar.gz dexon-solidity-6753e0a8e6796e99ee826c28c7bcbde55348b07d.tar.bz2 dexon-solidity-6753e0a8e6796e99ee826c28c7bcbde55348b07d.tar.lz dexon-solidity-6753e0a8e6796e99ee826c28c7bcbde55348b07d.tar.xz dexon-solidity-6753e0a8e6796e99ee826c28c7bcbde55348b07d.tar.zst dexon-solidity-6753e0a8e6796e99ee826c28c7bcbde55348b07d.zip |
Merge remote-tracking branch 'ethereum/develop' into sol_overloadingFunctions
Conflicts:
libsolidity/Types.cpp
Diffstat (limited to 'net.cpp')
-rw-r--r-- | net.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
@@ -145,6 +145,39 @@ public: bool success = false; }; +BOOST_AUTO_TEST_CASE(requestTimeout) +{ + using TimePoint = std::chrono::steady_clock::time_point; + using RequestTimeout = std::pair<NodeId, TimePoint>; + + std::chrono::milliseconds timeout(300); + std::list<RequestTimeout> timeouts; + + NodeId nodeA(sha3("a")); + NodeId nodeB(sha3("b")); + timeouts.push_back(make_pair(nodeA, chrono::steady_clock::now())); + this_thread::sleep_for(std::chrono::milliseconds(100)); + timeouts.push_back(make_pair(nodeB, chrono::steady_clock::now())); + this_thread::sleep_for(std::chrono::milliseconds(210)); + + bool nodeAtriggered = false; + bool nodeBtriggered = false; + timeouts.remove_if([&](RequestTimeout const& t) + { + auto now = chrono::steady_clock::now(); + auto diff = now - t.second; + if (t.first == nodeA && diff < timeout) + nodeAtriggered = true; + if (t.first == nodeB && diff < timeout) + nodeBtriggered = true; + return (t.first == nodeA || t.first == nodeB); + }); + + BOOST_REQUIRE(nodeAtriggered == false); + BOOST_REQUIRE(nodeBtriggered == true); + BOOST_REQUIRE(timeouts.size() == 0); +} + BOOST_AUTO_TEST_CASE(isIPAddressType) { string wildcard = "0.0.0.0"; @@ -190,6 +223,33 @@ BOOST_AUTO_TEST_CASE(v2PingNodePacket) BOOST_REQUIRE(p.version == 2); } +BOOST_AUTO_TEST_CASE(neighboursPacketLength) +{ + 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); + + // hash(32), signature(65), overhead: packet(2), type(1), nodeList(2), ts(9), + static unsigned const nlimit = (1280 - 111) / 87; + for (unsigned offset = 0; offset < testNodes.size(); offset += nlimit) + { + Neighbours out(to); + + auto limit = nlimit ? std::min(testNodes.size(), (size_t)(offset + nlimit)) : testNodes.size(); + for (auto i = offset; i < limit; i++) + { + Neighbours::Node node; + node.ipAddress = boost::asio::ip::address::from_string("200.200.200.200").to_string(); + node.port = testNodes[i].second; + node.node = testNodes[i].first.pub(); + out.nodes.push_back(node); + } + + out.sign(k.sec()); + BOOST_REQUIRE_LE(out.data.size(), 1280); + } +} + BOOST_AUTO_TEST_CASE(test_neighbours_packet) { KeyPair k = KeyPair::create(); |