Skip to content

Commit

Permalink
fix: unbreak hostname support
Browse files Browse the repository at this point in the history
  • Loading branch information
coolaj86 committed Mar 1, 2024
1 parent 5b08d0f commit a97331d
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/evo/providertx.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class CBlockIndex;
class CCoinsViewCache;
class TxValidationState;

// CProRegTx is defined here
class CProRegTx
{
public:
Expand Down
10 changes: 10 additions & 0 deletions src/netaddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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).
Expand Down
17 changes: 17 additions & 0 deletions src/netaddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -191,6 +203,7 @@ class CNetAddr
bool IsRoutable() const;
bool IsInternal() const;
bool IsValid() const;
bool IsHostname() const;

/**
* Check if the current object can be serialized in pre-ADDRv2/BIP155 format.
Expand Down Expand Up @@ -282,6 +295,8 @@ class CNetAddr
TORV3 = 4,
I2P = 5,
CJDNS = 6,
// add Hostname support here (and rename the enum?)
HOSTNAME = 1993,
};

/**
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion src/netbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -121,7 +123,7 @@ std::vector<std::string> GetNetworkNames(bool append_unroutable)
std::vector<std::string> names;
for (int n = 0; n < NET_MAX; ++n) {
const enum Network network{static_cast<Network>(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) {
Expand Down
4 changes: 3 additions & 1 deletion src/rpc/evo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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()));
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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), ", ") + ")"},
Expand Down

0 comments on commit a97331d

Please sign in to comment.