Skip to content

Commit

Permalink
--torrent.staticpeers (erigontech#7052)
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored and ty-sentio-xyz committed Mar 16, 2023
1 parent e5424a1 commit 588c1a8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion cmd/downloader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net"
"os"
"path/filepath"
"strings"
"time"

"github.com/anacrolix/torrent/metainfo"
Expand Down Expand Up @@ -45,6 +46,7 @@ var (
torrentVerbosity int
downloadRateStr, uploadRateStr string
torrentDownloadSlots int
staticPeersStr string
torrentPort int
torrentMaxPeers int
torrentConnsPerFile int
Expand All @@ -67,6 +69,7 @@ func init() {
rootCmd.Flags().IntVar(&torrentMaxPeers, "torrent.maxpeers", utils.TorrentMaxPeersFlag.Value, utils.TorrentMaxPeersFlag.Usage)
rootCmd.Flags().IntVar(&torrentConnsPerFile, "torrent.conns.perfile", utils.TorrentConnsPerFileFlag.Value, utils.TorrentConnsPerFileFlag.Usage)
rootCmd.Flags().IntVar(&torrentDownloadSlots, "torrent.download.slots", utils.TorrentDownloadSlotsFlag.Value, utils.TorrentDownloadSlotsFlag.Usage)
rootCmd.Flags().StringVar(&staticPeersStr, utils.TorrentStaticPeersFlag.Name, utils.TorrentStaticPeersFlag.Value, utils.TorrentStaticPeersFlag.Usage)
rootCmd.Flags().BoolVar(&disableIPV6, "downloader.disable.ipv6", utils.DisableIPV6.Value, utils.DisableIPV6.Usage)
rootCmd.Flags().BoolVar(&disableIPV4, "downloader.disable.ipv4", utils.DisableIPV4.Value, utils.DisableIPV6.Usage)

Expand Down Expand Up @@ -141,9 +144,10 @@ func Downloader(ctx context.Context) error {
if err != nil {
return fmt.Errorf("invalid nat option %s: %w", natSetting, err)
}
staticPeers := strings.Split(staticPeersStr, ",")

version := "erigon: " + params.VersionWithCommit(params.GitCommit)
cfg, err := downloadercfg2.New(dirs.Snap, version, torrentLogLevel, downloadRate, uploadRate, torrentPort, torrentConnsPerFile, torrentDownloadSlots)
cfg, err := downloadercfg2.New(dirs.Snap, version, torrentLogLevel, downloadRate, uploadRate, torrentPort, torrentConnsPerFile, torrentDownloadSlots, staticPeers)
if err != nil {
return err
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,11 @@ var (
Value: 3,
Usage: "amount of files to download in parallel. If network has enough seeders 1-3 slot enough, if network has lack of seeders increase to 5-7 (too big value will slow down everything).",
}
TorrentStaticPeersFlag = cli.StringFlag{
Name: "torrent.staticpeers",
Usage: "Comma separated enode URLs to connect to",
Value: "",
}
NoDownloaderFlag = cli.BoolFlag{
Name: "no-downloader",
Usage: "to disable downloader component",
Expand Down Expand Up @@ -1511,7 +1516,7 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *nodecfg.Config, cfg *ethconfig.C
}
log.Info("torrent verbosity", "level", lvl.LogString())
version := "erigon: " + params.VersionWithCommit(params.GitCommit)
cfg.Downloader, err = downloadercfg2.New(cfg.Dirs.Snap, version, lvl, downloadRate, uploadRate, ctx.Int(TorrentPortFlag.Name), ctx.Int(TorrentConnsPerFileFlag.Name), ctx.Int(TorrentDownloadSlotsFlag.Name))
cfg.Downloader, err = downloadercfg2.New(cfg.Dirs.Snap, version, lvl, downloadRate, uploadRate, ctx.Int(TorrentPortFlag.Name), ctx.Int(TorrentConnsPerFileFlag.Name), ctx.Int(TorrentDownloadSlotsFlag.Name), ctx.StringSlice(TorrentDownloadSlotsFlag.Name))
if err != nil {
panic(err)
}
Expand Down
1 change: 1 addition & 0 deletions turbo/cli/default_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ var DefaultFlags = []cli.Flag{
&utils.TorrentMaxPeersFlag,
&utils.TorrentConnsPerFileFlag,
&utils.TorrentDownloadSlotsFlag,
&utils.TorrentStaticPeersFlag,
&utils.TorrentUploadRateFlag,
&utils.TorrentDownloadRateFlag,
&utils.TorrentVerbosityFlag,
Expand Down

0 comments on commit 588c1a8

Please sign in to comment.