Skip to content

Commit

Permalink
Organize configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed May 15, 2024
1 parent 44da0ff commit b1780eb
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 167 deletions.
292 changes: 170 additions & 122 deletions console/executor.cpp

Large diffs are not rendered by default.

25 changes: 15 additions & 10 deletions console/executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class executor
std::ostream& error);

/// Invoke the menu command indicated by the metadata.
bool menu();
bool dispatch();

private:
enum menu : uint8_t
Expand All @@ -49,15 +49,16 @@ class executor
go,
hold,
info,
menu_,
test,
version,
work,
zeroize
};

using rotator_t = database::file::stream::out::rotator;

void logger(const auto& message) const;
void console(const auto& message) const;
void stopper(const auto& message);

static void initialize_stop() NOEXCEPT;
Expand All @@ -76,26 +77,28 @@ class executor
void dump_progress() const;
void dump_collisions() const;
void dump_options() const;
void dump_version() const;

// Store functions.
code open_store_coded(bool details=false);
bool open_store(bool details=false);
bool close_store(bool details=false);
bool create_store(bool details=false);
bool restore_store(bool details=false);
bool backup_store(bool details=false);
bool hot_backup_store(bool details=false);
bool cold_backup_store(bool details = false);
bool check_store_path(bool create=false) const;

// Command line options.
bool do_help();
bool do_version();
bool do_hardware();
bool do_settings();
bool do_version();
bool do_initchain();
bool do_new_store();
bool do_backup();
bool do_restore();
bool do_flags();
bool do_measure();
bool do_information();
bool do_slabs();
bool do_buckets();
bool do_collisions();
Expand All @@ -105,14 +108,16 @@ class executor

// Runtime options.
void do_hot_backup();
void do_hot_version();
void do_close();
void do_suspend();
void do_resume();
void do_reset_store();
void do_report_work();
void do_report_condition() const;
void do_information() const;
void do_menu() const;
void do_test() const;
void do_info() const;
void do_report_condition() const;

void scan_flags() const;
void measure_size() const;
Expand All @@ -135,11 +140,11 @@ class executor

// Runtime options.
static const std::unordered_map<std::string, uint8_t> options_;
static const std::unordered_map<uint8_t, std::string> menu_;
static const std::unordered_map<uint8_t, std::string> options_menu_;

// Runtime toggles.
static const std::unordered_map<std::string, uint8_t> toggles_;
static const std::unordered_map<uint8_t, std::string> display_;
static const std::unordered_map<uint8_t, std::string> toggles_menu_;
static const std::unordered_map<uint8_t, bool> defined_;

// Runtime events.
Expand Down
2 changes: 1 addition & 1 deletion console/localize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ namespace node {
#define BN_NODE_START_FAIL \
"Node failed to start with error '%1%'."
#define BN_NODE_UNAVAILABLE \
"Command not available until started."
"Command not available until node started."
#define BN_NODE_BACKUP_STARTED \
"Snapshot is started."
#define BN_NODE_BACKUP_FAIL \
Expand Down
2 changes: 1 addition & 1 deletion console/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,5 @@ int bc::system::main(int argc, char* argv[])
#endif

executor host(metadata, cin, cout, cerr);
return host.menu() ? 0 : -1;
return host.dispatch() ? 0 : -1;
}
12 changes: 6 additions & 6 deletions include/bitcoin/node/configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ namespace node {
#define BN_HARDWARE_VARIABLE "hardware"
#define BN_SETTINGS_VARIABLE "settings"
#define BN_VERSION_VARIABLE "version"
#define BN_INITCHAIN_VARIABLE "initchain"
#define BN_NEWSTORE_VARIABLE "newstore"
#define BN_BACKUP_VARIABLE "backup"
#define BN_RESTORE_VARIABLE "restore"

#define BN_FLAGS_VARIABLE "flags"
#define BN_MEASURE_VARIABLE "measure"
#define BN_SLABS_VARIABLE "slabs"
#define BN_BUCKETS_VARIABLE "buckets"
#define BN_COLLISIONS_VARIABLE "collisions"
#define BN_INFORMATION_VARIABLE "information"

#define BN_READ_VARIABLE "read"
#define BN_READ_VARIABLE "test"
#define BN_WRITE_VARIABLE "write"

// This must be lower case but the env var part can be any case.
Expand All @@ -69,19 +69,19 @@ class BCN_API configuration
bool version{};

/// Actions.
bool initchain{};
bool newstore{};
bool backup{};
bool restore{};

/// Chain scans.
bool flags{};
bool measure{};
bool information{};
bool slabs{};
bool buckets{};
bool collisions{};

/// Ad-hoc Testing.
bool read{};
bool test{};
bool write{};

/// Settings.
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/node/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class BCN_API settings
bool proxy;
bool remote;
bool fault;
bool quit;
bool quitting;
bool objects;
bool verbose;

Expand Down
34 changes: 17 additions & 17 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ options_metadata parser::load_options() THROWS
)
// Actions.
(
BN_INITCHAIN_VARIABLE ",i",
value<bool>(&configured.initchain)->
BN_NEWSTORE_VARIABLE ",n",
value<bool>(&configured.newstore)->
default_value(false)->zero_tokens(),
"Initialize store in configured directory."
"Create new store in configured directory."
)
(
BN_BACKUP_VARIABLE ",b",
Expand All @@ -176,7 +176,7 @@ options_metadata parser::load_options() THROWS
"Backup to a snapshot (can also do live)."
)
(
BN_RESTORE_VARIABLE ",x",
BN_RESTORE_VARIABLE ",r",
value<bool>(&configured.restore)->
default_value(false)->zero_tokens(),
"Restore from most recent snapshot."
Expand All @@ -188,12 +188,6 @@ options_metadata parser::load_options() THROWS
default_value(false)->zero_tokens(),
"Scan and display all flag transitions."
)
(
BN_MEASURE_VARIABLE ",m",
value<bool>(&configured.measure)->
default_value(false)->zero_tokens(),
"Scan and display store measures."
)
(
BN_SLABS_VARIABLE ",a",
value<bool>(&configured.slabs)->
Expand All @@ -212,18 +206,24 @@ options_metadata parser::load_options() THROWS
default_value(false)->zero_tokens(),
"Scan and display hashmap collision stats."
)
(
BN_INFORMATION_VARIABLE ",i",
value<bool>(&configured.information)->
default_value(false)->zero_tokens(),
"Scan and display store information."
)
// Ad-hoc Testing.
(
BN_READ_VARIABLE ",r",
value<bool>(&configured.read)->
BN_READ_VARIABLE ",t",
value<bool>(&configured.test)->
default_value(false)->zero_tokens(),
"Read test and display performance."
"Run built-in read test and display."
)
(
BN_WRITE_VARIABLE ",w",
value<bool>(&configured.write)->
default_value(false)->zero_tokens(),
"Write test and display performance."
"Run built-in write test and display."
);

return description;
Expand Down Expand Up @@ -987,9 +987,9 @@ options_metadata parser::load_settings() THROWS
#endif
#if defined(HAVE_LOGQ)
(
"log.quit",
value<bool>(&configured.log.quit),
"Enable quit logging, defaults to false."
"log.quitting",
value<bool>(&configured.log.quitting),
"Enable quitting logging, defaults to false."
)
#endif
#if defined(HAVE_LOGO)
Expand Down
2 changes: 1 addition & 1 deletion src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ settings::settings() NOEXCEPT
proxy{ false /*levels::proxy_defined*/ },
remote{ levels::remote_defined },
fault{ levels::fault_defined },
quit{ false /*levels::quit_defined*/ },
quitting{ false /*levels::quitting_defined*/ },
objects{ false /*levels::objects_defined*/ },
verbose{ false /*levels::verbose_defined*/ },
maximum_size{ 1'000'000_u32 }
Expand Down
15 changes: 8 additions & 7 deletions test/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,21 @@ BOOST_AUTO_TEST_SUITE(configuration_tests)
BOOST_AUTO_TEST_CASE(configuration__construct1__none_context__expected)
{
const node::configuration instance(chain::selection::none);

BOOST_REQUIRE(instance.file.empty());
BOOST_REQUIRE(!instance.help);
BOOST_REQUIRE(!instance.hardware);
BOOST_REQUIRE(!instance.settings);
BOOST_REQUIRE(!instance.version);
BOOST_REQUIRE(!instance.initchain);
BOOST_REQUIRE(!instance.newstore);
BOOST_REQUIRE(!instance.backup);
BOOST_REQUIRE(!instance.restore);
BOOST_REQUIRE(!instance.flags);
BOOST_REQUIRE(!instance.measure);
BOOST_REQUIRE(!instance.information);
BOOST_REQUIRE(!instance.slabs);
BOOST_REQUIRE(!instance.buckets);
BOOST_REQUIRE(!instance.collisions);
BOOST_REQUIRE(!instance.read);
BOOST_REQUIRE(!instance.test);
BOOST_REQUIRE(!instance.write);

BOOST_REQUIRE_EQUAL(instance.log.application, levels::application_defined);
Expand All @@ -49,18 +50,18 @@ BOOST_AUTO_TEST_CASE(configuration__construct1__none_context__expected)
BOOST_REQUIRE_EQUAL(instance.log.proxy, false /*levels::proxy_defined*/);
BOOST_REQUIRE_EQUAL(instance.log.remote, levels::remote_defined);
BOOST_REQUIRE_EQUAL(instance.log.fault, levels::fault_defined);
BOOST_REQUIRE_EQUAL(instance.log.quit, false /*levels::quit_defined*/);
BOOST_REQUIRE_EQUAL(instance.log.quitting, false /*levels::quitting_defined*/);
BOOST_REQUIRE_EQUAL(instance.log.objects, false /*levels::objects_defined*/);
BOOST_REQUIRE_EQUAL(instance.log.verbose, false /*levels::verbose_defined*/);

BOOST_REQUIRE_EQUAL(instance.log.maximum_size, 1'000'000_u32);
BOOST_REQUIRE_EQUAL(instance.log.log_file1(), "bn_end.log");
BOOST_REQUIRE_EQUAL(instance.log.log_file2(), "bn_begin.log");
BOOST_REQUIRE_EQUAL(instance.log.events_file(), "events.log");
BOOST_REQUIRE_EQUAL(instance.log.path, "");
#if defined(HAVE_MSC)
BOOST_REQUIRE_EQUAL(instance.log.symbols, "");
#endif
BOOST_REQUIRE_EQUAL(instance.log.log_file1(), "bn_end.log");
BOOST_REQUIRE_EQUAL(instance.log.log_file2(), "bn_begin.log");
BOOST_REQUIRE_EQUAL(instance.log.events_file(), "events.log");
}

BOOST_AUTO_TEST_SUITE_END()
2 changes: 1 addition & 1 deletion test/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ BOOST_AUTO_TEST_CASE(settings__log__default_context__expected)
BOOST_REQUIRE_EQUAL(log.proxy, false /*levels::proxy_defined*/);
BOOST_REQUIRE_EQUAL(log.remote, levels::remote_defined);
BOOST_REQUIRE_EQUAL(log.fault, levels::fault_defined);
BOOST_REQUIRE_EQUAL(log.quit, false /*levels::quit_defined*/);
BOOST_REQUIRE_EQUAL(log.quitting, false /*levels::quitting_defined*/);
BOOST_REQUIRE_EQUAL(log.objects, false /*levels::objects_defined*/);
BOOST_REQUIRE_EQUAL(log.verbose, false /*levels::verbose_defined*/);
BOOST_REQUIRE_EQUAL(log.maximum_size, 1'000'000_u32);
Expand Down

0 comments on commit b1780eb

Please sign in to comment.