diff options
author | Jon Atack <jon@atack.com> | 2020-08-13 16:16:36 +0200 |
---|---|---|
committer | Jon Atack <jon@atack.com> | 2020-08-30 22:37:45 +0200 |
commit | 54799b66b466c0d015e6fe2f820663cc5d8e7998 (patch) | |
tree | 3cd2aa323a2525f3e156c7ab9a2c8c80425f24a2 | |
parent | 12242b17a52c9833e6504f3f0a5b247a6e2fc5f9 (diff) | |
download | bitcoin-54799b66b466c0d015e6fe2f820663cc5d8e7998.tar.xz |
cli: add ipv6 and onion address type detection helpers
-rw-r--r-- | src/bitcoin-cli.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index b7634a7c84..1fb02b1a49 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -39,6 +39,8 @@ static const char DEFAULT_RPCCONNECT[] = "127.0.0.1"; static const int DEFAULT_HTTP_CLIENT_TIMEOUT=900; static const bool DEFAULT_NAMED=false; static const int CONTINUE_EXECUTION=-1; +static const std::string ONION{".onion"}; +static const size_t ONION_LEN{ONION.size()}; /** Default number of blocks to generate for RPC generatetoaddress. */ static const std::string DEFAULT_NBLOCKS = "1"; @@ -297,6 +299,21 @@ public: class NetinfoRequestHandler : public BaseRequestHandler { private: + bool IsAddrIPv6(const std::string& addr) const + { + return !addr.empty() && addr.front() == '['; + } + bool IsInboundOnion(const std::string& addr_local, int mapped_as) const + { + return mapped_as == 0 && addr_local.find(ONION) != std::string::npos; + } + bool IsOutboundOnion(const std::string& addr, int mapped_as) const + { + const size_t addr_len{addr.size()}; + const size_t onion_pos{addr.rfind(ONION)}; + return mapped_as == 0 && onion_pos != std::string::npos && addr_len > ONION_LEN && + (onion_pos == addr_len - ONION_LEN || onion_pos == addr.find_last_of(":") - ONION_LEN); + } bool m_verbose{false}; //!< Whether user requested verbose -netinfo report public: const int ID_PEERINFO = 0; |