FilesizeFetcher -> MetainfoFetcher
Cette révision appartient à :
Parent
80034bb52b
révision
2da2ad4214
6 fichiers modifiés avec 29 ajouts et 29 suppressions
|
@ -32,12 +32,12 @@ type Config struct {
|
|||
// optional i2p configuration
|
||||
I2P *I2PConfig `json:"i2p"`
|
||||
// filesize fetcher config
|
||||
FilesizeFetcher FilesizeFetcherConfig `json:"filesize_fetcher"`
|
||||
MetainfoFetcher MetainfoFetcherConfig `json:"metainfo_fetcher"`
|
||||
// internationalization config
|
||||
I18n I18nConfig `json:"i18n"`
|
||||
}
|
||||
|
||||
var Defaults = Config{"localhost", 9999, "sqlite3", "./nyaa.db?cache_size=50", "default", DefaultScraperConfig, DefaultCacheConfig, DefaultSearchConfig, nil, DefaultFilesizeFetcherConfig, DefaultI18nConfig}
|
||||
var Defaults = Config{"localhost", 9999, "sqlite3", "./nyaa.db?cache_size=50", "default", DefaultScraperConfig, DefaultCacheConfig, DefaultSearchConfig, nil, DefaultMetainfoFetcherConfig, DefaultI18nConfig}
|
||||
|
||||
|
||||
var allowedDatabaseTypes = map[string]bool{
|
||||
|
@ -62,7 +62,7 @@ func New() *Config {
|
|||
config.DBLogMode = Defaults.DBLogMode
|
||||
config.Scrape = Defaults.Scrape
|
||||
config.Cache = Defaults.Cache
|
||||
config.FilesizeFetcher = Defaults.FilesizeFetcher
|
||||
config.MetainfoFetcher = Defaults.MetainfoFetcher
|
||||
config.I18n = Defaults.I18n
|
||||
return &config
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package config
|
||||
|
||||
type FilesizeFetcherConfig struct {
|
||||
type MetainfoFetcherConfig struct {
|
||||
QueueSize int `json:"queue_size"`
|
||||
Timeout int `json:"timeout"`
|
||||
MaxDays int `json:"max_days"`
|
||||
WakeUpInterval int `json:"wake_up_interval"`
|
||||
}
|
||||
|
||||
var DefaultFilesizeFetcherConfig = FilesizeFetcherConfig{
|
||||
var DefaultMetainfoFetcherConfig = MetainfoFetcherConfig{
|
||||
QueueSize: 10,
|
||||
Timeout: 120, // 2 min
|
||||
MaxDays: 90,
|
12
main.go
12
main.go
|
@ -14,7 +14,7 @@ import (
|
|||
"github.com/ewhal/nyaa/network"
|
||||
"github.com/ewhal/nyaa/router"
|
||||
"github.com/ewhal/nyaa/service/scraper"
|
||||
"github.com/ewhal/nyaa/service/torrent/filesizeFetcher"
|
||||
"github.com/ewhal/nyaa/service/torrent/metainfoFetcher"
|
||||
"github.com/ewhal/nyaa/util/languages"
|
||||
"github.com/ewhal/nyaa/util/log"
|
||||
"github.com/ewhal/nyaa/util/search"
|
||||
|
@ -83,9 +83,9 @@ func RunScraper(conf *config.Config) {
|
|||
scraper.Wait()
|
||||
}
|
||||
|
||||
// RunFilesizeFetcher runs the database filesize fetcher main loop
|
||||
func RunFilesizeFetcher(conf *config.Config) {
|
||||
fetcher, err := filesizeFetcher.New(&conf.FilesizeFetcher)
|
||||
// RunMetainfoFetcher runs the database filesize fetcher main loop
|
||||
func RunMetainfoFetcher(conf *config.Config) {
|
||||
fetcher, err := metainfoFetcher.New(&conf.MetainfoFetcher)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to start fetcher, %s", err)
|
||||
return
|
||||
|
@ -147,8 +147,8 @@ func main() {
|
|||
RunScraper(conf)
|
||||
} else if *mode == "webapp" {
|
||||
RunServer(conf)
|
||||
} else if *mode == "filesize_fetcher" {
|
||||
RunFilesizeFetcher(conf)
|
||||
} else if *mode == "metainfo_fetcher" {
|
||||
RunMetainfoFetcher(conf)
|
||||
} else {
|
||||
log.Fatalf("invalid runtime mode: %s", *mode)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package filesizeFetcher;
|
||||
package metainfoFetcher;
|
||||
|
||||
import (
|
||||
"github.com/anacrolix/torrent"
|
||||
|
@ -13,7 +13,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
type FilesizeFetcher struct {
|
||||
type MetainfoFetcher struct {
|
||||
torrentClient *torrent.Client
|
||||
results chan Result
|
||||
queueSize int
|
||||
|
@ -27,9 +27,9 @@ type FilesizeFetcher struct {
|
|||
wg sync.WaitGroup
|
||||
}
|
||||
|
||||
func New(fetcherConfig *config.FilesizeFetcherConfig) (fetcher *FilesizeFetcher, err error) {
|
||||
func New(fetcherConfig *config.MetainfoFetcherConfig) (fetcher *MetainfoFetcher, err error) {
|
||||
client, err := torrent.NewClient(nil)
|
||||
fetcher = &FilesizeFetcher{
|
||||
fetcher = &MetainfoFetcher{
|
||||
torrentClient: client,
|
||||
results: make(chan Result, fetcherConfig.QueueSize),
|
||||
queueSize: fetcherConfig.QueueSize,
|
||||
|
@ -43,7 +43,7 @@ func New(fetcherConfig *config.FilesizeFetcherConfig) (fetcher *FilesizeFetcher,
|
|||
return
|
||||
}
|
||||
|
||||
func (fetcher *FilesizeFetcher) isFetchingOrFailed(t model.Torrent) bool {
|
||||
func (fetcher *MetainfoFetcher) isFetchingOrFailed(t model.Torrent) bool {
|
||||
for _, op := range fetcher.queue {
|
||||
if op.torrent.ID == t.ID {
|
||||
return true
|
||||
|
@ -54,7 +54,7 @@ func (fetcher *FilesizeFetcher) isFetchingOrFailed(t model.Torrent) bool {
|
|||
return ok
|
||||
}
|
||||
|
||||
func (fetcher *FilesizeFetcher) addToQueue(op *FetchOperation) bool {
|
||||
func (fetcher *MetainfoFetcher) addToQueue(op *FetchOperation) bool {
|
||||
fetcher.queueMutex.Lock()
|
||||
defer fetcher.queueMutex.Unlock()
|
||||
|
||||
|
@ -67,7 +67,7 @@ func (fetcher *FilesizeFetcher) addToQueue(op *FetchOperation) bool {
|
|||
}
|
||||
|
||||
|
||||
func (fetcher *FilesizeFetcher) removeFromQueue(op *FetchOperation) bool {
|
||||
func (fetcher *MetainfoFetcher) removeFromQueue(op *FetchOperation) bool {
|
||||
fetcher.queueMutex.Lock()
|
||||
defer fetcher.queueMutex.Unlock()
|
||||
|
||||
|
@ -111,7 +111,7 @@ func updateFileList(dbEntry model.Torrent, info *metainfo.Info) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (fetcher *FilesizeFetcher) gotResult(r Result) {
|
||||
func (fetcher *MetainfoFetcher) gotResult(r Result) {
|
||||
updatedSuccessfully := false
|
||||
if r.err != nil {
|
||||
log.Infof("Failed to get torrent filesize (TID: %d), err %v", r.operation.torrent.ID, r.err)
|
||||
|
@ -141,7 +141,7 @@ func (fetcher *FilesizeFetcher) gotResult(r Result) {
|
|||
fetcher.removeFromQueue(r.operation)
|
||||
}
|
||||
|
||||
func (fetcher *FilesizeFetcher) fillQueue() {
|
||||
func (fetcher *MetainfoFetcher) fillQueue() {
|
||||
toFill := fetcher.queueSize - len(fetcher.queue)
|
||||
|
||||
if toFill <= 0 {
|
||||
|
@ -180,7 +180,7 @@ func (fetcher *FilesizeFetcher) fillQueue() {
|
|||
}
|
||||
}
|
||||
|
||||
func (fetcher *FilesizeFetcher) run() {
|
||||
func (fetcher *MetainfoFetcher) run() {
|
||||
var result Result
|
||||
|
||||
defer fetcher.wg.Done()
|
||||
|
@ -202,13 +202,13 @@ func (fetcher *FilesizeFetcher) run() {
|
|||
}
|
||||
}
|
||||
|
||||
func (fetcher *FilesizeFetcher) RunAsync() {
|
||||
func (fetcher *MetainfoFetcher) RunAsync() {
|
||||
fetcher.wg.Add(1)
|
||||
|
||||
go fetcher.run()
|
||||
}
|
||||
|
||||
func (fetcher *FilesizeFetcher) Close() error {
|
||||
func (fetcher *MetainfoFetcher) Close() error {
|
||||
fetcher.queueMutex.Lock()
|
||||
defer fetcher.queueMutex.Unlock()
|
||||
|
||||
|
@ -222,7 +222,7 @@ func (fetcher *FilesizeFetcher) Close() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (fetcher *FilesizeFetcher) Wait() {
|
||||
func (fetcher *MetainfoFetcher) Wait() {
|
||||
fetcher.wg.Wait()
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package filesizeFetcher;
|
||||
package metainfoFetcher;
|
||||
|
||||
import (
|
||||
"github.com/anacrolix/torrent/metainfo"
|
||||
|
@ -11,7 +11,7 @@ import (
|
|||
)
|
||||
|
||||
type FetchOperation struct {
|
||||
fetcher *FilesizeFetcher
|
||||
fetcher *MetainfoFetcher
|
||||
torrent model.Torrent
|
||||
done chan int
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ type Result struct {
|
|||
info *metainfo.Info
|
||||
}
|
||||
|
||||
func NewFetchOperation(fetcher *FilesizeFetcher, dbEntry model.Torrent) (op *FetchOperation) {
|
||||
func NewFetchOperation(fetcher *MetainfoFetcher, dbEntry model.Torrent) (op *FetchOperation) {
|
||||
op = &FetchOperation{
|
||||
fetcher: fetcher,
|
||||
torrent: dbEntry,
|
|
@ -1,4 +1,4 @@
|
|||
package filesizeFetcher;
|
||||
package metainfoFetcher;
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
@ -13,7 +13,7 @@ func TestInvalidHash(t *testing.T) {
|
|||
t.Skipf("Failed to create client, with err %v. Skipping.", err)
|
||||
}
|
||||
|
||||
fetcher := &FilesizeFetcher{
|
||||
fetcher := &MetainfoFetcher{
|
||||
timeout: 5,
|
||||
torrentClient: client,
|
||||
results: make(chan Result, 1),
|
Référencer dans un nouveau ticket