Browse Source

Software update work...

Adam Ierymenko 11 years ago
parent
commit
a22a3ed7e8
4 changed files with 30 additions and 1 deletions
  1. 1 1
      make-mac.mk
  2. 6 0
      node/Node.cpp
  3. 9 0
      node/NodeConfig.cpp
  4. 14 0
      node/SoftwareUpdater.hpp

+ 1 - 1
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

+ 6 - 0
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)) {

+ 9 - 0
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());
 	}

+ 14 - 0
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()