Decreasing size of keepalive packets.
This commit is contained in:
parent
28ad9837b0
commit
77450b2020
3 changed files with 16 additions and 15 deletions
|
@ -49,7 +49,7 @@ namespace
|
|||
}
|
||||
bool constexpr log_to_cerr ()
|
||||
{
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -354,9 +354,9 @@ void rai::network::receive_action (boost::system::error_code const & error, size
|
|||
}
|
||||
}
|
||||
|
||||
void rai::network::merge_peers (std::array <rai::endpoint, 24> const & peers_a)
|
||||
void rai::network::merge_peers (std::array <rai::endpoint, 8> const & peers_a)
|
||||
{
|
||||
for (auto i (peers_a.begin ()), j (peers_a.end ()); i != j; ++i) // Amplify attack, send to the same IP many times
|
||||
for (auto i (peers_a.begin ()), j (peers_a.end ()); i != j; ++i)
|
||||
{
|
||||
if (*i != endpoint ())
|
||||
{
|
||||
|
@ -370,7 +370,7 @@ void rai::network::merge_peers (std::array <rai::endpoint, 24> const & peers_a)
|
|||
{
|
||||
if (i->address ().to_v4 ().to_ulong () != 0 || i->port () != 0)
|
||||
{
|
||||
client.log.add (boost::str (boost::format ("Keepalive req contained reserved address")));
|
||||
client.log.add (boost::str (boost::format ("Keepalive contained reserved address")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2763,7 +2763,7 @@ rai::bootstrap_connection::~bootstrap_connection ()
|
|||
}
|
||||
}
|
||||
|
||||
void rai::peer_container::random_fill (std::array <rai::endpoint, 24> & target_a)
|
||||
void rai::peer_container::random_fill (std::array <rai::endpoint, 8> & target_a)
|
||||
{
|
||||
auto peers (list ());
|
||||
while (peers.size () > target_a.size ())
|
||||
|
|
|
@ -150,7 +150,7 @@ namespace rai {
|
|||
bool deserialize (rai::stream &);
|
||||
void serialize (rai::stream &) override;
|
||||
bool operator == (rai::keepalive const &) const;
|
||||
std::array <rai::endpoint, 24> peers;
|
||||
std::array <rai::endpoint, 8> peers;
|
||||
rai::uint256_union checksum;
|
||||
};
|
||||
class publish : public message
|
||||
|
@ -439,7 +439,7 @@ namespace rai {
|
|||
void rpc_action (boost::system::error_code const &, size_t);
|
||||
void publish_block (rai::endpoint const &, std::unique_ptr <rai::block>);
|
||||
void confirm_block (std::unique_ptr <rai::block>, uint64_t);
|
||||
void merge_peers (std::array <rai::endpoint, 24> const &);
|
||||
void merge_peers (std::array <rai::endpoint, 8> const &);
|
||||
void maintain_keepalive (rai::endpoint const &);
|
||||
void send_confirm_req (rai::endpoint const &, rai::block const &);
|
||||
void send_buffer (uint8_t const *, size_t, rai::endpoint const &, std::function <void (boost::system::error_code const &, size_t)>);
|
||||
|
@ -549,7 +549,7 @@ namespace rai {
|
|||
bool known_peer (rai::endpoint const &);
|
||||
void incoming_from_peer (rai::endpoint const &);
|
||||
bool contacting_peer (rai::endpoint const &);
|
||||
void random_fill (std::array <rai::endpoint, 24> &);
|
||||
void random_fill (std::array <rai::endpoint, 8> &);
|
||||
std::vector <peer_information> list ();
|
||||
void refresh_action ();
|
||||
void queue_next_refresh ();
|
||||
|
|
|
@ -74,7 +74,7 @@ TEST (peer_container, split)
|
|||
TEST (peer_container, fill_random_clear)
|
||||
{
|
||||
rai::peer_container peers (rai::endpoint {});
|
||||
std::array <rai::endpoint, 24> target;
|
||||
std::array <rai::endpoint, 8> target;
|
||||
std::fill (target.begin (), target.end (), rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000));
|
||||
peers.random_fill (target);
|
||||
ASSERT_TRUE (std::all_of (target.begin (), target.end (), [] (rai::endpoint const & endpoint_a) {return endpoint_a == rai::endpoint (boost::asio::ip::address_v6::any (), 0); }));
|
||||
|
@ -87,7 +87,7 @@ TEST (peer_container, fill_random_full)
|
|||
{
|
||||
peers.incoming_from_peer (rai::endpoint (boost::asio::ip::address_v6::loopback (), i));
|
||||
}
|
||||
std::array <rai::endpoint, 24> target;
|
||||
std::array <rai::endpoint, 8> target;
|
||||
std::fill (target.begin (), target.end (), rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000));
|
||||
peers.random_fill (target);
|
||||
ASSERT_TRUE (std::none_of (target.begin (), target.end (), [] (rai::endpoint const & endpoint_a) {return endpoint_a == rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000); }));
|
||||
|
@ -96,14 +96,15 @@ TEST (peer_container, fill_random_full)
|
|||
TEST (peer_container, fill_random_part)
|
||||
{
|
||||
rai::peer_container peers (rai::endpoint {});
|
||||
for (auto i (0); i < 16; ++i)
|
||||
std::array <rai::endpoint, 8> target;
|
||||
auto half (target.size () / 2);
|
||||
for (auto i (0); i < half; ++i)
|
||||
{
|
||||
peers.incoming_from_peer (rai::endpoint (boost::asio::ip::address_v6::loopback (), i + 1));
|
||||
}
|
||||
std::array <rai::endpoint, 24> target;
|
||||
std::fill (target.begin (), target.end (), rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000));
|
||||
peers.random_fill (target);
|
||||
ASSERT_TRUE (std::none_of (target.begin (), target.begin () + 16, [] (rai::endpoint const & endpoint_a) {return endpoint_a == rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000); }));
|
||||
ASSERT_TRUE (std::none_of (target.begin (), target.begin () + 16, [] (rai::endpoint const & endpoint_a) {return endpoint_a == rai::endpoint (boost::asio::ip::address_v6::loopback (), 0); }));
|
||||
ASSERT_TRUE (std::all_of (target.begin () + 16, target.end (), [] (rai::endpoint const & endpoint_a) {return endpoint_a == rai::endpoint (boost::asio::ip::address_v6::any (), 0); }));
|
||||
ASSERT_TRUE (std::none_of (target.begin (), target.begin () + half, [] (rai::endpoint const & endpoint_a) {return endpoint_a == rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000); }));
|
||||
ASSERT_TRUE (std::none_of (target.begin (), target.begin () + half, [] (rai::endpoint const & endpoint_a) {return endpoint_a == rai::endpoint (boost::asio::ip::address_v6::loopback (), 0); }));
|
||||
ASSERT_TRUE (std::all_of (target.begin () + half, target.end (), [] (rai::endpoint const & endpoint_a) {return endpoint_a == rai::endpoint (boost::asio::ip::address_v6::any (), 0); }));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue