Clarity
Cette révision appartient à :
Parent
99ad76f76f
révision
21977ff406
4 fichiers modifiés avec 33 ajouts et 26 suppressions
|
@ -69,8 +69,9 @@ metainfo_fetcher:
|
||||||
base_fail_cooldown: 1800
|
base_fail_cooldown: 1800
|
||||||
max_fail_cooldown: 172800
|
max_fail_cooldown: 172800
|
||||||
wake_up_interval: 300
|
wake_up_interval: 300
|
||||||
upload_rate_limiter: 1024
|
# limits are in KiB, zero means no limit
|
||||||
download_rate_limiter: 1024
|
upload_rate_limit: 1024
|
||||||
|
download_rate_limit: 1024
|
||||||
fetch_new_torrents_only: true
|
fetch_new_torrents_only: true
|
||||||
i18n:
|
i18n:
|
||||||
# Default configuration for translation directory
|
# Default configuration for translation directory
|
||||||
|
|
|
@ -136,8 +136,8 @@ type MetainfoFetcherConfig struct {
|
||||||
MaxFailCooldown int `json:"max_fail_cooldown" yaml:"max_fail_cooldown,omitempty"`
|
MaxFailCooldown int `json:"max_fail_cooldown" yaml:"max_fail_cooldown,omitempty"`
|
||||||
WakeUpInterval int `json:"wake_up_interval" yaml:"wake_up_interval,omitempty"`
|
WakeUpInterval int `json:"wake_up_interval" yaml:"wake_up_interval,omitempty"`
|
||||||
|
|
||||||
UploadRateLimiter int `json:"upload_rate_limiter" yaml:"upload_rate_limiter,omitempty"`
|
UploadRateLimitKiB int `json:"upload_rate_limit" yaml:"upload_rate_limit,omitempty"`
|
||||||
DownloadRateLimiter int `json:"download_rate_limiter" yaml:"download_rate_limiter,omitempty"`
|
DownloadRateLimitKiB int `json:"download_rate_limit" yaml:"download_rate_limit,omitempty"`
|
||||||
|
|
||||||
FetchNewTorrentsOnly bool `json:"fetch_new_torrents_only" yaml:"fetch_new_torrents_only,omitempty"`
|
FetchNewTorrentsOnly bool `json:"fetch_new_torrents_only" yaml:"fetch_new_torrents_only,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ type MetainfoFetcher struct {
|
||||||
baseFailCooldown int
|
baseFailCooldown int
|
||||||
maxFailCooldown int
|
maxFailCooldown int
|
||||||
newTorrentsOnly bool
|
newTorrentsOnly bool
|
||||||
done chan int
|
done chan struct{}
|
||||||
queue []*FetchOperation
|
queue []*FetchOperation
|
||||||
queueMutex sync.Mutex
|
queueMutex sync.Mutex
|
||||||
failedOperations map[uint]time.Time
|
failedOperations map[uint]time.Time
|
||||||
|
@ -37,20 +37,32 @@ type MetainfoFetcher struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New : Creates a MetainfoFetcher struct
|
// New : Creates a MetainfoFetcher struct
|
||||||
func New(fetcherConfig *config.MetainfoFetcherConfig) (fetcher *MetainfoFetcher, err error) {
|
func New(fetcherConfig *config.MetainfoFetcherConfig) (*MetainfoFetcher, error) {
|
||||||
clientConfig := torrent.Config{}
|
clientConfig := torrent.Config{}
|
||||||
|
|
||||||
// Well, it seems this is the right way to convert speed -> rate.Limiter
|
// Well, it seems this is the right way to convert speed -> rate.Limiter
|
||||||
// https://github.com/anacrolix/torrent/blob/master/cmd/torrent/main.go
|
// https://github.com/anacrolix/torrent/blob/master/cmd/torrent/main.go
|
||||||
if fetcherConfig.UploadRateLimiter != -1 {
|
const uploadBurst = 0x40000 // 256K
|
||||||
clientConfig.UploadRateLimiter = rate.NewLimiter(rate.Limit(fetcherConfig.UploadRateLimiter*1024), 256<<10)
|
const downloadBurst = 0x100000 // 1M
|
||||||
|
uploadLimit := fetcherConfig.UploadRateLimitKiB*1024
|
||||||
|
downloadLimit := fetcherConfig.DownloadRateLimitKiB*1024
|
||||||
|
if uploadLimit > 0 {
|
||||||
|
limit := rate.Limit(uploadLimit)
|
||||||
|
limiter := rate.NewLimiter(limit, uploadBurst)
|
||||||
|
clientConfig.UploadRateLimiter = limiter
|
||||||
}
|
}
|
||||||
if fetcherConfig.DownloadRateLimiter != -1 {
|
if downloadLimit > 0 {
|
||||||
clientConfig.DownloadRateLimiter = rate.NewLimiter(rate.Limit(fetcherConfig.DownloadRateLimiter*1024), 1<<20)
|
limit := rate.Limit(downloadLimit)
|
||||||
|
limiter := rate.NewLimiter(limit, downloadBurst)
|
||||||
|
clientConfig.DownloadRateLimiter = limiter
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := torrent.NewClient(&clientConfig)
|
client, err := torrent.NewClient(&clientConfig)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
fetcher = &MetainfoFetcher{
|
fetcher := &MetainfoFetcher{
|
||||||
torrentClient: client,
|
torrentClient: client,
|
||||||
results: make(chan Result, fetcherConfig.QueueSize),
|
results: make(chan Result, fetcherConfig.QueueSize),
|
||||||
queueSize: fetcherConfig.QueueSize,
|
queueSize: fetcherConfig.QueueSize,
|
||||||
|
@ -59,13 +71,13 @@ func New(fetcherConfig *config.MetainfoFetcherConfig) (fetcher *MetainfoFetcher,
|
||||||
newTorrentsOnly: fetcherConfig.FetchNewTorrentsOnly,
|
newTorrentsOnly: fetcherConfig.FetchNewTorrentsOnly,
|
||||||
baseFailCooldown: fetcherConfig.BaseFailCooldown,
|
baseFailCooldown: fetcherConfig.BaseFailCooldown,
|
||||||
maxFailCooldown: fetcherConfig.MaxFailCooldown,
|
maxFailCooldown: fetcherConfig.MaxFailCooldown,
|
||||||
done: make(chan int, 1),
|
done: make(chan struct{}, 1),
|
||||||
failedOperations: make(map[uint]time.Time),
|
failedOperations: make(map[uint]time.Time),
|
||||||
numFails: make(map[uint]int),
|
numFails: make(map[uint]int),
|
||||||
wakeUp: time.NewTicker(time.Second * time.Duration(fetcherConfig.WakeUpInterval)),
|
wakeUp: time.NewTicker(time.Second * time.Duration(fetcherConfig.WakeUpInterval)),
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return fetcher, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fetcher *MetainfoFetcher) isFetchingOrFailed(t model.Torrent) bool {
|
func (fetcher *MetainfoFetcher) isFetchingOrFailed(t model.Torrent) bool {
|
||||||
|
@ -291,20 +303,17 @@ func (fetcher *MetainfoFetcher) run() {
|
||||||
|
|
||||||
defer fetcher.wg.Done()
|
defer fetcher.wg.Done()
|
||||||
|
|
||||||
done := 0
|
for {
|
||||||
for done == 0 {
|
|
||||||
fetcher.removeOldFailures()
|
fetcher.removeOldFailures()
|
||||||
fetcher.fillQueue()
|
fetcher.fillQueue()
|
||||||
select {
|
select {
|
||||||
case done = <-fetcher.done:
|
case <-fetcher.done:
|
||||||
log.Infof("Got done signal on main loop, leaving...")
|
log.Infof("Got done signal on main loop, leaving...")
|
||||||
break
|
return
|
||||||
case result = <-fetcher.results:
|
case result = <-fetcher.results:
|
||||||
fetcher.gotResult(result)
|
fetcher.gotResult(result)
|
||||||
break
|
|
||||||
case <-fetcher.wakeUp.C:
|
case <-fetcher.wakeUp.C:
|
||||||
log.Infof("Got wake up signal...")
|
log.Infof("Got wake up signal...")
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -323,10 +332,10 @@ func (fetcher *MetainfoFetcher) Close() error {
|
||||||
|
|
||||||
// Send the done event to every Operation
|
// Send the done event to every Operation
|
||||||
for _, op := range fetcher.queue {
|
for _, op := range fetcher.queue {
|
||||||
op.done <- 1
|
op.done <- struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
fetcher.done <- 1
|
fetcher.done <- struct{}{}
|
||||||
fetcher.torrentClient.Close()
|
fetcher.torrentClient.Close()
|
||||||
log.Infof("Send done signal to everyone, waiting...")
|
log.Infof("Send done signal to everyone, waiting...")
|
||||||
fetcher.wg.Wait()
|
fetcher.wg.Wait()
|
||||||
|
|
|
@ -15,7 +15,7 @@ import (
|
||||||
type FetchOperation struct {
|
type FetchOperation struct {
|
||||||
fetcher *MetainfoFetcher
|
fetcher *MetainfoFetcher
|
||||||
torrent model.Torrent
|
torrent model.Torrent
|
||||||
done chan int
|
done chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Result struct
|
// Result struct
|
||||||
|
@ -30,7 +30,7 @@ func NewFetchOperation(fetcher *MetainfoFetcher, dbEntry model.Torrent) (op *Fet
|
||||||
op = &FetchOperation{
|
op = &FetchOperation{
|
||||||
fetcher: fetcher,
|
fetcher: fetcher,
|
||||||
torrent: dbEntry,
|
torrent: dbEntry,
|
||||||
done: make(chan int, 1),
|
done: make(chan struct{}, 1),
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -52,11 +52,8 @@ func (op *FetchOperation) Start(out chan Result) {
|
||||||
select {
|
select {
|
||||||
case <-downloadingTorrent.GotInfo():
|
case <-downloadingTorrent.GotInfo():
|
||||||
out <- Result{op, nil, downloadingTorrent.Info()}
|
out <- Result{op, nil, downloadingTorrent.Info()}
|
||||||
break
|
|
||||||
case <-timeoutTimer.C:
|
case <-timeoutTimer.C:
|
||||||
out <- Result{op, errors.New("Timeout"), nil}
|
out <- Result{op, errors.New("Timeout"), nil}
|
||||||
break
|
|
||||||
case <-op.done:
|
case <-op.done:
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Référencer dans un nouveau ticket