aboutsummaryrefslogtreecommitdiff
path: root/src/hotstuff_client.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/hotstuff_client.cpp')
-rw-r--r--src/hotstuff_client.cpp22
1 files changed, 18 insertions, 4 deletions
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<std::string, std::string> 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