- rework the proxy handling in init to cover more cases and work more thoroughly
- extend RPC call getnetwork info to see if IPv6 and Tor proxy is the default proxy
See #2575 for discussion!
360 obj.push_back(Pair("name", GetNetworkName(network)));
361 obj.push_back(Pair("limited", IsLimited(network)));
362 obj.push_back(Pair("reachable", IsReachable(network)));
363 obj.push_back(Pair("proxy", proxy.IsValid() ? proxy.ToStringIPPort() : string()));
364+ if (network != NET_IPV4)
365+ obj.push_back(Pair("proxy-from-default", proxy == proxyDefault));
proxy-from-default
is useful information. Clients requesting from RPC just want to know the currently effective state, it shouldn’t matter how it came that way. For troubleshooting command line argument interaction there’s always debug.log.
- rework the proxy handling in init to cover more cases and work more
thoroughly
377 obj.push_back(Pair("limited", IsLimited(network)));
378 obj.push_back(Pair("reachable", IsReachable(network)));
379 obj.push_back(Pair("proxy", proxy.IsValid() ? proxy.proxy.ToStringIPPort() : string()));
380 obj.push_back(Pair("proxy_randomize_credentials", proxy.randomize_credentials));
381+ if (network != NET_IPV4)
382+ obj.push_back(Pair("proxy-from-default", proxy.proxy == proxyDefault.proxy));
proxy-from-default
, it’s not useful information and will always be true anyway according to the above code.
I’m terribly sorry sorry for holding this up so long, but I’m not convinced that the new logic is any better.
The logical flow here sounds to me:
-proxy
, apply to all nets, as well as the name proxy-onion
, apply to NET_TOR
. This overrides the default set in the first step, if anyAll errors during parsing of either setting should be fatal, to avoid that the user is running with different settings than they expect.
This is nearer to the original code than yours. I certainly think the code could be simplified and made more clear, what do you think about:
0 bool proxyRandomize = GetBoolArg("-proxyrandomize", true);
1 // -proxy sets a proxy for all outgoing network traffic
2 // -noproxy (or -proxy=0) as well as the empty string can be used to not set a proxy, this is the default
3 std::string proxyArg = GetArg("-proxy", "");
4 if (proxyArg != "" && proxyArg != "0") {
5 proxyType addrProxy = proxyType(CService(proxyArg, 9050), proxyRandomize);
6 if (!addrProxy.IsValid())
7 return InitError(strprintf(_("Invalid -proxy address: '%s'"), proxyArg));
8
9 SetProxy(NET_IPV4, addrProxy);
10 SetProxy(NET_IPV6, addrProxy);
11 SetProxy(NET_TOR, addrProxy);
12 SetNameProxy(addrProxy);
13 SetReachable(NET_TOR); // by default, -proxy sets onion as reachable, unless -noonion later
14 }
15
16 // -onion can override normal proxy for .onion addresses
17 // -noonion (or -onion=0) disables connecting to .onion entirely
18 // An empty string is used to just not override the onion proxy
19 std::string onionArg = GetArg("-onion", "");
20 if (onionArg != "") {
21 if (onionArg == "0") { // Handle -noonion/-onion=0
22 SetReachable(NET_TOR, false); // set onions as unreachable
23 } else {
24 proxyType addrOnion;
25 addrOnion = proxyType(CService(onionArg, 9050), proxyRandomize);
26 if (!addrOnion.IsValid())
27 return InitError(strprintf(_("Invalid -onion address: '%s'"), onionArg));
28 SetProxy(NET_TOR, addrOnion);
29 SetReachable(NET_TOR);
30 }
31 }
This provides a straightforward flow, gets rid of .count()
(which is what you needed for the GUI, as it makes it possible to override an earlier provided proxy option to nothing), as well as comments the different cases.
Diapolo
BitcoinPullTester
laanwj
fanquake
Labels
P2P