summaryrefslogtreecommitdiff
path: root/windows
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@zerotier.com>2015-04-24 15:44:39 -0700
committerAdam Ierymenko <adam.ierymenko@zerotier.com>2015-04-24 15:44:39 -0700
commite2c65bf16a9b6f30daf023a9cfc270354d351387 (patch)
treec4e8a185e6b973d50272d4d3c8dc49482fbeef8e /windows
parent0e315513497832874192a3f44fcb4404c65df275 (diff)
downloadinfinitytier-e2c65bf16a9b6f30daf023a9cfc270354d351387.tar.gz
infinitytier-e2c65bf16a9b6f30daf023a9cfc270354d351387.zip
Bring Windows service code up to date and into sync.
Diffstat (limited to 'windows')
-rw-r--r--windows/ZeroTierOne/ZeroTierOne.vcxproj14
-rw-r--r--windows/ZeroTierOne/ZeroTierOne.vcxproj.filters33
-rw-r--r--windows/ZeroTierOne/ZeroTierOneService.cpp71
-rw-r--r--windows/ZeroTierOne/ZeroTierOneService.h8
4 files changed, 103 insertions, 23 deletions
diff --git a/windows/ZeroTierOne/ZeroTierOne.vcxproj b/windows/ZeroTierOne/ZeroTierOne.vcxproj
index 2dfc4433..796c30d9 100644
--- a/windows/ZeroTierOne/ZeroTierOne.vcxproj
+++ b/windows/ZeroTierOne/ZeroTierOne.vcxproj
@@ -43,12 +43,21 @@
<ClCompile Include="..\..\node\Switch.cpp" />
<ClCompile Include="..\..\node\Topology.cpp" />
<ClCompile Include="..\..\node\Utils.cpp" />
+ <ClCompile Include="..\..\one.cpp" />
<ClCompile Include="..\..\osdep\Http.cpp" />
<ClCompile Include="..\..\osdep\OSUtils.cpp" />
<ClCompile Include="..\..\osdep\WindowsEthernetTap.cpp" />
- <ClCompile Include="..\..\selftest.cpp" />
+ <ClCompile Include="..\..\selftest.cpp">
+ <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
+ <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
+ <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
+ <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
+ </ClCompile>
<ClCompile Include="..\..\service\ControlPlane.cpp" />
<ClCompile Include="..\..\service\OneService.cpp" />
+ <ClCompile Include="ServiceBase.cpp" />
+ <ClCompile Include="ServiceInstaller.cpp" />
+ <ClCompile Include="ZeroTierOneService.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\ext\http-parser\http_parser.h" />
@@ -102,6 +111,9 @@
<ClInclude Include="..\..\service\OneService.hpp" />
<ClInclude Include="..\..\version.h" />
<ClInclude Include="resource.h" />
+ <ClInclude Include="ServiceBase.h" />
+ <ClInclude Include="ServiceInstaller.h" />
+ <ClInclude Include="ZeroTierOneService.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="ZeroTierOne.rc" />
diff --git a/windows/ZeroTierOne/ZeroTierOne.vcxproj.filters b/windows/ZeroTierOne/ZeroTierOne.vcxproj.filters
index be099745..7ed585ad 100644
--- a/windows/ZeroTierOne/ZeroTierOne.vcxproj.filters
+++ b/windows/ZeroTierOne/ZeroTierOne.vcxproj.filters
@@ -58,6 +58,18 @@
<Filter Include="Source Files\ext\json-parser">
<UniqueIdentifier>{da28e961-1761-41d8-9a59-65b00dfb1302}</UniqueIdentifier>
</Filter>
+ <Filter Include="Source Files\windows">
+ <UniqueIdentifier>{43f75f84-c70d-4d44-a0ef-28a7a399abd4}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="Source Files\windows\ZeroTierOne">
+ <UniqueIdentifier>{0da07a2f-8922-4827-ac51-29ca3f30f881}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="Header Files\windows">
+ <UniqueIdentifier>{b74916eb-bb6c-4449-a2a2-fa0b17f60121}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="Header Files\windows\ZeroTierOne">
+ <UniqueIdentifier>{bf604491-14c4-4a74-81a6-6105d07c5c7c}</UniqueIdentifier>
+ </Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\service\ControlPlane.cpp">
@@ -150,6 +162,18 @@
<ClCompile Include="..\..\ext\json-parser\json.c">
<Filter>Source Files\ext\json-parser</Filter>
</ClCompile>
+ <ClCompile Include="..\..\one.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="ServiceBase.cpp">
+ <Filter>Source Files\windows\ZeroTierOne</Filter>
+ </ClCompile>
+ <ClCompile Include="ServiceInstaller.cpp">
+ <Filter>Source Files\windows\ZeroTierOne</Filter>
+ </ClCompile>
+ <ClCompile Include="ZeroTierOneService.cpp">
+ <Filter>Source Files\windows\ZeroTierOne</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="resource.h">
@@ -305,6 +329,15 @@
<ClInclude Include="..\..\ext\http-parser\http_parser.h">
<Filter>Header Files\ext\http-parser</Filter>
</ClInclude>
+ <ClInclude Include="ServiceBase.h">
+ <Filter>Header Files\windows\ZeroTierOne</Filter>
+ </ClInclude>
+ <ClInclude Include="ServiceInstaller.h">
+ <Filter>Header Files\windows\ZeroTierOne</Filter>
+ </ClInclude>
+ <ClInclude Include="ZeroTierOneService.h">
+ <Filter>Header Files\windows\ZeroTierOne</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="ZeroTierOne.rc">
diff --git a/windows/ZeroTierOne/ZeroTierOneService.cpp b/windows/ZeroTierOne/ZeroTierOneService.cpp
index abae3aff..e5426dc2 100644
--- a/windows/ZeroTierOne/ZeroTierOneService.cpp
+++ b/windows/ZeroTierOne/ZeroTierOneService.cpp
@@ -34,15 +34,13 @@
#include "ZeroTierOneService.h"
-#include "../../node/Defaults.hpp"
-#include "../../node/Utils.hpp"
-
-#include "../../control/NodeControlClient.hpp"
-#include "../../control/NodeControlService.hpp"
+#include "../../version.h"
+#include "../../include/ZeroTierOne.h"
-#include "../../osdep/WindowsEthernetTapFactory.hpp"
-#include "../../osdep/WindowsRoutingTable.hpp"
-#include "../../osdep/NativeSocketManager.hpp"
+#include "../../node/Constants.hpp"
+#include "../../node/Utils.hpp"
+#include "../../osdep/OSUtils.hpp"
+#include "../../service/OneService.hpp"
#pragma endregion // Includes
@@ -53,7 +51,7 @@ ZeroTier::Mutex SVCDBGfile_m;
ZeroTierOneService::ZeroTierOneService() :
CServiceBase(ZT_SERVICE_NAME,TRUE,TRUE,FALSE),
- _node((ZeroTier::Node *)0)
+ _service((ZeroTier::OneService *)0)
{
#ifdef ZT_DEBUG_SERVICE
SVCDBGfile_m.lock();
@@ -86,6 +84,41 @@ void ZeroTierOneService::threadMain()
restart_node:
try {
+ {
+ ZeroTier::Mutex::Lock _l(_lock);
+ delete _service;
+ _service = (ZeroTier::OneService *)0; // in case newInstance() fails
+ _service = ZeroTier::OneService::newInstance(
+ ZeroTier::OneService::platformDefaultHomePath().c_str(),
+ ZT1_DEFAULT_PORT);
+ }
+ switch(_service->run()) {
+ case ZeroTier::OneService::ONE_UNRECOVERABLE_ERROR: {
+ std::string err("ZeroTier One encountered an unrecoverable error: ");
+ err.append(_service->fatalErrorMessage());
+ err.append(" (restarting in 5 seconds)");
+ WriteEventLogEntry(const_cast <PSTR>(err.c_str()),EVENTLOG_ERROR_TYPE);
+ Sleep(5000);
+ } goto restart_node;
+
+ case ZeroTier::OneService::ONE_IDENTITY_COLLISION: {
+ std::string homeDir(ZeroTier::OneService::platformDefaultHomePath());
+ delete _service;
+ _service = (ZeroTier::OneService *)0;
+ std::string oldid;
+ ZeroTier::OSUtils::readFile((homeDir + ZT_PATH_SEPARATOR_S + "identity.secret").c_str(),oldid);
+ if (oldid.length()) {
+ ZeroTier::OSUtils::writeFile((homeDir + ZT_PATH_SEPARATOR_S + "identity.secret.saved_after_collision").c_str(),oldid);
+ ZeroTier::OSUtils::rm((homeDir + ZT_PATH_SEPARATOR_S + "identity.secret").c_str());
+ ZeroTier::OSUtils::rm((homeDir + ZT_PATH_SEPARATOR_S + "identity.public").c_str());
+ }
+ } goto restart_node;
+
+ default: // normal termination
+ break;
+ }
+
+#if 0
std::string authToken(ZeroTier::NodeControlClient::getAuthToken((ZeroTier::ZT_DEFAULTS.defaultHomePath + ZT_PATH_SEPARATOR_S + "authtoken.secret").c_str(),true));
ZeroTier::WindowsEthernetTapFactory tapFactory(ZeroTier::ZT_DEFAULTS.defaultHomePath.c_str());
@@ -154,6 +187,7 @@ restart_node:
break;
}
+#endif
} catch ( ... ) {
// sanity check, shouldn't happen since Node::run() should catch all its own errors
// could also happen if we're out of memory though!
@@ -164,17 +198,19 @@ restart_node:
{
ZeroTier::Mutex::Lock _l(_lock);
- delete _node;
- _node = (ZeroTier::Node *)0;
+ delete _service;
+ _service = (ZeroTier::OneService *)0;
}
}
bool ZeroTierOneService::doStartUpgrade(const std::string &msiPath)
{
- std::string msiLog(ZeroTier::ZT_DEFAULTS.defaultHomePath + "\\LastUpdateLog.txt");
- ZeroTier::Utils::rm(msiLog);
+ std::string homePath(ZeroTier::OneService::platformDefaultHomePath());
- std::string bat(ZeroTier::ZT_DEFAULTS.defaultHomePath + "\\InstallAndRestartService.bat");
+ std::string msiLog(homePath + "\\LastUpdateLog.txt");
+ ZeroTier::OSUtils::rm(msiLog);
+
+ std::string bat(homePath + "\\InstallAndRestartService.bat");
FILE *batf = fopen(bat.c_str(),"wb");
if (!batf)
return false;
@@ -210,10 +246,11 @@ void ZeroTierOneService::OnStop()
ZT_SVCDBG("ZeroTierOneService::OnStop()\r\n");
_lock.lock();
- ZeroTier::Node *n = _node;
+ ZeroTier::OneService *s = _service;
_lock.unlock();
- if (n) {
- n->terminate(ZeroTier::Node::NODE_NORMAL_TERMINATION,"Windows service stopped");
+
+ if (s) {
+ s->terminate();
ZeroTier::Thread::join(_thread);
}
}
diff --git a/windows/ZeroTierOne/ZeroTierOneService.h b/windows/ZeroTierOne/ZeroTierOneService.h
index bfc835f2..1b97fd46 100644
--- a/windows/ZeroTierOne/ZeroTierOneService.h
+++ b/windows/ZeroTierOne/ZeroTierOneService.h
@@ -33,11 +33,9 @@
#include <string>
-#include "../../node/Node.hpp"
-#include "../../node/Defaults.hpp"
-#include "../../node/Thread.hpp"
#include "../../node/Mutex.hpp"
-#include "../../node/Utils.hpp"
+#include "../../osdep/Thread.hpp"
+#include "../../service/OneService.hpp"
// Uncomment to make debugging Windows services suck slightly less hard.
//#define ZT_DEBUG_SERVICE "C:\\ZeroTierOneServiceDebugLog.txt"
@@ -79,7 +77,7 @@ protected:
virtual void OnShutdown();
private:
- ZeroTier::Node *volatile _node;
+ ZeroTier::OneService *volatile _service;
ZeroTier::Mutex _lock;
ZeroTier::Thread _thread;
};