Skip to content

Commit

Permalink
bitcoin bitcoin#17812: extract conditional to bool CNetAddr::IsHeNet
Browse files Browse the repository at this point in the history
  • Loading branch information
kwvg committed Mar 9, 2021
1 parent 7dc09bd commit 7a9f8d6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/netaddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ bool CNetAddr::IsRFC7343() const
GetByte(13) == 0x00 && (GetByte(12) & 0xF0) == 0x20;
}

bool CNetAddr::IsHeNet() const
{
return (GetByte(15) == 0x20 && GetByte(14) == 0x01 && GetByte(13) == 0x04 && GetByte(12) == 0x70);
}

bool CNetAddr::IsTor() const { return m_net == NET_ONION; }

bool CNetAddr::IsLocal() const
Expand Down Expand Up @@ -440,12 +445,15 @@ std::vector<unsigned char> CNetAddr::GetGroup(const std::vector<bool> &asmap) co
nStartByte = 6;
nBits = 4;
}
// for he.net, use /36 groups
else if (GetByte(15) == 0x20 && GetByte(14) == 0x01 && GetByte(13) == 0x04 && GetByte(12) == 0x70)
else if (IsHeNet())
{
// for he.net, use /36 groups
nBits = 36;
// for the rest of the IPv6 network, use /32 groups
else
}
else {
// for the rest of the IPv6 network, use /32 groups
nBits = 32;
}

// If asmap is supplied and the address is IPv4/IPv6,
// ignore nBits and use 32/128 bits to obtain ASN from asmap.
Expand Down
1 change: 1 addition & 0 deletions src/netaddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class CNetAddr
bool IsRFC4862() const; // IPv6 autoconfig (FE80::/64)
bool IsRFC6052() const; // IPv6 well-known prefix (64:FF9B::/96)
bool IsRFC6145() const; // IPv6 IPv4-translated address (::FFFF:0:0:0/96)
bool IsHeNet() const; // IPv6 Hurricane Electric - https://he.net (2001:0470::/36)
bool IsTor() const;
bool IsLocal() const;
bool IsRoutable() const;
Expand Down

0 comments on commit 7a9f8d6

Please sign in to comment.