Browse Source

multiple server I2P tunnels

pull/163/head
orignal 10 years ago
parent
commit
d2d7b3b348
  1. 43
      ClientContext.cpp
  2. 6
      ClientContext.h

43
ClientContext.cpp

@ -14,8 +14,8 @@ namespace client
ClientContext context; ClientContext context;
ClientContext::ClientContext (): m_SharedLocalDestination (nullptr), ClientContext::ClientContext (): m_SharedLocalDestination (nullptr),
m_HttpProxy (nullptr), m_SocksProxy (nullptr), m_ServerTunnel (nullptr), m_HttpProxy (nullptr), m_SocksProxy (nullptr), m_SamBridge (nullptr),
m_SamBridge (nullptr), m_BOBCommandChannel (nullptr), m_I2PControlService (nullptr) m_BOBCommandChannel (nullptr), m_I2PControlService (nullptr)
{ {
} }
@ -23,7 +23,6 @@ namespace client
{ {
delete m_HttpProxy; delete m_HttpProxy;
delete m_SocksProxy; delete m_SocksProxy;
delete m_ServerTunnel;
delete m_SamBridge; delete m_SamBridge;
delete m_BOBCommandChannel; delete m_BOBCommandChannel;
delete m_I2PControlService; delete m_I2PControlService;
@ -64,9 +63,10 @@ namespace client
if (eepKeys.length () > 0) // eepkeys file is presented if (eepKeys.length () > 0) // eepkeys file is presented
{ {
auto localDestination = LoadLocalDestination (eepKeys, true); auto localDestination = LoadLocalDestination (eepKeys, true);
m_ServerTunnel = new I2PServerTunnel (i2p::util::config::GetArg("-eephost", "127.0.0.1"), auto serverTunnel = new I2PServerTunnel (i2p::util::config::GetArg("-eephost", "127.0.0.1"),
i2p::util::config::GetArg("-eepport", 80), localDestination); i2p::util::config::GetArg("-eepport", 80), localDestination);
m_ServerTunnel->Start (); serverTunnel->Start ();
m_ServerTunnels.insert (std::make_pair(localDestination->GetIdentHash (), std::unique_ptr<I2PServerTunnel>(serverTunnel)));
LogPrint("Server tunnel started"); LogPrint("Server tunnel started");
} }
ReadTunnels (); ReadTunnels ();
@ -117,13 +117,12 @@ namespace client
LogPrint("I2P client tunnel on port ", it.first, " stopped"); LogPrint("I2P client tunnel on port ", it.first, " stopped");
} }
m_ClientTunnels.clear (); m_ClientTunnels.clear ();
if (m_ServerTunnel) for (auto& it: m_ServerTunnels)
{ {
m_ServerTunnel->Stop (); it.second->Stop ();
delete m_ServerTunnel; LogPrint("I2P server tunnel stopped");
m_ServerTunnel = nullptr;
LogPrint("Server tunnel stopped");
} }
m_ServerTunnels.clear ();
if (m_SamBridge) if (m_SamBridge)
{ {
m_SamBridge->Stop (); m_SamBridge->Stop ();
@ -265,10 +264,16 @@ namespace client
{ {
boost::program_options::options_description params ("I2P tunnels parameters"); boost::program_options::options_description params ("I2P tunnels parameters");
params.add_options () params.add_options ()
// client
(I2P_CLIENT_TUNNEL_NAME, boost::program_options::value<std::vector<std::string> >(), "tunnel name") (I2P_CLIENT_TUNNEL_NAME, boost::program_options::value<std::vector<std::string> >(), "tunnel name")
(I2P_CLIENT_TUNNEL_PORT, boost::program_options::value<std::vector<int> >(), "Local port") (I2P_CLIENT_TUNNEL_PORT, boost::program_options::value<std::vector<int> >(), "Local port")
(I2P_CLIENT_TUNNEL_DESTINATION, boost::program_options::value<std::vector<std::string> >(), "destination") (I2P_CLIENT_TUNNEL_DESTINATION, boost::program_options::value<std::vector<std::string> >(), "destination")
(I2P_CLIENT_TUNNEL_KEYS, boost::program_options::value<std::vector<std::string> >(), "keys") (I2P_CLIENT_TUNNEL_KEYS, boost::program_options::value<std::vector<std::string> >(), "keys")
// server
(I2P_SERVER_TUNNEL_NAME, boost::program_options::value<std::vector<std::string> >(), "tunnel name")
(I2P_SERVER_TUNNEL_HOST, boost::program_options::value<std::vector<std::string> >(), "host")
(I2P_SERVER_TUNNEL_PORT, boost::program_options::value<std::vector<int> >(), "port")
(I2P_SERVER_TUNNEL_KEYS, boost::program_options::value<std::vector<std::string> >(), "keys")
; ;
@ -305,6 +310,24 @@ namespace client
} }
LogPrint (eLogInfo, numClientTunnels, " I2P client tunnels created"); LogPrint (eLogInfo, numClientTunnels, " I2P client tunnels created");
} }
int numServerTunnels = vm.count (I2P_SERVER_TUNNEL_NAME);
if (numServerTunnels > 0)
{
auto hosts = vm[I2P_SERVER_TUNNEL_HOST].as<std::vector<std::string> >();
auto ports = vm[I2P_SERVER_TUNNEL_PORT].as<std::vector<int> >();
auto keys = vm[I2P_SERVER_TUNNEL_KEYS].as<std::vector<std::string> >();
for (int i = 0; i < numServerTunnels; i++)
{
auto localDestination = LoadLocalDestination (keys[i], true);
auto serverTunnel = new I2PServerTunnel (hosts[i], ports[i], localDestination);
if (m_ServerTunnels.insert (std::make_pair (localDestination->GetIdentHash (), std::unique_ptr<I2PServerTunnel>(serverTunnel))).second)
serverTunnel->Start ();
else
LogPrint (eLogError, "I2P server tunnel for destination ", m_AddressBook.ToAddress(localDestination->GetIdentHash ()), " already exists");
}
LogPrint (eLogInfo, numServerTunnels, " I2P server tunnels created");
}
} }
} }
} }

6
ClientContext.h

@ -21,6 +21,10 @@ namespace client
const char I2P_CLIENT_TUNNEL_PORT[] = "client.port"; const char I2P_CLIENT_TUNNEL_PORT[] = "client.port";
const char I2P_CLIENT_TUNNEL_DESTINATION[] = "client.destination"; const char I2P_CLIENT_TUNNEL_DESTINATION[] = "client.destination";
const char I2P_CLIENT_TUNNEL_KEYS[] = "client.keys"; const char I2P_CLIENT_TUNNEL_KEYS[] = "client.keys";
const char I2P_SERVER_TUNNEL_NAME[] = "server.name";
const char I2P_SERVER_TUNNEL_HOST[] = "server.host";
const char I2P_SERVER_TUNNEL_PORT[] = "server.port";
const char I2P_SERVER_TUNNEL_KEYS[] = "server.keys";
const char TUNNELS_CONFIG_FILENAME[] = "tunnels.cfg"; const char TUNNELS_CONFIG_FILENAME[] = "tunnels.cfg";
class ClientContext class ClientContext
@ -59,7 +63,7 @@ namespace client
i2p::proxy::HTTPProxy * m_HttpProxy; i2p::proxy::HTTPProxy * m_HttpProxy;
i2p::proxy::SOCKSProxy * m_SocksProxy; i2p::proxy::SOCKSProxy * m_SocksProxy;
std::map<int, std::unique_ptr<I2PClientTunnel> > m_ClientTunnels; // port->tunnel std::map<int, std::unique_ptr<I2PClientTunnel> > m_ClientTunnels; // port->tunnel
I2PServerTunnel * m_ServerTunnel; std::map<i2p::data::IdentHash, std::unique_ptr<I2PServerTunnel> > m_ServerTunnels; // destination->tunnel
SAMBridge * m_SamBridge; SAMBridge * m_SamBridge;
BOBCommandChannel * m_BOBCommandChannel; BOBCommandChannel * m_BOBCommandChannel;
I2PControlService * m_I2PControlService; I2PControlService * m_I2PControlService;

Loading…
Cancel
Save