diff options
author | subtly <subtly@users.noreply.github.com> | 2015-04-14 14:44:01 +0800 |
---|---|---|
committer | subtly <subtly@users.noreply.github.com> | 2015-04-14 14:44:01 +0800 |
commit | b6ee801879a583c5ca199262ab2df5babaea10c4 (patch) | |
tree | 713c87183da52215de6960e693b9e2fea7cf7029 | |
parent | b848fa9af1487c3cfcc35d4ff24a6c48b0c79d06 (diff) | |
download | dexon-solidity-b6ee801879a583c5ca199262ab2df5babaea10c4.tar dexon-solidity-b6ee801879a583c5ca199262ab2df5babaea10c4.tar.gz dexon-solidity-b6ee801879a583c5ca199262ab2df5babaea10c4.tar.bz2 dexon-solidity-b6ee801879a583c5ca199262ab2df5babaea10c4.tar.lz dexon-solidity-b6ee801879a583c5ca199262ab2df5babaea10c4.tar.xz dexon-solidity-b6ee801879a583c5ca199262ab2df5babaea10c4.tar.zst dexon-solidity-b6ee801879a583c5ca199262ab2df5babaea10c4.zip |
proper neighbours packet size w/test
-rw-r--r-- | net.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -190,6 +190,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(); |