Skip to content

Commit a97331d

Browse files
committed
fix: unbreak hostname support
1 parent 5b08d0f commit a97331d

File tree

6 files changed

+35
-3
lines changed

6 files changed

+35
-3
lines changed

src/evo/providertx.h

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class CBlockIndex;
2222
class CCoinsViewCache;
2323
class TxValidationState;
2424

25+
// CProRegTx is defined here
2526
class CProRegTx
2627
{
2728
public:

src/netaddress.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ CNetAddr::BIP155Network CNetAddr::GetBIP155Network() const
3636
return BIP155Network::I2P;
3737
case NET_CJDNS:
3838
return BIP155Network::CJDNS;
39+
case NET_HOSTNAME:
40+
return BIP155Network::HOSTNAME;
3941
case NET_INTERNAL: // should have been handled before calling this function
4042
case NET_UNROUTABLE: // m_net is never and should not be set to NET_UNROUTABLE
4143
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
8890
throw std::ios_base::failure(
8991
strprintf("BIP155 CJDNS address with length %u (should be %u)", address_size,
9092
ADDR_CJDNS_SIZE));
93+
case BIP155Network::HOSTNAME:
94+
if (address_size == ADDR_HOSTNAME_SIZE) {
95+
m_net = NET_HOSTNAME;
96+
return true;
97+
}
98+
throw std::ios_base::failure(
99+
strprintf("BIP155 HOSTNAME address with length %u (should be %u)", address_size,
100+
ADDR_HOSTNAME_SIZE));
91101
}
92102

93103
// Don't throw on addresses with unknown network ids (maybe from the future).

src/netaddress.h

+17
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ enum Network {
6060
/// CJDNS
6161
NET_CJDNS,
6262

63+
/// Hostname
64+
NET_HOSTNAME,
65+
6366
/// A set of addresses that represent the hash of a string or FQDN. We use
6467
/// them in CAddrMan to keep track of which DNS seeds were used.
6568
NET_INTERNAL,
@@ -105,6 +108,10 @@ static constexpr size_t ADDR_I2P_SIZE = 32;
105108
/// Size of CJDNS address (in bytes).
106109
static constexpr size_t ADDR_CJDNS_SIZE = 16;
107110

111+
/// Size of Hostname (in bytes). This is the maximum length of all labels and
112+
/// dots as per RFC 1035 Size limits (Section 2.3.4.)
113+
static constexpr size_t ADDR_HOSTNAME_SIZE = 255;
114+
108115
/// Size of "internal" (NET_INTERNAL) address (in bytes).
109116
static constexpr size_t ADDR_INTERNAL_SIZE = 10;
110117

@@ -114,6 +121,7 @@ static constexpr uint16_t I2P_SAM31_PORT{0};
114121
/**
115122
* Network address.
116123
*/
124+
// CNetAddr is defined here for IPv6 or IPv4
117125
class CNetAddr
118126
{
119127
protected:
@@ -164,8 +172,12 @@ class CNetAddr
164172
* @returns Whether the operation was successful.
165173
* @see CNetAddr::IsTor(), CNetAddr::IsI2P()
166174
*/
175+
// Hmmm... looks like hostnames (DNS) *can* fit after all?
167176
bool SetSpecial(const std::string& addr);
168177

178+
// What might this look like??
179+
bool SetHostname(const std::string& addr);
180+
169181
bool IsBindAny() const; // INADDR_ANY equivalent
170182
bool IsIPv4() const; // IPv4 mapped address (::FFFF:0:0/96, 0.0.0.0/0)
171183
bool IsIPv6() const; // IPv6 address (not mapped IPv4, not Tor)
@@ -191,6 +203,7 @@ class CNetAddr
191203
bool IsRoutable() const;
192204
bool IsInternal() const;
193205
bool IsValid() const;
206+
bool IsHostname() const;
194207

195208
/**
196209
* Check if the current object can be serialized in pre-ADDRv2/BIP155 format.
@@ -282,6 +295,8 @@ class CNetAddr
282295
TORV3 = 4,
283296
I2P = 5,
284297
CJDNS = 6,
298+
// add Hostname support here (and rename the enum?)
299+
HOSTNAME = 1993,
285300
};
286301

287302
/**
@@ -339,6 +354,7 @@ class CNetAddr
339354
case NET_ONION:
340355
case NET_I2P:
341356
case NET_CJDNS:
357+
case NET_HOSTNAME:
342358
break;
343359
case NET_UNROUTABLE:
344360
case NET_MAX:
@@ -518,6 +534,7 @@ class CSubNet
518534
};
519535

520536
/** A combination of a network address (CNetAddr) and a (TCP) port */
537+
// CService is defined here
521538
class CService : public CNetAddr
522539
{
523540
protected:

src/netbase.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ enum Network ParseNetwork(const std::string& net_in) {
9090
if (net == "ipv4") return NET_IPV4;
9191
if (net == "ipv6") return NET_IPV6;
9292
if (net == "onion") return NET_ONION;
93+
if (net == "hostname") return NET_HOSTNAME;
9394
if (net == "tor") {
9495
LogPrintf("Warning: net name 'tor' is deprecated and will be removed in the future. You should use 'onion' instead.\n");
9596
return NET_ONION;
@@ -109,6 +110,7 @@ std::string GetNetworkName(enum Network net)
109110
case NET_ONION: return "onion";
110111
case NET_I2P: return "i2p";
111112
case NET_CJDNS: return "cjdns";
113+
case NET_HOSTNAME: return "hostname";
112114
case NET_INTERNAL: return "internal";
113115
case NET_MAX: assert(false);
114116
} // no default case, so the compiler can warn about missing cases
@@ -121,7 +123,7 @@ std::vector<std::string> GetNetworkNames(bool append_unroutable)
121123
std::vector<std::string> names;
122124
for (int n = 0; n < NET_MAX; ++n) {
123125
const enum Network network{static_cast<Network>(n)};
124-
if (network == NET_UNROUTABLE || network == NET_CJDNS || network == NET_INTERNAL) continue;
126+
if (network == NET_UNROUTABLE || network == NET_HOSTNAME || network == NET_CJDNS || network == NET_INTERNAL) continue;
125127
names.emplace_back(GetNetworkName(network));
126128
}
127129
if (append_unroutable) {

src/rpc/evo.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -620,11 +620,12 @@ static UniValue protx_register_common_wrapper(const JSONRPCRequest& request,
620620
size_t paramIdx = 0;
621621

622622
CMutableTransaction tx;
623-
tx.nVersion = 3;
623+
tx.nVersion = 3; // EVO SEND!!
624624
tx.nType = TRANSACTION_PROVIDER_REGISTER;
625625

626626
const bool use_legacy = isV19active ? specific_legacy_bls_scheme : true;
627627

628+
// This is the type that packs the IP presently
628629
CProRegTx ptx;
629630
ptx.nType = mnType;
630631

@@ -655,6 +656,7 @@ static UniValue protx_register_common_wrapper(const JSONRPCRequest& request,
655656
wallet->LockCoin(ptx.collateralOutpoint);
656657
}
657658

659+
// paramIdx is now for hostnameAndPort
658660
if (request.params[paramIdx].get_str() != "") {
659661
if (!Lookup(request.params[paramIdx].get_str().c_str(), ptx.addr, Params().GetDefaultPort(), false)) {
660662
throw std::runtime_error(strprintf("invalid network address %s", request.params[paramIdx].get_str()));

src/rpc/net.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static UniValue getpeerinfo(const JSONRPCRequest& request)
8787
{
8888
{
8989
{RPCResult::Type::NUM, "id", "Peer index"},
90-
{RPCResult::Type::STR, "addr", "(host:port) The IP address and port of the peer"},
90+
{RPCResult::Type::STR, "addr", "(hostname:port) The Hostname (or IP address) and port of the peer"},
9191
{RPCResult::Type::STR, "addrbind", "(ip:port) Bind address of the connection to the peer"},
9292
{RPCResult::Type::STR, "addrlocal", "(ip:port) Local address as reported by the peer"},
9393
{RPCResult::Type::STR, "network", "Network (" + Join(GetNetworkNames(/* append_unroutable */ true), ", ") + ")"},

0 commit comments

Comments
 (0)