mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 12:33:44 +02:00
Windows compile fixes, compiler warning fix, unfreed memory fix in main.c (though it would not have mattered since program exits immediately after).
This commit is contained in:
parent
db0d17cebb
commit
77457cbff1
8 changed files with 44 additions and 15 deletions
10
main.cpp
10
main.cpp
|
@ -702,9 +702,12 @@ int main(int argc,char **argv)
|
||||||
|
|
||||||
int exitCode = 0;
|
int exitCode = 0;
|
||||||
bool needsReset = false;
|
bool needsReset = false;
|
||||||
|
EthernetTapFactory *tapFactory = (EthernetTapFactory *)0;
|
||||||
|
RoutingTable *routingTable = (RoutingTable *)0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
EthernetTapFactory *tapFactory = ZTCreatePlatformEthernetTapFactory;
|
tapFactory = ZTCreatePlatformEthernetTapFactory;
|
||||||
RoutingTable *routingTable = ZTCreatePlatformRoutingTable;
|
routingTable = ZTCreatePlatformRoutingTable;
|
||||||
|
|
||||||
node = new Node(homeDir,tapFactory,routingTable,udpPort,tcpPort,needsReset);
|
node = new Node(homeDir,tapFactory,routingTable,udpPort,tcpPort,needsReset);
|
||||||
|
|
||||||
|
@ -761,6 +764,9 @@ int main(int argc,char **argv)
|
||||||
exitCode = 3;
|
exitCode = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete routingTable;
|
||||||
|
delete tapFactory;
|
||||||
|
|
||||||
#ifdef __UNIX_LIKE__
|
#ifdef __UNIX_LIKE__
|
||||||
Utils::rm((std::string(homeDir)+"/zerotier-one.pid").c_str());
|
Utils::rm((std::string(homeDir)+"/zerotier-one.pid").c_str());
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -340,7 +340,7 @@ void Network::threadMain()
|
||||||
char fname[1024],lcentry[128];
|
char fname[1024],lcentry[128];
|
||||||
Utils::snprintf(lcentry,sizeof(lcentry),"_dev_for_%.16llx",(unsigned long long)_id);
|
Utils::snprintf(lcentry,sizeof(lcentry),"_dev_for_%.16llx",(unsigned long long)_id);
|
||||||
|
|
||||||
EthernetTap *t;
|
EthernetTap *t = (EthernetTap *)0;
|
||||||
try {
|
try {
|
||||||
std::string desiredDevice(_nc->getLocalConfig(lcentry));
|
std::string desiredDevice(_nc->getLocalConfig(lcentry));
|
||||||
_mkNetworkFriendlyName(fname,sizeof(fname));
|
_mkNetworkFriendlyName(fname,sizeof(fname));
|
||||||
|
|
|
@ -180,7 +180,7 @@ public:
|
||||||
* @return Number of characters actually written
|
* @return Number of characters actually written
|
||||||
*/
|
*/
|
||||||
static unsigned int unhex(const char *hex,unsigned int maxlen,void *buf,unsigned int len);
|
static unsigned int unhex(const char *hex,unsigned int maxlen,void *buf,unsigned int len);
|
||||||
static inline unsigned int unhex(const std::string &hex,void *buf,unsigned int len) { return unhex(hex.c_str(),hex.length(),buf,len); }
|
static inline unsigned int unhex(const std::string &hex,void *buf,unsigned int len) { return unhex(hex.c_str(),(unsigned int)hex.length(),buf,len); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate secure random bytes
|
* Generate secure random bytes
|
||||||
|
|
|
@ -188,11 +188,11 @@ WindowsEthernetTap::WindowsEthernetTap(
|
||||||
PROCESS_INFORMATION processInfo;
|
PROCESS_INFORMATION processInfo;
|
||||||
memset(&startupInfo,0,sizeof(STARTUPINFOA));
|
memset(&startupInfo,0,sizeof(STARTUPINFOA));
|
||||||
memset(&processInfo,0,sizeof(PROCESS_INFORMATION));
|
memset(&processInfo,0,sizeof(PROCESS_INFORMATION));
|
||||||
if (!CreateProcessA(NULL,(LPSTR)(std::string("\"") + _pathToHelpers + WindowsEthernetTapFactory::WINENV.devcon + "\" install \"" + _pathToHelpers + _winEnv.tapDriver + "\" zttap200").c_str(),NULL,NULL,FALSE,0,NULL,NULL,&startupInfo,&processInfo)) {
|
if (!CreateProcessA(NULL,(LPSTR)(std::string("\"") + _pathToHelpers + WindowsEthernetTapFactory::WINENV.devcon + "\" install \"" + _pathToHelpers + WindowsEthernetTapFactory::WINENV.tapDriver + "\" zttap200").c_str(),NULL,NULL,FALSE,0,NULL,NULL,&startupInfo,&processInfo)) {
|
||||||
RegCloseKey(nwAdapters);
|
RegCloseKey(nwAdapters);
|
||||||
if (devconLog != INVALID_HANDLE_VALUE)
|
if (devconLog != INVALID_HANDLE_VALUE)
|
||||||
CloseHandle(devconLog);
|
CloseHandle(devconLog);
|
||||||
throw std::runtime_error(std::string("unable to find or execute devcon at ") + _winEnv.devcon);
|
throw std::runtime_error(std::string("unable to find or execute devcon at ") + WindowsEthernetTapFactory::WINENV.devcon);
|
||||||
}
|
}
|
||||||
WaitForSingleObject(processInfo.hProcess,INFINITE);
|
WaitForSingleObject(processInfo.hProcess,INFINITE);
|
||||||
CloseHandle(processInfo.hProcess);
|
CloseHandle(processInfo.hProcess);
|
||||||
|
|
|
@ -43,6 +43,7 @@ WindowsEthernetTapFactory::Env::Env()
|
||||||
tapDriver = ((is64Bit == TRUE) ? "\\tap-windows\\x64\\zttap200.inf" : "\\tap-windows\\x86\\zttap200.inf");
|
tapDriver = ((is64Bit == TRUE) ? "\\tap-windows\\x64\\zttap200.inf" : "\\tap-windows\\x86\\zttap200.inf");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
const WindowsEthernetTapFactory::Env WindowsEthernetTapFactory::WINENV;
|
||||||
|
|
||||||
WindowsEthernetTapFactory::WindowsEthernetTapFactory(const char *pathToHelpers) :
|
WindowsEthernetTapFactory::WindowsEthernetTapFactory(const char *pathToHelpers) :
|
||||||
_pathToHelpers(pathToHelpers)
|
_pathToHelpers(pathToHelpers)
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
<ClCompile Include="..\..\node\C25519.cpp" />
|
<ClCompile Include="..\..\node\C25519.cpp" />
|
||||||
<ClCompile Include="..\..\node\CertificateOfMembership.cpp" />
|
<ClCompile Include="..\..\node\CertificateOfMembership.cpp" />
|
||||||
<ClCompile Include="..\..\node\Defaults.cpp" />
|
<ClCompile Include="..\..\node\Defaults.cpp" />
|
||||||
|
<ClCompile Include="..\..\node\Dictionary.cpp" />
|
||||||
<ClCompile Include="..\..\node\HttpClient.cpp" />
|
<ClCompile Include="..\..\node\HttpClient.cpp" />
|
||||||
<ClCompile Include="..\..\node\Identity.cpp" />
|
<ClCompile Include="..\..\node\Identity.cpp" />
|
||||||
<ClCompile Include="..\..\node\InetAddress.cpp" />
|
<ClCompile Include="..\..\node\InetAddress.cpp" />
|
||||||
|
|
|
@ -126,6 +126,9 @@
|
||||||
<ClCompile Include="..\..\osnet\WindowsRoutingTable.cpp">
|
<ClCompile Include="..\..\osnet\WindowsRoutingTable.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\node\Dictionary.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\ext\lz4\lz4.h">
|
<ClInclude Include="..\..\ext\lz4\lz4.h">
|
||||||
|
|
|
@ -26,15 +26,21 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma region Includes
|
#pragma region Includes
|
||||||
|
|
||||||
#include <WinSock2.h>
|
#include <WinSock2.h>
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "ZeroTierOneService.h"
|
#include "ZeroTierOneService.h"
|
||||||
|
|
||||||
#include "../../node/Defaults.hpp"
|
#include "../../node/Defaults.hpp"
|
||||||
#include "../../node/Utils.hpp"
|
#include "../../node/Utils.hpp"
|
||||||
#pragma endregion
|
|
||||||
|
#include "../../osnet/WindowsEthernetTapFactory.hpp"
|
||||||
|
#include "../../osnet/WindowsRoutingTable.hpp"
|
||||||
|
|
||||||
|
#pragma endregion // Includes
|
||||||
|
|
||||||
#ifdef ZT_DEBUG_SERVICE
|
#ifdef ZT_DEBUG_SERVICE
|
||||||
FILE *SVCDBGfile = (FILE *)0;
|
FILE *SVCDBGfile = (FILE *)0;
|
||||||
|
@ -76,27 +82,35 @@ void ZeroTierOneService::threadMain()
|
||||||
|
|
||||||
restart_node:
|
restart_node:
|
||||||
try {
|
try {
|
||||||
|
ZeroTier::WindowsEthernetTapFactory tapFactory(ZeroTier::ZT_DEFAULTS.defaultHomePath.c_str());
|
||||||
|
ZeroTier::WindowsRoutingTable routingTable;
|
||||||
|
|
||||||
{
|
{
|
||||||
// start or restart
|
// start or restart
|
||||||
ZeroTier::Mutex::Lock _l(_lock);
|
ZeroTier::Mutex::Lock _l(_lock);
|
||||||
delete _node;
|
delete _node;
|
||||||
_node = new ZeroTier::Node(ZeroTier::ZT_DEFAULTS.defaultHomePath.c_str(),ZT_DEFAULT_UDP_PORT,0,false);
|
_node = new ZeroTier::Node(ZeroTier::ZT_DEFAULTS.defaultHomePath.c_str(),&tapFactory,&routingTable,ZT_DEFAULT_UDP_PORT,0,false);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(_node->run()) {
|
switch(_node->run()) {
|
||||||
|
|
||||||
case ZeroTier::Node::NODE_RESTART_FOR_UPGRADE: {
|
case ZeroTier::Node::NODE_RESTART_FOR_UPGRADE: {
|
||||||
// Shut down node
|
// Shut down node
|
||||||
ZeroTier::Node *n;
|
ZeroTier::Node *n;
|
||||||
{
|
{
|
||||||
ZeroTier::Mutex::Lock _l(_lock);
|
ZeroTier::Mutex::Lock _l(_lock);
|
||||||
n = _node;
|
n = _node;
|
||||||
_node = (ZeroTier::Node *)0;
|
_node = (ZeroTier::Node *)0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get upgrade path, which will be its reason for termination
|
||||||
std::string msiPath;
|
std::string msiPath;
|
||||||
if (n) {
|
if (n) {
|
||||||
const char *msiPathTmp = n->reasonForTermination();
|
const char *msiPathTmp = n->reasonForTermination();
|
||||||
if (msiPathTmp)
|
if (msiPathTmp)
|
||||||
msiPath = msiPathTmp;
|
msiPath = msiPathTmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete n;
|
delete n;
|
||||||
|
|
||||||
if ((!msiPath.length())||(!ZeroTier::Utils::fileExists(msiPath.c_str()))) {
|
if ((!msiPath.length())||(!ZeroTier::Utils::fileExists(msiPath.c_str()))) {
|
||||||
|
@ -114,6 +128,7 @@ restart_node:
|
||||||
// Terminate service to allow updater to update
|
// Terminate service to allow updater to update
|
||||||
Stop();
|
Stop();
|
||||||
} return;
|
} return;
|
||||||
|
|
||||||
case ZeroTier::Node::NODE_UNRECOVERABLE_ERROR: {
|
case ZeroTier::Node::NODE_UNRECOVERABLE_ERROR: {
|
||||||
std::string err("ZeroTier node encountered an unrecoverable error: ");
|
std::string err("ZeroTier node encountered an unrecoverable error: ");
|
||||||
const char *r = _node->reasonForTermination();
|
const char *r = _node->reasonForTermination();
|
||||||
|
@ -125,8 +140,10 @@ restart_node:
|
||||||
Sleep(5000);
|
Sleep(5000);
|
||||||
goto restart_node;
|
goto restart_node;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
default: // includes normal termination, which will terminate thread
|
default: // includes normal termination, which will terminate thread
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch ( ... ) {
|
} catch ( ... ) {
|
||||||
// sanity check, shouldn't happen since Node::run() should catch all its own errors
|
// sanity check, shouldn't happen since Node::run() should catch all its own errors
|
||||||
|
@ -136,10 +153,11 @@ restart_node:
|
||||||
goto restart_node;
|
goto restart_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
_lock.lock();
|
{
|
||||||
delete _node;
|
ZeroTier::Mutex::Lock _l(_lock);
|
||||||
_node = (ZeroTier::Node *)0;
|
delete _node;
|
||||||
_lock.unlock();
|
_node = (ZeroTier::Node *)0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZeroTierOneService::doStartUpgrade(const std::string &msiPath)
|
bool ZeroTierOneService::doStartUpgrade(const std::string &msiPath)
|
||||||
|
|
Loading…
Add table
Reference in a new issue