Browse Source

Updated convenience function zts_get_node_id_from_file()

pull/1/head
Joseph Henry 8 years ago
parent
commit
d3f92d98ed
  1. 8
      include/ZT1Service.h
  2. 26
      src/ZT1Service.cpp

8
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
*

26
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

Loading…
Cancel
Save