Self if now also in legislators map

This commit is contained in:
Julien CLEMENT 2020-05-06 19:07:37 +02:00
parent 5288ed69f4
commit 53d36d8569
3 changed files with 12 additions and 20 deletions

@ -8,9 +8,8 @@
namespace paxos
{
ServerConfig::ServerConfig(const std::vector<LegislatorConfig>& legislators,
const LegislatorConfig& self)
: legislators_(legislators), self_(self)
ServerConfig::ServerConfig(const std::vector<LegislatorConfig>& legislators)
: legislators_(legislators)
{
}
@ -60,8 +59,8 @@ namespace paxos
}
static std::pair<std::vector<LegislatorConfig>, LegislatorConfig>
parse_legislators(const json& j, const std::string& name)
static std::vector<LegislatorConfig> parse_legislators(const json& j,
const std::string& name)
{
/* Get 'vhosts' value */
std::vector<json> legislators;
@ -69,21 +68,16 @@ namespace paxos
/* Create VHostConfig vector and fill with VHostConfig */
std::vector<LegislatorConfig> legislator_configs;
LegislatorConfig self;
for (auto it : legislators)
{
/* Differenciable vhost checking */
auto legislator = it.get<paxos::LegislatorConfig>();
legislator.is_self = name == legislator.name;
if (!legislator.is_self)
legislator_configs.push_back(legislator);
else
self = legislator;
legislator_configs.push_back(legislator);
}
return std::pair<std::vector<LegislatorConfig>, LegislatorConfig>
(legislator_configs, self);
return legislator_configs;
}
@ -115,6 +109,6 @@ namespace paxos
auto legislators = parse_legislators(json_dict, name);
return ServerConfig(legislators.first, legislators.second);
return ServerConfig(legislators);
}
}

@ -16,13 +16,10 @@ namespace paxos
struct ServerConfig
{
ServerConfig(const std::vector<LegislatorConfig>& legislators,
const LegislatorConfig& self);
ServerConfig(const std::vector<LegislatorConfig>& legislators);
std::vector<LegislatorConfig> legislators_;
LegislatorConfig self_;
static ServerConfig parse(char **argv);
};
}

@ -36,11 +36,12 @@ int main(int argc, char **argv)
ev_signal_init(&sigstop_watcher, sigstop_cb, SIGTSTP);
paxos::event_register.get_event_loop().register_sigint_watcher(&sigstop_watcher);
paxos::self = paxos::LegislatorFactory::Create(server_config.self_);
for (auto config : server_config.legislators_)
{
paxos::legislators.insert(std::pair(config.name, paxos::LegislatorFactory::Create(config)));
paxos::shared_legislator legislator = paxos::LegislatorFactory::Create(config);
paxos::legislators.insert(std::pair(config.name, legislator));
if (config.is_self)
paxos::self = legislator;
}
paxos::event_register.get_event_loop()();