@@ -39,6 +39,9 @@ using std::placeholders::_4;
3939
4040const time_duration retry_start_duration = seconds(30 );
4141
42+ constexpr std::ofstream::openmode log_open_mode =
43+ std::ofstream::out | std::ofstream::app;
44+
4245static std::string make_log_string (log_level level,
4346 const std::string& domain, const std::string& body, bool log_requests)
4447{
@@ -71,16 +74,18 @@ void log_to_both(std::ostream& device, std::ofstream& file, log_level level,
7174}
7275
7376node_impl::node_impl (settings_type& config)
77+ : outfile_(config.debug_file.string(), log_open_mode),
78+ errfile_ (config.error_file.string(), log_open_mode),
7479 // Threadpools and the number of threads they spawn.
7580 // 6 threads spawned in total.
76- : network_pool_(1 ), disk_pool_(6 ), mem_pool_(1 ),
81+ network_pool_(1 ), disk_pool_(6 ), mem_pool_(1 ),
7782 // Networking related services.
7883 hosts_(network_pool_),
7984 handshake_(network_pool_),
8085 network_(network_pool_),
8186 protocol_(network_pool_, hosts_, handshake_, network_),
8287 // Blockchain database service.
83- chain_(disk_pool_, config.blockchain_path.generic_string (),
88+ chain_(disk_pool_, config.blockchain_path.string (),
8489 {config.history_height }),
8590 // Poll new blocks, tx memory pool and tx indexer.
8691 poller_ (mem_pool_, chain_),
@@ -95,27 +100,26 @@ node_impl::node_impl(settings_type& config)
95100
96101bool node_impl::start (settings_type& config)
97102{
98- auto file_mode = std::ofstream::out | std::ofstream::app;
99- outfile_.open (config.debug_file .generic_string (), file_mode);
100- errfile_.open (config.error_file .generic_string (), file_mode);
101103 log_debug ().set_output_function (
102104 std::bind (log_to_file, std::ref (outfile_),
103105 _1, _2, _3, config.log_requests ));
104106 log_info ().set_output_function (
105- std::bind (log_to_both, std::ref (std ::cout), std::ref (outfile_),
107+ std::bind (log_to_both, std::ref (bc ::cout), std::ref (outfile_),
106108 _1, _2, _3, config.log_requests ));
107109 log_warning ().set_output_function (
108110 std::bind (log_to_file, std::ref (errfile_),
109111 _1, _2, _3, config.log_requests ));
110112 log_error ().set_output_function (
111- std::bind (log_to_both, std::ref (std ::cerr), std::ref (errfile_),
113+ std::bind (log_to_both, std::ref (bc ::cerr), std::ref (errfile_),
112114 _1, _2, _3, config.log_requests ));
113115 log_fatal ().set_output_function (
114- std::bind (log_to_both, std::ref (std ::cerr), std::ref (errfile_),
116+ std::bind (log_to_both, std::ref (bc ::cerr), std::ref (errfile_),
115117 _1, _2, _3, config.log_requests ));
118+
116119 // Subscribe to new connections.
117120 protocol_.subscribe_channel (
118121 std::bind (&node_impl::monitor_tx, this , _1, _2));
122+
119123 // Start blockchain.
120124 if (!chain_.start ())
121125 {
@@ -124,24 +128,28 @@ bool node_impl::start(settings_type& config)
124128 }
125129 chain_.subscribe_reorganize (
126130 std::bind (&node_impl::reorganize, this , _1, _2, _3, _4));
131+
127132 // Start transaction pool
128133 txpool_.set_capacity (config.tx_pool_capacity );
129134 txpool_.start ();
135+
130136 // Outgoing connections setting in config file before we
131137 // start p2p network subsystem.
132138 int outgoing_connections = boost::lexical_cast<int >(
133139 config.out_connections );
134140 protocol_.set_max_outbound (outgoing_connections);
135- protocol_.set_hosts_filename (config.hosts_file .generic_string ());
141+ protocol_.set_hosts_filename (config.hosts_file .string ());
136142 if (!config.listener_enabled )
137143 protocol_.disable_listener ();
144+
138145 for (const auto & endpoint: config.peers )
139146 {
140147 log_info (LOG_NODE) << " Adding node: "
141148 << endpoint.get_host () << " " << endpoint.get_port ();
142149 protocol_.maintain_connection (endpoint.get_host (),
143150 endpoint.get_port ());
144151 }
152+
145153 start_session ();
146154 return true ;
147155}
0 commit comments