mirror of
https://github.com/GOSTSec/poolserver
synced 2025-01-15 01:00:10 +00:00
Redirect for getwork
This commit is contained in:
parent
035f04ebba
commit
4de65da79a
@ -43,7 +43,8 @@ bool InitConfig(int argc, char *argv[])
|
|||||||
|
|
||||||
// Stratum
|
// Stratum
|
||||||
descStratum.add_options()
|
descStratum.add_options()
|
||||||
("StratumHost,sh", boost::program_options::value<std::string>()->default_value("0.0.0.0"), "Stratum server host")
|
("StratumHost,sh", boost::program_options::value<std::string>()->default_value("0.0.0.0"), "Bind IP for stratum")
|
||||||
|
("StratumRedirectHost", boost::program_options::value<std::string>()->default_value("0.0.0.0"), "Where to redirect getwork requests")
|
||||||
("StratumPort,sp", boost::program_options::value<uint16_t>()->default_value(3333), "Stratum server port")
|
("StratumPort,sp", boost::program_options::value<uint16_t>()->default_value(3333), "Stratum server port")
|
||||||
("StratumBlockCheckTime", boost::program_options::value<uint32>()->default_value(2000), "Time between block checks in ms")
|
("StratumBlockCheckTime", boost::program_options::value<uint32>()->default_value(2000), "Time between block checks in ms")
|
||||||
("RetargetInterval", boost::program_options::value<uint32>()->default_value(20), "Time between difficulty checks in seconds")
|
("RetargetInterval", boost::program_options::value<uint32>()->default_value(20), "Time between difficulty checks in seconds")
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "Server.h"
|
#include "Server.h"
|
||||||
#include "Client.h"
|
#include "Client.h"
|
||||||
|
#include "Config.h"
|
||||||
#include "BigNum.h"
|
#include "BigNum.h"
|
||||||
#include "DataMgr.h"
|
#include "DataMgr.h"
|
||||||
#include "ShareLimiter.h"
|
#include "ShareLimiter.h"
|
||||||
@ -356,11 +357,21 @@ namespace Stratum
|
|||||||
char c;
|
char c;
|
||||||
while (is.get(c)) {
|
while (is.get(c)) {
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
|
sLog.Debug(LOG_STRATUM, "Received message: %s", _recvMessage.c_str());
|
||||||
|
|
||||||
|
// Redirect getwork
|
||||||
|
if (!_subscribed) {
|
||||||
|
if (_recvMessage.compare("POST / HTTP/1.1\r") == 0) {
|
||||||
|
RedirectGetwork();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
OnMessage(JSON::FromString(_recvMessage));
|
OnMessage(JSON::FromString(_recvMessage));
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
sLog.Error(LOG_SERVER, "Exception caught while parsing json: %s", e.what());
|
sLog.Error(LOG_SERVER, "Exception caught while parsing json: %s", e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
_recvMessage.clear();
|
_recvMessage.clear();
|
||||||
} else
|
} else
|
||||||
_recvMessage += c;
|
_recvMessage += c;
|
||||||
|
@ -135,6 +135,17 @@ namespace Stratum
|
|||||||
void Ban(uint32 time);
|
void Ban(uint32 time);
|
||||||
void Disconnect();
|
void Disconnect();
|
||||||
|
|
||||||
|
void RedirectGetwork()
|
||||||
|
{
|
||||||
|
sLog.Info(LOG_STRATUM, "Sending redirect to stratum for client %u", _ip);
|
||||||
|
std::string redirect(Util::FS("HTTP/1.1 200 OK\r\nX-Stratum: stratum+tcp://%s:%u\r\nConnection: Close\r\nContent-Length: 41\r\n\r\n{\"error\": null, \"result\": false, \"id\": 0}\n", sConfig.Get<std::string>("StratumRedirectHost").c_str(), sConfig.Get<uint16>("StratumPort")));
|
||||||
|
boost::asio::async_write(
|
||||||
|
_socket,
|
||||||
|
boost::asio::buffer(redirect.c_str(), redirect.length()),
|
||||||
|
_ioStrand.wrap(boost::bind(&Client::_OnSend, shared_from_this(), boost::asio::placeholders::error)));
|
||||||
|
Disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
void CloseSocket()
|
void CloseSocket()
|
||||||
{
|
{
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
|
@ -133,6 +133,8 @@ namespace Stratum
|
|||||||
|
|
||||||
void _OnAccept(ClientPtr client, const boost::system::error_code& error)
|
void _OnAccept(ClientPtr client, const boost::system::error_code& error)
|
||||||
{
|
{
|
||||||
|
_StartAccept();
|
||||||
|
|
||||||
if (!error) {
|
if (!error) {
|
||||||
if (client->Start()) {
|
if (client->Start()) {
|
||||||
_clients.insert(client);
|
_clients.insert(client);
|
||||||
@ -141,8 +143,6 @@ namespace Stratum
|
|||||||
} else {
|
} else {
|
||||||
sLog.Debug(LOG_STRATUM, "Failed to accept stratum client");
|
sLog.Debug(LOG_STRATUM, "Failed to accept stratum client");
|
||||||
}
|
}
|
||||||
|
|
||||||
_StartAccept();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user