forked from nginnever/zogminer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StratumClient.h
94 lines (70 loc) · 2.3 KB
/
StratumClient.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright (c) 2016 Genoil <[email protected]>
// Copyright (c) 2016 Jack Grigg <[email protected]>
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "clientversion.h"
#include "libstratum/ZcashStratum.h"
#include <iostream>
#include <boost/array.hpp>
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <thread>
#include "json/json_spirit_value.h"
using namespace std;
using namespace boost::asio;
using boost::asio::ip::tcp;
using namespace json_spirit;
typedef struct {
string host;
string port;
string user;
string pass;
} cred_t;
template <typename Miner, typename Job, typename Solution>
class StratumClient
{
public:
StratumClient(Miner * m,
string const & host, string const & port,
string const & user, string const & pass,
int const & retries, int const & worktimeout);
~StratumClient() { }
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 && m_authorized; }
bool current() { return p_current; }
bool submit(const Solution* solution);
void reconnect();
void disconnect();
private:
void startWorking();
void workLoop();
void connect();
void work_timeout_handler(const boost::system::error_code& ec);
void processReponse(const Object& responseObject);
cred_t * p_active;
cred_t m_primary;
cred_t m_failover;
bool m_authorized;
bool m_connected;
bool m_running = true;
int m_retries = 0;
int m_maxRetries;
int m_worktimeout = 60;
string m_response;
Miner * p_miner;
boost::mutex x_current;
Job * p_current;
Job * p_previous;
bool m_stale = false;
std::unique_ptr<std::thread> m_work;
boost::asio::io_service m_io_service;
tcp::socket m_socket;
boost::asio::streambuf m_requestBuffer;
boost::asio::streambuf m_responseBuffer;
boost::asio::deadline_timer * p_worktimer;
string m_nextJobTarget;
};
typedef StratumClient<ZcashMiner, ZcashJob, EquihashSolution> ZcashStratumClient;