Skip to content

Commit 32c3908

Browse files
committed
Derive server_node from full_node.
1 parent a5aaf40 commit 32c3908

3 files changed

Lines changed: 80 additions & 278 deletions

File tree

include/bitcoin/server/server_node.hpp

Lines changed: 28 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace libbitcoin {
3030
namespace server {
3131

3232
class BCS_API server_node
33-
/* : full_node */
33+
: public node::full_node
3434
{
3535
public:
3636
typedef std::function<void (size_t, const bc::block_type&)>
@@ -41,70 +41,49 @@ class BCS_API server_node
4141
server_node(settings_type& config);
4242
bool start(settings_type& config);
4343

44-
// Should only be called from the main thread.
45-
// It's an error to join() a thread from inside it.
46-
bool stop();
44+
virtual void subscribe_blocks(block_notify_callback notify_block);
45+
virtual void subscribe_transactions(transaction_notify_callback notify_tx);
4746

48-
void subscribe_blocks(block_notify_callback notify_block);
49-
void subscribe_transactions(transaction_notify_callback notify_tx);
50-
51-
// Access to underlying services.
52-
bc::chain::blockchain& blockchain();
53-
bc::chain::transaction_pool& transaction_pool();
54-
bc::node::indexer& transaction_indexer();
55-
bc::network::protocol& protocol();
47+
static void fullnode_fetch_history(server_node& node,
48+
const incoming_message& request, queue_send_callback queue_send);
5649

57-
// Threadpool for memory related operations.
58-
bc::threadpool& memory_related_threadpool();
50+
protected:
51+
// Result of store operation in transaction pool.
52+
virtual void new_unconfirm_valid_tx(const std::error_code& ec,
53+
const index_list& unconfirmed, const transaction_type& tx);
5954

60-
// TODO: use existing libbitcoin-node implementation.
61-
static void fullnode_fetch_history(server_node& node,
62-
const incoming_message& request, queue_send_callback queue_send);
55+
virtual void server_node::broadcast_new_blocks(const std::error_code& ec,
56+
uint32_t fork_point, const chain::blockchain::block_list& new_blocks,
57+
const chain::blockchain::block_list& replaced_blocks);
6358

6459
private:
6560
typedef std::vector<block_notify_callback> block_notify_list;
6661
typedef std::vector<transaction_notify_callback> transaction_notify_list;
6762

68-
void start_session();
69-
void wait_and_retry_start(const std::error_code& ec);
70-
71-
// New connection has been started.
72-
// Subscribe to new transaction messages from the network.
73-
void monitor_tx(const std::error_code& ec, bc::network::channel_ptr node);
63+
// Subscriptions for server API.
64+
block_notify_list block_sunscriptions_;
65+
transaction_notify_list tx_subscriptions_;
7466

75-
// New transaction message from the network.
76-
// Attempt to validate it by storing it in the transaction pool.
77-
void recv_transaction(const std::error_code& ec,
78-
const bc::transaction_type& tx, bc::network::channel_ptr node);
67+
// Logs.
68+
bc::ofstream outfile_;
69+
bc::ofstream errfile_;
7970

80-
// Result of store operation in transaction pool.
81-
void handle_mempool_store(const std::error_code& ec,
82-
const bc::index_list& unconfirmed, const bc::transaction_type& tx,
83-
bc::network::channel_ptr node);
84-
85-
void reorganize(const std::error_code& ec, size_t fork_point,
86-
const bc::chain::blockchain::block_list& new_blocks,
87-
const bc::chain::blockchain::block_list& replaced_blocks);
88-
89-
bc::ofstream outfile_, errfile_;
90-
91-
// Threadpools
92-
bc::threadpool network_pool_, disk_pool_, mem_pool_;
93-
94-
// Services
95-
bc::network::hosts hosts_;
71+
// Services.
72+
bc::threadpool network_threads_;
73+
bc::threadpool database_threads_;
74+
bc::threadpool memory_threads_;
75+
bc::network::hosts host_pool_;
9676
bc::network::handshake handshake_;
9777
bc::network::network network_;
9878
bc::network::protocol protocol_;
99-
bc::chain::blockchain_impl chain_;
79+
bc::chain::blockchain_impl blockchain_;
80+
bc::chain::transaction_pool tx_pool_;
81+
bc::node::indexer tx_indexer_;
10082
bc::node::poller poller_;
101-
bc::chain::transaction_pool txpool_;
102-
bc::node::indexer indexer_;
10383
bc::node::session session_;
84+
bc::node::responder responder_;
10485

105-
block_notify_list notify_blocks_;
106-
transaction_notify_list notify_txs_;
107-
86+
// Timer.
10887
boost::asio::deadline_timer retry_start_timer_;
10988
};
11089

0 commit comments

Comments
 (0)