Skip to content

Commit 7489c6d

Browse files
committed
Use bc stdio and fstream i/o wrappers, avoid boost generic path.
1 parent 96860e7 commit 7489c6d

File tree

7 files changed

+39
-26
lines changed

7 files changed

+39
-26
lines changed

src/config.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
*/
2020
#include "config.hpp"
2121

22-
#include <iostream>
2322
#include <string>
2423
#include <boost/filesystem.hpp>
2524
#include <boost/program_options.hpp>
@@ -79,11 +78,10 @@ static bool load_configuration_variables(variables_map& variables,
7978
error_code code;
8079
if (!config_path.empty() && exists(config_path, code))
8180
{
82-
const auto& path = config_path.generic_string();
83-
std::ifstream file(path);
81+
bc::ifstream file(config_path.string());
8482
if (!file.good())
8583
{
86-
BOOST_THROW_EXCEPTION(reading_file(path.c_str()));
84+
BOOST_THROW_EXCEPTION(reading_file(config_path.string().c_str()));
8785
}
8886

8987
const auto config = parse_config_file(file, config_settings);

src/echo.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
* You should have received a copy of the GNU Affero General Public License
1818
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
*/
20-
#include <iostream>
2120
#include "echo.hpp"
2221

22+
#include <iostream>
23+
#include <bitcoin/bitcoin.hpp>
24+
2325
namespace libbitcoin {
2426
namespace server {
2527

@@ -32,7 +34,7 @@ stdout_wrapper::stdout_wrapper(stdout_wrapper&& other)
3234
}
3335
stdout_wrapper::~stdout_wrapper()
3436
{
35-
std::cout << stream_.str() << std::endl;
37+
bc::cout << stream_.str() << std::endl;
3638
}
3739

3840
stdout_wrapper echo()

src/main.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/**
22
* Copyright (c) 2011-2015 libbitcoin developers (see AUTHORS)
33
*
44
* This file is part of libbitcoin-server.
@@ -17,16 +17,20 @@
1717
* You should have received a copy of the GNU Affero General Public License
1818
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
*/
20-
#include <iostream>
2120
#include <bitcoin/bitcoin.hpp>
2221
#include "server.hpp"
2322

23+
BC_USE_LIBBITCOIN_MAIN
24+
2425
/**
25-
* Server entry point.
26+
* Invoke this program with the raw arguments provided on the command line.
27+
* All console input and output streams for the application originate here.
28+
* @param argc The number of elements in the argv array.
29+
* @param argv The array of arguments, including the process.
30+
* @return The numeric result to return via console exit.
2631
*/
27-
int main(int argc, char* argv[])
32+
int bc::main(int argc, char* argv[])
2833
{
29-
// I/O injection.
3034
return bc::server::dispatch(argc, const_cast<const char**>(argv),
31-
std::cin, std::cout, std::cerr);
35+
bc::cin, bc::cout, bc::cerr);
3236
}

src/node_impl.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ using std::placeholders::_4;
3939

4040
const time_duration retry_start_duration = seconds(30);
4141

42+
constexpr std::ofstream::openmode log_open_mode =
43+
std::ofstream::out | std::ofstream::app;
44+
4245
static 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

7376
node_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

96101
bool 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
}

src/node_impl.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#ifndef LIBBITCOIN_SERVER_NODE_IMPL_HPP
2121
#define LIBBITCOIN_SERVER_NODE_IMPL_HPP
2222

23+
#include <bitcoin/bitcoin.hpp>
2324
#include <bitcoin/node.hpp>
2425
#include "settings.hpp"
2526

@@ -76,7 +77,7 @@ class node_impl
7677
const bc::chain::blockchain::block_list& new_blocks,
7778
const bc::chain::blockchain::block_list& replaced_blocks);
7879

79-
std::ofstream outfile_, errfile_;
80+
bc::ofstream outfile_, errfile_;
8081
// Threadpools
8182
bc::threadpool network_pool_, disk_pool_, mem_pool_;
8283
// Services

src/server.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ static console_result init_chain(path& directory, std::ostream& output,
154154
output << format(BS_INITIALIZING_CHAIN) % directory << std::endl;
155155

156156
using namespace bc::chain;
157-
const auto& prefix = directory.generic_string();
157+
const auto& prefix = directory.string();
158158
initialize_blockchain(prefix);
159159

160160
// Add genesis block.
@@ -191,7 +191,7 @@ static console_result verify_chain(path& directory, std::ostream& error)
191191
static bool stopped = false;
192192
static void interrupt_handler(int)
193193
{
194-
std::cout << BS_SERVER_STOPPING << std::endl;
194+
bc::cout << BS_SERVER_STOPPING << std::endl;
195195
stopped = true;
196196
}
197197

src/worker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ void request_worker::enable_crypto(settings_type& config)
107107
{
108108
std::string client_certs(CURVE_ALLOW_ANY);
109109
if (!config.client_certs_path.empty())
110-
client_certs = config.client_certs_path.generic_string();
110+
client_certs = config.client_certs_path.string();
111111
auth_.configure_curve("*", client_certs);
112-
czmqpp::certificate cert(config.cert_file.generic_string());
112+
czmqpp::certificate cert(config.cert_file.string());
113113
cert.apply(socket_);
114114
socket_.set_curve_server(zmq_curve_enabled);
115115
}

0 commit comments

Comments
 (0)