Skip to content

Commit 6159289

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

File tree

7 files changed

+40
-4
lines changed

7 files changed

+40
-4
lines changed

contrib/seeds/generate-seeds.py

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class BIP155Network(Enum):
4040
TORV3 = 4
4141
I2P = 5
4242
CJDNS = 6
43+
HOSTNAME = 1993
4344

4445
def name_to_bip155(addr):
4546
'''Convert address string to BIP155 (networkID, addr) tuple.'''

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

+13
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).
@@ -124,6 +134,9 @@ void CNetAddr::SetIP(const CNetAddr& ipIn)
124134
case NET_CJDNS:
125135
assert(ipIn.m_addr.size() == ADDR_CJDNS_SIZE);
126136
break;
137+
case NET_HOSTNAME:
138+
assert(ipIn.m_addr.size() <= ADDR_HOSTNAME_SIZE);
139+
break;
127140
case NET_INTERNAL:
128141
assert(ipIn.m_addr.size() == ADDR_INTERNAL_SIZE);
129142
break;

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)
@@ -187,6 +199,7 @@ class CNetAddr
187199
bool IsTor() const;
188200
bool IsI2P() const;
189201
bool IsCJDNS() const;
202+
bool IsHostname() const;
190203
bool IsLocal() const;
191204
bool IsRoutable() const;
192205
bool IsInternal() const;
@@ -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

+2-2
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), ", ") + ")"},
@@ -461,7 +461,7 @@ static UniValue GetNetworksInfo()
461461
UniValue networks(UniValue::VARR);
462462
for (int n = 0; n < NET_MAX; ++n) {
463463
enum Network network = static_cast<enum Network>(n);
464-
if (network == NET_UNROUTABLE || network == NET_CJDNS || network == NET_INTERNAL) continue;
464+
if (network == NET_UNROUTABLE || network == NET_HOSTNAME || network == NET_CJDNS || network == NET_INTERNAL) continue;
465465
proxyType proxy;
466466
UniValue obj(UniValue::VOBJ);
467467
GetProxy(network, proxy);

0 commit comments

Comments
 (0)