Browse Source

Merge branch 'master' into peercoin

peercoin
Intel 11 years ago
parent
commit
4c6c1baabd
  1. 6
      src/server/poolserver/Stratum/Client.cpp
  2. 20
      src/server/poolserver/Stratum/Client.h
  3. 9
      src/server/poolserver/Stratum/Server.h
  4. 1
      src/server/shared/MySQL/DatabaseOperation.h

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

@ -9,7 +9,7 @@
namespace Stratum namespace Stratum
{ {
void Client::Start() bool Client::Start()
{ {
// Get IP // Get IP
tcp::endpoint remote_ep = _socket.remote_endpoint(); tcp::endpoint remote_ep = _socket.remote_endpoint();
@ -19,11 +19,13 @@ namespace Stratum
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()); sLog.Warn(LOG_STRATUM, "Blocked banned client from: %s", remote_ad.to_v4().to_string().c_str());
Disconnect(); Disconnect();
return; return false;
} }
// Start reading socket // Start reading socket
StartRead(); StartRead();
return true;
} }
void Client::SendJob(bool clean) void Client::SendJob(bool clean)

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

@ -25,19 +25,24 @@ namespace Stratum
class Client : public boost::enable_shared_from_this<Client> class Client : public boost::enable_shared_from_this<Client>
{ {
public: public:
Client(Server* server, asio::io_service& io_service, uint64 id) : _server(server), _socket(io_service), _ioStrand(io_service), _id(id), _subscribed(false), _jobid(0), _shareLimiter(this) Client(Server* server, asio::io_service& io_service, uint64 id) : _io_service(io_service), _server(server), _socket(io_service), _ioStrand(io_service), _id(id), _subscribed(false), _jobid(0), _shareLimiter(this)
{ {
_diff = sConfig.Get<uint32>("StratumMinDifficulty"); _diff = sConfig.Get<uint32>("StratumMinDifficulty");
_minDiff = _diff; _minDiff = _diff;
} }
~Client()
{
sLog.Info(LOG_STRATUM, "%u: I'm going out! Cya!", _ip);
}
tcp::socket& GetSocket() tcp::socket& GetSocket()
{ {
return _socket; return _socket;
} }
// Start client up! // Start client up!
void Start(); bool Start();
void StartRead() void StartRead()
{ {
@ -46,7 +51,7 @@ namespace Stratum
_socket, _socket,
_recvBuffer, _recvBuffer,
asio::transfer_at_least(1), asio::transfer_at_least(1),
_ioStrand.wrap(boost::bind(&Client::_OnReceive, this, asio::placeholders::error, asio::placeholders::bytes_transferred))); _ioStrand.wrap(boost::bind(&Client::_OnReceive, shared_from_this(), asio::placeholders::error, asio::placeholders::bytes_transferred)));
} }
void SendJob(bool clean); void SendJob(bool clean);
@ -61,7 +66,7 @@ namespace Stratum
boost::asio::async_write( boost::asio::async_write(
_socket, _socket,
boost::asio::buffer(data.c_str(), data.length()), boost::asio::buffer(data.c_str(), data.length()),
_ioStrand.wrap(boost::bind(&Client::_OnSend, this, boost::asio::placeholders::error))); _ioStrand.wrap(boost::bind(&Client::_OnSend, shared_from_this(), boost::asio::placeholders::error)));
} }
void OnMiningSubmit(JSON msg); void OnMiningSubmit(JSON msg);
@ -126,13 +131,18 @@ namespace Stratum
void CloseSocket() void CloseSocket()
{ {
_socket.close(); boost::system::error_code ec;
_socket.shutdown(asio::ip::tcp::socket::shutdown_both, ec);
_socket.close(ec);
} }
public: public:
void _OnReceive(const boost::system::error_code& error, size_t bytes_transferred); void _OnReceive(const boost::system::error_code& error, size_t bytes_transferred);
void _OnSend(const boost::system::error_code& error); void _OnSend(const boost::system::error_code& error);
private: private:
// ASIO
asio::io_service& _io_service;
// Networking // Networking
asio::streambuf _recvBuffer; asio::streambuf _recvBuffer;
std::string _recvMessage; std::string _recvMessage;

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

@ -98,8 +98,8 @@ namespace Stratum
// Disconnects client // Disconnects client
void Disconnect(ClientPtr client) void Disconnect(ClientPtr client)
{ {
client->CloseSocket();
_clients.erase(client); _clients.erase(client);
client->CloseSocket();
sLog.Debug(LOG_STRATUM, "Stratum client disconnected from %s. Total clients: %u", asio::ip::address_v4(client->GetIP()).to_string().c_str(), _clients.size()); sLog.Debug(LOG_STRATUM, "Stratum client disconnected from %s. Total clients: %u", asio::ip::address_v4(client->GetIP()).to_string().c_str(), _clients.size());
} }
@ -134,9 +134,10 @@ 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) {
client->Start(); if (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()); 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");
} }

1
src/server/shared/MySQL/DatabaseOperation.h

@ -14,6 +14,7 @@ namespace MySQL
{ {
public: public:
DatabaseOperation(): _conn(NULL) {} DatabaseOperation(): _conn(NULL) {}
virtual ~DatabaseOperation() {}
virtual void Execute() = 0; virtual void Execute() = 0;
void SetConnection(DatabaseConnection* conn) { _conn = conn; } void SetConnection(DatabaseConnection* conn) { _conn = conn; }
protected: protected:

Loading…
Cancel
Save