-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player-Online.cpp
254 lines (233 loc) · 8.15 KB
/
Player-Online.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
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
// (C) 2018 University of Bristol. See License.txt
#include "Processor/Machine.h"
#include "Math/Setup.h"
#include "Tools/ezOptionParser.h"
#include "Tools/Config.h"
#include <iostream>
#include <map>
#include <string>
#include <stdio.h>
using namespace std;
int main(int argc, const char** argv)
{
ez::ezOptionParser opt;
opt.syntax = "./Player-Online.x [OPTIONS] <playernum> <progname>\n";
opt.example = "./Player-Online.x -lgp 64 -lg2 128 -m new 0 sample-prog\n./Player-Online.x -pn 13000 -h localhost 1 sample-prog\n";
opt.add(
"128", // Default.
0, // Required?
1, // Number of args expected.
0, // Delimiter if expecting multiple args.
"Bit length of GF(p) field (default: 128)", // Help description.
"-lgp", // Flag token.
"--lgp" // Flag token.
);
opt.add(
"40", // Default.
0, // Required?
1, // Number of args expected.
0, // Delimiter if expecting multiple args.
"Bit length of GF(2^n) field (default: 40)", // Help description.
"-lg2", // Flag token.
"--lg2" // Flag token.
);
opt.add(
"5000", // Default.
0, // Required?
1, // Number of args expected.
0, // Delimiter if expecting multiple args.
"Port number base to attempt to start connections from (default: 5000)", // Help description.
"-pn", // Flag token.
"--portnumbase" // Flag token.
);
opt.add(
"", // Default.
0, // Required?
1, // Number of args expected.
0, // Delimiter if expecting multiple args.
"Port to listen on (default: port number base + player number)", // Help description.
"-mp", // Flag token.
"--my-port" // Flag token.
);
opt.add(
"localhost", // Default.
0, // Required?
1, // Number of args expected.
0, // Delimiter if expecting multiple args.
"Host where Server.x is running to coordinate startup (default: localhost). Ignored if --ip-file-name is used.", // Help description.
"-h", // Flag token.
"--hostname" // Flag token.
);
opt.add(
"", // Default.
0, // Required?
1, // Number of args expected.
0, // Delimiter if expecting multiple args.
"Filename containing list of party ip addresses. Alternative to --hostname and running Server.x for startup coordination.", // Help description.
"-ip", // Flag token.
"--ip-file-name" // Flag token.
);
opt.add(
"empty", // Default.
0, // Required?
1, // Number of args expected.
0, // Delimiter if expecting multiple args.
"Where to obtain memory, new|old|empty (default: empty)\n\t"
"new: copy from Player-Memory-P<i> file\n\t"
"old: reuse previous memory in Memory-P<i>\n\t"
"empty: create new empty memory", // Help description.
"-m", // Flag token.
"--memory" // Flag token.
);
opt.add(
"", // Default.
0, // Required?
0, // Number of args expected.
0, // Delimiter if expecting multiple args.
"Direct communication instead of star-shaped", // Help description.
"-d", // Flag token.
"--direct" // Flag token.
);
opt.add(
"", // Default.
0, // Required?
0, // Number of args expected.
0, // Delimiter if expecting multiple args.
"Star-shaped communication handled by background threads", // Help description.
"-P", // Flag token.
"--parallel" // Flag token.
);
opt.add(
"0", // Default.
0, // Required?
1, // Number of args expected.
0, // Delimiter if expecting multiple args.
"Sum at most n shares at once when using indirect communication", // Help description.
"-s", // Flag token.
"--opening-sum" // Flag token.
);
opt.add(
"", // Default.
0, // Required?
0, // Number of args expected.
0, // Delimiter if expecting multiple args.
"Use player-specific threads for communication", // Help description.
"-t", // Flag token.
"--threads" // Flag token.
);
opt.add(
"0", // Default.
0, // Required?
1, // Number of args expected.
0, // Delimiter if expecting multiple args.
"Maximum number of parties to send to at once", // Help description.
"-b", // Flag token.
"--max-broadcast" // Flag token.
);
opt.add(
"0", // Default.
0, // Required?
0, // Number of args expected.
0, // Delimiter if expecting multiple args.
"Use communications security between SPDZ players", // Help description.
"-c", // Flag token.
"--player-to-player-commsec" // Flag token.
);
opt.parse(argc, argv);
vector<string*> allArgs(opt.firstArgs);
allArgs.insert(allArgs.end(), opt.lastArgs.begin(), opt.lastArgs.end());
string progname;
int playerno;
string usage;
vector<string> badOptions;
unsigned int i;
if (allArgs.size() != 3)
{
cerr << "ERROR: incorrect number of arguments to Player-Online.x\n";
cerr << "Arguments given were:\n";
for (unsigned int j = 1; j < allArgs.size(); j++)
cout << "'" << *allArgs[j] << "'" << endl;
opt.getUsage(usage);
cout << usage;
return 1;
}
else
{
playerno = atoi(allArgs[1]->c_str());
progname = *allArgs[2];
}
if(!opt.gotRequired(badOptions))
{
for (i=0; i < badOptions.size(); ++i)
cerr << "ERROR: Missing required option " << badOptions[i] << ".";
opt.getUsage(usage);
cout << usage;
return 1;
}
if(!opt.gotExpected(badOptions))
{
for(i=0; i < badOptions.size(); ++i)
cerr << "ERROR: Got unexpected number of arguments for option " << badOptions[i] << ".";
opt.getUsage(usage);
cout << usage;
return 1;
}
string memtype, hostname, ipFileName;
int lg2, lgp, pnbase, opening_sum, max_broadcast;
int p2pcommsec;
int my_port;
opt.get("--portnumbase")->getInt(pnbase);
opt.get("--lgp")->getInt(lgp);
opt.get("--lg2")->getInt(lg2);
opt.get("--memory")->getString(memtype);
opt.get("--hostname")->getString(hostname);
opt.get("--ip-file-name")->getString(ipFileName);
opt.get("--opening-sum")->getInt(opening_sum);
opt.get("--max-broadcast")->getInt(max_broadcast);
opt.get("--player-to-player-commsec")->getInt(p2pcommsec);
ez::OptionGroup* mp_opt = opt.get("--my-port");
if (mp_opt->isSet)
mp_opt->getInt(my_port);
else
my_port = Names::DEFAULT_PORT;
int mynum;
sscanf((*allArgs[1]).c_str(), "%d", &mynum);
CommsecKeysPackage *keys = NULL;
if(p2pcommsec) {
vector<public_signing_key> pubkeys;
secret_signing_key mykey;
public_signing_key mypublickey;
string prep_data_prefix = get_prep_dir(2, lgp, lg2);
Config::read_player_config(prep_data_prefix,mynum,pubkeys,mykey,mypublickey);
keys = new CommsecKeysPackage(pubkeys,mykey,mypublickey);
}
Names playerNames;
if (ipFileName.size() > 0) {
if (my_port != Names::DEFAULT_PORT)
throw runtime_error("cannot set port number when using IP file");
playerNames.init(playerno, pnbase, ipFileName);
} else {
playerNames.init(playerno, pnbase, my_port, hostname.c_str());
}
playerNames.set_keys(keys);
#ifndef INSECURE
try
#endif
{
Machine(playerno, playerNames, progname, memtype, lgp, lg2,
opt.get("--direct")->isSet, opening_sum, opt.get("--parallel")->isSet,
opt.get("--threads")->isSet, max_broadcast).run();
cerr << "Command line:";
for (int i = 0; i < argc; i++)
cerr << " " << argv[i];
cerr << endl;
}
#ifndef INSECURE
catch(...)
{
purge_preprocessing(playerNames,
get_prep_dir(playerNames.num_players(), lgp, lg2));
throw;
}
#endif
}