This commit is contained in:
Moritz Warning 2015-02-06 17:00:01 +00:00
commit 251edaa7b5
10 changed files with 52 additions and 91 deletions

View file

@ -33,6 +33,8 @@
#include "IpcListener.hpp" #include "IpcListener.hpp"
#include "NodeControlService.hpp" #include "NodeControlService.hpp"
#include "stddef.h"
#ifdef __WINDOWS__ #ifdef __WINDOWS__
#include <WinSock2.h> #include <WinSock2.h>
#include <Windows.h> #include <Windows.h>

View file

@ -573,8 +573,8 @@ static void printHelp(const char *cn,FILE *out)
fprintf(out,"Available switches:"ZT_EOL_S); fprintf(out,"Available switches:"ZT_EOL_S);
fprintf(out," -h - Display this help"ZT_EOL_S); fprintf(out," -h - Display this help"ZT_EOL_S);
fprintf(out," -v - Show version"ZT_EOL_S); fprintf(out," -v - Show version"ZT_EOL_S);
fprintf(out," -p<port> - Port for UDP (default: 9993)"ZT_EOL_S); fprintf(out," -p <port> - Port for UDP (default: 9993)"ZT_EOL_S);
fprintf(out," -t<port> - Port for TCP (default: disabled)"ZT_EOL_S); fprintf(out," -t <port> - Port for TCP (default: disabled)"ZT_EOL_S);
//fprintf(out," -T<path> - Override root topology, do not authenticate or update"ZT_EOL_S); //fprintf(out," -T<path> - Override root topology, do not authenticate or update"ZT_EOL_S);
#ifdef __UNIX_LIKE__ #ifdef __UNIX_LIKE__
fprintf(out," -d - Fork and run as daemon (Unix-ish OSes)"ZT_EOL_S); fprintf(out," -d - Fork and run as daemon (Unix-ish OSes)"ZT_EOL_S);

View file

@ -1,5 +1,5 @@
CC=cc CC?=cc
CXX=c++ CXX?=c++
INCLUDES= INCLUDES=
DEFS= DEFS=
@ -9,27 +9,6 @@ include objects.mk
OBJS+=osnet/BSDEthernetTapFactory.o osnet/BSDEthernetTap.o osnet/BSDRoutingTable.o OBJS+=osnet/BSDEthernetTapFactory.o osnet/BSDEthernetTap.o osnet/BSDRoutingTable.o
TESTNET_OBJS=testnet/SimNet.o testnet/SimNetSocketManager.o testnet/TestEthernetTap.o testnet/TestEthernetTapFactory.o testnet/TestRoutingTable.o TESTNET_OBJS=testnet/SimNet.o testnet/SimNetSocketManager.o testnet/TestEthernetTap.o testnet/TestEthernetTapFactory.o testnet/TestRoutingTable.o
# Enable SSE-optimized Salsa20 on x86 and x86_64 machines
MACHINE=$(shell uname -m)
ifeq ($(MACHINE),x86_64)
DEFS+=-DZT_SALSA20_SSE
endif
ifeq ($(MACHINE),amd64)
DEFS+=-DZT_SALSA20_SSE
endif
ifeq ($(MACHINE),i686)
DEFS+=-DZT_SALSA20_SSE
endif
ifeq ($(MACHINE),i586)
DEFS+=-DZT_SALSA20_SSE
endif
ifeq ($(MACHINE),i386)
DEFS+=-DZT_SALSA20_SSE
endif
ifeq ($(MACHINE),x86)
DEFS+=-DZT_SALSA20_SSE
endif
# "make official" is a shortcut for this # "make official" is a shortcut for this
ifeq ($(ZT_OFFICIAL_RELEASE),1) ifeq ($(ZT_OFFICIAL_RELEASE),1)
ZT_AUTO_UPDATE=1 ZT_AUTO_UPDATE=1
@ -42,19 +21,21 @@ endif
# "make debug" is a shortcut for this # "make debug" is a shortcut for this
ifeq ($(ZT_DEBUG),1) ifeq ($(ZT_DEBUG),1)
# DEFS+=-DZT_TRACE -DZT_LOG_STDOUT # DEFS+=-DZT_TRACE -DZT_LOG_STDOUT
CFLAGS=-Wall -g -pthread $(INCLUDES) $(DEFS) CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS)
LDFLAGS= LDFLAGS+=
STRIP=echo STRIP=echo
# The following line enables optimization for the crypto code, since # The following line enables optimization for the crypto code, since
# C25519 in particular is almost UNUSABLE in heavy testing without it. # C25519 in particular is almost UNUSABLE in heavy testing without it.
ext/lz4/lz4.o node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS = -Wall -O2 -g -pthread $(INCLUDES) $(DEFS) ext/lz4/lz4.o node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS?=-O2 CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS)
else else
CFLAGS=-Wall -O3 -fPIE -fvisibility=hidden -fstack-protector -pthread $(INCLUDES) -DNDEBUG $(DEFS) CFLAGS?=-O3 -fstack-protector
LDFLAGS=-pie -Wl,-z,relro,-z,now CFLAGS+=-Wall -fPIE -fvisibility=hidden -pthread $(INCLUDES) -DNDEBUG $(DEFS)
LDFLAGS+=-pie -Wl,-z,relro,-z,now
STRIP=strip --strip-all STRIP=strip --strip-all
endif endif
CXXFLAGS=$(CFLAGS) -fno-rtti CXXFLAGS?=-fno-rtti
CXXFLAGS=$(CFLAGS)
all: one all: one

View file

@ -1,6 +1,6 @@
# Pick clang or gcc, with preference for clang # Pick clang or gcc, with preference for clang
CC=$(shell which clang gcc cc 2>/dev/null | head -n 1) CC?=$(shell which clang gcc cc 2>/dev/null | head -n 1)
CXX=$(shell which clang++ g++ c++ 2>/dev/null | head -n 1) CXX?=$(shell which clang++ g++ c++ 2>/dev/null | head -n 1)
INCLUDES= INCLUDES=
DEFS= DEFS=
@ -10,27 +10,6 @@ include objects.mk
OBJS+=osnet/LinuxRoutingTable.o osnet/LinuxEthernetTap.o osnet/LinuxEthernetTapFactory.o OBJS+=osnet/LinuxRoutingTable.o osnet/LinuxEthernetTap.o osnet/LinuxEthernetTapFactory.o
TESTNET_OBJS=testnet/SimNet.o testnet/SimNetSocketManager.o testnet/TestEthernetTap.o testnet/TestEthernetTapFactory.o testnet/TestRoutingTable.o TESTNET_OBJS=testnet/SimNet.o testnet/SimNetSocketManager.o testnet/TestEthernetTap.o testnet/TestEthernetTapFactory.o testnet/TestRoutingTable.o
# Enable SSE-optimized Salsa20 on x86 and x86_64 machines
MACHINE=$(shell uname -m)
ifeq ($(MACHINE),x86_64)
DEFS+=-DZT_SALSA20_SSE
endif
ifeq ($(MACHINE),amd64)
DEFS+=-DZT_SALSA20_SSE
endif
ifeq ($(MACHINE),i686)
DEFS+=-DZT_SALSA20_SSE
endif
ifeq ($(MACHINE),i586)
DEFS+=-DZT_SALSA20_SSE
endif
ifeq ($(MACHINE),i386)
DEFS+=-DZT_SALSA20_SSE
endif
ifeq ($(MACHINE),x86)
DEFS+=-DZT_SALSA20_SSE
endif
# "make official" is a shortcut for this # "make official" is a shortcut for this
ifeq ($(ZT_OFFICIAL_RELEASE),1) ifeq ($(ZT_OFFICIAL_RELEASE),1)
ZT_AUTO_UPDATE=1 ZT_AUTO_UPDATE=1
@ -43,15 +22,16 @@ endif
# "make debug" is a shortcut for this # "make debug" is a shortcut for this
ifeq ($(ZT_DEBUG),1) ifeq ($(ZT_DEBUG),1)
# DEFS+=-DZT_TRACE -DZT_LOG_STDOUT # DEFS+=-DZT_TRACE -DZT_LOG_STDOUT
CFLAGS=-Wall -g -pthread $(INCLUDES) $(DEFS) CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS)
LDFLAGS= LDFLAGS+=
STRIP=echo STRIP=echo
# The following line enables optimization for the crypto code, since # The following line enables optimization for the crypto code, since
# C25519 in particular is almost UNUSABLE in heavy testing without it. # C25519 in particular is almost UNUSABLE in heavy testing without it.
ext/lz4/lz4.o node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS = -Wall -O2 -g -pthread $(INCLUDES) $(DEFS) ext/lz4/lz4.o node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS?=-O2 CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS)
else else
CFLAGS=-Wall -O3 -fPIE -fvisibility=hidden -fstack-protector -pthread $(INCLUDES) -DNDEBUG $(DEFS) CFLAGS?=-O3 -fstack-protector
LDFLAGS=-pie -Wl,-z,relro,-z,now CFLAGS+=-Wall -fPIE -fvisibility=hidden -pthread $(INCLUDES) -DNDEBUG $(DEFS)
LDFLAGS+=-pie -Wl,-z,relro,-z,now
STRIP=strip --strip-all STRIP=strip --strip-all
endif endif
@ -60,7 +40,8 @@ endif
#LDFLAGS= #LDFLAGS=
#STRIP=echo #STRIP=echo
CXXFLAGS=$(CFLAGS) -fno-rtti CXXFLAGS?=-fno-rtti
CXXFLAGS+=$(CFLAGS)
all: one all: one

View file

@ -1,5 +1,5 @@
CC=clang CC?=clang
CXX=clang++ CXX?=clang++
INCLUDES= INCLUDES=
DEFS= DEFS=
@ -25,22 +25,21 @@ ifeq ($(ZT_AUTO_UPDATE),1)
DEFS+=-DZT_AUTO_UPDATE DEFS+=-DZT_AUTO_UPDATE
endif endif
# Enable SSE-optimized Salsa20 -- all Intel macs support SSE2
DEFS+=-DZT_SALSA20_SSE
ifeq ($(ZT_DEBUG),1) ifeq ($(ZT_DEBUG),1)
# DEFS+=-DZT_TRACE -DZT_LOG_STDOUT # DEFS+=-DZT_TRACE -DZT_LOG_STDOUT
CFLAGS=-Wall -g -pthread $(INCLUDES) $(DEFS) CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS)
STRIP=echo STRIP=echo
# The following line enables optimization for the crypto code, since # The following line enables optimization for the crypto code, since
# C25519 in particular is almost UNUSABLE in heavy testing without it. # C25519 in particular is almost UNUSABLE in heavy testing without it.
ext/lz4/lz4.o node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS = -Wall -O2 -g -pthread $(INCLUDES) $(DEFS) ext/lz4/lz4.o node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS?=-O2 CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS)
else else
CFLAGS=-arch i386 -arch x86_64 -Wall -O3 -flto -fPIE -fvectorize -fstack-protector -pthread -mmacosx-version-min=10.6 -DNDEBUG -Wno-unused-private-field $(INCLUDES) $(DEFS) CFLAGS?=-O3 -fstack-protector
CFLAGS+=-arch i386 -arch x86_64 -Wall -flto -fPIE -fvectorize -pthread -mmacosx-version-min=10.6 -DNDEBUG -Wno-unused-private-field $(INCLUDES) $(DEFS)
STRIP=strip STRIP=strip
endif endif
CXXFLAGS=$(CFLAGS) -fno-rtti CXXFLAGS?=-fno-rtti
CXXFLAGS=$(CFLAGS)
all: one all: one

View file

@ -31,12 +31,14 @@
#include <string> #include <string>
#include <algorithm> #include <algorithm>
#include "stddef.h"
namespace ZeroTier { namespace ZeroTier {
/** /**
* Static array -- a simple thing that's belonged in STL since the time of the dinosaurs * Static array -- a simple thing that's belonged in STL since the time of the dinosaurs
*/ */
template<typename T,std::size_t S> template<typename T,size_t S>
class Array class Array
{ {
public: public:
@ -44,19 +46,19 @@ public:
Array(const Array &a) Array(const Array &a)
{ {
for(std::size_t i=0;i<S;++i) for(size_t i=0;i<S;++i)
data[i] = a.data[i]; data[i] = a.data[i];
} }
Array(const T *ptr) Array(const T *ptr)
{ {
for(std::size_t i=0;i<S;++i) for(size_t i=0;i<S;++i)
data[i] = ptr[i]; data[i] = ptr[i];
} }
inline Array &operator=(const Array &a) inline Array &operator=(const Array &a)
{ {
for(std::size_t i=0;i<S;++i) for(size_t i=0;i<S;++i)
data[i] = a.data[i]; data[i] = a.data[i];
return *this; return *this;
} }
@ -68,8 +70,8 @@ public:
typedef const T& const_reference; typedef const T& const_reference;
typedef T* iterator; typedef T* iterator;
typedef const T* const_iterator; typedef const T* const_iterator;
typedef std::size_t size_type; typedef size_t size_type;
typedef std::ptrdiff_t difference_type; typedef ptrdiff_t difference_type;
typedef std::reverse_iterator<iterator> reverse_iterator; typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator; typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
@ -83,11 +85,11 @@ public:
inline const_reverse_iterator rbegin() const throw() { return const_reverse_iterator(begin()); } inline const_reverse_iterator rbegin() const throw() { return const_reverse_iterator(begin()); }
inline const_reverse_iterator rend() const throw() { return const_reverse_iterator(end()); } inline const_reverse_iterator rend() const throw() { return const_reverse_iterator(end()); }
inline std::size_t size() const throw() { return S; } inline size_t size() const throw() { return S; }
inline std::size_t max_size() const throw() { return S; } inline size_t max_size() const throw() { return S; }
inline reference operator[](const std::size_t n) throw() { return data[n]; } inline reference operator[](const size_t n) throw() { return data[n]; }
inline const_reference operator[](const std::size_t n) const throw() { return data[n]; } inline const_reference operator[](const size_t n) const throw() { return data[n]; }
inline reference front() throw() { return data[0]; } inline reference front() throw() { return data[0]; }
inline const_reference front() const throw() { return data[0]; } inline const_reference front() const throw() { return data[0]; }

View file

@ -137,7 +137,7 @@ std::string InetAddress::toString() const
void InetAddress::fromString(const std::string &ipSlashPort) void InetAddress::fromString(const std::string &ipSlashPort)
{ {
std::size_t slashAt = ipSlashPort.find('/'); size_t slashAt = ipSlashPort.find('/');
if ((slashAt == std::string::npos)||(slashAt >= ipSlashPort.length())) if ((slashAt == std::string::npos)||(slashAt >= ipSlashPort.length()))
set(ipSlashPort,0); set(ipSlashPort,0);
else { else {

View file

@ -400,13 +400,4 @@ private:
} // namespace ZeroTier } // namespace ZeroTier
// Add a swap() for shared ptr's to peers to speed up peer sorts
namespace std {
template<>
inline void swap(ZeroTier::SharedPtr<ZeroTier::Peer> &a,ZeroTier::SharedPtr<ZeroTier::Peer> &b)
{
a.swap(b);
}
}
#endif #endif

View file

@ -11,6 +11,11 @@
#include "Constants.hpp" #include "Constants.hpp"
/* Enable SSE-optimized Salsa20 on SSE2 machines */
#ifdef __SSE2__
#define ZT_SALSA20_SSE
#endif
#ifdef ZT_SALSA20_SSE #ifdef ZT_SALSA20_SSE
#include <emmintrin.h> #include <emmintrin.h>
#endif // ZT_SALSA20_SSE #endif // ZT_SALSA20_SSE

View file

@ -270,7 +270,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)\ext\bin\libcrypto\include</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(SolutionDir)\ext\bin\libcrypto\include</AdditionalIncludeDirectories>
<PreprocessorDefinitions>ZT_OFFICIAL_RELEASE;ZT_AUTO_UPDATE;ZT_SALSA20_SSE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>ZT_OFFICIAL_RELEASE;ZT_AUTO_UPDATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<EnableEnhancedInstructionSet>NoExtensions</EnableEnhancedInstructionSet> <EnableEnhancedInstructionSet>NoExtensions</EnableEnhancedInstructionSet>
<StringPooling>true</StringPooling> <StringPooling>true</StringPooling>
@ -294,7 +294,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)\ext\bin\libcrypto\include</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(SolutionDir)\ext\bin\libcrypto\include</AdditionalIncludeDirectories>
<PreprocessorDefinitions>ZT_OFFICIAL_RELEASE;ZT_AUTO_UPDATE;ZT_SALSA20_SSE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>ZT_OFFICIAL_RELEASE;ZT_AUTO_UPDATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet> <EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet>
<StringPooling>true</StringPooling> <StringPooling>true</StringPooling>