Move block_deserializer to transport namespace

This commit is contained in:
Piotr Wójcik 2024-10-29 14:14:28 +01:00
commit b509b46045
2 changed files with 29 additions and 34 deletions

View file

@ -3,12 +3,12 @@
#include <nano/node/transport/block_deserializer.hpp> #include <nano/node/transport/block_deserializer.hpp>
#include <nano/node/transport/tcp_socket.hpp> #include <nano/node/transport/tcp_socket.hpp>
nano::bootstrap::block_deserializer::block_deserializer () : nano::transport::block_deserializer::block_deserializer () :
read_buffer{ std::make_shared<std::vector<uint8_t>> () } read_buffer{ std::make_shared<std::vector<uint8_t>> () }
{ {
} }
void nano::bootstrap::block_deserializer::read (nano::transport::tcp_socket & socket, callback_type const && callback) void nano::transport::block_deserializer::read (nano::transport::tcp_socket & socket, callback_type const && callback)
{ {
debug_assert (callback); debug_assert (callback);
read_buffer->resize (1); read_buffer->resize (1);
@ -27,7 +27,7 @@ void nano::bootstrap::block_deserializer::read (nano::transport::tcp_socket & so
}); });
} }
void nano::bootstrap::block_deserializer::received_type (nano::transport::tcp_socket & socket, callback_type const && callback) void nano::transport::block_deserializer::received_type (nano::transport::tcp_socket & socket, callback_type const && callback)
{ {
nano::block_type type = static_cast<nano::block_type> (read_buffer->data ()[0]); nano::block_type type = static_cast<nano::block_type> (read_buffer->data ()[0]);
if (type == nano::block_type::not_a_block) if (type == nano::block_type::not_a_block)
@ -57,7 +57,7 @@ void nano::bootstrap::block_deserializer::received_type (nano::transport::tcp_so
}); });
} }
void nano::bootstrap::block_deserializer::received_block (nano::block_type type, callback_type const && callback) void nano::transport::block_deserializer::received_block (nano::block_type type, callback_type const && callback)
{ {
nano::bufferstream stream{ read_buffer->data (), read_buffer->size () }; nano::bufferstream stream{ read_buffer->data (), read_buffer->size () };
auto block = nano::deserialize_block (stream, type); auto block = nano::deserialize_block (stream, type);

View file

@ -8,41 +8,36 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
namespace nano namespace nano::transport
{ {
class block; /**
* Class to read a block-type byte followed by a serialised block from a stream.
* It is typically used to read a series of block-types and blocks terminated by a not-a-block type.
*/
class block_deserializer : public std::enable_shared_from_this<block_deserializer>
{
public:
using callback_type = std::function<void (boost::system::error_code, std::shared_ptr<nano::block>)>;
namespace bootstrap block_deserializer ();
{
/** /**
* Class to read a block-type byte followed by a serialised block from a stream. * Read a type-prefixed block from 'socket' and pass the result, or an error, to 'callback'
* It is typically used to read a series of block-types and blocks terminated by a not-a-block type. * A normal end to series of blocks is a marked by return no error and a nullptr for block.
*/ */
class block_deserializer : public std::enable_shared_from_this<nano::bootstrap::block_deserializer> void read (nano::transport::tcp_socket & socket, callback_type const && callback);
{
public:
using callback_type = std::function<void (boost::system::error_code, std::shared_ptr<nano::block>)>;
block_deserializer (); private:
/** /**
* Read a type-prefixed block from 'socket' and pass the result, or an error, to 'callback' * Called by read method on receipt of a block type byte.
* A normal end to series of blocks is a marked by return no error and a nullptr for block. * The type byte will be in the read_buffer.
*/ */
void read (nano::transport::tcp_socket & socket, callback_type const && callback); void received_type (nano::transport::tcp_socket & socket, callback_type const && callback);
private: /**
/** * Called by received_type when a block is received, it parses the block and calls the callback.
* Called by read method on receipt of a block type byte. */
* The type byte will be in the read_buffer. void received_block (nano::block_type type, callback_type const && callback);
*/
void received_type (nano::transport::tcp_socket & socket, callback_type const && callback);
/** std::shared_ptr<std::vector<uint8_t>> read_buffer;
* Called by received_type when a block is received, it parses the block and calls the callback. };
*/
void received_block (nano::block_type type, callback_type const && callback);
std::shared_ptr<std::vector<uint8_t>> read_buffer;
};
}
} }