diff --git a/middleware/torrentapproval/container/directory/directory.go b/middleware/torrentapproval/container/directory/directory.go index c4063e1..41a30a3 100644 --- a/middleware/torrentapproval/container/directory/directory.go +++ b/middleware/torrentapproval/container/directory/directory.go @@ -1,3 +1,6 @@ +// Package directory implements container which +// checks if hash present in any of *.torrent file +// placed in some directory package directory import ( @@ -40,9 +43,8 @@ func build(confBytes []byte) (container.Container, error) { dir = c.BlacklistPath } var w *dirwatch.Instance - w, err = dirwatch.New(dir) if w, err = dirwatch.New(dir); err != nil { - return nil, fmt.Errorf("unable to initialize directory watch") + return nil, fmt.Errorf("unable to initialize directory watch: %v", err) } lst.watcher = w go func() { diff --git a/middleware/torrentapproval/container/list/list.go b/middleware/torrentapproval/container/list/list.go index ad2df74..13f4bb9 100644 --- a/middleware/torrentapproval/container/list/list.go +++ b/middleware/torrentapproval/container/list/list.go @@ -1,3 +1,5 @@ +// Package list implements container with pre-defined +// list of torrent hashes from config file package list import ( @@ -35,14 +37,13 @@ func build(confBytes []byte) (container.Container, error) { hashList := c.Whitelist if l.Invert { - l.Invert = true hashList = c.Blacklist } for _, hashString := range hashList { hashinfo, err := hex.DecodeString(hashString) if err != nil { - return nil, fmt.Errorf("whitelist : invalid hash %s", hashString) + return nil, fmt.Errorf("whitelist : invalid hash %s, %v", hashString, err) } if len(hashinfo) != 20 { return nil, fmt.Errorf("whitelist : hash %s is not 20 byes", hashString) diff --git a/storage/memory/peer_store.go b/storage/memory/peer_store.go index a3358b2..af66af9 100644 --- a/storage/memory/peer_store.go +++ b/storage/memory/peer_store.go @@ -147,23 +147,27 @@ func New(provided Config) (storage.PeerStore, error) { } }() - // Start a goroutine for reporting statistics to Prometheus. - ps.wg.Add(1) - go func() { - defer ps.wg.Done() - t := time.NewTicker(cfg.PrometheusReportingInterval) - for { - select { - case <-ps.closed: - t.Stop() - return - case <-t.C: - before := time.Now() - ps.populateProm() - log.Debug("storage: populateProm() finished", log.Fields{"timeTaken": time.Since(before)}) + if cfg.PrometheusReportingInterval > 0 { + // Start a goroutine for reporting statistics to Prometheus. + ps.wg.Add(1) + go func() { + defer ps.wg.Done() + t := time.NewTicker(cfg.PrometheusReportingInterval) + for { + select { + case <-ps.closed: + t.Stop() + return + case <-t.C: + before := time.Now() + ps.populateProm() + log.Debug("storage: populateProm() finished", log.Fields{"timeTaken": time.Since(before)}) + } } - } - }() + }() + } else { + log.Info("prometheus disabled because of zero reporting interval") + } return ps, nil }