-
Notifications
You must be signed in to change notification settings - Fork 75
/
webseedsource.go
44 lines (38 loc) · 1.09 KB
/
webseedsource.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package webseedsource
import (
"time"
"github.com/cenkalti/rain/internal/urldownloader"
"github.com/rcrowley/go-metrics"
)
// WebseedSource is a URL for downloading torrent data from web sources.
type WebseedSource struct {
URL string
Disabled bool
Downloader *urldownloader.URLDownloader
LastError error
DisabledAt time.Time
DownloadSpeed metrics.Meter
}
// NewList returns a new WebseedSource list.
func NewList(sources []string) []*WebseedSource {
l := make([]*WebseedSource, len(sources))
for i := range sources {
l[i] = &WebseedSource{
URL: sources[i],
DownloadSpeed: metrics.NilMeter{},
}
}
return l
}
// Downloading returns true if data is being downloaded from this source.
func (s *WebseedSource) Downloading() bool {
return s.Downloader != nil
}
// Remaining returns the number of pieces that is going to be downloaded by this source.
// If there is a piece currently downloading, it is not counted.
func (s *WebseedSource) Remaining() uint32 {
if s.Downloader == nil {
return 0
}
return s.Downloader.End - s.Downloader.ReadCurrent() - 1
}