|
@ -38,10 +38,22 @@ void EthStratumClient::connect() |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void EthStratumClient::reconnect() |
|
|
|
|
|
{ |
|
|
|
|
|
m_socket.close(); |
|
|
|
|
|
m_io_service.reset(); |
|
|
|
|
|
m_authorized = false; |
|
|
|
|
|
cnote << "Reconnecting in 3 seconds..."; |
|
|
|
|
|
boost::asio::deadline_timer timer(m_io_service, boost::posix_time::seconds(3)); |
|
|
|
|
|
timer.wait(); |
|
|
|
|
|
connect(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void EthStratumClient::disconnect() |
|
|
void EthStratumClient::disconnect() |
|
|
{ |
|
|
{ |
|
|
cnote << "Disconnecting"; |
|
|
cnote << "Disconnecting"; |
|
|
m_running = false; |
|
|
m_running = false; |
|
|
|
|
|
|
|
|
m_socket.close(); |
|
|
m_socket.close(); |
|
|
m_io_service.stop(); |
|
|
m_io_service.stop(); |
|
|
} |
|
|
} |
|
@ -78,7 +90,7 @@ void EthStratumClient::connect_handler(const boost::system::error_code& ec, tcp: |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
cwarn << "Could not connect to stratum server " << m_host << ":" << m_port << ", " << ec.message(); |
|
|
cwarn << "Could not connect to stratum server " << m_host << ":" << m_port << ", " << ec.message(); |
|
|
disconnect(); |
|
|
reconnect(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
@ -114,6 +126,8 @@ void EthStratumClient::readResponse(const boost::system::error_code& ec, std::si |
|
|
std::string response; |
|
|
std::string response; |
|
|
getline(is, response); |
|
|
getline(is, response); |
|
|
|
|
|
|
|
|
|
|
|
if (response.front() == '{' && response.back() == '}') |
|
|
|
|
|
{ |
|
|
Json::Value responseObject; |
|
|
Json::Value responseObject; |
|
|
Json::Reader reader; |
|
|
Json::Reader reader; |
|
|
if (reader.parse(response.c_str(), responseObject)) |
|
|
if (reader.parse(response.c_str(), responseObject)) |
|
@ -128,16 +142,20 @@ void EthStratumClient::readResponse(const boost::system::error_code& ec, std::si |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
cwarn << "Read response failed: " << ec.message(); |
|
|
cwarn << "Discarding incomplete response"; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
readline(); |
|
|
readline(); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
cwarn << "Read response failed: " << ec.message(); |
|
|
|
|
|
reconnect(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void EthStratumClient::processReponse(Json::Value& responseObject) |
|
|
void EthStratumClient::processReponse(Json::Value& responseObject) |
|
|
{ |
|
|
{ |
|
|
Json::Value error = responseObject.get("error", NULL); |
|
|
Json::Value error = responseObject.get("error", new Json::Value); |
|
|
if (error.isArray()) |
|
|
if (error.isArray()) |
|
|
{ |
|
|
{ |
|
|
string msg = error.get(1, "Unknown error").asString(); |
|
|
string msg = error.get(1, "Unknown error").asString(); |
|
@ -225,6 +243,7 @@ void EthStratumClient::processReponse(Json::Value& responseObject) |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool EthStratumClient::submit(EthashProofOfWork::Solution solution) { |
|
|
bool EthStratumClient::submit(EthashProofOfWork::Solution solution) { |
|
|