You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.4 KiB

#include <iostream>
#include <boost/array.hpp>
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <json/json.h>
#include <libdevcore/Log.h>
9 years ago
#include <libdevcore/FixedHash.h>
#include <libethcore/Farm.h>
#include <libethcore/EthashAux.h>
#include <libethcore/Miner.h>
9 years ago
#include "BuildInfo.h"
using namespace std;
using namespace boost::asio;
using boost::asio::ip::tcp;
9 years ago
using namespace dev;
using namespace dev::eth;
9 years ago
class EthStratumClient
{
public:
EthStratumClient(GenericFarm<EthashProofOfWork> * f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout);
~EthStratumClient();
9 years ago
void setFailover(string const & host, string const & port);
void setFailover(string const & host, string const & port, string const & user, string const & pass);
bool isRunning() { return m_running; }
bool isConnected() { return m_connected; }
9 years ago
h256 currentHeaderHash() { return m_current.headerHash; }
bool current() { return m_current; }
9 years ago
unsigned waitState() { return m_waitState; }
9 years ago
bool submit(EthashProofOfWork::Solution solution);
void reconnect();
private:
9 years ago
void connect();
9 years ago
void disconnect();
void resolve_handler(const boost::system::error_code& ec, tcp::resolver::iterator i);
void connect_handler(const boost::system::error_code& ec, tcp::resolver::iterator i);
9 years ago
void work_timeout_handler(const boost::system::error_code& ec);
void readline();
9 years ago
void handleResponse(const boost::system::error_code& ec);
void readResponse(const boost::system::error_code& ec, std::size_t bytes_transferred);
void processReponse(Json::Value& responseObject);
9 years ago
MinerType m_minerType;
9 years ago
cred_t * p_active;
cred_t m_primary;
cred_t m_failover;
bool m_authorized;
bool m_connected;
bool m_precompute;
bool m_running = true;
int m_retries = 0;
int m_maxRetries;
int m_worktimeout = 60;
9 years ago
int m_waitState = MINER_WAIT_STATE_WORK;
boost::mutex x_pending;
int m_pending;
string m_response;
9 years ago
GenericFarm<EthashProofOfWork> * p_farm;
boost::mutex x_current;
9 years ago
EthashProofOfWork::WorkPackage m_current;
9 years ago
EthashProofOfWork::WorkPackage m_previous;
bool m_stale = false;
9 years ago
string m_job;
9 years ago
string m_previousJob;
9 years ago
EthashAux::FullType m_dag;
boost::asio::io_service m_io_service;
tcp::socket m_socket;
9 years ago
boost::asio::streambuf m_requestBuffer;
boost::asio::streambuf m_responseBuffer;
9 years ago
boost::asio::deadline_timer * p_worktimer;
};