mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-11-17 00:07:47 +00:00
P2PServer: ban peers only after handshake finished and failed
This commit is contained in:
parent
541b3c653d
commit
456f5d356f
2 changed files with 20 additions and 4 deletions
|
@ -663,6 +663,7 @@ P2PServer::P2PClient::P2PClient()
|
||||||
, m_handshakeChallenge(0)
|
, m_handshakeChallenge(0)
|
||||||
, m_handshakeSolutionSent(false)
|
, m_handshakeSolutionSent(false)
|
||||||
, m_handshakeComplete(false)
|
, m_handshakeComplete(false)
|
||||||
|
, m_handshakeInvalid(false)
|
||||||
, m_listenPort(-1)
|
, m_listenPort(-1)
|
||||||
, m_lastPeerListRequest(0)
|
, m_lastPeerListRequest(0)
|
||||||
, m_lastAlive(0)
|
, m_lastAlive(0)
|
||||||
|
@ -684,6 +685,7 @@ void P2PServer::P2PClient::reset()
|
||||||
m_handshakeChallenge = 0;
|
m_handshakeChallenge = 0;
|
||||||
m_handshakeSolutionSent = false;
|
m_handshakeSolutionSent = false;
|
||||||
m_handshakeComplete = false;
|
m_handshakeComplete = false;
|
||||||
|
m_handshakeInvalid = false;
|
||||||
m_listenPort = -1;
|
m_listenPort = -1;
|
||||||
m_lastPeerListRequest = 0;
|
m_lastPeerListRequest = 0;
|
||||||
m_lastAlive = 0;
|
m_lastAlive = 0;
|
||||||
|
@ -1010,7 +1012,7 @@ void P2PServer::P2PClient::send_handshake_solution(const uint8_t (&challenge)[CH
|
||||||
memcpy(p, work->solution_salt, CHALLENGE_SIZE);
|
memcpy(p, work->solution_salt, CHALLENGE_SIZE);
|
||||||
p += CHALLENGE_SIZE;
|
p += CHALLENGE_SIZE;
|
||||||
|
|
||||||
if (work->client->m_handshakeComplete) {
|
if (work->client->m_handshakeComplete && !work->client->m_handshakeInvalid) {
|
||||||
work->client->on_after_handshake(p);
|
work->client->on_after_handshake(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1019,6 +1021,12 @@ void P2PServer::P2PClient::send_handshake_solution(const uint8_t (&challenge)[CH
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
work->client->m_handshakeSolutionSent = true;
|
work->client->m_handshakeSolutionSent = true;
|
||||||
|
|
||||||
|
if (work->client->m_handshakeInvalid) {
|
||||||
|
work->client->ban(DEFAULT_BAN_TIME);
|
||||||
|
work->server->remove_peer_from_list(work->client);
|
||||||
|
work->client->close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
work->client->close();
|
work->client->close();
|
||||||
|
@ -1119,19 +1127,26 @@ bool P2PServer::P2PClient::on_handshake_solution(const uint8_t* buf)
|
||||||
|
|
||||||
if (high) {
|
if (high) {
|
||||||
LOGWARN(5, "peer " << static_cast<char*>(m_addrString) << " handshake doesn't have enough PoW");
|
LOGWARN(5, "peer " << static_cast<char*>(m_addrString) << " handshake doesn't have enough PoW");
|
||||||
return false;
|
m_handshakeInvalid = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!check_handshake_solution(solution, solution_salt)) {
|
if (!check_handshake_solution(solution, solution_salt)) {
|
||||||
LOGWARN(5, "peer " << static_cast<char*>(m_addrString) << " handshake failed");
|
LOGWARN(5, "peer " << static_cast<char*>(m_addrString) << " handshake failed");
|
||||||
return false;
|
m_handshakeInvalid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_handshakeComplete = true;
|
m_handshakeComplete = true;
|
||||||
LOGINFO(5, "peer " << log::Gray() << static_cast<char*>(m_addrString) << log::NoColor() << " handshake completed");
|
|
||||||
|
if (!m_handshakeInvalid) {
|
||||||
|
LOGINFO(5, "peer " << log::Gray() << static_cast<char*>(m_addrString) << log::NoColor() << " handshake completed");
|
||||||
|
}
|
||||||
|
|
||||||
if (m_handshakeSolutionSent) {
|
if (m_handshakeSolutionSent) {
|
||||||
|
if (m_handshakeInvalid) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return m_owner->send(this,
|
return m_owner->send(this,
|
||||||
[this, &solution, &solution_salt](void* buf)
|
[this, &solution, &solution_salt](void* buf)
|
||||||
{
|
{
|
||||||
|
|
|
@ -103,6 +103,7 @@ public:
|
||||||
uint64_t m_handshakeChallenge;
|
uint64_t m_handshakeChallenge;
|
||||||
bool m_handshakeSolutionSent;
|
bool m_handshakeSolutionSent;
|
||||||
bool m_handshakeComplete;
|
bool m_handshakeComplete;
|
||||||
|
bool m_handshakeInvalid;
|
||||||
int m_listenPort;
|
int m_listenPort;
|
||||||
time_t m_lastPeerListRequest;
|
time_t m_lastPeerListRequest;
|
||||||
time_t m_lastAlive;
|
time_t m_lastAlive;
|
||||||
|
|
Loading…
Reference in a new issue