Skip to content

Commit

Permalink
Config: consolidate options + groupings. Refs monero-project#214
Browse files Browse the repository at this point in the history
- Cuts down number of groups down to:
  * system
  * network
  * client
- Removed confusing '-w' switch for '--help-with'
- Removed '-k' from proxykeys switch
- Minor style refactoring
  • Loading branch information
anonimal committed Aug 19, 2016
1 parent 87febb7 commit c7e54e6
Showing 1 changed file with 60 additions and 90 deletions.
150 changes: 60 additions & 90 deletions src/app/util/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ bool ParseArgs(
// TODO(unassigned): move this elsewhere (outside of ParseArgs()) when possible
size_t port = i2p::crypto::RandInRange<size_t>(9111, 30777);
// Map options values from CLI and config
bpo::options_description help("Help options");
bpo::options_description help("help");
help.add_options()
("help,h",

Expand All @@ -71,39 +71,45 @@ bool ParseArgs(

"Read kovri.conf and tunnels.conf for more options\n\n")

("help-with,w", bpo::value<std::string>(),
("help-with", bpo::value<std::string>(),

"Help with a specific option.\n\n"

"Available options:\n"
"==================\n\n"

"all | basic | system\n"
"network | proxy | i2pcs\n"
"reseed | config\n\n"
"all | system | network | client\n\n"

"Examples\n"
"========\n\n"

"List all options:\n\n"
"$ ./kovri -w all\n\n"
"$ ./kovri --help-with all\n\n"

"List only basic options:\n\n"
"$ ./kovri -w basic");
"List only system-related options:\n\n"
"$ ./kovri --help-with system");

bpo::options_description basic("\nBasic");
basic.add_options()
bpo::options_description system("\nsystem");
system.add_options()
("host", bpo::value<std::string>()->default_value("127.0.0.1"),
"The external IP (deprecated).\n"
"Default: external interface")

("port,p", bpo::value<int>()->default_value(port),
"Port to listen on.\n"
"Default: random (then saved to router.info)");
"Default: random (then saved to router.info)")

bpo::options_description system("\nSystem");
system.add_options()
("log-to-console", bpo::value<bool>()->default_value(true),
("daemon,d", bpo::value<bool>()->default_value(false),
"Enable or disable daemon mode\n"
"1 = enabled, 0 = disabled\n")

// TODO(unassigned): clarify what --service 'really' does
// See DaemonWin32.cpp
("service,s", bpo::value<bool>()->default_value(false),
"1 if using system folders, e.g.,\n"
"(/var/run/kovri.pid, /var/log/kovri.log, /var/lib/kovri)\n")

("log-to-console", bpo::value<bool>()->default_value(true),
"Enable or disable console log output\n"
"1 = enabled, 0 = disabled\n"
"Default: 1 = enabled\n")
Expand All @@ -129,35 +135,46 @@ bool ParseArgs(
"./kovri --log-levels warn error # warn/error only\n"
"Default: all levels [info warn error debug]\n")

("daemon,d", bpo::value<bool>()->default_value(0),
"Enable or disable daemon mode\n"
"1 = enabled, 0 = disabled\n")
("kovriconf,c", bpo::value<std::string>(&kovri_config)->default_value(
i2p::util::filesystem::GetFullPath("kovri.conf")),
"Options specified on the command line take"
"precedence over those in the config file.\n")

// TODO(unassigned): clarify what --service 'really' does
// See DaemonWin32.cpp
("service,s", bpo::value<bool>()->default_value(0),
"1 if using system folders, e.g.,\n"
"(/var/run/kovri.pid, /var/log/kovri.log, /var/lib/kovri)\n");
("tunnelsconf,t", bpo::value<std::string>(&tunnels_config)->default_value(
i2p::util::filesystem::GetFullPath("tunnels.conf")),
"Tunnels Config file\n");

bpo::options_description network("\nNetwork");
bpo::options_description network("\nnetwork");
network.add_options()
("v6,6", bpo::value<bool>()->default_value(0),
("v6,6", bpo::value<bool>()->default_value(false),
"1 to enable IPv6\n"
"1 = enabled, 0 = disabled\n")

("floodfill,f", bpo::value<bool>()->default_value(0),
("floodfill,f", bpo::value<bool>()->default_value(false),
"1 to enable router router as floodfill\n"
"1 = enabled, 0 = disabled\n")

("bandwidth,b", bpo::value<std::string>()->default_value("L"),
"L if bandwidth is limited to 32Kbs/sec, O if not\n"
"Always O if floodfill, otherwise L by default\n");
"Always O if floodfill, otherwise L by default\n")

("reseed-from,r", bpo::value<std::string>()->default_value(""),
"File or URL from which to reseed\n"
"Examples:\n"
"./kovri -r ~/local/path/to/i2pseeds.su3\n"
"./kovri -r https://my.server.tld/i2pseeds.su3\n"
"Note: if the server in your URL is not one of the "
"hard-coded reseed servers, either use --reseed-skip-ssl-check"
"or put your server's certificate in with the others. "
"They are located in the .kovri data directory\n")

("reseed-skip-ssl-check", bpo::value<bool>()->default_value(false),
"Skip SSL check for reseed host. Useful for custom reseed servers\n"
"Examples:\n"
"./kovri --reseed-skip-ssl-check -r https://my.server.tld/i2pseeds.su3\n");

// TODO(unassigned): do we want proxy/i2pcs options in CLI
// if we can redirect future multiple running instances
// of kovri to use unique config files per instance instead?
bpo::options_description proxy("\nProxy");
proxy.add_options()
bpo::options_description client("\nclient");
client.add_options()
("httpproxyport", bpo::value<int>()->default_value(4446),
"The HTTP Proxy port to listen on\n")

Expand All @@ -170,11 +187,9 @@ bool ParseArgs(
("socksproxyaddress", bpo::value<std::string>()->default_value("127.0.0.1"),
"The SOCKS Proxy address to listen on\n")

("proxykeys,k", bpo::value<std::string>()->default_value(""),
"Optional keys file for proxy's local destination\n");
("proxykeys", bpo::value<std::string>()->default_value(""),
"Optional keys file for proxy's local destination\n")

bpo::options_description i2pcs("\nI2P Control Service");
i2pcs.add_options()
("i2pcontrolport", bpo::value<int>()->default_value(0),
"Port of I2P control service (usually 7650)\n"
"I2PControl is disabled if not specified\n")
Expand All @@ -186,61 +201,26 @@ bool ParseArgs(
("i2pcontrolpassword", bpo::value<std::string>()->default_value("itoopie"),
"I2P control service password\n");

bpo::options_description reseed("\nReseed");
reseed.add_options()
("reseed-from,r", bpo::value<std::string>()->default_value(""),
"File or URL from which to reseed\n"
"Examples:\n"
"./kovri -r ~/local/path/to/i2pseeds.su3\n"
"./kovri -r https://my.server.tld/i2pseeds.su3\n"
"Note: if the server in your URL is not one of the "
"hard-coded reseed servers, either use --reseed-skip-ssl-check"
"or put your server's certificate in with the others. "
"They are located in the .kovri data directory\n")

("reseed-skip-ssl-check", bpo::value<bool>()->default_value(false),
"Skip SSL check for reseed host. Useful for custom reseed servers\n"
"Examples:\n"
"./kovri --reseed-skip-ssl-check -r https://my.server.tld/i2pseeds.su3\n");

//("reseed-to", bpo::value<std::string>()->default_value(""),
// "Creates a reseed file for you to share\n"
// "Example: ~/path/to/new/i2pseeds.su3\n")

bpo::options_description config("\nConfiguration");
config.add_options()
("kovriconf,c", bpo::value<std::string>(&kovri_config)->default_value(
i2p::util::filesystem::GetFullPath("kovri.conf")),
"Options specified on the command line take"
"precedence over those in the config file.\n")

("tunnelsconf,t", bpo::value<std::string>(&tunnels_config)->default_value(
i2p::util::filesystem::GetFullPath("tunnels.conf")),
"Tunnels Config file\n");
// Default visible option
bpo::options_description kovri("");
kovri.add(help);
// Available config file options
bpo::options_description config_options;
config_options
.add(basic)
.add(system)
.add(network)
.add(proxy)
.add(i2pcs)
.add(reseed)
.add(config);
.add(client);
// Available cli options
bpo::options_description cli_options;
cli_options
.add(help)
.add(basic)
.add(system)
.add(network)
.add(proxy)
.add(i2pcs)
.add(reseed)
.add(config);
.add(client);
// Map and store cli options
bpo::store(bpo::parse_command_line(argc, argv, cli_options), var_map);
bpo::notify(var_map);
Expand All @@ -249,33 +229,23 @@ bool ParseArgs(
// Set logging options
if (!SetLoggingOptions())
return false;
/*
* Display --help and --help-with
*/
// Display --help and --help-with
if (var_map.count("help")) {
std::cout << kovri << std::endl;
return false;
}
if (var_map.count("help-with")) {
const std::string& s = var_map["help-with"].as<std::string>();
if (s == "all") {
const std::string& help_option = var_map["help-with"].as<std::string>();
if (help_option == "all") {
std::cout << config_options; // We don't need .add(help)
} else if (s == "basic") {
std::cout << basic;
} else if (s == "system") {
} else if (help_option == "system") {
std::cout << system;
} else if (s == "network") {
} else if (help_option == "network") {
std::cout << network;
} else if (s == "proxy") {
std::cout << proxy;
} else if (s == "i2pcs") {
std::cout << i2pcs;
} else if (s == "reseed") {
std::cout << reseed;
} else if (s == "config") {
std::cout << config;
} else if (help_option == "client") {
std::cout << client;
} else {
std::cout << "Unknown option '" << s << "'"
std::cout << "Unknown option '" << help_option << "'"
<< "\nTry using --help" << std::endl;
}
return false;
Expand Down

0 comments on commit c7e54e6

Please sign in to comment.