From c131fc8c86dbc00fccd8e275d909b534c6e97a6a Mon Sep 17 00:00:00 2001 From: chertov Date: Wed, 23 Apr 2014 01:59:29 +0400 Subject: [PATCH 1/8] Print data path on the statistics page --- HTTPServer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/HTTPServer.cpp b/HTTPServer.cpp index 961acbb1..ac23ebb3 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -238,6 +238,7 @@ namespace util void HTTPConnection::FillContent (std::stringstream& s) { + s << "Data path: " << i2p::util::filesystem::GetDataDir().string() << "
" << "
"; s << "Our external address:" << "
" << "
"; for (auto& address : i2p::context.GetRouterInfo().GetAddresses()) { From 861e9c52ed9a1e31194b64ea4a0a9a2f32039614 Mon Sep 17 00:00:00 2001 From: chertov Date: Wed, 23 Apr 2014 02:01:57 +0400 Subject: [PATCH 2/8] Win32Service uses Daemon start()/stop() --- Win32/Win32Service.cpp | 152 ++++++++++++----------------------------- Win32/Win32Service.h | 8 +-- 2 files changed, 46 insertions(+), 114 deletions(-) diff --git a/Win32/Win32Service.cpp b/Win32/Win32Service.cpp index 0d75dd14..e5abc72a 100644 --- a/Win32/Win32Service.cpp +++ b/Win32/Win32Service.cpp @@ -7,17 +7,26 @@ #include #include -#include "Log.h" -#include "Transports.h" -#include "NTCPSession.h" -#include "Tunnel.h" -#include "NetDb.h" -#include "Garlic.h" -#include "util.h" -#include "Streaming.h" +#include "../Daemon.h" +#include "../Log.h" I2PService *I2PService::s_service = NULL; +BOOL I2PService::isService() +{ + BOOL bIsService = FALSE; + + HWINSTA hWinStation = GetProcessWindowStation(); + if (hWinStation != NULL) + { + USEROBJECTFLAGS uof = { 0 }; + if (GetUserObjectInformation(hWinStation, UOI_FLAGS, &uof, sizeof(USEROBJECTFLAGS), NULL) && ((uof.dwFlags & WSF_VISIBLE) == 0)) + { + bIsService = TRUE; + } + } + return bIsService; +} BOOL I2PService::Run(I2PService &service) { @@ -65,7 +74,7 @@ void WINAPI I2PService::ServiceCtrlHandler(DWORD dwCtrl) I2PService::I2PService(PSTR pszServiceName, BOOL fCanStop, BOOL fCanShutdown, - BOOL fCanPauseContinue) : _httpServer(nullptr), _httpProxy(nullptr) + BOOL fCanPauseContinue) { m_name = (pszServiceName == NULL) ? "" : pszServiceName; @@ -123,13 +132,13 @@ void I2PService::Start(DWORD dwArgc, PSTR *pszArgv) } catch (DWORD dwError) { - LogPrint("Service Start", dwError); + LogPrint("Win32Service Start", dwError); SetServiceStatus(SERVICE_STOPPED, dwError); } catch (...) { - LogPrint("Service failed to start.", EVENTLOG_ERROR_TYPE); + LogPrint("Win32Service failed to start.", EVENTLOG_ERROR_TYPE); SetServiceStatus(SERVICE_STOPPED); } @@ -138,32 +147,15 @@ void I2PService::Start(DWORD dwArgc, PSTR *pszArgv) void I2PService::OnStart(DWORD dwArgc, PSTR *pszArgv) { - LogPrint("CppWindowsService in OnStart", + LogPrint("Win32Service in OnStart", EVENTLOG_INFORMATION_TYPE); - i2p::util::config::OptionParser(dwArgc, pszArgv); - i2p::util::filesystem::ReadConfigFile(i2p::util::config::mapArgs, i2p::util::config::mapMultiArgs); - i2p::context.OverrideNTCPAddress(i2p::util::config::GetCharArg("-host", "127.0.0.1"), - i2p::util::config::GetArg("-port", 17070)); - - _httpServer = new i2p::util::HTTPServer(i2p::util::config::GetArg("-httpport", 7070)); - _httpServer->Start(); - LogPrint("HTTPServer started", EVENTLOG_INFORMATION_TYPE); - - i2p::data::netdb.Start(); - LogPrint("NetDB started", EVENTLOG_INFORMATION_TYPE); - i2p::transports.Start(); - LogPrint("Transports started", EVENTLOG_INFORMATION_TYPE); - i2p::tunnel::tunnels.Start(); - LogPrint("Tunnels started", EVENTLOG_INFORMATION_TYPE); - i2p::garlic::routing.Start(); - LogPrint("Routing started", EVENTLOG_INFORMATION_TYPE); - i2p::stream::StartStreaming(); - LogPrint("Streaming started", EVENTLOG_INFORMATION_TYPE); - - _httpProxy = new i2p::proxy::HTTPProxy(i2p::util::config::GetArg("-httpproxyport", 4446)); - _httpProxy->Start(); - LogPrint("Proxy started", EVENTLOG_INFORMATION_TYPE); + Daemon.start(); + + //i2p::util::config::OptionParser(dwArgc, pszArgv); + //i2p::util::filesystem::ReadConfigFile(i2p::util::config::mapArgs, i2p::util::config::mapMultiArgs); + //i2p::context.OverrideNTCPAddress(i2p::util::config::GetCharArg("-host", "127.0.0.1"), + // i2p::util::config::GetArg("-port", 17070)); _worker = new std::thread(std::bind(&I2PService::WorkerThread, this)); } @@ -194,13 +186,13 @@ void I2PService::Stop() } catch (DWORD dwError) { - LogPrint("Service Stop", dwError); + LogPrint("Win32Service Stop", dwError); SetServiceStatus(dwOriginalState); } catch (...) { - LogPrint("Service failed to stop.", EVENTLOG_ERROR_TYPE); + LogPrint("Win32Service failed to stop.", EVENTLOG_ERROR_TYPE); SetServiceStatus(dwOriginalState); } @@ -210,24 +202,9 @@ void I2PService::Stop() void I2PService::OnStop() { // Log a service stop message to the Application log. - LogPrint("CppWindowsService in OnStop", EVENTLOG_INFORMATION_TYPE); - - _httpProxy->Stop(); - LogPrint("HTTPProxy stoped", EVENTLOG_INFORMATION_TYPE); - delete _httpProxy; - i2p::stream::StopStreaming(); - LogPrint("Streaming stoped", EVENTLOG_INFORMATION_TYPE); - i2p::garlic::routing.Stop(); - LogPrint("Routing stoped", EVENTLOG_INFORMATION_TYPE); - i2p::tunnel::tunnels.Stop(); - LogPrint("Tunnels stoped", EVENTLOG_INFORMATION_TYPE); - i2p::transports.Stop(); - LogPrint("Transports stoped", EVENTLOG_INFORMATION_TYPE); - i2p::data::netdb.Stop(); - LogPrint("NetDB stoped", EVENTLOG_INFORMATION_TYPE); - _httpServer->Stop(); - LogPrint("HTTPServer stoped", EVENTLOG_INFORMATION_TYPE); - delete _httpServer; + LogPrint("Win32Service in OnStop", EVENTLOG_INFORMATION_TYPE); + + Daemon.stop(); m_fStopping = TRUE; if (WaitForSingleObject(m_hStoppedEvent, INFINITE) != WAIT_OBJECT_0) @@ -251,13 +228,13 @@ void I2PService::Pause() } catch (DWORD dwError) { - LogPrint("Service Pause", dwError); + LogPrint("Win32Service Pause", dwError); SetServiceStatus(SERVICE_RUNNING); } catch (...) { - LogPrint("Service failed to pause.", EVENTLOG_ERROR_TYPE); + LogPrint("Win32Service failed to pause.", EVENTLOG_ERROR_TYPE); SetServiceStatus(SERVICE_RUNNING); } @@ -281,13 +258,13 @@ void I2PService::Continue() } catch (DWORD dwError) { - LogPrint("Service Continue", dwError); + LogPrint("Win32Service Continue", dwError); SetServiceStatus(SERVICE_PAUSED); } catch (...) { - LogPrint("Service failed to resume.", EVENTLOG_ERROR_TYPE); + LogPrint("Win32Service failed to resume.", EVENTLOG_ERROR_TYPE); SetServiceStatus(SERVICE_PAUSED); } @@ -309,11 +286,11 @@ void I2PService::Shutdown() } catch (DWORD dwError) { - LogPrint("Service Shutdown", dwError); + LogPrint("Win32Service Shutdown", dwError); } catch (...) { - LogPrint("Service failed to shut down.", EVENTLOG_ERROR_TYPE); + LogPrint("Win32Service failed to shut down.", EVENTLOG_ERROR_TYPE); } } @@ -365,6 +342,8 @@ void InstallService(PSTR pszServiceName, PSTR pszAccount, PSTR pszPassword) { + printf("Try to install Win32Service (%s).\n", pszServiceName); + char szPath[MAX_PATH]; SC_HANDLE schSCManager = NULL; SC_HANDLE schService = NULL; @@ -409,7 +388,7 @@ void InstallService(PSTR pszServiceName, return; } - printf("%s is installed.\n", pszServiceName); + printf("Win32Service is installed as %s.\n", pszServiceName); // Centralized cleanup for all allocated resources. FreeHandles(schSCManager, schService); @@ -417,6 +396,8 @@ void InstallService(PSTR pszServiceName, void UninstallService(PSTR pszServiceName) { + printf("Try to uninstall Win32Service (%s).\n", pszServiceName); + SC_HANDLE schSCManager = NULL; SC_HANDLE schService = NULL; SERVICE_STATUS ssSvcStatus = {}; @@ -443,7 +424,7 @@ void UninstallService(PSTR pszServiceName) // Try to stop the service if (ControlService(schService, SERVICE_CONTROL_STOP, &ssSvcStatus)) { - printf("Stopping %s.", pszServiceName); + printf("Stopping %s.\n", pszServiceName); Sleep(1000); while (QueryServiceStatus(schService, &ssSvcStatus)) @@ -479,48 +460,3 @@ void UninstallService(PSTR pszServiceName) // Centralized cleanup for all allocated resources. FreeHandles(schSCManager, schService); } - -void service_control(int isDaemon) -{ - std::string serviceControl = i2p::util::config::GetArg("-service", "none"); - if (serviceControl == "install") - { - InstallService( - SERVICE_NAME, // Name of service - SERVICE_DISPLAY_NAME, // Name to display - SERVICE_START_TYPE, // Service start type - SERVICE_DEPENDENCIES, // Dependencies - SERVICE_ACCOUNT, // Service running account - SERVICE_PASSWORD // Password of the account - ); - exit(0); - } - else if (serviceControl == "remove") - { - UninstallService(SERVICE_NAME); - exit(0); - } - else if (serviceControl != "none") - { - printf(" --service=install to install the service.\n"); - printf(" --service=remove to remove the service.\n"); - exit(0); - } - else if (isDaemon) - { - std::string logfile = i2p::util::filesystem::GetDataDir().string(); - logfile.append("\\debug.log"); - FILE* openResult = freopen(logfile.c_str(), "a", stdout); - if (!openResult) - { - exit(-17); - } - LogPrint("Service logging enabled."); - I2PService service(SERVICE_NAME); - if (!I2PService::Run(service)) - { - LogPrint("Service failed to run w/err 0x%08lx\n", GetLastError()); - } - exit(0); - } -} \ No newline at end of file diff --git a/Win32/Win32Service.h b/Win32/Win32Service.h index 5e8f89b4..868528f6 100644 --- a/Win32/Win32Service.h +++ b/Win32/Win32Service.h @@ -1,8 +1,6 @@ #ifndef WIN_32_SERVICE_H__ #define WIN_32_SERVICE_H__ -#include "../HTTPServer.h" -#include "../HTTPProxy.h" #include #define WIN32_LEAN_AND_MEAN #include @@ -40,6 +38,7 @@ public: virtual ~I2PService(void); + static BOOL isService(); static BOOL Run(I2PService &service); void Stop(); @@ -70,8 +69,7 @@ private: BOOL m_fStopping; HANDLE m_hStoppedEvent; - i2p::util::HTTPServer* _httpServer; - i2p::proxy::HTTPProxy* _httpProxy; + std::thread* _worker; }; @@ -84,6 +82,4 @@ void InstallService(PSTR pszServiceName, void UninstallService(PSTR pszServiceName); -void service_control(int isDaemon); - #endif // WIN_32_SERVICE_H__ \ No newline at end of file From e3ff849aa4b7da35379fcc71b28e5519999e0f20 Mon Sep 17 00:00:00 2001 From: chertov Date: Wed, 23 Apr 2014 02:07:21 +0400 Subject: [PATCH 3/8] Using the d-pointer to hide HTTPProxy, HTTPServer, add logfile ofstream --- Daemon.cpp | 90 ++++++++++++++++++++++++++++++++++++++++--------- Daemon.h | 28 ++++++++------- DaemonWin32.cpp | 58 +++++++++++++++++++++++++++++-- 3 files changed, 146 insertions(+), 30 deletions(-) diff --git a/Daemon.cpp b/Daemon.cpp index f6c0668b..c587bfa9 100644 --- a/Daemon.cpp +++ b/Daemon.cpp @@ -2,6 +2,8 @@ #define _CRT_SECURE_NO_WARNINGS // to use freopen #endif +#include + #include "Daemon.h" #include "Log.h" @@ -15,15 +17,42 @@ #include "Garlic.h" #include "util.h" #include "Streaming.h" +#include "HTTPServer.h" +#include "HTTPProxy.h" namespace i2p { namespace util { - bool Daemon_Singleton::start() + class Daemon_Singleton::Daemon_Singleton_Private { + public: + Daemon_Singleton_Private() : httpServer(nullptr), httpProxy(nullptr) { }; + ~Daemon_Singleton_Private() { + delete httpServer; + delete httpProxy; + }; + + i2p::util::HTTPServer *httpServer; + i2p::proxy::HTTPProxy *httpProxy; + }; + + Daemon_Singleton::Daemon_Singleton() : d(*new Daemon_Singleton_Private()), running(1) {}; + Daemon_Singleton::~Daemon_Singleton() { + delete &d; + }; + + + bool Daemon_Singleton::init(int argc, char* argv[]) + { + i2p::util::config::OptionParser(argc, argv); + + LogPrint("\n\n\n\ni2pd starting\n"); + LogPrint("data directory: ", i2p::util::filesystem::GetDataDir().string()); + i2p::util::filesystem::ReadConfigFile(i2p::util::config::mapArgs, i2p::util::config::mapMultiArgs); + isDaemon = i2p::util::config::GetArg("-daemon", 0); - isLogging = i2p::util::config::GetArg("-log", 0); + isLogging = i2p::util::config::GetArg("-log", 1); //TODO: This is an ugly workaround. fix it. //TODO: Autodetect public IP. @@ -32,27 +61,51 @@ namespace i2p if (isLogging == 1) { - std::string logfile = i2p::util::filesystem::GetDataDir().string(); + std::string logfile_path = i2p::util::filesystem::GetDataDir().string(); #ifndef _WIN32 - logfile.append("/debug.log"); + logfile_path.append("/debug.log"); #else - logfile.append("\\debug.log"); + logfile_path.append("\\debug.log"); #endif - freopen(logfile.c_str(), "a", stdout); + logfile.open(logfile_path, std::ofstream::out | std::ofstream::binary | std::ofstream::trunc); + //logfile = freopen(logfile_path.c_str(), "a", stdout); + if (!logfile.is_open()) + { + exit(-17); + } + + //std::streambuf * old = std::cout.rdbuf(logfile.rdbuf()); + LogPrint("Logging to file enabled."); - } - httpServer = new i2p::util::HTTPServer(i2p::util::config::GetArg("-httpport", 7070)); - httpServer->Start(); + LogPrint("CMD parameters:"); + for (int i = 0; i < argc; ++i) + LogPrint(i, " ", argv[i]); + + } + return true; + } + + bool Daemon_Singleton::start() + { + d.httpServer = new i2p::util::HTTPServer(i2p::util::config::GetArg("-httpport", 7070)); + d.httpServer->Start(); + LogPrint("HTTPServer started", EVENTLOG_INFORMATION_TYPE); i2p::data::netdb.Start(); + LogPrint("NetDB started", EVENTLOG_INFORMATION_TYPE); i2p::transports.Start(); + LogPrint("Transports started", EVENTLOG_INFORMATION_TYPE); i2p::tunnel::tunnels.Start(); + LogPrint("Tunnels started", EVENTLOG_INFORMATION_TYPE); i2p::garlic::routing.Start(); + LogPrint("Routing started", EVENTLOG_INFORMATION_TYPE); i2p::stream::StartStreaming(); + LogPrint("Streaming started", EVENTLOG_INFORMATION_TYPE); - httpProxy = new i2p::proxy::HTTPProxy(i2p::util::config::GetArg("-httpproxyport", 4446)); - httpProxy->Start(); + d.httpProxy = new i2p::proxy::HTTPProxy(i2p::util::config::GetArg("-httpproxyport", 4446)); + d.httpProxy->Start(); + LogPrint("Proxy started", EVENTLOG_INFORMATION_TYPE); return true; } @@ -61,16 +114,23 @@ namespace i2p { LogPrint("Shutdown started."); - httpProxy->Stop(); + d.httpProxy->Stop(); + LogPrint("HTTPProxy stoped", EVENTLOG_INFORMATION_TYPE); i2p::stream::StopStreaming(); + LogPrint("Streaming stoped", EVENTLOG_INFORMATION_TYPE); i2p::garlic::routing.Stop(); + LogPrint("Routing stoped", EVENTLOG_INFORMATION_TYPE); i2p::tunnel::tunnels.Stop(); + LogPrint("Tunnels stoped", EVENTLOG_INFORMATION_TYPE); i2p::transports.Stop(); + LogPrint("Transports stoped", EVENTLOG_INFORMATION_TYPE); i2p::data::netdb.Stop(); - httpServer->Stop(); + LogPrint("NetDB stoped", EVENTLOG_INFORMATION_TYPE); + d.httpServer->Stop(); + LogPrint("HTTPServer stoped", EVENTLOG_INFORMATION_TYPE); - delete httpProxy; httpProxy = NULL; - delete httpServer; httpServer = NULL; + delete d.httpProxy; d.httpProxy = nullptr; + delete d.httpServer; d.httpServer = nullptr; if (isLogging == 1) { diff --git a/Daemon.h b/Daemon.h index 9ac00a48..4e27d108 100644 --- a/Daemon.h +++ b/Daemon.h @@ -1,15 +1,21 @@ #pragma once +#include -#include "HTTPServer.h" -#include "HTTPProxy.h" +#ifdef _WIN32 +#define Daemon i2p::util::DaemonWin32::Instance() +#else +#define Daemon i2p::util::DaemonLinux::Instance() +#endif namespace i2p { namespace util { + class Daemon_Singleton_Private; class Daemon_Singleton { public: + virtual bool init(int argc, char* argv[]); virtual bool start(); virtual bool stop(); @@ -18,20 +24,18 @@ namespace i2p int running; - private: - i2p::util::HTTPServer *httpServer; - i2p::proxy::HTTPProxy *httpProxy; + std::ofstream logfile; protected: - Daemon_Singleton() : running(1) {}; - virtual ~Daemon_Singleton() { - delete httpServer; - delete httpProxy; - }; + Daemon_Singleton(); + virtual ~Daemon_Singleton(); + + // d-pointer for httpServer, httpProxy, etc. + class Daemon_Singleton_Private; + Daemon_Singleton_Private &d; }; #ifdef _WIN32 - #define Daemon i2p::util::DaemonWin32::Instance() class DaemonWin32 : public Daemon_Singleton { public: @@ -41,11 +45,11 @@ namespace i2p return instance; } + virtual bool init(int argc, char* argv[]); virtual bool start(); virtual bool stop(); }; #else - #define Daemon i2p::util::DaemonLinux::Instance() class DaemonLinux : public Daemon_Singleton { public: diff --git a/DaemonWin32.cpp b/DaemonWin32.cpp index f27ba9c7..96b28076 100644 --- a/DaemonWin32.cpp +++ b/DaemonWin32.cpp @@ -1,22 +1,74 @@ #include "Daemon.h" +#include "util.h" +#include "Log.h" #ifdef _WIN32 #include "./Win32/Win32Service.h" - namespace i2p { namespace util { - bool DaemonWin32::start() + bool DaemonWin32::init(int argc, char* argv[]) { setlocale(LC_CTYPE, ""); SetConsoleCP(1251); SetConsoleOutputCP(1251); setlocale(LC_ALL, "Russian"); - service_control(isDaemon); + if (!Daemon_Singleton::init(argc, argv)) return false; + if (I2PService::isService()) + isDaemon = 1; + else + isDaemon = 0; + + std::string serviceControl = i2p::util::config::GetArg("-service", "none"); + if (serviceControl == "install") + { + InstallService( + SERVICE_NAME, // Name of service + SERVICE_DISPLAY_NAME, // Name to display + SERVICE_START_TYPE, // Service start type + SERVICE_DEPENDENCIES, // Dependencies + SERVICE_ACCOUNT, // Service running account + SERVICE_PASSWORD // Password of the account + ); + exit(0); + } + else if (serviceControl == "remove") + { + UninstallService(SERVICE_NAME); + exit(0); + } + else if (serviceControl != "none") + { + printf(" --service=install to install the service.\n"); + printf(" --service=remove to remove the service.\n"); + } + + if (isDaemon == 1) + { + LogPrint("Service session"); + I2PService service(SERVICE_NAME); + if (!I2PService::Run(service)) + { + LogPrint("Service failed to run w/err 0x%08lx\n", GetLastError()); + exit(EXIT_FAILURE); + } + exit(EXIT_SUCCESS); + } + else + LogPrint("User session"); + + return true; + } + bool DaemonWin32::start() + { + setlocale(LC_CTYPE, ""); + SetConsoleCP(1251); + SetConsoleOutputCP(1251); + setlocale(LC_ALL, "Russian"); return Daemon_Singleton::start(); } From 0236879c2605f34b50f8ba8e2a896d6519fe2fcb Mon Sep 17 00:00:00 2001 From: chertov Date: Wed, 23 Apr 2014 02:10:21 +0400 Subject: [PATCH 4/8] Logging to file directly. Win32 Services can't write to std::cout --- Log.cpp | 14 +++++++++++++- Log.h | 5 +---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Log.cpp b/Log.cpp index b5e49612..4db4920e 100644 --- a/Log.cpp +++ b/Log.cpp @@ -1,3 +1,15 @@ #include "Log.h" -i2p::util::MsgQueue g_Log; \ No newline at end of file +#include "Daemon.h" + +i2p::util::MsgQueue g_Log; + +void LogMsg::Process() +{ + if (Daemon.isLogging == 1 && Daemon.logfile.is_open()) + { + Daemon.logfile << s.str(); + Daemon.logfile.flush(); + } + output << s.str(); +} \ No newline at end of file diff --git a/Log.h b/Log.h index e538b7be..acef8f8e 100644 --- a/Log.h +++ b/Log.h @@ -12,10 +12,7 @@ struct LogMsg LogMsg (std::ostream& o = std::cout): output (o) {}; - void Process () - { - output << s.str (); - } + void Process(); }; extern i2p::util::MsgQueue g_Log; From 64ba1622c2eb89911a9a66d5e61fe0a742a6e63c Mon Sep 17 00:00:00 2001 From: chertov Date: Wed, 23 Apr 2014 02:10:51 +0400 Subject: [PATCH 5/8] Use Daemon.init in main() --- i2p.cpp | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/i2p.cpp b/i2p.cpp index 3c5f3637..f441fc02 100644 --- a/i2p.cpp +++ b/i2p.cpp @@ -1,16 +1,10 @@ -#include +#include -#include "util.h" #include "Daemon.h" int main( int argc, char* argv[] ) { - i2p::util::config::OptionParser(argc, argv); - - LogPrint("\n\n\n\ni2pd starting\n"); - LogPrint("data directory: ", i2p::util::filesystem::GetDataDir().string()); - i2p::util::filesystem::ReadConfigFile(i2p::util::config::mapArgs, i2p::util::config::mapMultiArgs); - + Daemon.init(argc, argv); Daemon.start(); while (Daemon.running) { @@ -18,6 +12,5 @@ int main( int argc, char* argv[] ) std::this_thread::sleep_for (std::chrono::seconds(1)); } Daemon.stop(); - - return 0; + return EXIT_SUCCESS; } From 6bb5a04102191a477aaa27765e945ab11a858745 Mon Sep 17 00:00:00 2001 From: chertov Date: Wed, 23 Apr 2014 02:11:19 +0400 Subject: [PATCH 6/8] Run as admin --- Win32/i2pd.vcxproj | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Win32/i2pd.vcxproj b/Win32/i2pd.vcxproj index 612c3de2..3eb9c283 100644 --- a/Win32/i2pd.vcxproj +++ b/Win32/i2pd.vcxproj @@ -110,6 +110,7 @@ ./..;$(BOOST);$(CRYPTOPP);$(IncludePath) $(BOOST)\stage\lib;$(CRYPTOPP)\cryptopp\Win32\Output\$(Configuration)\;$(LibraryPath) ./..;$(VC_SourcePath); + $(ProjectName)_d ./..;$(BOOST);$(CRYPTOPP);$(IncludePath) @@ -127,6 +128,8 @@ true cryptlib.lib;%(AdditionalDependencies) + $(ProjectDir)$(TargetName)$(TargetExt) + RequireAdministrator From 607be87a4dacb549351edc6f7e4edd08f5460c1e Mon Sep 17 00:00:00 2001 From: root Date: Wed, 23 Apr 2014 00:37:24 +0200 Subject: [PATCH 7/8] fix linux build --- Daemon.cpp | 40 ++++++++++++++++------------------------ DaemonLinux.cpp | 4 +++- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/Daemon.cpp b/Daemon.cpp index c587bfa9..7dfe54d9 100644 --- a/Daemon.cpp +++ b/Daemon.cpp @@ -1,7 +1,3 @@ -#ifdef _WIN32 -#define _CRT_SECURE_NO_WARNINGS // to use freopen -#endif - #include #include "Daemon.h" @@ -68,13 +64,9 @@ namespace i2p logfile_path.append("\\debug.log"); #endif logfile.open(logfile_path, std::ofstream::out | std::ofstream::binary | std::ofstream::trunc); - //logfile = freopen(logfile_path.c_str(), "a", stdout); + if (!logfile.is_open()) - { exit(-17); - } - - //std::streambuf * old = std::cout.rdbuf(logfile.rdbuf()); LogPrint("Logging to file enabled."); @@ -90,22 +82,22 @@ namespace i2p { d.httpServer = new i2p::util::HTTPServer(i2p::util::config::GetArg("-httpport", 7070)); d.httpServer->Start(); - LogPrint("HTTPServer started", EVENTLOG_INFORMATION_TYPE); + LogPrint("HTTPServer started"); i2p::data::netdb.Start(); - LogPrint("NetDB started", EVENTLOG_INFORMATION_TYPE); + LogPrint("NetDB started"); i2p::transports.Start(); - LogPrint("Transports started", EVENTLOG_INFORMATION_TYPE); + LogPrint("Transports started"); i2p::tunnel::tunnels.Start(); - LogPrint("Tunnels started", EVENTLOG_INFORMATION_TYPE); + LogPrint("Tunnels started"); i2p::garlic::routing.Start(); - LogPrint("Routing started", EVENTLOG_INFORMATION_TYPE); + LogPrint("Routing started"); i2p::stream::StartStreaming(); - LogPrint("Streaming started", EVENTLOG_INFORMATION_TYPE); + LogPrint("Streaming started"); d.httpProxy = new i2p::proxy::HTTPProxy(i2p::util::config::GetArg("-httpproxyport", 4446)); d.httpProxy->Start(); - LogPrint("Proxy started", EVENTLOG_INFORMATION_TYPE); + LogPrint("Proxy started"); return true; } @@ -115,19 +107,19 @@ namespace i2p LogPrint("Shutdown started."); d.httpProxy->Stop(); - LogPrint("HTTPProxy stoped", EVENTLOG_INFORMATION_TYPE); + LogPrint("HTTPProxy stoped"); i2p::stream::StopStreaming(); - LogPrint("Streaming stoped", EVENTLOG_INFORMATION_TYPE); + LogPrint("Streaming stoped"); i2p::garlic::routing.Stop(); - LogPrint("Routing stoped", EVENTLOG_INFORMATION_TYPE); + LogPrint("Routing stoped"); i2p::tunnel::tunnels.Stop(); - LogPrint("Tunnels stoped", EVENTLOG_INFORMATION_TYPE); + LogPrint("Tunnels stoped"); i2p::transports.Stop(); - LogPrint("Transports stoped", EVENTLOG_INFORMATION_TYPE); + LogPrint("Transports stoped"); i2p::data::netdb.Stop(); - LogPrint("NetDB stoped", EVENTLOG_INFORMATION_TYPE); + LogPrint("NetDB stoped"); d.httpServer->Stop(); - LogPrint("HTTPServer stoped", EVENTLOG_INFORMATION_TYPE); + LogPrint("HTTPServer stoped"); delete d.httpProxy; d.httpProxy = nullptr; delete d.httpServer; d.httpServer = nullptr; @@ -140,4 +132,4 @@ namespace i2p return true; } } -} \ No newline at end of file +} diff --git a/DaemonLinux.cpp b/DaemonLinux.cpp index 4cfd51ce..119752ac 100644 --- a/DaemonLinux.cpp +++ b/DaemonLinux.cpp @@ -5,8 +5,10 @@ #include #include #include +#include +#include -//#include +#include "Log.h" #include "util.h" From 042c3ebd80688c582fb09f0d2514cb9690aec834 Mon Sep 17 00:00:00 2001 From: chertov Date: Wed, 23 Apr 2014 02:42:10 +0400 Subject: [PATCH 8/8] Add SSUData to VS project --- Win32/i2pd.vcxproj | 2 ++ Win32/i2pd.vcxproj.filters | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/Win32/i2pd.vcxproj b/Win32/i2pd.vcxproj index 3eb9c283..9cef1468 100644 --- a/Win32/i2pd.vcxproj +++ b/Win32/i2pd.vcxproj @@ -31,6 +31,7 @@ + @@ -64,6 +65,7 @@ + diff --git a/Win32/i2pd.vcxproj.filters b/Win32/i2pd.vcxproj.filters index 091e4acf..7d0c33fd 100644 --- a/Win32/i2pd.vcxproj.filters +++ b/Win32/i2pd.vcxproj.filters @@ -108,6 +108,9 @@ Source Files + + Source Files + @@ -212,5 +215,8 @@ Header Files + + Header Files + \ No newline at end of file