diff --git a/internal/fetcher/fetcher.go b/internal/fetcher/fetcher.go index f8bd64c01..22afb5208 100644 --- a/internal/fetcher/fetcher.go +++ b/internal/fetcher/fetcher.go @@ -21,6 +21,8 @@ type Fetcher interface { Pause() error Close() error + // Stats refreshes health statistics and returns the latest information + Stats() any // Meta returns the meta information of the download. Meta() *FetcherMeta // Progress returns the progress of the download. diff --git a/internal/protocol/bt/fetcher.go b/internal/protocol/bt/fetcher.go index 240e2f087..5c17a223d 100644 --- a/internal/protocol/bt/fetcher.go +++ b/internal/protocol/bt/fetcher.go @@ -128,6 +128,7 @@ func (f *Fetcher) Start() (err error) { file.Download() } } + return } @@ -188,6 +189,16 @@ func (f *Fetcher) Meta() *fetcher.FetcherMeta { return f.meta } +func (f *Fetcher) Stats() any { + stats := f.torrent.Stats() + baseStats := &bt.Stats{ + TotalPeers: stats.TotalPeers, + ActivePeers: stats.ActivePeers, + ConnectedSeeders: stats.ConnectedSeeders, + } + return baseStats +} + func (f *Fetcher) Progress() fetcher.Progress { if !f.torrentReady.Load() { return f.progress diff --git a/internal/protocol/http/fetcher.go b/internal/protocol/http/fetcher.go index 8f7d03ed2..0e20ef44e 100644 --- a/internal/protocol/http/fetcher.go +++ b/internal/protocol/http/fetcher.go @@ -218,6 +218,11 @@ func (f *Fetcher) Meta() *fetcher.FetcherMeta { return f.meta } +func (f *Fetcher) Stats() any { + // todo http download health + return &fhttp.Stats{} +} + func (f *Fetcher) Progress() fetcher.Progress { p := make(fetcher.Progress, 0) if len(f.chunks) > 0 { diff --git a/pkg/protocol/bt/model.go b/pkg/protocol/bt/model.go index 5296d515b..b9ec54498 100644 --- a/pkg/protocol/bt/model.go +++ b/pkg/protocol/bt/model.go @@ -3,3 +3,12 @@ package bt type ReqExtra struct { Trackers []string `json:"trackers"` } + +// Stats for download +type Stats struct { + // bt stats + // health indicators of torrents, from large to small, ConnectedSeeders are also the key to the health of seed resources + TotalPeers int `json:"totalPeers"` + ActivePeers int `json:"activePeers"` + ConnectedSeeders int `json:"connectedSeeders"` +} diff --git a/pkg/protocol/http/model.go b/pkg/protocol/http/model.go index 726a0d086..94f1a4a12 100644 --- a/pkg/protocol/http/model.go +++ b/pkg/protocol/http/model.go @@ -9,3 +9,9 @@ type ReqExtra struct { type OptsExtra struct { Connections int `json:"connections"` } + +// Stats for download +type Stats struct { + // http stats + // health indicators of http +}