summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@zerotier.com>2014-08-07 19:08:41 -0700
committerAdam Ierymenko <adam.ierymenko@zerotier.com>2014-08-07 19:08:41 -0700
commit77457cbff14546a6b6173a46c0486767dab60847 (patch)
treeb9c5a7453d89678ed46cc51e51c2387c212e8055
parentdb0d17cebba67dec344ee63c3b8ecbdc46f2814a (diff)
downloadinfinitytier-77457cbff14546a6b6173a46c0486767dab60847.tar.gz
infinitytier-77457cbff14546a6b6173a46c0486767dab60847.zip
Windows compile fixes, compiler warning fix, unfreed memory fix in main.c (though it would not have mattered since program exits immediately after).
-rw-r--r--main.cpp10
-rw-r--r--node/Network.cpp2
-rw-r--r--node/Utils.hpp2
-rw-r--r--osnet/WindowsEthernetTap.cpp4
-rw-r--r--osnet/WindowsEthernetTapFactory.cpp1
-rw-r--r--windows/ZeroTierOne/ZeroTierOne.vcxproj1
-rw-r--r--windows/ZeroTierOne/ZeroTierOne.vcxproj.filters3
-rw-r--r--windows/ZeroTierOne/ZeroTierOneService.cpp36
8 files changed, 44 insertions, 15 deletions
diff --git a/main.cpp b/main.cpp
index 6485b8ff..f13f6ee2 100644
--- a/main.cpp
+++ b/main.cpp
@@ -702,9 +702,12 @@ int main(int argc,char **argv)
int exitCode = 0;
bool needsReset = false;
+ EthernetTapFactory *tapFactory = (EthernetTapFactory *)0;
+ RoutingTable *routingTable = (RoutingTable *)0;
+
try {
- EthernetTapFactory *tapFactory = ZTCreatePlatformEthernetTapFactory;
- RoutingTable *routingTable = ZTCreatePlatformRoutingTable;
+ tapFactory = ZTCreatePlatformEthernetTapFactory;
+ routingTable = ZTCreatePlatformRoutingTable;
node = new Node(homeDir,tapFactory,routingTable,udpPort,tcpPort,needsReset);
@@ -761,6 +764,9 @@ int main(int argc,char **argv)
exitCode = 3;
}
+ delete routingTable;
+ delete tapFactory;
+
#ifdef __UNIX_LIKE__
Utils::rm((std::string(homeDir)+"/zerotier-one.pid").c_str());
#endif
diff --git a/node/Network.cpp b/node/Network.cpp
index 23b32946..c024a54b 100644
--- a/node/Network.cpp
+++ b/node/Network.cpp
@@ -340,7 +340,7 @@ void Network::threadMain()
char fname[1024],lcentry[128];
Utils::snprintf(lcentry,sizeof(lcentry),"_dev_for_%.16llx",(unsigned long long)_id);
- EthernetTap *t;
+ EthernetTap *t = (EthernetTap *)0;
try {
std::string desiredDevice(_nc->getLocalConfig(lcentry));
_mkNetworkFriendlyName(fname,sizeof(fname));
diff --git a/node/Utils.hpp b/node/Utils.hpp
index 0b892cd9..affae9a8 100644
--- a/node/Utils.hpp
+++ b/node/Utils.hpp
@@ -180,7 +180,7 @@ public:
* @return Number of characters actually written
*/
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
diff --git a/osnet/WindowsEthernetTap.cpp b/osnet/WindowsEthernetTap.cpp
index 16fc72d6..8326597a 100644
--- a/osnet/WindowsEthernetTap.cpp
+++ b/osnet/WindowsEthernetTap.cpp
@@ -188,11 +188,11 @@ WindowsEthernetTap::WindowsEthernetTap(
PROCESS_INFORMATION processInfo;
memset(&startupInfo,0,sizeof(STARTUPINFOA));
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);
if (devconLog != INVALID_HANDLE_VALUE)
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);
CloseHandle(processInfo.hProcess);
diff --git a/osnet/WindowsEthernetTapFactory.cpp b/osnet/WindowsEthernetTapFactory.cpp
index 6564e186..74703077 100644
--- a/osnet/WindowsEthernetTapFactory.cpp
+++ b/osnet/WindowsEthernetTapFactory.cpp
@@ -43,6 +43,7 @@ WindowsEthernetTapFactory::Env::Env()
tapDriver = ((is64Bit == TRUE) ? "\\tap-windows\\x64\\zttap200.inf" : "\\tap-windows\\x86\\zttap200.inf");
#endif
}
+const WindowsEthernetTapFactory::Env WindowsEthernetTapFactory::WINENV;
WindowsEthernetTapFactory::WindowsEthernetTapFactory(const char *pathToHelpers) :
_pathToHelpers(pathToHelpers)
diff --git a/windows/ZeroTierOne/ZeroTierOne.vcxproj b/windows/ZeroTierOne/ZeroTierOne.vcxproj
index b31a76cc..c84d9570 100644
--- a/windows/ZeroTierOne/ZeroTierOne.vcxproj
+++ b/windows/ZeroTierOne/ZeroTierOne.vcxproj
@@ -24,6 +24,7 @@
<ClCompile Include="..\..\node\C25519.cpp" />
<ClCompile Include="..\..\node\CertificateOfMembership.cpp" />
<ClCompile Include="..\..\node\Defaults.cpp" />
+ <ClCompile Include="..\..\node\Dictionary.cpp" />
<ClCompile Include="..\..\node\HttpClient.cpp" />
<ClCompile Include="..\..\node\Identity.cpp" />
<ClCompile Include="..\..\node\InetAddress.cpp" />
diff --git a/windows/ZeroTierOne/ZeroTierOne.vcxproj.filters b/windows/ZeroTierOne/ZeroTierOne.vcxproj.filters
index dcba83ef..ee552627 100644
--- a/windows/ZeroTierOne/ZeroTierOne.vcxproj.filters
+++ b/windows/ZeroTierOne/ZeroTierOne.vcxproj.filters
@@ -126,6 +126,9 @@
<ClCompile Include="..\..\osnet\WindowsRoutingTable.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="..\..\node\Dictionary.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\ext\lz4\lz4.h">
diff --git a/windows/ZeroTierOne/ZeroTierOneService.cpp b/windows/ZeroTierOne/ZeroTierOneService.cpp
index a6758d1b..f0d93280 100644
--- a/windows/ZeroTierOne/ZeroTierOneService.cpp
+++ b/windows/ZeroTierOne/ZeroTierOneService.cpp
@@ -26,15 +26,21 @@
*/
#pragma region Includes
+
#include <WinSock2.h>
#include <Windows.h>
#include <stdio.h>
#include <stdlib.h>
#include "ZeroTierOneService.h"
+
#include "../../node/Defaults.hpp"
#include "../../node/Utils.hpp"
-#pragma endregion
+
+#include "../../osnet/WindowsEthernetTapFactory.hpp"
+#include "../../osnet/WindowsRoutingTable.hpp"
+
+#pragma endregion // Includes
#ifdef ZT_DEBUG_SERVICE
FILE *SVCDBGfile = (FILE *)0;
@@ -76,27 +82,35 @@ void ZeroTierOneService::threadMain()
restart_node:
try {
+ ZeroTier::WindowsEthernetTapFactory tapFactory(ZeroTier::ZT_DEFAULTS.defaultHomePath.c_str());
+ ZeroTier::WindowsRoutingTable routingTable;
+
{
// start or restart
ZeroTier::Mutex::Lock _l(_lock);
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()) {
+
case ZeroTier::Node::NODE_RESTART_FOR_UPGRADE: {
// Shut down node
ZeroTier::Node *n;
{
- ZeroTier::Mutex::Lock _l(_lock);
- n = _node;
- _node = (ZeroTier::Node *)0;
+ ZeroTier::Mutex::Lock _l(_lock);
+ n = _node;
+ _node = (ZeroTier::Node *)0;
}
+
+ // Get upgrade path, which will be its reason for termination
std::string msiPath;
if (n) {
const char *msiPathTmp = n->reasonForTermination();
if (msiPathTmp)
msiPath = msiPathTmp;
}
+
delete n;
if ((!msiPath.length())||(!ZeroTier::Utils::fileExists(msiPath.c_str()))) {
@@ -114,6 +128,7 @@ restart_node:
// Terminate service to allow updater to update
Stop();
} return;
+
case ZeroTier::Node::NODE_UNRECOVERABLE_ERROR: {
std::string err("ZeroTier node encountered an unrecoverable error: ");
const char *r = _node->reasonForTermination();
@@ -125,8 +140,10 @@ restart_node:
Sleep(5000);
goto restart_node;
} break;
+
default: // includes normal termination, which will terminate thread
break;
+
}
} catch ( ... ) {
// sanity check, shouldn't happen since Node::run() should catch all its own errors
@@ -136,10 +153,11 @@ restart_node:
goto restart_node;
}
- _lock.lock();
- delete _node;
- _node = (ZeroTier::Node *)0;
- _lock.unlock();
+ {
+ ZeroTier::Mutex::Lock _l(_lock);
+ delete _node;
+ _node = (ZeroTier::Node *)0;
+ }
}
bool ZeroTierOneService::doStartUpgrade(const std::string &msiPath)