diff options
| author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2014-08-16 09:08:52 -0700 |
|---|---|---|
| committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2014-08-16 09:08:52 -0700 |
| commit | 4f0fcc582eed69e4a45a94c4ef5a4d0e2e31a216 (patch) | |
| tree | df37c60c4afb113f3a4fa6efad1a6cb919543e10 /node/SoftwareUpdater.cpp | |
| parent | aa59cfd5458241cecb96409b90ca38058b65b651 (diff) | |
| download | infinitytier-4f0fcc582eed69e4a45a94c4ef5a4d0e2e31a216.tar.gz infinitytier-4f0fcc582eed69e4a45a94c4ef5a4d0e2e31a216.zip | |
Refactor HttpClient a bit.
Diffstat (limited to 'node/SoftwareUpdater.cpp')
| -rw-r--r-- | node/SoftwareUpdater.cpp | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/node/SoftwareUpdater.cpp b/node/SoftwareUpdater.cpp index e34fd3ca..d3a606fa 100644 --- a/node/SoftwareUpdater.cpp +++ b/node/SoftwareUpdater.cpp @@ -33,6 +33,7 @@ #include "../version.h" +#include "Constants.hpp" #include "SoftwareUpdater.hpp" #include "Dictionary.hpp" #include "C25519.hpp" @@ -42,6 +43,7 @@ #include "Thread.hpp" #include "Node.hpp" #include "Utils.hpp" +#include "HttpClient.hpp" #ifdef __UNIX_LIKE__ #include <unistd.h> @@ -85,6 +87,32 @@ void SoftwareUpdater::cleanOldUpdates() } } +void SoftwareUpdater::sawRemoteVersion(unsigned int vmaj,unsigned int vmin,unsigned int rev) +{ + const uint64_t tmp = packVersion(vmaj,vmin,rev); + if (tmp > _myVersion) { + Mutex::Lock _l(_lock); + if ((_status == UPDATE_STATUS_IDLE)&&(!_die)&&(ZT_DEFAULTS.updateLatestNfoURL.length())) { + const uint64_t now = Utils::now(); + if ((now - _lastUpdateAttempt) >= ZT_UPDATE_MIN_INTERVAL) { + _lastUpdateAttempt = now; + _status = UPDATE_STATUS_GETTING_NFO; + _r->http->GET(ZT_DEFAULTS.updateLatestNfoURL,HttpClient::NO_HEADERS,ZT_UPDATE_HTTP_TIMEOUT,&_cbHandleGetLatestVersionInfo,this); + } + } + } +} + +void SoftwareUpdater::checkNow() +{ + Mutex::Lock _l(_lock); + if (_status == UPDATE_STATUS_IDLE) { + _lastUpdateAttempt = Utils::now(); + _status = UPDATE_STATUS_GETTING_NFO; + _r->http->GET(ZT_DEFAULTS.updateLatestNfoURL,HttpClient::NO_HEADERS,ZT_UPDATE_HTTP_TIMEOUT,&_cbHandleGetLatestVersionInfo,this); + } +} + const char *SoftwareUpdater::parseNfo( const char *nfoText, unsigned int &vMajor, @@ -127,7 +155,7 @@ bool SoftwareUpdater::validateUpdate( return updateAuthority->second.verify(data,len,signature.data(),(unsigned int)signature.length()); } -void SoftwareUpdater::_cbHandleGetLatestVersionInfo(void *arg,int code,const std::string &url,bool onDisk,const std::string &body) +void SoftwareUpdater::_cbHandleGetLatestVersionInfo(void *arg,int code,const std::string &url,const std::string &body) { SoftwareUpdater *upd = (SoftwareUpdater *)arg; const RuntimeEnvironment *_r = (const RuntimeEnvironment *)upd->_r; @@ -175,14 +203,14 @@ void SoftwareUpdater::_cbHandleGetLatestVersionInfo(void *arg,int code,const std upd->_signedBy = signedBy; upd->_signature = signature; - HttpClient::GET(url,HttpClient::NO_HEADERS,ZT_UPDATE_HTTP_TIMEOUT,&_cbHandleGetLatestVersionBinary,arg); + _r->http->GET(url,HttpClient::NO_HEADERS,ZT_UPDATE_HTTP_TIMEOUT,&_cbHandleGetLatestVersionBinary,arg); } catch ( ... ) { LOG("software update check failed: .nfo file invalid or missing field(s)"); upd->_status = UPDATE_STATUS_IDLE; } } -void SoftwareUpdater::_cbHandleGetLatestVersionBinary(void *arg,int code,const std::string &url,bool onDisk,const std::string &body) +void SoftwareUpdater::_cbHandleGetLatestVersionBinary(void *arg,int code,const std::string &url,const std::string &body) { SoftwareUpdater *upd = (SoftwareUpdater *)arg; const RuntimeEnvironment *_r = (const RuntimeEnvironment *)upd->_r; |
