mirror of
https://github.com/GOSTSec/poolserver
synced 2025-01-15 01:00:10 +00:00
Fixed socket reading
This commit is contained in:
parent
e22760e4db
commit
c06c4edb2a
@ -17,6 +17,7 @@ namespace Stratum
|
|||||||
_ip = remote_ad.to_v4().to_ulong();
|
_ip = remote_ad.to_v4().to_ulong();
|
||||||
|
|
||||||
if (_server->IsBanned(_ip)) {
|
if (_server->IsBanned(_ip)) {
|
||||||
|
sLog.Warn(LOG_STRATUM, "Blocked banned client from: %s", remote_ad.to_v4().to_string().c_str());
|
||||||
Disconnect();
|
Disconnect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -349,10 +350,8 @@ namespace Stratum
|
|||||||
{
|
{
|
||||||
if (!error) {
|
if (!error) {
|
||||||
std::istream is(&_recvBuffer);
|
std::istream is(&_recvBuffer);
|
||||||
|
|
||||||
char c;
|
char c;
|
||||||
while (is.good()) {
|
while (is.get(c)) {
|
||||||
is >> c;
|
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
try {
|
try {
|
||||||
OnMessage(JSON::FromString(_recvMessage));
|
OnMessage(JSON::FromString(_recvMessage));
|
||||||
|
@ -45,10 +45,10 @@ namespace Stratum
|
|||||||
void StartRead()
|
void StartRead()
|
||||||
{
|
{
|
||||||
// Read until newline
|
// Read until newline
|
||||||
boost::asio::async_read_until(
|
asio::async_read(
|
||||||
_socket,
|
_socket,
|
||||||
_recvBuffer,
|
_recvBuffer,
|
||||||
'\n',
|
asio::transfer_at_least(1),
|
||||||
boost::bind(&Client::_OnReceive, this, asio::placeholders::error, asio::placeholders::bytes_transferred));
|
boost::bind(&Client::_OnReceive, this, asio::placeholders::error, asio::placeholders::bytes_transferred));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,6 +117,11 @@ namespace Stratum
|
|||||||
return _id;
|
return _id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32 GetIP()
|
||||||
|
{
|
||||||
|
return _ip;
|
||||||
|
}
|
||||||
|
|
||||||
void Ban(uint32 time);
|
void Ban(uint32 time);
|
||||||
void Disconnect();
|
void Disconnect();
|
||||||
|
|
||||||
|
@ -100,6 +100,7 @@ namespace Stratum
|
|||||||
{
|
{
|
||||||
client->CloseSocket();
|
client->CloseSocket();
|
||||||
_clients.erase(client);
|
_clients.erase(client);
|
||||||
|
sLog.Debug(LOG_STRATUM, "Stratum client disconnected from %s. Total clients: %u", asio::ip::address_v4(client->GetIP()).to_string().c_str(), _clients.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ban(uint32 ip, uint64 time)
|
void Ban(uint32 ip, uint64 time)
|
||||||
@ -133,9 +134,9 @@ namespace Stratum
|
|||||||
void _OnAccept(ClientPtr client, const boost::system::error_code& error)
|
void _OnAccept(ClientPtr client, const boost::system::error_code& error)
|
||||||
{
|
{
|
||||||
if (!error) {
|
if (!error) {
|
||||||
sLog.Debug(LOG_STRATUM, "New stratum client accepted. Total clients: %u", _clients.size());
|
|
||||||
client->Start();
|
client->Start();
|
||||||
_clients.insert(client);
|
_clients.insert(client);
|
||||||
|
sLog.Debug(LOG_STRATUM, "New stratum client accepted from %s. Total clients: %u", asio::ip::address_v4(client->GetIP()).to_string().c_str(), _clients.size());
|
||||||
} else {
|
} else {
|
||||||
sLog.Debug(LOG_STRATUM, "Failed to accept stratum client");
|
sLog.Debug(LOG_STRATUM, "Failed to accept stratum client");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user