summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--make-mac.mk2
-rw-r--r--node/Node.cpp6
-rw-r--r--node/NodeConfig.cpp9
-rw-r--r--node/SoftwareUpdater.hpp14
4 files changed, 30 insertions, 1 deletions
diff --git a/make-mac.mk b/make-mac.mk
index 8b1d121b..9f0d7d8c 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 8c6ab49b..dd0e47ed 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 <Windows.h>
@@ -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 ce5943c5..770f1f6f 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<std::string> NodeConfig::execute(const char *command)
_P("200 help join <network ID>");
_P("200 help leave <network ID>");
_P("200 help terminate [<reason>]");
+ _P("200 help updatecheck");
} else if (cmd[0] == "info") {
bool isOnline = false;
uint64_t now = Utils::now();
@@ -268,6 +270,13 @@ std::vector<std::string> 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 bfcdf395..5e47bbea 100644
--- a/node/SoftwareUpdater.hpp
+++ b/node/SoftwareUpdater.hpp
@@ -75,11 +75,25 @@ 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()