Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

Commit

Permalink
Kovri: boost.program_options bool option overhaul
Browse files Browse the repository at this point in the history
Our boolean options were confusing and redundant. There was no
reason to `--enable 1` if the argument was true nor a reason to
`--disable 0` if the argument was also true, etc.

Removes the need to set boolean after enable/disable.
  • Loading branch information
anonimal committed May 31, 2018
1 parent de34ffc commit a16f0ce
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 128 deletions.
4 changes: 2 additions & 2 deletions contrib/python/example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

# Copyright (c) 2015-2017, The Kovri I2P Router Project
# Copyright (c) 2015-2018, The Kovri I2P Router Project
#
# All rights reserved.
#
Expand Down Expand Up @@ -29,7 +29,7 @@
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

root = "../../"
args = "--log-level 5 --enable-ssu 0"
args = "--log-level 5 --disable-ssu"

# Ensure kovri data dir is available
import subprocess
Expand Down
4 changes: 2 additions & 2 deletions contrib/testnet/monitoring/collect.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# Copyright (c) 2015-2017, The Kovri I2P Router Project
# Copyright (c) 2015-2018, The Kovri I2P Router Project
#
# All rights reserved.
#
Expand Down Expand Up @@ -43,7 +43,7 @@ while true; do
IFS=$'\n'

# Get statistics from kovri instances
stats=$(/usr/bin/kovri-util control stats --host $_host --log-to-console 0)
stats=$(/usr/bin/kovri-util control stats --host $_host --disable-console-log)
if [[ $? -ne 0 ]]; then
echo "Instance $_seq is not accessible"
continue
Expand Down
8 changes: 4 additions & 4 deletions contrib/testnet/testnet.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2015-2017, The Kovri I2P Router Project
# Copyright (c) 2015-2018, The Kovri I2P Router Project
#
# All rights reserved.
#
Expand Down Expand Up @@ -300,19 +300,19 @@ set_args()
# TODO(unassigned): *all* arguments (including sequence count, etc.)
# Set utility binary arguments
if [[ -z $KOVRI_UTIL_ARGS ]]; then
KOVRI_UTIL_ARGS="--floodfill 1 --bandwidth P"
KOVRI_UTIL_ARGS="--enable-floodfill --bandwidth P"
read_input "Change utility binary arguments? [KOVRI_UTIL_ARGS=\"${KOVRI_UTIL_ARGS}\"]" KOVRI_UTIL_ARGS
fi

# Set daemon binary arguments
if [[ -z $KOVRI_BIN_ARGS ]]; then
KOVRI_BIN_ARGS="--floodfill 1 --enable-su3-verification 0 --log-auto-flush 1 --enable-https 0"
KOVRI_BIN_ARGS="--enable-floodfill --disable-su3-verification --disable-https --enable-auto-flush-log"
read_input "Change kovri binary arguments? [KOVRI_BIN_ARGS=\"${KOVRI_BIN_ARGS}\"]" KOVRI_BIN_ARGS
fi

# Set firewalled daemon binary arguments
if [[ $KOVRI_NB_FW -gt 0 && -z $KOVRI_FW_BIN_ARGS ]]; then
KOVRI_FW_BIN_ARGS="--floodfill 0 --enable-su3-verification 0 --log-auto-flush 1"
KOVRI_FW_BIN_ARGS="--enable-floodfill --disable-su3-verification --enable-auto-flush-log"
read_input "Change firewalled kovri binary arguments? [KOVRI_FW_BIN_ARGS=\"${KOVRI_FW_BIN_ARGS}\"]" KOVRI_FW_BIN_ARGS
fi
}
Expand Down
103 changes: 52 additions & 51 deletions pkg/config/kovri.conf
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@
#port =

#
# Daemon mode
# ===========
# Enable daemon mode
# ==================
#
# 1 = enabled, 0 = disabled
# 1 = option enabled, 0 = option disabled
#
# Default: 0
#

daemon = 0
enable-daemon = 0

#
# Windows Service
Expand All @@ -75,26 +75,26 @@ daemon = 0
#service =

#
# Log to console
# ==============
# Disable logging to console
# ==========================
#
# 1 = enabled, 0 = disabled
# 1 = option enabled, 0 = option disabled
#
# Default: 1
# Default: 0
#

log-to-console = 1
disable-console-log = 0

#
# Log to file
# ===========
# Disable logging to file
# =======================
#
# 1 = enabled, 0 = disabled
# 1 = option enabled, 0 = option disabled
#
# Default: 1
# Default: 0
#

log-to-file = 1
disable-file-log = 0

#
# Log filename
Expand Down Expand Up @@ -132,26 +132,26 @@ log-to-file = 1
log-level = 3

#
# Auto flush log
# ==============
# Enable auto flush logging (write immediately to log file)
# =========================================================
#
# 1 = enabled, 0 = disabled
# 1 = option enabled, 0 = option disabled
#
# Default: 0
#

log-auto-flush = 0
enable-auto-flush-log = 0

#
# Enable console log color
# ==========================
# Disable console log color
# =========================
#
# 1 = color, 0 = no color
# 1 = option enabled, 0 = option disabled
#
# Default: 1
# Default: 0
#

log-enable-color = 1
disable-color-log = 0

#
# Tunnels Config
Expand All @@ -172,26 +172,26 @@ log-enable-color = 1
########################

#
# Enable IPv6
# ===========
# Enable IPv6 support
# ===================
#
# 1 = enabled, 0 = disabled
# 1 = option enabled, 0 = option disabled
#
# Default: 0
#

v6 = 0
enable-ipv6 = 0

#
# Enable router as floodfill
# ==========================
# Enable router as a floodfill router
# ===================================
#
# 1 = enabled, 0 = disabled
# 1 = option enabled, 0 = option disabled
#
# Default: 0
#

floodfill = 0
enable-floodfill = 0

#
# Bandwidth Caps
Expand All @@ -206,26 +206,26 @@ floodfill = 0
bandwidth = L

#
# Enable SSU Transport (UDP)
# Disable SSU Transport (UDP)
# ==========================
#
# 1 = enabled, 0 = disabled
# 1 = option enabled, 0 = option disabled
#
# Default: 1
# Default: 0
#

enable-ssu = 1
disable-ssu = 0

#
# Enable NTCP Transport (TCP)
# ==========================
# Disable NTCP Transport (TCP)
# ===========================
#
# 1 = enabled, 0 = disabled
# 1 = option enabled, 0 = option disabled
#
# Default: 1
# Default: 0
#

enable-ntcp = 1
disable-ntcp = 0

#
# File or URL from which to reseed
Expand All @@ -244,7 +244,7 @@ enable-ntcp = 1
#reseed-from =

#
# Enable SU3 Signature Verification
# Disable SU3 Signature Verification
# =================================
#
# WARNING: DO NOT DISABLE UNLESS YOU KNOW WHAT YOU'RE DOING!
Expand All @@ -253,32 +253,33 @@ enable-ntcp = 1
#
# Examples:
#
# ./kovri --enable-su3-verification 0 --reseed-from https://my.server.tld/i2pseeds.su3
# ./kovri --disable-su3-verification --reseed-from https://my.server.tld/i2pseeds.su3
#
# 1 = enabled, 0 = disabled
# 1 = option enabled, 0 = option disabled
#
# Default: 1
# Default: 0
#

enable-su3-verification = 1
disable-su3-verification = 0

# Enable HTTPS
# ============
#
# Disable HTTPS
# =============
#
# WARNING: DO NOT DISABLE UNLESS YOU KNOW WHAT YOU'RE DOING!
#
# Useful for custom reseed servers and/or custom subscription publishers
#
# Examples:
#
# ./kovri --enable-https 0 --reseed-from https://my.server.tld/i2pseeds.su3
# ./kovri --disable-https --reseed-from https://my.server.tld/i2pseeds.su3
#
# 1 = enabled, 0 = disabled
# 1 = option enabled, 0 = option disabled
#
# Default: 1
# Default: 0
#

enable-https = 1
disable-https = 0

#######################
### ###
Expand Down
4 changes: 2 additions & 2 deletions src/app/daemon.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** //
* Copyright (c) 2013-2017, The Kovri I2P Router Project //
* Copyright (c) 2013-2018, The Kovri I2P Router Project //
* //
* All rights reserved. //
* //
Expand Down Expand Up @@ -63,7 +63,7 @@ bool DaemonSingleton::Configure(const std::vector<std::string>& args)
core::Instance core(args);

// Set daemon mode (if applicable)
m_IsDaemon = core.GetConfig().GetMap().at("daemon").as<bool>();
m_IsDaemon = core.GetConfig().GetMap().at("enable-daemon").as<bool>();
#ifdef _WIN32
m_Service = core.GetConfig().GetMap().at("service").as<std::string>();
#endif
Expand Down
3 changes: 2 additions & 1 deletion src/client/reseed.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ bool Reseed::Start() {
SU3 su3(
m_Stream,
m_SigningKeys,
core::context.GetOpts()["enable-su3-verification"].as<bool>());
core::context.GetOpts()["disable-su3-verification"].as<bool>() ? false
: true);
if (!su3.SU3Impl()) {
LOG(error) << "Reseed: SU3 implementation failed";
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/client/util/http.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** //
* Copyright (c) 2013-2017, The Kovri I2P Router Project //
* Copyright (c) 2013-2018, The Kovri I2P Router Project //
* //
* All rights reserved. //
* //
Expand Down Expand Up @@ -117,7 +117,7 @@ bool HTTP::DownloadViaClearnet() {
LOG(debug) << "HTTP: Download Clearnet with timeout : "
<< kovri::core::GetType(Timeout::Request);
// Ensure that we only download from explicit TLS-enabled hosts
if (core::context.GetOpts()["enable-https"].as<bool>()) {
if (!core::context.GetOpts()["disable-https"].as<bool>()) {
const std::string cert = uri.host() + ".crt";
const boost::filesystem::path cert_path = core::GetPath(core::Path::TLS) / cert;
if (!boost::filesystem::exists(cert_path)) {
Expand Down
19 changes: 10 additions & 9 deletions src/core/router/context.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** //
* Copyright (c) 2013-2017, The Kovri I2P Router Project //
* Copyright (c) 2013-2018, The Kovri I2P Router Project //
* //
* All rights reserved. //
* //
Expand Down Expand Up @@ -84,8 +84,8 @@ void RouterContext::Initialize(const boost::program_options::variables_map& map)
: m_Opts["port"].as<int>();

// Set available transports
bool const has_ntcp = m_Opts["enable-ntcp"].as<bool>();
bool const has_ssu = m_Opts["enable-ssu"].as<bool>();
bool const has_ntcp(m_Opts["disable-ntcp"].as<bool>() ? false : true);
bool const has_ssu(m_Opts["disable-ssu"].as<bool>() ? false : true);

if (!has_ntcp && !has_ssu)
throw std::invalid_argument(
Expand Down Expand Up @@ -143,17 +143,17 @@ void RouterContext::Initialize(const boost::program_options::variables_map& map)
if (has_ntcp && !router.GetNTCPAddress(address.is_v6()))
{
LOG(debug)
<< "RouterContext: enable-ntcp present and no transport "
"found in existing routerInfo for host "
<< "RouterContext: NTCP was expected but no transport "
"was found in existing routerInfo for host "
<< host;
router.AddAddress(std::make_tuple(Transport::NTCP, host, port));
}
// SSU
if (has_ssu && !router.GetSSUAddress(address.is_v6()))
{
LOG(debug)
<< "RouterContext: enable-ssu present and no transport "
"found in existing routerInfo for host "
<< "RouterContext: SSU was expected but no transport "
"was found in existing routerInfo for host "
<< host;
router.AddAddress(
std::make_tuple(Transport::SSU, host, port),
Expand Down Expand Up @@ -195,10 +195,11 @@ void RouterContext::Initialize(const boost::program_options::variables_map& map)
LOG(debug) << "RouterContext: setting context RI traits";

// IPv6
m_Opts["v6"].as<bool>() ? m_RouterInfo.EnableV6() : m_RouterInfo.DisableV6();
m_Opts["enable-ipv6"].as<bool>() ? m_RouterInfo.EnableV6()
: m_RouterInfo.DisableV6();

// Floodfill
if (m_Opts["floodfill"].as<bool>())
if (m_Opts["enable-floodfill"].as<bool>())
{
m_RouterInfo.SetCaps(
m_RouterInfo.GetCaps() | core::RouterInfo::Cap::Floodfill);
Expand Down

0 comments on commit a16f0ce

Please sign in to comment.