dhtfile param

This commit is contained in:
orignal
2026-10-15 18:58:35 -04:00
parent a3b87ab809
commit 3988b898c4
6 changed files with 21 additions and 26 deletions
+2 -1
View File
@@ -1048,6 +1048,7 @@ namespace client
i2p::data::SigningKeyType sigType = section.second.get (TORRENTS_TUNNEL_SIGNATURE_TYPE, i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519);
if (sigType > i2p::data::SIGNING_KEY_TYPE_REDDSA_SHA512_ED25519) sigType = i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519;
bool dht = section.second.get<bool> (TORRENTS_TUNNEL_DHT, true);
std::string dhtFileName = section.second.get<std::string> (TORRENTS_TUNNEL_DHT_FILE, "");
bool web = section.second.get<bool> (TORRENTS_TUNNEL_WEB, true);
// I2CP
@@ -1080,7 +1081,7 @@ namespace client
localDestination->SetPublic (true);
}
auto torrentsTunnel = std::make_shared<i2p::torrents::TorrentsTunnel> (name,
localDestination, torrentsDir, trackers, dht, web);
localDestination, torrentsDir, trackers, dht, dhtFileName, web);
auto [iit, inserted] = m_TorrentsTunnels.emplace (localDestination->GetIdentHash (), torrentsTunnel);
if (inserted)
{
+1
View File
@@ -85,6 +85,7 @@ namespace client
const char TORRENTS_TUNNEL_RPC_USER[] = "rpcuser";
const char TORRENTS_TUNNEL_RPC_PASS[] = "rpcpass";
const char TORRENTS_TUNNEL_DHT[] = "dht";
const char TORRENTS_TUNNEL_DHT_FILE[] = "dhtfile";
const char TORRENTS_TUNNEL_WEB[] = "web";
constexpr int STOP_DESTINATIONS_TIMEOUT = 8; // in seconds
+10 -19
View File
@@ -316,11 +316,10 @@ namespace torrents
return node;
}
TorrentsDHT::TorrentsDHT (TorrentsTunnel& tunnel, uint16_t port):
m_Tunnel (tunnel), m_DHTUpdateCheckTimer (tunnel.GetService ()),
m_DHTExpirationCheckTimer (tunnel.GetService ()),
m_DHTSendPingCheckTimer (tunnel.GetService ()),
m_DHTQueryExpirationCheckTimer (tunnel.GetService ()), m_Port (port),
TorrentsDHT::TorrentsDHT (TorrentsTunnel& tunnel, uint16_t port, std::string_view dhtFileName):
m_Tunnel (tunnel), m_Port (port), m_DHTFileName (dhtFileName),
m_DHTUpdateCheckTimer (tunnel.GetService ()), m_DHTExpirationCheckTimer (tunnel.GetService ()),
m_DHTSendPingCheckTimer (tunnel.GetService ()), m_DHTQueryExpirationCheckTimer (tunnel.GetService ()),
m_NextDHTExploratoryTime (i2p::util::GetMonotonicSeconds () + DHT_INITIAL_EXPLORATORY_INTERVAL)
{
auto dest = tunnel.GetLocalDestination ();
@@ -338,16 +337,17 @@ namespace torrents
void TorrentsDHT::Start ()
{
std::string filename ("nodest");
auto dest = m_Tunnel.GetLocalDestination ();
if (dest)
{
auto dgramDest = dest->GetDatagramDestination ();
if (dgramDest)
dgramDest->SetReceiver (std::bind_front (&TorrentsDHT::HandleDatagram, this));
filename = dest->GetIdentHash ().ToBase32 ();
if (m_DHTFileName.empty ())
m_DHTFileName = dest->GetIdentHash ().ToBase32 () + ".dht";
}
Load (GetDHTFilePath (filename));
if (m_DHTFileName.empty ()) m_DHTFileName = "nodest.dht";
Load (GetDHTFilePath (m_DHTFileName));
ScheduleDHTUpdateCheck ();
ScheduleDHTExpirationCheck ();
ScheduleDHTSendPingCheck ();
@@ -360,16 +360,7 @@ namespace torrents
m_DHTExpirationCheckTimer.cancel ();
m_DHTSendPingCheckTimer.cancel ();
m_DHTQueryExpirationCheckTimer.cancel ();
std::string filename ("nodest");
auto dest = m_Tunnel.GetLocalDestination ();
if (dest)
{
auto dgramDest = dest->GetDatagramDestination ();
if (dgramDest)
dgramDest->ResetReceiver ();
filename = dest->GetIdentHash ().ToBase32 ();
}
Save (GetDHTFilePath (filename));
Save (GetDHTFilePath (m_DHTFileName));
}
std::filesystem::path TorrentsDHT::GetDHTFilePath (std::string_view filename) const
@@ -377,7 +368,7 @@ namespace torrents
std::filesystem::path dhtFilePath (i2p::fs::GetDataDir()); dhtFilePath /= "torrents";
if (!std::filesystem::exists (dhtFilePath))
std::filesystem::create_directories (dhtFilePath);
dhtFilePath /= filename; dhtFilePath += ".dht";
dhtFilePath /= filename;
return dhtFilePath;
}
+4 -3
View File
@@ -222,7 +222,7 @@ namespace torrents
{
public:
TorrentsDHT (TorrentsTunnel& tunnel, uint16_t port);
TorrentsDHT (TorrentsTunnel& tunnel, uint16_t port, std::string_view dhtFileName);
void Start ();
void Stop ();
@@ -299,10 +299,11 @@ namespace torrents
private:
TorrentsTunnel& m_Tunnel;
uint16_t m_Port;
std::string m_DHTFileName;
NodeID m_NodeID;
boost::asio::steady_timer m_DHTUpdateCheckTimer, m_DHTExpirationCheckTimer,
m_DHTSendPingCheckTimer, m_DHTQueryExpirationCheckTimer;
uint16_t m_Port;
NodeID m_NodeID;
std::unique_ptr<RoutingTable> m_RoutingTable;
std::map<NodeID, uint64_t> m_HeardFrom; // nodeid -> time in monotonic seconds
std::unordered_map<i2p::data::IdentHash, uint64_t> m_FailedPeers; // peer -> failure time in monotonic seconds
+2 -2
View File
@@ -25,7 +25,7 @@ namespace i2p
namespace torrents
{
TorrentsTunnel::TorrentsTunnel (std::string_view name, std::shared_ptr<i2p::client::ClientDestination> localDestination,
std::string_view torrentsDir, std::string_view trackers, bool dht, bool web):
std::string_view torrentsDir, std::string_view trackers, bool dht, std::string_view dhtFileName, bool web):
i2p::client::I2PService (localDestination), m_Name (name), m_PeerID ("-I2PD-"),
m_TorrentsDir (torrentsDir), m_TrackerRequestsCheckTimer (GetService ()),
m_KeepAliveCheckTimer (GetService ()), m_ReconnectCheckTimer (GetService ()),
@@ -59,7 +59,7 @@ namespace torrents
m_Trackers.emplace_back (TrackerInfo{ it.second, true, 0, 0, 0 });
}
if (dht)
m_DHT = std::make_unique<TorrentsDHT>(*this, TORRENT_PORT + (localDestination ? localDestination->GetRng()() % (65535 - TORRENT_PORT - 1) : 1));
m_DHT = std::make_unique<TorrentsDHT>(*this, TORRENT_PORT + (localDestination ? localDestination->GetRng()() % (65535 - TORRENT_PORT - 1) : 1), dhtFileName);
}
void TorrentsTunnel::Start ()
+2 -1
View File
@@ -91,7 +91,8 @@ namespace torrents
public:
TorrentsTunnel (std::string_view name, std::shared_ptr<i2p::client::ClientDestination> localDestination,
std::string_view torrentsDir, std::string_view trackers = "", bool dht = true, bool web = true);
std::string_view torrentsDir, std::string_view trackers = "", bool dht = true, std::string_view dhtFileName = "",
bool web = true);
void Start () override;
void Stop () override;