New config

This commit is contained in:
Julien CLEMENT 2020-05-06 19:00:09 +02:00
parent 312eaab0be
commit 5288ed69f4
9 changed files with 18 additions and 80 deletions

@ -3,8 +3,7 @@
{ {
"ip" : "127.0.0.1", "ip" : "127.0.0.1",
"port" : 8000, "port" : 8000,
"name" : "legislator1", "name" : "legislator1"
"self" : true
} }
] ]
} }

@ -3,20 +3,17 @@
{ {
"ip" : "127.0.0.1", "ip" : "127.0.0.1",
"port" : 8000, "port" : 8000,
"name" : "legislator1", "name" : "legislator1"
"self" : true
}, },
{ {
"ip" : "127.0.0.1", "ip" : "127.0.0.1",
"port" : 8001, "port" : 8001,
"name" : "legislator2", "name" : "legislator2"
"self" : false
}, },
{ {
"ip" : "127.0.0.1", "ip" : "127.0.0.1",
"port" : 8002, "port" : 8002,
"name" : "legislator3", "name" : "legislator3"
"self" : false
} }
] ]
} }

@ -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
}
]
}

@ -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
}
]
}

@ -3,14 +3,12 @@
{ {
"ip" : "127.0.0.1", "ip" : "127.0.0.1",
"port" : 8000, "port" : 8000,
"name" : "legislator1", "name" : "legislator1"
"self" : false
}, },
{ {
"ip" : "127.0.0.1", "ip" : "127.0.0.1",
"port" : 8001, "port" : 8001,
"name" : "legislator2", "name" : "legislator2"
"self" : true
} }
] ]
} }

@ -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
}
]
}

@ -51,8 +51,6 @@ namespace paxos
config.port = std::to_string(port_int); config.port = std::to_string(port_int);
safe_get_key(j, "name", config.name, true); 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<std::vector<LegislatorConfig>, LegislatorConfig> static std::pair<std::vector<LegislatorConfig>, LegislatorConfig>
parse_legislators(const json& j) parse_legislators(const json& j, const std::string& name)
{ {
/* Get 'vhosts' value */ /* Get 'vhosts' value */
std::vector<json> legislators; std::vector<json> legislators;
@ -77,6 +75,7 @@ namespace paxos
{ {
/* Differenciable vhost checking */ /* Differenciable vhost checking */
auto legislator = it.get<paxos::LegislatorConfig>(); auto legislator = it.get<paxos::LegislatorConfig>();
legislator.is_self = name == legislator.name;
if (!legislator.is_self) if (!legislator.is_self)
legislator_configs.push_back(legislator); legislator_configs.push_back(legislator);
else 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; json json_dict;
std::ifstream json_file(path); std::ifstream json_file(path);
@ -111,7 +113,7 @@ namespace paxos
error_and_exit(1, e.what()); 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); return ServerConfig(legislators.first, legislators.second);
} }

@ -23,6 +23,6 @@ namespace paxos
LegislatorConfig self_; LegislatorConfig self_;
static ServerConfig parse(const std::string& path); static ServerConfig parse(char **argv);
}; };
} }

@ -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); ev_signal_init(&sigint_watcher, sigint_cb, SIGINT);
paxos::event_register.get_event_loop().register_sigint_watcher(&sigint_watcher); paxos::event_register.get_event_loop().register_sigint_watcher(&sigint_watcher);