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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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<std::vector<LegislatorConfig>, LegislatorConfig>
parse_legislators(const json& j)
parse_legislators(const json& j, const std::string& name)
{
/* Get 'vhosts' value */
std::vector<json> legislators;
@ -77,6 +75,7 @@ namespace paxos
{
/* 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
@ -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);
}

View File

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

View File

@ -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);