forked from decryp2kanon/yiimp-sugarchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.h
169 lines (117 loc) · 3.64 KB
/
client.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//struct YAAMP_SOURCE
//{
//public:
// int count;
// double speed;
//
// char ip[64];
//};
struct YAAMP_ALGO
{
char name[64];
YAAMP_HASH_FUNCTION hash_function;
double diff_multiplier;
double factor;
YAAMP_HASH_FUNCTION merkle_func;
double profit;
double rent;
bool overflow;
};
struct YAAMP_CLIENT_ALGO
{
double factor;
YAAMP_ALGO *algo;
};
#define YAAMP_JOB_MAXHISTORY 16
#define MIN_ADDRESS_LEN 30 /* BTC len can be as few as 26 chars, but gen. 33 or 34 */
#define MAX_ADDRESS_LEN 35 /* DCR */
class YAAMP_CLIENT: public YAAMP_OBJECT
{
public:
YAAMP_SOCKET *sock;
// YAAMP_SOURCE *source;
char notify_id[1024];
int64_t reqid; // ask request id
int created;
int last_best;
bool reconnectable;
bool reconnecting;
int userid;
int workerid;
int coinid;
bool logtraffic;
int id_int;
const char *id_str;
char version[1024];
char username[1024];
char password[1024];
char worker[1024];
double difficulty_actual;
double difficulty_remote;
double difficulty_written;
bool difficulty_fixed;
long long last_submit_time;
double shares_per_minute;
char extranonce1[32];
int extranonce2size;
char extranonce1_default[32];
int extranonce2size_default;
char extranonce1_last[32];
int extranonce2size_last;
char extranonce1_reconnect[32];
int extranonce2size_reconnect;
bool extranonce_subscribe;
int submit_bad;
double speed;
int extranonce1_id;
int jobid_next;
int jobid_sent;
int jobid_locked;
YAAMP_CLIENT_ALGO algos_subscribed[YAAMP_MAXALGOS];
int job_history[YAAMP_JOB_MAXHISTORY];
int64_t shares;
int stats;
int donation;
int broadcast_timeouts;
};
inline void client_delete(YAAMP_OBJECT *object)
{
YAAMP_CLIENT *client = (YAAMP_CLIENT *)object;
if (object == NULL) return;
socket_close(client->sock);
delete client;
object = NULL;
}
//////////////////////////////////////////////////////////////////////////
YAAMP_CLIENT *client_find_notify_id(const char *notify_id, bool reconnecting);
void get_next_extraonce1(char *extraonce1);
void get_random_key(char *key);
void client_sort();
void client_block_ip(YAAMP_CLIENT *client, const char *reason);
void client_block_ipset(YAAMP_CLIENT *client, const char *ipset_name);
bool client_reset_multialgo(YAAMP_CLIENT *client, bool first);
bool client_initialize_multialgo(YAAMP_CLIENT *client);
void client_add_job_history(YAAMP_CLIENT *client, int jobid);
bool client_find_job_history(YAAMP_CLIENT *client, int jobid, int startat=1);
bool client_find_my_ip(const char *ip);
//////////////////////////////////////////////////////////////////////////
int client_send_difficulty(YAAMP_CLIENT *client, double difficulty);
double client_normalize_difficulty(double difficulty);
void client_change_difficulty(YAAMP_CLIENT *client, double difficulty);
void client_record_difficulty(YAAMP_CLIENT *client);
void client_adjust_difficulty(YAAMP_CLIENT *client);
void client_initialize_difficulty(YAAMP_CLIENT *client);
//////////////////////////////////////////////////////////////////////////
int client_call(YAAMP_CLIENT *client, const char *method, const char *format, ...);
int client_ask(YAAMP_CLIENT *client, const char *method, const char *format, ...);
void client_dump_all();
int client_send_result(YAAMP_CLIENT *client, const char *format, ...);
int client_send_error(YAAMP_CLIENT *client, int error, const char *string);
bool client_ask_stats(YAAMP_CLIENT *client);
bool client_submit(YAAMP_CLIENT *client, json_value *json_params);
int client_workers_count(YAAMP_CLIENT *client);
int client_workers_byaddress(const char *username);
bool client_auth_by_workers(YAAMP_CLIENT *client);
void *client_thread(void *p);
void db_check_user_input(char* input);
//void source_prune();