-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProtocolParty.cpp
196 lines (125 loc) · 5.76 KB
/
ProtocolParty.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
//
// Created by moriya on 7/24/19.
//
#include "ProtocolParty.h"
ProtocolParty::ProtocolParty(int argc, char* argv[]) : Protocol("ObliviousDictionary", argc, argv)
{
partyId = stoi(this->getParser().getValueByKey(arguments, "partyID"));
this->times = stoi(this->getParser().getValueByKey(arguments, "internalIterationsNumber"));
this->hashSize = stoi(this->getParser().getValueByKey(arguments, "hashSize"));
vector<string> subTaskNames{"Online"};
timer = new Measurement(*this, subTaskNames);
MPCCommunication comm;
string partiesFile = this->getParser().getValueByKey(arguments, "partiesFile");
reportStatistics = stoi(this->getParser().getValueByKey(arguments, "reportStatistics"));
if(reportStatistics==0) {
otherParty = comm.setCommunication(io_service, partyId, 2, partiesFile)[0];
string tmp = "init times";
//cout<<"before sending any data"<<endl;
byte tmpBytes[20];
if (otherParty->getID() < partyId) {
otherParty->getChannel()->write(tmp);
otherParty->getChannel()->read(tmpBytes, tmp.size());
} else {
otherParty->getChannel()->read(tmpBytes, tmp.size());
otherParty->getChannel()->write(tmp);
}
}
}
ProtocolParty::~ProtocolParty(){
delete timer;
}
void ProtocolParty::run() {
auto total_duration = 0;
for (iteration=0; iteration<times; iteration++){
auto t1start = high_resolution_clock::now();
timer->startSubTask("Online", iteration);
runOnline();
timer->endSubTask("Online", iteration);
auto t2end = high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(t2end-t1start).count();
total_duration += duration;
}
cout << "average time per run = " << (float)total_duration/(float)times << " milliseconds" << endl;
}
DBParty::DBParty(int argc, char *argv[]): ProtocolParty(argc, argv){
auto version = this->getParser().getValueByKey(arguments, "version");
auto tool = this->getParser().getValueByKey(arguments, "tool");
auto batchSize = stoi(this->getParser().getValueByKey(arguments, "batchSize"));
auto tableRatio = stof(this->getParser().getValueByKey(arguments, "tableRatio"));
auto processId = this->getParser().getValueByKey(arguments, "processId");
if (version.compare("2Tables") == 0) {
dic = new ObliviousDictionaryDB2Tables(hashSize, tool);
} else if (version.compare("3Tables") == 0) {
dic = new ObliviousDictionaryDB3Tables(hashSize, tool,batchSize, processId, tableRatio);
}
dic->setReportStatstics(reportStatistics);
}
DBParty::~DBParty(){
delete dic;
}
void DBParty::runOnline() {
dic->init();
// auto start = high_resolution_clock::now();
// auto t1 = high_resolution_clock::now();
dic->fillTables();
// auto t2 = high_resolution_clock::now();
// duration = duration_cast<milliseconds>(t2 - t1).count();
// cout << "fillTables took in milliseconds: " << duration << endl;
// t1 = high_resolution_clock::now();
dic->peeling();
// t2 = high_resolution_clock::now();
// duration = duration_cast<milliseconds>(t2 - t1).count();
// cout << "peeling took in milliseconds: " << duration << endl;
if (reportStatistics == 1)
dic->updateIteration(iteration);
// if (reportStatistics == 0) {
// t1 = high_resolution_clock::now();
// dic->generateExternalToolValues();
// t2 = high_resolution_clock::now();
// duration = duration_cast<milliseconds>(t2 - t1).count();
// cout << "calcPolinomial took in milliseconds: " << duration << endl;
// t1 = high_resolution_clock::now();
// dic->unpeeling();
// t2 = high_resolution_clock::now();
// duration = duration_cast<milliseconds>(t2 - t1).count();
// cout << "unpeeling took in milliseconds: " << duration << endl;
// t1 = high_resolution_clock::now();
// dic->sendData(otherParty);
// t2 = high_resolution_clock::now();
// duration = duration_cast<milliseconds>(t2 - t1).count();
// cout << "send took in milliseconds: " << duration << endl;
// auto end = high_resolution_clock::now();
// duration = duration_cast<milliseconds>(end - start).count();
// cout << "all protocol took in milliseconds: " << duration << endl;
// dic->checkOutput();
// }
}
QueryParty::QueryParty(int argc, char *argv[]) : ProtocolParty(argc, argv){
auto version = this->getParser().getValueByKey(arguments, "version");
auto tool = this->getParser().getValueByKey(arguments, "tool");
if (version.compare("2Tables") == 0) {
dic = new ObliviousDictionaryQuery2Tables(hashSize, tool);
} else if (version.compare("3Tables") == 0) {
dic = new ObliviousDictionaryQuery3Tables(hashSize, tool);
}
}
QueryParty::~QueryParty() {
delete dic;
}
void QueryParty::runOnline() {
auto start = high_resolution_clock::now();
auto t1 = high_resolution_clock::now();
dic->readData(otherParty);
auto t2 = high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(t2-t1).count();
cout << "read data took in milliseconds: " << duration << endl;
t1 = high_resolution_clock::now();
dic->calcRealValues();
t2 = high_resolution_clock::now();
duration = duration_cast<milliseconds>(t2-t1).count();
cout << "calc real values took in milliseconds: " << duration << endl;
auto end = high_resolution_clock::now();
duration = duration_cast<milliseconds>(end-start).count();
cout << "all protocol took in milliseconds: " << duration << endl;
}