-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
50 lines (45 loc) · 1.54 KB
/
main.cpp
File metadata and controls
50 lines (45 loc) · 1.54 KB
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
#include "Daemon.cpp"
#include <bits/stdc++.h>
using namespace std;
int main (int argc, char* argv[]) {
// parse command line arguments and pass to Daemon - ./daemon <port> <introducer port>, introducer port is optional
// ./Daemon 4560 9870 localhost local/remote introducer
int introducerNumArgs = 6;
if(argc>=5){
bool isIntroducer = argc == introducerNumArgs ? true : false;
string machineType = isIntroducer ? "introducer":"node";
string env = argv[4];
char *daemonPort = argv[1];
char *hydfsPort = argv[2];
char *introducerName = argv[3];
cout<<"Starting "<<machineType<<" on "<<daemonPort<<" with introducer on "<<introducerName<<" with "<<env<<" environment\n";
HyDFS dfs(hydfsPort);
dfs.start();
Daemon d(daemonPort, hydfsPort);
d.addListener(&dfs);
d.start(isIntroducer, introducerName);
if(string(argv[4]) == "remote") {
dfs.setLocalFilesPath("./files/remote");
} else {
if(isIntroducer){
dfs.setLocalFilesPath("./files/introducer");
} else {
dfs.setLocalFilesPath("");
}
}
while(1){
string command;
getline(cin, command);
if(command == "leave"){
dfs.stopThreads();
d.stopThreads();
break;
} else {
d.runCommand(command);
}
}
} else {
cout<<"Invalid arguments\n";
}
return 0;
}