mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 11:41:19 +00:00
Better validate --torrent.verbosity flag (#4257)
* lastDup no key * lastDup no key * lastDup no key
This commit is contained in:
parent
0d259384a0
commit
1eb9aec08a
@ -13,11 +13,12 @@ func init() {
|
|||||||
utp.Logger.Handlers = []lg.Handler{noopHandler{}}
|
utp.Logger.Handlers = []lg.Handler{noopHandler{}}
|
||||||
}
|
}
|
||||||
|
|
||||||
var String2LogLevel = map[string]lg.Level{
|
func Str2LogLevel(in string) (lg.Level, error) {
|
||||||
lg.Debug.LogString(): lg.Debug,
|
lvl := lg.Level{}
|
||||||
lg.Info.LogString(): lg.Info,
|
if err := lvl.UnmarshalText([]byte(in)); err != nil {
|
||||||
lg.Warning.LogString(): lg.Warning,
|
return lvl, err
|
||||||
lg.Error.LogString(): lg.Error,
|
}
|
||||||
|
return lvl, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type noopHandler struct{}
|
type noopHandler struct{}
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
lg "github.com/anacrolix/log"
|
lg "github.com/anacrolix/log"
|
||||||
"github.com/anacrolix/torrent"
|
"github.com/anacrolix/torrent"
|
||||||
@ -41,9 +40,18 @@ func Default() *torrent.ClientConfig {
|
|||||||
//torrentConfig.DisableWebseeds = true
|
//torrentConfig.DisableWebseeds = true
|
||||||
|
|
||||||
// Reduce defaults - to avoid peers with very bad geography
|
// Reduce defaults - to avoid peers with very bad geography
|
||||||
torrentConfig.MinDialTimeout = 1 * time.Second // default: 3sec
|
//torrentConfig.MinDialTimeout = 1 * time.Second // default: 3sec
|
||||||
torrentConfig.NominalDialTimeout = 10 * time.Second // default: 20sec
|
//torrentConfig.NominalDialTimeout = 10 * time.Second // default: 20sec
|
||||||
torrentConfig.HandshakesTimeout = 1 * time.Second // default: 4sec
|
//torrentConfig.HandshakesTimeout = 1 * time.Second // default: 4sec
|
||||||
|
|
||||||
|
// see: https://en.wikipedia.org/wiki/TCP_half-open
|
||||||
|
//torrentConfig.TotalHalfOpenConns = 100 // default: 100
|
||||||
|
//torrentConfig.HalfOpenConnsPerTorrent = 25 // default: 25
|
||||||
|
//torrentConfig.TorrentPeersHighWater = 500 // default: 500
|
||||||
|
//torrentConfig.TorrentPeersLowWater = 50 // default: 50
|
||||||
|
|
||||||
|
torrentConfig.Seed = true
|
||||||
|
torrentConfig.UpnpID = torrentConfig.UpnpID + "leecher"
|
||||||
|
|
||||||
return torrentConfig
|
return torrentConfig
|
||||||
}
|
}
|
||||||
@ -52,17 +60,7 @@ func New(snapDir string, verbosity lg.Level, natif nat.Interface, downloadRate,
|
|||||||
torrentConfig := Default()
|
torrentConfig := Default()
|
||||||
// We would-like to reduce amount of goroutines in Erigon, so reducing next params
|
// We would-like to reduce amount of goroutines in Erigon, so reducing next params
|
||||||
torrentConfig.EstablishedConnsPerTorrent = connsPerFile // default: 50
|
torrentConfig.EstablishedConnsPerTorrent = connsPerFile // default: 50
|
||||||
|
|
||||||
// see: https://en.wikipedia.org/wiki/TCP_half-open
|
|
||||||
torrentConfig.TotalHalfOpenConns = 100 // default: 100
|
|
||||||
torrentConfig.HalfOpenConnsPerTorrent = 25 // default: 25
|
|
||||||
|
|
||||||
torrentConfig.TorrentPeersHighWater = 500 // default: 500
|
|
||||||
torrentConfig.TorrentPeersLowWater = 50 // default: 50
|
|
||||||
|
|
||||||
torrentConfig.Seed = true
|
|
||||||
torrentConfig.DataDir = snapDir
|
torrentConfig.DataDir = snapDir
|
||||||
torrentConfig.UpnpID = torrentConfig.UpnpID + "leecher"
|
|
||||||
|
|
||||||
torrentConfig.ListenPort = port
|
torrentConfig.ListenPort = port
|
||||||
// check if ipv6 is enabled
|
// check if ipv6 is enabled
|
||||||
|
@ -113,9 +113,9 @@ var rootCmd = &cobra.Command{
|
|||||||
|
|
||||||
func Downloader(ctx context.Context) error {
|
func Downloader(ctx context.Context) error {
|
||||||
snapDir := filepath.Join(datadir, "snapshots")
|
snapDir := filepath.Join(datadir, "snapshots")
|
||||||
torrentLogLevel, ok := torrentcfg.String2LogLevel[torrentVerbosity]
|
torrentLogLevel, err := torrentcfg.Str2LogLevel(torrentVerbosity)
|
||||||
if !ok {
|
if err != nil {
|
||||||
panic(fmt.Errorf("unexpected torrent.verbosity level: %s", torrentVerbosity))
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var downloadRate, uploadRate datasize.ByteSize
|
var downloadRate, uploadRate datasize.ByteSize
|
||||||
|
@ -113,7 +113,6 @@ var rootCmd = &cobra.Command{
|
|||||||
|
|
||||||
cfg := txpool.DefaultConfig
|
cfg := txpool.DefaultConfig
|
||||||
cfg.DBDir = filepath.Join(datadir, "txpool")
|
cfg.DBDir = filepath.Join(datadir, "txpool")
|
||||||
cfg.LogEvery = 30 * time.Second
|
|
||||||
cfg.CommitEvery = 30 * time.Second
|
cfg.CommitEvery = 30 * time.Second
|
||||||
cfg.PendingSubPoolLimit = pendingPoolLimit
|
cfg.PendingSubPoolLimit = pendingPoolLimit
|
||||||
cfg.BaseFeeSubPoolLimit = baseFeePoolLimit
|
cfg.BaseFeeSubPoolLimit = baseFeePoolLimit
|
||||||
|
@ -31,7 +31,6 @@ import (
|
|||||||
|
|
||||||
lg "github.com/anacrolix/log"
|
lg "github.com/anacrolix/log"
|
||||||
"github.com/c2h5oh/datasize"
|
"github.com/c2h5oh/datasize"
|
||||||
"github.com/ledgerwatch/erigon-lib/kv"
|
|
||||||
"github.com/ledgerwatch/erigon-lib/kv/kvcache"
|
"github.com/ledgerwatch/erigon-lib/kv/kvcache"
|
||||||
"github.com/ledgerwatch/erigon-lib/txpool"
|
"github.com/ledgerwatch/erigon-lib/txpool"
|
||||||
"github.com/ledgerwatch/erigon/cmd/downloader/downloader/torrentcfg"
|
"github.com/ledgerwatch/erigon/cmd/downloader/downloader/torrentcfg"
|
||||||
@ -642,7 +641,7 @@ var (
|
|||||||
TorrentVerbosityFlag = cli.StringFlag{
|
TorrentVerbosityFlag = cli.StringFlag{
|
||||||
Name: "torrent.verbosity",
|
Name: "torrent.verbosity",
|
||||||
Value: lg.Warning.LogString(),
|
Value: lg.Warning.LogString(),
|
||||||
Usage: "DEBUG | INFO | WARN | ERROR (must set --verbosity to equal or higher level)",
|
Usage: "DBG | INF | WRN | ERR (must set --verbosity to equal or higher level)",
|
||||||
}
|
}
|
||||||
TorrentDownloadRateFlag = cli.StringFlag{
|
TorrentDownloadRateFlag = cli.StringFlag{
|
||||||
Name: "torrent.download.rate",
|
Name: "torrent.download.rate",
|
||||||
@ -1391,9 +1390,12 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *node.Config, cfg *ethconfig.Conf
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
lvl, err := torrentcfg.Str2LogLevel(ctx.GlobalString(TorrentVerbosityFlag.Name))
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
cfg.Torrent, err = torrentcfg.New(cfg.SnapDir,
|
cfg.Torrent, err = torrentcfg.New(cfg.SnapDir,
|
||||||
torrentcfg.String2LogLevel[ctx.GlobalString(TorrentVerbosityFlag.Name)],
|
lvl,
|
||||||
nodeConfig.P2P.NAT,
|
nodeConfig.P2P.NAT,
|
||||||
downloadRate, uploadRate,
|
downloadRate, uploadRate,
|
||||||
ctx.GlobalInt(TorrentPortFlag.Name),
|
ctx.GlobalInt(TorrentPortFlag.Name),
|
||||||
@ -1527,15 +1529,6 @@ func SplitTagsFlag(tagsFlag string) map[string]string {
|
|||||||
return tagsMap
|
return tagsMap
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeChainDatabase open a database using the flags passed to the client and will hard crash if it fails.
|
|
||||||
func MakeChainDatabase(logger log.Logger, cfg *node.Config) kv.RwDB {
|
|
||||||
chainDb, err := node.OpenDatabase(cfg, logger, kv.ChainDB)
|
|
||||||
if err != nil {
|
|
||||||
Fatalf("Could not open database: %v", err)
|
|
||||||
}
|
|
||||||
return chainDb
|
|
||||||
}
|
|
||||||
|
|
||||||
// MakeConsolePreloads retrieves the absolute paths for the console JavaScript
|
// MakeConsolePreloads retrieves the absolute paths for the console JavaScript
|
||||||
// scripts to preload before starting.
|
// scripts to preload before starting.
|
||||||
func MakeConsolePreloads(ctx *cli.Context) []string {
|
func MakeConsolePreloads(ctx *cli.Context) []string {
|
||||||
|
Loading…
Reference in New Issue
Block a user