From d3f92d98edc92d93bd11956b966c2b7ba1246bdb Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Wed, 15 Nov 2017 15:28:55 -0800 Subject: [PATCH] Updated convenience function zts_get_node_id_from_file() --- include/ZT1Service.h | 8 ++++++++ src/ZT1Service.cpp | 26 +++----------------------- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/include/ZT1Service.h b/include/ZT1Service.h index 3f14a45..f6e52cf 100644 --- a/include/ZT1Service.h +++ b/include/ZT1Service.h @@ -197,6 +197,14 @@ void zts_get_homepath(char *homePath, size_t len); */ uint64_t zts_get_node_id(); +/** + * @brief Returns the ztaddress/nodeId/device ID of this instance (as read from a file) + * + * @usage Call with or without starting the service with zts_start() + * @return + */ +uint64_t zts_get_node_id_from_file(const char *filepath); + /** * @brief Return the number of peers * diff --git a/src/ZT1Service.cpp b/src/ZT1Service.cpp index 2255562..6e58ce7 100644 --- a/src/ZT1Service.cpp +++ b/src/ZT1Service.cpp @@ -162,37 +162,17 @@ VirtualTap *getAnyTap() return vtap; } -/* - - else // Service isn't online, try to read ID from file - { - std::string fname("identity.public"); - std::string fpath(homeDir); - if (ZeroTier::OSUtils::fileExists((fpath + ZT_PATH_SEPARATOR_S + fname).c_str(),false)) { - std::string oldid; - ZeroTier::OSUtils::readFile((fpath + ZT_PATH_SEPARATOR_S + fname).c_str(),oldid); - memcpy(devID, oldid.c_str(), ZTO_ID_LEN); // first 10 bytes of file - return 0; - } - } -*/ - -int zts_get_id_from_file(const char *filepath, uint64_t *nodeId) +uint64_t zts_get_node_id_from_file(const char *filepath) { - /* DEBUG_EXTRA(); std::string fname("identity.public"); std::string fpath(filepath); if (ZeroTier::OSUtils::fileExists((fpath + ZT_PATH_SEPARATOR_S + fname).c_str(),false)) { std::string oldid; ZeroTier::OSUtils::readFile((fpath + ZT_PATH_SEPARATOR_S + fname).c_str(),oldid); - uint64_t value = Utils::hexStrToU64(oldid); - memcpy(nodeId, value, sizeof(uint64_t)); // first 10 bytes of file - // TOmorrow - return 0; + return Utils::hexStrToU64(oldid); } - */ - return -1; + return 0; } // Starts a ZeroTier service in the background