osdep/ compile fixes, and remove some lingering OS-specific stuff from node/Defaults

This commit is contained in:
Adam Ierymenko 2015-04-08 19:03:30 -07:00
parent d761330465
commit 7192fe6d15
14 changed files with 110 additions and 140 deletions

View file

@ -48,40 +48,6 @@ namespace ZeroTier {
const Defaults ZT_DEFAULTS; const Defaults ZT_DEFAULTS;
static inline std::string _mkDefaultHomePath()
{
#ifdef __UNIX_LIKE__
#ifdef __APPLE__
// /Library/... on Apple
return std::string("/Library/Application Support/ZeroTier/One");
#else
#ifdef __FreeBSD__
// FreeBSD likes /var/db instead of /var/lib
return std::string("/var/db/zerotier-one");
#else
// Use /var/lib for Linux and other *nix
return std::string("/var/lib/zerotier-one");
#endif
#endif
#else // not __UNIX_LIKE__
#ifdef __WINDOWS__
// Look up app data folder on Windows, e.g. C:\ProgramData\...
char buf[16384];
if (SUCCEEDED(SHGetFolderPathA(NULL,CSIDL_COMMON_APPDATA,NULL,0,buf)))
return (std::string(buf) + "\\ZeroTier\\One");
else return std::string("C:\\ZeroTier\\One");
#else
#error Unknown platform, please define a default home path!
#endif
#endif // __UNIX_LIKE__ or not...
}
static inline std::map< Address,Identity > _mkRootTopologyAuth() static inline std::map< Address,Identity > _mkRootTopologyAuth()
{ {
std::map< Address,Identity > ua; std::map< Address,Identity > ua;
@ -106,60 +72,9 @@ static inline std::map< Address,Identity > _mkRootTopologyAuth()
return ua; return ua;
} }
static inline std::map< Address,Identity > _mkUpdateAuth()
{
std::map< Address,Identity > ua;
{ // 0001
Identity id("e9bc3707b5:0:c4cef17bde99eadf9748c4fd11b9b06dc5cd8eb429227811d2c336e6b96a8d329e8abd0a4f45e47fe1bcebf878c004c822d952ff77fc2833af4c74e65985c435");
ua[id.address()] = id;
}
{ // 0002
Identity id("56520eaf93:0:7d858b47988b34399a9a31136de07b46104d7edb4a98fa1d6da3e583d3a33e48be531532b886f0b12cd16794a66ab9220749ec5112cbe96296b18fe0cc79ca05");
ua[id.address()] = id;
}
{ // 0003
Identity id("7c195de2e0:0:9f659071c960f9b0f0b96f9f9ecdaa27c7295feed9c79b7db6eedcc11feb705e6dd85c70fa21655204d24c897865b99eb946b753a2bbcf2be5f5e006ae618c54");
ua[id.address()] = id;
}
{ // 0004
Identity id("415f4cfde7:0:54118e87777b0ea5d922c10b337c4f4bd1db7141845bd54004b3255551a6e356ba6b9e1e85357dbfafc45630b8faa2ebf992f31479e9005f0472685f2d8cbd6e");
ua[id.address()] = id;
}
return ua;
}
static inline const char *_mkUpdateUrl()
{
#if defined(__LINUX__) && ( defined(__i386__) || defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(__i386) )
if (sizeof(void *) == 8)
return "http://download.zerotier.com/ZeroTierOneInstaller-linux-x64-LATEST.nfo";
else return "http://download.zerotier.com/ZeroTierOneInstaller-linux-x86-LATEST.nfo";
#define GOT_UPDATE_URL
#endif
#ifdef __APPLE__
return "http://download.zerotier.com/ZeroTierOneInstaller-mac-combined-LATEST.nfo";
#define GOT_UPDATE_URL
#endif
#ifdef __WINDOWS__
return "http://download.zerotier.com/ZeroTierOneInstaller-windows-intel-LATEST.nfo";
#define GOT_UPDATE_URL
#endif
#ifndef GOT_UPDATE_URL
return "";
#endif
}
Defaults::Defaults() : Defaults::Defaults() :
defaultHomePath(_mkDefaultHomePath()),
defaultRootTopology((const char *)ZT_DEFAULT_ROOT_TOPOLOGY,ZT_DEFAULT_ROOT_TOPOLOGY_LEN), defaultRootTopology((const char *)ZT_DEFAULT_ROOT_TOPOLOGY,ZT_DEFAULT_ROOT_TOPOLOGY_LEN),
rootTopologyAuthorities(_mkRootTopologyAuth()), rootTopologyAuthorities(_mkRootTopologyAuth()),
updateAuthorities(_mkUpdateAuth()),
updateLatestNfoURL(_mkUpdateUrl()),
v4Broadcast(((uint32_t)0xffffffff),ZT1_DEFAULT_PORT) v4Broadcast(((uint32_t)0xffffffff),ZT1_DEFAULT_PORT)
{ {
} }

View file

@ -51,11 +51,6 @@ class Defaults
public: public:
Defaults(); Defaults();
/**
* Default home path for this platform
*/
const std::string defaultHomePath;
/** /**
* Default root topology dictionary * Default root topology dictionary
*/ */
@ -66,22 +61,6 @@ public:
*/ */
const std::map< Address,Identity > rootTopologyAuthorities; const std::map< Address,Identity > rootTopologyAuthorities;
/**
* Identities permitted to sign software updates
*
* ZTN can keep multiple signing identities and rotate them, keeping some in
* "cold storage" and obsoleting others gradually.
*
* If you don't build with ZT_OFFICIAL_BUILD, this isn't used since your
* build will not auto-update.
*/
const std::map< Address,Identity > updateAuthorities;
/**
* URL to latest .nfo for software updates
*/
const std::string updateLatestNfoURL;
/** /**
* Address for IPv4 LAN auto-location broadcasts: 255.255.255.255:9993 * Address for IPv4 LAN auto-location broadcasts: 255.255.255.255:9993
*/ */

View file

@ -34,7 +34,7 @@
#include <stdexcept> #include <stdexcept>
#include "EthernetTap.hpp" #include "EthernetTap.hpp"
#include "../node/Thread.hpp" #include "Thread.hpp"
namespace ZeroTier { namespace ZeroTier {

View file

@ -37,9 +37,8 @@
#include "../node/Constants.hpp" #include "../node/Constants.hpp"
#include "../node/MAC.hpp" #include "../node/MAC.hpp"
#include "../node/InetAddress.hpp" #include "../node/InetAddress.hpp"
#include "../node/Buffer.hpp" #include "../node/MulticastGroup.hpp"
#include "MulticastGroup.hpp" #include "../node/NonCopyable.hpp"
#include "NonCopyable.hpp"
namespace ZeroTier { namespace ZeroTier {

View file

@ -25,7 +25,7 @@
* LLC. Start here: http://www.zerotier.com/ * LLC. Start here: http://www.zerotier.com/
*/ */
#include "Constants.hpp" #include "../node/Constants.hpp"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -56,9 +56,7 @@
#include "HttpClient.hpp" #include "HttpClient.hpp"
#include "Thread.hpp" #include "Thread.hpp"
#include "Utils.hpp" #include "OSUtils.hpp"
#include "NonCopyable.hpp"
#include "Defaults.hpp"
namespace ZeroTier { namespace ZeroTier {
@ -82,7 +80,7 @@ static const char *CURL_PATHS[NUM_CURL_PATHS] = { "/usr/bin/curl","/bin/curl","/
// Internal private thread class that performs request, notifies handler, // Internal private thread class that performs request, notifies handler,
// and then commits suicide by deleting itself. // and then commits suicide by deleting itself.
class HttpClient_Private_Request : NonCopyable class HttpClient_Private_Request
{ {
public: public:
HttpClient_Private_Request(HttpClient *parent,const char *method,const std::string &url,const std::map<std::string,std::string> &headers,unsigned int timeout,void (*handler)(void *,int,const std::string &,const std::string &),void *arg) : HttpClient_Private_Request(HttpClient *parent,const char *method,const std::string &url,const std::map<std::string,std::string> &headers,unsigned int timeout,void (*handler)(void *,int,const std::string &,const std::string &),void *arg) :
@ -113,7 +111,7 @@ public:
std::string curlPath; std::string curlPath;
for(int i=0;i<NUM_CURL_PATHS;++i) { for(int i=0;i<NUM_CURL_PATHS;++i) {
if (Utils::fileExists(CURL_PATHS[i])) { if (OSUtils::fileExists(CURL_PATHS[i])) {
curlPath = CURL_PATHS[i]; curlPath = CURL_PATHS[i];
break; break;
} }
@ -177,7 +175,7 @@ public:
fcntl(curlStderr[0],F_SETFL,O_NONBLOCK); fcntl(curlStderr[0],F_SETFL,O_NONBLOCK);
int exitCode = -1; int exitCode = -1;
unsigned long long timesOutAt = Utils::now() + ((unsigned long long)_timeout * 1000ULL); unsigned long long timesOutAt = OSUtils::now() + ((unsigned long long)_timeout * 1000ULL);
bool timedOut = false; bool timedOut = false;
bool tooLong = false; bool tooLong = false;
@ -198,7 +196,7 @@ public:
if (n > 0) { if (n > 0) {
_body.append(buf,n); _body.append(buf,n);
// Reset timeout when data is read... // Reset timeout when data is read...
timesOutAt = Utils::now() + ((unsigned long long)_timeout * 1000ULL); timesOutAt = OSUtils::now() + ((unsigned long long)_timeout * 1000ULL);
} else if (n < 0) } else if (n < 0)
break; break;
if (_body.length() > CURL_MAX_MESSAGE_LENGTH) { if (_body.length() > CURL_MAX_MESSAGE_LENGTH) {
@ -213,7 +211,7 @@ public:
if (FD_ISSET(curlStdout[0],&errfds)||FD_ISSET(curlStderr[0],&errfds)) if (FD_ISSET(curlStdout[0],&errfds)||FD_ISSET(curlStderr[0],&errfds))
break; break;
if (Utils::now() >= timesOutAt) { if (OSUtils::now() >= timesOutAt) {
timedOut = true; timedOut = true;
break; break;
} }
@ -283,7 +281,7 @@ public:
return; return;
} }
++scPos; ++scPos;
unsigned int rcode = Utils::strToUInt(headers.front().substr(scPos,3).c_str()); unsigned int rcode = OSUtils::strToUInt(headers.front().substr(scPos,3).c_str());
if ((!rcode)||(rcode > 999)) { if ((!rcode)||(rcode > 999)) {
_doH(_arg,-1,_url,"invalid HTTP response (invalid response code)"); _doH(_arg,-1,_url,"invalid HTTP response (invalid response code)");
delete this; delete this;

View file

@ -32,8 +32,7 @@
#include <map> #include <map>
#include <set> #include <set>
#include "Constants.hpp" #include "../node/Mutex.hpp"
#include "Mutex.hpp"
namespace ZeroTier { namespace ZeroTier {

View file

@ -33,8 +33,8 @@
#include <stdexcept> #include <stdexcept>
#include "../node/EthernetTap.hpp" #include "EthernetTap.hpp"
#include "../node/Thread.hpp" #include "Thread.hpp"
namespace ZeroTier { namespace ZeroTier {

View file

@ -51,6 +51,40 @@
namespace ZeroTier { namespace ZeroTier {
static inline std::string _mkDefaultHomePath()
{
#ifdef __UNIX_LIKE__
#ifdef __APPLE__
// /Library/... on Apple
return std::string("/Library/Application Support/ZeroTier/One");
#else
#ifdef __FreeBSD__
// FreeBSD likes /var/db instead of /var/lib
return std::string("/var/db/zerotier-one");
#else
// Use /var/lib for Linux and other *nix
return std::string("/var/lib/zerotier-one");
#endif
#endif
#else // not __UNIX_LIKE__
#ifdef __WINDOWS__
// Look up app data folder on Windows, e.g. C:\ProgramData\...
char buf[16384];
if (SUCCEEDED(SHGetFolderPathA(NULL,CSIDL_COMMON_APPDATA,NULL,0,buf)))
return (std::string(buf) + "\\ZeroTier\\One");
else return std::string("C:\\ZeroTier\\One");
#else
#error Unknown platform, please define a default home path!
#endif
#endif // __UNIX_LIKE__ or not...
}
#ifdef __UNIX_LIKE__ #ifdef __UNIX_LIKE__
bool OSUtils::redirectUnixOutputs(const char *stdoutPath,const char *stderrPath) bool OSUtils::redirectUnixOutputs(const char *stdoutPath,const char *stderrPath)
throw() throw()

View file

@ -33,8 +33,8 @@
#include <stdexcept> #include <stdexcept>
#include "../node/EthernetTap.hpp" #include "EthernetTap.hpp"
#include "../node/Thread.hpp" #include "Thread.hpp"
namespace ZeroTier { namespace ZeroTier {

View file

@ -54,6 +54,54 @@
namespace ZeroTier { namespace ZeroTier {
static inline std::map< Address,Identity > _mkUpdateAuth()
{
std::map< Address,Identity > ua;
{ // 0001
Identity id("e9bc3707b5:0:c4cef17bde99eadf9748c4fd11b9b06dc5cd8eb429227811d2c336e6b96a8d329e8abd0a4f45e47fe1bcebf878c004c822d952ff77fc2833af4c74e65985c435");
ua[id.address()] = id;
}
{ // 0002
Identity id("56520eaf93:0:7d858b47988b34399a9a31136de07b46104d7edb4a98fa1d6da3e583d3a33e48be531532b886f0b12cd16794a66ab9220749ec5112cbe96296b18fe0cc79ca05");
ua[id.address()] = id;
}
{ // 0003
Identity id("7c195de2e0:0:9f659071c960f9b0f0b96f9f9ecdaa27c7295feed9c79b7db6eedcc11feb705e6dd85c70fa21655204d24c897865b99eb946b753a2bbcf2be5f5e006ae618c54");
ua[id.address()] = id;
}
{ // 0004
Identity id("415f4cfde7:0:54118e87777b0ea5d922c10b337c4f4bd1db7141845bd54004b3255551a6e356ba6b9e1e85357dbfafc45630b8faa2ebf992f31479e9005f0472685f2d8cbd6e");
ua[id.address()] = id;
}
return ua;
}
static inline const char *_mkUpdateUrl()
{
#if defined(__LINUX__) && ( defined(__i386__) || defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(__i386) )
if (sizeof(void *) == 8)
return "http://download.zerotier.com/ZeroTierOneInstaller-linux-x64-LATEST.nfo";
else return "http://download.zerotier.com/ZeroTierOneInstaller-linux-x86-LATEST.nfo";
#define GOT_UPDATE_URL
#endif
#ifdef __APPLE__
return "http://download.zerotier.com/ZeroTierOneInstaller-mac-combined-LATEST.nfo";
#define GOT_UPDATE_URL
#endif
#ifdef __WINDOWS__
return "http://download.zerotier.com/ZeroTierOneInstaller-windows-intel-LATEST.nfo";
#define GOT_UPDATE_URL
#endif
#ifndef GOT_UPDATE_URL
return "";
#endif
}
SoftwareUpdater::SoftwareUpdater(const RuntimeEnvironment *renv) : SoftwareUpdater::SoftwareUpdater(const RuntimeEnvironment *renv) :
RR(renv), RR(renv),
_myVersion(packVersion(ZEROTIER_ONE_VERSION_MAJOR,ZEROTIER_ONE_VERSION_MINOR,ZEROTIER_ONE_VERSION_REVISION)), _myVersion(packVersion(ZEROTIER_ONE_VERSION_MAJOR,ZEROTIER_ONE_VERSION_MINOR,ZEROTIER_ONE_VERSION_REVISION)),

View file

@ -32,11 +32,11 @@
#include <string> #include <string>
#include "Constants.hpp" #include "../node/Constants.hpp"
#include "Mutex.hpp" #include "../node/Mutex.hpp"
#include "Utils.hpp" #include "../node/Address.hpp"
#include "Defaults.hpp"
#include "Address.hpp" #include "HttpClient.hpp"
/** /**
* Delay between fetches of the root topology update URL * Delay between fetches of the root topology update URL
@ -62,15 +62,13 @@
namespace ZeroTier { namespace ZeroTier {
class RuntimeEnvironment;
/** /**
* Software updater * Software updater
*/ */
class SoftwareUpdater class SoftwareUpdater
{ {
public: public:
SoftwareUpdater(const RuntimeEnvironment *renv); SoftwareUpdater();
~SoftwareUpdater(); ~SoftwareUpdater();
/** /**
@ -169,7 +167,7 @@ private:
static void _cbHandleGetLatestVersionInfo(void *arg,int code,const std::string &url,const std::string &body); static void _cbHandleGetLatestVersionInfo(void *arg,int code,const std::string &url,const std::string &body);
static void _cbHandleGetLatestVersionBinary(void *arg,int code,const std::string &url,const std::string &body); static void _cbHandleGetLatestVersionBinary(void *arg,int code,const std::string &url,const std::string &body);
const RuntimeEnvironment *RR; HttpClient httpClient;
const uint64_t _myVersion; const uint64_t _myVersion;
volatile uint64_t _lastUpdateAttempt; volatile uint64_t _lastUpdateAttempt;
volatile enum { volatile enum {

View file

@ -30,7 +30,7 @@
#include <stdexcept> #include <stdexcept>
#include "Constants.hpp" #include "../node/Constants.hpp"
#ifdef __WINDOWS__ #ifdef __WINDOWS__

View file

@ -46,12 +46,11 @@
#include <iostream> #include <iostream>
#include "../node/Constants.hpp" #include "../node/Constants.hpp"
#include "WindowsEthernetTap.hpp"
#include "WindowsEthernetTapFactory.hpp"
#include "../node/Utils.hpp" #include "../node/Utils.hpp"
#include "../node/Mutex.hpp" #include "../node/Mutex.hpp"
#include "WindowsEthernetTap.hpp"
#include "..\windows\TapDriver\tap-windows.h" #include "..\windows\TapDriver\tap-windows.h"
// ff:ff:ff:ff:ff:ff with no ADI // ff:ff:ff:ff:ff:ff with no ADI

View file

@ -37,8 +37,9 @@
#include <queue> #include <queue>
#include <stdexcept> #include <stdexcept>
#include "EthernetTap.hpp"
#include "../node/Constants.hpp" #include "../node/Constants.hpp"
#include "../node/EthernetTap.hpp"
#include "../node/Mutex.hpp" #include "../node/Mutex.hpp"
#include "../node/Thread.hpp" #include "../node/Thread.hpp"
#include "../node/Array.hpp" #include "../node/Array.hpp"