Move block_deserializer to transport namespace
This commit is contained in:
parent
81967f7945
commit
b509b46045
2 changed files with 29 additions and 34 deletions
|
|
@ -3,12 +3,12 @@
|
|||
#include <nano/node/transport/block_deserializer.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>> () }
|
||||
{
|
||||
}
|
||||
|
||||
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<nano::block_type> (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);
|
||||
|
|
|
|||
|
|
@ -8,41 +8,36 @@
|
|||
#include <memory>
|
||||
#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.
|
||||
* 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<nano::bootstrap::block_deserializer>
|
||||
{
|
||||
public:
|
||||
using callback_type = std::function<void (boost::system::error_code, std::shared_ptr<nano::block>)>;
|
||||
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<std::vector<uint8_t>> read_buffer;
|
||||
};
|
||||
}
|
||||
std::shared_ptr<std::vector<uint8_t>> read_buffer;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue