mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
Merge bitcoin/bitcoin#22834: net: respect -onlynet= when making outbound connections
0eea83a85e
scripted-diff: rename `proxyType` to `Proxy` (Vasil Dimov)e53a8505db
net: respect -onlynet= when making outbound connections (Vasil Dimov) Pull request description: Do not make outbound connections to hosts which belong to a network which is restricted by `-onlynet`. This applies to hosts that are automatically chosen to connect to and to anchors. This does not apply to hosts given to `-connect`, `-addnode`, `addnode` RPC, dns seeds, `-seednode`. Fixes https://github.com/bitcoin/bitcoin/issues/13378 Fixes https://github.com/bitcoin/bitcoin/issues/22647 Supersedes https://github.com/bitcoin/bitcoin/pull/22651 ACKs for top commit: naumenkogs: utACK0eea83a85e
prayank23: reACK0eea83a85e
jonatack: ACK0eea83a85e
code review, rebased to master, debug built, and did some manual testing with various config options on signet Tree-SHA512: 37d68b449dd6d2715843fc84d85f48fa2508be40ea105a7f4a28443b318d0b6bd39e3b2ca2a6186f2913836adf08d91038a8b142928e1282130f39ac81aa741b
This commit is contained in:
commit
848b11615b
14 changed files with 72 additions and 52 deletions
|
@ -67,11 +67,7 @@ logging` for more information.
|
||||||
|
|
||||||
Make outgoing connections only to I2P addresses. Incoming connections are not
|
Make outgoing connections only to I2P addresses. Incoming connections are not
|
||||||
affected by this option. It can be specified multiple times to allow multiple
|
affected by this option. It can be specified multiple times to allow multiple
|
||||||
network types, e.g. onlynet=ipv4, onlynet=ipv6, onlynet=onion, onlynet=i2p.
|
network types, e.g. onlynet=onion, onlynet=i2p.
|
||||||
|
|
||||||
Warning: if you use -onlynet with values other than onion, and the -onion or
|
|
||||||
-proxy option is set, then outgoing onion connections will still be made; use
|
|
||||||
-noonion or -onion=0 to disable outbound onion connections in this case.
|
|
||||||
|
|
||||||
I2P support was added to Bitcoin Core in version 22.0 and there may be fewer I2P
|
I2P support was added to Bitcoin Core in version 22.0 and there may be fewer I2P
|
||||||
peers than Tor or IP ones. Therefore, using I2P alone without other networks may
|
peers than Tor or IP ones. Therefore, using I2P alone without other networks may
|
||||||
|
|
|
@ -153,6 +153,12 @@ Updated settings
|
||||||
E.g. `-maxuploadtarget=500g`. No whitespace, +- or fractions allowed.
|
E.g. `-maxuploadtarget=500g`. No whitespace, +- or fractions allowed.
|
||||||
Default is `M` if no suffix provided. (#23249)
|
Default is `M` if no suffix provided. (#23249)
|
||||||
|
|
||||||
|
- If `-proxy=` is given together with `-noonion` then the provided proxy will
|
||||||
|
not be set as a proxy for reaching the Tor network. So it will not be
|
||||||
|
possible to open manual connections to the Tor network for example with the
|
||||||
|
`addnode` RPC. To mimic the old behavior use `-proxy=` together with
|
||||||
|
`-onlynet=` listing all relevant networks except `onion`. (#22834)
|
||||||
|
|
||||||
Tools and Utilities
|
Tools and Utilities
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
|
|
|
@ -58,11 +58,7 @@ outgoing connections, but more is possible.
|
||||||
-onlynet=onion Make outgoing connections only to .onion addresses. Incoming
|
-onlynet=onion Make outgoing connections only to .onion addresses. Incoming
|
||||||
connections are not affected by this option. This option can be
|
connections are not affected by this option. This option can be
|
||||||
specified multiple times to allow multiple network types, e.g.
|
specified multiple times to allow multiple network types, e.g.
|
||||||
onlynet=ipv4, onlynet=ipv6, onlynet=onion, onlynet=i2p.
|
onlynet=onion, onlynet=i2p.
|
||||||
Warning: if you use -onlynet with values other than onion, and
|
|
||||||
the -onion or -proxy option is set, then outgoing onion
|
|
||||||
connections will still be made; use -noonion or -onion=0 to
|
|
||||||
disable outbound onion connections in this case.
|
|
||||||
|
|
||||||
In a typical situation, this suffices to run behind a Tor proxy:
|
In a typical situation, this suffices to run behind a Tor proxy:
|
||||||
|
|
||||||
|
|
37
src/init.cpp
37
src/init.cpp
|
@ -462,7 +462,7 @@ void SetupServerArgs(ArgsManager& argsman)
|
||||||
argsman.AddArg("-onion=<ip:port>", "Use separate SOCKS5 proxy to reach peers via Tor onion services, set -noonion to disable (default: -proxy)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
|
argsman.AddArg("-onion=<ip:port>", "Use separate SOCKS5 proxy to reach peers via Tor onion services, set -noonion to disable (default: -proxy)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
|
||||||
argsman.AddArg("-i2psam=<ip:port>", "I2P SAM proxy to reach I2P peers and accept I2P connections (default: none)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
|
argsman.AddArg("-i2psam=<ip:port>", "I2P SAM proxy to reach I2P peers and accept I2P connections (default: none)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
|
||||||
argsman.AddArg("-i2pacceptincoming", "If set and -i2psam is also set then incoming I2P connections are accepted via the SAM proxy. If this is not set but -i2psam is set then only outgoing connections will be made to the I2P network. Ignored if -i2psam is not set. Listening for incoming I2P connections is done through the SAM proxy, not by binding to a local address and port (default: 1)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
|
argsman.AddArg("-i2pacceptincoming", "If set and -i2psam is also set then incoming I2P connections are accepted via the SAM proxy. If this is not set but -i2psam is set then only outgoing connections will be made to the I2P network. Ignored if -i2psam is not set. Listening for incoming I2P connections is done through the SAM proxy, not by binding to a local address and port (default: 1)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
|
||||||
argsman.AddArg("-onlynet=<net>", "Make outgoing connections only through network <net> (" + Join(GetNetworkNames(), ", ") + "). Incoming connections are not affected by this option. This option can be specified multiple times to allow multiple networks. Warning: if it is used with non-onion networks and the -onion or -proxy option is set, then outbound onion connections will still be made; use -noonion or -onion=0 to disable outbound onion connections in this case.", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
|
argsman.AddArg("-onlynet=<net>", "Make automatic outgoing connections only through network <net> (" + Join(GetNetworkNames(), ", ") + "). Incoming connections are not affected by this option. This option can be specified multiple times to allow multiple networks.", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
|
||||||
argsman.AddArg("-peerbloomfilters", strprintf("Support filtering of blocks and transaction with bloom filters (default: %u)", DEFAULT_PEERBLOOMFILTERS), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
|
argsman.AddArg("-peerbloomfilters", strprintf("Support filtering of blocks and transaction with bloom filters (default: %u)", DEFAULT_PEERBLOOMFILTERS), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
|
||||||
argsman.AddArg("-peerblockfilters", strprintf("Serve compact block filters to peers per BIP 157 (default: %u)", DEFAULT_PEERBLOCKFILTERS), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
|
argsman.AddArg("-peerblockfilters", strprintf("Serve compact block filters to peers per BIP 157 (default: %u)", DEFAULT_PEERBLOCKFILTERS), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
|
||||||
argsman.AddArg("-permitbaremultisig", strprintf("Relay non-P2SH multisig (default: %u)", DEFAULT_PERMIT_BAREMULTISIG), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
|
argsman.AddArg("-permitbaremultisig", strprintf("Relay non-P2SH multisig (default: %u)", DEFAULT_PERMIT_BAREMULTISIG), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
|
||||||
|
@ -1317,27 +1317,27 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||||
// Check for host lookup allowed before parsing any network related parameters
|
// Check for host lookup allowed before parsing any network related parameters
|
||||||
fNameLookup = args.GetBoolArg("-dns", DEFAULT_NAME_LOOKUP);
|
fNameLookup = args.GetBoolArg("-dns", DEFAULT_NAME_LOOKUP);
|
||||||
|
|
||||||
|
Proxy onion_proxy;
|
||||||
|
|
||||||
bool proxyRandomize = args.GetBoolArg("-proxyrandomize", DEFAULT_PROXYRANDOMIZE);
|
bool proxyRandomize = args.GetBoolArg("-proxyrandomize", DEFAULT_PROXYRANDOMIZE);
|
||||||
// -proxy sets a proxy for all outgoing network traffic
|
// -proxy sets a proxy for all outgoing network traffic
|
||||||
// -noproxy (or -proxy=0) as well as the empty string can be used to not set a proxy, this is the default
|
// -noproxy (or -proxy=0) as well as the empty string can be used to not set a proxy, this is the default
|
||||||
std::string proxyArg = args.GetArg("-proxy", "");
|
std::string proxyArg = args.GetArg("-proxy", "");
|
||||||
SetReachable(NET_ONION, false);
|
|
||||||
if (proxyArg != "" && proxyArg != "0") {
|
if (proxyArg != "" && proxyArg != "0") {
|
||||||
CService proxyAddr;
|
CService proxyAddr;
|
||||||
if (!Lookup(proxyArg, proxyAddr, 9050, fNameLookup)) {
|
if (!Lookup(proxyArg, proxyAddr, 9050, fNameLookup)) {
|
||||||
return InitError(strprintf(_("Invalid -proxy address or hostname: '%s'"), proxyArg));
|
return InitError(strprintf(_("Invalid -proxy address or hostname: '%s'"), proxyArg));
|
||||||
}
|
}
|
||||||
|
|
||||||
proxyType addrProxy = proxyType(proxyAddr, proxyRandomize);
|
Proxy addrProxy = Proxy(proxyAddr, proxyRandomize);
|
||||||
if (!addrProxy.IsValid())
|
if (!addrProxy.IsValid())
|
||||||
return InitError(strprintf(_("Invalid -proxy address or hostname: '%s'"), proxyArg));
|
return InitError(strprintf(_("Invalid -proxy address or hostname: '%s'"), proxyArg));
|
||||||
|
|
||||||
SetProxy(NET_IPV4, addrProxy);
|
SetProxy(NET_IPV4, addrProxy);
|
||||||
SetProxy(NET_IPV6, addrProxy);
|
SetProxy(NET_IPV6, addrProxy);
|
||||||
SetProxy(NET_ONION, addrProxy);
|
|
||||||
SetProxy(NET_CJDNS, addrProxy);
|
SetProxy(NET_CJDNS, addrProxy);
|
||||||
SetNameProxy(addrProxy);
|
SetNameProxy(addrProxy);
|
||||||
SetReachable(NET_ONION, true); // by default, -proxy sets onion as reachable, unless -noonion later
|
onion_proxy = addrProxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -onion can be used to set only a proxy for .onion, or override normal proxy for .onion addresses
|
// -onion can be used to set only a proxy for .onion, or override normal proxy for .onion addresses
|
||||||
|
@ -1346,20 +1346,28 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||||
std::string onionArg = args.GetArg("-onion", "");
|
std::string onionArg = args.GetArg("-onion", "");
|
||||||
if (onionArg != "") {
|
if (onionArg != "") {
|
||||||
if (onionArg == "0") { // Handle -noonion/-onion=0
|
if (onionArg == "0") { // Handle -noonion/-onion=0
|
||||||
SetReachable(NET_ONION, false);
|
onion_proxy = Proxy{};
|
||||||
} else {
|
} else {
|
||||||
CService onionProxy;
|
CService addr;
|
||||||
if (!Lookup(onionArg, onionProxy, 9050, fNameLookup)) {
|
if (!Lookup(onionArg, addr, 9050, fNameLookup) || !addr.IsValid()) {
|
||||||
return InitError(strprintf(_("Invalid -onion address or hostname: '%s'"), onionArg));
|
return InitError(strprintf(_("Invalid -onion address or hostname: '%s'"), onionArg));
|
||||||
}
|
}
|
||||||
proxyType addrOnion = proxyType(onionProxy, proxyRandomize);
|
onion_proxy = Proxy{addr, proxyRandomize};
|
||||||
if (!addrOnion.IsValid())
|
|
||||||
return InitError(strprintf(_("Invalid -onion address or hostname: '%s'"), onionArg));
|
|
||||||
SetProxy(NET_ONION, addrOnion);
|
|
||||||
SetReachable(NET_ONION, true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (onion_proxy.IsValid()) {
|
||||||
|
SetProxy(NET_ONION, onion_proxy);
|
||||||
|
} else {
|
||||||
|
if (args.IsArgSet("-onlynet") && IsReachable(NET_ONION)) {
|
||||||
|
return InitError(
|
||||||
|
_("Outbound connections restricted to Tor (-onlynet=onion) but the proxy for "
|
||||||
|
"reaching the Tor network is not provided (no -proxy= and no -onion= given) or "
|
||||||
|
"it is explicitly forbidden (-onion=0)"));
|
||||||
|
}
|
||||||
|
SetReachable(NET_ONION, false);
|
||||||
|
}
|
||||||
|
|
||||||
for (const std::string& strAddr : args.GetArgs("-externalip")) {
|
for (const std::string& strAddr : args.GetArgs("-externalip")) {
|
||||||
CService addrLocal;
|
CService addrLocal;
|
||||||
if (Lookup(strAddr, addrLocal, GetListenPort(), fNameLookup) && addrLocal.IsValid())
|
if (Lookup(strAddr, addrLocal, GetListenPort(), fNameLookup) && addrLocal.IsValid())
|
||||||
|
@ -1752,8 +1760,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||||
if (!Lookup(i2psam_arg, addr, 7656, fNameLookup) || !addr.IsValid()) {
|
if (!Lookup(i2psam_arg, addr, 7656, fNameLookup) || !addr.IsValid()) {
|
||||||
return InitError(strprintf(_("Invalid -i2psam address or hostname: '%s'"), i2psam_arg));
|
return InitError(strprintf(_("Invalid -i2psam address or hostname: '%s'"), i2psam_arg));
|
||||||
}
|
}
|
||||||
SetReachable(NET_I2P, true);
|
SetProxy(NET_I2P, Proxy{addr});
|
||||||
SetProxy(NET_I2P, proxyType{addr});
|
|
||||||
} else {
|
} else {
|
||||||
SetReachable(NET_I2P, false);
|
SetReachable(NET_I2P, false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ class CNodeStats;
|
||||||
class Coin;
|
class Coin;
|
||||||
class RPCTimerInterface;
|
class RPCTimerInterface;
|
||||||
class UniValue;
|
class UniValue;
|
||||||
class proxyType;
|
class Proxy;
|
||||||
enum class SynchronizationState;
|
enum class SynchronizationState;
|
||||||
enum class TransactionError;
|
enum class TransactionError;
|
||||||
struct CNodeStateStats;
|
struct CNodeStateStats;
|
||||||
|
@ -101,7 +101,7 @@ public:
|
||||||
virtual void mapPort(bool use_upnp, bool use_natpmp) = 0;
|
virtual void mapPort(bool use_upnp, bool use_natpmp) = 0;
|
||||||
|
|
||||||
//! Get proxy.
|
//! Get proxy.
|
||||||
virtual bool getProxy(Network net, proxyType& proxy_info) = 0;
|
virtual bool getProxy(Network net, Proxy& proxy_info) = 0;
|
||||||
|
|
||||||
//! Get number of connections.
|
//! Get number of connections.
|
||||||
virtual size_t getNodeCount(ConnectionDirection flags) = 0;
|
virtual size_t getNodeCount(ConnectionDirection flags) = 0;
|
||||||
|
|
|
@ -449,7 +449,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
|
||||||
// Connect
|
// Connect
|
||||||
bool connected = false;
|
bool connected = false;
|
||||||
std::unique_ptr<Sock> sock;
|
std::unique_ptr<Sock> sock;
|
||||||
proxyType proxy;
|
Proxy proxy;
|
||||||
CAddress addr_bind;
|
CAddress addr_bind;
|
||||||
assert(!addr_bind.IsValid());
|
assert(!addr_bind.IsValid());
|
||||||
|
|
||||||
|
@ -2559,7 +2559,7 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
proxyType i2p_sam;
|
Proxy i2p_sam;
|
||||||
if (GetProxy(NET_I2P, i2p_sam)) {
|
if (GetProxy(NET_I2P, i2p_sam)) {
|
||||||
m_i2p_sam_session = std::make_unique<i2p::sam::Session>(gArgs.GetDataDirNet() / "i2p_private_key",
|
m_i2p_sam_session = std::make_unique<i2p::sam::Session>(gArgs.GetDataDirNet() / "i2p_private_key",
|
||||||
i2p_sam.proxy, &interruptNet);
|
i2p_sam.proxy, &interruptNet);
|
||||||
|
|
|
@ -31,8 +31,8 @@
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
static Mutex g_proxyinfo_mutex;
|
static Mutex g_proxyinfo_mutex;
|
||||||
static proxyType proxyInfo[NET_MAX] GUARDED_BY(g_proxyinfo_mutex);
|
static Proxy proxyInfo[NET_MAX] GUARDED_BY(g_proxyinfo_mutex);
|
||||||
static proxyType nameProxy GUARDED_BY(g_proxyinfo_mutex);
|
static Proxy nameProxy GUARDED_BY(g_proxyinfo_mutex);
|
||||||
int nConnectTimeout = DEFAULT_CONNECT_TIMEOUT;
|
int nConnectTimeout = DEFAULT_CONNECT_TIMEOUT;
|
||||||
bool fNameLookup = DEFAULT_NAME_LOOKUP;
|
bool fNameLookup = DEFAULT_NAME_LOOKUP;
|
||||||
|
|
||||||
|
@ -605,7 +605,7 @@ bool ConnectSocketDirectly(const CService &addrConnect, const Sock& sock, int nT
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SetProxy(enum Network net, const proxyType &addrProxy) {
|
bool SetProxy(enum Network net, const Proxy &addrProxy) {
|
||||||
assert(net >= 0 && net < NET_MAX);
|
assert(net >= 0 && net < NET_MAX);
|
||||||
if (!addrProxy.IsValid())
|
if (!addrProxy.IsValid())
|
||||||
return false;
|
return false;
|
||||||
|
@ -614,7 +614,7 @@ bool SetProxy(enum Network net, const proxyType &addrProxy) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetProxy(enum Network net, proxyType &proxyInfoOut) {
|
bool GetProxy(enum Network net, Proxy &proxyInfoOut) {
|
||||||
assert(net >= 0 && net < NET_MAX);
|
assert(net >= 0 && net < NET_MAX);
|
||||||
LOCK(g_proxyinfo_mutex);
|
LOCK(g_proxyinfo_mutex);
|
||||||
if (!proxyInfo[net].IsValid())
|
if (!proxyInfo[net].IsValid())
|
||||||
|
@ -623,7 +623,7 @@ bool GetProxy(enum Network net, proxyType &proxyInfoOut) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SetNameProxy(const proxyType &addrProxy) {
|
bool SetNameProxy(const Proxy &addrProxy) {
|
||||||
if (!addrProxy.IsValid())
|
if (!addrProxy.IsValid())
|
||||||
return false;
|
return false;
|
||||||
LOCK(g_proxyinfo_mutex);
|
LOCK(g_proxyinfo_mutex);
|
||||||
|
@ -631,7 +631,7 @@ bool SetNameProxy(const proxyType &addrProxy) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetNameProxy(proxyType &nameProxyOut) {
|
bool GetNameProxy(Proxy &nameProxyOut) {
|
||||||
LOCK(g_proxyinfo_mutex);
|
LOCK(g_proxyinfo_mutex);
|
||||||
if(!nameProxy.IsValid())
|
if(!nameProxy.IsValid())
|
||||||
return false;
|
return false;
|
||||||
|
@ -653,7 +653,7 @@ bool IsProxy(const CNetAddr &addr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConnectThroughProxy(const proxyType& proxy, const std::string& strDest, uint16_t port, const Sock& sock, int nTimeout, bool& outProxyConnectionFailed)
|
bool ConnectThroughProxy(const Proxy& proxy, const std::string& strDest, uint16_t port, const Sock& sock, int nTimeout, bool& outProxyConnectionFailed)
|
||||||
{
|
{
|
||||||
// first connect to proxy server
|
// first connect to proxy server
|
||||||
if (!ConnectSocketDirectly(proxy.proxy, sock, nTimeout, true)) {
|
if (!ConnectSocketDirectly(proxy.proxy, sock, nTimeout, true)) {
|
||||||
|
|
|
@ -45,11 +45,11 @@ static inline bool operator&(ConnectionDirection a, ConnectionDirection b) {
|
||||||
return (underlying(a) & underlying(b));
|
return (underlying(a) & underlying(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
class proxyType
|
class Proxy
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
proxyType(): randomize_credentials(false) {}
|
Proxy(): randomize_credentials(false) {}
|
||||||
explicit proxyType(const CService &_proxy, bool _randomize_credentials=false): proxy(_proxy), randomize_credentials(_randomize_credentials) {}
|
explicit Proxy(const CService &_proxy, bool _randomize_credentials=false): proxy(_proxy), randomize_credentials(_randomize_credentials) {}
|
||||||
|
|
||||||
bool IsValid() const { return proxy.IsValid(); }
|
bool IsValid() const { return proxy.IsValid(); }
|
||||||
|
|
||||||
|
@ -73,8 +73,8 @@ enum Network ParseNetwork(const std::string& net);
|
||||||
std::string GetNetworkName(enum Network net);
|
std::string GetNetworkName(enum Network net);
|
||||||
/** Return a vector of publicly routable Network names; optionally append NET_UNROUTABLE. */
|
/** Return a vector of publicly routable Network names; optionally append NET_UNROUTABLE. */
|
||||||
std::vector<std::string> GetNetworkNames(bool append_unroutable = false);
|
std::vector<std::string> GetNetworkNames(bool append_unroutable = false);
|
||||||
bool SetProxy(enum Network net, const proxyType &addrProxy);
|
bool SetProxy(enum Network net, const Proxy &addrProxy);
|
||||||
bool GetProxy(enum Network net, proxyType &proxyInfoOut);
|
bool GetProxy(enum Network net, Proxy &proxyInfoOut);
|
||||||
bool IsProxy(const CNetAddr &addr);
|
bool IsProxy(const CNetAddr &addr);
|
||||||
/**
|
/**
|
||||||
* Set the name proxy to use for all connections to nodes specified by a
|
* Set the name proxy to use for all connections to nodes specified by a
|
||||||
|
@ -92,9 +92,9 @@ bool IsProxy(const CNetAddr &addr);
|
||||||
* server in common use (most notably Tor) actually implements UDP
|
* server in common use (most notably Tor) actually implements UDP
|
||||||
* support, and a DNS resolver is beyond the scope of this project.
|
* support, and a DNS resolver is beyond the scope of this project.
|
||||||
*/
|
*/
|
||||||
bool SetNameProxy(const proxyType &addrProxy);
|
bool SetNameProxy(const Proxy &addrProxy);
|
||||||
bool HaveNameProxy();
|
bool HaveNameProxy();
|
||||||
bool GetNameProxy(proxyType &nameProxyOut);
|
bool GetNameProxy(Proxy &nameProxyOut);
|
||||||
|
|
||||||
using DNSLookupFn = std::function<std::vector<CNetAddr>(const std::string&, bool)>;
|
using DNSLookupFn = std::function<std::vector<CNetAddr>(const std::string&, bool)>;
|
||||||
extern DNSLookupFn g_dns_lookup;
|
extern DNSLookupFn g_dns_lookup;
|
||||||
|
@ -219,7 +219,7 @@ bool ConnectSocketDirectly(const CService &addrConnect, const Sock& sock, int nT
|
||||||
*
|
*
|
||||||
* @returns Whether or not the operation succeeded.
|
* @returns Whether or not the operation succeeded.
|
||||||
*/
|
*/
|
||||||
bool ConnectThroughProxy(const proxyType& proxy, const std::string& strDest, uint16_t port, const Sock& sock, int nTimeout, bool& outProxyConnectionFailed);
|
bool ConnectThroughProxy(const Proxy& proxy, const std::string& strDest, uint16_t port, const Sock& sock, int nTimeout, bool& outProxyConnectionFailed);
|
||||||
|
|
||||||
/** Disable or enable blocking-mode for a socket */
|
/** Disable or enable blocking-mode for a socket */
|
||||||
bool SetSocketNonBlocking(const SOCKET& hSocket, bool fNonBlocking);
|
bool SetSocketNonBlocking(const SOCKET& hSocket, bool fNonBlocking);
|
||||||
|
|
|
@ -113,7 +113,7 @@ public:
|
||||||
}
|
}
|
||||||
bool shutdownRequested() override { return ShutdownRequested(); }
|
bool shutdownRequested() override { return ShutdownRequested(); }
|
||||||
void mapPort(bool use_upnp, bool use_natpmp) override { StartMapPort(use_upnp, use_natpmp); }
|
void mapPort(bool use_upnp, bool use_natpmp) override { StartMapPort(use_upnp, use_natpmp); }
|
||||||
bool getProxy(Network net, proxyType& proxy_info) override { return GetProxy(net, proxy_info); }
|
bool getProxy(Network net, Proxy& proxy_info) override { return GetProxy(net, proxy_info); }
|
||||||
size_t getNodeCount(ConnectionDirection flags) override
|
size_t getNodeCount(ConnectionDirection flags) override
|
||||||
{
|
{
|
||||||
return m_context->connman ? m_context->connman->GetNodeCount(flags) : 0;
|
return m_context->connman ? m_context->connman->GetNodeCount(flags) : 0;
|
||||||
|
|
|
@ -329,7 +329,7 @@ void ClientModel::unsubscribeFromCoreSignals()
|
||||||
|
|
||||||
bool ClientModel::getProxyInfo(std::string& ip_port) const
|
bool ClientModel::getProxyInfo(std::string& ip_port) const
|
||||||
{
|
{
|
||||||
proxyType ipv4, ipv6;
|
Proxy ipv4, ipv6;
|
||||||
if (m_node.getProxy((Network) 1, ipv4) && m_node.getProxy((Network) 2, ipv6)) {
|
if (m_node.getProxy((Network) 1, ipv4) && m_node.getProxy((Network) 2, ipv6)) {
|
||||||
ip_port = ipv4.proxy.ToStringIPPort();
|
ip_port = ipv4.proxy.ToStringIPPort();
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -395,7 +395,7 @@ void OptionsDialog::updateProxyValidationState()
|
||||||
|
|
||||||
void OptionsDialog::updateDefaultProxyNets()
|
void OptionsDialog::updateDefaultProxyNets()
|
||||||
{
|
{
|
||||||
proxyType proxy;
|
Proxy proxy;
|
||||||
std::string strProxy;
|
std::string strProxy;
|
||||||
QString strDefaultProxyGUI;
|
QString strDefaultProxyGUI;
|
||||||
|
|
||||||
|
@ -425,7 +425,7 @@ QValidator::State ProxyAddressValidator::validate(QString &input, int &pos) cons
|
||||||
Q_UNUSED(pos);
|
Q_UNUSED(pos);
|
||||||
// Validate the proxy
|
// Validate the proxy
|
||||||
CService serv(LookupNumeric(input.toStdString(), DEFAULT_GUI_PROXY_PORT));
|
CService serv(LookupNumeric(input.toStdString(), DEFAULT_GUI_PROXY_PORT));
|
||||||
proxyType addrProxy = proxyType(serv, true);
|
Proxy addrProxy = Proxy(serv, true);
|
||||||
if (addrProxy.IsValid())
|
if (addrProxy.IsValid())
|
||||||
return QValidator::Acceptable;
|
return QValidator::Acceptable;
|
||||||
|
|
||||||
|
|
|
@ -556,7 +556,7 @@ static UniValue GetNetworksInfo()
|
||||||
for (int n = 0; n < NET_MAX; ++n) {
|
for (int n = 0; n < NET_MAX; ++n) {
|
||||||
enum Network network = static_cast<enum Network>(n);
|
enum Network network = static_cast<enum Network>(n);
|
||||||
if (network == NET_UNROUTABLE || network == NET_INTERNAL) continue;
|
if (network == NET_UNROUTABLE || network == NET_INTERNAL) continue;
|
||||||
proxyType proxy;
|
Proxy proxy;
|
||||||
UniValue obj(UniValue::VOBJ);
|
UniValue obj(UniValue::VOBJ);
|
||||||
GetProxy(network, proxy);
|
GetProxy(network, proxy);
|
||||||
obj.pushKV("name", GetNetworkName(network));
|
obj.pushKV("name", GetNetworkName(network));
|
||||||
|
|
|
@ -382,9 +382,24 @@ void TorController::auth_cb(TorControlConnection& _conn, const TorControlReply&
|
||||||
// if -onion isn't set to something else.
|
// if -onion isn't set to something else.
|
||||||
if (gArgs.GetArg("-onion", "") == "") {
|
if (gArgs.GetArg("-onion", "") == "") {
|
||||||
CService resolved(LookupNumeric("127.0.0.1", 9050));
|
CService resolved(LookupNumeric("127.0.0.1", 9050));
|
||||||
proxyType addrOnion = proxyType(resolved, true);
|
Proxy addrOnion = Proxy(resolved, true);
|
||||||
SetProxy(NET_ONION, addrOnion);
|
SetProxy(NET_ONION, addrOnion);
|
||||||
SetReachable(NET_ONION, true);
|
|
||||||
|
const auto onlynets = gArgs.GetArgs("-onlynet");
|
||||||
|
|
||||||
|
const bool onion_allowed_by_onlynet{
|
||||||
|
!gArgs.IsArgSet("-onlynet") ||
|
||||||
|
std::any_of(onlynets.begin(), onlynets.end(), [](const auto& n) {
|
||||||
|
return ParseNetwork(n) == NET_ONION;
|
||||||
|
})};
|
||||||
|
|
||||||
|
if (onion_allowed_by_onlynet) {
|
||||||
|
// If NET_ONION is reachable, then the below is a noop.
|
||||||
|
//
|
||||||
|
// If NET_ONION is not reachable, then none of -proxy or -onion was given.
|
||||||
|
// Since we are here, then -torcontrol and -torpassword were given.
|
||||||
|
SetReachable(NET_ONION, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally - now create the service
|
// Finally - now create the service
|
||||||
|
|
|
@ -280,7 +280,7 @@ class ProxyTest(BitcoinTestFramework):
|
||||||
n3 = networks_dict(self.nodes[3].getnetworkinfo())
|
n3 = networks_dict(self.nodes[3].getnetworkinfo())
|
||||||
assert_equal(NETWORKS, n3.keys())
|
assert_equal(NETWORKS, n3.keys())
|
||||||
for net in NETWORKS:
|
for net in NETWORKS:
|
||||||
if net == NET_I2P:
|
if net == NET_I2P or net == NET_ONION:
|
||||||
expected_proxy = ''
|
expected_proxy = ''
|
||||||
else:
|
else:
|
||||||
expected_proxy = f'[{self.conf3.addr[0]}]:{self.conf3.addr[1]}'
|
expected_proxy = f'[{self.conf3.addr[0]}]:{self.conf3.addr[1]}'
|
||||||
|
|
Loading…
Add table
Reference in a new issue