mirror of https://github.com/PurpleI2P/i2pd.git
I2P: End-to-End encrypted and anonymous Internet
https://i2pd.website/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
304 lines
16 KiB
304 lines
16 KiB
9 years ago
|
/*
|
||
|
* Copyright (c) 2013-2016, The PurpleI2P Project
|
||
|
*
|
||
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||
|
*
|
||
|
* See full license text in LICENSE file at top of project tree
|
||
|
*/
|
||
|
|
||
|
#include <cstdlib>
|
||
|
#include <iostream>
|
||
|
#include <fstream>
|
||
|
#include <map>
|
||
|
#include <string>
|
||
9 years ago
|
#include <boost/program_options/cmdline.hpp>
|
||
9 years ago
|
#include <boost/program_options/options_description.hpp>
|
||
|
#include <boost/program_options/parsers.hpp>
|
||
|
#include <boost/program_options/variables_map.hpp>
|
||
|
|
||
8 years ago
|
#include "Identity.h"
|
||
9 years ago
|
#include "Config.h"
|
||
|
#include "version.h"
|
||
|
|
||
|
using namespace boost::program_options;
|
||
|
|
||
|
namespace i2p {
|
||
|
namespace config {
|
||
|
options_description m_OptionsDesc;
|
||
|
variables_map m_Options;
|
||
|
|
||
|
void Init() {
|
||
9 years ago
|
|
||
9 years ago
|
options_description general("General options");
|
||
|
general.add_options()
|
||
9 years ago
|
("help", "Show this message")
|
||
9 years ago
|
("conf", value<std::string>()->default_value(""), "Path to main i2pd config file (default: try ~/.i2pd/i2pd.conf or /var/lib/i2pd/i2pd.conf)")
|
||
9 years ago
|
("tunconf", value<std::string>()->default_value(""), "Path to config with tunnels list and options (default: try ~/.i2pd/tunnels.conf or /var/lib/i2pd/tunnels.conf)")
|
||
9 years ago
|
("pidfile", value<std::string>()->default_value(""), "Path to pidfile (default: ~/i2pd/i2pd.pid or /var/lib/i2pd/i2pd.pid)")
|
||
9 years ago
|
("log", value<std::string>()->default_value(""), "Logs destination: stdout, file, syslog (stdout if not set)")
|
||
9 years ago
|
("logfile", value<std::string>()->default_value(""), "Path to logfile (stdout if not set, autodetect if daemon)")
|
||
9 years ago
|
("loglevel", value<std::string>()->default_value("info"), "Set the minimal level of log messages (debug, info, warn, error)")
|
||
9 years ago
|
("family", value<std::string>()->default_value(""), "Specify a family, router belongs to")
|
||
|
("datadir", value<std::string>()->default_value(""), "Path to storage of i2pd data (RI, keys, peer profiles, ...)")
|
||
9 years ago
|
("host", value<std::string>()->default_value("0.0.0.0"), "External IP")
|
||
8 years ago
|
("ifname", value<std::string>()->default_value(""), "Network interface to bind to")
|
||
8 years ago
|
("ifname4", value<std::string>()->default_value(""), "Network interface to bind to for ipv4")
|
||
|
("ifname6", value<std::string>()->default_value(""), "Network interface to bind to for ipv6")
|
||
8 years ago
|
("nat", value<bool>()->zero_tokens()->default_value(true), "Should we assume we are behind NAT?")
|
||
9 years ago
|
("port", value<uint16_t>()->default_value(0), "Port to listen for incoming connections (default: auto)")
|
||
9 years ago
|
("ipv4", value<bool>()->zero_tokens()->default_value(true), "Enable communication through ipv4")
|
||
9 years ago
|
("ipv6", value<bool>()->zero_tokens()->default_value(false), "Enable communication through ipv6")
|
||
8 years ago
|
("netid", value<int>()->default_value(I2PD_NET_ID), "Specify NetID. Main I2P is 2")
|
||
9 years ago
|
("daemon", value<bool>()->zero_tokens()->default_value(false), "Router will go to background after start")
|
||
|
("service", value<bool>()->zero_tokens()->default_value(false), "Router will use system folders like '/var/lib/i2pd'")
|
||
9 years ago
|
("notransit", value<bool>()->zero_tokens()->default_value(false), "Router will not accept transit tunnels at startup")
|
||
|
("floodfill", value<bool>()->zero_tokens()->default_value(false), "Router will be floodfill")
|
||
8 years ago
|
("bandwidth", value<std::string>()->default_value(""), "Bandwidth limit: integer in KBps or letters: L (32), O (256), P (2048), X (>9000)")
|
||
8 years ago
|
("ntcp", value<bool>()->zero_tokens()->default_value(true), "Enable NTCP transport")
|
||
|
("ssu", value<bool>()->zero_tokens()->default_value(true), "Enable SSU transport")
|
||
9 years ago
|
#ifdef _WIN32
|
||
|
("svcctl", value<std::string>()->default_value(""), "Windows service management ('install' or 'remove')")
|
||
9 years ago
|
("insomnia", value<bool>()->zero_tokens()->default_value(false), "Prevent system from sleeping")
|
||
9 years ago
|
("close", value<std::string>()->default_value("ask"), "Action on close: minimize, exit, ask") // TODO: add custom validator or something
|
||
9 years ago
|
#endif
|
||
9 years ago
|
;
|
||
8 years ago
|
|
||
9 years ago
|
options_description limits("Limits options");
|
||
|
limits.add_options()
|
||
8 years ago
|
("limits.coresize", value<uint32_t>()->default_value(0), "Maximum size of corefile in Kb (0 - use system limit)")
|
||
8 years ago
|
("limits.openfiles", value<uint16_t>()->default_value(0), "Maximum number of open files (0 - use system default)")
|
||
9 years ago
|
("limits.transittunnels", value<uint16_t>()->default_value(2500), "Maximum active transit sessions (default:2500)")
|
||
9 years ago
|
;
|
||
9 years ago
|
|
||
|
options_description httpserver("HTTP Server options");
|
||
|
httpserver.add_options()
|
||
|
("http.enabled", value<bool>()->default_value(true), "Enable or disable webconsole")
|
||
|
("http.address", value<std::string>()->default_value("127.0.0.1"), "Webconsole listen address")
|
||
|
("http.port", value<uint16_t>()->default_value(7070), "Webconsole listen port")
|
||
9 years ago
|
("http.auth", value<bool>()->default_value(false), "Enable Basic HTTP auth for webconsole")
|
||
|
("http.user", value<std::string>()->default_value("i2pd"), "Username for basic auth")
|
||
|
("http.pass", value<std::string>()->default_value(""), "Password for basic auth (default: random, see logs)")
|
||
9 years ago
|
;
|
||
|
|
||
|
options_description httpproxy("HTTP Proxy options");
|
||
|
httpproxy.add_options()
|
||
|
("httpproxy.enabled", value<bool>()->default_value(true), "Enable or disable HTTP Proxy")
|
||
|
("httpproxy.address", value<std::string>()->default_value("127.0.0.1"), "HTTP Proxy listen address")
|
||
9 years ago
|
("httpproxy.port", value<uint16_t>()->default_value(4444), "HTTP Proxy listen port")
|
||
9 years ago
|
("httpproxy.keys", value<std::string>()->default_value(""), "File to persist HTTP Proxy keys")
|
||
8 years ago
|
("httpproxy.signaturetype", value<i2p::data::SigningKeyType>()->default_value(i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519), "Signature type for new keys. 7 (EdDSA) by default")
|
||
8 years ago
|
("httpproxy.inbound.length", value<std::string>()->default_value("3"), "HTTP proxy inbound tunnel length")
|
||
|
("httpproxy.outbound.length", value<std::string>()->default_value("3"), "HTTP proxy outbound tunnel length")
|
||
|
("httpproxy.inbound.quantity", value<std::string>()->default_value("5"), "HTTP proxy inbound tunnels quantity")
|
||
8 years ago
|
("httpproxy.outbound.quantity", value<std::string>()->default_value("5"), "HTTP proxy outbound tunnels quantity")
|
||
8 years ago
|
("httpproxy.latency.min", value<std::string>()->default_value("0"), "HTTP proxy min latency for tunnels")
|
||
8 years ago
|
("httpproxy.latency.max", value<std::string>()->default_value("0"), "HTTP proxy max latency for tunnels")
|
||
|
("httpproxy.outproxy", value<std::string>()->default_value(""), "HTTP proxy upstream out proxy url")
|
||
8 years ago
|
("httpproxy.addresshelper", value<bool>()->default_value(true), "Enable or disable addresshelper")
|
||
9 years ago
|
;
|
||
|
|
||
|
options_description socksproxy("SOCKS Proxy options");
|
||
|
socksproxy.add_options()
|
||
|
("socksproxy.enabled", value<bool>()->default_value(true), "Enable or disable SOCKS Proxy")
|
||
|
("socksproxy.address", value<std::string>()->default_value("127.0.0.1"), "SOCKS Proxy listen address")
|
||
|
("socksproxy.port", value<uint16_t>()->default_value(4447), "SOCKS Proxy listen port")
|
||
9 years ago
|
("socksproxy.keys", value<std::string>()->default_value(""), "File to persist SOCKS Proxy keys")
|
||
8 years ago
|
("socksproxy.signaturetype", value<i2p::data::SigningKeyType>()->default_value(i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519), "Signature type for new keys. 7 (EdDSA) by default")
|
||
8 years ago
|
("socksproxy.inbound.length", value<std::string>()->default_value("3"), "SOCKS proxy inbound tunnel length")
|
||
|
("socksproxy.outbound.length", value<std::string>()->default_value("3"), "SOCKS proxy outbound tunnel length")
|
||
|
("socksproxy.inbound.quantity", value<std::string>()->default_value("5"), "SOCKS proxy inbound tunnels quantity")
|
||
8 years ago
|
("socksproxy.outbound.quantity", value<std::string>()->default_value("5"), "SOCKS proxy outbound tunnels quantity")
|
||
8 years ago
|
("socksproxy.latency.min", value<std::string>()->default_value("0"), "SOCKS proxy min latency for tunnels")
|
||
|
("socksproxy.latency.max", value<std::string>()->default_value("0"), "SOCKS proxy max latency for tunnels")
|
||
8 years ago
|
("socksproxy.outproxy", value<std::string>()->default_value("127.0.0.1"), "Upstream outproxy address for SOCKS Proxy")
|
||
9 years ago
|
("socksproxy.outproxyport", value<uint16_t>()->default_value(9050), "Upstream outproxy port for SOCKS Proxy")
|
||
9 years ago
|
;
|
||
|
|
||
|
options_description sam("SAM bridge options");
|
||
|
sam.add_options()
|
||
|
("sam.enabled", value<bool>()->default_value(false), "Enable or disable SAM Application bridge")
|
||
|
("sam.address", value<std::string>()->default_value("127.0.0.1"), "SAM listen address")
|
||
|
("sam.port", value<uint16_t>()->default_value(7656), "SAM listen port")
|
||
|
;
|
||
|
|
||
|
options_description bob("BOB options");
|
||
|
bob.add_options()
|
||
|
("bob.enabled", value<bool>()->default_value(false), "Enable or disable BOB command channel")
|
||
|
("bob.address", value<std::string>()->default_value("127.0.0.1"), "BOB listen address")
|
||
|
("bob.port", value<uint16_t>()->default_value(2827), "BOB listen port")
|
||
|
;
|
||
|
|
||
9 years ago
|
options_description i2cp("I2CP options");
|
||
9 years ago
|
i2cp.add_options()
|
||
9 years ago
|
("i2cp.enabled", value<bool>()->default_value(false), "Enable or disable I2CP")
|
||
|
("i2cp.address", value<std::string>()->default_value("127.0.0.1"), "I2CP listen address")
|
||
9 years ago
|
("i2cp.port", value<uint16_t>()->default_value(7654), "I2CP listen port")
|
||
9 years ago
|
;
|
||
|
|
||
9 years ago
|
options_description i2pcontrol("I2PControl options");
|
||
|
i2pcontrol.add_options()
|
||
|
("i2pcontrol.enabled", value<bool>()->default_value(false), "Enable or disable I2P Control Protocol")
|
||
|
("i2pcontrol.address", value<std::string>()->default_value("127.0.0.1"), "I2PCP listen address")
|
||
|
("i2pcontrol.port", value<uint16_t>()->default_value(7650), "I2PCP listen port")
|
||
9 years ago
|
("i2pcontrol.password", value<std::string>()->default_value("itoopie"), "I2PCP access password")
|
||
9 years ago
|
("i2pcontrol.cert", value<std::string>()->default_value("i2pcontrol.crt.pem"), "I2PCP connection cerificate")
|
||
|
("i2pcontrol.key", value<std::string>()->default_value("i2pcontrol.key.pem"), "I2PCP connection cerificate key")
|
||
9 years ago
|
;
|
||
|
|
||
9 years ago
|
bool upnp_default = false;
|
||
8 years ago
|
#if (defined(USE_UPNP) && (defined(WIN32_APP) || defined(ANDROID)))
|
||
9 years ago
|
upnp_default = true; // enable UPNP for windows GUI and android by default
|
||
|
#endif
|
||
|
options_description upnp("UPnP options");
|
||
|
upnp.add_options()
|
||
|
("upnp.enabled", value<bool>()->default_value(upnp_default), "Enable or disable UPnP: automatic port forwarding")
|
||
8 years ago
|
("upnp.name", value<std::string>()->default_value("I2Pd"), "Name i2pd appears in UPnP forwardings list")
|
||
9 years ago
|
;
|
||
|
|
||
9 years ago
|
options_description precomputation("Precomputation options");
|
||
|
precomputation.add_options()
|
||
|
("precomputation.elgamal",
|
||
|
#if defined(__x86_64__)
|
||
|
value<bool>()->default_value(false),
|
||
|
#else
|
||
|
value<bool>()->default_value(true),
|
||
|
#endif
|
||
|
"Enable or disable elgamal precomputation table")
|
||
|
;
|
||
8 years ago
|
|
||
|
options_description reseed("Reseed options");
|
||
|
reseed.add_options()
|
||
8 years ago
|
("reseed.verify", value<bool>()->default_value(false), "Verify .su3 signature")
|
||
8 years ago
|
("reseed.threshold", value<uint16_t>()->default_value(25), "Minimum number of known routers before requesting reseed")
|
||
8 years ago
|
("reseed.floodfill", value<std::string>()->default_value(""), "Path to router info of floodfill to reseed from")
|
||
8 years ago
|
("reseed.file", value<std::string>()->default_value(""), "Path to local .su3 file or HTTPS URL to reseed from")
|
||
8 years ago
|
("reseed.zipfile", value<std::string>()->default_value(""), "Path to local .zip file to reseed from")
|
||
8 years ago
|
("reseed.urls", value<std::string>()->default_value(
|
||
|
"https://reseed.i2p-projekt.de/,"
|
||
|
"https://i2p.mooo.com/netDb/,"
|
||
|
"https://netdb.i2p2.no/,"
|
||
8 years ago
|
// "https://us.reseed.i2p2.no:444/," // mamoth's shit
|
||
8 years ago
|
// "https://uk.reseed.i2p2.no:444/," // mamoth's shit
|
||
8 years ago
|
"https://i2p-0.manas.ca:8443/,"
|
||
|
"https://reseed.i2p.vzaws.com:8443/,"
|
||
|
"https://download.xxlspeed.com/,"
|
||
8 years ago
|
"https://reseed-ru.lngserv.ru/,"
|
||
8 years ago
|
"https://reseed.atomike.ninja/,"
|
||
8 years ago
|
"https://reseed.memcpy.io/,"
|
||
|
"https://reseed.onion.im/,"
|
||
8 years ago
|
"https://itoopie.atomike.ninja/,"
|
||
|
"https://randomrng.ddns.net/"
|
||
8 years ago
|
), "Reseed URLs, separated by comma")
|
||
8 years ago
|
;
|
||
|
|
||
8 years ago
|
options_description addressbook("AddressBook options");
|
||
|
addressbook.add_options()
|
||
|
("addressbook.defaulturl", value<std::string>()->default_value(
|
||
|
"http://joajgazyztfssty4w2on5oaqksz6tqoxbduy553y34mf4byv6gpq.b32.i2p/export/alive-hosts.txt"
|
||
|
), "AddressBook subscription URL for initial setup")
|
||
|
("addressbook.subscriptions", value<std::string>()->default_value(""),
|
||
|
"AddressBook subscriptions URLs, separated by comma");
|
||
|
|
||
8 years ago
|
options_description trust("Trust options");
|
||
|
trust.add_options()
|
||
8 years ago
|
("trust.enabled", value<bool>()->default_value(false), "Enable explicit trust options")
|
||
8 years ago
|
("trust.family", value<std::string>()->default_value(""), "Router Familiy to trust for first hops")
|
||
8 years ago
|
("trust.routers", value<std::string>()->default_value(""), "Only Connect to these routers")
|
||
8 years ago
|
("trust.hidden", value<bool>()->default_value(false), "Should we hide our router from other routers?");
|
||
8 years ago
|
|
||
8 years ago
|
options_description websocket("Websocket Options");
|
||
|
websocket.add_options()
|
||
|
("websockets.enabled", value<bool>()->default_value(false), "enable websocket server")
|
||
|
("websockets.address", value<std::string>()->default_value("127.0.0.1"), "address to bind websocket server on")
|
||
|
("websockets.port", value<uint16_t>()->default_value(7666), "port to bind websocket server on");
|
||
8 years ago
|
|
||
8 years ago
|
options_description exploratory("Exploratory Options");
|
||
|
exploratory.add_options()
|
||
|
("exploratory.inbound.length", value<int>()->default_value(2), "Exploratory inbound tunnel length")
|
||
|
("exploratory.outbound.length", value<int>()->default_value(2), "Exploratory outbound tunnel length")
|
||
|
("exploratory.inbound.quantity", value<int>()->default_value(3), "Exploratory inbound tunnels quantity")
|
||
|
("exploratory.outbound.quantity", value<int>()->default_value(3), "Exploratory outbound tunnels quantity");
|
||
|
|
||
9 years ago
|
m_OptionsDesc
|
||
|
.add(general)
|
||
9 years ago
|
.add(limits)
|
||
9 years ago
|
.add(httpserver)
|
||
|
.add(httpproxy)
|
||
|
.add(socksproxy)
|
||
|
.add(sam)
|
||
|
.add(bob)
|
||
9 years ago
|
.add(i2cp)
|
||
9 years ago
|
.add(i2pcontrol)
|
||
9 years ago
|
.add(upnp)
|
||
9 years ago
|
.add(precomputation)
|
||
8 years ago
|
.add(reseed)
|
||
8 years ago
|
.add(addressbook)
|
||
8 years ago
|
.add(trust)
|
||
|
.add(websocket)
|
||
8 years ago
|
.add(exploratory)
|
||
9 years ago
|
;
|
||
|
}
|
||
|
|
||
8 years ago
|
void ParseCmdline(int argc, char* argv[], bool ignoreUnknown)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
9 years ago
|
auto style = boost::program_options::command_line_style::unix_style
|
||
|
| boost::program_options::command_line_style::allow_long_disguise;
|
||
|
style &= ~ boost::program_options::command_line_style::allow_guessing;
|
||
8 years ago
|
if (ignoreUnknown)
|
||
|
store(command_line_parser(argc, argv).options(m_OptionsDesc).style (style).allow_unregistered().run(), m_Options);
|
||
|
else
|
||
|
store(parse_command_line(argc, argv, m_OptionsDesc, style), m_Options);
|
||
|
}
|
||
|
catch (boost::program_options::error& e)
|
||
|
{
|
||
9 years ago
|
std::cerr << "args: " << e.what() << std::endl;
|
||
|
exit(EXIT_FAILURE);
|
||
|
}
|
||
|
|
||
8 years ago
|
if (!ignoreUnknown && (m_Options.count("help") || m_Options.count("h")))
|
||
|
{
|
||
9 years ago
|
std::cout << "i2pd version " << I2PD_VERSION << " (" << I2P_VERSION << ")" << std::endl;
|
||
|
std::cout << m_OptionsDesc;
|
||
|
exit(EXIT_SUCCESS);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void ParseConfig(const std::string& path) {
|
||
9 years ago
|
if (path == "") return;
|
||
9 years ago
|
|
||
9 years ago
|
std::ifstream config(path, std::ios::in);
|
||
|
|
||
9 years ago
|
if (!config.is_open())
|
||
|
{
|
||
9 years ago
|
std::cerr << "missing/unreadable config file: " << path << std::endl;
|
||
|
exit(EXIT_FAILURE);
|
||
|
}
|
||
|
|
||
9 years ago
|
try
|
||
|
{
|
||
|
store(boost::program_options::parse_config_file(config, m_OptionsDesc), m_Options);
|
||
|
}
|
||
|
catch (boost::program_options::error& e)
|
||
|
{
|
||
9 years ago
|
std::cerr << e.what() << std::endl;
|
||
|
exit(EXIT_FAILURE);
|
||
|
};
|
||
|
}
|
||
|
|
||
|
void Finalize() {
|
||
|
notify(m_Options);
|
||
9 years ago
|
}
|
||
|
|
||
|
bool IsDefault(const char *name) {
|
||
|
if (!m_Options.count(name))
|
||
|
throw "try to check non-existent option";
|
||
|
|
||
|
if (m_Options[name].defaulted())
|
||
|
return true;
|
||
|
return false;
|
||
|
}
|
||
9 years ago
|
} // namespace config
|
||
|
} // namespace i2p
|