tstor/torrent/client.go

39 lines
1,013 B
Go
Raw Normal View History

package torrent
import (
"time"
"github.com/anacrolix/dht/v2"
"github.com/anacrolix/dht/v2/bep44"
tlog "github.com/anacrolix/log"
"github.com/anacrolix/torrent"
"github.com/anacrolix/torrent/storage"
2023-09-05 15:05:27 +00:00
"github.com/rs/zerolog/log"
2021-04-04 17:24:58 +00:00
"github.com/distribyted/distribyted/config"
dlog "github.com/distribyted/distribyted/log"
)
2021-12-09 16:45:25 +00:00
func NewClient(st storage.ClientImpl, fis bep44.Store, cfg *config.TorrentGlobal, id [20]byte) (*torrent.Client, error) {
// TODO download and upload limits
torrentCfg := torrent.NewDefaultClientConfig()
torrentCfg.Seed = true
2021-12-09 16:45:25 +00:00
torrentCfg.PeerID = string(id[:])
torrentCfg.DefaultStorage = st
2021-04-04 17:24:58 +00:00
torrentCfg.DisableIPv6 = cfg.DisableIPv6
l := log.Logger.With().Str("component", "torrent-client").Logger()
2023-09-05 15:05:27 +00:00
tl := tlog.NewLogger()
tl.SetHandlers(&dlog.Torrent{L: l})
torrentCfg.Logger = tl
torrentCfg.ConfigureAnacrolixDhtServer = func(cfg *dht.ServerConfig) {
cfg.Store = fis
cfg.Exp = 2 * time.Hour
cfg.NoSecurity = false
}
2021-04-04 17:24:58 +00:00
return torrent.NewClient(torrentCfg)
}