Changeset View
Changeset View
Standalone View
Standalone View
src/netaddress.cpp
Show First 20 Lines • Show All 491 Lines • ▼ Show 20 Lines | |||||
* @returns Whether or not this is a dummy address that represents a name. | * @returns Whether or not this is a dummy address that represents a name. | ||||
* | * | ||||
* @see CNetAddr::SetInternal(const std::string &) | * @see CNetAddr::SetInternal(const std::string &) | ||||
*/ | */ | ||||
bool CNetAddr::IsInternal() const { | bool CNetAddr::IsInternal() const { | ||||
return m_net == NET_INTERNAL; | return m_net == NET_INTERNAL; | ||||
} | } | ||||
bool CNetAddr::IsAddrV1Compatible() const { | |||||
switch (m_net) { | |||||
case NET_IPV4: | |||||
case NET_IPV6: | |||||
case NET_INTERNAL: | |||||
return true; | |||||
case NET_ONION: | |||||
return m_addr.size() == ADDR_TORV2_SIZE; | |||||
case NET_I2P: | |||||
case NET_CJDNS: | |||||
return false; | |||||
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 | |||||
assert(false); | |||||
} // no default case, so the compiler can warn about missing cases | |||||
assert(false); | |||||
} | |||||
enum Network CNetAddr::GetNetwork() const { | enum Network CNetAddr::GetNetwork() const { | ||||
if (IsInternal()) { | if (IsInternal()) { | ||||
return NET_INTERNAL; | return NET_INTERNAL; | ||||
} | } | ||||
if (!IsRoutable()) { | if (!IsRoutable()) { | ||||
return NET_UNROUTABLE; | return NET_UNROUTABLE; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 262 Lines • ▼ Show 20 Lines | if (nBits > 0) { | ||||
assert(num_bytes < m_addr.size()); | assert(num_bytes < m_addr.size()); | ||||
vchRet.push_back(m_addr[num_bytes] | ((1 << (8 - nBits)) - 1)); | vchRet.push_back(m_addr[num_bytes] | ((1 << (8 - nBits)) - 1)); | ||||
} | } | ||||
return vchRet; | return vchRet; | ||||
} | } | ||||
std::vector<uint8_t> CNetAddr::GetAddrBytes() const { | std::vector<uint8_t> CNetAddr::GetAddrBytes() const { | ||||
if (IsAddrV1Compatible()) { | |||||
uint8_t serialized[V1_SERIALIZATION_SIZE]; | uint8_t serialized[V1_SERIALIZATION_SIZE]; | ||||
SerializeV1Array(serialized); | SerializeV1Array(serialized); | ||||
return {std::begin(serialized), std::end(serialized)}; | return {std::begin(serialized), std::end(serialized)}; | ||||
} | } | ||||
return std::vector<uint8_t>(m_addr.begin(), m_addr.end()); | |||||
} | |||||
uint64_t CNetAddr::GetHash() const { | uint64_t CNetAddr::GetHash() const { | ||||
uint256 hash = Hash(m_addr); | uint256 hash = Hash(m_addr); | ||||
uint64_t nRet; | uint64_t nRet; | ||||
memcpy(&nRet, &hash, sizeof(nRet)); | memcpy(&nRet, &hash, sizeof(nRet)); | ||||
return nRet; | return nRet; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 384 Lines • Show Last 20 Lines |