From 6159289d110cb51da704a212a4f5c28738095fd7 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 29 Feb 2024 19:54:06 -0700 Subject: [PATCH] fix: unbreak hostname support --- contrib/seeds/generate-seeds.py | 1 + src/evo/providertx.h | 1 + src/netaddress.cpp | 13 +++++++++++++ src/netaddress.h | 17 +++++++++++++++++ src/netbase.cpp | 4 +++- src/rpc/evo.cpp | 4 +++- src/rpc/net.cpp | 4 ++-- 7 files changed, 40 insertions(+), 4 deletions(-) diff --git a/contrib/seeds/generate-seeds.py b/contrib/seeds/generate-seeds.py index 75cb6fad6e80c..f4438b655c1f5 100755 --- a/contrib/seeds/generate-seeds.py +++ b/contrib/seeds/generate-seeds.py @@ -40,6 +40,7 @@ class BIP155Network(Enum): TORV3 = 4 I2P = 5 CJDNS = 6 + HOSTNAME = 1993 def name_to_bip155(addr): '''Convert address string to BIP155 (networkID, addr) tuple.''' diff --git a/src/evo/providertx.h b/src/evo/providertx.h index d7f8f259ffbab..b4b24256da1e5 100644 --- a/src/evo/providertx.h +++ b/src/evo/providertx.h @@ -22,6 +22,7 @@ class CBlockIndex; class CCoinsViewCache; class TxValidationState; +// CProRegTx is defined here class CProRegTx { public: diff --git a/src/netaddress.cpp b/src/netaddress.cpp index ac6afed471a55..8ae23de7c5aa6 100644 --- a/src/netaddress.cpp +++ b/src/netaddress.cpp @@ -36,6 +36,8 @@ CNetAddr::BIP155Network CNetAddr::GetBIP155Network() const return BIP155Network::I2P; case NET_CJDNS: return BIP155Network::CJDNS; + case NET_HOSTNAME: + return BIP155Network::HOSTNAME; case NET_INTERNAL: // should have been handled before calling this function case NET_UNROUTABLE: // m_net is never and should not be set to NET_UNROUTABLE case NET_MAX: // m_net is never and should not be set to NET_MAX @@ -88,6 +90,14 @@ bool CNetAddr::SetNetFromBIP155Network(uint8_t possible_bip155_net, size_t addre throw std::ios_base::failure( strprintf("BIP155 CJDNS address with length %u (should be %u)", address_size, ADDR_CJDNS_SIZE)); + case BIP155Network::HOSTNAME: + if (address_size == ADDR_HOSTNAME_SIZE) { + m_net = NET_HOSTNAME; + return true; + } + throw std::ios_base::failure( + strprintf("BIP155 HOSTNAME address with length %u (should be %u)", address_size, + ADDR_HOSTNAME_SIZE)); } // Don't throw on addresses with unknown network ids (maybe from the future). @@ -124,6 +134,9 @@ void CNetAddr::SetIP(const CNetAddr& ipIn) case NET_CJDNS: assert(ipIn.m_addr.size() == ADDR_CJDNS_SIZE); break; + case NET_HOSTNAME: + assert(ipIn.m_addr.size() <= ADDR_HOSTNAME_SIZE); + break; case NET_INTERNAL: assert(ipIn.m_addr.size() == ADDR_INTERNAL_SIZE); break; diff --git a/src/netaddress.h b/src/netaddress.h index b8001a4dd7327..8c41937cc424d 100644 --- a/src/netaddress.h +++ b/src/netaddress.h @@ -60,6 +60,9 @@ enum Network { /// CJDNS NET_CJDNS, + /// Hostname + NET_HOSTNAME, + /// A set of addresses that represent the hash of a string or FQDN. We use /// them in CAddrMan to keep track of which DNS seeds were used. NET_INTERNAL, @@ -105,6 +108,10 @@ static constexpr size_t ADDR_I2P_SIZE = 32; /// Size of CJDNS address (in bytes). static constexpr size_t ADDR_CJDNS_SIZE = 16; +/// Size of Hostname (in bytes). This is the maximum length of all labels and +/// dots as per RFC 1035 Size limits (Section 2.3.4.) +static constexpr size_t ADDR_HOSTNAME_SIZE = 255; + /// Size of "internal" (NET_INTERNAL) address (in bytes). static constexpr size_t ADDR_INTERNAL_SIZE = 10; @@ -114,6 +121,7 @@ static constexpr uint16_t I2P_SAM31_PORT{0}; /** * Network address. */ +// CNetAddr is defined here for IPv6 or IPv4 class CNetAddr { protected: @@ -164,8 +172,12 @@ class CNetAddr * @returns Whether the operation was successful. * @see CNetAddr::IsTor(), CNetAddr::IsI2P() */ + // Hmmm... looks like hostnames (DNS) *can* fit after all? bool SetSpecial(const std::string& addr); + // What might this look like?? + bool SetHostname(const std::string& addr); + bool IsBindAny() const; // INADDR_ANY equivalent bool IsIPv4() const; // IPv4 mapped address (::FFFF:0:0/96, 0.0.0.0/0) bool IsIPv6() const; // IPv6 address (not mapped IPv4, not Tor) @@ -187,6 +199,7 @@ class CNetAddr bool IsTor() const; bool IsI2P() const; bool IsCJDNS() const; + bool IsHostname() const; bool IsLocal() const; bool IsRoutable() const; bool IsInternal() const; @@ -282,6 +295,8 @@ class CNetAddr TORV3 = 4, I2P = 5, CJDNS = 6, + // add Hostname support here (and rename the enum?) + HOSTNAME = 1993, }; /** @@ -339,6 +354,7 @@ class CNetAddr case NET_ONION: case NET_I2P: case NET_CJDNS: + case NET_HOSTNAME: break; case NET_UNROUTABLE: case NET_MAX: @@ -518,6 +534,7 @@ class CSubNet }; /** A combination of a network address (CNetAddr) and a (TCP) port */ +// CService is defined here class CService : public CNetAddr { protected: diff --git a/src/netbase.cpp b/src/netbase.cpp index fc940b0501dac..ecb56ab93888a 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -90,6 +90,7 @@ enum Network ParseNetwork(const std::string& net_in) { if (net == "ipv4") return NET_IPV4; if (net == "ipv6") return NET_IPV6; if (net == "onion") return NET_ONION; + if (net == "hostname") return NET_HOSTNAME; if (net == "tor") { LogPrintf("Warning: net name 'tor' is deprecated and will be removed in the future. You should use 'onion' instead.\n"); return NET_ONION; @@ -109,6 +110,7 @@ std::string GetNetworkName(enum Network net) case NET_ONION: return "onion"; case NET_I2P: return "i2p"; case NET_CJDNS: return "cjdns"; + case NET_HOSTNAME: return "hostname"; case NET_INTERNAL: return "internal"; case NET_MAX: assert(false); } // no default case, so the compiler can warn about missing cases @@ -121,7 +123,7 @@ std::vector GetNetworkNames(bool append_unroutable) std::vector names; for (int n = 0; n < NET_MAX; ++n) { const enum Network network{static_cast(n)}; - if (network == NET_UNROUTABLE || network == NET_CJDNS || network == NET_INTERNAL) continue; + if (network == NET_UNROUTABLE || network == NET_HOSTNAME || network == NET_CJDNS || network == NET_INTERNAL) continue; names.emplace_back(GetNetworkName(network)); } if (append_unroutable) { diff --git a/src/rpc/evo.cpp b/src/rpc/evo.cpp index 180b9f97741f7..7b85c9274ee49 100644 --- a/src/rpc/evo.cpp +++ b/src/rpc/evo.cpp @@ -620,11 +620,12 @@ static UniValue protx_register_common_wrapper(const JSONRPCRequest& request, size_t paramIdx = 0; CMutableTransaction tx; - tx.nVersion = 3; + tx.nVersion = 3; // EVO SEND!! tx.nType = TRANSACTION_PROVIDER_REGISTER; const bool use_legacy = isV19active ? specific_legacy_bls_scheme : true; + // This is the type that packs the IP presently CProRegTx ptx; ptx.nType = mnType; @@ -655,6 +656,7 @@ static UniValue protx_register_common_wrapper(const JSONRPCRequest& request, wallet->LockCoin(ptx.collateralOutpoint); } + // paramIdx is now for hostnameAndPort if (request.params[paramIdx].get_str() != "") { if (!Lookup(request.params[paramIdx].get_str().c_str(), ptx.addr, Params().GetDefaultPort(), false)) { throw std::runtime_error(strprintf("invalid network address %s", request.params[paramIdx].get_str())); diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index eb9b0af4d237a..41d7e65447421 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -87,7 +87,7 @@ static UniValue getpeerinfo(const JSONRPCRequest& request) { { {RPCResult::Type::NUM, "id", "Peer index"}, - {RPCResult::Type::STR, "addr", "(host:port) The IP address and port of the peer"}, + {RPCResult::Type::STR, "addr", "(hostname:port) The Hostname (or IP address) and port of the peer"}, {RPCResult::Type::STR, "addrbind", "(ip:port) Bind address of the connection to the peer"}, {RPCResult::Type::STR, "addrlocal", "(ip:port) Local address as reported by the peer"}, {RPCResult::Type::STR, "network", "Network (" + Join(GetNetworkNames(/* append_unroutable */ true), ", ") + ")"}, @@ -461,7 +461,7 @@ static UniValue GetNetworksInfo() UniValue networks(UniValue::VARR); for (int n = 0; n < NET_MAX; ++n) { enum Network network = static_cast(n); - if (network == NET_UNROUTABLE || network == NET_CJDNS || network == NET_INTERNAL) continue; + if (network == NET_UNROUTABLE || network == NET_HOSTNAME || network == NET_CJDNS || network == NET_INTERNAL) continue; proxyType proxy; UniValue obj(UniValue::VOBJ); GetProxy(network, proxy);