Skip to content

Commit

Permalink
feat: add download stats info (GopeedLab#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGlp authored Jan 17, 2024
1 parent cc0f61b commit 99f4e8c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/fetcher/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions internal/protocol/bt/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func (f *Fetcher) Start() (err error) {
file.Download()
}
}

return
}

Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions internal/protocol/http/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions pkg/protocol/bt/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
6 changes: 6 additions & 0 deletions pkg/protocol/http/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 99f4e8c

Please sign in to comment.