mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-20 13:37:28 +02:00
Merge e3b474c548 into merged_master (Bitcoin PR #20140)
This commit is contained in:
commit
ff121d071d
3 changed files with 31 additions and 2 deletions
|
|
@ -184,7 +184,7 @@ void BanMan::SweepBanned()
|
|||
while (it != m_banned.end()) {
|
||||
CSubNet sub_net = (*it).first;
|
||||
CBanEntry ban_entry = (*it).second;
|
||||
if (now > ban_entry.nBanUntil) {
|
||||
if (!sub_net.IsValid() || now > ban_entry.nBanUntil) {
|
||||
m_banned.erase(it++);
|
||||
m_is_dirty = true;
|
||||
notify_ui = true;
|
||||
|
|
|
|||
|
|
@ -1109,6 +1109,17 @@ bool CSubNet::IsValid() const
|
|||
return valid;
|
||||
}
|
||||
|
||||
bool CSubNet::SanityCheck() const
|
||||
{
|
||||
if (!(network.IsIPv4() || network.IsIPv6())) return false;
|
||||
|
||||
for (size_t x = 0; x < network.m_addr.size(); ++x) {
|
||||
if (network.m_addr[x] & ~netmask[x]) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator==(const CSubNet& a, const CSubNet& b)
|
||||
{
|
||||
return a.valid == b.valid && a.network == b.network && !memcmp(a.netmask, b.netmask, 16);
|
||||
|
|
|
|||
|
|
@ -459,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);
|
||||
|
|
@ -476,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 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue