-
Notifications
You must be signed in to change notification settings - Fork 1
/
mock_component.cpp
110 lines (103 loc) · 3.43 KB
/
mock_component.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
//
// Created by David Chu on 1/11/21.
//
#include "mock_component.hpp"
mock_component::mock_component(const int argc, const char**argv) {
printUsage(argc < 2);
const std::string& component = argv[1];
mock* mockComponent;
if (component == "client") {
if (argc == 2)
mockComponent = new mock(false);
else if (argc == 3)
mockComponent = new mock(true, argv[2]);
else
printUsage();
mockComponent->client();
}
else if (component == "batcher") {
if (argc == 2)
mockComponent = new mock(false);
else if (argc == 3)
mockComponent = new mock(true, argv[2]);
else
printUsage();
mockComponent->batcher();
}
else if (component == "proposer") {
printUsage(argc < 3);
const std::string& connectingTo = argv[2];
if (connectingTo == "batcher") {
mockComponent = new mock(false);
mockComponent->proposerForBatcher(std::string(argv[3]) == "true");
}
else if (connectingTo == "proxy_leader") {
mockComponent = new mock(true); //no server address, just acceptorGroupId
std::vector<std::string> acceptorGroupIds;
for (int i = 3; i < argc; ++i)
acceptorGroupIds.emplace_back(argv[i]);
mockComponent->proposerForProxyLeader(acceptorGroupIds);
}
else
printUsage();
}
else if (component == "proxy_leader") {
printUsage(argc < 3);
const std::string& connectingTo = argv[2];
if (connectingTo == "proposer") {
printUsage(argc != 5);
mockComponent = new mock(false, argv[3]);
mockComponent->proxyLeaderForProposer(argv[4]);
}
else if (connectingTo == "acceptor") {
printUsage(argc != 4);
mockComponent = new mock(true, argv[3]);
mockComponent->proxyLeaderForAcceptor();
}
else if (connectingTo == "unbatcher") {
printUsage(argc != 5);
mockComponent = new mock(true, argv[3]);
mockComponent->proxyLeaderForUnbatcher(argv[4]);
}
else
printUsage();
}
else if (component == "acceptor") {
printUsage(argc != 3);
mockComponent = new mock(true);
mockComponent->acceptor(argv[2]);
}
else if (component == "unbatcher") {
if (argc == 2)
mockComponent = new mock(false);
else if (argc == 3)
mockComponent = new mock(true, argv[2]);
else
printUsage();
mockComponent->unbatcher();
}
else
printUsage();
}
void mock_component::printUsage(const bool ifThisIsTrue) {
if (!ifThisIsTrue)
return;
printf("Usage: One of the following...\n\n");
printf("Client sender: ./mock_component client <BATCHER_ADDRESS>\n");
printf("Client receiver: ./mock_component client\n");
printf("Batcher sender: ./mock_component batcher <PROPOSER_ADDRESS>\n");
printf("Batcher receiver: ./mock_component batcher\n");
printf("Proposer sender: ./mock_component proposer proxy_leader <ACCEPTOR_GROUP_IDS>...\n");
printf("Proposer receiver: ./mock_component proposer batcher <IS_LEADER>\n");
printf("Proxy leader receiver for proposer, where the proposer expects 1 acceptor group: ./mock_component proxy_leader proposer <PROPOSER_ADDRESS> <ACCEPTOR_GROUP_ID>\n");
printf("Proxy leader for acceptor: ./mock_component proxy_leader acceptor <ACCEPTOR_ADDRESS>\n");
printf("Proxy leader sender for unbatcher: ./mock_component proxy_leader unbatcher <UNBATCHER_ADDRESS> <CLIENT_ADDRESS>\n");
printf("Acceptor: ./mock_component acceptor <ACCEPTOR_GROUP_ID>\n");
printf("Unbatcher sender: ./mock_component unbatcher <CLIENT_ADDRESS>\n");
printf("Unbatcher receiver: ./mock_component unbatcher\n");
exit(0);
}
int main(const int argc, const char** argv) {
INIT_LOGGER();
mock_component m(argc, argv);
}