Make ban time of stratum clients configurable via '--stratum-ban-time' option
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
--stratum Comma-separated list of IP:port for stratum server to listen on
|
--stratum Comma-separated list of IP:port for stratum server to listen on
|
||||||
--p2p Comma-separated list of IP:port for p2p server to listen on
|
--p2p Comma-separated list of IP:port for p2p server to listen on
|
||||||
--addpeers Comma-separated list of IP:port of other p2pool nodes to connect to
|
--addpeers Comma-separated list of IP:port of other p2pool nodes to connect to
|
||||||
|
--stratum-ban-time N Number of seconds to ban misbehaving stratum client, default is 600
|
||||||
--light-mode Don't allocate RandomX dataset, saves 2GB of RAM
|
--light-mode Don't allocate RandomX dataset, saves 2GB of RAM
|
||||||
--loglevel Verbosity of the log, integer number between 0 and 6
|
--loglevel Verbosity of the log, integer number between 0 and 6
|
||||||
--data-dir Path to store general p2pool files (log, cache, peer data, etc.), default is current directory
|
--data-dir Path to store general p2pool files (log, cache, peer data, etc.), default is current directory
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ void p2pool_usage()
|
|||||||
"--stratum Comma-separated list of IP:port for stratum server to listen on\n"
|
"--stratum Comma-separated list of IP:port for stratum server to listen on\n"
|
||||||
"--p2p Comma-separated list of IP:port for p2p server to listen on\n"
|
"--p2p Comma-separated list of IP:port for p2p server to listen on\n"
|
||||||
"--addpeers Comma-separated list of IP:port of other p2pool nodes to connect to\n"
|
"--addpeers Comma-separated list of IP:port of other p2pool nodes to connect to\n"
|
||||||
|
"--stratum-ban-time N Number of seconds to ban misbehaving stratum client, default is %u\n"
|
||||||
"--light-mode Don't allocate RandomX dataset, saves 2GB of RAM\n"
|
"--light-mode Don't allocate RandomX dataset, saves 2GB of RAM\n"
|
||||||
"--loglevel Verbosity of the log, integer number between 0 and %d\n"
|
"--loglevel Verbosity of the log, integer number between 0 and %d\n"
|
||||||
"--data-dir Path to store general p2pool files (log, cache, peer data, etc.), default is current directory\n"
|
"--data-dir Path to store general p2pool files (log, cache, peer data, etc.), default is current directory\n"
|
||||||
@@ -102,6 +103,7 @@ void p2pool_usage()
|
|||||||
"Example command line:\n\n"
|
"Example command line:\n\n"
|
||||||
"%s --host 127.0.0.1 --rpc-port 18081 --zmq-port 18083 --wallet YOUR_WALLET_ADDRESS --stratum 0.0.0.0:%d --p2p 0.0.0.0:%d\n\n",
|
"%s --host 127.0.0.1 --rpc-port 18081 --zmq-port 18083 --wallet YOUR_WALLET_ADDRESS --stratum 0.0.0.0:%d --p2p 0.0.0.0:%d\n\n",
|
||||||
p2pool::VERSION,
|
p2pool::VERSION,
|
||||||
|
static_cast<uint32_t>(p2pool::DEFAULT_STRATUM_BAN_TIME),
|
||||||
p2pool::log::MAX_GLOBAL_LOG_LEVEL,
|
p2pool::log::MAX_GLOBAL_LOG_LEVEL,
|
||||||
p2pool::DEFAULT_P2P_PORT,
|
p2pool::DEFAULT_P2P_PORT,
|
||||||
p2pool::DEFAULT_P2P_PORT_MINI,
|
p2pool::DEFAULT_P2P_PORT_MINI,
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ void p2pool_usage();
|
|||||||
|
|
||||||
namespace p2pool {
|
namespace p2pool {
|
||||||
|
|
||||||
|
static constexpr uint64_t MIN_STRATUM_BAN_TIME = UINT64_C(1);
|
||||||
|
static constexpr uint64_t MAX_STRATUM_BAN_TIME = (UINT64_C(1) << 34) - 1;
|
||||||
|
|
||||||
Params::Params(int argc, char* const argv[])
|
Params::Params(int argc, char* const argv[])
|
||||||
{
|
{
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
@@ -79,6 +82,11 @@ Params::Params(int argc, char* const argv[])
|
|||||||
ok = true;
|
ok = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((strcmp(argv[i], "--stratum-ban-time") == 0) && (i + 1 < argc)) {
|
||||||
|
m_stratumBanTime = strtoull(argv[++i], nullptr, 10);
|
||||||
|
ok = true;
|
||||||
|
}
|
||||||
|
|
||||||
if ((strcmp(argv[i], "--p2p") == 0) && (i + 1 < argc)) {
|
if ((strcmp(argv[i], "--p2p") == 0) && (i + 1 < argc)) {
|
||||||
m_p2pAddresses = argv[++i];
|
m_p2pAddresses = argv[++i];
|
||||||
ok = true;
|
ok = true;
|
||||||
@@ -284,6 +292,14 @@ Params::Params(int argc, char* const argv[])
|
|||||||
|
|
||||||
m_stratumAddresses = buf;
|
m_stratumAddresses = buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(m_stratumBanTime < MIN_STRATUM_BAN_TIME) {
|
||||||
|
LOGWARN(1, "Value for --stratum-ban-time is too low, adjusting to " << MIN_STRATUM_BAN_TIME);
|
||||||
|
m_stratumBanTime = MIN_STRATUM_BAN_TIME;
|
||||||
|
} else if(m_stratumBanTime > MAX_STRATUM_BAN_TIME) {
|
||||||
|
LOGWARN(1, "Value for --stratum-ban-time is too high, adjusting to " << MAX_STRATUM_BAN_TIME);
|
||||||
|
m_stratumBanTime = MAX_STRATUM_BAN_TIME;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Params::valid() const
|
bool Params::valid() const
|
||||||
|
|||||||
@@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
namespace p2pool {
|
namespace p2pool {
|
||||||
|
|
||||||
|
static constexpr uint64_t DEFAULT_STRATUM_BAN_TIME = 600;
|
||||||
|
|
||||||
struct Params
|
struct Params
|
||||||
{
|
{
|
||||||
Params(int argc, char* const argv[]);
|
Params(int argc, char* const argv[]);
|
||||||
@@ -74,6 +76,7 @@ struct Params
|
|||||||
std::string m_p2pPeerList;
|
std::string m_p2pPeerList;
|
||||||
std::string m_sidechainConfig;
|
std::string m_sidechainConfig;
|
||||||
std::string m_apiPath;
|
std::string m_apiPath;
|
||||||
|
uint64_t m_stratumBanTime = DEFAULT_STRATUM_BAN_TIME;
|
||||||
bool m_localStats = false;
|
bool m_localStats = false;
|
||||||
bool m_blockCache = true;
|
bool m_blockCache = true;
|
||||||
#ifdef WITH_RANDOMX
|
#ifdef WITH_RANDOMX
|
||||||
|
|||||||
@@ -29,7 +29,6 @@
|
|||||||
LOG_CATEGORY(StratumServer)
|
LOG_CATEGORY(StratumServer)
|
||||||
|
|
||||||
static constexpr int DEFAULT_BACKLOG = 128;
|
static constexpr int DEFAULT_BACKLOG = 128;
|
||||||
static constexpr uint64_t DEFAULT_BAN_TIME = 600;
|
|
||||||
static constexpr uint64_t MIN_DIFF = 1000;
|
static constexpr uint64_t MIN_DIFF = 1000;
|
||||||
static constexpr uint64_t AUTO_DIFF_TARGET_TIME = 30;
|
static constexpr uint64_t AUTO_DIFF_TARGET_TIME = 30;
|
||||||
|
|
||||||
@@ -84,6 +83,7 @@ StratumServer::StratumServer(p2pool* pool)
|
|||||||
m_showWorkersAsync.data = this;
|
m_showWorkersAsync.data = this;
|
||||||
|
|
||||||
const Params& params = pool->params();
|
const Params& params = pool->params();
|
||||||
|
m_banTime = params.m_stratumBanTime;
|
||||||
start_listening(params.m_stratumAddresses, params.m_upnp && params.m_upnpStratum);
|
start_listening(params.m_stratumAddresses, params.m_upnp && params.m_upnpStratum);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -791,7 +791,7 @@ void StratumServer::on_blobs_ready()
|
|||||||
// Not logged in yet, on_login() will send the job to this client. Also close inactive connections.
|
// Not logged in yet, on_login() will send the job to this client. Also close inactive connections.
|
||||||
if (cur_time >= client->m_connectedTime + 10) {
|
if (cur_time >= client->m_connectedTime + 10) {
|
||||||
LOGWARN(4, "client " << static_cast<char*>(client->m_addrString) << " didn't send login data");
|
LOGWARN(4, "client " << static_cast<char*>(client->m_addrString) << " didn't send login data");
|
||||||
client->ban(DEFAULT_BAN_TIME);
|
client->ban(m_banTime);
|
||||||
client->close();
|
client->close();
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@@ -1106,7 +1106,7 @@ void StratumServer::on_after_share_found(uv_work_t* req, int /*status*/)
|
|||||||
client->m_score += share->m_score;
|
client->m_score += share->m_score;
|
||||||
|
|
||||||
if (bad_share && (client->m_score <= BAN_THRESHOLD_POINTS)) {
|
if (bad_share && (client->m_score <= BAN_THRESHOLD_POINTS)) {
|
||||||
client->ban(DEFAULT_BAN_TIME);
|
client->ban(server->m_banTime);
|
||||||
client->close();
|
client->close();
|
||||||
}
|
}
|
||||||
else if (!result) {
|
else if (!result) {
|
||||||
@@ -1114,7 +1114,7 @@ void StratumServer::on_after_share_found(uv_work_t* req, int /*status*/)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (bad_share) {
|
else if (bad_share) {
|
||||||
server->ban(share->m_clientIPv6, share->m_clientAddr, DEFAULT_BAN_TIME);
|
server->ban(share->m_clientIPv6, share->m_clientAddr, server->m_banTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (share->m_allocated) {
|
if (share->m_allocated) {
|
||||||
@@ -1224,7 +1224,7 @@ bool StratumServer::StratumClient::on_read(const char* data, uint32_t size)
|
|||||||
auto on_parse = [this](const char* data, uint32_t size) {
|
auto on_parse = [this](const char* data, uint32_t size) {
|
||||||
if (static_cast<size_t>(m_stratumReadBufBytes) + size > STRATUM_BUF_SIZE) {
|
if (static_cast<size_t>(m_stratumReadBufBytes) + size > STRATUM_BUF_SIZE) {
|
||||||
LOGWARN(4, "client " << static_cast<const char*>(m_addrString) << " sent too long Stratum message");
|
LOGWARN(4, "client " << static_cast<const char*>(m_addrString) << " sent too long Stratum message");
|
||||||
ban(DEFAULT_BAN_TIME);
|
ban(static_cast<StratumServer*>(m_owner)->m_banTime);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1252,7 +1252,7 @@ bool StratumServer::StratumClient::on_read(const char* data, uint32_t size)
|
|||||||
|
|
||||||
*c = '\0';
|
*c = '\0';
|
||||||
if (!process_request(line_start, static_cast<uint32_t>(c - line_start))) {
|
if (!process_request(line_start, static_cast<uint32_t>(c - line_start))) {
|
||||||
ban(DEFAULT_BAN_TIME);
|
ban(static_cast<StratumServer*>(m_owner)->m_banTime);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -205,6 +205,8 @@ private:
|
|||||||
uint32_t m_totalFailedSidechainShares;
|
uint32_t m_totalFailedSidechainShares;
|
||||||
uint64_t m_totalStratumShares;
|
uint64_t m_totalStratumShares;
|
||||||
|
|
||||||
|
uint64_t m_banTime;
|
||||||
|
|
||||||
std::atomic<uint64_t> m_apiLastUpdateTime;
|
std::atomic<uint64_t> m_apiLastUpdateTime;
|
||||||
|
|
||||||
std::deque<SubmittedShare*> m_pendingShareChecks;
|
std::deque<SubmittedShare*> m_pendingShareChecks;
|
||||||
|
|||||||
Reference in New Issue
Block a user