Browse Source

moved start/stop client services from Daemon to ClientContext

pull/102/head
orignal 10 years ago
parent
commit
4379f8e5ee
  1. 83
      ClientContext.cpp
  2. 14
      ClientContext.h
  3. 88
      Daemon.cpp

83
ClientContext.cpp

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
#include "util.h"
#include "Log.h"
#include "ClientContext.h"
namespace i2p
@ -6,6 +7,22 @@ namespace i2p @@ -6,6 +7,22 @@ namespace i2p
namespace client
{
ClientContext context;
ClientContext::ClientContext (): m_SharedLocalDestination (nullptr),
m_HttpProxy (nullptr), m_SocksProxy (nullptr), m_IrcTunnel (nullptr),
m_ServerTunnel (nullptr), m_SamBridge (nullptr)
{
}
ClientContext::~ClientContext ()
{
delete m_HttpProxy;
delete m_SocksProxy;
delete m_IrcTunnel;
delete m_ServerTunnel;
delete m_SamBridge;
}
void ClientContext::Start ()
{
if (!m_SharedLocalDestination)
@ -14,10 +31,76 @@ namespace client @@ -14,10 +31,76 @@ namespace client
m_Destinations[m_SharedLocalDestination->GetIdentity ().GetIdentHash ()] = m_SharedLocalDestination;
m_SharedLocalDestination->Start ();
}
m_HttpProxy = new i2p::proxy::HTTPProxy(i2p::util::config::GetArg("-httpproxyport", 4446));
m_HttpProxy->Start();
LogPrint("HTTP Proxy started");
m_SocksProxy = new i2p::proxy::SOCKSProxy(i2p::util::config::GetArg("-socksproxyport", 4447));
m_SocksProxy->Start();
LogPrint("SOCKS Proxy Started");
std::string ircDestination = i2p::util::config::GetArg("-ircdest", "");
if (ircDestination.length () > 0) // ircdest is presented
{
i2p::stream::StreamingDestination * localDestination = nullptr;
std::string ircKeys = i2p::util::config::GetArg("-irckeys", "");
if (ircKeys.length () > 0)
localDestination = i2p::client::LoadLocalDestination (ircKeys, false);
m_IrcTunnel = new i2p::stream::I2PClientTunnel (m_SocksProxy->GetService (), ircDestination,
i2p::util::config::GetArg("-ircport", 6668), localDestination);
m_IrcTunnel->Start ();
LogPrint("IRC tunnel started");
}
std::string eepKeys = i2p::util::config::GetArg("-eepkeys", "");
if (eepKeys.length () > 0) // eepkeys file is presented
{
auto localDestination = i2p::client::LoadLocalDestination (eepKeys, true);
m_ServerTunnel = new i2p::stream::I2PServerTunnel (m_SocksProxy->GetService (),
i2p::util::config::GetArg("-eephost", "127.0.0.1"), i2p::util::config::GetArg("-eepport", 80),
localDestination);
m_ServerTunnel->Start ();
LogPrint("Server tunnel started");
}
int samPort = i2p::util::config::GetArg("-samport", 0);
if (samPort)
{
m_SamBridge = new i2p::stream::SAMBridge (samPort);
m_SamBridge->Start ();
LogPrint("SAM bridge started");
}
}
void ClientContext::Stop ()
{
m_HttpProxy->Stop();
delete m_HttpProxy;
m_HttpProxy = nullptr;
LogPrint("HTTP Proxy stoped");
m_SocksProxy->Stop();
delete m_SocksProxy;
m_SocksProxy = nullptr;
LogPrint("SOCKS Proxy stoped");
if (m_IrcTunnel)
{
m_IrcTunnel->Stop ();
delete m_IrcTunnel;
m_IrcTunnel = nullptr;
LogPrint("IRC tunnel stoped");
}
if (m_ServerTunnel)
{
m_ServerTunnel->Stop ();
delete m_ServerTunnel;
m_ServerTunnel = nullptr;
LogPrint("Server tunnel stoped");
}
if (m_SamBridge)
{
m_SamBridge->Stop ();
delete m_SamBridge;
m_SamBridge = nullptr;
LogPrint("SAM brdige stoped");
}
for (auto it: m_Destinations)
{
it.second->Stop ();

14
ClientContext.h

@ -3,6 +3,10 @@ @@ -3,6 +3,10 @@
#include <mutex>
#include "Destination.h"
#include "HTTPProxy.h"
#include "SOCKS.h"
#include "I2PTunnel.h"
#include "SAM.h"
namespace i2p
{
@ -12,8 +16,8 @@ namespace client @@ -12,8 +16,8 @@ namespace client
{
public:
ClientContext (): m_SharedLocalDestination (nullptr) {};
~ClientContext () {};
ClientContext ();
~ClientContext ();
void Start ();
void Stop ();
@ -35,6 +39,12 @@ namespace client @@ -35,6 +39,12 @@ namespace client
std::map<i2p::data::IdentHash, i2p::stream::StreamingDestination *> m_Destinations;
i2p::stream::StreamingDestination * m_SharedLocalDestination;
i2p::proxy::HTTPProxy * m_HttpProxy;
i2p::proxy::SOCKSProxy * m_SocksProxy;
i2p::stream::I2PClientTunnel * m_IrcTunnel;
i2p::stream::I2PServerTunnel * m_ServerTunnel;
i2p::stream::SAMBridge * m_SamBridge;
public:
// for HTTP
const decltype(m_Destinations)& GetDestinations () const { return m_Destinations; };

88
Daemon.cpp

@ -15,11 +15,7 @@ @@ -15,11 +15,7 @@
#include "Streaming.h"
#include "Destination.h"
#include "HTTPServer.h"
#include "HTTPProxy.h"
#include "SOCKS.h"
#include "ClientContext.h"
#include "I2PTunnel.h"
#include "SAM.h"
namespace i2p
{
@ -28,24 +24,14 @@ namespace i2p @@ -28,24 +24,14 @@ namespace i2p
class Daemon_Singleton::Daemon_Singleton_Private
{
public:
Daemon_Singleton_Private() : httpServer(nullptr), httpProxy(nullptr),
socksProxy(nullptr), ircTunnel(nullptr), serverTunnel (nullptr),
samBridge (nullptr) { };
~Daemon_Singleton_Private() {
Daemon_Singleton_Private() : httpServer(nullptr)
{};
~Daemon_Singleton_Private()
{
delete httpServer;
delete httpProxy;
delete socksProxy;
delete ircTunnel;
delete serverTunnel;
delete samBridge;
};
i2p::util::HTTPServer *httpServer;
i2p::proxy::HTTPProxy *httpProxy;
i2p::proxy::SOCKSProxy *socksProxy;
i2p::stream::I2PClientTunnel * ircTunnel;
i2p::stream::I2PServerTunnel * serverTunnel;
i2p::stream::SAMBridge * samBridge;
};
Daemon_Singleton::Daemon_Singleton() : running(1), d(*new Daemon_Singleton_Private()) {};
@ -105,7 +91,6 @@ namespace i2p @@ -105,7 +91,6 @@ namespace i2p
d.httpServer = new i2p::util::HTTPServer(i2p::util::config::GetArg("-httpport", 7070));
d.httpServer->Start();
LogPrint("HTTP Server started");
i2p::data::netdb.Start();
LogPrint("NetDB started");
i2p::transports.Start();
@ -115,52 +100,12 @@ namespace i2p @@ -115,52 +100,12 @@ namespace i2p
i2p::client::context.Start ();
LogPrint("Client started");
d.httpProxy = new i2p::proxy::HTTPProxy(i2p::util::config::GetArg("-httpproxyport", 4446));
d.httpProxy->Start();
LogPrint("HTTP Proxy started");
d.socksProxy = new i2p::proxy::SOCKSProxy(i2p::util::config::GetArg("-socksproxyport", 4447));
d.socksProxy->Start();
LogPrint("SOCKS Proxy Started");
std::string ircDestination = i2p::util::config::GetArg("-ircdest", "");
if (ircDestination.length () > 0) // ircdest is presented
{
i2p::stream::StreamingDestination * localDestination = nullptr;
std::string ircKeys = i2p::util::config::GetArg("-irckeys", "");
if (ircKeys.length () > 0)
localDestination = i2p::client::LoadLocalDestination (ircKeys, false);
d.ircTunnel = new i2p::stream::I2PClientTunnel (d.socksProxy->GetService (), ircDestination,
i2p::util::config::GetArg("-ircport", 6668), localDestination);
d.ircTunnel->Start ();
LogPrint("IRC tunnel started");
}
std::string eepKeys = i2p::util::config::GetArg("-eepkeys", "");
if (eepKeys.length () > 0) // eepkeys file is presented
{
auto localDestination = i2p::client::LoadLocalDestination (eepKeys, true);
d.serverTunnel = new i2p::stream::I2PServerTunnel (d.socksProxy->GetService (),
i2p::util::config::GetArg("-eephost", "127.0.0.1"), i2p::util::config::GetArg("-eepport", 80),
localDestination);
d.serverTunnel->Start ();
LogPrint("Server tunnel started");
}
int samPort = i2p::util::config::GetArg("-samport", 0);
if (samPort)
{
d.samBridge = new i2p::stream::SAMBridge (samPort);
d.samBridge->Start ();
LogPrint("SAM bridge started");
}
return true;
}
bool Daemon_Singleton::stop()
{
LogPrint("Shutdown started.");
d.httpProxy->Stop();
LogPrint("HTTP Proxy stoped");
d.socksProxy->Stop();
LogPrint("SOCKS Proxy stoped");
i2p::client::context.Stop();
LogPrint("Client stoped");
i2p::tunnel::tunnels.Stop();
@ -171,34 +116,9 @@ namespace i2p @@ -171,34 +116,9 @@ namespace i2p
LogPrint("NetDB stoped");
d.httpServer->Stop();
LogPrint("HTTP Server stoped");
if (d.ircTunnel)
{
d.ircTunnel->Stop ();
delete d.ircTunnel;
d.ircTunnel = nullptr;
LogPrint("IRC tunnel stoped");
}
if (d.serverTunnel)
{
d.serverTunnel->Stop ();
delete d.serverTunnel;
d.serverTunnel = nullptr;
LogPrint("Server tunnel stoped");
}
if (d.samBridge)
{
d.samBridge->Stop ();
delete d.samBridge;
d.samBridge = nullptr;
LogPrint("SAM brdige stoped");
}
StopLog ();
delete d.socksProxy; d.socksProxy = nullptr;
delete d.httpProxy; d.httpProxy = nullptr;
delete d.httpServer; d.httpServer = nullptr;
delete d.samBridge; d.samBridge = nullptr;
return true;
}

Loading…
Cancel
Save