diff --git a/config-files/one-legislator.json b/config-files/one-legislator.json index aec63f4..f5d490d 100644 --- a/config-files/one-legislator.json +++ b/config-files/one-legislator.json @@ -3,8 +3,7 @@ { "ip" : "127.0.0.1", "port" : 8000, - "name" : "legislator1", - "self" : true + "name" : "legislator1" } ] } diff --git a/config-files/three-legislators/three-legislators1.json b/config-files/three-legislators.json similarity index 59% rename from config-files/three-legislators/three-legislators1.json rename to config-files/three-legislators.json index ce8dc5c..47fce09 100644 --- a/config-files/three-legislators/three-legislators1.json +++ b/config-files/three-legislators.json @@ -3,20 +3,17 @@ { "ip" : "127.0.0.1", "port" : 8000, - "name" : "legislator1", - "self" : true + "name" : "legislator1" }, { "ip" : "127.0.0.1", "port" : 8001, - "name" : "legislator2", - "self" : false + "name" : "legislator2" }, { "ip" : "127.0.0.1", "port" : 8002, - "name" : "legislator3", - "self" : false + "name" : "legislator3" } ] } diff --git a/config-files/three-legislators/three-legislators2.json b/config-files/three-legislators/three-legislators2.json deleted file mode 100644 index e30b89c..0000000 --- a/config-files/three-legislators/three-legislators2.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "legislators" : [ - { - "ip" : "127.0.0.1", - "port" : 8000, - "name" : "legislator1", - "self" : false - }, - { - "ip" : "127.0.0.1", - "port" : 8001, - "name" : "legislator2", - "self" : true - }, - { - "ip" : "127.0.0.1", - "port" : 8002, - "name" : "legislator3", - "self" : false - } - ] -} diff --git a/config-files/three-legislators/three-legislators3.json b/config-files/three-legislators/three-legislators3.json deleted file mode 100644 index d7b0d0d..0000000 --- a/config-files/three-legislators/three-legislators3.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "legislators" : [ - { - "ip" : "127.0.0.1", - "port" : 8000, - "name" : "legislator1", - "self" : false - }, - { - "ip" : "127.0.0.1", - "port" : 8001, - "name" : "legislator2", - "self" : false - }, - { - "ip" : "127.0.0.1", - "port" : 8002, - "name" : "legislator3", - "self" : true - } - ] -} diff --git a/config-files/two-legislators/two-legislators2.json b/config-files/two-legislators.json similarity index 60% rename from config-files/two-legislators/two-legislators2.json rename to config-files/two-legislators.json index 4197286..f5e69dc 100644 --- a/config-files/two-legislators/two-legislators2.json +++ b/config-files/two-legislators.json @@ -3,14 +3,12 @@ { "ip" : "127.0.0.1", "port" : 8000, - "name" : "legislator1", - "self" : false + "name" : "legislator1" }, { "ip" : "127.0.0.1", "port" : 8001, - "name" : "legislator2", - "self" : true + "name" : "legislator2" } ] } diff --git a/config-files/two-legislators/two-legislators1.json b/config-files/two-legislators/two-legislators1.json deleted file mode 100644 index 32d9513..0000000 --- a/config-files/two-legislators/two-legislators1.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "legislators" : [ - { - "ip" : "127.0.0.1", - "port" : 8000, - "name" : "legislator1", - "self" : true - }, - { - "ip" : "127.0.0.1", - "port" : 8001, - "name" : "legislator2", - "self" : false - } - ] -} diff --git a/src/config/config.cc b/src/config/config.cc index 6cf1ad1..ca51ab8 100644 --- a/src/config/config.cc +++ b/src/config/config.cc @@ -51,8 +51,6 @@ namespace paxos config.port = std::to_string(port_int); safe_get_key(j, "name", config.name, true); - - safe_get_key(j, "self", config.is_self, true); } @@ -63,7 +61,7 @@ namespace paxos static std::pair, LegislatorConfig> - parse_legislators(const json& j) + parse_legislators(const json& j, const std::string& name) { /* Get 'vhosts' value */ std::vector legislators; @@ -77,6 +75,7 @@ namespace paxos { /* Differenciable vhost checking */ auto legislator = it.get(); + legislator.is_self = name == legislator.name; if (!legislator.is_self) legislator_configs.push_back(legislator); else @@ -88,8 +87,11 @@ namespace paxos } - ServerConfig ServerConfig::parse(const std::string& path) + ServerConfig ServerConfig::parse(char **argv) { + std::string path = argv[1]; + std::string name = argv[2]; + json json_dict; std::ifstream json_file(path); @@ -111,7 +113,7 @@ namespace paxos error_and_exit(1, e.what()); } - auto legislators = parse_legislators(json_dict); + auto legislators = parse_legislators(json_dict, name); return ServerConfig(legislators.first, legislators.second); } diff --git a/src/config/config.hh b/src/config/config.hh index 456efc1..388342d 100644 --- a/src/config/config.hh +++ b/src/config/config.hh @@ -23,6 +23,6 @@ namespace paxos LegislatorConfig self_; - static ServerConfig parse(const std::string& path); + static ServerConfig parse(char **argv); }; } diff --git a/src/main.cc b/src/main.cc index 8c13871..1d17460 100644 --- a/src/main.cc +++ b/src/main.cc @@ -24,9 +24,11 @@ static void sigstop_cb(struct ev_loop*, ev_signal*, int) } -int main(int, char **argv) +int main(int argc, char **argv) { - paxos::ServerConfig server_config = paxos::ServerConfig::parse(argv[1]); + if (argc != 3) + return 1; + paxos::ServerConfig server_config = paxos::ServerConfig::parse(argv); ev_signal_init(&sigint_watcher, sigint_cb, SIGINT); paxos::event_register.get_event_loop().register_sigint_watcher(&sigint_watcher);