Message header extensions: remove unused flags (#1199)
This commit is contained in:
parent
b9fd61a631
commit
e974115872
3 changed files with 31 additions and 24 deletions
|
@ -42,9 +42,6 @@ TEST (message, publish_serialization)
|
|||
{
|
||||
rai::publish publish (std::make_shared<rai::send_block> (0, 1, 2, rai::keypair ().prv, 4, 5));
|
||||
ASSERT_EQ (rai::block_type::send, publish.header.block_type ());
|
||||
ASSERT_FALSE (publish.header.ipv4_only ());
|
||||
publish.header.ipv4_only_set (true);
|
||||
ASSERT_TRUE (publish.header.ipv4_only ());
|
||||
std::vector<uint8_t> bytes;
|
||||
{
|
||||
rai::vectorstream stream (bytes);
|
||||
|
@ -57,7 +54,7 @@ TEST (message, publish_serialization)
|
|||
ASSERT_EQ (rai::protocol_version, bytes[3]);
|
||||
ASSERT_EQ (rai::protocol_version_min, bytes[4]);
|
||||
ASSERT_EQ (static_cast<uint8_t> (rai::message_type::publish), bytes[5]);
|
||||
ASSERT_EQ (0x02, bytes[6]);
|
||||
ASSERT_EQ (0x00, bytes[6]); // extensions
|
||||
ASSERT_EQ (static_cast<uint8_t> (rai::block_type::send), bytes[7]);
|
||||
rai::bufferstream stream (bytes.data (), bytes.size ());
|
||||
auto error (false);
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
#include <rai/node/wallet.hpp>
|
||||
|
||||
std::array<uint8_t, 2> constexpr rai::message_header::magic_number;
|
||||
size_t constexpr rai::message_header::ipv4_only_position;
|
||||
size_t constexpr rai::message_header::bootstrap_server_position;
|
||||
std::bitset<16> constexpr rai::message_header::block_type_mask;
|
||||
|
||||
rai::message_header::message_header (rai::message_type type_a) :
|
||||
|
@ -74,16 +72,6 @@ void rai::message_header::block_type_set (rai::block_type type_a)
|
|||
extensions |= std::bitset<16> (static_cast<unsigned long long> (type_a) << 8);
|
||||
}
|
||||
|
||||
bool rai::message_header::ipv4_only ()
|
||||
{
|
||||
return extensions.test (ipv4_only_position);
|
||||
}
|
||||
|
||||
void rai::message_header::ipv4_only_set (bool value_a)
|
||||
{
|
||||
extensions.set (ipv4_only_position, value_a);
|
||||
}
|
||||
|
||||
// MTU - IP header - UDP header
|
||||
const size_t rai::message_parser::max_safe_udp_message_size = 508;
|
||||
|
||||
|
@ -742,11 +730,11 @@ response (response)
|
|||
{
|
||||
if (query)
|
||||
{
|
||||
header.extensions.set (query_flag);
|
||||
set_query_flag (true);
|
||||
}
|
||||
if (response)
|
||||
{
|
||||
header.extensions.set (response_flag);
|
||||
set_response_flag (true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -754,7 +742,7 @@ bool rai::node_id_handshake::deserialize (rai::stream & stream_a)
|
|||
{
|
||||
auto result (false);
|
||||
assert (header.type == rai::message_type::node_id_handshake);
|
||||
if (!result && header.extensions.test (query_flag))
|
||||
if (!result && is_query_flag ())
|
||||
{
|
||||
rai::uint256_union query_hash;
|
||||
result = read (stream_a, query_hash);
|
||||
|
@ -763,7 +751,7 @@ bool rai::node_id_handshake::deserialize (rai::stream & stream_a)
|
|||
query = query_hash;
|
||||
}
|
||||
}
|
||||
if (!result && header.extensions.test (response_flag))
|
||||
if (!result && is_response_flag ())
|
||||
{
|
||||
rai::account response_account;
|
||||
result = read (stream_a, response_account);
|
||||
|
@ -800,6 +788,26 @@ bool rai::node_id_handshake::operator== (rai::node_id_handshake const & other_a)
|
|||
return result;
|
||||
}
|
||||
|
||||
bool rai::node_id_handshake::is_query_flag () const
|
||||
{
|
||||
return header.extensions.test (query_flag);
|
||||
}
|
||||
|
||||
void rai::node_id_handshake::set_query_flag (bool value_a)
|
||||
{
|
||||
header.extensions.set (query_flag, value_a);
|
||||
}
|
||||
|
||||
bool rai::node_id_handshake::is_response_flag () const
|
||||
{
|
||||
return header.extensions.test (response_flag);
|
||||
}
|
||||
|
||||
void rai::node_id_handshake::set_response_flag (bool value_a)
|
||||
{
|
||||
header.extensions.set (response_flag, value_a);
|
||||
}
|
||||
|
||||
void rai::node_id_handshake::visit (rai::message_visitor & visitor_a) const
|
||||
{
|
||||
visitor_a.node_id_handshake (*this);
|
||||
|
|
|
@ -164,16 +164,14 @@ public:
|
|||
bool deserialize (rai::stream &);
|
||||
rai::block_type block_type () const;
|
||||
void block_type_set (rai::block_type);
|
||||
bool ipv4_only ();
|
||||
void ipv4_only_set (bool);
|
||||
static std::array<uint8_t, 2> constexpr magic_number = rai::rai_network == rai::rai_networks::rai_test_network ? std::array<uint8_t, 2>{ { 'R', 'A' } } : rai::rai_network == rai::rai_networks::rai_beta_network ? std::array<uint8_t, 2>{ { 'R', 'B' } } : std::array<uint8_t, 2>{ { 'R', 'C' } };
|
||||
uint8_t version_max;
|
||||
uint8_t version_using;
|
||||
uint8_t version_min;
|
||||
rai::message_type type;
|
||||
std::bitset<16> extensions;
|
||||
static size_t constexpr ipv4_only_position = 1;
|
||||
static size_t constexpr bootstrap_server_position = 2;
|
||||
//static size_t constexpr ipv4_only_position = 1; // Not in use, deprecated, was conflicting
|
||||
//static size_t constexpr bootstrap_server_position = 2; // Not in use, deprecated
|
||||
static std::bitset<16> constexpr block_type_mask = std::bitset<16> (0x0f00);
|
||||
inline bool valid_magic () const
|
||||
{
|
||||
|
@ -347,6 +345,10 @@ public:
|
|||
void serialize (rai::stream &) const override;
|
||||
void visit (rai::message_visitor &) const override;
|
||||
bool operator== (rai::node_id_handshake const &) const;
|
||||
bool is_query_flag () const;
|
||||
void set_query_flag (bool);
|
||||
bool is_response_flag () const;
|
||||
void set_response_flag (bool);
|
||||
boost::optional<rai::uint256_union> query;
|
||||
boost::optional<std::pair<rai::account, rai::signature>> response;
|
||||
static size_t constexpr query_flag = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue