diff --git a/src/server/poolserver/Stratum/Client.cpp b/src/server/poolserver/Stratum/Client.cpp index f217d4f..4029dc2 100644 --- a/src/server/poolserver/Stratum/Client.cpp +++ b/src/server/poolserver/Stratum/Client.cpp @@ -17,6 +17,7 @@ namespace Stratum _ip = remote_ad.to_v4().to_ulong(); if (_server->IsBanned(_ip)) { + sLog.Warn(LOG_STRATUM, "Blocked banned client from: %s", remote_ad.to_v4().to_string().c_str()); Disconnect(); return; } @@ -349,10 +350,8 @@ namespace Stratum { if (!error) { std::istream is(&_recvBuffer); - char c; - while (is.good()) { - is >> c; + while (is.get(c)) { if (c == '\n') { try { OnMessage(JSON::FromString(_recvMessage)); diff --git a/src/server/poolserver/Stratum/Client.h b/src/server/poolserver/Stratum/Client.h index 9d4c274..00b7c6a 100644 --- a/src/server/poolserver/Stratum/Client.h +++ b/src/server/poolserver/Stratum/Client.h @@ -45,10 +45,10 @@ namespace Stratum void StartRead() { // Read until newline - boost::asio::async_read_until( + asio::async_read( _socket, _recvBuffer, - '\n', + asio::transfer_at_least(1), boost::bind(&Client::_OnReceive, this, asio::placeholders::error, asio::placeholders::bytes_transferred)); } @@ -117,6 +117,11 @@ namespace Stratum return _id; } + uint32 GetIP() + { + return _ip; + } + void Ban(uint32 time); void Disconnect(); diff --git a/src/server/poolserver/Stratum/Server.h b/src/server/poolserver/Stratum/Server.h index 3fdfa63..a8a8917 100644 --- a/src/server/poolserver/Stratum/Server.h +++ b/src/server/poolserver/Stratum/Server.h @@ -100,6 +100,7 @@ namespace Stratum { client->CloseSocket(); _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) @@ -133,9 +134,9 @@ namespace Stratum void _OnAccept(ClientPtr client, const boost::system::error_code& error) { if (!error) { - sLog.Debug(LOG_STRATUM, "New stratum client accepted. Total clients: %u", _clients.size()); client->Start(); _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 { sLog.Debug(LOG_STRATUM, "Failed to accept stratum client"); }