Skip to content

Commit 6b33f40

Browse files
committed
Derive settings from node, use const, change listener setting.
1 parent b8cb6a7 commit 6b33f40

5 files changed

Lines changed: 41 additions & 59 deletions

File tree

data/bs.cfg

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
blockchain_path = blockchain
66
# The minimum height of the history database, defaults to 0.
77
history_height = 0
8-
# The peer cache file path, defaults to 'hosts'.
9-
hosts_file = hosts
10-
# Enable the listening for incoming connections, defaults to true.
11-
listener_enabled = true
8+
# The peer cache file path, defaults to 'peers'.
9+
hosts_file = peers
10+
# Set the port for incoming connections, set to 0 to disable listener, defaults to 8333 (18333 for testnet).
11+
# listen_port = 0
1212
# The maximum number of outgoing P2P network connections, defaults to 8.
1313
out_connections = 8
1414
# Enable the publisher, defaults to false.

include/bitcoin/server/config/settings.hpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <vector>
2626
#include <boost/filesystem.hpp>
2727
#include <boost/program_options.hpp>
28+
#include <bitcoin/node.hpp>
2829
#include <bitcoin/server/config/endpoint.hpp>
2930
#include <bitcoin/server/define.hpp>
3031

@@ -42,8 +43,11 @@
4243
namespace libbitcoin {
4344
namespace server {
4445

45-
struct BCS_API settings_type
46+
class BCS_API settings_type
47+
: public node::settings
4648
{
49+
public:
50+
4751
// options
4852
bool help;
4953
bool initchain;
@@ -55,22 +59,16 @@ struct BCS_API settings_type
5559

5660
// settings
5761
bool log_requests;
58-
bool listener_enabled;
5962
bool publisher_enabled;
60-
uint32_t tx_pool_capacity;
61-
uint32_t out_connections;
62-
uint32_t history_height;
6363
endpoint_type unique_name;
6464
endpoint_type service;
6565
endpoint_type heartbeat;
6666
endpoint_type tx_publish;
6767
endpoint_type block_publish;
68-
boost::filesystem::path hosts_file;
6968
boost::filesystem::path debug_file;
7069
boost::filesystem::path error_file;
7170
boost::filesystem::path cert_file;
7271
boost::filesystem::path client_certs_path;
73-
boost::filesystem::path blockchain_path;
7472
std::vector<endpoint_type> clients;
7573
std::vector<endpoint_type> peers;
7674
};

include/bitcoin/server/server_node.hpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class BCS_API server_node
3838
typedef std::function<void (const bc::transaction_type&)>
3939
transaction_notify_callback;
4040

41-
server_node(settings_type& config);
42-
bool start(settings_type& config);
41+
server_node(const settings_type& config);
42+
bool start(const settings_type& config);
4343

4444
virtual void subscribe_blocks(block_notify_callback notify_block);
4545
virtual void subscribe_transactions(transaction_notify_callback notify_tx);
@@ -68,20 +68,20 @@ class BCS_API server_node
6868
bc::ofstream outfile_;
6969
bc::ofstream errfile_;
7070

71-
// Services.
72-
bc::threadpool network_threads_;
73-
bc::threadpool database_threads_;
74-
bc::threadpool memory_threads_;
75-
bc::network::hosts host_pool_;
76-
bc::network::handshake handshake_;
77-
bc::network::network network_;
78-
bc::network::protocol protocol_;
79-
bc::chain::blockchain_impl blockchain_;
80-
bc::chain::transaction_pool tx_pool_;
81-
bc::node::indexer tx_indexer_;
82-
bc::node::poller poller_;
83-
bc::node::session session_;
84-
bc::node::responder responder_;
71+
//// Services.
72+
//bc::threadpool network_threads_;
73+
//bc::threadpool database_threads_;
74+
//bc::threadpool memory_threads_;
75+
//bc::network::hosts host_pool_;
76+
//bc::network::handshake handshake_;
77+
//bc::network::network network_;
78+
//bc::network::protocol protocol_;
79+
//bc::chain::blockchain_impl blockchain_;
80+
//bc::chain::transaction_pool tx_pool_;
81+
//bc::node::indexer tx_indexer_;
82+
//bc::node::poller poller_;
83+
//bc::node::session session_;
84+
//bc::node::responder responder_;
8585

8686
// Timer.
8787
boost::asio::deadline_timer retry_start_timer_;

src/config/settings.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020
#include <bitcoin/server/config/settings.hpp>
2121

22+
#include <cstdint>
2223
#include <iostream>
2324
#include <string>
2425
#include <vector>
@@ -133,29 +134,29 @@ const options_description config_type::load_settings()
133134
value<bool>(&settings.log_requests)->default_value(false),
134135
"Write service requests to the log, impacts performance, defaults to false."
135136
)
136-
(
137-
"general.listener_enabled",
138-
value<bool>(&settings.listener_enabled)->default_value(true),
139-
"Enable the listening for incoming connections, defaults to true."
140-
)
141137
(
142138
"general.publisher_enabled",
143139
value<bool>(&settings.publisher_enabled)->default_value(false),
144140
"Enable the publisher, defaults to false."
145141
)
142+
(
143+
"general.listen_port",
144+
value<uint16_t>(&settings.listen_port)->default_value(BN_LISTEN_PORT),
145+
"Set the port for incoming connections, set to 0 to disable listener, defaults to 8333 (18333 for testnet)."
146+
)
146147
(
147148
"general.tx_pool_capacity",
148-
value<uint32_t>(&settings.tx_pool_capacity)->default_value(2000),
149+
value<uint32_t>(&settings.tx_pool_capacity)->default_value(BN_P2P_TX_POOL),
149150
"The maximum number of transactions in the pool, defaults to 2000."
150151
)
151152
(
152153
"general.out_connections",
153-
value<uint32_t>(&settings.out_connections)->default_value(8),
154+
value<uint32_t>(&settings.out_connections)->default_value(BN_P2P_OUTBOUND),
154155
"The maximum number of outgoing P2P network connections, defaults to 8."
155156
)
156157
(
157158
"general.history_height",
158-
value<uint32_t>(&settings.history_height)->default_value(0),
159+
value<uint32_t>(&settings.history_height)->default_value(BN_HISTORY_START_HEIGHT),
159160
"The minimum height of the history database, defaults to 0."
160161
)
161162
(
@@ -185,8 +186,8 @@ const options_description config_type::load_settings()
185186
)
186187
(
187188
"general.hosts_file",
188-
value<path>(&settings.hosts_file)->default_value("hosts"),
189-
"The peer cache file path, defaults to 'hosts'."
189+
value<path>(&settings.hosts_file)->default_value(BN_HOSTS_FILENAME),
190+
"The peer cache file path, defaults to 'peers'."
190191
)
191192
(
192193
"logging.debug_file",
@@ -210,7 +211,7 @@ const options_description config_type::load_settings()
210211
)
211212
(
212213
"general.blockchain_path",
213-
value<path>(&settings.blockchain_path)->default_value("blockchain"),
214+
value<path>(&settings.blockchain_path)->default_value(BN_DIRECTORY),
214215
"The blockchain directory, defaults to 'blockchain'."
215216
)
216217
(

src/server_node.cpp

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,32 +38,15 @@ using std::placeholders::_2;
3838

3939
constexpr auto append = std::ofstream::out | std::ofstream::app;
4040

41-
server_node::server_node(settings_type& config)
42-
: outfile_(config.debug_file.string(), append),
41+
server_node::server_node(const settings_type& config)
42+
: full_node(config),
43+
outfile_(config.debug_file.string(), append),
4344
errfile_(config.error_file.string(), append),
44-
network_threads_(BN_THREADS_NETWORK, thread_priority::low),
45-
database_threads_(BN_THREADS_DISK, thread_priority::low),
46-
memory_threads_(BN_THREADS_MEMORY, thread_priority::low),
47-
host_pool_(network_threads_, config.hosts_file, BN_P2P_HOST_POOL),
48-
handshake_(network_threads_, BN_LISTEN_PORT),
49-
network_(network_threads_),
50-
protocol_(network_threads_, host_pool_, handshake_, network_,
51-
network::protocol::default_seeds,
52-
(config.listener_enabled ? BN_LISTEN_PORT : 0),
53-
config.out_connections),
54-
blockchain_(database_threads_, config.blockchain_path.string(),
55-
{ config.history_height }, BN_P2P_ORPHAN_POOL),
56-
tx_pool_(memory_threads_, blockchain_, config.tx_pool_capacity),
57-
tx_indexer_(memory_threads_),
58-
poller_(memory_threads_, blockchain_),
59-
responder_(blockchain_, tx_pool_),
60-
session_(network_threads_, handshake_, protocol_, blockchain_, poller_,
61-
tx_pool_, responder_),
6245
retry_start_timer_(memory_threads_.service())
6346
{
6447
}
6548

66-
bool server_node::start(settings_type& config)
49+
bool server_node::start(const settings_type& config)
6750
{
6851
// Set up logging for node background threads (add to config).
6952
const auto skip_log = if_else(config.log_requests, "", LOG_REQUEST);

0 commit comments

Comments
 (0)