From 0305e4cf8a1f2555558875d2d8e5a9d476b363c7 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 3 Nov 2016 15:28:33 -0400 Subject: [PATCH] tunnel options for SOCKS proxy --- ClientContext.cpp | 37 +++++++++++++++++++++++++------------ ClientContext.h | 3 ++- Config.cpp | 6 +++++- Config.h | 8 +++++++- docs/configuration.md | 14 +++++++++----- 5 files changed, 48 insertions(+), 20 deletions(-) diff --git a/ClientContext.cpp b/ClientContext.cpp index a50f0e45..4639ec05 100644 --- a/ClientContext.cpp +++ b/ClientContext.cpp @@ -55,15 +55,7 @@ namespace client if(LoadPrivateKeys (keys, httpProxyKeys)) { std::map params; - std::string value; - if (i2p::config::GetOption("httpproxy.inbound.length", value)) - params["inbound.length"] = value; - if (i2p::config::GetOption("httpproxy.inbound.quantity", value)) - params["inbound.quantity"] = value; - if (i2p::config::GetOption("httpproxy.outbound.length", value)) - params["outbound.length"] = value; - if (i2p::config::GetOption("httpproxy.outbound.quantity", value)) - params["outbound.quantity"] = value; + ReadI2CPOptionsFromConfig ("httpproxy.", params); localDestination = CreateNewLocalDestination (keys, false, ¶ms); } else @@ -77,8 +69,10 @@ namespace client } } + localDestination = nullptr; bool socksproxy; i2p::config::GetOption("socksproxy.enabled", socksproxy); - if (socksproxy) { + if (socksproxy) + { std::string socksProxyKeys; i2p::config::GetOption("socksproxy.keys", socksProxyKeys); std::string socksProxyAddr; i2p::config::GetOption("socksproxy.address", socksProxyAddr); uint16_t socksProxyPort; i2p::config::GetOption("socksproxy.port", socksProxyPort); @@ -88,8 +82,14 @@ namespace client if (socksProxyKeys.length () > 0) { i2p::data::PrivateKeys keys; - LoadPrivateKeys (keys, socksProxyKeys); - localDestination = CreateNewLocalDestination (keys, false); + if (LoadPrivateKeys (keys, socksProxyKeys)) + { + std::map params; + ReadI2CPOptionsFromConfig ("socksproxy.", params); + localDestination = CreateNewLocalDestination (keys, false, ¶ms); + } + else + LogPrint(eLogError, "Clients: failed to load SOCKS Proxy key"); } try { m_SocksProxy = new i2p::proxy::SOCKSProxy(socksProxyAddr, socksProxyPort, socksOutProxyAddr, socksOutProxyPort, localDestination); @@ -374,6 +374,19 @@ namespace client options[I2CP_PARAM_TAGS_TO_SEND] = GetI2CPOption (section, I2CP_PARAM_TAGS_TO_SEND, DEFAULT_TAGS_TO_SEND); } + void ClientContext::ReadI2CPOptionsFromConfig (const std::string& prefix, std::map& options) const + { + std::string value; + if (i2p::config::GetOption(prefix + I2CP_PARAM_INBOUND_TUNNEL_LENGTH, value)) + options[I2CP_PARAM_INBOUND_TUNNEL_LENGTH] = value; + if (i2p::config::GetOption(prefix + I2CP_PARAM_INBOUND_TUNNELS_QUANTITY, value)) + options[I2CP_PARAM_INBOUND_TUNNELS_QUANTITY] = value; + if (i2p::config::GetOption(prefix + I2CP_PARAM_OUTBOUND_TUNNEL_LENGTH, value)) + options[I2CP_PARAM_OUTBOUND_TUNNEL_LENGTH] = value; + if (i2p::config::GetOption(prefix + I2CP_PARAM_OUTBOUND_TUNNELS_QUANTITY, value)) + options[I2CP_PARAM_OUTBOUND_TUNNELS_QUANTITY] = value; + } + void ClientContext::ReadTunnels () { boost::property_tree::ptree pt; diff --git a/ClientContext.h b/ClientContext.h index 356f28c4..73001934 100644 --- a/ClientContext.h +++ b/ClientContext.h @@ -75,7 +75,8 @@ namespace client template std::string GetI2CPOption (const Section& section, const std::string& name, const Type& value) const; template - void ReadI2CPOptions (const Section& section, std::map& options) const; + void ReadI2CPOptions (const Section& section, std::map& options) const; + void ReadI2CPOptionsFromConfig (const std::string& prefix, std::map& options) const; void CleanupUDP(const boost::system::error_code & ecode); void ScheduleCleanupUDP(); diff --git a/Config.cpp b/Config.cpp index ba7d0f23..000bc3f2 100644 --- a/Config.cpp +++ b/Config.cpp @@ -93,7 +93,11 @@ namespace config { ("socksproxy.address", value()->default_value("127.0.0.1"), "SOCKS Proxy listen address") ("socksproxy.port", value()->default_value(4447), "SOCKS Proxy listen port") ("socksproxy.keys", value()->default_value(""), "File to persist SOCKS Proxy keys") - ("socksproxy.outproxy", value()->default_value("127.0.0.1"), "Upstream outproxy address for SOCKS Proxy") + ("socksproxy.inbound.length", value()->default_value("3"), "SOCKS proxy inbound tunnel length") + ("socksproxy.outbound.length", value()->default_value("3"), "SOCKS proxy outbound tunnel length") + ("socksproxy.inbound.quantity", value()->default_value("5"), "SOCKS proxy inbound tunnels quantity") + ("socksproxy.outbound.quantity", value()->default_value("5"), "SOCKS proxy outbound tunnels quantity") + ("socksproxy.outproxy", value()->default_value("127.0.0.1"), "Upstream outproxy address for SOCKS Proxy") ("socksproxy.outproxyport", value()->default_value(9050), "Upstream outproxy port for SOCKS Proxy") ; diff --git a/Config.h b/Config.h index 6b2af717..595331cd 100644 --- a/Config.h +++ b/Config.h @@ -78,6 +78,12 @@ namespace config { return true; } + template + bool GetOption(const std::string& name, T& value) + { + return GetOption (name.c_str (), value); + } + /** * @brief Set value of given parameter * @param name Name of settable parameter @@ -93,7 +99,7 @@ namespace config { m_Options.at(name).value() = value; notify(m_Options); return true; - } + } /** * @brief Check is value explicitly given or default diff --git a/docs/configuration.md b/docs/configuration.md index 62dded11..7e99dcb2 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -50,12 +50,16 @@ All options below still possible in cmdline, but better write it in config file: * --httpproxy.outbound.length= - Outbound tunnels length if keys is set. 3 by default * --httpproxy.outbound.quantity= - Outbound tunnels quantity if keys is set. 5 by default -* --socksproxy.address= - The address to listen on (SOCKS Proxy) -* --socksproxy.port= - The port to listen on (SOCKS Proxy). 4447 by default +* --socksproxy.enabled= - If SOCKS proxy is enabled. true by default +* --socksproxy.address= - The address to listen on (SOCKS Proxy) +* --socksproxy.port= - The port to listen on (SOCKS Proxy). 4447 by default * --socksproxy.keys= - optional keys file for SOCKS proxy local destination -* --socksproxy.enabled= - If SOCKS proxy is enabled. true by default -* --socksproxy.outproxy= - Address of outproxy. requests outside i2p will go there -* --socksproxy.outproxyport= - Outproxy remote port +* --socksproxy.inbound.length= - Inbound tunnels length if keys is set. 3 by default +* --socksproxy.inbound.quantity= - Inbound tunnels quantity if keys is set. 5 by default +* --socksproxy.outbound.length= - Outbound tunnels length if keys is set. 3 by default +* --socksproxy.outbound.quantity= - Outbound tunnels quantity if keys is set. 5 by default +* --socksproxy.outproxy= - Address of outproxy. requests outside i2p will go there +* --socksproxy.outproxyport= - Outproxy remote port * --sam.address= - The address to listen on (SAM bridge) * --sam.port= - Port of SAM bridge. Usually 7656. SAM is off if not specified