mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-12-23 03:49:23 +00:00
P2PServer: don't add banned peers back to the peer list
This commit is contained in:
parent
3804bfb0ba
commit
81a12158fc
3 changed files with 28 additions and 21 deletions
|
@ -364,7 +364,7 @@ void P2PServer::load_saved_peer_list()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!already_added) {
|
if (!already_added && !is_banned(p.m_addr)) {
|
||||||
m_peerList.push_back(p);
|
m_peerList.push_back(p);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -383,7 +383,9 @@ void P2PServer::update_peer_in_list(bool is_v6, const raw_ip& ip, int port)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_peerList.emplace_back(Peer{ is_v6, ip, port, 0 });
|
if (!is_banned(ip)) {
|
||||||
|
m_peerList.emplace_back(Peer{ is_v6, ip, port, 0 });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void P2PServer::remove_peer_from_list(P2PClient* client)
|
void P2PServer::remove_peer_from_list(P2PClient* client)
|
||||||
|
@ -1343,7 +1345,7 @@ bool P2PServer::P2PClient::on_peer_list_response(const uint8_t* buf) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!already_added) {
|
if (!already_added && !server->is_banned(ip)) {
|
||||||
server->m_peerList.emplace_back(Peer{ is_v6, ip, port, 0 });
|
server->m_peerList.emplace_back(Peer{ is_v6, ip, port, 0 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -193,6 +193,8 @@ protected:
|
||||||
uv_mutex_t m_bansLock;
|
uv_mutex_t m_bansLock;
|
||||||
std::map<raw_ip, time_t> m_bans;
|
std::map<raw_ip, time_t> m_bans;
|
||||||
|
|
||||||
|
bool is_banned(const raw_ip& ip);
|
||||||
|
|
||||||
uv_mutex_t m_pendingConnectionsLock;
|
uv_mutex_t m_pendingConnectionsLock;
|
||||||
std::set<raw_ip> m_pendingConnections;
|
std::set<raw_ip> m_pendingConnections;
|
||||||
|
|
||||||
|
|
|
@ -312,18 +312,26 @@ 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>
|
||||||
|
bool TCPServer<READ_BUF_SIZE, WRITE_BUF_SIZE>::is_banned(const raw_ip& ip)
|
||||||
|
{
|
||||||
|
MutexLock lock(m_bansLock);
|
||||||
|
|
||||||
|
auto it = m_bans.find(ip);
|
||||||
|
if ((it != m_bans.end()) && (time(nullptr) < it->second)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
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>::connect_to_peer_nolock(Client* client, bool is_v6, const sockaddr* addr)
|
bool TCPServer<READ_BUF_SIZE, WRITE_BUF_SIZE>::connect_to_peer_nolock(Client* client, bool is_v6, const sockaddr* addr)
|
||||||
{
|
{
|
||||||
{
|
if (is_banned(client->m_addr)) {
|
||||||
MutexLock lock(m_bansLock);
|
LOGINFO(5, "peer " << log::Gray() << static_cast<char*>(client->m_addrString) << log::NoColor() << " is banned, not connecting to it");
|
||||||
|
m_preallocatedClients.push_back(client);
|
||||||
auto it = m_bans.find(client->m_addr);
|
return false;
|
||||||
if ((it != m_bans.end()) && (time(nullptr) < it->second)) {
|
|
||||||
LOGINFO(5, "peer " << log::Gray() << static_cast<char*>(client->m_addrString) << log::NoColor() << " is banned, not connecting to it");
|
|
||||||
m_preallocatedClients.push_back(client);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
client->m_isV6 = is_v6;
|
client->m_isV6 = is_v6;
|
||||||
|
@ -719,15 +727,10 @@ void TCPServer<READ_BUF_SIZE, WRITE_BUF_SIZE>::on_new_client_nolock(uv_stream_t*
|
||||||
client->m_isIncoming = false;
|
client->m_isIncoming = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
if (is_banned(client->m_addr)) {
|
||||||
MutexLock lock(m_bansLock);
|
LOGINFO(5, "peer " << log::Gray() << static_cast<char*>(client->m_addrString) << log::NoColor() << " is banned, disconnecting");
|
||||||
|
client->close();
|
||||||
auto it = m_bans.find(client->m_addr);
|
return;
|
||||||
if ((it != m_bans.end()) && (time(nullptr) < it->second)) {
|
|
||||||
LOGINFO(5, "peer " << log::Gray() << static_cast<char*>(client->m_addrString) << log::NoColor() << " is banned, disconnecting");
|
|
||||||
client->close();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client->m_owner->m_finished.load() || !client->on_connect()) {
|
if (client->m_owner->m_finished.load() || !client->on_connect()) {
|
||||||
|
|
Loading…
Reference in a new issue