-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTryMe2.cpp
74 lines (63 loc) · 2.48 KB
/
TryMe2.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
#include <iostream>
#include <GenSync/Syncs/GenSync.h>
using std::cout;
using std::endl;
using std::string;
int main(int argc, char *argv[]) {
if(argc<=1 || strcmp(argv[1], "client")!=0 && strcmp(argv[1], "server")!=0) {
cout << "usage: '"
<< argv[0]
<< " client <sync type>' for client mode, 'TryMe server <sync type>' for server mode." << endl;
cout << "run the client in one terminal instance and the server in another." << endl;
exit(0);
}
GenSync::SyncProtocol prot;
string type = string(argv[2]);
// no string switch statements :(
if(type == "CPISync") {
prot = GenSync::SyncProtocol::CPISync;
} else if (type == "InterCPISync") {
prot = GenSync::SyncProtocol::InteractiveCPISync;
} else if (type == "OneWayCPISync") {
prot = GenSync::SyncProtocol::OneWayCPISync;
} else if (type == "FullSync") {
prot = GenSync::SyncProtocol::FullSync;
} else if (type == "IBLTSync") {
prot = GenSync::SyncProtocol::IBLTSync;
} else if (type == "OneWayIBLTSync") {
prot = GenSync::SyncProtocol::OneWayIBLTSync;
} else {
cout << "invalid sync type!" << endl;
exit(1);
}
const int PORT = 8001; // port on which to connect
const int ERR = 8; // inverse log of error chance
const int M_BAR = 1; // max differences between server and client
const int BITS = CHAR_BIT; // bits per entry
const int PARTS = 3; // partitions per level for partition-syncs
const int EXP_ELTS = 4; // expected number of elements per set
GenSync genSync = GenSync::Builder().
setProtocol(prot).
setComm(GenSync::SyncComm::socket).
setPort(PORT).
setErr(ERR).
setMbar(M_BAR).
setBits((prot == GenSync::SyncProtocol::IBLTSync || prot == GenSync::SyncProtocol::OneWayIBLTSync ? BITS : BITS * CHAR_BIT)).
setNumPartitions(PARTS).
setExpNumElems(EXP_ELTS).
build();
genSync.addElem(make_shared<DataObject>('a'));
genSync.addElem(make_shared<DataObject>('b'));
genSync.addElem(make_shared<DataObject>('c'));
if(strcmp(argv[1], "client")==0) {
genSync.addElem(make_shared<DataObject>('d'));
cout << "listening on port " << PORT << "..." << endl;
genSync.clientSyncBegin(0);
cout << "sync succeeded." << endl;
} else {
genSync.addElem(make_shared<DataObject>('e'));
cout << "connecting on port " << PORT << "..." << endl;
genSync.serverSyncBegin(0);
cout << "sync succeeded." << endl;
}
}