mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2024-12-18 20:47:53 +00:00
Windows build fixes, self test cleanup.
This commit is contained in:
parent
a1c316b940
commit
72bd3064a2
@ -416,46 +416,6 @@ public:
|
||||
return (this->get(key,tmp,2) >= 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Erase a key from this dictionary
|
||||
*
|
||||
* Use this before add() to ensure that a key is replaced if it might
|
||||
* already be present.
|
||||
*
|
||||
* @param key Key to erase
|
||||
* @return True if key was found and erased
|
||||
*/
|
||||
inline bool erase(const char *key)
|
||||
{
|
||||
char d2[C];
|
||||
char *saveptr = (char *)0;
|
||||
unsigned int d2ptr = 0;
|
||||
bool found = false;
|
||||
for(char *f=Utils::stok(_d,"\r\n",&saveptr);(f);f=Utils::stok((char *)0,"\r\n",&saveptr)) {
|
||||
if (*f) {
|
||||
const char *p = f;
|
||||
const char *k = key;
|
||||
while ((*k)&&(*p)) {
|
||||
if (*k != *p)
|
||||
break;
|
||||
++k;
|
||||
++p;
|
||||
}
|
||||
if (*k) {
|
||||
p = f;
|
||||
while (*p)
|
||||
d2[d2ptr++] = *(p++);
|
||||
d2[d2ptr++] = '\n';
|
||||
} else {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
d2[d2ptr++] = (char)0;
|
||||
memcpy(_d,d2,d2ptr);
|
||||
return found;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Value of C template parameter
|
||||
*/
|
||||
|
99
selftest.cpp
99
selftest.cpp
@ -196,7 +196,7 @@ static int testCrypto()
|
||||
for(unsigned int i=0;i<1234567;++i)
|
||||
bb[i] = (unsigned char)i;
|
||||
Salsa20 s20(s20TV0Key,s20TV0Iv);
|
||||
double bytes = 0.0;
|
||||
long double bytes = 0.0;
|
||||
uint64_t start = OSUtils::now();
|
||||
for(unsigned int i=0;i<200;++i) {
|
||||
s20.crypt12(bb,bb,1234567);
|
||||
@ -204,7 +204,7 @@ static int testCrypto()
|
||||
}
|
||||
uint64_t end = OSUtils::now();
|
||||
SHA512::hash(buf1,bb,1234567);
|
||||
std::cout << ((bytes / 1048576.0) / ((double)(end - start) / 1000.0)) << " MiB/second (" << Utils::hex(buf1,16) << ')' << std::endl;
|
||||
std::cout << ((bytes / 1048576.0) / ((long double)(end - start) / 1024.0)) << " MiB/second (" << Utils::hex(buf1,16) << ')' << std::endl;
|
||||
::free((void *)bb);
|
||||
}
|
||||
|
||||
@ -221,7 +221,7 @@ static int testCrypto()
|
||||
bytes += 1234567.0;
|
||||
}
|
||||
uint64_t end = OSUtils::now();
|
||||
std::cout << ((bytes / 1048576.0) / ((double)(end - start) / 1000.0)) << " MiB/second" << std::endl;
|
||||
std::cout << ((bytes / 1048576.0) / ((double)(end - start) / 1024.0)) << " MiB/second" << std::endl;
|
||||
::free((void *)bb);
|
||||
}
|
||||
#endif
|
||||
@ -232,7 +232,7 @@ static int testCrypto()
|
||||
for(unsigned int i=0;i<1234567;++i)
|
||||
bb[i] = (unsigned char)i;
|
||||
Salsa20 s20(s20TV0Key,s20TV0Iv);
|
||||
double bytes = 0.0;
|
||||
long double bytes = 0.0;
|
||||
uint64_t start = OSUtils::now();
|
||||
for(unsigned int i=0;i<200;++i) {
|
||||
s20.crypt20(bb,bb,1234567);
|
||||
@ -240,7 +240,7 @@ static int testCrypto()
|
||||
}
|
||||
uint64_t end = OSUtils::now();
|
||||
SHA512::hash(buf1,bb,1234567);
|
||||
std::cout << ((bytes / 1048576.0) / ((double)(end - start) / 1000.0)) << " MiB/second (" << Utils::hex(buf1,16) << ')' << std::endl;
|
||||
std::cout << ((bytes / 1048576.0) / ((long double)(end - start) / 1024.0)) << " MiB/second (" << Utils::hex(buf1,16) << ')' << std::endl;
|
||||
::free((void *)bb);
|
||||
}
|
||||
|
||||
@ -270,14 +270,14 @@ static int testCrypto()
|
||||
unsigned char *bb = (unsigned char *)::malloc(1234567);
|
||||
for(unsigned int i=0;i<1234567;++i)
|
||||
bb[i] = (unsigned char)i;
|
||||
double bytes = 0.0;
|
||||
long double bytes = 0.0;
|
||||
uint64_t start = OSUtils::now();
|
||||
for(unsigned int i=0;i<200;++i) {
|
||||
Poly1305::compute(buf1,bb,1234567,poly1305TV0Key);
|
||||
bytes += 1234567.0;
|
||||
}
|
||||
uint64_t end = OSUtils::now();
|
||||
std::cout << ((bytes / 1048576.0) / ((double)(end - start) / 1000.0)) << " MiB/second" << std::endl;
|
||||
std::cout << ((bytes / 1048576.0) / ((long double)(end - start) / 1000.0)) << " MiB/second" << std::endl;
|
||||
::free((void *)bb);
|
||||
}
|
||||
|
||||
@ -632,6 +632,7 @@ static int testOther()
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if 0
|
||||
std::cout << "[other] Testing Hashtable... "; std::cout.flush();
|
||||
{
|
||||
Hashtable<uint64_t,std::string> ht;
|
||||
@ -795,40 +796,28 @@ static int testOther()
|
||||
}
|
||||
}
|
||||
std::cout << "PASS" << std::endl;
|
||||
|
||||
std::cout << "[other] Testing hex encode/decode... "; std::cout.flush();
|
||||
for(unsigned int k=0;k<1000;++k) {
|
||||
unsigned int flen = (rand() % 8194) + 1;
|
||||
for(unsigned int i=0;i<flen;++i)
|
||||
fuzzbuf[i] = (unsigned char)(rand() & 0xff);
|
||||
std::string dec = Utils::unhex(Utils::hex(fuzzbuf,flen).c_str());
|
||||
if ((dec.length() != flen)||(memcmp(dec.data(),fuzzbuf,dec.length()))) {
|
||||
std::cout << "FAILED!" << std::endl;
|
||||
std::cout << Utils::hex(fuzzbuf,flen) << std::endl;
|
||||
std::cout << Utils::hex(dec.data(),(unsigned int)dec.length()) << std::endl;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
std::cout << "PASS" << std::endl;
|
||||
#endif
|
||||
|
||||
std::cout << "[other] Testing/fuzzing Dictionary... "; std::cout.flush();
|
||||
for(int k=0;k<1000;++k) {
|
||||
Dictionary<8194> test;
|
||||
Dictionary<8194> *test = new Dictionary<8194>();
|
||||
char key[32][16];
|
||||
char value[32][128];
|
||||
memset(key, 0, sizeof(key));
|
||||
memset(value, 0, sizeof(value));
|
||||
for(unsigned int q=0;q<32;++q) {
|
||||
Utils::snprintf(key[q],16,"%.8lx",(unsigned long)rand());
|
||||
int r = rand() % 128;
|
||||
int r = (rand() % 127) + 1;
|
||||
for(int x=0;x<r;++x)
|
||||
value[q][x] = ("0123456789\0\t\r\n= ")[rand() % 16];
|
||||
value[q][r] = (char)0;
|
||||
test.add(key[q],value[q],r);
|
||||
test->add(key[q],value[q],r);
|
||||
}
|
||||
for(unsigned int q=0;q<1024;++q) {
|
||||
//int r = rand() % 128;
|
||||
int r = 31;
|
||||
char tmp[128];
|
||||
if (test.get(key[r],tmp,sizeof(tmp)) >= 0) {
|
||||
if (test->get(key[r],tmp,sizeof(tmp)) >= 0) {
|
||||
if (strcmp(value[r],tmp)) {
|
||||
std::cout << "FAILED (invalid value)!" << std::endl;
|
||||
return -1;
|
||||
@ -838,76 +827,30 @@ static int testOther()
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
for(unsigned int q=0;q<31;++q) {
|
||||
char tmp[128];
|
||||
test.erase(key[q]);
|
||||
if (test.get(key[q],tmp,sizeof(tmp)) >= 0) {
|
||||
std::cout << "FAILED (key should have been erased)!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
if (test.get(key[q+1],tmp,sizeof(tmp)) < 0) {
|
||||
std::cout << "FAILED (key should NOT have been erased)!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
delete test;
|
||||
}
|
||||
int foo = 0;
|
||||
volatile int *volatile bar = &foo; // force compiler not to optimize out test.get() below
|
||||
for(int k=0;k<200;++k) {
|
||||
int r = rand() % 8194;
|
||||
unsigned char tmp[8194];
|
||||
unsigned char *tmp = new unsigned char[8194];
|
||||
for(int q=0;q<r;++q)
|
||||
tmp[q] = (unsigned char)((rand() % 254) + 1); // don't put nulls since those will always just terminate scan
|
||||
tmp[r] = (r % 32) ? (char)(rand() & 0xff) : (char)0; // every 32nd iteration don't terminate the string maybe...
|
||||
Dictionary<8194> test((const char *)tmp);
|
||||
Dictionary<8194> *test = new Dictionary<8194>((const char *)tmp);
|
||||
for(unsigned int q=0;q<100;++q) {
|
||||
char tmp[128];
|
||||
for(unsigned int x=0;x<128;++x)
|
||||
tmp[x] = (char)(rand() & 0xff);
|
||||
tmp[127] = (char)0;
|
||||
char value[8194];
|
||||
*bar += test.get(tmp,value,sizeof(value));
|
||||
*bar += test->get(tmp,value,sizeof(value));
|
||||
}
|
||||
delete test;
|
||||
delete[] tmp;
|
||||
}
|
||||
std::cout << "PASS (junk value to prevent optimization-out of test: " << foo << ")" << std::endl;
|
||||
|
||||
/*
|
||||
std::cout << "[other] Testing controller/JSONDB..."; std::cout.flush();
|
||||
{
|
||||
std::map<std::string,nlohmann::json> db1data;
|
||||
JSONDB db1("jsondb-test");
|
||||
for(unsigned int i=0;i<256;++i) {
|
||||
std::string n;
|
||||
for(unsigned int j=0,k=rand() % 4;j<=k;++j) {
|
||||
if (j > 0) n.push_back('/');
|
||||
char foo[24];
|
||||
Utils::snprintf(foo,sizeof(foo),"%lx",rand());
|
||||
n.append(foo);
|
||||
}
|
||||
db1data[n] = {{"i",i}};
|
||||
db1.put(n,db1data[n]);
|
||||
}
|
||||
for(std::map<std::string,nlohmann::json>::iterator i(db1data.begin());i!=db1data.end();++i) {
|
||||
i->second["foo"] = "bar";
|
||||
db1.put(i->first,i->second);
|
||||
}
|
||||
JSONDB db2("jsondb-test");
|
||||
if (db1 != db2) {
|
||||
std::cout << " FAILED (db1!=db2 #1)" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
for(std::map<std::string,nlohmann::json>::iterator i(db1data.begin());i!=db1data.end();++i) {
|
||||
db1.erase(i->first);
|
||||
}
|
||||
db2.reload();
|
||||
if (db1 != db2) {
|
||||
std::cout << " FAILED (db1!=db2 #2)" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
std::cout << " PASS" << std::endl;
|
||||
*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -72,10 +72,7 @@
|
||||
<ClCompile Include="..\..\node\Tag.cpp" />
|
||||
<ClCompile Include="..\..\node\Topology.cpp" />
|
||||
<ClCompile Include="..\..\node\Utils.cpp" />
|
||||
<ClCompile Include="..\..\one.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Profile|x64'">false</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\one.cpp" />
|
||||
<ClCompile Include="..\..\osdep\Http.cpp" />
|
||||
<ClCompile Include="..\..\osdep\ManagedRoute.cpp" />
|
||||
<ClCompile Include="..\..\osdep\OSUtils.cpp" />
|
||||
@ -88,6 +85,8 @@
|
||||
<ClCompile Include="ZeroTierOneService.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\controller\EmbeddedNetworkController.hpp" />
|
||||
<ClInclude Include="..\..\controller\JSONDB.hpp" />
|
||||
<ClInclude Include="..\..\ext\http-parser\http_parser.h" />
|
||||
<ClInclude Include="..\..\ext\json\json.hpp" />
|
||||
<ClInclude Include="..\..\ext\libnatpmp\getgateway.h" />
|
||||
@ -109,6 +108,7 @@
|
||||
<ClInclude Include="..\..\ext\miniupnpc\upnpdev.h" />
|
||||
<ClInclude Include="..\..\ext\miniupnpc\upnperrors.h" />
|
||||
<ClInclude Include="..\..\ext\miniupnpc\upnpreplyparse.h" />
|
||||
<ClInclude Include="..\..\ext\x64-salsa2012-asm\salsa2012.h" />
|
||||
<ClInclude Include="..\..\include\ZeroTierOne.h" />
|
||||
<ClInclude Include="..\..\node\Address.hpp" />
|
||||
<ClInclude Include="..\..\node\Array.hpp" />
|
||||
|
@ -76,6 +76,12 @@
|
||||
<Filter Include="Header Files\ext\json">
|
||||
<UniqueIdentifier>{ff20532b-d9a2-440d-a7b4-b49e26a9b2f8}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Header Files\ext\x64-salsa2012-asm">
|
||||
<UniqueIdentifier>{05d9cde8-03ae-4e37-b9f7-7417de98cbe9}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Header Files\controller">
|
||||
<UniqueIdentifier>{7dc22e9c-f869-41e7-b43d-f07f5b94f6fb}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\service\OneService.cpp">
|
||||
@ -150,9 +156,6 @@
|
||||
<ClCompile Include="..\..\ext\http-parser\http_parser.c">
|
||||
<Filter>Source Files\ext\http-parser</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\one.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ServiceBase.cpp">
|
||||
<Filter>Source Files\windows\ZeroTierOne</Filter>
|
||||
</ClCompile>
|
||||
@ -246,6 +249,9 @@
|
||||
<ClCompile Include="..\..\node\CertificateOfOwnership.cpp">
|
||||
<Filter>Source Files\node</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\one.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="resource.h">
|
||||
@ -485,6 +491,15 @@
|
||||
<ClInclude Include="..\..\node\Credential.hpp">
|
||||
<Filter>Header Files\node</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\ext\x64-salsa2012-asm\salsa2012.h">
|
||||
<Filter>Header Files\ext\x64-salsa2012-asm</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\controller\EmbeddedNetworkController.hpp">
|
||||
<Filter>Header Files\controller</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\controller\JSONDB.hpp">
|
||||
<Filter>Header Files\controller</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="ZeroTierOne.rc">
|
||||
|
Loading…
Reference in New Issue
Block a user