1
1
#pragma once
2
2
3
3
#include < iostream>
4
+ #include < string>
4
5
5
- #include " jsonrpc_getwork.h"
6
- #include < jsonrpccpp/client/connectors/httpclient.h>
6
+ #include < boost/algorithm/string/predicate.hpp>
7
+ #include < boost/lexical_cast.hpp>
8
+ #include < boost/lockfree/queue.hpp>
7
9
8
- #include < libdevcore/Worker .h>
10
+ #include < json/json .h>
9
11
10
12
#include " ../PoolClient.h"
11
13
12
14
using namespace std ;
13
15
using namespace dev ;
14
16
using namespace eth ;
15
17
16
- class EthGetworkClient : public PoolClient , Worker
18
+ class EthGetworkClient : public PoolClient
17
19
{
18
20
public:
19
- EthGetworkClient (unsigned farmRecheckPeriod);
21
+ EthGetworkClient (int worktimeout, unsigned farmRecheckPeriod);
20
22
~EthGetworkClient ();
21
23
22
24
void connect () override ;
@@ -25,18 +27,52 @@ class EthGetworkClient : public PoolClient, Worker
25
27
bool isConnected () override { return m_connected; }
26
28
bool isPendingState () override { return false ; }
27
29
28
- string ActiveEndPoint () override { return " " ; };
30
+ string ActiveEndPoint () override { return " [ " + toString (m_endpoint) + " ] " ; };
29
31
30
32
void submitHashrate (string const & rate, string const & id) override ;
31
33
void submitSolution (const Solution& solution) override ;
32
34
33
35
private:
34
- void workLoop () override ;
35
- unsigned m_farmRecheckPeriod = 500 ;
36
36
37
- string m_HashrateHex; // Hashrate value already as hex string
38
- string m_HashrateId; // Hashrate unique identifier
37
+ unsigned m_farmRecheckPeriod = 500 ; // In milliseconds
39
38
40
- JsonrpcGetwork* p_client = nullptr ;
41
- WorkPackage m_prevWorkPackage;
39
+ void begin_connect ();
40
+ void handle_resolve (
41
+ const boost::system::error_code& ec, boost::asio::ip::tcp::resolver::iterator i);
42
+ void handle_connect (const boost::system::error_code& ec);
43
+ void handle_write (const boost::system::error_code& ec);
44
+ void handle_read (const boost::system::error_code& ec, std::size_t bytes_transferred);
45
+ std::string processError (Json::Value& JRes);
46
+ void processResponse (Json::Value& JRes);
47
+ void send (Json::Value const & jReq);
48
+ void send (std::string const & sReq );
49
+ void getwork_timer_elapsed (const boost::system::error_code& ec);
50
+
51
+ WorkPackage m_current;
52
+
53
+ std::atomic<bool > m_connecting = {false }; // Whether or not socket is on first try connect
54
+ std::atomic<bool > m_txPending = {false }; // Whether or not an async socket operation is pending
55
+ boost::lockfree::queue<std::string*> m_txQueue;
56
+
57
+ boost::asio::io_service& m_io_service; // The IO service reference passed in the constructor
58
+ boost::asio::io_service::strand m_io_strand;
59
+
60
+ boost::asio::ip::tcp::socket m_socket;
61
+ boost::asio::ip::tcp::resolver m_resolver;
62
+ std::queue<boost::asio::ip::basic_endpoint<boost::asio::ip::tcp>> m_endpoints;
63
+
64
+ boost::asio::streambuf m_request;
65
+ boost::asio::streambuf m_response;
66
+ Json::StreamWriterBuilder m_jSwBuilder;
67
+ std::string m_jsonGetWork;
68
+ Json::Value m_pendingJReq;
69
+ std::chrono::time_point<std::chrono::steady_clock> m_pending_tstamp;
70
+
71
+ boost::asio::deadline_timer m_getwork_timer; // The timer which triggers getWork requests
72
+
73
+ // seconds to trigger a work_timeout (overwritten in constructor)
74
+ int m_worktimeout;
75
+ std::chrono::time_point<std::chrono::steady_clock> m_current_tstamp;
76
+
77
+ unsigned m_solution_submitted_max_id; // maximum json id we used to send a solution
42
78
};
0 commit comments