From 77575990680720b49659d41bbc580a23209081c4 Mon Sep 17 00:00:00 2001 From: Nicolas Pope <nwpope@utu.fi> Date: Mon, 1 Jul 2019 11:06:38 +0300 Subject: [PATCH] Fix UUID to string for platform consistency --- components/control/cpp/src/master.cpp | 7 ++++++- components/net/cpp/include/ftl/net/universe.hpp | 3 ++- components/net/cpp/include/ftl/uuid.hpp | 10 ++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/components/control/cpp/src/master.cpp b/components/control/cpp/src/master.cpp index 086cfbcb1..80f9d841a 100644 --- a/components/control/cpp/src/master.cpp +++ b/components/control/cpp/src/master.cpp @@ -75,6 +75,7 @@ vector<json_t> Master::getSlaves() { vector<json_t> result; for (auto &r : response) { result.push_back(json_t::parse(r)); + LOG(INFO) << "Node details: " << result[result.size()-1]; } return result; } @@ -84,7 +85,11 @@ vector<string> Master::getConfigurables() { } vector<string> Master::getConfigurables(const ftl::UUID &peer) { - return net_->call<vector<string>>(peer, "list_configurables"); + try { + return net_->call<vector<string>>(peer, "list_configurables"); + } catch (...) { + return {}; + } } vector<json_t> Master::get(const string &uri) { diff --git a/components/net/cpp/include/ftl/net/universe.hpp b/components/net/cpp/include/ftl/net/universe.hpp index 720dc8a59..0fec5b023 100644 --- a/components/net/cpp/include/ftl/net/universe.hpp +++ b/components/net/cpp/include/ftl/net/universe.hpp @@ -361,7 +361,8 @@ template <typename R, typename... ARGS> R Universe::call(const ftl::UUID &pid, const std::string &name, ARGS... args) { Peer *p = getPeer(pid); if (p == nullptr || !p->isConnected()) { - DLOG(WARNING) << "Attempting to call an unknown peer : " << pid.to_string(); + if (p == nullptr) DLOG(WARNING) << "Attempting to call an unknown peer : " << pid.to_string(); + else DLOG(WARNING) << "Attempting to call an disconnected peer : " << pid.to_string(); throw -1; } return p->call<R>(name, args...); diff --git a/components/net/cpp/include/ftl/uuid.hpp b/components/net/cpp/include/ftl/uuid.hpp index 0b3cb6a1f..836e8f495 100644 --- a/components/net/cpp/include/ftl/uuid.hpp +++ b/components/net/cpp/include/ftl/uuid.hpp @@ -60,6 +60,15 @@ namespace ftl { * Get a pretty string. */ std::string to_string() const { + static const char *digits = "0123456789abcdef"; + std::string rc(sizeof(uuid_)*2,'0'); + + for (size_t i=0 ; i<16; ++i) { + rc[i*2] = digits[uuid_[i] & 0x0f]; + rc[i*2+1] = digits[(uuid_[i] >> 4) & 0x0f]; + } + return rc; +/* #ifdef WIN32 RPC_CSTR szUuid = NULL; if (::UuidToStringA(&guid_, &szUuid) == RPC_S_OK) { @@ -71,6 +80,7 @@ namespace ftl { uuid_unparse(uuid_, b); return std::string(b); #endif +*/ } /* Allow the UUID to be packed into an RPC message. */ -- GitLab