From cbfda8ccc88789cd3c83c63b6e18693e7dea718d Mon Sep 17 00:00:00 2001 From: Determinant Date: Wed, 17 Apr 2019 14:54:24 -0400 Subject: support auto client command for evaluation --- src/hotstuff_client.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/hotstuff_client.cpp') diff --git a/src/hotstuff_client.cpp b/src/hotstuff_client.cpp index 97bacab..8eeb8e5 100644 --- a/src/hotstuff_client.cpp +++ b/src/hotstuff_client.cpp @@ -80,8 +80,8 @@ void set_proposer(ReplicaID rid) { // conns.insert(std::make_pair(rid, mn.connect(replicas[rid]))); } -void try_send() { - while (waiting.size() < max_async_num && max_iter_num) +bool try_send(bool check = true) { + if ((!check || waiting.size() < max_async_num) && max_iter_num) { auto cmd = new CommandDummy(cid, cnt++); //mn.send_msg(MsgReqCmd(*cmd), *conns.at(proposer)); @@ -95,7 +95,9 @@ void try_send() { cmd->get_hash(), Request(proposer, cmd))); if (max_iter_num > 0) max_iter_num--; + return true; } + return false; } void client_resp_cmd_handler(MsgRespCmd &&msg, const Net::conn_t &) { @@ -134,9 +136,18 @@ void client_resp_cmd_handler(MsgRespCmd &&msg, const Net::conn_t &) { elapsed.push_back(std::make_pair(tv, et.elapsed_sec)); #endif waiting.erase(it); - try_send(); +#ifndef HOTSTUFF_AUTOCLI + while (try_send()); +#endif } +#ifdef HOTSTUFF_AUTOCLI +void client_demand_cmd_handler(hotstuff::MsgDemandCmd &&msg, const Net::conn_t &) { + for (size_t i = 0; i < msg.ncmd; i++) + try_send(false); +} +#endif + std::pair split_ip_port_cport(const std::string &s) { auto ret = salticidae::trim_all(salticidae::split(s, ";")); return std::make_pair(ret[0], ret[1]); @@ -158,6 +169,9 @@ int main(int argc, char **argv) { ev_sigterm.add(SIGTERM); mn.reg_handler(client_resp_cmd_handler); +#ifdef HOTSTUFF_AUTOCLI + mn.reg_handler(client_demand_cmd_handler); +#endif mn.start(); config.add_opt("idx", opt_idx, Config::SET_VAL); @@ -192,7 +206,7 @@ int main(int argc, char **argv) { HOTSTUFF_LOG_INFO("nfaulty = %zu", nfaulty); connect_all(); set_proposer(idx); - try_send(); + while (try_send()); ec.dispatch(); #ifdef HOTSTUFF_ENABLE_BENCHMARK -- cgit v1.2.3