mirror of
https://github.com/SChernykh/p2pool.git
synced 2025-01-24 03:05:57 +00:00
StartumServer: disconnect and ban inactive clients
This commit is contained in:
parent
8767ef9e19
commit
9f449320b5
2 changed files with 18 additions and 2 deletions
|
@ -516,6 +516,8 @@ void StratumServer::on_blobs_ready()
|
||||||
|
|
||||||
size_t numClientsProcessed = 0;
|
size_t numClientsProcessed = 0;
|
||||||
uint32_t extra_nonce = 0;
|
uint32_t extra_nonce = 0;
|
||||||
|
|
||||||
|
const time_t cur_time = time(nullptr);
|
||||||
{
|
{
|
||||||
MutexLock lock2(m_clientsListLock);
|
MutexLock lock2(m_clientsListLock);
|
||||||
|
|
||||||
|
@ -523,7 +525,12 @@ void StratumServer::on_blobs_ready()
|
||||||
++numClientsProcessed;
|
++numClientsProcessed;
|
||||||
|
|
||||||
if (!client->m_rpcId) {
|
if (!client->m_rpcId) {
|
||||||
// Not logged in yet, on_login() will send the job to this client
|
// Not logged in yet, on_login() will send the job to this client. Also close inactive connections.
|
||||||
|
if (cur_time >= client->m_connectedTime + 10) {
|
||||||
|
LOGWARN(4, "client " << static_cast<char*>(client->m_addrString) << " didn't send login data");
|
||||||
|
client->ban(DEFAULT_BAN_TIME);
|
||||||
|
client->close();
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -760,6 +767,7 @@ void StratumServer::on_after_share_found(uv_work_t* req, int /*status*/)
|
||||||
|
|
||||||
StratumServer::StratumClient::StratumClient()
|
StratumServer::StratumClient::StratumClient()
|
||||||
: m_rpcId(0)
|
: m_rpcId(0)
|
||||||
|
, m_connectedTime(0)
|
||||||
, m_jobs{}
|
, m_jobs{}
|
||||||
, m_perConnectionJobId(0)
|
, m_perConnectionJobId(0)
|
||||||
, m_customDiff{}
|
, m_customDiff{}
|
||||||
|
@ -776,12 +784,19 @@ void StratumServer::StratumClient::reset()
|
||||||
{
|
{
|
||||||
Client::reset();
|
Client::reset();
|
||||||
m_rpcId = 0;
|
m_rpcId = 0;
|
||||||
|
m_connectedTime = 0;
|
||||||
memset(m_jobs, 0, sizeof(m_jobs));
|
memset(m_jobs, 0, sizeof(m_jobs));
|
||||||
m_perConnectionJobId = 0;
|
m_perConnectionJobId = 0;
|
||||||
m_customDiff = {};
|
m_customDiff = {};
|
||||||
m_customUser.clear();
|
m_customUser.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool StratumServer::StratumClient::on_connect()
|
||||||
|
{
|
||||||
|
m_connectedTime = time(nullptr);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool StratumServer::StratumClient::on_read(char* data, uint32_t size)
|
bool StratumServer::StratumClient::on_read(char* data, uint32_t size)
|
||||||
{
|
{
|
||||||
if ((data != m_readBuf + m_numRead) || (data + size > m_readBuf + sizeof(m_readBuf))) {
|
if ((data != m_readBuf + m_numRead) || (data + size > m_readBuf + sizeof(m_readBuf))) {
|
||||||
|
|
|
@ -45,7 +45,7 @@ public:
|
||||||
static Client* allocate() { return new StratumClient(); }
|
static Client* allocate() { return new StratumClient(); }
|
||||||
|
|
||||||
void reset() override;
|
void reset() override;
|
||||||
bool on_connect() override { return true; }
|
bool on_connect() override;
|
||||||
bool on_read(char* data, uint32_t size) override;
|
bool on_read(char* data, uint32_t size) override;
|
||||||
|
|
||||||
bool process_request(char* data, uint32_t size);
|
bool process_request(char* data, uint32_t size);
|
||||||
|
@ -53,6 +53,7 @@ public:
|
||||||
bool process_submit(rapidjson::Document& doc, uint32_t id);
|
bool process_submit(rapidjson::Document& doc, uint32_t id);
|
||||||
|
|
||||||
uint32_t m_rpcId;
|
uint32_t m_rpcId;
|
||||||
|
time_t m_connectedTime;
|
||||||
|
|
||||||
uv_mutex_t m_jobsLock;
|
uv_mutex_t m_jobsLock;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue