diff options
author | Gav Wood <g@ethdev.com> | 2015-04-14 15:17:06 +0800 |
---|---|---|
committer | Gav Wood <g@ethdev.com> | 2015-04-14 15:17:06 +0800 |
commit | 4615f8cd1a7a61283de149a7f6f75f4910ee4b3b (patch) | |
tree | de2eea3dd316166494d2b6a88c344066f977fc6e /net.cpp | |
parent | 675975fad2c2efcd56f92025bbf2b1804adf2b7e (diff) | |
parent | 0a4e2329f03303d8d05c6a8f61077caf4425955b (diff) | |
download | dexon-solidity-4615f8cd1a7a61283de149a7f6f75f4910ee4b3b.tar dexon-solidity-4615f8cd1a7a61283de149a7f6f75f4910ee4b3b.tar.gz dexon-solidity-4615f8cd1a7a61283de149a7f6f75f4910ee4b3b.tar.bz2 dexon-solidity-4615f8cd1a7a61283de149a7f6f75f4910ee4b3b.tar.lz dexon-solidity-4615f8cd1a7a61283de149a7f6f75f4910ee4b3b.tar.xz dexon-solidity-4615f8cd1a7a61283de149a7f6f75f4910ee4b3b.tar.zst dexon-solidity-4615f8cd1a7a61283de149a7f6f75f4910ee4b3b.zip |
Merge pull request #1587 from subtly/neighbours
Drop unsolicited neighbours packets.
Diffstat (limited to 'net.cpp')
-rw-r--r-- | net.cpp | 33 |
1 files changed, 33 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"; |