2016-01-20 00:00:00 +00:00
/*
2023-01-29 03:33:44 +00:00
* Copyright ( c ) 2013 - 2023 , The PurpleI2P Project
2016-01-20 00:00:00 +00:00
*
* 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>
2016-01-27 00:00:00 +00:00
# include <boost/program_options/cmdline.hpp>
2016-01-20 00:00:00 +00:00
# include <boost/program_options/options_description.hpp>
# include <boost/program_options/parsers.hpp>
# include <boost/program_options/variables_map.hpp>
2017-02-10 17:51:55 +00:00
# include "Identity.h"
2016-01-20 00:00:00 +00:00
# include "Config.h"
# include "version.h"
2021-03-11 11:39:33 +00:00
# include "Log.h"
2016-01-20 00:00:00 +00:00
using namespace boost : : program_options ;
namespace i2p {
namespace config {
2017-07-18 20:50:07 +00:00
options_description m_OptionsDesc ;
variables_map m_Options ;
void Init ( )
{
options_description general ( " General options " ) ;
general . add_options ( )
( " help " , " Show this message " )
2018-10-28 14:52:22 +00:00
( " version " , " Show i2pd version " )
2017-07-18 20:50:07 +00:00
( " conf " , value < std : : string > ( ) - > default_value ( " " ) , " Path to main i2pd config file (default: try ~/.i2pd/i2pd.conf or /var/lib/i2pd/i2pd.conf) " )
( " 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) " )
2020-04-28 21:56:43 +00:00
( " tunnelsdir " , value < std : : string > ( ) - > default_value ( " " ) , " Path to extra tunnels' configs folder (default: ~/.i2pd/tunnels.d or /var/lib/i2pd/tunnels.d " )
2021-06-18 03:38:10 +00:00
( " certsdir " , value < std : : string > ( ) - > default_value ( " " ) , " Path to certificates used for verifying .su3, families (default: ~/.i2pd/certificates or /var/lib/i2pd/certificates " )
2017-07-18 20:50:07 +00:00
( " pidfile " , value < std : : string > ( ) - > default_value ( " " ) , " Path to pidfile (default: ~/i2pd/i2pd.pid or /var/lib/i2pd/i2pd.pid) " )
( " log " , value < std : : string > ( ) - > default_value ( " " ) , " Logs destination: stdout, file, syslog (stdout if not set) " )
( " logfile " , value < std : : string > ( ) - > default_value ( " " ) , " Path to logfile (stdout if not set, autodetect if daemon) " )
2020-04-28 21:56:43 +00:00
( " loglevel " , value < std : : string > ( ) - > default_value ( " warn " ) , " Set the minimal level of log messages (debug, info, warn, error, none) " )
2018-06-20 02:07:24 +00:00
( " logclftime " , bool_switch ( ) - > default_value ( false ) , " Write full CLF-formatted date and time to log (default: disabled, write only time) " )
2017-07-18 20:50:07 +00:00
( " 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, ...) " )
2023-02-11 06:41:51 +00:00
( " host " , value < std : : string > ( ) - > default_value ( " " ) , " External IP " )
2017-07-18 20:50:07 +00:00
( " ifname " , value < std : : string > ( ) - > default_value ( " " ) , " Network interface to bind to " )
( " 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 " )
2020-11-14 22:31:20 +00:00
( " nat " , bool_switch ( ) - > default_value ( true ) , " Should we assume we are behind NAT? (default: enabled) " )
2017-07-18 20:50:07 +00:00
( " port " , value < uint16_t > ( ) - > default_value ( 0 ) , " Port to listen for incoming connections (default: auto) " )
2020-11-14 22:31:20 +00:00
( " ipv4 " , bool_switch ( ) - > default_value ( true ) , " Enable communication through ipv4 (default: enabled) " )
2021-02-27 00:31:38 +00:00
( " address4 " , value < std : : string > ( ) - > default_value ( " " ) , " Local address to bind ipv4 transport sockets to " )
2018-06-20 02:07:24 +00:00
( " ipv6 " , bool_switch ( ) - > default_value ( false ) , " Enable communication through ipv6 (default: disabled) " )
2021-02-27 00:31:38 +00:00
( " address6 " , value < std : : string > ( ) - > default_value ( " " ) , " Local address to bind ipv6 transport sockets to " )
2020-11-14 22:31:20 +00:00
( " reservedrange " , bool_switch ( ) - > default_value ( true ) , " Check remote RI for being in blacklist of reserved IP ranges (default: enabled) " )
2017-07-18 20:50:07 +00:00
( " netid " , value < int > ( ) - > default_value ( I2PD_NET_ID ) , " Specify NetID. Main I2P is 2 " )
2018-06-20 02:07:24 +00:00
( " daemon " , bool_switch ( ) - > default_value ( false ) , " Router will go to background after start (default: disabled) " )
( " service " , bool_switch ( ) - > default_value ( false ) , " Router will use system folders like '/var/lib/i2pd' (default: disabled) " )
( " notransit " , bool_switch ( ) - > default_value ( false ) , " Router will not accept transit tunnels at startup (default: disabled) " )
( " floodfill " , bool_switch ( ) - > default_value ( false ) , " Router will be floodfill (default: disabled) " )
2021-11-20 13:37:36 +00:00
( " bandwidth " , value < std : : string > ( ) - > default_value ( " " ) , " Transit traffic bandwidth limit: integer in KBps or letters: L (32), O (256), P (2048), X (>9000) " )
2018-06-16 20:06:01 +00:00
( " share " , value < int > ( ) - > default_value ( 100 ) , " Limit of transit traffic from max bandwidth in percents. (default: 100) " )
2021-05-20 18:10:31 +00:00
( " ntcp " , bool_switch ( ) - > default_value ( false ) , " Ignored. Always false " )
2022-11-23 00:29:20 +00:00
( " ssu " , bool_switch ( ) - > default_value ( false ) , " Ignored. Always false " )
2021-05-20 18:10:31 +00:00
( " ntcpproxy " , value < std : : string > ( ) - > default_value ( " " ) , " Ignored " )
2016-02-03 11:22:00 +00:00
# ifdef _WIN32
2021-05-20 18:10:31 +00:00
( " svcctl " , value < std : : string > ( ) - > default_value ( " " ) , " Ignored " )
2018-06-20 02:07:24 +00:00
( " insomnia " , bool_switch ( ) - > default_value ( false ) , " Prevent system from sleeping (default: disabled) " )
2018-06-16 15:11:46 +00:00
( " close " , value < std : : string > ( ) - > default_value ( " ask " ) , " Action on close: minimize, exit, ask " )
2016-02-03 11:22:00 +00:00
# endif
2017-07-18 20:50:07 +00:00
;
options_description limits ( " Limits options " ) ;
limits . add_options ( )
( " limits.coresize " , value < uint32_t > ( ) - > default_value ( 0 ) , " Maximum size of corefile in Kb (0 - use system limit) " )
( " limits.openfiles " , value < uint16_t > ( ) - > default_value ( 0 ) , " Maximum number of open files (0 - use system default) " )
2022-12-21 23:27:42 +00:00
( " limits.transittunnels " , value < uint16_t > ( ) - > default_value ( 5000 ) , " Maximum active transit tunnels (default:5000) " )
2022-06-06 14:43:53 +00:00
( " limits.ntcpsoft " , value < uint16_t > ( ) - > default_value ( 0 ) , " Ignored " )
( " limits.ntcphard " , value < uint16_t > ( ) - > default_value ( 0 ) , " Ignored " )
( " limits.ntcpthreads " , value < uint16_t > ( ) - > default_value ( 1 ) , " Ignored " )
2017-07-18 20:50:07 +00:00
;
options_description httpserver ( " HTTP Server options " ) ;
httpserver . add_options ( )
2018-06-16 19:38:59 +00:00
( " 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 " )
( " 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) " )
( " http.strictheaders " , value < bool > ( ) - > default_value ( true ) , " Enable strict host checking on WebUI " )
( " http.hostname " , value < std : : string > ( ) - > default_value ( " localhost " ) , " Expected hostname for WebUI " )
2020-04-28 21:56:43 +00:00
( " http.webroot " , value < std : : string > ( ) - > default_value ( " / " ) , " WebUI root path (default: / ) " )
2021-05-22 15:29:05 +00:00
( " http.lang " , value < std : : string > ( ) - > default_value ( " english " ) , " WebUI language (default: english ) " )
2023-02-01 16:14:56 +00:00
( " http.showTotalTCSR " , value < bool > ( ) - > default_value ( false ) , " Show additional value with total TCSR since router's start (default: false) " )
2017-07-18 20:50:07 +00:00
;
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 " )
( " httpproxy.port " , value < uint16_t > ( ) - > default_value ( 4444 ) , " HTTP Proxy listen port " )
2020-09-28 00:50:57 +00:00
( " httpproxy.keys " , value < std : : string > ( ) - > default_value ( " transient-proxy " ) , " File to persist HTTP Proxy keys. Transient by default " )
2020-04-30 01:44:13 +00:00
( " 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 " )
2017-07-18 20:50:07 +00:00
( " 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 " )
( " httpproxy.outbound.quantity " , value < std : : string > ( ) - > default_value ( " 5 " ) , " HTTP proxy outbound tunnels quantity " )
2022-03-08 03:20:11 +00:00
( " httpproxy.inbound.lengthVariance " , value < std : : string > ( ) - > default_value ( " 0 " ) , " HTTP proxy inbound tunnels length variance " )
( " httpproxy.outbound.lengthVariance " , value < std : : string > ( ) - > default_value ( " 0 " ) , " HTTP proxy outbound tunnels length variance " )
2017-07-18 20:50:07 +00:00
( " httpproxy.latency.min " , value < std : : string > ( ) - > default_value ( " 0 " ) , " HTTP proxy min latency for tunnels " )
( " 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 " )
( " httpproxy.addresshelper " , value < bool > ( ) - > default_value ( true ) , " Enable or disable addresshelper " )
2020-10-19 22:26:01 +00:00
( " httpproxy.i2cp.leaseSetType " , value < std : : string > ( ) - > default_value ( " 3 " ) , " Local destination's LeaseSet type " )
( " httpproxy.i2cp.leaseSetEncType " , value < std : : string > ( ) - > default_value ( " 0,4 " ) , " Local destination's LeaseSet encryption type " )
2021-05-20 18:10:31 +00:00
( " httpproxy.i2cp.leaseSetPrivKey " , value < std : : string > ( ) - > default_value ( " " ) , " LeaseSet private key " )
2017-07-18 20:50:07 +00:00
;
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 " )
2020-09-28 00:50:57 +00:00
( " socksproxy.keys " , value < std : : string > ( ) - > default_value ( " transient-proxy " ) , " File to persist SOCKS Proxy keys. Transient by default " )
2020-04-30 01:44:13 +00:00
( " 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 " )
2017-07-18 20:50:07 +00:00
( " 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 " )
( " socksproxy.outbound.quantity " , value < std : : string > ( ) - > default_value ( " 5 " ) , " SOCKS proxy outbound tunnels quantity " )
2022-03-08 03:20:11 +00:00
( " socksproxy.inbound.lengthVariance " , value < std : : string > ( ) - > default_value ( " 0 " ) , " SOCKS proxy inbound tunnels length variance " )
( " socksproxy.outbound.lengthVariance " , value < std : : string > ( ) - > default_value ( " 0 " ) , " SOCKS proxy outbound tunnels length variance " )
2017-07-18 20:50:07 +00:00
( " 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 " )
2017-07-18 21:21:02 +00:00
( " socksproxy.outproxy.enabled " , value < bool > ( ) - > default_value ( false ) , " Enable or disable SOCKS outproxy " )
2017-07-18 20:50:07 +00:00
( " socksproxy.outproxy " , value < std : : string > ( ) - > default_value ( " 127.0.0.1 " ) , " Upstream outproxy address for SOCKS Proxy " )
( " socksproxy.outproxyport " , value < uint16_t > ( ) - > default_value ( 9050 ) , " Upstream outproxy port for SOCKS Proxy " )
2020-10-19 22:26:01 +00:00
( " socksproxy.i2cp.leaseSetType " , value < std : : string > ( ) - > default_value ( " 3 " ) , " Local destination's LeaseSet type " )
( " socksproxy.i2cp.leaseSetEncType " , value < std : : string > ( ) - > default_value ( " 0,4 " ) , " Local destination's LeaseSet encryption type " )
2021-05-20 18:10:31 +00:00
( " socksproxy.i2cp.leaseSetPrivKey " , value < std : : string > ( ) - > default_value ( " " ) , " LeaseSet private key " )
2017-07-18 20:50:07 +00:00
;
options_description sam ( " SAM bridge options " ) ;
sam . add_options ( )
( " sam.enabled " , value < bool > ( ) - > default_value ( true ) , " 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 " )
2020-04-28 21:56:43 +00:00
( " sam.singlethread " , value < bool > ( ) - > default_value ( true ) , " Sessions run in the SAM bridge's thread " )
2017-07-18 20:50:07 +00:00
;
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 " )
;
options_description i2cp ( " I2CP options " ) ;
i2cp . add_options ( )
( " 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 " )
( " i2cp.port " , value < uint16_t > ( ) - > default_value ( 7654 ) , " I2CP listen port " )
2020-10-02 17:13:27 +00:00
( " i2cp.singlethread " , value < bool > ( ) - > default_value ( true ) , " Destinations run in the I2CP server's thread " )
2017-07-18 20:50:07 +00:00
;
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 " )
( " i2pcontrol.password " , value < std : : string > ( ) - > default_value ( " itoopie " ) , " I2PCP access password " )
2019-04-08 19:22:42 +00:00
( " i2pcontrol.cert " , value < std : : string > ( ) - > default_value ( " i2pcontrol.crt.pem " ) , " I2PCP connection certificate " )
( " i2pcontrol.key " , value < std : : string > ( ) - > default_value ( " i2pcontrol.key.pem " ) , " I2PCP connection certificate key " )
2017-07-18 20:50:07 +00:00
;
bool upnp_default = false ;
2016-07-20 13:33:50 +00:00
# if (defined(USE_UPNP) && (defined(WIN32_APP) || defined(ANDROID)))
2017-07-18 20:50:07 +00:00
upnp_default = true ; // enable UPNP for windows GUI and android by default
2016-07-13 15:12:51 +00:00
# endif
2017-07-18 20:50:07 +00:00
options_description upnp ( " UPnP options " ) ;
upnp . add_options ( )
( " upnp.enabled " , value < bool > ( ) - > default_value ( upnp_default ) , " Enable or disable UPnP: automatic port forwarding " )
2019-04-08 19:22:42 +00:00
( " upnp.name " , value < std : : string > ( ) - > default_value ( " I2Pd " ) , " Name i2pd appears in UPnP forwarding list " )
2017-07-18 20:50:07 +00:00
;
options_description precomputation ( " Precomputation options " ) ;
precomputation . add_options ( )
( " precomputation.elgamal " ,
2017-05-29 05:28:16 +00:00
# if defined(__x86_64__)
2017-07-18 20:50:07 +00:00
value < bool > ( ) - > default_value ( false ) ,
2016-04-17 20:57:58 +00:00
# else
2017-07-18 20:50:07 +00:00
value < bool > ( ) - > default_value ( true ) ,
2017-05-29 05:28:16 +00:00
# endif
2017-07-18 20:50:07 +00:00
" Enable or disable elgamal precomputation table " )
;
options_description reseed ( " Reseed options " ) ;
reseed . add_options ( )
( " reseed.verify " , value < bool > ( ) - > default_value ( false ) , " Verify .su3 signature " )
( " reseed.threshold " , value < uint16_t > ( ) - > default_value ( 25 ) , " Minimum number of known routers before requesting reseed " )
( " reseed.floodfill " , value < std : : string > ( ) - > default_value ( " " ) , " Path to router info of floodfill to reseed from " )
( " reseed.file " , value < std : : string > ( ) - > default_value ( " " ) , " Path to local .su3 file or HTTPS URL to reseed from " )
( " reseed.zipfile " , value < std : : string > ( ) - > default_value ( " " ) , " Path to local .zip file to reseed from " )
2017-11-18 14:50:05 +00:00
( " reseed.proxy " , value < std : : string > ( ) - > default_value ( " " ) , " url for reseed proxy, supports http/socks " )
2017-07-18 20:50:07 +00:00
( " reseed.urls " , value < std : : string > ( ) - > default_value (
2022-01-28 15:38:59 +00:00
" https://reseed2.i2p.net/, "
2020-11-21 16:45:06 +00:00
" https://reseed.diva.exchange/, "
2018-04-19 16:46:00 +00:00
" https://reseed-fr.i2pd.xyz/, "
2017-07-18 20:50:07 +00:00
" https://reseed.memcpy.io/, "
" https://reseed.onion.im/, "
2017-08-20 21:34:53 +00:00
" https://i2pseed.creativecowpat.net:8443/, "
2020-11-21 16:45:06 +00:00
" https://reseed.i2pgit.org/, "
2021-11-21 17:20:23 +00:00
" https://i2p.novg.net/, "
2022-02-28 21:23:52 +00:00
" https://banana.incognet.io/, "
2022-04-30 16:33:30 +00:00
" https://reseed-pl.i2pd.xyz/, "
" https://www2.mk16.de/ "
2017-07-18 20:50:07 +00:00
) , " Reseed URLs, separated by comma " )
2021-01-26 00:48:33 +00:00
( " reseed.yggurls " , value < std : : string > ( ) - > default_value (
2021-07-07 12:24:01 +00:00
" http://[324:71e:281a:9ed3::ace]:7070/, "
2021-11-21 17:20:23 +00:00
" http://[301:65b9:c7cd:9a36::1]:18801/, "
2021-12-13 18:47:59 +00:00
" http://[320:8936:ec1a:31f1::216]/, "
2022-02-28 21:23:52 +00:00
" http://[306:3834:97b9:a00a::1]/, "
" http://[316:f9e0:f22e:a74f::216]/ "
2021-03-11 11:39:33 +00:00
) , " Reseed URLs through the Yggdrasil, separated by comma " )
2017-07-18 20:50:07 +00:00
;
options_description addressbook ( " AddressBook options " ) ;
addressbook . add_options ( )
2022-05-27 17:17:06 +00:00
( " addressbook.enabled " , value < bool > ( ) - > default_value ( true ) , " Enable address book lookups and subscritions (default: enabled) " )
2017-07-18 20:50:07 +00:00
( " addressbook.defaulturl " , value < std : : string > ( ) - > default_value (
2021-01-27 03:48:35 +00:00
" http://shx5vqsw7usdaunyzr2qmes2fq37oumybpudrd4jjj4e4vk4uusa.b32.i2p/hosts.txt "
2017-07-18 20:50:07 +00:00
) , " AddressBook subscription URL for initial setup " )
2021-12-07 19:59:11 +00:00
( " addressbook.subscriptions " , value < std : : string > ( ) - > default_value (
" http://reg.i2p/hosts.txt "
) , " AddressBook subscriptions URLs, separated by comma " )
2021-03-11 11:39:33 +00:00
( " addressbook.hostsfile " , value < std : : string > ( ) - > default_value ( " " ) , " File to dump addresses in hosts.txt format " ) ;
2017-07-18 20:50:07 +00:00
options_description trust ( " Trust options " ) ;
trust . add_options ( )
( " trust.enabled " , value < bool > ( ) - > default_value ( false ) , " Enable explicit trust options " )
2021-03-11 11:39:33 +00:00
( " trust.family " , value < std : : string > ( ) - > default_value ( " " ) , " Router Family to trust for first hops " )
2016-10-28 16:50:26 +00:00
( " trust.routers " , value < std : : string > ( ) - > default_value ( " " ) , " Only Connect to these routers " )
2017-07-18 20:50:07 +00:00
( " trust.hidden " , value < bool > ( ) - > default_value ( false ) , " Should we hide our router from other routers? " )
;
2020-05-27 18:27:16 +00:00
// Save deprecated websocket options for compatibility
options_description websocket ( " Websocket Options " ) ;
websocket . add_options ( )
( " websockets.enabled " , value < bool > ( ) - > default_value ( false ) , " Deprecated option " )
( " websockets.address " , value < std : : string > ( ) - > default_value ( " " ) , " Deprecated option " )
( " websockets.port " , value < uint16_t > ( ) - > default_value ( 0 ) , " Deprecated option " )
;
2017-07-18 20:50:07 +00:00
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 " )
;
2018-07-19 13:45:24 +00:00
options_description ntcp2 ( " NTCP2 Options " ) ;
ntcp2 . add_options ( )
2020-04-28 21:56:43 +00:00
( " ntcp2.enabled " , value < bool > ( ) - > default_value ( true ) , " Enable NTCP2 (default: enabled) " )
( " ntcp2.published " , value < bool > ( ) - > default_value ( true ) , " Publish NTCP2 (default: enabled) " )
( " ntcp2.port " , value < uint16_t > ( ) - > default_value ( 0 ) , " Port to listen for incoming NTCP2 connections (default: auto) " )
2021-02-27 00:31:38 +00:00
( " ntcp2.addressv6 " , value < std : : string > ( ) - > default_value ( " :: " ) , " Address to publish NTCP2 with " )
2020-04-28 21:56:43 +00:00
( " ntcp2.proxy " , value < std : : string > ( ) - > default_value ( " " ) , " Proxy URL for NTCP2 transport " )
2018-07-19 13:45:24 +00:00
;
2022-03-13 02:40:12 +00:00
options_description ssu2 ( " SSU2 Options " ) ;
2022-05-25 12:37:36 +00:00
ssu2 . add_options ( )
2022-09-24 20:37:18 +00:00
( " ssu2.enabled " , value < bool > ( ) - > default_value ( true ) , " Enable SSU2 (default: enabled) " )
( " ssu2.published " , value < bool > ( ) - > default_value ( true ) , " Publish SSU2 (default: enabled) " )
2022-03-13 02:40:12 +00:00
( " ssu2.port " , value < uint16_t > ( ) - > default_value ( 0 ) , " Port to listen for incoming SSU2 packets (default: auto) " )
2022-10-31 22:11:36 +00:00
( " ssu2.mtu4 " , value < uint16_t > ( ) - > default_value ( 0 ) , " MTU for ipv4 address (default: detect) " )
( " ssu2.mtu6 " , value < uint16_t > ( ) - > default_value ( 0 ) , " MTU for ipv6 address (default: detect) " )
2022-10-26 20:05:40 +00:00
( " ssu2.proxy " , value < std : : string > ( ) - > default_value ( " " ) , " Socks5 proxy URL for SSU2 transport " )
2022-03-13 02:40:12 +00:00
;
2022-05-20 16:56:05 +00:00
2018-11-14 16:06:53 +00:00
options_description nettime ( " Time sync options " ) ;
nettime . add_options ( )
2023-02-10 14:58:42 +00:00
( " nettime.enabled " , value < bool > ( ) - > default_value ( false ) , " Enable NTP time sync (default: disabled) " )
2018-11-14 16:06:53 +00:00
( " nettime.ntpservers " , value < std : : string > ( ) - > default_value (
2018-11-14 16:47:50 +00:00
" 0.pool.ntp.org, "
" 1.pool.ntp.org, "
" 2.pool.ntp.org, "
" 3.pool.ntp.org "
2022-02-01 23:43:11 +00:00
) , " Comma separated list of NTP servers " )
2020-04-28 21:56:43 +00:00
( " nettime.ntpsyncinterval " , value < int > ( ) - > default_value ( 72 ) , " NTP sync interval in hours (default: 72) " )
2022-02-01 23:43:11 +00:00
( " nettime.frompeers " , value < bool > ( ) - > default_value ( true ) , " Sync clock from transport peers (default: enabled) " )
2018-11-14 16:06:53 +00:00
;
2018-11-21 21:13:23 +00:00
options_description persist ( " Network information persisting options " ) ;
persist . add_options ( )
2020-04-28 21:56:43 +00:00
( " persist.profiles " , value < bool > ( ) - > default_value ( true ) , " Persist peer profiles (default: true) " )
( " persist.addressbook " , value < bool > ( ) - > default_value ( true ) , " Persist full addresses (default: true) " )
2018-11-21 21:13:23 +00:00
;
2020-11-14 22:31:20 +00:00
options_description cpuext ( " CPU encryption extensions options " ) ;
cpuext . add_options ( )
( " cpuext.aesni " , bool_switch ( ) - > default_value ( true ) , " Use auto detection for AESNI CPU extensions. If false, AESNI will be not used " )
( " cpuext.avx " , bool_switch ( ) - > default_value ( true ) , " Use auto detection for AVX CPU extensions. If false, AVX will be not used " )
( " cpuext.force " , bool_switch ( ) - > default_value ( false ) , " Force usage of CPU extensions. Useful when cpuinfo is not available on virtual machines " )
;
2021-01-31 22:25:07 +00:00
options_description meshnets ( " Meshnet transports options " ) ;
meshnets . add_options ( )
2021-06-20 17:02:20 +00:00
( " meshnets.yggdrasil " , bool_switch ( ) - > default_value ( false ) , " Support transports through the Yggdrasil (default: false) " )
2021-03-11 11:39:33 +00:00
( " meshnets.yggaddress " , value < std : : string > ( ) - > default_value ( " " ) , " Yggdrasil address to publish " )
;
2022-06-25 15:54:54 +00:00
# ifdef __linux__
2022-06-25 22:38:42 +00:00
options_description unix_specific ( " UNIX-specific options " ) ;
unix_specific . add_options ( )
( " unix.handle_sigtstp " , bool_switch ( ) - > default_value ( false ) , " Handle SIGTSTP and SIGCONT signals (default: disabled) " )
;
2022-06-25 15:54:54 +00:00
# endif
2017-07-18 20:50:07 +00:00
m_OptionsDesc
. add ( general )
. add ( limits )
. add ( httpserver )
. add ( httpproxy )
. add ( socksproxy )
. add ( sam )
. add ( bob )
. add ( i2cp )
. add ( i2pcontrol )
. add ( upnp )
. add ( precomputation )
. add ( reseed )
. add ( addressbook )
. add ( trust )
2020-05-27 18:27:16 +00:00
. add ( websocket ) // deprecated
2017-07-18 20:50:07 +00:00
. add ( exploratory )
2018-07-19 13:45:24 +00:00
. add ( ntcp2 )
2022-03-13 02:40:12 +00:00
. add ( ssu2 )
2018-11-14 16:06:53 +00:00
. add ( nettime )
2018-11-21 21:13:23 +00:00
. add ( persist )
2020-11-14 22:31:20 +00:00
. add ( cpuext )
2021-01-31 22:25:07 +00:00
. add ( meshnets )
2022-06-25 15:54:54 +00:00
# ifdef __linux__
2022-06-25 22:38:42 +00:00
. add ( unix_specific )
2022-06-25 15:54:54 +00:00
# endif
2017-07-18 20:50:07 +00:00
;
}
void ParseCmdline ( int argc , char * argv [ ] , bool ignoreUnknown )
2017-03-29 14:51:32 +00:00
{
2017-07-18 20:50:07 +00:00
try
{
auto style = boost : : program_options : : command_line_style : : unix_style
2021-03-11 11:39:33 +00:00
| boost : : program_options : : command_line_style : : allow_long_disguise ;
2017-07-18 20:50:07 +00:00
style & = ~ boost : : program_options : : command_line_style : : allow_guessing ;
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 )
{
2021-03-11 11:39:33 +00:00
ThrowFatal ( " Error while parsing arguments: " , e . what ( ) ) ;
2017-07-18 20:50:07 +00:00
std : : cerr < < " args: " < < e . what ( ) < < std : : endl ;
exit ( EXIT_FAILURE ) ;
}
if ( ! ignoreUnknown & & ( m_Options . count ( " help " ) | | m_Options . count ( " h " ) ) )
{
std : : cout < < " i2pd version " < < I2PD_VERSION < < " ( " < < I2P_VERSION < < " ) " < < std : : endl ;
std : : cout < < m_OptionsDesc ;
exit ( EXIT_SUCCESS ) ;
2020-03-01 14:35:24 +00:00
}
2018-10-28 14:52:22 +00:00
else if ( m_Options . count ( " version " ) )
{
std : : cout < < " i2pd version " < < I2PD_VERSION < < " ( " < < I2P_VERSION < < " ) " < < std : : endl ;
2020-03-01 14:35:24 +00:00
std : : cout < < " Boost version "
2018-10-28 14:52:22 +00:00
< < BOOST_VERSION / 100000 < < " . " // maj. version
< < BOOST_VERSION / 100 % 1000 < < " . " // min. version
< < BOOST_VERSION % 100 // patch version
< < std : : endl ;
2020-03-01 14:35:24 +00:00
# if defined(OPENSSL_VERSION_TEXT)
2018-10-28 14:52:22 +00:00
std : : cout < < OPENSSL_VERSION_TEXT < < std : : endl ;
# endif
# if defined(LIBRESSL_VERSION_TEXT)
std : : cout < < LIBRESSL_VERSION_TEXT < < std : : endl ;
# endif
exit ( EXIT_SUCCESS ) ;
2017-07-18 20:50:07 +00:00
}
}
void ParseConfig ( const std : : string & path )
2017-03-29 14:51:32 +00:00
{
2017-07-18 20:50:07 +00:00
if ( path = = " " ) return ;
std : : ifstream config ( path , std : : ios : : in ) ;
if ( ! config . is_open ( ) )
{
2021-03-11 11:39:33 +00:00
ThrowFatal ( " Missing or unreadable config file: " , path ) ;
2017-07-18 20:50:07 +00:00
std : : cerr < < " missing/unreadable config file: " < < path < < std : : endl ;
exit ( EXIT_FAILURE ) ;
}
try
{
store ( boost : : program_options : : parse_config_file ( config , m_OptionsDesc ) , m_Options ) ;
}
catch ( boost : : program_options : : error & e )
{
2021-03-11 11:39:33 +00:00
ThrowFatal ( " Error while parsing config file: " , e . what ( ) ) ;
2017-07-18 20:50:07 +00:00
std : : cerr < < e . what ( ) < < std : : endl ;
exit ( EXIT_FAILURE ) ;
} ;
}
void Finalize ( )
2017-03-29 14:51:32 +00:00
{
2017-07-18 20:50:07 +00:00
notify ( m_Options ) ;
}
2016-01-20 00:00:00 +00:00
2017-07-18 20:50:07 +00:00
bool IsDefault ( const char * name )
{
if ( ! m_Options . count ( name ) )
throw " try to check non-existent option " ;
2016-01-24 11:04:41 +00:00
2017-07-18 20:50:07 +00:00
if ( m_Options [ name ] . defaulted ( ) )
return true ;
return false ;
}
2016-01-20 00:00:00 +00:00
2017-07-18 20:50:07 +00:00
bool GetOptionAsAny ( const char * name , boost : : any & value )
2016-02-11 15:54:36 +00:00
{
2017-07-18 20:50:07 +00:00
if ( ! m_Options . count ( name ) )
return false ;
value = m_Options [ name ] ;
return true ;
}
2016-01-20 00:00:00 +00:00
2017-07-18 20:50:07 +00:00
bool GetOptionAsAny ( const std : : string & name , boost : : any & value )
2016-02-11 15:54:36 +00:00
{
2017-07-18 20:50:07 +00:00
return GetOptionAsAny ( name . c_str ( ) , value ) ;
}
2017-03-14 12:34:01 +00:00
2016-01-20 00:00:00 +00:00
} // namespace config
} // namespace i2p