aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDeterminant <ted.sybil@gmail.com>2019-04-17 14:54:24 -0400
committerDeterminant <ted.sybil@gmail.com>2019-04-17 14:54:24 -0400
commitcbfda8ccc88789cd3c83c63b6e18693e7dea718d (patch)
tree98e114ecc4f923f7e435c7ab94524e512e94fc14 /src
parentd859aa2cd2db03ef66f305a265ae908ef41d6a72 (diff)
support auto client command for evaluation
Diffstat (limited to 'src')
-rw-r--r--src/client.cpp3
-rw-r--r--src/hotstuff.cpp6
-rw-r--r--src/hotstuff_app.cpp10
-rw-r--r--src/hotstuff_client.cpp22
4 files changed, 37 insertions, 4 deletions
diff --git a/src/client.cpp b/src/client.cpp
index c1b571c..ee4b7dd 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -20,5 +20,8 @@ namespace hotstuff {
const opcode_t MsgReqCmd::opcode;
const opcode_t MsgRespCmd::opcode;
+#ifdef HOTSTUFF_AUTOCLI
+const opcode_t MsgDemandCmd::opcode;
+#endif
}
diff --git a/src/hotstuff.cpp b/src/hotstuff.cpp
index aeae2e2..2cc3821 100644
--- a/src/hotstuff.cpp
+++ b/src/hotstuff.cpp
@@ -115,7 +115,13 @@ promise_t HotStuffBase::exec_command(uint256_t cmd_hash) {
}
}
else
+ {
on_propose(cmds, pmaker->get_parents());
+#ifdef HOTSTUFF_AUTOCLI
+ for (size_t i = pmaker->get_pending_size(); i < 1; i++)
+ do_demand_commands(blk_size);
+#endif
+ }
});
}
return pm;
diff --git a/src/hotstuff_app.cpp b/src/hotstuff_app.cpp
index 30d127b..be9d3cd 100644
--- a/src/hotstuff_app.cpp
+++ b/src/hotstuff_app.cpp
@@ -110,6 +110,16 @@ class HotStuffApp: public HotStuff {
*/
}
+#ifdef HOTSTUFF_AUTOCLI
+ void do_demand_commands(size_t blk_size) override {
+ size_t ncli = client_conns.size();
+ size_t bsize = (blk_size + ncli - 1) / ncli;
+ hotstuff::MsgDemandCmd mdc{bsize};
+ for(const auto &conn: client_conns)
+ cn.send_msg(mdc, conn);
+ }
+#endif
+
#ifdef HOTSTUFF_MSG_STAT
std::unordered_set<conn_t> client_conns;
void print_stat() const;
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