From b509b4604560fdd0d37fb226ef76d54ceaaa4dd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Tue, 29 Oct 2024 14:14:28 +0100 Subject: [PATCH] Move `block_deserializer` to `transport` namespace --- nano/node/transport/block_deserializer.cpp | 8 ++-- nano/node/transport/block_deserializer.hpp | 55 ++++++++++------------ 2 files changed, 29 insertions(+), 34 deletions(-) diff --git a/nano/node/transport/block_deserializer.cpp b/nano/node/transport/block_deserializer.cpp index 61149eb39..6584d1b45 100644 --- a/nano/node/transport/block_deserializer.cpp +++ b/nano/node/transport/block_deserializer.cpp @@ -3,12 +3,12 @@ #include #include -nano::bootstrap::block_deserializer::block_deserializer () : +nano::transport::block_deserializer::block_deserializer () : read_buffer{ std::make_shared> () } { } -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); 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 (read_buffer->data ()[0]); 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 () }; auto block = nano::deserialize_block (stream, type); diff --git a/nano/node/transport/block_deserializer.hpp b/nano/node/transport/block_deserializer.hpp index dce67edf9..6280a7853 100644 --- a/nano/node/transport/block_deserializer.hpp +++ b/nano/node/transport/block_deserializer.hpp @@ -8,41 +8,36 @@ #include #include -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 +{ +public: + using callback_type = std::function)>; -namespace bootstrap -{ + block_deserializer (); /** - * 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. + * Read a type-prefixed block from 'socket' and pass the result, or an error, to 'callback' + * 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 - { - public: - using callback_type = std::function)>; + void read (nano::transport::tcp_socket & socket, callback_type const && callback); - block_deserializer (); - /** - * Read a type-prefixed block from 'socket' and pass the result, or an error, to 'callback' - * A normal end to series of blocks is a marked by return no error and a nullptr for block. - */ - void read (nano::transport::tcp_socket & socket, callback_type const && callback); +private: + /** + * Called by read method on receipt of a block type byte. + * The type byte will be in the read_buffer. + */ + void received_type (nano::transport::tcp_socket & socket, callback_type const && callback); - private: - /** - * Called by read method on receipt of a block type byte. - * The type byte will be in the read_buffer. - */ - void received_type (nano::transport::tcp_socket & socket, callback_type const && callback); + /** + * 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); - /** - * 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> read_buffer; - }; -} + std::shared_ptr> read_buffer; +}; }