mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-10 20:47:53 +00:00
* i2p::fs migration: ClientContext, Destination, HTTPServer, Reseed, RouterContext
This commit is contained in:
parent
ddd8d4aeb2
commit
79bf44b3f5
@ -3,7 +3,7 @@
|
|||||||
#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 "Config.h"
|
#include "Config.h"
|
||||||
#include "util.h"
|
#include "FS.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "Identity.h"
|
#include "Identity.h"
|
||||||
#include "ClientContext.h"
|
#include "ClientContext.h"
|
||||||
@ -152,10 +152,10 @@ namespace client
|
|||||||
m_SharedLocalDestination = nullptr;
|
m_SharedLocalDestination = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientContext::LoadPrivateKeys (i2p::data::PrivateKeys& keys, const std::string& filename, i2p::data::SigningKeyType sigType)
|
void ClientContext::LoadPrivateKeys (i2p::data::PrivateKeys& keys, const std::string& filename, i2p::data::SigningKeyType sigType)
|
||||||
{
|
{
|
||||||
std::string fullPath = i2p::util::filesystem::GetFullPath (filename);
|
std::string fullPath = i2p::fs::DataDirPath (filename);
|
||||||
std::ifstream s(fullPath.c_str (), std::ifstream::binary);
|
std::ifstream s(fullPath, std::ifstream::binary);
|
||||||
if (s.is_open ())
|
if (s.is_open ())
|
||||||
{
|
{
|
||||||
s.seekg (0, std::ios::end);
|
s.seekg (0, std::ios::end);
|
||||||
@ -256,14 +256,14 @@ namespace client
|
|||||||
void ClientContext::ReadTunnels ()
|
void ClientContext::ReadTunnels ()
|
||||||
{
|
{
|
||||||
boost::property_tree::ptree pt;
|
boost::property_tree::ptree pt;
|
||||||
std::string pathTunnelsConfigFile = i2p::util::filesystem::GetTunnelsConfigFile().string();
|
std::string pathTunConf;
|
||||||
try
|
i2p::config::GetOption("tunconf", pathTunConf);
|
||||||
{
|
if (pathTunConf == "")
|
||||||
boost::property_tree::read_ini (pathTunnelsConfigFile, pt);
|
return;
|
||||||
}
|
try {
|
||||||
catch (std::exception& ex)
|
boost::property_tree::read_ini (pathTunConf, pt);
|
||||||
{
|
} catch (std::exception& ex) {
|
||||||
LogPrint (eLogWarning, "Clients: Can't read ", pathTunnelsConfigFile, ": ", ex.what ());
|
LogPrint (eLogWarning, "Clients: Can't read ", pathTunConf, ": ", ex.what ());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,7 +351,7 @@ namespace client
|
|||||||
numServerTunnels++;
|
numServerTunnels++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
LogPrint (eLogWarning, "Clients: Unknown section type=", type, " of ", name, " in ", pathTunnelsConfigFile);
|
LogPrint (eLogWarning, "Clients: Unknown section type=", type, " of ", name, " in ", pathTunConf);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (std::exception& ex)
|
catch (std::exception& ex)
|
||||||
|
@ -2,8 +2,9 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
#include <openssl/rand.h>
|
#include <openssl/rand.h>
|
||||||
|
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "util.h"
|
#include "FS.h"
|
||||||
#include "Crypto.h"
|
#include "Crypto.h"
|
||||||
#include "Timestamp.h"
|
#include "Timestamp.h"
|
||||||
#include "NetDb.h"
|
#include "NetDb.h"
|
||||||
@ -690,30 +691,26 @@ namespace client
|
|||||||
|
|
||||||
void ClientDestination::PersistTemporaryKeys ()
|
void ClientDestination::PersistTemporaryKeys ()
|
||||||
{
|
{
|
||||||
auto path = i2p::util::filesystem::GetDefaultDataDir() / "destinations";
|
std::string ident = GetIdentHash().ToBase32();
|
||||||
auto filename = path / (GetIdentHash ().ToBase32 () + ".dat");
|
std::string path = i2p::fs::DataDirPath("destinations", (ident + ".dat"));
|
||||||
std::ifstream f(filename.string (), std::ifstream::binary);
|
std::ifstream f(path, std::ifstream::binary);
|
||||||
if (f)
|
|
||||||
{
|
if (f) {
|
||||||
f.read ((char *)m_EncryptionPublicKey, 256);
|
f.read ((char *)m_EncryptionPublicKey, 256);
|
||||||
f.read ((char *)m_EncryptionPrivateKey, 256);
|
f.read ((char *)m_EncryptionPrivateKey, 256);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (!f)
|
|
||||||
{
|
LogPrint (eLogInfo, "Destination: Creating new temporary keys for address ", ident, ".b32.i2p");
|
||||||
LogPrint (eLogInfo, "Creating new temporary keys for address ", GetIdentHash ().ToBase32 ());
|
i2p::crypto::GenerateElGamalKeyPair(m_EncryptionPrivateKey, m_EncryptionPublicKey);
|
||||||
i2p::crypto::GenerateElGamalKeyPair(m_EncryptionPrivateKey, m_EncryptionPublicKey);
|
|
||||||
if (!boost::filesystem::exists (path))
|
std::ofstream f1 (path, std::ofstream::binary | std::ofstream::out);
|
||||||
{
|
if (f1) {
|
||||||
if (!boost::filesystem::create_directory (path))
|
f1.write ((char *)m_EncryptionPublicKey, 256);
|
||||||
LogPrint (eLogError, "Failed to create destinations directory");
|
f1.write ((char *)m_EncryptionPrivateKey, 256);
|
||||||
}
|
return;
|
||||||
std::ofstream f1 (filename.string (), std::ofstream::binary | std::ofstream::out);
|
}
|
||||||
if (f1)
|
LogPrint(eLogError, "Destinations: Can't save keys to ", path);
|
||||||
{
|
|
||||||
f1.write ((char *)m_EncryptionPublicKey, 256);
|
|
||||||
f1.write ((char *)m_EncryptionPrivateKey, 256);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||||
#include "Base.h"
|
#include "Base.h"
|
||||||
|
#include "FS.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "Tunnel.h"
|
#include "Tunnel.h"
|
||||||
#include "TransitTunnel.h"
|
#include "TransitTunnel.h"
|
||||||
@ -420,7 +421,7 @@ namespace util
|
|||||||
s << " (" << i2p::transport::transports.GetInBandwidth () <<" Bps)<br>\r\n";
|
s << " (" << i2p::transport::transports.GetInBandwidth () <<" Bps)<br>\r\n";
|
||||||
s << "<b>Sent:</b> " << i2p::transport::transports.GetTotalSentBytes ()/1000 << "K";
|
s << "<b>Sent:</b> " << i2p::transport::transports.GetTotalSentBytes ()/1000 << "K";
|
||||||
s << " (" << i2p::transport::transports.GetOutBandwidth () <<" Bps)<br>\r\n";
|
s << " (" << i2p::transport::transports.GetOutBandwidth () <<" Bps)<br>\r\n";
|
||||||
s << "<b>Data path:</b> " << i2p::util::filesystem::GetDataDir().string() << "<br>\r\n<br>\r\n";
|
s << "<b>Data path:</b> " << i2p::fs::GetDataDir() << "<br>\r\n<br>\r\n";
|
||||||
s << "<b>Our external address:</b>" << "<br>\r\n" ;
|
s << "<b>Our external address:</b>" << "<br>\r\n" ;
|
||||||
for (auto& address : i2p::context.GetRouterInfo().GetAddresses())
|
for (auto& address : i2p::context.GetRouterInfo().GetAddresses())
|
||||||
{
|
{
|
||||||
|
30
Reseed.cpp
30
Reseed.cpp
@ -2,15 +2,16 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <boost/regex.hpp>
|
#include <boost/regex.hpp>
|
||||||
#include <boost/filesystem.hpp>
|
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
#include <boost/asio/ssl.hpp>
|
#include <boost/asio/ssl.hpp>
|
||||||
#include <openssl/bn.h>
|
#include <openssl/bn.h>
|
||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
#include <openssl/err.h>
|
#include <openssl/err.h>
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
|
||||||
#include "I2PEndian.h"
|
#include "I2PEndian.h"
|
||||||
#include "Reseed.h"
|
#include "Reseed.h"
|
||||||
|
#include "FS.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "Identity.h"
|
#include "Identity.h"
|
||||||
#include "Crypto.h"
|
#include "Crypto.h"
|
||||||
@ -346,23 +347,22 @@ namespace data
|
|||||||
|
|
||||||
void Reseeder::LoadCertificates ()
|
void Reseeder::LoadCertificates ()
|
||||||
{
|
{
|
||||||
boost::filesystem::path reseedDir = i2p::util::filesystem::GetCertificatesDir() / "reseed";
|
std::string certDir = i2p::fs::DataDirPath("certificates", "reseed");
|
||||||
|
std::vector<std::string> files;
|
||||||
if (!boost::filesystem::exists (reseedDir))
|
int numCertificates = 0;
|
||||||
{
|
|
||||||
LogPrint (eLogWarning, "Reseed: certificates not loaded, ", reseedDir, " doesn't exist");
|
if (!i2p::fs::ReadDir(certDir, files)) {
|
||||||
|
LogPrint(eLogWarning, "Reseed: Can't load reseed certificates from ", certDir);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int numCertificates = 0;
|
for (const std::string & file : files) {
|
||||||
boost::filesystem::directory_iterator end; // empty
|
if (file.compare(file.size() - 4, 4, ".crt") != 0) {
|
||||||
for (boost::filesystem::directory_iterator it (reseedDir); it != end; ++it)
|
LogPrint(eLogWarning, "Reseed: ignoring file ", file);
|
||||||
{
|
continue;
|
||||||
if (boost::filesystem::is_regular_file (it->status()) && it->path ().extension () == ".crt")
|
}
|
||||||
{
|
LoadCertificate (file);
|
||||||
LoadCertificate (it->path ().string ());
|
numCertificates++;
|
||||||
numCertificates++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
LogPrint (eLogInfo, "Reseed: ", numCertificates, " certificates loaded");
|
LogPrint (eLogInfo, "Reseed: ", numCertificates, " certificates loaded");
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include "Timestamp.h"
|
#include "Timestamp.h"
|
||||||
#include "I2NPProtocol.h"
|
#include "I2NPProtocol.h"
|
||||||
#include "NetDb.h"
|
#include "NetDb.h"
|
||||||
|
#include "FS.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
@ -64,7 +65,7 @@ namespace i2p
|
|||||||
void RouterContext::UpdateRouterInfo ()
|
void RouterContext::UpdateRouterInfo ()
|
||||||
{
|
{
|
||||||
m_RouterInfo.CreateBuffer (m_Keys);
|
m_RouterInfo.CreateBuffer (m_Keys);
|
||||||
m_RouterInfo.SaveToFile (i2p::util::filesystem::GetFullPath (ROUTER_INFO));
|
m_RouterInfo.SaveToFile (i2p::fs::DataDirPath (ROUTER_INFO));
|
||||||
m_LastUpdateTime = i2p::util::GetSecondsSinceEpoch ();
|
m_LastUpdateTime = i2p::util::GetSecondsSinceEpoch ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,7 +293,7 @@ namespace i2p
|
|||||||
|
|
||||||
bool RouterContext::Load ()
|
bool RouterContext::Load ()
|
||||||
{
|
{
|
||||||
std::ifstream fk (i2p::util::filesystem::GetFullPath (ROUTER_KEYS).c_str (), std::ifstream::binary | std::ifstream::in);
|
std::ifstream fk (i2p::fs::DataDirPath (ROUTER_KEYS), std::ifstream::in | std::ifstream::binary);
|
||||||
if (!fk.is_open ()) return false;
|
if (!fk.is_open ()) return false;
|
||||||
fk.seekg (0, std::ios::end);
|
fk.seekg (0, std::ios::end);
|
||||||
size_t len = fk.tellg();
|
size_t len = fk.tellg();
|
||||||
@ -312,7 +313,7 @@ namespace i2p
|
|||||||
delete[] buf;
|
delete[] buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
i2p::data::RouterInfo routerInfo(i2p::util::filesystem::GetFullPath (ROUTER_INFO)); // TODO
|
i2p::data::RouterInfo routerInfo(i2p::fs::DataDirPath (ROUTER_INFO)); // TODO
|
||||||
m_RouterInfo.SetRouterIdentity (GetIdentity ());
|
m_RouterInfo.SetRouterIdentity (GetIdentity ());
|
||||||
m_RouterInfo.Update (routerInfo.GetBuffer (), routerInfo.GetBufferLen ());
|
m_RouterInfo.Update (routerInfo.GetBuffer (), routerInfo.GetBufferLen ());
|
||||||
m_RouterInfo.SetProperty ("coreVersion", I2P_VERSION);
|
m_RouterInfo.SetProperty ("coreVersion", I2P_VERSION);
|
||||||
@ -331,7 +332,7 @@ namespace i2p
|
|||||||
void RouterContext::SaveKeys ()
|
void RouterContext::SaveKeys ()
|
||||||
{
|
{
|
||||||
// save in the same format as .dat files
|
// save in the same format as .dat files
|
||||||
std::ofstream fk (i2p::util::filesystem::GetFullPath (ROUTER_KEYS).c_str (), std::ofstream::binary | std::ofstream::out);
|
std::ofstream fk (i2p::fs::DataDirPath (ROUTER_KEYS), std::ofstream::binary | std::ofstream::out);
|
||||||
size_t len = m_Keys.GetFullLen ();
|
size_t len = m_Keys.GetFullLen ();
|
||||||
uint8_t * buf = new uint8_t[len];
|
uint8_t * buf = new uint8_t[len];
|
||||||
m_Keys.ToBuffer (buf, len);
|
m_Keys.ToBuffer (buf, len);
|
||||||
|
Loading…
Reference in New Issue
Block a user