diff --git a/contrib/webconsole/torrent_client.html b/contrib/webconsole/torrent_client.html index 07c18991..b8da12df 100644 --- a/contrib/webconsole/torrent_client.html +++ b/contrib/webconsole/torrent_client.html @@ -380,7 +380,7 @@ tbody.innerHTML = ""; currentTorrentsData.forEach((el) => { - const percent = el.percentDone.toFixed(2) + const percent = (el.percentDone*100).toFixed(2) const speed = window.tjs.formatBytes ? window.tjs.formatBytes(el.rateDownload) : (el.rateDownload + ' B/s'); const speed_upload = window.tjs.formatBytes ? window.tjs.formatBytes(el.rateUpload) : (el.rateUpload + ' B/s'); const statusText = window.tjs.getStatusString ? window.tjs.getStatusString(el.status) : el.status; diff --git a/libi2pd_client/Torrents.h b/libi2pd_client/Torrents.h index 49ad79fe..5ba50a2e 100644 --- a/libi2pd_client/Torrents.h +++ b/libi2pd_client/Torrents.h @@ -364,6 +364,7 @@ namespace torrents auto& GetDiskIOService () { return m_DiskIOService.GetService (); }; const std::string& GetPeerID () const { return m_PeerID; } + const std::vector& GetTrackers () const { return m_Trackers; } std::shared_ptr FindTorrent (const Torrent::InfoHash& infoHash) const; std::shared_ptr FindTorrentByID (int id) const; std::vector GetTorrentIDs () const; diff --git a/libi2pd_client/TorrentsRPC.cpp b/libi2pd_client/TorrentsRPC.cpp index 5e2b87e8..8e48b669 100644 --- a/libi2pd_client/TorrentsRPC.cpp +++ b/libi2pd_client/TorrentsRPC.cpp @@ -7,7 +7,7 @@ */ #include -#if BOOST_VERSION >= 108100 // boost::json since 1.75, we allow it since 1.81 due to std::string_view compatibility +#if !defined(ANDROID) && (BOOST_VERSION >= 108100) // boost::json since 1.75, we allow it since 1.81 due to std::string_view compatibility #include #define JSON_SUPPORTED #endif @@ -47,7 +47,8 @@ namespace torrents std::string ErrorResponse (JSONRPCErrorCode errorCode, int64_t id, std::string_view message); int64_t GetTag (boost::json::object& jsonRequest) const; static boost::json::value GetFieldValue (std::string_view field, std::shared_ptr torrent); - boost::json::array GetPeers (std::shared_ptr torrent); + boost::json::array GetPeers (std::shared_ptr torrent) const; + boost::json::array GetTrackers (std::shared_ptr torrent) const; static std::string_view RecognizeClientByPeerID (const PeerConnection::PeerID& peerID); std::string HandleTorrentAdd (boost::json::object&& jsonRequest); @@ -225,6 +226,8 @@ namespace torrents continue; else if (field == "peers") t["peers"] = GetPeers (torrent); + else if (field == "trackers") + t["trackers"] = GetTrackers (torrent); else { auto fieldValue = GetFieldValue (field.as_string (), torrent); @@ -257,10 +260,8 @@ namespace torrents { "totalSize", [](std::shared_ptr torrent) { return boost::json::value(torrent->GetLength ()); } }, { "percentDone", [](std::shared_ptr torrent) { - if(!torrent->GetLength()) return boost::json::value ( 100.0 ); - double left = torrent->GetLength () - torrent->GetLeft(); - double percent = (left*100)/torrent->GetLength(); - return boost::json::value( percent ); + if (!torrent->GetLength ()) return boost::json::value (1.0); + return boost::json::value ((float)(torrent->GetLength () - torrent->GetLeft ())/(float)torrent->GetLength ()); } }, { "hashString", [](std::shared_ptr torrent) @@ -329,7 +330,12 @@ namespace torrents } }, { "error", [](std::shared_ptr torrent) { return boost::json::value(0); } }, // no error - { "eta", [](std::shared_ptr torrent) { return boost::json::value(600); } }, // TODO: + { "eta", [](std::shared_ptr torrent) + { + auto downloadRate = torrent->GetDownloadRate (); + return boost::json::value (downloadRate ? torrent->GetLeft ()/downloadRate : -2); + } + }, { "uploadRatio", [](std::shared_ptr torrent) { float ratio = torrent->GetDownloaded () ? ((float)torrent->GetUploaded ())/((float)torrent->GetDownloaded ()) : 100.0; @@ -346,7 +352,7 @@ namespace torrents return boost::json::value (); } - boost::json::array JSONRPCHandler::GetPeers (std::shared_ptr torrent) + boost::json::array JSONRPCHandler::GetPeers (std::shared_ptr torrent) const { boost::json::array peers; std::list > conns; @@ -386,6 +392,21 @@ namespace torrents return peers; } + boost::json::array JSONRPCHandler::GetTrackers (std::shared_ptr torrent) const + { + boost::json::array trackers; + const auto& tunnelTrackers = m_Tunnel->GetTrackers (); + for (size_t i = 0; i < tunnelTrackers.size (); i++) + { + boost::json::object tracker; + tracker["id"] = std::to_string (i); + tracker["announce"] = tunnelTrackers[i]; + tracker["tier"] = 0; + trackers.push_back (tracker); + } + return trackers; + } + std::string_view JSONRPCHandler::RecognizeClientByPeerID (const PeerConnection::PeerID& peerID) { static constexpr std::array i2psnark { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x03 };