diff --git a/make-mac.mk b/make-mac.mk index 8b1d121b4..9f0d7d8cd 100644 --- a/make-mac.mk +++ b/make-mac.mk @@ -2,7 +2,7 @@ CC=clang CXX=clang++ INCLUDES= -DEFS= +DEFS=-DZT_AUTO_UPDATE LIBS=-lm # Uncomment for a release optimized universal binary build diff --git a/node/Node.cpp b/node/Node.cpp index 8c6ab49b7..dd0e47edf 100644 --- a/node/Node.cpp +++ b/node/Node.cpp @@ -68,6 +68,7 @@ #include "CMWC4096.hpp" #include "SHA512.hpp" #include "Service.hpp" +#include "SoftwareUpdater.hpp" #ifdef __WINDOWS__ #include @@ -210,6 +211,7 @@ struct _NodeImpl #ifndef __WINDOWS__ delete renv.netconfService; #endif + delete renv.updater; delete renv.nc; delete renv.sysEnv; delete renv.topology; @@ -429,6 +431,10 @@ Node::ReasonForTermination Node::run() return impl->terminateBecause(Node::NODE_UNRECOVERABLE_ERROR,foo); } _r->node = this; +#ifdef ZT_AUTO_UPDATE + if (ZT_DEFAULTS.updateLatestNfoURL.length()) + _r->updater = new SoftwareUpdater(_r); +#endif // Bind local port for core I/O if (!_r->demarc->bindLocalUdp(impl->port)) { diff --git a/node/NodeConfig.cpp b/node/NodeConfig.cpp index ce5943c56..770f1f6f1 100644 --- a/node/NodeConfig.cpp +++ b/node/NodeConfig.cpp @@ -56,6 +56,7 @@ #include "Poly1305.hpp" #include "SHA512.hpp" #include "Node.hpp" +#include "SoftwareUpdater.hpp" namespace ZeroTier { @@ -184,6 +185,7 @@ std::vector NodeConfig::execute(const char *command) _P("200 help join "); _P("200 help leave "); _P("200 help terminate []"); + _P("200 help updatecheck"); } else if (cmd[0] == "info") { bool isOnline = false; uint64_t now = Utils::now(); @@ -268,6 +270,13 @@ std::vector NodeConfig::execute(const char *command) if (cmd.size() > 1) _r->node->terminate(Node::NODE_NORMAL_TERMINATION,cmd[1].c_str()); else _r->node->terminate(Node::NODE_NORMAL_TERMINATION,(const char *)0); + } else if (cmd[0] == "updatecheck") { + if (_r->updater) { + _P("200 checking for software updates now at: %s",ZT_DEFAULTS.updateLatestNfoURL.c_str()); + _r->updater->checkNow(); + } else { + _P("500 software updates are not enabled"); + } } else { _P("404 %s No such command. Use 'help' for help.",cmd[0].c_str()); } diff --git a/node/SoftwareUpdater.hpp b/node/SoftwareUpdater.hpp index bfcdf3954..5e47bbead 100644 --- a/node/SoftwareUpdater.hpp +++ b/node/SoftwareUpdater.hpp @@ -74,12 +74,26 @@ public: } } + /** + * Check for updates now regardless of last check time or version + */ + inline void checkNow() + { + Mutex::Lock _l(_lock); + if (_status == UPDATE_STATUS_IDLE) { + _lastUpdateAttempt = Utils::now(); + _status = UPDATE_STATUS_GETTING_NFO; + HttpClient::GET(ZT_DEFAULTS.updateLatestNfoURL,HttpClient::NO_HEADERS,ZT_UPDATE_HTTP_TIMEOUT,&_cbHandleGetLatestVersionInfo,this); + } + } + /** * Pack three-component version into a 64-bit integer * * @param vmaj Major version (0..65535) * @param vmin Minor version (0..65535) * @param rev Revision (0..65535) + * @return Version packed into an easily comparable 64-bit integer */ static inline uint64_t packVersion(unsigned int vmaj,unsigned int vmin,unsigned int rev) throw()