torrent-reannounce RPC method

This commit is contained in:
orignal
2026-10-03 21:36:16 -04:00
parent a11971809c
commit 466e99fa55
3 changed files with 40 additions and 3 deletions
+13 -1
View File
@@ -66,6 +66,7 @@ namespace torrents
std::string HandleSessionGet (boost::json::object&& jsonRequest); // for transmission-rpc library
std::string HandleSessionStats (boost::json::object&& jsonRequest);
std::string HandleTorrentSet (boost::json::object&& jsonRequest);
std::string HandleTorrentReannounce (boost::json::object&& jsonRequest);
private:
@@ -123,7 +124,8 @@ namespace torrents
{ "torrent-start", &JSONRPCHandler::HandleTorrentStart },
{ "session-get", &JSONRPCHandler::HandleSessionGet },
{ "session-stats", &JSONRPCHandler::HandleSessionStats },
{ "torrent-set", &JSONRPCHandler::HandleTorrentSet }
{ "torrent-set", &JSONRPCHandler::HandleTorrentSet },
{ "torrent-reannounce", &JSONRPCHandler::HandleTorrentReannounce }
};
try
@@ -213,6 +215,16 @@ namespace torrents
return SuccessResponse (GetTag (jsonRequest), std::move (response));
}
std::string JSONRPCHandler::HandleTorrentReannounce (boost::json::object&& jsonRequest)
{
auto arguments = jsonRequest.at ("arguments").as_object ();
auto torrentIds = GetTorrentIds (arguments);
for (auto id: torrentIds)
m_Tunnel->ReannounceTorrent (id);
boost::json::object response; // always empty
return SuccessResponse (GetTag (jsonRequest), std::move (response));
}
std::string JSONRPCHandler::HandleTorrentGet (boost::json::object&& jsonRequest)
{
auto arguments = jsonRequest.at ("arguments").as_object ();
+26 -2
View File
@@ -453,12 +453,18 @@ namespace torrents
void TorrentsTunnel::RemoveAllTorrents (bool deleteFiles)
{
boost::asio::post (GetService (), [this, deleteFiles]()
std::list<std::shared_ptr<Torrent> > torrentsToRemove;
{
std::lock_guard<std::mutex> l(m_TorrentsMutex);
for (const auto& it: m_Torrents)
RemoveTorrent (it.second, deleteFiles);
torrentsToRemove.push_back (it.second);
m_Torrents.clear ();
m_TorrentsByID.clear ();
}
boost::asio::post (GetService (), [this, torrentsToRemove = std::move (torrentsToRemove), deleteFiles]()
{
for (auto it: torrentsToRemove)
RemoveTorrent (it, deleteFiles);
});
}
@@ -564,6 +570,24 @@ namespace torrents
return true;
}
bool TorrentsTunnel::ReannounceTorrent (int id)
{
std::shared_ptr<Torrent> torrent;
{
std::lock_guard<std::mutex> l(m_TorrentsMutex);
auto it = m_TorrentsByID.find (id);
if (it == m_TorrentsByID.end ()) return false;
torrent = it->second.lock ();
}
if (!torrent) return false;
boost::asio::post (GetService (), [this, torrent]()
{
RequestTorrentTrackers (torrent, eTrackerAnnounceEventNone);
if (m_DHT) m_DHT->GetPeersAndAnnounce (torrent);
});
return true;
}
void TorrentsTunnel::UpdateTorrentInfo (std::shared_ptr<Torrent> torrent, std::string_view info)
{
if (!torrent || torrent->IsStopped ()) return;
+1
View File
@@ -113,6 +113,7 @@ namespace torrents
void RemoveAllTorrents (bool deleteFiles);
bool StopTorrent (int id);
bool StartTorrent (int id);
bool ReannounceTorrent (int id);
void ConnectToNewPeers (std::shared_ptr<Torrent> torrent, std::unordered_set<i2p::data::IdentHash>& newPeers, PeerConnectionOrigin origin);
void SendDHTPingQuery (const i2p::data::IdentHash& toIdent, uint16_t toPort);
std::pair<uint16_t, uint16_t> GetDHTPorts () const { return { m_DHT ? m_DHT->GetPort () : 0, m_DHT ? m_DHT->GetRPort () : 0 }; }