mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-02-21 10:01:46 +00:00
Windows compiles! (w/Visual Studio 2012) That's about all it does, but it's a start.
This commit is contained in:
parent
5076c75b07
commit
d6414c9ff7
1
.gitignore
vendored
1
.gitignore
vendored
@ -11,3 +11,4 @@ mac-tap/tuntap/tap.kext
|
||||
|
||||
/ZeroTierOne.v11.suo
|
||||
/ZeroTierOne.opensdf
|
||||
/Debug_32
|
||||
|
@ -46,10 +46,7 @@
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="ext\kissdb\kissdb.c" />
|
||||
<ClCompile Include="ext\lz4\bench.c" />
|
||||
<ClCompile Include="ext\lz4\fuzzer.c" />
|
||||
<ClCompile Include="ext\lz4\lz4.c" />
|
||||
<ClCompile Include="ext\lz4\lz4demo.c" />
|
||||
<ClCompile Include="ext\lz4\lz4hc.c" />
|
||||
<ClCompile Include="node\Defaults.cpp" />
|
||||
<ClCompile Include="node\Demarc.cpp" />
|
||||
@ -151,7 +148,6 @@
|
||||
<ClInclude Include="ext\bin\libcrypto\include\openssl\x509v3.h" />
|
||||
<ClInclude Include="ext\bin\libcrypto\include\openssl\x509_vfy.h" />
|
||||
<ClInclude Include="ext\kissdb\kissdb.h" />
|
||||
<ClInclude Include="ext\lz4\bench.h" />
|
||||
<ClInclude Include="ext\lz4\lz4.h" />
|
||||
<ClInclude Include="ext\lz4\lz4hc.h" />
|
||||
<ClInclude Include="node\Address.hpp" />
|
||||
|
@ -18,18 +18,9 @@
|
||||
<ClCompile Include="ext\kissdb\kissdb.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ext\lz4\bench.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ext\lz4\fuzzer.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ext\lz4\lz4.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ext\lz4\lz4demo.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ext\lz4\lz4hc.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
@ -332,9 +323,6 @@
|
||||
<ClInclude Include="ext\kissdb\kissdb.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ext\lz4\bench.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ext\lz4\lz4.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
@ -15,7 +15,12 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define fseeko _fseeki64
|
||||
#define ftello _ftelli64
|
||||
#endif
|
||||
|
||||
#define KISSDB_HEADER_SIZE ((sizeof(uint64_t) * 3) + 4)
|
||||
|
||||
@ -322,6 +327,8 @@ int KISSDB_Iterator_next(KISSDB_Iterator *dbi,void *kbuf,void *vbuf)
|
||||
|
||||
#ifdef KISSDB_TEST
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
uint64_t i,j;
|
||||
|
@ -205,7 +205,7 @@ public:
|
||||
/**
|
||||
* @return True if this address is not zero
|
||||
*/
|
||||
inline operator bool() const throw() { return (_a); }
|
||||
inline operator bool() const throw() { return (_a != 0); }
|
||||
|
||||
/**
|
||||
* @return Sum of all bytes in address
|
||||
|
@ -94,7 +94,14 @@ public:
|
||||
inline reference back() throw() { return data[S-1]; }
|
||||
inline const_reference back() const throw() { return data[S-1]; }
|
||||
|
||||
inline bool operator==(const Array &k) const throw() { return std::equal(begin(),end(),k.begin()); }
|
||||
inline bool operator==(const Array &k) const throw()
|
||||
{
|
||||
for(unsigned long i=0;i<S;++i) {
|
||||
if (data[i] != k.data[i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
inline bool operator<(const Array &k) const throw() { return std::lexicographical_compare(begin(),end(),k.begin(),k.end()); }
|
||||
inline bool operator!=(const Array &k) const throw() { return !(*this == k); }
|
||||
inline bool operator>(const Array &k) const throw() { return (k < *this); }
|
||||
|
@ -110,7 +110,7 @@ public:
|
||||
throw()
|
||||
{
|
||||
n %= B;
|
||||
return (_field[n / 8] & (1 << (n % 8)));
|
||||
return ((_field[n / 8] & (1 << (n % 8))) != 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,12 +28,15 @@
|
||||
#ifndef _ZT_BUFFER_HPP
|
||||
#define _ZT_BUFFER_HPP
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "Constants.hpp"
|
||||
#include "Utils.hpp"
|
||||
|
||||
#ifdef __GNUC__
|
||||
|
@ -68,6 +68,9 @@
|
||||
#ifndef __WINDOWS__
|
||||
#define __WINDOWS__
|
||||
#endif
|
||||
#define NOMINMAX
|
||||
#pragma warning(disable : 4290)
|
||||
#pragma warning(disable : 4996)
|
||||
#undef __UNIX_LIKE__
|
||||
#define ZT_PATH_SEPARATOR '\\'
|
||||
#define ZT_PATH_SEPARATOR_S "\\"
|
||||
@ -96,11 +99,23 @@
|
||||
error_no_byte_order_defined;
|
||||
#endif
|
||||
#ifndef ZT_OSNAME
|
||||
error_no_ZT_OSNAME_defined;
|
||||
#ifdef __WINDOWS__
|
||||
#define ZT_OSNAME "windows"
|
||||
#else
|
||||
no ZT_OSNAME defined;
|
||||
#endif
|
||||
#endif
|
||||
#ifndef ZT_ARCH
|
||||
#ifdef __WINDOWS__
|
||||
#ifdef _WIN64
|
||||
#define ZT_ARCH "x64"
|
||||
#else
|
||||
#define ZT_ARCH "x86"
|
||||
#endif
|
||||
#else
|
||||
error_no_ZT_ARCH_defined;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Length of a ZeroTier address in bytes
|
||||
|
@ -26,6 +26,14 @@
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "Constants.hpp"
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
#include <WinSock2.h>
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
#include "Demarc.hpp"
|
||||
#include "RuntimeEnvironment.hpp"
|
||||
#include "Logger.hpp"
|
||||
@ -82,7 +90,7 @@ bool Demarc::has(Port p) const
|
||||
throw()
|
||||
{
|
||||
Mutex::Lock _l(_ports_m);
|
||||
return (_ports.count(p));
|
||||
return (_ports.count(p) != 0);
|
||||
}
|
||||
|
||||
bool Demarc::bindLocalUdp(unsigned int localPort)
|
||||
|
@ -29,6 +29,13 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "Constants.hpp"
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
#include <WinSock2.h>
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/obj_mac.h>
|
||||
#include <openssl/rand.h>
|
||||
@ -129,32 +136,9 @@ const EllipticCurveKeyPair &EllipticCurveKeyPair::operator=(const EllipticCurveK
|
||||
|
||||
bool EllipticCurveKeyPair::generate()
|
||||
{
|
||||
unsigned char tmp[16384];
|
||||
EC_KEY *key;
|
||||
int len;
|
||||
|
||||
// Make sure OpenSSL libcrypto has sufficient randomness (on most
|
||||
// platforms it auto-seeds, so this is a sanity check).
|
||||
if (!RAND_status()) {
|
||||
#if defined(__APPLE__) || defined(__linux__) || defined(linux) || defined(__LINUX__) || defined(__linux)
|
||||
FILE *rf = fopen("/dev/urandom","r");
|
||||
if (rf) {
|
||||
fread(tmp,sizeof(tmp),1,rf);
|
||||
fclose(rf);
|
||||
} else {
|
||||
fprintf(stderr,"FATAL: could not open /dev/urandom\n");
|
||||
exit(-1);
|
||||
}
|
||||
RAND_seed(tmp,sizeof(tmp));
|
||||
#else
|
||||
#ifdef _WIN32
|
||||
error need win32;
|
||||
#else
|
||||
error;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
key = EC_KEY_new();
|
||||
if (!key) return false;
|
||||
|
||||
|
@ -173,7 +173,7 @@ public:
|
||||
/**
|
||||
* @return True if this identity has its private portion
|
||||
*/
|
||||
inline bool hasPrivate() const throw() { return (_keyPair); }
|
||||
inline bool hasPrivate() const throw() { return (_keyPair != (EllipticCurveKeyPair *)0); }
|
||||
|
||||
/**
|
||||
* Shortcut method to perform key agreement with another identity
|
||||
@ -356,7 +356,7 @@ public:
|
||||
/**
|
||||
* @return True if this identity contains something
|
||||
*/
|
||||
inline operator bool() const throw() { return (_publicKey.size()); }
|
||||
inline operator bool() const throw() { return (_publicKey.size() != 0); }
|
||||
|
||||
inline bool operator==(const Identity &id) const
|
||||
throw()
|
||||
|
@ -28,10 +28,9 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <string>
|
||||
|
||||
#include "Constants.hpp"
|
||||
#include "InetAddress.hpp"
|
||||
|
||||
namespace ZeroTier {
|
||||
@ -62,13 +61,21 @@ std::string InetAddress::toString() const
|
||||
|
||||
switch(_sa.saddr.sa_family) {
|
||||
case AF_INET:
|
||||
#ifdef __WINDOWS__
|
||||
if (inet_ntop(AF_INET,(PVOID)&(_sa.sin.sin_addr.s_addr),buf,sizeof(buf))) {
|
||||
#else
|
||||
if (inet_ntop(AF_INET,(const void *)&(_sa.sin.sin_addr.s_addr),buf,sizeof(buf))) {
|
||||
#endif
|
||||
sprintf(buf2,"%s/%u",buf,(unsigned int)ntohs(_sa.sin.sin_port));
|
||||
return std::string(buf2);
|
||||
}
|
||||
break;
|
||||
case AF_INET6:
|
||||
#ifdef __WINDOWS__
|
||||
if (inet_ntop(AF_INET6,(PVOID)&(_sa.sin6.sin6_addr.s6_addr),buf,sizeof(buf))) {
|
||||
#else
|
||||
if (inet_ntop(AF_INET6,(const void *)&(_sa.sin6.sin6_addr.s6_addr),buf,sizeof(buf))) {
|
||||
#endif
|
||||
sprintf(buf2,"%s/%u",buf,(unsigned int)ntohs(_sa.sin6.sin6_port));
|
||||
return std::string(buf2);
|
||||
}
|
||||
@ -97,12 +104,22 @@ std::string InetAddress::toIpString() const
|
||||
|
||||
switch(_sa.saddr.sa_family) {
|
||||
case AF_INET:
|
||||
#ifdef __WINDOWS__
|
||||
if (inet_ntop(AF_INET,(PVOID)&(_sa.sin.sin_addr.s_addr),buf,sizeof(buf)))
|
||||
return std::string(buf);
|
||||
#else
|
||||
if (inet_ntop(AF_INET,(const void *)&(_sa.sin.sin_addr.s_addr),buf,sizeof(buf)))
|
||||
return std::string(buf);
|
||||
#endif
|
||||
break;
|
||||
case AF_INET6:
|
||||
#ifdef __WINDOWS__
|
||||
if (inet_ntop(AF_INET6,(PVOID)&(_sa.sin6.sin6_addr.s6_addr),buf,sizeof(buf)))
|
||||
return std::string(buf);
|
||||
#else
|
||||
if (inet_ntop(AF_INET6,(const void *)&(_sa.sin6.sin6_addr.s6_addr),buf,sizeof(buf)))
|
||||
return std::string(buf);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -30,9 +30,21 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Constants.hpp"
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
#include <WinSock2.h>
|
||||
#include <WS2tcpip.h>
|
||||
#include <Windows.h>
|
||||
#else
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
namespace ZeroTier {
|
||||
|
||||
/**
|
||||
|
@ -30,6 +30,8 @@
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "Constants.hpp"
|
||||
#include "Logger.hpp"
|
||||
|
||||
namespace ZeroTier {
|
||||
@ -64,7 +66,12 @@ void Logger::log(const char *fmt,...)
|
||||
|
||||
if (_log) {
|
||||
time_t now = time(0);
|
||||
#ifdef __WINDOWS__
|
||||
ctime_s(tmp,sizeof(tmp),&now);
|
||||
char *nowstr = tmp;
|
||||
#else
|
||||
char *nowstr = ctime_r(&now,tmp);
|
||||
#endif
|
||||
for(char *c=nowstr;*c;++c) {
|
||||
if (*c == '\n')
|
||||
*c = '\0';
|
||||
|
@ -86,9 +86,15 @@ bool Network::Certificate::qualifyMembership(const Network::Certificate &mc) con
|
||||
if (fabs(my - their) > delta)
|
||||
return false;
|
||||
} else {
|
||||
#ifdef __WINDOWS__
|
||||
int64_t my = _strtoi64(myField->second.c_str(),(char **)0,10);
|
||||
int64_t their = _strtoi64(theirField->second.c_str(),(char **)0,10);
|
||||
int64_t delta = _strtoi64(deltaField->second.c_str(),(char **)0,10);
|
||||
#else
|
||||
int64_t my = strtoll(myField->second.c_str(),(char **)0,10);
|
||||
int64_t their = strtoll(theirField->second.c_str(),(char **)0,10);
|
||||
int64_t delta = strtoll(deltaField->second.c_str(),(char **)0,10);
|
||||
#endif
|
||||
if (my > their) {
|
||||
if ((my - their) > delta)
|
||||
return false;
|
||||
|
@ -115,7 +115,11 @@ public:
|
||||
inline uint64_t networkId() const
|
||||
throw(std::invalid_argument)
|
||||
{
|
||||
#ifdef __WINDOWS__
|
||||
return _strtoui64(get("nwid").c_str(),(char **)0,16);
|
||||
#else
|
||||
return strtoull(get("nwid").c_str(),(char **)0,16);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void setPeerAddress(Address &a)
|
||||
@ -222,7 +226,11 @@ public:
|
||||
inline uint64_t networkId() const
|
||||
throw(std::invalid_argument)
|
||||
{
|
||||
#ifdef __WINDOWS__
|
||||
return _strtoui64(get("nwid").c_str(),(char **)0,16);
|
||||
#else
|
||||
return strtoull(get("nwid").c_str(),(char **)0,16);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline Address peerAddress() const
|
||||
|
@ -29,6 +29,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <utility>
|
||||
@ -37,6 +39,13 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "Constants.hpp"
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
#include <WinSock2.h>
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
#include "Condition.hpp"
|
||||
#include "Node.hpp"
|
||||
#include "Topology.hpp"
|
||||
@ -46,7 +55,6 @@
|
||||
#include "Utils.hpp"
|
||||
#include "EthernetTap.hpp"
|
||||
#include "Logger.hpp"
|
||||
#include "Constants.hpp"
|
||||
#include "InetAddress.hpp"
|
||||
#include "Salsa20.hpp"
|
||||
#include "HMAC.hpp"
|
||||
@ -68,7 +76,6 @@
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
#include "../version.h"
|
||||
|
@ -37,6 +37,13 @@
|
||||
|
||||
#include <openssl/sha.h>
|
||||
|
||||
#include "Constants.hpp"
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
#include <WinSock2.h>
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
#include "NodeConfig.hpp"
|
||||
#include "RuntimeEnvironment.hpp"
|
||||
#include "Defaults.hpp"
|
||||
|
@ -56,7 +56,7 @@ const char *Packet::errorString(ErrorCode e)
|
||||
case ERROR_NONE: return "NONE";
|
||||
case ERROR_INVALID_REQUEST: return "INVALID_REQUEST";
|
||||
case ERROR_BAD_PROTOCOL_VERSION: return "BAD_PROTOCOL_VERSION";
|
||||
case ERROR_NOT_FOUND: return "NOT_FOUND";
|
||||
case ERROR_OBJ_NOT_FOUND: return "OBJECT_NOT_FOUND";
|
||||
case ERROR_IDENTITY_COLLISION: return "IDENTITY_COLLISION";
|
||||
case ERROR_IDENTITY_INVALID: return "IDENTITY_INVALID";
|
||||
case ERROR_UNSUPPORTED_OPERATION: return "UNSUPPORTED_OPERATION";
|
||||
|
@ -551,7 +551,7 @@ public:
|
||||
ERROR_BAD_PROTOCOL_VERSION = 2,
|
||||
|
||||
/* Unknown object queried (e.g. with WHOIS) */
|
||||
ERROR_NOT_FOUND = 3,
|
||||
ERROR_OBJ_NOT_FOUND = 3,
|
||||
|
||||
/* HELLO pushed an identity whose address is already claimed */
|
||||
ERROR_IDENTITY_COLLISION = 4,
|
||||
@ -693,12 +693,12 @@ public:
|
||||
/**
|
||||
* @return True if packet is encrypted
|
||||
*/
|
||||
inline bool encrypted() const { return (((unsigned char)(*this)[ZT_PACKET_IDX_FLAGS] & ZT_PROTO_FLAG_ENCRYPTED)); }
|
||||
inline bool encrypted() const { return (((unsigned char)(*this)[ZT_PACKET_IDX_FLAGS] & ZT_PROTO_FLAG_ENCRYPTED) != 0); }
|
||||
|
||||
/**
|
||||
* @return True if packet is fragmented (expect fragments)
|
||||
*/
|
||||
inline bool fragmented() const { return (((unsigned char)(*this)[ZT_PACKET_IDX_FLAGS] & ZT_PROTO_FLAG_FRAGMENTED)); }
|
||||
inline bool fragmented() const { return (((unsigned char)(*this)[ZT_PACKET_IDX_FLAGS] & ZT_PROTO_FLAG_FRAGMENTED) != 0); }
|
||||
|
||||
/**
|
||||
* Set this packet's fragmented flag
|
||||
@ -715,7 +715,7 @@ public:
|
||||
/**
|
||||
* @return True if compressed (result only valid if unencrypted)
|
||||
*/
|
||||
inline bool compressed() const { return (((unsigned char)(*this)[ZT_PACKET_IDX_VERB] & ZT_PROTO_VERB_FLAG_COMPRESSED)); }
|
||||
inline bool compressed() const { return (((unsigned char)(*this)[ZT_PACKET_IDX_VERB] & ZT_PROTO_VERB_FLAG_COMPRESSED) != 0); }
|
||||
|
||||
/**
|
||||
* @return ZeroTier forwarding hops (0 to 7)
|
||||
|
@ -369,7 +369,7 @@ bool PacketDecoder::_doWHOIS(const RuntimeEnvironment *_r,const SharedPtr<Peer>
|
||||
Packet outp(source(),_r->identity.address(),Packet::VERB_ERROR);
|
||||
outp.append((unsigned char)Packet::VERB_WHOIS);
|
||||
outp.append(packetId());
|
||||
outp.append((unsigned char)Packet::ERROR_NOT_FOUND);
|
||||
outp.append((unsigned char)Packet::ERROR_OBJ_NOT_FOUND);
|
||||
outp.append(payload(),ZT_ADDRESS_LENGTH);
|
||||
outp.encrypt(peer->cryptKey());
|
||||
outp.hmacSet(peer->macKey());
|
||||
@ -612,11 +612,11 @@ bool PacketDecoder::_doNETWORK_MEMBERSHIP_CERTIFICATE(const RuntimeEnvironment *
|
||||
|
||||
bool PacketDecoder::_doNETWORK_CONFIG_REQUEST(const RuntimeEnvironment *_r,const SharedPtr<Peer> &peer)
|
||||
{
|
||||
char tmp[128];
|
||||
try {
|
||||
uint64_t nwid = at<uint64_t>(ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_NETWORK_ID);
|
||||
#ifndef __WINDOWS__
|
||||
if (_r->netconfService) {
|
||||
char tmp[128];
|
||||
unsigned int dictLen = at<uint16_t>(ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_DICT_LEN);
|
||||
|
||||
Dictionary request;
|
||||
|
@ -97,7 +97,7 @@ private:
|
||||
const RuntimeEnvironment *renv;
|
||||
Address source;
|
||||
InetAddress remoteAddress;
|
||||
int localPort;
|
||||
Demarc::Port localPort;
|
||||
unsigned int vMajor,vMinor,vRevision;
|
||||
uint64_t helloPacketId;
|
||||
uint64_t helloTimestamp;
|
||||
|
@ -28,10 +28,12 @@
|
||||
#ifndef _ZT_PEER_HPP
|
||||
#define _ZT_PEER_HPP
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include <stdexcept>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "Address.hpp"
|
||||
#include "Utils.hpp"
|
||||
#include "Identity.hpp"
|
||||
|
@ -29,8 +29,15 @@
|
||||
#define _ZT_RATELIMITER_HPP
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "Constants.hpp"
|
||||
#include "Utils.hpp"
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
#define fmin(a,b) (((a) <= (b)) ? (a) : (b))
|
||||
#define fmax(a,b) (((a) >= (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
namespace ZeroTier {
|
||||
|
||||
/**
|
||||
|
@ -99,7 +99,7 @@ public:
|
||||
with._ptr = tmp;
|
||||
}
|
||||
|
||||
inline operator bool() const throw() { return (_ptr); }
|
||||
inline operator bool() const throw() { return (_ptr != (T *)0); }
|
||||
inline T &operator*() const throw() { return *_ptr; }
|
||||
inline T *operator->() const throw() { return _ptr; }
|
||||
|
||||
|
@ -32,6 +32,13 @@
|
||||
#include <utility>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "Constants.hpp"
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
#include <WinSock2.h>
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
#include "Switch.hpp"
|
||||
#include "Node.hpp"
|
||||
#include "EthernetTap.hpp"
|
||||
|
@ -33,10 +33,12 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
#include "Constants.hpp"
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
#include <WinSock2.h>
|
||||
#include <WS2tcpip.h>
|
||||
#include <Windows.h>
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "Constants.hpp"
|
||||
|
||||
@ -37,19 +38,13 @@
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/uio.h>
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "Utils.hpp"
|
||||
#include "Mutex.hpp"
|
||||
#include "Salsa20.hpp"
|
||||
|
||||
namespace ZeroTier {
|
||||
|
||||
@ -390,14 +385,18 @@ unsigned int Utils::unhex(const char *hex,void *buf,unsigned int len)
|
||||
|
||||
void Utils::getSecureRandom(void *buf,unsigned int bytes)
|
||||
{
|
||||
#ifdef __UNIX_LIKE__
|
||||
static Mutex randomLock;
|
||||
static char randbuf[32768];
|
||||
static unsigned int randptr = sizeof(randbuf);
|
||||
#ifdef __WINDOWS__
|
||||
static Salsa20 s20;
|
||||
volatile bool s20Initialized = false;
|
||||
#endif
|
||||
|
||||
Mutex::Lock _l(randomLock);
|
||||
for(unsigned int i=0;i<bytes;++i) {
|
||||
if (randptr >= sizeof(randbuf)) {
|
||||
#ifdef __UNIX_LIKE__
|
||||
int fd = ::open("/dev/urandom",O_RDONLY);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr,"FATAL ERROR: unable to open /dev/urandom: %s"ZT_EOL_S,strerror(errno));
|
||||
@ -408,18 +407,32 @@ void Utils::getSecureRandom(void *buf,unsigned int bytes)
|
||||
exit(-1);
|
||||
}
|
||||
::close(fd);
|
||||
#else
|
||||
#ifdef __WINDOWS__
|
||||
if (!s20Initialized) {
|
||||
s20Initialized = true;
|
||||
char ktmp[32];
|
||||
char ivtmp[8];
|
||||
for(int i=0;i<32;++i) ktmp[i] = (char)rand();
|
||||
for(int i=0;i<8;++i) ivtmp[i] = (char)rand();
|
||||
double now = Utils::nowf();
|
||||
memcpy(ktmp,&now,sizeof(now));
|
||||
DWORD tmp = GetCurrentProcessId();
|
||||
memcpy(ktmp + sizeof(double),&tmp,sizeof(tmp));
|
||||
tmp = GetTickCount();
|
||||
memcpy(ktmp + sizeof(double) + sizeof(DWORD),&tmp,sizeof(tmp));
|
||||
s20.init(ktmp,256,ivtmp);
|
||||
for(int i=0;i<sizeof(randbuf);++i) randbuf[i] = (char)rand();
|
||||
}
|
||||
s20.encrypt(randbuf,randbuf,sizeof(randbuf));
|
||||
#else
|
||||
no getSecureRandom() implementation;
|
||||
#endif
|
||||
#endif
|
||||
randptr = 0;
|
||||
}
|
||||
((char *)buf)[i] = randbuf[randptr++];
|
||||
}
|
||||
|
||||
#else // !__UNIX_LIKE__
|
||||
#ifdef __WINDOWS__
|
||||
probably use windows capi...;
|
||||
#else // !__WINDOWS__
|
||||
no getSecureRandom() implementation!
|
||||
#endif // __WINDOWS__
|
||||
#endif // __UNIX_LIKE__
|
||||
}
|
||||
|
||||
void Utils::lockDownFile(const char *path,bool isDir)
|
||||
@ -428,7 +441,7 @@ void Utils::lockDownFile(const char *path,bool isDir)
|
||||
chmod(path,isDir ? 0700 : 0600);
|
||||
#else
|
||||
#ifdef _WIN32
|
||||
error need win32;
|
||||
// TODO: windows ACL hell...
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
@ -38,20 +38,20 @@
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "Constants.hpp"
|
||||
|
||||
#include "../ext/lz4/lz4.h"
|
||||
#include "../ext/lz4/lz4hc.h"
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
#include <Windows.h>
|
||||
#include <WinSock2.h>
|
||||
#include <Windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include "Constants.hpp"
|
||||
|
||||
/**
|
||||
* Maximum compression/decompression block size (do not change)
|
||||
*/
|
||||
@ -75,7 +75,7 @@ public:
|
||||
throw()
|
||||
{
|
||||
#ifdef __WINDOWS__
|
||||
DeleteFile(path);
|
||||
return (DeleteFile(path) != FALSE);
|
||||
#else
|
||||
return (unlink(path) == 0);
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user