forked from BeamMW/opencl-miner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
beamStratum.h
113 lines (89 loc) · 2.6 KB
/
beamStratum.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// BEAM OpenCL Miner
// Stratum interface class
// Copyright 2018 The Beam Team
// Copyright 2018 Wilke Trei
#include <iostream>
#include <thread>
#include <cstdlib>
#include <string>
#include <sstream>
#include <vector>
#include <deque>
#include <random>
#include <boost/scoped_ptr.hpp>
#include <boost/asio.hpp>
#include <boost/asio/ssl.hpp>
#include <boost/bind.hpp>
#include <boost/thread.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include "core/difficulty.h"
#include "core/uintBig.h"
using namespace std;
using namespace boost::asio;
using boost::asio::ip::tcp;
namespace pt = boost::property_tree;
namespace beamMiner {
#ifndef beamMiner_H
#define beamMiner_H
class beamStratum {
private:
// Definitions belonging to the physical connection
boost::asio::io_service io_service;
boost::scoped_ptr< boost::asio::ssl::stream<tcp::socket> > socket;
tcp::resolver res;
boost::asio::streambuf requestBuffer;
boost::asio::streambuf responseBuffer;
boost::asio::ssl::context context;
// User Data
string host;
string port;
string apiKey;
bool debug = true;
// Storage for received work
int64_t workId;
std::vector<uint8_t> serverWork;
std::atomic<uint64_t> nonce;
beam::Difficulty powDiff;
std::vector<uint8_t> poolNonce;
// Stat
uint64_t sharesAcc = 0;
uint64_t sharesRej = 0;
time_t t_start, t_current;
//Stratum sending subsystem
bool activeWrite = false;
void queueDataSend(string);
void syncSend(string);
void activateWrite();
void writeHandler(const boost::system::error_code&);
std::deque<string> writeRequests;
// Stratum receiving subsystem
void readStratum(const boost::system::error_code&);
boost::mutex updateMutex;
// Connection handling
void connect();
void handleConnect(const boost::system::error_code& err, tcp::resolver::iterator);
void handleHandshake(const boost::system::error_code& err);
bool verifyCertificate(bool,boost::asio::ssl::verify_context& );
// Solution Check & Submit
static bool testSolution(const beam::Difficulty&, const std::vector<uint32_t>&, std::vector<uint8_t>&);
void submitSolution(int64_t, uint64_t, const std::vector<uint8_t>&);
// Fork Information
uint64_t blockHeight = numeric_limits<uint64_t>::max();
uint64_t forkHeight = numeric_limits<uint64_t>::max();
public:
beamStratum(string, string, string, bool);
void startWorking();
struct WorkDescription
{
bool forceBeamHashI;
int64_t workId;
uint64_t nonce;
beam::Difficulty powDiff;
};
bool hasWork();
void getWork(WorkDescription&, uint8_t*);
void handleSolution(const WorkDescription&, std::vector<uint32_t>&);
};
#endif
}