From 60dc8e4208058814494b301c355a5996af9517a9 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Wed, 30 Jul 2014 15:27:03 +0200 Subject: Allow -onlynet=onion to be used Just an alias for onlynet=tor, but matches the new name of the proxy option -onion= better. --- src/init.cpp | 2 +- src/netbase.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index b84c233b99..a908169cd9 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -248,7 +248,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += " -maxreceivebuffer= " + _("Maximum per-connection receive buffer, *1000 bytes (default: 5000)") + "\n"; strUsage += " -maxsendbuffer= " + _("Maximum per-connection send buffer, *1000 bytes (default: 1000)") + "\n"; strUsage += " -onion= " + _("Use separate SOCKS5 proxy to reach peers via Tor hidden services (default: -proxy)") + "\n"; - strUsage += " -onlynet= " + _("Only connect to nodes in network (IPv4, IPv6 or Tor)") + "\n"; + strUsage += " -onlynet= " + _("Only connect to nodes in network (IPv4, IPv6 or Onion)") + "\n"; strUsage += " -permitbaremultisig " + _("Relay non-P2SH multisig (default: 1)") + "\n"; strUsage += " -port= " + _("Listen for connections on (default: 8333 or testnet: 18333)") + "\n"; strUsage += " -proxy= " + _("Connect through SOCKS5 proxy") + "\n"; diff --git a/src/netbase.cpp b/src/netbase.cpp index af6d11f0e2..f9f4755f7b 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -47,7 +47,7 @@ enum Network ParseNetwork(std::string net) { boost::to_lower(net); if (net == "ipv4") return NET_IPV4; if (net == "ipv6") return NET_IPV6; - if (net == "tor") return NET_TOR; + if (net == "tor" || net == "onion") return NET_TOR; return NET_UNROUTABLE; } -- cgit v1.2.3 From c91a9471be7a96311a7e1452a3624aa557bc185d Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Wed, 30 Jul 2014 15:31:36 +0200 Subject: Add IsReachable(net) function Allows other parts of the program to query for reachable status of a network. Similar to IsLimited(net). --- src/net.cpp | 10 ++++++++-- src/net.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 62124514c8..27f71e45dc 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -307,12 +307,18 @@ bool IsLocal(const CService& addr) return mapLocalHost.count(addr) > 0; } +/** check whether a given network is one we can probably connect to */ +bool IsReachable(enum Network net) +{ + LOCK(cs_mapLocalHost); + return vfReachable[net] && !vfLimited[net]; +} + /** check whether a given address is in a network we can probably connect to */ bool IsReachable(const CNetAddr& addr) { - LOCK(cs_mapLocalHost); enum Network net = addr.GetNetwork(); - return vfReachable[net] && !vfLimited[net]; + return IsReachable(net); } bool GetMyExternalIP2(const CService& addrConnect, const char* pszGet, const char* pszKeyword, CNetAddr& ipRet) diff --git a/src/net.h b/src/net.h index 2d9325abf9..8656766e26 100644 --- a/src/net.h +++ b/src/net.h @@ -106,6 +106,7 @@ bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE); bool SeenLocal(const CService& addr); bool IsLocal(const CService& addr); bool GetLocal(CService &addr, const CNetAddr *paddrPeer = NULL); +bool IsReachable(enum Network net); bool IsReachable(const CNetAddr &addr); void SetReachable(enum Network net, bool fFlag = true); CAddress GetLocalAddress(const CNetAddr *paddrPeer = NULL); -- cgit v1.2.3 From 075cf49e593025030c8b3572e606960f15de424e Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Wed, 30 Jul 2014 15:32:36 +0200 Subject: Add GetNetworkName function Returns the network name for an Network enum. --- src/netbase.cpp | 10 ++++++++++ src/netbase.h | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/netbase.cpp b/src/netbase.cpp index f9f4755f7b..4e109a8bc9 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -51,6 +51,16 @@ enum Network ParseNetwork(std::string net) { return NET_UNROUTABLE; } +std::string GetNetworkName(enum Network net) { + switch(net) + { + case NET_IPV4: return "ipv4"; + case NET_IPV6: return "ipv6"; + case NET_TOR: return "onion"; + default: return ""; + } +} + void SplitHostPort(std::string in, int &portOut, std::string &hostOut) { size_t colon = in.find_last_of(':'); // if a : is found, and it either follows a [...], or no other : is in the string, treat it as port separator diff --git a/src/netbase.h b/src/netbase.h index 7d83e35344..bd8dbf9695 100644 --- a/src/netbase.h +++ b/src/netbase.h @@ -26,7 +26,7 @@ extern bool fNameLookup; enum Network { - NET_UNROUTABLE, + NET_UNROUTABLE = 0, NET_IPV4, NET_IPV6, NET_TOR, @@ -164,6 +164,7 @@ class CService : public CNetAddr typedef CService proxyType; enum Network ParseNetwork(std::string net); +std::string GetNetworkName(enum Network net); void SplitHostPort(std::string in, int &portOut, std::string &hostOut); bool SetProxy(enum Network net, CService addrProxy); bool GetProxy(enum Network net, proxyType &proxyInfoOut); -- cgit v1.2.3 From aa8279513b5d206c172d3da3d5e3034c61d47b39 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Wed, 30 Jul 2014 15:35:14 +0200 Subject: Add detailed network info to getnetworkinfo RPC This commit adds per-network information to the getnetworkinfo RPC call: - Is the network limited? - Is the network reachable - Which proxy is used for this network, if any Inspired by #2575. --- src/init.cpp | 2 +- src/rpcnet.cpp | 33 ++++++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index a908169cd9..b20b940b86 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -248,7 +248,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += " -maxreceivebuffer= " + _("Maximum per-connection receive buffer, *1000 bytes (default: 5000)") + "\n"; strUsage += " -maxsendbuffer= " + _("Maximum per-connection send buffer, *1000 bytes (default: 1000)") + "\n"; strUsage += " -onion= " + _("Use separate SOCKS5 proxy to reach peers via Tor hidden services (default: -proxy)") + "\n"; - strUsage += " -onlynet= " + _("Only connect to nodes in network (IPv4, IPv6 or Onion)") + "\n"; + strUsage += " -onlynet= " + _("Only connect to nodes in network (ipv4, ipv6 or onion)") + "\n"; strUsage += " -permitbaremultisig " + _("Relay non-P2SH multisig (default: 1)") + "\n"; strUsage += " -port= " + _("Listen for connections on (default: 8333 or testnet: 18333)") + "\n"; strUsage += " -proxy= " + _("Connect through SOCKS5 proxy") + "\n"; diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index 88e7c4ab07..2baa481c4e 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -338,6 +338,26 @@ Value getnettotals(const Array& params, bool fHelp) return obj; } +static Array GetNetworksInfo() +{ + Array networks; + for(int n=0; n(n); + if(network == NET_UNROUTABLE) + continue; + proxyType proxy; + Object obj; + GetProxy(network, proxy); + obj.push_back(Pair("name", GetNetworkName(network))); + obj.push_back(Pair("limited", IsLimited(network))); + obj.push_back(Pair("reachable", IsReachable(network))); + obj.push_back(Pair("proxy", proxy.IsValid() ? proxy.ToStringIPPort() : string())); + networks.push_back(obj); + } + return networks; +} + Value getnetworkinfo(const Array& params, bool fHelp) { if (fHelp || params.size() != 0) @@ -351,7 +371,13 @@ Value getnetworkinfo(const Array& params, bool fHelp) " \"localservices\": \"xxxxxxxxxxxxxxxx\", (string) the services we offer to the network\n" " \"timeoffset\": xxxxx, (numeric) the time offset\n" " \"connections\": xxxxx, (numeric) the number of connections\n" - " \"proxy\": \"host:port\", (string, optional) the proxy used by the server\n" + " \"networks\": [ (array) information per network\n" + " \"name\": \"xxx\", (string) network (ipv4, ipv6 or onion)\n" + " \"limited\": xxx, (boolean) is the network limited using -onlynet?\n" + " \"reachable\": xxx, (boolean) is the network reachable?\n" + " \"proxy\": \"host:port\" (string) the proxy that is used for this network, or empty if none\n" + " },\n" + " ],\n" " \"relayfee\": x.xxxx, (numeric) minimum relay fee for non-free transactions in btc/kb\n" " \"localaddresses\": [, (array) list of local addresses\n" " \"address\": \"xxxx\", (string) network address\n" @@ -364,16 +390,13 @@ Value getnetworkinfo(const Array& params, bool fHelp) + HelpExampleRpc("getnetworkinfo", "") ); - proxyType proxy; - GetProxy(NET_IPV4, proxy); - Object obj; obj.push_back(Pair("version", (int)CLIENT_VERSION)); obj.push_back(Pair("protocolversion",(int)PROTOCOL_VERSION)); obj.push_back(Pair("localservices", strprintf("%016x", nLocalServices))); obj.push_back(Pair("timeoffset", GetTimeOffset())); obj.push_back(Pair("connections", (int)vNodes.size())); - obj.push_back(Pair("proxy", (proxy.IsValid() ? proxy.ToStringIPPort() : string()))); + obj.push_back(Pair("networks", GetNetworksInfo())); obj.push_back(Pair("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK()))); Array localAddresses; { -- cgit v1.2.3