Browse Source

Fixed socket reading

master
Intel 10 years ago
parent
commit
c06c4edb2a
  1. 5
      src/server/poolserver/Stratum/Client.cpp
  2. 9
      src/server/poolserver/Stratum/Client.h
  3. 3
      src/server/poolserver/Stratum/Server.h

5
src/server/poolserver/Stratum/Client.cpp

@ -17,6 +17,7 @@ namespace Stratum @@ -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 @@ -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));

9
src/server/poolserver/Stratum/Client.h

@ -45,10 +45,10 @@ namespace Stratum @@ -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 @@ -117,6 +117,11 @@ namespace Stratum
return _id;
}
uint32 GetIP()
{
return _ip;
}
void Ban(uint32 time);
void Disconnect();

3
src/server/poolserver/Stratum/Server.h

@ -100,6 +100,7 @@ namespace Stratum @@ -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 @@ -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");
}

Loading…
Cancel
Save