From 9f6d1d713a1d26af6ac841ab3f1a1fad350aa941 Mon Sep 17 00:00:00 2001 From: Antonio Navarro Perez Date: Thu, 21 May 2020 18:44:57 +0200 Subject: [PATCH] Add peers and seeders on routes page. Signed-off-by: Antonio Navarro Perez --- torrent/assets/js/routes.js | 4 ++++ torrent/stats/torrent.go | 9 ++++++++- torrent/templates/routes.html | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/torrent/assets/js/routes.js b/torrent/assets/js/routes.js index 1f86427..5b17f06 100644 --- a/torrent/assets/js/routes.js +++ b/torrent/assets/js/routes.js @@ -20,8 +20,12 @@ function fetchData() { var download = torrentStat.downloadedBytes / torrentStat.timePassed; var upload = torrentStat.uploadedBytes / torrentStat.timePassed; + var seeders = torrentStat.seeders + var peers = torrentStat.peers document.getElementById("up-down-speed-text-" + torrentStat.hash).innerText = Humanize.bytes(download, 1024) + "/s down, " + Humanize.bytes(upload, 1024) + "/s up"; + document.getElementById("peers-seeders-" + torrentStat.hash).innerText = + peers + " peers, " + seeders + " seeders." }); }); diff --git a/torrent/stats/torrent.go b/torrent/stats/torrent.go index 87a8423..46d4754 100644 --- a/torrent/stats/torrent.go +++ b/torrent/stats/torrent.go @@ -30,6 +30,8 @@ type TorrentStats struct { Hash string `json:"hash"` DownloadedBytes int64 `json:"downloadedBytes"` UploadedBytes int64 `json:"uploadedBytes"` + Peers int `json:"peers"` + Seeders int `json:"seeders"` TimePassed float64 `json:"timePassed"` PieceChunks []*PieceChunk `json:"pieceChunks"` TotalPieces int `json:"totalPieces"` @@ -51,6 +53,8 @@ type stats struct { downloadBytes int64 totalUploadBytes int64 uploadBytes int64 + peers int + seeders int time time.Time } @@ -141,7 +145,6 @@ func (s *Torrent) stats(now time.Time, t *torrent.Torrent, chunks bool) *Torrent log.Println("Using previous stats") } else { st := t.Stats() - rd := st.BytesReadData.Int64() wd := st.BytesWrittenData.Int64() ist := &stats{ @@ -150,10 +153,14 @@ func (s *Torrent) stats(now time.Time, t *torrent.Torrent, chunks bool) *Torrent totalDownloadBytes: rd, totalUploadBytes: wd, time: now, + peers: st.TotalPeers, + seeders: st.ConnectedSeeders, } ts.DownloadedBytes = ist.downloadBytes ts.UploadedBytes = ist.uploadBytes + ts.Peers = ist.peers + ts.Seeders = ist.seeders s.previousStats[t.InfoHash().String()] = ist } diff --git a/torrent/templates/routes.html b/torrent/templates/routes.html index d9427fe..130b128 100644 --- a/torrent/templates/routes.html +++ b/torrent/templates/routes.html @@ -28,6 +28,8 @@

...

+

...

+