소스 검색

Windows compile fixes, compiler warning fix, unfreed memory fix in main.c (though it would not have mattered since program exits immediately after).

Adam Ierymenko 11 년 전
부모
커밋
77457cbff1

+ 8 - 2
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

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

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

+ 2 - 2
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);

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

+ 1 - 0
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" />

+ 3 - 0
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">

+ 27 - 9
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)