Modify configuration structure. ()

This commit is contained in:
Antonio Navarro Perez 2021-04-04 19:24:58 +02:00 committed by GitHub
parent cfede1d8f1
commit 5bb067be1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 352 additions and 170 deletions

View file

@ -4,15 +4,17 @@ import (
"github.com/anacrolix/log"
"github.com/anacrolix/torrent"
"github.com/anacrolix/torrent/storage"
"github.com/distribyted/distribyted/config"
)
func NewClient(st storage.ClientImpl) (*torrent.Client, error) {
func NewClient(st storage.ClientImpl, cfg *config.TorrentGlobal) (*torrent.Client, error) {
// TODO download and upload limits
torrentCfg := torrent.NewDefaultClientConfig()
torrentCfg.Logger = log.Discard
torrentCfg.Seed = true
torrentCfg.DefaultStorage = st
return torrent.NewClient(torrentCfg)
torrentCfg.DisableIPv6 = cfg.DisableIPv6
return torrent.NewClient(torrentCfg)
}

View file

@ -27,7 +27,7 @@ func NewHandler(c *torrent.Client, s *stats.Torrent) *Handler {
}
}
func (s *Handler) Load(path string, ts []*config.Torrent) error {
func (s *Handler) Load(route string, ts []*config.Torrent) error {
var torrents []*torrent.Torrent
for _, mpcTorrent := range ts {
var t *torrent.Torrent
@ -36,10 +36,8 @@ func (s *Handler) Load(path string, ts []*config.Torrent) error {
switch {
case mpcTorrent.MagnetURI != "":
t, err = s.c.AddMagnet(mpcTorrent.MagnetURI)
break
case mpcTorrent.TorrentPath != "":
t, err = s.c.AddTorrentFromFile(mpcTorrent.TorrentPath)
break
default:
err = fmt.Errorf("no magnet URI or torrent path provided")
}
@ -53,13 +51,13 @@ func (s *Handler) Load(path string, ts []*config.Torrent) error {
<-t.GotInfo()
}
s.s.Add(path, t)
s.s.Add(route, t)
torrents = append(torrents, t)
log.Info().Str("name", t.Name()).Str("path", path).Msg("torrent added to mountpoint")
log.Info().Str("name", t.Name()).Str("route", route).Msg("torrent added to mountpoint")
}
folder := path
folder := "/" + route
s.fssMu.Lock()
defer s.fssMu.Unlock()