Browse Source

Redirect for getwork

master
Intel 11 years ago
parent
commit
4de65da79a
  1. 3
      src/server/poolserver/Main.cpp
  2. 11
      src/server/poolserver/Stratum/Client.cpp
  3. 11
      src/server/poolserver/Stratum/Client.h
  4. 4
      src/server/poolserver/Stratum/Server.h

3
src/server/poolserver/Main.cpp

@ -43,7 +43,8 @@ bool InitConfig(int argc, char *argv[]) @@ -43,7 +43,8 @@ bool InitConfig(int argc, char *argv[])
// Stratum
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")
("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")

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

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
#include "Server.h"
#include "Client.h"
#include "Config.h"
#include "BigNum.h"
#include "DataMgr.h"
#include "ShareLimiter.h"
@ -356,11 +357,21 @@ namespace Stratum @@ -356,11 +357,21 @@ namespace Stratum
char c;
while (is.get(c)) {
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 {
OnMessage(JSON::FromString(_recvMessage));
} catch (std::exception& e) {
sLog.Error(LOG_SERVER, "Exception caught while parsing json: %s", e.what());
}
_recvMessage.clear();
} else
_recvMessage += c;

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

@ -135,6 +135,17 @@ namespace Stratum @@ -135,6 +135,17 @@ namespace Stratum
void Ban(uint32 time);
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()
{
boost::system::error_code ec;

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

@ -133,6 +133,8 @@ namespace Stratum @@ -133,6 +133,8 @@ namespace Stratum
void _OnAccept(ClientPtr client, const boost::system::error_code& error)
{
_StartAccept();
if (!error) {
if (client->Start()) {
_clients.insert(client);
@ -141,8 +143,6 @@ namespace Stratum @@ -141,8 +143,6 @@ namespace Stratum
} else {
sLog.Debug(LOG_STRATUM, "Failed to accept stratum client");
}
_StartAccept();
}
private:

Loading…
Cancel
Save