Skip to content

Commit

Permalink
encode worker routing ids in z85
Browse files Browse the repository at this point in the history
  • Loading branch information
mschubert committed Dec 16, 2023
1 parent 490828e commit e778b36
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/CMQMaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,11 @@ class CMQMaster {
status.reserve(peers.size());
calls.reserve(peers.size());
Rcpp::List wtime, mem;
std::string cur_hex;
std::string cur_z85;
for (const auto &kv: peers) {
std::stringstream os;
os << std::hex << std::setw(2) << std::setfill('0');
for (const auto &ch: kv.first)
os << static_cast<short>(ch);
names.push_back(os.str());
names.push_back(z85_encode_routing_id(kv.first));
if (kv.first == cur)
cur_hex = os.str();
cur_z85 = names.back();
status.push_back(std::string(wlife_t2str(kv.second.status)));
calls.push_back(kv.second.n_calls);
wtime.push_back(kv.second.time);
Expand All @@ -245,7 +241,7 @@ class CMQMaster {
return Rcpp::List::create(
Rcpp::_["worker"] = Rcpp::wrap(names),
Rcpp::_["status"] = Rcpp::wrap(status),
Rcpp::_["current"] = cur_hex,
Rcpp::_["current"] = cur_z85,
Rcpp::_["calls"] = calls,
Rcpp::_["time"] = wtime,
Rcpp::_["mem"] = mem,
Expand All @@ -256,13 +252,8 @@ class CMQMaster {
if (peers.find(cur) == peers.end())
return Rcpp::List::create();
const auto &w = peers[cur];
std::string cur_hex;
std::stringstream os;
os << std::hex << std::setw(2) << std::setfill('0');
for (const auto &ch: cur)
os << static_cast<short>(ch);
return Rcpp::List::create(
Rcpp::_["worker"] = os.str(),
Rcpp::_["worker"] = z85_encode_routing_id(cur),
Rcpp::_["status"] = Rcpp::wrap(wlife_t2str(w.status)),
Rcpp::_["call_ref"] = w.call_ref,
Rcpp::_["calls"] = w.n_calls,
Expand Down
6 changes: 6 additions & 0 deletions src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,9 @@ wlife_t msg2wlife_t(const zmq::message_t &msg) {
memcpy(&res, msg.data(), msg.size());
return res;
}

std::string z85_encode_routing_id(const std::string rid) {
std::string dest(5, 0);
zmq_z85_encode(&dest[0], reinterpret_cast<const uint8_t*>(&rid[1]), 4);
return dest;
}
1 change: 1 addition & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ zmq::message_t int2msg(const int val);
zmq::message_t r2msg(SEXP data);
SEXP msg2r(const zmq::message_t &&msg, const bool unserialize);
wlife_t msg2wlife_t(const zmq::message_t &msg);
std::string z85_encode_routing_id(const std::string rid);

#endif // _COMMON_H_

0 comments on commit e778b36

Please sign in to comment.