Documentation
¶
Index ¶
- func InitDownloader()
- func MonitorBuiltin(recv, send chan MonitoredTorrent, ctx context.Context, ...)
- type Downloader
- type DownloaderConfig
- type FileName
- type FileOption
- type HttpUrlSeeker
- type MonitoredTorrent
- type TorrentInfo
- type TorrentProgress
- type TorrentProgressList
- type TorrentProgressListSend
- type TorrentProgressMonitor
- type TorrentSeeker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitDownloader ¶
func InitDownloader()
func MonitorBuiltin ¶
func MonitorBuiltin(recv, send chan MonitoredTorrent, ctx context.Context, monitor *TorrentProgressMonitor)
MonitorBuiltin monitors torrents and handles their state transitions. It listens for incoming MonitoredTorrent objects on the recv channel, processes them, and sends updated MonitoredTorrent objects on the send channel. The function also listens for context cancellation to gracefully exit.
Parameters: - recv: a channel from which MonitoredTorrent objects are received. - send: a channel to which updated MonitoredTorrent objects are sent. - ctx: a context to handle cancellation and timeout.
The function uses reflection to dynamically select from multiple channels and manage the state of each torrent. It tracks torrent states in a map and updates their status based on events such as receiving torrent info or completing the download.
Types ¶
type Downloader ¶
type Downloader struct {
TorrentSeeker
// contains filtered or unexported fields
}
var DefaultDownLoader *Downloader
func NewDownloader ¶
func NewDownloader(c *DownloaderConfig) *Downloader
func (*Downloader) Download ¶
func (d *Downloader) Download(s string, fOp FileOption, seeker TorrentSeeker) (t *torrent.Torrent, err error)
type DownloaderConfig ¶
type DownloaderConfig struct {
BaseDir string
Seeker TorrentSeeker
NopUpload bool
FakePeerID bool
}
type FileName ¶
type FileName interface {
Name() storage.FilePathMaker
}
type FileOption ¶
type FileOption interface {
FileName
Dir() storage.TorrentDirFilePathMaker
}
type HttpUrlSeeker ¶
func NewHttpSeeker ¶
func NewHttpSeeker() *HttpUrlSeeker
func (*HttpUrlSeeker) Seek ¶
func (hr *HttpUrlSeeker) Seek(n string) (*torrent.TorrentSpec, error)
type MonitoredTorrent ¶
type MonitoredTorrent struct {
TorrentInfo
Size int64
Url string
}
type TorrentInfo ¶
type TorrentProgress ¶
type TorrentProgressList ¶
type TorrentProgressList struct {
// contains filtered or unexported fields
}
func (*TorrentProgressList) Fin ¶
func (l *TorrentProgressList) Fin() bool
func (*TorrentProgressList) Get ¶
func (l *TorrentProgressList) Get() []TorrentProgress
func (*TorrentProgressList) Put ¶
func (l *TorrentProgressList) Put(dirty []TorrentProgress)
type TorrentProgressListSend ¶
type TorrentProgressListSend struct {
List []TorrentProgress `json:"list"`
Fin bool `json:"fin"`
}
type TorrentProgressMonitor ¶
type TorrentProgressMonitor struct {
// contains filtered or unexported fields
}
func NewTorrentProgressMonitor ¶
func NewTorrentProgressMonitor(ttl time.Duration) *TorrentProgressMonitor
func (*TorrentProgressMonitor) AddTorrent ¶
func (tm *TorrentProgressMonitor) AddTorrent(t TorrentInfo)
func (*TorrentProgressMonitor) GetProgressList ¶
func (tm *TorrentProgressMonitor) GetProgressList() []TorrentProgress
type TorrentSeeker ¶
type TorrentSeeker interface {
Seek(n string) (*torrent.TorrentSpec, error)
}