mirror of
https://github.com/SChernykh/p2pool.git
synced 2025-01-05 10:19:23 +00:00
Don't ban localhost
This commit is contained in:
parent
6b4640c413
commit
8f27d940e3
2 changed files with 16 additions and 0 deletions
|
@ -309,6 +309,14 @@ struct raw_ip
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCEINLINE bool operator!=(const raw_ip& other) const { return !operator==(other); }
|
FORCEINLINE bool operator!=(const raw_ip& other) const { return !operator==(other); }
|
||||||
|
|
||||||
|
FORCEINLINE bool is_localhost() const
|
||||||
|
{
|
||||||
|
static constexpr raw_ip localhost_ipv4 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x01 };
|
||||||
|
static constexpr raw_ip localhost_ipv6 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
|
||||||
|
|
||||||
|
return (*this == localhost_ipv4) || (*this == localhost_ipv6);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert(sizeof(raw_ip) == 16, "struct raw_ip has invalid size");
|
static_assert(sizeof(raw_ip) == 16, "struct raw_ip has invalid size");
|
||||||
|
|
|
@ -322,6 +322,10 @@ void TCPServer<READ_BUF_SIZE, WRITE_BUF_SIZE>::on_connect_failed(bool, const raw
|
||||||
template<size_t READ_BUF_SIZE, size_t WRITE_BUF_SIZE>
|
template<size_t READ_BUF_SIZE, size_t WRITE_BUF_SIZE>
|
||||||
bool TCPServer<READ_BUF_SIZE, WRITE_BUF_SIZE>::is_banned(const raw_ip& ip)
|
bool TCPServer<READ_BUF_SIZE, WRITE_BUF_SIZE>::is_banned(const raw_ip& ip)
|
||||||
{
|
{
|
||||||
|
if (ip.is_localhost()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const auto cur_time = std::chrono::steady_clock::now();
|
const auto cur_time = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
MutexLock lock(m_bansLock);
|
MutexLock lock(m_bansLock);
|
||||||
|
@ -495,6 +499,10 @@ void TCPServer<READ_BUF_SIZE, WRITE_BUF_SIZE>::print_status()
|
||||||
template<size_t READ_BUF_SIZE, size_t WRITE_BUF_SIZE>
|
template<size_t READ_BUF_SIZE, size_t WRITE_BUF_SIZE>
|
||||||
void TCPServer<READ_BUF_SIZE, WRITE_BUF_SIZE>::ban(const raw_ip& ip, uint64_t seconds)
|
void TCPServer<READ_BUF_SIZE, WRITE_BUF_SIZE>::ban(const raw_ip& ip, uint64_t seconds)
|
||||||
{
|
{
|
||||||
|
if (ip.is_localhost()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const auto ban_time = std::chrono::steady_clock::now() + std::chrono::seconds(seconds);
|
const auto ban_time = std::chrono::steady_clock::now() + std::chrono::seconds(seconds);
|
||||||
|
|
||||||
MutexLock lock(m_bansLock);
|
MutexLock lock(m_bansLock);
|
||||||
|
|
Loading…
Reference in a new issue