瀏覽代碼

Windows build fixes.

Adam Ierymenko 11 年之前
父節點
當前提交
07f505971c

+ 2 - 0
.gitignore

@@ -34,3 +34,5 @@
 *.autosave
 /ZeroTier One.zip
 /ZeroTier One.dmg
+/windows/ZeroTierOne.sdf
+/windows/ZeroTierOne.v11.suo

+ 4 - 0
node/BandwidthAccount.hpp

@@ -34,6 +34,10 @@
 #include "Constants.hpp"
 #include "Utils.hpp"
 
+#ifdef __WINDOWS__
+#define	round(x) ((x-floor(x))>0.5 ? ceil(x) : floor(x))
+#endif
+
 namespace ZeroTier {
 
 /**

+ 4 - 0
node/C25519.cpp

@@ -18,6 +18,10 @@ Derived from public domain code by D. J. Bernstein.
 #include "SHA512.hpp"
 #include "Buffer.hpp"
 
+#ifdef __WINDOWS__
+#pragma warning(disable: 4146)
+#endif
+
 namespace ZeroTier {
 
 //////////////////////////////////////////////////////////////////////////////

+ 2 - 0
node/Constants.hpp

@@ -77,6 +77,8 @@
 #define ZT_PATH_SEPARATOR '\\'
 #define ZT_PATH_SEPARATOR_S "\\"
 #define ZT_EOL_S "\r\n"
+#include <WinSock2.h>
+#include <Windows.h>
 #endif
 
 // Assume these are little-endian. PPC is not supported for OSX, and ARM

+ 1 - 1
node/EthernetTap.cpp

@@ -938,7 +938,7 @@ void EthernetTap::threadMain()
 #include <nldef.h>
 #include <netioapi.h>
 
-#include "..\vsprojects\TapDriver\tap-windows.h"
+#include "..\windows\TapDriver\tap-windows.h"
 
 namespace ZeroTier {
 

+ 19 - 17
node/HttpClient.cpp

@@ -25,21 +25,20 @@
  * LLC. Start here: http://www.zerotier.com/
  */
 
+#include "Constants.hpp"
+
+#ifdef __WINDOWS__
+#include <WinSock2.h>
+#include <Windows.h>
+#include <winhttp.h>
+#include <locale>
+#include <codecvt>
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
-#include <vector>
-#include <utility>
-#include <algorithm>
-
-#include "Constants.hpp"
-#include "HttpClient.hpp"
-#include "Thread.hpp"
-#include "Utils.hpp"
-#include "NonCopyable.hpp"
-#include "Defaults.hpp"
-
 #ifdef __UNIX_LIKE__
 #include <unistd.h>
 #include <signal.h>
@@ -51,12 +50,15 @@
 #include <sys/wait.h>
 #endif
 
-#ifdef __WINDOWS__
-#include <locale>
-#include <codecvt>
-#include <Windows.h>
-#include <winhttp.h>
-#endif
+#include <vector>
+#include <utility>
+#include <algorithm>
+
+#include "HttpClient.hpp"
+#include "Thread.hpp"
+#include "Utils.hpp"
+#include "NonCopyable.hpp"
+#include "Defaults.hpp"
 
 namespace ZeroTier {
 

+ 2 - 2
node/NetworkConfig.hpp

@@ -112,8 +112,8 @@ public:
 		if ((!etherType)||(etherType > 0xffff)) // sanity checks
 			return false;
 		else if ((_etWhitelist[0] & 1)) // prsence of 0 in set inverts sense: whitelist becomes blacklist
-			return (!(_etWhitelist[etherType >> 3] & (1 << (etherType & 7))));
-		else return ((_etWhitelist[etherType >> 3] & (1 << (etherType & 7))));
+			return ((_etWhitelist[etherType >> 3] & (1 << (etherType & 7))) == 0);
+		else return ((_etWhitelist[etherType >> 3] & (1 << (etherType & 7))) != 0);
 	}
 
 	std::set<unsigned int> allowedEtherTypes() const;

+ 3 - 3
node/NodeConfig.cpp

@@ -77,7 +77,7 @@ NodeConfig::NodeConfig(const RuntimeEnvironment *renv,const char *authToken,unsi
 		if (!d->second) {
 			std::string::size_type dot = d->first.rfind(".conf");
 			if (dot != std::string::npos) {
-				uint64_t nwid = strtoull(d->first.substr(0,dot).c_str(),(char **)0,16);
+				uint64_t nwid = Utils::hexStrToU64(d->first.substr(0,dot).c_str());
 
 				// TODO: remove legacy code once out of beta
 				if (nwid == 0x6c92786fee000001ULL) {
@@ -230,7 +230,7 @@ std::vector<std::string> NodeConfig::execute(const char *command)
 		}
 	} else if (cmd[0] == "join") {
 		if (cmd.size() > 1) {
-			uint64_t nwid = strtoull(cmd[1].c_str(),(char **)0,16);
+			uint64_t nwid = Utils::hexStrToU64(cmd[1].c_str());
 			if (nwid > 0) {
 				Mutex::Lock _l(_networks_m);
 				if (_networks.count(nwid)) {
@@ -255,7 +255,7 @@ std::vector<std::string> NodeConfig::execute(const char *command)
 	} else if (cmd[0] == "leave") {
 		if (cmd.size() > 1) {
 			Mutex::Lock _l(_networks_m);
-			uint64_t nwid = strtoull(cmd[1].c_str(),(char **)0,16);
+			uint64_t nwid = Utils::hexStrToU64(cmd[1].c_str());
 			std::map< uint64_t,SharedPtr<Network> >::iterator nw(_networks.find(nwid));
 			if (nw == _networks.end()) {
 				_P("404 leave %.16llx ERROR: not a member of that network",(unsigned long long)nwid);

+ 1 - 1
node/Packet.cpp

@@ -64,7 +64,7 @@ const char *Packet::errorString(ErrorCode e)
 		case ERROR_IDENTITY_COLLISION: return "IDENTITY_COLLISION";
 		case ERROR_UNSUPPORTED_OPERATION: return "UNSUPPORTED_OPERATION";
 		case ERROR_NEED_MEMBERSHIP_CERTIFICATE: return "NEED_MEMBERSHIP_CERTIFICATE";
-		case ERROR_NETWORK_ACCESS_DENIED: return "NETWORK_ACCESS_DENIED";
+		case ERROR_NETWORK_ACCESS_DENIED_: return "NETWORK_ACCESS_DENIED";
 	}
 	return "(unknown)";
 }

+ 1 - 1
node/Packet.hpp

@@ -672,7 +672,7 @@ public:
 		ERROR_NEED_MEMBERSHIP_CERTIFICATE = 6,
 
 		/* Tried to join network, but you're not a member */
-		ERROR_NETWORK_ACCESS_DENIED = 7
+		ERROR_NETWORK_ACCESS_DENIED_ = 7 /* extra _ to avoid Windows name conflict */
 	};
 
 	/**

+ 1 - 1
node/PacketDecoder.cpp

@@ -151,7 +151,7 @@ bool PacketDecoder::_doERROR(const RuntimeEnvironment *_r,const SharedPtr<Peer>
 				if (network)
 					network->pushMembershipCertificate(source(),true,Utils::now());
 			}	break;
-			case Packet::ERROR_NETWORK_ACCESS_DENIED: {
+			case Packet::ERROR_NETWORK_ACCESS_DENIED_: {
 				SharedPtr<Network> network(_r->nc->network(at<uint64_t>(ZT_PROTO_VERB_ERROR_IDX_PAYLOAD)));
 				if ((network)&&(network->controller() == source()))
 					network->forceStatusTo(Network::NETWORK_ACCESS_DENIED);

+ 5 - 0
node/Poly1305.cpp

@@ -4,8 +4,13 @@ D. J. Bernstein
 Public domain.
 */
 
+#include "Constants.hpp"
 #include "Poly1305.hpp"
 
+#ifdef __WINDOWS__
+#pragma warning(disable: 4146)
+#endif
+
 namespace ZeroTier {
 
 //////////////////////////////////////////////////////////////////////////////

+ 4 - 0
node/Utils.cpp

@@ -280,8 +280,12 @@ int64_t Utils::getFileSize(const char *path)
 	struct stat s;
 	if (stat(path,&s))
 		return -1;
+#ifdef __WINDOWS__
+	return s.st_size;
+#else
 	if (S_ISREG(s.st_mode))
 		return s.st_size;
+#endif
 	return -1;
 }
 

+ 1 - 0
windows/SelfTest/SelfTest.vcxproj

@@ -91,6 +91,7 @@
     <ClCompile Include="..\..\node\Topology.cpp" />
     <ClCompile Include="..\..\node\UdpSocket.cpp" />
     <ClCompile Include="..\..\node\Utils.cpp" />
+    <ClCompile Include="..\..\selftest.cpp" />
   </ItemGroup>
   <PropertyGroup Label="Globals">
     <ProjectGuid>{DCD73B97-0F44-4044-8BA4-95B59CCAB4BD}</ProjectGuid>

+ 3 - 0
windows/SelfTest/SelfTest.vcxproj.filters

@@ -223,5 +223,8 @@
     <ClCompile Include="..\..\node\Utils.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\selftest.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>