aboutsummaryrefslogtreecommitdiff
path: root/src/netaddress.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/netaddress.h')
-rw-r--r--src/netaddress.h44
1 files changed, 40 insertions, 4 deletions
diff --git a/src/netaddress.h b/src/netaddress.h
index 708cbd2095..29b2eaafeb 100644
--- a/src/netaddress.h
+++ b/src/netaddress.h
@@ -130,7 +130,11 @@ class CNetAddr
*/
Network m_net{NET_IPV6};
- uint32_t scopeId{0}; // for scoped/link-local ipv6 addresses
+ /**
+ * Scope id if scoped/link-local IPV6 address.
+ * See https://tools.ietf.org/html/rfc4007
+ */
+ uint32_t m_scope_id{0};
public:
CNetAddr();
@@ -173,12 +177,18 @@ class CNetAddr
bool IsRoutable() const;
bool IsInternal() const;
bool IsValid() const;
+
+ /**
+ * Check if the current object can be serialized in pre-ADDRv2/BIP155 format.
+ */
+ bool IsAddrV1Compatible() const;
+
enum Network GetNetwork() const;
std::string ToString() const;
std::string ToStringIP() const;
uint64_t GetHash() const;
bool GetInAddr(struct in_addr* pipv4Addr) const;
- uint32_t GetNetClass() const;
+ Network GetNetClass() const;
//! For IPv4, mapped IPv4, SIIT translated IPv4, Teredo, 6to4 tunneled addresses, return the relevant IPv4 address as a uint32.
uint32_t GetLinkedIPv4() const;
@@ -202,6 +212,14 @@ class CNetAddr
friend bool operator<(const CNetAddr& a, const CNetAddr& b);
/**
+ * Whether this address should be relayed to other peers even if we can't reach it ourselves.
+ */
+ bool IsRelayable() const
+ {
+ return IsIPv4() || IsIPv6() || IsTor();
+ }
+
+ /**
* Serialize to a stream.
*/
template <typename Stream>
@@ -388,7 +406,7 @@ class CNetAddr
"Address too long: %u > %u", address_size, MAX_ADDRV2_SIZE));
}
- scopeId = 0;
+ m_scope_id = 0;
if (SetNetFromBIP155Network(bip155_net, address_size)) {
m_addr.resize(address_size);
@@ -441,6 +459,8 @@ class CSubNet
/// Is this value valid? (only used to signal parse errors)
bool valid;
+ bool SanityCheck() const;
+
public:
CSubNet();
CSubNet(const CNetAddr& addr, uint8_t mask);
@@ -458,7 +478,23 @@ class CSubNet
friend bool operator!=(const CSubNet& a, const CSubNet& b) { return !(a == b); }
friend bool operator<(const CSubNet& a, const CSubNet& b);
- SERIALIZE_METHODS(CSubNet, obj) { READWRITE(obj.network, obj.netmask, obj.valid); }
+ SERIALIZE_METHODS(CSubNet, obj)
+ {
+ READWRITE(obj.network);
+ if (obj.network.IsIPv4()) {
+ // Before commit 102867c587f5f7954232fb8ed8e85cda78bb4d32, CSubNet used the last 4 bytes of netmask
+ // to store the relevant bytes for an IPv4 mask. For compatiblity reasons, keep doing so in
+ // serialized form.
+ unsigned char dummy[12] = {0};
+ READWRITE(dummy);
+ READWRITE(MakeSpan(obj.netmask).first(4));
+ } else {
+ READWRITE(obj.netmask);
+ }
+ READWRITE(obj.valid);
+ // Mark invalid if the result doesn't pass sanity checking.
+ SER_READ(obj, if (obj.valid) obj.valid = obj.SanityCheck());
+ }
};
/** A combination of a network address (CNetAddr) and a (TCP) port */