-
Notifications
You must be signed in to change notification settings - Fork 3
/
primenet.h
339 lines (275 loc) · 11.1 KB
/
primenet.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
/* Include file for primenet communication code */
/* The current version number of the the PRIMENET.DLL API */
#define PRIMENET_VERSION 5
#define PRIMENET_TRANSACTION_API_VERSION 0.95
/* Initialization routine. Call from the main thread at startup. */
void LoadPrimenet ();
/* There is one routine used to communicate with the Primenet server */
/* This routine, "PrimeNet", takes two arguments one is an operation_type */
/* defined below, and the other argument is a pointer to a structure. */
/* A different structure is declared for each operation type. All strings */
/* in structures are zero-terminated. */
int PRIMENET (short operation, void *pkt);
/* Operations as defined in the primenet protocol document */
#define PRIMENET_UPDATE_COMPUTER_INFO 100
#define PRIMENET_PROGRAM_OPTIONS 101
#define PRIMENET_GET_ASSIGNMENT 102
#define PRIMENET_REGISTER_ASSIGNMENT 103
#define PRIMENET_ASSIGNMENT_PROGRESS 104
#define PRIMENET_ASSIGNMENT_RESULT 105
#define PRIMENET_ASSIGNMENT_UNRESERVE 106
#define PRIMENET_BENCHMARK_DATA 107
#define PRIMENET_PING_SERVER 108
/* WARNING, WARNING, WARNING: Prime95 writes some of these structures */
/* (primenetAssignmentResult, primenetAssignmentUnreserve, */
/* primenetBenchmarkData) out to the prime.spl spool file. Thus, these */
/* structures must be padded and use data types that are the same size for */
/* all compilers. This is the only way we can make the spool file portable. */
/* This structure is passed for the uc - Update Computer Info call */
struct primenetUpdateComputerInfo {
int32_t versionNumber;
char computer_guid[33];
char hardware_guid[33];
char windows_guid[33];
char application[65]; /* Ex. Windows,Prime95,v25.5,build 1 */
char cpu_model[65]; /* Ex. Intel(R) Pentium 4 2.6 GHz */
char cpu_features[65]; /* Ex. RDTSC, MMX, SSE, SSE2 */
int32_t L1_cache_size; /* Cache size in KB */
int32_t L2_cache_size; /* Cache size in KB */
int32_t L3_cache_size; /* Cache size in KB */
uint32_t num_cpus; /* Number of cpus/cores in machine */
uint32_t num_hyperthread; /* Number virtual cpus per CPU core */
uint32_t mem_installed; /* Physical memory in MB */
uint32_t cpu_speed; /* CPU speed in MHz */
uint32_t hours_per_day; /* Hours per day the computer runs */
uint32_t rolling_average; /* Rough measure of this computer's */
/* actual output vs. expected output */
/* <1000 = less actual output */
/* >1000 = more actual output */
char user_id[21];
char computer_name[21];
/* Returned by the server */
char user_name[33];
char pad[1]; /* For 4-byte alignment */
uint32_t options_counter; /* Number of times options have been */
/* updated on the server. Whenever */
/* this increases client must get */
/* program options. */
};
/* This structure is passed for the po - Program Options call */
/* Valid work_preference values */
#define PRIMENET_WP_WHATEVER 0 /* Whatever makes most sense */
#define PRIMENET_WP_FACTOR_LMH 1 /* Factor big numbers to low limits */
#define PRIMENET_WP_FACTOR 2 /* Trial factoring */
#define PRIMENET_WP_PMINUS1 3 /* P-1 of small Mersennes */
#define PRIMENET_WP_PFACTOR 4 /* P-1 of large Mersennes */
#define PRIMENET_WP_ECM_SMALL 5 /* ECM of small Mersennes */
#define PRIMENET_WP_ECM_FERMAT 6 /* ECM of Fermat numbers */
#define PRIMENET_WP_ECM_CUNNINGHAM 7 /* ECM of Cunningham numbers */
#define PRIMENET_WP_LL_FIRST 100 /* LL first time tests */
#define PRIMENET_WP_LL_DBLCHK 101 /* LL double checks */
#define PRIMENET_WP_WORLD_RECORD 102 /* LL result, Mersenne prime */
#define PRIMENET_WP_LL_10M 103 /* LL 10 million digit */
#define PRIMENET_WP_LL_100M 104 /* LL 100 million digit */
#define PRIMENET_WP_LL_FIRST_NOFAC 105 /* LL first time tests, no trial */
/* factoring or P-1 factoring */
#define PRIMENET_WP_PRP 150 /* PRP test - unimplmeneted */
struct primenetProgramOptions {
int32_t versionNumber;
char computer_guid[33];
char pad[3];
int32_t cpu_num; /* CPU number (-1 = all) */
/* Read/write parameters. Minus 1 is used to specify parameter */
/* not passed in. */
int32_t num_workers;
int32_t work_preference; /* Primenet work preference */
int32_t priority;
int32_t daysOfWork;
int32_t dayMemory;
int32_t nightMemory;
int32_t dayStartTime;
int32_t nightStartTime;
int32_t runOnBattery;
/* Returned by the server */
uint32_t options_counter; /* Number of times options have been */
/* updated on the server. Whenever */
/* this increases client must get */
/* program options. */
};
/* This structure is passed for the ga - Get Assignment call */
/* Valid work_types returned by ga */
#define PRIMENET_WORK_TYPE_FACTOR 2
#define PRIMENET_WORK_TYPE_PMINUS1 3
#define PRIMENET_WORK_TYPE_PFACTOR 4
#define PRIMENET_WORK_TYPE_ECM 5
#define PRIMENET_WORK_TYPE_FIRST_LL 100
#define PRIMENET_WORK_TYPE_DBLCHK 101
#define PRIMENET_WORK_TYPE_PRP 150 /* Unimplmented */
struct primenetGetAssignment {
int32_t versionNumber;
char computer_guid[33];
char pad[3];
uint32_t cpu_num; /* CPU number */
/* Returned by the server */
char assignment_uid[33];
char pad2[7];
uint32_t work_type;
double k; /* K in k*b^n+c */
uint32_t b; /* B in k*b^n+c */
uint32_t n; /* N in k*b^n+c */
int32_t c; /* C in k*b^n+c */
uint32_t has_been_pminus1ed; /* TRUE if P-1 has been run */
double how_far_factored; /* Log base 2 of highest trial */
/* factor tested. */
double factor_to; /* Log base 2 of how far to trial */
/* factor. */
double B1; /* P-1/ECM B1 */
double B2; /* P-1/ECM B2 */
double tests_saved; /* Primality tests saved if P-1 */
/* finds a factor */
uint32_t curves; /* ECM curves to run */
char known_factors[2000]; /* List of known factors */
};
/* This structure is passed for the ra - Register Assignment call */
struct primenetRegisterAssignment {
int32_t versionNumber;
char computer_guid[33];
char pad[3];
uint32_t cpu_num; /* CPU number */
uint32_t work_type;
double k; /* K in k*b^n+c */
uint32_t b; /* B in k*b^n+c */
uint32_t n; /* N in k*b^n+c */
int32_t c; /* C in k*b^n+c */
uint32_t has_been_pminus1ed; /* TRUE if P-1 has been run */
double how_far_factored; /* Log base 2 of highest trial */
/* factor tested. */
double factor_to; /* Log base 2 of how far to trial */
/* factor. */
double B1; /* P-1/ECM B1 */
double B2; /* P-1/ECM B2 */
double tests_saved; /* Primality tests saved if P-1 */
/* finds a factor */
uint32_t curves; /* ECM curves to run */
/* Returned by the server */
char assignment_uid[33];
char pad2[3];
};
/* This structure is passed for the ap - Assignment Progress call */
struct primenetAssignmentProgress {
int32_t versionNumber;
char computer_guid[33];
char assignment_uid[33];
char stage[11]; /* Stage for multi-part assignments */
char pad[3];
uint32_t cpu_num; /* CPU number */
double pct_complete; /* From zero to 100 */
uint32_t end_date; /* Expected completion time in sec. */
uint32_t next_update; /* Next update time in seconds */
uint32_t fftlen; /* FFT len being used */
};
/* This structure is passed for the ar - Assignment Result call */
#define PRIMENET_AR_NO_RESULT 0 /* No result, just sending done msg */
#define PRIMENET_AR_TF_FACTOR 1 /* Trial factoring, factor found */
#define PRIMENET_AR_P1_FACTOR 2 /* P-1, factor found */
#define PRIMENET_AR_ECM_FACTOR 3 /* ECM, factor found */
#define PRIMENET_AR_TF_NOFACTOR 4 /* Trial Factoring no factor found */
#define PRIMENET_AR_P1_NOFACTOR 5 /* P-1 Factoring no factor found */
#define PRIMENET_AR_ECM_NOFACTOR 6 /* ECM Factoring no factor found */
#define PRIMENET_AR_LL_RESULT 100 /* LL result, not prime */
#define PRIMENET_AR_LL_PRIME 101 /* LL result, Mersenne prime */
#define PRIMENET_AR_PRP_RESULT 150 /* PRP result, not prime */
#define PRIMENET_AR_PRP_PRIME 151 /* PRP result, probably prime */
struct primenetAssignmentResult {
int32_t versionNumber;
char computer_guid[33];
char assignment_uid[33];
char message[201]; /* Result expressed as string */
char pad[1];
uint32_t done; /* True is assignment complete */
uint32_t result_type; /* Result type defined above */
double k; /* K in k*b^n+c */
uint32_t b; /* B in k*b^n+c */
uint32_t n; /* N in k*b^n+c */
int32_t c; /* C in k*b^n+c */
uint32_t curves; /* ECM curves ran */
double start_bits; /* Log base 2 of starting trial */
/* factor tested. */
double end_bits; /* Log base 2 of ending trial */
/* factor tested. */
double B1; /* P-1/ECM B1 */
double B2; /* P-1/ECM B2 */
uint32_t stage; /* ECM stage the factor was found */
uint32_t shift_count; /* LL shift count */
uint32_t fftlen; /* FFT length used, for proper */
/* CPU credit on server */
char residue[17]; /* LL residue result */
char error_count[9]; /* LL result error count */
char factor[201]; /* Factor found */
char pad2[1];
/* Returned by the server */
};
/* This structure is passed for the au - Assignment Unreserve call */
struct primenetAssignmentUnreserve {
int32_t versionNumber;
char computer_guid[33];
char assignment_uid[33];
char pad[2];
};
/* This structure is passed for the bd - Benchmark Data call */
#define PRIMENET_BENCH_MAX_DATAPOINTS 50
struct primenetBenchmarkData {
int32_t versionNumber;
char computer_guid[33];
char user_comment[201]; /* User supplied comment */
char pad[6];
uint32_t num_data_points;
struct {
char bench[13]; /* What was benchmarked */
char pad2[3]; /* Align on 8 byte boundary */
double timing; /* Time it took (in seconds) */
} data_points[PRIMENET_BENCH_MAX_DATAPOINTS];
/* Returned by the server */
};
/* This structure is passed for the ps - Ping Server call */
struct primenetPingServer {
int32_t versionNumber;
uint32_t ping_type;
/* Returned by the server */
char ping_response[513];
char pad[3];
};
/* Error codes returned to client */
#define PRIMENET_ERROR_OK 0 /* no error */
#define PRIMENET_ERROR_SERVER_BUSY 3 /* server is too busy now */
#define PRIMENET_ERROR_INVALID_VERSION 4
#define PRIMENET_ERROR_INVALID_TRANSACTION 5
#define PRIMENET_ERROR_INVALID_PARAMETER 7
#define PRIMENET_ERROR_ACCESS_DENIED 9
#define PRIMENET_ERROR_DATABASE_CORRUPT 11
#define PRIMENET_ERROR_DATABASE_FULL_OR_BROKEN 13
#define PRIMENET_ERROR_INVALID_USER 21
#define PRIMENET_ERROR_UNREGISTERED_CPU 30
#define PRIMENET_ERROR_OBSOLETE_CLIENT 31
#define PRIMENET_ERROR_STALE_CPU_INFO 32
#define PRIMENET_ERROR_CPU_IDENTITY_MISMATCH 33
#define PRIMENET_ERROR_CPU_CONFIGURATION_MISMATCH 34
#define PRIMENET_ERROR_NO_ASSIGNMENT 40
#define PRIMENET_ERROR_INVALID_ASSIGNMENT_KEY 43
#define PRIMENET_ERROR_INVALID_ASSIGNMENT_TYPE 44
#define PRIMENET_ERROR_INVALID_RESULT_TYPE 45
#define PRIMENET_ERROR_INVALID_WORK_TYPE 46
#define PRIMENET_ERROR_WORK_NO_LONGER_NEEDED 47
/* These error codes are not returned by the server but are generated */
/* by the client code that communicates with the server. */
#define PRIMENET_NO_ERROR 0
#define PRIMENET_FIRST_INTERNAL_ERROR 1000
#define PRIMENET_ERROR_CONNECT_FAILED 1000
#define PRIMENET_ERROR_SEND_FAILED 1001
#define PRIMENET_ERROR_RECV_FAILED 1002
#define PRIMENET_ERROR_SERVER_UNSPEC 1003
#define PRIMENET_ERROR_PNERRORRESULT 1004
#define PRIMENET_ERROR_PNERRORDETAIL 1005
#define PRIMENET_ERROR_CURL_INIT 1100
#define PRIMENET_ERROR_CURL_PERFORM 1101
#define PRIMENET_ERROR_MODEM_OFF 2000