mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
.ini file format for tunnel.cfg
This commit is contained in:
parent
5a31d2e817
commit
ea6597c3ad
|
@ -1,7 +1,5 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <boost/program_options/parsers.hpp>
|
|
||||||
#include <boost/program_options/variables_map.hpp>
|
|
||||||
#include <boost/property_tree/ptree.hpp>
|
#include <boost/property_tree/ptree.hpp>
|
||||||
#include <boost/property_tree/ini_parser.hpp>
|
#include <boost/property_tree/ini_parser.hpp>
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
@ -255,7 +253,7 @@ namespace client
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientContext::ReadTunnels ()
|
/*void ClientContext::ReadTunnels ()
|
||||||
{
|
{
|
||||||
std::ifstream ifs (i2p::util::filesystem::GetFullPath (TUNNELS_CONFIG_FILENAME));
|
std::ifstream ifs (i2p::util::filesystem::GetFullPath (TUNNELS_CONFIG_FILENAME));
|
||||||
if (ifs.good ())
|
if (ifs.good ())
|
||||||
|
@ -328,9 +326,9 @@ namespace client
|
||||||
LogPrint (eLogInfo, numServerTunnels, " I2P server tunnels created");
|
LogPrint (eLogInfo, numServerTunnels, " I2P server tunnels created");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
void ClientContext::ReadTunnels1 ()
|
void ClientContext::ReadTunnels ()
|
||||||
{
|
{
|
||||||
boost::property_tree::ptree pt;
|
boost::property_tree::ptree pt;
|
||||||
try
|
try
|
||||||
|
@ -346,16 +344,18 @@ namespace client
|
||||||
int numClientTunnels = 0, numServerTunnels = 0;
|
int numClientTunnels = 0, numServerTunnels = 0;
|
||||||
for (auto& section: pt)
|
for (auto& section: pt)
|
||||||
{
|
{
|
||||||
if (section.first == I2P_TUNNELS_SECTION_CLIENT)
|
std::string name = section.first;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
try
|
std::string type = section.second.get<std::string> (I2P_TUNNELS_SECTION_TYPE);
|
||||||
|
if (type == I2P_TUNNELS_SECTION_TYPE_CLIENT)
|
||||||
{
|
{
|
||||||
// mandatory params
|
// mandatory params
|
||||||
std::string dest = section.second.get<std::string> (I2P_CLIENT_TUNNEL_DESTINATION1);
|
std::string dest = section.second.get<std::string> (I2P_CLIENT_TUNNEL_DESTINATION);
|
||||||
int port = section.second.get<int> (I2P_CLIENT_TUNNEL_PORT1);
|
int port = section.second.get<int> (I2P_CLIENT_TUNNEL_PORT);
|
||||||
std::string keys = section.second.get<std::string> (I2P_CLIENT_TUNNEL_KEYS1);
|
std::string keys = section.second.get<std::string> (I2P_CLIENT_TUNNEL_KEYS);
|
||||||
// optional params
|
// optional params
|
||||||
//int destinationPort = section.second.get (I2P_CLIENT_TUNNEL_DESTINATION_PORT1, 0);
|
//int destinationPort = section.second.get (I2P_CLIENT_TUNNEL_DESTINATION_PORT, 0);
|
||||||
|
|
||||||
std::shared_ptr<ClientDestination> localDestination = nullptr;
|
std::shared_ptr<ClientDestination> localDestination = nullptr;
|
||||||
if (keys.length () > 0)
|
if (keys.length () > 0)
|
||||||
|
@ -367,17 +367,30 @@ namespace client
|
||||||
LogPrint (eLogError, "I2P client tunnel with port ", port, " already exists");
|
LogPrint (eLogError, "I2P client tunnel with port ", port, " already exists");
|
||||||
numClientTunnels++;
|
numClientTunnels++;
|
||||||
}
|
}
|
||||||
catch (std::exception& ex)
|
else if (type == I2P_TUNNELS_SECTION_TYPE_SERVER)
|
||||||
{
|
{
|
||||||
LogPrint (eLogError, "Can't read client tunnel params: ", ex.what ());
|
// mandatory params
|
||||||
|
std::string host = section.second.get<std::string> (I2P_SERVER_TUNNEL_HOST);
|
||||||
|
int port = section.second.get<int> (I2P_SERVER_TUNNEL_PORT);
|
||||||
|
std::string keys = section.second.get<std::string> (I2P_SERVER_TUNNEL_KEYS);
|
||||||
|
// optional params
|
||||||
|
|
||||||
|
auto localDestination = LoadLocalDestination (keys, true);
|
||||||
|
auto serverTunnel = new I2PServerTunnel (host, port, 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");
|
||||||
|
numServerTunnels++;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
LogPrint (eLogWarning, "Unknown section type=", type, " of ", name, " in ", TUNNELS_CONFIG_FILENAME);
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (section.first == I2P_TUNNELS_SECTION_SERVER)
|
catch (std::exception& ex)
|
||||||
{
|
{
|
||||||
numServerTunnels++;
|
LogPrint (eLogError, "Can't read tunnel ", name, " params: ", ex.what ());
|
||||||
}
|
}
|
||||||
else
|
|
||||||
LogPrint (eLogWarning, "Unknown section ", section.first, " in ", TUNNELS_CONFIG_FILENAME);
|
|
||||||
}
|
}
|
||||||
LogPrint (eLogInfo, numClientTunnels, " I2P client tunnels created");
|
LogPrint (eLogInfo, numClientTunnels, " I2P client tunnels created");
|
||||||
LogPrint (eLogInfo, numServerTunnels, " I2P server tunnels created");
|
LogPrint (eLogInfo, numServerTunnels, " I2P server tunnels created");
|
||||||
|
|
|
@ -17,21 +17,16 @@ namespace i2p
|
||||||
{
|
{
|
||||||
namespace client
|
namespace client
|
||||||
{
|
{
|
||||||
const char I2P_TUNNELS_SECTION_CLIENT[] = "client";
|
const char I2P_TUNNELS_SECTION_TYPE[] = "type";
|
||||||
const char I2P_TUNNELS_SECTION_SERVER[] = "server";
|
const char I2P_TUNNELS_SECTION_TYPE_CLIENT[] = "client";
|
||||||
const char I2P_CLIENT_TUNNEL_PORT1[] = "port";
|
const char I2P_TUNNELS_SECTION_TYPE_SERVER[] = "server";
|
||||||
const char I2P_CLIENT_TUNNEL_DESTINATION1[] = "destination";
|
const char I2P_CLIENT_TUNNEL_PORT[] = "port";
|
||||||
const char I2P_CLIENT_TUNNEL_KEYS1[] = "keys";
|
const char I2P_CLIENT_TUNNEL_DESTINATION[] = "destination";
|
||||||
const char I2P_CLIENT_TUNNEL_DESTINATION_PORT1[] = "destinationport";
|
const char I2P_CLIENT_TUNNEL_KEYS[] = "keys";
|
||||||
|
const char I2P_CLIENT_TUNNEL_DESTINATION_PORT[] = "destinationport";
|
||||||
const char I2P_CLIENT_TUNNEL_NAME[] = "client.name";
|
const char I2P_SERVER_TUNNEL_HOST[] = "host";
|
||||||
const char I2P_CLIENT_TUNNEL_PORT[] = "client.port";
|
const char I2P_SERVER_TUNNEL_PORT[] = "port";
|
||||||
const char I2P_CLIENT_TUNNEL_DESTINATION[] = "client.destination";
|
const char I2P_SERVER_TUNNEL_KEYS[] = "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 +54,6 @@ namespace client
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void ReadTunnels ();
|
void ReadTunnels ();
|
||||||
void ReadTunnels1 (); // using propery tree
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue