mirror of
https://github.com/GOSTSec/poolserver
synced 2025-01-28 07:24:16 +00:00
Added mutexes for shared access variables
This commit is contained in:
parent
4b220cbfb4
commit
b29cf2f08b
@ -16,6 +16,7 @@ namespace Stratum
|
|||||||
|
|
||||||
void Server::SendToAll(JSON msg)
|
void Server::SendToAll(JSON msg)
|
||||||
{
|
{
|
||||||
|
boost::lock_guard<boost::mutex> guard(_mtxClients);
|
||||||
std::set<ClientPtr>::iterator it;
|
std::set<ClientPtr>::iterator it;
|
||||||
for (it = _clients.begin(); it != _clients.end(); ++it)
|
for (it = _clients.begin(); it != _clients.end(); ++it)
|
||||||
_io_service.post(boost::bind(&Client::SendMessage, (*it), msg));
|
_io_service.post(boost::bind(&Client::SendMessage, (*it), msg));
|
||||||
@ -23,6 +24,7 @@ namespace Stratum
|
|||||||
|
|
||||||
void Server::SendBlockTmpl(bool resetWork)
|
void Server::SendBlockTmpl(bool resetWork)
|
||||||
{
|
{
|
||||||
|
boost::lock_guard<boost::mutex> guard(_mtxClients);
|
||||||
std::set<ClientPtr>::iterator it;
|
std::set<ClientPtr>::iterator it;
|
||||||
for (it = _clients.begin(); it != _clients.end(); ++it)
|
for (it = _clients.begin(); it != _clients.end(); ++it)
|
||||||
_io_service.post(boost::bind(&Client::SendJob, (*it), resetWork));
|
_io_service.post(boost::bind(&Client::SendJob, (*it), resetWork));
|
||||||
|
@ -71,6 +71,7 @@ namespace Stratum
|
|||||||
// Returns new extranonce
|
// Returns new extranonce
|
||||||
uint32 GetExtranonce()
|
uint32 GetExtranonce()
|
||||||
{
|
{
|
||||||
|
boost::lock_guard<boost::mutex> guard(_mtxExtranonce);
|
||||||
return _extranonce++;
|
return _extranonce++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +101,10 @@ namespace Stratum
|
|||||||
// Disconnects client
|
// Disconnects client
|
||||||
void Disconnect(ClientPtr client)
|
void Disconnect(ClientPtr client)
|
||||||
{
|
{
|
||||||
|
_mtxClients.lock();
|
||||||
_clients.erase(client);
|
_clients.erase(client);
|
||||||
|
_mtxClients.unlock();
|
||||||
|
|
||||||
client->CloseSocket();
|
client->CloseSocket();
|
||||||
sLog.Info(LOG_STRATUM, "Stratum client disconnected from %s. Total clients: %u", asio::ip::address_v4(client->GetIP()).to_string().c_str(), _clients.size());
|
sLog.Info(LOG_STRATUM, "Stratum client disconnected from %s. Total clients: %u", asio::ip::address_v4(client->GetIP()).to_string().c_str(), _clients.size());
|
||||||
}
|
}
|
||||||
@ -110,11 +114,15 @@ namespace Stratum
|
|||||||
BanInfo ban;
|
BanInfo ban;
|
||||||
ban.ip = ip;
|
ban.ip = ip;
|
||||||
ban.timestamp = Util::Date() + time;
|
ban.timestamp = Util::Date() + time;
|
||||||
|
|
||||||
|
_mtxBans.lock();
|
||||||
_bans.push_back(ban);
|
_bans.push_back(ban);
|
||||||
|
_mtxBans.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsBanned(uint32 ip)
|
bool IsBanned(uint32 ip)
|
||||||
{
|
{
|
||||||
|
boost::lock_guard<boost::mutex> guard(_mtxBans);
|
||||||
for (int i = 0; i < _bans.size(); ++i) {
|
for (int i = 0; i < _bans.size(); ++i) {
|
||||||
if (_bans[i].ip == ip) {
|
if (_bans[i].ip == ip) {
|
||||||
if (_bans[i].timestamp > Util::Date())
|
if (_bans[i].timestamp > Util::Date())
|
||||||
@ -137,7 +145,10 @@ namespace Stratum
|
|||||||
{
|
{
|
||||||
if (!error) {
|
if (!error) {
|
||||||
if (client->Start()) {
|
if (client->Start()) {
|
||||||
|
_mtxClients.lock();
|
||||||
_clients.insert(client);
|
_clients.insert(client);
|
||||||
|
_mtxClients.unlock();
|
||||||
|
|
||||||
sLog.Info(LOG_STRATUM, "New stratum client accepted from %s. Total clients: %u", asio::ip::address_v4(client->GetIP()).to_string().c_str(), _clients.size());
|
sLog.Info(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 {
|
||||||
@ -154,13 +165,18 @@ namespace Stratum
|
|||||||
|
|
||||||
// Clients
|
// Clients
|
||||||
std::set<ClientPtr, ClientPtrCMP> _clients;
|
std::set<ClientPtr, ClientPtrCMP> _clients;
|
||||||
std::vector<BanInfo> _bans;
|
boost::mutex _mtxClients;
|
||||||
uint64 _clientId;
|
uint64 _clientId;
|
||||||
|
|
||||||
|
// Bands
|
||||||
|
std::vector<BanInfo> _bans;
|
||||||
|
boost::mutex _mtxBans;
|
||||||
|
|
||||||
// Work
|
// Work
|
||||||
Bitcoin::BlockPtr _currentWork;
|
Bitcoin::BlockPtr _currentWork;
|
||||||
boost::mutex _mtxCurrentWork;
|
boost::mutex _mtxCurrentWork;
|
||||||
uint32 _extranonce;
|
uint32 _extranonce;
|
||||||
|
boost::mutex _mtxExtranonce;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user