2020-11-08 17:19:25 +00:00
|
|
|
package torrent
|
|
|
|
|
|
|
|
import (
|
2021-11-16 12:13:58 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/anacrolix/dht/v2"
|
|
|
|
"github.com/anacrolix/dht/v2/bep44"
|
|
|
|
tlog "github.com/anacrolix/log"
|
2020-11-08 17:19:25 +00:00
|
|
|
"github.com/anacrolix/torrent"
|
|
|
|
"github.com/anacrolix/torrent/storage"
|
2021-04-04 17:24:58 +00:00
|
|
|
"github.com/distribyted/distribyted/config"
|
2021-11-16 12:13:58 +00:00
|
|
|
dlog "github.com/distribyted/distribyted/log"
|
|
|
|
"github.com/rs/zerolog/log"
|
2020-11-08 17:19:25 +00:00
|
|
|
)
|
|
|
|
|
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) {
|
2020-11-08 17:19:25 +00:00
|
|
|
// TODO download and upload limits
|
|
|
|
torrentCfg := torrent.NewDefaultClientConfig()
|
|
|
|
torrentCfg.Seed = true
|
2021-12-09 16:45:25 +00:00
|
|
|
torrentCfg.PeerID = string(id[:])
|
2020-11-08 17:19:25 +00:00
|
|
|
torrentCfg.DefaultStorage = st
|
2021-04-04 17:24:58 +00:00
|
|
|
torrentCfg.DisableIPv6 = cfg.DisableIPv6
|
2020-11-08 17:19:25 +00:00
|
|
|
|
2021-11-16 12:13:58 +00:00
|
|
|
l := log.Logger.With().Str("component", "torrent-client").Logger()
|
|
|
|
torrentCfg.Logger = tlog.Logger{LoggerImpl: &dlog.Torrent{L: l}}
|
|
|
|
|
|
|
|
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)
|
2020-11-08 17:19:25 +00:00
|
|
|
}
|